ATLAS Offline Software
Loading...
Searching...
No Matches
Analysis::LikelihoodMultiDTool Class Reference

#include <LikelihoodMultiDTool.h>

Inheritance diagram for Analysis::LikelihoodMultiDTool:
Collaboration diagram for Analysis::LikelihoodMultiDTool:

Public Member Functions

 LikelihoodMultiDTool (const std::string &, const std::string &, const IInterface *)
virtual ~LikelihoodMultiDTool ()
StatusCode initialize ()
 AlgTool initailize method.
StatusCode finalize ()
 AlgTool finalize method.
void prepareHistosFromFile (const std::string &refFileName)
TH1 * retrieveHistoFromFile (const std::string &refFileName, const std::string &histoName, const std::string &jetPrefix)
void setLhVariableValue (std::vector< Slice > &value)
void setLhVariableValue (Slice &value)
std::vector< double > calculateLikelihood ()
const std::vector< double > & tagLikelihood ()
void printStatus ()
double getEff (const std::string &, const std::string &, const std::string &)
void addLhVariableToUse (const std::string &)
void resetLhVariableToUse ()
void setInterpolFlag (bool f)
void defineNbHypotheses (int n)
ServiceHandle< StoreGateSvc > & evtStore ()
 The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
const ServiceHandle< StoreGateSvc > & detStore () const
 The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.
virtual StatusCode sysInitialize () override
 Perform system initialization for an algorithm.
virtual StatusCode sysStart () override
 Handle START transition.
virtual std::vector< Gaudi::DataHandle * > inputHandles () const override
 Return this algorithm's input handles.
virtual std::vector< Gaudi::DataHandle * > outputHandles () const override
 Return this algorithm's output handles.
Gaudi::Details::PropertyBase & declareProperty (Gaudi::Property< T, V, H > &t)
void updateVHKA (Gaudi::Details::PropertyBase &)
MsgStream & msg () const
bool msgLvl (const MSG::Level lvl) const

Static Public Member Functions

static const InterfaceID & interfaceID ()

Protected Member Functions

void renounceArray (SG::VarHandleKeyArray &handlesArray)
 remove all handles from I/O resolution
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce (T &h)
void extraDeps_update_handler (Gaudi::Details::PropertyBase &ExtraDeps)
 Add StoreName to extra input/output deps as needed.

Private Types

typedef ServiceHandle< StoreGateSvcStoreGateSvc_t

Private Member Functions

Gaudi::Details::PropertyBase & declareGaudiProperty (Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
 specialization for handling Gaudi::Property<SG::VarHandleKey>

Private Attributes

ITHistSvc * m_histoSvc
std::vector< std::string > m_useTheseLhVariables
 names of lh variables which one wants to use (subset of m_allLhVariables)
std::vector< std::map< std::string, TH1 * > * > m_mapOfAllHistos
 For every histogram input file this vector contains a map with the names of the histograms as a key and the pointer to the histograms.
std::map< std::string, HistoLimitsm_histoLimitsMap1D
 To hold the histo limits.
std::map< std::string, HistoLimitsm_histoLimitsMap2D
std::map< std::string, HistoLimitsm_histoLimitsMap3D
std::vector< Slicem_lhVariableValues
 Contains the value of the likelihood variable with the key std::string.
std::vector< double > m_likelihoodVector
 Contains the combined likelihood for each input file category.
int m_nhis1D
 for debugging:
int m_nhis2D
int m_nhis3D
bool m_DoInterpol
bool m_WriteSmoothedHistos
unsigned int m_nbHypotheses
int m_nSmooth1D
bool m_normProb
StoreGateSvc_t m_evtStore
 Pointer to StoreGate (event store by default)
StoreGateSvc_t m_detStore
 Pointer to StoreGate (detector store by default)
std::vector< SG::VarHandleKeyArray * > m_vhka
bool m_varHandleArraysDeclared

Detailed Description

Definition at line 30 of file LikelihoodMultiDTool.h.

Member Typedef Documentation

◆ StoreGateSvc_t

typedef ServiceHandle<StoreGateSvc> AthCommonDataStore< AthCommonMsg< AlgTool > >::StoreGateSvc_t
privateinherited

Definition at line 388 of file AthCommonDataStore.h.

Constructor & Destructor Documentation

◆ LikelihoodMultiDTool()

Analysis::LikelihoodMultiDTool::LikelihoodMultiDTool ( const std::string & t,
const std::string & n,
const IInterface * p )

Definition at line 25 of file LikelihoodMultiDTool.cxx.

25 :
26 AthAlgTool(t,n,p),
27 m_histoSvc(0),
28 //m_allLhVariables(std::vector<std::string>()),
29 m_useTheseLhVariables(std::vector<std::string>()),
30 m_mapOfAllHistos(std::vector<std::map<std::string, TH1*>* >()),
31 m_histoLimitsMap1D(std::map< std::string, HistoLimits>() ),
32 m_histoLimitsMap2D(std::map< std::string, HistoLimits>() ),
33 m_histoLimitsMap3D(std::map< std::string, HistoLimits>() ),
34 m_lhVariableValues(std::vector<Slice> ()),
35 m_likelihoodVector(std::vector<double>()),
36 m_nhis1D(0),
37 m_nhis2D(0),
38 m_nhis3D(0),
39 m_DoInterpol(false),
42 m_nSmooth1D(1),
43 m_normProb(true)
44 {
45 declareInterface<LikelihoodMultiDTool>(this);
46 declareProperty("WriteSmoothedHistos", m_WriteSmoothedHistos);
47 declareProperty("NSmooth1D", m_nSmooth1D);
48 declareProperty("NormalizeProb", m_normProb);
49 }
std::vector< std::string > m_useTheseLhVariables
names of lh variables which one wants to use (subset of m_allLhVariables)
std::map< std::string, HistoLimits > m_histoLimitsMap2D
std::map< std::string, HistoLimits > m_histoLimitsMap3D
std::vector< Slice > m_lhVariableValues
Contains the value of the likelihood variable with the key std::string.
std::map< std::string, HistoLimits > m_histoLimitsMap1D
To hold the histo limits.
std::vector< double > m_likelihoodVector
Contains the combined likelihood for each input file category.
std::vector< std::map< std::string, TH1 * > * > m_mapOfAllHistos
For every histogram input file this vector contains a map with the names of the histograms as a key a...
AthAlgTool()
Default constructor:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)

