Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2022-05-03 02:56:59

0001 #ifndef RecoLocalMuon_CSCEfficiency_H
0002 #define RecoLocalMuon_CSCEfficiency_H
0003 
0004 /** \class CSCEfficiency
0005  *
0006  * Efficiency calculations
0007  * Stoyan Stoynev, Northwestern University
0008  */
0009 
0010 // how many of the headers below are not needed?...
0011 #include "FWCore/Framework/interface/ConsumesCollector.h"
0012 #include "FWCore/Framework/interface/Frameworkfwd.h"
0013 #include "FWCore/Framework/interface/one/EDFilter.h"
0014 #include "FWCore/Framework/interface/Event.h"
0015 #include "FWCore/Framework/interface/MakerMacros.h"
0016 #include "DataFormats/Common/interface/Handle.h"
0017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0018 #include "FWCore/Utilities/interface/InputTag.h"
0019 #include "FWCore/Framework/interface/EventSetup.h"
0020 
0021 #include "DataFormats/CSCDigi/interface/CSCALCTDigiCollection.h"
0022 #include "DataFormats/CSCDigi/interface/CSCCLCTDigiCollection.h"
0023 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
0024 #include "DataFormats/CSCDigi/interface/CSCWireDigiCollection.h"
0025 #include "DataFormats/CSCDigi/interface/CSCStripDigiCollection.h"
0026 #include "DataFormats/CSCDigi/interface/CSCComparatorDigiCollection.h"
0027 
0028 #include "DataFormats/CSCRecHit/interface/CSCRecHit2DCollection.h"
0029 #include "DataFormats/CSCRecHit/interface/CSCSegmentCollection.h"
0030 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0031 
0032 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
0033 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0034 
0035 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0036 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
0037 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
0038 #include "DataFormats/GeometryVector/interface/LocalVector.h"
0039 
0040 #include "DataFormats/TrackReco/interface/Track.h"
0041 #include "DataFormats/TrackReco/interface/TrackFwd.h"
0042 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
0043 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
0044 
0045 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
0046 #include "TrackingTools/DetLayers/interface/DetLayer.h"
0047 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
0048 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
0049 #include "TrackingTools/DetLayers/interface/NavigationDirection.h"
0050 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
0051 
0052 #include "RecoMuon/TrackingTools/interface/MuonServiceProxy.h"
0053 #include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h"
0054 
0055 #include "DataFormats/Common/interface/TriggerResults.h"
0056 
0057 #include "DataFormats/CLHEP/interface/AlgebraicObjects.h"
0058 #include "CLHEP/Matrix/Vector.h"
0059 #include "CLHEP/Vector/ThreeVector.h"
0060 
0061 #include "TFile.h"
0062 #include "TVector3.h"
0063 #include "TProfile.h"
0064 #include "TMath.h"
0065 #include "TH1F.h"
0066 #include "TH2F.h"
0067 #include "TString.h"
0068 
0069 #include <iostream>
0070 #include <iomanip>
0071 #include <fstream>
0072 //#include "Math/Interpolator.h"
0073 
0074 #include <vector>
0075 #include <map>
0076 #include <string>
0077 
0078 #define SQR(x) ((x) * (x))
0079 
0080 #define LastCh 36
0081 #define FirstCh 1
0082 #define NumCh (LastCh - FirstCh + 1)
0083 
0084 namespace edm {
0085   class ParameterSet;
0086   class Event;
0087   class EventSetup;
0088   class TriggerNames;
0089 }  // namespace edm
0090 
0091 class TFile;
0092 class CSCLayer;
0093 class CSCDetId;
0094 
0095 class CSCEfficiency : public edm::one::EDFilter<> {
0096 public:
0097   /// Constructor
0098   CSCEfficiency(const edm::ParameterSet &pset);
0099 
0100   /// Destructor
0101   ~CSCEfficiency() override;
0102 
0103 private:
0104   //---- analysis + filter
0105   bool filter(edm::Event &event, const edm::EventSetup &eventSetup) override;
0106 
0107   //---- (input) parameters
0108   //---- Root file name
0109   std::string rootFileName;
0110 
0111   //---- digi/object tokens
0112 
0113   edm::EDGetTokenT<CSCWireDigiCollection> wd_token;
0114   edm::EDGetTokenT<CSCStripDigiCollection> sd_token;
0115   edm::EDGetTokenT<CSCALCTDigiCollection> al_token;
0116   edm::EDGetTokenT<CSCCLCTDigiCollection> cl_token;
0117   edm::EDGetTokenT<CSCCorrelatedLCTDigiCollection> co_token;
0118   edm::EDGetTokenT<CSCRecHit2DCollection> rh_token;
0119   edm::EDGetTokenT<CSCSegmentCollection> se_token;
0120 
0121   edm::EDGetTokenT<edm::View<reco::Track> > tk_token;
0122   edm::EDGetTokenT<edm::PSimHitContainer> sh_token;
0123 
0124   edm::EDGetTokenT<edm::TriggerResults> ht_token;
0125 
0126   edm::ESGetToken<CSCGeometry, MuonGeometryRecord> geomToken_;
0127 
0128   //
0129   unsigned int printout_NEvents;
0130   bool isData;
0131   bool isIPdata;
0132   bool isBeamdata;
0133   bool getAbsoluteEfficiency;
0134   bool useDigis;
0135   double distanceFromDeadZone;
0136   double minP;
0137   double maxP;
0138   double maxNormChi2;
0139   unsigned int minTrackHits;
0140 
0141   bool applyIPangleCuts;
0142   double local_DY_DZ_Max;
0143   double local_DY_DZ_Min;
0144   double local_DX_DZ_Max;
0145 
0146   // trigger
0147   bool useTrigger;
0148   std::vector<std::string> myTriggers;
0149   std::vector<int> pointToTriggers;
0150   bool andOr;
0151 
0152   //---- The muon service
0153   MuonServiceProxy *theService;
0154   //---- The root file for the histograms
0155   TFile *theFile;
0156   //---- printalot debug output
0157   bool printalot;
0158   //---- counter
0159   int nEventsAnalyzed;
0160   //---- magnetic field
0161   bool magField;
0162   //---- track direction
0163   bool alongZ;
0164   //---- filter variable
0165   bool passTheEvent;
0166 
0167   //---- Variables
0168   //---- LCTs
0169   bool allCLCT[2][4][4][NumCh];     //endcap/station/ring/chamber
0170   bool allALCT[2][4][4][NumCh];     //endcap/station/ring/chamber
0171   bool allCorrLCT[2][4][4][NumCh];  //endcap/station/ring/chamber
0172 
0173   //----  Strips: strip number and ADCPeak
0174   std::vector<std::pair<int, float> > allStrips[2][4][4][NumCh][6];  //endcap/station/ring/chamber/layer
0175 
0176   //----Wires: WG number and Y-position, time bin
0177   std::vector<std::pair<std::pair<int, float>, int> > allWG[2][4][4][NumCh][6];  //endcap/station/ring/chamber/layer
0178 
0179   //SetOfSimHits  (*all_SimHits)[2][4][4][ NumCh];
0180   //---- Simhits
0181   std::vector<std::pair<LocalPoint, int> > allSimhits[2][4][4][NumCh][6];  //endcap/station/ring/chamber/layer
0182 
0183   //rechits
0184   //SetOfRecHits  (*all_RecHits)[2][4][4][ NumCh];
0185   std::vector<std::pair<LocalPoint, bool> > allRechits[2][4][4][NumCh][6];  //endcap/station/ring/chamber/layer
0186 
0187   // segments
0188   std::vector<std::pair<LocalPoint, LocalVector> > allSegments[2][4][4][NumCh];  //endcap/station/ring/chamber
0189 
0190   // empty chambers
0191   bool emptyChambers[2][4][4][NumCh];  //endcap/station/ring/chamber
0192 
0193   //---- Functions
0194   void fillDigiInfo(edm::Handle<CSCALCTDigiCollection> &alcts,
0195                     edm::Handle<CSCCLCTDigiCollection> &clcts,
0196                     edm::Handle<CSCCorrelatedLCTDigiCollection> &correlatedlcts,
0197                     edm::Handle<CSCWireDigiCollection> &wires,
0198                     edm::Handle<CSCStripDigiCollection> &strips,
0199                     edm::Handle<edm::PSimHitContainer> &simhits,
0200                     edm::Handle<CSCRecHit2DCollection> &rechits,
0201                     edm::Handle<CSCSegmentCollection> &segments,
0202                     edm::ESHandle<CSCGeometry> &cscGeom);
0203   void fillLCT_info(edm::Handle<CSCALCTDigiCollection> &alcts,
0204                     edm::Handle<CSCCLCTDigiCollection> &clcts,
0205                     edm::Handle<CSCCorrelatedLCTDigiCollection> &correlatedlcts);
0206   void fillWG_info(edm::Handle<CSCWireDigiCollection> &wires, edm::ESHandle<CSCGeometry> &cscGeom);
0207   void fillStrips_info(edm::Handle<CSCStripDigiCollection> &strips);
0208   void fillRechitsSegments_info(edm::Handle<CSCRecHit2DCollection> &rechits,
0209                                 edm::Handle<CSCSegmentCollection> &segments,
0210                                 edm::ESHandle<CSCGeometry> &cscGeom);
0211   void fillSimhit_info(edm::Handle<edm::PSimHitContainer> &simHits);
0212 
0213   void ringCandidates(int station, float absEta, std::map<std::string, bool> &chamberTypes);
0214   void chamberCandidates(int station, int ring, float phi, std::vector<int> &coupleOfChambers);
0215 
0216   bool efficienciesPerChamber(CSCDetId &id, const CSCChamber *cscChamber, FreeTrajectoryState &ftsChamber);
0217   bool stripWire_Efficiencies(CSCDetId &cscDetId, FreeTrajectoryState &ftsChamber);
0218   bool recHitSegment_Efficiencies(CSCDetId &cscDetId, const CSCChamber *cscChamber, FreeTrajectoryState &ftsChamber);
0219   bool recSimHitEfficiency(CSCDetId &id, FreeTrajectoryState &ftsChamber);
0220   //
0221   void returnTypes(CSCDetId &id, int &ec, int &st, int &rg, int &ch, int &secondRing);
0222   //
0223   void getFromFTS(const FreeTrajectoryState &fts,
0224                   CLHEP::Hep3Vector &p3,
0225                   CLHEP::Hep3Vector &r3,
0226                   int &charge,
0227                   AlgebraicSymMatrix66 &cov);
0228 
0229   FreeTrajectoryState getFromCLHEP(const CLHEP::Hep3Vector &p3,
0230                                    const CLHEP::Hep3Vector &r3,
0231                                    int charge,
0232                                    const AlgebraicSymMatrix66 &cov,
0233                                    const MagneticField *field);
0234 
0235   void linearExtrapolation(GlobalPoint initialPosition,
0236                            GlobalVector initialDirection,
0237                            float zSurface,
0238                            std::vector<float> &posZY);
0239   double extrapolate1D(double initPosition, double initDirection, double parameterOfTheLine);
0240   double lineParameter(double initZPosition, double destZPosition, double initZDirection);
0241   bool inSensitiveLocalRegion(double xLocal, double yLocal, int station, int ring);
0242   bool checkLocal(double yLocal, double yBoundary, int station, int ring);
0243   void chooseDirection(CLHEP::Hep3Vector &innerPosition, CLHEP::Hep3Vector &outerPosition);
0244   const Propagator *propagator(std::string propagatorName) const;
0245   TrajectoryStateOnSurface propagate(FreeTrajectoryState &ftsStart, const BoundPlane &bp);
0246   bool applyTrigger(edm::Handle<edm::TriggerResults> &hltR, const edm::TriggerNames &triggerNames);
0247   //bool applyTrigger(void);
0248 
0249   //---- Histograms
0250   TH1F *DataFlow;
0251   TH1F *TriggersFired;
0252   //
0253   TH1F *ALCTPerEvent;
0254   TH1F *CLCTPerEvent;
0255   TH1F *recHitsPerEvent;
0256   TH1F *segmentsPerEvent;
0257   //---- Histogram set (stations)...
0258   struct StationHistos {
0259     TH1F *segmentChi2_ndf;
0260     TH1F *hitsInSegment;
0261     TH1F *AllSegments_eta;
0262     TH1F *EfficientSegments_eta;
0263     TH1F *ResidualSegments;
0264     TH2F *EfficientSegments_XY;
0265     TH2F *InefficientSegments_XY;
0266     TH1F *EfficientALCT_momTheta;
0267     TH1F *InefficientALCT_momTheta;
0268     TH1F *EfficientCLCT_momPhi;
0269     TH1F *InefficientCLCT_momPhi;
0270   } StHist[2][4];
0271   //---- Histogram set (chambers)...
0272   struct ChamberHistos {
0273     TH1F *EfficientRechits_inSegment;
0274     TH1F *InefficientSingleHits;
0275     TH1F *digiAppearanceCount;
0276     TH1F *AllSingleHits;
0277     TH1F *EfficientRechits_good;
0278     TH1F *EfficientALCT_dydz;
0279     TH1F *InefficientALCT_dydz;
0280     TH1F *EfficientCLCT_dxdz;
0281     TH1F *InefficientCLCT_dxdz;
0282     TH1F *EfficientStrips;
0283     TH1F *StripWiresCorrelations;
0284     TH1F *NoWires_momTheta;
0285     TH1F *NoStrips_momPhi;
0286     TH1F *EfficientWireGroups;
0287     std::vector<TH1F *> Y_InefficientRecHits_inSegment;
0288     std::vector<TH1F *> Y_EfficientRecHits_inSegment;
0289     std::vector<TH1F *> Phi_InefficientRecHits_inSegment;
0290     std::vector<TH1F *> Phi_EfficientRecHits_inSegment;
0291     //
0292     TH1F *SimRechits;
0293     TH1F *SimSimhits;
0294     /*
0295     TH1F * SimRechits_each;
0296     TH1F * SimSimhits_each;
0297     */
0298   } ChHist[2][4][3][LastCh - FirstCh + 1];
0299 };
0300 
0301 #endif