ATLAS Offline Software
Loading...
Searching...
No Matches
JetHistoTools.py
Go to the documentation of this file.
1# Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2
3from JetMonitoring.JetMonitoringConf import JetKinematicHistos, HistosForJetSelection, LeadingJetsRelations, EfficiencyResponseHistos
4
5
6from JetMonitoring.JetHistoManager import jetHistoManager as jhm
7from JetMonitoring.JetAttributeHistoManager import attributeHistoManager
8from JetMonitoring.HistoDefinitionHelpers import createHistoDefTool as hdef
9
10# The dict below defines default specification to plot Jet attributes.
11# Specifications are given in a 1-line compact format.
12# They are then automatically converted to proper JetAttributeHisto tools below.
13compactSpecification = {
14
15 # 1D Histo format is
16 # "histoname" : ( binning, attributeInfo )
17 # where
18 # - binning is ("title;labelx;labely", nbins, xlow, xup) as in TH1 ctor
19 # - attributeInfo is ("attribute", "attribute type") or ("attribute", "attribute type", "gev")
20 #
21
22#
23# Jet moments added from https://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/Run2JetMoments/
24#
25
26 #newly added Substructure variables:
27 "DetectorEta" : (("DetectorEta;DetectorEta;",100,-5,5),("DetectorEta","float")),
28 "NTrimSubjets" : (("NTrimSubjets;NTrimSubjets;",20,0,20),("NTrimSubjets","int")),
29 "TrackSumPt" : (("TrackSumPt;TrackSumPt;",80,0,8000),("TrackSumPt","float")),
30 "TrackSumMass" : (("TrackSumMass;TrackSumMass;",100,0,10000),("TrackSumMass","float")),
31 "Qw" : (("Qw;Qw;",100,0,100000),("Qw","float")),
32 "KtDR" : (("KtDR;KtDR;",100,0,10),("KtDR","float")),
33#
34 "Tau1" : (("Tau1;Tau1;",100,0,1.0),("Tau1","float")),
35 "Tau2" : (("Tau2;Tau2;",100,0,1.0),("Tau2","float")),
36 "Tau3" : (("Tau3;Tau3;",100,0,1.0),("Tau3","float")),
37 "Tau1_wta" : (("Tau1_wta;Tau1_wta;",100,0,1.0),("Tau1_wta","float")),
38 "Tau2_wta" : (("Tau2_wta;Tau2_wta;",100,0,1.0),("Tau2_wta","float")),
39 "Tau3_wta" : (("Tau3_wta;Tau3_wta;",100,0,1.0),("Tau3_wta","float")),
40 "Tau21" : (("Tau21;Tau21;",100,0,1.0),("Tau21","float")),
41 "Tau32" : (("Tau32;Tau32;",100,0,1.0),("Tau32","float")),
42 "Tau21_wta" : (("Tau21_wta;Tau21_wta;",100,0,1.0),("Tau21_wta","float")),
43 "Tau32_wta" : (("Tau32_wta;Tau32_wta;",100,0,1.0),("Tau32_wta","float")),
44#
45 "Dip12" : (("Dip12;Dip12;",100,-1,2),("Dip12","float")),
46 "Dip13" : (("Dip13;Dip13;",100,-1,2),("Dip13","float")),
47 "Dip23" : (("Dip23;Dip23;",100,-1,2),("Dip23","float")),
48 "DipExcl12" : (("DipExcl12;DipExcl12;",100,-1,2),("DipExcl12","float")),
49#
50 "Split12" : (("Split12;Split12;",100,0,70000),("Split12","float")),
51 "Split23" : (("Split23;Split23;",60,0,24000),("Split23","float")),
52 "Split34" : (("Split34;Split34;",100,0,10000),("Split34","float")),
53#
54 "ZCut12" : (("ZCut12;ZCut12;",100,0,1.0),("ZCut12","float")),
55 "ZCut23" : (("ZCut23;ZCut23;",100,0,1.0),("ZCut23","float")),
56 "ZCut34" : (("ZCut34;ZCut34;",100,0,1.0),("ZCut34","float")),
57#
58 "Angularity" : (("Angularity;Angularity;",50,-.1,.1), ("Angularity","float")),
59#
60 "PlanarFlow" : (("PlanarFlow;PlanarFlow;",100,-1,1.1),("PlanarFlow","float")),
61#
62 "Mu12" : (("Mu12;Mu12;",100,0,1.0),("Mu12","float")),
63#
64 "ECF1" : (("ECF1;ECF1;",50,0,200000),("ECF1","float")),
65 "ECF2" : (("ECF2;ECF2;",100,0,2e10),("ECF2","float")),
66 "ECF3" : (("ECF3;ECF3;",100,0,1e14),("ECF3","float")),
67 "ECF1_Beta2" : (("ECF1_Beta2;ECF1_Beta2;",100,-1,1),("ECF1_Beta2","float")),
68 "ECF2_Beta2" : (("ECF2_Beta2;ECF2_Beta2;",100,-1,1),("ECF2_Beta2","float")),
69 "ECF3_Beta2" : (("ECF3_Beta2;ECF3_Beta2;",100,-1,1),("ECF3_Beta2","float")),
70#
71 "C1" : (("C1;C1;",100,-1,1), ("C1","float")),
72 "C2" : (("C2;C2;",100,-1,1), ("C2","float")),
73 "D2" : (("D2;D2;",100, 0,10), ("D2","float")),
74 "C1_Beta2" : (("C1;C1;",100,-1,1), ("C1","float")),
75 "C2_Beta2" : (("C2_Beta2;C2_Beta2;",100,-1,1), ("C2_Beta2","float")),
76 "D2_Beta2" : (("D2_Beta2;D2_Beta2;",100,-1,1), ("D2_Beta2","float")),
77#
78 "ThrustMin" : (("ThrustMin;ThrustMin;",100,-1,2),("ThrustMin","float")),
79 "ThrustMaj" : (("ThrustMaj;ThrustMaj;",100,-1,2),("ThrustMaj","float")),
80 "FoxWolfram0" : (("FoxWolfram0;FoxWolfram0;",100,-1,1),("FoxWolfram0","float")),
81 "FoxWolfram1" : (("FoxWolfram0;FoxWolfram1;",100,-1,1),("FoxWolfram1","float")),
82 "FoxWolfram2" : (("FoxWolfram0;FoxWolfram2;",100,-1,1),("FoxWolfram2","float")),
83 "FoxWolfram3" : (("FoxWolfram0;FoxWolfram3;",100,-1,1),("FoxWolfram3","float")),
84 "FoxWolfram4" : (("FoxWolfram0;FoxWolfram4;",100,-1,1),("FoxWolfram4","float")),
85 "Sphericity" : (("Sphericity;Sphericity;",100,0,1),("Sphericity","float")),
86 "Aplanarity" : (("Aplanarity;Aplanarity;",100,0,1),("Aplanarity","float")),
87#
88 "PullMag" : (("PullMag;PullMag;",100,0,100),("PullMag","float")),
89 "PullPhi" : (("PullPhi;PullPhi;",100,-6.3,6.3),("PullPhi","float")),
90 "Pull_C00" : (("Pull_C00;Pull_C00;",100,-1,1),("Pull_C00","float")),
91 "Pull_C01" : (("Pull_C01;Pull_C01;",100,-1,1),("Pull_C01","float")),
92 "Pull_C10" : (("Pull_C10;Pull_C10;",100,-1,1),("Pull_C10","float")),
93 "Pull_C11" : (("Pull_C11;Pull_C11;",100,-1,1),("Pull_C11","float")),
94#
95 "Charge" : (("Charge;Charge;",100,-2,2),("Charge","float")),
96#
97 "ShowerDeconstructionW": (("ShowerDeconstructionW;ShowerDeconstructionW;",100,-100,100),("ShowerDeconstructionW","float")),
98 "ShowerDeconstructionTop": (("ShowerDeconstructionTop;ShowerDeconstructionTop;",100,-100,100),("ShowerDeconstructionTop","float")),
99#
100 "Volatility" : (("Volatility;Volatility;",100,-100,100),("Volatility","float")),
101#
102 "pt" : (("Jet Pt;Pt [MeV];", 100, 0, 200) , ("pt","float","gev" ) ),
103 "Width" : (("Jet Width;Width;", 50, 0, 1.0) , ("Width","float" ) ),
104 "Width15" : (("Jet Width;Width;", 50, 0, 1.5) , ("Width","float" ) ),
105 "EMFrac" : (("EM Fraction;EM fraction;", 50, -0.1, 1.4), ("EMFrac", "float") ),
106 "HECFrac" : (("HEC Fraction;HEC fraction;", 50, -0.1, 1.4), ("HECFrac", "float") ),
107 "Timing" : (("Jet Time info;Time;", 40, -20, 20) , ("Timing", "float") ),
108 "NegativeE" : (("Negative E in Jet;Energy;", 80, -10, 0), ("NegativeE", "float", "gev") ),
109 "LArQuality" : (("LAr quality;Energy;", 50, -0.4, 1.2), ("LArQuality", "float") ),
110
111 "GhostTruthCount" : (("Number of associate truth part;Number;", 60,0,60) , ("GhostTruthCount", "int")),
112 "GhostTruthAssociationFraction" : (("Fraction of associated truth particles from a matched truth jet jet;GhostTruthAssociationFraction;", 50,0,1.) , ("GhostTruthAssociationFraction", "float")),
113 "GhostTrackCount" : (("Number of associate tracks;Number;", 60,0,60), ("GhostTrackCount", "int") ),
114 "GhostMuonSegmentCount" : (("Number of associated muon segments;Number;", 60,0,60), ("GhostMuonSegmentCount", "int") ),
115 "JVF" : (("Jet Vertex Fraction;JVF;", 60,0,1.2), ("JVF", "vector<float>") ),
116 "JVF[0]" : (("Jet Vertex Fraction;JVF;", 60,0,1.2), ("JVF[0]", "vector<float>") ),
117 'JVFCorr' : (("Jet JVT JVFCorr;;", 120, -1.2, 1.2) , ("JVFCorr","float" ) ),
118 'Jvt' : (("Jet JVT;;", 70, -0.2, 1.2) , ("Jvt","float" ) ),
119 'JvtRpt' : (("Jet JVT Rpt;;", 75, 0, 1.5) , ("JvtRpt","float" ) ),
120 "SumPtTrkPt500" : (("Sum Pt of all tracks above 0.5 GeV:SumPt(p_{T}>0.5 GeV);", 100,0,200), ("SumPtTrkPt500", "vector<float>", "gev") ),
121 "SumPtTrkPt500[0]" : (("Sum Pt of tracks from PV0 above 0.5 GeV:SumPt(p_{T}>0.5 GeV);", 100,0,200), ("SumPtTrkPt500[0]", "vector<float>", "gev") ),
122 "NumTrkPt500[0]" : (("Number of tracks from PV0 above 0.5 GeV:N_{tracks}(p_{T}>0.5 GeV);", 100,0,100), ("NumTrkPt500[0]", "vector<int>") ),
123 "NumTrkPt1000[0]" : (("Number of all tracks above 1 GeV:N_{tracks}(p_{T}>1 GeV);", 100,0,100), ("NumTrkPt1000[0]", "vector<int>") ),
124 "TrackWidthPt1000[0]": (("Width from tracks from PV0 above 1 GeV:Track Width(p_{T}>1 GeV);", 75,0.,1.5), ("TrackWidthPt1000[0]", "vector<float>") ),
125 "SumPtChargedPFOPt500" : (("Sum Pt of all charged PFOs above 0.5 GeV:SumPt chargedPFO(p_{T}>0.5 GeV);", 100,0,200), ("SumPtChargedPFOPt500", "vector<float>", "gev") ),
126 "SumPtChargedPFOPt500[0]" : (("Sum Pt of all charged PFOs from PV0 above 0.5 GeV:SumPt(p_{T}>0.5 GeV);", 100,0,200), ("SumPtChargedPFOPt500[0]", "vector<float>", "gev") ),
127 "NumChargedPFOPt500[0]" : (("Number of charged PFOs from PVO above 0.5 GeV:N_{charged PFO}(p_{T}>0.5 GeV);", 100,0,100), ("NumChargedPFOPt500[0]", "vector<int>") ),
128 "NumChargedPFOPt1000[0]" :(("Number of charged PFOs from PVO above 1 GeV:N_{charged PFO}(p_{T}>1 GeV);", 100,0,100), ("NumChargedPFOPt1000[0]", "vector<int>") ),
129 "ChargedPFOWidthPt1000[0]": (("Width from charged PFOs from PV0 above 1 GeV:Charged PFO Width(p_{T}>1 GeV);", 75,0.,1.5), ("ChargedPFOWidthPt1000[0]", "vector<float>") ),
130 "ActiveArea" : (("Active Area;Area;", 80, 0, 0.8), ("ActiveArea", "float") ),
131 "ActiveArea15" : (("Active Area;Area;", 80, 0, 1.5), ("ActiveArea", "float") ),
132 "BchCorrDotx" : (("BchCorrDotx:BchCorrDotx;",50,0,1), ("BchCorrDotx", "float") ),
133 "BchCorrCell" : (("BchCorrCell:BchCorrCell;",50,0,1), ("BchCorrCell", "float") ),
134
135 "AverageLArQF" : (("Average LAr QF;AverageLArQF;",100,0, 65535), ("AverageLArQF", "float") ),
136 "HECQuality" : (("HEC Quality;HEC Quality;",50,-0.1, 1.4), ("HECQuality", "float") ),
137 "FracSamplingMax" : (("FracSamplingMax; FracSamplingMax;",50,-0.1, 1.2), ("FracSamplingMax", "float") ),
138 # binning optimisation from Emma Tolley
139 #"FracSamplingMaxIndex" : (("FracSamplingMaxIndex; FracSamplingMaxIndex;",23,0,23), ("FracSamplingMaxIndex", "int") ),
140 "FracSamplingMaxIndex" : (("FracSamplingMaxIndex; FracSamplingMaxIndex;",24,0,24), ("FracSamplingMaxIndex", "int") ),
141 # binning optimisation from Emma Tolley
142 #"N90Constituents" : (("N90Constituents; N90Constituents;",50,0,10), ("N90Constituents", "float") ),
143 "N90Constituents" : (("N90Constituents; N90Constituents;",15,0,15), ("N90Constituents", "float") ),
144 "CentroidR" : (("CentroidR; CentroidR;",100,0,7500), ("CentroidR", "float") ),
145 "OotFracClusters5" : (("OotFracClusters5; OotFracClusters5;",50,-0.1,1.2), ("OotFracClusters5", "float") ),
146 "OotFracClusters10": (("OotFracClusters10; OotFracClusters10;",50,-0.1,1.2), ("OotFracClusters10", "float") ),
147 #CBG
148 "ptN" : (("Jet Pt;Pt [GeV];", 250, 0., 5000.) , ("pt","float","gev" ) ),
149 "LeadingClusterCenterLambda": (("LeadingClusterCenterLambda; LeadingClusterCenterLambda;",100,0.,10000.), ("LeadingClusterCenterLambda", "float") ),
150 "LeadingClusterSecondLambda": (("LeadingClusterSecondLambda; LeadingClusterSecondLambda;",100,0.,10000.), ("LeadingClusterSecondLambda", "float") ),
151 # binning optimisation from Emma Tolley
152 #"LeadingClusterSecondR": (("LeadingClusterSecondR; LeadingClusterSecondR;",100,0.,1000.), ("LeadingClusterSecondR", "float") ),
153 "LeadingClusterSecondR": (("LeadingClusterSecondR; LeadingClusterSecondR;",100,0.,100000.), ("LeadingClusterSecondR", "float") ),
154 #"CHF": (("SumPtTrkPt500/pT; SumPtTrkPt500/pT;",50,-1.,1.2), ("chf", "vector<float>", "gev") ),
155 #"CHF[0]": (("SumPtTrkPt500/pT; SumPtTrkPt500/pT;",50,-1.,1.2), ("chf[0]", "vector<float>", "gev") ),
156 #CBG
157 #
158
159 #New PFlow Variables
160 "DFCommonJets_QGTagger_NTracks": (("DFCommonJets_QGTagger_NTracks; DFCommonJets_QGTagger_NTracks;",30,0.,30.), ("DFCommonJets_QGTagger_NTracks", "int") ),
161 "DFCommonJets_QGTagger_TracksWidth": (("DFCommonJets_QGTagger_TracksWidth; DFCommonJets_QGTagger_TracksWidth;",16,-1.1,0.5), ("DFCommonJets_QGTagger_TracksWidth", "float") ),
162 "DFCommonJets_QGTagger_TracksC1": (("DFCommonJets_QGTagger_TracksC1; DFCommonJets_QGTagger_TracksC1;",16,-1.1,0.5), ("DFCommonJets_QGTagger_TracksC1", "float") ),
163 "DFCommonJets_fJvt": (("DFCommonJets_fJvt; DFCommonJets_fJvt;",23,0.,2.3), ("DFCommonJets_fJvt", "float") ),
164 #RG and ZG
165 "rg": (("rg; rg;",29,-1.2,1.7), ("rg", "float") ),
166 "zg": (("zg; zg;",19,-1.2,0.7), ("zg", "float") ),
167
168 #Variables for track jets
169 "HadronConeExclTruthLabelID": (("HadronConeExclTruthLabelID; HadronConeExclTruthLabelID;", 150, -100.5, 49.5), ("HadronConeExclTruthLabelID", "int") ),
170 "HadronConeExclExtendedTruthLabelID": (("HadronConeExclExtendedTruthLabelID; HadronConeExclExtendedTruthLabelID; ;", 150, -100.5, 49.5), ("HadronConeExclExtendedTruthLabelID", "int")),
171 "HadronGhostTruthLabelID": (("HadronGhostTruthLabelID; HadronGhostTruthLabelID;", 150, -100.5, 49.5), ("HadronGhostTruthLabelID", "int")),
172 "HadronGhostExtendedTruthLabelID": (("HadronGhostExtendedTruthLabelID; HadronGhostExtendedTruthLabelID;", 150, -100.5, 49.5), ("HadronGhostExtendedTruthLabelID", "int")),
173
174 # 2D Histo format is
175 # "histoname" : ( binning, attributeInfo1, attributeInfo2 )
176 # where
177 # - binning is ("title;labelx;labely", nbins, xlow, xup, nbinsy, ylow, yup) as in TH2 ctor
178 # - attributeInfo is ("attribute", "attribute type") or ("attribute", "attribute type", "gev")
179
180 }
181
182# then fill the pers calo sampling attributes one by one :
183caloSamples =["PreSamplerB", "EMB1", "EMB2", "EMB3", "PreSamplerE", "EME1", "EME2", "EME3", "HEC0", "HEC1", "HEC2", "HEC3", "TileBar0", "TileBar1", "TileBar2", "TileGap1", "TileGap2", "TileGap3", "TileExt0", "TileExt1", "TileExt2", "FCAL0", "FCAL1", "FCAL2", ]
184for i,c in enumerate(caloSamples):
185 compactSpecification[ c ] = ( ("Energy in "+c+";Energy(GeV);",100,-10,1000), ("EnergyPerSampling[%d]"%(i,), "vector<float>", "gev"))
186
187
188# Translate the above specifications into proper histo tools
189# and add them to jhm
190attributeHistoManager.buildKnownTools(compactSpecification)
191
192
193# Jet histogramming tools
194jhm.addTool( JetKinematicHistos("allkinematics",PlotOccupancy=True, PlotAveragePt=True, PlotNJet=True , PlotNConstit = True) )
195jhm.addTool( JetKinematicHistos("basickinematics") )
196jhm.addTool( JetKinematicHistos("basickinematics_emscale", JetScale="JetEMScaleMomentum") )
197jhm.addTool( JetKinematicHistos("basickinematics_constscale", JetScale="JetConstitScaleMomentum") )
198
199jhm.addTool( LeadingJetsRelations("leadingjetrel",
200 HistoDef = [
201 hdef('ljrDeltaEta', "#Delta #eta (lead, sublead);#Delta#eta;Entries",100,-10,10 ),
202 hdef('ljrDeltaPhi', "#Delta #Phi (lead, sublead);#Delta#Phi;Entries",100,0,3.142 ),
203 hdef('ljrDeltaR', "#Delta R (lead, sublead);#Delta R;Entries",100,0,10 ),
204 hdef('ljrFrac', "(sublead Pt)/(lead Pt);ratio;Entries",100,0,1. ),
205
206 #hdef('ljrEta1Eta2', "sublead #eta vs lead #eta;lead #eta;sublead #eta",100,-5,5.,100,-5,5 ),
207
208 ]
209 ) )
210
211jhm.addTool( EfficiencyResponseHistos("effresponse",
212 HistoDef = [
213 hdef('erhEfficiencyR1', "Jet p_{T} Efficiency #DeltaR = 0.1;p_{T}^{Truth} (GeV);Efficiency",50,0,100 ),
214 hdef('erhEfficiencyR2', "Jet p_{T} Efficiency #DeltaR = 0.2;p_{T}^{Truth} (GeV);Efficiency",50,0,100 ),
215 hdef('erhEfficiencyR3', "Jet p_{T} Efficiency #DeltaR = 0.3;p_{T}^{Truth} (GeV);Efficiency",50,0,100 ),
216
217 hdef('erhResponse', "Jet p_{T} Response;#frac{p_{T}^{Jet} - p_{T}^{Truth}}{p_{T}^{Truth}};Number of jets",50,-1,1 ),
218 hdef('erhResponseVsEta', "Jet p_{T} Response vs #eta;#eta of jet;#frac{p_{T}^{Jet} - p_{T}^{Truth}}{p_{T}^{Truth}}",50,-5,5 ),
219 hdef('erhResponseVsPt', "Jet p_{T} Response vs p_{T};p_{T}^{Truth} of jet;#frac{p_{T}^{Jet} - p_{T}^{Truth}}{p_{T}^{Truth}}",50,0,1000 ),
220
221 hdef('erhResponse_noShift', "Jet p_{T} Response;#frac{p_{T}^{Jet}}{p_{T}^{Truth}};Number of jets",50,0,2 ),
222 hdef('erhResponseVsEta_noShift', "Jet p_{T} Response vs #eta;#eta of jet;#frac{p_{T}^{Jet}}{p_{T}^{Truth}}",50,-5,5 ),
223 hdef('erhResponseVsPt_noShift', "Jet p_{T} Response vs p_{T};p_{T}^{Truth} of jet;#frac{p_{T}^{Jet}}{p_{T}^{Truth}}",50,0,1000 ),
224
225 hdef('erhDeltaR', "#DeltaR between Jet and closest Truth Jet;#DeltaR;Number of jets",50,0,4 ),
226
227 ]
228 ) )
229
230# Selection tools
231jhm.addTool( HistosForJetSelection("alljets", SelectionType=0) )
232jhm.addTool( HistosForJetSelection("leadingjet", SelectionType=1) )
233jhm.addTool( HistosForJetSelection("subleadingjet", SelectionType=2) )
234
235
236
237
238
239
240#**************************************
241#**************************************
242# a helper function to combine selection with histo tools.
243def selectionAndHistos( selectType, histos, selectionName="", histoNameSuffix="",**otherArgs):
244
245 if isinstance(selectType, str):
246 # interpret selectType as a string. For ex "20000<pt<500000" or "subleadingjet"
247 tool = jhm.tool(selectType)
248 if issubclass( tool.__class__ , HistosForJetSelection):
249 # we're done.
250 selTool = tool
251 else:
252 # assume we have or need an attribute selector
253 attSel = tool
254 if tool is None:
255 attSel = attributeHistoManager.addSelector(selectType)
256 # and we rebuild a HistosForJetSelection in any case.
257 if histoNameSuffix=="" : histoNameSuffix = attSel.getName()
258 selTool = HistosForJetSelection("hjsel_"+attSel.getName(), SelectionType=3,
259 JetSelectorTool = attSel ,
260 HistoTitleSuffix = ' ('+selectType+')',
261 HistoNameSuffix = histoNameSuffix)
262 else:
263 selTool = selectType
264
265 if selTool is None :
266 print ("ERROR can't build histo tool for a jet selection. Uknown or wrong selection request :",selectType , selTool)
267 return None
268
269 if selectionName != "":
270 selTool = selTool.clone(selectionName)
271
272 interpretedTools = []
273 for h in histos:
274 if isinstance(h,str):
275 h = jhm.tool(h)
276 interpretedTools.append(h)
277
278 selTool.HistoTools = interpretedTools
279
280 # set other args if any:
281 for k,v in otherArgs.items():
282 setattr(selTool, k, v)
283 return selTool
284
285
286
287
Fills a list of histograms on a selected subset of a JetContainer.
A tool producing basic jet kinematics histogramms.
selectionAndHistos(selectType, histos, selectionName="", histoNameSuffix="", **otherArgs)