5 #ifdef ONLINE // can only be built in an online environment
10 #include "dqm_core/AlgorithmManager.h"
11 #include "dqm_core/AlgorithmRegistrator.h"
12 #include "dqm_core/AlgorithmConfig.h"
15 #include "ipc/partition.h"
16 #include "is/inforeceiver.h"
17 #include "is/callbackinfo.h"
25 class TRTBeamConditions :
public ISInfoReceiver
28 static TRTBeamConditions &
instance();
30 virtual ~TRTBeamConditions() {}
37 static const char *m_name;
42 const char *TRTBeamConditions::m_name(
"beamconditions.hitfractionTRT_longToT");
46 static TRTBeamConditions s_instance;
52 boost::mutex::scoped_lock lock(m_mutex);
56 TRTBeamConditions::TRTBeamConditions() : ISInfoReceiver(IPCPartition(
"initial")), m_mutex(), m_value(0)
60 }
catch (daq::is::Exception &ex) {
61 ERS_LOG(
"Subscribing to " << m_name <<
" IS Info failed: " << ex);
68 ISInfoFloat hitfraction;
69 info->value(hitfraction);
71 const long long timestamp =
info->time().total_mksec_utc();
72 const long long now = OWLTime().total_mksec_utc();
73 const long long maxAge = 5 * 60 * 1000000;
75 boost::mutex::scoped_lock lock(m_mutex);
76 if (
now - timestamp < maxAge) {
77 m_value = hitfraction.getValue();
81 }
catch (daq::is::Exception &ex) {
82 ERS_LOG(
"Receiving " << m_name <<
" IS Info failed: " << ex);
86 dqm_core::AlgorithmRegistrator<dqm_algorithms::TRTAvgEventSizeCheck> __ii__(
"TRTAvgEventSizeCheck");
92 dqm_algorithms::TRTAvgEventSizeCheck::TRTAvgEventSizeCheck() : lastCollisionsSeen_(
boost::posix_time::min_date_time)
99 return new TRTAvgEventSizeCheck();
104 if (!
object.
IsA()->InheritsFrom(
"TH1")) {
105 throw dqm_core::BadConfig(ERS_HERE,
name,
"histogram does not inherit from TH1");
109 throw dqm_core::BadConfig(ERS_HERE,
name,
"histogram has more than one dimension");
117 const bool collisions = (hitFraction > noiseLimit);
118 const bool unknown = (hitFraction == 0);
120 const boost::posix_time::ptime
now = boost::posix_time::microsec_clock::universal_time();
122 const bool acceptLargeEvents = (
now <= (lastCollisionsSeen_ + delayTime) ||
unknown);
124 const char *avgThresholdName = acceptLargeEvents ?
"Avg_Collisions" :
"Avg_Noise";
130 int spyReadoutEnabled = 0;
131 int spyReadoutDisabled = 0;
134 const double binContent =
histogram.GetBinContent(
i);
137 sum2 += binContent * binContent;
140 ++spyReadoutDisabled;
144 const int &
N = spyReadoutEnabled;
146 const double rms =
N ? std::sqrt(sum2 /
N -
avg *
avg) : 0;
152 else if (
avg < avgR)
result->status_ = dqm_core::Result::Yellow;
157 result->tags_[
"SpyReadoutDisabled"] = spyReadoutDisabled;
158 result->tags_[
"_HitFraction_"] = hitFraction;
160 result->tags_[
"_AcceptLargeEvents_"] = acceptLargeEvents;
164 void dqm_algorithms::TRTAvgEventSizeCheck::printDescription(std::ostream&
out)
166 out <<
"TRTAvgEventSizeCheck: checks the average event size from the TRT RODs.\n"
167 "The algorithm applies two different sets of thresholds, depending on whether we have collisions or not.\n"
168 "Mandatory parameters:\n"
169 " NoiseLimit: if \"hitfractionTRT_longToT\" is above this value, the algorithm assumes we are having collisions.\n"
170 "Optional parameters:\n"
171 " DelayTime: how long after collisions the algorithm still accepts large events (in seconds, default = 60).\n"
172 "Mandatory thresholds:\n"
173 " Avg_Collisions: the allowed average event size when we are having collisions.\n"
174 " Avg_Noise: the allowed average event size when we are not having collisions.\n"
176 " Avg: the average event size, averaged over all RODs in the histogram, excluding the ones with disabled spy readout.\n"
177 " RMS: the RMS of the average event size distribution, excluding the ones with disabled spy readout.\n"
178 " SpyReadoutDisabled: the number of RODs with disabled spy readout.\n"
179 " _HitFraction_: the value of \"hitfractionTRT_longToT\", mirrored as a DQMF result.\n"
180 " _Collisions_: is \"hitfractionTRT_longToT\" currently above the NoiseLimit?\n"
181 " _AcceptLargeEvents_: are we still in the DelayTime after collisions?" << std::endl;