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 **************************************************************************/
16 //_________________________________________________________________________
17 // Implementation version 1 of algorithm class to construct PHOS track segments
18 // Track segment for PHOS is list of
19 // EMC RecPoint + (possibly) CPV RecPoint
20 // To find TrackSegments we do the following:
21 // for each EMC RecPoints we look at
22 // CPV RecPoints in the radious fRcpv.
23 // If there is such a CPV RecPoint,
24 // we make "Link" it is just indexes of EMC and CPV RecPoint and distance
25 // between them in the PHOS plane.
26 // Then we sort "Links" and starting from the
27 // least "Link" pointing to the unassined EMC and CPV RecPoints assing them to
29 // If there is no CPV RecPoint we make TrackSegment
30 // consisting from EMC alone. There is no TrackSegments without EMC RecPoint.
31 //// In principle this class should be called from AliPHOSReconstructor, but
32 // one can use it as well in standalone mode.
34 // root [0] AliPHOSTrackSegmentMakerv1 * t = new AliPHOSTrackSegmentMaker("galice.root", "tracksegmentsname", "recpointsname")
35 // Warning in <TDatabasePDG::TDatabasePDG>: object already instantiated
36 // // reads gAlice from header file "galice.root", uses recpoints stored in the branch names "recpointsname" (default = "Default")
37 // // and saves recpoints in branch named "tracksegmentsname" (default = "recpointsname")
38 // root [1] t->ExecuteTask()
39 // root [3] t->SetTrackSegmentsBranch("max distance 5 cm")
40 // root [4] t->ExecuteTask("deb all time")
42 //*-- Author: Dmitri Peressounko (RRC Ki & SUBATECH) & Yves Schutz (SUBATECH)
45 // --- ROOT system ---
47 #include "TBenchmark.h"
49 // --- Standard library ---
50 #include "Riostream.h"
51 // --- AliRoot header files ---
52 #include "AliPHOSGeometry.h"
53 #include "AliPHOSTrackSegmentMakerv1.h"
54 #include "AliPHOSTrackSegment.h"
55 #include "AliPHOSLink.h"
56 #include "AliPHOSGetter.h"
58 #include "AliESDtrack.h"
60 ClassImp( AliPHOSTrackSegmentMakerv1)
63 //____________________________________________________________________________
64 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1() : AliPHOSTrackSegmentMaker()
66 // default ctor (to be used mainly by Streamer)
69 fDefaultInit = kTRUE ;
72 //____________________________________________________________________________
73 AliPHOSTrackSegmentMakerv1::AliPHOSTrackSegmentMakerv1(const TString alirunFileName, const TString eventFolderName)
74 :AliPHOSTrackSegmentMaker(alirunFileName, eventFolderName)
80 fDefaultInit = kFALSE ;
84 //____________________________________________________________________________
85 AliPHOSTrackSegmentMakerv1::~AliPHOSTrackSegmentMakerv1()
88 // fDefaultInit = kTRUE if TrackSegmentMaker created by default ctor (to get just the parameters)
94 //____________________________________________________________________________
95 const TString AliPHOSTrackSegmentMakerv1::BranchName() const
101 //____________________________________________________________________________
102 void AliPHOSTrackSegmentMakerv1::FillOneModule()
104 // Finds first and last indexes between which
105 // clusters from one PHOS module are
107 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
109 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
110 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
113 Int_t totalEmc = emcRecPoints->GetEntriesFast() ;
114 for(fEmcFirst = fEmcLast; (fEmcLast < totalEmc) &&
115 ((dynamic_cast<AliPHOSRecPoint *>(emcRecPoints->At(fEmcLast)))->GetPHOSMod() == fModule );
119 Int_t totalCpv = cpvRecPoints->GetEntriesFast() ;
121 for(fCpvFirst = fCpvLast; (fCpvLast < totalCpv) &&
122 ((dynamic_cast<AliPHOSRecPoint *>(cpvRecPoints->At(fCpvLast)))->GetPHOSMod() == fModule );
127 //____________________________________________________________________________
128 Float_t AliPHOSTrackSegmentMakerv1::GetDistanceInPHOSPlane(AliPHOSEmcRecPoint * emcClu,AliPHOSCpvRecPoint * cpvClu, Int_t &trackindex) const
130 // Calculates the distance between the EMC RecPoint and the CPV RecPoint
131 // Clusters are sorted in "rows" and "columns" of width 1 cm
133 //Float_t delta = 1 ; // Width of the rows in sorting of RecPoints (in cm)
134 // if you change this value, change it as well in xxxRecPoint::Compare()
135 Float_t distance2Cpv = fRcpv ;
136 Float_t distance2Track = fRtpc ;
138 trackindex = -1 ; // closest track within fRCpv
140 TVector3 vecEmc ; // Local position of EMC recpoint
141 TVector3 vecCpv ; // Local position of CPV recpoint propagated to EMC
142 TVector3 vecDist ; // Distance between local positions of two points
144 emcClu->GetLocalPosition(vecEmc) ;
145 cpvClu->GetLocalPosition(vecCpv) ;
148 if(emcClu->GetPHOSMod() == cpvClu->GetPHOSMod()){
150 // Find EMC-CPV distance
151 distance2Cpv = (vecCpv - vecEmc).Mag() ;
154 // Extrapolate the global track direction if any to CPV and find the closest track
155 Int_t nTracks = fESD->GetNumberOfTracks();
156 Int_t iClosestTrack = -1;
157 Double_t minDistance = 1e6;
158 Double_t pxyz[3], xyz[3];
160 AliPHOSGetter::Instance()->PHOSGeometry()->GetIPtoCrystalSurface();
162 for (Int_t iTrack=0; iTrack<nTracks; iTrack++) {
163 track = fESD->GetTrack(iTrack);
166 if (!track->GetXYZAt(rPHOS,xyz))
167 continue; //track coord on the cylinder of PHOS radius
168 if ((TMath::Abs(xyz[0])+TMath::Abs(xyz[1])+TMath::Abs(xyz[2]))<=0)
170 if (!track->GetPxPyPzAt(rPHOS,pxyz))
171 continue; // track momentum ibid.
172 vecDist = PropagateToPlane(xyz,pxyz,"CPV",cpvClu->GetPHOSMod());
173 // Info("GetDistanceInPHOSPlane","Track %d propagation to CPV = (%f,%f,%f)",
174 // iTrack,vecDist.X(),vecDist.Y(),vecDist.Z());
176 distance2Track = TMath::Sqrt(vecDist.X()*vecDist.X() + vecDist.Z()*vecDist.Z());
177 // Find the closest track to the EMC recpoint
178 if (distance2Track < minDistance) {
179 minDistance = distance2Track;
180 iClosestTrack = iTrack;
184 if (iClosestTrack != -1) {
185 track = fESD->GetTrack(iClosestTrack);
186 if (track->GetPxPyPzAt(rPHOS,pxyz)) { // track momentum ibid.
187 TVector3 vecCpvGlobal; // Global position of the CPV recpoint
188 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
189 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
190 geom->GetGlobal((AliRecPoint*)cpvClu,vecCpvGlobal);
191 for (Int_t ixyz=0; ixyz<3; ixyz++)
192 xyz[ixyz] = vecCpvGlobal[ixyz];
193 vecDist = PropagateToPlane(xyz,pxyz,"EMC",cpvClu->GetPHOSMod());
194 // Info("GetDistanceInPHOSPlane","Track %d propagation to EMC = (%f,%f,%f)",
195 // iClosestTrack,vecDist.X(),vecDist.Y(),vecDist.Z());
197 distance2Track = TMath::Sqrt(vecDist.X()*vecDist.X() + vecDist.Z()*vecDist.Z());
201 // // If no ESD exists, than simply find EMC-CPV distance
202 // distance = (vecCpv - vecEmc).Mag() ;
204 //if(distance2Track < fRcpv + 2*delta )
205 if(distance2Track < fRtpc )
206 trackindex = iClosestTrack ;
209 // Info("GetDistanceInPHOSPlane","cpv-emc distance is %f cm",
213 return distance2Cpv ;
216 //____________________________________________________________________________
217 TVector3 AliPHOSTrackSegmentMakerv1::PropagateToPlane(Double_t *x, Double_t *p,
218 char *det, Int_t moduleNumber) const
220 // Propagate a straight-line track from the origin point x
221 // along the direction p to the CPV or EMC module moduleNumber
222 // Returns a local position of such a propagation
224 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
225 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
226 TVector3 moduleCenter = geom->GetModuleCenter(det,moduleNumber);
228 TVector3 direction(p);
230 // Info("PropagateToCPV","Center of the %s module %d is (%f,%f,%f)",
231 // det,moduleNumber,moduleCenter[0],moduleCenter[1],moduleCenter[2]);
233 Double_t time = (moduleCenter.Mag2() - vertex.Dot(moduleCenter)) /
234 (direction.Dot(moduleCenter));
235 TVector3 globalIntersection = vertex + direction*time;
236 return geom->Global2Local(globalIntersection,moduleNumber);
239 //____________________________________________________________________________
240 void AliPHOSTrackSegmentMakerv1::Init()
242 // Make all memory allocations that are not possible in default constructor
244 AliPHOSGetter* gime = AliPHOSGetter::Instance();
246 gime = AliPHOSGetter::Instance(GetTitle(), fEventFolderName.Data());
248 fLinkUpArray = new TClonesArray("AliPHOSLink", 1000);
249 if ( !gime->TrackSegmentMaker() ) {
250 gime->PostTrackSegmentMaker(this);
254 //____________________________________________________________________________
255 void AliPHOSTrackSegmentMakerv1::InitParameters()
257 //Initializes parameters
266 fTrackSegmentsInRun = 0 ;
267 SetEventRange(0,-1) ;
271 //____________________________________________________________________________
272 void AliPHOSTrackSegmentMakerv1::MakeLinks()const
274 // Finds distances (links) between all EMC and CPV clusters,
275 // which are not further apart from each other than fRcpv
276 // and sort them in accordance with this distance
278 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
279 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
280 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
282 fLinkUpArray->Clear() ;
284 AliPHOSCpvRecPoint * cpv ;
285 AliPHOSEmcRecPoint * emcclu ;
290 for(iEmcRP = fEmcFirst; iEmcRP < fEmcLast; iEmcRP++ ) {
291 emcclu = dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP)) ;
295 for(iCpv = fCpvFirst; iCpv < fCpvLast;iCpv++ ) {
297 cpv = dynamic_cast<AliPHOSCpvRecPoint *>(cpvRecPoints->At(iCpv)) ;
299 Float_t r = GetDistanceInPHOSPlane(emcclu, cpv, track) ;
303 new ((*fLinkUpArray)[iLinkUp++]) AliPHOSLink(r, iEmcRP, iCpv, track) ;
308 fLinkUpArray->Sort() ; //first links with smallest distances
311 //____________________________________________________________________________
312 void AliPHOSTrackSegmentMakerv1::MakePairs()
314 // Using the previously made list of "links", we found the smallest link - i.e.
315 // link with the least distance between EMC and CPV and pointing to still
316 // unassigned RecParticles. We assign these RecPoints to TrackSegment and
317 // remove them from the list of "unassigned".
319 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
321 TObjArray * emcRecPoints = gime->EmcRecPoints() ;
322 TObjArray * cpvRecPoints = gime->CpvRecPoints() ;
323 TClonesArray * trackSegments = gime->TrackSegments();
325 //Make arrays to mark clusters already chosen
326 Int_t * emcExist = 0;
327 if(fEmcLast > fEmcFirst)
328 emcExist = new Int_t[fEmcLast-fEmcFirst] ;
331 for(index = 0; index <fEmcLast-fEmcFirst; index ++)
332 emcExist[index] = 1 ;
334 Bool_t * cpvExist = 0;
335 if(fCpvLast > fCpvFirst)
336 cpvExist = new Bool_t[fCpvLast-fCpvFirst] ;
337 for(index = 0; index <fCpvLast-fCpvFirst; index ++)
338 cpvExist[index] = kTRUE ;
341 // Finds the smallest links and makes pairs of CPV and EMC clusters with smallest distance
342 TIter nextUp(fLinkUpArray) ;
344 AliPHOSLink * linkUp ;
346 AliPHOSCpvRecPoint * nullpointer = 0 ;
348 while ( (linkUp = static_cast<AliPHOSLink *>(nextUp()) ) ){
350 if(emcExist[linkUp->GetEmc()-fEmcFirst] != -1){
352 if(cpvExist[linkUp->GetCpv()-fCpvFirst]){ //CPV still exist
353 new ((* trackSegments)[fNTrackSegments])
354 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(linkUp->GetEmc())) ,
355 dynamic_cast<AliPHOSCpvRecPoint *>(cpvRecPoints->At(linkUp->GetCpv())) ,
356 linkUp->GetTrack()) ;
358 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
360 emcExist[linkUp->GetEmc()-fEmcFirst] = -1 ; //Mark emc that Cpv was found
361 //mark CPV recpoint as already used
362 cpvExist[linkUp->GetCpv()-fCpvFirst] = kFALSE ;
363 } //if CpvUp still exist
367 //look through emc recPoints left without CPV
368 if(emcExist){ //if there is emc rec point
370 for(iEmcRP = 0; iEmcRP < fEmcLast-fEmcFirst ; iEmcRP++ ){
371 if(emcExist[iEmcRP] > 0 ){
372 new ((*trackSegments)[fNTrackSegments])
373 AliPHOSTrackSegment(dynamic_cast<AliPHOSEmcRecPoint *>(emcRecPoints->At(iEmcRP+fEmcFirst)),
375 (dynamic_cast<AliPHOSTrackSegment *>(trackSegments->At(fNTrackSegments)))->SetIndexInList(fNTrackSegments);
384 //____________________________________________________________________________
385 void AliPHOSTrackSegmentMakerv1::Exec(Option_t *option)
387 // Steering method to perform track segment construction for events
388 // in the range from fFirstEvent to fLastEvent.
389 // This range is optionally set by SetEventRange().
390 // if fLastEvent=-1 (by default), then process events until the end.
392 if(strstr(option,"tim"))
393 gBenchmark->Start("PHOSTSMaker");
395 if(strstr(option,"print")) {
400 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
402 const AliPHOSGeometry * geom = gime->PHOSGeometry() ;
404 if (fLastEvent == -1)
405 fLastEvent = gime->MaxEvent() - 1 ;
407 fLastEvent = TMath::Min(fFirstEvent,gime->MaxEvent());
408 Int_t nEvents = fLastEvent - fFirstEvent + 1;
411 for (ievent = fFirstEvent; ievent <= fLastEvent; ievent++) {
412 gime->Event(ievent,"R") ;
413 //Make some initializations
414 fNTrackSegments = 0 ;
420 gime->TrackSegments()->Clear();
422 // if(!ReadRecPoints(ievent)) continue; //reads RecPoints for event ievent
424 for(fModule = 1; fModule <= geom->GetNModules() ; fModule++ ) {
430 WriteTrackSegments() ;
432 if(strstr(option,"deb"))
433 PrintTrackSegments(option);
435 //increment the total number of track segments per run
436 fTrackSegmentsInRun += gime->TrackSegments()->GetEntriesFast() ;
439 if(strstr(option,"tim")){
440 gBenchmark->Stop("PHOSTSMaker");
441 Info("Exec", "took %f seconds for making TS %f seconds per event",
442 gBenchmark->GetCpuTime("PHOSTSMaker"),
443 gBenchmark->GetCpuTime("PHOSTSMaker")/nEvents) ;
445 if(fWrite) //do not unload in "on flight" mode
449 //____________________________________________________________________________
450 void AliPHOSTrackSegmentMakerv1::Unload()
452 // Unloads the task from the folder
453 AliPHOSGetter * gime = AliPHOSGetter::Instance() ;
454 gime->PhosLoader()->UnloadRecPoints() ;
455 gime->PhosLoader()->UnloadTracks() ;
458 //____________________________________________________________________________
459 void AliPHOSTrackSegmentMakerv1::Print()const
461 // Print TrackSegmentMaker parameters
463 TString message("") ;
464 if( strcmp(GetName(), "") != 0 ) {
465 message = "\n======== AliPHOSTrackSegmentMakerv1 ========\n" ;
466 message += "Making Track segments\n" ;
467 message += "with parameters:\n" ;
468 message += " Maximal EMC - CPV distance (cm) %f\n" ;
469 message += "============================================\n" ;
470 Info("Print", message.Data(),fRcpv) ;
473 Info("Print", "AliPHOSTrackSegmentMakerv1 not initialized ") ;
476 //____________________________________________________________________________
477 void AliPHOSTrackSegmentMakerv1::WriteTrackSegments()
479 // Writes found TrackSegments to TreeR. Creates branches
480 // "PHOSTS" and "AliPHOSTrackSegmentMaker" with the same title.
481 // In the former branch found TrackSegments are stored, while
482 // in the latter all parameters, with which TS were made.
483 // ROOT does not allow overwriting existing branches, therefore
484 // first we check, if branches with the same title already exist.
485 // If yes - exits without writing.
487 AliPHOSGetter *gime = AliPHOSGetter::Instance() ;
489 TClonesArray * trackSegments = gime->TrackSegments() ;
490 trackSegments->Expand(trackSegments->GetEntriesFast()) ;
492 if(fWrite){ //We write TreeT
493 TTree * treeT = gime->TreeT();
496 Int_t bufferSize = 32000 ;
497 TBranch * tsBranch = treeT->Branch("PHOSTS",&trackSegments,bufferSize);
500 gime->WriteTracks("OVERWRITE");
501 gime->WriteTrackSegmentMaker("OVERWRITE");
506 //____________________________________________________________________________
507 void AliPHOSTrackSegmentMakerv1::PrintTrackSegments(Option_t * option)
509 // option deb - prints # of found TrackSegments
510 // option deb all - prints as well indexed of found RecParticles assigned to the TS
512 TClonesArray * trackSegments = AliPHOSGetter::Instance()->TrackSegments() ;
514 Info("PrintTrackSegments", "Results from TrackSegmentMaker:") ;
515 printf("nevent: %d\n", gAlice->GetEvNumber()) ;
516 printf(" Found %d TrackSegments\n", trackSegments->GetEntriesFast() );
518 if(strstr(option,"all")) { // printing found TS
519 printf("TrackSegment # EMC RP# CPV RP#\n") ;
521 for (index = 0 ; index <trackSegments->GetEntriesFast() ; index++) {
522 AliPHOSTrackSegment * ts = (AliPHOSTrackSegment * )trackSegments->At(index) ;
523 printf(" %d %d %d \n", ts->GetIndexInList(), ts->GetEmcIndex(), ts->GetCpvIndex() ) ;