◆ ~LikelihoodMultiDTool()

Analysis::LikelihoodMultiDTool::~LikelihoodMultiDTool ( )
virtual

Definition at line 51 of file LikelihoodMultiDTool.cxx.

52 {
53 for (std::vector< std::map<std::string, TH1*>* >::iterator itr = m_mapOfAllHistos.begin();
54 itr != m_mapOfAllHistos.end(); ++itr) delete (*itr);
55 }

Member Function Documentation

◆ addLhVariableToUse()

void Analysis::LikelihoodMultiDTool::addLhVariableToUse ( const std::string & var)

Definition at line 466 of file LikelihoodMultiDTool.cxx.

466 {
467 m_useTheseLhVariables.push_back(var);
468 }

◆ calculateLikelihood()

std::vector< double > Analysis::LikelihoodMultiDTool::calculateLikelihood ( )

Definition at line 263 of file LikelihoodMultiDTool.cxx.

263 {
264 m_likelihoodVector.clear();
265 std::vector<double> probDensityPerEventClassAllVariables;
266 ATH_MSG_VERBOSE("The sizes of the maps "<<m_mapOfAllHistos.size()<<" "<<m_nbHypotheses);
267 probDensityPerEventClassAllVariables.resize(m_nbHypotheses);
268 for (unsigned int i = 0 ; i < m_nbHypotheses; ++i) {
269 probDensityPerEventClassAllVariables[i]=1.;
270 }
271
272 // Loop on Tracks in the Jet (IP) / Vertices in the Jet (SV)
273 for (unsigned int iel = 0; iel<m_lhVariableValues.size(); iel++) {
274 int ncompo = m_lhVariableValues[iel].composites.size();
275 ATH_MSG_VERBOSE("-- element "<<iel<<" "<<m_lhVariableValues[iel].name<<" has "<<ncompo<<" composites.");
276 // Loop on variables that make up the Tag, e.g.
277 // one 1D for IP2D, one 2D for IP3D, one 1D and one 2D for SV1, one 3D for SV2
278 for (int icompo = 0;icompo<ncompo;icompo++) {
279 double sum(0.);
280 std::vector<double> tmpVector;
281 std::string histName = m_lhVariableValues[iel].composites[icompo].name;
282 int idim = m_lhVariableValues[iel].composites[icompo].atoms.size();
283 ATH_MSG_VERBOSE(" -- composite "<<icompo<<" histo= "<<histName<<" dim= "<<idim);
284 if (idim == 1) {
285 const HistoLimits& histoLimits = (*(m_histoLimitsMap1D.find(histName))).second;
286 // Loop on Hypotheses : b or light for the time being...
287 for (std::vector< std::map<std::string, TH1*>* >::iterator
288 itr2 = m_mapOfAllHistos.begin() ;
289 itr2 != m_mapOfAllHistos.end() ; ++itr2 ) {
290 if( (*itr2)->find(histName) != (*itr2)->end() ) {
291 TH1* tmpHisto = (*((*itr2)->find(histName))).second;
292 double value = m_lhVariableValues[iel].composites[icompo].atoms[0].value;
293 int bin((tmpHisto->GetXaxis())->FindBin(value));
294 double tmp(0);
295 if(!m_DoInterpol) {
296 if(value>= histoLimits.xmax) bin = histoLimits.bins;
297 if(value<= histoLimits.xmin) bin = 1;
298 tmp = tmpHisto->GetBinContent(bin);
299 }
300 else {
301 tmp = HistoHelperRoot::Interpol1d(value,dynamic_cast<TH1*>(tmpHisto));
302 }
303 ATH_MSG_VERBOSE(" (1D) value= "<<value<<" bin= "<<bin<< " f = "<<tmp);
304 if (!m_normProb) {
305 double binw = tmpHisto->GetBinWidth(bin);
306 if(binw != 0.)tmp /= binw;
307 else ATH_MSG_ERROR("Bin width is 0.");
308 ATH_MSG_VERBOSE(" (1D) value= "<<value<<" bin= "<<bin<<" binw= "<<binw<< " f = "<<tmp);
309 }
310 tmpVector.push_back(tmp);
311 sum += tmp;
312 }
313 }
314 } else if (idim == 2) {
315 const HistoLimits& histoLimits = (*(m_histoLimitsMap2D.find(histName))).second;
316 for (std::vector< std::map<std::string, TH1*>* >::iterator
317 itr2 = m_mapOfAllHistos.begin() ;
318 itr2 != m_mapOfAllHistos.end() ; ++itr2 ) {
319 if( (*itr2)->find(histName) != (*itr2)->end() ) {
320 TH1* tmpHisto = (*((*itr2)->find(histName))).second;
321 ATH_MSG_VERBOSE("tmpHisto="<<tmpHisto);
322 double valuex = m_lhVariableValues[iel].composites[icompo].atoms[0].value;
323 double valuey = m_lhVariableValues[iel].composites[icompo].atoms[1].value;
324 int binx((tmpHisto->GetXaxis())->FindBin(valuex));
325 int biny((tmpHisto->GetYaxis())->FindBin(valuey));
326 if(valuex>= histoLimits.xmax) binx = histoLimits.bins;
327 if(valuex<= histoLimits.xmin) binx = 1;
328 if(valuey>= histoLimits.ymax) biny = histoLimits.binsy;
329 if(valuey<= histoLimits.ymin) biny = 1;
330 double tmp(tmpHisto->GetBinContent(binx,biny));
331 ATH_MSG_VERBOSE(" (2D) value= "<<valuex<<" "<<valuey<<" bin= "<<binx<<" "<<biny<< " f = "<<tmp);
332 if (!m_normProb) {
333 double binw = tmpHisto->GetXaxis()->GetBinWidth(binx) * tmpHisto->GetYaxis()->GetBinWidth(biny);
334 if(binw != 0.)tmp /= binw;
335 else ATH_MSG_ERROR("Bin area is 0.");
336 ATH_MSG_VERBOSE(" (2D) value= "<<valuex<<" "<<valuey<<" bin= "<<binx<<" "<<biny<<" binw= "<<binw<< " f = "<<tmp);
337 }
338 tmpVector.push_back(tmp);
339 sum += tmp;
340 }
341 }
342 } else if (idim == 3) {
343 const HistoLimits& histoLimits = (*(m_histoLimitsMap3D.find(histName))).second;
344 for (std::vector< std::map<std::string, TH1*>* >::iterator
345 itr2 = m_mapOfAllHistos.begin() ;
346 itr2 != m_mapOfAllHistos.end() ; ++itr2 ) {
347 if( (*itr2)->find(histName) != (*itr2)->end() ) {
348 TH1* tmpHisto = (*((*itr2)->find(histName))).second;
349 double valuex = m_lhVariableValues[iel].composites[icompo].atoms[0].value;
350 double valuey = m_lhVariableValues[iel].composites[icompo].atoms[1].value;
351 double valuez = m_lhVariableValues[iel].composites[icompo].atoms[2].value;
352 int binx((tmpHisto->GetXaxis())->FindBin(valuex));
353 int biny((tmpHisto->GetYaxis())->FindBin(valuey));
354 int binz((tmpHisto->GetZaxis())->FindBin(valuez));
355 if(valuex>= histoLimits.xmax) binx = histoLimits.bins;
356 if(valuex<= histoLimits.xmin) binx = 1;
357 if(valuey>= histoLimits.ymax) biny = histoLimits.binsy;
358 if(valuey<= histoLimits.ymin) biny = 1;
359 if(valuez>= histoLimits.zmax) binz = histoLimits.binsz;
360 if(valuez<= histoLimits.zmin) binz = 1;
361 double tmpNoInt(tmpHisto->GetBinContent(binx,biny,binz));
362 double tmp(HistoHelperRoot::Interpol3d(valuex,valuey,valuez,dynamic_cast<TH3*>(tmpHisto)));
363 ATH_MSG_VERBOSE(" (3D) value= "<<valuex<<" "<<valuey<<" "<<valuez <<" bin= "<<binx<<" "<<biny<<" "<<binz<<" binContent = "<<tmp<< " binContentNoInt = "<< tmpNoInt);
364 if (!m_normProb) {
365 double binw =
366 tmpHisto->GetXaxis()->GetBinWidth(binx) *
367 tmpHisto->GetYaxis()->GetBinWidth(biny) *
368 tmpHisto->GetZaxis()->GetBinWidth(binz);
369 if(binw != 0.) {
370 tmpNoInt /= binw;
371 tmp /= binw;
372 }
373 else ATH_MSG_ERROR("Bin volume is 0.");
374 ATH_MSG_VERBOSE(" (3D) value= "<<valuex<<" "<<valuey<<" "<<valuez <<" bin= "<<binx<<" "<<biny<<" "<<binz<<" binw= "<<binw<<" binContent = "<<tmp<< " binContentNoInt = "<< tmpNoInt);
375 }
376 if (m_DoInterpol) {
377 tmpVector.push_back(tmp);
378 sum += tmp;
379 } else {
380 tmpVector.push_back(tmpNoInt);
381 sum += tmpNoInt;
382 }
383 }
384 }
385 } else {
386 ATH_MSG_WARNING("No more that 3D pdf for the time being !");
387 }
388 unsigned int classCount(0);
389 for (std::vector<double>::iterator itr3 = tmpVector.begin(); itr3 != tmpVector.end(); ++itr3) {
390 if (sum != 0.) {
391 ATH_MSG_VERBOSE("pb + pu = "<<sum);
392 double p = (*itr3);
393 if (m_normProb) p /= sum;
394 probDensityPerEventClassAllVariables[classCount] *= p;
395 } else {
396 ATH_MSG_WARNING("Empty bins for all hypothesis... The discriminating variables are not taken into account in this jet");
397 ATH_MSG_WARNING("Check your inputs");
398 }
399 ATH_MSG_VERBOSE(" probDensity= "<<probDensityPerEventClassAllVariables[classCount]<<" ic= "<<classCount);
400 classCount++;
401 }
402 ATH_MSG_VERBOSE(" Final probDensity= "<<probDensityPerEventClassAllVariables);
403 }
404 }
405 ATH_MSG_VERBOSE(" Ending ...");
406 m_likelihoodVector=probDensityPerEventClassAllVariables;
407 return m_likelihoodVector;
408 }
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
static double Interpol3d(double, double, double, TH3 *)
static double Interpol1d(double, TH1 *)

