AliPhysics  vAN-20150427 (e6e7aad)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros
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 <TList.h>
22 #include <TMath.h>
23 #include <TString.h>
24 
25 #include "AliAODMCParticle.h"
26 #include "AliLog.h"
27 #include "AliEmcalTriggerPatchInfo.h"
28 #include "AliMCEvent.h"
29 #include "AliPicoTrack.h"
30 #include "AliVCluster.h"
31 #include "AliVEvent.h"
32 #include "AliVParticle.h"
33 #include "AliVTrack.h"
34 
42 
46 
47 namespace EMCalTriggerPtAnalysis {
48 
54 AliEMCalTriggerRecTrackAnalysisComponent::AliEMCalTriggerRecTrackAnalysisComponent() :
56  fTrackSelection(NULL),
57  fSwapEta(kFALSE),
58  fTriggerMethod(kTriggerString),
59  fRequestMCtrue(kFALSE)
60 {
61 }
62 
71  fTrackSelection(NULL),
72  fSwapEta(kFALSE),
73  fTriggerMethod(kTriggerString),
74  fRequestMCtrue(kFALSE)
75 {
76 }
77 
85 }
86 
104 
105  // Create trigger definitions
106  std::map<std::string, std::string> triggerCombinations;
107  const char *triggernames[11] = {"MinBias", "EMCJHigh", "EMCJLow", "EMCGHigh",
108  "EMCGLow", "EMCHighBoth", "EMCHighGammaOnly", "EMCHighJetOnly",
109  "EMCLowBoth", "EMCLowGammaOnly", "EMCLowJetOnly"};
110  // Define names and titles for different triggers in the histogram container
111  triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[0], "min. bias events"));
112  triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[1], "jet-triggered events (high threshold)"));
113  triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[2], "jet-triggered events (low threshold)"));
114  triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[3], "gamma-triggered events (high threshold)"));
115  triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[4], "gamma-triggered events (low threshold)"));
116  triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[5], "jet and gamma triggered events (high threshold)"));
117  triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[6], "exclusively gamma-triggered events (high threshold)"));
118  triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[7], "exclusively jet-triggered events (high threshold)"));
119  triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[8], "jet and gamma triggered events (low threshold)"));
120  triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[9], "exclusively gamma-triggered events (low threshold)"));
121  triggerCombinations.insert(std::pair<std::string,std::string>(triggernames[10], "exclusively-triggered events (low threshold)"));
122 
123  // Create axis definitions
124  const AliEMCalTriggerBinningDimension *ptbinning = fBinning->GetBinning("pt"),
125  *etabinning = fBinning->GetBinning("eta"),
126  *phibinning = fBinning->GetBinning("phi"),
127  *vertexbinning = fBinning->GetBinning("zvertex");
128 
129  const TAxis *trackaxes[5] = {
130  DefineAxis("pt", ptbinning),
131  DefineAxis("eta", etabinning),
132  DefineAxis("phi", phibinning),
133  DefineAxis("zvertex", vertexbinning),
134  DefineAxis("mbtrigger", 2, -0.5, 1.5)
135  };
136 
137  // Build histograms
138  for(std::map<std::string,std::string>::iterator it = triggerCombinations.begin(); it != triggerCombinations.end(); ++it){
139  const std::string name = it->first, &title = it->second;
140  fHistos->CreateTHnSparse(Form("hTrackHist%s", name.c_str()), Form("Track-based data for %s events", title.c_str()), 5, trackaxes, "s");
141  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");
142  fHistos->CreateTHnSparse(Form("hMCTrackHist%s", name.c_str()), Form("Track-based data for %s events with MC kinematics", title.c_str()), 5, trackaxes, "s");
143  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");
144  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");
145  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");
146  }
147 
148  // Correlation Matrix
149  // 1. gen pt
150  // 2. rec pt
151  // 3. rec eta
152  // 4. rec phi
153  const TAxis *corraxes[4] = {
154  DefineAxis("ptgen", ptbinning),
155  DefineAxis("ptrec", ptbinning),
156  DefineAxis("eta", etabinning),
157  DefineAxis("phi", phibinning)
158  };
159  fHistos->CreateTHnSparse("hTrackPtCorrelation", "Correlation matrix for track pt", 4, corraxes);
160 
161  for(int iaxis = 0; iaxis < 5; iaxis++) delete trackaxes[iaxis];
162 }
163 
183  AliDebug(1, Form("Number of matched tracks: %d", data->GetMatchedTrackContainer()->GetEntries()));
184  if(fRequestMCtrue && !data->GetMCEvent()) return;
185 
186  std::vector<std::string> triggernames;
187  this->GetMachingTriggerNames(triggernames, fTriggerMethod);
188 
189  AliVTrack *track(NULL);
190  const AliVParticle *assocMC(NULL);
191  if(!data->GetMatchedTrackContainer()){
192  AliError("No container for matched tracks");
193  return;
194  }
195  TIter trackIter(data->GetMatchedTrackContainer());
196 
197  double weight = 1.;
198  if(fWeightHandler && data->GetMCEvent()){
199  weight = fWeightHandler->GetEventWeight(data->GetMCEvent());
200  }
201  while((track = dynamic_cast<AliVTrack *>(trackIter()))){
202  // Apply track selection
203  assocMC = NULL;
204  if(fKineCuts && !fKineCuts->IsSelected(track)) continue;
206  AliDebug(2, "Track not accepted");
207  continue;
208  }
209 
210  if(fRequestMCtrue){
211  if(!(assocMC = IsMCTrueTrack(track, data->GetMCEvent()))) continue; // Not a true track
212  this->FillCorrelation(assocMC, track);
213  }
214  // Try to match the cluster
215  Bool_t hasCluster = kFALSE;
216  AliVCluster *clust(NULL);
217  AliVTrack *testtrack = track;
218  AliPicoTrack *pictrack = dynamic_cast<AliPicoTrack *>(track);
219  if(pictrack) testtrack = pictrack->GetTrack();
220  if(testtrack->GetEMCALcluster() >= 0 && (clust = dynamic_cast<AliVCluster *>(data->GetClusterContainer()->At(testtrack->GetEMCALcluster()))))
221  hasCluster = kTRUE;
222 
223  // Try to match to EMCAL patches (only in case the event is triggered)
224  TList patches;
225  if(triggernames.size()) MatchTriggerPatches(track, data->GetTriggerPatchContainer(), patches);
226 
227  // Fill histograms
228  for(std::vector<std::string>::iterator name = triggernames.begin(); name != triggernames.end(); name++){
229  FillHistogram(Form("hTrackHist%s", name->c_str()), track, NULL, data->GetRecEvent(), kFALSE, weight);
230  if(hasCluster) FillHistogram(Form("hTrackInAcceptanceHist%s", name->c_str()), track, NULL, data->GetRecEvent(), kFALSE, weight);
231  Bool_t hasPatch = HasMatchedPatchOfType(*name, patches);
232  if(hasPatch) FillHistogram(Form("hTrackHistPatchMatch%s", name->c_str()), track, NULL, data->GetRecEvent(), kFALSE, weight);
233  if(assocMC){
234  FillHistogram(Form("hMCTrackHist%s", name->c_str()), track, assocMC, data->GetRecEvent(), kTRUE, weight);
235  if(hasCluster) FillHistogram(Form("hMCTrackInAcceptanceHist%s", name->c_str()), track, assocMC, data->GetRecEvent(), kTRUE, weight);
236  if(hasPatch) FillHistogram(Form("hMCTrackHistPatchMatch%s", name->c_str()), track, NULL, data->GetRecEvent(), kFALSE, weight);
237  }
238  }
239  }
240 }
241 
253  const AliVTrack* const trk, const AliMCEvent* evnt) const {
254  int label = TMath::Abs(trk->GetLabel());
255  const AliVParticle *mcpart = evnt->GetTrack(label);
256  if(!mcpart) return NULL;
257  const AliAODMCParticle *aodpart = dynamic_cast<const AliAODMCParticle *>(mcpart);
258  if(aodpart){
259  if(!aodpart->IsPhysicalPrimary()) return NULL;
260  } else {
261  if(!evnt->IsPhysicalPrimary(label)) return NULL;
262  }
263  return mcpart;
264 }
265 
286  const TString& histname, const AliVTrack* const trk,
287  const AliVParticle* assocMC, const AliVEvent* const recev,
288  Bool_t useMCkine, Double_t weight) {
289  if(useMCkine && !assocMC) return;
290  double data[5];
291  data[0] = useMCkine ? TMath::Abs(assocMC->Pt()) : TMath::Abs(trk->Pt());
292  data[1] = (fSwapEta ? -1. : 1.) * (useMCkine ? assocMC->Eta() : trk->Eta());
293  data[2] = useMCkine ? assocMC->Phi() : trk->Phi();
294  data[3] = recev->GetPrimaryVertex()->GetZ();
295  data[4] = fTriggerDecision->IsMinBias();
296  fHistos->FillTHnSparse(histname.Data(), data, weight);
297 }
298 
311  const AliVParticle* const genparticle,
312  const AliVParticle* const recparticle, double weight) {
313  double data[4] = {TMath::Abs(genparticle->Pt()), TMath::Abs(recparticle->Pt()), recparticle->Eta(), recparticle->Phi()};
314  fHistos->FillTHnSparse("hTrackPtCorrelation", data, weight);
315 }
316 
325  const AliVTrack* rectrack, const TClonesArray* inputpatches,
326  TList& outputpatches) const {
327  outputpatches.Clear();
328  Double_t etaEMCAL = rectrack->GetTrackEtaOnEMCal(),
329  phiEMCAL = rectrack->GetTrackPhiOnEMCal();
330  for(TIter patchiter = TIter(inputpatches).Begin(); patchiter != TIter::End(); ++patchiter){
331  AliEmcalTriggerPatchInfo *recpatch = static_cast<AliEmcalTriggerPatchInfo *>(*patchiter);
332  double etamin = TMath::Min(recpatch->GetEtaMin(), recpatch->GetEtaMax()),
333  etamax = TMath::Max(recpatch->GetEtaMin(), recpatch->GetEtaMax()),
334  phimin = TMath::Min(recpatch->GetPhiMin(), recpatch->GetPhiMax()),
335  phimax = TMath::Max(recpatch->GetPhiMin(), recpatch->GetPhiMax());
336  if(etaEMCAL >= etamin && etaEMCAL <= etamax && phiEMCAL >= phimin && phiEMCAL <= phimax){
337  // Patch accepted
338  outputpatches.Add(recpatch);
339  }
340  }
341 }
342 
350  TString triggertype, const TList& patches) const {
351  Bool_t hasGammaLow = kFALSE,
352  hasGammaHigh = kFALSE,
353  hasJetLow = kFALSE,
354  hasJetHigh = kFALSE;
355  for(TIter patchIter = TIter(&patches).Begin(); patchIter != TIter::End(); ++patchIter){
356  AliEmcalTriggerPatchInfo *matchedpad = static_cast<AliEmcalTriggerPatchInfo *>(*patchIter);
358  if(!matchedpad->IsOfflineSimple()) continue;
359  if(matchedpad->IsJetHighSimple()) hasJetHigh = kTRUE;
360  if(matchedpad->IsJetLowSimple()) hasJetLow = kTRUE;
361  if(matchedpad->IsGammaHighSimple()) hasGammaHigh = kTRUE;
362  if(matchedpad->IsGammaLowSimple()) hasGammaLow = kTRUE;
363  } else {
364  if(matchedpad->IsOfflineSimple()) continue;
365  if(matchedpad->IsJetHigh()) hasJetHigh = kTRUE;
366  if(matchedpad->IsJetLow()) hasJetLow = kTRUE;
367  if(matchedpad->IsGammaHigh()) hasGammaHigh = kTRUE;
368  if(matchedpad->IsGammaLow()) hasGammaLow = kTRUE;
369  }
370  }
371  // Evaluate status
372  if((triggertype.Contains("EMCJHigh") || triggertype.Contains("EMCHighJetOnly")) && hasJetHigh) return kTRUE;
373  if((triggertype.Contains("EMCJLow") || triggertype.Contains("EMCLowJetOnly")) && hasJetLow) return kTRUE;
374  if((triggertype.Contains("EMCGHigh") || triggertype.Contains("EMCHighGammaOnly")) && hasGammaHigh) return kTRUE;
375  if((triggertype.Contains("EMCGLow") || triggertype.Contains("EMCLowGammaOnly")) && hasGammaLow) return kTRUE;
376  if(triggertype.Contains("EMCHighBoth") && (hasJetHigh || hasGammaHigh)) return kTRUE;
377  if(triggertype.Contains("EMCLowBoth") && (hasJetLow || hasGammaLow)) return kTRUE;
378  return kFALSE;
379 }
380 
381 } /* namespace EMCalTriggerPtAnalysis */
bool IsSelected(const AliVParticle *const track) const
ClassImp(AliAnalysisTaskTriggerRates) AliAnalysisTaskTriggerRates
Weight handler for the analysis of high- tracks in EMCAL-triggered events.
Declaration of class AliEMCalTriggerAnaTriggerDecision, a container for trigger decision in EMCAL-tri...
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.
void GetMachingTriggerNames(std::vector< std::string > &triggernames, ETriggerMethod_t usePatches)
TAxis * DefineAxis(const char *name, const AliEMCalTriggerBinningDimension *binning)
const AliEMCalTriggerAnaTriggerDecisionConfig * GetConfiguration() const
void FillTHnSparse(const char *name, const double *x, double weight=1.)
Analysis component for reconstructed tracks.
void CreateTHnSparse(const char *name, const char *title, int ndim, const int *nbins, const double *min, const double *max, Option_t *opt="")
const AliVParticle * IsMCTrueTrack(const AliVTrack *const trk, const AliMCEvent *evnt) const
Check whether track is a true signal track.
AliEMCalHistoContainer * fHistos
Histogram container of the analysis component.
const AliEMCalTriggerAnaTriggerDecision * fTriggerDecision
Trigger decision handler.
AliEMCalPtTaskVTrackSelection * fTrackSelection
Track selection cuts used in the analysis.
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.
double GetEventWeight(const AliMCEvent *const event) const
Declaration of the classes AliEMCalTriggerBinningComponent and AliEMCalTriggerBinningDimension.
virtual bool IsTrackAccepted(AliVTrack *const trk)=0
Bool_t HasMatchedPatchOfType(TString triggertype, const TList &patches) const
void FillCorrelation(const AliVParticle *const genparticle, const AliVParticle *const recparticle, double weight=1.)
void MatchTriggerPatches(const AliVTrack *rectrack, const TClonesArray *inputpatches, TList &outputpatches) const
virtual void Process(const AliEMCalTriggerEventData *const data)
Run track loop on list of matching tracks.
const AliEMCalTriggerBinningComponent * fBinning
Global binning handler.
Declartion of class AliEMCalPtTaskVTrackSelection.