StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
subtractPileup5.C
1 void subtractPileup5(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("dir","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  // What about "pio", "Ko" and "po" ??
18  const char* binName[]={"all","pipi","piK","pip","KK","Kp","pp","oo"};
19  const char* type[] = {"PP", "PM", "MP", "MM", "LS", "US", "CD", "CI"};
20  //>>>>> I may have forgotten things that should be in knd.
21  const char* knd[]={"YtYt", "SYtDYt", "PtPt",
22  "NEtaEta", "PtEtaEta", "NPhiPhi", "PtPhiPhi",
23  "NDEtaDPhi", "PtDEtaDPhi", "NSEtaDPhi", "PtSEtaDPhi"};
24 
25  char buffer[1024];
26  TFile *tfCut = new TFile(pileupCutFile);
27  TFile *tfNoCut = new TFile(noPileupCutFile);
28  TFile *tfOut = new TFile(subFile,"RECREATE");
29 
30  // Don't know how to ask root for list of histograms.
31  // Look for names we believe are possible
32  for (int it=0;it<8;it++) {
33  for (int ik=0;ik<11;ik++) {
34  for (int ibin=0;ibin<8;ibin++) {
35  int ic=0;
36  sprintf(buffer,"%s_%s_%s_%i",binName[ibin],knd[ik],type[it],ic);
37  tfCut->GetObject(buffer,cut);
38  tfNoCut->GetObject(buffer,noCut);
39  while (cut && noCut) {
40  // Found something.
41  noPileup = (TH2D *) cut->Clone();
42  pileup = (TH2D *) cut->Clone();
43  noPileup->Reset();
44  pileup->Reset();
45  sprintf(buffer,"%s_%s_%s_%i_pileup",binName[ibin],knd[ik],type[it],ic);
46  pileup->SetName(buffer);
47 
48  noPileup->Add(cut,noCut,1,-(1-eff));
49  noPileup->Scale(1/eff);
50  pileup->Add(noCut,cut,1,-1);
51  pileup->Scale(1/eff);
52  // Adjust errors to be only errors of cut.
53  for (int ix=1;ix<=noCut->GetNbinsX();ix++) {
54  for (int iy=1;iy<=noCut->GetNbinsY();iy++) {
55  double err = cut->GetBinError(ix,iy);
56  noPileup->SetBinError(ix,iy,err);
57  pileup->SetBinError(ix,iy,err);
58  }
59  }
60  // Write to subFile
61  tfOut->cd();
62  noPileup->Write();
63  pileup->Write();
64  // Clean up histogram space.
65  delete pileup;
66  delete noPileup;
67 
68  // Check for next centrality
69  ic++;
70  sprintf(buffer,"%s_%s_%s_%i",binName[ibin],knd[ik],type[it],ic);
71  tfCut->GetObject(buffer,cut);
72  tfNoCut->GetObject(buffer,noCut);
73  }
74  }
75  }
76  }
77  tfOut->Close();
78 }