00001
00002
00003
00004
00005 #include "DataFormats/Scalers/interface/L1TriggerRates.h"
00006 #include "DataFormats/Scalers/interface/L1TriggerScalers.h"
00007
00008 #include <iostream>
00009 #include <cstdio>
00010
00011 L1TriggerRates::L1TriggerRates():
00012 version_(0),
00013 collectionTimeSummary_(0,0),
00014 deltaT_(0),
00015 deltaTActive_(0),
00016 triggerNumberRate_(0.0),
00017 eventNumberRate_(0.0),
00018 finalTriggersDistributedRate_(0.0),
00019 finalTriggersGeneratedRate_(0.0),
00020 randomTriggersRate_(0.0),
00021 calibrationTriggersRate_(0.0),
00022 totalTestTriggersRate_(0.0),
00023 orbitNumberRate_(0.0),
00024 numberResetsRate_(0.0),
00025 deadTimePercent_(0.0),
00026 deadTimeActivePercent_(0.0),
00027 deadTimeActiveCalibrationPercent_(0.0),
00028 deadTimeActivePrivatePercent_(0.0),
00029 deadTimeActivePartitionPercent_(0.0),
00030 deadTimeActiveThrottlePercent_(0.0),
00031 deadTimeActiveTimeSlotPercent_(0.0),
00032 finalTriggersInvalidBCPercent_(0.0),
00033 lostFinalTriggersPercent_(0.0),
00034 lostFinalTriggersActivePercent_(0.0),
00035 triggersRate_(L1TriggerScalers::nL1Triggers),
00036 testTriggersRate_(L1TriggerScalers::nL1TestTriggers),
00037 triggerNumberRunRate_(0.0),
00038 eventNumberRunRate_(0.0),
00039 finalTriggersDistributedRunRate_(0.0),
00040 finalTriggersGeneratedRunRate_(0.0),
00041 randomTriggersRunRate_(0.0),
00042 calibrationTriggersRunRate_(0.0),
00043 totalTestTriggersRunRate_(0.0),
00044 orbitNumberRunRate_(0.0),
00045 numberResetsRunRate_(0.0),
00046 deadTimeRunPercent_(0.0),
00047 deadTimeActiveRunPercent_(0.0),
00048 deadTimeActiveCalibrationRunPercent_(0.0),
00049 deadTimeActivePrivateRunPercent_(0.0),
00050 deadTimeActivePartitionRunPercent_(0.0),
00051 deadTimeActiveThrottleRunPercent_(0.0),
00052 deadTimeActiveTimeSlotRunPercent_(0.0),
00053 finalTriggersInvalidBCRunPercent_(0.0),
00054 lostFinalTriggersRunPercent_(0.0),
00055 lostFinalTriggersActiveRunPercent_(0.0),
00056 collectionTimeDetails_(0,0),
00057 triggersRunRate_(L1TriggerScalers::nL1Triggers),
00058 testTriggersRunRate_(L1TriggerScalers::nL1TestTriggers)
00059 {
00060 }
00061
00062 L1TriggerRates::L1TriggerRates(L1TriggerScalers const& s)
00063 {
00064 L1TriggerRates();
00065 computeRunRates(s);
00066 }
00067
00068 L1TriggerRates::L1TriggerRates(L1TriggerScalers const& s1,
00069 L1TriggerScalers const& s2)
00070 {
00071 L1TriggerRates();
00072
00073 const L1TriggerScalers *t1 = &s1;
00074 const L1TriggerScalers *t2 = &s2;
00075
00076
00077 if ( t1->orbitNumber() > t2->orbitNumber())
00078 {
00079 t1 = &s2;
00080 t2 = &s1;
00081 }
00082
00083 computeRunRates(*t2);
00084 computeRates(*t1,*t2);
00085 }
00086
00087 L1TriggerRates::~L1TriggerRates() { }
00088
00089
00090 void L1TriggerRates::computeRates(L1TriggerScalers const& t1,
00091 L1TriggerScalers const& t2)
00092 {
00093 double deltaOrbit = (double)t2.orbitNumber() - (double)t1.orbitNumber();
00094 if ( deltaOrbit > 0 )
00095 {
00096
00097 double deltaBC = deltaOrbit * N_BX;
00098 double deltaBCActive = deltaOrbit * N_BX_ACTIVE;
00099 deltaT_ = deltaBC * BX_SPACING;
00100 deltaTActive_ = deltaBCActive * BX_SPACING;
00101
00102 triggerNumberRate_ = ((double)t2.triggerNumber()
00103 - (double)t1.triggerNumber()) / deltaT_;
00104 eventNumberRate_ = ((double)t2.eventNumber()
00105 - (double)t1.eventNumber()) / deltaT_;
00106 finalTriggersDistributedRate_ = ((double)t2.finalTriggersDistributed()
00107 - (double)t1.finalTriggersDistributed()) / deltaT_;
00108 finalTriggersGeneratedRate_ = ((double)t2.finalTriggersGenerated()
00109 - (double)t1.finalTriggersGenerated()) / deltaT_;
00110 randomTriggersRate_ = ((double)t2.randomTriggers()
00111 - (double)t1.randomTriggers()) / deltaT_;
00112 calibrationTriggersRate_ = ((double)t2.calibrationTriggers()
00113 - (double)t1.calibrationTriggers()) / deltaT_;
00114 totalTestTriggersRate_ = ((double)t2.totalTestTriggers()
00115 - (double)t1.totalTestTriggers()) / deltaT_;
00116 orbitNumberRate_ = ((double)t2.orbitNumber()
00117 - (double)t1.orbitNumber()) / deltaT_;
00118 numberResetsRate_ = ((double)t2.numberResets()
00119 - (double)t1.numberResets()) / deltaT_;
00120
00121 deadTimePercent_ = 100.0 * ((double)t2.deadTime()
00122 - (double)t1.deadTime()) / deltaBC;
00123 deadTimeActivePercent_ = 100.0 * ((double)t2.deadTimeActive()
00124 - (double)t1.deadTimeActive()) / deltaBCActive;
00125 deadTimeActiveCalibrationPercent_ = 100.0 * ((double)t2.deadTimeActiveCalibration()
00126 - (double)t1.deadTimeActiveCalibration()) / deltaBCActive;
00127 deadTimeActivePrivatePercent_ = 100.0 * ((double)t2.deadTimeActivePrivate()
00128 - (double)t1.deadTimeActivePrivate()) / deltaBCActive;
00129 deadTimeActivePartitionPercent_ = 100.0 * ((double)t2.deadTimeActivePartition()
00130 - (double)t1.deadTimeActivePartition()) / deltaBCActive;
00131 deadTimeActiveThrottlePercent_ = 100.0 * ((double)t2.deadTimeActiveThrottle()
00132 - (double)t1.deadTimeActiveThrottle()) / deltaBCActive;
00133 deadTimeActiveTimeSlotPercent_ = 100.0 * ((double)t2.deadTimeActiveTimeSlot()
00134 - (double)t1.deadTimeActiveTimeSlot()) / deltaBCActive;
00135 finalTriggersInvalidBCPercent_ = 100.0 * ((double)t2.finalTriggersInvalidBC()
00136 - (double)t1.finalTriggersInvalidBC()) / deltaBC;
00137 lostFinalTriggersPercent_ = 100.0 * ((double)t2.lostFinalTriggers()
00138 - (double)t1.lostFinalTriggers()) / deltaBC;
00139 lostFinalTriggersActivePercent_ = 100.0 * ((double)t2.lostFinalTriggersActive()
00140 - (double)t1.lostFinalTriggersActive()) / deltaBCActive;
00141
00142 int length1 = t1.triggers().size();
00143 int length2 = t2.triggers().size();
00144 int minLength;
00145 ( length1 >= length2 ) ? minLength = length2 : minLength=length1;
00146 std::vector<unsigned int> triggers1 = t1.triggers();
00147 std::vector<unsigned int> triggers2 = t2.triggers();
00148 for ( int i=0; i<minLength; i++)
00149 {
00150 double rate = ((double)triggers2[i] -
00151 (double)triggers1[i] ) / deltaT_;
00152 triggersRate_.push_back(rate);
00153 }
00154
00155
00156 length1 = t1.testTriggers().size();
00157 length2 = t2.testTriggers().size();
00158 ( length1 >= length2 ) ? minLength = length2 : minLength=length1;
00159 std::vector<unsigned int> testTriggers1 = t1.testTriggers();
00160 std::vector<unsigned int> testTriggers2 = t2.testTriggers();
00161 for ( int i=0; i<minLength; i++)
00162 {
00163 double rate = ((double)testTriggers2[i] -
00164 (double)testTriggers1[i] ) / deltaT_;
00165 testTriggersRate_.push_back(rate);
00166 }
00167 }
00168 }
00169
00170 void L1TriggerRates::computeRunRates(L1TriggerScalers const& t)
00171 {
00172 version_ = t.version();
00173
00174 collectionTimeSummary_.set_tv_sec(static_cast<long>(t.collectionTimeSummary().tv_sec));
00175 collectionTimeSummary_.set_tv_nsec(t.collectionTimeSummary().tv_nsec);
00176
00177 collectionTimeDetails_.set_tv_sec(static_cast<long>(t.collectionTimeDetails().tv_sec));
00178 collectionTimeDetails_.set_tv_nsec(t.collectionTimeDetails().tv_nsec);
00179
00180 double deltaOrbit = (double)t.orbitNumber();
00181 if ( deltaOrbit > 0 )
00182 {
00183
00184 double deltaBC = deltaOrbit * N_BX;
00185 double deltaBCActive = deltaOrbit * N_BX_ACTIVE;
00186 deltaTRun_ = deltaBC * BX_SPACING;
00187 deltaTRunActive_ = deltaBCActive * BX_SPACING;
00188
00189 triggerNumberRunRate_ = (double)t.triggerNumber() / deltaTRun_;
00190 eventNumberRunRate_ = (double)t.eventNumber() / deltaTRun_;
00191 finalTriggersDistributedRunRate_ = (double)t.finalTriggersDistributed()
00192 / deltaTRun_;
00193 finalTriggersGeneratedRunRate_ = (double)t.finalTriggersGenerated() / deltaTRun_;
00194 randomTriggersRunRate_ = (double)t.randomTriggers() / deltaTRun_;
00195 calibrationTriggersRunRate_ = (double)t.calibrationTriggers() / deltaTRun_;
00196 totalTestTriggersRunRate_ = (double)t.totalTestTriggers() / deltaTRun_;
00197 orbitNumberRunRate_ = (double)t.orbitNumber() / deltaTRun_;
00198 numberResetsRunRate_ = (double)t.numberResets() / deltaTRun_;
00199
00200 deadTimeRunPercent_ = 100.0 * (double)t.deadTime() / deltaBC;
00201 deadTimeActiveRunPercent_ = 100.0 * (double)t.deadTimeActive() / deltaBCActive;
00202 deadTimeActiveCalibrationRunPercent_ = 100.0 * (double)t.deadTimeActiveCalibration() / deltaBCActive;
00203 deadTimeActivePrivateRunPercent_ = 100.0 * (double)t.deadTimeActivePrivate() / deltaBCActive;
00204 deadTimeActivePartitionRunPercent_ = 100.0 * (double)t.deadTimeActivePartition() / deltaBCActive;
00205 deadTimeActiveThrottleRunPercent_ = 100.0 * (double)t.deadTimeActiveThrottle() / deltaBCActive;
00206 deadTimeActiveTimeSlotRunPercent_ = 100.0 * (double)t.deadTimeActiveTimeSlot() / deltaBCActive;
00207 finalTriggersInvalidBCRunPercent_ = 100.0 * (double)t.finalTriggersInvalidBC() / deltaBC;
00208 lostFinalTriggersRunPercent_ = 100.0 * (double)t.lostFinalTriggers() / deltaBC;
00209 lostFinalTriggersActiveRunPercent_ = 100.0 * (double)t.lostFinalTriggersActive() / deltaBCActive;
00210
00211 int length = t.triggers().size();
00212 for ( int i=0; i<length; i++)
00213 {
00214 double rate = ((double)t.triggers()[i]) / deltaTRun_;
00215 triggersRunRate_.push_back(rate);
00216 }
00217 }
00218 }
00219
00220
00222 std::ostream& operator<<(std::ostream& s, const L1TriggerRates& c)
00223 {
00224 s << "L1TriggerRates Version: " << c.version()
00225 << " Differential Rates in Hz, DeltaT: " <<
00226 c.deltaT() << " sec" << std::endl;
00227 char line[128];
00228
00229 sprintf(line,
00230 " TriggerNumber: %e EventNumber: %e",
00231 c.triggerNumberRate(), c.eventNumberRate());
00232 s << line << std::endl;
00233
00234 sprintf(line,
00235 " TriggersDistributed: %e TriggersGenerated: %e",
00236 c.finalTriggersDistributedRate(), c.finalTriggersGeneratedRate());
00237 s << line << std::endl;
00238
00239 sprintf(line,
00240 " RandomTriggers: %e CalibrationTriggers: %e",
00241 c.randomTriggersRate(), c.calibrationTriggersRate());
00242 s << line << std::endl;
00243
00244 sprintf(line,
00245 " TotalTestTriggers: %e OrbitNumber: %e",
00246 c.totalTestTriggersRate(), c.orbitNumberRate());
00247 s << line << std::endl;
00248
00249 sprintf(line,
00250 " NumberResets: %e DeadTime: %3.3f%%",
00251 c.numberResetsRate(), c.deadTimePercent());
00252 s << line << std::endl;
00253
00254 sprintf(line,
00255 " DeadTimeActive: %3.3f%% DeadTimeActiveCalibration: %3.3f%%",
00256 c.deadTimeActivePercent(),
00257 c.deadTimeActiveCalibrationPercent());
00258 s << line << std::endl;
00259
00260 sprintf(line,
00261 " LostTriggers: %3.3f%% DeadTimeActivePartition: %3.3f%%",
00262 c.lostFinalTriggersPercent(),
00263 c.deadTimeActivePartitionPercent());
00264 s << line << std::endl;
00265
00266 sprintf(line,
00267 " LostTriggersActive: %3.3f%% DeadTimeActiveThrottle: %3.3f%%",
00268 c.lostFinalTriggersActivePercent(),
00269 c.deadTimeActiveThrottlePercent());
00270 s << line << std::endl;
00271
00272 sprintf(line,
00273 " TriggersInvalidBC: %3.3f%% DeadTimeActivePrivate: %3.3f%%",
00274 c.finalTriggersInvalidBCPercent(),
00275 c.deadTimeActivePrivatePercent());
00276 s << line << std::endl;
00277
00278 sprintf(line,
00279 " DeadTimeActiveTimeSlot: %3.3f%%",
00280 c.deadTimeActiveTimeSlotPercent());
00281 s << line << std::endl;
00282
00283 std::vector<double> triggersRate = c.triggersRate();
00284 int length = triggersRate.size() / 4;
00285 for ( int i=0; i<length; i++)
00286 {
00287 sprintf(line," %3.3d:%e %3.3d:%e %3.3d:%e %3.3d:%e",
00288 i, triggersRate[i],
00289 (i+length), triggersRate[i+length],
00290 (i+(length*2)), triggersRate[i+(length*2)],
00291 (i+(length*3)), triggersRate[i+(length*3)]);
00292 s << line << std::endl;
00293 }
00294
00295 std::vector<double> testTriggersRate = c.testTriggersRate();
00296 length = testTriggersRate.size() / 4;
00297 for ( int i=0; i<length; i++)
00298 {
00299 sprintf(line," %3.3d:%e %3.3d:%e %3.3d:%e %3.3d:%e",
00300 i, testTriggersRate[i],
00301 (i+length), testTriggersRate[i+length],
00302 (i+(length*2)), testTriggersRate[i+(length*2)],
00303 (i+(length*3)), testTriggersRate[i+(length*3)]);
00304 s << line << std::endl;
00305 }
00306
00307
00308
00309
00310 s << "L1TriggerRates Version: " << c.version()
00311 << " Run Average Rates in Hz, DeltaT: " <<
00312 c.deltaTRun() << " sec" << std::endl;
00313
00314 sprintf(line,
00315 " TriggerNumber: %e EventNumber: %e",
00316 c.triggerNumberRunRate(), c.eventNumberRunRate());
00317 s << line << std::endl;
00318
00319 sprintf(line,
00320 " TriggersDistributed: %e TriggersGenerated: %e",
00321 c.finalTriggersDistributedRunRate(),
00322 c.finalTriggersGeneratedRunRate());
00323 s << line << std::endl;
00324
00325 sprintf(line,
00326 " RandomTriggers: %e CalibrationTriggers: %e",
00327 c.randomTriggersRunRate(), c.calibrationTriggersRunRate());
00328 s << line << std::endl;
00329
00330 sprintf(line,
00331 " TotalTestTriggers: %e OrbitNumber: %e",
00332 c.totalTestTriggersRunRate(), c.orbitNumberRunRate());
00333 s << line << std::endl;
00334
00335 sprintf(line,
00336 " NumberResets: %e DeadTime: %3.3f%%",
00337 c.numberResetsRunRate(), c.deadTimeRunPercent());
00338 s << line << std::endl;
00339
00340 sprintf(line,
00341 " DeadTimeActive: %3.3f%% DeadTimeActiveCalibration: %3.3f%%",
00342 c.deadTimeActiveRunPercent(),
00343 c.deadTimeActiveCalibrationRunPercent());
00344 s << line << std::endl;
00345
00346 sprintf(line,
00347 " LostTriggers: %3.3f%% DeadTimeActivePartition: %3.3f%%",
00348 c.lostFinalTriggersRunPercent(),
00349 c.deadTimeActivePartitionRunPercent());
00350 s << line << std::endl;
00351
00352 sprintf(line,
00353 " LostTriggersActive: %3.3f%% DeadTimeActiveThrottle: %3.3f%%",
00354 c.lostFinalTriggersActiveRunPercent(),
00355 c.deadTimeActiveThrottleRunPercent());
00356 s << line << std::endl;
00357
00358 sprintf(line,
00359 " FinalTriggersInvalidBC: %3.3f%% DeadTimeActivePrivate: %3.3f%%",
00360 c.finalTriggersInvalidBCRunPercent(),
00361 c.deadTimeActivePrivateRunPercent());
00362 s << line << std::endl;
00363
00364 sprintf(line,
00365 " DeadTimeActiveTimeSlot: %3.3f%%",
00366 c.deadTimeActiveTimeSlotRunPercent());
00367 s << line << std::endl;
00368
00369 std::vector<double> triggersRunRate = c.triggersRunRate();
00370 length = triggersRunRate.size() / 4;
00371 for ( int i=0; i<length; i++)
00372 {
00373 sprintf(line," %3.3d:%e %3.3d:%e %3.3d:%e %3.3d:%e",
00374 i, triggersRunRate[i],
00375 (i+length), triggersRunRate[i+length],
00376 (i+(length*2)), triggersRunRate[i+(length*2)],
00377 (i+(length*3)), triggersRunRate[i+(length*3)]);
00378 s << line << std::endl;
00379 }
00380
00381 return s;
00382 }