]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWGHF/hfe/AliHFEdebugTreeTask.cxx
Adapt v2 analysis macros to new histo names
[u/mrichter/AliRoot.git] / PWGHF / hfe / AliHFEdebugTreeTask.cxx
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 // Debug tree task
17 // 
18 // Authors:
19 //   Markus Fasel <M.Fasel@gsi.de>
20 //
21 #include <TBits.h>
22 #include <TString.h>
23
24 #include "AliAnalysisManager.h"
25 #include "AliCentrality.h"
26 #include "AliESDEvent.h"
27 #include "AliESDtrack.h"
28 #include "AliESDtrackCuts.h"
29 #include "AliESDVertex.h"
30 #include "AliHFEcuts.h"
31 #include "AliHFEsignalCuts.h"
32 #include "AliInputEventHandler.h"
33 #include "AliLog.h"
34 #include "AliMCEvent.h"
35 #include "AliMCEventHandler.h"
36 #include "AliMCParticle.h"
37 #include "AliPIDResponse.h"
38 #include "AliTrackReference.h"
39 #include "AliVEvent.h"
40 #include "AliHFEpidTPC.h"
41 #include "AliHFEpidTRD.h"
42 #include "AliHFEmcQA.h"
43 #include "TTreeStream.h"
44
45 #include "AliHFEdebugTreeTask.h"
46
47 ClassImp(AliHFEdebugTreeTask)
48
49 AliHFEdebugTreeTask::AliHFEdebugTreeTask():
50   AliAnalysisTaskSE(),
51   fTrackCuts(NULL),
52   fSignalCuts(NULL),
53   fTRDpid(NULL),
54   fTPCpid(NULL),
55   fExtraCuts(NULL),
56   fNclustersTPC(70),
57   fNclustersTPCPID(0),
58   fNclustersITS(2),
59   fFilename("HFEtree.root"),
60   fDebugTree(NULL),
61   fNparents(-1)
62 {
63
64 }
65
66 AliHFEdebugTreeTask::AliHFEdebugTreeTask(const char *name):
67   AliAnalysisTaskSE(name),
68   fTrackCuts(NULL),
69   fSignalCuts(NULL),
70   fTRDpid(NULL),
71   fTPCpid(NULL),
72   fExtraCuts(NULL),
73   fNclustersTPC(70),
74   fNclustersTPCPID(0),
75   fNclustersITS(2),
76   fFilename("HFEtree.root"),
77   fDebugTree(NULL),
78   fNparents(-1)
79 {
80   fTRDpid = new AliHFEpidTRD("QAtrdPID");
81   fTPCpid = new AliHFEpidTPC("QAtpcPID");
82 }
83
84 AliHFEdebugTreeTask::~AliHFEdebugTreeTask(){
85     if(fDebugTree) delete fDebugTree;
86     if(fTRDpid) delete fTRDpid;
87     if(fTPCpid) delete fTPCpid;
88 }
89
90 void AliHFEdebugTreeTask::UserCreateOutputObjects(){
91   //
92   // Create debug tree, signal cuts and track cuts
93   //
94   fDebugTree = new TTreeSRedirector(fFilename.Data());
95
96   fSignalCuts = new AliHFEsignalCuts("HFEsignalCuts", "HFE MC Signal definition");
97
98   fTrackCuts = new AliHFEcuts("fTrackCuts", "Basic HFE track cuts");
99   fTrackCuts->CreateStandardCuts();
100   // Track cuts
101   fTrackCuts->SetMinNClustersTPC(fNclustersTPC);
102   fTrackCuts->SetMinRatioTPCclusters(0);
103   fTrackCuts->SetTPCmodes(AliHFEextraCuts::kFound, AliHFEextraCuts::kFoundOverFindable); 
104   fTrackCuts->SetMinNClustersTPCPID(fNclustersTPCPID);
105   fTrackCuts->SetMinNClustersITS(fNclustersITS);
106   // Event cuts
107   fTrackCuts->SetUseMixedVertex(kTRUE);
108   fTrackCuts->SetVertexRange(10.);
109   fTrackCuts->Initialize();
110
111   fExtraCuts = new AliHFEextraCuts("hfeExtraCuts","HFE Extra Cuts");
112
113 }
114
115 void AliHFEdebugTreeTask::UserExec(Option_t *){
116   //
117   // User Exec: Fill debug Tree
118   // 
119
120   // Get PID response
121   AliPIDResponse *pid = NULL;
122   AliInputEventHandler *handler = dynamic_cast<AliInputEventHandler *>(AliAnalysisManager::GetAnalysisManager()->GetInputEventHandler());
123   if(handler){
124     pid = handler->GetPIDResponse();
125   } else {
126     AliError("No Handler");
127   }
128   if(!pid){
129     AliError("No PID response");
130     return;
131   }
132   if(!fInputEvent) {
133     AliError("No Input event");
134     return;
135   }
136
137   AliESDtrack copyTrack;
138   
139   fTrackCuts->SetRecEvent(fInputEvent);
140
141   // Cut event
142   if(fInputEvent->IsPileupFromSPD(3, 0.8, 3., 2., 5)){
143   AliDebug(1, "Event flagged as pileup\n");
144     return;
145   }
146   if(!fTrackCuts->CheckEventCuts("fCutsEvRec", fInputEvent)){
147     AliDebug(1, "Event rejected by the event cuts\n");
148     return;
149   }
150
151   // Get run number
152   Int_t run = fInputEvent->GetRunNumber();
153
154   // Derive trigger 
155   UInt_t trigger = fInputHandler->IsEventSelected();
156   Bool_t isMBTrigger = trigger & AliVEvent::kMB;
157   Bool_t isCentralTrigger = trigger & AliVEvent::kCentral;
158   Bool_t isSemicentralTrigger = trigger & AliVEvent::kSemiCentral;
159   Bool_t isEMCALTrigger = trigger & AliVEvent::kEMCEJE;
160
161   // Check if MC information is available
162   Bool_t mcthere = dynamic_cast<AliMCEventHandler *>(AliAnalysisManager::GetAnalysisManager()->GetMCtruthEventHandler()) != NULL;
163   if(mcthere){ 
164     fTrackCuts->SetMCEvent(fMCEvent);
165     fSignalCuts->SetMCEvent(fMCEvent);
166   }
167
168   // Get Primary Vertex
169   const AliVVertex *vertex = fInputEvent->GetPrimaryVertex();
170   Double_t vtx[3];
171   vertex->GetXYZ(vtx);
172   Double_t ncontrib = fInputEvent->GetPrimaryVertex()->GetNContributors();
173
174   // Get centrality
175   Float_t centrality = -1.;
176   AliESDEvent *event = (dynamic_cast<AliESDEvent *>(fInputEvent));
177   if(!event) return;
178   TString beamtype = event->GetBeamType();
179   //printf("Beam type %s\n",(const char*)beamtype);
180   if(!beamtype.CompareTo("Pb-Pb") || !beamtype.CompareTo("A-A")){
181     // Heavy ion run
182     AliDebug(1, "Heavy-Ion event\n");
183     AliCentrality *hicent = fInputEvent->GetCentrality();
184     centrality = hicent->GetCentralityPercentile("V0M");
185   }
186
187   if(!fExtraCuts){
188     fExtraCuts = new AliHFEextraCuts("hfeExtraCuts","HFE Extra Cuts");
189   }
190   fExtraCuts->SetRecEventInfo(event);
191
192   // Store event selection variables
193   (*fDebugTree) << "EventDebug"
194                 << "Centrality="              << centrality
195                 << "VertexZ="                 << vtx[2]
196                 << "NumberOfContributors="    << ncontrib
197                 << "\n";
198
199   // Common variables
200   Double_t charge, eta, phi, momentum, transversemomentum;
201   Int_t source;
202       
203   // Monte-Carlo loop
204   if(mcthere){
205     AliMCParticle * mcpart;
206     for(Int_t itrk = 0; itrk < fMCEvent->GetNumberOfTracks(); itrk++){
207       mcpart = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(itrk));
208       if(!mcpart) continue;
209       if(!fTrackCuts->CheckParticleCuts(static_cast<UInt_t>(AliHFEcuts::kStepMCGenerated), mcpart)) continue;
210       // Kinematics
211       charge = mcpart->Charge() > 0. ? 1. : -1.;
212       momentum = mcpart->P() * charge;
213       transversemomentum = mcpart->Pt() * charge;
214       eta = mcpart->Eta();
215       phi = mcpart->Phi();
216       Int_t pdg = mcpart->Particle()->GetPdgCode();
217       
218       // Get Production Vertex in radial direction
219       Double_t vx = mcpart->Particle()->Vx(), 
220               vy = mcpart->Particle()->Vy(); 
221       Double_t productionVertex = TMath::Sqrt(vx*vx+vy*vy);
222       
223       // Get Mother PDG code of the particle
224       Int_t motherPdg = 0;
225       Int_t motherlabel = mcpart->Particle()->GetFirstMother();
226       if(motherlabel >= 0 && motherlabel < fMCEvent->GetNumberOfTracks()){
227         AliMCParticle *mother = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(motherlabel));
228         if(mother) motherPdg = mother->Particle()->GetPdgCode();
229       }
230       
231       // derive source
232       source = 5;
233       if(fSignalCuts->IsCharmElectron(mcpart)) source = 0;
234       else if(fSignalCuts->IsBeautyElectron(mcpart)) source = 1;
235       else if(fSignalCuts->IsGammaElectron(mcpart)) source = 2;
236       else if(fSignalCuts->IsNonHFElectron(mcpart)) source = 3;
237       else if(TMath::Abs(pdg) == 11) source = 4;
238       else source = 5;
239       
240       // Momemntum at the inner wall of the TPC
241       Double_t pTPC = 0., ptTPC = 0.;
242       AliTrackReference *ref = FindTrackReference(mcpart, 80, 270, AliTrackReference::kTPC);
243       if(ref){
244         pTPC = ref->P();
245         ptTPC = ref->Pt();
246       }
247
248
249
250     (*fDebugTree) << "MCDebug"
251                     << "centrality="          << centrality
252                     << "MBtrigger="           << isMBTrigger 
253                     << "CentralTrigger="      << isCentralTrigger
254                     << "SemicentralTrigger="  << isSemicentralTrigger
255                     << "EMCALtrigger="        << isEMCALTrigger
256                     << "run="                 << run
257                     << "p="                   << momentum
258                     << "pt="                  << transversemomentum
259                     << "eta="                 << eta
260                     << "phi="                 << phi
261                     << "pdg="                 << pdg
262                     << "ProductionVertex="    << productionVertex
263                     << "motherPdg="           << motherPdg
264                   << "source="              << source
265                     << "\n";
266     }
267   }
268   
269   AliESDtrack *track;
270   Double_t mcp, mcpt, mcptTPC, mcpTPC;  // MC Variables added to the debug tree
271   for(Int_t itrack = 0; itrack < fInputEvent->GetNumberOfTracks(); itrack++){
272     // fill the tree
273     track = dynamic_cast<AliESDtrack *>(fInputEvent->GetTrack(itrack));
274     if(!track) continue;
275     // Cut track (Only basic track cuts)
276     if(!fTrackCuts->CheckParticleCuts(AliHFEcuts::kNcutStepsMCTrack + AliHFEcuts::kStepRecKineITSTPC, track)) continue;
277     // Debug streaming of PID-related quantities
278     copyTrack.~AliESDtrack();
279     new(&copyTrack) AliESDtrack(*track);
280     if(fTPCpid->HasEtaCorrection()) fTPCpid->ApplyEtaCorrection(&copyTrack, AliHFEpidObject::kESDanalysis); // Apply Eta Correction on copy track
281     Double_t nSigmaTOF = pid->NumberOfSigmasTOF(track, AliPID::kElectron);
282     Double_t nSigmaTPC = pid->NumberOfSigmasTPC(&copyTrack, AliPID::kElectron);
283     //if(TMath::Abs(nSigmaTOF) > 5) continue;
284     // we are not interested in tracks which are more than 5 sigma away from the electron hypothesis in either TOF or TPC
285     Double_t tPCdEdx = track->GetTPCsignal();
286     // Signal, source and MCPID
287     Bool_t signal = kTRUE;
288     source = 5;
289     mcp = mcpt = mcpTPC = mcptTPC = 0.;
290
291
292
293     Double_t bgcategory = 0.;
294     Int_t mArr = -1;
295     Int_t mesonID = -999;
296     Double_t xr[3]={-999,-999,-999};
297     Double_t eR=-999;
298     Double_t eZ=-999;
299     Double_t unique=-999;
300     Double_t mesonunique=-999;
301     Double_t mesonR=-999;
302     Double_t mesonZ=-999;
303     Double_t mesonMomPdg=-999;
304     Double_t mesonMomPt=-999;
305     Double_t mesonGMomPdg=-999;
306     Double_t mesonGGMomPdg=-999;
307     Double_t mesonPt = -999;
308     Double_t mceta = -999;
309     Double_t mcphi = -999;
310     Int_t mcpdg;
311
312     if(mcthere){
313       // Signal
314       AliMCParticle *mctrack;
315       if((mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(track->GetLabel()))))){
316         if(!fTrackCuts->CheckParticleCuts(AliHFEcuts::kStepMCGenerated, mctrack)) signal = kFALSE; 
317       }
318   
319       // Source
320       if(fSignalCuts->IsCharmElectron(track)) source = 0;
321       else if(fSignalCuts->IsBeautyElectron(track)) source = 1;
322       else if(fSignalCuts->IsGammaElectron(track)) source = 2;
323       else if(fSignalCuts->IsNonHFElectron(track)) source = 3;
324       else if(mctrack && (TMath::Abs(mctrack->Particle()->GetPdgCode()) == 11)) source = 4;
325       else source = 5;
326
327       if(!mctrack) continue;
328
329       // Kinematics
330       mcpt  = mctrack->Pt();
331       mcp   = mctrack->P();
332       mceta = mctrack->Eta();
333       mcphi = mctrack->Phi();
334       mcpdg = mctrack->Particle()->GetPdgCode();
335
336       AliTrackReference *ref = FindTrackReference(mctrack, 80, 270, AliTrackReference::kTPC);
337       if(ref){
338         mcpTPC = ref->P();
339         mcptTPC = ref->Pt();
340       }
341
342     
343       TParticle *mctrack1 = mctrack->Particle();
344       mesonID=GetElecSourceMC(mctrack1);
345       if(mesonID==AliHFEmcQA::kGammaPi0 || mesonID==AliHFEmcQA::kPi0) mArr=0;                //pion
346       else if(mesonID==AliHFEmcQA::kGammaEta || mesonID==AliHFEmcQA::kEta) mArr=1;           //eta
347       else if(mesonID==AliHFEmcQA::kGammaOmega || mesonID==AliHFEmcQA::kOmega) mArr=2;       //omega
348       else if(mesonID==AliHFEmcQA::kGammaPhi || mesonID==AliHFEmcQA::kPhi) mArr=3;           //phi
349       else if(mesonID==AliHFEmcQA::kGammaEtaPrime || mesonID==AliHFEmcQA::kEtaPrime) mArr=4; //etaprime
350       else if(mesonID==AliHFEmcQA::kGammaRho0 || mesonID==AliHFEmcQA::kRho0) mArr=5;         //rho
351     
352       mctrack->XvYvZv(xr);
353     
354       eR= TMath::Sqrt(xr[0]*xr[0]+xr[1]*xr[1]);
355       eZ = xr[2];
356       TParticle *mctrackt = mctrack->Particle();
357       unique=mctrackt->GetUniqueID();
358     
359       AliMCParticle *mctrackmother = NULL;
360
361       if(!(mArr<0)){
362     if(mesonID>=AliHFEmcQA::kGammaPi0) {  // conversion electron, be careful with the enum odering
363         Int_t glabel=TMath::Abs(mctrack->GetMother()); // gamma label
364         if((mctrackmother = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(glabel)))){
365       glabel=TMath::Abs(mctrackmother->GetMother()); // gamma's mother's label
366       if((mctrackmother = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(glabel)))){
367           mesonPt = mctrackmother->Pt(); //meson pt
368           bgcategory = 1.;
369           mctrackmother->XvYvZv(xr);
370           mesonR = TMath::Sqrt(xr[0]*xr[0]+xr[1]*xr[1]);
371           mesonZ = xr[2];
372
373           mctrackt = mctrackmother->Particle();
374           if(mctrackt){
375         mesonunique = mctrackt->GetUniqueID();
376           }
377           if(glabel>fMCEvent->GetNumberOfPrimaries()) {
378         bgcategory = 2.;
379         glabel=TMath::Abs(mctrackmother->GetMother()); // gamma's mother's mother
380         if((mctrackmother = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(glabel)))){
381             mesonMomPdg=mctrackmother->PdgCode();
382             mesonMomPt=mctrackmother->Pt();
383             if(TMath::Abs(mctrackmother->PdgCode())==310){
384           bgcategory = 3.;
385           glabel=TMath::Abs(mctrackmother->GetMother()); // gamma's mother's mother's mother
386           if((mctrackmother = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(glabel)))){
387               mesonGMomPdg=mctrackmother->PdgCode();
388               glabel=TMath::Abs(mctrackmother->GetMother()); // gamma's mother's mother
389               if((mctrackmother = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(glabel)))){
390             mesonGGMomPdg=mctrackmother->PdgCode();
391               }
392           }
393             }
394         }
395           }
396       }
397         }
398     }
399     else{ // nonHFE except for the conversion electron
400         Int_t glabel=TMath::Abs(mctrack->GetMother());
401         if((mctrackmother = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(glabel)))){
402       mesonPt = mctrackmother->Pt(); //meson pt
403       bgcategory = -1.;
404       mctrackmother->XvYvZv(xr);
405       mesonR = TMath::Sqrt(xr[0]*xr[0]+xr[1]*xr[1]);
406       mesonZ = xr[2];
407
408       mctrackt = mctrackmother->Particle();
409       if(mctrackt){
410           mesonunique = mctrackt->GetUniqueID();
411       }
412       if(glabel>fMCEvent->GetNumberOfPrimaries()) {
413           bgcategory = -2.;
414           glabel=TMath::Abs(mctrackmother->GetMother()); // gamma's mother's mother
415           if((mctrackmother = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(glabel)))){
416         mesonMomPdg=mctrackmother->PdgCode();
417         mesonMomPt=mctrackmother->Pt();
418         if(TMath::Abs(mctrackmother->PdgCode())==310){
419             bgcategory = -3.;
420             glabel=TMath::Abs(mctrackmother->GetMother()); // gamma's mother's mother's mother
421             if((mctrackmother = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(glabel)))){
422                                   mesonGMomPdg=mctrackmother->PdgCode();
423           glabel=TMath::Abs(mctrackmother->GetMother()); // gamma's mother's mother
424           if((mctrackmother = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(glabel)))){
425                                     mesonGGMomPdg=mctrackmother->PdgCode();
426           }
427             }
428         }
429           }
430       }
431         }
432     }
433       }
434
435
436
437     }
438     // Get V0 tag (if available)
439     Int_t v0pid = -1;
440     if(track->TestBit(BIT(14))) v0pid = AliPID::kElectron;
441     else if(track->TestBit(BIT(15))) v0pid = AliPID::kPion;
442     else if(track->TestBit(BIT(16))) v0pid = AliPID::kProton;
443     // Kinematics
444     charge = track->Charge() > 0 ? 1. : -1.;
445     eta = track->Eta();
446     phi = track->Phi();
447     momentum = track->P() * charge;
448     transversemomentum = track->Pt() * charge;
449     Double_t momentumTPC = track->GetTPCInnerParam() ? track->GetTPCInnerParam()->P() : 0.;
450     Double_t transversemomentumTPC = track->GetTPCInnerParam() ? track->GetTPCInnerParam()->Pt() : 0.;
451     // ITS number of clusters
452     UChar_t nclustersITS = track->GetITSclusters(NULL);
453     Double_t chi2matching =  track->GetChi2TPCConstrainedVsGlobal(dynamic_cast<const AliESDVertex *>(vertex));
454     Double_t chi2PerClusterITS = 0.0;
455     if (nclustersITS != 0) chi2PerClusterITS = track->GetITSchi2() / Float_t(nclustersITS);
456     // TPC number of clusters (different definitions)
457     UChar_t nclustersTPC = track->GetTPCncls();
458     UChar_t nclustersTPCPID = track->GetTPCsignalN();
459     UChar_t nfindableTPC =  track->GetTPCNclsF();
460     Double_t clusterRatioTPC = 0.0;
461     if((static_cast<Double_t>(nfindableTPC))>0.0) clusterRatioTPC = static_cast<Double_t>(nclustersTPC)/static_cast<Double_t>(nfindableTPC);
462     UChar_t nclustersTPCshared = 0;
463     Float_t ncrossedRowsTPC = track->GetTPCCrossedRows();
464     const TBits &sharedTPC = track->GetTPCSharedMap();
465     for(Int_t ibit = 0; ibit < 160; ibit++) if(sharedTPC.TestBitNumber(ibit)) nclustersTPCshared++;
466     // TRD clusters and tracklets
467     UChar_t nclustersTRD = track->GetTRDncls();
468     UChar_t ntrackletsTRDPID = track->GetTRDntrackletsPID();
469     // ITS and TRD acceptance maps
470     UChar_t hasClusterITS[6], hasTrackletTRD[6];
471     UChar_t itsPixel = track->GetITSClusterMap();
472     for(Int_t icl = 0; icl < 6; icl++) hasClusterITS[icl] = TESTBIT(itsPixel, icl) ? 1 : 0;
473     Double_t trddEdxSum[6];
474     for(Int_t a=0;a<6;a++) { trddEdxSum[a]= 0.;}
475     for(Int_t itl = 0; itl < 6; itl++){
476       Int_t nSliceNonZero = 0;
477       trddEdxSum[itl] = track->GetTRDslice(itl, 0); // in new reconstruction slice 0 contains the total charge
478       for(Int_t islice = 0; islice < 8; islice++){
479         if(track->GetTRDslice(itl, islice) > 0.001) nSliceNonZero++;
480       }
481       hasTrackletTRD[itl] = nSliceNonZero ? 1 : 0;
482     }
483     // TRD PID
484     Double_t pidprobs[5];
485     track->GetTRDpid(pidprobs);
486     Double_t likeEleTRD = pidprobs[0];
487     Double_t likeEleTRDn = likeEleTRD/(likeEleTRD + pidprobs[2]);
488     Double_t trdtruncmean1 = fTRDpid->GetTRDSignalV1(track, 0.6);
489     Double_t trdtruncmean2 = fTRDpid->GetTRDSignalV2(track, 0.6);
490
491     // DCA
492     Float_t b[2] = {0.,0.};
493     Float_t bCov[3] = {0.,0.,0.};
494     track->GetImpactParameters(b,bCov);
495     Double_t dca = TMath::Sqrt(b[0]*b[0]+b[1]*b[1]); // impact parameter space
496     Double_t dcaSR=0, dcaSZ=0;
497     if(bCov[0]>0) dcaSR = b[0]/TMath::Sqrt(bCov[0]); // normalised impact parameter xy
498     if(bCov[2]>0) dcaSZ = b[1]/TMath::Sqrt(bCov[2]); // normalised impact parameter z
499     Double_t dcaS = AliESDtrackCuts::GetSigmaToVertex(track); // n_sigma
500
501     // HFE DCA
502     Double_t hfeb[2] = {-99.,-99.};
503     Double_t hfebCov[3] = {-999.,-999.,-999.};
504     fExtraCuts->GetHFEImpactParameters(track, hfeb, hfebCov);
505
506     Double_t tofdx= -999.0;
507     Double_t tofdz= -999.0;
508     tofdx=track->GetTOFsignalDx();
509     tofdz=track->GetTOFsignalDz();
510
511     // Fill Tree
512     (*fDebugTree) << "PIDdebug"
513                   << "centrality="          << centrality
514                   << "MBtrigger="           << isMBTrigger 
515                   << "CentralTrigger="      << isCentralTrigger
516                   << "SemicentralTrigger="  << isSemicentralTrigger
517                   << "EMCALtrigger="        << isEMCALTrigger
518                   << "signal="              << signal
519                   << "source="              << source
520                   << "v0pid="               << v0pid
521                   << "run="                 << run
522                   << "p="                   << momentum
523                   << "ptpc="                << momentumTPC
524                   << "pt="                  << transversemomentum
525                   << "pttpc="               << transversemomentumTPC
526                   << "mcp="                 << mcp
527                   << "mcpt="                << mcpt
528                   << "mcpTPC="              << mcpTPC
529                   << "mcptTPC="             << mcptTPC
530                   << "mceta="               << mceta
531                   << "mcphi="               << mcphi
532                   << "mcpdg="               << mcpdg
533                   << "eta="                 << eta
534                   << "phi="                 << phi
535                   << "ntracklets="          << ntrackletsTRDPID
536                   << "nclustersTPC="        << nclustersTPC
537                   << "nclustersTPCPID="     << nclustersTPCPID
538                   << "nclustersTPCshared="  << nclustersTPCshared
539                   << "ncrossedRowsTPC="     << ncrossedRowsTPC
540                   << "clusterRatioTPC="     << clusterRatioTPC
541                   << "nclustersITS="        << nclustersITS
542                   << "nclusters="           << nclustersTRD
543                   << "chi2matching="        << chi2matching
544       << "chi2PerClusterITS="   << chi2PerClusterITS
545                   << "its0="                << hasClusterITS[0]
546                   << "its1="                << hasClusterITS[1]
547                   << "its2="                << hasClusterITS[2]
548                   << "its3="                << hasClusterITS[3]
549                   << "its4="                << hasClusterITS[4]
550                   << "its5="                << hasClusterITS[5]
551                   << "trd0="                << hasTrackletTRD[0]
552                   << "trd1="                << hasTrackletTRD[1]
553                   << "trd2="                << hasTrackletTRD[2]
554                   << "trd3="                << hasTrackletTRD[3]
555                   << "trd4="                << hasTrackletTRD[4]
556                   << "trd5="                << hasTrackletTRD[5]
557             << "TRDdEdxl0="           << trddEdxSum[0]
558             << "TRDdEdxl1="           << trddEdxSum[1]
559             << "TRDdEdxl2="           << trddEdxSum[2]
560             << "TRDdEdxl3="           << trddEdxSum[3]
561             << "TRDdEdxl4="           << trddEdxSum[4]
562             << "TRDdEdxl5="           << trddEdxSum[5]
563                   << "TOFsigmaEl="          << nSigmaTOF
564                   << "TPCsigmaEl="          << nSigmaTPC
565                   << "TPCdEdx="             << tPCdEdx
566                   << "TRDlikeEl="           << likeEleTRD
567                   << "TRDlikeEln="          << likeEleTRDn
568             << "trdtruncmean1="       << trdtruncmean1
569                   << "trdtruncmean2="       << trdtruncmean2
570                   << "dcaR="                << b[0]
571                   << "dcaZ="                << b[1]
572                   << "dca="                 << dca
573                   << "dcaSR="               << dcaSR
574                   << "dcaSZ="               << dcaSZ
575                   << "dcaS="                << dcaS
576                   << "hfedcaR="             << hfeb[0]
577                   << "hfedcaZ="             << hfeb[1]
578                   << "hfedcacovR="          << hfebCov[0]
579                   << "hfedcacovZ="          << hfebCov[2]
580                   << "vx="                  << vtx[0]
581                   << "vy="                  << vtx[1]
582                   << "vz="                  << vtx[2]
583             << "tofdx="                << tofdx
584             << "tofdz="                << tofdz
585             << "ncontrib="            << ncontrib
586             << "mesonID="             << mesonID
587             << "eR="                  << eR
588             << "mesonR="              << mesonR
589             << "eZ="                  << eZ
590             << "mesonZ="              << mesonZ
591             << "unique="              << unique
592             << "mesonunique="         << mesonunique
593             << "bgcategory="          << bgcategory
594             << "mesonpt="             << mesonPt
595                   << "mesonMomPdg="         << mesonMomPdg
596                   << "mesonGMomPdg="         << mesonGMomPdg
597                   << "mesonGGMomPdg="         << mesonGGMomPdg
598                   << "mesonMomPt="         << mesonMomPt
599                   << "\n";
600   }
601 }
602
603
604 void AliHFEdebugTreeTask::SetFileName(const char *filename){ fFilename = filename; }
605 //___________________________________________________________
606 AliTrackReference *AliHFEdebugTreeTask::FindTrackReference(AliMCParticle *track, Float_t minRadius, Float_t maxRadius, Int_t detectorID)
607 {
608   //
609   // Find the track reference
610   //
611   AliTrackReference *ref = NULL, *reftmp;
612   Float_t radius;
613   for(Int_t iref = 0; iref < track->GetNumberOfTrackReferences(); iref++){
614     reftmp = track->GetTrackReference(iref);
615     if(reftmp->DetectorId() != detectorID) continue;
616     radius = reftmp->R();
617     if(radius >= minRadius && radius < maxRadius){
618       ref = reftmp;
619       break;
620     } 
621     if(radius > maxRadius) break;
622   }
623   return ref;
624 }
625
626 //__________________________________________
627 Int_t AliHFEdebugTreeTask::GetElecSourceMC(TParticle * const mcpart)
628 {
629   // decay particle's origin 
630
631   if(!mcpart){
632     AliDebug(1, "no mcparticle, return\n");
633     return -1;
634   }
635
636   if ( abs(mcpart->GetPdgCode()) != AliHFEmcQA::kElectronPDG ) return AliHFEmcQA::kMisID;
637
638   Int_t origin = -1;
639   Bool_t isFinalOpenCharm = kFALSE;
640
641   Int_t iLabel = mcpart->GetFirstMother();
642   if (iLabel<0){
643     AliDebug(1, "Stack label is negative, return\n");
644     return -1;
645   }
646
647   AliMCParticle *mctrack = NULL;
648   Int_t tmpMomLabel=0;
649   if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(iLabel))))) return -1; 
650   TParticle *partMother = mctrack->Particle();
651   TParticle *partMotherCopy = mctrack->Particle();
652   Int_t maPdgcode = partMother->GetPdgCode();
653
654   // if the mother is charmed hadron  
655   if ( (int(abs(maPdgcode)/100.)%10) == AliHFEmcQA::kCharm || (int(abs(maPdgcode)/1000.)%10) == AliHFEmcQA::kCharm ) {
656
657     for (Int_t i=0; i<fNparents; i++){
658         if (abs(maPdgcode)==fParentSelect[0][i]){
659           isFinalOpenCharm = kTRUE;
660         }
661     }
662     if (!isFinalOpenCharm) return -1;
663
664     // iterate until you find B hadron as a mother or become top ancester 
665     for (Int_t i=1; i<fgkMaxIter; i++){
666
667         Int_t jLabel = partMother->GetFirstMother();
668         if (jLabel == -1){
669           origin = AliHFEmcQA::kDirectCharm;
670           return origin;
671         }
672         if (jLabel < 0){ // safety protection
673           AliDebug(1, "Stack label is negative, return\n");
674           return -1;
675         }
676
677         // if there is an ancester
678         if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(jLabel))))) return -1; 
679         TParticle* grandMa = mctrack->Particle();
680         Int_t grandMaPDG = grandMa->GetPdgCode();
681
682         for (Int_t j=0; j<fNparents; j++){
683           if (abs(grandMaPDG)==fParentSelect[1][j]){
684             origin = AliHFEmcQA::kBeautyCharm;
685             return origin;
686           }
687         }
688
689         partMother = grandMa;
690     } // end of iteration 
691   } // end of if
692   else if ( (int(abs(maPdgcode)/100.)%10) == AliHFEmcQA::kBeauty || (int(abs(maPdgcode)/1000.)%10) == AliHFEmcQA::kBeauty ) {
693     for (Int_t i=0; i<fNparents; i++){
694         if (abs(maPdgcode)==fParentSelect[1][i]){
695           origin = AliHFEmcQA::kDirectBeauty;
696           return origin;
697         }
698     }
699   } // end of if
700   else if ( abs(maPdgcode) == 22 ) { //conversion
701
702     tmpMomLabel = partMotherCopy->GetFirstMother();
703     if(!(mctrack = dynamic_cast<AliMCParticle *>(fMCEvent->GetTrack(TMath::Abs(tmpMomLabel))))) return -1;
704     partMother = mctrack->Particle();
705     maPdgcode = partMother->GetPdgCode();
706     if ( abs(maPdgcode) == 111 ) {
707       origin = AliHFEmcQA::kGammaPi0;
708       return origin;
709     } 
710     else if ( abs(maPdgcode) == 221 ) {
711       origin = AliHFEmcQA::kGammaEta;
712       return origin;
713     } 
714     else if ( abs(maPdgcode) == 223 ) {
715       origin = AliHFEmcQA::kGammaOmega;
716       return origin;
717     } 
718     else if ( abs(maPdgcode) == 333 ) {
719       origin = AliHFEmcQA::kGammaPhi;
720       return origin;
721     }
722     else if ( abs(maPdgcode) == 331 ) {
723       origin = AliHFEmcQA::kGammaEtaPrime;
724       return origin; 
725     }
726     else if ( abs(maPdgcode) == 113 ) {
727       origin = AliHFEmcQA::kGammaRho0;
728       return origin;
729     }
730     else origin = AliHFEmcQA::kElse;
731     //origin = kGamma; // finer category above
732     return origin;
733
734   } // end of if
735   else if ( abs(maPdgcode) == 111 ) {
736     origin = AliHFEmcQA::kPi0;
737     return origin;
738   } // end of if
739   else if ( abs(maPdgcode) == 221 ) {
740     origin = AliHFEmcQA::kEta;
741     return origin;
742   } // end of if
743   else if ( abs(maPdgcode) == 223 ) {
744     origin = AliHFEmcQA::kOmega;
745     return origin;
746   } // end of if
747   else if ( abs(maPdgcode) == 333 ) {
748     origin = AliHFEmcQA::kPhi;
749     return origin;
750   } // end of if
751   else if ( abs(maPdgcode) == 331 ) {
752     origin = AliHFEmcQA::kEtaPrime;
753     return origin;
754   } // end of if
755   else if ( abs(maPdgcode) == 113 ) {
756     origin = AliHFEmcQA::kRho0;
757     return origin;
758   } // end of if
759   else{ 
760     origin = AliHFEmcQA::kElse;
761   }
762   return origin;
763 }