Back to home page

Project CMSSW displayed by LXR

 
 

    


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

0001 // -*- c++ -*-
0002 /**\class SiStripMonitorDigi SiStripMonitorDigi.cc DQM/SiStripMonitorDigi/src/SiStripMonitorDigi.cc
0003  */
0004 // Original Author:  Dorian Kcira
0005 //         Created:  Sat Feb  4 20:49:10 CET 2006
0006 //         Updated:  May 2020, Suvankar Roy Chowdhury
0007 
0008 // std library includes
0009 #include <fstream>
0010 #include <iostream>
0011 
0012 // root includes
0013 #include "TNamed.h"
0014 #include "TMath.h"
0015 
0016 // user file includes
0017 #include "FWCore/Framework/interface/ESHandle.h"
0018 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0019 #include "FWCore/ServiceRegistry/interface/Service.h"
0020 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
0021 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
0022 #include "DataFormats/Common/interface/DetSetNew.h"
0023 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0024 #include "DataFormats/Common/interface/DetSetVector.h"
0025 #include "DataFormats/Common/interface/Handle.h"
0026 #include "DataFormats/TrackerCommon/interface/SiStripSubStructure.h"
0027 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
0028 #include "DQM/SiStripCommon/interface/SiStripFolderOrganizer.h"
0029 #include "DQM/SiStripCommon/interface/SiStripHistoId.h"
0030 #include "DQM/SiStripMonitorDigi/interface/SiStripMonitorDigi.h"
0031 #include "DQMServices/Core/interface/DQMStore.h"
0032 #include "DPGAnalysis/SiStripTools/interface/APVCyclePhaseCollection.h"
0033 #include "DPGAnalysis/SiStripTools/interface/EventWithHistory.h"
0034 #include "CalibTracker/SiStripCommon/interface/SiStripDCSStatus.h"
0035 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
0036 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
0037 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0038 #include "DataFormats/Scalers/interface/DcsStatus.h"
0039 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerEvmReadoutRecord.h"
0040 #include "DataFormats/L1GlobalTrigger/interface/L1GtFdlWord.h"
0041 #include "DataFormats/L1GlobalTrigger/interface/L1GlobalTriggerReadoutRecord.h"
0042 #include "Geometry/Records/interface/TrackerTopologyRcd.h"
0043 
0044 /* mia: but is there not a smarter way ?!?!?! */
0045 namespace {
0046   const double NORBITS_PER_LS = 262144.;  // per-second value would be 11223
0047 }
0048 
0049 //--------------------------------------------------------------------------------------------
0050 SiStripMonitorDigi::SiStripMonitorDigi(const edm::ParameterSet& iConfig)
0051     :  //dqmStore_(edm::Service<DQMStore>().operator->()),
0052       conf_(iConfig),
0053       show_mechanical_structure_view(true),
0054       show_readout_view(false),
0055       show_control_view(false),
0056       select_all_detectors(true),
0057       reset_each_run(false),
0058       folder_organizer(),
0059       m_cacheID_(0) {
0060   firstEvent = -1;
0061   eventNb = 0;
0062 
0063   // Detector Partitions
0064   SubDetPhasePartMap["TIB"] = "TI";
0065   SubDetPhasePartMap["TID__MINUS"] = "TI";
0066   SubDetPhasePartMap["TID__PLUS"] = "TI";
0067   SubDetPhasePartMap["TOB"] = "TO";
0068   SubDetPhasePartMap["TEC__MINUS"] = "TM";
0069   SubDetPhasePartMap["TEC__PLUS"] = "TP";
0070 
0071   topFolderName_ = conf_.getParameter<std::string>("TopFolderName");
0072 
0073   // get Digi Producer List
0074   digiProducerList = conf_.getParameter<std::vector<edm::InputTag> >("DigiProducersList");
0075   for (auto const& tag : digiProducerList) {
0076     digiProducerTokenList.push_back(consumes<edm::DetSetVector<SiStripDigi> >(tag));
0077   }
0078 
0079   //get on/off option for every cluster from cfi
0080   edm::ParameterSet ParametersNumberOfDigis = conf_.getParameter<edm::ParameterSet>("TH1NumberOfDigis");
0081   layerswitchnumdigison = ParametersNumberOfDigis.getParameter<bool>("layerswitchon");
0082   moduleswitchnumdigison = ParametersNumberOfDigis.getParameter<bool>("moduleswitchon");
0083 
0084   edm::ParameterSet ParametersNumberOfDigisPerStrip = conf_.getParameter<edm::ParameterSet>("TH1NumberOfDigisPerStrip");
0085   moduleswitchnumdigispstripon = ParametersNumberOfDigisPerStrip.getParameter<bool>("moduleswitchon");
0086 
0087   edm::ParameterSet ParametersADCsHottestStrip = conf_.getParameter<edm::ParameterSet>("TH1ADCsHottestStrip");
0088   layerswitchadchotteston = ParametersADCsHottestStrip.getParameter<bool>("layerswitchon");
0089   moduleswitchadchotteston = ParametersADCsHottestStrip.getParameter<bool>("moduleswitchon");
0090 
0091   edm::ParameterSet ParametersADCsCoolestStrip = conf_.getParameter<edm::ParameterSet>("TH1ADCsCoolestStrip");
0092   layerswitchadccooleston = ParametersADCsCoolestStrip.getParameter<bool>("layerswitchon");
0093   moduleswitchadccooleston = ParametersADCsCoolestStrip.getParameter<bool>("moduleswitchon");
0094 
0095   edm::ParameterSet ParametersDigiADCs = conf_.getParameter<edm::ParameterSet>("TH1DigiADCs");
0096   layerswitchdigiadcson = ParametersDigiADCs.getParameter<bool>("layerswitchon");
0097   moduleswitchdigiadcson = ParametersDigiADCs.getParameter<bool>("moduleswitchon");
0098 
0099   edm::ParameterSet ParametersStripOccupancy = conf_.getParameter<edm::ParameterSet>("TH1StripOccupancy");
0100   layerswitchstripoccupancyon = ParametersStripOccupancy.getParameter<bool>("layerswitchon");
0101   moduleswitchstripoccupancyon = ParametersStripOccupancy.getParameter<bool>("moduleswitchon");
0102 
0103   edm::ParameterSet ParametersDigiProf = conf_.getParameter<edm::ParameterSet>("TProfNumberOfDigi");
0104   layerswitchnumdigisprofon = ParametersDigiProf.getParameter<bool>("layerswitchon");
0105 
0106   edm::ParameterSet ParametersDigiADC = conf_.getParameter<edm::ParameterSet>("TProfDigiADC");
0107   layerswitchdigiadcprofon = ParametersDigiProf.getParameter<bool>("layerswitchon");
0108 
0109   edm::ParameterSet ParametersTotDigiProf = conf_.getParameter<edm::ParameterSet>("TProfTotalNumberOfDigis");
0110   subdetswitchtotdigiprofon = ParametersTotDigiProf.getParameter<bool>("subdetswitchon");
0111 
0112   edm::ParameterSet ParametersTotDigiFailure = conf_.getParameter<edm::ParameterSet>("TotalNumberOfDigisFailure");
0113   subdetswitchtotdigifailureon = ParametersTotDigiFailure.getParameter<bool>("subdetswitchon");
0114 
0115   edm::ParameterSet ParametersDigiApvProf = conf_.getParameter<edm::ParameterSet>("TProfDigiApvCycle");
0116   subdetswitchapvcycleprofon = ParametersDigiApvProf.getParameter<bool>("subdetswitchon");
0117 
0118   edm::ParameterSet ParametersDigiApvTH2 = conf_.getParameter<edm::ParameterSet>("TH2DigiApvCycle");
0119   subdetswitchapvcycleth2on = ParametersDigiApvTH2.getParameter<bool>("subdetswitchon");
0120 
0121   edm::ParameterSet ParametersNApvShots = conf_.getParameter<edm::ParameterSet>("TH1NApvShots");
0122   subdetswitchnapvshotson = ParametersNApvShots.getParameter<bool>("subdetswitchon");
0123 
0124   edm::ParameterSet ParametersNStripApvShots = conf_.getParameter<edm::ParameterSet>("TH1NStripsApvShots");
0125   subdetswitchnstripsapvshotson = ParametersNStripApvShots.getParameter<bool>("subdetswitchon");
0126 
0127   edm::ParameterSet ParametersChargeMedianApvShots = conf_.getParameter<edm::ParameterSet>("TH1ChargeMedianApvShots");
0128   subdetswitchchargemedianapvshotson = ParametersChargeMedianApvShots.getParameter<bool>("subdetswitchon");
0129 
0130   edm::ParameterSet ParametersApvNumberApvShots = conf_.getParameter<edm::ParameterSet>("TH1ApvNumApvShots");
0131   subdetswitchapvshotsApvon = ParametersChargeMedianApvShots.getParameter<bool>("subdetswitchon");
0132 
0133   edm::ParameterSet ParametersNApvShotsProf = conf_.getParameter<edm::ParameterSet>("TProfNShotsVsTime");
0134   subdetswitchapvshotsonprof = ParametersNApvShotsProf.getParameter<bool>("subdetswitchon");
0135 
0136   //Global Histograms
0137 
0138   edm::ParameterSet ParametersGlobalNApvShots = conf_.getParameter<edm::ParameterSet>("TH1NApvShots");
0139   globalswitchnapvshotson = ParametersGlobalNApvShots.getParameter<bool>("globalswitchon");
0140 
0141   edm::ParameterSet ParametersGlobalNApvShotsProf = conf_.getParameter<edm::ParameterSet>("TProfGlobalNShots");
0142   globalsummaryapvshotson = ParametersGlobalNApvShotsProf.getParameter<bool>("globalswitchon");
0143 
0144   edm::ParameterSet ParametersGlobalNStripApvShots = conf_.getParameter<edm::ParameterSet>("TH1NStripsApvShots");
0145   globalswitchnstripsapvshotson = ParametersGlobalNStripApvShots.getParameter<bool>("globalswitchon");
0146 
0147   edm::ParameterSet ParametersGlobalApvNumApvShots = conf_.getParameter<edm::ParameterSet>("TH1ApvNumApvShots");
0148   globalswitchapvshotsApvon = ParametersGlobalApvNumApvShots.getParameter<bool>("globalswitchon");
0149 
0150   edm::ParameterSet ParametersGlobalChargeMedianApvShots =
0151       conf_.getParameter<edm::ParameterSet>("TH1ChargeMedianApvShots");
0152   globalswitchchargemedianapvshotson = ParametersGlobalChargeMedianApvShots.getParameter<bool>("globalswitchon");
0153 
0154   edm::ParameterSet ParametersGlobalNApvShotsTimeProf = conf_.getParameter<edm::ParameterSet>("TProfNShotsVsTime");
0155   globalswitchapvshotsonprof = ParametersGlobalNApvShotsTimeProf.getParameter<bool>("globalswitchon");
0156 
0157   edm::ParameterSet ParametersGlobalNDigisFEDID = conf_.getParameter<edm::ParameterSet>("TProfNDigisFED");
0158   globalswitchNDigisFEDID = ParametersGlobalNDigisFEDID.getParameter<bool>("globalswitchon");
0159 
0160   //Digi and APV Shots Maps
0161 
0162   digitkhistomapon = conf_.getParameter<bool>("TkHistoMap_On");
0163 
0164   shotshistomapon = conf_.getParameter<bool>("TkHistoMapNApvShots_On");
0165   shotsstripshistomapon = conf_.getParameter<bool>("TkHistoMapNStripApvShots_On");
0166   shotschargehistomapon = conf_.getParameter<bool>("TkHistoMapMedianChargeApvShots_On");
0167 
0168   createTrendMEs = conf_.getParameter<bool>("CreateTrendMEs");
0169   Mod_On_ = conf_.getParameter<bool>("Mod_On");
0170   m_trendVs10LS = conf_.getParameter<bool>("TrendVs10LS");
0171   //  xLumiProf             = conf_.getParameter<int>("xLumiProf");
0172   // Event History Producer
0173   historyProducer_ = conf_.getParameter<edm::InputTag>("HistoryProducer");
0174   historyProducerToken_ = consumes<EventWithHistory>(conf_.getParameter<edm::InputTag>("HistoryProducer"));
0175 
0176   // Apv Phase Producer
0177   apvPhaseProducer_ = conf_.getParameter<edm::InputTag>("ApvPhaseProducer");
0178   apvPhaseProducerToken_ = consumes<APVCyclePhaseCollection>(conf_.getParameter<edm::InputTag>("ApvPhaseProducer"));
0179 
0180   gtEvmToken_ = consumes<L1GlobalTriggerEvmReadoutRecord>(edm::InputTag("gtEvmDigis"));
0181 
0182   if (show_mechanical_structure_view) {
0183     tTopoTokenRun_ = esConsumes<edm::Transition::BeginRun>();
0184     tkDetMapTokenRun_ = esConsumes<edm::Transition::BeginRun>();
0185     SiStripDetCablingTokenRun_ = esConsumes<edm::Transition::BeginRun>();
0186   }
0187   if (subdetswitchtotdigifailureon) {
0188     runInfoTokenRun_ = esConsumes<edm::Transition::BeginRun>();
0189   }
0190   tTopoToken_ = esConsumes();
0191 
0192   // Create DCS Status
0193   bool checkDCS = conf_.getParameter<bool>("UseDCSFiltering");
0194   if (checkDCS)
0195     dcsStatus_ = new SiStripDCSStatus(consumesCollector());
0196   else
0197     dcsStatus_ = nullptr;
0198 
0199   //initialize boolean for the data-presence check (needed for TotalNumberOfDigisFailure histogram)
0200   SBTransitionDone = false;
0201   SBDeclaredAt = 0;
0202   ignoreFirstNLumisections_ = TMath::Max(0, ParametersTotDigiFailure.getParameter<int32_t>("ignoreFirstNLumisections"));
0203   integrateNLumisections_ = TMath::Max(1, ParametersTotDigiFailure.getParameter<int32_t>("integrateNLumisections"));
0204   vecSubDetTotDigiProfLS.reserve(7);
0205 }
0206 //------------------------------------------------------------------------------------------
0207 
0208 SiStripMonitorDigi::~SiStripMonitorDigi() {
0209   if (dcsStatus_)
0210     delete dcsStatus_;
0211 }
0212 
0213 void SiStripMonitorDigi::bookHistograms(DQMStore::IBooker& ibooker, const edm::Run& run, const edm::EventSetup& es) {
0214   if (show_mechanical_structure_view) {
0215     unsigned long long cacheID = es.get<SiStripDetCablingRcd>().cacheIdentifier();
0216     if (m_cacheID_ != cacheID) {
0217       m_cacheID_ = cacheID;
0218       edm::LogInfo("SiStripMonitorDigi") << "SiStripMonitorDigi::bookHistograms: "
0219                                          << " Creating MEs for new Cabling ";
0220       createMEs(ibooker, es);
0221     }
0222   } else if (reset_each_run) {
0223     edm::LogInfo("SiStripMonitorDigi") << "SiStripMonitorDigi::bookHistograms: "
0224                                        << " Resetting MEs ";
0225     for (std::map<uint32_t, ModMEs>::const_iterator idet = DigiMEs.begin(); idet != DigiMEs.end(); idet++) {
0226       ResetModuleMEs(idet->first);
0227     }
0228   }
0229 }
0230 
0231 //--------------------------------------------------------------------------------------------
0232 void SiStripMonitorDigi::dqmBeginRun(const edm::Run& run, const edm::EventSetup& es) {
0233   if (subdetswitchtotdigifailureon) {
0234     //get FED cabling to know if SiStrip is in DAQ or no
0235     unsigned long long cacheID = es.get<SiStripDetCablingRcd>().cacheIdentifier();
0236     if (m_cacheID_ != cacheID) {
0237       m_cacheID_ = cacheID;
0238     }
0239 
0240     //nFEDConnected = 0;
0241     nFedTIB = 0;
0242     nFedTIDm = 0;
0243     nFedTIDp = 0;
0244     nFedTECm = 0;
0245     nFedTECp = 0;
0246     nFedTOB = 0;
0247 
0248     //const int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
0249     //const int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
0250 
0251     if (auto runInfoRec = es.tryToGet<RunInfoRcd>()) {
0252       edm::ESHandle<RunInfo> sumFED = runInfoRec->getHandle(runInfoTokenRun_);
0253 
0254       if (sumFED.isValid()) {
0255         std::vector<int> FedsInIds = sumFED->m_fed_in;
0256         for (unsigned int it = 0; it < FedsInIds.size(); ++it) {
0257           int fedID = FedsInIds[it];
0258           //      if(fedID>=siStripFedIdMin &&  fedID<=siStripFedIdMax)  ++nFEDConnected;
0259           /* mia: but is there not a smarter way !?!?!? */
0260           if (fedID >= 50 && fedID <= 133)
0261             ++nFedTIB;
0262           if (fedID >= 134 && fedID <= 148)
0263             ++nFedTIDm;
0264           if (fedID >= 149 && fedID <= 163)
0265             ++nFedTIDp;
0266           if (fedID >= 164 && fedID <= 259)
0267             ++nFedTECm;
0268           if (fedID >= 260 && fedID <= 355)
0269             ++nFedTECp;
0270           if (fedID >= 356 && fedID <= 489)
0271             ++nFedTOB;
0272         }
0273       }
0274     }
0275   }
0276 }
0277 
0278 //--------------------------------------------------------------------------------------------
0279 std::shared_ptr<bool> SiStripMonitorDigi::globalBeginLuminosityBlock(const edm::LuminosityBlock& lb,
0280                                                                      const edm::EventSetup& es) const {
0281   bool isStableBeams = false;
0282   return std::make_shared<bool>(isStableBeams);
0283 }
0284 
0285 //--------------------------------------------------------------------------------------------
0286 void SiStripMonitorDigi::globalEndLuminosityBlock(const edm::LuminosityBlock& lb, const edm::EventSetup& es) {
0287   unsigned int currentLS = lb.id().luminosityBlock();
0288   const bool isStableBeams = luminosityBlockCache(lb.index());
0289   if (subdetswitchtotdigifailureon && isStableBeams && !SBTransitionDone) {
0290     SBDeclaredAt = (int)currentLS;
0291     SBTransitionDone = true;
0292   }
0293 
0294   if (subdetswitchtotdigifailureon && currentLS % integrateNLumisections_ == 0) {
0295     int nFeds[6] = {96, 96, 84, 15, 15, 134};  // tec- , tec+ , tib , tid- , tid+ , tob
0296     int nFedsConnected[6] = {nFedTECm, nFedTECp, nFedTIB, nFedTIDm, nFedTIDp, nFedTOB};
0297 
0298     if (digiFailureMEs.SubDetTotDigiProfLS) {
0299       for (int ibin = 1; ibin < 7; ibin++) {
0300         //the vector now has the sum from previous integrateNLumisections_
0301         //whereas digiFailureMEs.SubDetTotDigiProfLS now has sum for all LS upto now.
0302         float value = digiFailureMEs.SubDetTotDigiProfLS->getBinContent(ibin) - vecSubDetTotDigiProfLS[ibin];
0303         vecSubDetTotDigiProfLS[ibin] = digiFailureMEs.SubDetTotDigiProfLS->getBinContent(ibin);
0304 
0305         float fillvalue = 2;
0306         if (isStableBeams
0307             //       && (int)lb.id().luminosityBlock() > ignoreFirstNLumisections_     //ignore first X lumisections for HV rampup
0308             && ((int)currentLS - SBDeclaredAt) > ignoreFirstNLumisections_ &&
0309             (float)nFedsConnected[ibin - 1] / nFeds[ibin - 1] > 0.5 && value < 50.) {
0310           fillvalue = 1.01;
0311         }
0312         //account for integrated LS: fill previous bins as well
0313         for (int fillbin = (int)currentLS - integrateNLumisections_ + 1; fillbin <= (int)currentLS; fillbin++)
0314           digiFailureMEs.SubDetDigiFailures2D->Fill(fillbin, ibin - 1, fillvalue);
0315       }
0316     }
0317   }
0318 }
0319 //--------------------------------------------------------------------------------------------
0320 void SiStripMonitorDigi::createMEs(DQMStore::IBooker& ibooker, const edm::EventSetup& es) {
0321   if (show_mechanical_structure_view) {
0322     //Retrieve tracker topology from geometry
0323     const TrackerTopology* const tTopo = &es.getData(tTopoTokenRun_);
0324     const TkDetMap* tkDetMap = &es.getData(tkDetMapTokenRun_);
0325 
0326     // take from eventSetup the SiStripDetCabling object - here will use SiStripDetControl later on
0327     SiStripDetCabling_ = &es.getData(SiStripDetCablingTokenRun_);
0328 
0329     // get list of active detectors from SiStripDetCabling
0330     std::vector<uint32_t> activeDets;
0331     activeDets.clear();  // just in case
0332     SiStripDetCabling_->addActiveDetectorsRawIds(activeDets);
0333 
0334     // remove any eventual zero elements - there should be none, but just in case
0335     for (std::vector<uint32_t>::iterator idets = activeDets.begin(); idets != activeDets.end(); idets++) {
0336       if (*idets == 0)
0337         activeDets.erase(idets);
0338     }
0339 
0340     // create SiStripFolderOrganizer
0341     SiStripFolderOrganizer folder_organizer;
0342 
0343     // Create TkHistoMap for Digi and APV shots properies
0344 
0345     if (digitkhistomapon)
0346       tkmapdigi = std::make_unique<TkHistoMap>(tkDetMap, ibooker, topFolderName_, "TkHMap_NumberOfDigi", 0.0, true);
0347     if (shotshistomapon)
0348       tkmapNApvshots = std::make_unique<TkHistoMap>(tkDetMap, ibooker, topFolderName_, "TkHMap_NApvShots", 0.0, true);
0349     if (shotsstripshistomapon)
0350       tkmapNstripApvshot =
0351           std::make_unique<TkHistoMap>(tkDetMap, ibooker, topFolderName_, "TkHMap_NStripApvShots", 0.0, true);
0352     if (shotschargehistomapon)
0353       tkmapMedianChargeApvshots =
0354           std::make_unique<TkHistoMap>(tkDetMap, ibooker, topFolderName_, "TkHMap_MedianChargeApvShots", 0.0, true);
0355 
0356     std::vector<uint32_t> tibDetIds;
0357 
0358     // loop over detectors and book MEs
0359     edm::LogInfo("SiStripTkDQM|SiStripMonitorDigi") << "nr. of activeDets:  " << activeDets.size();
0360     for (std::vector<uint32_t>::const_iterator detid_iterator = activeDets.begin(); detid_iterator != activeDets.end();
0361          detid_iterator++) {
0362       uint32_t detid = (*detid_iterator);
0363 
0364       ModMEs local_modmes;
0365 
0366       local_modmes.NumberOfDigis = nullptr;
0367       local_modmes.NumberOfDigisPerStrip = nullptr;
0368       local_modmes.ADCsHottestStrip = nullptr;
0369       local_modmes.ADCsCoolestStrip = nullptr;
0370       local_modmes.DigiADCs = nullptr;
0371       local_modmes.StripOccupancy = nullptr;
0372 
0373       if (Mod_On_) {
0374         // set appropriate folder using SiStripFolderOrganizer
0375         folder_organizer.setDetectorFolder(detid, tTopo);  // pass the detid to this method
0376         if (reset_each_run)
0377           ResetModuleMEs(detid);
0378         createModuleMEs(ibooker, local_modmes, detid);
0379 
0380         // append to DigiMEs
0381         DigiMEs.insert(std::make_pair(detid, local_modmes));
0382       }
0383 
0384       // Create Layer Level MEs if they are not created already
0385       std::pair<std::string, int32_t> det_layer_pair = folder_organizer.GetSubDetAndLayer(detid, tTopo);
0386       SiStripHistoId hidmanager;
0387       std::string label = hidmanager.getSubdetid(detid, tTopo, false);
0388 
0389       // get detids for the layer
0390       std::map<std::string, LayerMEs>::iterator iLayerME = LayerMEsMap.find(label);
0391 
0392       if (iLayerME == LayerMEsMap.end()) {
0393         int32_t lnumber = det_layer_pair.second;
0394         std::vector<uint32_t> layerDetIds;
0395         if (det_layer_pair.first == "TIB") {
0396           SiStripSubStructure::getTIBDetectors(activeDets, layerDetIds, tTopo, lnumber, 0, 0, 0);
0397         } else if (det_layer_pair.first == "TOB") {
0398           SiStripSubStructure::getTOBDetectors(activeDets, layerDetIds, tTopo, lnumber, 0, 0);
0399         } else if (det_layer_pair.first == "TID" && lnumber > 0) {
0400           SiStripSubStructure::getTIDDetectors(activeDets, layerDetIds, tTopo, 2, abs(lnumber), 0, 0);
0401         } else if (det_layer_pair.first == "TID" && lnumber < 0) {
0402           SiStripSubStructure::getTIDDetectors(activeDets, layerDetIds, tTopo, 1, abs(lnumber), 0, 0);
0403         } else if (det_layer_pair.first == "TEC" && lnumber > 0) {
0404           SiStripSubStructure::getTECDetectors(activeDets, layerDetIds, tTopo, 2, abs(lnumber), 0, 0, 0, 0);
0405         } else if (det_layer_pair.first == "TEC" && lnumber < 0) {
0406           SiStripSubStructure::getTECDetectors(activeDets, layerDetIds, tTopo, 1, abs(lnumber), 0, 0, 0, 0);
0407         }
0408 
0409         LayerDetMap[label] = layerDetIds;
0410 
0411         // book Layer plots
0412         folder_organizer.setLayerFolder(detid, tTopo, det_layer_pair.second);
0413         createLayerMEs(ibooker, label, layerDetIds.size());
0414       }
0415 
0416       // book sub-detector plots
0417       auto sdet_pair = folder_organizer.getSubDetFolderAndTag(detid, tTopo);
0418       if (SubDetMEsMap.find(sdet_pair.second) == SubDetMEsMap.end()) {
0419         ibooker.setCurrentFolder(sdet_pair.first);
0420         createSubDetMEs(ibooker, sdet_pair.second);
0421       }
0422 
0423     }  //end of loop over detectors
0424 
0425     //book some Summary histograms on APV shots in the MechanicalView
0426 
0427     ibooker.setCurrentFolder(topFolderName_ + "/MechanicalView/");
0428 
0429     if (globalsummaryapvshotson) {
0430       const char* HistoName = "Summary Mean Apv shots for SubDets";
0431       NApvShotsGlobalProf = ibooker.bookProfile(HistoName, HistoName, 6, 0.5, 6.5, 100, 0., 0., "");
0432       NApvShotsGlobalProf->setBinLabel(1, std::string("TEC-"));
0433       NApvShotsGlobalProf->setBinLabel(2, std::string("TEC+"));
0434       NApvShotsGlobalProf->setBinLabel(3, std::string("TIB"));
0435       NApvShotsGlobalProf->setBinLabel(4, std::string("TID-"));
0436       NApvShotsGlobalProf->setBinLabel(5, std::string("TID+"));
0437       NApvShotsGlobalProf->setBinLabel(6, std::string("TOB"));
0438       NApvShotsGlobalProf->setAxisTitle(" mean APV shots # / evt", 2);
0439     }
0440 
0441     //cumulative number of APV shots Vs Time
0442     if (globalswitchapvshotsonprof) {
0443       edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TProfNShotsVsTime");
0444       const char* HistoName = "NApv_Shots_vs_Time";
0445       ShotsVsTimeApvShotsGlobal = ibooker.bookProfile(HistoName,
0446                                                       HistoName,
0447                                                       Parameters.getParameter<int32_t>("Nbins"),
0448                                                       Parameters.getParameter<double>("xmin"),
0449                                                       Parameters.getParameter<double>("xmax"),
0450                                                       200,  //that parameter should not be there !?
0451                                                       Parameters.getParameter<double>("ymin"),
0452                                                       Parameters.getParameter<double>("ymax"),
0453                                                       "");
0454       ShotsVsTimeApvShotsGlobal->setAxisTitle("Time (s)", 1);
0455       ShotsVsTimeApvShotsGlobal->setAxisTitle("# Apv Shots", 2);
0456       if (ShotsVsTimeApvShotsGlobal->kind() == MonitorElement::Kind::TPROFILE)
0457         ShotsVsTimeApvShotsGlobal->setCanExtend(TH1::kAllAxes);
0458     }
0459 
0460     //cumulative number of Strips in APV shots
0461     if (globalswitchnstripsapvshotson) {
0462       edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TH1NStripsApvShots");
0463       const char* HistoName = "Number_of_Strips_in_Apv_Shots";
0464       StripMultiplicityApvShotsGlobal = ibooker.book1D(HistoName,
0465                                                        HistoName,
0466                                                        Parameters.getParameter<int32_t>("Nbins"),
0467                                                        Parameters.getParameter<double>("xmin"),
0468                                                        Parameters.getParameter<double>("xmax"));
0469       StripMultiplicityApvShotsGlobal->setAxisTitle("# strips in Apv Shots", 1);
0470     }
0471 
0472     //cumulative number of APV shots
0473     if (globalswitchnapvshotson) {
0474       edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TH1NApvShots");
0475       const char* HistoName = "Number_of_Apv_Shots";
0476       NApvShotsGlobal = ibooker.book1D(HistoName,
0477                                        HistoName,
0478                                        Parameters.getParameter<int32_t>("Nbins"),
0479                                        Parameters.getParameter<double>("xmin"),
0480                                        Parameters.getParameter<double>("xmax"));
0481       NApvShotsGlobal->setAxisTitle("# Apv Shots", 1);
0482     }
0483 
0484     //cumulative Median Charge in APV shots
0485     if (globalswitchchargemedianapvshotson) {
0486       edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TH1ChargeMedianApvShots");
0487       //dqmStore_->setCurrentFolder("SiStrip/MechanicalView/"+label);
0488       const char* HistoName = "Apv_Shots_Charge_Median";
0489       MedianChargeApvShotsGlobal = ibooker.book1D(HistoName,
0490                                                   HistoName,
0491                                                   Parameters.getParameter<int32_t>("Nbins"),
0492                                                   Parameters.getParameter<double>("xmin"),
0493                                                   Parameters.getParameter<double>("xmax"));
0494       MedianChargeApvShotsGlobal->setAxisTitle("Apv Shots Charge Median (ADC)", 1);
0495     }
0496 
0497     //cmulative APV number with shots
0498     if (globalswitchapvshotsApvon) {
0499       edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TH1ApvNumApvShots");
0500       //dqmStore_->setCurrentFolder("SiStrip/MechanicalView/"+label);
0501       const char* HistoName = "Apv_Shots_Apv_Number";
0502       NApvApvShotsGlobal = ibooker.book1D(HistoName,
0503                                           HistoName,
0504                                           Parameters.getParameter<int32_t>("Nbins"),
0505                                           Parameters.getParameter<double>("xmin"),
0506                                           Parameters.getParameter<double>("xmax"));
0507       NApvApvShotsGlobal->setAxisTitle("Apv Number", 1);
0508     }
0509 
0510     if (globalswitchNDigisFEDID) {
0511       // Number of digis per FED
0512       edm::ParameterSet FEDDigi = conf_.getParameter<edm::ParameterSet>("TProfNDigisFED");
0513       const char* HistoName = "NumberOfDigisinFED_v_FEDID";
0514       //Using TProfile for average.
0515       NumberOfFEDDigis = ibooker.bookProfile(HistoName,
0516                                              HistoName,
0517                                              FEDDigi.getParameter<int32_t>("Nbinsx"),
0518                                              FEDDigi.getParameter<double>("xmin"),
0519                                              FEDDigi.getParameter<double>("xmax"),
0520                                              FEDDigi.getParameter<int32_t>("Nbinsy"),
0521                                              FEDDigi.getParameter<double>("ymin"),
0522                                              FEDDigi.getParameter<double>("ymax"),
0523                                              "");
0524       NumberOfFEDDigis->setAxisTitle("FED ID", 1);
0525       NumberOfFEDDigis->setAxisTitle("Mean # of Digis in FED", 2);
0526     }
0527 
0528     //
0529     // Book new histogram to monitor digi in last LS
0530     //
0531 
0532     digiFailureMEs.SubDetTotDigiProfLS = nullptr;
0533     digiFailureMEs.SubDetDigiFailures2D = nullptr;
0534 
0535     std::stringstream ss;
0536 
0537     folder_organizer.getLayerFolderName(ss, 0, tTopo);
0538     ibooker.setCurrentFolder(ss.str());
0539 
0540     if (subdetswitchtotdigifailureon) {
0541       const char* HistoName = "NumberOfDigisInLastLS";
0542       digiFailureMEs.SubDetTotDigiProfLS = ibooker.bookProfile(HistoName, HistoName, 6, 0.5, 6.5, 0., 0., "");
0543       digiFailureMEs.SubDetTotDigiProfLS->setBinLabel(1, std::string("TEC-"));
0544       digiFailureMEs.SubDetTotDigiProfLS->setBinLabel(2, std::string("TEC+"));
0545       digiFailureMEs.SubDetTotDigiProfLS->setBinLabel(3, std::string("TIB"));
0546       digiFailureMEs.SubDetTotDigiProfLS->setBinLabel(4, std::string("TID-"));
0547       digiFailureMEs.SubDetTotDigiProfLS->setBinLabel(5, std::string("TID+"));
0548       digiFailureMEs.SubDetTotDigiProfLS->setBinLabel(6, std::string("TOB"));
0549     }
0550 
0551     if (subdetswitchtotdigifailureon) {
0552       std::string HistoName = "DataPresentInLS";
0553       edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TotalNumberOfDigisFailure");
0554 
0555       digiFailureMEs.SubDetDigiFailures2D = ibooker.book2D(HistoName,
0556                                                            HistoName,
0557                                                            Parameters.getParameter<int32_t>("Nbins"),      //bins X
0558                                                            1,                                              //xmin
0559                                                            Parameters.getParameter<int32_t>("Nbins") + 1,  //xmax
0560                                                            6,                                              //bins Y
0561                                                            0,                                              //ymin
0562                                                            6);                                             //ymax
0563 
0564       digiFailureMEs.SubDetDigiFailures2D->setBinLabel(1, std::string("TEC-"), 2);
0565       digiFailureMEs.SubDetDigiFailures2D->setBinLabel(2, std::string("TEC+"), 2);
0566       digiFailureMEs.SubDetDigiFailures2D->setBinLabel(3, std::string("TIB"), 2);
0567       digiFailureMEs.SubDetDigiFailures2D->setBinLabel(4, std::string("TID-"), 2);
0568       digiFailureMEs.SubDetDigiFailures2D->setBinLabel(5, std::string("TID+"), 2);
0569       digiFailureMEs.SubDetDigiFailures2D->setBinLabel(6, std::string("TOB"), 2);
0570       digiFailureMEs.SubDetDigiFailures2D->setAxisTitle("Luminosity Section");
0571     }
0572   }  //end of if
0573 
0574 }  //end of method
0575 
0576 //--------------------------------------------------------------------------------------------
0577 void SiStripMonitorDigi::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0578   // Filter out events if DCS Event if requested
0579   if (dcsStatus_ && !dcsStatus_->getStatus(iEvent, iSetup))
0580     return;
0581 
0582   //Retrieve tracker topology from geometry
0583   const TrackerTopology* const tTopo = &iSetup.getData(tTopoToken_);
0584 
0585   TotalNShots = 0;
0586 
0587   runNb = iEvent.id().run();
0588   eventNb++;
0589 
0590   float iOrbitVar =
0591       m_trendVs10LS ? iEvent.orbitNumber() / (10 * NORBITS_PER_LS) : iEvent.orbitNumber() / NORBITS_PER_LS;
0592 
0593   digi_detset_handles.clear();
0594 
0595   std::vector<edm::EDGetTokenT<edm::DetSetVector<SiStripDigi> > >::const_iterator iToken =
0596       digiProducerTokenList.begin();
0597   for (std::vector<edm::InputTag>::const_iterator iter = digiProducerList.begin(), iEnd = digiProducerList.end();
0598        iter != iEnd;
0599        ++iter, ++iToken) {
0600     edm::Handle<edm::DetSetVector<SiStripDigi> > digi_handle;
0601     iEvent.getByToken(*iToken, digi_handle);
0602     if (digi_handle.isValid())
0603       digi_detset_handles.push_back(digi_handle.product());
0604   }
0605 
0606   // initialise # of clusters to zero
0607   for (std::map<std::string, SubDetMEs>::iterator iSubdet = SubDetMEsMap.begin(); iSubdet != SubDetMEsMap.end();
0608        iSubdet++) {
0609     iSubdet->second.totNDigis = 0;
0610     iSubdet->second.SubDetApvShots.clear();
0611   }
0612 
0613   std::map<int, int> FEDID_v_digisum;
0614 
0615   for (std::map<std::string, std::vector<uint32_t> >::const_iterator iterLayer = LayerDetMap.begin();
0616        iterLayer != LayerDetMap.end();
0617        iterLayer++) {
0618     std::string layer_label = iterLayer->first;
0619 
0620     std::vector<uint32_t> layer_dets = iterLayer->second;
0621     std::map<std::string, LayerMEs>::iterator iLayerME = LayerMEsMap.find(layer_label);
0622 
0623     //get Layer MEs
0624     LayerMEs local_layermes;
0625 
0626     if (iLayerME == LayerMEsMap.end())
0627       continue;
0628     else
0629       local_layermes = iLayerME->second;
0630 
0631     int largest_adc_layer = 0;
0632     int smallest_adc_layer = 99999;
0633 
0634     int ndigi_layer = 0;
0635 
0636     uint16_t iDet = 0;
0637 
0638     std::string subdet_label = "";
0639 
0640     // loop over all modules in the layer
0641     for (std::vector<uint32_t>::const_iterator iterDets = layer_dets.begin(); iterDets != layer_dets.end();
0642          iterDets++) {
0643       iDet++;
0644 
0645       // detid and type of ME
0646       uint32_t detid = (*iterDets);
0647 
0648       // Get SubDet label once
0649       if (subdet_label.empty())
0650         subdet_label = folder_organizer.getSubDetFolderAndTag(detid, tTopo).second;
0651 
0652       // DetId and corresponding set of MEs
0653 
0654       std::map<uint32_t, ModMEs>::iterator pos = DigiMEs.find(detid);
0655       ModMEs local_modmes = pos->second;
0656 
0657       // search  digis of detid
0658       int loc = getDigiSourceIndex(detid);
0659 
0660       int ndigi_det = 0;
0661 
0662       if (loc > -1) {
0663         ndigi_det = (*(digi_detset_handles[loc]))[detid].size();
0664 
0665         //////////////////////// FED N digis Monitoring //////////////////////
0666 
0667         //Get all FED connections associated with given detID.
0668         // All connections for a detid have same FED Id therefore one FEDID is associated with a given detID.
0669         std::vector<const FedChannelConnection*> fedConnections = SiStripDetCabling_->getConnections(detid);
0670 
0671         // Filling FED Id associated clusters map.
0672 
0673         int good_fcc_index = -999;
0674         for (unsigned int x = 0; x < fedConnections.size(); x++) {
0675           if (fedConnections[x] != nullptr) {
0676             good_fcc_index = x;
0677             break;
0678           }
0679         }
0680         if (fedConnections[good_fcc_index] != nullptr) {
0681           int temp_fedid = fedConnections[good_fcc_index]->fedId();
0682           if (FEDID_v_digisum.find(temp_fedid) != FEDID_v_digisum.end()) {
0683             if (ndigi_det < 1000 && ndigi_det > 0) {
0684               FEDID_v_digisum[temp_fedid] = FEDID_v_digisum.find(temp_fedid)->second + ndigi_det;
0685             }
0686           } else {
0687             if (ndigi_det < 1000 && ndigi_det > 0) {
0688               FEDID_v_digisum[temp_fedid] = ndigi_det;
0689             }
0690           }
0691         } else {
0692           edm::LogInfo("SiStripMonitorDigi")
0693               << "SiStripMonitorDigi::analyze WARNING! no good connections for detid = " << detid << std::endl;
0694         }
0695         ///////////////////////////////////////////////////////////////////////////
0696 
0697         APVShotFinder theShotFinder = APVShotFinder((*(digi_detset_handles[loc]))[detid]);
0698         const std::vector<APVShot>& shots = theShotFinder.getShots();
0699         AddApvShotsToSubDet(shots, SubDetMEsMap[subdet_label].SubDetApvShots);
0700         if (shotshistomapon)
0701           tkmapNApvshots->fill(detid, shots.size());
0702         if (shotsstripshistomapon)
0703           FillApvShotsMap(tkmapNstripApvshot.get(), shots, detid, 1);
0704         if (shotschargehistomapon)
0705           FillApvShotsMap(tkmapMedianChargeApvshots.get(), shots, detid, 2);
0706       }
0707 
0708       if (Mod_On_ && moduleswitchnumdigison && (local_modmes.NumberOfDigis != nullptr))
0709         (local_modmes.NumberOfDigis)->Fill(ndigi_det);
0710 
0711       if (layerswitchnumdigisprofon)
0712         local_layermes.LayerNumberOfDigisProfile->Fill(iDet * 1.0, ndigi_det);
0713 
0714       if (digitkhistomapon)
0715         tkmapdigi->fill(detid, ndigi_det);
0716 
0717       if (ndigi_det == 0)
0718         continue;  // no digis for this detid => jump to next step of loop
0719 
0720       const edm::DetSet<SiStripDigi>& digi_detset = (*(digi_detset_handles[loc]))[detid];
0721 
0722       ndigi_layer += ndigi_det;
0723 
0724       // ADCs
0725       int largest_adc = (digi_detset.data.begin())->adc();
0726       int smallest_adc = (digi_detset.data.begin())->adc();
0727 
0728       // Check if these parameters are really needed
0729       float det_occupancy = 0.0;
0730 
0731       for (edm::DetSet<SiStripDigi>::const_iterator digiIter = digi_detset.data.begin();
0732            digiIter != digi_detset.data.end();
0733            digiIter++) {
0734         int this_adc = digiIter->adc();
0735 
0736         if (this_adc > 0.0)
0737           det_occupancy++;
0738 
0739         if (this_adc > largest_adc)
0740           largest_adc = this_adc;
0741         if (this_adc < smallest_adc)
0742           smallest_adc = this_adc;
0743 
0744         if (Mod_On_ && moduleswitchnumdigispstripon && (local_modmes.NumberOfDigisPerStrip != nullptr) &&
0745             (this_adc > 0.0))
0746           (local_modmes.NumberOfDigisPerStrip)->Fill(digiIter->strip());
0747 
0748         if (Mod_On_ && moduleswitchdigiadcson && (local_modmes.DigiADCs != nullptr))
0749           (local_modmes.DigiADCs)->Fill(static_cast<float>(this_adc));
0750 
0751         //Fill #ADCs for this digi at layer level
0752         if (layerswitchdigiadcson) {
0753           fillME(local_layermes.LayerDigiADCs, this_adc);
0754           if (createTrendMEs)
0755             fillTrend(local_layermes.LayerDigiADCsTrend, this_adc, iOrbitVar);
0756         }
0757 
0758         if (layerswitchdigiadcprofon)
0759           local_layermes.LayerDigiADCProfile->Fill(iDet * 1.0, this_adc);
0760 
0761       }  //end of loop over digis in this det
0762 
0763       // Occupancy
0764       short nstrips = SiStripDetCabling_->nApvPairs(detid) * 2 * 128;
0765       if (nstrips > 0 && det_occupancy > 0) {
0766         det_occupancy = det_occupancy / nstrips;
0767         if (Mod_On_ && moduleswitchstripoccupancyon && (local_modmes.StripOccupancy != nullptr))
0768           (local_modmes.StripOccupancy)->Fill(det_occupancy);
0769         if (layerswitchstripoccupancyon) {
0770           fillME(local_layermes.LayerStripOccupancy, det_occupancy);
0771           if (createTrendMEs)
0772             fillTrend(local_layermes.LayerStripOccupancyTrend, det_occupancy, iOrbitVar);
0773         }
0774       }
0775 
0776       if (largest_adc > largest_adc_layer)
0777         largest_adc_layer = largest_adc;
0778       if (smallest_adc < smallest_adc_layer)
0779         smallest_adc_layer = smallest_adc;
0780 
0781       // nr. of adcs for hottest strip
0782       if (Mod_On_ && moduleswitchadchotteston && (local_modmes.ADCsHottestStrip != nullptr))
0783         (local_modmes.ADCsHottestStrip)->Fill(static_cast<float>(largest_adc));
0784 
0785       // nr. of adcs for coolest strip
0786       if (Mod_On_ && moduleswitchadccooleston && (local_modmes.ADCsCoolestStrip != nullptr))
0787         (local_modmes.ADCsCoolestStrip)->Fill(static_cast<float>(smallest_adc));
0788 
0789     }  //end of loop over DetIds
0790 
0791     if (layerswitchnumdigison) {
0792       fillME(local_layermes.LayerNumberOfDigis, ndigi_layer);
0793       if (createTrendMEs)
0794         fillTrend(local_layermes.LayerNumberOfDigisTrend, ndigi_layer, iOrbitVar);
0795     }
0796     if (layerswitchadchotteston) {
0797       fillME(local_layermes.LayerADCsHottestStrip, largest_adc_layer);
0798       if (createTrendMEs)
0799         fillTrend(local_layermes.LayerADCsHottestStripTrend, largest_adc_layer, iOrbitVar);
0800     }
0801     if (layerswitchadccooleston) {
0802       fillME(local_layermes.LayerADCsCoolestStrip, smallest_adc_layer);
0803       if (createTrendMEs)
0804         fillTrend(local_layermes.LayerADCsCoolestStripTrend, smallest_adc_layer, iOrbitVar);
0805     }
0806 
0807     std::map<std::string, SubDetMEs>::iterator iSubdet = SubDetMEsMap.find(subdet_label);
0808     if (iSubdet != SubDetMEsMap.end()) {
0809       iSubdet->second.totNDigis += ndigi_layer;
0810       //std::cout << " totDigis" <<  iSubdet->second.totNDigis << " in "  << subdet_label << std::endl;
0811     }
0812   }
0813 
0814   bool& isStableBeams = *luminosityBlockCache(iEvent.getLuminosityBlock().index());
0815   if (subdetswitchtotdigifailureon) {
0816     //check Stable beams bit
0817     edm::Handle<L1GlobalTriggerEvmReadoutRecord> gtEvm_handle;
0818     iEvent.getByToken(gtEvmToken_, gtEvm_handle);
0819     L1GlobalTriggerEvmReadoutRecord const* gtevm = gtEvm_handle.product();
0820 
0821     L1GtfeExtWord gtfeEvmExtWord;
0822     if (gtevm) {
0823       gtfeEvmExtWord = gtevm->gtfeWord();
0824     } else
0825       edm::LogInfo("DQMProvInfo") << " gtfeEvmWord inaccessible";
0826 
0827     /* mia: is there not a smarter way !?!?!?!? */
0828     if (gtfeEvmExtWord.beamMode() == 11)
0829       isStableBeams = true;
0830   }
0831 
0832   for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
0833     if (subdetswitchtotdigifailureon) {
0834       if (strcmp(it->first.c_str(), "TEC__MINUS") == 0) {
0835         digiFailureMEs.SubDetTotDigiProfLS->Fill(1, it->second.totNDigis);
0836       } else if (strcmp(it->first.c_str(), "TEC__PLUS") == 0) {
0837         digiFailureMEs.SubDetTotDigiProfLS->Fill(2, it->second.totNDigis);
0838       } else if (strcmp(it->first.c_str(), "TIB") == 0) {
0839         digiFailureMEs.SubDetTotDigiProfLS->Fill(3, it->second.totNDigis);
0840       } else if (strcmp(it->first.c_str(), "TID__MINUS") == 0) {
0841         digiFailureMEs.SubDetTotDigiProfLS->Fill(4, it->second.totNDigis);
0842       } else if (strcmp(it->first.c_str(), "TID__PLUS") == 0) {
0843         digiFailureMEs.SubDetTotDigiProfLS->Fill(5, it->second.totNDigis);
0844       } else if (strcmp(it->first.c_str(), "TOB") == 0) {
0845         digiFailureMEs.SubDetTotDigiProfLS->Fill(6, it->second.totNDigis);
0846       }
0847     }
0848 
0849     if (globalsummaryapvshotson) {
0850       if (strcmp(it->first.c_str(), "TEC__MINUS") == 0) {
0851         NApvShotsGlobalProf->Fill(1, it->second.SubDetApvShots.size());
0852       } else if (strcmp(it->first.c_str(), "TEC__PLUS") == 0) {
0853         NApvShotsGlobalProf->Fill(2, it->second.SubDetApvShots.size());
0854       } else if (strcmp(it->first.c_str(), "TIB") == 0) {
0855         NApvShotsGlobalProf->Fill(3, it->second.SubDetApvShots.size());
0856       } else if (strcmp(it->first.c_str(), "TID__MINUS") == 0) {
0857         NApvShotsGlobalProf->Fill(4, it->second.SubDetApvShots.size());
0858       } else if (strcmp(it->first.c_str(), "TID__PLUS") == 0) {
0859         NApvShotsGlobalProf->Fill(5, it->second.SubDetApvShots.size());
0860       } else if (strcmp(it->first.c_str(), "TOB") == 0) {
0861         NApvShotsGlobalProf->Fill(6, it->second.SubDetApvShots.size());
0862       }
0863     }
0864 
0865     SubDetMEs subdetmes = it->second;
0866     std::string subdet = it->first;
0867 
0868     // Fill APV shots histograms for SubDet
0869 
0870     uint ShotsSize = subdetmes.SubDetApvShots.size();
0871     TotalNShots += ShotsSize;  //Counter for total Shots in the SiStrip Tracker
0872 
0873     if (subdetswitchnapvshotson)
0874       subdetmes.SubDetNApvShotsTH1->Fill(ShotsSize);  // N shots
0875     if (subdetswitchapvshotsonprof)
0876       subdetmes.SubDetNApvShotsProf->Fill(iOrbitVar, ShotsSize);  //N shots vs time
0877 
0878     for (uint i = 0; i < ShotsSize;
0879          ++i) {  // Strip multiplicity, charge median and APV number distributions for APV shots
0880 
0881       if (subdetswitchapvshotsApvon)
0882         subdetmes.SubDetNApvShotsNApvTH1->Fill(
0883             (subdetmes.SubDetApvShots[i].apvNumber() + 1));  //APV are defined by 0 to 5 I want 1 to 6
0884       if (globalswitchapvshotsApvon)
0885         NApvApvShotsGlobal->Fill((subdetmes.SubDetApvShots[i].apvNumber() + 1));
0886 
0887       if (subdetswitchnstripsapvshotson)
0888         subdetmes.SubDetNStripsApvShotsTH1->Fill(subdetmes.SubDetApvShots[i].nStrips());
0889       if (globalswitchnstripsapvshotson)
0890         StripMultiplicityApvShotsGlobal->Fill(subdetmes.SubDetApvShots[i].nStrips());
0891 
0892       if (subdetswitchchargemedianapvshotson)
0893         subdetmes.SubDetChargeMedianApvShotsTH1->Fill(subdetmes.SubDetApvShots[i].median());
0894       if (globalswitchchargemedianapvshotson)
0895         MedianChargeApvShotsGlobal->Fill(subdetmes.SubDetApvShots[i].median());
0896     }
0897 
0898     if (subdetswitchtotdigiprofon)
0899       subdetmes.SubDetTotDigiProf->Fill(iOrbitVar, subdetmes.totNDigis);
0900   }
0901 
0902   if (globalswitchnapvshotson)
0903     NApvShotsGlobal->Fill(TotalNShots);
0904   if (globalswitchapvshotsonprof)
0905     ShotsVsTimeApvShotsGlobal->Fill(iOrbitVar, TotalNShots);
0906 
0907   if (globalswitchNDigisFEDID) {
0908     std::map<int, int>::iterator it;
0909     for (it = FEDID_v_digisum.begin(); it != FEDID_v_digisum.end(); it++) {
0910       NumberOfFEDDigis->Fill(it->first, it->second);
0911     }
0912   }
0913 
0914   // get EventHistory
0915 
0916   edm::Handle<EventWithHistory> event_history;
0917   iEvent.getByToken(historyProducerToken_, event_history);
0918 
0919   // get Phase of APV
0920   edm::Handle<APVCyclePhaseCollection> apv_phase_collection;
0921   iEvent.getByToken(apvPhaseProducerToken_, apv_phase_collection);
0922 
0923   if (event_history.isValid() && !event_history.failedToGet() && apv_phase_collection.isValid() &&
0924       !apv_phase_collection.failedToGet()) {
0925     long long tbx = event_history->absoluteBX();
0926 
0927     for (std::map<std::string, SubDetMEs>::iterator it = SubDetMEsMap.begin(); it != SubDetMEsMap.end(); it++) {
0928       SubDetMEs subdetmes;
0929       std::string subdet = it->first;
0930       subdetmes = it->second;
0931 
0932       int the_phase = APVCyclePhaseCollection::invalid;
0933       long long tbx_corr = tbx;
0934 
0935       if (SubDetPhasePartMap.find(subdet) != SubDetPhasePartMap.end())
0936         the_phase = apv_phase_collection->getPhase(SubDetPhasePartMap[subdet]);
0937       if (the_phase == APVCyclePhaseCollection::nopartition || the_phase == APVCyclePhaseCollection::multiphase ||
0938           the_phase == APVCyclePhaseCollection::invalid)
0939         the_phase = 30;
0940       tbx_corr -= the_phase;
0941 
0942       if (subdetswitchapvcycleprofon)
0943         subdetmes.SubDetDigiApvProf->Fill(tbx_corr % 70, subdetmes.totNDigis);
0944       if (subdetswitchapvcycleth2on)
0945         subdetmes.SubDetDigiApvTH2->Fill(tbx_corr % 70, subdetmes.totNDigis);
0946     }
0947   }
0948 }  //end of method analyze
0949 //--------------------------------------------------------------------------------------------
0950 void SiStripMonitorDigi::ResetModuleMEs(uint32_t idet) {
0951   std::map<uint32_t, ModMEs>::iterator pos = DigiMEs.find(idet);
0952   ModMEs mod_me = pos->second;
0953 
0954   if (Mod_On_ && moduleswitchnumdigison)
0955     mod_me.NumberOfDigis->Reset();
0956   if (Mod_On_ && moduleswitchnumdigispstripon)
0957     mod_me.NumberOfDigisPerStrip->Reset();
0958   if (Mod_On_ && moduleswitchadchotteston)
0959     mod_me.ADCsHottestStrip->Reset();
0960   if (Mod_On_ && moduleswitchadccooleston)
0961     mod_me.ADCsCoolestStrip->Reset();
0962   if (Mod_On_ && moduleswitchdigiadcson)
0963     mod_me.DigiADCs->Reset();
0964   if (Mod_On_ && moduleswitchstripoccupancyon)
0965     mod_me.StripOccupancy->Reset();
0966 }
0967 //------------------------------------------------------------------------------------------
0968 SiStripMonitorDigi::MonitorElement* SiStripMonitorDigi::bookMETrend(DQMStore::IBooker& ibooker,
0969                                                                     const char* ParameterSetLabel,
0970                                                                     const char* HistoName) {
0971   edm::ParameterSet ParametersTrend = conf_.getParameter<edm::ParameterSet>("Trending");
0972   MonitorElement* me =
0973       ibooker.bookProfile(HistoName,
0974                           HistoName,
0975                           ParametersTrend.getParameter<int32_t>("Nbins"),
0976                           //                          0,
0977                           ParametersTrend.getParameter<double>("xmin"),
0978                           ParametersTrend.getParameter<double>("xmax"),
0979                           //                          ParametersTrend.getParameter<int32_t>("Nbins"),
0980                           100,  //that parameter should not be there !?
0981                           ParametersTrend.getParameter<double>("ymin"),
0982                           ParametersTrend.getParameter<double>("ymax"),
0983                           "");
0984   if (!me)
0985     return me;
0986 
0987   me->setAxisTitle("Lumisection", 1);
0988   if (me->kind() == MonitorElement::Kind::TPROFILE)
0989     me->setCanExtend(TH1::kAllAxes);
0990   return me;
0991 }
0992 
0993 //------------------------------------------------------------------------------------------
0994 SiStripMonitorDigi::MonitorElement* SiStripMonitorDigi::bookME1D(DQMStore::IBooker& ibooker,
0995                                                                  const char* ParameterSetLabel,
0996                                                                  const char* HistoName) {
0997   edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
0998   return ibooker.book1D(HistoName,
0999                         HistoName,
1000                         Parameters.getParameter<int32_t>("Nbinx"),
1001                         Parameters.getParameter<double>("xmin"),
1002                         Parameters.getParameter<double>("xmax"));
1003 }
1004 
1005 //--------------------------------------------------------------------------------
1006 void SiStripMonitorDigi::fillTrend(MonitorElement* me, float value, float timeinorbit) {
1007   if (!me)
1008     return;
1009   me->Fill(timeinorbit, value);
1010 }
1011 
1012 //
1013 // -- Create Module Level MEs
1014 //
1015 void SiStripMonitorDigi::createModuleMEs(DQMStore::IBooker& ibooker, ModMEs& mod_single, uint32_t detid) {
1016   // use SistripHistoId for producing histogram id (and title)
1017   SiStripHistoId hidmanager;
1018   std::string hid;
1019 
1020   //nr. of digis per module
1021   if (moduleswitchnumdigison) {
1022     hid = hidmanager.createHistoId("NumberOfDigis", "det", detid);
1023     mod_single.NumberOfDigis = ibooker.book1D(hid, hid, 21, -0.5, 20.5);
1024     mod_single.NumberOfDigis->setAxisTitle("number of digis in one detector module");
1025     mod_single.NumberOfDigis->setStatOverflows(kTRUE);  // over/underflows in Mean calculation
1026   }
1027 
1028   //nr. of digis per strip in module
1029   if (moduleswitchnumdigispstripon) {
1030     hid = hidmanager.createHistoId("NumberOfDigisPerStrip", "det", detid);
1031     short nstrips = SiStripDetCabling_->nApvPairs(detid) * 2 * 128;
1032     mod_single.NumberOfDigisPerStrip = ibooker.book1D(hid, hid, nstrips, -0.5, nstrips + 0.5);
1033     mod_single.NumberOfDigisPerStrip->setAxisTitle("number of (digis > 0) per strip");
1034     mod_single.NumberOfDigisPerStrip->setStatOverflows(kTRUE);  // over/underflows in Mean calculation
1035   }
1036   //#ADCs for hottest strip
1037   if (moduleswitchadchotteston) {
1038     hid = hidmanager.createHistoId("ADCsHottestStrip", "det", detid);
1039     mod_single.ADCsHottestStrip = bookME1D(ibooker, "TH1ADCsHottestStrip", hid.c_str());
1040     mod_single.ADCsHottestStrip->setAxisTitle("number of ADCs for hottest strip");
1041   }
1042 
1043   //#ADCs for coolest strip
1044   if (moduleswitchadccooleston) {
1045     hid = hidmanager.createHistoId("ADCsCoolestStrip", "det", detid);
1046     mod_single.ADCsCoolestStrip = bookME1D(ibooker, "TH1ADCsCoolestStrip", hid.c_str());
1047     mod_single.ADCsCoolestStrip->setAxisTitle("number of ADCs for coolest strip");
1048   }
1049 
1050   //#ADCs for each digi
1051   if (moduleswitchdigiadcson) {
1052     hid = hidmanager.createHistoId("DigiADCs", "det", detid);
1053     mod_single.DigiADCs = bookME1D(ibooker, "TH1DigiADCs", hid.c_str());
1054     mod_single.DigiADCs->setAxisTitle("number of ADCs for each digi");
1055   }
1056 
1057   //Strip occupancy
1058   if (moduleswitchstripoccupancyon) {
1059     hid = hidmanager.createHistoId("StripOccupancy", "det", detid);
1060     mod_single.StripOccupancy = bookME1D(ibooker, "TH1StripOccupancy", hid.c_str());
1061     mod_single.StripOccupancy->setAxisTitle("strip occupancy");
1062   }
1063 }
1064 
1065 //
1066 // -- Create Module Level MEs
1067 //
1068 
1069 void SiStripMonitorDigi::createLayerMEs(DQMStore::IBooker& ibooker, std::string label, int ndets) {
1070   std::map<std::string, LayerMEs>::iterator iLayerME = LayerMEsMap.find(label);
1071   if (iLayerME == LayerMEsMap.end()) {
1072     SiStripHistoId hidmanager;
1073     LayerMEs layerMEs;
1074     layerMEs.LayerNumberOfDigis = nullptr;
1075     layerMEs.LayerNumberOfDigisTrend = nullptr;
1076     layerMEs.LayerADCsHottestStrip = nullptr;
1077     layerMEs.LayerADCsHottestStripTrend = nullptr;
1078     layerMEs.LayerADCsCoolestStrip = nullptr;
1079     layerMEs.LayerADCsCoolestStripTrend = nullptr;
1080     layerMEs.LayerDigiADCs = nullptr;
1081     layerMEs.LayerDigiADCsTrend = nullptr;
1082     layerMEs.LayerStripOccupancy = nullptr;
1083     layerMEs.LayerStripOccupancyTrend = nullptr;
1084     layerMEs.LayerNumberOfDigisProfile = nullptr;
1085     layerMEs.LayerDigiADCProfile = nullptr;
1086 
1087     //#Digis
1088     if (layerswitchnumdigison) {
1089       layerMEs.LayerNumberOfDigis =
1090           bookME1D(ibooker,
1091                    "TH1NumberOfDigis",
1092                    hidmanager.createHistoLayer("Summary_TotalNumberOfDigis", "layer", label, "").c_str());
1093       if (createTrendMEs)
1094         layerMEs.LayerNumberOfDigisTrend =
1095             bookMETrend(ibooker,
1096                         "TH1NumberOfDigis",
1097                         hidmanager.createHistoLayer("Trend_NumberOfDigis", "layer", label, "").c_str());
1098     }
1099 
1100     //#ADCs for hottest strip
1101     if (layerswitchadchotteston) {
1102       layerMEs.LayerADCsHottestStrip =
1103           bookME1D(ibooker,
1104                    "TH1ADCsHottestStrip",
1105                    hidmanager.createHistoLayer("Summary_ADCsHottestStrip", "layer", label, "").c_str());
1106       if (createTrendMEs)
1107         layerMEs.LayerADCsHottestStripTrend =
1108             bookMETrend(ibooker,
1109                         "TH1ADCsHottestStrip",
1110                         hidmanager.createHistoLayer("Trend_ADCsHottestStrip", "layer", label, "").c_str());
1111     }
1112 
1113     //#ADCs for coolest strip
1114     if (layerswitchadccooleston) {
1115       layerMEs.LayerADCsCoolestStrip =
1116           bookME1D(ibooker,
1117                    "TH1ADCsCoolestStrip",
1118                    hidmanager.createHistoLayer("Summary_ADCsCoolestStrip", "layer", label, "").c_str());
1119       if (createTrendMEs)
1120         layerMEs.LayerADCsCoolestStripTrend =
1121             bookMETrend(ibooker,
1122                         "TH1ADCsCoolestStrip",
1123                         hidmanager.createHistoLayer("Trend_ADCsCoolestStrip", "layer", label, "").c_str());
1124     }
1125 
1126     //#ADCs for each digi
1127     if (layerswitchdigiadcson) {
1128       layerMEs.LayerDigiADCs =
1129           bookME1D(ibooker, "TH1DigiADCs", hidmanager.createHistoLayer("Summary_DigiADCs", "layer", label, "").c_str());
1130       if (createTrendMEs)
1131         layerMEs.LayerDigiADCsTrend = bookMETrend(
1132             ibooker, "TH1DigiADCs", hidmanager.createHistoLayer("Trend_DigiADCs", "layer", label, "").c_str());
1133     }
1134 
1135     //Strip Occupancy
1136     if (layerswitchstripoccupancyon) {
1137       layerMEs.LayerStripOccupancy =
1138           bookME1D(ibooker,
1139                    "TH1StripOccupancy",
1140                    hidmanager.createHistoLayer("Summary_StripOccupancy", "layer", label, "").c_str());
1141       if (createTrendMEs)
1142         layerMEs.LayerStripOccupancyTrend =
1143             bookMETrend(ibooker,
1144                         "TH1StripOccupancy",
1145                         hidmanager.createHistoLayer("Trend_StripOccupancy", "layer", label, "").c_str());
1146     }
1147     // # of Digis
1148     if (layerswitchnumdigisprofon) {
1149       std::string hid = hidmanager.createHistoLayer("NumberOfDigiProfile", "layer", label, "");
1150       layerMEs.LayerNumberOfDigisProfile = ibooker.bookProfile(hid, hid, ndets, 0.5, ndets + 0.5, 21, -0.5, 200.5);
1151     }
1152 
1153     // # of Digis
1154     if (layerswitchdigiadcprofon) {
1155       std::string hid = hidmanager.createHistoLayer("DigiADCProfile", "layer", label, "");
1156       layerMEs.LayerDigiADCProfile = ibooker.bookProfile(hid, hid, ndets, 0.5, ndets + 0.5, 64, -0.5, 255.5);
1157     }
1158 
1159     LayerMEsMap[label] = layerMEs;
1160   }
1161 }
1162 //
1163 // -- Create SubDetector MEs
1164 //
1165 void SiStripMonitorDigi::createSubDetMEs(DQMStore::IBooker& ibooker, std::string label) {
1166   SubDetMEs subdetMEs;
1167 
1168   std::string HistoName;
1169 
1170   // Total Number of Digi - Profile
1171   if (subdetswitchtotdigiprofon) {
1172     edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TProfTotalNumberOfDigis");
1173     HistoName = "TotalNumberOfDigiProfile__" + label;
1174     subdetMEs.SubDetTotDigiProf = ibooker.bookProfile(HistoName,
1175                                                       HistoName,
1176                                                       Parameters.getParameter<int32_t>("Nbins"),
1177                                                       Parameters.getParameter<double>("xmin"),
1178                                                       Parameters.getParameter<double>("xmax"),
1179                                                       100,  //that parameter should not be there !?
1180                                                       Parameters.getParameter<double>("ymin"),
1181                                                       Parameters.getParameter<double>("ymax"),
1182                                                       "");
1183     subdetMEs.SubDetTotDigiProf->setAxisTitle("Lumisection", 1);
1184 
1185     if (subdetMEs.SubDetTotDigiProf->kind() == MonitorElement::Kind::TPROFILE)
1186       subdetMEs.SubDetTotDigiProf->setCanExtend(TH1::kAllAxes);
1187   }
1188 
1189   // Number of Digi vs Bx - Profile
1190   if (subdetswitchapvcycleprofon) {
1191     edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TProfDigiApvCycle");
1192     HistoName = "Digi_vs_ApvCycle__" + label;
1193     subdetMEs.SubDetDigiApvProf = ibooker.bookProfile(HistoName,
1194                                                       HistoName,
1195                                                       Parameters.getParameter<int32_t>("Nbins"),
1196                                                       Parameters.getParameter<double>("xmin"),
1197                                                       Parameters.getParameter<double>("xmax"),
1198                                                       200,  //that parameter should not be there !?
1199                                                       Parameters.getParameter<double>("ymin"),
1200                                                       Parameters.getParameter<double>("ymax"),
1201                                                       "");
1202     subdetMEs.SubDetDigiApvProf->setAxisTitle("ApvCycle (Corrected Absolute Bx % 70)", 1);
1203   }
1204 
1205   // Number of Digi vs Bx - TH2
1206   if (subdetswitchapvcycleth2on) {
1207     edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TH2DigiApvCycle");
1208     //dqmStore_->setCurrentFolder("SiStrip/MechanicalView/"+label);
1209     HistoName = "Digi_vs_ApvCycle_2D__" + label;
1210     // Adjusting the scale for 2D histogram
1211     double h2ymax = 9999.0;
1212     double yfact = Parameters.getParameter<double>("yfactor");
1213     if (label.find("TIB") != std::string::npos)
1214       h2ymax = (6984. * 256.) * yfact;
1215     else if (label.find("TID") != std::string::npos)
1216       h2ymax = (2208. * 256.) * yfact;
1217     else if (label.find("TOB") != std::string::npos)
1218       h2ymax = (12906. * 256.) * yfact;
1219     else if (label.find("TEC") != std::string::npos)
1220       h2ymax = (7552. * 2. * 256.) * yfact;
1221     subdetMEs.SubDetDigiApvTH2 =
1222         ibooker.book2D(HistoName,
1223                        HistoName,
1224                        Parameters.getParameter<int32_t>("Nbins"),
1225                        Parameters.getParameter<double>("xmin"),
1226                        Parameters.getParameter<double>("xmax"),
1227                        Parameters.getParameter<int32_t>("Nbinsy"),  //it was 100 that parameter should not be there !?
1228                        Parameters.getParameter<double>("ymin"),
1229                        h2ymax);
1230     subdetMEs.SubDetDigiApvTH2->setAxisTitle("absolute Bx mod(70)", 1);
1231   }
1232 
1233   //Number of APV Shots
1234   if (subdetswitchnapvshotson) {
1235     edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TH1NApvShots");
1236     //dqmStore_->setCurrentFolder("SiStrip/MechanicalView/"+label);
1237     HistoName = "Number_of_Apv_Shots_" + label;
1238     subdetMEs.SubDetNApvShotsTH1 = ibooker.book1D(HistoName,
1239                                                   HistoName,
1240                                                   Parameters.getParameter<int32_t>("Nbins"),
1241                                                   Parameters.getParameter<double>("xmin"),
1242                                                   Parameters.getParameter<double>("xmax"));
1243     subdetMEs.SubDetNApvShotsTH1->setAxisTitle("# Apv Shots", 1);
1244   }
1245 
1246   //Strip multiplicity of APV Shots
1247   if (subdetswitchnstripsapvshotson) {
1248     edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TH1NStripsApvShots");
1249     //dqmStore_->setCurrentFolder("SiStrip/MechanicalView/"+label);
1250     HistoName = "Number_of_Strips_in_Apv_Shots_" + label;
1251     subdetMEs.SubDetNStripsApvShotsTH1 = ibooker.book1D(HistoName,
1252                                                         HistoName,
1253                                                         Parameters.getParameter<int32_t>("Nbins"),
1254                                                         Parameters.getParameter<double>("xmin"),
1255                                                         Parameters.getParameter<double>("xmax"));
1256     subdetMEs.SubDetNStripsApvShotsTH1->setAxisTitle("# strips in Apv Shots", 1);
1257   }
1258 
1259   //Charge median of APV Shots
1260   if (subdetswitchchargemedianapvshotson) {
1261     edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TH1ChargeMedianApvShots");
1262     //dqmStore_->setCurrentFolder("SiStrip/MechanicalView/"+label);
1263     HistoName = "Apv_Shots_Charge_Median_" + label;
1264     subdetMEs.SubDetChargeMedianApvShotsTH1 = ibooker.book1D(HistoName,
1265                                                              HistoName,
1266                                                              Parameters.getParameter<int32_t>("Nbins"),
1267                                                              Parameters.getParameter<double>("xmin"),
1268                                                              Parameters.getParameter<double>("xmax"));
1269     subdetMEs.SubDetChargeMedianApvShotsTH1->setAxisTitle("Apv Shots Charge Median (ADC)", 1);
1270   }
1271 
1272   if (subdetswitchchargemedianapvshotson) {
1273     edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TH1ApvNumApvShots");
1274     //dqmStore_->setCurrentFolder("SiStrip/MechanicalView/"+label);
1275     HistoName = "Apv_Shots_Apv_Number_" + label;
1276     subdetMEs.SubDetNApvShotsNApvTH1 = ibooker.book1D(HistoName,
1277                                                       HistoName,
1278                                                       Parameters.getParameter<int32_t>("Nbins"),
1279                                                       Parameters.getParameter<double>("xmin"),
1280                                                       Parameters.getParameter<double>("xmax"));
1281     subdetMEs.SubDetNApvShotsNApvTH1->setAxisTitle("Apv Number", 1);
1282   }
1283 
1284   //APV Shots number Vs time
1285   if (subdetswitchapvshotsonprof) {
1286     edm::ParameterSet Parameters = conf_.getParameter<edm::ParameterSet>("TProfNShotsVsTime");
1287     HistoName = "NApv_Shots_vs_Time_" + label;
1288     subdetMEs.SubDetNApvShotsProf = ibooker.bookProfile(HistoName,
1289                                                         HistoName,
1290                                                         Parameters.getParameter<int32_t>("Nbins"),
1291                                                         Parameters.getParameter<double>("xmin"),
1292                                                         Parameters.getParameter<double>("xmax"),
1293                                                         200,  //that parameter should not be there !?
1294                                                         Parameters.getParameter<double>("ymin"),
1295                                                         Parameters.getParameter<double>("ymax"),
1296                                                         "");
1297     subdetMEs.SubDetNApvShotsProf->setAxisTitle("Time (s)", 1);
1298     subdetMEs.SubDetNApvShotsProf->setAxisTitle("# Apv Shots", 2);
1299     if (subdetMEs.SubDetNApvShotsProf->kind() == MonitorElement::Kind::TPROFILE)
1300       subdetMEs.SubDetNApvShotsProf->setCanExtend(TH1::kAllAxes);
1301   }
1302 
1303   SubDetMEsMap[label] = subdetMEs;
1304 }
1305 //
1306 // -- Get DetSet vector for a given Detector
1307 //
1308 int SiStripMonitorDigi::getDigiSourceIndex(uint32_t id) {
1309   int location = -1;
1310   for (unsigned int ival = 0; ival < digi_detset_handles.size(); ++ival) {
1311     edm::DetSetVector<SiStripDigi>::const_iterator isearch = digi_detset_handles[ival]->find(id);
1312     if (isearch != digi_detset_handles[ival]->end()) {
1313       location = ival;
1314       break;
1315     }
1316   }
1317   return location;
1318 }
1319 
1320 void SiStripMonitorDigi::AddApvShotsToSubDet(const std::vector<APVShot>& moduleShots,
1321                                              std::vector<APVShot>& subdetShots) {
1322   for (uint i = 0; i < moduleShots.size(); i++) {
1323     subdetShots.push_back(moduleShots[i]);
1324   }
1325 }
1326 
1327 void SiStripMonitorDigi::FillApvShotsMap(TkHistoMap* the_map, const std::vector<APVShot>& shots, uint32_t id, int mode) {
1328   for (uint i = 0; i < shots.size(); i++) {
1329     if (mode == 1)
1330       the_map->fill(id, shots[i].nStrips());  //mode == 1 fill with strip multiplicity
1331     if (mode == 2)
1332       the_map->fill(id, shots[i].median());  // mode == 2 fill with charge median
1333   }
1334 }
1335 
1336 //define this as a plug-in
1337 DEFINE_FWK_MODULE(SiStripMonitorDigi);