AliPhysics  2c6b7ad (2c6b7ad)
AliAnalysisTaskEmcalJetEnergySpectrum.cxx
Go to the documentation of this file.
1 /************************************************************************************
2  * Copyright (C) 2017, Copyright Holders of the ALICE Collaboration *
3  * All rights reserved. *
4  * *
5  * Redistribution and use in source and binary forms, with or without *
6  * modification, are permitted provided that the following conditions are met: *
7  * * Redistributions of source code must retain the above copyright *
8  * notice, this list of conditions and the following disclaimer. *
9  * * Redistributions in binary form must reproduce the above copyright *
10  * notice, this list of conditions and the following disclaimer in the *
11  * documentation and/or other materials provided with the distribution. *
12  * * Neither the name of the <organization> nor the *
13  * names of its contributors may be used to endorse or promote products *
14  * derived from this software without specific prior written permission. *
15  * *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND *
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED *
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE *
19  * DISCLAIMED. IN NO EVENT SHALL ALICE COLLABORATION BE LIABLE FOR ANY *
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; *
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND *
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
26  ************************************************************************************/
27 #include <algorithm>
28 #include <array>
29 #include <sstream>
30 #include <string>
31 #include <vector>
32 
33 #include <THistManager.h>
34 #include <TLinearBinning.h>
35 #include <TVariableBinning.h>
36 
37 #include "AliAODInputHandler.h"
38 #include "AliAnalysisManager.h"
41 #include "AliEmcalJet.h"
44 #include "AliInputEventHandler.h"
45 #include "AliJetContainer.h"
46 #include "AliLog.h"
47 #include "AliMultSelection.h"
48 #include "AliVEvent.h"
49 
51 
52 using namespace EmcalTriggerJets;
53 
56  fHistos(nullptr),
57  fIsMC(false),
58  fTriggerSelectionBits(AliVEvent::kAny),
59  fTriggerSelectionString(""),
60  fRequireSubsetMB(false),
61  fMinBiasTrigger(AliVEvent::kAny),
62  fNameTriggerDecisionContainer("EmcalTriggerDecision"),
63  fUseTriggerSelectionForData(false),
64  fUseDownscaleWeight(false),
65  fNameJetContainer("datajets"),
66  fRequestTriggerClusters(true),
67  fRequestCentrality(false),
68  fCentralityEstimator("V0M")
69 {
70  SetUseAliAnaUtils(true);
71 }
72 
74  AliAnalysisTaskEmcalJet(name, true),
76  fIsMC(false),
77  fTriggerSelectionBits(AliVEvent::kAny),
79  fRequireSubsetMB(false),
80  fMinBiasTrigger(AliVEvent::kAny),
81  fNameTriggerDecisionContainer("EmcalTriggerDecision"),
83  fUseDownscaleWeight(false),
84  fNameJetContainer("datajets"),
86  fRequestCentrality(false),
88 {
89  SetUseAliAnaUtils(true);
90 }
91 
93  if(fHistos) delete fHistos;
94 }
95 
98 
99  if(!fUserPtBinning.GetSize()) {
100  // binning not set. apply default binning
101  AliInfoStream() << "Using default pt binning";
102  fUserPtBinning.Set(201);
103  double current(0.);
104  for(int istep = 0; istep < 201; istep++) {
105  fUserPtBinning[istep] = current;
106  current += 1;
107  }
108  }
109 
110  TLinearBinning centralitybinning(100, 0., 100.), etabinning(100, -1., 1.), phibinning(100., 0., 7.), nefbinning(100, 0., 1.), trgclusterbinning(kTrgClusterN + 1, -0.5, kTrgClusterN -0.5);
111  TVariableBinning jetptbinning(fUserPtBinning);
112  const TBinning *binnings[6] = {&centralitybinning, &jetptbinning, &etabinning, &phibinning, &nefbinning, &trgclusterbinning};
113  fHistos = new THistManager(Form("Histos_%s", GetName()));
114  fHistos->CreateTH1("hEventCounter", "Event counter histogram", 1, 0.5, 1.5);
115  fHistos->CreateTH1("hEventCentrality", "Event centrality", 100., 0., 100.);
116  fHistos->CreateTH1("hClusterCounter", "Event counter histogram", kTrgClusterN, -0.5, kTrgClusterN - 0.5);
117  fHistos->CreateTHnSparse("hJetTHnSparse", "jet thnsparse", 6, binnings, "s");
118  fHistos->CreateTHnSparse("hMaxJetTHnSparse", "jet thnsparse", 6, binnings, "s");
119 
120  for(auto h : *fHistos->GetListOfHistograms()) fOutput->Add(h);
121  PostData(1, fOutput);
122 }
123 
125  auto datajets = this->GetJetContainer(fNameJetContainer);
126  if(!datajets) {
127  AliErrorStream() << "Jet container " << fNameJetContainer << " not found" << std::endl;
128  return false;
129  }
130 
131  double eventCentrality = 99; // without centrality put everything in the peripheral bin
132  if(fRequestCentrality){
133  AliMultSelection *mult = dynamic_cast<AliMultSelection *>(InputEvent()->FindListObject("MultSelection"));
134  if(!mult){
135  AliErrorStream() << GetName() << ": Centrality selection enabled but no centrality estimator found" << std::endl;
136  return false;
137  }
138  if(mult->IsEventSelected()) return false;
139  eventCentrality = mult->GetEstimator(fCentralityEstimator)->GetPercentile();
140  AliDebugStream(1) << GetName() << ": Centrality " << eventCentrality << std::endl;
141  } else {
142  AliDebugStream(1) << GetName() << ": No centrality selection applied" << std::endl;
143  }
144 
145  auto trgclusters = GetTriggerClusterIndices(fInputEvent->GetFiredTriggerClasses());
146  fHistos->FillTH1("hEventCounter", 1);
147  fHistos->FillTH1("hEventCentrality", eventCentrality);
148  AliEmcalJet *maxjet(nullptr);
149  for(auto t : trgclusters) fHistos->FillTH1("hClusterCounter", t);
150  for(auto j : datajets->accepted()){
151  if(!maxjet || (j->E() > maxjet->E())) maxjet = j;
152  double datapoint[6] = {eventCentrality, j->Pt(), j->Eta(), j->Phi(), j->NEF(), 0.};
153  for(auto t : trgclusters){
154  datapoint[5] = static_cast<double>(t);
155  fHistos->FillTHnSparse("hJetTHnSparse", datapoint);
156  }
157  }
158 
159  double maxdata[6];
160  memset(maxdata, 0., sizeof(double) * 5);
161  maxdata[0] = eventCentrality;
162  if(maxjet){
163  maxdata[1] = maxjet->Pt();
164  maxdata[2] = maxjet->Eta();
165  maxdata[3] = maxjet->Phi();
166  maxdata[4] = maxjet->NEF();
167  }
168  for(auto t : trgclusters){
169  maxdata[5] = static_cast<double>(t);
170  fHistos->FillTHnSparse("hMaxJetTHnSparse", maxdata);
171  }
172  return true;
173 }
174 
175 std::vector<AliAnalysisTaskEmcalJetEnergySpectrum::TriggerCluster_t> AliAnalysisTaskEmcalJetEnergySpectrum::GetTriggerClusterIndices(const TString &triggerstring) const {
176  // decode trigger string in order to determine the trigger clusters
177  std::vector<TriggerCluster_t> result;
178  result.emplace_back(kTrgClusterANY); // cluster ANY always included
180  // Data - separate trigger clusters
181  std::vector<std::string> clusternames;
182  auto triggerinfos = PWG::EMCAL::Triggerinfo::DecodeTriggerString(triggerstring.Data());
183  for(auto t : triggerinfos) {
184  if(std::find(clusternames.begin(), clusternames.end(), t.Triggercluster()) == clusternames.end()) clusternames.emplace_back(t.Triggercluster());
185  }
186  bool isCENT = (std::find(clusternames.begin(), clusternames.end(), "CENT") != clusternames.end()),
187  isCENTNOTRD = (std::find(clusternames.begin(), clusternames.end(), "CENTNOTRD") != clusternames.end()),
188  isCALO = (std::find(clusternames.begin(), clusternames.end(), "CALO") != clusternames.end()),
189  isCALOFAST = (std::find(clusternames.begin(), clusternames.end(), "CALOFAST") != clusternames.end());
190  if(isCENT || isCENTNOTRD) {
191  if(isCENT) {
192  result.emplace_back(kTrgClusterCENT);
193  if(isCENTNOTRD) {
194  result.emplace_back(kTrgClusterCENTNOTRD);
195  result.emplace_back(kTrgClusterCENTBOTH);
196  } else result.emplace_back(kTrgClusterOnlyCENT);
197  } else {
198  result.emplace_back(kTrgClusterCENTNOTRD);
199  result.emplace_back(kTrgClusterOnlyCENTNOTRD);
200  }
201  }
202  if(isCALO || isCALOFAST) {
203  if(isCALO) {
204  result.emplace_back(kTrgClusterCALO);
205  if(isCALOFAST) {
206  result.emplace_back(kTrgClusterCALOFAST);
207  result.emplace_back(kTrgClusterCALOBOTH);
208  } else result.emplace_back(kTrgClusterOnlyCALO);
209  } else {
210  result.emplace_back(kTrgClusterCALOFAST);
211  result.emplace_back(kTrgClusterOnlyCALOFAST);
212  }
213  }
214  }
215  return result;
216 }
217 
219  if(!fIsMC){
220  // Pure data - do EMCAL trigger selection from selection string
221  if(!(fInputHandler->IsEventSelected() & fTriggerSelectionBits)) return false;
222  if(fTriggerSelectionString.Length()) {
223  if(!fInputEvent->GetFiredTriggerClasses().Contains(fTriggerSelectionString)) return false;
224  if(fRequireSubsetMB && !(fInputHandler->IsEventSelected() & fMinBiasTrigger)) return false; // Require EMCAL trigger to be subset of the min. bias trigger (for efficiency studies)
225  if((fTriggerSelectionString.Contains("EJ") || fTriggerSelectionString.Contains("EG") || fTriggerSelectionString.Contains("DJ") || fTriggerSelectionString.Contains("DG")) && fUseTriggerSelectionForData) {
226  auto trgselresult = static_cast<PWG::EMCAL::AliEmcalTriggerDecisionContainer *>(fInputEvent->FindListObject(fNameTriggerDecisionContainer));
227  AliDebugStream(1) << "Found trigger decision object: " << (trgselresult ? "yes" : "no") << std::endl;
228  if(!trgselresult){
229  AliErrorStream() << "Trigger decision container with name " << fNameTriggerDecisionContainer << " not found in event - not possible to select EMCAL triggers" << std::endl;
230  return false;
231  }
232  if(!trgselresult->IsEventSelected(fTriggerSelectionString)) return false;
233  }
234  }
235  } else {
236  if(!(fInputHandler->IsEventSelected() & AliVEvent::kINT7)) return false;
238  // Simulation - do EMCAL trigger selection from trigger selection object
239  auto mctrigger = static_cast<PWG::EMCAL::AliEmcalTriggerDecisionContainer *>(fInputEvent->FindListObject(fNameTriggerDecisionContainer));
240  AliDebugStream(1) << "Found trigger decision object: " << (mctrigger ? "yes" : "no") << std::endl;
241  if(!mctrigger){
242  AliErrorStream() << "Trigger decision container with name " << fNameTriggerDecisionContainer << " not found in event - not possible to select EMCAL triggers" << std::endl;
243  return false;
244  }
245  if(!mctrigger->IsEventSelected(fTriggerSelectionString)) return false;
246  }
247  }
248  return true;
249 }
250 
251 bool AliAnalysisTaskEmcalJetEnergySpectrum::IsSelectEmcalTriggers(const std::string &triggerstring) const {
252  const std::array<std::string, 8> kEMCALTriggers = {
253  "EJ1", "EJ2", "DJ1", "DJ2", "EG1", "EG2", "DG1", "DG2"
254  };
255  bool isEMCAL = false;
256  for(auto emcaltrg : kEMCALTriggers) {
257  if(triggerstring.find(emcaltrg) != std::string::npos) {
258  isEMCAL = true;
259  break;
260  }
261  }
262  return isEMCAL;
263 }
264 
265 
267  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
268  if(!mgr) {
269  std::cerr << "Analysis manager not initialized" << std::endl;
270  return nullptr;
271  }
272 
273  Bool_t isAOD(kFALSE);
274  AliInputEventHandler *inputhandler = static_cast<AliInputEventHandler *>(mgr->GetInputEventHandler());
275  if(inputhandler) {
276  if(inputhandler->IsA() == AliAODInputHandler::Class()){
277  std::cout << "Analysing AOD events\n";
278  isAOD = kTRUE;
279  } else {
280  std::cout << "Analysing ESD events\n";
281  }
282  }
283 
284  std::string jettypestring;
286  switch(jettype){
287  case AliJetContainer::kChargedJet: jettypestring = "ChargedJets"; acctype = AliJetContainer::kTPCfid; break;
288  case AliJetContainer::kFullJet: jettypestring = "FullJets"; acctype = AliJetContainer::kEMCALfid; break;
289  case AliJetContainer::kNeutralJet: jettypestring = "NeutralJets"; acctype = AliJetContainer::kEMCALfid; break;
290  };
291 
292  std::stringstream tag, outfilename;
293  tag << jettypestring << "_R" << std::setw(2) << std::setfill('0') << int(radius * 10.) << "_" << trigger;
294  if(strlen(suffix)) {
295  tag << "_" << suffix;
296  }
297  auto task = new AliAnalysisTaskEmcalJetEnergySpectrum(Form("JetEnergySpectrum_%s", tag.str().data()));
298  task->SetIsMC(isMC);
299  mgr->AddTask(task);
300 
301  auto contains = [](const std::string &str, const std::string &test) {
302  return str.find(test) != std::string::npos;
303  };
304 
305  std::string trgstr(trigger);
306  if(contains(trgstr, "INT7")) task->SetTriggerSelection(AliVEvent::kINT7, "INT7");
307  else if(contains(trgstr, "EJ1")) task->SetTriggerSelection(AliVEvent::kEMCEJE, "EJ1");
308  else if(contains(trgstr, "EJ2")) task->SetTriggerSelection(AliVEvent::kEMCEJE, "EJ2");
309  else if(contains(trgstr, "EG1")) task->SetTriggerSelection(AliVEvent::kEMCEGA, "EG1");
310  else if(contains(trgstr, "EG2")) task->SetTriggerSelection(AliVEvent::kEMCEGA, "EG2");
311 
312  // Connect particle and cluster container
313  AliTrackContainer *tracks(nullptr);
314  AliClusterContainer *clusters(nullptr);
315  if(jettype == AliJetContainer::kChargedJet || jettype == AliJetContainer::kFullJet) {
317  tracks->SetMinPt(0.15);
318  }
319  if(jettype == AliJetContainer::kNeutralJet || jettype == AliJetContainer::kFullJet){
320  clusters = task->AddClusterContainer(EMCalTriggerPtAnalysis::AliEmcalAnalysisFactory::ClusterContainerNameFactory(isAOD));
321  clusters->SetDefaultClusterEnergy(AliVCluster::kHadCorr);
322  clusters->SetClusHadCorrEnergyCut(0.3);
323  }
324 
325 
326  // Create proper jet container
327  auto jetcont = task->AddJetContainer(jettype, AliJetContainer::antikt_algorithm, AliJetContainer::E_scheme, radius, acctype, tracks, clusters);
328  jetcont->SetName("datajets");
329  task->SetNameJetContainer("datajets");
330  std::cout << "Adding jet container with underlying array:" << jetcont->GetArrayName() << std::endl;
331 
332  // Link input and output container
333  outfilename << mgr->GetCommonFileName() << ":JetSpectrum_" << tag.str().data();
334  mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
335  mgr->ConnectOutput(task, 1, mgr->CreateContainer(Form("JetSpectrum_%s", tag.str().data()), TList::Class(), AliAnalysisManager::kOutputContainer, outfilename.str().data()));
336 
337  return task;
338 }
EMCal fiducial acceptance (each eta, phi edge narrowed by jet R)
Class creating a variable binning, used in the histogram manager.
Class creating a linear binning, used in the histogram manager.
AliJetContainer * GetJetContainer(Int_t i=0) const
Double_t Eta() const
Definition: AliEmcalJet.h:121
Double_t Phi() const
Definition: AliEmcalJet.h:117
Container with name, TClonesArray and cuts for particles.
void SetUseAliAnaUtils(Bool_t b, Bool_t bRejPilup=kTRUE)
Bool_t fRequireSubsetMB
Require for triggers to be a subset of Min. Bias (for efficiency studies)
static AliAnalysisTaskEmcalJetEnergySpectrum * AddTaskJetEnergySpectrum(Bool_t isMC, AliJetContainer::EJetType_t jettype, double radius, const char *trigger, const char *suffix="")
std::vector< TriggerCluster_t > GetTriggerClusterIndices(const TString &triggerstring) const
Double_t E() const
Definition: AliEmcalJet.h:119
Interface for binnings used by the histogram handler.
Definition: TBinning.h:21
static std::vector< PWG::EMCAL::Triggerinfo > DecodeTriggerString(const std::string &triggerstring)
Decoding trigger string.
void FillTHnSparse(const char *name, const double *x, double weight=1., Option_t *opt="")
virtual bool Run()
Run function. This is the core function of the analysis and contains the user code. Therefore users have to implement this function.
unsigned int UInt_t
Definition: External.C:33
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
ULong_t fMinBiasTrigger
Min bias trigger for trigger subset (for efficiency studies)
TH1 * CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt="")
Create a new TH1 within the container.
TPC fiducial acceptance (each eta edge narrowed by jet R)
void FillTH1(const char *hname, double x, double weight=1., Option_t *opt="")
Fill a 1D histogram within the container.
Bool_t fRequestTriggerClusters
Request distinction of trigger clusters.
Double_t Pt() const
Definition: AliEmcalJet.h:109
Bool_t fUseTriggerSelectionForData
Use trigger selection on data (require trigger patch in addition to trigger selection string) ...
Bool_t isMC
AliEmcalList * fOutput
!output list
Base task in the EMCAL jet framework.
Represent a jet reconstructed using the EMCal jet framework.
Definition: AliEmcalJet.h:51
Container class for histograms.
Definition: THistManager.h:99
void test(int runnumber=195345)
void UserCreateOutputObjects()
Main initialization function on the worker.
bool Bool_t
Definition: External.C:53
Double_t NEF() const
Definition: AliEmcalJet.h:148
void SetDefaultClusterEnergy(Int_t d)
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.
Container structure for EMCAL clusters.
void SetClusHadCorrEnergyCut(Double_t cut)
static TString ClusterContainerNameFactory(Bool_t isAOD)
Get name of the default cluster container.
static TString TrackContainerNameFactory(Bool_t isAOD)
Get name of the default track container.