CMS 3D CMS Logo

CSCEfficiency.h

Go to the documentation of this file.
00001 #ifndef RecoLocalMuon_CSCEfficiency_H
00002 #define RecoLocalMuon_CSCEfficiency_H
00003 
00010 #include "FWCore/Framework/interface/EDAnalyzer.h"
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "DataFormats/Common/interface/Handle.h"
00013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00014 #include <FWCore/ParameterSet/interface/InputTag.h>
00015 #include "FWCore/Framework/interface/EventSetup.h"
00016 #include "FWCore/Framework/interface/ESHandle.h"
00017 
00018 #include "DataFormats/CSCDigi/interface/CSCALCTDigi.h"
00019 #include "DataFormats/CSCDigi/interface/CSCALCTDigiCollection.h"
00020 #include "DataFormats/CSCDigi/interface/CSCCLCTDigi.h"
00021 #include "DataFormats/CSCDigi/interface/CSCCLCTDigiCollection.h"
00022 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigi.h"
00023 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
00024 
00025 //#include "RecoLocalMuon/CSCRecHit/src/CSCWireCluster.h"
00026 #include "DataFormats/CSCRecHit/interface/CSCRecHit2DCollection.h"
00027 
00028 #include "SimMuon/MCTruth/interface/PSimHitMap.h"
00029 
00030 #include "DataFormats/MuonDetId/interface/CSCDetId.h"
00031 #include <DataFormats/CSCRecHit/interface/CSCSegmentCollection.h>
00032 
00033 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
00034 #include <Geometry/CSCGeometry/interface/CSCChamber.h>
00035 #include <Geometry/CSCGeometry/interface/CSCLayer.h>
00036 #include <Geometry/CSCGeometry/interface/CSCLayerGeometry.h>
00037 #include <Geometry/Records/interface/MuonGeometryRecord.h>
00038 
00039 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00040 #include "DataFormats/GeometryVector/interface/GlobalVector.h"
00041 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00042 #include "DataFormats/GeometryVector/interface/LocalVector.h"
00043 
00044 #include "DataFormats/CSCDigi/interface/CSCWireDigi.h"
00045 #include "DataFormats/CSCDigi/interface/CSCWireDigiCollection.h"
00046 #include "DataFormats/CSCDigi/interface/CSCStripDigi.h"
00047 #include "DataFormats/CSCDigi/interface/CSCStripDigiCollection.h"
00048 
00049 #include "DataFormats/CSCDigi/interface/CSCComparatorDigi.h"
00050 #include "DataFormats/CSCDigi/interface/CSCComparatorDigiCollection.h"
00051 
00052 #include "Utilities/Timing/interface/TimerStack.h"
00053  
00054 #include "FWCore/Framework/interface/MakerMacros.h"
00055 #include "FWCore/Framework/interface/Frameworkfwd.h"
00056 #include "FWCore/Framework/interface/Event.h"
00057 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00058 #include "FWCore/Framework/interface/EventSetup.h"
00059 #include "FWCore/Framework/interface/ESHandle.h"
00060 
00061 #include "TFile.h"
00062 #include "TVector3.h"
00063 #include "TProfile.h"
00064 #include "TMath.h"
00065 #include "TH1F.h"
00066 #include "TH2F.h"
00067 #include "TString.h"
00068 #include "TGraphAsymmErrors.h"
00069 
00070 #include <iostream>
00071 #include <iomanip>
00072 #include <fstream>
00073 //#include "Math/Interpolator.h"
00074 
00075 
00076 
00077 //#include "myHistograms.h"
00078 
00079 #include <vector>
00080 #include <map>
00081 #include <string>
00082 
00083 #define SQR(x) ((x)*(x))
00084 
00085 #define LastCh 36
00086 #define FirstCh  1
00087 #define NumCh (LastCh-FirstCh+1)
00088 //---- Useful structures 
00089 struct ChamberRecHits{
00090   std::map<int,  std::vector <double> > RecHitsPosXlocal; // layers vs number of hits
00091   std::map<int,  std::vector <double> > RecHitsPosYlocal;
00092   std::map<int,  std::vector <double> > RecHitsPosX; 
00093   std::map<int,  std::vector <double> > RecHitsPosY;
00094   std::map<int,  std::vector <double> > RecHitsPosZ;
00095   std::map<int,  int > NRecHits;
00096   std::map<int,  int > TheRightRecHit;
00097   int nSegments;
00098   ChamberRecHits(){
00099     std::vector <double> Zero;
00100     nSegments = 0;
00101     for (int iLayer=0;iLayer<6;iLayer++){
00102       RecHitsPosXlocal[iLayer] = Zero;
00103       RecHitsPosYlocal[iLayer] = Zero;
00104       RecHitsPosX[iLayer] = Zero;
00105       RecHitsPosY[iLayer] = Zero;
00106       RecHitsPosZ[iLayer] = Zero;
00107       TheRightRecHit[iLayer] = -1;
00108       NRecHits[iLayer] = 0;
00109     }
00110   }
00111 } ; 
00112 struct SetOfRecHits{
00113   ChamberRecHits sChamber;
00114 } ;
00115 //
00116 struct ChamberSimHits{
00117   std::map<int,  std::vector <double> > SimHitsPosXlocal; // layers vs number of hits
00118   std::map<int,  std::vector <double> > SimHitsPosYlocal;
00119   std::map<int,  std::vector <double> > SimHitsEnergy; 
00120   std::map<int,  std::vector <int> > SimHitsPID;
00121   std::vector <int > NSimHits;
00122   ChamberSimHits(){
00123     std::vector <double> Zero;
00124     std::vector <int> iZero;
00125     for (int iLayer=0;iLayer<6;iLayer++){
00126       SimHitsPosXlocal[iLayer] = Zero;
00127       SimHitsPosYlocal[iLayer] = Zero;
00128       SimHitsEnergy[iLayer] = Zero;
00129       SimHitsPID[iLayer] = iZero;
00130       NSimHits.push_back(0);
00131     }
00132   }
00133 };
00134 struct SetOfSimHits{
00135   ChamberSimHits sChamber;
00136 } ;
00137 
00138 
00139 namespace edm {
00140   class ParameterSet;
00141   class Event;
00142   class EventSetup;
00143 }
00144 
00145 //class PSimHit;
00146 class TFile;
00147 class CSCLayer;
00148 class CSCDetId;
00149 
00150 class CSCEfficiency : public edm::EDAnalyzer {
00151 public:
00153   CSCEfficiency(const edm::ParameterSet& pset);
00154 
00156   virtual ~CSCEfficiency();
00157 
00158   // Operations
00159 
00160   //---- Perform the real analysis
00161   void analyze(const edm::Event & event, const edm::EventSetup& eventSetup);
00162 
00163 protected:
00164 
00165 private:
00166 
00167   edm::InputTag stripDigiTag_;
00168   edm::InputTag wireDigiTag_;
00169 
00170   //---- Variables
00171 
00172   SetOfRecHits  (*all_RecHits)[2][4][4][ NumCh];
00173   SetOfSimHits  (*all_SimHits)[2][4][4][ NumCh];
00174 
00175   //---- Strip number and ADCPeak
00176   std::vector <std::pair <int, float> > AllStrips[2][4][4][NumCh][6];//endcap/station/ring/chamber/layer
00177 
00178   //---- WG number and Y-position, time bin
00179   std::vector <std::pair <std::pair <int, float>, int> > AllWG[2][4][4][NumCh][6];//endcap/station/ring/chamber/layer
00180 
00181   //---- Functions
00182   void CalculateEfficiencies(const edm::Event & event, const edm::EventSetup& eventSetup,
00183                           std::vector<double> &Pos , std::vector<double> &Dir, int NSegFound, double theta);
00184   void RecHitEfficiency(double Yprime, double Yright, int iCh);
00185   bool LCT_Efficiencies(edm::Handle<CSCALCTDigiCollection> alcts,     
00186                                   edm::Handle<CSCCLCTDigiCollection> clcts,
00187                                   edm::Handle<CSCCorrelatedLCTDigiCollection> correlatedlcts, int iCh, int cond);
00188   void StripWire_Efficiencies (int iCh);
00189   void Segment_Efficiency (int iCh, int NSegmentsFound, double theta);
00190   void RecSimHitEfficiency(void);
00191 
00192   //---- counter
00193   int nEventsAnalyzed;
00194 
00195   //---- Histograms 
00196     TH1F * DataFlow;
00197     //
00198     TH1F * Chi2;
00199     TH1F * Chi2_ME1_a;
00200     TH1F * Chi2_ME1_b;
00201     TH1F * Chi2_ME1_2;
00202     TH1F * Chi2_ME1_3;
00203     TH1F * Chi2_ME2_1;
00204     TH1F * Chi2_ME2_2;
00205     TH1F * Chi2_ME3_1;
00206     TH1F * Chi2_ME3_2;
00207     TH1F * Chi2_ME4_1;
00208     //
00209     TH2F * XY_ALCTmissing;
00210     TH1F * dydz_Eff_ALCT;
00211     TH1F * dydz_All_ALCT;
00212     TH1F * FINAL_dydz_Efficiency_ALCT;
00213     //
00214     TH1F * EfficientSegments;
00215     TH1F * AllSegments;
00216     TH1F * EfficientSegments_theta;
00217     TH1F * AllSegments_theta;
00218     TH1F * EfficientRechits_inSegment;
00219     TH1F * InefficientSingleHits;
00220     TH1F * AllSingleHits;
00221     TH2F * XvsY_InefficientRecHits;
00222     TH2F * XvsY_InefficientRecHits_good;
00223     TH2F * XvsY_InefficientSegments;
00224     TH2F * XvsY_InefficientSegments_good;
00225     TH1F * EfficientRechits;
00226     TH1F * EfficientRechits_good;
00227     TH1F * EfficientLCTs;
00228     TH1F * EfficientStrips;
00229     TH1F * EfficientWireGroups;
00230     TH1F * Rechit_eff;
00231     std::vector<TH2F *> XvsY_InefficientRecHits_inSegment;
00232     std::vector<TH1F *> Y_InefficientRecHits_inSegment;
00233     std::vector<TH1F *> Y_AllRecHits_inSegment; 
00234     //
00235     TH1F * SimRechits;
00236     TH1F * SimSimhits;
00237     TH1F * SimRechits_each;
00238     TH1F * SimSimhits_each;
00239 //---- Efficiencies
00240     TH1F * FINAL_Segment_Efficiency;
00241     TH1F * FINAL_Segment_Efficiency_theta;
00242     TH1F * FINAL_Rechit_inSegment_Efficiency;
00243     TH1F * FINAL_Attachment_Efficiency;
00244     TH1F * FINAL_Rechit_Efficiency;
00245     TH1F * FINAL_Rechit_Efficiency_good;
00246     TH1F * FINAL_LCTs_Efficiency;
00247     TH1F * FINAL_Strip_Efficiency;
00248     TH1F * FINAL_WireGroup_Efficiency;
00249     std::vector<TH1F *> FINAL_Y_RecHit_InSegment_Efficiency;
00250     TH1F * FINAL_SimRechit_Efficiency;
00251     TH1F * FINAL_SimRechit_each_Efficiency;
00252 //---- Histograms set (chambers)...
00253   struct ChamberHistos{
00254     TH1F * EfficientRechits_inSegment;
00255     TH1F * InefficientSingleHits;
00256     TH1F * AllSingleHits;
00257     TH2F * XvsY_InefficientRecHits;
00258     TH2F * XvsY_InefficientRecHits_good;
00259     TH2F * XvsY_InefficientSegments;
00260     TH2F * XvsY_InefficientSegments_good;
00261     TH1F * EfficientRechits;
00262     TH1F * EfficientRechits_good;
00263     TH1F * EfficientLCTs;
00264     TH1F * EfficientStrips;
00265     TH1F * EfficientWireGroups;
00266     std::vector<TH2F *> XvsY_InefficientRecHits_inSegment;
00267     std::vector<TH1F *> Y_InefficientRecHits_inSegment;
00268     std::vector<TH1F *> Y_AllRecHits_inSegment;
00269     TH1F * SimRechits;
00270     TH1F * SimSimhits;
00271     TH1F * SimRechits_each;
00272     TH1F * SimSimhits_each;
00273 //---- Efficiencies
00274     TH1F * FINAL_Rechit_inSegment_Efficiency;
00275     TH1F * FINAL_Attachment_Efficiency;
00276     TH1F * FINAL_Rechit_Efficiency;
00277     TH1F * FINAL_Rechit_Efficiency_good;
00278     TH1F * FINAL_LCTs_Efficiency;
00279     TH1F * FINAL_Strip_Efficiency;
00280     TH1F * FINAL_WireGroup_Efficiency;
00281     std::vector<TH1F *> FINAL_Y_RecHit_InSegment_Efficiency;
00282     TH1F * FINAL_SimRechit_Efficiency;
00283     TH1F * FINAL_SimRechit_each_Efficiency;
00284     //Auto_ptr...
00285     //std::auto_ptr<TH1F> perLayerIneffRecHit;
00286     
00287   }ChHist[LastCh-FirstCh+1];
00288   // utility flag
00289   bool flag;
00290   // dy/dz of the segment in the ref. station  
00291   float seg_dydz;
00292   // printalot debug output
00293   bool printalot;
00294 
00295   // Data (true) or MC (false) input file
00296   bool DATA;
00297 
00298   
00299   // calculate efficiencies from existing file (if set to "true")
00300   bool update;
00301 
00302   //---- The root file for the histograms
00303   TFile *theFile;
00304 
00305   //---- input parameters for this module
00306   std::string mycscunpacker;
00307   //---- Root file name
00308   std::string rootFileName;
00309   int WorkInEndcap, ExtrapolateFromStation; 
00310   int ExtrapolateToStation, ExtrapolateToRing;
00311   //---- Utility functions
00312   bool GoodRegion(double Yreal, double Yborder, int Station, int Ring, int Chamber);
00313   bool GoodLocalRegion(double Xreal, double Yreal, int Station, int Ring, int Chamber);
00314   bool CheckLocal(double Yreal, double Yborder, int Station, int Ring, bool withinChamberOnly);
00315   void getEfficiency(float bin, float Norm, std::vector <float> &eff);
00316   void histoEfficiency(TH1F *readHisto, TH1F *writeHisto, int flag);
00317   const char*  ChangeTitle(const char * name);
00318   double Extrapolate1D(double initPosition, double initDirection, double ParameterOfTheLine);
00319   double LineParam(double z1Position, double z2Position, double z1Direction);
00320 
00321   PSimHitMap theSimHitMap;
00322 };
00323 
00324 #endif
00325 
00326 
00327 
00328 

Generated on Tue Jun 9 17:43:48 2009 for CMSSW by  doxygen 1.5.4