AliPhysics  6bc8652 (6bc8652)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliAnalysisTaskEventSelectionRef.cxx
Go to the documentation of this file.
1 /**************************************************************************
2  * Copyright(c) 1998-2015, 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 <TArrayD.h>
16 #include <TClonesArray.h>
17 #include <THashList.h>
18 #include <THistManager.h>
19 #include <TMath.h>
20 #include <TObjArray.h>
21 #include <TString.h>
22 
23 #include "AliAnalysisUtils.h"
24 #include "AliAODTrack.h"
25 #include "AliESDEvent.h"
26 #include "AliESDtrack.h"
27 #include "AliESDtrackCuts.h"
29 #include "AliEMCALTriggerPatchInfo.h"
30 #include "AliEMCALGeometry.h"
31 #include "AliEMCALRecoUtils.h"
32 #include "AliInputEventHandler.h"
33 #include "AliVCluster.h"
34 #include "AliVEvent.h"
35 
37 
38 #if __cplusplus < 201103L
39 #ifndef nullptr
40 #define nullptr NULL
41 #endif
42 #endif
43 
45 
46 namespace EMCalTriggerPtAnalysis {
47 
48 AliAnalysisTaskEventSelectionRef::AliAnalysisTaskEventSelectionRef():
50  fClusterContainerName(""),
51  fAnalysisUtils(nullptr),
52  fTriggerSelection(nullptr),
53  fHistos(nullptr),
54  fTrackCuts(nullptr),
55  fGeometry(nullptr),
56  fTriggerPatchContainer(nullptr),
57  fClusterContainer(nullptr),
58  fTrackContainer(nullptr)
59 {
60 }
61 
62 AliAnalysisTaskEventSelectionRef::AliAnalysisTaskEventSelectionRef(const char *name):
63  AliAnalysisTaskSE(name),
64  fClusterContainerName(""),
65  fAnalysisUtils(nullptr),
66  fTriggerSelection(nullptr),
67  fHistos(nullptr),
68  fTrackCuts(nullptr),
69  fGeometry(nullptr),
70  fTriggerPatchContainer(nullptr),
71  fClusterContainer(nullptr),
72  fTrackContainer(nullptr)
73 {
74  DefineOutput(1, TList::Class());
75 }
76 
77 AliAnalysisTaskEventSelectionRef::~AliAnalysisTaskEventSelectionRef() {
78  if(fAnalysisUtils) delete fAnalysisUtils;
79  if(fTriggerSelection) delete fTriggerSelection;
80  if(fTrackCuts) delete fTrackCuts;
81  if(fTrackContainer) delete fTrackContainer;
82 }
83 
84 void AliAnalysisTaskEventSelectionRef::UserCreateOutputObjects(){
85  fAnalysisUtils = new AliAnalysisUtils;
86 
87  fTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2011(true, 1);
88  fTrackCuts->SetName("Standard Track cuts");
89  fTrackCuts->SetMinNCrossedRowsTPC(120);
90  fTrackCuts->SetMaxDCAToVertexXYPtDep("0.0182+0.0350/pt^1.01");
91 
92  fHistos = new THistManager("Ref");
93 
94  TArrayD ptbinning, energybinning;
95  CreatePtBinning(ptbinning);
96  CreateEnergyBinning(energybinning);
97 
98  TString triggers[6] = {"MB", "EMC7", "EJ1", "EJ2", "EG1", "EG2"};
99  TString selectionStatus[3] = {"All","Accepted","Rejected"};
100  for(TString *trgit = triggers; trgit < triggers + sizeof(triggers)/sizeof(TString); ++trgit){
101  fHistos->CreateTH1(Form("hEventCount%sBeforeEventSelection", trgit->Data()), Form("Event count for trigger %s before event selection", trgit->Data()), 1, 0.5, 1.5);
102  fHistos->CreateTH1(Form("hEventCount%sBeforeOfflineTrigger", trgit->Data()), Form("Event count for trigger %s before offline selection", trgit->Data()), 1, 0.5, 1.5);
103  fHistos->CreateTH1(Form("hEventCount%sAfterOfflineTrigger", trgit->Data()), Form("Event count for trigger %s before offline selection", trgit->Data()), 1, 0.5, 1.5);
104  fHistos->CreateTH1(Form("hVertexTrigger%sBeforeEventSelection", trgit->Data()), Form("Vertex Distribution for trigger %s before event selection", trgit->Data()), 400, -40, 40);
105  fHistos->CreateTH1(Form("hVertexTrigger%sBeforeOfflineTrigger", trgit->Data()), Form("Vertex Distribution for trigger %s before offline trigger", trgit->Data()), 400, -40, 40);
106  fHistos->CreateTH1(Form("hVertexTrigger%sAfterOfflineTrigger", trgit->Data()), Form("Vertex Distribution for trigger %s after offline trigger", trgit->Data()), 400, -40, 40);
107  for(TString *statit = selectionStatus; statit < selectionStatus + sizeof(selectionStatus)/sizeof(TString); ++statit){
108  fHistos->CreateTH1(Form("hTrackPt%s%s", statit->Data(), trgit->Data()), Form("Pt spectrum of tracks in %s events of trigger %s", statit->Data(), trgit->Data()), ptbinning);
109  fHistos->CreateTH1(Form("hClusterEnergy%s%s", statit->Data(), trgit->Data()), Form("Cluster energy spectrum in %s events of trigger %s", statit->Data(), trgit->Data()), energybinning);
110  if(trgit->CompareTo("MB"))
111  fHistos->CreateTH1(Form("hPatchEnergy%s%s", statit->Data(), trgit->Data()), Form("Patch energy spectrum in %s events of trigger %s", statit->Data(), trgit->Data()), energybinning);
112  }
113  // Make histos for patch energy spectra for Min. Bias for different triggers
114  fHistos->CreateTH1(Form("hPatchEnergy%sMinBias", trgit->Data()), Form("Patch energy spectrum for %s patches found in MB events", trgit->Data()), energybinning);
115  }
116 
117 
118  fTrackContainer = new TObjArray;
119  fTrackContainer->SetOwner(kFALSE);
120 
121  PostData(1, fHistos->GetListOfHistograms());
122 }
123 
124 void AliAnalysisTaskEventSelectionRef::UserExec(Option_t *){
125  // Select event
126  if(!fGeometry){
127  fGeometry = AliEMCALGeometry::GetInstanceFromRunNumber(fInputEvent->GetRunNumber());
128  }
129  fTriggerPatchContainer = static_cast<TClonesArray *>(fInputEvent->FindListObject("EmcalTriggers"));
130  fClusterContainer = static_cast<TClonesArray *>(fInputEvent->FindListObject(fClusterContainerName.Data()));
131  TString triggerstring = fInputEvent->GetFiredTriggerClasses();
132  UInt_t selectionstatus = fInputHandler->IsEventSelected();
133  Bool_t isMinBias = selectionstatus & AliVEvent::kINT7,
134  isEJ1 = (selectionstatus & AliVEvent::kEMCEJE) && triggerstring.Contains("EJ1"),
135  isEJ2 = (selectionstatus & AliVEvent::kEMCEJE) && triggerstring.Contains("EJ2"),
136  isEG1 = (selectionstatus & AliVEvent::kEMCEGA) && triggerstring.Contains("EG1"),
137  isEG2 = (selectionstatus & AliVEvent::kEMCEGA) && triggerstring.Contains("EG2"),
138  isEMC7 = (selectionstatus & AliVEvent::kEMC7) && triggerstring.Contains("CEMC7");
139  if(!(isMinBias || isEMC7 || isEG1 || isEG2 || isEJ1 || isEJ2)) return;
140  const AliVVertex *vtx = fInputEvent->GetPrimaryVertex();
141  //if(!fInputEvent->IsPileupFromSPD(3, 0.8, 3., 2., 5.)) return; // reject pileup event
142  if(vtx->GetNContributors() < 1) return;
143  if(fInputEvent->IsA() == AliESDEvent::Class() && fAnalysisUtils->IsFirstEventInChunk(fInputEvent)) return;
144  bool isSelected = kTRUE;
145  if(!fAnalysisUtils->IsVertexSelected2013pA(fInputEvent)) isSelected = kFALSE; // Apply new vertex cut
146  if(fAnalysisUtils->IsPileUpEvent(fInputEvent)) isSelected = kFALSE; // Apply new vertex cut
147  // Apply vertex z cut
148  if(vtx->GetZ() < -10. || vtx->GetZ() > 10.) isSelected = kFALSE;
149 
150  // prepare tracks: Apply track selection and extrapolate to EMCAL surface
151  fTrackContainer->Clear();
152  AliVTrack *trk(nullptr); Double_t etaEMCAL(0.), phiEMCAL(0.); Int_t supermoduleID(-1);
153  for(int itrk = 0; itrk < fInputEvent->GetNumberOfTracks(); itrk++){
154  trk = static_cast<AliESDtrack *>(fInputEvent->GetTrack(itrk));
155  if(TMath::Abs(trk->Eta()) > 0.6) continue;
156  if(trk->IsA() == AliESDtrack::Class()){
157  AliESDtrack *origtrack = static_cast<AliESDtrack *>(trk);
158  if(!TrackSelectionESD(origtrack)) continue;
159  AliESDtrack copytrack(*origtrack);
160  AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(&copytrack);
161  etaEMCAL = copytrack.GetTrackEtaOnEMCal();
162  phiEMCAL = copytrack.GetTrackPhiOnEMCal();
163  } else {
164  AliAODTrack *origtrack = static_cast<AliAODTrack *>(trk);
165  if(!TrackSelectionAOD(origtrack)) continue;
166  AliAODTrack copytrack(*origtrack);
167  AliEMCALRecoUtils::ExtrapolateTrackToEMCalSurface(&copytrack);
168  etaEMCAL = copytrack.GetTrackEtaOnEMCal();
169  phiEMCAL = copytrack.GetTrackPhiOnEMCal();
170  }
171  if(!fGeometry->SuperModuleNumberFromEtaPhi(etaEMCAL, phiEMCAL, supermoduleID)) continue;
172  if(supermoduleID < 0 || supermoduleID >= 10) continue;
173  fTrackContainer->Add(trk);
174  }
175 
176  // Fill Event counter and reference vertex distributions for the different trigger classes
177  if(isMinBias){
178  FillEventCounterHists("MB", vtx->GetZ(), isSelected, true);
179  }
180  if(isEMC7){
181  FillEventCounterHists("EMC7", vtx->GetZ(), isSelected, fTriggerSelection->IsOfflineSelected(AliEmcalTriggerOfflineSelection::kTrgEL0, fInputEvent));
182  }
183  if(isEJ2){
184  FillEventCounterHists("EJ2", vtx->GetZ(), isSelected, fTriggerSelection->IsOfflineSelected(AliEmcalTriggerOfflineSelection::kTrgEJ2, fInputEvent));
185  }
186  if(isEJ1){
187  FillEventCounterHists("EJ1", vtx->GetZ(), isSelected, fTriggerSelection->IsOfflineSelected(AliEmcalTriggerOfflineSelection::kTrgEJ1, fInputEvent));
188  }
189  if(isEG2){
190  FillEventCounterHists("EG2", vtx->GetZ(), isSelected, fTriggerSelection->IsOfflineSelected(AliEmcalTriggerOfflineSelection::kTrgEG2, fInputEvent));
191  }
192  if(isEG1){
193  FillEventCounterHists("EG1", vtx->GetZ(), isSelected, fTriggerSelection->IsOfflineSelected(AliEmcalTriggerOfflineSelection::kTrgEG1, fInputEvent));
194  }
195 
196  PostData(1, fHistos->GetListOfHistograms());
197 }
198 
199 void AliAnalysisTaskEventSelectionRef::FillEventCounterHists(
200  const char *triggerclass,
201  double vtxz,
202  bool isSelected,
203  bool isOfflineSelected
204 )
205 {
206  // Fill reference distribution for the primary vertex before any z-cut
207  fHistos->FillTH1(Form("hVertexTrigger%sBeforeEventSelection", triggerclass), vtxz);
208  fHistos->FillTH1(Form("hEventCount%sBeforeEventSelection", triggerclass), 1.);
209  if(isSelected){
210  // Fill Event counter and reference vertex distributions after event selection
211  fHistos->FillTH1(Form("hEventCount%sBeforeOfflineTrigger", triggerclass), 1);
212  fHistos->FillTH1(Form("hVertexTrigger%sBeforeOfflineTrigger", triggerclass), vtxz);
213  if(isOfflineSelected){
214  fHistos->FillTH1(Form("hEventCount%sAfterOfflineTrigger", triggerclass), 1);
215  fHistos->FillTH1(Form("hVertexTrigger%sAfterOfflineTrigger", triggerclass), vtxz);
216  }
217 
218  // Now make some distributions of quantities in selected and rejected event
219  //... tracks
220  for(TIter trackIter = TIter(fTrackContainer).Begin(); trackIter != TIter::End(); ++trackIter){
221  ProcessTrack(triggerclass, static_cast<AliVTrack *>(*trackIter), isOfflineSelected);
222  }
223 
224  // ... clusters
225  if(fClusterContainer){
226  for(TIter clsit = TIter(fClusterContainer).Begin(); clsit != TIter::End(); ++clsit){
227  ProcessCluster(triggerclass, static_cast<AliVCluster *>(*clsit), isOfflineSelected);
228  }
229  }
230 
231  // ... patches
232  for(TIter patchiter = TIter(fTriggerPatchContainer).Begin(); patchiter != TIter::End(); ++patchiter){
233  ProcessOfflinePatch(triggerclass, static_cast<AliEMCALTriggerPatchInfo *>(*patchiter), isOfflineSelected);
234  }
235  }
236 }
237 
238 void AliAnalysisTaskEventSelectionRef::ProcessTrack(
239  const char *triggerclass,
240  const AliVTrack * track,
241  bool isOfflineSelected
242 )
243 {
244  fHistos->FillTH1(Form("hTrackPtAll%s", triggerclass), TMath::Abs(track->Pt()));
245  if(isOfflineSelected){
246  fHistos->FillTH1(Form("hTrackPtAccepted%s", triggerclass), TMath::Abs(track->Pt()));
247  } else {
248  fHistos->FillTH1(Form("hTrackPtRejected%s", triggerclass), TMath::Abs(track->Pt()));
249  }
250 }
251 
252 void AliAnalysisTaskEventSelectionRef::ProcessCluster(
253  const char *triggerclass,
254  const AliVCluster *clust,
255  bool isOfflineSelected
256 )
257 {
258  if(!clust->IsEMCAL()) return;
259  fHistos->FillTH1(Form("hClusterEnergyAll%s", triggerclass), clust->E());
260  if(isOfflineSelected){
261  fHistos->FillTH1(Form("hClusterEnergyAccepted%s", triggerclass), clust->E());
262  } else {
263  fHistos->FillTH1(Form("hClusterEnergyRejected%s", triggerclass), clust->E());
264  }
265 }
266 
267 void AliAnalysisTaskEventSelectionRef::ProcessOfflinePatch(
268  const char * triggerclass,
269  const AliEMCALTriggerPatchInfo * patch,
270  bool isOfflineSelected
271 )
272 {
273  bool isSingleShower = patch->IsGammaLowSimple();
274  bool isJetPatch = patch->IsJetLowSimple();
275  if(!(isSingleShower || isJetPatch)) return;
276  TString triggerstring(triggerclass);
277  if(!triggerstring.CompareTo("MB")){
278  if(isSingleShower){
279  fHistos->FillTH1("hPatchEnergyEMC7MinBias", patch->GetPatchE());
280  fHistos->FillTH1("hPatchEnergyEG1MinBias", patch->GetPatchE());
281  fHistos->FillTH1("hPatchEnergyEG2MinBias", patch->GetPatchE());
282  } else {
283  fHistos->FillTH1("hPatchEnergyEJ1MinBias", patch->GetPatchE());
284  fHistos->FillTH1("hPatchEnergyEJ2MinBias", patch->GetPatchE());
285  }
286  } else {
287  bool singleShowerTrigger = !triggerstring.CompareTo("EMC7") || !triggerstring.CompareTo("EG1") || !triggerstring.CompareTo("EG2");
288  if((isSingleShower && singleShowerTrigger) || (isJetPatch && !singleShowerTrigger)){
289  fHistos->FillTH1(Form("hPatchEnergyAll%s", triggerclass), patch->GetPatchE());
290  if(isOfflineSelected)
291  fHistos->FillTH1(Form("hPatchEnergyAccepted%s", triggerclass), patch->GetPatchE());
292  else
293  fHistos->FillTH1(Form("hPatchEnergyRejected%s", triggerclass), patch->GetPatchE());
294  }
295  }
296 }
297 
302 void AliAnalysisTaskEventSelectionRef::CreateEnergyBinning(TArrayD& binning) const {
303  std::vector<double> mybinning;
304  std::map<double,double> definitions;
305  definitions.insert(std::pair<double, double>(1, 0.05));
306  definitions.insert(std::pair<double, double>(2, 0.1));
307  definitions.insert(std::pair<double, double>(4, 0.2));
308  definitions.insert(std::pair<double, double>(7, 0.5));
309  definitions.insert(std::pair<double, double>(16, 1));
310  definitions.insert(std::pair<double, double>(32, 2));
311  definitions.insert(std::pair<double, double>(40, 4));
312  definitions.insert(std::pair<double, double>(50, 5));
313  definitions.insert(std::pair<double, double>(100, 10));
314  definitions.insert(std::pair<double, double>(200, 20));
315  double currentval = 0.;
316  mybinning.push_back(currentval);
317  for(std::map<double,double>::iterator id = definitions.begin(); id != definitions.end(); ++id){
318  double limit = id->first, binwidth = id->second;
319  while(currentval < limit){
320  currentval += binwidth;
321  mybinning.push_back(currentval);
322  }
323  }
324  binning.Set(mybinning.size());
325  int ib = 0;
326  for(std::vector<double>::iterator it = mybinning.begin(); it != mybinning.end(); ++it)
327  binning[ib++] = *it;
328 }
329 
334 void AliAnalysisTaskEventSelectionRef::CreatePtBinning(TArrayD& binning) const {
335  std::vector<double> mybinning;
336  std::map<double,double> definitions;
337  definitions.insert(std::pair<double, double>(1, 0.05));
338  definitions.insert(std::pair<double, double>(2, 0.1));
339  definitions.insert(std::pair<double, double>(4, 0.2));
340  definitions.insert(std::pair<double, double>(7, 0.5));
341  definitions.insert(std::pair<double, double>(16, 1));
342  definitions.insert(std::pair<double, double>(36, 2));
343  definitions.insert(std::pair<double, double>(40, 4));
344  definitions.insert(std::pair<double, double>(50, 5));
345  definitions.insert(std::pair<double, double>(100, 10));
346  definitions.insert(std::pair<double, double>(200, 20));
347  double currentval = 0.;
348  mybinning.push_back(currentval);
349  for(std::map<double,double>::iterator id = definitions.begin(); id != definitions.end(); ++id){
350  double limit = id->first, binwidth = id->second;
351  while(currentval < limit){
352  currentval += binwidth;
353  mybinning.push_back(currentval);
354  }
355  }
356  binning.Set(mybinning.size());
357  int ib = 0;
358  for(std::vector<double>::iterator it = mybinning.begin(); it != mybinning.end(); ++it)
359  binning[ib++] = *it;
360 }
361 
367 Bool_t AliAnalysisTaskEventSelectionRef::TrackSelectionESD(AliESDtrack* track) {
368  return fTrackCuts->AcceptTrack(track);
369 }
370 
376 Bool_t AliAnalysisTaskEventSelectionRef::TrackSelectionAOD(AliAODTrack* track) {
377  if(!track->TestFilterBit(AliAODTrack::kTrkGlobal)) return false;
378  if(track->GetTPCNCrossedRows() < 120) return false;
379  return true;
380 }
381 
382 } /* namespace EMCalTriggerPtAnalysis */
double Double_t
Definition: External.C:58
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
Container class for histograms.
Definition: THistManager.h:43
const char Option_t
Definition: External.C:48
bool Bool_t
Definition: External.C:53
ClassImp(EMCalTriggerPtAnalysis::AliAnalysisTaskEventSelectionRef) namespace EMCalTriggerPtAnalysis