AliPhysics  d497afb (d497afb)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AliAnalysisTaskEmcalJetSubstructureTree.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 <iostream>
28 #include <string>
29 #include <set>
30 #include <sstream>
31 #include <vector>
32 
33 #include <fastjet/ClusterSequence.hh>
34 #include <fastjet/contrib/Nsubjettiness.hh>
35 #include <fastjet/contrib/SoftDrop.hh>
36 
37 #include <THistManager.h>
38 #include <TLinearBinning.h>
39 #include <TLorentzVector.h>
40 #include <TMath.h>
41 #include <TString.h>
42 #include <TVector3.h>
43 
44 #include "AliAODEvent.h"
45 #include "AliAODInputHandler.h"
46 #include "AliAnalysisManager.h"
48 #include "AliClusterContainer.h"
49 #include "AliJetContainer.h"
52 #include "AliEmcalJet.h"
53 #include "AliEmcalList.h"
55 #include "AliLog.h"
56 #include "AliParticleContainer.h"
57 #include "AliTrackContainer.h"
58 #include "AliRhoParameter.h"
59 #include "AliVCluster.h"
60 #include "AliVParticle.h"
61 
62 #ifdef EXPERIMENTAL_JETCONSTITUENTS
65 #endif
66 
67 
71 
72 namespace EmcalTriggerJets {
73 
76  fJetSubstructureTree(nullptr),
77  fQAHistos(nullptr),
78  fSDZCut(0.1),
79  fSDBetaCut(0),
80  fReclusterizer(kCAAlgo),
81  fTriggerSelectionBits(AliVEvent::kAny),
82  fTriggerSelectionString(""),
83  fUseDownscaleWeight(false)
84 {
85  memset(fJetTreeData, 0, sizeof(Double_t) * kTNVar);
86 }
87 
89  AliAnalysisTaskEmcalJet(name, kTRUE),
90  fJetSubstructureTree(nullptr),
91  fQAHistos(nullptr),
92  fSDZCut(0.1),
93  fSDBetaCut(0),
94  fReclusterizer(kCAAlgo),
95  fTriggerSelectionBits(AliVEvent::kAny),
96  fTriggerSelectionString(""),
97  fUseDownscaleWeight(false)
98 {
99  memset(fJetTreeData, 0, sizeof(Double_t) * kTNVar);
100  DefineOutput(2, TTree::Class());
101 }
102 
104 
105 }
106 
109 
110  // Make QA for constituent clusters
111  TLinearBinning jetptbinning(9, 20, 200),
112  clusterenergybinning(200, 0., 200),
113  timebinning(1000, -500., 500.),
114  m02binning(100, 0., 1.),
115  ncellbinning(101, -0.5, 100.5);
116  fQAHistos = new THistManager("QAhistos");
117  fQAHistos->CreateTH2("hClusterConstE", "EMCAL cluster energy vs jet pt; p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
118  fQAHistos->CreateTH2("hClusterConstTime", "EMCAL cluster time vs. jet pt; p_{t, jet} (GeV/c); t_{cl} (ns)", jetptbinning, timebinning);
119  fQAHistos->CreateTH2("hClusterConstM02", "EMCAL cluster M02 vs. jet pt; p{t, jet} (GeV/c); M02", jetptbinning, m02binning);
120  fQAHistos->CreateTH2("hClusterConstNcell", "EMCAL cluster ncell vs. jet pt; p{t, jet} (GeV/c); Number of cells", jetptbinning, ncellbinning);
121 
122  // Test of constituent QA
123 #ifdef EXPERIMENTAL_JETCONSTITUENTS
124  fQAHistos->CreateTH2("hChargedConstituentPt", "charged constituent pt vs jet pt (via constituent map); p_{t,jet} (GeV/c); p_{t,ch} (GeV/c)", jetptbinning, clusterenergybinning);
125  fQAHistos->CreateTH2("hChargedIndexPt", "charged constituent pt vs jet pt (via index map); p_{t, jet} (GeV/c); p_{t, ch} (GeV/c)", jetptbinning, clusterenergybinning);
126 
127  fQAHistos->CreateTH2("hClusterConstituentEDefault", "cluster constituent default energy vs. jet pt (va constituent map); p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
128  fQAHistos->CreateTH2("hClusterConstituentENLC", "cluster constituent non-linearity-corrected energy vs. jet pt (va constituent map); p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
129  fQAHistos->CreateTH2("hClusterConstituentEHC", "cluster constituent hadronic-corrected energy vs. jet pt (va constituent map); p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
130  fQAHistos->CreateTH2("hClusterIndexENLC", "cluster constituent non-linearity-corrected energy vs. jet pt (via index map); p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
131  fQAHistos->CreateTH2("hClusterIndexEHC", "cluster constituent hadronic-corrected energy vs. jet pt (via index map); p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
132 #endif
133  for(auto h : *(fQAHistos->GetListOfHistograms())) fOutput->Add(h);
134 
135  OpenFile(2);
136  fJetSubstructureTree = new TTree("jetSubstructure", "Tree with jet substructure information");
137  TString varnames[kTNVar];
138  varnames[0] = "Radius";
139  varnames[1] = "EventWeight";
140  varnames[2] = "PtJetRec";
141  varnames[3] = "PtJetSim";
142  varnames[4] = "EJetRec";
143  varnames[5] = "EJetSim";
144  varnames[6] = "RhoPtRec";
145  varnames[7] = "RhoPtSim";
146  varnames[8] = "RhoMassRec";
147  varnames[9] = "RhoMassSim";
148  varnames[10] = "AreaRec";
149  varnames[11] = "AreaSim";
150  varnames[12] = "NEFRec";
151  varnames[13] = "NEFSim";
152  varnames[14] = "MassRec";
153  varnames[15] = "MassSim";
154  varnames[16] = "ZgMeasured";
155  varnames[17] = "ZgTrue";
156  varnames[18] = "RgMeasured";
157  varnames[19] = "RgTrue";
158  varnames[20] = "MgMeasured";
159  varnames[21] = "MgTrue";
160  varnames[22] = "PtgMeasured";
161  varnames[23] = "PtgTrue";
162  varnames[24] = "MugMeasured";
163  varnames[25] = "MugTrue";
164  varnames[26] = "OneSubjettinessMeasured";
165  varnames[27] = "OneSubjettinessTrue";
166  varnames[28] = "TwoSubjettinessMeasured";
167  varnames[29] = "TwoSubjettinessTrue";
168  varnames[30] = "AngularityMeasured";
169  varnames[31] = "AngularityTrue";
170  varnames[32] = "PtDMeasured";
171  varnames[33] = "PtDTrue";
172  varnames[34] = "NCharged";
173  varnames[35] = "NNeutral";
174  varnames[36] = "NConstTrue";
175  varnames[37] = "NDroppedMeasured";
176  varnames[38] = "NDroppedTrue";
177 
178  for(int ib = 0; ib < kTNVar; ib++){
179  fJetSubstructureTree->Branch(varnames[ib], fJetTreeData + ib, Form("%s/D", varnames[ib].Data()));
180  }
181  PostData(1, fOutput);
182  PostData(2, fJetSubstructureTree);
183 }
184 
188  }
189 }
190 
194  AliParticleContainer *particles = GetParticleContainer("mcparticles");
195 
196  AliJetContainer *mcjets = GetJetContainer("mcjets");
197  AliJetContainer *datajets = GetJetContainer("datajets");
198 
199  // for(auto e : *(fInputEvent->GetList())) std::cout << e->GetName() << std::endl;
200 
201  TString rhoTagData = datajets ? TString::Format("R%02d", static_cast<Int_t>(datajets->GetJetRadius() * 10.)) : "",
202  rhoTagMC = mcjets ? TString::Format("R%02d", static_cast<Int_t>(mcjets->GetJetRadius() * 10.)) : "";
203 
204  AliRhoParameter *rhoPtRec = GetRhoFromEvent("RhoSparse_Full_" + rhoTagData),
205  *rhoMassRec = GetRhoFromEvent("RhoMassSparse_Full_" + rhoTagData),
206  *rhoPtSim = GetRhoFromEvent("RhoSparse_Full_" + rhoTagMC),
207  *rhoMassSim = GetRhoFromEvent("RhoMassSparse_Full_" + rhoTagMC);
208  AliDebugStream(2) << "Found rho parameter for reconstructed pt: " << (rhoPtRec ? "yes" : "no") << ", value: " << (rhoPtRec ? rhoPtRec->GetVal() : 0.) << std::endl;
209  AliDebugStream(2) << "Found rho parameter for sim pt: " << (rhoPtSim ? "yes" : "no") << ", value: " << (rhoPtSim ? rhoPtSim->GetVal() : 0.) << std::endl;
210  AliDebugStream(2) << "Found rho parameter for reconstructed Mass: " << (rhoMassRec ? "yes" : "no") << ", value: " << (rhoMassRec ? rhoMassRec->GetVal() : 0.) << std::endl;
211  AliDebugStream(2) << "Found rho parameter for sim Mass: " << (rhoMassSim ? "yes" : "no") << ", value: " << (rhoMassSim ? rhoMassSim->GetVal() : 0.) << std::endl;
212 
213  AliDebugStream(1) << "Inspecting jet radius " << (datajets ? datajets->GetJetRadius() : mcjets->GetJetRadius()) << std::endl;
214 
215  double weight = 1.;
218  }
219 
220  // Run trigger selection (not on pure MCgen train)
221  if(datajets){
222  if(!(fInputHandler->IsEventSelected() & fTriggerSelectionBits)) return false;
223  if(!mcjets){
224  // Pure data - do EMCAL trigger selection from selection string
225  if(fTriggerSelectionString.Length()) {
226  if(!fInputEvent->GetFiredTriggerClasses().Contains(fTriggerSelectionString)) return false;
227  }
228  } else {
229  // Simulation - do EMCAL trigger selection from trigger selection object
230  PWG::EMCAL::AliEmcalTriggerDecisionContainer *mctrigger = static_cast<PWG::EMCAL::AliEmcalTriggerDecisionContainer *>(fInputEvent->FindListObject("EmcalTriggerDecision"));
231  AliDebugStream(1) << "Found trigger decision object: " << (mctrigger ? "yes" : "no") << std::endl;
232  if(fTriggerSelectionString.Length()){
233  if(!mctrigger){
234  AliErrorStream() << "Trigger decision container not found in event - not possible to select EMCAL triggers" << std::endl;
235  return false;
236  }
237  if(!mctrigger->IsEventSelected(fTriggerSelectionString)) return false;
238  }
239  }
240  }
241 
242  Double_t rhoparameters[4]; memset(rhoparameters, 0, sizeof(Double_t) * 4);
243  if(rhoPtRec) rhoparameters[0] = rhoPtRec->GetVal();
244  if(rhoPtSim) rhoparameters[1] = rhoPtSim->GetVal();
245  if(rhoMassRec) rhoparameters[2] = rhoMassRec->GetVal();
246  if(rhoMassSim) rhoparameters[3] = rhoMassSim->GetVal();
247 
248  AliSoftdropDefinition softdropSettings;
249  softdropSettings.fBeta = fSDBetaCut;
250  softdropSettings.fZ = fSDZCut;
251  switch(fReclusterizer) {
252  case kCAAlgo: softdropSettings.fRecluserAlgo = fastjet::cambridge_aachen_algorithm; break;
253  case kKTAlgo: softdropSettings.fRecluserAlgo = fastjet::kt_algorithm; break;
254  case kAKTAlgo: softdropSettings.fRecluserAlgo = fastjet::antikt_algorithm; break;
255  };
256 
257  AliNSubjettinessDefinition nsubjettinessSettings;
258  nsubjettinessSettings.fBeta = 1.;
259  nsubjettinessSettings.fRadius = 0.4;
260 
261  std::set<AliEmcalJet *> taglist;
262  if(datajets) {
263  AliDebugStream(1) << "In data jets branch: found" << datajets->GetNJets() << " jets, " << datajets->GetNAcceptedJets() << " were accepted\n";
264  AliDebugStream(1) << "Having MC information: " << (mcjets ? TString::Format("yes, with %d jets", mcjets->GetNJets()) : "no") << std::endl;
265  for(auto jet : datajets->accepted()) {
266  double pt = jet->Pt(), pz = jet->Pz(), E = jet->E(), M = TMath::Sqrt(E*E - pt*pt - pz*pz);
267  AliDebugStream(2) << "Next jet: pt:" << jet->Pt() << ", E: " << E << ", pz: " << pz << ", M(self): " << M << "M(fj)" << jet->M() << std::endl;
268  AliEmcalJet *associatedJet = jet->ClosestJet();
269 
270  if(mcjets) {
271  if(!associatedJet) continue;
272  try {
273  DoConstituentQA(jet, tracks, clusters);
274  AliJetSubstructureData structureData = MakeJetSubstructure(*jet, datajets->GetJetRadius() * 2., tracks, clusters, {softdropSettings, nsubjettinessSettings}),
275  structureMC = MakeJetSubstructure(*associatedJet, mcjets->GetJetRadius() * 2, particles, nullptr, {softdropSettings, nsubjettinessSettings});
276  Double_t angularity[2] = {MakeAngularity(*jet, tracks, clusters), MakeAngularity(*associatedJet, particles, nullptr)},
277  ptd[2] = {MakePtD(*jet, tracks, clusters), MakePtD(*associatedJet, particles, nullptr)};
278  FillTree(datajets->GetJetRadius(), weight, jet, associatedJet, &(structureData.fSoftDrop), &(structureMC.fSoftDrop), &(structureData.fNsubjettiness), &(structureMC.fNsubjettiness), angularity, ptd, rhoparameters);
279  } catch(ReclusterizerException &e) {
280  AliErrorStream() << "Error in reclusterization - skipping jet" << std::endl;
281  } catch(SubstructureException &e) {
282  AliErrorStream() << "Error in substructure observable - skipping jet" << std::endl;
283  }
284  } else {
285  try {
286  DoConstituentQA(jet, tracks, clusters);
287  AliJetSubstructureData structure = MakeJetSubstructure(*jet, 0.4, tracks, clusters, {softdropSettings, nsubjettinessSettings});
288  Double_t angularity[2] = {MakeAngularity(*jet, tracks, clusters), 0.},
289  ptd[2] = {MakePtD(*jet, tracks, clusters), 0.};
290  FillTree(datajets->GetJetRadius(), weight, jet, nullptr, &(structure.fSoftDrop), nullptr, &(structure.fNsubjettiness), nullptr, angularity, ptd, rhoparameters);
291  } catch(ReclusterizerException &e) {
292  AliErrorStream() << "Error in reclusterization - skipping jet" << std::endl;
293  } catch(SubstructureException &e) {
294  AliErrorStream() << "Error in substructure observable - skipping jet" << std::endl;
295  }
296  }
297  }
298  } else {
299  if(mcjets) {
300  // for MCgen train
301  AliDebugStream(1) << "In MC pure jet branch: found " << mcjets->GetNJets() << " jets, " << mcjets->GetNAcceptedJets() << " were accepted\n";
302  for(auto j : mcjets->accepted()){
303  AliEmcalJet *mcjet = static_cast<AliEmcalJet *>(j);
304  try {
305  AliJetSubstructureData structure = MakeJetSubstructure(*mcjet, mcjets->GetJetRadius() * 2., particles, nullptr,{softdropSettings, nsubjettinessSettings});
306  Double_t angularity[2] = {0., MakeAngularity(*mcjet, particles, nullptr)},
307  ptd[2] = {0., MakePtD(*mcjet, particles, nullptr)};
308  FillTree(mcjets->GetJetRadius(), weight, nullptr, mcjet, nullptr, &(structure.fSoftDrop), nullptr, &(structure.fNsubjettiness), angularity, ptd, rhoparameters);
309  } catch (ReclusterizerException &e) {
310  AliErrorStream() << "Error in reclusterization - skipping jet" << std::endl;
311  } catch (SubstructureException &e) {
312  AliErrorStream() << "Error in substructure observable - skipping jet" << std::endl;
313  }
314  }
315  }
316  }
317 
318 
319  return true;
320 }
321 
323  const AliEmcalJet *datajet, const AliEmcalJet *mcjet,
324  AliSoftDropParameters *dataSoftdrop, AliSoftDropParameters *mcSoftdrop,
325  AliNSubjettinessParameters *dataSubjettiness, AliNSubjettinessParameters *mcSubjettiness,
326  Double_t *angularity, Double_t *ptd, Double_t *rhoparameters){
327  fJetTreeData[kTRadius] = r;
328  fJetTreeData[kTWeight] = weight;
329  fJetTreeData[kTRhoPtRec] = rhoparameters[0];
330  fJetTreeData[kTRhoPtSim] = rhoparameters[1];
331  fJetTreeData[kTRhoMassRec] = rhoparameters[2];
332  fJetTreeData[kTRhoMassSim] = rhoparameters[3];
333  if(datajet) {
334  fJetTreeData[kTPtJetRec] = TMath::Abs(datajet->Pt());
336  fJetTreeData[kTNNeutral] = datajet->GetNumberOfClusters();
337  fJetTreeData[kTAreaRec] = datajet->Area();
338  fJetTreeData[kTNEFRec] = datajet->NEF();
339  fJetTreeData[kTMassRec] = datajet->M();
340  fJetTreeData[kTEJetRec] = datajet->E();
341  } else {
342  fJetTreeData[kTPtJetRec] = 0.;
345  fJetTreeData[kTAreaRec] = 0.;
346  fJetTreeData[kTNEFRec] = 0.;
347  fJetTreeData[kTMassRec] = 0.;
348  fJetTreeData[kTEJetRec] = 0.;
349  }
350 
351  if(mcjet) {
352  fJetTreeData[kTPtJetSim] = TMath::Abs(mcjet->Pt());
354  fJetTreeData[kTAreaSim] = mcjet->Area();
355  fJetTreeData[kTNEFSim] = mcjet->NEF();
356  fJetTreeData[kTMassSim] = mcjet->M();
357  fJetTreeData[kTEJetSim] = mcjet->E();
358  } else {
359  fJetTreeData[kTPtJetSim] = 0.;
361  fJetTreeData[kTAreaSim] = 0.;
362  fJetTreeData[kTNEFSim] = 0.;
363  fJetTreeData[kTMassSim] = 0.;
364  fJetTreeData[kTEJetSim] = 0.;
365  }
366 
367  if(dataSoftdrop) {
368  fJetTreeData[kTZgMeasured] = dataSoftdrop->fZg;
369  fJetTreeData[kTRgMeasured] = dataSoftdrop->fRg;
370  fJetTreeData[kTMgMeasured] = dataSoftdrop->fMg;
371  fJetTreeData[kTPtgMeasured] = dataSoftdrop->fPtg;
372  fJetTreeData[kTMugMeasured] = dataSoftdrop->fMug;
373  fJetTreeData[kTNDroppedMeasured] = dataSoftdrop->fNDropped;
374  } else {
381  }
382 
383  if(mcSoftdrop) {
384  fJetTreeData[kTZgTrue] = mcSoftdrop->fZg;
385  fJetTreeData[kTRgTrue] = mcSoftdrop->fRg;
386  fJetTreeData[kTMgTrue] = mcSoftdrop->fMg;
387  fJetTreeData[kTPtgTrue] = mcSoftdrop->fPtg;
388  fJetTreeData[kTMugTrue] = mcSoftdrop->fMug;
389  fJetTreeData[kTNDroppedTrue] = mcSoftdrop->fNDropped;
390  } else {
391  fJetTreeData[kTZgTrue] = 0.;
392  fJetTreeData[kTRgTrue] = 0.;
393  fJetTreeData[kTMgTrue] = 0.;
394  fJetTreeData[kTPtgTrue] = 0.;
395  fJetTreeData[kTMugTrue] = 0.;
397  }
398 
399  if(dataSubjettiness) {
402  } else {
405  }
406 
407  if(mcSubjettiness) {
410  } else {
413  }
414 
415  fJetTreeData[kTAngularityMeasured] = angularity[0];
416  fJetTreeData[kTAngularityTrue] = angularity[1];
417  fJetTreeData[kTPtDMeasured] = ptd[0];
418  fJetTreeData[kTPtDTrue] = ptd[1];
419 
420  fJetSubstructureTree->Fill();
421 }
422 
423 
425  const int kClusterOffset = 30000; // In order to handle tracks and clusters in the same index space the cluster index needs and offset, large enough so that there is no overlap with track indices
426  std::vector<fastjet::PseudoJet> constituents;
427  bool isMC = dynamic_cast<const AliTrackContainer *>(tracks);
428  AliDebugStream(2) << "Make new jet substrucutre for " << (isMC ? "MC" : "data") << " jet: Number of tracks " << jet.GetNumberOfTracks() << ", clusters " << jet.GetNumberOfClusters() << std::endl;
429  for(int itrk = 0; itrk < jet.GetNumberOfTracks(); itrk++){
430  AliVTrack *track = static_cast<AliVTrack *>(jet.TrackAt(itrk, tracks->GetArray()));
431  fastjet::PseudoJet constituentTrack(track->Px(), track->Py(), track->Pz(), track->E());
432  constituentTrack.set_user_index(jet.TrackAt(itrk));
433  constituents.push_back(constituentTrack);
434  }
435 
436  if(clusters){
437  for(int icl = 0; icl < jet.GetNumberOfClusters(); icl++) {
438  AliVCluster *cluster = jet.ClusterAt(icl, clusters->GetArray());
439  TLorentzVector clustervec;
440  cluster->GetMomentum(clustervec, fVertex, (AliVCluster::VCluUserDefEnergy_t)clusters->GetDefaultClusterEnergy());
441  fastjet::PseudoJet constituentCluster(clustervec.Px(), clustervec.Py(), clustervec.Pz(), cluster->GetHadCorrEnergy());
442  constituentCluster.set_user_index(jet.ClusterAt(icl) + kClusterOffset);
443  constituents.push_back(constituentCluster);
444  }
445  }
446 
447  AliDebugStream(3) << "Found " << constituents.size() << " constituents for jet with pt=" << jet.Pt() << " GeV/c" << std::endl;
448  if(!constituents.size())
449  throw ReclusterizerException();
450  // Redo jet finding on constituents with a
451  fastjet::JetDefinition jetdef(fastjet::antikt_algorithm, jetradius*2, static_cast<fastjet::RecombinationScheme>(0), fastjet::BestFJ30 );
452  std::vector<fastjet::PseudoJet> outputjets;
453  try {
454  fastjet::ClusterSequence jetfinder(constituents, jetdef);
455  outputjets = jetfinder.inclusive_jets(0);
456  AliJetSubstructureData result({MakeSoftDropParameters(outputjets[0], settings.fSoftdropSettings), MakeNsubjettinessParameters(outputjets[0], settings.fSubjettinessSettings)});
457  return result;
458  } catch (fastjet::Error &e) {
459  AliErrorStream() << " FJ Exception caught: " << e.message() << std::endl;
460  throw ReclusterizerException();
461  }
462 }
463 
465  fastjet::contrib::SoftDrop softdropAlgorithm(cutparameters.fBeta, cutparameters.fZ);
466  softdropAlgorithm.set_verbose_structure(kTRUE);
467  std::unique_ptr<fastjet::contrib::Recluster> reclusterizer(new fastjet::contrib::Recluster(cutparameters.fRecluserAlgo, 1, true));
468  softdropAlgorithm.set_reclustering(kTRUE, reclusterizer.get());
469  AliDebugStream(4) << "Jet has " << jet.constituents().size() << " constituents" << std::endl;
470  fastjet::PseudoJet groomed = softdropAlgorithm(jet);
471 
472  AliSoftDropParameters result({groomed.structure_of<fastjet::contrib::SoftDrop>().symmetry(),
473  groomed.m(),
474  groomed.structure_of<fastjet::contrib::SoftDrop>().delta_R(),
475  groomed.perp(),
476  groomed.structure_of<fastjet::contrib::SoftDrop>().mu(),
477  groomed.structure_of<fastjet::contrib::SoftDrop>().dropped_count()});
478  return result;
479 }
480 
483  fastjet::contrib::Nsubjettiness (1,fastjet::contrib::KT_Axes(),fastjet::contrib::NormalizedCutoffMeasure(cut.fBeta, cut.fRadius, 1e100)).result(jet),
484  fastjet::contrib::Nsubjettiness (2,fastjet::contrib::KT_Axes(),fastjet::contrib::NormalizedCutoffMeasure(cut.fBeta, cut.fRadius, 1e100)).result(jet)
485  });
486  return result;
487 }
488 
490  if(!(jet.GetNumberOfTracks() || jet.GetNumberOfClusters()))
491  throw SubstructureException();
492  TVector3 jetvec(jet.Px(), jet.Py(), jet.Pz());
493  Double_t den(0.), num(0.);
494  if(tracks){
495  for(UInt_t itrk = 0; itrk < jet.GetNumberOfTracks(); itrk++) {
496  AliVParticle *track = jet.TrackAt(itrk, tracks->GetArray());
497  if(!track){
498  AliErrorStream() << "Associated constituent particle / track not found\n";
499  continue;
500  }
501  TVector3 trackvec(track->Px(), track->Py(), track->Pz());
502 
503  num += track->Pt() * trackvec.DrEtaPhi(jetvec);
504  den += +track->Pt();
505  }
506  }
507  if(clusters) {
508  for(UInt_t icl = 0; icl < jet.GetNumberOfClusters(); icl++){
509  AliVCluster *clust = jet.ClusterAt(icl, clusters->GetArray());
510  if(!clust) {
511  AliErrorStream() << "Associated constituent cluster not found\n";
512  continue;
513  }
514  TLorentzVector clusterp;
515  clust->GetMomentum(clusterp, fVertex, (AliVCluster::VCluUserDefEnergy_t)clusters->GetDefaultClusterEnergy());
516 
517  num += clusterp.Pt() * clusterp.Vect().DrEtaPhi(jetvec);
518  den += clusterp.Pt();
519  }
520  }
521  return num/den;
522 }
523 
525  if (!(jet.GetNumberOfTracks() || jet.GetNumberOfClusters()))
526  throw SubstructureException();
527  Double_t den(0.), num(0.);
528  if(particles){
529  for(UInt_t itrk = 0; itrk < jet.GetNumberOfTracks(); itrk++) {
530  AliVParticle *trk = jet.TrackAt(itrk, particles->GetArray());
531  if(!trk){
532  AliErrorStream() << "Associated constituent particle / track not found\n";
533  continue;
534  }
535  num += trk->Pt() * trk->Pt();
536  den += trk->Pt();
537  }
538  }
539  if(clusters){
540  for(UInt_t icl = 0; icl < jet.GetNumberOfClusters(); icl++){
541  AliVCluster *clust = jet.ClusterAt(icl, clusters->GetArray());
542  if(!clust) {
543  AliErrorStream() << "Associated constituent cluster not found\n";
544  continue;
545  }
546  TLorentzVector clusterp;
547  clust->GetMomentum(clusterp, fVertex, (AliVCluster::VCluUserDefEnergy_t)clusters->GetDefaultClusterEnergy());
548  num += clusterp.Pt() * clusterp.Pt();
549  den += clusterp.Pt();
550  }
551  }
552  return TMath::Sqrt(num)/den;
553 }
554 
556  for(int icl = 0; icl < jet->GetNumberOfClusters(); icl++){
557  AliVCluster *clust = jet->ClusterAt(icl, clusters->GetArray());
558  AliDebugStream(3) << "cluster time " << clust->GetTOF() << std::endl;
559  fQAHistos->FillTH2("hClusterConstE", jet->Pt(),clust->GetUserDefEnergy(clusters->GetDefaultClusterEnergy()));
560  fQAHistos->FillTH2("hClusterConstTime", jet->Pt(), clust->GetTOF());
561  fQAHistos->FillTH2("hClusterConstM02", jet->Pt(), clust->GetM02());
562  fQAHistos->FillTH2("hClusterConstNcell", jet->Pt(), clust->GetNCells());
563 
564 #ifdef EXPERIMENTAL_JETCONSTITUENTS
565  fQAHistos->FillTH2("hClusterIndexENLC", jet->Pt(), clust->GetNonLinCorrEnergy());
566  fQAHistos->FillTH2("hClusterIndexEHC", jet->Pt(), clust->GetHadCorrEnergy());
567 #endif
568  }
569 
570 #ifdef EXPERIMENTAL_JETCONSTITUENTS
571  // Loop over charged particles - fill test histogram
572  for(int itrk = 0; itrk < jet->GetNumberOfTracks(); itrk++){
573  AliVParticle *part = jet->TrackAt(itrk, cont->GetArray());
574  fQAHistos->FillTH2("hChargedIndexPt", jet->Pt(), part->Pt());
575  }
576 
577  // Look over charged constituents
578  AliDebugStream(2) << "Jet: Number of particle constituents: " << jet->GetParticleConstituents().GetEntriesFast() << std::endl;
579  for(auto pconst : jet->GetParticleConstituents()) {
581  AliDebugStream(3) << "Found particle constituent with pt " << part->Pt() << ", from VParticle " << part->GetParticle()->Pt() << std::endl;
582  fQAHistos->FillTH2("hChargedConstituentPt", jet->Pt(), part->Pt());
583  }
584 
585  // Loop over neutral constituents
586  AliDebugStream(2) << "Jet: Number of cluster constituents: " << jet->GetClusterConstituents().GetEntriesFast() << std::endl;
587  for(auto cconst : jet->GetClusterConstituents()){
589  AliDebugStream(3) << "Found cluster constituent with energy " << clust->E() << " using energy definition " << static_cast<int>(clust->GetDefaultEnergyType()) << std::endl;
590  fQAHistos->FillTH2("hClusterConstituentEDefault", jet->Pt(), clust->E());
591  fQAHistos->FillTH2("hClusterConstituentENLC", jet->Pt(), clust->GetCluster()->GetNonLinCorrEnergy());
592  fQAHistos->FillTH2("hClusterConstituentEHC", jet->Pt(), clust->GetCluster()->GetHadCorrEnergy());
593  }
594 #endif
595 }
596 
598  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
599 
600  Bool_t isAOD(kFALSE);
601  AliInputEventHandler *inputhandler = static_cast<AliInputEventHandler *>(mgr->GetInputEventHandler());
602  if(inputhandler) {
603  if(inputhandler->IsA() == AliAODInputHandler::Class()){
604  std::cout << "Analysing AOD events\n";
605  isAOD = kTRUE;
606  } else {
607  std::cout << "Analysing ESD events\n";
608  }
609  }
610 
611  AliAnalysisTaskEmcalJetSubstructureTree *treemaker = new AliAnalysisTaskEmcalJetSubstructureTree("JetSubstructureTreemaker_" + TString::Format("R%02d_", int(jetradius * 10.)) + trigger);
612  mgr->AddTask(treemaker);
613  treemaker->SetMakeGeneralHistograms(kTRUE);
614 
615  // Adding containers
616  if(isMC) {
617  AliParticleContainer *particles = treemaker->AddMCParticleContainer("mcparticles");
618  particles->SetMinPt(0.);
619 
620  AliJetContainer *mcjets = treemaker->AddJetContainer(
623  recombinationScheme,
624  jetradius,
625  (isData && jettype == kFull) ? AliEmcalJet::kEMCALfid : AliEmcalJet::kTPC,
626  particles, nullptr);
627  mcjets->SetName("mcjets");
628  mcjets->SetJetPtCut(20.);
629  }
630 
631  if(isData) {
633  std::cout << "Track container name: " << tracks->GetName() << std::endl;
634  tracks->SetMinPt(0.15);
635  AliClusterContainer *clusters(nullptr);
636  if(jettype == kFull){
637  std::cout << "Using full jets ..." << std::endl;
639  std::cout << "Cluster container name: " << clusters->GetName() << std::endl;
640  clusters->SetClusHadCorrEnergyCut(0.3); // 300 MeV E-cut
641  clusters->SetDefaultClusterEnergy(AliVCluster::kHadCorr);
642  } else {
643  std::cout << "Using charged jets ... " << std::endl;
644  }
645 
646  AliJetContainer *datajets = treemaker->AddJetContainer(
649  recombinationScheme,
650  jetradius,
652  tracks, clusters);
653  datajets->SetName("datajets");
654  datajets->SetJetPtCut(20.);
655 
656  treemaker->SetUseAliAnaUtils(true, true);
657  treemaker->SetVzRange(-10., 10);
658 
659  // configure trigger selection
660  TString triggerstring(trigger);
661  if(triggerstring.Contains("INT7")) {
662  treemaker->SetTriggerBits(AliVEvent::kINT7);
663  } else if(triggerstring.Contains("EJ1")) {
664  treemaker->SetTriggerBits(AliVEvent::kEMCEJE);
665  treemaker->SetTriggerString("EJ1");
666  } else if(triggerstring.Contains("EJ2")) {
667  treemaker->SetTriggerBits(AliVEvent::kEMCEJE);
668  treemaker->SetTriggerString("EJ2");
669  }
670  }
671 
672  // Connecting containers
673  TString outputfile = mgr->GetCommonFileName();
674  outputfile += TString::Format(":JetSubstructure_R%02d_%s", int(jetradius * 10.), trigger);
675  mgr->ConnectInput(treemaker, 0, mgr->GetCommonInputContainer());
676  mgr->ConnectOutput(treemaker, 1, mgr->CreateContainer("JetSubstructureHistos_" + TString::Format("R%0d_", int(jetradius * 10.)) + trigger, AliEmcalList::Class(), AliAnalysisManager::kOutputContainer, outputfile));
677  mgr->ConnectOutput(treemaker, 2, mgr->CreateContainer("JetSubstuctureTree_" + TString::Format("R%0d_", int(jetradius * 10.)) + trigger, TTree::Class(), AliAnalysisManager::kOutputContainer, Form("JetSubstructureTree_R%02d_%s.root", static_cast<int>(jetradius*10.), trigger)));
678 
679  return treemaker;
680 }
681 
682 } /* namespace EmcalTriggerJets */
Double_t Area() const
Definition: AliEmcalJet.h:130
bool IsEventSelected(const char *name) const
Checks whether the events is selected for a given trigger type.
double Double_t
Definition: External.C:58
Class creating a linear binning, used in the histogram manager.
Double_t MakePtD(const AliEmcalJet &jet, const AliParticleContainer *const particles, const AliClusterContainer *const clusters) const
AliEmcalJet * ClosestJet() const
Definition: AliEmcalJet.h:327
AliJetContainer * GetJetContainer(Int_t i=0) const
virtual double E() const
Access to constituent energy.
static AliEmcalDownscaleFactorsOCDB * Instance()
Double_t Py() const
Definition: AliEmcalJet.h:107
Container with name, TClonesArray and cuts for particles.
void SetUseAliAnaUtils(Bool_t b, Bool_t bRejPilup=kTRUE)
AliJetSubstructureData MakeJetSubstructure(const AliEmcalJet &jet, double jetradius, const AliParticleContainer *tracks, const AliClusterContainer *clusters, const AliJetSubstructureSettings &settings) const
void FillTH2(const char *hname, double x, double y, double weight=1., Option_t *opt="")
Fill a 2D histogram within the container.
Int_t ClusterAt(Int_t idx) const
Definition: AliEmcalJet.h:137
AliJetContainer * AddJetContainer(const char *n, TString defaultCutType, Float_t jetRadius=0.4)
const std::vector< PWG::JETFW::AliEmcalParticleJetConstituent > & GetParticleConstituents() const
Get container with particle (track / MC particle) constituents.
Definition: AliEmcalJet.h:184
Structure for results from the soft drop algorithm.
Double_t E() const
Definition: AliEmcalJet.h:119
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.
Double_t GetDownscaleFactorForTriggerClass(const TString &trigger) const
void SetVzRange(Double_t min, Double_t max)
AliVCluster::VCluUserDefEnergy_t GetDefaultEnergyType() const
Get the energy definition used to calculate the cluster energy in the jetfinder.
AliClusterContainer * AddClusterContainer(const char *n)
Create new cluster container and attach it to the task.
fastjet::JetAlgorithm fRecluserAlgo
Reclusterization algorithm.
UShort_t GetNumberOfConstituents() const
Definition: AliEmcalJet.h:140
Container for particles within the EMCAL framework.
Int_t GetDefaultClusterEnergy() const
Int_t TrackAt(Int_t idx) const
Definition: AliEmcalJet.h:160
UShort_t GetNumberOfTracks() const
Definition: AliEmcalJet.h:139
Double_t Px() const
Definition: AliEmcalJet.h:106
AliParticleContainer * GetParticleContainer(Int_t i=0) const
Get particle container attached to this task.
static AliAnalysisTaskEmcalJetSubstructureTree * AddEmcalJetSubstructureTreeMaker(Bool_t isMC, Bool_t isData, Double_t jetradius, JetType_t jettype, AliJetContainer::ERecoScheme_t recombinationScheme, const char *name)
TPC fiducial acceptance (each eta edge narrowed by jet R)
Definition: AliEmcalJet.h:68
AliRhoParameter * GetRhoFromEvent(const char *name)
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.
int Int_t
Definition: External.C:63
UShort_t GetNumberOfClusters() const
Definition: AliEmcalJet.h:138
void SetJetPtCut(Float_t cut)
TPC acceptance.
Definition: AliEmcalJet.h:67
unsigned int UInt_t
Definition: External.C:33
THashList * GetListOfHistograms() const
Get the list of histograms.
Definition: THistManager.h:671
Int_t GetNJets() const
AliNSubjettinessParameters MakeNsubjettinessParameters(const fastjet::PseudoJet &jet, const AliNSubjettinessDefinition &cut) const
Definition for the algorithm obtaining the softdrop parameters.
AliClusterContainer * GetClusterContainer(Int_t i=0) const
Get cluster container attached to this task.
const AliVCluster * GetCluster() const
Get the underlying cluster.
virtual void RunChanged(Int_t newrun)
Process tasks relevant when a file with a different run number is processed.
AliMCParticleContainer * AddMCParticleContainer(const char *n)
Create new container for MC particles and attach it to the task.
Double_t MakeAngularity(const AliEmcalJet &jet, const AliParticleContainer *tracks, const AliClusterContainer *clusters) const
Implementation of a jet constituent for constituent clusters.
Bool_t Data(TH1F *h, Double_t *rangefit, Bool_t writefit, Double_t &sgn, Double_t &errsgn, Double_t &bkg, Double_t &errbkg, Double_t &sgnf, Double_t &errsgnf, Double_t &sigmafit, Int_t &status)
Double_t Pt() const
Definition: AliEmcalJet.h:109
Bool_t isMC
void DoConstituentQA(const AliEmcalJet *jet, const AliParticleContainer *tracks, const AliClusterContainer *clusters)
Float_t GetJetRadius() const
const std::vector< PWG::JETFW::AliEmcalClusterJetConstituent > & GetClusterConstituents() const
Get container with cluster constituents.
Definition: AliEmcalJet.h:190
virtual double Pt() const
Access to transverse momentum.
AliEmcalList * fOutput
!output list
Double_t fVertex[3]
!event vertex
AliTrackContainer * AddTrackContainer(const char *n)
Create new track container and attach it to the task.
AliTrackContainer * GetTrackContainer(Int_t i=0) const
void SetMakeGeneralHistograms(Bool_t g)
Base task in the EMCAL jet framework.
void FillTree(double r, double weight, const AliEmcalJet *datajet, const AliEmcalJet *mcjet, AliSoftDropParameters *dataSoftdrop, AliSoftDropParameters *mcsoftdrop, AliNSubjettinessParameters *dataSubjettiness, AliNSubjettinessParameters *mcSubjettiness, Double_t *angularity, Double_t *ptd, Double_t *rhoparameters)
Represent a jet reconstructed using the EMCal jet framework.
Definition: AliEmcalJet.h:51
Container class for histograms.
Definition: THistManager.h:99
Double_t Pz() const
Definition: AliEmcalJet.h:108
AliSoftDropParameters MakeSoftDropParameters(const fastjet::PseudoJet &jet, const AliSoftdropDefinition &cut) const
void UserCreateOutputObjects()
Main initialization function on the worker.
const AliJetIterableContainer accepted() const
bool Bool_t
Definition: External.C:53
Double_t NEF() const
Definition: AliEmcalJet.h:148
void SetDefaultClusterEnergy(Int_t d)
Container structure for EMCAL clusters.
Double_t M() const
Definition: AliEmcalJet.h:120
EMCal fiducial acceptance (each eta, phi edge narrowed by jet R)
Definition: AliEmcalJet.h:70
Container for jet within the EMCAL jet framework.
TList * OpenFile(const char *fname)
Definition: DrawAnaELoss.C:65
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.