polish
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALPIDv1.cxx
CommitLineData
c9b2f104 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/* $Id$ */
17
18//_________________________________________________________________________
19// Implementation version v1 of the EMCAL particle identifier
20
21//*-- Author: Yves Schutz (SUBATECH)
22//
23// --- ROOT system ---
d64c959b 24//#include "TROOT.h"
c9b2f104 25#include "TTree.h"
c9b2f104 26#include "TBenchmark.h"
c9b2f104 27#include "TSystem.h"
88cb7938 28
29 // --- Standard library ---
30
31 // --- AliRoot header files ---
c9b2f104 32#include "AliEMCALPIDv1.h"
c9b2f104 33#include "AliEMCALTrackSegment.h"
c9b2f104 34#include "AliEMCALRecParticle.h"
c9b2f104 35#include "AliEMCALGetter.h"
88cb7938 36
37 ClassImp( AliEMCALPIDv1)
c9b2f104 38
39//____________________________________________________________________________
40AliEMCALPIDv1::AliEMCALPIDv1():AliEMCALPID()
41{
42 // default ctor
88cb7938 43
c9b2f104 44 InitParameters() ;
45 fDefaultInit = kTRUE ;
88cb7938 46
47}
c9b2f104 48
88cb7938 49//____________________________________________________________________________
50AliEMCALPIDv1::AliEMCALPIDv1(const AliEMCALPIDv1 & pid ):AliEMCALPID(pid)
51{
52 // ctor
53 InitParameters() ;
54 Init() ;
55
c9b2f104 56}
57
58//____________________________________________________________________________
88cb7938 59AliEMCALPIDv1::AliEMCALPIDv1(const TString alirunFileName, const TString eventFolderName):AliEMCALPID(alirunFileName, eventFolderName)
c9b2f104 60{
61 //ctor with the indication on where to look for the track segments
62
63 InitParameters() ;
c9b2f104 64 Init() ;
65 fDefaultInit = kFALSE ;
66
67}
68
69//____________________________________________________________________________
70AliEMCALPIDv1::~AliEMCALPIDv1()
71{
72 // dtor
c9b2f104 73}
74
75//____________________________________________________________________________
76const TString AliEMCALPIDv1::BranchName() const
77{
88cb7938 78
79 return GetName() ;
c9b2f104 80}
81
82//____________________________________________________________________________
83void AliEMCALPIDv1::Init()
84{
85 // Make all memory allocations that are not possible in default constructor
86 // Add the PID task to the list of EMCAL tasks
87
c9b2f104 88
88cb7938 89 AliEMCALGetter * gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName.Data()) ;
c9b2f104 90
88cb7938 91 if ( !gime->PID() )
92 gime->PostPID(this) ;
c9b2f104 93}
94
95//____________________________________________________________________________
96void AliEMCALPIDv1::InitParameters()
97{
d64c959b 98 // Initialize the parameters
c9b2f104 99 fRecParticlesInRun = 0 ;
100 fNEvent = 0 ;
101 fRecParticlesInRun = 0 ;
c9b2f104 102}
103
104//____________________________________________________________________________
105
106void AliEMCALPIDv1::Exec(Option_t * option)
107{
108 //Steering method
88cb7938 109
c9b2f104 110 if(strstr(option,"tim"))
111 gBenchmark->Start("EMCALPID");
112
113 if(strstr(option,"print")) {
114 Print("") ;
115 return ;
116 }
88cb7938 117 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
118
119 Int_t nevents = gime->MaxEvent() ;
c9b2f104 120 Int_t ievent ;
121
122
123 for(ievent = 0; ievent < nevents; ievent++){
88cb7938 124 gime->Event(ievent,"TR") ;
125 if(gime->TrackSegments() && //Skip events, where no track segments made
126 gime->TrackSegments()->GetEntriesFast()) {
127 MakeRecParticles() ;
9e5d2067 128 WriteRecParticles();
88cb7938 129 if(strstr(option,"deb"))
130 PrintRecParticles(option) ;
131 //increment the total number of rec particles per run
132 fRecParticlesInRun += gime->RecParticles()->GetEntriesFast() ;
133 }
c9b2f104 134 }
c9b2f104 135 if(strstr(option,"tim")){
136 gBenchmark->Stop("EMCALPID");
fdebddeb 137 printf("Exec: took %f seconds for PID %f seconds per event",
c9b2f104 138 gBenchmark->GetCpuTime("EMCALPID"),
139 gBenchmark->GetCpuTime("EMCALPID")/nevents) ;
140 }
88cb7938 141
142 Unload();
c9b2f104 143}
144
145//____________________________________________________________________________
146void AliEMCALPIDv1::MakeRecParticles(){
147
148 // Makes a RecParticle out of a TrackSegment
149
88cb7938 150 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
151 TObjArray * aECARecPoints = gime->ECARecPoints() ;
c9b2f104 152 TClonesArray * trackSegments = gime->TrackSegments() ;
fdebddeb 153 if ( !aECARecPoints || !trackSegments ) {
c9b2f104 154 Fatal("MakeRecParticles", "RecPoints or TrackSegments not found !") ;
155 }
156 TClonesArray * recParticles = gime->RecParticles() ;
157 recParticles->Clear();
158
159 TIter next(trackSegments) ;
160 AliEMCALTrackSegment * ts ;
161 Int_t index = 0 ;
162 AliEMCALRecParticle * rp ;
163 while ( (ts = (AliEMCALTrackSegment *)next()) ) {
164
165 new( (*recParticles)[index] ) AliEMCALRecParticle() ;
166 rp = (AliEMCALRecParticle *)recParticles->At(index) ;
167 rp->SetTrackSegment(index) ;
168 rp->SetIndexInList(index) ;
169
88cb7938 170 AliEMCALTowerRecPoint * eca = 0 ;
171 if(ts->GetECAIndex()>=0)
172 eca = dynamic_cast<AliEMCALTowerRecPoint *>(aECARecPoints->At(ts->GetECAIndex())) ;
c9b2f104 173
174 // Now set type (reconstructed) of the particle
175
176 // Choose the cluster energy range
177
88cb7938 178 if (!eca) {
179 Fatal("MakeRecParticles", "-> emcal(%d) = %d", ts->GetECAIndex(), eca ) ;
c9b2f104 180 }
181
88cb7938 182 Float_t e = eca->GetEnergy() ;
c9b2f104 183
184 Float_t lambda[2] ;
88cb7938 185 eca->GetElipsAxis(lambda) ;
c9b2f104 186
187 if((lambda[0]>0.01) && (lambda[1]>0.01)){
188 // Looking PCA. Define and calculate the data (X),
189 // introduce in the function X2P that gives the components (P).
190
d64c959b 191 Float_t spher = 0. ;
192 Float_t emaxdtotal = 0. ;
c9b2f104 193
194 if((lambda[0]+lambda[1])!=0)
d64c959b 195 spher=fabs(lambda[0]-lambda[1])/(lambda[0]+lambda[1]);
c9b2f104 196
d64c959b 197 emaxdtotal=eca->GetMaximalEnergy()/eca->GetEnergy();
c9b2f104 198 }
199
200 // Float_t time = ecal->GetTime() ;
201
202 //Set momentum, energy and other parameters
88cb7938 203 Float_t enca = e;
c9b2f104 204 TVector3 dir(0., 0., 0.) ;
88cb7938 205 dir.SetMag(enca) ;
206 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),enca) ;
c9b2f104 207 rp->SetCalcMass(0);
208 rp->Name(); //If photon sets the particle pdg name to gamma
209 rp->SetProductionVertex(0,0,0,0);
210 rp->SetFirstMother(-1);
211 rp->SetLastMother(-1);
212 rp->SetFirstDaughter(-1);
213 rp->SetLastDaughter(-1);
214 rp->SetPolarisation(0,0,0);
215 index++ ;
216 }
217
218}
219
220//____________________________________________________________________________
9e5d2067 221void AliEMCALPIDv1:: Print(Option_t * /*option*/) const
c9b2f104 222{
223 // Print the parameters used for the particle type identification
224
fdebddeb 225 printf("Print: =============== AliEMCALPID1 ================") ;
88cb7938 226 printf("Making PID\n");
227 printf(" Pricipal analysis file from 0.5 to 100 %s\n", fFileName.Data() ) ;
228 printf(" Name of parameters file %s\n", fFileNamePar.Data() ) ;
c9b2f104 229}
230
231//____________________________________________________________________________
232void AliEMCALPIDv1::PrintRecParticles(Option_t * option)
233{
234 // Print table of reconstructed particles
235
88cb7938 236 AliEMCALGetter *gime = AliEMCALGetter::Instance() ;
c9b2f104 237
88cb7938 238 TClonesArray * recParticles = gime->RecParticles() ;
c9b2f104 239
fdebddeb 240 printf("\nevent %i", gAlice->GetEvNumber());
241 printf(" found %i", recParticles->GetEntriesFast());
242 printf(" RecParticles\n");
c9b2f104 243
244 if(strstr(option,"all")) { // printing found TS
fdebddeb 245 printf("\n PARTICLE Index \n");
c9b2f104 246
247 Int_t index ;
248 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
249 AliEMCALRecParticle * rp = (AliEMCALRecParticle * ) recParticles->At(index) ;
fdebddeb 250 printf("\n");
251 printf(rp->Name().Data());
252 printf(" %i", rp->GetIndexInList());
253 printf(" %i", rp->GetType());
c9b2f104 254 }
255 }
c9b2f104 256}
257
88cb7938 258//____________________________________________________________________________
259void AliEMCALPIDv1::Unload()
260{
d64c959b 261 // Unloads RecPoints, TrackSegments and RecParticles from the folder
88cb7938 262 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
263 gime->EmcalLoader()->UnloadRecPoints() ;
264 gime->EmcalLoader()->UnloadTracks() ;
265 gime->EmcalLoader()->UnloadRecParticles() ;
266}
267
268//____________________________________________________________________________
9e5d2067 269void AliEMCALPIDv1::WriteRecParticles()
88cb7938 270{
d64c959b 271 // Write RecParticles array to file
88cb7938 272 AliEMCALGetter *gime = AliEMCALGetter::Instance() ;
273
274 TClonesArray * recParticles = gime->RecParticles() ;
275 recParticles->Expand(recParticles->GetEntriesFast() ) ;
276 TTree * treeP = gime->TreeP() ;
c9b2f104 277
88cb7938 278
279
280 //First rp
281 Int_t bufferSize = 32000 ;
282 TBranch * rpBranch = treeP->Branch("EMCALRP",&recParticles,bufferSize);
283 rpBranch->SetTitle(BranchName());
284
285 rpBranch->Fill() ;
286
287 gime->WriteRecParticles("OVERWRITE");
288 gime->WritePID("OVERWRITE");
289
290}
c9b2f104 291