Anti-Splitting Cut implemented
[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");
137 Info("Exec", "took %f seconds for PID %f seconds per event",
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() ;
152 TObjArray * aPRERecPoints = gime->PRERecPoints() ;
153 TObjArray * aHCARecPoints = gime->HCARecPoints() ;
c9b2f104 154 TClonesArray * trackSegments = gime->TrackSegments() ;
88cb7938 155 if ( !aECARecPoints || !aPRERecPoints || !aHCARecPoints || !trackSegments ) {
c9b2f104 156 Fatal("MakeRecParticles", "RecPoints or TrackSegments not found !") ;
157 }
158 TClonesArray * recParticles = gime->RecParticles() ;
159 recParticles->Clear();
160
161 TIter next(trackSegments) ;
162 AliEMCALTrackSegment * ts ;
163 Int_t index = 0 ;
164 AliEMCALRecParticle * rp ;
165 while ( (ts = (AliEMCALTrackSegment *)next()) ) {
166
167 new( (*recParticles)[index] ) AliEMCALRecParticle() ;
168 rp = (AliEMCALRecParticle *)recParticles->At(index) ;
169 rp->SetTrackSegment(index) ;
170 rp->SetIndexInList(index) ;
171
88cb7938 172 AliEMCALTowerRecPoint * eca = 0 ;
173 if(ts->GetECAIndex()>=0)
174 eca = dynamic_cast<AliEMCALTowerRecPoint *>(aECARecPoints->At(ts->GetECAIndex())) ;
c9b2f104 175
88cb7938 176 AliEMCALTowerRecPoint * pre = 0 ;
c9b2f104 177 if(ts->GetPREIndex()>=0)
88cb7938 178 pre = dynamic_cast<AliEMCALTowerRecPoint *>(aPRERecPoints->At(ts->GetPREIndex())) ;
c9b2f104 179
88cb7938 180 AliEMCALTowerRecPoint * hca = 0 ;
181 if(ts->GetHCAIndex()>=0)
182 hca = dynamic_cast<AliEMCALTowerRecPoint *>(aHCARecPoints->At(ts->GetHCAIndex())) ;
c9b2f104 183
184 // Now set type (reconstructed) of the particle
185
186 // Choose the cluster energy range
187
88cb7938 188 if (!eca) {
189 Fatal("MakeRecParticles", "-> emcal(%d) = %d", ts->GetECAIndex(), eca ) ;
c9b2f104 190 }
191
88cb7938 192 Float_t e = eca->GetEnergy() ;
c9b2f104 193
194 Float_t lambda[2] ;
88cb7938 195 eca->GetElipsAxis(lambda) ;
c9b2f104 196
197 if((lambda[0]>0.01) && (lambda[1]>0.01)){
198 // Looking PCA. Define and calculate the data (X),
199 // introduce in the function X2P that gives the components (P).
200
d64c959b 201 Float_t spher = 0. ;
202 Float_t emaxdtotal = 0. ;
c9b2f104 203
204 if((lambda[0]+lambda[1])!=0)
d64c959b 205 spher=fabs(lambda[0]-lambda[1])/(lambda[0]+lambda[1]);
c9b2f104 206
d64c959b 207 emaxdtotal=eca->GetMaximalEnergy()/eca->GetEnergy();
c9b2f104 208 }
209
210 // Float_t time = ecal->GetTime() ;
211
212 //Set momentum, energy and other parameters
88cb7938 213 Float_t enca = e;
c9b2f104 214 TVector3 dir(0., 0., 0.) ;
88cb7938 215 dir.SetMag(enca) ;
216 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),enca) ;
c9b2f104 217 rp->SetCalcMass(0);
218 rp->Name(); //If photon sets the particle pdg name to gamma
219 rp->SetProductionVertex(0,0,0,0);
220 rp->SetFirstMother(-1);
221 rp->SetLastMother(-1);
222 rp->SetFirstDaughter(-1);
223 rp->SetLastDaughter(-1);
224 rp->SetPolarisation(0,0,0);
225 index++ ;
226 }
227
228}
229
230//____________________________________________________________________________
9e5d2067 231void AliEMCALPIDv1:: Print(Option_t * /*option*/) const
c9b2f104 232{
233 // Print the parameters used for the particle type identification
234
88cb7938 235 Info("Print", "=============== AliEMCALPID1 ================") ;
236 printf("Making PID\n");
237 printf(" Pricipal analysis file from 0.5 to 100 %s\n", fFileName.Data() ) ;
238 printf(" Name of parameters file %s\n", fFileNamePar.Data() ) ;
c9b2f104 239}
240
241//____________________________________________________________________________
242void AliEMCALPIDv1::PrintRecParticles(Option_t * option)
243{
244 // Print table of reconstructed particles
245
88cb7938 246 AliEMCALGetter *gime = AliEMCALGetter::Instance() ;
c9b2f104 247
88cb7938 248 TClonesArray * recParticles = gime->RecParticles() ;
c9b2f104 249
250 TString message ;
251 message = "\nevent " ;
252 message += gAlice->GetEvNumber() ;
253 message += " found " ;
254 message += recParticles->GetEntriesFast();
255 message += " RecParticles\n" ;
256
257 if(strstr(option,"all")) { // printing found TS
258 message += "\n PARTICLE Index \n" ;
259
260 Int_t index ;
261 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
262 AliEMCALRecParticle * rp = (AliEMCALRecParticle * ) recParticles->At(index) ;
263 message += "\n" ;
264 message += rp->Name().Data() ;
265 message += " " ;
266 message += rp->GetIndexInList() ;
267 message += " " ;
268 message += rp->GetType() ;
269 }
270 }
271 Info("Print", message.Data() ) ;
272}
273
88cb7938 274//____________________________________________________________________________
275void AliEMCALPIDv1::Unload()
276{
d64c959b 277 // Unloads RecPoints, TrackSegments and RecParticles from the folder
88cb7938 278 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
279 gime->EmcalLoader()->UnloadRecPoints() ;
280 gime->EmcalLoader()->UnloadTracks() ;
281 gime->EmcalLoader()->UnloadRecParticles() ;
282}
283
284//____________________________________________________________________________
9e5d2067 285void AliEMCALPIDv1::WriteRecParticles()
88cb7938 286{
d64c959b 287 // Write RecParticles array to file
88cb7938 288 AliEMCALGetter *gime = AliEMCALGetter::Instance() ;
289
290 TClonesArray * recParticles = gime->RecParticles() ;
291 recParticles->Expand(recParticles->GetEntriesFast() ) ;
292 TTree * treeP = gime->TreeP() ;
c9b2f104 293
88cb7938 294
295
296 //First rp
297 Int_t bufferSize = 32000 ;
298 TBranch * rpBranch = treeP->Branch("EMCALRP",&recParticles,bufferSize);
299 rpBranch->SetTitle(BranchName());
300
301 rpBranch->Fill() ;
302
303 gime->WriteRecParticles("OVERWRITE");
304 gime->WritePID("OVERWRITE");
305
306}
c9b2f104 307