ATLAS Offline Software
Loading...
Searching...
No Matches
HistosForJetSelection.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3*/
4
7#include "TH1.h"
8
10 , m_histoTools(this)
12 , m_titleSuffix("")
13 , m_nameSuffix("")
14{
15 declareProperty("SelectionType", m_selType=AllJets);
16 declareProperty("HistoTools", m_histoTools);
17 declareProperty("HistoTitleSuffix", m_titleSuffix);
18 declareProperty("HistoNameSuffix", m_nameSuffix);
19 declareProperty("JetSelectorTool", m_selTool);
20 declareProperty("InverseToolSelection", m_inverseToolSelection);
21}
22
24
26 CHECK( m_histoTools.retrieve() );
28
29 // build the title and name modifiers
30
31 switch((SelectionType)m_selType){
32 case LeadingJet:
33 m_titleSuffix = " (Leading Jet)";
34 m_nameSuffix = "leadingjet";
35 break;
36 case SubLeadingJet:
37 m_titleSuffix = " (SubLeading Jet)";
38 m_nameSuffix = "subleadingjet";
39 break;
40 case FromTool:
41 {
42 CHECK(m_selTool.retrieve());
43 if( (m_nameSuffix.empty() ) || (m_titleSuffix.empty()) ) {
44 ATH_MSG_ERROR("When using a selection tool, please set BOTH of HistoTitleSuffix (="<<m_titleSuffix<<") and HistoNameSuffix (="<<m_nameSuffix<<") or set them explicitely to 'none'. This is to avoid histo names clashes.");
45 return StatusCode::FAILURE;
46 }
47 if(m_nameSuffix == "none") m_nameSuffix="";
48 if(m_titleSuffix == "none") m_titleSuffix="";
49 // either ask from tool or let m_xxSuffix be properties
50 }
51 break;
52 default:
53 break;
54 }
55 return StatusCode::SUCCESS;
56}
57
58
60 // build histos of each subtools
61 int count=0;
62 for( auto jtool : m_histoTools){
63 count+=jtool->buildHistos();
64 // keep a pointer to histos :
65 const auto & hdata = jtool->bookedHistograms();
66 ATH_MSG_DEBUG(" Histo tool "<< jtool->name() << " count= "<< count<< " nh="<<hdata.size());
67 for( const auto & hd : hdata ){
68 TH1 * h = const_cast<TH1*>(hd.hist);
69 ATH_MSG_DEBUG(" Histo tool h "<< h->GetName() );
70 m_vBookedHistograms.push_back(hd);
72 }
73 }
74 return count;
75}
76
77
78
80
82 const xAOD::JetContainer * contPtr = nullptr;
83
85 switch((SelectionType)m_selType){
86 case LeadingJet:
87 {
88 if(!cont.empty()){
89 tmpCont.push_back(cont[0]);
90 contPtr = tmpCont.asDataVector();
91 } else return 0;
92 }
93 break;
94
95 case SubLeadingJet:
96 {
97 if(cont.size()>1){
98 tmpCont.push_back(cont[1]);
99 contPtr = tmpCont.asDataVector();
100 }else return 0;
101 }
102 break;
103
104 case AllJets:
105 contPtr = &cont;
106 break;
107
108 case FromTool:
109 {
110 // filter :
111 for(const xAOD::Jet* jet : cont ) {
113 {
114 if(! m_selTool->keep(*jet) )
115 {
116 tmpCont.push_back(jet) ;
117 }
118 }
119 else if( m_selTool->keep(*jet) )
120 {
121 tmpCont.push_back(jet) ;
122 }
123 }
124 contPtr = tmpCont.asDataVector();
125 }
126 break;
127 default:
128 break;
129 }
130
131 // then fill histos
132 for( auto jtool : m_histoTools){
133 ATH_MSG_DEBUG (" Filling " << jtool->name() << "..." );
134 jtool->fillHistosFromContainer(*contPtr, weight);
135 }
136 return 0;
137}
138
140 h->SetName( (h->GetName()+m_nameSuffix).c_str());
141 h->SetTitle( (h->GetTitle()+m_titleSuffix).c_str() );
142}
143
145 int count = 0;
146 for( auto jtool : m_histoTools){
147 count+=jtool->finalizeHistos();
148 }
149 return count;
150
151}
152
153void HistosForJetSelection::prefixHistoDir(const std::string & preDir){
154 for( auto jtool : m_histoTools){
155 jtool->prefixHistoDir(preDir+m_histoDir);
156 }
157}
158
160 // propagate interval to sub-tools
161 for( auto jtool : m_histoTools){
162 jtool->setInterval(ityp,force);
163 }
164}
#define ATH_MSG_ERROR(x)
#define ATH_MSG_DEBUG(x)
DataVector adapter that acts like it holds const pointers.
#define CHECK(...)
Evaluate an expression and check for errors.
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
Header file for AthHistogramAlgorithm.
DataVector adapter that acts like it holds const pointers.
value_type push_back(value_type pElem)
Add an element to the end of the collection.
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
std::string m_histoDir
The path where histos in this group leave.
std::vector< HistData > m_vBookedHistograms
The list of histos in this group.
Interval_t
Redefinition of fill intervals as in ManagedMonitorToolBase.
virtual void modifyNameAndTitle(TH1 *h)
virtual void setInterval(Interval_t ityp, bool force=false)
redefine to forward to sub histos
HistosForJetSelection(const std::string &t)
std::string m_nameSuffix
Suffix of the histos names.
ToolHandleArray< JetHistoBase > m_histoTools
List of histo tools to call on selected jets.
ToolHandle< IJetSelector > m_selTool
virtual void prefixHistoDir(const std::string &preDir)
redefine to forward to sub histos
virtual ~HistosForJetSelection()
int m_selType
used only if m_selType == FromTool
SelectionType
Describes the selection type : built-in or use of an external type.
std::string m_titleSuffix
Suffix of the histos titles. If the property is not set and using a built-in type,...
virtual int fillHistosFromContainer(const xAOD::JetContainer &cont, float weight)
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
JetHistoBase(const std::string &t)
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
int count(std::string s, const std::string &regx)
count how many occurances of a regx are in a string
Definition hcg.cxx:146
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Jet_v1 Jet
Definition of the current "jet version".
JetContainer_v1 JetContainer
Definition of the current "jet container version".