CMS 3D CMS Logo

EcalTrivialConditionRetriever.cc
Go to the documentation of this file.
1 //
2 // Created: 2 Mar 2006
3 // Shahram Rahatlou, University of Rome & INFN
4 //
5 #include <iostream>
6 #include <fstream>
7 #include "TRandom3.h"
8 
13 
20 
21 //#include "DataFormats/Provenance/interface/Timestamp.h"
22 
26 
27 
28 using namespace edm;
29 
31 {
32  // initilize parameters used to produce cond DB objects
33  totLumi_=ps.getUntrackedParameter<double>("TotLumi",0.0);
34  instLumi_ = ps.getUntrackedParameter<double>("InstLumi",0.0);
35 
36  // initilize parameters used to produce cond DB objects
37  adcToGeVEBConstant_ = ps.getUntrackedParameter<double>("adcToGeVEBConstant",0.035);
38  adcToGeVEEConstant_ = ps.getUntrackedParameter<double>("adcToGeVEEConstant",0.060);
39 
40  intercalibConstantMeanMC_ = ps.getUntrackedParameter<double>("intercalibConstantMeanMC",1.0);
41  intercalibConstantSigmaMC_ = ps.getUntrackedParameter<double>("intercalibConstantSigmaMC",0.0);
42 
43  linCorrMean_ = ps.getUntrackedParameter<double>("linCorrMean",1.0);
44  linCorrSigma_ = ps.getUntrackedParameter<double>("linCorrSigma",0.0);
45 
46  linearTime1_ = (unsigned long)atoi( ps.getUntrackedParameter<std::string>("linearTime1","1").c_str());
47  linearTime2_= (unsigned long)atoi( ps.getUntrackedParameter<std::string>("linearTime2","0").c_str());
48  linearTime3_= (unsigned long)atoi( ps.getUntrackedParameter<std::string>("linearTime3","0").c_str());
49 
50 
51  intercalibConstantMean_ = ps.getUntrackedParameter<double>("intercalibConstantMean",1.0);
52  intercalibConstantSigma_ = ps.getUntrackedParameter<double>("intercalibConstantSigma",0.0);
53  intercalibErrorMean_ = ps.getUntrackedParameter<double>("IntercalibErrorMean",0.0);
54 
55  timeCalibConstantMean_ = ps.getUntrackedParameter<double>("timeCalibConstantMean",0.0);
56  timeCalibConstantSigma_ = ps.getUntrackedParameter<double>("timeCalibConstantSigma",0.0);
57  timeCalibErrorMean_ = ps.getUntrackedParameter<double>("timeCalibErrorMean",0.0);
58 
59  timeOffsetEBConstant_ = ps.getUntrackedParameter<double>("timeOffsetEBConstant",0.0);
60  timeOffsetEEConstant_ = ps.getUntrackedParameter<double>("timeOffsetEEConstant",0.0);
61 
62  laserAlphaMean_ = ps.getUntrackedParameter<double>("laserAlphaMean",1.55);
63  laserAlphaSigma_ = ps.getUntrackedParameter<double>("laserAlphaSigma",0);
64 
65  laserAPDPNTime1_ = (unsigned long)atoi( ps.getUntrackedParameter<std::string>("laserAPDPNTime1","1").c_str());
66  laserAPDPNTime2_= (unsigned long)atoi( ps.getUntrackedParameter<std::string>("laserAPDPNTime2","0").c_str());
67  laserAPDPNTime3_= (unsigned long)atoi( ps.getUntrackedParameter<std::string>("laserAPDPNTime3","0").c_str());
68 
69  laserAPDPNRefMean_ = ps.getUntrackedParameter<double>("laserAPDPNRefMean",1.0);
70  laserAPDPNRefSigma_ = ps.getUntrackedParameter<double>("laserAPDPNRefSigma",0.0);
71 
72  laserAPDPNMean_ = ps.getUntrackedParameter<double>("laserAPDPNMean",1.0);
73  laserAPDPNSigma_ = ps.getUntrackedParameter<double>("laserAPDPNSigma",0.0);
74 
75  localContCorrParameters_ = ps.getUntrackedParameter< std::vector<double> >("localContCorrParameters", std::vector<double>(0) );
76  crackCorrParameters_ = ps.getUntrackedParameter< std::vector<double> >("crackCorrParameters", std::vector<double>(0) );
77  energyCorrectionParameters_ = ps.getUntrackedParameter< std::vector<double> >("energyCorrectionParameters", std::vector<double>(0) );
78  energyUncertaintyParameters_ = ps.getUntrackedParameter< std::vector<double> >("energyUncertaintyParameters", std::vector<double>(0) );
79  energyCorrectionObjectSpecificParameters_ = ps.getUntrackedParameter< std::vector<double> >("energyCorrectionObjectSpecificParameters", std::vector<double>(0) );
80 
81  EBpedMeanX12_ = ps.getUntrackedParameter<double>("EBpedMeanX12", 200.);
82  EBpedRMSX12_ = ps.getUntrackedParameter<double>("EBpedRMSX12", 1.10);
83  EBpedMeanX6_ = ps.getUntrackedParameter<double>("EBpedMeanX6", 200.);
84  EBpedRMSX6_ = ps.getUntrackedParameter<double>("EBpedRMSX6", 0.90);
85  EBpedMeanX1_ = ps.getUntrackedParameter<double>("EBpedMeanX1", 200.);
86  EBpedRMSX1_ = ps.getUntrackedParameter<double>("EBpedRMSX1", 0.62);
87 
88  EEpedMeanX12_ = ps.getUntrackedParameter<double>("EEpedMeanX12", 200.);
89  EEpedRMSX12_ = ps.getUntrackedParameter<double>("EEpedRMSX12", 2.50);
90  EEpedMeanX6_ = ps.getUntrackedParameter<double>("EEpedMeanX6", 200.);
91  EEpedRMSX6_ = ps.getUntrackedParameter<double>("EEpedRMSX6", 2.00);
92  EEpedMeanX1_ = ps.getUntrackedParameter<double>("EEpedMeanX1", 200.);
93  EEpedRMSX1_ = ps.getUntrackedParameter<double>("EEpedRMSX1", 1.40);
94 
95  gainRatio12over6_ = ps.getUntrackedParameter<double>("gainRatio12over6", 2.0);
96  gainRatio6over1_ = ps.getUntrackedParameter<double>("gainRatio6over1", 6.0);
97 
98  getWeightsFromFile_ = ps.getUntrackedParameter<bool>("getWeightsFromFile",false);
99 
100  sampleMaskEB_ = ps.getUntrackedParameter<unsigned int>("sampleMaskEB",1023);
101  sampleMaskEE_ = ps.getUntrackedParameter<unsigned int>("sampleMaskEB",1023);
102 
103  EBtimeCorrAmplitudeBins_ = ps.getUntrackedParameter< std::vector<double> >("EBtimeCorrAmplitudeBins", std::vector<double>() );
104  EBtimeCorrShiftBins_ = ps.getUntrackedParameter< std::vector<double> >("EBtimeCorrShiftBins", std::vector<double>() );
105  EEtimeCorrAmplitudeBins_ = ps.getUntrackedParameter< std::vector<double> >("EEtimeCorrAmplitudeBins", std::vector<double>() );
106  EEtimeCorrShiftBins_ = ps.getUntrackedParameter< std::vector<double> >("EEtimeCorrShiftBins", std::vector<double>() );
107 
108  EBG12samplesCorrelation_ = ps.getUntrackedParameter< std::vector<double> >("EBG12samplesCorrelation", std::vector<double>() );
109  EBG6samplesCorrelation_ = ps.getUntrackedParameter< std::vector<double> >("EBG6samplesCorrelation", std::vector<double>() );
110  EBG1samplesCorrelation_ = ps.getUntrackedParameter< std::vector<double> >("EBG1samplesCorrelation", std::vector<double>() );
111  EEG12samplesCorrelation_ = ps.getUntrackedParameter< std::vector<double> >("EEG12samplesCorrelation", std::vector<double>() );
112  EEG6samplesCorrelation_ = ps.getUntrackedParameter< std::vector<double> >("EEG6samplesCorrelation", std::vector<double>() );
113  EEG1samplesCorrelation_ = ps.getUntrackedParameter< std::vector<double> >("EEG1samplesCorrelation", std::vector<double>() );
114 
115 
116  sim_pulse_shape_EB_thresh_ = ps.getParameter<double>("sim_pulse_shape_EB_thresh" );
117  sim_pulse_shape_EE_thresh_ = ps.getParameter<double>("sim_pulse_shape_EE_thresh" );
118  sim_pulse_shape_APD_thresh_ = ps.getParameter<double>("sim_pulse_shape_APD_thresh");
119 
120  sim_pulse_shape_TI_ = ps.getUntrackedParameter<double>("sim_pulse_shape_TI", 1.0);
121 
122  nTDCbins_ = 1;
123 
124  weightsForAsynchronousRunning_ = ps.getUntrackedParameter<bool>("weightsForTB",false);
125 
126  std::cout << " EcalTrivialConditionRetriever " << std::endl;
127 
128 
129 
130  if(totLumi_ > 0 ) {
131 
132  std::cout << " EcalTrivialConditionRetriever going to create conditions based on the damage deu to "<<totLumi_<<
133  " fb-1 integrated luminosity" << std::endl;
134 
135  }
136 
137  if (weightsForAsynchronousRunning_)
138  {
139  getWeightsFromFile_ = true; //override user request
140  //nTDCbins_ = 25;
141  nTDCbins_ = 50; //modif Alex-21-07-2006
142  }
143 
144  std::string path="CalibCalorimetry/EcalTrivialCondModules/data/";
145  std::string weightType;
146  std::ostringstream str;
147 
148  if (!weightsForAsynchronousRunning_)
149  str << "_CMS.txt" ;
150  else
151  str << "_TB.txt" ;
152 
153  weightType = str.str();
154 
155  amplWeightsFile_ = ps.getUntrackedParameter<std::string>("amplWeightsFile",path+"ampWeights"+weightType);
156  amplWeightsAftFile_ = ps.getUntrackedParameter<std::string>("amplWeightsAftFile",path+"ampWeightsAfterGainSwitch"+weightType);
157  pedWeightsFile_ = ps.getUntrackedParameter<std::string>("pedWeightsFile",path+"pedWeights"+weightType);
158  pedWeightsAftFile_ = ps.getUntrackedParameter<std::string>("pedWeightsAftFile",path+"pedWeightsAfterGainSwitch"+weightType);
159  jittWeightsFile_ = ps.getUntrackedParameter<std::string>("jittWeightsFile",path+"timeWeights"+weightType);
160  jittWeightsAftFile_ = ps.getUntrackedParameter<std::string>("jittWeightsAftFile",path+"timeWeightsAfterGainSwitch"+weightType);
161  chi2MatrixFile_ = ps.getUntrackedParameter<std::string>("chi2MatrixFile",path+"chi2Matrix"+weightType);
162  chi2MatrixAftFile_ = ps.getUntrackedParameter<std::string>("chi2MatrixAftFile",path+"chi2MatrixAfterGainSwitch"+weightType);
163 
164  amplWeights_.resize(nTDCbins_);
165  amplWeightsAft_.resize(nTDCbins_);
166  pedWeights_.resize(nTDCbins_);
167  pedWeightsAft_.resize(nTDCbins_);
168  jittWeights_.resize(nTDCbins_);
169  jittWeightsAft_.resize(nTDCbins_);
170  chi2Matrix_.resize(nTDCbins_);
171  chi2MatrixAft_.resize(nTDCbins_);
172 
173  // default weights for MGPA shape after pedestal subtraction
174  getWeightsFromConfiguration(ps);
175 
176  producedEcalPedestals_ = ps.getUntrackedParameter<bool>("producedEcalPedestals",true);
177  producedEcalWeights_ = ps.getUntrackedParameter<bool>("producedEcalWeights",true);
178 
179  producedEcalGainRatios_ = ps.getUntrackedParameter<bool>("producedEcalGainRatios",true);
180  producedEcalADCToGeVConstant_ = ps.getUntrackedParameter<bool>("producedEcalADCToGeVConstant",true);
181 
182  producedEcalMappingElectronics_ = ps.getUntrackedParameter<bool>("producedEcalMappingElectronics",true);
183  mappingFile_ = ps.getUntrackedParameter<std::string>("mappingFile","");
184 
185  if ( producedEcalMappingElectronics_ ) {
186  if ( !mappingFile_.empty() ) { // if file provided read channel map
188  } else {
190  }
191  findingRecord<EcalMappingElectronicsRcd>();
192  }
193  // Alignment from file
194  getEBAlignmentFromFile_ = ps.getUntrackedParameter<bool>("getEBAlignmentFromFile",false);
195  if(getEBAlignmentFromFile_) {
196  EBAlignmentFile_ = ps.getUntrackedParameter<std::string>("EBAlignmentFile",path+"EBAlignment.txt");
197  }
198 
199  getEEAlignmentFromFile_ = ps.getUntrackedParameter<bool>("getEEAlignmentFromFile",false);
200  if(getEEAlignmentFromFile_) {
201  EEAlignmentFile_ = ps.getUntrackedParameter<std::string>("EEAlignmentFile",path+"EEAlignment.txt");
202  }
203 
204  getESAlignmentFromFile_ = ps.getUntrackedParameter<bool>("getESAlignmentFromFile",false);
205  if(getESAlignmentFromFile_)
206  ESAlignmentFile_ = ps.getUntrackedParameter<std::string>("ESAlignmentFile",path+"ESAlignment.txt");
207 
208  verbose_ = ps.getUntrackedParameter<int>("verbose", 0);
209 
210  //Tell Producer what we produce
211  //setWhatproduce(this);
212  if (producedEcalPedestals_)
214 
215  if (producedEcalWeights_) {
218  }
219 
220  if (producedEcalGainRatios_)
222 
223  if (producedEcalADCToGeVConstant_)
225 
226  // TimeOffsetConstant
227  producedEcalTimeOffsetConstant_ = ps.getUntrackedParameter<bool>("producedEcalTimeOffsetConstant",true);
228  //std::cout << " EcalTrivialConditionRetriever : producedEcalTimeOffsetConstant_" << producedEcalTimeOffsetConstant_ << std::endl;
229  if (producedEcalTimeOffsetConstant_) {
231  findingRecord<EcalTimeOffsetConstantRcd>();
232  }
233 
234  // linear corrections
235  producedEcalLinearCorrections_ = ps.getUntrackedParameter<bool>("producedEcalLinearCorrections",true);
236  linearCorrectionsFile_ = ps.getUntrackedParameter<std::string>("linearCorrectionsFile","") ;
237 
238  if (producedEcalLinearCorrections_) { // user asks to produce constants
239  if(!linearCorrectionsFile_.empty()) { // if file provided read constants
241  } else { // set all constants to 1. or smear as specified by user
243  }
244  findingRecord<EcalLinearCorrectionsRcd> () ;
245  }
246 
247 
248 
249  // intercalibration constants
250  producedEcalIntercalibConstants_ = ps.getUntrackedParameter<bool>("producedEcalIntercalibConstants",true);
251  intercalibConstantsFile_ = ps.getUntrackedParameter<std::string>("intercalibConstantsFile","") ;
252 
253  intercalibConstantsMCFile_ = ps.getUntrackedParameter<std::string>("intercalibConstantsMCFile","") ;
254 
255  if (producedEcalIntercalibConstants_) { // user asks to produce constants
256  if(!intercalibConstantsFile_.empty()) { // if file provided read constants
258  } else { // set all constants to 1. or smear as specified by user
260  }
261  findingRecord<EcalIntercalibConstantsRcd> () ;
262  }
263  // MC intercalibrations
264  producedEcalIntercalibConstantsMC_ = ps.getUntrackedParameter<bool>("producedEcalIntercalibConstantsMC",true);
265 
266  if (producedEcalIntercalibConstantsMC_) { // user asks to produce constants
267  if(!intercalibConstantsMCFile_.empty()) { // if file provided read constants
269  } else { // set all constants to 1. or smear as specified by user
271  }
272  findingRecord<EcalIntercalibConstantsMCRcd> () ;
273  }
274 
275  // intercalibration constants
276  producedEcalIntercalibErrors_ = ps.getUntrackedParameter<bool>("producedEcalIntercalibErrors",true);
277  intercalibErrorsFile_ = ps.getUntrackedParameter<std::string>("intercalibErrorsFile","") ;
278 
279  if (producedEcalIntercalibErrors_) { // user asks to produce constants
280  if(!intercalibErrorsFile_.empty()) { // if file provided read constants
282  } else { // set all constants to 1. or smear as specified by user
284  }
285  findingRecord<EcalIntercalibErrorsRcd> () ;
286  }
287 
288  // time calibration constants
289  producedEcalTimeCalibConstants_ = ps.getUntrackedParameter<bool>("producedEcalTimeCalibConstants",true);
290  timeCalibConstantsFile_ = ps.getUntrackedParameter<std::string>("timeCalibConstantsFile","") ;
291 
292  if (producedEcalTimeCalibConstants_) { // user asks to produce constants
293  if(!timeCalibConstantsFile_.empty()) { // if file provided read constants
295  } else { // set all constants to 1. or smear as specified by user
297  }
298  findingRecord<EcalTimeCalibConstantsRcd> () ;
299  }
300 
301  // time calibration constants
302  producedEcalTimeCalibErrors_ = ps.getUntrackedParameter<bool>("producedEcalTimeCalibErrors",true);
303  timeCalibErrorsFile_ = ps.getUntrackedParameter<std::string>("timeCalibErrorsFile","") ;
304 
305  if (producedEcalTimeCalibErrors_) { // user asks to produce constants
306  if(!timeCalibErrorsFile_.empty()) { // if file provided read constants
308  } else { // set all constants to 1. or smear as specified by user
310  }
311  findingRecord<EcalTimeCalibErrorsRcd> () ;
312  }
313 
314  // sim pulse shape
315  getSimPulseShapeFromFile_ = ps.getUntrackedParameter<bool>("getSimPulseShapeFromFile",false);
316  producedEcalSimPulseShape_ = ps.getUntrackedParameter<bool>("producedEcalSimPulseShape",true);
317  EBSimPulseShapeFile_ = ps.getUntrackedParameter<std::string>("EBSimPulseShapeFile","") ;
318  EESimPulseShapeFile_ = ps.getUntrackedParameter<std::string>("EESimPulseShapeFile","") ;
319  APDSimPulseShapeFile_ = ps.getUntrackedParameter<std::string>("APDSimPulseShapeFile","") ;
320 
321  if (producedEcalSimPulseShape_) { // user asks to produce constants
323  findingRecord<EcalSimPulseShapeRcd> () ;
324  }
325 
326 
327  // cluster corrections
328  producedEcalClusterLocalContCorrParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterLocalContCorrParameters", false);
329  producedEcalClusterCrackCorrParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterCrackCorrParameters", false);
330  producedEcalClusterEnergyCorrectionParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterEnergyCorrectionParameters", false);
331  producedEcalClusterEnergyUncertaintyParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterEnergyUncertaintyParameters", false);
332  producedEcalClusterEnergyCorrectionObjectSpecificParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterEnergyCorrectionObjectSpecificParameters", false);
333  if ( producedEcalClusterLocalContCorrParameters_ ) {
335  findingRecord<EcalClusterLocalContCorrParametersRcd>();
336  }
337  if ( producedEcalClusterCrackCorrParameters_ ) {
339  findingRecord<EcalClusterCrackCorrParametersRcd>();
340  }
341  if ( producedEcalClusterEnergyCorrectionParameters_ ) {
343  findingRecord<EcalClusterEnergyCorrectionParametersRcd>();
344  }
345  if ( producedEcalClusterEnergyUncertaintyParameters_ ) {
347  findingRecord<EcalClusterEnergyUncertaintyParametersRcd>();
348  }
349  if ( producedEcalClusterEnergyCorrectionObjectSpecificParameters_ ) {
351  findingRecord<EcalClusterEnergyCorrectionObjectSpecificParametersRcd>();
352  }
353 
354  // laser correction
355  producedEcalLaserCorrection_ = ps.getUntrackedParameter<bool>("producedEcalLaserCorrection",true);
356  if (producedEcalLaserCorrection_) { // user asks to produce constants
357  // set all constants to 1. or smear as specified by user
359  findingRecord<EcalLaserAlphasRcd> () ;
360  getLaserAlphaFromFileEB_ = ps.getUntrackedParameter<bool>("getLaserAlphaFromFileEB",false);
361  getLaserAlphaFromFileEE_ = ps.getUntrackedParameter<bool>("getLaserAlphaFromFileEE",false);
362  getLaserAlphaFromTypeEB_ = ps.getUntrackedParameter<bool>("getLaserAlphaFromTypeEB",false);
363  getLaserAlphaFromTypeEE_ = ps.getUntrackedParameter<bool>("getLaserAlphaFromTypeEE",false);
364  std::cout << " getLaserAlphaFromFileEB_ " << getLaserAlphaFromFileEB_ << std::endl;
365  std::cout << " getLaserAlphaFromFileEE_ " << getLaserAlphaFromFileEE_ << std::endl;
366  std::cout << " getLaserAlphaFromTypeEB_ " << getLaserAlphaFromTypeEB_ << std::endl;
367  std::cout << " getLaserAlphaFromTypeEE_ " << getLaserAlphaFromTypeEE_ << std::endl;
368  if(getLaserAlphaFromFileEB_) {
369  EBLaserAlphaFile_ = ps.getUntrackedParameter<std::string>("EBLaserAlphaFile",path+"EBLaserAlpha.txt"); // file is used to read the alphas
370  }
371  if(getLaserAlphaFromFileEE_) {
372  EELaserAlphaFile_ = ps.getUntrackedParameter<std::string>("EELaserAlphaFile",path+"EELaserAlpha.txt"); // file is used to read the alphas
373  }
374  if(getLaserAlphaFromTypeEB_) {
375  laserAlphaMeanEBR_ = ps.getUntrackedParameter<double>("laserAlphaMeanEBR",1.55); // alpha russian crystals in EB
376  laserAlphaMeanEBC_ = ps.getUntrackedParameter<double>("laserAlphaMeanEBC",1.00); // alpha chinese crystals in EB
377  EBLaserAlphaFile_ = ps.getUntrackedParameter<std::string>("EBLaserAlphaFile",path+"EBLaserAlpha.txt"); // file to find out which one is russian/chinese
378  }
379  if(getLaserAlphaFromTypeEE_) {
380  laserAlphaMeanEER_ = ps.getUntrackedParameter<double>("laserAlphaMeanEER",1.16); // alpha russian crystals in EE
381  laserAlphaMeanEEC_ = ps.getUntrackedParameter<double>("laserAlphaMeanEEC",1.00); // alpha chinese crystals in EE
382  EELaserAlphaFile_ = ps.getUntrackedParameter<std::string>("EELaserAlphaFile",path+"EELaserAlpha.txt"); // file is used to find out which one is russian or chinese
383  }
385  findingRecord<EcalLaserAPDPNRatiosRefRcd> () ;
387  findingRecord<EcalLaserAPDPNRatiosRcd> () ;
388  }
389 
390  // channel status
391  producedEcalChannelStatus_ = ps.getUntrackedParameter<bool>("producedEcalChannelStatus",true);
392  channelStatusFile_ = ps.getUntrackedParameter<std::string>("channelStatusFile","");
393 
394  if ( producedEcalChannelStatus_ ) {
395  if ( !channelStatusFile_.empty() ) { // if file provided read channel map
397  } else { // set all channels to working -- FIXME might be changed
399  }
400  findingRecord<EcalChannelStatusRcd>();
401  }
402  // DQM channel status
403  producedEcalDQMChannelStatus_ = ps.getUntrackedParameter<bool>("producedEcalDQMChannelStatus",true);
404  if ( producedEcalDQMChannelStatus_ ) {
406  findingRecord<EcalDQMChannelStatusRcd>();
407  }
408  // DCS Tower status
409  producedEcalDCSTowerStatus_ = ps.getUntrackedParameter<bool>("producedEcalDCSTowerStatus",true);
410  if ( producedEcalDCSTowerStatus_ ) {
412  findingRecord<EcalDCSTowerStatusRcd>();
413  }
414  // DAQ Tower status
415  producedEcalDAQTowerStatus_ = ps.getUntrackedParameter<bool>("producedEcalDAQTowerStatus",true);
416  if ( producedEcalDAQTowerStatus_ ) {
418  findingRecord<EcalDAQTowerStatusRcd>();
419  }
420  // DQM Tower status
421  producedEcalDQMTowerStatus_ = ps.getUntrackedParameter<bool>("producedEcalDQMTowerStatus",true);
422  if ( producedEcalDQMTowerStatus_ ) {
424  findingRecord<EcalDQMTowerStatusRcd>();
425  }
426 
427  // trigger channel status
428  producedEcalTrgChannelStatus_ = ps.getUntrackedParameter<bool>("producedEcalTrgChannelStatus",true);
429  trgChannelStatusFile_ = ps.getUntrackedParameter<std::string>("trgChannelStatusFile","");
430 
431  if ( producedEcalTrgChannelStatus_ ) {
432  if ( !trgChannelStatusFile_.empty() ) { // if file provided read channel map
434  } else { // set all channels to working -- FIXME might be changed
436  }
437  findingRecord<EcalTPGCrystalStatusRcd>();
438  }
439 
440  // Alignment
441  producedEcalAlignmentEB_ = ps.getUntrackedParameter<bool>("producedEcalAlignmentEB",true);
442  if ( producedEcalAlignmentEB_ ) {
444  findingRecord<EBAlignmentRcd>();
445  }
446  producedEcalAlignmentEE_ = ps.getUntrackedParameter<bool>("producedEcalAlignmentEE",true);
447  if ( producedEcalAlignmentEE_ ) {
449  findingRecord<EEAlignmentRcd>();
450  }
451  producedEcalAlignmentES_ = ps.getUntrackedParameter<bool>("producedEcalAlignmentES",true);
452  if ( producedEcalAlignmentES_ ) {
454  findingRecord<ESAlignmentRcd>();
455  }
456  //Tell Finder what records we find
457  if (producedEcalPedestals_) findingRecord<EcalPedestalsRcd>();
458 
459  if (producedEcalWeights_) {
460  findingRecord<EcalWeightXtalGroupsRcd>();
461  findingRecord<EcalTBWeightsRcd>();
462  }
463 
464  if (producedEcalGainRatios_) findingRecord<EcalGainRatiosRcd>();
465 
466  if (producedEcalADCToGeVConstant_) findingRecord<EcalADCToGeVConstantRcd>();
467 
468  producedEcalSampleMask_ = ps.getUntrackedParameter<bool>("producedEcalSampleMask",true);
469  if (producedEcalSampleMask_) {
471  findingRecord<EcalSampleMaskRcd>();
472  }
473  producedEcalTimeBiasCorrections_ = ps.getUntrackedParameter<bool>("producedEcalTimeBiasCorrections", false);
474  if (producedEcalTimeBiasCorrections_) {
476  findingRecord<EcalTimeBiasCorrectionsRcd>();
477  }
478  producedEcalSamplesCorrelation_ = ps.getUntrackedParameter<bool>("producedEcalSamplesCorrelation", false);
479  if (producedEcalSamplesCorrelation_) {
481  findingRecord<EcalSamplesCorrelationRcd>();
482  getSamplesCorrelationFromFile_ = ps.getUntrackedParameter<bool>("getSamplesCorrelationFromFile",false);
483  if(getSamplesCorrelationFromFile_) {
484  SamplesCorrelationFile_ = ps.getUntrackedParameter<std::string>("SamplesCorrelationFile","EcalSamplesCorrelation.txt");
485  }
486  }
487 }
488 
490 {
491 }
492 
493 //
494 // member functions
495 //
496 void
498  const edm::IOVSyncValue& iTime,
499  edm::ValidityInterval& oValidity)
500 {
501  if(verbose_>=1) std::cout << "EcalTrivialConditionRetriever::setIntervalFor(): record key = " << rk.name() << "\ttime: " << iTime.time().value() << std::endl;
502  //For right now, we will just use an infinite interval of validity
504 }
505 
506 //produce methods
507 std::unique_ptr<EcalPedestals>
509  auto peds = std::make_unique<EcalPedestals>();
510  EcalPedestals::Item EBitem;
511  EcalPedestals::Item EEitem;
512 
513  EBitem.mean_x1 = EBpedMeanX1_;
514  EBitem.rms_x1 = EBpedRMSX1_;
515  EBitem.mean_x6 = EBpedMeanX6_;
516  EBitem.rms_x6 = EBpedRMSX6_;
517  EBitem.mean_x12 = EBpedMeanX12_;
518  EBitem.rms_x12 = EBpedRMSX12_;
519 
520  EEitem.mean_x1 = EEpedMeanX1_;
521  EEitem.rms_x1 = EEpedRMSX1_;
522  EEitem.mean_x6 = EEpedMeanX6_;
523  EEitem.rms_x6 = EEpedRMSX6_;
524  EEitem.mean_x12 = EEpedMeanX12_;
525  EEitem.rms_x12 = EEpedRMSX12_;
526 
527 
528 
529 
530 
531  for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
532  if(iEta==0) continue;
533 
534  if(totLumi_>0) {
535  double eta=EBDetId::approxEta(EBDetId(iEta,1));
536 
537  EnergyResolutionVsLumi ageing;
538  ageing.setLumi(totLumi_);
539  ageing.setInstLumi(instLumi_);
540  eta = fabs(eta);
541  double noisefactor= ageing.calcnoiseIncreaseADC(eta);
542 
543 
544  EBitem.rms_x1 = EBpedRMSX1_*noisefactor;
545  EBitem.rms_x6 = EBpedRMSX6_*noisefactor;
546  EBitem.rms_x12 = EBpedRMSX12_*noisefactor;
547  std::cout << "rms ped at eta:"<< eta<<" ="<< EBitem.rms_x12 << std::endl;
548  }
549 
550 
551 
552  for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
553  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
554  if (EBDetId::validDetId(iEta,iPhi))
555  {
556  EBDetId ebdetid(iEta,iPhi);
557  peds->insert(std::make_pair(ebdetid.rawId(),EBitem));
558  }
559  }
560  }
561 
562  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
563  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
564  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
565  if (EEDetId::validDetId(iX,iY,1))
566  {
567  EEDetId eedetidpos(iX,iY,1);
568  peds->insert(std::make_pair(eedetidpos.rawId(),EEitem));
569  }
570  if(EEDetId::validDetId(iX,iY,-1))
571  {
572  EEDetId eedetidneg(iX,iY,-1);
573  peds->insert(std::make_pair(eedetidneg.rawId(),EEitem));
574  }
575  }
576  }
577 
578  //return std::unique_ptr<EcalPedestals>( peds );
579  return peds;
580 }
581 
582 
583 
584 std::unique_ptr<EcalWeightXtalGroups>
586 {
587  auto xtalGroups = std::make_unique<EcalWeightXtalGroups>();
588  EcalXtalGroupId defaultGroupId(1);
589  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
590  if(ieta==0) continue;
591  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
592  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
593  if (EBDetId::validDetId(ieta,iphi))
594  {
595  EBDetId ebid(ieta,iphi);
596  // xtalGroups->setValue(ebid.rawId(), EcalXtalGroupId(ieta) ); // define rings in eta
597  xtalGroups->setValue(ebid.rawId(), defaultGroupId ); // define rings in eta
598  }
599  }
600  }
601 
602  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
603  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
604  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
605  if (EEDetId::validDetId(iX,iY,1))
606  {
607  EEDetId eedetidpos(iX,iY,1);
608  xtalGroups->setValue(eedetidpos.rawId(), defaultGroupId );
609  }
610  if(EEDetId::validDetId(iX,iY,-1))
611  {
612  EEDetId eedetidneg(iX,iY,-1);
613  xtalGroups->setValue(eedetidneg.rawId(), defaultGroupId );
614  }
615  }
616  }
617  return xtalGroups;
618 }
619 
620 
621 std::unique_ptr<EcalLinearCorrections>
623 {
624  auto ical = std::make_unique<EcalLinearCorrections>();
625 
626  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
627  if(ieta==0) continue;
628  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
629  if (EBDetId::validDetId(ieta,iphi)) {
630  EBDetId ebid(ieta,iphi);
631  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
632 
634  pairAPDPN.p1 = linCorrMean_ + r*linCorrSigma_;
635  pairAPDPN.p2 = linCorrMean_ + r*linCorrSigma_;
636  pairAPDPN.p3 = linCorrMean_ + r*linCorrSigma_;
637  ical->setValue( ebid, pairAPDPN );
638  }
639  }
640  }
641 
642  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
643  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
644  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
645  if (EEDetId::validDetId(iX,iY,1)) {
646  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
647  EEDetId eedetidpos(iX,iY,1);
648 
650  pairAPDPN.p1 = linCorrMean_ + r*linCorrSigma_;
651  pairAPDPN.p2 = linCorrMean_ + r*linCorrSigma_;
652  pairAPDPN.p3 = linCorrMean_ + r*linCorrSigma_;
653 
654  ical->setValue( eedetidpos, pairAPDPN );
655  }
656 
657  if (EEDetId::validDetId(iX,iY,-1)) {
658  double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
659  EEDetId eedetidneg(iX,iY,-1);
660 
662  pairAPDPN.p1 = linCorrMean_ + r1*linCorrSigma_;
663  pairAPDPN.p2 = linCorrMean_ + r1*linCorrSigma_;
664  pairAPDPN.p3 = linCorrMean_ + r1*linCorrSigma_;
665 
666  ical->setValue( eedetidneg, pairAPDPN );
667  }
668  }
669  }
670 
672  // for(int i=1; i<=92; i++){
673  for(int i=0; i<92; i++){
674  TimeStamp.t1 = Timestamp(linearTime1_);
675  if(linearTime2_ == 0 ){
676  TimeStamp.t2 = Timestamp(edm::Timestamp::endOfTime().value());
677  } else {
678  TimeStamp.t2 = Timestamp(linearTime2_);
679  }
680  if(linearTime3_ == 0 ){
681  TimeStamp.t3 = Timestamp(edm::Timestamp::endOfTime().value());
682  } else {
683  TimeStamp.t3 = Timestamp(linearTime3_);
684  }
685 
686  ical->setTime( i, TimeStamp );
687  }
688 
689  return ical;
690 
691 }
692 
693 //------------------------------
694 
695 std::unique_ptr<EcalIntercalibConstants>
697 {
698  auto ical = std::make_unique<EcalIntercalibConstants>();
699 
700  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
701  if(ieta==0) continue;
702  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
703  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
704  if (EBDetId::validDetId(ieta,iphi))
705  {
706  EBDetId ebid(ieta,iphi);
707  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
708  ical->setValue( ebid.rawId(), intercalibConstantMean_ + r*intercalibConstantSigma_ );
709  }
710  }
711  }
712 
713  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
714  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
715  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
716  if (EEDetId::validDetId(iX,iY,1))
717  {
718  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
719  EEDetId eedetidpos(iX,iY,1);
720  ical->setValue( eedetidpos.rawId(), intercalibConstantMean_ + r*intercalibConstantSigma_ );
721  }
722  if(EEDetId::validDetId(iX,iY,-1))
723  {
724  double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
725  EEDetId eedetidneg(iX,iY,-1);
726  ical->setValue( eedetidneg.rawId(), intercalibConstantMean_ + r1*intercalibConstantSigma_ );
727  }
728  }
729  }
730 
731  return ical;
732 }
733 
734 std::unique_ptr<EcalIntercalibConstantsMC>
736 {
737  auto ical = std::make_unique<EcalIntercalibConstantsMC>();
738 
739  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
740  if(ieta==0) continue;
741  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
742  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
743  if (EBDetId::validDetId(ieta,iphi))
744  {
745  EBDetId ebid(ieta,iphi);
746  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
747  ical->setValue( ebid.rawId(), intercalibConstantMeanMC_ + r*intercalibConstantSigmaMC_ );
748  }
749  }
750  }
751 
752  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
753  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
754  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
755  if (EEDetId::validDetId(iX,iY,1))
756  {
757  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
758  EEDetId eedetidpos(iX,iY,1);
759  ical->setValue( eedetidpos.rawId(), intercalibConstantMeanMC_ + r*intercalibConstantSigmaMC_ );
760  }
761  if(EEDetId::validDetId(iX,iY,-1))
762  {
763  double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
764  EEDetId eedetidneg(iX,iY,-1);
765  ical->setValue( eedetidneg.rawId(), intercalibConstantMeanMC_ + r1*intercalibConstantSigmaMC_ );
766  }
767  }
768  }
769 
770  return ical;
771 }
772 
773 std::unique_ptr<EcalIntercalibErrors>
775 {
776  auto ical = std::make_unique<EcalIntercalibErrors>();
777 
778  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
779  if(ieta==0) continue;
780  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
781  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
782  if (EBDetId::validDetId(ieta,iphi))
783  {
784  EBDetId ebid(ieta,iphi);
785  ical->setValue( ebid.rawId(), intercalibErrorMean_);
786  }
787  }
788  }
789 
790  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
791  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
792  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
793  if (EEDetId::validDetId(iX,iY,1))
794  {
795  EEDetId eedetidpos(iX,iY,1);
796  ical->setValue( eedetidpos.rawId(), intercalibErrorMean_ );
797  }
798  if(EEDetId::validDetId(iX,iY,-1))
799  {
800  EEDetId eedetidneg(iX,iY,-1);
801  ical->setValue( eedetidneg.rawId(), intercalibErrorMean_ );
802  }
803  }
804  }
805 
806  return ical;
807 }
808 
809 std::unique_ptr<EcalTimeCalibConstants>
811 {
812  auto ical = std::make_unique<EcalTimeCalibConstants>();
813 
814  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
815  if(ieta==0) continue;
816  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
817  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
818  if (EBDetId::validDetId(ieta,iphi))
819  {
820  EBDetId ebid(ieta,iphi);
821  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
822  ical->setValue( ebid.rawId(), timeCalibConstantMean_ + r*timeCalibConstantSigma_ );
823  }
824  }
825  }
826 
827  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
828  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
829  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
830  if (EEDetId::validDetId(iX,iY,1))
831  {
832  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
833  EEDetId eedetidpos(iX,iY,1);
834  ical->setValue( eedetidpos.rawId(), timeCalibConstantMean_ + r*timeCalibConstantSigma_ );
835  }
836  if(EEDetId::validDetId(iX,iY,-1))
837  {
838  double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
839  EEDetId eedetidneg(iX,iY,-1);
840  ical->setValue( eedetidneg.rawId(), timeCalibConstantMean_ + r1*timeCalibConstantSigma_ );
841  }
842  }
843  }
844 
845  return ical;
846 }
847 
848 std::unique_ptr<EcalTimeCalibErrors>
850 {
851  auto ical = std::make_unique<EcalTimeCalibErrors>();
852 
853  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
854  if(ieta==0) continue;
855  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
856  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
857  if (EBDetId::validDetId(ieta,iphi))
858  {
859  EBDetId ebid(ieta,iphi);
860  ical->setValue( ebid.rawId(), timeCalibErrorMean_);
861  }
862  }
863  }
864 
865  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
866  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
867  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
868  if (EEDetId::validDetId(iX,iY,1))
869  {
870  EEDetId eedetidpos(iX,iY,1);
871  ical->setValue( eedetidpos.rawId(), timeCalibErrorMean_ );
872  }
873  if(EEDetId::validDetId(iX,iY,-1))
874  {
875  EEDetId eedetidneg(iX,iY,-1);
876  ical->setValue( eedetidneg.rawId(), timeCalibErrorMean_ );
877  }
878  }
879  }
880 
881  return ical;
882 }
883 
884 std::unique_ptr<EcalTimeOffsetConstant>
886 {
887  std::cout << " produceEcalTimeOffsetConstant: " << std::endl;
888  std::cout << " EB " << timeOffsetEBConstant_ << " EE " << timeOffsetEEConstant_<< std::endl;
889  return std::make_unique<EcalTimeOffsetConstant>(timeOffsetEBConstant_,timeOffsetEEConstant_);
890 }
891 
892 std::unique_ptr<EcalGainRatios>
894 {
895  auto gratio = std::make_unique<EcalGainRatios>();
897  gr.setGain12Over6( gainRatio12over6_ );
898  gr.setGain6Over1( gainRatio6over1_ );
899 
900  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
901  if(ieta==0) continue;
902  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
903  if (EBDetId::validDetId(ieta,iphi))
904  {
905  EBDetId ebid(ieta,iphi);
906  gratio->setValue( ebid.rawId(), gr );
907  }
908  }
909  }
910 
911  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
912  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
913  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
914  if (EEDetId::validDetId(iX,iY,1))
915  {
916  EEDetId eedetidpos(iX,iY,1);
917  gratio->setValue( eedetidpos.rawId(), gr );
918  }
919  if (EEDetId::validDetId(iX,iY,-1))
920  {
921  EEDetId eedetidneg(iX,iY,-1);
922  gratio->setValue( eedetidneg.rawId(), gr );
923  }
924  }
925  }
926 
927  return gratio;
928 }
929 
930 std::unique_ptr<EcalADCToGeVConstant>
932 {
933  return std::make_unique<EcalADCToGeVConstant>(adcToGeVEBConstant_,adcToGeVEEConstant_);
934 }
935 
936 std::unique_ptr<EcalTBWeights>
938 {
939  // create weights for the test-beam
940  auto tbwgt = std::make_unique<EcalTBWeights>();
941 
942  // create weights for each distinct group ID
943  // int nMaxTDC = 10;
944 // for(int igrp=-EBDetId::MAX_IETA; igrp<=EBDetId::MAX_IETA; ++igrp) {
945 // if(igrp==0) continue;
946  int igrp=1;
947  for(int itdc=1; itdc<=nTDCbins_; ++itdc) {
948  // generate random number
949  // double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
950 
951  // make a new set of weights
952  EcalWeightSet wgt;
953  //typedef std::vector< std::vector<EcalWeight> > EcalWeightSet::EcalWeightMatrix;
956 
957 // if(verbose_>=1) {
958 // std::cout << "initial size of mat1: " << mat1.size() << std::endl;
959 // std::cout << "initial size of mat2: " << mat2.size() << std::endl;
960 // }
961 
962  // generate random numbers to use as weights
977  // use values provided by user
978  mat1.Place_in_row(amplWeights_[itdc-1],0,0);
979  mat1.Place_in_row(pedWeights_[itdc-1],1,0);
980  mat1.Place_in_row(jittWeights_[itdc-1],2,0);
981 
982  // wdights after gain switch
983  mat2.Place_in_row(amplWeightsAft_[itdc-1],0,0);
984  mat2.Place_in_row(pedWeightsAft_[itdc-1],1,0);
985  mat2.Place_in_row(jittWeightsAft_[itdc-1],2,0);
986 
987  // fill the chi2 matrcies with random numbers
988  // r = (double)std::rand()/( double(RAND_MAX)+double(1) );
991  mat3=chi2Matrix_[itdc-1];
992  mat4=chi2MatrixAft_[itdc-1];
993 
994  // for(size_t i=0; i<10; ++i)
995  // {
996  // mat3.push_back(chi2Matrix_[itdc-1][i]);
997  // mat4.push_back(chi2MatrixAft_[itdc-1][i]);
998  // }
999  // std::vector<EcalWeight> tv1, tv2;
1000  // for(size_t j=0; j<10; ++j) {
1001  // double ww = igrp*itdc*r + i*10. + j;
1002  // tv1.push_back( EcalWeight(1000+ww) );
1003  // tv2.push_back( EcalWeight(1000+100+ww) );
1004  // }
1005 
1006 
1007 
1008 
1009 // if(verbose_>=1) {
1010 // std::cout << "group: " << igrp << " TDC: " << itdc
1011 // << " mat1: " << mat1.size() << " mat2: " << mat2.size()
1012 // << " mat3: " << mat3.size() << " mat4: " << mat4.size()
1013 // << std::endl;
1014 // }
1015 
1016  // put the weight in the container
1017  tbwgt->setValue(std::make_pair(igrp,itdc), wgt);
1018  }
1019  // }
1020  return tbwgt;
1021 }
1022 
1023 
1024 
1025 // cluster functions/corrections
1026 std::unique_ptr<EcalClusterLocalContCorrParameters>
1028 {
1029  auto ipar = std::make_unique<EcalClusterLocalContCorrParameters>();
1030  for (size_t i = 0; i < localContCorrParameters_.size(); ++i ) {
1031  ipar->params().push_back( localContCorrParameters_[i] );
1032  }
1033  return ipar;
1034 }
1035 std::unique_ptr<EcalClusterCrackCorrParameters>
1037 {
1038  auto ipar = std::make_unique<EcalClusterCrackCorrParameters>();
1039  for (size_t i = 0; i < crackCorrParameters_.size(); ++i ) {
1040  ipar->params().push_back( crackCorrParameters_[i] );
1041  }
1042  return ipar;
1043 }
1044 std::unique_ptr<EcalClusterEnergyCorrectionParameters>
1046 {
1047  auto ipar = std::make_unique<EcalClusterEnergyCorrectionParameters>();
1048  for (size_t i = 0; i < energyCorrectionParameters_.size(); ++i ) {
1049  ipar->params().push_back( energyCorrectionParameters_[i] );
1050  }
1051  return ipar;
1052 }
1053 std::unique_ptr<EcalClusterEnergyUncertaintyParameters>
1055 {
1056  auto ipar = std::make_unique<EcalClusterEnergyUncertaintyParameters>();
1057  for (size_t i = 0; i < energyUncertaintyParameters_.size(); ++i ) {
1058  ipar->params().push_back( energyUncertaintyParameters_[i] );
1059  }
1060  return ipar;
1061 }
1062 std::unique_ptr<EcalClusterEnergyCorrectionObjectSpecificParameters>
1064 {
1065  auto ipar = std::make_unique<EcalClusterEnergyCorrectionObjectSpecificParameters>();
1066  for (size_t i = 0; i < energyCorrectionObjectSpecificParameters_.size(); ++i ) {
1067  ipar->params().push_back( energyCorrectionObjectSpecificParameters_[i] );
1068  }
1069  return ipar;
1070 }
1071 
1072 
1073 // laser records
1074 std::unique_ptr<EcalLaserAlphas>
1076 {
1077 
1078  std::cout << " produceEcalLaserAlphas " << std::endl;
1079  auto ical = std::make_unique<EcalLaserAlphas>();
1080 
1081  // get Barrel alpha from type
1082  if(getLaserAlphaFromTypeEB_) {
1083  std::ifstream fEB(edm::FileInPath(EBLaserAlphaFile_).fullPath().c_str());
1084  int SMpos[36] = {-10, 4, -7, -16, 6, -9, 11, -17, 5, 18, 3, -8, 1, -3, -13, 14, -6, 2,
1085  15, -18, 8, 17, -2, 9, -1, 10, -5, 7, -12, -11, 16, -4, -15, -14, 12, 13};
1086  // check!
1087  int SMCal[36] = {12,17,10, 1, 8, 4,27,20,23,25, 6,34,35,15,18,30,21, 9,
1088  24,22,13,31,26,16, 2,11, 5, 0,29,28,14,33,32, 3, 7,19};
1089 
1090  for(int SMcons = 0; SMcons < 36; SMcons++) {
1091  int SM = SMpos[SMcons];
1092  if(SM < 0) SM = 17 + abs(SM);
1093  else SM--;
1094  if(SMCal[SM] != SMcons)
1095  std::cout << " SM pb : read SM " << SMcons<< " SMpos " << SM
1096  << " SMCal " << SMCal[SM] << std::endl;
1097  }
1098 
1100  int readSM, pos, bar, bar2;
1101  float alpha = 0;
1102  for(int SMcons = 0; SMcons < 36; SMcons++) {
1103  int SM = SMpos[SMcons];
1104  for(int ic = 0; ic < 1700; ic++) {
1105  fEB >> readSM >> pos >> bar >> bar2 >> type >> batch;
1106 
1107  if(readSM != SMcons || pos != ic + 1)
1108  std::cout << " barrel read pb read SM " << readSM << " const SM " << SMcons
1109  << " read pos " << pos << " ic " << ic << std::endl;
1110  if(SM < 0) SM = 18 + abs(SM);
1111  EBDetId ebdetid(SM, pos, EBDetId::SMCRYSTALMODE);
1112  if(bar == 33101 || bar == 30301 )
1113  alpha = laserAlphaMeanEBR_;
1114  else if(bar == 33106) {
1115  if(bar2 <= 2000)
1116  alpha = laserAlphaMeanEBC_;
1117  else {
1118  std::cout << " problem with barcode first " << bar << " last " << bar2
1119  << " read SM " << readSM << " read pos " << pos << std::endl;
1120  alpha = laserAlphaMeanEBR_;
1121  }
1122  }
1123  ical->setValue( ebdetid, alpha );
1124 
1125  if( ic==1650 ){
1126  std::cout << " ic/alpha "<<ic<<"/"<<alpha<<std::endl;
1127  }
1128 
1129  }
1130  } // loop over SMcons
1131  fEB.close();
1132  // end laserAlpha from type
1133  } else if(getLaserAlphaFromFileEB_) {
1134  // laser alpha from file
1135  std::cout <<"Laser alpha for EB will be taken from File"<<std::endl;
1136  int ieta, iphi;
1137  float alpha;
1138  std::ifstream fEB(edm::FileInPath(EBLaserAlphaFile_).fullPath().c_str());
1139  // std::ifstream fEB(EBLaserAlphaFile_.c_str());
1140  for(int ic = 0; ic < 61200; ic++) {
1141  fEB >> ieta>> iphi>>alpha;
1142 
1143  if (EBDetId::validDetId(ieta,iphi)) {
1144  EBDetId ebid(ieta,iphi);
1145  ical->setValue( ebid, alpha );
1146  std::cout << " ieta/iphi/alpha "<<ieta<<"/"<<iphi<<"/"<<alpha<<std::endl;
1147  }
1148  if( ieta==10 ){
1149  std::cout << "I will print some alphas from the file... ieta/iphi/alpha "<<ieta<<"/"<<iphi<<"/"<<alpha<<std::endl;
1150  }
1151  }
1152  fEB.close();
1153 
1154  } else {
1155  // laser alpha from mean and smearing
1156  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
1157  if(ieta==0) continue;
1158  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
1159  if (EBDetId::validDetId(ieta,iphi)) {
1160  EBDetId ebid(ieta,iphi);
1161  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
1162  ical->setValue( ebid, laserAlphaMean_ + r*laserAlphaSigma_ );
1163  }
1164  } // loop over iphi
1165  } // loop over ieta
1166  } // do not read a file
1167 
1168  std::cout << " produceEcalLaserAlphas EE" << std::endl;
1169  if(getLaserAlphaFromTypeEE_) {
1170  std::ifstream fEE(edm::FileInPath(EELaserAlphaFile_).fullPath().c_str());
1171 
1172  for(int crystal = 0; crystal < 14648; crystal++) {
1173  int x, y ,z, bid, bar, bar2;
1174  float LY, alpha = 0;
1175  fEE >> z >> x >> y >> LY >> bid >> bar >> bar2;
1176  if(x < 1 || x > 100 || y < 1 || y > 100)
1177  std::cout << " wrong coordinates for barcode " << bar
1178  << " x " << x << " y " << y << " z " << z << std::endl;
1179  else {
1180  if(bar == 33201 || (bar == 30399 && bar2 < 568))
1181  alpha = laserAlphaMeanEER_;
1182  else if((bar == 33106 && bar2 > 2000 && bar2 < 4669)
1183  || (bar == 30399 && bar2 > 567))
1184  alpha = laserAlphaMeanEEC_;
1185  else {
1186  std::cout << " problem with barcode " << bar << " " << bar2
1187  << " x " << x << " y " << y << " z " << z << std::endl;
1188  alpha = laserAlphaMeanEER_;
1189  }
1190  }
1191  if (EEDetId::validDetId(x, y, z)) {
1192  EEDetId eedetidpos(x, y, z);
1193  ical->setValue( eedetidpos, alpha );
1194  }
1195  else // should not occur
1196  std::cout << " problem with EEDetId " << " x " << x << " y " << y << " z " << z << std::endl;
1197  }
1198  fEE.close();
1199 
1200  // end laserAlpha from type EE
1201 
1202  } else if (getLaserAlphaFromFileEE_) {
1203 
1204  std::ifstream fEE(edm::FileInPath(EELaserAlphaFile_).fullPath().c_str());
1205 
1206  for(int crystal = 0; crystal < 14648; crystal++) {
1207  int x, y ,z;
1208  float alpha = 1;
1209  fEE >> z >> x >> y >> alpha;
1210  if(x < 1 || x > 100 || y < 1 || y > 100 || z==0 || z>1 || z<-1 ) {
1211  std::cout << "ERROR: wrong coordinates for crystal "
1212  << " x " << x << " y " << y << " z " << z << std::endl;
1213  std::cout << " the format of the file should be z x y alpha " << std::endl;
1214  } else {
1215  if (EEDetId::validDetId(x, y, z)) {
1216  EEDetId eedetidpos(x, y, z);
1217  ical->setValue( eedetidpos, alpha );
1218  }
1219  else // should not occur
1220  std::cout << " problem with EEDetId " << " x " << x << " y " << y << " z " << z << std::endl;
1221  }
1222  }
1223  fEE.close();
1224 
1225  // end laser alpha from file EE
1226  } else {
1227  // alphas from python config file
1228  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
1229  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
1230  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
1231  if (EEDetId::validDetId(iX,iY,1)) {
1232  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
1233  EEDetId eedetidpos(iX,iY,1);
1234  ical->setValue( eedetidpos, laserAlphaMean_ + r*laserAlphaSigma_ );
1235  }
1236  if (EEDetId::validDetId(iX,iY,-1)) {
1237  double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
1238  EEDetId eedetidneg(iX,iY,-1);
1239  ical->setValue( eedetidneg, laserAlphaMean_ + r1*laserAlphaSigma_ );
1240  }
1241  } // loop over iY
1242  } // loop over iX
1243  }
1244 
1245  return ical;
1246 }
1247 
1248 
1249 std::unique_ptr<EcalLaserAPDPNRatiosRef>
1251 {
1252  auto ical = std::make_unique<EcalLaserAPDPNRatiosRef>();
1253  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
1254  if(ieta==0) continue;
1255  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
1256  if (EBDetId::validDetId(ieta,iphi)) {
1257  EBDetId ebid(ieta,iphi);
1258  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
1259  ical->setValue( ebid, laserAPDPNRefMean_ + r*laserAPDPNRefSigma_ );
1260  }
1261  }
1262  }
1263 
1264  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
1265  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
1266  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
1267  if (EEDetId::validDetId(iX,iY,1)) {
1268  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
1269  EEDetId eedetidpos(iX,iY,1);
1270  ical->setValue( eedetidpos, laserAPDPNRefMean_ + r*laserAPDPNRefSigma_ );
1271  }
1272 
1273  if (EEDetId::validDetId(iX,iY,-1)) {
1274  double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
1275  EEDetId eedetidneg(iX,iY,-1);
1276  ical->setValue( eedetidneg, laserAPDPNRefMean_ + r1*laserAPDPNRefSigma_ );
1277  }
1278  }
1279  }
1280 
1281  return ical;
1282 }
1283 
1284 
1285 std::unique_ptr<EcalLaserAPDPNRatios>
1287 {
1288  EnergyResolutionVsLumi ageing;
1289  ageing.setLumi(totLumi_);
1290  ageing.setInstLumi(instLumi_);
1291 
1292 
1293  auto ical = std::make_unique<EcalLaserAPDPNRatios>();
1294  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
1295  if(ieta==0) continue;
1296 
1297 
1298 
1299  double eta=EBDetId::approxEta(EBDetId(ieta,1));
1300 
1301  eta = fabs(eta);
1302  double drop=ageing.calcampDropTotal(eta);
1303  std::cout<<"EB at eta="<<eta<<" dropping by "<<drop<<std::endl;
1304 
1305  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
1306  if (EBDetId::validDetId(ieta,iphi)) {
1307  EBDetId ebid(ieta,iphi);
1308  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
1309 
1311  pairAPDPN.p1 = laserAPDPNMean_*drop + r*laserAPDPNSigma_;
1312  pairAPDPN.p2 = laserAPDPNMean_*drop + r*laserAPDPNSigma_;
1313  pairAPDPN.p3 = laserAPDPNMean_*drop + r*laserAPDPNSigma_;
1314  ical->setValue( ebid, pairAPDPN );
1315  }
1316  }
1317  }
1318 
1319 
1320  std::cout<<"----- EE -----"<<std::endl;
1321 
1322  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
1323  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
1324  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
1325 
1326 
1327  if (EEDetId::validDetId(iX,iY,1)) {
1328  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
1329  EEDetId eedetidpos(iX,iY,1);
1330 
1331  double eta= -log(tan(0.5*atan(sqrt((iX-50.0)
1332  *(iX-50.0)+
1333  (iY-50.0)*
1334  (iY-50.0))
1335  *2.98/328.)));
1336  eta = fabs(eta);
1337  double drop=ageing.calcampDropTotal(eta);
1338  if(iX==50) std::cout<<"EE at eta="<<eta<<" dropping by "<<drop<<std::endl;
1339 
1340 
1342  pairAPDPN.p1 = laserAPDPNMean_*drop + r*laserAPDPNSigma_;
1343  pairAPDPN.p2 = laserAPDPNMean_*drop + r*laserAPDPNSigma_;
1344  pairAPDPN.p3 = laserAPDPNMean_*drop + r*laserAPDPNSigma_;
1345  ical->setValue( eedetidpos, pairAPDPN );
1346  }
1347 
1348  if (EEDetId::validDetId(iX,iY,-1)) {
1349  double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
1350  EEDetId eedetidneg(iX,iY,-1);
1351 
1352  double eta= -log(tan(0.5*atan(sqrt((iX-50.0)*(iX-50.0)+(iY-50.0)*(iY-50.0))*2.98/328.)));
1353  eta = fabs(eta);
1354  double drop=ageing.calcampDropTotal(eta);
1355  if(iX==50) std::cout<<"EE at eta="<<eta<<" dropping by "<<drop<<std::endl;
1356 
1357 
1359  pairAPDPN.p1 = laserAPDPNMean_*drop + r1*laserAPDPNSigma_;
1360  pairAPDPN.p2 = laserAPDPNMean_*drop + r1*laserAPDPNSigma_;
1361  pairAPDPN.p3 = laserAPDPNMean_*drop + r1*laserAPDPNSigma_;
1362  ical->setValue( eedetidneg, pairAPDPN );
1363  }
1364  }
1365  }
1366 
1368  // for(int i=1; i<=92; i++){
1369  for(int i=0; i<92; i++){
1370  TimeStamp.t1 = Timestamp(laserAPDPNTime1_);
1371  if(laserAPDPNTime2_ == 0 ){
1372  TimeStamp.t2 = Timestamp(edm::Timestamp::endOfTime().value());
1373  } else {
1374  TimeStamp.t2 = Timestamp(laserAPDPNTime2_);
1375  }
1376  if(laserAPDPNTime3_ == 0 ){
1377  TimeStamp.t3 = Timestamp(edm::Timestamp::endOfTime().value());
1378  } else {
1379  TimeStamp.t3 = Timestamp(laserAPDPNTime3_);
1380  }
1381 
1382  ical->setTime( i, TimeStamp );
1383  }
1384 
1385  return ical;
1386 
1387 }
1388 
1389 
1391 {
1392 
1393  std::vector < std::vector<double> > amplwgtv(nTDCbins_);
1394 
1395  if (!getWeightsFromFile_ && nTDCbins_ == 1)
1396  {
1397  std::vector<double> vampl;
1398  //As default using simple 3+1 weights
1399  vampl.push_back( -0.33333 );
1400  vampl.push_back( -0.33333 );
1401  vampl.push_back( -0.33333 );
1402  vampl.push_back( 0. );
1403  vampl.push_back( 0. );
1404  vampl.push_back( 1. );
1405  vampl.push_back( 0. );
1406  vampl.push_back( 0. );
1407  vampl.push_back( 0. );
1408  vampl.push_back( 0. );
1409  amplwgtv[0]= ps.getUntrackedParameter< std::vector<double> >("amplWeights", vampl);
1410  }
1411  else if (getWeightsFromFile_)
1412  {
1413  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading amplitude weights from file " << edm::FileInPath(amplWeightsFile_).fullPath().c_str() ;
1414  std::ifstream amplFile(edm::FileInPath(amplWeightsFile_).fullPath().c_str());
1415  int tdcBin=0;
1416  while (!amplFile.eof() && tdcBin < nTDCbins_)
1417  {
1418  for(int j = 0; j < 10; ++j) {
1419  float ww;
1420  amplFile >> ww;
1421  amplwgtv[tdcBin].push_back(ww);
1422  }
1423  ++tdcBin;
1424  }
1425  assert (tdcBin == nTDCbins_);
1426  //Read from file
1427  }
1428  else
1429  {
1430  //Not supported
1431  edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1432  throw cms::Exception("WrongConfig");
1433  }
1434 
1435 
1436  for (int i=0;i<nTDCbins_;i++)
1437  {
1438  assert(amplwgtv[i].size() == 10);
1439  int j=0;
1440  for(std::vector<double>::const_iterator it = amplwgtv[i].begin(); it != amplwgtv[i].end(); ++it)
1441  {
1442  (amplWeights_[i])[j]=*it;
1443  j++;
1444  }
1445  }
1446 
1447 
1448  std::vector < std::vector<double> > amplwgtvAftGain(nTDCbins_);
1449 
1450  if (!getWeightsFromFile_ && nTDCbins_ == 1 )
1451  {
1452  std::vector<double> vamplAftGain;
1453  vamplAftGain.push_back( 0. );
1454  vamplAftGain.push_back( 0. );
1455  vamplAftGain.push_back( 0. );
1456  vamplAftGain.push_back( 0. );
1457  vamplAftGain.push_back( 0. );
1458  vamplAftGain.push_back( 1. );
1459  vamplAftGain.push_back( 0. );
1460  vamplAftGain.push_back( 0. );
1461  vamplAftGain.push_back( 0. );
1462  vamplAftGain.push_back( 0. );
1463  amplwgtvAftGain[0] = ps.getUntrackedParameter< std::vector<double> >("amplWeightsAftGain", vamplAftGain);
1464  }
1465  else if (getWeightsFromFile_)
1466  {
1467  //Read from file
1468  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading amplitude weights aftre gain switch from file " << edm::FileInPath(amplWeightsAftFile_).fullPath().c_str() ;
1469  std::ifstream amplFile(edm::FileInPath(amplWeightsAftFile_).fullPath().c_str());
1470  int tdcBin=0;
1471  while (!amplFile.eof() && tdcBin < nTDCbins_)
1472  {
1473  for(int j = 0; j < 10; ++j) {
1474  float ww;
1475  amplFile >> ww;
1476  amplwgtvAftGain[tdcBin].push_back(ww);
1477  }
1478  ++tdcBin;
1479  }
1480  assert (tdcBin == nTDCbins_);
1481  }
1482  else
1483  {
1484  //Not supported
1485  edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1486  throw cms::Exception("WrongConfig");
1487  }
1488 
1489  for (int i=0;i<nTDCbins_;i++)
1490  {
1491  assert(amplwgtvAftGain[i].size() == 10);
1492  int j=0;
1493  for(std::vector<double>::const_iterator it = amplwgtvAftGain[i].begin(); it != amplwgtvAftGain[i].end(); ++it) {
1494  (amplWeightsAft_[i])[j]=*it;
1495  j++;
1496  }
1497  }
1498 
1499  // default weights to reco amplitude w/o pedestal subtraction
1500 
1501  std::vector< std::vector<double> > pedwgtv(nTDCbins_);
1502 
1503  if (!getWeightsFromFile_ && nTDCbins_ == 1)
1504  {
1505  std::vector<double> vped;
1506  vped.push_back( 0.33333 );
1507  vped.push_back( 0.33333 );
1508  vped.push_back( 0.33333 );
1509  vped.push_back( 0. );
1510  vped.push_back( 0. );
1511  vped.push_back( 0. );
1512  vped.push_back( 0. );
1513  vped.push_back( 0. );
1514  vped.push_back( 0. );
1515  vped.push_back( 0. );
1516  pedwgtv[0] = ps.getUntrackedParameter< std::vector<double> >("pedWeights", vped);
1517  }
1518  else if (getWeightsFromFile_)
1519  {
1520  //Read from file
1521  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading pedestal weights from file " << edm::FileInPath(pedWeightsFile_).fullPath().c_str() ;
1522  std::ifstream pedFile(edm::FileInPath(pedWeightsFile_).fullPath().c_str());
1523  int tdcBin=0;
1524  while (!pedFile.eof() && tdcBin < nTDCbins_)
1525  {
1526  for(int j = 0; j < 10; ++j) {
1527  float ww;
1528  pedFile >> ww;
1529  pedwgtv[tdcBin].push_back(ww);
1530  }
1531  ++tdcBin;
1532  }
1533  assert (tdcBin == nTDCbins_);
1534  }
1535  else
1536  {
1537  //Not supported
1538  edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1539  throw cms::Exception("WrongConfig");
1540  }
1541 
1542  for (int i=0;i<nTDCbins_;i++)
1543  {
1544  assert(pedwgtv[i].size() == 10);
1545  int j=0;
1546  for(std::vector<double>::const_iterator it = pedwgtv[i].begin(); it != pedwgtv[i].end(); ++it) {
1547  (pedWeights_[i])[j] = *it;
1548  j++;
1549  }
1550  }
1551 
1552  std::vector< std::vector<double> > pedwgtvaft(nTDCbins_);
1553 
1554  if (!getWeightsFromFile_ && nTDCbins_ == 1)
1555  {
1556  std::vector<double> vped;
1557  vped.push_back( 0. );
1558  vped.push_back( 0. );
1559  vped.push_back( 0. );
1560  vped.push_back( 0. );
1561  vped.push_back( 0. );
1562  vped.push_back( 0. );
1563  vped.push_back( 0. );
1564  vped.push_back( 0. );
1565  vped.push_back( 0. );
1566  vped.push_back( 0. );
1567  pedwgtvaft[0] = ps.getUntrackedParameter< std::vector<double> >("pedWeightsAft", vped);
1568  }
1569  else if (getWeightsFromFile_)
1570  {
1571  //Read from file
1572  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading pedestal after gain switch weights from file " << edm::FileInPath(pedWeightsAftFile_).fullPath().c_str() ;
1573  std::ifstream pedFile(edm::FileInPath(pedWeightsAftFile_).fullPath().c_str());
1574  int tdcBin=0;
1575  while (!pedFile.eof() && tdcBin < nTDCbins_)
1576  {
1577  for(int j = 0; j < 10; ++j) {
1578  float ww;
1579  pedFile >> ww;
1580  pedwgtvaft[tdcBin].push_back(ww);
1581  }
1582  ++tdcBin;
1583  }
1584  assert (tdcBin == nTDCbins_);
1585  }
1586  else
1587  {
1588  //Not supported
1589  edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1590  throw cms::Exception("WrongConfig");
1591  }
1592 
1593  for (int i=0;i<nTDCbins_;i++)
1594  {
1595  assert(pedwgtvaft[i].size() == 10);
1596  int j=0;
1597  for(std::vector<double>::const_iterator it = pedwgtvaft[i].begin(); it != pedwgtvaft[i].end(); ++it) {
1598  (pedWeightsAft_[i])[j]=*it;
1599  j++;
1600  }
1601  }
1602 
1603 
1604 
1605  // default weights to reco jitter
1606 
1607  std::vector< std::vector<double> > jittwgtv(nTDCbins_);
1608 
1609  if (!getWeightsFromFile_ && nTDCbins_ == 1 )
1610  {
1611  std::vector<double> vjitt;
1612  vjitt.push_back( 0.04066309 );
1613  vjitt.push_back( 0.04066309 );
1614  vjitt.push_back( 0.04066309 );
1615  vjitt.push_back( 0.000 );
1616  vjitt.push_back( 1.325176 );
1617  vjitt.push_back( -0.04997078 );
1618  vjitt.push_back( -0.504338 );
1619  vjitt.push_back( -0.5024844 );
1620  vjitt.push_back( -0.3903718 );
1621  vjitt.push_back( 0.000 );
1622  jittwgtv[0] = ps.getUntrackedParameter< std::vector<double> >("jittWeights", vjitt);
1623  }
1624  else if (getWeightsFromFile_)
1625  {
1626  //Read from file
1627  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading jitter weights from file " << edm::FileInPath(jittWeightsFile_).fullPath().c_str() ;
1628  std::ifstream jittFile(edm::FileInPath(jittWeightsFile_).fullPath().c_str());
1629  int tdcBin=0;
1630  while (!jittFile.eof() && tdcBin < nTDCbins_)
1631  {
1632  for(int j = 0; j < 10; ++j) {
1633  float ww;
1634  jittFile >> ww;
1635  jittwgtv[tdcBin].push_back(ww);
1636  }
1637  ++tdcBin;
1638  }
1639  assert (tdcBin == nTDCbins_);
1640  }
1641  else
1642  {
1643  //Not supported
1644  edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1645  throw cms::Exception("WrongConfig");
1646  }
1647 
1648  for (int i=0;i<nTDCbins_;i++)
1649  {
1650  assert(jittwgtv[i].size() == 10);
1651  int j=0;
1652  for(std::vector<double>::const_iterator it = jittwgtv[i].begin(); it != jittwgtv[i].end(); ++it) {
1653  (jittWeights_[i])[j]= *it;
1654  j++;
1655  }
1656  }
1657 
1658  std::vector< std::vector<double> > jittwgtvaft(nTDCbins_);
1659 
1660  if (!getWeightsFromFile_ && nTDCbins_ == 1)
1661  {
1662  std::vector<double> vjitt;
1663  vjitt.push_back( 0. );
1664  vjitt.push_back( 0. );
1665  vjitt.push_back( 0. );
1666  vjitt.push_back( 0. );
1667  vjitt.push_back( 1.097871 );
1668  vjitt.push_back( -0.04551035 );
1669  vjitt.push_back( -0.4159156 );
1670  vjitt.push_back( -0.4185352 );
1671  vjitt.push_back( -0.3367127 );
1672  vjitt.push_back( 0. );
1673  jittwgtvaft[0] = ps.getUntrackedParameter< std::vector<double> >("jittWeightsAft", vjitt);
1674  }
1675  else if (getWeightsFromFile_)
1676  {
1677  //Read from file
1678  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading jitter after gain switch weights from file " << edm::FileInPath(jittWeightsAftFile_).fullPath().c_str() ;
1679  std::ifstream jittFile(edm::FileInPath(jittWeightsAftFile_).fullPath().c_str());
1680  int tdcBin=0;
1681  while (!jittFile.eof() && tdcBin < nTDCbins_)
1682  {
1683  for(int j = 0; j < 10; ++j) {
1684  float ww;
1685  jittFile >> ww;
1686  jittwgtvaft[tdcBin].push_back(ww);
1687  }
1688  ++tdcBin;
1689  }
1690  assert (tdcBin == nTDCbins_);
1691  }
1692  else
1693  {
1694  //Not supported
1695  edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1696  throw cms::Exception("WrongConfig");
1697  }
1698 
1699  for (int i=0;i<nTDCbins_;i++)
1700  {
1701  assert(jittwgtvaft[i].size() == 10);
1702  int j=0;
1703  for(std::vector<double>::const_iterator it = jittwgtvaft[i].begin(); it != jittwgtvaft[i].end(); ++it) {
1704  (jittWeightsAft_[i])[j]= *it;
1705  j++;
1706  }
1707  }
1708 
1709 
1710  std::vector< EcalWeightSet::EcalChi2WeightMatrix > chi2Matrix(nTDCbins_);
1711  if (!getWeightsFromFile_ && nTDCbins_ == 1 )
1712  {
1713  // chi2Matrix[0].resize(10);
1714  // for (int i=0;i<10;i++)
1715  // chi2Matrix[0][i].resize(10);
1716 
1717  chi2Matrix[0](0,0) = 0.694371;
1718  chi2Matrix[0](0,1) = -0.305629;
1719  chi2Matrix[0](0,2) = -0.305629;
1720  chi2Matrix[0](0,3) = 0.;
1721  chi2Matrix[0](0,4) = 0.;
1722  chi2Matrix[0](0,5) = 0.;
1723  chi2Matrix[0](0,6) = 0.;
1724  chi2Matrix[0](0,7) = 0.;
1725  chi2Matrix[0](0,8) = 0.;
1726  chi2Matrix[0](0,9) = 0.;
1727  chi2Matrix[0](1,0) = -0.305629;
1728  chi2Matrix[0](1,1) = 0.694371;
1729  chi2Matrix[0](1,2) = -0.305629;
1730  chi2Matrix[0](1,3) = 0.;
1731  chi2Matrix[0](1,4) = 0.;
1732  chi2Matrix[0](1,5) = 0.;
1733  chi2Matrix[0](1,6) = 0.;
1734  chi2Matrix[0](1,7) = 0.;
1735  chi2Matrix[0](1,8) = 0.;
1736  chi2Matrix[0](1,9) = 0.;
1737  chi2Matrix[0](2,0) = -0.305629;
1738  chi2Matrix[0](2,1) = -0.305629;
1739  chi2Matrix[0](2,2) = 0.694371;
1740  chi2Matrix[0](2,3) = 0.;
1741  chi2Matrix[0](2,4) = 0.;
1742  chi2Matrix[0](2,5) = 0.;
1743  chi2Matrix[0](2,6) = 0.;
1744  chi2Matrix[0](2,7) = 0.;
1745  chi2Matrix[0](2,8) = 0.;
1746  chi2Matrix[0](2,9) = 0.;
1747  chi2Matrix[0](3,0) = 0.;
1748  chi2Matrix[0](3,1) = 0.;
1749  chi2Matrix[0](3,2) = 0.;
1750  chi2Matrix[0](3,3) = 0.;
1751  chi2Matrix[0](3,4) = 0.;
1752  chi2Matrix[0](3,5) = 0.;
1753  chi2Matrix[0](3,6) = 0.;
1754  chi2Matrix[0](3,7) = 0.;
1755  chi2Matrix[0](3,8) = 0.;
1756  chi2Matrix[0](3,9) = 0.;
1757  chi2Matrix[0](4,0) = 0.;
1758  chi2Matrix[0](4,1) = 0.;
1759  chi2Matrix[0](4,2) = 0.;
1760  chi2Matrix[0](4,3) = 0.;
1761  chi2Matrix[0](4,4) = 0.8027116;
1762  chi2Matrix[0](4,5) = -0.2517103;
1763  chi2Matrix[0](4,6) = -0.2232882;
1764  chi2Matrix[0](4,7) = -0.1716192;
1765  chi2Matrix[0](4,8) = -0.1239006;
1766  chi2Matrix[0](4,9) = 0.;
1767  chi2Matrix[0](5,0) = 0.;
1768  chi2Matrix[0](5,1) = 0.;
1769  chi2Matrix[0](5,2) = 0.;
1770  chi2Matrix[0](5,3) = 0.;
1771  chi2Matrix[0](5,4) = -0.2517103;
1772  chi2Matrix[0](5,5) = 0.6528964;
1773  chi2Matrix[0](5,6) = -0.2972839;
1774  chi2Matrix[0](5,7) = -0.2067162;
1775  chi2Matrix[0](5,8) = -0.1230729;
1776  chi2Matrix[0](5,9) = 0.;
1777  chi2Matrix[0](6,0) = 0.;
1778  chi2Matrix[0](6,1) = 0.;
1779  chi2Matrix[0](6,2) = 0.;
1780  chi2Matrix[0](6,3) = 0.;
1781  chi2Matrix[0](6,4) = -0.2232882;
1782  chi2Matrix[0](6,5) = -0.2972839;
1783  chi2Matrix[0](6,6) = 0.7413607;
1784  chi2Matrix[0](6,7) = -0.1883866;
1785  chi2Matrix[0](6,8) = -0.1235052;
1786  chi2Matrix[0](6,9) = 0.;
1787  chi2Matrix[0](7,0) = 0.;
1788  chi2Matrix[0](7,1) = 0.;
1789  chi2Matrix[0](7,2) = 0.;
1790  chi2Matrix[0](7,3) = 0.;
1791  chi2Matrix[0](7,4) = -0.1716192;
1792  chi2Matrix[0](7,5) = -0.2067162;
1793  chi2Matrix[0](7,6) = -0.1883866;
1794  chi2Matrix[0](7,7) = 0.844935;
1795  chi2Matrix[0](7,8) = -0.124291;
1796  chi2Matrix[0](7,9) = 0.;
1797  chi2Matrix[0](8,0) = 0.;
1798  chi2Matrix[0](8,1) = 0.;
1799  chi2Matrix[0](8,2) = 0.;
1800  chi2Matrix[0](8,3) = 0.;
1801  chi2Matrix[0](8,4) = -0.1239006;
1802  chi2Matrix[0](8,5) = -0.1230729;
1803  chi2Matrix[0](8,6) = -0.1235052;
1804  chi2Matrix[0](8,7) = -0.124291;
1805  chi2Matrix[0](8,8) = 0.8749833;
1806  chi2Matrix[0](8,9) = 0.;
1807  chi2Matrix[0](9,0) = 0.;
1808  chi2Matrix[0](9,1) = 0.;
1809  chi2Matrix[0](9,2) = 0.;
1810  chi2Matrix[0](9,3) = 0.;
1811  chi2Matrix[0](9,4) = 0.;
1812  chi2Matrix[0](9,5) = 0.;
1813  chi2Matrix[0](9,6) = 0.;
1814  chi2Matrix[0](9,7) = 0.;
1815  chi2Matrix[0](9,8) = 0.;
1816  chi2Matrix[0](9,9) = 0.;
1817  }
1818  else if (getWeightsFromFile_)
1819  {
1820  //Read from file
1821  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading chi2Matrix from file " << edm::FileInPath(chi2MatrixFile_).fullPath().c_str() ;
1822  std::ifstream chi2MatrixFile(edm::FileInPath(chi2MatrixFile_).fullPath().c_str());
1823  int tdcBin=0;
1824  while (!chi2MatrixFile.eof() && tdcBin < nTDCbins_)
1825  {
1826  // chi2Matrix[tdcBin].resize(10);
1827  for(int j = 0; j < 10; ++j) {
1828  for(int l = 0; l < 10; ++l) {
1829  float ww;
1830  chi2MatrixFile >> ww;
1831  chi2Matrix[tdcBin](j,l)=ww;
1832  }
1833  }
1834  ++tdcBin;
1835  }
1836  assert (tdcBin == nTDCbins_);
1837  }
1838  else
1839  {
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 // {
1847  // assert(chi2Matrix[i].size() == 10);
1848  chi2Matrix_ = chi2Matrix;
1849 // }
1850 
1851  std::vector< EcalWeightSet::EcalChi2WeightMatrix > chi2MatrixAft(nTDCbins_);
1852  if (!getWeightsFromFile_ && nTDCbins_ == 1 )
1853  {
1854  // chi2MatrixAft[0].resize(10);
1855  // for (int i=0;i<10;i++)
1856  // chi2MatrixAft[0][i].resize(10);
1857 
1858  chi2MatrixAft[0](0,0) = 0.;
1859  chi2MatrixAft[0](0,1) = 0.;
1860  chi2MatrixAft[0](0,2) = 0.;
1861  chi2MatrixAft[0](0,3) = 0.;
1862  chi2MatrixAft[0](0,4) = 0.;
1863  chi2MatrixAft[0](0,5) = 0.;
1864  chi2MatrixAft[0](0,6) = 0.;
1865  chi2MatrixAft[0](0,7) = 0.;
1866  chi2MatrixAft[0](0,8) = 0.;
1867  chi2MatrixAft[0](0,9) = 0.;
1868  chi2MatrixAft[0](1,0) = 0.;
1869  chi2MatrixAft[0](1,1) = 0.;
1870  chi2MatrixAft[0](1,2) = 0.;
1871  chi2MatrixAft[0](1,3) = 0.;
1872  chi2MatrixAft[0](1,4) = 0.;
1873  chi2MatrixAft[0](1,5) = 0.;
1874  chi2MatrixAft[0](1,6) = 0.;
1875  chi2MatrixAft[0](1,7) = 0.;
1876  chi2MatrixAft[0](1,8) = 0.;
1877  chi2MatrixAft[0](1,9) = 0.;
1878  chi2MatrixAft[0](2,0) = 0.;
1879  chi2MatrixAft[0](2,1) = 0.;
1880  chi2MatrixAft[0](2,2) = 0.;
1881  chi2MatrixAft[0](2,3) = 0.;
1882  chi2MatrixAft[0](2,4) = 0.;
1883  chi2MatrixAft[0](2,5) = 0.;
1884  chi2MatrixAft[0](2,6) = 0.;
1885  chi2MatrixAft[0](2,7) = 0.;
1886  chi2MatrixAft[0](2,8) = 0.;
1887  chi2MatrixAft[0](2,9) = 0.;
1888  chi2MatrixAft[0](3,0) = 0.;
1889  chi2MatrixAft[0](3,1) = 0.;
1890  chi2MatrixAft[0](3,2) = 0.;
1891  chi2MatrixAft[0](3,3) = 0.;
1892  chi2MatrixAft[0](3,4) = 0.;
1893  chi2MatrixAft[0](3,5) = 0.;
1894  chi2MatrixAft[0](3,6) = 0.;
1895  chi2MatrixAft[0](3,7) = 0.;
1896  chi2MatrixAft[0](3,8) = 0.;
1897  chi2MatrixAft[0](3,9) = 0.;
1898  chi2MatrixAft[0](4,0) = 0.;
1899  chi2MatrixAft[0](4,1) = 0.;
1900  chi2MatrixAft[0](4,2) = 0.;
1901  chi2MatrixAft[0](4,3) = 0.;
1902  chi2MatrixAft[0](4,4) = 0.8030884;
1903  chi2MatrixAft[0](4,5) = -0.2543541;
1904  chi2MatrixAft[0](4,6) = -0.2243544;
1905  chi2MatrixAft[0](4,7) = -0.1698177;
1906  chi2MatrixAft[0](4,8) = -0.1194506;
1907  chi2MatrixAft[0](4,9) = 0.;
1908  chi2MatrixAft[0](5,0) = 0.;
1909  chi2MatrixAft[0](5,1) = 0.;
1910  chi2MatrixAft[0](5,2) = 0.;
1911  chi2MatrixAft[0](5,3) = 0.;
1912  chi2MatrixAft[0](5,4) = -0.2543541;
1913  chi2MatrixAft[0](5,5) = 0.6714465;
1914  chi2MatrixAft[0](5,6) = -0.2898025;
1915  chi2MatrixAft[0](5,7) = -0.2193564;
1916  chi2MatrixAft[0](5,8) = -0.1542964;
1917  chi2MatrixAft[0](5,9) = 0.;
1918  chi2MatrixAft[0](6,0) = 0.;
1919  chi2MatrixAft[0](6,1) = 0.;
1920  chi2MatrixAft[0](6,2) = 0.;
1921  chi2MatrixAft[0](6,3) = 0.;
1922  chi2MatrixAft[0](6,4) = -0.2243544;
1923  chi2MatrixAft[0](6,5) = -0.2898025;
1924  chi2MatrixAft[0](6,6) = 0.7443781;
1925  chi2MatrixAft[0](6,7) = -0.1934846;
1926  chi2MatrixAft[0](6,8) = -0.136098;
1927  chi2MatrixAft[0](6,9) = 0.;
1928  chi2MatrixAft[0](7,0) = 0.;
1929  chi2MatrixAft[0](7,1) = 0.;
1930  chi2MatrixAft[0](7,2) = 0.;
1931  chi2MatrixAft[0](7,3) = 0.;
1932  chi2MatrixAft[0](7,4) = -0.1698177;
1933  chi2MatrixAft[0](7,5) = -0.2193564;
1934  chi2MatrixAft[0](7,6) = -0.1934846;
1935  chi2MatrixAft[0](7,7) = 0.8535482;
1936  chi2MatrixAft[0](7,8) = -0.1030149;
1937  chi2MatrixAft[0](7,9) = 0.;
1938  chi2MatrixAft[0](8,0) = 0.;
1939  chi2MatrixAft[0](8,1) = 0.;
1940  chi2MatrixAft[0](8,2) = 0.;
1941  chi2MatrixAft[0](8,3) = 0.;
1942  chi2MatrixAft[0](8,4) = -0.1194506;
1943  chi2MatrixAft[0](8,5) = -0.1542964;
1944  chi2MatrixAft[0](8,6) = -0.136098;
1945  chi2MatrixAft[0](8,7) = -0.1030149;
1946  chi2MatrixAft[0](8,8) = 0.9275388;
1947  chi2MatrixAft[0](8,9) = 0.;
1948  chi2MatrixAft[0](9,0) = 0.;
1949  chi2MatrixAft[0](9,1) = 0.;
1950  chi2MatrixAft[0](9,2) = 0.;
1951  chi2MatrixAft[0](9,3) = 0.;
1952  chi2MatrixAft[0](9,4) = 0.;
1953  chi2MatrixAft[0](9,5) = 0.;
1954  chi2MatrixAft[0](9,6) = 0.;
1955  chi2MatrixAft[0](9,7) = 0.;
1956  chi2MatrixAft[0](9,8) = 0.;
1957  chi2MatrixAft[0](9,9) = 0.;
1958  }
1959  else if (getWeightsFromFile_)
1960  {
1961  //Read from file
1962  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading chi2MatrixAft from file " << edm::FileInPath(chi2MatrixAftFile_).fullPath().c_str() ;
1963  std::ifstream chi2MatrixAftFile(edm::FileInPath(chi2MatrixAftFile_).fullPath().c_str());
1964  int tdcBin=0;
1965  while (!chi2MatrixAftFile.eof() && tdcBin < nTDCbins_)
1966  {
1967  // chi2MatrixAft[tdcBin].resize(10);
1968  for(int j = 0; j < 10; ++j) {
1969  for(int l = 0; l < 10; ++l) {
1970  float ww;
1971  chi2MatrixAftFile >> ww;
1972  chi2MatrixAft[tdcBin](j,l)=ww;
1973  }
1974  }
1975  ++tdcBin;
1976  }
1977  assert (tdcBin == nTDCbins_);
1978  }
1979  else
1980  {
1981  //Not supported
1982  edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1983  throw cms::Exception("WrongConfig");
1984  }
1985 
1986 // for (int i=0;i<nTDCbins_;i++)
1987 // {
1988  // assert(chi2MatrixAft[i].size() == 10);
1989  chi2MatrixAft_ = chi2MatrixAft;
1990  // }
1991 
1992 }
1993 
1994 
1995 // --------------------------------------------------------------------------------
1996 
1997 std::unique_ptr<EcalChannelStatus>
1999 {
2000  auto ecalStatus = std::make_unique<EcalChannelStatus>();
2001 
2002 
2003  // start by setting all statuses to 0
2004 
2005  // barrel
2006  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
2007  if(ieta==0) continue;
2008  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
2009  if (EBDetId::validDetId(ieta,iphi)) {
2010  EBDetId ebid(ieta,iphi);
2011  ecalStatus->setValue( ebid, 0 );
2012  }
2013  }
2014  }
2015  // endcap
2016  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
2017  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
2018  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
2019  if (EEDetId::validDetId(iX,iY,1)) {
2020  EEDetId eedetidpos(iX,iY,1);
2021  ecalStatus->setValue( eedetidpos, 0 );
2022  }
2023  if (EEDetId::validDetId(iX,iY,-1)) {
2024  EEDetId eedetidneg(iX,iY,-1);
2025  ecalStatus->setValue( eedetidneg, 0 );
2026  }
2027  }
2028  }
2029 
2030 
2031 
2032  // overwrite the statuses which are in the file
2033 
2034  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading channel statuses from file " << edm::FileInPath(channelStatusFile_).fullPath().c_str() ;
2035  std::ifstream statusFile(edm::FileInPath(channelStatusFile_).fullPath().c_str());
2036  if ( !statusFile.good() ) {
2037  edm::LogError ("EcalTrivialConditionRetriever")
2038  << "*** Problems opening file: " << channelStatusFile_ ;
2039  throw cms::Exception ("Cannot open ECAL channel status file") ;
2040  }
2041 
2042  std::string EcalSubDet;
2043  std::string str;
2044  int hashIndex(0);
2045  int status(0);
2046 
2047  while (!statusFile.eof())
2048  {
2049  statusFile >> EcalSubDet;
2050  if (EcalSubDet!=std::string("EB") && EcalSubDet!=std::string("EE"))
2051  {
2052  std::getline(statusFile,str);
2053  continue;
2054  }
2055  else
2056  {
2057  statusFile>> hashIndex >> status;
2058  }
2059  // std::cout << EcalSubDet << " " << hashIndex << " " << status;
2060 
2061  if(EcalSubDet==std::string("EB"))
2062  {
2063  EBDetId ebid = EBDetId::unhashIndex(hashIndex);
2064  ecalStatus->setValue( ebid, status );
2065  }
2066  else if(EcalSubDet==std::string("EE"))
2067  {
2068  EEDetId eedetid = EEDetId::unhashIndex(hashIndex);
2069  ecalStatus->setValue( eedetid, status );
2070  }
2071  else
2072  {
2073  edm::LogError ("EcalTrivialConditionRetriever")
2074  << " *** " << EcalSubDet << " is neither EB nor EE ";
2075  }
2076 
2077  }
2078  // the file is supposed to be in the form -- FIXME
2079 
2080 
2081  statusFile.close();
2082  return ecalStatus;
2083 }
2084 
2085 
2086 
2087 std::unique_ptr<EcalChannelStatus>
2089 {
2090 
2091  auto ical = std::make_unique<EcalChannelStatus>();
2092  // barrel
2093  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
2094  if(ieta==0) continue;
2095  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
2096  if (EBDetId::validDetId(ieta,iphi)) {
2097  EBDetId ebid(ieta,iphi);
2098  ical->setValue( ebid, 0 );
2099  }
2100  }
2101  }
2102  // endcap
2103  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
2104  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
2105  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
2106  if (EEDetId::validDetId(iX,iY,1)) {
2107  EEDetId eedetidpos(iX,iY,1);
2108  ical->setValue( eedetidpos, 0 );
2109  }
2110  if (EEDetId::validDetId(iX,iY,-1)) {
2111  EEDetId eedetidneg(iX,iY,-1);
2112  ical->setValue( eedetidneg, 0 );
2113  }
2114  }
2115  }
2116  return ical;
2117 }
2118 
2119 // --------------------------------------------------------------------------------
2120 std::unique_ptr<EcalDQMChannelStatus>
2122 {
2123  uint32_t sta(0);
2124 
2125  auto ical = std::make_unique<EcalDQMChannelStatus>();
2126  // barrel
2127  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
2128  if(ieta==0) continue;
2129  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
2130  if (EBDetId::validDetId(ieta,iphi)) {
2131  EBDetId ebid(ieta,iphi);
2132  ical->setValue( ebid, sta );
2133  }
2134  }
2135  }
2136  // endcap
2137  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
2138  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
2139  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
2140  if (EEDetId::validDetId(iX,iY,1)) {
2141  EEDetId eedetidpos(iX,iY,1);
2142  ical->setValue( eedetidpos, sta );
2143  }
2144  if (EEDetId::validDetId(iX,iY,-1)) {
2145  EEDetId eedetidneg(iX,iY,-1);
2146  ical->setValue( eedetidneg, sta );
2147  }
2148  }
2149  }
2150  return ical;
2151 }
2152 // --------------------------------------------------------------------------------
2153 
2154 std::unique_ptr<EcalDQMTowerStatus>
2156 {
2157 
2158  auto ical = std::make_unique<EcalDQMTowerStatus>();
2159 
2160  uint32_t sta(0);
2161 
2162  // barrel
2163  int iz=0;
2164  for(int k=0 ; k<2; k++ ) {
2165  if(k==0) iz=-1;
2166  if(k==1) iz=+1;
2167  for(int i=1 ; i<73; i++) {
2168  for(int j=1 ; j<18; j++) {
2170  EcalTrigTowerDetId ebid(iz,EcalBarrel,j,i);
2171 
2172  ical->setValue( ebid, sta );
2173  }
2174  }
2175  }
2176  }
2177 
2178 
2179  // endcap
2180  for(int k=0 ; k<2; k++ ) {
2181  if(k==0) iz=-1;
2182  if(k==1) iz=+1;
2183  for(int i=1 ; i<21; i++) {
2184  for(int j=1 ; j<21; j++) {
2185  if (EcalScDetId::validDetId(i,j,iz )){
2186  EcalScDetId eeid(i,j,iz);
2187  ical->setValue( eeid, sta );
2188  }
2189  }
2190  }
2191  }
2192 
2193  return ical;
2194 }
2195 
2196 // --------------------------------------------------------------------------------
2197 std::unique_ptr<EcalDCSTowerStatus>
2199 {
2200 
2201  auto ical = std::make_unique<EcalDCSTowerStatus>();
2202 
2203  int status(0);
2204 
2205  // barrel
2206  int iz=0;
2207  for(int k=0 ; k<2; k++ ) {
2208  if(k==0) iz=-1;
2209  if(k==1) iz=+1;
2210  for(int i=1 ; i<73; i++) {
2211  for(int j=1 ; j<18; j++) {
2213  EcalTrigTowerDetId ebid(iz,EcalBarrel,j,i);
2214 
2215  ical->setValue( ebid, status );
2216  }
2217  }
2218  }
2219  }
2220 
2221 
2222  // endcap
2223  for(int k=0 ; k<2; k++ ) {
2224  if(k==0) iz=-1;
2225  if(k==1) iz=+1;
2226  for(int i=1 ; i<21; i++) {
2227  for(int j=1 ; j<21; j++) {
2228  if (EcalScDetId::validDetId(i,j,iz )){
2229  EcalScDetId eeid(i,j,iz);
2230  ical->setValue( eeid, status );
2231  }
2232  }
2233  }
2234  }
2235 
2236  return ical;
2237 }
2238 // --------------------------------------------------------------------------------
2239 
2240 std::unique_ptr<EcalDAQTowerStatus>
2242 {
2243 
2244  auto ical = std::make_unique<EcalDAQTowerStatus>();
2245 
2246  int status(0);
2247 
2248  // barrel
2249  int iz=0;
2250  for(int k=0 ; k<2; k++ ) {
2251  if(k==0) iz=-1;
2252  if(k==1) iz=+1;
2253  for(int i=1 ; i<73; i++) {
2254  for(int j=1 ; j<18; j++) {
2256  EcalTrigTowerDetId ebid(iz,EcalBarrel,j,i);
2257 
2258  ical->setValue( ebid, status );
2259  }
2260  }
2261  }
2262  }
2263 
2264 
2265  // endcap
2266  for(int k=0 ; k<2; k++ ) {
2267  if(k==0) iz=-1;
2268  if(k==1) iz=+1;
2269  for(int i=1 ; i<21; i++) {
2270  for(int j=1 ; j<21; j++) {
2271  if (EcalScDetId::validDetId(i,j,iz )){
2272  EcalScDetId eeid(i,j,iz);
2273  ical->setValue( eeid, status );
2274  }
2275  }
2276  }
2277  }
2278 
2279  return ical;
2280 }
2281 // --------------------------------------------------------------------------------
2282 
2283 std::unique_ptr<EcalTPGCrystalStatus>
2285 {
2286  auto ecalStatus = std::make_unique<EcalTPGCrystalStatus>();
2287 
2288 
2289  // start by setting all statuses to 0
2290 
2291  // barrel
2292  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
2293  if(ieta==0) continue;
2294  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
2295  if (EBDetId::validDetId(ieta,iphi)) {
2296  EBDetId ebid(ieta,iphi);
2297  ecalStatus->setValue( ebid, 0 );
2298  }
2299  }
2300  }
2301  // endcap
2302  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
2303  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
2304  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
2305  if (EEDetId::validDetId(iX,iY,1)) {
2306  EEDetId eedetidpos(iX,iY,1);
2307  ecalStatus->setValue( eedetidpos, 0 );
2308  }
2309  if (EEDetId::validDetId(iX,iY,-1)) {
2310  EEDetId eedetidneg(iX,iY,-1);
2311  ecalStatus->setValue( eedetidneg, 0 );
2312  }
2313  }
2314  }
2315 
2316 
2317 
2318  // overwrite the statuses which are in the file
2319 
2320  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading channel statuses from file " << edm::FileInPath(channelStatusFile_).fullPath().c_str() ;
2321  std::ifstream statusFile(edm::FileInPath(channelStatusFile_).fullPath().c_str());
2322  if ( !statusFile.good() ) {
2323  edm::LogError ("EcalTrivialConditionRetriever")
2324  << "*** Problems opening file: " << channelStatusFile_ ;
2325  throw cms::Exception ("Cannot open ECAL channel status file") ;
2326  }
2327 
2328  std::string EcalSubDet;
2329  std::string str;
2330  int hashIndex(0);
2331  int status(0);
2332 
2333  while (!statusFile.eof())
2334  {
2335  statusFile >> EcalSubDet;
2336  if (EcalSubDet!=std::string("EB") && EcalSubDet!=std::string("EE"))
2337  {
2338  std::getline(statusFile,str);
2339  continue;
2340  }
2341  else
2342  {
2343  statusFile>> hashIndex >> status;
2344  }
2345  // std::cout << EcalSubDet << " " << hashIndex << " " << status;
2346 
2347  if(EcalSubDet==std::string("EB"))
2348  {
2349  EBDetId ebid = EBDetId::unhashIndex(hashIndex);
2350  ecalStatus->setValue( ebid, status );
2351  }
2352  else if(EcalSubDet==std::string("EE"))
2353  {
2354  EEDetId eedetid = EEDetId::unhashIndex(hashIndex);
2355  ecalStatus->setValue( eedetid, status );
2356  }
2357  else
2358  {
2359  edm::LogError ("EcalTrivialConditionRetriever")
2360  << " *** " << EcalSubDet << " is neither EB nor EE ";
2361  }
2362 
2363  }
2364  // the file is supposed to be in the form -- FIXME
2365 
2366 
2367  statusFile.close();
2368  return ecalStatus;
2369 }
2370 
2371 
2372 
2373 std::unique_ptr<EcalTPGCrystalStatus>
2375 {
2376 
2377  auto ical = std::make_unique<EcalTPGCrystalStatus>();
2378  // barrel
2379  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
2380  if(ieta==0) continue;
2381  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
2382  if (EBDetId::validDetId(ieta,iphi)) {
2383  EBDetId ebid(ieta,iphi);
2384  ical->setValue( ebid, 0 );
2385  }
2386  }
2387  }
2388  // endcap
2389  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
2390  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
2391  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
2392  if (EEDetId::validDetId(iX,iY,1)) {
2393  EEDetId eedetidpos(iX,iY,1);
2394  ical->setValue( eedetidpos, 0 );
2395  }
2396  if (EEDetId::validDetId(iX,iY,-1)) {
2397  EEDetId eedetidneg(iX,iY,-1);
2398  ical->setValue( eedetidneg, 0 );
2399  }
2400  }
2401  }
2402  return ical;
2403 }
2404 
2405 
2406 
2407 
2408 std::unique_ptr<EcalIntercalibConstants>
2411 {
2412  std::unique_ptr<EcalIntercalibConstants> ical;
2413  // std::make_unique<EcalIntercalibConstants>();
2414 
2415  // Read the values from a txt file
2416  // -------------------------------
2417 
2418  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading intercalibration constants from file "
2419  << intercalibConstantsFile_.c_str() ;
2420 
2421  if(intercalibConstantsFile_.find(".xml")!= std::string::npos) {
2422 
2423  std::cout<<"generating Intercalib from xml file"<<std::endl;
2424 
2425  EcalCondHeader h;
2427  EcalIntercalibConstantsXMLTranslator::readXML(intercalibConstantsFile_,h,*rcd);
2428 
2429 
2430  if(totLumi_ !=0 || instLumi_!=0) {
2431  std::cout<<"implementing ageing for intercalib"<<std::endl;
2432 
2434 
2435  if(intercalibConstantsMCFile_.find(".xml")!= std::string::npos) {
2436 
2437  std::cout<<"generating IntercalibMC from xml file"<<std::endl;
2438 
2439  EcalCondHeader h;
2440  EcalIntercalibConstantsMCXMLTranslator::readXML(intercalibConstantsMCFile_,h,*rcdMC);
2441 
2442  } else {
2443  std::cout<<"please provide the xml file of the EcalIntercalibConstantsMC"<<std::endl;
2444  }
2445 
2446 
2447  TRandom3 * gRandom = new TRandom3();
2448 
2449  EnergyResolutionVsLumi ageing;
2450  ageing.setLumi(totLumi_);
2451  ageing.setInstLumi(instLumi_);
2452 
2453 
2454  const EcalIntercalibConstantMap& mymap= rcd->getMap();
2455  const EcalIntercalibConstantMCMap& mymapMC= rcdMC->getMap();
2456 
2457  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
2458  if(ieta==0) continue;
2459 
2460  double eta=EBDetId::approxEta(EBDetId(ieta,1));
2461  eta = fabs(eta);
2462  double constantTerm= ageing.calcresolutitonConstantTerm(eta);
2463  std::cout<<"EB at eta="<<eta<<" constant term is "<<constantTerm<<std::endl;
2464 
2465  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
2466  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
2467  if (EBDetId::validDetId(ieta,iphi))
2468  {
2469  EBDetId ebid(ieta,iphi);
2471  EcalIntercalibConstant icalconstant=1;
2472  if(idref!=mymap.end())icalconstant=(*idref);
2473 
2474  EcalIntercalibConstantsMC::const_iterator idrefMC=mymapMC.find(ebid);
2475  EcalIntercalibConstantMC icalconstantMC=1;
2476  if(idrefMC!=mymapMC.end())icalconstantMC=(*idrefMC);
2477 
2478  double r = gRandom->Gaus(0,constantTerm);
2479 
2480  if(iphi==10) std::cout<<"EB at eta="<<eta<<" IC="<<icalconstant<<" ICMC="<<icalconstantMC<<" smear="<<r<<" ";
2481 
2482  icalconstant = icalconstant + r*1.29*icalconstantMC;
2483  rcd->setValue( ebid.rawId(), icalconstant );
2484 
2485  if(iphi==10) std::cout<<"newIC="<<icalconstant<<std::endl;
2486 
2487  EcalIntercalibConstant icalconstant2=(*idref);
2488  if(icalconstant !=icalconstant2) std::cout<<">>>> error in smearing intercalib"<<std::endl;
2489  }
2490  }
2491  }
2492 
2493  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
2494  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
2495  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
2496  if (EEDetId::validDetId(iX,iY,1))
2497  {
2498 
2499  EEDetId eedetidpos(iX,iY,1);
2500  double eta= -log(tan(0.5*atan(sqrt((iX-50.0)*(iX-50.0)+(iY-50.0)*(iY-50.0))*2.98/328.)));
2501  eta = fabs(eta);
2502  double constantTerm=ageing.calcresolutitonConstantTerm(eta);
2503  if(iX==50) std::cout<<"EE at eta="<<eta<<" constant term is "<<constantTerm<<std::endl;
2504 
2505 
2506 
2507 
2508  EcalIntercalibConstants::const_iterator idref=mymap.find(eedetidpos);
2509  EcalIntercalibConstant icalconstant=1;
2510  if(idref!=mymap.end())icalconstant=(*idref);
2511 
2512  EcalIntercalibConstantsMC::const_iterator idrefMC=mymapMC.find(eedetidpos);
2513  EcalIntercalibConstantMC icalconstantMC=1;
2514  if(idrefMC!=mymapMC.end())icalconstantMC=(*idrefMC);
2515 
2516  double r = gRandom->Gaus(0,constantTerm);
2517 
2518  if(iX==10) std::cout<<"EE at eta="<<eta<<" IC="<<icalconstant<<" ICMC="<<icalconstantMC<<" smear="<<r<<" ";
2519  icalconstant = icalconstant + r*1.29*icalconstantMC;
2520  rcd->setValue( eedetidpos.rawId(), icalconstant );
2521  if(iX==10) std::cout<<"newIC="<<icalconstant<<std::endl;
2522 
2523 
2524 
2525  }
2526  if(EEDetId::validDetId(iX,iY,-1))
2527  {
2528 
2529  EEDetId eedetidneg(iX,iY,-1);
2530  double eta= -log(tan(0.5*atan(sqrt((iX-50.0)*(iX-50.0)+(iY-50.0)*(iY-50.0))*2.98/328.)));
2531  eta = fabs(eta);
2532  double constantTerm=ageing.calcresolutitonConstantTerm(eta);
2533  EcalIntercalibConstant icalconstant=1;
2534 
2535 
2536  EcalIntercalibConstantsMC::const_iterator idrefMC=mymapMC.find(eedetidneg);
2537  EcalIntercalibConstantMC icalconstantMC=1;
2538  if(idrefMC!=mymapMC.end())icalconstantMC=(*idrefMC);
2539 
2540  double r = gRandom->Gaus(0,constantTerm);
2541  icalconstant = icalconstant + r*1.29*icalconstantMC;
2542  rcd->setValue( eedetidneg.rawId(), icalconstant );
2543 
2544 
2545  }
2546  }
2547  }
2548 
2549  ical = std::unique_ptr<EcalIntercalibConstants>(rcd);
2550 
2551  delete gRandom;
2552 
2553  }
2554 
2555 
2556  } else {
2557 
2558  ical = std::make_unique<EcalIntercalibConstants>();
2559 
2560  FILE *inpFile ;
2561  inpFile = fopen (intercalibConstantsFile_.c_str (),"r") ;
2562  if (!inpFile)
2563  {
2564  edm::LogError ("EcalTrivialConditionRetriever")
2565  << "*** Can not open file: " << intercalibConstantsFile_ ;
2566  throw cms::Exception ("Cannot open inter-calibration coefficients txt file") ;
2567  }
2568 
2569  char line[256] ;
2570  std::ostringstream str ;
2571  fgets (line,255,inpFile) ;
2572  int sm_number=atoi (line) ;
2573  str << "sm: " << sm_number ;
2574 
2575  fgets (line,255,inpFile) ;
2576  //int nevents=atoi (line) ; // not necessary here just for online conddb
2577 
2578  fgets (line,255,inpFile) ;
2579  std::string gen_tag = line ;
2580  str << "gen tag: " << gen_tag ; // should I use this?
2581 
2582  fgets (line,255,inpFile) ;
2583  std::string cali_method = line ;
2584  str << "cali method: " << cali_method << std::endl ; // not important
2585 
2586  fgets (line,255,inpFile) ;
2587  std::string cali_version = line ;
2588  str << "cali version: " << cali_version << std::endl ; // not important
2589 
2590  fgets (line,255,inpFile) ;
2591  std::string cali_type = line ;
2592  str << "cali type: " << cali_type ; // not important
2593 
2594  edm::LogInfo("EcalTrivialConditionRetriever")
2595  << "[PIETRO] Intercalibration file - "
2596  << str.str () << std::endl ;
2597 
2598  float calib[1700]={1} ;
2599  int calib_status[1700]={0} ;
2600 
2601  int ii = 0 ;
2602 
2603  while (fgets (line,255,inpFile))
2604  {
2605  ii++;
2606  int dmy_num = 0 ;
2607  float dmy_calib = 0. ;
2608  float dmy_RMS = 0. ;
2609  int dmy_events = 0 ;
2610  int dmy_status = 0 ;
2611  sscanf (line, "%d %f %f %d %d", &dmy_num, &dmy_calib,
2612  &dmy_RMS, &dmy_events,
2613  &dmy_status) ;
2614  assert (dmy_num >= 1) ;
2615  assert (dmy_num <= 1700) ;
2616  calib[dmy_num-1] = dmy_calib ;
2617  calib_status[dmy_num-1] = dmy_status ;
2618 
2619  // edm::LogInfo ("EcalTrivialConditionRetriever")
2620  // << "[PIETRO] cry = " << dmy_num
2621  // << " calib = " << calib[dmy_num-1]
2622  // << " RMS = " << dmy_RMS
2623  // << " events = " << dmy_events
2624  // << " status = " << calib_status[dmy_num-1]
2625  // << std::endl ;
2626  }
2627 
2628  fclose (inpFile) ; // close inp. file
2629  edm::LogInfo ("EcalTrivialConditionRetriever") << "Read intercalibrations for " << ii << " xtals " ;
2630  if (ii!=1700) edm::LogWarning ("StoreEcalCondition")
2631  << "Some crystals missing, set to 1" << std::endl ;
2632 
2633  // Transfer the data to the inter-calibration coefficients container
2634  // -----------------------------------------------------------------
2635 
2636  // DB supermodule always set to 1 for the TestBeam FIXME
2637  int sm_db=1 ;
2638  // loop over channels
2639  for (int i=0 ; i<1700 ; i++)
2640  {
2641  //if (EBDetId::validDetId(iEta,iPhi)) {
2642  // CANNOT be used -- validDetId only checks ETA PHI method
2643  // doing a check by hand, here is the only place in CMSSW
2644  // outside TB code and EcalRawToDigi where needed
2645  // => no need for changing the DetId interface
2646  //
2647  // checking only sm_db -- guess can change with the above FIXME
2648  if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
2649  EBDetId ebid (sm_db,i+1,EBDetId::SMCRYSTALMODE) ;
2650  if (calib_status[i]) ical->setValue (ebid.rawId (), calib[i]) ;
2651  else ical->setValue (ebid.rawId (), 1.) ;
2652  }
2653  //}
2654  } // loop over channels
2655 
2656 
2657 
2658 
2659  }
2660 
2661  return ical;
2662 
2663 
2664 }
2665 
2666 std::unique_ptr<EcalIntercalibConstantsMC>
2669 {
2670  std::unique_ptr<EcalIntercalibConstantsMC> ical;
2671  // std::make_unique<EcalIntercalibConstants>();
2672 
2673  // Read the values from a xml file
2674  // -------------------------------
2675 
2676  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading intercalibration constants MC from file "
2677  << intercalibConstantsMCFile_.c_str() ;
2678 
2679  if(intercalibConstantsMCFile_.find(".xml")!= std::string::npos) {
2680 
2681  std::cout<<"generating Intercalib MC from xml file"<<std::endl;
2682 
2683  EcalCondHeader h;
2685  EcalIntercalibConstantsMCXMLTranslator::readXML(intercalibConstantsMCFile_,h,*rcd);
2686 
2687  ical = std::unique_ptr<EcalIntercalibConstants>(rcd);
2688 
2689  } else {
2690 
2691  std::cout <<"ERROR>>> please provide a xml file"<<std::endl;
2692  }
2693 
2694 
2695  return ical;
2696 
2697 }
2698 
2699 
2700 std::unique_ptr<EcalIntercalibErrors>
2703 {
2704  auto ical = std::make_unique<EcalIntercalibErrors>();
2705 
2706  // Read the values from a txt file
2707  // -------------------------------
2708 
2709  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading intercalibration constants from file "
2710  << intercalibErrorsFile_.c_str() ;
2711 
2712  FILE *inpFile ;
2713  inpFile = fopen (intercalibErrorsFile_.c_str (),"r") ;
2714  if (!inpFile)
2715  {
2716  edm::LogError ("EcalTrivialConditionRetriever")
2717  << "*** Can not open file: " << intercalibErrorsFile_ ;
2718  throw cms::Exception ("Cannot open inter-calibration coefficients txt file") ;
2719  }
2720 
2721  char line[256] ;
2722  std::ostringstream str ;
2723  fgets (line,255,inpFile) ;
2724  int sm_number=atoi (line) ;
2725  str << "sm: " << sm_number ;
2726 
2727  fgets (line,255,inpFile) ;
2728  //int nevents=atoi (line) ; // not necessary here just for online conddb
2729 
2730  fgets (line,255,inpFile) ;
2731  std::string gen_tag = line ;
2732  str << "gen tag: " << gen_tag ; // should I use this?
2733 
2734  fgets (line,255,inpFile) ;
2735  std::string cali_method = line ;
2736  str << "cali method: " << cali_method << std::endl ; // not important
2737 
2738  fgets (line,255,inpFile) ;
2739  std::string cali_version = line ;
2740  str << "cali version: " << cali_version << std::endl ; // not important
2741 
2742  fgets (line,255,inpFile) ;
2743  std::string cali_type = line ;
2744  str << "cali type: " << cali_type ; // not important
2745 
2746  edm::LogInfo("EcalTrivialConditionRetriever")
2747  << "[PIETRO] Intercalibration file - "
2748  << str.str () << std::endl ;
2749 
2750  float calib[1700]={1} ;
2751  int calib_status[1700]={0} ;
2752 
2753  int ii = 0 ;
2754 
2755  while (fgets (line,255,inpFile))
2756  {
2757  ii++;
2758  int dmy_num = 0 ;
2759  float dmy_calib = 0. ;
2760  float dmy_RMS = 0. ;
2761  int dmy_events = 0 ;
2762  int dmy_status = 0 ;
2763  sscanf (line, "%d %f %f %d %d", &dmy_num, &dmy_calib,
2764  &dmy_RMS, &dmy_events,
2765  &dmy_status) ;
2766  assert (dmy_num >= 1) ;
2767  assert (dmy_num <= 1700) ;
2768  calib[dmy_num-1] = dmy_calib ;
2769  calib_status[dmy_num-1] = dmy_status ;
2770 
2771 // edm::LogInfo ("EcalTrivialConditionRetriever")
2772 // << "[PIETRO] cry = " << dmy_num
2773 // << " calib = " << calib[dmy_num-1]
2774 // << " RMS = " << dmy_RMS
2775 // << " events = " << dmy_events
2776 // << " status = " << calib_status[dmy_num-1]
2777 // << std::endl ;
2778  }
2779 
2780  fclose (inpFile) ; // close inp. file
2781  edm::LogInfo ("EcalTrivialConditionRetriever") << "Read intercalibrations for " << ii << " xtals " ;
2782  if (ii!=1700) edm::LogWarning ("StoreEcalCondition")
2783  << "Some crystals missing, set to 1" << std::endl ;
2784 
2785  // Transfer the data to the inter-calibration coefficients container
2786  // -----------------------------------------------------------------
2787 
2788  // DB supermodule always set to 1 for the TestBeam FIXME
2789  int sm_db=1 ;
2790  // loop over channels
2791  for (int i=0 ; i<1700 ; i++)
2792  {
2793  //if (EBDetId::validDetId(iEta,iPhi)) {
2794  // CANNOT be used -- validDetId only checks ETA PHI method
2795  // doing a check by hand, here is the only place in CMSSW
2796  // outside TB code and EcalRawToDigi where needed
2797  // => no need for changing the DetId interface
2798  //
2799  // checking only sm_db -- guess can change with the above FIXME
2800  if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
2801  EBDetId ebid (sm_db,i+1,EBDetId::SMCRYSTALMODE) ;
2802  if (calib_status[i]) ical->setValue (ebid.rawId (), calib[i]) ;
2803  else ical->setValue (ebid.rawId (), 1.) ;
2804  }
2805  //}
2806  } // loop over channels
2807 
2808 // edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ;
2809  return ical;
2810 
2811 
2812 
2813 
2814 
2815 }
2816 
2817 // --------------------------------------------------------------------------------
2818 
2819 
2820 std::unique_ptr<EcalTimeCalibConstants>
2823 {
2824  auto ical = std::make_unique<EcalTimeCalibConstants>();
2825 
2826  // Read the values from a txt file
2827  // -------------------------------
2828 
2829  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading time calibration constants from file "
2830  << timeCalibConstantsFile_.c_str() ;
2831 
2832  FILE *inpFile ;
2833  inpFile = fopen (timeCalibConstantsFile_.c_str (),"r") ;
2834  if (!inpFile)
2835  {
2836  edm::LogError ("EcalTrivialConditionRetriever")
2837  << "*** Can not open file: " << timeCalibConstantsFile_ ;
2838  throw cms::Exception ("Cannot open inter-calibration coefficients txt file") ;
2839  }
2840 
2841  char line[256] ;
2842  std::ostringstream str ;
2843  fgets (line,255,inpFile) ;
2844  int sm_number=atoi (line) ;
2845  str << "sm: " << sm_number ;
2846 
2847  fgets (line,255,inpFile) ;
2848  //int nevents=atoi (line) ; // not necessary here just for online conddb
2849 
2850  fgets (line,255,inpFile) ;
2851  std::string gen_tag = line ;
2852  str << "gen tag: " << gen_tag ; // should I use this?
2853 
2854  fgets (line,255,inpFile) ;
2855  std::string cali_method = line ;
2856  str << "cali method: " << cali_method << std::endl ; // not important
2857 
2858  fgets (line,255,inpFile) ;
2859  std::string cali_version = line ;
2860  str << "cali version: " << cali_version << std::endl ; // not important
2861 
2862  fgets (line,255,inpFile) ;
2863  std::string cali_type = line ;
2864  str << "cali type: " << cali_type ; // not important
2865 
2866  edm::LogInfo("EcalTrivialConditionRetriever")
2867  << "TimeCalibration file - "
2868  << str.str () << std::endl ;
2869 
2870  float calib[1700]={1} ;
2871  int calib_status[1700]={0} ;
2872 
2873  int ii = 0 ;
2874 
2875  while (fgets (line,255,inpFile))
2876  {
2877  ii++;
2878  int dmy_num = 0 ;
2879  float dmy_calib = 0. ;
2880  float dmy_RMS = 0. ;
2881  int dmy_events = 0 ;
2882  int dmy_status = 0 ;
2883  sscanf (line, "%d %f %f %d %d", &dmy_num, &dmy_calib,
2884  &dmy_RMS, &dmy_events,
2885  &dmy_status) ;
2886  assert (dmy_num >= 1) ;
2887  assert (dmy_num <= 1700) ;
2888  calib[dmy_num-1] = dmy_calib ;
2889  calib_status[dmy_num-1] = dmy_status ;
2890 
2891 // edm::LogInfo ("EcalTrivialConditionRetriever")
2892 // << "[PIETRO] cry = " << dmy_num
2893 // << " calib = " << calib[dmy_num-1]
2894 // << " RMS = " << dmy_RMS
2895 // << " events = " << dmy_events
2896 // << " status = " << calib_status[dmy_num-1]
2897 // << std::endl ;
2898  }
2899 
2900  fclose (inpFile) ; // close inp. file
2901  edm::LogInfo ("EcalTrivialConditionRetriever") << "Read timeCalibrations for " << ii << " xtals " ;
2902  if (ii!=1700) edm::LogWarning ("StoreEcalCondition")
2903  << "Some crystals missing, set to 1" << std::endl ;
2904 
2905  // Transfer the data to the inter-calibration coefficients container
2906  // -----------------------------------------------------------------
2907 
2908  // DB supermodule always set to 1 for the TestBeam FIXME
2909  int sm_db=1 ;
2910  // loop over channels
2911  for (int i=0 ; i<1700 ; i++)
2912  {
2913  //if (EBDetId::validDetId(iEta,iPhi)) {
2914  // CANNOT be used -- validDetId only checks ETA PHI method
2915  // doing a check by hand, here is the only place in CMSSW
2916  // outside TB code and EcalRawToDigi where needed
2917  // => no need for changing the DetId interface
2918  //
2919  // checking only sm_db -- guess can change with the above FIXME
2920  if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
2921  EBDetId ebid (sm_db,i+1,EBDetId::SMCRYSTALMODE) ;
2922  if (calib_status[i]) ical->setValue (ebid.rawId (), calib[i]) ;
2923  else ical->setValue (ebid.rawId (), 1.) ;
2924  }
2925  //}
2926  } // loop over channels
2927 
2928 // edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ;
2929  return ical;
2930 }
2931 
2932 
2933 std::unique_ptr<EcalTimeCalibErrors>
2936 {
2937  auto ical = std::make_unique<EcalTimeCalibErrors>();
2938 
2939  // Read the values from a txt file
2940  // -------------------------------
2941 
2942  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading timeCalibration constants from file "
2943  << timeCalibErrorsFile_.c_str() ;
2944 
2945  FILE *inpFile ;
2946  inpFile = fopen (timeCalibErrorsFile_.c_str (),"r") ;
2947  if (!inpFile)
2948  {
2949  edm::LogError ("EcalTrivialConditionRetriever")
2950  << "*** Can not open file: " << timeCalibErrorsFile_ ;
2951  throw cms::Exception ("Cannot open inter-calibration coefficients txt file") ;
2952  }
2953 
2954  char line[256] ;
2955  std::ostringstream str ;
2956  fgets (line,255,inpFile) ;
2957  int sm_number=atoi (line) ;
2958  str << "sm: " << sm_number ;
2959 
2960  fgets (line,255,inpFile) ;
2961  //int nevents=atoi (line) ; // not necessary here just for online conddb
2962 
2963  fgets (line,255,inpFile) ;
2964  std::string gen_tag = line ;
2965  str << "gen tag: " << gen_tag ; // should I use this?
2966 
2967  fgets (line,255,inpFile) ;
2968  std::string cali_method = line ;
2969  str << "cali method: " << cali_method << std::endl ; // not important
2970 
2971  fgets (line,255,inpFile) ;
2972  std::string cali_version = line ;
2973  str << "cali version: " << cali_version << std::endl ; // not important
2974 
2975  fgets (line,255,inpFile) ;
2976  std::string cali_type = line ;
2977  str << "cali type: " << cali_type ; // not important
2978 
2979  edm::LogInfo("EcalTrivialConditionRetriever")
2980  << "TimeCalibration file - "
2981  << str.str () << std::endl ;
2982 
2983  float calib[1700]={1} ;
2984  int calib_status[1700]={0} ;
2985 
2986  int ii = 0 ;
2987 
2988  while (fgets (line,255,inpFile))
2989  {
2990  ii++;
2991  int dmy_num = 0 ;
2992  float dmy_calib = 0. ;
2993  float dmy_RMS = 0. ;
2994  int dmy_events = 0 ;
2995  int dmy_status = 0 ;
2996  sscanf (line, "%d %f %f %d %d", &dmy_num, &dmy_calib,
2997  &dmy_RMS, &dmy_events,
2998  &dmy_status) ;
2999  assert (dmy_num >= 1) ;
3000  assert (dmy_num <= 1700) ;
3001  calib[dmy_num-1] = dmy_calib ;
3002  calib_status[dmy_num-1] = dmy_status ;
3003 
3004 // edm::LogInfo ("EcalTrivialConditionRetriever")
3005 // << "[PIETRO] cry = " << dmy_num
3006 // << " calib = " << calib[dmy_num-1]
3007 // << " RMS = " << dmy_RMS
3008 // << " events = " << dmy_events
3009 // << " status = " << calib_status[dmy_num-1]
3010 // << std::endl ;
3011  }
3012 
3013  fclose (inpFile) ; // close inp. file
3014  edm::LogInfo ("EcalTrivialConditionRetriever") << "Read time calibrations for " << ii << " xtals " ;
3015  if (ii!=1700) edm::LogWarning ("StoreEcalCondition")
3016  << "Some crystals missing, set to 1" << std::endl ;
3017 
3018  // Transfer the data to the inter-calibration coefficients container
3019  // -----------------------------------------------------------------
3020 
3021  // DB supermodule always set to 1 for the TestBeam FIXME
3022  int sm_db=1 ;
3023  // loop over channels
3024  for (int i=0 ; i<1700 ; i++)
3025  {
3026  //if (EBDetId::validDetId(iEta,iPhi)) {
3027  // CANNOT be used -- validDetId only checks ETA PHI method
3028  // doing a check by hand, here is the only place in CMSSW
3029  // outside TB code and EcalRawToDigi where needed
3030  // => no need for changing the DetId interface
3031  //
3032  // checking only sm_db -- guess can change with the above FIXME
3033  if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
3034  EBDetId ebid (sm_db,i+1,EBDetId::SMCRYSTALMODE) ;
3035  if (calib_status[i]) ical->setValue (ebid.rawId (), calib[i]) ;
3036  else ical->setValue (ebid.rawId (), 1.) ;
3037  }
3038  //}
3039  } // loop over channels
3040 
3041 // edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ;
3042  return ical;
3043 }
3044 
3045 // --------------------------------------------------------------------------------
3046 
3047 std::unique_ptr<EcalMappingElectronics>
3049 {
3050  auto mapping = std::make_unique<EcalMappingElectronics>();
3051  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading mapping from file " << edm::FileInPath(mappingFile_).fullPath().c_str() ;
3052 
3053  std::ifstream f(edm::FileInPath(mappingFile_).fullPath().c_str());
3054  if (!f.good())
3055  {
3056  edm::LogError("EcalTrivialConditionRetriever") << "File not found";
3057  throw cms::Exception("FileNotFound");
3058  }
3059 
3060  // uint32_t detid, elecid, triggerid;
3061 
3062  int ix, iy, iz, CL;
3063  // int dccid, towerid, stripid, xtalid;
3064  // int tccid, tower, ipseudostrip, xtalinps;
3065  int dccid, towerid, pseudostrip_in_SC, xtal_in_pseudostrip;
3066  int tccid, tower, pseudostrip_in_TCC, pseudostrip_in_TT;
3067 
3068  while ( ! f.eof())
3069  {
3070  // f >> detid >> elecid >> triggerid;
3071  f >> ix >> iy >> iz >> CL >> dccid >> towerid >> pseudostrip_in_SC >> xtal_in_pseudostrip >> tccid >> tower >>
3072  pseudostrip_in_TCC >> pseudostrip_in_TT ;
3073 
3074 // if (!EEDetId::validDetId(ix,iy,iz))
3075 // continue;
3076 
3077  EEDetId detid(ix,iy,iz,EEDetId::XYMODE);
3078  // std::cout << " dcc tower ps_in_SC xtal_in_ps " << dccid << " " << towerid << " " << pseudostrip_in_SC << " " << xtal_in_pseudostrip << std::endl;
3079  EcalElectronicsId elecid(dccid,towerid, pseudostrip_in_SC, xtal_in_pseudostrip);
3080  // std::cout << " tcc tt ps_in_TT xtal_in_ps " << tccid << " " << tower << " " << pseudostrip_in_TT << " " << xtal_in_pseudostrip << std::endl;
3081  EcalTriggerElectronicsId triggerid(tccid, tower, pseudostrip_in_TT, xtal_in_pseudostrip);
3082  EcalMappingElement aElement;
3083  aElement.electronicsid = elecid.rawId();
3084  aElement.triggerid = triggerid.rawId();
3085  (*mapping).setValue(detid, aElement);
3086  }
3087 
3088  f.close();
3089  return mapping;
3090 }
3091 
3092 
3093 
3094 std::unique_ptr<EcalMappingElectronics>
3096 {
3097 
3098  auto ical = std::make_unique<EcalMappingElectronics>();
3099  return ical;
3100 }
3101 
3102 // --------------------------------------------------------------------------------
3103 
3104 std::unique_ptr<Alignments>
3106  double mytrans[3] = {0., 0., 0.};
3107  double myeuler[3] = {0., 0., 0.};
3108  std::ifstream f;
3109  if(getEBAlignmentFromFile_)
3110  f.open(edm::FileInPath(EBAlignmentFile_).fullPath().c_str());
3111  std::vector<AlignTransform> my_align;
3112  int ieta = 1;
3113  int iphi = 0;
3114  for(int SM = 1 ; SM < 37; SM++ ) {
3115  // make an EBDetId since we need EBDetId::rawId()
3116  if(SM > 18) {
3117  iphi = 1 + (SM - 19) * 20;
3118  ieta = -1;
3119  }
3120  else
3121  iphi = SM * 20;
3122  EBDetId ebdetId(ieta,iphi);
3123  if(getEBAlignmentFromFile_) {
3124  f >> myeuler[0] >> myeuler[1] >> myeuler[2] >> mytrans[0] >> mytrans[1] >> mytrans[2];
3125  std::cout << " translation " << mytrans[0] << " " << mytrans[1] << " " << mytrans[2] << "\n"
3126  << " euler " << myeuler[0] << " " << myeuler[1] << " " << myeuler[2] << std::endl;
3127  }
3128  CLHEP::Hep3Vector translation( mytrans[0], mytrans[1], mytrans[2]);
3129  CLHEP::HepEulerAngles euler( myeuler[0], myeuler[1], myeuler[2]);
3130  AlignTransform transform( translation, euler, ebdetId );
3131  my_align.push_back(transform);
3132  }
3133  /*
3134  // check
3135  uint32_t m_rawid;
3136  double m_x, m_y, m_z;
3137  double m_phi, m_theta, m_psi;
3138  int SM = 0;
3139  for (std::vector<AlignTransform>::const_iterator i = my_align.begin(); i != my_align.end(); ++i){
3140  m_rawid = i->rawId();
3141  CLHEP::Hep3Vector translation = i->translation();
3142  m_x = translation.x();
3143  m_y = translation.y();
3144  m_z = translation.z();
3145  CLHEP::HepRotation rotation = i->rotation();
3146  m_phi = rotation.getPhi();
3147  m_theta = rotation.getTheta();
3148  m_psi = rotation.getPsi();
3149  SM++;
3150  std::cout << " SM " << SM << " Id " << m_rawid << " x " << m_x << " y " << m_y << " z " << m_z
3151  << " phi " << m_phi << " theta " << m_theta << " psi " << m_psi << std::endl;
3152  }
3153  */
3154  Alignments a;
3155  a.m_align = my_align;
3156 
3157  return std::make_unique<Alignments>(a);
3158 }
3159 
3160 std::unique_ptr<Alignments>
3162  double mytrans[3] = {0., 0., 0.};
3163  double myeuler[3] = {0., 0., 0.};
3164  std::ifstream f;
3165  if(getEEAlignmentFromFile_)
3166  f.open(edm::FileInPath(EEAlignmentFile_).fullPath().c_str());
3167  std::vector<AlignTransform> my_align;
3168  int ix = 20;
3169  int iy = 50;
3170  int side = -1;
3171  for(int Dee = 0 ; Dee < 4; Dee++ ) {
3172  // make an EEDetId since we need EEDetId::rawId()
3173  if(Dee == 1 || Dee == 3)
3174  ix = 70;
3175  else ix = 20;
3176  if(Dee == 2)
3177  side = 1;
3178  EEDetId eedetId(ix, iy, side);
3179  if(getEEAlignmentFromFile_) {
3180  f >> myeuler[0] >> myeuler[1] >> myeuler[2] >> mytrans[0] >> mytrans[1] >> mytrans[2];
3181  std::cout << " translation " << mytrans[0] << " " << mytrans[1] << " " << mytrans[2] << "\n"
3182  << " euler " << myeuler[0] << " " << myeuler[1] << " " << myeuler[2] << std::endl;
3183  }
3184  CLHEP::Hep3Vector translation( mytrans[0], mytrans[1], mytrans[2]);
3185  CLHEP::HepEulerAngles euler( myeuler[0], myeuler[1], myeuler[2]);
3186  AlignTransform transform( translation, euler, eedetId );
3187  my_align.push_back(transform);
3188  }
3189  Alignments a;
3190  a.m_align = my_align;
3191  return std::make_unique<Alignments>(a);
3192 }
3193 
3194 std::unique_ptr<Alignments>
3196  double mytrans[3] = {0., 0., 0.};
3197  double myeuler[3] = {0., 0., 0.};
3198  std::ifstream f;
3199  if(getESAlignmentFromFile_)
3200  f.open(edm::FileInPath(ESAlignmentFile_).fullPath().c_str());
3201  std::vector<AlignTransform> my_align;
3202  // int ix_vect[10] = {10, 30, 30, 50, 10, 30, 10, 30};
3203  int pl_vect[10] = {2, 2, 1, 1, 1, 1, 2, 2};
3204  int iy = 10;
3205  int side = -1;
3206  int strip = 1;
3207  for(int layer = 0 ; layer < 8; layer++ ) {
3208  // make an ESDetId since we need ESDetId::rawId()
3209  int ix = 10 + (layer%2) * 20;
3210  int plane = pl_vect[layer];
3211  if(layer > 3) side = 1;
3212  ESDetId esdetId(strip, ix, iy, plane, side);
3213  if(getESAlignmentFromFile_) {
3214  f >> myeuler[0] >> myeuler[1] >> myeuler[2] >> mytrans[0] >> mytrans[1] >> mytrans[2];
3215  std::cout << " translation " << mytrans[0] << " " << mytrans[1] << " " << mytrans[2] << "\n"
3216  << " euler " << myeuler[0] << " " << myeuler[1] << " " << myeuler[2] << std::endl;
3217  }
3218  CLHEP::Hep3Vector translation( mytrans[0], mytrans[1], mytrans[2]);
3219  CLHEP::HepEulerAngles euler( myeuler[0], myeuler[1], myeuler[2]);
3220  AlignTransform transform( translation, euler, esdetId );
3221  my_align.push_back(transform);
3222  }
3223  Alignments a;
3224  a.m_align = my_align;
3225  return std::make_unique<Alignments>(a);
3226 }
3227 
3228 std::unique_ptr<EcalSampleMask>
3230 {
3231  return std::unique_ptr<EcalSampleMask>( new EcalSampleMask(sampleMaskEB_, sampleMaskEE_) );
3232 }
3233 
3234 std::unique_ptr<EcalTimeBiasCorrections>
3236  auto ipar = std::make_unique<EcalTimeBiasCorrections>();
3237  copy(EBtimeCorrAmplitudeBins_.begin(), EBtimeCorrAmplitudeBins_.end(),
3238  back_inserter(ipar->EBTimeCorrAmplitudeBins));
3239  copy(EBtimeCorrShiftBins_.begin(), EBtimeCorrShiftBins_.end(),
3240  back_inserter(ipar->EBTimeCorrShiftBins));
3241  copy(EEtimeCorrAmplitudeBins_.begin(), EEtimeCorrAmplitudeBins_.end(),
3242  back_inserter(ipar->EETimeCorrAmplitudeBins));
3243  copy(EEtimeCorrShiftBins_.begin(), EEtimeCorrShiftBins_.end(),
3244  back_inserter(ipar->EETimeCorrShiftBins));
3245  return ipar;
3246 }
3247 
3248 std::unique_ptr<EcalSamplesCorrelation>
3250  if(getSamplesCorrelationFromFile_) {
3251  std::ifstream f;
3252  f.open(edm::FileInPath(SamplesCorrelationFile_).fullPath().c_str());
3253  float ww;
3254  for(int j = 0; j < 10; ++j) {
3255  f >> ww;
3256  EBG12samplesCorrelation_.push_back(ww);
3257  }
3258  for(int j = 0; j < 10; ++j) {
3259  f >> ww;
3260  EBG6samplesCorrelation_.push_back(ww);
3261  }
3262  for(int j = 0; j < 10; ++j) {
3263  f >> ww;
3264  EBG1samplesCorrelation_.push_back(ww);
3265  }
3266  for(int j = 0; j < 10; ++j) {
3267  f >> ww;
3268  EEG12samplesCorrelation_.push_back(ww);
3269  }
3270  for(int j = 0; j < 10; ++j) {
3271  f >> ww;
3272  EEG6samplesCorrelation_.push_back(ww);
3273  }
3274  for(int j = 0; j < 10; ++j) {
3275  f >> ww;
3276  EEG1samplesCorrelation_.push_back(ww);
3277  }
3278  f.close();
3279  }
3280  auto ipar = std::make_unique<EcalSamplesCorrelation>();
3281  copy(EBG12samplesCorrelation_.begin(), EBG12samplesCorrelation_.end(),
3282  back_inserter(ipar->EBG12SamplesCorrelation));
3283  copy(EBG6samplesCorrelation_.begin(), EBG6samplesCorrelation_.end(),
3284  back_inserter(ipar->EBG6SamplesCorrelation));
3285  copy(EBG1samplesCorrelation_.begin(), EBG1samplesCorrelation_.end(),
3286  back_inserter(ipar->EBG1SamplesCorrelation));
3287  copy(EEG12samplesCorrelation_.begin(), EEG12samplesCorrelation_.end(),
3288  back_inserter(ipar->EEG12SamplesCorrelation));
3289  copy(EEG6samplesCorrelation_.begin(), EEG6samplesCorrelation_.end(),
3290  back_inserter(ipar->EEG6SamplesCorrelation));
3291  copy(EEG1samplesCorrelation_.begin(), EEG1samplesCorrelation_.end(),
3292  back_inserter(ipar->EEG1SamplesCorrelation));
3293  return ipar;
3294 }
3295 
3296 std::unique_ptr<EcalSimPulseShape>
3299 {
3300  auto result = std::make_unique<EcalSimPulseShape>();
3301 
3302  // save time interval to be used for the pulse shape
3303  result->time_interval = sim_pulse_shape_TI_;
3304 
3305  // containers to store the shape info
3306  std::vector<double> EBshape;
3307  std::vector<double> EEshape;
3308  std::vector<double> APDshape;
3309 
3310  // --- get the 3 shapes from the user provided txt files
3311  if (!EBSimPulseShapeFile_.empty() )
3312  {
3313  std::ifstream shapeEBFile;
3314  shapeEBFile.open(EBSimPulseShapeFile_.c_str());
3315  double ww;
3316  while (shapeEBFile >> ww) EBshape.push_back(ww);
3317  shapeEBFile.close();
3318  }
3319  if (!EESimPulseShapeFile_.empty() )
3320  {
3321  std::ifstream shapeEEFile;
3322  shapeEEFile.open(EESimPulseShapeFile_.c_str());
3323  double ww;
3324  while (shapeEEFile >> ww) EEshape.push_back(ww);
3325  shapeEEFile.close();
3326  }
3327  if (!APDSimPulseShapeFile_.empty()) {
3328  std::ifstream shapeAPDFile;
3329  shapeAPDFile.open(APDSimPulseShapeFile_.c_str());
3330  double ww;
3331  while (shapeAPDFile >> ww) APDshape.push_back(ww);
3332  shapeAPDFile.close();
3333  }
3334 
3335  // --- save threshold
3336  result->barrel_thresh = sim_pulse_shape_EB_thresh_;
3337  result->endcap_thresh = sim_pulse_shape_EE_thresh_;
3338  result->apd_thresh = sim_pulse_shape_APD_thresh_;
3339 
3340  // --- copy
3341  copy(EBshape.begin(), EBshape.end(),
3342  back_inserter(result->barrel_shape));
3343  copy(EEshape.begin(), EEshape.end(),
3344  back_inserter(result->endcap_shape));
3345  copy(APDshape.begin(), APDshape.end(),
3346  back_inserter(result->apd_shape));
3347 
3348  return result;
3349 }
3350 
3351 
3352 
3353 
float approxEta() const
Definition: EBDetId.h:106
size
Write out results.
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:31
type
Definition: HCALResponse.h:21
static bool validDetId(int ix, int iy, int iz)
Definition: EcalScDetId.cc:64
T getParameter(std::string const &) const
EcalIntercalibConstantMCMap EcalIntercalibConstantsMC
T getUntrackedParameter(std::string const &, T const &) const
float alpha
Definition: AMPTWrapper.h:95
static const int MIN_IPHI
Definition: EBDetId.h:142
static Timestamp endOfTime()
Definition: Timestamp.h:102
void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &) override
virtual std::unique_ptr< EcalDQMChannelStatus > produceEcalDQMChannelStatus(const EcalDQMChannelStatusRcd &)
virtual std::unique_ptr< EcalIntercalibConstants > produceEcalIntercalibConstants(const EcalIntercalibConstantsRcd &)
virtual std::unique_ptr< EcalIntercalibErrors > produceEcalIntercalibErrors(const EcalIntercalibErrorsRcd &)
virtual std::unique_ptr< EcalLaserAPDPNRatiosRef > produceEcalLaserAPDPNRatiosRef(const EcalLaserAPDPNRatiosRefRcd &)
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
def copy(args, dbName)
virtual std::unique_ptr< EcalSamplesCorrelation > produceEcalSamplesCorrelation(const EcalSamplesCorrelationRcd &)
const self & getMap() const
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
virtual std::unique_ptr< EcalTimeCalibConstants > produceEcalTimeCalibConstants(const EcalTimeCalibConstantsRcd &)
virtual std::unique_ptr< EcalMappingElectronics > getMappingFromConfiguration(const EcalMappingElectronicsRcd &)
static const int XYMODE
Definition: EEDetId.h:339
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
virtual std::unique_ptr< EcalADCToGeVConstant > produceEcalADCToGeVConstant(const EcalADCToGeVConstantRcd &)
virtual std::unique_ptr< EcalWeightXtalGroups > produceEcalWeightXtalGroups(const EcalWeightXtalGroupsRcd &)
virtual std::unique_ptr< EcalChannelStatus > produceEcalChannelStatus(const EcalChannelStatusRcd &)
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
void getWeightsFromConfiguration(const edm::ParameterSet &ps)
double calcresolutitonConstantTerm(double eta)
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:99
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
static const int IX_MIN
Definition: EEDetId.h:294
static int readXML(const std::string &filename, EcalCondHeader &header, EcalFloatCondObjectContainer &record)
static const int IY_MIN
Definition: EEDetId.h:298
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:124
virtual std::unique_ptr< EcalLaserAlphas > produceEcalLaserAlphas(const EcalLaserAlphasRcd &)
static const int MIN_SM
Definition: EBDetId.h:152
void setGain12Over6(const float &g)
virtual std::unique_ptr< EcalClusterEnergyUncertaintyParameters > produceEcalClusterEnergyUncertaintyParameters(const EcalClusterEnergyUncertaintyParametersRcd &)
virtual std::unique_ptr< Alignments > produceEcalAlignmentEB(const EBAlignmentRcd &)
void setValue(const uint32_t id, const Item &item)
virtual std::unique_ptr< EcalClusterEnergyCorrectionParameters > produceEcalClusterEnergyCorrectionParameters(const EcalClusterEnergyCorrectionParametersRcd &)
virtual std::unique_ptr< EcalIntercalibConstantsMC > getIntercalibConstantsMCFromConfiguration(const EcalIntercalibConstantsMCRcd &)
static const IOVSyncValue & beginOfTime()
double calcnoiseIncreaseADC(double eta)
virtual std::unique_ptr< EcalDQMTowerStatus > produceEcalDQMTowerStatus(const EcalDQMTowerStatusRcd &)
T sqrt(T t)
Definition: SSEVec.h:18
virtual std::unique_ptr< Alignments > produceEcalAlignmentEE(const EEAlignmentRcd &)
virtual std::unique_ptr< EcalLinearCorrections > produceEcalLinearCorrections(const EcalLinearCorrectionsRcd &)
virtual std::unique_ptr< EcalMappingElectronics > produceEcalMappingElectronics(const EcalMappingElectronicsRcd &)
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
EcalChi2WeightMatrix & getChi2WeightsAfterGainSwitch()
Definition: EcalWeightSet.h:32
virtual std::unique_ptr< EcalLaserAPDPNRatios > produceEcalLaserAPDPNRatios(const EcalLaserAPDPNRatiosRcd &)
virtual std::unique_ptr< EcalChannelStatus > getChannelStatusFromConfiguration(const EcalChannelStatusRcd &)
double f[11][100]
virtual std::unique_ptr< EcalTimeBiasCorrections > produceEcalTimeBiasCorrections(const EcalTimeBiasCorrectionsRcd &)
virtual std::unique_ptr< EcalIntercalibConstants > getIntercalibConstantsFromConfiguration(const EcalIntercalibConstantsRcd &)
virtual std::unique_ptr< EcalIntercalibConstantsMC > produceEcalIntercalibConstantsMC(const EcalIntercalibConstantsMCRcd &)
virtual std::unique_ptr< Alignments > produceEcalAlignmentES(const ESAlignmentRcd &)
EcalWeightMatrix & getWeightsAfterGainSwitch()
Definition: EcalWeightSet.h:30
uint32_t rawId() const
ii
Definition: cuy.py:590
const int drop
int k[5][pyjets_maxn]
math::Matrix< 10, 10 >::type EcalChi2WeightMatrix
Definition: EcalWeightSet.h:23
static const int IX_MAX
Definition: EEDetId.h:302
virtual std::unique_ptr< EcalPedestals > produceEcalPedestals(const EcalPedestalsRcd &)
virtual std::unique_ptr< EcalClusterEnergyCorrectionObjectSpecificParameters > produceEcalClusterEnergyCorrectionObjectSpecificParameters(const EcalClusterEnergyCorrectionObjectSpecificParametersRcd &)
static const int MAX_IPHI
Definition: EBDetId.h:144
EcalWeightMatrix & getWeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:29
virtual std::unique_ptr< EcalDCSTowerStatus > produceEcalDCSTowerStatus(const EcalDCSTowerStatusRcd &)
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
EcalTrivialConditionRetriever(const edm::ParameterSet &pset)
std::vector< Item >::const_iterator const_iterator
static const int MAX_IETA
Definition: EBDetId.h:143
virtual std::unique_ptr< EcalClusterLocalContCorrParameters > produceEcalClusterLocalContCorrParameters(const EcalClusterLocalContCorrParametersRcd &)
virtual std::unique_ptr< EcalTimeCalibErrors > getTimeCalibErrorsFromConfiguration(const EcalTimeCalibErrorsRcd &)
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.h:114
EcalIntercalibConstantMap EcalIntercalibConstants
virtual std::unique_ptr< EcalGainRatios > produceEcalGainRatios(const EcalGainRatiosRcd &)
static bool validDetId(int iz, EcalSubdetector sd, int i, int j)
check if a valid index combination
virtual std::unique_ptr< EcalTPGCrystalStatus > produceEcalTrgChannelStatus(const EcalTPGCrystalStatusRcd &)
#define begin
Definition: vmac.h:32
HLT enums.
virtual std::unique_ptr< EcalTimeCalibErrors > produceEcalTimeCalibErrors(const EcalTimeCalibErrorsRcd &)
batch
Use ROOT&#39;s batch mode, unless outputting to C macros, since there is a bug in pyROOT that fails to ex...
Definition: core.py:64
double a
Definition: hdecay.h:121
virtual std::unique_ptr< EcalTBWeights > produceEcalTBWeights(const EcalTBWeightsRcd &)
virtual std::unique_ptr< EcalTimeOffsetConstant > produceEcalTimeOffsetConstant(const EcalTimeOffsetConstantRcd &)
Signal rand(Signal arg)
Definition: vlib.cc:442
const_iterator find(uint32_t rawId) const
math::Matrix< 3, 10 >::type EcalWeightMatrix
Definition: EcalWeightSet.h:22
std::string fullPath() const
Definition: FileInPath.cc:197
const Timestamp & time() const
Definition: IOVSyncValue.h:44
static const int MAX_SM
Definition: EBDetId.h:153
virtual std::unique_ptr< EcalTimeCalibConstants > getTimeCalibConstantsFromConfiguration(const EcalTimeCalibConstantsRcd &)
static const int IY_MAX
Definition: EEDetId.h:306
const_iterator end() const
virtual std::unique_ptr< EcalTPGCrystalStatus > getTrgChannelStatusFromConfiguration(const EcalTPGCrystalStatusRcd &)
float EcalIntercalibConstantMC
virtual std::unique_ptr< EcalSampleMask > produceEcalSampleMask(const EcalSampleMaskRcd &)
virtual std::unique_ptr< EcalIntercalibErrors > getIntercalibErrorsFromConfiguration(const EcalIntercalibErrorsRcd &)
static const int SMCRYSTALMODE
Definition: EBDetId.h:167
#define str(s)
double calcampDropTotal(double eta)
TimeValue_t value() const
Definition: Timestamp.h:56
Ecal trigger electronics identification [32:20] Unused (so far) [19:13] TCC id [12:6] TT id [5:3] pse...
virtual std::unique_ptr< EcalDAQTowerStatus > produceEcalDAQTowerStatus(const EcalDAQTowerStatusRcd &)
virtual std::unique_ptr< EcalSimPulseShape > getEcalSimPulseShapeFromConfiguration(const EcalSimPulseShapeRcd &)
float EcalIntercalibConstant
virtual std::unique_ptr< EcalClusterCrackCorrParameters > produceEcalClusterCrackCorrParameters(const EcalClusterCrackCorrParametersRcd &)