]> git.uio.no Git - u/mrichter/AliRoot.git/blob - JETAN/AliJetAODReader.cxx
from Y. Schutz
[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(Int_t /*event*/)
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("Fill Momentum Array %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   
148   //loop over tracks
149   Int_t aodTrack = 0;
150   Float_t pt, eta;
151   TVector3 p3;
152   for (Int_t it = 0; it < nt; it++) {
153       AliAODTrack *track = fAOD->GetTrack(it);
154
155       Double_t mom[3] = {track->Px(),track->Py(),track->Pz()};
156       p3.SetXYZ(mom[0],mom[1],mom[2]);
157       pt = p3.Pt();
158       eta = p3.Eta();
159           if ( pt < ptMin )                      continue;      // checking pt  cut
160       if ( (eta > etaMax) || (eta < etaMin)) continue;      // checking eta cut
161       sflag[aodTrack]=1;
162       cflag[aodTrack]=1;
163           new ((*fMomentumArray)[aodTrack++]) TLorentzVector(p3,p3.Mag());
164           fRef->Add(track);
165   }
166   // set the signal flags
167   fSignalFlag.Set(aodTrack,sflag);
168   fCutFlag.Set(aodTrack,cflag);
169
170   return kTRUE;
171 }