AliPhysics  a8afd6c (a8afd6c)
ScaleExtractPtHardBinHistograms.C
Go to the documentation of this file.
1 
17 //---------------------------------------------------------
18 // Set includes and declare methods for compilation
19 
20 #if !defined(__CINT__) || defined(__MAKECINT__)
21 
22 #include "TString.h"
23 #include "TH1F.h"
24 #include "TH2F.h"
25 #include "TFile.h"
26 #include "TList.h"
27 #include "TDirectoryFile.h"
28 
29 #endif // CINT
30 
31 void ForBin
32 (
33  Int_t bin = -1,
34  TString listName = "Pi0IM_GammaTrackCorr_EMCAL",
35  TString subListName = "default"
36 );
37 
45 //_______________________________________________________________________
47 (Int_t bin = -1,
48  TString listName = "Pi0IM_GammaTrackCorr_EMCAL",
49  TString subListName = "default" )
50 {
51  if(bin < 0)
52  {
53  for(Int_t i = 1; i < 21; i++)
54  {
55  ForBin(i,listName,subListName);
56  }
57  }
58  else
59  ForBin(bin,listName,subListName);
60 }
61 
69 //_______________________________________________________________________
70 void ForBin ( Int_t bin, TString listName, TString subListName )
71 {
72  printf("Scale pT hard bin %d\n",bin);
73 
74  TFile * f= TFile::Open(Form("%d/Merged.root",bin),"read");
75 
76  if(!f)
77  {
78  printf("No file available \n");
79  return;
80  }
81 
82  TDirectoryFile* dir = (TDirectoryFile*) f->Get(Form("%s",listName.Data()));
83 
84  if(!dir)
85  {
86  printf("No directory <%s> available \n",listName.Data());
87  return;
88  }
89 
90  TList* list = (TList*) dir->Get(Form("%s",subListName.Data()));
91 
92  if(!list)
93  {
94  printf("No list <%s> available \n", subListName.Data());
95  return;
96  }
97 
98  //
99  // Extract into separate file without scaling
100  //
101  TFile * foutNo = new TFile(Form("%d/NotScaledMerged.root",bin),"recreate");
102 
103  foutNo->Print("");
104 
105  list->Write();
106 
107  foutNo->Close();
108  delete foutNo;
109 
110  //
111  // Calculate scaling factor
112  //
113  Double_t nEve = ((TH1F*)list->FindObject("hNEvents"))->GetBinContent(1);
114  Double_t xsec = 1;
115  Double_t trials = 1;
116  Int_t nfiles = 1;
117  if((TH1F*)list->FindObject("hXsec" ))
118  {
119  xsec = ((TH1F*)list->FindObject("hXsec" ))->GetBinContent(1);
120  trials = ((TH1F*)list->FindObject("hTrials" ))->GetBinContent(1);
121  nfiles = ((TH1F*)list->FindObject("hTrials" ))->GetEntries();
122  }
123  else printf("XSec histogram not found!!!!\n");
124  printf(" nevents %e, xsec %2.2e, nTrials %e, files %d; ",nEve,xsec,trials,nfiles);
125 
126  trials/=nfiles;
127  xsec /=nfiles;
128 
129  Double_t scale = xsec/trials/nEve;
130 
131  printf(" average: xsec %2.2e, trials %2.2f, scale factor %2.3e\n",xsec,trials,scale);
132 
133  //
134  // Scale each histogram, apply Sumw2 before.
135  //
136 
137  printf("\t scaling ...\n ");
138 
139  TObject * h = 0 ;
140 
141  for(Int_t i = 0; i < list->GetEntries(); i++)
142  {
143  h = list->At(i);
144  if(h)
145  {
146  if ( !strncmp(h->ClassName(),"TH",2) )
147  {
148  //snprintf(name, buffersize, "%sScaled", h->GetName()) ;
149 
150  TH1 * hout = dynamic_cast<TH1*> (h);//(h->Clone(name)) ;
151 
152  if(hout)
153  {
154  hout->Sumw2();
155  hout->Scale(scale) ;
156  // fOutputList->Add(hout) ;
157  }// casting not null
158  }
159  //else fOutputList->Add(h) ;
160  }
161  }
162 
163  printf("\t ... end scaling, write ...\n");
164 
165  TFile * fout = new TFile(Form("%d/ScaledMerged.root",bin),"recreate");
166 
167  fout->Print("");
168 
169  list->Write();
170 
171  fout->Close();
172  delete fout;
173  f->Close();
174  delete f;
175  delete h;
176 
177  printf("\t ... done.\n");
178 
179 }
double Double_t
Definition: External.C:58
int Int_t
Definition: External.C:63
void ForBin(Int_t bin=-1, TString listName="Pi0IM_GammaTrackCorr_EMCAL", TString subListName="default")
void ScaleExtractPtHardBinHistograms(Int_t bin=-1, TString listName="Pi0IM_GammaTrackCorr_EMCAL", TString subListName="default")
TFile * fout
input train file
Definition: External.C:196
TDirectoryFile * dir