Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 09:42:57

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   Active_Dead = nullptr;
0034   Active_Fraction = nullptr;
0035 }
0036 
0037 void RPCOccupancyTest::getMonitorElements(std::vector<MonitorElement*>& meVector,
0038                                           std::vector<RPCDetId>& detIdVector,
0039                                           std::string& clientHistoName) {
0040   //Get NumberOfDigi ME for each roll
0041   for (unsigned int i = 0; i < meVector.size(); i++) {
0042     std::string meName = meVector[i]->getName();
0043 
0044     if (meName.find(clientHistoName) != std::string::npos) {
0045       myOccupancyMe_.push_back(meVector[i]);
0046       myDetIds_.push_back(detIdVector[i]);
0047     }
0048   }
0049 }
0050 
0051 void RPCOccupancyTest::clientOperation() {
0052   edm::LogVerbatim("rpceventsummary") << "[RPCOccupancyTest]: Client Operation";
0053 
0054   //Loop on MEs
0055   for (unsigned int i = 0; i < myOccupancyMe_.size(); i++) {
0056     this->fillGlobalME(myDetIds_[i], myOccupancyMe_[i]);
0057   }  //End loop on MEs
0058 
0059   //Active Channels
0060   if (Active_Fraction && totalStrips_ != 0.) {
0061     Active_Fraction->setBinContent(1, (totalActive_ / totalStrips_));
0062   }
0063   if (Active_Dead) {
0064     Active_Dead->setBinContent(1, totalActive_);
0065     Active_Dead->setBinContent(2, (totalStrips_ - totalActive_));
0066   }
0067 }
0068 
0069 void RPCOccupancyTest::myBooker(DQMStore::IBooker& ibooker) {
0070   ibooker.setCurrentFolder(globalFolder_);
0071 
0072   std::stringstream histoName;
0073 
0074   histoName.str("");
0075   histoName << "RPC_Active_Channel_Fractions";
0076   Active_Fraction = ibooker.book1D(histoName.str().c_str(), histoName.str().c_str(), 1, 0.5, 1.5);
0077   Active_Fraction->setBinLabel(1, "Active Fraction", 1);
0078 
0079   histoName.str("");
0080   histoName << "RPC_Active_Inactive_Strips";
0081   Active_Dead = ibooker.book1D(histoName.str().c_str(), histoName.str().c_str(), 2, 0.5, 2.5);
0082   Active_Dead->setBinLabel(1, "Active Strips", 1);
0083   Active_Dead->setBinLabel(2, "Inactive Strips", 1);
0084 
0085   for (int w = -2; w <= 2; w++) {  //loop on wheels
0086 
0087     histoName.str("");
0088     histoName << "AsymmetryLeftRight_Roll_vs_Sector_Wheel" << w;
0089 
0090     auto me = RPCRollMapHisto::bookBarrel(ibooker, w, histoName.str(), histoName.str(), useRollInfo_);
0091     AsyMeWheel[w + 2] = dynamic_cast<MonitorElement*>(me);
0092   }  //end Barrel
0093 
0094   for (int d = -numberOfDisks_; d <= numberOfDisks_; d++) {
0095     if (d == 0)
0096       continue;
0097 
0098     int offset = numberOfDisks_;
0099     if (d > 0)
0100       offset--;  //used to skip case equale to zero
0101 
0102     histoName.str("");
0103     histoName << "AsymmetryLeftRight_Ring_vs_Segment_Disk" << d;
0104     auto me = RPCRollMapHisto::bookEndcap(ibooker, d, histoName.str(), histoName.str(), useRollInfo_);
0105     AsyMeDisk[d + offset] = dynamic_cast<MonitorElement*>(me);
0106   }  //End loop on Endcap
0107 }
0108 
0109 void RPCOccupancyTest::fillGlobalME(RPCDetId& detId, MonitorElement* myMe) {
0110   if (!myMe)
0111     return;
0112 
0113   MonitorElement* AsyMe = nullptr;  //Left Right Asymetry
0114 
0115   if (detId.region() == 0) {
0116     AsyMe = AsyMeWheel[detId.ring() + 2];
0117 
0118   } else {
0119     if (-detId.station() + numberOfDisks_ >= 0) {
0120       if (detId.region() < 0) {
0121         AsyMe = AsyMeDisk[-detId.station() + numberOfDisks_];
0122       } else {
0123         AsyMe = AsyMeDisk[detId.station() + numberOfDisks_ - 1];
0124       }
0125     }
0126   }
0127 
0128   int xBin, yBin;
0129   if (detId.region() == 0) {  //Barrel
0130     xBin = detId.sector();
0131     rpcdqm::utils rollNumber;
0132     yBin = rollNumber.detId2RollNr(detId);
0133   } else {  //Endcap
0134     //get segment number
0135     RPCGeomServ RPCServ(detId);
0136     xBin = RPCServ.segment();
0137     (numberOfRings_ == 3 ? yBin = detId.ring() * 3 - detId.roll() + 1
0138                          : yBin = (detId.ring() - 1) * 3 - detId.roll() + 1);
0139   }
0140 
0141   int stripInRoll = myMe->getNbinsX();
0142   totalStrips_ += (float)stripInRoll;
0143   float FOccupancy = 0;
0144   float BOccupancy = 0;
0145 
0146   float totEnt = myMe->getEntries();
0147   for (int strip = 1; strip <= stripInRoll; strip++) {
0148     float stripEntries = myMe->getBinContent(strip);
0149     if (stripEntries > 0) {
0150       totalActive_++;
0151     }
0152     if (strip <= stripInRoll / 2) {
0153       FOccupancy += myMe->getBinContent(strip);
0154     } else {
0155       BOccupancy += myMe->getBinContent(strip);
0156     }
0157   }
0158 
0159   float asym = 0;
0160   if (totEnt != 0)
0161     asym = fabs((FOccupancy - BOccupancy) / totEnt);
0162 
0163   if (AsyMe)
0164     AsyMe->setBinContent(xBin, yBin, asym);
0165 }