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 fRcpv.
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 ;
86 fDefaultInit = kTRUE ;
89 //____________________________________________________________________________
90 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const char * headerFile, const char * name, const Bool_t toSplit) : AliPHOSTrackSegmentMaker(headerFile, name, toSplit)
95 // fHeaderFileName = GetTitle() ;
96 // fRecPointsBranchTitle = GetName() ;
97 // fTrackSegmentsBranchTitle = GetName() ;
98 fTrackSegmentsInRun = 0 ;
106 fDefaultInit = kFALSE ;
110 //____________________________________________________________________________
111 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
114 // fDefaultInit = kTRUE if TrackSegmentMaker created by default ctor (to get just the parameters)
117 delete fLinkUpArray ;
119 // AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
121 // // remove the task from the folder list
122 // gime->RemoveTask("T",GetName()) ;
123 // TString name(GetName()) ;
124 // name.ReplaceAll("tsm", "clu") ;
125 // gime->RemoveTask("C",name) ;
127 // // remove the data from the folder list
128 // name = GetName() ;
129 // name.Remove(name.Index(":")) ;
130 // gime->RemoveObjects("RE", name) ; // EMCARecPoints
131 // gime->RemoveObjects("RC", name) ; // CPVRecPoints
132 // gime->RemoveObjects("T", name) ; // TrackSegments
135 // gime->CloseFile() ;
142 //____________________________________________________________________________
143 const TString AliPHOSTrackSegmentMakerv1::BranchName() const
145 TString branchName(GetName() ) ;
146 branchName.Remove(branchName.Index(Version())-1) ;
150 //____________________________________________________________________________
151 void AliPHOSTrackSegmentMakerv1::FillOneModule()
153 // Finds first and last indexes between which
154 // clusters from one PHOS module are
156 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
157 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
158 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
161 Int_t totalEmc = emcRecPoints->GetEntriesFast() ;
162 for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&
163 ((dynamic_cast<AliPHOSRecPoint *>(emcRecPoints->At(fEmcLast)))->GetPHOSMod() == fModule );
167 Int_t totalCpv = cpvRecPoints->GetEntriesFast() ;
169 for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&
170 ((dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(fCpvLast)))->GetPHOSMod() == fModule );
175 //____________________________________________________________________________
176 Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,AliPHOSRecPoint * cpvClu, Bool_t &toofar)const
178 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
179 // Clusters are sorted in "rows" and "columns" of width 1 cm
181 Float_t delta = 1 ; // Width of the rows in sorting of RecPoints (in cm)
182 // if you change this value, change it as well in xxxRecPoint::Compare()
188 emcClu->GetLocalPosition(vecEmc) ;
189 cpvClu->GetLocalPosition(vecCpv) ;
191 if(emcClu->GetPHOSMod() == cpvClu->GetPHOSMod()){
192 if(vecCpv.X() <= vecEmc.X() + fRcpv + 2*delta ){
194 vecCpv = vecCpv - vecEmc ;
198 } // if xPpsd >= xEmc + ...
211 //____________________________________________________________________________
212 void AliPHOSTrackSegmentMakerv1::Init()
214 // Make all memory allocations that are not possible in default constructor
216 if ( strcmp(GetTitle(), "") == 0 )
217 SetTitle("galice.root") ;
219 TString branchname = GetName() ;
220 branchname.Remove(branchname.Index(Version())-1) ;
221 AliPHOSGetter * gime = AliPHOSGetter::GetInstance(GetTitle(),branchname.Data(), fToSplit ) ;
223 cerr << "ERROR: AliPHOSTrackSegmentMakerv1::Init -> Could not obtain the Getter object !" << endl ;
229 //First - extract full path if necessary
230 TString fileName(GetTitle()) ;
231 Ssiz_t islash = fileName.Last('/') ;
232 if(islash<fileName.Length())
233 fileName.Remove(islash+1,fileName.Length()) ;
236 fileName+="PHOS.RecData." ;
237 if((strcmp(branchname.Data(),"Default")!=0)&&(strcmp(branchname.Data(),"")!=0)){
238 fileName+=branchname ;
242 fSplitFile = static_cast<TFile*>(gROOT->GetFile(fileName.Data()));
244 fSplitFile = TFile::Open(fileName.Data(),"update") ;
247 fLinkUpArray = new TClonesArray("AliPHOSLink", 1000);
250 gime->PostTrackSegmentMaker(this) ;
251 gime->PostTrackSegments(BranchName()) ;
255 //____________________________________________________________________________
256 void AliPHOSTrackSegmentMakerv1::InitParameters()
264 TString tsmName( GetName()) ;
265 if (tsmName.IsNull() )
266 tsmName = "Default" ;
267 tsmName.Append(":") ;
268 tsmName.Append(Version()) ;
273 //____________________________________________________________________________
274 void AliPHOSTrackSegmentMakerv1::MakeLinks()const
276 // Finds distances (links) between all EMC and PPSD clusters,
277 // which are not further apart from each other than fRcpv
278 // and sort them in accordance with this distance
280 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
281 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
282 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
284 fLinkUpArray->Clear() ;
286 AliPHOSRecPoint * cpv ;
287 AliPHOSEmcRecPoint * emcclu ;
292 for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
293 emcclu = dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP)) ;
297 for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) {
299 cpv = dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(iCpv)) ;
300 Float_t r = GetDistanceInPHOSPlane(emcclu, cpv, toofar) ;
305 new ((*fLinkUpArray)[iLinkUp++]) AliPHOSLink(r, iEmcRP, iCpv) ;
310 fLinkUpArray->Sort() ; //first links with smallest distances
313 //____________________________________________________________________________
314 void AliPHOSTrackSegmentMakerv1::MakePairs()
316 // Using the previously made list of "links", we found the smallest link - i.e.
317 // link with the least distance between EMC and CPV and pointing to still
318 // unassigned RecParticles. We assign these RecPoints to TrackSegment and
319 // remove them from the list of "unassigned".
321 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
322 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
323 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
324 TClonesArray * trackSegments = gime->TrackSegments(BranchName()) ;
326 //Make arrays to mark clusters already chosen
327 Int_t * emcExist = 0;
328 if(fEmcLast > fEmcFirst)
329 emcExist = new Int_t[fEmcLast-fEmcFirst] ;
332 for(index = 0; index <fEmcLast-fEmcFirst; index ++)
333 emcExist[index] = 1 ;
335 Bool_t * cpvExist = 0;
336 if(fCpvLast > fCpvFirst)
337 cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
338 for(index = 0; index <fCpvLast-fCpvFirst; index ++)
339 cpvExist[index] = kTRUE ;
342 // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance
343 TIter nextUp(fLinkUpArray) ;
345 AliPHOSLink * linkUp ;
347 AliPHOSRecPoint * nullpointer = 0 ;
349 while ( (linkUp = static_cast<AliPHOSLink *>(nextUp()) ) ){
351 if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){ //without ppsd Up yet
353 if(cpvExist[linkUp->GetPpsd()-fCpvFirst]){ //CPV still exist
355 new ((* trackSegments)[fNTrackSegments])
356 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(linkUp->GetEmc())) ,
357 dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(linkUp->GetPpsd()))) ;
358 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
361 emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc that Cpv was found
362 //mark CPV recpoint as already used
363 cpvExist[linkUp->GetPpsd()-fCpvFirst] = kFALSE ;
364 } //if ppsdUp still exist
368 //look through emc recPoints left without CPV/PPSD
369 if(emcExist){ //if there is emc rec point
371 for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst ; iEmcRP++ ){
372 if(emcExist[iEmcRP] > 0 ){
373 new ((*trackSegments)[fNTrackSegments])
374 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP+fEmcFirst)),
376 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
385 //____________________________________________________________________________
386 void AliPHOSTrackSegmentMakerv1::Exec(Option_t * option)
390 if( strcmp(GetName(), "")== 0 )
393 if(strstr(option,"tim"))
394 gBenchmark->Start("PHOSTSMaker");
396 if(strstr(option,"print")) {
401 // gAlice->GetEvent(0) ;
402 // //check, if the branch with name of this" already exits?
403 // if (gAlice->TreeR()) {
404 // TObjArray * lob = static_cast<TObjArray*>(gAlice->TreeR()->GetListOfBranches()) ;
406 // TBranch * branch = 0 ;
407 // Bool_t phostsfound = kFALSE, tracksegmentmakerfound = kFALSE ;
409 // TString branchname = GetName() ;
410 // branchname.Remove(branchname.Index(Version())-1) ;
412 // while ( (branch = static_cast<TBranch*>(next())) && (!phostsfound || !tracksegmentmakerfound) ) {
413 // if ( (strcmp(branch->GetName(), "PHOSTS")==0) && (strcmp(branch->GetTitle(), branchname.Data())==0) )
414 // phostsfound = kTRUE ;
416 // else if ( (strcmp(branch->GetName(), "AliPHOSTrackSegmentMaker")==0) && (strcmp(branch->GetTitle(), GetName())==0) )
417 // tracksegmentmakerfound = kTRUE ;
420 // if ( phostsfound || tracksegmentmakerfound ) {
421 // cerr << "WARNING: AliPHOSTrackSegmentMakerv1::Exec -> TrackSegments and/or TrackSegmentMaker branch with name "
422 // << branchname.Data() << " already exits" << endl ;
427 AliPHOSGetter * gime = AliPHOSGetter::GetInstance() ;
428 if(gime->BranchExists("TrackSegments") )
430 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
431 Int_t nevents = gime->MaxEvent() ; //(Int_t) gAlice->TreeE()->GetEntries() ;
434 for(ievent = 0; ievent < nevents; ievent++){
436 gime->Event(ievent,"R") ;
437 //Make some initializations
438 fNTrackSegments = 0 ;
443 gime->TrackSegments(BranchName())->Clear() ;
445 // if(!ReadRecPoints(ievent)) continue; //reads RecPoints for event ievent
447 for(fModule = 1; fModule <= geom->GetNModules() ; fModule++ ){
457 WriteTrackSegments(ievent) ;
459 if(strstr(option,"deb"))
460 PrintTrackSegments(option) ;
462 //increment the total number of track segments per run
463 fTrackSegmentsInRun += gime->TrackSegments(BranchName())->GetEntriesFast() ;
467 if(strstr(option,"tim")){
468 gBenchmark->Stop("PHOSTSMaker");
469 cout << "AliPHOSTSMaker:" << endl ;
470 cout << " took " << gBenchmark->GetCpuTime("PHOSTSMaker") << " seconds for making TS "
471 << gBenchmark->GetCpuTime("PHOSTSMaker")/nevents << " seconds per event " << endl ;
477 //____________________________________________________________________________
478 void AliPHOSTrackSegmentMakerv1::Print(Option_t * option)const
480 // Print TrackSegmentMaker parameters
482 if( strcmp(GetName(), "") != 0 ) {
483 cout << "======== AliPHOSTrackSegmentMakerv1 ========" << endl ;
484 cout << "Making Track segments "<< endl ;
485 // cout << " Headers file: " << fHeaderFileName.Data() << endl ;
486 // cout << " RecPoints branch file name: " << fRecPointsBranchTitle.Data() << endl ;
487 // cout << " TrackSegments Branch file name: " << fTrackSegmentsBranchTitle.Data() << endl ;
488 cout << "with parameters: " << endl ;
489 cout << " Maximal EMC - CPV (PPSD) distance (cm)" << fRcpv << endl ;
490 cout << "============================================" << endl ;
493 cout << "AliPHOSTrackSegmentMakerv1 not initialized " << endl ;
496 //____________________________________________________________________________
497 void AliPHOSTrackSegmentMakerv1::WriteTrackSegments(Int_t event)
499 // Writes found TrackSegments to TreeR. Creates branches
500 // "PHOSTS" and "AliPHOSTrackSegmentMaker" with the same title.
501 // In the former branch found TrackSegments are stored, while
502 // in the latter all parameters, with which TS were made.
503 // ROOT does not allow overwriting existing branches, therefore
504 // first we check, if branches with the same title already exist.
505 // If yes - exits without writing.
507 AliPHOSGetter *gime = AliPHOSGetter::GetInstance() ;
509 TClonesArray * trackSegments = gime->TrackSegments() ;
510 trackSegments->Expand(trackSegments->GetEntriesFast()) ;
518 sprintf(name,"%s%d", "TreeR",event) ;
519 treeR = dynamic_cast<TTree*>(fSplitFile->Get(name));
522 treeR = gAlice->TreeR();
526 gAlice->MakeTree("R", fSplitFile);
527 treeR = gAlice->TreeR() ;
531 Int_t bufferSize = 32000 ;
532 TBranch * tsBranch = treeR->Branch("PHOSTS",&trackSegments,bufferSize);
533 tsBranch->SetTitle(BranchName());
536 Int_t splitlevel = 0 ;
537 AliPHOSTrackSegmentMakerv1 * ts = this ;
538 TBranch * tsMakerBranch = treeR->Branch("AliPHOSTrackSegmentMaker","AliPHOSTrackSegmentMakerv1",
539 &ts,bufferSize,splitlevel);
540 tsMakerBranch->SetTitle(BranchName());
543 tsMakerBranch->Fill() ;
545 treeR->AutoSave() ; //Write(0,kOverwrite) ;
546 if(gAlice->TreeR()!=treeR)
551 //____________________________________________________________________________
552 void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
554 // option deb - prints # of found TrackSegments
555 // option deb all - prints as well indexed of found RecParticles assigned to the TS
556 TString taskName(GetName()) ;
557 taskName.Remove(taskName.Index(Version())-1) ;
559 TClonesArray * trackSegments = AliPHOSGetter::GetInstance()->TrackSegments(taskName) ;
562 cout << "AliPHOSTrackSegmentMakerv1: event "<<gAlice->GetEvNumber() << endl ;
563 cout << " Found " << trackSegments->GetEntriesFast() << " trackSegments " << endl ;
565 if(strstr(option,"all")) { // printing found TS
566 cout << "TrackSegment # " << " EMC RP# " << " CPV RP# " << endl ;
569 for (index = 0 ; index <trackSegments->GetEntriesFast() ; index++) {
570 AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )trackSegments->At(index) ;
571 cout<<" "<< setw(4) << ts->GetIndexInList() << " "
572 <<setw(4) << ts->GetEmcIndex()<< " "
573 <<setw(4) << ts->GetCpvIndex()<< " " << endl ;
576 cout << "-------------------------------------------------------"<< endl ;