Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-06-30 04:13:35

0001 
0002 #ifndef QcdLowPtDQM_H
0003 #define QcdLowPtDQM_H
0004 
0005 #include "DQMServices/Core/interface/DQMOneEDAnalyzer.h"
0006 #include "DataFormats/Common/interface/Handle.h"
0007 #include "DataFormats/GeometryVector/interface/VectorUtil.h"
0008 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0009 #include "FWCore/Framework/interface/Frameworkfwd.h"
0010 #include "FWCore/Framework/interface/Event.h"
0011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0012 #include "HLTrigger/HLTcore/interface/HLTConfigProvider.h"
0013 #include "DQMServices/Core/interface/DQMStore.h"
0014 #include <TMath.h>
0015 #include <vector>
0016 
0017 class TrackerGeometry;
0018 class TrackerDigiGeometryRecord;
0019 class TrackerTopology;
0020 class TrackerTopologyRcd;
0021 class TH1F;
0022 class TH2F;
0023 class TH3F;
0024 
0025 namespace qlpd {
0026   struct Cache {};
0027 }  // namespace qlpd
0028 
0029 class QcdLowPtDQM : public DQMOneEDAnalyzer<edm::LuminosityBlockCache<qlpd::Cache>> {
0030 public:
0031   class Pixel {
0032   public:
0033     Pixel(double x = 0,
0034           double y = 0,
0035           double z = 0,
0036           double eta = 0,
0037           double phi = 0,
0038           double adc = 0,
0039           double sx = 0,
0040           double sy = 0)
0041         : x_(x),
0042           y_(y),
0043           z_(z),
0044           rho_(TMath::Sqrt(x_ * x_ + y_ * y_)),
0045           eta_(eta),
0046           phi_(phi),
0047           adc_(adc),
0048           sizex_(sx),
0049           sizey_(sy) {}
0050     Pixel(const GlobalPoint &p, double adc = 0, double sx = 0, double sy = 0)
0051         : x_(p.x()),
0052           y_(p.y()),
0053           z_(p.z()),
0054           rho_(TMath::Sqrt(x_ * x_ + y_ * y_)),
0055           eta_(p.eta()),
0056           phi_(p.phi()),
0057           adc_(adc),
0058           sizex_(sx),
0059           sizey_(sy) {}
0060     double adc() const { return adc_; }
0061     double eta() const { return eta_; }
0062     double rho() const { return rho_; }
0063     double phi() const { return phi_; }
0064     double sizex() const { return sizex_; }
0065     double sizey() const { return sizey_; }
0066     double x() const { return x_; }
0067     double y() const { return y_; }
0068     double z() const { return z_; }
0069 
0070   protected:
0071     double x_, y_, z_, rho_, eta_, phi_;
0072     double adc_, sizex_, sizey_;
0073   };
0074   class Tracklet {
0075   public:
0076     Tracklet() : i1_(-1), i2_(-2), deta_(0), dphi_(0) {}
0077     Tracklet(const Pixel &p1, const Pixel &p2)
0078         : p1_(p1), p2_(p2), i1_(-1), i2_(-1), deta_(p1.eta() - p2.eta()), dphi_(Geom::deltaPhi(p1.phi(), p2.phi())) {}
0079     double deta() const { return deta_; }
0080     double dphi() const { return dphi_; }
0081     int i1() const { return i1_; }
0082     int i2() const { return i2_; }
0083     double eta() const { return p1_.eta(); }
0084     const Pixel &p1() const { return p1_; }
0085     const Pixel &p2() const { return p2_; }
0086     void seti1(int i1) { i1_ = i1; }
0087     void seti2(int i2) { i2_ = i2; }
0088 
0089   protected:
0090     Pixel p1_, p2_;
0091     int i1_, i2_;
0092     double deta_, dphi_;
0093   };
0094   class Vertex {
0095   public:
0096     Vertex(double x = 0, double y = 0, double z = 0, double xs = 0, double ys = 0, double zs = 0, int n = 0)
0097         : x_(x), y_(y), z_(z), xs_(xs), ys_(ys), zs_(zs), n_(n) {}
0098     int n() const { return n_; }
0099     double x() const { return x_; }
0100     double y() const { return y_; }
0101     double z() const { return z_; }
0102     double xs() const { return xs_; }
0103     double ys() const { return ys_; }
0104     double zs() const { return zs_; }
0105     void set(int n, double z, double zs) {
0106       n_ = n;
0107       z_ = z;
0108       zs_ = zs;
0109     }
0110     void set(int n, double x, double y, double z, double xs, double ys, double zs) {
0111       n_ = n;
0112       x_ = x;
0113       xs_ = xs;
0114       y_ = y;
0115       ys_ = ys;
0116       z_ = z;
0117       zs_ = zs;
0118     }
0119 
0120   protected:
0121     double x_, y_, z_, xs_, ys_, zs_;
0122     int n_;
0123   };
0124 
0125   QcdLowPtDQM(const edm::ParameterSet &parameters);
0126   ~QcdLowPtDQM() override;
0127   void dqmBeginRun(const edm::Run &, const edm::EventSetup &) override;
0128   void bookHistograms(DQMStore::IBooker &, edm::Run const &, edm::EventSetup const &) override;
0129   void analyze(const edm::Event &iEvent, const edm::EventSetup &iSetup) override;
0130   std::shared_ptr<qlpd::Cache> globalBeginLuminosityBlock(const edm::LuminosityBlock &,
0131                                                           const edm::EventSetup &) const override;
0132   void globalEndLuminosityBlock(const edm::LuminosityBlock &l, const edm::EventSetup &iSetup) override;
0133   void dqmEndRun(const edm::Run &r, const edm::EventSetup &iSetup) override;
0134 
0135 private:
0136   void book1D(DQMStore::IBooker &,
0137               std::vector<MonitorElement *> &mes,
0138               const std::string &name,
0139               const std::string &title,
0140               int nx,
0141               double x1,
0142               double x2,
0143               bool sumw2 = true,
0144               bool sbox = true);
0145   void book2D(DQMStore::IBooker &,
0146               std::vector<MonitorElement *> &mes,
0147               const std::string &name,
0148               const std::string &title,
0149               int nx,
0150               double x1,
0151               double x2,
0152               int ny,
0153               double y1,
0154               double y2,
0155               bool sumw2 = true,
0156               bool sbox = true);
0157   void create1D(std::vector<TH1F *> &mes,
0158                 const std::string &name,
0159                 const std::string &title,
0160                 int nx,
0161                 double x1,
0162                 double x2,
0163                 bool sumw2 = true,
0164                 bool sbox = true);
0165   void create2D(std::vector<TH2F *> &mes,
0166                 const std::string &name,
0167                 const std::string &title,
0168                 int nx,
0169                 double x1,
0170                 double x2,
0171                 int ny,
0172                 double y1,
0173                 double y2,
0174                 bool sumw2 = true,
0175                 bool sbox = true);
0176   void fill1D(std::vector<TH1F *> &hs, double val, double w = 1.);
0177   void fill1D(std::vector<MonitorElement *> &mes, double val, double w = 1.);
0178   void fill2D(std::vector<TH2F *> &hs, double valx, double valy, double w = 1.);
0179   void fill2D(std::vector<MonitorElement *> &mes, double valx, double valy, double w = 1.);
0180   void fill3D(std::vector<TH3F *> &hs, int gbin, double w = 1.);
0181   void filldNdeta(const TH3F *AlphaTracklets,
0182                   const std::vector<TH3F *> &NsigTracklets,
0183                   const std::vector<TH3F *> &NbkgTracklets,
0184                   const std::vector<TH1F *> &NEvsPerEta,
0185                   std::vector<MonitorElement *> &hdNdEtaRawTrkl,
0186                   std::vector<MonitorElement *> &hdNdEtaSubTrkl,
0187                   std::vector<MonitorElement *> &hdNdEtaTrklets);
0188   void fillHltBits(const edm::Event &iEvent);
0189   void fillPixels(const edm::Event &iEvent, const edm::EventSetup &iSetup);
0190   void fillPixelClusterInfos(const edm::Event &iEvent, int which = 12);
0191   void fillPixelClusterInfos(const double vz,
0192                              const std::vector<Pixel> &pix,
0193                              std::vector<MonitorElement *> &hClusterYSize,
0194                              std::vector<MonitorElement *> &hClusterADC);
0195   void fillTracklets(const edm::Event &iEvent, int which = 12);
0196   void fillTracklets(std::vector<Tracklet> &tracklets,
0197                      const std::vector<Pixel> &pix1,
0198                      const std::vector<Pixel> &pix2,
0199                      const Vertex &trackletV);
0200   void fillTracklets(const std::vector<Tracklet> &tracklets,
0201                      const std::vector<Pixel> &pixels,
0202                      const Vertex &trackletV,
0203                      const TH3F *AlphaTracklets,
0204                      std::vector<TH3F *> &NsigTracklets,
0205                      std::vector<TH3F *> &NbkgTracklets,
0206                      std::vector<TH1F *> &eventpereta,
0207                      std::vector<MonitorElement *> &detaphi,
0208                      std::vector<MonitorElement *> &deta,
0209                      std::vector<MonitorElement *> &dphi,
0210                      std::vector<MonitorElement *> &etavsvtx);
0211   template <typename TYPE>
0212   void getProduct(const std::string name, edm::Handle<TYPE> &prod, const edm::Event &event) const;
0213   template <typename TYPE>
0214   bool getProductSafe(const std::string name, edm::Handle<TYPE> &prod, const edm::Event &event) const;
0215   void print(int level, const char *msg);
0216   void print(int level, const std::string &msg) { print(level, msg.c_str()); }
0217   void reallyPrint(int level, const char *msg);
0218   void trackletVertexUnbinned(const edm::Event &iEvent, int which = 12);
0219   void trackletVertexUnbinned(std::vector<Pixel> &pix1, std::vector<Pixel> &pix2, Vertex &vtx);
0220   double vertexZFromClusters(const std::vector<Pixel> &pix) const;
0221   void yieldAlphaHistogram(int which = 12);
0222 
0223   edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> tkGeomToken_;
0224   edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> tTopoToken_;
0225   std::string hltResName_;                    // HLT trigger results name
0226   std::vector<std::string> hltProcNames_;     // HLT process name(s)
0227   std::vector<std::string> hltTrgNames_;      // HLT trigger name(s)
0228   std::string pixelName_;                     // pixel reconstructed hits name
0229   std::string clusterVtxName_;                // cluster vertex name
0230   double ZVCut_;                              // Z vertex cut for selected events
0231   double ZVEtaRegion_;                        // Z vertex eta region
0232   double ZVVtxRegion_;                        // Z vertex vtx region
0233   double dPhiVc_;                             // dPhi vertex cut for tracklet based vertex
0234   double dZVc_;                               // dZ vertex cut for tracklet based vertex
0235   double sigEtaCut_;                          // signal tracklet eta cut
0236   double sigPhiCut_;                          // signal tracklet phi cut
0237   double bkgEtaCut_;                          // bkg tracklet eta cut
0238   double bkgPhiCut_;                          // bgk tracklet phi cut
0239   int verbose_;                               // verbosity (0=debug,1=warn,2=error,3=throw)
0240   int pixLayers_;                             // 12 for 12, 13 for 12 and 13, 23 for all
0241   int clusLayers_;                            // 12 for 12, 13 for 12 and 13, 23 for all
0242   bool useRecHitQ_;                           // if true use rec hit quality word
0243   bool usePixelQ_;                            // if true use pixel hit quality word
0244   std::vector<int> hltTrgBits_;               // HLT trigger bit(s)
0245   std::vector<bool> hltTrgDeci_;              // HLT trigger descision(s)
0246   std::vector<std::string> hltTrgUsedNames_;  // HLT used trigger name(s)
0247   std::string hltUsedResName_;                // used HLT trigger results name
0248   std::vector<Pixel> bpix1_;                  // barrel pixels layer 1
0249   std::vector<Pixel> bpix2_;                  // barrel pixels layer 2
0250   std::vector<Pixel> bpix3_;                  // barrel pixels layer 3
0251   std::vector<Tracklet> btracklets12_;        // barrel tracklets 12
0252   std::vector<Tracklet> btracklets13_;        // barrel tracklets 13
0253   std::vector<Tracklet> btracklets23_;        // barrel tracklets 23
0254   Vertex trackletV12_;                        // reconstructed tracklet vertex 12
0255   Vertex trackletV13_;                        // reconstructed tracklet vertex 13
0256   Vertex trackletV23_;                        // reconstructed tracklet vertex 23
0257   std::vector<TH3F *> NsigTracklets12_;       // number of signal tracklets 12
0258   std::vector<TH3F *> NbkgTracklets12_;       // number of background tracklets 12
0259   std::vector<TH1F *> hEvtCountsPerEta12_;    // event count per tracklet12
0260                                               // eta-vtx region
0261   TH3F *AlphaTracklets12_;                    // alpha correction for tracklets 12
0262   std::vector<TH3F *> NsigTracklets13_;       // number of signal tracklets 13
0263   std::vector<TH3F *> NbkgTracklets13_;       // number of background tracklets 13
0264   std::vector<TH1F *> hEvtCountsPerEta13_;    // event count per tracklet13
0265                                               // eta-vtx region
0266   TH3F *AlphaTracklets13_;                    // alpha correction for tracklets 13
0267   std::vector<TH3F *> NsigTracklets23_;       // number of signal tracklets 23
0268   std::vector<TH3F *> NbkgTracklets23_;       // number of background tracklets 23
0269   std::vector<TH1F *> hEvtCountsPerEta23_;    // event count per tracklet23
0270                                               // eta-vtx region
0271   TH3F *AlphaTracklets23_;                    // alpha correction for tracklets 23
0272   HLTConfigProvider hltConfig_;
0273   const TrackerGeometry *tgeo_;                      // tracker geometry
0274   MonitorElement *repSumMap_;                        // report summary map
0275   MonitorElement *repSummary_;                       // report summary
0276   MonitorElement *h2TrigCorr_;                       // trigger correlation plot
0277   std::vector<MonitorElement *> hNhitsL1_;           // number of hits on layer 1
0278   std::vector<MonitorElement *> hNhitsL2_;           // number of hits on layer 2
0279   std::vector<MonitorElement *> hNhitsL3_;           // number of hits on layer 3
0280   std::vector<MonitorElement *> hNhitsL1z_;          // number of hits on layer 1
0281                                                      // (zoomed)
0282   std::vector<MonitorElement *> hNhitsL2z_;          // number of hits on layer 2
0283                                                      // (zoomed)
0284   std::vector<MonitorElement *> hNhitsL3z_;          // number of hits on layer 3
0285                                                      // (zoomed)
0286   std::vector<MonitorElement *> hdNdEtaHitsL1_;      // dN/dEta of hits on layer 1
0287   std::vector<MonitorElement *> hdNdEtaHitsL2_;      // dN/dEta of hits on layer 2
0288   std::vector<MonitorElement *> hdNdEtaHitsL3_;      // dN/dEta of hits on layer 3
0289   std::vector<MonitorElement *> hdNdPhiHitsL1_;      // dN/dPhi of hits on layer 1
0290   std::vector<MonitorElement *> hdNdPhiHitsL2_;      // dN/dPhi of hits on layer 2
0291   std::vector<MonitorElement *> hdNdPhiHitsL3_;      // dN/dPhi of hits on layer 3
0292   std::vector<MonitorElement *> hTrkVtxZ12_;         // tracklet z vertex 12 histograms
0293   std::vector<MonitorElement *> hTrkVtxZ13_;         // tracklet z vertex 13 histograms
0294   std::vector<MonitorElement *> hTrkVtxZ23_;         // tracklet z vertex 23 histograms
0295   std::vector<MonitorElement *> hRawTrkEtaVtxZ12_;   // tracklet eta vs z vertex
0296                                                      // 12 histograms
0297   std::vector<MonitorElement *> hRawTrkEtaVtxZ13_;   // tracklet eta vs z vertex
0298                                                      // 13 histograms
0299   std::vector<MonitorElement *> hRawTrkEtaVtxZ23_;   // tracklet eta vs z vertex
0300                                                      // 23 histograms
0301   std::vector<MonitorElement *> hTrkRawDetaDphi12_;  // tracklet12 Deta/Dphi
0302                                                      // distribution
0303   std::vector<MonitorElement *> hTrkRawDeta12_;      // tracklet12 Deta distribution
0304   std::vector<MonitorElement *> hTrkRawDphi12_;      // tracklet12 Dphi distribution
0305   std::vector<MonitorElement *> hTrkRawDetaDphi13_;  // tracklet13 Deta/Dphi
0306                                                      // distribution
0307   std::vector<MonitorElement *> hTrkRawDeta13_;      // tracklet13 Deta distribution
0308   std::vector<MonitorElement *> hTrkRawDphi13_;      // tracklet13 Dphi distribution
0309   std::vector<MonitorElement *> hTrkRawDetaDphi23_;  // tracklet23 Deta/Dphi
0310                                                      // distribution
0311   std::vector<MonitorElement *> hTrkRawDeta23_;      // tracklet23 Deta distribution
0312   std::vector<MonitorElement *> hTrkRawDphi23_;      // tracklet23 Dphi distribution
0313   std::vector<MonitorElement *> hdNdEtaRawTrkl12_;   // dN/dEta from raw
0314                                                      // tracklets 12
0315   std::vector<MonitorElement *> hdNdEtaSubTrkl12_;   // dN/dEta from beta
0316                                                      // tracklets 12
0317   std::vector<MonitorElement *> hdNdEtaTrklets12_;   // dN/dEta corrected by
0318                                                      // alpha 12
0319   std::vector<MonitorElement *> hdNdEtaRawTrkl13_;   // dN/dEta from raw
0320                                                      // tracklets 13
0321   std::vector<MonitorElement *> hdNdEtaSubTrkl13_;   // dN/dEta from beta
0322                                                      // tracklets 13
0323   std::vector<MonitorElement *> hdNdEtaTrklets13_;   // dN/dEta corrected by
0324                                                      // alpha 13
0325   std::vector<MonitorElement *> hdNdEtaRawTrkl23_;   // dN/dEta from raw
0326                                                      // tracklets 23
0327   std::vector<MonitorElement *> hdNdEtaSubTrkl23_;   // dN/dEta from beta
0328                                                      // tracklets 23
0329   std::vector<MonitorElement *> hdNdEtaTrklets23_;   // dN/dEta corrected by
0330                                                      // alpha 23
0331   std::vector<MonitorElement *> hClusterVertexZ_;    // cluster z vertex
0332                                                      // histograms
0333   std::vector<MonitorElement *> hClusterYSize1_;     // cluster y size histograms
0334                                                      // on layer 1
0335   std::vector<MonitorElement *> hClusterYSize2_;     // cluster y size histograms
0336                                                      // on layer 2
0337   std::vector<MonitorElement *> hClusterYSize3_;     // cluster y size histograms
0338                                                      // on layer 3
0339   std::vector<MonitorElement *> hClusterADC1_;       // cluster adc histograms on
0340                                                      // layer 1
0341   std::vector<MonitorElement *> hClusterADC2_;       // cluster adc histograms on
0342                                                      // layer 2
0343   std::vector<MonitorElement *> hClusterADC3_;       // cluster adc histograms on
0344                                                      // layer 3
0345 };
0346 
0347 //--------------------------------------------------------------------------------------------------
0348 template <typename TYPE>
0349 inline void QcdLowPtDQM::getProduct(const std::string name, edm::Handle<TYPE> &prod, const edm::Event &event) const {
0350   // Try to access data collection from EDM file. We check if we really get just
0351   // one
0352   // product with the given name. If not we throw an exception.
0353 
0354   event.getByLabel(edm::InputTag(name), prod);
0355   if (!prod.isValid())
0356     throw edm::Exception(edm::errors::Configuration, "QcdLowPtDQM::GetProduct()\n")
0357         << "Collection with label " << name << " is not valid" << std::endl;
0358 }
0359 
0360 //--------------------------------------------------------------------------------------------------
0361 template <typename TYPE>
0362 inline bool QcdLowPtDQM::getProductSafe(const std::string name,
0363                                         edm::Handle<TYPE> &prod,
0364                                         const edm::Event &event) const {
0365   // Try to safely access data collection from EDM file. We check if we really
0366   // get just one
0367   // product with the given name. If not, we return false.
0368 
0369   if (name.empty())
0370     return false;
0371 
0372   try {
0373     event.getByLabel(edm::InputTag(name), prod);
0374     if (!prod.isValid())
0375       return false;
0376   } catch (...) {
0377     return false;
0378   }
0379   return true;
0380 }
0381 
0382 //--------------------------------------------------------------------------------------------------
0383 inline void QcdLowPtDQM::print(int level, const char *msg) {
0384   // Print out message if it
0385 
0386   if (level >= verbose_)
0387     reallyPrint(level, msg);
0388 }
0389 #endif
0390 
0391 /* Local Variables: */
0392 /* show-trailing-whitespace: t */
0393 /* truncate-lines: t */
0394 /* End: */