Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:52

0001 // -*- C++ -*-
0002 //
0003 // Package:    SiStripMonitorPedestals
0004 // Class:      SiStripMonitorPedestals
0005 //
0006 /**\class SiStripMonitorDigi SiStripMonitorDigi.cc
0007  DQM/SiStripMonitorDigi/src/SiStripMonitorDigi.cc
0008 
0009  Description: <one line class summary>
0010 
0011  Implementation:
0012      <Notes on implementation>
0013 */
0014 //
0015 // Original Author:  Simone Gennai and Suchandra Dutta
0016 //         Created:  Sat Feb  4 20:49:10 CET 2006
0017 //
0018 //
0019 
0020 #include "CalibFormats/SiStripObjects/interface/SiStripQuality.h"
0021 #include "CalibTracker/Records/interface/SiStripQualityRcd.h"
0022 #include "CalibTracker/SiStripAPVAnalysis/interface/ApvAnalysisFactory.h"
0023 #include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
0024 #include "CondFormats/DataRecord/interface/SiStripPedestalsRcd.h"
0025 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
0026 #include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
0027 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
0028 #include "DQM/SiStripCommon/interface/SiStripHistoId.h"
0029 #include "DQM/SiStripMonitorPedestals/interface/SiStripMonitorPedestals.h"
0030 #include "DQMServices/Core/interface/DQMStore.h"
0031 #include "DataFormats/Common/interface/Handle.h"
0032 #include "FWCore/Framework/interface/EventSetup.h"
0033 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0034 #include "FWCore/ServiceRegistry/interface/Service.h"
0035 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0036 
0037 // ROOT profile
0038 #include "TProfile.h"
0039 
0040 // std includes
0041 #include <algorithm>
0042 #include <cmath>
0043 #include <cstdlib>
0044 #include <numeric>
0045 
0046 const std::string SiStripMonitorPedestals::RunMode1 = "ConDBPlotsOnly";
0047 const std::string SiStripMonitorPedestals::RunMode2 = "CalculatedPlotsOnly";
0048 const std::string SiStripMonitorPedestals::RunMode3 = "AllPlots";
0049 
0050 SiStripMonitorPedestals::SiStripMonitorPedestals(edm::ParameterSet const &iConfig)
0051     : dqmStore_(edm::Service<DQMStore>().operator->()),
0052       conf_(iConfig),
0053       pedsPSet_(iConfig.getParameter<edm::ParameterSet>("PedestalsPSet")),
0054       analyzed(false),
0055       firstEvent(true),
0056       signalCutPeds_(4),
0057       nEvTot_(0),
0058       nIteration_(0),
0059       apvFactory_(nullptr),
0060       tTopoToken_(esConsumes<edm::Transition::BeginRun>()),
0061       detCablingToken_(esConsumes<edm::Transition::BeginRun>()) {
0062   // retrieve producer name of input StripDigiCollection
0063   std::string digiProducer = conf_.getParameter<std::string>("DigiProducer");
0064   std::string digiType = "VirginRaw";
0065   digiToken_ = consumes<edm::DetSetVector<SiStripRawDigi>>(edm::InputTag(digiProducer, digiType));
0066 
0067   edm::LogInfo("SiStripMonitorPedestals") << "SiStripMonitorPedestals  "
0068                                           << " Constructing....... ";
0069 
0070   theEventInitNumber_ = pedsPSet_.getParameter<int>("NumberOfEventsForInit");
0071   theEventIterNumber_ = pedsPSet_.getParameter<int>("NumberOfEventsForIteration");
0072   NumCMstripsInGroup_ = pedsPSet_.getParameter<int>("NumCMstripsInGroup");
0073   runTypeFlag_ = conf_.getParameter<std::string>("RunTypeFlag");
0074 
0075   if (runTypeFlag_ == RunMode1 || runTypeFlag_ == RunMode3) {
0076     pedestalToken_ = esConsumes<edm::Transition::BeginRun>();
0077     noiseToken_ = esConsumes<edm::Transition::BeginRun>();
0078     qualityToken_ = esConsumes<edm::Transition::BeginRun>(
0079         edm::ESInputTag{"", iConfig.getParameter<std::string>("StripQualityLabel")});
0080   }
0081 }
0082 //
0083 // -- Destructor
0084 //
0085 SiStripMonitorPedestals::~SiStripMonitorPedestals() {
0086   edm::LogInfo("SiStripMonitorPedestals") << "SiStripMonitorPedestals  "
0087                                           << " Destructing...... ";
0088   if (apvFactory_) {
0089     delete apvFactory_;
0090   }
0091 }
0092 //
0093 // -- BeginRun
0094 //
0095 
0096 void SiStripMonitorPedestals::bookHistograms(DQMStore::IBooker &ibooker,
0097                                              const edm::Run &run,
0098                                              const edm::EventSetup &eSetup) {
0099   if (detCablingWatcher_.check(eSetup)) {
0100     detcabling = &eSetup.getData(detCablingToken_);
0101     edm::LogInfo("SiStripMonitorPedestals") << "SiStripMonitorPedestals::bookHistograms: "
0102                                             << " Creating MEs for new Cabling ";
0103     createMEs(ibooker, eSetup);
0104   }
0105 
0106   if (runTypeFlag_ == RunMode1 || runTypeFlag_ == RunMode3)
0107     fillCondDBMEs(eSetup);
0108 }
0109 
0110 //
0111 // -- Create Monitor Elements
0112 //
0113 void SiStripMonitorPedestals::createMEs(DQMStore::IBooker &ibooker, const edm::EventSetup &es) {
0114   const auto tTopo = &es.getData(tTopoToken_);
0115 
0116   std::vector<uint32_t> SelectedDetIds;
0117 
0118   // ApvAnalysisFactory
0119   if (apvFactory_) {
0120     delete apvFactory_;
0121   }
0122   apvFactory_ = new ApvAnalysisFactory(pedsPSet_);
0123 
0124   detcabling->addActiveDetectorsRawIds(SelectedDetIds);
0125 
0126   // use SistripHistoId for producing histogram id (and title)
0127   SiStripHistoId hidmanager;
0128   // create SiStripFolderOrganizer
0129   SiStripFolderOrganizer folder_organizer;
0130 
0131   edm::LogInfo("SiStripMonitorPedestals") << "SiStripMonitorPedestals::createMEs: "
0132                                           << "Number of Detector Present in cabling " << SelectedDetIds.size();
0133 
0134   for (std::vector<uint32_t>::const_iterator idetid = SelectedDetIds.begin(), iEnd = SelectedDetIds.end();
0135        idetid != iEnd;
0136        ++idetid) {
0137     uint32_t detid = *idetid;
0138 
0139     // Check consistency in DetId
0140     if (detid == 0 || detid == 0xFFFFFFFF) {
0141       edm::LogError("SiStripMonitorPedestals") << "SiStripMonitorPedestals::createMEs: "
0142                                                << "Wrong DetId !!!!!! " << detid << " Neglecting !!!!!! ";
0143       continue;
0144     }
0145 
0146     unsigned int apv_pairs = detcabling->nApvPairs(detid);
0147 
0148     // Check consistency in Apv numbers
0149     if (apv_pairs < 1 || apv_pairs > 3) {
0150       edm::LogError("SiStripMonitorPedestals") << "SiStripMonitorPedestals::createMEs: Wrong APV Pairs  => detId "
0151                                                << detid << " APV pairs " << apv_pairs << " Neglecting !!!!!! ";
0152       continue;
0153     }
0154     unsigned int napvs = apv_pairs * 2;
0155     unsigned int nStrip = napvs * 128;
0156 
0157     bool newDetId = apvFactory_->instantiateApvs(detid, napvs);
0158 
0159     if (newDetId) {
0160       ModMEs local_modmes;
0161       local_modmes.PedsPerStrip = nullptr;
0162       local_modmes.PedsDistribution = nullptr;
0163       local_modmes.PedsEvolution = nullptr;
0164       local_modmes.CMSubNoisePerStrip = nullptr;
0165       local_modmes.RawNoisePerStrip = nullptr;
0166       local_modmes.CMSubNoiseProfile = nullptr;
0167       local_modmes.RawNoiseProfile = nullptr;
0168       local_modmes.NoisyStrips = nullptr;
0169       local_modmes.NoisyStripDistribution = nullptr;
0170       local_modmes.CMDistribution = nullptr;
0171       local_modmes.CMSlopeDistribution = nullptr;
0172       local_modmes.PedsPerStripDB = nullptr;
0173       local_modmes.CMSubNoisePerStripDB = nullptr;
0174       local_modmes.BadStripsDB = nullptr;
0175 
0176       std::string hid;
0177       // set appropriate folder using SiStripFolderOrganizer
0178       folder_organizer.setDetectorFolder(detid, tTopo);  // pass the detid to this method
0179 
0180       // if the deid already exists in the map, then reset MEs otherwise create
0181       // them
0182       resetMEs(detid);
0183 
0184       if (runTypeFlag_ == RunMode1 || runTypeFlag_ == RunMode3) {
0185         // Pedestals histos
0186         hid = hidmanager.createHistoId("PedestalFromCondDB", "det", detid);
0187         local_modmes.PedsPerStripDB =
0188             ibooker.book1D(hid, hid, nStrip, 0.5, nStrip + 0.5);  // to modify the size binning
0189         (local_modmes.PedsPerStripDB)->setAxisTitle("Pedestal from CondDB(ADC) vs Strip Number", 1);
0190 
0191         hid = hidmanager.createHistoId("NoiseFromCondDB", "det", detid);
0192         local_modmes.CMSubNoisePerStripDB = ibooker.book1D(hid, hid, nStrip, 0.5, nStrip + 0.5);
0193         (local_modmes.CMSubNoisePerStripDB)->setAxisTitle("CMSubNoise from CondDB(ADC) vs Strip Number", 1);
0194 
0195         hid = hidmanager.createHistoId("BadStripFlagCondDB", "det", detid);
0196         local_modmes.BadStripsDB = ibooker.book2D(hid, hid, nStrip, 0.5, nStrip + 0.5, 6, -0.5, 5.5);
0197         (local_modmes.BadStripsDB)->setAxisTitle("Strip Flag from CondDB(ADC) vs Strip Number", 1);
0198       }
0199       if (runTypeFlag_ == RunMode2 || runTypeFlag_ == RunMode3) {
0200         // Pedestals histos
0201         hid = hidmanager.createHistoId("PedsPerStrip", "det", detid);
0202         local_modmes.PedsPerStrip = ibooker.book1D(hid, hid, nStrip, 0.5, nStrip + 0.5);  // to modify the size binning
0203         (local_modmes.PedsPerStrip)->setAxisTitle("Pedestal (ADC)  vs Strip Number ", 1);
0204 
0205         hid = hidmanager.createHistoId("PedsDistribution", "det", detid);
0206         local_modmes.PedsDistribution = ibooker.book2D(hid,
0207                                                        hid,
0208                                                        napvs,
0209                                                        -0.5,
0210                                                        napvs - 0.5,
0211                                                        300,
0212                                                        200,
0213                                                        500);  // to modify the size binning
0214         (local_modmes.PedsDistribution)->setAxisTitle("Apv Number", 1);
0215         (local_modmes.PedsDistribution)->setAxisTitle("Mean Pedestal Value (ADC)", 2);
0216 
0217         hid = hidmanager.createHistoId("PedsEvolution", "det", detid);
0218         local_modmes.PedsEvolution = ibooker.book2D(hid,
0219                                                     hid,
0220                                                     napvs,
0221                                                     -0.5,
0222                                                     napvs - 0.5,
0223                                                     50,
0224                                                     0.,
0225                                                     50.);  // to modify the size binning
0226         (local_modmes.PedsEvolution)->setAxisTitle("Apv Number", 1);
0227         (local_modmes.PedsEvolution)->setAxisTitle("Iteration Number", 2);
0228 
0229         // Noise histos
0230         hid = hidmanager.createHistoId("CMSubNoisePerStrip", "det", detid);
0231         local_modmes.CMSubNoisePerStrip = ibooker.book1D(hid, hid, nStrip, 0.5, nStrip + 0.5);
0232         (local_modmes.CMSubNoisePerStrip)->setAxisTitle("CMSubNoise (ADC) vs Strip Number", 1);
0233 
0234         hid = hidmanager.createHistoId("RawNoisePerStrip", "det", detid);
0235         local_modmes.RawNoisePerStrip = ibooker.book1D(hid, hid, nStrip, 0.5, nStrip + 0.5);
0236         (local_modmes.RawNoisePerStrip)->setAxisTitle("RawNoise(ADC) vs Strip Number", 1);
0237 
0238         hid = hidmanager.createHistoId("CMSubNoiseProfile", "det", detid);
0239         local_modmes.CMSubNoiseProfile = ibooker.bookProfile(hid, hid, nStrip, 0.5, nStrip + 0.5, 100, 0., 100.);
0240         (local_modmes.CMSubNoiseProfile)->setAxisTitle("Mean of CMSubNoise (ADC) vs Strip Number", 1);
0241 
0242         hid = hidmanager.createHistoId("RawNoiseProfile", "det", detid);
0243         local_modmes.RawNoiseProfile = ibooker.bookProfile(hid, hid, nStrip, 0.5, nStrip + 0.5, 100, 0., 100.);
0244         (local_modmes.RawNoiseProfile)->setAxisTitle("Mean of RawNoise (ADC) vs Strip Number", 1);
0245 
0246         hid = hidmanager.createHistoId("NoisyStrips", "det", detid);
0247         local_modmes.NoisyStrips = ibooker.book2D(hid, hid, nStrip, 0.5, nStrip + 0.5, 6, -0.5, 5.5);
0248         (local_modmes.NoisyStrips)->setAxisTitle("Strip Number", 1);
0249         (local_modmes.NoisyStrips)->setAxisTitle("Flag Value", 2);
0250 
0251         hid = hidmanager.createHistoId("NoisyStripDistribution", "det", detid);
0252         local_modmes.NoisyStripDistribution = ibooker.book1D(hid, hid, 11, -0.5, 10.5);
0253         (local_modmes.NoisyStripDistribution)->setAxisTitle("Flag Value", 1);
0254 
0255         // Common Mode histos
0256         hid = hidmanager.createHistoId("CMDistribution", "det", detid);
0257         local_modmes.CMDistribution = ibooker.book2D(hid, hid, napvs, -0.5, napvs - 0.5, 150, -15., 15.);
0258         (local_modmes.CMDistribution)->setAxisTitle("Common Mode (ADC) vs APV Number", 1);
0259 
0260         hid = hidmanager.createHistoId("CMSlopeDistribution", "det", detid);
0261         local_modmes.CMSlopeDistribution = ibooker.book2D(hid, hid, napvs, -0.5, napvs - 0.5, 100, -0.05, 0.05);
0262         (local_modmes.CMSlopeDistribution)->setAxisTitle("Common Mode Slope vs APV Number", 1);
0263       }
0264       // data from CondDB
0265       // append to PedMEs
0266       PedMEs.insert(std::make_pair(detid, local_modmes));
0267     }  // newDetId
0268   }
0269   edm::LogInfo("SiStripMonitorPedestals")
0270       << "SiStripMonitorPedestals::createMEs: Number of DETS used " << PedMEs.size();
0271 }
0272 // ------------ method called to produce the data  ------------
0273 void SiStripMonitorPedestals::analyze(const edm::Event &iEvent, const edm::EventSetup &eSetup) {
0274   edm::LogInfo("SiStripMonitorPedestals")
0275       << "SiStripMonitorPedestals::analyze: Run " << iEvent.id().run() << " Event " << iEvent.id().event();
0276 
0277   detcabling = &eSetup.getData(detCablingToken_);
0278 
0279   if (runTypeFlag_ != RunMode2 && runTypeFlag_ != RunMode3)
0280     return;
0281 
0282   // Increment # of Events
0283   nEvTot_++;
0284 
0285   // get DigiCollection object from Event
0286   edm::Handle<edm::DetSetVector<SiStripRawDigi>> digi_collection;
0287   // you have a collection as there are all the digis for the event for every
0288   // detector
0289   iEvent.getByToken(digiToken_, digi_collection);
0290 
0291   // Increase the number of iterations ...
0292   if ((nEvTot_ - theEventInitNumber_) % theEventIterNumber_ == 1)
0293     nIteration_++;
0294 
0295   // loop over all MEs
0296   for (std::map<uint32_t, ModMEs>::const_iterator i = PedMEs.begin(); i != PedMEs.end(); i++) {
0297     uint32_t detid = i->first;
0298     ModMEs local_modmes = i->second;
0299     // get iterators for digis belonging to one DetId, it is an iterator, i.e.
0300     // one element of the vector
0301     std::vector<edm::DetSet<SiStripRawDigi>>::const_iterator digis = digi_collection->find(detid);
0302     if (digis == digi_collection->end() || digis->data.empty() || digis->data.size() > 768) {
0303       if (digis == digi_collection->end()) {
0304         edm::LogError("SiStripMonitorPedestals") << " SiStripMonitorPedestals::analyze: Event " << nEvTot_ << " DetId "
0305                                                  << detid << " at the end of Digi Collection!!!";
0306       } else {
0307         edm::LogError("SiStripMonitorPedestals") << " [SiStripMonitorPedestals::analyze: Event " << nEvTot_ << " DetId "
0308                                                  << detid << " # of Digis " << digis->data.size();
0309       }
0310       std::vector<const FedChannelConnection *> fed_conns = detcabling->getConnections(detid);
0311       bool firstchannel(true);
0312       for (unsigned int k = 0; k < fed_conns.size(); k++) {
0313         if (fed_conns[k] && fed_conns[k]->isConnected()) {
0314           if (firstchannel) {
0315             edm::LogError("SiStripMonitorPedestals") << " SiStripMonitorPedestals::analyze: Fed Id "
0316                                                      << fed_conns[k]->fedId() << " Channel " << fed_conns[k]->fedCh();
0317             firstchannel = false;
0318           } else
0319             edm::LogError("SiStripMonitorPedestals")
0320                 << "  SiStripMonitorPedestals::analyze: Channel " << fed_conns[k]->fedCh();
0321         }
0322       }
0323       std::cout << std::endl;
0324       continue;
0325     }
0326 
0327     if (digis->data.empty()) {
0328       edm::LogError("MonitorDigi_tmp") << "[SiStripRawDigiToRaw::createFedBuffers] Zero digis found!";
0329     }
0330     uint32_t id = detid;
0331     //    cout <<"Data size "<<digis->data.size()<<endl;
0332     apvFactory_->update(id, (*digis));
0333 
0334     if (nEvTot_ > theEventInitNumber_) {
0335       if (local_modmes.CMDistribution != nullptr) {
0336         std::vector<float> tmp;
0337         tmp.clear();
0338         apvFactory_->getCommonMode(id, tmp);
0339         // unpacking the info looking at the right topology
0340         int numberCMBlocks = int(128. / NumCMstripsInGroup_);
0341         int ibin = 0;
0342         for (std::vector<float>::const_iterator iped = tmp.begin(); iped != tmp.end(); iped++) {
0343           int iapv = int(ibin / numberCMBlocks);
0344           (local_modmes.CMDistribution)->Fill(iapv, static_cast<float>(*iped));
0345           ibin++;
0346         }
0347       }
0348       if (local_modmes.CMSlopeDistribution != nullptr) {
0349         std::vector<float> tmp;
0350         tmp.clear();
0351         int iapv = 0;
0352         apvFactory_->getCommonModeSlope(id, tmp);
0353         for (std::vector<float>::const_iterator it = tmp.begin(); it != tmp.end(); it++) {
0354           (local_modmes.CMSlopeDistribution)->Fill(iapv, static_cast<float>(*it));
0355           iapv++;
0356         }
0357       }
0358     }
0359 
0360     // asking for the status
0361     if ((nEvTot_ - theEventInitNumber_ - theEventIterNumber_) % theEventIterNumber_ == 1) {
0362       std::vector<float> tmp;
0363       tmp.clear();
0364       apvFactory_->getPedestal(id, tmp);
0365       if (local_modmes.PedsPerStrip != nullptr) {
0366         int numberOfApvs = int(tmp.size() / 128.);
0367         for (int i = 0; i < numberOfApvs; i++) {
0368           std::vector<float> myPedPerApv;
0369           apvFactory_->getPedestal(id, i, myPedPerApv);
0370           float avarage = 0;
0371           avarage = std::accumulate(myPedPerApv.begin(), myPedPerApv.end(), avarage);
0372           avarage = avarage / 128.;
0373           (local_modmes.PedsEvolution)->setBinContent(i + 1, nIteration_, avarage);
0374         }
0375         int ibin = 0;
0376 
0377         for (std::vector<float>::const_iterator iped = tmp.begin(); iped != tmp.end(); iped++) {
0378           int napv = int(ibin / 128.);
0379           ibin++;
0380           float last_value = (local_modmes.PedsPerStrip)->getBinContent(ibin);
0381           if (last_value != 0.) {
0382             (local_modmes.PedsPerStrip)->setBinContent(ibin, (static_cast<float>(*iped) + last_value) / 2.);
0383           } else {
0384             (local_modmes.PedsPerStrip)->setBinContent(ibin, static_cast<float>(*iped));
0385           }
0386           (local_modmes.PedsDistribution)->Fill(napv, static_cast<float>(*iped));
0387         }
0388       }
0389 
0390       if (local_modmes.CMSubNoisePerStrip != nullptr && local_modmes.CMSubNoiseProfile != nullptr) {
0391         tmp.clear();
0392         apvFactory_->getNoise(id, tmp);
0393         int ibin = 0;
0394         for (std::vector<float>::const_iterator iped = tmp.begin(); iped != tmp.end(); iped++) {
0395           ibin++;
0396           (local_modmes.CMSubNoiseProfile)->Fill(static_cast<double>(ibin * 1.), static_cast<float>(*iped));
0397 
0398           float last_value = (local_modmes.CMSubNoisePerStrip)->getBinContent(ibin);
0399           if (last_value != 0.) {
0400             (local_modmes.CMSubNoisePerStrip)->setBinContent(ibin, (static_cast<float>(*iped) + last_value) / 2.);
0401           } else {
0402             (local_modmes.CMSubNoisePerStrip)->setBinContent(ibin, static_cast<float>(*iped));
0403           }
0404         }
0405       }
0406 
0407       if (local_modmes.RawNoisePerStrip != nullptr && local_modmes.RawNoiseProfile != nullptr) {
0408         tmp.clear();
0409         apvFactory_->getRawNoise(id, tmp);
0410         int ibin = 0;
0411         for (std::vector<float>::const_iterator iped = tmp.begin(); iped != tmp.end(); iped++) {
0412           ibin++;
0413           (local_modmes.RawNoiseProfile)->Fill(static_cast<double>(ibin * 1.), static_cast<float>(*iped));
0414           float last_value = (local_modmes.RawNoisePerStrip)->getBinContent(ibin);
0415           if (last_value != 0.) {
0416             (local_modmes.RawNoisePerStrip)->setBinContent(ibin, (static_cast<float>(*iped) + last_value) / 2.);
0417           } else {
0418             (local_modmes.RawNoisePerStrip)->setBinContent(ibin, static_cast<float>(*iped));
0419           }
0420         }
0421       }
0422 
0423       if (local_modmes.NoisyStrips != nullptr) {
0424         TkApvMask::MaskType temp;
0425         apvFactory_->getMask(id, temp);
0426         int ibin = 0;
0427         for (TkApvMask::MaskType::const_iterator iped = temp.begin(); iped != temp.end(); iped++) {
0428           ibin++;
0429 
0430           if (nIteration_ < 2) {
0431             if (*iped == 1)
0432               (local_modmes.NoisyStrips)->Fill(ibin, 3.);
0433             if (*iped == 2)
0434               (local_modmes.NoisyStrips)->Fill(ibin, 4.);
0435             if (*iped == 0)
0436               (local_modmes.NoisyStrips)->Fill(ibin, 0.);
0437           } else {
0438             (local_modmes.NoisyStrips)->Fill(ibin, static_cast<float>(*iped));
0439             (local_modmes.NoisyStripDistribution)->Fill(static_cast<float>(*iped));
0440           }
0441         }
0442       }
0443     }
0444   }
0445   if (firstEvent)
0446     firstEvent = false;
0447 }
0448 //
0449 // -- End Run
0450 //
0451 void SiStripMonitorPedestals::dqmEndRun(edm::Run const &run, edm::EventSetup const &eSetup) {
0452   bool outputMEsInRootFile = conf_.getParameter<bool>("OutputMEsInRootFile");
0453   if (outputMEsInRootFile) {
0454     std::string outPutFileName = conf_.getParameter<std::string>("OutPutFileName");
0455     dqmStore_->save(outPutFileName);
0456   }
0457 }
0458 //
0459 // -- End Job
0460 //
0461 void SiStripMonitorPedestals::endJob(void) {
0462   edm::LogInfo("SiStripMonitorPedestals") << "SiStripMonitorPedestals::EndJob: "
0463                                           << " Finishing!! ";
0464 }
0465 //
0466 // -- Reset Monitor Elements corresponding to a detetor
0467 //
0468 void SiStripMonitorPedestals::resetMEs(uint32_t idet) {
0469   std::map<uint32_t, ModMEs>::iterator pos = PedMEs.find(idet);
0470   if (pos != PedMEs.end()) {
0471     ModMEs mod_me = pos->second;
0472 
0473     if (runTypeFlag_ == RunMode1 || runTypeFlag_ == RunMode3) {
0474       mod_me.PedsPerStripDB->Reset();
0475       mod_me.CMSubNoisePerStripDB->Reset();
0476       mod_me.BadStripsDB->Reset();
0477     }
0478     if (runTypeFlag_ == RunMode2 || runTypeFlag_ == RunMode3) {
0479       mod_me.PedsPerStrip->Reset();
0480       mod_me.PedsDistribution->Reset();
0481       mod_me.PedsEvolution->Reset();
0482       mod_me.CMSubNoisePerStrip->Reset();
0483       mod_me.RawNoisePerStrip->Reset();
0484       mod_me.CMSubNoiseProfile->Reset();
0485       mod_me.RawNoiseProfile->Reset();
0486       mod_me.NoisyStrips->Reset();
0487       mod_me.CMDistribution->Reset();
0488       mod_me.CMSlopeDistribution->Reset();
0489     }
0490   }
0491 }
0492 //
0493 // -- Fill CondDB Monitoring Elements
0494 //
0495 void SiStripMonitorPedestals::fillCondDBMEs(edm::EventSetup const &eSetup) {
0496   const auto &pedestals = eSetup.getData(pedestalToken_);
0497   const auto &noises = eSetup.getData(noiseToken_);
0498   const auto &quality = eSetup.getData(qualityToken_);
0499 
0500   for (std::map<uint32_t, ModMEs>::const_iterator i = PedMEs.begin(); i != PedMEs.end(); i++) {
0501     uint32_t detid = i->first;
0502     ModMEs local_modmes = i->second;
0503     edm::LogInfo("SiStripMonitorPedestals") << " SiStripMonitorPedestals::analyze: "
0504                                             << " Get Ped/Noise/Bad Strips from CondDb for DetId " << detid;
0505     int nStrip = detcabling->nApvPairs(detid) * 256;
0506     // Get range of pedestal and noise for the detid
0507     SiStripNoises::Range noiseRange = noises.getRange(detid);
0508     SiStripPedestals::Range pedRange = pedestals.getRange(detid);
0509     SiStripQuality::Range qualityRange = quality.getRange(detid);
0510 
0511     for (int istrip = 0; istrip < nStrip; ++istrip) {
0512       try {
0513         // Fill Pedestals
0514         (local_modmes.PedsPerStripDB)->Fill(istrip + 1, pedestals.getPed(istrip, pedRange));
0515       } catch (cms::Exception &e) {
0516         edm::LogError("SiStripMonitorPedestals") << "[SiStripMonitorPedestals::analyze]  cms::Exception accessing "
0517                                                     "SiStripPedestalsService_.getPedestal("
0518                                                  << detid << "," << istrip << ") :  "
0519                                                  << " " << e.what();
0520       }
0521       try {
0522         // Fill Noises
0523         (local_modmes.CMSubNoisePerStripDB)->Fill(istrip + 1, noises.getNoise(istrip, noiseRange));
0524 
0525       } catch (cms::Exception &e) {
0526         edm::LogError("SiStripMonitorPedestals") << "[SiStripMonitorPedestals::analyze]  cms::Exception accessing "
0527                                                     "SiStripNoiseService_.getNoise("
0528                                                  << detid << "," << istrip << ") :  "
0529                                                  << " " << e.what();
0530       }
0531       try {
0532         // Fill BadStripsNoise
0533         (local_modmes.BadStripsDB)->Fill(istrip + 1, quality.IsStripBad(qualityRange, istrip) ? 1. : 0.);
0534 
0535       } catch (cms::Exception &e) {
0536         edm::LogError("SiStripMonitorPedestals") << "[SiStripMonitorPedestals::analyze]  cms::Exception accessing "
0537                                                     "SiStripNoiseService_.getDisable("
0538                                                  << detid << "," << istrip << ") :  "
0539                                                  << " " << e.what();
0540       }
0541     }  // close istrip loop
0542   }
0543 }
0544 DEFINE_FWK_MODULE(SiStripMonitorPedestals);