CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/RecoLocalMuon/CSCValidation/src/CSCValidation.h

Go to the documentation of this file.
00001 #ifndef RecoLocalMuon_CSCValidation_H
00002 #define RecoLocalMuon_CSCValidation_H
00003 
00018 // user include files
00019 #include "FWCore/Framework/interface/MakerMacros.h"
00020 #include "FWCore/Framework/interface/Frameworkfwd.h"
00021 #include "FWCore/Framework/interface/EDAnalyzer.h"
00022 #include "FWCore/Framework/interface/EDFilter.h"
00023 #include "FWCore/Framework/interface/Event.h"
00024 #include "DataFormats/Common/interface/Handle.h"
00025 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00026 #include "FWCore/Framework/interface/EventSetup.h"
00027 #include "FWCore/Framework/interface/ESHandle.h"
00028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00029 
00030 #include "DataFormats/CSCDigi/interface/CSCWireDigi.h"
00031 #include "DataFormats/CSCDigi/interface/CSCWireDigiCollection.h"
00032 #include "DataFormats/CSCDigi/interface/CSCStripDigi.h"
00033 #include "DataFormats/CSCDigi/interface/CSCStripDigiCollection.h"
00034 #include "DataFormats/CSCDigi/interface/CSCComparatorDigi.h"
00035 #include "DataFormats/CSCDigi/interface/CSCComparatorDigiCollection.h"
00036 #include "DataFormats/CSCDigi/interface/CSCALCTDigi.h"
00037 #include "DataFormats/CSCDigi/interface/CSCALCTDigiCollection.h"
00038 #include "DataFormats/CSCDigi/interface/CSCCLCTDigi.h"
00039 #include "DataFormats/CSCDigi/interface/CSCCLCTDigiCollection.h"
00040 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigi.h"
00041 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
00042 
00043 #include "EventFilter/CSCRawToDigi/interface/CSCDCCEventData.h"
00044 #include "EventFilter/CSCRawToDigi/interface/CSCDCCExaminer.h"
00045 #include "EventFilter/CSCRawToDigi/interface/CSCEventData.h"
00046 #include "EventFilter/CSCRawToDigi/interface/CSCCFEBData.h"
00047 #include "EventFilter/CSCRawToDigi/interface/CSCALCTHeader.h"
00048 #include "EventFilter/CSCRawToDigi/interface/CSCAnodeData.h"
00049 #include "EventFilter/CSCRawToDigi/interface/CSCCLCTData.h"
00050 #include "EventFilter/CSCRawToDigi/interface/CSCDDUEventData.h"
00051 #include "EventFilter/CSCRawToDigi/interface/CSCTMBData.h"
00052 #include "EventFilter/CSCRawToDigi/interface/CSCTMBHeader.h"
00053 #include "EventFilter/CSCRawToDigi/interface/CSCRPCData.h"
00054 #include "EventFilter/CSCRawToDigi/interface/CSCDCCExaminer.h"
00055 #include "EventFilter/CSCRawToDigi/interface/CSCDCCEventData.h"
00056 #include "EventFilter/CSCRawToDigi/interface/CSCCFEBData.h"
00057 #include "EventFilter/CSCRawToDigi/interface/CSCCFEBTimeSlice.h"
00058 #include "CondFormats/CSCObjects/interface/CSCCrateMap.h"
00059 #include "CondFormats/DataRecord/interface/CSCCrateMapRcd.h"
00060 #include <EventFilter/CSCRawToDigi/interface/CSCMonitorInterface.h>
00061 #include "FWCore/ServiceRegistry/interface/Service.h"
00062 //FEDRawData
00063 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00064 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00065 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00066 
00067 
00068 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00069 #include <DataFormats/CSCRecHit/interface/CSCRecHit2D.h>
00070 #include <DataFormats/CSCRecHit/interface/CSCSegmentCollection.h>
00071 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
00072 
00073 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutRecord.h"
00074 #include "DataFormats/L1GlobalMuonTrigger/interface/L1MuGMTReadoutCollection.h"
00075 #include "DataFormats/Common/interface/TriggerResults.h"
00076 #include "FWCore/Common/interface/TriggerNames.h"
00077 
00078 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
00079 #include "Geometry/CSCGeometry/interface/CSCChamber.h"
00080 #include "Geometry/CSCGeometry/interface/CSCLayer.h"
00081 #include "Geometry/CSCGeometry/interface/CSCLayerGeometry.h"
00082 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00083 
00084 #include "DataFormats/TrackReco/interface/Track.h"
00085 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00086 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
00087 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00088 
00089 #include "DataFormats/CSCRecHit/interface/CSCRecHit2DCollection.h"
00090 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00091 
00092 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00093 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00094 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00095 #include "DataFormats/GeometryVector/interface/LocalVector.h"
00096 #include "DataFormats/CLHEP/interface/AlgebraicObjects.h"
00097 #include "DataFormats/MuonDetId/interface/CSCIndexer.h"
00098 
00099 #include "CondFormats/CSCObjects/interface/CSCDBGains.h"
00100 #include "CondFormats/DataRecord/interface/CSCDBGainsRcd.h"
00101 #include "CondFormats/CSCObjects/interface/CSCDBNoiseMatrix.h"
00102 #include "CondFormats/DataRecord/interface/CSCDBNoiseMatrixRcd.h"
00103 #include "CondFormats/CSCObjects/interface/CSCDBCrosstalk.h"
00104 #include "CondFormats/DataRecord/interface/CSCDBCrosstalkRcd.h"
00105 #include "CondFormats/CSCObjects/interface/CSCDBPedestals.h"
00106 #include "CondFormats/DataRecord/interface/CSCDBPedestalsRcd.h"
00107 
00108 #include "CommonTools/Statistics/interface/ChiSquaredProbability.h"
00109 
00110 #include "RecoLocalMuon/CSCValidation/src/CSCValHists.h"
00111 #include "TVector3.h"
00112 #include "TH1F.h"
00113 #include "TH2F.h"
00114 #include "TFile.h"
00115 #include "TString.h"
00116 #include "TTree.h"
00117 #include "TProfile2D.h"
00118 
00119 class CSCValidation : public edm::EDAnalyzer {
00120 public:
00122   CSCValidation(const edm::ParameterSet& pset);
00123 
00125   virtual ~CSCValidation();
00126 
00128   void analyze(const edm::Event & event, const edm::EventSetup& eventSetup);
00129   void endJob();
00130 
00131   // for noise module
00132   struct ltrh
00133   {
00134     bool operator()(const CSCRecHit2D rh1, const CSCRecHit2D rh2) const
00135     {
00136       return ((rh1.localPosition()).x()-(rh2.localPosition()).x()) < 0;
00137     }
00138   };
00139 
00140 
00141 protected:
00142 
00143 private: 
00144 
00145   // these are the "modules"
00146   // if you would like to add code to CSCValidation, please do so by adding an
00147   // extra module in the form of an additional private member function
00148   void  doOccupancies(edm::Handle<CSCStripDigiCollection> strips, edm::Handle<CSCWireDigiCollection> wires,
00149                       edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<CSCSegmentCollection> cscSegments);
00150   void  doStripDigis(edm::Handle<CSCStripDigiCollection> strips);
00151   void  doWireDigis(edm::Handle<CSCWireDigiCollection> wires);
00152   void  doRecHits(edm::Handle<CSCRecHit2DCollection> recHits, edm::ESHandle<CSCGeometry> cscGeom);
00153   void  doSimHits(edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<edm::PSimHitContainer> simHits);
00154   void  doPedestalNoise(edm::Handle<CSCStripDigiCollection> strips);
00155   void  doSegments(edm::Handle<CSCSegmentCollection> cscSegments, edm::ESHandle<CSCGeometry> cscGeom);
00156   void  doResolution(edm::Handle<CSCSegmentCollection> cscSegments, edm::ESHandle<CSCGeometry> cscGeom);
00157   void  doEfficiencies(edm::Handle<CSCWireDigiCollection> wires, edm::Handle<CSCStripDigiCollection> strips,
00158                        edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<CSCSegmentCollection> cscSegments,
00159                        edm::ESHandle<CSCGeometry> cscGeom);
00160   void  doGasGain(const CSCWireDigiCollection &, const CSCStripDigiCollection &, const CSCRecHit2DCollection &);
00161   void  doCalibrations(const edm::EventSetup& eventSetup);
00162   void  doAFEBTiming(const CSCWireDigiCollection &);
00163   void  doCompTiming(const CSCComparatorDigiCollection &);
00164   void  doADCTiming(const CSCRecHit2DCollection  &);
00165   void  doNoiseHits(edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<CSCSegmentCollection> cscSegments,
00166                     edm::ESHandle<CSCGeometry> cscGeom,  edm::Handle<CSCStripDigiCollection> strips);
00167   bool  doTrigger(edm::Handle<L1MuGMTReadoutCollection> pCollection);
00168   void  doStandalone(edm::Handle<reco::TrackCollection> saMuons);
00169   void  doTimeMonitoring(edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<CSCSegmentCollection> cscSegments,
00170                          edm::Handle<CSCALCTDigiCollection> alcts, edm::Handle<CSCCLCTDigiCollection> clcts,
00171                          edm::Handle<CSCCorrelatedLCTDigiCollection> correlatedlcts,
00172                          edm::Handle<L1MuGMTReadoutCollection> pCollection, edm::ESHandle<CSCGeometry> cscGeom,
00173                          const edm::EventSetup& eventSetup, const edm::Event &event);
00174   bool  doHLT(edm::Handle<edm::TriggerResults> hltResults);
00175 
00176 
00177   // some useful functions
00178   bool   filterEvents(edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<CSCSegmentCollection> cscSegments,
00179                       edm::Handle<reco::TrackCollection> saMuons);
00180   float  fitX(CLHEP::HepMatrix sp, CLHEP::HepMatrix ep);
00181   float  getSignal(const CSCStripDigiCollection& stripdigis, CSCDetId idRH, int centerStrip);
00182   float  getthisSignal(const CSCStripDigiCollection& stripdigis, CSCDetId idRH, int centerStrip);
00183   int    getWidth(const CSCStripDigiCollection& stripdigis, CSCDetId idRH, int centerStrip);
00184   void   findNonAssociatedRecHits(edm::ESHandle<CSCGeometry> cscGeom,  edm::Handle<CSCStripDigiCollection> strips);
00185   int    chamberSerial( CSCDetId id );
00186   int    ringSerial( CSCDetId id );
00187 
00188   // these functions handle Stoyan's efficiency code
00189   void  fillEfficiencyHistos(int bin, int flag);
00190   void  getEfficiency(float bin, float Norm, std::vector<float> &eff);
00191   void  histoEfficiency(TH1F *readHisto, TH1F *writeHisto);
00192   double lineParametrization(double z1Position, double z2Position, double z1Direction){
00193     double parameterLine = (z2Position-z1Position)/z1Direction;
00194     return parameterLine;
00195   }
00196   double extrapolate1D(double initPosition, double initDirection, double parameterOfTheLine){
00197     double extrapolatedPosition = initPosition + initDirection*parameterOfTheLine;
00198     return extrapolatedPosition; 
00199   }
00200     bool withinSensitiveRegion(LocalPoint localPos, const std::array<const float, 4> & layerBounds, int station, int ring, float shiftFromEdge, float shiftFromDeadZone);
00201 
00202 
00203   // counters
00204   int nEventsAnalyzed;
00205   int rhTreeCount;
00206   int segTreeCount;
00207   bool firstEvent;
00208   bool cleanEvent;
00209 
00210   //
00211   //
00212   // The root file for the histograms.
00213   TFile *theFile;
00214 
00215   //
00216   //
00217   // input parameters for this module
00218   bool makePlots;
00219   bool makeComparisonPlots;
00220   std::string refRootFile;
00221   bool writeTreeToFile;
00222   bool isSimulation;
00223   std::string rootFileName;
00224   bool detailedAnalysis;
00225   bool useDigis;
00226   bool makeHLTPlots;
00227 
00228   // filters
00229   bool useQualityFilter;
00230   bool useTriggerFilter;
00231 
00232   // quality filter parameters
00233   double pMin;
00234   double chisqMax;
00235   int    nCSCHitsMin, nCSCHitsMax;
00236   double lengthMin, lengthMax;
00237   double deltaPhiMax;
00238   double polarMin, polarMax;
00239 
00240 
00241   edm::InputTag stripDigiTag;
00242   edm::InputTag wireDigiTag;
00243   edm::InputTag compDigiTag;
00244   edm::InputTag cscRecHitTag;
00245   edm::InputTag cscSegTag;
00246   edm::InputTag saMuonTag;
00247   edm::InputTag l1aTag;
00248   edm::InputTag simHitTag;
00249   edm::InputTag alctDigiTag;
00250   edm::InputTag clctDigiTag;
00251   edm::InputTag corrlctDigiTag;
00252   edm::InputTag hltTag;
00253 
00254   // module on/off switches
00255   bool makeOccupancyPlots;
00256   bool makeTriggerPlots;
00257   bool makeStripPlots;
00258   bool makeWirePlots;
00259   bool makeRecHitPlots;
00260   bool makeSimHitPlots;
00261   bool makeSegmentPlots;
00262   bool makeResolutionPlots;
00263   bool makePedNoisePlots;
00264   bool makeEfficiencyPlots;
00265   bool makeGasGainPlots;
00266   bool makeAFEBTimingPlots;
00267   bool makeCompTimingPlots;
00268   bool makeADCTimingPlots;
00269   bool makeRHNoisePlots;
00270   bool makeCalibPlots;
00271   bool makeStandalonePlots;
00272   bool makeTimeMonitorPlots;
00273 
00274   // The histo managing object
00275   CSCValHists *histos;
00276 
00277   // tmp histos for Efficiency
00278   TH1F *hSSTE;
00279   TH1F *hRHSTE;
00280   TH1F *hSEff;
00281   TH1F *hRHEff;
00282   TH2F *hSSTE2;
00283   TH2F *hRHSTE2;
00284   TH2F *hStripSTE2;
00285   TH2F *hWireSTE2;
00286   TH2F *hSEff2;
00287   TH2F *hRHEff2;
00288   TH2F *hStripEff2;
00289   TH2F *hWireEff2;
00290   TH2F *hEffDenominator;
00291   TH2F *hSensitiveAreaEvt;
00292 
00293   // occupancy
00294   TH2I *hOWires;
00295   TH2I *hOStrips;
00296   TH2I *hORecHits;
00297   TH2I *hOSegments;
00298 
00300   std::vector<int>     nmbhvsegm;
00301   std::map<int, std::vector<int> >   m_wire_hvsegm;
00302   std::map<int, int>   m_single_wire_layer;
00303 
00304   //maps to store the DetId and associated RecHits  
00305   std::multimap<CSCDetId , CSCRecHit2D> AllRechits;
00306   std::multimap<CSCDetId , CSCRecHit2D> SegRechits;
00307   std::multimap<CSCDetId , CSCRecHit2D> NonAssociatedRechits;
00308   std::map<CSCRecHit2D,float,ltrh> distRHmap;
00309 
00310   int typeIndex(CSCDetId id){
00311     // linearlized index bases on endcap, station, and ring
00312     int index = 0;
00313     if (id.station() == 1){
00314       index = id.ring() + 1;
00315       if (id.ring() == 4) index = 1;
00316     }
00317     else index = id.station()*2 + id.ring();
00318     if (id.endcap() == 1) index = index + 10;
00319     if (id.endcap() == 2) index = 11 - index;
00320     return index;
00321   }
00322   
00323 
00324 
00325 
00326 };
00327 #endif