Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2025-05-15 02:27:53

0001 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0002 #include "FWCore/Utilities/interface/Transition.h"
0003 
0004 #include "Geometry/CommonDetUnit/interface/GluedGeomDet.h"
0005 
0006 #include "DataFormats/DetId/interface/DetId.h"
0007 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0008 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit2D.h"
0009 #include "DataFormats/TrackerRecHit2D/interface/SiStripRecHit1D.h"
0010 #include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h"
0011 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
0012 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
0013 #include "CalibTracker/SiStripCommon/interface/SiStripDCSStatus.h"
0014 #include "CommonTools/TriggerUtils/interface/GenericTriggerEventFlag.h"
0015 #include "DataFormats/TrackReco/interface/HitPattern.h"
0016 #include "DQM/SiStripMonitorTrack/interface/SiStripMonitorTrack.h"
0017 
0018 #include "DQM/SiStripCommon/interface/SiStripHistoId.h"
0019 #include "TMath.h"
0020 
0021 #include "RecoLocalTracker/ClusterParameterEstimator/interface/StripClusterParameterEstimator.h"
0022 #include "RecoLocalTracker/Records/interface/TkStripCPERecord.h"
0023 
0024 SiStripMonitorTrack::SiStripMonitorTrack(const edm::ParameterSet& conf)
0025     : conf_(conf),
0026       siStripClusterInfo_(consumesCollector()),
0027       trackerGeometryToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>()),
0028       siStripDetCablingToken_(esConsumes<SiStripDetCabling, SiStripDetCablingRcd, edm::Transition::BeginRun>()),
0029       trackerTopologyRunToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()),
0030       tkDetMapToken_(esConsumes<TkDetMap, TrackerTopologyRcd, edm::Transition::BeginRun>()),
0031       trackerTopologyEventToken_(esConsumes<TrackerTopology, TrackerTopologyRcd>()),
0032       tracksCollection_in_EventTree(true),
0033       firstEvent(-1),
0034       genTriggerEventFlag_(new GenericTriggerEventFlag(
0035           conf.getParameter<edm::ParameterSet>("genericTriggerEventPSet"), consumesCollector(), *this)) {
0036   Cluster_src_ = conf.getParameter<edm::InputTag>("Cluster_src");
0037   Mod_On_ = conf.getParameter<bool>("Mod_On");
0038   Trend_On_ = conf.getParameter<bool>("Trend_On");
0039   TkHistoMap_On_ = conf.getParameter<bool>("TkHistoMap_On");
0040   clchCMoriginTkHmap_On_ = conf.getParameter<bool>("clchCMoriginTkHmap_On");
0041 
0042   TrackProducer_ = conf_.getParameter<std::string>("TrackProducer");
0043   TrackLabel_ = conf_.getParameter<std::string>("TrackLabel");
0044 
0045   topFolderName_ = conf_.getParameter<std::string>("TopFolderName");
0046 
0047   digiToken_ = consumes<edm::DetSetVector<SiStripDigi>>(conf.getParameter<edm::InputTag>("ADCDigi_src"));
0048   clusterToken_ = consumes<edmNew::DetSetVector<SiStripCluster>>(Cluster_src_);
0049   trackToken_ = consumes<reco::TrackCollection>(edm::InputTag(TrackProducer_, TrackLabel_));
0050 
0051   // cluster quality conditions
0052   edm::ParameterSet cluster_condition = conf_.getParameter<edm::ParameterSet>("ClusterConditions");
0053   applyClusterQuality_ = cluster_condition.getParameter<bool>("On");
0054   sToNLowerLimit_ = cluster_condition.getParameter<double>("minStoN");
0055   sToNUpperLimit_ = cluster_condition.getParameter<double>("maxStoN");
0056   widthLowerLimit_ = cluster_condition.getParameter<double>("minWidth");
0057   widthUpperLimit_ = cluster_condition.getParameter<double>("maxWidth");
0058 
0059   // Create DCS Status
0060   bool checkDCS = conf_.getParameter<bool>("UseDCSFiltering");
0061   if (checkDCS)
0062     dcsStatus_ = new SiStripDCSStatus(consumesCollector());
0063   else
0064     dcsStatus_ = nullptr;
0065 }
0066 
0067 //------------------------------------------------------------------------
0068 SiStripMonitorTrack::~SiStripMonitorTrack() {
0069   if (dcsStatus_)
0070     delete dcsStatus_;
0071   if (genTriggerEventFlag_)
0072     delete genTriggerEventFlag_;
0073 }
0074 
0075 //------------------------------------------------------------------------
0076 void SiStripMonitorTrack::dqmBeginRun(const edm::Run& run, const edm::EventSetup& iSetup) {
0077   tkgeom_ = &iSetup.getData(trackerGeometryToken_);
0078   LogDebug("SiStripMonitorTrack") << "[SiStripMonitorTrack::beginRun] There are " << tkgeom_->detUnits().size()
0079                                   << " detectors instantiated in the geometry" << std::endl;
0080   siStripDetCabling_ = &iSetup.getData(siStripDetCablingToken_);
0081 
0082   // Initialize the GenericTriggerEventFlag
0083   if (genTriggerEventFlag_->on())
0084     genTriggerEventFlag_->initRun(run, iSetup);
0085 }
0086 
0087 //------------------------------------------------------------------------
0088 void SiStripMonitorTrack::bookHistograms(DQMStore::IBooker& ibooker,
0089                                          const edm::Run& run,
0090                                          const edm::EventSetup& iSetup) {
0091   const TrackerTopology* trackerTopology = &iSetup.getData(trackerTopologyRunToken_);
0092   const TkDetMap* tkDetMap = &iSetup.getData(tkDetMapToken_);
0093 
0094   book(ibooker, trackerTopology, tkDetMap);
0095 }
0096 
0097 // ------------ method called to produce the data  ------------
0098 void SiStripMonitorTrack::analyze(const edm::Event& e, const edm::EventSetup& iSetup) {
0099   siStripClusterInfo_.initEvent(iSetup);
0100 
0101   // Filter out events if DCS checking is requested
0102   if (dcsStatus_ && !dcsStatus_->getStatus(e, iSetup))
0103     return;
0104 
0105   // Filter out events if Trigger Filtering is requested
0106   if (genTriggerEventFlag_->on() && !genTriggerEventFlag_->accept(e, iSetup))
0107     return;
0108 
0109   //initialization of global quantities
0110   LogDebug("SiStripMonitorTrack") << "[SiStripMonitorTrack::analyse]  "
0111                                   << "Run " << e.id().run() << " Event " << e.id().event() << std::endl;
0112   eventNb = e.id().event();
0113   vPSiStripCluster.clear();
0114 
0115   iLumisection = e.orbitNumber() / 262144.0;
0116 
0117   // initialise # of clusters
0118   for (auto& iSubDet : SubDetMEsMap) {
0119     iSubDet.second.totNClustersOnTrack = 0;
0120     iSubDet.second.totNClustersOffTrack = 0;
0121     iSubDet.second.totNClustersOnTrackMono = 0;
0122     iSubDet.second.totNClustersOnTrackStereo = 0;
0123   }
0124 
0125   trackerTopology_ = &iSetup.getData(trackerTopologyEventToken_);
0126 
0127   //Perform track study
0128   trackStudy(e);
0129 
0130   //Perform Cluster Study (irrespectively to tracks)
0131 
0132   AllClusters(e);  //analyzes the off Track Clusters
0133 
0134   //Summary Counts of clusters
0135   std::map<std::string, MonitorElement*>::iterator iME;
0136   std::map<std::string, LayerMEs>::iterator iLayerME;
0137 
0138   if (!(topFolderName_.find("IsolatedBunches") != std::string::npos)) {
0139     fillControlViewHistos(e);
0140   }
0141 
0142   if (Trend_On_) {
0143     for (auto const& iSubDet : SubDetMEsMap) {
0144       SubDetMEs subdet_mes = iSubDet.second;
0145       if (subdet_mes.totNClustersOnTrack > 0) {
0146         fillME(subdet_mes.nClustersOnTrack, subdet_mes.totNClustersOnTrack);
0147       }
0148       if (subdet_mes.totNClustersOnTrackMono > 0) {
0149         fillME(subdet_mes.nClustersOnTrackMono, subdet_mes.totNClustersOnTrackMono);
0150       }
0151       if (subdet_mes.totNClustersOnTrackStereo > 0) {
0152         fillME(subdet_mes.nClustersOnTrackStereo, subdet_mes.totNClustersOnTrackStereo);
0153       }
0154       fillME(subdet_mes.nClustersOffTrack, subdet_mes.totNClustersOffTrack);
0155       fillME(subdet_mes.nClustersTrendOnTrack, iLumisection, subdet_mes.totNClustersOnTrack);
0156       fillME(subdet_mes.nClustersTrendOffTrack, iLumisection, subdet_mes.totNClustersOffTrack);
0157     }
0158   } else {
0159     for (auto const& iSubDet : SubDetMEsMap) {
0160       SubDetMEs subdet_mes = iSubDet.second;
0161       if (subdet_mes.totNClustersOnTrack > 0) {
0162         fillME(subdet_mes.nClustersOnTrack, subdet_mes.totNClustersOnTrack);
0163       }
0164       if (subdet_mes.totNClustersOnTrackMono > 0) {
0165         fillME(subdet_mes.nClustersOnTrackMono, subdet_mes.totNClustersOnTrackMono);
0166       }
0167       if (subdet_mes.totNClustersOnTrackStereo > 0) {
0168         fillME(subdet_mes.nClustersOnTrackStereo, subdet_mes.totNClustersOnTrackStereo);
0169       }
0170 
0171       fillME(subdet_mes.nClustersOffTrack, subdet_mes.totNClustersOffTrack);
0172     }
0173   }
0174 }
0175 
0176 //------------------------------------------------------------------------
0177 void SiStripMonitorTrack::book(DQMStore::IBooker& ibooker, const TrackerTopology* tTopo, const TkDetMap* tkDetMap) {
0178   SiStripFolderOrganizer folder_organizer;
0179   folder_organizer.setSiStripFolderName(topFolderName_);
0180   //******** TkHistoMaps
0181   if (TkHistoMap_On_) {
0182     tkhisto_StoNCorrOnTrack =
0183         std::make_unique<TkHistoMap>(tkDetMap, topFolderName_, "TkHMap_StoNCorrOnTrack", 0.0, true);
0184     tkhisto_NumOnTrack =
0185         std::make_unique<TkHistoMap>(tkDetMap, topFolderName_, "TkHMap_NumberOfOnTrackCluster", 0.0, true);
0186     tkhisto_NumOffTrack =
0187         std::make_unique<TkHistoMap>(tkDetMap, topFolderName_, "TkHMap_NumberOfOfffTrackCluster", 0.0, true);
0188     tkhisto_ClChPerCMfromTrack =
0189         std::make_unique<TkHistoMap>(tkDetMap, topFolderName_, "TkHMap_ChargePerCMfromTrack", 0.0, true);
0190     tkhisto_NumMissingHits =
0191         std::make_unique<TkHistoMap>(tkDetMap, topFolderName_, "TkHMap_NumberMissingHits", 0.0, true, true);
0192     tkhisto_NumberInactiveHits =
0193         std::make_unique<TkHistoMap>(tkDetMap, topFolderName_, "TkHMap_NumberInactiveHits", 0.0, true, true);
0194     tkhisto_NumberValidHits =
0195         std::make_unique<TkHistoMap>(tkDetMap, topFolderName_, "TkHMap_NumberValidHits", 0.0, true, true);
0196     tkhisto_NoiseOnTrack = std::make_unique<TkHistoMap>(tkDetMap, topFolderName_, "TkHMap_NoiseOnTrack", 0.0, true);
0197     tkhisto_NoiseOffTrack = std::make_unique<TkHistoMap>(tkDetMap, topFolderName_, "TkHMap_NoiseOffTrack", 0.0, true);
0198     tkhisto_ClusterWidthOnTrack =
0199         std::make_unique<TkHistoMap>(tkDetMap, topFolderName_, "TkHMap_ClusterWidthOnTrack", 0.0, true);
0200     tkhisto_ClusterWidthOffTrack =
0201         std::make_unique<TkHistoMap>(tkDetMap, topFolderName_, "TkHMap_ClusterWidthOffTrack", 0.0, true);
0202   }
0203   if (clchCMoriginTkHmap_On_)
0204     tkhisto_ClChPerCMfromOrigin =
0205         std::make_unique<TkHistoMap>(tkDetMap, topFolderName_, "TkHMap_ChargePerCMfromOrigin", 0.0, true);
0206   //******** TkHistoMaps
0207 
0208   std::vector<uint32_t> vdetId_;
0209   siStripDetCabling_->addActiveDetectorsRawIds(vdetId_);
0210   const char* tec = "TEC";
0211   const char* tid = "TID";
0212   //Histos for each detector, layer and module
0213   SiStripHistoId hidmanager;
0214 
0215   if (Mod_On_) {
0216     for (std::vector<uint32_t>::const_iterator detid_iter = vdetId_.begin(), detid_end = vdetId_.end();
0217          detid_iter != detid_end;
0218          ++detid_iter) {  //loop on all the active detid
0219       uint32_t detid = *detid_iter;
0220 
0221       if (detid < 1) {
0222         edm::LogError("SiStripMonitorTrack") << "[" << __PRETTY_FUNCTION__ << "] invalid detid " << detid << std::endl;
0223         continue;
0224       }
0225 
0226       //std::string name;
0227 
0228       // book Layer and RING plots
0229       std::pair<std::string, int32_t> det_layer_pair = folder_organizer.GetSubDetAndLayer(detid, tTopo, false);
0230       /*
0231       std::string thickness;
0232       std::pair<std::string,int32_t> det_layer_pair_test = folder_organizer.GetSubDetAndLayerThickness(detid,tTopo,thickness);
0233       std::cout << "[SiStripMonitorTrack::book] det_layer_pair " << det_layer_pair.first << " " << det_layer_pair.second << " " << thickness << std::endl;
0234       */
0235 
0236       std::string layer_id = hidmanager.getSubdetid(detid, tTopo, false);
0237 
0238       std::map<std::string, LayerMEs>::iterator iLayerME = LayerMEsMap.find(layer_id);
0239       if (iLayerME == LayerMEsMap.end()) {
0240         folder_organizer.setLayerFolder(detid, tTopo, det_layer_pair.second, false);
0241         bookLayerMEs(ibooker, detid, layer_id);
0242       }
0243 
0244       const char* subdet = det_layer_pair.first.c_str();
0245       if (std::strstr(subdet, tec) != nullptr || std::strstr(subdet, tid) != nullptr) {
0246         std::string ring_id = hidmanager.getSubdetid(detid, tTopo, true);
0247         std::map<std::string, RingMEs>::iterator iRingME = RingMEsMap.find(ring_id);
0248         if (iRingME == RingMEsMap.end()) {
0249           std::pair<std::string, int32_t> det_ring_pair = folder_organizer.GetSubDetAndLayer(detid, tTopo, true);
0250           folder_organizer.setLayerFolder(detid, tTopo, det_ring_pair.second, true);
0251           bookRingMEs(ibooker, detid, ring_id);
0252         }
0253       }
0254 
0255       // book sub-detector plots
0256       auto sdet_pair = folder_organizer.getSubDetFolderAndTag(detid, tTopo);
0257       if (SubDetMEsMap.find(sdet_pair.second) == SubDetMEsMap.end()) {
0258         ibooker.setCurrentFolder(sdet_pair.first);
0259         bookSubDetMEs(ibooker, sdet_pair.second);
0260       }
0261       // book module plots
0262       folder_organizer.setDetectorFolder(detid, tTopo);
0263       bookModMEs(ibooker, *detid_iter);
0264     }  //end loop on detectors detid
0265   } else {
0266     for (std::vector<uint32_t>::const_iterator detid_iter = vdetId_.begin(), detid_end = vdetId_.end();
0267          detid_iter != detid_end;
0268          ++detid_iter) {  //loop on all the active detid
0269       uint32_t detid = *detid_iter;
0270 
0271       if (detid < 1) {
0272         edm::LogError("SiStripMonitorTrack") << "[" << __PRETTY_FUNCTION__ << "] invalid detid " << detid << std::endl;
0273         continue;
0274       }
0275 
0276       //std::string name;
0277 
0278       // book Layer and RING plots
0279       std::pair<std::string, int32_t> det_layer_pair = folder_organizer.GetSubDetAndLayer(detid, tTopo, false);
0280       /*
0281       std::string thickness;
0282       std::pair<std::string,int32_t> det_layer_pair_test = folder_organizer.GetSubDetAndLayerThickness(detid,tTopo,thickness);
0283       std::cout << "[SiStripMonitorTrack::book] det_layer_pair " << det_layer_pair.first << " " << det_layer_pair.second << " " << thickness << std::endl;
0284       */
0285 
0286       std::string layer_id = hidmanager.getSubdetid(detid, tTopo, false);
0287 
0288       std::map<std::string, LayerMEs>::iterator iLayerME = LayerMEsMap.find(layer_id);
0289       if (iLayerME == LayerMEsMap.end()) {
0290         folder_organizer.setLayerFolder(detid, tTopo, det_layer_pair.second, false);
0291         bookLayerMEs(ibooker, detid, layer_id);
0292       }
0293 
0294       const char* subdet = det_layer_pair.first.c_str();
0295       if (std::strstr(subdet, tec) != nullptr || std::strstr(subdet, tid) != nullptr) {
0296         std::string ring_id = hidmanager.getSubdetid(detid, tTopo, true);
0297         std::map<std::string, RingMEs>::iterator iRingME = RingMEsMap.find(ring_id);
0298         if (iRingME == RingMEsMap.end()) {
0299           std::pair<std::string, int32_t> det_ring_pair = folder_organizer.GetSubDetAndLayer(detid, tTopo, true);
0300           folder_organizer.setLayerFolder(detid, tTopo, det_ring_pair.second, true);
0301           bookRingMEs(ibooker, detid, ring_id);
0302         }
0303       }
0304 
0305       // book sub-detector plots
0306       auto sdet_pair = folder_organizer.getSubDetFolderAndTag(detid, tTopo);
0307       if (SubDetMEsMap.find(sdet_pair.second) == SubDetMEsMap.end()) {
0308         ibooker.setCurrentFolder(sdet_pair.first);
0309         bookSubDetMEs(ibooker, sdet_pair.second);
0310       }
0311     }  //end loop on detectors detid
0312   }
0313 
0314   //book control view plots
0315   if (!(topFolderName_.find("IsolatedBunches") != std::string::npos)) {
0316     ibooker.setCurrentFolder(topFolderName_ + "/ControlView/");
0317 
0318     ClusterStoNCorr_OnTrack_TIBTID =
0319         ibooker.book1D("ClusterStoNCorr_OnTrack_TIBTID", "TIB/TID [FECCrate=1] (OnTrack)", 100, 0., 100.);
0320     ClusterStoNCorr_OnTrack_TIBTID->setAxisTitle("S/N", 1);
0321 
0322     ClusterStoNCorr_OnTrack_TOB =
0323         ibooker.book1D("ClusterStoNCorr_OnTrack_TOB", "TOB [FECCrate=4] (OnTrack)", 100, 0., 100.);
0324     ClusterStoNCorr_OnTrack_TOB->setAxisTitle("S/N", 1);
0325 
0326     ClusterStoNCorr_OnTrack_TECM =
0327         ibooker.book1D("ClusterStoNCorr_OnTrack_TECM", "TECM [FECCrate=3] (OnTrack)", 100, 0., 100.);
0328     ClusterStoNCorr_OnTrack_TECM->setAxisTitle("S/N", 1);
0329 
0330     ClusterStoNCorr_OnTrack_TECP =
0331         ibooker.book1D("ClusterStoNCorr_OnTrack_TECP", "TECP [FECCrate=2] (OnTrack)", 100, 0., 100.);
0332     ClusterStoNCorr_OnTrack_TECP->setAxisTitle("S/N", 1);
0333 
0334     ClusterStoNCorr_OnTrack_FECCratevsFECSlot =
0335         ibooker.book2D("ClusterStoNCorr_OnTrack_FECCratevsFECSlot", " S/N (On track)", 22, 0.5, 22.5, 4, 0.5, 4.5);
0336     ClusterStoNCorr_OnTrack_FECCratevsFECSlot->setAxisTitle("FEC Slot", 1);
0337     ClusterStoNCorr_OnTrack_FECCratevsFECSlot->setAxisTitle("FEC Crate (TTC partition)", 2);
0338     ClusterStoNCorr_OnTrack_FECCratevsFECSlot->setBinLabel(1, "TIB/TID", 2);
0339     ClusterStoNCorr_OnTrack_FECCratevsFECSlot->setBinLabel(2, "TEC+", 2);
0340     ClusterStoNCorr_OnTrack_FECCratevsFECSlot->setBinLabel(3, "TEC-", 2);
0341     ClusterStoNCorr_OnTrack_FECCratevsFECSlot->setBinLabel(4, "TOB", 2);
0342 
0343     ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TIBTID = ibooker.book2D("ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TIBTID",
0344                                                                      "TIB/TID [FECCrate=1] (OnTrack)",
0345                                                                      10,
0346                                                                      -0.5,
0347                                                                      9.5,
0348                                                                      22,
0349                                                                      0.5,
0350                                                                      22.5);
0351     ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TIBTID->setAxisTitle("FEC Ring", 1);
0352     ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TIBTID->setAxisTitle("FEC Slot", 2);
0353 
0354     ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TOB = ibooker.book2D(
0355         "ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TOB", "TOB [FECCrate=4] (OnTrack)", 10, -0.5, 9.5, 22, 0.5, 22.5);
0356     ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TOB->setAxisTitle("FEC Ring", 1);
0357     ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TOB->setAxisTitle("FEC Slot", 2);
0358 
0359     ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TECM = ibooker.book2D(
0360         "ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TECM", "TEC- [FECCrate=3] (OnTrack)", 10, -0.5, 9.5, 22, 0.5, 22.5);
0361     ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TECM->setAxisTitle("FEC Ring", 1);
0362     ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TECM->setAxisTitle("FEC Slot", 2);
0363 
0364     ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TECP = ibooker.book2D(
0365         "ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TECP", "TEC- [FECCrate=2] (OnTrack)", 10, -0.5, 9.5, 22, 0.5, 22.5);
0366     ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TECP->setAxisTitle("FEC Ring", 1);
0367     ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TECP->setAxisTitle("FEC Slot", 2);
0368 
0369     //----------------------------------------
0370     // for conting the number of clusters, for the mean S/N calculation
0371     //book control view plots
0372 
0373     ClusterCount_OnTrack_FECCratevsFECSlot =
0374         ibooker.book2D("ClusterCount_OnTrack_FECCratevsFECSlot", " S/N (On track)", 22, 0.5, 22.5, 4, 0.5, 4.5);
0375     ClusterCount_OnTrack_FECCratevsFECSlot->setAxisTitle("FEC Slot", 1);
0376     ClusterCount_OnTrack_FECCratevsFECSlot->setAxisTitle("FEC Crate (TTC partition)", 2);
0377     ClusterCount_OnTrack_FECCratevsFECSlot->setBinLabel(1, "TIB/TID", 2);
0378     ClusterCount_OnTrack_FECCratevsFECSlot->setBinLabel(2, "TEC+", 2);
0379     ClusterCount_OnTrack_FECCratevsFECSlot->setBinLabel(3, "TEC-", 2);
0380     ClusterCount_OnTrack_FECCratevsFECSlot->setBinLabel(4, "TOB", 2);
0381 
0382     ClusterCount_OnTrack_FECSlotVsFECRing_TIBTID = ibooker.book2D(
0383         "ClusterCount_OnTrack_FECSlotVsFECRing_TIBTID", "TIB/TID [FECCrate=1] (OnTrack)", 10, -0.5, 9.5, 22, 0.5, 22.5);
0384     ClusterCount_OnTrack_FECSlotVsFECRing_TIBTID->setAxisTitle("FEC Ring", 1);
0385     ClusterCount_OnTrack_FECSlotVsFECRing_TIBTID->setAxisTitle("FEC Slot", 2);
0386 
0387     ClusterCount_OnTrack_FECSlotVsFECRing_TOB = ibooker.book2D(
0388         "ClusterCount_OnTrack_FECSlotVsFECRing_TOB", "TOB [FECCrate=4] (OnTrack)", 10, -0.5, 9.5, 22, 0.5, 22.5);
0389     ClusterCount_OnTrack_FECSlotVsFECRing_TOB->setAxisTitle("FEC Ring", 1);
0390     ClusterCount_OnTrack_FECSlotVsFECRing_TOB->setAxisTitle("FEC Slot", 2);
0391 
0392     ClusterCount_OnTrack_FECSlotVsFECRing_TECM = ibooker.book2D(
0393         "ClusterCount_OnTrack_FECSlotVsFECRing_TECM", "TEC- [FECCrate=3] (OnTrack)", 10, -0.5, 9.5, 22, 0.5, 22.5);
0394     ClusterCount_OnTrack_FECSlotVsFECRing_TECM->setAxisTitle("FEC Ring", 1);
0395     ClusterCount_OnTrack_FECSlotVsFECRing_TECM->setAxisTitle("FEC Slot", 2);
0396 
0397     ClusterCount_OnTrack_FECSlotVsFECRing_TECP = ibooker.book2D(
0398         "ClusterCount_OnTrack_FECSlotVsFECRing_TECP", "TEC- [FECCrate=2] (OnTrack)", 10, -0.5, 9.5, 22, 0.5, 22.5);
0399     ClusterCount_OnTrack_FECSlotVsFECRing_TECP->setAxisTitle("FEC Ring", 1);
0400     ClusterCount_OnTrack_FECSlotVsFECRing_TECP->setAxisTitle("FEC Slot", 2);
0401   }
0402 }
0403 
0404 //--------------------------------------------------------------------------------
0405 void SiStripMonitorTrack::bookModMEs(DQMStore::IBooker& ibooker, const uint32_t id)  //Histograms at MODULE level
0406 {
0407   std::string name = "det";
0408   SiStripHistoId hidmanager;
0409   std::string hid = hidmanager.createHistoId("", name, id);
0410   std::map<std::string, ModMEs>::iterator iModME = ModMEsMap.find(hid);
0411   if (iModME == ModMEsMap.end()) {
0412     ModMEs theModMEs;
0413 
0414     // Cluster Width
0415     theModMEs.ClusterWidth =
0416         bookME1D(ibooker, "TH1ClusterWidth", hidmanager.createHistoId("ClusterWidth_OnTrack", name, id).c_str());
0417     // Cluster Gain
0418     theModMEs.ClusterGain =
0419         bookME1D(ibooker, "TH1ClusterGain", hidmanager.createHistoId("ClusterGain", name, id).c_str());
0420     // Cluster Charge
0421     theModMEs.ClusterCharge =
0422         bookME1D(ibooker, "TH1ClusterCharge", hidmanager.createHistoId("ClusterCharge_OnTrack", name, id).c_str());
0423     // Cluster Charge Raw (no gain )
0424     theModMEs.ClusterChargeRaw = bookME1D(
0425         ibooker, "TH1ClusterChargeRaw", hidmanager.createHistoId("ClusterChargeRaw_OnTrack", name, id).c_str());
0426     // Cluster Charge Corrected
0427     theModMEs.ClusterChargeCorr = bookME1D(
0428         ibooker, "TH1ClusterChargeCorr", hidmanager.createHistoId("ClusterChargeCorr_OnTrack", name, id).c_str());
0429     // Cluster StoN Corrected
0430     theModMEs.ClusterStoNCorr = bookME1D(
0431         ibooker, "TH1ClusterStoNCorrMod", hidmanager.createHistoId("ClusterStoNCorr_OnTrack", name, id).c_str());
0432     // Cluster Position
0433     short total_nr_strips = siStripDetCabling_->nApvPairs(id) * 2 * 128;
0434     theModMEs.ClusterPos = ibooker.book1D(hidmanager.createHistoId("ClusterPosition_OnTrack", name, id).c_str(),
0435                                           hidmanager.createHistoId("ClusterPosition_OnTrack", name, id).c_str(),
0436                                           total_nr_strips,
0437                                           0.5,
0438                                           total_nr_strips + 0.5);
0439     // Cluster PGV
0440     theModMEs.ClusterPGV =
0441         bookMEProfile(ibooker, "TProfileClusterPGV", hidmanager.createHistoId("PGV_OnTrack", name, id).c_str());
0442     // Cluster Charge per cm
0443     theModMEs.ClusterChargePerCMfromTrack = bookME1D(
0444         ibooker, "TH1ClusterChargePerCM", hidmanager.createHistoId("ClusterChargePerCMfromTrack", name, id).c_str());
0445 
0446     theModMEs.ClusterChargePerCMfromOrigin = bookME1D(
0447         ibooker, "TH1ClusterChargePerCM", hidmanager.createHistoId("ClusterChargePerCMfromOrigin", name, id).c_str());
0448 
0449     ModMEsMap[hid] = theModMEs;
0450   }
0451 }
0452 
0453 SiStripMonitorTrack::MonitorElement* SiStripMonitorTrack::handleBookMEs(DQMStore::IBooker& ibooker,
0454                                                                         std::string& viewParameter,
0455                                                                         std::string& id,
0456                                                                         std::string& histoParameters,
0457                                                                         std::string& histoName) {
0458   MonitorElement* me = nullptr;
0459   bool view = false;
0460   view = (conf_.getParameter<edm::ParameterSet>(histoParameters.c_str())).getParameter<bool>(viewParameter.c_str());
0461   if (id.find("TEC") == std::string::npos && id.find("TID") == std::string::npos) {
0462     me = bookME1D(ibooker, histoParameters.c_str(), histoName.c_str());
0463   } else {
0464     if (view) {
0465       //      histoName = histoName + "__" + thickness;
0466       me = bookME1D(ibooker, histoParameters.c_str(), histoName.c_str());
0467     }
0468   }
0469   return me;
0470 }
0471 
0472 //
0473 // -- Book Layer Level Histograms and Trend plots
0474 //
0475 //------------------------------------------------------------------------
0476 void SiStripMonitorTrack::bookLayerMEs(DQMStore::IBooker& ibooker, const uint32_t mod_id, std::string& layer_id) {
0477   std::string name = "layer";
0478   std::string view = "layerView";
0479   std::string hname;
0480   std::string hpar;
0481   SiStripHistoId hidmanager;
0482 
0483   LayerMEs theLayerMEs;
0484 
0485   // Signal/Noise (w/ cluster harge corrected)
0486   hname = hidmanager.createHistoLayer("Summary_ClusterStoNCorr", name, layer_id, "OnTrack");
0487   hpar = "TH1ClusterStoNCorr";
0488   theLayerMEs.ClusterStoNCorrOnTrack = handleBookMEs(ibooker, view, layer_id, hpar, hname);
0489 
0490   // Cluster Gain
0491   hname = hidmanager.createHistoLayer("Summary_ClusterGain", name, layer_id, "");
0492   hpar = "TH1ClusterGain";
0493   theLayerMEs.ClusterGain = handleBookMEs(ibooker, view, layer_id, hpar, hname);
0494 
0495   // Cluster Charge Corrected
0496   hname = hidmanager.createHistoLayer("Summary_ClusterChargeCorr", name, layer_id, "OnTrack");
0497   hpar = "TH1ClusterChargeCorr";
0498   theLayerMEs.ClusterChargeCorrOnTrack = handleBookMEs(ibooker, view, layer_id, hpar, hname);
0499 
0500   // Cluster Charge (On and Off Track)
0501   hname = hidmanager.createHistoLayer("Summary_ClusterCharge", name, layer_id, "OnTrack");
0502   hpar = "TH1ClusterCharge";
0503   theLayerMEs.ClusterChargeOnTrack = handleBookMEs(ibooker, view, layer_id, hpar, hname);
0504 
0505   hname = hidmanager.createHistoLayer("Summary_ClusterCharge", name, layer_id, "OffTrack");
0506   hpar = "TH1ClusterCharge";
0507   theLayerMEs.ClusterChargeOffTrack = handleBookMEs(ibooker, view, layer_id, hpar, hname);
0508 
0509   // Cluster Charge Raw (On and Off Track)
0510   hname = hidmanager.createHistoLayer("Summary_ClusterChargeRaw", name, layer_id, "OnTrack");
0511   hpar = "TH1ClusterChargeRaw";
0512   theLayerMEs.ClusterChargeRawOnTrack = handleBookMEs(ibooker, view, layer_id, hpar, hname);
0513 
0514   hname = hidmanager.createHistoLayer("Summary_ClusterChargeRaw", name, layer_id, "OffTrack");
0515   hpar = "TH1ClusterChargeRaw";
0516   theLayerMEs.ClusterChargeRawOffTrack = handleBookMEs(ibooker, view, layer_id, hpar, hname);
0517 
0518   // Cluster Noise (On and Off Track)
0519   hname = hidmanager.createHistoLayer("Summary_ClusterNoise", name, layer_id, "OnTrack");
0520   hpar = "TH1ClusterNoise";
0521   theLayerMEs.ClusterNoiseOnTrack = handleBookMEs(ibooker, view, layer_id, hpar, hname);
0522 
0523   hname = hidmanager.createHistoLayer("Summary_ClusterNoise", name, layer_id, "OffTrack");
0524   hpar = "TH1ClusterNoise";
0525   theLayerMEs.ClusterNoiseOffTrack = handleBookMEs(ibooker, view, layer_id, hpar, hname);
0526 
0527   // Cluster Width (On and Off Track)
0528   hname = hidmanager.createHistoLayer("Summary_ClusterWidth", name, layer_id, "OnTrack");
0529   hpar = "TH1ClusterWidth";
0530   theLayerMEs.ClusterWidthOnTrack = handleBookMEs(ibooker, view, layer_id, hpar, hname);
0531 
0532   hname = hidmanager.createHistoLayer("Summary_ClusterWidth", name, layer_id, "OffTrack");
0533   hpar = "TH1ClusterWidth";
0534   theLayerMEs.ClusterWidthOffTrack = handleBookMEs(ibooker, view, layer_id, hpar, hname);
0535 
0536   //Cluster Position
0537   short total_nr_strips = siStripDetCabling_->nApvPairs(mod_id) * 2 * 128;
0538   if (layer_id.find("TEC") != std::string::npos)
0539     total_nr_strips = 3 * 2 * 128;
0540 
0541   hname = hidmanager.createHistoLayer("Summary_ClusterPosition", name, layer_id, "OnTrack");
0542   hpar = "TH1ClusterPos";
0543   if (layer_id.find("TIB") != std::string::npos || layer_id.find("TOB") != std::string::npos ||
0544       (conf_.getParameter<edm::ParameterSet>(hpar.c_str())).getParameter<bool>(view.c_str()))
0545     theLayerMEs.ClusterPosOnTrack = ibooker.book1D(hname, hname, total_nr_strips, 0.5, total_nr_strips + 0.5);
0546 
0547   //----------------------
0548   //add 2D z-phi map per layer
0549   hname = hidmanager.createHistoLayer("Summary_ClusterPosition2D", name, layer_id, "OnTrack");
0550   hpar = "TH2ClusterPosTOB";
0551   if (layer_id.find("TOB") != std::string::npos)
0552     theLayerMEs.ClusterPosOnTrack2D = ibooker.book2D(hname, hname, 12, -110, 110, 300, -3.2, 3.2);
0553 
0554   hname = hidmanager.createHistoLayer("Summary_ClusterPosition2D", name, layer_id, "OnTrack");
0555   hpar = "TH2ClusterPosTIB";
0556   if (layer_id.find("TIB") != std::string::npos)
0557     theLayerMEs.ClusterPosOnTrack2D = ibooker.book2D(hname, hname, 12, -65, 65, 450, -3.2, 3.2);
0558 
0559   hname = hidmanager.createHistoLayer("Summary_ClusterPosition2D", name, layer_id, "OnTrack");
0560   hpar = "TH2ClusterPosTEC";
0561   if (layer_id.find("TEC") != std::string::npos) {
0562     static constexpr int nbinR = 8;
0563     static constexpr float rval[9] = {0, 21.2, 30.8, 40.4, 50.0, 60.0, 75.0, 90.0, 110.0};
0564     static constexpr int nmodulesPhi = 40 * 6;  //max number of APV  for a ring
0565     float phival[nmodulesPhi];
0566     for (int i = 0; i < nmodulesPhi; i++)
0567       phival[i] = -3.2 + 2 * i * 3.2 / nmodulesPhi;
0568 
0569     TH2F* temp = new TH2F("tmp", "tmp", nbinR, rval, nmodulesPhi - 1, phival);
0570     theLayerMEs.ClusterPosOnTrack2D = ibooker.book2D(hname, temp);
0571   }
0572 
0573   hname = hidmanager.createHistoLayer("Summary_ClusterPosition2D", name, layer_id, "OnTrack");
0574   hpar = "TH2ClusterPosTID";
0575   if (layer_id.find("TID") != std::string::npos) {
0576     static constexpr int nbinR = 4;
0577     static constexpr float rval[5] = {0, 21.2, 30.8, 40.4, 50.0};
0578     static constexpr int nmodulesPhi = 80 * 4;  //max number of APV  for a ring
0579     float phival[nmodulesPhi];
0580     for (int i = 0; i < nmodulesPhi; i++)
0581       phival[i] = -3.2 + i * 2 * 3.2 / nmodulesPhi;
0582 
0583     TH2F* temp = new TH2F("tmp", "tmp", nbinR, rval, nmodulesPhi - 1, phival);
0584     theLayerMEs.ClusterPosOnTrack2D = ibooker.book2D(hname, temp);
0585   }
0586 
0587   hname = hidmanager.createHistoLayer("Summary_ClusterPosition", name, layer_id, "OffTrack");
0588   hpar = "TH1ClusterPos";
0589   if (layer_id.find("TIB") != std::string::npos || layer_id.find("TOB") != std::string::npos ||
0590       (conf_.getParameter<edm::ParameterSet>(hpar.c_str())).getParameter<bool>(view.c_str()))
0591     theLayerMEs.ClusterPosOffTrack = ibooker.book1D(hname, hname, total_nr_strips, 0.5, total_nr_strips + 0.5);
0592 
0593   // dQ/dx
0594   hname = hidmanager.createHistoLayer("Summary_ClusterChargePerCMfromTrack", name, layer_id, "");
0595   hpar = "TH1ClusterChargePerCM";
0596   theLayerMEs.ClusterChargePerCMfromTrack = handleBookMEs(ibooker, view, layer_id, hpar, hname);
0597 
0598   hname = hidmanager.createHistoLayer("Summary_ClusterChargePerCMfromOrigin", name, layer_id, "OnTrack");
0599   hpar = "TH1ClusterChargePerCM";
0600   theLayerMEs.ClusterChargePerCMfromOriginOnTrack = handleBookMEs(ibooker, view, layer_id, hpar, hname);
0601 
0602   hname = hidmanager.createHistoLayer("Summary_ClusterChargePerCMfromOrigin", name, layer_id, "OffTrack");
0603   hpar = "TH1ClusterChargePerCM";
0604   theLayerMEs.ClusterChargePerCMfromOriginOffTrack = handleBookMEs(ibooker, view, layer_id, hpar, hname);
0605 
0606   //bookeeping
0607   LayerMEsMap[layer_id] = theLayerMEs;
0608 }
0609 
0610 void SiStripMonitorTrack::bookRingMEs(DQMStore::IBooker& ibooker, const uint32_t mod_id, std::string& ring_id) {
0611   std::string name = "ring";
0612   std::string view = "ringView";
0613   std::string hname;
0614   std::string hpar;
0615   SiStripHistoId hidmanager;
0616 
0617   RingMEs theRingMEs;
0618 
0619   hname = hidmanager.createHistoLayer("Summary_ClusterStoNCorr", name, ring_id, "OnTrack");
0620   hpar = "TH1ClusterStoNCorr";
0621   theRingMEs.ClusterStoNCorrOnTrack = handleBookMEs(ibooker, view, ring_id, hpar, hname);
0622 
0623   // Cluster Gain
0624   hname = hidmanager.createHistoLayer("Summary_ClusterGain", name, ring_id, "");
0625   hpar = "TH1ClusterGain";
0626   theRingMEs.ClusterGain = handleBookMEs(ibooker, view, ring_id, hpar, hname);
0627 
0628   // Cluster Charge Corrected
0629   hname = hidmanager.createHistoLayer("Summary_ClusterChargeCorr", name, ring_id, "OnTrack");
0630   hpar = "TH1ClusterChargeCorr";
0631   theRingMEs.ClusterChargeCorrOnTrack = handleBookMEs(ibooker, view, ring_id, hpar, hname);
0632 
0633   // Cluster Charge (On and Off Track)
0634   hname = hidmanager.createHistoLayer("Summary_ClusterCharge", name, ring_id, "OnTrack");
0635   hpar = "TH1ClusterCharge";
0636   theRingMEs.ClusterChargeOnTrack = handleBookMEs(ibooker, view, ring_id, hpar, hname);
0637 
0638   hname = hidmanager.createHistoLayer("Summary_ClusterCharge", name, ring_id, "OffTrack");
0639   hpar = "TH1ClusterCharge";
0640   theRingMEs.ClusterChargeOffTrack = handleBookMEs(ibooker, view, ring_id, hpar, hname);
0641 
0642   // Cluster Charge Raw (no-gain), On and off track
0643   hname = hidmanager.createHistoLayer("Summary_ClusterChargeRaw", name, ring_id, "OnTrack");
0644   hpar = "TH1ClusterChargeRaw";
0645   theRingMEs.ClusterChargeRawOnTrack = handleBookMEs(ibooker, view, ring_id, hpar, hname);
0646 
0647   hname = hidmanager.createHistoLayer("Summary_ClusterChargeRaw", name, ring_id, "OffTrack");
0648   hpar = "TH1ClusterChargeRaw";
0649   theRingMEs.ClusterChargeRawOffTrack = handleBookMEs(ibooker, view, ring_id, hpar, hname);
0650 
0651   // Cluster Noise (On and Off Track)
0652   hname = hidmanager.createHistoLayer("Summary_ClusterNoise", name, ring_id, "OnTrack");
0653   hpar = "TH1ClusterNoise";
0654   theRingMEs.ClusterNoiseOnTrack = handleBookMEs(ibooker, view, ring_id, hpar, hname);
0655 
0656   hname = hidmanager.createHistoLayer("Summary_ClusterNoise", name, ring_id, "OffTrack");
0657   hpar = "TH1ClusterNoise";
0658   theRingMEs.ClusterNoiseOffTrack = handleBookMEs(ibooker, view, ring_id, hpar, hname);
0659 
0660   // Cluster Width (On and Off Track)
0661   hname = hidmanager.createHistoLayer("Summary_ClusterWidth", name, ring_id, "OnTrack");
0662   hpar = "TH1ClusterWidth";
0663   theRingMEs.ClusterWidthOnTrack = handleBookMEs(ibooker, view, ring_id, hpar, hname);
0664 
0665   hname = hidmanager.createHistoLayer("Summary_ClusterWidth", name, ring_id, "OffTrack");
0666   hpar = "TH1ClusterWidth";
0667   theRingMEs.ClusterWidthOffTrack = handleBookMEs(ibooker, view, ring_id, hpar, hname);
0668 
0669   //Cluster Position
0670   short total_nr_strips = siStripDetCabling_->nApvPairs(mod_id) * 2 * 128;
0671   if (ring_id.find("TEC") != std::string::npos)
0672     total_nr_strips = 3 * 2 * 128;
0673 
0674   hname = hidmanager.createHistoLayer("Summary_ClusterPosition", name, ring_id, "OnTrack");
0675   hpar = "TH1ClusterPos";
0676   if ((conf_.getParameter<edm::ParameterSet>(hpar.c_str())).getParameter<bool>(view.c_str()))
0677     theRingMEs.ClusterPosOnTrack = ibooker.book1D(hname, hname, total_nr_strips, 0.5, total_nr_strips + 0.5);
0678 
0679   hname = hidmanager.createHistoLayer("Summary_ClusterPosition", name, ring_id, "OffTrack");
0680   hpar = "TH1ClusterPos";
0681   if ((conf_.getParameter<edm::ParameterSet>(hpar.c_str())).getParameter<bool>(view.c_str()))
0682     theRingMEs.ClusterPosOffTrack = ibooker.book1D(hname, hname, total_nr_strips, 0.5, total_nr_strips + 0.5);
0683 
0684   // dQ/dx
0685   hname = hidmanager.createHistoLayer("Summary_ClusterChargePerCMfromTrack", name, ring_id, "");
0686   hpar = "TH1ClusterChargePerCM";
0687   theRingMEs.ClusterChargePerCMfromTrack = handleBookMEs(ibooker, view, ring_id, hpar, hname);
0688 
0689   hname = hidmanager.createHistoLayer("Summary_ClusterChargePerCMfromOrigin", name, ring_id, "OnTrack");
0690   hpar = "TH1ClusterChargePerCM";
0691   theRingMEs.ClusterChargePerCMfromOriginOnTrack = handleBookMEs(ibooker, view, ring_id, hpar, hname);
0692 
0693   hname = hidmanager.createHistoLayer("Summary_ClusterChargePerCMfromOrigin", name, ring_id, "OffTrack");
0694   hpar = "TH1ClusterChargePerCM";
0695   theRingMEs.ClusterChargePerCMfromOriginOffTrack = handleBookMEs(ibooker, view, ring_id, hpar, hname);
0696 
0697   //bookeeping
0698   RingMEsMap[ring_id] = theRingMEs;
0699 }
0700 //------------------------------------------------------------------------
0701 //
0702 // -- Book Histograms at Sub-Detector Level
0703 //
0704 void SiStripMonitorTrack::bookSubDetMEs(DQMStore::IBooker& ibooker, std::string_view& name) {
0705   std::string subdet_tag;
0706   auto sname = std::string(name);
0707   subdet_tag = "__" + sname;
0708   std::string completeName;
0709   std::string axisName;
0710 
0711   SubDetMEs theSubDetMEs;
0712 
0713   // TotalNumber of Cluster OnTrack
0714   completeName = "Summary_TotalNumberOfClusters_OnTrack" + subdet_tag;
0715   axisName = "Number of on-track clusters in " + sname;
0716   theSubDetMEs.nClustersOnTrack = bookME1D(ibooker, "TH1nClustersOn", completeName.c_str());
0717   theSubDetMEs.nClustersOnTrack->setAxisTitle(axisName);
0718   theSubDetMEs.nClustersOnTrack->setStatOverflows(kTRUE);
0719 
0720   // TotalNumber of Cluster OnTrack
0721   completeName = "Summary_TotalNumberOfClusters_OnTrackStereo" + subdet_tag;
0722   axisName = "Number of on-track stereo clusters in " + sname;
0723   theSubDetMEs.nClustersOnTrackStereo = bookME1D(ibooker, "TH1nClustersOnStereo", completeName.c_str());
0724   theSubDetMEs.nClustersOnTrackStereo->setAxisTitle(axisName);
0725   theSubDetMEs.nClustersOnTrackStereo->setStatOverflows(kTRUE);
0726 
0727   // TotalNumber of Cluster OffTrack
0728   completeName = "Summary_TotalNumberOfClusters_OffTrack" + subdet_tag;
0729   axisName = "Number of off-track clusters in " + sname;
0730   theSubDetMEs.nClustersOffTrack = bookME1D(ibooker, "TH1nClustersOff", completeName.c_str());
0731   theSubDetMEs.nClustersOffTrack->setAxisTitle(axisName);
0732 
0733   double xmaximum = 0;
0734   if (sname.find("TIB") != std::string_view::npos) {
0735     xmaximum = 40000.0;
0736     theSubDetMEs.nClustersOffTrack->setAxisRange(0.0, xmaximum, 1);
0737   }
0738   if (sname.find("TOB") != std::string_view::npos) {
0739     xmaximum = 40000.0;
0740     theSubDetMEs.nClustersOffTrack->setAxisRange(0.0, xmaximum, 1);
0741   }
0742   if (sname.find("TID") != std::string_view::npos) {
0743     xmaximum = 10000.0;
0744     theSubDetMEs.nClustersOffTrack->setAxisRange(0.0, xmaximum, 1);
0745   }
0746   if (sname.find("TEC") != std::string_view::npos) {
0747     xmaximum = 40000.0;
0748     theSubDetMEs.nClustersOffTrack->setAxisRange(0.0, xmaximum, 1);
0749   }
0750 
0751   theSubDetMEs.nClustersOffTrack->setStatOverflows(kTRUE);
0752 
0753   // Cluster Gain
0754   completeName = "Summary_ClusterGain" + subdet_tag;
0755   theSubDetMEs.ClusterGain = bookME1D(ibooker, "TH1ClusterGain", completeName.c_str());
0756 
0757   // Cluster StoN On Track
0758   completeName = "Summary_ClusterStoNCorr_OnTrack" + subdet_tag;
0759   theSubDetMEs.ClusterStoNCorrOnTrack = bookME1D(ibooker, "TH1ClusterStoNCorr", completeName.c_str());
0760 
0761   completeName = "Summary_ClusterStoNCorrThin_OnTrack" + subdet_tag;
0762   if (subdet_tag.find("TEC") != std::string::npos)
0763     theSubDetMEs.ClusterStoNCorrThinOnTrack = bookME1D(ibooker, "TH1ClusterStoNCorr", completeName.c_str());
0764 
0765   completeName = "Summary_ClusterStoNCorrThick_OnTrack" + subdet_tag;
0766   if (subdet_tag.find("TEC") != std::string::npos)
0767     theSubDetMEs.ClusterStoNCorrThickOnTrack = bookME1D(ibooker, "TH1ClusterStoNCorr", completeName.c_str());
0768 
0769   // Cluster Charge Corrected
0770   completeName = "Summary_ClusterChargeCorr_OnTrack" + subdet_tag;
0771   theSubDetMEs.ClusterChargeCorrOnTrack = bookME1D(ibooker, "TH1ClusterChargeCorr", completeName.c_str());
0772 
0773   completeName = "Summary_ClusterChargeCorrThin_OnTrack" + subdet_tag;
0774   if (subdet_tag.find("TEC") != std::string::npos)
0775     theSubDetMEs.ClusterChargeCorrThinOnTrack = bookME1D(ibooker, "TH1ClusterChargeCorr", completeName.c_str());
0776 
0777   completeName = "Summary_ClusterChargeCorrThick_OnTrack" + subdet_tag;
0778   if (subdet_tag.find("TEC") != std::string::npos)
0779     theSubDetMEs.ClusterChargeCorrThickOnTrack = bookME1D(ibooker, "TH1ClusterChargeCorr", completeName.c_str());
0780 
0781   // Cluster Charge On Track
0782   completeName = "Summary_ClusterCharge_OnTrack" + subdet_tag;
0783   theSubDetMEs.ClusterChargeOnTrack = bookME1D(ibooker, "TH1ClusterCharge", completeName.c_str());
0784 
0785   // Cluster Charge On Track, Raw (no-gain)
0786   completeName = "Summary_ClusterChargeRaw_OnTrack" + subdet_tag;
0787   theSubDetMEs.ClusterChargeRawOnTrack = bookME1D(ibooker, "TH1ClusterChargeRaw", completeName.c_str());
0788 
0789   // Cluster Charge Off Track
0790   completeName = "Summary_ClusterCharge_OffTrack" + subdet_tag;
0791   theSubDetMEs.ClusterChargeOffTrack = bookME1D(ibooker, "TH1ClusterCharge", completeName.c_str());
0792 
0793   // Cluster Charge Off Track, Raw (no-gain)
0794   completeName = "Summary_ClusterChargeRaw_OffTrack" + subdet_tag;
0795   theSubDetMEs.ClusterChargeRawOffTrack = bookME1D(ibooker, "TH1ClusterChargeRaw", completeName.c_str());
0796 
0797   // Cluster Charge StoN Off Track
0798   completeName = "Summary_ClusterStoN_OffTrack" + subdet_tag;
0799   theSubDetMEs.ClusterStoNOffTrack = bookME1D(ibooker, "TH1ClusterStoN", completeName.c_str());
0800 
0801   // cluster charge per cm on track
0802   completeName = "Summary_ClusterChargePerCMfromTrack" + subdet_tag;
0803   theSubDetMEs.ClusterChargePerCMfromTrack = bookME1D(ibooker, "TH1ClusterChargePerCM", completeName.c_str());
0804 
0805   // cluster charge per cm on track
0806   completeName = "Summary_ClusterChargePerCMfromOrigin_OnTrack" + subdet_tag;
0807   theSubDetMEs.ClusterChargePerCMfromOriginOnTrack = bookME1D(ibooker, "TH1ClusterChargePerCM", completeName.c_str());
0808 
0809   // cluster charge per cm off track
0810   completeName = "Summary_ClusterChargePerCMfromOrigin_OffTrack" + subdet_tag;
0811   theSubDetMEs.ClusterChargePerCMfromOriginOffTrack = bookME1D(ibooker, "TH1ClusterChargePerCM", completeName.c_str());
0812 
0813   if (Trend_On_) {
0814     // TotalNumber of Cluster
0815     completeName = "Trend_TotalNumberOfClusters_OnTrack" + subdet_tag;
0816     theSubDetMEs.nClustersTrendOnTrack = bookMETrend(ibooker, completeName.c_str());
0817     completeName = "Trend_TotalNumberOfClusters_OffTrack" + subdet_tag;
0818     theSubDetMEs.nClustersTrendOffTrack = bookMETrend(ibooker, completeName.c_str());
0819   }
0820 
0821   //bookeeping
0822   SubDetMEsMap[name] = theSubDetMEs;
0823 }
0824 //--------------------------------------------------------------------------------
0825 
0826 SiStripMonitorTrack::MonitorElement* SiStripMonitorTrack::bookME1D(DQMStore::IBooker& ibooker,
0827                                                                    const char* ParameterSetLabel,
0828                                                                    const char* HistoName) {
0829   Parameters = conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
0830   return ibooker.book1D(HistoName,
0831                         HistoName,
0832                         Parameters.getParameter<int32_t>("Nbinx"),
0833                         Parameters.getParameter<double>("xmin"),
0834                         Parameters.getParameter<double>("xmax"));
0835 }
0836 
0837 //--------------------------------------------------------------------------------
0838 SiStripMonitorTrack::MonitorElement* SiStripMonitorTrack::bookME2D(DQMStore::IBooker& ibooker,
0839                                                                    const char* ParameterSetLabel,
0840                                                                    const char* HistoName) {
0841   Parameters = conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
0842   return ibooker.book2D(HistoName,
0843                         HistoName,
0844                         Parameters.getParameter<int32_t>("Nbinx"),
0845                         Parameters.getParameter<double>("xmin"),
0846                         Parameters.getParameter<double>("xmax"),
0847                         Parameters.getParameter<int32_t>("Nbiny"),
0848                         Parameters.getParameter<double>("ymin"),
0849                         Parameters.getParameter<double>("ymax"));
0850 }
0851 
0852 //--------------------------------------------------------------------------------
0853 SiStripMonitorTrack::MonitorElement* SiStripMonitorTrack::bookME3D(DQMStore::IBooker& ibooker,
0854                                                                    const char* ParameterSetLabel,
0855                                                                    const char* HistoName) {
0856   Parameters = conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
0857   return ibooker.book3D(HistoName,
0858                         HistoName,
0859                         Parameters.getParameter<int32_t>("Nbinx"),
0860                         Parameters.getParameter<double>("xmin"),
0861                         Parameters.getParameter<double>("xmax"),
0862                         Parameters.getParameter<int32_t>("Nbiny"),
0863                         Parameters.getParameter<double>("ymin"),
0864                         Parameters.getParameter<double>("ymax"),
0865                         Parameters.getParameter<int32_t>("Nbinz"),
0866                         Parameters.getParameter<double>("zmin"),
0867                         Parameters.getParameter<double>("zmax"));
0868 }
0869 
0870 //--------------------------------------------------------------------------------
0871 SiStripMonitorTrack::MonitorElement* SiStripMonitorTrack::bookMEProfile(DQMStore::IBooker& ibooker,
0872                                                                         const char* ParameterSetLabel,
0873                                                                         const char* HistoName) {
0874   Parameters = conf_.getParameter<edm::ParameterSet>(ParameterSetLabel);
0875   return ibooker.bookProfile(HistoName,
0876                              HistoName,
0877                              Parameters.getParameter<int32_t>("Nbinx"),
0878                              Parameters.getParameter<double>("xmin"),
0879                              Parameters.getParameter<double>("xmax"),
0880                              Parameters.getParameter<int32_t>("Nbiny"),
0881                              Parameters.getParameter<double>("ymin"),
0882                              Parameters.getParameter<double>("ymax"),
0883                              "");
0884 }
0885 
0886 //--------------------------------------------------------------------------------
0887 SiStripMonitorTrack::MonitorElement* SiStripMonitorTrack::bookMETrend(DQMStore::IBooker& ibooker,
0888                                                                       const char* HistoName) {
0889   edm::ParameterSet ParametersTrend = conf_.getParameter<edm::ParameterSet>("Trending");
0890   MonitorElement* me = ibooker.bookProfile(HistoName,
0891                                            HistoName,
0892                                            ParametersTrend.getParameter<int32_t>("Nbins"),
0893                                            ParametersTrend.getParameter<double>("xmin"),
0894                                            ParametersTrend.getParameter<double>("xmax"),
0895                                            0,
0896                                            0,
0897                                            "");
0898   if (me->kind() == MonitorElement::Kind::TPROFILE)
0899     me->setCanExtend(TH1::kAllAxes);
0900 
0901   if (!me)
0902     return me;
0903   me->setAxisTitle("Lumisection", 1);
0904   return me;
0905 }
0906 
0907 //------------------------------------------------------------------------------------------
0908 void SiStripMonitorTrack::trajectoryStudy(const reco::Track& track,
0909                                           const edm::DetSetVector<SiStripDigi>& digilist,
0910                                           const edm::Event& ev,
0911                                           bool track_ok) {
0912   auto const& trajParams = track.extra()->trajParams();
0913   assert(trajParams.size() == track.recHitsSize());
0914   auto hb = track.recHitsBegin();
0915   for (unsigned int h = 0; h < track.recHitsSize(); h++) {
0916     auto ttrh = *(hb + h);
0917 
0918     if (TkHistoMap_On_) {
0919       uint32_t thedetid = ttrh->rawId();
0920       if (SiStripDetId(thedetid).subDetector() >= 3 &&
0921           SiStripDetId(thedetid).subDetector() <= 6) {  //TIB/TID + TOB + TEC only
0922         if ((ttrh->getType() == 1))
0923           tkhisto_NumMissingHits->fill(thedetid, 1.);
0924         if ((ttrh->getType() == 2))
0925           tkhisto_NumberInactiveHits->fill(thedetid, 1.);
0926         if ((ttrh->getType() == 0))
0927           tkhisto_NumberValidHits->fill(thedetid, 1.);
0928       }
0929     }
0930 
0931     if (!ttrh->isValid())
0932       continue;
0933 
0934     //trajectory local direction and position on detector
0935     auto statedirection = trajParams[h].momentum();
0936 
0937     const ProjectedSiStripRecHit2D* projhit = dynamic_cast<const ProjectedSiStripRecHit2D*>(ttrh->hit());
0938     const SiStripMatchedRecHit2D* matchedhit = dynamic_cast<const SiStripMatchedRecHit2D*>(ttrh->hit());
0939     const SiStripRecHit2D* hit2D = dynamic_cast<const SiStripRecHit2D*>(ttrh->hit());
0940     const SiStripRecHit1D* hit1D = dynamic_cast<const SiStripRecHit1D*>(ttrh->hit());
0941 
0942     //      RecHitType type=Single;
0943 
0944     if (matchedhit) {
0945       LogTrace("SiStripMonitorTrack") << "\nMatched recHit found" << std::endl;
0946       //    type=Matched;
0947 
0948       const GluedGeomDet* gdet = static_cast<const GluedGeomDet*>(tkgeom_->idToDet(matchedhit->geographicalId()));
0949       GlobalVector gtrkdirup = gdet->toGlobal(statedirection);
0950       //mono side
0951       const GeomDetUnit* monodet = gdet->monoDet();
0952       statedirection = monodet->toLocal(gtrkdirup);
0953       SiStripRecHit2D m = matchedhit->monoHit();
0954       //      if(statedirection.mag() != 0)   RecHitInfo<SiStripRecHit2D>(&m,statedirection,trackref);
0955       if (statedirection.mag())
0956         RecHitInfo<SiStripRecHit2D>(&m, statedirection, digilist, ev, track_ok);
0957       //stereo side
0958       const GeomDetUnit* stereodet = gdet->stereoDet();
0959       statedirection = stereodet->toLocal(gtrkdirup);
0960       SiStripRecHit2D s = matchedhit->stereoHit();
0961       //      if(statedirection.mag() != 0)   RecHitInfo<SiStripRecHit2D>(&s,statedirection,trackref);
0962       if (statedirection.mag())
0963         RecHitInfo<SiStripRecHit2D>(&s, statedirection, digilist, ev, track_ok);
0964     } else if (projhit) {
0965       LogTrace("SiStripMonitorTrack") << "\nProjected recHit found" << std::endl;
0966       //    type=Projected;
0967       const GluedGeomDet* gdet = static_cast<const GluedGeomDet*>(tkgeom_->idToDet(projhit->geographicalId()));
0968 
0969       GlobalVector gtrkdirup = gdet->toGlobal(statedirection);
0970       const SiStripRecHit2D originalhit = projhit->originalHit();
0971       const GeomDetUnit* det;
0972       if (!StripSubdetector(originalhit.geographicalId().rawId()).stereo()) {
0973         //mono side
0974         LogTrace("SiStripMonitorTrack") << "\nProjected recHit found  MONO" << std::endl;
0975         det = gdet->monoDet();
0976         statedirection = det->toLocal(gtrkdirup);
0977         if (statedirection.mag())
0978           RecHitInfo<SiStripRecHit2D>(&(originalhit), statedirection, digilist, ev, track_ok);
0979       } else {
0980         LogTrace("SiStripMonitorTrack") << "\nProjected recHit found STEREO" << std::endl;
0981         //stereo side
0982         det = gdet->stereoDet();
0983         statedirection = det->toLocal(gtrkdirup);
0984         if (statedirection.mag())
0985           RecHitInfo<SiStripRecHit2D>(&(originalhit), statedirection, digilist, ev, track_ok);
0986       }
0987     } else if (hit2D) {
0988       if (statedirection.mag())
0989         RecHitInfo<SiStripRecHit2D>(hit2D, statedirection, digilist, ev, track_ok);
0990     } else if (hit1D) {
0991       if (statedirection.mag())
0992         RecHitInfo<SiStripRecHit1D>(hit1D, statedirection, digilist, ev, track_ok);
0993     } else {
0994       LogDebug("SiStripMonitorTrack") << " LocalMomentum: " << statedirection
0995                                       << "\nLocal x-z plane angle: " << atan2(statedirection.x(), statedirection.z());
0996     }
0997   }
0998 }
0999 //------------------------------------------------------------------------
1000 void SiStripMonitorTrack::hitStudy(const edm::Event& ev,
1001                                    const edm::DetSetVector<SiStripDigi>& digilist,
1002                                    const ProjectedSiStripRecHit2D* projhit,
1003                                    const SiStripMatchedRecHit2D* matchedhit,
1004                                    const SiStripRecHit2D* hit2D,
1005                                    const SiStripRecHit1D* hit1D,
1006                                    LocalVector localMomentum,
1007                                    const bool track_ok) {
1008   LocalVector statedirection;
1009   if (matchedhit) {  // type=Matched;
1010     LogTrace("SiStripMonitorTrack") << "\nMatched recHit found" << std::endl;
1011 
1012     const GluedGeomDet* gdet = static_cast<const GluedGeomDet*>(tkgeom_->idToDet(matchedhit->geographicalId()));
1013 
1014     GlobalVector gtrkdirup = gdet->toGlobal(localMomentum);
1015 
1016     //mono side
1017     const GeomDetUnit* monodet = gdet->monoDet();
1018     statedirection = monodet->toLocal(gtrkdirup);
1019     SiStripRecHit2D m = matchedhit->monoHit();
1020     if (statedirection.mag())
1021       RecHitInfo<SiStripRecHit2D>(&m, statedirection, digilist, ev, track_ok);
1022 
1023     //stereo side
1024     const GeomDetUnit* stereodet = gdet->stereoDet();
1025     statedirection = stereodet->toLocal(gtrkdirup);
1026     SiStripRecHit2D s = matchedhit->stereoHit();
1027     if (statedirection.mag())
1028       RecHitInfo<SiStripRecHit2D>(&s, statedirection, digilist, ev, track_ok);
1029   } else if (projhit) {  // type=Projected;
1030     LogTrace("SiStripMonitorTrack") << "\nProjected recHit found" << std::endl;
1031 
1032     const GluedGeomDet* gdet = static_cast<const GluedGeomDet*>(tkgeom_->idToDet(projhit->geographicalId()));
1033 
1034     GlobalVector gtrkdirup = gdet->toGlobal(localMomentum);
1035     const SiStripRecHit2D originalhit = projhit->originalHit();
1036 
1037     const GeomDetUnit* det;
1038     if (!StripSubdetector(originalhit.geographicalId().rawId()).stereo()) {
1039       //mono side
1040       LogTrace("SiStripMonitorTrack") << "\nProjected recHit found  MONO" << std::endl;
1041       det = gdet->monoDet();
1042       statedirection = det->toLocal(gtrkdirup);
1043       if (statedirection.mag())
1044         RecHitInfo<SiStripRecHit2D>(&(originalhit), statedirection, digilist, ev, track_ok);
1045     } else {
1046       LogTrace("SiStripMonitorTrack") << "\nProjected recHit found STEREO" << std::endl;
1047       //stereo side
1048       det = gdet->stereoDet();
1049       statedirection = det->toLocal(gtrkdirup);
1050       if (statedirection.mag())
1051         RecHitInfo<SiStripRecHit2D>(&(originalhit), statedirection, digilist, ev, track_ok);
1052     }
1053   } else if (hit2D) {  // type=2D
1054     statedirection = localMomentum;
1055     if (statedirection.mag())
1056       RecHitInfo<SiStripRecHit2D>(hit2D, statedirection, digilist, ev, track_ok);
1057   } else if (hit1D) {  // type=1D
1058     statedirection = localMomentum;
1059     if (statedirection.mag())
1060       RecHitInfo<SiStripRecHit1D>(hit1D, statedirection, digilist, ev, track_ok);
1061   } else {
1062     LogDebug("SiStripMonitorTrack") << " LocalMomentum: " << statedirection
1063                                     << "\nLocal x-z plane angle: " << atan2(statedirection.x(), statedirection.z());
1064   }
1065 }
1066 //------------------------------------------------------------------------
1067 void SiStripMonitorTrack::trackStudy(const edm::Event& ev) {
1068   using namespace std;
1069   using namespace edm;
1070   using namespace reco;
1071 
1072   //    edm::Handle<std::vector<Trajectory> > trajectories;
1073   //    ev.getByToken(trajectoryToken_, trajectories);
1074 
1075   // track input
1076   edm::Handle<reco::TrackCollection> trackCollectionHandle;
1077   ev.getByToken(trackToken_, trackCollectionHandle);  //takes the track collection
1078 
1079   // digis list
1080   edm::Handle<edm::DetSetVector<SiStripDigi>> digihandle;
1081   ev.getByToken(digiToken_, digihandle);
1082   edm::DetSetVector<SiStripDigi> dummy;
1083   auto& digilist = digihandle.isValid() ? *(digihandle.product()) : dummy;
1084 
1085   if (trackCollectionHandle.isValid()) {
1086     trackStudyFromTrajectory(trackCollectionHandle, digilist, ev);
1087   } else {
1088     edm::LogError("SiStripMonitorTrack") << "also Track Collection is not valid !! " << TrackLabel_ << std::endl;
1089     return;
1090   }
1091 }
1092 
1093 //------------------------------------------------------------------------
1094 // Should return true if the track is good, false if it should be discarded.
1095 bool SiStripMonitorTrack::trackFilter(const reco::Track& track) {
1096   if (track.pt() < 0.8)
1097     return false;
1098   if (track.p() < 2.0)
1099     return false;
1100   if (track.hitPattern().numberOfValidTrackerHits() <= 6)
1101     return false;
1102   if (track.normalizedChi2() > 10.0)
1103     return false;
1104   return true;
1105 }
1106 //------------------------------------------------------------------------
1107 void SiStripMonitorTrack::trackStudyFromTrack(edm::Handle<reco::TrackCollection> trackCollectionHandle,
1108                                               const edm::DetSetVector<SiStripDigi>& digilist,
1109                                               const edm::Event& ev) {
1110   //numTracks = trackCollectionHandle->size();
1111   reco::TrackCollection trackCollection = *trackCollectionHandle;
1112   for (reco::TrackCollection::const_iterator track = trackCollection.begin(), etrack = trackCollection.end();
1113        track != etrack;
1114        ++track) {
1115     bool track_ok = trackFilter(*track);
1116     //    const reco::TransientTrack transientTrack = transientTrackBuilder->build(track);
1117 
1118     for (trackingRecHit_iterator hit = track->recHitsBegin(), ehit = track->recHitsEnd(); hit != ehit; ++hit) {
1119       if (TkHistoMap_On_) {
1120         uint32_t thedetid = (*hit)->rawId();
1121         if (SiStripDetId(thedetid).subDetector() >= 3 &&
1122             SiStripDetId(thedetid).subDetector() <= 6) {  //TIB/TID + TOB + TEC only
1123           if (((*hit)->getType() == 1))
1124             tkhisto_NumMissingHits->add(thedetid, 1.);
1125           if (((*hit)->getType() == 2))
1126             tkhisto_NumberInactiveHits->add(thedetid, 1.);
1127           if (((*hit)->getType() == 0))
1128             tkhisto_NumberValidHits->add(thedetid, 1.);
1129         }
1130       }
1131 
1132       if (!(*hit)->isValid())
1133         continue;
1134       DetId detID = (*hit)->geographicalId();
1135       if (detID.det() != DetId::Tracker)
1136         continue;
1137       const TrackingRecHit* theHit = (*hit);
1138       const ProjectedSiStripRecHit2D* projhit = dynamic_cast<const ProjectedSiStripRecHit2D*>((theHit));
1139       const SiStripMatchedRecHit2D* matchedhit = dynamic_cast<const SiStripMatchedRecHit2D*>((theHit));
1140       const SiStripRecHit2D* hit2D = dynamic_cast<const SiStripRecHit2D*>((theHit));
1141       const SiStripRecHit1D* hit1D = dynamic_cast<const SiStripRecHit1D*>((theHit));
1142 
1143       //      GlobalPoint globalPoint = hit->globalPosition();
1144       //      reco::TrajectoryStateOnSurface stateOnSurface = transientTrack->stateOnSurface(globalPoint);
1145 
1146       LocalVector localMomentum;
1147       hitStudy(ev, digilist, projhit, matchedhit, hit2D, hit1D, localMomentum, track_ok);
1148     }
1149 
1150     // hit pattern of the track
1151     // const reco::HitPattern & hitsPattern = track->hitPattern();
1152     // loop over the hits of the track
1153     //    for (int i=0; i<hitsPattern.numberOfAllHits(); i++) {
1154     // for (int i=0; i<hitsPattern.numberOfAllHits(reco::HitPattern::TRACK_HITS); i++) {
1155     //   uint32_t hit = hitsPattern.getHitPattern(reco::HitPattern::TRACK_HITS,i);
1156 
1157     // if the hit is valid and in pixel barrel, print out the layer
1158     //   if (hitsPattern.validHitFilter(hit) && hitsPattern.pixelBarrelHitFilter(hit))
1159 
1160     //   if (!hitsPattern.validHitFilter(hit)) continue;
1161     //      if (hitsPattern.pixelHitFilter(hit))       std::cout << "pixel"        << std::endl;       // pixel
1162     //      if (hitsPattern.pixelBarrelHitFilter(hit)) std::cout << "pixel barrel" << std::endl; // pixel barrel
1163     //      if (hitsPattern.pixelEndcapHitFilter(hit)) std::cout << "pixel endcap" << std::endl; // pixel endcap
1164     //      if (hitsPattern.stripHitFilter(hit))       std::cout << "strip" << std::endl;       // strip
1165     //      if (hitsPattern.stripTIBHitFilter(hit))    std::cout << "TIB" << std::endl;    // strip TIB
1166     //      if (hitsPattern.stripTIDHitFilter(hit))    std::cout << "TID" << std::endl;    // strip TID
1167     //      if (hitsPattern.stripTOBHitFilter(hit))    std::cout << "TOB" << std::endl;    // strip TOB
1168     //      if (hitsPattern.stripTECHitFilter(hit))    std::cout << "TEC" << std::endl;    // strip TEC
1169     //      if (hitsPattern.muonDTHitFilter(hit))      std::cout << "DT"  << std::endl;      // muon DT
1170     //      if (hitsPattern.muonCSCHitFilter(hit))     std::cout << "CSC" << std::endl;     // muon CSC
1171     //      if (hitsPattern.muonRPCHitFilter(hit))     std::cout << "RPC" << std::endl;     // muon RPC
1172     //
1173     //      // expert level: printout the hit in 10-bit binary format
1174     //      std::cout << "hit in 10-bit binary format = ";
1175     //      for (int j=9; j>=0; j--) {
1176     //        int bit = (hit >> j) & 0x1;
1177     //        std::cout << bit;
1178     //      }
1179     //      std::cout << std::endl;
1180     // }
1181   }
1182 }
1183 //------------------------------------------------------------------------
1184 void SiStripMonitorTrack::trackStudyFromTrajectory(edm::Handle<reco::TrackCollection> trackCollectionHandle,
1185                                                    const edm::DetSetVector<SiStripDigi>& digilist,
1186                                                    const edm::Event& ev) {
1187   //Perform track study
1188   int i = 0;
1189   reco::TrackCollection trackCollection = *trackCollectionHandle;
1190   numTracks = trackCollection.size();
1191   for (reco::TrackCollection::const_iterator track = trackCollection.begin(), etrack = trackCollection.end();
1192        track != etrack;
1193        ++track) {
1194     LogDebug("SiStripMonitorTrack") << "Track number " << ++i << std::endl;
1195     //      << "\n\tmomentum: " << trackref->momentum()
1196     //      << "\n\tPT: " << trackref->pt()
1197     //      << "\n\tvertex: " << trackref->vertex()
1198     //      << "\n\timpact parameter: " << trackref->d0()
1199     //      << "\n\tcharge: " << trackref->charge()
1200     //      << "\n\tnormalizedChi2: " << trackref->normalizedChi2()
1201     //      <<"\n\tFrom EXTRA : "
1202     //      <<"\n\t\touter PT "<< trackref->outerPt()<<std::endl;
1203 
1204     //    trajectoryStudy(traj_iterator,trackref);
1205     bool track_ok = trackFilter(*track);
1206     trajectoryStudy(*track, digilist, ev, track_ok);
1207   }
1208 }
1209 //------------------------------------------------------------------------
1210 template <class T>
1211 void SiStripMonitorTrack::RecHitInfo(const T* tkrecHit,
1212                                      LocalVector LV,
1213                                      const edm::DetSetVector<SiStripDigi>& digilist,
1214                                      const edm::Event& ev,
1215                                      bool track_ok) {
1216   if (!tkrecHit->isValid()) {
1217     LogTrace("SiStripMonitorTrack") << "\t\t Invalid Hit " << std::endl;
1218     return;
1219   }
1220 
1221   const uint32_t& detid = tkrecHit->geographicalId().rawId();
1222 
1223   LogTrace("SiStripMonitorTrack")
1224       << "\n\t\tRecHit on det " << detid << "\n\t\tRecHit in LP " << tkrecHit->localPosition() << "\n\t\tRecHit in GP "
1225       << tkgeom_->idToDet(tkrecHit->geographicalId())->surface().toGlobal(tkrecHit->localPosition())
1226       << "\n\t\tRecHit trackLocal vector " << LV.x() << " " << LV.y() << " " << LV.z() << std::endl;
1227 
1228   //Get SiStripCluster from SiStripRecHit
1229   if (tkrecHit != nullptr && tkrecHit->isValid()) {
1230     const DetId detid = tkrecHit->geographicalId();
1231     int subDet = detid.subdetId();
1232     //std::cout << __LINE__ << std::endl;
1233     float clust_Pos1 = -1000;
1234     float clust_Pos2 = -1000;
1235 
1236     GlobalPoint theGlobalPos =
1237         tkgeom_->idToDet(tkrecHit->geographicalId())->surface().toGlobal(tkrecHit->localPosition());
1238     if (subDet == SiStripDetId::TIB || subDet == SiStripDetId::TOB) {
1239       clust_Pos1 = theGlobalPos.z();
1240       clust_Pos2 = theGlobalPos.phi();
1241     } else {
1242       clust_Pos1 = pow(theGlobalPos.x() * theGlobalPos.x() + theGlobalPos.y() * theGlobalPos.y(), 0.5);
1243       clust_Pos2 = theGlobalPos.phi();
1244     }
1245 
1246     const SiStripCluster* SiStripCluster_ = &*(tkrecHit->cluster());
1247     siStripClusterInfo_.setCluster(*SiStripCluster_, detid);
1248 
1249     const Det2MEs MEs = findMEs(trackerTopology_, detid);
1250     if (clusterInfos(&siStripClusterInfo_,
1251                      detid,
1252                      OnTrack,
1253                      track_ok,
1254                      LV,
1255                      MEs,
1256                      trackerTopology_,
1257                      siStripClusterInfo_.siStripGain(),
1258                      siStripClusterInfo_.siStripQuality(),
1259                      digilist,
1260                      clust_Pos1,
1261                      clust_Pos2)) {
1262       vPSiStripCluster.insert(SiStripCluster_);
1263     }
1264   } else {
1265     edm::LogError("SiStripMonitorTrack") << "NULL hit" << std::endl;
1266   }
1267 }
1268 
1269 //------------------------------------------------------------------------
1270 void SiStripMonitorTrack::AllClusters(const edm::Event& ev) {
1271   const TrackerTopology* tTopo = trackerTopology_;
1272 
1273   edm::Handle<edm::DetSetVector<SiStripDigi>> digihandle;
1274   ev.getByToken(digiToken_, digihandle);
1275 
1276   edm::DetSetVector<SiStripDigi> dummy;
1277   auto& digilist = digihandle.isValid() ? *(digihandle.product()) : dummy;
1278 
1279   edm::Handle<edmNew::DetSetVector<SiStripCluster>> siStripClusterHandle;
1280   ev.getByToken(clusterToken_, siStripClusterHandle);
1281 
1282   /*edm::ESHandle<StripClusterParameterEstimator> parameterestimator;
1283   es.get<TkStripCPERecord>().get("StripCPEfromTrackAngle", parameterestimator); 
1284   const StripClusterParameterEstimator &stripcpe(*parameterestimator);*/
1285 
1286   if (siStripClusterHandle.isValid()) {
1287     //Loop on Dets
1288     for (edmNew::DetSetVector<SiStripCluster>::const_iterator DSViter = siStripClusterHandle->begin(),
1289                                                               DSVEnd = siStripClusterHandle->end();
1290          DSViter != DSVEnd;
1291          ++DSViter) {
1292       uint32_t detid = DSViter->id();
1293       const Det2MEs MEs = findMEs(tTopo, detid);
1294 
1295       LogDebug("SiStripMonitorTrack") << "on detid " << detid << " N Cluster= " << DSViter->size();
1296 
1297       //Loop on Clusters
1298       for (edmNew::DetSet<SiStripCluster>::const_iterator ClusIter = DSViter->begin(), ClusEnd = DSViter->end();
1299            ClusIter != ClusEnd;
1300            ++ClusIter) {
1301         if (vPSiStripCluster.find(&*ClusIter) == vPSiStripCluster.end()) {
1302           siStripClusterInfo_.setCluster(*ClusIter, detid);
1303 
1304           /*const StripGeomDetUnit * stripdet = (const StripGeomDetUnit*) tkgeom->idToDetUnit(detid);
1305           StripClusterParameterEstimator::LocalValues parameters=stripcpe.localParameters(*ClusIter, *stripdet);
1306           LocalPoint lp = parameters.first;
1307       const Surface& surface = tracker->idToDet(detid)->surface();
1308       GlobalPoint gp = surface.toGlobal(lp);*/
1309 
1310           clusterInfos(&siStripClusterInfo_,
1311                        detid,
1312                        OffTrack,
1313                        /*track_ok*/ false,
1314                        LV,
1315                        MEs,
1316                        tTopo,
1317                        siStripClusterInfo_.siStripGain(),
1318                        siStripClusterInfo_.siStripQuality(),
1319                        digilist,
1320                        0,
1321                        0);
1322         }
1323       }
1324     }
1325   } else {
1326     edm::LogError("SiStripMonitorTrack") << "ClusterCollection is not valid!!" << std::endl;
1327     return;
1328   }
1329 }
1330 
1331 //------------------------------------------------------------------------
1332 SiStripMonitorTrack::Det2MEs SiStripMonitorTrack::findMEs(const TrackerTopology* tTopo, const uint32_t detid) {
1333   SiStripHistoId hidmanager1;
1334 
1335   std::string layer_id = hidmanager1.getSubdetid(detid, tTopo, false);
1336   std::string ring_id = hidmanager1.getSubdetid(detid, tTopo, true);
1337   const std::string_view sdet_tag = folderOrganizer_.getSubDetTag(detid, tTopo);
1338 
1339   Det2MEs me;
1340   me.iLayer = nullptr;
1341   me.iRing = nullptr;
1342   me.iSubdet = nullptr;
1343 
1344   std::map<std::string, LayerMEs>::iterator iLayer = LayerMEsMap.find(layer_id);
1345   if (iLayer != LayerMEsMap.end()) {
1346     me.iLayer = &(iLayer->second);
1347   }
1348 
1349   std::map<std::string, RingMEs>::iterator iRing = RingMEsMap.find(ring_id);
1350   if (iRing != RingMEsMap.end()) {
1351     me.iRing = &(iRing->second);
1352   }
1353 
1354   auto iSubdet = SubDetMEsMap.find(sdet_tag);
1355   if (iSubdet != SubDetMEsMap.end()) {
1356     me.iSubdet = &(iSubdet->second);
1357   }
1358 
1359   return me;
1360 }
1361 
1362 bool SiStripMonitorTrack::fillControlViewHistos(const edm::Event& ev) {
1363   const TrackerTopology* tTopo = trackerTopology_;
1364 
1365   edm::Handle<reco::TrackCollection> tracks;
1366   ev.getByToken(trackToken_, tracks);  //takes the track collection
1367 
1368   //check that tracks are valid
1369   if (!tracks.isValid())
1370     return false;
1371 
1372   // loop over the tracks
1373   for (const auto& track : *tracks) {
1374     // loop over the rechits of this track
1375     for (trackingRecHit_iterator hit = track.recHitsBegin(), ehit = track.recHitsEnd(); hit != ehit; ++hit) {
1376       uint32_t thedetid = (*hit)->rawId();
1377       if (!(DetId(thedetid).subdetId() >= 3 && DetId(thedetid).subdetId() <= 6)) {
1378         continue;
1379       }
1380 
1381       if (!(*hit)->isValid())
1382         continue;
1383 
1384       const TrackingRecHit* theHit = (*hit);
1385       if (theHit == nullptr) {
1386         continue;
1387       }
1388 
1389       const SiStripRecHit1D* hit1D = dynamic_cast<const SiStripRecHit1D*>(theHit);
1390       const SiStripRecHit2D* hit2D = dynamic_cast<const SiStripRecHit2D*>(theHit);
1391 
1392       float sovn = -1.;
1393       if (hit1D && !hit2D) {
1394         const SiStripCluster* SiStripCluster_ = &*(hit1D->cluster());
1395         siStripClusterInfo_.setCluster(*SiStripCluster_, thedetid);
1396         sovn = siStripClusterInfo_.signalOverNoise();
1397       }
1398 
1399       else if (!hit1D && hit2D) {
1400         const SiStripCluster* SiStripCluster_ = &*(hit2D->cluster());
1401         siStripClusterInfo_.setCluster(*SiStripCluster_, thedetid);
1402         sovn = siStripClusterInfo_.signalOverNoise();
1403       }
1404 
1405       std::vector<const FedChannelConnection*> getFedChanConnections;
1406       getFedChanConnections = siStripDetCabling_->getConnections(thedetid);
1407 
1408       //      SiStripFolderOrganizer folder_organizer;
1409       //      std::string sistripsubdet = folder_organizer.getSubDetFolderAndTag(thedetid, tTopo).second;
1410 
1411       // loop over the fed chan connections
1412       for (const auto& getFedChanConnection : getFedChanConnections) {
1413         if (getFedChanConnection == nullptr) {
1414           continue;
1415         }
1416 
1417         int binfeccrate = getFedChanConnection->fecCrate();
1418         int binfecslot = getFedChanConnection->fecSlot();
1419         int binfecring = getFedChanConnection->fecRing();
1420         //int binccuchan  = getFedChanConnections[i0]->ccuChan(); //will be used in a new PR
1421         //int binccuadd   = getFedChanConnections[i0]->ccuAddr(); //will be used in a new PR
1422 
1423         return2DME(ClusterStoNCorr_OnTrack_FECCratevsFECSlot,
1424                    ClusterCount_OnTrack_FECCratevsFECSlot,
1425                    binfecslot,
1426                    binfeccrate,
1427                    sovn);
1428 
1429         // TIB/TID
1430         //        if ((sistripsubdet.find("TIB")) || (sistripsubdet.find("TID"))) {
1431         if ((DetId(thedetid).subdetId() == SiStripDetId::TIB) || ((DetId(thedetid).subdetId() == SiStripDetId::TID))) {
1432           ClusterStoNCorr_OnTrack_TIBTID->Fill(sovn);
1433           return2DME(ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TIBTID,
1434                      ClusterCount_OnTrack_FECSlotVsFECRing_TIBTID,
1435                      binfecring,
1436                      binfecslot,
1437                      sovn);
1438         }
1439 
1440         // TOB
1441         if (DetId(thedetid).subdetId() == SiStripDetId::TOB) {
1442           ClusterStoNCorr_OnTrack_TOB->Fill(sovn);
1443           return2DME(ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TOB,
1444                      ClusterCount_OnTrack_FECSlotVsFECRing_TOB,
1445                      binfecring,
1446                      binfecslot,
1447                      sovn);
1448         }
1449 
1450         // TECM
1451         if ((DetId(thedetid).subdetId() == SiStripDetId::TEC) && (tTopo->tecSide(thedetid) == 1)) {
1452           ClusterStoNCorr_OnTrack_TECM->Fill(sovn);
1453           return2DME(ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TECM,
1454                      ClusterCount_OnTrack_FECSlotVsFECRing_TECM,
1455                      binfecring,
1456                      binfecslot,
1457                      sovn);
1458         }
1459 
1460         // TECP
1461         if ((DetId(thedetid).subdetId() == SiStripDetId::TEC) && (tTopo->tecSide(thedetid) == 2)) {
1462           ClusterStoNCorr_OnTrack_TECP->Fill(sovn);
1463           return2DME(ClusterStoNCorr_OnTrack_FECSlotVsFECRing_TECP,
1464                      ClusterCount_OnTrack_FECSlotVsFECRing_TECP,
1465                      binfecring,
1466                      binfecslot,
1467                      sovn);
1468         }
1469 
1470       }  // end of looping over the fed chan connections
1471     }  // end of looping over the rechits of the track
1472   }  // end of looping over the tracks
1473 
1474   return true;
1475 }
1476 
1477 void SiStripMonitorTrack::return2DME(MonitorElement* input1, MonitorElement* input2, int binx, int biny, double value) {
1478   if (input1->getBinContent(binx, biny) == 0.) {
1479     input1->setBinContent(binx, biny, value);
1480     input2->setBinContent(binx, biny, 1);
1481   } else {
1482     double nentries = input2->getBinContent(binx, biny);
1483     double theMeanSoN = (input1->getBinContent(binx, biny) * nentries + value) / (nentries + 1);
1484     //input1->setBinContent(binx,biny,((input1->getBinContent(binx,biny)+value)/2.));
1485     input1->setBinContent(binx, biny, theMeanSoN);
1486     input2->setBinContent(binx, biny, input2->getBinContent(binx, biny) + 1);
1487   }
1488 }
1489 
1490 //------------------------------------------------------------------------
1491 #include "DataFormats/SiStripCluster/interface/SiStripClusterTools.h"
1492 bool SiStripMonitorTrack::clusterInfos(SiStripClusterInfo* cluster,
1493                                        const uint32_t detid,
1494                                        enum ClusterFlags flag,
1495                                        bool track_ok,
1496                                        const LocalVector LV,
1497                                        const Det2MEs& MEs,
1498                                        const TrackerTopology* tTopo,
1499                                        const SiStripGain* stripGain,
1500                                        const SiStripQuality* stripQuality,
1501                                        const edm::DetSetVector<SiStripDigi>& digilist,
1502                                        float valX,
1503                                        float valY) {
1504   if (cluster == nullptr)
1505     return false;
1506   // if one imposes a cut on the clusters, apply it
1507   if ((applyClusterQuality_) &&
1508       (cluster->signalOverNoise() < sToNLowerLimit_ || cluster->signalOverNoise() > sToNUpperLimit_ ||
1509        cluster->width() < widthLowerLimit_ || cluster->width() > widthUpperLimit_))
1510     return false;
1511   // start of the analysis
1512 
1513   float cosRZ = -2;
1514   LogDebug("SiStripMonitorTrack") << "\n\tLV " << LV.x() << " " << LV.y() << " " << LV.z() << " " << LV.mag()
1515                                   << std::endl;
1516   if (LV.mag()) {
1517     cosRZ = fabs(LV.z()) / LV.mag();
1518     LogDebug("SiStripMonitorTrack") << "\n\t cosRZ " << cosRZ << std::endl;
1519   }
1520 
1521   // Filling SubDet/Layer Plots (on Track + off Track)
1522   float StoN = cluster->signalOverNoise();
1523   float noise = cluster->noiseRescaledByGain();
1524   uint16_t charge = cluster->charge();
1525   uint16_t width = cluster->width();
1526   float position = cluster->baryStrip();
1527 
1528   // Getting raw charge with strip gain.
1529   double chargeraw = 0;
1530   double clustergain = 0;
1531   auto digi_it = digilist.find(detid);  //(digilist.isValid() ? digilist.find(detid) : digilist.end());
1532   // SiStripClusterInfo.stripCharges() <==> SiStripCluster.amplitudes()
1533   for (size_t chidx = 0; chidx < cluster->stripCharges().size(); ++chidx) {
1534     if (cluster->stripCharges()[chidx] <= 0) {
1535       continue;
1536     }  // nonzero amplitude
1537     if (stripQuality->IsStripBad(stripQuality->getRange(detid), cluster->firstStrip() + chidx)) {
1538       continue;
1539     }
1540     clustergain += stripGain->getStripGain(cluster->firstStrip() + chidx, stripGain->getRange(detid));
1541     // Getting raw adc charge from digi collections
1542     if (digi_it == digilist.end()) {
1543       continue;
1544     }  // skipping if not found
1545     for (const auto& digiobj : *digi_it) {
1546       if (digiobj.strip() == cluster->firstStrip() + chidx) {
1547         chargeraw += digiobj.adc();
1548       }
1549     }
1550   }
1551 
1552   clustergain /= double(cluster->stripCharges().size());  // calculating average gain inside cluster
1553 
1554   // new dE/dx (chargePerCM)
1555   // https://indico.cern.ch/event/342236/session/5/contribution/10/material/slides/0.pdf
1556   float dQdx_fromTrack = siStripClusterTools::chargePerCM(detid, *cluster, LV);
1557   // from straigth line origin-sensor centre
1558   const StripGeomDetUnit* DetUnit = static_cast<const StripGeomDetUnit*>(tkgeom_->idToDetUnit(DetId(detid)));
1559   LocalPoint locVtx = DetUnit->toLocal(GlobalPoint(0.0, 0.0, 0.0));
1560   LocalVector locDir(locVtx.x(), locVtx.y(), locVtx.z());
1561   float dQdx_fromOrigin = siStripClusterTools::chargePerCM(detid, *cluster, locDir);
1562 
1563   if (TkHistoMap_On_ && (flag == OnTrack)) {
1564     uint32_t adet = cluster->detId();
1565     if (track_ok)
1566       tkhisto_ClChPerCMfromTrack->fill(adet, dQdx_fromTrack);
1567   }
1568   if (clchCMoriginTkHmap_On_ && (flag == OffTrack)) {
1569     uint32_t adet = cluster->detId();
1570     if (track_ok)
1571       tkhisto_ClChPerCMfromOrigin->fill(adet, dQdx_fromOrigin);
1572   }
1573 
1574   if (flag == OnTrack) {
1575     if (MEs.iSubdet != nullptr) {
1576       MEs.iSubdet->totNClustersOnTrack++;
1577       if (StripSubdetector(detid).stereo() == 1)
1578         MEs.iSubdet->totNClustersOnTrackStereo++;
1579       else
1580         MEs.iSubdet->totNClustersOnTrackMono++;
1581     }
1582     // layerMEs
1583     if (MEs.iLayer != nullptr) {
1584       if (noise > 0.0)
1585         fillME(MEs.iLayer->ClusterStoNCorrOnTrack, StoN * cosRZ);
1586       if (noise == 0.0)
1587         LogDebug("SiStripMonitorTrack") << "Module " << detid << " in Event " << eventNb << " noise "
1588                                         << cluster->noiseRescaledByGain() << std::endl;
1589       fillME(MEs.iLayer->ClusterGain, clustergain);
1590       fillME(MEs.iLayer->ClusterChargeCorrOnTrack, charge * cosRZ);
1591       fillME(MEs.iLayer->ClusterChargeOnTrack, charge);
1592       fillME(MEs.iLayer->ClusterChargeRawOnTrack, chargeraw);
1593       fillME(MEs.iLayer->ClusterNoiseOnTrack, noise);
1594       fillME(MEs.iLayer->ClusterWidthOnTrack, width);
1595       fillME(MEs.iLayer->ClusterPosOnTrack, position);
1596       //auto clustgp = cluster->globalPosition();
1597 
1598       fillME(MEs.iLayer->ClusterPosOnTrack2D, valX, valY);
1599 
1600       if (track_ok)
1601         fillME(MEs.iLayer->ClusterChargePerCMfromTrack, dQdx_fromTrack);
1602       if (track_ok)
1603         fillME(MEs.iLayer->ClusterChargePerCMfromOriginOnTrack, dQdx_fromOrigin);
1604     }
1605     // ringMEs
1606     if (MEs.iRing != nullptr) {
1607       if (noise > 0.0)
1608         fillME(MEs.iRing->ClusterStoNCorrOnTrack, StoN * cosRZ);
1609       if (noise == 0.0)
1610         LogDebug("SiStripMonitorTrack") << "Module " << detid << " in Event " << eventNb << " noise "
1611                                         << cluster->noiseRescaledByGain() << std::endl;
1612       fillME(MEs.iRing->ClusterGain, clustergain);
1613       fillME(MEs.iRing->ClusterChargeCorrOnTrack, charge * cosRZ);
1614       fillME(MEs.iRing->ClusterChargeOnTrack, charge);
1615       fillME(MEs.iRing->ClusterChargeRawOnTrack, chargeraw);
1616       fillME(MEs.iRing->ClusterNoiseOnTrack, noise);
1617       fillME(MEs.iRing->ClusterWidthOnTrack, width);
1618       fillME(MEs.iRing->ClusterPosOnTrack, position);
1619       if (track_ok)
1620         fillME(MEs.iRing->ClusterChargePerCMfromTrack, dQdx_fromTrack);
1621       if (track_ok)
1622         fillME(MEs.iRing->ClusterChargePerCMfromOriginOnTrack, dQdx_fromOrigin);
1623     }
1624     // subdetMEs
1625     if (MEs.iSubdet != nullptr) {
1626       fillME(MEs.iSubdet->ClusterGain, clustergain);
1627       fillME(MEs.iSubdet->ClusterChargeOnTrack, charge);
1628       fillME(MEs.iSubdet->ClusterChargeRawOnTrack, chargeraw);
1629       if (noise > 0.0)
1630         fillME(MEs.iSubdet->ClusterStoNCorrOnTrack, StoN * cosRZ);
1631       fillME(MEs.iSubdet->ClusterChargeCorrOnTrack, charge * cosRZ);
1632       if (track_ok)
1633         fillME(MEs.iSubdet->ClusterChargePerCMfromTrack, dQdx_fromTrack);
1634       if (track_ok)
1635         fillME(MEs.iSubdet->ClusterChargePerCMfromOriginOnTrack, dQdx_fromOrigin);
1636       if (tTopo->moduleGeometry(detid) == SiStripModuleGeometry::W5 ||
1637           tTopo->moduleGeometry(detid) == SiStripModuleGeometry::W6 ||
1638           tTopo->moduleGeometry(detid) == SiStripModuleGeometry::W7) {
1639         if (noise > 0.0)
1640           fillME(MEs.iSubdet->ClusterStoNCorrThickOnTrack, StoN * cosRZ);
1641         fillME(MEs.iSubdet->ClusterChargeCorrThickOnTrack, charge * cosRZ);
1642       } else {
1643         if (noise > 0.0)
1644           fillME(MEs.iSubdet->ClusterStoNCorrThinOnTrack, StoN * cosRZ);
1645         fillME(MEs.iSubdet->ClusterChargeCorrThinOnTrack, charge * cosRZ);
1646       }
1647     }
1648     //******** TkHistoMaps
1649     if (TkHistoMap_On_) {
1650       uint32_t adet = cluster->detId();
1651       tkhisto_NumOnTrack->add(adet, 1.);
1652       if (noise > 0.0)
1653         tkhisto_StoNCorrOnTrack->fill(adet, cluster->signalOverNoise() * cosRZ);
1654       if (noise == 0.0)
1655         LogDebug("SiStripMonitorTrack") << "Module " << detid << " in Event " << eventNb << " noise " << noise
1656                                         << std::endl;
1657     }
1658     if (TkHistoMap_On_ && (flag == OnTrack)) {
1659       uint32_t adet = cluster->detId();
1660       tkhisto_ClusterWidthOnTrack->fill(adet, cluster->width());
1661       if (noise > 0.0)
1662         tkhisto_NoiseOnTrack->fill(adet, cluster->noiseRescaledByGain() * cosRZ);
1663     }
1664 
1665     // Module plots filled only for onTrack Clusters
1666     if (Mod_On_) {
1667       SiStripHistoId hidmanager2;
1668       std::string name = hidmanager2.createHistoId("", "det", detid);
1669       //fillModMEs
1670       std::map<std::string, ModMEs>::iterator iModME = ModMEsMap.find(name);
1671       if (iModME != ModMEsMap.end()) {
1672         if (noise > 0.0)
1673           fillME(iModME->second.ClusterStoNCorr, StoN * cosRZ);
1674         if (noise == 0.0)
1675           LogDebug("SiStripMonitorTrack")
1676               << "Module " << name << " in Event " << eventNb << " noise " << noise << std::endl;
1677         fillME(iModME->second.ClusterGain, clustergain);
1678         fillME(iModME->second.ClusterCharge, charge);
1679         fillME(iModME->second.ClusterChargeRaw, chargeraw);
1680 
1681         fillME(iModME->second.ClusterChargeCorr, charge * cosRZ);
1682 
1683         fillME(iModME->second.ClusterWidth, width);
1684         fillME(iModME->second.ClusterPos, position);
1685 
1686         if (track_ok)
1687           fillME(iModME->second.ClusterChargePerCMfromTrack, dQdx_fromTrack);
1688         if (track_ok)
1689           fillME(iModME->second.ClusterChargePerCMfromOrigin, dQdx_fromOrigin);
1690 
1691         //fill the PGV histo
1692         float PGVmax = cluster->maxCharge();
1693         int PGVposCounter = cluster->maxIndex();
1694         for (int i = int(conf_.getParameter<edm::ParameterSet>("TProfileClusterPGV").getParameter<double>("xmin"));
1695              i < PGVposCounter;
1696              ++i)
1697           fillME(iModME->second.ClusterPGV, i, 0.);
1698         for (auto it = cluster->stripCharges().begin(); it < cluster->stripCharges().end(); ++it) {
1699           fillME(iModME->second.ClusterPGV, PGVposCounter++, (*it) / PGVmax);
1700         }
1701         for (int i = PGVposCounter;
1702              i < int(conf_.getParameter<edm::ParameterSet>("TProfileClusterPGV").getParameter<double>("xmax"));
1703              ++i)
1704           fillME(iModME->second.ClusterPGV, i, 0.);
1705         //end fill the PGV histo
1706       }
1707     }
1708   } else {
1709     if (flag == OffTrack) {
1710       if (MEs.iSubdet != nullptr)
1711         MEs.iSubdet->totNClustersOffTrack++;
1712       //******** TkHistoMaps
1713       if (TkHistoMap_On_) {
1714         uint32_t adet = cluster->detId();
1715         tkhisto_NumOffTrack->add(adet, 1.);
1716         if (charge > 250) {
1717           LogDebug("SiStripMonitorTrack") << "Module firing " << detid << " in Event " << eventNb << std::endl;
1718         }
1719       }
1720       if (TkHistoMap_On_) {
1721         uint32_t adet = cluster->detId();
1722         tkhisto_ClusterWidthOffTrack->fill(adet, cluster->width());
1723         if (noise > 0.0)
1724           tkhisto_NoiseOffTrack->fill(adet, cluster->noiseRescaledByGain());
1725       }
1726     }
1727     // layerMEs
1728     if (MEs.iLayer != nullptr) {
1729       fillME(MEs.iLayer->ClusterGain, clustergain);
1730       fillME(MEs.iLayer->ClusterChargeOffTrack, charge);
1731       fillME(MEs.iLayer->ClusterChargeRawOffTrack, chargeraw);
1732       fillME(MEs.iLayer->ClusterNoiseOffTrack, noise);
1733       fillME(MEs.iLayer->ClusterWidthOffTrack, width);
1734       fillME(MEs.iLayer->ClusterPosOffTrack, position);
1735       fillME(MEs.iLayer->ClusterChargePerCMfromOriginOffTrack, dQdx_fromOrigin);
1736     }
1737     // ringMEs
1738     if (MEs.iRing != nullptr) {
1739       fillME(MEs.iRing->ClusterGain, clustergain);
1740       fillME(MEs.iRing->ClusterChargeOffTrack, charge);
1741       fillME(MEs.iRing->ClusterChargeRawOffTrack, chargeraw);
1742       fillME(MEs.iRing->ClusterNoiseOffTrack, noise);
1743       fillME(MEs.iRing->ClusterWidthOffTrack, width);
1744       fillME(MEs.iRing->ClusterPosOffTrack, position);
1745       fillME(MEs.iRing->ClusterChargePerCMfromOriginOffTrack, dQdx_fromOrigin);
1746     }
1747     // subdetMEs
1748     if (MEs.iSubdet != nullptr) {
1749       fillME(MEs.iSubdet->ClusterGain, clustergain);
1750       fillME(MEs.iSubdet->ClusterChargeOffTrack, charge);
1751       fillME(MEs.iSubdet->ClusterChargeRawOffTrack, chargeraw);
1752       if (noise > 0.0)
1753         fillME(MEs.iSubdet->ClusterStoNOffTrack, StoN);
1754       fillME(MEs.iSubdet->ClusterChargePerCMfromOriginOffTrack, dQdx_fromOrigin);
1755     }
1756   }
1757   return true;
1758 }
1759 //--------------------------------------------------------------------------------