1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
18 //_________________________________________________________________________
19 // Implementation version v1 of the EMCAL particle identifier
21 //*-- Author: Yves Schutz (SUBATECH)
23 // --- ROOT system ---
31 #include "TBenchmark.h"
35 // --- Standard library ---
37 #include <Riostream.h>
39 // --- AliRoot header files ---
42 #include "AliGenerator.h"
44 #include "AliEMCALPIDv1.h"
45 #include "AliEMCALClusterizerv1.h"
46 #include "AliEMCALTrackSegment.h"
47 #include "AliEMCALTrackSegmentMakerv1.h"
48 #include "AliEMCALRecParticle.h"
49 #include "AliEMCALGeometry.h"
50 #include "AliEMCALGetter.h"
52 ClassImp( AliEMCALPIDv1)
54 //____________________________________________________________________________
55 AliEMCALPIDv1::AliEMCALPIDv1():AliEMCALPID()
60 fDefaultInit = kTRUE ;
64 //____________________________________________________________________________
65 AliEMCALPIDv1::AliEMCALPIDv1(const char * headerFile,const char * name, const Bool_t toSplit)
66 :AliEMCALPID(headerFile, name,toSplit)
68 //ctor with the indication on where to look for the track segments
73 fDefaultInit = kFALSE ;
77 //____________________________________________________________________________
78 AliEMCALPIDv1::~AliEMCALPIDv1()
87 //____________________________________________________________________________
88 const TString AliEMCALPIDv1::BranchName() const
90 TString branchName(GetName() ) ;
91 branchName.Remove(branchName.Index(Version())-1) ;
95 //____________________________________________________________________________
96 void AliEMCALPIDv1::Init()
98 // Make all memory allocations that are not possible in default constructor
99 // Add the PID task to the list of EMCAL tasks
101 if ( strcmp(GetTitle(), "") == 0 )
102 SetTitle("galice.root") ;
104 TString branchname(GetName()) ;
105 branchname.Remove(branchname.Index(Version())-1) ;
106 AliEMCALGetter * gime = AliEMCALGetter::GetInstance(GetTitle(),branchname.Data(),fToSplit ) ;
108 // gime->SetRecParticlesTitle(BranchName()) ;
110 Error("Init", "Could not obtain the Getter object !" ) ;
116 //First - extract full path if necessary
117 TString fileName(GetTitle()) ;
118 Ssiz_t islash = fileName.Last('/') ;
119 if(islash<fileName.Length())
120 fileName.Remove(islash+1,fileName.Length()) ;
123 fileName+="EMCAL.RecData." ;
124 if((strcmp(branchname.Data(),"Default")!=0)&&(strcmp(branchname.Data(),"")!=0)){
125 fileName+=branchname.Data() ;
129 fSplitFile = static_cast<TFile*>(gROOT->GetFile(fileName.Data()));
131 fSplitFile = TFile::Open(fileName.Data(),"update") ;
134 gime->PostPID(this) ;
135 gime->PostRecParticles(branchname) ;
139 //____________________________________________________________________________
140 void AliEMCALPIDv1::InitParameters()
143 fRecParticlesInRun = 0 ;
145 fRecParticlesInRun = 0 ;
146 TString pidName( GetName()) ;
147 if (pidName.IsNull() )
148 pidName = "Default" ;
149 pidName.Append(":") ;
150 pidName.Append(Version()) ;
152 fPi0Analysis = kFALSE ;
155 //____________________________________________________________________________
157 void AliEMCALPIDv1::Exec(Option_t * option)
161 if( strcmp(GetName(), "")== 0 )
164 if(strstr(option,"tim"))
165 gBenchmark->Start("EMCALPID");
167 if(strstr(option,"print")) {
171 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
172 if(gime->BranchExists("RecParticles") )
174 Int_t nevents = gime->MaxEvent() ; //(Int_t) gAlice->TreeE()->GetEntries() ;
178 for(ievent = 0; ievent < nevents; ievent++){
179 gime->Event(ievent,"R") ;
183 WriteRecParticles(ievent);
185 if(strstr(option,"deb"))
186 PrintRecParticles(option) ;
188 //increment the total number of rec particles per run
189 fRecParticlesInRun += gime->RecParticles(BranchName())->GetEntriesFast() ;
193 if(strstr(option,"tim")){
194 gBenchmark->Stop("EMCALPID");
195 Info("Exec", "took %f seconds for PID %f seconds per event",
196 gBenchmark->GetCpuTime("EMCALPID"),
197 gBenchmark->GetCpuTime("EMCALPID")/nevents) ;
201 //____________________________________________________________________________
202 void AliEMCALPIDv1::MakeRecParticles(){
204 // Makes a RecParticle out of a TrackSegment
206 AliEMCALGetter * gime = AliEMCALGetter::GetInstance() ;
207 TObjArray * aECRecPoints = gime->ECALRecPoints() ;
208 TObjArray * aPRRecPoints = gime->PRERecPoints() ;
209 TObjArray * aHCRecPoints = gime->HCALRecPoints() ;
210 TClonesArray * trackSegments = gime->TrackSegments() ;
211 if ( !aECRecPoints || !aPRRecPoints || !aHCRecPoints || !trackSegments ) {
212 Fatal("MakeRecParticles", "RecPoints or TrackSegments not found !") ;
214 TClonesArray * recParticles = gime->RecParticles() ;
215 recParticles->Clear();
217 TIter next(trackSegments) ;
218 AliEMCALTrackSegment * ts ;
220 AliEMCALRecParticle * rp ;
221 while ( (ts = (AliEMCALTrackSegment *)next()) ) {
223 new( (*recParticles)[index] ) AliEMCALRecParticle() ;
224 rp = (AliEMCALRecParticle *)recParticles->At(index) ;
225 rp->SetTrackSegment(index) ;
226 rp->SetIndexInList(index) ;
228 AliEMCALTowerRecPoint * ecal = 0 ;
229 if(ts->GetECIndex()>=0)
230 ecal = dynamic_cast<AliEMCALTowerRecPoint *>(aECRecPoints->At(ts->GetECIndex())) ;
232 AliEMCALTowerRecPoint * pre = 0 ;
233 if(ts->GetPREIndex()>=0)
234 pre = dynamic_cast<AliEMCALTowerRecPoint *>(aPRRecPoints->At(ts->GetPREIndex())) ;
236 AliEMCALTowerRecPoint * hcal = 0 ;
237 if(ts->GetHCIndex()>=0)
238 hcal = dynamic_cast<AliEMCALTowerRecPoint *>(aHCRecPoints->At(ts->GetHCIndex())) ;
240 // Now set type (reconstructed) of the particle
242 // Choose the cluster energy range
245 Fatal("MakeRecParticles", "-> emcal(%d) = %d", ts->GetECIndex(), ecal ) ;
248 Float_t e = ecal->GetEnergy() ;
251 ecal->GetElipsAxis(lambda) ;
253 if((lambda[0]>0.01) && (lambda[1]>0.01)){
254 // Looking PCA. Define and calculate the data (X),
255 // introduce in the function X2P that gives the components (P).
258 Float_t Emaxdtotal = 0. ;
260 if((lambda[0]+lambda[1])!=0)
261 Spher=fabs(lambda[0]-lambda[1])/(lambda[0]+lambda[1]);
263 Emaxdtotal=ecal->GetMaximalEnergy()/ecal->GetEnergy();
266 // Float_t time = ecal->GetTime() ;
268 //Set momentum, energy and other parameters
270 TVector3 dir(0., 0., 0.) ;
272 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),encal) ;
274 rp->Name(); //If photon sets the particle pdg name to gamma
275 rp->SetProductionVertex(0,0,0,0);
276 rp->SetFirstMother(-1);
277 rp->SetLastMother(-1);
278 rp->SetFirstDaughter(-1);
279 rp->SetLastDaughter(-1);
280 rp->SetPolarisation(0,0,0);
286 //____________________________________________________________________________
287 void AliEMCALPIDv1:: Print()
289 // Print the parameters used for the particle type identification
292 message = "\n=============== AliEMCALPID1 ================\n" ;
293 message += "Making PID\n";
294 message += " Pricipal analysis file from 0.5 to 100 %s\n" ;
295 message += " Name of parameters file %s\n" ;
296 message += " Matrix of Parameters: 9x4\n" ;
297 message += " RCPV 2x3 rows x and z, columns function cut parameters\n" ;
298 message += " TOF 1x3 [High Eff-Low Pur,Medium Eff-Pur, Low Eff-High Pur]\n" ;
299 message += " PCA 5x4 [5 ellipse parametres and 4 parametres to calculate them: A/Sqrt(E) + B* E + C * E^2 + D]\n" ;
300 message += " Energy Calibration 1x3 [3 parametres to calibrate energy: A + B* E + C * E^2]\n" ;
301 Info("Print", message.Data(), fFileName.Data(), fFileNamePar.Data() ) ;
304 //____________________________________________________________________________
305 void AliEMCALPIDv1::WriteRecParticles(Int_t event)
308 AliEMCALGetter *gime = AliEMCALGetter::GetInstance() ;
310 TClonesArray * recParticles = gime->RecParticles() ;
311 recParticles->Expand(recParticles->GetEntriesFast() ) ;
319 sprintf(name,"%s%d", "TreeR",event) ;
320 treeR = dynamic_cast<TTree*>(fSplitFile->Get(name));
323 treeR = gAlice->TreeR();
327 gAlice->MakeTree("R", fSplitFile);
328 treeR = gAlice->TreeR() ;
332 Int_t bufferSize = 32000 ;
333 TBranch * rpBranch = treeR->Branch("EMCALRP",&recParticles,bufferSize);
334 rpBranch->SetTitle(BranchName());
338 Int_t splitlevel = 0 ;
339 AliEMCALPIDv1 * pid = this ;
340 TBranch * pidBranch = treeR->Branch("AliEMCALPID","AliEMCALPIDv1",&pid,bufferSize,splitlevel);
341 pidBranch->SetTitle(BranchName());
346 treeR->AutoSave() ; //Write(0,kOverwrite) ;
347 if(gAlice->TreeR()!=treeR){
352 //____________________________________________________________________________
353 void AliEMCALPIDv1::PrintRecParticles(Option_t * option)
355 // Print table of reconstructed particles
357 AliEMCALGetter *gime = AliEMCALGetter::GetInstance() ;
359 TClonesArray * recParticles = gime->RecParticles(BranchName()) ;
362 message = "\nevent " ;
363 message += gAlice->GetEvNumber() ;
364 message += " found " ;
365 message += recParticles->GetEntriesFast();
366 message += " RecParticles\n" ;
368 if(strstr(option,"all")) { // printing found TS
369 message += "\n PARTICLE Index \n" ;
372 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
373 AliEMCALRecParticle * rp = (AliEMCALRecParticle * ) recParticles->At(index) ;
375 message += rp->Name().Data() ;
377 message += rp->GetIndexInList() ;
379 message += rp->GetType() ;
382 Info("Print", message.Data() ) ;