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.77 2005/11/17 23:34:36 hristov
23 * Revision 1.76 2005/11/17 22:29:12 hristov
24 * Faster version, no attempt to match tracks outside the PHOS acceptance
26 * Revision 1.75 2005/11/17 12:35:27 hristov
27 * Use references instead of objects. Avoid to create objects when they are not really needed
29 * Revision 1.74 2005/07/08 14:01:36 hristov
30 * Tracking in non-uniform nmagnetic field (Yu.Belikov)
32 * Revision 1.73 2005/05/28 14:19:05 schutz
33 * Compilation warnings fixed by T.P.
37 //_________________________________________________________________________
38 // Implementation version 1 of algorithm class to construct PHOS track segments
39 // Track segment for PHOS is list of
40 // EMC RecPoint + (possibly) CPV RecPoint
41 // To find TrackSegments we do the following:
42 // for each EMC RecPoints we look at
43 // CPV RecPoints in the radious fRcpv.
44 // If there is such a CPV RecPoint,
45 // we make "Link" it is just indexes of EMC and CPV RecPoint and distance
46 // between them in the PHOS plane.
47 // Then we sort "Links" and starting from the
48 // least "Link" pointing to the unassined EMC and CPV RecPoints assing them to
50 // If there is no CPV RecPoint we make TrackSegment
51 // consisting from EMC alone. There is no TrackSegments without EMC RecPoint.
52 //// In principle this class should be called from AliPHOSReconstructor, but
53 // one can use it as well in standalone mode.
55 // root [0] AliPHOSTrackSegmentMakerv1 * t = new AliPHOSTrackSegmentMaker("galice.root", "tracksegmentsname", "recpointsname")
56 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
57 // // reads gAlice from header file "galice.root", uses recpoints stored in the branch names "recpointsname" (default = "Default")
58 // // and saves recpoints in branch named "tracksegmentsname" (default = "recpointsname")
59 // root [1] t->ExecuteTask()
60 // root [3] t->SetTrackSegmentsBranch("max distance 5 cm")
61 // root [4] t->ExecuteTask("deb all time")
63 //*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH) & Yves Schutz (SUBATECH)
66 // --- ROOT system ---
68 #include "TBenchmark.h"
70 // --- Standard library ---
71 #include "Riostream.h"
72 // --- AliRoot header files ---
73 #include "AliPHOSGeometry.h"
74 #include "AliPHOSTrackSegmentMakerv1.h"
75 #include "AliPHOSTrackSegment.h"
76 #include "AliPHOSLink.h"
77 #include "AliPHOSGetter.h"
79 #include "AliESDtrack.h"
81 ClassImp( AliPHOSTrackSegmentMakerv1)
84 //____________________________________________________________________________
85 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() : AliPHOSTrackSegmentMaker()
87 // default ctor (to be used mainly by Streamer)
90 fDefaultInit = kTRUE ;
93 //____________________________________________________________________________
94 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const TString alirunFileName, const TString eventFolderName)
95 :AliPHOSTrackSegmentMaker(alirunFileName, eventFolderName)
101 fDefaultInit = kFALSE ;
105 //____________________________________________________________________________
106 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
109 // fDefaultInit = kTRUE if TrackSegmentMaker created by default ctor (to get just the parameters)
111 delete fLinkUpArray ;
115 //____________________________________________________________________________
116 const TString AliPHOSTrackSegmentMakerv1::BranchName() const
122 //____________________________________________________________________________
123 void AliPHOSTrackSegmentMakerv1::FillOneModule()
125 // Finds first and last indexes between which
126 // clusters from one PHOS module are
128 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
130 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
131 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
134 Int_t totalEmc = emcRecPoints->GetEntriesFast() ;
135 for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&
136 ((dynamic_cast<AliPHOSRecPoint *>(emcRecPoints->At(fEmcLast)))->GetPHOSMod() == fModule );
140 Int_t totalCpv = cpvRecPoints->GetEntriesFast() ;
142 for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&
143 ((dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(fCpvLast)))->GetPHOSMod() == fModule );
148 //____________________________________________________________________________
149 Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,AliPHOSCpvRecPoint * cpvClu, Int_t &trackindex) const
151 // Calculates the distance between the EMC RecPoint and the CPV RecPoint
152 // Clusters are sorted in "rows" and "columns" of width 1 cm
154 //Float_t delta = 1 ; // Width of the rows in sorting of RecPoints (in cm)
155 // if you change this value, change it as well in xxxRecPoint::Compare()
156 Float_t distance2Cpv = fRcpv ;
157 Float_t distance2Track = fRtpc ;
159 trackindex = -1 ; // closest track within fRCpv
161 TVector3 vecEmc ; // Local position of EMC recpoint
162 TVector3 vecCpv ; // Local position of CPV recpoint propagated to EMC
163 TVector3 vecDist ; // Distance between local positions of two points
165 emcClu->GetLocalPosition(vecEmc) ;
166 cpvClu->GetLocalPosition(vecCpv) ;
169 if(emcClu->GetPHOSMod() == cpvClu->GetPHOSMod()){
171 // Find EMC-CPV distance
172 distance2Cpv = (vecCpv - vecEmc).Mag() ;
175 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
176 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
178 Double_t rPHOS = geom->GetIPtoCrystalSurface();
180 //PH Acceptance boundaries for each PHOS module
181 Int_t nModules = geom->GetNModules();
182 Double_t * thmin = new Double_t[nModules];// theta min
183 Double_t * thmax = new Double_t[nModules];// theta max
184 Double_t * phmin = new Double_t[nModules];// phi min
185 Double_t * phmax = new Double_t[nModules];// phi max
187 for (Int_t imod=0; imod<nModules; imod++) {
188 geom->EmcModuleCoverage(imod,
189 thmin[imod],thmax[imod],
190 phmin[imod],phmax[imod]);
193 // Extrapolate the global track direction if any to CPV and find the closest track
194 Int_t nTracks = fESD->GetNumberOfTracks();
195 Int_t iClosestTrack = -1;
196 Double_t minDistance = 1e6;
197 Double_t pxyz[3], xyz[3];
198 TVector3 inPHOS; //PH Used to calculate theta and phi
202 for (Int_t iTrack=0; iTrack<nTracks; iTrack++) {
203 track = fESD->GetTrack(iTrack);
205 continue ; //Skip the PHOS tracks
206 if (!track->GetXYZAt(rPHOS, fESD->GetMagneticField(), xyz))
207 continue; //track coord on the cylinder of PHOS radius
208 if ((TMath::Abs(xyz[0])+TMath::Abs(xyz[1])+TMath::Abs(xyz[2]))<=0)
210 //PH Here one has to cut out the tracks which are not inside the PHOS
212 inPHOS.SetXYZ(xyz[0],xyz[1],xyz[2]);
213 Double_t inPhi = inPHOS.Phi();
214 Double_t inTheta = inPHOS.Theta();
217 for (Int_t imod=0; imod<nModules; imod++) {
218 //PH Loop on modules to check if the track enters in the acceptance
219 if (thmin[imod] < inTheta && thmax[imod] > inTheta &&
220 phmin[imod] < inPhi && phmax[imod] > inPhi) {
225 if (skip) continue; //PH Skip, if not in the PHOS acceptance
227 if (!track->GetPxPyPzAt(rPHOS, fESD->GetMagneticField(), pxyz))
228 continue; // track momentum ibid.
229 PropagateToPlane(vecDist,xyz,pxyz,"CPV",cpvClu->GetPHOSMod());
230 // Info("GetDistanceInPHOSPlane","Track %d propagation to CPV = (%f,%f,%f)",
231 // iTrack,vecDist.X(),vecDist.Y(),vecDist.Z());
233 distance2Track = TMath::Sqrt(vecDist.X()*vecDist.X() + vecDist.Z()*vecDist.Z());
234 // Find the closest track to the EMC recpoint
235 if (distance2Track < minDistance) {
236 minDistance = distance2Track;
237 iClosestTrack = iTrack;
246 if (iClosestTrack != -1) {
247 track = fESD->GetTrack(iClosestTrack);
248 if (track->GetPxPyPzAt(rPHOS, fESD->GetMagneticField(), pxyz)) { // track momentum ibid.
249 TVector3 vecCpvGlobal; // Global position of the CPV recpoint
250 geom->GetGlobal((AliRecPoint*)cpvClu,vecCpvGlobal);
251 for (Int_t ixyz=0; ixyz<3; ixyz++)
252 xyz[ixyz] = vecCpvGlobal[ixyz];
253 PropagateToPlane(vecDist,xyz,pxyz,"EMC",cpvClu->GetPHOSMod());
254 // Info("GetDistanceInPHOSPlane","Track %d propagation to EMC = (%f,%f,%f)",
255 // iClosestTrack,vecDist.X(),vecDist.Y(),vecDist.Z());
257 distance2Track = TMath::Sqrt(vecDist.X()*vecDist.X() + vecDist.Z()*vecDist.Z());
261 // // If no ESD exists, than simply find EMC-CPV distance
262 // distance = (vecCpv - vecEmc).Mag() ;
264 //if(distance2Track < fRcpv + 2*delta )
265 if(distance2Track < fRtpc )
266 trackindex = iClosestTrack ;
269 // Info("GetDistanceInPHOSPlane","cpv-emc distance is %f cm",
273 return distance2Cpv ;
276 //____________________________________________________________________________
277 void AliPHOSTrackSegmentMakerv1::PropagateToPlane(TVector3& globalIntersection,
281 Int_t moduleNumber) const
283 // Propagate a straight-line track from the origin point x
284 // along the direction p to the CPV or EMC module moduleNumber
285 // Returns a local position of such a propagation
287 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
288 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
289 TVector3 moduleCenter;
290 geom->GetModuleCenter(moduleCenter,det,moduleNumber);
291 TVector3 vertex; vertex.SetXYZ(x[0],x[1],x[2]);
292 TVector3 direction; direction.SetXYZ(p[0],p[1],p[2]);
294 // Info("PropagateToCPV","Center of the %s module %d is (%f,%f,%f)",
295 // det,moduleNumber,moduleCenter[0],moduleCenter[1],moduleCenter[2]);
297 Double_t time = (moduleCenter.Mag2() - vertex.Dot(moduleCenter)) /
298 (direction.Dot(moduleCenter));
299 vertex += direction*time;
300 geom->Global2Local(globalIntersection,vertex,moduleNumber);
303 //____________________________________________________________________________
304 void AliPHOSTrackSegmentMakerv1::Init()
306 // Make all memory allocations that are not possible in default constructor
308 AliPHOSGetter* gime = AliPHOSGetter::Instance();
310 gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
312 fLinkUpArray = new TClonesArray("AliPHOSLink", 1000);
313 if ( !gime->TrackSegmentMaker() ) {
314 gime->PostTrackSegmentMaker(this);
318 //____________________________________________________________________________
319 void AliPHOSTrackSegmentMakerv1::InitParameters()
321 //Initializes parameters
330 fTrackSegmentsInRun = 0 ;
331 SetEventRange(0,-1) ;
335 //____________________________________________________________________________
336 void AliPHOSTrackSegmentMakerv1::MakeLinks()const
338 // Finds distances (links) between all EMC and CPV clusters,
339 // which are not further apart from each other than fRcpv
340 // and sort them in accordance with this distance
342 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
343 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
344 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
346 fLinkUpArray->Clear() ;
348 AliPHOSCpvRecPoint * cpv ;
349 AliPHOSEmcRecPoint * emcclu ;
354 for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
355 emcclu = dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP)) ;
359 for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) {
361 cpv = dynamic_cast<AliPHOSCpvRecPoint *>(cpvRecPoints->At(iCpv)) ;
363 Float_t r = GetDistanceInPHOSPlane(emcclu, cpv, track) ;
367 new ((*fLinkUpArray)[iLinkUp++]) AliPHOSLink(r, iEmcRP, iCpv, track) ;
372 fLinkUpArray->Sort() ; //first links with smallest distances
375 //____________________________________________________________________________
376 void AliPHOSTrackSegmentMakerv1::MakePairs()
378 // Using the previously made list of "links", we found the smallest link - i.e.
379 // link with the least distance between EMC and CPV and pointing to still
380 // unassigned RecParticles. We assign these RecPoints to TrackSegment and
381 // remove them from the list of "unassigned".
383 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
385 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
386 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
387 TClonesArray * trackSegments = gime->TrackSegments();
389 //Make arrays to mark clusters already chosen
390 Int_t * emcExist = 0;
391 if(fEmcLast > fEmcFirst)
392 emcExist = new Int_t[fEmcLast-fEmcFirst] ;
395 for(index = 0; index <fEmcLast-fEmcFirst; index ++)
396 emcExist[index] = 1 ;
398 Bool_t * cpvExist = 0;
399 if(fCpvLast > fCpvFirst)
400 cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
401 for(index = 0; index <fCpvLast-fCpvFirst; index ++)
402 cpvExist[index] = kTRUE ;
405 // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance
406 TIter nextUp(fLinkUpArray) ;
408 AliPHOSLink * linkUp ;
410 AliPHOSCpvRecPoint * nullpointer = 0 ;
412 while ( (linkUp = static_cast<AliPHOSLink *>(nextUp()) ) ){
414 if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){
416 if(cpvExist[linkUp->GetCpv()-fCpvFirst]){ //CPV still exist
417 new ((* trackSegments)[fNTrackSegments])
418 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(linkUp->GetEmc())) ,
419 dynamic_cast<AliPHOSCpvRecPoint *>(cpvRecPoints->At(linkUp->GetCpv())) ,
420 linkUp->GetTrack()) ;
422 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
424 emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc that Cpv was found
425 //mark CPV recpoint as already used
426 cpvExist[linkUp->GetCpv()-fCpvFirst] = kFALSE ;
427 } //if CpvUp still exist
431 //look through emc recPoints left without CPV
432 if(emcExist){ //if there is emc rec point
434 for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst ; iEmcRP++ ){
435 if(emcExist[iEmcRP] > 0 ){
436 new ((*trackSegments)[fNTrackSegments])
437 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP+fEmcFirst)),
439 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
448 //____________________________________________________________________________
449 void AliPHOSTrackSegmentMakerv1::Exec(Option_t *option)
451 // Steering method to perform track segment construction for events
452 // in the range from fFirstEvent to fLastEvent.
453 // This range is optionally set by SetEventRange().
454 // if fLastEvent=-1 (by default), then process events until the end.
456 if(strstr(option,"tim"))
457 gBenchmark->Start("PHOSTSMaker");
459 if(strstr(option,"print")) {
464 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
466 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
468 if (fLastEvent == -1)
469 fLastEvent = gime->MaxEvent() - 1 ;
471 fLastEvent = TMath::Min(fFirstEvent,gime->MaxEvent());
472 Int_t nEvents = fLastEvent - fFirstEvent + 1;
475 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
476 gime->Event(ievent,"R") ;
477 //Make some initializations
478 fNTrackSegments = 0 ;
484 gime->TrackSegments()->Clear();
486 // if(!ReadRecPoints(ievent)) continue; //reads RecPoints for event ievent
488 for(fModule = 1; fModule <= geom->GetNModules() ; fModule++ ) {
494 WriteTrackSegments() ;
496 if(strstr(option,"deb"))
497 PrintTrackSegments(option);
499 //increment the total number of track segments per run
500 fTrackSegmentsInRun += gime->TrackSegments()->GetEntriesFast() ;
503 if(strstr(option,"tim")){
504 gBenchmark->Stop("PHOSTSMaker");
505 Info("Exec", "took %f seconds for making TS %f seconds per event",
506 gBenchmark->GetCpuTime("PHOSTSMaker"),
507 gBenchmark->GetCpuTime("PHOSTSMaker")/nEvents) ;
509 if(fWrite) //do not unload in "on flight" mode
513 //____________________________________________________________________________
514 void AliPHOSTrackSegmentMakerv1::Unload()
516 // Unloads the task from the folder
517 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
518 gime->PhosLoader()->UnloadRecPoints() ;
519 gime->PhosLoader()->UnloadTracks() ;
522 //____________________________________________________________________________
523 void AliPHOSTrackSegmentMakerv1::Print(const Option_t *)const
525 // Print TrackSegmentMaker parameters
527 TString message("") ;
528 if( strcmp(GetName(), "") != 0 ) {
529 message = "\n======== AliPHOSTrackSegmentMakerv1 ========\n" ;
530 message += "Making Track segments\n" ;
531 message += "with parameters:\n" ;
532 message += " Maximal EMC - CPV distance (cm) %f\n" ;
533 message += "============================================\n" ;
534 Info("Print", message.Data(),fRcpv) ;
537 Info("Print", "AliPHOSTrackSegmentMakerv1 not initialized ") ;
540 //____________________________________________________________________________
541 void AliPHOSTrackSegmentMakerv1::WriteTrackSegments()
543 // Writes found TrackSegments to TreeR. Creates branches
544 // "PHOSTS" and "AliPHOSTrackSegmentMaker" with the same title.
545 // In the former branch found TrackSegments are stored, while
546 // in the latter all parameters, with which TS were made.
547 // ROOT does not allow overwriting existing branches, therefore
548 // first we check, if branches with the same title already exist.
549 // If yes - exits without writing.
551 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
553 TClonesArray * trackSegments = gime->TrackSegments() ;
554 trackSegments->Expand(trackSegments->GetEntriesFast()) ;
556 if(fWrite){ //We write TreeT
557 TTree * treeT = gime->TreeT();
560 Int_t bufferSize = 32000 ;
561 TBranch * tsBranch = treeT->Branch("PHOSTS",&trackSegments,bufferSize);
564 gime->WriteTracks("OVERWRITE");
565 gime->WriteTrackSegmentMaker("OVERWRITE");
570 //____________________________________________________________________________
571 void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
573 // option deb - prints # of found TrackSegments
574 // option deb all - prints as well indexed of found RecParticles assigned to the TS
576 TClonesArray * trackSegments = AliPHOSGetter::Instance()->TrackSegments() ;
578 Info("PrintTrackSegments", "Results from TrackSegmentMaker:") ;
579 printf("nevent: %d\n", gAlice->GetEvNumber()) ;
580 printf(" Found %d TrackSegments\n", trackSegments->GetEntriesFast() );
582 if(strstr(option,"all")) { // printing found TS
583 printf("TrackSegment # EMC RP# CPV RP#\n") ;
585 for (index = 0 ; index <trackSegments->GetEntriesFast() ; index++) {
586 AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )trackSegments->At(index) ;
587 printf(" %d %d %d \n", ts->GetIndexInList(), ts->GetEmcIndex(), ts->GetCpvIndex() ) ;