CMS 3D CMS Logo

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

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