]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG4/GammaConv/AliV0Reader.h
Bugfix, fixed memory leaks.
[u/mrichter/AliRoot.git] / PWG4 / GammaConv / AliV0Reader.h
1 #ifndef ALIV0READER_H
2 #define ALIV0READER_H
3 /* Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4  * See cxx source for full Copyright notice     */
5
6 ////////////////////////////////////////////////
7 //--------------------------------------------- 
8 // Class used to do analysis on conversion pairs
9 //---------------------------------------------
10 ////////////////////////////////////////////////
11
12 // --- ROOT system ---
13 #include "TObject.h" 
14 #include "AliMCEvent.h"   // for CF
15 #include "AliESDv0.h"
16 #include "AliESDEvent.h"
17 #include "AliKFParticle.h"
18 #include "TParticle.h"
19 #include "AliGammaConversionHistograms.h"
20 #include <vector>
21 #include "AliCFManager.h"
22
23
24 class TClonesArray; 
25 class TFormula;
26 class Riostream;
27 class TChain;
28
29 //--- AliRoot system ---
30
31 class AliStack;
32 class AliMCEvent;       // for CF
33 class AliESDEvent; 
34 class AliMCEventHandler;
35 class AliESDInputHandler;
36 class AliESDVertex;
37 class AliLog;
38 class TChain;
39 class TChain;
40 class AliCFManager;   // for CF
41 class AliCFContainer;  // for CF
42 class AliTPCpidESD; // for dEdx cut based on nSigma to particle lines 
43
44
45 class AliV0Reader : public TObject {
46         
47  public: 
48         
49         
50   // for CF
51   enum{
52     kStepGenerated = 0,
53     kStepReconstructable = 1, 
54     kStepLikeSign = 2,
55     kStepTPCRefit = 3,
56     kStepKinks = 4,
57     kStepGetOnFly = 5,
58     kStepNContributors = 6,
59     kStepTPCPID = 7,
60     kStepR = 8,
61     kStepLine = 9,
62     kStepZ = 10,
63     kStepNDF = 11,
64     kStepChi2 = 12,
65     kStepEta = 13,
66     kStepPt = 14
67   };
68         
69         
70         
71   AliV0Reader();                                        //constructor
72   AliV0Reader(const AliV0Reader & g);                   //copy constructor
73   AliV0Reader & operator = (const AliV0Reader & g);     //assignment operator
74   //  virtual ~AliV0Reader() {;}                            //virtual destructor
75   virtual ~AliV0Reader();                            //virtual destructor
76   /*
77    *Initialize the reader
78    */
79   void Initialize();
80         
81         
82   // for CF
83   void SetCFManager(AliCFManager * const io){fCFManager = io;};
84   AliCFManager *GetCFManager() const {return fCFManager;}
85         
86         
87         
88         
89   /*
90    * Returns  AliESDEvent
91    */                   
92   AliESDEvent* GetESDEvent() const{return fESDEvent;}   
93         
94   /*
95    *Returns the number of v0s in the event, no cuts applied.
96    */
97   Int_t GetNumberOfV0s() const{return fESDEvent->GetNumberOfV0s();}
98         
99   /*
100    * Check if there are any more good v0s left in the v0 stack
101    * if so, fCurrent v0 is set to this v0 and can be retrieved
102    * by GetCurrentV0 function.
103    * returns kFALSE if there is no more good v0s in the v0 stack
104    */
105   Bool_t NextV0();
106         
107   /*
108    * Returns the v0 at the given index, no checks are done on the v0. 
109    */
110   AliESDv0* GetV0(Int_t index);
111         
112   /*
113    * Returns the current v0
114    */
115   AliESDv0* GetCurrentV0() const{return fCurrentV0;}
116         
117   /*
118    * Returns the negative ESD track which belongs to fCurrentV0
119    */
120   AliESDtrack* GetNegativeESDTrack(){return fESDEvent->GetTrack(fCurrentV0->GetNindex());}
121         
122   /*
123    * Returns the positive ESD track which belongs to fCurrentV0
124    */
125   AliESDtrack* GetPositiveESDTrack(){return fESDEvent->GetTrack(fCurrentV0->GetPindex());}
126         
127   /*
128    * Returns the negative KF particle which belongs to fCurrentV0
129    */
130   AliKFParticle* GetNegativeKFParticle() const{return fCurrentNegativeKFParticle;}
131         
132   /*
133    * Returns the positive KF particle which belongs to fCurrentV0
134    */
135   AliKFParticle* GetPositiveKFParticle() const{return fCurrentPositiveKFParticle;}
136         
137   /*
138    * Returns the KFParticle object of the 2 tracks.
139    */
140   AliKFParticle* GetMotherCandidateKFCombination() const{return fCurrentMotherKFCandidate;}
141         
142   /*
143    * Checks the probablity that the PID of the particle is what we want it to be.
144    */
145   Bool_t CheckPIDProbability(Double_t negProbCut, Double_t posProbCut);
146         
147   /*
148    * Checks if the PID of the two particles are within our cuts.
149    */
150   void GetPIDProbability(Double_t &negPIDProb, Double_t &posPIDProb);
151         
152   /*
153    *Get the negative MC TParticle from the stack 
154    */
155   TParticle * GetNegativeMCParticle() const{return fNegativeMCParticle;}
156         
157   /*
158    *Get the positive MC TParticle from the stack 
159    */
160   TParticle * GetPositiveMCParticle() const{return fPositiveMCParticle;}
161         
162   /*
163    *Get the mother MC TParticle from the stack 
164    */
165   TParticle * GetMotherMCParticle() const{return fMotherMCParticle;}
166         
167   /*
168    * Flag to see if the v0 particles share the same mother
169    */
170   Bool_t HasSameMCMother();
171         
172         
173   /*
174    *Get the PID of the MC mother particle
175    */
176   Int_t GetMotherMCParticlePDGCode() const{if(fMotherMCParticle != NULL){ cout<<"MCParticle exists"<<endl;} return fMotherMCParticle->GetPdgCode();}
177         
178   /*
179    *Get the MC stack 
180    */
181   AliStack* GetMCStack() const{return fMCStack;}
182         
183         
184   /*
185    * Setup  AliMCEventHandler
186    */                   
187   AliMCEventHandler* GetMCTruth() const{return fMCTruth;}       // for CF
188         
189         
190   /*
191    *Get the MC stack 
192    */
193   AliMCEvent* GetMCEvent() const{return fMCEvent;}   // for CF
194         
195         
196   /*
197    *Get the magnetic field from the ESD event 
198    */
199   Double_t GetMagneticField() const{return fESDEvent->GetMagneticField();}
200         
201   /*
202    *Get the primary vertex from the esd event
203    */
204   const AliESDVertex *GetPrimaryVertex() const {return fESDEvent->GetPrimaryVertex();}
205         
206   /*
207    * Set the PID of the negative track
208    */
209   void SetNegativeTrackPID(Int_t negTrackPID){fNegativeTrackPID=negTrackPID;}
210         
211   /*
212    * Set the PID of the positive track
213    */
214   void SetPositiveTrackPID(Int_t posTrackPID){fPositiveTrackPID=posTrackPID;}
215         
216   /*
217    * Set the flag to use the kfparticle class. Will also disable the use of esd tracks
218    */
219   void UseKFParticle(){fUseKFParticle = kTRUE; fUseESDTrack = kFALSE;}
220         
221   /*
222    *  Set the flag to use the esd track class. Will also disable the use of kf particles
223    */
224   void UseESDTrack(){fUseESDTrack = kTRUE; fUseKFParticle = kFALSE;}
225         
226   /*
227    *  Set the flag to use improved vertex or not
228    */
229   void SetUseImprovedVertex(Bool_t useImprovedVertex){fUseImprovedVertex=useImprovedVertex;}
230         
231   /*
232    * Return the number in the species array belonging to the negative or positive track pid.
233    */
234   Int_t GetSpeciesIndex(Int_t chargeOfTrack);
235         
236   /*
237    * Return the x coordinate of the v0
238    */
239   Double_t GetX() const{return fCurrentXValue;}
240         
241   /*
242    * Return the y coordinate of the v0
243    */
244   Double_t GetY() const{return fCurrentYValue;}
245         
246   /*
247    * Return the Z coordinate of the v0
248    */
249   Double_t GetZ() const{return fCurrentZValue;}
250         
251   /*
252    * Return the radius of the v0
253    */
254   Double_t GetXYRadius() const{return sqrt((Double_t)(fCurrentXValue*fCurrentXValue + fCurrentYValue*fCurrentYValue));}
255         
256   /*
257    * Get the opening angle between the two tracks
258    */
259   Double_t GetOpeningAngle(){return fNegativeTrackLorentzVector->Angle(fPositiveTrackLorentzVector->Vect());}
260
261   /*
262    * Get the Cos Pointing angle between the two tracks
263    */
264   Double_t GetCosPointingAngle(){return fCurrentV0->GetV0CosineOfPointingAngle();}
265
266   /*
267    * Get the DCA between the two tracks
268    */
269   Double_t GetDcaDaughters(){return fCurrentV0->GetDcaV0Daughters();}
270
271   /*
272    * Get the Normalized DCA between the two tracks
273    */
274   Double_t GetNormDcaDistDaughters(){return fCurrentV0->GetDcaV0Daughters()/fCurrentV0->GetDistSigma();}
275
276   /*
277    * Get the Likelihood for a Conversion
278    */
279   Double_t GetLikelihoodAP(){return fCurrentV0->GetLikelihoodAP(0,0);}
280       
281   /*
282    * Gets the Energy of the negative track.
283    */
284   Double_t GetNegativeTrackEnergy() const{return fCurrentNegativeKFParticle->E();}
285         
286   /*
287    * Gets the Energy of the positive track.
288    */
289   Double_t GetPositiveTrackEnergy() const{return fCurrentPositiveKFParticle->E();}
290         
291   /*
292    * Gets the Energy of the mother candidate.
293    */
294   Double_t GetMotherCandidateEnergy() const{return fCurrentMotherKFCandidate->E();}
295         
296   /*
297    * Gets the Pt of the negative track.
298    */
299   Double_t GetNegativeTrackPt() const{return fNegativeTrackLorentzVector->Pt();}
300         
301   /*
302    * Gets the Pt of the positive track.
303    */
304   Double_t GetPositiveTrackPt() const{return fPositiveTrackLorentzVector->Pt();}
305         
306
307   /*
308    * Gets the Pt of the mother candidate.
309    */
310   Double_t GetMotherCandidatePt() const{return fMotherCandidateLorentzVector->Pt();}
311
312
313   /*
314    * Gets the P of the mother candidate.
315    */
316   Double_t GetMotherCandidateP() const{return fMotherCandidateLorentzVector->P();}
317         
318
319   /*
320    * Gets the Eta of the negative track.
321    */
322   Double_t GetNegativeTrackEta() const{return fNegativeTrackLorentzVector->Eta();}
323   /*
324    * Gets the Eta of the positive track.
325    */
326   Double_t GetPositiveTrackEta() const{return fPositiveTrackLorentzVector->Eta();}
327   /*
328    * Gets the Eta of the mother candidate.
329    */
330   Double_t GetMotherCandidateEta() const{return fMotherCandidateLorentzVector->Eta();}
331         
332   /*
333    * Gets the NDF of the mother candidate.
334    */
335   Double_t GetMotherCandidateNDF() const{return fCurrentMotherKFCandidate->GetNDF();}
336         
337   /*
338    * Gets the Chi2 of the mother candidate.
339    */
340   Double_t GetMotherCandidateChi2() const{return fCurrentMotherKFCandidate->GetChi2();}
341         
342   /*
343    * Gets the Mass of the mother candidate.
344    */
345   Double_t GetMotherCandidateMass() const{return fMotherCandidateKFMass;}
346         
347   /*
348    * Gets the Width of the mother candidate.
349    */
350   Double_t GetMotherCandidateWidth() const{return fMotherCandidateKFWidth;}
351         
352   /*
353    * Gets the Phi of the negative track.
354    */
355   Double_t GetNegativeTrackPhi() const;
356         
357   /*
358    * Gets the Phi of the positive track.
359    */
360   Double_t GetPositiveTrackPhi() const;
361         
362   /*
363    * Gets the Phi of the mother candidate.
364    */
365   Double_t GetMotherCandidatePhi() const;
366         
367   /*
368    * Gets the Rapidity of the mother candidate.
369    */
370   Double_t GetMotherCandidateRapidity() const;
371         
372
373   /*
374    * Gets the P of the negative track.
375    */
376   Double_t GetNegativeTrackP() const{return fNegativeTrackLorentzVector->P();}
377         
378   /*
379    * Gets the P of the positive track.
380    */
381   Double_t GetPositiveTrackP() const{return fPositiveTrackLorentzVector->P();}
382
383   /*
384    * Gets the dE/dx in the TPC of the negative track.
385    */
386   Double_t GetNegativeTrackTPCdEdx() const{return fCurrentNegativeESDTrack->GetTPCsignal();}
387         
388   /*
389    * Gets the dE/dx in the TPC of the positive track.
390    */
391   Double_t GetPositiveTrackTPCdEdx() const{return fCurrentPositiveESDTrack->GetTPCsignal();}
392         
393   /*
394    * Update data which need to be updated every event.
395    */
396   void UpdateEventByEventData();
397         
398   /*
399    * Gets the MaxRCut value.
400    */
401   Double_t GetMaxRCut() const{return fMaxR;}
402         
403   /*
404    * Gets the Eta cut value.
405    */
406   Double_t GetEtaCut() const{return fEtaCut;}
407         
408   /*
409    * Gets the Pt cut value.
410    */
411   Double_t GetPtCut() const{return fPtCut;}
412         
413         
414   /*
415    * Gets the MaxZCut value.
416    */
417   Double_t GetMaxZCut() const{return fMaxZ;}
418         
419         
420   /*
421    * Gets the line cut values.
422    */
423   Double_t GetLineCutZRSlope() const{return fLineCutZRSlope;}
424   Double_t GetLineCutZValue() const{return fLineCutZValue;}
425         
426   /*
427    * Gets the Chi2 cut value for the conversions.
428    */
429   Double_t GetChi2CutConversion() const{return fChi2CutConversion;}
430         
431   /*
432    * Gets the Chi2 cut value for the mesons.
433    */
434   Double_t GetChi2CutMeson() const{return fChi2CutMeson;}
435         
436   Double_t GetPositiveTrackLength() const{return fCurrentPositiveESDTrack->GetIntegratedLength();}
437   Double_t GetNegativeTrackLength() const{return fCurrentNegativeESDTrack->GetIntegratedLength();}
438         
439   Double_t GetPositiveNTPCClusters() const{return fCurrentPositiveESDTrack->GetTPCNcls();}
440   Double_t GetNegativeNTPCClusters() const{return fCurrentNegativeESDTrack->GetTPCNcls();}
441         
442   /*
443    * Sets the MaxRCut value.
444    */
445   void SetMaxRCut(Double_t maxR){fMaxR=maxR;}
446         
447   /*
448    * Sets the EtaCut value.
449    */
450   void SetEtaCut(Double_t etaCut){fEtaCut=etaCut;}
451         
452   /*
453    * Sets the PtCut value.
454    */
455   void SetPtCut(Double_t ptCut){fPtCut=ptCut;}
456         
457     
458   /*
459    * Sets the MaxZCut value.
460    */
461   void SetMaxZCut(Double_t maxZ){fMaxZ=maxZ;}
462         
463         
464   /*
465    * Sets the LineCut values.
466    */
467   void SetLineCutZRSlope(Double_t LineCutZRSlope){fLineCutZRSlope=LineCutZRSlope;}
468   void SetLineCutZValue(Double_t LineCutZValue){fLineCutZValue=LineCutZValue;}
469         
470   /*
471    * Sets the Chi2Cut value for conversions.
472    */
473   void SetChi2CutConversion(Double_t chi2){fChi2CutConversion=chi2;}
474         
475   /*
476    * Sets the Chi2Cut for the mesons.
477    */
478   void SetChi2CutMeson(Double_t chi2){fChi2CutMeson=chi2;}
479         
480   /*
481    * Sets the XVertexCut value.
482    */
483   void SetXVertexCut(Double_t xVtx){fCurrentXValue=xVtx;}
484         
485   /*
486    * Sets the YVertexCut value.
487    */
488   void SetYVertexCut(Double_t yVtx){fCurrentYValue=yVtx;}
489         
490   /*
491    * Sets the ZVertexCut value.
492    */
493   void SetZVertexCut(Double_t zVtx){fCurrentZValue=zVtx;}
494         
495   /*
496    * Sets the PIDProbabilityCut value for track particles.
497    */
498   void SetPIDProbability(Double_t pidProb){fPIDProbabilityCutPositiveParticle=pidProb; fPIDProbabilityCutNegativeParticle=pidProb;}
499         
500   /*
501    * Sets the PIDProbability cut value for the negative track.
502    */
503   void SetPIDProbabilityNegativeParticle(Double_t pidProb){fPIDProbabilityCutNegativeParticle=pidProb;}
504         
505   /*
506    * Sets the PIDProbability cut value for the positive track.
507    */
508   void SetPIDProbabilityPositiveParticle(Double_t pidProb){fPIDProbabilityCutPositiveParticle=pidProb;}
509
510   /*
511    * Sets the PIDnSigmaAboveElectron cut value for the tracks.
512    */
513   void SetPIDnSigmaAboveElectronLine(Double_t nSigmaAbove){fPIDnSigmaAboveElectronLine=nSigmaAbove;}
514         
515   /*
516    * Sets the PIDnSigmaBelowElectron cut value for the tracks.
517    */
518   void SetPIDnSigmaBelowElectronLine(Double_t nSigmaBelow){fPIDnSigmaBelowElectronLine=nSigmaBelow;}
519         
520   /*
521    * Sets the PIDnSigmaAbovePion cut value for the tracks.
522    */
523   void SetPIDnSigmaAbovePionLine(Double_t nSigmaAbovePion){fPIDnSigmaAbovePionLine=nSigmaAbovePion;}
524
525   /*
526    * Sets the PIDMinPnSigmaAbovePion cut value for the tracks.
527    */
528   void SetPIDMinPnSigmaAbovePionLine(Double_t MinPnSigmaAbovePion){fPIDMinPnSigmaAbovePionLine=MinPnSigmaAbovePion;}
529
530   /*
531    * Sets the SigmaMassCut value.
532    */
533   void SetSigmaMass(Double_t sigmaMass){fNSigmaMass=sigmaMass;}
534         
535   /*
536    * Sets the flag to enable/disable the usage of MC information. 
537    */
538   void SetDoMCTruth(Bool_t doMC){fDoMC = doMC;}
539         
540   /*
541    * Sets the flag to enable/disable the cut dedx N sigma 
542    */
543
544   void SetDodEdxSigmaCut( Bool_t dodEdxSigmaCut){fDodEdxSigmaCut=dodEdxSigmaCut;}
545
546
547   /*
548    * Updates the V0 information of the current V0.
549    */
550   Bool_t UpdateV0Information();
551         
552   /*
553    * Resets the V0 index.
554    */
555   void ResetV0IndexNumber(){fCurrentV0IndexNumber=0;}
556         
557   /*
558    * Sets the histograms.
559    */
560   void SetHistograms(AliGammaConversionHistograms * const histograms){fHistograms=histograms;}
561         
562   /*
563    * Check for primary vertex.
564    */
565   Bool_t CheckForPrimaryVertex();
566         
567   /*
568    * Gets a vector of good v0s.
569    */
570   vector<AliKFParticle> GetCurrentEventGoodV0s() const{return fCurrentEventGoodV0s;}
571         
572   /*
573    * Gets the vector of previous events v0s (for bacground analysis)
574    */
575   vector<AliKFParticle> GetPreviousEventGoodV0s() const{return fPreviousEventGoodV0s;}
576
577   void SetUseOwnXYZCalculation(Bool_t flag){fUseOwnXYZCalculation=flag;}
578
579   Bool_t GetHelixCenter(AliESDtrack* track, Double_t b,Int_t charge, Double_t center[2]);
580         
581   Bool_t GetConvPosXY(AliESDtrack* ptrack,AliESDtrack* ntrack, Double_t b, Double_t convpos[2]);
582         
583   Double_t GetConvPosZ(AliESDtrack* ptrack,AliESDtrack* ntrack, Double_t b);
584
585   void SetDoCF(Bool_t flag){fDoCF = flag;}
586
587         
588  private:
589   AliStack * fMCStack;           // pointer to MonteCarlo particle stack 
590   AliMCEventHandler* fMCTruth;   // for CF    pointer to the MC object
591   AliMCEvent *fMCEvent;                 //  for CF      pointer to MC event
592   TChain * fChain;               // pointer to the TChain
593         
594   AliESDInputHandler* fESDHandler;      //! pointer to esd object
595   AliESDEvent *fESDEvent;               //! pointer to esd object
596         
597         
598   // for CF
599   AliCFManager *fCFManager; // pointer to the cf manager
600   //  AliCFContainer *container;
601         
602   // for dEdx cut based on nSigma to a particle line
603   AliTPCpidESD * fTPCpid; 
604         
605   AliGammaConversionHistograms *fHistograms; //! pointer to histogram handling class
606         
607   Int_t fCurrentV0IndexNumber;  // the current v0 index number
608   AliESDv0 * fCurrentV0;                //! pointer to the current v0
609   AliKFParticle * fCurrentNegativeKFParticle;  //! pointer to the negative KF particle
610   AliKFParticle * fCurrentPositiveKFParticle;  //! pointer to the positive KF particle
611   AliKFParticle * fCurrentMotherKFCandidate;   //! pointer to the positive KF particle
612         
613   AliESDtrack * fCurrentNegativeESDTrack;      //! pointer to the negative ESD track
614   AliESDtrack * fCurrentPositiveESDTrack;      //! pointer to the positive ESD track
615         
616   TLorentzVector * fNegativeTrackLorentzVector; //! pointer to the negative Track Lorentz Vector
617   TLorentzVector * fPositiveTrackLorentzVector; //! pointer to the positive Track Lorentz Vector
618   TLorentzVector * fMotherCandidateLorentzVector;   //! pointer to the mother candidate Track Lorentz Vector
619         
620   Double_t fCurrentXValue;   // current x value
621   Double_t fCurrentYValue;   // current y value
622   Double_t fCurrentZValue;   // current z value
623         
624   Int_t fPositiveTrackPID;   // positive track pid
625   Int_t fNegativeTrackPID;   // negative track pid
626         
627   TParticle *fNegativeMCParticle;      //!
628   TParticle *fPositiveMCParticle;      //!
629   TParticle *fMotherMCParticle;        //!
630         
631   Double_t fMotherCandidateKFMass;   // mass of mother candidate KF particle
632   Double_t fMotherCandidateKFWidth;  // width of mother candidate KF particle
633         
634   Bool_t fUseKFParticle;   // flag 
635   Bool_t fUseESDTrack;     // flag 
636   Bool_t fDoMC;            // flag 
637         
638   //cuts
639   Double_t fMaxR; //r cut
640   Double_t fEtaCut; //eta cut
641   Double_t fPtCut; // pt cut
642   Double_t fMaxZ; //z cut  
643   Double_t fLineCutZRSlope; //linecut
644   Double_t fLineCutZValue; //linecut
645   Double_t fChi2CutConversion; //chi2cut
646   Double_t fChi2CutMeson;  //chi2cut
647   Double_t fPIDProbabilityCutNegativeParticle; //pid cut
648   Double_t fPIDProbabilityCutPositiveParticle; //pid cut
649   Bool_t   fDodEdxSigmaCut; // flag to use the dEdxCut based on sigmas
650   Double_t fPIDnSigmaAboveElectronLine;
651   Double_t fPIDnSigmaBelowElectronLine;
652   Double_t fPIDnSigmaAbovePionLine;
653   Double_t fPIDMinPnSigmaAbovePionLine;
654   Double_t fXVertexCut; //vertex cut
655   Double_t fYVertexCut; //vertex cut
656   Double_t fZVertexCut; // vertexcut
657         
658   Double_t fNSigmaMass; //nsigma cut
659         
660   Bool_t fUseImprovedVertex; //flag
661
662   Bool_t fUseOwnXYZCalculation; //flag that determines if we use our own calculation of xyz (markus)
663
664   Bool_t fDoCF;
665         
666   vector<AliKFParticle> fCurrentEventGoodV0s; //vector of good v0s
667   vector<AliKFParticle> fPreviousEventGoodV0s; // vector of good v0s from prevous events
668         
669   ClassDef(AliV0Reader,5)
670 };
671 #endif
672
673
674