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)
84 fHeaderFileName = "" ;
85 fRecPointsBranchTitle = "" ;
86 fTrackSegmentsBranchTitle = "" ;
89 fTrackSegmentsInRun = 0 ;
92 //____________________________________________________________________________
93 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const char * headerFile, const char * name, const char * from) : AliPHOSTrackSegmentMaker(headerFile, name)
104 fHeaderFileName = GetTitle() ;
105 fRecPointsBranchTitle = GetName() ;
106 fTrackSegmentsBranchTitle = GetName() ;
107 fTrackSegmentsInRun = 0 ;
109 TString tsmName( GetName()) ;
110 tsmName.Append(":") ;
111 tsmName.Append(Version()) ;
121 //____________________________________________________________________________
122 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
125 delete fLinkUpArray ;
128 //____________________________________________________________________________
129 const TString AliPHOSTrackSegmentMakerv1::BranchName() const
131 TString branchName(GetName() ) ;
132 branchName.Remove(branchName.Index(Version())-1) ;
136 //____________________________________________________________________________
137 void AliPHOSTrackSegmentMakerv1::FillOneModule()
139 // Finds first and last indexes between which
140 // clusters from one PHOS module are
142 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
143 TObjArray * emcRecPoints = gime->EmcRecPoints(fFrom) ;
144 TObjArray * cpvRecPoints = gime->CpvRecPoints(fFrom) ;
147 Int_t totalEmc = emcRecPoints->GetEntriesFast() ;
148 for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&
149 ((dynamic_cast<AliPHOSRecPoint *>(emcRecPoints->At(fEmcLast)))->GetPHOSMod() == fModule );
153 Int_t totalCpv = cpvRecPoints->GetEntriesFast() ;
155 for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&
156 ((dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(fCpvLast)))->GetPHOSMod() == fModule );
161 //____________________________________________________________________________
162 Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,AliPHOSRecPoint * cpvClu, Bool_t &toofar)const
164 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
165 // Clusters are sorted in "rows" and "columns" of width 1 cm
167 Float_t delta = 1 ; // Width of the rows in sorting of RecPoints (in cm)
168 // if you change this value, change it as well in xxxRecPoint::Compare()
174 emcClu->GetLocalPosition(vecEmc) ;
175 cpvClu->GetLocalPosition(vecCpv) ;
177 if(emcClu->GetPHOSMod() == cpvClu->GetPHOSMod()){
178 if(vecCpv.X() <= vecEmc.X() + fR0 + 2*delta ){
180 vecCpv = vecCpv - vecEmc ;
184 } // if xPpsd >= xEmc + ...
197 //____________________________________________________________________________
198 void AliPHOSTrackSegmentMakerv1::Init()
200 // Make all memory allocations that are not possible in default constructor
202 if ( strcmp(GetTitle(), "") == 0 )
203 SetTitle("galice.root") ;
205 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(), fFrom.Data()) ;
207 cerr << "ERROR: AliPHOSTrackSegmentMakerv1::Init -> Could not obtain the Getter object !" << endl ;
211 fLinkUpArray = new TClonesArray("AliPHOSLink", 1000);
213 //add Task to //YSAlice/tasks/Reconstructioner/PHOS
214 gime->PostTrackSegmentMaker(this) ;
216 // create a folder on the white board //YSAlice/WhiteBoard/RecPoints/PHOS/trackSegmentsName
217 gime->PostTrackSegments(BranchName()) ;
221 //____________________________________________________________________________
222 void AliPHOSTrackSegmentMakerv1::MakeLinks()const
224 // Finds distances (links) between all EMC and PPSD clusters,
225 // which are not further apart from each other than fR0
226 // and sort them in accordance with this distance
228 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
229 TObjArray * emcRecPoints = gime->EmcRecPoints(fFrom) ;
230 TObjArray * cpvRecPoints = gime->CpvRecPoints(fFrom) ;
232 fLinkUpArray->Clear() ;
234 AliPHOSRecPoint * cpv ;
235 AliPHOSEmcRecPoint * emcclu ;
240 for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
241 emcclu = dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP)) ;
245 for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) {
247 cpv = dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(iCpv)) ;
248 Float_t r = GetDistanceInPHOSPlane(emcclu, cpv, toofar) ;
253 new ((*fLinkUpArray)[iLinkUp++]) AliPHOSLink(r, iEmcRP, iCpv) ;
258 fLinkUpArray->Sort() ; //first links with smallest distances
261 //____________________________________________________________________________
262 void AliPHOSTrackSegmentMakerv1::MakePairs()
264 // Using the previously made list of "links", we found the smallest link - i.e.
265 // link with the least distance between EMC and CPV and pointing to still
266 // unassigned RecParticles. We assign these RecPoints to TrackSegment and
267 // remove them from the list of "unassigned".
269 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
270 TObjArray * emcRecPoints = gime->EmcRecPoints(fFrom) ;
271 TObjArray * cpvRecPoints = gime->CpvRecPoints(fFrom) ;
272 TClonesArray * trackSegments = gime->TrackSegments(BranchName()) ;
274 //Make arrays to mark clusters already chosen
275 Int_t * emcExist = 0;
276 if(fEmcLast > fEmcFirst)
277 emcExist = new Int_t[fEmcLast-fEmcFirst] ;
280 for(index = 0; index <fEmcLast-fEmcFirst; index ++)
281 emcExist[index] = 1 ;
283 Bool_t * cpvExist = 0;
284 if(fCpvLast > fCpvFirst)
285 cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
286 for(index = 0; index <fCpvLast-fCpvFirst; index ++)
287 cpvExist[index] = kTRUE ;
290 // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance
291 TIter nextUp(fLinkUpArray) ;
293 AliPHOSLink * linkUp ;
295 AliPHOSRecPoint * nullpointer = 0 ;
297 while ( (linkUp = static_cast<AliPHOSLink *>(nextUp()) ) ){
299 if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){ //without ppsd Up yet
301 if(cpvExist[linkUp->GetPpsd()-fCpvFirst]){ //CPV still exist
303 new ((* trackSegments)[fNTrackSegments])
304 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(linkUp->GetEmc())) ,
305 dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(linkUp->GetPpsd()))) ;
306 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
309 emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc that Cpv was found
310 //mark CPV recpoint as already used
311 cpvExist[linkUp->GetPpsd()-fCpvFirst] = kFALSE ;
312 } //if ppsdUp still exist
316 //look through emc recPoints left without CPV/PPSD
317 if(emcExist){ //if there is emc rec point
319 for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst ; iEmcRP++ ){
320 if(emcExist[iEmcRP] > 0 ){
321 new ((*trackSegments)[fNTrackSegments])
322 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP+fEmcFirst)),
324 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
333 //____________________________________________________________________________
334 void AliPHOSTrackSegmentMakerv1::Exec(Option_t * option)
338 if( strcmp(GetName(), "")== 0 )
341 if(strstr(option,"tim"))
342 gBenchmark->Start("PHOSTSMaker");
344 if(strstr(option,"print")) {
349 gAlice->GetEvent(0) ;
350 //check, if the branch with name of this" already exits?
351 TObjArray * lob = static_cast<TObjArray*>(gAlice->TreeR()->GetListOfBranches()) ;
353 TBranch * branch = 0 ;
354 Bool_t phostsfound = kFALSE, tracksegmentmakerfound = kFALSE ;
356 TString branchname = GetName() ;
357 branchname.Remove(branchname.Index(Version())-1) ;
359 while ( (branch = static_cast<TBranch*>(next())) && (!phostsfound || !tracksegmentmakerfound) ) {
360 if ( (strcmp(branch->GetName(), "PHOSTS")==0) && (strcmp(branch->GetTitle(), branchname.Data())==0) )
361 phostsfound = kTRUE ;
363 else if ( (strcmp(branch->GetName(), "AliPHOSTrackSegmentMaker")==0) && (strcmp(branch->GetTitle(), GetName())==0) )
364 tracksegmentmakerfound = kTRUE ;
367 if ( phostsfound || tracksegmentmakerfound ) {
368 cerr << "WARNING: AliPHOSTrackSegmentMakerv1::Exec -> TrackSegments and/or TrackSegmentMaker branch with name "
369 << branchname.Data() << " already exits" << endl ;
373 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
374 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
375 Int_t nevents = (Int_t) gAlice->TreeE()->GetEntries() ;
378 for(ievent = 0; ievent < nevents; ievent++){
380 gime->Event(ievent,"R") ;
381 //Make some initializations
382 fNTrackSegments = 0 ;
387 gime->TrackSegments(BranchName())->Clear() ;
389 // if(!ReadRecPoints(ievent)) continue; //reads RecPoints for event ievent
391 for(fModule = 1; fModule <= geom->GetNModules() ; fModule++ ){
401 WriteTrackSegments(ievent) ;
403 if(strstr(option,"deb"))
404 PrintTrackSegments(option) ;
406 //increment the total number of track segments per run
407 fTrackSegmentsInRun += gime->TrackSegments(BranchName())->GetEntriesFast() ;
411 if(strstr(option,"tim")){
412 gBenchmark->Stop("PHOSTSMaker");
413 cout << "AliPHOSTSMaker:" << endl ;
414 cout << " took " << gBenchmark->GetCpuTime("PHOSTSMaker") << " seconds for making TS "
415 << gBenchmark->GetCpuTime("PHOSTSMaker")/nevents << " seconds per event " << endl ;
421 //____________________________________________________________________________
422 void AliPHOSTrackSegmentMakerv1::Print(Option_t * option)const
424 // Print TrackSegmentMaker parameters
426 if( strcmp(GetName(), "") != 0 ) {
427 cout << "======== AliPHOSTrackSegmentMakerv1 ========" << endl ;
428 cout << "Making Track segments "<< endl ;
429 cout << " Headers file: " << fHeaderFileName.Data() << endl ;
430 cout << " RecPoints branch file name: " << fRecPointsBranchTitle.Data() << endl ;
431 cout << " TrackSegments Branch file name: " << fTrackSegmentsBranchTitle.Data() << endl ;
432 cout << "with parameters: " << endl ;
433 cout << " Maximal EMC - CPV (PPSD) distance (cm)" << fR0 << endl ;
434 cout << "============================================" << endl ;
437 cout << "AliPHOSTrackSegmentMakerv1 not initialized " << endl ;
440 //____________________________________________________________________________
441 void AliPHOSTrackSegmentMakerv1::WriteTrackSegments(Int_t event)
443 // Writes found TrackSegments to TreeR. Creates branches
444 // "PHOSTS" and "AliPHOSTrackSegmentMaker" with the same title.
445 // In the former branch found TrackSegments are stored, while
446 // in the latter all parameters, with which TS were made.
447 // ROOT does not allow overwriting existing branches, therefore
448 // first we check, if branches with the same title already exist.
449 // If yes - exits without writing.
451 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
453 TClonesArray * trackSegments = gime->TrackSegments(BranchName()) ;
454 trackSegments->Expand(trackSegments->GetEntriesFast()) ;
456 //Make branch in TreeR for TrackSegments
458 if(gSystem->Getenv("CONFIG_SPLIT_FILE")!=0){ //generating file name
459 filename = new char[strlen(gAlice->GetBaseFile())+20] ;
460 sprintf(filename,"%s/PHOS.Reco.root",gAlice->GetBaseFile()) ;
463 TDirectory *cwd = gDirectory;
466 Int_t bufferSize = 32000 ;
467 TBranch * tsBranch = gAlice->TreeR()->Branch("PHOSTS",&trackSegments,bufferSize);
468 tsBranch->SetTitle(BranchName());
470 tsBranch->SetFile(filename);
471 TIter next( tsBranch->GetListOfBranches());
473 while ((sb=static_cast<TBranch*>(next()))) {
474 sb->SetFile(filename);
480 Int_t splitlevel = 0 ;
481 AliPHOSTrackSegmentMakerv1 * ts = this ;
482 TBranch * tsMakerBranch = gAlice->TreeR()->Branch("AliPHOSTrackSegmentMaker","AliPHOSTrackSegmentMakerv1",
483 &ts,bufferSize,splitlevel);
484 tsMakerBranch->SetTitle(BranchName());
486 tsMakerBranch->SetFile(filename);
487 TIter next( tsMakerBranch->GetListOfBranches());
489 while ((sb=static_cast<TBranch*>(next()))) {
490 sb->SetFile(filename);
496 tsMakerBranch->Fill() ;
498 gAlice->TreeR()->Write(0,kOverwrite) ;
504 //____________________________________________________________________________
505 void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
507 // option deb - prints # of found TrackSegments
508 // option deb all - prints as well indexed of found RecParticles assigned to the TS
509 TString taskName(GetName()) ;
510 taskName.Remove(taskName.Index(Version())-1) ;
512 TClonesArray * trackSegments = AliPHOSGetter::GetInstance()->TrackSegments(taskName) ;
515 cout << "AliPHOSTrackSegmentMakerv1: event "<<gAlice->GetEvNumber() << endl ;
516 cout << " Found " << trackSegments->GetEntriesFast() << " trackSegments " << endl ;
518 if(strstr(option,"all")) { // printing found TS
519 cout << "TrackSegment # " << " EMC RP# " << " CPV RP# " << endl ;
522 for (index = 0 ; index <trackSegments->GetEntriesFast() ; index++) {
523 AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )trackSegments->At(index) ;
524 cout<<" "<< setw(4) << ts->GetIndexInList() << " "
525 <<setw(4) << ts->GetEmcIndex()<< " "
526 <<setw(4) << ts->GetCpvIndex()<< " " << endl ;
529 cout << "-------------------------------------------------------"<< endl ;