ATLAS Offline Software
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)
11  , m_selType(AllJets)
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 
153 void 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 }
HistosForJetSelection::modifyNameAndTitle
virtual void modifyNameAndTitle(TH1 *h)
Definition: HistosForJetSelection.cxx:139
HistosForJetSelection::m_selTool
ToolHandle< IJetSelector > m_selTool
Definition: HistosForJetSelection.h:66
calibdata.force
bool force
Definition: calibdata.py:19
SG::VIEW_ELEMENTS
@ VIEW_ELEMENTS
this data object is a view, it does not own its elmts
Definition: OwnershipPolicy.h:18
ConstDataVector.h
DataVector adapter that acts like it holds const pointers.
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
HistosForJetSelection::m_histoTools
ToolHandleArray< JetHistoBase > m_histoTools
List of histo tools to call on selected jets.
Definition: HistosForJetSelection.h:64
HistosForJetSelection::HistosForJetSelection
HistosForJetSelection(const std::string &t)
Definition: HistosForJetSelection.cxx:9
HistosForJetSelection::setInterval
virtual void setInterval(Interval_t ityp, bool force=false)
redefine to forward to sub histos
Definition: HistosForJetSelection.cxx:159
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
HistosForJetSelection::m_selType
int m_selType
used only if m_selType == FromTool
Definition: HistosForJetSelection.h:69
HistosForJetSelection::SelectionType
SelectionType
Describes the selection type : built-in or use of an external type.
Definition: HistosForJetSelection.h:51
HistosForJetSelection::m_titleSuffix
std::string m_titleSuffix
Suffix of the histos titles. If the property is not set and using a built-in type,...
Definition: HistosForJetSelection.h:72
HistosForJetSelection.h
XMLtoHeader.count
count
Definition: XMLtoHeader.py:85
ConstDataVector::asDataVector
const DV * asDataVector() const
Return a pointer to this object, as a const DataVector.
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
JetHistoBase
Definition: JetHistoBase.h:27
HistosForJetSelection::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: HistosForJetSelection.cxx:25
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
HistosForJetSelection::buildHistos
virtual int buildHistos()
Definition: HistosForJetSelection.cxx:59
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
HistosForJetSelection::prefixHistoDir
virtual void prefixHistoDir(const std::string &preDir)
redefine to forward to sub histos
Definition: HistosForJetSelection.cxx:153
HistosForJetSelection::finalizeHistos
virtual int finalizeHistos()
Definition: HistosForJetSelection.cxx:144
HistosForJetSelection::m_nameSuffix
std::string m_nameSuffix
Suffix of the histos names.
Definition: HistosForJetSelection.h:74
CHECK
#define CHECK(...)
Evaluate an expression and check for errors.
Definition: Control/AthenaKernel/AthenaKernel/errorcheck.h:422
HistosForJetSelection::m_inverseToolSelection
bool m_inverseToolSelection
Definition: HistosForJetSelection.h:48
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
HistosForJetSelection::SubLeadingJet
@ SubLeadingJet
Definition: HistosForJetSelection.h:54
HistoGroupBase::m_histoDir
std::string m_histoDir
The path where histos in this group leave.
Definition: HistoGroupBase.h:93
HistosForJetSelection::FromTool
@ FromTool
Definition: HistosForJetSelection.h:55
ConstDataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
HistoGroupBase::Interval_t
Interval_t
Redefinition of fill intervals as in ManagedMonitorToolBase.
Definition: HistoGroupBase.h:37
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
JetHistoBase::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: JetHistoBase.cxx:16
HistosForJetSelection::fillHistosFromContainer
virtual int fillHistosFromContainer(const xAOD::JetContainer &cont, float weight)
Definition: HistosForJetSelection.cxx:79
h
ConstDataVector
DataVector adapter that acts like it holds const pointers.
Definition: ConstDataVector.h:76
HistosForJetSelection::LeadingJet
@ LeadingJet
Definition: HistosForJetSelection.h:53
HistosForJetSelection::AllJets
@ AllJets
Definition: HistosForJetSelection.h:52
HistoGroupBase::m_vBookedHistograms
std::vector< HistData > m_vBookedHistograms
The list of histos in this group.
Definition: HistoGroupBase.h:90
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
HistosForJetSelection::~HistosForJetSelection
virtual ~HistosForJetSelection()