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