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 PHOS particle identifier
20 // Particle identification based on the
22 // - Preshower information (in MIX or GPS2 geometries)
25 // CPV or Preshower cluster should be clother in PHOS plane than fCpvEmcDistance (in cm).
26 // This variable can be set by method SetCpvtoEmcDistanceCut(Float_t cut)
28 // One can set desirable ID method by the function SetIdentificationMethod(option).
29 // Now 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, drown 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] AliPHOSPIDv1 * p1 = new AliPHOSPIDv1("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] AliPHOSPIDv1 * p2 = new AliPHOSPIDv1("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 // Complitely redesined by Dmitri Peressounko, March 2001
59 // --- ROOT system ---
68 #include "TBenchmark.h"
69 // --- Standard library ---
74 // --- AliRoot header files ---
77 #include "AliGenerator.h"
79 #include "AliPHOSPIDv1.h"
80 #include "AliPHOSClusterizerv1.h"
81 #include "AliPHOSTrackSegment.h"
82 #include "AliPHOSTrackSegmentMakerv1.h"
83 #include "AliPHOSRecParticle.h"
85 ClassImp( AliPHOSPIDv1)
87 //____________________________________________________________________________
88 AliPHOSPIDv1::AliPHOSPIDv1():AliPHOSPID()
90 fIsInitialized = kFALSE ;
93 //____________________________________________________________________________
94 AliPHOSPIDv1::AliPHOSPIDv1(const char * headeFile,const char * tsBranchTitle):AliPHOSPID()
97 fHeaderFileName = headeFile ;
99 fTSTitle = tsBranchTitle ;
101 SetName("AliPHOSPID") ;
102 SetTitle("version1") ;
104 TFile * file = (TFile*) gROOT->GetFile(fHeaderFileName.Data() ) ;
107 if(fHeaderFileName.Contains("rfio")) // if we read file using HPSS
108 file = TFile::Open(fHeaderFileName.Data(),"update") ;
110 file = new TFile(fHeaderFileName.Data(),"update") ;
111 gAlice = (AliRun *) file->Get("gAlice") ;
114 AliPHOS * phos = (AliPHOS *) gAlice->GetDetector("PHOS") ;
115 fGeom = AliPHOSGeometry::GetInstance(phos->GetGeometry()->GetName(),phos->GetGeometry()->GetTitle() );
117 fTrackSegments = new TClonesArray("AliPHOSTrackSegment",1) ;
119 fEmcRecPoints = new TObjArray(1) ;
120 fCpvRecPoints = new TObjArray(1) ;
122 fRecParticles = new TClonesArray("AliPHOSRecParticle",100) ;
124 fFormula = new TFormula("LambdaCuts","(x>1)*(x<3)*(y>0)*(y<x)") ;
126 // add Task to //root/Tasks folder
127 TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ;
128 roottasks->Add(this) ;
131 fCpvEmcDistance = 3.0 ;
132 fIsInitialized = kTRUE ;
135 //____________________________________________________________________________
136 AliPHOSPIDv1::~AliPHOSPIDv1()
140 //____________________________________________________________________________
141 void AliPHOSPIDv1::Init()
143 // Make all memory allocationa not possible in default constructor
145 if(fHeaderFileName.IsNull())
146 fHeaderFileName = "galice.root" ;
148 TFile * file = (TFile*) gROOT->GetFile(fHeaderFileName.Data() ) ;
151 file = new TFile(fHeaderFileName.Data(),"update") ;
152 gAlice = (AliRun *) file->Get("gAlice") ;
155 AliPHOS * phos = (AliPHOS *) gAlice->GetDetector("PHOS") ;
156 fGeom = AliPHOSGeometry::GetInstance(phos->GetGeometry()->GetName(),phos->GetGeometry()->GetTitle() );
158 fTrackSegments = new TClonesArray("AliPHOSTrackSegment",1) ;
159 fTSMaker = new AliPHOSTrackSegmentMakerv1() ;
160 fEmcRecPoints = new TObjArray(1) ;
161 fCpvRecPoints = new TObjArray(1) ;
162 fClusterizer = new AliPHOSClusterizerv1() ;
163 fRecParticles = new TClonesArray("AliPHOSRecParticle",100) ;
165 fFormula = new TFormula("LambdaCuts","(x>1)*(x<2.5)*(y>0)*(y<x)") ;
167 // add Task to //root/Tasks folder
168 TTask * roottasks = (TTask*)gROOT->GetRootFolder()->FindObject("Tasks") ;
169 roottasks->Add(this) ;
172 fCpvEmcDistance = 3.0 ;
174 fIsInitialized = kTRUE ;
177 //____________________________________________________________________________
178 Bool_t AliPHOSPIDv1::ReadTrackSegments()
180 // Reads TrackSegments an extracts the title of the RecPoints
181 // branch from which TS were made.
182 // Then reads both TrackSegments and RecPoints.
184 //Fist read Track Segment Branch and extract RecPointsBranch from fTSMaker
185 fTrackSegments->Clear() ;
186 fEmcRecPoints->Clear() ;
187 fCpvRecPoints->Clear() ;
188 fRecParticles->Clear() ;
190 gAlice->GetEvent(fNEvent) ;
192 TTree * treeR = gAlice->TreeR() ;
196 sprintf(treeName,"TreeR%d",fNEvent);
197 cout << "Error in AliPHOSClusterizerv1 : no "<<treeName << endl ;
198 cout << " Do nothing " << endl ;
202 //first read TSMaker branch and extract information about RecPoints Branches
203 TBranch * tsMakerBranch = 0;
204 TBranch * tsBranch = 0;
206 TObjArray * branches = treeR->GetListOfBranches() ;
208 Bool_t tsMakerNotFound = kTRUE ;
209 Bool_t tsNotFound = kTRUE ;
211 for(ibranch = 0;(ibranch <branches->GetEntries())&&(tsMakerNotFound||tsNotFound);ibranch++){
213 tsMakerBranch=(TBranch *) branches->At(ibranch) ;
214 if( fTSTitle.CompareTo(tsMakerBranch->GetTitle())==0 )
215 if( strcmp(tsMakerBranch->GetName(),"AliPHOSTrackSegmentMaker") == 0)
216 tsMakerNotFound = kFALSE ;
219 tsBranch=(TBranch *) branches->At(ibranch) ;
220 if( fTSTitle.CompareTo(tsBranch->GetTitle())==0 )
221 if( strcmp(tsBranch->GetName(),"PHOSTS") == 0)
222 tsNotFound = kFALSE ;
226 if(tsMakerNotFound ||tsNotFound ){
227 cout << "Can't find Branch with TrackSegmentMaker and TrackSegments " ;
228 cout << "Do nothing" <<endl ;
232 tsMakerBranch->SetAddress(&fTSMaker) ;
233 tsBranch->SetAddress(&fTrackSegments) ;
237 fRecPointsTitle = fTSMaker->GetRecPointsBranch() ;
239 //reading now recponts branches
240 TBranch * emcBranch = 0;
241 TBranch * cpvBranch = 0;
242 TBranch * cluBranch = 0;
244 Bool_t emcNotFound = kTRUE ;
245 Bool_t cpvNotFound = kTRUE ;
246 Bool_t cluNotFound = kTRUE ;
248 for(ibranch = 0;(ibranch <branches->GetEntries())&&(emcNotFound||cpvNotFound||cluNotFound);ibranch++){
250 emcBranch=(TBranch *) branches->At(ibranch) ;
251 if( fRecPointsTitle.CompareTo(emcBranch->GetTitle())==0 )
252 if( strcmp(emcBranch->GetName(),"PHOSEmcRP") == 0)
253 emcNotFound = kFALSE ;
256 cpvBranch=(TBranch *) branches->At(ibranch) ;
257 if( fRecPointsTitle.CompareTo(cpvBranch->GetTitle())==0 )
258 if( strcmp(cpvBranch->GetName(),"PHOSCpvRP") == 0)
259 cpvNotFound = kFALSE ;
262 cluBranch=(TBranch *) branches->At(ibranch) ;
263 if( fRecPointsTitle.CompareTo(cluBranch->GetTitle())==0 )
264 if( strcmp(cluBranch->GetName(),"AliPHOSClusterizer") == 0)
265 cluNotFound = kFALSE ;
269 if(emcNotFound ||cpvNotFound ||cluNotFound ){
270 cout << "Can't find Branch with RecPoints or AliPHOSClusterizer " ;
271 cout << "Do nothing" <<endl ;
275 emcBranch->SetAddress(&fEmcRecPoints) ;
276 cpvBranch->SetAddress(&fCpvRecPoints) ;
277 cluBranch->SetAddress(&fClusterizer) ;
285 //____________________________________________________________________________
286 Float_t AliPHOSPIDv1::GetDistance(AliPHOSEmcRecPoint * emc,AliPHOSRecPoint * cpv, Option_t * Axis)const
288 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
293 emc->GetLocalPosition(vecEmc) ;
294 cpv->GetLocalPosition(vecCpv) ;
295 if(emc->GetPHOSMod() == cpv->GetPHOSMod()){
297 // Correct to difference in CPV and EMC position due to different distance to center.
298 // we assume, that particle moves from center
299 Float_t dCPV = fGeom->GetIPtoOuterCoverDistance();
300 Float_t dEMC = fGeom->GetIPtoCrystalSurface() ;
302 vecCpv = dEMC * vecCpv - vecEmc ;
303 if (Axis == "X") return vecCpv.X();
304 if (Axis == "Y") return vecCpv.Y();
305 if (Axis == "Z") return vecCpv.Z();
306 if (Axis == "R") return vecCpv.Mag();
312 //____________________________________________________________________________
313 void AliPHOSPIDv1::Exec(Option_t * option)
320 if(strstr(option,"tim"))
321 gBenchmark->Start("PHOSPID");
324 Int_t nEvents = (Int_t) gAlice->TreeE()->GetEntries() ;
326 for(fNEvent = 0 ;fNEvent <nEvents; fNEvent++){
327 if(!ReadTrackSegments())
331 if(strstr(option,"deb"))
332 PrintRecParticles(option) ;
335 if(strstr(option,"tim")){
336 gBenchmark->Stop("PHOSPID");
337 cout << "AliPHOSPID:" << endl ;
338 cout << " took " << gBenchmark->GetCpuTime("PHOSPID") << " seconds for PID "
339 << gBenchmark->GetCpuTime("PHOSPID")/nEvents << " seconds per event " << endl ;
344 //____________________________________________________________________________
345 void AliPHOSPIDv1::MakeRecParticles(){
347 // Makes a RecParticle out of a TrackSegment
349 TIter next(fTrackSegments) ;
350 AliPHOSTrackSegment * ts ;
352 AliPHOSRecParticle * rp ;
354 Bool_t ellips = fIDOptions.Contains("ell",TString::kIgnoreCase ) ;
355 Bool_t disp = fIDOptions.Contains("dis",TString::kIgnoreCase ) ;
357 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
359 new( (*fRecParticles)[index] ) AliPHOSRecParticle() ;
360 rp = (AliPHOSRecParticle *)fRecParticles->At(index) ;
361 rp->SetTraskSegment(index) ;
363 AliPHOSEmcRecPoint * emc = 0 ;
364 if(ts->GetEmcIndex()>=0)
365 emc = (AliPHOSEmcRecPoint *) fEmcRecPoints->At(ts->GetEmcIndex()) ;
367 AliPHOSRecPoint * cpv = 0 ;
368 if(ts->GetCpvIndex()>=0)
369 cpv = (AliPHOSRecPoint *) fCpvRecPoints->At(ts->GetCpvIndex()) ;
371 AliPHOSRecPoint * ppsd = 0 ;
372 if(ts->GetPpsdIndex()>=0)
373 ppsd= (AliPHOSRecPoint *) fCpvRecPoints->At(ts->GetPpsdIndex()) ;
375 //set momentum and energy first
376 Float_t e = emc->GetEnergy() ;
377 TVector3 dir = GetMomentumDirection(emc,cpv,ppsd) ;
380 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),e) ;
383 //now set type (reconstructed) of the particle
384 Int_t showerprofile = 0; // 0 narrow and 1 wide
388 emc->GetElipsAxis(lambda) ;
389 if(fFormula->Eval(lambda[0],lambda[1]) <= 0 )
390 showerprofile = 1 ; // not narrow
394 if(emc->GetDispersion() > fDispersion )
395 showerprofile = 1 ; // not narrow
398 // Looking at the photon conversion detector
399 Int_t pcdetector= 0 ; //1 hit and 0 no hit
401 if(GetDistance(emc, ppsd, "R") < fCpvEmcDistance)
404 // Looking at the CPV detector
405 Int_t cpvdetector= 0 ; //1 hit and 0 no hit
407 if(GetDistance(emc, cpv, "R") < fCpvEmcDistance)
410 Int_t type = showerprofile + 2 * pcdetector + 4 * cpvdetector ;
417 //____________________________________________________________________________
418 void AliPHOSPIDv1:: Print(Option_t * option) const
420 // Print the parameters used for the particle type identification
421 cout << "=============== AliPHOSPID1 ================" << endl ;
422 cout << "Making PID "<< endl ;
423 cout << " Headers file: " << fHeaderFileName.Data() << endl ;
424 cout << " RecPoints branch title: " << fRecPointsTitle.Data() << endl ;
425 cout << " TrackSegments Branch title: " << fTSTitle.Data() << endl ;
426 cout << " RecParticles Branch title " << fRecparticlesTitle.Data() << endl;
427 cout << "with parameters: " << endl ;
428 cout << " Maximal EMC - CPV (PPSD) distance (cm) " << fCpvEmcDistance << endl ;
429 if(fIDOptions.Contains("dis",TString::kIgnoreCase ))
430 cout << " dispersion cut " << fDispersion << endl ;
431 if(fIDOptions.Contains("ell",TString::kIgnoreCase )){
432 cout << "Eliptic cuts function: " << endl ;
433 cout << fFormula->GetTitle() << endl ;
435 cout << "============================================" << endl ;
438 //____________________________________________________________________________
439 void AliPHOSPIDv1::SetShowerProfileCut(char * formula){
440 //set shape of the cut on the axis of ellipce, drown around shouer
441 //shower considered "narrow" if Formula(lambda[0],lambda[1]) > 0.
444 fFormula = new TFormula("Lambda Cut",formula) ;
446 //____________________________________________________________________________
447 void AliPHOSPIDv1::WriteRecParticles()
449 //check, if these branches already exist
450 TBranch * pidBranch = 0;
451 TBranch * rpBranch = 0;
453 TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
455 Bool_t pidNotFound = kTRUE ;
456 Bool_t rpNotFound = kTRUE ;
458 for(ibranch = 0;(ibranch <branches->GetEntries())&& pidNotFound && rpNotFound;ibranch++){
460 pidBranch=(TBranch *) branches->At(ibranch) ;
461 if( (strcmp(pidBranch->GetName(),"PHOSPID") == 0) &&
462 (fRecparticlesTitle.CompareTo(pidBranch->GetTitle()) == 0) )
463 pidNotFound = kFALSE ;
466 rpBranch=(TBranch *) branches->At(ibranch) ;
467 if( (strcmp(rpBranch->GetName(),"PHOSRP") == 0) &&
468 (fRecparticlesTitle.CompareTo(rpBranch->GetTitle())==0 ))
469 rpNotFound = kFALSE ;
473 if(!pidNotFound || !rpNotFound) {
474 cout << "AliPHOSPIDv1 error: " << endl ;
475 cout << " Branch PHOSRP and PHOSPID with title '"<<fRecparticlesTitle.Data()<<"' already exist "<< endl ;
476 cout << " can not overwrite " << endl ;
480 //Make branch in TreeR for TrackSegments
482 if(gSystem->Getenv("CONFIG_SPLIT_FILE")!=0){ //generating file name
483 filename = new char[strlen(gAlice->GetBaseFile())+20] ;
484 sprintf(filename,"%s/PHOS.Reco.root",gAlice->GetBaseFile()) ;
487 TDirectory *cwd = gDirectory;
490 Int_t bufferSize = 32000 ;
491 rpBranch = gAlice->TreeR()->Branch("PHOSRP",&fRecParticles,bufferSize);
492 rpBranch->SetTitle(fRecparticlesTitle.Data());
494 rpBranch->SetFile(filename);
495 TIter next( rpBranch->GetListOfBranches());
496 while ((rpBranch=(TBranch*)next())) {
497 rpBranch->SetFile(filename);
503 Int_t splitlevel = 0 ;
504 AliPHOSPIDv1 * pid = this ;
505 pidBranch = gAlice->TreeR()->Branch("AliPHOSPID","AliPHOSPIDv1",&pid,bufferSize,splitlevel);
506 pidBranch->SetTitle(fRecparticlesTitle.Data());
508 pidBranch->SetFile(filename);
509 TIter next( pidBranch->GetListOfBranches());
510 while ((pidBranch=(TBranch*)next())) {
511 pidBranch->SetFile(filename);
516 gAlice->TreeR()->Fill() ;
517 gAlice->TreeR()->Write(0,kOverwrite) ;
520 //____________________________________________________________________________
521 void AliPHOSPIDv1::PlotDispersionCuts()const
523 TCanvas* lambdas = new TCanvas("lambdas","Cuts on the elipse axise",200,10,700,500);
525 if(fIDOptions.Contains("ell",TString::kIgnoreCase ) ){
526 TF2 * ell = new TF2("Elliptic Cuts",fFormula->GetName(),0,3,0,3) ;
527 ell->SetMinimum(0.0000001) ;
528 ell->SetMaximum(0.001) ;
529 ell->SetLineStyle(1) ;
530 ell->SetLineWidth(2) ;
534 if( fIDOptions.Contains("dis",TString::kIgnoreCase ) ){
535 TF2 * dsp = new TF2("dispersion","(y<x)*(x*x+y*y < [0]*[0])",0,3,0,3) ;
536 dsp->SetParameter(0,fDispersion) ;
537 dsp->SetMinimum(0.0000001) ;
538 dsp->SetMaximum(0.001) ;
539 dsp->SetLineStyle(1) ;
540 dsp->SetLineColor(2) ;
541 dsp->SetLineWidth(2) ;
544 if(fIDOptions.Contains("ell",TString::kIgnoreCase ) )
552 //____________________________________________________________________________
553 TVector3 AliPHOSPIDv1::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSRecPoint * cpv,AliPHOSRecPoint * ppsd)const
555 // Calculates the momentum direction:
556 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
557 // 2. if a EMC RecPoint and one PPSD RecPoint, direction is given by the line through the 2 recpoints
558 // 3. if a EMC RecPoint and two PPSD RecPoints, dirrection is given by the average line through
559 // the 2 pairs of recpoints
560 // However because of the poor position resolution of PPSD the direction is always taken as if we were
563 TVector3 dir(0,0,0) ;
565 TVector3 emcglobalpos ;
568 emc->GetGlobalPosition(emcglobalpos, dummy) ;
571 // The following commeneted code becomes valid once the PPSD provides
572 // a reasonable position resolution, at least as good as EMC !
573 // TVector3 ppsdlglobalpos ;
574 // TVector3 ppsduglobalpos ;
575 // if( fPpsdLowRecPoint ){ // certainly a photon that has concerted
576 // fPpsdLowRecPoint->GetGlobalPosition(ppsdlglobalpos, mdummy) ;
577 // dir = emcglobalpos - ppsdlglobalpos ;
578 // if( fPpsdUpRecPoint ){ // not looks like a charged
579 // fPpsdUpRecPoint->GetGlobalPosition(ppsduglobalpos, mdummy) ;
580 // dir = ( dir + emcglobalpos - ppsduglobalpos ) * 0.5 ;
583 // else { // looks like a neutral
584 // dir = emcglobalpos ;
588 dir.SetZ( -dir.Z() ) ; // why ?
591 //account correction to the position of IP
592 Float_t xo,yo,zo ; //Coordinates of the origin
593 gAlice->Generator()->GetOrigin(xo,yo,zo) ;
594 TVector3 origin(xo,yo,zo);
599 //____________________________________________________________________________
600 void AliPHOSPIDv1::PrintRecParticles(Option_t * option){
602 cout << "AliPHOSPIDv1: " << endl ;
603 cout << " found " << fRecParticles->GetEntriesFast() << " RecParticles " << endl ;
605 if(strstr(option,"all")) { // printing found TS
608 << " Index " << endl ;
612 // << " # of primaries "
613 // << " Primaries list " << endl;
616 for (index = 0 ; index < fRecParticles->GetEntries() ; index++) {
617 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) fRecParticles->At(index) ;
620 switch(rp->GetType()) {
621 case AliPHOSFastRecParticle::kNEUTRALEM:
622 strcpy( particle, "NEUTRAL_EM");
624 case AliPHOSFastRecParticle::kNEUTRALHA:
625 strcpy(particle, "NEUTRAL_HA");
627 case AliPHOSFastRecParticle::kGAMMA:
628 strcpy(particle, "GAMMA");
630 case AliPHOSFastRecParticle::kGAMMAHA:
631 strcpy(particle, "GAMMA_H");
633 case AliPHOSFastRecParticle::kABSURDEM:
634 strcpy(particle, "ABSURD_EM") ;
636 case AliPHOSFastRecParticle::kABSURDHA:
637 strcpy(particle, "ABSURD_HA") ;
639 case AliPHOSFastRecParticle::kELECTRON:
640 strcpy(particle, "ELECTRON") ;
642 case AliPHOSFastRecParticle::kCHARGEDHA:
643 strcpy(particle, "CHARGED_HA") ;
647 // Int_t * primaries;
649 // primaries = rp->GetPrimaries(nprimaries);
651 cout << setw(15) << particle << " "
652 << setw(3) << rp->GetIndexInList() << " " ;
653 // << setw(4) << nprimaries << " ";
654 // for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
655 // cout << setw(4) << primaries[iprimary] << " ";
658 cout << "-------------------------------------------" << endl ;