]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PHOS/AliPHOSTrackSegmentMakerv1.cxx
Corrected copy constructor and assignment operator, fixed memory leaks (Christian)
[u/mrichter/AliRoot.git] / PHOS / AliPHOSTrackSegmentMakerv1.cxx
CommitLineData
d15a28e7 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
b2a60966 15/* $Id$ */
702ab87e 16
17/* History of cvs commits:
18 *
19 * $Log$
ddd1a39c 20 * Revision 1.90 2007/07/11 13:43:30 hristov
21 * New class AliESDEvent, backward compatibility with the old AliESD (Christian)
22 *
af885e0f 23 * Revision 1.89 2007/07/03 08:13:04 kharlov
24 * Bug fix in CPV local coordinates
25 *
b22f5347 26 * Revision 1.88 2007/06/27 09:11:07 kharlov
27 * Bug fix for CPV-EMC distance
28 *
78881c42 29 * Revision 1.87 2007/05/04 14:49:29 policheh
30 * AliPHOSRecPoint inheritance from AliCluster
31 *
9ee9f78d 32 * Revision 1.86 2007/04/02 15:00:16 cvetan
33 * No more calls to gAlice in the reconstruction
34 *
999f9a8f 35 * Revision 1.85 2007/03/28 19:18:15 kharlov
36 * RecPoints recalculation in TSM removed
37 *
8c1fb709 38 * Revision 1.84 2007/03/07 07:01:21 hristov
39 * Fixing copy/paste erro. Additional protections
40 *
b89c16b2 41 * Revision 1.83 2007/03/06 21:07:37 kharlov
42 * DP: xz CPV-EMC distance filled to TS
43 *
d7ddbb70 44 * Revision 1.82 2007/03/06 06:54:48 kharlov
45 * DP:Calculation of cluster properties dep. on vertex added
46 *
e84d3def 47 * Revision 1.81 2007/02/05 10:02:40 kharlov
48 * Module numbering is corrected
49 *
a2ee5b34 50 * Revision 1.80 2006/08/28 10:01:56 kharlov
51 * Effective C++ warnings fixed (Timur Pocheptsov)
52 *
3663622c 53 * Revision 1.79 2006/04/25 12:41:15 hristov
54 * Moving non-persistent data to AliESDfriend (Yu.Belikov)
55 *
15e85efa 56 * Revision 1.78 2005/11/18 13:04:51 hristov
57 * Bug fix
58 *
a494460a 59 * Revision 1.77 2005/11/17 23:34:36 hristov
60 * Corrected logics
61 *
f74a631d 62 * Revision 1.76 2005/11/17 22:29:12 hristov
63 * Faster version, no attempt to match tracks outside the PHOS acceptance
64 *
0d9aa319 65 * Revision 1.75 2005/11/17 12:35:27 hristov
66 * Use references instead of objects. Avoid to create objects when they are not really needed
67 *
7b51037f 68 * Revision 1.74 2005/07/08 14:01:36 hristov
69 * Tracking in non-uniform nmagnetic field (Yu.Belikov)
70 *
c84a5e9e 71 * Revision 1.73 2005/05/28 14:19:05 schutz
72 * Compilation warnings fixed by T.P.
73 *
702ab87e 74 */
75
d15a28e7 76//_________________________________________________________________________
b2a60966 77// Implementation version 1 of algorithm class to construct PHOS track segments
f035f6ce 78// Track segment for PHOS is list of
194f9939 79// EMC RecPoint + (possibly) CPV RecPoint
a4e98857 80// To find TrackSegments we do the following:
81// for each EMC RecPoints we look at
194f9939 82// CPV RecPoints in the radious fRcpv.
a4e98857 83// If there is such a CPV RecPoint,
194f9939 84// we make "Link" it is just indexes of EMC and CPV RecPoint and distance
a4e98857 85// between them in the PHOS plane.
86// Then we sort "Links" and starting from the
87// least "Link" pointing to the unassined EMC and CPV RecPoints assing them to
88// new TrackSegment.
194f9939 89// If there is no CPV RecPoint we make TrackSegment
a4e98857 90// consisting from EMC alone. There is no TrackSegments without EMC RecPoint.
f444a19f 91//// In principle this class should be called from AliPHOSReconstructor, but
a4e98857 92// one can use it as well in standalone mode.
93// Use case:
fc12304f 94// root [0] AliPHOSTrackSegmentMakerv1 * t = new AliPHOSTrackSegmentMaker("galice.root", "tracksegmentsname", "recpointsname")
a4e98857 95// Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
fc12304f 96// // reads gAlice from header file "galice.root", uses recpoints stored in the branch names "recpointsname" (default = "Default")
97// // and saves recpoints in branch named "tracksegmentsname" (default = "recpointsname")
a4e98857 98// root [1] t->ExecuteTask()
a4e98857 99// root [3] t->SetTrackSegmentsBranch("max distance 5 cm")
100// root [4] t->ExecuteTask("deb all time")
f035f6ce 101//
fc12304f 102//*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH) & Yves Schutz (SUBATECH)
b2a60966 103//
d15a28e7 104
105// --- ROOT system ---
2731cd1e 106#include "TTree.h"
2731cd1e 107#include "TBenchmark.h"
d15a28e7 108
21cd0c07 109// --- Standard library ---
194f9939 110#include "Riostream.h"
d15a28e7 111// --- AliRoot header files ---
e957fea8 112#include "AliPHOSGeometry.h"
d15a28e7 113#include "AliPHOSTrackSegmentMakerv1.h"
114#include "AliPHOSTrackSegment.h"
115#include "AliPHOSLink.h"
7b7c1533 116#include "AliPHOSGetter.h"
af885e0f 117#include "AliESDEvent.h"
aa0b9641 118#include "AliESDtrack.h"
ddd1a39c 119#include "AliPHOSQualAssDataMaker.h"
d15a28e7 120
121ClassImp( AliPHOSTrackSegmentMakerv1)
122
123
124//____________________________________________________________________________
3663622c 125AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() :
126 AliPHOSTrackSegmentMaker(),
127 fDefaultInit(kTRUE),
128 fWrite(kFALSE),
129 fNTrackSegments(0),
130 fRcpv(0.f),
131 fRtpc(0.f),
ddd1a39c 132 fVtx(0.f),
3663622c 133 fLinkUpArray(0),
134 fEmcFirst(0),
135 fEmcLast(0),
136 fCpvFirst(0),
137 fCpvLast(0),
138 fModule(0),
139 fTrackSegmentsInRun(0)
140
d15a28e7 141{
7b7c1533 142 // default ctor (to be used mainly by Streamer)
8d0f3f77 143 InitParameters() ;
d15a28e7 144}
7b7c1533 145
9f616d61 146//____________________________________________________________________________
3663622c 147AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const TString & alirunFileName, const TString & eventFolderName) :
148 AliPHOSTrackSegmentMaker(alirunFileName, eventFolderName),
149 fDefaultInit(kFALSE),
150 fWrite(kFALSE),
151 fNTrackSegments(0),
152 fRcpv(0.f),
153 fRtpc(0.f),
ddd1a39c 154 fVtx(0.f),
3663622c 155 fLinkUpArray(0),
156 fEmcFirst(0),
157 fEmcLast(0),
158 fCpvFirst(0),
159 fCpvLast(0),
160 fModule(0),
161 fTrackSegmentsInRun(0)
2731cd1e 162{
163 // ctor
8d0f3f77 164 InitParameters() ;
7b7c1533 165 Init() ;
aa0b9641 166 fESD = 0;
2731cd1e 167}
98cbd830 168
3663622c 169
170AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const AliPHOSTrackSegmentMakerv1 & tsm) :
171 AliPHOSTrackSegmentMaker(tsm),
172 fDefaultInit(kFALSE),
173 fWrite(kFALSE),
174 fNTrackSegments(0),
175 fRcpv(0.f),
176 fRtpc(0.f),
ddd1a39c 177 fVtx(0.f),
3663622c 178 fLinkUpArray(0),
179 fEmcFirst(0),
180 fEmcLast(0),
181 fCpvFirst(0),
182 fCpvLast(0),
183 fModule(0),
184 fTrackSegmentsInRun(0)
185{
186 // cpy ctor: no implementation yet
187 // requested by the Coding Convention
188 Fatal("cpy ctor", "not implemented") ;
189}
190
191
2731cd1e 192//____________________________________________________________________________
193 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
194{
195 // dtor
92f521a9 196 // fDefaultInit = kTRUE if TrackSegmentMaker created by default ctor (to get just the parameters)
88cb7938 197 if (!fDefaultInit)
198 delete fLinkUpArray ;
d15a28e7 199}
9f616d61 200
8d0f3f77 201
fc12304f 202//____________________________________________________________________________
203const TString AliPHOSTrackSegmentMakerv1::BranchName() const
204{
88cb7938 205
206 return GetName() ;
fc12304f 207}
208
d15a28e7 209//____________________________________________________________________________
2731cd1e 210void AliPHOSTrackSegmentMakerv1::FillOneModule()
9f616d61 211{
f035f6ce 212 // Finds first and last indexes between which
213 // clusters from one PHOS module are
88cb7938 214
215 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
fbf811ec 216 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
217 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
ddd1a39c 218
2731cd1e 219 //First EMC clusters
7b7c1533 220 Int_t totalEmc = emcRecPoints->GetEntriesFast() ;
2731cd1e 221 for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&
29b077b5 222 ((dynamic_cast<AliPHOSRecPoint *>(emcRecPoints->At(fEmcLast)))->GetPHOSMod() == fModule );
2731cd1e 223 fEmcLast ++) ;
224
2731cd1e 225 //Now CPV clusters
7b7c1533 226 Int_t totalCpv = cpvRecPoints->GetEntriesFast() ;
6ad0bfa0 227
2731cd1e 228 for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&
88cb7938 229 ((dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(fCpvLast)))->GetPHOSMod() == fModule );
230 fCpvLast ++) ;
9688c1dd 231
d15a28e7 232}
7b7c1533 233
d15a28e7 234//____________________________________________________________________________
e84d3def 235void AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,
236 AliPHOSCpvRecPoint * cpvClu,
237 Int_t &trackindex,
238 Float_t &dx, Float_t &dz) const
d15a28e7 239{
194f9939 240 // Calculates the distance between the EMC RecPoint and the CPV RecPoint
a4e98857 241 // Clusters are sorted in "rows" and "columns" of width 1 cm
f035f6ce 242
e84d3def 243// Float_t delta = 1 ; // Width of the rows in sorting of RecPoints (in cm)
244// // if you change this value, change it as well in xxxRecPoint::Compare()
743cb288 245 Float_t distance2Track = fRtpc ;
194f9939 246
247 trackindex = -1 ; // closest track within fRCpv
248
aa0b9641 249 TVector3 vecEmc ; // Local position of EMC recpoint
e84d3def 250 TVector3 vecP ; // Momentum direction at CPV plain
251 TVector3 vecPloc ; // Momentum direction at CPV plain
2731cd1e 252
194f9939 253 //toofar = kTRUE ;
e84d3def 254 if(emcClu->GetPHOSMod() != cpvClu->GetPHOSMod()){
255 dx=999. ;
256 dz=999. ;
257 return ;
258 }
259
260 emcClu->GetLocalPosition(vecEmc) ;
2731cd1e 261
e84d3def 262 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
263 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
194f9939 264
e84d3def 265 Double_t xCPV,zCPV ; //EMC-projected coordinates of CPV cluster
266 TVector3 cpvGlobal; // Global position of the CPV recpoint
9ee9f78d 267 geom->GetGlobalPHOS((AliPHOSRecPoint*)cpvClu,cpvGlobal);
e84d3def 268 Double_t vtxCPV[3]={cpvGlobal.X(),cpvGlobal.Y(),cpvGlobal.Z()} ;
78881c42 269 Int_t dummyMod ;
e84d3def 270
271 if (fESD == 0x0) {
272 //if no track information available, assume straight line from IP to emcal
b22f5347 273 geom->ImpactOnEmc(vtxCPV,cpvGlobal.Theta(),cpvGlobal.Phi(),dummyMod,zCPV,xCPV) ;
e84d3def 274 dx=xCPV - vecEmc.X() ;
275 dz=zCPV - vecEmc.Z() ;
276 return ;
277 }
278
279 //if there is ESD try to correct distance using TPC information on particle direct in CPV
280 if (fESD != 0x0) {
0d9aa319 281
e84d3def 282 Double_t rCPV = cpvGlobal.Pt() ;// Radius from IP to current point
283
284 // Extrapolate the global track direction if any to CPV and find the closest track
285 Int_t nTracks = fESD->GetNumberOfTracks();
286 Int_t iClosestTrack = -1;
287 Double_t minDistance = 1.e6;
288 TVector3 inPHOS ;
289
290 AliESDtrack *track;
291 Double_t xyz[3] ;
292 Double_t pxyz[3];
293 for (Int_t iTrack=0; iTrack<nTracks; iTrack++) {
294 track = fESD->GetTrack(iTrack);
295 if (!track->GetXYZAt(rCPV, fESD->GetMagneticField(), xyz))
23904d16 296 continue; //track coord on the cylinder of PHOS radius
e84d3def 297 if ((TMath::Abs(xyz[0])+TMath::Abs(xyz[1])+TMath::Abs(xyz[2]))<=0)
23904d16 298 continue;
e84d3def 299 //Check if this track hits PHOS
300 inPHOS.SetXYZ(xyz[0],xyz[1],xyz[2]);
301 distance2Track = inPHOS.Angle(cpvGlobal) ;
302 // Find the closest track to the CPV recpoint
303 if (distance2Track < minDistance) {
304 minDistance = distance2Track;
305 iClosestTrack = iTrack;
aa0b9641 306 }
e84d3def 307 }
aa0b9641 308
e84d3def 309 if (iClosestTrack != -1) {
310 track = fESD->GetTrack(iClosestTrack);
311 if (track->GetPxPyPzAt(rCPV, fESD->GetMagneticField(), pxyz)) { // track momentum ibid.
312 vecP.SetXYZ(pxyz[0],pxyz[1],pxyz[2]);
313 Int_t dummyMod ;
b22f5347 314 geom->ImpactOnEmc(vtxCPV,vecP.Theta(),vecP.Phi(),dummyMod,zCPV,xCPV) ;
aa0b9641 315 }
e84d3def 316 }
194f9939 317
e84d3def 318 if(minDistance < fRtpc ){
319 trackindex = iClosestTrack ;
aa0b9641 320 }
bfc17d18 321 }
e84d3def 322 if(trackindex!=-1){
78881c42 323 // If the closest global track is found, calculate EMC-CPV distance from it
e84d3def 324 dx=xCPV - vecEmc.X() ;
325 dz=zCPV - vecEmc.Z() ;
326 }
327 else{
78881c42 328 // If no global track was found, just take the nearest CPV point
b22f5347 329 geom->ImpactOnEmc(vtxCPV,cpvGlobal.Theta(),cpvGlobal.Phi(),dummyMod,zCPV,xCPV) ;
78881c42 330 dx=xCPV - vecEmc.X() ;
331 dz=zCPV - vecEmc.Z() ;
e84d3def 332 }
333 return ;
d15a28e7 334}
7b7c1533 335//____________________________________________________________________________
336void AliPHOSTrackSegmentMakerv1::Init()
337{
338 // Make all memory allocations that are not possible in default constructor
339
adcca1e6 340 AliPHOSGetter* gime = AliPHOSGetter::Instance();
341 if(!gime)
342 gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
fbf811ec 343
7b7c1533 344 fLinkUpArray = new TClonesArray("AliPHOSLink", 1000);
88cb7938 345 if ( !gime->TrackSegmentMaker() ) {
346 gime->PostTrackSegmentMaker(this);
347 }
7b7c1533 348}
349
8d0f3f77 350//____________________________________________________________________________
351void AliPHOSTrackSegmentMakerv1::InitParameters()
352{
e957fea8 353 //Initializes parameters
743cb288 354 fRcpv = 10. ;
355 fRtpc = 4. ;
8d0f3f77 356 fEmcFirst = 0 ;
357 fEmcLast = 0 ;
358 fCpvFirst = 0 ;
359 fCpvLast = 0 ;
360 fLinkUpArray = 0 ;
adcca1e6 361 fWrite = kTRUE ;
88cb7938 362 fTrackSegmentsInRun = 0 ;
eabde521 363 SetEventRange(0,-1) ;
8d0f3f77 364}
365
366
d15a28e7 367//____________________________________________________________________________
baef0810 368void AliPHOSTrackSegmentMakerv1::MakeLinks()const
d15a28e7 369{
194f9939 370 // Finds distances (links) between all EMC and CPV clusters,
fbf811ec 371 // which are not further apart from each other than fRcpv
f035f6ce 372 // and sort them in accordance with this distance
9688c1dd 373
88cb7938 374 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
fbf811ec 375 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
376 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
7b7c1533 377
2731cd1e 378 fLinkUpArray->Clear() ;
2731cd1e 379
2bb500e5 380 AliPHOSCpvRecPoint * cpv ;
92862013 381 AliPHOSEmcRecPoint * emcclu ;
28c3a259 382
d15a28e7 383 Int_t iLinkUp = 0 ;
384
28c3a259 385 Int_t iEmcRP;
2731cd1e 386 for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
29b077b5 387 emcclu = dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP)) ;
2731cd1e 388
194f9939 389 //Bool_t toofar ;
2731cd1e 390 Int_t iCpv = 0 ;
391 for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) {
28c3a259 392
2bb500e5 393 cpv = dynamic_cast<AliPHOSCpvRecPoint *>(cpvRecPoints->At(iCpv)) ;
194f9939 394 Int_t track = -1 ;
e84d3def 395 Float_t dx,dz ;
396 GetDistanceInPHOSPlane(emcclu, cpv, track,dx,dz) ;
397 if(TMath::Sqrt(dx*dx+dz*dz) < fRcpv ){
398 new ((*fLinkUpArray)[iLinkUp++]) AliPHOSLink(dx, dz, iEmcRP, iCpv, track) ;
28c3a259 399 }
d15a28e7 400 }
28c3a259 401 }
d15a28e7 402
9688c1dd 403 fLinkUpArray->Sort() ; //first links with smallest distances
d15a28e7 404}
28c3a259 405
d15a28e7 406//____________________________________________________________________________
2731cd1e 407void AliPHOSTrackSegmentMakerv1::MakePairs()
6ad0bfa0 408{
f035f6ce 409 // Using the previously made list of "links", we found the smallest link - i.e.
a4e98857 410 // link with the least distance between EMC and CPV and pointing to still
f035f6ce 411 // unassigned RecParticles. We assign these RecPoints to TrackSegment and
412 // remove them from the list of "unassigned".
88cb7938 413
414 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
415
fbf811ec 416 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
417 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
88cb7938 418 TClonesArray * trackSegments = gime->TrackSegments();
9688c1dd 419
01a599c9 420 //Make arrays to mark clusters already chosen
2731cd1e 421 Int_t * emcExist = 0;
422 if(fEmcLast > fEmcFirst)
423 emcExist = new Int_t[fEmcLast-fEmcFirst] ;
424
425 Int_t index;
426 for(index = 0; index <fEmcLast-fEmcFirst; index ++)
427 emcExist[index] = 1 ;
428
429 Bool_t * cpvExist = 0;
430 if(fCpvLast > fCpvFirst)
431 cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
432 for(index = 0; index <fCpvLast-fCpvFirst; index ++)
433 cpvExist[index] = kTRUE ;
434
2731cd1e 435
436 // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance
2731cd1e 437 TIter nextUp(fLinkUpArray) ;
d15a28e7 438
d15a28e7 439 AliPHOSLink * linkUp ;
9688c1dd 440
2bb500e5 441 AliPHOSCpvRecPoint * nullpointer = 0 ;
9688c1dd 442
29b077b5 443 while ( (linkUp = static_cast<AliPHOSLink *>(nextUp()) ) ){
9688c1dd 444
194f9939 445 if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){
d15a28e7 446
194f9939 447 if(cpvExist[linkUp->GetCpv()-fCpvFirst]){ //CPV still exist
d7ddbb70 448 Float_t dx,dz ;
449 linkUp->GetXZ(dx,dz) ;
194f9939 450 new ((* trackSegments)[fNTrackSegments])
451 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(linkUp->GetEmc())) ,
452 dynamic_cast<AliPHOSCpvRecPoint *>(cpvRecPoints->At(linkUp->GetCpv())) ,
d7ddbb70 453 linkUp->GetTrack(),dx,dz) ;
194f9939 454
88cb7938 455 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
456 fNTrackSegments++ ;
88cb7938 457 emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc that Cpv was found
458 //mark CPV recpoint as already used
194f9939 459 cpvExist[linkUp->GetCpv()-fCpvFirst] = kFALSE ;
460 } //if CpvUp still exist
28c3a259 461 }
88cb7938 462 }
28c3a259 463
194f9939 464 //look through emc recPoints left without CPV
2731cd1e 465 if(emcExist){ //if there is emc rec point
466 Int_t iEmcRP ;
467 for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst ; iEmcRP++ ){
468 if(emcExist[iEmcRP] > 0 ){
88cb7938 469 new ((*trackSegments)[fNTrackSegments])
470 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP+fEmcFirst)),
471 nullpointer) ;
472 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
473 fNTrackSegments++;
2731cd1e 474 }
d15a28e7 475 }
d15a28e7 476 }
780a31c1 477 delete [] emcExist ;
478 delete [] cpvExist ;
d15a28e7 479}
480
481//____________________________________________________________________________
eabde521 482void AliPHOSTrackSegmentMakerv1::Exec(Option_t *option)
d15a28e7 483{
eabde521 484 // Steering method to perform track segment construction for events
485 // in the range from fFirstEvent to fLastEvent.
486 // This range is optionally set by SetEventRange().
487 // if fLastEvent=-1 (by default), then process events until the end.
88cb7938 488
2731cd1e 489 if(strstr(option,"tim"))
b3f97575 490 gBenchmark->Start("PHOSTSMaker");
7b7c1533 491
492 if(strstr(option,"print")) {
88cb7938 493 Print() ;
7b7c1533 494 return ;
495 }
88cb7938 496
adcca1e6 497 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
fb43ada4 498
55ea5766 499 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
7b7c1533 500
0588c896 501 if (fLastEvent == -1)
502 fLastEvent = gime->MaxEvent() - 1 ;
503 else
504 fLastEvent = TMath::Min(fFirstEvent,gime->MaxEvent());
eabde521 505 Int_t nEvents = fLastEvent - fFirstEvent + 1;
01a599c9 506
fb43ada4 507 Int_t ievent ;
508 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
e84d3def 509 gime->Event(ievent,"DR") ;
0588c896 510 //Make some initializations
55ea5766 511 fNTrackSegments = 0 ;
512 fEmcFirst = 0 ;
513 fEmcLast = 0 ;
514 fCpvFirst = 0 ;
515 fCpvLast = 0 ;
88cb7938 516
517 gime->TrackSegments()->Clear();
55ea5766 518
ddd1a39c 519 // if(!ReadRecPoints(ievent)) continue; //reads RecPoints for event ievent
9688c1dd 520
88cb7938 521 for(fModule = 1; fModule <= geom->GetNModules() ; fModule++ ) {
2731cd1e 522 FillOneModule() ;
2731cd1e 523 MakeLinks() ;
2731cd1e 524 MakePairs() ;
2731cd1e 525 }
ddd1a39c 526
527
90cceaf6 528 WriteTrackSegments() ;
7b7c1533 529
2731cd1e 530 if(strstr(option,"deb"))
88cb7938 531 PrintTrackSegments(option);
94de8339 532
533 //increment the total number of track segments per run
88cb7938 534 fTrackSegmentsInRun += gime->TrackSegments()->GetEntriesFast() ;
2731cd1e 535 }
88cb7938 536
2731cd1e 537 if(strstr(option,"tim")){
538 gBenchmark->Stop("PHOSTSMaker");
21cd0c07 539 Info("Exec", "took %f seconds for making TS %f seconds per event",
88cb7938 540 gBenchmark->GetCpuTime("PHOSTSMaker"),
eabde521 541 gBenchmark->GetCpuTime("PHOSTSMaker")/nEvents) ;
88cb7938 542 }
adcca1e6 543 if(fWrite) //do not unload in "on flight" mode
544 Unload();
e84d3def 545}
88cb7938 546//____________________________________________________________________________
547void AliPHOSTrackSegmentMakerv1::Unload()
548{
e957fea8 549 // Unloads the task from the folder
88cb7938 550 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
551 gime->PhosLoader()->UnloadRecPoints() ;
552 gime->PhosLoader()->UnloadTracks() ;
d15a28e7 553}
7b7c1533 554
d15a28e7 555//____________________________________________________________________________
702ab87e 556void AliPHOSTrackSegmentMakerv1::Print(const Option_t *)const
a4e98857 557{
baef0810 558 // Print TrackSegmentMaker parameters
559
21cd0c07 560 TString message("") ;
7b7c1533 561 if( strcmp(GetName(), "") != 0 ) {
21cd0c07 562 message = "\n======== AliPHOSTrackSegmentMakerv1 ========\n" ;
563 message += "Making Track segments\n" ;
564 message += "with parameters:\n" ;
194f9939 565 message += " Maximal EMC - CPV distance (cm) %f\n" ;
21cd0c07 566 message += "============================================\n" ;
567 Info("Print", message.Data(),fRcpv) ;
2731cd1e 568 }
569 else
21cd0c07 570 Info("Print", "AliPHOSTrackSegmentMakerv1 not initialized ") ;
d15a28e7 571}
7b7c1533 572
d15a28e7 573//____________________________________________________________________________
90cceaf6 574void AliPHOSTrackSegmentMakerv1::WriteTrackSegments()
a4e98857 575{
f035f6ce 576 // Writes found TrackSegments to TreeR. Creates branches
577 // "PHOSTS" and "AliPHOSTrackSegmentMaker" with the same title.
578 // In the former branch found TrackSegments are stored, while
579 // in the latter all parameters, with which TS were made.
580 // ROOT does not allow overwriting existing branches, therefore
a4e98857 581 // first we check, if branches with the same title already exist.
f035f6ce 582 // If yes - exits without writing.
88cb7938 583
584 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
55ea5766 585
fbf811ec 586 TClonesArray * trackSegments = gime->TrackSegments() ;
55ea5766 587 trackSegments->Expand(trackSegments->GetEntriesFast()) ;
8d0f3f77 588
adcca1e6 589 if(fWrite){ //We write TreeT
590 TTree * treeT = gime->TreeT();
591
592 //First TS
593 Int_t bufferSize = 32000 ;
594 TBranch * tsBranch = treeT->Branch("PHOSTS",&trackSegments,bufferSize);
595 tsBranch->Fill() ;
596
597 gime->WriteTracks("OVERWRITE");
598 gime->WriteTrackSegmentMaker("OVERWRITE");
599 }
2731cd1e 600}
98cbd830 601
98cbd830 602
2731cd1e 603//____________________________________________________________________________
a4e98857 604void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
605{
f035f6ce 606 // option deb - prints # of found TrackSegments
607 // option deb all - prints as well indexed of found RecParticles assigned to the TS
9688c1dd 608
88cb7938 609 TClonesArray * trackSegments = AliPHOSGetter::Instance()->TrackSegments() ;
21cd0c07 610
88cb7938 611 Info("PrintTrackSegments", "Results from TrackSegmentMaker:") ;
999f9a8f 612 printf("nevent: %d\n", AliPHOSGetter::Instance()->EventNumber()) ;
88cb7938 613 printf(" Found %d TrackSegments\n", trackSegments->GetEntriesFast() );
614
2731cd1e 615 if(strstr(option,"all")) { // printing found TS
88cb7938 616 printf("TrackSegment # EMC RP# CPV RP#\n") ;
2731cd1e 617 Int_t index;
7b7c1533 618 for (index = 0 ; index <trackSegments->GetEntriesFast() ; index++) {
619 AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )trackSegments->At(index) ;
88cb7938 620 printf(" %d %d %d \n", ts->GetIndexInList(), ts->GetEmcIndex(), ts->GetCpvIndex() ) ;
2731cd1e 621 }
d15a28e7 622 }
2731cd1e 623}