]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnAnalysisMonitorTask.cxx
Corrections after survey of Coverity tests
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnAnalysisMonitorTask.cxx
CommitLineData
6aecf4fd 1//
2// Implementation file for implementation of data analysis aft 900 GeV
3//
4// Author: A. Pulvirenti
5//
6
7#include "Riostream.h"
8#include <iomanip>
9
10#include "TH1.h"
11#include "TTree.h"
12#include "TParticle.h"
13#include "TRandom.h"
14#include "TLorentzVector.h"
15
16#include "AliLog.h"
17#include "AliESDpid.h"
18#include "AliESDEvent.h"
19#include "AliESDVertex.h"
20#include "AliESDtrack.h"
21#include "AliStack.h"
22#include "AliMCEvent.h"
23#include "AliTOFT0maker.h"
24#include "AliTOFcalib.h"
25#include "AliCDBManager.h"
26#include "AliITSPIDResponse.h"
27#include "AliRsnMonitorTrack.h"
69fbb331 28#include "AliRsnDaughter.h"
29#include "AliRsnEvent.h"
6aecf4fd 30
31#include "AliRsnAnalysisMonitorTask.h"
32
33//__________________________________________________________________________________________________
34AliRsnAnalysisMonitorTask::AliRsnAnalysisMonitorTask(const char *name) :
35 AliAnalysisTaskSE(name),
69fbb331 36 fEventOK(kFALSE),
6aecf4fd 37 fEventType(2),
38 fNTracks(0),
39 fOut(0x0),
40 fTracks(0x0),
6aecf4fd 41 fESDpid(0x0),
42 fTOFmaker(0x0),
43 fTOFcalib(0x0),
44 fTOFcalibrateESD(kFALSE),
45 fTOFcorrectTExp(kFALSE),
46 fTOFuseT0(kFALSE),
47 fTOFtuneMC(kFALSE),
69fbb331 48 fTOFresolution(0.0),
49 fEventCuts("eventCuts", AliRsnCut::kEvent),
50 fTrackCuts("trackCuts", AliRsnCut::kDaughter)
6aecf4fd 51
52{
53//
54// Constructor
55//
56
57 DefineOutput(1, TTree::Class());
58}
59
60//__________________________________________________________________________________________________
61AliRsnAnalysisMonitorTask::AliRsnAnalysisMonitorTask(const AliRsnAnalysisMonitorTask& copy) :
62 AliAnalysisTaskSE(copy),
69fbb331 63 fEventOK(kFALSE),
6aecf4fd 64 fEventType(2),
65 fNTracks(0),
66 fOut(0x0),
67 fTracks(0x0),
6aecf4fd 68 fESDpid(0x0),
69 fTOFmaker(0x0),
70 fTOFcalib(0x0),
71 fTOFcalibrateESD(kFALSE),
72 fTOFcorrectTExp(kFALSE),
73 fTOFuseT0(kFALSE),
74 fTOFtuneMC(kFALSE),
69fbb331 75 fTOFresolution(0.0),
76 fEventCuts(copy.fEventCuts),
77 fTrackCuts(copy.fTrackCuts)
6aecf4fd 78{
79//
80// Copy constructor
81//
82}
83
84//__________________________________________________________________________________________________
85AliRsnAnalysisMonitorTask& AliRsnAnalysisMonitorTask::operator=(const AliRsnAnalysisMonitorTask& copy)
86{
87//
88// Assignment operator
89//
90
6aecf4fd 91 fTOFcalibrateESD = copy.fTOFcalibrateESD;
92 fTOFcorrectTExp = copy.fTOFcorrectTExp;
93 fTOFuseT0 = copy.fTOFuseT0;
94 fTOFtuneMC = copy.fTOFtuneMC;
95 fTOFresolution = copy.fTOFresolution;
96
97 return (*this);
98}
99
100//__________________________________________________________________________________________________
101AliRsnAnalysisMonitorTask::~AliRsnAnalysisMonitorTask()
102{
103//
104// Destructor
105//
106
107 if (fOut) delete fOut;
108 if (fESDpid) delete fESDpid;
109}
110
111//__________________________________________________________________________________________________
112void AliRsnAnalysisMonitorTask::UserCreateOutputObjects()
113{
114//
115// Create the output data container
116//
117
118 // setup TPC response
119 fESDpid = new AliESDpid;
120 fESDpid->GetTPCResponse().SetBetheBlochParameters(fTPCpar[0], fTPCpar[1], fTPCpar[2], fTPCpar[3], fTPCpar[4]);
121
122 // setup TOF maker & calibration
123 fTOFcalib = new AliTOFcalib;
124 fTOFmaker = new AliTOFT0maker(fESDpid, fTOFcalib);
125 fTOFmaker->SetTimeResolution(fTOFresolution);
126
127 // initialize all the branch arrays
128 fTracks = new TClonesArray("AliRsnMonitorTrack", 0);
129
130 // create output tree
131 OpenFile(1);
132 fOut = new TTree("rsnMonitor", "Informations on single tracks for cut checking");
133
134 // link branches
135 fOut->Branch("ntracks", &fNTracks , "ntracks/I" );
136 fOut->Branch("evtype" , &fEventType , "evtype/I" );
69fbb331 137 fOut->Branch("evok" , &fEventOK , "evok/O" );
138 fOut->Branch("vertex" , &fVertex , "vertex[3]/F" );
6aecf4fd 139 fOut->Branch("tracks" , "TClonesArray", &fTracks );
140}
141
142//__________________________________________________________________________________________________
143void AliRsnAnalysisMonitorTask::UserExec(Option_t *)
144{
145//
146// Main execution function.
147// Fills the fHEvents data member with the following legenda:
148// 0 -- event OK, prim vertex with tracks
149// 1 -- event OK, prim vertex with SPD
150// 2 -- event OK but vz large
151// 3 -- event bad
152//
153
154 static Int_t evNum = 0;
155 evNum++;
156
157 // retrieve ESD event and related stack (if available)
158 AliESDEvent *esd = dynamic_cast<AliESDEvent*>(fInputEvent);
96e9d35d 159 AliStack *stack = 0x0;
160
161 // skip NULL events
162 if (!esd) return;
163 if (fMCEvent) stack = fMCEvent->Stack();
6aecf4fd 164
165 // check the event
166 EventEval(esd);
167
168 // if processable, then process it
169 if (fEventType == 0) ProcessESD(esd, esd->GetPrimaryVertexTracks(), stack);
170 else if (fEventType == 1) ProcessESD(esd, esd->GetPrimaryVertexSPD() , stack);
171 else
172 {
173 fTracks->Delete();
174 fTracks->Clear();
175 fNTracks = 0;
176 }
177
178 // add a new entry in the TTree
179 fOut->Fill();
180
181 // update histogram container
182 PostData(1, fOut);
183}
184
185//__________________________________________________________________________________________________
186void AliRsnAnalysisMonitorTask::Terminate(Option_t *)
187{
188//
189// Terminate
190//
191}
192
193//__________________________________________________________________________________________________
194void AliRsnAnalysisMonitorTask::EventEval(AliESDEvent *esd)
195{
196//
197// Checks if the event is good for analysis.
198// Sets the 'fEventType' flag to:
199// ---> 0 if a good primary vertex with tracks was found,
200// ---> 1 if a good SPD primary vertex was found
201// ---> 2 otherwise (event to be rejected)
202// In any case, adds an entry to the TTree, to keep trace of all events.
203//
204
205 // get number of tracks
206 fNTracks = esd->GetNumberOfTracks();
207
208 // get the best primary vertex:
209 // first try that with tracks, then the SPD one
210 const AliESDVertex *vTrk = esd->GetPrimaryVertexTracks();
211 const AliESDVertex *vSPD = esd->GetPrimaryVertexSPD();
212 if(vTrk->GetNContributors() > 0)
213 {
214 fVertex[0] = vTrk->GetXv();
215 fVertex[1] = vTrk->GetYv();
216 fVertex[2] = vTrk->GetZv();
217 fEventType = 0;
218 }
219 else if (vSPD->GetNContributors() > 0)
220 {
221 fVertex[0] = vSPD->GetXv();
222 fVertex[1] = vSPD->GetYv();
223 fVertex[2] = vSPD->GetZv();
224 fEventType = 1;
225 }
226 else
227 {
228 fNTracks = 0;
229 fEventType = 2;
230 }
231}
232
233//__________________________________________________________________________________________________
234void AliRsnAnalysisMonitorTask::ProcessESD
235(AliESDEvent *esd, const AliESDVertex *v, AliStack *stack)
236{
237//
238// Process the ESD container, to read all tracks and copy their useful values.
239// All info are stored into an AliRsnMonitorTrack object and saved into the
240// TClonesArray which is one of the branches of the output TTree.
241//
242
69fbb331 243 // create interfacr objects
244 AliRsnEvent event;
245 AliRsnDaughter daughter;
246 event.SetRef(esd, fMCEvent);
247
248 // check event cuts and track cuts
249 fEventOK = fEventCuts.IsSelected(&event);
250
6aecf4fd 251 // clear array
252 fTracks->Delete();
253 fTracks->Clear();
254
255 // reject empty events
256 if (!fNTracks) return;
257
258 // ITS stuff #1
259 // create the response function and initialize it to MC or not
260 // depending if the AliStack object is there or not
261 Bool_t isMC = (stack != 0x0);
262 AliITSPIDResponse itsrsp(isMC);
263
264 // TOF stuff #1: init OCDB
265 Int_t run = esd->GetRunNumber();
266 AliCDBManager *cdb = AliCDBManager::Instance();
267 cdb->SetDefaultStorage("raw://");
268 cdb->SetRun(run);
269 // TOF stuff #2: init calibration
270 fTOFcalib->SetCorrectTExp(fTOFcorrectTExp);
271 fTOFcalib->Init();
272 // TOF stuff #3: calibrate
273 if (fTOFcalibrateESD) fTOFcalib->CalibrateESD(esd);
274 if (fTOFtuneMC) fTOFmaker->TuneForMC(esd);
275 if (fTOFuseT0)
276 {
277 fTOFmaker->ComputeT0TOF(esd);
278 fTOFmaker->ApplyT0TOF(esd);
279 fESDpid->MakePID(esd, kFALSE, 0.);
280 }
6aecf4fd 281
282 // loop on all tracks
69fbb331 283 Int_t i, k, size;
284 Double_t itsdedx[4];
285 Bool_t isTPC, isITSSA;
6aecf4fd 286 Float_t b[2], bCov[3];
287 AliRsnMonitorTrack mon;
288
289 for (i = 0; i < fNTracks; i++)
290 {
291 AliESDtrack *track = esd->GetTrack(i);
69fbb331 292 event.SetDaughter(daughter, i, AliRsnDaughter::kTrack);
6aecf4fd 293
69fbb331 294 // reset the output object
295 // 'usable' flag will need to be set to 'ok'
296 mon.Reset();
297
298 // check cuts
299 mon.CutsPassed() = fTrackCuts.IsSelected(&daughter);
300
6aecf4fd 301 // skip NULL pointers, kink daughters and tracks which
302 // cannot be propagated to primary vertex
303 if (!track) continue;
304 if ((Int_t)track->GetKinkIndex(0) > 0) continue;
305 if (!track->RelateToVertex(v, esd->GetMagneticField(), kVeryBig)) continue;
306
19a7d46c 307 // get MC info if possible
308 if (stack) mon.AdoptMC(TMath::Abs(track->GetLabel()), stack);
309
6aecf4fd 310 // copy general info
311 mon.Status() = (UInt_t)track->GetStatus();
312 mon.Length() = (Double_t)track->GetIntegratedLength();
313 mon.Charge() = (Int_t)track->Charge();
314 mon.PrecX() = (Double_t)track->Px();
315 mon.PrecY() = (Double_t)track->Py();
316 mon.PrecZ() = (Double_t)track->Pz();
317
318 // evaluate some flags from the status to decide what to do next in some points
319 isTPC = ((mon.Status() & AliESDtrack::kTPCin) != 0);
320 isITSSA = ((mon.Status() & AliESDtrack::kTPCin) == 0 && (mon.Status() & AliESDtrack::kITSrefit) != 0 && (mon.Status() & AliESDtrack::kITSpureSA) == 0 && (mon.Status() & AliESDtrack::kITSpid) != 0);
6aecf4fd 321
322 // accept only tracks which are TPC+ITS or ITS standalone
323 if (!isTPC && !isITSSA) continue;
324
325 // set the track type in the output object
326 mon.ITSsa() = isITSSA;
327
328 // get DCA to primary vertex
329 track->GetImpactParameters(b, bCov);
330 mon.DCAr() = (Double_t)b[0];
331 mon.DCAz() = (Double_t)b[1];
332
333 // get ITS info
334 track->GetITSdEdxSamples(itsdedx);
335 mon.ITSchi2() = track->GetITSchi2();
336 mon.ITSsignal() = track->GetITSsignal();
6aecf4fd 337 for (k = 0; k < 6; k++)
338 {
339 mon.ITSmap(k) = track->HasPointOnITSLayer(k);
340 if (k < 4) mon.ITSdedx(k) = itsdedx[k];
341 }
342
343 // get TPC info
c8ec81d6 344 if (isTPC)
6aecf4fd 345 {
c8ec81d6 346 mon.TPCcount() = (Int_t)track->GetTPCclusters(0);
347 mon.TPCdedx() = (Double_t)track->GetTPCsignal();
348 mon.TPCchi2() = (Double_t)track->GetTPCchi2();
349 mon.TPCnsigma() = fESDpid->NumberOfSigmasTPC(track, AliPID::kKaon);
350 mon.PtpcX() = mon.PtpcY() = mon.PtpcZ() = 1E10;
351 if (track->GetInnerParam())
352 {
353 mon.PtpcX() = track->GetInnerParam()->Px();
354 mon.PtpcY() = track->GetInnerParam()->Py();
355 mon.PtpcZ() = track->GetInnerParam()->Pz();
356 for (k = 0; k < AliPID::kSPECIES; k++) mon.TPCref(k) = fESDpid->GetTPCResponse().GetExpectedSignal(mon.Ptpc(), (AliPID::EParticleType)k);
357 }
6aecf4fd 358 }
359
360 // get TOF info
361 Double_t time[10];
362 track->GetIntegratedTimes(time);
363 mon.TOFsignal() = (Double_t)track->GetTOFsignal();
364 for (k = 0; k < AliPID::kSPECIES; k++)
365 {
366 mon.TOFref(k) = time[k];
367 mon.TOFsigma(k) = (Double_t)fTOFmaker->GetExpectedSigma(mon.Prec(), time[k], AliPID::ParticleMass(k));
368 }
369
370 // if we are here, the track is usable
371 mon.SetUsable();
372
6aecf4fd 373 // collect only tracks which are declared usable
374 if (mon.IsUsable())
375 {
376 size = (Int_t)fTracks->GetEntriesFast();
377 new ((*fTracks)[size]) AliRsnMonitorTrack(mon);
378 }
379 }
380}