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