CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalTrivialConditionRetriever.cc
Go to the documentation of this file.
1 //
2 // $Id: EcalTrivialConditionRetriever.cc,v 1.47 2010/01/29 10:45:27 fra Exp $
3 // Created: 2 Mar 2006
4 // Shahram Rahatlou, University of Rome & INFN
5 //
6 #include <iostream>
7 #include <fstream>
8 
12 
18 
19 //#include "DataFormats/Provenance/interface/Timestamp.h"
20 
22 
23 
24 using namespace edm;
25 
27 {
28 
29  // initilize parameters used to produce cond DB objects
30  adcToGeVEBConstant_ = ps.getUntrackedParameter<double>("adcToGeVEBConstant",0.035);
31  adcToGeVEEConstant_ = ps.getUntrackedParameter<double>("adcToGeVEEConstant",0.060);
32 
33  intercalibConstantMeanMC_ = ps.getUntrackedParameter<double>("intercalibConstantMeanMC",1.0);
34  intercalibConstantSigmaMC_ = ps.getUntrackedParameter<double>("intercalibConstantSigmaMC",0.0);
35 
36  intercalibConstantMean_ = ps.getUntrackedParameter<double>("intercalibConstantMean",1.0);
37  intercalibConstantSigma_ = ps.getUntrackedParameter<double>("intercalibConstantSigma",0.0);
38  intercalibErrorMean_ = ps.getUntrackedParameter<double>("IntercalibErrorMean",0.0);
39 
40  timeCalibConstantMean_ = ps.getUntrackedParameter<double>("timeCalibConstantMean",0.0);
41  timeCalibConstantSigma_ = ps.getUntrackedParameter<double>("timeCalibConstantSigma",0.0);
42  timeCalibErrorMean_ = ps.getUntrackedParameter<double>("timeCalibErrorMean",0.0);
43 
44  laserAlphaMean_ = ps.getUntrackedParameter<double>("laserAlphaMean",1.55);
45  laserAlphaSigma_ = ps.getUntrackedParameter<double>("laserAlphaSigma",0);
46 
47  laserAPDPNTime1_ = (unsigned long)atoi( ps.getUntrackedParameter<std::string>("laserAPDPNTime1","1").c_str());
48  laserAPDPNTime2_= (unsigned long)atoi( ps.getUntrackedParameter<std::string>("laserAPDPNTime2","0").c_str());
49  laserAPDPNTime3_= (unsigned long)atoi( ps.getUntrackedParameter<std::string>("laserAPDPNTime3","0").c_str());
50 
51  laserAPDPNRefMean_ = ps.getUntrackedParameter<double>("laserAPDPNRefMean",1.0);
52  laserAPDPNRefSigma_ = ps.getUntrackedParameter<double>("laserAPDPNRefSigma",0.0);
53 
54  laserAPDPNMean_ = ps.getUntrackedParameter<double>("laserAPDPNMean",1.0);
55  laserAPDPNSigma_ = ps.getUntrackedParameter<double>("laserAPDPNSigma",0.0);
56 
57  localContCorrParameters_ = ps.getUntrackedParameter< std::vector<double> >("localContCorrParameters", std::vector<double>(0) );
58  crackCorrParameters_ = ps.getUntrackedParameter< std::vector<double> >("crackCorrParameters", std::vector<double>(0) );
59  energyCorrectionParameters_ = ps.getUntrackedParameter< std::vector<double> >("energyCorrectionParameters", std::vector<double>(0) );
60  energyUncertaintyParameters_ = ps.getUntrackedParameter< std::vector<double> >("energyUncertaintyParameters", std::vector<double>(0) );
61 
62  EBpedMeanX12_ = ps.getUntrackedParameter<double>("EBpedMeanX12", 200.);
63  EBpedRMSX12_ = ps.getUntrackedParameter<double>("EBpedRMSX12", 1.10);
64  EBpedMeanX6_ = ps.getUntrackedParameter<double>("EBpedMeanX6", 200.);
65  EBpedRMSX6_ = ps.getUntrackedParameter<double>("EBpedRMSX6", 0.90);
66  EBpedMeanX1_ = ps.getUntrackedParameter<double>("EBpedMeanX1", 200.);
67  EBpedRMSX1_ = ps.getUntrackedParameter<double>("EBpedRMSX1", 0.62);
68 
69  EEpedMeanX12_ = ps.getUntrackedParameter<double>("EEpedMeanX12", 200.);
70  EEpedRMSX12_ = ps.getUntrackedParameter<double>("EEpedRMSX12", 2.50);
71  EEpedMeanX6_ = ps.getUntrackedParameter<double>("EEpedMeanX6", 200.);
72  EEpedRMSX6_ = ps.getUntrackedParameter<double>("EEpedRMSX6", 2.00);
73  EEpedMeanX1_ = ps.getUntrackedParameter<double>("EEpedMeanX1", 200.);
74  EEpedRMSX1_ = ps.getUntrackedParameter<double>("EEpedRMSX1", 1.40);
75 
76  gainRatio12over6_ = ps.getUntrackedParameter<double>("gainRatio12over6", 2.0);
77  gainRatio6over1_ = ps.getUntrackedParameter<double>("gainRatio6over1", 6.0);
78 
79  getWeightsFromFile_ = ps.getUntrackedParameter<bool>("getWeightsFromFile",false);
80 
81  nTDCbins_ = 1;
82 
83  weightsForAsynchronousRunning_ = ps.getUntrackedParameter<bool>("weightsForTB",false);
84 
85  if (weightsForAsynchronousRunning_)
86  {
87  getWeightsFromFile_ = true; //override user request
88  //nTDCbins_ = 25;
89  nTDCbins_ = 50; //modif Alex-21-07-2006
90  }
91 
92  std::string path="CalibCalorimetry/EcalTrivialCondModules/data/";
93  std::string weightType;
94  std::ostringstream str;
95 
96  if (!weightsForAsynchronousRunning_)
97  str << "_CMS.txt" ;
98  else
99  str << "_TB.txt" ;
100 
101  weightType = str.str();
102 
103  amplWeightsFile_ = ps.getUntrackedParameter<std::string>("amplWeightsFile",path+"ampWeights"+weightType);
104  amplWeightsAftFile_ = ps.getUntrackedParameter<std::string>("amplWeightsAftFile",path+"ampWeightsAfterGainSwitch"+weightType);
105  pedWeightsFile_ = ps.getUntrackedParameter<std::string>("pedWeightsFile",path+"pedWeights"+weightType);
106  pedWeightsAftFile_ = ps.getUntrackedParameter<std::string>("pedWeightsAftFile",path+"pedWeightsAfterGainSwitch"+weightType);
107  jittWeightsFile_ = ps.getUntrackedParameter<std::string>("jittWeightsFile",path+"timeWeights"+weightType);
108  jittWeightsAftFile_ = ps.getUntrackedParameter<std::string>("jittWeightsAftFile",path+"timeWeightsAfterGainSwitch"+weightType);
109  chi2MatrixFile_ = ps.getUntrackedParameter<std::string>("chi2MatrixFile",path+"chi2Matrix"+weightType);
110  chi2MatrixAftFile_ = ps.getUntrackedParameter<std::string>("chi2MatrixAftFile",path+"chi2MatrixAfterGainSwitch"+weightType);
111 
112  amplWeights_.resize(nTDCbins_);
113  amplWeightsAft_.resize(nTDCbins_);
114  pedWeights_.resize(nTDCbins_);
115  pedWeightsAft_.resize(nTDCbins_);
116  jittWeights_.resize(nTDCbins_);
117  jittWeightsAft_.resize(nTDCbins_);
118  chi2Matrix_.resize(nTDCbins_);
119  chi2MatrixAft_.resize(nTDCbins_);
120 
121  // default weights for MGPA shape after pedestal subtraction
122  getWeightsFromConfiguration(ps);
123 
124  producedEcalPedestals_ = ps.getUntrackedParameter<bool>("producedEcalPedestals",true);
125  producedEcalWeights_ = ps.getUntrackedParameter<bool>("producedEcalWeights",true);
126 
127  producedEcalGainRatios_ = ps.getUntrackedParameter<bool>("producedEcalGainRatios",true);
128  producedEcalADCToGeVConstant_ = ps.getUntrackedParameter<bool>("producedEcalADCToGeVConstant",true);
129 
130  producedEcalMappingElectronics_ = ps.getUntrackedParameter<bool>("producedEcalMappingElectronics",true);
131  mappingFile_ = ps.getUntrackedParameter<std::string>("mappingFile","");
132 
133  if ( producedEcalMappingElectronics_ ) {
134  if ( mappingFile_ != "" ) { // if file provided read channel map
136  } else {
138  }
139  findingRecord<EcalMappingElectronicsRcd>();
140  }
141 
142  verbose_ = ps.getUntrackedParameter<int>("verbose", 0);
143 
144  //Tell Producer what we produce
145  //setWhatproduce(this);
146  if (producedEcalPedestals_)
148 
149  if (producedEcalWeights_) {
152  }
153 
154  if (producedEcalGainRatios_)
156 
157  if (producedEcalADCToGeVConstant_)
159 
160  // intercalibration constants
161  producedEcalIntercalibConstants_ = ps.getUntrackedParameter<bool>("producedEcalIntercalibConstants",true);
162  intercalibConstantsFile_ = ps.getUntrackedParameter<std::string>("intercalibConstantsFile","") ;
163 
164  if (producedEcalIntercalibConstants_) { // user asks to produce constants
165  if(intercalibConstantsFile_ != "") { // if file provided read constants
167  } else { // set all constants to 1. or smear as specified by user
169  }
170  findingRecord<EcalIntercalibConstantsRcd> () ;
171  }
172  // MC intercalibrations
173  producedEcalIntercalibConstantsMC_ = ps.getUntrackedParameter<bool>("producedEcalIntercalibConstantsMC",true);
174 
175  if (producedEcalIntercalibConstantsMC_) { // user asks to produce constants
177  findingRecord<EcalIntercalibConstantsMCRcd> () ;
178  }
179 
180  // intercalibration constants
181  producedEcalIntercalibErrors_ = ps.getUntrackedParameter<bool>("producedEcalIntercalibErrors",true);
182  intercalibErrorsFile_ = ps.getUntrackedParameter<std::string>("intercalibErrorsFile","") ;
183 
184  if (producedEcalIntercalibErrors_) { // user asks to produce constants
185  if(intercalibErrorsFile_ != "") { // if file provided read constants
187  } else { // set all constants to 1. or smear as specified by user
189  }
190  findingRecord<EcalIntercalibErrorsRcd> () ;
191  }
192 
193  // time calibration constants
194  producedEcalTimeCalibConstants_ = ps.getUntrackedParameter<bool>("producedEcalTimeCalibConstants",true);
195  timeCalibConstantsFile_ = ps.getUntrackedParameter<std::string>("timeCalibConstantsFile","") ;
196 
197  if (producedEcalTimeCalibConstants_) { // user asks to produce constants
198  if(timeCalibConstantsFile_ != "") { // if file provided read constants
200  } else { // set all constants to 1. or smear as specified by user
202  }
203  findingRecord<EcalTimeCalibConstantsRcd> () ;
204  }
205 
206  // time calibration constants
207  producedEcalTimeCalibErrors_ = ps.getUntrackedParameter<bool>("producedEcalTimeCalibErrors",true);
208  timeCalibErrorsFile_ = ps.getUntrackedParameter<std::string>("timeCalibErrorsFile","") ;
209 
210  if (producedEcalTimeCalibErrors_) { // user asks to produce constants
211  if(timeCalibErrorsFile_ != "") { // if file provided read constants
213  } else { // set all constants to 1. or smear as specified by user
215  }
216  findingRecord<EcalTimeCalibErrorsRcd> () ;
217  }
218 
219  // cluster corrections
220  producedEcalClusterLocalContCorrParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterLocalContCorrParameters", true);
221  producedEcalClusterCrackCorrParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterCrackCorrParameters", true);
222  producedEcalClusterEnergyCorrectionParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterEnergyCorrectionParameters", true);
223  producedEcalClusterEnergyUncertaintyParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterEnergyUncertaintyParameters", true);
224  if ( producedEcalClusterLocalContCorrParameters_ ) {
226  findingRecord<EcalClusterLocalContCorrParametersRcd>();
227  }
228  if ( producedEcalClusterCrackCorrParameters_ ) {
230  findingRecord<EcalClusterCrackCorrParametersRcd>();
231  }
232  if ( producedEcalClusterEnergyCorrectionParameters_ ) {
234  findingRecord<EcalClusterEnergyCorrectionParametersRcd>();
235  }
236  if ( producedEcalClusterEnergyUncertaintyParameters_ ) {
238  findingRecord<EcalClusterEnergyUncertaintyParametersRcd>();
239  }
240 
241  // laser correction
242  producedEcalLaserCorrection_ = ps.getUntrackedParameter<bool>("producedEcalLaserCorrection",true);
243  if (producedEcalLaserCorrection_) { // user asks to produce constants
244  // set all constants to 1. or smear as specified by user
246  findingRecord<EcalLaserAlphasRcd> () ;
248  findingRecord<EcalLaserAPDPNRatiosRefRcd> () ;
250  findingRecord<EcalLaserAPDPNRatiosRcd> () ;
251  }
252 
253  // channel status
254  producedEcalChannelStatus_ = ps.getUntrackedParameter<bool>("producedEcalChannelStatus",true);
255  channelStatusFile_ = ps.getUntrackedParameter<std::string>("channelStatusFile","");
256 
257  if ( producedEcalChannelStatus_ ) {
258  if ( channelStatusFile_ != "" ) { // if file provided read channel map
260  } else { // set all channels to working -- FIXME might be changed
262  }
263  findingRecord<EcalChannelStatusRcd>();
264  }
265  // DQM channel status
266  producedEcalDQMChannelStatus_ = ps.getUntrackedParameter<bool>("producedEcalDQMChannelStatus",true);
267  if ( producedEcalDQMChannelStatus_ ) {
269  findingRecord<EcalDQMChannelStatusRcd>();
270  }
271  // DCS Tower status
272  producedEcalDCSTowerStatus_ = ps.getUntrackedParameter<bool>("producedEcalDCSTowerStatus",true);
273  if ( producedEcalDCSTowerStatus_ ) {
275  findingRecord<EcalDCSTowerStatusRcd>();
276  }
277  // DAQ Tower status
278  producedEcalDAQTowerStatus_ = ps.getUntrackedParameter<bool>("producedEcalDAQTowerStatus",true);
279  if ( producedEcalDAQTowerStatus_ ) {
281  findingRecord<EcalDAQTowerStatusRcd>();
282  }
283  // DQM Tower status
284  producedEcalDQMTowerStatus_ = ps.getUntrackedParameter<bool>("producedEcalDQMTowerStatus",true);
285  if ( producedEcalDQMTowerStatus_ ) {
287  findingRecord<EcalDQMTowerStatusRcd>();
288  }
289 
290  // trigger channel status
291  producedEcalTrgChannelStatus_ = ps.getUntrackedParameter<bool>("producedEcalTrgChannelStatus",true);
292  trgChannelStatusFile_ = ps.getUntrackedParameter<std::string>("trgChannelStatusFile","");
293 
294  if ( producedEcalTrgChannelStatus_ ) {
295  if ( trgChannelStatusFile_ != "" ) { // if file provided read channel map
297  } else { // set all channels to working -- FIXME might be changed
299  }
300  findingRecord<EcalTPGCrystalStatusRcd>();
301  }
302 
303  //Tell Finder what records we find
304  if (producedEcalPedestals_) findingRecord<EcalPedestalsRcd>();
305 
306  if (producedEcalWeights_) {
307  findingRecord<EcalWeightXtalGroupsRcd>();
308  findingRecord<EcalTBWeightsRcd>();
309  }
310 
311  if (producedEcalGainRatios_) findingRecord<EcalGainRatiosRcd>();
312 
313  if (producedEcalADCToGeVConstant_) findingRecord<EcalADCToGeVConstantRcd>();
314 
315 }
316 
318 {
319 }
320 
321 //
322 // member functions
323 //
324 void
326  const edm::IOVSyncValue& iTime,
327  edm::ValidityInterval& oValidity)
328 {
329  if(verbose_>=1) std::cout << "EcalTrivialConditionRetriever::setIntervalFor(): record key = " << rk.name() << "\ttime: " << iTime.time().value() << std::endl;
330  //For right now, we will just use an infinite interval of validity
332 }
333 
334 //produce methods
335 std::auto_ptr<EcalPedestals>
337  std::auto_ptr<EcalPedestals> peds = std::auto_ptr<EcalPedestals>( new EcalPedestals() );
338  EcalPedestals::Item EBitem;
339  EcalPedestals::Item EEitem;
340 
341  EBitem.mean_x1 = EBpedMeanX1_;
342  EBitem.rms_x1 = EBpedRMSX1_;
343  EBitem.mean_x6 = EBpedMeanX6_;
344  EBitem.rms_x6 = EBpedRMSX6_;
345  EBitem.mean_x12 = EBpedMeanX12_;
346  EBitem.rms_x12 = EBpedRMSX12_;
347 
348  EEitem.mean_x1 = EEpedMeanX1_;
349  EEitem.rms_x1 = EEpedRMSX1_;
350  EEitem.mean_x6 = EEpedMeanX6_;
351  EEitem.rms_x6 = EEpedRMSX6_;
352  EEitem.mean_x12 = EEpedMeanX12_;
353  EEitem.rms_x12 = EEpedRMSX12_;
354 
355  for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
356  if(iEta==0) continue;
357  for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
358  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
359  if (EBDetId::validDetId(iEta,iPhi))
360  {
361  EBDetId ebdetid(iEta,iPhi);
362  peds->insert(std::make_pair(ebdetid.rawId(),EBitem));
363  }
364  }
365  }
366 
367  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
368  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
369  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
370  if (EEDetId::validDetId(iX,iY,1))
371  {
372  EEDetId eedetidpos(iX,iY,1);
373  peds->insert(std::make_pair(eedetidpos.rawId(),EEitem));
374  }
375  if(EEDetId::validDetId(iX,iY,-1))
376  {
377  EEDetId eedetidneg(iX,iY,-1);
378  peds->insert(std::make_pair(eedetidneg.rawId(),EEitem));
379  }
380  }
381  }
382 
383  //return std::auto_ptr<EcalPedestals>( peds );
384  return peds;
385 }
386 
387 std::auto_ptr<EcalWeightXtalGroups>
389 {
390  std::auto_ptr<EcalWeightXtalGroups> xtalGroups = std::auto_ptr<EcalWeightXtalGroups>( new EcalWeightXtalGroups() );
391  EcalXtalGroupId defaultGroupId(1);
392  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
393  if(ieta==0) continue;
394  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
395  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
396  if (EBDetId::validDetId(ieta,iphi))
397  {
398  EBDetId ebid(ieta,iphi);
399  // xtalGroups->setValue(ebid.rawId(), EcalXtalGroupId(ieta) ); // define rings in eta
400  xtalGroups->setValue(ebid.rawId(), defaultGroupId ); // define rings in eta
401  }
402  }
403  }
404 
405  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
406  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
407  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
408  if (EEDetId::validDetId(iX,iY,1))
409  {
410  EEDetId eedetidpos(iX,iY,1);
411  xtalGroups->setValue(eedetidpos.rawId(), defaultGroupId );
412  }
413  if(EEDetId::validDetId(iX,iY,-1))
414  {
415  EEDetId eedetidneg(iX,iY,-1);
416  xtalGroups->setValue(eedetidneg.rawId(), defaultGroupId );
417  }
418  }
419  }
420  return xtalGroups;
421 }
422 
423 std::auto_ptr<EcalIntercalibConstants>
425 {
426  std::auto_ptr<EcalIntercalibConstants> ical = std::auto_ptr<EcalIntercalibConstants>( new EcalIntercalibConstants() );
427 
428  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
429  if(ieta==0) continue;
430  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
431  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
432  if (EBDetId::validDetId(ieta,iphi))
433  {
434  EBDetId ebid(ieta,iphi);
435  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
436  ical->setValue( ebid.rawId(), intercalibConstantMean_ + r*intercalibConstantSigma_ );
437  }
438  }
439  }
440 
441  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
442  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
443  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
444  if (EEDetId::validDetId(iX,iY,1))
445  {
446  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
447  EEDetId eedetidpos(iX,iY,1);
448  ical->setValue( eedetidpos.rawId(), intercalibConstantMean_ + r*intercalibConstantSigma_ );
449  }
450  if(EEDetId::validDetId(iX,iY,-1))
451  {
452  double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
453  EEDetId eedetidneg(iX,iY,-1);
454  ical->setValue( eedetidneg.rawId(), intercalibConstantMean_ + r1*intercalibConstantSigma_ );
455  }
456  }
457  }
458 
459  return ical;
460 }
461 
462 std::auto_ptr<EcalIntercalibConstantsMC>
464 {
465  std::auto_ptr<EcalIntercalibConstantsMC> ical = std::auto_ptr<EcalIntercalibConstantsMC>( new EcalIntercalibConstantsMC() );
466 
467  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
468  if(ieta==0) continue;
469  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
470  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
471  if (EBDetId::validDetId(ieta,iphi))
472  {
473  EBDetId ebid(ieta,iphi);
474  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
475  ical->setValue( ebid.rawId(), intercalibConstantMeanMC_ + r*intercalibConstantSigmaMC_ );
476  }
477  }
478  }
479 
480  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
481  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
482  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
483  if (EEDetId::validDetId(iX,iY,1))
484  {
485  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
486  EEDetId eedetidpos(iX,iY,1);
487  ical->setValue( eedetidpos.rawId(), intercalibConstantMeanMC_ + r*intercalibConstantSigmaMC_ );
488  }
489  if(EEDetId::validDetId(iX,iY,-1))
490  {
491  double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
492  EEDetId eedetidneg(iX,iY,-1);
493  ical->setValue( eedetidneg.rawId(), intercalibConstantMeanMC_ + r1*intercalibConstantSigmaMC_ );
494  }
495  }
496  }
497 
498  return ical;
499 }
500 
501 std::auto_ptr<EcalIntercalibErrors>
503 {
504  std::auto_ptr<EcalIntercalibErrors> ical = std::auto_ptr<EcalIntercalibErrors>( new EcalIntercalibErrors() );
505 
506  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
507  if(ieta==0) continue;
508  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
509  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
510  if (EBDetId::validDetId(ieta,iphi))
511  {
512  EBDetId ebid(ieta,iphi);
513  ical->setValue( ebid.rawId(), intercalibErrorMean_);
514  }
515  }
516  }
517 
518  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
519  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
520  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
521  if (EEDetId::validDetId(iX,iY,1))
522  {
523  EEDetId eedetidpos(iX,iY,1);
524  ical->setValue( eedetidpos.rawId(), intercalibErrorMean_ );
525  }
526  if(EEDetId::validDetId(iX,iY,-1))
527  {
528  EEDetId eedetidneg(iX,iY,-1);
529  ical->setValue( eedetidneg.rawId(), intercalibErrorMean_ );
530  }
531  }
532  }
533 
534  return ical;
535 }
536 
537 std::auto_ptr<EcalTimeCalibConstants>
539 {
540  std::auto_ptr<EcalTimeCalibConstants> ical = std::auto_ptr<EcalTimeCalibConstants>( new EcalTimeCalibConstants() );
541 
542  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
543  if(ieta==0) continue;
544  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
545  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
546  if (EBDetId::validDetId(ieta,iphi))
547  {
548  EBDetId ebid(ieta,iphi);
549  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
550  ical->setValue( ebid.rawId(), timeCalibConstantMean_ + r*timeCalibConstantSigma_ );
551  }
552  }
553  }
554 
555  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
556  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
557  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
558  if (EEDetId::validDetId(iX,iY,1))
559  {
560  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
561  EEDetId eedetidpos(iX,iY,1);
562  ical->setValue( eedetidpos.rawId(), timeCalibConstantMean_ + r*timeCalibConstantSigma_ );
563  }
564  if(EEDetId::validDetId(iX,iY,-1))
565  {
566  double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
567  EEDetId eedetidneg(iX,iY,-1);
568  ical->setValue( eedetidneg.rawId(), timeCalibConstantMean_ + r1*timeCalibConstantSigma_ );
569  }
570  }
571  }
572 
573  return ical;
574 }
575 
576 std::auto_ptr<EcalTimeCalibErrors>
578 {
579  std::auto_ptr<EcalTimeCalibErrors> ical = std::auto_ptr<EcalTimeCalibErrors>( new EcalTimeCalibErrors() );
580 
581  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
582  if(ieta==0) continue;
583  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
584  // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
585  if (EBDetId::validDetId(ieta,iphi))
586  {
587  EBDetId ebid(ieta,iphi);
588  ical->setValue( ebid.rawId(), timeCalibErrorMean_);
589  }
590  }
591  }
592 
593  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
594  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
595  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
596  if (EEDetId::validDetId(iX,iY,1))
597  {
598  EEDetId eedetidpos(iX,iY,1);
599  ical->setValue( eedetidpos.rawId(), timeCalibErrorMean_ );
600  }
601  if(EEDetId::validDetId(iX,iY,-1))
602  {
603  EEDetId eedetidneg(iX,iY,-1);
604  ical->setValue( eedetidneg.rawId(), timeCalibErrorMean_ );
605  }
606  }
607  }
608 
609  return ical;
610 }
611 
612 std::auto_ptr<EcalGainRatios>
614 {
615  std::auto_ptr<EcalGainRatios> gratio = std::auto_ptr<EcalGainRatios>( new EcalGainRatios() );
617  gr.setGain12Over6( gainRatio12over6_ );
618  gr.setGain6Over1( gainRatio6over1_ );
619 
620  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
621  if(ieta==0) continue;
622  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
623  if (EBDetId::validDetId(ieta,iphi))
624  {
625  EBDetId ebid(ieta,iphi);
626  gratio->setValue( ebid.rawId(), gr );
627  }
628  }
629  }
630 
631  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
632  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
633  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
634  if (EEDetId::validDetId(iX,iY,1))
635  {
636  EEDetId eedetidpos(iX,iY,1);
637  gratio->setValue( eedetidpos.rawId(), gr );
638  }
639  if (EEDetId::validDetId(iX,iY,-1))
640  {
641  EEDetId eedetidneg(iX,iY,-1);
642  gratio->setValue( eedetidneg.rawId(), gr );
643  }
644  }
645  }
646 
647  return gratio;
648 }
649 
650 std::auto_ptr<EcalADCToGeVConstant>
652 {
653  return std::auto_ptr<EcalADCToGeVConstant>( new EcalADCToGeVConstant(adcToGeVEBConstant_,adcToGeVEEConstant_) );
654 }
655 
656 std::auto_ptr<EcalTBWeights>
658 {
659  // create weights for the test-beam
660  std::auto_ptr<EcalTBWeights> tbwgt = std::auto_ptr<EcalTBWeights>( new EcalTBWeights() );
661 
662  // create weights for each distinct group ID
663  // int nMaxTDC = 10;
664 // for(int igrp=-EBDetId::MAX_IETA; igrp<=EBDetId::MAX_IETA; ++igrp) {
665 // if(igrp==0) continue;
666  int igrp=1;
667  for(int itdc=1; itdc<=nTDCbins_; ++itdc) {
668  // generate random number
669  // double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
670 
671  // make a new set of weights
672  EcalWeightSet wgt;
673  //typedef std::vector< std::vector<EcalWeight> > EcalWeightSet::EcalWeightMatrix;
676 
677 // if(verbose_>=1) {
678 // std::cout << "initial size of mat1: " << mat1.size() << std::endl;
679 // std::cout << "initial size of mat2: " << mat2.size() << std::endl;
680 // }
681 
682  // generate random numbers to use as weights
697  // use values provided by user
698  mat1.Place_in_row(amplWeights_[itdc-1],0,0);
699  mat1.Place_in_row(pedWeights_[itdc-1],1,0);
700  mat1.Place_in_row(jittWeights_[itdc-1],2,0);
701 
702  // wdights after gain switch
703  mat2.Place_in_row(amplWeightsAft_[itdc-1],0,0);
704  mat2.Place_in_row(pedWeightsAft_[itdc-1],1,0);
705  mat2.Place_in_row(jittWeightsAft_[itdc-1],2,0);
706 
707  // fill the chi2 matrcies with random numbers
708  // r = (double)std::rand()/( double(RAND_MAX)+double(1) );
711  mat3=chi2Matrix_[itdc-1];
712  mat4=chi2MatrixAft_[itdc-1];
713 
714  // for(size_t i=0; i<10; ++i)
715  // {
716  // mat3.push_back(chi2Matrix_[itdc-1][i]);
717  // mat4.push_back(chi2MatrixAft_[itdc-1][i]);
718  // }
719  // std::vector<EcalWeight> tv1, tv2;
720  // for(size_t j=0; j<10; ++j) {
721  // double ww = igrp*itdc*r + i*10. + j;
722  // tv1.push_back( EcalWeight(1000+ww) );
723  // tv2.push_back( EcalWeight(1000+100+ww) );
724  // }
725 
726 
727 
728 
729 // if(verbose_>=1) {
730 // std::cout << "group: " << igrp << " TDC: " << itdc
731 // << " mat1: " << mat1.size() << " mat2: " << mat2.size()
732 // << " mat3: " << mat3.size() << " mat4: " << mat4.size()
733 // << std::endl;
734 // }
735 
736  // put the weight in the container
737  tbwgt->setValue(std::make_pair(igrp,itdc), wgt);
738  }
739  // }
740  return tbwgt;
741 }
742 
743 
744 // cluster functions/corrections
745 std::auto_ptr<EcalClusterLocalContCorrParameters>
747 {
748  std::auto_ptr<EcalClusterLocalContCorrParameters> ipar = std::auto_ptr<EcalClusterLocalContCorrParameters>( new EcalClusterLocalContCorrParameters() );
749  for (size_t i = 0; i < localContCorrParameters_.size(); ++i ) {
750  ipar->params().push_back( localContCorrParameters_[i] );
751  }
752  return ipar;
753 }
754 std::auto_ptr<EcalClusterCrackCorrParameters>
756 {
757  std::auto_ptr<EcalClusterCrackCorrParameters> ipar = std::auto_ptr<EcalClusterCrackCorrParameters>( new EcalClusterCrackCorrParameters() );
758  for (size_t i = 0; i < crackCorrParameters_.size(); ++i ) {
759  ipar->params().push_back( crackCorrParameters_[i] );
760  }
761  return ipar;
762 }
763 std::auto_ptr<EcalClusterEnergyCorrectionParameters>
765 {
766  std::auto_ptr<EcalClusterEnergyCorrectionParameters> ipar = std::auto_ptr<EcalClusterEnergyCorrectionParameters>( new EcalClusterEnergyCorrectionParameters() );
767  for (size_t i = 0; i < energyCorrectionParameters_.size(); ++i ) {
768  ipar->params().push_back( energyCorrectionParameters_[i] );
769  }
770  return ipar;
771 }
772 std::auto_ptr<EcalClusterEnergyUncertaintyParameters>
774 {
775  std::auto_ptr<EcalClusterEnergyUncertaintyParameters> ipar = std::auto_ptr<EcalClusterEnergyUncertaintyParameters>( new EcalClusterEnergyUncertaintyParameters() );
776  for (size_t i = 0; i < energyUncertaintyParameters_.size(); ++i ) {
777  ipar->params().push_back( energyUncertaintyParameters_[i] );
778  }
779  return ipar;
780 }
781 
782 
783 // laser records
784 std::auto_ptr<EcalLaserAlphas>
786 {
787  std::auto_ptr<EcalLaserAlphas> ical = std::auto_ptr<EcalLaserAlphas>( new EcalLaserAlphas() );
788  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
789  if(ieta==0) continue;
790  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
791  if (EBDetId::validDetId(ieta,iphi)) {
792  EBDetId ebid(ieta,iphi);
793  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
794  ical->setValue( ebid, laserAlphaMean_ + r*laserAlphaSigma_ );
795  }
796  }
797  }
798 
799  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
800  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
801  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
802  if (EEDetId::validDetId(iX,iY,1)) {
803  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
804  EEDetId eedetidpos(iX,iY,1);
805  ical->setValue( eedetidpos, laserAlphaMean_ + r*laserAlphaSigma_ );
806  }
807 
808  if (EEDetId::validDetId(iX,iY,-1)) {
809  double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
810  EEDetId eedetidneg(iX,iY,-1);
811  ical->setValue( eedetidneg, laserAlphaMean_ + r1*laserAlphaSigma_ );
812  }
813  }
814  }
815 
816  return ical;
817 }
818 
819 
820 std::auto_ptr<EcalLaserAPDPNRatiosRef>
822 {
823  std::auto_ptr<EcalLaserAPDPNRatiosRef> ical = std::auto_ptr<EcalLaserAPDPNRatiosRef>( new EcalLaserAPDPNRatiosRef() );
824  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
825  if(ieta==0) continue;
826  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
827  if (EBDetId::validDetId(ieta,iphi)) {
828  EBDetId ebid(ieta,iphi);
829  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
830  ical->setValue( ebid, laserAPDPNRefMean_ + r*laserAPDPNRefSigma_ );
831  }
832  }
833  }
834 
835  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
836  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
837  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
838  if (EEDetId::validDetId(iX,iY,1)) {
839  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
840  EEDetId eedetidpos(iX,iY,1);
841  ical->setValue( eedetidpos, laserAPDPNRefMean_ + r*laserAPDPNRefSigma_ );
842  }
843 
844  if (EEDetId::validDetId(iX,iY,-1)) {
845  double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
846  EEDetId eedetidneg(iX,iY,-1);
847  ical->setValue( eedetidneg, laserAPDPNRefMean_ + r1*laserAPDPNRefSigma_ );
848  }
849  }
850  }
851 
852  return ical;
853 }
854 
855 
856 std::auto_ptr<EcalLaserAPDPNRatios>
858 {
859 
860  std::auto_ptr<EcalLaserAPDPNRatios> ical = std::auto_ptr<EcalLaserAPDPNRatios>( new EcalLaserAPDPNRatios() );
861  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
862  if(ieta==0) continue;
863  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
864  if (EBDetId::validDetId(ieta,iphi)) {
865  EBDetId ebid(ieta,iphi);
866  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
867 
869  pairAPDPN.p1 = laserAPDPNMean_ + r*laserAPDPNSigma_;
870  pairAPDPN.p2 = laserAPDPNMean_ + r*laserAPDPNSigma_;
871  pairAPDPN.p3 = laserAPDPNMean_ + r*laserAPDPNSigma_;
872  ical->setValue( ebid, pairAPDPN );
873  }
874  }
875  }
876 
877  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
878  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
879  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
880  if (EEDetId::validDetId(iX,iY,1)) {
881  double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
882  EEDetId eedetidpos(iX,iY,1);
883 
885  pairAPDPN.p1 = laserAPDPNMean_ + r*laserAPDPNSigma_;
886  pairAPDPN.p2 = laserAPDPNMean_ + r*laserAPDPNSigma_;
887  pairAPDPN.p3 = laserAPDPNMean_ + r*laserAPDPNSigma_;
888  ical->setValue( eedetidpos, pairAPDPN );
889  }
890 
891  if (EEDetId::validDetId(iX,iY,-1)) {
892  double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
893  EEDetId eedetidneg(iX,iY,-1);
894 
896  pairAPDPN.p1 = laserAPDPNMean_ + r1*laserAPDPNSigma_;
897  pairAPDPN.p2 = laserAPDPNMean_ + r1*laserAPDPNSigma_;
898  pairAPDPN.p3 = laserAPDPNMean_ + r1*laserAPDPNSigma_;
899  ical->setValue( eedetidneg, pairAPDPN );
900  }
901  }
902  }
903 
905  // for(int i=1; i<=92; i++){
906  for(int i=0; i<92; i++){
907  TimeStamp.t1 = Timestamp(laserAPDPNTime1_);
908  if(laserAPDPNTime2_ == 0 ){
909  TimeStamp.t2 = Timestamp(edm::Timestamp::endOfTime().value());
910  } else {
911  TimeStamp.t2 = Timestamp(laserAPDPNTime2_);
912  }
913  if(laserAPDPNTime3_ == 0 ){
914  TimeStamp.t3 = Timestamp(edm::Timestamp::endOfTime().value());
915  } else {
916  TimeStamp.t3 = Timestamp(laserAPDPNTime3_);
917  }
918 
919  ical->setTime( i, TimeStamp );
920  }
921 
922  return ical;
923 
924 }
925 
926 
928 {
929 
930  std::vector < std::vector<double> > amplwgtv(nTDCbins_);
931 
932  if (!getWeightsFromFile_ && nTDCbins_ == 1)
933  {
934  std::vector<double> vampl;
935  //As default using simple 3+1 weights
936  vampl.push_back( -0.33333 );
937  vampl.push_back( -0.33333 );
938  vampl.push_back( -0.33333 );
939  vampl.push_back( 0. );
940  vampl.push_back( 0. );
941  vampl.push_back( 1. );
942  vampl.push_back( 0. );
943  vampl.push_back( 0. );
944  vampl.push_back( 0. );
945  vampl.push_back( 0. );
946  amplwgtv[0]= ps.getUntrackedParameter< std::vector<double> >("amplWeights", vampl);
947  }
948  else if (getWeightsFromFile_)
949  {
950  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading amplitude weights from file " << edm::FileInPath(amplWeightsFile_).fullPath().c_str() ;
951  std::ifstream amplFile(edm::FileInPath(amplWeightsFile_).fullPath().c_str());
952  int tdcBin=0;
953  while (!amplFile.eof() && tdcBin < nTDCbins_)
954  {
955  for(int j = 0; j < 10; ++j) {
956  float ww;
957  amplFile >> ww;
958  amplwgtv[tdcBin].push_back(ww);
959  }
960  ++tdcBin;
961  }
962  assert (tdcBin == nTDCbins_);
963  //Read from file
964  }
965  else
966  {
967  //Not supported
968  edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
969  throw cms::Exception("WrongConfig");
970  }
971 
972 
973  for (int i=0;i<nTDCbins_;i++)
974  {
975  assert(amplwgtv[i].size() == 10);
976  int j=0;
977  for(std::vector<double>::const_iterator it = amplwgtv[i].begin(); it != amplwgtv[i].end(); ++it)
978  {
979  (amplWeights_[i])[j]=*it;
980  j++;
981  }
982  }
983 
984 
985  std::vector < std::vector<double> > amplwgtvAftGain(nTDCbins_);
986 
987  if (!getWeightsFromFile_ && nTDCbins_ == 1 )
988  {
989  std::vector<double> vamplAftGain;
990  vamplAftGain.push_back( 0. );
991  vamplAftGain.push_back( 0. );
992  vamplAftGain.push_back( 0. );
993  vamplAftGain.push_back( 0. );
994  vamplAftGain.push_back( 0. );
995  vamplAftGain.push_back( 1. );
996  vamplAftGain.push_back( 0. );
997  vamplAftGain.push_back( 0. );
998  vamplAftGain.push_back( 0. );
999  vamplAftGain.push_back( 0. );
1000  amplwgtvAftGain[0] = ps.getUntrackedParameter< std::vector<double> >("amplWeightsAftGain", vamplAftGain);
1001  }
1002  else if (getWeightsFromFile_)
1003  {
1004  //Read from file
1005  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading amplitude weights aftre gain switch from file " << edm::FileInPath(amplWeightsAftFile_).fullPath().c_str() ;
1006  std::ifstream amplFile(edm::FileInPath(amplWeightsAftFile_).fullPath().c_str());
1007  int tdcBin=0;
1008  while (!amplFile.eof() && tdcBin < nTDCbins_)
1009  {
1010  for(int j = 0; j < 10; ++j) {
1011  float ww;
1012  amplFile >> ww;
1013  amplwgtvAftGain[tdcBin].push_back(ww);
1014  }
1015  ++tdcBin;
1016  }
1017  assert (tdcBin == nTDCbins_);
1018  }
1019  else
1020  {
1021  //Not supported
1022  edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1023  throw cms::Exception("WrongConfig");
1024  }
1025 
1026  for (int i=0;i<nTDCbins_;i++)
1027  {
1028  assert(amplwgtvAftGain[i].size() == 10);
1029  int j=0;
1030  for(std::vector<double>::const_iterator it = amplwgtvAftGain[i].begin(); it != amplwgtvAftGain[i].end(); ++it) {
1031  (amplWeightsAft_[i])[j]=*it;
1032  j++;
1033  }
1034  }
1035 
1036  // default weights to reco amplitude w/o pedestal subtraction
1037 
1038  std::vector< std::vector<double> > pedwgtv(nTDCbins_);
1039 
1040  if (!getWeightsFromFile_ && nTDCbins_ == 1)
1041  {
1042  std::vector<double> vped;
1043  vped.push_back( 0.33333 );
1044  vped.push_back( 0.33333 );
1045  vped.push_back( 0.33333 );
1046  vped.push_back( 0. );
1047  vped.push_back( 0. );
1048  vped.push_back( 0. );
1049  vped.push_back( 0. );
1050  vped.push_back( 0. );
1051  vped.push_back( 0. );
1052  vped.push_back( 0. );
1053  pedwgtv[0] = ps.getUntrackedParameter< std::vector<double> >("pedWeights", vped);
1054  }
1055  else if (getWeightsFromFile_)
1056  {
1057  //Read from file
1058  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading pedestal weights from file " << edm::FileInPath(pedWeightsFile_).fullPath().c_str() ;
1059  std::ifstream pedFile(edm::FileInPath(pedWeightsFile_).fullPath().c_str());
1060  int tdcBin=0;
1061  while (!pedFile.eof() && tdcBin < nTDCbins_)
1062  {
1063  for(int j = 0; j < 10; ++j) {
1064  float ww;
1065  pedFile >> ww;
1066  pedwgtv[tdcBin].push_back(ww);
1067  }
1068  ++tdcBin;
1069  }
1070  assert (tdcBin == nTDCbins_);
1071  }
1072  else
1073  {
1074  //Not supported
1075  edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1076  throw cms::Exception("WrongConfig");
1077  }
1078 
1079  for (int i=0;i<nTDCbins_;i++)
1080  {
1081  assert(pedwgtv[i].size() == 10);
1082  int j=0;
1083  for(std::vector<double>::const_iterator it = pedwgtv[i].begin(); it != pedwgtv[i].end(); ++it) {
1084  (pedWeights_[i])[j] = *it;
1085  j++;
1086  }
1087  }
1088 
1089  std::vector< std::vector<double> > pedwgtvaft(nTDCbins_);
1090 
1091  if (!getWeightsFromFile_ && nTDCbins_ == 1)
1092  {
1093  std::vector<double> vped;
1094  vped.push_back( 0. );
1095  vped.push_back( 0. );
1096  vped.push_back( 0. );
1097  vped.push_back( 0. );
1098  vped.push_back( 0. );
1099  vped.push_back( 0. );
1100  vped.push_back( 0. );
1101  vped.push_back( 0. );
1102  vped.push_back( 0. );
1103  vped.push_back( 0. );
1104  pedwgtvaft[0] = ps.getUntrackedParameter< std::vector<double> >("pedWeightsAft", vped);
1105  }
1106  else if (getWeightsFromFile_)
1107  {
1108  //Read from file
1109  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading pedestal after gain switch weights from file " << edm::FileInPath(pedWeightsAftFile_).fullPath().c_str() ;
1110  std::ifstream pedFile(edm::FileInPath(pedWeightsAftFile_).fullPath().c_str());
1111  int tdcBin=0;
1112  while (!pedFile.eof() && tdcBin < nTDCbins_)
1113  {
1114  for(int j = 0; j < 10; ++j) {
1115  float ww;
1116  pedFile >> ww;
1117  pedwgtvaft[tdcBin].push_back(ww);
1118  }
1119  ++tdcBin;
1120  }
1121  assert (tdcBin == nTDCbins_);
1122  }
1123  else
1124  {
1125  //Not supported
1126  edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1127  throw cms::Exception("WrongConfig");
1128  }
1129 
1130  for (int i=0;i<nTDCbins_;i++)
1131  {
1132  assert(pedwgtvaft[i].size() == 10);
1133  int j=0;
1134  for(std::vector<double>::const_iterator it = pedwgtvaft[i].begin(); it != pedwgtvaft[i].end(); ++it) {
1135  (pedWeightsAft_[i])[j]=*it;
1136  j++;
1137  }
1138  }
1139 
1140 
1141 
1142  // default weights to reco jitter
1143 
1144  std::vector< std::vector<double> > jittwgtv(nTDCbins_);
1145 
1146  if (!getWeightsFromFile_ && nTDCbins_ == 1 )
1147  {
1148  std::vector<double> vjitt;
1149  vjitt.push_back( 0.04066309 );
1150  vjitt.push_back( 0.04066309 );
1151  vjitt.push_back( 0.04066309 );
1152  vjitt.push_back( 0.000 );
1153  vjitt.push_back( 1.325176 );
1154  vjitt.push_back( -0.04997078 );
1155  vjitt.push_back( -0.504338 );
1156  vjitt.push_back( -0.5024844 );
1157  vjitt.push_back( -0.3903718 );
1158  vjitt.push_back( 0.000 );
1159  jittwgtv[0] = ps.getUntrackedParameter< std::vector<double> >("jittWeights", vjitt);
1160  }
1161  else if (getWeightsFromFile_)
1162  {
1163  //Read from file
1164  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading jitter weights from file " << edm::FileInPath(jittWeightsFile_).fullPath().c_str() ;
1165  std::ifstream jittFile(edm::FileInPath(jittWeightsFile_).fullPath().c_str());
1166  int tdcBin=0;
1167  while (!jittFile.eof() && tdcBin < nTDCbins_)
1168  {
1169  for(int j = 0; j < 10; ++j) {
1170  float ww;
1171  jittFile >> ww;
1172  jittwgtv[tdcBin].push_back(ww);
1173  }
1174  ++tdcBin;
1175  }
1176  assert (tdcBin == nTDCbins_);
1177  }
1178  else
1179  {
1180  //Not supported
1181  edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1182  throw cms::Exception("WrongConfig");
1183  }
1184 
1185  for (int i=0;i<nTDCbins_;i++)
1186  {
1187  assert(jittwgtv[i].size() == 10);
1188  int j=0;
1189  for(std::vector<double>::const_iterator it = jittwgtv[i].begin(); it != jittwgtv[i].end(); ++it) {
1190  (jittWeights_[i])[j]= *it;
1191  j++;
1192  }
1193  }
1194 
1195  std::vector< std::vector<double> > jittwgtvaft(nTDCbins_);
1196 
1197  if (!getWeightsFromFile_ && nTDCbins_ == 1)
1198  {
1199  std::vector<double> vjitt;
1200  vjitt.push_back( 0. );
1201  vjitt.push_back( 0. );
1202  vjitt.push_back( 0. );
1203  vjitt.push_back( 0. );
1204  vjitt.push_back( 1.097871 );
1205  vjitt.push_back( -0.04551035 );
1206  vjitt.push_back( -0.4159156 );
1207  vjitt.push_back( -0.4185352 );
1208  vjitt.push_back( -0.3367127 );
1209  vjitt.push_back( 0. );
1210  jittwgtvaft[0] = ps.getUntrackedParameter< std::vector<double> >("jittWeightsAft", vjitt);
1211  }
1212  else if (getWeightsFromFile_)
1213  {
1214  //Read from file
1215  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading jitter after gain switch weights from file " << edm::FileInPath(jittWeightsAftFile_).fullPath().c_str() ;
1216  std::ifstream jittFile(edm::FileInPath(jittWeightsAftFile_).fullPath().c_str());
1217  int tdcBin=0;
1218  while (!jittFile.eof() && tdcBin < nTDCbins_)
1219  {
1220  for(int j = 0; j < 10; ++j) {
1221  float ww;
1222  jittFile >> ww;
1223  jittwgtvaft[tdcBin].push_back(ww);
1224  }
1225  ++tdcBin;
1226  }
1227  assert (tdcBin == nTDCbins_);
1228  }
1229  else
1230  {
1231  //Not supported
1232  edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1233  throw cms::Exception("WrongConfig");
1234  }
1235 
1236  for (int i=0;i<nTDCbins_;i++)
1237  {
1238  assert(jittwgtvaft[i].size() == 10);
1239  int j=0;
1240  for(std::vector<double>::const_iterator it = jittwgtvaft[i].begin(); it != jittwgtvaft[i].end(); ++it) {
1241  (jittWeightsAft_[i])[j]= *it;
1242  j++;
1243  }
1244  }
1245 
1246 
1247  std::vector< EcalWeightSet::EcalChi2WeightMatrix > chi2Matrix(nTDCbins_);
1248  if (!getWeightsFromFile_ && nTDCbins_ == 1 )
1249  {
1250  // chi2Matrix[0].resize(10);
1251  // for (int i=0;i<10;i++)
1252  // chi2Matrix[0][i].resize(10);
1253 
1254  chi2Matrix[0](0,0) = 0.694371;
1255  chi2Matrix[0](0,1) = -0.305629;
1256  chi2Matrix[0](0,2) = -0.305629;
1257  chi2Matrix[0](0,3) = 0.;
1258  chi2Matrix[0](0,4) = 0.;
1259  chi2Matrix[0](0,5) = 0.;
1260  chi2Matrix[0](0,6) = 0.;
1261  chi2Matrix[0](0,7) = 0.;
1262  chi2Matrix[0](0,8) = 0.;
1263  chi2Matrix[0](0,9) = 0.;
1264  chi2Matrix[0](1,0) = -0.305629;
1265  chi2Matrix[0](1,1) = 0.694371;
1266  chi2Matrix[0](1,2) = -0.305629;
1267  chi2Matrix[0](1,3) = 0.;
1268  chi2Matrix[0](1,4) = 0.;
1269  chi2Matrix[0](1,5) = 0.;
1270  chi2Matrix[0](1,6) = 0.;
1271  chi2Matrix[0](1,7) = 0.;
1272  chi2Matrix[0](1,8) = 0.;
1273  chi2Matrix[0](1,9) = 0.;
1274  chi2Matrix[0](2,0) = -0.305629;
1275  chi2Matrix[0](2,1) = -0.305629;
1276  chi2Matrix[0](2,2) = 0.694371;
1277  chi2Matrix[0](2,3) = 0.;
1278  chi2Matrix[0](2,4) = 0.;
1279  chi2Matrix[0](2,5) = 0.;
1280  chi2Matrix[0](2,6) = 0.;
1281  chi2Matrix[0](2,7) = 0.;
1282  chi2Matrix[0](2,8) = 0.;
1283  chi2Matrix[0](2,9) = 0.;
1284  chi2Matrix[0](3,0) = 0.;
1285  chi2Matrix[0](3,1) = 0.;
1286  chi2Matrix[0](3,2) = 0.;
1287  chi2Matrix[0](3,3) = 0.;
1288  chi2Matrix[0](3,4) = 0.;
1289  chi2Matrix[0](3,5) = 0.;
1290  chi2Matrix[0](3,6) = 0.;
1291  chi2Matrix[0](3,7) = 0.;
1292  chi2Matrix[0](3,8) = 0.;
1293  chi2Matrix[0](3,9) = 0.;
1294  chi2Matrix[0](4,0) = 0.;
1295  chi2Matrix[0](4,1) = 0.;
1296  chi2Matrix[0](4,2) = 0.;
1297  chi2Matrix[0](4,3) = 0.;
1298  chi2Matrix[0](4,4) = 0.8027116;
1299  chi2Matrix[0](4,5) = -0.2517103;
1300  chi2Matrix[0](4,6) = -0.2232882;
1301  chi2Matrix[0](4,7) = -0.1716192;
1302  chi2Matrix[0](4,8) = -0.1239006;
1303  chi2Matrix[0](4,9) = 0.;
1304  chi2Matrix[0](5,0) = 0.;
1305  chi2Matrix[0](5,1) = 0.;
1306  chi2Matrix[0](5,2) = 0.;
1307  chi2Matrix[0](5,3) = 0.;
1308  chi2Matrix[0](5,4) = -0.2517103;
1309  chi2Matrix[0](5,5) = 0.6528964;
1310  chi2Matrix[0](5,6) = -0.2972839;
1311  chi2Matrix[0](5,7) = -0.2067162;
1312  chi2Matrix[0](5,8) = -0.1230729;
1313  chi2Matrix[0](5,9) = 0.;
1314  chi2Matrix[0](6,0) = 0.;
1315  chi2Matrix[0](6,1) = 0.;
1316  chi2Matrix[0](6,2) = 0.;
1317  chi2Matrix[0](6,3) = 0.;
1318  chi2Matrix[0](6,4) = -0.2232882;
1319  chi2Matrix[0](6,5) = -0.2972839;
1320  chi2Matrix[0](6,6) = 0.7413607;
1321  chi2Matrix[0](6,7) = -0.1883866;
1322  chi2Matrix[0](6,8) = -0.1235052;
1323  chi2Matrix[0](6,9) = 0.;
1324  chi2Matrix[0](7,0) = 0.;
1325  chi2Matrix[0](7,1) = 0.;
1326  chi2Matrix[0](7,2) = 0.;
1327  chi2Matrix[0](7,3) = 0.;
1328  chi2Matrix[0](7,4) = -0.1716192;
1329  chi2Matrix[0](7,5) = -0.2067162;
1330  chi2Matrix[0](7,6) = -0.1883866;
1331  chi2Matrix[0](7,7) = 0.844935;
1332  chi2Matrix[0](7,8) = -0.124291;
1333  chi2Matrix[0](7,9) = 0.;
1334  chi2Matrix[0](8,0) = 0.;
1335  chi2Matrix[0](8,1) = 0.;
1336  chi2Matrix[0](8,2) = 0.;
1337  chi2Matrix[0](8,3) = 0.;
1338  chi2Matrix[0](8,4) = -0.1239006;
1339  chi2Matrix[0](8,5) = -0.1230729;
1340  chi2Matrix[0](8,6) = -0.1235052;
1341  chi2Matrix[0](8,7) = -0.124291;
1342  chi2Matrix[0](8,8) = 0.8749833;
1343  chi2Matrix[0](8,9) = 0.;
1344  chi2Matrix[0](9,0) = 0.;
1345  chi2Matrix[0](9,1) = 0.;
1346  chi2Matrix[0](9,2) = 0.;
1347  chi2Matrix[0](9,3) = 0.;
1348  chi2Matrix[0](9,4) = 0.;
1349  chi2Matrix[0](9,5) = 0.;
1350  chi2Matrix[0](9,6) = 0.;
1351  chi2Matrix[0](9,7) = 0.;
1352  chi2Matrix[0](9,8) = 0.;
1353  chi2Matrix[0](9,9) = 0.;
1354  }
1355  else if (getWeightsFromFile_)
1356  {
1357  //Read from file
1358  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading chi2Matrix from file " << edm::FileInPath(chi2MatrixFile_).fullPath().c_str() ;
1359  std::ifstream chi2MatrixFile(edm::FileInPath(chi2MatrixFile_).fullPath().c_str());
1360  int tdcBin=0;
1361  while (!chi2MatrixFile.eof() && tdcBin < nTDCbins_)
1362  {
1363  // chi2Matrix[tdcBin].resize(10);
1364  for(int j = 0; j < 10; ++j) {
1365  for(int l = 0; l < 10; ++l) {
1366  float ww;
1367  chi2MatrixFile >> ww;
1368  chi2Matrix[tdcBin](j,l)=ww;
1369  }
1370  }
1371  ++tdcBin;
1372  }
1373  assert (tdcBin == nTDCbins_);
1374  }
1375  else
1376  {
1377  //Not supported
1378  edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1379  throw cms::Exception("WrongConfig");
1380  }
1381 
1382 // for (int i=0;i<nTDCbins_;i++)
1383 // {
1384  // assert(chi2Matrix[i].size() == 10);
1385  chi2Matrix_ = chi2Matrix;
1386 // }
1387 
1388  std::vector< EcalWeightSet::EcalChi2WeightMatrix > chi2MatrixAft(nTDCbins_);
1389  if (!getWeightsFromFile_ && nTDCbins_ == 1 )
1390  {
1391  // chi2MatrixAft[0].resize(10);
1392  // for (int i=0;i<10;i++)
1393  // chi2MatrixAft[0][i].resize(10);
1394 
1395  chi2MatrixAft[0](0,0) = 0.;
1396  chi2MatrixAft[0](0,1) = 0.;
1397  chi2MatrixAft[0](0,2) = 0.;
1398  chi2MatrixAft[0](0,3) = 0.;
1399  chi2MatrixAft[0](0,4) = 0.;
1400  chi2MatrixAft[0](0,5) = 0.;
1401  chi2MatrixAft[0](0,6) = 0.;
1402  chi2MatrixAft[0](0,7) = 0.;
1403  chi2MatrixAft[0](0,8) = 0.;
1404  chi2MatrixAft[0](0,9) = 0.;
1405  chi2MatrixAft[0](1,0) = 0.;
1406  chi2MatrixAft[0](1,1) = 0.;
1407  chi2MatrixAft[0](1,2) = 0.;
1408  chi2MatrixAft[0](1,3) = 0.;
1409  chi2MatrixAft[0](1,4) = 0.;
1410  chi2MatrixAft[0](1,5) = 0.;
1411  chi2MatrixAft[0](1,6) = 0.;
1412  chi2MatrixAft[0](1,7) = 0.;
1413  chi2MatrixAft[0](1,8) = 0.;
1414  chi2MatrixAft[0](1,9) = 0.;
1415  chi2MatrixAft[0](2,0) = 0.;
1416  chi2MatrixAft[0](2,1) = 0.;
1417  chi2MatrixAft[0](2,2) = 0.;
1418  chi2MatrixAft[0](2,3) = 0.;
1419  chi2MatrixAft[0](2,4) = 0.;
1420  chi2MatrixAft[0](2,5) = 0.;
1421  chi2MatrixAft[0](2,6) = 0.;
1422  chi2MatrixAft[0](2,7) = 0.;
1423  chi2MatrixAft[0](2,8) = 0.;
1424  chi2MatrixAft[0](2,9) = 0.;
1425  chi2MatrixAft[0](3,0) = 0.;
1426  chi2MatrixAft[0](3,1) = 0.;
1427  chi2MatrixAft[0](3,2) = 0.;
1428  chi2MatrixAft[0](3,3) = 0.;
1429  chi2MatrixAft[0](3,4) = 0.;
1430  chi2MatrixAft[0](3,5) = 0.;
1431  chi2MatrixAft[0](3,6) = 0.;
1432  chi2MatrixAft[0](3,7) = 0.;
1433  chi2MatrixAft[0](3,8) = 0.;
1434  chi2MatrixAft[0](3,9) = 0.;
1435  chi2MatrixAft[0](4,0) = 0.;
1436  chi2MatrixAft[0](4,1) = 0.;
1437  chi2MatrixAft[0](4,2) = 0.;
1438  chi2MatrixAft[0](4,3) = 0.;
1439  chi2MatrixAft[0](4,4) = 0.8030884;
1440  chi2MatrixAft[0](4,5) = -0.2543541;
1441  chi2MatrixAft[0](4,6) = -0.2243544;
1442  chi2MatrixAft[0](4,7) = -0.1698177;
1443  chi2MatrixAft[0](4,8) = -0.1194506;
1444  chi2MatrixAft[0](4,9) = 0.;
1445  chi2MatrixAft[0](5,0) = 0.;
1446  chi2MatrixAft[0](5,1) = 0.;
1447  chi2MatrixAft[0](5,2) = 0.;
1448  chi2MatrixAft[0](5,3) = 0.;
1449  chi2MatrixAft[0](5,4) = -0.2543541;
1450  chi2MatrixAft[0](5,5) = 0.6714465;
1451  chi2MatrixAft[0](5,6) = -0.2898025;
1452  chi2MatrixAft[0](5,7) = -0.2193564;
1453  chi2MatrixAft[0](5,8) = -0.1542964;
1454  chi2MatrixAft[0](5,9) = 0.;
1455  chi2MatrixAft[0](6,0) = 0.;
1456  chi2MatrixAft[0](6,1) = 0.;
1457  chi2MatrixAft[0](6,2) = 0.;
1458  chi2MatrixAft[0](6,3) = 0.;
1459  chi2MatrixAft[0](6,4) = -0.2243544;
1460  chi2MatrixAft[0](6,5) = -0.2898025;
1461  chi2MatrixAft[0](6,6) = 0.7443781;
1462  chi2MatrixAft[0](6,7) = -0.1934846;
1463  chi2MatrixAft[0](6,8) = -0.136098;
1464  chi2MatrixAft[0](6,9) = 0.;
1465  chi2MatrixAft[0](7,0) = 0.;
1466  chi2MatrixAft[0](7,1) = 0.;
1467  chi2MatrixAft[0](7,2) = 0.;
1468  chi2MatrixAft[0](7,3) = 0.;
1469  chi2MatrixAft[0](7,4) = -0.1698177;
1470  chi2MatrixAft[0](7,5) = -0.2193564;
1471  chi2MatrixAft[0](7,6) = -0.1934846;
1472  chi2MatrixAft[0](7,7) = 0.8535482;
1473  chi2MatrixAft[0](7,8) = -0.1030149;
1474  chi2MatrixAft[0](7,9) = 0.;
1475  chi2MatrixAft[0](8,0) = 0.;
1476  chi2MatrixAft[0](8,1) = 0.;
1477  chi2MatrixAft[0](8,2) = 0.;
1478  chi2MatrixAft[0](8,3) = 0.;
1479  chi2MatrixAft[0](8,4) = -0.1194506;
1480  chi2MatrixAft[0](8,5) = -0.1542964;
1481  chi2MatrixAft[0](8,6) = -0.136098;
1482  chi2MatrixAft[0](8,7) = -0.1030149;
1483  chi2MatrixAft[0](8,8) = 0.9275388;
1484  chi2MatrixAft[0](8,9) = 0.;
1485  chi2MatrixAft[0](9,0) = 0.;
1486  chi2MatrixAft[0](9,1) = 0.;
1487  chi2MatrixAft[0](9,2) = 0.;
1488  chi2MatrixAft[0](9,3) = 0.;
1489  chi2MatrixAft[0](9,4) = 0.;
1490  chi2MatrixAft[0](9,5) = 0.;
1491  chi2MatrixAft[0](9,6) = 0.;
1492  chi2MatrixAft[0](9,7) = 0.;
1493  chi2MatrixAft[0](9,8) = 0.;
1494  chi2MatrixAft[0](9,9) = 0.;
1495  }
1496  else if (getWeightsFromFile_)
1497  {
1498  //Read from file
1499  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading chi2MatrixAft from file " << edm::FileInPath(chi2MatrixAftFile_).fullPath().c_str() ;
1500  std::ifstream chi2MatrixAftFile(edm::FileInPath(chi2MatrixAftFile_).fullPath().c_str());
1501  int tdcBin=0;
1502  while (!chi2MatrixAftFile.eof() && tdcBin < nTDCbins_)
1503  {
1504  // chi2MatrixAft[tdcBin].resize(10);
1505  for(int j = 0; j < 10; ++j) {
1506  for(int l = 0; l < 10; ++l) {
1507  float ww;
1508  chi2MatrixAftFile >> ww;
1509  chi2MatrixAft[tdcBin](j,l)=ww;
1510  }
1511  }
1512  ++tdcBin;
1513  }
1514  assert (tdcBin == nTDCbins_);
1515  }
1516  else
1517  {
1518  //Not supported
1519  edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
1520  throw cms::Exception("WrongConfig");
1521  }
1522 
1523 // for (int i=0;i<nTDCbins_;i++)
1524 // {
1525  // assert(chi2MatrixAft[i].size() == 10);
1526  chi2MatrixAft_ = chi2MatrixAft;
1527  // }
1528 
1529 }
1530 
1531 
1532 // --------------------------------------------------------------------------------
1533 
1534 std::auto_ptr<EcalChannelStatus>
1536 {
1537  std::auto_ptr<EcalChannelStatus> ecalStatus = std::auto_ptr<EcalChannelStatus>( new EcalChannelStatus() );
1538 
1539 
1540  // start by setting all statuses to 0
1541 
1542  // barrel
1543  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
1544  if(ieta==0) continue;
1545  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
1546  if (EBDetId::validDetId(ieta,iphi)) {
1547  EBDetId ebid(ieta,iphi);
1548  ecalStatus->setValue( ebid, 0 );
1549  }
1550  }
1551  }
1552  // endcap
1553  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
1554  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
1555  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
1556  if (EEDetId::validDetId(iX,iY,1)) {
1557  EEDetId eedetidpos(iX,iY,1);
1558  ecalStatus->setValue( eedetidpos, 0 );
1559  }
1560  if (EEDetId::validDetId(iX,iY,-1)) {
1561  EEDetId eedetidneg(iX,iY,-1);
1562  ecalStatus->setValue( eedetidneg, 0 );
1563  }
1564  }
1565  }
1566 
1567 
1568 
1569  // overwrite the statuses which are in the file
1570 
1571  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading channel statuses from file " << edm::FileInPath(channelStatusFile_).fullPath().c_str() ;
1572  std::ifstream statusFile(edm::FileInPath(channelStatusFile_).fullPath().c_str());
1573  if ( !statusFile.good() ) {
1574  edm::LogError ("EcalTrivialConditionRetriever")
1575  << "*** Problems opening file: " << channelStatusFile_ ;
1576  throw cms::Exception ("Cannot open ECAL channel status file") ;
1577  }
1578 
1579  std::string EcalSubDet;
1580  std::string str;
1581  int hashIndex(0);
1582  int status(0);
1583 
1584  while (!statusFile.eof())
1585  {
1586  statusFile >> EcalSubDet;
1587  if (EcalSubDet!=std::string("EB") && EcalSubDet!=std::string("EE"))
1588  {
1589  std::getline(statusFile,str);
1590  continue;
1591  }
1592  else
1593  {
1594  statusFile>> hashIndex >> status;
1595  }
1596  // std::cout << EcalSubDet << " " << hashIndex << " " << status;
1597 
1598  if(EcalSubDet==std::string("EB"))
1599  {
1600  EBDetId ebid = EBDetId::unhashIndex(hashIndex);
1601  ecalStatus->setValue( ebid, status );
1602  }
1603  else if(EcalSubDet==std::string("EE"))
1604  {
1605  EEDetId eedetid = EEDetId::unhashIndex(hashIndex);
1606  ecalStatus->setValue( eedetid, status );
1607  }
1608  else
1609  {
1610  edm::LogError ("EcalTrivialConditionRetriever")
1611  << " *** " << EcalSubDet << " is neither EB nor EE ";
1612  }
1613 
1614  }
1615  // the file is supposed to be in the form -- FIXME
1616 
1617 
1618  statusFile.close();
1619  return ecalStatus;
1620 }
1621 
1622 
1623 
1624 std::auto_ptr<EcalChannelStatus>
1626 {
1627 
1628  std::auto_ptr<EcalChannelStatus> ical = std::auto_ptr<EcalChannelStatus>( new EcalChannelStatus() );
1629  // barrel
1630  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
1631  if(ieta==0) continue;
1632  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
1633  if (EBDetId::validDetId(ieta,iphi)) {
1634  EBDetId ebid(ieta,iphi);
1635  ical->setValue( ebid, 0 );
1636  }
1637  }
1638  }
1639  // endcap
1640  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
1641  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
1642  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
1643  if (EEDetId::validDetId(iX,iY,1)) {
1644  EEDetId eedetidpos(iX,iY,1);
1645  ical->setValue( eedetidpos, 0 );
1646  }
1647  if (EEDetId::validDetId(iX,iY,-1)) {
1648  EEDetId eedetidneg(iX,iY,-1);
1649  ical->setValue( eedetidneg, 0 );
1650  }
1651  }
1652  }
1653  return ical;
1654 }
1655 
1656 // --------------------------------------------------------------------------------
1657 std::auto_ptr<EcalDQMChannelStatus>
1659 {
1660  uint32_t sta(0);
1661 
1662  std::auto_ptr<EcalDQMChannelStatus> ical = std::auto_ptr<EcalDQMChannelStatus>( new EcalDQMChannelStatus() );
1663  // barrel
1664  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
1665  if(ieta==0) continue;
1666  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
1667  if (EBDetId::validDetId(ieta,iphi)) {
1668  EBDetId ebid(ieta,iphi);
1669  ical->setValue( ebid, sta );
1670  }
1671  }
1672  }
1673  // endcap
1674  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
1675  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
1676  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
1677  if (EEDetId::validDetId(iX,iY,1)) {
1678  EEDetId eedetidpos(iX,iY,1);
1679  ical->setValue( eedetidpos, sta );
1680  }
1681  if (EEDetId::validDetId(iX,iY,-1)) {
1682  EEDetId eedetidneg(iX,iY,-1);
1683  ical->setValue( eedetidneg, sta );
1684  }
1685  }
1686  }
1687  return ical;
1688 }
1689 // --------------------------------------------------------------------------------
1690 
1691 std::auto_ptr<EcalDQMTowerStatus>
1693 {
1694 
1695  std::auto_ptr<EcalDQMTowerStatus> ical = std::auto_ptr<EcalDQMTowerStatus>( new EcalDQMTowerStatus() );
1696 
1697  uint32_t sta(0);
1698 
1699  // barrel
1700  int iz=0;
1701  for(int k=0 ; k<2; k++ ) {
1702  if(k==0) iz=-1;
1703  if(k==1) iz=+1;
1704  for(int i=1 ; i<73; i++) {
1705  for(int j=1 ; j<18; j++) {
1707  EcalTrigTowerDetId ebid(iz,EcalBarrel,j,i);
1708 
1709  ical->setValue( ebid, sta );
1710  }
1711  }
1712  }
1713  }
1714 
1715 
1716  // endcap
1717  for(int k=0 ; k<2; k++ ) {
1718  if(k==0) iz=-1;
1719  if(k==1) iz=+1;
1720  for(int i=1 ; i<21; i++) {
1721  for(int j=1 ; j<21; j++) {
1722  if (EcalScDetId::validDetId(i,j,iz )){
1723  EcalScDetId eeid(i,j,iz);
1724  ical->setValue( eeid, sta );
1725  }
1726  }
1727  }
1728  }
1729 
1730  return ical;
1731 }
1732 
1733 // --------------------------------------------------------------------------------
1734 std::auto_ptr<EcalDCSTowerStatus>
1736 {
1737 
1738  std::auto_ptr<EcalDCSTowerStatus> ical = std::auto_ptr<EcalDCSTowerStatus>( new EcalDCSTowerStatus() );
1739 
1740  int status(0);
1741 
1742  // barrel
1743  int iz=0;
1744  for(int k=0 ; k<2; k++ ) {
1745  if(k==0) iz=-1;
1746  if(k==1) iz=+1;
1747  for(int i=1 ; i<73; i++) {
1748  for(int j=1 ; j<18; j++) {
1750  EcalTrigTowerDetId ebid(iz,EcalBarrel,j,i);
1751 
1752  ical->setValue( ebid, status );
1753  }
1754  }
1755  }
1756  }
1757 
1758 
1759  // endcap
1760  for(int k=0 ; k<2; k++ ) {
1761  if(k==0) iz=-1;
1762  if(k==1) iz=+1;
1763  for(int i=1 ; i<21; i++) {
1764  for(int j=1 ; j<21; j++) {
1765  if (EcalScDetId::validDetId(i,j,iz )){
1766  EcalScDetId eeid(i,j,iz);
1767  ical->setValue( eeid, status );
1768  }
1769  }
1770  }
1771  }
1772 
1773  return ical;
1774 }
1775 // --------------------------------------------------------------------------------
1776 
1777 std::auto_ptr<EcalDAQTowerStatus>
1779 {
1780 
1781  std::auto_ptr<EcalDAQTowerStatus> ical = std::auto_ptr<EcalDAQTowerStatus>( new EcalDAQTowerStatus() );
1782 
1783  int status(0);
1784 
1785  // barrel
1786  int iz=0;
1787  for(int k=0 ; k<2; k++ ) {
1788  if(k==0) iz=-1;
1789  if(k==1) iz=+1;
1790  for(int i=1 ; i<73; i++) {
1791  for(int j=1 ; j<18; j++) {
1793  EcalTrigTowerDetId ebid(iz,EcalBarrel,j,i);
1794 
1795  ical->setValue( ebid, status );
1796  }
1797  }
1798  }
1799  }
1800 
1801 
1802  // endcap
1803  for(int k=0 ; k<2; k++ ) {
1804  if(k==0) iz=-1;
1805  if(k==1) iz=+1;
1806  for(int i=1 ; i<21; i++) {
1807  for(int j=1 ; j<21; j++) {
1808  if (EcalScDetId::validDetId(i,j,iz )){
1809  EcalScDetId eeid(i,j,iz);
1810  ical->setValue( eeid, status );
1811  }
1812  }
1813  }
1814  }
1815 
1816  return ical;
1817 }
1818 // --------------------------------------------------------------------------------
1819 
1820 std::auto_ptr<EcalTPGCrystalStatus>
1822 {
1823  std::auto_ptr<EcalTPGCrystalStatus> ecalStatus = std::auto_ptr<EcalTPGCrystalStatus>( new EcalTPGCrystalStatus() );
1824 
1825 
1826  // start by setting all statuses to 0
1827 
1828  // barrel
1829  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
1830  if(ieta==0) continue;
1831  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
1832  if (EBDetId::validDetId(ieta,iphi)) {
1833  EBDetId ebid(ieta,iphi);
1834  ecalStatus->setValue( ebid, 0 );
1835  }
1836  }
1837  }
1838  // endcap
1839  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
1840  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
1841  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
1842  if (EEDetId::validDetId(iX,iY,1)) {
1843  EEDetId eedetidpos(iX,iY,1);
1844  ecalStatus->setValue( eedetidpos, 0 );
1845  }
1846  if (EEDetId::validDetId(iX,iY,-1)) {
1847  EEDetId eedetidneg(iX,iY,-1);
1848  ecalStatus->setValue( eedetidneg, 0 );
1849  }
1850  }
1851  }
1852 
1853 
1854 
1855  // overwrite the statuses which are in the file
1856 
1857  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading channel statuses from file " << edm::FileInPath(channelStatusFile_).fullPath().c_str() ;
1858  std::ifstream statusFile(edm::FileInPath(channelStatusFile_).fullPath().c_str());
1859  if ( !statusFile.good() ) {
1860  edm::LogError ("EcalTrivialConditionRetriever")
1861  << "*** Problems opening file: " << channelStatusFile_ ;
1862  throw cms::Exception ("Cannot open ECAL channel status file") ;
1863  }
1864 
1865  std::string EcalSubDet;
1866  std::string str;
1867  int hashIndex(0);
1868  int status(0);
1869 
1870  while (!statusFile.eof())
1871  {
1872  statusFile >> EcalSubDet;
1873  if (EcalSubDet!=std::string("EB") && EcalSubDet!=std::string("EE"))
1874  {
1875  std::getline(statusFile,str);
1876  continue;
1877  }
1878  else
1879  {
1880  statusFile>> hashIndex >> status;
1881  }
1882  // std::cout << EcalSubDet << " " << hashIndex << " " << status;
1883 
1884  if(EcalSubDet==std::string("EB"))
1885  {
1886  EBDetId ebid = EBDetId::unhashIndex(hashIndex);
1887  ecalStatus->setValue( ebid, status );
1888  }
1889  else if(EcalSubDet==std::string("EE"))
1890  {
1891  EEDetId eedetid = EEDetId::unhashIndex(hashIndex);
1892  ecalStatus->setValue( eedetid, status );
1893  }
1894  else
1895  {
1896  edm::LogError ("EcalTrivialConditionRetriever")
1897  << " *** " << EcalSubDet << " is neither EB nor EE ";
1898  }
1899 
1900  }
1901  // the file is supposed to be in the form -- FIXME
1902 
1903 
1904  statusFile.close();
1905  return ecalStatus;
1906 }
1907 
1908 
1909 
1910 std::auto_ptr<EcalTPGCrystalStatus>
1912 {
1913 
1914  std::auto_ptr<EcalTPGCrystalStatus> ical = std::auto_ptr<EcalTPGCrystalStatus>( new EcalTPGCrystalStatus() );
1915  // barrel
1916  for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
1917  if(ieta==0) continue;
1918  for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
1919  if (EBDetId::validDetId(ieta,iphi)) {
1920  EBDetId ebid(ieta,iphi);
1921  ical->setValue( ebid, 0 );
1922  }
1923  }
1924  }
1925  // endcap
1926  for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
1927  for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
1928  // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
1929  if (EEDetId::validDetId(iX,iY,1)) {
1930  EEDetId eedetidpos(iX,iY,1);
1931  ical->setValue( eedetidpos, 0 );
1932  }
1933  if (EEDetId::validDetId(iX,iY,-1)) {
1934  EEDetId eedetidneg(iX,iY,-1);
1935  ical->setValue( eedetidneg, 0 );
1936  }
1937  }
1938  }
1939  return ical;
1940 }
1941 
1942 
1943 
1944 // --------------------------------------------------------------------------------
1945 
1946 
1947 std::auto_ptr<EcalIntercalibConstants>
1950 {
1951  std::auto_ptr<EcalIntercalibConstants> ical =
1952  std::auto_ptr<EcalIntercalibConstants>( new EcalIntercalibConstants() );
1953 
1954  // Read the values from a txt file
1955  // -------------------------------
1956 
1957  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading intercalibration constants from file "
1958  << intercalibConstantsFile_.c_str() ;
1959 
1960  FILE *inpFile ;
1961  inpFile = fopen (intercalibConstantsFile_.c_str (),"r") ;
1962  if (!inpFile)
1963  {
1964  edm::LogError ("EcalTrivialConditionRetriever")
1965  << "*** Can not open file: " << intercalibConstantsFile_ ;
1966  throw cms::Exception ("Cannot open inter-calibration coefficients txt file") ;
1967  }
1968 
1969  char line[256] ;
1970  std::ostringstream str ;
1971  fgets (line,255,inpFile) ;
1972  int sm_number=atoi (line) ;
1973  str << "sm: " << sm_number ;
1974 
1975  fgets (line,255,inpFile) ;
1976  //int nevents=atoi (line) ; // not necessary here just for online conddb
1977 
1978  fgets (line,255,inpFile) ;
1979  std::string gen_tag = line ;
1980  str << "gen tag: " << gen_tag ; // should I use this?
1981 
1982  fgets (line,255,inpFile) ;
1983  std::string cali_method = line ;
1984  str << "cali method: " << cali_method << std::endl ; // not important
1985 
1986  fgets (line,255,inpFile) ;
1987  std::string cali_version = line ;
1988  str << "cali version: " << cali_version << std::endl ; // not important
1989 
1990  fgets (line,255,inpFile) ;
1991  std::string cali_type = line ;
1992  str << "cali type: " << cali_type ; // not important
1993 
1994  edm::LogInfo("EcalTrivialConditionRetriever")
1995  << "[PIETRO] Intercalibration file - "
1996  << str.str () << std::endl ;
1997 
1998  float calib[1700]={1} ;
1999  float calib_rms[1700]={0} ;
2000  int calib_nevents[1700]={0} ;
2001  int calib_status[1700]={0} ;
2002 
2003  int ii = 0 ;
2004 
2005  while (fgets (line,255,inpFile))
2006  {
2007  ii++;
2008  int dmy_num = 0 ;
2009  float dmy_calib = 0. ;
2010  float dmy_RMS = 0. ;
2011  int dmy_events = 0 ;
2012  int dmy_status = 0 ;
2013  sscanf (line, "%d %f %f %d %d", &dmy_num, &dmy_calib,
2014  &dmy_RMS, &dmy_events,
2015  &dmy_status) ;
2016  assert (dmy_num >= 1) ;
2017  assert (dmy_num <= 1700) ;
2018  calib[dmy_num-1] = dmy_calib ;
2019  calib_rms[dmy_num-1] = dmy_RMS ;
2020  calib_nevents[dmy_num-1] = dmy_events ;
2021  calib_status[dmy_num-1] = dmy_status ;
2022 
2023 // edm::LogInfo ("EcalTrivialConditionRetriever")
2024 // << "[PIETRO] cry = " << dmy_num
2025 // << " calib = " << calib[dmy_num-1]
2026 // << " RMS = " << calib_rms[dmy_num-1]
2027 // << " events = " << calib_nevents[dmy_num-1]
2028 // << " status = " << calib_status[dmy_num-1]
2029 // << std::endl ;
2030  }
2031 
2032  fclose (inpFile) ; // close inp. file
2033  edm::LogInfo ("EcalTrivialConditionRetriever") << "Read intercalibrations for " << ii << " xtals " ;
2034  if (ii!=1700) edm::LogWarning ("StoreEcalCondition")
2035  << "Some crystals missing, set to 1" << std::endl ;
2036 
2037  // Transfer the data to the inter-calibration coefficients container
2038  // -----------------------------------------------------------------
2039 
2040  // DB supermodule always set to 1 for the TestBeam FIXME
2041  int sm_db=1 ;
2042  // loop over channels
2043  for (int i=0 ; i<1700 ; i++)
2044  {
2045  //if (EBDetId::validDetId(iEta,iPhi)) {
2046  // CANNOT be used -- validDetId only checks ETA PHI method
2047  // doing a check by hand, here is the only place in CMSSW
2048  // outside TB code and EcalRawToDigi where needed
2049  // => no need for changing the DetId interface
2050  //
2051  // checking only sm_db -- guess can change with the above FIXME
2052  if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
2053  EBDetId ebid (sm_db,i+1,EBDetId::SMCRYSTALMODE) ;
2054  if (calib_status[i]) ical->setValue (ebid.rawId (), calib[i]) ;
2055  else ical->setValue (ebid.rawId (), 1.) ;
2056  }
2057  //}
2058  } // loop over channels
2059 
2060 // edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ;
2061  return ical;
2062 }
2063 
2064 
2065 std::auto_ptr<EcalIntercalibErrors>
2068 {
2069  std::auto_ptr<EcalIntercalibErrors> ical =
2070  std::auto_ptr<EcalIntercalibErrors>( new EcalIntercalibErrors() );
2071 
2072  // Read the values from a txt file
2073  // -------------------------------
2074 
2075  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading intercalibration constants from file "
2076  << intercalibErrorsFile_.c_str() ;
2077 
2078  FILE *inpFile ;
2079  inpFile = fopen (intercalibErrorsFile_.c_str (),"r") ;
2080  if (!inpFile)
2081  {
2082  edm::LogError ("EcalTrivialConditionRetriever")
2083  << "*** Can not open file: " << intercalibErrorsFile_ ;
2084  throw cms::Exception ("Cannot open inter-calibration coefficients txt file") ;
2085  }
2086 
2087  char line[256] ;
2088  std::ostringstream str ;
2089  fgets (line,255,inpFile) ;
2090  int sm_number=atoi (line) ;
2091  str << "sm: " << sm_number ;
2092 
2093  fgets (line,255,inpFile) ;
2094  //int nevents=atoi (line) ; // not necessary here just for online conddb
2095 
2096  fgets (line,255,inpFile) ;
2097  std::string gen_tag = line ;
2098  str << "gen tag: " << gen_tag ; // should I use this?
2099 
2100  fgets (line,255,inpFile) ;
2101  std::string cali_method = line ;
2102  str << "cali method: " << cali_method << std::endl ; // not important
2103 
2104  fgets (line,255,inpFile) ;
2105  std::string cali_version = line ;
2106  str << "cali version: " << cali_version << std::endl ; // not important
2107 
2108  fgets (line,255,inpFile) ;
2109  std::string cali_type = line ;
2110  str << "cali type: " << cali_type ; // not important
2111 
2112  edm::LogInfo("EcalTrivialConditionRetriever")
2113  << "[PIETRO] Intercalibration file - "
2114  << str.str () << std::endl ;
2115 
2116  float calib[1700]={1} ;
2117  float calib_rms[1700]={0} ;
2118  int calib_nevents[1700]={0} ;
2119  int calib_status[1700]={0} ;
2120 
2121  int ii = 0 ;
2122 
2123  while (fgets (line,255,inpFile))
2124  {
2125  ii++;
2126  int dmy_num = 0 ;
2127  float dmy_calib = 0. ;
2128  float dmy_RMS = 0. ;
2129  int dmy_events = 0 ;
2130  int dmy_status = 0 ;
2131  sscanf (line, "%d %f %f %d %d", &dmy_num, &dmy_calib,
2132  &dmy_RMS, &dmy_events,
2133  &dmy_status) ;
2134  assert (dmy_num >= 1) ;
2135  assert (dmy_num <= 1700) ;
2136  calib[dmy_num-1] = dmy_calib ;
2137  calib_rms[dmy_num-1] = dmy_RMS ;
2138  calib_nevents[dmy_num-1] = dmy_events ;
2139  calib_status[dmy_num-1] = dmy_status ;
2140 
2141 // edm::LogInfo ("EcalTrivialConditionRetriever")
2142 // << "[PIETRO] cry = " << dmy_num
2143 // << " calib = " << calib[dmy_num-1]
2144 // << " RMS = " << calib_rms[dmy_num-1]
2145 // << " events = " << calib_nevents[dmy_num-1]
2146 // << " status = " << calib_status[dmy_num-1]
2147 // << std::endl ;
2148  }
2149 
2150  fclose (inpFile) ; // close inp. file
2151  edm::LogInfo ("EcalTrivialConditionRetriever") << "Read intercalibrations for " << ii << " xtals " ;
2152  if (ii!=1700) edm::LogWarning ("StoreEcalCondition")
2153  << "Some crystals missing, set to 1" << std::endl ;
2154 
2155  // Transfer the data to the inter-calibration coefficients container
2156  // -----------------------------------------------------------------
2157 
2158  // DB supermodule always set to 1 for the TestBeam FIXME
2159  int sm_db=1 ;
2160  // loop over channels
2161  for (int i=0 ; i<1700 ; i++)
2162  {
2163  //if (EBDetId::validDetId(iEta,iPhi)) {
2164  // CANNOT be used -- validDetId only checks ETA PHI method
2165  // doing a check by hand, here is the only place in CMSSW
2166  // outside TB code and EcalRawToDigi where needed
2167  // => no need for changing the DetId interface
2168  //
2169  // checking only sm_db -- guess can change with the above FIXME
2170  if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
2171  EBDetId ebid (sm_db,i+1,EBDetId::SMCRYSTALMODE) ;
2172  if (calib_status[i]) ical->setValue (ebid.rawId (), calib[i]) ;
2173  else ical->setValue (ebid.rawId (), 1.) ;
2174  }
2175  //}
2176  } // loop over channels
2177 
2178 // edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ;
2179  return ical;
2180 }
2181 
2182 // --------------------------------------------------------------------------------
2183 
2184 
2185 std::auto_ptr<EcalTimeCalibConstants>
2188 {
2189  std::auto_ptr<EcalTimeCalibConstants> ical =
2190  std::auto_ptr<EcalTimeCalibConstants>( new EcalTimeCalibConstants() );
2191 
2192  // Read the values from a txt file
2193  // -------------------------------
2194 
2195  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading time calibration constants from file "
2196  << timeCalibConstantsFile_.c_str() ;
2197 
2198  FILE *inpFile ;
2199  inpFile = fopen (timeCalibConstantsFile_.c_str (),"r") ;
2200  if (!inpFile)
2201  {
2202  edm::LogError ("EcalTrivialConditionRetriever")
2203  << "*** Can not open file: " << timeCalibConstantsFile_ ;
2204  throw cms::Exception ("Cannot open inter-calibration coefficients txt file") ;
2205  }
2206 
2207  char line[256] ;
2208  std::ostringstream str ;
2209  fgets (line,255,inpFile) ;
2210  int sm_number=atoi (line) ;
2211  str << "sm: " << sm_number ;
2212 
2213  fgets (line,255,inpFile) ;
2214  //int nevents=atoi (line) ; // not necessary here just for online conddb
2215 
2216  fgets (line,255,inpFile) ;
2217  std::string gen_tag = line ;
2218  str << "gen tag: " << gen_tag ; // should I use this?
2219 
2220  fgets (line,255,inpFile) ;
2221  std::string cali_method = line ;
2222  str << "cali method: " << cali_method << std::endl ; // not important
2223 
2224  fgets (line,255,inpFile) ;
2225  std::string cali_version = line ;
2226  str << "cali version: " << cali_version << std::endl ; // not important
2227 
2228  fgets (line,255,inpFile) ;
2229  std::string cali_type = line ;
2230  str << "cali type: " << cali_type ; // not important
2231 
2232  edm::LogInfo("EcalTrivialConditionRetriever")
2233  << "TimeCalibration file - "
2234  << str.str () << std::endl ;
2235 
2236  float calib[1700]={1} ;
2237  float calib_rms[1700]={0} ;
2238  int calib_nevents[1700]={0} ;
2239  int calib_status[1700]={0} ;
2240 
2241  int ii = 0 ;
2242 
2243  while (fgets (line,255,inpFile))
2244  {
2245  ii++;
2246  int dmy_num = 0 ;
2247  float dmy_calib = 0. ;
2248  float dmy_RMS = 0. ;
2249  int dmy_events = 0 ;
2250  int dmy_status = 0 ;
2251  sscanf (line, "%d %f %f %d %d", &dmy_num, &dmy_calib,
2252  &dmy_RMS, &dmy_events,
2253  &dmy_status) ;
2254  assert (dmy_num >= 1) ;
2255  assert (dmy_num <= 1700) ;
2256  calib[dmy_num-1] = dmy_calib ;
2257  calib_rms[dmy_num-1] = dmy_RMS ;
2258  calib_nevents[dmy_num-1] = dmy_events ;
2259  calib_status[dmy_num-1] = dmy_status ;
2260 
2261 // edm::LogInfo ("EcalTrivialConditionRetriever")
2262 // << "[PIETRO] cry = " << dmy_num
2263 // << " calib = " << calib[dmy_num-1]
2264 // << " RMS = " << calib_rms[dmy_num-1]
2265 // << " events = " << calib_nevents[dmy_num-1]
2266 // << " status = " << calib_status[dmy_num-1]
2267 // << std::endl ;
2268  }
2269 
2270  fclose (inpFile) ; // close inp. file
2271  edm::LogInfo ("EcalTrivialConditionRetriever") << "Read timeCalibrations for " << ii << " xtals " ;
2272  if (ii!=1700) edm::LogWarning ("StoreEcalCondition")
2273  << "Some crystals missing, set to 1" << std::endl ;
2274 
2275  // Transfer the data to the inter-calibration coefficients container
2276  // -----------------------------------------------------------------
2277 
2278  // DB supermodule always set to 1 for the TestBeam FIXME
2279  int sm_db=1 ;
2280  // loop over channels
2281  for (int i=0 ; i<1700 ; i++)
2282  {
2283  //if (EBDetId::validDetId(iEta,iPhi)) {
2284  // CANNOT be used -- validDetId only checks ETA PHI method
2285  // doing a check by hand, here is the only place in CMSSW
2286  // outside TB code and EcalRawToDigi where needed
2287  // => no need for changing the DetId interface
2288  //
2289  // checking only sm_db -- guess can change with the above FIXME
2290  if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
2291  EBDetId ebid (sm_db,i+1,EBDetId::SMCRYSTALMODE) ;
2292  if (calib_status[i]) ical->setValue (ebid.rawId (), calib[i]) ;
2293  else ical->setValue (ebid.rawId (), 1.) ;
2294  }
2295  //}
2296  } // loop over channels
2297 
2298 // edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ;
2299  return ical;
2300 }
2301 
2302 
2303 std::auto_ptr<EcalTimeCalibErrors>
2306 {
2307  std::auto_ptr<EcalTimeCalibErrors> ical =
2308  std::auto_ptr<EcalTimeCalibErrors>( new EcalTimeCalibErrors() );
2309 
2310  // Read the values from a txt file
2311  // -------------------------------
2312 
2313  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading timeCalibration constants from file "
2314  << timeCalibErrorsFile_.c_str() ;
2315 
2316  FILE *inpFile ;
2317  inpFile = fopen (timeCalibErrorsFile_.c_str (),"r") ;
2318  if (!inpFile)
2319  {
2320  edm::LogError ("EcalTrivialConditionRetriever")
2321  << "*** Can not open file: " << timeCalibErrorsFile_ ;
2322  throw cms::Exception ("Cannot open inter-calibration coefficients txt file") ;
2323  }
2324 
2325  char line[256] ;
2326  std::ostringstream str ;
2327  fgets (line,255,inpFile) ;
2328  int sm_number=atoi (line) ;
2329  str << "sm: " << sm_number ;
2330 
2331  fgets (line,255,inpFile) ;
2332  //int nevents=atoi (line) ; // not necessary here just for online conddb
2333 
2334  fgets (line,255,inpFile) ;
2335  std::string gen_tag = line ;
2336  str << "gen tag: " << gen_tag ; // should I use this?
2337 
2338  fgets (line,255,inpFile) ;
2339  std::string cali_method = line ;
2340  str << "cali method: " << cali_method << std::endl ; // not important
2341 
2342  fgets (line,255,inpFile) ;
2343  std::string cali_version = line ;
2344  str << "cali version: " << cali_version << std::endl ; // not important
2345 
2346  fgets (line,255,inpFile) ;
2347  std::string cali_type = line ;
2348  str << "cali type: " << cali_type ; // not important
2349 
2350  edm::LogInfo("EcalTrivialConditionRetriever")
2351  << "TimeCalibration file - "
2352  << str.str () << std::endl ;
2353 
2354  float calib[1700]={1} ;
2355  float calib_rms[1700]={0} ;
2356  int calib_nevents[1700]={0} ;
2357  int calib_status[1700]={0} ;
2358 
2359  int ii = 0 ;
2360 
2361  while (fgets (line,255,inpFile))
2362  {
2363  ii++;
2364  int dmy_num = 0 ;
2365  float dmy_calib = 0. ;
2366  float dmy_RMS = 0. ;
2367  int dmy_events = 0 ;
2368  int dmy_status = 0 ;
2369  sscanf (line, "%d %f %f %d %d", &dmy_num, &dmy_calib,
2370  &dmy_RMS, &dmy_events,
2371  &dmy_status) ;
2372  assert (dmy_num >= 1) ;
2373  assert (dmy_num <= 1700) ;
2374  calib[dmy_num-1] = dmy_calib ;
2375  calib_rms[dmy_num-1] = dmy_RMS ;
2376  calib_nevents[dmy_num-1] = dmy_events ;
2377  calib_status[dmy_num-1] = dmy_status ;
2378 
2379 // edm::LogInfo ("EcalTrivialConditionRetriever")
2380 // << "[PIETRO] cry = " << dmy_num
2381 // << " calib = " << calib[dmy_num-1]
2382 // << " RMS = " << calib_rms[dmy_num-1]
2383 // << " events = " << calib_nevents[dmy_num-1]
2384 // << " status = " << calib_status[dmy_num-1]
2385 // << std::endl ;
2386  }
2387 
2388  fclose (inpFile) ; // close inp. file
2389  edm::LogInfo ("EcalTrivialConditionRetriever") << "Read time calibrations for " << ii << " xtals " ;
2390  if (ii!=1700) edm::LogWarning ("StoreEcalCondition")
2391  << "Some crystals missing, set to 1" << std::endl ;
2392 
2393  // Transfer the data to the inter-calibration coefficients container
2394  // -----------------------------------------------------------------
2395 
2396  // DB supermodule always set to 1 for the TestBeam FIXME
2397  int sm_db=1 ;
2398  // loop over channels
2399  for (int i=0 ; i<1700 ; i++)
2400  {
2401  //if (EBDetId::validDetId(iEta,iPhi)) {
2402  // CANNOT be used -- validDetId only checks ETA PHI method
2403  // doing a check by hand, here is the only place in CMSSW
2404  // outside TB code and EcalRawToDigi where needed
2405  // => no need for changing the DetId interface
2406  //
2407  // checking only sm_db -- guess can change with the above FIXME
2408  if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
2409  EBDetId ebid (sm_db,i+1,EBDetId::SMCRYSTALMODE) ;
2410  if (calib_status[i]) ical->setValue (ebid.rawId (), calib[i]) ;
2411  else ical->setValue (ebid.rawId (), 1.) ;
2412  }
2413  //}
2414  } // loop over channels
2415 
2416 // edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ;
2417  return ical;
2418 }
2419 
2420 // --------------------------------------------------------------------------------
2421 
2422 std::auto_ptr<EcalMappingElectronics>
2424 {
2425  std::auto_ptr<EcalMappingElectronics> mapping = std::auto_ptr<EcalMappingElectronics>( new EcalMappingElectronics() );
2426  edm::LogInfo("EcalTrivialConditionRetriever") << "Reading mapping from file " << edm::FileInPath(mappingFile_).fullPath().c_str() ;
2427 
2428  std::ifstream f(edm::FileInPath(mappingFile_).fullPath().c_str());
2429  if (!f.good())
2430  {
2431  edm::LogError("EcalTrivialConditionRetriever") << "File not found";
2432  throw cms::Exception("FileNotFound");
2433  }
2434 
2435  // uint32_t detid, elecid, triggerid;
2436 
2437  int ix, iy, iz, CL;
2438  // int dccid, towerid, stripid, xtalid;
2439  // int tccid, tower, ipseudostrip, xtalinps;
2440  int dccid, towerid, pseudostrip_in_SC, xtal_in_pseudostrip;
2441  int tccid, tower, pseudostrip_in_TCC, pseudostrip_in_TT;
2442 
2443  while ( ! f.eof())
2444  {
2445  // f >> detid >> elecid >> triggerid;
2446  f >> ix >> iy >> iz >> CL >> dccid >> towerid >> pseudostrip_in_SC >> xtal_in_pseudostrip >> tccid >> tower >>
2447  pseudostrip_in_TCC >> pseudostrip_in_TT ;
2448 
2449 // if (!EEDetId::validDetId(ix,iy,iz))
2450 // continue;
2451 
2452  EEDetId detid(ix,iy,iz,EEDetId::XYMODE);
2453  // std::cout << " dcc tower ps_in_SC xtal_in_ps " << dccid << " " << towerid << " " << pseudostrip_in_SC << " " << xtal_in_pseudostrip << std::endl;
2454  EcalElectronicsId elecid(dccid,towerid, pseudostrip_in_SC, xtal_in_pseudostrip);
2455  // std::cout << " tcc tt ps_in_TT xtal_in_ps " << tccid << " " << tower << " " << pseudostrip_in_TT << " " << xtal_in_pseudostrip << std::endl;
2456  EcalTriggerElectronicsId triggerid(tccid, tower, pseudostrip_in_TT, xtal_in_pseudostrip);
2457  EcalMappingElement aElement;
2458  aElement.electronicsid = elecid.rawId();
2459  aElement.triggerid = triggerid.rawId();
2460  (*mapping).setValue(detid, aElement);
2461  }
2462 
2463  f.close();
2464  return mapping;
2465 }
2466 
2467 
2468 
2469 std::auto_ptr<EcalMappingElectronics>
2471 {
2472 
2473  std::auto_ptr<EcalMappingElectronics> ical = std::auto_ptr<EcalMappingElectronics>( new EcalMappingElectronics() );
2474  return ical;
2475 }
EcalChi2WeightMatrix & getChi2WeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:29
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.cc:59
EcalDAQTowerStatusMap EcalDAQTowerStatus
virtual std::auto_ptr< EcalTimeCalibConstants > produceEcalTimeCalibConstants(const EcalTimeCalibConstantsRcd &)
static bool validDetId(int ix, int iy, int iz)
Definition: EcalScDetId.cc:63
virtual std::auto_ptr< EcalChannelStatus > produceEcalChannelStatus(const EcalChannelStatusRcd &)
virtual std::auto_ptr< EcalIntercalibConstants > getIntercalibConstantsFromConfiguration(const EcalIntercalibConstantsRcd &)
EcalIntercalibConstantMCMap EcalIntercalibConstantsMC
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
static const int MIN_IPHI
Definition: EBDetId.h:121
virtual void setIntervalFor(const edm::eventsetup::EventSetupRecordKey &, const edm::IOVSyncValue &, edm::ValidityInterval &)
virtual std::auto_ptr< EcalClusterCrackCorrParameters > produceEcalClusterCrackCorrParameters(const EcalClusterCrackCorrParametersRcd &)
EcalFunParams EcalClusterCrackCorrParameters
virtual std::auto_ptr< EcalTPGCrystalStatus > produceEcalTrgChannelStatus(const EcalTPGCrystalStatusRcd &)
virtual std::auto_ptr< EcalChannelStatus > getChannelStatusFromConfiguration(const EcalChannelStatusRcd &)
Ecal readout channel identification [32:20] Unused (so far) [19:13] DCC id [12:6] tower [5:3] strip [...
virtual std::auto_ptr< EcalTBWeights > produceEcalTBWeights(const EcalTBWeightsRcd &)
virtual std::auto_ptr< EcalMappingElectronics > produceEcalMappingElectronics(const EcalMappingElectronicsRcd &)
static const int XYMODE
Definition: EEDetId.h:316
static const IOVSyncValue & endOfTime()
Definition: IOVSyncValue.cc:97
EcalTimeCalibErrorMap EcalTimeCalibErrors
EcalCondObjectContainer< EcalXtalGroupId > EcalWeightXtalGroups
EcalLaserAPDPNRatiosRefMap EcalLaserAPDPNRatiosRef
std::pair< Time_t, Time_t > ValidityInterval
Definition: Time.h:19
void getWeightsFromConfiguration(const edm::ParameterSet &ps)
static EEDetId unhashIndex(int hi)
Definition: EEDetId.cc:115
virtual std::auto_ptr< EcalPedestals > produceEcalPedestals(const EcalPedestalsRcd &)
virtual std::auto_ptr< EcalLaserAPDPNRatios > produceEcalLaserAPDPNRatios(const EcalLaserAPDPNRatiosRcd &)
static const int IX_MIN
Definition: EEDetId.h:271
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.cc:562
static const int IY_MIN
Definition: EEDetId.h:275
virtual std::auto_ptr< EcalLaserAlphas > produceEcalLaserAlphas(const EcalLaserAlphasRcd &)
static const int MIN_SM
Definition: EBDetId.h:131
int path() const
Definition: HLTadd.h:3
void setGain12Over6(const float &g)
uint32_t rawId() const
get the raw id
Definition: DetId.h:45
virtual std::auto_ptr< EcalTimeCalibConstants > getTimeCalibConstantsFromConfiguration(const EcalTimeCalibConstantsRcd &)
virtual std::auto_ptr< EcalDAQTowerStatus > produceEcalDAQTowerStatus(const EcalDAQTowerStatusRcd &)
EcalDQMChannelStatusMap EcalDQMChannelStatus
MVATrainerComputer * calib
Definition: MVATrainer.cc:64
EcalMappingElectronicsMap EcalMappingElectronics
EcalChannelStatusMap EcalChannelStatus
EcalGainRatioMap EcalGainRatios
virtual std::auto_ptr< EcalADCToGeVConstant > produceEcalADCToGeVConstant(const EcalADCToGeVConstantRcd &)
static const IOVSyncValue & beginOfTime()
virtual std::auto_ptr< EcalClusterLocalContCorrParameters > produceEcalClusterLocalContCorrParameters(const EcalClusterLocalContCorrParametersRcd &)
EcalLaserAlphaMap EcalLaserAlphas
EcalDCSTowerStatusMap EcalDCSTowerStatus
EcalDQMTowerStatusMap EcalDQMTowerStatus
virtual std::auto_ptr< EcalWeightXtalGroups > produceEcalWeightXtalGroups(const EcalWeightXtalGroupsRcd &)
virtual std::auto_ptr< EcalIntercalibErrors > getIntercalibErrorsFromConfiguration(const EcalIntercalibErrorsRcd &)
EcalTPGCrystalStatusMap EcalTPGCrystalStatus
int j
Definition: DBlmapReader.cc:9
EcalChi2WeightMatrix & getChi2WeightsAfterGainSwitch()
Definition: EcalWeightSet.h:30
virtual std::auto_ptr< EcalDQMTowerStatus > produceEcalDQMTowerStatus(const EcalDQMTowerStatusRcd &)
double f[11][100]
virtual std::auto_ptr< EcalClusterEnergyUncertaintyParameters > produceEcalClusterEnergyUncertaintyParameters(const EcalClusterEnergyUncertaintyParametersRcd &)
virtual std::auto_ptr< EcalMappingElectronics > getMappingFromConfiguration(const EcalMappingElectronicsRcd &)
virtual std::auto_ptr< EcalIntercalibErrors > produceEcalIntercalibErrors(const EcalIntercalibErrorsRcd &)
virtual std::auto_ptr< EcalTimeCalibErrors > produceEcalTimeCalibErrors(const EcalTimeCalibErrorsRcd &)
virtual std::auto_ptr< EcalTPGCrystalStatus > getTrgChannelStatusFromConfiguration(const EcalTPGCrystalStatusRcd &)
virtual std::auto_ptr< EcalClusterEnergyCorrectionParameters > produceEcalClusterEnergyCorrectionParameters(const EcalClusterEnergyCorrectionParametersRcd &)
EcalWeightMatrix & getWeightsAfterGainSwitch()
Definition: EcalWeightSet.h:28
uint32_t rawId() const
EcalIntercalibErrorMap EcalIntercalibErrors
int k[5][pyjets_maxn]
math::Matrix< 10, 10 >::type EcalChi2WeightMatrix
Definition: EcalWeightSet.h:21
static const int IX_MAX
Definition: EEDetId.h:279
EcalFunParams EcalClusterEnergyUncertaintyParameters
virtual std::auto_ptr< EcalDCSTowerStatus > produceEcalDCSTowerStatus(const EcalDCSTowerStatusRcd &)
TimeValue_t value() const
Definition: Timestamp.cc:72
virtual std::auto_ptr< EcalIntercalibConstants > produceEcalIntercalibConstants(const EcalIntercalibConstantsRcd &)
virtual std::auto_ptr< EcalIntercalibConstantsMC > produceEcalIntercalibConstantsMC(const EcalIntercalibConstantsMCRcd &)
EcalPedestalsMap EcalPedestals
Definition: EcalPedestals.h:38
static const int MAX_IPHI
Definition: EBDetId.h:123
EcalWeightMatrix & getWeightsBeforeGainSwitch()
Definition: EcalWeightSet.h:27
EcalTimeCalibConstantMap EcalTimeCalibConstants
EcalTrivialConditionRetriever(const edm::ParameterSet &pset)
static EBDetId unhashIndex(int hi)
get a DetId from a compact index for arrays
Definition: EBDetId.cc:12
static const int MAX_IETA
Definition: EBDetId.h:122
virtual std::auto_ptr< EcalLaserAPDPNRatiosRef > produceEcalLaserAPDPNRatiosRef(const EcalLaserAPDPNRatiosRefRcd &)
EcalFunParams EcalClusterLocalContCorrParameters
EcalIntercalibConstantMap EcalIntercalibConstants
static bool validDetId(int iz, EcalSubdetector sd, int i, int j)
check if a valid index combination
#define begin
Definition: vmac.h:31
static Timestamp const & endOfTime()
Definition: Timestamp.cc:88
EcalFunParams EcalClusterEnergyCorrectionParameters
Signal rand(Signal arg)
Definition: vlib.cc:442
math::Matrix< 3, 10 >::type EcalWeightMatrix
Definition: EcalWeightSet.h:20
virtual std::auto_ptr< EcalTimeCalibErrors > getTimeCalibErrorsFromConfiguration(const EcalTimeCalibErrorsRcd &)
const Timestamp & time() const
Definition: IOVSyncValue.h:44
tuple cout
Definition: gather_cfg.py:41
static const int MAX_SM
Definition: EBDetId.h:132
static const int IY_MAX
Definition: EEDetId.h:283
std::string fullPath() const
Definition: FileInPath.cc:170
tuple status
Definition: ntuplemaker.py:245
virtual std::auto_ptr< EcalDQMChannelStatus > produceEcalDQMChannelStatus(const EcalDQMChannelStatusRcd &)
static const int SMCRYSTALMODE
Definition: EBDetId.h:146
virtual std::auto_ptr< EcalGainRatios > produceEcalGainRatios(const EcalGainRatiosRcd &)
Ecal trigger electronics identification [32:20] Unused (so far) [19:13] TCC id [12:6] TT id [5:3] pse...
tuple size
Write out results.