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 **************************************************************************/
17 /* History of cvs commits:
20 * Revision 1.80 2006/08/28 10:01:56 kharlov
21 * Effective C++ warnings fixed (Timur Pocheptsov)
23 * Revision 1.79 2006/04/25 12:41:15 hristov
24 * Moving non-persistent data to AliESDfriend (Yu.Belikov)
26 * Revision 1.78 2005/11/18 13:04:51 hristov
29 * Revision 1.77 2005/11/17 23:34:36 hristov
32 * Revision 1.76 2005/11/17 22:29:12 hristov
33 * Faster version, no attempt to match tracks outside the PHOS acceptance
35 * Revision 1.75 2005/11/17 12:35:27 hristov
36 * Use references instead of objects. Avoid to create objects when they are not really needed
38 * Revision 1.74 2005/07/08 14:01:36 hristov
39 * Tracking in non-uniform nmagnetic field (Yu.Belikov)
41 * Revision 1.73 2005/05/28 14:19:05 schutz
42 * Compilation warnings fixed by T.P.
46 //_________________________________________________________________________
47 // Implementation version 1 of algorithm class to construct PHOS track segments
48 // Track segment for PHOS is list of
49 // EMC RecPoint + (possibly) CPV RecPoint
50 // To find TrackSegments we do the following:
51 // for each EMC RecPoints we look at
52 // CPV RecPoints in the radious fRcpv.
53 // If there is such a CPV RecPoint,
54 // we make "Link" it is just indexes of EMC and CPV RecPoint and distance
55 // between them in the PHOS plane.
56 // Then we sort "Links" and starting from the
57 // least "Link" pointing to the unassined EMC and CPV RecPoints assing them to
59 // If there is no CPV RecPoint we make TrackSegment
60 // consisting from EMC alone. There is no TrackSegments without EMC RecPoint.
61 //// In principle this class should be called from AliPHOSReconstructor, but
62 // one can use it as well in standalone mode.
64 // root [0] AliPHOSTrackSegmentMakerv1 * t = new AliPHOSTrackSegmentMaker("galice.root", "tracksegmentsname", "recpointsname")
65 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
66 // // reads gAlice from header file "galice.root", uses recpoints stored in the branch names "recpointsname" (default = "Default")
67 // // and saves recpoints in branch named "tracksegmentsname" (default = "recpointsname")
68 // root [1] t->ExecuteTask()
69 // root [3] t->SetTrackSegmentsBranch("max distance 5 cm")
70 // root [4] t->ExecuteTask("deb all time")
72 //*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH) & Yves Schutz (SUBATECH)
75 // --- ROOT system ---
77 #include "TBenchmark.h"
79 // --- Standard library ---
80 #include "Riostream.h"
81 // --- AliRoot header files ---
82 #include "AliPHOSGeometry.h"
83 #include "AliPHOSTrackSegmentMakerv1.h"
84 #include "AliPHOSTrackSegment.h"
85 #include "AliPHOSLink.h"
86 #include "AliPHOSGetter.h"
88 #include "AliESDtrack.h"
90 ClassImp( AliPHOSTrackSegmentMakerv1)
93 //____________________________________________________________________________
94 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() :
95 AliPHOSTrackSegmentMaker(),
107 fTrackSegmentsInRun(0)
110 // default ctor (to be used mainly by Streamer)
114 //____________________________________________________________________________
115 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const TString & alirunFileName, const TString & eventFolderName) :
116 AliPHOSTrackSegmentMaker(alirunFileName, eventFolderName),
117 fDefaultInit(kFALSE),
128 fTrackSegmentsInRun(0)
137 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const AliPHOSTrackSegmentMakerv1 & tsm) :
138 AliPHOSTrackSegmentMaker(tsm),
139 fDefaultInit(kFALSE),
150 fTrackSegmentsInRun(0)
152 // cpy ctor: no implementation yet
153 // requested by the Coding Convention
154 Fatal("cpy ctor", "not implemented") ;
158 //____________________________________________________________________________
159 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
162 // fDefaultInit = kTRUE if TrackSegmentMaker created by default ctor (to get just the parameters)
164 delete fLinkUpArray ;
168 //____________________________________________________________________________
169 const TString AliPHOSTrackSegmentMakerv1::BranchName() const
175 //____________________________________________________________________________
176 void AliPHOSTrackSegmentMakerv1::FillOneModule()
178 // Finds first and last indexes between which
179 // clusters from one PHOS module are
181 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
183 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
184 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
187 Int_t totalEmc = emcRecPoints->GetEntriesFast() ;
188 for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&
189 ((dynamic_cast<AliPHOSRecPoint *>(emcRecPoints->At(fEmcLast)))->GetPHOSMod() == fModule );
193 Int_t totalCpv = cpvRecPoints->GetEntriesFast() ;
195 for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&
196 ((dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(fCpvLast)))->GetPHOSMod() == fModule );
201 //____________________________________________________________________________
202 Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,AliPHOSCpvRecPoint * cpvClu, Int_t &trackindex) const
204 // Calculates the distance between the EMC RecPoint and the CPV RecPoint
205 // Clusters are sorted in "rows" and "columns" of width 1 cm
207 //Float_t delta = 1 ; // Width of the rows in sorting of RecPoints (in cm)
208 // if you change this value, change it as well in xxxRecPoint::Compare()
209 Float_t distance2Cpv = fRcpv ;
210 Float_t distance2Track = fRtpc ;
212 trackindex = -1 ; // closest track within fRCpv
214 TVector3 vecEmc ; // Local position of EMC recpoint
215 TVector3 vecCpv ; // Local position of CPV recpoint propagated to EMC
216 TVector3 vecDist ; // Distance between local positions of two points
218 emcClu->GetLocalPosition(vecEmc) ;
219 cpvClu->GetLocalPosition(vecCpv) ;
222 if(emcClu->GetPHOSMod() == cpvClu->GetPHOSMod()){
224 // Find EMC-CPV distance
225 distance2Cpv = (vecCpv - vecEmc).Mag() ;
228 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
229 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
231 Double_t rPHOS = geom->GetIPtoCrystalSurface();
233 //PH Acceptance boundaries for each PHOS module
234 Int_t nModules = geom->GetNModules();
235 Double_t * thmin = new Double_t[nModules];// theta min
236 Double_t * thmax = new Double_t[nModules];// theta max
237 Double_t * phmin = new Double_t[nModules];// phi min
238 Double_t * phmax = new Double_t[nModules];// phi max
240 for (Int_t imod=0; imod<nModules; imod++) {
241 // Modules are numbered from 1 to 5 in AliPHOSGeometry
242 geom->EmcModuleCoverage(imod+1,
243 thmin[imod],thmax[imod],
244 phmin[imod],phmax[imod]);
247 // Extrapolate the global track direction if any to CPV and find the closest track
248 Int_t nTracks = fESD->GetNumberOfTracks();
249 Int_t iClosestTrack = -1;
250 Double_t minDistance = 1e6;
251 Double_t pxyz[3], xyz[3];
252 TVector3 inPHOS; //PH Used to calculate theta and phi
256 for (Int_t iTrack=0; iTrack<nTracks; iTrack++) {
257 track = fESD->GetTrack(iTrack);
258 if (!track->GetXYZAt(rPHOS, fESD->GetMagneticField(), xyz))
259 continue; //track coord on the cylinder of PHOS radius
260 if ((TMath::Abs(xyz[0])+TMath::Abs(xyz[1])+TMath::Abs(xyz[2]))<=0)
262 //PH Here one has to cut out the tracks which are not inside the PHOS
264 inPHOS.SetXYZ(xyz[0],xyz[1],xyz[2]);
265 Double_t inPhi = inPHOS.Phi();
266 Double_t inTheta = inPHOS.Theta();
269 for (Int_t imod=0; imod<nModules; imod++) {
270 //PH Loop on modules to check if the track enters in the acceptance
271 if (thmin[imod] < inTheta && thmax[imod] > inTheta &&
272 phmin[imod] < inPhi && phmax[imod] > inPhi) {
277 if (skip) continue; //PH Skip, if not in the PHOS acceptance
279 if (!track->GetPxPyPzAt(rPHOS, fESD->GetMagneticField(), pxyz))
280 continue; // track momentum ibid.
281 PropagateToPlane(vecDist,xyz,pxyz,"CPV",cpvClu->GetPHOSMod());
282 // Info("GetDistanceInPHOSPlane","Track %d propagation to CPV = (%f,%f,%f)",
283 // iTrack,vecDist.X(),vecDist.Y(),vecDist.Z());
285 distance2Track = TMath::Sqrt(vecDist.X()*vecDist.X() + vecDist.Z()*vecDist.Z());
286 // Find the closest track to the EMC recpoint
287 if (distance2Track < minDistance) {
288 minDistance = distance2Track;
289 iClosestTrack = iTrack;
298 if (iClosestTrack != -1) {
299 track = fESD->GetTrack(iClosestTrack);
300 if (track->GetPxPyPzAt(rPHOS, fESD->GetMagneticField(), pxyz)) { // track momentum ibid.
301 TVector3 vecCpvGlobal; // Global position of the CPV recpoint
302 geom->GetGlobal((AliRecPoint*)cpvClu,vecCpvGlobal);
303 for (Int_t ixyz=0; ixyz<3; ixyz++)
304 xyz[ixyz] = vecCpvGlobal[ixyz];
305 PropagateToPlane(vecDist,xyz,pxyz,"EMC",cpvClu->GetPHOSMod());
306 // Info("GetDistanceInPHOSPlane","Track %d propagation to EMC = (%f,%f,%f)",
307 // iClosestTrack,vecDist.X(),vecDist.Y(),vecDist.Z());
309 distance2Track = TMath::Sqrt(vecDist.X()*vecDist.X() + vecDist.Z()*vecDist.Z());
313 // // If no ESD exists, than simply find EMC-CPV distance
314 // distance = (vecCpv - vecEmc).Mag() ;
316 //if(distance2Track < fRcpv + 2*delta )
317 if(distance2Track < fRtpc )
318 trackindex = iClosestTrack ;
321 // Info("GetDistanceInPHOSPlane","cpv-emc distance is %f cm",
325 return distance2Cpv ;
328 //____________________________________________________________________________
329 void AliPHOSTrackSegmentMakerv1::PropagateToPlane(TVector3& globalIntersection,
333 Int_t moduleNumber) const
335 // Propagate a straight-line track from the origin point x
336 // along the direction p to the CPV or EMC module moduleNumber
337 // Returns a local position of such a propagation
339 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
340 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
341 TVector3 moduleCenter;
342 geom->GetModuleCenter(moduleCenter,det,moduleNumber);
343 TVector3 vertex; vertex.SetXYZ(x[0],x[1],x[2]);
344 TVector3 direction; direction.SetXYZ(p[0],p[1],p[2]);
346 // Info("PropagateToCPV","Center of the %s module %d is (%f,%f,%f)",
347 // det,moduleNumber,moduleCenter[0],moduleCenter[1],moduleCenter[2]);
349 Double_t time = (moduleCenter.Mag2() - vertex.Dot(moduleCenter)) /
350 (direction.Dot(moduleCenter));
351 vertex += direction*time;
352 geom->Global2Local(globalIntersection,vertex,moduleNumber);
355 //____________________________________________________________________________
356 void AliPHOSTrackSegmentMakerv1::Init()
358 // Make all memory allocations that are not possible in default constructor
360 AliPHOSGetter* gime = AliPHOSGetter::Instance();
362 gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
364 fLinkUpArray = new TClonesArray("AliPHOSLink", 1000);
365 if ( !gime->TrackSegmentMaker() ) {
366 gime->PostTrackSegmentMaker(this);
370 //____________________________________________________________________________
371 void AliPHOSTrackSegmentMakerv1::InitParameters()
373 //Initializes parameters
382 fTrackSegmentsInRun = 0 ;
383 SetEventRange(0,-1) ;
387 //____________________________________________________________________________
388 void AliPHOSTrackSegmentMakerv1::MakeLinks()const
390 // Finds distances (links) between all EMC and CPV clusters,
391 // which are not further apart from each other than fRcpv
392 // and sort them in accordance with this distance
394 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
395 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
396 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
398 fLinkUpArray->Clear() ;
400 AliPHOSCpvRecPoint * cpv ;
401 AliPHOSEmcRecPoint * emcclu ;
406 for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
407 emcclu = dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP)) ;
411 for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) {
413 cpv = dynamic_cast<AliPHOSCpvRecPoint *>(cpvRecPoints->At(iCpv)) ;
415 Float_t r = GetDistanceInPHOSPlane(emcclu, cpv, track) ;
419 new ((*fLinkUpArray)[iLinkUp++]) AliPHOSLink(r, iEmcRP, iCpv, track) ;
424 fLinkUpArray->Sort() ; //first links with smallest distances
427 //____________________________________________________________________________
428 void AliPHOSTrackSegmentMakerv1::MakePairs()
430 // Using the previously made list of "links", we found the smallest link - i.e.
431 // link with the least distance between EMC and CPV and pointing to still
432 // unassigned RecParticles. We assign these RecPoints to TrackSegment and
433 // remove them from the list of "unassigned".
435 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
437 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
438 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
439 TClonesArray * trackSegments = gime->TrackSegments();
441 //Make arrays to mark clusters already chosen
442 Int_t * emcExist = 0;
443 if(fEmcLast > fEmcFirst)
444 emcExist = new Int_t[fEmcLast-fEmcFirst] ;
447 for(index = 0; index <fEmcLast-fEmcFirst; index ++)
448 emcExist[index] = 1 ;
450 Bool_t * cpvExist = 0;
451 if(fCpvLast > fCpvFirst)
452 cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
453 for(index = 0; index <fCpvLast-fCpvFirst; index ++)
454 cpvExist[index] = kTRUE ;
457 // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance
458 TIter nextUp(fLinkUpArray) ;
460 AliPHOSLink * linkUp ;
462 AliPHOSCpvRecPoint * nullpointer = 0 ;
464 while ( (linkUp = static_cast<AliPHOSLink *>(nextUp()) ) ){
466 if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){
468 if(cpvExist[linkUp->GetCpv()-fCpvFirst]){ //CPV still exist
469 new ((* trackSegments)[fNTrackSegments])
470 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(linkUp->GetEmc())) ,
471 dynamic_cast<AliPHOSCpvRecPoint *>(cpvRecPoints->At(linkUp->GetCpv())) ,
472 linkUp->GetTrack()) ;
474 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
476 emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc that Cpv was found
477 //mark CPV recpoint as already used
478 cpvExist[linkUp->GetCpv()-fCpvFirst] = kFALSE ;
479 } //if CpvUp still exist
483 //look through emc recPoints left without CPV
484 if(emcExist){ //if there is emc rec point
486 for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst ; iEmcRP++ ){
487 if(emcExist[iEmcRP] > 0 ){
488 new ((*trackSegments)[fNTrackSegments])
489 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP+fEmcFirst)),
491 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
500 //____________________________________________________________________________
501 void AliPHOSTrackSegmentMakerv1::Exec(Option_t *option)
503 // Steering method to perform track segment construction for events
504 // in the range from fFirstEvent to fLastEvent.
505 // This range is optionally set by SetEventRange().
506 // if fLastEvent=-1 (by default), then process events until the end.
508 if(strstr(option,"tim"))
509 gBenchmark->Start("PHOSTSMaker");
511 if(strstr(option,"print")) {
516 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
518 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
520 if (fLastEvent == -1)
521 fLastEvent = gime->MaxEvent() - 1 ;
523 fLastEvent = TMath::Min(fFirstEvent,gime->MaxEvent());
524 Int_t nEvents = fLastEvent - fFirstEvent + 1;
527 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
528 gime->Event(ievent,"R") ;
529 //Make some initializations
530 fNTrackSegments = 0 ;
536 gime->TrackSegments()->Clear();
538 // if(!ReadRecPoints(ievent)) continue; //reads RecPoints for event ievent
540 for(fModule = 1; fModule <= geom->GetNModules() ; fModule++ ) {
546 WriteTrackSegments() ;
548 if(strstr(option,"deb"))
549 PrintTrackSegments(option);
551 //increment the total number of track segments per run
552 fTrackSegmentsInRun += gime->TrackSegments()->GetEntriesFast() ;
555 if(strstr(option,"tim")){
556 gBenchmark->Stop("PHOSTSMaker");
557 Info("Exec", "took %f seconds for making TS %f seconds per event",
558 gBenchmark->GetCpuTime("PHOSTSMaker"),
559 gBenchmark->GetCpuTime("PHOSTSMaker")/nEvents) ;
561 if(fWrite) //do not unload in "on flight" mode
565 //____________________________________________________________________________
566 void AliPHOSTrackSegmentMakerv1::Unload()
568 // Unloads the task from the folder
569 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
570 gime->PhosLoader()->UnloadRecPoints() ;
571 gime->PhosLoader()->UnloadTracks() ;
574 //____________________________________________________________________________
575 void AliPHOSTrackSegmentMakerv1::Print(const Option_t *)const
577 // Print TrackSegmentMaker parameters
579 TString message("") ;
580 if( strcmp(GetName(), "") != 0 ) {
581 message = "\n======== AliPHOSTrackSegmentMakerv1 ========\n" ;
582 message += "Making Track segments\n" ;
583 message += "with parameters:\n" ;
584 message += " Maximal EMC - CPV distance (cm) %f\n" ;
585 message += "============================================\n" ;
586 Info("Print", message.Data(),fRcpv) ;
589 Info("Print", "AliPHOSTrackSegmentMakerv1 not initialized ") ;
592 //____________________________________________________________________________
593 void AliPHOSTrackSegmentMakerv1::WriteTrackSegments()
595 // Writes found TrackSegments to TreeR. Creates branches
596 // "PHOSTS" and "AliPHOSTrackSegmentMaker" with the same title.
597 // In the former branch found TrackSegments are stored, while
598 // in the latter all parameters, with which TS were made.
599 // ROOT does not allow overwriting existing branches, therefore
600 // first we check, if branches with the same title already exist.
601 // If yes - exits without writing.
603 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
605 TClonesArray * trackSegments = gime->TrackSegments() ;
606 trackSegments->Expand(trackSegments->GetEntriesFast()) ;
608 if(fWrite){ //We write TreeT
609 TTree * treeT = gime->TreeT();
612 Int_t bufferSize = 32000 ;
613 TBranch * tsBranch = treeT->Branch("PHOSTS",&trackSegments,bufferSize);
616 gime->WriteTracks("OVERWRITE");
617 gime->WriteTrackSegmentMaker("OVERWRITE");
622 //____________________________________________________________________________
623 void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
625 // option deb - prints # of found TrackSegments
626 // option deb all - prints as well indexed of found RecParticles assigned to the TS
628 TClonesArray * trackSegments = AliPHOSGetter::Instance()->TrackSegments() ;
630 Info("PrintTrackSegments", "Results from TrackSegmentMaker:") ;
631 printf("nevent: %d\n", gAlice->GetEvNumber()) ;
632 printf(" Found %d TrackSegments\n", trackSegments->GetEntriesFast() );
634 if(strstr(option,"all")) { // printing found TS
635 printf("TrackSegment # EMC RP# CPV RP#\n") ;
637 for (index = 0 ; index <trackSegments->GetEntriesFast() ; index++) {
638 AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )trackSegments->At(index) ;
639 printf(" %d %d %d \n", ts->GetIndexInList(), ts->GetEmcIndex(), ts->GetCpvIndex() ) ;