ATLAS Offline Software
LArCollisionTimeMonAlg.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // ********************************************************************
6 //
7 // NAME: LArCollisionTimeMonAlg.cxx
8 // PACKAGE: LArMonitoring
9 //
10 // AUTHOR: Margherita Spalla (migrated from LArCollisionTimeMonTool by Vikas Bansal)
11 //
12 // Class for monitoring : EC timing from LArCollisionTime Container
13 
14 //
15 // ********************************************************************
16 
17 
18 
19 #include "LArCollisionTimeMonAlg.h"
22 
23 /*---------------------------------------------------------*/
24 LArCollisionTimeMonAlg::LArCollisionTimeMonAlg( const std::string& name, ISvcLocator* pSvcLocator )
25  : AthMonitorAlgorithm(name,pSvcLocator)
26 {}
27 
28 /*---------------------------------------------------------*/
30 {}
31 
32 /*---------------------------------------------------------*/
35 
36  //init handlers
39  ATH_CHECK( m_eventInfoDecorKey.initialize() );
41 }
42 
43 /*---------------------------------------------------------*/
44 /*
45 TO BE MOVED IN PYTHON
46  MonGroup generalGroupShift( this, "/LAr/"+m_histPath+"/", run, ATTRIB_MANAGED);
47  MonGroup generalGroupLB( this, "/LAr/"+m_histPath+"/", run, ATTRIB_X_VS_LB, "", "merge");
48 
49 */
50 
51 /*---------------------------------------------------------*/
53 LArCollisionTimeMonAlg::fillHistograms( const EventContext& ctx ) const
54 {
55  using namespace Monitored;
56 
57  ATH_MSG_DEBUG( "in fillHists()" );
58 
59  //monitored variables
60  auto ecTimeDiff = Monitored::Scalar<float>("ecTimeDiff",0.0);
61  auto ecTimeAvg = Monitored::Scalar<float>("ecTimeAvg",0.0);
62  auto lumi_block = Monitored::Scalar<unsigned int>("lumi_block",0);
63  auto lumi_block_timeWindow = Monitored::Scalar<float>("lumi_block_timeWindow",0);
64  auto lumi_block_singleBeam_timeWindow = Monitored::Scalar<float>("lumi_block_singleBeam_timeWindow",0);
65  auto bunch_crossing_id = Monitored::Scalar<unsigned int>("bunch_crossing_id",0);
66  auto weight = Monitored::Scalar<float>("weight",1.);
67 
69  ATH_CHECK(thisEvent.isValid());
70  // bunch crossing ID:
71  bunch_crossing_id = thisEvent->bcid();
72 
73  // luminosity block number
74  lumi_block = thisEvent->lumiBlock();
75 
77  if (!bcidHdl.isValid()) {
78  ATH_MSG_WARNING( "Unable to retrieve BunchCrossing conditions object" );
79  return StatusCode::SUCCESS;
80  }
81  const BunchCrossingCondData* bcData=*bcidHdl;
82 
83  if (!bcData->isFilled(bunch_crossing_id)) {
84  ATH_MSG_INFO("BCID: "<<bunch_crossing_id<<" empty ? not filling the coll. time" );
85  return StatusCode::SUCCESS; // not filling anything in empty bunches
86  }
87 
88  const int bcid_distance = bcData->distanceFromFront(bunch_crossing_id, BunchCrossingCondData::BunchCrossings);
89  ATH_MSG_DEBUG("BCID distance: "<<bcid_distance );
90 
91  // Retrieve LArCollision Timing information
93  if(! larTime.isValid())
94  {
95  ATH_MSG_WARNING( "Unable to retrieve LArCollisionTime with key " << m_LArCollisionTimeKey );
96  return StatusCode::SUCCESS; // Check if failure shd be returned. VB
97  } else {
98  ATH_MSG_DEBUG( "LArCollisionTime successfully retrieved from event store" );
99  }
100 
101  if(!thisEvent->isEventFlagBitSet(xAOD::EventInfo::LAr,LArEventBitInfo::NOISEBURSTVETO)) { // Do not fill histo if noise burst suspected
102 
103  // Calculate the time diff between ECC and ECA
104  ecTimeDiff = (larTime->timeC() - larTime->timeA())/m_timeUnit;
105  ecTimeAvg = (larTime->timeC() + larTime->timeA())/(m_timeUnit*2.);
106  if (larTime->ncellA() > m_minCells && larTime->ncellC() > m_minCells && std::fabs(ecTimeDiff) < m_timeCut/m_timeUnit ) { // Only fill histograms if a minimum number of cells were found and time difference was sensible
107 
108  ATH_MSG_DEBUG( "filling !" );
109  //set the weight if needed
110  if (m_eWeighted) weight = (larTime->energyA()+larTime->energyC())*1e-3;
111 
112  //fill your group
113  ATH_MSG_DEBUG( "time A = " << larTime->timeA() << " time C = " << larTime->timeC() << " diff = " << larTime->timeC() - larTime->timeA() << "saved diff = " << ecTimeDiff );
114  fill(m_MonGroupName,ecTimeDiff,ecTimeAvg,lumi_block,bunch_crossing_id,weight);
115 
116  //check timeWindow
117  lumi_block_timeWindow=lumi_block;
118  if ( fabs(ecTimeDiff) < 10*Gaudi::Units::nanosecond/m_timeUnit) fill(m_MonGroupName,lumi_block_timeWindow);
119 
120  //check singleBeam-timeWindow
121  lumi_block_singleBeam_timeWindow=lumi_block;
122  if ( fabs(ecTimeDiff) > 20*Gaudi::Units::nanosecond/m_timeUnit && fabs(ecTimeDiff) < 30*Gaudi::Units::nanosecond/m_timeUnit ) fill(m_MonGroupName,lumi_block_singleBeam_timeWindow);
123 
124  //check in-train (online only)
125  if(m_IsOnline && bcid_distance > m_distance) { // fill histos inside the train
126 
127  ATH_MSG_DEBUG("BCID: "<<bunch_crossing_id<<" distance from Front: "<<bcid_distance<<"Filling in train...");
128  if(m_InTrain_MonGroupName!="") { //group name is empty by default, give it a name when you define it in the python
129 
130  //fill the intrain group
131  fill(m_InTrain_MonGroupName,ecTimeDiff,ecTimeAvg,lumi_block,bunch_crossing_id,weight);
132  //check timeWindow
133  if ( fabs(ecTimeDiff) < 10*Gaudi::Units::nanosecond/m_timeUnit ) fill(m_InTrain_MonGroupName,lumi_block_timeWindow,weight);
134 
135  //check singleBeam-timeWindow
136  if ( fabs(ecTimeDiff) > 20*Gaudi::Units::nanosecond/m_timeUnit && fabs(ecTimeDiff) < 30*Gaudi::Units::nanosecond/m_timeUnit ) fill(m_InTrain_MonGroupName,lumi_block_singleBeam_timeWindow,weight);
137  }
138  else ATH_MSG_WARNING( "I should be filling the 'inTrain' group now, but it looks undefined. Did you remember to set 'm_InTrain_MonGroupName' in the python?" );
139  }
140  } else {
141  ATH_MSG_DEBUG( "LAr below cuts ncells: " << larTime->ncellA() << " " << larTime->ncellC() << " times: " << larTime->timeA() << " " <<larTime->timeC() << " " << std::fabs(ecTimeDiff) <<", not filling !" );
142  }
143  }
144 
145  return StatusCode::SUCCESS;
146 }
147 
148 
149 
LArCollisionTimeMonAlg.h
LArCollisionTimeMonAlg::~LArCollisionTimeMonAlg
virtual ~LArCollisionTimeMonAlg()
Default destructor.
Definition: LArCollisionTimeMonAlg.cxx:29
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
LArCollisionTimeMonAlg::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
Called each event.
Definition: LArCollisionTimeMonAlg.cxx:53
LArCollisionTime::energyC
double energyC() const
total energy C side
Definition: LArCollisionTime.h:39
BunchCrossingCondData
Definition: BunchCrossingCondData.h:23
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
LArCollisionTime::energyA
double energyA() const
total energy A side
Definition: LArCollisionTime.h:36
python.SystemOfUnits.nanosecond
int nanosecond
Definition: SystemOfUnits.py:119
LArCollisionTimeMonAlg::m_bunchCrossingKey
SG::ReadCondHandleKey< BunchCrossingCondData > m_bunchCrossingKey
Definition: LArCollisionTimeMonAlg.h:63
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
xAOD::EventInfo_v1::LAr
@ LAr
The LAr calorimeter.
Definition: EventInfo_v1.h:335
LArEventBitInfo.h
dqt_zlumi_pandas.weight
int weight
Definition: dqt_zlumi_pandas.py:189
AthMonitorAlgorithm
Base class for Athena Monitoring Algorithms.
Definition: AthMonitorAlgorithm.h:36
LArCollisionTime::ncellC
int ncellC() const
get number of cells for time C side
Definition: LArCollisionTime.h:33
LArEventBitInfo::NOISEBURSTVETO
@ NOISEBURSTVETO
Definition: LArEventBitInfo.h:13
LArCollisionTimeMonAlg::m_MonGroupName
Gaudi::Property< std::string > m_MonGroupName
Definition: LArCollisionTimeMonAlg.h:48
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:30
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
LArCollisionTimeMonAlg::LArCollisionTimeMonAlg
LArCollisionTimeMonAlg(const std::string &name, ISvcLocator *pSvcLocator)
Definition: LArCollisionTimeMonAlg.cxx:24
BunchCrossingCondData::BunchCrossings
@ BunchCrossings
Distance in units of 25 nanoseconds.
Definition: BunchCrossingCondData.h:132
LArCollisionTime::timeC
double timeC() const
time C side
Definition: LArCollisionTime.h:45
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
AthMonitorAlgorithm::fill
void fill(const ToolHandle< GenericMonitoringTool > &groupHandle, std::vector< std::reference_wrapper< Monitored::IMonitoredVariable >> &&variables) const
Fills a vector of variables to a group by reference.
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
LArCollisionTimeMonAlg::m_timeCut
Gaudi::Property< float > m_timeCut
Definition: LArCollisionTimeMonAlg.h:56
AthMonitorAlgorithm::GetEventInfo
SG::ReadHandle< xAOD::EventInfo > GetEventInfo(const EventContext &) const
Return a ReadHandle for an EventInfo object (get run/event numbers, etc.)
Definition: AthMonitorAlgorithm.cxx:107
xAOD::EventInfo_v1::lumiBlock
uint32_t lumiBlock() const
The current event's luminosity block number.
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
BunchCrossingCondData::distanceFromFront
int distanceFromFront(const bcid_type bcid, const BunchDistanceType type=NanoSec) const
The distance of the specific bunch crossing from the front of the train.
Definition: BunchCrossingCondData.cxx:38
LArCollisionTimeMonAlg::m_InTrain_MonGroupName
Gaudi::Property< std::string > m_InTrain_MonGroupName
Definition: LArCollisionTimeMonAlg.h:49
LArCollisionTimeMonAlg::m_eWeighted
Gaudi::Property< bool > m_eWeighted
Definition: LArCollisionTimeMonAlg.h:58
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
LArCollisionTimeMonAlg::m_eventInfoDecorKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_eventInfoDecorKey
Definition: LArCollisionTimeMonAlg.h:65
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
LArCollisionTimeMonAlg::m_LArCollisionTimeKey
SG::ReadHandleKey< LArCollisionTime > m_LArCollisionTimeKey
Definition: LArCollisionTimeMonAlg.h:61
LArCollisionTimeMonAlg::m_minCells
Gaudi::Property< int > m_minCells
Definition: LArCollisionTimeMonAlg.h:57
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
LArCollisionTime::ncellA
int ncellA() const
get number of cells for time A side
Definition: LArCollisionTime.h:30
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
LArCollisionTimeMonAlg::m_distance
Gaudi::Property< int > m_distance
Definition: LArCollisionTimeMonAlg.h:54
xAOD::EventInfo_v1::isEventFlagBitSet
bool isEventFlagBitSet(EventFlagSubDet subDet, size_t bit) const
Check one particular bit of one particular sub-detector.
Definition: EventInfo_v1.cxx:703
ReadDecorHandle.h
Handle class for reading a decoration on an object.
LArCollisionTime::timeA
double timeA() const
time A side
Definition: LArCollisionTime.h:42
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
LArCollisionTimeMonAlg::m_IsOnline
Gaudi::Property< bool > m_IsOnline
Definition: LArCollisionTimeMonAlg.h:55
xAOD::EventInfo_v1::bcid
uint32_t bcid() const
The bunch crossing ID of the event.
LArCollisionTimeMonAlg::m_timeUnit
Gaudi::Property< double > m_timeUnit
Definition: LArCollisionTimeMonAlg.h:53
BunchCrossingCondData::isFilled
bool isFilled(const bcid_type bcid) const
The simplest query: Is the bunch crossing filled or not?
Definition: BunchCrossingCondData.h:339
LArCollisionTimeMonAlg::initialize
virtual StatusCode initialize() override
Overwrite dummy method from AlgTool.
Definition: LArCollisionTimeMonAlg.cxx:34