Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-04-11 22:43:44

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