AliPhysics  d009c82 (d009c82)
AliAnalysisTaskEmcalJetEnergyScale.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 <string>
30 #include <sstream>
31 #include <vector>
32 #include <THistManager.h>
33 #include <TCustomBinning.h>
34 #include <TLinearBinning.h>
35 
36 #include "AliAODInputHandler.h"
37 #include "AliAnalysisManager.h"
41 #include "AliLog.h"
42 #include "AliVEventHandler.h"
43 
45 
46 using namespace EmcalTriggerJets;
47 
50  fHistos(nullptr),
51  fNameDetectorJets(),
52  fNameParticleJets(),
53  fTriggerSelectionString(),
54  fNameTriggerDecisionContainer("EmcalTriggerDecision")
55 {
56 }
57 
58 AliAnalysisTaskEmcalJetEnergyScale::AliAnalysisTaskEmcalJetEnergyScale(const char *name):
59  AliAnalysisTaskEmcalJet(name, true),
60  fHistos(nullptr),
61  fNameDetectorJets(),
62  fNameParticleJets(),
63  fTriggerSelectionString(),
64  fNameTriggerDecisionContainer("EmcalTriggerDecision")
65 {
66  SetUseAliAnaUtils(true);
67  DefineOutput(1, TList::Class());
68 }
69 
71  if(fHistos) delete fHistos;
72 }
73 
76 
77  TLinearBinning jetPtBinning(20, 0., 200.), nefbinning(100, 0., 1.), ptdiffbinning(200, -1., 1.), jetEtaBinning(100, -0.9, 0.9), jetPhiBinning(100, 0., TMath::TwoPi());
78 
79  const TBinning *diffbinning[3] = {&jetPtBinning, &nefbinning, &ptdiffbinning},
80  *corrbinning[3] = {&jetPtBinning, &jetPtBinning, &nefbinning},
81  *effbinning[3] = {&jetPtBinning, &jetEtaBinning, &jetPhiBinning};
82 
83  fHistos = new THistManager("energyScaleHistos");
84  fHistos->CreateTH1("hEventCounter", "Event counter", 1, 0.5, 1.5);
85  fHistos->CreateTHnSparse("hPtDiff", "pt diff det/part", 3., diffbinning, "s");
86  fHistos->CreateTHnSparse("hPtCorr", "Correlation det pt / part pt", 3., corrbinning, "s");
87  fHistos->CreateTHnSparse("hPartJetsAccepted", "Accepted particle level jets", 3, effbinning, "s");
88  fHistos->CreateTHnSparse("hPartJetsReconstructed", "Accepted and reconstructed particle level jets", 3, effbinning, "s");
89  for(auto h : *(fHistos->GetListOfHistograms())) fOutput->Add(h);
90 
91  PostData(1, fOutput);
92 }
93 
95  AliDebugStream(1) << "Next event" << std::endl;
96  if(!(fInputHandler->IsEventSelected() & AliVEvent::kINT7)) return false;
98  auto mctrigger = static_cast<PWG::EMCAL::AliEmcalTriggerDecisionContainer *>(fInputEvent->FindListObject(fNameTriggerDecisionContainer));
99  AliDebugStream(1) << "Found trigger decision object: " << (mctrigger ? "yes" : "no") << std::endl;
100  if(!mctrigger){
101  AliErrorStream() << "Trigger decision container with name " << fNameTriggerDecisionContainer << " not found in event - not possible to select EMCAL triggers" << std::endl;
102  return false;
103  }
104  if(!mctrigger->IsEventSelected(fTriggerSelectionString)) return false;
105  }
106  AliDebugStream(1) << "event selected" << std::endl;
107  fHistos->FillTH1("hEventCounter", 1);
108 
109  auto detjets = GetJetContainer(fNameDetectorJets),
111  if(!detjets || !partjets) {
112  AliErrorStream() << "At least one jet container missing, exiting ..." << std::endl;
113  return false;
114  }
115  AliDebugStream(1) << "Have both jet containers: part(" << partjets->GetNAcceptedJets() << "|" << partjets->GetNJets() << "), det(" << detjets->GetNAcceptedJets() << "|" << detjets->GetNJets() << ")" << std::endl;
116 
117  std::vector<AliEmcalJet *> taggedjets;
118  for(auto detjet : detjets->accepted()){
119  AliDebugStream(2) << "Next jet" << std::endl;
120  auto partjet = detjet->ClosestJet();
121  if(!partjet) {
122  AliDebugStream(2) << "No tagged jet" << std::endl;
123  continue;
124  }
125  taggedjets.emplace_back(partjet);
126  double pointCorr[3] = {partjet->Pt(), detjet->Pt(), detjet->NEF()},
127  pointDiff[3] = {partjet->Pt(), (detjet->Pt()-partjet->Pt())/partjet->Pt(), detjet->NEF()};
128  fHistos->FillTHnSparse("hPtDiff", pointDiff);
129  fHistos->FillTHnSparse("hPtCorr", pointCorr);
130  }
131 
132  // efficiency x acceptance: Add histos for all accepted and reconstucted accepted jets
133  for(auto partjet : partjets->accepted()){
134  double pvect[3] = {partjet->Pt(), partjet->Eta(), partjet->Phi()};
135  if(pvect[2] < 0) pvect[2] += TMath::TwoPi();
136  fHistos->FillTHnSparse("hPartJetsAccepted", pvect);
137  if(std::find(taggedjets.begin(), taggedjets.end(), partjet) != taggedjets.end()) fHistos->FillTHnSparse("hPartJetsReconstructed", pvect);
138  }
139  return true;
140 }
141 
143  const std::array<TString, 8> kEMCALTriggers = {
144  "EJ1", "EJ2", "DJ1", "DJ2", "EG1", "EG2", "DG1", "DG2"
145  };
146  bool isEMCAL = false;
147  for(auto emcaltrg : kEMCALTriggers) {
148  if(triggerstring.Contains(emcaltrg)) {
149  isEMCAL = true;
150  break;
151  }
152  }
153  return isEMCAL;
154 }
155 
157  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
158  if(!mgr){
159  ::Error("EmcalTriggerJets::AliAnalysisTaskEmcalJetEnergyScale::AddTaskJetEnergyScale", "No analysis manager available");
160  return nullptr;
161  }
162 
163  auto inputhandler = mgr->GetInputEventHandler();
164  auto isAOD = inputhandler->IsA() == AliAODInputHandler::Class();
165 
166  std::string jettypename;
168  bool addClusterContainer(false), addTrackContainer(false);
169  switch(jettype){
171  jettypename = "FullJet";
172  acceptance = useDCAL ? AliJetContainer::kDCALfid : AliJetContainer::kEMCALfid;
173  addClusterContainer = addTrackContainer = true;
174  break;
176  jettypename = "ChargedJet";
177  acceptance = AliJetContainer::kTPCfid;
178  addTrackContainer = true;
179  break;
181  jettypename = "NeutralJet";
182  acceptance = useDCAL ? AliJetContainer::kDCALfid : AliJetContainer::kEMCALfid;
183  addClusterContainer = true;
184  break;
185  };
186 
187  std::stringstream taskname, tag;
188  tag << jettypename << "_R" << std::setw(2) << std::setfill('0') << int(jetradius * 10.) << "_" << trigger;
189  taskname << "EnergyScaleTask_" << tag.str();
190  AliAnalysisTaskEmcalJetEnergyScale *energyscaletask = new AliAnalysisTaskEmcalJetEnergyScale(taskname.str().data());
191  mgr->AddTask(energyscaletask);
192  energyscaletask->SetTriggerName(trigger);
193 
194  auto partcont = energyscaletask->AddMCParticleContainer("mcparticles");
195  partcont->SetMinPt(0.);
196 
197  AliClusterContainer *clusters(nullptr);
198  if(addClusterContainer) {
200  switch(jettype){
201  case AliJetContainer::kChargedJet: break; // Silence compiler
203  clusters->SetDefaultClusterEnergy(AliVCluster::kHadCorr);
204  clusters->SetClusHadCorrEnergyCut(0.3);
205  break;
207  clusters->SetDefaultClusterEnergy(AliVCluster::kNonLinCorr);
208  clusters->SetClusNonLinCorrEnergyCut(0.3);
209  break;
210  };
211  }
212  AliTrackContainer *tracks(nullptr);
213  if(addTrackContainer) {
215  }
216 
217  auto contpartjet = energyscaletask->AddJetContainer(jettype, AliJetContainer::antikt_algorithm, AliJetContainer::E_scheme, jetradius,
218  AliJetContainer::kTPCfid, partcont, nullptr);
219  contpartjet->SetName("particleLevelJets");
220  energyscaletask->SetNamePartJetContainer("particleLevelJets");
221  std::cout << "Adding particle-level jet container with underling array: " << contpartjet->GetArrayName() << std::endl;
222 
223  auto contdetjet = energyscaletask->AddJetContainer(jettype, AliJetContainer::antikt_algorithm, AliJetContainer::E_scheme, jetradius,
224  acceptance, tracks, clusters);
225  contdetjet->SetName("detectorLevelJets");
226  energyscaletask->SetNameDetJetContainer("detectorLevelJets");
227  std::cout << "Adding detector-level jet container with underling array: " << contdetjet->GetArrayName() << std::endl;
228 
229  std::stringstream outnamebuilder, listnamebuilder;
230  listnamebuilder << "EnergyScaleHists_" << tag.str();
231  outnamebuilder << mgr->GetCommonFileName() << ":EnergyScaleResults_" << tag.str();
232 
233  mgr->ConnectInput(energyscaletask, 0, mgr->GetCommonInputContainer());
234  mgr->ConnectOutput(energyscaletask, 1, mgr->CreateContainer(listnamebuilder.str().data(), TList::Class(), AliAnalysisManager::kOutputContainer, outnamebuilder.str().data()));
235  return energyscaletask;
236 }
EMCal fiducial acceptance (each eta, phi edge narrowed by jet R)
double Double_t
Definition: External.C:58
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)
AliJetContainer * AddJetContainer(const char *n, TString defaultCutType, Float_t jetRadius=0.4)
Interface for binnings used by the histogram handler.
Definition: TBinning.h:21
TString fNameTriggerDecisionContainer
Global trigger decision container.
AliClusterContainer * AddClusterContainer(const char *n)
Create new cluster container and attach it to the task.
DCal fiducial acceptance (each eta, phi edge narrowed by jet R)
void FillTHnSparse(const char *name, const double *x, double weight=1., Option_t *opt="")
JetAcceptanceType
Bit definition for jet geometry acceptance. Defined here for backwards compatibility. This will be removed. Please use AliEmcalJet::JetAcceptanceType in your code.
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
static AliAnalysisTaskEmcalJetEnergyScale * AddTaskJetEnergyScale(AliJetContainer::EJetType_t jetType, Double_t radius, Bool_t useDCAL, const char *trigger)
void SetClusNonLinCorrEnergyCut(Double_t cut)
virtual Bool_t Run()
Run function. This is the core function of the analysis and contains the user code. Therefore users have to implement this function.
TH1 * CreateTH1(const char *name, const char *title, int nbins, double xmin, double xmax, Option_t *opt="")
Create a new TH1 within the container.
AliMCParticleContainer * AddMCParticleContainer(const char *n)
Create new container for MC particles and attach it to the task.
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.
AliEmcalList * fOutput
!output list
AliTrackContainer * AddTrackContainer(const char *n)
Create new track container and attach it to the task.
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)
static TString TrackContainerNameFactory(Bool_t isAOD)
Get name of the default track container.
static TString ClusterContainerNameFactory(Bool_t isAOD)
Get name of the default cluster container.