]> git.uio.no Git - u/mrichter/AliRoot.git/blob - JETAN/AliJetParticlesReaderKineGoodTPC.cxx
Added class to read good tracks tpc.
[u/mrichter/AliRoot.git] / JETAN / AliJetParticlesReaderKineGoodTPC.cxx
1 // $Id$
2
3 //_______________________________________________________________________
4 /////////////////////////////////////////////////////////////////////////
5 //
6 // class AliJetParticlesReaderKineGoodTPC
7 //
8 // Reader for Good TPC tracks
9 //
10 // loizides@ikf.uni-frankfurt.de
11 //
12 /////////////////////////////////////////////////////////////////////////
13
14 #include <Riostream.h>
15 #include <TFile.h>
16 #include <TString.h>
17 #include <TParticle.h>
18 #include <TLorentzVector.h>
19 #include <AliRunLoader.h>
20 #include <AliStack.h>
21 #include <AliHeader.h>
22 #include <AliGenEventHeader.h>
23 #include <AliGenPythiaEventHeader.h>
24 #include <AliGenHijingEventHeader.h>
25 #include "AliJetParticle.h"
26 #include "AliJetEventParticles.h"
27 #include "AliJetParticlesReaderKineGoodTPC.h"
28
29 ClassImp(AliJetParticlesReaderKineGoodTPC)
30
31 AliJetParticlesReaderKineGoodTPC::AliJetParticlesReaderKineGoodTPC() :
32   AliJetParticlesReader(),
33   fFileName("good_tracks_tpc"),
34   fInput(0)
35 {
36   //constructor
37 }
38
39 AliJetParticlesReaderKineGoodTPC::AliJetParticlesReaderKineGoodTPC(TString& fname) :
40   AliJetParticlesReader(),
41   fFileName(fname),
42   fInput(0)
43 {
44   //constructor
45 }
46
47 AliJetParticlesReaderKineGoodTPC::AliJetParticlesReaderKineGoodTPC(TObjArray* dirs, const Char_t *filename):
48   AliJetParticlesReader(dirs),
49   fFileName(filename),
50   fInput(0)
51 {
52   //constructor
53 }
54
55 AliJetParticlesReaderKineGoodTPC::~AliJetParticlesReaderKineGoodTPC()
56 {
57   //destructor
58   if(fInput) delete fInput;
59 }
60
61 void AliJetParticlesReaderKineGoodTPC::Rewind()
62 {
63   //Rewinds to the beginning
64   if(fInput) delete fInput;
65   fInput       = 0;
66   fCurrentDir  = 0;
67   fNEventsRead = 0;  
68 }
69
70 Int_t AliJetParticlesReaderKineGoodTPC::ReadNext()
71 {
72   //Reads good_tpc_tracks file
73   if((!fOwner) || (fEventParticles == 0)) 
74     fEventParticles = new AliJetEventParticles();
75   else
76      fEventParticles->Reset();
77
78   while(fCurrentDir < GetNumberOfDirs())
79     { 
80       if(!OpenFile(fCurrentDir)) 
81       { 
82         delete fInput; //close current session
83         fInput = 0;    //assure pointer is null
84         fCurrentDir++;
85         continue;
86       }
87     
88       Info("ReadNext","Reading Event %d",fCurrentEvent);
89
90       Int_t label,code;
91       Float_t px,py,pz,x,y,z;
92       Int_t i=0;
93       while (*fInput>>label>>code>>px>>py>>pz>>x>>y>>z)
94       {
95         const Float_t kp2=px*px+py*py+pz*pz;
96         if(kp2<1e-3)  continue;
97         const Float_t kpt=TMath::Sqrt(px*px+py*py);
98         const Float_t kp=TMath::Sqrt(kp2);
99         const Float_t keta=0.5*TMath::Log((kp+pz+1e-30)/(kp-pz+1e-30)); 
100         const Float_t kphi=TMath::Pi()+TMath::ATan2(-py,-px);
101         //cout << i << " " << label << " " << px << " " << py << " " << pz << endl;
102         if(IsAcceptedParticle(kpt,kphi,keta))
103           fEventParticles->AddParticle(px,py,pz,kp,i++,label,code,kpt,kphi,keta);
104       }
105
106       fCurrentEvent++;
107       fNEventsRead++;
108       return kTRUE;
109
110     }
111   return kFALSE;
112 }
113
114 Int_t AliJetParticlesReaderKineGoodTPC::OpenFile(Int_t n)
115 {
116   if(fInput){ //change here if you want to 
117               //support more than one good file per dir
118     return kFALSE;
119   }
120
121   const TString& dirname = GetDirName(n);
122   if (dirname == "")
123     { 
124       Error("OpenNextFile","Can't get directory name with index %d",n);
125       return kFALSE;
126     }
127
128   TString filename = dirname +"/"+ fFileName;
129   fInput=new ifstream(filename);
130   if ( fInput->is_open() == 0)
131     {
132       Error("OpenNextFile","Can't open session from file %s",filename.Data());
133       return kFALSE;
134     }
135
136   fCurrentEvent = 0;
137   return kTRUE;
138 }