CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_9_patch3/src/RecoLocalMuon/CSCEfficiency/src/CSCEfficiency.h

Go to the documentation of this file.
00001 #ifndef RecoLocalMuon_CSCEfficiency_H
00002 #define RecoLocalMuon_CSCEfficiency_H
00003 
00010 // how many of the headers below are not needed?...
00011 #include "FWCore/Framework/interface/EDFilter.h"
00012 #include "FWCore/Framework/interface/Event.h"
00013 #include "DataFormats/Common/interface/Handle.h"
00014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00015 #include <FWCore/Utilities/interface/InputTag.h>
00016 #include "FWCore/Framework/interface/EventSetup.h"
00017 #include "FWCore/Framework/interface/ESHandle.h"
00018 
00019 #include "DataFormats/CSCDigi/interface/CSCALCTDigi.h"
00020 #include "DataFormats/CSCDigi/interface/CSCALCTDigiCollection.h"
00021 #include "DataFormats/CSCDigi/interface/CSCCLCTDigi.h"
00022 #include "DataFormats/CSCDigi/interface/CSCCLCTDigiCollection.h"
00023 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigi.h"
00024 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
00025 
00026 #include "DataFormats/CSCRecHit/interface/CSCRecHit2DCollection.h"
00027 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00028 
00029 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00030 #include <DataFormats/CSCRecHit/interface/CSCSegmentCollection.h>
00031 
00032 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
00033 #include <Geometry/CSCGeometry/interface/CSCChamber.h>
00034 #include <Geometry/CSCGeometry/interface/CSCLayer.h>
00035 #include <Geometry/CSCGeometry/interface/CSCLayerGeometry.h>
00036 #include <Geometry/Records/interface/MuonGeometryRecord.h>
00037 
00038 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00039 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00040 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00041 #include "DataFormats/GeometryVector/interface/LocalVector.h"
00042 
00043 #include "DataFormats/CSCDigi/interface/CSCWireDigi.h"
00044 #include "DataFormats/CSCDigi/interface/CSCWireDigiCollection.h"
00045 #include "DataFormats/CSCDigi/interface/CSCStripDigi.h"
00046 #include "DataFormats/CSCDigi/interface/CSCStripDigiCollection.h"
00047 
00048 #include "DataFormats/CSCDigi/interface/CSCComparatorDigi.h"
00049 #include "DataFormats/CSCDigi/interface/CSCComparatorDigiCollection.h"
00050 
00051 #include "Utilities/Timing/interface/TimerStack.h"
00052  
00053 #include "FWCore/Framework/interface/MakerMacros.h"
00054 #include "FWCore/Framework/interface/Frameworkfwd.h"
00055 #include "FWCore/Framework/interface/Event.h"
00056 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00057 #include "FWCore/Framework/interface/EventSetup.h"
00058 #include "FWCore/Framework/interface/ESHandle.h"
00059 
00060 #include "DataFormats/TrackReco/interface/Track.h"
00061 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00062 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
00063 #include "Geometry/Records/interface/GlobalTrackingGeometryRecord.h"
00064 
00065 #include "TrackingTools/PatternTools/interface/TrajectoryMeasurement.h"
00066 #include "TrackingTools/DetLayers/interface/DetLayer.h"
00067 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00068 #include "TrackingTools/TrajectoryState/interface/FreeTrajectoryState.h"
00069 #include "TrackingTools/DetLayers/interface/NavigationDirection.h"
00070 #include "TrackingTools/GeomPropagators/interface/Propagator.h"
00071 
00072 #include <RecoMuon/TrackingTools/interface/MuonServiceProxy.h>
00073 #include "RecoMuon/TrackingTools/interface/MuonPatternRecoDumper.h"
00074 
00075 #include "DataFormats/Common/interface/TriggerResults.h"
00076 
00077 //#include "CLHEP/Matrix/DiagMatrix.h"
00078 #include "DataFormats/CLHEP/interface/AlgebraicObjects.h"
00079 #include "CLHEP/Matrix/Vector.h"
00080 #include "CLHEP/Vector/ThreeVector.h"
00081 
00082 #include "TFile.h"
00083 #include "TVector3.h"
00084 #include "TProfile.h"
00085 #include "TMath.h"
00086 #include "TH1F.h"
00087 #include "TH2F.h"
00088 #include "TString.h"
00089 
00090 #include <iostream>
00091 #include <iomanip>
00092 #include <fstream>
00093 //#include "Math/Interpolator.h"
00094 
00095 #include <vector>
00096 #include <map>
00097 #include <string>
00098 
00099 #define SQR(x) ((x)*(x))
00100 
00101 #define LastCh 36
00102 #define FirstCh  1
00103 #define NumCh (LastCh-FirstCh+1)
00104 
00105 namespace edm {
00106   class ParameterSet;
00107   class Event;
00108   class EventSetup;
00109   class TriggerNames;
00110 }
00111 
00112 class TFile;
00113 class CSCLayer;
00114 class CSCDetId;
00115 
00116 class CSCEfficiency : public edm::EDFilter {
00117 public:
00119   CSCEfficiency(const edm::ParameterSet& pset);
00120 
00122   virtual ~CSCEfficiency();
00123 
00124  private:
00125   virtual void beginJob() ;
00126   //---- analysis + filter
00127   virtual bool filter(edm::Event & event, const edm::EventSetup& eventSetup);
00128 
00129   virtual void endJob() ;
00130 
00131   //---- (input) parameters
00132   //---- Root file name
00133   std::string rootFileName;
00134   //---- digi/object tags
00135   edm::InputTag alctDigiTag_;
00136   edm::InputTag clctDigiTag_;
00137   edm::InputTag corrlctDigiTag_;
00138   edm::InputTag stripDigiTag_;
00139   edm::InputTag wireDigiTag_;
00140   edm::InputTag rechitDigiTag_;
00141   edm::InputTag simHitTag;
00142   edm::InputTag segmentDigiTag_;
00143   edm::InputTag tracksTag;
00144   //
00145   unsigned int printout_NEvents;
00146   bool isData;
00147   bool isIPdata;
00148   bool isBeamdata;
00149   bool getAbsoluteEfficiency;
00150   bool useDigis;
00151   double distanceFromDeadZone;
00152   double minP;
00153   double maxP;
00154   double maxNormChi2;
00155   unsigned int minTrackHits;
00156 
00157   bool applyIPangleCuts;
00158   double local_DY_DZ_Max;
00159   double local_DY_DZ_Min;
00160   double local_DX_DZ_Max;
00161 
00162   // trigger
00163   bool useTrigger;
00164   //edm::Handle<edm::TriggerResults> hltR
00165   edm::InputTag hlTriggerResults_;  // Input tag for TriggerResults
00166   std::vector<std::string> myTriggers;
00167   std::vector <int> pointToTriggers;
00168   bool andOr; 
00169 
00170 
00171   //---- The muon service
00172   MuonServiceProxy *theService;
00173   //---- The root file for the histograms
00174   TFile *theFile;
00175   //---- printalot debug output
00176   bool printalot;
00177   //---- counter
00178   int nEventsAnalyzed;
00179   //---- magnetic field
00180   bool magField;
00181   //---- track direction
00182   bool alongZ;
00183   //---- filter variable
00184   bool passTheEvent;
00185 
00186   //---- Variables
00187   //---- LCTs
00188   bool allCLCT[2][4][4][NumCh];//endcap/station/ring/chamber
00189   bool allALCT[2][4][4][NumCh];//endcap/station/ring/chamber
00190   bool allCorrLCT[2][4][4][NumCh];//endcap/station/ring/chamber
00191 
00192   //----  Strips: strip number and ADCPeak
00193   std::vector <std::pair <int, float> > allStrips[2][4][4][NumCh][6];//endcap/station/ring/chamber/layer
00194 
00195   //----Wires: WG number and Y-position, time bin
00196   std::vector <std::pair <std::pair <int, float>, int> > allWG[2][4][4][NumCh][6];//endcap/station/ring/chamber/layer
00197 
00198   //SetOfSimHits  (*all_SimHits)[2][4][4][ NumCh];
00199   //---- Simhits
00200   std::vector <std::pair <LocalPoint, int> > allSimhits[2][4][4][NumCh][6];//endcap/station/ring/chamber/layer
00201 
00202   //rechits
00203   //SetOfRecHits  (*all_RecHits)[2][4][4][ NumCh];
00204   std::vector <std::pair <LocalPoint, bool> > allRechits[2][4][4][NumCh][6];//endcap/station/ring/chamber/layer
00205 
00206   // segments
00207   std::vector <std::pair <LocalPoint, LocalVector> > allSegments[2][4][4][NumCh];//endcap/station/ring/chamber
00208 
00209   // empty chambers
00210   bool emptyChambers[2][4][4][NumCh];//endcap/station/ring/chamber
00211 
00212   //---- Functions
00213   void fillDigiInfo(edm::Handle<CSCALCTDigiCollection> &alcts, 
00214                 edm::Handle<CSCCLCTDigiCollection> &clcts, 
00215                 edm::Handle<CSCCorrelatedLCTDigiCollection> &correlatedlcts,
00216                 edm::Handle<CSCWireDigiCollection> &wires,
00217                 edm::Handle<CSCStripDigiCollection> &strips,
00218                 edm::Handle<edm::PSimHitContainer> &simhits,
00219                 edm::Handle<CSCRecHit2DCollection> &rechits,
00220                 edm::Handle<CSCSegmentCollection> &segments,
00221                 edm::ESHandle<CSCGeometry> &cscGeom);
00222   void fillLCT_info(edm::Handle<CSCALCTDigiCollection> &alcts, 
00223                     edm::Handle<CSCCLCTDigiCollection> &clcts, 
00224                     edm::Handle<CSCCorrelatedLCTDigiCollection> &correlatedlcts );
00225   void fillWG_info(edm::Handle<CSCWireDigiCollection> &wires, edm::ESHandle<CSCGeometry> &cscGeom);
00226   void fillStrips_info(edm::Handle<CSCStripDigiCollection> &strips);
00227   void fillRechitsSegments_info(edm::Handle<CSCRecHit2DCollection> &rechits,
00228                                 edm::Handle<CSCSegmentCollection> &segments,
00229                                 edm::ESHandle<CSCGeometry> &cscGeom);
00230   void fillSimhit_info(edm::Handle<edm::PSimHitContainer> &simHits);
00231 
00232   void ringCandidates(int station, float absEta, std::map <std::string, bool> & chamberTypes);
00233   void chamberCandidates(int station, int ring, float phi, std::vector <int> &coupleOfChambers);
00234 
00235   bool efficienciesPerChamber(CSCDetId & id, const CSCChamber* cscChamber, FreeTrajectoryState &ftsChamber);
00236   bool stripWire_Efficiencies(CSCDetId & cscDetId, FreeTrajectoryState &ftsChamber);
00237   bool recHitSegment_Efficiencies(CSCDetId & cscDetId, const CSCChamber* cscChamber, FreeTrajectoryState &ftsChamber);
00238   bool recSimHitEfficiency(CSCDetId & id, FreeTrajectoryState &ftsChamber);
00239   // 
00240   void returnTypes(CSCDetId & id, int &ec, int &st, int &rg, int &ch, int &secondRing);
00241   //  
00242   void getFromFTS(const FreeTrajectoryState& fts,
00243                   CLHEP::Hep3Vector& p3, CLHEP::Hep3Vector& r3,
00244                   int& charge, AlgebraicSymMatrix66& cov);
00245   
00246   FreeTrajectoryState getFromCLHEP(const CLHEP::Hep3Vector& p3, const CLHEP::Hep3Vector& r3,
00247                                    int charge, const AlgebraicSymMatrix66& cov,
00248                                    const MagneticField* field);
00249 
00250   void linearExtrapolation(GlobalPoint initialPosition ,GlobalVector initialDirection, 
00251                            float zSurface, std::vector <float> &posZY);
00252   double extrapolate1D(double initPosition, double initDirection, double parameterOfTheLine);
00253   double lineParameter(double initZPosition, double destZPosition, double initZDirection);
00254   bool inSensitiveLocalRegion(double xLocal, double yLocal, int station, int ring);
00255   bool checkLocal(double yLocal, double yBoundary, int station, int ring);
00256   void chooseDirection(CLHEP::Hep3Vector & innerPosition, CLHEP::Hep3Vector & outerPosition);
00257   const Propagator* propagator(std::string propagatorName) const ;
00258   TrajectoryStateOnSurface propagate(FreeTrajectoryState & ftsStart, const BoundPlane &bp);
00259   bool applyTrigger(edm::Handle<edm::TriggerResults> &hltR, const edm::TriggerNames & triggerNames);
00260   //bool applyTrigger(void);
00261 
00262 
00263   //---- Histograms 
00264     TH1F * DataFlow;
00265     TH1F * TriggersFired;
00266     //
00267     TH1F * ALCTPerEvent;
00268     TH1F * CLCTPerEvent;
00269     TH1F * recHitsPerEvent;
00270     TH1F * segmentsPerEvent;
00271 //---- Histogram set (stations)...
00272     struct StationHistos{
00273       TH1F * segmentChi2_ndf;
00274       TH1F * hitsInSegment;
00275       TH1F * AllSegments_eta;
00276       TH1F * EfficientSegments_eta;
00277       TH1F * ResidualSegments;
00278       TH2F * EfficientSegments_XY;
00279       TH2F * InefficientSegments_XY;
00280       TH1F * EfficientALCT_momTheta;
00281       TH1F * InefficientALCT_momTheta;
00282       TH1F * EfficientCLCT_momPhi;
00283       TH1F * InefficientCLCT_momPhi;
00284     }StHist[2][4];
00285 //---- Histogram set (chambers)...
00286   struct ChamberHistos{
00287     TH1F * EfficientRechits_inSegment;
00288     TH1F * InefficientSingleHits;
00289     TH1F * digiAppearanceCount;
00290     TH1F * AllSingleHits;
00291     TH1F * EfficientRechits_good;
00292     TH1F * EfficientALCT_dydz;
00293     TH1F * InefficientALCT_dydz;
00294     TH1F * EfficientCLCT_dxdz;
00295     TH1F * InefficientCLCT_dxdz;
00296     TH1F * EfficientStrips;
00297     TH1F * StripWiresCorrelations;
00298     TH1F * NoWires_momTheta;
00299     TH1F * NoStrips_momPhi;
00300     TH1F * EfficientWireGroups;
00301     std::vector<TH1F *> Y_InefficientRecHits_inSegment;
00302     std::vector<TH1F *> Y_EfficientRecHits_inSegment;
00303     std::vector<TH1F *> Phi_InefficientRecHits_inSegment;
00304     std::vector<TH1F *> Phi_EfficientRecHits_inSegment;
00305     //
00306     TH1F * SimRechits;
00307     TH1F * SimSimhits;
00308     /*
00309     TH1F * SimRechits_each;
00310     TH1F * SimSimhits_each;
00311     */
00312   }ChHist[2][4][3][LastCh-FirstCh+1];
00313 };
00314 
00315 #endif
00316 
00317 
00318 
00319