ATLAS Offline Software
AFP_LBsOutOfRange.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
8 #include <dqm_core/AlgorithmManager.h>
9 #include <dqm_core/exceptions.h>
10 
11 #include <CoolApplication/DatabaseSvcFactory.h>
12 #include <CoolKernel/ChannelSelection.h>
13 #include <CoolKernel/IDatabase.h>
14 #include <CoolKernel/IDatabaseSvc.h>
15 #include <CoolKernel/IField.h>
16 #include <CoolKernel/IFolder.h>
17 #include <CoolKernel/IObject.h>
18 #include <CoolKernel/IObjectIterator.h>
19 #include <CoolKernel/IRecord.h>
20 #include <CoolKernel/ValidityKey.h>
21 #include <CoolKernel/pointers.h>
22 #include <CoolKernel/types.h>
23 
24 #include <TDirectory.h>
25 #include <TH1.h>
26 #include <TFile.h>
27 
28 namespace {
30  constexpr uint64_t LB_MASK = 0xffffffff;
31  uint64_t getTime( const cool::IObject& obj, const std::string& name ) {
32  return obj.payload()[ name ].data<cool::UInt63>();
33  }
34  uint64_t getStartTime( const cool::IObject& obj ) {
35  return getTime( obj, "StartTime" );
36  }
37  uint64_t getEndTime( const cool::IObject& obj ) {
38  return getTime( obj, "EndTime" );
39  }
40  uint32_t getLB( const cool::IObject& obj ) {
41  return obj.since() & LB_MASK;
42  }
43 } // namespace
44 
46  dqm_core::AlgorithmManager::instance().registerAlgorithm( "AFP_LBsOutOfRange", this );
47 }
48 
50 }
51 
54  return new AFP_LBsOutOfRange();
55 }
56 
59  auto& iovs = m_iov_cache[ std::make_pair( run, channel ) ];
60  if ( iovs.empty() ) {
61  auto& dbService = cool::DatabaseSvcFactory::databaseService();
62  // Get map of LB timestamps to LB numbers
63  uint64_t runStartTime = 0xFFffFFffFFffFFff;
64  uint64_t runEndTime = 0;
65  std::map<uint64_t, uint32_t> lbs;
66  {
67  auto databaseName = std::string( "COOLONL_TRIGGER/CONDBR2" );
68  auto folderName = std::string( "/TRIGGER/LUMI/LBLB" );
69  auto databasePtr = dbService.openDatabase( databaseName, true );
70  auto folderPtr = databasePtr->getFolder( folderName );
71  uint64_t run64 = run;
72  auto since = cool::ValidityKey( run64 << 32 );
73  auto until = cool::ValidityKey( ( run64 + 1 ) << 32 );
74  auto iterPtr = folderPtr->browseObjects( since, until, cool::ChannelSelection::all() );
75  while ( iterPtr->goToNext() ) {
76  auto& object = iterPtr->currentRef();
77  auto lbStartTime = getStartTime( object );
78  auto lbEndTime = getEndTime( object );
79  lbs.emplace( lbStartTime, getLB( object ) );
80  if ( lbStartTime < runStartTime ) runStartTime = lbStartTime;
81  if ( lbEndTime > runEndTime ) runEndTime = lbEndTime;
82  }
83  if ( lbs.empty() ) throw afp::CantReadCool( ERS_HERE, databaseName, folderName );
84  }
85  // Get IOVs where the station was in physics position,
86  // merge the neighbouring ones,
87  // and translate the timestamps to LB numbers
88  {
89  auto databaseName = std::string( "COOLOFL_DCS/CONDBR2" );
90  auto folderName = std::string( "/AFP/DCS/STATION" );
91  auto databasePtr = dbService.openDatabase( databaseName, true );
92  auto folderPtr = databasePtr->getFolder( folderName );
93  auto iterPtr = folderPtr->browseObjects( runStartTime, runEndTime, cool::ChannelSelection( channel ) );
94  uint64_t since = 0, until = 0;
95  iovs.reserve( iterPtr->size() / 2 );
96  while ( iterPtr->goToNext() ) {
97  auto& object = iterPtr->currentRef();
98  auto inphysics = object.payload()[ "inphysics" ].data<cool::Bool>();
99  if ( inphysics ) {
100  if ( since == 0 ) since = object.since();
101  until = object.until();
102  } else if ( since != 0 ) {
103  uint32_t start = lbs.lower_bound( since )->second;
104  uint32_t end = ( --lbs.upper_bound( until ) )->second;
105  iovs.emplace_back( start, end );
106  since = 0;
107  }
108  }
109  }
110  // Ensure the list is not empty
111  if ( iovs.empty() ) {
112  iovs.emplace_back( 0u, 0u );
113  }
114  }
115  return iovs;
116 }
117 
120  const TObject& object,
121  const dqm_core::AlgorithmConfig& config ) {
122  if ( !object.IsA()->InheritsFrom( "TH1" ) ) {
123  throw dqm_core::BadConfig( ERS_HERE, name, "does not inherit from TH1" );
124  }
125 
126  auto histogram = static_cast<const TH1*>( &object );
127 
128  if ( histogram->GetDimension() > 1 ) {
129  throw dqm_core::BadConfig( ERS_HERE, name, "histogram has more than 1 dimension" );
130  }
131 
132  auto gthreshold = static_cast<uint32_t>( dqm_algorithms::tools::GetFromMap( "NbadBins", config.getGreenThresholds() ) );
133  auto rthreshold = static_cast<uint32_t>( dqm_algorithms::tools::GetFromMap( "NbadBins", config.getRedThresholds() ) );
134 
135  auto channel = static_cast<uint32_t>( dqm_algorithms::tools::GetFirstFromMap( "channel", config.getParameters() ) );
136  auto RANGE_D = static_cast<double>( dqm_algorithms::tools::GetFirstFromMap( "RANGE_D", config.getParameters(), -100 ) );
137  auto RANGE_U = static_cast<double>( dqm_algorithms::tools::GetFirstFromMap( "RANGE_U", config.getParameters(), 100 ) );
138  auto ignoreval = static_cast<double>( dqm_algorithms::tools::GetFirstFromMap( "ignoreval", config.getParameters(), 0 ) );
139  auto minLBs = static_cast<uint32_t>( dqm_algorithms::tools::GetFirstFromMap( "MinLBs", config.getParameters(), 0 ) );
140 
141  auto run = dqm_algorithms::tools::GetFirstFromMap( "run_number", config.getParameters(), 0 );
142  auto& iovs = run > 0 ? fetchIOVs( run, channel ) : IOVSet{ { 0, 0 } };
143 
144  auto range = dqm_algorithms::tools::GetBinRange( histogram, config.getParameters() );
145  uint32_t xmin = range[ 0 ];
146  uint32_t xmax = range[ 1 ] + 1;
147  auto xaxis = histogram->GetXaxis();
148  std::vector<uint32_t> badbins;
149  uint32_t checkedLBs = 0;
150  for ( auto& iov : iovs ) {
151  auto xstart = std::max<uint32_t>( xaxis->FindFixBin( iov.first ), xmin );
152  auto xend = std::min<uint32_t>( xaxis->FindFixBin( iov.second ), xmax );
153  for ( uint32_t ix = xstart; ix < xend; ++ix ) {
154  double binvalue = histogram->GetBinContent( ix );
155  if ( binvalue == ignoreval ) continue;
156  ++checkedLBs;
157  if ( RANGE_D < binvalue && binvalue < RANGE_U ) continue;
158  badbins.push_back( ix );
159  }
160  }
161 
162  auto publish = static_cast<bool>( dqm_algorithms::tools::GetFirstFromMap( "PublishBins", config.getParameters(), true ) );
163  auto Nmaxpublish = static_cast<uint32_t>( dqm_algorithms::tools::GetFirstFromMap( "MaxPublish", config.getParameters(), 20 ) );
164  auto result = new dqm_core::Result();
165 
166  // publish problematic bins
167  result->tags_[ "NBadBins" ] = badbins.size();
168  if ( publish ) {
169  auto npublish = std::min<uint32_t>( Nmaxpublish, badbins.size() );
170  for ( uint32_t i = 0; i < npublish; ++i ) {
171  uint32_t ix = badbins[ i ];
172  uint32_t lb = std::floor( xaxis->GetBinCenter( ix ) );
173  auto tag = ( std::ostringstream() << "LB " << lb ).str();
174 
175  result->tags_[ tag ] = histogram->GetBinContent( ix );
176  }
177  }
178 
179  if ( checkedLBs < minLBs )
181  else if ( badbins.size() > rthreshold )
182  result->status_ = dqm_core::Result::Red;
183  else if ( badbins.size() > gthreshold )
184  result->status_ = dqm_core::Result::Yellow;
185  else
186  result->status_ = dqm_core::Result::Green;
187 
188  return result;
189 }
190 
192  out << "AFP_LBsOutOfRange: Print out the bad LBs, during which AFP was in physics position, and which are out of range [RANDE_D,RANGE_U] (default [-100,100])\n"
193  << "Required Parameter: channel: channel number of the station in COOLOFL_DCS/CONDBR2 /AFP/DCS/STATION\n"
194  << "Optional Parameter: ignoreval: value to be ignored for being processed (default 0)\n"
195  << "Optional Parameter: MaxPublish: Max number of bins to save (default 20)\n"
196  << "Optional Parameter: MinLBs: Minimum number of LBs in physics with value not equal to ignoreval to assign color (default 0)" << std::endl;
197 }
dqm_algorithms::tools::GetBinRange
std::vector< int > GetBinRange(const TH1 *histogram, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:380
python.SystemOfUnits.second
int second
Definition: SystemOfUnits.py:120
dqm_algorithms::AFP_LBsOutOfRange::IOVSet
std::vector< std::pair< int, int > > IOVSet
Definition: AFP_LBsOutOfRange.h:30
beamspotman.lbs
lbs
Definition: beamspotman.py:1154
Undefined
@ Undefined
Definition: MaterialTypes.h:8
get_generator_info.result
result
Definition: get_generator_info.py:21
dqt_zlumi_alleff_HIST.iov
iov
Definition: dqt_zlumi_alleff_HIST.py:119
dqm_algorithms::AFP_LBsOutOfRange
Definition: AFP_LBsOutOfRange.h:28
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:24
IsA
#define IsA
Declare the TObject style functions.
Definition: xAODTEventBranch.h:59
xAOD::uint32_t
setEventNumber uint32_t
Definition: EventInfo_v1.cxx:127
find_tgc_unfilled_channelids.iovs
iovs
Definition: find_tgc_unfilled_channelids.py:12
mergePhysValFiles.start
start
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:14
Cut::all
@ all
Definition: SUSYToolsAlg.cxx:67
python.AthDsoLogger.out
out
Definition: AthDsoLogger.py:71
run
int run(int argc, char *argv[])
Definition: ttree2hdf5.cxx:28
dqm_algorithms::AFP_LBsOutOfRange::~AFP_LBsOutOfRange
~AFP_LBsOutOfRange()
Definition: AFP_LBsOutOfRange.cxx:49
IDTPM::getTime
float getTime(const xAOD::TrackParticle &p)
Accessor utility function for getting the track time.
Definition: TrackParametersHelper.h:154
Trk::u
@ u
Enums for curvilinear frames.
Definition: ParamDefs.h:77
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
dq_defect_copy_defect_database.since
def since
Definition: dq_defect_copy_defect_database.py:54
dq_defect_copy_defect_database.until
def until
Definition: dq_defect_copy_defect_database.py:55
instance
std::map< std::string, double > instance
Definition: Run_To_Get_Tags.h:8
python.BunchSpacingUtils.lb
lb
Definition: BunchSpacingUtils.py:88
lumiFormat.i
int i
Definition: lumiFormat.py:85
xmin
double xmin
Definition: listroot.cxx:60
Result
ICscStripFitter::Result Result
Definition: CalibCscStripFitter.cxx:13
dqm_algorithms::AFP_LBsOutOfRange::AFP_LBsOutOfRange
AFP_LBsOutOfRange()
Definition: AFP_LBsOutOfRange.cxx:45
AFP_LBsOutOfRange.h
plotBeamSpotVxVal.range
range
Definition: plotBeamSpotVxVal.py:195
python.handimod.Green
int Green
Definition: handimod.py:524
xAOD::uint64_t
uint64_t
Definition: EventInfo_v1.cxx:123
run
Definition: run.py:1
dqm_algorithms::AFP_LBsOutOfRange::fetchIOVs
const IOVSet & fetchIOVs(uint32_t run, uint32_t channel)
Definition: AFP_LBsOutOfRange.cxx:58
python.handimod.Red
Red
Definition: handimod.py:551
dqm_algorithms::AFP_LBsOutOfRange::printDescriptionTo
void printDescriptionTo(std::ostream &out) override
Definition: AFP_LBsOutOfRange.cxx:191
CaloCellTimeCorrFiller.folderName
string folderName
Definition: CaloCellTimeCorrFiller.py:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
dqm_algorithms::AFP_LBsOutOfRange::execute
dqm_core::Result * execute(const std::string &name, const TObject &object, const dqm_core::AlgorithmConfig &config) override
Definition: AFP_LBsOutOfRange.cxx:119
dqm_algorithms::AFP_LBsOutOfRange::clone
AFP_LBsOutOfRange * clone() override
Definition: AFP_LBsOutOfRange.cxx:53
python.CaloScaleNoiseConfig.str
str
Definition: CaloScaleNoiseConfig.py:78
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
xmax
double xmax
Definition: listroot.cxx:61
AlgorithmHelper.h
dqm_algorithms::tools::GetFromMap
const T & GetFromMap(const std::string &pname, const std::map< std::string, T > &params)
Definition: AlgorithmHelper.h:114
pickleTool.object
object
Definition: pickleTool.py:30
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
python.PyAthena.obj
obj
Definition: PyAthena.py:132
dqm_algorithms::tools::GetFirstFromMap
double GetFirstFromMap(const std::string &paramName, const std::map< std::string, double > &params)
Definition: AlgorithmHelper.cxx:339
histogram
std::string histogram
Definition: chains.cxx:52