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 **************************************************************************/
16 //_________________________________________________________________________
17 // Implementation version 1 of algorithm class to construct PHOS track segments
18 // Track segment for PHOS is list of
19 // EMC RecPoint + (possibly) CPV RecPoint + (possibly) PPSD RecPoint
20 // To find TrackSegments we do the following:
21 // for each EMC RecPoints we look at
22 // CPV/PPSD RecPoints in the radious fR0.
23 // If there is such a CPV RecPoint,
24 // we make "Link" it is just indexes of EMC and CPV/PPSD RecPoint and distance
25 // between them in the PHOS plane.
26 // Then we sort "Links" and starting from the
27 // least "Link" pointing to the unassined EMC and CPV RecPoints assing them to
29 // If there is no CPV/PPSD RecPoint we make TrackSegment
30 // consisting from EMC alone. There is no TrackSegments without EMC RecPoint.
32 // In principle this class should be called from AliPHOSReconstructioner, but
33 // one can use it as well in standalone mode.
35 // root [0] AliPHOSTrackSegmentMakerv1 * t = new AliPHOSTrackSegmentMaker("galice.root", "tracksegmentsname", "recpointsname")
36 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
37 // // reads gAlice from header file "galice.root", uses recpoints stored in the branch names "recpointsname" (default = "Default")
38 // // and saves recpoints in branch named "tracksegmentsname" (default = "recpointsname")
39 // root [1] t->ExecuteTask()
40 // root [2] t->SetMaxEmcPpsdDistance(5)
41 // root [3] t->SetTrackSegmentsBranch("max distance 5 cm")
42 // root [4] t->ExecuteTask("deb all time")
44 //*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH) & Yves Schutz (SUBATECH)
47 // --- ROOT system ---
53 #include "TBenchmark.h"
54 // --- Standard library ---
59 // --- AliRoot header files ---
61 #include "AliPHOSTrackSegmentMakerv1.h"
62 #include "AliPHOSClusterizerv1.h"
63 #include "AliPHOSTrackSegment.h"
64 #include "AliPHOSCpvRecPoint.h"
65 #include "AliPHOSLink.h"
66 #include "AliPHOSGetter.h"
70 ClassImp( AliPHOSTrackSegmentMakerv1)
73 //____________________________________________________________________________
74 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() : AliPHOSTrackSegmentMaker()
76 // default ctor (to be used mainly by Streamer)
79 fHeaderFileName = "" ;
80 fRecPointsBranchTitle = "" ;
81 fTrackSegmentsBranchTitle = "" ;
84 fTrackSegmentsInRun = 0 ;
87 //____________________________________________________________________________
88 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const char * headerFile, const char * name, const char * from) : AliPHOSTrackSegmentMaker(headerFile, name)
93 fHeaderFileName = GetTitle() ;
94 fRecPointsBranchTitle = GetName() ;
95 fTrackSegmentsBranchTitle = GetName() ;
96 fTrackSegmentsInRun = 0 ;
106 //____________________________________________________________________________
107 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
110 delete fLinkUpArray ;
112 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
114 // remove the task from the folder list
115 gime->RemoveTask("T",GetName()) ;
116 TString name(GetName()) ;
117 name.ReplaceAll("tsm", "clu") ;
118 gime->RemoveTask("C",name) ;
120 // remove the data from the folder list
122 name.Remove(name.Index(":")) ;
123 gime->RemoveObjects("RE", name) ; // EMCARecPoints
124 gime->RemoveObjects("RC", name) ; // CPVRecPoints
125 gime->RemoveObjects("T", name) ; // TrackSegments
133 //____________________________________________________________________________
134 const TString AliPHOSTrackSegmentMakerv1::BranchName() const
136 TString branchName(GetName() ) ;
137 branchName.Remove(branchName.Index(Version())-1) ;
141 //____________________________________________________________________________
142 void AliPHOSTrackSegmentMakerv1::FillOneModule()
144 // Finds first and last indexes between which
145 // clusters from one PHOS module are
147 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
148 TObjArray * emcRecPoints = gime->EmcRecPoints(fFrom) ;
149 TObjArray * cpvRecPoints = gime->CpvRecPoints(fFrom) ;
152 Int_t totalEmc = emcRecPoints->GetEntriesFast() ;
153 for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&
154 ((dynamic_cast<AliPHOSRecPoint *>(emcRecPoints->At(fEmcLast)))->GetPHOSMod() == fModule );
158 Int_t totalCpv = cpvRecPoints->GetEntriesFast() ;
160 for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&
161 ((dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(fCpvLast)))->GetPHOSMod() == fModule );
166 //____________________________________________________________________________
167 Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,AliPHOSRecPoint * cpvClu, Bool_t &toofar)const
169 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
170 // Clusters are sorted in "rows" and "columns" of width 1 cm
172 Float_t delta = 1 ; // Width of the rows in sorting of RecPoints (in cm)
173 // if you change this value, change it as well in xxxRecPoint::Compare()
179 emcClu->GetLocalPosition(vecEmc) ;
180 cpvClu->GetLocalPosition(vecCpv) ;
182 if(emcClu->GetPHOSMod() == cpvClu->GetPHOSMod()){
183 if(vecCpv.X() <= vecEmc.X() + fR0 + 2*delta ){
185 vecCpv = vecCpv - vecEmc ;
189 } // if xPpsd >= xEmc + ...
202 //____________________________________________________________________________
203 void AliPHOSTrackSegmentMakerv1::Init()
205 // Make all memory allocations that are not possible in default constructor
207 if ( strcmp(GetTitle(), "") == 0 )
208 SetTitle("galice.root") ;
210 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), fFrom.Data()) ;
212 cerr << "ERROR: AliPHOSTrackSegmentMakerv1::Init -> Could not obtain the Getter object !" << endl ;
216 fLinkUpArray = new TClonesArray("AliPHOSLink", 1000);
218 //add Task to //YSAlice/tasks/Reconstructioner/PHOS
219 gime->PostTrackSegmentMaker(this) ;
221 // create a folder on the white board //YSAlice/WhiteBoard/RecPoints/PHOS/trackSegmentsName
222 gime->PostTrackSegments(BranchName()) ;
226 //____________________________________________________________________________
227 void AliPHOSTrackSegmentMakerv1::InitParameters()
235 TString tsmName( GetName()) ;
236 if (tsmName.IsNull() )
237 tsmName = "Default" ;
238 tsmName.Append(":") ;
239 tsmName.Append(Version()) ;
244 //____________________________________________________________________________
245 void AliPHOSTrackSegmentMakerv1::MakeLinks()const
247 // Finds distances (links) between all EMC and PPSD clusters,
248 // which are not further apart from each other than fR0
249 // and sort them in accordance with this distance
251 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
252 TObjArray * emcRecPoints = gime->EmcRecPoints(fFrom) ;
253 TObjArray * cpvRecPoints = gime->CpvRecPoints(fFrom) ;
255 fLinkUpArray->Clear() ;
257 AliPHOSRecPoint * cpv ;
258 AliPHOSEmcRecPoint * emcclu ;
263 for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
264 emcclu = dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP)) ;
268 for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) {
270 cpv = dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(iCpv)) ;
271 Float_t r = GetDistanceInPHOSPlane(emcclu, cpv, toofar) ;
276 new ((*fLinkUpArray)[iLinkUp++]) AliPHOSLink(r, iEmcRP, iCpv) ;
281 fLinkUpArray->Sort() ; //first links with smallest distances
284 //____________________________________________________________________________
285 void AliPHOSTrackSegmentMakerv1::MakePairs()
287 // Using the previously made list of "links", we found the smallest link - i.e.
288 // link with the least distance between EMC and CPV and pointing to still
289 // unassigned RecParticles. We assign these RecPoints to TrackSegment and
290 // remove them from the list of "unassigned".
292 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
293 TObjArray * emcRecPoints = gime->EmcRecPoints(fFrom) ;
294 TObjArray * cpvRecPoints = gime->CpvRecPoints(fFrom) ;
295 TClonesArray * trackSegments = gime->TrackSegments(BranchName()) ;
297 //Make arrays to mark clusters already chosen
298 Int_t * emcExist = 0;
299 if(fEmcLast > fEmcFirst)
300 emcExist = new Int_t[fEmcLast-fEmcFirst] ;
303 for(index = 0; index <fEmcLast-fEmcFirst; index ++)
304 emcExist[index] = 1 ;
306 Bool_t * cpvExist = 0;
307 if(fCpvLast > fCpvFirst)
308 cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
309 for(index = 0; index <fCpvLast-fCpvFirst; index ++)
310 cpvExist[index] = kTRUE ;
313 // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance
314 TIter nextUp(fLinkUpArray) ;
316 AliPHOSLink * linkUp ;
318 AliPHOSRecPoint * nullpointer = 0 ;
320 while ( (linkUp = static_cast<AliPHOSLink *>(nextUp()) ) ){
322 if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){ //without ppsd Up yet
324 if(cpvExist[linkUp->GetPpsd()-fCpvFirst]){ //CPV still exist
326 new ((* trackSegments)[fNTrackSegments])
327 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(linkUp->GetEmc())) ,
328 dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(linkUp->GetPpsd()))) ;
329 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
332 emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc that Cpv was found
333 //mark CPV recpoint as already used
334 cpvExist[linkUp->GetPpsd()-fCpvFirst] = kFALSE ;
335 } //if ppsdUp still exist
339 //look through emc recPoints left without CPV/PPSD
340 if(emcExist){ //if there is emc rec point
342 for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst ; iEmcRP++ ){
343 if(emcExist[iEmcRP] > 0 ){
344 new ((*trackSegments)[fNTrackSegments])
345 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP+fEmcFirst)),
347 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
356 //____________________________________________________________________________
357 void AliPHOSTrackSegmentMakerv1::Exec(Option_t * option)
361 if( strcmp(GetName(), "")== 0 )
364 if(strstr(option,"tim"))
365 gBenchmark->Start("PHOSTSMaker");
367 if(strstr(option,"print")) {
372 gAlice->GetEvent(0) ;
373 //check, if the branch with name of this" already exits?
374 if (gAlice->TreeR()) {
375 TObjArray * lob = static_cast<TObjArray*>(gAlice->TreeR()->GetListOfBranches()) ;
377 TBranch * branch = 0 ;
378 Bool_t phostsfound = kFALSE, tracksegmentmakerfound = kFALSE ;
380 TString branchname = GetName() ;
381 branchname.Remove(branchname.Index(Version())-1) ;
383 while ( (branch = static_cast<TBranch*>(next())) && (!phostsfound || !tracksegmentmakerfound) ) {
384 if ( (strcmp(branch->GetName(), "PHOSTS")==0) && (strcmp(branch->GetTitle(), branchname.Data())==0) )
385 phostsfound = kTRUE ;
387 else if ( (strcmp(branch->GetName(), "AliPHOSTrackSegmentMaker")==0) && (strcmp(branch->GetTitle(), GetName())==0) )
388 tracksegmentmakerfound = kTRUE ;
391 if ( phostsfound || tracksegmentmakerfound ) {
392 cerr << "WARNING: AliPHOSTrackSegmentMakerv1::Exec -> TrackSegments and/or TrackSegmentMaker branch with name "
393 << branchname.Data() << " already exits" << endl ;
398 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
399 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
400 Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
403 for(ievent = 0; ievent < nevents; ievent++){
405 gime->Event(ievent,"R") ;
406 //Make some initializations
407 fNTrackSegments = 0 ;
412 gime->TrackSegments(BranchName())->Clear() ;
414 // if(!ReadRecPoints(ievent)) continue; //reads RecPoints for event ievent
416 for(fModule = 1; fModule <= geom->GetNModules() ; fModule++ ){
426 WriteTrackSegments(ievent) ;
428 if(strstr(option,"deb"))
429 PrintTrackSegments(option) ;
431 //increment the total number of track segments per run
432 fTrackSegmentsInRun += gime->TrackSegments(BranchName())->GetEntriesFast() ;
436 if(strstr(option,"tim")){
437 gBenchmark->Stop("PHOSTSMaker");
438 cout << "AliPHOSTSMaker:" << endl ;
439 cout << " took " << gBenchmark->GetCpuTime("PHOSTSMaker") << " seconds for making TS "
440 << gBenchmark->GetCpuTime("PHOSTSMaker")/nevents << " seconds per event " << endl ;
446 //____________________________________________________________________________
447 void AliPHOSTrackSegmentMakerv1::Print(Option_t * option)const
449 // Print TrackSegmentMaker parameters
451 if( strcmp(GetName(), "") != 0 ) {
452 cout << "======== AliPHOSTrackSegmentMakerv1 ========" << endl ;
453 cout << "Making Track segments "<< endl ;
454 cout << " Headers file: " << fHeaderFileName.Data() << endl ;
455 cout << " RecPoints branch file name: " << fRecPointsBranchTitle.Data() << endl ;
456 cout << " TrackSegments Branch file name: " << fTrackSegmentsBranchTitle.Data() << endl ;
457 cout << "with parameters: " << endl ;
458 cout << " Maximal EMC - CPV (PPSD) distance (cm)" << fR0 << endl ;
459 cout << "============================================" << endl ;
462 cout << "AliPHOSTrackSegmentMakerv1 not initialized " << endl ;
465 //____________________________________________________________________________
466 void AliPHOSTrackSegmentMakerv1::WriteTrackSegments(Int_t event)
468 // Writes found TrackSegments to TreeR. Creates branches
469 // "PHOSTS" and "AliPHOSTrackSegmentMaker" with the same title.
470 // In the former branch found TrackSegments are stored, while
471 // in the latter all parameters, with which TS were made.
472 // ROOT does not allow overwriting existing branches, therefore
473 // first we check, if branches with the same title already exist.
474 // If yes - exits without writing.
476 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
478 TClonesArray * trackSegments = gime->TrackSegments(BranchName()) ;
479 trackSegments->Expand(trackSegments->GetEntriesFast()) ;
480 TTree * treeR = gAlice->TreeR();
483 gAlice->MakeTree("R", fSplitFile);
484 treeR = gAlice->TreeR();
487 Int_t bufferSize = 32000 ;
488 TBranch * tsBranch = treeR->Branch("PHOSTS",&trackSegments,bufferSize);
489 tsBranch->SetTitle(BranchName());
492 Int_t splitlevel = 0 ;
493 AliPHOSTrackSegmentMakerv1 * ts = this ;
494 TBranch * tsMakerBranch = treeR->Branch("AliPHOSTrackSegmentMaker","AliPHOSTrackSegmentMakerv1",
495 &ts,bufferSize,splitlevel);
496 tsMakerBranch->SetTitle(BranchName());
499 tsMakerBranch->Fill() ;
501 treeR->AutoSave() ; //Write(0,kOverwrite) ;
506 //____________________________________________________________________________
507 void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
509 // option deb - prints # of found TrackSegments
510 // option deb all - prints as well indexed of found RecParticles assigned to the TS
511 TString taskName(GetName()) ;
512 taskName.Remove(taskName.Index(Version())-1) ;
514 TClonesArray * trackSegments = AliPHOSGetter::GetInstance()->TrackSegments(taskName) ;
517 cout << "AliPHOSTrackSegmentMakerv1: event "<<gAlice->GetEvNumber() << endl ;
518 cout << " Found " << trackSegments->GetEntriesFast() << " trackSegments " << endl ;
520 if(strstr(option,"all")) { // printing found TS
521 cout << "TrackSegment # " << " EMC RP# " << " CPV RP# " << endl ;
524 for (index = 0 ; index <trackSegments->GetEntriesFast() ; index++) {
525 AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )trackSegments->At(index) ;
526 cout<<" "<< setw(4) << ts->GetIndexInList() << " "
527 <<setw(4) << ts->GetEmcIndex()<< " "
528 <<setw(4) << ts->GetCpvIndex()<< " " << endl ;
531 cout << "-------------------------------------------------------"<< endl ;