Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-31 22:35:52

0001 /*  \author Anna Cimmino*/
0002 #include <DQM/RPCMonitorClient/interface/RPCOccupancyTest.h>
0003 #include "DQM/RPCMonitorClient/interface/RPCRollMapHisto.h"
0004 #include "DQM/RPCMonitorClient/interface/utils.h"
0005 
0006 // Framework
0007 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0008 //Geometry
0009 #include "Geometry/RPCGeometry/interface/RPCGeomServ.h"
0010 
0011 RPCOccupancyTest::RPCOccupancyTest(const edm::ParameterSet& ps) {
0012   edm::LogVerbatim("rpceventsummary") << "[RPCOccupancyTest]: Constructor";
0013 
0014   prescaleFactor_ = ps.getUntrackedParameter<int>("DiagnosticPrescale", 1);
0015   numberOfDisks_ = ps.getUntrackedParameter<int>("NumberOfEndcapDisks", 4);
0016   numberOfRings_ = ps.getUntrackedParameter<int>("NumberOfEndcapRings", 2);
0017   useNormalization_ = ps.getUntrackedParameter<bool>("testMode", true);
0018   useRollInfo_ = ps.getUntrackedParameter<bool>("useRollInfo_", false);
0019 
0020   std::string subsystemFolder = ps.getUntrackedParameter<std::string>("RPCFolder", "RPC");
0021   std::string recHitTypeFolder = ps.getUntrackedParameter<std::string>("RecHitTypeFolder", "AllHits");
0022 
0023   prefixDir_ = subsystemFolder + "/" + recHitTypeFolder;
0024 }
0025 
0026 void RPCOccupancyTest::beginJob(std::string& workingFolder) {
0027   edm::LogVerbatim("rpceventsummary") << "[RPCOccupancyTest]: Begin job ";
0028   globalFolder_ = workingFolder;
0029 
0030   totalStrips_ = 0.;
0031   totalActive_ = 0.;
0032 }
0033 
0034 void RPCOccupancyTest::getMonitorElements(std::vector<MonitorElement*>& meVector,
0035                                           std::vector<RPCDetId>& detIdVector,
0036                                           std::string& clientHistoName) {
0037   //Get NumberOfDigi ME for each roll
0038   for (unsigned int i = 0; i < meVector.size(); i++) {
0039     std::string meName = meVector[i]->getName();
0040 
0041     if (meName.find(clientHistoName) != std::string::npos) {
0042       myOccupancyMe_.push_back(meVector[i]);
0043       myDetIds_.push_back(detIdVector[i]);
0044     }
0045   }
0046 }
0047 
0048 void RPCOccupancyTest::clientOperation() {
0049   edm::LogVerbatim("rpceventsummary") << "[RPCOccupancyTest]: Client Operation";
0050 
0051   //Loop on MEs
0052   for (unsigned int i = 0; i < myOccupancyMe_.size(); i++) {
0053     this->fillGlobalME(myDetIds_[i], myOccupancyMe_[i]);
0054   }  //End loop on MEs
0055 
0056   //Active Channels
0057   if (Active_Fraction && totalStrips_ != 0.) {
0058     Active_Fraction->setBinContent(1, (totalActive_ / totalStrips_));
0059   }
0060   if (Active_Dead) {
0061     Active_Dead->setBinContent(1, totalActive_);
0062     Active_Dead->setBinContent(2, (totalStrips_ - totalActive_));
0063   }
0064 }
0065 
0066 void RPCOccupancyTest::myBooker(DQMStore::IBooker& ibooker) {
0067   ibooker.setCurrentFolder(globalFolder_);
0068 
0069   std::stringstream histoName;
0070 
0071   histoName.str("");
0072   histoName << "RPC_Active_Channel_Fractions";
0073   Active_Fraction = ibooker.book1D(histoName.str().c_str(), histoName.str().c_str(), 1, 0.5, 1.5);
0074   Active_Fraction->setBinLabel(1, "Active Fraction", 1);
0075 
0076   histoName.str("");
0077   histoName << "RPC_Active_Inactive_Strips";
0078   Active_Dead = ibooker.book1D(histoName.str().c_str(), histoName.str().c_str(), 2, 0.5, 2.5);
0079   Active_Dead->setBinLabel(1, "Active Strips", 1);
0080   Active_Dead->setBinLabel(2, "Inactive Strips", 1);
0081 
0082   for (int w = -2; w <= 2; w++) {  //loop on wheels
0083 
0084     histoName.str("");
0085     histoName << "AsymmetryLeftRight_Roll_vs_Sector_Wheel" << w;
0086 
0087     auto me = RPCRollMapHisto::bookBarrel(ibooker, w, histoName.str(), histoName.str(), useRollInfo_);
0088     AsyMeWheel[w + 2] = dynamic_cast<MonitorElement*>(me);
0089   }  //end Barrel
0090 
0091   for (int d = -numberOfDisks_; d <= numberOfDisks_; d++) {
0092     if (d == 0)
0093       continue;
0094 
0095     int offset = numberOfDisks_;
0096     if (d > 0)
0097       offset--;  //used to skip case equale to zero
0098 
0099     histoName.str("");
0100     histoName << "AsymmetryLeftRight_Ring_vs_Segment_Disk" << d;
0101     auto me = RPCRollMapHisto::bookEndcap(ibooker, d, histoName.str(), histoName.str(), useRollInfo_);
0102     AsyMeDisk[d + offset] = dynamic_cast<MonitorElement*>(me);
0103   }  //End loop on Endcap
0104 }
0105 
0106 void RPCOccupancyTest::fillGlobalME(RPCDetId& detId, MonitorElement* myMe) {
0107   if (!myMe)
0108     return;
0109 
0110   MonitorElement* AsyMe = nullptr;  //Left Right Asymetry
0111 
0112   if (detId.region() == 0) {
0113     AsyMe = AsyMeWheel[detId.ring() + 2];
0114 
0115   } else {
0116     if (-detId.station() + numberOfDisks_ >= 0) {
0117       if (detId.region() < 0) {
0118         AsyMe = AsyMeDisk[-detId.station() + numberOfDisks_];
0119       } else {
0120         AsyMe = AsyMeDisk[detId.station() + numberOfDisks_ - 1];
0121       }
0122     }
0123   }
0124 
0125   int xBin, yBin;
0126   if (detId.region() == 0) {  //Barrel
0127     xBin = detId.sector();
0128     rpcdqm::utils rollNumber;
0129     yBin = rollNumber.detId2RollNr(detId);
0130   } else {  //Endcap
0131     //get segment number
0132     RPCGeomServ RPCServ(detId);
0133     xBin = RPCServ.segment();
0134     (numberOfRings_ == 3 ? yBin = detId.ring() * 3 - detId.roll() + 1
0135                          : yBin = (detId.ring() - 1) * 3 - detId.roll() + 1);
0136   }
0137 
0138   int stripInRoll = myMe->getNbinsX();
0139   totalStrips_ += (float)stripInRoll;
0140   float FOccupancy = 0;
0141   float BOccupancy = 0;
0142 
0143   float totEnt = myMe->getEntries();
0144   for (int strip = 1; strip <= stripInRoll; strip++) {
0145     float stripEntries = myMe->getBinContent(strip);
0146     if (stripEntries > 0) {
0147       totalActive_++;
0148     }
0149     if (strip <= stripInRoll / 2) {
0150       FOccupancy += myMe->getBinContent(strip);
0151     } else {
0152       BOccupancy += myMe->getBinContent(strip);
0153     }
0154   }
0155 
0156   float asym = 0;
0157   if (totEnt != 0)
0158     asym = fabs((FOccupancy - BOccupancy) / totEnt);
0159 
0160   if (AsyMe)
0161     AsyMe->setBinContent(xBin, yBin, asym);
0162 }