ATLAS Offline Software
Loading...
Searching...
No Matches
testResolution.cxx File Reference

Go to the source code of this file.

Functions

void setJetKinematics (xAOD::Jet &jet, double pt, double eta, double phi, double mass)
int main (int argc, char *argv[])

Function Documentation

◆ main()

int main ( int argc,
char * argv[] )

Definition at line 50 of file testResolution.cxx.

51{
52 StatusCode::enableFailure();
54
55
56 if (argc != 7 && argc != 8)
57 {
58 printf("Expected arguments:\n");
59 printf("\t1. Output file (pdf)\n");
60 printf("\t2. Jet definition\n");
61 printf("\t3. MC type\n");
62 printf("\t4. Config file\n");
63 printf("\t5. Component name and variation\n");
64 printf("\t\tExample: \"FourVecResUnc,+1\"\n");
65 printf("\t6. IsData (\"true\" or \"false\")\n");
66 printf("\t7. Options (optional argument), semi-colon delimited, examples:\n");
67 printf("\t\tisDijet=false\n");
68 printf("\t\tisLargeR=false\n");
69 exit(1);
70 }
71 TString outFile = argv[1];
72 TString jetDef = argv[2];
73 TString mcType = argv[3];
74 TString config = argv[4];
75 TString component = argv[5];
76 TString isDataStr = argv[6];
77 if (argc == 8) optHelper.Initialize(jet::utils::vectorize<TString>(argv[7],";"));
78 else optHelper.Initialize(std::vector<TString>());
79
80 if (!outFile.EndsWith(".pdf"))
81 {
82 printf("Only pdf output files are currently supported\n");
83 exit(1);
84 }
85
86 if (jet::utils::vectorize<TString>(component,",").size() != 2)
87 {
88 printf("Bad component formatting, got \"%s\"\n",component.Data());
89 exit(1);
90 }
91 TString compName = jet::utils::vectorize<TString>(component,",").at(0);
92 float shift = atof(jet::utils::vectorize<TString>(component,",").at(1));
93
94 bool isData = false;
95 if (!isDataStr.CompareTo("true",TString::kIgnoreCase))
96 isData = true;
97 else if (!isDataStr.CompareTo("false",TString::kIgnoreCase))
98 isData = false;
99 else
100 {
101 printf("Unable to determine whether to configure for data or MC: %s\n",isDataStr.Data());
102 exit(1);
103 }
104
106 if (tool->setProperty("JetDefinition",jetDef.Data()).isFailure())
107 exit(1);
108 if (tool->setProperty("MCType",mcType.Data()).isFailure())
109 exit(1);
110 if (tool->setProperty("ConfigFile",config.Data()).isFailure())
111 exit(1);
112 if (tool->setProperty("IsData",isData).isFailure())
113 exit(1);
114 if (optHelper.GetPath() != "")
115 if (tool->setProperty("Path",optHelper.GetPath().Data()).isFailure())
116 exit(1);
117 if (tool->setScaleToGeV().isFailure())
118 exit(1);
119 if (tool->initialize().isFailure())
120 exit(1);
121
122
123 // Build a jet container and a jet for us to manipulate later
127 jets->setStore(new xAOD::JetAuxContainer());
128 jets->push_back(new xAOD::Jet());
129 xAOD::Jet* jet = jets->at(0);
130
131 // Build an EventInfo object for us to manipulate later
133 eInfos->setStore(new xAOD::EventInfoAuxContainer());
134 eInfos->push_back(new xAOD::EventInfo());
135 xAOD::EventInfo* eInfo = eInfos->at(0);
136
137 // Ensure that the specified component is a valid systematic
138 // This is a +1sigma variation
139 CP::SystematicVariation variation(Form("JET_%s",compName.Data()),shift);
140 if (!tool->isAffectedBySystematic(variation))
141 {
142 printf("The specified variation was not recognized: JET_%s\n",compName.Data());
143 exit(1);
144 }
146 syst.insert(variation);
147 if (tool->applySystematicVariation(syst) != StatusCode::SUCCESS)
148 {
149 printf("Failed to apply systematic variation\n");
150 exit(1);
151 }
152
153 // Get info on the variation
154 const size_t compIndex = tool->getComponentIndex("JET_"+compName);
155 const std::set<jet::CompScaleVar::TypeEnum> scaleVars = tool->getComponentScaleVars(compIndex);
156 const jet::CompScaleVar::TypeEnum scaleVar = scaleVars.size() == 1 ? *(scaleVars.begin()) : jet::CompScaleVar::UNKNOWN;
157 const jet::JetTopology::TypeEnum topology = tool->getComponentTopology(compIndex);
158
159 printf("Component is index %zu, with ScaleVar %s and topology %s\n",compIndex,jet::CompScaleVar::enumToString(scaleVar).Data(),jet::JetTopology::enumToString(topology).Data());
160
161 // Prepare the canvas
162 TCanvas canvas("canvas");
163 canvas.SetMargin(0.12,0.04,0.15,0.04);
164 canvas.SetFillStyle(4000);
165 canvas.SetFillColor(0);
166 canvas.SetFrameBorderMode(0);
167 canvas.cd();
168 canvas.Print(outFile+"[");
169
170
171 // Prepare to add labels
172 TLatex tex;
173 tex.SetNDC();
174 tex.SetTextFont(42);
175 tex.SetTextSize(0.04);
176
177
178 // Define the jet that we want to smear repeatedly
179 // Center the jet around pT of 1 TeV and mass of 100 GeV (easy numbers)
180 // eta_bins = [0.0,0.2,0.7,1.3,1.8,2.5,3.2,3.5,4.5]
181 const double pT = 1000;
182 const double mass = 100;
183 const double phi = 0;
184 const std::vector<double> etaVals = optHelper.GetFixedEtaVals();
185 const int numSmear = 100000;
186
187 for (const double eta : etaVals)
188 {
189 // Prepare a histogram to fill repeatedly as we smear the value
190 TH1D smearPt(Form("smearPt_eta%.2f",eta),"",100,500,1500);
191 TH1D smearMass(Form("smearMass_eta%.2f",eta),"",100,50,150);
192 smearPt.Sumw2();
193 smearMass.Sumw2();
194 smearPt.SetStats(0);
195 smearMass.SetStats(0);
196 smearPt.GetXaxis()->SetTitle("#it{p}_{T} [GeV]");
197 smearMass.GetXaxis()->SetTitle("#it{m} [GeV]");
198 smearPt.GetYaxis()->SetTitle("Number of events");
199 smearMass.GetYaxis()->SetTitle("Number of events");
200
201 // Now smear repeatedly from the same starting jet
202 for (int iSmear = 0; iSmear < numSmear; ++iSmear)
203 {
204 setJetKinematics(*jet,pT,eta,phi,mass);
205 if (tool->applyCorrection(*jet,*eInfo) != CP::CorrectionCode::Ok)
206 {
207 printf("Error while smearing, iteration %d\n",iSmear);
208 exit(1);
209 }
210 // Fill the histograms with the smeared jet
211 smearPt.Fill(jet->pt());
212 smearMass.Fill(jet->m());
213 }
214
215 // Get info on the expected values
216 setJetKinematics(*jet,pT,eta,phi,mass);
217 const double nomData = tool->getNominalResolutionData(*jet,scaleVar,topology);
218 const double nomMC = tool->getNominalResolutionMC(*jet,scaleVar,topology);
219 const double uncert = tool->getUncertainty(compIndex,*jet,*eInfo,scaleVar);
220
221 const double fullUncMC = jet::CompScaleVar::isRelResolutionType(scaleVar) ? nomMC * uncert : uncert;
222 const double fullUncData = jet::CompScaleVar::isRelResolutionType(scaleVar) ? nomData * uncert : uncert;
223 const double smearMC = sqrt(pow(nomMC + fabs(shift*fullUncMC),2) - pow(nomMC,2));
224 const double smearData = nomData != JESUNC_ERROR_CODE ? sqrt(pow(nomData + fabs(shift*fullUncData),2) - pow(nomData,2)) : 0;
225
226 // Fit a Gaussian
227 TF1 fitPt("fitPt","gaus");
228 smearPt.Fit(&fitPt,"E");
229 TF1 fitMass("fitMass","gaus");
230 smearMass.Fit(&fitMass,"E");
231
232 // Draw and print the plot
233 smearPt.Draw();
234 tex.DrawLatex(0.70,0.9,"Gaussian fit results");
235 tex.DrawLatex(0.70,0.85,Form("#mu = %.0f GeV",fitPt.GetParameter(1)));
236 tex.DrawLatex(0.70,0.80,Form("#sigma = %.1f GeV",fitPt.GetParameter(2)));
237 tex.DrawLatex(0.70,0.75,Form("#mu/#sigma = %.1f%%",fitPt.GetParameter(2)/fitPt.GetParameter(1)*100));
238 tex.DrawLatex(0.15,0.9,"Expectation from tool");
239 tex.DrawLatex(0.15,0.85,"#sigma_{smear}^{2} = (#sigma_{nom} + |N#delta#sigma|)^{2} - (#sigma_{nom})^{2}");
240 if (nomData != JESUNC_ERROR_CODE)
241 tex.DrawLatex(0.15,0.80,Form("#sigma_{nom}^{data}/#it{p}_{T} = %.1f%%",100*nomData));
242 else
243 tex.DrawLatex(0.15,0.80,Form("#sigma_{nom}^{data}/#it{p}_{T} = N/A"));
244 tex.DrawLatex(0.15,0.75,Form("#sigma_{nom}^{MC}/#it{p}_{T} = %.1f%%",100*nomMC));
245 tex.DrawLatex(0.15,0.70,Form("#delta#sigma/#it{p}_{T} = %.1f%%",100*uncert));
246 tex.DrawLatex(0.15,0.65,Form("N_{sigma} = %+.1f",shift));
247 if (nomData != JESUNC_ERROR_CODE)
248 tex.DrawLatex(0.15,0.55,Form("#sigma_{smear}^{data}/#it{p}_{T} = %.1f%%",100*smearData));
249 else
250 tex.DrawLatex(0.15,0.55,Form("#sigma_{smear}^{data}/#it{p}_{T} = N/A"));
251 tex.DrawLatex(0.15,0.50,Form("#sigma_{smear}^{MC}/#it{p}_{T} = %.1f%%",100*smearMC));
252 canvas.Print(outFile);
253
254
255
256 smearMass.Draw();
257 tex.DrawLatex(0.70,0.9,"Gaussian fit results");
258 tex.DrawLatex(0.70,0.85,Form("#mu = %.0f GeV",fitMass.GetParameter(1)));
259 tex.DrawLatex(0.70,0.80,Form("#sigma = %.1f GeV",fitMass.GetParameter(2)));
260 tex.DrawLatex(0.70,0.75,Form("#mu/#sigma = %.1f%%",fitMass.GetParameter(2)/fitMass.GetParameter(1)*100));
261 tex.DrawLatex(0.15,0.9,"Expectation from tool");
262 tex.DrawLatex(0.15,0.85,"#sigma_{smear}^{2} = (#sigma_{nom} + |N#delta#sigma|)^{2} - (#sigma_{nom})^{2}");
263 if (nomData != JESUNC_ERROR_CODE)
264 tex.DrawLatex(0.15,0.80,Form("#sigma_{nom}^{data}/#it{p}_{T} = %.1f%%",100*nomData));
265 else
266 tex.DrawLatex(0.15,0.80,Form("#sigma_{nom}^{data}/#it{p}_{T} = N/A"));
267 tex.DrawLatex(0.15,0.75,Form("#sigma_{nom}^{MC}/#it{p}_{T} = %.1f%%",100*nomMC));
268 tex.DrawLatex(0.15,0.70,Form("#delta#sigma/#it{p}_{T} = %.1f%%",100*uncert));
269 tex.DrawLatex(0.15,0.65,Form("N_{sigma} = %+.1f",shift));
270 if (nomData != JESUNC_ERROR_CODE)
271 tex.DrawLatex(0.15,0.55,Form("#sigma_{smear}^{data}/#it{p}_{T} = %.1f%%",100*smearData));
272 else
273 tex.DrawLatex(0.15,0.55,Form("#sigma_{smear}^{data}/#it{p}_{T} = N/A"));
274 tex.DrawLatex(0.15,0.50,Form("#sigma_{smear}^{MC}/#it{p}_{T} = %.1f%%",100*smearMC));
275 canvas.Print(outFile);
276 }
277
278 // Done printing
279 canvas.Print(outFile+"]");
280
281 return 0;
282}
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
@ Data
Definition BaseObject.h:11
jet::OptionHelper optHelper
constexpr int pow(int base, int exp) noexcept
@ Ok
The correction was done successfully.
Class to wrap a set of SystematicVariations.
void insert(const SystematicVariation &systematic)
description: insert a systematic into the set
const T * at(size_type n) const
Access an element, as an rvalue.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
Tool for accessing xAOD files outside of Athena.
A relatively simple transient store for objects created in analysis.
Definition TStore.h:45
double atof(std::string_view str)
Converts a string into a double / float.
outFile
Comment Out Those You do not wish to run.
TestStore store
Definition TestStore.cxx:23
bool isRelResolutionType(const TypeEnum type)
TString enumToString(const TypeEnum type)
TString enumToString(const TypeEnum type)
bool vectorize(const TString &str, const TString &sep, std::vector< T > &result)
Jet_v1 Jet
Definition of the current "jet version".
EventInfoContainer_v1 EventInfoContainer
Define the latest version of the container.
EventInfo_v1 EventInfo
Definition of the latest event info version.
EventInfoAuxContainer_v1 EventInfoAuxContainer
Define the latest version of the auxiliary container.
JetAuxContainer_v1 JetAuxContainer
Definition of the current jet auxiliary container.
JetContainer_v1 JetContainer
Definition of the current "jet container version".
void setJetKinematics(xAOD::Jet &jet, double pt, double eta, double phi, double mass)

