]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ANALYSIS/AliCollisionNormalizationTask.cxx
Information for TOF resolution added.
[u/mrichter/AliRoot.git] / ANALYSIS / AliCollisionNormalizationTask.cxx
CommitLineData
9b0cb3c3 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
30ClassImp(AliCollisionNormalizationTask)
31
32AliCollisionNormalizationTask::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
47AliCollisionNormalizationTask::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
63AliCollisionNormalizationTask::~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
dd446fb7 72 if (fOutput && !AliAnalysisManager::GetAnalysisManager()->IsProofMode()) {
9b0cb3c3 73 delete fOutput;
74 fOutput = 0;
75 }
76}
77
78void 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
101void 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 (strcmp(aESD->ClassName(),"AliESDEvent")) {
111 AliFatal("Not processing ESDs");
112 }
113 // Get MC event, if needed
114 AliMCEvent* mcEvent = fIsMC ? MCEvent() : 0;
115 if (!mcEvent && fIsMC){
116 AliFatal("Running on MC but no MC handler available");
117 }
118
119 // Physics selection. At least in the case of MC we cannot use
120 // yourTask->SelectCollisionCandidates();, because we also need to
121 // fill the "generated" histogram
122 // NB never call IsEventSelected more than once per event
123 // (statistics histogram would be altered)
124
125 Bool_t isSelected = ((AliInputEventHandler*)(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler()))->IsEventSelected();
126
127 // Get the Multiplicity cut
128 const AliMultiplicity* mult = aESD->GetMultiplicity();
129 if (!mult){
130 AliError("Can't get mult object");
131 return;
132 }
133
134 // Check if the event is "reconstructed" according to some quality
135 // cuts. Tipically, we mean "it has a good-eonugh vertex"
136
137 Int_t ntracklet = mult->GetNumberOfTracklets();
138 const AliESDVertex * vtxESD = aESD->GetPrimaryVertexSPD();
0d300b4f 139 if (IsEventInBinZero()) {
140 ntracklet = 0;
141 vtxESD = 0;
142 }
9b0cb3c3 143
144 if (ntracklet > 0 && !vtxESD) {
145 AliError("No vertex but reconstructed tracklets?");
146 }
147
148 // assign vz. For MC we use generated vz
149 Float_t vz = 0;
150 if (!fIsMC) vz = vtxESD ? vtxESD->GetZ() : 0; // FIXME : is zv used anywhere in Gen?
151 else vz = mcEvent->GetPrimaryVertex()->GetZ();
152
153 if (fIsMC) {
154 // Monte Carlo: we fill 3 histos
0d300b4f 155 if (!isSelected || !vtxESD) ntracklet = 0; //If the event does not pass the physics selection or is not rec, it goes in the bin0
9b0cb3c3 156 fCollisionNormalization->FillVzMCGen(vz, ntracklet, mcEvent);
157 // If triggered == passing the physics selection
0d300b4f 158 if (isSelected) {
159 fCollisionNormalization->FillVzMCTrg(vz, ntracklet, mcEvent);
160 // If reconstructer == good enough vertex
161 if (vtxESD) fCollisionNormalization->FillVzMCRec(vz, ntracklet, mcEvent);
162 }
9b0cb3c3 163 } else {
164 if (isSelected) {
165 // Passing the trigger
166 fCollisionNormalization->FillVzData(vz,ntracklet);
167 }
168 }
169
170}
171
172void AliCollisionNormalizationTask::Terminate(Option_t *)
173{
174 // The Terminate() function is the last function to be called during
175 // a query. It always runs on the client, it can be used to present
176 // the results graphically or save the results to file.
177
178 fOutput = dynamic_cast<TList*> (GetOutputData(1));
179 if (!fOutput)
180 Printf("ERROR: fOutput not available");
181
182
183}
184
185Bool_t AliCollisionNormalizationTask::IsEventInBinZero() {
186
187 // Returns true if an event is to be assigned to the zero bin
188 //
189 // You should have your own version of this method in the class: in
190 // general, the definition of "reconstructed" event is subjective.
191
192 Bool_t isZeroBin = kTRUE;
193 const AliESDEvent* esd= dynamic_cast<AliESDEvent*>(fInputEvent);
194 const AliMultiplicity* mult = esd->GetMultiplicity();
195 if (!mult){
196 Printf("AliAnalysisTaskBGvsTime::IsBinZero: Can't get mult object");
197 return kFALSE;
198 }
199 Int_t ntracklet = mult->GetNumberOfTracklets();
200 const AliESDVertex * vtxESD = esd->GetPrimaryVertexSPD();
201 if(vtxESD) {
202 // If there is a vertex from vertexer z with delta phi > 0.02 we
203 // don't consider it rec (we keep the event in bin0). If quality
204 // is good eneough we check the number of tracklets
205 // if the vertex is more than 15 cm away, this is autamatically bin0
206 if( TMath::Abs(vtxESD->GetZ()) <= 15 ) {
207 if (vtxESD->IsFromVertexerZ()) {
208 if (vtxESD->GetDispersion()<=0.02 ) {
209 if(ntracklet>0) isZeroBin = kFALSE;
210 }
211 } else if(ntracklet>0) isZeroBin = kFALSE; // if the event is not from Vz we chek the n of tracklets
212 }
213 }
214 return isZeroBin;
215
216}