◆ declareGaudiProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareGaudiProperty ( Gaudi::Property< T, V, H > & hndl,
const SG::VarHandleKeyType &  )
inlineprivateinherited

specialization for handling Gaudi::Property<SG::VarHandleKey>

Definition at line 156 of file AthCommonDataStore.h.

158 {
160 hndl.value(),
161 hndl.documentation());
162
163 }

◆ declareProperty()

Gaudi::Details::PropertyBase & AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty ( Gaudi::Property< T, V, H > & t)
inlineinherited

Definition at line 145 of file AthCommonDataStore.h.

145 {
146 typedef typename SG::HandleClassifier<T>::type htype;
148 }
Gaudi::Details::PropertyBase & declareGaudiProperty(Gaudi::Property< T, V, H > &hndl, const SG::VarHandleKeyType &)
specialization for handling Gaudi::Property<SG::VarHandleKey>

◆ defineNbHypotheses()

void Analysis::LikelihoodMultiDTool::defineNbHypotheses ( int n)
inline

Definition at line 57 of file LikelihoodMultiDTool.h.

◆ detStore()

const ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::detStore ( ) const
inlineinherited

The standard StoreGateSvc/DetectorStore Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 95 of file AthCommonDataStore.h.

◆ evtStore()

ServiceHandle< StoreGateSvc > & AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore ( )
inlineinherited

