Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-30 02:37:16

0001 #ifndef ECALZEROSUPPRESSIONPRODUCER_H
0002 #define ECALZEROSUPPRESSIONPRODUCER_H
0003 
0004 #include "FWCore/Framework/interface/ConsumesCollector.h"
0005 #include "FWCore/Framework/interface/one/EDProducer.h"
0006 #include "FWCore/Utilities/interface/ESGetToken.h"
0007 #include "DataFormats/EcalDigi/interface/EcalDigiCollections.h"
0008 #include "SimCalorimetry/EcalSelectiveReadoutAlgos/interface/EcalSelectiveReadoutSuppressor.h"
0009 #include "DataFormats/Provenance/interface/ProductID.h"
0010 #include "CondFormats/EcalObjects/interface/EcalSRSettings.h"
0011 #include "CondFormats/DataRecord/interface/EcalSRSettingsRcd.h"
0012 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0013 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
0014 
0015 #include <memory>
0016 #include <vector>
0017 
0018 class EcalSelectiveReadoutProducer : public edm::one::EDProducer<> {
0019 public:
0020   /** Constructor
0021    * @param params seletive readout parameters
0022    */
0023   explicit EcalSelectiveReadoutProducer(const edm::ParameterSet& params);
0024 
0025   /** Destructor
0026    */
0027 
0028   ~EcalSelectiveReadoutProducer() override;
0029 
0030   /** Produces the EDM products
0031    * @param CMS event
0032    * @param eventSetup event conditions
0033    */
0034   void produce(edm::Event& event, const edm::EventSetup& eventSetup) override;
0035 
0036   /** Help function to print SR flags.
0037    * @param ebSrFlags the action flags of EB
0038    * @param eeSrFlag the action flags of EE
0039    * @param iEvent event number. Ignored if <0.
0040    * @param withHeader, if true an output description is written out as header.
0041    */
0042   static void printSrFlags(std::ostream& os,
0043                            const EBSrFlagCollection& ebSrFlags,
0044                            const EESrFlagCollection& eeSrFlags,
0045                            int iEvent = -1,
0046                            bool withHeader = true);
0047 
0048 private:
0049   /** Sanity check on the DCC FIR filter weights. Log warning or
0050    * error message if an unexpected weight set is found. In principle
0051    * it is checked that the maximum weight is applied to the expected
0052    * maximum sample.
0053    */
0054   void checkWeights(const edm::Event& evt, const edm::ProductID& noZSDigiId) const;
0055 
0056   /** Gets the value of the digitizer binOfMaximum parameter.
0057    * @param noZsDigiId product ID of the non-suppressed digis
0058    * @param binOfMax [out] set the parameter value if found
0059    * @return true on success, false otherwise
0060    */
0061   bool getBinOfMax(const edm::Event& evt, const edm::ProductID& noZsDigiId, int& binOfMax) const;
0062 
0063   const EBDigiCollection* getEBDigis(edm::Event& event);
0064 
0065   const EEDigiCollection* getEEDigis(edm::Event& event);
0066 
0067   const EcalTrigPrimDigiCollection* getTrigPrims(edm::Event& event) const;
0068 
0069   ///@{
0070   /// call these once an event, to make sure everything
0071   /// is up-to-date
0072   void checkGeometry(const edm::EventSetup& eventSetup);
0073   void checkTriggerMap(const edm::EventSetup& eventSetup);
0074   void checkElecMap(const edm::EventSetup& eventSetup);
0075 
0076   ///@}
0077 
0078   ///Checks validity of selective setting object is valid to be used
0079   ///for MC, especially checks the number of elements in the vectors
0080   ///@param forEmulator if true check the restriction that applies for
0081   ///EcalSelectiveReadoutProducer
0082   ///@throw cms::Exception if the setting is not valid.
0083   static void checkValidity(const EcalSRSettings& settings);
0084 
0085   void printTTFlags(const EcalTrigPrimDigiCollection& tp, std::ostream& os) const;
0086 
0087 private:
0088   EcalSelectiveReadoutSuppressor suppressor_;
0089   std::string digiProducer_;         // name of module/plugin/producer making digis
0090   std::string ebdigiCollection_;     // secondary name given to collection of input digis
0091   std::string eedigiCollection_;     // secondary name given to collection of input digis
0092   std::string ebSRPdigiCollection_;  // secondary name given to collection of suppressed digis
0093   std::string eeSRPdigiCollection_;  // secondary name given to collection of suppressed digis
0094   std::string ebSrFlagCollection_;   // secondary name given to collection of SR flag digis
0095   std::string eeSrFlagCollection_;   // secondary name given to collection of SR flag digis
0096   std::string trigPrimProducer_;     // name of module/plugin/producer making triggere primitives
0097   std::string trigPrimCollection_;   // name of module/plugin/producer making triggere primitives
0098 
0099   // store the pointer, so we don't have to update it every event
0100   const CaloGeometry* theGeometry;
0101   const EcalTrigTowerConstituentsMap* theTriggerTowerMap;
0102   const EcalElectronicsMapping* theElecMap;
0103 
0104   bool suppressorSettingsSet_ = false;
0105 
0106   bool trigPrimBypass_;
0107 
0108   int trigPrimBypassMode_;
0109 
0110   /** Number of event whose TT and SR flags must be dumped into a file.
0111    */
0112   int dumpFlags_;
0113 
0114   /** switch to write out the SrFlags collections in the event
0115    */
0116   bool writeSrFlags_;
0117 
0118   /** Switch for suppressed digi production If false SR flags are produced
0119    * but selective readout is not applied on the crystal channel digis.
0120    */
0121   bool produceDigis_;
0122 
0123   /** SR settings
0124    */
0125   const EcalSRSettings* settings_;
0126 
0127   /** Switch for retrieving SR settings from condition database instead
0128    * of CMSSW python configuration file.
0129    */
0130   bool useCondDb_;
0131 
0132   /**  Special switch to turn off SR entirely using special DB entries 
0133    */
0134 
0135   bool useFullReadout_;
0136 
0137   /** keys
0138    */
0139   bool firstCallEB_;
0140   bool firstCallEE_;
0141   int iEvent_;
0142 
0143   /** Used when settings_ is imported from configuration file. Just used
0144    * for memory management. Used settings_ to access to the object
0145    */
0146   std::unique_ptr<EcalSRSettings> settingsFromFile_;
0147 
0148   // Tokens for consumes collection:
0149 
0150   edm::EDGetTokenT<EBDigiCollection> EB_token;
0151   edm::EDGetTokenT<EEDigiCollection> EE_token;
0152   edm::EDGetTokenT<EcalTrigPrimDigiCollection> EcTP_token;
0153   edm::ESGetToken<EcalSRSettings, EcalSRSettingsRcd> hSr_token_;
0154   edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geom_token_;
0155   edm::ESGetToken<EcalTrigTowerConstituentsMap, IdealGeometryRecord> eTTmap_token_;
0156   edm::ESGetToken<EcalElectronicsMapping, EcalMappingRcd> eElecmap_token_;
0157 };
0158 
0159 #endif