ATLAS Offline Software
DQTBackgroundMon.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 DQTBackgroundMon::DQTBackgroundMon( const std::string& name, ISvcLocator* pSvcLocator )
8 : AthMonitorAlgorithm(name,pSvcLocator)
9 {}
10 
12 
14  ATH_CHECK( m_LArCollisionTimeKey.initialize() );
15  ATH_CHECK( m_MBTSCollisionTimeKey.initialize() );
16  ATH_CHECK( m_TileCellContainerKey.initialize() );
17  ATH_CHECK( m_LUCID_RawDataContainerKey.initialize() );
18  ATH_CHECK( m_BeamBackgroundDataKey.initialize() );
19  ATH_CHECK( m_VertexContainerKey.initialize() );
20  ATH_CHECK( m_eventInfoDecorKey.initialize() );
21  ATH_CHECK( m_sctSpacePointKey.initialize() );
22  ATH_CHECK( m_pixSpacePointKey.initialize() );
24 }
25 
26 StatusCode DQTBackgroundMon::fillHistograms( const EventContext& ctx ) const {
27  ATH_MSG_DEBUG("In DQTBackgroundMon::fillHistograms()");
28  using namespace Monitored;
29 
30  auto group = getGroup("default");
31 
32  auto filled = Scalar<bool>("filled",false);
33  auto empty = Scalar<bool>("empty",false);
34  auto unpairIso = Scalar<bool>("unpairIso",false);
35  auto unpairNonIso = Scalar<bool>("unpairNonIso",false);
36 
37  RH<xAOD::EventInfo> eventInfo{GetEventInfo(ctx)};
42  RH<TileCellContainer> tileCellContainer(m_TileCellContainerKey,ctx);
44  RH<BeamBackgroundData> beamBackgroundData(m_BeamBackgroundDataKey,ctx);
46 
47  if ( eventInfo.isValid() ) {
48  if (!getTrigDecisionTool().empty()) {
49  unsigned int bgCode = getTrigDecisionTool()->getBGCode();
50  filled = bgCode & (1<<m_filledBG);
51  empty = bgCode & (1<<m_emptyBG);
52  unpairIso = bgCode & (1<<m_unpairIsoBG);
53  unpairNonIso = bgCode & (1<<m_unpairNonIsoBG);
54  }
55 
56  std::vector<int> bitVec = {};
57  std::vector<int> filledVec = {};
58  std::vector<int> emptyVec = {};
59  std::vector<int> unpairIsoVec = {};
60  std::vector<int> unpairNonIsoVec = {};
61 
62  for ( int bkg=0; bkg<m_nBkgWords; bkg++ ) {
63  unsigned int bgWord = eventInfo->eventFlags(xAOD::EventInfo::Background);
64  ATH_MSG_DEBUG("Background word is "<<bgWord);
65  if ( !(bgWord & 1<<bkg) ) {
66  continue;
67  }
68 
69  bitVec.push_back(bkg);
70  if (filled) {
71  filledVec.push_back(bkg);
72  } else if (empty) {
73  emptyVec.push_back(bkg);
74  } else if (unpairIso) {
75  unpairIsoVec.push_back(bkg);
76  } else if (unpairNonIso) {
77  unpairNonIsoVec.push_back(bkg);
78  }
79  }
80 
81  auto bitSet = Collection("bitSet",bitVec);
82  auto bitSetFilled = Collection("bitSetFilled",filledVec);
83  auto bitSetEmpty = Collection("bitSetEmpty",emptyVec);
84  auto bitSetUnpairIso = Collection("bitSetUnpairIso",unpairIsoVec);
85  auto bitSetUnpairNonIso = Collection("bitSetUnpairNonIso",unpairNonIsoVec);
86  fill(group,bitSet,bitSetFilled,bitSetEmpty,bitSetUnpairIso,bitSetUnpairNonIso);
87  } else {
88  ATH_MSG_WARNING("Event data invalid. Background word histograms are being skipped.");
89  }
90 
91 
92 
93  if (sctSP.isValid() and pixSP.isValid()) {
94  auto nSctSPs = Scalar<float>("nSctSPs",0.0);
95  std::for_each(sctSP->begin(),sctSP->end(),[&nSctSPs](const auto coll){if (coll) nSctSPs+=coll->size();});
96 
97  auto nPixSPs = Scalar<float>("nPixSPs",0.0);
98  std::for_each(pixSP->begin(),pixSP->end(),[&nPixSPs](const auto coll){if (coll) nPixSPs+=coll->size();});
99 
100  fill(group,nPixSPs,nSctSPs,unpairIso,unpairNonIso);
101  if ( nPixSPs<m_upPixSP ){
102  fill("lowMultiplicityPixGroup",nPixSPs,unpairIso,unpairNonIso);
103  }
104  if ( nSctSPs<m_upSctSP ) {
105  fill("lowMultiplicitySctGroup",nSctSPs,unpairIso,unpairNonIso);
106  }
107  } else {
108  ATH_MSG_WARNING("Pixe/SCT Spacepoint data invalid. nPix/nSct is being skipped.");
109  }
110 
111  if ( tps.isValid() ) {
112  if ( tps->ncellA()>m_LArECSideCut && tps->ncellC()>m_LArECSideCut ) {
113  auto LArECTimeDiff = Scalar<float>("LArECTimeDiff", tps->timeA()-tps->timeC());
114  fill(group,LArECTimeDiff);
115  }
116  } else {
117  ATH_MSG_WARNING("TPS data invalid. LArECTimeDiff is being skipped.");
118  }
119 
120  if ( mbtsTime.isValid() ) {
121  if ( mbtsTime->ncellA()>m_MBTSSideCut && mbtsTime->ncellC()>m_MBTSSideCut ) {
122  auto MBTStimeDiff = Scalar<float>("MBTStimeDiff", mbtsTime->time());
123  fill(group,MBTStimeDiff);
124  }
125  } else {
126  ATH_MSG_WARNING("MBTSCollisionTime data invalid. MBTStimeDiff is being skipped.");
127  }
128 
129  if ( tileCellContainer.isValid() ) {
130  auto MBTSCount = Scalar<int>("MBTSvetoHits",0);
131  for ( auto tileCell : *tileCellContainer ) {
132  if (tileCell->energy()>m_MBTSThresholdCut &&
133  (tileCell->qbit1() & m_MBTSMask)==m_MBTSPattern &&
134  fabs(tileCell->time())<m_MBTSTimeCut )
135  MBTSCount++;
136  }
137  fill(group,MBTSCount);
138  } else {
139  ATH_MSG_WARNING("TileCell data invalid. MBTSvetoHits is being skipped.");
140  }
141 
142  if ( LUCID_RawDataContainer.isValid() ) {
143  auto LUCIDCounter = Scalar<int>("LUCIDCounter",0);
144  for ( auto LUCID_RawData : *LUCID_RawDataContainer ) {
146  }
147  fill(group,LUCIDCounter);
148  } else {
149  ATH_MSG_WARNING("LUCID data invalid. LUCID is being skipped.");
150  }
151 
152  if ( m_doMuons ) {
153  if (beamBackgroundData.isValid() ) {
154  // Muon segments and clusters
155  std::vector<double> muSegXVec = {};
156  std::vector<double> muSegYVec = {};
157  for (int iSeg=0; iSeg<beamBackgroundData->GetNumSegment(); iSeg++) {
158  const Trk::Segment* trkSeg = beamBackgroundData->GetIndexSeg(iSeg);
159  const xAOD::MuonSegment* muonSeg = dynamic_cast<const xAOD::MuonSegment*>(trkSeg);
160  if (muonSeg) {
161  muSegXVec.push_back(muonSeg->x()*1e-3);
162  muSegYVec.push_back(muonSeg->y()*1e-3);
163  }
164  }
165  auto muSegXCollection = Collection("muonSegmentX",muSegXVec);
166  auto muSegYCollection = Collection("muonSegmentY",muSegYVec);
167 
168  std::vector<double> clusterEnergyVec = {};
169  std::vector<double> clusterEtaVec = {};
170  std::vector<double> clusterPhiVec = {};
171  std::vector<double> clusterTimeVec = {};
172  for (int i=0; i<beamBackgroundData->GetNumMatched(); i++) {
173  const xAOD::CaloCluster* cluster = beamBackgroundData->GetIndexClus(i);
174  clusterEnergyVec.push_back(cluster->e()*1e-3);
175  clusterEtaVec.push_back(cluster->eta());
176  clusterPhiVec.push_back(cluster->phi());
177  clusterTimeVec.push_back(cluster->time());
178  }
179  auto clusterEnergyCollection = Collection("clusterEnergy",clusterEnergyVec);
180  auto clusterEtaCollection = Collection("clusterEta",clusterEtaVec);
181  auto clusterPhiCollection = Collection("clusterPhi",clusterPhiVec);
182  auto clusterTimeCollection = Collection("clusterTime",clusterTimeVec);
183 
184  fill(group,muSegXCollection,muSegYCollection,clusterEnergyCollection,
185  clusterEtaCollection,clusterPhiCollection,clusterTimeCollection);
186 
187  // fake jets
188  if ( beamBackgroundData->GetNumNoTimeTight() ) {
189  std::vector<int> jetIndexVec = {};
190  for (int i=0; i<beamBackgroundData->GetNumJet(); i++) {
191  const xAOD::Jet* jet = beamBackgroundData->GetIndexJet(i);
192  int jetIndex = beamBackgroundData->GetIndexJet(jet);
193  jetIndexVec.push_back(jetIndex);
194 
195  // Leading jet
196  if ( jetIndex==0 ) {
197  auto pt = Scalar<double>("leadingJetPt", jet->pt());
198  auto eta = Scalar<double>("leadingJetEta", jet->eta());
199  auto phi = Scalar<double>("leadingJetPhi", jet->phi());
200  double timeValue = jet->getAttribute<float>(xAOD::JetAttribute::Timing);
201  auto time = Scalar<double>("leadingJetTime", timeValue);
202  double emfValue = jet->getAttribute<float>(xAOD::JetAttribute::EMFrac);
203  auto emf = Scalar<double>("leadingJetEMFrac", emfValue);
204 
205  std::vector<float> sumPt_v;
206  auto trkPtAttr = xAOD::JetAttribute::SumPtTrkPt1000;
207  bool hasSumPt = jet->getAttribute<std::vector<float>>(trkPtAttr, sumPt_v);
208  double sumPtTrk = hasSumPt ? sumPt_v[0] : 0.;
209  auto chf = Scalar<double>("leadingJetCHF", sumPtTrk / pt);
210 
211  fill(group,pt,eta,phi,time,emf,chf);
212  }
213  }
214  auto jetIndexCollection = Collection("jetIndex",jetIndexVec);
215 
216  auto bcid = Scalar<int>("bcid",2);
217  auto isAC = Scalar<bool>("isAC", beamBackgroundData->GetDirection()>0);
218  auto isCA = Scalar<bool>("isCA", beamBackgroundData->GetDirection()<0);
219  bool isOneSided = beamBackgroundData->GetNumOneSidedLoose();
220  auto isACOneSided = Scalar<bool>("isACOneSided", isAC && isOneSided );
221  auto isCAOneSided = Scalar<bool>("isCAOneSided", isCA && isOneSided );
222  fill(group,jetIndexCollection,bcid,isAC,isCA,isACOneSided,isCAOneSided);
223  } // end fake jets
224  } else {
225  ATH_MSG_WARNING("BeamBackgroundData data invalid. Muons are being skipped.");
226  }
227  } // end muons
228 
229  if (vertexContainer.isValid()) {
230  // count vertices, excluding the dummy vertex
231  auto nVertex = Scalar<int>("nVertex", vertexContainer->size()-1);
232  fill(group,nVertex,unpairIso,unpairNonIso);
233  } else {
234  ATH_MSG_DEBUG("Primary vertex data invalid. Primary vertex counts are being skipped.");
235  }
236  return StatusCode::SUCCESS;
237 }
DQTBackgroundMon::m_LArECSideCut
GP< int > m_LArECSideCut
Definition: DQTBackgroundMon.h:63
xAOD::CaloCluster_v1::phi
virtual double phi() const
The azimuthal angle ( ) of the particle.
Definition: CaloCluster_v1.cxx:256
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
DQTBackgroundMon::m_MBTSThresholdCut
GP< float > m_MBTSThresholdCut
Definition: DQTBackgroundMon.h:66
xAOD::CaloCluster_v1::time
flt_t time() const
Access cluster time.
DQTBackgroundMon::m_VertexContainerKey
RHK< xAOD::VertexContainer > m_VertexContainerKey
Definition: DQTBackgroundMon.h:44
xAOD::MuonSegment_v1::x
float x() const
MBTSCollisionTime::time
double time() const
time difference A - C
Definition: MBTSCollisionTime.h:55
BeamBackgroundData::GetNumSegment
int GetNumSegment() const
Definition: BeamBackgroundData.h:74
Merge_LAr_blobs.filled
list filled
Definition: Merge_LAr_blobs.py:43
DQTBackgroundMon::m_MBTSCollisionTimeKey
RHK< MBTSCollisionTime > m_MBTSCollisionTimeKey
Definition: DQTBackgroundMon.h:40
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
MBTSCollisionTime::ncellC
int ncellC() const
get number of cells for time C side
Definition: MBTSCollisionTime.h:34
xAOD::bgCode
bgCode
Definition: TrigDecision_v1.cxx:39
DQTBackgroundMon::m_LArCollisionTimeKey
RHK< LArCollisionTime > m_LArCollisionTimeKey
Definition: DQTBackgroundMon.h:39
BeamBackgroundData::GetIndexSeg
int GetIndexSeg(const Trk::Segment *seg) const
This function looks for the muon segment among the beam halo muon candidates.
Definition: BeamBackgroundData.cxx:13
DQTBackgroundMon::m_doMuons
GP< bool > m_doMuons
Definition: DQTBackgroundMon.h:36
BeamBackgroundData::GetNumJet
int GetNumJet() const
Definition: BeamBackgroundData.h:88
DQTBackgroundMon::m_sctSpacePointKey
RHK< SpacePointContainer > m_sctSpacePointKey
Definition: DQTBackgroundMon.h:45
AthMonitorAlgorithm::getTrigDecisionTool
const ToolHandle< Trig::TrigDecisionTool > & getTrigDecisionTool() const
Get the trigger decision tool member.
Definition: AthMonitorAlgorithm.cxx:189
test_pyathena.pt
pt
Definition: test_pyathena.py:11
DQTBackgroundMon.h
xAOD::MuonSegment_v1
Class describing a MuonSegment.
Definition: MuonSegment_v1.h:33
DQTBackgroundMon::m_MBTSMask
GP< int > m_MBTSMask
Definition: DQTBackgroundMon.h:67
DQTBackgroundMon::m_unpairNonIsoBG
GP< int > m_unpairNonIsoBG
Definition: DQTBackgroundMon.h:58
xAOD::EventInfo_v1::Background
@ Background
The beam background detectors.
Definition: EventInfo_v1.h:340
empty
bool empty(TH1 *h)
Definition: computils.cxx:295
BeamBackgroundData::GetIndexJet
int GetIndexJet(const xAOD::Jet *jet) const
This function looks for the jet among the fake jets candidates.
Definition: BeamBackgroundData.cxx:51
LUCID_RawData
Definition: LUCID_RawData.h:40
Monitored::Collection
ValuesCollection< T > Collection(std::string name, const T &collection)
Declare a monitored (double-convertible) collection.
Definition: MonitoredCollection.h:38
DQTBackgroundMon::initialize
virtual StatusCode initialize() override
initialize
Definition: DQTBackgroundMon.cxx:13
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
BeamBackgroundData::GetDirection
int GetDirection() const
Definition: BeamBackgroundData.h:101
xAOD::CaloCluster_v1
Description of a calorimeter cluster.
Definition: CaloCluster_v1.h:59
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
LUCID_RawDataContainer
Definition: LUCID_RawDataContainer.h:12
xAOD::CaloCluster_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
Definition: CaloCluster_v1.cxx:251
lumiFormat.i
int i
Definition: lumiFormat.py:85
Monitored
Generic monitoring tool for athena components.
Definition: GenericMonitoringTool.h:30
xAOD::JetAttribute::EMFrac
@ EMFrac
Definition: JetAttributes.h:112
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
DQTBackgroundMon::m_eventInfoDecorKey
SG::ReadDecorHandleKey< xAOD::EventInfo > m_eventInfoDecorKey
Definition: DQTBackgroundMon.h:48
Trk::Segment
Definition: Tracking/TrkEvent/TrkSegment/TrkSegment/Segment.h:56
xAOD::JetAttribute::SumPtTrkPt1000
@ SumPtTrkPt1000
Definition: JetAttributes.h:107
xAOD::JetAttribute::Timing
@ Timing
Definition: JetAttributes.h:90
LArCollisionTime::timeC
double timeC() const
time C side
Definition: LArCollisionTime.h:45
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
DQTBackgroundMon::m_nBkgWords
GP< int > m_nBkgWords
Definition: DQTBackgroundMon.h:69
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.
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
DQTBackgroundMon::m_MBTSSideCut
GP< int > m_MBTSSideCut
Definition: DQTBackgroundMon.h:64
SG::ReadHandle::isValid
virtual bool isValid() override final
Can the handle be successfully dereferenced?
BeamBackgroundData::GetNumNoTimeTight
int GetNumNoTimeTight() const
Definition: BeamBackgroundData.h:81
MBTSCollisionTime::ncellA
int ncellA() const
get number of cells for time A side
Definition: MBTSCollisionTime.h:31
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
BeamBackgroundData::GetNumMatched
int GetNumMatched() const
Definition: BeamBackgroundData.h:78
DQTBackgroundMon::m_unpairIsoBG
GP< int > m_unpairIsoBG
Definition: DQTBackgroundMon.h:57
DQTBackgroundMon::DQTBackgroundMon
DQTBackgroundMon(const std::string &name, ISvcLocator *pSvcLocator)
Definition: DQTBackgroundMon.cxx:7
xAOD::bcid
setEventNumber setTimeStamp bcid
Definition: EventInfo_v1.cxx:133
LUCID_RawData::getNhitsPMTsideC
int getNhitsPMTsideC() const
Definition: LUCID_RawData.h:115
AthMonitorAlgorithm::initialize
virtual StatusCode initialize() override
initialize
Definition: AthMonitorAlgorithm.cxx:18
DQTBackgroundMon::m_LUCID_RawDataContainerKey
RHK< LUCID_RawDataContainer > m_LUCID_RawDataContainerKey
Definition: DQTBackgroundMon.h:42
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
LArCollisionTime::ncellA
int ncellA() const
get number of cells for time A side
Definition: LArCollisionTime.h:30
LUCID_RawData::getNhitsPMTsideA
int getNhitsPMTsideA() const
Definition: LUCID_RawData.h:114
DQTBackgroundMon::m_emptyBG
GP< int > m_emptyBG
Definition: DQTBackgroundMon.h:56
CaloLCW_tf.group
group
Definition: CaloLCW_tf.py:28
DQTBackgroundMon::m_MBTSTimeCut
GP< float > m_MBTSTimeCut
Definition: DQTBackgroundMon.h:65
xAOD::MuonSegment_v1::y
float y() const
Returns the x position.
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
DQTBackgroundMon::m_pixSpacePointKey
RHK< SpacePointContainer > m_pixSpacePointKey
Definition: DQTBackgroundMon.h:46
DQTBackgroundMon::m_upSctSP
GP< int > m_upSctSP
Definition: DQTBackgroundMon.h:62
DQTBackgroundMon::m_MBTSPattern
GP< int > m_MBTSPattern
Definition: DQTBackgroundMon.h:68
DQTBackgroundMon::m_filledBG
GP< int > m_filledBG
Definition: DQTBackgroundMon.h:55
BeamBackgroundData::GetNumOneSidedLoose
int GetNumOneSidedLoose() const
Definition: BeamBackgroundData.h:82
DQTBackgroundMon::m_BeamBackgroundDataKey
RHK< BeamBackgroundData > m_BeamBackgroundDataKey
Definition: DQTBackgroundMon.h:43
LArCollisionTime::timeA
double timeA() const
time A side
Definition: LArCollisionTime.h:42
Monitored::Scalar
Declare a monitored scalar variable.
Definition: MonitoredScalar.h:34
BeamBackgroundData::GetIndexClus
int GetIndexClus(const xAOD::CaloCluster *clus) const
This function looks for the calorimeter cluster among the beam halo muon candidates.
Definition: BeamBackgroundData.cxx:32
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
DQTBackgroundMon::m_upPixSP
GP< int > m_upPixSP
Definition: DQTBackgroundMon.h:61
xAOD::CaloCluster_v1::e
virtual double e() const
The total energy of the particle.
Definition: CaloCluster_v1.cxx:265
DQTBackgroundMon::m_TileCellContainerKey
RHK< TileCellContainer > m_TileCellContainerKey
Definition: DQTBackgroundMon.h:41
AthMonitorAlgorithm::getGroup
const ToolHandle< GenericMonitoringTool > & getGroup(const std::string &name) const
Get a specific monitoring tool from the tool handle array.
Definition: AthMonitorAlgorithm.cxx:164
DQTBackgroundMon::fillHistograms
virtual StatusCode fillHistograms(const EventContext &ctx) const override
adds event to the monitoring histograms
Definition: DQTBackgroundMon.cxx:26
DQTBackgroundMon::~DQTBackgroundMon
virtual ~DQTBackgroundMon()
Definition: DQTBackgroundMon.cxx:11