Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:54:39

0001 /*
0002  *   File: DataFormats/Scalers/src/L1TriggerRates.cc   (W.Badgett)
0003  */
0004 
0005 #include "DataFormats/Scalers/interface/L1TriggerRates.h"
0006 #include "DataFormats/Scalers/interface/L1TriggerScalers.h"
0007 
0008 #include <iostream>
0009 #include <cstdio>
0010 
0011 L1TriggerRates::L1TriggerRates()
0012     : version_(0),
0013       collectionTimeSummary_(0, 0),
0014       deltaT_(0),
0015       deltaTActive_(0),
0016       triggerNumberRate_(0.0),
0017       eventNumberRate_(0.0),
0018       finalTriggersDistributedRate_(0.0),
0019       finalTriggersGeneratedRate_(0.0),
0020       randomTriggersRate_(0.0),
0021       calibrationTriggersRate_(0.0),
0022       totalTestTriggersRate_(0.0),
0023       orbitNumberRate_(0.0),
0024       numberResetsRate_(0.0),
0025       deadTimePercent_(0.0),
0026       deadTimeActivePercent_(0.0),
0027       deadTimeActiveCalibrationPercent_(0.0),
0028       deadTimeActivePrivatePercent_(0.0),
0029       deadTimeActivePartitionPercent_(0.0),
0030       deadTimeActiveThrottlePercent_(0.0),
0031       deadTimeActiveTimeSlotPercent_(0.0),
0032       finalTriggersInvalidBCPercent_(0.0),
0033       lostFinalTriggersPercent_(0.0),
0034       lostFinalTriggersActivePercent_(0.0),
0035       triggersRate_(L1TriggerScalers::nL1Triggers),
0036       testTriggersRate_(L1TriggerScalers::nL1TestTriggers),
0037       triggerNumberRunRate_(0.0),
0038       eventNumberRunRate_(0.0),
0039       finalTriggersDistributedRunRate_(0.0),
0040       finalTriggersGeneratedRunRate_(0.0),
0041       randomTriggersRunRate_(0.0),
0042       calibrationTriggersRunRate_(0.0),
0043       totalTestTriggersRunRate_(0.0),
0044       orbitNumberRunRate_(0.0),
0045       numberResetsRunRate_(0.0),
0046       deadTimeRunPercent_(0.0),
0047       deadTimeActiveRunPercent_(0.0),
0048       deadTimeActiveCalibrationRunPercent_(0.0),
0049       deadTimeActivePrivateRunPercent_(0.0),
0050       deadTimeActivePartitionRunPercent_(0.0),
0051       deadTimeActiveThrottleRunPercent_(0.0),
0052       deadTimeActiveTimeSlotRunPercent_(0.0),
0053       finalTriggersInvalidBCRunPercent_(0.0),
0054       lostFinalTriggersRunPercent_(0.0),
0055       lostFinalTriggersActiveRunPercent_(0.0),
0056       collectionTimeDetails_(0, 0),
0057       triggersRunRate_(L1TriggerScalers::nL1Triggers),
0058       testTriggersRunRate_(L1TriggerScalers::nL1TestTriggers) {}
0059 
0060 L1TriggerRates::L1TriggerRates(L1TriggerScalers const& s) {
0061   L1TriggerRates();
0062   computeRunRates(s);
0063 }
0064 
0065 L1TriggerRates::L1TriggerRates(L1TriggerScalers const& s1, L1TriggerScalers const& s2) {
0066   L1TriggerRates();
0067 
0068   const L1TriggerScalers* t1 = &s1;
0069   const L1TriggerScalers* t2 = &s2;
0070 
0071   // Choose the later sample to be t2
0072   if (t1->orbitNumber() > t2->orbitNumber()) {
0073     t1 = &s2;
0074     t2 = &s1;
0075   }
0076 
0077   computeRunRates(*t2);
0078   computeRates(*t1, *t2);
0079 }
0080 
0081 L1TriggerRates::~L1TriggerRates() {}
0082 
0083 void L1TriggerRates::computeRates(L1TriggerScalers const& t1, L1TriggerScalers const& t2) {
0084   double deltaOrbit = (double)t2.orbitNumber() - (double)t1.orbitNumber();
0085   if (deltaOrbit > 0) {
0086     // Convert orbits into crossings and time in seconds
0087     double deltaBC = deltaOrbit * N_BX;
0088     double deltaBCActive = deltaOrbit * N_BX_ACTIVE;
0089     deltaT_ = deltaBC * BX_SPACING;
0090     deltaTActive_ = deltaBCActive * BX_SPACING;
0091 
0092     triggerNumberRate_ = ((double)t2.triggerNumber() - (double)t1.triggerNumber()) / deltaT_;
0093     eventNumberRate_ = ((double)t2.eventNumber() - (double)t1.eventNumber()) / deltaT_;
0094     finalTriggersDistributedRate_ =
0095         ((double)t2.finalTriggersDistributed() - (double)t1.finalTriggersDistributed()) / deltaT_;
0096     finalTriggersGeneratedRate_ = ((double)t2.finalTriggersGenerated() - (double)t1.finalTriggersGenerated()) / deltaT_;
0097     randomTriggersRate_ = ((double)t2.randomTriggers() - (double)t1.randomTriggers()) / deltaT_;
0098     calibrationTriggersRate_ = ((double)t2.calibrationTriggers() - (double)t1.calibrationTriggers()) / deltaT_;
0099     totalTestTriggersRate_ = ((double)t2.totalTestTriggers() - (double)t1.totalTestTriggers()) / deltaT_;
0100     orbitNumberRate_ = ((double)t2.orbitNumber() - (double)t1.orbitNumber()) / deltaT_;
0101     numberResetsRate_ = ((double)t2.numberResets() - (double)t1.numberResets()) / deltaT_;
0102 
0103     deadTimePercent_ = 100.0 * ((double)t2.deadTime() - (double)t1.deadTime()) / deltaBC;
0104     deadTimeActivePercent_ = 100.0 * ((double)t2.deadTimeActive() - (double)t1.deadTimeActive()) / deltaBCActive;
0105     deadTimeActiveCalibrationPercent_ =
0106         100.0 * ((double)t2.deadTimeActiveCalibration() - (double)t1.deadTimeActiveCalibration()) / deltaBCActive;
0107     deadTimeActivePrivatePercent_ =
0108         100.0 * ((double)t2.deadTimeActivePrivate() - (double)t1.deadTimeActivePrivate()) / deltaBCActive;
0109     deadTimeActivePartitionPercent_ =
0110         100.0 * ((double)t2.deadTimeActivePartition() - (double)t1.deadTimeActivePartition()) / deltaBCActive;
0111     deadTimeActiveThrottlePercent_ =
0112         100.0 * ((double)t2.deadTimeActiveThrottle() - (double)t1.deadTimeActiveThrottle()) / deltaBCActive;
0113     deadTimeActiveTimeSlotPercent_ =
0114         100.0 * ((double)t2.deadTimeActiveTimeSlot() - (double)t1.deadTimeActiveTimeSlot()) / deltaBCActive;
0115     finalTriggersInvalidBCPercent_ =
0116         100.0 * ((double)t2.finalTriggersInvalidBC() - (double)t1.finalTriggersInvalidBC()) / deltaBC;
0117     lostFinalTriggersPercent_ = 100.0 * ((double)t2.lostFinalTriggers() - (double)t1.lostFinalTriggers()) / deltaBC;
0118     lostFinalTriggersActivePercent_ =
0119         100.0 * ((double)t2.lostFinalTriggersActive() - (double)t1.lostFinalTriggersActive()) / deltaBCActive;
0120 
0121     int length1 = t1.triggers().size();
0122     int length2 = t2.triggers().size();
0123     int minLength;
0124     (length1 >= length2) ? minLength = length2 : minLength = length1;
0125     std::vector<unsigned int> triggers1 = t1.triggers();
0126     std::vector<unsigned int> triggers2 = t2.triggers();
0127     for (int i = 0; i < minLength; i++) {
0128       double rate = ((double)triggers2[i] - (double)triggers1[i]) / deltaT_;
0129       triggersRate_.push_back(rate);
0130     }
0131 
0132     length1 = t1.testTriggers().size();
0133     length2 = t2.testTriggers().size();
0134     (length1 >= length2) ? minLength = length2 : minLength = length1;
0135     std::vector<unsigned int> testTriggers1 = t1.testTriggers();
0136     std::vector<unsigned int> testTriggers2 = t2.testTriggers();
0137     for (int i = 0; i < minLength; i++) {
0138       double rate = ((double)testTriggers2[i] - (double)testTriggers1[i]) / deltaT_;
0139       testTriggersRate_.push_back(rate);
0140     }
0141   }
0142 }
0143 
0144 void L1TriggerRates::computeRunRates(L1TriggerScalers const& t) {
0145   version_ = t.version();
0146 
0147   collectionTimeSummary_.set_tv_sec(static_cast<long>(t.collectionTimeSummary().tv_sec));
0148   collectionTimeSummary_.set_tv_nsec(t.collectionTimeSummary().tv_nsec);
0149 
0150   collectionTimeDetails_.set_tv_sec(static_cast<long>(t.collectionTimeDetails().tv_sec));
0151   collectionTimeDetails_.set_tv_nsec(t.collectionTimeDetails().tv_nsec);
0152 
0153   double deltaOrbit = (double)t.orbitNumber();
0154   if (deltaOrbit > 0) {
0155     // Convert orbits into crossings and time in seconds
0156     double deltaBC = deltaOrbit * N_BX;
0157     double deltaBCActive = deltaOrbit * N_BX_ACTIVE;
0158     deltaTRun_ = deltaBC * BX_SPACING;
0159     deltaTRunActive_ = deltaBCActive * BX_SPACING;
0160 
0161     triggerNumberRunRate_ = (double)t.triggerNumber() / deltaTRun_;
0162     eventNumberRunRate_ = (double)t.eventNumber() / deltaTRun_;
0163     finalTriggersDistributedRunRate_ = (double)t.finalTriggersDistributed() / deltaTRun_;
0164     finalTriggersGeneratedRunRate_ = (double)t.finalTriggersGenerated() / deltaTRun_;
0165     randomTriggersRunRate_ = (double)t.randomTriggers() / deltaTRun_;
0166     calibrationTriggersRunRate_ = (double)t.calibrationTriggers() / deltaTRun_;
0167     totalTestTriggersRunRate_ = (double)t.totalTestTriggers() / deltaTRun_;
0168     orbitNumberRunRate_ = (double)t.orbitNumber() / deltaTRun_;
0169     numberResetsRunRate_ = (double)t.numberResets() / deltaTRun_;
0170 
0171     deadTimeRunPercent_ = 100.0 * (double)t.deadTime() / deltaBC;
0172     deadTimeActiveRunPercent_ = 100.0 * (double)t.deadTimeActive() / deltaBCActive;
0173     deadTimeActiveCalibrationRunPercent_ = 100.0 * (double)t.deadTimeActiveCalibration() / deltaBCActive;
0174     deadTimeActivePrivateRunPercent_ = 100.0 * (double)t.deadTimeActivePrivate() / deltaBCActive;
0175     deadTimeActivePartitionRunPercent_ = 100.0 * (double)t.deadTimeActivePartition() / deltaBCActive;
0176     deadTimeActiveThrottleRunPercent_ = 100.0 * (double)t.deadTimeActiveThrottle() / deltaBCActive;
0177     deadTimeActiveTimeSlotRunPercent_ = 100.0 * (double)t.deadTimeActiveTimeSlot() / deltaBCActive;
0178     finalTriggersInvalidBCRunPercent_ = 100.0 * (double)t.finalTriggersInvalidBC() / deltaBC;
0179     lostFinalTriggersRunPercent_ = 100.0 * (double)t.lostFinalTriggers() / deltaBC;
0180     lostFinalTriggersActiveRunPercent_ = 100.0 * (double)t.lostFinalTriggersActive() / deltaBCActive;
0181 
0182     int length = t.triggers().size();
0183     for (int i = 0; i < length; i++) {
0184       double rate = ((double)t.triggers()[i]) / deltaTRun_;
0185       triggersRunRate_.push_back(rate);
0186     }
0187   }
0188 }
0189 
0190 /// Pretty-print operator for L1TriggerRates
0191 std::ostream& operator<<(std::ostream& s, const L1TriggerRates& c) {
0192   s << "L1TriggerRates Version: " << c.version() << " Differential Rates in Hz, DeltaT: " << c.deltaT() << " sec"
0193     << std::endl;
0194   char line[128];
0195 
0196   sprintf(line, " TriggerNumber:       %e  EventNumber:             %e", c.triggerNumberRate(), c.eventNumberRate());
0197   s << line << std::endl;
0198 
0199   sprintf(line,
0200           " TriggersDistributed: %e  TriggersGenerated:     %e",
0201           c.finalTriggersDistributedRate(),
0202           c.finalTriggersGeneratedRate());
0203   s << line << std::endl;
0204 
0205   sprintf(line,
0206           " RandomTriggers:      %e  CalibrationTriggers:    %e",
0207           c.randomTriggersRate(),
0208           c.calibrationTriggersRate());
0209   s << line << std::endl;
0210 
0211   sprintf(
0212       line, " TotalTestTriggers:   %e  OrbitNumber:             %e", c.totalTestTriggersRate(), c.orbitNumberRate());
0213   s << line << std::endl;
0214 
0215   sprintf(
0216       line, " NumberResets:        %e  DeadTime:                %3.3f%%", c.numberResetsRate(), c.deadTimePercent());
0217   s << line << std::endl;
0218 
0219   sprintf(line,
0220           " DeadTimeActive:        %3.3f%%    DeadTimeActiveCalibration:  %3.3f%%",
0221           c.deadTimeActivePercent(),
0222           c.deadTimeActiveCalibrationPercent());
0223   s << line << std::endl;
0224 
0225   sprintf(line,
0226           " LostTriggers:          %3.3f%%    DeadTimeActivePartition:    %3.3f%%",
0227           c.lostFinalTriggersPercent(),
0228           c.deadTimeActivePartitionPercent());
0229   s << line << std::endl;
0230 
0231   sprintf(line,
0232           " LostTriggersActive:    %3.3f%%    DeadTimeActiveThrottle:     %3.3f%%",
0233           c.lostFinalTriggersActivePercent(),
0234           c.deadTimeActiveThrottlePercent());
0235   s << line << std::endl;
0236 
0237   sprintf(line,
0238           " TriggersInvalidBC:     %3.3f%%    DeadTimeActivePrivate:      %3.3f%%",
0239           c.finalTriggersInvalidBCPercent(),
0240           c.deadTimeActivePrivatePercent());
0241   s << line << std::endl;
0242 
0243   sprintf(line,
0244           "                                   DeadTimeActiveTimeSlot:     %3.3f%%",
0245           c.deadTimeActiveTimeSlotPercent());
0246   s << line << std::endl;
0247 
0248   std::vector<double> triggersRate = c.triggersRate();
0249   int length = triggersRate.size() / 4;
0250   for (int i = 0; i < length; i++) {
0251     sprintf(line,
0252             " %3.3d:%e    %3.3d:%e    %3.3d:%e    %3.3d:%e",
0253             i,
0254             triggersRate[i],
0255             (i + length),
0256             triggersRate[i + length],
0257             (i + (length * 2)),
0258             triggersRate[i + (length * 2)],
0259             (i + (length * 3)),
0260             triggersRate[i + (length * 3)]);
0261     s << line << std::endl;
0262   }
0263 
0264   std::vector<double> testTriggersRate = c.testTriggersRate();
0265   length = testTriggersRate.size() / 4;
0266   for (int i = 0; i < length; i++) {
0267     sprintf(line,
0268             " %3.3d:%e    %3.3d:%e    %3.3d:%e    %3.3d:%e",
0269             i,
0270             testTriggersRate[i],
0271             (i + length),
0272             testTriggersRate[i + length],
0273             (i + (length * 2)),
0274             testTriggersRate[i + (length * 2)],
0275             (i + (length * 3)),
0276             testTriggersRate[i + (length * 3)]);
0277     s << line << std::endl;
0278   }
0279 
0280   // Run Average rates
0281 
0282   s << "L1TriggerRates Version: " << c.version() << " Run Average Rates in Hz, DeltaT: " << c.deltaTRun() << " sec"
0283     << std::endl;
0284 
0285   sprintf(
0286       line, " TriggerNumber:     %e  EventNumber:             %e", c.triggerNumberRunRate(), c.eventNumberRunRate());
0287   s << line << std::endl;
0288 
0289   sprintf(line,
0290           " TriggersDistributed:  %e  TriggersGenerated:     %e",
0291           c.finalTriggersDistributedRunRate(),
0292           c.finalTriggersGeneratedRunRate());
0293   s << line << std::endl;
0294 
0295   sprintf(line,
0296           " RandomTriggers:   %e  CalibrationTriggers:    %e",
0297           c.randomTriggersRunRate(),
0298           c.calibrationTriggersRunRate());
0299   s << line << std::endl;
0300 
0301   sprintf(line,
0302           " TotalTestTriggers: %e  OrbitNumber:             %e",
0303           c.totalTestTriggersRunRate(),
0304           c.orbitNumberRunRate());
0305   s << line << std::endl;
0306 
0307   sprintf(line,
0308           " NumberResets:      %e  DeadTime:                %3.3f%%",
0309           c.numberResetsRunRate(),
0310           c.deadTimeRunPercent());
0311   s << line << std::endl;
0312 
0313   sprintf(line,
0314           " DeadTimeActive:        %3.3f%%    DeadTimeActiveCalibration:  %3.3f%%",
0315           c.deadTimeActiveRunPercent(),
0316           c.deadTimeActiveCalibrationRunPercent());
0317   s << line << std::endl;
0318 
0319   sprintf(line,
0320           " LostTriggers:          %3.3f%%    DeadTimeActivePartition:    %3.3f%%",
0321           c.lostFinalTriggersRunPercent(),
0322           c.deadTimeActivePartitionRunPercent());
0323   s << line << std::endl;
0324 
0325   sprintf(line,
0326           " LostTriggersActive:    %3.3f%%    DeadTimeActiveThrottle:     %3.3f%%",
0327           c.lostFinalTriggersActiveRunPercent(),
0328           c.deadTimeActiveThrottleRunPercent());
0329   s << line << std::endl;
0330 
0331   sprintf(line,
0332           " FinalTriggersInvalidBC:    %3.3f%%    DeadTimeActivePrivate:      %3.3f%%",
0333           c.finalTriggersInvalidBCRunPercent(),
0334           c.deadTimeActivePrivateRunPercent());
0335   s << line << std::endl;
0336 
0337   sprintf(line, " DeadTimeActiveTimeSlot:      %3.3f%%", c.deadTimeActiveTimeSlotRunPercent());
0338   s << line << std::endl;
0339 
0340   std::vector<double> triggersRunRate = c.triggersRunRate();
0341   length = triggersRunRate.size() / 4;
0342   for (int i = 0; i < length; i++) {
0343     sprintf(line,
0344             " %3.3d:%e    %3.3d:%e    %3.3d:%e    %3.3d:%e",
0345             i,
0346             triggersRunRate[i],
0347             (i + length),
0348             triggersRunRate[i + length],
0349             (i + (length * 2)),
0350             triggersRunRate[i + (length * 2)],
0351             (i + (length * 3)),
0352             triggersRunRate[i + (length * 3)]);
0353     s << line << std::endl;
0354   }
0355 
0356   return s;
0357 }