Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-09-16 03:23:21

0001 #ifndef CalibCalorimetry_EcalSRTools_EcalDccWeightBuilder_h
0002 #define CalibCalorimetry_EcalSRTools_EcalDccWeightBuilder_h
0003 
0004 #include "FWCore/Framework/interface/one/EDAnalyzer.h"
0005 #include "SimCalorimetry/EcalSimAlgos/interface/EBShape.h"
0006 #include "SimCalorimetry/EcalSimAlgos/interface/EEShape.h"
0007 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0008 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0009 #include "CondFormats/EcalObjects/interface/EcalIntercalibConstants.h"
0010 #include "CondFormats/DataRecord/interface/EcalIntercalibConstantsRcd.h"
0011 #include "Geometry/EcalMapping/interface/EcalElectronicsMapping.h"
0012 #include "Geometry/EcalMapping/interface/EcalMappingRcd.h"
0013 #include "Geometry/Records/interface/CaloGeometryRecord.h"
0014 #include "FWCore/Framework/interface/EventSetup.h"
0015 #include "FWCore/Framework/interface/ESHandle.h"
0016 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
0017 
0018 #include <vector>
0019 #include <map>
0020 #include <cinttypes>
0021 
0022 // Forward declarations:
0023 class EcalElectronicsMapping;
0024 
0025 /**
0026  */
0027 class EcalDccWeightBuilder : public edm::one::EDAnalyzer<> {
0028 private:
0029   enum mode_t { WEIGHTS_FROM_CONFIG, COMPUTE_WEIGHTS };
0030 
0031   //constructor(s) and destructor(s)
0032 public:
0033   /** Constructs an EcalDccWeightBuilder
0034    * @param ps CMSSW mondule configuration
0035    */
0036   EcalDccWeightBuilder(edm::ParameterSet const& ps);
0037 
0038   /**Destructor
0039    */
0040   ~EcalDccWeightBuilder() override{};
0041 
0042   //method(s)
0043 public:
0044   /** Analyze method called by the event loop.
0045    * @param event CMSSW event
0046    * @param es event setup
0047    */
0048   void analyze(const edm::Event& event, const edm::EventSetup& es) override;
0049 
0050 private:
0051   /** Weight computation
0052    * @param shape signal shape to use for weight computation
0053    * @param binOfMax time bin which shall contain the pulse peak
0054    * @param timePhase signal phase. First sample corresponds to
0055    *                  t = ((binOfMax-1)*25+timePhase) ns
0056    * in the time reference of EcalShapeBase.
0057    * @param iFirst first sample the weights must be applied to
0058    * @param nWeights number of weights
0059    * @param iSkip0 if greater than 0, the corresponding sample will not be
0060    * used (weights forced to 0).
0061    * @param result [out] vector filled with computed weights. The vector is
0062    * resized to the number of weights
0063    */
0064   void computeWeights(const EcalShapeBase& shape,
0065                       int binOfMax,
0066                       double timePhase,
0067                       int iFirst0,
0068                       int nWeights,
0069                       int iSkip0,
0070                       std::vector<double>& result);
0071 
0072   void computeAllWeights(bool withIntercalib, const edm::EventSetup& es);
0073 
0074   int encodeWeight(double w);
0075 
0076   double decodeWeight(int W);
0077 
0078   void unbiasWeights(std::vector<double>& weights, std::vector<int32_t>* encodedWeigths);
0079 
0080   /** Retrieve intercalibration coefficent for channel detId.
0081    * @param detId ID of the channel the intercalibration coef. must be
0082    * retrieved for.
0083    */
0084   double intercalib(const DetId& detId);
0085 
0086   void writeWeightToAsciiFile();
0087   void writeWeightToRootFile();
0088   void writeWeightToDB();
0089 
0090   //converts DetId to IDs used by DB:
0091   void dbId(const DetId& detId, int& fedId, int& smId, int& ruId, int& xtalId) const;
0092 
0093   /** Vector index sorting.
0094    * @param vector of values
0095    * @param [out] sorted index of the vector
0096    * @param decreasingOrder switch to use decreasing order instead of
0097    * default increasing order
0098    */
0099   template <class T>
0100   void sort(const std::vector<T>& a, std::vector<int>& s, bool decreasingOrder = false);
0101 
0102   //attribute(s)
0103 protected:
0104 private:
0105   int dcc1stSample_;
0106   int sampleToSkip_;
0107   int nDccWeights_;
0108   /** weights used in weightFromConfig mode.
0109    */
0110   std::vector<double> inputWeights_;
0111   std::string mode_;
0112   mode_t imode_;
0113   bool dccWeightsWithIntercalib_;
0114   bool writeToDB_;
0115   bool writeToAsciiFile_;
0116   bool writeToRootFile_;
0117   std::string asciiOutputFileName_;
0118   std::string rootOutputFileName_;
0119   std::string dbSid_;
0120   std::string dbUser_;
0121   std::string dbPassword_;
0122   std::string dbTag_;
0123   int dbVersion_;
0124   bool sqlMode_;
0125 
0126   const edm::ESGetToken<CaloGeometry, CaloGeometryRecord> geometryToken_;
0127   const edm::ESGetToken<EcalElectronicsMapping, EcalMappingRcd> mappingToken_;
0128   const edm::ESGetToken<EcalIntercalibConstants, EcalIntercalibConstantsRcd> intercalibConstToken_;
0129 
0130   edm::ESHandle<CaloGeometry> geom_;
0131 
0132   EcalIntercalibConstantMap& calibMap_;
0133   EcalIntercalibConstantMap emptyCalibMap_;
0134   std::map<DetId, std::vector<int> > encodedWeights_;
0135 
0136   EBShape ebShape_;
0137   EEShape eeShape_;
0138 
0139   static const double weightScale_;
0140   const EcalElectronicsMapping* ecalElectronicsMap_;
0141 
0142   static const int ecalDccFedIdMin = 601;
0143   static const int ecalDccFedIdMax = 654;
0144   static const int nDccs = ecalDccFedIdMax - ecalDccFedIdMin + 1;
0145 };
0146 
0147 #endif  //CalibCalorimetry_EcalSRTools_EcalDccWeightBuilder_h not defined