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