AliPhysics  9b6b435 (9b6b435)
AliCaloTrackMatcher.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  * *
4  * Author: Daniel Mühlheim *
5  * Version 1.0 *
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 
17 //---------------------------------------------
18 // Basic Track Matching Class
19 //---------------------------------------------
21 
22 
23 #include "AliAnalysisManager.h"
24 #include "AliAODEvent.h"
25 #include "AliCaloTrackMatcher.h"
26 #include "AliEMCALRecoUtils.h"
27 #include "AliESDEvent.h"
28 #include "AliESDtrack.h"
29 #include "AliESDtrackCuts.h"
30 #include "AliInputEventHandler.h"
31 #include "AliTrackerBase.h"
32 #include "AliV0ReaderV1.h"
33 
34 #include "TAxis.h"
35 #include "TChain.h"
36 #include "TH1F.h"
37 #include "TF1.h"
38 
39 #include <vector>
40 #include <map>
41 #include <utility>
42 
43 class iostream;
44 
45 using namespace std;
46 
47 
48 ClassImp(AliCaloTrackMatcher)
49 
50 //________________________________________________________________________
51 AliCaloTrackMatcher::AliCaloTrackMatcher(const char *name, Int_t clusterType, Int_t runningMode) : AliAnalysisTaskSE(name),
52  fClusterType(clusterType),
53  fRunningMode(runningMode),
54  fV0ReaderName(""),
55  fCorrTaskSetting(""),
56  fAnalysisTrainMode("Grid"),
57  fMatchingWindow(200),
58  fMatchingResidual(0.2),
59  fRunNumber(-1),
60  fGeomEMCAL(NULL),
61  fGeomPHOS(NULL),
62  fMapTrackToCluster(),
63  fMapClusterToTrack(),
64  fNEntries(1),
65  fVectorDeltaEtaDeltaPhi(0),
66  fMap_TrID_ClID_ToIndex(),
67  fSecMapTrackToCluster(),
68  fSecMapClusterToTrack(),
69  fSecNEntries(1),
70  fSecVectorDeltaEtaDeltaPhi(0),
71  fSecMap_TrID_ClID_ToIndex(),
72  fSecMap_TrID_ClID_AlreadyTried(),
73  fListHistos(NULL),
74  fHistControlMatches(NULL),
75  fSecHistControlMatches(NULL)
76 {
77  // Default constructor
78  DefineInput(0, TChain::Class());
79 
80  if( !(fRunningMode == 0 || fRunningMode == 1 || fRunningMode == 2 || fRunningMode == 5 || fRunningMode == 6) )
81  AliFatal(Form("AliCaloTrackMatcher: Running mode not defined: '%d' ! Please set a proper mode in the AddTask, returning...",fRunningMode));
82 }
83 
84 //________________________________________________________________________
86  // default deconstructor
87  fMapTrackToCluster.clear();
88  fMapClusterToTrack.clear();
89  fVectorDeltaEtaDeltaPhi.clear();
90  fMap_TrID_ClID_ToIndex.clear();
91 
92  fSecMapTrackToCluster.clear();
93  fSecMapClusterToTrack.clear();
94  fSecVectorDeltaEtaDeltaPhi.clear();
95  fSecMap_TrID_ClID_ToIndex.clear();
96  fSecMap_TrID_ClID_AlreadyTried.clear();
97 
98  if(fHistControlMatches) delete fHistControlMatches;
99  if(fSecHistControlMatches) delete fSecHistControlMatches;
100  if(fAnalysisTrainMode.EqualTo("Grid")){
101  if(fListHistos != NULL){
102  delete fListHistos;
103  }
104  }
105 }
106 
107 //________________________________________________________________________
109  fMapTrackToCluster.clear();
110  fMapClusterToTrack.clear();
111  fVectorDeltaEtaDeltaPhi.clear();
112  fMap_TrID_ClID_ToIndex.clear();
113 
114  fSecMapTrackToCluster.clear();
115  fSecMapClusterToTrack.clear();
116  fSecVectorDeltaEtaDeltaPhi.clear();
117  fSecMap_TrID_ClID_ToIndex.clear();
118  fSecMap_TrID_ClID_AlreadyTried.clear();
119 }
120 
121 //________________________________________________________________________
123  if(fListHistos != NULL){
124  delete fListHistos;
125  fListHistos = NULL;
126  }
127  if(fListHistos == NULL){
128  fListHistos = new TList();
129  fListHistos->SetOwner(kTRUE);
130  fListHistos->SetName(Form("CaloTrackMatcher_%i_%i",fClusterType,fRunningMode));
131  }
132 
133  // Create User Output Objects
134  fHistControlMatches = new TH2F(Form("ControlMatches_%i_%i",fClusterType,fRunningMode),Form("ControlMatches_%i_%i",fClusterType,fRunningMode),7,-0.5,6.5,50,0.05,200.0);
135  SetLogBinningYTH2(fHistControlMatches);
136  fHistControlMatches->GetYaxis()->SetTitle("track pT (GeV/c)");
137  fHistControlMatches->GetXaxis()->SetBinLabel(1,"nTr in");
138  fHistControlMatches->GetXaxis()->SetBinLabel(2,"no inner Tr params || track not in right direction");
139  fHistControlMatches->GetXaxis()->SetBinLabel(3,"failed 1st pro-step");
140  fHistControlMatches->GetXaxis()->SetBinLabel(4,"Tr not in EMCal acc");
141  fHistControlMatches->GetXaxis()->SetBinLabel(5,"failed 2nd pro-step");
142  fHistControlMatches->GetXaxis()->SetBinLabel(6,"w/o match to cluster");
143  fHistControlMatches->GetXaxis()->SetBinLabel(7,"nTr out, w/ match");
144  fListHistos->Add(fHistControlMatches);
145 
146  fSecHistControlMatches = new TH2F(Form("ControlSecMatches_%i_%i",fClusterType,fRunningMode),Form("ControlSecMatches_%i_%i",fClusterType,fRunningMode),7,-0.5,6.5,50,0.05,200.0);
147  SetLogBinningYTH2(fSecHistControlMatches);
148  fSecHistControlMatches->GetYaxis()->SetTitle("track pT (GeV/c)");
149  fSecHistControlMatches->GetXaxis()->SetBinLabel(1,"nTr in");
150  fSecHistControlMatches->GetXaxis()->SetBinLabel(2,"no inner Tr params || track not in right direction");
151  fSecHistControlMatches->GetXaxis()->SetBinLabel(3,"failed 1st pro-step");
152  fSecHistControlMatches->GetXaxis()->SetBinLabel(4,"Tr not in EMCal acc");
153  fSecHistControlMatches->GetXaxis()->SetBinLabel(5,"failed 2nd pro-step");
154  fSecHistControlMatches->GetXaxis()->SetBinLabel(6,"w/o match to cluster");
155  fSecHistControlMatches->GetXaxis()->SetBinLabel(7,"nTr out, w/ match");
156  fListHistos->Add(fSecHistControlMatches);
157 }
158 
159 //________________________________________________________________________
161  // Initialize function to be called once before analysis
162  fMapTrackToCluster.clear();
163  fMapClusterToTrack.clear();
164  fNEntries = 1;
165  fVectorDeltaEtaDeltaPhi.clear();
166  fMap_TrID_ClID_ToIndex.clear();
167 
168  fSecMapTrackToCluster.clear();
169  fSecMapClusterToTrack.clear();
170  fSecNEntries = 1;
171  fSecVectorDeltaEtaDeltaPhi.clear();
172  fSecMap_TrID_ClID_ToIndex.clear();
173  fSecMap_TrID_ClID_AlreadyTried.clear();
174 
175  if(fRunNumber == -1 || fRunNumber != runNumber){
176  if(fClusterType == 1 || fClusterType == 3 || fClusterType == 4){
177  fGeomEMCAL = AliEMCALGeometry::GetInstanceFromRunNumber(runNumber);
178  if(!fGeomEMCAL){ AliFatal("EMCal geometry not initialized!");}
179  }else if(fClusterType == 2){
180  fGeomPHOS = AliPHOSGeometry::GetInstance();
181  if(!fGeomPHOS) AliFatal("PHOS geometry not initialized!");
182  }
183  fRunNumber = runNumber;
184  }
185 }
186 
187 //________________________________________________________________________
189 
190  // main method of AliCaloTrackMatcher, first initialize and then process event
191 
192  //DebugV0Matching();
193 
194  // do processing only for EMCal (1), DCal (3) or PHOS (2) clusters, otherwise do nothing
195  if(fClusterType == 1 || fClusterType == 2 || fClusterType == 3 || fClusterType == 4){
196  Initialize(fInputEvent->GetRunNumber());
197  ProcessEvent(fInputEvent);
198  }
199 
200  //DebugMatching();
201 
202  return;
203 }
204 
205 //________________________________________________________________________
206 void AliCaloTrackMatcher::ProcessEvent(AliVEvent *event){
207  Int_t nClus = 0;
208  TClonesArray * arrClusters = NULL;
209  if(!fCorrTaskSetting.CompareTo("")){
210  nClus = event->GetNumberOfCaloClusters();
211  } else {
212  arrClusters = dynamic_cast<TClonesArray*>(event->FindListObject(Form("%sClustersBranch",fCorrTaskSetting.Data())));
213  if(arrClusters){
214  nClus = arrClusters->GetEntries();
215  }else{
216  AliError(Form("Could not find %sClustersBranch despite correction framework being used!",fCorrTaskSetting.Data()));
217  return;
218  }
219  }
220  Int_t nModules = 0;
221  if(fClusterType == 1 || fClusterType == 3 || fClusterType == 4) nModules = fGeomEMCAL->GetNumberOfSuperModules();
222  else if(fClusterType == 2) nModules = fGeomPHOS->GetNModules();
223 
224  AliESDEvent *esdev = dynamic_cast<AliESDEvent*>(event);
225  AliAODEvent *aodev = 0;
226  if (!esdev) {
227  aodev = dynamic_cast<AliAODEvent*>(event);
228  if (!aodev) {
229  AliError("Task needs AOD or ESD event, returning");
230  return;
231  }
232  }
233  static AliESDtrackCuts *EsdTrackCuts = 0x0;
234  static int prevRun = -1;
235  // Using standard function for setting Cuts
236  if (esdev && (fRunningMode == 0 || fRunningMode == 6)){
237  Int_t runNumber = fInputEvent->GetRunNumber();
238  if (prevRun!=runNumber) {
239  delete EsdTrackCuts;
240  EsdTrackCuts = 0;
241  prevRun = runNumber;
242  }
243  if (!EsdTrackCuts) {
244  // if LHC11a or earlier or if LHC13g or if LHC12a-i -> use 2010 cuts
245  if( (runNumber<=146860) || (runNumber>=197470 && runNumber<=197692) || (runNumber>=172440 && runNumber<=193766) ){
246  if(fRunningMode == 6) EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010(kFALSE);
247  else EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2010();
248  // else if run2 data use 2015 PbPb cuts
249  } else if (runNumber>=209122){
250  //EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2015PbPb();
251  // hard coded track cuts for the moment, because AliESDtrackCuts::GetStandardITSTPCTrackCuts2015PbPb() gives spams warnings
252  EsdTrackCuts = new AliESDtrackCuts();
253  // TPC; clusterCut = 1, cutAcceptanceEdges = kTRUE, removeDistortedRegions = kFALSE
254  EsdTrackCuts->AliESDtrackCuts::SetMinNCrossedRowsTPC(70);
255  EsdTrackCuts->AliESDtrackCuts::SetMinRatioCrossedRowsOverFindableClustersTPC(0.8);
256  EsdTrackCuts->SetCutGeoNcrNcl(2., 130., 1.5, 0.0, 0.0); // only dead zone and not clusters per length
257  //EsdTrackCuts->AliESDtrackCuts::SetCutOutDistortedRegionsTPC(kTRUE);
258  EsdTrackCuts->AliESDtrackCuts::SetMaxChi2PerClusterTPC(4);
259  EsdTrackCuts->AliESDtrackCuts::SetAcceptKinkDaughters(kFALSE);
260  EsdTrackCuts->AliESDtrackCuts::SetRequireTPCRefit(kTRUE);
261  // ITS; selPrimaries = 1
262  EsdTrackCuts->AliESDtrackCuts::SetRequireITSRefit(kTRUE);
263  EsdTrackCuts->AliESDtrackCuts::SetClusterRequirementITS(AliESDtrackCuts::kSPD,
264  AliESDtrackCuts::kAny);
265  if(fRunningMode != 6){
266  EsdTrackCuts->AliESDtrackCuts::SetMaxDCAToVertexXYPtDep("0.0105+0.0350/pt^1.1");
267  EsdTrackCuts->AliESDtrackCuts::SetMaxChi2TPCConstrainedGlobal(36);
268  }
269  EsdTrackCuts->AliESDtrackCuts::SetMaxDCAToVertexZ(2);
270  EsdTrackCuts->AliESDtrackCuts::SetDCAToVertex2D(kFALSE);
271  EsdTrackCuts->AliESDtrackCuts::SetRequireSigmaToVertex(kFALSE);
272  EsdTrackCuts->AliESDtrackCuts::SetMaxChi2PerClusterITS(36);
273  // else use 2011 version of track cuts
274  }else{
275  if(fRunningMode == 6) EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2011(kFALSE);
276  else EsdTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2011();
277  }
278  EsdTrackCuts->SetMaxDCAToVertexZ(2);
279  }
280  }
281 
282  for (Int_t itr=0;itr<event->GetNumberOfTracks();itr++){
283  AliExternalTrackParam *trackParam = 0;
284  AliVTrack *inTrack = 0x0;
285  if(esdev){
286  inTrack = esdev->GetTrack(itr);
287  if(!inTrack) continue;
288  fHistControlMatches->Fill(0.,inTrack->Pt());
289  AliESDtrack *esdt = dynamic_cast<AliESDtrack*>(inTrack);
290 
291  if(fRunningMode == 0){
292  if(TMath::Abs(inTrack->Eta())>0.8 && (fClusterType == 1 || fClusterType == 3 || fClusterType == 4)){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
293  if(TMath::Abs(inTrack->Eta())>0.3 && fClusterType == 2 ){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
294  if(inTrack->Pt()<0.5){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
295  if(!EsdTrackCuts->AcceptTrack(esdt)) {fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
296  }else if(fRunningMode == 5 || fRunningMode == 6){
297  if(TMath::Abs(inTrack->Eta())>0.8 && (fClusterType == 1 || fClusterType == 3 || fClusterType == 4)){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
298  if(TMath::Abs(inTrack->Eta())>0.3 && fClusterType == 2 ){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
299  if(inTrack->Pt()<0.3){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
300 
301  if(fRunningMode == 6){
302  if(!EsdTrackCuts->AcceptTrack(esdt)) {fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
303  }
304  }
305 
306  const AliExternalTrackParam *in = esdt->GetInnerParam();
307  if (!in){AliDebug(2, "Could not get InnerParam of Track, continue"); fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
308  trackParam = new AliExternalTrackParam(*in);
309  } else if(aodev) {
310  inTrack = dynamic_cast<AliVTrack*>(aodev->GetTrack(itr));
311  if(!inTrack) continue;
312  fHistControlMatches->Fill(0.,inTrack->Pt());
313  AliAODTrack *aodt = dynamic_cast<AliAODTrack*>(inTrack);
314 
315  if(fRunningMode == 0){
316  if(inTrack->GetID()<0){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;} // Avoid double counting of tracks
317  if(TMath::Abs(inTrack->Eta())>0.8 && (fClusterType == 1 || fClusterType == 3 || fClusterType == 4)){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
318  if(TMath::Abs(inTrack->Eta())>0.3 && fClusterType == 2 ){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
319  if(inTrack->Pt()<0.5){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
320  if(!aodt->IsHybridGlobalConstrainedGlobal()){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
321  }else if(fRunningMode == 5 || fRunningMode == 6){
322  if(inTrack->GetID()<0){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;} // Avoid double counting of tracks
323  if(TMath::Abs(inTrack->Eta())>0.8 && (fClusterType == 1 || fClusterType == 3 || fClusterType == 4)){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
324  if(TMath::Abs(inTrack->Eta())>0.3 && fClusterType == 2 ){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
325  if(inTrack->Pt()<0.3){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
326 
327  if(fRunningMode == 6){
328  if(!aodt->IsHybridGlobalConstrainedGlobal()){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
329  }
330  }
331 
332  Double_t xyz[3] = {0}, pxpypz[3] = {0}, cv[21] = {0};
333  aodt->GetPxPyPz(pxpypz);
334  aodt->GetXYZ(xyz);
335  aodt->GetCovarianceXYZPxPyPz(cv);
336 
337  // check for EMC tracks already propagated tracks are out of bounds
338  if (fClusterType == 1 || fClusterType == 3 || fClusterType == 4){
339  if( TMath::Abs(aodt->GetTrackEtaOnEMCal()) > 0.75 ){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
340 
341  // conditions for run1
342  if( fClusterType == 1 && nModules < 13 && ( aodt->GetTrackPhiOnEMCal() < 70*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 190*TMath::DegToRad())){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
343 
344  // conditions for run2
345  if( nModules > 12 ){
346  if( fClusterType == 3 && ( aodt->GetTrackPhiOnEMCal() < 250*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 340*TMath::DegToRad()) ){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
347  if( fClusterType == 1 && ( aodt->GetTrackPhiOnEMCal() < 70*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 190*TMath::DegToRad()) ){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
348  if( fClusterType == 4 && ( aodt->GetTrackPhiOnEMCal() < 70*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 190*TMath::DegToRad()) && ( aodt->GetTrackPhiOnEMCal() < 250*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 340*TMath::DegToRad()) ){fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
349  }
350  }
351  trackParam = new AliExternalTrackParam(xyz,pxpypz,cv,aodt->Charge());
352  }
353 
354  if (!trackParam) {AliError("Could not get TrackParameters, continue"); fHistControlMatches->Fill(1.,inTrack->Pt()); continue;}
355  AliExternalTrackParam emcParam(*trackParam);
356  Float_t eta, phi, pt;
357 
358  //propagate tracks to emc surfaces
359  if(fClusterType == 1 || fClusterType == 3 || fClusterType == 4){
360  if (!AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(&emcParam, 440., 0.139, 20., eta, phi, pt)) {
361  delete trackParam;
362  fHistControlMatches->Fill(2.,inTrack->Pt());
363  continue;
364  }
365  if( TMath::Abs(eta) > 0.75 ) {
366  delete trackParam;
367  fHistControlMatches->Fill(3.,inTrack->Pt());
368  continue;
369  }
370  // Save some time and memory in case of no DCal present
371  if( fClusterType == 1 && nModules < 13 && ( phi < 70*TMath::DegToRad() || phi > 190*TMath::DegToRad())){
372  delete trackParam;
373  fHistControlMatches->Fill(3.,inTrack->Pt());
374  continue;
375  }
376  // Save some time and memory in case of run2
377  if( nModules > 12 ){
378  if (fClusterType == 3 && ( phi < 250*TMath::DegToRad() || phi > 340*TMath::DegToRad())){
379  delete trackParam;
380  fHistControlMatches->Fill(3.,inTrack->Pt());
381  continue;
382  }
383  if( fClusterType == 1 && ( phi < 70*TMath::DegToRad() || phi > 190*TMath::DegToRad())){
384  delete trackParam;
385  fHistControlMatches->Fill(3.,inTrack->Pt());
386  continue;
387  }
388  if( fClusterType == 4 && ( phi < 70*TMath::DegToRad() || phi > 190*TMath::DegToRad())
389  && ( phi < 250*TMath::DegToRad() || phi > 340*TMath::DegToRad())){
390  delete trackParam;
391  fHistControlMatches->Fill(3.,inTrack->Pt());
392  continue;
393  }
394  }
395  }else if(fClusterType == 2){
396  if( !AliTrackerBase::PropagateTrackToBxByBz(&emcParam, 460., 0.139, 20, kTRUE, 0.8, -1)){
397  delete trackParam;
398  fHistControlMatches->Fill(2.,inTrack->Pt());
399  continue;
400  }
401  Double_t trkPos[3] = {0,0,0};
402  if(emcParam.GetXYZ(trkPos)){
403  TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
404  if (TMath::Abs(trkPosVec.Eta()) > 0.25 && (fClusterType == 2)){
405  delete trackParam;
406  fHistControlMatches->Fill(3.,inTrack->Pt());
407  continue;
408  }
409  }
410  }
411 
412  Float_t dEta=-999, dPhi=-999;
413  Float_t clsPos[3] = {0.,0.,0.};
414  Double_t exPos[3] = {0.,0.,0.};
415  if (!emcParam.GetXYZ(exPos)){
416  delete trackParam;
417  fHistControlMatches->Fill(2.,inTrack->Pt());
418  continue;
419  }
420 
421  // cout << inTrack->GetID() << " - " << trackParam << endl;
422  // cout << "eta/phi: " << eta << ", " << phi << endl;
423  // cout << "nClus: " << nClus << endl;
424  Int_t nClusterMatchesToTrack = 0;
425  for(Int_t iclus=0;iclus < nClus;iclus++){
426  AliVCluster* cluster = NULL;
427  if(arrClusters){
428  if(esdev){
429  if(arrClusters)
430  cluster = new AliESDCaloCluster(*(AliESDCaloCluster*)arrClusters->At(iclus));
431  } else if(aodev){
432  if(arrClusters)
433  cluster = new AliAODCaloCluster(*(AliAODCaloCluster*)arrClusters->At(iclus));
434  }
435  }
436  else
437  cluster = event->GetCaloCluster(iclus);
438  if (!cluster){
439  if(arrClusters) delete cluster;
440  continue;
441  }
442  // cout << "-------------------------LOOPING: " << iclus << ", " << cluster->GetID() << endl;
443  cluster->GetPosition(clsPos);
444  Double_t dR = TMath::Sqrt(TMath::Power(exPos[0]-clsPos[0],2)+TMath::Power(exPos[1]-clsPos[1],2)+TMath::Power(exPos[2]-clsPos[2],2));
445  //cout << "dR: " << dR << endl;
446  if (dR > fMatchingWindow){
447  if(arrClusters) delete cluster;
448  continue;
449  }
450  Double_t clusterR = TMath::Sqrt( clsPos[0]*clsPos[0] + clsPos[1]*clsPos[1] );
451  AliExternalTrackParam trackParamTmp(emcParam);//Retrieve the starting point every time before the extrapolation
452  if(fClusterType == 1 || fClusterType == 3 || fClusterType == 4){
453  if (!cluster->IsEMCAL()){
454  if(arrClusters) delete cluster;
455  continue;
456  }
457  if(!AliEMCALRecoUtils::ExtrapolateTrackToCluster(&trackParamTmp, cluster, 0.139, 5., dEta, dPhi)){
458  fHistControlMatches->Fill(4.,inTrack->Pt());
459  if(arrClusters) delete cluster;
460  continue;
461  }
462  }else if(fClusterType == 2){
463  if (!cluster->IsPHOS()){
464  if(arrClusters) delete cluster;
465  continue;
466  }
467  if(!AliTrackerBase::PropagateTrackToBxByBz(&trackParamTmp, clusterR, 0.139, 5., kTRUE, 0.8, -1)){
468  fHistControlMatches->Fill(4.,inTrack->Pt());
469  if(arrClusters) delete cluster;
470  continue;
471  }
472  Double_t trkPos[3] = {0,0,0};
473  trackParamTmp.GetXYZ(trkPos);
474  TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
475  TVector3 clsPosVec(clsPos);
476  dPhi = clsPosVec.DeltaPhi(trkPosVec);
477  dEta = clsPosVec.Eta()-trkPosVec.Eta();
478  }
479 
480  Float_t dR2 = dPhi*dPhi + dEta*dEta;
481 
482  //cout << dEta << " - " << dPhi << " - " << dR2 << endl;
483  if(dR2 > fMatchingResidual){
484  if(arrClusters) delete cluster;
485  continue;
486  }
487  nClusterMatchesToTrack++;
488  if(aodev){
489  fMapTrackToCluster.insert(make_pair(itr,cluster->GetID()));
490  fMapClusterToTrack.insert(make_pair(cluster->GetID(),itr));
491  }else{
492  fMapTrackToCluster.insert(make_pair(inTrack->GetID(),cluster->GetID()));
493  fMapClusterToTrack.insert(make_pair(cluster->GetID(),inTrack->GetID()));
494  }
495  fVectorDeltaEtaDeltaPhi.push_back(make_pair(dEta,dPhi));
496  fMap_TrID_ClID_ToIndex[make_pair(inTrack->GetID(),cluster->GetID())] = fNEntries++;
497  if( (Int_t)fVectorDeltaEtaDeltaPhi.size() != (fNEntries-1)) AliFatal("Fatal error in AliCaloTrackMatcher, vector and map are not in sync!");
498  if(arrClusters) delete cluster;
499  }
500  if(nClusterMatchesToTrack == 0) fHistControlMatches->Fill(5.,inTrack->Pt());
501  else fHistControlMatches->Fill(6.,inTrack->Pt());
502  delete trackParam;
503  }
504 
505  return;
506 }
507 
508 //________________________________________________________________________
509 Bool_t AliCaloTrackMatcher::PropagateV0TrackToClusterAndGetMatchingResidual(AliVTrack* inSecTrack, AliVCluster* cluster, AliVEvent* event, Float_t &dEta, Float_t &dPhi){
510 
511  //if V0-track to cluster match is already available return stored residuals
512 // cout << "matching sec track: " << inSecTrack->GetID() << "\t to cluster" << cluster->GetID() << endl;
513  if(GetSecTrackClusterMatchingResidual(inSecTrack->GetID(),cluster->GetID(), dEta, dPhi)){
514 // cout << "RESIDUAL ALREADY AVAILABLE! - " << dEta << "/" << dPhi << endl;
515  return kTRUE;
516  }
517 
518  if(IsSecTrackClusterAlreadyTried(inSecTrack->GetID(),cluster->GetID())){
519  //cout << "PROPAGATION ALREADY FAILED! - " << inSecTrack->GetID() << "/" << cluster->GetID() << endl;
520  return kFALSE;
521  }
522 
523  //cout << "running matching! - " << inSecTrack->GetID() << "/" << cluster->GetID() << endl;
524  //if match has not yet been computed, go on:
525  Int_t nModules = 0;
526  if(fClusterType == 1 || fClusterType == 3 || fClusterType == 4) nModules = fGeomEMCAL->GetNumberOfSuperModules();
527  else if(fClusterType == 2) nModules = fGeomPHOS->GetNModules();
528 
529  AliESDEvent *esdev = dynamic_cast<AliESDEvent*>(event);
530  AliAODEvent *aodev = 0;
531  if (!esdev) {
532  aodev = dynamic_cast<AliAODEvent*>(event);
533  if (!aodev) {
534  AliError("Task needs AOD or ESD event, returning");
535  return kFALSE;
536  }
537  }
538 
539  if(!cluster->IsEMCAL() && !cluster->IsPHOS()){AliError("Cluster is neither EMCAL nor PHOS, returning");return kFALSE;}
540 
541  Float_t clusterPosition[3] = {0,0,0};
542  cluster->GetPosition(clusterPosition);
543  Double_t clusterR = TMath::Sqrt( clusterPosition[0]*clusterPosition[0] + clusterPosition[1]*clusterPosition[1] );
544 
545  if(!inSecTrack) return kFALSE;
546  fSecHistControlMatches->Fill(0.,inSecTrack->Pt());
547 
548  if (inSecTrack->Pt() < 0.3 ) {
549  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
550  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
551  return kFALSE;
552  }
553 
554  AliESDtrack *esdt = dynamic_cast<AliESDtrack*>(inSecTrack);
555  AliAODTrack *aodt = 0;
556  if (!esdt) {
557  aodt = dynamic_cast<AliAODTrack*>(inSecTrack);
558  if (!aodt){
559  AliError("Track is neither ESD nor AOD, continue");
560  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
561  return kFALSE;
562  }
563  }
564 
565  AliExternalTrackParam *trackParam = 0;
566  if (esdt) {
567  const AliExternalTrackParam *in = esdt->GetInnerParam();
568  if (!in){
569  AliDebug(2, "Could not get InnerParam of Track, continue");
570  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
571  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
572  return kFALSE;
573  }
574  trackParam = new AliExternalTrackParam(*in);
575  } else {
576  // check if tracks should be propagated at all
577  if (fClusterType == 1 || fClusterType == 3 || fClusterType == 4){
578  if (TMath::Abs(aodt->GetTrackEtaOnEMCal()) > 0.8){
579  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
580  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
581  return kFALSE;
582  }
583  if( nModules < 13 ){
584  if (( aodt->GetTrackPhiOnEMCal() < 60*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 200*TMath::DegToRad())){
585  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
586  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
587  return kFALSE;
588  }
589  } else if( nModules > 12 ){
590  if (fClusterType == 3 && ( aodt->GetTrackPhiOnEMCal() < 250*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 340*TMath::DegToRad())){
591  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
592  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
593  return kFALSE;
594  }
595  if( fClusterType == 1 && ( aodt->GetTrackPhiOnEMCal() < 60*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 200*TMath::DegToRad())){
596  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
597  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
598  return kFALSE;
599  }
600  if( fClusterType == 4 && ( aodt->GetTrackPhiOnEMCal() < 60*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 200*TMath::DegToRad())
601  && ( aodt->GetTrackPhiOnEMCal() < 250*TMath::DegToRad() || aodt->GetTrackPhiOnEMCal() > 340*TMath::DegToRad()) ){
602  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
603  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
604  return kFALSE;
605  }
606  }
607  } else {
608  if ( aodt->Phi() < 230*TMath::DegToRad() || aodt->Phi() > 350*TMath::DegToRad()){
609  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
610  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
611  return kFALSE;
612  }
613  if (TMath::Abs(aodt->Eta()) > 0.3 ){
614  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
615  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
616  return kFALSE;
617  }
618  }
619 
620  Double_t xyz[3] = {0}, pxpypz[3] = {0}, cv[21] = {0};
621  aodt->GetPxPyPz(pxpypz);
622  aodt->GetXYZ(xyz);
623  aodt->GetCovarianceXYZPxPyPz(cv);
624  trackParam = new AliExternalTrackParam(xyz,pxpypz,cv,aodt->Charge());
625  }
626  if(!trackParam){
627  AliError("Could not get TrackParameters, continue");
628  fSecHistControlMatches->Fill(1.,inSecTrack->Pt());
629  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
630  return kFALSE;
631  }
632 
633  Bool_t propagated = kFALSE;
634  AliExternalTrackParam emcParam(*trackParam);
635  Float_t dPhiTemp = 0;
636  Float_t dEtaTemp = 0;
637 
638  if(cluster->IsEMCAL()){
639  Float_t eta = 0;Float_t phi = 0;Float_t pt = 0;
640  propagated = AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(&emcParam, 430, 0.000510999, 20, eta, phi, pt);
641  if(propagated){
642  if( TMath::Abs(eta) > 0.8 ) {
643  delete trackParam;
644  fSecHistControlMatches->Fill(3.,inSecTrack->Pt());
645  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
646  return kFALSE;
647  }
648  // Save some time and memory in case of no DCal present
649  if( nModules < 13 && ( phi < 60*TMath::DegToRad() || phi > 200*TMath::DegToRad())){
650  delete trackParam;
651  fSecHistControlMatches->Fill(3.,inSecTrack->Pt());
652  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
653  return kFALSE;
654  }
655 
656  propagated = AliEMCALRecoUtils::ExtrapolateTrackToCluster(&emcParam, cluster, 0.000510999, 5, dEtaTemp, dPhiTemp);
657  if(!propagated){
658  delete trackParam;
659  fSecHistControlMatches->Fill(4.,inSecTrack->Pt());
660  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
661  return kFALSE;
662  }
663  }else{
664  delete trackParam;
665  fSecHistControlMatches->Fill(2.,inSecTrack->Pt());
666  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
667  return kFALSE;
668  }
669 
670  }else if(cluster->IsPHOS()){
671  propagated = AliTrackerBase::PropagateTrackToBxByBz(&emcParam, clusterR, 0.000510999, 20, kTRUE, 0.8, -1);
672  if (propagated){
673  Double_t trkPos[3] = {0,0,0};
674  emcParam.GetXYZ(trkPos);
675  TVector3 trkPosVec(trkPos[0],trkPos[1],trkPos[2]);
676  TVector3 clsPosVec(clusterPosition);
677  dPhiTemp = clsPosVec.DeltaPhi(trkPosVec);
678  dEtaTemp = clsPosVec.Eta()-trkPosVec.Eta();
679  }else{
680  delete trackParam;
681  fSecHistControlMatches->Fill(2.,inSecTrack->Pt());
682  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
683  return kFALSE;}
684  }
685 
686  if (propagated){
687  Float_t dR2 = dPhiTemp*dPhiTemp + dEtaTemp*dEtaTemp;
688  //cout << dEtaTemp << " - " << dPhiTemp << " - " << dR2 << endl;
689  if(dR2 > fMatchingResidual){
690  fSecHistControlMatches->Fill(5.,inSecTrack->Pt());
691  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
692  //cout << "NO MATCH! - " << inSecTrack->GetID() << "/" << cluster->GetID() << endl;
693  delete trackParam;
694  return kFALSE;
695  }
696  //cout << "MATCHED!!!!!!!" << endl;
697 
698  if(aodev){
699  //need to search for position in case of AOD
700  Int_t TrackPos = -1;
701  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
702  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
703  if(currTrack->GetID() == inSecTrack->GetID()){
704  TrackPos = iTrack;
705  break;
706  }
707  }
708  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: PropagateV0TrackToClusterAndGetMatchingResidual - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",inSecTrack->GetID()));
709  fSecMapTrackToCluster.insert(make_pair(TrackPos,cluster->GetID()));
710  fSecMapClusterToTrack.insert(make_pair(cluster->GetID(),TrackPos));
711  }else{
712  fSecMapTrackToCluster.insert(make_pair(inSecTrack->GetID(),cluster->GetID()));
713  fSecMapClusterToTrack.insert(make_pair(cluster->GetID(),inSecTrack->GetID()));
714  }
715  fSecVectorDeltaEtaDeltaPhi.push_back(make_pair(dEtaTemp,dPhiTemp));
716  fSecMap_TrID_ClID_ToIndex[make_pair(inSecTrack->GetID(),cluster->GetID())] = fSecNEntries++;
717  if( (Int_t)fSecVectorDeltaEtaDeltaPhi.size() != (fSecNEntries-1)) AliFatal("Fatal error in AliCaloTrackMatcher, vector and map are not in sync!");
718 
719  fSecHistControlMatches->Fill(6.,inSecTrack->Pt());
720  dEta = dEtaTemp;
721  dPhi = dPhiTemp;
722  delete trackParam;
723  return kTRUE;
724  }else AliFatal("Fatal error in AliCaloTrackMatcher, track is labeled as sucessfully propagated although this should be impossible!");
725 
726  fSecMap_TrID_ClID_AlreadyTried[make_pair(inSecTrack->GetID(),cluster->GetID())] = 1.;
727  delete trackParam;
728  return kFALSE;
729 }
730 
731 //________________________________________________________________________
732 //________________________________________________________________________
733 //________________________________________________________________________
734 //________________________________________________________________________
735 //________________________________________________________________________
737  Int_t position = fMap_TrID_ClID_ToIndex[make_pair(trackID,clusterID)];
738  if(position == 0) return kFALSE;
739 
740  pairFloat tempEtaPhi = fVectorDeltaEtaDeltaPhi.at(position-1);
741  dEta = tempEtaPhi.first;
742  dPhi = tempEtaPhi.second;
743  return kTRUE;
744 }
745 //________________________________________________________________________
746 Int_t AliCaloTrackMatcher::GetNMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
747  Int_t matched = 0;
748  multimap<Int_t,Int_t>::iterator it;
749  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
750  if(it->first == clusterID){
751  Float_t tempDEta, tempDPhi;
752  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
753  if(!tempTrack) continue;
754  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
755  if(tempTrack->Charge()>0){
756  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) matched++;
757  }else if(tempTrack->Charge()<0){
758  dPhiMin*=-1;
759  dPhiMax*=-1;
760  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) matched++;
761  }
762  }
763  }
764  }
765 
766  return matched;
767 }
768 
769 //________________________________________________________________________
770 Int_t AliCaloTrackMatcher::GetNMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
771  Int_t matched = 0;
772  multimap<Int_t,Int_t>::iterator it;
773  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
774  if(it->first == clusterID){
775  Float_t tempDEta, tempDPhi;
776  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
777  if(!tempTrack) continue;
778  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
779  Bool_t match_dEta = kFALSE;
780  Bool_t match_dPhi = kFALSE;
781  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
782  else match_dEta = kFALSE;
783 
784  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
785  else match_dPhi = kFALSE;
786 
787  if (match_dPhi && match_dEta )matched++;
788  }
789  }
790  }
791  return matched;
792 }
793 
794 //________________________________________________________________________
796  Int_t matched = 0;
797  multimap<Int_t,Int_t>::iterator it;
798  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
799  if(it->first == clusterID){
800  Float_t tempDEta, tempDPhi;
801  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
802  if(!tempTrack) continue;
803  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
804  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) matched++;
805  }
806  }
807  }
808  return matched;
809 }
810 
811 //________________________________________________________________________
812 Int_t AliCaloTrackMatcher::GetNMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
813 
814  Int_t TrackPos = -1;
815  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
816  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
817  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
818  if(currTrack->GetID() == trackID){
819  TrackPos = iTrack;
820  break;
821  }
822  }
823  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
824  }else TrackPos = trackID; // for ESD just take trackID
825 
826  Int_t matched = 0;
827  multimap<Int_t,Int_t>::iterator it;
828  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
829  if(!tempTrack) return matched;
830  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
831  if(it->first == TrackPos){
832  Float_t tempDEta, tempDPhi;
833  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
834  if(tempTrack->Charge()>0){
835  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) matched++;
836  }else if(tempTrack->Charge()<0){
837  dPhiMin*=-1;
838  dPhiMax*=-1;
839  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) matched++;
840  }
841  }
842  }
843  }
844  return matched;
845 }
846 
847 //________________________________________________________________________
848 Int_t AliCaloTrackMatcher::GetNMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
849  Int_t TrackPos = -1;
850  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
851  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
852  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
853  if(currTrack->GetID() == trackID){
854  TrackPos = iTrack;
855  break;
856  }
857  }
858  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
859  }else TrackPos = trackID; // for ESD just take trackID
860 
861  Int_t matched = 0;
862  multimap<Int_t,Int_t>::iterator it;
863  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
864  if(!tempTrack) return matched;
865  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
866  if(it->first == TrackPos){
867  Float_t tempDEta, tempDPhi;
868  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
869  Bool_t match_dEta = kFALSE;
870  Bool_t match_dPhi = kFALSE;
871  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
872  else match_dEta = kFALSE;
873 
874  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
875  else match_dPhi = kFALSE;
876 
877  if (match_dPhi && match_dEta )matched++;
878 
879  }
880  }
881  }
882  return matched;
883 }
884 
885 //________________________________________________________________________
887  Int_t TrackPos = -1;
888  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
889  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
890  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
891  if(currTrack->GetID() == trackID){
892  TrackPos = iTrack;
893  break;
894  }
895  }
896  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
897  }else TrackPos = trackID; // for ESD just take trackID
898 
899  Int_t matched = 0;
900  multimap<Int_t,Int_t>::iterator it;
901  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
902  if(!tempTrack) return matched;
903  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
904  if(it->first == TrackPos){
905  Float_t tempDEta, tempDPhi;
906  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
907  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) matched++;
908  }
909  }
910  }
911  return matched;
912 }
913 
914 //________________________________________________________________________
915 vector<Int_t> AliCaloTrackMatcher::GetMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
916  vector<Int_t> tempMatchedTracks;
917  multimap<Int_t,Int_t>::iterator it;
918  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
919  if(it->first == clusterID){
920  Float_t tempDEta, tempDPhi;
921  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
922  if(!tempTrack) continue;
923  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
924  if(tempTrack->Charge()>0){
925  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) tempMatchedTracks.push_back(it->second);
926  }else if(tempTrack->Charge()<0){
927  dPhiMin*=-1;
928  dPhiMax*=-1;
929  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) tempMatchedTracks.push_back(it->second);
930  }
931  }
932  }
933  }
934  return tempMatchedTracks;
935 }
936 
937 //________________________________________________________________________
938 vector<Int_t> AliCaloTrackMatcher::GetMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
939  vector<Int_t> tempMatchedTracks;
940  multimap<Int_t,Int_t>::iterator it;
941  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
942  if(it->first == clusterID){
943  Float_t tempDEta, tempDPhi;
944  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
945  if(!tempTrack) continue;
946  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
947  Bool_t match_dEta = kFALSE;
948  Bool_t match_dPhi = kFALSE;
949  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
950  else match_dEta = kFALSE;
951 
952  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
953  else match_dPhi = kFALSE;
954 
955  if (match_dPhi && match_dEta )tempMatchedTracks.push_back(it->second);
956 
957  }
958  }
959  }
960  return tempMatchedTracks;
961 }
962 
963 //________________________________________________________________________
964 vector<Int_t> AliCaloTrackMatcher::GetMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dR){
965  vector<Int_t> tempMatchedTracks;
966  multimap<Int_t,Int_t>::iterator it;
967  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it){
968  if(it->first == clusterID){
969  Float_t tempDEta, tempDPhi;
970  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
971  if(!tempTrack) continue;
972  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
973  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) tempMatchedTracks.push_back(it->second);
974  }
975  }
976  }
977  return tempMatchedTracks;
978 }
979 
980 //________________________________________________________________________
981 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
982  Int_t TrackPos = -1;
983  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
984  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
985  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
986  if(currTrack->GetID() == trackID){
987  TrackPos = iTrack;
988  break;
989  }
990  }
991  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
992  }else TrackPos = trackID; // for ESD just take trackID
993 
994  vector<Int_t> tempMatchedClusters;
995  multimap<Int_t,Int_t>::iterator it;
996  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
997  if(!tempTrack) return tempMatchedClusters;
998  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
999  if(it->first == TrackPos){
1000  Float_t tempDEta, tempDPhi;
1001  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1002  if(tempTrack->Charge()>0){
1003  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) tempMatchedClusters.push_back(it->second);
1004  }else if(tempTrack->Charge()<0){
1005  dPhiMin*=-1;
1006  dPhiMax*=-1;
1007  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) tempMatchedClusters.push_back(it->second);
1008  }
1009  }
1010  }
1011  }
1012 
1013  return tempMatchedClusters;
1014 }
1015 
1016 //________________________________________________________________________
1017 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
1018  Int_t TrackPos = -1;
1019  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1020  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1021  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1022  if(currTrack->GetID() == trackID){
1023  TrackPos = iTrack;
1024  break;
1025  }
1026  }
1027  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
1028  }else TrackPos = trackID; // for ESD just take trackID
1029 
1030  vector<Int_t> tempMatchedClusters;
1031  multimap<Int_t,Int_t>::iterator it;
1032  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1033  if(!tempTrack) return tempMatchedClusters;
1034  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
1035  if(it->first == TrackPos){
1036  Float_t tempDEta, tempDPhi;
1037  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1038  Bool_t match_dEta = kFALSE;
1039  Bool_t match_dPhi = kFALSE;
1040  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
1041  else match_dEta = kFALSE;
1042 
1043  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
1044  else match_dPhi = kFALSE;
1045 
1046  if (match_dPhi && match_dEta )tempMatchedClusters.push_back(it->second);
1047  }
1048  }
1049  }
1050  return tempMatchedClusters;
1051 }
1052 
1053 //________________________________________________________________________
1054 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, Float_t dR){
1055  Int_t TrackPos = -1;
1056  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1057  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1058  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1059  if(currTrack->GetID() == trackID){
1060  TrackPos = iTrack;
1061  break;
1062  }
1063  }
1064  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
1065  }else TrackPos = trackID; // for ESD just take trackID
1066 
1067  vector<Int_t> tempMatchedClusters;
1068  multimap<Int_t,Int_t>::iterator it;
1069  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1070  if(!tempTrack) return tempMatchedClusters;
1071  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it){
1072  if(it->first == TrackPos){
1073  Float_t tempDEta, tempDPhi;
1074  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1075  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) tempMatchedClusters.push_back(it->second);
1076  }
1077  }
1078  }
1079  return tempMatchedClusters;
1080 }
1081 
1082 //________________________________________________________________________
1083 //________________________________________________________________________
1084 //________________________________________________________________________
1085 //________________________________________________________________________
1086 //________________________________________________________________________
1088  Int_t position = fSecMap_TrID_ClID_ToIndex[make_pair(trackID,clusterID)];
1089  if(position == 0) return kFALSE;
1090 
1091  pairFloat tempEtaPhi = fSecVectorDeltaEtaDeltaPhi.at(position-1);
1092  dEta = tempEtaPhi.first;
1093  dPhi = tempEtaPhi.second;
1094  return kTRUE;
1095 }
1096 //________________________________________________________________________
1098  Int_t position = fSecMap_TrID_ClID_AlreadyTried[make_pair(trackID,clusterID)];
1099  if(position == 0) return kFALSE;
1100  else return kTRUE;
1101 }
1102 //________________________________________________________________________
1103 Int_t AliCaloTrackMatcher::GetNMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
1104  Int_t matched = 0;
1105  multimap<Int_t,Int_t>::iterator it;
1106  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1107  if(it->first == clusterID){
1108  Float_t tempDEta, tempDPhi;
1109  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1110  if(!tempTrack) continue;
1111  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1112  if(tempTrack->Charge()>0){
1113  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) matched++;
1114  }else if(tempTrack->Charge()<0){
1115  dPhiMin*=-1;
1116  dPhiMax*=-1;
1117  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) matched++;
1118  }
1119  }
1120  }
1121  }
1122 
1123  return matched;
1124 }
1125 
1126 //________________________________________________________________________
1127 Int_t AliCaloTrackMatcher::GetNMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
1128  Int_t matched = 0;
1129  multimap<Int_t,Int_t>::iterator it;
1130  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1131  if(it->first == clusterID){
1132  Float_t tempDEta, tempDPhi;
1133  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1134  if(!tempTrack) continue;
1135  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1136  Bool_t match_dEta = kFALSE;
1137  Bool_t match_dPhi = kFALSE;
1138  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
1139  else match_dEta = kFALSE;
1140 
1141  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
1142  else match_dPhi = kFALSE;
1143 
1144  if (match_dPhi && match_dEta )matched++;
1145  }
1146  }
1147  }
1148 
1149  return matched;
1150 }
1151 
1152 //________________________________________________________________________
1154  Int_t matched = 0;
1155  multimap<Int_t,Int_t>::iterator it;
1156  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1157  if(it->first == clusterID){
1158  Float_t tempDEta, tempDPhi;
1159  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1160  if(!tempTrack) continue;
1161  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1162  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) matched++;
1163  }
1164  }
1165  }
1166 
1167  return matched;
1168 }
1169 
1170 //________________________________________________________________________
1171 Int_t AliCaloTrackMatcher::GetNMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
1172  Int_t TrackPos = -1;
1173  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1174  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1175  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1176  if(currTrack->GetID() == trackID){
1177  TrackPos = iTrack;
1178  break;
1179  }
1180  }
1181  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
1182  }else TrackPos = trackID; // for ESD just take trackID
1183 
1184  Int_t matched = 0;
1185  multimap<Int_t,Int_t>::iterator it;
1186  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1187  if(!tempTrack) return matched;
1188  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1189  if(it->first == TrackPos){
1190  Float_t tempDEta, tempDPhi;
1191  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1192  if(tempTrack->Charge()>0){
1193  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) matched++;
1194  }else if(tempTrack->Charge()<0){
1195  dPhiMin*=-1;
1196  dPhiMax*=-1;
1197  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) matched++;
1198  }
1199  }
1200  }
1201  }
1202 
1203  return matched;
1204 }
1205 
1206 //________________________________________________________________________
1207 Int_t AliCaloTrackMatcher::GetNMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
1208  Int_t TrackPos = -1;
1209  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1210  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1211  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1212  if(currTrack->GetID() == trackID){
1213  TrackPos = iTrack;
1214  break;
1215  }
1216  }
1217  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
1218  }else TrackPos = trackID; // for ESD just take trackID
1219 
1220  Int_t matched = 0;
1221  multimap<Int_t,Int_t>::iterator it;
1222  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1223  if(!tempTrack) return matched;
1224  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1225  if(it->first == TrackPos){
1226  Float_t tempDEta, tempDPhi;
1227  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1228  Bool_t match_dEta = kFALSE;
1229  Bool_t match_dPhi = kFALSE;
1230  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
1231  else match_dEta = kFALSE;
1232 
1233  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
1234  else match_dPhi = kFALSE;
1235 
1236  if (match_dPhi && match_dEta )matched++;
1237 
1238  }
1239  }
1240  }
1241 
1242  return matched;
1243 }
1244 
1245 //________________________________________________________________________
1247  Int_t TrackPos = -1;
1248  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1249  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1250  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1251  if(currTrack->GetID() == trackID){
1252  TrackPos = iTrack;
1253  break;
1254  }
1255  }
1256  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
1257  }else TrackPos = trackID; // for ESD just take trackID
1258 
1259  Int_t matched = 0;
1260  multimap<Int_t,Int_t>::iterator it;
1261  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1262  if(!tempTrack) return matched;
1263  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1264  if(it->first == TrackPos){
1265  Float_t tempDEta, tempDPhi;
1266  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1267  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) matched++;
1268  }
1269  }
1270  }
1271 
1272  return matched;
1273 }
1274 
1275 //________________________________________________________________________
1276 vector<Int_t> AliCaloTrackMatcher::GetMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
1277  vector<Int_t> tempMatchedTracks;
1278  multimap<Int_t,Int_t>::iterator it;
1279  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1280  if(it->first == clusterID){
1281  Float_t tempDEta, tempDPhi;
1282  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1283  if(!tempTrack) continue;
1284  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1285  if(tempTrack->Charge()>0){
1286  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) tempMatchedTracks.push_back(it->second);
1287  }else if(tempTrack->Charge()<0){
1288  dPhiMin*=-1;
1289  dPhiMax*=-1;
1290  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) tempMatchedTracks.push_back(it->second);
1291  }
1292  }
1293  }
1294  }
1295 
1296  return tempMatchedTracks;
1297 }
1298 
1299 //________________________________________________________________________
1300 vector<Int_t> AliCaloTrackMatcher::GetMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
1301  vector<Int_t> tempMatchedTracks;
1302  multimap<Int_t,Int_t>::iterator it;
1303  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1304  if(it->first == clusterID){
1305  Float_t tempDEta, tempDPhi;
1306  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1307  if(!tempTrack) continue;
1308  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1309  Bool_t match_dEta = kFALSE;
1310  Bool_t match_dPhi = kFALSE;
1311  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
1312  else match_dEta = kFALSE;
1313 
1314  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
1315  else match_dPhi = kFALSE;
1316 
1317  if (match_dPhi && match_dEta )tempMatchedTracks.push_back(it->second);
1318  }
1319  }
1320  }
1321 
1322  return tempMatchedTracks;
1323 }
1324 
1325 //________________________________________________________________________
1326 vector<Int_t> AliCaloTrackMatcher::GetMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dR){
1327  vector<Int_t> tempMatchedTracks;
1328  multimap<Int_t,Int_t>::iterator it;
1329  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it){
1330  if(it->first == clusterID){
1331  Float_t tempDEta, tempDPhi;
1332  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(it->second));
1333  if(!tempTrack) continue;
1334  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->first,tempDEta,tempDPhi)){
1335  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) tempMatchedTracks.push_back(it->second);
1336  }
1337  }
1338  }
1339 
1340  return tempMatchedTracks;
1341 }
1342 
1343 //________________________________________________________________________
1344 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin){
1345  Int_t TrackPos = -1;
1346  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1347  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1348  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1349  if(currTrack->GetID() == trackID){
1350  TrackPos = iTrack;
1351  break;
1352  }
1353  }
1354  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
1355  }else TrackPos = trackID; // for ESD just take trackID
1356 
1357  vector<Int_t> tempMatchedClusters;
1358  multimap<Int_t,Int_t>::iterator it;
1359  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1360  if(!tempTrack) return tempMatchedClusters;
1361  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1362  if(it->first == TrackPos){
1363  Float_t tempDEta, tempDPhi;
1364  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1365  if(tempTrack->Charge()>0){
1366  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin < tempDPhi) && (tempDPhi < dPhiMax) ) tempMatchedClusters.push_back(it->second);
1367  }else if(tempTrack->Charge()<0){
1368  dPhiMin*=-1;
1369  dPhiMax*=-1;
1370  if( (dEtaMin < tempDEta) && (tempDEta < dEtaMax) && (dPhiMin > tempDPhi) && (tempDPhi > dPhiMax) ) tempMatchedClusters.push_back(it->second);
1371  }
1372  }
1373  }
1374  }
1375 
1376  return tempMatchedClusters;
1377 }
1378 
1379 //________________________________________________________________________
1380 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, TF1* fFuncPtDepEta, TF1* fFuncPtDepPhi){
1381  Int_t TrackPos = -1;
1382  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1383  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1384  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1385  if(currTrack->GetID() == trackID){
1386  TrackPos = iTrack;
1387  break;
1388  }
1389  }
1390  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
1391  }else TrackPos = trackID; // for ESD just take trackID
1392 
1393  vector<Int_t> tempMatchedClusters;
1394  multimap<Int_t,Int_t>::iterator it;
1395  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1396  if(!tempTrack) return tempMatchedClusters;
1397  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1398  if(it->first == TrackPos){
1399  Float_t tempDEta, tempDPhi;
1400  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1401  Bool_t match_dEta = kFALSE;
1402  Bool_t match_dPhi = kFALSE;
1403  if( TMath::Abs(tempDEta) < fFuncPtDepEta->Eval(tempTrack->Pt())) match_dEta = kTRUE;
1404  else match_dEta = kFALSE;
1405 
1406  if( TMath::Abs(tempDPhi) < fFuncPtDepPhi->Eval(tempTrack->Pt())) match_dPhi = kTRUE;
1407  else match_dPhi = kFALSE;
1408 
1409  if (match_dPhi && match_dEta )tempMatchedClusters.push_back(it->second);
1410  }
1411  }
1412  }
1413 
1414  return tempMatchedClusters;
1415 }
1416 
1417 //________________________________________________________________________
1418 vector<Int_t> AliCaloTrackMatcher::GetMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, Float_t dR){
1419  Int_t TrackPos = -1;
1420  if(event->IsA()==AliAODEvent::Class()){ // for AOD, we have to look for position of track in the event
1421  for (Int_t iTrack = 0; iTrack < event->GetNumberOfTracks(); iTrack++){
1422  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(iTrack));
1423  if(currTrack->GetID() == trackID){
1424  TrackPos = iTrack;
1425  break;
1426  }
1427  }
1428  if(TrackPos == -1) AliFatal(Form("AliCaloTrackMatcher: GetNMatchedClusterIDsForTrack - track (ID: '%i') cannot be retrieved from event, should be impossible as it has been used in maim task before!",trackID));
1429  }else TrackPos = trackID; // for ESD just take trackID
1430 
1431  vector<Int_t> tempMatchedClusters;
1432  multimap<Int_t,Int_t>::iterator it;
1433  AliVTrack* tempTrack = dynamic_cast<AliVTrack*>(event->GetTrack(TrackPos));
1434  if(!tempTrack) return tempMatchedClusters;
1435  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it){
1436  if(it->first == TrackPos){
1437  Float_t tempDEta, tempDPhi;
1438  if(GetTrackClusterMatchingResidual(tempTrack->GetID(),it->second,tempDEta,tempDPhi)){
1439  if (TMath::Sqrt(tempDEta*tempDEta + tempDPhi*tempDPhi) < dR ) tempMatchedClusters.push_back(it->second);
1440  }
1441  }
1442  }
1443 
1444  return tempMatchedClusters;
1445 }
1446 
1447 //________________________________________________________________________
1449  Float_t sumTrackEt = 0.;
1450  vector<Int_t> labelsMatched = GetMatchedTrackIDsForCluster(event, clusterID, dR);
1451  if((Int_t) labelsMatched.size()<1) return sumTrackEt;
1452 
1453  TLorentzVector vecTrack;
1454  for (UInt_t i = 0; i < labelsMatched.size(); i++){
1455  AliVTrack* currTrack = dynamic_cast<AliVTrack*>(event->GetTrack(labelsMatched.at(i)));
1456  if(!currTrack) continue;
1457  vecTrack.SetPxPyPzE(currTrack->Px(),currTrack->Py(),currTrack->Pz(),currTrack->E());
1458  sumTrackEt += vecTrack.Et();
1459  }
1460 
1461  return sumTrackEt;
1462 }
1463 
1464 //________________________________________________________________________
1466  TAxis *axisafter = histoRebin->GetYaxis();
1467  Int_t bins = axisafter->GetNbins();
1468  Double_t from = axisafter->GetXmin();
1469  Double_t to = axisafter->GetXmax();
1470  Double_t *newbins = new Double_t[bins+1];
1471  newbins[0] = from;
1472  Double_t factor = TMath::Power(to/from, 1./bins);
1473  for(Int_t i=1; i<=bins; ++i) newbins[i] = factor * newbins[i-1];
1474  axisafter->Set(bins, newbins);
1475  delete [] newbins;
1476  return;
1477 }
1478 
1479 //________________________________________________________________________
1481  if(fSecVectorDeltaEtaDeltaPhi.size()>0){
1482  cout << "******************************" << endl;
1483  cout << "******************************" << endl;
1484  cout << "NEW EVENT !" << endl;
1485  cout << "vector etaphi:" << endl;
1486  cout << fSecVectorDeltaEtaDeltaPhi.size() << endl;
1487  cout << "multimap" << endl;
1488  mapT::iterator iter = fSecMap_TrID_ClID_ToIndex.begin();
1489  for (iter = fSecMap_TrID_ClID_ToIndex.begin(); iter != fSecMap_TrID_ClID_ToIndex.end(); ++iter){
1490  Float_t dEta, dPhi = 0;
1491  if(!GetSecTrackClusterMatchingResidual(iter->first.first,iter->first.second,dEta,dPhi)) continue;
1492  cout << " [" << iter->first.first << "/" << iter->first.second << ", " << iter->second << "] - (" << dEta << "/" << dPhi << ")" << endl;
1493  }
1494  cout << "mapTrackToCluster" << endl;
1495  AliESDEvent *esdev = dynamic_cast<AliESDEvent*>(fInputEvent);
1496  for (Int_t itr=0;itr<esdev->GetNumberOfTracks();itr++){
1497  AliVTrack *inTrack = esdev->GetTrack(itr);
1498  if(!inTrack) continue;
1499  TString tCharge;
1500  if(inTrack->Charge()>0) tCharge = "+";
1501  else if(inTrack->Charge()<0) tCharge = "-";
1502  cout << itr << " (" << tCharge << ") - " << GetNMatchedClusterIDsForSecTrack(fInputEvent,inTrack->GetID(),5,-5,0.2,-0.4) << "\t\t";
1503  }
1504  cout << endl;
1505  multimap<Int_t,Int_t>::iterator it;
1506  for (it=fSecMapTrackToCluster.begin(); it!=fSecMapTrackToCluster.end(); ++it) cout << it->first << " => " << it->second << '\n';
1507  cout << "mapClusterToTrack" << endl;
1508  Int_t tempClus = it->second;
1509  for (it=fSecMapClusterToTrack.begin(); it!=fSecMapClusterToTrack.end(); ++it) cout << it->first << " => " << it->second << '\n';
1510  vector<Int_t> tempTracks = GetMatchedSecTrackIDsForCluster(fInputEvent,tempClus, 5, -5, 0.2, -0.4);
1511  for(UInt_t iJ=0; iJ<tempTracks.size();iJ++){
1512  cout << tempClus << " - " << tempTracks.at(iJ) << endl;
1513  }
1514  }
1515  return;
1516 }
1517 
1518 //________________________________________________________________________
1520  if(fVectorDeltaEtaDeltaPhi.size()>0){
1521  cout << "******************************" << endl;
1522  cout << "******************************" << endl;
1523  cout << "NEW EVENT !" << endl;
1524  cout << "vector etaphi:" << endl;
1525  cout << fVectorDeltaEtaDeltaPhi.size() << endl;
1526  cout << "multimap" << endl;
1527  mapT::iterator iter = fMap_TrID_ClID_ToIndex.begin();
1528  for (iter = fMap_TrID_ClID_ToIndex.begin(); iter != fMap_TrID_ClID_ToIndex.end(); ++iter){
1529  Float_t dEta, dPhi = 0;
1530  if(!GetTrackClusterMatchingResidual(iter->first.first,iter->first.second,dEta,dPhi)) continue;
1531  cout << " [" << iter->first.first << "/" << iter->first.second << ", " << iter->second << "] - (" << dEta << "/" << dPhi << ")" << endl;
1532  }
1533  cout << "mapTrackToCluster" << endl;
1534  AliESDEvent *esdev = dynamic_cast<AliESDEvent*>(fInputEvent);
1535  for (Int_t itr=0;itr<esdev->GetNumberOfTracks();itr++){
1536  AliVTrack *inTrack = esdev->GetTrack(itr);
1537  if(!inTrack) continue;
1538  TString tCharge;
1539  if(inTrack->Charge()>0) tCharge = "+";
1540  else if(inTrack->Charge()<0) tCharge = "-";
1541  cout << itr << " (" << tCharge << ") - " << GetNMatchedClusterIDsForTrack(fInputEvent,inTrack->GetID(),5,-5,0.2,-0.4) << "\t\t";
1542  }
1543  cout << endl;
1544  multimap<Int_t,Int_t>::iterator it;
1545  for (it=fMapTrackToCluster.begin(); it!=fMapTrackToCluster.end(); ++it) cout << it->first << " => " << it->second << '\n';
1546  cout << "mapClusterToTrack" << endl;
1547  Int_t tempClus = it->second;
1548  for (it=fMapClusterToTrack.begin(); it!=fMapClusterToTrack.end(); ++it) cout << it->first << " => " << it->second << '\n';
1549  vector<Int_t> tempTracks = GetMatchedTrackIDsForCluster(fInputEvent,tempClus, 5, -5, 0.2, -0.4);
1550  for(UInt_t iJ=0; iJ<tempTracks.size();iJ++){
1551  cout << tempClus << " - " << tempTracks.at(iJ) << endl;
1552  }
1553  }
1554  return;
1555 }
double Double_t
Definition: External.C:58
Definition: External.C:236
Int_t GetNMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin)
void ProcessEvent(AliVEvent *event)
Bool_t GetTrackClusterMatchingResidual(Int_t trackID, Int_t clusterID, Float_t &dEta, Float_t &dPhi)
void Initialize(Int_t runNumber)
vector< Int_t > GetMatchedClusterIDsForSecTrack(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin)
Int_t GetNMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin)
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
float Float_t
Definition: External.C:68
virtual void Terminate(Option_t *)
Bool_t GetSecTrackClusterMatchingResidual(Int_t trackID, Int_t clusterID, Float_t &dEta, Float_t &dPhi)
Float_t SumTrackEtAroundCluster(AliVEvent *event, Int_t clusterID, Float_t dR)
Int_t GetNMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin)
vector< Int_t > GetMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin)
virtual void UserExec(Option_t *option)
static Bool_t ExtrapolateTrackToCluster(AliExternalTrackParam *trkParam, const AliVCluster *cluster, Double_t mass, Double_t step, Float_t &tmpEta, Float_t &tmpPhi)
Definition: External.C:220
Int_t GetNMatchedSecTrackIDsForCluster(AliVEvent *event, Int_t trackID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin)
Bool_t PropagateV0TrackToClusterAndGetMatchingResidual(AliVTrack *inSecTrack, AliVCluster *cluster, AliVEvent *event, Float_t &dEta, Float_t &dPhi)
pair< Float_t, Float_t > pairFloat
Bool_t IsSecTrackClusterAlreadyTried(Int_t trackID, Int_t clusterID)
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53
vector< Int_t > GetMatchedClusterIDsForTrack(AliVEvent *event, Int_t trackID, TF1 *fFuncPtDepEta, TF1 *fFuncPtDepPhi)
vector< Int_t > GetMatchedTrackIDsForCluster(AliVEvent *event, Int_t clusterID, Float_t dEtaMax, Float_t dEtaMin, Float_t dPhiMax, Float_t dPhiMin)
void SetLogBinningYTH2(TH2 *histoRebin)