Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-18 03:27:07

0001 /*  \author Anna Cimmino*/
0002 #include "DQM/RPCMonitorClient/interface/RPCEventSummary.h"
0003 #include "DQM/RPCMonitorClient/interface/RPCSummaryMapHisto.h"
0004 
0005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0006 #include "FWCore/Framework/interface/EventSetup.h"
0007 #include "FWCore/Framework/interface/ESHandle.h"
0008 
0009 RPCEventSummary::RPCEventSummary(const edm::ParameterSet& ps) {
0010   edm::LogVerbatim("rpceventsummary") << "[RPCEventSummary]: Constructor";
0011 
0012   enableReportSummary_ = ps.getUntrackedParameter<bool>("EnableSummaryReport", true);
0013   prescaleFactor_ = ps.getUntrackedParameter<int>("PrescaleFactor", 1);
0014   eventInfoPath_ = ps.getUntrackedParameter<std::string>("EventInfoPath", "RPC/EventInfo");
0015 
0016   std::string subsystemFolder = ps.getUntrackedParameter<std::string>("RPCFolder", "RPC");
0017   std::string recHitTypeFolder = ps.getUntrackedParameter<std::string>("RecHitTypeFolder", "AllHits");
0018   std::string summaryFolder = ps.getUntrackedParameter<std::string>("SummaryFolder", "SummaryHistograms");
0019 
0020   globalFolder_ = subsystemFolder + "/" + recHitTypeFolder + "/" + summaryFolder;
0021   prefixFolder_ = subsystemFolder + "/" + recHitTypeFolder;
0022 
0023   minimumEvents_ = ps.getUntrackedParameter<int>("MinimumRPCEvents", 10000);
0024   numberDisk_ = ps.getUntrackedParameter<int>("NumberOfEndcapDisks", 4);
0025   doEndcapCertification_ = ps.getUntrackedParameter<bool>("EnableEndcapSummary", false);
0026 
0027   FEDRange_.first = ps.getUntrackedParameter<unsigned int>("MinimumRPCFEDId", 790);
0028   FEDRange_.second = ps.getUntrackedParameter<unsigned int>("MaximumRPCFEDId", 792);
0029 
0030   NumberOfFeds_ = FEDRange_.second - FEDRange_.first + 1;
0031 
0032   offlineDQM_ = ps.getUntrackedParameter<bool>("OfflineDQM", true);
0033 
0034   runInfoToken_ = esConsumes<edm::Transition::EndLuminosityBlock>();
0035 }
0036 
0037 RPCEventSummary::~RPCEventSummary() { edm::LogVerbatim("rpceventsummary") << "[RPCEventSummary]: Destructor "; }
0038 
0039 void RPCEventSummary::beginJob() {
0040   edm::LogVerbatim("rpceventsummary") << "[RPCEventSummary]: Begin job ";
0041   init_ = false;
0042 }
0043 
0044 void RPCEventSummary::dqmEndLuminosityBlock(DQMStore::IBooker& ibooker,
0045                                             DQMStore::IGetter& igetter,
0046                                             edm::LuminosityBlock const& lb,
0047                                             edm::EventSetup const& setup) {
0048   edm::LogVerbatim("rpceventsummary") << "[RPCEventSummary]: Begin run";
0049 
0050   if (!init_) {
0051     lumiCounter_ = prescaleFactor_;
0052 
0053     edm::eventsetup::EventSetupRecordKey recordKey(
0054         edm::eventsetup::EventSetupRecordKey::TypeTag::findType("RunInfoRcd"));
0055 
0056     int defaultValue = 1;
0057     isIn_ = true;
0058 
0059     if (auto runInfoRec = setup.tryToGet<RunInfoRcd>()) {
0060       defaultValue = -1;
0061       //get fed summary information
0062       auto sumFED = runInfoRec->get(runInfoToken_);
0063       const std::vector<int> FedsInIds = sumFED.m_fed_in;
0064       unsigned int f = 0;
0065       isIn_ = false;
0066       while (!isIn_ && f < FedsInIds.size()) {
0067         int fedID = FedsInIds[f];
0068         //make sure fed id is in allowed range
0069         if (fedID >= FEDRange_.first && fedID <= FEDRange_.second) {
0070           defaultValue = 1;
0071           isIn_ = true;
0072         }
0073         f++;
0074       }
0075     }
0076 
0077     ibooker.setCurrentFolder(eventInfoPath_);
0078 
0079     //a global summary float [0,1] providing a global summary of the status
0080     //and showing the goodness of the data taken by the the sub-system
0081     MonitorElement* meSummary = ibooker.bookFloat("reportSummary");
0082     meSummary->Fill(defaultValue);
0083 
0084     //TH2F ME providing a mapof values[0-1] to show if problems are localized or distributed
0085     MonitorElement* me = RPCSummaryMapHisto::book(ibooker, "reportSummaryMap", "RPC Report Summary Map");
0086     MonitorElement* me2 = RPCSummaryMapHisto::book(ibooker, "noisySummaryMap", "RPC Noisy Chamber Summary Map");
0087     RPCSummaryMapHisto::setBinsBarrel(me, defaultValue);
0088     RPCSummaryMapHisto::setBinsEndcap(me, defaultValue);
0089     RPCSummaryMapHisto::setBinsBarrel(me2, defaultValue);
0090     RPCSummaryMapHisto::setBinsEndcap(me2, defaultValue);
0091 
0092     //the reportSummaryContents folder containins a collection of ME floats [0-1] (order of 5-10)
0093     // which describe the behavior of the respective subsystem sub-components.
0094     ibooker.setCurrentFolder(eventInfoPath_ + "/reportSummaryContents");
0095 
0096     std::vector<std::string> segmentNames;
0097     for (int i = -2; i <= 2; i++) {
0098       const std::string segName = fmt::format("RPC_Wheel{}", i);
0099       segmentNames.push_back(segName);
0100     }
0101 
0102     for (int i = -numberDisk_; i <= numberDisk_; i++) {
0103       if (i == 0)
0104         continue;
0105       const std::string segName = fmt::format("RPC_Disk{}", i);
0106       segmentNames.push_back(segName);
0107     }
0108 
0109     for (const auto& segmentName : segmentNames) {
0110       MonitorElement* me3 = ibooker.bookFloat(segmentName);
0111       me3->Fill(defaultValue);
0112     }
0113 
0114     lumiCounter_ = prescaleFactor_;
0115     init_ = true;
0116   }
0117 
0118   if (isIn_ && !offlineDQM_ && lumiCounter_ % prescaleFactor_ == 0) {
0119     this->clientOperation(igetter);
0120   }
0121 
0122   ++lumiCounter_;
0123 }
0124 
0125 void RPCEventSummary::dqmEndJob(DQMStore::IBooker& ibooker, DQMStore::IGetter& igetter) {
0126   if (isIn_) {
0127     this->clientOperation(igetter);
0128   }
0129 }
0130 
0131 void RPCEventSummary::clientOperation(DQMStore::IGetter& igetter) {
0132   float rpcevents = minimumEvents_;
0133   MonitorElement* RPCEvents = igetter.get(prefixFolder_ + "/RPCEvents");
0134 
0135   if (RPCEvents) {
0136     rpcevents = RPCEvents->getBinContent(1);
0137   }
0138 
0139   if (rpcevents < minimumEvents_)
0140     return;
0141 
0142   MonitorElement* reportMe = igetter.get(eventInfoPath_ + "/reportSummaryMap");
0143   MonitorElement* reportMe2 = igetter.get(eventInfoPath_ + "/noisySummaryMap");
0144 
0145   //BARREL
0146   float barrelFactor = 0;
0147 
0148   for (int w = -2; w < 3; w++) {
0149     const std::string meName1 = fmt::format("{}/DeadChannelFraction_Roll_vs_Sector_Wheel{}", globalFolder_, w);
0150     const std::string meName2 = fmt::format("{}/RPCNoisyStrips_Roll_vs_Sector_Wheel{}", globalFolder_, w);
0151     MonitorElement* myMe1 = igetter.get(meName1);
0152     MonitorElement* myMe2 = igetter.get(meName2);
0153 
0154     if (myMe1 && myMe2) {
0155       float wheelFactor = 0;
0156 
0157       for (int s = 1; s <= myMe1->getNbinsX(); s++) {
0158         float sectorFactor = 0;
0159         float sectorFactor2 = 0;
0160         int rollInSector = 0;
0161 
0162         for (int r = 1; r <= myMe1->getNbinsY(); r++) {
0163           if ((s != 4 && r > 17) || ((s == 9 || s == 11) && r > 15))
0164             continue;
0165           rollInSector++;
0166           sectorFactor += 1 - myMe1->getBinContent(s, r);
0167           sectorFactor2 += myMe2->getBinContent(s, r);
0168         }
0169 
0170         if (rollInSector != 0) {
0171           sectorFactor = sectorFactor / rollInSector;
0172           sectorFactor2 = sectorFactor2 / rollInSector;
0173         }
0174 
0175         if (reportMe)
0176           reportMe->setBinContent(w + 8, s, sectorFactor);
0177         if (reportMe2)
0178           reportMe2->setBinContent(w + 8, s, sectorFactor2);
0179         wheelFactor += sectorFactor;
0180 
0181       }  //end loop on sectors
0182 
0183       wheelFactor = wheelFactor / myMe1->getNbinsX();
0184 
0185       const std::string globalMEName = fmt::format("{}/reportSummaryContents/RPC_Wheel{}", eventInfoPath_, w);
0186       MonitorElement* globalMe = igetter.get(globalMEName);
0187       if (globalMe)
0188         globalMe->Fill(wheelFactor);
0189 
0190       barrelFactor += wheelFactor;
0191     }  //
0192   }    //end loop on wheel
0193 
0194   barrelFactor = barrelFactor / 5;
0195 
0196   float endcapFactor = 0;
0197 
0198   if (doEndcapCertification_) {
0199     //Endcap
0200     for (int d = -numberDisk_; d <= numberDisk_; d++) {
0201       if (d == 0)
0202         continue;
0203 
0204       const std::string meName1 = fmt::format("{}/DeadChannelFraction_Ring_vs_Segment_Disk{}", globalFolder_, d);
0205       const std::string meName2 = fmt::format("{}/RPCNoisyStrips_Ring_vs_Segment_Disk{}", globalFolder_, d);
0206       MonitorElement* myMe1 = igetter.get(meName1);
0207       MonitorElement* myMe2 = igetter.get(meName2);
0208 
0209       if (myMe1 && myMe2) {
0210         float diskFactor = 0;
0211 
0212         float sectorFactor[6] = {0, 0, 0, 0, 0, 0};
0213         float sectorFactor2[6] = {0, 0, 0, 0, 0, 0};
0214 
0215         for (int i = 0; i < 6; i++) {
0216           int firstSeg = (i * 6) + 1;
0217           int lastSeg = firstSeg + 6;
0218           int rollInSector = 0;
0219           for (int seg = firstSeg; seg < lastSeg; seg++) {
0220             for (int y = 1; y <= myMe1->getNbinsY(); y++) {
0221               rollInSector++;
0222               sectorFactor[i] += 1 - myMe1->getBinContent(seg, y);
0223               sectorFactor2[i] += myMe2->getBinContent(seg, y);
0224             }
0225           }
0226           sectorFactor[i] = sectorFactor[i] / rollInSector;
0227           sectorFactor2[i] = sectorFactor2[i] / rollInSector;
0228         }  //end loop on Sectors
0229 
0230         for (int sec = 0; sec < 6; sec++) {
0231           diskFactor += sectorFactor[sec];
0232           if (reportMe) {
0233             if (d < 0)
0234               reportMe->setBinContent(d + 5, sec + 1, sectorFactor[sec]);
0235             else
0236               reportMe->setBinContent(d + 11, sec + 1, sectorFactor[sec]);
0237           }
0238           if (reportMe2) {
0239             if (d < 0)
0240               reportMe2->setBinContent(d + 5, sec + 1, sectorFactor2[sec]);
0241             else
0242               reportMe2->setBinContent(d + 11, sec + 1, sectorFactor2[sec]);
0243           }
0244         }
0245 
0246         diskFactor = diskFactor / 6;
0247 
0248         const std::string globalMEName = fmt::format("{}/reportSummaryContents/RPC_Disk{}", eventInfoPath_, d);
0249         MonitorElement* globalMe = igetter.get(globalMEName);
0250         if (globalMe)
0251           globalMe->Fill(diskFactor);
0252 
0253         endcapFactor += diskFactor;
0254       }  //end loop on disks
0255     }
0256 
0257     endcapFactor = endcapFactor / (numberDisk_ * 2);
0258   }
0259 
0260   //Fill repor summary
0261   float rpcFactor = barrelFactor;
0262   if (doEndcapCertification_) {
0263     rpcFactor = (barrelFactor + endcapFactor) / 2;
0264   }
0265 
0266   MonitorElement* globalMe = igetter.get(eventInfoPath_ + "/reportSummary");
0267   if (globalMe)
0268     globalMe->Fill(rpcFactor);
0269 }