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 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] 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 // Completely 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"
84 #include "AliPHOSGeometry.h"
85 #include "AliPHOSGetter.h"
87 ClassImp( AliPHOSPIDv1)
89 //____________________________________________________________________________
90 AliPHOSPIDv1::AliPHOSPIDv1():AliPHOSPID()
97 fHeaderFileName = "" ;
98 fTrackSegmentsTitle= "" ;
99 fRecPointsTitle = "" ;
100 fRecParticlesTitle = "" ;
101 fIDOptions = "dis time" ;
102 fRecParticlesInRun = 0 ;
107 //____________________________________________________________________________
108 AliPHOSPIDv1::AliPHOSPIDv1(const char * headerFile,const char * name) : AliPHOSPID(headerFile, name)
110 //ctor with the indication on where to look for the track segments
112 fFormula = new TFormula("LambdaCuts","(x>1)*(x<2.5)*(y>0)*(y<x)") ;
114 fCpvEmcDistance = 3.0 ;
117 fHeaderFileName = GetTitle() ;
118 fTrackSegmentsTitle = GetName() ;
119 fRecPointsTitle = GetName() ;
120 fRecParticlesTitle = GetName() ;
121 fIDOptions = "dis time" ;
123 TString tempo(GetName()) ;
125 tempo.Append(Version()) ;
127 fRecParticlesInRun = 0 ;
133 //____________________________________________________________________________
134 AliPHOSPIDv1::~AliPHOSPIDv1()
139 //____________________________________________________________________________
140 Float_t AliPHOSPIDv1::GetDistance(AliPHOSEmcRecPoint * emc,AliPHOSRecPoint * cpv, Option_t * Axis)const
142 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
144 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
148 emc->GetLocalPosition(vecEmc) ;
149 cpv->GetLocalPosition(vecCpv) ;
150 if(emc->GetPHOSMod() == cpv->GetPHOSMod()){
152 // Correct to difference in CPV and EMC position due to different distance to center.
153 // we assume, that particle moves from center
154 Float_t dCPV = geom->GetIPtoOuterCoverDistance();
155 Float_t dEMC = geom->GetIPtoCrystalSurface() ;
157 vecCpv = dEMC * vecCpv - vecEmc ;
158 if (Axis == "X") return vecCpv.X();
159 if (Axis == "Y") return vecCpv.Y();
160 if (Axis == "Z") return vecCpv.Z();
161 if (Axis == "R") return vecCpv.Mag();
167 //____________________________________________________________________________
168 void AliPHOSPIDv1::Exec(Option_t * option)
172 if( strcmp(GetName(), "")== 0 )
175 if(strstr(option,"tim"))
176 gBenchmark->Start("PHOSPID");
178 if(strstr(option,"print")) {
183 gAlice->GetEvent(0) ;
184 //check, if the branch with name of this" already exits?
185 TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
187 TBranch * branch = 0 ;
188 Bool_t phospidfound = kFALSE, pidfound = kFALSE ;
190 TString taskName(GetName()) ;
191 taskName.Remove(taskName.Index(Version())-1) ;
193 while ( (branch = (TBranch*)next()) && (!phospidfound || !pidfound) ) {
194 if ( (strcmp(branch->GetName(), "PHOSPID")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) )
195 phospidfound = kTRUE ;
197 else if ( (strcmp(branch->GetName(), "AliPHOSPID")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) )
201 if ( phospidfound || pidfound ) {
202 cerr << "WARNING: AliPHOSPIDv1::Exec -> RecParticles and/or PIDtMaker branch with name "
203 << taskName.Data() << " already exits" << endl ;
207 Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
209 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
211 for(ievent = 0; ievent < nevents; ievent++){
212 gime->Event(ievent,"R") ;
216 WriteRecParticles(ievent);
218 if(strstr(option,"deb"))
219 PrintRecParticles(option) ;
221 //increment the total number of rec particles per run
222 fRecParticlesInRun += gime->RecParticles()->GetEntriesFast() ;
226 if(strstr(option,"tim")){
227 gBenchmark->Stop("PHOSPID");
228 cout << "AliPHOSPID:" << endl ;
229 cout << " took " << gBenchmark->GetCpuTime("PHOSPID") << " seconds for PID "
230 << gBenchmark->GetCpuTime("PHOSPID")/nevents << " seconds per event " << endl ;
235 //____________________________________________________________________________
236 void AliPHOSPIDv1::Init()
238 // Make all memory allocations that are not possible in default constructor
239 // Add the PID task to the list of PHOS tasks
241 if ( strcmp(GetTitle(), "") == 0 )
242 SetTitle("galice.root") ;
244 TString taskName(GetName()) ;
245 taskName.Remove(taskName.Index(Version())-1) ;
247 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), taskName.Data()) ;
249 cerr << "ERROR: AliPHOSPIDv1::Init -> Could not obtain the Getter object !" << endl ;
253 gime->PostPID(this) ;
254 // create a folder on the white board //YSAlice/WhiteBoard/RecParticles/PHOS/recparticlesName
255 gime->PostRecParticles(taskName.Data() ) ;
259 //____________________________________________________________________________
260 void AliPHOSPIDv1::MakeRecParticles(){
262 // Makes a RecParticle out of a TrackSegment
263 TString taskName(GetName()) ;
264 taskName.Remove(taskName.Index(Version())-1) ;
266 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
267 TObjArray * emcRecPoints = gime->EmcRecPoints(taskName) ;
268 TObjArray * cpvRecPoints = gime->CpvRecPoints(taskName) ;
269 TClonesArray * trackSegments = gime->TrackSegments(taskName) ;
270 TClonesArray * recParticles = gime->RecParticles(taskName) ;
271 recParticles->Clear();
273 TIter next(trackSegments) ;
274 AliPHOSTrackSegment * ts ;
276 AliPHOSRecParticle * rp ;
278 Bool_t ellips = fIDOptions.Contains("ell",TString::kIgnoreCase ) ;
279 Bool_t disp = fIDOptions.Contains("dis",TString::kIgnoreCase ) ;
280 Bool_t time = fIDOptions.Contains("tim",TString::kIgnoreCase ) ;
282 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
284 new( (*recParticles)[index] ) AliPHOSRecParticle() ;
285 rp = (AliPHOSRecParticle *)recParticles->At(index) ;
286 rp->SetTraskSegment(index) ;
287 rp->SetIndexInList(index) ;
289 AliPHOSEmcRecPoint * emc = 0 ;
290 if(ts->GetEmcIndex()>=0)
291 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
293 AliPHOSRecPoint * cpv = 0 ;
294 if(ts->GetCpvIndex()>=0)
295 cpv = (AliPHOSRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
297 //set momentum and energy first
298 Float_t e = emc->GetEnergy() ;
299 TVector3 dir = GetMomentumDirection(emc,cpv) ;
302 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),e) ;
305 //now set type (reconstructed) of the particle
306 Int_t showerprofile = 0; // 0 narrow and 1 wide
310 emc->GetElipsAxis(lambda) ;
311 if(fFormula->Eval(lambda[0],lambda[1]) <= 0 )
312 showerprofile = 1 ; // not narrow
316 if(emc->GetDispersion() > fDispersion )
317 showerprofile = 1 ; // not narrow
321 if(emc->GetTime() > fTimeGate )
324 // Looking at the CPV detector
325 Int_t cpvdetector= 0 ; //1 hit and 0 no hit
327 if(GetDistance(emc, cpv, "R") < fCpvEmcDistance)
330 Int_t type = showerprofile + 2 * slow + 4 * cpvdetector ;
337 //____________________________________________________________________________
338 void AliPHOSPIDv1:: Print(Option_t * option) const
340 // Print the parameters used for the particle type identification
341 cout << "=============== AliPHOSPID1 ================" << endl ;
342 cout << "Making PID "<< endl ;
343 cout << " Headers file: " << fHeaderFileName.Data() << endl ;
344 cout << " RecPoints branch title: " << fRecPointsTitle.Data() << endl ;
345 cout << " TrackSegments Branch title: " << fTrackSegmentsTitle.Data() << endl ;
346 cout << " RecParticles Branch title " << fRecParticlesTitle.Data() << endl;
347 cout << "with parameters: " << endl ;
348 cout << " Maximal EMC - CPV distance (cm) " << fCpvEmcDistance << endl ;
349 if(fIDOptions.Contains("dis",TString::kIgnoreCase ))
350 cout << " dispersion cut " << fDispersion << endl ;
351 if(fIDOptions.Contains("ell",TString::kIgnoreCase )){
352 cout << " Eliptic cuts function: " << endl ;
353 cout << fFormula->GetTitle() << endl ;
355 if(fIDOptions.Contains("tim",TString::kIgnoreCase ))
356 cout << " Time Gate uzed: " << fTimeGate << endl ;
357 cout << "============================================" << endl ;
360 //____________________________________________________________________________
361 void AliPHOSPIDv1::SetShowerProfileCut(char * formula)
363 //set shape of the cut on the axis of ellipce, drown around shouer
364 //shower considered "narrow" if Formula(lambda[0],lambda[1]) > 0.
367 fFormula = new TFormula("Lambda Cut",formula) ;
369 //____________________________________________________________________________
370 void AliPHOSPIDv1::WriteRecParticles(Int_t event)
373 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
374 TString taskName(GetName()) ;
375 taskName.Remove(taskName.Index(Version())-1) ;
376 TClonesArray * recParticles = gime->RecParticles(taskName) ;
377 recParticles->Expand(recParticles->GetEntriesFast() ) ;
379 //Make branch in TreeR for RecParticles
381 if(gSystem->Getenv("CONFIG_SPLIT_FILE")!=0){ //generating file name
382 filename = new char[strlen(gAlice->GetBaseFile())+20] ;
383 sprintf(filename,"%s/PHOS.Reco.root",gAlice->GetBaseFile()) ;
386 TDirectory *cwd = gDirectory;
389 Int_t bufferSize = 32000 ;
390 TBranch * rpBranch = gAlice->TreeR()->Branch("PHOSRP",&recParticles,bufferSize);
391 rpBranch->SetTitle(fRecParticlesTitle);
393 rpBranch->SetFile(filename);
394 TIter next( rpBranch->GetListOfBranches());
396 while ((sb=(TBranch*)next())) {
397 sb->SetFile(filename);
403 Int_t splitlevel = 0 ;
404 AliPHOSPIDv1 * pid = this ;
405 TBranch * pidBranch = gAlice->TreeR()->Branch("AliPHOSPID","AliPHOSPIDv1",&pid,bufferSize,splitlevel);
406 pidBranch->SetTitle(fRecParticlesTitle.Data());
408 pidBranch->SetFile(filename);
409 TIter next( pidBranch->GetListOfBranches());
411 while ((sb=(TBranch*)next())) {
412 sb->SetFile(filename);
420 gAlice->TreeR()->Write(0,kOverwrite) ;
424 //____________________________________________________________________________
425 void AliPHOSPIDv1::PlotDispersionCuts()const
427 // produces a plot of the dispersion cut
428 TCanvas* lambdas = new TCanvas("lambdas","Cuts on the ellipse axis",200,10,700,500);
430 if(fIDOptions.Contains("ell",TString::kIgnoreCase ) ){
431 TF2 * ell = new TF2("Elliptic Cuts",fFormula->GetName(),0,3,0,3) ;
432 ell->SetMinimum(0.0000001) ;
433 ell->SetMaximum(0.001) ;
434 ell->SetLineStyle(1) ;
435 ell->SetLineWidth(2) ;
439 if( fIDOptions.Contains("dis",TString::kIgnoreCase ) ){
440 TF2 * dsp = new TF2("dispersion","(y<x)*(x*x+y*y < [0]*[0])",0,3,0,3) ;
441 dsp->SetParameter(0,fDispersion) ;
442 dsp->SetMinimum(0.0000001) ;
443 dsp->SetMaximum(0.001) ;
444 dsp->SetLineStyle(1) ;
445 dsp->SetLineColor(2) ;
446 dsp->SetLineWidth(2) ;
449 if(fIDOptions.Contains("ell",TString::kIgnoreCase ) )
457 //____________________________________________________________________________
458 TVector3 AliPHOSPIDv1::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSRecPoint * cpv)const
460 // Calculates the momentum direction:
461 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
462 // 2. if a EMC RecPoint and CPV RecPoint, direction is given by the line through the 2 recpoints
463 // However because of the poor position resolution of PPSD the direction is always taken as if we were
466 TVector3 dir(0,0,0) ;
468 TVector3 emcglobalpos ;
471 emc->GetGlobalPosition(emcglobalpos, dummy) ;
474 // The following commented code becomes valid once the PPSD provides
475 // a reasonable position resolution, at least as good as EMC !
476 // TVector3 ppsdlglobalpos ;
477 // TVector3 ppsduglobalpos ;
478 // if( fPpsdLowRecPoint ){ // certainly a photon that has concerted
479 // fPpsdLowRecPoint->GetGlobalPosition(ppsdlglobalpos, mdummy) ;
480 // dir = emcglobalpos - ppsdlglobalpos ;
481 // if( fPpsdUpRecPoint ){ // not looks like a charged
482 // fPpsdUpRecPoint->GetGlobalPosition(ppsduglobalpos, mdummy) ;
483 // dir = ( dir + emcglobalpos - ppsduglobalpos ) * 0.5 ;
486 // else { // looks like a neutral
487 // dir = emcglobalpos ;
491 dir.SetZ( -dir.Z() ) ; // why ?
494 //account correction to the position of IP
495 Float_t xo,yo,zo ; //Coordinates of the origin
496 gAlice->Generator()->GetOrigin(xo,yo,zo) ;
497 TVector3 origin(xo,yo,zo);
502 //____________________________________________________________________________
503 void AliPHOSPIDv1::PrintRecParticles(Option_t * option)
505 // Print table of reconstructed particles
507 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
509 TString taskName(GetName()) ;
510 taskName.Remove(taskName.Index(Version())-1) ;
511 TClonesArray * recParticles = gime->RecParticles(taskName) ;
513 cout << "AliPHOSPIDv1: event "<<gAlice->GetEvNumber() << endl ;
514 cout << " found " << recParticles->GetEntriesFast() << " RecParticles " << endl ;
516 if(strstr(option,"all")) { // printing found TS
519 << " Index " << endl ;
523 // << " # of primaries "
524 // << " Primaries list " << endl;
527 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
528 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) recParticles->At(index) ;
531 switch(rp->GetType()) {
532 case AliPHOSFastRecParticle::kNEUTRALEMFAST:
533 strcpy( particle, "NEUTRAL EM FAST");
535 case AliPHOSFastRecParticle::kNEUTRALHAFAST:
536 strcpy(particle, "NEUTRAL HA FAST");
538 case AliPHOSFastRecParticle::kNEUTRALEMSLOW:
539 strcpy(particle, "NEUTRAL EM SLOW");
541 case AliPHOSFastRecParticle::kNEUTRALHASLOW:
542 strcpy(particle, "NEUTRAL HA SLOW");
544 case AliPHOSFastRecParticle::kCHARGEDEMFAST:
545 strcpy(particle, "CHARGED EM FAST") ;
547 case AliPHOSFastRecParticle::kCHARGEDHAFAST:
548 strcpy(particle, "CHARGED HA FAST") ;
550 case AliPHOSFastRecParticle::kCHARGEDEMSLOW:
551 strcpy(particle, "CHARGEDEMSLOW") ;
553 case AliPHOSFastRecParticle::kCHARGEDHASLOW:
554 strcpy(particle, "CHARGED HA SLOW") ;
558 // Int_t * primaries;
560 // primaries = rp->GetPrimaries(nprimaries);
562 cout << setw(10) << particle << " "
563 << setw(5) << rp->GetIndexInList() << " " ;
564 // << setw(4) << nprimaries << " ";
565 // for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
566 // cout << setw(4) << primaries[iprimary] << " ";
569 cout << "-------------------------------------------" << endl ;