New class for normalization studies (Giacomo)
[u/mrichter/AliRoot.git] / PWG3 / vertexingHF / AliNormalizationCounter.cxx
CommitLineData
a96083b9 1#include "AliNormalizationCounter.h"
2#include <AliESDEvent.h>
3#include <AliESDtrack.h>
4#include <AliAODEvent.h>
5#include <AliVParticle.h>
6#include <AliTriggerAnalysis.h>
7#include <TH1F.h>
8#include <TH2D.h>
9#include <TList.h>
10#include <TString.h>
11#include <TCanvas.h>
12#include <AliPhysicsSelection.h>
13
14ClassImp(AliNormalizationCounter)
15
16//____________________________________________
17AliNormalizationCounter::AliNormalizationCounter():
18AliCounterCollection(),
19fESD(kFALSE)
20{
21 // empty constructor
22}
23
24//__________________________________________________
25AliNormalizationCounter::AliNormalizationCounter(const char *name):
26AliCounterCollection(name),
27fESD(kFALSE)
28{
29 //default constructor
30 AddRubric("Event","triggered/V0AND/Candles0.2/Candles0.25/Candles0.3/2xCandles0.2/PrimaryVTracks/PrimaryV/!V0A&Candle02/!V0A&Candle025/!V0A&Candle03/!V0A&PrimaryVTracks/!V0A&PrimaryV/!V0A&2xCandles02/Candid(Filter)/Candid(Analysis)/NCandid(Filter)/NCandid(Analysis)");//new line
31 AddRubric("Run", 10000000);//new line
32 Init();//new line
33}
34//______________________________________________
35AliNormalizationCounter::~AliNormalizationCounter()
36{
37 //destructor
38}
39
40
41//_______________________________________
42void AliNormalizationCounter::StoreEvent(AliVEvent *event,Bool_t mc){
43 //
44
45 Bool_t v0A=kFALSE;
46 Bool_t v0B=kFALSE;
47 Bool_t flag02=kFALSE;
48 Bool_t flag025=kFALSE;
49 Bool_t flag03=kFALSE;
50 Int_t flag0202=0;
51 Bool_t flagPV=kFALSE;
52 Bool_t flagPVT=kFALSE;
53
54 //Run Number
55 Int_t runNumber = event->GetRunNumber();
56
57 //Find CINT1B
58
59 AliESDEvent *eventESD = (AliESDEvent*)event;
60 if(!eventESD){AliError("ESD event not available");return;}
61 if(mc&&event->GetEventType() != 0)return;
62 //event must be either physics or MC
63 if(!(event->GetEventType() == 7||event->GetEventType() == 0))return;
64
65 Count(Form("Event:triggered/Run:%d",runNumber));
66
67 //Find V0AND
68 AliTriggerAnalysis trAn; /// Trigger Analysis
69 v0B = trAn.IsOfflineTriggerFired(eventESD , AliTriggerAnalysis::kV0C);
70 v0A = trAn.IsOfflineTriggerFired(eventESD , AliTriggerAnalysis::kV0A);
71 if(v0A&&v0B){Count(Form("Event:V0AND/Run:%d",runNumber));}
72
73 //Find Candle
74 Int_t trkEntries = (Int_t)event->GetNumberOfTracks();
75
76 for(Int_t i=0;i<trkEntries;i++){
77 AliAODTrack *track=(AliAODTrack*)event->GetTrack(i);
78 UShort_t nClusTPC=track->GetTPCNcls();
79 if((nClusTPC>=70)&&(track->GetStatus()&AliESDtrack::kITSrefit)&&(track->GetStatus()&AliESDtrack::kTPCrefit)){
80
81 if((track->Pt()>0.2)&&flag0202<2){
82 if(!flag02)Count(Form("Event:Candles0.2/Run:%d",runNumber));
83 flag02=kTRUE;
84 flag0202++;
85 }
86 if((track->Pt()>0.25)&&(!flag025)){
87 Count(Form("Event:Candles0.25/Run:%d",runNumber));
88 flag025=kTRUE;
89 }
90 if((track->Pt()>0.3)&&(!flag03)){
91 Count(Form("Event:Candles0.3/Run:%d",runNumber));
92 flag03=kTRUE;
93 }
94 }
95 if((flag02)&&(flag025)&&(flag03)&&flag0202>=2) break; //i=trkEntries+1;
96 }
97
98 //FindPrimary vertex
99 AliVVertex *vtrc = (AliVVertex*)event->GetPrimaryVertex();
100 if(vtrc && vtrc->GetNContributors()>0){
101 Count(Form("Event:PrimaryV/Run:%d",runNumber));
102 flagPV=kTRUE;
103 }
104
105 if(fESD){
106 const AliESDVertex *vtrc1 = eventESD->GetPrimaryVertexTracks();
107 if(vtrc1 && vtrc1->GetNContributors()>0){
108 Count(Form("Event:PrimaryVTracks/Run:%d",runNumber));
109 flagPVT=kTRUE;
110 }
111 }
112
113 if(!(v0A&&v0B)&&(flag02))Count(Form("Event:!V0A&Candle02/Run:%d",runNumber));
114 if(!(v0A&&v0B)&&(flag025))Count(Form("Event:!V0A&Candle025/Run:%d",runNumber));
115 if(!(v0A&&v0B)&&(flag03))Count(Form("Event:!V0A&Candle03/Run:%d",runNumber));
116 if(!(v0A&&v0B)&&flagPVT)Count(Form("Event:!V0A&PrimaryVTracks/Run:%d",runNumber));
117 if(!(v0A&&v0B)&&flagPV)Count(Form("Event:!V0A&PrimaryV/Run:%d",runNumber));
118 if(flag0202>1)Count(Form("Event:2xCandles0.2/Run:%d",runNumber));
119 if(!(v0A&&v0B)&&flag0202>1)Count(Form("Event:!V0A&2xCandles02/Run:%d",runNumber));
120
121 //delete eventESD;
122
123 return;
124}
125//_____________________________________________________________________
126void AliNormalizationCounter::StoreCandidates(AliVEvent *event,Int_t nCand,Bool_t flagFilter){
127 //
128
129 Int_t runNumber = event->GetRunNumber();
130 if(nCand==0)return;
131 if(flagFilter){
132 Count(Form("Event:Candid(Filter)/Run:%d",runNumber));
133 for(Int_t i=0;i<nCand;i++)Count(Form("Event:NCandid(Filter)/Run:%d",runNumber));
134 }else{
135 Count(Form("Event:Candid(Analysis)/Run:%d",runNumber));
136 for(Int_t i=0;i<nCand;i++)Count(Form("Event:NCandid(Analysis)/Run:%d",runNumber));
137 }
138 return;
139}
140//_______________________________________________________________________
141TH1D* AliNormalizationCounter::DrawAgainstRuns(TString candle="candid(filter)"){
142 //
143 TString selection;
144 selection.Form("event:%s",candle.Data());
145 TH2D* hist = Draw("event","run",selection.Data());
146 TH1D* histoneD =(TH1D*)(hist->ProjectionX()->Clone());
147 histoneD->DrawClone();
148 return histoneD;
149}
150//___________________________________________________________________________
151TH1D* AliNormalizationCounter::DrawRatio(TString candle1="candid(filter)",TString candle2="triggered"){
152 //
153 TString name;
154 name.Form("%s/%s",candle1.Data(),candle2.Data());
155 TH1D* num=(TH1D*)(DrawAgainstRuns(candle1.Data())->Clone(name.Data()));
156 TH1D* den=DrawAgainstRuns(candle2.Data());
157 den->SetTitle(candle2.Data());
158 den->SetName(candle2.Data());
159 printf("%f %f",num->GetEntries(),den->GetEntries());
160 num->Divide(num,den,1,1,"B");
161 num->DrawClone();
162 return num;
163}
164