]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG3/hfe/AliAnalysisTaskCheckV0tender.cxx
Further Coverity fixes, and V0 developments.
[u/mrichter/AliRoot.git] / PWG3 / hfe / AliAnalysisTaskCheckV0tender.cxx
CommitLineData
3a72645a 1/**************************************************************************
2* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3* *
4* Author: The ALICE Off-line Project. *
5* Contributors are mentioned in the code where appropriate. *
6* *
7* Permission to use, copy, modify and distribute this software and its *
8* documentation strictly for non-commercial purposes is hereby granted *
9* without fee, provided that the above copyright notice appears in all *
10* copies and that both the copyright notice and this permission notice *
11* appear in the supporting documentation. The authors make no claims *
12* about the suitability of this software for any purpose. It is *
13* provided "as is" without express or implied warranty. *
14**************************************************************************/
15//
16// Task fir checking the performance of the V0 tender
17//
18//
19// Authors
20// Matus Kalisky <matus.kalisky@cern.ch>
21//
22
e3ae862b 23#include <sstream>
24
3a72645a 25#include <TH1F.h>
26#include <TList.h>
27
28#include "AliAnalysisManager.h"
29#include "AliMCEventHandler.h"
30#include "AliESDInputHandler.h"
31#include "AliESDv0.h"
32#include "AliESDtrack.h"
33#include "AliMCParticle.h"
34#include "AliMCEvent.h"
35
36#include "AliHFEtools.h"
37#include "AliHFEcollection.h"
38
39#include "AliAnalysisTaskCheckV0tender.h"
40
41ClassImp(AliAnalysisTaskCheckV0tender)
42
43//__________________________________________________________
44AliAnalysisTaskCheckV0tender::AliAnalysisTaskCheckV0tender():
45 AliAnalysisTaskSE("CheckV0tenderTask")
46 , fOutput(0x0)
47 , fColl(0x0)
48 , fCollMC(0x0)
49 , fEvents(0x0)
50{
51 //
52 // Default Constructor
53 //
54}
55//__________________________________________________________
56AliAnalysisTaskCheckV0tender::AliAnalysisTaskCheckV0tender(const Char_t *name):
57 AliAnalysisTaskSE(name)
58 , fOutput(0x0)
59 , fColl(0x0)
60 , fCollMC(0x0)
61 , fEvents(0x0)
62{
63 //
64 // Default Constructor
65 //
66 DefineOutput(1, TH1F::Class());
67 DefineOutput(2, TList::Class());
68
69}
70//__________________________________________________________
71AliAnalysisTaskCheckV0tender::~AliAnalysisTaskCheckV0tender(){
72 //
73 // Destructor
74 //
75
76 if (fOutput) delete fOutput;
e3ae862b 77 //if (fColl) delete fColl;
78 //if (fCollMC) delete fCollMC;
3a72645a 79 if (fEvents) delete fEvents;
80}
81//__________________________________________________________
82void AliAnalysisTaskCheckV0tender::UserCreateOutputObjects(){
83 //
84 // prepare output objects
85 //
86
87 fOutput = new TList();
88 fOutput->SetOwner();
89 // Counter for number of events
90 fEvents = new TH1I("nEvents", "NumberOfEvents", 1, 1, 2);
91
92 fColl = new AliHFEcollection("V0_QA", "tender V0s for data");
93 fCollMC = new AliHFEcollection("V0_MC_QA", "tender V0s for MC");
94
95 //
96 // Data histos
97 //
98
99 // total number of tagged V0s
100 fColl->CreateTH1F("h_NumberOf_V0s", "Number of tagged V0s; type; counts", 4, -0.5, 3.5);
101 // pT spectra of the tagged V0s
102 fColl->CreateTH1F("h_Gamma_pt", "p_{T} spectrum of tagged gammas; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
103 fColl->CreateTH1F("h_K0_pt", "p_{T} spectrum of tagged K0s; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
104 fColl->CreateTH1F("h_Lambda_pt", "p_{T} spectrum of tagged Lambdas; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
105 fColl->CreateTH1F("h_ALambda_pt", "p_{T} spectrum of tagged A-Lambdas; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
106 // invariant mass of the V0s
107 fColl->CreateTH1F("h_Gamma_mass", "Inv. Mass of the ", 100, 0., 0.1);
108 fColl->CreateTH1F("h_K0_mass", "Inv. Mass of the ", 100, 0.45, 0.55);
109 fColl->CreateTH1F("h_Lambda_mass", "Inv. Mass of the ", 100, 1.08, 1.14);
110 fColl->CreateTH1F("h_ALambda_mass", "Inv. Mass of the ", 100, 1.08, 1.14);
111
112 // total number of tagged daughter particles (should correlate with number of V0s !
113 fColl->CreateTH1F("h_NumberOfDaughters", "Number of tagged daughters; type; counts", 3, -0.5, 2.5);
114 // pT spectra of tagged daughter particles
115 fColl->CreateTH1F("h_Electron_pt", "p_{T} spectrum of tagged; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
116 fColl->CreateTH1F("h_Pion_pt", "p_{T} spectrum of tagged; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
117 fColl->CreateTH1F("h_Proton_pt", "p_{T} spectrum of tagged; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
118
119 //
120 // MC histos
121 //
122
123 // pT spectra of the tagged V0s
124 fCollMC->CreateTH1F("h_Gamma_pt_S", "MC-S: p_{T} spectrum of tagged gammas; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
125 fCollMC->CreateTH1F("h_K0_pt_S", "MC-S: p_{T} spectrum of tagged K0s; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
126 fCollMC->CreateTH1F("h_Lambda_pt_S", "MC-S: p_{T} spectrum of tagged Lambdas; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
127 fCollMC->CreateTH1F("h_ALambda_pt_S", "MC-S: p_{T} spectrum of tagged A-Lambdas; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
128 fCollMC->CreateTH1F("h_Gamma_pt_B", "MC-B: p_{T} spectrum of tagged gammas; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
129 fCollMC->CreateTH1F("h_K0_pt_B", "MC-B: p_{T} spectrum of tagged K0s; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
130 fCollMC->CreateTH1F("h_Lambda_pt_B", "MC-B: p_{T} spectrum of tagged Lambdas; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
131 fCollMC->CreateTH1F("h_ALambda_pt_B", "MC-B: p_{T} spectrum of tagged A-Lambdas; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
132 // invariant mass of the V0s
133 fCollMC->CreateTH1F("h_Gamma_mass_S", "MC-S: Inv. Mass of the gamma; m (GeV/c^{2}); counts", 100, 0., 0.1);
134 fCollMC->CreateTH1F("h_K0_mass_S", "MC-S: Inv. Mass of the K0; m (GeV/c^{2}); counts", 100, 0.45, 0.55);
135 fCollMC->CreateTH1F("h_Lambda_mass_S", "MC-S: Inv. Mass of the Lambda; m (GeV/c^{2}); counts", 100, 1.08, 1.14);
136 fCollMC->CreateTH1F("h_ALambda_mass_S", "MC-S: Inv. Mass of the A-Lambda; m (GeV/c^{2}); counts", 100, 1.08, 1.14);
137 fCollMC->CreateTH1F("h_Gamma_mass_B", "MC-B: Inv. Mass of the gamma; m (GeV/c^{2}); counts", 100, 0., 0.1);
138 fCollMC->CreateTH1F("h_K0_mass_B", "MC-B: Inv. Mass of the K0; m (GeV/c^{2}); counts", 100, 0.45, 0.55);
139 fCollMC->CreateTH1F("h_Lambda_mass_B", "MC-B: Inv. Mass of the Lambda; m (GeV/c^{2}); counts", 100, 1.08, 1.14);
140 fCollMC->CreateTH1F("h_ALambda_mass_B", "MC-B: Inv. Mass of the A-Lambda; m (GeV/c^{2}); counts", 100, 1.08, 1.14);
141 // pT spectra of tagged daughter particles
142 fCollMC->CreateTH1F("h_Electron_pt_S", "MC-S: p_{T} spectrum of tagged electrons; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
143 fCollMC->CreateTH1F("h_Pion_pt_S", "MC-S: p_{T} spectrum of tagged pions; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
144 fCollMC->CreateTH1F("h_Proton_pt_S", "MC-S: p_{T} spectrum of tagged protons; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
145 fCollMC->CreateTH1F("h_Electron_pt_B", "MC-B: p_{T} spectrum of tagged electrons; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
146 fCollMC->CreateTH1F("h_Pion_pt_B", "MC-B: p_{T} spectrum of tagged pions; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
147 fCollMC->CreateTH1F("h_Proton_pt_B", "MC-B: p_{T} spectrum of tagged protons; p_{T} (GeV/c); counts", 20, 0.1, 20, 0);
148
149
150 TList *tmp = fColl->GetList();
151 tmp->SetName(fColl->GetName());
152 fOutput->Add(tmp);
153 tmp = 0x0;
154 tmp = fCollMC->GetList();
155 tmp->SetName(fCollMC->GetName());
156 fOutput->Add(tmp);
157
158
159}
160//__________________________________________________________
161void AliAnalysisTaskCheckV0tender::UserExec(Option_t *){
162 //
163 // Event Loop
164 //
bf892a6a 165
3a72645a 166 AliMCEventHandler* mcHandler = (dynamic_cast<AliMCEventHandler*>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()));
bf892a6a 167 //AliESDInputHandler *inh = dynamic_cast<AliESDInputHandler *>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
168 //AliESDpid *workingPID = NULL;
169 //if(inh && (workingPID = inh->GetESDpid())) workingPID = inh->GetESDpid();
170 //else workingPID = AliHFEtools::GetDefaultPID(mcHandler ? kTRUE : kFALSE);
3a72645a 171
172 // check the MC data
173 if(fMCEvent && !mcHandler ) return;
174 if(fMCEvent && !mcHandler->InitOk() ) return;
175 if(fMCEvent && !mcHandler->TreeK() ) return;
176 if(fMCEvent && !mcHandler->TreeTR() ) return;
177
178 ProcessV0s();
179 ProcessDaughters();
180
181 if(fMCEvent){
182 ProcessV0sMC();
183 ProcessDaughtersMC();
184 }
185
186 fEvents->Fill(1.1);
187 PostData(1, fEvents);
188 PostData(2, fOutput);
189}
190//__________________________________________________________
191void AliAnalysisTaskCheckV0tender::Terminate(Option_t *){
192 //
193 // Do Post Processing
194 //
195}
196//__________________________________________________________
197void AliAnalysisTaskCheckV0tender::ProcessV0s(){
198 //
199 // loop over the V0s and extract the information about
200 // the V0s tagged by the V0 tender
201 //
202
e3ae862b 203 const TString type[4] = {"Gamma", "K0", "Lambda", "ALambda"};
204 TString name;
3a72645a 205
206 Int_t nV0s = fInputEvent->GetNumberOfV0s();
207 for(Int_t i=0; i<nV0s; ++i){
bf892a6a 208 AliESDv0 *esdV0 = (static_cast<AliESDEvent *>(fInputEvent))->GetV0(i);
3a72645a 209 if(!esdV0) continue;
210 if(!esdV0->GetOnFlyStatus()) continue; // Take only V0s from the On-the-fly v0 finder
211 Int_t pid = GetTenderPidV0(esdV0);
e97c2edf 212 if(pid < 0) continue;
3a72645a 213 fColl->Fill("h_NumberOf_V0s", pid);
3a72645a 214 Float_t pT = esdV0->Pt();
e3ae862b 215 name = "h_" + type[pid] + "_pt";
3a72645a 216 fColl->Fill(name, pT);
e3ae862b 217 Float_t mass = MassV0(esdV0, pid);
218 name = "h_" + type[pid] + "_mass";
219 //printf(" -D: name: %s \n", name.Data());
3a72645a 220 fColl->Fill(name, mass);
221 }
222
223}
224//__________________________________________________________
225void AliAnalysisTaskCheckV0tender::ProcessDaughters(){
226 //
227 // produce some check plots for V0 tender tagged single tracks
228 //
229
e3ae862b 230 const TString type[3] = {"Electron", "Pion", "Proton"};
231 TString name;
3a72645a 232
233 Int_t nTracks = fInputEvent->GetNumberOfTracks();
234 for(Int_t i=0; i<nTracks; ++i){
235 AliESDtrack *track = dynamic_cast<AliESDtrack*>(fInputEvent->GetTrack(i));
236 if(!track) continue;
237 Int_t pid = GetTenderPidDaughter(track);
238 if(pid < 0) continue;
239 fColl->Fill("h_NumberOfDaughters", pid*1.0);
240 Float_t pT = track->Pt();
e3ae862b 241 name = "h_" + type[pid] + "_pt";
3a72645a 242 fColl->Fill(name, pT);
243
244 }
245}
246//__________________________________________________________
247void AliAnalysisTaskCheckV0tender::ProcessV0sMC(){
248 //
249 // check all V0tender selected V0 on their true identity
250 //
251
252 const Int_t pid2pdg[4] = {22, 310, 3122, -3122};
e3ae862b 253 const TString type[4] = {"Gamma", "K0", "Lambda", "ALambda"};
254 TString name;
3a72645a 255 Int_t nV0s = fInputEvent->GetNumberOfV0s();
256
257 Int_t nTracks = fInputEvent->GetNumberOfTracks();
258
259 // V0 loop
260 for(Int_t i=0; i<nV0s; ++i){
261 Bool_t id = kFALSE;
bf892a6a 262 AliESDv0 *esdV0 = (static_cast<AliESDEvent *>(fInputEvent))->GetV0(i);
3a72645a 263 if(!esdV0) continue;
264 if(!esdV0->GetOnFlyStatus()) continue; // Take only V0s from the On-the-fly v0 finder
265 Int_t pid = GetTenderPidV0(esdV0);
266 if(pid < 0) continue;
267
268 // both ESD daughtr tracks
269 Int_t iN, iP;
270 iN = iP = -1;
271 iP = esdV0->GetPindex();
272 iN = esdV0->GetNindex();
273 if(iN < 0 || iP < 0) continue;
274 if(iN >= nTracks || iP >= nTracks) continue;
275 AliESDtrack *dP, *dN;
276 dP = dynamic_cast<AliESDtrack *>(fInputEvent->GetTrack(iP));
277 dN = dynamic_cast<AliESDtrack *>(fInputEvent->GetTrack(iN));
278 if(!dN || !dP) continue;
279
280 // MC labels of the daughter tracks
281 Int_t lN, lP;
282 lN = dN->GetLabel();
283 lP = dP->GetLabel();
284 if(lN < 0 || lP < 0) continue;
285
286 // MC daughter particles
287 AliMCParticle *mcP, *mcN;
288 mcP = dynamic_cast<AliMCParticle*>(fMCEvent->GetTrack(lP));
289 mcN = dynamic_cast<AliMCParticle*>(fMCEvent->GetTrack(lN));
290 if(!mcP || !mcN) continue;
291
292 // labels of the mother particles
293 Int_t lPm, lNm;
294 lPm = mcP->GetMother();
295 lNm = mcN->GetMother();
296 if(lPm < 0) continue;
297 AliMCParticle *m = dynamic_cast<AliMCParticle*>(fMCEvent->GetTrack(lPm));
298 if(!m) continue;
299 Int_t pdg = m->PdgCode();
300 if((lPm == lNm) && (pdg == pid2pdg[pid])) id = kTRUE;
301
e3ae862b 302 if(id) name = "h_" + type[pid] + "_pt_S";
303 else name = "h_" + type[pid] + "_pt_B";
3a72645a 304 Float_t pT = esdV0->Pt();
305 fCollMC->Fill(name, pT);
306
e3ae862b 307 if(id) name = "h_" + type[pid] + "_mass_S";
308 else name = "h_" + type[pid] + "_mass_B";
3a72645a 309 Float_t mass = MassV0(esdV0, pid);
310 fCollMC->Fill(name, mass);
311
312 }
313}
314//__________________________________________________________
315void AliAnalysisTaskCheckV0tender::ProcessDaughtersMC(){
316 //
317 // check the identity of the V0tender selected V0 daughters
318 // !!! for positive check only the true identity plays a role here,
319 // not the true V0 mother identity (e.g. selected electron could come
320 // from primary vertex or pion dalitz deca or true gamma conversion) !!!
321 //
322
323 const Int_t pid2pdg [3] = {11, 211, 2212};
e3ae862b 324 const TString type[3] = {"Electron", "Pion", "Proton"};
325 TString name;
3a72645a 326
327
328 Int_t nTracks = fInputEvent->GetNumberOfTracks();
329 for(Int_t i=0; i<nTracks; ++i){
330 Bool_t id = kFALSE;
331 AliESDtrack *track = dynamic_cast<AliESDtrack*>(fInputEvent->GetTrack(i));
332 if(!track) continue;
333 Int_t pid = GetTenderPidDaughter(track);
334 if(pid < 0) continue;
335 Float_t pT = track->Pt();
336 Int_t label = track->GetLabel();
337 if(label < 0) continue;
338 AliMCParticle *mcp = 0x0;
339 mcp = dynamic_cast<AliMCParticle*>(fMCEvent->GetTrack(label));
340 if(!mcp) continue;
341 Int_t pdg = TMath::Abs(mcp->PdgCode());
342 if(pdg == pid2pdg[pid]) id = kTRUE;
e3ae862b 343 if(id) name = "h_" + type[pid] + "_pt_S";
344 else name = "h_" + type[pid] + "_pt_B";
3a72645a 345 fCollMC->Fill(name, pT);
346 }
347}
348//__________________________________________________________
349Int_t AliAnalysisTaskCheckV0tender::GetTenderPidV0(AliESDv0 * const v0){
350 //
351 // retrieve the PID nformation stored in the status flags by the train tender
352 //
353 Int_t pid = -1;
354 if(!v0){
355 return pid;
356 }
357 Int_t nTimes = 0;
358 if(v0->TestBit(BIT(14))){
359 pid = 0;
360 nTimes++;
361 }
362 if(v0->TestBit(BIT(15))){
363 pid = 1;
364 nTimes++;
365 }
366 if(v0->TestBit(BIT(16))){
367 pid = 2;
368 nTimes++;
369 }
370 if(v0->TestBit(BIT(17))){
371 pid = 3;
372 nTimes++;
373 }
374 if(nTimes > 1){
375 AliWarning("V0 track labeled multiple times by the V0 tender");
376 pid = -1;
377 }
378
379 //printf(" -D: pid: %i \n", pid);
380
381 return pid;
382}
383//__________________________________________________________
384Int_t AliAnalysisTaskCheckV0tender::GetTenderPidDaughter(AliESDtrack * const track){
385 //
386 // retrieve the PID nformation stored in the status flags by the train tender
387 //
388
389 Int_t pid = -1;
390 if(!track){
391 return pid;
392 }
393 Int_t nTimes = 0;
394 if(track->TestBit(BIT(14))){
395 pid = 0;
396 nTimes++;
397 }
398 if(track->TestBit(BIT(15))){
399 pid = 1;
400 nTimes++;
401 }
402 if(track->TestBit(BIT(16))){
403 pid = 2;
404 nTimes++;
405 }
406 if(nTimes > 1){
407 AliWarning("V0 track labeled multiple times by the V0 tender");
408 pid = -1;
409 }
410 return pid;
411}
412//__________________________________________________________
413Float_t AliAnalysisTaskCheckV0tender::MassV0(AliESDv0 * const v0, Int_t id){
414 //
415 // Get the V0 effective mass
416 //
417
418 Float_t mass = -0.1;
419 Bool_t sign = CheckSigns(v0);
420 if(0 == id){
421 mass = v0->GetEffMass(0, 0);
422 }
423 else if(1 == id){
424 mass = v0->GetEffMass(2, 2);
425 }
426 else if(2 == id){
427 mass = (sign) ? v0->GetEffMass(4, 2) : v0->GetEffMass(2, 4);
428 }
429 else if(3 == id){
430 mass = (sign) ? v0->GetEffMass(2, 4) : v0->GetEffMass(4, 2);
431 }
432 else{
433 AliWarning(Form("Unrecognized V0 id: %i", id));
434 }
435
436 return mass;
437
438}
439//__________________________________________________________
440Bool_t AliAnalysisTaskCheckV0tender::CheckSigns(AliESDv0 * const v0){
441 //
442 // check wheter the sign was correctly applied to
443 // V0 daughter tracks
444 // This function should become obsolete once the V0 finder will be updated (fixed)
445 //
446
447 Bool_t correct = kFALSE;
448
449 Int_t pIndex = 0, nIndex = 0;
450 pIndex = v0->GetPindex();
451 nIndex = v0->GetNindex();
452
453 AliESDtrack* d[2];
454 d[0] = dynamic_cast<AliESDtrack*>(fInputEvent->GetTrack(pIndex));
455 d[1] = dynamic_cast<AliESDtrack*>(fInputEvent->GetTrack(nIndex));
456
457 Int_t sign[2];
458 sign[0] = (int)d[0]->GetSign();
459 sign[1] = (int)d[1]->GetSign();
460
461 if(-1 == sign[0] && 1 == sign[1]){
462 correct = kFALSE;
463 //v0->SetIndex(0, pIndex); // set the index of the negative v0 track
464 //v0->SetIndex(1, nIndex); // set the index of the positive v0 track
465 }
466 else{
467 correct = kTRUE;
468 }
469
470 //pIndex = v0->GetPindex();
471 //nIndex = v0->GetNindex();
472 //printf("-D2: P: %i, N: %i\n", pIndex, nIndex);
473
474 return correct;
475}