The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.

Definition at line 85 of file AthCommonDataStore.h.

◆ extraDeps_update_handler()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::extraDeps_update_handler ( Gaudi::Details::PropertyBase & ExtraDeps)
protectedinherited

Add StoreName to extra input/output deps as needed.

use the logic of the VarHandleKey to parse the DataObjID keys supplied via the ExtraInputs and ExtraOuputs Properties to add the StoreName if it's not explicitly given

◆ finalize()

StatusCode Analysis::LikelihoodMultiDTool::finalize ( )

AlgTool finalize method.

Definition at line 70 of file LikelihoodMultiDTool.cxx.

71 {
72 return StatusCode::SUCCESS;
73 }

◆ getEff()

double Analysis::LikelihoodMultiDTool::getEff ( const std::string & refFileName,
const std::string & histoName,
const std::string & mode )

Definition at line 421 of file LikelihoodMultiDTool.cxx.

422 {
423 //
424 StatusCode scs = SUCCESS, scg = SUCCESS;
425 std::string fullPathSel(refFileName+histoName+"Eff"+mode);
426 std::string fullPathGen(refFileName+histoName+"Norm"+mode);
427 ATH_MSG_VERBOSE("Retrieving histo for efficiency computation: " << fullPathSel);
428 ATH_MSG_VERBOSE("Retrieving histo for efficiency computation: " << fullPathGen);
429 TH1 *sel(0), *gen(0);
430 scs = m_histoSvc->regHist(fullPathSel);
431 scg = m_histoSvc->regHist(fullPathGen);
432 if (scs.isSuccess() && scg.isSuccess()) {
433 scs = m_histoSvc->getHist(fullPathSel,sel);
434 scg = m_histoSvc->getHist(fullPathGen,gen);
435 if (sel && gen && scs.isSuccess() && scg.isSuccess()) {
436 double nsel = sel->GetEntries(); // I need also the over/under flow for the efficiency !!!
437 double ngen = gen->GetEntries();
438 if (ngen != 0) {
439 ATH_MSG_VERBOSE("N RecSvx = " << nsel << " in a total of "<< ngen << " jets.");
440 return nsel/ngen;
441 } else {
442 ATH_MSG_ERROR("Pb in computing Svx efficiency " << nsel << " "<< ngen);
443 return 0.;
444 }
445 }
446 } else {
447 // already there...
448 scs = m_histoSvc->getHist(fullPathSel,sel);
449 scg = m_histoSvc->getHist(fullPathGen,gen);
450 if (sel && gen && scs.isSuccess() && scg.isSuccess()) {
451 double nsel = sel->GetEntries();
452 double ngen = gen->GetEntries();
453 if (ngen != 0) {
454 ATH_MSG_VERBOSE("N RecSvx = " << nsel << " in a total of "<< ngen << " jets.");
455 return nsel/ngen;
456 } else {
457 ATH_MSG_ERROR("Pb in computing Svx efficiency " << nsel << " "<< ngen);
458 return 0.;
459 }
460 }
461 }
462 ATH_MSG_ERROR("Pb in computing Svx efficiency ");
463 return 0.;
464 }
::StatusCode StatusCode
StatusCode definition for legacy code.

