AliPhysics  93c564e (93c564e)
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 <array>
28 #include <string>
29 #include <sstream>
30 #include <THistManager.h>
31 #include <TCustomBinning.h>
32 #include <TLinearBinning.h>
33 
34 #include "AliAODInputHandler.h"
35 #include "AliAnalysisManager.h"
39 #include "AliLog.h"
40 #include "AliVEventHandler.h"
41 
43 
44 using namespace EmcalTriggerJets;
45 
47  AliAnalysisTaskEmcalJet(name, true),
48  fHistos(nullptr),
49  fNameDetectorJets(),
50  fNameParticleJets(),
51  fTriggerSelectionString(),
52  fNameTriggerDecisionContainer("EmcalTriggerDecision")
53 {
54  DefineOutput(1, TList::Class());
55 }
56 
57 AliAnalysisTaskEmcalJetEnergyScale::~AliAnalysisTaskEmcalJetEnergyScale() {
58  if(fHistos) delete fHistos;
59 }
60 
63 
64  TLinearBinning jetPtBinning(20, 0., 200.), nefbinning(100, 0., 1.), ptdiffbinning(200, -1., 1.);
65 
66  const TBinning *diffbinning[3] = {&jetPtBinning, &nefbinning, &ptdiffbinning},
67  *corrbinning[3] = {&jetPtBinning, &jetPtBinning, &nefbinning};
68 
69  fHistos = new THistManager("energyScaleHistos");
70  fHistos->CreateTH1("hEventCounter", "Event counter", 1, 0.5, 1.5);
71  fHistos->CreateTHnSparse("hPtDiff", "pt diff det/part", 3., diffbinning, "s");
72  fHistos->CreateTHnSparse("hPtCorr", "Correlation det pt / part pt", 3., corrbinning, "s");
73  for(auto h : *(fHistos->GetListOfHistograms())) fOutput->Add(h);
74 
75  PostData(1, fOutput);
76 }
77 
79  if(!(fInputHandler->IsEventSelected() & AliVEvent::kINT7)) return false;
81  auto mctrigger = static_cast<PWG::EMCAL::AliEmcalTriggerDecisionContainer *>(fInputEvent->FindListObject(fNameTriggerDecisionContainer));
82  AliDebugStream(1) << "Found trigger decision object: " << (mctrigger ? "yes" : "no") << std::endl;
83  if(!mctrigger){
84  AliErrorStream() << "Trigger decision container with name " << fNameTriggerDecisionContainer << " not found in event - not possible to select EMCAL triggers" << std::endl;
85  return false;
86  }
87  if(!mctrigger->IsEventSelected(fTriggerSelectionString)) return false;
88  }
89  fHistos->FillTH1("hEventCounter", 1);
90 
91  auto detjets = GetJetContainer(fNameDetectorJets),
93  if(!detjets || !partjets) {
94  AliErrorStream() << "At least one jet container missing, exiting ..." << std::endl;
95  return false;
96  }
97 
98  for(auto detjet : detjets->accepted()){
99  auto partjet = detjet->ClosestJet();
100  if(!partjet) continue;
101  double pointCorr[3] = {partjet->Pt(), detjet->Pt(), detjet->NEF()},
102  pointDiff[3] = {partjet->Pt(), (detjet->Pt()-partjet->Pt())/partjet->Pt(), detjet->NEF()};
103  fHistos->FillTHnSparse("hPtDiff", pointDiff);
104  fHistos->FillTHnSparse("hPtCorr", pointCorr);
105  }
106  return true;
107 }
108 
110  const std::array<TString, 8> kEMCALTriggers = {
111  "EJ1", "EJ2", "DJ1", "DJ2", "EG1", "EG2", "DG1", "DG2"
112  };
113  bool isEMCAL = false;
114  for(auto emcaltrg : kEMCALTriggers) {
115  if(triggerstring.Contains(emcaltrg)) {
116  isEMCAL = true;
117  break;
118  }
119  }
120  return isEMCAL;
121 }
122 
124  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
125  if(!mgr){
126  ::Error("EmcalTriggerJets::AliAnalysisTaskEmcalJetEnergyScale::AddTaskJetEnergyScale", "No analysis manager available");
127  return nullptr;
128  }
129 
130  auto inputhandler = mgr->GetInputEventHandler();
131  auto isAOD = inputhandler->IsA() == AliAODInputHandler::Class();
132 
133  std::string jettypename;
135  bool addClusterContainer(false), addTrackContainer(false);
136  switch(jettype){
138  jettypename = "FullJet";
139  acceptance = useDCAL ? AliJetContainer::kDCALfid : AliJetContainer::kEMCALfid;
140  addClusterContainer = addTrackContainer = true;
141  break;
143  jettypename = "ChargedJet";
144  acceptance = AliJetContainer::kTPCfid;
145  addTrackContainer = true;
146  break;
148  jettypename = "NeutralJet";
149  acceptance = useDCAL ? AliJetContainer::kDCALfid : AliJetContainer::kEMCALfid;
150  addClusterContainer = true;
151  break;
152  };
153 
154  std::stringstream taskname, tag;
155  tag << jettypename << "_R" << std::setw(2) << std::setfill('0') << int(jetradius * 10.) << "_" << trigger;
156  taskname << "EnergyScaleTask_" << tag.str();
157  AliAnalysisTaskEmcalJetEnergyScale *energyscaletask = new AliAnalysisTaskEmcalJetEnergyScale(taskname.str().data());
158  mgr->AddTask(energyscaletask);
159 
160  auto partcont = energyscaletask->AddMCParticleContainer("mcparticles");
161  partcont->SetMinPt(0.);
162 
163  AliClusterContainer *clusters(nullptr);
164  if(addClusterContainer) {
166  }
167  AliTrackContainer *tracks(nullptr);
168  if(addTrackContainer) {
170  }
171 
172  auto contpartjet = energyscaletask->AddJetContainer(jettype, AliJetContainer::antikt_algorithm, AliJetContainer::E_scheme, jetradius,
173  acceptance, partcont, nullptr, "Jet");
174  contpartjet->SetName("particleLevelJets");
175  energyscaletask->SetNamePartJetContainer("particleLevelJets");
176 
177  auto contdetjet = energyscaletask->AddJetContainer(jettype, AliJetContainer::antikt_algorithm, AliJetContainer::E_scheme, jetradius,
178  acceptance, tracks, clusters, "Jet");
179  contdetjet->SetName("detectorLevelJets");
180  energyscaletask->SetNameDetJetContainer("detectorLevelJets");
181 
182  std::stringstream outnamebuilder, listnamebuilder;
183  listnamebuilder << "EnergyScaleHists_" << tag.str();
184  outnamebuilder << mgr->GetCommonFileName() << ":EnergyScaleResults_" << tag.str();
185 
186  mgr->ConnectInput(energyscaletask, 0, mgr->GetCommonInputContainer());
187  mgr->ConnectOutput(energyscaletask, 1, mgr->CreateContainer(listnamebuilder.str().data(), TList::Class(), AliAnalysisManager::kOutputContainer, outnamebuilder.str().data()));
188  return energyscaletask;
189 }
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.
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)
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
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.
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.