]> git.uio.no Git - u/mrichter/AliRoot.git/blob - JETAN/AliJetAODReader.cxx
Using ARCH instead of PLATFORM
[u/mrichter/AliRoot.git] / JETAN / AliJetAODReader.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 //------------------------------------------------------------------------- 
17 // Jet AOD Reader 
18 // AOD reader for jet analysis
19 // Author: Davide Perrino <davide.perrino@cern.ch>
20 //------------------------------------------------------------------------- 
21
22
23 #include <Riostream.h>
24 #include <TSystem.h>
25 #include <TLorentzVector.h>
26 #include <TVector3.h>
27 #include <TChain.h>
28
29 #include "AliJetAODReader.h"
30 #include "AliJetAODReaderHeader.h"
31 #include "AliAODEvent.h"
32 #include "AliAODTrack.h"
33
34 ClassImp(AliJetAODReader)
35
36 AliJetAODReader::AliJetAODReader():
37     AliJetReader(),
38     fChain(0x0),
39     fAOD(0x0),
40     fRef(new TRefArray),
41     fDebug(0),
42     fOpt(0)
43 {
44   // Constructor    
45 }
46
47 //____________________________________________________________________________
48
49 AliJetAODReader::~AliJetAODReader()
50 {
51   // Destructor
52     delete fChain;
53     delete fAOD;
54     delete fRef;
55 }
56
57 //____________________________________________________________________________
58
59 void AliJetAODReader::OpenInputFiles()
60 {
61     // Open the necessary input files
62     // chain for the AODs
63   fChain   = new TChain("aodTree");
64
65   // get directory and pattern name from the header
66    const char* dirName=fReaderHeader->GetDirectory();
67    const char* pattern=fReaderHeader->GetPattern();
68
69 //   // Add files matching patters to the chain
70
71    void *dir  = gSystem->OpenDirectory(dirName);
72    const char *name = 0x0;
73    int naod = ((AliJetAODReaderHeader*) fReaderHeader)->GetNaod();
74    int a = 0;
75    while ((name = gSystem->GetDirEntry(dir))){
76        if (a>=naod) continue;
77        
78        if (strstr(name,pattern)){
79            char path[256];
80            sprintf(path,"%s/%s/aod.root",dirName,name);
81            fChain->AddFile(path);
82            a++;
83        }
84    }
85   
86   gSystem->FreeDirectory(dir);
87   
88
89   fAOD = 0;
90   fChain->SetBranchAddress("AOD",&fAOD);
91   
92   int nMax = fChain->GetEntries(); 
93
94   printf("\n AliJetAODReader: Total number of events in chain= %d \n",nMax);
95   
96   // set number of events in header
97   if (fReaderHeader->GetLastEvent() == -1)
98     fReaderHeader->SetLastEvent(nMax);
99   else {
100     Int_t nUsr = fReaderHeader->GetLastEvent();
101     fReaderHeader->SetLastEvent(TMath::Min(nMax,nUsr));
102   }
103 }
104
105 //____________________________________________________________________________
106
107 void AliJetAODReader::ConnectTree(TTree* tree, TObject* /*data*/) {
108     // Connect the tree
109     // For AOD reader it's needed only to set the number of events
110      fChain = (TChain*)      tree;
111      
112      Int_t nMax = fChain->GetEntries(); 
113      printf("\n AliJetAODReader: Total number of events in chain= %5d \n", nMax);
114      // set number of events in header
115      if (fReaderHeader->GetLastEvent() == -1)
116          fReaderHeader->SetLastEvent(nMax);
117      else {
118          Int_t nUsr = fReaderHeader->GetLastEvent();
119          fReaderHeader->SetLastEvent(TMath::Min(nMax,nUsr));
120      }
121 }
122
123 //____________________________________________________________________________
124
125 Bool_t AliJetAODReader::FillMomentumArray()
126 {
127   // Clear momentum array
128   ClearArray();
129   fDebug = fReaderHeader->GetDebug();
130   
131   if (!fAOD) {
132       return kFALSE;
133   }
134   
135   // get number of tracks in event (for the loop)
136   Int_t nt = fAOD->GetNTracks();
137   printf("AOD tracks: %5d ", nt);
138   
139   // temporary storage of signal and pt cut flag
140   Int_t* sflag  = new Int_t[nt];
141   Int_t* cflag  = new Int_t[nt];
142   
143   // get cuts set by user
144   Float_t ptMin =  fReaderHeader->GetPtCut();
145   Float_t etaMin = fReaderHeader->GetFiducialEtaMin();
146   Float_t etaMax = fReaderHeader->GetFiducialEtaMax();  
147   UInt_t  filterMask =  ((AliJetAODReaderHeader*)fReaderHeader)->GetTestFilterMask();
148   //loop over tracks
149   Int_t aodTrack = 0;
150   Float_t pt, eta;
151   TVector3 p3;
152
153   for (Int_t it = 0; it < nt; it++) {
154     AliAODTrack *track = fAOD->GetTrack(it);
155     
156     Double_t mom[3] = {track->Px(),track->Py(),track->Pz()};
157     p3.SetXYZ(mom[0],mom[1],mom[2]);
158     pt = p3.Pt();
159     eta = p3.Eta();
160     if((filterMask>0)&&!(track->TestFilterBit(filterMask)))continue;
161     if ( pt < ptMin )                      continue;      // checking pt  cut
162     if ( (eta > etaMax) || (eta < etaMin)) continue;      // checking eta cut
163     sflag[aodTrack]=1;
164     cflag[aodTrack]=1;
165     new ((*fMomentumArray)[aodTrack++]) TLorentzVector(p3,p3.Mag());
166     fRef->Add(track);
167   }
168   printf("Used AOD tracks: %5d ", aodTrack);
169   // set the signal flags
170   fSignalFlag.Set(aodTrack,sflag);
171   fCutFlag.Set(aodTrack,cflag);
172
173   delete [] sflag;
174   delete [] cflag;
175   
176   return kTRUE;
177 }