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