Added a prototype of V0 cut.
[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),
de1b82ff 48fRejectPileUp(kFALSE),
e0fdfa52 49fHistTrackFilterEvMult(0),
50fHistTrackAnaEvMult(0),
51fHistTrackFilterSpdMult(0),
52fHistTrackAnaSpdMult(0)
a96083b9 53{
54 // empty constructor
55}
56
57//__________________________________________________
58AliNormalizationCounter::AliNormalizationCounter(const char *name):
e0fdfa52 59TNamed(name,name),
60fCounters(name),
61fESD(kFALSE),
de1b82ff 62fRejectPileUp(kFALSE),
e0fdfa52 63fHistTrackFilterEvMult(0),
64fHistTrackAnaEvMult(0),
65fHistTrackFilterSpdMult(0),
66fHistTrackAnaSpdMult(0)
a96083b9 67{
68 //default constructor
de1b82ff 69 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 70 fCounters.AddRubric("Run", 1000000);
71 fCounters.Init();
de1b82ff 72 fHistTrackFilterEvMult=new TH2F("FiltCandidvsTracksinEv","FiltCandidvsTracksinEv",10000,-0.5,9999.5,200,-0.5,199.5);
73 fHistTrackFilterEvMult->GetYaxis()->SetTitle("NCandidates");
74 fHistTrackFilterEvMult->GetXaxis()->SetTitle("NTracksinEvent");
75 fHistTrackAnaEvMult=new TH2F("AnaCandidvsTracksinEv","AnaCandidvsTracksinEv",10000,-0.5,9999.5,100,-0.5,99.5);
76 fHistTrackAnaEvMult->GetYaxis()->SetTitle("NCandidates");
77 fHistTrackAnaEvMult->GetXaxis()->SetTitle("NTracksinEvent");
78 fHistTrackFilterSpdMult=new TH2F("FilterCandidvsSpdMult","FilterCandidvsSpdMult",5000,-0.5,4999.5,200,-0.5,199.5);
79 fHistTrackFilterSpdMult->GetYaxis()->SetTitle("NCandidates");
80 fHistTrackFilterSpdMult->GetXaxis()->SetTitle("NSPDTracklets");
81 fHistTrackAnaSpdMult=new TH2F("AnaCandidvsSpdMult","AnaCandidvsSpdMult",5000,-0.5,4999.5,100,-0.5,99.5);
82 fHistTrackAnaSpdMult->GetYaxis()->SetTitle("NCandidates");
83 fHistTrackAnaSpdMult->GetXaxis()->SetTitle("NSPDTracklets");
a96083b9 84}
85//______________________________________________
86AliNormalizationCounter::~AliNormalizationCounter()
87{
88 //destructor
e0fdfa52 89 if(fHistTrackFilterEvMult){
90 delete fHistTrackFilterEvMult;
91 fHistTrackFilterEvMult =0;
92 }
93 if(fHistTrackAnaEvMult){
94 delete fHistTrackAnaEvMult;
95 fHistTrackAnaEvMult=0;
96 }
97 if(fHistTrackFilterSpdMult){
98 delete fHistTrackFilterSpdMult;
99 fHistTrackFilterSpdMult=0;
100 }
101 if(fHistTrackAnaSpdMult){
102 delete fHistTrackAnaSpdMult;
103 fHistTrackAnaSpdMult=0;
104 }
a96083b9 105}
106
e0fdfa52 107//______________________________________________
108Long64_t AliNormalizationCounter::Merge(TCollection* list){
109 if (!list) return 0;
110 if (list->IsEmpty()) return 0;//(Long64_t)fCounters.Merge(list);
111
112 TIter next(list);
113 const TObject* obj = 0x0;
114 while ((obj = next())) {
115
116 // check that "obj" is an object of the class AliNormalizationCounter
117 const AliNormalizationCounter* counter = dynamic_cast<const AliNormalizationCounter*>(obj);
118 if (!counter) {
119 AliError(Form("object named %s is not AliNormalizationCounter! Skipping it.", counter->GetName()));
120 continue;
121 }
122
123 Add(counter);
a96083b9 124
e0fdfa52 125 }
126
127 return (Long64_t)1;//(Long64_t)fCounters->GetEntries();
128}
129//_______________________________________
130void AliNormalizationCounter::Add(const AliNormalizationCounter *norm){
131 fCounters.Add(&(norm->fCounters));
132 fHistTrackFilterEvMult->Add(norm->fHistTrackFilterEvMult);
133 fHistTrackAnaEvMult->Add(norm->fHistTrackAnaEvMult);
134 fHistTrackFilterSpdMult->Add(norm->fHistTrackFilterSpdMult);
135 fHistTrackAnaSpdMult->Add(norm->fHistTrackAnaSpdMult);
136}
a96083b9 137//_______________________________________
138void AliNormalizationCounter::StoreEvent(AliVEvent *event,Bool_t mc){
139 //
140
141 Bool_t v0A=kFALSE;
142 Bool_t v0B=kFALSE;
143 Bool_t flag02=kFALSE;
a96083b9 144 Bool_t flag03=kFALSE;
145 Int_t flag0202=0;
146 Bool_t flagPV=kFALSE;
147 Bool_t flagPVT=kFALSE;
e0fdfa52 148 Bool_t flag35cls=kFALSE;
149 Bool_t flagITSsa=kFALSE;
150 Bool_t flag02spd=kFALSE;
a96083b9 151
152 //Run Number
153 Int_t runNumber = event->GetRunNumber();
154
155 //Find CINT1B
a96083b9 156 AliESDEvent *eventESD = (AliESDEvent*)event;
157 if(!eventESD){AliError("ESD event not available");return;}
158 if(mc&&event->GetEventType() != 0)return;
159 //event must be either physics or MC
160 if(!(event->GetEventType() == 7||event->GetEventType() == 0))return;
161
e0fdfa52 162 fCounters.Count(Form("Event:triggered/Run:%d",runNumber));
a96083b9 163
164 //Find V0AND
165 AliTriggerAnalysis trAn; /// Trigger Analysis
166 v0B = trAn.IsOfflineTriggerFired(eventESD , AliTriggerAnalysis::kV0C);
167 v0A = trAn.IsOfflineTriggerFired(eventESD , AliTriggerAnalysis::kV0A);
e0fdfa52 168 if(v0A&&v0B){fCounters.Count(Form("Event:V0AND/Run:%d",runNumber));}
a96083b9 169
de1b82ff 170 //FindPrimary vertex
ea3defa4 171 AliAODEvent *eventAOD = (AliAODEvent*)event;
de1b82ff 172 AliVVertex *vtrc = (AliVVertex*)event->GetPrimaryVertex();
173 if(vtrc && vtrc->GetNContributors()>0){
174 fCounters.Count(Form("Event:PrimaryV/Run:%d",runNumber));
175 flagPV=kTRUE;
176 }
177
178 AliAODVertex *vrtcSPD = (AliAODVertex*)eventAOD->GetPrimaryVertexSPD();
179 if(vrtcSPD){
180 if(vrtcSPD->GetNContributors()>0)fCounters.Count(Form("Event:PrimaryVSPD/Run:%d",runNumber));
181 }
182
183 if(fESD){
184 const AliESDVertex *vtrc1 = eventESD->GetPrimaryVertexTracks();
185 if(vtrc1 && vtrc1->GetNContributors()>0){
186 fCounters.Count(Form("Event:PrimaryVTracks/Run:%d",runNumber));
187 flagPVT=kTRUE;
188 }
189 }
190
191 //trigger
192 TString trigclass=eventAOD->GetFiredTriggerClasses();
193 if(trigclass.Contains("C0SMH-B-NOPF-ALLNOTRD")||trigclass.Contains("C0SMH-B-NOPF-ALL"))fCounters.Count(Form("Event:PbPbC0SMH-B-NOPF-ALLNOTRD/Run:%d",runNumber));
194
195 //PileUp
196 if(eventAOD->IsPileupFromSPD()){
197 fCounters.Count(Form("Event:PileUp/Run:%d",runNumber));
198 if(fRejectPileUp==1)return;
199 }
ea3defa4 200
a96083b9 201 //Find Candle
202 Int_t trkEntries = (Int_t)event->GetNumberOfTracks();
203
204 for(Int_t i=0;i<trkEntries;i++){
205 AliAODTrack *track=(AliAODTrack*)event->GetTrack(i);
206 UShort_t nClusTPC=track->GetTPCNcls();
e0fdfa52 207 Int_t nSPD=0;
208 if(TESTBIT(track->GetITSClusterMap(),1))nSPD++;
209 if(TESTBIT(track->GetITSClusterMap(),0))nSPD++;
210 if(nClusTPC==0&&(track->GetStatus()&AliESDtrack::kITSrefit)&&!flagITSsa){
211 flagITSsa=kTRUE;
212 fCounters.Count(Form("Event:CandleITSsa/Run:%d",runNumber));
213 }
214 if((nClusTPC>=35)&&(track->GetStatus()&AliESDtrack::kITSrefit)&&(track->GetStatus()&AliESDtrack::kTPCrefit)&&(track->Pt()>0.2)&&(!flag35cls)){
215 fCounters.Count(Form("Event:Candle35clsTPC/Run:%d",runNumber));
216 flag35cls=kTRUE;
217 }
a96083b9 218 if((nClusTPC>=70)&&(track->GetStatus()&AliESDtrack::kITSrefit)&&(track->GetStatus()&AliESDtrack::kTPCrefit)){
219
220 if((track->Pt()>0.2)&&flag0202<2){
e0fdfa52 221 if(!flag02)fCounters.Count(Form("Event:Candles0.2/Run:%d",runNumber));
a96083b9 222 flag02=kTRUE;
223 flag0202++;
224 }
e0fdfa52 225 if((track->Pt()>0.2)&&!flag02spd&&nSPD>=1){
226 fCounters.Count(Form("Event:Candles0.2spd1/Run:%d",runNumber));
227 flag02spd=kTRUE;
a96083b9 228 }
229 if((track->Pt()>0.3)&&(!flag03)){
e0fdfa52 230 fCounters.Count(Form("Event:Candles0.3/Run:%d",runNumber));
a96083b9 231 flag03=kTRUE;
232 }
233 }
e0fdfa52 234 if((flag02)&&(flag03)&&flag0202>=2&&flag35cls&&flagITSsa) break;
a96083b9 235 }
236
e0fdfa52 237 if(!(v0A&&v0B)&&(flag02))fCounters.Count(Form("Event:!V0A&Candle02/Run:%d",runNumber));
238 if(!(v0A&&v0B)&&(flag03))fCounters.Count(Form("Event:!V0A&Candle03/Run:%d",runNumber));
239 if(!(v0A&&v0B)&&flagPVT)fCounters.Count(Form("Event:!V0A&PrimaryVTracks/Run:%d",runNumber));
240 if(!(v0A&&v0B)&&flagPV)fCounters.Count(Form("Event:!V0A&PrimaryV/Run:%d",runNumber));
241 if(flag0202>1)fCounters.Count(Form("Event:2xCandles0.2/Run:%d",runNumber));
242 if(!(v0A&&v0B)&&flag0202>1)fCounters.Count(Form("Event:!V0A&2xCandles02/Run:%d",runNumber));
a96083b9 243
244 //delete eventESD;
245
246 return;
247}
248//_____________________________________________________________________
249void AliNormalizationCounter::StoreCandidates(AliVEvent *event,Int_t nCand,Bool_t flagFilter){
e0fdfa52 250
251 Int_t ntracks=event->GetNumberOfTracks();
de1b82ff 252 if(flagFilter)fHistTrackFilterEvMult->Fill(ntracks,nCand);
253 else fHistTrackAnaEvMult->Fill(ntracks,nCand);
e0fdfa52 254 Int_t nSPD=0;
255 if(fESD){
256 AliESDEvent *ESDevent=(AliESDEvent*)event;
257 const AliMultiplicity *alimult = ESDevent->GetMultiplicity();
258 nSPD = alimult->GetNumberOfTracklets();
a96083b9 259
e0fdfa52 260 }else{
261 AliAODEvent *aodEvent =(AliAODEvent*)event;
262 AliAODTracklets *trklets=aodEvent->GetTracklets();
263 nSPD = trklets->GetNumberOfTracklets();
264 }
de1b82ff 265 if(flagFilter)fHistTrackFilterSpdMult->Fill(nSPD,nCand);
266 else fHistTrackAnaSpdMult->Fill(nSPD,nCand);
e0fdfa52 267
a96083b9 268 Int_t runNumber = event->GetRunNumber();
269 if(nCand==0)return;
270 if(flagFilter){
e0fdfa52 271 fCounters.Count(Form("Event:Candid(Filter)/Run:%d",runNumber));
272 for(Int_t i=0;i<nCand;i++)fCounters.Count(Form("Event:NCandid(Filter)/Run:%d",runNumber));
a96083b9 273 }else{
e0fdfa52 274 fCounters.Count(Form("Event:Candid(Analysis)/Run:%d",runNumber));
275 for(Int_t i=0;i<nCand;i++)fCounters.Count(Form("Event:NCandid(Analysis)/Run:%d",runNumber));
a96083b9 276 }
277 return;
278}
279//_______________________________________________________________________
e0fdfa52 280TH1D* AliNormalizationCounter::DrawAgainstRuns(TString candle,Bool_t drawHist){
a96083b9 281 //
e0fdfa52 282 fCounters.SortRubric("Run");
a96083b9 283 TString selection;
284 selection.Form("event:%s",candle.Data());
de1b82ff 285 TH1D* histoneD = fCounters.Get("run",selection.Data());
286
ea3defa4 287 histoneD->Sumw2();
e0fdfa52 288 if(drawHist)histoneD->DrawClone();
a96083b9 289 return histoneD;
290}
291//___________________________________________________________________________
e0fdfa52 292TH1D* AliNormalizationCounter::DrawRatio(TString candle1,TString candle2){
a96083b9 293 //
e0fdfa52 294 fCounters.SortRubric("Run");
a96083b9 295 TString name;
de1b82ff 296
a96083b9 297 name.Form("%s/%s",candle1.Data(),candle2.Data());
de1b82ff 298 TH1D* num=DrawAgainstRuns(candle1.Data(),kFALSE);
e0fdfa52 299 TH1D* den=DrawAgainstRuns(candle2.Data(),kFALSE);
de1b82ff 300
a96083b9 301 den->SetTitle(candle2.Data());
302 den->SetName(candle2.Data());
a96083b9 303 num->Divide(num,den,1,1,"B");
de1b82ff 304 num->SetTitle(name.Data());
305 num->SetName(name.Data());
a96083b9 306 num->DrawClone();
307 return num;
308}
e0fdfa52 309//___________________________________________________________________________
310void AliNormalizationCounter::PrintRubrics(){
311 fCounters.PrintKeyWords();
312}
313//___________________________________________________________________________
314Double_t AliNormalizationCounter::GetSum(TString candle){
315 TString selection="event:";
316 selection.Append(candle);
317 return fCounters.GetSum(selection.Data());
318}
319//___________________________________________________________________________
320TH2F* AliNormalizationCounter::GetHist(Bool_t filtercuts,Bool_t spdtracklets,Bool_t drawHist){
321 if(filtercuts){
322 if(spdtracklets){
323 if(drawHist)fHistTrackFilterSpdMult->DrawCopy("LEGO2Z 0");
324 return fHistTrackFilterSpdMult;
325 }else{
326 if(drawHist)fHistTrackFilterEvMult->DrawCopy("LEGO2Z 0");
327 return fHistTrackFilterEvMult;
328 }
329 }else{
330 if(spdtracklets){
331 if(drawHist)fHistTrackAnaSpdMult->DrawCopy("LEGO2Z 0");
332 return fHistTrackAnaSpdMult;
333 }else{
334 if(drawHist)fHistTrackAnaEvMult->DrawCopy("LEGO2Z 0");
335 return fHistTrackAnaEvMult;
336 }
337 }
338}