◆ setJetKinematics()

void setJetKinematics ( xAOD::Jet & jet,
double pt,
double eta,
double phi,
double mass )

Definition at line 32 of file testResolution.cxx.

33{
40
41 jet.setJetP4( xAOD::JetFourMom_t(pt,eta,phi,mass));
42 scaleCalo.setAttribute( jet, xAOD::JetFourMom_t(pt,eta,phi,mass));
43 scaleTA.setAttribute( jet, xAOD::JetFourMom_t(pt,eta,phi,mass));
44 scaleCombQCD.setAttribute(jet, xAOD::JetFourMom_t(pt,eta,phi,mass));
45 scaleCombWZ.setAttribute( jet, xAOD::JetFourMom_t(pt,eta,phi,mass));
46 scaleCombHbb.setAttribute(jet, xAOD::JetFourMom_t(pt,eta,phi,mass));
47 scaleCombTop.setAttribute(jet, xAOD::JetFourMom_t(pt,eta,phi,mass));
48}
JetFourMomAccessor is an extension of JetAttributeAccessor::AccessorWrapper<xAOD::JetFourMom_t> Acces...
TString getJetScaleString(const TypeEnum type)
ROOT::Math::LorentzVector< ROOT::Math::PtEtaPhiM4D< double > > JetFourMom_t
Base 4 Momentum type for Jet.
Definition JetTypes.h:17