Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-04-29 23:10:17

0001 /*
0002  * \file DTDCSByLumiTask.cc
0003  *
0004  * \author C. Battilana - CIEMAT
0005  * \author P. Bellan - INFN PD
0006  * \author A. Branca = INFN PD
0007 
0008  *
0009  */
0010 
0011 #include "DQM/DTMonitorModule/src/DTDCSByLumiTask.h"
0012 
0013 // Framework
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 
0016 // Geometry
0017 #include "Geometry/DTGeometry/interface/DTLayer.h"
0018 #include "Geometry/DTGeometry/interface/DTTopology.h"
0019 
0020 #include "DQMServices/Core/interface/DQMStore.h"
0021 #include "FWCore/Framework/interface/EventSetupRecord.h"
0022 #include "FWCore/Framework/interface/EventSetupRecordKey.h"
0023 #include "FWCore/Utilities/interface/Transition.h"
0024 
0025 #include <iostream>
0026 
0027 using namespace edm;
0028 using namespace std;
0029 
0030 DTDCSByLumiTask::DTDCSByLumiTask(const edm::ParameterSet& ps)
0031     : theEvents(0),
0032       theLumis(0),
0033       dtGeometryToken_(esConsumes<DTGeometry, MuonGeometryRecord, edm::Transition::BeginRun>()),
0034       dtHVStatusToken_(esConsumes<DTHVStatus, DTHVStatusRcd, edm::Transition::EndLuminosityBlock>()) {
0035   LogTrace("DTDQM|DTMonitorModule|DTDCSByLumiTask") << "[DTDCSByLumiTask]: Constructor" << endl;
0036 
0037   // If needed put getParameter here
0038   // dtDCSByLumiLabel = ps.getParameter<InputTag>("dtDCSByLumiLabel");
0039 }
0040 
0041 DTDCSByLumiTask::~DTDCSByLumiTask() {
0042   LogTrace("DTDQM|DTMonitorModule|DTDCSByLumiTask")
0043       << "DTDCSByLumiTask: processed " << theEvents << " events in " << theLumis << " lumi sections" << endl;
0044 }
0045 
0046 void DTDCSByLumiTask::dqmBeginRun(const edm::Run& run, const edm::EventSetup& context) {
0047   LogTrace("DTDQM|DTMonitorModule|DTDCSByLumiTask") << "[DTDCSByLumiTask]: begin run" << endl;
0048 
0049   theDTGeom = context.getHandle(dtGeometryToken_);
0050 
0051   DTHVRecordFound = true;
0052 
0053   eventsetup::EventSetupRecordKey recordKey(eventsetup::EventSetupRecordKey::TypeTag::findType("DTHVStatusRcd"));
0054 
0055   std::vector<eventsetup::EventSetupRecordKey> recordKeys;
0056   context.fillAvailableRecordKeys(recordKeys);
0057   vector<eventsetup::EventSetupRecordKey>::iterator it = find(recordKeys.begin(), recordKeys.end(), recordKey);
0058 
0059   if (it == recordKeys.end()) {
0060     //record not found
0061     LogTrace("DTDQM|DTMonitorModule|DTDCSByLumiTask") << "Record DTHVStatusRcd does not exist " << std::endl;
0062 
0063     DTHVRecordFound = false;
0064   }
0065 }
0066 
0067 void DTDCSByLumiTask::bookHistograms(DQMStore::IBooker& ibooker, edm::Run const& iRun, edm::EventSetup const&) {
0068   // Book bylumi histo (# of bins as reduced as possible)
0069   ibooker.setCurrentFolder(topFolder());
0070 
0071   for (int wheel = -2; wheel <= 2; wheel++) {
0072     stringstream wheel_str;
0073     wheel_str << wheel;
0074 
0075     {
0076       // Set Lumi scope in order to save histo every LS
0077       auto scope = DQMStore::IBooker::UseLumiScope(ibooker);
0078       MonitorElement* ME =
0079           ibooker.book1D("hActiveUnits" + wheel_str.str(), "Active Untis x LS Wh" + wheel_str.str(), 2, 0.5, 2.5);
0080       hActiveUnits.push_back(ME);
0081     }
0082   }
0083 }
0084 
0085 void DTDCSByLumiTask::dqmBeginLuminosityBlock(LuminosityBlock const& lumiSeg, EventSetup const&) {
0086   theLumis++;
0087 
0088   LogTrace("DTDQM|DTMonitorModule|DTDCSByLumiTask")
0089       << "[DTDCSByLumiTask]: Begin of processed lumi # " << lumiSeg.id().luminosityBlock() << " " << theLumis
0090       << " lumi processed by this job" << endl;
0091 
0092   for (int wheel = 0; wheel < 5; wheel++) {
0093     hActiveUnits[wheel]->Reset();  // Cb by lumi histo need to be resetted in between lumi boundaries
0094   }
0095 }
0096 
0097 void DTDCSByLumiTask::dqmEndLuminosityBlock(const edm::LuminosityBlock& lumiSeg, const edm::EventSetup& context) {
0098   const DTHVStatus* dtHVStatus = nullptr;
0099   if (DTHVRecordFound) {
0100     dtHVStatus = &context.getData(dtHVStatusToken_);
0101   }
0102 
0103   vector<const DTLayer*>::const_iterator layersIt = theDTGeom->layers().begin();
0104   vector<const DTLayer*>::const_iterator layersEnd = theDTGeom->layers().end();
0105 
0106   for (; layersIt != layersEnd; ++layersIt) {
0107     int wheel = (*layersIt)->id().wheel();
0108 
0109     int nWiresLayer = (*layersIt)->specificTopology().channels();
0110     hActiveUnits[wheel + 2]->Fill(1, nWiresLayer);  // CB first bin is # of layers
0111     int nActiveWires = nWiresLayer;
0112 
0113     int flagA = -100;
0114     int flagC = -100;
0115     int flagS = -100;
0116     int first = -100;
0117     int last = -100;
0118 
0119     // CB info is not stored if HV is ON -> in this case get returns 1
0120     // process all other cases and removed wires with "BAD HV" from active
0121     // wires list
0122 
0123     if (DTHVRecordFound) {
0124       if (!dtHVStatus->get((*layersIt)->id(), 0, first, last, flagA, flagC, flagS) && (flagA || flagC || flagS)) {
0125         nActiveWires -= (last - first + 1);
0126       }
0127 
0128       if (!dtHVStatus->get((*layersIt)->id(), 1, first, last, flagA, flagC, flagS) && (flagA || flagC || flagS)) {
0129         nActiveWires -= (last - first + 1);
0130       }
0131     } else {
0132       nActiveWires = -1.;
0133     }
0134 
0135     hActiveUnits[wheel + 2]->Fill(2, nActiveWires);  // CB 2nd bin is the list of wires wit HV ON
0136   }
0137 }
0138 
0139 void DTDCSByLumiTask::analyze(const edm::Event&, const edm::EventSetup&) { theEvents++; }
0140 
0141 string DTDCSByLumiTask::topFolder() const { return string("DT/EventInfo/DCSContents"); }
0142 
0143 // Local Variables:
0144 // show-trailing-whitespace: t
0145 // truncate-lines: t
0146 // End: