]> git.uio.no Git - u/mrichter/AliRoot.git/blob - JETAN/AliJetESDReader.cxx
MUON trigger classes to collaborate with CTP (E. Lopez Torres)
[u/mrichter/AliRoot.git] / JETAN / AliJetESDReader.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 // Jet ESD Reader 
17 // ESD reader for jet analysis
18 // Author: Mercedes Lopez Noriega (mercedes.lopez.noriega@cern.ch)
19
20 #include <Riostream.h>
21 #include <TSystem.h>
22 #include <TLorentzVector.h>
23 #include <TVector3.h>
24 #include "AliJetESDReader.h"
25 #include "AliJetESDReaderHeader.h"
26 #include "AliESD.h"
27 #include "AliESDtrack.h"
28
29 ClassImp(AliJetESDReader)
30
31 AliJetESDReader::AliJetESDReader()
32 {
33   // Constructor    
34   printf("\nIn reader constructor\n");
35   fReaderHeader = 0x0;
36   fMass = 0;
37   fSign = 0;
38 }
39
40 //____________________________________________________________________________
41
42 AliJetESDReader::~AliJetESDReader()
43 {
44   // Destructor
45 }
46
47 //____________________________________________________________________________
48
49 void AliJetESDReader::OpenInputFiles()
50 {
51   // Open input files
52   printf("\nOpening files\n");
53   // chain for the ESDs
54   fChain   = new TChain("esdTree");
55   fChainMC = new TChain("mcStackTree");
56
57   // get directory and pattern name from the header
58   const char* dirName=fReaderHeader->GetDirectory();
59   const char* pattern=fReaderHeader->GetPattern();
60     
61   // Add files matching patters to the chain
62   void *dir  = gSystem->OpenDirectory(dirName);
63   const char *name = 0x0;
64   while ((name = gSystem->GetDirEntry(dir))){
65     if (strstr(name,pattern)){
66       printf("Adding %s\n",name);
67       char path[256];
68       sprintf(path,"%s/%s",dirName,name);
69       fChain->AddFile(path,-1);
70       fChainMC->AddFile(path,-1);
71      }
72   }
73
74   gSystem ->FreeDirectory(dir);
75   fChain  ->SetBranchAddress("ESD",    &fESD);
76   fChainMC->SetBranchAddress("Header", &fAliHeader);
77   fChainMC->SetBranchAddress("Stack",  &fArrayMC);
78
79   int nMax = fChain->GetEntries(); 
80   printf("\nTotal number of events in chain= %d",nMax);
81
82   // set number of events in header
83   if (fReaderHeader->GetLastEvent() == -1)
84     fReaderHeader->SetLastEvent(nMax);
85   else {
86     Int_t nUsr = fReaderHeader->GetLastEvent();
87     fReaderHeader->SetLastEvent(TMath::Min(nMax,nUsr));
88   }
89 }
90
91 //____________________________________________________________________________
92
93 void AliJetESDReader::FillMomentumArray(Int_t event)
94 {
95   // Fill the momentum array for each track
96   Int_t goodTrack = 0;
97   Int_t nt = 0;
98   Float_t pt, eta;
99   TVector3 p3;
100
101   // clear momentum array
102   ClearArray();
103
104   // get event from chain
105   fChain->GetEntry(event);
106   fChainMC->GetEntry(event);
107
108   // get number of tracks in event (for the loop)
109   nt = fESD->GetNumberOfTracks();
110  
111  // temporary storage of signal and pt cut flag
112   Int_t* sflag  = new Int_t[nt];
113   Int_t* cflag  = new Int_t[nt];
114
115   // get cuts set by user
116   Float_t ptMin = fReaderHeader->GetPtCut();
117   Float_t etaMin = fReaderHeader->GetFiducialEtaMin();
118   Float_t etaMax = fReaderHeader->GetFiducialEtaMax();  
119
120   //loop over tracks
121   for (Int_t it = 0; it < nt; it++) {
122       AliESDtrack *track = fESD->GetTrack(it);
123       UInt_t status = track->GetStatus();
124       p3 = track->P3();
125       pt = p3.Pt();
126       if (((status & AliESDtrack::kITSrefit) == 0) ||
127           ((status & AliESDtrack::kTPCrefit) == 0)) continue;    // quality check
128       if (((AliJetESDReaderHeader*) fReaderHeader)->ReadSignalOnly() 
129           && TMath::Abs(track->GetLabel()) > 10000)  continue;   // quality check
130       if (((AliJetESDReaderHeader*) fReaderHeader)->ReadBkgdOnly() 
131           && TMath::Abs(track->GetLabel()) < 10000)  continue;   // quality check
132       eta = p3.Eta();
133       if ( (eta > etaMax) || (eta < etaMin)) continue;           // checking eta cut
134
135       new ((*fMomentumArray)[goodTrack]) TLorentzVector(p3,p3.Mag());
136       sflag[goodTrack]=0;
137       if (TMath::Abs(track->GetLabel()) < 10000) sflag[goodTrack]=1;
138       cflag[goodTrack]=0;
139       if (pt > ptMin) cflag[goodTrack]=1;                       // pt cut
140       goodTrack++;
141   }
142   // set the signal flags
143   fSignalFlag.Set(goodTrack,sflag);
144   fCutFlag.Set(goodTrack,cflag);
145
146   //printf("\nIn event %d, number of good tracks %d \n", event, goodTrack);
147 }
148
149