Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:47:09

0001 //
0002 // Created: 2 Mar 2006
0003 //          Shahram Rahatlou, University of Rome & INFN
0004 //
0005 #include <fstream>
0006 #include <iostream>
0007 #include <memory>
0008 
0009 #include "TRandom3.h"
0010 
0011 #include "CalibCalorimetry/EcalTrivialCondModules/interface/EcalTrivialConditionRetriever.h"
0012 #include "SimG4CMS/Calo/interface/EnergyResolutionVsLumi.h"
0013 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0014 #include "FWCore/Utilities/interface/Exception.h"
0015 
0016 #include "DataFormats/EcalDetId/interface/EBDetId.h"
0017 #include "DataFormats/EcalDetId/interface/EEDetId.h"
0018 #include "DataFormats/EcalDetId/interface/ESDetId.h"
0019 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
0020 #include "DataFormats/EcalDetId/interface/EcalTriggerElectronicsId.h"
0021 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
0022 
0023 //#include "DataFormats/Provenance/interface/Timestamp.h"
0024 
0025 #include "FWCore/MessageLogger/interface/MessageLogger.h"
0026 #include "CondTools/Ecal/interface/EcalIntercalibConstantsXMLTranslator.h"
0027 #include "CondTools/Ecal/interface/EcalIntercalibConstantsMCXMLTranslator.h"
0028 
0029 using namespace edm;
0030 
0031 EcalTrivialConditionRetriever::EcalTrivialConditionRetriever(const edm::ParameterSet& ps) {
0032   std::string dataPath_ =
0033       ps.getUntrackedParameter<std::string>("dataPath", "CalibCalorimetry/EcalTrivialCondModules/data/");
0034   //  std::string dataPath_ = "CalibCalorimetry/EcalTrivialCondModules/data_test/";
0035 
0036   /*since CMSSW_10_6_0, this dataPath_ points to https://github.com/cms-data/CalibCalorimetry-EcalTrivialCondModules  (extra package). 
0037 To modify the default values :
0038 $ git clone https://github.com/cms-data/CalibCalorimetry-EcalTrivialCondModules.git
0039 $ cd CalibCalorimetry-EcalTrivialCondModules
0040 $ modify what you want
0041 $ git commit -a
0042 $ git remote add ModifyCalibCalorimetryExtraPackage  git@github.com:yourName/CalibCalorimetry-EcalTrivialCondModules
0043 $ git push ModifyCalibCalorimetryExtraPackage master:building-calibCalorimetry-extra-package
0044 
0045 other solution : change this dataPath name to work directly in afs, ex. :
0046 
0047   std::string dataPath_="CalibCalorimetry/EcalTrivialCondModules/data_test/";
0048 
0049  */
0050 
0051   // initialize parameters used to produce cond DB objects
0052   totLumi_ = ps.getUntrackedParameter<double>("TotLumi", 0.0);
0053   instLumi_ = ps.getUntrackedParameter<double>("InstLumi", 0.0);
0054 
0055   // initilize parameters used to produce cond DB objects
0056   adcToGeVEBConstant_ = ps.getUntrackedParameter<double>("adcToGeVEBConstant", 0.035);
0057   adcToGeVEEConstant_ = ps.getUntrackedParameter<double>("adcToGeVEEConstant", 0.060);
0058 
0059   intercalibConstantMeanMC_ = ps.getUntrackedParameter<double>("intercalibConstantMeanMC", 1.0);
0060   intercalibConstantSigmaMC_ = ps.getUntrackedParameter<double>("intercalibConstantSigmaMC", 0.0);
0061 
0062   linCorrMean_ = ps.getUntrackedParameter<double>("linCorrMean", 1.0);
0063   linCorrSigma_ = ps.getUntrackedParameter<double>("linCorrSigma", 0.0);
0064 
0065   linearTime1_ = (unsigned long)atoi(ps.getUntrackedParameter<std::string>("linearTime1", "1").c_str());
0066   linearTime2_ = (unsigned long)atoi(ps.getUntrackedParameter<std::string>("linearTime2", "0").c_str());
0067   linearTime3_ = (unsigned long)atoi(ps.getUntrackedParameter<std::string>("linearTime3", "0").c_str());
0068 
0069   intercalibConstantMean_ = ps.getUntrackedParameter<double>("intercalibConstantMean", 1.0);
0070   intercalibConstantSigma_ = ps.getUntrackedParameter<double>("intercalibConstantSigma", 0.0);
0071   intercalibErrorMean_ = ps.getUntrackedParameter<double>("IntercalibErrorMean", 0.0);
0072 
0073   timeCalibConstantMean_ = ps.getUntrackedParameter<double>("timeCalibConstantMean", 0.0);
0074   timeCalibConstantSigma_ = ps.getUntrackedParameter<double>("timeCalibConstantSigma", 0.0);
0075   timeCalibErrorMean_ = ps.getUntrackedParameter<double>("timeCalibErrorMean", 0.0);
0076 
0077   timeOffsetEBConstant_ = ps.getUntrackedParameter<double>("timeOffsetEBConstant", 0.0);
0078   timeOffsetEEConstant_ = ps.getUntrackedParameter<double>("timeOffsetEEConstant", 0.0);
0079 
0080   laserAlphaMean_ = ps.getUntrackedParameter<double>("laserAlphaMean", 1.55);
0081   laserAlphaSigma_ = ps.getUntrackedParameter<double>("laserAlphaSigma", 0);
0082 
0083   laserAPDPNTime1_ = (unsigned long)atoi(ps.getUntrackedParameter<std::string>("laserAPDPNTime1", "1").c_str());
0084   laserAPDPNTime2_ = (unsigned long)atoi(ps.getUntrackedParameter<std::string>("laserAPDPNTime2", "0").c_str());
0085   laserAPDPNTime3_ = (unsigned long)atoi(ps.getUntrackedParameter<std::string>("laserAPDPNTime3", "0").c_str());
0086 
0087   laserAPDPNRefMean_ = ps.getUntrackedParameter<double>("laserAPDPNRefMean", 1.0);
0088   laserAPDPNRefSigma_ = ps.getUntrackedParameter<double>("laserAPDPNRefSigma", 0.0);
0089 
0090   laserAPDPNMean_ = ps.getUntrackedParameter<double>("laserAPDPNMean", 1.0);
0091   laserAPDPNSigma_ = ps.getUntrackedParameter<double>("laserAPDPNSigma", 0.0);
0092 
0093   pfRecHitThresholdsNSigmas_ = ps.getUntrackedParameter<double>("EcalPFRecHitThresholdNSigmas", 1.0);
0094   pfRecHitThresholdsNSigmasHEta_ = ps.getUntrackedParameter<double>("EcalPFRecHitThresholdNSigmasHEta", 1.0);
0095   pfRecHitThresholdsEB_ = ps.getUntrackedParameter<double>("EcalPFRecHitThresholdEB", 0.0);
0096   pfRecHitThresholdsEE_ = ps.getUntrackedParameter<double>("EcalPFRecHitThresholdEE", 0.0);
0097 
0098   localContCorrParameters_ =
0099       ps.getUntrackedParameter<std::vector<double> >("localContCorrParameters", std::vector<double>(0));
0100   crackCorrParameters_ = ps.getUntrackedParameter<std::vector<double> >("crackCorrParameters", std::vector<double>(0));
0101   energyCorrectionParameters_ =
0102       ps.getUntrackedParameter<std::vector<double> >("energyCorrectionParameters", std::vector<double>(0));
0103   energyUncertaintyParameters_ =
0104       ps.getUntrackedParameter<std::vector<double> >("energyUncertaintyParameters", std::vector<double>(0));
0105   energyCorrectionObjectSpecificParameters_ = ps.getUntrackedParameter<std::vector<double> >(
0106       "energyCorrectionObjectSpecificParameters", std::vector<double>(0));
0107 
0108   EBpedMeanX12_ = ps.getUntrackedParameter<double>("EBpedMeanX12", 200.);
0109   EBpedRMSX12_ = ps.getUntrackedParameter<double>("EBpedRMSX12", 1.10);
0110   EBpedMeanX6_ = ps.getUntrackedParameter<double>("EBpedMeanX6", 200.);
0111   EBpedRMSX6_ = ps.getUntrackedParameter<double>("EBpedRMSX6", 0.90);
0112   EBpedMeanX1_ = ps.getUntrackedParameter<double>("EBpedMeanX1", 200.);
0113   EBpedRMSX1_ = ps.getUntrackedParameter<double>("EBpedRMSX1", 0.62);
0114 
0115   EEpedMeanX12_ = ps.getUntrackedParameter<double>("EEpedMeanX12", 200.);
0116   EEpedRMSX12_ = ps.getUntrackedParameter<double>("EEpedRMSX12", 2.50);
0117   EEpedMeanX6_ = ps.getUntrackedParameter<double>("EEpedMeanX6", 200.);
0118   EEpedRMSX6_ = ps.getUntrackedParameter<double>("EEpedRMSX6", 2.00);
0119   EEpedMeanX1_ = ps.getUntrackedParameter<double>("EEpedMeanX1", 200.);
0120   EEpedRMSX1_ = ps.getUntrackedParameter<double>("EEpedRMSX1", 1.40);
0121 
0122   gainRatio12over6_ = ps.getUntrackedParameter<double>("gainRatio12over6", 2.0);
0123   gainRatio6over1_ = ps.getUntrackedParameter<double>("gainRatio6over1", 6.0);
0124 
0125   getWeightsFromFile_ = ps.getUntrackedParameter<bool>("getWeightsFromFile", false);
0126 
0127   sampleMaskEB_ = ps.getUntrackedParameter<unsigned int>("sampleMaskEB", 1023);
0128   sampleMaskEE_ = ps.getUntrackedParameter<unsigned int>("sampleMaskEB", 1023);
0129 
0130   EBtimeCorrAmplitudeBins_ =
0131       ps.getUntrackedParameter<std::vector<double> >("EBtimeCorrAmplitudeBins", std::vector<double>());
0132   EBtimeCorrShiftBins_ = ps.getUntrackedParameter<std::vector<double> >("EBtimeCorrShiftBins", std::vector<double>());
0133   EEtimeCorrAmplitudeBins_ =
0134       ps.getUntrackedParameter<std::vector<double> >("EEtimeCorrAmplitudeBins", std::vector<double>());
0135   EEtimeCorrShiftBins_ = ps.getUntrackedParameter<std::vector<double> >("EEtimeCorrShiftBins", std::vector<double>());
0136 
0137   EBG12samplesCorrelation_ =
0138       ps.getUntrackedParameter<std::vector<double> >("EBG12samplesCorrelation", std::vector<double>());
0139   EBG6samplesCorrelation_ =
0140       ps.getUntrackedParameter<std::vector<double> >("EBG6samplesCorrelation", std::vector<double>());
0141   EBG1samplesCorrelation_ =
0142       ps.getUntrackedParameter<std::vector<double> >("EBG1samplesCorrelation", std::vector<double>());
0143   EEG12samplesCorrelation_ =
0144       ps.getUntrackedParameter<std::vector<double> >("EEG12samplesCorrelation", std::vector<double>());
0145   EEG6samplesCorrelation_ =
0146       ps.getUntrackedParameter<std::vector<double> >("EEG6samplesCorrelation", std::vector<double>());
0147   EEG1samplesCorrelation_ =
0148       ps.getUntrackedParameter<std::vector<double> >("EEG1samplesCorrelation", std::vector<double>());
0149 
0150   sim_pulse_shape_EB_thresh_ = ps.getParameter<double>("sim_pulse_shape_EB_thresh");
0151   sim_pulse_shape_EE_thresh_ = ps.getParameter<double>("sim_pulse_shape_EE_thresh");
0152   sim_pulse_shape_APD_thresh_ = ps.getParameter<double>("sim_pulse_shape_APD_thresh");
0153 
0154   sim_pulse_shape_TI_ = ps.getUntrackedParameter<double>("sim_pulse_shape_TI", 1.0);
0155 
0156   nTDCbins_ = 1;
0157 
0158   weightsForAsynchronousRunning_ = ps.getUntrackedParameter<bool>("weightsForTB", false);
0159 
0160   edm::LogInfo(" EcalTrivialConditionRetriever ");
0161 
0162   if (totLumi_ > 0) {
0163     edm::LogInfo(" EcalTrivialConditionRetriever going to create conditions based on the damage due to ")
0164         << totLumi_ << " fb-1 integrated luminosity";
0165   }
0166 
0167   if (weightsForAsynchronousRunning_) {
0168     getWeightsFromFile_ = true;  //override user request
0169     //nTDCbins_ = 25;
0170     nTDCbins_ = 50;  //modif Alex-21-07-2006
0171   }
0172 
0173   std::string weightType;
0174   std::ostringstream str;
0175 
0176   if (!weightsForAsynchronousRunning_)
0177     str << "_CMS.txt";
0178   else
0179     str << "_TB.txt";
0180 
0181   weightType = str.str();
0182 
0183   amplWeightsFile_ = ps.getUntrackedParameter<std::string>("amplWeightsFile", dataPath_ + "ampWeights" + weightType);
0184   amplWeightsAftFile_ =
0185       ps.getUntrackedParameter<std::string>("amplWeightsAftFile", dataPath_ + "ampWeightsAfterGainSwitch" + weightType);
0186   pedWeightsFile_ = ps.getUntrackedParameter<std::string>("pedWeightsFile", dataPath_ + "pedWeights" + weightType);
0187   pedWeightsAftFile_ =
0188       ps.getUntrackedParameter<std::string>("pedWeightsAftFile", dataPath_ + "pedWeightsAfterGainSwitch" + weightType);
0189   jittWeightsFile_ = ps.getUntrackedParameter<std::string>("jittWeightsFile", dataPath_ + "timeWeights" + weightType);
0190   jittWeightsAftFile_ = ps.getUntrackedParameter<std::string>("jittWeightsAftFile",
0191                                                               dataPath_ + "timeWeightsAfterGainSwitch" + weightType);
0192   chi2MatrixFile_ = ps.getUntrackedParameter<std::string>("chi2MatrixFile", dataPath_ + "chi2Matrix" + weightType);
0193   chi2MatrixAftFile_ =
0194       ps.getUntrackedParameter<std::string>("chi2MatrixAftFile", dataPath_ + "chi2MatrixAfterGainSwitch" + weightType);
0195 
0196   amplWeights_.resize(nTDCbins_);
0197   amplWeightsAft_.resize(nTDCbins_);
0198   pedWeights_.resize(nTDCbins_);
0199   pedWeightsAft_.resize(nTDCbins_);
0200   jittWeights_.resize(nTDCbins_);
0201   jittWeightsAft_.resize(nTDCbins_);
0202   chi2Matrix_.resize(nTDCbins_);
0203   chi2MatrixAft_.resize(nTDCbins_);
0204 
0205   // default weights for MGPA shape after pedestal subtraction
0206   getWeightsFromConfiguration(ps);
0207 
0208   producedEcalPedestals_ = ps.getUntrackedParameter<bool>("producedEcalPedestals", true);
0209   producedEcalWeights_ = ps.getUntrackedParameter<bool>("producedEcalWeights", true);
0210 
0211   producedEcalGainRatios_ = ps.getUntrackedParameter<bool>("producedEcalGainRatios", true);
0212   producedEcalADCToGeVConstant_ = ps.getUntrackedParameter<bool>("producedEcalADCToGeVConstant", true);
0213 
0214   producedEcalMappingElectronics_ = ps.getUntrackedParameter<bool>("producedEcalMappingElectronics", true);
0215   mappingFile_ = ps.getUntrackedParameter<std::string>("mappingFile", "");
0216 
0217   if (producedEcalMappingElectronics_) {
0218     if (!mappingFile_.empty()) {  // if file provided read channel map
0219       setWhatProduced(this, &EcalTrivialConditionRetriever::getMappingFromConfiguration);
0220     } else {
0221       setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalMappingElectronics);
0222     }
0223     findingRecord<EcalMappingElectronicsRcd>();
0224   }
0225   // Alignment from file
0226   getEBAlignmentFromFile_ = ps.getUntrackedParameter<bool>("getEBAlignmentFromFile", false);
0227   if (getEBAlignmentFromFile_) {
0228     EBAlignmentFile_ = ps.getUntrackedParameter<std::string>("EBAlignmentFile", dataPath_ + "EBAlignment.txt");
0229   }
0230 
0231   getEEAlignmentFromFile_ = ps.getUntrackedParameter<bool>("getEEAlignmentFromFile", false);
0232   if (getEEAlignmentFromFile_) {
0233     EEAlignmentFile_ = ps.getUntrackedParameter<std::string>("EEAlignmentFile", dataPath_ + "EEAlignment.txt");
0234   }
0235 
0236   getESAlignmentFromFile_ = ps.getUntrackedParameter<bool>("getESAlignmentFromFile", false);
0237   if (getESAlignmentFromFile_)
0238     ESAlignmentFile_ = ps.getUntrackedParameter<std::string>("ESAlignmentFile", dataPath_ + "ESAlignment.txt");
0239 
0240   verbose_ = ps.getUntrackedParameter<int>("verbose", 0);
0241 
0242   //Tell Producer what we produce
0243   //setWhatproduce(this);
0244   if (producedEcalPedestals_)
0245     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalPedestals);
0246 
0247   if (producedEcalWeights_) {
0248     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalWeightXtalGroups);
0249     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalTBWeights);
0250   }
0251 
0252   if (producedEcalGainRatios_)
0253     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalGainRatios);
0254 
0255   if (producedEcalADCToGeVConstant_)
0256     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalADCToGeVConstant);
0257 
0258   // TimeOffsetConstant
0259   producedEcalTimeOffsetConstant_ = ps.getUntrackedParameter<bool>("producedEcalTimeOffsetConstant", true);
0260   //std::cout << " EcalTrivialConditionRetriever : producedEcalTimeOffsetConstant_" << producedEcalTimeOffsetConstant_ << std::endl;
0261   if (producedEcalTimeOffsetConstant_) {
0262     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalTimeOffsetConstant);
0263     findingRecord<EcalTimeOffsetConstantRcd>();
0264   }
0265 
0266   // linear corrections
0267   producedEcalLinearCorrections_ = ps.getUntrackedParameter<bool>("producedEcalLinearCorrections", true);
0268   linearCorrectionsFile_ = ps.getUntrackedParameter<std::string>("linearCorrectionsFile", "");
0269 
0270   if (producedEcalLinearCorrections_) {     // user asks to produce constants
0271     if (!linearCorrectionsFile_.empty()) {  // if file provided read constants
0272       setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalLinearCorrections);
0273     } else {  // set all constants to 1. or smear as specified by user
0274       setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalLinearCorrections);
0275     }
0276     findingRecord<EcalLinearCorrectionsRcd>();
0277   }
0278 
0279   // intercalibration constants
0280   producedEcalIntercalibConstants_ = ps.getUntrackedParameter<bool>("producedEcalIntercalibConstants", true);
0281   intercalibConstantsFile_ = ps.getUntrackedParameter<std::string>("intercalibConstantsFile", "");
0282 
0283   intercalibConstantsMCFile_ = ps.getUntrackedParameter<std::string>("intercalibConstantsMCFile", "");
0284 
0285   if (producedEcalIntercalibConstants_) {     // user asks to produce constants
0286     if (!intercalibConstantsFile_.empty()) {  // if file provided read constants
0287       setWhatProduced(this, &EcalTrivialConditionRetriever::getIntercalibConstantsFromConfiguration);
0288     } else {  // set all constants to 1. or smear as specified by user
0289       setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalIntercalibConstants);
0290     }
0291     findingRecord<EcalIntercalibConstantsRcd>();
0292   }
0293   // MC intercalibrations
0294   producedEcalIntercalibConstantsMC_ = ps.getUntrackedParameter<bool>("producedEcalIntercalibConstantsMC", true);
0295 
0296   if (producedEcalIntercalibConstantsMC_) {     // user asks to produce constants
0297     if (!intercalibConstantsMCFile_.empty()) {  // if file provided read constants
0298       setWhatProduced(this, &EcalTrivialConditionRetriever::getIntercalibConstantsMCFromConfiguration);
0299     } else {  // set all constants to 1. or smear as specified by user
0300       setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalIntercalibConstantsMC);
0301     }
0302     findingRecord<EcalIntercalibConstantsMCRcd>();
0303   }
0304 
0305   // intercalibration constants
0306   producedEcalIntercalibErrors_ = ps.getUntrackedParameter<bool>("producedEcalIntercalibErrors", true);
0307   intercalibErrorsFile_ = ps.getUntrackedParameter<std::string>("intercalibErrorsFile", "");
0308 
0309   if (producedEcalIntercalibErrors_) {     // user asks to produce constants
0310     if (!intercalibErrorsFile_.empty()) {  // if file provided read constants
0311       setWhatProduced(this, &EcalTrivialConditionRetriever::getIntercalibErrorsFromConfiguration);
0312     } else {  // set all constants to 1. or smear as specified by user
0313       setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalIntercalibErrors);
0314     }
0315     findingRecord<EcalIntercalibErrorsRcd>();
0316   }
0317 
0318   // time calibration constants
0319   producedEcalTimeCalibConstants_ = ps.getUntrackedParameter<bool>("producedEcalTimeCalibConstants", true);
0320   timeCalibConstantsFile_ = ps.getUntrackedParameter<std::string>("timeCalibConstantsFile", "");
0321 
0322   if (producedEcalTimeCalibConstants_) {     // user asks to produce constants
0323     if (!timeCalibConstantsFile_.empty()) {  // if file provided read constants
0324       setWhatProduced(this, &EcalTrivialConditionRetriever::getTimeCalibConstantsFromConfiguration);
0325     } else {  // set all constants to 1. or smear as specified by user
0326       setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalTimeCalibConstants);
0327     }
0328     findingRecord<EcalTimeCalibConstantsRcd>();
0329   }
0330 
0331   // time calibration constants
0332   producedEcalTimeCalibErrors_ = ps.getUntrackedParameter<bool>("producedEcalTimeCalibErrors", true);
0333   timeCalibErrorsFile_ = ps.getUntrackedParameter<std::string>("timeCalibErrorsFile", "");
0334 
0335   if (producedEcalTimeCalibErrors_) {     // user asks to produce constants
0336     if (!timeCalibErrorsFile_.empty()) {  // if file provided read constants
0337       setWhatProduced(this, &EcalTrivialConditionRetriever::getTimeCalibErrorsFromConfiguration);
0338     } else {  // set all constants to 1. or smear as specified by user
0339       setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalTimeCalibErrors);
0340     }
0341     findingRecord<EcalTimeCalibErrorsRcd>();
0342   }
0343 
0344   // sim pulse shape
0345   getSimPulseShapeFromFile_ = ps.getUntrackedParameter<bool>("getSimPulseShapeFromFile", false);
0346   producedEcalSimPulseShape_ = ps.getUntrackedParameter<bool>("producedEcalSimPulseShape", true);
0347   EBSimPulseShapeFile_ = ps.getUntrackedParameter<std::string>("EBSimPulseShapeFile", "");
0348   EESimPulseShapeFile_ = ps.getUntrackedParameter<std::string>("EESimPulseShapeFile", "");
0349   APDSimPulseShapeFile_ = ps.getUntrackedParameter<std::string>("APDSimPulseShapeFile", "");
0350 
0351   if (producedEcalSimPulseShape_) {  // user asks to produce constants
0352     setWhatProduced(this, &EcalTrivialConditionRetriever::getEcalSimPulseShapeFromConfiguration);
0353     findingRecord<EcalSimPulseShapeRcd>();
0354   }
0355 
0356   producedEcalPFRecHitThresholds_ = ps.getUntrackedParameter<bool>("producedEcalPFRecHitThresholds", false);
0357 
0358   // new for PFRecHit Thresholds
0359   pfRecHitFile_ = ps.getUntrackedParameter<std::string>("pFRecHitFile", dataPath_ + "EB_product_TL235.txt");
0360   pfRecHitFileEE_ = ps.getUntrackedParameter<std::string>("pFRecHitFileEE", dataPath_ + "EE_product_TL235.txt");
0361 
0362   if (producedEcalPFRecHitThresholds_) {  // user asks to produce constants
0363     if (!pfRecHitFile_.empty()) {         // if file provided read constants
0364       setWhatProduced(this, &EcalTrivialConditionRetriever::getPFRecHitThresholdsFromConfiguration);
0365     } else {  // set all constants to 0
0366       setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalPFRecHitThresholds);
0367     }
0368     findingRecord<EcalPFRecHitThresholdsRcd>();
0369   }
0370 
0371   // cluster corrections
0372   producedEcalClusterLocalContCorrParameters_ =
0373       ps.getUntrackedParameter<bool>("producedEcalClusterLocalContCorrParameters", false);
0374   producedEcalClusterCrackCorrParameters_ =
0375       ps.getUntrackedParameter<bool>("producedEcalClusterCrackCorrParameters", false);
0376   producedEcalClusterEnergyCorrectionParameters_ =
0377       ps.getUntrackedParameter<bool>("producedEcalClusterEnergyCorrectionParameters", false);
0378   producedEcalClusterEnergyUncertaintyParameters_ =
0379       ps.getUntrackedParameter<bool>("producedEcalClusterEnergyUncertaintyParameters", false);
0380   producedEcalClusterEnergyCorrectionObjectSpecificParameters_ =
0381       ps.getUntrackedParameter<bool>("producedEcalClusterEnergyCorrectionObjectSpecificParameters", false);
0382   if (producedEcalClusterLocalContCorrParameters_) {
0383     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalClusterLocalContCorrParameters);
0384     findingRecord<EcalClusterLocalContCorrParametersRcd>();
0385   }
0386   if (producedEcalClusterCrackCorrParameters_) {
0387     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalClusterCrackCorrParameters);
0388     findingRecord<EcalClusterCrackCorrParametersRcd>();
0389   }
0390   if (producedEcalClusterEnergyCorrectionParameters_) {
0391     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalClusterEnergyCorrectionParameters);
0392     findingRecord<EcalClusterEnergyCorrectionParametersRcd>();
0393   }
0394   if (producedEcalClusterEnergyUncertaintyParameters_) {
0395     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalClusterEnergyUncertaintyParameters);
0396     findingRecord<EcalClusterEnergyUncertaintyParametersRcd>();
0397   }
0398   if (producedEcalClusterEnergyCorrectionObjectSpecificParameters_) {
0399     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalClusterEnergyCorrectionObjectSpecificParameters);
0400     findingRecord<EcalClusterEnergyCorrectionObjectSpecificParametersRcd>();
0401   }
0402 
0403   // laser correction
0404   producedEcalLaserCorrection_ = ps.getUntrackedParameter<bool>("producedEcalLaserCorrection", false);
0405   if (producedEcalLaserCorrection_) {  // user asks to produce constants
0406     // set all constants to 1. or smear as specified by user
0407     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalLaserAlphas);
0408     findingRecord<EcalLaserAlphasRcd>();
0409     getLaserAlphaFromFileEB_ = ps.getUntrackedParameter<bool>("getLaserAlphaFromFileEB", false);
0410     getLaserAlphaFromFileEE_ = ps.getUntrackedParameter<bool>("getLaserAlphaFromFileEE", false);
0411     getLaserAlphaFromTypeEB_ = ps.getUntrackedParameter<bool>("getLaserAlphaFromTypeEB", false);
0412     getLaserAlphaFromTypeEE_ = ps.getUntrackedParameter<bool>("getLaserAlphaFromTypeEE", false);
0413     edm::LogInfo(" getLaserAlphaFromFileEB_ ") << getLaserAlphaFromFileEB_;
0414     edm::LogInfo(" getLaserAlphaFromFileEE_ ") << getLaserAlphaFromFileEE_;
0415     edm::LogInfo(" getLaserAlphaFromTypeEB_ ") << getLaserAlphaFromTypeEB_;
0416     edm::LogInfo(" getLaserAlphaFromTypeEE_ ") << getLaserAlphaFromTypeEE_;
0417     if (getLaserAlphaFromFileEB_) {
0418       EBLaserAlphaFile_ = ps.getUntrackedParameter<std::string>(
0419           "EBLaserAlphaFile", dataPath_ + "EBLaserAlpha.txt");  // file is used to read the alphas
0420     }
0421     if (getLaserAlphaFromFileEE_) {
0422       EELaserAlphaFile_ = ps.getUntrackedParameter<std::string>(
0423           "EELaserAlphaFile", dataPath_ + "EELaserAlpha.txt");  // file is used to read the alphas
0424     }
0425     if (getLaserAlphaFromTypeEB_) {
0426       laserAlphaMeanEBR_ = ps.getUntrackedParameter<double>("laserAlphaMeanEBR", 1.55);  // alpha russian crystals in EB
0427       laserAlphaMeanEBC_ = ps.getUntrackedParameter<double>("laserAlphaMeanEBC", 1.00);  // alpha chinese crystals in EB
0428       EBLaserAlphaFile_ = ps.getUntrackedParameter<std::string>(
0429           "EBLaserAlphaFile", dataPath_ + "EBLaserAlpha.txt");  // file to find out which one is russian/chinese
0430     }
0431     if (getLaserAlphaFromTypeEE_) {
0432       laserAlphaMeanEEC_higheta_ = ps.getUntrackedParameter<double>("laserAlphaMeanEEC_higheta",
0433                                                                     1.00);  // alpha chinese crystals in EE for eta>2.5
0434       laserAlphaMeanEER_higheta_ = ps.getUntrackedParameter<double>("laserAlphaMeanEER_higheta",
0435                                                                     1.16);  // alpha russian crystals in EE for eta>2
0436       laserAlphaMeanEER_ = ps.getUntrackedParameter<double>("laserAlphaMeanEER", 1.16);  // alpha russian crystals in EE
0437       laserAlphaMeanEEC_ = ps.getUntrackedParameter<double>("laserAlphaMeanEEC", 1.00);  // alpha chinese crystals in EE
0438       EELaserAlphaFile_ = ps.getUntrackedParameter<std::string>(
0439           "EELaserAlphaFile",
0440           dataPath_ + "EELaserAlpha.txt");  // file is used to find out which one is russian or chinese
0441       EELaserAlphaFile2_ = ps.getUntrackedParameter<std::string>(
0442           "EELaserAlphaFile2", dataPath_ + "EELaserAlpha2.txt");  // file is used to read the alphas
0443     }
0444     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalLaserAPDPNRatiosRef);
0445     findingRecord<EcalLaserAPDPNRatiosRefRcd>();
0446     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalLaserAPDPNRatios);
0447     findingRecord<EcalLaserAPDPNRatiosRcd>();
0448   }
0449 
0450   // channel status
0451   producedEcalChannelStatus_ = ps.getUntrackedParameter<bool>("producedEcalChannelStatus", true);
0452   channelStatusFile_ = ps.getUntrackedParameter<std::string>("channelStatusFile", "");
0453 
0454   if (producedEcalChannelStatus_) {
0455     if (!channelStatusFile_.empty()) {  // if file provided read channel map
0456       setWhatProduced(this, &EcalTrivialConditionRetriever::getChannelStatusFromConfiguration);
0457     } else {  // set all channels to working -- FIXME might be changed
0458       setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalChannelStatus);
0459     }
0460     findingRecord<EcalChannelStatusRcd>();
0461   }
0462   // DQM channel status
0463   producedEcalDQMChannelStatus_ = ps.getUntrackedParameter<bool>("producedEcalDQMChannelStatus", true);
0464   if (producedEcalDQMChannelStatus_) {
0465     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalDQMChannelStatus);
0466     findingRecord<EcalDQMChannelStatusRcd>();
0467   }
0468   // DCS Tower status
0469   producedEcalDCSTowerStatus_ = ps.getUntrackedParameter<bool>("producedEcalDCSTowerStatus", true);
0470   if (producedEcalDCSTowerStatus_) {
0471     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalDCSTowerStatus);
0472     findingRecord<EcalDCSTowerStatusRcd>();
0473   }
0474   // DAQ Tower status
0475   producedEcalDAQTowerStatus_ = ps.getUntrackedParameter<bool>("producedEcalDAQTowerStatus", true);
0476   if (producedEcalDAQTowerStatus_) {
0477     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalDAQTowerStatus);
0478     findingRecord<EcalDAQTowerStatusRcd>();
0479   }
0480   // DQM Tower status
0481   producedEcalDQMTowerStatus_ = ps.getUntrackedParameter<bool>("producedEcalDQMTowerStatus", true);
0482   if (producedEcalDQMTowerStatus_) {
0483     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalDQMTowerStatus);
0484     findingRecord<EcalDQMTowerStatusRcd>();
0485   }
0486 
0487   // trigger channel status
0488   producedEcalTrgChannelStatus_ = ps.getUntrackedParameter<bool>("producedEcalTrgChannelStatus", true);
0489   trgChannelStatusFile_ = ps.getUntrackedParameter<std::string>("trgChannelStatusFile", "");
0490 
0491   if (producedEcalTrgChannelStatus_) {
0492     if (!trgChannelStatusFile_.empty()) {  // if file provided read channel map
0493       setWhatProduced(this, &EcalTrivialConditionRetriever::getTrgChannelStatusFromConfiguration);
0494     } else {  // set all channels to working -- FIXME might be changed
0495       setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalTrgChannelStatus);
0496     }
0497     findingRecord<EcalTPGCrystalStatusRcd>();
0498   }
0499 
0500   // Alignment
0501   producedEcalAlignmentEB_ = ps.getUntrackedParameter<bool>("producedEcalAlignmentEB", true);
0502   if (producedEcalAlignmentEB_) {
0503     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalAlignmentEB);
0504     findingRecord<EBAlignmentRcd>();
0505   }
0506   producedEcalAlignmentEE_ = ps.getUntrackedParameter<bool>("producedEcalAlignmentEE", true);
0507   if (producedEcalAlignmentEE_) {
0508     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalAlignmentEE);
0509     findingRecord<EEAlignmentRcd>();
0510   }
0511   producedEcalAlignmentES_ = ps.getUntrackedParameter<bool>("producedEcalAlignmentES", true);
0512   if (producedEcalAlignmentES_) {
0513     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalAlignmentES);
0514     findingRecord<ESAlignmentRcd>();
0515   }
0516   //Tell Finder what records we find
0517   if (producedEcalPedestals_)
0518     findingRecord<EcalPedestalsRcd>();
0519 
0520   if (producedEcalWeights_) {
0521     findingRecord<EcalWeightXtalGroupsRcd>();
0522     findingRecord<EcalTBWeightsRcd>();
0523   }
0524 
0525   if (producedEcalGainRatios_)
0526     findingRecord<EcalGainRatiosRcd>();
0527 
0528   if (producedEcalADCToGeVConstant_)
0529     findingRecord<EcalADCToGeVConstantRcd>();
0530 
0531   producedEcalSampleMask_ = ps.getUntrackedParameter<bool>("producedEcalSampleMask", true);
0532   if (producedEcalSampleMask_) {
0533     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalSampleMask);
0534     findingRecord<EcalSampleMaskRcd>();
0535   }
0536   producedEcalTimeBiasCorrections_ = ps.getUntrackedParameter<bool>("producedEcalTimeBiasCorrections", false);
0537   if (producedEcalTimeBiasCorrections_) {
0538     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalTimeBiasCorrections);
0539     findingRecord<EcalTimeBiasCorrectionsRcd>();
0540   }
0541   producedEcalSamplesCorrelation_ = ps.getUntrackedParameter<bool>("producedEcalSamplesCorrelation", false);
0542   if (producedEcalSamplesCorrelation_) {
0543     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalSamplesCorrelation);
0544     findingRecord<EcalSamplesCorrelationRcd>();
0545     getSamplesCorrelationFromFile_ = ps.getUntrackedParameter<bool>("getSamplesCorrelationFromFile", false);
0546     if (getSamplesCorrelationFromFile_) {
0547       SamplesCorrelationFile_ =
0548           ps.getUntrackedParameter<std::string>("SamplesCorrelationFile", "EcalSamplesCorrelation.txt");
0549     }
0550   }
0551 }
0552 
0553 EcalTrivialConditionRetriever::~EcalTrivialConditionRetriever() {}
0554 
0555 //
0556 // member functions
0557 //
0558 void EcalTrivialConditionRetriever::setIntervalFor(const edm::eventsetup::EventSetupRecordKey& rk,
0559                                                    const edm::IOVSyncValue& iTime,
0560                                                    edm::ValidityInterval& oValidity) {
0561   if (verbose_ >= 1)
0562     edm::LogInfo("EcalTrivialConditionRetriever::setIntervalFor(): record key = ")
0563         << rk.name() << "\ttime: " << iTime.time().value();
0564   //For right now, we will just use an infinite interval of validity
0565   oValidity = edm::ValidityInterval(edm::IOVSyncValue::beginOfTime(), edm::IOVSyncValue::endOfTime());
0566 }
0567 
0568 //produce methods
0569 std::unique_ptr<EcalPedestals> EcalTrivialConditionRetriever::produceEcalPedestals(const EcalPedestalsRcd&) {
0570   auto peds = std::make_unique<EcalPedestals>();
0571   EcalPedestals::Item EBitem;
0572   EcalPedestals::Item EEitem;
0573 
0574   EBitem.mean_x1 = EBpedMeanX1_;
0575   EBitem.rms_x1 = EBpedRMSX1_;
0576   EBitem.mean_x6 = EBpedMeanX6_;
0577   EBitem.rms_x6 = EBpedRMSX6_;
0578   EBitem.mean_x12 = EBpedMeanX12_;
0579   EBitem.rms_x12 = EBpedRMSX12_;
0580 
0581   EEitem.mean_x1 = EEpedMeanX1_;
0582   EEitem.rms_x1 = EEpedRMSX1_;
0583   EEitem.mean_x6 = EEpedMeanX6_;
0584   EEitem.rms_x6 = EEpedRMSX6_;
0585   EEitem.mean_x12 = EEpedMeanX12_;
0586   EEitem.rms_x12 = EEpedRMSX12_;
0587 
0588   for (int iEta = -EBDetId::MAX_IETA; iEta <= EBDetId::MAX_IETA; ++iEta) {
0589     if (iEta == 0)
0590       continue;
0591 
0592     if (totLumi_ > 0) {
0593       double eta = EBDetId::approxEta(EBDetId(iEta, 1));
0594 
0595       EnergyResolutionVsLumi ageing;
0596       ageing.setLumi(totLumi_);
0597       ageing.setInstLumi(instLumi_);
0598       eta = fabs(eta);
0599       double noisefactor = ageing.calcnoiseIncreaseADC(eta);
0600 
0601       EBitem.rms_x1 = EBpedRMSX1_ * noisefactor;
0602       EBitem.rms_x6 = EBpedRMSX6_ * noisefactor;
0603       EBitem.rms_x12 = EBpedRMSX12_ * noisefactor;
0604       edm::LogInfo("rms ped at eta:") << eta << " =" << EBitem.rms_x12;
0605     }
0606 
0607     for (int iPhi = EBDetId::MIN_IPHI; iPhi <= EBDetId::MAX_IPHI; ++iPhi) {
0608       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
0609       if (EBDetId::validDetId(iEta, iPhi)) {
0610         EBDetId ebdetid(iEta, iPhi);
0611         peds->insert(std::make_pair(ebdetid.rawId(), EBitem));
0612       }
0613     }
0614   }
0615 
0616   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
0617     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
0618       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
0619       if (EEDetId::validDetId(iX, iY, 1)) {
0620         EEDetId eedetidpos(iX, iY, 1);
0621         peds->insert(std::make_pair(eedetidpos.rawId(), EEitem));
0622       }
0623       if (EEDetId::validDetId(iX, iY, -1)) {
0624         EEDetId eedetidneg(iX, iY, -1);
0625         peds->insert(std::make_pair(eedetidneg.rawId(), EEitem));
0626       }
0627     }
0628   }
0629 
0630   //return std::unique_ptr<EcalPedestals>( peds );
0631   return peds;
0632 }
0633 
0634 std::unique_ptr<EcalWeightXtalGroups> EcalTrivialConditionRetriever::produceEcalWeightXtalGroups(
0635     const EcalWeightXtalGroupsRcd&) {
0636   auto xtalGroups = std::make_unique<EcalWeightXtalGroups>();
0637   EcalXtalGroupId defaultGroupId(1);
0638   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
0639     if (ieta == 0)
0640       continue;
0641     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
0642       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
0643       if (EBDetId::validDetId(ieta, iphi)) {
0644         EBDetId ebid(ieta, iphi);
0645         //    xtalGroups->setValue(ebid.rawId(), EcalXtalGroupId(ieta) ); // define rings in eta
0646         xtalGroups->setValue(ebid.rawId(), defaultGroupId);  // define rings in eta
0647       }
0648     }
0649   }
0650 
0651   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
0652     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
0653       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
0654       if (EEDetId::validDetId(iX, iY, 1)) {
0655         EEDetId eedetidpos(iX, iY, 1);
0656         xtalGroups->setValue(eedetidpos.rawId(), defaultGroupId);
0657       }
0658       if (EEDetId::validDetId(iX, iY, -1)) {
0659         EEDetId eedetidneg(iX, iY, -1);
0660         xtalGroups->setValue(eedetidneg.rawId(), defaultGroupId);
0661       }
0662     }
0663   }
0664   return xtalGroups;
0665 }
0666 
0667 std::unique_ptr<EcalLinearCorrections> EcalTrivialConditionRetriever::produceEcalLinearCorrections(
0668     const EcalLinearCorrectionsRcd&) {
0669   auto ical = std::make_unique<EcalLinearCorrections>();
0670 
0671   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
0672     if (ieta == 0)
0673       continue;
0674     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
0675       if (EBDetId::validDetId(ieta, iphi)) {
0676         EBDetId ebid(ieta, iphi);
0677         double r = (double)std::rand() / (double(RAND_MAX) + double(1));
0678 
0679         EcalLinearCorrections::Values pairAPDPN;
0680         pairAPDPN.p1 = linCorrMean_ + r * linCorrSigma_;
0681         pairAPDPN.p2 = linCorrMean_ + r * linCorrSigma_;
0682         pairAPDPN.p3 = linCorrMean_ + r * linCorrSigma_;
0683         ical->setValue(ebid, pairAPDPN);
0684       }
0685     }
0686   }
0687 
0688   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
0689     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
0690       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
0691       if (EEDetId::validDetId(iX, iY, 1)) {
0692         double r = (double)std::rand() / (double(RAND_MAX) + double(1));
0693         EEDetId eedetidpos(iX, iY, 1);
0694 
0695         EcalLinearCorrections::Values pairAPDPN;
0696         pairAPDPN.p1 = linCorrMean_ + r * linCorrSigma_;
0697         pairAPDPN.p2 = linCorrMean_ + r * linCorrSigma_;
0698         pairAPDPN.p3 = linCorrMean_ + r * linCorrSigma_;
0699 
0700         ical->setValue(eedetidpos, pairAPDPN);
0701       }
0702 
0703       if (EEDetId::validDetId(iX, iY, -1)) {
0704         double r1 = (double)std::rand() / (double(RAND_MAX) + double(1));
0705         EEDetId eedetidneg(iX, iY, -1);
0706 
0707         EcalLinearCorrections::Values pairAPDPN;
0708         pairAPDPN.p1 = linCorrMean_ + r1 * linCorrSigma_;
0709         pairAPDPN.p2 = linCorrMean_ + r1 * linCorrSigma_;
0710         pairAPDPN.p3 = linCorrMean_ + r1 * linCorrSigma_;
0711 
0712         ical->setValue(eedetidneg, pairAPDPN);
0713       }
0714     }
0715   }
0716 
0717   EcalLinearCorrections::Times TimeStamp;
0718   //  for(int i=1; i<=92; i++){
0719   for (int i = 0; i < 92; i++) {
0720     TimeStamp.t1 = Timestamp(linearTime1_);
0721     if (linearTime2_ == 0) {
0722       TimeStamp.t2 = Timestamp(edm::Timestamp::endOfTime().value());
0723     } else {
0724       TimeStamp.t2 = Timestamp(linearTime2_);
0725     }
0726     if (linearTime3_ == 0) {
0727       TimeStamp.t3 = Timestamp(edm::Timestamp::endOfTime().value());
0728     } else {
0729       TimeStamp.t3 = Timestamp(linearTime3_);
0730     }
0731 
0732     ical->setTime(i, TimeStamp);
0733   }
0734 
0735   return ical;
0736 }
0737 
0738 // new for the PF Rec Hit Thresholds
0739 
0740 std::unique_ptr<EcalPFRecHitThresholds> EcalTrivialConditionRetriever::produceEcalPFRecHitThresholds(
0741     const EcalPFRecHitThresholdsRcd&) {
0742   auto ical = std::make_unique<EcalPFRecHitThresholds>();
0743 
0744   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
0745     if (ieta == 0)
0746       continue;
0747     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
0748       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
0749       if (EBDetId::validDetId(ieta, iphi)) {
0750         EBDetId ebid(ieta, iphi);
0751         ical->setValue(ebid.rawId(), pfRecHitThresholdsEB_);
0752       }
0753     }
0754   }
0755 
0756   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
0757     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
0758       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
0759       if (EEDetId::validDetId(iX, iY, 1)) {
0760         EEDetId eedetidpos(iX, iY, 1);
0761         ical->setValue(eedetidpos.rawId(), pfRecHitThresholdsEE_);
0762       }
0763       if (EEDetId::validDetId(iX, iY, -1)) {
0764         EEDetId eedetidneg(iX, iY, -1);
0765         ical->setValue(eedetidneg.rawId(), pfRecHitThresholdsEE_);
0766       }
0767     }
0768   }
0769 
0770   return ical;
0771 }
0772 
0773 //------------------------------
0774 
0775 std::unique_ptr<EcalIntercalibConstants> EcalTrivialConditionRetriever::produceEcalIntercalibConstants(
0776     const EcalIntercalibConstantsRcd&) {
0777   auto ical = std::make_unique<EcalIntercalibConstants>();
0778 
0779   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
0780     if (ieta == 0)
0781       continue;
0782     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
0783       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
0784       if (EBDetId::validDetId(ieta, iphi)) {
0785         EBDetId ebid(ieta, iphi);
0786         double r = (double)std::rand() / (double(RAND_MAX) + double(1));
0787         ical->setValue(ebid.rawId(), intercalibConstantMean_ + r * intercalibConstantSigma_);
0788       }
0789     }
0790   }
0791 
0792   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
0793     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
0794       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
0795       if (EEDetId::validDetId(iX, iY, 1)) {
0796         double r = (double)std::rand() / (double(RAND_MAX) + double(1));
0797         EEDetId eedetidpos(iX, iY, 1);
0798         ical->setValue(eedetidpos.rawId(), intercalibConstantMean_ + r * intercalibConstantSigma_);
0799       }
0800       if (EEDetId::validDetId(iX, iY, -1)) {
0801         double r1 = (double)std::rand() / (double(RAND_MAX) + double(1));
0802         EEDetId eedetidneg(iX, iY, -1);
0803         ical->setValue(eedetidneg.rawId(), intercalibConstantMean_ + r1 * intercalibConstantSigma_);
0804       }
0805     }
0806   }
0807 
0808   return ical;
0809 }
0810 
0811 std::unique_ptr<EcalIntercalibConstantsMC> EcalTrivialConditionRetriever::produceEcalIntercalibConstantsMC(
0812     const EcalIntercalibConstantsMCRcd&) {
0813   auto ical = std::make_unique<EcalIntercalibConstantsMC>();
0814 
0815   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
0816     if (ieta == 0)
0817       continue;
0818     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
0819       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
0820       if (EBDetId::validDetId(ieta, iphi)) {
0821         EBDetId ebid(ieta, iphi);
0822         double r = (double)std::rand() / (double(RAND_MAX) + double(1));
0823         ical->setValue(ebid.rawId(), intercalibConstantMeanMC_ + r * intercalibConstantSigmaMC_);
0824       }
0825     }
0826   }
0827 
0828   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
0829     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
0830       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
0831       if (EEDetId::validDetId(iX, iY, 1)) {
0832         double r = (double)std::rand() / (double(RAND_MAX) + double(1));
0833         EEDetId eedetidpos(iX, iY, 1);
0834         ical->setValue(eedetidpos.rawId(), intercalibConstantMeanMC_ + r * intercalibConstantSigmaMC_);
0835       }
0836       if (EEDetId::validDetId(iX, iY, -1)) {
0837         double r1 = (double)std::rand() / (double(RAND_MAX) + double(1));
0838         EEDetId eedetidneg(iX, iY, -1);
0839         ical->setValue(eedetidneg.rawId(), intercalibConstantMeanMC_ + r1 * intercalibConstantSigmaMC_);
0840       }
0841     }
0842   }
0843 
0844   return ical;
0845 }
0846 
0847 std::unique_ptr<EcalIntercalibErrors> EcalTrivialConditionRetriever::produceEcalIntercalibErrors(
0848     const EcalIntercalibErrorsRcd&) {
0849   auto ical = std::make_unique<EcalIntercalibErrors>();
0850 
0851   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
0852     if (ieta == 0)
0853       continue;
0854     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
0855       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
0856       if (EBDetId::validDetId(ieta, iphi)) {
0857         EBDetId ebid(ieta, iphi);
0858         ical->setValue(ebid.rawId(), intercalibErrorMean_);
0859       }
0860     }
0861   }
0862 
0863   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
0864     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
0865       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
0866       if (EEDetId::validDetId(iX, iY, 1)) {
0867         EEDetId eedetidpos(iX, iY, 1);
0868         ical->setValue(eedetidpos.rawId(), intercalibErrorMean_);
0869       }
0870       if (EEDetId::validDetId(iX, iY, -1)) {
0871         EEDetId eedetidneg(iX, iY, -1);
0872         ical->setValue(eedetidneg.rawId(), intercalibErrorMean_);
0873       }
0874     }
0875   }
0876 
0877   return ical;
0878 }
0879 
0880 std::unique_ptr<EcalTimeCalibConstants> EcalTrivialConditionRetriever::produceEcalTimeCalibConstants(
0881     const EcalTimeCalibConstantsRcd&) {
0882   auto ical = std::make_unique<EcalTimeCalibConstants>();
0883 
0884   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
0885     if (ieta == 0)
0886       continue;
0887     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
0888       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
0889       if (EBDetId::validDetId(ieta, iphi)) {
0890         EBDetId ebid(ieta, iphi);
0891         double r = (double)std::rand() / (double(RAND_MAX) + double(1));
0892         ical->setValue(ebid.rawId(), timeCalibConstantMean_ + r * timeCalibConstantSigma_);
0893       }
0894     }
0895   }
0896 
0897   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
0898     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
0899       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
0900       if (EEDetId::validDetId(iX, iY, 1)) {
0901         double r = (double)std::rand() / (double(RAND_MAX) + double(1));
0902         EEDetId eedetidpos(iX, iY, 1);
0903         ical->setValue(eedetidpos.rawId(), timeCalibConstantMean_ + r * timeCalibConstantSigma_);
0904       }
0905       if (EEDetId::validDetId(iX, iY, -1)) {
0906         double r1 = (double)std::rand() / (double(RAND_MAX) + double(1));
0907         EEDetId eedetidneg(iX, iY, -1);
0908         ical->setValue(eedetidneg.rawId(), timeCalibConstantMean_ + r1 * timeCalibConstantSigma_);
0909       }
0910     }
0911   }
0912 
0913   return ical;
0914 }
0915 
0916 std::unique_ptr<EcalTimeCalibErrors> EcalTrivialConditionRetriever::produceEcalTimeCalibErrors(
0917     const EcalTimeCalibErrorsRcd&) {
0918   auto ical = std::make_unique<EcalTimeCalibErrors>();
0919 
0920   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
0921     if (ieta == 0)
0922       continue;
0923     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
0924       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
0925       if (EBDetId::validDetId(ieta, iphi)) {
0926         EBDetId ebid(ieta, iphi);
0927         ical->setValue(ebid.rawId(), timeCalibErrorMean_);
0928       }
0929     }
0930   }
0931 
0932   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
0933     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
0934       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
0935       if (EEDetId::validDetId(iX, iY, 1)) {
0936         EEDetId eedetidpos(iX, iY, 1);
0937         ical->setValue(eedetidpos.rawId(), timeCalibErrorMean_);
0938       }
0939       if (EEDetId::validDetId(iX, iY, -1)) {
0940         EEDetId eedetidneg(iX, iY, -1);
0941         ical->setValue(eedetidneg.rawId(), timeCalibErrorMean_);
0942       }
0943     }
0944   }
0945 
0946   return ical;
0947 }
0948 
0949 std::unique_ptr<EcalTimeOffsetConstant> EcalTrivialConditionRetriever::produceEcalTimeOffsetConstant(
0950     const EcalTimeOffsetConstantRcd&) {
0951   edm::LogInfo(" produceEcalTimeOffsetConstant: ");
0952   edm::LogInfo("  EB ") << timeOffsetEBConstant_ << " EE " << timeOffsetEEConstant_;
0953   return std::make_unique<EcalTimeOffsetConstant>(timeOffsetEBConstant_, timeOffsetEEConstant_);
0954 }
0955 
0956 std::unique_ptr<EcalGainRatios> EcalTrivialConditionRetriever::produceEcalGainRatios(const EcalGainRatiosRcd&) {
0957   auto gratio = std::make_unique<EcalGainRatios>();
0958   EcalMGPAGainRatio gr;
0959   gr.setGain12Over6(gainRatio12over6_);
0960   gr.setGain6Over1(gainRatio6over1_);
0961 
0962   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
0963     if (ieta == 0)
0964       continue;
0965     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
0966       if (EBDetId::validDetId(ieta, iphi)) {
0967         EBDetId ebid(ieta, iphi);
0968         gratio->setValue(ebid.rawId(), gr);
0969       }
0970     }
0971   }
0972 
0973   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
0974     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
0975       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
0976       if (EEDetId::validDetId(iX, iY, 1)) {
0977         EEDetId eedetidpos(iX, iY, 1);
0978         gratio->setValue(eedetidpos.rawId(), gr);
0979       }
0980       if (EEDetId::validDetId(iX, iY, -1)) {
0981         EEDetId eedetidneg(iX, iY, -1);
0982         gratio->setValue(eedetidneg.rawId(), gr);
0983       }
0984     }
0985   }
0986 
0987   return gratio;
0988 }
0989 
0990 std::unique_ptr<EcalADCToGeVConstant> EcalTrivialConditionRetriever::produceEcalADCToGeVConstant(
0991     const EcalADCToGeVConstantRcd&) {
0992   return std::make_unique<EcalADCToGeVConstant>(adcToGeVEBConstant_, adcToGeVEEConstant_);
0993 }
0994 
0995 std::unique_ptr<EcalTBWeights> EcalTrivialConditionRetriever::produceEcalTBWeights(const EcalTBWeightsRcd&) {
0996   // create weights for the test-beam
0997   auto tbwgt = std::make_unique<EcalTBWeights>();
0998 
0999   // create weights for each distinct group ID
1000   //  int nMaxTDC = 10;
1001   //   for(int igrp=-EBDetId::MAX_IETA; igrp<=EBDetId::MAX_IETA; ++igrp) {
1002   //     if(igrp==0) continue;
1003   int igrp = 1;
1004   for (int itdc = 1; itdc <= nTDCbins_; ++itdc) {
1005     // generate random number
1006     //    double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
1007 
1008     // make a new set of weights
1009     EcalWeightSet wgt;
1010     //typedef std::vector< std::vector<EcalWeight> > EcalWeightSet::EcalWeightMatrix;
1011     EcalWeightSet::EcalWeightMatrix& mat1 = wgt.getWeightsBeforeGainSwitch();
1012     EcalWeightSet::EcalWeightMatrix& mat2 = wgt.getWeightsAfterGainSwitch();
1013 
1014     //     if(verbose_>=1) {
1015     //       std::cout << "initial size of mat1: " << mat1.size() << std::endl;
1016     //       std::cout << "initial size of mat2: " << mat2.size() << std::endl;
1017     //     }
1018 
1019     // generate random numbers to use as weights
1020     /**
1021        for(size_t i=0; i<3; ++i) {
1022        std::vector<EcalWeight> tv1, tv2;
1023        for(size_t j=0; j<10; ++j) {
1024        double ww = igrp*itdc*r + i*10. + j;
1025        //std::cout << "row: " << i << " col: " << j << " -  val: " << ww  << std::endl;
1026        tv1.push_back( EcalWeight(ww) );
1027        tv2.push_back( EcalWeight(100+ww) );
1028        }
1029        mat1.push_back(tv1);
1030        mat2.push_back(tv2);
1031        }
1032     **/
1033 
1034     // use values provided by user
1035     mat1.Place_in_row(amplWeights_[itdc - 1], 0, 0);
1036     mat1.Place_in_row(pedWeights_[itdc - 1], 1, 0);
1037     mat1.Place_in_row(jittWeights_[itdc - 1], 2, 0);
1038 
1039     // wdights after gain switch
1040     mat2.Place_in_row(amplWeightsAft_[itdc - 1], 0, 0);
1041     mat2.Place_in_row(pedWeightsAft_[itdc - 1], 1, 0);
1042     mat2.Place_in_row(jittWeightsAft_[itdc - 1], 2, 0);
1043 
1044     // fill the chi2 matrcies with random numbers
1045     //    r = (double)std::rand()/( double(RAND_MAX)+double(1) );
1046     EcalWeightSet::EcalChi2WeightMatrix& mat3 = wgt.getChi2WeightsBeforeGainSwitch();
1047     EcalWeightSet::EcalChi2WeightMatrix& mat4 = wgt.getChi2WeightsAfterGainSwitch();
1048     mat3 = chi2Matrix_[itdc - 1];
1049     mat4 = chi2MatrixAft_[itdc - 1];
1050 
1051     //     for(size_t i=0; i<10; ++i)
1052     //       {
1053     //  mat3.push_back(chi2Matrix_[itdc-1][i]);
1054     //  mat4.push_back(chi2MatrixAft_[itdc-1][i]);
1055     //       }
1056     //       std::vector<EcalWeight> tv1, tv2;
1057     //       for(size_t j=0; j<10; ++j) {
1058     //  double ww = igrp*itdc*r + i*10. + j;
1059     //  tv1.push_back( EcalWeight(1000+ww) );
1060     //  tv2.push_back( EcalWeight(1000+100+ww) );
1061     //       }
1062 
1063     //     if(verbose_>=1) {
1064     //       std::cout << "group: " << igrp << " TDC: " << itdc
1065     //      << " mat1: " << mat1.size() << " mat2: " << mat2.size()
1066     //      << " mat3: " << mat3.size() << " mat4: " << mat4.size()
1067     //      << std::endl;
1068     //     }
1069 
1070     // put the weight in the container
1071     tbwgt->setValue(std::make_pair(igrp, itdc), wgt);
1072   }
1073   //   }
1074   return tbwgt;
1075 }
1076 
1077 // cluster functions/corrections
1078 std::unique_ptr<EcalClusterLocalContCorrParameters>
1079 EcalTrivialConditionRetriever::produceEcalClusterLocalContCorrParameters(const EcalClusterLocalContCorrParametersRcd&) {
1080   auto ipar = std::make_unique<EcalClusterLocalContCorrParameters>();
1081   for (size_t i = 0; i < localContCorrParameters_.size(); ++i) {
1082     ipar->params().push_back(localContCorrParameters_[i]);
1083   }
1084   return ipar;
1085 }
1086 std::unique_ptr<EcalClusterCrackCorrParameters> EcalTrivialConditionRetriever::produceEcalClusterCrackCorrParameters(
1087     const EcalClusterCrackCorrParametersRcd&) {
1088   auto ipar = std::make_unique<EcalClusterCrackCorrParameters>();
1089   for (size_t i = 0; i < crackCorrParameters_.size(); ++i) {
1090     ipar->params().push_back(crackCorrParameters_[i]);
1091   }
1092   return ipar;
1093 }
1094 std::unique_ptr<EcalClusterEnergyCorrectionParameters>
1095 EcalTrivialConditionRetriever::produceEcalClusterEnergyCorrectionParameters(
1096     const EcalClusterEnergyCorrectionParametersRcd&) {
1097   auto ipar = std::make_unique<EcalClusterEnergyCorrectionParameters>();
1098   for (size_t i = 0; i < energyCorrectionParameters_.size(); ++i) {
1099     ipar->params().push_back(energyCorrectionParameters_[i]);
1100   }
1101   return ipar;
1102 }
1103 std::unique_ptr<EcalClusterEnergyUncertaintyParameters>
1104 EcalTrivialConditionRetriever::produceEcalClusterEnergyUncertaintyParameters(
1105     const EcalClusterEnergyUncertaintyParametersRcd&) {
1106   auto ipar = std::make_unique<EcalClusterEnergyUncertaintyParameters>();
1107   for (size_t i = 0; i < energyUncertaintyParameters_.size(); ++i) {
1108     ipar->params().push_back(energyUncertaintyParameters_[i]);
1109   }
1110   return ipar;
1111 }
1112 std::unique_ptr<EcalClusterEnergyCorrectionObjectSpecificParameters>
1113 EcalTrivialConditionRetriever::produceEcalClusterEnergyCorrectionObjectSpecificParameters(
1114     const EcalClusterEnergyCorrectionObjectSpecificParametersRcd&) {
1115   auto ipar = std::make_unique<EcalClusterEnergyCorrectionObjectSpecificParameters>();
1116   for (size_t i = 0; i < energyCorrectionObjectSpecificParameters_.size(); ++i) {
1117     ipar->params().push_back(energyCorrectionObjectSpecificParameters_[i]);
1118   }
1119   return ipar;
1120 }
1121 
1122 /* 
1123 // laser records
1124 std::unique_ptr<EcalLaserAlphas>
1125 EcalTrivialConditionRetriever::produceEcalLaserAlphas( const EcalLaserAlphasRcd& )
1126 {
1127 
1128   std::cout << " produceEcalLaserAlphas " << std::endl;
1129   auto ical = std::make_unique<EcalLaserAlphas>();
1130 
1131   // get Barrel alpha from type
1132   if(getLaserAlphaFromTypeEB_) {
1133     std::ifstream fEB(edm::FileInPath(EBLaserAlphaFile_).fullPath().c_str());
1134     int SMpos[36] = {-10, 4, -7, -16, 6, -9, 11, -17, 5, 18, 3, -8, 1, -3, -13, 14, -6, 2,
1135              15, -18, 8, 17, -2, 9, -1, 10, -5, 7, -12, -11, 16, -4, -15, -14, 12, 13};
1136     // check!
1137     int SMCal[36] = {12,17,10, 1, 8, 4,27,20,23,25, 6,34,35,15,18,30,21, 9,
1138              24,22,13,31,26,16, 2,11, 5, 0,29,28,14,33,32, 3, 7,19};
1139 
1140     for(int SMcons = 0; SMcons < 36; SMcons++) {
1141       int SM = SMpos[SMcons];
1142       if(SM < 0) SM = 17 + abs(SM);
1143       else SM--;
1144       if(SMCal[SM] != SMcons)
1145      std::cout << " SM pb : read SM " <<  SMcons<< " SMpos " << SM
1146            << " SMCal " << SMCal[SM] << std::endl;
1147     }
1148 
1149     std::string type, batch;
1150     int readSM, pos, bar, bar2;
1151     float alpha = 0;
1152     for(int SMcons = 0; SMcons < 36; SMcons++) {
1153       int SM = SMpos[SMcons];
1154       for(int ic = 0; ic < 1700; ic++) {
1155     fEB >> readSM >> pos >> bar >>  bar2 >> type >> batch;
1156 
1157     if(readSM != SMcons || pos != ic + 1) 
1158       std::cout << " barrel read pb read SM " << readSM << " const SM " << SMcons
1159             << " read pos " << pos << " ic " << ic << std::endl;
1160     if(SM < 0) SM = 18 + abs(SM);
1161     EBDetId ebdetid(SM, pos, EBDetId::SMCRYSTALMODE);
1162     if(bar == 33101 || bar == 30301 )
1163       alpha = laserAlphaMeanEBR_;
1164     else if(bar == 33106) {
1165       if(bar2 <= 2000)
1166         alpha = laserAlphaMeanEBC_;
1167       else {
1168         std::cout << " problem with barcode first " << bar << " last " << bar2 
1169               << " read SM " << readSM << " read pos " << pos << std::endl;
1170         alpha = laserAlphaMeanEBR_;
1171       }
1172     }
1173     ical->setValue( ebdetid, alpha );
1174 
1175     if( ic==1650  ){
1176       std::cout << " ic/alpha "<<ic<<"/"<<alpha<<std::endl; 
1177     }
1178 
1179       }
1180     }  // loop over SMcons
1181     fEB.close(); 
1182     // end laserAlpha from type 
1183   }    else if(getLaserAlphaFromFileEB_) { 
1184     // laser alpha from file 
1185     std::cout <<"Laser alpha for EB will be taken from File"<<std::endl; 
1186     int ieta, iphi;
1187     float alpha;
1188     std::ifstream fEB(edm::FileInPath(EBLaserAlphaFile_).fullPath().c_str());
1189     //    std::ifstream fEB(EBLaserAlphaFile_.c_str());
1190     for(int ic = 0; ic < 61200; ic++) {
1191       fEB >> ieta>> iphi>>alpha;
1192 
1193       if (EBDetId::validDetId(ieta,iphi)) {
1194     EBDetId ebid(ieta,iphi);
1195     ical->setValue( ebid, alpha );
1196     std::cout << " ieta/iphi/alpha "<<ieta<<"/"<<iphi<<"/"<<alpha<<std::endl; 
1197       }
1198       if( ieta==10 ){
1199     std::cout << "I will print some alphas from the file... ieta/iphi/alpha "<<ieta<<"/"<<iphi<<"/"<<alpha<<std::endl; 
1200       }
1201     }
1202     fEB.close(); 
1203 
1204   } else {
1205     // laser alpha from mean and smearing 
1206     for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
1207       if(ieta==0) continue;
1208       for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
1209     if (EBDetId::validDetId(ieta,iphi)) {
1210       EBDetId ebid(ieta,iphi);
1211       double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
1212       ical->setValue( ebid, laserAlphaMean_ + r*laserAlphaSigma_ );
1213     }
1214       }  // loop over iphi
1215     }  // loop over ieta
1216   }   // do not read a file
1217 
1218   std::cout << " produceEcalLaserAlphas EE" << std::endl;
1219   if(getLaserAlphaFromTypeEE_) {
1220     std::ifstream fEE(edm::FileInPath(EELaserAlphaFile_).fullPath().c_str());
1221 
1222     for(int crystal = 0; crystal < 14648; crystal++) {
1223       int x, y ,z, bid, bar, bar2;
1224       float LY, alpha = 0;
1225       fEE >> z >> x >> y >> LY >> bid >> bar >> bar2;
1226       if(x < 1 || x > 100 || y < 1 || y > 100)
1227     std::cout << " wrong coordinates for barcode " << bar 
1228           << " x " << x << " y " << y << " z " << z << std::endl;
1229       else {
1230     if(bar == 33201 || (bar == 30399 && bar2 < 568))
1231         alpha = laserAlphaMeanEER_;
1232     else if((bar == 33106 && bar2 > 2000 && bar2 < 4669) 
1233         || (bar == 30399 && bar2 > 567))
1234       alpha = laserAlphaMeanEEC_;
1235     else {
1236       std::cout << " problem with barcode " << bar << " " << bar2 
1237             << " x " << x << " y " << y << " z " << z << std::endl;
1238       alpha = laserAlphaMeanEER_;
1239     }
1240       } 
1241       if (EEDetId::validDetId(x, y, z)) {
1242     EEDetId eedetidpos(x, y, z);
1243     ical->setValue( eedetidpos, alpha );
1244       }
1245       else // should not occur
1246     std::cout << " problem with EEDetId " << " x " << x << " y " << y << " z " << z << std::endl;
1247     }  
1248     fEE.close(); 
1249 
1250     // end laserAlpha from type EE
1251 
1252   } else if (getLaserAlphaFromFileEE_) {
1253 
1254     std::ifstream fEE(edm::FileInPath(EELaserAlphaFile_).fullPath().c_str());
1255 
1256     for(int crystal = 0; crystal < 14648; crystal++) {
1257       int x, y ,z;
1258       float alpha = 1;
1259       fEE >> z >> x >> y >> alpha;
1260       if(x < 1 || x > 100 || y < 1 || y > 100 || z==0 || z>1 || z<-1 ) {
1261     std::cout << "ERROR: wrong coordinates for crystal " 
1262           << " x " << x << " y " << y << " z " << z << std::endl;
1263     std::cout << " the format of the file should be z x y alpha " << std::endl;
1264       } else {
1265     if (EEDetId::validDetId(x, y, z)) {
1266       EEDetId eedetidpos(x, y, z);
1267       ical->setValue( eedetidpos, alpha );
1268     }
1269     else // should not occur
1270       std::cout << " problem with EEDetId " << " x " << x << " y " << y << " z " << z << std::endl;
1271       }  
1272     }
1273     fEE.close(); 
1274 
1275     // end laser alpha from file EE
1276   }  else {
1277     // alphas from python config file
1278     for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
1279       for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
1280     // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
1281     if (EEDetId::validDetId(iX,iY,1)) {
1282       double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
1283       EEDetId eedetidpos(iX,iY,1);
1284       ical->setValue( eedetidpos, laserAlphaMean_ + r*laserAlphaSigma_ );
1285     }
1286     if (EEDetId::validDetId(iX,iY,-1)) {
1287       double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
1288       EEDetId eedetidneg(iX,iY,-1);
1289       ical->setValue( eedetidneg, laserAlphaMean_ + r1*laserAlphaSigma_ );
1290     }
1291       } // loop over iY
1292     } // loop over iX
1293   }  
1294   
1295   return ical;
1296 }
1297 */
1298 
1299 // laser alphas
1300 std::unique_ptr<EcalLaserAlphas> EcalTrivialConditionRetriever::produceEcalLaserAlphas(const EcalLaserAlphasRcd&) {
1301   edm::LogInfo(" produceEcalLaserAlphas ");
1302   auto ical = std::make_unique<EcalLaserAlphas>();
1303 
1304   // get Barrel alpha from type
1305   if (getLaserAlphaFromTypeEB_) {
1306     std::ifstream fEB(edm::FileInPath(EBLaserAlphaFile_).fullPath().c_str());
1307     int SMpos[36] = {-10, 4,   -7, -16, 6,  -9, 11, -17, 5,  18, 3,   -8,  1,  -3, -13, 14,  -6, 2,
1308                      15,  -18, 8,  17,  -2, 9,  -1, 10,  -5, 7,  -12, -11, 16, -4, -15, -14, 12, 13};
1309     // check!
1310     int SMCal[36] = {12, 17, 10, 1,  8,  4,  27, 20, 23, 25, 6,  34, 35, 15, 18, 30, 21, 9,
1311                      24, 22, 13, 31, 26, 16, 2,  11, 5,  0,  29, 28, 14, 33, 32, 3,  7,  19};
1312 
1313     for (int SMcons = 0; SMcons < 36; SMcons++) {
1314       int SM = SMpos[SMcons];
1315       if (SM < 0)
1316         SM = 17 + abs(SM);
1317       else
1318         SM--;
1319       if (SMCal[SM] != SMcons)
1320         edm::LogInfo(" SM pb : read SM ") << SMcons << " SMpos " << SM << " SMCal " << SMCal[SM];
1321     }
1322 
1323     std::string type, batch;
1324     int readSM, pos, bar, bar2;
1325     float alpha = 0;
1326     for (int SMcons = 0; SMcons < 36; SMcons++) {
1327       int SM = SMpos[SMcons];
1328       for (int ic = 0; ic < 1700; ic++) {
1329         fEB >> readSM >> pos >> bar >> bar2 >> type >> batch;
1330 
1331         if (readSM != SMcons || pos != ic + 1)
1332           edm::LogInfo(" barrel read pb read SM ")
1333               << readSM << " const SM " << SMcons << " read pos " << pos << " ic " << ic;
1334         if (SM < 0)
1335           SM = 18 + abs(SM);
1336         EBDetId ebdetid(SM, pos, EBDetId::SMCRYSTALMODE);
1337         if (bar == 33101 || bar == 30301)
1338           alpha = laserAlphaMeanEBR_;
1339         else if (bar == 33106) {
1340           if (bar2 <= 2000)
1341             alpha = laserAlphaMeanEBC_;
1342           else {
1343             edm::LogInfo(" problem with barcode first ")
1344                 << bar << " last " << bar2 << " read SM " << readSM << " read pos " << pos;
1345             alpha = laserAlphaMeanEBR_;
1346           }
1347         }
1348         ical->setValue(ebdetid, alpha);
1349 
1350         if (ic == 1650) {
1351           edm::LogInfo(" ic/alpha ") << ic << "/" << alpha;
1352         }
1353       }
1354     }  // loop over SMcons
1355     fEB.close();
1356     // end laserAlpha from type
1357   } else if (getLaserAlphaFromFileEB_) {
1358     // laser alpha from file
1359     edm::LogInfo("Laser alpha for EB will be taken from File");
1360     int ieta, iphi;
1361     float alpha;
1362     std::ifstream fEB(edm::FileInPath(EBLaserAlphaFile_).fullPath().c_str());
1363     //    std::ifstream fEB(EBLaserAlphaFile_.c_str());
1364     for (int ic = 0; ic < 61200; ic++) {
1365       fEB >> ieta >> iphi >> alpha;
1366 
1367       if (EBDetId::validDetId(ieta, iphi)) {
1368         EBDetId ebid(ieta, iphi);
1369         ical->setValue(ebid, alpha);
1370         //std::cout << " ieta/iphi/alpha "<<ieta<<"/"<<iphi<<"/"<<alpha<<std::endl;
1371       }
1372       if (ieta == 10) {
1373         edm::LogInfo("I will print some alphas from the file... ieta/iphi/alpha ")
1374             << ieta << "/" << iphi << "/" << alpha;
1375       }
1376     }
1377     fEB.close();
1378 
1379   } else {
1380     edm::LogInfo("laser alphas from default values");
1381 
1382     // laser alpha from mean and smearing
1383     for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
1384       if (ieta == 0)
1385         continue;
1386       for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
1387         if (EBDetId::validDetId(ieta, iphi)) {
1388           EBDetId ebid(ieta, iphi);
1389           double r = (double)std::rand() / (double(RAND_MAX) + double(1));
1390           ical->setValue(ebid, laserAlphaMean_ + r * laserAlphaSigma_);
1391         }
1392       }  // loop over iphi
1393     }    // loop over ieta
1394   }      // do not read a file
1395 
1396   edm::LogInfo(" produceEcalLaserAlphas EE");
1397   // read mean laser per ring per year
1398 
1399   int itype, iring, iyear;
1400   float laser = 0;
1401   float las[2][140][6];
1402 
1403   if (getLaserAlphaFromTypeEE_) {
1404     edm::LogInfo(" EE laser alphas from type");
1405 
1406     std::ifstream fRing(edm::FileInPath(EELaserAlphaFile2_).fullPath().c_str());
1407     for (int i = 0; i < 1681; i++) {
1408       fRing >> itype >> iring >> iyear >> laser;
1409       edm::LogInfo(" ") << itype << " " << iring << " " << iyear << " " << laser << std::endl;
1410       las[itype][iring][iyear] = laser;
1411     }
1412     fRing.close();
1413 
1414     std::ifstream fEE(edm::FileInPath(EELaserAlphaFile_).fullPath().c_str());
1415     int nxt = 0;
1416     for (int crystal = 0; crystal < 14648; crystal++) {
1417       int x, y, z, bid, bar, bar2;
1418       float LY, alpha = 0;
1419       fEE >> z >> x >> y >> LY >> bid >> bar >> bar2;
1420       if (x < 1 || x > 100 || y < 1 || y > 100)
1421         edm::LogInfo(" wrong coordinates for barcode ") << bar << " x " << x << " y " << y << " z " << z;
1422       else {
1423         int iyear = 4;
1424         int iring = (int)(sqrt(((float)x - 50.5) * ((float)x - 50.5) + ((float)y - 50.5) * ((float)y - 50.5)) + 85);
1425 
1426         double eta = -log(tan(0.5 * atan(sqrt((x - 50.5) * (x - 50.5) + (y - 50.5) * (y - 50.5)) * 2.98 / 328.)));
1427 
1428         if (bar == 33201 || (bar == 30399 && bar2 < 568)) {
1429           // russian
1430           alpha = laserAlphaMeanEER_;
1431 
1432           double raggio = 50.5 - sqrt(((float)x - 50.5) * ((float)x - 50.5) + ((float)y - 50.5) * ((float)y - 50.5));
1433 
1434           if (raggio >= 25) {
1435             alpha = 1.07;
1436           }
1437           /*                                                                                                                                                                
1438             if(raggio>=34){                                                                                                                                                   
1439                                                                                                                                                                               
1440               if(eta>2.0) {                                                                                                                                                   
1441                 itype=0;                                                                                                                                                      
1442                 if(las[itype][iring][iyear]!=999){                                                                                                                            
1443                   alpha=0.8044+0.3555*las[itype][iring][iyear];                                                                                                               
1444                 }                                                                                                                                                             
1445               }                                                                                                                                                               
1446                                                                                                                                                                               
1447             }                                                                                                                                                                 
1448             */
1449 
1450           if (x == 50)
1451             edm::LogInfo("R=") << raggio << " x " << x << " y " << y << " z " << z << "eta=" << eta
1452                                << " alpha=" << alpha << " R";
1453 
1454         } else if ((bar == 33106 && bar2 > 2000 && bar2 < 4669) || (bar == 30399 && bar2 > 567)) {
1455           // SIC
1456           itype = 1;
1457           alpha = laserAlphaMeanEEC_;
1458 
1459           double raggio = 50.5 - sqrt(((float)x - 50.5) * ((float)x - 50.5) + ((float)y - 50.5) * ((float)y - 50.5));
1460 
1461           if (raggio >= 25) {
1462             alpha = 0.80;
1463           }
1464           if (raggio >= 34) {
1465             float r = sqrt((x - 50.5) * (x - 50.5) + (y - 50.5) * (y - 50.5));
1466             if (r < 21) {
1467               nxt = nxt + 1;
1468               // inner SIC crystals
1469 
1470               if (las[itype][iring][iyear] != 999) {
1471                 alpha = 0.7312 + 0.2688 * las[itype][iring][iyear];
1472               }
1473             }
1474           }
1475           if (x == 50)
1476             edm::LogInfo("R=") << raggio << " x " << x << " y " << y << " z " << z << "eta=" << eta
1477                                << " alpha=" << alpha << " C";
1478 
1479         } else {
1480           edm::LogInfo(" problem with barcode ") << bar << " " << bar2 << " x " << x << " y " << y << " z " << z;
1481           alpha = laserAlphaMeanEER_;
1482         }
1483       }
1484 
1485       if (EEDetId::validDetId(x, y, z)) {
1486         EEDetId eedetidpos(x, y, z);
1487         ical->setValue(eedetidpos, alpha);
1488         if (x == 50)
1489           edm::LogInfo(" x ") << x << " y " << y << " alpha " << alpha;
1490       } else  // should not occur
1491         edm::LogInfo(" problem with EEDetId ") << " x " << x << " y " << y << " z " << z;
1492     }
1493     fEE.close();
1494     edm::LogInfo("Number of inner SIC crystals with different alpha= ") << nxt;
1495     // end laserAlpha from type EE
1496 
1497   } else if (getLaserAlphaFromFileEE_) {
1498     edm::LogInfo(" EE laser alphas from file");
1499 
1500     std::ifstream fEE(edm::FileInPath(EELaserAlphaFile_).fullPath().c_str());
1501 
1502     for (int crystal = 0; crystal < 14648; crystal++) {
1503       int x, y, z;
1504       float alpha = 1;
1505       fEE >> z >> x >> y >> alpha;
1506       if (x < 1 || x > 100 || y < 1 || y > 100 || z == 0 || z > 1 || z < -1) {
1507         edm::LogInfo("ERROR: wrong coordinates for crystal ") << " x " << x << " y " << y << " z " << z;
1508         edm::LogInfo(" the format of the file should be z x y alpha ");
1509       } else {
1510         if (EEDetId::validDetId(x, y, z)) {
1511           EEDetId eedetidpos(x, y, z);
1512           ical->setValue(eedetidpos, alpha);
1513         } else  // should not occur
1514           edm::LogInfo(" problem with EEDetId ") << " x " << x << " y " << y << " z " << z;
1515       }
1516     }
1517     fEE.close();
1518 
1519     // end laser alpha from file EE
1520   } else {
1521     // alphas from python config file
1522     edm::LogInfo(" EE laser alphas from default values");
1523     for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
1524       for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
1525         // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
1526         if (EEDetId::validDetId(iX, iY, 1)) {
1527           double r = (double)std::rand() / (double(RAND_MAX) + double(1));
1528           EEDetId eedetidpos(iX, iY, 1);
1529           ical->setValue(eedetidpos, laserAlphaMean_ + r * laserAlphaSigma_);
1530         }
1531         if (EEDetId::validDetId(iX, iY, -1)) {
1532           double r1 = (double)std::rand() / (double(RAND_MAX) + double(1));
1533           EEDetId eedetidneg(iX, iY, -1);
1534           ical->setValue(eedetidneg, laserAlphaMean_ + r1 * laserAlphaSigma_);
1535         }
1536       }  // loop over iY
1537     }    // loop over iX
1538   }
1539 
1540   return ical;
1541 }
1542 
1543 std::unique_ptr<EcalLaserAPDPNRatiosRef> EcalTrivialConditionRetriever::produceEcalLaserAPDPNRatiosRef(
1544     const EcalLaserAPDPNRatiosRefRcd&) {
1545   auto ical = std::make_unique<EcalLaserAPDPNRatiosRef>();
1546   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
1547     if (ieta == 0)
1548       continue;
1549     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
1550       if (EBDetId::validDetId(ieta, iphi)) {
1551         EBDetId ebid(ieta, iphi);
1552         double r = (double)std::rand() / (double(RAND_MAX) + double(1));
1553         ical->setValue(ebid, laserAPDPNRefMean_ + r * laserAPDPNRefSigma_);
1554       }
1555     }
1556   }
1557 
1558   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
1559     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
1560       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
1561       if (EEDetId::validDetId(iX, iY, 1)) {
1562         double r = (double)std::rand() / (double(RAND_MAX) + double(1));
1563         EEDetId eedetidpos(iX, iY, 1);
1564         ical->setValue(eedetidpos, laserAPDPNRefMean_ + r * laserAPDPNRefSigma_);
1565       }
1566 
1567       if (EEDetId::validDetId(iX, iY, -1)) {
1568         double r1 = (double)std::rand() / (double(RAND_MAX) + double(1));
1569         EEDetId eedetidneg(iX, iY, -1);
1570         ical->setValue(eedetidneg, laserAPDPNRefMean_ + r1 * laserAPDPNRefSigma_);
1571       }
1572     }
1573   }
1574 
1575   return ical;
1576 }
1577 
1578 std::unique_ptr<EcalLaserAPDPNRatios> EcalTrivialConditionRetriever::produceEcalLaserAPDPNRatios(
1579     const EcalLaserAPDPNRatiosRcd&) {
1580   EnergyResolutionVsLumi ageing;
1581   ageing.setLumi(totLumi_);
1582   ageing.setInstLumi(instLumi_);
1583 
1584   auto ical = std::make_unique<EcalLaserAPDPNRatios>();
1585   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
1586     if (ieta == 0)
1587       continue;
1588 
1589     double eta = EBDetId::approxEta(EBDetId(ieta, 1));
1590 
1591     eta = fabs(eta);
1592     double drop = ageing.calcampDropTotal(eta);
1593     // edm::LogInfo("EB at eta=")<<eta<<" dropping by "<<drop;
1594 
1595     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
1596       if (EBDetId::validDetId(ieta, iphi)) {
1597         EBDetId ebid(ieta, iphi);
1598         double r = (double)std::rand() / (double(RAND_MAX) + double(1));
1599 
1600         EcalLaserAPDPNRatios::EcalLaserAPDPNpair pairAPDPN;
1601         pairAPDPN.p1 = laserAPDPNMean_ * drop + r * laserAPDPNSigma_;
1602         pairAPDPN.p2 = laserAPDPNMean_ * drop + r * laserAPDPNSigma_;
1603         pairAPDPN.p3 = laserAPDPNMean_ * drop + r * laserAPDPNSigma_;
1604         ical->setValue(ebid, pairAPDPN);
1605       }
1606     }
1607   }
1608 
1609   edm::LogInfo("----- EE -----");
1610 
1611   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
1612     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
1613       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
1614 
1615       if (EEDetId::validDetId(iX, iY, 1)) {
1616         double r = (double)std::rand() / (double(RAND_MAX) + double(1));
1617         EEDetId eedetidpos(iX, iY, 1);
1618 
1619         double eta = -log(tan(0.5 * atan(sqrt((iX - 50.0) * (iX - 50.0) + (iY - 50.0) * (iY - 50.0)) * 2.98 / 328.)));
1620         eta = fabs(eta);
1621         double drop = ageing.calcampDropTotal(eta);
1622         // if(iX==50) edm::LogInfo("EE at eta=")<<eta<<" dropping by "<<drop;
1623 
1624         EcalLaserAPDPNRatios::EcalLaserAPDPNpair pairAPDPN;
1625         pairAPDPN.p1 = laserAPDPNMean_ * drop + r * laserAPDPNSigma_;
1626         pairAPDPN.p2 = laserAPDPNMean_ * drop + r * laserAPDPNSigma_;
1627         pairAPDPN.p3 = laserAPDPNMean_ * drop + r * laserAPDPNSigma_;
1628         ical->setValue(eedetidpos, pairAPDPN);
1629       }
1630 
1631       if (EEDetId::validDetId(iX, iY, -1)) {
1632         double r1 = (double)std::rand() / (double(RAND_MAX) + double(1));
1633         EEDetId eedetidneg(iX, iY, -1);
1634 
1635         double eta = -log(tan(0.5 * atan(sqrt((iX - 50.0) * (iX - 50.0) + (iY - 50.0) * (iY - 50.0)) * 2.98 / 328.)));
1636         eta = fabs(eta);
1637         double drop = ageing.calcampDropTotal(eta);
1638         // if(iX==50) edm::LogInfo("EE at eta=")<<eta<<" dropping by "<<drop;
1639 
1640         EcalLaserAPDPNRatios::EcalLaserAPDPNpair pairAPDPN;
1641         pairAPDPN.p1 = laserAPDPNMean_ * drop + r1 * laserAPDPNSigma_;
1642         pairAPDPN.p2 = laserAPDPNMean_ * drop + r1 * laserAPDPNSigma_;
1643         pairAPDPN.p3 = laserAPDPNMean_ * drop + r1 * laserAPDPNSigma_;
1644         ical->setValue(eedetidneg, pairAPDPN);
1645       }
1646     }
1647   }
1648 
1649   EcalLaserAPDPNRatios::EcalLaserTimeStamp TimeStamp;
1650   //  for(int i=1; i<=92; i++){
1651   for (int i = 0; i < 92; i++) {
1652     TimeStamp.t1 = Timestamp(laserAPDPNTime1_);
1653     if (laserAPDPNTime2_ == 0) {
1654       TimeStamp.t2 = Timestamp(edm::Timestamp::endOfTime().value());
1655     } else {
1656       TimeStamp.t2 = Timestamp(laserAPDPNTime2_);
1657     }
1658     if (laserAPDPNTime3_ == 0) {
1659       TimeStamp.t3 = Timestamp(edm::Timestamp::endOfTime().value());
1660     } else {
1661       TimeStamp.t3 = Timestamp(laserAPDPNTime3_);
1662     }
1663 
1664     ical->setTime(i, TimeStamp);
1665   }
1666 
1667   return ical;
1668 }
1669 
1670 void EcalTrivialConditionRetriever::getWeightsFromConfiguration(const edm::ParameterSet& ps) {
1671   std::vector<std::vector<double> > amplwgtv(nTDCbins_);
1672 
1673   if (!getWeightsFromFile_ && nTDCbins_ == 1) {
1674     std::vector<double> vampl;
1675     //As default using simple 3+1 weights
1676     vampl.push_back(-0.33333);
1677     vampl.push_back(-0.33333);
1678     vampl.push_back(-0.33333);
1679     vampl.push_back(0.);
1680     vampl.push_back(0.);
1681     vampl.push_back(1.);
1682     vampl.push_back(0.);
1683     vampl.push_back(0.);
1684     vampl.push_back(0.);
1685     vampl.push_back(0.);
1686     amplwgtv[0] = ps.getUntrackedParameter<std::vector<double> >("amplWeights", vampl);
1687   } else if (getWeightsFromFile_) {
1688     edm::LogInfo("EcalTrivialConditionRetriever")
1689         << "Reading amplitude weights from file " << edm::FileInPath(amplWeightsFile_).fullPath().c_str();
1690     std::ifstream amplFile(edm::FileInPath(amplWeightsFile_).fullPath().c_str());
1691     int tdcBin = 0;
1692     while (!amplFile.eof() && tdcBin < nTDCbins_) {
1693       for (int j = 0; j < 10; ++j) {
1694         float ww;
1695         amplFile >> ww;
1696         amplwgtv[tdcBin].push_back(ww);
1697       }
1698       ++tdcBin;
1699     }
1700     assert(tdcBin == nTDCbins_);
1701     //Read from file
1702   } else {
1703     //Not supported
1704     edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1705     throw cms::Exception("WrongConfig");
1706   }
1707 
1708   for (int i = 0; i < nTDCbins_; i++) {
1709     assert(amplwgtv[i].size() == 10);
1710     int j = 0;
1711     for (std::vector<double>::const_iterator it = amplwgtv[i].begin(); it != amplwgtv[i].end(); ++it) {
1712       (amplWeights_[i])[j] = *it;
1713       j++;
1714     }
1715   }
1716 
1717   std::vector<std::vector<double> > amplwgtvAftGain(nTDCbins_);
1718 
1719   if (!getWeightsFromFile_ && nTDCbins_ == 1) {
1720     std::vector<double> vamplAftGain;
1721     vamplAftGain.push_back(0.);
1722     vamplAftGain.push_back(0.);
1723     vamplAftGain.push_back(0.);
1724     vamplAftGain.push_back(0.);
1725     vamplAftGain.push_back(0.);
1726     vamplAftGain.push_back(1.);
1727     vamplAftGain.push_back(0.);
1728     vamplAftGain.push_back(0.);
1729     vamplAftGain.push_back(0.);
1730     vamplAftGain.push_back(0.);
1731     amplwgtvAftGain[0] = ps.getUntrackedParameter<std::vector<double> >("amplWeightsAftGain", vamplAftGain);
1732   } else if (getWeightsFromFile_) {
1733     //Read from file
1734     edm::LogInfo("EcalTrivialConditionRetriever") << "Reading amplitude weights aftre gain switch from file "
1735                                                   << edm::FileInPath(amplWeightsAftFile_).fullPath().c_str();
1736     std::ifstream amplFile(edm::FileInPath(amplWeightsAftFile_).fullPath().c_str());
1737     int tdcBin = 0;
1738     while (!amplFile.eof() && tdcBin < nTDCbins_) {
1739       for (int j = 0; j < 10; ++j) {
1740         float ww;
1741         amplFile >> ww;
1742         amplwgtvAftGain[tdcBin].push_back(ww);
1743       }
1744       ++tdcBin;
1745     }
1746     assert(tdcBin == nTDCbins_);
1747   } else {
1748     //Not supported
1749     edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1750     throw cms::Exception("WrongConfig");
1751   }
1752 
1753   for (int i = 0; i < nTDCbins_; i++) {
1754     assert(amplwgtvAftGain[i].size() == 10);
1755     int j = 0;
1756     for (std::vector<double>::const_iterator it = amplwgtvAftGain[i].begin(); it != amplwgtvAftGain[i].end(); ++it) {
1757       (amplWeightsAft_[i])[j] = *it;
1758       j++;
1759     }
1760   }
1761 
1762   // default weights to reco amplitude w/o pedestal subtraction
1763 
1764   std::vector<std::vector<double> > pedwgtv(nTDCbins_);
1765 
1766   if (!getWeightsFromFile_ && nTDCbins_ == 1) {
1767     std::vector<double> vped;
1768     vped.push_back(0.33333);
1769     vped.push_back(0.33333);
1770     vped.push_back(0.33333);
1771     vped.push_back(0.);
1772     vped.push_back(0.);
1773     vped.push_back(0.);
1774     vped.push_back(0.);
1775     vped.push_back(0.);
1776     vped.push_back(0.);
1777     vped.push_back(0.);
1778     pedwgtv[0] = ps.getUntrackedParameter<std::vector<double> >("pedWeights", vped);
1779   } else if (getWeightsFromFile_) {
1780     //Read from file
1781     edm::LogInfo("EcalTrivialConditionRetriever")
1782         << "Reading pedestal weights from file " << edm::FileInPath(pedWeightsFile_).fullPath().c_str();
1783     std::ifstream pedFile(edm::FileInPath(pedWeightsFile_).fullPath().c_str());
1784     int tdcBin = 0;
1785     while (!pedFile.eof() && tdcBin < nTDCbins_) {
1786       for (int j = 0; j < 10; ++j) {
1787         float ww;
1788         pedFile >> ww;
1789         pedwgtv[tdcBin].push_back(ww);
1790       }
1791       ++tdcBin;
1792     }
1793     assert(tdcBin == nTDCbins_);
1794   } else {
1795     //Not supported
1796     edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1797     throw cms::Exception("WrongConfig");
1798   }
1799 
1800   for (int i = 0; i < nTDCbins_; i++) {
1801     assert(pedwgtv[i].size() == 10);
1802     int j = 0;
1803     for (std::vector<double>::const_iterator it = pedwgtv[i].begin(); it != pedwgtv[i].end(); ++it) {
1804       (pedWeights_[i])[j] = *it;
1805       j++;
1806     }
1807   }
1808 
1809   std::vector<std::vector<double> > pedwgtvaft(nTDCbins_);
1810 
1811   if (!getWeightsFromFile_ && nTDCbins_ == 1) {
1812     std::vector<double> vped;
1813     vped.push_back(0.);
1814     vped.push_back(0.);
1815     vped.push_back(0.);
1816     vped.push_back(0.);
1817     vped.push_back(0.);
1818     vped.push_back(0.);
1819     vped.push_back(0.);
1820     vped.push_back(0.);
1821     vped.push_back(0.);
1822     vped.push_back(0.);
1823     pedwgtvaft[0] = ps.getUntrackedParameter<std::vector<double> >("pedWeightsAft", vped);
1824   } else if (getWeightsFromFile_) {
1825     //Read from file
1826     edm::LogInfo("EcalTrivialConditionRetriever") << "Reading pedestal after gain switch weights from file "
1827                                                   << edm::FileInPath(pedWeightsAftFile_).fullPath().c_str();
1828     std::ifstream pedFile(edm::FileInPath(pedWeightsAftFile_).fullPath().c_str());
1829     int tdcBin = 0;
1830     while (!pedFile.eof() && tdcBin < nTDCbins_) {
1831       for (int j = 0; j < 10; ++j) {
1832         float ww;
1833         pedFile >> ww;
1834         pedwgtvaft[tdcBin].push_back(ww);
1835       }
1836       ++tdcBin;
1837     }
1838     assert(tdcBin == nTDCbins_);
1839   } else {
1840     //Not supported
1841     edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1842     throw cms::Exception("WrongConfig");
1843   }
1844 
1845   for (int i = 0; i < nTDCbins_; i++) {
1846     assert(pedwgtvaft[i].size() == 10);
1847     int j = 0;
1848     for (std::vector<double>::const_iterator it = pedwgtvaft[i].begin(); it != pedwgtvaft[i].end(); ++it) {
1849       (pedWeightsAft_[i])[j] = *it;
1850       j++;
1851     }
1852   }
1853 
1854   // default weights to reco jitter
1855 
1856   std::vector<std::vector<double> > jittwgtv(nTDCbins_);
1857 
1858   if (!getWeightsFromFile_ && nTDCbins_ == 1) {
1859     std::vector<double> vjitt;
1860     vjitt.push_back(0.04066309);
1861     vjitt.push_back(0.04066309);
1862     vjitt.push_back(0.04066309);
1863     vjitt.push_back(0.000);
1864     vjitt.push_back(1.325176);
1865     vjitt.push_back(-0.04997078);
1866     vjitt.push_back(-0.504338);
1867     vjitt.push_back(-0.5024844);
1868     vjitt.push_back(-0.3903718);
1869     vjitt.push_back(0.000);
1870     jittwgtv[0] = ps.getUntrackedParameter<std::vector<double> >("jittWeights", vjitt);
1871   } else if (getWeightsFromFile_) {
1872     //Read from file
1873     edm::LogInfo("EcalTrivialConditionRetriever")
1874         << "Reading jitter weights from file " << edm::FileInPath(jittWeightsFile_).fullPath().c_str();
1875     std::ifstream jittFile(edm::FileInPath(jittWeightsFile_).fullPath().c_str());
1876     int tdcBin = 0;
1877     while (!jittFile.eof() && tdcBin < nTDCbins_) {
1878       for (int j = 0; j < 10; ++j) {
1879         float ww;
1880         jittFile >> ww;
1881         jittwgtv[tdcBin].push_back(ww);
1882       }
1883       ++tdcBin;
1884     }
1885     assert(tdcBin == nTDCbins_);
1886   } else {
1887     //Not supported
1888     edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1889     throw cms::Exception("WrongConfig");
1890   }
1891 
1892   for (int i = 0; i < nTDCbins_; i++) {
1893     assert(jittwgtv[i].size() == 10);
1894     int j = 0;
1895     for (std::vector<double>::const_iterator it = jittwgtv[i].begin(); it != jittwgtv[i].end(); ++it) {
1896       (jittWeights_[i])[j] = *it;
1897       j++;
1898     }
1899   }
1900 
1901   std::vector<std::vector<double> > jittwgtvaft(nTDCbins_);
1902 
1903   if (!getWeightsFromFile_ && nTDCbins_ == 1) {
1904     std::vector<double> vjitt;
1905     vjitt.push_back(0.);
1906     vjitt.push_back(0.);
1907     vjitt.push_back(0.);
1908     vjitt.push_back(0.);
1909     vjitt.push_back(1.097871);
1910     vjitt.push_back(-0.04551035);
1911     vjitt.push_back(-0.4159156);
1912     vjitt.push_back(-0.4185352);
1913     vjitt.push_back(-0.3367127);
1914     vjitt.push_back(0.);
1915     jittwgtvaft[0] = ps.getUntrackedParameter<std::vector<double> >("jittWeightsAft", vjitt);
1916   } else if (getWeightsFromFile_) {
1917     //Read from file
1918     edm::LogInfo("EcalTrivialConditionRetriever") << "Reading jitter after gain switch weights from file "
1919                                                   << edm::FileInPath(jittWeightsAftFile_).fullPath().c_str();
1920     std::ifstream jittFile(edm::FileInPath(jittWeightsAftFile_).fullPath().c_str());
1921     int tdcBin = 0;
1922     while (!jittFile.eof() && tdcBin < nTDCbins_) {
1923       for (int j = 0; j < 10; ++j) {
1924         float ww;
1925         jittFile >> ww;
1926         jittwgtvaft[tdcBin].push_back(ww);
1927       }
1928       ++tdcBin;
1929     }
1930     assert(tdcBin == nTDCbins_);
1931   } else {
1932     //Not supported
1933     edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1934     throw cms::Exception("WrongConfig");
1935   }
1936 
1937   for (int i = 0; i < nTDCbins_; i++) {
1938     assert(jittwgtvaft[i].size() == 10);
1939     int j = 0;
1940     for (std::vector<double>::const_iterator it = jittwgtvaft[i].begin(); it != jittwgtvaft[i].end(); ++it) {
1941       (jittWeightsAft_[i])[j] = *it;
1942       j++;
1943     }
1944   }
1945 
1946   std::vector<EcalWeightSet::EcalChi2WeightMatrix> chi2Matrix(nTDCbins_);
1947   if (!getWeightsFromFile_ && nTDCbins_ == 1) {
1948     //        chi2Matrix[0].resize(10);
1949     //        for (int i=0;i<10;i++)
1950     //   chi2Matrix[0][i].resize(10);
1951 
1952     chi2Matrix[0](0, 0) = 0.694371;
1953     chi2Matrix[0](0, 1) = -0.305629;
1954     chi2Matrix[0](0, 2) = -0.305629;
1955     chi2Matrix[0](0, 3) = 0.;
1956     chi2Matrix[0](0, 4) = 0.;
1957     chi2Matrix[0](0, 5) = 0.;
1958     chi2Matrix[0](0, 6) = 0.;
1959     chi2Matrix[0](0, 7) = 0.;
1960     chi2Matrix[0](0, 8) = 0.;
1961     chi2Matrix[0](0, 9) = 0.;
1962     chi2Matrix[0](1, 0) = -0.305629;
1963     chi2Matrix[0](1, 1) = 0.694371;
1964     chi2Matrix[0](1, 2) = -0.305629;
1965     chi2Matrix[0](1, 3) = 0.;
1966     chi2Matrix[0](1, 4) = 0.;
1967     chi2Matrix[0](1, 5) = 0.;
1968     chi2Matrix[0](1, 6) = 0.;
1969     chi2Matrix[0](1, 7) = 0.;
1970     chi2Matrix[0](1, 8) = 0.;
1971     chi2Matrix[0](1, 9) = 0.;
1972     chi2Matrix[0](2, 0) = -0.305629;
1973     chi2Matrix[0](2, 1) = -0.305629;
1974     chi2Matrix[0](2, 2) = 0.694371;
1975     chi2Matrix[0](2, 3) = 0.;
1976     chi2Matrix[0](2, 4) = 0.;
1977     chi2Matrix[0](2, 5) = 0.;
1978     chi2Matrix[0](2, 6) = 0.;
1979     chi2Matrix[0](2, 7) = 0.;
1980     chi2Matrix[0](2, 8) = 0.;
1981     chi2Matrix[0](2, 9) = 0.;
1982     chi2Matrix[0](3, 0) = 0.;
1983     chi2Matrix[0](3, 1) = 0.;
1984     chi2Matrix[0](3, 2) = 0.;
1985     chi2Matrix[0](3, 3) = 0.;
1986     chi2Matrix[0](3, 4) = 0.;
1987     chi2Matrix[0](3, 5) = 0.;
1988     chi2Matrix[0](3, 6) = 0.;
1989     chi2Matrix[0](3, 7) = 0.;
1990     chi2Matrix[0](3, 8) = 0.;
1991     chi2Matrix[0](3, 9) = 0.;
1992     chi2Matrix[0](4, 0) = 0.;
1993     chi2Matrix[0](4, 1) = 0.;
1994     chi2Matrix[0](4, 2) = 0.;
1995     chi2Matrix[0](4, 3) = 0.;
1996     chi2Matrix[0](4, 4) = 0.8027116;
1997     chi2Matrix[0](4, 5) = -0.2517103;
1998     chi2Matrix[0](4, 6) = -0.2232882;
1999     chi2Matrix[0](4, 7) = -0.1716192;
2000     chi2Matrix[0](4, 8) = -0.1239006;
2001     chi2Matrix[0](4, 9) = 0.;
2002     chi2Matrix[0](5, 0) = 0.;
2003     chi2Matrix[0](5, 1) = 0.;
2004     chi2Matrix[0](5, 2) = 0.;
2005     chi2Matrix[0](5, 3) = 0.;
2006     chi2Matrix[0](5, 4) = -0.2517103;
2007     chi2Matrix[0](5, 5) = 0.6528964;
2008     chi2Matrix[0](5, 6) = -0.2972839;
2009     chi2Matrix[0](5, 7) = -0.2067162;
2010     chi2Matrix[0](5, 8) = -0.1230729;
2011     chi2Matrix[0](5, 9) = 0.;
2012     chi2Matrix[0](6, 0) = 0.;
2013     chi2Matrix[0](6, 1) = 0.;
2014     chi2Matrix[0](6, 2) = 0.;
2015     chi2Matrix[0](6, 3) = 0.;
2016     chi2Matrix[0](6, 4) = -0.2232882;
2017     chi2Matrix[0](6, 5) = -0.2972839;
2018     chi2Matrix[0](6, 6) = 0.7413607;
2019     chi2Matrix[0](6, 7) = -0.1883866;
2020     chi2Matrix[0](6, 8) = -0.1235052;
2021     chi2Matrix[0](6, 9) = 0.;
2022     chi2Matrix[0](7, 0) = 0.;
2023     chi2Matrix[0](7, 1) = 0.;
2024     chi2Matrix[0](7, 2) = 0.;
2025     chi2Matrix[0](7, 3) = 0.;
2026     chi2Matrix[0](7, 4) = -0.1716192;
2027     chi2Matrix[0](7, 5) = -0.2067162;
2028     chi2Matrix[0](7, 6) = -0.1883866;
2029     chi2Matrix[0](7, 7) = 0.844935;
2030     chi2Matrix[0](7, 8) = -0.124291;
2031     chi2Matrix[0](7, 9) = 0.;
2032     chi2Matrix[0](8, 0) = 0.;
2033     chi2Matrix[0](8, 1) = 0.;
2034     chi2Matrix[0](8, 2) = 0.;
2035     chi2Matrix[0](8, 3) = 0.;
2036     chi2Matrix[0](8, 4) = -0.1239006;
2037     chi2Matrix[0](8, 5) = -0.1230729;
2038     chi2Matrix[0](8, 6) = -0.1235052;
2039     chi2Matrix[0](8, 7) = -0.124291;
2040     chi2Matrix[0](8, 8) = 0.8749833;
2041     chi2Matrix[0](8, 9) = 0.;
2042     chi2Matrix[0](9, 0) = 0.;
2043     chi2Matrix[0](9, 1) = 0.;
2044     chi2Matrix[0](9, 2) = 0.;
2045     chi2Matrix[0](9, 3) = 0.;
2046     chi2Matrix[0](9, 4) = 0.;
2047     chi2Matrix[0](9, 5) = 0.;
2048     chi2Matrix[0](9, 6) = 0.;
2049     chi2Matrix[0](9, 7) = 0.;
2050     chi2Matrix[0](9, 8) = 0.;
2051     chi2Matrix[0](9, 9) = 0.;
2052   } else if (getWeightsFromFile_) {
2053     //Read from file
2054     edm::LogInfo("EcalTrivialConditionRetriever")
2055         << "Reading chi2Matrix from file " << edm::FileInPath(chi2MatrixFile_).fullPath().c_str();
2056     std::ifstream chi2MatrixFile(edm::FileInPath(chi2MatrixFile_).fullPath().c_str());
2057     int tdcBin = 0;
2058     while (!chi2MatrixFile.eof() && tdcBin < nTDCbins_) {
2059       //      chi2Matrix[tdcBin].resize(10);
2060       for (int j = 0; j < 10; ++j) {
2061         for (int l = 0; l < 10; ++l) {
2062           float ww;
2063           chi2MatrixFile >> ww;
2064           chi2Matrix[tdcBin](j, l) = ww;
2065         }
2066       }
2067       ++tdcBin;
2068     }
2069     assert(tdcBin == nTDCbins_);
2070   } else {
2071     //Not supported
2072     edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
2073     throw cms::Exception("WrongConfig");
2074   }
2075 
2076   //    for (int i=0;i<nTDCbins_;i++)
2077   //      {
2078   //       assert(chi2Matrix[i].size() == 10);
2079   chi2Matrix_ = chi2Matrix;
2080   //      }
2081 
2082   std::vector<EcalWeightSet::EcalChi2WeightMatrix> chi2MatrixAft(nTDCbins_);
2083   if (!getWeightsFromFile_ && nTDCbins_ == 1) {
2084     //       chi2MatrixAft[0].resize(10);
2085     //       for (int i=0;i<10;i++)
2086     //   chi2MatrixAft[0][i].resize(10);
2087 
2088     chi2MatrixAft[0](0, 0) = 0.;
2089     chi2MatrixAft[0](0, 1) = 0.;
2090     chi2MatrixAft[0](0, 2) = 0.;
2091     chi2MatrixAft[0](0, 3) = 0.;
2092     chi2MatrixAft[0](0, 4) = 0.;
2093     chi2MatrixAft[0](0, 5) = 0.;
2094     chi2MatrixAft[0](0, 6) = 0.;
2095     chi2MatrixAft[0](0, 7) = 0.;
2096     chi2MatrixAft[0](0, 8) = 0.;
2097     chi2MatrixAft[0](0, 9) = 0.;
2098     chi2MatrixAft[0](1, 0) = 0.;
2099     chi2MatrixAft[0](1, 1) = 0.;
2100     chi2MatrixAft[0](1, 2) = 0.;
2101     chi2MatrixAft[0](1, 3) = 0.;
2102     chi2MatrixAft[0](1, 4) = 0.;
2103     chi2MatrixAft[0](1, 5) = 0.;
2104     chi2MatrixAft[0](1, 6) = 0.;
2105     chi2MatrixAft[0](1, 7) = 0.;
2106     chi2MatrixAft[0](1, 8) = 0.;
2107     chi2MatrixAft[0](1, 9) = 0.;
2108     chi2MatrixAft[0](2, 0) = 0.;
2109     chi2MatrixAft[0](2, 1) = 0.;
2110     chi2MatrixAft[0](2, 2) = 0.;
2111     chi2MatrixAft[0](2, 3) = 0.;
2112     chi2MatrixAft[0](2, 4) = 0.;
2113     chi2MatrixAft[0](2, 5) = 0.;
2114     chi2MatrixAft[0](2, 6) = 0.;
2115     chi2MatrixAft[0](2, 7) = 0.;
2116     chi2MatrixAft[0](2, 8) = 0.;
2117     chi2MatrixAft[0](2, 9) = 0.;
2118     chi2MatrixAft[0](3, 0) = 0.;
2119     chi2MatrixAft[0](3, 1) = 0.;
2120     chi2MatrixAft[0](3, 2) = 0.;
2121     chi2MatrixAft[0](3, 3) = 0.;
2122     chi2MatrixAft[0](3, 4) = 0.;
2123     chi2MatrixAft[0](3, 5) = 0.;
2124     chi2MatrixAft[0](3, 6) = 0.;
2125     chi2MatrixAft[0](3, 7) = 0.;
2126     chi2MatrixAft[0](3, 8) = 0.;
2127     chi2MatrixAft[0](3, 9) = 0.;
2128     chi2MatrixAft[0](4, 0) = 0.;
2129     chi2MatrixAft[0](4, 1) = 0.;
2130     chi2MatrixAft[0](4, 2) = 0.;
2131     chi2MatrixAft[0](4, 3) = 0.;
2132     chi2MatrixAft[0](4, 4) = 0.8030884;
2133     chi2MatrixAft[0](4, 5) = -0.2543541;
2134     chi2MatrixAft[0](4, 6) = -0.2243544;
2135     chi2MatrixAft[0](4, 7) = -0.1698177;
2136     chi2MatrixAft[0](4, 8) = -0.1194506;
2137     chi2MatrixAft[0](4, 9) = 0.;
2138     chi2MatrixAft[0](5, 0) = 0.;
2139     chi2MatrixAft[0](5, 1) = 0.;
2140     chi2MatrixAft[0](5, 2) = 0.;
2141     chi2MatrixAft[0](5, 3) = 0.;
2142     chi2MatrixAft[0](5, 4) = -0.2543541;
2143     chi2MatrixAft[0](5, 5) = 0.6714465;
2144     chi2MatrixAft[0](5, 6) = -0.2898025;
2145     chi2MatrixAft[0](5, 7) = -0.2193564;
2146     chi2MatrixAft[0](5, 8) = -0.1542964;
2147     chi2MatrixAft[0](5, 9) = 0.;
2148     chi2MatrixAft[0](6, 0) = 0.;
2149     chi2MatrixAft[0](6, 1) = 0.;
2150     chi2MatrixAft[0](6, 2) = 0.;
2151     chi2MatrixAft[0](6, 3) = 0.;
2152     chi2MatrixAft[0](6, 4) = -0.2243544;
2153     chi2MatrixAft[0](6, 5) = -0.2898025;
2154     chi2MatrixAft[0](6, 6) = 0.7443781;
2155     chi2MatrixAft[0](6, 7) = -0.1934846;
2156     chi2MatrixAft[0](6, 8) = -0.136098;
2157     chi2MatrixAft[0](6, 9) = 0.;
2158     chi2MatrixAft[0](7, 0) = 0.;
2159     chi2MatrixAft[0](7, 1) = 0.;
2160     chi2MatrixAft[0](7, 2) = 0.;
2161     chi2MatrixAft[0](7, 3) = 0.;
2162     chi2MatrixAft[0](7, 4) = -0.1698177;
2163     chi2MatrixAft[0](7, 5) = -0.2193564;
2164     chi2MatrixAft[0](7, 6) = -0.1934846;
2165     chi2MatrixAft[0](7, 7) = 0.8535482;
2166     chi2MatrixAft[0](7, 8) = -0.1030149;
2167     chi2MatrixAft[0](7, 9) = 0.;
2168     chi2MatrixAft[0](8, 0) = 0.;
2169     chi2MatrixAft[0](8, 1) = 0.;
2170     chi2MatrixAft[0](8, 2) = 0.;
2171     chi2MatrixAft[0](8, 3) = 0.;
2172     chi2MatrixAft[0](8, 4) = -0.1194506;
2173     chi2MatrixAft[0](8, 5) = -0.1542964;
2174     chi2MatrixAft[0](8, 6) = -0.136098;
2175     chi2MatrixAft[0](8, 7) = -0.1030149;
2176     chi2MatrixAft[0](8, 8) = 0.9275388;
2177     chi2MatrixAft[0](8, 9) = 0.;
2178     chi2MatrixAft[0](9, 0) = 0.;
2179     chi2MatrixAft[0](9, 1) = 0.;
2180     chi2MatrixAft[0](9, 2) = 0.;
2181     chi2MatrixAft[0](9, 3) = 0.;
2182     chi2MatrixAft[0](9, 4) = 0.;
2183     chi2MatrixAft[0](9, 5) = 0.;
2184     chi2MatrixAft[0](9, 6) = 0.;
2185     chi2MatrixAft[0](9, 7) = 0.;
2186     chi2MatrixAft[0](9, 8) = 0.;
2187     chi2MatrixAft[0](9, 9) = 0.;
2188   } else if (getWeightsFromFile_) {
2189     //Read from file
2190     edm::LogInfo("EcalTrivialConditionRetriever")
2191         << "Reading chi2MatrixAft from file " << edm::FileInPath(chi2MatrixAftFile_).fullPath().c_str();
2192     std::ifstream chi2MatrixAftFile(edm::FileInPath(chi2MatrixAftFile_).fullPath().c_str());
2193     int tdcBin = 0;
2194     while (!chi2MatrixAftFile.eof() && tdcBin < nTDCbins_) {
2195       //      chi2MatrixAft[tdcBin].resize(10);
2196       for (int j = 0; j < 10; ++j) {
2197         for (int l = 0; l < 10; ++l) {
2198           float ww;
2199           chi2MatrixAftFile >> ww;
2200           chi2MatrixAft[tdcBin](j, l) = ww;
2201         }
2202       }
2203       ++tdcBin;
2204     }
2205     assert(tdcBin == nTDCbins_);
2206   } else {
2207     //Not supported
2208     edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
2209     throw cms::Exception("WrongConfig");
2210   }
2211 
2212   //    for (int i=0;i<nTDCbins_;i++)
2213   //      {
2214   //       assert(chi2MatrixAft[i].size() == 10);
2215   chi2MatrixAft_ = chi2MatrixAft;
2216   //      }
2217 }
2218 
2219 // --------------------------------------------------------------------------------
2220 
2221 std::unique_ptr<EcalChannelStatus> EcalTrivialConditionRetriever::getChannelStatusFromConfiguration(
2222     const EcalChannelStatusRcd&) {
2223   auto ecalStatus = std::make_unique<EcalChannelStatus>();
2224 
2225   // start by setting all statuses to 0
2226 
2227   // barrel
2228   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
2229     if (ieta == 0)
2230       continue;
2231     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
2232       if (EBDetId::validDetId(ieta, iphi)) {
2233         EBDetId ebid(ieta, iphi);
2234         ecalStatus->setValue(ebid, 0);
2235       }
2236     }
2237   }
2238   // endcap
2239   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
2240     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
2241       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
2242       if (EEDetId::validDetId(iX, iY, 1)) {
2243         EEDetId eedetidpos(iX, iY, 1);
2244         ecalStatus->setValue(eedetidpos, 0);
2245       }
2246       if (EEDetId::validDetId(iX, iY, -1)) {
2247         EEDetId eedetidneg(iX, iY, -1);
2248         ecalStatus->setValue(eedetidneg, 0);
2249       }
2250     }
2251   }
2252 
2253   // overwrite the statuses which are in the file
2254 
2255   edm::LogInfo("EcalTrivialConditionRetriever")
2256       << "Reading channel statuses from file " << edm::FileInPath(channelStatusFile_).fullPath().c_str();
2257   std::ifstream statusFile(edm::FileInPath(channelStatusFile_).fullPath().c_str());
2258   if (!statusFile.good()) {
2259     edm::LogError("EcalTrivialConditionRetriever") << "*** Problems opening file: " << channelStatusFile_;
2260     throw cms::Exception("Cannot open ECAL channel status file");
2261   }
2262 
2263   std::string EcalSubDet;
2264   std::string str;
2265   int hashIndex(0);
2266   int status(0);
2267 
2268   while (!statusFile.eof()) {
2269     statusFile >> EcalSubDet;
2270     if (EcalSubDet != std::string("EB") && EcalSubDet != std::string("EE")) {
2271       std::getline(statusFile, str);
2272       continue;
2273     } else {
2274       statusFile >> hashIndex >> status;
2275     }
2276     // std::cout << EcalSubDet << " " << hashIndex << " " << status;
2277 
2278     if (EcalSubDet == std::string("EB")) {
2279       EBDetId ebid = EBDetId::unhashIndex(hashIndex);
2280       ecalStatus->setValue(ebid, status);
2281     } else if (EcalSubDet == std::string("EE")) {
2282       EEDetId eedetid = EEDetId::unhashIndex(hashIndex);
2283       ecalStatus->setValue(eedetid, status);
2284     } else {
2285       edm::LogError("EcalTrivialConditionRetriever") << " *** " << EcalSubDet << " is neither EB nor EE ";
2286     }
2287   }
2288   // the file is supposed to be in the form  -- FIXME
2289 
2290   statusFile.close();
2291   return ecalStatus;
2292 }
2293 
2294 std::unique_ptr<EcalChannelStatus> EcalTrivialConditionRetriever::produceEcalChannelStatus(const EcalChannelStatusRcd&) {
2295   auto ical = std::make_unique<EcalChannelStatus>();
2296   // barrel
2297   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
2298     if (ieta == 0)
2299       continue;
2300     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
2301       if (EBDetId::validDetId(ieta, iphi)) {
2302         EBDetId ebid(ieta, iphi);
2303         ical->setValue(ebid, 0);
2304       }
2305     }
2306   }
2307   // endcap
2308   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
2309     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
2310       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
2311       if (EEDetId::validDetId(iX, iY, 1)) {
2312         EEDetId eedetidpos(iX, iY, 1);
2313         ical->setValue(eedetidpos, 0);
2314       }
2315       if (EEDetId::validDetId(iX, iY, -1)) {
2316         EEDetId eedetidneg(iX, iY, -1);
2317         ical->setValue(eedetidneg, 0);
2318       }
2319     }
2320   }
2321   return ical;
2322 }
2323 
2324 // --------------------------------------------------------------------------------
2325 std::unique_ptr<EcalDQMChannelStatus> EcalTrivialConditionRetriever::produceEcalDQMChannelStatus(
2326     const EcalDQMChannelStatusRcd&) {
2327   uint32_t sta(0);
2328 
2329   auto ical = std::make_unique<EcalDQMChannelStatus>();
2330   // barrel
2331   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
2332     if (ieta == 0)
2333       continue;
2334     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
2335       if (EBDetId::validDetId(ieta, iphi)) {
2336         EBDetId ebid(ieta, iphi);
2337         ical->setValue(ebid, sta);
2338       }
2339     }
2340   }
2341   // endcap
2342   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
2343     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
2344       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
2345       if (EEDetId::validDetId(iX, iY, 1)) {
2346         EEDetId eedetidpos(iX, iY, 1);
2347         ical->setValue(eedetidpos, sta);
2348       }
2349       if (EEDetId::validDetId(iX, iY, -1)) {
2350         EEDetId eedetidneg(iX, iY, -1);
2351         ical->setValue(eedetidneg, sta);
2352       }
2353     }
2354   }
2355   return ical;
2356 }
2357 // --------------------------------------------------------------------------------
2358 
2359 std::unique_ptr<EcalDQMTowerStatus> EcalTrivialConditionRetriever::produceEcalDQMTowerStatus(
2360     const EcalDQMTowerStatusRcd&) {
2361   auto ical = std::make_unique<EcalDQMTowerStatus>();
2362 
2363   uint32_t sta(0);
2364 
2365   // barrel
2366   int iz = 0;
2367   for (int k = 0; k < 2; k++) {
2368     if (k == 0)
2369       iz = -1;
2370     if (k == 1)
2371       iz = +1;
2372     for (int i = 1; i < 73; i++) {
2373       for (int j = 1; j < 18; j++) {
2374         if (EcalTrigTowerDetId::validDetId(iz, EcalBarrel, j, i)) {
2375           EcalTrigTowerDetId ebid(iz, EcalBarrel, j, i);
2376 
2377           ical->setValue(ebid, sta);
2378         }
2379       }
2380     }
2381   }
2382 
2383   // endcap
2384   for (int k = 0; k < 2; k++) {
2385     if (k == 0)
2386       iz = -1;
2387     if (k == 1)
2388       iz = +1;
2389     for (int i = 1; i < 21; i++) {
2390       for (int j = 1; j < 21; j++) {
2391         if (EcalScDetId::validDetId(i, j, iz)) {
2392           EcalScDetId eeid(i, j, iz);
2393           ical->setValue(eeid, sta);
2394         }
2395       }
2396     }
2397   }
2398 
2399   return ical;
2400 }
2401 
2402 // --------------------------------------------------------------------------------
2403 std::unique_ptr<EcalDCSTowerStatus> EcalTrivialConditionRetriever::produceEcalDCSTowerStatus(
2404     const EcalDCSTowerStatusRcd&) {
2405   auto ical = std::make_unique<EcalDCSTowerStatus>();
2406 
2407   int status(0);
2408 
2409   // barrel
2410   int iz = 0;
2411   for (int k = 0; k < 2; k++) {
2412     if (k == 0)
2413       iz = -1;
2414     if (k == 1)
2415       iz = +1;
2416     for (int i = 1; i < 73; i++) {
2417       for (int j = 1; j < 18; j++) {
2418         if (EcalTrigTowerDetId::validDetId(iz, EcalBarrel, j, i)) {
2419           EcalTrigTowerDetId ebid(iz, EcalBarrel, j, i);
2420 
2421           ical->setValue(ebid, status);
2422         }
2423       }
2424     }
2425   }
2426 
2427   // endcap
2428   for (int k = 0; k < 2; k++) {
2429     if (k == 0)
2430       iz = -1;
2431     if (k == 1)
2432       iz = +1;
2433     for (int i = 1; i < 21; i++) {
2434       for (int j = 1; j < 21; j++) {
2435         if (EcalScDetId::validDetId(i, j, iz)) {
2436           EcalScDetId eeid(i, j, iz);
2437           ical->setValue(eeid, status);
2438         }
2439       }
2440     }
2441   }
2442 
2443   return ical;
2444 }
2445 // --------------------------------------------------------------------------------
2446 
2447 std::unique_ptr<EcalDAQTowerStatus> EcalTrivialConditionRetriever::produceEcalDAQTowerStatus(
2448     const EcalDAQTowerStatusRcd&) {
2449   auto ical = std::make_unique<EcalDAQTowerStatus>();
2450 
2451   int status(0);
2452 
2453   // barrel
2454   int iz = 0;
2455   for (int k = 0; k < 2; k++) {
2456     if (k == 0)
2457       iz = -1;
2458     if (k == 1)
2459       iz = +1;
2460     for (int i = 1; i < 73; i++) {
2461       for (int j = 1; j < 18; j++) {
2462         if (EcalTrigTowerDetId::validDetId(iz, EcalBarrel, j, i)) {
2463           EcalTrigTowerDetId ebid(iz, EcalBarrel, j, i);
2464 
2465           ical->setValue(ebid, status);
2466         }
2467       }
2468     }
2469   }
2470 
2471   // endcap
2472   for (int k = 0; k < 2; k++) {
2473     if (k == 0)
2474       iz = -1;
2475     if (k == 1)
2476       iz = +1;
2477     for (int i = 1; i < 21; i++) {
2478       for (int j = 1; j < 21; j++) {
2479         if (EcalScDetId::validDetId(i, j, iz)) {
2480           EcalScDetId eeid(i, j, iz);
2481           ical->setValue(eeid, status);
2482         }
2483       }
2484     }
2485   }
2486 
2487   return ical;
2488 }
2489 // --------------------------------------------------------------------------------
2490 
2491 std::unique_ptr<EcalTPGCrystalStatus> EcalTrivialConditionRetriever::getTrgChannelStatusFromConfiguration(
2492     const EcalTPGCrystalStatusRcd&) {
2493   auto ecalStatus = std::make_unique<EcalTPGCrystalStatus>();
2494 
2495   // start by setting all statuses to 0
2496 
2497   // barrel
2498   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
2499     if (ieta == 0)
2500       continue;
2501     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
2502       if (EBDetId::validDetId(ieta, iphi)) {
2503         EBDetId ebid(ieta, iphi);
2504         ecalStatus->setValue(ebid, 0);
2505       }
2506     }
2507   }
2508   // endcap
2509   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
2510     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
2511       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
2512       if (EEDetId::validDetId(iX, iY, 1)) {
2513         EEDetId eedetidpos(iX, iY, 1);
2514         ecalStatus->setValue(eedetidpos, 0);
2515       }
2516       if (EEDetId::validDetId(iX, iY, -1)) {
2517         EEDetId eedetidneg(iX, iY, -1);
2518         ecalStatus->setValue(eedetidneg, 0);
2519       }
2520     }
2521   }
2522 
2523   // overwrite the statuses which are in the file
2524 
2525   edm::LogInfo("EcalTrivialConditionRetriever")
2526       << "Reading channel statuses from file " << edm::FileInPath(channelStatusFile_).fullPath().c_str();
2527   std::ifstream statusFile(edm::FileInPath(channelStatusFile_).fullPath().c_str());
2528   if (!statusFile.good()) {
2529     edm::LogError("EcalTrivialConditionRetriever") << "*** Problems opening file: " << channelStatusFile_;
2530     throw cms::Exception("Cannot open ECAL channel status file");
2531   }
2532 
2533   std::string EcalSubDet;
2534   std::string str;
2535   int hashIndex(0);
2536   int status(0);
2537 
2538   while (!statusFile.eof()) {
2539     statusFile >> EcalSubDet;
2540     if (EcalSubDet != std::string("EB") && EcalSubDet != std::string("EE")) {
2541       std::getline(statusFile, str);
2542       continue;
2543     } else {
2544       statusFile >> hashIndex >> status;
2545     }
2546     // std::cout << EcalSubDet << " " << hashIndex << " " << status;
2547 
2548     if (EcalSubDet == std::string("EB")) {
2549       EBDetId ebid = EBDetId::unhashIndex(hashIndex);
2550       ecalStatus->setValue(ebid, status);
2551     } else if (EcalSubDet == std::string("EE")) {
2552       EEDetId eedetid = EEDetId::unhashIndex(hashIndex);
2553       ecalStatus->setValue(eedetid, status);
2554     } else {
2555       edm::LogError("EcalTrivialConditionRetriever") << " *** " << EcalSubDet << " is neither EB nor EE ";
2556     }
2557   }
2558   // the file is supposed to be in the form  -- FIXME
2559 
2560   statusFile.close();
2561   return ecalStatus;
2562 }
2563 
2564 std::unique_ptr<EcalTPGCrystalStatus> EcalTrivialConditionRetriever::produceEcalTrgChannelStatus(
2565     const EcalTPGCrystalStatusRcd&) {
2566   auto ical = std::make_unique<EcalTPGCrystalStatus>();
2567   // barrel
2568   for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
2569     if (ieta == 0)
2570       continue;
2571     for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
2572       if (EBDetId::validDetId(ieta, iphi)) {
2573         EBDetId ebid(ieta, iphi);
2574         ical->setValue(ebid, 0);
2575       }
2576     }
2577   }
2578   // endcap
2579   for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
2580     for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
2581       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
2582       if (EEDetId::validDetId(iX, iY, 1)) {
2583         EEDetId eedetidpos(iX, iY, 1);
2584         ical->setValue(eedetidpos, 0);
2585       }
2586       if (EEDetId::validDetId(iX, iY, -1)) {
2587         EEDetId eedetidneg(iX, iY, -1);
2588         ical->setValue(eedetidneg, 0);
2589       }
2590     }
2591   }
2592   return ical;
2593 }
2594 
2595 std::unique_ptr<EcalIntercalibConstants> EcalTrivialConditionRetriever::getIntercalibConstantsFromConfiguration(
2596     const EcalIntercalibConstantsRcd&) {
2597   std::unique_ptr<EcalIntercalibConstants> ical;
2598   //        std::make_unique<EcalIntercalibConstants>();
2599 
2600   // Read the values from a txt file
2601   // -------------------------------
2602 
2603   edm::LogInfo("EcalTrivialConditionRetriever")
2604       << "Reading intercalibration constants from file " << intercalibConstantsFile_.c_str();
2605 
2606   if (intercalibConstantsFile_.find(".xml") != std::string::npos) {
2607     edm::LogInfo("generating Intercalib from xml file");
2608 
2609     EcalCondHeader h;
2610     EcalIntercalibConstants* rcd = new EcalIntercalibConstants;
2611     EcalIntercalibConstantsXMLTranslator::readXML(intercalibConstantsFile_, h, *rcd);
2612 
2613     if (totLumi_ != 0 || instLumi_ != 0) {
2614       edm::LogInfo("implementing ageing for intercalib");
2615 
2616       EcalIntercalibConstantsMC* rcdMC = new EcalIntercalibConstantsMC;
2617 
2618       if (intercalibConstantsMCFile_.find(".xml") != std::string::npos) {
2619         edm::LogInfo("generating IntercalibMC from xml file");
2620 
2621         EcalCondHeader h;
2622         EcalIntercalibConstantsMCXMLTranslator::readXML(intercalibConstantsMCFile_, h, *rcdMC);
2623 
2624       } else {
2625         edm::LogInfo("please provide the xml file of the EcalIntercalibConstantsMC");
2626       }
2627 
2628       TRandom3* gRandom = new TRandom3();
2629 
2630       EnergyResolutionVsLumi ageing;
2631       ageing.setLumi(totLumi_);
2632       ageing.setInstLumi(instLumi_);
2633 
2634       const EcalIntercalibConstantMap& mymap = rcd->getMap();
2635       const EcalIntercalibConstantMCMap& mymapMC = rcdMC->getMap();
2636 
2637       for (int ieta = -EBDetId::MAX_IETA; ieta <= EBDetId::MAX_IETA; ++ieta) {
2638         if (ieta == 0)
2639           continue;
2640 
2641         double eta = EBDetId::approxEta(EBDetId(ieta, 1));
2642         eta = fabs(eta);
2643         double constantTerm = ageing.calcresolutitonConstantTerm(eta);
2644         edm::LogInfo("EB at eta=") << eta << " constant term is " << constantTerm;
2645 
2646         for (int iphi = EBDetId::MIN_IPHI; iphi <= EBDetId::MAX_IPHI; ++iphi) {
2647           // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
2648           if (EBDetId::validDetId(ieta, iphi)) {
2649             EBDetId ebid(ieta, iphi);
2650             EcalIntercalibConstants::const_iterator idref = mymap.find(ebid);
2651             EcalIntercalibConstant icalconstant = 1;
2652             if (idref != mymap.end())
2653               icalconstant = (*idref);
2654 
2655             EcalIntercalibConstantsMC::const_iterator idrefMC = mymapMC.find(ebid);
2656             EcalIntercalibConstantMC icalconstantMC = 1;
2657             if (idrefMC != mymapMC.end())
2658               icalconstantMC = (*idrefMC);
2659 
2660             double r = gRandom->Gaus(0, constantTerm);
2661 
2662             if (iphi == 10)
2663               edm::LogInfo("EB at eta=") << eta << " IC=" << icalconstant << " ICMC=" << icalconstantMC
2664                                          << " smear=" << r << " ";
2665 
2666             icalconstant = icalconstant + r * 1.29 * icalconstantMC;
2667             rcd->setValue(ebid.rawId(), icalconstant);
2668 
2669             if (iphi == 10)
2670               edm::LogInfo("newIC=") << icalconstant;
2671 
2672             EcalIntercalibConstant icalconstant2 = (*idref);
2673             if (icalconstant != icalconstant2)
2674               edm::LogInfo(">>>> error in smearing intercalib");
2675           }
2676         }
2677       }
2678 
2679       for (int iX = EEDetId::IX_MIN; iX <= EEDetId::IX_MAX; ++iX) {
2680         for (int iY = EEDetId::IY_MIN; iY <= EEDetId::IY_MAX; ++iY) {
2681           // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
2682           if (EEDetId::validDetId(iX, iY, 1)) {
2683             EEDetId eedetidpos(iX, iY, 1);
2684             double eta =
2685                 -log(tan(0.5 * atan(sqrt((iX - 50.0) * (iX - 50.0) + (iY - 50.0) * (iY - 50.0)) * 2.98 / 328.)));
2686             eta = fabs(eta);
2687             double constantTerm = ageing.calcresolutitonConstantTerm(eta);
2688             if (iX == 50)
2689               edm::LogInfo("EE at eta=") << eta << " constant term is " << constantTerm;
2690 
2691             EcalIntercalibConstants::const_iterator idref = mymap.find(eedetidpos);
2692             EcalIntercalibConstant icalconstant = 1;
2693             if (idref != mymap.end())
2694               icalconstant = (*idref);
2695 
2696             EcalIntercalibConstantsMC::const_iterator idrefMC = mymapMC.find(eedetidpos);
2697             EcalIntercalibConstantMC icalconstantMC = 1;
2698             if (idrefMC != mymapMC.end())
2699               icalconstantMC = (*idrefMC);
2700 
2701             double r = gRandom->Gaus(0, constantTerm);
2702 
2703             if (iX == 10)
2704               edm::LogInfo("EE at eta=") << eta << " IC=" << icalconstant << " ICMC=" << icalconstantMC
2705                                          << " smear=" << r << " ";
2706             icalconstant = icalconstant + r * 1.29 * icalconstantMC;
2707             rcd->setValue(eedetidpos.rawId(), icalconstant);
2708             if (iX == 10)
2709               edm::LogInfo("newIC=") << icalconstant;
2710           }
2711           if (EEDetId::validDetId(iX, iY, -1)) {
2712             EEDetId eedetidneg(iX, iY, -1);
2713             double eta =
2714                 -log(tan(0.5 * atan(sqrt((iX - 50.0) * (iX - 50.0) + (iY - 50.0) * (iY - 50.0)) * 2.98 / 328.)));
2715             eta = fabs(eta);
2716             double constantTerm = ageing.calcresolutitonConstantTerm(eta);
2717             EcalIntercalibConstant icalconstant = 1;
2718 
2719             EcalIntercalibConstantsMC::const_iterator idrefMC = mymapMC.find(eedetidneg);
2720             EcalIntercalibConstantMC icalconstantMC = 1;
2721             if (idrefMC != mymapMC.end())
2722               icalconstantMC = (*idrefMC);
2723 
2724             double r = gRandom->Gaus(0, constantTerm);
2725             icalconstant = icalconstant + r * 1.29 * icalconstantMC;
2726             rcd->setValue(eedetidneg.rawId(), icalconstant);
2727           }
2728         }
2729       }
2730 
2731       ical = std::unique_ptr<EcalIntercalibConstants>(rcd);
2732 
2733       delete gRandom;
2734     }
2735 
2736   } else {
2737     ical = std::make_unique<EcalIntercalibConstants>();
2738 
2739     FILE* inpFile;
2740     inpFile = fopen(intercalibConstantsFile_.c_str(), "r");
2741     if (!inpFile) {
2742       edm::LogError("EcalTrivialConditionRetriever") << "*** Can not open file: " << intercalibConstantsFile_;
2743       throw cms::Exception("Cannot open inter-calibration coefficients txt file");
2744     }
2745 
2746     char line[256];
2747     std::ostringstream str;
2748     fgets(line, 255, inpFile);
2749     int sm_number = atoi(line);
2750     str << "sm: " << sm_number;
2751 
2752     fgets(line, 255, inpFile);
2753     //int nevents=atoi (line) ; // not necessary here just for online conddb
2754 
2755     fgets(line, 255, inpFile);
2756     std::string gen_tag = line;
2757     str << "gen tag: " << gen_tag;  // should I use this?
2758 
2759     fgets(line, 255, inpFile);
2760     std::string cali_method = line;
2761     str << "cali method: " << cali_method << std::endl;  // not important
2762 
2763     fgets(line, 255, inpFile);
2764     std::string cali_version = line;
2765     str << "cali version: " << cali_version << std::endl;  // not important
2766 
2767     fgets(line, 255, inpFile);
2768     std::string cali_type = line;
2769     str << "cali type: " << cali_type;  // not important
2770 
2771     edm::LogInfo("EcalTrivialConditionRetriever") << "[PIETRO] Intercalibration file - " << str.str();
2772 
2773     float calib[1700] = {1};
2774     int calib_status[1700] = {0};
2775 
2776     int ii = 0;
2777 
2778     while (fgets(line, 255, inpFile)) {
2779       ii++;
2780       int dmy_num = 0;
2781       float dmy_calib = 0.;
2782       float dmy_RMS = 0.;
2783       int dmy_events = 0;
2784       int dmy_status = 0;
2785       sscanf(line, "%d %f %f %d %d", &dmy_num, &dmy_calib, &dmy_RMS, &dmy_events, &dmy_status);
2786       assert(dmy_num >= 1);
2787       assert(dmy_num <= 1700);
2788       calib[dmy_num - 1] = dmy_calib;
2789       calib_status[dmy_num - 1] = dmy_status;
2790 
2791       //       edm::LogInfo ("EcalTrivialConditionRetriever")
2792       //                 << "[PIETRO] cry = " << dmy_num
2793       //                 << " calib = " << calib[dmy_num-1]
2794       //                 << " RMS = " << dmy_RMS
2795       //                 << " events = " << dmy_events
2796       //                 << " status = " << calib_status[dmy_num-1]
2797       //                 << std::endl ;
2798     }
2799 
2800     fclose(inpFile);  // close inp. file
2801     edm::LogInfo("EcalTrivialConditionRetriever") << "Read intercalibrations for " << ii << " xtals ";
2802     if (ii != 1700)
2803       edm::LogWarning("StoreEcalCondition") << "Some crystals missing, set to 1" << std::endl;
2804 
2805     // Transfer the data to the inter-calibration coefficients container
2806     // -----------------------------------------------------------------
2807 
2808     // DB supermodule always set to 1 for the TestBeam FIXME
2809     int sm_db = 1;
2810     // loop over channels
2811     for (int i = 0; i < 1700; i++) {
2812       //if (EBDetId::validDetId(iEta,iPhi)) {
2813       // CANNOT be used -- validDetId only checks ETA PHI method
2814       // doing a check by hand, here is the only place in CMSSW
2815       // outside TB code and EcalRawToDigi where needed
2816       // => no need for changing the DetId interface
2817       //
2818       // checking only sm_db -- guess can change with the above FIXME
2819       if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
2820         EBDetId ebid(sm_db, i + 1, EBDetId::SMCRYSTALMODE);
2821         if (calib_status[i])
2822           ical->setValue(ebid.rawId(), calib[i]);
2823         else
2824           ical->setValue(ebid.rawId(), 1.);
2825       }
2826       //}
2827     }  // loop over channels
2828   }
2829 
2830   return ical;
2831 }
2832 
2833 // new for the PF rec hit thresholds
2834 
2835 std::unique_ptr<EcalPFRecHitThresholds> EcalTrivialConditionRetriever::getPFRecHitThresholdsFromConfiguration(
2836     const EcalPFRecHitThresholdsRcd&) {
2837   std::unique_ptr<EcalPFRecHitThresholds> ical;
2838 
2839   // Reads the values from a txt file
2840   edm::LogInfo("EcalTrivialConditionRetriever")
2841       << "Reading PF RecHit Thresholds from file " << edm::FileInPath(pfRecHitFile_).fullPath().c_str();
2842 
2843   std::ifstream PFRecHitsFile(edm::FileInPath(pfRecHitFile_).fullPath().c_str());
2844 
2845   ical = std::make_unique<EcalPFRecHitThresholds>();
2846 
2847   // char line[50];
2848 
2849   int nxt = 0;
2850 
2851   edm::LogInfo("Going to multiply the sigmas by ") << pfRecHitThresholdsNSigmas_;
2852   edm::LogInfo("We will print some values ");
2853 
2854   while (!PFRecHitsFile.eof()) {
2855     //  while (fgets(line,50,inpFile)) {
2856     float thresh;
2857     int eta = 0;
2858     int phi = 0;
2859     int zeta = 0;
2860     PFRecHitsFile >> eta >> phi >> zeta >> thresh;
2861     //    sscanf(line, "%d %d %d %f", &eta, &phi, &zeta, &thresh);
2862 
2863     thresh = thresh * pfRecHitThresholdsNSigmas_;
2864 
2865     if (phi == 50)
2866       edm::LogInfo("EB ") << std::dec << eta << "/" << std::dec << phi << "/" << std::dec << zeta
2867                           << " thresh: " << thresh;
2868     nxt = nxt + 1;
2869     if (EBDetId::validDetId(eta, phi)) {
2870       EBDetId ebid(eta, phi);
2871       ical->setValue(ebid.rawId(), thresh);
2872     }
2873   }
2874   PFRecHitsFile.close();
2875   // fclose(inpFile);
2876 
2877   edm::LogInfo("Read number of EB crystals: ") << nxt;
2878 
2879   //******************************************************
2880   edm::LogInfo("Now reading the EE file ... ");
2881   edm::LogInfo("We will multiply the sigma in EE by ") << pfRecHitThresholdsNSigmas_;
2882   edm::LogInfo("We will multiply the sigma in EE at high eta by") << pfRecHitThresholdsNSigmasHEta_;
2883   edm::LogInfo("We will print some values ");
2884 
2885   edm::LogInfo("EcalTrivialConditionRetriever")
2886       << "Reading PF RecHit Thresholds EE from file " << edm::FileInPath(pfRecHitFileEE_).fullPath().c_str();
2887   std::ifstream PFRecHitsFileEE(edm::FileInPath(pfRecHitFileEE_).fullPath().c_str());
2888 
2889   nxt = 0;
2890 
2891   while (!PFRecHitsFileEE.eof()) {
2892     //  while (fgets(line,40,inpFileEE)) {
2893     float thresh;
2894     int ix = 0;
2895     int iy = 0;
2896     int iz = 0;
2897     PFRecHitsFileEE >> ix >> iy >> iz >> thresh;
2898     //    sscanf(line, "%d %d %d %f", &ix, &iy,&iz, &thresh);
2899 
2900     double eta =
2901         -log(tan(0.5 * atan(sqrt((ix - 50.5) * (ix - 50.5) + (iy - 50.5) * (iy - 50.5)) * 2.98 / 328.)));  // approx eta
2902 
2903     if (eta > 2.5) {
2904       thresh = thresh * pfRecHitThresholdsNSigmasHEta_;
2905     } else {
2906       thresh = thresh * pfRecHitThresholdsNSigmas_;
2907     }
2908 
2909     if (ix == 50)
2910       edm::LogInfo("EE ") << std::dec << ix << "/" << std::dec << iy << "/" << std::dec << iz << " thresh: " << thresh;
2911     if (EEDetId::validDetId(ix, iy, iz)) {
2912       EEDetId eeid(ix, iy, iz);
2913       ical->setValue(eeid.rawId(), thresh);
2914     }
2915     nxt = nxt + 1;
2916   }
2917   PFRecHitsFileEE.close();
2918   //  fclose(inpFileEE);
2919   edm::LogInfo("Read number of EE crystals: ") << nxt;
2920   edm::LogInfo("end PF Rec Hits ... ");
2921 
2922   return ical;
2923 }
2924 
2925 std::unique_ptr<EcalIntercalibConstantsMC> EcalTrivialConditionRetriever::getIntercalibConstantsMCFromConfiguration(
2926     const EcalIntercalibConstantsMCRcd&) {
2927   std::unique_ptr<EcalIntercalibConstantsMC> ical;
2928   //        std::make_unique<EcalIntercalibConstants>();
2929 
2930   // Read the values from a xml file
2931   // -------------------------------
2932 
2933   edm::LogInfo("EcalTrivialConditionRetriever")
2934       << "Reading intercalibration constants MC from file " << intercalibConstantsMCFile_.c_str();
2935 
2936   if (intercalibConstantsMCFile_.find(".xml") != std::string::npos) {
2937     edm::LogInfo("generating Intercalib MC from xml file");
2938 
2939     EcalCondHeader h;
2940     EcalIntercalibConstantsMC* rcd = new EcalIntercalibConstantsMC;
2941     EcalIntercalibConstantsMCXMLTranslator::readXML(intercalibConstantsMCFile_, h, *rcd);
2942 
2943     ical = std::unique_ptr<EcalIntercalibConstants>(rcd);
2944 
2945   } else {
2946     edm::LogInfo("ERROR>>> please provide a xml file");
2947   }
2948 
2949   return ical;
2950 }
2951 
2952 std::unique_ptr<EcalIntercalibErrors> EcalTrivialConditionRetriever::getIntercalibErrorsFromConfiguration(
2953     const EcalIntercalibErrorsRcd&) {
2954   auto ical = std::make_unique<EcalIntercalibErrors>();
2955 
2956   // Read the values from a txt file
2957   // -------------------------------
2958 
2959   edm::LogInfo("EcalTrivialConditionRetriever")
2960       << "Reading intercalibration constants from file " << intercalibErrorsFile_.c_str();
2961 
2962   FILE* inpFile;
2963   inpFile = fopen(intercalibErrorsFile_.c_str(), "r");
2964   if (!inpFile) {
2965     edm::LogError("EcalTrivialConditionRetriever") << "*** Can not open file: " << intercalibErrorsFile_;
2966     throw cms::Exception("Cannot open inter-calibration coefficients txt file");
2967   }
2968 
2969   char line[256];
2970   std::ostringstream str;
2971   fgets(line, 255, inpFile);
2972   int sm_number = atoi(line);
2973   str << "sm: " << sm_number;
2974 
2975   fgets(line, 255, inpFile);
2976   //int nevents=atoi (line) ; // not necessary here just for online conddb
2977 
2978   fgets(line, 255, inpFile);
2979   std::string gen_tag = line;
2980   str << "gen tag: " << gen_tag;  // should I use this?
2981 
2982   fgets(line, 255, inpFile);
2983   std::string cali_method = line;
2984   str << "cali method: " << cali_method << std::endl;  // not important
2985 
2986   fgets(line, 255, inpFile);
2987   std::string cali_version = line;
2988   str << "cali version: " << cali_version << std::endl;  // not important
2989 
2990   fgets(line, 255, inpFile);
2991   std::string cali_type = line;
2992   str << "cali type: " << cali_type;  // not important
2993 
2994   edm::LogInfo("EcalTrivialConditionRetriever") << "[PIETRO] Intercalibration file - " << str.str() << std::endl;
2995 
2996   float calib[1700] = {1};
2997   int calib_status[1700] = {0};
2998 
2999   int ii = 0;
3000 
3001   while (fgets(line, 255, inpFile)) {
3002     ii++;
3003     int dmy_num = 0;
3004     float dmy_calib = 0.;
3005     float dmy_RMS = 0.;
3006     int dmy_events = 0;
3007     int dmy_status = 0;
3008     sscanf(line, "%d %f %f %d %d", &dmy_num, &dmy_calib, &dmy_RMS, &dmy_events, &dmy_status);
3009     assert(dmy_num >= 1);
3010     assert(dmy_num <= 1700);
3011     calib[dmy_num - 1] = dmy_calib;
3012     calib_status[dmy_num - 1] = dmy_status;
3013 
3014     //       edm::LogInfo ("EcalTrivialConditionRetriever")
3015     //                 << "[PIETRO] cry = " << dmy_num
3016     //                 << " calib = " << calib[dmy_num-1]
3017     //                 << " RMS = " << dmy_RMS
3018     //                 << " events = " << dmy_events
3019     //                 << " status = " << calib_status[dmy_num-1]
3020     //                 << std::endl ;
3021   }
3022 
3023   fclose(inpFile);  // close inp. file
3024   edm::LogInfo("EcalTrivialConditionRetriever") << "Read intercalibrations for " << ii << " xtals ";
3025   if (ii != 1700)
3026     edm::LogWarning("StoreEcalCondition") << "Some crystals missing, set to 1" << std::endl;
3027 
3028   // Transfer the data to the inter-calibration coefficients container
3029   // -----------------------------------------------------------------
3030 
3031   // DB supermodule always set to 1 for the TestBeam FIXME
3032   int sm_db = 1;
3033   // loop over channels
3034   for (int i = 0; i < 1700; i++) {
3035     //if (EBDetId::validDetId(iEta,iPhi)) {
3036     // CANNOT be used -- validDetId only checks ETA PHI method
3037     // doing a check by hand, here is the only place in CMSSW
3038     // outside TB code and EcalRawToDigi where needed
3039     // => no need for changing the DetId interface
3040     //
3041     // checking only sm_db -- guess can change with the above FIXME
3042     if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
3043       EBDetId ebid(sm_db, i + 1, EBDetId::SMCRYSTALMODE);
3044       if (calib_status[i])
3045         ical->setValue(ebid.rawId(), calib[i]);
3046       else
3047         ical->setValue(ebid.rawId(), 1.);
3048     }
3049     //}
3050   }  // loop over channels
3051 
3052   //  edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ;
3053   return ical;
3054 }
3055 
3056 // --------------------------------------------------------------------------------
3057 
3058 std::unique_ptr<EcalTimeCalibConstants> EcalTrivialConditionRetriever::getTimeCalibConstantsFromConfiguration(
3059     const EcalTimeCalibConstantsRcd&) {
3060   auto ical = std::make_unique<EcalTimeCalibConstants>();
3061 
3062   // Read the values from a txt file
3063   // -------------------------------
3064 
3065   edm::LogInfo("EcalTrivialConditionRetriever")
3066       << "Reading time calibration constants from file " << timeCalibConstantsFile_.c_str();
3067 
3068   FILE* inpFile;
3069   inpFile = fopen(timeCalibConstantsFile_.c_str(), "r");
3070   if (!inpFile) {
3071     edm::LogError("EcalTrivialConditionRetriever") << "*** Can not open file: " << timeCalibConstantsFile_;
3072     throw cms::Exception("Cannot open inter-calibration coefficients txt file");
3073   }
3074 
3075   char line[256];
3076   std::ostringstream str;
3077   fgets(line, 255, inpFile);
3078   int sm_number = atoi(line);
3079   str << "sm: " << sm_number;
3080 
3081   fgets(line, 255, inpFile);
3082   //int nevents=atoi (line) ; // not necessary here just for online conddb
3083 
3084   fgets(line, 255, inpFile);
3085   std::string gen_tag = line;
3086   str << "gen tag: " << gen_tag;  // should I use this?
3087 
3088   fgets(line, 255, inpFile);
3089   std::string cali_method = line;
3090   str << "cali method: " << cali_method << std::endl;  // not important
3091 
3092   fgets(line, 255, inpFile);
3093   std::string cali_version = line;
3094   str << "cali version: " << cali_version << std::endl;  // not important
3095 
3096   fgets(line, 255, inpFile);
3097   std::string cali_type = line;
3098   str << "cali type: " << cali_type;  // not important
3099 
3100   edm::LogInfo("EcalTrivialConditionRetriever") << "TimeCalibration file - " << str.str() << std::endl;
3101 
3102   float calib[1700] = {1};
3103   int calib_status[1700] = {0};
3104 
3105   int ii = 0;
3106 
3107   while (fgets(line, 255, inpFile)) {
3108     ii++;
3109     int dmy_num = 0;
3110     float dmy_calib = 0.;
3111     float dmy_RMS = 0.;
3112     int dmy_events = 0;
3113     int dmy_status = 0;
3114     sscanf(line, "%d %f %f %d %d", &dmy_num, &dmy_calib, &dmy_RMS, &dmy_events, &dmy_status);
3115     assert(dmy_num >= 1);
3116     assert(dmy_num <= 1700);
3117     calib[dmy_num - 1] = dmy_calib;
3118     calib_status[dmy_num - 1] = dmy_status;
3119 
3120     //       edm::LogInfo ("EcalTrivialConditionRetriever")
3121     //                 << "[PIETRO] cry = " << dmy_num
3122     //                 << " calib = " << calib[dmy_num-1]
3123     //                 << " RMS = " << dmy_RMS
3124     //                 << " events = " << dmy_events
3125     //                 << " status = " << calib_status[dmy_num-1]
3126     //                 << std::endl ;
3127   }
3128 
3129   fclose(inpFile);  // close inp. file
3130   edm::LogInfo("EcalTrivialConditionRetriever") << "Read timeCalibrations for " << ii << " xtals ";
3131   if (ii != 1700)
3132     edm::LogWarning("StoreEcalCondition") << "Some crystals missing, set to 1" << std::endl;
3133 
3134   // Transfer the data to the inter-calibration coefficients container
3135   // -----------------------------------------------------------------
3136 
3137   // DB supermodule always set to 1 for the TestBeam FIXME
3138   int sm_db = 1;
3139   // loop over channels
3140   for (int i = 0; i < 1700; i++) {
3141     //if (EBDetId::validDetId(iEta,iPhi)) {
3142     // CANNOT be used -- validDetId only checks ETA PHI method
3143     // doing a check by hand, here is the only place in CMSSW
3144     // outside TB code and EcalRawToDigi where needed
3145     // => no need for changing the DetId interface
3146     //
3147     // checking only sm_db -- guess can change with the above FIXME
3148     if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
3149       EBDetId ebid(sm_db, i + 1, EBDetId::SMCRYSTALMODE);
3150       if (calib_status[i])
3151         ical->setValue(ebid.rawId(), calib[i]);
3152       else
3153         ical->setValue(ebid.rawId(), 1.);
3154     }
3155     //}
3156   }  // loop over channels
3157 
3158   //  edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ;
3159   return ical;
3160 }
3161 
3162 std::unique_ptr<EcalTimeCalibErrors> EcalTrivialConditionRetriever::getTimeCalibErrorsFromConfiguration(
3163     const EcalTimeCalibErrorsRcd&) {
3164   auto ical = std::make_unique<EcalTimeCalibErrors>();
3165 
3166   // Read the values from a txt file
3167   // -------------------------------
3168 
3169   edm::LogInfo("EcalTrivialConditionRetriever")
3170       << "Reading timeCalibration constants from file " << timeCalibErrorsFile_.c_str();
3171 
3172   FILE* inpFile;
3173   inpFile = fopen(timeCalibErrorsFile_.c_str(), "r");
3174   if (!inpFile) {
3175     edm::LogError("EcalTrivialConditionRetriever") << "*** Can not open file: " << timeCalibErrorsFile_;
3176     throw cms::Exception("Cannot open inter-calibration coefficients txt file");
3177   }
3178 
3179   char line[256];
3180   std::ostringstream str;
3181   fgets(line, 255, inpFile);
3182   int sm_number = atoi(line);
3183   str << "sm: " << sm_number;
3184 
3185   fgets(line, 255, inpFile);
3186   //int nevents=atoi (line) ; // not necessary here just for online conddb
3187 
3188   fgets(line, 255, inpFile);
3189   std::string gen_tag = line;
3190   str << "gen tag: " << gen_tag;  // should I use this?
3191 
3192   fgets(line, 255, inpFile);
3193   std::string cali_method = line;
3194   str << "cali method: " << cali_method << std::endl;  // not important
3195 
3196   fgets(line, 255, inpFile);
3197   std::string cali_version = line;
3198   str << "cali version: " << cali_version << std::endl;  // not important
3199 
3200   fgets(line, 255, inpFile);
3201   std::string cali_type = line;
3202   str << "cali type: " << cali_type;  // not important
3203 
3204   edm::LogInfo("EcalTrivialConditionRetriever") << "TimeCalibration file - " << str.str() << std::endl;
3205 
3206   float calib[1700] = {1};
3207   int calib_status[1700] = {0};
3208 
3209   int ii = 0;
3210 
3211   while (fgets(line, 255, inpFile)) {
3212     ii++;
3213     int dmy_num = 0;
3214     float dmy_calib = 0.;
3215     float dmy_RMS = 0.;
3216     int dmy_events = 0;
3217     int dmy_status = 0;
3218     sscanf(line, "%d %f %f %d %d", &dmy_num, &dmy_calib, &dmy_RMS, &dmy_events, &dmy_status);
3219     assert(dmy_num >= 1);
3220     assert(dmy_num <= 1700);
3221     calib[dmy_num - 1] = dmy_calib;
3222     calib_status[dmy_num - 1] = dmy_status;
3223 
3224     //       edm::LogInfo ("EcalTrivialConditionRetriever")
3225     //                 << "[PIETRO] cry = " << dmy_num
3226     //                 << " calib = " << calib[dmy_num-1]
3227     //                 << " RMS = " << dmy_RMS
3228     //                 << " events = " << dmy_events
3229     //                 << " status = " << calib_status[dmy_num-1]
3230     //                 << std::endl ;
3231   }
3232 
3233   fclose(inpFile);  // close inp. file
3234   edm::LogInfo("EcalTrivialConditionRetriever") << "Read time calibrations for " << ii << " xtals ";
3235   if (ii != 1700)
3236     edm::LogWarning("StoreEcalCondition") << "Some crystals missing, set to 1" << std::endl;
3237 
3238   // Transfer the data to the inter-calibration coefficients container
3239   // -----------------------------------------------------------------
3240 
3241   // DB supermodule always set to 1 for the TestBeam FIXME
3242   int sm_db = 1;
3243   // loop over channels
3244   for (int i = 0; i < 1700; i++) {
3245     //if (EBDetId::validDetId(iEta,iPhi)) {
3246     // CANNOT be used -- validDetId only checks ETA PHI method
3247     // doing a check by hand, here is the only place in CMSSW
3248     // outside TB code and EcalRawToDigi where needed
3249     // => no need for changing the DetId interface
3250     //
3251     // checking only sm_db -- guess can change with the above FIXME
3252     if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
3253       EBDetId ebid(sm_db, i + 1, EBDetId::SMCRYSTALMODE);
3254       if (calib_status[i])
3255         ical->setValue(ebid.rawId(), calib[i]);
3256       else
3257         ical->setValue(ebid.rawId(), 1.);
3258     }
3259     //}
3260   }  // loop over channels
3261 
3262   //  edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ;
3263   return ical;
3264 }
3265 
3266 // --------------------------------------------------------------------------------
3267 
3268 std::unique_ptr<EcalMappingElectronics> EcalTrivialConditionRetriever::getMappingFromConfiguration(
3269     const EcalMappingElectronicsRcd&) {
3270   auto mapping = std::make_unique<EcalMappingElectronics>();
3271   edm::LogInfo("EcalTrivialConditionRetriever")
3272       << "Reading mapping from file " << edm::FileInPath(mappingFile_).fullPath().c_str();
3273 
3274   std::ifstream f(edm::FileInPath(mappingFile_).fullPath().c_str());
3275   if (!f.good()) {
3276     edm::LogError("EcalTrivialConditionRetriever") << "File not found";
3277     throw cms::Exception("FileNotFound");
3278   }
3279 
3280   // uint32_t detid, elecid, triggerid;
3281 
3282   int ix, iy, iz, CL;
3283   // int dccid, towerid, stripid, xtalid;
3284   // int tccid, tower, ipseudostrip, xtalinps;
3285   int dccid, towerid, pseudostrip_in_SC, xtal_in_pseudostrip;
3286   int tccid, tower, pseudostrip_in_TCC, pseudostrip_in_TT;
3287 
3288   while (!f.eof()) {
3289     // f >> detid >> elecid >> triggerid;
3290     f >> ix >> iy >> iz >> CL >> dccid >> towerid >> pseudostrip_in_SC >> xtal_in_pseudostrip >> tccid >> tower >>
3291         pseudostrip_in_TCC >> pseudostrip_in_TT;
3292 
3293     //       if (!EEDetId::validDetId(ix,iy,iz))
3294     //    continue;
3295 
3296     EEDetId detid(ix, iy, iz, EEDetId::XYMODE);
3297     // std::cout << " dcc tower ps_in_SC xtal_in_ps " << dccid << " " << towerid << " " << pseudostrip_in_SC << " " << xtal_in_pseudostrip << std::endl;
3298     EcalElectronicsId elecid(dccid, towerid, pseudostrip_in_SC, xtal_in_pseudostrip);
3299     // std::cout << " tcc tt ps_in_TT xtal_in_ps " << tccid << " " << tower << " " << pseudostrip_in_TT << " " << xtal_in_pseudostrip << std::endl;
3300     EcalTriggerElectronicsId triggerid(tccid, tower, pseudostrip_in_TT, xtal_in_pseudostrip);
3301     EcalMappingElement aElement;
3302     aElement.electronicsid = elecid.rawId();
3303     aElement.triggerid = triggerid.rawId();
3304     (*mapping).setValue(detid, aElement);
3305   }
3306 
3307   f.close();
3308   return mapping;
3309 }
3310 
3311 std::unique_ptr<EcalMappingElectronics> EcalTrivialConditionRetriever::produceEcalMappingElectronics(
3312     const EcalMappingElectronicsRcd&) {
3313   auto ical = std::make_unique<EcalMappingElectronics>();
3314   return ical;
3315 }
3316 
3317 // --------------------------------------------------------------------------------
3318 
3319 std::unique_ptr<Alignments> EcalTrivialConditionRetriever::produceEcalAlignmentEB(const EBAlignmentRcd&) {
3320   double mytrans[3] = {0., 0., 0.};
3321   double myeuler[3] = {0., 0., 0.};
3322   std::ifstream f;
3323   if (getEBAlignmentFromFile_)
3324     f.open(edm::FileInPath(EBAlignmentFile_).fullPath().c_str());
3325   std::vector<AlignTransform> my_align;
3326   int ieta = 1;
3327   int iphi = 0;
3328   for (int SM = 1; SM < 37; SM++) {
3329     // make an EBDetId since we need EBDetId::rawId()
3330     if (SM > 18) {
3331       iphi = 1 + (SM - 19) * 20;
3332       ieta = -1;
3333     } else
3334       iphi = SM * 20;
3335     EBDetId ebdetId(ieta, iphi);
3336     if (getEBAlignmentFromFile_) {
3337       f >> myeuler[0] >> myeuler[1] >> myeuler[2] >> mytrans[0] >> mytrans[1] >> mytrans[2];
3338       edm::LogInfo(" translation ") << mytrans[0] << " " << mytrans[1] << " " << mytrans[2] << "\n"
3339                                     << " euler " << myeuler[0] << " " << myeuler[1] << " " << myeuler[2];
3340     }
3341     CLHEP::Hep3Vector translation(mytrans[0], mytrans[1], mytrans[2]);
3342     CLHEP::HepEulerAngles euler(myeuler[0], myeuler[1], myeuler[2]);
3343     AlignTransform transform(translation, euler, ebdetId);
3344     my_align.push_back(transform);
3345   }
3346   /*
3347   // check
3348   uint32_t m_rawid;
3349   double m_x, m_y, m_z;
3350   double m_phi, m_theta, m_psi;
3351   int SM = 0;
3352   for (std::vector<AlignTransform>::const_iterator i = my_align.begin(); i != my_align.end(); ++i){ 
3353     m_rawid = i->rawId();
3354     CLHEP::Hep3Vector translation = i->translation();
3355     m_x = translation.x();
3356     m_y = translation.y();
3357     m_z = translation.z();
3358     CLHEP::HepRotation rotation = i->rotation();
3359     m_phi = rotation.getPhi();
3360     m_theta = rotation.getTheta();
3361     m_psi = rotation.getPsi();
3362     SM++;
3363     std::cout << " SM " << SM << " Id " << m_rawid << " x " << m_x << " y " << m_y << " z " << m_z
3364           << " phi " << m_phi << " theta " << m_theta << " psi " << m_psi << std::endl;
3365   }
3366   */
3367   Alignments a;
3368   a.m_align = my_align;
3369 
3370   return std::make_unique<Alignments>(a);
3371 }
3372 
3373 std::unique_ptr<Alignments> EcalTrivialConditionRetriever::produceEcalAlignmentEE(const EEAlignmentRcd&) {
3374   double mytrans[3] = {0., 0., 0.};
3375   double myeuler[3] = {0., 0., 0.};
3376   std::ifstream f;
3377   if (getEEAlignmentFromFile_)
3378     f.open(edm::FileInPath(EEAlignmentFile_).fullPath().c_str());
3379   std::vector<AlignTransform> my_align;
3380   int ix = 20;
3381   int iy = 50;
3382   int side = -1;
3383   for (int Dee = 0; Dee < 4; Dee++) {
3384     // make an EEDetId since we need EEDetId::rawId()
3385     if (Dee == 1 || Dee == 3)
3386       ix = 70;
3387     else
3388       ix = 20;
3389     if (Dee == 2)
3390       side = 1;
3391     EEDetId eedetId(ix, iy, side);
3392     if (getEEAlignmentFromFile_) {
3393       f >> myeuler[0] >> myeuler[1] >> myeuler[2] >> mytrans[0] >> mytrans[1] >> mytrans[2];
3394       edm::LogInfo(" translation ") << mytrans[0] << " " << mytrans[1] << " " << mytrans[2] << "\n"
3395                                     << " euler " << myeuler[0] << " " << myeuler[1] << " " << myeuler[2];
3396     }
3397     CLHEP::Hep3Vector translation(mytrans[0], mytrans[1], mytrans[2]);
3398     CLHEP::HepEulerAngles euler(myeuler[0], myeuler[1], myeuler[2]);
3399     AlignTransform transform(translation, euler, eedetId);
3400     my_align.push_back(transform);
3401   }
3402   Alignments a;
3403   a.m_align = my_align;
3404   return std::make_unique<Alignments>(a);
3405 }
3406 
3407 std::unique_ptr<Alignments> EcalTrivialConditionRetriever::produceEcalAlignmentES(const ESAlignmentRcd&) {
3408   double mytrans[3] = {0., 0., 0.};
3409   double myeuler[3] = {0., 0., 0.};
3410   std::ifstream f;
3411   if (getESAlignmentFromFile_)
3412     f.open(edm::FileInPath(ESAlignmentFile_).fullPath().c_str());
3413   std::vector<AlignTransform> my_align;
3414   //  int ix_vect[10] = {10, 30, 30, 50, 10, 30, 10, 30};
3415   int pl_vect[10] = {2, 2, 1, 1, 1, 1, 2, 2};
3416   int iy = 10;
3417   int side = -1;
3418   int strip = 1;
3419   for (int layer = 0; layer < 8; layer++) {
3420     // make an ESDetId since we need ESDetId::rawId()
3421     int ix = 10 + (layer % 2) * 20;
3422     int plane = pl_vect[layer];
3423     if (layer > 3)
3424       side = 1;
3425     ESDetId esdetId(strip, ix, iy, plane, side);
3426     if (getESAlignmentFromFile_) {
3427       f >> myeuler[0] >> myeuler[1] >> myeuler[2] >> mytrans[0] >> mytrans[1] >> mytrans[2];
3428       edm::LogInfo(" translation ") << mytrans[0] << " " << mytrans[1] << " " << mytrans[2] << "\n"
3429                                     << " euler " << myeuler[0] << " " << myeuler[1] << " " << myeuler[2];
3430     }
3431     CLHEP::Hep3Vector translation(mytrans[0], mytrans[1], mytrans[2]);
3432     CLHEP::HepEulerAngles euler(myeuler[0], myeuler[1], myeuler[2]);
3433     AlignTransform transform(translation, euler, esdetId);
3434     my_align.push_back(transform);
3435   }
3436   Alignments a;
3437   a.m_align = my_align;
3438   return std::make_unique<Alignments>(a);
3439 }
3440 
3441 std::unique_ptr<EcalSampleMask> EcalTrivialConditionRetriever::produceEcalSampleMask(const EcalSampleMaskRcd&) {
3442   return std::make_unique<EcalSampleMask>(sampleMaskEB_, sampleMaskEE_);
3443 }
3444 
3445 std::unique_ptr<EcalTimeBiasCorrections> EcalTrivialConditionRetriever::produceEcalTimeBiasCorrections(
3446     const EcalTimeBiasCorrectionsRcd&) {
3447   auto ipar = std::make_unique<EcalTimeBiasCorrections>();
3448   copy(EBtimeCorrAmplitudeBins_.begin(), EBtimeCorrAmplitudeBins_.end(), back_inserter(ipar->EBTimeCorrAmplitudeBins));
3449   copy(EBtimeCorrShiftBins_.begin(), EBtimeCorrShiftBins_.end(), back_inserter(ipar->EBTimeCorrShiftBins));
3450   copy(EEtimeCorrAmplitudeBins_.begin(), EEtimeCorrAmplitudeBins_.end(), back_inserter(ipar->EETimeCorrAmplitudeBins));
3451   copy(EEtimeCorrShiftBins_.begin(), EEtimeCorrShiftBins_.end(), back_inserter(ipar->EETimeCorrShiftBins));
3452   return ipar;
3453 }
3454 
3455 std::unique_ptr<EcalSamplesCorrelation> EcalTrivialConditionRetriever::produceEcalSamplesCorrelation(
3456     const EcalSamplesCorrelationRcd&) {
3457   if (getSamplesCorrelationFromFile_) {
3458     std::ifstream f;
3459     f.open(edm::FileInPath(SamplesCorrelationFile_).fullPath().c_str());
3460     float ww;
3461     for (int j = 0; j < 10; ++j) {
3462       f >> ww;
3463       EBG12samplesCorrelation_.push_back(ww);
3464     }
3465     for (int j = 0; j < 10; ++j) {
3466       f >> ww;
3467       EBG6samplesCorrelation_.push_back(ww);
3468     }
3469     for (int j = 0; j < 10; ++j) {
3470       f >> ww;
3471       EBG1samplesCorrelation_.push_back(ww);
3472     }
3473     for (int j = 0; j < 10; ++j) {
3474       f >> ww;
3475       EEG12samplesCorrelation_.push_back(ww);
3476     }
3477     for (int j = 0; j < 10; ++j) {
3478       f >> ww;
3479       EEG6samplesCorrelation_.push_back(ww);
3480     }
3481     for (int j = 0; j < 10; ++j) {
3482       f >> ww;
3483       EEG1samplesCorrelation_.push_back(ww);
3484     }
3485     f.close();
3486   }
3487   auto ipar = std::make_unique<EcalSamplesCorrelation>();
3488   copy(EBG12samplesCorrelation_.begin(), EBG12samplesCorrelation_.end(), back_inserter(ipar->EBG12SamplesCorrelation));
3489   copy(EBG6samplesCorrelation_.begin(), EBG6samplesCorrelation_.end(), back_inserter(ipar->EBG6SamplesCorrelation));
3490   copy(EBG1samplesCorrelation_.begin(), EBG1samplesCorrelation_.end(), back_inserter(ipar->EBG1SamplesCorrelation));
3491   copy(EEG12samplesCorrelation_.begin(), EEG12samplesCorrelation_.end(), back_inserter(ipar->EEG12SamplesCorrelation));
3492   copy(EEG6samplesCorrelation_.begin(), EEG6samplesCorrelation_.end(), back_inserter(ipar->EEG6SamplesCorrelation));
3493   copy(EEG1samplesCorrelation_.begin(), EEG1samplesCorrelation_.end(), back_inserter(ipar->EEG1SamplesCorrelation));
3494   return ipar;
3495 }
3496 
3497 std::unique_ptr<EcalSimPulseShape> EcalTrivialConditionRetriever::getEcalSimPulseShapeFromConfiguration(
3498     const EcalSimPulseShapeRcd&) {
3499   auto result = std::make_unique<EcalSimPulseShape>();
3500 
3501   // save time interval to be used for the pulse shape
3502   result->time_interval = sim_pulse_shape_TI_;
3503 
3504   // containers to store the shape info
3505   std::vector<double> EBshape;
3506   std::vector<double> EEshape;
3507   std::vector<double> APDshape;
3508 
3509   // --- get the 3 shapes from the user provided txt files
3510   if (!EBSimPulseShapeFile_.empty()) {
3511     std::ifstream shapeEBFile;
3512     shapeEBFile.open(EBSimPulseShapeFile_.c_str());
3513     double ww;
3514     while (shapeEBFile >> ww)
3515       EBshape.push_back(ww);
3516     shapeEBFile.close();
3517   }
3518   if (!EESimPulseShapeFile_.empty()) {
3519     std::ifstream shapeEEFile;
3520     shapeEEFile.open(EESimPulseShapeFile_.c_str());
3521     double ww;
3522     while (shapeEEFile >> ww)
3523       EEshape.push_back(ww);
3524     shapeEEFile.close();
3525   }
3526   if (!APDSimPulseShapeFile_.empty()) {
3527     std::ifstream shapeAPDFile;
3528     shapeAPDFile.open(APDSimPulseShapeFile_.c_str());
3529     double ww;
3530     while (shapeAPDFile >> ww)
3531       APDshape.push_back(ww);
3532     shapeAPDFile.close();
3533   }
3534 
3535   // --- save threshold
3536   result->barrel_thresh = sim_pulse_shape_EB_thresh_;
3537   result->endcap_thresh = sim_pulse_shape_EE_thresh_;
3538   result->apd_thresh = sim_pulse_shape_APD_thresh_;
3539 
3540   // --- copy
3541   copy(EBshape.begin(), EBshape.end(), back_inserter(result->barrel_shape));
3542   copy(EEshape.begin(), EEshape.end(), back_inserter(result->endcap_shape));
3543   copy(APDshape.begin(), APDshape.end(), back_inserter(result->apd_shape));
3544 
3545   return result;
3546 }