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