AliPhysics  068200c (068200c)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
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 = ((TH1F*)list->FindObject("hXsec" ))->GetBinContent(1);
115  Double_t trials = ((TH1F*)list->FindObject("hTrials" ))->GetBinContent(1);
116  Int_t nfiles = ((TH1F*)list->FindObject("hTrials" ))->GetEntries();
117 
118  printf(" nevents %e, xsec %2.2e, nTrials %e, files %d; ",nEve,xsec,trials,nfiles);
119 
120  trials/=nfiles;
121  xsec /=nfiles;
122 
123  Double_t scale = xsec/trials/nEve;
124 
125  printf(" average: xsec %2.2e, trials %2.2f, scale factor %2.3e\n",xsec,trials,scale);
126 
127  //
128  // Scale each histogram, apply Sumw2 before.
129  //
130 
131  printf("\t scaling ...\n ");
132 
133  TObject * h ;
134 
135  for(Int_t i = 0; i < list->GetEntries(); i++)
136  {
137  h = list->At(i);
138  if(h)
139  {
140  if ( !strncmp(h->ClassName(),"TH",2) )
141  {
142  //snprintf(name, buffersize, "%sScaled", h->GetName()) ;
143 
144  TH1 * hout = dynamic_cast<TH1*> (h);//(h->Clone(name)) ;
145 
146  if(hout)
147  {
148  hout->Sumw2();
149  hout->Scale(scale) ;
150  // fOutputList->Add(hout) ;
151  }// casting not null
152  }
153  //else fOutputList->Add(h) ;
154  }
155  }
156 
157  printf("\t ... end scaling, write ...\n");
158 
159  TFile * fout = new TFile(Form("%d/ScaledMerged.root",bin),"recreate");
160 
161  fout->Print("");
162 
163  list->Write();
164 
165  fout->Close();
166  delete fout;
167  f->Close();
168  delete f;
169  delete h;
170 
171  printf("\t ... done.\n");
172 
173 }
double Double_t
Definition: External.C:58
TList * list
TDirectory file where lists per trigger are stored in train ouput.
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