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.
31 //// In principle this class should be called from AliPHOSReconstructioner, but
32 // one can use it as well in standalone mode.
34 // root [0] AliPHOSTrackSegmentMakerv1 * t = new AliPHOSTrackSegmentMaker("galice.root", "tracksegmentsname", "recpointsname")
35 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
36 // // reads gAlice from header file "galice.root", uses recpoints stored in the branch names "recpointsname" (default = "Default")
37 // // and saves recpoints in branch named "tracksegmentsname" (default = "recpointsname")
38 // root [1] t->ExecuteTask()
39 // root [2] t->SetMaxEmcPpsdDistance(5)
40 // root [3] t->SetTrackSegmentsBranch("max distance 5 cm")
41 // root [4] t->ExecuteTask("deb all time")
43 //*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH) & Yves Schutz (SUBATECH)
46 // --- ROOT system ---
48 #include "TBenchmark.h"
50 // --- Standard library ---
52 // --- AliRoot header files ---
53 #include "AliPHOSGeometry.h"
54 #include "AliPHOSTrackSegmentMakerv1.h"
55 #include "AliPHOSTrackSegment.h"
56 #include "AliPHOSLink.h"
57 #include "AliPHOSGetter.h"
59 ClassImp( AliPHOSTrackSegmentMakerv1)
62 //____________________________________________________________________________
63 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() : AliPHOSTrackSegmentMaker()
65 // default ctor (to be used mainly by Streamer)
68 fDefaultInit = kTRUE ;
71 //____________________________________________________________________________
72 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const TString alirunFileName, const TString eventFolderName)
73 :AliPHOSTrackSegmentMaker(alirunFileName, eventFolderName)
79 fDefaultInit = kFALSE ;
82 //____________________________________________________________________________
83 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
86 // fDefaultInit = kTRUE if TrackSegmentMaker created by default ctor (to get just the parameters)
92 //____________________________________________________________________________
93 const TString AliPHOSTrackSegmentMakerv1::BranchName() const
99 //____________________________________________________________________________
100 void AliPHOSTrackSegmentMakerv1::FillOneModule()
102 // Finds first and last indexes between which
103 // clusters from one PHOS module are
105 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
107 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
108 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
111 Int_t totalEmc = emcRecPoints->GetEntriesFast() ;
112 for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&
113 ((dynamic_cast<AliPHOSRecPoint *>(emcRecPoints->At(fEmcLast)))->GetPHOSMod() == fModule );
117 Int_t totalCpv = cpvRecPoints->GetEntriesFast() ;
119 for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&
120 ((dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(fCpvLast)))->GetPHOSMod() == fModule );
125 //____________________________________________________________________________
126 Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,AliPHOSRecPoint * cpvClu, Bool_t &toofar)const
128 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
129 // Clusters are sorted in "rows" and "columns" of width 1 cm
131 Float_t delta = 1 ; // Width of the rows in sorting of RecPoints (in cm)
132 // if you change this value, change it as well in xxxRecPoint::Compare()
138 emcClu->GetLocalPosition(vecEmc) ;
139 cpvClu->GetLocalPosition(vecCpv) ;
141 if(emcClu->GetPHOSMod() == cpvClu->GetPHOSMod()){
142 if(vecCpv.X() <= vecEmc.X() + fRcpv + 2*delta ){
144 vecCpv = vecCpv - vecEmc ;
148 } // if xPpsd >= xEmc + ...
161 //____________________________________________________________________________
162 void AliPHOSTrackSegmentMakerv1::Init()
164 // Make all memory allocations that are not possible in default constructor
166 AliPHOSGetter* gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
168 fLinkUpArray = new TClonesArray("AliPHOSLink", 1000);
169 if ( !gime->TrackSegmentMaker() ) {
170 gime->PostTrackSegmentMaker(this);
174 //____________________________________________________________________________
175 void AliPHOSTrackSegmentMakerv1::InitParameters()
177 //Initializes parameters
184 fTrackSegmentsInRun = 0 ;
185 SetEventRange(0,-1) ;
189 //____________________________________________________________________________
190 void AliPHOSTrackSegmentMakerv1::MakeLinks()const
192 // Finds distances (links) between all EMC and PPSD clusters,
193 // which are not further apart from each other than fRcpv
194 // and sort them in accordance with this distance
196 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
197 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
198 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
200 fLinkUpArray->Clear() ;
202 AliPHOSRecPoint * cpv ;
203 AliPHOSEmcRecPoint * emcclu ;
208 for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
209 emcclu = dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP)) ;
213 for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) {
215 cpv = dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(iCpv)) ;
216 Float_t r = GetDistanceInPHOSPlane(emcclu, cpv, toofar) ;
221 new ((*fLinkUpArray)[iLinkUp++]) AliPHOSLink(r, iEmcRP, iCpv) ;
226 fLinkUpArray->Sort() ; //first links with smallest distances
229 //____________________________________________________________________________
230 void AliPHOSTrackSegmentMakerv1::MakePairs()
232 // Using the previously made list of "links", we found the smallest link - i.e.
233 // link with the least distance between EMC and CPV and pointing to still
234 // unassigned RecParticles. We assign these RecPoints to TrackSegment and
235 // remove them from the list of "unassigned".
237 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
239 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
240 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
241 TClonesArray * trackSegments = gime->TrackSegments();
243 //Make arrays to mark clusters already chosen
244 Int_t * emcExist = 0;
245 if(fEmcLast > fEmcFirst)
246 emcExist = new Int_t[fEmcLast-fEmcFirst] ;
249 for(index = 0; index <fEmcLast-fEmcFirst; index ++)
250 emcExist[index] = 1 ;
252 Bool_t * cpvExist = 0;
253 if(fCpvLast > fCpvFirst)
254 cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
255 for(index = 0; index <fCpvLast-fCpvFirst; index ++)
256 cpvExist[index] = kTRUE ;
259 // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance
260 TIter nextUp(fLinkUpArray) ;
262 AliPHOSLink * linkUp ;
264 AliPHOSRecPoint * nullpointer = 0 ;
266 while ( (linkUp = static_cast<AliPHOSLink *>(nextUp()) ) ){
268 if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){ //without ppsd Up yet
270 if(cpvExist[linkUp->GetPpsd()-fCpvFirst]){ //CPV still exist
272 new ((* trackSegments)[fNTrackSegments])
273 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(linkUp->GetEmc())) ,
274 dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(linkUp->GetPpsd()))) ;
275 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
278 emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc that Cpv was found
279 //mark CPV recpoint as already used
280 cpvExist[linkUp->GetPpsd()-fCpvFirst] = kFALSE ;
281 } //if ppsdUp still exist
285 //look through emc recPoints left without CPV/PPSD
286 if(emcExist){ //if there is emc rec point
288 for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst ; iEmcRP++ ){
289 if(emcExist[iEmcRP] > 0 ){
290 new ((*trackSegments)[fNTrackSegments])
291 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP+fEmcFirst)),
293 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
302 //____________________________________________________________________________
303 void AliPHOSTrackSegmentMakerv1::Exec(Option_t *option)
305 // Steering method to perform track segment construction for events
306 // in the range from fFirstEvent to fLastEvent.
307 // This range is optionally set by SetEventRange().
308 // if fLastEvent=-1 (by default), then process events until the end.
310 if(strstr(option,"tim"))
311 gBenchmark->Start("PHOSTSMaker");
313 if(strstr(option,"print")) {
318 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
320 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
322 if (fLastEvent == -1) fLastEvent = gime->MaxEvent() - 1 ;
323 else fLastEvent = TMath::Min(fLastEvent,gime->MaxEvent());
324 Int_t nEvents = fLastEvent - fFirstEvent + 1;
326 for (Int_t ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
327 gime->Event(ievent,"R") ;
328 //Make some initializations
329 fNTrackSegments = 0 ;
335 gime->TrackSegments()->Clear();
337 // if(!ReadRecPoints(ievent)) continue; //reads RecPoints for event ievent
339 for(fModule = 1; fModule <= geom->GetNModules() ; fModule++ ) {
345 WriteTrackSegments() ;
347 if(strstr(option,"deb"))
348 PrintTrackSegments(option);
350 //increment the total number of track segments per run
351 fTrackSegmentsInRun += gime->TrackSegments()->GetEntriesFast() ;
355 if(strstr(option,"tim")){
356 gBenchmark->Stop("PHOSTSMaker");
357 Info("Exec", "took %f seconds for making TS %f seconds per event",
358 gBenchmark->GetCpuTime("PHOSTSMaker"),
359 gBenchmark->GetCpuTime("PHOSTSMaker")/nEvents) ;
364 //____________________________________________________________________________
365 void AliPHOSTrackSegmentMakerv1::Unload()
367 // Unloads the task from the folder
368 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
369 gime->PhosLoader()->UnloadRecPoints() ;
370 gime->PhosLoader()->UnloadTracks() ;
373 //____________________________________________________________________________
374 void AliPHOSTrackSegmentMakerv1::Print()const
376 // Print TrackSegmentMaker parameters
378 TString message("") ;
379 if( strcmp(GetName(), "") != 0 ) {
380 message = "\n======== AliPHOSTrackSegmentMakerv1 ========\n" ;
381 message += "Making Track segments\n" ;
382 message += "with parameters:\n" ;
383 message += " Maximal EMC - CPV (PPSD) distance (cm) %f\n" ;
384 message += "============================================\n" ;
385 Info("Print", message.Data(),fRcpv) ;
388 Info("Print", "AliPHOSTrackSegmentMakerv1 not initialized ") ;
391 //____________________________________________________________________________
392 void AliPHOSTrackSegmentMakerv1::WriteTrackSegments()
394 // Writes found TrackSegments to TreeR. Creates branches
395 // "PHOSTS" and "AliPHOSTrackSegmentMaker" with the same title.
396 // In the former branch found TrackSegments are stored, while
397 // in the latter all parameters, with which TS were made.
398 // ROOT does not allow overwriting existing branches, therefore
399 // first we check, if branches with the same title already exist.
400 // If yes - exits without writing.
402 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
404 TClonesArray * trackSegments = gime->TrackSegments() ;
405 trackSegments->Expand(trackSegments->GetEntriesFast()) ;
407 TTree * treeT = gime->TreeT();
410 Int_t bufferSize = 32000 ;
411 TBranch * tsBranch = treeT->Branch("PHOSTS",&trackSegments,bufferSize);
414 gime->WriteTracks("OVERWRITE");
415 gime->WriteTrackSegmentMaker("OVERWRITE");
419 //____________________________________________________________________________
420 void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
422 // option deb - prints # of found TrackSegments
423 // option deb all - prints as well indexed of found RecParticles assigned to the TS
425 TClonesArray * trackSegments = AliPHOSGetter::Instance()->TrackSegments() ;
427 Info("PrintTrackSegments", "Results from TrackSegmentMaker:") ;
428 printf("nevent: %d\n", gAlice->GetEvNumber()) ;
429 printf(" Found %d TrackSegments\n", trackSegments->GetEntriesFast() );
431 if(strstr(option,"all")) { // printing found TS
432 printf("TrackSegment # EMC RP# CPV RP#\n") ;
434 for (index = 0 ; index <trackSegments->GetEntriesFast() ; index++) {
435 AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )trackSegments->At(index) ;
436 printf(" %d %d %d \n", ts->GetIndexInList(), ts->GetEmcIndex(), ts->GetCpvIndex() ) ;