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