AliPhysics  ef3b16e (ef3b16e)
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 
36 #include "AliAODInputHandler.h"
37 #include "AliAnalysisManager.h"
40 #include "AliEmcalJet.h"
43 #include "AliInputEventHandler.h"
44 #include "AliJetContainer.h"
45 #include "AliLog.h"
46 #include "AliVEvent.h"
47 
49 
50 using namespace EmcalTriggerJets;
51 
54  fHistos(nullptr),
55  fIsMC(false),
56  fTriggerSelectionBits(AliVEvent::kAny),
57  fTriggerSelectionString(""),
58  fRequireSubsetMB(false),
59  fMinBiasTrigger(AliVEvent::kAny),
60  fNameTriggerDecisionContainer("EmcalTriggerDecision"),
61  fUseTriggerSelectionForData(false),
62  fUseDownscaleWeight(false),
63  fNameJetContainer("datajets")
64 {
65  SetUseAliAnaUtils(true);
66 }
67 
69  AliAnalysisTaskEmcalJet(name, true),
71  fIsMC(false),
72  fTriggerSelectionBits(AliVEvent::kAny),
74  fRequireSubsetMB(false),
75  fMinBiasTrigger(AliVEvent::kAny),
76  fNameTriggerDecisionContainer("EmcalTriggerDecision"),
78  fUseDownscaleWeight(false),
79  fNameJetContainer("datajets")
80 {
81  SetUseAliAnaUtils(true);
82 }
83 
85  if(fHistos) delete fHistos;
86 }
87 
90 
91  TLinearBinning jetptbinning(200, 0., 200.), etabinning(100, -1., 1.), phibinning(100., 0., 7.), nefbinning(100, 0., 1.), trgclusterbinning(kTrgClusterN + 1, -0.5, kTrgClusterN -0.5);
92  const TBinning *binnings[5] = {&jetptbinning, &etabinning, &phibinning, &nefbinning, &trgclusterbinning};
93  fHistos = new THistManager(Form("Histos_%s", GetName()));
94  fHistos->CreateTH1("hEventCounter", "Event counter histogram", 1, 0.5, 1.5);
95  fHistos->CreateTH1("hClusterCounter", "Event counter histogram", kTrgClusterN, -0.5, kTrgClusterN - 0.5);
96  fHistos->CreateTHnSparse("hJetTHnSparse", "jet thnsparse", 5, binnings, "s");
97  fHistos->CreateTHnSparse("hMaxJetTHnSparse", "jet thnsparse", 5, binnings, "s");
98 
99  for(auto h : *fHistos->GetListOfHistograms()) fOutput->Add(h);
100  PostData(1, fOutput);
101 }
102 
104  auto datajets = this->GetJetContainer(fNameJetContainer);
105  if(!datajets) {
106  AliErrorStream() << "Jet container " << fNameJetContainer << " not found" << std::endl;
107  return false;
108  }
109 
110  auto trgclusters = GetTriggerClusterIndices(fInputEvent->GetFiredTriggerClasses());
111  fHistos->FillTH1("hEventCounter", 1);
112  AliEmcalJet *maxjet(nullptr);
113  for(auto t : trgclusters) fHistos->FillTH1("hClusterCounter", t);
114  for(auto j : datajets->accepted()){
115  if(!maxjet || (j->E() > maxjet->E())) maxjet = j;
116  double datapoint[5] = {j->Pt(), j->Eta(), j->Phi(), j->NEF(), 0.};
117  for(auto t : trgclusters){
118  datapoint[4] = static_cast<double>(t);
119  fHistos->FillTHnSparse("hJetTHnSparse", datapoint);
120  }
121  }
122 
123  double maxdata[5];
124  memset(maxdata, 0., sizeof(double) * 5);
125  if(maxjet){
126  maxdata[0] = maxjet->Pt();
127  maxdata[1] = maxjet->Eta();
128  maxdata[2] = maxjet->Phi();
129  maxdata[3] = maxjet->NEF();
130  for(auto t : trgclusters){
131  maxdata[4] = static_cast<double>(t);
132  fHistos->FillTHnSparse("hMaxJetTHnSparse", maxdata);
133  }
134  }
135  return true;
136 }
137 
138 std::vector<AliAnalysisTaskEmcalJetEnergySpectrum::TriggerCluster_t> AliAnalysisTaskEmcalJetEnergySpectrum::GetTriggerClusterIndices(const TString &triggerstring) const {
139  // decode trigger string in order to determine the trigger clusters
140  std::vector<TriggerCluster_t> result;
141  result.emplace_back(kTrgClusterANY); // cluster ANY always included
142  if(!fIsMC){
143  // Data - separate trigger clusters
144  std::vector<std::string> clusternames;
145  auto triggerinfos = PWG::EMCAL::Triggerinfo::DecodeTriggerString(triggerstring.Data());
146  for(auto t : triggerinfos) {
147  if(std::find(clusternames.begin(), clusternames.end(), t.Triggercluster()) == clusternames.end()) clusternames.emplace_back(t.Triggercluster());
148  }
149  bool isCENT = (std::find(clusternames.begin(), clusternames.end(), "CENT") != clusternames.end()),
150  isCENTNOTRD = (std::find(clusternames.begin(), clusternames.end(), "CENTNOTRD") != clusternames.end()),
151  isCALO = (std::find(clusternames.begin(), clusternames.end(), "CALO") != clusternames.end()),
152  isCALOFAST = (std::find(clusternames.begin(), clusternames.end(), "CALOFAST") != clusternames.end());
153  if(isCENT || isCENTNOTRD) {
154  if(isCENT) {
155  result.emplace_back(kTrgClusterCENT);
156  if(isCENTNOTRD) {
157  result.emplace_back(kTrgClusterCENTNOTRD);
158  result.emplace_back(kTrgClusterCENTBOTH);
159  } else result.emplace_back(kTrgClusterOnlyCENT);
160  } else {
161  result.emplace_back(kTrgClusterCENTNOTRD);
162  result.emplace_back(kTrgClusterOnlyCENTNOTRD);
163  }
164  }
165  if(isCALO || isCALOFAST) {
166  if(isCALO) {
167  result.emplace_back(kTrgClusterCALO);
168  if(isCALOFAST) {
169  result.emplace_back(kTrgClusterCALOFAST);
170  result.emplace_back(kTrgClusterCALOBOTH);
171  } else result.emplace_back(kTrgClusterOnlyCALO);
172  } else {
173  result.emplace_back(kTrgClusterCALOFAST);
174  result.emplace_back(kTrgClusterOnlyCALOFAST);
175  }
176  }
177  }
178  return result;
179 }
180 
182  if(!fIsMC){
183  // Pure data - do EMCAL trigger selection from selection string
184  if(!(fInputHandler->IsEventSelected() & fTriggerSelectionBits)) return false;
185  if(fTriggerSelectionString.Length()) {
186  if(!fInputEvent->GetFiredTriggerClasses().Contains(fTriggerSelectionString)) return false;
187  if(fRequireSubsetMB && !(fInputHandler->IsEventSelected() & fMinBiasTrigger)) return false; // Require EMCAL trigger to be subset of the min. bias trigger (for efficiency studies)
188  if((fTriggerSelectionString.Contains("EJ") || fTriggerSelectionString.Contains("EG") || fTriggerSelectionString.Contains("DJ") || fTriggerSelectionString.Contains("DG")) && fUseTriggerSelectionForData) {
189  auto trgselresult = static_cast<PWG::EMCAL::AliEmcalTriggerDecisionContainer *>(fInputEvent->FindListObject(fNameTriggerDecisionContainer));
190  AliDebugStream(1) << "Found trigger decision object: " << (trgselresult ? "yes" : "no") << std::endl;
191  if(!trgselresult){
192  AliErrorStream() << "Trigger decision container with name " << fNameTriggerDecisionContainer << " not found in event - not possible to select EMCAL triggers" << std::endl;
193  return false;
194  }
195  if(!trgselresult->IsEventSelected(fTriggerSelectionString)) return false;
196  }
197  }
198  } else {
199  if(!(fInputHandler->IsEventSelected() & AliVEvent::kINT7)) return false;
201  // Simulation - do EMCAL trigger selection from trigger selection object
202  auto mctrigger = static_cast<PWG::EMCAL::AliEmcalTriggerDecisionContainer *>(fInputEvent->FindListObject(fNameTriggerDecisionContainer));
203  AliDebugStream(1) << "Found trigger decision object: " << (mctrigger ? "yes" : "no") << std::endl;
204  if(!mctrigger){
205  AliErrorStream() << "Trigger decision container with name " << fNameTriggerDecisionContainer << " not found in event - not possible to select EMCAL triggers" << std::endl;
206  return false;
207  }
208  if(!mctrigger->IsEventSelected(fTriggerSelectionString)) return false;
209  }
210  }
211  return true;
212 }
213 
214 bool AliAnalysisTaskEmcalJetEnergySpectrum::IsSelectEmcalTriggers(const std::string &triggerstring) const {
215  const std::array<std::string, 8> kEMCALTriggers = {
216  "EJ1", "EJ2", "DJ1", "DJ2", "EG1", "EG2", "DG1", "DG2"
217  };
218  bool isEMCAL = false;
219  for(auto emcaltrg : kEMCALTriggers) {
220  if(triggerstring.find(emcaltrg) != std::string::npos) {
221  isEMCAL = true;
222  break;
223  }
224  }
225  return isEMCAL;
226 }
227 
228 
230  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
231  if(!mgr) {
232  std::cerr << "Analysis manager not initialized" << std::endl;
233  return nullptr;
234  }
235 
236  Bool_t isAOD(kFALSE);
237  AliInputEventHandler *inputhandler = static_cast<AliInputEventHandler *>(mgr->GetInputEventHandler());
238  if(inputhandler) {
239  if(inputhandler->IsA() == AliAODInputHandler::Class()){
240  std::cout << "Analysing AOD events\n";
241  isAOD = kTRUE;
242  } else {
243  std::cout << "Analysing ESD events\n";
244  }
245  }
246 
247  std::string jettypestring;
249  switch(jettype){
250  case AliJetContainer::kChargedJet: jettypestring = "ChargedJets"; acctype = AliJetContainer::kTPCfid; break;
251  case AliJetContainer::kFullJet: jettypestring = "FullJets"; acctype = AliJetContainer::kEMCALfid; break;
252  case AliJetContainer::kNeutralJet: jettypestring = "NeutralJets"; acctype = AliJetContainer::kEMCALfid; break;
253  };
254 
255  std::stringstream tag, outfilename;
256  tag << jettypestring << "_R" << std::setw(2) << std::setfill('0') << int(radius * 10.) << "_" << trigger;
257  if(strlen(suffix)) {
258  tag << "_" << suffix;
259  }
260  auto task = new AliAnalysisTaskEmcalJetEnergySpectrum(Form("JetEnergySpectrum_%s", tag.str().data()));
261  task->SetIsMC(isMC);
262  mgr->AddTask(task);
263 
264  auto contains = [](const std::string &str, const std::string &test) {
265  return str.find(test) != std::string::npos;
266  };
267 
268  std::string trgstr(trigger);
269  if(contains(trgstr, "INT7")) task->SetTriggerSelection(AliVEvent::kINT7, "INT7");
270  else if(contains(trgstr, "EJ1")) task->SetTriggerSelection(AliVEvent::kEMCEJE, "EJ1");
271  else if(contains(trgstr, "EJ2")) task->SetTriggerSelection(AliVEvent::kEMCEJE, "EJ2");
272  else if(contains(trgstr, "EG1")) task->SetTriggerSelection(AliVEvent::kEMCEGA, "EG1");
273  else if(contains(trgstr, "EG2")) task->SetTriggerSelection(AliVEvent::kEMCEGA, "EG2");
274 
275  // Connect particle and cluster container
276  AliTrackContainer *tracks(nullptr);
277  AliClusterContainer *clusters(nullptr);
278  if(jettype == AliJetContainer::kChargedJet || jettype == AliJetContainer::kFullJet) {
280  tracks->SetMinPt(0.15);
281  }
282  if(jettype == AliJetContainer::kNeutralJet || jettype == AliJetContainer::kFullJet){
283  clusters = task->AddClusterContainer(EMCalTriggerPtAnalysis::AliEmcalAnalysisFactory::ClusterContainerNameFactory(isAOD));
284  clusters->SetDefaultClusterEnergy(AliVCluster::kHadCorr);
285  clusters->SetClusHadCorrEnergyCut(0.3);
286  }
287 
288 
289  // Create proper jet container
290  auto jetcont = task->AddJetContainer(jettype, AliJetContainer::antikt_algorithm, AliJetContainer::E_scheme, radius, acctype, tracks, clusters);
291  jetcont->SetName("datajets");
292  task->SetNameJetContainer("datajets");
293  std::cout << "Adding jet container with underlying array:" << jetcont->GetArrayName() << std::endl;
294 
295  // Link input and output container
296  outfilename << mgr->GetCommonFileName() << ":JetSpectrum_" << tag.str().data();
297  mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
298  mgr->ConnectOutput(task, 1, mgr->CreateContainer(Form("JetSpectrum_%s", tag.str().data()), TList::Class(), AliAnalysisManager::kOutputContainer, outfilename.str().data()));
299 
300  return task;
301 }
EMCal fiducial acceptance (each eta, phi edge narrowed by jet R)
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.
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.