Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 10:57:13

0001 #ifndef DQM_TRACKERREMAPPER_SIPIXELPHASE1ANALYZER_H
0002 #define DQM_TRACKERREMAPPER_SIPIXELPHASE1ANALYZER_H
0003 
0004 /**\class SiPixelPhase1Analyzer SiPixelPhase1Analyzer.cc EJTerm/SiPixelPhase1Analyzer/plugins/SiPixelPhase1Analyzer.cc
0005 
0006  Description: [one line class summary]
0007 
0008  Implementation:
0009      [Notes on implementation]
0010 */
0011 //
0012 // Original Author:  Pawel Jurgielewicz
0013 //         Created:  Tue, 21 Feb 2017 09:42:19 GMT
0014 //
0015 //
0016 
0017 // system include files
0018 #include <memory>
0019 
0020 // #include <iostream>
0021 #include <fstream>
0022 #include <string>
0023 
0024 #include <algorithm>
0025 
0026 #include <vector>
0027 #include <map>
0028 
0029 // user include files
0030 #include "CommonTools/UtilAlgos/interface/TFileService.h"
0031 #include "DQM/TrackerRemapper/interface/mat4.h"
0032 #include "DataFormats/GeometrySurface/interface/DiskSectorBounds.h"
0033 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
0034 #include "DataFormats/GeometrySurface/interface/TrapezoidalPlaneBounds.h"
0035 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
0036 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
0037 #include "DataFormats/TrackReco/interface/Track.h"
0038 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0039 #include "DataFormats/TrackerCommon/interface/PixelBarrelName.h"
0040 #include "DataFormats/TrackerCommon/interface/PixelEndcapName.h"
0041 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0042 #include "DataFormats/TrackerRecHit2D/interface/SiPixelRecHitCollection.h"
0043 #include "FWCore/Framework/interface/Event.h"
0044 #include "FWCore/Framework/interface/Frameworkfwd.h"
0045 #include "FWCore/Framework/interface/MakerMacros.h"
0046 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0047 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0048 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0049 #include "FWCore/ServiceRegistry/interface/Service.h"
0050 #include "Geometry/CommonTopologies/interface/PixelGeomDetUnit.h"
0051 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
0052 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
0053 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0054 
0055 #include "TH2.h"
0056 #include "TProfile2D.h"
0057 #include "TH2Poly.h"
0058 #include "TGraph.h"
0059 
0060 #define CODE_FORWARD(s, d, b) ((unsigned short)((b << 8) + (d << 4) + s))
0061 
0062 //#define DEBUG_MODE
0063 
0064 //
0065 // class declaration
0066 //
0067 
0068 enum OperationMode { MODE_ANALYZE = 0, MODE_REMAP = 1 };
0069 
0070 class SiPixelPhase1Analyzer : public edm::one::EDAnalyzer<edm::one::SharedResources> {
0071 public:
0072   explicit SiPixelPhase1Analyzer(const edm::ParameterSet&);
0073   ~SiPixelPhase1Analyzer() override;
0074 
0075   static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
0076 
0077 private:
0078   void analyze(const edm::Event&, const edm::EventSetup&) override;
0079   void BookHistograms();
0080 
0081   void BookBarrelHistograms(TDirectory* currentDir, const std::string& currentHistoName);
0082   void BookForwardHistograms(TDirectory* currentDir, const std::string& currentHistoName);
0083 
0084   void BookBins(const TrackerGeometry& theTrackerGeometry, const TrackerTopology* tt);
0085   void BookBarrelBins(const TrackerGeometry& theTrackerGeometry, const TrackerTopology* tt);
0086   void BookForwardBins(const TrackerGeometry& theTrackerGeometry, const TrackerTopology* tt);
0087 
0088   void SaveDetectorVertices(const TrackerTopology* tt);
0089 
0090   void FillBins(edm::Handle<reco::TrackCollection>* tracks,
0091                 const TrackerGeometry& theTrackerGeometry,
0092                 const TrackerTopology* tt);
0093 
0094   void FillBarrelBinsAnalyze(const TrackerGeometry& theTrackerGeometry,
0095                              const TrackerTopology* tt,
0096                              unsigned rawId,
0097                              const GlobalPoint& globalPoint);
0098   void FillForwardBinsAnalyze(const TrackerGeometry& theTrackerGeometry,
0099                               const TrackerTopology* tt,
0100                               unsigned rawId,
0101                               const GlobalPoint& globalPoint);
0102 
0103   void FillBarrelBinsRemap(const TrackerGeometry& theTrackerGeometry, const TrackerTopology* tt);
0104   void FillForwardBinsRemap(const TrackerGeometry& theTrackerGeometry, const TrackerTopology* tt);
0105 
0106   // ----------member data ---------------------------
0107   const edm::ESGetToken<TrackerGeometry, TrackerDigiGeometryRecord> geomToken_;
0108   const edm::ESGetToken<TrackerTopology, TrackerTopologyRcd> topoToken_;
0109 
0110   OperationMode opMode;
0111 
0112   edm::EDGetTokenT<reco::TrackCollection> tracksToken;
0113 
0114   std::string debugFileName;
0115   std::ofstream debugFile;
0116 
0117   edm::Service<TFileService> fs;
0118 
0119   bool firstEvent;
0120 
0121   std::map<uint32_t, TGraph*> bins, binsSummary;
0122 
0123   std::map<std::string, std::vector<TH2Poly*> > th2PolyBarrel;
0124   std::map<std::string, TH2Poly*> th2PolyBarrelSummary;
0125 
0126 #ifdef DEBUG_MODE
0127   std::map<std::string, std::vector<TH2*> > th2PolyBarrelDebug;
0128 #endif
0129 
0130   std::map<std::string, std::vector<TH2Poly*> > pxfTh2PolyForward;
0131   std::map<std::string, TH2Poly*> pxfTh2PolyForwardSummary;
0132 
0133 #ifdef DEBUG_MODE
0134   std::map<std::string, std::vector<TH2*> > pxfTh2PolyForwardDebug;
0135 #endif
0136 
0137   mat4 orthoProjectionMatrix;
0138 
0139   struct complementaryElements {
0140     mat4 mat[2];
0141     unsigned rawId[2];
0142   };
0143   // used to hold information about elements': ids & matrices which are of the same side, disk and barrel but different panel
0144   // to build trapezoidal ring elements
0145   std::map<unsigned short, complementaryElements> mapOfComplementaryElements;
0146 
0147   //Input root file handle;
0148   TFile* rootFileHandle;
0149 
0150   // read input histograms
0151   std::vector<unsigned> isBarrelSource;
0152   std::vector<std::string> analazedRootFileName;
0153   std::vector<std::string> pathToHistograms;
0154   std::vector<std::string> baseHistogramName;
0155 
0156   // temporal functionality
0157   void SaveDetectorData(bool isBarrel, unsigned rawId, int shell_hc, int layer_disk, int ladder_blade) {
0158     std::ofstream file("det.data", std::ofstream::out);
0159 
0160     file << isBarrel << "\t" << rawId << "\t" << shell_hc << "\t" << layer_disk << "\t" << ladder_blade << std::endl;
0161   }
0162 };
0163 
0164 #endif