set ownership of cuts container
[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
16//*************************************************************************
17// Class AliNormalizationCounter
18// Class to store the informations relevant for the normalization in the
19// barrel for each run
20// Authors: G. Ortona, ortona@to.infn.it
21// D. Caffarri, davide.caffarri@pd.to.infn.it
22// with many thanks to P. Pillot
23/////////////////////////////////////////////////////////////
24
a96083b9 25#include "AliNormalizationCounter.h"
26#include <AliESDEvent.h>
27#include <AliESDtrack.h>
28#include <AliAODEvent.h>
29#include <AliVParticle.h>
30#include <AliTriggerAnalysis.h>
31#include <TH1F.h>
e0fdfa52 32#include <TH2F.h>
a96083b9 33#include <TList.h>
34#include <TString.h>
35#include <TCanvas.h>
36#include <AliPhysicsSelection.h>
e0fdfa52 37#include <AliMultiplicity.h>
a96083b9 38
39ClassImp(AliNormalizationCounter)
40
41//____________________________________________
42AliNormalizationCounter::AliNormalizationCounter():
e0fdfa52 43TNamed(),
44fCounters(),
45fESD(kFALSE),
de1b82ff 46fRejectPileUp(kFALSE),
e0fdfa52 47fHistTrackFilterEvMult(0),
48fHistTrackAnaEvMult(0),
49fHistTrackFilterSpdMult(0),
50fHistTrackAnaSpdMult(0)
a96083b9 51{
52 // empty constructor
53}
54
55//__________________________________________________
56AliNormalizationCounter::AliNormalizationCounter(const char *name):
e0fdfa52 57TNamed(name,name),
58fCounters(name),
59fESD(kFALSE),
de1b82ff 60fRejectPileUp(kFALSE),
e0fdfa52 61fHistTrackFilterEvMult(0),
62fHistTrackAnaEvMult(0),
63fHistTrackFilterSpdMult(0),
64fHistTrackAnaSpdMult(0)
a96083b9 65{
66 //default constructor
de1b82ff 67 fCounters.AddRubric("Event","triggered/V0AND/PileUp/PbPbC0SMH-B-NOPF-ALLNOTRD/Candles0.2/Candles0.2spd1/Candles0.3/2xCandles0.2/CandleITSsa/Candle35clsTPC/PrimaryVTracks/PrimaryV/PrimaryVSPD/!V0A&Candle02/!V0A&Candle025/!V0A&Candle03/!V0A&PrimaryVTracks/!V0A&PrimaryV/!V0A&2xCandles02/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//_______________________________________
136void AliNormalizationCounter::StoreEvent(AliVEvent *event,Bool_t mc){
137 //
138
139 Bool_t v0A=kFALSE;
140 Bool_t v0B=kFALSE;
141 Bool_t flag02=kFALSE;
a96083b9 142 Bool_t flag03=kFALSE;
143 Int_t flag0202=0;
144 Bool_t flagPV=kFALSE;
145 Bool_t flagPVT=kFALSE;
e0fdfa52 146 Bool_t flag35cls=kFALSE;
147 Bool_t flagITSsa=kFALSE;
148 Bool_t flag02spd=kFALSE;
a96083b9 149
150 //Run Number
151 Int_t runNumber = event->GetRunNumber();
152
153 //Find CINT1B
a96083b9 154 AliESDEvent *eventESD = (AliESDEvent*)event;
155 if(!eventESD){AliError("ESD event not available");return;}
156 if(mc&&event->GetEventType() != 0)return;
157 //event must be either physics or MC
158 if(!(event->GetEventType() == 7||event->GetEventType() == 0))return;
159
e0fdfa52 160 fCounters.Count(Form("Event:triggered/Run:%d",runNumber));
a96083b9 161
162 //Find V0AND
163 AliTriggerAnalysis trAn; /// Trigger Analysis
164 v0B = trAn.IsOfflineTriggerFired(eventESD , AliTriggerAnalysis::kV0C);
165 v0A = trAn.IsOfflineTriggerFired(eventESD , AliTriggerAnalysis::kV0A);
e0fdfa52 166 if(v0A&&v0B){fCounters.Count(Form("Event:V0AND/Run:%d",runNumber));}
a96083b9 167
de1b82ff 168 //FindPrimary vertex
ea3defa4 169 AliAODEvent *eventAOD = (AliAODEvent*)event;
de1b82ff 170 AliVVertex *vtrc = (AliVVertex*)event->GetPrimaryVertex();
171 if(vtrc && vtrc->GetNContributors()>0){
172 fCounters.Count(Form("Event:PrimaryV/Run:%d",runNumber));
173 flagPV=kTRUE;
174 }
175
176 AliAODVertex *vrtcSPD = (AliAODVertex*)eventAOD->GetPrimaryVertexSPD();
177 if(vrtcSPD){
178 if(vrtcSPD->GetNContributors()>0)fCounters.Count(Form("Event:PrimaryVSPD/Run:%d",runNumber));
179 }
180
181 if(fESD){
182 const AliESDVertex *vtrc1 = eventESD->GetPrimaryVertexTracks();
183 if(vtrc1 && vtrc1->GetNContributors()>0){
184 fCounters.Count(Form("Event:PrimaryVTracks/Run:%d",runNumber));
185 flagPVT=kTRUE;
186 }
187 }
188
189 //trigger
190 TString trigclass=eventAOD->GetFiredTriggerClasses();
191 if(trigclass.Contains("C0SMH-B-NOPF-ALLNOTRD")||trigclass.Contains("C0SMH-B-NOPF-ALL"))fCounters.Count(Form("Event:PbPbC0SMH-B-NOPF-ALLNOTRD/Run:%d",runNumber));
192
193 //PileUp
194 if(eventAOD->IsPileupFromSPD()){
195 fCounters.Count(Form("Event:PileUp/Run:%d",runNumber));
196 if(fRejectPileUp==1)return;
197 }
ea3defa4 198
a96083b9 199 //Find Candle
200 Int_t trkEntries = (Int_t)event->GetNumberOfTracks();
201
202 for(Int_t i=0;i<trkEntries;i++){
203 AliAODTrack *track=(AliAODTrack*)event->GetTrack(i);
204 UShort_t nClusTPC=track->GetTPCNcls();
e0fdfa52 205 Int_t nSPD=0;
206 if(TESTBIT(track->GetITSClusterMap(),1))nSPD++;
207 if(TESTBIT(track->GetITSClusterMap(),0))nSPD++;
208 if(nClusTPC==0&&(track->GetStatus()&AliESDtrack::kITSrefit)&&!flagITSsa){
209 flagITSsa=kTRUE;
210 fCounters.Count(Form("Event:CandleITSsa/Run:%d",runNumber));
211 }
212 if((nClusTPC>=35)&&(track->GetStatus()&AliESDtrack::kITSrefit)&&(track->GetStatus()&AliESDtrack::kTPCrefit)&&(track->Pt()>0.2)&&(!flag35cls)){
213 fCounters.Count(Form("Event:Candle35clsTPC/Run:%d",runNumber));
214 flag35cls=kTRUE;
215 }
a96083b9 216 if((nClusTPC>=70)&&(track->GetStatus()&AliESDtrack::kITSrefit)&&(track->GetStatus()&AliESDtrack::kTPCrefit)){
217
218 if((track->Pt()>0.2)&&flag0202<2){
e0fdfa52 219 if(!flag02)fCounters.Count(Form("Event:Candles0.2/Run:%d",runNumber));
a96083b9 220 flag02=kTRUE;
221 flag0202++;
222 }
e0fdfa52 223 if((track->Pt()>0.2)&&!flag02spd&&nSPD>=1){
224 fCounters.Count(Form("Event:Candles0.2spd1/Run:%d",runNumber));
225 flag02spd=kTRUE;
a96083b9 226 }
227 if((track->Pt()>0.3)&&(!flag03)){
e0fdfa52 228 fCounters.Count(Form("Event:Candles0.3/Run:%d",runNumber));
a96083b9 229 flag03=kTRUE;
230 }
231 }
e0fdfa52 232 if((flag02)&&(flag03)&&flag0202>=2&&flag35cls&&flagITSsa) break;
a96083b9 233 }
234
e0fdfa52 235 if(!(v0A&&v0B)&&(flag02))fCounters.Count(Form("Event:!V0A&Candle02/Run:%d",runNumber));
236 if(!(v0A&&v0B)&&(flag03))fCounters.Count(Form("Event:!V0A&Candle03/Run:%d",runNumber));
237 if(!(v0A&&v0B)&&flagPVT)fCounters.Count(Form("Event:!V0A&PrimaryVTracks/Run:%d",runNumber));
238 if(!(v0A&&v0B)&&flagPV)fCounters.Count(Form("Event:!V0A&PrimaryV/Run:%d",runNumber));
239 if(flag0202>1)fCounters.Count(Form("Event:2xCandles0.2/Run:%d",runNumber));
240 if(!(v0A&&v0B)&&flag0202>1)fCounters.Count(Form("Event:!V0A&2xCandles02/Run:%d",runNumber));
a96083b9 241
242 //delete eventESD;
243
244 return;
245}
246//_____________________________________________________________________
247void AliNormalizationCounter::StoreCandidates(AliVEvent *event,Int_t nCand,Bool_t flagFilter){
e0fdfa52 248
249 Int_t ntracks=event->GetNumberOfTracks();
de1b82ff 250 if(flagFilter)fHistTrackFilterEvMult->Fill(ntracks,nCand);
251 else fHistTrackAnaEvMult->Fill(ntracks,nCand);
e0fdfa52 252 Int_t nSPD=0;
253 if(fESD){
254 AliESDEvent *ESDevent=(AliESDEvent*)event;
255 const AliMultiplicity *alimult = ESDevent->GetMultiplicity();
256 nSPD = alimult->GetNumberOfTracklets();
a96083b9 257
e0fdfa52 258 }else{
259 AliAODEvent *aodEvent =(AliAODEvent*)event;
260 AliAODTracklets *trklets=aodEvent->GetTracklets();
261 nSPD = trklets->GetNumberOfTracklets();
262 }
de1b82ff 263 if(flagFilter)fHistTrackFilterSpdMult->Fill(nSPD,nCand);
264 else fHistTrackAnaSpdMult->Fill(nSPD,nCand);
e0fdfa52 265
a96083b9 266 Int_t runNumber = event->GetRunNumber();
267 if(nCand==0)return;
268 if(flagFilter){
e0fdfa52 269 fCounters.Count(Form("Event:Candid(Filter)/Run:%d",runNumber));
270 for(Int_t i=0;i<nCand;i++)fCounters.Count(Form("Event:NCandid(Filter)/Run:%d",runNumber));
a96083b9 271 }else{
e0fdfa52 272 fCounters.Count(Form("Event:Candid(Analysis)/Run:%d",runNumber));
273 for(Int_t i=0;i<nCand;i++)fCounters.Count(Form("Event:NCandid(Analysis)/Run:%d",runNumber));
a96083b9 274 }
275 return;
276}
277//_______________________________________________________________________
e0fdfa52 278TH1D* AliNormalizationCounter::DrawAgainstRuns(TString candle,Bool_t drawHist){
a96083b9 279 //
e0fdfa52 280 fCounters.SortRubric("Run");
a96083b9 281 TString selection;
282 selection.Form("event:%s",candle.Data());
de1b82ff 283 TH1D* histoneD = fCounters.Get("run",selection.Data());
284
ea3defa4 285 histoneD->Sumw2();
e0fdfa52 286 if(drawHist)histoneD->DrawClone();
a96083b9 287 return histoneD;
288}
289//___________________________________________________________________________
e0fdfa52 290TH1D* AliNormalizationCounter::DrawRatio(TString candle1,TString candle2){
a96083b9 291 //
e0fdfa52 292 fCounters.SortRubric("Run");
a96083b9 293 TString name;
de1b82ff 294
a96083b9 295 name.Form("%s/%s",candle1.Data(),candle2.Data());
de1b82ff 296 TH1D* num=DrawAgainstRuns(candle1.Data(),kFALSE);
e0fdfa52 297 TH1D* den=DrawAgainstRuns(candle2.Data(),kFALSE);
de1b82ff 298
a96083b9 299 den->SetTitle(candle2.Data());
300 den->SetName(candle2.Data());
a96083b9 301 num->Divide(num,den,1,1,"B");
de1b82ff 302 num->SetTitle(name.Data());
303 num->SetName(name.Data());
a96083b9 304 num->DrawClone();
305 return num;
306}
e0fdfa52 307//___________________________________________________________________________
308void AliNormalizationCounter::PrintRubrics(){
309 fCounters.PrintKeyWords();
310}
311//___________________________________________________________________________
312Double_t AliNormalizationCounter::GetSum(TString candle){
313 TString selection="event:";
314 selection.Append(candle);
315 return fCounters.GetSum(selection.Data());
316}
317//___________________________________________________________________________
318TH2F* AliNormalizationCounter::GetHist(Bool_t filtercuts,Bool_t spdtracklets,Bool_t drawHist){
319 if(filtercuts){
320 if(spdtracklets){
321 if(drawHist)fHistTrackFilterSpdMult->DrawCopy("LEGO2Z 0");
322 return fHistTrackFilterSpdMult;
323 }else{
324 if(drawHist)fHistTrackFilterEvMult->DrawCopy("LEGO2Z 0");
325 return fHistTrackFilterEvMult;
326 }
327 }else{
328 if(spdtracklets){
329 if(drawHist)fHistTrackAnaSpdMult->DrawCopy("LEGO2Z 0");
330 return fHistTrackAnaSpdMult;
331 }else{
332 if(drawHist)fHistTrackAnaEvMult->DrawCopy("LEGO2Z 0");
333 return fHistTrackAnaEvMult;
334 }
335 }
336}