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