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.93 2007/10/10 09:05:10 schutz
21 * Changing name QualAss to QA
23 * Revision 1.92 2007/08/28 12:55:08 policheh
24 * Loaders removed from the reconstruction code (C.Cheshkov)
26 * Revision 1.91 2007/08/07 14:12:03 kharlov
27 * Quality assurance added (Yves Schutz)
29 * Revision 1.90 2007/07/11 13:43:30 hristov
30 * New class AliESDEvent, backward compatibility with the old AliESD (Christian)
32 * Revision 1.89 2007/07/03 08:13:04 kharlov
33 * Bug fix in CPV local coordinates
35 * Revision 1.88 2007/06/27 09:11:07 kharlov
36 * Bug fix for CPV-EMC distance
38 * Revision 1.87 2007/05/04 14:49:29 policheh
39 * AliPHOSRecPoint inheritance from AliCluster
41 * Revision 1.86 2007/04/02 15:00:16 cvetan
42 * No more calls to gAlice in the reconstruction
44 * Revision 1.85 2007/03/28 19:18:15 kharlov
45 * RecPoints recalculation in TSM removed
47 * Revision 1.84 2007/03/07 07:01:21 hristov
48 * Fixing copy/paste erro. Additional protections
50 * Revision 1.83 2007/03/06 21:07:37 kharlov
51 * DP: xz CPV-EMC distance filled to TS
53 * Revision 1.82 2007/03/06 06:54:48 kharlov
54 * DP:Calculation of cluster properties dep. on vertex added
56 * Revision 1.81 2007/02/05 10:02:40 kharlov
57 * Module numbering is corrected
59 * Revision 1.80 2006/08/28 10:01:56 kharlov
60 * Effective C++ warnings fixed (Timur Pocheptsov)
62 * Revision 1.79 2006/04/25 12:41:15 hristov
63 * Moving non-persistent data to AliESDfriend (Yu.Belikov)
65 * Revision 1.78 2005/11/18 13:04:51 hristov
68 * Revision 1.77 2005/11/17 23:34:36 hristov
71 * Revision 1.76 2005/11/17 22:29:12 hristov
72 * Faster version, no attempt to match tracks outside the PHOS acceptance
74 * Revision 1.75 2005/11/17 12:35:27 hristov
75 * Use references instead of objects. Avoid to create objects when they are not really needed
77 * Revision 1.74 2005/07/08 14:01:36 hristov
78 * Tracking in non-uniform nmagnetic field (Yu.Belikov)
80 * Revision 1.73 2005/05/28 14:19:05 schutz
81 * Compilation warnings fixed by T.P.
85 //_________________________________________________________________________
86 // Implementation version 1 of algorithm class to construct PHOS track segments
87 // Track segment for PHOS is list of
88 // EMC RecPoint + (possibly) CPV RecPoint
89 // To find TrackSegments we do the following:
90 // for each EMC RecPoints we look at
91 // CPV RecPoints in the radious fRcpv.
92 // If there is such a CPV RecPoint,
93 // we make "Link" it is just indexes of EMC and CPV RecPoint and distance
94 // between them in the PHOS plane.
95 // Then we sort "Links" and starting from the
96 // least "Link" pointing to the unassined EMC and CPV RecPoints assing them to
98 // If there is no CPV RecPoint we make TrackSegment
99 // consisting from EMC alone. There is no TrackSegments without EMC RecPoint.
100 //// In principle this class should be called from AliPHOSReconstructor, but
101 // one can use it as well in standalone mode.
103 // root [0] AliPHOSTrackSegmentMakerv1 * t = new AliPHOSTrackSegmentMaker("galice.root", "tracksegmentsname", "recpointsname")
104 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
105 // // reads gAlice from header file "galice.root", uses recpoints stored in the branch names "recpointsname" (default = "Default")
106 // // and saves recpoints in branch named "tracksegmentsname" (default = "recpointsname")
107 // root [1] t->ExecuteTask()
108 // root [3] t->SetTrackSegmentsBranch("max distance 5 cm")
109 // root [4] t->ExecuteTask("deb all time")
111 //*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH) & Yves Schutz (SUBATECH)
114 // --- ROOT system ---
115 #include "TVector3.h"
117 #include "TBenchmark.h"
119 // --- Standard library ---
120 #include "Riostream.h"
121 // --- AliRoot header files ---
122 #include "AliPHOSGeometry.h"
123 #include "AliPHOSTrackSegmentMakerv1.h"
124 #include "AliPHOSTrackSegment.h"
125 #include "AliPHOSLink.h"
126 #include "AliESDEvent.h"
127 #include "AliESDtrack.h"
128 #include "AliPHOSEmcRecPoint.h"
129 #include "AliPHOSCpvRecPoint.h"
133 #include "AliTracker.h"
134 #include "AliGeomManager.h"
135 #include "AliCluster.h"
136 #include "AliKalmanTrack.h"
137 #include "AliGlobalQADataMaker.h"
138 #include "AliVParticle.h"
141 ClassImp( AliPHOSTrackSegmentMakerv1)
144 //____________________________________________________________________________
145 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() :
146 AliPHOSTrackSegmentMaker(),
161 // default ctor (to be used mainly by Streamer)
165 //____________________________________________________________________________
166 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(AliPHOSGeometry *geom) :
167 AliPHOSTrackSegmentMaker(geom),
168 fDefaultInit(kFALSE),
189 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const AliPHOSTrackSegmentMakerv1 & tsm) :
190 AliPHOSTrackSegmentMaker(tsm),
191 fDefaultInit(kFALSE),
205 // cpy ctor: no implementation yet
206 // requested by the Coding Convention
207 Fatal("cpy ctor", "not implemented") ;
211 //____________________________________________________________________________
212 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
215 // fDefaultInit = kTRUE if TrackSegmentMaker created by default ctor (to get just the parameters)
217 delete fLinkUpArray ;
218 if (fTrackSegments) {
219 fTrackSegments->Delete();
220 delete fTrackSegments;
224 //____________________________________________________________________________
225 void AliPHOSTrackSegmentMakerv1::FillOneModule()
227 // Finds first and last indexes between which
228 // clusters from one PHOS module are
231 Int_t totalEmc = fEMCRecPoints->GetEntriesFast() ;
232 for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&
233 ((static_cast<AliPHOSRecPoint *>(fEMCRecPoints->At(fEmcLast)))->GetPHOSMod() == fModule );
237 Int_t totalCpv = fCPVRecPoints->GetEntriesFast() ;
239 for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&
240 ((static_cast<AliPHOSRecPoint *>(fCPVRecPoints->At(fCpvLast)))->GetPHOSMod() == fModule );
245 //____________________________________________________________________________
246 void AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,
247 AliPHOSCpvRecPoint * cpvClu,
249 Float_t &dx, Float_t &dz) const
251 // Calculates the distance between the EMC RecPoint and the CPV RecPoint
252 // If no CPV, calculates the distance between the EMC RecPoint and the track
253 // prolongation to the PHOS module plane.
254 // Clusters are sorted in "rows" and "columns" of width 1 cm
256 // Float_t delta = 1 ; // Width of the rows in sorting of RecPoints (in cm)
257 // // if you change this value, change it as well in xxxRecPoint::Compare()
269 // *** Start the matching
270 Int_t nt=fESD->GetNumberOfTracks();
271 Int_t iPHOSMod = emcClu->GetPHOSMod() ;
272 //Calculate actual distance to PHOS module
274 fGeom->Local2Global(iPHOSMod, 0.,0., globaPos) ;
275 const Double_t rPHOS = globaPos.Pt() ; //Distance to center of PHOS module
276 const Double_t kYmax = 72.+10. ; //Size of the module (with some reserve) in phi direction
277 const Double_t kZmax = 64.+10. ; //Size of the module (with some reserve) in z direction
278 const Double_t kAlpha0=330./180.*TMath::Pi() ; //First PHOS module angular direction
279 const Double_t kAlpha= 20./180.*TMath::Pi() ; //PHOS module angular size
280 Double_t minDistance = 1.e6;
282 TVector3 vecEmc ; // Local position of EMC recpoint
283 emcClu->GetLocalPosition(vecEmc) ;
285 Double_t gposTrack[3] ;
286 Double_t bz = AliTracker::GetBz() ; //B-Field for approximate matching
288 for (Int_t i=0; i<nt; i++) {
289 AliESDtrack *esdTrack=fESD->GetTrack(i);
291 // Skip the tracks having "wrong" status (has to be checked/tuned)
292 ULong_t status = esdTrack->GetStatus();
293 if ((status & AliESDtrack::kTPCout) == 0) continue;
294 // if ((status & AliESDtrack::kTRDout) == 0) continue;
295 // if ((status & AliESDtrack::kTRDrefit) == 1) continue;
297 //Continue extrapolation from TPC outer surface
298 const AliExternalTrackParam *outerParam=esdTrack->GetOuterParam();
299 if (!outerParam) continue;
300 AliExternalTrackParam t(*outerParam);
303 //Direction to the current PHOS module
304 Double_t phiMod=kAlpha0-kAlpha*iPHOSMod ;
305 if(!t.Rotate(phiMod))
308 Double_t y; // Some tracks do not reach the PHOS
309 if (!t.GetYAt(rPHOS,bz,y)) continue; // because of the bending
312 if(!t.GetZAt(rPHOS,bz,z))
314 if (TMath::Abs(z) > kZmax)
315 continue; // Some tracks miss the PHOS in Z
316 if(TMath::Abs(y) < kYmax){
317 t.PropagateToBxByBz(rPHOS,b); // Propagate to the matching module
318 //t.CorrectForMaterial(...); // Correct for the TOF material, if needed
319 t.GetXYZ(gposTrack) ;
320 TVector3 globalPositionTr(gposTrack) ;
321 TVector3 localPositionTr ;
322 fGeom->Global2Local(localPositionTr,globalPositionTr,iPHOSMod) ;
323 Double_t ddx = vecEmc.X()-localPositionTr.X();
324 Double_t ddz = vecEmc.Z()-localPositionTr.Z();
325 Double_t d2 = ddx*ddx + ddz*ddz;
326 if(d2 < minDistance) {
333 } //Scanned all tracks
339 fGeom->GetGlobalPHOS((AliPHOSRecPoint*)emcClu,emcGlobal);
341 // Radius from IP to current point
342 Double_t rEMC = TMath::Abs(emcGlobal.Pt());
344 // Extrapolate the global track direction to EMC
345 // and find the closest track
347 Int_t nTracks = fESD->GetNumberOfTracks();
350 Double_t xyz[] = {-1,-1,-1};
357 Float_t minDistance = 1.e6;
360 for (Int_t iTrack=0; iTrack<nTracks; iTrack++) {
361 track = fESD->GetTrack(iTrack);
362 if (!track->GetXYZAt(rEMC, fESD->GetMagneticField(), xyz)) continue;
364 AliDebug(1,Form("Event %d, iTrack: %d, (%.3f,%.3f,%.3f)",
365 fESD->GetEventNumberInFile(),iTrack,xyz[0],xyz[1],xyz[2]));
367 if (track->GetPxPyPzAt(rEMC,fESD->GetMagneticField(),pxyz)) {
369 vecP.SetXYZ(pxyz[0],pxyz[1],pxyz[2]);
370 fGeom->ImpactOnEmc(xyz,vecP.Theta(),vecP.Phi(),module,zEMC,xEMC) ;
372 if(!module) continue;
373 AliDebug(1,Form("\t\tTrack hit PHOS! Module: %d, (x,z)=(%.3f,%.3f)",module,xEMC,zEMC));
375 if(emcClu->GetPHOSMod() != module) continue;
377 // match track to EMC cluster
378 emcClu->GetLocalPosition(locClu);
380 Float_t delta_x = xEMC - locClu.X();
381 Float_t delta_z = zEMC - locClu.Z();
382 dr = TMath::Sqrt(delta_x*delta_x + delta_z*delta_z);
383 AliDebug(1,Form("\tMatch iTrack=%d: (dx,dz)=(%.3f,%.3f)",iTrack,delta_x,delta_z));
396 AliDebug(1,Form("\t\tBest match for (xClu,zClu,eClu)=(%.3f,%.3f,%.3f): iTrack=%d, dR=%.3f",
397 locClu.X(),locClu.Z(),emcClu->GetEnergy(),
398 trackindex,TMath::Sqrt(dx*dx+dz*dz)));
402 Float_t distance2Track = fRtpc ;
404 trackindex = -1 ; // closest track within fRCpv
406 TVector3 vecEmc ; // Local position of EMC recpoint
407 TVector3 vecPloc ; // Momentum direction at CPV plain
410 if(emcClu->GetPHOSMod() != cpvClu->GetPHOSMod()){
416 emcClu->GetLocalPosition(vecEmc) ;
418 Double_t xCPV=0,zCPV=0 ; //EMC-projected coordinates of CPV cluster
419 TVector3 cpvGlobal; // Global position of the CPV recpoint
420 fGeom->GetGlobalPHOS((AliPHOSRecPoint*)cpvClu,cpvGlobal);
421 Double_t vtxCPV[3]={cpvGlobal.X(),cpvGlobal.Y(),cpvGlobal.Z()} ;
425 //if no track information available, assume straight line from IP to emcal
426 fGeom->ImpactOnEmc(vtxCPV,cpvGlobal.Theta(),cpvGlobal.Phi(),dummyMod,zCPV,xCPV) ;
427 dx=xCPV - vecEmc.X() ;
428 dz=zCPV - vecEmc.Z() ;
432 //if there is ESD try to correct distance using TPC information on particle direct in CPV
435 Double_t rCPV = cpvGlobal.Pt() ;// Radius from IP to current point
437 // Extrapolate the global track direction if any to CPV and find the closest track
438 Int_t iClosestTrack = -1;
441 for (Int_t iTrack=0; iTrack<nTracks; iTrack++) {
442 track = fESD->GetTrack(iTrack);
443 if (!track->GetXYZAt(rCPV, fESD->GetMagneticField(), xyz))
444 continue; //track coord on the cylinder of PHOS radius
445 if ((TMath::Abs(xyz[0])+TMath::Abs(xyz[1])+TMath::Abs(xyz[2]))<=0)
447 //Check if this track hits PHOS
448 inPHOS.SetXYZ(xyz[0],xyz[1],xyz[2]);
449 distance2Track = inPHOS.Angle(cpvGlobal) ;
450 // Find the closest track to the CPV recpoint
451 if (distance2Track < minDistance) {
452 minDistance = distance2Track;
453 iClosestTrack = iTrack;
457 if (iClosestTrack != -1) {
458 track = fESD->GetTrack(iClosestTrack);
459 if (track->GetPxPyPzAt(rCPV, fESD->GetMagneticField(), pxyz)) { // track momentum ibid.
460 vecP.SetXYZ(pxyz[0],pxyz[1],pxyz[2]);
461 fGeom->ImpactOnEmc(vtxCPV,vecP.Theta(),vecP.Phi(),dummyMod,zCPV,xCPV) ;
465 if(minDistance < fRtpc ){
466 trackindex = iClosestTrack ;
470 // If the closest global track is found, calculate EMC-CPV distance from it
471 dx=xCPV - vecEmc.X() ;
472 dz=zCPV - vecEmc.Z() ;
475 // If no global track was found, just take the nearest CPV point
476 fGeom->ImpactOnEmc(vtxCPV,cpvGlobal.Theta(),cpvGlobal.Phi(),dummyMod,zCPV,xCPV) ;
477 dx=xCPV - vecEmc.X() ;
478 dz=zCPV - vecEmc.Z() ;
482 //____________________________________________________________________________
483 void AliPHOSTrackSegmentMakerv1::Init()
485 // Make all memory allocations that are not possible in default constructor
487 fLinkUpArray = new TClonesArray("AliPHOSLink", 1000);
488 fTrackSegments = new TClonesArray("AliPHOSTrackSegment",100);
489 fTrackSegments->SetName("TRACKS");
492 //____________________________________________________________________________
493 void AliPHOSTrackSegmentMakerv1::InitParameters()
495 //Initializes parameters
507 //____________________________________________________________________________
508 void AliPHOSTrackSegmentMakerv1::MakeLinks()const
510 // Finds distances (links) between all EMC and CPV clusters,
511 // which are not further apart from each other than fRcpv
512 // and sort them in accordance with this distance
514 fLinkUpArray->Clear() ;
516 AliPHOSCpvRecPoint * cpv ;
517 AliPHOSEmcRecPoint * emcclu ;
522 for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
523 emcclu = dynamic_cast<AliPHOSEmcRecPoint *>(fEMCRecPoints->At(iEmcRP)) ;
527 for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) {
529 cpv = dynamic_cast<AliPHOSCpvRecPoint *>(fCPVRecPoints->At(iCpv)) ;
532 GetDistanceInPHOSPlane(emcclu, cpv, track,dx,dz) ;
533 if(TMath::Sqrt(dx*dx+dz*dz) < fRcpv ){
534 new ((*fLinkUpArray)[iLinkUp++]) AliPHOSLink(dx, dz, iEmcRP, iCpv, track) ;
539 fLinkUpArray->Sort() ; //first links with smallest distances
542 //____________________________________________________________________________
543 void AliPHOSTrackSegmentMakerv1::MakePairs()
545 // Using the previously made list of "links", we found the smallest link - i.e.
546 // link with the least distance between EMC and CPV and pointing to still
547 // unassigned RecParticles. We assign these RecPoints to TrackSegment and
548 // remove them from the list of "unassigned".
550 //Make arrays to mark clusters already chosen
553 Int_t * emcExist = 0;
554 if(fEmcLast > fEmcFirst) {
555 emcExist = new Int_t[fEmcLast-fEmcFirst] ;
556 for(index = 0; index <fEmcLast-fEmcFirst; index ++)
557 emcExist[index] = 1 ;
562 Bool_t * cpvExist = 0;
563 if(fCpvLast > fCpvFirst) {
564 cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
565 for(index = 0; index <fCpvLast-fCpvFirst; index ++)
566 cpvExist[index] = kTRUE ;
569 // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance
570 TIter nextUp(fLinkUpArray) ;
572 AliPHOSLink * linkUp ;
574 AliPHOSCpvRecPoint * nullpointer = 0 ;
576 while ( (linkUp = static_cast<AliPHOSLink *>(nextUp()) ) ){
578 if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){
580 //array cpvExist[] should be non-zero as far as linkUp exists
581 //But Coverity requires to check it
582 if(cpvExist && cpvExist[linkUp->GetCpv()-fCpvFirst]){ //CPV still exist
584 linkUp->GetXZ(dx,dz) ;
585 new ((* fTrackSegments)[fNTrackSegments])
586 AliPHOSTrackSegment(static_cast<AliPHOSEmcRecPoint *>(fEMCRecPoints->At(linkUp->GetEmc())) ,
587 static_cast<AliPHOSCpvRecPoint *>(fCPVRecPoints->At(linkUp->GetCpv())) ,
588 linkUp->GetTrack(),dx,dz) ;
590 (static_cast<AliPHOSTrackSegment *>(fTrackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
592 emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc that Cpv was found
593 //mark CPV recpoint as already used
594 cpvExist[linkUp->GetCpv()-fCpvFirst] = kFALSE ;
595 } //if CpvUp still exist
599 //look through emc recPoints left without CPV
600 if(emcExist){ //if there is emc rec point
602 for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst ; iEmcRP++ ){
603 if(emcExist[iEmcRP] > 0 ){
606 AliPHOSEmcRecPoint *emcclu = dynamic_cast<AliPHOSEmcRecPoint *>(fEMCRecPoints->At(iEmcRP+fEmcFirst));
607 GetDistanceInPHOSPlane(emcclu, 0, track,dx,dz);
609 new ((*fTrackSegments)[fNTrackSegments]) AliPHOSTrackSegment(emcclu,nullpointer) ;
611 new ((*fTrackSegments)[fNTrackSegments]) AliPHOSTrackSegment(emcclu,0,track,dx,dz);
612 (static_cast<AliPHOSTrackSegment *>(fTrackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
622 //____________________________________________________________________________
623 void AliPHOSTrackSegmentMakerv1::Clusters2TrackSegments(Option_t *option)
625 // Steering method to perform track segment construction for the current event
626 // Returns an array with the found track-segments.
628 if(strstr(option,"tim"))
629 gBenchmark->Start("PHOSTSMaker");
631 if(strstr(option,"print")) {
636 //Make some initializations
637 fNTrackSegments = 0 ;
643 fTrackSegments->Clear();
645 // if(!ReadRecPoints(ievent)) continue; //reads RecPoints for event ievent
647 for(fModule = 1; fModule <= fGeom->GetNModules() ; fModule++ ) {
653 if(strstr(option,"deb"))
654 PrintTrackSegments(option);
656 if(strstr(option,"tim")){
657 gBenchmark->Stop("PHOSTSMaker");
658 Info("Exec", "took %f seconds for making TS",
659 gBenchmark->GetCpuTime("PHOSTSMaker"));
663 //____________________________________________________________________________
664 void AliPHOSTrackSegmentMakerv1::Print(const Option_t *)const
666 // Print TrackSegmentMaker parameters
668 TString message("") ;
669 if( strcmp(GetName(), "") != 0 ) {
670 message = "\n======== AliPHOSTrackSegmentMakerv1 ========\n" ;
671 message += "Making Track segments\n" ;
672 message += "with parameters:\n" ;
673 message += " Maximal EMC - CPV distance (cm) %f\n" ;
674 message += "============================================\n" ;
675 Info("Print", message.Data(),fRcpv) ;
678 Info("Print", "AliPHOSTrackSegmentMakerv1 not initialized ") ;
681 //____________________________________________________________________________
682 void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
684 // option deb - prints # of found TrackSegments
685 // option deb all - prints as well indexed of found RecParticles assigned to the TS
687 Info("PrintTrackSegments", "Results from TrackSegmentMaker:") ;
688 printf(" Found %d TrackSegments\n", fTrackSegments->GetEntriesFast() );
690 if(strstr(option,"all")) { // printing found TS
691 printf("TrackSegment # EMC RP# CPV RP#\n") ;
693 for (index = 0 ; index <fTrackSegments->GetEntriesFast() ; index++) {
694 AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )fTrackSegments->At(index) ;
695 printf(" %d %d %d \n", ts->GetIndexInList(), ts->GetEmcIndex(), ts->GetCpvIndex() ) ;