◆ initialize()

StatusCode Analysis::LikelihoodMultiDTool::initialize ( )

AlgTool initailize method.

Definition at line 57 of file LikelihoodMultiDTool.cxx.

58 {
59
60 StatusCode sc = service("THistSvc", m_histoSvc);
61 if (sc.isFailure())
62 {
63 ATH_MSG_FATAL("THistSvc not found!");
64 return StatusCode::FAILURE;
65 }
66 //
67 return StatusCode::SUCCESS;
68 }
#define ATH_MSG_FATAL(x)
static Double_t sc

◆ inputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::inputHandles ( ) const
overridevirtualinherited

Return this algorithm's input handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ interfaceID()

const InterfaceID & Analysis::LikelihoodMultiDTool::interfaceID ( )
inlinestatic

Definition at line 43 of file LikelihoodMultiDTool.h.

43{ return IID_LikelihoodMultiDTool; };
static const InterfaceID IID_LikelihoodMultiDTool("Analysis::LikelihoodMultiDTool", 1, 0)

◆ msg()

MsgStream & AthCommonMsg< AlgTool >::msg ( ) const
inlineinherited

Definition at line 24 of file AthCommonMsg.h.

24 {
25 return this->msgStream();
26 }

◆ msgLvl()

bool AthCommonMsg< AlgTool >::msgLvl ( const MSG::Level lvl) const
inlineinherited

Definition at line 30 of file AthCommonMsg.h.

30 {
31 return this->msgLevel(lvl);
32 }

◆ outputHandles()

virtual std::vector< Gaudi::DataHandle * > AthCommonDataStore< AthCommonMsg< AlgTool > >::outputHandles ( ) const
overridevirtualinherited

Return this algorithm's output handles.

We override this to include handle instances from key arrays if they have not yet been declared. See comments on updateVHKA.

◆ prepareHistosFromFile()

void Analysis::LikelihoodMultiDTool::prepareHistosFromFile ( const std::string & refFileName)

Definition at line 75 of file LikelihoodMultiDTool.cxx.

