ATLAS Offline Software
HIEventSelectionTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
3 */
4 
9 //#include "HIPileupTool/HIPileupTool.h"
11 
12 #include <TString.h>
13 
14 #include <iomanip>
15 #include <iostream>
16 
17 namespace HI
18 {
19 
20  const std::string HIEventSelectionTool::m_VERTEX_CNAME="PrimaryVertices";
21  const std::string HIEventSelectionTool::m_MBTS_CNAME="MBTSContainer";
22  const std::string HIEventSelectionTool::m_FWD_CNAME="MBTSForwardEventInfo";
23  const std::string HIEventSelectionTool::m_ZDC_CNAME="ZdcModules";
24  const std::string HIEventSelectionTool::m_SHAPE_CNAME="CaloSums"; //HIEventShape
25 
26  HIEventSelectionTool::HIEventSelectionTool(const std::string& name) : asg::AsgTool(name),
27  m_name(name),
28  m_accept("HIEventSelection"),
29  m_vertexSelectionTool(""),
30  m_hiPileupTool("")
31  {
32  // MBTS timing cut
33  declareProperty("TimeCut",m_timeCut,"maximum DeltaT cut for MBTS timing cut");
34  // Vertex
35  declareProperty("VertexSumPtCut",m_vtx_min_sumPt,"Minimum sum pT from good tracks for a good vertex");
36  declareProperty("VertexNtrkCut",m_vtx_min_nTrk,"Minimum number good tracks for a good vertex");
37  declareProperty("RejectPileup",m_reject_pileup,"If true, cut on events w/ pileup applied");
38  declareProperty("ExclusiveMode",m_exclusive_mode,"returns at first failure (for speed), doesn't evaluate subsequent cuts");
39  declareProperty("VertexSelectionTool",m_vertexSelectionTool);
40  declareProperty("PileupTool",m_hiPileupTool);
41 
42  ATH_MSG_DEBUG("Creating HIEventSelectionTool named" << m_name);
43  }
44 
46  {
47  ATH_MSG_DEBUG(Form("Deleting HIEventSelectionTool named %s",m_name.c_str()));
48  }
49 
51  {
52  if (m_timeCut > 0.) {
53  m_checkTime = true;
54  ATH_MSG_INFO( "Maximum delta t = " << m_timeCut );
55  m_accept.addCut("goodMBTSTime","good MBTS timing");
56  }
57 
58  m_accept.addCut("hasPrimaryVertex","has at least one primary vertex");
59 
60  m_accept.addCut("pileupVeto","reject events with topological features indicating pileup");
61 
62  if (m_vertexSelectionTool.empty())
63  {
64 #ifdef ROOTCORE
65  HI::HIVertexSelectionTool* vxSelTool = new HIVertexSelectionTool("HIVxSel");
66  ATH_CHECK( vxSelTool->initialize() );
67  m_vertexSelectionTool = ToolHandle<HI::IHIVertexSelectionTool>(vxSelTool);
68 #endif
69  }
70  ATH_CHECK( m_vertexSelectionTool.retrieve() );
71 
72  if (m_hiPileupTool.empty())
73  {
74 #ifdef ROOTCORE
75  HI::HIPileupTool* m_hipileuptool = new HIPileupTool("HIpileup");
76  ATH_CHECK( m_hipileuptool->initialize() );
77  m_hiPileupTool = ToolHandle<HI::IHIPileupTool>(m_hipileuptool);
78 #endif
79  }
80  ATH_CHECK( m_hiPileupTool.retrieve() );
81 
82  return StatusCode::SUCCESS;
83  }
84 
86 {
87 
88  ATH_MSG_INFO( "Finalizing event selection tool." );
89  return StatusCode::SUCCESS;
90 
91 }
92 
94  {
95  asg::AcceptData acceptData ( &m_accept );
96  if(m_checkTime){
97  checkMBTSTime( acceptData );
98  }
99  checkVertex( acceptData );
100  return m_accept;
101  }
102 
103  //R.Longo - 14/10/2019 - From checkMBTSTime to checkMBTSTime( asg::AcceptData& acceptData )
105  {
106  const xAOD::ForwardEventInfoContainer* forwardEventInfoContainer = 0;
107  if(evtStore()->retrieve(forwardEventInfoContainer,m_FWD_CNAME).isFailure())
108  {
109  ATH_MSG_ERROR("Could not retrieve ForwardEventInfo object w/ name " << m_FWD_CNAME);
110  return;
111  }
112 
113  acceptData.setCutResult("goodMBTSTime",false);
114  const xAOD::ForwardEventInfo* forwardEventInfo = forwardEventInfoContainer->at(0);
115  int countA = forwardEventInfo->countA();
116  int countC = forwardEventInfo->countC();
117  float timeA = forwardEventInfo->timeA();
118  float timeC = forwardEventInfo->timeC();
119 
120  if (countA==0||countC==0) return; // if either time undefined, return false;
121 
122  float timeDiff = timeA - timeC;
123 
124  if ( (std::abs(timeDiff)<m_timeCut) ) acceptData.setCutResult("goodMBTSTime",true);
125 
126  return;
127  }
128 
129 
130  //R.Longo - 14/10/2019 - Introducting acceptData instead of m_accept
132  {
133  asg::AcceptData acceptData ( &m_accept );
134  std::stringstream ss;
135  for(unsigned int icut=0; icut < acceptData.getNCuts(); icut++)
136  {
137  std::string cname=acceptData.getCutName(icut);
138  ss << std::setw(15) << cname
139  << std::setw(10) << acceptData.getCutResult(cname)
140  << std::setw(40) << acceptData.getCutDescription(cname)
141  << std::endl;
142  }
143  return ss.str();
144  }
145 
146 //R.Longo - 14/10/2019 - From checkVertex to checkVertex( asg::AcceptData& acceptData )
148  {
149  unsigned int numPrimaryVertices=getNPrimaryVertices();
150  acceptData.setCutResult("hasPrimaryVertex", (numPrimaryVertices > 0) );
151 
152  const xAOD::ZdcModuleContainer* zdcMod = 0;
153  if(evtStore()->retrieve(zdcMod,m_ZDC_CNAME).isFailure())
154  {
155  ATH_MSG_ERROR("Could not retrieve ZdcModule object w/ name " << m_ZDC_CNAME);
156  return;
157  }
158 
159  const xAOD::HIEventShapeContainer* hiev = 0;
160  if(evtStore()->retrieve(hiev,m_SHAPE_CNAME).isFailure())
161  {
162  ATH_MSG_ERROR("Could not retrieve HIEventShape object w/ name " << m_SHAPE_CNAME);
163  return;
164  }
165 
166  if (m_reject_pileup) acceptData.setCutResult("pileupVeto", m_hiPileupTool->is_pileup( *hiev, *zdcMod ));
167  else acceptData.setCutResult("pileupVeto", true );
168 
169 
170  return;
171  }
172 
173 
175  {
176  unsigned int nPriVx = 0;
177 
178  const xAOD::VertexContainer* pv_container = 0;
179  if(evtStore()->retrieve(pv_container,m_VERTEX_CNAME).isFailure())
180  {
181  ATH_MSG_ERROR("Could not retrieve VertexContainer object w/ name " << m_VERTEX_CNAME);
182  return 0;
183  }
184  //if( pv_container->size() < 2) return 0;
185 
186  for(const auto vert: *pv_container)
187  {
188  if (m_vertexSelectionTool->accept(*vert)) nPriVx++;
189  }
190 
191  return nPriVx;
192 
193  }
194 
195 } // HI
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
xAOD::ForwardEventInfo_v1::countC
unsigned short countC() const
HI::HIEventSelectionTool::m_MBTS_CNAME
static const std::string m_MBTS_CNAME
Definition: HIEventSelectionTool.h:43
HI::HIEventSelectionTool::getNPrimaryVertices
unsigned int getNPrimaryVertices() const
Definition: HIEventSelectionTool.cxx:174
HI::HIEventSelectionTool::m_name
const std::string m_name
Definition: HIEventSelectionTool.h:49
HI::HIEventSelectionTool::checkMBTSTime
void checkMBTSTime(asg::AcceptData &acceptData) const
Definition: HIEventSelectionTool.cxx:104
HI::HIEventSelectionTool::m_vertexSelectionTool
ToolHandle< HI::IHIVertexSelectionTool > m_vertexSelectionTool
Definition: HIEventSelectionTool.h:57
HI::HIEventSelectionTool::dumpSelection
std::string dumpSelection() const
Definition: HIEventSelectionTool.cxx:131
asg::AcceptData::getNCuts
unsigned int getNCuts() const
Get the number of cuts defined.
Definition: AcceptData.h:64
asg::AcceptData::getCutDescription
const std::string & getCutDescription(const std::string &cutName) const
Get the description of a cut, based on the cut name.
Definition: AcceptData.h:85
PowhegControl_ttHplus_NLO.ss
ss
Definition: PowhegControl_ttHplus_NLO.py:83
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
HI::HIPileupTool
Definition: HIPileupTool.h:27
ForwardEventInfoContainer.h
HIVertexSelectionTool.h
HI::HIEventSelectionTool::m_ZDC_CNAME
static const std::string m_ZDC_CNAME
Definition: HIEventSelectionTool.h:47
HI::HIEventSelectionTool::m_accept
asg::AcceptInfo m_accept
Definition: HIEventSelectionTool.h:50
asg
Definition: DataHandleTestTool.h:28
HI::HIEventSelectionTool::m_hiPileupTool
ToolHandle< HI::IHIPileupTool > m_hiPileupTool
Definition: HIEventSelectionTool.h:58
HI::HIEventSelectionTool::m_FWD_CNAME
static const std::string m_FWD_CNAME
Definition: HIEventSelectionTool.h:44
HI::HIEventSelectionTool::m_VERTEX_CNAME
static const std::string m_VERTEX_CNAME
Definition: HIEventSelectionTool.h:45
xAOD::ForwardEventInfo_v1::timeC
float timeC() const
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
asg::AcceptInfo
Definition: AcceptInfo.h:28
HI::HIEventSelectionTool::m_checkTime
bool m_checkTime
Definition: HIEventSelectionTool.h:53
HI::HIEventSelectionTool::m_reject_pileup
bool m_reject_pileup
Definition: HIEventSelectionTool.h:62
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
HI::HIVertexSelectionTool
Definition: HIVertexSelectionTool.h:19
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
HI::HIEventSelectionTool::m_vtx_min_sumPt
float m_vtx_min_sumPt
Definition: HIEventSelectionTool.h:59
xAOD::ForwardEventInfo_v1::timeA
float timeA() const
DataVector
Derived DataVector<T>.
Definition: DataVector.h:581
asg::AcceptData::getCutName
const std::string & getCutName(unsigned int cutPosition) const
Get the name of a cut, based on the cut position (slow, avoid usage)
Definition: AcceptData.h:78
HI
Definition: HIEventDefs.h:14
HI::HIVertexSelectionTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: HIVertexSelectionTool.cxx:29
HI::HIEventSelectionTool::m_timeCut
float m_timeCut
Definition: HIEventSelectionTool.h:54
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
HIEventSelectionTool.h
HI::HIEventSelectionTool::m_vtx_min_nTrk
int m_vtx_min_nTrk
Definition: HIEventSelectionTool.h:60
VertexContainer.h
HI::HIEventSelectionTool::~HIEventSelectionTool
virtual ~HIEventSelectionTool()
Definition: HIEventSelectionTool.cxx:45
asg::AcceptData::setCutResult
void setCutResult(const std::string &cutName, bool cutResult)
Set the result of a cut, based on the cut name (safer)
Definition: AcceptData.h:134
asg::AcceptData::getCutResult
bool getCutResult(const std::string &cutName) const
Get the result of a cut, based on the cut name (safer)
Definition: AcceptData.h:98
xAOD::ForwardEventInfo_v1::countA
unsigned short countA() const
HI::HIEventSelectionTool::finalize
virtual StatusCode finalize() override
Definition: HIEventSelectionTool.cxx:85
HI::HIEventSelectionTool::HIEventSelectionTool
HIEventSelectionTool(const std::string &name="HIEventSelection")
Definition: HIEventSelectionTool.cxx:26
xAOD::ForwardEventInfo_v1
add description
Definition: ForwardEventInfo_v1.h:17
HI::HIPileupTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: HIPileupTool.cxx:45
HI::HIEventSelectionTool::m_exclusive_mode
bool m_exclusive_mode
Definition: HIEventSelectionTool.h:61
DataVector::at
const T * at(size_type n) const
Access an element, as an rvalue.
HI::HIEventSelectionTool::m_SHAPE_CNAME
static const std::string m_SHAPE_CNAME
Definition: HIEventSelectionTool.h:46
asg::AcceptData
Definition: AcceptData.h:30
HI::HIEventSelectionTool::checkVertex
void checkVertex(asg::AcceptData &acceptData) const
Definition: HIEventSelectionTool.cxx:147
HI::HIEventSelectionTool::initialize
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
Definition: HIEventSelectionTool.cxx:50
HI::HIEventSelectionTool::getAcceptInfo
virtual const asg::AcceptInfo & getAcceptInfo() const override
Definition: HIEventSelectionTool.cxx:93
HIPileupTool.h
asg::AcceptInfo::addCut
int addCut(const std::string &cutName, const std::string &cutDescription)
Add a cut; returning the cut position.
Definition: AcceptInfo.h:53