]> git.uio.no Git - u/mrichter/AliRoot.git/blame - EMCAL/AliEMCALTracker.cxx
Bug fix for HMPID bits in readout list.
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTracker.cxx
CommitLineData
fe17d4cb 1//========================================================================
2// Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved.
3//
4// Author: The ALICE Off-line Project.
5// Contributors are mentioned in the code where appropriate.
6//
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//========================================================================
15//
16// Class AliEMCALTracker
17// -----------------------
18// Implementation of the track matching method between barrel tracks and
19// EMCAL clusters.
20// Besides algorithm implementation, some cuts are required to be set
21// in order to define, for each track, an acceptance window where clusters
22// are searched to find best match (if any).
23// The class accepts as input an ESD container, and works directly on it,
24// simply setting, for each of its tracks, the fEMCALindex flag, for each
25// track which is matched to a cluster.
26// In order to use method, one must launch PropagateBack().
27//
28// ------------------------------------------------------------------------
29// author: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
30//=========================================================================
31
32#include <Riostream.h>
33#include <iomanip>
34
35#include <TFile.h>
36#include <TTree.h>
fe17d4cb 37#include <TList.h>
38#include <TString.h>
39#include <TVector3.h>
40#include <TClonesArray.h>
c61f0e70 41#include <TGeoMatrix.h>
fe17d4cb 42
43#include "AliLog.h"
af885e0f 44#include "AliESDEvent.h"
fe17d4cb 45#include "AliESDtrack.h"
89ffc0b0 46#include "AliESDCaloCluster.h"
fe17d4cb 47#include "AliEMCALRecPoint.h"
48#include "AliRunLoader.h"
49#include "AliEMCALTrack.h"
50#include "AliEMCALLoader.h"
c61f0e70 51#include "AliEMCALGeometry.h"
8ba062b1 52#include "AliEMCALReconstructor.h"
53#include "AliEMCALRecParam.h"
54#include "AliCDBEntry.h"
55#include "AliCDBManager.h"
3e3faf55 56#include "AliEMCALReconstructor.h"
c61f0e70 57
fe17d4cb 58#include "AliEMCALTracker.h"
59
60ClassImp(AliEMCALTracker)
8ba062b1 61
fe17d4cb 62//
63//------------------------------------------------------------------------------
64//
65AliEMCALTracker::AliEMCALTracker()
66 : AliTracker(),
67 fNPropSteps(0),
68 fTrackCorrMode(kTrackCorrNone),
69 fCutX(50.0),
70 fCutY(50.0),
71 fCutZ(50.0),
72 fCutAlphaMin(-200.0),
73 fCutAlphaMax(200.0),
74 fCutAngle(100.0),
5a14e691 75 fMaxDist(10.0),
dcd86c5d 76 fCutNITS(3.0),
77 fCutNTPC(20.0),
fe17d4cb 78 fRho(1.0),
79 fX0(1.0),
80 fTracks(0),
81 fClusters(0),
c61f0e70 82 fMatches(0),
83 fGeom(0)
fe17d4cb 84{
85 //
86 // Default constructor.
87 // Initializes al simple data members to default values,
88 // and all collections to NULL.
89 // Output file name is set to a default value.
90 //
0832a2bf 91 InitParameters();
fe17d4cb 92}
93//
94//------------------------------------------------------------------------------
95//
96AliEMCALTracker::AliEMCALTracker(const AliEMCALTracker& copy)
97 : AliTracker(),
98 fNPropSteps(copy.fNPropSteps),
99 fTrackCorrMode(copy.fTrackCorrMode),
100 fCutX(copy.fCutX),
101 fCutY(copy.fCutY),
102 fCutZ(copy.fCutZ),
103 fCutAlphaMin(copy.fCutAlphaMin),
104 fCutAlphaMax(copy.fCutAlphaMax),
105 fCutAngle(copy.fCutAngle),
106 fMaxDist(copy.fMaxDist),
dcd86c5d 107 fCutNITS(copy.fCutNITS),
108 fCutNTPC(copy.fCutNTPC),
fe17d4cb 109 fRho(copy.fRho),
110 fX0(copy.fX0),
111 fTracks((TObjArray*)copy.fTracks->Clone()),
112 fClusters((TObjArray*)copy.fClusters->Clone()),
c61f0e70 113 fMatches((TList*)copy.fMatches->Clone()),
114 fGeom(copy.fGeom)
fe17d4cb 115{
116 //
117 // Copy constructor
118 // Besides copying all parameters, duplicates all collections.
119 //
120}
121//
122//------------------------------------------------------------------------------
123//
124AliEMCALTracker& AliEMCALTracker::operator=(const AliEMCALTracker& copy)
125{
126 //
127 // Assignment operator.
128 // Besides copying all parameters, duplicates all collections.
129 //
130
131 fCutX = copy.fCutX;
132 fCutY = copy.fCutY;
133 fCutZ = copy.fCutZ;
134 fCutAlphaMin = copy.fCutAlphaMin;
135 fCutAlphaMax = copy.fCutAlphaMax;
136 fCutAngle = copy.fCutAngle;
137 fMaxDist = copy.fMaxDist;
dcd86c5d 138 fCutNITS = copy.fCutNITS;
139 fCutNTPC = copy.fCutNTPC;
fe17d4cb 140
141 fTracks = (TObjArray*)copy.fTracks->Clone();
142 fClusters = (TObjArray*)copy.fClusters->Clone();
143 fMatches = (TList*)copy.fMatches->Clone();
144
c61f0e70 145 fGeom = copy.fGeom;
146
fe17d4cb 147 return (*this);
148}
149//
150//------------------------------------------------------------------------------
151//
8ba062b1 152void AliEMCALTracker::InitParameters()
153{
154 //
155 // Retrieve initialization parameters
156 //
157
158 // Check if the instance of AliEMCALRecParam exists,
3e3faf55 159 const AliEMCALRecParam* recParam = AliEMCALReconstructor::GetRecParam();
3a2a23e1 160
ba6de5ea 161 if(!recParam){
162 AliFatal("Reconstruction parameters for EMCAL not set!");
8ba062b1 163 }
164
ba6de5ea 165 fCutX = recParam->GetTrkCutX();
166 fCutY = recParam->GetTrkCutY();
167 fCutZ = recParam->GetTrkCutZ();
168 fMaxDist = recParam->GetTrkCutR();
169 fCutAngle = recParam->GetTrkCutAngle();
170 fCutAlphaMin = recParam->GetTrkCutAlphaMin();
171 fCutAlphaMax = recParam->GetTrkCutAlphaMax();
dcd86c5d 172 fCutNITS = recParam->GetTrkCutNITS();
173 fCutNTPC = recParam->GetTrkCutNTPC();
3e3faf55 174
8ba062b1 175}
176//
177//------------------------------------------------------------------------------
178//
c61f0e70 179TTree* AliEMCALTracker::SearchTrueMatches()
180{
b9560ae2 181 //Search through the list of
182 //track match candidates and clusters
183 //and look for true matches
184 //
185 //
c61f0e70 186 if (!fClusters) return 0;
187 if (fClusters->IsEmpty()) return 0;
188 if (!fTracks) return 0;
189 if (fTracks->IsEmpty()) return 0;
190
191 TTree *outTree = new TTree("tree", "True matches from event");
192 Int_t indexT, indexC, label;
193 outTree->Branch("indexC", &indexC, "indexC/I");
194 outTree->Branch("indexT", &indexT, "indexT/I");
195 outTree->Branch("label", &label , "label/I");
196
197 Double_t dist;
198 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
199 Int_t it, nTracks = fTracks->GetEntries();
200
201 for (ic = 0; ic < nClusters; ic++) {
202 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
203 label = cluster->Label();
204 indexC = cluster->Index();
205 for (it = 0; it < nTracks; it++) {
206 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
207 if (TMath::Abs(track->GetSeedLabel()) != label) continue;
208 dist = CheckPair(track, cluster);
209 if (dist <= fMaxDist) {
210 indexT = track->GetSeedIndex();
211 outTree->Fill();
212 }
213 }
214 }
215
216 return outTree;
217}
218//
219//------------------------------------------------------------------------------
220//
fe17d4cb 221void AliEMCALTracker::Clear(Option_t* option)
222{
223 //
224 // Clearing method
044225d9 225 // Deletes all objects in arrays and the arrays themselves
fe17d4cb 226 //
227
228 TString opt(option);
229 Bool_t clearTracks = opt.Contains("TRACKS");
230 Bool_t clearClusters = opt.Contains("CLUSTERS");
231 Bool_t clearMatches = opt.Contains("MATCHES");
232 if (opt.Contains("ALL")) {
233 clearTracks = kTRUE;
234 clearClusters = kTRUE;
235 clearMatches = kTRUE;
236 }
237
238 if (fTracks != 0x0 && clearTracks) {
044225d9 239 fTracks->Delete();
240 delete fTracks;
241 fTracks = 0;
fe17d4cb 242 }
243 if (fClusters != 0x0 && clearClusters) {
044225d9 244 fClusters->Delete();
245 delete fClusters;
246 fClusters = 0;
fe17d4cb 247 }
248 if (fMatches != 0x0 && clearMatches) {
044225d9 249 fMatches->Delete();
250 delete fMatches;
251 fMatches = 0;
fe17d4cb 252 }
253}
254//
255//------------------------------------------------------------------------------
256//
257Int_t AliEMCALTracker::LoadClusters(TTree *cTree)
258{
259 //
260 // Load EMCAL clusters in the form of AliEMCALRecPoint,
261 // from simulation temporary files.
262 // (When included in reconstruction chain, this method is used automatically)
263 //
264
265 Clear("CLUSTERS");
266
bce21ea7 267 cTree->SetBranchStatus("*",0); //disable all branches
268 cTree->SetBranchStatus("EMCALECARP",1); //Enable only the branch we need
269
fe17d4cb 270 TBranch *branch = cTree->GetBranch("EMCALECARP");
271 if (!branch) {
c61f0e70 272 AliError("Can't get the branch with the EMCAL clusters");
fe17d4cb 273 return 1;
274 }
275
9596d957 276 TClonesArray *clusters = new TClonesArray("AliEMCALRecPoint", 1000);
fe17d4cb 277 branch->SetAddress(&clusters);
fe17d4cb 278
bce21ea7 279 //cTree->GetEvent(0);
280 branch->GetEntry(0);
9596d957 281 Int_t nClusters = (Int_t)clusters->GetEntries();
bce21ea7 282 if(fClusters) fClusters->Delete();
283 else fClusters = new TObjArray(0);
fe17d4cb 284 for (Int_t i = 0; i < nClusters; i++) {
285 AliEMCALRecPoint *cluster = (AliEMCALRecPoint*)clusters->At(i);
286 if (!cluster) continue;
8ada0ffe 287 if (cluster->GetClusterType() != AliESDCaloCluster::kEMCALClusterv1) continue;
fe17d4cb 288 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
289 fClusters->AddLast(matchCluster);
290 }
3d9e8b15 291
2ad4424e 292 branch->SetAddress(0);
293 clusters->Delete();
294 delete clusters;
3d9e8b15 295 if (fClusters->IsEmpty())
9310749e 296 AliDebug(1,"No clusters collected");
2ad4424e 297
9310749e 298 AliDebug(1,Form("Collected %d clusters (RecPoints)", fClusters->GetEntries()));
fe17d4cb 299
300 return 0;
301}
302//
303//------------------------------------------------------------------------------
304//
af885e0f 305Int_t AliEMCALTracker::LoadClusters(AliESDEvent *esd)
fe17d4cb 306{
307 //
308 // Load EMCAL clusters in the form of AliESDCaloClusters,
309 // from an AliESD object.
310 //
311
312 // make sure that tracks/clusters collections are empty
313 Clear("CLUSTERS");
314
3a2a23e1 315 Int_t start = 0;
316 Int_t nClustersEMC = esd->GetNumberOfCaloClusters();
fe17d4cb 317 Int_t end = start + nClustersEMC;
318
319 fClusters = new TObjArray(0);
320
321 Int_t i;
322 for (i = start; i < end; i++) {
323 AliESDCaloCluster *cluster = esd->GetCaloCluster(i);
324 if (!cluster) continue;
3a2a23e1 325 if (!cluster->IsEMCAL()) continue ;
fe17d4cb 326 AliEMCALMatchCluster *matchCluster = new AliEMCALMatchCluster(i, cluster);
327 fClusters->AddLast(matchCluster);
328 }
3d9e8b15 329 if (fClusters->IsEmpty())
9310749e 330 AliDebug(1,"No clusters collected");
fe17d4cb 331
9310749e 332 AliDebug(1,Form("Collected %d clusters from ESD", fClusters->GetEntries()));
fe17d4cb 333
334 return 0;
335}
336//
337//------------------------------------------------------------------------------
338//
af885e0f 339Int_t AliEMCALTracker::LoadTracks(AliESDEvent *esd)
fe17d4cb 340{
341 //
342 // Load ESD tracks.
343 //
344
345 Clear("TRACKS");
346
347 Int_t nTracks = esd->GetNumberOfTracks();
348 fTracks = new TObjArray(0);
349
350 Int_t i, j;
351 Bool_t isKink;
352 Double_t alpha;
353 for (i = 0; i < nTracks; i++) {
354 AliESDtrack *esdTrack = esd->GetTrack(i);
355 // set by default the value corresponding to "no match"
c61f0e70 356 esdTrack->SetEMCALcluster(kUnmatched);
fe17d4cb 357// if (esdTrack->GetLabel() < 0) continue;
358// if (!(esdTrack->GetStatus() & AliESDtrack::kTOFout)) continue;
359 isKink = kFALSE;
360 for (j = 0; j < 3; j++) {
c61f0e70 361 if (esdTrack->GetKinkIndex(j) != 0) isKink = kTRUE;
fe17d4cb 362 }
363 if (isKink) continue;
364 AliEMCALTrack *track = new AliEMCALTrack(*esdTrack);
c61f0e70 365 track->SetMass(0.13957018);
fe17d4cb 366 // check alpha and reject the tracks which fall outside EMCAL acceptance
367 alpha = track->GetAlpha() * TMath::RadToDeg();
368 if (alpha > -155.0 && alpha < 67.0) {
369 delete track;
370 continue;
371 }
c61f0e70 372// if (!PropagateToEMCAL(track)) {
373// delete track;
374// continue;
375// }
fe17d4cb 376 track->SetSeedIndex(i);
377 track->SetSeedLabel(esdTrack->GetLabel());
378 fTracks->AddLast(track);
379 }
380 if (fTracks->IsEmpty()) {
9310749e 381 AliDebug(1,"No tracks collected");
fe17d4cb 382 }
383
9310749e 384 AliDebug(1,Form("Collected %d tracks", fTracks->GetEntries()));
fe17d4cb 385
386 return 0;
387}
388//
389//------------------------------------------------------------------------------
390//
af885e0f 391Int_t AliEMCALTracker::PropagateBack(AliESDEvent* esd)
fe17d4cb 392{
393 //
394 // Main operation method.
395 // Gets external AliESD containing tracks to be matched.
396 // After executing match finding, stores in the same ESD object all infos
397 // and releases the object for further reconstruction steps.
398 //
3d9e8b15 399 //
400 // Note: should always return 0=OK, because otherwise all tracking
401 // is aborted for this event
402
fe17d4cb 403 if (!esd) {
404 AliError("NULL ESD passed");
405 return 1;
406 }
407
408 // step 1:
409 // if cluster array is empty, cluster are collected
410 // from the passed ESD, and work is done with ESDCaloClusters
c61f0e70 411 Int_t okLoadClusters, nClusters;
fe17d4cb 412 if (!fClusters || (fClusters && fClusters->IsEmpty())) {
fe17d4cb 413 okLoadClusters = LoadClusters(esd);
fe17d4cb 414 }
c61f0e70 415 nClusters = fClusters->GetEntries();
fe17d4cb 416
417 // step 2:
418 // collect ESD tracks
c61f0e70 419 Int_t okLoadTracks = LoadTracks(esd), nTracks;
fe17d4cb 420 if (okLoadTracks) return 3;
c61f0e70 421 nTracks = fTracks->GetEntries();
fe17d4cb 422
423 // step 3:
424 // each track is propagated to the "R" position of each cluster.
425 // The closest cluster is assigned as match.
426 // IF no clusters lie within the maximum allowed distance, no matches are assigned.
427 Int_t nMatches = CreateMatches();
428 if (!nMatches) {
9310749e 429 AliDebug(1,Form("#clusters = %d -- #tracks = %d --> No good matches found.", nClusters, nTracks));
3d9e8b15 430 return 0;
fe17d4cb 431 }
432 else {
9310749e 433 AliDebug(1,Form("#clusters = %d -- #tracks = %d --> Found %d matches.", nClusters, nTracks, nMatches));
fe17d4cb 434 }
435
436 // step 4:
437 // when more than 1 track share the same matched cluster, only the closest one is kept.
438 Int_t nRemoved = SolveCompetitions();
9310749e 439 AliDebug(1,Form("Removed %d duplicate matches", nRemoved));
fe17d4cb 440 if (nRemoved >= nMatches) {
441 AliError("Removed ALL matches! Check the algorithm or data. Nothing to save");
442 return 5;
443 }
444
445 // step 5:
446 // save obtained information setting the 'fEMCALindex' field of AliESDtrack object
33eb9693 447 Int_t nSaved = 0, trackID;
fe17d4cb 448 TListIter iter(fMatches);
449 AliEMCALMatch *match = 0;
450 while ( (match = (AliEMCALMatch*)iter.Next()) ) {
451 if (!match->CanBeSaved()) continue;
452 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(match->GetIndexT());
453 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(match->GetIndexC());
454 trackID = track->GetSeedIndex();
455 AliESDtrack *esdTrack = esd->GetTrack(trackID);
456 if (!esdTrack) continue;
dcd86c5d 457
458 // cut on its and tpc track hits
459 if(esdTrack->GetNcls(0)<=fCutNITS)continue;
460 if(esdTrack->GetNcls(1)<=fCutNTPC)continue;
33eb9693 461
462 esdTrack->SetEMCALcluster(cluster->Index());
fe17d4cb 463 nSaved++;
464 }
465 /*
466 AliEMCALTrack *track = 0;
467 TObjArrayIter tracks(fTracks);
468 while ( (track = (AliEMCALTrack*)tracks.Next()) ) {
469 trackID = track->GetSeedIndex();
470 clusterID = track->GetMatchedClusterIndex();
471 AliESDtrack *esdTrack = esd->GetTrack(trackID);
472 if (!esdTrack) continue;
473 if (clusterID < 0) {
c61f0e70 474 esdTrack->SetEMCALcluster(kUnmatched);
fe17d4cb 475 }
476 else {
477 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(clusterID);
478 if (!cluster) continue;
33eb9693 479
480 esdTrack->SetEMCALcluster(cluster->Index());
fe17d4cb 481 nSaved++;
482 }
483 }
484 */
33eb9693 485 AliDebug(1,Form("Saved %d matches", nSaved));
fe17d4cb 486
487 return 0;
488}
489//
490//------------------------------------------------------------------------------
491//
492void AliEMCALTracker::SetTrackCorrectionMode(Option_t *option)
493{
494 //
495 // Set track correction mode
496 // gest the choice in string format and converts into
497 // internal enum
498 //
499
500 TString opt(option);
501 opt.ToUpper();
502
503 if (!opt.CompareTo("NONE")) {
504 fTrackCorrMode = kTrackCorrNone;
505 }
506 else if (!opt.CompareTo("MMB")) {
507 fTrackCorrMode = kTrackCorrMMB;
508 }
509 else if (!opt.CompareTo("FIXED")) {
510 fTrackCorrMode = kTrackCorrFixed;
511 }
512 else {
513 cerr << "E-AliEMCALTracker::SetTrackCorrectionMode '" << option << "': Unrecognized option" << endl;
514 }
515}
516
517//
518//------------------------------------------------------------------------------
519//
520Double_t AliEMCALTracker::AngleDiff(Double_t angle1, Double_t angle2)
521{
522 //
523 // [PRIVATE]
524 // Given two angles in radiants, it converts them in the range 0-2pi
525 // then computes their true difference, i.e. if the difference a1-a2
526 // results to be larger than 180 degrees, it returns 360 - diff.
527 //
528
529 if (angle1 < 0.0) angle1 += TMath::TwoPi();
530 if (angle1 > TMath::TwoPi()) angle1 -= TMath::TwoPi();
531 if (angle2 < 0.0) angle2 += TMath::TwoPi();
532 if (angle2 > TMath::TwoPi()) angle2 -= TMath::TwoPi();
533
534 Double_t diff = TMath::Abs(angle1 - angle2);
535 if (diff > TMath::Pi()) diff = TMath::TwoPi() - diff;
536
537 if (angle2 > angle1) diff = -diff;
538
539 return diff;
540}
541//
542//------------------------------------------------------------------------------
543//
544Double_t AliEMCALTracker::CheckPair
545(AliEMCALTrack *track, AliEMCALMatchCluster *cl)
546{
547 //
548 // Given a track and a cluster,
549 // propagates the first to the radius of the second.
550 // Then, checks the propagation point against all cuts.
551 // If at least a cut is not passed, a valuer equal to
552 // twice the maximum allowed distance is passed (so the value returned
553 // will not be taken into account when creating matches)
554 //
555
556 // TEMP
557 Bool_t isTrue = kFALSE;
558// if (tr->GetSeedLabel() == cl->Label()) {
559// isTrue = kTRUE;
fe17d4cb 560// }
561
562 // copy track into temporary variable
563 AliEMCALTrack *tr = new AliEMCALTrack(*track);
564
565 Double_t distance = 2.0 * fMaxDist;
566
567 // check against cut on difference 'alpha - phi'
568 Double_t phi = TMath::ATan2(cl->Y(), cl->X());
569 phi = AngleDiff(phi, tr->GetAlpha());
5a14e691 570 if (phi < fCutAlphaMin || phi > fCutAlphaMax){
571 delete tr;
572 return distance;
573 }
fe17d4cb 574
575 // try to propagate to cluster radius
576 // (return the 'distance' value if it fails)
577 Double_t pos[3], &x = pos[0], &y = pos[1], &z = pos[2];
578 Double_t x0, rho;
579 tr->GetXYZ(pos);
580 Double_t rt = TMath::Sqrt(x*x + y*y);
581 Double_t rc = TMath::Sqrt(cl->X()*cl->X() + cl->Y()*cl->Y());
582
583 if (fTrackCorrMode == kTrackCorrMMB) {
584 Double_t pos1[3], pos2[3], param[6];
585 pos1[0] = x;
586 pos1[1] = y;
587 pos1[2] = z;
588 pos2[0] = cl->X();
589 pos2[1] = cl->Y();
590 pos2[2] = cl->Z();
c3c15772 591 MeanMaterialBudget(pos1, pos2, param);
592 rho = param[0]*param[4];
fe17d4cb 593 x0 = param[1];
594 }
595 else if (fTrackCorrMode == kTrackCorrFixed) {
596 rho = fRho;
597 x0 = fX0;
598 }
599 else {
600 rho = 0.0;
601 x0 = 0.0;
602 }
603 if (fNPropSteps) {
604 Int_t i;
605 Double_t r;
606 cout.setf(ios::fixed);
607 cout.precision(5);
608 if (isTrue) cout << "Init : " << rt << ' ' << x << ' ' << y << ' ' << z << endl;
609 for (i = 0; i < fNPropSteps; i++) {
610 r = rt + (rc - rt) * ((Double_t)(i+1)/(Double_t)fNPropSteps);
5a14e691 611 if (!tr->PropagateTo(r, x0, rho)){
612 delete tr;
613 return distance;
614 }
fe17d4cb 615 tr->GetXYZ(pos);
616 if (isTrue) cout << "Step : " << r << ' ' << x << ' ' << y << ' ' << z << endl;
617 }
618 if (isTrue) cout << "Clstr: " << rc << ' ' << cl->X() << ' ' << cl->Y() << ' ' << cl->Z() << endl;
619 }
620 else {
621 // when no steps are used, no correction makes sense
c61f0e70 622 //if (!tr->PropagateTo(rc, 0.0, 0.0)) return distance;
5a14e691 623 if (!tr->PropagateToGlobal(cl->X(), cl->Y(), cl->Z(), 0.0, 0.0)){
624 delete tr;
625 return distance;
626 }
c61f0e70 627 /*
628 Bool_t propOK = kFALSE;
629 cout << "START" << endl;
630 Double_t dist, rCHK, bestDist = 10000000.0;
631 for (Double_t rTMP = rc; rTMP> rc*0.95; rTMP -= 0.1) {
632 if (!tr->PropagateTo(rTMP)) continue;
633 propOK = kTRUE;
634 tr->GetXYZ(pos);
635 rCHK = TMath::Sqrt(x*x + y*y);
636 dist = TMath::Abs(rCHK - rc);
637 cout << rCHK << " vs. " << rc << endl;
638
639 if (TMath::Abs(rCHK - rc) < 0.01) break;
640 }
641 cout << "STOP" << endl;
642 if (!propOK) return distance;
643 */
fe17d4cb 644 }
645
646 // get global propagation of track at end of propagation
647 tr->GetXYZ(pos);
648
649 // check angle cut
650 TVector3 vc(cl->X(), cl->Y(), cl->Z());
651 TVector3 vt(x, y, z);
652 Double_t angle = TMath::Abs(vc.Angle(vt)) * TMath::RadToDeg();
c61f0e70 653 // check: where is the track?
654 Double_t r, phiT, phiC;
655 r = TMath::Sqrt(pos[0]*pos[0] + pos[1]*pos[1]);
656 phiT = TMath::ATan2(pos[1], pos[0]) * TMath::RadToDeg();
657 phiC = vc.Phi() * TMath::RadToDeg();
658 //cout << "Propagated R, phiT, phiC = " << r << ' ' << phiT << ' ' << phiC << endl;
659
fe17d4cb 660 if (angle > fCutAngle) {
661 //cout << "angle" << endl;
5a14e691 662 delete tr;
fe17d4cb 663 return distance;
664 }
665
666 // compute differences wr to each coordinate
667 x -= cl->X();
c61f0e70 668 if (TMath::Abs(x) > fCutX) {
fe17d4cb 669 //cout << "cut X" << endl;
5a14e691 670 delete tr;
fe17d4cb 671 return distance;
672 }
673 y -= cl->Y();
c61f0e70 674 if (TMath::Abs(y) > fCutY) {
fe17d4cb 675 //cout << "cut Y" << endl;
5a14e691 676 delete tr;
fe17d4cb 677 return distance;
678 }
679 z -= cl->Z();
c61f0e70 680 if (TMath::Abs(z) > fCutZ) {
fe17d4cb 681 //cout << "cut Z" << endl;
5a14e691 682 delete tr;
fe17d4cb 683 return distance;
684 }
685
686 // compute true distance
687 distance = TMath::Sqrt(x*x + y*y + z*z);
688 //Double_t temp = CheckPairV2(tr, cl);
689 //if (temp < distance) return temp; else
690
691 // delete temporary object
692 delete tr;
693
694 return distance;
695}
696//
697//------------------------------------------------------------------------------
698//
699Double_t AliEMCALTracker::CheckPairV2
700(AliEMCALTrack *tr, AliEMCALMatchCluster *cl)
701{
702 //
703 // Given a track and a cluster,
704 // propagates the first to the radius of the second.
705 // Then, checks the propagation point against all cuts.
706 // If at least a cut is not passed, a valuer equal to
707 // twice the maximum allowed distance is passed (so the value returned
708 // will not be taken into account when creating matches)
709 //
710
711 // TEMP
712// Bool_t isTrue = kFALSE;
713// if (tr->GetSeedLabel() == cl->Label()) {
714// isTrue = kTRUE;
715// cout << "TRUE MATCH!!!" << endl;
716// }
717
718 Double_t distance = 2.0 * fMaxDist;
719
720 Double_t x0, rho;
721 if (fTrackCorrMode == kTrackCorrMMB) {
722 Double_t pos1[3], pos2[3], param[6];
723 tr->GetXYZ(pos1);
724// pos1[0] = x;
725// pos1[1] = y;
726// pos1[2] = z;
727 pos2[0] = cl->X();
728 pos2[1] = cl->Y();
729 pos2[2] = cl->Z();
c3c15772 730 MeanMaterialBudget(pos1, pos2, param);
731 rho = param[0]*param[4];
fe17d4cb 732 x0 = param[1];
733 }
734 else if (fTrackCorrMode == kTrackCorrFixed) {
735 rho = fRho;
736 x0 = fX0;
737 }
738 else {
739 rho = 0.0;
740 x0 = 0.0;
741 }
742
743 // check against cut on difference 'alpha - phi'
744 Double_t phi = TMath::ATan2(cl->Y(), cl->X());
745 phi = AngleDiff(phi, tr->GetAlpha());
746 if (phi < fCutAlphaMin || phi > fCutAlphaMax) return distance;
747
748 // get cluster position and put them into a vector
749 TVector3 vc(cl->X(), cl->Y(), cl->Z());
750 // rotate the vector in order to put all clusters on a plane intersecting
751 // vertically the X axis; the angle depends on the sector
752 Double_t clusterRot, clusterPhi = vc.Phi() * TMath::RadToDeg();
753 if (clusterPhi < 0.0) clusterPhi += 360.0;
754 if (clusterPhi < 100.0) {
755 clusterRot = -90.0;
756 }
757 else if (clusterPhi < 120.0) {
758 clusterRot = -110.0;
759 }
760 else if (clusterPhi < 140.0) {
761 clusterRot = -130.0;
762 }
763 else if (clusterPhi < 160.0) {
764 clusterRot = -150.0;
765 }
766 else if (clusterPhi < 180.0) {
767 clusterRot = -170.0;
768 }
769 else {
770 clusterRot = -190.0;
771 }
772 vc.RotateZ(clusterRot * TMath::DegToRad());
773 // generate a track from the ESD track selected
774 AliEMCALTrack *track = new AliEMCALTrack(*tr);
775 // compute the 'phi' coordinate of the intersection point to
776 // the EMCAL surface
777 Double_t x = vc.X();
778 Double_t y;
779 track->GetYAt(vc.X(), track->GetBz(), y);
780 Double_t tmp = x*TMath::Cos(track->GetAlpha()) - y*TMath::Sin(track->GetAlpha());
781 y = x*TMath::Sin(track->GetAlpha()) + y*TMath::Cos(track->GetAlpha());
782 x = tmp;
783 Double_t trackPhi = TMath::ATan2(y, x) * TMath::RadToDeg();
784 // compute phi difference
785 Double_t dphi = trackPhi - clusterPhi;
786 if (TMath::Abs(dphi) > 180.0) {
787 dphi = 360.0 - TMath::Abs(dphi);
788 if (clusterPhi > trackPhi) dphi = -dphi;
789 }
790 // propagate track to the X position of rotated cluster
791 // and get the vector of X, Y, Z in the local ref. frame of the track
792 track->PropagateTo(vc.X(), x0, rho);
793 TVector3 vt(track->GetX(), track->GetY(), track->GetZ());
794 vt.RotateZ((clusterPhi - trackPhi) * TMath::DegToRad());
795 TVector3 vdiff = vt-vc;
796
797 // compute differences wr to each coordinate
5a14e691 798 delete track;
fe17d4cb 799 if (vdiff.X() > fCutX) return distance;
800 if (vdiff.Y() > fCutY) return distance;
801 if (vdiff.Z() > fCutZ) return distance;
802
803 // compute true distance
804 distance = vdiff.Mag();
805 return distance;
806}
807//
808//------------------------------------------------------------------------------
809//
c61f0e70 810Double_t AliEMCALTracker::CheckPairV3
811(AliEMCALTrack *track, AliEMCALMatchCluster *cl)
812{
813 //
814 // Given a track and a cluster,
815 // propagates the first to the radius of the second.
816 // Then, checks the propagation point against all cuts.
817 // If at least a cut is not passed, a valuer equal to
818 // twice the maximum allowed distance is passed (so the value returned
819 // will not be taken into account when creating matches)
820 //
821
822 AliEMCALTrack tr(*track);
823
824 Int_t sector;
825 Double_t distance = 2.0 * fMaxDist;
826 Double_t dx, dy, dz;
827 Double_t phi, alpha, slope, tgtXnum, tgtXden, sectorWidth = 20.0 * TMath::DegToRad();
e77c61fe 828 Double_t xcurr, xprop, param[6] = {0., 0., 0., 0., 0., 0.}, x0, rho, bz;
c61f0e70 829 Double_t x[3], x1[3], x2[3];
830
831 // get initial track position
832 xcurr = tr.GetX();
833
834 // evaluate the EMCAL sector number
835 phi = cl->Phi();
836 if (phi < 0.0) phi += TMath::TwoPi();
837 sector = (Int_t)(phi / sectorWidth);
838 alpha = ((Double_t)sector + 0.5) * sectorWidth;
839 // evaluate the corresponding X for track propagation
840 slope = TMath::Tan(alpha - 0.5*TMath::Pi());
841 tgtXnum = cl->Y() - slope * cl->X();
842 tgtXden = TMath::Sqrt(1.0 + slope*slope);
843 xprop = TMath::Abs(tgtXnum / tgtXden);
844
845 // propagate by small steps
846 tr.GetXYZ(x1);
847 bz = tr.GetBz();
848 if (!tr.GetXYZAt(xprop, bz, x2)) return distance;
849 //AliKalmanTrack::MeanMaterialBudget(x1, x2, param);
e77c61fe 850 rho = param[0]*param[4];
c61f0e70 851 x0 = param[1];
e77c61fe 852 if (!tr.PropagateTo(xprop, x0, rho)) return distance;
c61f0e70 853 //if (!tr.PropagateTo(xprop, 0.0, 0.0)) return distance;
854
855 // get propagated position at the end
856 tr.GetXYZ(x);
857 dx = TMath::Abs(x[0] - cl->X());
858 dy = TMath::Abs(x[1] - cl->Y());
859 dz = TMath::Abs(x[2] - cl->Z());
860 if (dx > fCutX || dy > fCutY || dz > fCutZ) return distance;
861
862 distance = TMath::Sqrt(dx*dx + dy*dy + dz*dz);
863
864 return distance;
865}
866//
867//------------------------------------------------------------------------------
868//
869Bool_t AliEMCALTracker::PropagateToEMCAL(AliEMCALTrack *tr)
870{
871 //
872 // Propagates the track to the proximity of the EMCAL surface
873 //
874
e77c61fe 875 Double_t xcurr, xtemp, xprop = 438.0, step = 10.0, param[6], x0, rho, bz;
c61f0e70 876 Double_t x1[3], x2[3];
877
878 // get initial track position
879 xcurr = tr->GetX();
880
881 // propagate by small steps
882 for (xtemp = xcurr + step; xtemp < xprop; xtemp += step) {
883 // to compute material budget, take current position and
884 // propagated hypothesis without energy loss
885 tr->GetXYZ(x1);
886 bz = tr->GetBz();
887 if (!tr->GetXYZAt(xtemp, bz, x2)) return kFALSE;
c3c15772 888 MeanMaterialBudget(x1, x2, param);
889 rho = param[0]*param[4];
c61f0e70 890 x0 = param[1];
e77c61fe 891 if (!tr->PropagateTo(xtemp, x0, rho)) return kFALSE;
c61f0e70 892 }
893
894 return kTRUE;
895}
896//
897//------------------------------------------------------------------------------
898//
fe17d4cb 899Int_t AliEMCALTracker::CreateMatches()
900{
901 //
902 // Creation of matches between tracks and clusters.
903 // For each ESD track collected by ReadESD(), an AliEMCALTrack is made.
904 // If it finds a cluster close enough to its propagation to EMCAL,
905 // which passes all cuts, its index is stored.
906 // If many clusters are found which satisfy the criteria described above,
907 // only the closest one is stored.
908 // At this level, it is possible that two tracks share the same cluster.
909 //
910
911 // if matches collection is already present, it is deleted
912 if (fMatches) {
913 fMatches->Delete();
914 delete fMatches;
915 }
916 fMatches = new TList;
917
918 // initialize counters and indexes
919 Int_t count = 0;
920 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
921 Int_t it, nTracks = fTracks->GetEntries();
922
923 // external loop on clusters, internal loop on tracks
924 Double_t dist;
925 for (ic = 0; ic < nClusters; ic++) {
fe17d4cb 926 AliEMCALMatchCluster *cluster = (AliEMCALMatchCluster*)fClusters->At(ic);
927 for (it = 0; it < nTracks; it++) {
928 AliEMCALTrack *track = (AliEMCALTrack*)fTracks->At(it);
929 dist = CheckPair(track, cluster);
c61f0e70 930 //cout << dist << endl;
fe17d4cb 931 if (dist <= fMaxDist) {
932 AliEMCALMatch *candidate = new AliEMCALMatch;
933 candidate->SetIndexT(it);
934 candidate->SetIndexC(ic);
935 candidate->SetDistance(dist);
6c23ffed 936 candidate->SetPt(track->GetSignedPt());
fe17d4cb 937 fMatches->Add(candidate);
938 count++;
939 }
940 }
941 }
fe17d4cb 942
943 return count;
944}
945//
946//------------------------------------------------------------------------------
947//
948Int_t AliEMCALTracker::SolveCompetitions()
949{
950 //
951 // Match selector.
952 // The match list is sorted from the best to the worst match, w.r. to the
953 // distance between track prolongation and cluster position.
954 // Based on this criterion, starting from the first (best) match, a flag
955 // is set to both the involved track and cluster, and all matches containing
956 // an already used track or cluster are removed, leaving only the best match
957 // for each cluster.
958 //
959
960 // sort matches with respect to track-cluster distance
961 fMatches->Sort(kSortAscending);
962
963 // keep track of eliminated matches
964 Int_t count = 0;
965
966 // initialize flags to check repetitions
967 Int_t ic, nClusters = (Int_t)fClusters->GetEntries();
968 Int_t it, nTracks = fTracks->GetEntries();
969 Bool_t *usedC = new Bool_t[nClusters];
970 Bool_t *usedT = new Bool_t[nTracks];
971 for (ic = 0; ic < nClusters; ic++) usedC[ic] = kFALSE;
972 for (it = 0; it < nTracks; it++) usedT[it] = kFALSE;
973
974 // loop on matches
975 TListIter iter(fMatches);
976 AliEMCALMatch *match = 0;
977 while ( (match = (AliEMCALMatch*)iter.Next()) ) {
978 ic = match->GetIndexC();
979 it = match->GetIndexT();
980 if (!usedT[it] && !usedC[ic]) {
981 usedT[it] = kTRUE;
982 usedC[ic] = kTRUE;
983 match->CanBeSaved() = kTRUE;
984 }
985 else {
986 count++;
987 }
988 }
989
17773e2e 990 delete [] usedC;
991 delete [] usedT;
992
fe17d4cb 993 return count;
994}
995//
996//------------------------------------------------------------------------------
997//
998void AliEMCALTracker::UnloadClusters()
999{
1000 //
044225d9 1001 // Free memory from all arrays
1002 // This method is called after the local tracking step
1003 // so we can safely delete everything
fe17d4cb 1004 //
1005
044225d9 1006 Clear();
fe17d4cb 1007}
04475328 1008//
1009//------------------------------------------------------------------------------
1010//
1011TVector3 AliEMCALTracker::FindExtrapolationPoint(Double_t x,Double_t y,Double_t z, AliESDtrack *track)
1012{
1013 //Method to determine extrapolation point of track at location x,y,z
1014 AliEMCALTrack *tr = new AliEMCALTrack(*track);
1015 TVector3 error(-100.,-100.,-100.);
1016 if (!tr->PropagateToGlobal(x,y,z, 0.0, 0.0)) {
1017 return error;
1018 }
1019 Double_t pos[3];
1020 tr->GetXYZ(pos);
1021 TVector3 ExTrPos(pos[0],pos[1],pos[2]);
1022 return ExTrPos;
1023}
1024
fe17d4cb 1025//
1026//------------------------------------------------------------------------------
1027//
1028AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliEMCALRecPoint *recPoint)
1029 : fIndex(index),
0f7fcbef 1030 fLabel(recPoint->GetPrimaryIndex()), //wrong! fixed below
fe17d4cb 1031 fX(0.),
1032 fY(0.),
1033 fZ(0.)
1034{
1035 //
1036 // Translates an AliEMCALRecPoint object into the internal format.
1037 // Index of passed cluster in its native array must be specified.
1038 //
1039 TVector3 clpos;
1040 recPoint->GetGlobalPosition(clpos);
1041
1042 fX = clpos.X();
1043 fY = clpos.Y();
1044 fZ = clpos.Z();
0f7fcbef 1045
1046 //AliEMCALRecPoint stores the track labels in the parents
1047 //list, sorted according to the fractional contribution to the
1048 //RecPoint. The zeroth parent gave the highest contribution
1049 Int_t multparent = 0;
1050 Int_t *parents = recPoint->GetParents(multparent);
1051 if(multparent > 0)
1052 fLabel = parents[0];
1053 else
1054 fLabel = -1;
1055
fe17d4cb 1056}
1057//
1058//------------------------------------------------------------------------------
1059//
1060AliEMCALTracker::AliEMCALMatchCluster::AliEMCALMatchCluster(Int_t index, AliESDCaloCluster *caloCluster)
1061 : fIndex(index),
7592dfc4 1062 fLabel(caloCluster->GetLabel()),
fe17d4cb 1063 fX(0.),
1064 fY(0.),
1065 fZ(0.)
1066{
1067 //
1068 // Translates an AliESDCaloCluster object into the internal format.
1069 // Index of passed cluster in its native array must be specified.
1070 //
1071 Float_t clpos[3];
7592dfc4 1072 caloCluster->GetPosition(clpos);
fe17d4cb 1073
1074 fX = (Double_t)clpos[0];
1075 fY = (Double_t)clpos[1];
1076 fZ = (Double_t)clpos[2];
1077}
1078//
1079//------------------------------------------------------------------------------
1080//
1081Int_t AliEMCALTracker::AliEMCALMatch::Compare(const TObject *obj) const
1082{
1083 //
1084 // Tracks compared wrt their distance from matched point
1085 //
1086
1087 AliEMCALTracker::AliEMCALMatch *that = (AliEMCALTracker::AliEMCALMatch*)obj;
1088
c61f0e70 1089 Double_t thisDist = fPt;//fDistance;
1090 Double_t thatDist = that->fPt;//that->GetDistance();
fe17d4cb 1091
1092 if (thisDist > thatDist) return 1;
1093 else if (thisDist < thatDist) return -1;
1094 return 0;
1095}
1096
1097AliEMCALTracker::AliEMCALMatch::AliEMCALMatch()
1098 : TObject(),
1099 fCanBeSaved(kFALSE),
1100 fIndexC(0),
1101 fIndexT(0),
c61f0e70 1102 fDistance(0.),
1103 fPt(0.)
fe17d4cb 1104{
1105 //default constructor
1106
1107}
1108
1109AliEMCALTracker::AliEMCALMatch::AliEMCALMatch(const AliEMCALMatch& copy)
1110 : TObject(),
1111 fCanBeSaved(copy.fCanBeSaved),
1112 fIndexC(copy.fIndexC),
1113 fIndexT(copy.fIndexT),
c61f0e70 1114 fDistance(copy.fDistance),
1115 fPt(copy.fPt)
fe17d4cb 1116{
1117 //copy ctor
1118}