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.91 2007/08/07 14:12:03 kharlov
21 * Quality assurance added (Yves Schutz)
23 * Revision 1.90 2007/07/11 13:43:30 hristov
24 * New class AliESDEvent, backward compatibility with the old AliESD (Christian)
26 * Revision 1.89 2007/07/03 08:13:04 kharlov
27 * Bug fix in CPV local coordinates
29 * Revision 1.88 2007/06/27 09:11:07 kharlov
30 * Bug fix for CPV-EMC distance
32 * Revision 1.87 2007/05/04 14:49:29 policheh
33 * AliPHOSRecPoint inheritance from AliCluster
35 * Revision 1.86 2007/04/02 15:00:16 cvetan
36 * No more calls to gAlice in the reconstruction
38 * Revision 1.85 2007/03/28 19:18:15 kharlov
39 * RecPoints recalculation in TSM removed
41 * Revision 1.84 2007/03/07 07:01:21 hristov
42 * Fixing copy/paste erro. Additional protections
44 * Revision 1.83 2007/03/06 21:07:37 kharlov
45 * DP: xz CPV-EMC distance filled to TS
47 * Revision 1.82 2007/03/06 06:54:48 kharlov
48 * DP:Calculation of cluster properties dep. on vertex added
50 * Revision 1.81 2007/02/05 10:02:40 kharlov
51 * Module numbering is corrected
53 * Revision 1.80 2006/08/28 10:01:56 kharlov
54 * Effective C++ warnings fixed (Timur Pocheptsov)
56 * Revision 1.79 2006/04/25 12:41:15 hristov
57 * Moving non-persistent data to AliESDfriend (Yu.Belikov)
59 * Revision 1.78 2005/11/18 13:04:51 hristov
62 * Revision 1.77 2005/11/17 23:34:36 hristov
65 * Revision 1.76 2005/11/17 22:29:12 hristov
66 * Faster version, no attempt to match tracks outside the PHOS acceptance
68 * Revision 1.75 2005/11/17 12:35:27 hristov
69 * Use references instead of objects. Avoid to create objects when they are not really needed
71 * Revision 1.74 2005/07/08 14:01:36 hristov
72 * Tracking in non-uniform nmagnetic field (Yu.Belikov)
74 * Revision 1.73 2005/05/28 14:19:05 schutz
75 * Compilation warnings fixed by T.P.
79 //_________________________________________________________________________
80 // Implementation version 1 of algorithm class to construct PHOS track segments
81 // Track segment for PHOS is list of
82 // EMC RecPoint + (possibly) CPV RecPoint
83 // To find TrackSegments we do the following:
84 // for each EMC RecPoints we look at
85 // CPV RecPoints in the radious fRcpv.
86 // If there is such a CPV RecPoint,
87 // we make "Link" it is just indexes of EMC and CPV RecPoint and distance
88 // between them in the PHOS plane.
89 // Then we sort "Links" and starting from the
90 // least "Link" pointing to the unassined EMC and CPV RecPoints assing them to
92 // If there is no CPV RecPoint we make TrackSegment
93 // consisting from EMC alone. There is no TrackSegments without EMC RecPoint.
94 //// In principle this class should be called from AliPHOSReconstructor, but
95 // one can use it as well in standalone mode.
97 // root [0] AliPHOSTrackSegmentMakerv1 * t = new AliPHOSTrackSegmentMaker("galice.root", "tracksegmentsname", "recpointsname")
98 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
99 // // reads gAlice from header file "galice.root", uses recpoints stored in the branch names "recpointsname" (default = "Default")
100 // // and saves recpoints in branch named "tracksegmentsname" (default = "recpointsname")
101 // root [1] t->ExecuteTask()
102 // root [3] t->SetTrackSegmentsBranch("max distance 5 cm")
103 // root [4] t->ExecuteTask("deb all time")
105 //*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH) & Yves Schutz (SUBATECH)
108 // --- ROOT system ---
110 #include "TBenchmark.h"
112 // --- Standard library ---
113 #include "Riostream.h"
114 // --- AliRoot header files ---
115 #include "AliPHOSGeometry.h"
116 #include "AliPHOSTrackSegmentMakerv1.h"
117 #include "AliPHOSTrackSegment.h"
118 #include "AliPHOSLink.h"
119 #include "AliESDEvent.h"
120 #include "AliESDtrack.h"
121 #include "AliPHOSQualAssDataMaker.h"
122 #include "AliPHOSEmcRecPoint.h"
123 #include "AliPHOSCpvRecPoint.h"
125 ClassImp( AliPHOSTrackSegmentMakerv1)
128 //____________________________________________________________________________
129 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() :
130 AliPHOSTrackSegmentMaker(),
145 // default ctor (to be used mainly by Streamer)
149 //____________________________________________________________________________
150 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(AliPHOSGeometry *geom) :
151 AliPHOSTrackSegmentMaker(geom),
152 fDefaultInit(kFALSE),
173 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const AliPHOSTrackSegmentMakerv1 & tsm) :
174 AliPHOSTrackSegmentMaker(tsm),
175 fDefaultInit(kFALSE),
189 // cpy ctor: no implementation yet
190 // requested by the Coding Convention
191 Fatal("cpy ctor", "not implemented") ;
195 //____________________________________________________________________________
196 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
199 // fDefaultInit = kTRUE if TrackSegmentMaker created by default ctor (to get just the parameters)
201 delete fLinkUpArray ;
202 if (fTrackSegments) {
203 fTrackSegments->Delete();
204 delete fTrackSegments;
208 //____________________________________________________________________________
209 void AliPHOSTrackSegmentMakerv1::FillOneModule()
211 // Finds first and last indexes between which
212 // clusters from one PHOS module are
215 Int_t totalEmc = fEMCRecPoints->GetEntriesFast() ;
216 for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&
217 ((dynamic_cast<AliPHOSRecPoint *>(fEMCRecPoints->At(fEmcLast)))->GetPHOSMod() == fModule );
221 Int_t totalCpv = fCPVRecPoints->GetEntriesFast() ;
223 for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&
224 ((dynamic_cast<AliPHOSRecPoint *>(fCPVRecPoints->At(fCpvLast)))->GetPHOSMod() == fModule );
229 //____________________________________________________________________________
230 void AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,
231 AliPHOSCpvRecPoint * cpvClu,
233 Float_t &dx, Float_t &dz) const
235 // Calculates the distance between the EMC RecPoint and the CPV RecPoint
236 // Clusters are sorted in "rows" and "columns" of width 1 cm
238 // Float_t delta = 1 ; // Width of the rows in sorting of RecPoints (in cm)
239 // // if you change this value, change it as well in xxxRecPoint::Compare()
240 Float_t distance2Track = fRtpc ;
242 trackindex = -1 ; // closest track within fRCpv
244 TVector3 vecEmc ; // Local position of EMC recpoint
245 TVector3 vecP ; // Momentum direction at CPV plain
246 TVector3 vecPloc ; // Momentum direction at CPV plain
249 if(emcClu->GetPHOSMod() != cpvClu->GetPHOSMod()){
255 emcClu->GetLocalPosition(vecEmc) ;
257 Double_t xCPV,zCPV ; //EMC-projected coordinates of CPV cluster
258 TVector3 cpvGlobal; // Global position of the CPV recpoint
259 fGeom->GetGlobalPHOS((AliPHOSRecPoint*)cpvClu,cpvGlobal);
260 Double_t vtxCPV[3]={cpvGlobal.X(),cpvGlobal.Y(),cpvGlobal.Z()} ;
264 //if no track information available, assume straight line from IP to emcal
265 fGeom->ImpactOnEmc(vtxCPV,cpvGlobal.Theta(),cpvGlobal.Phi(),dummyMod,zCPV,xCPV) ;
266 dx=xCPV - vecEmc.X() ;
267 dz=zCPV - vecEmc.Z() ;
271 //if there is ESD try to correct distance using TPC information on particle direct in CPV
274 Double_t rCPV = cpvGlobal.Pt() ;// Radius from IP to current point
276 // Extrapolate the global track direction if any to CPV and find the closest track
277 Int_t nTracks = fESD->GetNumberOfTracks();
278 Int_t iClosestTrack = -1;
279 Double_t minDistance = 1.e6;
285 for (Int_t iTrack=0; iTrack<nTracks; iTrack++) {
286 track = fESD->GetTrack(iTrack);
287 if (!track->GetXYZAt(rCPV, fESD->GetMagneticField(), xyz))
288 continue; //track coord on the cylinder of PHOS radius
289 if ((TMath::Abs(xyz[0])+TMath::Abs(xyz[1])+TMath::Abs(xyz[2]))<=0)
291 //Check if this track hits PHOS
292 inPHOS.SetXYZ(xyz[0],xyz[1],xyz[2]);
293 distance2Track = inPHOS.Angle(cpvGlobal) ;
294 // Find the closest track to the CPV recpoint
295 if (distance2Track < minDistance) {
296 minDistance = distance2Track;
297 iClosestTrack = iTrack;
301 if (iClosestTrack != -1) {
302 track = fESD->GetTrack(iClosestTrack);
303 if (track->GetPxPyPzAt(rCPV, fESD->GetMagneticField(), pxyz)) { // track momentum ibid.
304 vecP.SetXYZ(pxyz[0],pxyz[1],pxyz[2]);
306 fGeom->ImpactOnEmc(vtxCPV,vecP.Theta(),vecP.Phi(),dummyMod,zCPV,xCPV) ;
310 if(minDistance < fRtpc ){
311 trackindex = iClosestTrack ;
315 // If the closest global track is found, calculate EMC-CPV distance from it
316 dx=xCPV - vecEmc.X() ;
317 dz=zCPV - vecEmc.Z() ;
320 // If no global track was found, just take the nearest CPV point
321 fGeom->ImpactOnEmc(vtxCPV,cpvGlobal.Theta(),cpvGlobal.Phi(),dummyMod,zCPV,xCPV) ;
322 dx=xCPV - vecEmc.X() ;
323 dz=zCPV - vecEmc.Z() ;
327 //____________________________________________________________________________
328 void AliPHOSTrackSegmentMakerv1::Init()
330 // Make all memory allocations that are not possible in default constructor
332 fLinkUpArray = new TClonesArray("AliPHOSLink", 1000);
333 fTrackSegments = new TClonesArray("AliPHOSTrackSegment",100);
334 fTrackSegments->SetName("TRACKS");
337 //____________________________________________________________________________
338 void AliPHOSTrackSegmentMakerv1::InitParameters()
340 //Initializes parameters
352 //____________________________________________________________________________
353 void AliPHOSTrackSegmentMakerv1::MakeLinks()const
355 // Finds distances (links) between all EMC and CPV clusters,
356 // which are not further apart from each other than fRcpv
357 // and sort them in accordance with this distance
359 fLinkUpArray->Clear() ;
361 AliPHOSCpvRecPoint * cpv ;
362 AliPHOSEmcRecPoint * emcclu ;
367 for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
368 emcclu = dynamic_cast<AliPHOSEmcRecPoint *>(fEMCRecPoints->At(iEmcRP)) ;
372 for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) {
374 cpv = dynamic_cast<AliPHOSCpvRecPoint *>(fCPVRecPoints->At(iCpv)) ;
377 GetDistanceInPHOSPlane(emcclu, cpv, track,dx,dz) ;
378 if(TMath::Sqrt(dx*dx+dz*dz) < fRcpv ){
379 new ((*fLinkUpArray)[iLinkUp++]) AliPHOSLink(dx, dz, iEmcRP, iCpv, track) ;
384 fLinkUpArray->Sort() ; //first links with smallest distances
387 //____________________________________________________________________________
388 void AliPHOSTrackSegmentMakerv1::MakePairs()
390 // Using the previously made list of "links", we found the smallest link - i.e.
391 // link with the least distance between EMC and CPV and pointing to still
392 // unassigned RecParticles. We assign these RecPoints to TrackSegment and
393 // remove them from the list of "unassigned".
395 //Make arrays to mark clusters already chosen
396 Int_t * emcExist = 0;
397 if(fEmcLast > fEmcFirst)
398 emcExist = new Int_t[fEmcLast-fEmcFirst] ;
401 for(index = 0; index <fEmcLast-fEmcFirst; index ++)
402 emcExist[index] = 1 ;
404 Bool_t * cpvExist = 0;
405 if(fCpvLast > fCpvFirst)
406 cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
407 for(index = 0; index <fCpvLast-fCpvFirst; index ++)
408 cpvExist[index] = kTRUE ;
411 // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance
412 TIter nextUp(fLinkUpArray) ;
414 AliPHOSLink * linkUp ;
416 AliPHOSCpvRecPoint * nullpointer = 0 ;
418 while ( (linkUp = static_cast<AliPHOSLink *>(nextUp()) ) ){
420 if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){
422 if(cpvExist[linkUp->GetCpv()-fCpvFirst]){ //CPV still exist
424 linkUp->GetXZ(dx,dz) ;
425 new ((* fTrackSegments)[fNTrackSegments])
426 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(fEMCRecPoints->At(linkUp->GetEmc())) ,
427 dynamic_cast<AliPHOSCpvRecPoint *>(fCPVRecPoints->At(linkUp->GetCpv())) ,
428 linkUp->GetTrack(),dx,dz) ;
430 (dynamic_cast<AliPHOSTrackSegment *>(fTrackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
432 emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc that Cpv was found
433 //mark CPV recpoint as already used
434 cpvExist[linkUp->GetCpv()-fCpvFirst] = kFALSE ;
435 } //if CpvUp still exist
439 //look through emc recPoints left without CPV
440 if(emcExist){ //if there is emc rec point
442 for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst ; iEmcRP++ ){
443 if(emcExist[iEmcRP] > 0 ){
444 new ((*fTrackSegments)[fNTrackSegments])
445 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(fEMCRecPoints->At(iEmcRP+fEmcFirst)),
447 (dynamic_cast<AliPHOSTrackSegment *>(fTrackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
456 //____________________________________________________________________________
457 void AliPHOSTrackSegmentMakerv1::Clusters2TrackSegments(Option_t *option)
459 // Steering method to perform track segment construction for the current event
460 // Returns an array with the found track-segments.
462 if(strstr(option,"tim"))
463 gBenchmark->Start("PHOSTSMaker");
465 if(strstr(option,"print")) {
470 //Make some initializations
471 fNTrackSegments = 0 ;
477 fTrackSegments->Clear();
479 // if(!ReadRecPoints(ievent)) continue; //reads RecPoints for event ievent
481 for(fModule = 1; fModule <= fGeom->GetNModules() ; fModule++ ) {
487 if(strstr(option,"deb"))
488 PrintTrackSegments(option);
490 if(strstr(option,"tim")){
491 gBenchmark->Stop("PHOSTSMaker");
492 Info("Exec", "took %f seconds for making TS",
493 gBenchmark->GetCpuTime("PHOSTSMaker"));
497 //____________________________________________________________________________
498 void AliPHOSTrackSegmentMakerv1::Print(const Option_t *)const
500 // Print TrackSegmentMaker parameters
502 TString message("") ;
503 if( strcmp(GetName(), "") != 0 ) {
504 message = "\n======== AliPHOSTrackSegmentMakerv1 ========\n" ;
505 message += "Making Track segments\n" ;
506 message += "with parameters:\n" ;
507 message += " Maximal EMC - CPV distance (cm) %f\n" ;
508 message += "============================================\n" ;
509 Info("Print", message.Data(),fRcpv) ;
512 Info("Print", "AliPHOSTrackSegmentMakerv1 not initialized ") ;
515 //____________________________________________________________________________
516 void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
518 // option deb - prints # of found TrackSegments
519 // option deb all - prints as well indexed of found RecParticles assigned to the TS
521 Info("PrintTrackSegments", "Results from TrackSegmentMaker:") ;
522 printf(" Found %d TrackSegments\n", fTrackSegments->GetEntriesFast() );
524 if(strstr(option,"all")) { // printing found TS
525 printf("TrackSegment # EMC RP# CPV RP#\n") ;
527 for (index = 0 ; index <fTrackSegments->GetEntriesFast() ; index++) {
528 AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )fTrackSegments->At(index) ;
529 printf(" %d %d %d \n", ts->GetIndexInList(), ts->GetEmcIndex(), ts->GetCpvIndex() ) ;