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 EMCAL track segments
18 // Track segment for EMCAL is list of
19 // ECAL RecPoint + (possibly) PRE RecPoint + (possibly) HCAL RecPoint
20 // To find TrackSegments we do the following:
21 // for each ECAL RecPoint we look for PRE and HC RecPoints with same direction within fSame.
22 // If there is such a PRE or ECAL RecPoint,
23 // we make a "Link": indexes of ECAL and PRE, HCAL RecPoints and their scalar product.
24 // Then we sort "Links", starting from the
25 // least "Link" pointing to the unassigned RecPoints assigning them to a new TrackSegment.
26 // If there is no PRE, HCAL RecPoint we make a TrackSegment
27 // consisting from ECAL alone. There is no TrackSegments without ECAL RecPoint.
28 //// In principle this class should be called from AliEMCALReconstructioner, but
29 // one can use it as well in standalone mode.
31 //*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH) & Yves Schutz (SUBATECH)
34 // --- ROOT system ---
36 #include "TBenchmark.h"
38 // --- Standard library ---
40 // --- AliRoot header files ---
42 #include "AliEMCALTrackSegmentMakerv1.h"
43 #include "AliEMCALTrackSegment.h"
44 #include "AliEMCALLink.h"
45 #include "AliEMCALGetter.h"
47 ClassImp( AliEMCALTrackSegmentMakerv1)
50 //____________________________________________________________________________
51 AliEMCALTrackSegmentMakerv1::AliEMCALTrackSegmentMakerv1() : AliEMCALTrackSegmentMaker()
53 // default ctor (to be used mainly by Streamer)
56 fDefaultInit = kTRUE ;
59 //____________________________________________________________________________
60 AliEMCALTrackSegmentMakerv1::AliEMCALTrackSegmentMakerv1(const TString alirunFileName, const TString eventFolderName)
61 :AliEMCALTrackSegmentMaker(alirunFileName, eventFolderName)
67 fDefaultInit = kFALSE ;
71 //____________________________________________________________________________
72 AliEMCALTrackSegmentMakerv1::~AliEMCALTrackSegmentMakerv1()
75 // fDefaultInit = kTRUE if TrackSegmentMaker created by default ctor (to get just the parameters)
79 //____________________________________________________________________________
80 const TString AliEMCALTrackSegmentMakerv1::BranchName() const
86 //____________________________________________________________________________
87 Float_t AliEMCALTrackSegmentMakerv1::HowClose(AliEMCALTowerRecPoint * ec, AliEMCALTowerRecPoint * rp, Bool_t &toofar)const
89 // Calculates the distance between the EMC RecPoint and the PPSD RecPoint
90 // Clusters are sorted in "rows" and "columns" of width 1 cm
93 Float_t delta = 10. ; // large enough to be ineffective ??!
96 TVector3 vecEC = ec->XYZInAlice() ;
97 TVector3 vecRP = rp->XYZInAlice() ;
99 Float_t pro = TMath::Abs(1 - (vecEC * vecRP / ( vecEC.Mag() * vecRP.Mag() ))) ;
109 printf("HowClose: ec = %d, rp = %d pro = %f, toofar=%d", ec->GetIndexInList(), rp->GetIndexInList(), pro, toofar ) ;
114 //____________________________________________________________________________
115 void AliEMCALTrackSegmentMakerv1::Init()
117 // Make all memory allocations that are not possible in default constructor
119 AliEMCALGetter* gime = AliEMCALGetter::Instance(GetTitle(), fEventFolderName.Data());
121 if ( !gime->TrackSegmentMaker() ) {
122 gime->PostTrackSegmentMaker(this);
126 //____________________________________________________________________________
127 void AliEMCALTrackSegmentMakerv1::InitParameters()
130 fTrackSegmentsInRun = 0 ;
134 //____________________________________________________________________________
135 void AliEMCALTrackSegmentMakerv1::MakeLinks()const
137 // Finds distances (links) between all PRE, EC and HC clusters,
138 // which are not further apart from each other than fDangle
139 // and sort them in accordance with this distance
141 /* AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
142 TObjArray * aECARecPoints = gime->ECARecPoints() ;
143 // TObjArray * aPRERecPoints = gime->PRERecPoints() ;
144 //TObjArray * aHCARecPoints = gime->HCARecPoints() ;
146 fPRELinkArray->Clear() ;
147 fHCALinkArray->Clear() ;
149 AliEMCALTowerRecPoint * pre ;
150 AliEMCALTowerRecPoint * eca ;
151 AliEMCALTowerRecPoint * hca ;
157 for(iECARP = 0; iECARP < aECARecPoints->GetEntriesFast(); iECARP++ ) {
158 eca = dynamic_cast<AliEMCALTowerRecPoint *>(aECARecPoints->At(iECARP)) ;
159 Bool_t toofar = kTRUE ;
161 for(iPRERP = 0; iPRERP < aPRERecPoints->GetEntriesFast(); iPRERP++ ) {
162 pre = dynamic_cast<AliEMCALTowerRecPoint *>(aPRERecPoints->At(iPRERP)) ;
163 Float_t prod = HowClose(eca, pre, toofar) ;
167 new ((*fPRELinkArray)[iPRELink++]) AliEMCALLink(prod, iECARP, iPRERP, 0) ;
172 for(iHCARP = 0; iHCARP < aHCARecPoints->GetEntriesFast(); iHCARP++ ) {
173 hca = dynamic_cast<AliEMCALTowerRecPoint *>(aHCARecPoints->At(iHCARP)) ;
174 Float_t prod = HowClose(eca, hca, toofar) ;
178 new ((*fHCALinkArray)[iHCALink++]) AliEMCALLink(prod, iECARP, iHCARP, 1) ;
183 fPRELinkArray->Sort() ; //first links with largest scalar product
184 fHCALinkArray->Sort() ; //first links with largest scalar product
188 //____________________________________________________________________________
189 void AliEMCALTrackSegmentMakerv1::MakePairs()
191 // Using the previously made list of "links", we found the best link - i.e.
192 // link with the largest scalar product (closest to one) to still
193 // unassigned RecParticles. We assign these RecPoints to TrackSegment and
194 // remove them from the list of "unassigned".
196 /*AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
197 TObjArray * aECARecPoints = gime->ECARecPoints() ;
198 TObjArray * aPRERecPoints = gime->PRERecPoints() ;
199 TObjArray * aHCARecPoints = gime->HCARecPoints() ;
200 TClonesArray * trackSegments = gime->TrackSegments() ;
202 //Make arrays to mark clusters already chosen
203 Int_t * ecaExist = 0;
204 Int_t nECA = aECARecPoints->GetEntriesFast() ;
206 ecaExist = new Int_t[nECA] ;
209 for(index = 0; index < nECA; index ++)
210 ecaExist[index] = 1 ;
212 Bool_t * preExist = 0;
213 Int_t nPRE = aPRERecPoints->GetEntriesFast() ;
215 preExist = new Bool_t[nPRE] ;
216 for(index = 0; index < nPRE; index ++)
217 preExist[index] = kTRUE ;
219 Bool_t * hcaExist = 0;
220 Int_t nHCA = aHCARecPoints->GetEntriesFast() ;
222 hcaExist = new Bool_t[nHCA] ;
223 for(index = 0; index < nHCA; index ++)
224 hcaExist[index] = kTRUE ;
226 AliEMCALTowerRecPoint * null = 0 ;
227 // Finds the smallest links and makes pairs of PRE and ECAL clusters with largest scalar product
229 TIter nextPRE(fPRELinkArray) ;
230 AliEMCALLink * linkPRE ;
232 while ( (linkPRE = static_cast<AliEMCALLink *>(nextPRE()) ) ){
234 if(ecaExist[linkPRE->GetECA()] != -1){ //without PRE yet
236 if(preExist[linkPRE->GetOther()]){ // PRE still exist
238 new ((* trackSegments)[fNTrackSegments])
239 AliEMCALTrackSegment(dynamic_cast<AliEMCALTowerRecPoint *>(aECARecPoints->At(linkPRE->GetECA())) ,
240 dynamic_cast<AliEMCALTowerRecPoint *>(aPRERecPoints->At(linkPRE->GetOther())), null) ;
241 (dynamic_cast<AliEMCALTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
244 printf("MakePairs: ECAL section with PRE section") ;
245 ecaExist[linkPRE->GetECA()] = -1 ; //Mark ecal that pre was found
246 //mark PRE recpoint as already used
247 preExist[linkPRE->GetOther()] = kFALSE ;
248 } //if PRE still exist
252 // Finds the smallest links and makes pairs of HCAL and ECAL clusters with largest scalar product
254 TIter nextHCA(fHCALinkArray) ;
255 AliEMCALLink * linkHCA ;
257 while ( (linkHCA = static_cast<AliEMCALLink *>(nextHCA()) ) ){
259 if(ecaExist[linkHCA->GetECA()] != -2){ //without HCAL yet
261 if(hcaExist[linkHCA->GetOther()]){ // HCAL still exist
262 // search among the already existing track segments
264 Bool_t found = kFALSE ;
265 AliEMCALTrackSegment * ts = 0 ;
266 for ( ii = 0 ; ii < fNTrackSegments ; ii++ ) {
267 ts = dynamic_cast<AliEMCALTrackSegment *>(trackSegments->At(ii)) ;
268 if ( ts->GetECAIndex() == linkHCA->GetECA() ) {
274 ts->SetHCARecPoint( dynamic_cast<AliEMCALTowerRecPoint *>(aHCARecPoints->At(linkHCA->GetOther())) ) ;
276 printf("MakePairs: ECAL section with PRE and HCAL sections") ;
279 new ((* trackSegments)[fNTrackSegments])
280 AliEMCALTrackSegment(dynamic_cast<AliEMCALTowerRecPoint *>(aECARecPoints->At(linkHCA->GetECA())), null,
281 dynamic_cast<AliEMCALTowerRecPoint *>(aHCARecPoints->At(linkHCA->GetOther()))) ;
282 (dynamic_cast<AliEMCALTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
285 printf("MakePairs: ECAL section with HCAL section") ;
287 ecaExist[linkHCA->GetECA()] = -2 ; //Mark ecal that hcal was found
288 //mark HCAL recpoint as already used
289 hcaExist[linkHCA->GetOther()] = kFALSE ;
290 } //if HCAL still exist
295 //look through ECAL recPoints left without PRE/HCAL
296 if(ecaExist){ //if there is ecal rec point
298 for(iECARP = 0; iECARP < nECA ; iECARP++ ){
299 if(ecaExist[iECARP] > 0 ){
300 new ((*trackSegments)[fNTrackSegments])
301 AliEMCALTrackSegment(dynamic_cast<AliEMCALTowerRecPoint *>(aECARecPoints->At(iECARP)), null, null) ;
302 (dynamic_cast<AliEMCALTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
305 printf("MakePairs: ECAL section alone") ;
315 //____________________________________________________________________________
316 void AliEMCALTrackSegmentMakerv1::Exec(Option_t * option)
321 if(strstr(option,"tim"))
322 gBenchmark->Start("EMCALTSMaker");
324 if(strstr(option,"print")) {
329 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
331 Int_t nevents = gime->MaxEvent() ;
334 for(ievent = 0; ievent < nevents; ievent++){
335 gime->Event(ievent,"R") ;
336 //Make some initializations
337 fNTrackSegments = 0 ;
339 gime->TrackSegments()->Clear() ;
344 WriteTrackSegments() ;
346 if(strstr(option,"deb"))
347 PrintTrackSegments(option) ;
349 //increment the total number of track segments per run
350 fTrackSegmentsInRun += gime->TrackSegments()->GetEntriesFast() ;
354 if(strstr(option,"tim")){
355 gBenchmark->Stop("EMCALTSMaker");
356 printf("Exec: took %f seconds for making TS %f seconds per event",
357 gBenchmark->GetCpuTime("EMCALTSMaker"), gBenchmark->GetCpuTime("EMCALTSMaker")/nevents) ;
362 //____________________________________________________________________________
363 void AliEMCALTrackSegmentMakerv1::Unload()
365 // Unloads the RecPoints and Tracks
366 AliEMCALGetter * gime = AliEMCALGetter::Instance() ;
367 gime->EmcalLoader()->UnloadRecPoints() ;
368 gime->EmcalLoader()->UnloadTracks() ;
371 //____________________________________________________________________________
372 void AliEMCALTrackSegmentMakerv1::Print(Option_t * /*option*/)const
374 // Print TrackSegmentMaker parameters
376 printf("Print: TrackSegmentMakerv1 parameters:") ;
377 if( strcmp(GetName(), "") != 0 ) {
378 printf("Making Track segments with parameters:\n") ;
379 printf(" Allowed spred on the scalar product of two recpoints with same direction: %f\n", fClose) ;
380 printf("============================================\n") ;
383 printf("AliEMCALTrackSegmentMakerv1 not initialized ") ;
386 //____________________________________________________________________________
387 void AliEMCALTrackSegmentMakerv1::WriteTrackSegments()
389 // Writes found TrackSegments to TreeR. Creates branches
390 // "EMCALTS" and "AliEMCALTrackSegmentMaker" with the same title.
391 // In the former branch found TrackSegments are stored, while
392 // in the latter all parameters, with which TS were made.
393 // ROOT does not allow overwriting existing branches, therefore
394 // first we check, if branches with the same title already exist.
395 // If yes - exits without writing.
397 AliEMCALGetter *gime = AliEMCALGetter::Instance() ;
399 TClonesArray * trackSegments = gime->TrackSegments() ;
400 trackSegments->Expand(trackSegments->GetEntriesFast()) ;
402 TTree * treeT = gime->TreeT();
405 Int_t bufferSize = 32000 ;
406 TBranch * tsBranch = treeT->Branch("EMCALTS",&trackSegments,bufferSize);
409 gime->WriteTracks("OVERWRITE");
410 gime->WriteTrackSegmentMaker("OVERWRITE");
414 //____________________________________________________________________________
415 void AliEMCALTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
417 // option deb - prints # of found TrackSegments
418 // option deb all - prints as well indexed of found RecParticles assigned to the TS
420 TClonesArray * trackSegments = AliEMCALGetter::Instance()->TrackSegments() ;
423 printf("PrintTrackSegments: Results from TrackSegmentMaker:") ;
424 printf("nevent: %d\n", gAlice->GetEvNumber()) ;
425 printf(" Found %d TrackSegments\n", trackSegments->GetEntriesFast() );
427 if(strstr(option,"all")) { // printing found TS
428 printf("TrackSegment# ECAL RP# \n") ;
430 for (index = 0 ; index < fNTrackSegments ; index++) {
431 AliEMCALTrackSegment * ts = (AliEMCALTrackSegment * )trackSegments->At(index) ;
433 ts->GetIndexInList(), ts->GetECAIndex());