75 {
76 MsgStream mlog(msgSvc(),name());
77 ATH_MSG_DEBUG("refFileName = "<<refFileName);
78 // the tmpHistoMap belongs to m_mapOfAllHistos and is deleted at the end in the destructor of LikelihoodMultiDTool()
79 std::map<std::string, TH1*>* tmpHistoMap = new std::map<std::string, TH1*>();
80 // loop on requested histos:
81 for (std::vector<std::string>::iterator itr = m_useTheseLhVariables.begin() ;
82 itr != m_useTheseLhVariables.end() ; ++itr ) {
83 std::string histoName = *itr;
84 std::vector<std::string> grades;
85 // parse histo name to extract words separated by _ sign:
86 // first word is the histo base name, following ones are the grades
87 // first word is jet category, 2nd is the histo base name, following ones are the grades
88 std::vector<std::string> words;
89
90 ATH_MSG_DEBUG("decoding histoName = "<<histoName);
91
92 const std::string delim("_");
93 std::string::size_type sPos, sEnd, sLen;
94 sPos = histoName.find_first_not_of(delim);
95 while ( sPos != std::string::npos ) {
96 sEnd = histoName.find_first_of(delim, sPos);
97 if(sEnd==std::string::npos) sEnd = histoName.length();
98 sLen = sEnd - sPos;
99 std::string word = histoName.substr(sPos,sLen);
100
101 ATH_MSG_DEBUG(" -> word = "<<word);
102
103 words.push_back(word);
104 sPos = histoName.find_first_not_of(delim, sEnd);
105 }
106 // first treat cases with a single or no grade:
107 int nGrade = words.size() - 2;
108 TH1* histoSum(0);
109 if(nGrade==0) {
110 ATH_MSG_DEBUG("Histo "<<histoName<<" has "<<nGrade<<" grade: direct retrieval");
111 histoSum = this->retrieveHistoFromFile(refFileName, words[1], words[0]);
112 } else if(nGrade==1) {
113 ATH_MSG_DEBUG("Histo "<<histoName<<" has "<<nGrade<<" grade: direct retrieval");
114 histoSum = this->retrieveHistoFromFile(refFileName, words[1]+"_"+words[2], words[0]);
115 } else {
116 // for many grades, get individual histos and sum them up:
117 ATH_MSG_DEBUG("Histo "<<histoName<<" has "<<nGrade<<" grades:");
118 for(int i=1;i<=nGrade;i++) {
119 ATH_MSG_DEBUG(" -> retrieving histo for grade "<<i<<" : "<<words[1]<<" "<<words[i+1]);
120 TH1* histo = this->retrieveHistoFromFile(refFileName, words[1]+"_"+words[i+1], words[0]);
121 ATH_MSG_DEBUG(" #entries= "<<histo->GetEntries());
122 if(1==i) {
123 histoSum = histo;
124 } else {
125 histoSum->Add(histo,1.);
126 }
127 ATH_MSG_DEBUG(" #entries for Sum= "<<histoSum->GetEntries());
128 }
129 }
130 if(histoSum) {
131 // smooth and normalize:
132 double norm = histoSum->Integral();
133 if(norm) {
134 if(1==histoSum->GetDimension() && m_nSmooth1D) {
135 if(histoName.find("N2T")==std::string::npos){ // do not smooth N2T
136 if(norm>10000)histoSum->Smooth(m_nSmooth1D);
137 else histoSum->Smooth((int)(m_nSmooth1D*100./sqrt(norm)));
138 }
139 }
140 if(2==histoSum->GetDimension()) {
141 int m2d=3;
142 if(refFileName.find("Bkg/")!=std::string::npos) m2d=5;
143 bool debug = mlog.level()<=MSG::DEBUG ? true : false;
144 // do not smooth Sip3D for the time being
145 if(histoName.find("Sip3D")==std::string::npos) HistoHelperRoot::smoothASH2D(dynamic_cast<TH2*>(histoSum), m2d, m2d, debug);
146 }
147 if(3==histoSum->GetDimension()) {
148 int m3d1=3;
149 int m3d3=2;
150 bool debug = mlog.level()<=MSG::DEBUG ? true : false;
151 HistoHelperRoot::smoothASH3D(dynamic_cast<TH3*>(histoSum), m3d1, m3d1, m3d3, debug);
152 }
153 norm = histoSum->Integral();
154 histoSum->Scale(1./norm);
155 } else {
156 ATH_MSG_WARNING("Histo "<<histoName<<" is empty!");
157 }
158 // store: if >= 2 grades in one histo, the histoName is the name of the first Grade
159 // Change LV 2005/10/09: if >=2 grades, insert a copy for each grade:
160 std::string namemap = histoName;
161 if (nGrade == 0) {
162 namemap = words[0]+"_"+words[1];
163 ATH_MSG_VERBOSE("Inserting as " << namemap);
164 tmpHistoMap->insert(std::pair<std::string, TH1*>(namemap, histoSum));
165 }
166 for(int i=1;i<=nGrade;i++) {
167 namemap = words[0] + "_" + words[1] + "_" + words[i+1];
168 ATH_MSG_VERBOSE("Inserting as " << namemap);
169 tmpHistoMap->insert(std::pair<std::string, TH1*>(namemap, histoSum));
170 }
171 // Also for control, store the smoothed histograms in a file
173 std::string namedir = refFileName; namedir = namedir.substr((namedir.erase(namedir.size()-1,1)).rfind('/')+1)+"/";
174 std::string namehis = histoSum->GetName();
175 ATH_MSG_VERBOSE("Registering smoothed histogram in " << namedir);
176 TH1* histoSumClone = (TH1*)histoSum->Clone();
177 StatusCode sc = m_histoSvc->regHist("/ControlFile/"+namedir+namehis, histoSumClone);
178 if (sc.isFailure()) {
179 ATH_MSG_ERROR("Cannot store the smoothed histogram in the control file !");
180 }
181 }
182 }
183 }
184 ATH_MSG_DEBUG("I found "<<m_nhis1D<<" 1D histos, "<<m_nhis2D<<" 2D histos and "<<m_nhis3D<<" 3D histos");
185 if (m_nhis1D+m_nhis2D+m_nhis3D) m_mapOfAllHistos.push_back(tmpHistoMap);
186 }
#define ATH_MSG_DEBUG(x)
const bool debug
static void smoothASH2D(TH2 *, int m1=3, int m2=3, bool debug=false)
static void smoothASH3D(TH3 *, int m1=3, int m2=3, int m3=2, bool debug=false)
TH1 * retrieveHistoFromFile(const std::string &refFileName, const std::string &histoName, const std::string &jetPrefix)
msgSvc
Provide convenience handles for various services.
Definition StdJOSetup.py:36

◆ printStatus()

void Analysis::LikelihoodMultiDTool::printStatus ( )

Definition at line 415 of file LikelihoodMultiDTool.cxx.

416 {
417 unsigned int num = m_mapOfAllHistos.size();
418 ATH_MSG_INFO("Currently I hold histos of " << num << " input files");
419 }
#define ATH_MSG_INFO(x)

◆ renounce()

std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > AthCommonDataStore< AthCommonMsg< AlgTool > >::renounce ( T & h)
inlineprotectedinherited

Definition at line 380 of file AthCommonDataStore.h.

381 {
382 h.renounce();
384 }
std::enable_if_t< std::is_void_v< std::result_of_t< decltype(&T::renounce)(T)> > &&!std::is_base_of_v< SG::VarHandleKeyArray, T > &&std::is_base_of_v< Gaudi::DataHandle, T >, void > renounce(T &h)

◆ renounceArray()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::renounceArray ( SG::VarHandleKeyArray & handlesArray)
inlineprotectedinherited

remove all handles from I/O resolution

Definition at line 364 of file AthCommonDataStore.h.

364 {
366 }

◆ resetLhVariableToUse()

void Analysis::LikelihoodMultiDTool::resetLhVariableToUse ( )
inline

Definition at line 55 of file LikelihoodMultiDTool.h.

55{ m_useTheseLhVariables.clear(); }

◆ retrieveHistoFromFile()

TH1 * Analysis::LikelihoodMultiDTool::retrieveHistoFromFile ( const std::string & refFileName,
const std::string & histoName,
const std::string & jetPrefix )

Retrieve and set histo limits for this histogram

Definition at line 188 of file LikelihoodMultiDTool.cxx.

