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: for each EMC RecPoints we look at
21 // CPV/PPSD RecPoints in the radious fR0. If there is such a CPV RecPoint,
22 // we make "Link" it is just indexes of EMC and CPV/PPSD RecPoint and distance
23 // between them in the PHOS plane. Then we sort "Links" and starting from the
24 // least "Link" pointing to the unassined EMC and CPV RecPoints assing them to
25 // new TrackSegment. If there is no CPV/PPSD RecPoint we make TrackSegment
26 // consisting from EMC along. There is no TrackSegments without EMC RecPoint.
28 // In principle this class should be called from AliPHOSReconstructioner, but
29 // one can use it as well in standalong mode.
31 // root [0] AliPHOSTrackSegmentMakerv1 * t = new AliPHOSTrackSegmentMaker("galice.root")
32 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
33 // root [1] t->ExecuteTask()
34 // root [2] t->SetMaxEmcPpsdDistance(5)
35 // root [3] t->SetTrackSegmentsBranch("max distance 5 cm")
36 // root [4] t->ExecuteTask("deb all time")
38 //*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH)
41 // --- ROOT system ---
46 #include "TBenchmark.h"
47 // --- Standard library ---
52 // --- AliRoot header files ---
54 #include "AliPHOSTrackSegmentMakerv1.h"
55 #include "AliPHOSClusterizerv1.h"
56 #include "AliPHOSTrackSegment.h"
57 #include "AliPHOSCpvRecPoint.h"
58 #include "AliPHOSPpsdRecPoint.h"
59 #include "AliPHOSLink.h"
60 #include "AliPHOSv0.h"
63 ClassImp( AliPHOSTrackSegmentMakerv1)
66 //____________________________________________________________________________
67 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() : AliPHOSTrackSegmentMaker()
70 SetTitle("version 1") ;
71 SetName("AliPHOSTrackSegmentMaker") ;
81 fIsInitialized = kFALSE ;
83 //____________________________________________________________________________
84 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const char* headerFile, const char* branchTitle):
85 AliPHOSTrackSegmentMaker()
88 SetTitle("version 1") ;
89 SetName("AliPHOSTrackSegmentMaker") ;
98 fHeaderFileName = headerFile ;
99 fRecPointsBranchTitle = branchTitle ;
101 TFile * file = (TFile*) gROOT->GetFile(fHeaderFileName.Data() ) ;
104 file = new TFile(fHeaderFileName.Data(),"update") ;
105 gAlice = (AliRun *) file->Get("gAlice") ;
108 AliPHOS * phos = (AliPHOS *) gAlice->GetDetector("PHOS") ;
109 fGeom = AliPHOSGeometry::GetInstance(phos->GetGeometry()->GetName(),phos->GetGeometry()->GetTitle() );
111 fEmcRecPoints = new TObjArray(200) ;
112 fCpvRecPoints = new TObjArray(200) ;
113 fClusterizer = new AliPHOSClusterizerv1() ;
115 fTrackSegments = new TClonesArray("AliPHOSTrackSegment",200) ;
117 fLinkLowArray = new TClonesArray("AliPHOSLink", 1000);
118 fLinkUpArray = new TClonesArray("AliPHOSLink", 1000);
120 fIsInitialized = kTRUE ;
123 //____________________________________________________________________________
124 void AliPHOSTrackSegmentMakerv1::Init(){
125 //Make all memory allokations not possible in default constructor
128 if(fHeaderFileName.IsNull())
129 fHeaderFileName = "galice.root" ;
132 TFile * file = (TFile*) gROOT->GetFile(fHeaderFileName.Data() ) ;
135 file = new TFile(fHeaderFileName.Data(),"update") ;
136 gAlice = (AliRun *) file->Get("gAlice") ;
139 AliPHOS * phos = (AliPHOS *) gAlice->GetDetector("PHOS") ;
140 fGeom = AliPHOSGeometry::GetInstance(phos->GetGeometry()->GetName(),phos->GetGeometry()->GetTitle() );
143 fEmcRecPoints = new TObjArray(200) ;
144 fCpvRecPoints = new TObjArray(200) ;
145 fClusterizer = new AliPHOSClusterizerv1() ;
148 fTrackSegments = new TClonesArray("AliPHOSTrackSegment",200) ;
150 fLinkLowArray = new TClonesArray("AliPHOSLink", 1000);
151 fLinkUpArray = new TClonesArray("AliPHOSLink", 1000);
153 fIsInitialized = kTRUE ;
157 //____________________________________________________________________________
158 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
161 if(fLinkLowArray) delete fLinkLowArray ;
162 if(fLinkUpArray) delete fLinkUpArray ;
165 //____________________________________________________________________________
166 void AliPHOSTrackSegmentMakerv1::FillOneModule()
168 // Finds first and last indexes between which
169 // clusters from one PHOS module are
173 Int_t totalEmc = fEmcRecPoints->GetEntriesFast() ;
174 for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&
175 (((AliPHOSRecPoint *) fEmcRecPoints->At(fEmcLast))->GetPHOSMod() == fModule );
180 Int_t totalCpv = fCpvRecPoints->GetEntriesFast() ;
182 if(fModule <= fGeom->GetNCPVModules()){ // in CPV geometry
184 for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&
185 (((AliPHOSRecPoint *) fCpvRecPoints->At(fCpvLast))->GetPHOSMod() == fModule );
188 fPpsdFirst = fCpvLast ; //To avoid scanning RecPoints between fPpsdFirst and fPpsdLast
189 fPpsdLast = fCpvLast ; //and to be ready to switch to mixed geometry
191 else{ //in PPSD geometry
192 fCpvLast = fPpsdLast ;
194 for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&
195 (((AliPHOSPpsdRecPoint *) fCpvRecPoints->At(fCpvLast))->GetPHOSMod() == fModule ) &&
196 (((AliPHOSPpsdRecPoint *) fCpvRecPoints->At(fCpvLast))->GetUp()) ;
199 fPpsdLast= fCpvLast ;
200 for(fPpsdFirst = fPpsdLast; (fPpsdLast < totalCpv) &&
201 (((AliPHOSPpsdRecPoint *) fCpvRecPoints->At(fPpsdLast))->GetPHOSMod() == fModule ) &&
202 (!((AliPHOSPpsdRecPoint *) fCpvRecPoints->At(fPpsdLast))->GetUp()) ;
207 //____________________________________________________________________________
208 Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,AliPHOSRecPoint * cpvClu, Bool_t &toofar)
210 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
211 //clusters are sorted in "rows" and "columns" of width 1 cm
213 Float_t delta = 1 ; // Width of the rows in sorting of RecPoints (in cm)
214 // if you change this value, change it as well in xxxRecPoint::Compare()
220 emcClu->GetLocalPosition(vecEmc) ;
221 cpvClu->GetLocalPosition(vecCpv) ;
223 if(emcClu->GetPHOSMod() == cpvClu->GetPHOSMod()){
224 if(vecCpv.X() <= vecEmc.X() + fR0 + 2*delta ){
226 vecCpv = vecCpv - vecEmc ;
230 } // if xPpsd >= xEmc + ...
243 //____________________________________________________________________________
244 void AliPHOSTrackSegmentMakerv1::MakeLinks()
246 // Finds distances (links) between all EMC and PPSD clusters,
247 // which are not further apart from each other than fR0
248 // and sort them in accordance with this distance
250 fLinkUpArray->Clear() ;
251 fLinkLowArray->Clear() ;
253 AliPHOSRecPoint * ppsd ;
254 AliPHOSRecPoint * cpv ;
255 AliPHOSEmcRecPoint * emcclu ;
261 for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
262 emcclu = (AliPHOSEmcRecPoint *) fEmcRecPoints->At(iEmcRP) ;
266 for(iPpsd = fPpsdFirst; iPpsd < fPpsdLast;iPpsd++ ) {
268 ppsd = (AliPHOSRecPoint *) fCpvRecPoints->At(iPpsd) ;
269 Float_t r = GetDistanceInPHOSPlane(emcclu, ppsd, toofar) ;
274 new ((*fLinkLowArray)[iLinkLow++]) AliPHOSLink(r, iEmcRP, iPpsd) ;
278 for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) {
280 cpv = (AliPHOSRecPoint *) fCpvRecPoints->At(iCpv) ;
281 Float_t r = GetDistanceInPHOSPlane(emcclu, cpv, toofar) ;
286 new ((*fLinkUpArray)[iLinkUp++]) AliPHOSLink(r, iEmcRP, iCpv) ;
291 fLinkLowArray->Sort() ; //first links with smallest distances
292 fLinkUpArray->Sort() ;
295 //____________________________________________________________________________
296 void AliPHOSTrackSegmentMakerv1::MakePairs()
298 // Using the previously made list of "links", we found the smallest link - i.e.
299 // link with the least distance betwing EMC and CPV and pointing to still
300 // unassigned RecParticles. We assign these RecPoints to TrackSegment and
301 // remove them from the list of "unassigned".
303 //Make arrays to mark clusters already chousen
304 Int_t * emcExist = 0;
305 if(fEmcLast > fEmcFirst)
306 emcExist = new Int_t[fEmcLast-fEmcFirst] ;
309 for(index = 0; index <fEmcLast-fEmcFirst; index ++)
310 emcExist[index] = 1 ;
312 Bool_t * cpvExist = 0;
313 if(fCpvLast > fCpvFirst)
314 cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
315 for(index = 0; index <fCpvLast-fCpvFirst; index ++)
316 cpvExist[index] = kTRUE ;
318 Bool_t * ppsdExist = 0;
319 if(fPpsdLast > fPpsdFirst)
320 ppsdExist = new Bool_t[fPpsdLast-fPpsdFirst] ;
321 for(index = 0; index <fPpsdLast-fPpsdFirst; index ++)
322 ppsdExist[index] = kTRUE ;
324 // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance
325 TIter nextLow(fLinkLowArray) ;
326 TIter nextUp(fLinkUpArray) ;
328 AliPHOSLink * linkLow ;
329 AliPHOSLink * linkUp ;
332 AliPHOSRecPoint * nullpointer = 0 ;
334 while ( (linkLow = (AliPHOSLink *)nextLow() ) ){
336 if( (emcExist[linkLow->GetEmc()-fEmcFirst]> 0) && ppsdExist[linkLow->GetPpsd()-fPpsdFirst] ){ // RecPoints not removed yet
337 new ((*fTrackSegments)[fNTrackSegments]) AliPHOSTrackSegment((AliPHOSEmcRecPoint *) fEmcRecPoints->At(linkLow->GetEmc()),
339 (AliPHOSPpsdRecPoint *)fCpvRecPoints->At(linkLow->GetPpsd()) ) ;
341 ((AliPHOSTrackSegment* )fTrackSegments->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
342 //replace index of emc to negative and shifted index of TS
343 emcExist[linkLow->GetEmc()-fEmcFirst] = -2 - fNTrackSegments ;
345 ppsdExist[linkLow->GetPpsd()-fPpsdFirst] = kFALSE ;
351 while ( (linkUp = (AliPHOSLink *)nextUp() ) ){
352 if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){ //without ppsd Up yet
354 if(cpvExist[linkUp->GetPpsd()-fCpvFirst]){ //CPV still exist
356 if(emcExist[linkUp->GetEmc()-fEmcFirst] > 0){ //without ppsd Low => create new TS
358 new ((* fTrackSegments)[fNTrackSegments]) AliPHOSTrackSegment((AliPHOSEmcRecPoint *) fEmcRecPoints->At(linkUp->GetEmc()) ,
359 (AliPHOSPpsdRecPoint *)fCpvRecPoints->At(linkUp->GetPpsd()),
361 ((AliPHOSTrackSegment *) fTrackSegments->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
364 else{ // append ppsd Up to existing TS
365 ((AliPHOSTrackSegment *)fTrackSegments->At(-2-emcExist[linkUp->GetEmc()-fEmcFirst]))->SetCpvRecPoint((AliPHOSCpvRecPoint *)fCpvRecPoints->At(linkUp->GetPpsd()));
368 emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc that Cpv was found
369 //mark CPV recpoint as already used
370 cpvExist[linkUp->GetPpsd()-fCpvFirst] = kFALSE ;
371 } //if ppsdUp still exist
375 //look through emc recPoints left without CPV/PPSD
376 if(emcExist){ //if there is emc rec point
378 for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst ; iEmcRP++ ){
379 if(emcExist[iEmcRP] > 0 ){
380 new ((*fTrackSegments)[fNTrackSegments]) AliPHOSTrackSegment((AliPHOSEmcRecPoint *)fEmcRecPoints->At(iEmcRP+fEmcFirst),
383 ((AliPHOSTrackSegment *) fTrackSegments->At(fNTrackSegments))->SetIndexInList(fNTrackSegments);
391 //____________________________________________________________________________
392 void AliPHOSTrackSegmentMakerv1::Exec(Option_t * option)
396 if(! fIsInitialized) Init() ;
398 if(strstr(option,"tim"))
399 gBenchmark->Start("PHOSTSMaker");
401 Int_t nEvents = (Int_t) gAlice->TreeE()->GetEntries() ;
403 for(fEvent = 0;fEvent< nEvents; fEvent++){
404 if(!ReadRecPoints()) //reads RecPoints for event fEvent
407 for(fModule = 1; fModule <= fGeom->GetNModules() ; fModule++ ){
417 WriteTrackSegments() ;
418 if(strstr(option,"deb"))
419 PrintTrackSegments(option) ;
422 if(strstr(option,"tim")){
423 gBenchmark->Stop("PHOSTSMaker");
424 cout << "AliPHOSTSMaker:" << endl ;
425 cout << " took " << gBenchmark->GetCpuTime("PHOSTSMaker") << " seconds for making TS "
426 << gBenchmark->GetCpuTime("PHOSTSMaker")/nEvents << " seconds per event " << endl ;
432 //____________________________________________________________________________
433 void AliPHOSTrackSegmentMakerv1::Print(Option_t * option)const {
435 cout << "======== AliPHOSTrackSegmentMakerv1 ========" << endl ;
436 cout << "Making Track segments "<< endl ;
437 cout << " Headers file: " << fHeaderFileName.Data() << endl ;
438 cout << " RecPoints branch file name: " << fRecPointsBranchTitle.Data() << endl ;
439 cout << " TrackSegments Branch file name: " << fTSBranchTitle.Data() << endl ;
440 cout << "with parameters: " << endl ;
441 cout << " Maximal EMC - CPV (PPSD) distance (cm)" << fR0 << endl ;
442 cout << "============================================" << endl ;
445 cout << "AliPHOSTrackSegmentMakerv1 not initialized " << endl ;
447 //____________________________________________________________________________
448 Bool_t AliPHOSTrackSegmentMakerv1::ReadRecPoints(){
449 // Reads Emc and CPV recPoints with given title (fRecPointsBranchTitle)
450 // made priveously with Clusterizer.
453 //Make some initializations
454 fEmcRecPoints->Clear() ;
455 fCpvRecPoints->Clear() ;
456 fTrackSegments->Clear() ;
457 fNTrackSegments = 0 ;
466 gAlice->GetEvent(fEvent) ;
468 // Get TreeR header from file
469 if(gAlice->TreeR()==0){
471 sprintf(treeName,"TreeR%d",fEvent);
472 cout << "Error in AliPHOSTrackSegmentMakerv1 : no "<<treeName << endl ;
473 cout << " Do nothing " << endl ;
478 //Find RecPoints with title fRecPointsBranchTitle
479 TBranch * emcBranch = 0;
480 TBranch * cpvBranch = 0;
481 TBranch * clusterizerBranch = 0;
483 TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
485 Bool_t emcNotFound = kTRUE ;
486 Bool_t cpvNotFound = kTRUE ;
487 Bool_t clusterizerNotFound = kTRUE ;
489 for(ibranch = 0;ibranch <branches->GetEntries();ibranch++){
492 emcBranch=(TBranch *) branches->At(ibranch) ;
493 if( fRecPointsBranchTitle.CompareTo(emcBranch->GetTitle())==0 )
494 if( strcmp(emcBranch->GetName(),"PHOSEmcRP") == 0) {
495 emcNotFound = kFALSE ;
500 cpvBranch=(TBranch *) branches->At(ibranch) ;
501 if( fRecPointsBranchTitle.CompareTo(cpvBranch->GetTitle())==0 )
502 if( strcmp(cpvBranch->GetName(),"PHOSCpvRP") == 0)
503 cpvNotFound = kFALSE ;
506 if(clusterizerNotFound){
507 clusterizerBranch = (TBranch *) branches->At(ibranch) ;
508 if( fRecPointsBranchTitle.CompareTo(clusterizerBranch->GetTitle()) == 0)
509 if( strcmp(clusterizerBranch->GetName(),"AliPHOSClusterizer") == 0)
510 clusterizerNotFound = kFALSE ;
515 if(clusterizerNotFound || emcNotFound || cpvNotFound){
516 cout << "AliPHOSTrackSegmentMakerv1: " << endl ;
517 cout << " Can't find Branch with RecPoints or Clusterizer " ;
518 cout << " Do nothing" <<endl ;
522 emcBranch->SetAddress(&fEmcRecPoints) ;
523 cpvBranch->SetAddress(&fCpvRecPoints) ;
524 clusterizerBranch->SetAddress(&fClusterizer) ;
526 gAlice->TreeR()->GetEvent(0) ;
531 //____________________________________________________________________________
532 void AliPHOSTrackSegmentMakerv1::WriteTrackSegments(){
533 // Writes found TrackSegments to TreeR. Creates branches
534 // "PHOSTS" and "AliPHOSTrackSegmentMaker" with the same title.
535 // In the former branch found TrackSegments are stored, while
536 // in the latter all parameters, with which TS were made.
537 // ROOT does not allow overwriting existing branches, therefore
538 // first we chesk, if branches with the same title alredy exist.
539 // If yes - exits without writing.
541 //First, check, if branches already exist
542 TBranch * tsMakerBranch = 0;
543 TBranch * tsBranch = 0;
545 TObjArray * branches = gAlice->TreeR()->GetListOfBranches() ;
547 Bool_t tsMakerNotFound = kTRUE ;
548 Bool_t tsNotFound = kTRUE ;
550 for(ibranch = 0;(ibranch <branches->GetEntries())&&(tsMakerNotFound||tsNotFound);ibranch++){
552 tsMakerBranch=(TBranch *) branches->At(ibranch) ;
553 if( (strcmp(tsMakerBranch->GetName(),"AliPHOSTrackSegmentMaker") == 0) &&
554 (fTSBranchTitle.CompareTo( tsMakerBranch->GetTitle())==0 ))
555 tsMakerNotFound = kFALSE ;
558 tsBranch=(TBranch *) branches->At(ibranch) ;
559 if( (strcmp(tsBranch->GetName(),"PHOSTS") == 0) &&
560 (fTSBranchTitle.CompareTo( tsBranch->GetTitle())==0 ))
561 tsNotFound = kFALSE ;
565 if(!(tsMakerNotFound && tsNotFound )){
566 cout << "AliPHOSTrackSegmentMakerv1 error:"<< endl ;
567 cout << " Branches PHOSTS and AliPHOSTrackSegementMaker " << endl ;
568 cout << " with title '"<<fTSBranchTitle.Data() << "' already exist " << endl ;
569 cout << " can not overwrite " << endl ;
573 //Make branch in TreeR for TrackSegments
575 if(gSystem->Getenv("CONFIG_SPLIT_FILE")!=0){ //generating file name
576 filename = new char[strlen(gAlice->GetBaseFile())+20] ;
577 sprintf(filename,"%s/PHOS.Reco.root",gAlice->GetBaseFile()) ;
580 TDirectory *cwd = gDirectory;
583 Int_t bufferSize = 32000 ;
584 tsBranch = gAlice->TreeR()->Branch("PHOSTS",&fTrackSegments,bufferSize);
585 tsBranch->SetTitle(fTSBranchTitle.Data());
587 tsBranch->SetFile(filename);
588 TIter next( tsBranch->GetListOfBranches());
589 while ((tsBranch=(TBranch*)next())) {
590 tsBranch->SetFile(filename);
596 Int_t splitlevel = 0 ;
597 AliPHOSTrackSegmentMakerv1 * ts = this ;
598 tsMakerBranch = gAlice->TreeR()->Branch("AliPHOSTrackSegmentMaker","AliPHOSTrackSegmentMakerv1",
599 &ts,bufferSize,splitlevel);
600 tsMakerBranch->SetTitle(fTSBranchTitle.Data());
602 tsMakerBranch->SetFile(filename);
603 TIter next( tsMakerBranch->GetListOfBranches());
604 while ((tsMakerBranch=(TBranch*)next())) {
605 tsMakerBranch->SetFile(filename);
610 gAlice->TreeR()->Fill() ;
611 gAlice->TreeR()->Write(0,kOverwrite) ;
616 //____________________________________________________________________________
617 void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option){
618 // option deb - prints # of found TrackSegments
619 // option deb all - prints as well indexed of found RecParticles assigned to the TS
622 cout << "AliPHOSTrackSegmentMakerv1: " << endl ;
623 cout << " Found " << fTrackSegments->GetEntriesFast() << " trackSegments " << endl ;
625 if(strstr(option,"all")) { // printing found TS
626 cout << "TrackSegment # " << " EMC RP# " << " CPV RP# " << " PPSD RP#" << endl ;
629 for (index = 0 ; index <fTrackSegments->GetEntriesFast() ; index++) {
630 AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )fTrackSegments->At(index) ;
631 cout<<" "<< setw(4) << ts->GetIndexInList() << " "
632 <<setw(4) << ts->GetEmcIndex()<< " "
633 <<setw(4) << ts->GetCpvIndex()<< " "
634 <<setw(4) << ts->GetPpsdIndex()<< endl ;
637 cout << "-------------------------------------------------------"<< endl ;