File indexing completed on 2023-03-17 10:41:36
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
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
0032 public:
0033
0034
0035
0036 EcalDccWeightBuilder(edm::ParameterSet const& ps);
0037
0038
0039
0040 ~EcalDccWeightBuilder() override{};
0041
0042
0043 public:
0044
0045
0046
0047
0048 void analyze(const edm::Event& event, const edm::EventSetup& es) override;
0049
0050 private:
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
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
0081
0082
0083
0084 double intercalib(const DetId& detId);
0085
0086 void writeWeightToAsciiFile();
0087 void writeWeightToRootFile();
0088 void writeWeightToDB();
0089
0090
0091 void dbId(const DetId& detId, int& fedId, int& smId, int& ruId, int& xtalId) const;
0092
0093
0094
0095
0096
0097
0098
0099 template <class T>
0100 void sort(const std::vector<T>& a, std::vector<int>& s, bool decreasingOrder = false);
0101
0102
0103 protected:
0104 private:
0105 int dcc1stSample_;
0106 int sampleToSkip_;
0107 int nDccWeights_;
0108
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