13#include "EventInfo/EventInfo.h"
20 return (
e1.lumiBlock<
e2.lumiBlock);
25 return (
e1.runNumber<
e2.runNumber);
57 ATH_MSG_FATAL(
"FATAL ERROR: must provide at least one beamspot tool in beamSpotToolList");
58 return StatusCode::FAILURE;
73 return StatusCode::SUCCESS;
84 for(
auto & thisVertex: currentEvent.
vertices){
90 return StatusCode::SUCCESS;
97 return StatusCode::SUCCESS;
106 event.bcid = eventInfo.
bcid();
115 if(
evtStore()->retrieve(BSeventInfo) != StatusCode::SUCCESS){
121 event.lumiBlock = BSeventInfo->
event_ID()->lumi_block();
129 vertex.vxx = vtx->covariancePosition()(0,0);
130 vertex.vxy = vtx->covariancePosition()(0,1);
131 vertex.vyy = vtx->covariancePosition()(1,1);
132 vertex.vzz = vtx->covariancePosition()(2,2);
133 vertex.vertexType = vtx->vertexType();
134 vertex.nTracks = vtx->nTrackParticles();
136 vertex.valid = vertex.passed;
138 if(vertex.vxy*vertex.vxy/vertex.vxx/vertex.vyy > 1.0 ||
142 ATH_MSG_DEBUG(
"Bad vertex: " << event.eventNumber <<
" " << vtx->vertexType() <<
" "
143 << vertex.x <<
" " << vertex.y <<
" " << vertex.z <<
" "
144 << vertex.vxx <<
" " << vertex.vyy <<
" " << vertex.vzz <<
" "
145 << vertex.nTracks <<
" " << vertex.vxy*vertex.vxy/vertex.vxx/vertex.vyy);
150 vertex.vxx < 0.)
continue;
151 event.vertices.push_back( vertex );
169 unsigned int nRuns = 0;
170 unsigned int nLBs = 0;
171 unsigned int nFits = 1;
175 currentID = iter->first;
180 || currentID.
bcid() != lastID.
bcid()
184 << currentID.
pileup() <<
" <-- " << lastID.
pileup() <<
"\n\t"
185 << currentID.
bcid() <<
" <-- " << lastID.
bcid() <<
"\n\t"
193 for(
unsigned int i = 0; i < iter->second.size(); i++){
202 lastID = iter->first;
211 if ((*it) ==
"NoVtx") ;
223 ATH_MSG_DEBUG(
"No selection based on vertexType will be done" );
228 const int bcid = eventInfo.
bcid();
231 if ( !bcData->isFilled(bcid) )
return false;
240 if(!vtx) {
return false; }
246 if(vtx->covariancePosition()(0,0) <= 0 || vtx->covariancePosition()(1,1) <= 0 || vtx->covariancePosition()(2,2) <= 0 ) {
return false; }
248 if(vtx->covariancePosition()(0,0) > maxTransverseError2 || vtx->covariancePosition()(1,1) > maxTransverseError2) {
return false;}
253 const std::string inRootID =
"/INDETBEAMSPOTFINDER/";
255 m_root_vrt =
new TTree(svrts.data(),
"Vertices");
256 m_root_vrt->Branch(
"vrt",&
m_root_vtx,
"x/D:y:z:vxx:vxy:vyy:vzz:vType/i:run:lb:bcid:pileup:nTracks:eventNumber/l:eventTime:eventTime_NS:passed/O:valid");
262 std::vector<BeamSpot::VrtHolder> verticesToFit;
265 verticesToFit.clear();
266 if(eventList.size() > 0) {
268 ATH_MSG_INFO(
"Event list size/LB/bcid: " << eventList.size() <<
" " <<
ev.lumiBlock <<
" " <<
ev.bcid);
270 for(
const auto & thisEvent: eventList){
271 for(
const auto & thisVertex: thisEvent.vertices){
272 if( thisVertex.passed ) {
273 verticesToFit.push_back( thisVertex );
281 if(!bs){
return StatusCode::FAILURE; }
282 if(not verticesToFit.empty()) { bsFitStatus = bs->
fit(verticesToFit); }
304 return StatusCode::SUCCESS;
308 const std::string inRootID =
"/INDETBEAMSPOTFINDER/";
309 const std::string sbs =
"BeamSpotNt";
310 m_root_bs =
new TTree(sbs.data(),
"Beamspot Solutions");
329 std::map<std::string,double> paramMap = tool->getParamMap();
330 std::map<std::string,double> covMap = tool->getCovMap();
332 std::string slashD =
"/D";
333 std::string keySlashD;
336 for( std::map<std::string,double>::iterator iter = paramMap.begin(); iter != paramMap.end(); ++iter){
337 std::string key = iter->first;
339 if( !(
m_root_bs->GetBranch(key.c_str())) ){
341 keySlashD = key + slashD;
346 for( std::map<std::string,double>::iterator iter = covMap.begin(); iter != covMap.end(); ++iter){
347 const std::string & key = iter->first;
349 if( !(
m_root_bs->GetBranch(key.c_str())) ){
351 keySlashD = key + slashD;
383 unsigned int sz =
a.size();
386 for (
unsigned int i = 0; i <
sz; ++i)
401 unsigned int nVtxAll = 0;
402 unsigned int nVtxPrim = 0;
404 for(
const auto & thisEvent : eventList){
405 const auto & theseVertices=thisEvent.vertices;
406 nVtxAll += theseVertices.size();
407 nVtxPrim+= std::count_if(theseVertices.begin(), theseVertices.end(), isPrimaryVertex);
418 const auto & bsToolCovMap= bs->
getCovMap();
420 const std::string & key = param.first;
421 const auto & bsToolEquivalent =bsToolParamMap.find(key);
422 param.second = ( bsToolEquivalent == bsToolParamMap.end() ) ? 0 : bsToolEquivalent->second;
432 const std::string & key = covariance.first;
433 const auto & bsToolEquivalent = bsToolCovMap.find(key);
434 covariance.second = ( bsToolEquivalent == bsToolCovMap.end() ) ? 0 : bsToolEquivalent->second;
453 const auto smallestLbEvent=std::min_element(eventList.begin(),eventList.end(), lesserLumiBlock);
454 return smallestLbEvent->lumiBlock;
458 const auto largestLbEvent=std::max_element(eventList.begin(),eventList.end(), lesserLumiBlock);
459 return largestLbEvent->lumiBlock;
463 const auto smallestRunEvent=std::min_element(eventList.begin(),eventList.end(), lesserRunNumber);
464 return smallestRunEvent->runNumber;
468 const auto largestRunEvent=std::max_element(eventList.begin(),eventList.end(), lesserRunNumber);
469 return largestRunEvent->runNumber;
#define ATH_CHECK
Evaluate an expression and check for errors.
void tolower(std::string &s)
This class provides a unique identification for each event, in terms of run/event number and/or a tim...
AthAlgorithm(const std::string &name, ISvcLocator *pSvcLocator)
Constructor with parameters:
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T, V, H > &t)
ServiceHandle< StoreGateSvc > & evtStore()
unsigned int pileup() const
unsigned int lumiBlock() const
unsigned int bcid() const
unsigned long timeStamp() const
unsigned int runNumber() const
EventID * event_ID()
the unique identification of the event.
std::vector< BeamSpot::Event > m_eventList
virtual StatusCode finalize() override
std::map< BeamSpot::ID, std::vector< BeamSpot::Event > > m_eventMap
ServiceHandle< IToolSvc > m_toolSvc
void writeToBeamSpotTree(const IInDetBeamSpotTool *bs, std::vector< BeamSpot::Event > &, std::vector< BeamSpot::VrtHolder > &)
virtual StatusCode initialize() override
bool iequals(const std::string &, const std::string &)
SG::ReadHandleKey< xAOD::VertexContainer > m_vertexContainer
bool passVertexSelection(const xAOD::Vertex *)
std::vector< std::string > m_vertexTypeNames
double m_maxTransverseError
int min_run(std::vector< BeamSpot::Event > &)
void convertVtxTypeNames()
void writeToVertexTree(BeamSpot::Event &, BeamSpot::VrtHolder &)
StatusCode setupVertexTree()
std::vector< xAOD::VxType::VertexType > m_vertexTypes
bool m_useFilledBCIDsOnly
ToolHandleArray< IInDetBeamSpotTool > m_beamSpotToolList
SG::ReadCondHandleKey< BunchCrossingCondData > m_bcDataKey
unsigned long m_secondsPerFit
std::vector< std::vector< BeamSpot::Event > > m_sortedEventList
int max_run(std::vector< BeamSpot::Event > &)
BeamSpot::Event readEvent(const xAOD::EventInfo &, const xAOD::VertexContainer &)
virtual StatusCode execute() override
InDetBeamSpotFinder(const std::string &name, ISvcLocator *pSvcLocator)
ServiceHandle< ITHistSvc > m_thistSvc
int min_lb(std::vector< BeamSpot::Event > &)
std::vector< unsigned int > m_BCIDsToAccept
IInDetBeamSpotTool * cloneTool(int)
std::string m_vertexTreeName
unsigned int m_maxRunsPerFit
int max_lb(std::vector< BeamSpot::Event > &)
SG::ReadHandleKey< xAOD::EventInfo > m_eventInfo
BeamSpotStatusCode m_BeamStatusCode
unsigned int m_minVertexNum
bool passEventSelection(const xAOD::EventInfo &)
unsigned int m_maxEventsPerFit
vertexNtuple_struct m_root_vtx
beamSpotNtuple_struct m_beamSpotNtuple
std::string m_fitSortingKey
unsigned int m_maxLBsPerFit
StatusCode setupBeamSpotTree()
uint32_t lumiBlock() const
The current event's luminosity block number.
bool eventType(EventType type) const
Check for one particular bitmask value.
uint32_t bcid() const
The bunch crossing ID of the event.
float actualInteractionsPerCrossing() const
Average interactions per crossing for the current BCID - for in-time pile-up.
uint32_t timeStamp() const
POSIX time in seconds from 1970. January 1st.
@ IS_SIMULATION
true: simulation, false: data
uint32_t runNumber() const
The current event's run number.
uint32_t timeStampNSOffset() const
Nanosecond time offset wrt. the time stamp.
uint64_t eventNumber() const
The current event's event number.
size_t nTrackParticles() const
Get the number of tracks associated with this vertex.
float numberDoF() const
Returns the number of degrees of freedom of the vertex fit as float.
VxType::VertexType vertexType() const
The type of the vertex.
float chiSquared() const
Returns the of the vertex fit as float.
double e2(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 2nd sampling
double e1(const xAOD::CaloCluster &cluster)
return the uncorrected cluster energy in 1st sampling
@ V0Vtx
Vertex from V0 decay.
@ ConvVtx
Conversion vertex.
@ NotSpecified
Default value, no explicit type set.
@ SecVtx
Secondary vertex.
@ NoVtx
Dummy vertex. TrackParticle was not used in vertex fit.
EventInfo_v1 EventInfo
Definition of the latest event info version.
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
std::vector< BeamSpot::VrtHolder > vertices
xAOD::VxType::VertexType vertexType