A new (final?) geometry developed
[u/mrichter/AliRoot.git] / PHOS / AliPHOSPIDv1.cxx
CommitLineData
6ad0bfa0 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
b2a60966 16/* $Id$ */
17
6ad0bfa0 18//_________________________________________________________________________
b2a60966 19// Implementation version v1 of the PHOS particle identifier
7acf6008 20// Particle identification based on the
21// - CPV information,
a4e98857 22// - Preshower information (in MIXT or GPS2 geometries)
7acf6008 23// - shower width.
a4e98857 24//
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)
7acf6008 27//
28// One can set desirable ID method by the function SetIdentificationMethod(option).
a4e98857 29// Presently the following options can be used together or separately :
7acf6008 30// - "disp": use dispersion cut on shower width
31// (width can be set by method SetDispersionCut(Float_t cut)
a4e98857 32// - "ell" : use cut on the axis of the ellipse, drawn around shower
7acf6008 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().
37//
a4e98857 38// use case:
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
7acf6008 45// // reading headers from file galice1.root and TrackSegments
46// // with title "ts1"
a4e98857 47// root [4] p2->SetRecParticlesBranch("rp1")
7acf6008 48// // set file name for the branch RecParticles
a4e98857 49// root [5] p2->ExecuteTask("deb all time")
7acf6008 50// // available options
51// // "deb" - prints # of reconstructed particles
52// // "deb all" - prints # and list of RecParticles
53// // "time" - prints benchmarking results
54//
55//*-- Author: Yves Schutz (SUBATECH) & Gines Martinez (SUBATECH) &
56// Dmitri Peressounko (SUBATECH & Kurchatov Institute)
57// Complitely redesined by Dmitri Peressounko, March 2001
6ad0bfa0 58
59// --- ROOT system ---
7acf6008 60#include "TROOT.h"
61#include "TTree.h"
62#include "TFile.h"
63#include "TF2.h"
64#include "TFormula.h"
65#include "TCanvas.h"
66#include "TFolder.h"
67#include "TSystem.h"
68#include "TBenchmark.h"
6ad0bfa0 69// --- Standard library ---
70
de9ec31b 71#include <iostream.h>
7acf6008 72#include <iomanip.h>
6ad0bfa0 73
74// --- AliRoot header files ---
75
7acf6008 76#include "AliRun.h"
77#include "AliGenerator.h"
78#include "AliPHOS.h"
26d4b141 79#include "AliPHOSPIDv1.h"
7acf6008 80#include "AliPHOSClusterizerv1.h"
6ad0bfa0 81#include "AliPHOSTrackSegment.h"
7acf6008 82#include "AliPHOSTrackSegmentMakerv1.h"
6ad0bfa0 83#include "AliPHOSRecParticle.h"
7b7c1533 84#include "AliPHOSGeometry.h"
85#include "AliPHOSGetter.h"
6ad0bfa0 86
26d4b141 87ClassImp( AliPHOSPIDv1)
6ad0bfa0 88
6ad0bfa0 89//____________________________________________________________________________
1cb7c1ee 90AliPHOSPIDv1::AliPHOSPIDv1():AliPHOSPID()
91{
a4e98857 92 // default ctor
7b7c1533 93 fFormula = 0 ;
94 fDispersion = 0. ;
95 fCpvEmcDistance = 0 ;
96 fHeaderFileName = "" ;
97 fTrackSegmentsTitle= "" ;
98 fRecPointsTitle = "" ;
99 fRecParticlesTitle = "" ;
100 fIDOptions = "" ;
2b60655b 101 fRecParticlesInRun = 0 ;
7acf6008 102}
103
104//____________________________________________________________________________
7b7c1533 105AliPHOSPIDv1::AliPHOSPIDv1(const char * headerFile,const char * name) : AliPHOSPID(headerFile, name)
7acf6008 106{
a4e98857 107 //ctor with the indication on where to look for the track segments
dd5c4038 108
7b7c1533 109 fFormula = new TFormula("LambdaCuts","(x>1)*(x<2.5)*(y>0)*(y<x)") ;
110 fDispersion = 2.0 ;
111 fCpvEmcDistance = 3.0 ;
112
113 fHeaderFileName = GetTitle() ;
114 fTrackSegmentsTitle = GetName() ;
115 fRecPointsTitle = GetName() ;
116 fRecParticlesTitle = GetName() ;
117 fIDOptions = "" ;
118
119 TString tempo(GetName()) ;
bf8f1fbd 120 tempo.Append(":") ;
7b7c1533 121 tempo.Append(Version()) ;
bf8f1fbd 122 SetName(tempo) ;
2b60655b 123 fRecParticlesInRun = 0 ;
7b7c1533 124
2bd5457f 125 Init() ;
7acf6008 126
127}
7b7c1533 128
7acf6008 129//____________________________________________________________________________
130AliPHOSPIDv1::~AliPHOSPIDv1()
131{
a4e98857 132 //dtor
7acf6008 133}
2bd5457f 134
7acf6008 135//____________________________________________________________________________
7b7c1533 136Bool_t AliPHOSPIDv1::ReadTrackSegments(Int_t event)
7acf6008 137{
f035f6ce 138 // Reads TrackSegments an extracts the title of the RecPoints
a4e98857 139 // branch from which TS were made of.
f035f6ce 140 // Then reads both TrackSegments and RecPoints.
7acf6008 141
f035f6ce 142 //Fist read Track Segment Branch and extract RecPointsBranch from fTSMaker
7acf6008 143
7b7c1533 144 // Get TreeR header from file
145 if(gAlice->TreeR()==0){
146 cerr << "ERROR: AliPHOSPIDv1::ReadTrackSegments -> There is no Reconstruction Tree" << endl;
147 return kFALSE;
7acf6008 148 }
7b7c1533 149
150 // Find TrackSegments
151 TBranch * tsbranch = 0;
152 TBranch * tsmakerbranch = 0;
153 TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
154 TIter next(lob) ;
155 TBranch * branch = 0 ;
156 Bool_t phostsfound = kFALSE, tsmakerfound = kFALSE ;
157
158 TString taskName(GetName()) ;
159 taskName.ReplaceAll(Version(), "") ;
7acf6008 160
7b7c1533 161 while ( (branch = (TBranch*)next()) && (!phostsfound || !tsmakerfound) ) {
162 if ( (strcmp(branch->GetName(), "PHOSTS")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) ) {
163 phostsfound = kTRUE ;
164 tsbranch = branch ;
7acf6008 165
7b7c1533 166 } else if ( (strcmp(branch->GetName(), "AliPHOSTrackSegmentMaker")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) ) {
167 tsmakerfound = kTRUE ;
168 tsmakerbranch = branch ;
7acf6008 169 }
170 }
7b7c1533 171 if ( !phostsfound || !tsmakerfound ) {
172 cerr << "WARNING: AliPHOSPIDv1::ReadTrackSegments -> TrackSegments and/or TrackSegmentMaker branch with name " << taskName.Data()
173 << " not found" << endl ;
174 return kFALSE ;
175 }
7acf6008 176
7b7c1533 177 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
178
179 TClonesArray * trackSegments = gime->TrackSegments() ;
180 trackSegments->Clear() ;
181 tsbranch->SetAddress(&trackSegments) ;
182
183 AliPHOSTrackSegmentMaker * tsmaker = 0 ;
184 tsmakerbranch->SetAddress(&tsmaker) ;
185 tsmakerbranch->GetEntry(0) ;
186 TString tsmakerName( fRecParticlesTitle ) ;
187 tsmakerName.Append(tsmaker->Version()) ;
188 tsmaker = gime->TrackSegmentMaker(tsmakerName) ;
189
190 tsbranch->GetEntry(0) ;
191 tsmakerbranch->GetEntry(0) ;
192
193 fRecPointsTitle = tsmaker->GetRecPointsBranch() ;
194
195 // Find RecPoints
196 TBranch * emcbranch = 0;
197 TBranch * cpvbranch = 0;
198 TBranch * clusterizerbranch = 0;
199 lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
200 TIter next2(lob) ;
201 branch = 0 ;
202 Bool_t phosemcfound = kFALSE, phoscpvfound = kFALSE, clusterizerfound = kFALSE ;
203
204 while ( (branch = (TBranch*)next2()) && (!phosemcfound || !phoscpvfound || !clusterizerfound) ) {
205 if ( (strcmp(branch->GetName(), "PHOSEmcRP")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) ) {
206 phosemcfound = kTRUE ;
207 emcbranch = branch ;
7acf6008 208 }
7b7c1533 209
210 else if ( (strcmp(branch->GetName(), "PHOSCpvRP")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) ) {
211 phoscpvfound = kTRUE ;
212 cpvbranch = branch ;
213
214 } else if ( (strcmp(branch->GetName(), "AliPHOSClusterizer")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) ) {
215 clusterizerfound = kTRUE ;
216 clusterizerbranch = branch ;
7acf6008 217 }
218 }
7b7c1533 219 if ( !phosemcfound || !phoscpvfound || !clusterizerfound ) {
220 cerr << "WARNING: AliPHOSTrackPIDv1::ReadTrackSegments -> emc(cpv)RecPoints and/or Clusterizer branch with name " << taskName.Data()
221 << " not found" << endl ;
222 return kFALSE ;
223 }
224
225 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
226 emcRecPoints->Clear() ;
227 emcbranch->SetAddress(&emcRecPoints) ;
7acf6008 228
7b7c1533 229 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
230 cpvRecPoints->Clear() ;
231 cpvbranch->SetAddress(&cpvRecPoints) ;
7acf6008 232
7b7c1533 233
234 AliPHOSClusterizer * clusterizer = 0 ;
235 clusterizerbranch->SetAddress(&clusterizer) ;
236 clusterizerbranch->GetEntry(0) ;
237 TString clusterizerName( fTrackSegmentsTitle ) ;
238 clusterizerName.Append(clusterizer->Version()) ;
239 clusterizer = gime->Clusterizer(clusterizerName) ;
240
241 emcbranch->GetEntry(0) ;
242 cpvbranch->GetEntry(0) ;
243 clusterizerbranch->GetEntry(0) ;
244
7acf6008 245 return kTRUE ;
7b7c1533 246
7acf6008 247}
7b7c1533 248
1cb7c1ee 249//____________________________________________________________________________
7acf6008 250Float_t AliPHOSPIDv1::GetDistance(AliPHOSEmcRecPoint * emc,AliPHOSRecPoint * cpv, Option_t * Axis)const
69183710 251{
252 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
253
7b7c1533 254 const AliPHOSGeometry * geom = AliPHOSGetter::GetInstance()->PHOSGeometry() ;
69183710 255 TVector3 vecEmc ;
7acf6008 256 TVector3 vecCpv ;
257
258 emc->GetLocalPosition(vecEmc) ;
259 cpv->GetLocalPosition(vecCpv) ;
260 if(emc->GetPHOSMod() == cpv->GetPHOSMod()){
261
262 // Correct to difference in CPV and EMC position due to different distance to center.
263 // we assume, that particle moves from center
7b7c1533 264 Float_t dCPV = geom->GetIPtoOuterCoverDistance();
265 Float_t dEMC = geom->GetIPtoCrystalSurface() ;
7acf6008 266 dEMC = dEMC / dCPV ;
267 vecCpv = dEMC * vecCpv - vecEmc ;
268 if (Axis == "X") return vecCpv.X();
269 if (Axis == "Y") return vecCpv.Y();
270 if (Axis == "Z") return vecCpv.Z();
271 if (Axis == "R") return vecCpv.Mag();
272 }
273
274 return 100000000 ;
69183710 275}
276
69183710 277//____________________________________________________________________________
7acf6008 278void AliPHOSPIDv1::Exec(Option_t * option)
6ad0bfa0 279{
f035f6ce 280 //Steering method
281
bf8f1fbd 282 if( strcmp(GetName(), "")== 0 )
7acf6008 283 Init() ;
bf8f1fbd 284
285 if(strstr(option,"tim"))
7acf6008 286 gBenchmark->Start("PHOSPID");
bf8f1fbd 287
288 if(strstr(option,"print")) {
7b7c1533 289 Print("") ;
290 return ;
bf8f1fbd 291 }
292
293 gAlice->GetEvent(0) ;
7b7c1533 294 //check, if the branch with name of this" already exits?
295 TObjArray * lob = (TObjArray*)gAlice->TreeR()->GetListOfBranches() ;
296 TIter next(lob) ;
297 TBranch * branch = 0 ;
298 Bool_t phospidfound = kFALSE, pidfound = kFALSE ;
299
300 TString taskName(GetName()) ;
bf8f1fbd 301 taskName.Remove(taskName.Index(Version())-1) ;
302
7b7c1533 303 while ( (branch = (TBranch*)next()) && (!phospidfound || !pidfound) ) {
304 if ( (strcmp(branch->GetName(), "PHOSPID")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) )
305 phospidfound = kTRUE ;
306
307 else if ( (strcmp(branch->GetName(), "AliPHOSPID")==0) && (strcmp(branch->GetTitle(), taskName.Data())==0) )
308 pidfound = kTRUE ;
309 }
bf8f1fbd 310
7b7c1533 311 if ( phospidfound || pidfound ) {
312 cerr << "WARNING: AliPHOSPIDv1::Exec -> RecParticles and/or PIDtMaker branch with name "
313 << taskName.Data() << " already exits" << endl ;
314 return ;
315 }
bf8f1fbd 316
7b7c1533 317 Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
318 Int_t ievent ;
bf8f1fbd 319 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
320
7b7c1533 321 for(ievent = 0; ievent < nevents; ievent++){
01a599c9 322
bf8f1fbd 323 gime->Event(ievent,"R") ;
324
325 // if(!ReadTrackSegments(ievent)) //reads TrackSegments for event ievent
326 // continue ;
7b7c1533 327
7acf6008 328 MakeRecParticles() ;
01a599c9 329
7b7c1533 330 WriteRecParticles(ievent);
331
7acf6008 332 if(strstr(option,"deb"))
333 PrintRecParticles(option) ;
334 }
335
336 if(strstr(option,"tim")){
337 gBenchmark->Stop("PHOSPID");
338 cout << "AliPHOSPID:" << endl ;
339 cout << " took " << gBenchmark->GetCpuTime("PHOSPID") << " seconds for PID "
7b7c1533 340 << gBenchmark->GetCpuTime("PHOSPID")/nevents << " seconds per event " << endl ;
7acf6008 341 cout << endl ;
342 }
343
344}
345//____________________________________________________________________________
7b7c1533 346void AliPHOSPIDv1::Init()
347{
348 // Make all memory allocations that are not possible in default constructor
349 // Add the PID task to the list of PHOS tasks
350
351 if ( strcmp(GetTitle(), "") == 0 )
352 SetTitle("galice.root") ;
353
354 TString taskName(GetName()) ;
bf8f1fbd 355 taskName.Remove(taskName.Index(Version())-1) ;
356
7b7c1533 357 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), taskName.Data()) ;
358 if ( gime == 0 ) {
359 cerr << "ERROR: AliPHOSPIDv1::Init -> Could not obtain the Getter object !" << endl ;
360 return ;
361 }
362
363 //add Task to //YSAlice/tasks/Reconstructioner/PHOS
bf8f1fbd 364 // TTask * aliceRe = (TTask*)gROOT->FindObjectAny("YSAlice/tasks/Reconstructioner") ;
365 // TTask * phosRe = (TTask*)aliceRe->GetListOfTasks()->FindObject("PHOS") ;
366 // phosRe->Add(this) ;
367 gime->PostPID(this) ;
7b7c1533 368 // create a folder on the white board //YSAlice/WhiteBoard/RecParticles/PHOS/recparticlesName
bf8f1fbd 369 gime->PostRecParticles(taskName.Data() ) ;
7b7c1533 370
371}
372
373//____________________________________________________________________________
7acf6008 374void AliPHOSPIDv1::MakeRecParticles(){
375
b2a60966 376 // Makes a RecParticle out of a TrackSegment
bf8f1fbd 377 TString taskName(GetName()) ;
378 taskName.Remove(taskName.Index(Version())-1) ;
6ad0bfa0 379
7b7c1533 380 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
bf8f1fbd 381 TObjArray * emcRecPoints = gime->EmcRecPoints(taskName) ;
382 TObjArray * cpvRecPoints = gime->CpvRecPoints(taskName) ;
383 TClonesArray * trackSegments = gime->TrackSegments(taskName) ;
384 TClonesArray * recParticles = gime->RecParticles(taskName) ;
01a599c9 385 recParticles->Clear();
bf8f1fbd 386
7b7c1533 387 TIter next(trackSegments) ;
7acf6008 388 AliPHOSTrackSegment * ts ;
6ad0bfa0 389 Int_t index = 0 ;
09fc14a0 390 AliPHOSRecParticle * rp ;
7acf6008 391
392 Bool_t ellips = fIDOptions.Contains("ell",TString::kIgnoreCase ) ;
393 Bool_t disp = fIDOptions.Contains("dis",TString::kIgnoreCase ) ;
394
395 while ( (ts = (AliPHOSTrackSegment *)next()) ) {
fad3e5b9 396
7b7c1533 397 new( (*recParticles)[index] ) AliPHOSRecParticle() ;
398 rp = (AliPHOSRecParticle *)recParticles->At(index) ;
7acf6008 399 rp->SetTraskSegment(index) ;
f035f6ce 400
7acf6008 401 AliPHOSEmcRecPoint * emc = 0 ;
402 if(ts->GetEmcIndex()>=0)
7b7c1533 403 emc = (AliPHOSEmcRecPoint *) emcRecPoints->At(ts->GetEmcIndex()) ;
fad3e5b9 404
7acf6008 405 AliPHOSRecPoint * cpv = 0 ;
406 if(ts->GetCpvIndex()>=0)
7b7c1533 407 cpv = (AliPHOSRecPoint *) cpvRecPoints->At(ts->GetCpvIndex()) ;
fad3e5b9 408
7acf6008 409 AliPHOSRecPoint * ppsd = 0 ;
410 if(ts->GetPpsdIndex()>=0)
7b7c1533 411 ppsd= (AliPHOSRecPoint *) cpvRecPoints->At(ts->GetPpsdIndex()) ;
7acf6008 412
413 //set momentum and energy first
414 Float_t e = emc->GetEnergy() ;
415 TVector3 dir = GetMomentumDirection(emc,cpv,ppsd) ;
416 dir.SetMag(e) ;
417
418 rp->SetMomentum(dir.X(),dir.Y(),dir.Z(),e) ;
419 rp->SetCalcMass(0);
420
421 //now set type (reconstructed) of the particle
422 Int_t showerprofile = 0; // 0 narrow and 1 wide
fad3e5b9 423
7acf6008 424 if(ellips){
425 Float_t lambda[2] ;
426 emc->GetElipsAxis(lambda) ;
427 if(fFormula->Eval(lambda[0],lambda[1]) <= 0 )
428 showerprofile = 1 ; // not narrow
1cb7c1ee 429 }
fad3e5b9 430
7acf6008 431 if(disp)
432 if(emc->GetDispersion() > fDispersion )
433 showerprofile = 1 ; // not narrow
434
435
2aad621e 436 // Looking at the photon conversion detector
7acf6008 437 Int_t pcdetector= 0 ; //1 hit and 0 no hit
438 if(ppsd)
439 if(GetDistance(emc, ppsd, "R") < fCpvEmcDistance)
440 pcdetector = 1 ;
441
442 // Looking at the CPV detector
443 Int_t cpvdetector= 0 ; //1 hit and 0 no hit
444 if(cpv)
445 if(GetDistance(emc, cpv, "R") < fCpvEmcDistance)
446 cpvdetector = 1 ;
447
448 Int_t type = showerprofile + 2 * pcdetector + 4 * cpvdetector ;
bf8f1fbd 449 rp->SetType(type) ;
450 rp->SetIndexInList(index) ;
6ad0bfa0 451 index++ ;
452 }
7acf6008 453
6ad0bfa0 454}
455
09fc14a0 456//____________________________________________________________________________
7acf6008 457void AliPHOSPIDv1:: Print(Option_t * option) const
09fc14a0 458{
b2a60966 459 // Print the parameters used for the particle type identification
f035f6ce 460 cout << "=============== AliPHOSPID1 ================" << endl ;
461 cout << "Making PID "<< endl ;
462 cout << " Headers file: " << fHeaderFileName.Data() << endl ;
463 cout << " RecPoints branch title: " << fRecPointsTitle.Data() << endl ;
7b7c1533 464 cout << " TrackSegments Branch title: " << fTrackSegmentsTitle.Data() << endl ;
465 cout << " RecParticles Branch title " << fRecParticlesTitle.Data() << endl;
f035f6ce 466 cout << "with parameters: " << endl ;
467 cout << " Maximal EMC - CPV (PPSD) distance (cm) " << fCpvEmcDistance << endl ;
468 if(fIDOptions.Contains("dis",TString::kIgnoreCase ))
469 cout << " dispersion cut " << fDispersion << endl ;
470 if(fIDOptions.Contains("ell",TString::kIgnoreCase )){
471 cout << "Eliptic cuts function: " << endl ;
472 cout << fFormula->GetTitle() << endl ;
473 }
474 cout << "============================================" << endl ;
09fc14a0 475}
476
477//____________________________________________________________________________
a4e98857 478void AliPHOSPIDv1::SetShowerProfileCut(char * formula)
479{
7acf6008 480 //set shape of the cut on the axis of ellipce, drown around shouer
481 //shower considered "narrow" if Formula(lambda[0],lambda[1]) > 0.
482 if(fFormula)
483 delete fFormula;
f035f6ce 484 fFormula = new TFormula("Lambda Cut",formula) ;
7acf6008 485}
486//____________________________________________________________________________
7b7c1533 487void AliPHOSPIDv1::WriteRecParticles(Int_t event)
09fc14a0 488{
7b7c1533 489
490 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
bf8f1fbd 491 TString taskName(GetName()) ;
492 taskName.Remove(taskName.Index(Version())-1) ;
493 TClonesArray * recParticles = gime->RecParticles(taskName) ;
494 recParticles->Expand(recParticles->GetEntriesFast() ) ;
495
7b7c1533 496 //Make branch in TreeR for RecParticles
7acf6008 497 char * filename = 0;
498 if(gSystem->Getenv("CONFIG_SPLIT_FILE")!=0){ //generating file name
499 filename = new char[strlen(gAlice->GetBaseFile())+20] ;
500 sprintf(filename,"%s/PHOS.Reco.root",gAlice->GetBaseFile()) ;
501 }
bf8f1fbd 502
7acf6008 503 TDirectory *cwd = gDirectory;
504
505 //First rp
506 Int_t bufferSize = 32000 ;
7b7c1533 507 TBranch * rpBranch = gAlice->TreeR()->Branch("PHOSRP",&recParticles,bufferSize);
bf8f1fbd 508 rpBranch->SetTitle(fRecParticlesTitle);
7acf6008 509 if (filename) {
510 rpBranch->SetFile(filename);
511 TIter next( rpBranch->GetListOfBranches());
761e34c0 512 TBranch * sb ;
513 while ((sb=(TBranch*)next())) {
514 sb->SetFile(filename);
7acf6008 515 }
516 cwd->cd();
517 }
518
519 //second, pid
520 Int_t splitlevel = 0 ;
521 AliPHOSPIDv1 * pid = this ;
7b7c1533 522 TBranch * pidBranch = gAlice->TreeR()->Branch("AliPHOSPID","AliPHOSPIDv1",&pid,bufferSize,splitlevel);
bf8f1fbd 523 pidBranch->SetTitle(fRecParticlesTitle);
7acf6008 524 if (filename) {
525 pidBranch->SetFile(filename);
526 TIter next( pidBranch->GetListOfBranches());
761e34c0 527 TBranch * sb ;
528 while ((sb=(TBranch*)next())) {
529 sb->SetFile(filename);
7acf6008 530 }
531 cwd->cd();
532 }
533
761e34c0 534 rpBranch->Fill() ;
535 pidBranch->Fill() ;
eec3ac52 536
7acf6008 537 gAlice->TreeR()->Write(0,kOverwrite) ;
538
539}
7b7c1533 540
69183710 541//____________________________________________________________________________
7acf6008 542void AliPHOSPIDv1::PlotDispersionCuts()const
69183710 543{
a4e98857 544 // produces a plot of the dispersion cut
545 TCanvas* lambdas = new TCanvas("lambdas","Cuts on the ellipse axis",200,10,700,500);
dd5c4038 546
7acf6008 547 if(fIDOptions.Contains("ell",TString::kIgnoreCase ) ){
548 TF2 * ell = new TF2("Elliptic Cuts",fFormula->GetName(),0,3,0,3) ;
549 ell->SetMinimum(0.0000001) ;
550 ell->SetMaximum(0.001) ;
551 ell->SetLineStyle(1) ;
552 ell->SetLineWidth(2) ;
553 ell->Draw() ;
554 }
555
556 if( fIDOptions.Contains("dis",TString::kIgnoreCase ) ){
557 TF2 * dsp = new TF2("dispersion","(y<x)*(x*x+y*y < [0]*[0])",0,3,0,3) ;
558 dsp->SetParameter(0,fDispersion) ;
559 dsp->SetMinimum(0.0000001) ;
560 dsp->SetMaximum(0.001) ;
561 dsp->SetLineStyle(1) ;
562 dsp->SetLineColor(2) ;
563 dsp->SetLineWidth(2) ;
564 dsp->SetNpx(200) ;
565 dsp->SetNpy(200) ;
566 if(fIDOptions.Contains("ell",TString::kIgnoreCase ) )
567 dsp->Draw("same") ;
568 else
569 dsp->Draw() ;
570 }
571 lambdas->Update();
572}
69183710 573
7acf6008 574//____________________________________________________________________________
575TVector3 AliPHOSPIDv1::GetMomentumDirection(AliPHOSEmcRecPoint * emc, AliPHOSRecPoint * cpv,AliPHOSRecPoint * ppsd)const
576{
577 // Calculates the momentum direction:
578 // 1. if only a EMC RecPoint, direction is given by IP and this RecPoint
579 // 2. if a EMC RecPoint and one PPSD RecPoint, direction is given by the line through the 2 recpoints
580 // 3. if a EMC RecPoint and two PPSD RecPoints, dirrection is given by the average line through
581 // the 2 pairs of recpoints
582 // However because of the poor position resolution of PPSD the direction is always taken as if we were
583 // in case 1.
584
585 TVector3 dir(0,0,0) ;
586
587 TVector3 emcglobalpos ;
588 TMatrix dummy ;
589
590 emc->GetGlobalPosition(emcglobalpos, dummy) ;
591
69183710 592
a4e98857 593 // The following commented code becomes valid once the PPSD provides
7acf6008 594 // a reasonable position resolution, at least as good as EMC !
595 // TVector3 ppsdlglobalpos ;
596 // TVector3 ppsduglobalpos ;
597 // if( fPpsdLowRecPoint ){ // certainly a photon that has concerted
598 // fPpsdLowRecPoint->GetGlobalPosition(ppsdlglobalpos, mdummy) ;
599 // dir = emcglobalpos - ppsdlglobalpos ;
600 // if( fPpsdUpRecPoint ){ // not looks like a charged
601 // fPpsdUpRecPoint->GetGlobalPosition(ppsduglobalpos, mdummy) ;
602 // dir = ( dir + emcglobalpos - ppsduglobalpos ) * 0.5 ;
603 // }
604 // }
605 // else { // looks like a neutral
606 // dir = emcglobalpos ;
607 // }
608
609 dir = emcglobalpos ;
610 dir.SetZ( -dir.Z() ) ; // why ?
611 dir.SetMag(1.) ;
612
613 //account correction to the position of IP
614 Float_t xo,yo,zo ; //Coordinates of the origin
615 gAlice->Generator()->GetOrigin(xo,yo,zo) ;
616 TVector3 origin(xo,yo,zo);
617 dir = dir - origin ;
618
619 return dir ;
620}
621//____________________________________________________________________________
a4e98857 622void AliPHOSPIDv1::PrintRecParticles(Option_t * option)
623{
dd5c4038 624 // Print table of reconstructed particles
625
7b7c1533 626 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
bf8f1fbd 627
628 TString taskName(GetName()) ;
629 taskName.Remove(taskName.Index(Version())-1) ;
630 TClonesArray * recParticles = gime->RecParticles(taskName) ;
7b7c1533 631
632
01a599c9 633 cout << "AliPHOSPIDv1: event "<<gAlice->GetEvNumber() << endl ;
7b7c1533 634 cout << " found " << recParticles->GetEntriesFast() << " RecParticles " << endl ;
7acf6008 635
2b60655b 636 fRecParticlesInRun += recParticles->GetEntriesFast() ;
637
7acf6008 638 if(strstr(option,"all")) { // printing found TS
639
640 cout << " PARTICLE "
641 << " Index " << endl ;
642 // << " X "
643 // << " Y "
644 // << " Z "
645 // << " # of primaries "
646 // << " Primaries list " << endl;
647
648 Int_t index ;
7b7c1533 649 for (index = 0 ; index < recParticles->GetEntries() ; index++) {
650 AliPHOSRecParticle * rp = (AliPHOSRecParticle * ) recParticles->At(index) ;
7acf6008 651
652 Text_t particle[11];
653 switch(rp->GetType()) {
654 case AliPHOSFastRecParticle::kNEUTRALEM:
655 strcpy( particle, "NEUTRAL_EM");
656 break;
657 case AliPHOSFastRecParticle::kNEUTRALHA:
658 strcpy(particle, "NEUTRAL_HA");
659 break;
660 case AliPHOSFastRecParticle::kGAMMA:
661 strcpy(particle, "GAMMA");
662 break ;
663 case AliPHOSFastRecParticle::kGAMMAHA:
664 strcpy(particle, "GAMMA_H");
665 break ;
666 case AliPHOSFastRecParticle::kABSURDEM:
667 strcpy(particle, "ABSURD_EM") ;
668 break ;
669 case AliPHOSFastRecParticle::kABSURDHA:
670 strcpy(particle, "ABSURD_HA") ;
671 break ;
672 case AliPHOSFastRecParticle::kELECTRON:
673 strcpy(particle, "ELECTRON") ;
674 break ;
675 case AliPHOSFastRecParticle::kCHARGEDHA:
676 strcpy(particle, "CHARGED_HA") ;
677 break ;
678 }
679
680 // Int_t * primaries;
681 // Int_t nprimaries;
682 // primaries = rp->GetPrimaries(nprimaries);
683
684 cout << setw(15) << particle << " "
685 << setw(3) << rp->GetIndexInList() << " " ;
686 // << setw(4) << nprimaries << " ";
687 // for (Int_t iprimary=0; iprimary<nprimaries; iprimary++)
688 // cout << setw(4) << primaries[iprimary] << " ";
689 cout << endl;
690 }
691 cout << "-------------------------------------------" << endl ;
692 }
693
69183710 694}
695
7acf6008 696
697