AliPhysics  7f1bdba (7f1bdba)
AliEMCalTriggerRecTrackAnalysisComponent.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2014, 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 #include <map>
16 #include <string>
17 #include <vector>
18 
19 #include <TAxis.h>
20 #include <TClonesArray.h>
21 #include <THistManager.h>
22 #include <TLinearBinning.h>
23 #include <TList.h>
24 #include <TMath.h>
25 #include <TString.h>
26 
27 #include "AliAODMCParticle.h"
28 #include "AliLog.h"
29 #include "AliEmcalTrackSelection.h"
30 #include "AliEMCALTriggerPatchInfo.h"
31 #include "AliMCEvent.h"
32 #include "AliPicoTrack.h"
33 #include "AliVCluster.h"
34 #include "AliVEvent.h"
35 #include "AliVParticle.h"
36 #include "AliVTrack.h"
37 
44 
48 
49 namespace EMCalTriggerPtAnalysis {
50 
56 AliEMCalTriggerRecTrackAnalysisComponent::AliEMCalTriggerRecTrackAnalysisComponent() :
58  fTrackSelection(NULL),
59  fSwapEta(kFALSE),
60  fRequestMCtrue(kFALSE),
61  fDoMatchPatches(kFALSE)
62 {
63 }
64 
73  fTrackSelection(NULL),
74  fSwapEta(kFALSE),
75  fRequestMCtrue(kFALSE),
76  fDoMatchPatches(kFALSE)
77 {
78 }
79 
87 }
88 
106 
107  // Create trigger definitions
108  std::map<std::string, std::string> triggerCombinations;
109  GetAllTriggerNamesAndTitles(triggerCombinations);
110 
111  // Create axis definitions
112  const TBinning *ptbinning = fBinning->GetBinning("pt"),
113  *etabinning = fBinning->GetBinning("eta"),
114  *phibinning = fBinning->GetBinning("phi"),
115  *vertexbinning = fBinning->GetBinning("zvertex");
116 
117  const TAxis *trackaxes[5] = {
118  DefineAxis("pt", *ptbinning),
119  DefineAxis("eta", *etabinning),
120  DefineAxis("phi", *phibinning),
121  DefineAxis("zvertex", *vertexbinning),
122  DefineAxis("mbtrigger", TLinearBinning(2, -0.5, 1.5))
123  };
124 
125  // Build histograms
126  for(std::map<std::string,std::string>::iterator it = triggerCombinations.begin(); it != triggerCombinations.end(); ++it){
127  const std::string name = it->first, &title = it->second;
128  fHistos->CreateTHnSparse(Form("hTrackHist%s", name.c_str()), Form("Track-based data for %s events", title.c_str()), 5, trackaxes, "s");
129  fHistos->CreateTHnSparse(Form("hTrackInAcceptanceHist%s", name.c_str()), Form("Track-based data for %s events for tracks matched to EMCal clusters", title.c_str()), 5, trackaxes, "s");
130  fHistos->CreateTHnSparse(Form("hMCTrackHist%s", name.c_str()), Form("Track-based data for %s events with MC kinematics", title.c_str()), 5, trackaxes, "s");
131  fHistos->CreateTHnSparse(Form("hMCTrackInAcceptanceHist%s", name.c_str()), Form("Track-based data for %s events for tracks matched to EMCal clusters with MC kinematics", title.c_str()), 5, trackaxes, "s");
132  if(fDoMatchPatches){
133  fHistos->CreateTHnSparse(Form("hTrackHistPatchMatch%s", name.c_str()), Form("Track-based data for %s events for tracks matched to EMCal patches", title.c_str()), 5, trackaxes, "s");
134  fHistos->CreateTHnSparse(Form("hMCTrackHistPatchMatch%s", name.c_str()), Form("Track-based data for %s events for tracks matched to EMCal patches with MC kinematics", title.c_str()), 5, trackaxes, "s");
135  }
136  }
137 
138  // Correlation Matrix
139  // 1. gen pt
140  // 2. rec pt
141  // 3. rec eta
142  // 4. rec phi
143  const TAxis *corraxes[4] = {
144  DefineAxis("ptgen", *ptbinning),
145  DefineAxis("ptrec", *ptbinning),
146  DefineAxis("eta", *etabinning),
147  DefineAxis("phi", *phibinning)
148  };
149  fHistos->CreateTHnSparse("hTrackPtCorrelation", "Correlation matrix for track pt", 4, corraxes);
150 
151  for(int iaxis = 0; iaxis < 5; iaxis++) delete trackaxes[iaxis];
152 }
153 
173  AliDebug(1, Form("Number of matched tracks: %d", data->GetMatchedTrackContainer()->GetEntries()));
174  if(fRequestMCtrue && !data->GetMCEvent()) return;
175 
176  std::vector<std::string> triggernames;
177  this->GetMachingTriggerNames(triggernames);
178 
179  AliVTrack *track(NULL);
180  const AliVParticle *assocMC(NULL);
181  if(!data->GetMatchedTrackContainer()){
182  AliError("No container for matched tracks");
183  return;
184  }
185  TIter trackIter(data->GetMatchedTrackContainer());
186 
187  double weight = 1.;
188  if(fWeightHandler && data->GetMCEvent()){
189  weight = fWeightHandler->GetEventWeight(data->GetMCEvent());
190  }
191  while((track = dynamic_cast<AliVTrack *>(trackIter()))){
192  // Apply track selection
193  assocMC = NULL;
194  if(fKineCuts && !fKineCuts->IsSelected(track)) continue;
196  AliDebug(2, "Track not accepted");
197  continue;
198  }
199 
200  if(fRequestMCtrue){
201  if(!(assocMC = IsMCTrueTrack(track, data->GetMCEvent()))) continue; // Not a true track
202  this->FillCorrelation(assocMC, track);
203  }
204  // Try to match the cluster
205  Bool_t hasCluster = kFALSE;
206  AliVCluster *clust(NULL);
207  AliVTrack *testtrack = track;
208  AliPicoTrack *pictrack = dynamic_cast<AliPicoTrack *>(track);
209  if(pictrack) testtrack = pictrack->GetTrack();
210  if(testtrack->GetEMCALcluster() >= 0 && (clust = dynamic_cast<AliVCluster *>(data->GetClusterContainer()->At(testtrack->GetEMCALcluster()))))
211  hasCluster = kTRUE;
212 
213  // Try to match to EMCAL patches (only in case the event is triggered)
214  TList patches;
215  if(fDoMatchPatches && triggernames.size()) MatchTriggerPatches(track, data->GetTriggerPatchContainer(), patches);
216 
217  // Fill histograms
218  for(std::vector<std::string>::iterator name = triggernames.begin(); name != triggernames.end(); name++){
219  FillHistogram(Form("hTrackHist%s", name->c_str()), track, NULL, data->GetRecEvent(), kFALSE, weight);
220  if(hasCluster) FillHistogram(Form("hTrackInAcceptanceHist%s", name->c_str()), track, NULL, data->GetRecEvent(), kFALSE, weight);
221  Bool_t hasPatch = HasMatchedPatchOfType(*name, patches);
222  if(fDoMatchPatches && hasPatch) FillHistogram(Form("hTrackHistPatchMatch%s", name->c_str()), track, NULL, data->GetRecEvent(), kFALSE, weight);
223  if(assocMC){
224  FillHistogram(Form("hMCTrackHist%s", name->c_str()), track, assocMC, data->GetRecEvent(), kTRUE, weight);
225  if(hasCluster) FillHistogram(Form("hMCTrackInAcceptanceHist%s", name->c_str()), track, assocMC, data->GetRecEvent(), kTRUE, weight);
226  if(fDoMatchPatches && hasPatch) FillHistogram(Form("hMCTrackHistPatchMatch%s", name->c_str()), track, NULL, data->GetRecEvent(), kFALSE, weight);
227  }
228  }
229  }
230 }
231 
243  const AliVTrack* const trk, const AliMCEvent* evnt) const {
244  int label = TMath::Abs(trk->GetLabel());
245  const AliVParticle *mcpart = evnt->GetTrack(label);
246  if(!mcpart) return NULL;
247  const AliAODMCParticle *aodpart = dynamic_cast<const AliAODMCParticle *>(mcpart);
248  if(aodpart){
249  if(!aodpart->IsPhysicalPrimary()) return NULL;
250  } else {
251  if(!evnt->IsPhysicalPrimary(mcpart->GetLabel())) return NULL;
252  }
253  return mcpart;
254 }
255 
276  const TString& histname, const AliVTrack* const trk,
277  const AliVParticle* assocMC, const AliVEvent* const recev,
278  Bool_t useMCkine, Double_t weight) {
279  if(useMCkine && !assocMC) return;
280  double data[5];
281  data[0] = useMCkine ? TMath::Abs(assocMC->Pt()) : TMath::Abs(trk->Pt());
282  data[1] = (fSwapEta ? -1. : 1.) * (useMCkine ? assocMC->Eta() : trk->Eta());
283  data[2] = useMCkine ? assocMC->Phi() : trk->Phi();
284  data[3] = recev->GetPrimaryVertex()->GetZ();
286  fHistos->FillTHnSparse(histname.Data(), data, weight);
287 }
288 
301  const AliVParticle* const genparticle,
302  const AliVParticle* const recparticle, double weight) {
303  double data[4] = {TMath::Abs(genparticle->Pt()), TMath::Abs(recparticle->Pt()), recparticle->Eta(), recparticle->Phi()};
304  fHistos->FillTHnSparse("hTrackPtCorrelation", data, weight);
305 }
306 
315  const AliVTrack* rectrack, const TClonesArray* inputpatches,
316  TList& outputpatches) const {
317  outputpatches.Clear();
318  Double_t etaEMCAL = rectrack->GetTrackEtaOnEMCal(),
319  phiEMCAL = rectrack->GetTrackPhiOnEMCal();
320  for(TIter patchiter = TIter(inputpatches).Begin(); patchiter != TIter::End(); ++patchiter){
321  AliEMCALTriggerPatchInfo *recpatch = static_cast<AliEMCALTriggerPatchInfo *>(*patchiter);
322  double etamin = TMath::Min(recpatch->GetEtaMin(), recpatch->GetEtaMax()),
323  etamax = TMath::Max(recpatch->GetEtaMin(), recpatch->GetEtaMax()),
324  phimin = TMath::Min(recpatch->GetPhiMin(), recpatch->GetPhiMax()),
325  phimax = TMath::Max(recpatch->GetPhiMin(), recpatch->GetPhiMax());
326  if(etaEMCAL >= etamin && etaEMCAL <= etamax && phiEMCAL >= phimin && phiEMCAL <= phimax){
327  // Patch accepted
328  outputpatches.Add(recpatch);
329  }
330  }
331 }
332 
340  TString triggertype, const TList& patches) const {
341  Bool_t hasGammaLow = kFALSE,
342  hasGammaHigh = kFALSE,
343  hasJetLow = kFALSE,
344  hasJetHigh = kFALSE;
345  for(TIter patchIter = TIter(&patches).Begin(); patchIter != TIter::End(); ++patchIter){
346  AliEMCALTriggerPatchInfo *matchedpad = static_cast<AliEMCALTriggerPatchInfo *>(*patchIter);
347  if(matchedpad->IsOfflineSimple()) continue;
348  if(matchedpad->IsJetHigh()) hasJetHigh = kTRUE;
349  if(matchedpad->IsJetLow()) hasJetLow = kTRUE;
350  if(matchedpad->IsGammaHigh()) hasGammaHigh = kTRUE;
351  if(matchedpad->IsGammaLow()) hasGammaLow = kTRUE;
352  }
353  // Evaluate status
354  if((triggertype.Contains("EMCJHigh") || triggertype.Contains("EMCHighJetOnly")) && hasJetHigh) return kTRUE;
355  if((triggertype.Contains("EMCJLow") || triggertype.Contains("EMCLowJetOnly")) && hasJetLow) return kTRUE;
356  if((triggertype.Contains("EMCGHigh") || triggertype.Contains("EMCHighGammaOnly")) && hasGammaHigh) return kTRUE;
357  if((triggertype.Contains("EMCGLow") || triggertype.Contains("EMCLowGammaOnly")) && hasGammaLow) return kTRUE;
358  if(triggertype.Contains("EMCHighBoth") && (hasJetHigh || hasGammaHigh)) return kTRUE;
359  if(triggertype.Contains("EMCLowBoth") && (hasJetLow || hasGammaLow)) return kTRUE;
360  return kFALSE;
361 }
362 
363 } /* namespace EMCalTriggerPtAnalysis */
double Double_t
Definition: External.C:58
const char * title
Definition: MakeQAPdf.C:27
Class creating a linear binning, used in the histogram manager.
void GetMachingTriggerNames(std::vector< std::string > &triggernames) const
void FillHistogram(const TString &histname, const AliVTrack *const trk, const AliVParticle *assocMC, const AliVEvent *const recev, Bool_t useMCkine, Double_t weight)
Fill main track-based histogram.
const AliEMCalTriggerWeightHandler * fWeightHandler
Event weight handler.
Interface for binnings used by the histogram handler.
Definition: TBinning.h:21
Analysis component for reconstructed tracks.
const Double_t etamin
Declaration of a management class for trigger classes.
void FillTHnSparse(const char *name, const double *x, double weight=1., Option_t *opt="")
void GetAllTriggerNamesAndTitles(std::map< std::string, std::string > &triggers) const
const AliVParticle * IsMCTrueTrack(const AliVTrack *const trk, const AliMCEvent *evnt) const
Check whether track is a true signal track.
THistManager * fHistos
Histogram container of the analysis component.
const AliEMCalTriggerAnaClassManager * fTriggerClassManager
Global trigger class manager.
virtual void CreateHistos()
Creating histograms for the analysis component.
const AliEMCalTriggerKineCuts * fKineCuts
Kinematical cuts for tracks and particle selection.
Base class for analysis components in the analysis of EMCAL-triggered events.
AliVTrack * GetTrack() const
Definition: AliPicoTrack.h:60
AliEmcalTrackSelection * fTrackSelection
Track selection cuts used in the analysis.
double GetEventWeight(const AliMCEvent *const event) const
virtual PWG::EMCAL::AliEmcalTrackSelResultPtr IsTrackAccepted(AliVTrack *const trk)=0
Interface for track selection code.
Analysis of high- tracks in triggered events.
Bool_t HasMatchedPatchOfType(TString triggertype, const TList &patches) const
const Double_t etamax
void FillCorrelation(const AliVParticle *const genparticle, const AliVParticle *const recparticle, double weight=1.)
void MatchTriggerPatches(const AliVTrack *rectrack, const TClonesArray *inputpatches, TList &outputpatches) const
Simple event container within the high- track analysis.
bool Bool_t
Definition: External.C:53
THnSparse * CreateTHnSparse(const char *name, const char *title, int ndim, const int *nbins, const double *min, const double *max, Option_t *opt="")
Create a new THnSparse within the container.
virtual void Process(const AliEMCalTriggerEventData *const data)
Run track loop on list of matching tracks.
const AliEMCalTriggerBinningComponent * fBinning
Global binning handler.
Event Data used in exchange to the different analysis components.
const Double_t phimin