190 {
191 std::string fullPath(refFileName+histoName);
192 ATH_MSG_VERBOSE("Retrieving histo: " << fullPath);
193 bool is1D = false, is2D = false, is3D = false;
194 TH1* tmphisto(0);
195 StatusCode sc = m_histoSvc->regHist(fullPath);
196 if(sc.isFailure()) {};
197 sc = m_histoSvc->getHist(fullPath,tmphisto);
198 int dim = 0;
199 if (sc.isSuccess()) {
200 dim = tmphisto->GetDimension();
201 if (dim == 1) {
202 is1D = true;
203 m_nhis1D++;
204 } else if (dim == 2) {
205 is2D = true;
206 m_nhis2D++;
207 } else if (dim == 3) {
208 is3D = true;
209 m_nhis3D++;
210 } else {
211 ATH_MSG_DEBUG("cannot retrieve histo " << fullPath << " Unexpected dimension "<< dim);
212 return tmphisto;
213 }
214 } else {
215 ATH_MSG_DEBUG("I COULD NOT RETRIEVE HISTO: " << fullPath);
216 return tmphisto;
217 }
219 unsigned int bins = (tmphisto->GetXaxis())->GetNbins();
220 double minx = (tmphisto->GetXaxis())->GetXmin();
221 double maxx = (tmphisto->GetXaxis())->GetXmax();
222 if (is1D) {
223 m_histoLimitsMap1D[jetPrefix+"_"+histoName] = HistoLimits(bins, minx, maxx);
224 ATH_MSG_DEBUG("Histo "<< jetPrefix+"_"+histoName << " properties: ");
225 ATH_MSG_DEBUG(bins <<" bins X between " << minx <<" and " << maxx);
226 } else if (is2D) {
227 unsigned int binsy = (tmphisto->GetYaxis())->GetNbins();
228 double miny = (tmphisto->GetYaxis())->GetXmin();
229 double maxy = (tmphisto->GetYaxis())->GetXmax();
230 m_histoLimitsMap2D[jetPrefix+"_"+histoName] = HistoLimits(bins, minx, maxx, binsy, miny, maxy);
231 ATH_MSG_DEBUG("Histo "<< jetPrefix+"_"+histoName << " properties: ");
232 ATH_MSG_DEBUG(bins <<" bins X between " << minx <<" and " << maxx );
233 ATH_MSG_DEBUG(binsy <<" bins Y between " << miny <<" and " << maxy);
234 } else if (is3D) {
235 unsigned int binsy = (tmphisto->GetYaxis())->GetNbins();
236 double miny = (tmphisto->GetYaxis())->GetXmin();
237 double maxy = (tmphisto->GetYaxis())->GetXmax();
238 unsigned int binsz = (tmphisto->GetZaxis())->GetNbins();
239 double minz = (tmphisto->GetZaxis())->GetXmin();
240 double maxz = (tmphisto->GetZaxis())->GetXmax();
241 m_histoLimitsMap3D[jetPrefix+"_"+histoName] = HistoLimits(bins, minx, maxx, binsy, miny, maxy, binsz, minz, maxz);
242
243 ATH_MSG_DEBUG("Histo "<< jetPrefix+"_"+histoName << " properties: ");
244 ATH_MSG_DEBUG(bins <<" bins X between " << minx <<" and " << maxx);
245 ATH_MSG_DEBUG(binsy <<" bins Y between " << miny <<" and " << maxy);
246 ATH_MSG_DEBUG(binsz <<" bins Z between " << minz <<" and " << maxz);
247 }
248 return tmphisto;
249 }
static const std::vector< std::string > bins

◆ setInterpolFlag()

void Analysis::LikelihoodMultiDTool::setInterpolFlag ( bool f)
inline

Definition at line 56 of file LikelihoodMultiDTool.h.

◆ setLhVariableValue() [1/2]

void Analysis::LikelihoodMultiDTool::setLhVariableValue ( Slice & value)

Definition at line 255 of file LikelihoodMultiDTool.cxx.

256 {
257 std::vector<Slice> tmpVector;
258 tmpVector.push_back(value);
259 setLhVariableValue(tmpVector);
260 }
void setLhVariableValue(std::vector< Slice > &value)

◆ setLhVariableValue() [2/2]

void Analysis::LikelihoodMultiDTool::setLhVariableValue ( std::vector< Slice > & value)

Definition at line 251 of file LikelihoodMultiDTool.cxx.

252 {
254 }

◆ sysInitialize()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysInitialize ( )
overridevirtualinherited

Perform system initialization for an algorithm.

We override this to declare all the elements of handle key arrays at the end of initialization. See comments on updateVHKA.

Reimplemented in asg::AsgMetadataTool, AthCheckedComponent< AthAlgTool >, AthCheckedComponent<::AthAlgTool >, and DerivationFramework::CfAthAlgTool.

◆ sysStart()

virtual StatusCode AthCommonDataStore< AthCommonMsg< AlgTool > >::sysStart ( )
overridevirtualinherited

Handle START transition.

We override this in order to make sure that conditions handle keys can cache a pointer to the conditions container.

◆ tagLikelihood()

const std::vector< double > & Analysis::LikelihoodMultiDTool::tagLikelihood ( )

Definition at line 410 of file LikelihoodMultiDTool.cxx.

411 {
412 return m_likelihoodVector;
413 }

◆ updateVHKA()

