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 AliError(Form("Can not find run getter in event folder \"%s\"",
178 AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(runget->GetLoader("PHOSLoader"));
181 AliError("Could not obtain the Loader object !");
185 if(gime->BranchExists("RecParticles") )
189 Int_t nevents = runget->GetNumberOfEvents() ; //(Int_t) gAlice->TreeE()->GetEntries() ;
193 for(ievent = 0; ievent < nevents; ievent++){
194 runget->GetEvent(ievent);
195 AliInfo(Form("event %d %d %d",
196 ievent, gime->EmcRecPoints(),
197 gime->TrackSegments())) ;
202 if(strstr(option,"deb"))
203 PrintRecParticles(option) ;
205 //increment the total number of rec particles per run
206 fRecParticlesInRun += gime->RecParticles()->GetEntriesFast() ;
210 if(strstr(option,"tim")){
211 gBenchmark->Stop("PHOSPID");
212 AliInfo(Form("took %f seconds for PID %f seconds per event",
213 gBenchmark->GetCpuTime("PHOSPID"),
214 gBenchmark->GetCpuTime("PHOSPID")/nevents)) ;
218 //____________________________________________________________________________
219 void AliPHOSPIDv0::Init()
221 // Make all memory allocations that are not possible in default constructor
222 // Add the PID task to the list of PHOS tasks
224 AliRunLoader* runget = AliRunLoader::GetRunLoader(GetTitle());
227 AliError(Form("Can not find run getter in event folder \"%s\"",
232 AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(runget->GetLoader("PHOSLoader"));
235 AliError("Could not obtain the Loader object !");
240 gime->LoadRecParticles("UPDATE");
244 //____________________________________________________________________________
245 void AliPHOSPIDv0::MakeRecParticles()
247 // Reconstructs the particles from the tracksegments
249 TString taskName(GetName()) ;
250 taskName.Remove(taskName.Index(Version())-1) ;
252 AliRunLoader* runget = AliRunLoader::GetRunLoader(GetTitle());
255 AliError(Form("Can not find run getter in event folder \"%s\"",
260 AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(runget->GetLoader("PHOSLoader"));
263 AliError("Could not obtain the Loader object !");
267 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
268 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
269 TClonesArray * trackSegments = gime->TrackSegments() ;
270 TClonesArray * recParticles = gime->RecParticles() ;
272 recParticles->Clear();
274 TIter next(trackSegments) ;
275 AliPHOSTrackSegment * ts ;
277 AliPHOSRecParticle * rp ;
279 Bool_t ellips = fIDOptions.Contains("ell",TString::kIgnoreCase ) ;
280 Bool_t disp = fIDOptions.Contains("dis",TString::kIgnoreCase ) ;
281 Bool_t time = fIDOptions.Contains("tim",TString::kIgnoreCase ) ;
283 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
285 new( (*recParticles)[index] ) AliPHOSRecParticle() ;
286 rp = (AliPHOSRecParticle *)recParticles->At(index) ;
287 rp->SetTrackSegment(index) ;
288 rp->SetIndexInList(index) ;
290 AliPHOSEmcRecPoint * emc = 0 ;
291 if(ts->GetEmcIndex()>=0)
292 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
294 AliPHOSRecPoint * cpv = 0 ;
295 if(ts->GetCpvIndex()>=0)
296 cpv = (AliPHOSRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
298 //set momentum and energy first
299 Float_t e = emc->GetEnergy() ;
300 TVector3 dir = GetMomentumDirection(emc,cpv) ;
303 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),e) ;
306 //now set type (reconstructed) of the particle
307 Int_t showerprofile = 0; // 0 narrow and 1 wide
311 emc->GetElipsAxis(lambda) ;
312 if(fFormula->Eval(lambda[0],lambda[1]) <= 0 )
313 showerprofile = 1 ; // not narrow
317 if(emc->GetDispersion() > fDispersion )
318 showerprofile = 1 ; // not narrow
322 if(emc->GetTime() > fTimeGate )
325 // Looking at the CPV detector
326 Int_t cpvdetector= 0 ; //1 hit and 0 no hit
328 if(GetDistance(emc, cpv, "R") < fCpvEmcDistance)
331 Int_t type = showerprofile + 2 * slow + 4 * cpvdetector ;
333 rp->SetProductionVertex(0,0,0,0);
334 rp->SetFirstMother(-1);
335 rp->SetLastMother(-1);
336 rp->SetFirstDaughter(-1);
337 rp->SetLastDaughter(-1);
338 rp->SetPolarisation(0,0,0);
344 //____________________________________________________________________________
345 void AliPHOSPIDv0:: Print() const
347 // Print the parameters used for the particle type identification
349 message = "=============== AliPHOSPIDv0 ================\n" ;
350 message += "Making PID\n" ;
351 message += " Headers file: %s\n" ;
352 message += " RecPoints branch title: %s\n" ;
353 message += " TrackSegments Branch title: %s\n" ;
354 message += " RecParticles Branch title %s\n" ;
355 message += "with parameters:\n" ;
356 message += " Maximal EMC - CPV distance (cm) %f\n" ;
357 AliInfo(Form( message.Data(),
359 fRecPointsTitle.Data(),
360 fTrackSegmentsTitle.Data(),
361 fRecParticlesTitle.Data(),
364 if(fIDOptions.Contains("dis",TString::kIgnoreCase ))
365 AliInfo(Form(" dispersion cut %f", fDispersion )) ;
366 if(fIDOptions.Contains("ell",TString::kIgnoreCase ))
367 AliInfo(Form(" Eliptic cuts function: %s",
368 fFormula->GetTitle() )) ;
369 if(fIDOptions.Contains("tim",TString::kIgnoreCase ))
370 AliInfo(Form(" Time Gate used: %f", fTimeGate)) ;
373 //____________________________________________________________________________
374 void AliPHOSPIDv0::SetShowerProfileCut(const char * formula)
376 //set shape of the cut on the axis of ellipce, drown around shouer
377 //shower considered "narrow" if Formula(lambda[0],lambda[1]) > 0.
380 fFormula = new TFormula("Lambda Cut",formula) ;
382 //____________________________________________________________________________
383 void AliPHOSPIDv0::WriteRecParticles()
385 // Saves the reconstructed particles too a file
387 AliRunLoader* runget = AliRunLoader::GetRunLoader(GetTitle());
390 AliError(Form("Can not find run getter in event folder \"%s\"",
395 AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(runget->GetLoader("PHOSLoader"));
398 AliError("Could not obtain the Loader object !");
402 TClonesArray * recParticles = gime->RecParticles() ;
403 recParticles->Expand(recParticles->GetEntriesFast() ) ;
405 TTree * treeR = gime->TreeR();
409 treeR = gime->TreeR() ;
413 Int_t bufferSize = 32000 ;
414 TBranch * rpBranch = treeR->Branch("PHOSRP",&recParticles,bufferSize);
415 rpBranch->SetTitle(fRecParticlesTitle);
418 Int_t splitlevel = 0 ;
419 AliPHOSPIDv0 * pid = this ;
420 TBranch * pidBranch = treeR->Branch("AliPHOSPID","AliPHOSPIDv0",&pid,bufferSize,splitlevel);
421 pidBranch->SetTitle(fRecParticlesTitle.Data());
426 gime->WriteRecParticles("OVERWRITE");
427 gime->WritePID("OVERWRITE");
431 //____________________________________________________________________________
432 void AliPHOSPIDv0::PlotDispersionCuts()const
434 // produces a plot of the dispersion cut
435 TCanvas* lambdas = new TCanvas("lambdas","Cuts on the ellipse axis",200,10,700,500);
437 if(fIDOptions.Contains("ell",TString::kIgnoreCase ) ){
438 TF2 * ell = new TF2("Elliptic Cuts",fFormula->GetName(),0,3,0,3) ;
439 ell->SetMinimum(0.0000001) ;
440 ell->SetMaximum(0.001) ;
441 ell->SetLineStyle(1) ;
442 ell->SetLineWidth(2) ;
446 if( fIDOptions.Contains("dis",TString::kIgnoreCase ) ){
447 TF2 * dsp = new TF2("dispersion","(y<x)*(x*x+y*y < [0]*[0])",0,3,0,3) ;
448 dsp->SetParameter(0,fDispersion) ;
449 dsp->SetMinimum(0.0000001) ;
450 dsp->SetMaximum(0.001) ;
451 dsp->SetLineStyle(1) ;
452 dsp->SetLineColor(2) ;
453 dsp->SetLineWidth(2) ;
456 if(fIDOptions.Contains("ell",TString::kIgnoreCase ) )
464 //____________________________________________________________________________
465 TVector3 AliPHOSPIDv0::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSRecPoint * )const
467 // Calculates the momentum direction:
468 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
469 // 2. if a EMC RecPoint and CPV RecPoint, direction is given by the line through the 2 recpoints
470 // However because of the poor position resolution of PPSD the direction is always taken as if we were
473 TVector3 dir(0,0,0) ;
475 TVector3 emcglobalpos ;
478 emc->GetGlobalPosition(emcglobalpos, dummy) ;
481 // The following commented code becomes valid once the PPSD provides
482 // a reasonable position resolution, at least as good as EMC !
483 // TVector3 ppsdlglobalpos ;
484 // TVector3 ppsduglobalpos ;
485 // if( fPpsdLowRecPoint ){ // certainly a photon that has concerted
486 // fPpsdLowRecPoint->GetGlobalPosition(ppsdlglobalpos, mdummy) ;
487 // dir = emcglobalpos - ppsdlglobalpos ;
488 // if( fPpsdUpRecPoint ){ // not looks like a charged
489 // fPpsdUpRecPoint->GetGlobalPosition(ppsduglobalpos, mdummy) ;
490 // dir = ( dir + emcglobalpos - ppsduglobalpos ) * 0.5 ;
493 // else { // looks like a neutral
494 // dir = emcglobalpos ;
498 dir.SetZ( -dir.Z() ) ; // why ?
501 //account correction to the position of IP
502 Float_t xo,yo,zo ; //Coordinates of the origin
503 gAlice->Generator()->GetOrigin(xo,yo,zo) ;
504 TVector3 origin(xo,yo,zo);
509 //____________________________________________________________________________
510 void AliPHOSPIDv0::PrintRecParticles(Option_t * option)
512 // Print table of reconstructed particles
514 AliRunLoader* runget = AliRunLoader::GetRunLoader(GetTitle());
517 AliError(Form("Can not find run getter in event folder \"%s\"",
522 AliPHOSLoader* gime = dynamic_cast<AliPHOSLoader*>(runget->GetLoader("PHOSLoader"));
525 AliError("Could not obtain the Loader object !");
529 TString taskName(GetName()) ;
530 taskName.Remove(taskName.Index(Version())-1) ;
531 TClonesArray * recParticles = gime->RecParticles() ;
534 message = "event %d\n" ;
535 message += " found %d RecParticles\n" ;
536 AliInfo(Form(message.Data(),
537 gAlice->GetEvNumber(), recParticles->GetEntriesFast() )) ;
539 if(strstr(option,"all")) { // printing found TS
540 AliInfo(" PARTICLE Index" ) ;
543 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
544 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) recParticles->At(index) ;
547 switch(rp->GetType()) {
548 case AliPHOSFastRecParticle::kNEUTRALEMFAST:
549 strcpy( particle, "NEUTRAL EM FAST");
551 case AliPHOSFastRecParticle::kNEUTRALHAFAST:
552 strcpy(particle, "NEUTRAL HA FAST");
554 case AliPHOSFastRecParticle::kNEUTRALEMSLOW:
555 strcpy(particle, "NEUTRAL EM SLOW");
557 case AliPHOSFastRecParticle::kNEUTRALHASLOW:
558 strcpy(particle, "NEUTRAL HA SLOW");
560 case AliPHOSFastRecParticle::kCHARGEDEMFAST:
561 strcpy(particle, "CHARGED EM FAST") ;
563 case AliPHOSFastRecParticle::kCHARGEDHAFAST:
564 strcpy(particle, "CHARGED HA FAST") ;
566 case AliPHOSFastRecParticle::kCHARGEDEMSLOW:
567 strcpy(particle, "CHARGEDEMSLOW") ;
569 case AliPHOSFastRecParticle::kCHARGEDHASLOW:
570 strcpy(particle, "CHARGED HA SLOW") ;
574 // Int_t * primaries;
576 // primaries = rp->GetPrimaries(nprimaries);
578 AliInfo(Form(" %s %d",
579 particle, rp->GetIndexInList())) ;