Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-09-11 04:32:41

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