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