Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-15 22:41:03

0001 // -*- C++ -*-
0002 //
0003 // Package:    Phase2TrackerValidateDigi
0004 // Class:      Phase2TrackerValidateDigi
0005 //
0006 /**\class Phase2TrackerValidateDigi Phase2TrackerValidateDigi.cc 
0007 
0008  Description: Test pixel digis. 
0009 
0010 */
0011 //
0012 // Author: Suchandra Dutta, Gourab Saha, Suvankar Roy Chowdhury, Subir Sarkar
0013 // Date: January 29, 2016
0014 //
0015 // system include files
0016 #include <memory>
0017 #include "Validation/SiTrackerPhase2V/plugins/Phase2TrackerValidateDigi.h"
0018 
0019 #include "FWCore/Framework/interface/MakerMacros.h"
0020 #include "FWCore/Framework/interface/ESWatcher.h"
0021 
0022 #include "FWCore/ServiceRegistry/interface/Service.h"
0023 #include "FWCore/Utilities/interface/InputTag.h"
0024 
0025 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0026 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0027 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0028 #include "Geometry/CommonDetUnit/interface/TrackerGeomDet.h"
0029 #include "Geometry/CommonDetUnit/interface/PixelGeomDetUnit.h"
0030 #include "Geometry/CommonDetUnit/interface/PixelGeomDetType.h"
0031 
0032 #include "DataFormats/Common/interface/DetSetVector.h"
0033 #include "DataFormats/Phase2TrackerDigi/interface/Phase2TrackerDigi.h"
0034 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
0035 #include "DataFormats/SiPixelDigi/interface/PixelDigiCollection.h"
0036 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0037 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0038 
0039 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0040 #include "SimDataFormats/TrackerDigiSimLink/interface/PixelDigiSimLink.h"
0041 
0042 // DQM Histograming
0043 #include "DQMServices/Core/interface/MonitorElement.h"
0044 #include "DQM/SiTrackerPhase2/interface/TrackerPhase2DQMUtil.h"
0045 
0046 using Phase2TrackerGeomDetUnit = PixelGeomDetUnit;
0047 
0048 //
0049 // constructors
0050 //
0051 Phase2TrackerValidateDigi::Phase2TrackerValidateDigi(const edm::ParameterSet& iConfig)
0052     : config_(iConfig),
0053       pixelFlag_(config_.getParameter<bool>("PixelPlotFillingFlag")),
0054       geomType_(config_.getParameter<std::string>("GeometryType")),
0055       otDigiSrc_(config_.getParameter<edm::InputTag>("OuterTrackerDigiSource")),
0056       otDigiSimLinkSrc_(config_.getParameter<edm::InputTag>("OuterTrackerDigiSimLinkSource")),
0057       itPixelDigiSrc_(config_.getParameter<edm::InputTag>("InnerPixelDigiSource")),
0058       itPixelDigiSimLinkSrc_(config_.getParameter<edm::InputTag>("InnerPixelDigiSimLinkSource")),
0059       pSimHitSrc_(config_.getParameter<std::vector<edm::InputTag>>("PSimHitSource")),
0060       simTrackSrc_(config_.getParameter<edm::InputTag>("SimTrackSource")),
0061       simVertexSrc_(config_.getParameter<edm::InputTag>("SimVertexSource")),
0062       otDigiToken_(consumes<edm::DetSetVector<Phase2TrackerDigi>>(otDigiSrc_)),
0063       otDigiSimLinkToken_(consumes<edm::DetSetVector<PixelDigiSimLink>>(otDigiSimLinkSrc_)),
0064       itPixelDigiToken_(consumes<edm::DetSetVector<PixelDigi>>(itPixelDigiSrc_)),
0065       itPixelDigiSimLinkToken_(consumes<edm::DetSetVector<PixelDigiSimLink>>(itPixelDigiSimLinkSrc_)),
0066       simTrackToken_(consumes<edm::SimTrackContainer>(simTrackSrc_)),
0067       simVertexToken_(consumes<edm::SimVertexContainer>(simVertexSrc_)),
0068       geomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>()),
0069       topoToken_(esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>()),
0070       GeVperElectron(3.61E-09),  // 1 electron(3.61eV, 1keV(277e, mod 9/06 d.k.
0071       cval(30.) {
0072   for (const auto& itag : pSimHitSrc_)
0073     simHitTokens_.push_back(consumes<edm::PSimHitContainer>(itag));
0074 
0075   etaCut_ = config_.getParameter<double>("EtaCutOff");
0076   ptCut_ = config_.getParameter<double>("PtCutOff");
0077   tofUpperCut_ = config_.getParameter<double>("TOFUpperCutOff");
0078   tofLowerCut_ = config_.getParameter<double>("TOFLowerCutOff");
0079 
0080   edm::LogInfo("Phase2TrackerValidateDigi") << ">>> Construct Phase2TrackerValidateDigi ";
0081 }
0082 
0083 //
0084 // destructor
0085 //
0086 Phase2TrackerValidateDigi::~Phase2TrackerValidateDigi() {
0087   // do anything here that needs to be done at desctruction time
0088   // (e.g. close files, deallocate resources etc.)
0089   edm::LogInfo("Phase2TrackerValidateDigi") << ">>> Destroy Phase2TrackerValidateDigi ";
0090 }
0091 //
0092 // -- DQM Begin Run
0093 void Phase2TrackerValidateDigi::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0094   edm::ESWatcher<TrackerDigiGeometryRecord> theTkDigiGeomWatcher;
0095   edm::ESHandle<TrackerGeometry> geomHandle;
0096   if (theTkDigiGeomWatcher.check(iSetup)) {
0097     geomHandle = iSetup.getHandle(geomToken_);
0098   }
0099   if (!geomHandle.isValid())
0100     return;
0101   tkGeom_ = &(*geomHandle);
0102 
0103   tTopo_ = &iSetup.getData(topoToken_);
0104 }
0105 //
0106 // -- Analyze
0107 //
0108 void Phase2TrackerValidateDigi::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup) {
0109   //Digis
0110   itdigis_ = &iEvent.get(itPixelDigiToken_);
0111   otdigis_ = &iEvent.get(otDigiToken_);
0112   // DigiSimLink
0113   itSimLink_ = &iEvent.get(itPixelDigiSimLinkToken_);
0114   otSimLink_ = &iEvent.get(otDigiSimLinkToken_);
0115 
0116   // SimTrack
0117   simTracks = iEvent.getHandle(simTrackToken_);
0118   // SimVertex
0119   simVertices = iEvent.getHandle(simVertexToken_);
0120 
0121   // Fil # of SIM Vertices@
0122   nSimVertices->Fill((*simVertices).size());
0123   // Loop over Sim Tracks and Fill relevant histograms
0124   int nTracks = 0;
0125   int nTracksP = 0;
0126   int nTracksS = 0;
0127   for (edm::SimTrackContainer::const_iterator simTrkItr = simTracks->begin(); simTrkItr != simTracks->end();
0128        ++simTrkItr) {
0129     if (simTrkItr->charge() == 0)
0130       continue;
0131     int vtxIndex = simTrkItr->vertIndex();
0132     int vtxParent = -1;
0133     if (vtxIndex > 0) {
0134       SimVertex vtx = (*simVertices)[vtxIndex];
0135       if (!vtx.noParent()) {
0136         int trkId = vtx.parentIndex();
0137         vtxParent = (*simTracks)[matchedSimTrack(simTracks, trkId)].vertIndex();
0138       }
0139     }
0140     int simTk_type = -1;
0141     if (vtxIndex == 0 || vtxParent == 0)
0142       simTk_type = 1;
0143     else
0144       simTk_type = 0;
0145     nTracks++;
0146     if (simTk_type == 1)
0147       nTracksP++;
0148     else
0149       nTracksS++;
0150 
0151     float simTk_pt = simTrkItr->momentum().pt();
0152     float simTk_eta = simTrkItr->momentum().eta();
0153     float simTk_phi = simTrkItr->momentum().phi();
0154 
0155     if (fabs(simTk_eta) < etaCut_)
0156       fillHistogram(SimulatedTrackPt, SimulatedTrackPtP, SimulatedTrackPtS, simTk_pt, simTk_type);
0157     if (simTk_pt > ptCut_)
0158       fillHistogram(SimulatedTrackEta, SimulatedTrackEtaP, SimulatedTrackEtaS, simTk_eta, simTk_type);
0159     if (fabs(simTk_eta) < etaCut_ && simTk_pt > ptCut_)
0160       fillHistogram(SimulatedTrackPhi, SimulatedTrackPhiP, SimulatedTrackPhiS, simTk_phi, simTk_type);
0161 
0162     // initialize
0163     for (auto& it : layerMEs) {
0164       it.second.nDigis = 0;
0165       it.second.nHits = 0;
0166     }
0167     fillSimHitInfo(iEvent, (*simTrkItr));
0168 
0169     int nHitCutoff = 2;
0170     if (pixelFlag_)
0171       nHitCutoff = 1;
0172     for (auto& it : layerMEs) {
0173       DigiMEs& local_mes = it.second;
0174       if (it.second.nHits < nHitCutoff) {
0175         if (std::fabs(simTk_eta) < 1.0)
0176           local_mes.MissedHitTrackPt->Fill(simTk_pt);
0177         if (simTk_pt > ptCut_ && std::fabs(simTk_eta) < 1.0)
0178           local_mes.MissedHitTrackEta->Fill(simTk_eta);
0179         if (std::fabs(simTk_eta) < 1.0 && simTk_pt > ptCut_)
0180           local_mes.MissedHitTrackPhi->Fill(simTk_phi);
0181       }
0182     }
0183   }
0184   nSimulatedTracks->Fill(nTracks);
0185   nSimulatedTracksP->Fill(nTracksP);
0186   nSimulatedTracksS->Fill(nTracksS);
0187   if (pixelFlag_)
0188     fillITPixelBXInfo();
0189   else
0190     fillOTBXInfo();
0191 }
0192 
0193 int Phase2TrackerValidateDigi::fillSimHitInfo(const edm::Event& iEvent, const SimTrack simTrk) {
0194   int totalHits = 0;
0195   unsigned int id = simTrk.trackId();
0196   // Get digis
0197 
0198   for (const auto& itoken : simHitTokens_) {
0199     const auto& simHitHandle = iEvent.getHandle(itoken);
0200     if (!simHitHandle.isValid())
0201       continue;
0202     const edm::PSimHitContainer& simHits = (*simHitHandle.product());
0203     for (edm::PSimHitContainer::const_iterator isim = simHits.begin(); isim != simHits.end(); ++isim) {
0204       if ((*isim).trackId() != id)
0205         continue;
0206       const PSimHit& simHit = (*isim);
0207 
0208       if (!isPrimary(simTrk, simHit))
0209         continue;
0210 
0211       unsigned int rawid = (*isim).detUnitId();
0212       int layer;
0213       if (pixelFlag_)
0214         layer = tTopo_->getITPixelLayerNumber(rawid);
0215       else
0216         layer = tTopo_->getOTLayerNumber(rawid);
0217       if (layer < 0)
0218         continue;
0219       std::string key = getHistoId(rawid, pixelFlag_);
0220       auto pos = layerMEs.find(key);
0221       if (pos == layerMEs.end())
0222         continue;
0223       DigiMEs& local_mes = pos->second;
0224 
0225       const DetId detId(rawid);
0226       float dZ = (*isim).entryPoint().z() - (*isim).exitPoint().z();
0227       if (fabs(dZ) <= 0.01)
0228         continue;
0229 
0230       if (DetId(detId).det() != DetId::Detector::Tracker)
0231         continue;
0232 
0233       const GeomDet* geomDet = tkGeom_->idToDet(detId);
0234       if (!geomDet)
0235         continue;
0236       Global3DPoint pdPos = geomDet->surface().toGlobal(isim->localPosition());
0237 
0238       if (((*isim).tof() - pdPos.mag() / cval) < tofLowerCut_ || ((*isim).tof() - pdPos.mag() / cval) > tofUpperCut_)
0239         continue;
0240 
0241       if (SimulatedXYPositionMap)
0242         SimulatedXYPositionMap->Fill(pdPos.x() * 10., pdPos.y() * 10.);
0243       if (SimulatedRZPositionMap)
0244         SimulatedRZPositionMap->Fill(pdPos.z() * 10., std::hypot(pdPos.x(), pdPos.y()) * 10.);
0245 
0246       const TrackerGeomDet* geomDetUnit(tkGeom_->idToDetUnit(detId));
0247       const Phase2TrackerGeomDetUnit* tkDetUnit = dynamic_cast<const Phase2TrackerGeomDetUnit*>(geomDetUnit);
0248       int nColumns = tkDetUnit->specificTopology().ncolumns();
0249 
0250       float pt = simTrk.momentum().pt();
0251       float eta = simTrk.momentum().eta();
0252       float phi = simTrk.momentum().phi();
0253       totalHits++;
0254       pos->second.nHits++;
0255 
0256       if (local_mes.SimHitDx)
0257         local_mes.SimHitDx->Fill(std::fabs((*isim).entryPoint().x() - (*isim).exitPoint().x()));
0258       if (local_mes.SimHitDy)
0259         local_mes.SimHitDy->Fill(std::fabs((*isim).entryPoint().y() - (*isim).exitPoint().y()));
0260       if (local_mes.SimHitDz)
0261         local_mes.SimHitDz->Fill(std::fabs((*isim).entryPoint().z() - (*isim).exitPoint().z()));
0262 
0263       if (SimulatedTOFEtaMap)
0264         SimulatedTOFEtaMap->Fill(pdPos.eta(), (*isim).timeOfFlight());
0265       if (SimulatedTOFPhiMap)
0266         SimulatedTOFPhiMap->Fill(pdPos.phi(), (*isim).timeOfFlight());
0267       if (SimulatedTOFRMap)
0268         SimulatedTOFRMap->Fill(std::hypot(pdPos.x(), pdPos.y()), (*isim).timeOfFlight());
0269       if (SimulatedTOFZMap)
0270         SimulatedTOFZMap->Fill(pdPos.z(), (*isim).timeOfFlight());
0271 
0272       bool digiFlag;
0273 
0274       if (pixelFlag_)
0275         digiFlag = findITPixelDigi(rawid, id);
0276       else
0277         digiFlag = findOTDigi(rawid, id);
0278 
0279       if (fabs(eta) < etaCut_) {
0280         if (local_mes.SimTrackPt)
0281           local_mes.SimTrackPt->Fill(pt);
0282         if (digiFlag && local_mes.MatchedTrackPt)
0283           local_mes.MatchedTrackPt->Fill(pt);
0284         else if (local_mes.MissedDigiTrackPt)
0285           local_mes.MissedDigiTrackPt->Fill(pt);
0286       }
0287       if (pt > ptCut_) {
0288         if (local_mes.SimTrackEta)
0289           local_mes.SimTrackEta->Fill(eta);
0290         if (digiFlag && local_mes.MatchedTrackEta)
0291           local_mes.MatchedTrackEta->Fill(eta);
0292         else if (local_mes.MissedDigiTrackEta)
0293           local_mes.MissedDigiTrackEta->Fill(eta);
0294       }
0295       if (fabs(eta) < etaCut_ && pt > ptCut_) {
0296         if (local_mes.SimTrackPhi)
0297           local_mes.SimTrackPhi->Fill(phi);
0298         if (digiFlag && local_mes.MatchedTrackPhi)
0299           local_mes.MatchedTrackPhi->Fill(phi);
0300         else if (local_mes.MissedDigiTrackPhi)
0301           local_mes.MissedDigiTrackPhi->Fill(phi);
0302       }
0303       if (digiFlag) {
0304         pos->second.nDigis++;
0305         if (MatchedRZPositionMap)
0306           MatchedRZPositionMap->Fill(pdPos.z() * 10., std::hypot(pdPos.x(), pdPos.y()) * 10.);
0307         if (MatchedXYPositionMap)
0308           MatchedXYPositionMap->Fill(pdPos.x() * 10., pdPos.y() * 10.);
0309         if (nColumns <= 2 && local_mes.MatchedSimHitElossS)
0310           local_mes.MatchedSimHitElossS->Fill((*isim).energyLoss() / GeVperElectron);
0311         else if (local_mes.MatchedSimHitElossP)
0312           local_mes.MatchedSimHitElossP->Fill((*isim).energyLoss() / GeVperElectron);
0313       } else {
0314         if (local_mes.MissedDigiLocalXposVsYPos)
0315           local_mes.MissedDigiLocalXposVsYPos->Fill((*isim).localPosition().x(), (*isim).localPosition().y());
0316         if (local_mes.MissedDigiTimeWindow)
0317           local_mes.MissedDigiTimeWindow->Fill(std::fabs((*isim).timeOfFlight() - pdPos.mag() / cval));
0318         if (nColumns <= 2 && local_mes.MissedDigiSimHitElossS)
0319           local_mes.MissedDigiSimHitElossS->Fill((*isim).energyLoss() / GeVperElectron);
0320         else if (local_mes.MissedDigiSimHitElossP)
0321           local_mes.MissedDigiSimHitElossP->Fill((*isim).energyLoss() / GeVperElectron);
0322       }
0323     }
0324   }
0325   return totalHits;
0326 }
0327 bool Phase2TrackerValidateDigi::findOTDigi(unsigned int detid, unsigned int id) {
0328   bool matched = false;
0329   edm::DetSetVector<Phase2TrackerDigi>::const_iterator DSVIter = otdigis_->find(detid);
0330   if (DSVIter != otdigis_->end()) {
0331     for (edm::DetSet<Phase2TrackerDigi>::const_iterator di = DSVIter->begin(); di != DSVIter->end(); di++) {
0332       int col = di->column();  // column
0333       int row = di->row();     // row
0334       unsigned int channel = Phase2TrackerDigi::pixelToChannel(row, col);
0335       unsigned int simTkId = getSimTrackId(otSimLink_, detid, channel);
0336       if (simTkId == id) {
0337         matched = true;
0338         break;
0339       }
0340     }
0341   }
0342   return matched;
0343 }
0344 bool Phase2TrackerValidateDigi::findITPixelDigi(unsigned int detid, unsigned int id) {
0345   bool matched = false;
0346   edm::DetSetVector<PixelDigi>::const_iterator DSVIter = itdigis_->find(detid);
0347   if (DSVIter != itdigis_->end()) {
0348     for (edm::DetSet<PixelDigi>::const_iterator di = DSVIter->begin(); di != DSVIter->end(); di++) {
0349       int col = di->column();  // column
0350       int row = di->row();     // row
0351       unsigned int channel = PixelDigi::pixelToChannel(row, col);
0352       unsigned int simTkId = getSimTrackId(itSimLink_, detid, channel);
0353       if (simTkId == id) {
0354         matched = true;
0355         break;
0356       }
0357     }
0358   }
0359   return matched;
0360 }
0361 //
0362 // -- Book Histograms
0363 //
0364 void Phase2TrackerValidateDigi::bookHistograms(DQMStore::IBooker& ibooker,
0365                                                edm::Run const& iRun,
0366                                                edm::EventSetup const& iSetup) {
0367   std::string top_folder = config_.getParameter<std::string>("TopFolderName");
0368   std::stringstream folder_name;
0369 
0370   ibooker.cd();
0371   folder_name << top_folder << "/"
0372               << "SimTrackInfo";
0373   ibooker.setCurrentFolder(folder_name.str());
0374 
0375   edm::LogInfo("Phase2TrackerValidateDigi") << " Booking Histograms in : " << folder_name.str();
0376   std::stringstream HistoName;
0377 
0378   HistoName.str("");
0379   HistoName << "NumberOfSimulatedTracks";
0380   nSimulatedTracks = ibooker.book1D(HistoName.str(), HistoName.str(), 501, -0.5, 500.5);
0381 
0382   HistoName.str("");
0383   HistoName << "NumberOfSimulatedTracksP";
0384   nSimulatedTracksP = ibooker.book1D(HistoName.str(), HistoName.str(), 501, -0.5, 500.5);
0385 
0386   HistoName.str("");
0387   HistoName << "NumberOfSimulatedTracksS";
0388   nSimulatedTracksS = ibooker.book1D(HistoName.str(), HistoName.str(), 501, -0.5, 500.5);
0389 
0390   HistoName.str("");
0391   HistoName << "NumberOfSimulatedVertices";
0392   nSimVertices = ibooker.book1D(HistoName.str(), HistoName.str(), 101, -0.5, 100.5);
0393 
0394   edm::ParameterSet Parameters = config_.getParameter<edm::ParameterSet>("TrackPtH");
0395   HistoName.str("");
0396   HistoName << "SimulatedTrackPt";
0397   if (Parameters.getParameter<bool>("switch"))
0398     SimulatedTrackPt = ibooker.book1D(HistoName.str(),
0399                                       HistoName.str(),
0400                                       Parameters.getParameter<int32_t>("Nbins"),
0401                                       Parameters.getParameter<double>("xmin"),
0402                                       Parameters.getParameter<double>("xmax"));
0403   else
0404     SimulatedTrackPt = nullptr;
0405   /*  
0406   HistoName.str("");
0407   HistoName << "SimulatedTrackPt";   
0408   SimulatedTrackPt = ibooker.book1D(HistoName.str(),HistoName.str(),
0409                   Parameters.getParameter<int32_t>("Nbins"),
0410                         Parameters.getParameter<double>("xmin"),
0411                         Parameters.getParameter<double>("xmax");*/
0412   HistoName.str("");
0413   HistoName << "SimulatedTrackPtP";
0414   if (Parameters.getParameter<bool>("switch"))
0415     SimulatedTrackPtP = ibooker.book1D(HistoName.str(),
0416                                        HistoName.str(),
0417                                        Parameters.getParameter<int32_t>("Nbins"),
0418                                        Parameters.getParameter<double>("xmin"),
0419                                        Parameters.getParameter<double>("xmax"));
0420   else
0421     SimulatedTrackPtP = nullptr;
0422   HistoName.str("");
0423   HistoName << "SimulatedTrackPtS";
0424   if (Parameters.getParameter<bool>("switch"))
0425     SimulatedTrackPtS = ibooker.book1D(HistoName.str(),
0426                                        HistoName.str(),
0427                                        Parameters.getParameter<int32_t>("Nbins"),
0428                                        Parameters.getParameter<double>("xmin"),
0429                                        Parameters.getParameter<double>("xmax"));
0430   else
0431     SimulatedTrackPtS = nullptr;
0432 
0433   Parameters = config_.getParameter<edm::ParameterSet>("TrackEtaH");
0434   HistoName.str("");
0435   HistoName << "SimulatedTrackEta";
0436   if (Parameters.getParameter<bool>("switch"))
0437     SimulatedTrackEta = ibooker.book1D(HistoName.str(),
0438                                        HistoName.str(),
0439                                        Parameters.getParameter<int32_t>("Nbins"),
0440                                        Parameters.getParameter<double>("xmin"),
0441                                        Parameters.getParameter<double>("xmax"));
0442   else
0443     SimulatedTrackEta = nullptr;
0444   HistoName.str("");
0445   HistoName << "SimulatedTrackEtaP";
0446   if (Parameters.getParameter<bool>("switch"))
0447     SimulatedTrackEtaP = ibooker.book1D(HistoName.str(),
0448                                         HistoName.str(),
0449                                         Parameters.getParameter<int32_t>("Nbins"),
0450                                         Parameters.getParameter<double>("xmin"),
0451                                         Parameters.getParameter<double>("xmax"));
0452   else
0453     SimulatedTrackEtaP = nullptr;
0454   HistoName.str("");
0455   HistoName << "SimulatedTrackEtaS";
0456   if (Parameters.getParameter<bool>("switch"))
0457     SimulatedTrackEtaS = ibooker.book1D(HistoName.str(),
0458                                         HistoName.str(),
0459                                         Parameters.getParameter<int32_t>("Nbins"),
0460                                         Parameters.getParameter<double>("xmin"),
0461                                         Parameters.getParameter<double>("xmax"));
0462   else
0463     SimulatedTrackEtaS = nullptr;
0464 
0465   Parameters = config_.getParameter<edm::ParameterSet>("TrackPhiH");
0466   HistoName.str("");
0467   HistoName << "SimulatedTrackPhi";
0468   if (Parameters.getParameter<bool>("switch"))
0469     SimulatedTrackPhi = ibooker.book1D(HistoName.str(),
0470                                        HistoName.str(),
0471                                        Parameters.getParameter<int32_t>("Nbins"),
0472                                        Parameters.getParameter<double>("xmin"),
0473                                        Parameters.getParameter<double>("xmax"));
0474   else
0475     SimulatedTrackPhi = nullptr;
0476 
0477   HistoName.str("");
0478   HistoName << "SimulatedTrackPhiP";
0479   if (Parameters.getParameter<bool>("switch"))
0480     SimulatedTrackPhiP = ibooker.book1D(HistoName.str(),
0481                                         HistoName.str(),
0482                                         Parameters.getParameter<int32_t>("Nbins"),
0483                                         Parameters.getParameter<double>("xmin"),
0484                                         Parameters.getParameter<double>("xmax"));
0485   else
0486     SimulatedTrackPhiP = nullptr;
0487 
0488   HistoName.str("");
0489   HistoName << "SimulatedTrackPhiS";
0490   if (Parameters.getParameter<bool>("switch"))
0491     SimulatedTrackPhiS = ibooker.book1D(HistoName.str(),
0492                                         HistoName.str(),
0493                                         Parameters.getParameter<int32_t>("Nbins"),
0494                                         Parameters.getParameter<double>("xmin"),
0495                                         Parameters.getParameter<double>("xmax"));
0496   else
0497     SimulatedTrackPhiS = nullptr;
0498 
0499   Parameters = config_.getParameter<edm::ParameterSet>("XYPositionMapH");
0500   HistoName.str("");
0501   HistoName << "SimulatedXPosVsYPos";
0502   if (Parameters.getParameter<bool>("switch"))
0503     SimulatedXYPositionMap = ibooker.book2D(HistoName.str(),
0504                                             HistoName.str(),
0505                                             Parameters.getParameter<int32_t>("Nxbins"),
0506                                             Parameters.getParameter<double>("xmin"),
0507                                             Parameters.getParameter<double>("xmax"),
0508                                             Parameters.getParameter<int32_t>("Nybins"),
0509                                             Parameters.getParameter<double>("ymin"),
0510                                             Parameters.getParameter<double>("ymax"));
0511   else
0512     SimulatedXYPositionMap = nullptr;
0513 
0514   Parameters = config_.getParameter<edm::ParameterSet>("RZPositionMapH");
0515   HistoName.str("");
0516   HistoName << "SimulatedRPosVsZPos";
0517   if (Parameters.getParameter<bool>("switch"))
0518     SimulatedRZPositionMap = ibooker.book2D(HistoName.str(),
0519                                             HistoName.str(),
0520                                             Parameters.getParameter<int32_t>("Nxbins"),
0521                                             Parameters.getParameter<double>("xmin"),
0522                                             Parameters.getParameter<double>("xmax"),
0523                                             Parameters.getParameter<int32_t>("Nybins"),
0524                                             Parameters.getParameter<double>("ymin"),
0525                                             Parameters.getParameter<double>("ymax"));
0526   else
0527     SimulatedRZPositionMap = nullptr;
0528 
0529   //add TOF maps
0530   Parameters = config_.getParameter<edm::ParameterSet>("TOFEtaMapH");
0531   HistoName.str("");
0532   HistoName << "SimulatedTOFVsEta";
0533   if (Parameters.getParameter<bool>("switch"))
0534     SimulatedTOFEtaMap = ibooker.book2D(HistoName.str(),
0535                                         HistoName.str(),
0536                                         Parameters.getParameter<int32_t>("Nxbins"),
0537                                         Parameters.getParameter<double>("xmin"),
0538                                         Parameters.getParameter<double>("xmax"),
0539                                         Parameters.getParameter<int32_t>("Nybins"),
0540                                         Parameters.getParameter<double>("ymin"),
0541                                         Parameters.getParameter<double>("ymax"));
0542   else
0543     SimulatedTOFEtaMap = nullptr;
0544   Parameters = config_.getParameter<edm::ParameterSet>("TOFPhiMapH");
0545   HistoName.str("");
0546   HistoName << "SimulatedTOFVsPhi";
0547   if (Parameters.getParameter<bool>("switch"))
0548     SimulatedTOFPhiMap = ibooker.book2D(HistoName.str(),
0549                                         HistoName.str(),
0550                                         Parameters.getParameter<int32_t>("Nxbins"),
0551                                         Parameters.getParameter<double>("xmin"),
0552                                         Parameters.getParameter<double>("xmax"),
0553                                         Parameters.getParameter<int32_t>("Nybins"),
0554                                         Parameters.getParameter<double>("ymin"),
0555                                         Parameters.getParameter<double>("ymax"));
0556   else
0557     SimulatedTOFPhiMap = nullptr;
0558   Parameters = config_.getParameter<edm::ParameterSet>("TOFRMapH");
0559   HistoName.str("");
0560   HistoName << "SimulatedTOFVsR";
0561   if (Parameters.getParameter<bool>("switch"))
0562     SimulatedTOFRMap = ibooker.book2D(HistoName.str(),
0563                                       HistoName.str(),
0564                                       Parameters.getParameter<int32_t>("Nxbins"),
0565                                       Parameters.getParameter<double>("xmin"),
0566                                       Parameters.getParameter<double>("xmax"),
0567                                       Parameters.getParameter<int32_t>("Nybins"),
0568                                       Parameters.getParameter<double>("ymin"),
0569                                       Parameters.getParameter<double>("ymax"));
0570   else
0571     SimulatedTOFRMap = nullptr;
0572   Parameters = config_.getParameter<edm::ParameterSet>("TOFZMapH");
0573   HistoName.str("");
0574   HistoName << "SimulatedTOFVsZ";
0575   if (Parameters.getParameter<bool>("switch"))
0576     SimulatedTOFZMap = ibooker.book2D(HistoName.str(),
0577                                       HistoName.str(),
0578                                       Parameters.getParameter<int32_t>("Nxbins"),
0579                                       Parameters.getParameter<double>("xmin"),
0580                                       Parameters.getParameter<double>("xmax"),
0581                                       Parameters.getParameter<int32_t>("Nybins"),
0582                                       Parameters.getParameter<double>("ymin"),
0583                                       Parameters.getParameter<double>("ymax"));
0584   else
0585     SimulatedTOFZMap = nullptr;
0586 
0587   edm::ESWatcher<TrackerDigiGeometryRecord> theTkDigiGeomWatcher;
0588   if (theTkDigiGeomWatcher.check(iSetup)) {
0589     for (auto const& det_u : tkGeom_->detUnits()) {
0590       unsigned int detId_raw = det_u->geographicalId().rawId();
0591       bookLayerHistos(ibooker, detId_raw, pixelFlag_);
0592     }
0593   }
0594   ibooker.cd();
0595   folder_name.str("");
0596   folder_name << top_folder << "/"
0597               << "DigiMonitor";
0598   ibooker.setCurrentFolder(folder_name.str());
0599 
0600   Parameters = config_.getParameter<edm::ParameterSet>("XYPositionMapH");
0601   HistoName.str("");
0602   HistoName << "MatchedSimXPosVsYPos";
0603   if (Parameters.getParameter<bool>("switch"))
0604     MatchedXYPositionMap = ibooker.book2D(HistoName.str(),
0605                                           HistoName.str(),
0606                                           Parameters.getParameter<int32_t>("Nxbins"),
0607                                           Parameters.getParameter<double>("xmin"),
0608                                           Parameters.getParameter<double>("xmax"),
0609                                           Parameters.getParameter<int32_t>("Nybins"),
0610                                           Parameters.getParameter<double>("ymin"),
0611                                           Parameters.getParameter<double>("ymax"));
0612   else
0613     MatchedXYPositionMap = nullptr;
0614 
0615   Parameters = config_.getParameter<edm::ParameterSet>("RZPositionMapH");
0616   HistoName.str("");
0617   HistoName << "MatchedSimRPosVsZPos";
0618   if (Parameters.getParameter<bool>("switch"))
0619     MatchedRZPositionMap = ibooker.book2D(HistoName.str(),
0620                                           HistoName.str(),
0621                                           Parameters.getParameter<int32_t>("Nxbins"),
0622                                           Parameters.getParameter<double>("xmin"),
0623                                           Parameters.getParameter<double>("xmax"),
0624                                           Parameters.getParameter<int32_t>("Nybins"),
0625                                           Parameters.getParameter<double>("ymin"),
0626                                           Parameters.getParameter<double>("ymax"));
0627   else
0628     MatchedRZPositionMap = nullptr;
0629 }
0630 //
0631 // -- Book Layer Histograms
0632 //
0633 void Phase2TrackerValidateDigi::bookLayerHistos(DQMStore::IBooker& ibooker, unsigned int det_id, bool flag) {
0634   int layer;
0635   if (flag)
0636     layer = tTopo_->getITPixelLayerNumber(det_id);
0637   else
0638     layer = tTopo_->getOTLayerNumber(det_id);
0639 
0640   if (layer < 0)
0641     return;
0642 
0643   std::string key = getHistoId(det_id, flag);
0644   std::map<std::string, DigiMEs>::iterator pos = layerMEs.find(key);
0645   if (pos == layerMEs.end()) {
0646     std::string top_folder = config_.getParameter<std::string>("TopFolderName");
0647     std::stringstream folder_name;
0648 
0649     //For endCap: P-type sensors are present only upto ring 10 for discs 1&2 (TEDD-1) and upto ring 7 for discs 3,4&5 (TEDD-2)
0650     bool isPStypeModForTEDD_1 =
0651         (!pixelFlag_ && layer > 100 && tTopo_->tidWheel(det_id) < 3 && tTopo_->tidRing(det_id) <= 10) ? true : false;
0652     bool isPStypeModForTEDD_2 =
0653         (!pixelFlag_ && layer > 100 && tTopo_->tidWheel(det_id) >= 3 && tTopo_->tidRing(det_id) <= 7) ? true : false;
0654 
0655     bool isPtypeSensor =
0656         (flag || (layer < 4 || (layer > 6 && (isPStypeModForTEDD_1 || isPStypeModForTEDD_2)))) ? true : false;
0657 
0658     ibooker.cd();
0659     ibooker.setCurrentFolder(top_folder + "/DigiMonitor/" + key);
0660     edm::LogInfo("Phase2TrackerValidateDigi") << " Booking Histograms in : " << key;
0661 
0662     std::ostringstream HistoName;
0663     DigiMEs local_mes;
0664 
0665     edm::ParameterSet Parameters = config_.getParameter<edm::ParameterSet>("TrackPtH");
0666     HistoName.str("");
0667     HistoName << "SimTrackPt";
0668     if (Parameters.getParameter<bool>("switch"))
0669       local_mes.SimTrackPt = ibooker.book1D(HistoName.str(),
0670                                             HistoName.str(),
0671                                             Parameters.getParameter<int32_t>("Nbins"),
0672                                             Parameters.getParameter<double>("xmin"),
0673                                             Parameters.getParameter<double>("xmax"));
0674     else
0675       local_mes.SimTrackPt = nullptr;
0676     HistoName.str("");
0677     HistoName << "MatchedTrackPt";
0678     if (Parameters.getParameter<bool>("switch"))
0679       local_mes.MatchedTrackPt = ibooker.book1D(HistoName.str(),
0680                                                 HistoName.str(),
0681                                                 Parameters.getParameter<int32_t>("Nbins"),
0682                                                 Parameters.getParameter<double>("xmin"),
0683                                                 Parameters.getParameter<double>("xmax"));
0684     else
0685       local_mes.MatchedTrackPt = nullptr;
0686     HistoName.str("");
0687     HistoName << "MissedHitTrackPt";
0688     if (Parameters.getParameter<bool>("switch"))
0689       local_mes.MissedHitTrackPt = ibooker.book1D(HistoName.str(),
0690                                                   HistoName.str(),
0691                                                   Parameters.getParameter<int32_t>("Nbins"),
0692                                                   Parameters.getParameter<double>("xmin"),
0693                                                   Parameters.getParameter<double>("xmax"));
0694     else
0695       local_mes.MissedHitTrackPt = nullptr;
0696     HistoName.str("");
0697     HistoName << "MissedDigiTrackPt";
0698     if (Parameters.getParameter<bool>("switch"))
0699       local_mes.MissedDigiTrackPt = ibooker.book1D(HistoName.str(),
0700                                                    HistoName.str(),
0701                                                    Parameters.getParameter<int32_t>("Nbins"),
0702                                                    Parameters.getParameter<double>("xmin"),
0703                                                    Parameters.getParameter<double>("xmax"));
0704     else
0705       local_mes.MissedDigiTrackPt = nullptr;
0706 
0707     Parameters = config_.getParameter<edm::ParameterSet>("TrackEtaH");
0708     HistoName.str("");
0709     HistoName << "SimTrackEta";
0710     if (Parameters.getParameter<bool>("switch"))
0711       local_mes.SimTrackEta = ibooker.book1D(HistoName.str(),
0712                                              HistoName.str(),
0713                                              Parameters.getParameter<int32_t>("Nbins"),
0714                                              Parameters.getParameter<double>("xmin"),
0715                                              Parameters.getParameter<double>("xmax"));
0716     else
0717       local_mes.SimTrackEta = nullptr;
0718     HistoName.str("");
0719     HistoName << "MatchedTrackEta";
0720     if (Parameters.getParameter<bool>("switch"))
0721       local_mes.MatchedTrackEta = ibooker.book1D(HistoName.str(),
0722                                                  HistoName.str(),
0723                                                  Parameters.getParameter<int32_t>("Nbins"),
0724                                                  Parameters.getParameter<double>("xmin"),
0725                                                  Parameters.getParameter<double>("xmax"));
0726     else
0727       local_mes.MatchedTrackEta = nullptr;
0728     HistoName.str("");
0729     HistoName << "MissedHitTrackEta";
0730     if (Parameters.getParameter<bool>("switch"))
0731       local_mes.MissedHitTrackEta = ibooker.book1D(HistoName.str(),
0732                                                    HistoName.str(),
0733                                                    Parameters.getParameter<int32_t>("Nbins"),
0734                                                    Parameters.getParameter<double>("xmin"),
0735                                                    Parameters.getParameter<double>("xmax"));
0736     else
0737       local_mes.MissedHitTrackEta = nullptr;
0738     HistoName.str("");
0739     HistoName << "MissedDigiTrackEta";
0740     if (Parameters.getParameter<bool>("switch"))
0741       local_mes.MissedDigiTrackEta = ibooker.book1D(HistoName.str(),
0742                                                     HistoName.str(),
0743                                                     Parameters.getParameter<int32_t>("Nbins"),
0744                                                     Parameters.getParameter<double>("xmin"),
0745                                                     Parameters.getParameter<double>("xmax"));
0746     else
0747       local_mes.MissedDigiTrackEta = nullptr;
0748 
0749     Parameters = config_.getParameter<edm::ParameterSet>("TrackPhiH");
0750     HistoName.str("");
0751     HistoName << "SimTrackPhi";
0752     if (Parameters.getParameter<bool>("switch"))
0753       local_mes.SimTrackPhi = ibooker.book1D(HistoName.str(),
0754                                              HistoName.str(),
0755                                              Parameters.getParameter<int32_t>("Nbins"),
0756                                              Parameters.getParameter<double>("xmin"),
0757                                              Parameters.getParameter<double>("xmax"));
0758     else
0759       local_mes.SimTrackPhi = nullptr;
0760     HistoName.str("");
0761     HistoName << "MatchedTrackPhi";
0762     if (Parameters.getParameter<bool>("switch"))
0763       local_mes.MatchedTrackPhi = ibooker.book1D(HistoName.str(),
0764                                                  HistoName.str(),
0765                                                  Parameters.getParameter<int32_t>("Nbins"),
0766                                                  Parameters.getParameter<double>("xmin"),
0767                                                  Parameters.getParameter<double>("xmax"));
0768     else
0769       local_mes.MatchedTrackPhi = nullptr;
0770     HistoName.str("");
0771     HistoName << "MissedHitTrackPhi";
0772     if (Parameters.getParameter<bool>("switch"))
0773       local_mes.MissedHitTrackPhi = ibooker.book1D(HistoName.str(),
0774                                                    HistoName.str(),
0775                                                    Parameters.getParameter<int32_t>("Nbins"),
0776                                                    Parameters.getParameter<double>("xmin"),
0777                                                    Parameters.getParameter<double>("xmax"));
0778     else
0779       local_mes.MissedHitTrackPhi = nullptr;
0780     HistoName.str("");
0781     HistoName << "MissedDigiTrackPhi";
0782     if (Parameters.getParameter<bool>("switch"))
0783       local_mes.MissedDigiTrackPhi = ibooker.book1D(HistoName.str(),
0784                                                     HistoName.str(),
0785                                                     Parameters.getParameter<int32_t>("Nbins"),
0786                                                     Parameters.getParameter<double>("xmin"),
0787                                                     Parameters.getParameter<double>("xmax"));
0788     else
0789       local_mes.MissedDigiTrackPhi = nullptr;
0790 
0791     Parameters = config_.getParameter<edm::ParameterSet>("SimHitElossH");
0792     if (!flag) {
0793       HistoName.str("");
0794       HistoName << "MatchedSimHitElossS";
0795       if (Parameters.getParameter<bool>("switch"))
0796         local_mes.MatchedSimHitElossS = ibooker.book1D(HistoName.str(),
0797                                                        HistoName.str(),
0798                                                        Parameters.getParameter<int32_t>("Nbins"),
0799                                                        Parameters.getParameter<double>("xmin"),
0800                                                        Parameters.getParameter<double>("xmax"));
0801       else
0802         local_mes.MatchedSimHitElossS = nullptr;
0803       HistoName.str("");
0804       HistoName << "MissedDigiSimHitElossS";
0805       if (Parameters.getParameter<bool>("switch"))
0806         local_mes.MissedDigiSimHitElossS = ibooker.book1D(HistoName.str(),
0807                                                           HistoName.str(),
0808                                                           Parameters.getParameter<int32_t>("Nbins"),
0809                                                           Parameters.getParameter<double>("xmin"),
0810                                                           Parameters.getParameter<double>("xmax"));
0811       else
0812         local_mes.MissedDigiSimHitElossS = nullptr;
0813     }
0814     if (isPtypeSensor) {
0815       HistoName.str("");
0816       HistoName << "MatchedSimHitElossP";
0817       if (Parameters.getParameter<bool>("switch"))
0818         local_mes.MatchedSimHitElossP = ibooker.book1D(HistoName.str(),
0819                                                        HistoName.str(),
0820                                                        Parameters.getParameter<int32_t>("Nbins"),
0821                                                        Parameters.getParameter<double>("xmin"),
0822                                                        Parameters.getParameter<double>("xmax"));
0823       else
0824         local_mes.MatchedSimHitElossP = nullptr;
0825       HistoName.str("");
0826       HistoName << "MissedDigiSimHitElossP";
0827       if (Parameters.getParameter<bool>("switch"))
0828         local_mes.MissedDigiSimHitElossP = ibooker.book1D(HistoName.str(),
0829                                                           HistoName.str(),
0830                                                           Parameters.getParameter<int32_t>("Nbins"),
0831                                                           Parameters.getParameter<double>("xmin"),
0832                                                           Parameters.getParameter<double>("xmax"));
0833       else
0834         local_mes.MissedDigiSimHitElossP = nullptr;
0835     }
0836     Parameters = config_.getParameter<edm::ParameterSet>("SimHitDxH");
0837     HistoName.str("");
0838     HistoName << "SimHitDx";
0839     if (Parameters.getParameter<bool>("switch"))
0840       local_mes.SimHitDx = ibooker.book1D(HistoName.str(),
0841                                           HistoName.str(),
0842                                           Parameters.getParameter<int32_t>("Nbins"),
0843                                           Parameters.getParameter<double>("xmin"),
0844                                           Parameters.getParameter<double>("xmax"));
0845     else
0846       local_mes.SimHitDx = nullptr;
0847 
0848     Parameters = config_.getParameter<edm::ParameterSet>("SimHitDyH");
0849     HistoName.str("");
0850     HistoName << "SimHitDy";
0851     if (Parameters.getParameter<bool>("switch"))
0852       local_mes.SimHitDy = ibooker.book1D(HistoName.str(),
0853                                           HistoName.str(),
0854                                           Parameters.getParameter<int32_t>("Nbins"),
0855                                           Parameters.getParameter<double>("xmin"),
0856                                           Parameters.getParameter<double>("xmax"));
0857     else
0858       local_mes.SimHitDy = nullptr;
0859 
0860     Parameters = config_.getParameter<edm::ParameterSet>("SimHitDzH");
0861     HistoName.str("");
0862     HistoName << "SimHitDz";
0863     if (Parameters.getParameter<bool>("switch"))
0864       local_mes.SimHitDz = ibooker.book1D(HistoName.str(),
0865                                           HistoName.str(),
0866                                           Parameters.getParameter<int32_t>("Nbins"),
0867                                           Parameters.getParameter<double>("xmin"),
0868                                           Parameters.getParameter<double>("xmax"));
0869     else
0870       local_mes.SimHitDz = nullptr;
0871 
0872     HistoName.str("");
0873     HistoName << "BunchXingWindow";
0874     local_mes.BunchXTimeBin = ibooker.book1D(HistoName.str(), HistoName.str(), 8, -5.5, 2.5);
0875 
0876     HistoName.str("");
0877     HistoName << "FractionOfOOTPUDigi";
0878     local_mes.FractionOfOOTDigis = ibooker.bookProfile(HistoName.str(), HistoName.str(), 8, -5.5, 2.5, 0., 1.0, "s");
0879 
0880     HistoName.str("");
0881     HistoName << "MissedDigiLocalXPosvsYPos";
0882     local_mes.MissedDigiLocalXposVsYPos =
0883         ibooker.book2D(HistoName.str(), HistoName.str(), 130, -6.5, 6.5, 130, -6.5, 6.5);
0884 
0885     Parameters = config_.getParameter<edm::ParameterSet>("TOFEtaMapH");
0886     HistoName.str("");
0887     HistoName << "MissedDigiTimeWindow";
0888     if (Parameters.getParameter<bool>("switch"))
0889       local_mes.MissedDigiTimeWindow = ibooker.book1D(HistoName.str(), HistoName.str(), 100, -0.5, 49.5);
0890     else
0891       local_mes.MissedDigiTimeWindow = nullptr;
0892     local_mes.nDigis = 0;
0893     layerMEs.insert(std::make_pair(key, local_mes));
0894   }
0895 }
0896 //
0897 // -- Get SimTrack Id
0898 //
0899 unsigned int Phase2TrackerValidateDigi::getSimTrackId(const edm::DetSetVector<PixelDigiSimLink>* simLinks,
0900                                                       const DetId& detId,
0901                                                       unsigned int& channel) {
0902   edm::DetSetVector<PixelDigiSimLink>::const_iterator isearch = simLinks->find(detId);
0903 
0904   unsigned int simTrkId(0);
0905   if (isearch == simLinks->end())
0906     return simTrkId;
0907 
0908   edm::DetSet<PixelDigiSimLink> link_detset = (*simLinks)[detId];
0909   // Loop over DigiSimLink in this det unit
0910   int iSimLink = 0;
0911   for (edm::DetSet<PixelDigiSimLink>::const_iterator it = link_detset.data.begin(); it != link_detset.data.end();
0912        it++, iSimLink++) {
0913     if (channel == it->channel()) {
0914       simTrkId = it->SimTrackId();
0915       break;
0916     }
0917   }
0918   return simTrkId;
0919 }
0920 void Phase2TrackerValidateDigi::fillOTBXInfo() {
0921   for (typename edm::DetSetVector<PixelDigiSimLink>::const_iterator DSViter = otSimLink_->begin();
0922        DSViter != otSimLink_->end();
0923        DSViter++) {
0924     unsigned int rawid = DSViter->id;
0925     DetId detId(rawid);
0926     if (DetId(detId).det() != DetId::Detector::Tracker)
0927       continue;
0928     int layer = tTopo_->getOTLayerNumber(rawid);
0929     if (layer < 0)
0930       continue;
0931     bool flag_ = false;
0932     std::string key = getHistoId(rawid, flag_);
0933     std::map<std::string, DigiMEs>::iterator pos = layerMEs.find(key);
0934     if (pos == layerMEs.end())
0935       continue;
0936     DigiMEs& local_mes = pos->second;
0937     int tot_digi = 0;
0938     std::map<int, float> bxMap;
0939     for (typename edm::DetSet<PixelDigiSimLink>::const_iterator di = DSViter->begin(); di != DSViter->end(); di++) {
0940       tot_digi++;
0941       int bx = di->eventId().bunchCrossing();
0942       std::map<int, float>::iterator ic = bxMap.find(bx);
0943       if (ic == bxMap.end())
0944         bxMap[bx] = 1.0;
0945       else
0946         bxMap[bx] += 1.0;
0947     }
0948     for (const auto& v : bxMap) {
0949       if (tot_digi) {
0950         local_mes.BunchXTimeBin->Fill(v.first, v.second);
0951         local_mes.FractionOfOOTDigis->Fill(v.first, v.second / tot_digi);
0952       }
0953     }
0954   }
0955 }
0956 void Phase2TrackerValidateDigi::fillITPixelBXInfo() {
0957   for (typename edm::DetSetVector<PixelDigiSimLink>::const_iterator DSViter = itSimLink_->begin();
0958        DSViter != itSimLink_->end();
0959        DSViter++) {
0960     unsigned int rawid = DSViter->id;
0961     DetId detId(rawid);
0962     if (DetId(detId).det() != DetId::Detector::Tracker)
0963       continue;
0964     int layer = tTopo_->getITPixelLayerNumber(rawid);
0965     if (layer < 0)
0966       continue;
0967     bool flag_ = true;
0968     std::string key = getHistoId(rawid, flag_);
0969     std::map<std::string, DigiMEs>::iterator pos = layerMEs.find(key);
0970     if (pos == layerMEs.end())
0971       continue;
0972     DigiMEs& local_mes = pos->second;
0973     int tot_digi = 0;
0974     std::map<int, float> bxMap;
0975     for (typename edm::DetSet<PixelDigiSimLink>::const_iterator di = DSViter->begin(); di != DSViter->end(); di++) {
0976       tot_digi++;
0977       int bx = di->eventId().bunchCrossing();
0978       std::map<int, float>::iterator ic = bxMap.find(bx);
0979       if (ic == bxMap.end())
0980         bxMap[bx] = 1.0;
0981       else
0982         bxMap[bx] += 1.0;
0983     }
0984     for (const auto& v : bxMap) {
0985       if (tot_digi) {
0986         local_mes.BunchXTimeBin->Fill(v.first, v.second);
0987         local_mes.FractionOfOOTDigis->Fill(v.first, v.second / tot_digi);
0988       }
0989     }
0990   }
0991 }
0992 //
0993 // -- Get Matched SimTrack
0994 //
0995 int Phase2TrackerValidateDigi::matchedSimTrack(edm::Handle<edm::SimTrackContainer>& SimTk, unsigned int simTrkId) {
0996   edm::SimTrackContainer sim_tracks = (*SimTk.product());
0997   for (unsigned int it = 0; it < sim_tracks.size(); it++) {
0998     if (sim_tracks[it].trackId() == simTrkId) {
0999       return it;
1000     }
1001   }
1002   return -1;
1003 }
1004 //
1005 //  -- Check if the SimTrack is _Primary or not
1006 //
1007 bool Phase2TrackerValidateDigi::isPrimary(const SimTrack& simTrk, const PSimHit& simHit) {
1008   bool retval = false;
1009   unsigned int trkId = simTrk.trackId();
1010   if (trkId != simHit.trackId())
1011     return retval;
1012   int vtxIndex = simTrk.vertIndex();
1013   int ptype = simHit.processType();
1014   if ((vtxIndex == 0) && (ptype == 0))
1015     retval = true;
1016   return retval;
1017 }
1018 //
1019 // -- Fill Histogram
1020 //
1021 void Phase2TrackerValidateDigi::fillHistogram(
1022     MonitorElement* th1, MonitorElement* th2, MonitorElement* th3, float val, int primary) {
1023   if (th1)
1024     th1->Fill(val);
1025   if (th2 && primary == 1)
1026     th2->Fill(val);
1027   if (th3 && primary != 1)
1028     th3->Fill(val);
1029 }
1030 //
1031 // -- Fill NHit per Layer Histogram [Need to work on!!!]
1032 //
1033 /*
1034 void Phase2TrackerValidateDigi::fillHitsPerTrack() {
1035   for (const auto& it : layerMEs) {
1036     const DigiMEs& local_mes = it.second;
1037     unsigned int layer = it.first;
1038     int lval;
1039     if (layer < 10)
1040       lval = layer;
1041     else if (layer / 100 == 1)
1042       lval = 100 - (layer + 10);
1043     else if (layer / 100 == 2)
1044       lval = (layer + 10) - 200;
1045     else
1046       lval = 0;
1047     nSimHitsPerTrack->Fill(lval, local_mes.nHits);
1048   }
1049 }
1050 */
1051 std::string Phase2TrackerValidateDigi::getHistoId(uint32_t det_id, bool flag) {
1052   if (flag)
1053     return phase2tkutil::getITHistoId(det_id, tTopo_);
1054   else
1055     return phase2tkutil::getOTHistoId(det_id, tTopo_);
1056 }
1057 
1058 //define this as a plug-in
1059 DEFINE_FWK_MODULE(Phase2TrackerValidateDigi);