ATLAS Offline Software
Loading...
Searching...
No Matches
ConfigurableAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4// BaseTOBoAlg.cpp
5// TopoCore
6// Created by Joerg Stelzer on 11/10/12.
7
11// Bitwise implementation utils
16
17#include "TH1.h"
18#include "TH2.h"
19#include <iostream>
20#include <sstream>
21
22using namespace TCS;
23
24
30public:
31 ConfigurableAlgImpl(const std::string & name) :
33 {}
34
36 for( auto h : m_localHistStore )
37 delete h;
38 }
39
40 void setL1TopoHistSvc(std::shared_ptr<IL1TopoHistSvc> histSvc) {
41 m_histSvc = std::move(histSvc);
42 }
43
44 void registerHist(TH1 * h) {
45 // histograms in the L1Topo framework are put in a algorithm specific folder
46 std::string newHistName = m_name + "/" + h->GetName();
47 h->SetName(newHistName.c_str());
48
49 if( m_histSvc ) {
50 m_histSvc->registerHist(h);
51 } else {
52 m_localHistStore.push_back(h);
53 }
54 }
55
56 void registerHist(TH2 * h) {
57 // histograms in the L1Topo framework are put in a algorithm specific folder
58 std::string newHistName = m_name + "/" + h->GetName();
59 h->SetName(newHistName.c_str());
60
61 if( m_histSvc ) {
62 m_histSvc->registerHist(h);
63 } else {
64 m_localHistStore.push_back(h);
65 }
66 }
67
68 void fillHist1D(const std::string & histName, double x) {
69 if ( m_histSvc ) {
70 m_histSvc->fillHist1D(histName,x);
71 } else {
72 //Implement here to fill local histograms or something.
73 return;
74 }
75 }
76
77
78 void fillHist2D(const std::string & histName, double x, double y) {
79 if ( m_histSvc ) {
80 m_histSvc->fillHist2D(histName,x,y);
81 } else {
82 //Implement here to fill local histograms or something.
83 return;
84 }
85 }
86
87
88private:
89
90 std::string m_name;
91
92 // histogram service
93 std::shared_ptr<IL1TopoHistSvc> m_histSvc;
94
95 // store histograms locally if no hist service is available
96 std::vector<TH1 *> m_localHistStore;
97
98};
99
100
101
102
103
104
105ConfigurableAlg::ConfigurableAlg(const std::string & name, AlgType algType) :
108 m_name(name),
110 m_algType(algType),
111 m_isLegacyTopo(false)
112{}
113
114
117
118// Kinematic Calculation
119unsigned int
121 if (m_isLegacyTopo)
122 {return TSU::Kinematics::calcDeltaPhiBWLegacy(tob1,tob2);}
123 else
124 {return TSU::Kinematics::calcDeltaPhiBW(tob1,tob2);}
125}
126
127unsigned int
129 if (m_isLegacyTopo)
130 {return TSU::Kinematics::calcDeltaEtaBWLegacy(tob1,tob2);}
131 else
132 {return TSU::Kinematics::calcDeltaEtaBW(tob1,tob2);}
133}
134
135unsigned int
137 if (m_isLegacyTopo)
138 {return TSU::Kinematics::calcInvMassBWLegacy(tob1,tob2);}
139 else
140 {return TSU::Kinematics::calcInvMassBW(tob1,tob2);}
141}
142
143unsigned int
145 if (m_isLegacyTopo)
146 {return TSU::Kinematics::calcTMassBWLegacy(tob1,tob2);}
147 else
148 {return TSU::Kinematics::calcTMassBW(tob1,tob2);}
149}
150
151unsigned int
153 if (m_isLegacyTopo)
154 {return TSU::Kinematics::calcDeltaR2BWLegacy(tob1,tob2);}
155 else
156 {return TSU::Kinematics::calcDeltaR2BW(tob1,tob2);}
157}
158
159unsigned long
161 return TSU::Kinematics::quadraticSumBW(i1, i2);
162}
163
164unsigned int
166 if (m_isLegacyTopo)
167 {return TSU::Kinematics::calcDeltaPhiLegacy(tob1,tob2);}
168 else
169 {return TSU::Kinematics::calcDeltaPhi(tob1,tob2);}
170}
171
172unsigned int
174 if (m_isLegacyTopo)
175 {return TSU::Kinematics::calcDeltaEtaLegacy(tob1,tob2);}
176 else
177 {return TSU::Kinematics::calcDeltaEta(tob1,tob2);}
178}
179
180unsigned int
182 return TSU::Kinematics::calcInvMass(tob1,tob2);
183}
184
185unsigned int
187 return TSU::Kinematics::calcTMass(tob1,tob2);
188}
189
190unsigned int
192 if (m_isLegacyTopo)
193 {return TSU::Kinematics::calcDeltaR2Legacy(tob1,tob2);}
194 else
195 {return TSU::Kinematics::calcDeltaR2(tob1,tob2);}
196}
197
198
199// define parameters to be called by developer
200void
202 defineParameter( Parameter(name, value) );
203}
204
205
206void
207ConfigurableAlg::defineParameter(const std::string & name, TCS::parType_t value, unsigned int selection) {
209}
210
211
212void
214 if( parameters().contains( parameter.name(), parameter.selection() ) ) {
215 TCS_EXCEPTION("Duplicate parameter definition '" << parameter.name() << "' for algorithm '" << name() << "'");
216 }
217 m_parameters.addParameter(parameter);
218}
219
220
221void
223
224 // check if parameterspace is for this algorithm
225 if(name() != parameters.algName()) {
226 TCS_EXCEPTION("Name of parameter set (" << parameters.algName() << ") do not match configurable name (" << name() << ")" );
227 }
228
229 // copy parameters
230 for(const Parameter & p : parameters) {
231 try {
232 m_parameters.setParameter(p);
233 }
234 catch(const TCS::Exception& e) {
235 TCS_EXCEPTION("Algorithm configuration failed for " << name() << "! Caught exception: " << e.what());
236 }
237 }
238}
239
240
241
242const TCS::Parameter &
243ConfigurableAlg::parameter(const std::string & parameterName) const {
244 return parameters().parameter(parameterName);
245}
246
247
248const TCS::Parameter &
249ConfigurableAlg::parameter(const std::string & parameterName, unsigned int selection) const {
250 return parameters().parameter(parameterName, selection);
251}
252
253
257
258void ConfigurableAlg::setL1TopoHistSvc(std::shared_ptr<IL1TopoHistSvc> histSvc) {
259 m_impl->setL1TopoHistSvc(std::move(histSvc));
260}
261
263 m_impl->registerHist(h);
264}
265
267 m_impl->registerHist(h);
268}
269
270void ConfigurableAlg::bookHist(std::vector<std::string> &regName, const std::string& name, const std::string& title, const int binx, const int xmin, const int xmax) {
271 std::string xmin_str = ToString(xmin);
272 std::string xmax_str = ToString(xmax);
273 std::string newTitle = title;
274 std::string newName = name;
275
276 newTitle = xmin_str+title+xmax_str;
277 newName = name+"_"+xmin_str+title+xmax_str;
278 std::replace( newName.begin(), newName.end(), '-', 'n');
279 std::replace( newName.begin(), newName.end(), ' ', '_');
280
281 regName.push_back(m_name+"/"+newName);
282
283 // Add units to axis labels
284 std::string xTitle = title;
285 if (m_isLegacyTopo) {
286 if (title == "ETA" || title == "DETA" || title == "PHI" || title == "DPHI" || title == "DR") { xTitle = title+"#times10"; }
287 if (title == "PT" || title == "ET" || title == "HT" || title == "INVM" || title == "MT") { xTitle = title+" [GeV]"; }
288 }
289 else {
290 if (title == "ETA" || title == "DETA" || title == "DR") { xTitle = title+"#times40"; }
291 if (title == "PHI" || title == "DPHI") { xTitle = title+"#times20"; }
292 if (title == "PT" || title == "ET" || title == "HT" || title == "INVM" || title == "MT") { xTitle = title+" [100 MeV]"; }
293 }
294
295 int xmin_new,xmax_new,binx_new=binx;
296 if ( xmin > 0.0)
297 { xmin_new=0.0; }
298 else
299 { xmin_new=1.5*xmin; }
300
301 // if the maximum inv. mass cut defined by the menu over 4000 MeV,
302 // set x-axis range maximum to 4000 MeV. This is only for legacy triggers,
303 // phase1 does not exceed this limit- asonay 08/2022
304 if (xmax > 4000 && m_isLegacyTopo) {
305 xmax_new = 4000;
306 binx_new = 200;
307 }
308 else {xmax_new = 1.5*xmax;}
309
310 // if angular kinematics, use fixed range
311 int eta_max = 50;
312 int phi_max = 64;
313 int dr_max = 30;
314 if (not m_isLegacyTopo) {
315 eta_max *= 4;
316 phi_max *= 2;
317 dr_max *= 4;
318 }
319
320 if ( title.find("ETA") != std::string::npos ){
321 xmin_new=-eta_max;
322 xmax_new=eta_max;
323 }
324 if ( title.find("PHI") != std::string::npos || title.find("DPHI") != std::string::npos ){
325 xmin_new=0;
326 xmax_new=phi_max;
327 }
328 if ( title.find("DETA") != std::string::npos || title.find("DR") != std::string::npos ){
329 xmin_new=0;
330 xmax_new=dr_max;
331 }
332
333 TH1 *h = new TH1F(newName.c_str(), newTitle.c_str(), binx_new, xmin_new, xmax_new);
334 h->GetXaxis()->SetTitle(xTitle.c_str());
335 m_impl->registerHist(h);
336}
337
338void ConfigurableAlg::bookHistMult(std::vector<std::string> &regName, const std::string& name, const std::string& title, const std::string& xtitle, const int binx, const int xmin, const int xmax) {
339
340 regName.push_back(m_name+"/"+name);
341
342 TH1 *h = new TH1F(name.c_str(), title.c_str(), binx, xmin, xmax);
343 h->GetXaxis()->SetTitle(xtitle.c_str());
344 m_impl->registerHist(h);
345}
346
347void ConfigurableAlg::bookHist(std::vector<std::string> &regName, const std::string& name, const std::string& title, const int binx, const int xmin, const int xmax, const int biny, const int ymin, const int ymax) {
348 auto usPos = title.find(" vs ");
349 std::string xName = title.substr(0,usPos);
350 std::string yName = title.substr(usPos+4);
351 std::string xmin_str = ToString(xmin);
352 std::string xmax_str = ToString(xmax);
353 std::string ymin_str = ToString(ymin);
354 std::string ymax_str = ToString(ymax);
355 std::string newTitle = title;
356 std::string newName = name;
357
358 newTitle = xmin_str+xName+xmax_str+" vs "+ymin_str+yName+ymax_str;
359 newName = name+"_"+xmin_str+xName+xmax_str+"_"+ymin_str+yName+ymax_str;
360 std::replace( newName.begin(), newName.end(), '-', 'n');
361 std::replace( newName.begin(), newName.end(), ' ', '_');
362
363 regName.push_back(m_name+"/"+newName);
364
365 // Add units to axis labels
366 std::string xTitle = xName;
367 std::string yTitle = yName;
368 if (m_isLegacyTopo) {
369 if (xName == "ETA" || xName == "DETA" || xName == "PHI" || xName == "DPHI" || xName == "DR") { xTitle = xName+"#times10"; }
370 if (xName == "PT" || xName == "ET" || xName == "HT" || xName == "INVM" || xName == "MT") { xTitle = xName+" [GeV]"; }
371
372 if (yName == "ETA" || yName == "DETA" || yName == "PHI" || yName == "DPHI" || yName == "DR") { yTitle = yName+"#times10"; }
373 if (yName == "PT" || yName == "ET" || yName == "HT" || yName == "INVM" || yName == "MT") { yTitle = yName+" [GeV]"; }
374 }
375 else {
376 if (xName == "ETA" || xName == "DETA" || xName == "DR") { xTitle = xName+"#times40"; }
377 if (xName == "PHI" || xName == "DPHI") { xTitle = xName+"#times20"; }
378 if (xName == "PT" || xName == "ET" || xName == "HT" || xName == "INVM" || xName == "MT") { xTitle = xName+" [100 MeV]"; }
379
380 if (yName == "ETA" || yName == "DETA" || yName == "DR") { yTitle = yName+"#times40"; }
381 if (yName == "PHI" || yName == "DPHI") { yTitle = yName+"#times20"; }
382 if (yName == "PT" || yName == "ET" || yName == "HT" || yName == "INVM" || yName == "MT") { yTitle = yName+" [100 MeV]"; }
383 }
384
385 int xmin_new,xmax_new,binx_new=binx;
386 if ( xmin > 0.0)
387 { xmin_new=0.0; }
388 else
389 { xmin_new=1.5*xmin; }
390
391 // if the maximum inv. mass cut defined by the menu over 4000 MeV,
392 // set x-axis range maximum to 4000 MeV. This is only for legacy triggers,
393 // phase1 does not exceed this limit- asonay 08/2022
394 if (xmax > 4000 && m_isLegacyTopo) {
395 xmax_new = 4000;
396 binx_new = 200;
397 }
398 else {xmax_new = 1.5*xmax;}
399
400 int ymin_new,ymax_new,biny_new=biny;
401 if ( ymin > 0.0)
402 { ymin_new=0.0; }
403 else
404 { ymin_new=1.5*ymin; }
405
406 // if the maximum inv. mass cut defined by the menu over 4000 MeV,
407 // set y-axis range maximum to 4000 MeV. This is only for legacy triggers,
408 // phase1 does not exceed this limit- asonay 08/2022
409 if (ymax > 4000 && m_isLegacyTopo) {
410 ymax_new = 4000;
411 biny_new = 200;
412 }
413 else {ymax_new = 1.5*ymax;}
414
415
416 // if angular kinematics, use fixed range
417 int eta_max = 50;
418 int phi_max = 64;
419 int dr_max = 30;
420 if (not m_isLegacyTopo) {
421 eta_max *= 4;
422 phi_max *= 2;
423 dr_max *= 4;
424 }
425
426 if ( xName.find("ETA") != std::string::npos ){
427 xmin_new=-eta_max;
428 xmax_new=eta_max;
429 }
430 if ( yName.find("ETA") != std::string::npos ){
431 ymin_new=-eta_max;
432 ymax_new=eta_max;
433 }
434 if ( xName.find("PHI") != std::string::npos || xName.find("DPHI") != std::string::npos ){
435 xmin_new=0;
436 xmax_new=phi_max;
437 }
438 if ( yName.find("PHI") != std::string::npos || yName.find("DPHI") != std::string::npos ){
439 ymin_new=0;
440 ymax_new=phi_max;
441 }
442 if ( xName.find("DETA") != std::string::npos || xName.find("DR") != std::string::npos ){
443 xmin_new=0;
444 xmax_new=dr_max;
445 }
446 if ( yName.find("DETA") != std::string::npos || yName.find("DR") != std::string::npos ){
447 ymin_new=0;
448 ymax_new=dr_max;
449 }
450
451 TH2 *h = new TH2F(newName.c_str(), newTitle.c_str(), binx_new, xmin_new, xmax_new, biny_new, ymin_new, ymax_new);
452 h->GetXaxis()->SetTitle(xTitle.c_str());
453 h->GetYaxis()->SetTitle(yTitle.c_str());
454 m_impl->registerHist(h);
455}
456
457 void ConfigurableAlg::bookHistMult(std::vector<std::string> &regName, const std::string& name, const std::string& title, const std::string& xtitle, const std::string& ytitle, const int binx, const int xmin, const int xmax, const int biny, const int ymin, const int ymax) {
458
459 regName.push_back(m_name+"/"+name);
460
461 TH2 *h = new TH2F(name.c_str(), title.c_str(), binx, xmin, xmax, biny, ymin, ymax);
462 h->GetXaxis()->SetTitle(xtitle.c_str());
463 h->GetYaxis()->SetTitle(ytitle.c_str());
464 m_impl->registerHist(h);
465}
466
467void ConfigurableAlg::fillHist1D(const std::string & histName, double x) {
468 m_impl->fillHist1D(histName,x);
469}
470
471void ConfigurableAlg::fillHist2D(const std::string & histName, double x, double y) {
472 m_impl->fillHist2D(histName,x,y);
473}
474
475std::string ConfigurableAlg::ToString(const int val)
476{
477 const int val_int = static_cast<int>(val);
478 std::ostringstream temp;
479 temp << val_int;
480 return temp.str();
481}
482
483bool
484ConfigurableAlg::isocut(const std::string& threshold, const unsigned int bit) const {
485 unsigned int value = 0;
486 if (threshold == "None") {value = 0;}
487 else if (threshold == "Loose") {value = 1;}
488 else if (threshold == "Medium") {value = 2;}
489 else if (threshold == "HadMedium") {value = 2;}
490 else if (threshold == "Tight") {value = 3;}
491 else {
492 TRG_MSG_WARNING("No isolation defined as " << threshold);
493 }
494
495 if (bit >= value) {return true;}
496 else {return false;}
497}
498
499bool
500ConfigurableAlg::isocut(const unsigned int threshold, const unsigned int bit) const {
501 if (bit >= threshold) {return true;}
502 else {return false;}
503}
504
505namespace TCS {
506
507 std::ostream &
508 operator<<(std::ostream & o, const TCS::ConfigurableAlg & alg) {
509
510 o << "algorithm '" << alg.fullname() << "'" << std::endl;
511 o << alg.parameters();
512 return o;
513
514 }
515
516}
#define y
#define x
void fillHist2D(const std::string &histName, double x, double y)
void fillHist1D(const std::string &histName, double x)
std::shared_ptr< IL1TopoHistSvc > m_histSvc
void setL1TopoHistSvc(std::shared_ptr< IL1TopoHistSvc > histSvc)
const ParameterSpace & parameters() const
ConfigurableAlg(const std::string &name, AlgType algType)
const Parameter & parameter(const std::string &parameterName) const
unsigned int calcTMass(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
const std::string & name() const
bool isocut(const std::string &threshold, const unsigned int bit) const
void bookHist(std::vector< std::string > &regName, const std::string &name, const std::string &title, const int binx, const int xmin, const int xmax)
void fillHist1D(const std::string &histName, double x)
unsigned int calcDeltaR2BW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
unsigned int calcDeltaPhiBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
void setL1TopoHistSvc(std::shared_ptr< IL1TopoHistSvc >)
sets the external hist service
unsigned int calcInvMassBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
unsigned long quadraticSumBW(int i1, int i2)
unsigned int calcDeltaEta(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
std::string ToString(const int val)
void setParameters(const ParameterSpace &)
std::unique_ptr< ConfigurableAlgImpl > m_impl
void bookHistMult(std::vector< std::string > &regName, const std::string &name, const std::string &title, const std::string &xtitle, const int binx, const int xmin, const int xmax)
ParameterSpace m_parameters
unsigned int calcDeltaEtaBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
void defineParameter(const std::string &name, TCS::parType_t value)
unsigned int calcDeltaR2(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
unsigned int calcTMassBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
unsigned int calcDeltaPhi(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
unsigned int calcInvMass(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
void fillHist2D(const std::string &histName, double x, double y)
const Parameter & parameter(const std::string &parameterName) const
TrigConfMessaging(const std::string &name)
Constructor with parameters.
const std::string selection
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
double xmax
Definition listroot.cxx:61
double ymin
Definition listroot.cxx:63
double xmin
Definition listroot.cxx:60
double ymax
Definition listroot.cxx:64
std::ostream & operator<<(std::ostream &os, const TCS::Bin &bin)
uint32_t parType_t
Definition Parameter.h:22
static unsigned int calcDeltaEtaBWLegacy(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcDeltaEtaBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcTMass(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcDeltaR2Legacy(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcInvMassBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcDeltaPhiBWLegacy(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcDeltaPhi(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcDeltaPhiLegacy(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcDeltaEta(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcInvMass(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcDeltaR2BW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcTMassBWLegacy(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcDeltaPhiBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcTMassBW(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcDeltaEtaLegacy(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcInvMassBWLegacy(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned long quadraticSumBW(int i1, int i2)
compute the sum in quadrature of two ints
static unsigned int calcDeltaR2(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)
static unsigned int calcDeltaR2BWLegacy(const TCS::GenericTOB *tob1, const TCS::GenericTOB *tob2)