]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliCollisionNormalizationTask.cxx
New version of the QAtrain.C macro to run in 2012 productions (Mihaela)
[u/mrichter/AliRoot.git] / ANALYSIS / AliCollisionNormalizationTask.cxx
1 /* $Id$ */
2
3
4 // Simple task to test the collision normalization. Can be called for
5 // both MC and data and shows how to fill the collision normalization
6 // class
7 //
8 // Author: Michele Floris
9 //         CERN
10
11
12 #include "AliCollisionNormalizationTask.h"
13
14 #include <TFile.h>
15 #include <TH1F.h>
16 #include <TH2F.h>
17
18 #include <AliLog.h>
19 #include <AliESDEvent.h>
20 #include <AliHeader.h>
21
22 #include "AliCollisionNormalization.h"
23 #include "AliAnalysisManager.h"
24 #include "AliInputEventHandler.h"
25
26 //#include "AliBackgroundSelection.h"
27 #include "AliMultiplicity.h"
28 #include "AliMCEvent.h"
29
30 ClassImp(AliCollisionNormalizationTask)
31
32 AliCollisionNormalizationTask::AliCollisionNormalizationTask() :
33   AliAnalysisTaskSE("AliCollisionNormalizationTask"),
34   fOutput(0),
35   fIsMC(0),
36   fCollisionNormalization(0)
37 {
38   //
39   // Default event handler
40   //
41
42   // Define input and output slots here
43   DefineOutput(1, TList::Class());
44   
45 }
46
47 AliCollisionNormalizationTask::AliCollisionNormalizationTask(const char* name) :
48   AliAnalysisTaskSE(name),
49   fOutput(0),
50   fIsMC(0),
51   fCollisionNormalization(new AliCollisionNormalization())
52 {
53   //
54   // Constructor. Initialization of pointers
55   //
56
57   // Define input and output slots here
58   DefineOutput(1, TList::Class());
59   
60   //  AliLog::SetClassDebugLevel("AliCollisionNormalizationTask", AliLog::kWarning);
61 }
62
63 AliCollisionNormalizationTask::~AliCollisionNormalizationTask()
64 {
65   //
66   // Destructor
67   //
68
69   // histograms are in the output list and deleted when the output
70   // list is deleted by the TSelector dtor
71
72   if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
73     delete fOutput;
74     fOutput = 0;
75   }
76 }
77
78 void AliCollisionNormalizationTask::UserCreateOutputObjects()
79 {
80   // create result objects and add to output list
81
82   Printf("AliCollisionNormalizationTask::CreateOutputObjects");
83
84   fOutput = new TList;
85   fOutput->SetOwner();
86   
87   if (!fCollisionNormalization)
88     fCollisionNormalization = new AliCollisionNormalization;
89   
90   fOutput->Add(fCollisionNormalization);
91 //   fOutput->Add(fCollisionNormalization->GetVzCorrZeroBin ());
92 //   fOutput->Add(fCollisionNormalization->GetVzMCGen       ());
93 //   fOutput->Add(fCollisionNormalization->GetVzMCRec       ());
94 //   fOutput->Add(fCollisionNormalization->GetVzMCTrg       ());
95 //   fOutput->Add(fCollisionNormalization->GetVzData        ());
96 //   fOutput->Add(fCollisionNormalization->GetNEvents       ());
97 //   fOutput->Add(fCollisionNormalization->GetStatBin0      ());
98
99 }
100
101 void AliCollisionNormalizationTask::UserExec(Option_t*)
102 {
103   // process the event
104
105
106   PostData(1, fOutput);
107
108   // Get the ESD
109   AliESDEvent * aESD = dynamic_cast<AliESDEvent*>(fInputEvent);
110   if(!aESD) {
111     AliFatal("Cannot get ESD");
112   }
113   if (strcmp(aESD->ClassName(),"AliESDEvent")) {
114     AliFatal("Not processing ESDs");
115   }
116   // Get MC event, if needed
117   AliMCEvent* mcEvent = fIsMC ? MCEvent() : 0;
118   if (!mcEvent && fIsMC){
119     AliFatal("Running on MC but no MC handler available");
120   }
121
122   // Physics selection. At least in the case of MC we cannot use
123   // yourTask->SelectCollisionCandidates();, because we also need to
124   // fill the "generated" histogram 
125   // NB never call IsEventSelected more than once per event
126   // (statistics histogram would be altered)
127
128   // FIXME: using only MB events, foresee more events?
129   Bool_t isSelected = (((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected() & AliVEvent::kMB);
130
131   // Get the Multiplicity cut
132   const AliMultiplicity* mult = aESD->GetMultiplicity();
133   if (!mult){
134     AliError("Can't get mult object");
135     return;
136   }
137
138   // Check if the event is "reconstructed" according to some quality
139   // cuts. Tipically, we mean "it has a good-eonugh vertex"
140
141   Int_t ntracklet = mult->GetNumberOfTracklets();
142   const AliESDVertex * vtxESD = aESD->GetPrimaryVertexSPD();
143   if (IsEventInBinZero()) {
144     ntracklet = 0;
145     vtxESD    = 0;
146   }
147   
148   if (ntracklet > 0 && !vtxESD) {
149     AliError("No vertex but reconstructed tracklets?");
150   }
151
152   // assign vz. For MC we use generated vz
153   Float_t vz = 0;
154   if (!fIsMC) vz = vtxESD ? vtxESD->GetZ() : 0; // FIXME : is zv used anywhere in Gen?
155   else        vz = mcEvent->GetPrimaryVertex()->GetZ();
156
157   if (fIsMC) {
158     // Monte Carlo:  we fill 3 histos
159     if (!isSelected || !vtxESD) ntracklet = 0; //If the event does not pass the physics selection or is not rec, it goes in the bin0
160     fCollisionNormalization->FillVzMCGen(vz, ntracklet, mcEvent);      
161     // If triggered == passing the physics selection
162     if (isSelected) {
163       fCollisionNormalization->FillVzMCTrg(vz, ntracklet, mcEvent);
164       // If reconstructer == good enough vertex
165       if (vtxESD) fCollisionNormalization->FillVzMCRec(vz, ntracklet, mcEvent);    
166     }
167   } else {
168     if (isSelected) {
169       // Passing the trigger
170       fCollisionNormalization->FillVzData(vz,ntracklet);
171     }
172   }
173
174 }
175
176 void AliCollisionNormalizationTask::Terminate(Option_t *)
177 {
178   // The Terminate() function is the last function to be called during
179   // a query. It always runs on the client, it can be used to present
180   // the results graphically or save the results to file.
181
182   fOutput = dynamic_cast<TList*> (GetOutputData(1));
183   if (!fOutput)
184     Printf("ERROR: fOutput not available");
185
186
187 }
188
189 Bool_t AliCollisionNormalizationTask::IsEventInBinZero() {
190
191   // Returns true if an event is to be assigned to the zero bin
192   //
193   // You should have your own version of this method in the class: in
194   // general, the definition of "reconstructed" event is subjective.
195
196   Bool_t isZeroBin = kTRUE;
197   const AliESDEvent* esd= dynamic_cast<AliESDEvent*>(fInputEvent);
198   if (!esd){ 
199     Printf("AliCollisionNormalizationTask::IsEventInBinZero: Can't get ESD");
200     return kFALSE;   
201   }
202   const AliMultiplicity* mult = esd->GetMultiplicity();
203   if (!mult){
204     Printf("AliCollisionNormalizationTask::IsEventInBinZero: Can't get mult object");
205     return kFALSE;
206   }
207   Int_t ntracklet = mult->GetNumberOfTracklets();
208   const AliESDVertex * vtxESD = esd->GetPrimaryVertexSPD();
209   if(vtxESD) {
210     // If there is a vertex from vertexer z with delta phi > 0.02 we
211     // don't consider it rec (we keep the event in bin0). If quality
212     // is good eneough we check the number of tracklets
213     // if the vertex is more than 15 cm away, this is autamatically bin0
214     if( TMath::Abs(vtxESD->GetZ()) <= 15 ) {
215       if (vtxESD->IsFromVertexerZ()) {
216         if (vtxESD->GetDispersion()<=0.02 ) {
217           if(ntracklet>0) isZeroBin = kFALSE;
218         }
219       } else if(ntracklet>0) isZeroBin = kFALSE; // if the event is not from Vz we chek the n of tracklets
220     } 
221   }
222   return isZeroBin;
223
224 }