CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/CalibCalorimetry/EcalTrivialCondModules/src/EcalTrivialConditionRetriever.cc

Go to the documentation of this file.
00001 //
00002 // $Id: EcalTrivialConditionRetriever.cc,v 1.56 2012/11/21 16:56:13 fra Exp $
00003 // Created: 2 Mar 2006
00004 //          Shahram Rahatlou, University of Rome & INFN
00005 //
00006 #include <iostream>
00007 #include <fstream>
00008 
00009 #include "CalibCalorimetry/EcalTrivialCondModules/interface/EcalTrivialConditionRetriever.h"
00010 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00011 #include "FWCore/Utilities/interface/Exception.h"
00012 
00013 #include "DataFormats/EcalDetId/interface/EBDetId.h"
00014 #include "DataFormats/EcalDetId/interface/EEDetId.h"
00015 #include "DataFormats/EcalDetId/interface/ESDetId.h"
00016 #include "DataFormats/EcalDetId/interface/EcalElectronicsId.h"
00017 #include "DataFormats/EcalDetId/interface/EcalTriggerElectronicsId.h"
00018 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00019 
00020 //#include "DataFormats/Provenance/interface/Timestamp.h"
00021 
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023 
00024 
00025 using namespace edm;
00026 
00027 EcalTrivialConditionRetriever::EcalTrivialConditionRetriever( const edm::ParameterSet&  ps)
00028 {
00029   // initilize parameters used to produce cond DB objects
00030   adcToGeVEBConstant_ = ps.getUntrackedParameter<double>("adcToGeVEBConstant",0.035);
00031   adcToGeVEEConstant_ = ps.getUntrackedParameter<double>("adcToGeVEEConstant",0.060);
00032 
00033   intercalibConstantMeanMC_ = ps.getUntrackedParameter<double>("intercalibConstantMeanMC",1.0);
00034   intercalibConstantSigmaMC_ = ps.getUntrackedParameter<double>("intercalibConstantSigmaMC",0.0);
00035 
00036   linCorrMean_ = ps.getUntrackedParameter<double>("linCorrMean",1.0);
00037   linCorrSigma_ = ps.getUntrackedParameter<double>("linCorrSigma",0.0);
00038   intercalibConstantMean_ = ps.getUntrackedParameter<double>("intercalibConstantMean",1.0);
00039   intercalibConstantSigma_ = ps.getUntrackedParameter<double>("intercalibConstantSigma",0.0);
00040   intercalibErrorMean_ = ps.getUntrackedParameter<double>("IntercalibErrorMean",0.0);
00041 
00042   timeCalibConstantMean_ = ps.getUntrackedParameter<double>("timeCalibConstantMean",0.0);
00043   timeCalibConstantSigma_ = ps.getUntrackedParameter<double>("timeCalibConstantSigma",0.0);
00044   timeCalibErrorMean_ = ps.getUntrackedParameter<double>("timeCalibErrorMean",0.0);
00045 
00046   timeOffsetEBConstant_ = ps.getUntrackedParameter<double>("timeOffsetEBConstant",0.0);
00047   timeOffsetEEConstant_ = ps.getUntrackedParameter<double>("timeOffsetEEConstant",0.0);
00048 
00049   laserAlphaMean_  = ps.getUntrackedParameter<double>("laserAlphaMean",1.55);
00050   laserAlphaSigma_ = ps.getUntrackedParameter<double>("laserAlphaSigma",0);
00051 
00052   laserAPDPNTime1_ = (unsigned long)atoi( ps.getUntrackedParameter<std::string>("laserAPDPNTime1","1").c_str());
00053   laserAPDPNTime2_= (unsigned long)atoi( ps.getUntrackedParameter<std::string>("laserAPDPNTime2","0").c_str());
00054   laserAPDPNTime3_= (unsigned long)atoi( ps.getUntrackedParameter<std::string>("laserAPDPNTime3","0").c_str());
00055 
00056   laserAPDPNRefMean_ = ps.getUntrackedParameter<double>("laserAPDPNRefMean",1.0);
00057   laserAPDPNRefSigma_ = ps.getUntrackedParameter<double>("laserAPDPNRefSigma",0.0);
00058 
00059   laserAPDPNMean_ = ps.getUntrackedParameter<double>("laserAPDPNMean",1.0);
00060   laserAPDPNSigma_ = ps.getUntrackedParameter<double>("laserAPDPNSigma",0.0);
00061 
00062   localContCorrParameters_ = ps.getUntrackedParameter< std::vector<double> >("localContCorrParameters", std::vector<double>(0) );
00063   crackCorrParameters_ = ps.getUntrackedParameter< std::vector<double> >("crackCorrParameters", std::vector<double>(0) );
00064   energyCorrectionParameters_ = ps.getUntrackedParameter< std::vector<double> >("energyCorrectionParameters", std::vector<double>(0) );
00065   energyUncertaintyParameters_ = ps.getUntrackedParameter< std::vector<double> >("energyUncertaintyParameters", std::vector<double>(0) );
00066   energyCorrectionObjectSpecificParameters_ = ps.getUntrackedParameter< std::vector<double> >("energyCorrectionObjectSpecificParameters", std::vector<double>(0) );
00067 
00068   EBpedMeanX12_ = ps.getUntrackedParameter<double>("EBpedMeanX12", 200.);
00069   EBpedRMSX12_  = ps.getUntrackedParameter<double>("EBpedRMSX12",  1.10);
00070   EBpedMeanX6_  = ps.getUntrackedParameter<double>("EBpedMeanX6",  200.);
00071   EBpedRMSX6_   = ps.getUntrackedParameter<double>("EBpedRMSX6",   0.90);
00072   EBpedMeanX1_  = ps.getUntrackedParameter<double>("EBpedMeanX1",  200.);
00073   EBpedRMSX1_   = ps.getUntrackedParameter<double>("EBpedRMSX1",   0.62);
00074 
00075   EEpedMeanX12_ = ps.getUntrackedParameter<double>("EEpedMeanX12", 200.);
00076   EEpedRMSX12_  = ps.getUntrackedParameter<double>("EEpedRMSX12",  2.50);
00077   EEpedMeanX6_  = ps.getUntrackedParameter<double>("EEpedMeanX6",  200.);
00078   EEpedRMSX6_   = ps.getUntrackedParameter<double>("EEpedRMSX6",   2.00);
00079   EEpedMeanX1_  = ps.getUntrackedParameter<double>("EEpedMeanX1",  200.);
00080   EEpedRMSX1_   = ps.getUntrackedParameter<double>("EEpedRMSX1",   1.40);
00081 
00082   gainRatio12over6_ = ps.getUntrackedParameter<double>("gainRatio12over6", 2.0);
00083   gainRatio6over1_  = ps.getUntrackedParameter<double>("gainRatio6over1",  6.0);
00084 
00085   getWeightsFromFile_ = ps.getUntrackedParameter<bool>("getWeightsFromFile",false);
00086 
00087   sampleMaskEB_ = ps.getUntrackedParameter<unsigned int>("sampleMaskEB",1023);
00088   sampleMaskEE_ = ps.getUntrackedParameter<unsigned int>("sampleMaskEB",1023);
00089 
00090   nTDCbins_ = 1;
00091 
00092   std::cout << " EcalTrivialConditionRetriever " << std::endl;
00093   weightsForAsynchronousRunning_ = ps.getUntrackedParameter<bool>("weightsForTB",false);
00094 
00095   if (weightsForAsynchronousRunning_)
00096     {
00097       getWeightsFromFile_ = true; //override user request 
00098       //nTDCbins_ = 25;
00099       nTDCbins_ = 50; //modif Alex-21-07-2006
00100     }
00101 
00102   std::string path="CalibCalorimetry/EcalTrivialCondModules/data/";
00103   std::string weightType;
00104   std::ostringstream str;
00105 
00106   if (!weightsForAsynchronousRunning_)
00107     str << "_CMS.txt" ;
00108   else
00109     str << "_TB.txt" ;
00110 
00111   weightType = str.str();
00112 
00113   amplWeightsFile_ = ps.getUntrackedParameter<std::string>("amplWeightsFile",path+"ampWeights"+weightType);
00114   amplWeightsAftFile_ = ps.getUntrackedParameter<std::string>("amplWeightsAftFile",path+"ampWeightsAfterGainSwitch"+weightType);
00115   pedWeightsFile_ = ps.getUntrackedParameter<std::string>("pedWeightsFile",path+"pedWeights"+weightType);
00116   pedWeightsAftFile_ = ps.getUntrackedParameter<std::string>("pedWeightsAftFile",path+"pedWeightsAfterGainSwitch"+weightType);
00117   jittWeightsFile_ = ps.getUntrackedParameter<std::string>("jittWeightsFile",path+"timeWeights"+weightType);
00118   jittWeightsAftFile_ = ps.getUntrackedParameter<std::string>("jittWeightsAftFile",path+"timeWeightsAfterGainSwitch"+weightType);
00119   chi2MatrixFile_ = ps.getUntrackedParameter<std::string>("chi2MatrixFile",path+"chi2Matrix"+weightType);
00120   chi2MatrixAftFile_ = ps.getUntrackedParameter<std::string>("chi2MatrixAftFile",path+"chi2MatrixAfterGainSwitch"+weightType);
00121 
00122   amplWeights_.resize(nTDCbins_);  
00123   amplWeightsAft_.resize(nTDCbins_); 
00124   pedWeights_.resize(nTDCbins_);  
00125   pedWeightsAft_.resize(nTDCbins_); 
00126   jittWeights_.resize(nTDCbins_);  
00127   jittWeightsAft_.resize(nTDCbins_); 
00128   chi2Matrix_.resize(nTDCbins_);
00129   chi2MatrixAft_.resize(nTDCbins_);
00130 
00131   // default weights for MGPA shape after pedestal subtraction
00132   getWeightsFromConfiguration(ps);
00133 
00134   producedEcalPedestals_ = ps.getUntrackedParameter<bool>("producedEcalPedestals",true);
00135   producedEcalWeights_ = ps.getUntrackedParameter<bool>("producedEcalWeights",true);
00136 
00137   producedEcalGainRatios_ = ps.getUntrackedParameter<bool>("producedEcalGainRatios",true);
00138   producedEcalADCToGeVConstant_ = ps.getUntrackedParameter<bool>("producedEcalADCToGeVConstant",true);
00139 
00140   producedEcalMappingElectronics_ = ps.getUntrackedParameter<bool>("producedEcalMappingElectronics",true);
00141   mappingFile_ = ps.getUntrackedParameter<std::string>("mappingFile","");
00142 
00143   if ( producedEcalMappingElectronics_ ) {
00144     if ( mappingFile_ != "" ) { // if file provided read channel map
00145       setWhatProduced( this, &EcalTrivialConditionRetriever::getMappingFromConfiguration );
00146     } else { 
00147       setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalMappingElectronics );
00148     }
00149     findingRecord<EcalMappingElectronicsRcd>();
00150   }
00151   // Alignment from file
00152   getEBAlignmentFromFile_ = ps.getUntrackedParameter<bool>("getEBAlignmentFromFile",false);
00153   if(getEBAlignmentFromFile_) {
00154     EBAlignmentFile_ = ps.getUntrackedParameter<std::string>("EBAlignmentFile",path+"EBAlignment.txt");
00155   }
00156 
00157   getEEAlignmentFromFile_ = ps.getUntrackedParameter<bool>("getEEAlignmentFromFile",false);
00158   if(getEEAlignmentFromFile_) {
00159     EEAlignmentFile_ = ps.getUntrackedParameter<std::string>("EEAlignmentFile",path+"EEAlignment.txt");
00160   }
00161 
00162   getESAlignmentFromFile_ = ps.getUntrackedParameter<bool>("getESAlignmentFromFile",false);
00163   if(getESAlignmentFromFile_)
00164     ESAlignmentFile_ = ps.getUntrackedParameter<std::string>("ESAlignmentFile",path+"ESAlignment.txt");
00165 
00166   verbose_ = ps.getUntrackedParameter<int>("verbose", 0);
00167 
00168   //Tell Producer what we produce
00169   //setWhatproduce(this);
00170   if (producedEcalPedestals_)
00171     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalPedestals );
00172 
00173   if (producedEcalWeights_) {
00174       setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalWeightXtalGroups );
00175       setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalTBWeights );
00176     }
00177 
00178   if (producedEcalGainRatios_)
00179     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalGainRatios );
00180 
00181   if (producedEcalADCToGeVConstant_)
00182     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalADCToGeVConstant );
00183 
00184   // TimeOffsetConstant
00185   producedEcalTimeOffsetConstant_ = ps.getUntrackedParameter<bool>("producedEcalTimeOffsetConstant",true);
00186   //std::cout << " EcalTrivialConditionRetriever : producedEcalTimeOffsetConstant_" << producedEcalTimeOffsetConstant_ << std::endl;
00187   if (producedEcalTimeOffsetConstant_) {
00188     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalTimeOffsetConstant );
00189     findingRecord<EcalTimeOffsetConstantRcd>();
00190   }
00191 
00192   // linear corrections
00193   producedEcalLinearCorrections_ = ps.getUntrackedParameter<bool>("producedEcalLinearCorrections",true);
00194   linearCorrectionsFile_ = ps.getUntrackedParameter<std::string>("linearCorrectionsFile","") ;
00195 
00196   if (producedEcalLinearCorrections_) { // user asks to produce constants
00197     if(linearCorrectionsFile_ != "") {  // if file provided read constants
00198         setWhatProduced (this, &EcalTrivialConditionRetriever::getLinearCorrectionsFromConfiguration ) ;
00199     } else { // set all constants to 1. or smear as specified by user
00200         setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalLinearCorrections ) ;
00201     }
00202     findingRecord<EcalLinearCorrectionsRcd> () ;
00203   }
00204 
00205 
00206 
00207   // intercalibration constants
00208   producedEcalIntercalibConstants_ = ps.getUntrackedParameter<bool>("producedEcalIntercalibConstants",true);
00209   intercalibConstantsFile_ = ps.getUntrackedParameter<std::string>("intercalibConstantsFile","") ;
00210 
00211   if (producedEcalIntercalibConstants_) { // user asks to produce constants
00212     if(intercalibConstantsFile_ != "") {  // if file provided read constants
00213         setWhatProduced (this, &EcalTrivialConditionRetriever::getIntercalibConstantsFromConfiguration ) ;
00214     } else { // set all constants to 1. or smear as specified by user
00215         setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalIntercalibConstants ) ;
00216     }
00217     findingRecord<EcalIntercalibConstantsRcd> () ;
00218   }
00219   // MC intercalibrations
00220   producedEcalIntercalibConstantsMC_ = ps.getUntrackedParameter<bool>("producedEcalIntercalibConstantsMC",true);
00221 
00222   if (producedEcalIntercalibConstantsMC_) { // user asks to produce constants
00223     setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalIntercalibConstantsMC ) ;
00224     findingRecord<EcalIntercalibConstantsMCRcd> () ;
00225   }
00226 
00227   // intercalibration constants
00228   producedEcalIntercalibErrors_ = ps.getUntrackedParameter<bool>("producedEcalIntercalibErrors",true);
00229   intercalibErrorsFile_ = ps.getUntrackedParameter<std::string>("intercalibErrorsFile","") ;
00230 
00231   if (producedEcalIntercalibErrors_) { // user asks to produce constants
00232     if(intercalibErrorsFile_ != "") {  // if file provided read constants
00233         setWhatProduced (this, &EcalTrivialConditionRetriever::getIntercalibErrorsFromConfiguration ) ;
00234     } else { // set all constants to 1. or smear as specified by user
00235         setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalIntercalibErrors ) ;
00236     }
00237     findingRecord<EcalIntercalibErrorsRcd> () ;
00238   }
00239 
00240   // time calibration constants
00241   producedEcalTimeCalibConstants_ = ps.getUntrackedParameter<bool>("producedEcalTimeCalibConstants",true);
00242   timeCalibConstantsFile_ = ps.getUntrackedParameter<std::string>("timeCalibConstantsFile","") ;
00243 
00244   if (producedEcalTimeCalibConstants_) { // user asks to produce constants
00245     if(timeCalibConstantsFile_ != "") {  // if file provided read constants
00246         setWhatProduced (this, &EcalTrivialConditionRetriever::getTimeCalibConstantsFromConfiguration ) ;
00247     } else { // set all constants to 1. or smear as specified by user
00248         setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalTimeCalibConstants ) ;
00249     }
00250     findingRecord<EcalTimeCalibConstantsRcd> () ;
00251   }
00252 
00253   // time calibration constants
00254   producedEcalTimeCalibErrors_ = ps.getUntrackedParameter<bool>("producedEcalTimeCalibErrors",true);
00255   timeCalibErrorsFile_ = ps.getUntrackedParameter<std::string>("timeCalibErrorsFile","") ;
00256 
00257   if (producedEcalTimeCalibErrors_) { // user asks to produce constants
00258     if(timeCalibErrorsFile_ != "") {  // if file provided read constants
00259         setWhatProduced (this, &EcalTrivialConditionRetriever::getTimeCalibErrorsFromConfiguration ) ;
00260     } else { // set all constants to 1. or smear as specified by user
00261         setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalTimeCalibErrors ) ;
00262     }
00263     findingRecord<EcalTimeCalibErrorsRcd> () ;
00264   }
00265 
00266   // cluster corrections
00267   producedEcalClusterLocalContCorrParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterLocalContCorrParameters", false);
00268   producedEcalClusterCrackCorrParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterCrackCorrParameters", false);
00269   producedEcalClusterEnergyCorrectionParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterEnergyCorrectionParameters", false);
00270   producedEcalClusterEnergyUncertaintyParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterEnergyUncertaintyParameters", false);
00271   producedEcalClusterEnergyCorrectionObjectSpecificParameters_ = ps.getUntrackedParameter<bool>("producedEcalClusterEnergyCorrectionObjectSpecificParameters", false);
00272   if ( producedEcalClusterLocalContCorrParameters_ ) {
00273           setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalClusterLocalContCorrParameters );
00274           findingRecord<EcalClusterLocalContCorrParametersRcd>();
00275   }
00276   if ( producedEcalClusterCrackCorrParameters_ ) {
00277           setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalClusterCrackCorrParameters );
00278           findingRecord<EcalClusterCrackCorrParametersRcd>();
00279   }
00280   if ( producedEcalClusterEnergyCorrectionParameters_ ) {
00281           setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalClusterEnergyCorrectionParameters );
00282           findingRecord<EcalClusterEnergyCorrectionParametersRcd>();
00283   }
00284   if ( producedEcalClusterEnergyUncertaintyParameters_ ) {
00285           setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalClusterEnergyUncertaintyParameters );
00286           findingRecord<EcalClusterEnergyUncertaintyParametersRcd>();
00287   }
00288   if ( producedEcalClusterEnergyCorrectionObjectSpecificParameters_ ) {
00289     setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalClusterEnergyCorrectionObjectSpecificParameters );
00290     findingRecord<EcalClusterEnergyCorrectionObjectSpecificParametersRcd>();
00291   }
00292 
00293   // laser correction
00294   producedEcalLaserCorrection_ = ps.getUntrackedParameter<bool>("producedEcalLaserCorrection",true);
00295   if (producedEcalLaserCorrection_) { // user asks to produce constants
00296     // set all constants to 1. or smear as specified by user
00297     setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalLaserAlphas ) ;
00298     findingRecord<EcalLaserAlphasRcd> () ;
00299     getLaserAlphaFromFile_ = ps.getUntrackedParameter<bool>("getLaserAlphaFromFile",false);
00300     std::cout << " getLaserAlphaFromFile_ " <<  getLaserAlphaFromFile_ << std::endl;
00301     if(getLaserAlphaFromFile_) {
00302       EBLaserAlphaFile_ = ps.getUntrackedParameter<std::string>("EBLaserAlphaFile",path+"EBLaserAlpha.txt");
00303       EELaserAlphaFile_ = ps.getUntrackedParameter<std::string>("EELaserAlphaFile",path+"EELaserAlpha.txt");
00304       std::cout << " EELaserAlphaFile_ " <<  EELaserAlphaFile_.c_str() << std::endl;
00305     }
00306     setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalLaserAPDPNRatiosRef ) ;
00307     findingRecord<EcalLaserAPDPNRatiosRefRcd> () ;
00308     setWhatProduced (this, &EcalTrivialConditionRetriever::produceEcalLaserAPDPNRatios) ;
00309     findingRecord<EcalLaserAPDPNRatiosRcd> () ;
00310   }
00311 
00312   // channel status
00313   producedEcalChannelStatus_ = ps.getUntrackedParameter<bool>("producedEcalChannelStatus",true);
00314   channelStatusFile_ = ps.getUntrackedParameter<std::string>("channelStatusFile","");
00315 
00316   if ( producedEcalChannelStatus_ ) {
00317           if ( channelStatusFile_ != "" ) { // if file provided read channel map
00318                   setWhatProduced( this, &EcalTrivialConditionRetriever::getChannelStatusFromConfiguration );
00319           } else { // set all channels to working -- FIXME might be changed
00320                   setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalChannelStatus );
00321           }
00322           findingRecord<EcalChannelStatusRcd>();
00323   }
00324   // DQM channel status
00325   producedEcalDQMChannelStatus_ = ps.getUntrackedParameter<bool>("producedEcalDQMChannelStatus",true);
00326   if ( producedEcalDQMChannelStatus_ ) {
00327     setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalDQMChannelStatus );
00328     findingRecord<EcalDQMChannelStatusRcd>();
00329   }
00330   // DCS Tower status
00331   producedEcalDCSTowerStatus_ = ps.getUntrackedParameter<bool>("producedEcalDCSTowerStatus",true);
00332   if ( producedEcalDCSTowerStatus_ ) {
00333     setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalDCSTowerStatus );
00334     findingRecord<EcalDCSTowerStatusRcd>();
00335   }
00336   // DAQ Tower status
00337   producedEcalDAQTowerStatus_ = ps.getUntrackedParameter<bool>("producedEcalDAQTowerStatus",true);
00338   if ( producedEcalDAQTowerStatus_ ) {
00339     setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalDAQTowerStatus );
00340     findingRecord<EcalDAQTowerStatusRcd>();
00341   }
00342   // DQM Tower status
00343   producedEcalDQMTowerStatus_ = ps.getUntrackedParameter<bool>("producedEcalDQMTowerStatus",true);
00344   if ( producedEcalDQMTowerStatus_ ) {
00345     setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalDQMTowerStatus );
00346     findingRecord<EcalDQMTowerStatusRcd>();
00347   }
00348 
00349   // trigger channel status
00350   producedEcalTrgChannelStatus_ = ps.getUntrackedParameter<bool>("producedEcalTrgChannelStatus",true);
00351   trgChannelStatusFile_ = ps.getUntrackedParameter<std::string>("trgChannelStatusFile","");
00352 
00353   if ( producedEcalTrgChannelStatus_ ) {
00354           if ( trgChannelStatusFile_ != "" ) { // if file provided read channel map
00355                   setWhatProduced( this, &EcalTrivialConditionRetriever::getTrgChannelStatusFromConfiguration );
00356           } else { // set all channels to working -- FIXME might be changed
00357                   setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalTrgChannelStatus );
00358           }
00359           findingRecord<EcalTPGCrystalStatusRcd>();
00360   }
00361 
00362   // Alignment
00363   producedEcalAlignmentEB_ = ps.getUntrackedParameter<bool>("producedEcalAlignmentEB",true);
00364   if ( producedEcalAlignmentEB_ ) {
00365     setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalAlignmentEB );
00366     findingRecord<EBAlignmentRcd>();
00367   }
00368   producedEcalAlignmentEE_ = ps.getUntrackedParameter<bool>("producedEcalAlignmentEE",true);
00369   if ( producedEcalAlignmentEE_ ) {
00370     setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalAlignmentEE );
00371     findingRecord<EEAlignmentRcd>();
00372   }
00373   producedEcalAlignmentES_ = ps.getUntrackedParameter<bool>("producedEcalAlignmentES",true);
00374   if ( producedEcalAlignmentES_ ) {
00375     setWhatProduced( this, &EcalTrivialConditionRetriever::produceEcalAlignmentES );
00376     findingRecord<ESAlignmentRcd>();
00377   }
00378   //Tell Finder what records we find
00379   if (producedEcalPedestals_)  findingRecord<EcalPedestalsRcd>();
00380 
00381   if (producedEcalWeights_) {
00382       findingRecord<EcalWeightXtalGroupsRcd>();
00383       findingRecord<EcalTBWeightsRcd>();
00384     }
00385 
00386   if (producedEcalGainRatios_)  findingRecord<EcalGainRatiosRcd>();
00387 
00388   if (producedEcalADCToGeVConstant_)  findingRecord<EcalADCToGeVConstantRcd>();
00389 
00390   producedEcalSampleMask_ = ps.getUntrackedParameter<bool>("producedEcalSampleMask",true);
00391   if (producedEcalSampleMask_) {
00392     setWhatProduced(this, &EcalTrivialConditionRetriever::produceEcalSampleMask );
00393     findingRecord<EcalSampleMaskRcd>();
00394   }
00395 }
00396 
00397 EcalTrivialConditionRetriever::~EcalTrivialConditionRetriever()
00398 {
00399 }
00400 
00401 //
00402 // member functions
00403 //
00404 void
00405 EcalTrivialConditionRetriever::setIntervalFor( const edm::eventsetup::EventSetupRecordKey& rk,
00406                                                const edm::IOVSyncValue& iTime,
00407                                                edm::ValidityInterval& oValidity)
00408 {
00409   if(verbose_>=1) std::cout << "EcalTrivialConditionRetriever::setIntervalFor(): record key = " << rk.name() << "\ttime: " << iTime.time().value() << std::endl;
00410   //For right now, we will just use an infinite interval of validity
00411   oValidity = edm::ValidityInterval( edm::IOVSyncValue::beginOfTime(),edm::IOVSyncValue::endOfTime() );
00412 }
00413 
00414 //produce methods
00415 std::auto_ptr<EcalPedestals>
00416 EcalTrivialConditionRetriever::produceEcalPedestals( const EcalPedestalsRcd& ) {
00417   std::auto_ptr<EcalPedestals>  peds = std::auto_ptr<EcalPedestals>( new EcalPedestals() );
00418   EcalPedestals::Item EBitem;
00419   EcalPedestals::Item EEitem;
00420   
00421   EBitem.mean_x1  = EBpedMeanX1_;
00422   EBitem.rms_x1   = EBpedRMSX1_;
00423   EBitem.mean_x6  = EBpedMeanX6_;
00424   EBitem.rms_x6   = EBpedRMSX6_;
00425   EBitem.mean_x12 = EBpedMeanX12_;
00426   EBitem.rms_x12  = EBpedRMSX12_;
00427 
00428   EEitem.mean_x1  = EEpedMeanX1_;
00429   EEitem.rms_x1   = EEpedRMSX1_;
00430   EEitem.mean_x6  = EEpedMeanX6_;
00431   EEitem.rms_x6   = EEpedRMSX6_;
00432   EEitem.mean_x12 = EEpedMeanX12_;
00433   EEitem.rms_x12  = EEpedRMSX12_;
00434   
00435   for(int iEta=-EBDetId::MAX_IETA; iEta<=EBDetId::MAX_IETA ;++iEta) {
00436     if(iEta==0) continue;
00437     for(int iPhi=EBDetId::MIN_IPHI; iPhi<=EBDetId::MAX_IPHI; ++iPhi) {
00438       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00439       if (EBDetId::validDetId(iEta,iPhi))
00440         {
00441           EBDetId ebdetid(iEta,iPhi);
00442           peds->insert(std::make_pair(ebdetid.rawId(),EBitem));
00443         }
00444     }
00445   }
00446   
00447   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00448     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00449       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00450       if (EEDetId::validDetId(iX,iY,1))
00451         {
00452           EEDetId eedetidpos(iX,iY,1);
00453           peds->insert(std::make_pair(eedetidpos.rawId(),EEitem));
00454         }
00455       if(EEDetId::validDetId(iX,iY,-1))
00456         {
00457           EEDetId eedetidneg(iX,iY,-1);
00458           peds->insert(std::make_pair(eedetidneg.rawId(),EEitem));
00459         }
00460     }
00461   }
00462 
00463   //return std::auto_ptr<EcalPedestals>( peds );
00464   return peds;
00465 }
00466 
00467 std::auto_ptr<EcalWeightXtalGroups>
00468 EcalTrivialConditionRetriever::produceEcalWeightXtalGroups( const EcalWeightXtalGroupsRcd& )
00469 {
00470   std::auto_ptr<EcalWeightXtalGroups> xtalGroups = std::auto_ptr<EcalWeightXtalGroups>( new EcalWeightXtalGroups() );
00471   EcalXtalGroupId defaultGroupId(1);
00472   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
00473     if(ieta==0) continue;
00474     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00475       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00476       if (EBDetId::validDetId(ieta,iphi))
00477         {
00478           EBDetId ebid(ieta,iphi);
00479           //      xtalGroups->setValue(ebid.rawId(), EcalXtalGroupId(ieta) ); // define rings in eta
00480           xtalGroups->setValue(ebid.rawId(), defaultGroupId ); // define rings in eta
00481         }
00482     }
00483   }
00484 
00485   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00486     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00487       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00488       if (EEDetId::validDetId(iX,iY,1))
00489         {
00490           EEDetId eedetidpos(iX,iY,1);
00491           xtalGroups->setValue(eedetidpos.rawId(), defaultGroupId ); 
00492         }
00493       if(EEDetId::validDetId(iX,iY,-1))
00494         {
00495           EEDetId eedetidneg(iX,iY,-1);
00496           xtalGroups->setValue(eedetidneg.rawId(), defaultGroupId ); 
00497         }
00498     }
00499   }
00500   return xtalGroups;
00501 }
00502 
00503 std::auto_ptr<EcalLinearCorrections>
00504 EcalTrivialConditionRetriever::produceEcalLinearCorrections( const EcalLinearCorrectionsRcd& )
00505 {
00506   std::auto_ptr<EcalLinearCorrections>  ical = std::auto_ptr<EcalLinearCorrections>( new EcalLinearCorrections() );
00507 
00508   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
00509     if(ieta==0) continue;
00510     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00511       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00512       if (EBDetId::validDetId(ieta,iphi))
00513         {
00514           EBDetId ebid(ieta,iphi);
00515           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00516           ical->setValue( ebid.rawId(), linCorrMean_ + r*linCorrSigma_ );
00517         }
00518     }
00519   }
00520 
00521   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00522     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00523       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00524       if (EEDetId::validDetId(iX,iY,1))
00525         {
00526           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00527           EEDetId eedetidpos(iX,iY,1);
00528           ical->setValue( eedetidpos.rawId(), linCorrMean_ + r*linCorrSigma_ );
00529         }
00530       if(EEDetId::validDetId(iX,iY,-1))
00531         {
00532           double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
00533           EEDetId eedetidneg(iX,iY,-1);
00534           ical->setValue( eedetidneg.rawId(), linCorrMean_ + r1*linCorrSigma_ );
00535         }
00536     }
00537   }
00538   
00539   return ical;
00540 }
00541 //------------------------------
00542 
00543 std::auto_ptr<EcalIntercalibConstants>
00544 EcalTrivialConditionRetriever::produceEcalIntercalibConstants( const EcalIntercalibConstantsRcd& )
00545 {
00546   std::auto_ptr<EcalIntercalibConstants>  ical = std::auto_ptr<EcalIntercalibConstants>( new EcalIntercalibConstants() );
00547 
00548   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
00549     if(ieta==0) continue;
00550     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00551       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00552       if (EBDetId::validDetId(ieta,iphi))
00553         {
00554           EBDetId ebid(ieta,iphi);
00555           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00556           ical->setValue( ebid.rawId(), intercalibConstantMean_ + r*intercalibConstantSigma_ );
00557         }
00558     }
00559   }
00560 
00561   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00562     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00563       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00564       if (EEDetId::validDetId(iX,iY,1))
00565         {
00566           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00567           EEDetId eedetidpos(iX,iY,1);
00568           ical->setValue( eedetidpos.rawId(), intercalibConstantMean_ + r*intercalibConstantSigma_ );
00569         }
00570       if(EEDetId::validDetId(iX,iY,-1))
00571         {
00572           double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
00573           EEDetId eedetidneg(iX,iY,-1);
00574           ical->setValue( eedetidneg.rawId(), intercalibConstantMean_ + r1*intercalibConstantSigma_ );
00575         }
00576     }
00577   }
00578   
00579   return ical;
00580 }
00581 
00582 std::auto_ptr<EcalIntercalibConstantsMC>
00583 EcalTrivialConditionRetriever::produceEcalIntercalibConstantsMC( const EcalIntercalibConstantsMCRcd& )
00584 {
00585   std::auto_ptr<EcalIntercalibConstantsMC>  ical = std::auto_ptr<EcalIntercalibConstantsMC>( new EcalIntercalibConstantsMC() );
00586 
00587   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
00588     if(ieta==0) continue;
00589     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00590       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00591       if (EBDetId::validDetId(ieta,iphi))
00592         {
00593           EBDetId ebid(ieta,iphi);
00594           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00595           ical->setValue( ebid.rawId(), intercalibConstantMeanMC_ + r*intercalibConstantSigmaMC_ );
00596         }
00597     }
00598   }
00599 
00600   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00601     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00602       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00603       if (EEDetId::validDetId(iX,iY,1))
00604         {
00605           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00606           EEDetId eedetidpos(iX,iY,1);
00607           ical->setValue( eedetidpos.rawId(), intercalibConstantMeanMC_ + r*intercalibConstantSigmaMC_ );
00608         }
00609       if(EEDetId::validDetId(iX,iY,-1))
00610         {
00611           double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
00612           EEDetId eedetidneg(iX,iY,-1);
00613           ical->setValue( eedetidneg.rawId(), intercalibConstantMeanMC_ + r1*intercalibConstantSigmaMC_ );
00614         }
00615     }
00616   }
00617   
00618   return ical;
00619 }
00620 
00621 std::auto_ptr<EcalIntercalibErrors>
00622 EcalTrivialConditionRetriever::produceEcalIntercalibErrors( const EcalIntercalibErrorsRcd& )
00623 {
00624   std::auto_ptr<EcalIntercalibErrors>  ical = std::auto_ptr<EcalIntercalibErrors>( new EcalIntercalibErrors() );
00625 
00626   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
00627     if(ieta==0) continue;
00628     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00629       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00630       if (EBDetId::validDetId(ieta,iphi))
00631         {
00632           EBDetId ebid(ieta,iphi);
00633           ical->setValue( ebid.rawId(), intercalibErrorMean_);
00634         }
00635     }
00636   }
00637 
00638   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00639     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00640       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00641       if (EEDetId::validDetId(iX,iY,1))
00642         {
00643           EEDetId eedetidpos(iX,iY,1);
00644           ical->setValue( eedetidpos.rawId(), intercalibErrorMean_ );
00645         }
00646       if(EEDetId::validDetId(iX,iY,-1))
00647         {
00648           EEDetId eedetidneg(iX,iY,-1);
00649           ical->setValue( eedetidneg.rawId(), intercalibErrorMean_ );
00650         }
00651     }
00652   }
00653   
00654   return ical;
00655 }
00656 
00657 std::auto_ptr<EcalTimeCalibConstants>
00658 EcalTrivialConditionRetriever::produceEcalTimeCalibConstants( const EcalTimeCalibConstantsRcd& )
00659 {
00660   std::auto_ptr<EcalTimeCalibConstants>  ical = std::auto_ptr<EcalTimeCalibConstants>( new EcalTimeCalibConstants() );
00661 
00662   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
00663     if(ieta==0) continue;
00664     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00665       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00666       if (EBDetId::validDetId(ieta,iphi))
00667         {
00668           EBDetId ebid(ieta,iphi);
00669           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00670           ical->setValue( ebid.rawId(), timeCalibConstantMean_ + r*timeCalibConstantSigma_ );
00671         }
00672     }
00673   }
00674 
00675   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00676     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00677       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00678       if (EEDetId::validDetId(iX,iY,1))
00679         {
00680           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00681           EEDetId eedetidpos(iX,iY,1);
00682           ical->setValue( eedetidpos.rawId(), timeCalibConstantMean_ + r*timeCalibConstantSigma_ );
00683         }
00684       if(EEDetId::validDetId(iX,iY,-1))
00685         {
00686           double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
00687           EEDetId eedetidneg(iX,iY,-1);
00688           ical->setValue( eedetidneg.rawId(), timeCalibConstantMean_ + r1*timeCalibConstantSigma_ );
00689         }
00690     }
00691   }
00692   
00693   return ical;
00694 }
00695 
00696 std::auto_ptr<EcalTimeCalibErrors>
00697 EcalTrivialConditionRetriever::produceEcalTimeCalibErrors( const EcalTimeCalibErrorsRcd& )
00698 {
00699   std::auto_ptr<EcalTimeCalibErrors>  ical = std::auto_ptr<EcalTimeCalibErrors>( new EcalTimeCalibErrors() );
00700 
00701   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA ;++ieta) {
00702     if(ieta==0) continue;
00703     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00704       // make an EBDetId since we need EBDetId::rawId() to be used as the key for the pedestals
00705       if (EBDetId::validDetId(ieta,iphi))
00706         {
00707           EBDetId ebid(ieta,iphi);
00708           ical->setValue( ebid.rawId(), timeCalibErrorMean_);
00709         }
00710     }
00711   }
00712 
00713   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00714     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00715       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00716       if (EEDetId::validDetId(iX,iY,1))
00717         {
00718           EEDetId eedetidpos(iX,iY,1);
00719           ical->setValue( eedetidpos.rawId(), timeCalibErrorMean_ );
00720         }
00721       if(EEDetId::validDetId(iX,iY,-1))
00722         {
00723           EEDetId eedetidneg(iX,iY,-1);
00724           ical->setValue( eedetidneg.rawId(), timeCalibErrorMean_ );
00725         }
00726     }
00727   }
00728   
00729   return ical;
00730 }
00731 
00732 std::auto_ptr<EcalTimeOffsetConstant>
00733 EcalTrivialConditionRetriever::produceEcalTimeOffsetConstant( const EcalTimeOffsetConstantRcd& )
00734 {
00735   std::cout << " produceEcalTimeOffsetConstant: " << std::endl;
00736   std::cout << "  EB " << timeOffsetEBConstant_ << " EE " <<  timeOffsetEEConstant_<< std::endl;
00737   return std::auto_ptr<EcalTimeOffsetConstant>( new EcalTimeOffsetConstant(timeOffsetEBConstant_,timeOffsetEEConstant_) );
00738 }
00739 
00740 std::auto_ptr<EcalGainRatios>
00741 EcalTrivialConditionRetriever::produceEcalGainRatios( const EcalGainRatiosRcd& )
00742 {
00743   std::auto_ptr<EcalGainRatios> gratio = std::auto_ptr<EcalGainRatios>( new EcalGainRatios() );
00744   EcalMGPAGainRatio gr;
00745   gr.setGain12Over6( gainRatio12over6_ );
00746   gr.setGain6Over1( gainRatio6over1_ );
00747 
00748   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
00749     if(ieta==0) continue;
00750     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00751       if (EBDetId::validDetId(ieta,iphi))
00752         {
00753           EBDetId ebid(ieta,iphi);
00754           gratio->setValue( ebid.rawId(), gr );
00755         }
00756     }
00757   }
00758   
00759   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
00760     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
00761       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
00762       if (EEDetId::validDetId(iX,iY,1))
00763         {
00764           EEDetId eedetidpos(iX,iY,1);
00765           gratio->setValue( eedetidpos.rawId(), gr );
00766         }
00767       if (EEDetId::validDetId(iX,iY,-1))
00768         {
00769           EEDetId eedetidneg(iX,iY,-1);
00770           gratio->setValue( eedetidneg.rawId(), gr );
00771         }
00772     }
00773   }
00774   
00775   return gratio;
00776 }
00777 
00778 std::auto_ptr<EcalADCToGeVConstant>
00779 EcalTrivialConditionRetriever::produceEcalADCToGeVConstant( const EcalADCToGeVConstantRcd& )
00780 {
00781   return std::auto_ptr<EcalADCToGeVConstant>( new EcalADCToGeVConstant(adcToGeVEBConstant_,adcToGeVEEConstant_) );
00782 }
00783 
00784 std::auto_ptr<EcalTBWeights>
00785 EcalTrivialConditionRetriever::produceEcalTBWeights( const EcalTBWeightsRcd& )
00786 {
00787   // create weights for the test-beam
00788   std::auto_ptr<EcalTBWeights> tbwgt = std::auto_ptr<EcalTBWeights>( new EcalTBWeights() );
00789 
00790   // create weights for each distinct group ID
00791   //  int nMaxTDC = 10;
00792 //   for(int igrp=-EBDetId::MAX_IETA; igrp<=EBDetId::MAX_IETA; ++igrp) {
00793 //     if(igrp==0) continue; 
00794   int igrp=1;
00795   for(int itdc=1; itdc<=nTDCbins_; ++itdc) {
00796     // generate random number
00797     //    double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00798     
00799     // make a new set of weights
00800     EcalWeightSet wgt;
00801     //typedef std::vector< std::vector<EcalWeight> > EcalWeightSet::EcalWeightMatrix;
00802     EcalWeightSet::EcalWeightMatrix& mat1 = wgt.getWeightsBeforeGainSwitch();
00803     EcalWeightSet::EcalWeightMatrix& mat2 = wgt.getWeightsAfterGainSwitch();
00804     
00805 //     if(verbose_>=1) {
00806 //       std::cout << "initial size of mat1: " << mat1.size() << std::endl;
00807 //       std::cout << "initial size of mat2: " << mat2.size() << std::endl;
00808 //     }
00809     
00810     // generate random numbers to use as weights
00825     // use values provided by user
00826     mat1.Place_in_row(amplWeights_[itdc-1],0,0);
00827     mat1.Place_in_row(pedWeights_[itdc-1],1,0);
00828     mat1.Place_in_row(jittWeights_[itdc-1],2,0);
00829     
00830     // wdights after gain switch 
00831     mat2.Place_in_row(amplWeightsAft_[itdc-1],0,0);
00832     mat2.Place_in_row(pedWeightsAft_[itdc-1],1,0);
00833     mat2.Place_in_row(jittWeightsAft_[itdc-1],2,0);
00834     
00835     // fill the chi2 matrcies with random numbers
00836     //    r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00837     EcalWeightSet::EcalChi2WeightMatrix& mat3 = wgt.getChi2WeightsBeforeGainSwitch();
00838     EcalWeightSet::EcalChi2WeightMatrix& mat4 = wgt.getChi2WeightsAfterGainSwitch();
00839     mat3=chi2Matrix_[itdc-1];
00840     mat4=chi2MatrixAft_[itdc-1];
00841     
00842     //     for(size_t i=0; i<10; ++i) 
00843     //       {
00844     //  mat3.push_back(chi2Matrix_[itdc-1][i]);
00845     //  mat4.push_back(chi2MatrixAft_[itdc-1][i]);
00846     //       }
00847     //       std::vector<EcalWeight> tv1, tv2;
00848     //       for(size_t j=0; j<10; ++j) {
00849     //  double ww = igrp*itdc*r + i*10. + j;
00850     //  tv1.push_back( EcalWeight(1000+ww) );
00851     //  tv2.push_back( EcalWeight(1000+100+ww) );
00852     //       }
00853     
00854   
00855     
00856     
00857 //     if(verbose_>=1) {
00858 //       std::cout << "group: " << igrp << " TDC: " << itdc 
00859 //              << " mat1: " << mat1.size() << " mat2: " << mat2.size()
00860 //              << " mat3: " << mat3.size() << " mat4: " << mat4.size()
00861 //              << std::endl;
00862 //     }
00863     
00864     // put the weight in the container
00865     tbwgt->setValue(std::make_pair(igrp,itdc), wgt);
00866   } 
00867   //   }
00868   return tbwgt;
00869 }
00870 
00871 
00872 // cluster functions/corrections
00873 std::auto_ptr<EcalClusterLocalContCorrParameters>
00874 EcalTrivialConditionRetriever::produceEcalClusterLocalContCorrParameters( const EcalClusterLocalContCorrParametersRcd &)
00875 {
00876         std::auto_ptr<EcalClusterLocalContCorrParameters> ipar = std::auto_ptr<EcalClusterLocalContCorrParameters>( new EcalClusterLocalContCorrParameters() );
00877         for (size_t i = 0; i < localContCorrParameters_.size(); ++i ) {
00878                 ipar->params().push_back( localContCorrParameters_[i] );
00879         }
00880         return ipar;
00881 }
00882 std::auto_ptr<EcalClusterCrackCorrParameters>
00883 EcalTrivialConditionRetriever::produceEcalClusterCrackCorrParameters( const EcalClusterCrackCorrParametersRcd &)
00884 {
00885         std::auto_ptr<EcalClusterCrackCorrParameters> ipar = std::auto_ptr<EcalClusterCrackCorrParameters>( new EcalClusterCrackCorrParameters() );
00886         for (size_t i = 0; i < crackCorrParameters_.size(); ++i ) {
00887                 ipar->params().push_back( crackCorrParameters_[i] );
00888         }
00889         return ipar;
00890 }
00891 std::auto_ptr<EcalClusterEnergyCorrectionParameters>
00892 EcalTrivialConditionRetriever::produceEcalClusterEnergyCorrectionParameters( const EcalClusterEnergyCorrectionParametersRcd &)
00893 {
00894         std::auto_ptr<EcalClusterEnergyCorrectionParameters> ipar = std::auto_ptr<EcalClusterEnergyCorrectionParameters>( new EcalClusterEnergyCorrectionParameters() );
00895         for (size_t i = 0; i < energyCorrectionParameters_.size(); ++i ) {
00896                 ipar->params().push_back( energyCorrectionParameters_[i] );
00897         }
00898         return ipar;
00899 }
00900 std::auto_ptr<EcalClusterEnergyUncertaintyParameters>
00901 EcalTrivialConditionRetriever::produceEcalClusterEnergyUncertaintyParameters( const EcalClusterEnergyUncertaintyParametersRcd &)
00902 {
00903         std::auto_ptr<EcalClusterEnergyUncertaintyParameters> ipar = std::auto_ptr<EcalClusterEnergyUncertaintyParameters>( new EcalClusterEnergyUncertaintyParameters() );
00904         for (size_t i = 0; i < energyUncertaintyParameters_.size(); ++i ) {
00905                 ipar->params().push_back( energyUncertaintyParameters_[i] );
00906         }
00907         return ipar;
00908 }
00909 std::auto_ptr<EcalClusterEnergyCorrectionObjectSpecificParameters>
00910 EcalTrivialConditionRetriever::produceEcalClusterEnergyCorrectionObjectSpecificParameters( const EcalClusterEnergyCorrectionObjectSpecificParametersRcd &)
00911 {
00912   std::auto_ptr<EcalClusterEnergyCorrectionObjectSpecificParameters> ipar = std::auto_ptr<EcalClusterEnergyCorrectionObjectSpecificParameters>( new EcalClusterEnergyCorrectionObjectSpecificParameters() );
00913   for (size_t i = 0; i < energyCorrectionObjectSpecificParameters_.size(); ++i ) {
00914     ipar->params().push_back( energyCorrectionObjectSpecificParameters_[i] );
00915   }
00916   return ipar;
00917 }
00918 
00919 
00920 // laser records
00921 std::auto_ptr<EcalLaserAlphas>
00922 EcalTrivialConditionRetriever::produceEcalLaserAlphas( const EcalLaserAlphasRcd& )
00923 {
00924 
00925   std::cout << " produceEcalLaserAlphas " << std::endl;
00926   std::auto_ptr<EcalLaserAlphas> ical = std::auto_ptr<EcalLaserAlphas>( new EcalLaserAlphas() );
00927   if(getLaserAlphaFromFile_) {
00928     std::ifstream fEB(edm::FileInPath(EBLaserAlphaFile_).fullPath().c_str());
00929     int SMpos[36] = {-10, 4, -7, -16, 6, -9, 11, -17, 5, 18, 3, -8, 1, -3, -13, 14, -6, 2,
00930                      15, -18, 8, 17, -2, 9, -1, 10, -5, 7, -12, -11, 16, -4, -15, -14, 12, 13};
00931     // check!
00932     int SMCal[36] = {12,17,10, 1, 8, 4,27,20,23,25, 6,34,35,15,18,30,21, 9,
00933                      24,22,13,31,26,16, 2,11, 5, 0,29,28,14,33,32, 3, 7,19};
00934     /*
00935   int slot_to_constr[37]={-1,12,17,10,1,8,4,27,20,23,25,6,34,35,15,18,30,21,9
00936                           ,24,22,13,31,26,16,2,11,5,0,29,28,14,33,32,3,7,19};
00937   int constr_to_slot[36]={28,4,25,34,6,27,11,35,5,18,3,26,1,21,31,14,24,2,15,
00938                           36,8,17,20,9,19,10,23,7,30,29,16,22,33,32,12,13  };
00939     */
00940     for(int SMcons = 0; SMcons < 36; SMcons++) {
00941       int SM = SMpos[SMcons];
00942       if(SM < 0) SM = 17 + abs(SM);
00943       else SM--;
00944       if(SMCal[SM] != SMcons)
00945          std::cout << " SM pb : read SM " <<  SMcons<< " SMpos " << SM
00946                    << " SMCal " << SMCal[SM] << std::endl;
00947     }
00948     // check
00949     std::string type, batch;
00950     int readSM, pos, bar, bar2;
00951     float alpha = 0;
00952     for(int SMcons = 0; SMcons < 36; SMcons++) {
00953       int SM = SMpos[SMcons];
00954       for(int ic = 0; ic < 1700; ic++) {
00955         fEB >> readSM >> pos >> bar >>  bar2 >> type >> batch;
00956         //      if(ic == 0) std::cout << readSM << " " << pos << " " << bar << " " << bar2 << " " 
00957         //                            << type << " " << batch << std::endl;
00958         if(readSM != SMcons || pos != ic + 1) 
00959           std::cout << " barrel read pb read SM " << readSM << " const SM " << SMcons
00960                     << " read pos " << pos << " ic " << ic << std::endl;
00961         if(SM < 0) SM = 18 + abs(SM);
00962         EBDetId ebdetid(SM, pos, EBDetId::SMCRYSTALMODE);
00963         if(bar == 33101 || bar == 30301 )
00964           alpha = 1.52;
00965         else if(bar == 33106) {
00966           if(bar2 <= 2000)
00967             alpha = 1.0;
00968           else {
00969             std::cout << " problem with barcode first " << bar << " last " << bar2 
00970                       << " read SM " << readSM << " read pos " << pos << std::endl;
00971             alpha = 0.0;
00972           }
00973         }
00974         ical->setValue( ebdetid, alpha );
00975       }
00976     }  // loop over SMcons
00977   }   // laserAlpha from a file
00978   else {
00979     for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
00980       if(ieta==0) continue;
00981       for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
00982         if (EBDetId::validDetId(ieta,iphi)) {
00983           EBDetId ebid(ieta,iphi);
00984           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
00985           ical->setValue( ebid, laserAlphaMean_ + r*laserAlphaSigma_ );
00986         }
00987       }  // loop over iphi
00988     }  // loop over ieta
00989   }   // do not read a file
00990 
00991   std::cout << " produceEcalLaserAlphas EE" << std::endl;
00992   if(getLaserAlphaFromFile_) {
00993     std::ifstream fEE(edm::FileInPath(EELaserAlphaFile_).fullPath().c_str());
00994     int check[101][101];
00995     for(int x = 1; x < 101; x++)
00996       for(int y = 1; y < 101; y++)
00997         check[x][y] = -1;
00998     for(int crystal = 0; crystal < 14648; crystal++) {
00999       int x, y ,z, bid, bar, bar2;
01000       float LY, alpha = 0;
01001       fEE >> z >> x >> y >> LY >> bid >> bar >> bar2;
01002       if(x < 1 || x > 100 || y < 1 || y > 100)
01003         std::cout << " wrong coordinates for barcode " << bar 
01004                   << " x " << x << " y " << y << " z " << z << std::endl;
01005       else {
01006         if(z == 1) check[x][y] = 1;
01007         else check[x][y] = 0;
01008         if(bar == 33201 || (bar == 30399 && bar2 < 568))
01009           alpha = 1.52;
01010         else if((bar == 33106 && bar2 > 2000 && bar2 < 4669) 
01011                 || (bar == 30399 && bar2 > 567))
01012           alpha = 1.0;
01013         else {
01014           std::cout << " problem with barcode " << bar << " " << bar2 
01015                     << " x " << x << " y " << y << " z " << z << std::endl;
01016           alpha = 0.0;
01017         }
01018       } 
01019       if (EEDetId::validDetId(x, y, z)) {
01020         EEDetId eedetidpos(x, y, z);
01021         ical->setValue( eedetidpos, alpha );
01022       }
01023       else // should not occur
01024         std::cout << " problem with EEDetId " << " x " << x << " y " << y << " z " << z << std::endl;
01025     }  // loop over crystal in file
01026     for(int x = 1; x < 101; x++)
01027       for(int y = 1; y < 101; y++)
01028         if(check[x][y] == 1) std::cout << " missing x " << x << " y " << y << std::endl;
01029   }  // laserAlpha from a file
01030   else {
01031     for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
01032       for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
01033         // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
01034         if (EEDetId::validDetId(iX,iY,1)) {
01035           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
01036           EEDetId eedetidpos(iX,iY,1);
01037           ical->setValue( eedetidpos, laserAlphaMean_ + r*laserAlphaSigma_ );
01038         }
01039 
01040         if (EEDetId::validDetId(iX,iY,-1)) {
01041           double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
01042           EEDetId eedetidneg(iX,iY,-1);
01043           ical->setValue( eedetidneg, laserAlphaMean_ + r1*laserAlphaSigma_ );
01044         }
01045       } // loop over iY
01046     } // loop over iX
01047   }  // do not read a file
01048   
01049   return ical;
01050 }
01051 
01052 
01053 std::auto_ptr<EcalLaserAPDPNRatiosRef>
01054 EcalTrivialConditionRetriever::produceEcalLaserAPDPNRatiosRef( const EcalLaserAPDPNRatiosRefRcd& )
01055 {
01056   std::auto_ptr<EcalLaserAPDPNRatiosRef>  ical = std::auto_ptr<EcalLaserAPDPNRatiosRef>( new EcalLaserAPDPNRatiosRef() );
01057   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
01058     if(ieta==0) continue;
01059     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
01060       if (EBDetId::validDetId(ieta,iphi)) {
01061           EBDetId ebid(ieta,iphi);
01062           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
01063           ical->setValue( ebid, laserAPDPNRefMean_ + r*laserAPDPNRefSigma_ );
01064       }
01065     }
01066   }
01067 
01068    for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
01069      for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
01070        // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
01071        if (EEDetId::validDetId(iX,iY,1)) {
01072           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
01073           EEDetId eedetidpos(iX,iY,1);
01074           ical->setValue( eedetidpos, laserAPDPNRefMean_ + r*laserAPDPNRefSigma_ );
01075        }
01076 
01077        if (EEDetId::validDetId(iX,iY,-1)) {
01078           double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
01079           EEDetId eedetidneg(iX,iY,-1);
01080           ical->setValue( eedetidneg, laserAPDPNRefMean_ + r1*laserAPDPNRefSigma_ );
01081        }
01082      }
01083    }
01084   
01085   return ical;
01086 }
01087 
01088 
01089 std::auto_ptr<EcalLaserAPDPNRatios>
01090 EcalTrivialConditionRetriever::produceEcalLaserAPDPNRatios( const EcalLaserAPDPNRatiosRcd& )
01091 {
01092 
01093   std::auto_ptr<EcalLaserAPDPNRatios>  ical = std::auto_ptr<EcalLaserAPDPNRatios>( new EcalLaserAPDPNRatios() );
01094   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
01095     if(ieta==0) continue;
01096     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
01097       if (EBDetId::validDetId(ieta,iphi)) {
01098           EBDetId ebid(ieta,iphi);
01099           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
01100 
01101           EcalLaserAPDPNRatios::EcalLaserAPDPNpair pairAPDPN;
01102           pairAPDPN.p1 = laserAPDPNMean_ + r*laserAPDPNSigma_;
01103           pairAPDPN.p2 = laserAPDPNMean_ + r*laserAPDPNSigma_;
01104           pairAPDPN.p3 = laserAPDPNMean_ + r*laserAPDPNSigma_;
01105           ical->setValue( ebid, pairAPDPN );
01106       }
01107      }
01108   }
01109 
01110    for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
01111      for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
01112        // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
01113        if (EEDetId::validDetId(iX,iY,1)) {
01114           double r = (double)std::rand()/( double(RAND_MAX)+double(1) );
01115           EEDetId eedetidpos(iX,iY,1);
01116 
01117           EcalLaserAPDPNRatios::EcalLaserAPDPNpair pairAPDPN;
01118           pairAPDPN.p1 = laserAPDPNMean_ + r*laserAPDPNSigma_;
01119           pairAPDPN.p2 = laserAPDPNMean_ + r*laserAPDPNSigma_;
01120           pairAPDPN.p3 = laserAPDPNMean_ + r*laserAPDPNSigma_;
01121           ical->setValue( eedetidpos, pairAPDPN );
01122        }
01123 
01124        if (EEDetId::validDetId(iX,iY,-1)) {
01125           double r1 = (double)std::rand()/( double(RAND_MAX)+double(1) );
01126           EEDetId eedetidneg(iX,iY,-1);
01127 
01128           EcalLaserAPDPNRatios::EcalLaserAPDPNpair pairAPDPN;
01129           pairAPDPN.p1 = laserAPDPNMean_ + r1*laserAPDPNSigma_;
01130           pairAPDPN.p2 = laserAPDPNMean_ + r1*laserAPDPNSigma_;
01131           pairAPDPN.p3 = laserAPDPNMean_ + r1*laserAPDPNSigma_;
01132           ical->setValue( eedetidneg, pairAPDPN );
01133        }
01134      }
01135    }
01136 
01137   EcalLaserAPDPNRatios::EcalLaserTimeStamp TimeStamp;
01138   //  for(int i=1; i<=92; i++){
01139   for(int i=0; i<92; i++){
01140     TimeStamp.t1 = Timestamp(laserAPDPNTime1_);
01141     if(laserAPDPNTime2_ == 0 ){ 
01142       TimeStamp.t2 = Timestamp(edm::Timestamp::endOfTime().value());
01143     } else {
01144       TimeStamp.t2 = Timestamp(laserAPDPNTime2_);
01145     }
01146     if(laserAPDPNTime3_ == 0 ){ 
01147       TimeStamp.t3 = Timestamp(edm::Timestamp::endOfTime().value());
01148     } else {
01149       TimeStamp.t3 = Timestamp(laserAPDPNTime3_);
01150     }
01151 
01152     ical->setTime( i, TimeStamp );
01153   }
01154   
01155   return ical;
01156 
01157 }
01158 
01159   
01160 void EcalTrivialConditionRetriever::getWeightsFromConfiguration(const edm::ParameterSet& ps)
01161 {
01162 
01163   std::vector < std::vector<double> > amplwgtv(nTDCbins_);
01164 
01165   if (!getWeightsFromFile_ && nTDCbins_ == 1)
01166     {
01167       std::vector<double> vampl;
01168       //As default using simple 3+1 weights
01169       vampl.push_back( -0.33333 );
01170       vampl.push_back( -0.33333 );
01171       vampl.push_back( -0.33333 );
01172       vampl.push_back(  0. );
01173       vampl.push_back(  0. );
01174       vampl.push_back(  1. );
01175       vampl.push_back(  0. );
01176       vampl.push_back(  0. );
01177       vampl.push_back(  0. );
01178       vampl.push_back(  0. );
01179       amplwgtv[0]= ps.getUntrackedParameter< std::vector<double> >("amplWeights", vampl);
01180     }
01181   else if (getWeightsFromFile_)
01182     {
01183       edm::LogInfo("EcalTrivialConditionRetriever") << "Reading amplitude weights from file " << edm::FileInPath(amplWeightsFile_).fullPath().c_str() ;
01184       std::ifstream amplFile(edm::FileInPath(amplWeightsFile_).fullPath().c_str());
01185       int tdcBin=0;
01186       while (!amplFile.eof() && tdcBin < nTDCbins_) 
01187         {
01188           for(int j = 0; j < 10; ++j) {
01189             float ww;
01190             amplFile >> ww;
01191             amplwgtv[tdcBin].push_back(ww);
01192           }
01193           ++tdcBin;
01194         }
01195       assert (tdcBin == nTDCbins_);
01196       //Read from file
01197     }
01198   else
01199     {
01200       //Not supported
01201       edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
01202       throw cms::Exception("WrongConfig");
01203     }
01204 
01205   
01206   for (int i=0;i<nTDCbins_;i++)
01207     {
01208       assert(amplwgtv[i].size() == 10);
01209       int j=0;
01210       for(std::vector<double>::const_iterator it = amplwgtv[i].begin(); it != amplwgtv[i].end(); ++it) 
01211         {
01212           (amplWeights_[i])[j]=*it;
01213           j++;
01214         }
01215     }
01216   
01217 
01218   std::vector < std::vector<double> > amplwgtvAftGain(nTDCbins_);
01219 
01220   if (!getWeightsFromFile_ && nTDCbins_ == 1 )
01221     {
01222       std::vector<double> vamplAftGain;
01223       vamplAftGain.push_back(  0. );
01224       vamplAftGain.push_back(  0. );
01225       vamplAftGain.push_back(  0. );
01226       vamplAftGain.push_back(  0. );
01227       vamplAftGain.push_back(  0. );
01228       vamplAftGain.push_back(  1. );
01229       vamplAftGain.push_back(  0. );
01230       vamplAftGain.push_back(  0. );
01231       vamplAftGain.push_back(  0. );
01232       vamplAftGain.push_back(  0. );
01233       amplwgtvAftGain[0] = ps.getUntrackedParameter< std::vector<double> >("amplWeightsAftGain", vamplAftGain);
01234     }
01235   else if (getWeightsFromFile_)
01236     {
01237       //Read from file
01238       edm::LogInfo("EcalTrivialConditionRetriever") << "Reading amplitude weights aftre gain switch from file " << edm::FileInPath(amplWeightsAftFile_).fullPath().c_str() ;
01239       std::ifstream amplFile(edm::FileInPath(amplWeightsAftFile_).fullPath().c_str());
01240       int tdcBin=0;
01241       while (!amplFile.eof() && tdcBin < nTDCbins_) 
01242         {
01243           for(int j = 0; j < 10; ++j) {
01244             float ww;
01245             amplFile >> ww;
01246             amplwgtvAftGain[tdcBin].push_back(ww);
01247           }
01248           ++tdcBin;
01249         }
01250       assert (tdcBin == nTDCbins_);
01251     }
01252   else
01253     {
01254       //Not supported
01255       edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
01256       throw cms::Exception("WrongConfig");
01257     }
01258 
01259   for (int i=0;i<nTDCbins_;i++)
01260     {
01261       assert(amplwgtvAftGain[i].size() == 10);
01262       int j=0;
01263       for(std::vector<double>::const_iterator it = amplwgtvAftGain[i].begin(); it != amplwgtvAftGain[i].end(); ++it) {
01264         (amplWeightsAft_[i])[j]=*it;
01265         j++;
01266       }
01267     }
01268       
01269   // default weights to reco amplitude w/o pedestal subtraction
01270 
01271   std::vector< std::vector<double> > pedwgtv(nTDCbins_);
01272 
01273   if (!getWeightsFromFile_ && nTDCbins_ == 1)
01274     {
01275       std::vector<double> vped;
01276       vped.push_back( 0.33333 );
01277       vped.push_back( 0.33333 );
01278       vped.push_back( 0.33333 );
01279       vped.push_back( 0. );
01280       vped.push_back( 0. );
01281       vped.push_back( 0. );
01282       vped.push_back( 0. );
01283       vped.push_back( 0. );
01284       vped.push_back( 0. );
01285       vped.push_back( 0. );
01286       pedwgtv[0] = ps.getUntrackedParameter< std::vector<double> >("pedWeights", vped);
01287     }
01288   else if (getWeightsFromFile_)
01289     {
01290       //Read from file
01291       edm::LogInfo("EcalTrivialConditionRetriever") << "Reading pedestal weights from file " << edm::FileInPath(pedWeightsFile_).fullPath().c_str() ;
01292       std::ifstream pedFile(edm::FileInPath(pedWeightsFile_).fullPath().c_str());
01293       int tdcBin=0;
01294       while (!pedFile.eof() && tdcBin < nTDCbins_) 
01295         {
01296           for(int j = 0; j < 10; ++j) {
01297             float ww;
01298             pedFile >> ww;
01299             pedwgtv[tdcBin].push_back(ww);
01300           }
01301           ++tdcBin;
01302         }
01303       assert (tdcBin == nTDCbins_);
01304     }
01305   else
01306     {
01307       //Not supported
01308       edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
01309       throw cms::Exception("WrongConfig");
01310     }
01311 
01312   for (int i=0;i<nTDCbins_;i++)
01313     {
01314       assert(pedwgtv[i].size() == 10);
01315       int j=0;
01316       for(std::vector<double>::const_iterator it = pedwgtv[i].begin(); it != pedwgtv[i].end(); ++it) {
01317         (pedWeights_[i])[j] = *it;
01318         j++;
01319       }
01320     }
01321   
01322   std::vector< std::vector<double> > pedwgtvaft(nTDCbins_);
01323 
01324   if (!getWeightsFromFile_ && nTDCbins_ == 1)
01325     {
01326       std::vector<double> vped;
01327       vped.push_back( 0. );
01328       vped.push_back( 0. );
01329       vped.push_back( 0. );
01330       vped.push_back( 0. );
01331       vped.push_back( 0. );
01332       vped.push_back( 0. );
01333       vped.push_back( 0. );
01334       vped.push_back( 0. );
01335       vped.push_back( 0. );
01336       vped.push_back( 0. );
01337       pedwgtvaft[0] = ps.getUntrackedParameter< std::vector<double> >("pedWeightsAft", vped);
01338     }
01339   else if (getWeightsFromFile_)
01340     {
01341       //Read from file
01342       edm::LogInfo("EcalTrivialConditionRetriever") << "Reading pedestal after gain switch weights from file " << edm::FileInPath(pedWeightsAftFile_).fullPath().c_str() ;
01343       std::ifstream pedFile(edm::FileInPath(pedWeightsAftFile_).fullPath().c_str());
01344       int tdcBin=0;
01345       while (!pedFile.eof() && tdcBin < nTDCbins_) 
01346         {
01347           for(int j = 0; j < 10; ++j) {
01348             float ww;
01349             pedFile >> ww;
01350             pedwgtvaft[tdcBin].push_back(ww);
01351           }
01352           ++tdcBin;
01353         }
01354       assert (tdcBin == nTDCbins_);
01355     }
01356   else
01357     {
01358       //Not supported
01359       edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
01360       throw cms::Exception("WrongConfig");
01361     }
01362   
01363   for (int i=0;i<nTDCbins_;i++)
01364     {
01365       assert(pedwgtvaft[i].size() == 10);
01366       int j=0;
01367       for(std::vector<double>::const_iterator it = pedwgtvaft[i].begin(); it != pedwgtvaft[i].end(); ++it) {
01368         (pedWeightsAft_[i])[j]=*it;
01369         j++;
01370       }
01371     }
01372   
01373   
01374   
01375   // default weights to reco jitter
01376 
01377   std::vector< std::vector<double> > jittwgtv(nTDCbins_);
01378 
01379   if (!getWeightsFromFile_  && nTDCbins_ == 1 )
01380     {
01381       std::vector<double> vjitt;
01382       vjitt.push_back( 0.04066309 );
01383       vjitt.push_back( 0.04066309 );
01384       vjitt.push_back( 0.04066309 );
01385       vjitt.push_back( 0.000 );
01386       vjitt.push_back( 1.325176 );
01387       vjitt.push_back( -0.04997078 );
01388       vjitt.push_back( -0.504338 );
01389       vjitt.push_back( -0.5024844 );
01390       vjitt.push_back( -0.3903718 );
01391       vjitt.push_back( 0.000 );
01392       jittwgtv[0] = ps.getUntrackedParameter< std::vector<double> >("jittWeights", vjitt);
01393     }
01394   else if (getWeightsFromFile_)
01395     {
01396       //Read from file
01397       edm::LogInfo("EcalTrivialConditionRetriever") << "Reading jitter weights from file " << edm::FileInPath(jittWeightsFile_).fullPath().c_str() ;
01398       std::ifstream jittFile(edm::FileInPath(jittWeightsFile_).fullPath().c_str());
01399       int tdcBin=0;
01400       while (!jittFile.eof() && tdcBin < nTDCbins_) 
01401         {
01402           for(int j = 0; j < 10; ++j) {
01403             float ww;
01404             jittFile >> ww;
01405             jittwgtv[tdcBin].push_back(ww);
01406           }
01407           ++tdcBin;
01408         }
01409       assert (tdcBin == nTDCbins_);
01410     }
01411   else
01412     {
01413       //Not supported
01414       edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
01415       throw cms::Exception("WrongConfig");
01416     }
01417   
01418   for (int i=0;i<nTDCbins_;i++)
01419     {
01420       assert(jittwgtv[i].size() == 10);
01421       int j=0;
01422       for(std::vector<double>::const_iterator it = jittwgtv[i].begin(); it != jittwgtv[i].end(); ++it) {
01423         (jittWeights_[i])[j]= *it;
01424         j++;
01425       }
01426     }
01427   
01428   std::vector< std::vector<double> > jittwgtvaft(nTDCbins_);
01429 
01430   if (!getWeightsFromFile_ && nTDCbins_ == 1)
01431     {
01432       std::vector<double> vjitt;
01433       vjitt.push_back( 0. );
01434       vjitt.push_back( 0. );
01435       vjitt.push_back( 0. );
01436       vjitt.push_back( 0. );
01437       vjitt.push_back( 1.097871 );
01438       vjitt.push_back( -0.04551035 );
01439       vjitt.push_back( -0.4159156 );
01440       vjitt.push_back( -0.4185352 );
01441       vjitt.push_back( -0.3367127 );
01442       vjitt.push_back( 0. );
01443       jittwgtvaft[0] = ps.getUntrackedParameter< std::vector<double> >("jittWeightsAft", vjitt);
01444     }
01445   else if (getWeightsFromFile_)
01446     {
01447       //Read from file
01448       edm::LogInfo("EcalTrivialConditionRetriever") << "Reading jitter after gain switch weights from file " << edm::FileInPath(jittWeightsAftFile_).fullPath().c_str() ;
01449       std::ifstream jittFile(edm::FileInPath(jittWeightsAftFile_).fullPath().c_str());
01450       int tdcBin=0;
01451       while (!jittFile.eof() && tdcBin < nTDCbins_) 
01452         {
01453           for(int j = 0; j < 10; ++j) {
01454             float ww;
01455             jittFile >> ww;
01456             jittwgtvaft[tdcBin].push_back(ww);
01457           }
01458           ++tdcBin;
01459         }
01460       assert (tdcBin == nTDCbins_);
01461     }
01462   else
01463     {
01464       //Not supported
01465       edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
01466       throw cms::Exception("WrongConfig");
01467     }
01468   
01469   for (int i=0;i<nTDCbins_;i++)
01470     {
01471       assert(jittwgtvaft[i].size() == 10);
01472       int j=0;
01473       for(std::vector<double>::const_iterator it = jittwgtvaft[i].begin(); it != jittwgtvaft[i].end(); ++it) {
01474         (jittWeightsAft_[i])[j]= *it;
01475         j++;
01476       }
01477     }
01478 
01479    
01480    std::vector<  EcalWeightSet::EcalChi2WeightMatrix > chi2Matrix(nTDCbins_);
01481    if (!getWeightsFromFile_  && nTDCbins_ == 1 )
01482      {
01483        //        chi2Matrix[0].resize(10);
01484        //        for (int i=0;i<10;i++)
01485          //      chi2Matrix[0][i].resize(10);
01486 
01487        chi2Matrix[0](0,0) = 0.694371;
01488        chi2Matrix[0](0,1) = -0.305629;  
01489        chi2Matrix[0](0,2) = -0.305629;
01490        chi2Matrix[0](0,3) = 0.;
01491        chi2Matrix[0](0,4) = 0.;
01492        chi2Matrix[0](0,5) = 0.;
01493        chi2Matrix[0](0,6) = 0.;
01494        chi2Matrix[0](0,7) = 0.;
01495        chi2Matrix[0](0,8) = 0.;
01496        chi2Matrix[0](0,9) = 0.;
01497        chi2Matrix[0](1,0) = -0.305629;
01498        chi2Matrix[0](1,1) = 0.694371;
01499        chi2Matrix[0](1,2) = -0.305629;
01500        chi2Matrix[0](1,3) = 0.;
01501        chi2Matrix[0](1,4) = 0.;
01502        chi2Matrix[0](1,5) = 0.;
01503        chi2Matrix[0](1,6) = 0.;
01504        chi2Matrix[0](1,7) = 0.;
01505        chi2Matrix[0](1,8) = 0.;
01506        chi2Matrix[0](1,9) = 0.;
01507        chi2Matrix[0](2,0) = -0.305629;
01508        chi2Matrix[0](2,1) = -0.305629;
01509        chi2Matrix[0](2,2) = 0.694371;
01510        chi2Matrix[0](2,3) = 0.;
01511        chi2Matrix[0](2,4) = 0.;
01512        chi2Matrix[0](2,5) = 0.;
01513        chi2Matrix[0](2,6) = 0.;
01514        chi2Matrix[0](2,7) = 0.;
01515        chi2Matrix[0](2,8) = 0.;
01516        chi2Matrix[0](2,9) = 0.;
01517        chi2Matrix[0](3,0) = 0.;
01518        chi2Matrix[0](3,1) = 0.;
01519        chi2Matrix[0](3,2) = 0.;
01520        chi2Matrix[0](3,3) = 0.;
01521        chi2Matrix[0](3,4) = 0.;
01522        chi2Matrix[0](3,5) = 0.;
01523        chi2Matrix[0](3,6) = 0.;
01524        chi2Matrix[0](3,7) = 0.;
01525        chi2Matrix[0](3,8) = 0.;
01526        chi2Matrix[0](3,9) = 0.; 
01527        chi2Matrix[0](4,0) = 0.;
01528        chi2Matrix[0](4,1) = 0.;
01529        chi2Matrix[0](4,2) = 0.;
01530        chi2Matrix[0](4,3) = 0.;
01531        chi2Matrix[0](4,4) = 0.8027116;
01532        chi2Matrix[0](4,5) = -0.2517103;
01533        chi2Matrix[0](4,6) = -0.2232882;
01534        chi2Matrix[0](4,7) = -0.1716192;
01535        chi2Matrix[0](4,8) = -0.1239006;
01536        chi2Matrix[0](4,9) = 0.; 
01537        chi2Matrix[0](5,0) = 0.;
01538        chi2Matrix[0](5,1) = 0.;
01539        chi2Matrix[0](5,2) = 0.;
01540        chi2Matrix[0](5,3) = 0.;
01541        chi2Matrix[0](5,4) = -0.2517103;
01542        chi2Matrix[0](5,5) = 0.6528964;
01543        chi2Matrix[0](5,6) = -0.2972839;
01544        chi2Matrix[0](5,7) = -0.2067162;
01545        chi2Matrix[0](5,8) = -0.1230729;
01546        chi2Matrix[0](5,9) = 0.;
01547        chi2Matrix[0](6,0) = 0.;
01548        chi2Matrix[0](6,1) = 0.;
01549        chi2Matrix[0](6,2) = 0.;
01550        chi2Matrix[0](6,3) = 0.;
01551        chi2Matrix[0](6,4) = -0.2232882;
01552        chi2Matrix[0](6,5) = -0.2972839;
01553        chi2Matrix[0](6,6) = 0.7413607;
01554        chi2Matrix[0](6,7) = -0.1883866;
01555        chi2Matrix[0](6,8) = -0.1235052;
01556        chi2Matrix[0](6,9) = 0.; 
01557        chi2Matrix[0](7,0) = 0.;
01558        chi2Matrix[0](7,1) = 0.;
01559        chi2Matrix[0](7,2) = 0.;
01560        chi2Matrix[0](7,3) = 0.;
01561        chi2Matrix[0](7,4) = -0.1716192;
01562        chi2Matrix[0](7,5) = -0.2067162;
01563        chi2Matrix[0](7,6) = -0.1883866;
01564        chi2Matrix[0](7,7) = 0.844935;
01565        chi2Matrix[0](7,8) = -0.124291;
01566        chi2Matrix[0](7,9) = 0.; 
01567        chi2Matrix[0](8,0) = 0.;
01568        chi2Matrix[0](8,1) = 0.;
01569        chi2Matrix[0](8,2) = 0.;
01570        chi2Matrix[0](8,3) = 0.;
01571        chi2Matrix[0](8,4) = -0.1239006;
01572        chi2Matrix[0](8,5) = -0.1230729;
01573        chi2Matrix[0](8,6) = -0.1235052;
01574        chi2Matrix[0](8,7) = -0.124291;
01575        chi2Matrix[0](8,8) = 0.8749833;
01576        chi2Matrix[0](8,9) = 0.;
01577        chi2Matrix[0](9,0) = 0.;
01578        chi2Matrix[0](9,1) = 0.;
01579        chi2Matrix[0](9,2) = 0.;
01580        chi2Matrix[0](9,3) = 0.;
01581        chi2Matrix[0](9,4) = 0.;
01582        chi2Matrix[0](9,5) = 0.;
01583        chi2Matrix[0](9,6) = 0.;
01584        chi2Matrix[0](9,7) = 0.;
01585        chi2Matrix[0](9,8) = 0.;
01586        chi2Matrix[0](9,9) = 0.; 
01587      }
01588    else if (getWeightsFromFile_)
01589     {
01590       //Read from file
01591       edm::LogInfo("EcalTrivialConditionRetriever") << "Reading chi2Matrix from file " << edm::FileInPath(chi2MatrixFile_).fullPath().c_str() ;
01592       std::ifstream chi2MatrixFile(edm::FileInPath(chi2MatrixFile_).fullPath().c_str());
01593       int tdcBin=0;
01594       while (!chi2MatrixFile.eof() && tdcBin < nTDCbins_) 
01595         {
01596           //      chi2Matrix[tdcBin].resize(10);
01597           for(int j = 0; j < 10; ++j) {
01598             for(int l = 0; l < 10; ++l) {
01599               float ww;
01600               chi2MatrixFile >> ww;
01601               chi2Matrix[tdcBin](j,l)=ww;
01602             }
01603           }
01604           ++tdcBin;
01605         }
01606       assert (tdcBin == nTDCbins_);
01607     }
01608   else
01609     {
01610       //Not supported
01611       edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
01612       throw cms::Exception("WrongConfig");
01613     }
01614    
01615 //    for (int i=0;i<nTDCbins_;i++)
01616 //      {
01617        //       assert(chi2Matrix[i].size() == 10);
01618    chi2Matrix_ =  chi2Matrix;
01619 //      }
01620 
01621    std::vector< EcalWeightSet::EcalChi2WeightMatrix > chi2MatrixAft(nTDCbins_);
01622    if (!getWeightsFromFile_  && nTDCbins_ == 1 )
01623      {
01624        //       chi2MatrixAft[0].resize(10);
01625        //       for (int i=0;i<10;i++)
01626          //      chi2MatrixAft[0][i].resize(10);
01627 
01628        chi2MatrixAft[0](0,0) = 0.;
01629        chi2MatrixAft[0](0,1) = 0.;  
01630        chi2MatrixAft[0](0,2) = 0.;
01631        chi2MatrixAft[0](0,3) = 0.;
01632        chi2MatrixAft[0](0,4) = 0.;
01633        chi2MatrixAft[0](0,5) = 0.;
01634        chi2MatrixAft[0](0,6) = 0.;
01635        chi2MatrixAft[0](0,7) = 0.;
01636        chi2MatrixAft[0](0,8) = 0.;
01637        chi2MatrixAft[0](0,9) = 0.;
01638        chi2MatrixAft[0](1,0) = 0.;
01639        chi2MatrixAft[0](1,1) = 0.;
01640        chi2MatrixAft[0](1,2) = 0.;
01641        chi2MatrixAft[0](1,3) = 0.;
01642        chi2MatrixAft[0](1,4) = 0.;
01643        chi2MatrixAft[0](1,5) = 0.;
01644        chi2MatrixAft[0](1,6) = 0.;
01645        chi2MatrixAft[0](1,7) = 0.;
01646        chi2MatrixAft[0](1,8) = 0.;
01647        chi2MatrixAft[0](1,9) = 0.;
01648        chi2MatrixAft[0](2,0) = 0.;
01649        chi2MatrixAft[0](2,1) = 0.;
01650        chi2MatrixAft[0](2,2) = 0.;
01651        chi2MatrixAft[0](2,3) = 0.;
01652        chi2MatrixAft[0](2,4) = 0.;
01653        chi2MatrixAft[0](2,5) = 0.;
01654        chi2MatrixAft[0](2,6) = 0.;
01655        chi2MatrixAft[0](2,7) = 0.;
01656        chi2MatrixAft[0](2,8) = 0.;
01657        chi2MatrixAft[0](2,9) = 0.;
01658        chi2MatrixAft[0](3,0) = 0.;
01659        chi2MatrixAft[0](3,1) = 0.;
01660        chi2MatrixAft[0](3,2) = 0.;
01661        chi2MatrixAft[0](3,3) = 0.;
01662        chi2MatrixAft[0](3,4) = 0.;
01663        chi2MatrixAft[0](3,5) = 0.;
01664        chi2MatrixAft[0](3,6) = 0.;
01665        chi2MatrixAft[0](3,7) = 0.;
01666        chi2MatrixAft[0](3,8) = 0.;
01667        chi2MatrixAft[0](3,9) = 0.; 
01668        chi2MatrixAft[0](4,0) = 0.;
01669        chi2MatrixAft[0](4,1) = 0.;
01670        chi2MatrixAft[0](4,2) = 0.;
01671        chi2MatrixAft[0](4,3) = 0.;
01672        chi2MatrixAft[0](4,4) = 0.8030884;
01673        chi2MatrixAft[0](4,5) = -0.2543541;
01674        chi2MatrixAft[0](4,6) = -0.2243544;
01675        chi2MatrixAft[0](4,7) = -0.1698177;
01676        chi2MatrixAft[0](4,8) = -0.1194506;
01677        chi2MatrixAft[0](4,9) = 0.; 
01678        chi2MatrixAft[0](5,0) = 0.;
01679        chi2MatrixAft[0](5,1) = 0.;
01680        chi2MatrixAft[0](5,2) = 0.;
01681        chi2MatrixAft[0](5,3) = 0.;
01682        chi2MatrixAft[0](5,4) = -0.2543541;
01683        chi2MatrixAft[0](5,5) = 0.6714465;
01684        chi2MatrixAft[0](5,6) = -0.2898025;
01685        chi2MatrixAft[0](5,7) = -0.2193564;
01686        chi2MatrixAft[0](5,8) = -0.1542964;
01687        chi2MatrixAft[0](5,9) = 0.;
01688        chi2MatrixAft[0](6,0) = 0.;
01689        chi2MatrixAft[0](6,1) = 0.;
01690        chi2MatrixAft[0](6,2) = 0.;
01691        chi2MatrixAft[0](6,3) = 0.;
01692        chi2MatrixAft[0](6,4) = -0.2243544;
01693        chi2MatrixAft[0](6,5) = -0.2898025;
01694        chi2MatrixAft[0](6,6) = 0.7443781;
01695        chi2MatrixAft[0](6,7) = -0.1934846;
01696        chi2MatrixAft[0](6,8) = -0.136098;
01697        chi2MatrixAft[0](6,9) = 0.; 
01698        chi2MatrixAft[0](7,0) = 0.;
01699        chi2MatrixAft[0](7,1) = 0.;
01700        chi2MatrixAft[0](7,2) = 0.;
01701        chi2MatrixAft[0](7,3) = 0.;
01702        chi2MatrixAft[0](7,4) = -0.1698177;
01703        chi2MatrixAft[0](7,5) = -0.2193564;
01704        chi2MatrixAft[0](7,6) = -0.1934846;
01705        chi2MatrixAft[0](7,7) = 0.8535482;
01706        chi2MatrixAft[0](7,8) = -0.1030149;
01707        chi2MatrixAft[0](7,9) = 0.; 
01708        chi2MatrixAft[0](8,0) = 0.;
01709        chi2MatrixAft[0](8,1) = 0.;
01710        chi2MatrixAft[0](8,2) = 0.;
01711        chi2MatrixAft[0](8,3) = 0.;
01712        chi2MatrixAft[0](8,4) = -0.1194506;
01713        chi2MatrixAft[0](8,5) = -0.1542964;
01714        chi2MatrixAft[0](8,6) = -0.136098;
01715        chi2MatrixAft[0](8,7) = -0.1030149;
01716        chi2MatrixAft[0](8,8) = 0.9275388;
01717        chi2MatrixAft[0](8,9) = 0.;
01718        chi2MatrixAft[0](9,0) = 0.;
01719        chi2MatrixAft[0](9,1) = 0.;
01720        chi2MatrixAft[0](9,2) = 0.;
01721        chi2MatrixAft[0](9,3) = 0.;
01722        chi2MatrixAft[0](9,4) = 0.;
01723        chi2MatrixAft[0](9,5) = 0.;
01724        chi2MatrixAft[0](9,6) = 0.;
01725        chi2MatrixAft[0](9,7) = 0.;
01726        chi2MatrixAft[0](9,8) = 0.;
01727        chi2MatrixAft[0](9,9) = 0.; 
01728      }
01729    else if (getWeightsFromFile_)
01730     {
01731       //Read from file
01732       edm::LogInfo("EcalTrivialConditionRetriever") << "Reading chi2MatrixAft from file " << edm::FileInPath(chi2MatrixAftFile_).fullPath().c_str() ;
01733       std::ifstream chi2MatrixAftFile(edm::FileInPath(chi2MatrixAftFile_).fullPath().c_str());
01734       int tdcBin=0;
01735       while (!chi2MatrixAftFile.eof() && tdcBin < nTDCbins_) 
01736         {
01737           //      chi2MatrixAft[tdcBin].resize(10);
01738           for(int j = 0; j < 10; ++j) {
01739             for(int l = 0; l < 10; ++l) {
01740               float ww;
01741               chi2MatrixAftFile >> ww;
01742               chi2MatrixAft[tdcBin](j,l)=ww;
01743             }
01744           }
01745           ++tdcBin;
01746         }
01747       assert (tdcBin == nTDCbins_);
01748     }
01749   else
01750     {
01751       //Not supported
01752       edm::LogError("EcalTrivialConditionRetriever") << "Configuration not supported. Exception is raised ";
01753       throw cms::Exception("WrongConfig");
01754     }
01755    
01756 //    for (int i=0;i<nTDCbins_;i++)
01757 //      {
01758        //       assert(chi2MatrixAft[i].size() == 10);
01759    chi2MatrixAft_ =  chi2MatrixAft;
01760    //      }
01761 
01762 }
01763 
01764 
01765 // --------------------------------------------------------------------------------
01766 
01767 std::auto_ptr<EcalChannelStatus>
01768 EcalTrivialConditionRetriever::getChannelStatusFromConfiguration (const EcalChannelStatusRcd&)
01769 {
01770   std::auto_ptr<EcalChannelStatus> ecalStatus = std::auto_ptr<EcalChannelStatus>( new EcalChannelStatus() );
01771   
01772 
01773   // start by setting all statuses to 0
01774   
01775   // barrel
01776   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
01777     if(ieta==0) continue;
01778     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
01779       if (EBDetId::validDetId(ieta,iphi)) {
01780         EBDetId ebid(ieta,iphi);
01781         ecalStatus->setValue( ebid, 0 );
01782       }
01783     }
01784   }
01785   // endcap
01786   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
01787     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
01788       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
01789       if (EEDetId::validDetId(iX,iY,1)) {
01790         EEDetId eedetidpos(iX,iY,1);
01791         ecalStatus->setValue( eedetidpos, 0 );
01792       }
01793       if (EEDetId::validDetId(iX,iY,-1)) {
01794         EEDetId eedetidneg(iX,iY,-1);
01795         ecalStatus->setValue( eedetidneg, 0 );
01796       }
01797     }
01798   }
01799   
01800   
01801   
01802   // overwrite the statuses which are in the file
01803   
01804   edm::LogInfo("EcalTrivialConditionRetriever") << "Reading channel statuses from file " << edm::FileInPath(channelStatusFile_).fullPath().c_str() ;
01805   std::ifstream statusFile(edm::FileInPath(channelStatusFile_).fullPath().c_str());
01806   if ( !statusFile.good() ) {
01807     edm::LogError ("EcalTrivialConditionRetriever") 
01808       << "*** Problems opening file: " << channelStatusFile_ ;
01809     throw cms::Exception ("Cannot open ECAL channel status file") ;
01810   }
01811   
01812   std::string EcalSubDet;
01813   std::string str;
01814   int hashIndex(0);
01815   int status(0);
01816   
01817   while (!statusFile.eof()) 
01818     {
01819       statusFile >> EcalSubDet;
01820       if (EcalSubDet!=std::string("EB") && EcalSubDet!=std::string("EE"))
01821         {
01822           std::getline(statusFile,str);
01823           continue;
01824         }
01825       else
01826         {
01827           statusFile>> hashIndex >> status;
01828         }
01829       // std::cout << EcalSubDet << " " << hashIndex << " " << status;
01830       
01831       if(EcalSubDet==std::string("EB"))
01832         {
01833           EBDetId ebid = EBDetId::unhashIndex(hashIndex);
01834           ecalStatus->setValue( ebid, status );
01835         }
01836       else if(EcalSubDet==std::string("EE"))
01837         {
01838           EEDetId eedetid = EEDetId::unhashIndex(hashIndex);
01839           ecalStatus->setValue( eedetid, status );
01840         }
01841       else
01842         {
01843           edm::LogError ("EcalTrivialConditionRetriever") 
01844             << " *** " << EcalSubDet << " is neither EB nor EE ";
01845         }
01846       
01847     }
01848   // the file is supposed to be in the form  -- FIXME
01849   
01850   
01851   statusFile.close();
01852   return ecalStatus;
01853 }
01854 
01855 
01856 
01857 std::auto_ptr<EcalChannelStatus>
01858 EcalTrivialConditionRetriever::produceEcalChannelStatus( const EcalChannelStatusRcd& )
01859 {
01860 
01861         std::auto_ptr<EcalChannelStatus>  ical = std::auto_ptr<EcalChannelStatus>( new EcalChannelStatus() );
01862         // barrel
01863         for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
01864                 if(ieta==0) continue;
01865                 for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
01866                         if (EBDetId::validDetId(ieta,iphi)) {
01867                                 EBDetId ebid(ieta,iphi);
01868                                 ical->setValue( ebid, 0 );
01869                         }
01870                 }
01871         }
01872         // endcap
01873         for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
01874                 for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
01875                         // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
01876                         if (EEDetId::validDetId(iX,iY,1)) {
01877                                 EEDetId eedetidpos(iX,iY,1);
01878                                 ical->setValue( eedetidpos, 0 );
01879                         }
01880                         if (EEDetId::validDetId(iX,iY,-1)) {
01881                                 EEDetId eedetidneg(iX,iY,-1);
01882                                 ical->setValue( eedetidneg, 0 );
01883                         }
01884                 }
01885         }
01886         return ical;
01887 }
01888 
01889 // --------------------------------------------------------------------------------
01890 std::auto_ptr<EcalDQMChannelStatus>
01891 EcalTrivialConditionRetriever::produceEcalDQMChannelStatus( const EcalDQMChannelStatusRcd& )
01892 {
01893   uint32_t sta(0);
01894 
01895         std::auto_ptr<EcalDQMChannelStatus>  ical = std::auto_ptr<EcalDQMChannelStatus>( new EcalDQMChannelStatus() );
01896         // barrel
01897         for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
01898                 if(ieta==0) continue;
01899                 for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
01900                         if (EBDetId::validDetId(ieta,iphi)) {
01901                                 EBDetId ebid(ieta,iphi);
01902                                 ical->setValue( ebid, sta );
01903                         }
01904                 }
01905         }
01906         // endcap
01907         for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
01908                 for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
01909                         // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
01910                         if (EEDetId::validDetId(iX,iY,1)) {
01911                                 EEDetId eedetidpos(iX,iY,1);
01912                                 ical->setValue( eedetidpos, sta );
01913                         }
01914                         if (EEDetId::validDetId(iX,iY,-1)) {
01915                                 EEDetId eedetidneg(iX,iY,-1);
01916                                 ical->setValue( eedetidneg, sta );
01917                         }
01918                 }
01919         }
01920         return ical;
01921 }
01922 // --------------------------------------------------------------------------------
01923 
01924 std::auto_ptr<EcalDQMTowerStatus>
01925 EcalTrivialConditionRetriever::produceEcalDQMTowerStatus( const EcalDQMTowerStatusRcd& )
01926 {
01927 
01928         std::auto_ptr<EcalDQMTowerStatus>  ical = std::auto_ptr<EcalDQMTowerStatus>( new EcalDQMTowerStatus() );
01929 
01930         uint32_t sta(0);
01931         
01932         // barrel
01933         int iz=0;
01934         for(int k=0 ; k<2; k++ ) {
01935           if(k==0) iz=-1;
01936           if(k==1) iz=+1;
01937           for(int i=1 ; i<73; i++) {
01938             for(int j=1 ; j<18; j++) {
01939               if (EcalTrigTowerDetId::validDetId(iz,EcalBarrel,j,i )){
01940                 EcalTrigTowerDetId ebid(iz,EcalBarrel,j,i);
01941 
01942                 ical->setValue( ebid, sta );
01943               }
01944             }
01945           }
01946         }
01947 
01948 
01949         // endcap
01950         for(int k=0 ; k<2; k++ ) {
01951           if(k==0) iz=-1;
01952           if(k==1) iz=+1;
01953           for(int i=1 ; i<21; i++) {
01954             for(int j=1 ; j<21; j++) {
01955               if (EcalScDetId::validDetId(i,j,iz )){
01956                 EcalScDetId eeid(i,j,iz);
01957                 ical->setValue( eeid, sta );
01958               }
01959             }
01960           }
01961         }
01962 
01963         return ical;
01964 }
01965 
01966 // --------------------------------------------------------------------------------
01967 std::auto_ptr<EcalDCSTowerStatus>
01968 EcalTrivialConditionRetriever::produceEcalDCSTowerStatus( const EcalDCSTowerStatusRcd& )
01969 {
01970 
01971         std::auto_ptr<EcalDCSTowerStatus>  ical = std::auto_ptr<EcalDCSTowerStatus>( new EcalDCSTowerStatus() );
01972 
01973         int status(0);
01974         
01975         // barrel
01976         int iz=0;
01977         for(int k=0 ; k<2; k++ ) {
01978           if(k==0) iz=-1;
01979           if(k==1) iz=+1;
01980           for(int i=1 ; i<73; i++) {
01981             for(int j=1 ; j<18; j++) {
01982               if (EcalTrigTowerDetId::validDetId(iz,EcalBarrel,j,i )){
01983                 EcalTrigTowerDetId ebid(iz,EcalBarrel,j,i);
01984 
01985                 ical->setValue( ebid, status );
01986               }
01987             }
01988           }
01989         }
01990 
01991 
01992         // endcap
01993         for(int k=0 ; k<2; k++ ) {
01994           if(k==0) iz=-1;
01995           if(k==1) iz=+1;
01996           for(int i=1 ; i<21; i++) {
01997             for(int j=1 ; j<21; j++) {
01998               if (EcalScDetId::validDetId(i,j,iz )){
01999                 EcalScDetId eeid(i,j,iz);
02000                 ical->setValue( eeid, status );
02001               }
02002             }
02003           }
02004         }
02005 
02006         return ical;
02007 }
02008 // --------------------------------------------------------------------------------
02009 
02010 std::auto_ptr<EcalDAQTowerStatus>
02011 EcalTrivialConditionRetriever::produceEcalDAQTowerStatus( const EcalDAQTowerStatusRcd& )
02012 {
02013 
02014         std::auto_ptr<EcalDAQTowerStatus>  ical = std::auto_ptr<EcalDAQTowerStatus>( new EcalDAQTowerStatus() );
02015 
02016         int status(0);
02017         
02018         // barrel
02019         int iz=0;
02020         for(int k=0 ; k<2; k++ ) {
02021           if(k==0) iz=-1;
02022           if(k==1) iz=+1;
02023           for(int i=1 ; i<73; i++) {
02024             for(int j=1 ; j<18; j++) {
02025               if (EcalTrigTowerDetId::validDetId(iz,EcalBarrel,j,i )){
02026                 EcalTrigTowerDetId ebid(iz,EcalBarrel,j,i);
02027 
02028                 ical->setValue( ebid, status );
02029               }
02030             }
02031           }
02032         }
02033 
02034 
02035         // endcap
02036         for(int k=0 ; k<2; k++ ) {
02037           if(k==0) iz=-1;
02038           if(k==1) iz=+1;
02039           for(int i=1 ; i<21; i++) {
02040             for(int j=1 ; j<21; j++) {
02041               if (EcalScDetId::validDetId(i,j,iz )){
02042                 EcalScDetId eeid(i,j,iz);
02043                 ical->setValue( eeid, status );
02044               }
02045             }
02046           }
02047         }
02048 
02049         return ical;
02050 }
02051 // --------------------------------------------------------------------------------
02052 
02053 std::auto_ptr<EcalTPGCrystalStatus>
02054 EcalTrivialConditionRetriever::getTrgChannelStatusFromConfiguration (const EcalTPGCrystalStatusRcd&)
02055 {
02056   std::auto_ptr<EcalTPGCrystalStatus> ecalStatus = std::auto_ptr<EcalTPGCrystalStatus>( new EcalTPGCrystalStatus() );
02057   
02058 
02059   // start by setting all statuses to 0
02060   
02061   // barrel
02062   for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
02063     if(ieta==0) continue;
02064     for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
02065       if (EBDetId::validDetId(ieta,iphi)) {
02066         EBDetId ebid(ieta,iphi);
02067         ecalStatus->setValue( ebid, 0 );
02068       }
02069     }
02070   }
02071   // endcap
02072   for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
02073     for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
02074       // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
02075       if (EEDetId::validDetId(iX,iY,1)) {
02076         EEDetId eedetidpos(iX,iY,1);
02077         ecalStatus->setValue( eedetidpos, 0 );
02078       }
02079       if (EEDetId::validDetId(iX,iY,-1)) {
02080         EEDetId eedetidneg(iX,iY,-1);
02081         ecalStatus->setValue( eedetidneg, 0 );
02082       }
02083     }
02084   }
02085   
02086   
02087   
02088   // overwrite the statuses which are in the file
02089   
02090   edm::LogInfo("EcalTrivialConditionRetriever") << "Reading channel statuses from file " << edm::FileInPath(channelStatusFile_).fullPath().c_str() ;
02091   std::ifstream statusFile(edm::FileInPath(channelStatusFile_).fullPath().c_str());
02092   if ( !statusFile.good() ) {
02093     edm::LogError ("EcalTrivialConditionRetriever") 
02094       << "*** Problems opening file: " << channelStatusFile_ ;
02095     throw cms::Exception ("Cannot open ECAL channel status file") ;
02096   }
02097   
02098   std::string EcalSubDet;
02099   std::string str;
02100   int hashIndex(0);
02101   int status(0);
02102   
02103   while (!statusFile.eof()) 
02104     {
02105       statusFile >> EcalSubDet;
02106       if (EcalSubDet!=std::string("EB") && EcalSubDet!=std::string("EE"))
02107         {
02108           std::getline(statusFile,str);
02109           continue;
02110         }
02111       else
02112         {
02113           statusFile>> hashIndex >> status;
02114         }
02115       // std::cout << EcalSubDet << " " << hashIndex << " " << status;
02116       
02117       if(EcalSubDet==std::string("EB"))
02118         {
02119           EBDetId ebid = EBDetId::unhashIndex(hashIndex);
02120           ecalStatus->setValue( ebid, status );
02121         }
02122       else if(EcalSubDet==std::string("EE"))
02123         {
02124           EEDetId eedetid = EEDetId::unhashIndex(hashIndex);
02125           ecalStatus->setValue( eedetid, status );
02126         }
02127       else
02128         {
02129           edm::LogError ("EcalTrivialConditionRetriever") 
02130             << " *** " << EcalSubDet << " is neither EB nor EE ";
02131         }
02132       
02133     }
02134   // the file is supposed to be in the form  -- FIXME
02135   
02136   
02137   statusFile.close();
02138   return ecalStatus;
02139 }
02140 
02141 
02142 
02143 std::auto_ptr<EcalTPGCrystalStatus>
02144 EcalTrivialConditionRetriever::produceEcalTrgChannelStatus( const EcalTPGCrystalStatusRcd& )
02145 {
02146 
02147         std::auto_ptr<EcalTPGCrystalStatus>  ical = std::auto_ptr<EcalTPGCrystalStatus>( new EcalTPGCrystalStatus() );
02148         // barrel
02149         for(int ieta=-EBDetId::MAX_IETA; ieta<=EBDetId::MAX_IETA; ++ieta) {
02150                 if(ieta==0) continue;
02151                 for(int iphi=EBDetId::MIN_IPHI; iphi<=EBDetId::MAX_IPHI; ++iphi) {
02152                         if (EBDetId::validDetId(ieta,iphi)) {
02153                                 EBDetId ebid(ieta,iphi);
02154                                 ical->setValue( ebid, 0 );
02155                         }
02156                 }
02157         }
02158         // endcap
02159         for(int iX=EEDetId::IX_MIN; iX<=EEDetId::IX_MAX ;++iX) {
02160                 for(int iY=EEDetId::IY_MIN; iY<=EEDetId::IY_MAX; ++iY) {
02161                         // make an EEDetId since we need EEDetId::rawId() to be used as the key for the pedestals
02162                         if (EEDetId::validDetId(iX,iY,1)) {
02163                                 EEDetId eedetidpos(iX,iY,1);
02164                                 ical->setValue( eedetidpos, 0 );
02165                         }
02166                         if (EEDetId::validDetId(iX,iY,-1)) {
02167                                 EEDetId eedetidneg(iX,iY,-1);
02168                                 ical->setValue( eedetidneg, 0 );
02169                         }
02170                 }
02171         }
02172         return ical;
02173 }
02174 
02175 
02176 
02177 std::auto_ptr<EcalLinearCorrections> 
02178 EcalTrivialConditionRetriever::getLinearCorrectionsFromConfiguration ( const EcalLinearCorrectionsRcd& )
02179 {
02180   std::auto_ptr<EcalLinearCorrections>  ical = std::auto_ptr<EcalLinearCorrections>( new EcalLinearCorrections() );
02181   
02182   edm::LogInfo("EcalTrivialConditionRetriever") << "Reading linear corrections from file "
02183                                                 << linearCorrectionsFile_.c_str() ;
02184   
02185   FILE *inpFile ;
02186   inpFile = fopen (linearCorrectionsFile_.c_str (),"r") ;
02187   if (!inpFile) 
02188     {
02189       edm::LogError ("EcalTrivialConditionRetriever") 
02190         << "*** Can not open file: " << linearCorrectionsFile_ ;
02191       throw cms::Exception ("Cannot open linear-corrections coefficients txt file") ;
02192     }
02193   
02194   char line[256] ;
02195   std::ostringstream str ;
02196   fgets (line,255,inpFile) ; // header of the file 
02197   
02198   
02199   edm::LogInfo("EcalTrivialConditionRetriever")
02200     << "linear corrections file - " 
02201     << str.str () << std::endl ;
02202   
02203   int ii = 0 ;
02204   
02205   while (fgets (line,255,inpFile)) 
02206     {
02207       ii++;
02208       int eta = 0 ;
02209       int phi = 0. ;
02210       int zeta = 0. ;
02211       float calib=1.0;
02212       sscanf (line, "%d %d %d %f", &eta, &phi, &zeta, &calib);
02213       if(zeta==0){
02214         EBDetId ebid (eta,phi);
02215         ical->setValue (ebid.rawId (), calib) ;
02216       } else {
02217         EEDetId eeid(eta,phi,zeta);
02218         ical->setValue(eeid.rawId(), calib);
02219       }
02220       
02221     }
02222   fclose (inpFile) ;           // close inp. file
02223   edm::LogInfo ("EcalTrivialConditionRetriever") << "Read intercalibrations for " << ii << " xtals " ; 
02224   if (ii!=75648) edm::LogWarning ("StoreEcalCondition") 
02225     << "Some crystals missing" << std::endl ;
02226 
02227   return ical;
02228 }
02229 
02230 
02231 std::auto_ptr<EcalIntercalibConstants> 
02232 EcalTrivialConditionRetriever::getIntercalibConstantsFromConfiguration 
02233 ( const EcalIntercalibConstantsRcd& )
02234 {
02235   std::auto_ptr<EcalIntercalibConstants>  ical = 
02236       std::auto_ptr<EcalIntercalibConstants>( new EcalIntercalibConstants() );
02237 
02238   // Read the values from a txt file
02239   // -------------------------------
02240 
02241   edm::LogInfo("EcalTrivialConditionRetriever") << "Reading intercalibration constants from file "
02242                                                 << intercalibConstantsFile_.c_str() ;
02243 
02244   FILE *inpFile ;
02245   inpFile = fopen (intercalibConstantsFile_.c_str (),"r") ;
02246   if (!inpFile) 
02247     {
02248       edm::LogError ("EcalTrivialConditionRetriever") 
02249          << "*** Can not open file: " << intercalibConstantsFile_ ;
02250       throw cms::Exception ("Cannot open inter-calibration coefficients txt file") ;
02251     }
02252 
02253   char line[256] ;
02254   std::ostringstream str ;
02255   fgets (line,255,inpFile) ;
02256   int sm_number=atoi (line) ;
02257   str << "sm: " << sm_number ;  
02258 
02259   fgets (line,255,inpFile) ;
02260   //int nevents=atoi (line) ; // not necessary here just for online conddb
02261 
02262   fgets (line,255,inpFile) ;
02263   std::string gen_tag = line ;
02264   str << "gen tag: " << gen_tag ;  // should I use this? 
02265 
02266   fgets (line,255,inpFile) ;
02267   std::string cali_method = line ;
02268   str << "cali method: " << cali_method << std::endl ; // not important 
02269 
02270   fgets (line,255,inpFile) ;
02271   std::string cali_version = line ;
02272   str << "cali version: " << cali_version << std::endl ; // not important 
02273 
02274   fgets (line,255,inpFile) ;
02275   std::string cali_type = line ;
02276   str << "cali type: " << cali_type ; // not important
02277 
02278   edm::LogInfo("EcalTrivialConditionRetriever")
02279             << "[PIETRO] Intercalibration file - " 
02280             << str.str () << std::endl ;
02281 
02282   float calib[1700]={1} ;
02283   int calib_status[1700]={0} ;
02284 
02285   int ii = 0 ;
02286 
02287   while (fgets (line,255,inpFile)) 
02288     {
02289       ii++;
02290       int dmy_num = 0 ;
02291       float dmy_calib = 0. ;
02292       float dmy_RMS = 0. ;
02293       int dmy_events = 0 ;
02294       int dmy_status = 0 ;
02295       sscanf (line, "%d %f %f %d %d", &dmy_num, &dmy_calib,
02296                                       &dmy_RMS, &dmy_events,
02297                                       &dmy_status) ;
02298       assert (dmy_num >= 1) ;
02299       assert (dmy_num <= 1700) ;
02300       calib[dmy_num-1] = dmy_calib ; 
02301       calib_status[dmy_num-1] = dmy_status ;
02302 
02303 //       edm::LogInfo ("EcalTrivialConditionRetriever")
02304 //                 << "[PIETRO] cry = " << dmy_num 
02305 //                 << " calib = " << calib[dmy_num-1] 
02306 //                 << " RMS = " << dmy_RMS
02307 //                 << " events = " << dmy_events
02308 //                 << " status = " << calib_status[dmy_num-1] 
02309 //                 << std::endl ;
02310     }
02311 
02312   fclose (inpFile) ;           // close inp. file
02313   edm::LogInfo ("EcalTrivialConditionRetriever") << "Read intercalibrations for " << ii << " xtals " ; 
02314   if (ii!=1700) edm::LogWarning ("StoreEcalCondition") 
02315                 << "Some crystals missing, set to 1" << std::endl ;
02316 
02317   // Transfer the data to the inter-calibration coefficients container
02318   // -----------------------------------------------------------------
02319 
02320   // DB supermodule always set to 1 for the TestBeam FIXME
02321   int sm_db=1 ;
02322   // loop over channels 
02323   for (int i=0 ; i<1700 ; i++)
02324     {
02325       //if (EBDetId::validDetId(iEta,iPhi)) {
02326       // CANNOT be used -- validDetId only checks ETA PHI method
02327       // doing a check by hand, here is the only place in CMSSW 
02328       // outside TB code and EcalRawToDigi where needed
02329       // => no need for changing the DetId interface
02330       //
02331       // checking only sm_db -- guess can change with the above FIXME
02332       if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
02333         EBDetId ebid (sm_db,i+1,EBDetId::SMCRYSTALMODE) ;
02334         if (calib_status[i]) ical->setValue (ebid.rawId (), calib[i]) ;
02335         else ical->setValue (ebid.rawId (), 1.) ;
02336       }
02337       //}
02338     } // loop over channels 
02339         
02340 //  edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ; 
02341   return ical;
02342 }
02343 
02344 
02345 
02346 
02347 std::auto_ptr<EcalIntercalibErrors> 
02348 EcalTrivialConditionRetriever::getIntercalibErrorsFromConfiguration 
02349 ( const EcalIntercalibErrorsRcd& )
02350 {
02351   std::auto_ptr<EcalIntercalibErrors>  ical = 
02352       std::auto_ptr<EcalIntercalibErrors>( new EcalIntercalibErrors() );
02353 
02354   // Read the values from a txt file
02355   // -------------------------------
02356 
02357   edm::LogInfo("EcalTrivialConditionRetriever") << "Reading intercalibration constants from file "
02358                                                 << intercalibErrorsFile_.c_str() ;
02359 
02360   FILE *inpFile ;
02361   inpFile = fopen (intercalibErrorsFile_.c_str (),"r") ;
02362   if (!inpFile) 
02363     {
02364       edm::LogError ("EcalTrivialConditionRetriever") 
02365          << "*** Can not open file: " << intercalibErrorsFile_ ;
02366       throw cms::Exception ("Cannot open inter-calibration coefficients txt file") ;
02367     }
02368 
02369   char line[256] ;
02370   std::ostringstream str ;
02371   fgets (line,255,inpFile) ;
02372   int sm_number=atoi (line) ;
02373   str << "sm: " << sm_number ;  
02374 
02375   fgets (line,255,inpFile) ;
02376   //int nevents=atoi (line) ; // not necessary here just for online conddb
02377 
02378   fgets (line,255,inpFile) ;
02379   std::string gen_tag = line ;
02380   str << "gen tag: " << gen_tag ;  // should I use this? 
02381 
02382   fgets (line,255,inpFile) ;
02383   std::string cali_method = line ;
02384   str << "cali method: " << cali_method << std::endl ; // not important 
02385 
02386   fgets (line,255,inpFile) ;
02387   std::string cali_version = line ;
02388   str << "cali version: " << cali_version << std::endl ; // not important 
02389 
02390   fgets (line,255,inpFile) ;
02391   std::string cali_type = line ;
02392   str << "cali type: " << cali_type ; // not important
02393 
02394   edm::LogInfo("EcalTrivialConditionRetriever")
02395             << "[PIETRO] Intercalibration file - " 
02396             << str.str () << std::endl ;
02397 
02398   float calib[1700]={1} ;
02399   int calib_status[1700]={0} ;
02400 
02401   int ii = 0 ;
02402 
02403   while (fgets (line,255,inpFile)) 
02404     {
02405       ii++;
02406       int dmy_num = 0 ;
02407       float dmy_calib = 0. ;
02408       float dmy_RMS = 0. ;
02409       int dmy_events = 0 ;
02410       int dmy_status = 0 ;
02411       sscanf (line, "%d %f %f %d %d", &dmy_num, &dmy_calib,
02412                                       &dmy_RMS, &dmy_events,
02413                                       &dmy_status) ;
02414       assert (dmy_num >= 1) ;
02415       assert (dmy_num <= 1700) ;
02416       calib[dmy_num-1] = dmy_calib ; 
02417       calib_status[dmy_num-1] = dmy_status ;
02418 
02419 //       edm::LogInfo ("EcalTrivialConditionRetriever")
02420 //                 << "[PIETRO] cry = " << dmy_num 
02421 //                 << " calib = " << calib[dmy_num-1] 
02422 //                 << " RMS = " << dmy_RMS
02423 //                 << " events = " << dmy_events
02424 //                 << " status = " << calib_status[dmy_num-1] 
02425 //                 << std::endl ;
02426     }
02427 
02428   fclose (inpFile) ;           // close inp. file
02429   edm::LogInfo ("EcalTrivialConditionRetriever") << "Read intercalibrations for " << ii << " xtals " ; 
02430   if (ii!=1700) edm::LogWarning ("StoreEcalCondition") 
02431                 << "Some crystals missing, set to 1" << std::endl ;
02432 
02433   // Transfer the data to the inter-calibration coefficients container
02434   // -----------------------------------------------------------------
02435 
02436   // DB supermodule always set to 1 for the TestBeam FIXME
02437   int sm_db=1 ;
02438   // loop over channels 
02439   for (int i=0 ; i<1700 ; i++)
02440     {
02441       //if (EBDetId::validDetId(iEta,iPhi)) {
02442       // CANNOT be used -- validDetId only checks ETA PHI method
02443       // doing a check by hand, here is the only place in CMSSW 
02444       // outside TB code and EcalRawToDigi where needed
02445       // => no need for changing the DetId interface
02446       //
02447       // checking only sm_db -- guess can change with the above FIXME
02448       if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
02449         EBDetId ebid (sm_db,i+1,EBDetId::SMCRYSTALMODE) ;
02450         if (calib_status[i]) ical->setValue (ebid.rawId (), calib[i]) ;
02451         else ical->setValue (ebid.rawId (), 1.) ;
02452       }
02453       //}
02454     } // loop over channels 
02455         
02456 //  edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ; 
02457   return ical;
02458 }
02459 
02460 // --------------------------------------------------------------------------------
02461 
02462 
02463 std::auto_ptr<EcalTimeCalibConstants> 
02464 EcalTrivialConditionRetriever::getTimeCalibConstantsFromConfiguration 
02465 ( const EcalTimeCalibConstantsRcd& )
02466 {
02467   std::auto_ptr<EcalTimeCalibConstants>  ical = 
02468       std::auto_ptr<EcalTimeCalibConstants>( new EcalTimeCalibConstants() );
02469 
02470   // Read the values from a txt file
02471   // -------------------------------
02472 
02473   edm::LogInfo("EcalTrivialConditionRetriever") << "Reading time calibration constants from file "
02474                                                 << timeCalibConstantsFile_.c_str() ;
02475 
02476   FILE *inpFile ;
02477   inpFile = fopen (timeCalibConstantsFile_.c_str (),"r") ;
02478   if (!inpFile) 
02479     {
02480       edm::LogError ("EcalTrivialConditionRetriever") 
02481          << "*** Can not open file: " << timeCalibConstantsFile_ ;
02482       throw cms::Exception ("Cannot open inter-calibration coefficients txt file") ;
02483     }
02484 
02485   char line[256] ;
02486   std::ostringstream str ;
02487   fgets (line,255,inpFile) ;
02488   int sm_number=atoi (line) ;
02489   str << "sm: " << sm_number ;  
02490 
02491   fgets (line,255,inpFile) ;
02492   //int nevents=atoi (line) ; // not necessary here just for online conddb
02493 
02494   fgets (line,255,inpFile) ;
02495   std::string gen_tag = line ;
02496   str << "gen tag: " << gen_tag ;  // should I use this? 
02497 
02498   fgets (line,255,inpFile) ;
02499   std::string cali_method = line ;
02500   str << "cali method: " << cali_method << std::endl ; // not important 
02501 
02502   fgets (line,255,inpFile) ;
02503   std::string cali_version = line ;
02504   str << "cali version: " << cali_version << std::endl ; // not important 
02505 
02506   fgets (line,255,inpFile) ;
02507   std::string cali_type = line ;
02508   str << "cali type: " << cali_type ; // not important
02509 
02510   edm::LogInfo("EcalTrivialConditionRetriever")
02511             << "TimeCalibration file - " 
02512             << str.str () << std::endl ;
02513 
02514   float calib[1700]={1} ;
02515   int calib_status[1700]={0} ;
02516 
02517   int ii = 0 ;
02518 
02519   while (fgets (line,255,inpFile)) 
02520     {
02521       ii++;
02522       int dmy_num = 0 ;
02523       float dmy_calib = 0. ;
02524       float dmy_RMS = 0. ;
02525       int dmy_events = 0 ;
02526       int dmy_status = 0 ;
02527       sscanf (line, "%d %f %f %d %d", &dmy_num, &dmy_calib,
02528                                       &dmy_RMS, &dmy_events,
02529                                       &dmy_status) ;
02530       assert (dmy_num >= 1) ;
02531       assert (dmy_num <= 1700) ;
02532       calib[dmy_num-1] = dmy_calib ; 
02533       calib_status[dmy_num-1] = dmy_status ;
02534 
02535 //       edm::LogInfo ("EcalTrivialConditionRetriever")
02536 //                 << "[PIETRO] cry = " << dmy_num 
02537 //                 << " calib = " << calib[dmy_num-1] 
02538 //                 << " RMS = " << dmy_RMS
02539 //                 << " events = " << dmy_events
02540 //                 << " status = " << calib_status[dmy_num-1] 
02541 //                 << std::endl ;
02542     }
02543 
02544   fclose (inpFile) ;           // close inp. file
02545   edm::LogInfo ("EcalTrivialConditionRetriever") << "Read timeCalibrations for " << ii << " xtals " ; 
02546   if (ii!=1700) edm::LogWarning ("StoreEcalCondition") 
02547                 << "Some crystals missing, set to 1" << std::endl ;
02548 
02549   // Transfer the data to the inter-calibration coefficients container
02550   // -----------------------------------------------------------------
02551 
02552   // DB supermodule always set to 1 for the TestBeam FIXME
02553   int sm_db=1 ;
02554   // loop over channels 
02555   for (int i=0 ; i<1700 ; i++)
02556     {
02557       //if (EBDetId::validDetId(iEta,iPhi)) {
02558       // CANNOT be used -- validDetId only checks ETA PHI method
02559       // doing a check by hand, here is the only place in CMSSW 
02560       // outside TB code and EcalRawToDigi where needed
02561       // => no need for changing the DetId interface
02562       //
02563       // checking only sm_db -- guess can change with the above FIXME
02564       if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
02565         EBDetId ebid (sm_db,i+1,EBDetId::SMCRYSTALMODE) ;
02566         if (calib_status[i]) ical->setValue (ebid.rawId (), calib[i]) ;
02567         else ical->setValue (ebid.rawId (), 1.) ;
02568       }
02569       //}
02570     } // loop over channels 
02571         
02572 //  edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ; 
02573   return ical;
02574 }
02575 
02576 
02577 std::auto_ptr<EcalTimeCalibErrors> 
02578 EcalTrivialConditionRetriever::getTimeCalibErrorsFromConfiguration 
02579 ( const EcalTimeCalibErrorsRcd& )
02580 {
02581   std::auto_ptr<EcalTimeCalibErrors>  ical = 
02582       std::auto_ptr<EcalTimeCalibErrors>( new EcalTimeCalibErrors() );
02583 
02584   // Read the values from a txt file
02585   // -------------------------------
02586 
02587   edm::LogInfo("EcalTrivialConditionRetriever") << "Reading timeCalibration constants from file "
02588                                                 << timeCalibErrorsFile_.c_str() ;
02589 
02590   FILE *inpFile ;
02591   inpFile = fopen (timeCalibErrorsFile_.c_str (),"r") ;
02592   if (!inpFile) 
02593     {
02594       edm::LogError ("EcalTrivialConditionRetriever") 
02595          << "*** Can not open file: " << timeCalibErrorsFile_ ;
02596       throw cms::Exception ("Cannot open inter-calibration coefficients txt file") ;
02597     }
02598 
02599   char line[256] ;
02600   std::ostringstream str ;
02601   fgets (line,255,inpFile) ;
02602   int sm_number=atoi (line) ;
02603   str << "sm: " << sm_number ;  
02604 
02605   fgets (line,255,inpFile) ;
02606   //int nevents=atoi (line) ; // not necessary here just for online conddb
02607 
02608   fgets (line,255,inpFile) ;
02609   std::string gen_tag = line ;
02610   str << "gen tag: " << gen_tag ;  // should I use this? 
02611 
02612   fgets (line,255,inpFile) ;
02613   std::string cali_method = line ;
02614   str << "cali method: " << cali_method << std::endl ; // not important 
02615 
02616   fgets (line,255,inpFile) ;
02617   std::string cali_version = line ;
02618   str << "cali version: " << cali_version << std::endl ; // not important 
02619 
02620   fgets (line,255,inpFile) ;
02621   std::string cali_type = line ;
02622   str << "cali type: " << cali_type ; // not important
02623 
02624   edm::LogInfo("EcalTrivialConditionRetriever")
02625             << "TimeCalibration file - " 
02626             << str.str () << std::endl ;
02627 
02628   float calib[1700]={1} ;
02629   int calib_status[1700]={0} ;
02630 
02631   int ii = 0 ;
02632 
02633   while (fgets (line,255,inpFile)) 
02634     {
02635       ii++;
02636       int dmy_num = 0 ;
02637       float dmy_calib = 0. ;
02638       float dmy_RMS = 0. ;
02639       int dmy_events = 0 ;
02640       int dmy_status = 0 ;
02641       sscanf (line, "%d %f %f %d %d", &dmy_num, &dmy_calib,
02642                                       &dmy_RMS, &dmy_events,
02643                                       &dmy_status) ;
02644       assert (dmy_num >= 1) ;
02645       assert (dmy_num <= 1700) ;
02646       calib[dmy_num-1] = dmy_calib ; 
02647       calib_status[dmy_num-1] = dmy_status ;
02648 
02649 //       edm::LogInfo ("EcalTrivialConditionRetriever")
02650 //                 << "[PIETRO] cry = " << dmy_num 
02651 //                 << " calib = " << calib[dmy_num-1] 
02652 //                 << " RMS = " << dmy_RMS
02653 //                 << " events = " << dmy_events
02654 //                 << " status = " << calib_status[dmy_num-1] 
02655 //                 << std::endl ;
02656     }
02657 
02658   fclose (inpFile) ;           // close inp. file
02659   edm::LogInfo ("EcalTrivialConditionRetriever") << "Read time calibrations for " << ii << " xtals " ; 
02660   if (ii!=1700) edm::LogWarning ("StoreEcalCondition") 
02661                 << "Some crystals missing, set to 1" << std::endl ;
02662 
02663   // Transfer the data to the inter-calibration coefficients container
02664   // -----------------------------------------------------------------
02665 
02666   // DB supermodule always set to 1 for the TestBeam FIXME
02667   int sm_db=1 ;
02668   // loop over channels 
02669   for (int i=0 ; i<1700 ; i++)
02670     {
02671       //if (EBDetId::validDetId(iEta,iPhi)) {
02672       // CANNOT be used -- validDetId only checks ETA PHI method
02673       // doing a check by hand, here is the only place in CMSSW 
02674       // outside TB code and EcalRawToDigi where needed
02675       // => no need for changing the DetId interface
02676       //
02677       // checking only sm_db -- guess can change with the above FIXME
02678       if (sm_db >= EBDetId::MIN_SM && sm_db <= EBDetId::MAX_SM) {
02679         EBDetId ebid (sm_db,i+1,EBDetId::SMCRYSTALMODE) ;
02680         if (calib_status[i]) ical->setValue (ebid.rawId (), calib[i]) ;
02681         else ical->setValue (ebid.rawId (), 1.) ;
02682       }
02683       //}
02684     } // loop over channels 
02685         
02686 //  edm::LogInfo ("EcalTrivialConditionRetriever") << "INTERCALIBRATION DONE" ; 
02687   return ical;
02688 }
02689 
02690 // --------------------------------------------------------------------------------
02691 
02692 std::auto_ptr<EcalMappingElectronics>
02693 EcalTrivialConditionRetriever::getMappingFromConfiguration (const EcalMappingElectronicsRcd&)
02694 {
02695   std::auto_ptr<EcalMappingElectronics> mapping = std::auto_ptr<EcalMappingElectronics>( new EcalMappingElectronics() );
02696   edm::LogInfo("EcalTrivialConditionRetriever") << "Reading mapping from file " << edm::FileInPath(mappingFile_).fullPath().c_str() ;
02697   
02698   std::ifstream f(edm::FileInPath(mappingFile_).fullPath().c_str());
02699   if (!f.good())
02700     {
02701       edm::LogError("EcalTrivialConditionRetriever") << "File not found";
02702       throw cms::Exception("FileNotFound");
02703     }
02704   
02705   // uint32_t detid, elecid, triggerid;
02706   
02707   int ix, iy, iz, CL;
02708   // int dccid, towerid, stripid, xtalid;
02709   // int tccid, tower, ipseudostrip, xtalinps;
02710   int dccid, towerid, pseudostrip_in_SC, xtal_in_pseudostrip;
02711   int tccid, tower, pseudostrip_in_TCC, pseudostrip_in_TT;
02712   
02713   while ( ! f.eof()) 
02714     {
02715       // f >> detid >> elecid >> triggerid; 
02716       f >> ix >> iy >> iz >> CL >> dccid >> towerid >> pseudostrip_in_SC >> xtal_in_pseudostrip >> tccid >> tower >> 
02717         pseudostrip_in_TCC >> pseudostrip_in_TT ;
02718       
02719 //       if (!EEDetId::validDetId(ix,iy,iz))
02720 //        continue;
02721           
02722       EEDetId detid(ix,iy,iz,EEDetId::XYMODE);
02723       // std::cout << " dcc tower ps_in_SC xtal_in_ps " << dccid << " " << towerid << " " << pseudostrip_in_SC << " " << xtal_in_pseudostrip << std::endl;
02724       EcalElectronicsId elecid(dccid,towerid, pseudostrip_in_SC, xtal_in_pseudostrip);
02725       // std::cout << " tcc tt ps_in_TT xtal_in_ps " << tccid << " " << tower << " " << pseudostrip_in_TT << " " << xtal_in_pseudostrip << std::endl;
02726       EcalTriggerElectronicsId triggerid(tccid, tower, pseudostrip_in_TT, xtal_in_pseudostrip);
02727       EcalMappingElement aElement;
02728       aElement.electronicsid = elecid.rawId();
02729       aElement.triggerid = triggerid.rawId();
02730       (*mapping).setValue(detid, aElement);
02731     }
02732   
02733   f.close();
02734   return mapping;
02735 }
02736 
02737 
02738 
02739 std::auto_ptr<EcalMappingElectronics>
02740 EcalTrivialConditionRetriever::produceEcalMappingElectronics( const EcalMappingElectronicsRcd& )
02741 {
02742 
02743         std::auto_ptr<EcalMappingElectronics>  ical = std::auto_ptr<EcalMappingElectronics>( new EcalMappingElectronics() );
02744         return ical;
02745 }
02746 
02747 // --------------------------------------------------------------------------------
02748 
02749 std::auto_ptr<Alignments>
02750 EcalTrivialConditionRetriever::produceEcalAlignmentEB( const EBAlignmentRcd& ) {
02751   double mytrans[3] = {0., 0., 0.};
02752   double myeuler[3] = {0., 0., 0.};
02753   std::ifstream f;
02754   if(getEBAlignmentFromFile_)
02755     f.open(edm::FileInPath(EBAlignmentFile_).fullPath().c_str());
02756   std::vector<AlignTransform> my_align;
02757   int ieta = 1;
02758   int iphi = 0;
02759   for(int SM = 1 ; SM < 37; SM++ ) {
02760     // make an EBDetId since we need EBDetId::rawId()
02761     if(SM > 18) { 
02762       iphi = 1 + (SM - 19) * 20;
02763       ieta = -1;
02764     }
02765     else
02766       iphi = SM * 20;
02767     EBDetId ebdetId(ieta,iphi);
02768     if(getEBAlignmentFromFile_) {
02769       f >> myeuler[0] >> myeuler[1] >> myeuler[2] >> mytrans[0] >> mytrans[1] >> mytrans[2];
02770       std::cout << " translation " << mytrans[0] << " " << mytrans[1] << " " << mytrans[2] << "\n" 
02771            << " euler " << myeuler[0] << " " << myeuler[1] << " " << myeuler[2] << std::endl;
02772     }
02773     CLHEP::Hep3Vector translation( mytrans[0], mytrans[1], mytrans[2]);
02774     CLHEP::HepEulerAngles euler( myeuler[0], myeuler[1], myeuler[2]);
02775     AlignTransform transform( translation, euler, ebdetId );
02776     my_align.push_back(transform);
02777   }
02778   /*
02779   // check
02780   uint32_t m_rawid;
02781   double m_x, m_y, m_z;
02782   double m_phi, m_theta, m_psi;
02783   int SM = 0;
02784   for (std::vector<AlignTransform>::const_iterator i = my_align.begin(); i != my_align.end(); ++i){     
02785     m_rawid = i->rawId();
02786     CLHEP::Hep3Vector translation = i->translation();
02787     m_x = translation.x();
02788     m_y = translation.y();
02789     m_z = translation.z();
02790     CLHEP::HepRotation rotation = i->rotation();
02791     m_phi = rotation.getPhi();
02792     m_theta = rotation.getTheta();
02793     m_psi = rotation.getPsi();
02794     SM++;
02795     std::cout << " SM " << SM << " Id " << m_rawid << " x " << m_x << " y " << m_y << " z " << m_z
02796               << " phi " << m_phi << " theta " << m_theta << " psi " << m_psi << std::endl;
02797   }
02798   */
02799   Alignments a; 
02800   a.m_align = my_align; 
02801 
02802   std::auto_ptr<Alignments> ical = std::auto_ptr<Alignments>( new Alignments(a) );
02803   return ical;
02804 }
02805 
02806 std::auto_ptr<Alignments>
02807 EcalTrivialConditionRetriever::produceEcalAlignmentEE( const EEAlignmentRcd& ) {
02808   double mytrans[3] = {0., 0., 0.};
02809   double myeuler[3] = {0., 0., 0.};
02810   std::ifstream f;
02811   if(getEEAlignmentFromFile_)
02812     f.open(edm::FileInPath(EEAlignmentFile_).fullPath().c_str());
02813   std::vector<AlignTransform> my_align;
02814   int ix = 20;
02815   int iy = 50;
02816   int side = -1;
02817   for(int Dee = 0 ; Dee < 4; Dee++ ) {
02818     // make an EEDetId since we need EEDetId::rawId()
02819     if(Dee == 1 || Dee == 3) 
02820       ix = 70;
02821     else ix = 20;
02822     if(Dee == 2)
02823       side = 1;
02824     EEDetId eedetId(ix, iy, side);
02825     if(getEEAlignmentFromFile_) {
02826       f >> myeuler[0] >> myeuler[1] >> myeuler[2] >> mytrans[0] >> mytrans[1] >> mytrans[2];
02827       std::cout << " translation " << mytrans[0] << " " << mytrans[1] << " " << mytrans[2] << "\n" 
02828            << " euler " << myeuler[0] << " " << myeuler[1] << " " << myeuler[2] << std::endl;
02829     }
02830     CLHEP::Hep3Vector translation( mytrans[0], mytrans[1], mytrans[2]);
02831     CLHEP::HepEulerAngles euler( myeuler[0], myeuler[1], myeuler[2]);
02832     AlignTransform transform( translation, euler, eedetId );
02833     my_align.push_back(transform);
02834   }
02835   Alignments a; 
02836   a.m_align = my_align; 
02837   std::auto_ptr<Alignments> ical = std::auto_ptr<Alignments>( new Alignments(a) );
02838   return ical;
02839 }
02840 
02841 std::auto_ptr<Alignments>
02842 EcalTrivialConditionRetriever::produceEcalAlignmentES( const ESAlignmentRcd& ) {
02843   double mytrans[3] = {0., 0., 0.};
02844   double myeuler[3] = {0., 0., 0.};
02845   std::ifstream f;
02846   if(getESAlignmentFromFile_)
02847     f.open(edm::FileInPath(ESAlignmentFile_).fullPath().c_str());
02848   std::vector<AlignTransform> my_align;
02849   //  int ix_vect[10] = {10, 30, 30, 50, 10, 30, 10, 30};
02850   int pl_vect[10] = {2, 2, 1, 1, 1, 1, 2, 2};
02851   int iy = 10;
02852   int side = -1;
02853   int strip = 1;
02854   for(int layer = 0 ; layer < 8; layer++ ) {
02855     // make an ESDetId since we need ESDetId::rawId()
02856     int ix = 10 + (layer%2) * 20;
02857     int plane = pl_vect[layer];
02858     if(layer > 3) side = 1;
02859     ESDetId esdetId(strip, ix, iy, plane, side);
02860     if(getESAlignmentFromFile_) {
02861       f >> myeuler[0] >> myeuler[1] >> myeuler[2] >> mytrans[0] >> mytrans[1] >> mytrans[2];
02862       std::cout << " translation " << mytrans[0] << " " << mytrans[1] << " " << mytrans[2] << "\n" 
02863                 << " euler " << myeuler[0] << " " << myeuler[1] << " " << myeuler[2] << std::endl;
02864     }
02865     CLHEP::Hep3Vector translation( mytrans[0], mytrans[1], mytrans[2]);
02866     CLHEP::HepEulerAngles euler( myeuler[0], myeuler[1], myeuler[2]);
02867     AlignTransform transform( translation, euler, esdetId );
02868     my_align.push_back(transform);
02869   }
02870   Alignments a; 
02871   a.m_align = my_align; 
02872   std::auto_ptr<Alignments> ical = std::auto_ptr<Alignments>( new Alignments(a) );
02873   return ical;
02874 }
02875 
02876 std::auto_ptr<EcalSampleMask>
02877 EcalTrivialConditionRetriever::produceEcalSampleMask( const EcalSampleMaskRcd& )
02878 {
02879   return std::auto_ptr<EcalSampleMask>( new EcalSampleMask(sampleMaskEB_, sampleMaskEE_) );
02880 }
02881 
02882