Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:19:16

0001 #ifndef RecoLocalMuon_CSCValidation_H
0002 #define RecoLocalMuon_CSCValidation_H
0003 
0004 /** \class CSCValidation
0005  *
0006  * Package to validate local CSC reconstruction:
0007  *    DIGIS
0008  *    recHits
0009  *    segments
0010  *    L1 trigger
0011  *    CSC STA muons
0012  *    Various efficiencies
0013  *
0014  * Responsible:
0015  *    CSC DPG
0016  */
0017 
0018 #include "FWCore/Framework/interface/ConsumesCollector.h"
0019 #include "FWCore/Framework/interface/MakerMacros.h"
0020 #include "FWCore/Framework/interface/Frameworkfwd.h"
0021 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0022 #include "FWCore/Framework/interface/Event.h"
0023 #include "DataFormats/Common/interface/Handle.h"
0024 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0025 #include "FWCore/Framework/interface/EventSetup.h"
0026 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0027 #include "FWCore/Utilities/interface/ESGetToken.h"
0028 #include "DataFormats/CSCDigi/interface/CSCWireDigiCollection.h"
0029 #include "DataFormats/CSCDigi/interface/CSCStripDigiCollection.h"
0030 #include "DataFormats/CSCDigi/interface/CSCComparatorDigiCollection.h"
0031 #include "DataFormats/CSCDigi/interface/CSCALCTDigiCollection.h"
0032 #include "DataFormats/CSCDigi/interface/CSCCLCTDigiCollection.h"
0033 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
0034 
0035 #include "EventFilter/CSCRawToDigi/interface/CSCDCCEventData.h"
0036 #include "EventFilter/CSCRawToDigi/interface/CSCDCCExaminer.h"
0037 #include "EventFilter/CSCRawToDigi/interface/CSCEventData.h"
0038 #include "EventFilter/CSCRawToDigi/interface/CSCCFEBData.h"
0039 #include "EventFilter/CSCRawToDigi/interface/CSCALCTHeader.h"
0040 #include "EventFilter/CSCRawToDigi/interface/CSCAnodeData.h"
0041 #include "EventFilter/CSCRawToDigi/interface/CSCComparatorData.h"
0042 #include "EventFilter/CSCRawToDigi/interface/CSCDDUEventData.h"
0043 #include "EventFilter/CSCRawToDigi/interface/CSCTMBData.h"
0044 #include "EventFilter/CSCRawToDigi/interface/CSCTMBHeader.h"
0045 #include "EventFilter/CSCRawToDigi/interface/CSCRPCData.h"
0046 #include "EventFilter/CSCRawToDigi/interface/CSCDCCExaminer.h"
0047 #include "EventFilter/CSCRawToDigi/interface/CSCDCCEventData.h"
0048 #include "EventFilter/CSCRawToDigi/interface/CSCCFEBData.h"
0049 #include "EventFilter/CSCRawToDigi/interface/CSCCFEBTimeSlice.h"
0050 #include "EventFilter/CSCRawToDigi/interface/CSCMonitorInterface.h"
0051 #include "CondFormats/CSCObjects/interface/CSCCrateMap.h"
0052 #include "CondFormats/DataRecord/interface/CSCCrateMapRcd.h"
0053 #include "FWCore/ServiceRegistry/interface/Service.h"
0054 //FEDRawData
0055 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
0056 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
0057 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
0058 
0059 #include "DataFormats/CSCRecHit/interface/CSCSegmentCollection.h"
0060 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0061 
0062 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutRecord.h"
0063 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutCollection.h"
0064 #include "DataFormats/Common/interface/TriggerResults.h"
0065 #include "FWCore/Common/interface/TriggerNames.h"
0066 
0067 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
0068 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0069 
0070 #include "DataFormats/TrackReco/interface/Track.h"
0071 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0072 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
0073 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0074 
0075 #include "DataFormats/CSCRecHit/interface/CSCRecHit2DCollection.h"
0076 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0077 
0078 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0079 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
0080 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0081 #include "DataFormats/GeometryVector/interface/LocalVector.h"
0082 #include "DataFormats/CLHEP/interface/AlgebraicObjects.h"
0083 #include "DataFormats/MuonDetId/interface/CSCIndexer.h"
0084 
0085 #include "CondFormats/CSCObjects/interface/CSCDBGains.h"
0086 #include "CondFormats/DataRecord/interface/CSCDBGainsRcd.h"
0087 #include "CondFormats/CSCObjects/interface/CSCDBNoiseMatrix.h"
0088 #include "CondFormats/DataRecord/interface/CSCDBNoiseMatrixRcd.h"
0089 #include "CondFormats/CSCObjects/interface/CSCDBCrosstalk.h"
0090 #include "CondFormats/DataRecord/interface/CSCDBCrosstalkRcd.h"
0091 #include "CondFormats/CSCObjects/interface/CSCDBPedestals.h"
0092 #include "CondFormats/DataRecord/interface/CSCDBPedestalsRcd.h"
0093 
0094 #include "CommonTools/Statistics/interface/ChiSquaredProbability.h"
0095 
0096 #include "RecoLocalMuon/CSCValidation/src/CSCValHists.h"
0097 #include "TVector3.h"
0098 #include "TH1F.h"
0099 #include "TH2F.h"
0100 #include "TFile.h"
0101 #include "TString.h"
0102 #include "TTree.h"
0103 #include "TProfile2D.h"
0104 
0105 namespace {
0106   class CSCValidation : public edm::one::EDAnalyzer<> {
0107   public:
0108     /// Constructor
0109     CSCValidation(const edm::ParameterSet &pset);
0110 
0111     /// Destructor
0112     ~CSCValidation() override;
0113 
0114     /// Perform the analysis
0115     void analyze(edm::Event const &event, edm::EventSetup const &eventSetup) override;
0116     void beginJob() override;
0117     void endJob() override;
0118 
0119     // for noise module
0120     struct ltrh {
0121       bool operator()(const CSCRecHit2D &rh1, const CSCRecHit2D &rh2) const {
0122         return ((rh1.localPosition()).x() - (rh2.localPosition()).x()) < 0;
0123       }
0124     };
0125 
0126   protected:
0127   private:
0128     // these are the "modules"
0129     // if you would like to add code to CSCValidation, please do so by adding an
0130     // extra module in the form of an additional private member function
0131     void doOccupancies(edm::Handle<CSCStripDigiCollection> strips,
0132                        edm::Handle<CSCWireDigiCollection> wires,
0133                        edm::Handle<CSCRecHit2DCollection> recHits,
0134                        edm::Handle<CSCSegmentCollection> cscSegments);
0135     void doStripDigis(edm::Handle<CSCStripDigiCollection> strips);
0136     void doWireDigis(edm::Handle<CSCWireDigiCollection> wires);
0137     void doRecHits(edm::Handle<CSCRecHit2DCollection> recHits, edm::ESHandle<CSCGeometry> cscGeom);
0138     void doSimHits(edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<edm::PSimHitContainer> simHits);
0139     void doPedestalNoise(edm::Handle<CSCStripDigiCollection> strips);
0140     void doSegments(edm::Handle<CSCSegmentCollection> cscSegments, edm::ESHandle<CSCGeometry> cscGeom);
0141     void doResolution(edm::Handle<CSCSegmentCollection> cscSegments, edm::ESHandle<CSCGeometry> cscGeom);
0142     void doEfficiencies(edm::Handle<CSCWireDigiCollection> wires,
0143                         edm::Handle<CSCStripDigiCollection> strips,
0144                         edm::Handle<CSCRecHit2DCollection> recHits,
0145                         edm::Handle<CSCSegmentCollection> cscSegments,
0146                         edm::ESHandle<CSCGeometry> cscGeom);
0147     void doGasGain(const CSCWireDigiCollection &, const CSCStripDigiCollection &, const CSCRecHit2DCollection &);
0148     void doCalibrations(const edm::EventSetup &eventSetup);
0149     void doAFEBTiming(const CSCWireDigiCollection &);
0150     void doCompTiming(const CSCComparatorDigiCollection &);
0151     void doADCTiming(const CSCRecHit2DCollection &);
0152     void doNoiseHits(edm::Handle<CSCRecHit2DCollection> recHits,
0153                      edm::Handle<CSCSegmentCollection> cscSegments,
0154                      edm::ESHandle<CSCGeometry> cscGeom,
0155                      edm::Handle<CSCStripDigiCollection> strips);
0156     bool doTrigger(edm::Handle<L1MuGMTReadoutCollection> pCollection);
0157     void doStandalone(edm::Handle<reco::TrackCollection> saMuons);
0158     void doTimeMonitoring(edm::Handle<CSCRecHit2DCollection> recHits,
0159                           edm::Handle<CSCSegmentCollection> cscSegments,
0160                           edm::Handle<CSCALCTDigiCollection> alcts,
0161                           edm::Handle<CSCCLCTDigiCollection> clcts,
0162                           edm::Handle<CSCCorrelatedLCTDigiCollection> correlatedlcts,
0163                           edm::Handle<L1MuGMTReadoutCollection> pCollection,
0164                           edm::ESHandle<CSCGeometry> cscGeom,
0165                           const edm::EventSetup &eventSetup,
0166                           const edm::Event &event);
0167     bool doHLT(edm::Handle<edm::TriggerResults> hltResults);
0168 
0169     // some useful functions
0170     bool filterEvents(edm::Handle<CSCRecHit2DCollection> recHits,
0171                       edm::Handle<CSCSegmentCollection> cscSegments,
0172                       edm::Handle<reco::TrackCollection> saMuons);
0173     float fitX(const CLHEP::HepMatrix &sp, const CLHEP::HepMatrix &ep);
0174     float getSignal(const CSCStripDigiCollection &stripdigis, CSCDetId idRH, int centerStrip);
0175     float getthisSignal(const CSCStripDigiCollection &stripdigis, CSCDetId idRH, int centerStrip);
0176     int getWidth(const CSCStripDigiCollection &stripdigis, CSCDetId idRH, int centerStrip);
0177     void findNonAssociatedRecHits(edm::ESHandle<CSCGeometry> cscGeom, edm::Handle<CSCStripDigiCollection> strips);
0178     int chamberSerial(CSCDetId id);
0179     int ringSerial(CSCDetId id);
0180 
0181     // these functions handle Stoyan's efficiency code
0182     void fillEfficiencyHistos(int bin, int flag);
0183     void getEfficiency(float bin, float Norm, std::vector<float> &eff);
0184     void histoEfficiency(TH1F *readHisto, TH1F *writeHisto);
0185     double lineParametrization(double z1Position, double z2Position, double z1Direction) {
0186       double parameterLine = (z2Position - z1Position) / z1Direction;
0187       return parameterLine;
0188     }
0189     double extrapolate1D(double initPosition, double initDirection, double parameterOfTheLine) {
0190       double extrapolatedPosition = initPosition + initDirection * parameterOfTheLine;
0191       return extrapolatedPosition;
0192     }
0193     bool withinSensitiveRegion(LocalPoint localPos,
0194                                const std::array<const float, 4> &layerBounds,
0195                                int station,
0196                                int ring,
0197                                float shiftFromEdge,
0198                                float shiftFromDeadZone);
0199 
0200     // counters
0201     int nEventsAnalyzed;
0202     int rhTreeCount;
0203     int segTreeCount;
0204     bool firstEvent;
0205     bool cleanEvent;
0206 
0207     //
0208     //
0209     // The root file for the histograms.
0210     TFile *theFile;
0211 
0212     //
0213     //
0214     // input parameters for this module
0215     bool makePlots;
0216     bool makeComparisonPlots;
0217     std::string refRootFile;
0218     bool writeTreeToFile;
0219     bool isSimulation;
0220     std::string rootFileName;
0221     bool detailedAnalysis;
0222     bool useDigis;
0223     bool makeHLTPlots;
0224 
0225     // filters
0226     bool useQualityFilter;
0227     bool useTriggerFilter;
0228 
0229     // quality filter parameters
0230     double pMin;
0231     double chisqMax;
0232     int nCSCHitsMin, nCSCHitsMax;
0233     double lengthMin, lengthMax;
0234     double deltaPhiMax;
0235     double polarMin, polarMax;
0236 
0237     edm::EDGetTokenT<FEDRawDataCollection> rd_token;
0238     edm::EDGetTokenT<CSCWireDigiCollection> wd_token;
0239     edm::EDGetTokenT<CSCStripDigiCollection> sd_token;
0240     edm::EDGetTokenT<CSCComparatorDigiCollection> cd_token;
0241     edm::EDGetTokenT<CSCALCTDigiCollection> al_token;
0242     edm::EDGetTokenT<CSCCLCTDigiCollection> cl_token;
0243     edm::EDGetTokenT<CSCCorrelatedLCTDigiCollection> co_token;
0244     edm::EDGetTokenT<CSCRecHit2DCollection> rh_token;
0245     edm::EDGetTokenT<CSCSegmentCollection> se_token;
0246     edm::EDGetTokenT<L1MuGMTReadoutCollection> l1_token;
0247     edm::EDGetTokenT<edm::TriggerResults> tr_token;
0248     edm::EDGetTokenT<reco::TrackCollection> sa_token;
0249     edm::EDGetTokenT<edm::PSimHitContainer> sh_token;
0250     // geometry
0251     edm::ESGetToken<CSCGeometry, MuonGeometryRecord> geomToken_;
0252     edm::ESGetToken<CSCCrateMap, CSCCrateMapRcd> crateToken_;
0253     // conditions data
0254     edm::ESGetToken<CSCDBPedestals, CSCDBPedestalsRcd> pedestalsToken_;
0255     edm::ESGetToken<CSCDBGains, CSCDBGainsRcd> gainsToken_;
0256     edm::ESGetToken<CSCDBNoiseMatrix, CSCDBNoiseMatrixRcd> noiseToken_;
0257     edm::ESGetToken<CSCDBCrosstalk, CSCDBCrosstalkRcd> crosstalkToken_;
0258 
0259     // module on/off switches
0260     bool makeOccupancyPlots;
0261     bool makeTriggerPlots;
0262     bool makeStripPlots;
0263     bool makeWirePlots;
0264     bool makeRecHitPlots;
0265     bool makeSimHitPlots;
0266     bool makeSegmentPlots;
0267     bool makeResolutionPlots;
0268     bool makePedNoisePlots;
0269     bool makeEfficiencyPlots;
0270     bool makeGasGainPlots;
0271     bool makeAFEBTimingPlots;
0272     bool makeCompTimingPlots;
0273     bool makeADCTimingPlots;
0274     bool makeRHNoisePlots;
0275     bool makeCalibPlots;
0276     bool makeStandalonePlots;
0277     bool makeTimeMonitorPlots;
0278 
0279     // The histo managing object
0280     CSCValHists *histos;
0281 
0282     // tmp histos for Efficiency
0283     TH1F *hSSTE;
0284     TH1F *hRHSTE;
0285     TH1F *hSEff;
0286     TH1F *hRHEff;
0287     TH2F *hSSTE2;
0288     TH2F *hRHSTE2;
0289     TH2F *hStripSTE2;
0290     TH2F *hWireSTE2;
0291     TH2F *hSEff2;
0292     TH2F *hRHEff2;
0293     TH2F *hStripEff2;
0294     TH2F *hWireEff2;
0295     TH2F *hEffDenominator;
0296     TH2F *hSensitiveAreaEvt;
0297 
0298     TH1F *hSSTETight;
0299     TH1F *hRHSTETight;
0300     TH2F *hSSTE2Tight;
0301     TH2F *hRHSTE2Tight;
0302     TH2F *hStripSTE2Tight;
0303     TH2F *hWireSTE2Tight;
0304     TH2F *hEffDenominatorTight;
0305 
0306     // occupancy
0307     TH2I *hOWires;
0308     TH2I *hOStrips;
0309     TH2I *hORecHits;
0310     TH2I *hOSegments;
0311 
0312     /// Maps and vectors for module doGasGain()
0313     std::vector<int> nmbhvsegm;
0314     std::map<int, std::vector<int> > m_wire_hvsegm;
0315     std::map<int, int> m_single_wire_layer;
0316 
0317     //maps to store the DetId and associated RecHits
0318     std::multimap<CSCDetId, CSCRecHit2D> AllRechits;
0319     std::multimap<CSCDetId, CSCRecHit2D> SegRechits;
0320     std::multimap<CSCDetId, CSCRecHit2D> NonAssociatedRechits;
0321     std::map<CSCRecHit2D, float, ltrh> distRHmap;
0322 
0323     int typeIndex(CSCDetId id) {
0324       // linearlized index bases on endcap, station, and ring
0325       int index = 0;
0326       if (id.station() == 1) {
0327         index = id.ring() + 1;
0328         if (id.ring() == 4)
0329           index = 1;
0330       } else
0331         index = id.station() * 2 + id.ring();
0332       if (id.endcap() == 1)
0333         index = index + 10;
0334       if (id.endcap() == 2)
0335         index = 11 - index;
0336       return index;
0337     }
0338   };
0339 }  // namespace
0340 #endif