Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-01-24 01:11:32

0001 #include "DQMServices/Core/interface/DQMEDAnalyzer.h"
0002 #include "DQMServices/Core/interface/DQMStore.h"
0003 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0004 #include "DataFormats/BeamSpot/interface/BeamSpot.h"
0005 #include "DataFormats/Common/interface/DetSetVectorNew.h"
0006 #include "DataFormats/Common/interface/Handle.h"
0007 #include "DataFormats/DetId/interface/DetId.h"
0008 #include "DataFormats/TrackReco/interface/Track.h"
0009 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0010 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0011 #include "DataFormats/TrackerRecHit2D/interface/BaseTrackerRecHit.h"
0012 #include "DataFormats/TrackerRecHit2D/interface/OmniClusterRef.h"
0013 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
0014 #include "DataFormats/VertexReco/interface/Vertex.h"
0015 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0016 #include "DataFormats/VertexReco/interface/VertexFwd.h"
0017 #include "FWCore/Framework/interface/ESHandle.h"
0018 #include "FWCore/Framework/interface/Event.h"
0019 #include "FWCore/Framework/interface/Frameworkfwd.h"
0020 #include "FWCore/Framework/interface/MakerMacros.h"
0021 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0022 #include "FWCore/ServiceRegistry/interface/Service.h"
0023 #include "FWCore/ServiceRegistry/interface/Service.h"
0024 #include "FWCore/Utilities/interface/InputTag.h"
0025 #include "Geometry/CommonDetUnit/interface/GluedGeomDet.h"
0026 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0027 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0028 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0029 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0030 #include "RecoLocalTracker/SiStripClusterizer/interface/SiStripClusterInfo.h"
0031 #include "SimDataFormats/PileupSummaryInfo/interface/PileupSummaryInfo.h"
0032 
0033 #include "TFile.h"
0034 #include "TH1.h"
0035 #include "TMath.h"
0036 #include "TPRegexp.h"
0037 
0038 #include <string>
0039 #include <vector>
0040 #include <map>
0041 #include <set>
0042 
0043 class StandaloneTrackMonitor : public DQMEDAnalyzer {
0044 public:
0045   StandaloneTrackMonitor(const edm::ParameterSet&);
0046 
0047 protected:
0048   void analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) override;
0049   void processHit(const TrackingRecHit& recHit, edm::EventSetup const& iSetup, double wfac = 1);
0050   void processClusters(edm::Event const& iEvent, edm::EventSetup const& iSetup, double wfac = 1);
0051   void addClusterToMap(uint32_t detid, const SiStripCluster* cluster);
0052   void bookHistograms(DQMStore::IBooker&, edm::Run const&, edm::EventSetup const&) override;
0053   void dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) override;
0054 
0055 private:
0056   edm::ParameterSet parameters_;
0057 
0058   std::string moduleName_;
0059   std::string folderName_;
0060   const edm::InputTag trackTag_;
0061   const edm::InputTag bsTag_;
0062   const edm::InputTag vertexTag_;
0063   const edm::InputTag puSummaryTag_;
0064   const edm::InputTag clusterTag_;
0065   const edm::EDGetTokenT<reco::TrackCollection> trackToken_;
0066   const edm::EDGetTokenT<reco::BeamSpot> bsToken_;
0067   const edm::EDGetTokenT<reco::VertexCollection> vertexToken_;
0068   const edm::EDGetTokenT<std::vector<PileupSummaryInfo> > puSummaryToken_;
0069   const edm::EDGetTokenT<edmNew::DetSetVector<SiStripCluster> > clusterToken_;
0070 
0071   const std::string trackQuality_;
0072   SiStripClusterInfo siStripClusterInfo_;
0073   const bool doPUCorrection_;
0074   const bool isMC_;
0075   const bool haveAllHistograms_;
0076   const std::string puScaleFactorFile_;
0077   const bool verbose_;
0078 
0079   MonitorElement* trackEtaH_;
0080   MonitorElement* trackEtaerrH_;
0081   MonitorElement* trackCosThetaH_;
0082   MonitorElement* trackThetaerrH_;
0083   MonitorElement* trackPhiH_;
0084   MonitorElement* trackPhierrH_;
0085   MonitorElement* trackPH_;
0086   MonitorElement* trackPtH_;
0087   MonitorElement* trackPtUpto2GeVH_;
0088   MonitorElement* trackPtOver10GeVH_;
0089   MonitorElement* trackPterrH_;
0090   MonitorElement* trackqOverpH_;
0091   MonitorElement* trackqOverperrH_;
0092   MonitorElement* trackChargeH_;
0093   MonitorElement* trackChi2H_;
0094   MonitorElement* tracknDOFH_;
0095   MonitorElement* trackd0H_;
0096   MonitorElement* trackChi2bynDOFH_;
0097 
0098   MonitorElement* nlostHitsH_;
0099   MonitorElement* nvalidTrackerHitsH_;
0100   MonitorElement* nvalidPixelHitsH_;
0101   MonitorElement* nvalidStripHitsH_;
0102   MonitorElement* trkLayerwithMeasurementH_;
0103   MonitorElement* pixelLayerwithMeasurementH_;
0104   MonitorElement* stripLayerwithMeasurementH_;
0105 
0106   MonitorElement* beamSpotXYposH_;
0107   MonitorElement* beamSpotXYposerrH_;
0108   MonitorElement* beamSpotZposH_;
0109   MonitorElement* beamSpotZposerrH_;
0110 
0111   MonitorElement* vertexXposH_;
0112   MonitorElement* vertexYposH_;
0113   MonitorElement* vertexZposH_;
0114   MonitorElement* nVertexH_;
0115 
0116   MonitorElement* nPixBarrelH_;
0117   MonitorElement* nPixEndcapH_;
0118   MonitorElement* nStripTIBH_;
0119   MonitorElement* nStripTOBH_;
0120   MonitorElement* nStripTECH_;
0121   MonitorElement* nStripTIDH_;
0122   MonitorElement* nTracksH_;
0123 
0124   // MC only
0125   MonitorElement* bunchCrossingH_;
0126   MonitorElement* nPUH_;
0127   MonitorElement* trueNIntH_;
0128 
0129   // Exclusive Quantities
0130   MonitorElement* nHitsVspTH_;
0131   MonitorElement* nHitsVsnVtxH_;
0132   MonitorElement* nHitsVsEtaH_;
0133   MonitorElement* nHitsVsCosThetaH_;
0134   MonitorElement* nHitsVsPhiH_;
0135   MonitorElement* nLostHitsVspTH_;
0136   MonitorElement* nLostHitsVsEtaH_;
0137   MonitorElement* nLostHitsVsCosThetaH_;
0138   MonitorElement* nLostHitsVsPhiH_;
0139 
0140   MonitorElement* hOnTrkClusChargeThinH_;
0141   MonitorElement* hOnTrkClusWidthThinH_;
0142   MonitorElement* hOnTrkClusChargeThickH_;
0143   MonitorElement* hOnTrkClusWidthThickH_;
0144 
0145   MonitorElement* hOffTrkClusChargeThinH_;
0146   MonitorElement* hOffTrkClusWidthThinH_;
0147   MonitorElement* hOffTrkClusChargeThickH_;
0148   MonitorElement* hOffTrkClusWidthThickH_;
0149 
0150   unsigned long long m_cacheID_;
0151 
0152   std::vector<float> vpu_;
0153   std::map<uint32_t, std::set<const SiStripCluster*> > clusterMap_;
0154   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
0155   const TrackerGeometry* tkGeom_ = nullptr;
0156 };
0157 
0158 // -----------------------------
0159 // constructors and destructor
0160 // -----------------------------
0161 StandaloneTrackMonitor::StandaloneTrackMonitor(const edm::ParameterSet& ps)
0162     : parameters_(ps),
0163       moduleName_(parameters_.getUntrackedParameter<std::string>("moduleName", "StandaloneTrackMonitor")),
0164       folderName_(parameters_.getUntrackedParameter<std::string>("folderName", "highPurityTracks")),
0165       trackTag_(parameters_.getUntrackedParameter<edm::InputTag>("trackInputTag", edm::InputTag("generalTracks"))),
0166       bsTag_(parameters_.getUntrackedParameter<edm::InputTag>("offlineBeamSpot", edm::InputTag("offlineBeamSpot"))),
0167       vertexTag_(
0168           parameters_.getUntrackedParameter<edm::InputTag>("vertexTag", edm::InputTag("offlinePrimaryVertices"))),
0169       puSummaryTag_(parameters_.getUntrackedParameter<edm::InputTag>("puTag", edm::InputTag("addPileupInfo"))),
0170       clusterTag_(parameters_.getUntrackedParameter<edm::InputTag>("clusterTag", edm::InputTag("siStripClusters"))),
0171       trackToken_(consumes<reco::TrackCollection>(trackTag_)),
0172       bsToken_(consumes<reco::BeamSpot>(bsTag_)),
0173       vertexToken_(consumes<reco::VertexCollection>(vertexTag_)),
0174       puSummaryToken_(consumes<std::vector<PileupSummaryInfo> >(puSummaryTag_)),
0175       clusterToken_(consumes<edmNew::DetSetVector<SiStripCluster> >(clusterTag_)),
0176       trackQuality_(parameters_.getUntrackedParameter<std::string>("trackQuality", "highPurity")),
0177       siStripClusterInfo_(consumesCollector()),
0178       doPUCorrection_(parameters_.getUntrackedParameter<bool>("doPUCorrection", false)),
0179       isMC_(parameters_.getUntrackedParameter<bool>("isMC", false)),
0180       haveAllHistograms_(parameters_.getUntrackedParameter<bool>("haveAllHistograms", false)),
0181       puScaleFactorFile_(
0182           parameters_.getUntrackedParameter<std::string>("puScaleFactorFile", "PileupScaleFactor_run203002.root")),
0183       verbose_(parameters_.getUntrackedParameter<bool>("verbose", false)),
0184       geomToken_(esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>()) {
0185   trackEtaH_ = nullptr;
0186   trackEtaerrH_ = nullptr;
0187   trackCosThetaH_ = nullptr;
0188   trackThetaerrH_ = nullptr;
0189   trackPhiH_ = nullptr;
0190   trackPhierrH_ = nullptr;
0191   trackPH_ = nullptr;
0192   trackPtH_ = nullptr;
0193   trackPtUpto2GeVH_ = nullptr;
0194   trackPtOver10GeVH_ = nullptr;
0195   trackPterrH_ = nullptr;
0196   trackqOverpH_ = nullptr;
0197   trackqOverperrH_ = nullptr;
0198   trackChargeH_ = nullptr;
0199   nlostHitsH_ = nullptr;
0200   nvalidTrackerHitsH_ = nullptr;
0201   nvalidPixelHitsH_ = nullptr;
0202   nvalidStripHitsH_ = nullptr;
0203   trkLayerwithMeasurementH_ = nullptr;
0204   pixelLayerwithMeasurementH_ = nullptr;
0205   stripLayerwithMeasurementH_ = nullptr;
0206   beamSpotXYposH_ = nullptr;
0207   beamSpotXYposerrH_ = nullptr;
0208   beamSpotZposH_ = nullptr;
0209   beamSpotZposerrH_ = nullptr;
0210   trackChi2H_ = nullptr;
0211   tracknDOFH_ = nullptr;
0212   trackd0H_ = nullptr;
0213   trackChi2bynDOFH_ = nullptr;
0214   vertexXposH_ = nullptr;
0215   vertexYposH_ = nullptr;
0216   vertexZposH_ = nullptr;
0217 
0218   nPixBarrelH_ = nullptr;
0219   nPixEndcapH_ = nullptr;
0220   nStripTIBH_ = nullptr;
0221   nStripTOBH_ = nullptr;
0222   nStripTECH_ = nullptr;
0223   nStripTIDH_ = nullptr;
0224   nTracksH_ = nullptr;
0225 
0226   // for MC only
0227   nVertexH_ = nullptr;
0228   bunchCrossingH_ = nullptr;
0229   nPUH_ = nullptr;
0230   trueNIntH_ = nullptr;
0231 
0232   nHitsVspTH_ = nullptr;
0233   nHitsVsEtaH_ = nullptr;
0234   nHitsVsCosThetaH_ = nullptr;
0235   nHitsVsPhiH_ = nullptr;
0236   nHitsVsnVtxH_ = nullptr;
0237   nLostHitsVspTH_ = nullptr;
0238   nLostHitsVsEtaH_ = nullptr;
0239   nLostHitsVsCosThetaH_ = nullptr;
0240   nLostHitsVsPhiH_ = nullptr;
0241 
0242   hOnTrkClusChargeThinH_ = nullptr;
0243   hOnTrkClusWidthThinH_ = nullptr;
0244   hOnTrkClusChargeThickH_ = nullptr;
0245   hOnTrkClusWidthThickH_ = nullptr;
0246 
0247   hOffTrkClusChargeThinH_ = nullptr;
0248   hOffTrkClusWidthThinH_ = nullptr;
0249   hOffTrkClusChargeThickH_ = nullptr;
0250   hOffTrkClusWidthThickH_ = nullptr;
0251 
0252   // Read pileup weight factors
0253   if (isMC_ && doPUCorrection_) {
0254     vpu_.clear();
0255     TFile* f1 = TFile::Open(puScaleFactorFile_.c_str());
0256     TH1F* h1 = dynamic_cast<TH1F*>(f1->Get("pileupweight"));
0257     for (int i = 1; i <= h1->GetNbinsX(); ++i)
0258       vpu_.push_back(h1->GetBinContent(i));
0259     f1->Close();
0260   }
0261 }
0262 
0263 void StandaloneTrackMonitor::dqmBeginRun(const edm::Run& iRun, const edm::EventSetup& iSetup) {
0264   tkGeom_ = &(iSetup.getData(geomToken_));
0265 }
0266 
0267 void StandaloneTrackMonitor::bookHistograms(DQMStore::IBooker& iBook,
0268                                             edm::Run const& iRun,
0269                                             edm::EventSetup const& iSetup) {
0270   edm::ParameterSet TrackEtaHistoPar = parameters_.getParameter<edm::ParameterSet>("trackEtaH");
0271   edm::ParameterSet TrackPtHistoPar = parameters_.getParameter<edm::ParameterSet>("trackPtH");
0272 
0273   std::string currentFolder = moduleName_ + "/" + folderName_;
0274   iBook.setCurrentFolder(currentFolder);
0275 
0276   // The following are common with the official tool
0277   if (haveAllHistograms_) {
0278     if (!trackEtaH_)
0279       trackEtaH_ = iBook.book1D("trackEta",
0280                                 "Track Eta",
0281                                 TrackEtaHistoPar.getParameter<int32_t>("Xbins"),
0282                                 TrackEtaHistoPar.getParameter<double>("Xmin"),
0283                                 TrackEtaHistoPar.getParameter<double>("Xmax"));
0284     if (!trackEtaerrH_)
0285       trackEtaerrH_ = iBook.book1D("trackEtaerr", "Track Eta Error", 50, 0.0, 1.0);
0286     if (!trackCosThetaH_)
0287       trackCosThetaH_ = iBook.book1D("trackCosTheta", "Track Cos(Theta)", 50, -1.0, 1.0);
0288     if (!trackThetaerrH_)
0289       trackThetaerrH_ = iBook.book1D("trackThetaerr", "Track Theta Error", 50, 0.0, 1.0);
0290     if (!trackPhiH_)
0291       trackPhiH_ = iBook.book1D("trackPhi", "Track Phi", 70, -3.5, 3.5);
0292     if (!trackPhierrH_)
0293       trackPhierrH_ = iBook.book1D("trackPhierr", "Track Phi Error", 50, 0.0, 1.0);
0294 
0295     if (!trackPH_)
0296       trackPH_ = iBook.book1D("trackP", "Track 4-momentum", 50, 0.0, 10.0);
0297     if (!trackPtH_)
0298       trackPtH_ = iBook.book1D("trackPt",
0299                                "Track Pt",
0300                                TrackPtHistoPar.getParameter<int32_t>("Xbins"),
0301                                TrackPtHistoPar.getParameter<double>("Xmin"),
0302                                TrackPtHistoPar.getParameter<double>("Xmax"));
0303     if (!trackPtUpto2GeVH_)
0304       trackPtUpto2GeVH_ = iBook.book1D("trackPtUpto2GeV", "Track Pt upto 2GeV", 100, 0, 2.0);
0305     if (!trackPtOver10GeVH_)
0306       trackPtOver10GeVH_ = iBook.book1D("trackPtOver10GeV", "Track Pt greater than 10 GeV", 100, 0, 100.0);
0307     if (!trackPterrH_)
0308       trackPterrH_ = iBook.book1D("trackPterr", "Track Pt Error", 100, 0.0, 100.0);
0309     if (!trackqOverpH_)
0310       trackqOverpH_ = iBook.book1D("trackqOverp", "q Over p", 40, -10.0, 10.0);
0311     if (!trackqOverperrH_)
0312       trackqOverperrH_ = iBook.book1D("trackqOverperr", "q Over p Error", 50, 0.0, 25.0);
0313     if (!trackChargeH_)
0314       trackChargeH_ = iBook.book1D("trackCharge", "Track Charge", 50, -5, 5);
0315     if (!trackChi2H_)
0316       trackChi2H_ = iBook.book1D("trackChi2", "Chi2", 100, 0.0, 100.0);
0317     if (!tracknDOFH_)
0318       tracknDOFH_ = iBook.book1D("tracknDOF", "nDOF", 100, 0.0, 100.0);
0319     if (!trackd0H_)
0320       trackd0H_ = iBook.book1D("trackd0", "Track d0", 100, -1, 1);
0321     if (!trackChi2bynDOFH_)
0322       trackChi2bynDOFH_ = iBook.book1D("trackChi2bynDOF", "Chi2 Over nDOF", 100, 0.0, 10.0);
0323 
0324     if (!nlostHitsH_)
0325       nlostHitsH_ = iBook.book1D("nlostHits", "No. of Lost Hits", 10, 0.0, 10.0);
0326     if (!nvalidTrackerHitsH_)
0327       nvalidTrackerHitsH_ = iBook.book1D("nvalidTrackerhits", "No. of Valid Tracker Hits", 35, 0.0, 35.0);
0328     if (!nvalidPixelHitsH_)
0329       nvalidPixelHitsH_ = iBook.book1D("nvalidPixelHits", "No. of Valid Hits in Pixel", 10, 0.0, 10.0);
0330     if (!nvalidStripHitsH_)
0331       nvalidStripHitsH_ = iBook.book1D("nvalidStripHits", "No.of Valid Hits in Strip", 25, 0.0, 25.0);
0332 
0333     if (!trkLayerwithMeasurementH_)
0334       trkLayerwithMeasurementH_ = iBook.book1D("trkLayerwithMeasurement", "No. of Layers per Track", 25, 0.0, 25.0);
0335     if (!pixelLayerwithMeasurementH_)
0336       pixelLayerwithMeasurementH_ =
0337           iBook.book1D("pixelLayerwithMeasurement", "No. of Pixel Layers per Track", 10, 0.0, 10.0);
0338     if (!stripLayerwithMeasurementH_)
0339       stripLayerwithMeasurementH_ =
0340           iBook.book1D("stripLayerwithMeasurement", "No. of Strip Layers per Track", 20, 0.0, 20.0);
0341 
0342     if (!beamSpotXYposH_)
0343       beamSpotXYposH_ = iBook.book1D("beamSpotXYpos", "XY position of beam spot", 40, -4.0, 4.0);
0344     if (!beamSpotXYposerrH_)
0345       beamSpotXYposerrH_ = iBook.book1D("beamSpotXYposerr", "Error in XY position of beam spot", 20, 0.0, 4.0);
0346     if (!beamSpotZposH_)
0347       beamSpotZposH_ = iBook.book1D("beamSpotZpos", "Z position of beam spot", 100, -20.0, 20.0);
0348     if (!beamSpotZposerrH_)
0349       beamSpotZposerrH_ = iBook.book1D("beamSpotZposerr", "Error in Z position of beam spot", 50, 0.0, 5.0);
0350 
0351     if (!vertexXposH_)
0352       vertexXposH_ = iBook.book1D("vertexXpos", "Vertex X position", 50, -1.0, 1.0);
0353     if (!vertexYposH_)
0354       vertexYposH_ = iBook.book1D("vertexYpos", "Vertex Y position", 50, -1.0, 1.0);
0355     if (!vertexZposH_)
0356       vertexZposH_ = iBook.book1D("vertexZpos", "Vertex Z position", 100, -20.0, 20.0);
0357     if (!nVertexH_)
0358       nVertexH_ = iBook.book1D("nVertex", "# of vertices", 60, -0.5, 59.5);
0359 
0360     if (!nPixBarrelH_)
0361       nPixBarrelH_ = iBook.book1D("nHitPixelBarrel", "No. of hits in Pixel Barrel per Track", 20, 0, 20.0);
0362     if (!nPixEndcapH_)
0363       nPixEndcapH_ = iBook.book1D("nHitPixelEndcap", "No. of hits in Pixel Endcap per Track", 20, 0, 20.0);
0364     if (!nStripTIBH_)
0365       nStripTIBH_ = iBook.book1D("nHitStripTIB", "No. of hits in Strip TIB per Track", 30, 0, 30.0);
0366     if (!nStripTOBH_)
0367       nStripTOBH_ = iBook.book1D("nHitStripTOB", "No. of hits in Strip TOB per Track", 30, 0, 30.0);
0368     if (!nStripTECH_)
0369       nStripTECH_ = iBook.book1D("nHitStripTEC", "No. of hits in Strip TEC per Track", 30, 0, 30.0);
0370     if (!nStripTIDH_)
0371       nStripTIDH_ = iBook.book1D("nHitStripTID", "No. of hits in Strip TID per Tracks", 30, 0, 30.0);
0372 
0373     if (!nTracksH_)
0374       nTracksH_ = iBook.book1D("nTracks", "No. of Tracks", 100, -0.5, 999.5);
0375   }
0376   if (isMC_) {
0377     if (!bunchCrossingH_)
0378       bunchCrossingH_ = iBook.book1D("bunchCrossing", "Bunch Crosssing", 60, 0, 60.0);
0379     if (!nPUH_)
0380       nPUH_ = iBook.book1D("nPU", "No of Pileup", 60, 0, 60.0);
0381     if (!trueNIntH_)
0382       trueNIntH_ = iBook.book1D("trueNInt", "True no of Interactions", 60, 0, 60.0);
0383   }
0384   // Exclusive histograms
0385   if (!nHitsVspTH_)
0386     nHitsVspTH_ = iBook.bookProfile("nHitsVspT",
0387                                     "Number of Hits Vs pT",
0388                                     TrackPtHistoPar.getParameter<int32_t>("Xbins"),
0389                                     TrackPtHistoPar.getParameter<double>("Xmin"),
0390                                     TrackPtHistoPar.getParameter<double>("Xmax"),
0391                                     0.0,
0392                                     0.0,
0393                                     "g");
0394   if (!nHitsVsnVtxH_)
0395     nHitsVsnVtxH_ = iBook.bookProfile("nHitsVsnVtx", "Number of Hits Vs Number of Vertex", 100, 0.0, 50, 0.0, 0.0, "g");
0396   if (!nHitsVsEtaH_)
0397     nHitsVsEtaH_ = iBook.bookProfile("nHitsVsEta",
0398                                      "Number of Hits Vs Eta",
0399                                      TrackEtaHistoPar.getParameter<int32_t>("Xbins"),
0400                                      TrackEtaHistoPar.getParameter<double>("Xmin"),
0401                                      TrackEtaHistoPar.getParameter<double>("Xmax"),
0402                                      0.0,
0403                                      0.0,
0404                                      "g");
0405   if (!nHitsVsCosThetaH_)
0406     nHitsVsCosThetaH_ =
0407         iBook.bookProfile("nHitsVsCosTheta", "Number of Hits Vs Cos(Theta)", 50, -1.0, 1.0, 0.0, 0.0, "g");
0408   if (!nHitsVsPhiH_)
0409     nHitsVsPhiH_ = iBook.bookProfile("nHitsVsPhi", "Number of Hits Vs Phi", 100, -3.5, 3.5, 0.0, 0.0, "g");
0410 
0411   if (!nLostHitsVspTH_)
0412     nLostHitsVspTH_ = iBook.bookProfile("nLostHitsVspT",
0413                                         "Number of Lost Hits Vs pT",
0414                                         TrackPtHistoPar.getParameter<int32_t>("Xbins"),
0415                                         TrackPtHistoPar.getParameter<double>("Xmin"),
0416                                         TrackPtHistoPar.getParameter<double>("Xmax"),
0417                                         0.0,
0418                                         0.0,
0419                                         "g");
0420   if (!nLostHitsVsEtaH_)
0421     nLostHitsVsEtaH_ = iBook.bookProfile("nLostHitsVsEta",
0422                                          "Number of Lost Hits Vs Eta",
0423                                          TrackEtaHistoPar.getParameter<int32_t>("Xbins"),
0424                                          TrackEtaHistoPar.getParameter<double>("Xmin"),
0425                                          TrackEtaHistoPar.getParameter<double>("Xmax"),
0426                                          0.0,
0427                                          0.0,
0428                                          "g");
0429   if (!nLostHitsVsCosThetaH_)
0430     nLostHitsVsCosThetaH_ =
0431         iBook.bookProfile("nLostHitsVsCosTheta", "Number of Lost Hits Vs Cos(Theta)", 50, -1.0, 1.0, 0.0, 0.0, "g");
0432   if (!nLostHitsVsPhiH_)
0433     nLostHitsVsPhiH_ = iBook.bookProfile("nLostHitsVsPhi", "Number of Lost Hits Vs Phi", 100, -3.5, 3.5, 0.0, 0.0, "g");
0434 
0435   // On and off-track cluster properties
0436   if (!hOnTrkClusChargeThinH_)
0437     hOnTrkClusChargeThinH_ =
0438         iBook.book1D("hOnTrkClusChargeThin", "On-track Cluster Charge (Thin Sensor)", 100, 0, 1000);
0439   if (!hOnTrkClusWidthThinH_)
0440     hOnTrkClusWidthThinH_ = iBook.book1D("hOnTrkClusWidthThin", "On-track Cluster Width (Thin Sensor)", 20, -0.5, 19.5);
0441   if (!hOnTrkClusChargeThickH_)
0442     hOnTrkClusChargeThickH_ =
0443         iBook.book1D("hOnTrkClusChargeThick", "On-track Cluster Charge (Thick Sensor)", 100, 0, 1000);
0444   if (!hOnTrkClusWidthThickH_)
0445     hOnTrkClusWidthThickH_ =
0446         iBook.book1D("hOnTrkClusWidthThick", "On-track Cluster Width (Thick Sensor)", 20, -0.5, 19.5);
0447 
0448   if (!hOffTrkClusChargeThinH_)
0449     hOffTrkClusChargeThinH_ =
0450         iBook.book1D("hOffTrkClusChargeThin", "Off-track Cluster Charge (Thin Sensor)", 100, 0, 1000);
0451   if (!hOffTrkClusWidthThinH_)
0452     hOffTrkClusWidthThinH_ =
0453         iBook.book1D("hOffTrkClusWidthThin", "Off-track Cluster Width (Thin Sensor)", 20, -0.5, 19.5);
0454   if (!hOffTrkClusChargeThickH_)
0455     hOffTrkClusChargeThickH_ =
0456         iBook.book1D("hOffTrkClusChargeThick", "Off-track Cluster Charge (Thick Sensor)", 100, 0, 1000);
0457   if (!hOffTrkClusWidthThickH_)
0458     hOffTrkClusWidthThickH_ =
0459         iBook.book1D("hOffTrkClusWidthThick", "Off-track Cluster Width (Thick Sensor)", 20, -0.5, 19.5);
0460 }
0461 void StandaloneTrackMonitor::analyze(edm::Event const& iEvent, edm::EventSetup const& iSetup) {
0462   // Get event setup (to get global transformation)
0463 
0464   siStripClusterInfo_.initEvent(iSetup);
0465 
0466   // Primary vertex collection
0467   edm::Handle<reco::VertexCollection> vertexColl;
0468   iEvent.getByToken(vertexToken_, vertexColl);
0469 
0470   // Beam spot
0471   edm::Handle<reco::BeamSpot> beamSpot;
0472   iEvent.getByToken(bsToken_, beamSpot);
0473 
0474   // Track collection
0475   edm::Handle<reco::TrackCollection> tracks;
0476   iEvent.getByToken(trackToken_, tracks);
0477 
0478   // Access PU information
0479   double wfac = 1.0;  // for data
0480   if (!iEvent.isRealData()) {
0481     edm::Handle<std::vector<PileupSummaryInfo> > PupInfo;
0482     iEvent.getByToken(puSummaryToken_, PupInfo);
0483 
0484     if (verbose_)
0485       edm::LogInfo("StandaloneTrackMonitor") << "nPUColl = " << PupInfo->size();
0486     for (auto const& v : *PupInfo) {
0487       int bx = v.getBunchCrossing();
0488       if (bunchCrossingH_)
0489         bunchCrossingH_->Fill(bx);
0490       if (bx == 0) {
0491         if (nPUH_)
0492           nPUH_->Fill(v.getPU_NumInteractions());
0493         int ntrueInt = v.getTrueNumInteractions();
0494         if (trueNIntH_)
0495           trueNIntH_->Fill(ntrueInt);
0496         if (doPUCorrection_)
0497           if (ntrueInt > -1 && ntrueInt < int(vpu_.size()))
0498             wfac = vpu_.at(ntrueInt);
0499       }
0500     }
0501   }
0502   if (verbose_)
0503     edm::LogInfo("StandaloneTrackMonitor") << "PU reweight factor = " << wfac;
0504 
0505   if (!vertexColl.isValid())
0506     edm::LogError("DqmTrackStudy") << "Error! Failed to get reco::Vertex Collection, " << vertexTag_;
0507   if (haveAllHistograms_) {
0508     int nvtx = (vertexColl.isValid() ? vertexColl->size() : 0);
0509     nVertexH_->Fill(nvtx);
0510   }
0511 
0512   int ntracks = 0;
0513   if (tracks.isValid()) {
0514     edm::LogInfo("StandaloneTrackMonitor") << "Total # of Tracks: " << tracks->size();
0515     if (verbose_)
0516       edm::LogInfo("StandaloneTrackMonitor") << "Total # of Tracks: " << tracks->size();
0517     reco::Track::TrackQuality quality = reco::Track::qualityByName(trackQuality_);
0518     for (auto const& track : *tracks) {
0519       if (!track.quality(quality))
0520         continue;
0521 
0522       ++ntracks;
0523 
0524       double eta = track.eta();
0525       double theta = track.theta();
0526       double phi = track.phi();
0527       double pt = track.pt();
0528 
0529       const reco::HitPattern& hitp = track.hitPattern();
0530       double nValidTrackerHits = hitp.numberOfValidTrackerHits();
0531       nHitsVsEtaH_->Fill(eta, nValidTrackerHits);
0532       nHitsVsCosThetaH_->Fill(std::cos(theta), nValidTrackerHits);
0533       nHitsVsPhiH_->Fill(phi, nValidTrackerHits);
0534       nHitsVspTH_->Fill(pt, nValidTrackerHits);
0535       nHitsVsnVtxH_->Fill(vertexColl->size(), nValidTrackerHits);
0536 
0537       int nLostHits = track.numberOfLostHits();
0538       nLostHitsVspTH_->Fill(pt, nLostHits);
0539       nLostHitsVsEtaH_->Fill(eta, nLostHits);
0540       nLostHitsVsCosThetaH_->Fill(std::cos(theta), nLostHits);
0541       nLostHitsVsPhiH_->Fill(phi, nLostHits);
0542 
0543       double nValidPixelHits = hitp.numberOfValidPixelHits();
0544       double nValidStripHits = hitp.numberOfValidStripHits();
0545       double pixelLayersWithMeasurement = hitp.pixelLayersWithMeasurement();
0546       double stripLayersWithMeasurement = hitp.stripLayersWithMeasurement();
0547 
0548       if (haveAllHistograms_) {
0549         double etaError = track.etaError();
0550         double thetaError = track.thetaError();
0551         double phiError = track.phiError();
0552         double p = track.p();
0553         double ptError = track.ptError();
0554         double qoverp = track.qoverp();
0555         double qoverpError = track.qoverpError();
0556         double charge = track.charge();
0557 
0558         double trackerLayersWithMeasurement = hitp.trackerLayersWithMeasurement();
0559 
0560         double dxy = track.dxy(beamSpot->position());
0561         double dxyError = track.dxyError();
0562         double dz = track.dz(beamSpot->position());
0563         double dzError = track.dzError();
0564 
0565         double trkd0 = track.d0();
0566         double chi2 = track.chi2();
0567         double ndof = track.ndof();
0568         double vx = track.vx();
0569         double vy = track.vy();
0570         double vz = track.vz();
0571 
0572         // Fill the histograms
0573         trackEtaH_->Fill(eta, wfac);
0574         trackEtaerrH_->Fill(etaError, wfac);
0575         trackCosThetaH_->Fill(std::cos(theta), wfac);
0576         trackThetaerrH_->Fill(thetaError, wfac);
0577         trackPhiH_->Fill(phi, wfac);
0578         trackPhierrH_->Fill(phiError, wfac);
0579         trackPH_->Fill(p, wfac);
0580         trackPtH_->Fill(pt, wfac);
0581         if (pt <= 2)
0582           trackPtUpto2GeVH_->Fill(pt, wfac);
0583         if (pt >= 10)
0584           trackPtOver10GeVH_->Fill(pt, wfac);
0585         trackPterrH_->Fill(ptError, wfac);
0586         trackqOverpH_->Fill(qoverp, wfac);
0587         trackqOverperrH_->Fill(qoverpError, wfac);
0588         trackChargeH_->Fill(charge, wfac);
0589         trackChi2H_->Fill(chi2, wfac);
0590         trackd0H_->Fill(trkd0, wfac);
0591         tracknDOFH_->Fill(ndof, wfac);
0592         trackChi2bynDOFH_->Fill(chi2 / ndof, wfac);
0593 
0594         nlostHitsH_->Fill(nLostHits, wfac);
0595         nvalidTrackerHitsH_->Fill(nValidTrackerHits, wfac);
0596         nvalidPixelHitsH_->Fill(nValidPixelHits, wfac);
0597         nvalidStripHitsH_->Fill(nValidStripHits, wfac);
0598 
0599         trkLayerwithMeasurementH_->Fill(trackerLayersWithMeasurement, wfac);
0600         pixelLayerwithMeasurementH_->Fill(pixelLayersWithMeasurement, wfac);
0601         stripLayerwithMeasurementH_->Fill(stripLayersWithMeasurement, wfac);
0602 
0603         beamSpotXYposH_->Fill(dxy, wfac);
0604         beamSpotXYposerrH_->Fill(dxyError, wfac);
0605         beamSpotZposH_->Fill(dz, wfac);
0606         beamSpotZposerrH_->Fill(dzError, wfac);
0607 
0608         vertexXposH_->Fill(vx, wfac);
0609         vertexYposH_->Fill(vy, wfac);
0610         vertexZposH_->Fill(vz, wfac);
0611       }
0612       int nPixBarrel = 0, nPixEndcap = 0, nStripTIB = 0, nStripTOB = 0, nStripTEC = 0, nStripTID = 0;
0613       for (auto it = track.recHitsBegin(); it != track.recHitsEnd(); ++it) {
0614         const TrackingRecHit& hit = (**it);
0615         if (hit.isValid()) {
0616           if (hit.geographicalId().det() == DetId::Tracker) {
0617             int subdetId = hit.geographicalId().subdetId();
0618             if (subdetId == PixelSubdetector::PixelBarrel)
0619               ++nPixBarrel;
0620             else if (subdetId == PixelSubdetector::PixelEndcap)
0621               ++nPixEndcap;
0622             else if (subdetId == StripSubdetector::TIB)
0623               ++nStripTIB;
0624             else if (subdetId == StripSubdetector::TOB)
0625               ++nStripTOB;
0626             else if (subdetId == StripSubdetector::TEC)
0627               ++nStripTEC;
0628             else if (subdetId == StripSubdetector::TID)
0629               ++nStripTID;
0630 
0631             // Find on-track clusters
0632             processHit(hit, iSetup, wfac);
0633           }
0634         }
0635       }
0636       if (verbose_)
0637         edm::LogInfo("StandaloneTrackMonitor")
0638             << " >>> HITs: nPixBarrel: " << nPixBarrel << " nPixEndcap: " << nPixEndcap << " nStripTIB: " << nStripTIB
0639             << " nStripTOB: " << nStripTOB << " nStripTEC: " << nStripTEC << " nStripTID: " << nStripTID;
0640       if (haveAllHistograms_) {
0641         nPixBarrelH_->Fill(nPixBarrel, wfac);
0642         nPixEndcapH_->Fill(nPixEndcap, wfac);
0643         nStripTIBH_->Fill(nStripTIB, wfac);
0644         nStripTOBH_->Fill(nStripTOB, wfac);
0645         nStripTECH_->Fill(nStripTEC, wfac);
0646         nStripTIDH_->Fill(nStripTID, wfac);
0647       }
0648     }
0649   } else {
0650     edm::LogError("DqmTrackStudy") << "Error! Failed to get reco::Track collection, " << trackTag_;
0651   }
0652   if (haveAllHistograms_)
0653     nTracksH_->Fill(ntracks);
0654 
0655   // off track cluster properties
0656   processClusters(iEvent, iSetup, wfac);
0657 }
0658 void StandaloneTrackMonitor::processClusters(edm::Event const& iEvent, edm::EventSetup const& iSetup, double wfac) {
0659   // SiStripClusters
0660   edm::Handle<edmNew::DetSetVector<SiStripCluster> > clusterHandle;
0661   iEvent.getByToken(clusterToken_, clusterHandle);
0662 
0663   if (clusterHandle.isValid()) {
0664     // Loop on Dets
0665     for (edmNew::DetSetVector<SiStripCluster>::const_iterator dsvit = clusterHandle->begin();
0666          dsvit != clusterHandle->end();
0667          ++dsvit) {
0668       uint32_t detId = dsvit->id();
0669       std::map<uint32_t, std::set<const SiStripCluster*> >::iterator jt = clusterMap_.find(detId);
0670       bool detid_found = (jt != clusterMap_.end()) ? true : false;
0671 
0672       // Loop on Clusters
0673       for (edmNew::DetSet<SiStripCluster>::const_iterator clusit = dsvit->begin(); clusit != dsvit->end(); ++clusit) {
0674         if (detid_found) {
0675           std::set<const SiStripCluster*>& s = jt->second;
0676           if (s.find(&*clusit) != s.end())
0677             continue;
0678         }
0679 
0680         siStripClusterInfo_.setCluster(*clusit, detId);
0681         float charge = siStripClusterInfo_.charge();
0682         float width = siStripClusterInfo_.width();
0683 
0684         const GeomDetUnit* detUnit = tkGeom_->idToDetUnit(detId);
0685         float thickness = detUnit->surface().bounds().thickness();  // unit cm
0686         if (thickness > 0.035) {
0687           hOffTrkClusChargeThickH_->Fill(charge, wfac);
0688           hOffTrkClusWidthThickH_->Fill(width, wfac);
0689         } else {
0690           hOffTrkClusChargeThinH_->Fill(charge, wfac);
0691           hOffTrkClusWidthThinH_->Fill(width, wfac);
0692         }
0693       }
0694     }
0695   } else {
0696     edm::LogError("StandaloneTrackMonitor") << "ClusterCollection " << clusterTag_ << " not valid!!" << std::endl;
0697   }
0698 }
0699 void StandaloneTrackMonitor::processHit(const TrackingRecHit& recHit, edm::EventSetup const& iSetup, double wfac) {
0700   uint32_t detid = recHit.geographicalId();
0701   const GeomDetUnit* detUnit = tkGeom_->idToDetUnit(detid);
0702   float thickness = detUnit->surface().bounds().thickness();  // unit cm
0703 
0704   auto const& thit = static_cast<BaseTrackerRecHit const&>(recHit);
0705   if (!thit.isValid())
0706     return;
0707 
0708   auto const& clus = thit.firstClusterRef();
0709   if (!clus.isValid())
0710     return;
0711   if (!clus.isStrip())
0712     return;
0713 
0714   if (thit.isMatched()) {
0715     const SiStripMatchedRecHit2D& matchedHit = dynamic_cast<const SiStripMatchedRecHit2D&>(recHit);
0716 
0717     auto& clusterM = matchedHit.monoCluster();
0718     siStripClusterInfo_.setCluster(clusterM, detid);
0719     if (thickness > 0.035) {
0720       hOnTrkClusChargeThickH_->Fill(siStripClusterInfo_.charge(), wfac);
0721       hOnTrkClusWidthThickH_->Fill(siStripClusterInfo_.width(), wfac);
0722     } else {
0723       hOnTrkClusChargeThinH_->Fill(siStripClusterInfo_.charge(), wfac);
0724       hOnTrkClusWidthThinH_->Fill(siStripClusterInfo_.width(), wfac);
0725     }
0726     addClusterToMap(detid, &clusterM);
0727 
0728     auto& clusterS = matchedHit.stereoCluster();
0729     siStripClusterInfo_.setCluster(clusterS, detid);
0730     if (thickness > 0.035) {
0731       hOnTrkClusChargeThickH_->Fill(siStripClusterInfo_.charge(), wfac);
0732       hOnTrkClusWidthThickH_->Fill(siStripClusterInfo_.width(), wfac);
0733     } else {
0734       hOnTrkClusChargeThinH_->Fill(siStripClusterInfo_.charge(), wfac);
0735       hOnTrkClusWidthThinH_->Fill(siStripClusterInfo_.width(), wfac);
0736     }
0737     addClusterToMap(detid, &clusterS);
0738   } else {
0739     auto& cluster = clus.stripCluster();
0740     siStripClusterInfo_.setCluster(cluster, detid);
0741     if (thickness > 0.035) {
0742       hOnTrkClusChargeThickH_->Fill(siStripClusterInfo_.charge(), wfac);
0743       hOnTrkClusWidthThickH_->Fill(siStripClusterInfo_.width(), wfac);
0744     } else {
0745       hOnTrkClusChargeThinH_->Fill(siStripClusterInfo_.charge(), wfac);
0746       hOnTrkClusWidthThinH_->Fill(siStripClusterInfo_.width(), wfac);
0747     }
0748     addClusterToMap(detid, &cluster);
0749   }
0750 }
0751 void StandaloneTrackMonitor::addClusterToMap(uint32_t detid, const SiStripCluster* cluster) {
0752   std::map<uint32_t, std::set<const SiStripCluster*> >::iterator it = clusterMap_.find(detid);
0753   if (it == clusterMap_.end()) {
0754     std::set<const SiStripCluster*> s;
0755     s.insert(cluster);
0756     clusterMap_.insert(std::pair<uint32_t, std::set<const SiStripCluster*> >(detid, s));
0757   } else {
0758     std::set<const SiStripCluster*>& s = it->second;
0759     s.insert(cluster);
0760   }
0761 }
0762 // Define this as a plug-in
0763 #include "FWCore/Framework/interface/MakerMacros.h"
0764 DEFINE_FWK_MODULE(StandaloneTrackMonitor);