AliPhysics  c923f52 (c923f52)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 <TList.h>
23 #include <TMath.h>
24 #include <TString.h>
25 
26 #include "AliAODMCParticle.h"
27 #include "AliLog.h"
28 #include "AliEmcalTrackSelection.h"
29 #include "AliEMCALTriggerPatchInfo.h"
30 #include "AliMCEvent.h"
31 #include "AliPicoTrack.h"
32 #include "AliVCluster.h"
33 #include "AliVEvent.h"
34 #include "AliVParticle.h"
35 #include "AliVTrack.h"
36 
43 
47 
48 namespace EMCalTriggerPtAnalysis {
49 
55 AliEMCalTriggerRecTrackAnalysisComponent::AliEMCalTriggerRecTrackAnalysisComponent() :
57  fTrackSelection(NULL),
58  fSwapEta(kFALSE),
59  fRequestMCtrue(kFALSE),
60  fDoMatchPatches(kFALSE)
61 {
62 }
63 
72  fTrackSelection(NULL),
73  fSwapEta(kFALSE),
74  fRequestMCtrue(kFALSE),
75  fDoMatchPatches(kFALSE)
76 {
77 }
78 
86 }
87 
105 
106  // Create trigger definitions
107  std::map<std::string, std::string> triggerCombinations;
108  GetAllTriggerNamesAndTitles(triggerCombinations);
109 
110  // Create axis definitions
111  const AliEMCalTriggerBinningDimension *ptbinning = fBinning->GetBinning("pt"),
112  *etabinning = fBinning->GetBinning("eta"),
113  *phibinning = fBinning->GetBinning("phi"),
114  *vertexbinning = fBinning->GetBinning("zvertex");
115 
116  const TAxis *trackaxes[5] = {
117  DefineAxis("pt", ptbinning),
118  DefineAxis("eta", etabinning),
119  DefineAxis("phi", phibinning),
120  DefineAxis("zvertex", vertexbinning),
121  DefineAxis("mbtrigger", 2, -0.5, 1.5)
122  };
123 
124  // Build histograms
125  for(std::map<std::string,std::string>::iterator it = triggerCombinations.begin(); it != triggerCombinations.end(); ++it){
126  const std::string name = it->first, &title = it->second;
127  fHistos->CreateTHnSparse(Form("hTrackHist%s", name.c_str()), Form("Track-based data for %s events", title.c_str()), 5, trackaxes, "s");
128  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");
129  fHistos->CreateTHnSparse(Form("hMCTrackHist%s", name.c_str()), Form("Track-based data for %s events with MC kinematics", title.c_str()), 5, trackaxes, "s");
130  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");
131  if(fDoMatchPatches){
132  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");
133  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");
134  }
135  }
136 
137  // Correlation Matrix
138  // 1. gen pt
139  // 2. rec pt
140  // 3. rec eta
141  // 4. rec phi
142  const TAxis *corraxes[4] = {
143  DefineAxis("ptgen", ptbinning),
144  DefineAxis("ptrec", ptbinning),
145  DefineAxis("eta", etabinning),
146  DefineAxis("phi", phibinning)
147  };
148  fHistos->CreateTHnSparse("hTrackPtCorrelation", "Correlation matrix for track pt", 4, corraxes);
149 
150  for(int iaxis = 0; iaxis < 5; iaxis++) delete trackaxes[iaxis];
151 }
152 
172  AliDebug(1, Form("Number of matched tracks: %d", data->GetMatchedTrackContainer()->GetEntries()));
173  if(fRequestMCtrue && !data->GetMCEvent()) return;
174 
175  std::vector<std::string> triggernames;
176  this->GetMachingTriggerNames(triggernames);
177 
178  AliVTrack *track(NULL);
179  const AliVParticle *assocMC(NULL);
180  if(!data->GetMatchedTrackContainer()){
181  AliError("No container for matched tracks");
182  return;
183  }
184  TIter trackIter(data->GetMatchedTrackContainer());
185 
186  double weight = 1.;
187  if(fWeightHandler && data->GetMCEvent()){
188  weight = fWeightHandler->GetEventWeight(data->GetMCEvent());
189  }
190  while((track = dynamic_cast<AliVTrack *>(trackIter()))){
191  // Apply track selection
192  assocMC = NULL;
193  if(fKineCuts && !fKineCuts->IsSelected(track)) continue;
195  AliDebug(2, "Track not accepted");
196  continue;
197  }
198 
199  if(fRequestMCtrue){
200  if(!(assocMC = IsMCTrueTrack(track, data->GetMCEvent()))) continue; // Not a true track
201  this->FillCorrelation(assocMC, track);
202  }
203  // Try to match the cluster
204  Bool_t hasCluster = kFALSE;
205  AliVCluster *clust(NULL);
206  AliVTrack *testtrack = track;
207  AliPicoTrack *pictrack = dynamic_cast<AliPicoTrack *>(track);
208  if(pictrack) testtrack = pictrack->GetTrack();
209  if(testtrack->GetEMCALcluster() >= 0 && (clust = dynamic_cast<AliVCluster *>(data->GetClusterContainer()->At(testtrack->GetEMCALcluster()))))
210  hasCluster = kTRUE;
211 
212  // Try to match to EMCAL patches (only in case the event is triggered)
213  TList patches;
214  if(fDoMatchPatches && triggernames.size()) MatchTriggerPatches(track, data->GetTriggerPatchContainer(), patches);
215 
216  // Fill histograms
217  for(std::vector<std::string>::iterator name = triggernames.begin(); name != triggernames.end(); name++){
218  FillHistogram(Form("hTrackHist%s", name->c_str()), track, NULL, data->GetRecEvent(), kFALSE, weight);
219  if(hasCluster) FillHistogram(Form("hTrackInAcceptanceHist%s", name->c_str()), track, NULL, data->GetRecEvent(), kFALSE, weight);
220  Bool_t hasPatch = HasMatchedPatchOfType(*name, patches);
221  if(fDoMatchPatches && hasPatch) FillHistogram(Form("hTrackHistPatchMatch%s", name->c_str()), track, NULL, data->GetRecEvent(), kFALSE, weight);
222  if(assocMC){
223  FillHistogram(Form("hMCTrackHist%s", name->c_str()), track, assocMC, data->GetRecEvent(), kTRUE, weight);
224  if(hasCluster) FillHistogram(Form("hMCTrackInAcceptanceHist%s", name->c_str()), track, assocMC, data->GetRecEvent(), kTRUE, weight);
225  if(fDoMatchPatches && hasPatch) FillHistogram(Form("hMCTrackHistPatchMatch%s", name->c_str()), track, NULL, data->GetRecEvent(), kFALSE, weight);
226  }
227  }
228  }
229 }
230 
242  const AliVTrack* const trk, const AliMCEvent* evnt) const {
243  int label = TMath::Abs(trk->GetLabel());
244  const AliVParticle *mcpart = evnt->GetTrack(label);
245  if(!mcpart) return NULL;
246  const AliAODMCParticle *aodpart = dynamic_cast<const AliAODMCParticle *>(mcpart);
247  if(aodpart){
248  if(!aodpart->IsPhysicalPrimary()) return NULL;
249  } else {
250  if(!evnt->IsPhysicalPrimary(mcpart->GetLabel())) return NULL;
251  }
252  return mcpart;
253 }
254 
275  const TString& histname, const AliVTrack* const trk,
276  const AliVParticle* assocMC, const AliVEvent* const recev,
277  Bool_t useMCkine, Double_t weight) {
278  if(useMCkine && !assocMC) return;
279  double data[5];
280  data[0] = useMCkine ? TMath::Abs(assocMC->Pt()) : TMath::Abs(trk->Pt());
281  data[1] = (fSwapEta ? -1. : 1.) * (useMCkine ? assocMC->Eta() : trk->Eta());
282  data[2] = useMCkine ? assocMC->Phi() : trk->Phi();
283  data[3] = recev->GetPrimaryVertex()->GetZ();
285  fHistos->FillTHnSparse(histname.Data(), data, weight);
286 }
287 
300  const AliVParticle* const genparticle,
301  const AliVParticle* const recparticle, double weight) {
302  double data[4] = {TMath::Abs(genparticle->Pt()), TMath::Abs(recparticle->Pt()), recparticle->Eta(), recparticle->Phi()};
303  fHistos->FillTHnSparse("hTrackPtCorrelation", data, weight);
304 }
305 
314  const AliVTrack* rectrack, const TClonesArray* inputpatches,
315  TList& outputpatches) const {
316  outputpatches.Clear();
317  Double_t etaEMCAL = rectrack->GetTrackEtaOnEMCal(),
318  phiEMCAL = rectrack->GetTrackPhiOnEMCal();
319  for(TIter patchiter = TIter(inputpatches).Begin(); patchiter != TIter::End(); ++patchiter){
320  AliEMCALTriggerPatchInfo *recpatch = static_cast<AliEMCALTriggerPatchInfo *>(*patchiter);
321  double etamin = TMath::Min(recpatch->GetEtaMin(), recpatch->GetEtaMax()),
322  etamax = TMath::Max(recpatch->GetEtaMin(), recpatch->GetEtaMax()),
323  phimin = TMath::Min(recpatch->GetPhiMin(), recpatch->GetPhiMax()),
324  phimax = TMath::Max(recpatch->GetPhiMin(), recpatch->GetPhiMax());
325  if(etaEMCAL >= etamin && etaEMCAL <= etamax && phiEMCAL >= phimin && phiEMCAL <= phimax){
326  // Patch accepted
327  outputpatches.Add(recpatch);
328  }
329  }
330 }
331 
339  TString triggertype, const TList& patches) const {
340  Bool_t hasGammaLow = kFALSE,
341  hasGammaHigh = kFALSE,
342  hasJetLow = kFALSE,
343  hasJetHigh = kFALSE;
344  for(TIter patchIter = TIter(&patches).Begin(); patchIter != TIter::End(); ++patchIter){
345  AliEMCALTriggerPatchInfo *matchedpad = static_cast<AliEMCALTriggerPatchInfo *>(*patchIter);
346  if(matchedpad->IsOfflineSimple()) continue;
347  if(matchedpad->IsJetHigh()) hasJetHigh = kTRUE;
348  if(matchedpad->IsJetLow()) hasJetLow = kTRUE;
349  if(matchedpad->IsGammaHigh()) hasGammaHigh = kTRUE;
350  if(matchedpad->IsGammaLow()) hasGammaLow = kTRUE;
351  }
352  // Evaluate status
353  if((triggertype.Contains("EMCJHigh") || triggertype.Contains("EMCHighJetOnly")) && hasJetHigh) return kTRUE;
354  if((triggertype.Contains("EMCJLow") || triggertype.Contains("EMCLowJetOnly")) && hasJetLow) return kTRUE;
355  if((triggertype.Contains("EMCGHigh") || triggertype.Contains("EMCHighGammaOnly")) && hasGammaHigh) return kTRUE;
356  if((triggertype.Contains("EMCGLow") || triggertype.Contains("EMCLowGammaOnly")) && hasGammaLow) return kTRUE;
357  if(triggertype.Contains("EMCHighBoth") && (hasJetHigh || hasGammaHigh)) return kTRUE;
358  if(triggertype.Contains("EMCLowBoth") && (hasJetLow || hasGammaLow)) return kTRUE;
359  return kFALSE;
360 }
361 
362 } /* namespace EMCalTriggerPtAnalysis */
double Double_t
Definition: External.C:58
const char * title
Definition: MakeQAPdf.C:26
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.
TAxis * DefineAxis(const char *name, const AliEMCalTriggerBinningDimension *binning)
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.
AliEMCalTriggerBinningDimension * GetBinning(const char *name) const
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:59
AliEmcalTrackSelection * fTrackSelection
Track selection cuts used in the analysis.
double GetEventWeight(const AliMCEvent *const event) const
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="")
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.
ClassImp(AliAnalysisTaskCascadeTester) AliAnalysisTaskCascadeTester
virtual bool IsTrackAccepted(AliVTrack *const trk)=0
const Double_t phimin