Input histograms with crystal amplitudes for Shuttle
[u/mrichter/AliRoot.git] / JETAN / AliJetESDReader.cxx
CommitLineData
99e5fe42 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 **************************************************************************/
1994c1b0 15
16//-------------------------------------------------------------------------
99e5fe42 17// Jet ESD Reader
18// ESD reader for jet analysis
83a444b1 19// Author: Mercedes Lopez Noriega (mercedes.lopez.noriega@cern.ch)
1994c1b0 20//-------------------------------------------------------------------------
21
99e5fe42 22
23#include <Riostream.h>
24#include <TSystem.h>
25#include <TLorentzVector.h>
83a444b1 26#include <TVector3.h>
99e5fe42 27#include "AliJetESDReader.h"
28#include "AliJetESDReaderHeader.h"
29#include "AliESD.h"
30#include "AliESDtrack.h"
31
32ClassImp(AliJetESDReader)
33
1b7d5d7e 34AliJetESDReader::AliJetESDReader():
35 fMass(0),
36 fSign(0)
99e5fe42 37{
38 // Constructor
99e5fe42 39 fReaderHeader = 0x0;
99e5fe42 40}
41
42//____________________________________________________________________________
43
44AliJetESDReader::~AliJetESDReader()
45{
46 // Destructor
99e5fe42 47}
48
49//____________________________________________________________________________
50
51void AliJetESDReader::OpenInputFiles()
99e5fe42 52{
53 // chain for the ESDs
54 fChain = new TChain("esdTree");
99e5fe42 55
56 // get directory and pattern name from the header
7d0f353c 57 const char* dirName=fReaderHeader->GetDirectory();
58 const char* pattern=fReaderHeader->GetPattern();
99e5fe42 59
7d0f353c 60// // Add files matching patters to the chain
61
62 void *dir = gSystem->OpenDirectory(dirName);
63 const char *name = 0x0;
64 int nesd = fReaderHeader->GetNesd();
65 int a = 0;
66 while ((name = gSystem->GetDirEntry(dir))){
67 if (a>=nesd) continue;
68
69 if (strstr(name,pattern)){
70 char path[256];
71 sprintf(path,"%s/%s/AliESDs.root",dirName,name);
72 fChain->AddFile(path);
73 a++;
74 }
75 }
1994c1b0 76
77 gSystem->FreeDirectory(dir);
7d0f353c 78
79
80 fESD = 0;
1994c1b0 81 fChain->SetBranchAddress("ESD", &fESD);
82
99e5fe42 83 int nMax = fChain->GetEntries();
7d0f353c 84
99e5fe42 85 printf("\nTotal number of events in chain= %d",nMax);
1994c1b0 86
99e5fe42 87 // set number of events in header
88 if (fReaderHeader->GetLastEvent() == -1)
89 fReaderHeader->SetLastEvent(nMax);
90 else {
91 Int_t nUsr = fReaderHeader->GetLastEvent();
92 fReaderHeader->SetLastEvent(TMath::Min(nMax,nUsr));
93 }
94}
95
7d0f353c 96void AliJetESDReader::ConnectTree(TTree* tree) {
97 fChain = (TChain*) tree;
98
99 fChain->SetBranchAddress("ESD", &fESD);
100 Int_t nMax = fChain->GetEntries();
101 printf("\nTotal number of events in chain= %5d", nMax);
102 // set number of events in header
103 if (fReaderHeader->GetLastEvent() == -1)
104 fReaderHeader->SetLastEvent(nMax);
105 else {
106 Int_t nUsr = fReaderHeader->GetLastEvent();
107 fReaderHeader->SetLastEvent(TMath::Min(nMax,nUsr));
108 }
109}
110
99e5fe42 111//____________________________________________________________________________
112
7d0f353c 113Bool_t AliJetESDReader::FillMomentumArray(Int_t event)
99e5fe42 114{
1994c1b0 115 // Fill momentum array
116
99e5fe42 117 Int_t goodTrack = 0;
118 Int_t nt = 0;
83a444b1 119 Float_t pt, eta;
120 TVector3 p3;
1994c1b0 121
99e5fe42 122 // clear momentum array
7d0f353c 123 ClearArray();
1994c1b0 124
99e5fe42 125 // get event from chain
7d0f353c 126 fChain->GetTree()->GetEntry(event);
127
128 if (!fESD) {
129 return kFALSE;
130 }
1994c1b0 131
99e5fe42 132 // get number of tracks in event (for the loop)
133 nt = fESD->GetNumberOfTracks();
1994c1b0 134 // temporary storage of signal and pt cut flag
83a444b1 135 Int_t* sflag = new Int_t[nt];
136 Int_t* cflag = new Int_t[nt];
1994c1b0 137
99e5fe42 138 // get cuts set by user
7d0f353c 139 Float_t ptMin = fReaderHeader->GetPtCut();
83a444b1 140 Float_t etaMin = fReaderHeader->GetFiducialEtaMin();
141 Float_t etaMax = fReaderHeader->GetFiducialEtaMax();
1994c1b0 142
99e5fe42 143 //loop over tracks
144 for (Int_t it = 0; it < nt; it++) {
7d0f353c 145 AliESDtrack *track = fESD->GetTrack(it);
146 UInt_t status = track->GetStatus();
147
148 Double_t mom[3];
149 track->GetPxPyPz(mom);
150 p3.SetXYZ(mom[0],mom[1],mom[2]);
151 pt = p3.Pt();
152 if ((status & AliESDtrack::kTPCrefit) == 0) continue; // quality check
153 if ((status & AliESDtrack::kITSrefit) == 0) continue; // quality check
154 if (((AliJetESDReaderHeader*) fReaderHeader)->ReadSignalOnly()
155 && TMath::Abs(track->GetLabel()) > 10000) continue; // quality check
156 if (((AliJetESDReaderHeader*) fReaderHeader)->ReadBkgdOnly()
157 && TMath::Abs(track->GetLabel()) < 10000) continue; // quality check
158 eta = p3.Eta();
159 if ( (eta > etaMax) || (eta < etaMin)) continue; // checking eta cut
160
161 new ((*fMomentumArray)[goodTrack]) TLorentzVector(p3,p3.Mag());
162 sflag[goodTrack]=0;
163 if (TMath::Abs(track->GetLabel()) < 10000) sflag[goodTrack]=1;
164 cflag[goodTrack]=0;
165 if (pt > ptMin) cflag[goodTrack]=1; // pt cut
166 goodTrack++;
99e5fe42 167 }
8011d399 168 // set the signal flags
83a444b1 169 fSignalFlag.Set(goodTrack,sflag);
170 fCutFlag.Set(goodTrack,cflag);
7d0f353c 171 return kTRUE;
99e5fe42 172}
173
7d0f353c 174
175
99e5fe42 176