Added LHC10h run list for flow analysis (Giacomo)
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliNormalizationCounter.cxx
CommitLineData
e0fdfa52 1/**************************************************************************
2 * Copyright(c) 1998-2008, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
27de2dfb 16/* $Id$ */
17
e0fdfa52 18//*************************************************************************
19// Class AliNormalizationCounter
20// Class to store the informations relevant for the normalization in the
21// barrel for each run
22// Authors: G. Ortona, ortona@to.infn.it
23// D. Caffarri, davide.caffarri@pd.to.infn.it
24// with many thanks to P. Pillot
25/////////////////////////////////////////////////////////////
26
a96083b9 27#include "AliNormalizationCounter.h"
28#include <AliESDEvent.h>
29#include <AliESDtrack.h>
30#include <AliAODEvent.h>
31#include <AliVParticle.h>
32#include <AliTriggerAnalysis.h>
33#include <TH1F.h>
e0fdfa52 34#include <TH2F.h>
a96083b9 35#include <TList.h>
36#include <TString.h>
37#include <TCanvas.h>
38#include <AliPhysicsSelection.h>
e0fdfa52 39#include <AliMultiplicity.h>
a96083b9 40
41ClassImp(AliNormalizationCounter)
42
43//____________________________________________
44AliNormalizationCounter::AliNormalizationCounter():
e0fdfa52 45TNamed(),
46fCounters(),
47fESD(kFALSE),
48fHistTrackFilterEvMult(0),
49fHistTrackAnaEvMult(0),
50fHistTrackFilterSpdMult(0),
51fHistTrackAnaSpdMult(0)
a96083b9 52{
53 // empty constructor
54}
55
56//__________________________________________________
57AliNormalizationCounter::AliNormalizationCounter(const char *name):
e0fdfa52 58TNamed(name,name),
59fCounters(name),
60fESD(kFALSE),
61fHistTrackFilterEvMult(0),
62fHistTrackAnaEvMult(0),
63fHistTrackFilterSpdMult(0),
64fHistTrackAnaSpdMult(0)
a96083b9 65{
66 //default constructor
1879baec 67 fCounters.AddRubric("Event","triggered/V0AND/PileUp/PbPbC0SMH-B-NOPF-ALLNOTRD/Candles0.3/PrimaryV/countForNorm/noPrimaryV/zvtxGT10/!V0A&Candle03/!V0A&PrimaryV/Candid(Filter)/Candid(Analysis)/NCandid(Filter)/NCandid(Analysis)");
e0fdfa52 68 fCounters.AddRubric("Run", 1000000);
69 fCounters.Init();
de1b82ff 70 fHistTrackFilterEvMult=new TH2F("FiltCandidvsTracksinEv","FiltCandidvsTracksinEv",10000,-0.5,9999.5,200,-0.5,199.5);
71 fHistTrackFilterEvMult->GetYaxis()->SetTitle("NCandidates");
72 fHistTrackFilterEvMult->GetXaxis()->SetTitle("NTracksinEvent");
73 fHistTrackAnaEvMult=new TH2F("AnaCandidvsTracksinEv","AnaCandidvsTracksinEv",10000,-0.5,9999.5,100,-0.5,99.5);
74 fHistTrackAnaEvMult->GetYaxis()->SetTitle("NCandidates");
75 fHistTrackAnaEvMult->GetXaxis()->SetTitle("NTracksinEvent");
76 fHistTrackFilterSpdMult=new TH2F("FilterCandidvsSpdMult","FilterCandidvsSpdMult",5000,-0.5,4999.5,200,-0.5,199.5);
77 fHistTrackFilterSpdMult->GetYaxis()->SetTitle("NCandidates");
78 fHistTrackFilterSpdMult->GetXaxis()->SetTitle("NSPDTracklets");
79 fHistTrackAnaSpdMult=new TH2F("AnaCandidvsSpdMult","AnaCandidvsSpdMult",5000,-0.5,4999.5,100,-0.5,99.5);
80 fHistTrackAnaSpdMult->GetYaxis()->SetTitle("NCandidates");
81 fHistTrackAnaSpdMult->GetXaxis()->SetTitle("NSPDTracklets");
a96083b9 82}
83//______________________________________________
84AliNormalizationCounter::~AliNormalizationCounter()
85{
86 //destructor
e0fdfa52 87 if(fHistTrackFilterEvMult){
88 delete fHistTrackFilterEvMult;
89 fHistTrackFilterEvMult =0;
90 }
91 if(fHistTrackAnaEvMult){
92 delete fHistTrackAnaEvMult;
93 fHistTrackAnaEvMult=0;
94 }
95 if(fHistTrackFilterSpdMult){
96 delete fHistTrackFilterSpdMult;
97 fHistTrackFilterSpdMult=0;
98 }
99 if(fHistTrackAnaSpdMult){
100 delete fHistTrackAnaSpdMult;
101 fHistTrackAnaSpdMult=0;
102 }
a96083b9 103}
104
e0fdfa52 105//______________________________________________
106Long64_t AliNormalizationCounter::Merge(TCollection* list){
107 if (!list) return 0;
108 if (list->IsEmpty()) return 0;//(Long64_t)fCounters.Merge(list);
109
110 TIter next(list);
111 const TObject* obj = 0x0;
112 while ((obj = next())) {
113
114 // check that "obj" is an object of the class AliNormalizationCounter
115 const AliNormalizationCounter* counter = dynamic_cast<const AliNormalizationCounter*>(obj);
116 if (!counter) {
117 AliError(Form("object named %s is not AliNormalizationCounter! Skipping it.", counter->GetName()));
118 continue;
119 }
120
121 Add(counter);
a96083b9 122
e0fdfa52 123 }
124
125 return (Long64_t)1;//(Long64_t)fCounters->GetEntries();
126}
127//_______________________________________
128void AliNormalizationCounter::Add(const AliNormalizationCounter *norm){
129 fCounters.Add(&(norm->fCounters));
130 fHistTrackFilterEvMult->Add(norm->fHistTrackFilterEvMult);
131 fHistTrackAnaEvMult->Add(norm->fHistTrackAnaEvMult);
132 fHistTrackFilterSpdMult->Add(norm->fHistTrackFilterSpdMult);
133 fHistTrackAnaSpdMult->Add(norm->fHistTrackAnaSpdMult);
134}
a96083b9 135//_______________________________________
1879baec 136/*
137Stores the variables used for normalization as function of run number
138returns kTRUE if the event is to be counted for normalization
139(pass event selection cuts OR has no primary vertex)
140 */
141void AliNormalizationCounter::StoreEvent(AliVEvent *event,AliRDHFCuts *rdCut,Bool_t mc){
a96083b9 142 //
143
144 Bool_t v0A=kFALSE;
145 Bool_t v0B=kFALSE;
a96083b9 146 Bool_t flag03=kFALSE;
a96083b9 147 Bool_t flagPV=kFALSE;
a96083b9 148
149 //Run Number
150 Int_t runNumber = event->GetRunNumber();
151
152 //Find CINT1B
a96083b9 153 AliESDEvent *eventESD = (AliESDEvent*)event;
154 if(!eventESD){AliError("ESD event not available");return;}
155 if(mc&&event->GetEventType() != 0)return;
156 //event must be either physics or MC
157 if(!(event->GetEventType() == 7||event->GetEventType() == 0))return;
158
e0fdfa52 159 fCounters.Count(Form("Event:triggered/Run:%d",runNumber));
1879baec 160
a96083b9 161 //Find V0AND
162 AliTriggerAnalysis trAn; /// Trigger Analysis
163 v0B = trAn.IsOfflineTriggerFired(eventESD , AliTriggerAnalysis::kV0C);
164 v0A = trAn.IsOfflineTriggerFired(eventESD , AliTriggerAnalysis::kV0A);
e0fdfa52 165 if(v0A&&v0B){fCounters.Count(Form("Event:V0AND/Run:%d",runNumber));}
a96083b9 166
1879baec 167 //FindPrimary vertex
168 // AliVVertex *vtrc = (AliVVertex*)event->GetPrimaryVertex();
169 // if(vtrc && vtrc->GetNContributors()>0){
170 // fCounters.Count(Form("Event:PrimaryV/Run:%d",runNumber));
171 // flagPV=kTRUE;
172 // }
de1b82ff 173
174 //trigger
1879baec 175 AliAODEvent *eventAOD = (AliAODEvent*)event;
de1b82ff 176 TString trigclass=eventAOD->GetFiredTriggerClasses();
177 if(trigclass.Contains("C0SMH-B-NOPF-ALLNOTRD")||trigclass.Contains("C0SMH-B-NOPF-ALL"))fCounters.Count(Form("Event:PbPbC0SMH-B-NOPF-ALLNOTRD/Run:%d",runNumber));
178
1879baec 179 //FindPrimary vertex
180 if(rdCut->IsEventSelected(event)){
181 fCounters.Count(Form("Event:PrimaryV/Run:%d",runNumber));
182 flagPV=kTRUE;
183 }else{
184 if(rdCut->GetWhyRejection()==0)fCounters.Count(Form("Event:noPrimaryV/Run:%d",runNumber));
185 //find good vtx outside range
186 if(rdCut->GetWhyRejection()==6){
187 fCounters.Count(Form("Event:zvtxGT10/Run:%d",runNumber));
188 fCounters.Count(Form("Event:PrimaryV/Run:%d",runNumber));
189 flagPV=kTRUE;
190 }
191 if(rdCut->GetWhyRejection()==1)fCounters.Count(Form("Event:PileUp/Run:%d",runNumber));
de1b82ff 192 }
1879baec 193 //to be counted for normalization
194 if(rdCut->CountEventForNormalization())fCounters.Count(Form("Event:countForNorm/Run:%d",runNumber));
195
ea3defa4 196
a96083b9 197 //Find Candle
198 Int_t trkEntries = (Int_t)event->GetNumberOfTracks();
1879baec 199 for(Int_t i=0;i<trkEntries&&!flag03;i++){
a96083b9 200 AliAODTrack *track=(AliAODTrack*)event->GetTrack(i);
1879baec 201 if((track->Pt()>0.3)&&(!flag03)){
202 fCounters.Count(Form("Event:Candles0.3/Run:%d",runNumber));
203 flag03=kTRUE;
204 break;
e0fdfa52 205 }
a96083b9 206 }
207
e0fdfa52 208 if(!(v0A&&v0B)&&(flag03))fCounters.Count(Form("Event:!V0A&Candle03/Run:%d",runNumber));
e0fdfa52 209 if(!(v0A&&v0B)&&flagPV)fCounters.Count(Form("Event:!V0A&PrimaryV/Run:%d",runNumber));
a96083b9 210
a96083b9 211 return;
212}
213//_____________________________________________________________________
214void AliNormalizationCounter::StoreCandidates(AliVEvent *event,Int_t nCand,Bool_t flagFilter){
e0fdfa52 215
216 Int_t ntracks=event->GetNumberOfTracks();
de1b82ff 217 if(flagFilter)fHistTrackFilterEvMult->Fill(ntracks,nCand);
218 else fHistTrackAnaEvMult->Fill(ntracks,nCand);
e0fdfa52 219 Int_t nSPD=0;
220 if(fESD){
221 AliESDEvent *ESDevent=(AliESDEvent*)event;
222 const AliMultiplicity *alimult = ESDevent->GetMultiplicity();
223 nSPD = alimult->GetNumberOfTracklets();
a96083b9 224
e0fdfa52 225 }else{
226 AliAODEvent *aodEvent =(AliAODEvent*)event;
227 AliAODTracklets *trklets=aodEvent->GetTracklets();
228 nSPD = trklets->GetNumberOfTracklets();
229 }
de1b82ff 230 if(flagFilter)fHistTrackFilterSpdMult->Fill(nSPD,nCand);
231 else fHistTrackAnaSpdMult->Fill(nSPD,nCand);
e0fdfa52 232
a96083b9 233 Int_t runNumber = event->GetRunNumber();
234 if(nCand==0)return;
235 if(flagFilter){
e0fdfa52 236 fCounters.Count(Form("Event:Candid(Filter)/Run:%d",runNumber));
237 for(Int_t i=0;i<nCand;i++)fCounters.Count(Form("Event:NCandid(Filter)/Run:%d",runNumber));
a96083b9 238 }else{
e0fdfa52 239 fCounters.Count(Form("Event:Candid(Analysis)/Run:%d",runNumber));
240 for(Int_t i=0;i<nCand;i++)fCounters.Count(Form("Event:NCandid(Analysis)/Run:%d",runNumber));
a96083b9 241 }
242 return;
243}
244//_______________________________________________________________________
e0fdfa52 245TH1D* AliNormalizationCounter::DrawAgainstRuns(TString candle,Bool_t drawHist){
a96083b9 246 //
e0fdfa52 247 fCounters.SortRubric("Run");
a96083b9 248 TString selection;
249 selection.Form("event:%s",candle.Data());
de1b82ff 250 TH1D* histoneD = fCounters.Get("run",selection.Data());
251
ea3defa4 252 histoneD->Sumw2();
e0fdfa52 253 if(drawHist)histoneD->DrawClone();
a96083b9 254 return histoneD;
255}
256//___________________________________________________________________________
e0fdfa52 257TH1D* AliNormalizationCounter::DrawRatio(TString candle1,TString candle2){
a96083b9 258 //
e0fdfa52 259 fCounters.SortRubric("Run");
a96083b9 260 TString name;
de1b82ff 261
a96083b9 262 name.Form("%s/%s",candle1.Data(),candle2.Data());
de1b82ff 263 TH1D* num=DrawAgainstRuns(candle1.Data(),kFALSE);
e0fdfa52 264 TH1D* den=DrawAgainstRuns(candle2.Data(),kFALSE);
de1b82ff 265
a96083b9 266 den->SetTitle(candle2.Data());
267 den->SetName(candle2.Data());
a96083b9 268 num->Divide(num,den,1,1,"B");
de1b82ff 269 num->SetTitle(name.Data());
270 num->SetName(name.Data());
a96083b9 271 num->DrawClone();
272 return num;
273}
e0fdfa52 274//___________________________________________________________________________
275void AliNormalizationCounter::PrintRubrics(){
276 fCounters.PrintKeyWords();
277}
278//___________________________________________________________________________
279Double_t AliNormalizationCounter::GetSum(TString candle){
280 TString selection="event:";
281 selection.Append(candle);
282 return fCounters.GetSum(selection.Data());
283}
284//___________________________________________________________________________
285TH2F* AliNormalizationCounter::GetHist(Bool_t filtercuts,Bool_t spdtracklets,Bool_t drawHist){
286 if(filtercuts){
287 if(spdtracklets){
288 if(drawHist)fHistTrackFilterSpdMult->DrawCopy("LEGO2Z 0");
289 return fHistTrackFilterSpdMult;
290 }else{
291 if(drawHist)fHistTrackFilterEvMult->DrawCopy("LEGO2Z 0");
292 return fHistTrackFilterEvMult;
293 }
294 }else{
295 if(spdtracklets){
296 if(drawHist)fHistTrackAnaSpdMult->DrawCopy("LEGO2Z 0");
297 return fHistTrackAnaSpdMult;
298 }else{
299 if(drawHist)fHistTrackAnaEvMult->DrawCopy("LEGO2Z 0");
300 return fHistTrackAnaEvMult;
301 }
302 }
303}
1879baec 304//___________________________________________________________________________
305Double_t AliNormalizationCounter::GetNEventsForNorm(){
306 Double_t noVtxzGT10=GetSum("noPrimaryV")*GetSum("zvtxGT10")/GetSum("PrimaryV");
307 return GetSum("countForNorm")-noVtxzGT10;
308}
309//___________________________________________________________________________
310Double_t AliNormalizationCounter::GetNEventsForNorm(Int_t runnumber){
311 TString listofruns = fCounters.GetKeyWords("RUN");
312 if(!listofruns.Contains(Form("%d",runnumber))){
313 printf("WARNING: %d is not a valid run number\n",runnumber);
314 fCounters.Print("Run","",kTRUE);
315 return 0.;
316 }
317 TString suffix;suffix.Form("/RUN:%d",runnumber);
318 TString zvtx;zvtx.Form("zvtxGT10%s",suffix.Data());
319 TString noPV;noPV.Form("noPrimaryV%s",suffix.Data());
320 TString pV;pV.Form("PrimaryV%s",suffix.Data());
321 TString tbc;tbc.Form("countForNorm%s",suffix.Data());
322 Double_t noVtxzGT10=GetSum(noPV.Data())*GetSum(zvtx.Data())/GetSum(pV.Data());
323 return GetSum(tbc.Data())-noVtxzGT10;
324}
325//___________________________________________________________________________
fc9bad91 326TH1D* AliNormalizationCounter::DrawNEventsForNorm(Bool_t drawRatio){
1879baec 327 //usare algebra histos
328 fCounters.SortRubric("Run");
329 TString selection;
330
331 selection.Form("event:noPrimaryV");
332 TH1D* hnoPrimV = fCounters.Get("run",selection.Data());
333 hnoPrimV->Sumw2();
334
335 selection.Form("event:zvtxGT10");
336 TH1D* hzvtx= fCounters.Get("run",selection.Data());
337 hzvtx->Sumw2();
338
339 selection.Form("event:PrimaryV");
340 TH1D* hPrimV = fCounters.Get("run",selection.Data());
341 hPrimV->Sumw2();
342
343 hzvtx->Multiply(hnoPrimV);
344 hzvtx->Divide(hPrimV);
1879baec 345
346 selection.Form("event:countForNorm");
347 TH1D* hCountForNorm = fCounters.Get("run",selection.Data());
348 hCountForNorm->Sumw2();
349
fc9bad91 350 hCountForNorm->Add(hzvtx,-1.);
1879baec 351
fc9bad91 352 if(drawRatio){
353 selection.Form("event:triggered");
354 TH1D* htriggered = fCounters.Get("run",selection.Data());
355 htriggered->Sumw2();
356 hCountForNorm->Divide(htriggered);
357 }
1879baec 358
359 hCountForNorm->DrawClone();
360 return hCountForNorm;
361}