CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_3/src/Validation/EcalDigis/interface/EcalSelectiveReadoutValidation.h

Go to the documentation of this file.
00001 #ifndef EcalSelectiveReadoutValidation_H
00002 #define EcalSelectiveReadoutValidation_H
00003 
00004 /*
00005  * \file EcalSelectiveReadoutValidation.h
00006  *
00007  * $Date: 2012/01/31 22:28:20 $
00008  * $Revision: 1.14 $
00009  *
00010  */
00011 
00012 #include "FWCore/Framework/interface/Frameworkfwd.h"
00013 #include "FWCore/Framework/interface/EDAnalyzer.h"
00014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00015 
00016 #include "DataFormats/Common/interface/Handle.h"
00017 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00018 #include "SimDataFormats/CaloHit/interface/PCaloHit.h"
00019 
00020 
00021 #include "Geometry/CaloTopology/interface/EcalTrigTowerConstituentsMap.h"
00022 #include "DataFormats/EcalDetId/interface/EcalScDetId.h"
00023 #include "DataFormats/EcalDetId/interface/EcalTrigTowerDetId.h"
00024 
00025 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
00026 //#include "DataFormats/EcalDetId/interface/EEDetId.h"
00027 //#include "DataFormats/EcalDetId/interface/EBDetId.h"
00028 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00029 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00030 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00031 
00032 #include "Validation/EcalDigis/src/CollHandle.h"
00033 
00034 #include <string>
00035 #include <set>
00036 #include <utility>
00037 #include <fstream>
00038 #include <inttypes.h>
00039 #include "DQMServices/Core/interface/DQMStore.h"
00040 #include "DQMServices/Core/interface/MonitorElement.h"
00041 
00042 class DQMStore;
00043 class MonitorElement;
00044 class EBDetId;
00045 class EEDetId;
00046 class EcalTPParameters;
00047 class EcalElectronicsMapping;
00048 
00049 class EcalSelectiveReadoutValidation: public edm::EDAnalyzer{
00050 
00051   //typedef EcalUncalibratedRecHitCollection RecHitCollection;
00052   //typedef EcalUncalibratedRecHit RecHit;
00053   typedef EcalRecHitCollection RecHitCollection;
00054   typedef EcalRecHit RecHit;
00055   
00056 public:
00057 
00059   EcalSelectiveReadoutValidation(const edm::ParameterSet& ps);
00060 
00062   ~EcalSelectiveReadoutValidation();
00063 
00064 protected:
00065 
00067   void analyze(edm::Event const & e, edm::EventSetup const & c);
00068 
00070   void beginRun(const edm::Run& r, const edm::EventSetup& c); 
00071   
00073   void endRun(const edm::Run& r, const edm::EventSetup& c); 
00074 
00075 private:
00077   enum subdet_t {EB, EE};
00078 
00082   template<class T, class U>
00083   void anaDigi(const T& frame, const U& srFlagColl);
00084 
00088   void anaDigiInit();
00089 
00094   void analyzeDataVolume(const edm::Event& e, const edm::EventSetup& es);
00095 
00100   void analyzeEB(const edm::Event& event, const edm::EventSetup& es);
00101 
00106   void analyzeEE(const edm::Event& event, const edm::EventSetup& es);
00107 
00112   void analyzeTP(const edm::Event& event, const edm::EventSetup& es); 
00113   
00114   //  /** Selective Readout decisions Validation
00115   //    * @param event EDM event
00116   //    * @param es event setup
00117   //    */ 
00118   //   void SRFlagValidation(const edm::Event& event, const edm::EventSetup& es);
00119 
00125   void SRFlagValidation(const edm::Event& event, const edm::EventSetup& es);
00126 
00130   double frame2Energy(const EcalDataFrame& frame) const;
00131 
00138   template<class T>
00139   double frame2EnergyForTp(const T& frame, int offset = 0) const;
00140   
00141   //   double getEcalEventSize(double nReadXtals) const{
00142   //     return getDccOverhead(EB)*nEbDccs+getDccOverhead(EE)*nEeDccs
00143   //       + nReadXtals*getBytesPerCrystal()
00144   //       + (nEeRus+nEbRus)*8;
00145   //   }
00146 
00151   double getEbEventSize(double nReadXtals) const;
00152 
00157   double getEeEventSize(double nReadXtals) const;
00158 
00162   double getDccOverhead(subdet_t subdet) const{
00163     //  return (subdet==EB?34:25)*8;
00164     return (subdet==EB?34:52)*8;
00165   }
00166 
00171   double getBytesPerCrystal() const{
00172     return 3*8;
00173   }
00174 
00180   double getDccEventSize(int iDcc0, double nReadXtals) const{
00181     subdet_t subdet;
00182      if(iDcc0<9 || iDcc0>=45){
00183        subdet = EE;
00184      } else{
00185        subdet = EB;
00186      }
00187      //     return getDccOverhead(subdet)+nReadXtals*getBytesPerCrystal()
00188      //       + getRuCount(iDcc0)*8;
00189     return getDccOverhead(subdet)
00190       + getDccSrDependentPayload(iDcc0, getRuCount(iDcc0), nReadXtals);
00191   }
00192 
00200   double getDccSrDependentPayload(int iDcc0, double nReadRus,
00201                                   double nReadXtals) const{
00202     return nReadXtals*getBytesPerCrystal() + nReadRus*8;
00203   }
00204 
00209   int getRuCount(int iDcc0) const;
00210 
00215   void readAllCollections(const edm::Event& e);
00216 
00225   void setTtEtSums(const edm::EventSetup& es,
00226                    const EBDigiCollection& ebDigis,
00227                    const EEDigiCollection& eeDigis);
00228 
00229   //   /** Retrieves the logical number of the DCC reading a given crystal channel.
00230   //    * @param xtarId crystal channel identifier
00231   //    * @return the DCC logical number starting from 1.
00232   //    */
00233   //   unsigned dccNum(const DetId& xtalId) const;
00234 
00242   std::pair<int,int> dccCh(const DetId& xtalId) const;
00243 
00244   
00248   int iEta2cIndex(int iEta) const{
00249     return (iEta<0)?iEta+85:iEta+84;
00250   }
00251   
00255   int iPhi2cIndex(int iPhi) const{
00256     //    return iPhi-1;
00257     int iPhi0 = iPhi - 11;
00258     if(iPhi0<0) iPhi0 += 360;
00259     return iPhi0;
00260   }
00261 
00265   int iXY2cIndex(int iX) const{
00266     return iX-1;
00267   }
00268 
00271   int cIndex2iXY(int iX0) const{
00272     return iX0+1;
00273   }
00274 
00277   int cIndex2iEta(int i) const{
00278     return (i<85)?i-85:i-84;
00279   }
00280 
00281 
00284   int cIndex2iPhi(int i) const {
00285     return (i+11) % 360;
00286   }
00287 
00293   int iTtEta2cIndex(int iEta) const{
00294     return (iEta<0)?iEta+28:iEta+27;
00295   }
00296   
00302   int iTtPhi2cIndex(int iPhi) const{
00303     return iPhi-1;
00304     //int iPhi0 = iPhi - 3;
00305     //if(iPhi0<0) iPhi0 += 72;
00306     //return iPhi0;
00307   }
00308 
00311   int cIndex2iTtEta(int i) const{
00312     return (i<27)?i-28:i-27;
00313   }
00314 
00317   int cIndex2iTtPhi(int i) const{
00318     return i + 1;
00319   }
00320   
00325   EcalScDetId superCrystalOf(const EEDetId& xtalId) const;
00326 
00328 
00333   EcalTrigTowerDetId readOutUnitOf(const EBDetId& xtalId) const;
00334   
00335   EcalScDetId readOutUnitOf(const EEDetId& xtalId) const;
00337 
00348   static int dccZsFIR(const EcalDataFrame& frame,
00349                       const std::vector<int>& firWeights,
00350                       int firstFIRSample,
00351                       bool* saturated = 0);
00352   
00353 
00358   static std::vector<int> getFIRWeights(const std::vector<double>&
00359                                         normalizedWeights);
00360   
00362 
00365   MonitorElement* bookFloat(const std::string& name);
00366   
00367   MonitorElement* book1D(const std::string& name,
00368                          const std::string& title, int nbins,
00369                          double xmin, double xmax);
00370  
00371   MonitorElement* book2D(const std::string& name,
00372                          const std::string& title,
00373                          int nxbins, double xmin, double xmax,
00374                          int nybins, double ymin, double ymax);
00375 
00376   MonitorElement* bookProfile(const std::string& name,
00377                               const std::string& title,
00378                               int nbins, double xmin, double xmax);
00379   
00380   MonitorElement* bookProfile2D(const std::string& name,
00381                                 const std::string& title,
00382                                 int nbinx, double xmin, double xmax,
00383                                 int nbiny, double ymin, double ymax,
00384                                 const char* option = "");
00386 
00388 
00390   void fill(MonitorElement* me, float x){
00391     if(me) me->Fill(x);
00392   }
00393   void fill(MonitorElement* me,float x, float yw){
00394     if(me) me->Fill(x, yw);
00395   }
00396   void fill(MonitorElement* me,float x, float y, float zw){
00397     if(me) me->Fill(x, y, zw);
00398   }
00399   void fill(MonitorElement* me,float x, float y, float z, float w){
00400     if(me) me->Fill(x, y, z, w);
00401   }
00403 
00404   void initAsciiFile();
00405 
00409   void updateL1aRate(const edm::Event& event);
00410 
00415   double getL1aRate() const;
00416   
00417 private:
00420   struct energiesEb_t{
00421     double simE;     
00422     double noZsRecE; 
00423     double recE;     
00424     //    EBDigiCollection::const_iterator itNoZsFrame; //
00425     int simHit;      
00426     double phi;      
00427     double eta;      
00428     bool gain12;     //all MGPA samples at gain 12?
00429   };
00430 
00433   struct energiesEe_t{
00434     double simE;     
00435     double noZsRecE; 
00436     double recE;     
00437     //    EEDigiCollection::const_iterator itNoZsFrame;
00438     int simHit;      
00439     double phi;      
00440     double eta;      
00441     bool gain12;     //all MGPA samples at gain 12?
00442   };
00443 
00445   static const int kByte_ = 1024;
00446   
00448   static const unsigned nDccs_ = 54;
00449 
00451   // = maximum number of RUs read by a DCC
00452   static const unsigned nDccChs_ = 68;
00453   
00454   //Lower bound of DCC ID range
00455   static const int minDccId_ = 1 ;
00456 
00457   //Upper bound of DCC ID range
00458   static const int maxDccId_  = minDccId_ + nDccs_ -1;
00459   
00461   static const int nEbDccs = 36;
00462 
00464   static const int nEeDccs = 18;
00465 
00467   static const int nEbRus = 36*68;
00468 
00470   static const int nEeRus = 2*(34+32+33+33+32+34+33+34+33);
00471 
00473   static const int nDccRus_[nDccs_];
00474 
00476   static const int nEndcaps = 2;
00477 
00479   static const int nEbEta = 170;
00480 
00482   static const int nEbPhi = 360;
00483 
00485   static const int nEeX = 100;
00486 
00488   static const int nEeY = 100;
00489 
00491   static const int ebTtEdge = 5;
00492   
00494   static const int scEdge = 5;
00495 
00497   static const int nOneEeTtEta = 11;
00498   
00500   static const int nEbTtEta = 34;
00501   
00503   static const int nTtEta = 2*nOneEeTtEta + nEbTtEta;
00504 
00506   static const int nTtPhi = 72;
00507 
00509   static const int nMaxXtalPerRu = 25;
00511   static const double rad2deg;
00512   
00514   bool verbose_;
00515 
00517   DQMStore* dbe_;
00518 
00520   std::string outputFile_;
00521 
00523   bool collNotFoundWarn_;
00524   
00527   std::string srpAlgoErrorLogFileName_;
00528 
00531   std::string srApplicationErrorLogFileName_;
00532   
00534   std::ofstream srpAlgoErrorLog_; 
00535 
00537   std::ofstream srApplicationErrorLog_; 
00538 
00540   std::ofstream zsErrorLog_;
00541   
00543 
00545   CollHandle<EBDigiCollection>           ebDigis_;
00546   CollHandle<EEDigiCollection>           eeDigis_;
00547   CollHandle<EBDigiCollection>           ebNoZsDigis_;
00548   CollHandle<EEDigiCollection>           eeNoZsDigis_;
00549   CollHandle<EBSrFlagCollection>         ebSrFlags_;
00550   CollHandle<EESrFlagCollection>         eeSrFlags_;
00551   CollHandle<EBSrFlagCollection>         ebComputedSrFlags_;
00552   CollHandle<EESrFlagCollection>         eeComputedSrFlags_;
00553   CollHandle<std::vector<PCaloHit> >     ebSimHits_;
00554   CollHandle<std::vector<PCaloHit> >     eeSimHits_;
00555   CollHandle<EcalTrigPrimDigiCollection> tps_;
00556   CollHandle<RecHitCollection>       ebRecHits_;
00557   CollHandle<RecHitCollection>       eeRecHits_;
00558   CollHandle<FEDRawDataCollection>       fedRaw_;
00560 
00562 
00564   int64_t tmax;
00565   int64_t tmin;
00566   int64_t l1aOfTmin;
00567   int64_t l1aOfTmax;
00568   bool l1aRateErr;
00570   
00572 
00574   MonitorElement* meDccVol_;
00575   MonitorElement* meDccLiVol_;
00576   MonitorElement* meDccHiVol_;
00577   MonitorElement* meDccVolFromData_;
00578   MonitorElement* meVol_;
00579   MonitorElement* meVolB_;
00580   MonitorElement* meVolE_;
00581   MonitorElement* meVolBLI_;
00582   MonitorElement* meVolELI_;
00583   MonitorElement* meVolLI_;
00584   MonitorElement* meVolBHI_;
00585   MonitorElement* meVolEHI_;
00586   MonitorElement* meVolHI_;
00587   MonitorElement* meChOcc_;
00588   
00589   MonitorElement* meTp_;
00590   MonitorElement* meTtf_;
00591   MonitorElement* meTtfVsTp_;
00592   MonitorElement* meTtfVsEtSum_;
00593   MonitorElement* meTpVsEtSum_;
00594 
00595   MonitorElement* meEbRecE_;
00596   MonitorElement* meEbEMean_;
00597   MonitorElement* meEbNoise_;
00598   MonitorElement* meEbSimE_;
00599   MonitorElement* meEbRecEHitXtal_;
00600   MonitorElement* meEbRecVsSimE_;
00601   MonitorElement* meEbNoZsRecVsSimE_;
00602   
00603   MonitorElement* meEeRecE_;
00604   MonitorElement* meEeEMean_;
00605   MonitorElement* meEeNoise_;
00606   MonitorElement* meEeSimE_;
00607   MonitorElement* meEeRecEHitXtal_;
00608   MonitorElement* meEeRecVsSimE_;
00609   MonitorElement* meEeNoZsRecVsSimE_;
00610 
00611   MonitorElement* meFullRoRu_;
00612   MonitorElement* meZs1Ru_;
00613   MonitorElement* meForcedRu_;
00614 
00615   MonitorElement* meLiTtf_;
00616   MonitorElement* meMiTtf_;
00617   MonitorElement* meHiTtf_;
00618   MonitorElement* meForcedTtf_;
00619 
00620   MonitorElement* meTpMap_;
00621 
00622   MonitorElement* meFullRoCnt_;
00623   MonitorElement* meEbFullRoCnt_;
00624   MonitorElement* meEeFullRoCnt_;
00625   
00626   MonitorElement* meEbLiZsFir_;
00627   MonitorElement* meEbHiZsFir_;
00628   MonitorElement* meEbIncompleteRUZsFir_;
00629   
00630   MonitorElement* meEeLiZsFir_;
00631   MonitorElement* meEeHiZsFir_;
00632   MonitorElement* meSRFlagsFromData_; 
00633   MonitorElement* meSRFlagsComputed_; 
00634   MonitorElement* meSRFlagsConsistency_;
00635         
00636   MonitorElement* meIncompleteFRO_;
00637   MonitorElement* meDroppedFRO_;
00638   MonitorElement* meCompleteZS_;
00639   
00640   MonitorElement* meIncompleteFROMap_;
00641   MonitorElement* meDroppedFROMap_;
00642   MonitorElement* meCompleteZSMap_;
00643 
00644   MonitorElement* meIncompleteFRORateMap_;
00645   MonitorElement* meDroppedFRORateMap_;
00646   MonitorElement* meCompleteZSRateMap_;
00647 
00648   MonitorElement* meIncompleteFROCnt_;
00649   MonitorElement* meDroppedFROCnt_;
00650   MonitorElement* meCompleteZSCnt_;
00651   MonitorElement* meEbZsErrCnt_;
00652   MonitorElement* meEeZsErrCnt_;
00653   MonitorElement* meZsErrCnt_;
00654   MonitorElement* meEbZsErrType1Cnt_;
00655   MonitorElement* meEeZsErrType1Cnt_;
00656   MonitorElement* meZsErrType1Cnt_;
00658 
00660 
00663   MonitorElement* meEbFixedPayload_;
00664   MonitorElement* meEeFixedPayload_;
00665   MonitorElement* meFixedPayload_;
00667   
00670   MonitorElement* meL1aRate_;
00671   
00673   int nDroppedFRO_;
00674 
00676   int nIncompleteFRO_;
00677 
00679   int nCompleteZS_;
00680 
00682   int nEbFROCnt_;
00683 
00685   int nEeFROCnt_;
00686 
00688   int nEbZsErrors_;
00689 
00691   int nEeZsErrors_;
00692 
00695   int nEbZsErrorsType1_;
00696 
00699   int nEeZsErrorsType1_;
00700 
00701   
00704   const EcalTrigTowerConstituentsMap * triggerTowerMap_;
00705 
00709   const EcalTPParameters* tpParam_;
00710 
00713   const EcalElectronicsMapping* elecMap_;
00714   
00718   bool localReco_;
00719   
00722   std::vector<double> weights_;
00723 
00726   std::vector<int> firWeights_;
00727 
00730   int ebZsThr_;
00731 
00734   int eeZsThr_;
00735   
00738   bool tpInGeV_;
00739 
00743   int firstFIRSample_;
00744 
00748   bool useEventRate_;
00749 
00754   std::vector<bool> logErrForDccs_;
00755   
00758   int nEb_;
00759 
00762   int nEe_;
00763 
00766   int nEeLI_;
00767 
00770   int nEeHI_;
00771 
00774   int nEbLI_;
00775 
00778   int nEbHI_;
00779 
00782   int nPerDcc_[nDccs_];
00783 
00786   int nLiPerDcc_[nDccs_];
00787 
00790   int nHiPerDcc_[nDccs_];
00791 
00792   
00795   int nRuPerDcc_[nDccs_];
00796 
00799   int nLiRuPerDcc_[nDccs_];
00800 
00803   int nHiRuPerDcc_[nDccs_];
00804 
00805   
00807 
00809   bool ebRuActive_[nEbEta/ebTtEdge][nEbPhi/ebTtEdge];
00810   bool eeRuActive_[nEndcaps][nEeX/scEdge][nEeY/scEdge];
00812   
00813   bool isRuComplete_[nDccs_][nDccChs_];
00814 
00817   int nPerRu_[nDccs_][nDccChs_];  
00818   
00821   int ievt_;
00822 
00827   double ttEtSums[nTtEta][nTtPhi];
00828 
00832   energiesEb_t ebEnergies[nEbEta][nEbPhi];
00833 
00838   energiesEe_t eeEnergies[nEndcaps][nEeX][nEeY];
00839 
00842   bool SkipInnerSC_;
00843 
00847   std::set<std::string> histList_;
00848 
00851   bool allHists_;
00852 
00855   std::string histDir_;
00856   
00860   std::map<std::string, std::string> availableHistList_;
00861 
00862 
00865   bool withEeSimHit_;
00866 
00869   bool withEbSimHit_;
00870   
00875   bool registerHist(const std::string& name, const std::string& title);
00876 
00880   void printAvailableHists();
00881 
00885   void normalizeHists(double eventCount);
00886 
00892   void configFirWeights(std::vector<double> weightsForZsFIR);
00893 
00898   bool logSrpAlgoErrors_;
00899 
00903   bool logSrApplicationErrors_;
00904 
00913   template<class T>
00914   void compareSrfColl(const edm::Event& event, T& srfFromData, T& computedSrf);
00915 
00920   template<class T>
00921   void checkSrApplication(const edm::Event& event, T& srfs);
00922 
00923   
00927 
00928   int ruGraphX(const EcalScDetId& id) const{
00929     return id.ix() + (id.zside()>0?20:-40);
00930   }
00931   
00932   int ruGraphY(const EcalScDetId& id) const{
00933     return id.iy();
00934   }
00935   
00936   int ruGraphX(const EcalTrigTowerDetId& id) const{
00937     return id.ieta();
00938   }
00939   
00940   int ruGraphY(const EcalTrigTowerDetId& id) const{
00941     return id.iphi();
00942   }
00943   
00944   int xtalGraphX(const EEDetId& id) const{
00945     return id.ix() + (id.zside()>0?100:-200);
00946   }
00947   
00948   int xtalGraphY(const EEDetId& id) const{
00949     return id.iy();
00950   }
00951   
00952   int xtalGraphX(const EBDetId& id) const{
00953     return id.ieta();
00954   }
00955   
00956   int xtalGraphY(const EBDetId& id) const{
00957     return id.iphi();
00958   }
00960 
00962 
00965   int dccId(const EcalScDetId& detId) const;
00966   int dccId(const EcalTrigTowerDetId& detId) const;
00968 
00974   void selectFedsForLog();
00975 
00981   int getCrystalCount(int iDcc, int iDccCh);
00982 
00983   
00984 private:
00987   class Sorter{
00988     EcalSelectiveReadoutValidation* validation;
00989   public:
00990     Sorter(EcalSelectiveReadoutValidation* v): validation(v){};
00991     bool operator()(std::pair<int,int>a, std::pair<int,int>b){
00992       return (validation->ebEnergies[a.first][a.second].simE
00993               > validation->ebEnergies[b.first][b.second].simE);
00994     }
00995   };
00996 
00997   void myAna();
00998 };
00999 
01000 #endif //EcalSelectiveReadoutValidation_H not defined
01001