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.92 2007/08/28 12:55:08 policheh
21 * Loaders removed from the reconstruction code (C.Cheshkov)
23 * Revision 1.91 2007/08/07 14:12:03 kharlov
24 * Quality assurance added (Yves Schutz)
26 * Revision 1.90 2007/07/11 13:43:30 hristov
27 * New class AliESDEvent, backward compatibility with the old AliESD (Christian)
29 * Revision 1.89 2007/07/03 08:13:04 kharlov
30 * Bug fix in CPV local coordinates
32 * Revision 1.88 2007/06/27 09:11:07 kharlov
33 * Bug fix for CPV-EMC distance
35 * Revision 1.87 2007/05/04 14:49:29 policheh
36 * AliPHOSRecPoint inheritance from AliCluster
38 * Revision 1.86 2007/04/02 15:00:16 cvetan
39 * No more calls to gAlice in the reconstruction
41 * Revision 1.85 2007/03/28 19:18:15 kharlov
42 * RecPoints recalculation in TSM removed
44 * Revision 1.84 2007/03/07 07:01:21 hristov
45 * Fixing copy/paste erro. Additional protections
47 * Revision 1.83 2007/03/06 21:07:37 kharlov
48 * DP: xz CPV-EMC distance filled to TS
50 * Revision 1.82 2007/03/06 06:54:48 kharlov
51 * DP:Calculation of cluster properties dep. on vertex added
53 * Revision 1.81 2007/02/05 10:02:40 kharlov
54 * Module numbering is corrected
56 * Revision 1.80 2006/08/28 10:01:56 kharlov
57 * Effective C++ warnings fixed (Timur Pocheptsov)
59 * Revision 1.79 2006/04/25 12:41:15 hristov
60 * Moving non-persistent data to AliESDfriend (Yu.Belikov)
62 * Revision 1.78 2005/11/18 13:04:51 hristov
65 * Revision 1.77 2005/11/17 23:34:36 hristov
68 * Revision 1.76 2005/11/17 22:29:12 hristov
69 * Faster version, no attempt to match tracks outside the PHOS acceptance
71 * Revision 1.75 2005/11/17 12:35:27 hristov
72 * Use references instead of objects. Avoid to create objects when they are not really needed
74 * Revision 1.74 2005/07/08 14:01:36 hristov
75 * Tracking in non-uniform nmagnetic field (Yu.Belikov)
77 * Revision 1.73 2005/05/28 14:19:05 schutz
78 * Compilation warnings fixed by T.P.
82 //_________________________________________________________________________
83 // Implementation version 1 of algorithm class to construct PHOS track segments
84 // Track segment for PHOS is list of
85 // EMC RecPoint + (possibly) CPV RecPoint
86 // To find TrackSegments we do the following:
87 // for each EMC RecPoints we look at
88 // CPV RecPoints in the radious fRcpv.
89 // If there is such a CPV RecPoint,
90 // we make "Link" it is just indexes of EMC and CPV RecPoint and distance
91 // between them in the PHOS plane.
92 // Then we sort "Links" and starting from the
93 // least "Link" pointing to the unassined EMC and CPV RecPoints assing them to
95 // If there is no CPV RecPoint we make TrackSegment
96 // consisting from EMC alone. There is no TrackSegments without EMC RecPoint.
97 //// In principle this class should be called from AliPHOSReconstructor, but
98 // one can use it as well in standalone mode.
100 // root [0] AliPHOSTrackSegmentMakerv1 * t = new AliPHOSTrackSegmentMaker("galice.root", "tracksegmentsname", "recpointsname")
101 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
102 // // reads gAlice from header file "galice.root", uses recpoints stored in the branch names "recpointsname" (default = "Default")
103 // // and saves recpoints in branch named "tracksegmentsname" (default = "recpointsname")
104 // root [1] t->ExecuteTask()
105 // root [3] t->SetTrackSegmentsBranch("max distance 5 cm")
106 // root [4] t->ExecuteTask("deb all time")
108 //*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH) & Yves Schutz (SUBATECH)
111 // --- ROOT system ---
113 #include "TBenchmark.h"
115 // --- Standard library ---
116 #include "Riostream.h"
117 // --- AliRoot header files ---
118 #include "AliPHOSGeometry.h"
119 #include "AliPHOSTrackSegmentMakerv1.h"
120 #include "AliPHOSTrackSegment.h"
121 #include "AliPHOSLink.h"
122 #include "AliESDEvent.h"
123 #include "AliESDtrack.h"
124 #include "AliPHOSQADataMaker.h"
125 #include "AliPHOSEmcRecPoint.h"
126 #include "AliPHOSCpvRecPoint.h"
128 ClassImp( AliPHOSTrackSegmentMakerv1)
131 //____________________________________________________________________________
132 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() :
133 AliPHOSTrackSegmentMaker(),
148 // default ctor (to be used mainly by Streamer)
152 //____________________________________________________________________________
153 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(AliPHOSGeometry *geom) :
154 AliPHOSTrackSegmentMaker(geom),
155 fDefaultInit(kFALSE),
176 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const AliPHOSTrackSegmentMakerv1 & tsm) :
177 AliPHOSTrackSegmentMaker(tsm),
178 fDefaultInit(kFALSE),
192 // cpy ctor: no implementation yet
193 // requested by the Coding Convention
194 Fatal("cpy ctor", "not implemented") ;
198 //____________________________________________________________________________
199 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
202 // fDefaultInit = kTRUE if TrackSegmentMaker created by default ctor (to get just the parameters)
204 delete fLinkUpArray ;
205 if (fTrackSegments) {
206 fTrackSegments->Delete();
207 delete fTrackSegments;
211 //____________________________________________________________________________
212 void AliPHOSTrackSegmentMakerv1::FillOneModule()
214 // Finds first and last indexes between which
215 // clusters from one PHOS module are
218 Int_t totalEmc = fEMCRecPoints->GetEntriesFast() ;
219 for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&
220 ((dynamic_cast<AliPHOSRecPoint *>(fEMCRecPoints->At(fEmcLast)))->GetPHOSMod() == fModule );
224 Int_t totalCpv = fCPVRecPoints->GetEntriesFast() ;
226 for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&
227 ((dynamic_cast<AliPHOSRecPoint *>(fCPVRecPoints->At(fCpvLast)))->GetPHOSMod() == fModule );
232 //____________________________________________________________________________
233 void AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,
234 AliPHOSCpvRecPoint * cpvClu,
236 Float_t &dx, Float_t &dz) const
238 // Calculates the distance between the EMC RecPoint and the CPV RecPoint
239 // Clusters are sorted in "rows" and "columns" of width 1 cm
241 // Float_t delta = 1 ; // Width of the rows in sorting of RecPoints (in cm)
242 // // if you change this value, change it as well in xxxRecPoint::Compare()
243 Float_t distance2Track = fRtpc ;
245 trackindex = -1 ; // closest track within fRCpv
247 TVector3 vecEmc ; // Local position of EMC recpoint
248 TVector3 vecP ; // Momentum direction at CPV plain
249 TVector3 vecPloc ; // Momentum direction at CPV plain
252 if(emcClu->GetPHOSMod() != cpvClu->GetPHOSMod()){
258 emcClu->GetLocalPosition(vecEmc) ;
260 Double_t xCPV,zCPV ; //EMC-projected coordinates of CPV cluster
261 TVector3 cpvGlobal; // Global position of the CPV recpoint
262 fGeom->GetGlobalPHOS((AliPHOSRecPoint*)cpvClu,cpvGlobal);
263 Double_t vtxCPV[3]={cpvGlobal.X(),cpvGlobal.Y(),cpvGlobal.Z()} ;
267 //if no track information available, assume straight line from IP to emcal
268 fGeom->ImpactOnEmc(vtxCPV,cpvGlobal.Theta(),cpvGlobal.Phi(),dummyMod,zCPV,xCPV) ;
269 dx=xCPV - vecEmc.X() ;
270 dz=zCPV - vecEmc.Z() ;
274 //if there is ESD try to correct distance using TPC information on particle direct in CPV
277 Double_t rCPV = cpvGlobal.Pt() ;// Radius from IP to current point
279 // Extrapolate the global track direction if any to CPV and find the closest track
280 Int_t nTracks = fESD->GetNumberOfTracks();
281 Int_t iClosestTrack = -1;
282 Double_t minDistance = 1.e6;
288 for (Int_t iTrack=0; iTrack<nTracks; iTrack++) {
289 track = fESD->GetTrack(iTrack);
290 if (!track->GetXYZAt(rCPV, fESD->GetMagneticField(), xyz))
291 continue; //track coord on the cylinder of PHOS radius
292 if ((TMath::Abs(xyz[0])+TMath::Abs(xyz[1])+TMath::Abs(xyz[2]))<=0)
294 //Check if this track hits PHOS
295 inPHOS.SetXYZ(xyz[0],xyz[1],xyz[2]);
296 distance2Track = inPHOS.Angle(cpvGlobal) ;
297 // Find the closest track to the CPV recpoint
298 if (distance2Track < minDistance) {
299 minDistance = distance2Track;
300 iClosestTrack = iTrack;
304 if (iClosestTrack != -1) {
305 track = fESD->GetTrack(iClosestTrack);
306 if (track->GetPxPyPzAt(rCPV, fESD->GetMagneticField(), pxyz)) { // track momentum ibid.
307 vecP.SetXYZ(pxyz[0],pxyz[1],pxyz[2]);
309 fGeom->ImpactOnEmc(vtxCPV,vecP.Theta(),vecP.Phi(),dummyMod,zCPV,xCPV) ;
313 if(minDistance < fRtpc ){
314 trackindex = iClosestTrack ;
318 // If the closest global track is found, calculate EMC-CPV distance from it
319 dx=xCPV - vecEmc.X() ;
320 dz=zCPV - vecEmc.Z() ;
323 // If no global track was found, just take the nearest CPV point
324 fGeom->ImpactOnEmc(vtxCPV,cpvGlobal.Theta(),cpvGlobal.Phi(),dummyMod,zCPV,xCPV) ;
325 dx=xCPV - vecEmc.X() ;
326 dz=zCPV - vecEmc.Z() ;
330 //____________________________________________________________________________
331 void AliPHOSTrackSegmentMakerv1::Init()
333 // Make all memory allocations that are not possible in default constructor
335 fLinkUpArray = new TClonesArray("AliPHOSLink", 1000);
336 fTrackSegments = new TClonesArray("AliPHOSTrackSegment",100);
337 fTrackSegments->SetName("TRACKS");
340 //____________________________________________________________________________
341 void AliPHOSTrackSegmentMakerv1::InitParameters()
343 //Initializes parameters
355 //____________________________________________________________________________
356 void AliPHOSTrackSegmentMakerv1::MakeLinks()const
358 // Finds distances (links) between all EMC and CPV clusters,
359 // which are not further apart from each other than fRcpv
360 // and sort them in accordance with this distance
362 fLinkUpArray->Clear() ;
364 AliPHOSCpvRecPoint * cpv ;
365 AliPHOSEmcRecPoint * emcclu ;
370 for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
371 emcclu = dynamic_cast<AliPHOSEmcRecPoint *>(fEMCRecPoints->At(iEmcRP)) ;
375 for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) {
377 cpv = dynamic_cast<AliPHOSCpvRecPoint *>(fCPVRecPoints->At(iCpv)) ;
380 GetDistanceInPHOSPlane(emcclu, cpv, track,dx,dz) ;
381 if(TMath::Sqrt(dx*dx+dz*dz) < fRcpv ){
382 new ((*fLinkUpArray)[iLinkUp++]) AliPHOSLink(dx, dz, iEmcRP, iCpv, track) ;
387 fLinkUpArray->Sort() ; //first links with smallest distances
390 //____________________________________________________________________________
391 void AliPHOSTrackSegmentMakerv1::MakePairs()
393 // Using the previously made list of "links", we found the smallest link - i.e.
394 // link with the least distance between EMC and CPV and pointing to still
395 // unassigned RecParticles. We assign these RecPoints to TrackSegment and
396 // remove them from the list of "unassigned".
398 //Make arrays to mark clusters already chosen
399 Int_t * emcExist = 0;
400 if(fEmcLast > fEmcFirst)
401 emcExist = new Int_t[fEmcLast-fEmcFirst] ;
404 for(index = 0; index <fEmcLast-fEmcFirst; index ++)
405 emcExist[index] = 1 ;
407 Bool_t * cpvExist = 0;
408 if(fCpvLast > fCpvFirst)
409 cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
410 for(index = 0; index <fCpvLast-fCpvFirst; index ++)
411 cpvExist[index] = kTRUE ;
414 // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance
415 TIter nextUp(fLinkUpArray) ;
417 AliPHOSLink * linkUp ;
419 AliPHOSCpvRecPoint * nullpointer = 0 ;
421 while ( (linkUp = static_cast<AliPHOSLink *>(nextUp()) ) ){
423 if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){
425 if(cpvExist[linkUp->GetCpv()-fCpvFirst]){ //CPV still exist
427 linkUp->GetXZ(dx,dz) ;
428 new ((* fTrackSegments)[fNTrackSegments])
429 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(fEMCRecPoints->At(linkUp->GetEmc())) ,
430 dynamic_cast<AliPHOSCpvRecPoint *>(fCPVRecPoints->At(linkUp->GetCpv())) ,
431 linkUp->GetTrack(),dx,dz) ;
433 (dynamic_cast<AliPHOSTrackSegment *>(fTrackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
435 emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc that Cpv was found
436 //mark CPV recpoint as already used
437 cpvExist[linkUp->GetCpv()-fCpvFirst] = kFALSE ;
438 } //if CpvUp still exist
442 //look through emc recPoints left without CPV
443 if(emcExist){ //if there is emc rec point
445 for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst ; iEmcRP++ ){
446 if(emcExist[iEmcRP] > 0 ){
447 new ((*fTrackSegments)[fNTrackSegments])
448 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(fEMCRecPoints->At(iEmcRP+fEmcFirst)),
450 (dynamic_cast<AliPHOSTrackSegment *>(fTrackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
459 //____________________________________________________________________________
460 void AliPHOSTrackSegmentMakerv1::Clusters2TrackSegments(Option_t *option)
462 // Steering method to perform track segment construction for the current event
463 // Returns an array with the found track-segments.
465 if(strstr(option,"tim"))
466 gBenchmark->Start("PHOSTSMaker");
468 if(strstr(option,"print")) {
473 //Make some initializations
474 fNTrackSegments = 0 ;
480 fTrackSegments->Clear();
482 // if(!ReadRecPoints(ievent)) continue; //reads RecPoints for event ievent
484 for(fModule = 1; fModule <= fGeom->GetNModules() ; fModule++ ) {
490 if(strstr(option,"deb"))
491 PrintTrackSegments(option);
493 if(strstr(option,"tim")){
494 gBenchmark->Stop("PHOSTSMaker");
495 Info("Exec", "took %f seconds for making TS",
496 gBenchmark->GetCpuTime("PHOSTSMaker"));
500 //____________________________________________________________________________
501 void AliPHOSTrackSegmentMakerv1::Print(const Option_t *)const
503 // Print TrackSegmentMaker parameters
505 TString message("") ;
506 if( strcmp(GetName(), "") != 0 ) {
507 message = "\n======== AliPHOSTrackSegmentMakerv1 ========\n" ;
508 message += "Making Track segments\n" ;
509 message += "with parameters:\n" ;
510 message += " Maximal EMC - CPV distance (cm) %f\n" ;
511 message += "============================================\n" ;
512 Info("Print", message.Data(),fRcpv) ;
515 Info("Print", "AliPHOSTrackSegmentMakerv1 not initialized ") ;
518 //____________________________________________________________________________
519 void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
521 // option deb - prints # of found TrackSegments
522 // option deb all - prints as well indexed of found RecParticles assigned to the TS
524 Info("PrintTrackSegments", "Results from TrackSegmentMaker:") ;
525 printf(" Found %d TrackSegments\n", fTrackSegments->GetEntriesFast() );
527 if(strstr(option,"all")) { // printing found TS
528 printf("TrackSegment # EMC RP# CPV RP#\n") ;
530 for (index = 0 ; index <fTrackSegments->GetEntriesFast() ; index++) {
531 AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )fTrackSegments->At(index) ;
532 printf(" %d %d %d \n", ts->GetIndexInList(), ts->GetEmcIndex(), ts->GetCpvIndex() ) ;