]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ANALYSIS/AliCollisionNormalizationTask.cxx
Set status flag for TPC only tracks
[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   Bool_t isSelected = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
129
130   // Get the Multiplicity cut
131   const AliMultiplicity* mult = aESD->GetMultiplicity();
132   if (!mult){
133     AliError("Can't get mult object");
134     return;
135   }
136
137   // Check if the event is "reconstructed" according to some quality
138   // cuts. Tipically, we mean "it has a good-eonugh vertex"
139
140   Int_t ntracklet = mult->GetNumberOfTracklets();
141   const AliESDVertex * vtxESD = aESD->GetPrimaryVertexSPD();
142   if (IsEventInBinZero()) {
143     ntracklet = 0;
144     vtxESD    = 0;
145   }
146   
147   if (ntracklet > 0 && !vtxESD) {
148     AliError("No vertex but reconstructed tracklets?");
149   }
150
151   // assign vz. For MC we use generated vz
152   Float_t vz = 0;
153   if (!fIsMC) vz = vtxESD ? vtxESD->GetZ() : 0; // FIXME : is zv used anywhere in Gen?
154   else        vz = mcEvent->GetPrimaryVertex()->GetZ();
155
156   if (fIsMC) {
157     // Monte Carlo:  we fill 3 histos
158     if (!isSelected || !vtxESD) ntracklet = 0; //If the event does not pass the physics selection or is not rec, it goes in the bin0
159     fCollisionNormalization->FillVzMCGen(vz, ntracklet, mcEvent);      
160     // If triggered == passing the physics selection
161     if (isSelected) {
162       fCollisionNormalization->FillVzMCTrg(vz, ntracklet, mcEvent);
163       // If reconstructer == good enough vertex
164       if (vtxESD) fCollisionNormalization->FillVzMCRec(vz, ntracklet, mcEvent);    
165     }
166   } else {
167     if (isSelected) {
168       // Passing the trigger
169       fCollisionNormalization->FillVzData(vz,ntracklet);
170     }
171   }
172
173 }
174
175 void AliCollisionNormalizationTask::Terminate(Option_t *)
176 {
177   // The Terminate() function is the last function to be called during
178   // a query. It always runs on the client, it can be used to present
179   // the results graphically or save the results to file.
180
181   fOutput = dynamic_cast<TList*> (GetOutputData(1));
182   if (!fOutput)
183     Printf("ERROR: fOutput not available");
184
185
186 }
187
188 Bool_t AliCollisionNormalizationTask::IsEventInBinZero() {
189
190   // Returns true if an event is to be assigned to the zero bin
191   //
192   // You should have your own version of this method in the class: in
193   // general, the definition of "reconstructed" event is subjective.
194
195   Bool_t isZeroBin = kTRUE;
196   const AliESDEvent* esd= dynamic_cast<AliESDEvent*>(fInputEvent);
197   if (!esd){ 
198     Printf("AliCollisionNormalizationTask::IsEventInBinZero: Can't get ESD");
199     return kFALSE;   
200   }
201   const AliMultiplicity* mult = esd->GetMultiplicity();
202   if (!mult){
203     Printf("AliCollisionNormalizationTask::IsEventInBinZero: Can't get mult object");
204     return kFALSE;
205   }
206   Int_t ntracklet = mult->GetNumberOfTracklets();
207   const AliESDVertex * vtxESD = esd->GetPrimaryVertexSPD();
208   if(vtxESD) {
209     // If there is a vertex from vertexer z with delta phi > 0.02 we
210     // don't consider it rec (we keep the event in bin0). If quality
211     // is good eneough we check the number of tracklets
212     // if the vertex is more than 15 cm away, this is autamatically bin0
213     if( TMath::Abs(vtxESD->GetZ()) <= 15 ) {
214       if (vtxESD->IsFromVertexerZ()) {
215         if (vtxESD->GetDispersion()<=0.02 ) {
216           if(ntracklet>0) isZeroBin = kFALSE;
217         }
218       } else if(ntracklet>0) isZeroBin = kFALSE; // if the event is not from Vz we chek the n of tracklets
219     } 
220   }
221   return isZeroBin;
222
223 }