]> git.uio.no Git - u/mrichter/AliRoot.git/blob - JETAN/AliJetKineReader.cxx
First commit of new jet reconstruction and analysis code to be used for the
[u/mrichter/AliRoot.git] / JETAN / AliJetKineReader.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 kinematics reader 
18 // MC reader for jet analysis
19 // Author: Andreas Morsch 
20 // andreas.morsch@cern.ch
21 //
22
23 // From root ...
24 #include <TClonesArray.h>
25 #include <TPDGCode.h>
26 #include <TParticle.h>
27 #include <TParticlePDG.h>
28 #include <TVector3.h>
29 #include <TLorentzVector.h>
30 #include <TSystem.h>
31 #include <TDatabasePDG.h>
32 #include <TRandom.h>
33 // From AliRoot ...
34 #include "AliJetKineReaderHeader.h"
35 #include "AliJetKineReader.h"
36 #include "AliRunLoader.h"
37 #include "AliStack.h"
38
39 ClassImp(AliJetKineReader)
40
41 AliJetKineReader::AliJetKineReader()
42 {
43   // Constructor
44   fReaderHeader = 0x0;
45   fRunLoader    = 0x0;
46   fMass         = 0;
47   fPdgC         = 0;
48 }
49
50 //____________________________________________________________________________
51
52 AliJetKineReader::~AliJetKineReader()
53 {
54   // Destructor
55   delete fReaderHeader;
56 }
57
58 //____________________________________________________________________________
59
60 void AliJetKineReader::OpenInputFiles()
61 {
62     // Opens the input file using the run loader
63     const char* dirName = fReaderHeader->GetDirectory();
64     char path[256];
65     sprintf(path, "%s/galice.root",dirName);
66     fRunLoader = AliRunLoader::Open(path);
67     fRunLoader->LoadKinematics();
68     fRunLoader->LoadHeader(); 
69     
70     Int_t nMax = fRunLoader->GetNumberOfEvents();
71     printf("\nTotal number of events = %d", nMax);
72     
73   // set number of events in header
74     if (fReaderHeader->GetLastEvent() == -1)
75         fReaderHeader->SetLastEvent(nMax);
76     else {
77         Int_t nUsr = fReaderHeader->GetLastEvent();
78         fReaderHeader->SetLastEvent(TMath::Min(nMax, nUsr));
79     }
80 }
81
82 //____________________________________________________________________________
83
84 void AliJetKineReader::FillMomentumArray(Int_t event)
85 {
86 //
87 // Fill momentum array for event
88 //
89     Int_t goodTrack = 0;
90     // Clear array
91     ClearArray();
92
93     fRunLoader->GetEvent(event);
94     AliStack* stack = fRunLoader->Stack();
95     Int_t nt = stack->GetNprimary();
96     // Get cuts set by user
97     Double_t ptMin = ((AliJetKineReaderHeader*) fReaderHeader)->GetPtCut();
98     fAliHeader = fRunLoader->GetHeader();
99         
100     // Loop over particles
101     for (Int_t it = 0; it < nt; it++) {
102         TParticle *part = stack->Particle(it);
103         Int_t   status  = part->GetStatusCode();
104         Int_t   pdg     = TMath::Abs(part->GetPdgCode());
105         Float_t pt      = part->Pt(); 
106         
107         if (
108             (status != 1)            
109             || (pdg == 12 || pdg == 14) 
110             || (pt < ptMin)             
111             ) continue; 
112
113         if (((AliJetKineReaderHeader*)fReaderHeader)->FastSimTPC()) {
114             Float_t charge = TDatabasePDG::Instance()->GetParticle(pdg)->Charge();
115               if (
116                   (charge == 0)  
117                   || (gRandom->Rndm() < 0.1) 
118                   ) continue;
119         }
120         
121         fMass = part->GetCalcMass();
122         fPdgC = part->GetPdgCode();
123         // Fill momentum array
124         
125         new ((*fMomentumArray)[goodTrack]) 
126             TLorentzVector(part->Px(),part->Py(),part->Pz(), part->Energy());
127         goodTrack++;
128   }
129     printf("\nNumber of good tracks %d \n", goodTrack);
130 }
131
132