AliPhysics  58f3d52 (58f3d52)
 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"
47 #include "AliAnalysisDataSlot.h"
48 #include "AliAnalysisDataContainer.h"
50 #include "AliClusterContainer.h"
51 #include "AliJetContainer.h"
54 #include "AliEmcalJet.h"
55 #include "AliEmcalList.h"
57 #include "AliLog.h"
58 #include "AliParticleContainer.h"
59 #include "AliTrackContainer.h"
60 #include "AliRhoParameter.h"
61 #include "AliVCluster.h"
62 #include "AliVParticle.h"
63 
64 #ifdef EXPERIMENTAL_JETCONSTITUENTS
67 #endif
68 
69 
73 
74 namespace EmcalTriggerJets {
75 
78  fJetSubstructureTree(nullptr),
79  fQAHistos(nullptr),
80  fSDZCut(0.1),
81  fSDBetaCut(0),
82  fReclusterizer(kCAAlgo),
83  fTriggerSelectionBits(AliVEvent::kAny),
84  fTriggerSelectionString(""),
85  fUseDownscaleWeight(false),
86  fFillPart(true),
87  fFillAcceptance(true),
88  fFillRho(true),
89  fFillMass(true),
90  fFillSoftDrop(true),
91  fFillNSub(true),
92  fFillStructGlob(true)
93 {
94  memset(fJetTreeData, 0, sizeof(Double_t) * kTNVar);
95 }
96 
98  AliAnalysisTaskEmcalJet(name, kTRUE),
99  fJetSubstructureTree(nullptr),
100  fQAHistos(nullptr),
101  fSDZCut(0.1),
102  fSDBetaCut(0),
103  fReclusterizer(kCAAlgo),
104  fTriggerSelectionBits(AliVEvent::kAny),
105  fTriggerSelectionString(""),
106  fUseDownscaleWeight(false),
107  fFillPart(true),
108  fFillAcceptance(true),
109  fFillRho(true),
110  fFillMass(true),
111  fFillSoftDrop(true),
112  fFillNSub(true),
113  fFillStructGlob(true)
114 {
115  memset(fJetTreeData, 0, sizeof(Double_t) * kTNVar);
116  DefineOutput(2, TTree::Class());
117 }
118 
120 
121 }
122 
125 
126  // Make QA for constituent clusters
127  TLinearBinning jetptbinning(9, 20, 200),
128  clusterenergybinning(200, 0., 200),
129  timebinning(1000, -500., 500.),
130  m02binning(100, 0., 1.),
131  ncellbinning(101, -0.5, 100.5);
132  fQAHistos = new THistManager("QAhistos");
133  fQAHistos->CreateTH2("hClusterConstE", "EMCAL cluster energy vs jet pt; p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
134  fQAHistos->CreateTH2("hClusterConstTime", "EMCAL cluster time vs. jet pt; p_{t, jet} (GeV/c); t_{cl} (ns)", jetptbinning, timebinning);
135  fQAHistos->CreateTH2("hClusterConstM02", "EMCAL cluster M02 vs. jet pt; p{t, jet} (GeV/c); M02", jetptbinning, m02binning);
136  fQAHistos->CreateTH2("hClusterConstNcell", "EMCAL cluster ncell vs. jet pt; p{t, jet} (GeV/c); Number of cells", jetptbinning, ncellbinning);
137 
138  // Test of constituent QA
139 #ifdef EXPERIMENTAL_JETCONSTITUENTS
140  fQAHistos->CreateTH2("hChargedConstituentPt", "charged constituent pt vs jet pt (via constituent map); p_{t,jet} (GeV/c); p_{t,ch} (GeV/c)", jetptbinning, clusterenergybinning);
141  fQAHistos->CreateTH2("hChargedIndexPt", "charged constituent pt vs jet pt (via index map); p_{t, jet} (GeV/c); p_{t, ch} (GeV/c)", jetptbinning, clusterenergybinning);
142 
143  fQAHistos->CreateTH2("hClusterConstituentEDefault", "cluster constituent default energy vs. jet pt (va constituent map); p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
144  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);
145  fQAHistos->CreateTH2("hClusterConstituentEHC", "cluster constituent hadronic-corrected energy vs. jet pt (va constituent map); p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
146  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);
147  fQAHistos->CreateTH2("hClusterIndexEHC", "cluster constituent hadronic-corrected energy vs. jet pt (via index map); p_{t, jet} (GeV/c); E_{cl} (GeV)", jetptbinning, clusterenergybinning);
148 #endif
149  for(auto h : *(fQAHistos->GetListOfHistograms())) fOutput->Add(h);
150 
151  OpenFile(2);
152  TString treename = this->GetOutputSlot(2)->GetContainer()->GetName();
153  fJetSubstructureTree = new TTree(treename, "Tree with jet substructure information");
154  TString varnames[kTNVar];
155  varnames[0] = "Radius";
156  varnames[1] = "EventWeight";
157  varnames[2] = "PtJetRec";
158  varnames[3] = "PtJetSim";
159  varnames[4] = "EJetRec";
160  varnames[5] = "EJetSim";
161  varnames[6] = "EtaRec";
162  varnames[7] = "EtaSim";
163  varnames[8] = "PhiRec";
164  varnames[9] = "PhiSim";
165  varnames[10] = "RhoPtRec";
166  varnames[11] = "RhoPtSim";
167  varnames[12] = "RhoMassRec";
168  varnames[13] = "RhoMassSim";
169  varnames[14] = "AreaRec";
170  varnames[15] = "AreaSim";
171  varnames[16] = "NEFRec";
172  varnames[17] = "NEFSim";
173  varnames[18] = "MassRec";
174  varnames[19] = "MassSim";
175  varnames[20] = "ZgMeasured";
176  varnames[21] = "ZgTrue";
177  varnames[22] = "RgMeasured";
178  varnames[23] = "RgTrue";
179  varnames[24] = "MgMeasured";
180  varnames[25] = "MgTrue";
181  varnames[26] = "PtgMeasured";
182  varnames[27] = "PtgTrue";
183  varnames[28] = "MugMeasured";
184  varnames[29] = "MugTrue";
185  varnames[30] = "OneSubjettinessMeasured";
186  varnames[31] = "OneSubjettinessTrue";
187  varnames[32] = "TwoSubjettinessMeasured";
188  varnames[33] = "TwoSubjettinessTrue";
189  varnames[34] = "AngularityMeasured";
190  varnames[35] = "AngularityTrue";
191  varnames[36] = "PtDMeasured";
192  varnames[37] = "PtDTrue";
193  varnames[38] = "NCharged";
194  varnames[39] = "NNeutral";
195  varnames[40] = "NConstTrue";
196  varnames[41] = "NDroppedMeasured";
197  varnames[42] = "NDroppedTrue";
198 
199  for(int ib = 0; ib < kTNVar; ib++){
200  LinkOutputBranch(varnames[ib], fJetTreeData + ib);
201  }
202  PostData(1, fOutput);
203  PostData(2, fJetSubstructureTree);
204 }
205 
207  // Check whether branch is rejected
208  if(!fFillPart && IsPartBranch(branchname)) return;
209  if(!fFillAcceptance && IsAcceptanceBranch(branchname)) return;
210  if(!fFillRho && IsRhoBranch(branchname)) return;
211  if(!fFillMass && IsMassBranch(branchname)) return;
212  if(!fFillSoftDrop && IsSoftdropBranch(branchname)) return;
213  if(!fFillNSub && IsNSubjettinessBranch(branchname)) return;
214  if(!fFillStructGlob && IsStructbranch(branchname)) return;
215 
216  std::cout << "Adding branch " << branchname << std::endl;
217  fJetSubstructureTree->Branch(branchname, datalocation, Form("%s/D", branchname.Data()));
218 }
219 
223  }
224 }
225 
229  AliParticleContainer *particles = GetParticleContainer("mcparticles");
230 
231  AliJetContainer *mcjets = GetJetContainer("mcjets");
232  AliJetContainer *datajets = GetJetContainer("datajets");
233 
234  // for(auto e : *(fInputEvent->GetList())) std::cout << e->GetName() << std::endl;
235 
236  TString rhoTagData = datajets ? TString::Format("R%02d", static_cast<Int_t>(datajets->GetJetRadius() * 10.)) : "",
237  rhoTagMC = mcjets ? TString::Format("R%02d", static_cast<Int_t>(mcjets->GetJetRadius() * 10.)) : "";
238 
239  AliRhoParameter *rhoPtRec = GetRhoFromEvent("RhoSparse_Full_" + rhoTagData),
240  *rhoMassRec = GetRhoFromEvent("RhoMassSparse_Full_" + rhoTagData),
241  *rhoPtSim = GetRhoFromEvent("RhoSparse_Full_" + rhoTagMC),
242  *rhoMassSim = GetRhoFromEvent("RhoMassSparse_Full_" + rhoTagMC);
243  AliDebugStream(2) << "Found rho parameter for reconstructed pt: " << (rhoPtRec ? "yes" : "no") << ", value: " << (rhoPtRec ? rhoPtRec->GetVal() : 0.) << std::endl;
244  AliDebugStream(2) << "Found rho parameter for sim pt: " << (rhoPtSim ? "yes" : "no") << ", value: " << (rhoPtSim ? rhoPtSim->GetVal() : 0.) << std::endl;
245  AliDebugStream(2) << "Found rho parameter for reconstructed Mass: " << (rhoMassRec ? "yes" : "no") << ", value: " << (rhoMassRec ? rhoMassRec->GetVal() : 0.) << std::endl;
246  AliDebugStream(2) << "Found rho parameter for sim Mass: " << (rhoMassSim ? "yes" : "no") << ", value: " << (rhoMassSim ? rhoMassSim->GetVal() : 0.) << std::endl;
247 
248  AliDebugStream(1) << "Inspecting jet radius " << (datajets ? datajets->GetJetRadius() : mcjets->GetJetRadius()) << std::endl;
249 
250  double weight = 1.;
253  }
254 
255  // Run trigger selection (not on pure MCgen train)
256  if(datajets){
257  if(!(fInputHandler->IsEventSelected() & fTriggerSelectionBits)) return false;
258  if(!mcjets){
259  // Pure data - do EMCAL trigger selection from selection string
260  if(fTriggerSelectionString.Length()) {
261  if(!fInputEvent->GetFiredTriggerClasses().Contains(fTriggerSelectionString)) return false;
262  }
263  } else {
264  // Simulation - do EMCAL trigger selection from trigger selection object
265  PWG::EMCAL::AliEmcalTriggerDecisionContainer *mctrigger = static_cast<PWG::EMCAL::AliEmcalTriggerDecisionContainer *>(fInputEvent->FindListObject("EmcalTriggerDecision"));
266  AliDebugStream(1) << "Found trigger decision object: " << (mctrigger ? "yes" : "no") << std::endl;
267  if(fTriggerSelectionString.Length()){
268  if(!mctrigger){
269  AliErrorStream() << "Trigger decision container not found in event - not possible to select EMCAL triggers" << std::endl;
270  return false;
271  }
272  if(!mctrigger->IsEventSelected(fTriggerSelectionString)) return false;
273  }
274  }
275  }
276 
277  Double_t rhoparameters[4]; memset(rhoparameters, 0, sizeof(Double_t) * 4);
278  if(rhoPtRec) rhoparameters[0] = rhoPtRec->GetVal();
279  if(rhoPtSim) rhoparameters[1] = rhoPtSim->GetVal();
280  if(rhoMassRec) rhoparameters[2] = rhoMassRec->GetVal();
281  if(rhoMassSim) rhoparameters[3] = rhoMassSim->GetVal();
282 
283  AliSoftdropDefinition softdropSettings;
284  softdropSettings.fBeta = fSDBetaCut;
285  softdropSettings.fZ = fSDZCut;
286  switch(fReclusterizer) {
287  case kCAAlgo: softdropSettings.fRecluserAlgo = fastjet::cambridge_aachen_algorithm; break;
288  case kKTAlgo: softdropSettings.fRecluserAlgo = fastjet::kt_algorithm; break;
289  case kAKTAlgo: softdropSettings.fRecluserAlgo = fastjet::antikt_algorithm; break;
290  };
291 
292  AliNSubjettinessDefinition nsubjettinessSettings;
293  nsubjettinessSettings.fBeta = 1.;
294  nsubjettinessSettings.fRadius = 0.4;
295 
296  if(datajets) {
297  AliDebugStream(1) << "In data jets branch: found " << datajets->GetNJets() << " jets, " << datajets->GetNAcceptedJets() << " were accepted\n";
298  AliDebugStream(1) << "Having MC information: " << (mcjets ? TString::Format("yes, with %d jets", mcjets->GetNJets()) : "no") << std::endl;
299  if(mcjets) {
300  AliDebugStream(1) << "In MC jets branch: found " << mcjets->GetNJets() << " jets, " << mcjets->GetNAcceptedJets() << " were accepted\n";
301  }
302  for(auto jet : datajets->accepted()) {
303  double pt = jet->Pt(), pz = jet->Pz(), E = jet->E(), M = TMath::Sqrt(E*E - pt*pt - pz*pz);
304  AliDebugStream(2) << "Next jet: pt:" << jet->Pt() << ", E: " << E << ", pz: " << pz << ", M(self): " << M << "M(fj)" << jet->M() << std::endl;
305  AliEmcalJet *associatedJet = jet->ClosestJet();
306 
307  if(mcjets) {
308  if(!associatedJet) {
309  AliDebugStream(2) << "Not found associated jet" << std::endl;
310  continue;
311  }
312  try {
313  DoConstituentQA(jet, tracks, clusters);
314  AliJetSubstructureData structureData = MakeJetSubstructure(*jet, datajets->GetJetRadius() * 2., tracks, clusters, {softdropSettings, nsubjettinessSettings}),
315  structureMC = fFillPart ? MakeJetSubstructure(*associatedJet, mcjets->GetJetRadius() * 2, particles, nullptr, {softdropSettings, nsubjettinessSettings}) : AliJetSubstructureData();
316  Double_t angularity[2] = {fFillStructGlob ? MakeAngularity(*jet, tracks, clusters) : 0., (fFillStructGlob && fFillPart) ? MakeAngularity(*associatedJet, particles, nullptr) : 0.},
317  ptd[2] = {fFillStructGlob ? MakePtD(*jet, tracks, clusters) : 0., (fFillStructGlob && fFillPart) ? MakePtD(*associatedJet, particles, nullptr) : 0};
318  FillTree(datajets->GetJetRadius(), weight, jet, associatedJet, &(structureData.fSoftDrop), &(structureMC.fSoftDrop), &(structureData.fNsubjettiness), &(structureMC.fNsubjettiness), angularity, ptd, rhoparameters);
319  } catch(ReclusterizerException &e) {
320  AliErrorStream() << "Error in reclusterization - skipping jet" << std::endl;
321  } catch(SubstructureException &e) {
322  AliErrorStream() << "Error in substructure observable - skipping jet" << std::endl;
323  }
324  } else {
325  try {
326  DoConstituentQA(jet, tracks, clusters);
327  AliJetSubstructureData structure = MakeJetSubstructure(*jet, 0.4, tracks, clusters, {softdropSettings, nsubjettinessSettings});
328  Double_t angularity[2] = {fFillStructGlob ? MakeAngularity(*jet, tracks, clusters): 0., 0.},
329  ptd[2] = {fFillStructGlob ? MakePtD(*jet, tracks, clusters) : 0., 0.};
330  FillTree(datajets->GetJetRadius(), weight, jet, nullptr, &(structure.fSoftDrop), nullptr, &(structure.fNsubjettiness), nullptr, angularity, ptd, rhoparameters);
331  } catch(ReclusterizerException &e) {
332  AliErrorStream() << "Error in reclusterization - skipping jet" << std::endl;
333  } catch(SubstructureException &e) {
334  AliErrorStream() << "Error in substructure observable - skipping jet" << std::endl;
335  }
336  }
337  }
338  } else {
339  if(mcjets) {
340  // for MCgen train
341  AliDebugStream(1) << "In MC pure jet branch: found " << mcjets->GetNJets() << " jets, " << mcjets->GetNAcceptedJets() << " were accepted\n";
342  for(auto j : mcjets->accepted()){
343  AliEmcalJet *mcjet = static_cast<AliEmcalJet *>(j);
344  try {
345  AliJetSubstructureData structure = MakeJetSubstructure(*mcjet, mcjets->GetJetRadius() * 2., particles, nullptr,{softdropSettings, nsubjettinessSettings});
346  Double_t angularity[2] = {0., MakeAngularity(*mcjet, particles, nullptr)},
347  ptd[2] = {0., MakePtD(*mcjet, particles, nullptr)};
348  FillTree(mcjets->GetJetRadius(), weight, nullptr, mcjet, nullptr, &(structure.fSoftDrop), nullptr, &(structure.fNsubjettiness), angularity, ptd, rhoparameters);
349  } catch (ReclusterizerException &e) {
350  AliErrorStream() << "Error in reclusterization - skipping jet" << std::endl;
351  } catch (SubstructureException &e) {
352  AliErrorStream() << "Error in substructure observable - skipping jet" << std::endl;
353  }
354  }
355  }
356  }
357 
358  return true;
359 }
360 
362  const AliEmcalJet *datajet, const AliEmcalJet *mcjet,
363  AliSoftDropParameters *dataSoftdrop, AliSoftDropParameters *mcSoftdrop,
364  AliNSubjettinessParameters *dataSubjettiness, AliNSubjettinessParameters *mcSubjettiness,
365  Double_t *angularity, Double_t *ptd, Double_t *rhoparameters){
366 
367  memset(fJetTreeData,0, sizeof(Double_t) * kTNVar);
368  fJetTreeData[kTRadius] = r;
369  fJetTreeData[kTWeight] = weight;
370  if(fFillRho){
371  fJetTreeData[kTRhoPtRec] = rhoparameters[0];
372  if(fFillMass) fJetTreeData[kTRhoMassRec] = rhoparameters[2];
373  if(fFillPart){
374  fJetTreeData[kTRhoPtSim] = rhoparameters[1];
375  if(fFillMass) fJetTreeData[kTRhoMassSim] = rhoparameters[3];
376  }
377  }
378  if(datajet) {
379  fJetTreeData[kTPtJetRec] = TMath::Abs(datajet->Pt());
381  fJetTreeData[kTNNeutral] = datajet->GetNumberOfClusters();
382  fJetTreeData[kTAreaRec] = datajet->Area();
383  fJetTreeData[kTNEFRec] = datajet->NEF();
384  if(fFillMass) fJetTreeData[kTMassRec] = datajet->M();
385  fJetTreeData[kTEJetRec] = datajet->E();
386  if(fFillAcceptance) {
387  fJetTreeData[kTEtaRec] = datajet->Eta();
388  fJetTreeData[kTPhiRec] = datajet->Phi();
389  }
390  }
391 
392  if(fFillPart && mcjet){
393  fJetTreeData[kTPtJetSim] = TMath::Abs(mcjet->Pt());
395  fJetTreeData[kTAreaSim] = mcjet->Area();
396  fJetTreeData[kTNEFSim] = mcjet->NEF();
397  if(fFillMass) fJetTreeData[kTMassSim] = mcjet->M();
398  fJetTreeData[kTEJetSim] = mcjet->E();
399  if(fFillAcceptance){
400  fJetTreeData[kTEtaSim] = mcjet->Eta();
401  fJetTreeData[kTPhiSim] = mcjet->Phi();
402  }
403  }
404 
405  if(fFillSoftDrop){
406  if(dataSoftdrop) {
407  fJetTreeData[kTZgMeasured] = dataSoftdrop->fZg;
408  fJetTreeData[kTRgMeasured] = dataSoftdrop->fRg;
409  fJetTreeData[kTMgMeasured] = dataSoftdrop->fMg;
410  fJetTreeData[kTPtgMeasured] = dataSoftdrop->fPtg;
411  fJetTreeData[kTMugMeasured] = dataSoftdrop->fMug;
412  fJetTreeData[kTNDroppedMeasured] = dataSoftdrop->fNDropped;
413  }
414 
415  if(fFillPart && mcSoftdrop) {
416  fJetTreeData[kTZgTrue] = mcSoftdrop->fZg;
417  fJetTreeData[kTRgTrue] = mcSoftdrop->fRg;
418  fJetTreeData[kTMgTrue] = mcSoftdrop->fMg;
419  fJetTreeData[kTPtgTrue] = mcSoftdrop->fPtg;
420  fJetTreeData[kTMugTrue] = mcSoftdrop->fMug;
421  fJetTreeData[kTNDroppedTrue] = mcSoftdrop->fNDropped;
422  }
423  }
424 
425  if(fFillNSub){
426  if(dataSubjettiness) {
429  }
430 
431  if(fFillPart && mcSubjettiness) {
434  }
435  }
436 
437  if(fFillStructGlob){
438  fJetTreeData[kTAngularityMeasured] = angularity[0];
439  fJetTreeData[kTPtDMeasured] = ptd[0];
440 
441  if(fFillPart){
442  fJetTreeData[kTAngularityTrue] = angularity[1];
443  fJetTreeData[kTPtDTrue] = ptd[1];
444  }
445  }
446 
447  fJetSubstructureTree->Fill();
448 }
449 
450 
452  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
453  std::vector<fastjet::PseudoJet> constituents;
454  bool isMC = dynamic_cast<const AliTrackContainer *>(tracks);
455  AliDebugStream(2) << "Make new jet substrucutre for " << (isMC ? "MC" : "data") << " jet: Number of tracks " << jet.GetNumberOfTracks() << ", clusters " << jet.GetNumberOfClusters() << std::endl;
456  for(int itrk = 0; itrk < jet.GetNumberOfTracks(); itrk++){
457  auto track = jet.TrackAt(itrk, tracks->GetArray());
458  fastjet::PseudoJet constituentTrack(track->Px(), track->Py(), track->Pz(), track->E());
459  constituentTrack.set_user_index(jet.TrackAt(itrk));
460  constituents.push_back(constituentTrack);
461  }
462 
463  if(clusters){
464  for(int icl = 0; icl < jet.GetNumberOfClusters(); icl++) {
465  auto cluster = jet.ClusterAt(icl, clusters->GetArray());
466  TLorentzVector clustervec;
467  cluster->GetMomentum(clustervec, fVertex, (AliVCluster::VCluUserDefEnergy_t)clusters->GetDefaultClusterEnergy());
468  fastjet::PseudoJet constituentCluster(clustervec.Px(), clustervec.Py(), clustervec.Pz(), cluster->GetHadCorrEnergy());
469  constituentCluster.set_user_index(jet.ClusterAt(icl) + kClusterOffset);
470  constituents.push_back(constituentCluster);
471  }
472  }
473 
474  AliDebugStream(3) << "Found " << constituents.size() << " constituents for jet with pt=" << jet.Pt() << " GeV/c" << std::endl;
475  if(!constituents.size())
476  throw ReclusterizerException();
477  // Redo jet finding on constituents with a
478  fastjet::JetDefinition jetdef(fastjet::antikt_algorithm, jetradius*2, static_cast<fastjet::RecombinationScheme>(0), fastjet::BestFJ30 );
479  std::vector<fastjet::PseudoJet> outputjets;
480  try {
481  fastjet::ClusterSequence jetfinder(constituents, jetdef);
482  outputjets = jetfinder.inclusive_jets(0);
484  return result;
485  } catch (fastjet::Error &e) {
486  AliErrorStream() << " FJ Exception caught: " << e.message() << std::endl;
487  throw ReclusterizerException();
488  } catch (SoftDropException &e) {
489  AliErrorStream() << "Softdrop exception caught: " << e.what() << std::endl;
490  throw ReclusterizerException();
491  }
492 }
493 
495  fastjet::contrib::SoftDrop softdropAlgorithm(cutparameters.fBeta, cutparameters.fZ);
496  softdropAlgorithm.set_verbose_structure(kTRUE);
497  std::unique_ptr<fastjet::contrib::Recluster> reclusterizer(new fastjet::contrib::Recluster(cutparameters.fRecluserAlgo, 1, true));
498  softdropAlgorithm.set_reclustering(kTRUE, reclusterizer.get());
499  AliDebugStream(4) << "Jet has " << jet.constituents().size() << " constituents" << std::endl;
500  auto groomed = softdropAlgorithm(jet);
501  try {
502  auto softdropstruct = groomed.structure_of<fastjet::contrib::SoftDrop>();
503 
504  AliSoftDropParameters result({softdropstruct.symmetry(),
505  groomed.m(),
506  softdropstruct.delta_R(),
507  groomed.perp(),
508  softdropstruct.mu(),
509  softdropstruct.dropped_count()});
510  return result;
511  } catch(std::bad_cast &e) {
512  throw SoftDropException();
513  }
514 }
515 
518  fastjet::contrib::Nsubjettiness (1,fastjet::contrib::KT_Axes(),fastjet::contrib::NormalizedCutoffMeasure(cut.fBeta, cut.fRadius, 1e100)).result(jet),
519  fastjet::contrib::Nsubjettiness (2,fastjet::contrib::KT_Axes(),fastjet::contrib::NormalizedCutoffMeasure(cut.fBeta, cut.fRadius, 1e100)).result(jet)
520  });
521  return result;
522 }
523 
525  if(!(jet.GetNumberOfTracks() || jet.GetNumberOfClusters()))
526  throw SubstructureException();
527  TVector3 jetvec(jet.Px(), jet.Py(), jet.Pz());
528  Double_t den(0.), num(0.);
529  if(tracks){
530  for(UInt_t itrk = 0; itrk < jet.GetNumberOfTracks(); itrk++) {
531  auto track = jet.TrackAt(itrk, tracks->GetArray());
532  if(!track){
533  AliErrorStream() << "Associated constituent particle / track not found\n";
534  continue;
535  }
536  TVector3 trackvec(track->Px(), track->Py(), track->Pz());
537 
538  num += track->Pt() * trackvec.DrEtaPhi(jetvec);
539  den += +track->Pt();
540  }
541  }
542  if(clusters) {
543  for(UInt_t icl = 0; icl < jet.GetNumberOfClusters(); icl++){
544  auto clust = jet.ClusterAt(icl, clusters->GetArray());
545  if(!clust) {
546  AliErrorStream() << "Associated constituent cluster not found\n";
547  continue;
548  }
549  TLorentzVector clusterp;
550  clust->GetMomentum(clusterp, fVertex, (AliVCluster::VCluUserDefEnergy_t)clusters->GetDefaultClusterEnergy());
551 
552  num += clusterp.Pt() * clusterp.Vect().DrEtaPhi(jetvec);
553  den += clusterp.Pt();
554  }
555  }
556  return num/den;
557 }
558 
560  if (!(jet.GetNumberOfTracks() || jet.GetNumberOfClusters()))
561  throw SubstructureException();
562  Double_t den(0.), num(0.);
563  if(particles){
564  for(UInt_t itrk = 0; itrk < jet.GetNumberOfTracks(); itrk++) {
565  auto trk = jet.TrackAt(itrk, particles->GetArray());
566  if(!trk){
567  AliErrorStream() << "Associated constituent particle / track not found\n";
568  continue;
569  }
570  num += trk->Pt() * trk->Pt();
571  den += trk->Pt();
572  }
573  }
574  if(clusters){
575  for(UInt_t icl = 0; icl < jet.GetNumberOfClusters(); icl++){
576  auto clust = jet.ClusterAt(icl, clusters->GetArray());
577  if(!clust) {
578  AliErrorStream() << "Associated constituent cluster not found\n";
579  continue;
580  }
581  TLorentzVector clusterp;
582  clust->GetMomentum(clusterp, fVertex, (AliVCluster::VCluUserDefEnergy_t)clusters->GetDefaultClusterEnergy());
583  num += clusterp.Pt() * clusterp.Pt();
584  den += clusterp.Pt();
585  }
586  }
587  return TMath::Sqrt(num)/den;
588 }
589 
591  for(int icl = 0; icl < jet->GetNumberOfClusters(); icl++){
592  auto clust = jet->ClusterAt(icl, clusters->GetArray());
593  AliDebugStream(3) << "cluster time " << clust->GetTOF() << std::endl;
594  fQAHistos->FillTH2("hClusterConstE", jet->Pt(),clust->GetUserDefEnergy(clusters->GetDefaultClusterEnergy()));
595  fQAHistos->FillTH2("hClusterConstTime", jet->Pt(), clust->GetTOF());
596  fQAHistos->FillTH2("hClusterConstM02", jet->Pt(), clust->GetM02());
597  fQAHistos->FillTH2("hClusterConstNcell", jet->Pt(), clust->GetNCells());
598 
599 #ifdef EXPERIMENTAL_JETCONSTITUENTS
600  fQAHistos->FillTH2("hClusterIndexENLC", jet->Pt(), clust->GetNonLinCorrEnergy());
601  fQAHistos->FillTH2("hClusterIndexEHC", jet->Pt(), clust->GetHadCorrEnergy());
602 #endif
603  }
604 
605 #ifdef EXPERIMENTAL_JETCONSTITUENTS
606  // Loop over charged particles - fill test histogram
607  for(int itrk = 0; itrk < jet->GetNumberOfTracks(); itrk++){
608  auto part = jet->TrackAt(itrk, cont->GetArray());
609  fQAHistos->FillTH2("hChargedIndexPt", jet->Pt(), part->Pt());
610  }
611 
612  // Look over charged constituents
613  AliDebugStream(2) << "Jet: Number of particle constituents: " << jet->GetParticleConstituents().GetEntriesFast() << std::endl;
614  for(auto pconst : jet->GetParticleConstituents()) {
615  auto part = static_cast<PWG::JETFW::AliEmcalParticleJetConstituent *>(pconst);
616  AliDebugStream(3) << "Found particle constituent with pt " << part->Pt() << ", from VParticle " << part->GetParticle()->Pt() << std::endl;
617  fQAHistos->FillTH2("hChargedConstituentPt", jet->Pt(), part->Pt());
618  }
619 
620  // Loop over neutral constituents
621  AliDebugStream(2) << "Jet: Number of cluster constituents: " << jet->GetClusterConstituents().GetEntriesFast() << std::endl;
622  for(auto cconst : jet->GetClusterConstituents()){
623  auto clust = static_cast<PWG::JETFW::AliEmcalClusterJetConstituent *>(cconst);
624  AliDebugStream(3) << "Found cluster constituent with energy " << clust->E() << " using energy definition " << static_cast<int>(clust->GetDefaultEnergyType()) << std::endl;
625  fQAHistos->FillTH2("hClusterConstituentEDefault", jet->Pt(), clust->E());
626  fQAHistos->FillTH2("hClusterConstituentENLC", jet->Pt(), clust->GetCluster()->GetNonLinCorrEnergy());
627  fQAHistos->FillTH2("hClusterConstituentEHC", jet->Pt(), clust->GetCluster()->GetHadCorrEnergy());
628  }
629 #endif
630 }
631 
633  return branchname.Contains("Sim") || branchname.Contains("True");
634 }
635 
637  return branchname.Contains("Eta") || branchname.Contains("Phi");
638 }
639 
641  return branchname.Contains("Rho");
642 }
643 
645  return branchname.Contains("Mass"); // also disable rho mass branch
646 }
647 
649  return branchname.Contains("gMeasured") || branchname.Contains("gTrue") || branchname.Contains("NDropped");
650 }
651 
653  return branchname.Contains("Subjettiness");
654 }
655 
657  return branchname.Contains("Angularity") || branchname.Contains("PtD");
658 }
659 
661  AliAnalysisManager *mgr = AliAnalysisManager::GetAnalysisManager();
662 
663  Bool_t isAOD(kFALSE);
664  AliInputEventHandler *inputhandler = static_cast<AliInputEventHandler *>(mgr->GetInputEventHandler());
665  if(inputhandler) {
666  if(inputhandler->IsA() == AliAODInputHandler::Class()){
667  std::cout << "Analysing AOD events\n";
668  isAOD = kTRUE;
669  } else {
670  std::cout << "Analysing ESD events\n";
671  }
672  }
673 
674  AliAnalysisTaskEmcalJetSubstructureTree *treemaker = new AliAnalysisTaskEmcalJetSubstructureTree("JetSubstructureTreemaker_" + TString::Format("R%02d_", int(jetradius * 10.)) + trigger);
675  mgr->AddTask(treemaker);
676  treemaker->SetMakeGeneralHistograms(kTRUE);
677 
678  // Adding containers
679  if(isMC) {
680  AliParticleContainer *particles = treemaker->AddMCParticleContainer("mcparticles");
681  particles->SetMinPt(0.);
682 
683  AliJetContainer *mcjets = treemaker->AddJetContainer(
684  jettype,
686  recombinationScheme,
687  jetradius,
689  particles, nullptr);
690  mcjets->SetName("mcjets");
691  mcjets->SetJetPtCut(20.);
692  }
693 
694  if(isData) {
695  AliTrackContainer *tracks(nullptr);
696  if((jettype == AliJetContainer::kChargedJet) || (jettype == AliJetContainer::kFullJet)){
698  std::cout << "Track container name: " << tracks->GetName() << std::endl;
699  tracks->SetMinPt(0.15);
700  }
701  AliClusterContainer *clusters(nullptr);
703  std::cout << "Using full or neutral jets ..." << std::endl;
705  std::cout << "Cluster container name: " << clusters->GetName() << std::endl;
706  clusters->SetClusHadCorrEnergyCut(0.3); // 300 MeV E-cut
707  clusters->SetDefaultClusterEnergy(AliVCluster::kHadCorr);
708  } else {
709  std::cout << "Using charged jets ... " << std::endl;
710  }
711 
712  AliJetContainer *datajets = treemaker->AddJetContainer(
713  jettype,
715  recombinationScheme,
716  jetradius,
718  tracks, clusters);
719  datajets->SetName("datajets");
720  datajets->SetJetPtCut(20.);
721 
722  treemaker->SetUseAliAnaUtils(true, true);
723  treemaker->SetVzRange(-10., 10);
724 
725  // configure trigger selection
726  TString triggerstring(trigger);
727  if(triggerstring.Contains("INT7")) {
728  treemaker->SetTriggerBits(AliVEvent::kINT7);
729  } else if(triggerstring.Contains("EJ1")) {
730  treemaker->SetTriggerBits(AliVEvent::kEMCEJE);
731  treemaker->SetTriggerString("EJ1");
732  } else if(triggerstring.Contains("EJ2")) {
733  treemaker->SetTriggerBits(AliVEvent::kEMCEJE);
734  treemaker->SetTriggerString("EJ2");
735  }
736  }
737 
738  // Connecting containers
739  TString outputfile = mgr->GetCommonFileName();
740  outputfile += TString::Format(":JetSubstructure_R%02d_%s", int(jetradius * 10.), trigger);
741  mgr->ConnectInput(treemaker, 0, mgr->GetCommonInputContainer());
742  mgr->ConnectOutput(treemaker, 1, mgr->CreateContainer("JetSubstructureHistos_" + TString::Format("R%0d_", int(jetradius * 10.)) + trigger, AliEmcalList::Class(), AliAnalysisManager::kOutputContainer, outputfile));
743  mgr->ConnectOutput(treemaker, 2, mgr->CreateContainer("JetSubstuctureTree_" + TString::Format("R%0d_", int(jetradius * 10.)) + trigger, TTree::Class(), AliAnalysisManager::kOutputContainer, mgr->GetCommonFileName()));
744 
745  return treemaker;
746 }
747 
748 } /* 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
static AliAnalysisTaskEmcalJetSubstructureTree * AddEmcalJetSubstructureTreeMaker(Bool_t isMC, Bool_t isData, Double_t jetradius, AliJetContainer::EJetType_t jettype, AliJetContainer::ERecoScheme_t recombinationScheme, const char *name)
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.
Double_t Eta() const
Definition: AliEmcalJet.h:121
static AliEmcalDownscaleFactorsOCDB * Instance()
Double_t Py() const
Definition: AliEmcalJet.h:107
Double_t Phi() const
Definition: AliEmcalJet.h:117
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)
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.
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.
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.
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
void LinkOutputBranch(const TString &branchname, Double_t *datalocation)
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.