diff --git a/CalibTracker/SiStripChannelGain/interface/APVGainHelpers.h b/CalibTracker/SiStripChannelGain/interface/APVGainHelpers.h index ed5fe4e5c0d5a..a2a4ab9e5aa52 100644 --- a/CalibTracker/SiStripChannelGain/interface/APVGainHelpers.h +++ b/CalibTracker/SiStripChannelGain/interface/APVGainHelpers.h @@ -1,67 +1,116 @@ #ifndef CALIBTRACKER_SISTRIPCHANNELGAIN_APVGAINHELPERS_H #define CALIBTRACKER_SISTRIPCHANNELGAIN_APVGAINHELPERS_H +#include "CalibTracker/SiStripChannelGain/interface/APVGainStruct.h" #include "DataFormats/TrackerCommon/interface/TrackerTopology.h" -#include "DQMServices/Core/interface/MonitorElement.h" #include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "DQMServices/Core/interface/ConcurrentMonitorElement.h" +#include "DQMServices/Core/interface/MonitorElement.h" #include #include #include #include - +#include namespace APVGain { - int subdetectorId(uint32_t); - int subdetectorId(const std::string&); - int subdetectorSide(uint32_t,const TrackerTopology*); - int subdetectorSide(const std::string&); - int subdetectorPlane(uint32_t,const TrackerTopology*); - int subdetectorPlane(const std::string&); - - std::vector> monHnames(std::vector,bool,const char* tag); - - struct APVmon{ - - public: - - APVmon(int v1, int v2, int v3, MonitorElement* v4) : - m_subdetectorId(v1),m_subdetectorSide(v2),m_subdetectorPlane(v3),m_monitor(v4){} - - int getSubdetectorId(){ - return m_subdetectorId; - } - int getSubdetectorSide(){ - return m_subdetectorSide; - } + int subdetectorId(uint32_t); + int subdetectorId(const std::string&); + int subdetectorSide(uint32_t,const TrackerTopology*); + int subdetectorSide(const std::string&); + int subdetectorPlane(uint32_t,const TrackerTopology*); + int subdetectorPlane(const std::string&); - int getSubdetectorPlane(){ - return m_subdetectorPlane; - } + std::vector> monHnames(std::vector,bool,const char* tag); - MonitorElement* getMonitor(){ - return m_monitor; - } - - void printAll(){ - LogDebug("APVGainHelpers")<< "subDetectorID:" << m_subdetectorId << std::endl; - LogDebug("APVGainHelpers")<< "subDetectorSide:" << m_subdetectorSide << std::endl; - LogDebug("APVGainHelpers")<< "subDetectorPlane:" << m_subdetectorPlane << std::endl; - LogDebug("APVGainHelpers")<< "histoName:" << m_monitor->getName() << std::endl; - return; - } - - private: - - int m_subdetectorId; - int m_subdetectorSide; - int m_subdetectorPlane; - MonitorElement* m_monitor; + struct APVmon{ + + public: - }; + APVmon(int v1, int v2, int v3,MonitorElement* v4) : + m_subdetectorId(v1),m_subdetectorSide(v2),m_subdetectorPlane(v3),m_monitor(v4){} + + int getSubdetectorId(){ + return m_subdetectorId; + } + + int getSubdetectorSide(){ + return m_subdetectorSide; + } + + int getSubdetectorPlane(){ + return m_subdetectorPlane; + } + + MonitorElement* getMonitor(){ + return m_monitor; + } + + void printAll(){ + LogDebug("APVGainHelpers")<< "subDetectorID:" << m_subdetectorId << std::endl; + LogDebug("APVGainHelpers")<< "subDetectorSide:" << m_subdetectorSide << std::endl; + LogDebug("APVGainHelpers")<< "subDetectorPlane:" << m_subdetectorPlane << std::endl; + LogDebug("APVGainHelpers")<< "histoName:" << m_monitor->getName() << std::endl; + return; + } + + private: + + int m_subdetectorId; + int m_subdetectorSide; + int m_subdetectorPlane; + MonitorElement* m_monitor; + + }; + + struct APVGainHistograms { + public: + APVGainHistograms(): + Charge_Vs_Index(7), + Charge_1(), + Charge_2(), + Charge_3(), + Charge_4(), + Charge_Vs_PathlengthTIB(7), + Charge_Vs_PathlengthTOB(7), + Charge_Vs_PathlengthTIDP(7), + Charge_Vs_PathlengthTIDM(7), + Charge_Vs_PathlengthTECP1(7), + Charge_Vs_PathlengthTECP2(7), + Charge_Vs_PathlengthTECM1(7), + Charge_Vs_PathlengthTECM2(7), + NStripAPVs(0), + NPixelDets(0), + APVsCollOrdered(), + APVsColl() + { + } + + std::vector Charge_Vs_Index; /*!< Charge per cm for each detector id */ + std::array< std::vector,7 > Charge_1; /*!< Charge per cm per layer / wheel */ + std::array< std::vector,7 > Charge_2; /*!< Charge per cm per layer / wheel without G2 */ + std::array< std::vector,7 > Charge_3; /*!< Charge per cm per layer / wheel without G1 */ + std::array< std::vector,7 > Charge_4; /*!< Charge per cm per layer / wheel without G1 and G1*/ + + std::vector Charge_Vs_PathlengthTIB; /*!< Charge vs pathlength in TIB */ + std::vector Charge_Vs_PathlengthTOB; /*!< Charge vs pathlength in TOB */ + std::vector Charge_Vs_PathlengthTIDP; /*!< Charge vs pathlength in TIDP */ + std::vector Charge_Vs_PathlengthTIDM; /*!< Charge vs pathlength in TIDM */ + std::vector Charge_Vs_PathlengthTECP1; /*!< Charge vs pathlength in TECP thin */ + std::vector Charge_Vs_PathlengthTECP2; /*!< Charge vs pathlength in TECP thick */ + std::vector Charge_Vs_PathlengthTECM1; /*!< Charge vs pathlength in TECP thin */ + std::vector Charge_Vs_PathlengthTECM2; /*!< Charge vs pathlength in TECP thick */ + mutable std::atomic NStripAPVs; + mutable std::atomic NPixelDets; + std::vector > APVsCollOrdered; + std::unordered_map > APVsColl; + + }; + + std::vector FetchMonitor(std::vector, uint32_t, const TrackerTopology* topo=nullptr); + std::vector FetchIndices(std::map, uint32_t, const TrackerTopology* topo=nullptr); - std::vector FetchMonitor(std::vector, uint32_t, const TrackerTopology* topo=nullptr); }; #endif diff --git a/CalibTracker/SiStripChannelGain/interface/APVGainStruct.h b/CalibTracker/SiStripChannelGain/interface/APVGainStruct.h index 6e19a3c7da5dd..7e9f25080e0ee 100644 --- a/CalibTracker/SiStripChannelGain/interface/APVGainStruct.h +++ b/CalibTracker/SiStripChannelGain/interface/APVGainStruct.h @@ -2,6 +2,7 @@ #define CALIBTRACKER_SISTRIPCHANNELGAIN_STAPVGAIN_H class TH1F; +#include struct stAPVGain{ unsigned int Index; @@ -32,6 +33,27 @@ struct stAPVGain{ bool isMasked; }; +struct APVloc{ + +public: + +APVloc(int v1, int v2, int v3,const std::string& s) : + m_subdetectorId(v1),m_subdetectorSide(v2),m_subdetectorPlane(v3),m_string(s){} + + int m_subdetectorId; + int m_subdetectorSide; + int m_subdetectorPlane; + std::string m_string; + + bool operator==(const APVloc& a) const + { + return (m_subdetectorId == a.m_subdetectorId && + m_subdetectorSide == a.m_subdetectorSide && + m_subdetectorPlane == a.m_subdetectorPlane); + } + +}; + enum statistic_type {None=-1, StdBunch, StdBunch0T, FaABunch, FaABunch0T, IsoBunch, IsoBunch0T, Harvest}; #endif diff --git a/CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLHarvester.h b/CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLHarvester.h index 03c5dadb76c21..6aacb902e7d13 100644 --- a/CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLHarvester.h +++ b/CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLHarvester.h @@ -57,7 +57,6 @@ class SiStripGainsPCLHarvester : public DQMEDHarvester { void gainQualityMonitor(DQMStore::IBooker& ibooker_, const MonitorElement* Charge_Vs_Index) const; - int statCollectionFromMode(const char* tag) const; void algoComputeMPVandGain(const MonitorElement* Charge_Vs_Index); @@ -88,8 +87,6 @@ class SiStripGainsPCLHarvester : public DQMEDHarvester { std::vector dqm_tag_; - - int CalibrationLevel; edm::ESHandle tkGeom_; diff --git a/CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLWorker.h b/CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLWorker.h index 3170991c34c60..df1f5e0204cae 100644 --- a/CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLWorker.h +++ b/CalibTracker/SiStripChannelGain/interface/SiStripGainsPCLWorker.h @@ -25,7 +25,7 @@ #include "CalibTracker/Records/interface/SiStripGainRcd.h" #include "CalibTracker/Records/interface/SiStripQualityRcd.h" #include "CondFormats/SiStripObjects/interface/SiStripApvGain.h" -#include "DQMServices/Core/interface/DQMEDAnalyzer.h" +#include "DQMServices/Core/interface/DQMGlobalEDAnalyzer.h" #include "DQMServices/Core/interface/DQMStore.h" #include "DataFormats/DetId/interface/DetId.h" #include "DataFormats/FEDRawData/interface/FEDNumbering.h" @@ -48,6 +48,7 @@ #include "FWCore/ServiceRegistry/interface/Service.h" #include "FWCore/Utilities/interface/EDGetToken.h" #include "FWCore/Utilities/interface/Exception.h" +#include "FWCore/Framework/interface/ESWatcher.h" #include "Geometry/CommonDetUnit/interface/GeomDetType.h" #include "Geometry/CommonDetUnit/interface/GeomDet.h" #include "Geometry/CommonDetUnit/interface/TrackingGeometry.h" @@ -71,49 +72,25 @@ // class declaration // -class SiStripGainsPCLWorker : public DQMEDAnalyzer { +class SiStripGainsPCLWorker : public DQMGlobalEDAnalyzer { public: explicit SiStripGainsPCLWorker(const edm::ParameterSet&); + void bookHistograms(DQMStore::ConcurrentBooker &, edm::Run const&, edm::EventSetup const&, APVGain::APVGainHistograms &) const override; + void dqmAnalyze(edm::Event const&, edm::EventSetup const&, APVGain::APVGainHistograms const&) const override; + static void fillDescriptions(edm::ConfigurationDescriptions& descriptions); private: - void beginJob() override; - void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override; - void dqmBeginRun(edm::Run const&, edm::EventSetup const&) override; - void analyze(const edm::Event&, const edm::EventSetup&) override; - void endJob() override; - - void processEvent(const TrackerTopology* topo); //what really does the job - virtual void checkBookAPVColls(const edm::EventSetup& setup); + void beginJob() override ; + void dqmBeginRun(edm::Run const&, edm::EventSetup const&, APVGain::APVGainHistograms &) const override; + void endJob() override ; + void checkBookAPVColls(const TrackerGeometry *bareTkGeomPtr,APVGain::APVGainHistograms & histograms) const; + std::vector dqm_tag_; int statCollectionFromMode(const char* tag) const; - - std::vector Charge_Vs_Index; /*!< Charge per cm for each detector id */ - std::array< std::vector,7 > Charge_1; /*!< Charge per cm per layer / wheel */ - std::array< std::vector,7 > Charge_2; /*!< Charge per cm per layer / wheel without G2 */ - std::array< std::vector,7 > Charge_3; /*!< Charge per cm per layer / wheel without G1 */ - std::array< std::vector,7 > Charge_4; /*!< Charge per cm per layer / wheel without G1 and G1*/ - - std::vector Charge_Vs_PathlengthTIB; /*!< Charge vs pathlength in TIB */ - std::vector Charge_Vs_PathlengthTOB; /*!< Charge vs pathlength in TOB */ - std::vector Charge_Vs_PathlengthTIDP; /*!< Charge vs pathlength in TIDP */ - std::vector Charge_Vs_PathlengthTIDM; /*!< Charge vs pathlength in TIDM */ - std::vector Charge_Vs_PathlengthTECP1; /*!< Charge vs pathlength in TECP thin */ - std::vector Charge_Vs_PathlengthTECP2; /*!< Charge vs pathlength in TECP thick */ - std::vector Charge_Vs_PathlengthTECM1; /*!< Charge vs pathlength in TECP thin */ - std::vector Charge_Vs_PathlengthTECM2; /*!< Charge vs pathlength in TECP thick */ - - unsigned int NEvent; - unsigned int NTrack; - unsigned int NClusterStrip; - unsigned int NClusterPixel; - int NStripAPVs; - int NPixelDets; - unsigned int SRun; - unsigned int ERun; double MinTrackMomentum; double MaxTrackMomentum; @@ -133,43 +110,33 @@ class SiStripGainsPCLWorker : public DQMEDAnalyzer { std::string m_DQMdir; /*!< DQM folder hosting the charge statistics and the monitor plots */ std::string m_calibrationMode; /*!< Type of statistics for the calibration */ std::vector VChargeHisto; /*!< Charge monitor plots to be output */ - - edm::ESHandle tkGeom_; - const TrackerGeometry *bareTkGeomPtr_; // ugly hack to fill APV colls only once, but checks - + //Data members for processing - //Event data - unsigned int eventnumber =0; - unsigned int runnumber =0; - const std::vector* TrigTech =nullptr; edm::EDGetTokenT > TrigTech_token_; - - // Track data - const std::vector* trackchi2ndof =nullptr; edm::EDGetTokenT > trackchi2ndof_token_; - const std::vector* trackp =nullptr; edm::EDGetTokenT > trackp_token_; - const std::vector* trackpt =nullptr; edm::EDGetTokenT > trackpt_token_; - const std::vector* tracketa =nullptr; edm::EDGetTokenT > tracketa_token_; - const std::vector* trackphi =nullptr; edm::EDGetTokenT > trackphi_token_; - const std::vector* trackhitsvalid =nullptr; edm::EDGetTokenT > trackhitsvalid_token_; - const std::vector* trackalgo =nullptr; edm::EDGetTokenT > trackalgo_token_; - - // CalibTree data - const std::vector* trackindex =nullptr; edm::EDGetTokenT > trackindex_token_; - const std::vector* rawid =nullptr; edm::EDGetTokenT > rawid_token_; - const std::vector* localdirx =nullptr; edm::EDGetTokenT > localdirx_token_; - const std::vector* localdiry =nullptr; edm::EDGetTokenT > localdiry_token_; - const std::vector* localdirz =nullptr; edm::EDGetTokenT > localdirz_token_; - const std::vector* firststrip =nullptr; edm::EDGetTokenT > firststrip_token_; - const std::vector* nstrips =nullptr; edm::EDGetTokenT > nstrips_token_; - const std::vector* saturation =nullptr; edm::EDGetTokenT > saturation_token_; - const std::vector* overlapping =nullptr; edm::EDGetTokenT > overlapping_token_; - const std::vector* farfromedge =nullptr; edm::EDGetTokenT > farfromedge_token_; - const std::vector* charge =nullptr; edm::EDGetTokenT > charge_token_; - const std::vector* path =nullptr; edm::EDGetTokenT > path_token_; - const std::vector* chargeoverpath =nullptr; edm::EDGetTokenT > chargeoverpath_token_; - const std::vector* amplitude =nullptr; edm::EDGetTokenT > amplitude_token_; - const std::vector* gainused =nullptr; edm::EDGetTokenT > gainused_token_; - const std::vector* gainusedTick =nullptr; edm::EDGetTokenT > gainusedTick_token_; + edm::EDGetTokenT > TrigTech_token_; + edm::EDGetTokenT > trackchi2ndof_token_; + edm::EDGetTokenT > trackp_token_; + edm::EDGetTokenT > trackpt_token_; + edm::EDGetTokenT > tracketa_token_; + edm::EDGetTokenT > trackphi_token_; + edm::EDGetTokenT > trackhitsvalid_token_; + edm::EDGetTokenT > trackalgo_token_; + edm::EDGetTokenT > trackindex_token_; + edm::EDGetTokenT > rawid_token_; + edm::EDGetTokenT > localdirx_token_; + edm::EDGetTokenT > localdiry_token_; + edm::EDGetTokenT > localdirz_token_; + edm::EDGetTokenT > firststrip_token_; + edm::EDGetTokenT > nstrips_token_; + edm::EDGetTokenT > saturation_token_; + edm::EDGetTokenT > overlapping_token_; + edm::EDGetTokenT > farfromedge_token_; + edm::EDGetTokenT > charge_token_; + edm::EDGetTokenT > path_token_; + edm::EDGetTokenT > chargeoverpath_token_; + edm::EDGetTokenT > amplitude_token_; + edm::EDGetTokenT > gainused_token_; + edm::EDGetTokenT > gainusedTick_token_; std::string EventPrefix_; //(""); std::string EventSuffix_; //(""); @@ -178,9 +145,9 @@ class SiStripGainsPCLWorker : public DQMEDAnalyzer { std::string CalibPrefix_; //("GainCalibration"); std::string CalibSuffix_; //(""); - std::vector > APVsCollOrdered; - std::unordered_map > APVsColl; - + // maps histograms index to topology + std::map theTopologyMap; + }; inline int @@ -192,15 +159,8 @@ SiStripGainsPCLWorker::statCollectionFromMode(const char* tag) const it++; } - if (std::string(tag)=="") return 0; // return StdBunch calibration mode for backward compatibility + if (std::string(tag).empty()) return 0; // return StdBunch calibration mode for backward compatibility return None; } -template -inline edm::Handle connect(const T* &ptr, edm::EDGetTokenT token, const edm::Event &evt) { - edm::Handle handle; - evt.getByToken(token, handle); - ptr = handle.product(); - return handle; //return handle to keep alive pointer (safety first) -} diff --git a/CalibTracker/SiStripChannelGain/plugins/SiStripGainFromCalibTree.cc b/CalibTracker/SiStripChannelGain/plugins/SiStripGainFromCalibTree.cc index 25291203d6f81..c29c6e66431b9 100644 --- a/CalibTracker/SiStripChannelGain/plugins/SiStripGainFromCalibTree.cc +++ b/CalibTracker/SiStripChannelGain/plugins/SiStripGainFromCalibTree.cc @@ -319,7 +319,7 @@ SiStripGainFromCalibTree::statCollectionFromMode(const char* tag) const it++; } - if (std::string(tag)=="") return 0; // return StdBunch calibration mode for backward compatibility + if (std::string(tag).empty()) return 0; // return StdBunch calibration mode for backward compatibility return None; } diff --git a/CalibTracker/SiStripChannelGain/python/SiStripGainsPCLWorker_cfi.py b/CalibTracker/SiStripChannelGain/python/SiStripGainsPCLWorker_cfi.py index 7cd781a427dc7..915d7a1b46446 100644 --- a/CalibTracker/SiStripChannelGain/python/SiStripGainsPCLWorker_cfi.py +++ b/CalibTracker/SiStripChannelGain/python/SiStripGainsPCLWorker_cfi.py @@ -1,7 +1,6 @@ import FWCore.ParameterSet.Config as cms -from DQMServices.Core.DQMEDAnalyzer import DQMEDAnalyzer -SiStripGainsPCLWorker = DQMEDAnalyzer( +SiStripGainsPCLWorker = cms.EDAnalyzer( "SiStripGainsPCLWorker", minTrackMomentum = cms.untracked.double(2), maxNrStrips = cms.untracked.uint32(8), diff --git a/CalibTracker/SiStripChannelGain/src/APVGainHelpers.cc b/CalibTracker/SiStripChannelGain/src/APVGainHelpers.cc index 961d7f25e653a..8c125ac77ce8a 100644 --- a/CalibTracker/SiStripChannelGain/src/APVGainHelpers.cc +++ b/CalibTracker/SiStripChannelGain/src/APVGainHelpers.cc @@ -1,10 +1,8 @@ #include "CalibTracker/SiStripChannelGain/interface/APVGainHelpers.h" - #include "DataFormats/DetId/interface/DetId.h" #include "DataFormats/SiStripDetId/interface/StripSubdetector.h" - /** Brief Extract from the DetId the subdetector type. * Return an integer which is associated to the subdetector type. The integer * coding for phase0/phase1 geometry follows: @@ -107,14 +105,14 @@ int APVGain::subdetectorPlane(const std::string& tag) { * */ std::vector APVGain::FetchMonitor(std::vector histos, uint32_t det_id, const TrackerTopology* topo) { - + std::vector found = std::vector(); int sId = APVGain::subdetectorId(det_id); int sPlane = APVGain::subdetectorPlane(det_id, topo); int sSide = APVGain::subdetectorSide(det_id, topo); - std::vector::iterator it= histos.begin(); - - LogDebug("APVGainHelpers")<<"sId: "<getName(); @@ -122,10 +120,10 @@ std::vector APVGain::FetchMonitor(std::vector int subdetectorSide = (*it).getSubdetectorSide(); int subdetectorPlane = (*it).getSubdetectorPlane(); - bool match = (subdetectorId==0 || subdetectorId==sId) && (subdetectorPlane==0 || subdetectorPlane==sPlane) && (subdetectorSide==0 || subdetectorSide==sSide); + bool match = (subdetectorId==0 || subdetectorId==sId) && (subdetectorPlane==0 || subdetectorPlane==sPlane) && (subdetectorSide==0 || subdetectorSide==sSide); if (match) { - found.push_back((*it).getMonitor()); + found.emplace_back((*it).getMonitor()); LogDebug("APVGainHelpers")< APVGain::FetchMonitor(std::vector return found; } +/** Brief Fetch the Monitor Element index corresponding to a DetId. + * */ +std::vector APVGain::FetchIndices(std::map theMap, uint32_t det_id, const TrackerTopology* topo){ + + std::vector found_indices = std::vector(); + + int sId = APVGain::subdetectorId(det_id); + int sPlane = APVGain::subdetectorPlane(det_id, topo); + int sSide = APVGain::subdetectorSide(det_id, topo); + + for(auto &element : theMap){ + + int subdetectorId = element.second.m_subdetectorId; + int subdetectorSide = element.second.m_subdetectorSide; + int subdetectorPlane = element.second.m_subdetectorPlane; + bool match = (subdetectorId==0 || subdetectorId==sId) && (subdetectorPlane==0 || subdetectorPlane==sPlane) && (subdetectorSide==0 || subdetectorSide==sSide); + + if (match ){ + found_indices.push_back(element.first); + } + } + return found_indices; +} std::vector> APVGain::monHnames(std::vector VH, bool allPlanes, const char* tag) { diff --git a/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc b/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc index 828dfd2c54947..ebb0938b27e85 100644 --- a/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc +++ b/CalibTracker/SiStripChannelGain/src/SiStripGainsPCLWorker.cc @@ -6,18 +6,8 @@ #include //********************************************************************************// -SiStripGainsPCLWorker::SiStripGainsPCLWorker(const edm::ParameterSet& iConfig) : - NEvent(0), - NTrack(0), - NClusterStrip(0), - NClusterPixel(0), - NStripAPVs(0), - NPixelDets(0), - SRun(1<<31), - ERun(0), - bareTkGeomPtr_(nullptr) -{ - +SiStripGainsPCLWorker::SiStripGainsPCLWorker(const edm::ParameterSet& iConfig) +{ MinTrackMomentum = iConfig.getUntrackedParameter ("minTrackMomentum" , 3.0); MaxTrackMomentum = iConfig.getUntrackedParameter ("maxTrackMomentum" , 99999.0); MinTrackEta = iConfig.getUntrackedParameter ("minTrackEta" , -5.0); @@ -36,6 +26,19 @@ SiStripGainsPCLWorker::SiStripGainsPCLWorker(const edm::ParameterSet& iConfig) : m_calibrationMode = iConfig.getUntrackedParameter ("calibrationMode" , "StdBunch"); VChargeHisto = iConfig.getUntrackedParameter > ("ChargeHisto"); + // fill in the mapping between the histogram indices and the (id,side,plane) tuple + std::vector> hnames = APVGain::monHnames(VChargeHisto,doChargeMonitorPerPlane,""); + for (unsigned int i=0;i("gain"); @@ -104,12 +97,16 @@ SiStripGainsPCLWorker::SiStripGainsPCLWorker(const edm::ParameterSet& iConfig) : //********************************************************************************// void -SiStripGainsPCLWorker::dqmBeginRun(edm::Run const& run, const edm::EventSetup& iSetup){ +SiStripGainsPCLWorker::dqmBeginRun(edm::Run const& run, edm::EventSetup const& iSetup, APVGain::APVGainHistograms & histograms) const { using namespace edm; - - this->checkBookAPVColls(iSetup); // check whether APV colls are booked and do so if not yet done + // fills the APV collections at each begin run + edm::ESHandle tkGeom_; + iSetup.get().get( tkGeom_ ); + const TrackerGeometry *bareTkGeomPtr = &(*tkGeom_); + checkBookAPVColls(bareTkGeomPtr,histograms); + edm::ESHandle gainHandle; iSetup.get().get(gainHandle); if(!gainHandle.isValid()){edm::LogError("SiStripGainPCLWorker")<< "gainHandle is not valid\n"; exit(0);} @@ -117,9 +114,9 @@ SiStripGainsPCLWorker::dqmBeginRun(edm::Run const& run, const edm::EventSetup& i edm::ESHandle SiStripQuality_; iSetup.get().get(SiStripQuality_); - for(unsigned int a=0;a APV = APVsCollOrdered[a]; + std::shared_ptr APV = histograms.APVsCollOrdered[a]; if(APV->SubDet==PixelSubdetector::PixelBarrel || APV->SubDet==PixelSubdetector::PixelEndcap) continue; @@ -144,75 +141,111 @@ SiStripGainsPCLWorker::dqmBeginRun(edm::Run const& run, const edm::EventSetup& i //********************************************************************************// // ------------ method called for each event ------------ void -SiStripGainsPCLWorker::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) +SiStripGainsPCLWorker::dqmAnalyze(edm::Event const& iEvent, edm::EventSetup const& iSetup, APVGain::APVGainHistograms const& histograms) const { using namespace edm; - // this->checkBookAPVColls(iSetup); // check whether APV colls are booked and do so if not yet done - - eventnumber = iEvent.id().event(); - runnumber = iEvent.id().run(); - - auto handle01 = connect(TrigTech , TrigTech_token_ , iEvent); - auto handle02 = connect(trackchi2ndof , trackchi2ndof_token_ , iEvent); - auto handle03 = connect(trackp , trackp_token_ , iEvent); - auto handle04 = connect(trackpt , trackpt_token_ , iEvent); - auto handle05 = connect(tracketa , tracketa_token_ , iEvent); - auto handle06 = connect(trackphi , trackphi_token_ , iEvent); - auto handle07 = connect(trackhitsvalid, trackhitsvalid_token_, iEvent); - auto handle08 = connect(trackindex , trackindex_token_ , iEvent); - auto handle09 = connect(rawid , rawid_token_ , iEvent); - auto handle11 = connect(localdirx , localdirx_token_ , iEvent); - auto handle12 = connect(localdiry , localdiry_token_ , iEvent); - auto handle13 = connect(localdirz , localdirz_token_ , iEvent); - auto handle14 = connect(firststrip , firststrip_token_ , iEvent); - auto handle15 = connect(nstrips , nstrips_token_ , iEvent); - auto handle16 = connect(saturation , saturation_token_ , iEvent); - auto handle17 = connect(overlapping , overlapping_token_ , iEvent); - auto handle18 = connect(farfromedge , farfromedge_token_ , iEvent); - auto handle19 = connect(charge , charge_token_ , iEvent); - auto handle21 = connect(path , path_token_ , iEvent); - auto handle22 = connect(chargeoverpath, chargeoverpath_token_, iEvent); - auto handle23 = connect(amplitude , amplitude_token_ , iEvent); - auto handle24 = connect(gainused , gainused_token_ , iEvent); - auto handle25 = connect(gainusedTick , gainusedTick_token_ , iEvent); - auto handle26 = connect(trackalgo , trackalgo_token_ , iEvent); - + unsigned int eventnumber = iEvent.id().event(); + unsigned int runnumber = iEvent.id().run(); + + edm::LogInfo("SiStripGainsPCLWorker") << "Processing run " << runnumber + << " and event " << eventnumber + << std::endl; + edm::ESHandle TopoHandle; iSetup.get().get( TopoHandle ); const TrackerTopology* topo = TopoHandle.product(); - processEvent(topo); + // ***************************** + // * Event data handles + // ***************************** -} + //Event data + + // Track data + Handle> handle01; + iEvent.getByToken(trackchi2ndof_token_,handle01); + auto trackchi2ndof = handle01.product(); + + Handle> handle02; + iEvent.getByToken(trackp_token_,handle02); + auto trackp = handle02.product(); + + Handle> handle03; + iEvent.getByToken(tracketa_token_,handle03); + auto tracketa = handle03.product(); + + Handle> handle04; + iEvent.getByToken(trackhitsvalid_token_,handle04); + auto trackhitsvalid = handle04.product(); -//********************************************************************************// -void SiStripGainsPCLWorker::processEvent(const TrackerTopology* topo) { + Handle> handle05; + iEvent.getByToken(trackalgo_token_,handle05); + auto trackalgo = handle05.product(); - edm::LogInfo("SiStripGainsPCLWorker") << "Processing run " << runnumber - << " and event " << eventnumber - << std::endl; + // CalibTree data + Handle> handle06; + iEvent.getByToken(trackindex_token_,handle06); + auto trackindex = handle06.product(); - if(runnumberERun)ERun=runnumber; - - NEvent++; - NTrack+=(*trackp).size(); - - LogDebug("SiStripGainsPCLWorker") - <<"for mode"<< m_calibrationMode - <<" Nevent:"<> handle07; + iEvent.getByToken(rawid_token_,handle07); + auto rawid = handle07.product(); + + Handle> handle08; + iEvent.getByToken(firststrip_token_,handle08); + auto firststrip = handle08.product(); + + Handle> handle09; + iEvent.getByToken(nstrips_token_,handle09); + auto nstrips = handle09.product(); + + Handle> handle10; + iEvent.getByToken(saturation_token_,handle10); + auto saturation = handle10.product(); + + Handle> handle11; + iEvent.getByToken(overlapping_token_,handle11); + auto overlapping = handle11.product(); + + Handle> handle12; + iEvent.getByToken(farfromedge_token_,handle12); + auto farfromedge = handle12.product(); + + Handle> handle13; + iEvent.getByToken(charge_token_,handle13); + auto charge = handle13.product(); + + Handle> handle14; + iEvent.getByToken(path_token_,handle14); + auto path = handle14.product(); + + Handle> handle15; + iEvent.getByToken(chargeoverpath_token_,handle15); + auto chargeoverpath = handle15.product(); + + Handle> handle16; + iEvent.getByToken(amplitude_token_,handle16); + auto amplitude = handle16.product(); + + Handle> handle17; + iEvent.getByToken(gainused_token_,handle17); + auto gainused = handle17.product(); + + Handle> handle18; + iEvent.getByToken(gainusedTick_token_,handle18); + auto gainusedTick = handle18.product(); + + for (const auto &elem : theTopologyMap){ + LogDebug("SiStripGainsPCLWorker") << elem.first << " - " << elem.second.m_string << " " << elem.second.m_subdetectorId << " " << elem.second.m_subdetectorSide << " " << elem.second.m_subdetectorPlane << std::endl; + } + + LogDebug("SiStripGainsPCLWorker") <<"for mode"<< m_calibrationMode <size();i++){ FirstAmplitude+=(*nstrips)[i]; int TI = (*trackindex)[i]; @@ -225,19 +258,13 @@ void SiStripGainsPCLWorker::processEvent(const TrackerTopology* topo) { if((*trackchi2ndof )[TI] > MaxTrackChiOverNdf )continue; if((*trackalgo )[TI] > MaxTrackingIteration )continue; - std::shared_ptr APV = APVsColl[((*rawid)[i]<<4) | ((*firststrip)[i]/128)]; //works for both strip and pixel thanks to firstStrip encoding for pixel in the calibTree + std::shared_ptr APV = histograms.APVsColl.at(((*rawid)[i]<<4) | ((*firststrip)[i]/128)); //works for both strip and pixel thanks to firstStrip encoding for pixel in the calibTree if(APV->SubDet>2 && (*farfromedge)[i] == false )continue; if(APV->SubDet>2 && (*overlapping)[i] == true )continue; if(APV->SubDet>2 && (*saturation )[i] && !AllowSaturation)continue; if(APV->SubDet>2 && (*nstrips )[i] > MaxNrStrips )continue; - - if(APV->SubDet>2){ - NClusterStrip++; - } else { - NClusterPixel++; - } - + int Charge = 0; if(APV->SubDet>2 && (useCalibration || !FirstSetOfConstants)){ bool Saturation = false; @@ -272,16 +299,17 @@ void SiStripGainsPCLWorker::processEvent(const TrackerTopology* topo) { if(APV->SubDet<=2) continue; // real histogram for calibration - (Charge_Vs_Index[elepos])->Fill(APV->Index,ClusterChargeOverPath); - + histograms.Charge_Vs_Index[elepos].fill(APV->Index,ClusterChargeOverPath); LogDebug("SiStripGainsPCLWorker") <<" for mode "<< m_calibrationMode << "\n" <<" i "<< i - <<" NClusterStrip "<< NClusterStrip <<" useCalibration "<< useCalibration <<" FirstSetOfConstants "<< FirstSetOfConstants + <<" APV->PreviousGain " << APV->PreviousGain + <<" APV->CalibGain " << APV->CalibGain <<" APV->DetId "<< APV->DetId <<" APV->Index "<< APV->Index <<" Charge "<< Charge + <<" Path "<< (*path)[i] <<" ClusterChargeOverPath "<< ClusterChargeOverPath < cmon1 = APVGain::FetchMonitor(Charge_1[elepos], (*rawid)[i], topo); - for(unsigned int m=0; mFill(( (double) mCharge1 )/(*path)[i]); - - std::vector cmon2 = APVGain::FetchMonitor(Charge_2[elepos], (*rawid)[i], topo); - for(unsigned int m=0; mFill(( (double) mCharge2 )/(*path)[i]); - std::vector cmon3 = APVGain::FetchMonitor(Charge_3[elepos], (*rawid)[i], topo); - for(unsigned int m=0; mFill(( (double) mCharge3 )/(*path)[i]); + auto indices = APVGain::FetchIndices(theTopologyMap,(*rawid)[i], topo); - std::vector cmon4 = APVGain::FetchMonitor(Charge_4[elepos], (*rawid)[i], topo); - for(unsigned int m=0; mFill(( (double) mCharge4 )/(*path)[i]); + for(auto m : indices) histograms.Charge_1[elepos][m].fill(( (double) mCharge1 )/(*path)[i]); + for(auto m : indices) histograms.Charge_2[elepos][m].fill(( (double) mCharge2 )/(*path)[i]); + for(auto m : indices) histograms.Charge_3[elepos][m].fill(( (double) mCharge3 )/(*path)[i]); + for(auto m : indices) histograms.Charge_4[elepos][m].fill(( (double) mCharge4 )/(*path)[i]); if(APV->SubDet==StripSubdetector::TIB){ - (Charge_Vs_PathlengthTIB[elepos])->Fill((*path)[i],Charge); // TIB + histograms.Charge_Vs_PathlengthTIB[elepos].fill((*path)[i],Charge); // TIB }else if(APV->SubDet==StripSubdetector::TOB){ - (Charge_Vs_PathlengthTOB[elepos])->Fill((*path)[i],Charge); // TOB + histograms.Charge_Vs_PathlengthTOB[elepos].fill((*path)[i],Charge); // TOB }else if(APV->SubDet==StripSubdetector::TID){ - if(APV->Eta<0) { (Charge_Vs_PathlengthTIDM[elepos])->Fill((*path)[i],Charge); } // TID minus - else if(APV->Eta>0){ (Charge_Vs_PathlengthTIDP[elepos])->Fill((*path)[i],Charge); } // TID plus + if(APV->Eta<0) { histograms.Charge_Vs_PathlengthTIDM[elepos].fill((*path)[i],Charge); } // TID minus + else if(APV->Eta>0){ histograms.Charge_Vs_PathlengthTIDP[elepos].fill((*path)[i],Charge); } // TID plus }else if(APV->SubDet==StripSubdetector::TEC){ if(APV->Eta<0){ - if(APV->Thickness<0.04) { (Charge_Vs_PathlengthTECM1[elepos])->Fill((*path)[i],Charge); } // TEC minus, type 1 - else if(APV->Thickness>0.04){ (Charge_Vs_PathlengthTECM2[elepos])->Fill((*path)[i],Charge); } // TEC minus, type 2 + if(APV->Thickness<0.04) { histograms.Charge_Vs_PathlengthTECM1[elepos].fill((*path)[i],Charge); } // TEC minus, type 1 + else if(APV->Thickness>0.04){ histograms.Charge_Vs_PathlengthTECM2[elepos].fill((*path)[i],Charge); } // TEC minus, type 2 } else if(APV->Eta>0){ - if(APV->Thickness<0.04) { (Charge_Vs_PathlengthTECP1[elepos])->Fill((*path)[i],Charge); } // TEC plus, type 1 - else if(APV->Thickness>0.04){ (Charge_Vs_PathlengthTECP2[elepos])->Fill((*path)[i],Charge); } // TEC plus, type 2 + if(APV->Thickness<0.04) { histograms.Charge_Vs_PathlengthTECP1[elepos].fill((*path)[i],Charge); } // TEC plus, type 1 + else if(APV->Thickness>0.04){ histograms.Charge_Vs_PathlengthTECP2[elepos].fill((*path)[i],Charge); } // TEC plus, type 2 } } }// END OF ON-CLUSTER LOOP - LogDebug("SiStripGainsPCLWorker")<<" for mode"<< m_calibrationMode - <<" entries in histogram:"<< (Charge_Vs_Index[elepos])->getTH2S()->GetEntries() - <().get( tkGeom_ ); - const TrackerGeometry *newBareTkGeomPtr = &(*tkGeom_); - if (newBareTkGeomPtr == bareTkGeomPtr_) return; // already filled APVColls, nothing changed - - if (!bareTkGeomPtr_) { // pointer not yet set: called the first time => fill the APVColls - auto const & Det = newBareTkGeomPtr->dets(); +SiStripGainsPCLWorker::checkBookAPVColls(const TrackerGeometry *bareTkGeomPtr,APVGain::APVGainHistograms & histograms) const +{ + if (bareTkGeomPtr) { // pointer not yet set: called the first time => fill the APVColls + auto const & Det = bareTkGeomPtr->dets(); - edm::LogInfo("SiStripGainsPCLWorker") - <<" Resetting APV struct"<NEntries = 0; APV->isMasked = false; - APVsCollOrdered.push_back(APV); - APVsColl[(APV->DetId<<4) | APV->APVId] = APV; + histograms.APVsCollOrdered.push_back(APV); + histograms.APVsColl[(APV->DetId<<4) | APV->APVId] = APV; Index++; - NStripAPVs++; + histograms.NStripAPVs++; } // loop on APVs } // if is Strips } // loop on dets @@ -462,20 +479,18 @@ SiStripGainsPCLWorker::checkBookAPVColls(const edm::EventSetup& es){ APV->isMasked = false; //SiPixelQuality_->IsModuleBad(Detid.rawId()); APV->NEntries = 0; - APVsCollOrdered.push_back(APV); - APVsColl[(APV->DetId<<4) | APV->APVId] = APV; + histograms.APVsCollOrdered.push_back(APV); + histograms.APVsColl[(APV->DetId<<4) | APV->APVId] = APV; Index++; - NPixelDets++; + histograms.NPixelDets++; } // loop on ROC cols } // loop on ROC rows } // if Pixel } // loop on Dets } //if (!bareTkGeomPtr_) ... - bareTkGeomPtr_ = newBareTkGeomPtr; } - //********************************************************************************// void SiStripGainsPCLWorker::endJob() @@ -492,7 +507,7 @@ SiStripGainsPCLWorker::fillDescriptions(edm::ConfigurationDescriptions& descript //********************************************************************************// void -SiStripGainsPCLWorker::bookHistograms(DQMStore::IBooker & ibooker, edm::Run const & run, edm::EventSetup const & es){ +SiStripGainsPCLWorker::bookHistograms(DQMStore::ConcurrentBooker & ibooker, edm::Run const& run, edm::EventSetup const& setup, APVGain::APVGainHistograms & histograms) const { ibooker.cd(); std::string dqm_dir = m_DQMdir; @@ -517,6 +532,16 @@ SiStripGainsPCLWorker::bookHistograms(DQMStore::IBooker & ibooker, edm::Run cons std::string cvpTECM2 = std::string("Charge_Vs_PathlengthTECM2") + stag; int elepos = statCollectionFromMode(tag); + + histograms.Charge_Vs_Index.reserve(dqm_tag_.size()); + histograms.Charge_Vs_PathlengthTIB.reserve(dqm_tag_.size()); + histograms.Charge_Vs_PathlengthTOB.reserve(dqm_tag_.size()); + histograms.Charge_Vs_PathlengthTIDP.reserve(dqm_tag_.size()); + histograms.Charge_Vs_PathlengthTIDM.reserve(dqm_tag_.size()); + histograms.Charge_Vs_PathlengthTECP1.reserve(dqm_tag_.size()); + histograms.Charge_Vs_PathlengthTECP2.reserve(dqm_tag_.size()); + histograms.Charge_Vs_PathlengthTECM1.reserve(dqm_tag_.size()); + histograms.Charge_Vs_PathlengthTECM2.reserve(dqm_tag_.size()); // The cluster charge is stored by exploiting a non uniform binning in order // reduce the histogram memory size. The bin width is relaxed with a falling @@ -527,12 +552,11 @@ SiStripGainsPCLWorker::bookHistograms(DQMStore::IBooker & ibooker, edm::Run cons // https://indico.cern.ch/event/649344/contributions/2672267/attachments/1498323/2332518/OptimizeChHisto.pdf std::vector binXarray; - binXarray.reserve( NStripAPVs+1 ); - for(int a=0;a<=NStripAPVs;a++){ + binXarray.reserve( histograms.NStripAPVs+1 ); + for(unsigned int a=0;a<=histograms.NStripAPVs;a++){ binXarray.push_back( (float)a ); } - - + std::array binYarray; double p0 = 5.445; double p1 = 0.002113; @@ -544,59 +568,61 @@ SiStripGainsPCLWorker::bookHistograms(DQMStore::IBooker & ibooker, edm::Run cons else y = ( p0 - log(exp(p0-p1*y) - p2*p1)) / p1; } binYarray[687] = 4000.; - - Charge_Vs_Index[elepos] = ibooker.book2S(cvi.c_str() , cvi.c_str() , NStripAPVs, &binXarray[0], 687, binYarray.data()); - Charge_Vs_PathlengthTIB[elepos] = ibooker.book2S(cvpTIB.c_str() , cvpTIB.c_str() , 20 , 0.3 , 1.3 , 250,0,2000); - Charge_Vs_PathlengthTOB[elepos] = ibooker.book2S(cvpTOB.c_str() , cvpTOB.c_str() , 20 , 0.3 , 1.3 , 250,0,2000); - Charge_Vs_PathlengthTIDP[elepos] = ibooker.book2S(cvpTIDP.c_str() , cvpTIDP.c_str() , 20 , 0.3 , 1.3 , 250,0,2000); - Charge_Vs_PathlengthTIDM[elepos] = ibooker.book2S(cvpTIDM.c_str() , cvpTIDM.c_str() , 20 , 0.3 , 1.3 , 250,0,2000); - Charge_Vs_PathlengthTECP1[elepos] = ibooker.book2S(cvpTECP1.c_str(), cvpTECP1.c_str(), 20 , 0.3 , 1.3 , 250,0,2000); - Charge_Vs_PathlengthTECP2[elepos] = ibooker.book2S(cvpTECP2.c_str(), cvpTECP2.c_str(), 20 , 0.3 , 1.3 , 250,0,2000); - Charge_Vs_PathlengthTECM1[elepos] = ibooker.book2S(cvpTECM1.c_str(), cvpTECM1.c_str(), 20 , 0.3 , 1.3 , 250,0,2000); - Charge_Vs_PathlengthTECM2[elepos] = ibooker.book2S(cvpTECM2.c_str(), cvpTECM2.c_str(), 20 , 0.3 , 1.3 , 250,0,2000); - - Charge_1[elepos].clear(); - Charge_2[elepos].clear(); - Charge_3[elepos].clear(); - Charge_4[elepos].clear(); + histograms.Charge_1[elepos].clear(); + histograms.Charge_2[elepos].clear(); + histograms.Charge_3[elepos].clear(); + histograms.Charge_4[elepos].clear(); + + + auto it = histograms.Charge_Vs_Index.begin(); + histograms.Charge_Vs_Index.insert(it+elepos,ibooker.book2S(cvi.c_str() , cvi.c_str() , histograms.NStripAPVs, &binXarray[0], 687, binYarray.data())); + + it = histograms.Charge_Vs_PathlengthTIB.begin(); + histograms.Charge_Vs_PathlengthTIB.insert(it+elepos,ibooker.book2S(cvpTIB.c_str() , cvpTIB.c_str() , 20 , 0.3 , 1.3 , 250,0,2000)); + + it = histograms.Charge_Vs_PathlengthTOB.begin(); + histograms.Charge_Vs_PathlengthTOB.insert(it+elepos,ibooker.book2S(cvpTOB.c_str() , cvpTOB.c_str() , 20 , 0.3 , 1.3 , 250,0,2000)); + + it = histograms.Charge_Vs_PathlengthTIDP.begin(); + histograms.Charge_Vs_PathlengthTIDP.insert(it+elepos,ibooker.book2S(cvpTIDP.c_str() , cvpTIDP.c_str() , 20 , 0.3 , 1.3 , 250,0,2000)); + + it = histograms.Charge_Vs_PathlengthTIDM.begin(); + histograms.Charge_Vs_PathlengthTIDM.insert(it+elepos,ibooker.book2S(cvpTIDM.c_str() , cvpTIDM.c_str() , 20 , 0.3 , 1.3 , 250,0,2000)); + + it = histograms.Charge_Vs_PathlengthTECP1.begin(); + histograms.Charge_Vs_PathlengthTECP1.insert(it+elepos,ibooker.book2S(cvpTECP1.c_str(), cvpTECP1.c_str(), 20 , 0.3 , 1.3 , 250,0,2000)); + + it = histograms.Charge_Vs_PathlengthTECP2.begin(); + histograms.Charge_Vs_PathlengthTECP2.insert(it+elepos,ibooker.book2S(cvpTECP2.c_str(), cvpTECP2.c_str(), 20 , 0.3 , 1.3 , 250,0,2000)); + + it = histograms.Charge_Vs_PathlengthTECM1.begin(); + histograms.Charge_Vs_PathlengthTECM1.insert(it+elepos,ibooker.book2S(cvpTECM1.c_str(), cvpTECM1.c_str(), 20 , 0.3 , 1.3 , 250,0,2000)); + + it = histograms.Charge_Vs_PathlengthTECM2.begin(); + histograms.Charge_Vs_PathlengthTECM2.insert(it+elepos,ibooker.book2S(cvpTECM2.c_str(), cvpTECM2.c_str(), 20 , 0.3 , 1.3 , 250,0,2000)); + std::vector> hnames = APVGain::monHnames(VChargeHisto,doChargeMonitorPerPlane,""); for (unsigned int i=0;i