Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-05-06 01:53:47

0001 #ifndef L1Trigger_CSCTriggerPrimitives_CSCTriggerPrimitivesReader_h
0002 #define L1Trigger_CSCTriggerPrimitives_CSCTriggerPrimitivesReader_h
0003 
0004 /** \class CSCTriggerPrimitivesReader
0005  *
0006  * Basic analyzer class which accesses ALCTs, CLCTs, and correlated LCTs
0007  * and plot various quantities.
0008  *
0009  * \author Slava Valuev, UCLA.
0010  *
0011  *
0012  */
0013 
0014 #include "FWCore/Utilities/interface/EDGetToken.h"
0015 #include "FWCore/Framework/interface/Frameworkfwd.h"
0016 #include "FWCore/Framework/interface/EDAnalyzer.h"
0017 #include "FWCore/Framework/interface/Event.h"
0018 #include "FWCore/Framework/interface/EventSetup.h"
0019 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0020 #include "FWCore/Utilities/interface/InputTag.h"
0021 #include "FWCore/Utilities/interface/ESGetToken.h"
0022 
0023 #include "DataFormats/CSCDigi/interface/CSCConstants.h"
0024 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
0025 #include "DataFormats/CSCDigi/interface/CSCALCTDigiCollection.h"
0026 #include "DataFormats/CSCDigi/interface/CSCCLCTDigiCollection.h"
0027 #include "DataFormats/CSCDigi/interface/CSCCLCTPreTriggerDigiCollection.h"
0028 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
0029 #include "DataFormats/CSCDigi/interface/CSCWireDigiCollection.h"
0030 #include "DataFormats/CSCDigi/interface/CSCComparatorDigiCollection.h"
0031 #include "Geometry/Records/interface/MuonGeometryRecord.h"
0032 #include "CondFormats/DataRecord/interface/CSCBadChambersRcd.h"
0033 
0034 #include "L1Trigger/CSCTriggerPrimitives/interface/CSCCathodeLCTProcessor.h"  // TMB07
0035 
0036 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
0037 
0038 #include <TH1.h>
0039 #include <TH2.h>
0040 #include <TTree.h>
0041 #include <sstream>
0042 #define MAXSTUBS 100
0043 
0044 class CSCGeometry;
0045 class CSCBadChambers;
0046 class TFile;
0047 
0048 struct TreePerStub {
0049   void init(int run, int event);  // initialize to default values
0050   TTree *bookTree(TTree *t, const std::string &name = "TreePerStub");
0051 
0052   Int_t t_EventNumberAnalyzed;
0053   Int_t t_RUN;
0054   Int_t t_Event;
0055   Int_t t_nStubs;
0056   Int_t t_nStubs_readout;  //only for emulation
0057   Int_t t_nStubs_ME119;
0058   Int_t t_nStubs_ME11no911;
0059   Int_t t_nStubs_noMEpm11;
0060 
0061   Int_t t_chamber;
0062   Int_t t_ring;
0063   Int_t t_endcap;
0064   Int_t t_station;
0065   Int_t t_chambertype;
0066 };
0067 
0068 struct MyStubComparison {
0069   void init(int run, int event);  // initialize to default values
0070   TTree *bookTree(TTree *t, const std::string &name = "Stub_compare");
0071 
0072   Int_t nEvents;
0073   Int_t nRUN;
0074   Int_t nEvent;
0075   Bool_t firstfill;
0076   Int_t totStubs_data;
0077   Int_t totStubs_emul;
0078   Int_t totStubs_emul_readout;
0079   Int_t nStub_data;
0080   Int_t nStub_emul;
0081   Int_t chamber;
0082   Int_t ring;
0083   Int_t endcap;
0084   Int_t station;
0085   Int_t chambertype;
0086   Bool_t has_data;
0087   Bool_t has_emul;
0088 
0089   Int_t quality_data;
0090   Int_t bend_data;
0091   Int_t bx_data;
0092   Int_t quality_emul;
0093   Int_t bend_emul;
0094   Int_t bx_emul;
0095   Int_t bx_corr_emul;  //corrected
0096   Int_t npretrig;
0097   Int_t quality_pretrig;
0098   Int_t maxquality_pretrig;
0099   Int_t bend_pretrig;
0100   Int_t bx_pretrig;
0101   Int_t key_hs_pretrig;
0102   Int_t pattern_pretrig;
0103   Int_t maxpattern_pretrig;
0104   Int_t fullbx_data;
0105   Int_t fullbx_emul;
0106   Int_t pattern_data;
0107   Int_t pattern_emul;
0108   Bool_t WGcrossHS_data;
0109   Bool_t WGcrossHS_emul;
0110   Int_t key_WG_data;
0111   Int_t key_WG_emul;
0112   Int_t key_hs_data;
0113   Int_t key_hs_emul;
0114   Int_t trknmb_data;
0115   Int_t trknmb_emul;
0116   Float_t dphi_data;
0117   Float_t dphi_emul;
0118   Float_t eta_data;
0119   Float_t eta_emul;
0120   Float_t phi_data;
0121   Float_t phi_emul;
0122 };
0123 
0124 class CSCTriggerPrimitivesReader : public edm::EDAnalyzer {
0125 public:
0126   /// Constructor
0127   explicit CSCTriggerPrimitivesReader(const edm::ParameterSet &conf);
0128 
0129   /// Destructor
0130   ~CSCTriggerPrimitivesReader() override;
0131 
0132   /// Does the job
0133   void analyze(const edm::Event &event, const edm::EventSetup &setup) override;
0134 
0135   /// Write to ROOT file, make plots, etc.
0136   void endJob() override;
0137 
0138   int chamberSerial(CSCDetId id);
0139   int chamberIX(CSCDetId id);
0140   int chamberIXi(CSCDetId id);
0141   void HotWires(const edm::Event &iEvent);
0142 
0143 private:
0144   int eventsAnalyzed;        // event number
0145   bool debug;                // on/off switch
0146   std::string rootFileName;  // root file name
0147 
0148   // Run number, Event number
0149   int RUN_;
0150   int Event_;
0151 
0152   // Cache geometry for current event
0153   const CSCGeometry *geom_;
0154 
0155   // Cache conditions data for bad chambers
0156   const CSCBadChambers *badChambers_;
0157 
0158   // Define which LCTs are present in the input file.  This will determine the
0159   // workflow of the Reader.
0160   bool dataLctsIn_;
0161   bool emulLctsIn_;
0162 
0163   bool gangedME1a;
0164 
0165   // Flag to plot or not plot ME1/A as a separate chamber.
0166   bool plotME1A;
0167 
0168   // Flag to plot or not plot ME4/2.
0169   bool plotME42;
0170 
0171   // Producer's labels
0172   std::string lctProducerData_;
0173   std::string mpclctProducerData_;
0174   std::string lctProducerEmul_;
0175   edm::InputTag simHitProducer_;
0176   edm::InputTag wireDigiProducer_;
0177   edm::InputTag compDigiProducer_;
0178 
0179   edm::EDGetTokenT<edm::PSimHitContainer> simHit_token_;
0180   edm::EDGetTokenT<CSCWireDigiCollection> wireDigi_token_;
0181   edm::EDGetTokenT<CSCComparatorDigiCollection> compDigi_token_;
0182 
0183   edm::EDGetTokenT<CSCALCTDigiCollection> alcts_d_token_;
0184   edm::EDGetTokenT<CSCCLCTDigiCollection> clcts_d_token_;
0185   edm::EDGetTokenT<CSCCorrelatedLCTDigiCollection> lcts_tmb_d_token_;
0186   edm::EDGetTokenT<CSCCorrelatedLCTDigiCollection> lcts_mpc_d_token_;
0187   edm::EDGetTokenT<CSCALCTDigiCollection> alcts_e_token_;
0188   edm::EDGetTokenT<CSCCLCTDigiCollection> clcts_e_token_;
0189   edm::EDGetTokenT<CSCCLCTPreTriggerDigiCollection> pretrigs_e_token_;
0190   edm::EDGetTokenT<CSCCorrelatedLCTDigiCollection> lcts_tmb_e_token_;
0191   edm::EDGetTokenT<CSCCorrelatedLCTDigiCollection> lcts_mpc_e_token_;
0192   edm::ESGetToken<CSCGeometry, MuonGeometryRecord> cscGeomToken_;
0193   edm::ESGetToken<CSCBadChambers, CSCBadChambersRcd> pBadToken_;
0194 
0195   // a prefix for results ps files
0196   std::string resultsFileNamesPrefix_;
0197 
0198   // whether to perform check against known "bad chambers" list
0199   bool checkBadChambers_;
0200 
0201   // not data vs. mc, but mc vs mc
0202   bool dataIsAnotherMC_;
0203 
0204   // The file which will store the histos
0205   // TFile *theFile;
0206 
0207   enum trig_cscs { MAX_ENDCAPS = 2, MAX_STATIONS = 4, CSC_TYPES = 10 };
0208   enum { MAXPAGES = 20 };     // max. number of pages in postscript files
0209   static const double TWOPI;  // 2.*pi
0210 
0211   // Various useful constants
0212   static const std::string csc_type[CSC_TYPES];
0213   static const std::string csc_type_plus[CSC_TYPES];
0214   static const std::string csc_type_minus[CSC_TYPES];
0215   static const int NCHAMBERS[CSC_TYPES];
0216   static const int MAX_WG[CSC_TYPES];
0217   static const int MAX_HS[CSC_TYPES];
0218   static const int ptype_TMB07[CSCConstants::NUM_CLCT_PATTERNS];
0219 
0220   static const int lut_wg_vs_hs_me1b[48][2];
0221   static const int lut_wg_vs_hs_me1a[48][2];
0222   static const int lut_wg_vs_hs_me1ag[48][2];
0223   // LCT counters
0224   static int numALCT;
0225   static int numCLCT;
0226   static int numLCTTMB;
0227   static int numLCTMPC;
0228 
0229   static bool bookedHotWireHistos;
0230   static bool bookedALCTHistos;
0231   static bool bookedCLCTHistos;
0232   static bool bookedLCTTMBHistos;
0233   static bool bookedLCTMPCHistos;
0234 
0235   static bool bookedCompHistos;
0236 
0237   static bool bookedResolHistos;
0238   static bool bookedEfficHistos;
0239 
0240   static bool printps;
0241 
0242   void setRootStyle();
0243 
0244   void bookHotWireHistos();
0245   void bookALCTHistos();
0246   void bookCLCTHistos();
0247   void bookLCTTMBHistos();
0248   void bookLCTMPCHistos();
0249   void fillALCTHistos(const CSCALCTDigiCollection *alcts);
0250   void fillCLCTHistos(const CSCCLCTDigiCollection *clcts);
0251   void fillLCTTMBHistos(const CSCCorrelatedLCTDigiCollection *lcts);
0252   void fillLCTMPCHistos(const CSCCorrelatedLCTDigiCollection *lcts);
0253   void drawALCTHistos();
0254   void drawCLCTHistos();
0255   void drawLCTTMBHistos();
0256   void drawLCTMPCHistos();
0257 
0258   void bookResolHistos();
0259   void drawResolHistos();
0260   void bookEfficHistos();
0261   void drawEfficHistos();
0262   void drawHistosForTalks();
0263 
0264   GlobalPoint getGlobalPosition(unsigned int rawId, int keWg, int keyHS) const;
0265   bool doesALCTCrossCLCT(CSCDetId id, int key_wg, int key_hs) const;
0266   int getCSCType(const CSCDetId &id);
0267   double getHsPerRad(const int idh);
0268 
0269   void compare(const CSCALCTDigiCollection *alcts_data,
0270                const CSCALCTDigiCollection *alcts_emul,
0271                const CSCCLCTDigiCollection *clcts_data,
0272                const CSCCLCTDigiCollection *clcts_emul,
0273                const CSCCLCTPreTriggerDigiCollection *pretrigs_emul,
0274                const CSCCorrelatedLCTDigiCollection *lcts_data,
0275                const CSCCorrelatedLCTDigiCollection *lcts_emul);  //,
0276   //const CSCCorrelatedLCTDigiCollection* mpclcts_data,
0277   //const CSCCorrelatedLCTDigiCollection* mpclcts_emul);
0278   void bookCompHistos();
0279   void compareALCTs(const CSCALCTDigiCollection *alcts_data, const CSCALCTDigiCollection *alcts_emul);
0280   void compareCLCTs(const CSCCLCTDigiCollection *clcts_data,
0281                     const CSCCLCTDigiCollection *clcts_emul,
0282                     const CSCCLCTPreTriggerDigiCollection *pretrigs_emul);
0283   void compareLCTs(const CSCCorrelatedLCTDigiCollection *lcts_data,
0284                    const CSCCorrelatedLCTDigiCollection *lcts_emul,
0285                    const CSCALCTDigiCollection *alcts_data,
0286                    const CSCCLCTDigiCollection *clcts_data);
0287   void compareMPCLCTs(const CSCCorrelatedLCTDigiCollection *lcts_data,
0288                       const CSCCorrelatedLCTDigiCollection *lcts_emul,
0289                       const CSCALCTDigiCollection *alcts_data,
0290                       const CSCCLCTDigiCollection *clcts_data);
0291   int convertBXofLCT(const int emul_bx,
0292                      const CSCDetId &detid,
0293                      const CSCALCTDigiCollection *alcts_data,
0294                      const CSCCLCTDigiCollection *clcts_data);
0295   void drawCompHistos();
0296 
0297   void MCStudies(const edm::Event &ev, const CSCALCTDigiCollection *alcts, const CSCCLCTDigiCollection *clcts);
0298 
0299   void calcResolution(const CSCALCTDigiCollection *alcts,
0300                       const CSCCLCTDigiCollection *clcts,
0301                       const CSCWireDigiCollection *wiredc,
0302                       const CSCComparatorDigiCollection *compdc,
0303                       const edm::PSimHitContainer &allSimHits);
0304 
0305   void calcEfficiency(const CSCALCTDigiCollection *alcts,
0306                       const CSCCLCTDigiCollection *clcts,
0307                       const edm::PSimHitContainer &allSimHits);
0308 
0309   int maxRing(int station);
0310 
0311   //fill 3 Trees
0312   MyStubComparison stubs_comparison[4];
0313   TTree *stub_tree[4];
0314   //fill 3 Trees: alct, clct, lct for data and emul
0315   TreePerStub perStub[6];
0316   TTree *event_tree[6];
0317 
0318   // Histograms
0319   //Hot wires
0320   TH1F *hHotWire1, *hHotCham1;
0321 
0322   // ALCTs, data
0323   TH1F *hAlctPerEvent, *hAlctPerChamber, *hAlctPerCSC;
0324   TH1F *hAlctCsc[MAX_ENDCAPS][CSC_TYPES];
0325   TH1F *hAlctValid, *hAlctQuality, *hAlctAccel, *hAlctCollis, *hAlctKeyGroup;
0326   TH1F *hAlctBXN;
0327   // CLCTs
0328   TH1F *hClctPerEvent, *hClctPerChamber, *hClctPerCSC;
0329   TH1F *hClctCsc[MAX_ENDCAPS][CSC_TYPES];
0330   TH1F *hClctValid, *hClctQuality, *hClctStripType, *hClctSign, *hClctCFEB;
0331   TH1F *hClctBXN;
0332   TH1F *hClctKeyStrip[2], *hClctPattern[2];
0333   TH1F *hClctBendCsc[CSC_TYPES][2], *hClctKeyStripCsc[CSC_TYPES];
0334   // Correlated LCTs in TMB
0335   TH1F *hLctTMBPerEvent, *hLctTMBPerChamber;
0336   TH1F *hLctTMBPerCSC, *hCorrLctTMBPerCSC;
0337   TH1F *hLctTMBEndcap, *hLctTMBStation, *hLctTMBSector, *hLctTMBRing;
0338   TH1F *hLctTMBChamber[MAX_STATIONS], *hLctTMBCsc[MAX_ENDCAPS][CSC_TYPES];
0339   TH1F *hLctTMBValid, *hLctTMBQuality, *hLctTMBKeyGroup;
0340   TH1F *hLctTMBKeyStrip, *hLctTMBStripType;
0341   TH1F *hLctTMBPattern, *hLctTMBBend, *hLctTMBBXN;
0342   // Correlated LCTs in MPC
0343   TH1F *hLctMPCPerEvent, *hLctMPCPerCSC, *hCorrLctMPCPerCSC;
0344   TH1F *hLctMPCEndcap, *hLctMPCStation, *hLctMPCSector, *hLctMPCRing;
0345   TH1F *hLctMPCChamber[MAX_STATIONS];
0346   TH1F *hLctMPCValid, *hLctMPCQuality, *hLctMPCKeyGroup;
0347   TH1F *hLctMPCKeyStrip, *hLctMPCStripType;
0348   TH1F *hLctMPCPattern, *hLctMPCBend, *hLctMPCBXN;
0349 
0350   //Chad's hists
0351 
0352   TH1F *hAlctCompFound;
0353   TH2F *hAlctCompFound2;
0354   TH2F *hAlctCompFound2x;
0355   TH2F *hAlctCompFound2i;
0356 
0357   TH1F *hAlctCompSameN;
0358   TH2F *hAlctCompSameN2;
0359   TH2F *hAlctCompSameN2x;
0360   TH2F *hAlctCompSameN2i;
0361 
0362   TH1F *hAlctCompMatch;
0363   TH2F *hAlctCompMatch2;
0364   TH2F *hAlctCompMatch2x;
0365   TH2F *hAlctCompMatch2i;
0366 
0367   TH1F *hAlctCompTotal;
0368   TH2F *hAlctCompTotal2;
0369   TH2F *hAlctCompTotal2x;
0370   TH2F *hAlctCompTotal2i;
0371 
0372   TH1F *hClctCompFound;
0373   TH2F *hClctCompFound2;
0374   TH2F *hClctCompFound2x;
0375   TH2F *hClctCompFound2i;
0376   TH1F *hClctCompSameN;
0377   TH2F *hClctCompSameN2;
0378   TH2F *hClctCompSameN2x;
0379   TH2F *hClctCompSameN2i;
0380 
0381   TH1F *hClctCompMatch;
0382   TH2F *hClctCompMatch2;
0383   TH2F *hClctCompMatch2x;
0384   TH2F *hClctCompMatch2i;
0385 
0386   TH1F *hClctCompTotal;
0387   TH2F *hClctCompTotal2;
0388   TH2F *hClctCompTotal2x;
0389   TH2F *hClctCompTotal2i;
0390 
0391   TH1F *hLCTCompFound;
0392   TH2F *hLCTCompFound2;
0393   TH2F *hLCTCompFound2x;
0394   TH2F *hLCTCompFound2i;
0395 
0396   TH1F *hLCTCompSameN;
0397   TH2F *hLCTCompSameN2;
0398   TH2F *hLCTCompSameN2x;
0399   TH2F *hLCTCompSameN2i;
0400 
0401   TH1F *hLCTCompMatch;
0402   TH2F *hLCTCompMatch2;
0403   TH2F *hLCTCompMatch2x;
0404   TH2F *hLCTCompMatch2i;
0405 
0406   TH1F *hLCTCompTotal;
0407   TH2F *hLCTCompTotal2;
0408   TH2F *hLCTCompTotal2x;
0409   TH2F *hLCTCompTotal2i;
0410 
0411   // Histograms for firmware-emulator comparisons
0412   // ALCTs
0413   TH1F *hAlctCompFoundCsc[MAX_ENDCAPS][CSC_TYPES];
0414   TH1F *hAlctCompSameNCsc[MAX_ENDCAPS][CSC_TYPES];
0415   TH1F *hAlctCompTotalCsc[MAX_ENDCAPS][CSC_TYPES];
0416   TH1F *hAlctCompMatchCsc[MAX_ENDCAPS][CSC_TYPES];
0417   // CLCTs
0418   TH1F *hClctCompFoundCsc[MAX_ENDCAPS][CSC_TYPES];
0419   TH1F *hClctCompSameNCsc[MAX_ENDCAPS][CSC_TYPES];
0420   TH1F *hClctCompTotalCsc[MAX_ENDCAPS][CSC_TYPES];
0421   TH1F *hClctCompMatchCsc[MAX_ENDCAPS][CSC_TYPES];
0422   // Correlated LCTs
0423   TH1F *hLctCompFoundCsc[MAX_ENDCAPS][CSC_TYPES];
0424   TH1F *hLctCompSameNCsc[MAX_ENDCAPS][CSC_TYPES];
0425   TH1F *hLctCompTotalCsc[MAX_ENDCAPS][CSC_TYPES];
0426   TH1F *hLctCompMatchCsc[MAX_ENDCAPS][CSC_TYPES];
0427 
0428   // Resolution histograms
0429   // ALCT
0430   TH2F *hEtaRecVsSim;
0431   TH1F *hResolDeltaWG, *hResolDeltaEta;
0432   TH1F *hAlctVsEta[MAX_STATIONS];
0433   TH1F *hEtaDiffVsEta[MAX_STATIONS];
0434   TH1F *hEtaDiffCsc[CSC_TYPES][3];
0435   TH2F *hEtaDiffVsWireCsc[CSC_TYPES];
0436   // CLCT
0437   TH2F *hPhiRecVsSim;
0438   TH1F *hResolDeltaHS, *hResolDeltaDS;
0439   TH1F *hResolDeltaPhi, *hResolDeltaPhiHS, *hResolDeltaPhiDS;
0440   TH1F *hClctVsPhi[MAX_STATIONS];
0441   TH1F *hPhiDiffVsPhi[MAX_STATIONS];
0442   TH1F *hPhiDiffCsc[CSC_TYPES][5];
0443   TH2F *hPhiDiffVsStripCsc[CSC_TYPES][2];
0444   TH1F *hTrueBendCsc[CSC_TYPES];
0445   TH1F *hPhiDiffPattern[CSCConstants::NUM_CLCT_PATTERNS];
0446   // Efficiency histograms
0447   TH1F *hEfficHitsEta[MAX_STATIONS];
0448   TH1F *hEfficALCTEta[MAX_STATIONS], *hEfficCLCTEta[MAX_STATIONS];
0449   TH1F *hEfficHitsEtaCsc[CSC_TYPES];
0450   TH1F *hEfficALCTEtaCsc[CSC_TYPES], *hEfficCLCTEtaCsc[CSC_TYPES];
0451 
0452   TH1F *hAlctKeyGroupME11;
0453   TH1F *hClctKeyStripME11;
0454   TH1F *hLctTMBKeyGroupME11;
0455   TH1F *hLctTMBKeyStripME11;
0456   TH1F *hLctMPCKeyGroupME11;
0457   TH1F *hLctMPCKeyStripME11;
0458 };
0459 
0460 #endif