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 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
204 defineParameter( Parameter(name, value) );
205}
206
207
208void
209ConfigurableAlg::defineParameter(const std::string & 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(const std::string & parameterName) const {
246 return parameters().parameter(parameterName);
247}
248
249
250const TCS::Parameter &
251ConfigurableAlg::parameter(const std::string & 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, const std::string& name, const std::string& 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 newTitle = xmin_str+title+xmax_str;
279 newName = name+"_"+xmin_str+title+xmax_str;
280 std::replace( newName.begin(), newName.end(), '-', 'n');
281 std::replace( newName.begin(), newName.end(), ' ', '_');
282
283 regName.push_back(m_name+"/"+newName);
284
285 // Add units to axis labels
286 std::string xTitle = title;
287 if (m_isLegacyTopo) {
288 if (title == "ETA" || title == "DETA" || title == "PHI" || title == "DPHI" || title == "DR") { xTitle = title+"#times10"; }
289 if (title == "PT" || title == "ET" || title == "HT" || title == "INVM" || title == "MT") { xTitle = title+" [GeV]"; }
290 }
291 else {
292 if (title == "ETA" || title == "DETA" || title == "DR") { xTitle = title+"#times40"; }
293 if (title == "PHI" || title == "DPHI") { xTitle = title+"#times20"; }
294 if (title == "PT" || title == "ET" || title == "HT" || title == "INVM" || title == "MT") { xTitle = title+" [100 MeV]"; }
295 }
296
297 int xmin_new,xmax_new,binx_new=binx;
298 if ( xmin > 0.0)
299 { xmin_new=0.0; }
300 else
301 { xmin_new=1.5*xmin; }
302
303 // if the maximum inv. mass cut defined by the menu over 4000 MeV,
304 // set x-axis range maximum to 4000 MeV. This is only for legacy triggers,
305 // phase1 does not exceed this limit- asonay 08/2022
306 if (xmax > 4000 && m_isLegacyTopo) {
307 xmax_new = 4000;
308 binx_new = 200;
309 }
310 else {xmax_new = 1.5*xmax;}
311
312 // if angular kinematics, use fixed range
313 int eta_max = 50;
314 int phi_max = 64;
315 int dr_max = 30;
316 if (not m_isLegacyTopo) {
317 eta_max *= 4;
318 phi_max *= 2;
319 dr_max *= 4;
320 }
321
322 if ( title.find("ETA") != std::string::npos ){
323 xmin_new=-eta_max;
324 xmax_new=eta_max;
325 }
326 if ( title.find("PHI") != std::string::npos || title.find("DPHI") != std::string::npos ){
327 xmin_new=0;
328 xmax_new=phi_max;
329 }
330 if ( title.find("DETA") != std::string::npos || title.find("DR") != std::string::npos ){
331 xmin_new=0;
332 xmax_new=dr_max;
333 }
334
335 TH1 *h = new TH1F(newName.c_str(), newTitle.c_str(), binx_new, xmin_new, xmax_new);
336 h->GetXaxis()->SetTitle(xTitle.c_str());
337 m_impl->registerHist(h);
338}
339
340void 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) {
341
342 regName.push_back(m_name+"/"+name);
343
344 TH1 *h = new TH1F(name.c_str(), title.c_str(), binx, xmin, xmax);
345 h->GetXaxis()->SetTitle(xtitle.c_str());
346 m_impl->registerHist(h);
347}
348
349void 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) {
350 auto usPos = title.find(" vs ");
351 std::string xName = title.substr(0,usPos);
352 std::string yName = title.substr(usPos+4);
353 std::string xmin_str = ToString(xmin);
354 std::string xmax_str = ToString(xmax);
355 std::string ymin_str = ToString(ymin);
356 std::string ymax_str = ToString(ymax);
357 std::string newTitle = title;
358 std::string newName = name;
359
360 newTitle = xmin_str+xName+xmax_str+" vs "+ymin_str+yName+ymax_str;
361 newName = name+"_"+xmin_str+xName+xmax_str+"_"+ymin_str+yName+ymax_str;
362 std::replace( newName.begin(), newName.end(), '-', 'n');
363 std::replace( newName.begin(), newName.end(), ' ', '_');
364
365 regName.push_back(m_name+"/"+newName);
366
367 // Add units to axis labels
368 std::string xTitle = xName;
369 std::string yTitle = yName;
370 if (m_isLegacyTopo) {
371 if (xName == "ETA" || xName == "DETA" || xName == "PHI" || xName == "DPHI" || xName == "DR") { xTitle = xName+"#times10"; }
372 if (xName == "PT" || xName == "ET" || xName == "HT" || xName == "INVM" || xName == "MT") { xTitle = xName+" [GeV]"; }
373
374 if (yName == "ETA" || yName == "DETA" || yName == "PHI" || yName == "DPHI" || yName == "DR") { yTitle = yName+"#times10"; }
375 if (yName == "PT" || yName == "ET" || yName == "HT" || yName == "INVM" || yName == "MT") { yTitle = yName+" [GeV]"; }
376 }
377 else {
378 if (xName == "ETA" || xName == "DETA" || xName == "DR") { xTitle = xName+"#times40"; }
379 if (xName == "PHI" || xName == "DPHI") { xTitle = xName+"#times20"; }
380 if (xName == "PT" || xName == "ET" || xName == "HT" || xName == "INVM" || xName == "MT") { xTitle = xName+" [100 MeV]"; }
381
382 if (yName == "ETA" || yName == "DETA" || yName == "DR") { yTitle = yName+"#times40"; }
383 if (yName == "PHI" || yName == "DPHI") { yTitle = yName+"#times20"; }
384 if (yName == "PT" || yName == "ET" || yName == "HT" || yName == "INVM" || yName == "MT") { yTitle = yName+" [100 MeV]"; }
385 }
386
387 int xmin_new,xmax_new,binx_new=binx;
388 if ( xmin > 0.0)
389 { xmin_new=0.0; }
390 else
391 { xmin_new=1.5*xmin; }
392
393 // if the maximum inv. mass cut defined by the menu over 4000 MeV,
394 // set x-axis range maximum to 4000 MeV. This is only for legacy triggers,
395 // phase1 does not exceed this limit- asonay 08/2022
396 if (xmax > 4000 && m_isLegacyTopo) {
397 xmax_new = 4000;
398 binx_new = 200;
399 }
400 else {xmax_new = 1.5*xmax;}
401
402 int ymin_new,ymax_new,biny_new=biny;
403 if ( ymin > 0.0)
404 { ymin_new=0.0; }
405 else
406 { ymin_new=1.5*ymin; }
407
408 // if the maximum inv. mass cut defined by the menu over 4000 MeV,
409 // set y-axis range maximum to 4000 MeV. This is only for legacy triggers,
410 // phase1 does not exceed this limit- asonay 08/2022
411 if (ymax > 4000 && m_isLegacyTopo) {
412 ymax_new = 4000;
413 biny_new = 200;
414 }
415 else {ymax_new = 1.5*ymax;}
416
417
418 // if angular kinematics, use fixed range
419 int eta_max = 50;
420 int phi_max = 64;
421 int dr_max = 30;
422 if (not m_isLegacyTopo) {
423 eta_max *= 4;
424 phi_max *= 2;
425 dr_max *= 4;
426 }
427
428 if ( xName.find("ETA") != std::string::npos ){
429 xmin_new=-eta_max;
430 xmax_new=eta_max;
431 }
432 if ( yName.find("ETA") != std::string::npos ){
433 ymin_new=-eta_max;
434 ymax_new=eta_max;
435 }
436 if ( xName.find("PHI") != std::string::npos || xName.find("DPHI") != std::string::npos ){
437 xmin_new=0;
438 xmax_new=phi_max;
439 }
440 if ( yName.find("PHI") != std::string::npos || yName.find("DPHI") != std::string::npos ){
441 ymin_new=0;
442 ymax_new=phi_max;
443 }
444 if ( xName.find("DETA") != std::string::npos || xName.find("DR") != std::string::npos ){
445 xmin_new=0;
446 xmax_new=dr_max;
447 }
448 if ( yName.find("DETA") != std::string::npos || yName.find("DR") != std::string::npos ){
449 ymin_new=0;
450 ymax_new=dr_max;
451 }
452
453 TH2 *h = new TH2F(newName.c_str(), newTitle.c_str(), binx_new, xmin_new, xmax_new, biny_new, ymin_new, ymax_new);
454 h->GetXaxis()->SetTitle(xTitle.c_str());
455 h->GetYaxis()->SetTitle(yTitle.c_str());
456 m_impl->registerHist(h);
457}
458
459 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) {
460
461 regName.push_back(m_name+"/"+name);
462
463 TH2 *h = new TH2F(name.c_str(), title.c_str(), binx, xmin, xmax, biny, ymin, ymax);
464 h->GetXaxis()->SetTitle(xtitle.c_str());
465 h->GetYaxis()->SetTitle(ytitle.c_str());
466 m_impl->registerHist(h);
467}
468
469void ConfigurableAlg::fillHist1D(const std::string & histName, double x) {
470 m_impl->fillHist1D(histName,x);
471}
472
473void ConfigurableAlg::fillHist2D(const std::string & histName, double x, double y) {
474 m_impl->fillHist2D(histName,x,y);
475}
476
477std::string ConfigurableAlg::ToString(const int val)
478{
479 const int val_int = static_cast<int>(val);
480 std::ostringstream temp;
481 temp << val_int;
482 return temp.str();
483}
484
485bool
486ConfigurableAlg::isocut(const std::string& threshold, const unsigned int bit) const {
487 unsigned int value = 0;
488 if (threshold == "None") {value = 0;}
489 else if (threshold == "Loose") {value = 1;}
490 else if (threshold == "Medium") {value = 2;}
491 else if (threshold == "HadMedium") {value = 2;}
492 else if (threshold == "Tight") {value = 3;}
493 else {
494 TRG_MSG_WARNING("No isolation defined as " << threshold);
495 }
496
497 if (bit >= value) {return true;}
498 else {return false;}
499}
500
501bool
502ConfigurableAlg::isocut(const unsigned int threshold, const unsigned int bit) const {
503 if (bit >= threshold) {return true;}
504 else {return false;}
505}
506
507namespace TCS {
508
509 std::ostream &
510 operator<<(std::ostream & o, const TCS::ConfigurableAlg & alg) {
511
512 o << "algorithm '" << alg.fullname() << "'" << std::endl;
513 o << alg.parameters();
514 return o;
515
516 }
517
518}
#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)