CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/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: 2010/05/05 10:54:53 $
00008  * $Revision: 1.13 $
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     subdet_t subdet;
00203     if(iDcc0<9 || iDcc0>=45){
00204       subdet = EE;
00205     } else{
00206       subdet = EB;
00207     }
00208     return nReadXtals*getBytesPerCrystal() + nReadRus*8;
00209   }
00210 
00215   int getRuCount(int iDcc0) const;
00216 
00221   void readAllCollections(const edm::Event& e);
00222 
00231   void setTtEtSums(const edm::EventSetup& es,
00232                    const EBDigiCollection& ebDigis,
00233                    const EEDigiCollection& eeDigis);
00234 
00235   //   /** Retrieves the logical number of the DCC reading a given crystal channel.
00236   //    * @param xtarId crystal channel identifier
00237   //    * @return the DCC logical number starting from 1.
00238   //    */
00239   //   unsigned dccNum(const DetId& xtalId) const;
00240 
00248   std::pair<int,int> dccCh(const DetId& xtalId) const;
00249 
00250   
00254   int iEta2cIndex(int iEta) const{
00255     return (iEta<0)?iEta+85:iEta+84;
00256   }
00257   
00261   int iPhi2cIndex(int iPhi) const{
00262     //    return iPhi-1;
00263     int iPhi0 = iPhi - 11;
00264     if(iPhi0<0) iPhi0 += 360;
00265     return iPhi0;
00266   }
00267 
00271   int iXY2cIndex(int iX) const{
00272     return iX-1;
00273   }
00274 
00277   int cIndex2iXY(int iX0) const{
00278     return iX0+1;
00279   }
00280 
00283   int cIndex2iEta(int i) const{
00284     return (i<85)?i-85:i-84;
00285   }
00286 
00287 
00290   int cIndex2iPhi(int i) const {
00291     return (i+11) % 360;
00292   }
00293 
00299   int iTtEta2cIndex(int iEta) const{
00300     return (iEta<0)?iEta+28:iEta+27;
00301   }
00302   
00308   int iTtPhi2cIndex(int iPhi) const{
00309     return iPhi-1;
00310     //int iPhi0 = iPhi - 3;
00311     //if(iPhi0<0) iPhi0 += 72;
00312     //return iPhi0;
00313   }
00314 
00317   int cIndex2iTtEta(int i) const{
00318     return (i<27)?i-28:i-27;
00319   }
00320 
00323   int cIndex2iTtPhi(int i) const{
00324     return i + 1;
00325   }
00326   
00331   EcalScDetId superCrystalOf(const EEDetId& xtalId) const;
00332 
00334 
00339   EcalTrigTowerDetId readOutUnitOf(const EBDetId& xtalId) const;
00340   
00341   EcalScDetId readOutUnitOf(const EEDetId& xtalId) const;
00343 
00354   static int dccZsFIR(const EcalDataFrame& frame,
00355                       const std::vector<int>& firWeights,
00356                       int firstFIRSample,
00357                       bool* saturated = 0);
00358   
00359 
00364   static std::vector<int> getFIRWeights(const std::vector<double>&
00365                                         normalizedWeights);
00366   
00368 
00371   MonitorElement* bookFloat(const std::string& name);
00372   
00373   MonitorElement* book1D(const std::string& name,
00374                          const std::string& title, int nbins,
00375                          double xmin, double xmax);
00376  
00377   MonitorElement* book2D(const std::string& name,
00378                          const std::string& title,
00379                          int nxbins, double xmin, double xmax,
00380                          int nybins, double ymin, double ymax);
00381 
00382   MonitorElement* bookProfile(const std::string& name,
00383                               const std::string& title,
00384                               int nbins, double xmin, double xmax);
00385   
00386   MonitorElement* bookProfile2D(const std::string& name,
00387                                 const std::string& title,
00388                                 int nbinx, double xmin, double xmax,
00389                                 int nbiny, double ymin, double ymax,
00390                                 const char* option = "");
00392 
00394 
00396   void fill(MonitorElement* me, float x){
00397     if(me) me->Fill(x);
00398   }
00399   void fill(MonitorElement* me,float x, float yw){
00400     if(me) me->Fill(x, yw);
00401   }
00402   void fill(MonitorElement* me,float x, float y, float zw){
00403     if(me) me->Fill(x, y, zw);
00404   }
00405   void fill(MonitorElement* me,float x, float y, float z, float w){
00406     if(me) me->Fill(x, y, z, w);
00407   }
00409 
00410   void initAsciiFile();
00411 
00415   void updateL1aRate(const edm::Event& event);
00416 
00421   double getL1aRate() const;
00422   
00423 private:
00426   struct energiesEb_t{
00427     double simE;     
00428     double noZsRecE; 
00429     double recE;     
00430     //    EBDigiCollection::const_iterator itNoZsFrame; //
00431     int simHit;      
00432     double phi;      
00433     double eta;      
00434     bool gain12;     //all MGPA samples at gain 12?
00435   };
00436 
00439   struct energiesEe_t{
00440     double simE;     
00441     double noZsRecE; 
00442     double recE;     
00443     //    EEDigiCollection::const_iterator itNoZsFrame;
00444     int simHit;      
00445     double phi;      
00446     double eta;      
00447     bool gain12;     //all MGPA samples at gain 12?
00448   };
00449 
00451   static const int kByte_ = 1024;
00452   
00454   static const unsigned nDccs_ = 54;
00455 
00457   // = maximum number of RUs read by a DCC
00458   static const unsigned nDccChs_ = 68;
00459   
00460   //Lower bound of DCC ID range
00461   static const int minDccId_ = 1 ;
00462 
00463   //Upper bound of DCC ID range
00464   static const int maxDccId_  = minDccId_ + nDccs_ -1;
00465   
00467   static const int nEbDccs = 36;
00468 
00470   static const int nEeDccs = 18;
00471 
00473   static const int nEbRus = 36*68;
00474 
00476   static const int nEeRus = 2*(34+32+33+33+32+34+33+34+33);
00477 
00479   static const int nDccRus_[nDccs_];
00480 
00482   static const int nEndcaps = 2;
00483 
00485   static const int nEbEta = 170;
00486 
00488   static const int nEbPhi = 360;
00489 
00491   static const int nEeX = 100;
00492 
00494   static const int nEeY = 100;
00495 
00497   static const int ebTtEdge = 5;
00498   
00500   static const int scEdge = 5;
00501 
00503   static const int nOneEeTtEta = 11;
00504   
00506   static const int nEbTtEta = 34;
00507   
00509   static const int nTtEta = 2*nOneEeTtEta + nEbTtEta;
00510 
00512   static const int nTtPhi = 72;
00513 
00515   static const int nMaxXtalPerRu = 25;
00517   static const double rad2deg;
00518   
00520   bool verbose_;
00521 
00523   DQMStore* dbe_;
00524 
00526   std::string outputFile_;
00527 
00529   bool collNotFoundWarn_;
00530   
00533   std::string srpAlgoErrorLogFileName_;
00534 
00537   std::string srApplicationErrorLogFileName_;
00538   
00540   std::ofstream srpAlgoErrorLog_; 
00541 
00543   std::ofstream srApplicationErrorLog_; 
00544 
00546   std::ofstream zsErrorLog_;
00547   
00549 
00551   CollHandle<EBDigiCollection>           ebDigis_;
00552   CollHandle<EEDigiCollection>           eeDigis_;
00553   CollHandle<EBDigiCollection>           ebNoZsDigis_;
00554   CollHandle<EEDigiCollection>           eeNoZsDigis_;
00555   CollHandle<EBSrFlagCollection>         ebSrFlags_;
00556   CollHandle<EESrFlagCollection>         eeSrFlags_;
00557   CollHandle<EBSrFlagCollection>         ebComputedSrFlags_;
00558   CollHandle<EESrFlagCollection>         eeComputedSrFlags_;
00559   CollHandle<std::vector<PCaloHit> >     ebSimHits_;
00560   CollHandle<std::vector<PCaloHit> >     eeSimHits_;
00561   CollHandle<EcalTrigPrimDigiCollection> tps_;
00562   CollHandle<RecHitCollection>       ebRecHits_;
00563   CollHandle<RecHitCollection>       eeRecHits_;
00564   CollHandle<FEDRawDataCollection>       fedRaw_;
00566 
00568 
00570   int64_t tmax;
00571   int64_t tmin;
00572   int64_t l1aOfTmin;
00573   int64_t l1aOfTmax;
00574   bool l1aRateErr;
00576   
00578 
00580   MonitorElement* meDccVol_;
00581   MonitorElement* meDccLiVol_;
00582   MonitorElement* meDccHiVol_;
00583   MonitorElement* meDccVolFromData_;
00584   MonitorElement* meVol_;
00585   MonitorElement* meVolB_;
00586   MonitorElement* meVolE_;
00587   MonitorElement* meVolBLI_;
00588   MonitorElement* meVolELI_;
00589   MonitorElement* meVolLI_;
00590   MonitorElement* meVolBHI_;
00591   MonitorElement* meVolEHI_;
00592   MonitorElement* meVolHI_;
00593   MonitorElement* meChOcc_;
00594   
00595   MonitorElement* meTp_;
00596   MonitorElement* meTtf_;
00597   MonitorElement* meTtfVsTp_;
00598   MonitorElement* meTtfVsEtSum_;
00599   MonitorElement* meTpVsEtSum_;
00600 
00601   MonitorElement* meEbRecE_;
00602   MonitorElement* meEbEMean_;
00603   MonitorElement* meEbNoise_;
00604   MonitorElement* meEbSimE_;
00605   MonitorElement* meEbRecEHitXtal_;
00606   MonitorElement* meEbRecVsSimE_;
00607   MonitorElement* meEbNoZsRecVsSimE_;
00608   
00609   MonitorElement* meEeRecE_;
00610   MonitorElement* meEeEMean_;
00611   MonitorElement* meEeNoise_;
00612   MonitorElement* meEeSimE_;
00613   MonitorElement* meEeRecEHitXtal_;
00614   MonitorElement* meEeRecVsSimE_;
00615   MonitorElement* meEeNoZsRecVsSimE_;
00616 
00617   MonitorElement* meFullRoRu_;
00618   MonitorElement* meZs1Ru_;
00619   MonitorElement* meForcedRu_;
00620 
00621   MonitorElement* meLiTtf_;
00622   MonitorElement* meMiTtf_;
00623   MonitorElement* meHiTtf_;
00624   MonitorElement* meForcedTtf_;
00625 
00626   MonitorElement* meTpMap_;
00627 
00628   MonitorElement* meFullRoCnt_;
00629   MonitorElement* meEbFullRoCnt_;
00630   MonitorElement* meEeFullRoCnt_;
00631   
00632   MonitorElement* meEbLiZsFir_;
00633   MonitorElement* meEbHiZsFir_;
00634   MonitorElement* meEbIncompleteRUZsFir_;
00635   
00636   MonitorElement* meEeLiZsFir_;
00637   MonitorElement* meEeHiZsFir_;
00638   MonitorElement* meSRFlagsFromData_; 
00639   MonitorElement* meSRFlagsComputed_; 
00640   MonitorElement* meSRFlagsConsistency_;
00641         
00642   MonitorElement* meIncompleteFRO_;
00643   MonitorElement* meDroppedFRO_;
00644   MonitorElement* meCompleteZS_;
00645   
00646   MonitorElement* meIncompleteFROMap_;
00647   MonitorElement* meDroppedFROMap_;
00648   MonitorElement* meCompleteZSMap_;
00649 
00650   MonitorElement* meIncompleteFRORateMap_;
00651   MonitorElement* meDroppedFRORateMap_;
00652   MonitorElement* meCompleteZSRateMap_;
00653 
00654   MonitorElement* meIncompleteFROCnt_;
00655   MonitorElement* meDroppedFROCnt_;
00656   MonitorElement* meCompleteZSCnt_;
00657   MonitorElement* meEbZsErrCnt_;
00658   MonitorElement* meEeZsErrCnt_;
00659   MonitorElement* meZsErrCnt_;
00660   MonitorElement* meEbZsErrType1Cnt_;
00661   MonitorElement* meEeZsErrType1Cnt_;
00662   MonitorElement* meZsErrType1Cnt_;
00664 
00666 
00669   MonitorElement* meEbFixedPayload_;
00670   MonitorElement* meEeFixedPayload_;
00671   MonitorElement* meFixedPayload_;
00673   
00676   MonitorElement* meL1aRate_;
00677   
00679   int nDroppedFRO_;
00680 
00682   int nIncompleteFRO_;
00683 
00685   int nCompleteZS_;
00686 
00688   int nEbFROCnt_;
00689 
00691   int nEeFROCnt_;
00692 
00694   int nEbZsErrors_;
00695 
00697   int nEeZsErrors_;
00698 
00701   int nEbZsErrorsType1_;
00702 
00705   int nEeZsErrorsType1_;
00706 
00707   
00710   const EcalTrigTowerConstituentsMap * triggerTowerMap_;
00711 
00715   const EcalTPParameters* tpParam_;
00716 
00719   const EcalElectronicsMapping* elecMap_;
00720   
00724   bool localReco_;
00725   
00728   std::vector<double> weights_;
00729 
00732   std::vector<int> firWeights_;
00733 
00736   int ebZsThr_;
00737 
00740   int eeZsThr_;
00741   
00744   bool tpInGeV_;
00745 
00749   int firstFIRSample_;
00750 
00754   bool useEventRate_;
00755 
00760   std::vector<bool> logErrForDccs_;
00761   
00764   int nEb_;
00765 
00768   int nEe_;
00769 
00772   int nEeLI_;
00773 
00776   int nEeHI_;
00777 
00780   int nEbLI_;
00781 
00784   int nEbHI_;
00785 
00788   int nPerDcc_[nDccs_];
00789 
00792   int nLiPerDcc_[nDccs_];
00793 
00796   int nHiPerDcc_[nDccs_];
00797 
00798   
00801   int nRuPerDcc_[nDccs_];
00802 
00805   int nLiRuPerDcc_[nDccs_];
00806 
00809   int nHiRuPerDcc_[nDccs_];
00810 
00811   
00813 
00815   bool ebRuActive_[nEbEta/ebTtEdge][nEbPhi/ebTtEdge];
00816   bool eeRuActive_[nEndcaps][nEeX/scEdge][nEeY/scEdge];
00818   
00819   bool isRuComplete_[nDccs_][nDccChs_];
00820 
00823   int nPerRu_[nDccs_][nDccChs_];  
00824   
00827   int ievt_;
00828 
00833   double ttEtSums[nTtEta][nTtPhi];
00834 
00838   energiesEb_t ebEnergies[nEbEta][nEbPhi];
00839 
00844   energiesEe_t eeEnergies[nEndcaps][nEeX][nEeY];
00845 
00848   bool SkipInnerSC_;
00849 
00853   std::set<std::string> histList_;
00854 
00857   bool allHists_;
00858 
00861   std::string histDir_;
00862   
00866   std::map<std::string, std::string> availableHistList_;
00867 
00868 
00871   bool withEeSimHit_;
00872 
00875   bool withEbSimHit_;
00876   
00881   bool registerHist(const std::string& name, const std::string& title);
00882 
00886   void printAvailableHists();
00887 
00891   void normalizeHists(double eventCount);
00892 
00898   void configFirWeights(std::vector<double> weightsForZsFIR);
00899 
00904   bool logSrpAlgoErrors_;
00905 
00909   bool logSrApplicationErrors_;
00910 
00919   template<class T>
00920   void compareSrfColl(const edm::Event& event, T& srfFromData, T& computedSrf);
00921 
00926   template<class T>
00927   void checkSrApplication(const edm::Event& event, T& srfs);
00928 
00929   
00933 
00934   int ruGraphX(const EcalScDetId& id) const{
00935     return id.ix() + (id.zside()>0?20:-40);
00936   }
00937   
00938   int ruGraphY(const EcalScDetId& id) const{
00939     return id.iy();
00940   }
00941   
00942   int ruGraphX(const EcalTrigTowerDetId& id) const{
00943     return id.ieta();
00944   }
00945   
00946   int ruGraphY(const EcalTrigTowerDetId& id) const{
00947     return id.iphi();
00948   }
00949   
00950   int xtalGraphX(const EEDetId& id) const{
00951     return id.ix() + (id.zside()>0?100:-200);
00952   }
00953   
00954   int xtalGraphY(const EEDetId& id) const{
00955     return id.iy();
00956   }
00957   
00958   int xtalGraphX(const EBDetId& id) const{
00959     return id.ieta();
00960   }
00961   
00962   int xtalGraphY(const EBDetId& id) const{
00963     return id.iphi();
00964   }
00966 
00968 
00971   int dccId(const EcalScDetId& detId) const;
00972   int dccId(const EcalTrigTowerDetId& detId) const;
00974 
00980   void selectFedsForLog();
00981 
00987   int getCrystalCount(int iDcc, int iDccCh);
00988 
00989   
00990 private:
00993   class Sorter{
00994     EcalSelectiveReadoutValidation* validation;
00995   public:
00996     Sorter(EcalSelectiveReadoutValidation* v): validation(v){};
00997     bool operator()(std::pair<int,int>a, std::pair<int,int>b){
00998       return (validation->ebEnergies[a.first][a.second].simE
00999               > validation->ebEnergies[b.first][b.second].simE);
01000     }
01001   };
01002 
01003   void myAna();
01004 };
01005 
01006 #endif //EcalSelectiveReadoutValidation_H not defined
01007