AliPhysics  93c564e (93c564e)
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 "AliAnalysisManager.h"
39 #include "AliEmcalJet.h"
42 #include "AliInputEventHandler.h"
43 #include "AliJetContainer.h"
44 #include "AliLog.h"
45 #include "AliVEvent.h"
46 
48 
49 using namespace EmcalTriggerJets;
50 
52  AliAnalysisTaskEmcalJet(name, true),
53  fHistos(nullptr),
54  fIsMC(false),
55  fTriggerSelectionBits(AliVEvent::kAny),
56  fTriggerSelectionString(""),
57  fNameTriggerDecisionContainer("EmcalTriggerDecision"),
58  fUseTriggerSelectionForData(true),
59  fUseDownscaleWeight(false),
60  fNameJetContainer("datajets")
61 {
62  SetUseAliAnaUtils(true);
63 }
64 
66  if(fHistos) delete fHistos;
67 }
68 
71 
72  TLinearBinning jetptbinning(200, 0., 200.), etabinning(100, -1., 1.), phibinning(100., 0., 7.), nefbinning(100, 0., 1.), trgclusterbinning(5, -1.5, 3.5);
73  const TBinning *binnings[5] = {&jetptbinning, &etabinning, &phibinning, &nefbinning, &trgclusterbinning};
74  fHistos = new THistManager(Form("Histos_%s", GetName()));
75  fHistos->CreateTH1("hEventCounter", "Event counter histogram", 1, 0.5, 1.5);
76  fHistos->CreateTH1("hClusterCounter", "Event counter histogram", 5, -1.5, 3.5);
77  fHistos->CreateTHnSparse("hJetTHnSparse", "jet thnsparse", 5, binnings, "s");
78 
79  for(auto h : *fHistos->GetListOfHistograms()) fOutput->Add(h);
80  PostData(1, fOutput);
81 }
82 
84  auto datajets = this->GetJetContainer(fNameJetContainer);
85  if(!datajets) {
86  AliErrorStream() << "Jet container " << fNameJetContainer << " not found" << std::endl;
87  return false;
88  }
89  if(!TriggerSelection()) return false;
90 
91  auto trgcluster = GetTriggerClusterIndex(fInputEvent->GetFiredTriggerClasses());
92  fHistos->FillTH1("hEventCounter", 1);
93  fHistos->FillTH1("hClusterCounter", trgcluster);
94  for(auto j : datajets->accepted()){
95  double datapoint[5] = {j->Pt(), j->Eta(), j->Phi(), j->NEF(), static_cast<double>(trgcluster)};
96  fHistos->FillTHnSparse("hJetTHnSparse", datapoint);
97  }
98  return true;
99 }
100 
102  // decode trigger string in order to determine the trigger clusters
103  int clusterindex = -1;
104  std::vector<std::string> clusternames;
105  auto triggerinfos = PWG::EMCAL::Triggerinfo::DecodeTriggerString(triggerstring.Data());
106  for(auto t : triggerinfos) {
107  if(std::find(clusternames.begin(), clusternames.end(), t.Triggercluster()) == clusternames.end()) clusternames.emplace_back(t.Triggercluster());
108  }
109  bool isCENT = (std::find(clusternames.begin(), clusternames.end(), "CENT") != clusternames.end()),
110  isCENTNOTRD = (std::find(clusternames.begin(), clusternames.end(), "CENTNOTRD") != clusternames.end()),
111  isCALO = (std::find(clusternames.begin(), clusternames.end(), "CALO") != clusternames.end()),
112  isCALOFAST = (std::find(clusternames.begin(), clusternames.end(), "CALOFAST") != clusternames.end());
113  if(isCENT) clusterindex = 0;
114  else if(isCENTNOTRD) clusterindex = 1;
115  else if(isCALO) clusterindex = 2;
116  else if(isCALOFAST) clusterindex = 3;
117  return clusterindex;
118 }
119 
121  if(!fIsMC){
122  // Pure data - do EMCAL trigger selection from selection string
123  if(!(fInputHandler->IsEventSelected() & fTriggerSelectionBits)) return false;
124  if(fTriggerSelectionString.Length()) {
125  if(!fInputEvent->GetFiredTriggerClasses().Contains(fTriggerSelectionString)) return false;
127  auto trgselresult = static_cast<PWG::EMCAL::AliEmcalTriggerDecisionContainer *>(fInputEvent->FindListObject(fNameTriggerDecisionContainer));
128  AliDebugStream(1) << "Found trigger decision object: " << (trgselresult ? "yes" : "no") << std::endl;
129  if(!trgselresult){
130  AliErrorStream() << "Trigger decision container with name " << fNameTriggerDecisionContainer << " not found in event - not possible to select EMCAL triggers" << std::endl;
131  return false;
132  }
133  if(!trgselresult->IsEventSelected(fTriggerSelectionString)) return false;
134  }
135  }
136  } else {
138  // Simulation - do EMCAL trigger selection from trigger selection object
139  auto mctrigger = static_cast<PWG::EMCAL::AliEmcalTriggerDecisionContainer *>(fInputEvent->FindListObject(fNameTriggerDecisionContainer));
140  AliDebugStream(1) << "Found trigger decision object: " << (mctrigger ? "yes" : "no") << std::endl;
141  if(!mctrigger){
142  AliErrorStream() << "Trigger decision container with name " << fNameTriggerDecisionContainer << " not found in event - not possible to select EMCAL triggers" << std::endl;
143  return false;
144  }
145  if(!mctrigger->IsEventSelected(fTriggerSelectionString)) return false;
146  }
147  }
148  return true;
149 }
150 
151 bool AliAnalysisTaskEmcalJetEnergySpectrum::IsSelectEmcalTriggers(const std::string &triggerstring) const {
152  const std::array<std::string, 8> kEMCALTriggers = {
153  "EJ1", "EJ2", "DJ1", "DJ2", "EG1", "EG2", "DG1", "DG2"
154  };
155  bool isEMCAL = false;
156  for(auto emcaltrg : kEMCALTriggers) {
157  if(triggerstring.find(emcaltrg) != std::string::npos) {
158  isEMCAL = true;
159  break;
160  }
161  }
162  return isEMCAL;
163 }
164 
165 
167  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
168  if(!mgr) {
169  std::cerr << "Analysis manager not initialized" << std::endl;
170  return nullptr;
171  }
172 
173  std::string jettypestring;
175  switch(jettype){
176  case AliJetContainer::kChargedJet: jettypestring = "ChargedJets"; acctype = AliJetContainer::kTPCfid; break;
177  case AliJetContainer::kFullJet: jettypestring = "FullJets"; acctype = AliJetContainer::kEMCALfid; break;
178  case AliJetContainer::kNeutralJet: jettypestring = "NeutralJets"; acctype = AliJetContainer::kTPCfid; break;
179  };
180 
181  std::stringstream tag, outfilename;
182  tag << jettypestring << "_R" << std::setw(2) << std::setfill('0') << radius << "_" << trigger;
183  if(strlen(suffix)) {
184  tag << "_" << suffix;
185  }
186  auto task = new AliAnalysisTaskEmcalJetEnergySpectrum(Form("JetEnergySpectrum_%s", tag.str().data()));
187  task->SetIsMC(isMC);
188  mgr->AddTask(task);
189 
190  // Connect particle and cluster container
191  AliTrackContainer *tracks(nullptr);
192  AliClusterContainer *clusters(nullptr);
193  if(jettype == AliJetContainer::kChargedJet || jettype == AliJetContainer::kFullJet) {
194  tracks = task->AddTrackContainer("usedefault");
195  tracks->SetMinPt(0.15);
196  }
197  if(jettype == AliJetContainer::kNeutralJet || jettype == AliJetContainer::kChargedJet){
198  clusters = task->AddClusterContainer("usedefault");
199  clusters->SetDefaultClusterEnergy(AliVCluster::kHadCorr);
200  clusters->SetClusHadCorrEnergyCut(0.3);
201  }
202 
203 
204  // Create proper jet container
205  auto jetcont = task->AddJetContainer(jettype, AliJetContainer::antikt_algorithm, AliJetContainer::E_scheme, radius, acctype, tracks, clusters);
206  jetcont->SetName("datajets");
207  task->SetNameJetContainer("datajets");
208 
209  // Link input and output container
210  outfilename << mgr->GetCommonFileName() << ":JetSpectrum_" << tag.str().data();
211  mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
212  mgr->ConnectOutput(task, 1, mgr->CreateContainer(Form("JetSpectrum_%s", tag.str().data()), TList::Class(), AliAnalysisManager::kOutputContainer, outfilename.str().data()));
213 
214  return task;
215 }
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
Container with name, TClonesArray and cuts for particles.
void SetUseAliAnaUtils(Bool_t b, Bool_t bRejPilup=kTRUE)
static AliAnalysisTaskEmcalJetEnergySpectrum * AddTaskJetEnergySpectrum(Bool_t isMC, AliJetContainer::EJetType_t jettype, double radius, const char *trigger, const char *suffix="")
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.
int Int_t
Definition: External.C:63
unsigned int UInt_t
Definition: External.C:33
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
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 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.
Container class for histograms.
Definition: THistManager.h:99
void UserCreateOutputObjects()
Main initialization function on the worker.
bool Bool_t
Definition: External.C:53
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)