StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
subtractPileup.C
1 void subtractPileup(const char *pileupCutFile, const char *noPileupCutFile, const char *subFile, double eff=0.75) {
2 
3  // -- Look for correlation histograms in both input files solve for pileup and
4  // noPileup (assuming 75% rejection efficiency for now) and write to outputfile.
5  //
6  // root.exe -q -b subtractPileup.C("cutFile","noCutFile","subFile")
7  //
8  // cutFile is root histogram file with pileup cuts invoked
9  // noCutFile is root histogram file without pileup cuts invoked
10  // Solve for extrapolation to no pileup and to only pileup.
11  // Write histograms to subFile
12  // Filenames include paths.
13 
14  TFile *tfCut, *tfNoCut, *tfOut;
15  TH2D *cut, *noCut, *noPileup, *pileup;
16 
17  const char* binName[]={"all","awayside","nearside","soft","softAS","softNS","neck","neckAS","neckNS","hard","hardAS","hardNS","softHard","softHardAS","softHardNS"};
18  const char* type[] = {"PP", "PM", "MP", "MM", "LS", "US", "CD", "CI"};
19  //>>>>> I may have forgotten things that should be in knd.
20  const char* knd[]={"YtYt", "SYtDYt", "PtPt",
21  "NEtaEta", "PtEtaEta", "NPhiPhi", "PtPhiPhi",
22  "NDEtaDPhi", "PtDEtaDPhi", "NSEtaDPhi", "PtSEtaDPhi"};
23 
24  char buffer[1024];
25  TFile *tfCut = new TFile(pileupCutFile);
26  TFile *tfNoCut = new TFile(noPileupCutFile);
27  TFile *tfOut = new TFile(subFile,"RECREATE");
28 
29  // Don't know how to ask root for list of histograms.
30  // Look for names we believe are possible
31  for (int it=0;it<8;it++) {
32  for (int ik=0;ik<11;ik++) {
33  for (int ibin=0;ibin<15;ibin++) {
34  int ic=0;
35  sprintf(buffer,"%s_%s_%s_%i",binName[ibin],knd[ik],type[it],ic);
36  tfCut->GetObject(buffer,cut);
37  tfNoCut->GetObject(buffer,noCut);
38  while (cut && noCut) {
39  // Found something.
40  noPileup = (TH2D *) cut->Clone();
41  pileup = (TH2D *) cut->Clone();
42  noPileup->Reset();
43  pileup->Reset();
44  sprintf(buffer,"%s_%s_%s_%i_pileup",binName[ibin],knd[ik],type[it],ic);
45  pileup->SetName(buffer);
46 
47  noPileup->Add(cut,noCut,1,-(1-eff));
48  noPileup->Scale(1/eff);
49  pileup->Add(noCut,cut,1,-1);
50  pileup->Scale(1/eff);
51  // Adjust errors to be only errors of cut.
52  for (int ix=1;ix<=noCut->GetNbinsX();ix++) {
53  for (int iy=1;iy<=noCut->GetNbinsY();iy++) {
54  double err = cut->GetBinError(ix,iy);
55  noPileup->SetBinError(ix,iy,err);
56  pileup->SetBinError(ix,iy,err);
57  }
58  }
59  // Write to subFile
60  tfOut->cd();
61  noPileup->Write();
62  pileup->Write();
63  // Clean up histogram space.
64  delete pileup;
65  delete noPileup;
66 
67  // Check for next centrality
68  ic++;
69  sprintf(buffer,"%s_%s_%s_%i",binName[ibin],knd[ik],type[it],ic);
70  tfCut->GetObject(buffer,cut);
71  tfNoCut->GetObject(buffer,noCut);
72  }
73  }
74  }
75  }
76  tfOut->Close();
77 }