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 v0 of the PHOS particle identifier
20 // Particle identification based on the
22 // - Preshower information (in MIXT or GPS2 geometries)
25 // CPV or Preshower clusters should be closer in PHOS plane than fCpvEmcDistance (in cm).
26 // This parameter can be set by method SetCpvtoEmcDistanceCut(Float_t cut)
28 // One can set desirable ID method by the function SetIdentificationMethod(option).
29 // Presently the following options can be used together or separately :
30 // - "disp": use dispersion cut on shower width
31 // (width can be set by method SetDispersionCut(Float_t cut)
32 // - "ell" : use cut on the axis of the ellipse, drawn around shower
33 // (this cut can be changed by SetShowerProfileCut(char* formula),
34 // where formula - any function of two variables f(lambda[0],lambda[1]).
35 // Shower is considered as EM if f() > 0 )
36 // One can visualize current cuts calling method PlotDispersionCuts().
39 // root [0] AliPHOSPIDv0 * p1 = new AliPHOSPIDv0("galice.root")
40 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
41 // root [1] p1->SetIdentificationMethod("disp ellipse")
42 // root [2] p1->ExecuteTask()
43 // root [3] AliPHOSPIDv0 * p2 = new AliPHOSPIDv0("galice1.root","ts1")
44 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
45 // // reading headers from file galice1.root and TrackSegments
46 // // with title "ts1"
47 // root [4] p2->SetRecParticlesBranch("rp1")
48 // // set file name for the branch RecParticles
49 // root [5] p2->ExecuteTask("deb all time")
50 // // available options
51 // // "deb" - prints # of reconstructed particles
52 // // "deb all" - prints # and list of RecParticles
53 // // "time" - prints benchmarking results
55 //*-- Author: Yves Schutz (SUBATECH) & Gines Martinez (SUBATECH) &
56 // Dmitri Peressounko (SUBATECH & Kurchatov Institute)
57 // Completely redesined by Dmitri Peressounko, March 2001
59 // --- ROOT system ---
65 #include "TBenchmark.h"
66 // --- Standard library ---
68 // --- AliRoot header files ---
71 #include "AliGenerator.h"
72 #include "AliPHOSPIDv0.h"
73 #include "AliPHOSEmcRecPoint.h"
74 #include "AliPHOSTrackSegment.h"
75 #include "AliPHOSRecParticle.h"
76 #include "AliPHOSGeometry.h"
77 #include "AliPHOSLoader.h"
79 ClassImp( AliPHOSPIDv0)
81 //____________________________________________________________________________
82 AliPHOSPIDv0::AliPHOSPIDv0():AliPHOSPID()
89 fEventFolderName = "" ;
90 fTrackSegmentsTitle= "" ;
91 fRecPointsTitle = "" ;
92 fRecParticlesTitle = "" ;
93 fIDOptions = "dis time" ;
94 fRecParticlesInRun = 0 ;
99 //____________________________________________________________________________
100 AliPHOSPIDv0::AliPHOSPIDv0(const char * evFolderName,const char * name) : AliPHOSPID(evFolderName, name)
102 //ctor with the indication on where to look for the track segments
104 fFormula = new TFormula("LambdaCuts","(x>1)*(x<2.5)*(y>0)*(y<x)") ;
106 fCpvEmcDistance = 3.0 ;
109 fEventFolderName = GetTitle() ;
110 fTrackSegmentsTitle = GetName();
111 fRecPointsTitle = GetName();
112 fRecParticlesTitle = GetName();
113 fIDOptions = "dis time" ;
115 fRecParticlesInRun = 0 ;
121 //____________________________________________________________________________
122 AliPHOSPIDv0::~AliPHOSPIDv0()
126 //____________________________________________________________________________
127 Float_t AliPHOSPIDv0::GetDistance(AliPHOSEmcRecPoint * emc,AliPHOSRecPoint * cpv, Option_t * Axis)const
129 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
131 const AliPHOSGeometry * geom = AliPHOSLoader::GetPHOSGeometry() ;
135 emc->GetLocalPosition(vecEmc) ;
136 cpv->GetLocalPosition(vecCpv) ;
137 if(emc->GetPHOSMod() == cpv->GetPHOSMod()){
139 // Correct to difference in CPV and EMC position due to different distance to center.
140 // we assume, that particle moves from center
141 Float_t dCPV = geom->GetIPtoOuterCoverDistance();
142 Float_t dEMC = geom->GetIPtoCrystalSurface() ;
144 vecCpv = dEMC * vecCpv - vecEmc ;
145 if (Axis == "X") return vecCpv.X();
146 if (Axis == "Y") return vecCpv.Y();
147 if (Axis == "Z") return vecCpv.Z();
148 if (Axis == "R") return vecCpv.Mag();
154 //____________________________________________________________________________
155 void AliPHOSPIDv0::Exec(Option_t * option)
159 if( strcmp(GetName(), "")== 0 )
162 if(strstr(option,"tim"))
163 gBenchmark->Start("PHOSPID");
165 if(strstr(option,"print")) {
170 AliRunLoader* runget = AliRunLoader::GetRunLoader(GetTitle());
173 Error("Exec","Can not find run getter in event folder \"%s\"",GetTitle());
177 AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(runget->GetLoader("PHOSLoader"));
180 Error("Exec","Could not obtain the Loader object !");
184 if(gime->BranchExists("RecParticles") )
188 Int_t nevents = runget->GetNumberOfEvents() ; //(Int_t) gAlice->TreeE()->GetEntries() ;
192 for(ievent = 0; ievent < nevents; ievent++){
193 runget->GetEvent(ievent);
194 Info("Exec", "event %d %d %d", ievent, gime->EmcRecPoints(), gime->TrackSegments()) ;
199 if(strstr(option,"deb"))
200 PrintRecParticles(option) ;
202 //increment the total number of rec particles per run
203 fRecParticlesInRun += gime->RecParticles()->GetEntriesFast() ;
207 if(strstr(option,"tim")){
208 gBenchmark->Stop("PHOSPID");
209 Info("Exec", "took %f seconds for PID %f seconds per event",
210 gBenchmark->GetCpuTime("PHOSPID"), gBenchmark->GetCpuTime("PHOSPID")/nevents) ;
214 //____________________________________________________________________________
215 void AliPHOSPIDv0::Init()
217 // Make all memory allocations that are not possible in default constructor
218 // Add the PID task to the list of PHOS tasks
220 AliRunLoader* runget = AliRunLoader::GetRunLoader(GetTitle());
223 Error("Exec","Can not find run getter in event folder \"%s\"",GetTitle());
227 AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(runget->GetLoader("PHOSLoader"));
230 Error("Exec","Could not obtain the Loader object !");
235 gime->LoadRecParticles("UPDATE");
239 //____________________________________________________________________________
240 void AliPHOSPIDv0::MakeRecParticles()
242 // Reconstructs the particles from the tracksegments
244 TString taskName(GetName()) ;
245 taskName.Remove(taskName.Index(Version())-1) ;
247 AliRunLoader* runget = AliRunLoader::GetRunLoader(GetTitle());
250 Error("Exec","Can not find run getter in event folder \"%s\"",GetTitle());
254 AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(runget->GetLoader("PHOSLoader"));
257 Error("Exec","Could not obtain the Loader object !");
261 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
262 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
263 TClonesArray * trackSegments = gime->TrackSegments() ;
264 TClonesArray * recParticles = gime->RecParticles() ;
266 recParticles->Clear();
268 TIter next(trackSegments) ;
269 AliPHOSTrackSegment * ts ;
271 AliPHOSRecParticle * rp ;
273 Bool_t ellips = fIDOptions.Contains("ell",TString::kIgnoreCase ) ;
274 Bool_t disp = fIDOptions.Contains("dis",TString::kIgnoreCase ) ;
275 Bool_t time = fIDOptions.Contains("tim",TString::kIgnoreCase ) ;
277 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
279 new( (*recParticles)[index] ) AliPHOSRecParticle() ;
280 rp = (AliPHOSRecParticle *)recParticles->At(index) ;
281 rp->SetTrackSegment(index) ;
282 rp->SetIndexInList(index) ;
284 AliPHOSEmcRecPoint * emc = 0 ;
285 if(ts->GetEmcIndex()>=0)
286 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
288 AliPHOSRecPoint * cpv = 0 ;
289 if(ts->GetCpvIndex()>=0)
290 cpv = (AliPHOSRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
292 //set momentum and energy first
293 Float_t e = emc->GetEnergy() ;
294 TVector3 dir = GetMomentumDirection(emc,cpv) ;
297 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),e) ;
300 //now set type (reconstructed) of the particle
301 Int_t showerprofile = 0; // 0 narrow and 1 wide
305 emc->GetElipsAxis(lambda) ;
306 if(fFormula->Eval(lambda[0],lambda[1]) <= 0 )
307 showerprofile = 1 ; // not narrow
311 if(emc->GetDispersion() > fDispersion )
312 showerprofile = 1 ; // not narrow
316 if(emc->GetTime() > fTimeGate )
319 // Looking at the CPV detector
320 Int_t cpvdetector= 0 ; //1 hit and 0 no hit
322 if(GetDistance(emc, cpv, "R") < fCpvEmcDistance)
325 Int_t type = showerprofile + 2 * slow + 4 * cpvdetector ;
327 rp->SetProductionVertex(0,0,0,0);
328 rp->SetFirstMother(-1);
329 rp->SetLastMother(-1);
330 rp->SetFirstDaughter(-1);
331 rp->SetLastDaughter(-1);
332 rp->SetPolarisation(0,0,0);
338 //____________________________________________________________________________
339 void AliPHOSPIDv0:: Print() const
341 // Print the parameters used for the particle type identification
343 message = "=============== AliPHOSPIDv0 ================\n" ;
344 message += "Making PID\n" ;
345 message += " Headers file: %s\n" ;
346 message += " RecPoints branch title: %s\n" ;
347 message += " TrackSegments Branch title: %s\n" ;
348 message += " RecParticles Branch title %s\n" ;
349 message += "with parameters:\n" ;
350 message += " Maximal EMC - CPV distance (cm) %f\n" ;
351 Info("Print", message.Data(),
353 fRecPointsTitle.Data(),
354 fTrackSegmentsTitle.Data(),
355 fRecParticlesTitle.Data(),
358 if(fIDOptions.Contains("dis",TString::kIgnoreCase ))
359 Info("Print", " dispersion cut %f", fDispersion ) ;
360 if(fIDOptions.Contains("ell",TString::kIgnoreCase ))
361 Info("Print", " Eliptic cuts function: %s", fFormula->GetTitle() ) ;
362 if(fIDOptions.Contains("tim",TString::kIgnoreCase ))
363 Info("Print", " Time Gate used: %f", fTimeGate) ;
366 //____________________________________________________________________________
367 void AliPHOSPIDv0::SetShowerProfileCut(const char * formula)
369 //set shape of the cut on the axis of ellipce, drown around shouer
370 //shower considered "narrow" if Formula(lambda[0],lambda[1]) > 0.
373 fFormula = new TFormula("Lambda Cut",formula) ;
375 //____________________________________________________________________________
376 void AliPHOSPIDv0::WriteRecParticles()
378 // Saves the reconstructed particles too a file
380 AliRunLoader* runget = AliRunLoader::GetRunLoader(GetTitle());
383 Error("Exec","Can not find run getter in event folder \"%s\"",GetTitle());
387 AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(runget->GetLoader("PHOSLoader"));
390 Error("Exec","Could not obtain the Loader object !");
394 TClonesArray * recParticles = gime->RecParticles() ;
395 recParticles->Expand(recParticles->GetEntriesFast() ) ;
397 TTree * treeR = gime->TreeR();
401 treeR = gime->TreeR() ;
405 Int_t bufferSize = 32000 ;
406 TBranch * rpBranch = treeR->Branch("PHOSRP",&recParticles,bufferSize);
407 rpBranch->SetTitle(fRecParticlesTitle);
410 Int_t splitlevel = 0 ;
411 AliPHOSPIDv0 * pid = this ;
412 TBranch * pidBranch = treeR->Branch("AliPHOSPID","AliPHOSPIDv0",&pid,bufferSize,splitlevel);
413 pidBranch->SetTitle(fRecParticlesTitle.Data());
418 gime->WriteRecParticles("OVERWRITE");
419 gime->WritePID("OVERWRITE");
423 //____________________________________________________________________________
424 void AliPHOSPIDv0::PlotDispersionCuts()const
426 // produces a plot of the dispersion cut
427 TCanvas* lambdas = new TCanvas("lambdas","Cuts on the ellipse axis",200,10,700,500);
429 if(fIDOptions.Contains("ell",TString::kIgnoreCase ) ){
430 TF2 * ell = new TF2("Elliptic Cuts",fFormula->GetName(),0,3,0,3) ;
431 ell->SetMinimum(0.0000001) ;
432 ell->SetMaximum(0.001) ;
433 ell->SetLineStyle(1) ;
434 ell->SetLineWidth(2) ;
438 if( fIDOptions.Contains("dis",TString::kIgnoreCase ) ){
439 TF2 * dsp = new TF2("dispersion","(y<x)*(x*x+y*y < [0]*[0])",0,3,0,3) ;
440 dsp->SetParameter(0,fDispersion) ;
441 dsp->SetMinimum(0.0000001) ;
442 dsp->SetMaximum(0.001) ;
443 dsp->SetLineStyle(1) ;
444 dsp->SetLineColor(2) ;
445 dsp->SetLineWidth(2) ;
448 if(fIDOptions.Contains("ell",TString::kIgnoreCase ) )
456 //____________________________________________________________________________
457 TVector3 AliPHOSPIDv0::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSRecPoint * )const
459 // Calculates the momentum direction:
460 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
461 // 2. if a EMC RecPoint and CPV RecPoint, direction is given by the line through the 2 recpoints
462 // However because of the poor position resolution of PPSD the direction is always taken as if we were
465 TVector3 dir(0,0,0) ;
467 TVector3 emcglobalpos ;
470 emc->GetGlobalPosition(emcglobalpos, dummy) ;
473 // The following commented code becomes valid once the PPSD provides
474 // a reasonable position resolution, at least as good as EMC !
475 // TVector3 ppsdlglobalpos ;
476 // TVector3 ppsduglobalpos ;
477 // if( fPpsdLowRecPoint ){ // certainly a photon that has concerted
478 // fPpsdLowRecPoint->GetGlobalPosition(ppsdlglobalpos, mdummy) ;
479 // dir = emcglobalpos - ppsdlglobalpos ;
480 // if( fPpsdUpRecPoint ){ // not looks like a charged
481 // fPpsdUpRecPoint->GetGlobalPosition(ppsduglobalpos, mdummy) ;
482 // dir = ( dir + emcglobalpos - ppsduglobalpos ) * 0.5 ;
485 // else { // looks like a neutral
486 // dir = emcglobalpos ;
490 dir.SetZ( -dir.Z() ) ; // why ?
493 //account correction to the position of IP
494 Float_t xo,yo,zo ; //Coordinates of the origin
495 gAlice->Generator()->GetOrigin(xo,yo,zo) ;
496 TVector3 origin(xo,yo,zo);
501 //____________________________________________________________________________
502 void AliPHOSPIDv0::PrintRecParticles(Option_t * option)
504 // Print table of reconstructed particles
506 AliRunLoader* runget = AliRunLoader::GetRunLoader(GetTitle());
509 Error("WriteRecParticles","Can not find run getter in event folder \"%s\"",GetTitle());
513 AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(runget->GetLoader("PHOSLoader"));
516 Error("WriteRecParticles","Could not obtain the Loader object !");
520 TString taskName(GetName()) ;
521 taskName.Remove(taskName.Index(Version())-1) ;
522 TClonesArray * recParticles = gime->RecParticles() ;
525 message = "event %d\n" ;
526 message += " found %d RecParticles\n" ;
527 Info("PrintRecParticles", message.Data(), gAlice->GetEvNumber(), recParticles->GetEntriesFast() ) ;
529 if(strstr(option,"all")) { // printing found TS
530 Info("PrintRecParticles"," PARTICLE Index \n" ) ;
533 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
534 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) recParticles->At(index) ;
537 switch(rp->GetType()) {
538 case AliPHOSFastRecParticle::kNEUTRALEMFAST:
539 strcpy( particle, "NEUTRAL EM FAST");
541 case AliPHOSFastRecParticle::kNEUTRALHAFAST:
542 strcpy(particle, "NEUTRAL HA FAST");
544 case AliPHOSFastRecParticle::kNEUTRALEMSLOW:
545 strcpy(particle, "NEUTRAL EM SLOW");
547 case AliPHOSFastRecParticle::kNEUTRALHASLOW:
548 strcpy(particle, "NEUTRAL HA SLOW");
550 case AliPHOSFastRecParticle::kCHARGEDEMFAST:
551 strcpy(particle, "CHARGED EM FAST") ;
553 case AliPHOSFastRecParticle::kCHARGEDHAFAST:
554 strcpy(particle, "CHARGED HA FAST") ;
556 case AliPHOSFastRecParticle::kCHARGEDEMSLOW:
557 strcpy(particle, "CHARGEDEMSLOW") ;
559 case AliPHOSFastRecParticle::kCHARGEDHASLOW:
560 strcpy(particle, "CHARGED HA SLOW") ;
564 // Int_t * primaries;
566 // primaries = rp->GetPrimaries(nprimaries);
568 Info("PrintRecParticles", " %s %d\n", particle, rp->GetIndexInList()) ;