AliPhysics  ff0b22e (ff0b22e)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliAnalysisTaskEventFilter.cxx
Go to the documentation of this file.
1 /*
2  * AliAnalysisTaskEventFilter.cxx
3  *
4  * Created on: Jan 29, 2016
5  * Author: markus
6  */
7 #include <TArray.h>
8 #include <THashList.h>
9 #include <THistManager.h>
10 #include <TMath.h>
11 #include <TString.h>
12 
13 #include <AliAnalysisUtils.h>
14 #include <AliESDtrackCuts.h>
15 #include <AliESDtrack.h>
16 #include <AliInputEventHandler.h>
17 #include <AliVEvent.h>
18 #include <AliVTrack.h>
19 #include <AliVVertex.h>
20 
21 #include <map>
22 #include <string>
23 
25 
26 using namespace EMCalTriggerPtAnalysis;
27 
29 
31 AliAnalysisTaskSE(),
32 fAnalysisUtils(NULL),
33 fTrackCuts(NULL),
34 fHistos(NULL)
35 {
36 }
37 
39 AliAnalysisTaskSE(name),
40 fAnalysisUtils(NULL),
41 fTrackCuts(NULL),
42 fHistos(NULL)
43 {
44  DefineOutput(1, TList::Class());
45 }
46 
48  delete fAnalysisUtils;
49  delete fHistos;
50 }
51 
53  fAnalysisUtils = new AliAnalysisUtils;
54 
55  fTrackCuts = AliESDtrackCuts::GetStandardITSTPCTrackCuts2011(true, 1);
56  fTrackCuts->SetName("Standard Track cuts");
57  fTrackCuts->SetMinNCrossedRowsTPC(120);
58  fTrackCuts->SetMaxDCAToVertexXYPtDep("0.0182+0.0350/pt^1.01");
59 
60  std::map<std::string, std::string> filtersteps;
61  filtersteps.insert(std::pair<std::string,std::string>("all", "All INT7 events")); // all INT7 events
62  filtersteps.insert(std::pair<std::string,std::string>("psel", "Physics selected INT7 events")); // after Physics selection
63  filtersteps.insert(std::pair<std::string,std::string>("fe", "INT7 no first event in chunk")); // Not first event in chunk
64  filtersteps.insert(std::pair<std::string,std::string>("np", "INT7 no pileup event")); // Not a pileup event
65  filtersteps.insert(std::pair<std::string,std::string>("fv", "INT7 after fake vertex cut")); // survived fake vertex cut
66  filtersteps.insert(std::pair<std::string,std::string>("tv", "INT7 after true vertex cut")); // survived true vertex cut
67 
68  TArrayD ptbinning;
69  CreatePtBinning(ptbinning);
70 
71  fHistos = new THistManager("eventHistos");
72  for(std::map<std::string, std::string>::iterator it = filtersteps.begin(); it != filtersteps.end(); ++it){
73  fHistos->CreateTH1(Form("hINT7%s", it->first.c_str()), it->second.c_str(), 1000, -100, 100);
74  }
75  for(std::map<std::string, std::string>::iterator it = filtersteps.begin(); it != filtersteps.end(); ++it){
76  fHistos->CreateTH1(Form("hPt%s", it->first.c_str()), it->second.c_str(), ptbinning);
77  }
78  for(std::map<std::string, std::string>::iterator it = filtersteps.begin(); it != filtersteps.end(); ++it){
79  fHistos->CreateTH1(Form("hEta%s", it->first.c_str()), it->second.c_str(), 100, -0.8, 0.8);
80  }
81 
82  PostData(1, fHistos->GetListOfHistograms());
83 }
84 
86  std::map<int, std::string> eventfilters;
87  eventfilters.insert(std::pair<int, std::string>(0, "psel"));
88  eventfilters.insert(std::pair<int, std::string>(1, "fe"));
89  eventfilters.insert(std::pair<int, std::string>(2, "np"));
90  eventfilters.insert(std::pair<int, std::string>(3, "fv"));
91  eventfilters.insert(std::pair<int, std::string>(4, "tv"));
92 
93  PostData(1, fHistos->GetListOfHistograms());
94  // Filter event, also run buggy event selection explicitly to check impact
95  double vz = InputEvent()->GetPrimaryVertex()->GetZ();
96  TString triggerstring(InputEvent()->GetFiredTriggerClasses());
97  if(!triggerstring.Contains("INT7-B")) return;
98 
99  UChar_t eventfilter = FilterEvent();
100  std::vector<const AliVTrack *> tracks = FilterTracks();
101  FillEvent("all", vz);
102  FillTracks("all", tracks);
103  for(int ifilter = 0; ifilter < 5; ifilter++){
104  if(eventfilter & 1 << ifilter){
105  std::string filtername = eventfilters.find(ifilter)->second;
106  FillEvent(filtername.c_str(), vz);
107  FillTracks(filtername.c_str(), tracks);
108  }
109  }
110 }
111 
113  UChar_t filterbits = 0;
114  if(!(fInputHandler->IsEventSelected() && AliVEvent::kINT7)) return filterbits;
115  filterbits |= 1 << 0;
116  if(fAnalysisUtils->IsFirstEventInChunk(InputEvent())) return filterbits;
117  filterbits |= 1 << 1;
118  if(fAnalysisUtils->IsPileUpEvent(InputEvent())) return filterbits;
119  filterbits |= 1 << 2;
120  if(!FakeVertexSelection2013pA(InputEvent())) return filterbits;
121  filterbits |= 1 << 3;
122  if(!fAnalysisUtils->IsVertexSelected2013pA(InputEvent())) return filterbits;
123  filterbits |= 1 << 4;
124  return filterbits;
125 }
126 
127 std::vector<const AliVTrack *> AliAnalysisTaskEventFilter::FilterTracks() const {
128  std::vector<const AliVTrack *> result;
129  AliESDtrack *track(NULL);
130  for(Int_t itrk = 0; itrk < InputEvent()->GetNumberOfTracks(); itrk++){
131  track = dynamic_cast<AliESDtrack *>(InputEvent()->GetTrack(itrk));
132  if(!track) continue;
133  if(TMath::Abs(track->Eta()) > 0.8) continue;
134  if(!fTrackCuts->AcceptTrack(track)) continue;
135  result.push_back(track);
136  }
137  return result;
138 }
139 
140 void AliAnalysisTaskEventFilter::FillEvent(const char *filterstep, double vz){
141  fHistos->FillTH1(Form("hINT7%s", filterstep), vz);
142 }
143 
144 void AliAnalysisTaskEventFilter::FillTracks(const char *filterstep, const std::vector<const AliVTrack *> &tracks){
145  for(std::vector<const AliVTrack *>::const_iterator trackiter = tracks.begin(); trackiter != tracks.end(); ++trackiter){
146  fHistos->FillTH1(Form("hPt%s", filterstep), TMath::Abs((*trackiter)->Pt()));
147  fHistos->FillTH1(Form("hEta%s", filterstep), (*trackiter)->Eta());
148  }
149 }
150 
151 Bool_t AliAnalysisTaskEventFilter::FakeVertexSelection2013pA(const AliVEvent *const inputEvent) const {
152 
153  Bool_t accept = kFALSE;
154 
155  const AliVVertex *trkVtx = dynamic_cast<const AliVVertex*>(inputEvent->GetPrimaryVertex()) ;
156  if(!trkVtx || trkVtx->GetNContributors() <= 0){
157  accept = kFALSE;
158  return accept;
159  }
160 
161  TString vtxTtl = trkVtx->GetTitle();
162  if (!vtxTtl.Contains("VertexerTracks")) return accept;
163 
164  Float_t zvtx = trkVtx->GetZ();
165  const AliVVertex* spdVtx = dynamic_cast<const AliVVertex*>(inputEvent->GetPrimaryVertexSPD()) ;
166  if (spdVtx->GetNContributors()<=0) return accept;
167 
168  Double_t cov[6]={0};
169  spdVtx->GetCovarianceMatrix(cov);
170  Double_t zRes = TMath::Sqrt(cov[5]);
171  if (TString(spdVtx->GetTitle()).Contains("vertexer:Z") && (zRes>0.25)) return accept; // Explicitly done the old way in order to estimate effect of not applied cut
172  if (TMath::Abs(spdVtx->GetZ() - trkVtx->GetZ())>0.5) return accept;
173 
174  if (TMath::Abs(zvtx) > 10) return accept;
175 
176  return kTRUE;
177 }
178 
179 void AliAnalysisTaskEventFilter::CreatePtBinning(TArrayD& binning) const {
180  std::vector<double> mybinning;
181  std::map<double,double> definitions;
182  definitions.insert(std::pair<double, double>(1, 0.05));
183  definitions.insert(std::pair<double, double>(2, 0.1));
184  definitions.insert(std::pair<double, double>(4, 0.2));
185  definitions.insert(std::pair<double, double>(7, 0.5));
186  definitions.insert(std::pair<double, double>(16, 1));
187  definitions.insert(std::pair<double, double>(36, 2));
188  definitions.insert(std::pair<double, double>(40, 4));
189  definitions.insert(std::pair<double, double>(50, 5));
190  definitions.insert(std::pair<double, double>(100, 10));
191  definitions.insert(std::pair<double, double>(200, 20));
192  double currentval = 0.;
193  mybinning.push_back(currentval);
194  for(std::map<double,double>::iterator id = definitions.begin(); id != definitions.end(); ++id){
195  double limit = id->first, binwidth = id->second;
196  while(currentval < limit){
197  currentval += binwidth;
198  mybinning.push_back(currentval);
199  }
200  }
201  binning.Set(mybinning.size());
202  int ib = 0;
203  for(std::vector<double>::iterator it = mybinning.begin(); it != mybinning.end(); ++it)
204  binning[ib++] = *it;
205 }
206 
std::vector< const AliVTrack * > FilterTracks() const
THashList * GetListOfHistograms() const
Definition: THistManager.h:504
TH1 * CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt="")
void FillTH1(const char *hname, double x, double weight=1., Option_t *opt="")
void FillTracks(const char *filterstep, const std::vector< const AliVTrack * > &tracks)
Container class for histograms for the high- charged particle analysis.
Definition: THistManager.h:43
Bool_t FakeVertexSelection2013pA(const AliVEvent *const inputevent) const
ClassImp(EMCalTriggerPtAnalysis::AliAnalysisTaskEventFilter) AliAnalysisTaskEventFilter