3ae37f9dab78e997a8838d17a844623d18f40b56
[u/mrichter/AliRoot.git] / JETAN / AliJetParticlesReaderHLT.cxx
1 // $Id$
2
3 //___________________________________________________________________________
4 /////////////////////////////////////////////////////////////////////////////
5 //                                                                         //
6 // File reader for HLT tracks ESD                                          //
7 //                                                                         //
8 // loizides@ikf.uni-frankfurt.de                                           //
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include <Riostream.h>
12 #include <TMath.h>
13 #include <TString.h>
14 #include <TObjString.h>
15 #include <TTree.h>
16 #include <TFile.h>
17 #include <AliESD.h>
18 #include <AliESDtrack.h>
19 #include <AliESDHLTtrack.h>
20 #include <AliKalmanTrack.h>
21 #include <AliJetEventParticles.h>
22 #include "AliJetParticlesReaderHLT.h"
23
24 ClassImp(AliJetParticlesReaderHLT)
25
26 AliJetParticlesReaderHLT::AliJetParticlesReaderHLT(Bool_t bMapper, const Char_t* esdfilename) :
27   AliJetParticlesReaderESD(0,esdfilename),
28   fTrackerType(bMapper),
29   fMinHits(0),
30   fMinWeight(0)
31 {
32   //constructor
33 }
34
35 /********************************************************************/
36   
37 AliJetParticlesReaderHLT::AliJetParticlesReaderHLT(
38                                       Bool_t bMapper,
39                                       TObjArray* dirs,
40                                       const Char_t* esdfilename) :
41   AliJetParticlesReaderESD(0,dirs,esdfilename),
42   fTrackerType(bMapper),
43   fMinHits(0),
44   fMinWeight(0)
45
46 {
47   //constructor
48 }
49
50 /********************************************************************/
51
52 AliJetParticlesReaderHLT::~AliJetParticlesReaderHLT()
53 {
54   //desctructor
55 }
56
57 Int_t AliJetParticlesReaderHLT::ReadESD(AliESD* esd)
58 {
59   //Reads one ESD
60
61   if (esd == 0)
62    {
63      Error("ReadESD","ESD is NULL");
64      return kFALSE;
65    }
66
67   Float_t mf = esd->GetMagneticField(); 
68   if (mf <= 0.0)  
69   {
70      Error("ReadESD","Magnetic Field is 0. Skipping to next event.");
71      return kFALSE;
72   }
73   AliKalmanTrack::SetMagneticField(mf/10.);
74
75   Info("ReadESD","Reading Event %d",fCurrentDir*1000+fCurrentEvent);
76   if((!fOwner) || (fEventParticles==0)) 
77     fEventParticles = new AliJetEventParticles();
78
79   Int_t ntr=0;
80   if(fTrackerType){
81     ntr =esd->GetNumberOfHLTHoughTracks();
82     Info("ReadESD","Found %d conformal tracks.",ntr);
83   } else {
84     ntr=esd->GetNumberOfHLTHoughTracks();
85     Info("ReadESD","Found %d hough tracks.",ntr);
86   }
87   fEventParticles->Reset(ntr);
88
89   TString headdesc="";
90   headdesc+="Run ";
91   headdesc+=esd->GetRunNumber();
92   headdesc+=": Ev ";
93   headdesc+=esd->GetEventNumber();
94   fEventParticles->SetHeader(headdesc);
95
96   Double_t vertexpos[3];//vertex position
97   const AliESDVertex* kvertex = esd->GetVertex();
98   if (kvertex == 0)
99    {
100      Info("ReadESD","ESD returned NULL pointer to vertex - assuming (0.0,0.0,0.0)");
101      vertexpos[0] = 0.0;
102      vertexpos[1] = 0.0;
103      vertexpos[2] = 0.0;
104    }
105   else
106    {
107      kvertex->GetXYZ(vertexpos);
108    }
109
110   fEventParticles->SetVertex(vertexpos[0],vertexpos[1],vertexpos[2]);
111
112   for (Int_t i = 0;i<ntr; i++) {
113     AliESDHLTtrack *kesdtrack;
114     if(fTrackerType){
115       kesdtrack=esd->GetHLTConfMapTrack(i);
116     } else {
117       kesdtrack=esd->GetHLTHoughTrack(i);
118     }
119
120     if (kesdtrack == 0)
121       {
122         Error("ReadESD","Can not get track %d", i);
123         continue;
124       }
125
126     //const Float_t kpid=kesdtrack->GetPID();
127     const Int_t knhits=kesdtrack->GetNHits();
128     const Int_t kweight=kesdtrack->GetWeight();
129     //cout << i << " " << kweight << " " << knhits << endl;
130     if((fMinHits>0) && (knhits<fMinHits)) continue;    
131     if(kweight>1000) continue; //avoid ghosts 
132     if((fMinWeight>0) && (kweight<fMinWeight)) continue;
133
134     const Float_t kpx=kesdtrack->GetPx();
135     const Float_t kpy=kesdtrack->GetPy();
136     const Float_t kpz=kesdtrack->GetPz();
137     const Float_t kpt=kesdtrack->GetPt();
138     const Float_t kp=TMath::Sqrt(kpz*kpz+kpt*kpt);
139     const Float_t keta=0.5*TMath::Log((kp+kpz+1e-30)/(kp-kpz+1e-30)); 
140     const Float_t kphi=TMath::Pi()+TMath::ATan2(-kpy,-kpx);
141
142     if(IsAcceptedParticle(kpt,kphi,keta))
143       fEventParticles->AddParticle(kpx,kpy,kpz,kp,i,kesdtrack->GetMCid(),knhits,kpt,kphi,keta);
144   } //loop over tracks
145
146   return kTRUE;
147 }