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