AliPhysics  f9b5d69 (f9b5d69)
AliAnalysisTaskEmcalJetConstituentQA.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 <cmath>
29 #include <iomanip>
30 #include <iostream>
31 #include <sstream>
32 #include <string>
33 #include <THistManager.h>
34 #include <TLorentzVector.h>
35 
36 #include "AliAnalysisManager.h"
38 #include "AliAODInputHandler.h"
39 #include "AliClusterContainer.h"
41 #include "AliEmcalJet.h"
42 #include "AliInputEventHandler.h"
43 #include "AliJetContainer.h"
44 #include "AliLog.h"
45 #include "AliTrackContainer.h"
46 #include "AliVCluster.h"
47 #include "AliVEvent.h"
48 #include "AliVTrack.h"
49 
53 
54 using namespace EmcalTriggerJets;
55 
58  fHistos(nullptr),
59  fNameTrackContainer(""),
60  fNameClusterContainer(""),
61  fTriggerSelectionString("")
62 {
63  this->SetUseAliAnaUtils(true);
64 }
65 
67  AliAnalysisTaskEmcalJet(name, true),
72 {
73  this->SetUseAliAnaUtils(true);
74 }
75 
77  if(fHistos) delete fHistos;
78 }
79 
82 
83  fHistos = new THistManager(Form("histos_%s", GetName()));
84  for(auto c : fNamesJetContainers){
85  auto contname = dynamic_cast<TObjString *>(c);
86  if(!contname) continue;
87  fHistos->CreateTH2(Form("hPtChargedConstituents%s", contname->String().Data()), "Charged jet constituents; p_{t, jet} (GeV/c); p_{t,ch}", 200, 0., 200., 200., 0., 200.);
88  fHistos->CreateTH2(Form("hPtNeutralConstituents%s", contname->String().Data()), "Neutral jet constituents; p_{t, jet} (GeV/c); p_{t,ne}", 200, 0., 200., 200., 0., 200.);
89  fHistos->CreateTH2(Form("hENeutralConstituents%s", contname->String().Data()), "Neutral jet constituents; p_{t, jet} (GeV/c); E_{ne}", 200, 0., 200., 200., 0., 200.);
90  fHistos->CreateTH2(Form("hENeutralConstituentsNoSub%s", contname->String().Data()), "Neutral jet constituent without hadronic correction; p_{t, jet} (GeV/c); E_{ne}", 200, 0., 200., 200., 0., 200.);
91  fHistos->CreateTH2(Form("hZChargedConstituents%s", contname->String().Data()), "Charged jet constituents; p_{t, jet} (GeV/c); z", 200, 0., 200., 100., 0., 1.);
92  fHistos->CreateTH2(Form("hZNeutralConstituents%s", contname->String().Data()), "Neutral jet constituent without hadronic correction; p_{t, jet} (GeV/c); z", 200, 0., 200., 100., 0., 1.);
93  }
94 
95  for(auto h : *(fHistos->GetListOfHistograms())) fOutput->Add(h);
96  PostData(1, fOutput);
97 }
98 
100  auto tracks = GetTrackContainer(fNameTrackContainer);
101  const auto clusters = GetClusterContainer(fNameClusterContainer);
102  if(!(tracks && clusters)){
103  AliErrorStream() << "Either track or cluster container missing, aborting ..." << std::endl;
104  }
105 
106  // Event selection
107  AliDebugStream(1) << "Trigger selection string: " << fTriggerSelectionString << ", fired trigger classes: " << fInputEvent->GetFiredTriggerClasses() << std::endl;
108  if(fTriggerSelectionString.Contains("INT7")){
109  // INT7 trigger
110  if(!(fInputHandler->IsEventSelected() & AliVEvent::kINT7)) return false;
111  } else if(fTriggerSelectionString.Contains("EJ")){
112  auto triggerclass = fTriggerSelectionString(fTriggerSelectionString.Index("EJ"),3);
113  // EMCAL JET trigger
114  if(!(fInputHandler->IsEventSelected() & AliVEvent::kEMCEJE)) return false;
115  if(!fInputEvent->GetFiredTriggerClasses().Contains(triggerclass)) return false;
116  } else return false;
117 
118  AliDebugStream(1) << "Event is selected" << std::endl;
119 
120  for(auto jc : fNamesJetContainers){
121  auto contname = dynamic_cast<TObjString *>(jc);
122  if(!contname) {
123  AliErrorStream() << "Non-string object in the list of jet container names" << std::endl;
124  continue;
125  }
126  const auto jetcont = GetJetContainer(contname->String().Data());
127  if(!jetcont){
128  AliErrorStream() << "Jet container with name " << contname->String() << " not found in the list of jet containers" << std::endl;
129  continue;
130  }
131 
132  for(auto jet : jetcont->accepted()){
133  AliDebugStream(3) << "Next accepted jet, found " << jet->GetNumberOfTracks() << " tracks and " << jet->GetNumberOfClusters() << " clusters." << std::endl;
134  for(decltype(jet->GetNumberOfTracks()) itrk = 0; itrk < jet->GetNumberOfTracks(); itrk++){
135  const auto trk = jet->TrackAt(itrk, tracks->GetArray());
136  if(!trk) continue;
137  fHistos->FillTH2(Form("hPtChargedConstituents%s", contname->String().Data()), std::abs(jet->Pt()), std::abs(trk->Pt()));
138  fHistos->FillTH2(Form("hZChargedConstituents%s", contname->String().Data()), std::abs(jet->Pt()), jet->GetZ(trk));
139  }
140  for(decltype(jet->GetNumberOfClusters()) icl = 0; icl < jet->GetNumberOfClusters(); icl++){
141  const auto clust = jet->ClusterAt(icl, clusters->GetArray());
142  if(!clust) continue;
143  TLorentzVector ptvec;
144  clust->GetMomentum(ptvec, this->fVertex, AliVCluster::kHadCorr);
145  fHistos->FillTH2(Form("hPtNeutralConstituents%s", contname->String().Data()), std::abs(jet->Pt()), std::abs(ptvec.Pt()));
146  fHistos->FillTH2(Form("hENeutralConstituents%s", contname->String().Data()), std::abs(jet->Pt()), std::abs(clust->GetHadCorrEnergy()));
147  fHistos->FillTH2(Form("hENeutralConstituentsNoSub%s", contname->String().Data()), std::abs(jet->Pt()), std::abs(clust->GetNonLinCorrEnergy()));
148  fHistos->FillTH2(Form("hZNeutralConstituents%s", contname->String().Data()), std::abs(jet->Pt()), jet->GetZ(ptvec.Px(), ptvec.Py(), ptvec.Pz()));
149  }
150  }
151  }
152 
153  return kTRUE;
154 }
155 
157  using AnalysisHelpers = EMCalTriggerPtAnalysis::AliEmcalAnalysisFactory;
158  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
159  if(!mgr) {
160  std::cerr << "[AliAnalysisTaskJetConstituentQA::AddTaskEmcalJetConstituentQA(EE)] No analysis manager provided ..." << std::endl;
161  return nullptr;
162  }
163 
164  std::stringstream taskname;
165  taskname << "constituentQA_" << trigger;
166  auto task = new AliAnalysisTaskEmcalJetConstituentQA(taskname.str().data());
167  task->SetTriggerSelection(trigger);
168  mgr->AddTask(task);
169 
170  auto inputhandler = mgr->GetInputEventHandler();
171  auto isAOD = false;
172  if(inputhandler->IsA() == AliAODInputHandler::Class()) isAOD = true;
173 
174  auto tracksname = AnalysisHelpers::TrackContainerNameFactory(isAOD);
175  auto tracks = task->AddTrackContainer(tracksname);
176  task->SetNameTrackContainer(tracksname);
177  tracks->SetMinPt(0.15);
178 
179  auto clustername = AnalysisHelpers::ClusterContainerNameFactory(isAOD);
180  auto clusters = task->AddClusterContainer(clustername);
181  task->SetNameClusterContainer(clustername);
182  clusters->SetDefaultClusterEnergy(AliVCluster::kHadCorr);
183  clusters->SetClusHadCorrEnergyCut(0.3);
184 
185  // create jet containers for R02 and R04 jets
186  std::array<double, 2> jetradii = {{0.2, 0.4}};
187  for(auto r : jetradii) {
188  std::stringstream contname;
189  contname << "fulljets_R" << std::setw(2) << std::setfill('0') << int(r*10.);
190  auto jcont = task->AddJetContainer(AliJetContainer::kFullJet, AliJetContainer::antikt_algorithm, AliJetContainer::E_scheme, r, AliJetContainer::kEMCALfid, tracks, clusters, "Jet");
191  jcont->SetName(contname.str().data());
192  task->AddNameJetContainer(contname.str().data());
193  jcont->SetMinPt(20.);
194  }
195 
196  std::stringstream contname, outfilename;
197  contname << "JetConstituentQA_" << trigger;
198  outfilename << mgr->GetCommonFileName() << ":JetConstituentQA_" << trigger;
199  mgr->ConnectInput(task, 0, mgr->GetCommonInputContainer());
200  mgr->ConnectOutput(task, 1, mgr->CreateContainer(contname.str().data(), AliEmcalList::Class(), AliAnalysisManager::kOutputContainer, outfilename.str().data()));
201 
202  return task;
203 }
EMCal fiducial acceptance (each eta, phi edge narrowed by jet R)
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.
AliJetContainer * GetJetContainer(Int_t i=0) const
TObjArray fNamesJetContainers
Names of the connected jet container.
static AliAnalysisTaskEmcalJetConstituentQA * AddTaskEmcalJetConstituentQA(const char *trigger)
void SetUseAliAnaUtils(Bool_t b, Bool_t bRejPilup=kTRUE)
void FillTH2(const char *hname, double x, double y, double weight=1., Option_t *opt="")
Fill a 2D histogram within the container.
TCanvas * c
Definition: TestFitELoss.C:172
TH2 * CreateTH2(const char *name, const char *title, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax, Option_t *opt="")
Create a new TH2 within the container.
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
Collection of helper functions used to configure the analysis.
AliClusterContainer * GetClusterContainer(Int_t i=0) const
Get cluster container attached to this task.
AliEmcalList * fOutput
!output list
Double_t fVertex[3]
!event vertex
AliTrackContainer * GetTrackContainer(Int_t i=0) const
Base task in the EMCAL jet framework.
Container class for histograms.
Definition: THistManager.h:99
void UserCreateOutputObjects()
Main initialization function on the worker.