void AthCommonDataStore< AthCommonMsg< AlgTool > >::updateVHKA ( Gaudi::Details::PropertyBase & )
inlineinherited

Definition at line 308 of file AthCommonDataStore.h.

308 {
309 // debug() << "updateVHKA for property " << p.name() << " " << p.toString()
310 // << " size: " << m_vhka.size() << endmsg;
311 for (auto &a : m_vhka) {
313 for (auto k : keys) {
314 k->setOwner(this);
315 }
316 }
317 }
std::vector< SG::VarHandleKeyArray * > m_vhka

Member Data Documentation

◆ m_detStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_detStore
privateinherited

Pointer to StoreGate (detector store by default)

Definition at line 393 of file AthCommonDataStore.h.

◆ m_DoInterpol

bool Analysis::LikelihoodMultiDTool::m_DoInterpol
private

Definition at line 98 of file LikelihoodMultiDTool.h.

◆ m_evtStore

StoreGateSvc_t AthCommonDataStore< AthCommonMsg< AlgTool > >::m_evtStore
privateinherited

Pointer to StoreGate (event store by default)

Definition at line 390 of file AthCommonDataStore.h.

◆ m_histoLimitsMap1D

std::map<std::string, HistoLimits> Analysis::LikelihoodMultiDTool::m_histoLimitsMap1D
private

To hold the histo limits.

If a lh variable is out of range it should use the entries in the first or the last bin.

Definition at line 76 of file LikelihoodMultiDTool.h.

◆ m_histoLimitsMap2D

std::map<std::string, HistoLimits> Analysis::LikelihoodMultiDTool::m_histoLimitsMap2D
private

Definition at line 77 of file LikelihoodMultiDTool.h.

◆ m_histoLimitsMap3D

std::map<std::string, HistoLimits> Analysis::LikelihoodMultiDTool::m_histoLimitsMap3D
private

Definition at line 78 of file LikelihoodMultiDTool.h.

◆ m_histoSvc

ITHistSvc* Analysis::LikelihoodMultiDTool::m_histoSvc
private

Definition at line 61 of file LikelihoodMultiDTool.h.

◆ m_lhVariableValues

std::vector<Slice> Analysis::LikelihoodMultiDTool::m_lhVariableValues
private

Contains the value of the likelihood variable with the key std::string.

It is necessary that the value of a likelihood variable is stored with a key to the histogram it should be compared to. Otherwise the likelihood class never knows which lh valuable it handles when only a subset of variables is used. It has a vector of double because some LH variabels are there more than once per jet/event (e.g. tracksignificance of LifetimeTag).

Definition at line 86 of file LikelihoodMultiDTool.h.

◆ m_likelihoodVector

std::vector<double> Analysis::LikelihoodMultiDTool::m_likelihoodVector
private

Contains the combined likelihood for each input file category.

Usually input 1 are the signal distributions - so the first entry is the sigLh of the event.

Definition at line 90 of file LikelihoodMultiDTool.h.

◆ m_mapOfAllHistos

std::vector< std::map<std::string, TH1*>* > Analysis::LikelihoodMultiDTool::m_mapOfAllHistos
private

For every histogram input file this vector contains a map with the names of the histograms as a key and the pointer to the histograms.

It is a vector because there can be 2+ (sig, bkg1, bkg2, ...) histogram input files.

Definition at line 71 of file LikelihoodMultiDTool.h.

◆ m_nbHypotheses

unsigned int Analysis::LikelihoodMultiDTool::m_nbHypotheses
private

Definition at line 101 of file LikelihoodMultiDTool.h.

◆ m_nhis1D

int Analysis::LikelihoodMultiDTool::m_nhis1D
private

for debugging:

Definition at line 93 of file LikelihoodMultiDTool.h.

◆ m_nhis2D

int Analysis::LikelihoodMultiDTool::m_nhis2D
private

Definition at line 94 of file LikelihoodMultiDTool.h.

◆ m_nhis3D

int Analysis::LikelihoodMultiDTool::m_nhis3D
private

Definition at line 95 of file LikelihoodMultiDTool.h.

◆ m_normProb

bool Analysis::LikelihoodMultiDTool::m_normProb
private

Definition at line 105 of file LikelihoodMultiDTool.h.

◆ m_nSmooth1D

int Analysis::LikelihoodMultiDTool::m_nSmooth1D
private

Definition at line 104 of file LikelihoodMultiDTool.h.

◆ m_useTheseLhVariables

std::vector<std::string> Analysis::LikelihoodMultiDTool::m_useTheseLhVariables
private

names of lh variables which one wants to use (subset of m_allLhVariables)

Definition at line 65 of file LikelihoodMultiDTool.h.

◆ m_varHandleArraysDeclared

bool AthCommonDataStore< AthCommonMsg< AlgTool > >::m_varHandleArraysDeclared
privateinherited

Definition at line 399 of file AthCommonDataStore.h.

◆ m_vhka

std::vector<SG::VarHandleKeyArray*> AthCommonDataStore< AthCommonMsg< AlgTool > >::m_vhka
privateinherited

Definition at line 398 of file AthCommonDataStore.h.

◆ m_WriteSmoothedHistos

bool Analysis::LikelihoodMultiDTool::m_WriteSmoothedHistos
private

Definition at line 99 of file LikelihoodMultiDTool.h.


The documentation for this class was generated from the following files: