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