00001 #include "SimCalorimetry/HcalSimAlgos/interface/HcalSimParameters.h"
00002 #include "DataFormats/HcalDetId/interface/HcalSubdetector.h"
00003 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00004 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00005 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00006 #include "CondFormats/HcalObjects/interface/HcalGain.h"
00007 #include "CondFormats/HcalObjects/interface/HcalGainWidth.h"
00008 #include "CLHEP/Random/RandGaussQ.h"
00009 using namespace std;
00010
00011 HcalSimParameters::HcalSimParameters(double simHitToPhotoelectrons, const std::vector<double> & photoelectronsToAnalog,
00012 double samplingFactor, double timePhase,
00013 int readoutFrameSize, int binOfMaximum,
00014 bool doPhotostatistics, bool syncPhase,
00015 int firstRing, const std::vector<double> & samplingFactors)
00016 : CaloSimParameters(simHitToPhotoelectrons, photoelectronsToAnalog[0], samplingFactor, timePhase,
00017 readoutFrameSize, binOfMaximum, doPhotostatistics, syncPhase),
00018 theDbService(0),
00019 theFirstRing(firstRing),
00020 theSamplingFactors(samplingFactors),
00021 thePE2fCByRing(photoelectronsToAnalog),
00022 thePixels(0),
00023 doTimeSmear_(true)
00024 {
00025 defaultTimeSmearing();
00026 }
00027
00028 HcalSimParameters::HcalSimParameters(const edm::ParameterSet & p)
00029 : CaloSimParameters(p),
00030 theDbService(0),
00031 theFirstRing( p.getParameter<int>("firstRing") ),
00032 theSamplingFactors( p.getParameter<std::vector<double> >("samplingFactors") ),
00033 thePE2fCByRing( p.getParameter<std::vector<double> >("photoelectronsToAnalog") ),
00034 thePixels(0),
00035 doTimeSmear_( p.getParameter<bool>("timeSmearing"))
00036 {
00037 if(p.exists("pixels"))
00038 {
00039 thePixels = p.getParameter<int>("pixels");
00040 }
00041 defaultTimeSmearing();
00042 }
00043
00044 double HcalSimParameters::simHitToPhotoelectrons(const DetId & detId) const
00045 {
00046
00047
00048 double result = CaloSimParameters::simHitToPhotoelectrons(detId);
00049 if(HcalGenericDetId(detId).genericSubdet() != HcalGenericDetId::HcalGenForward
00050 || HcalGenericDetId(detId).genericSubdet() != HcalGenericDetId::HcalGenZDC)
00051 {
00052 result = samplingFactor(detId) / fCtoGeV(detId) / photoelectronsToAnalog(detId);
00053 }
00054 return result;
00055 }
00056
00057
00058 double HcalSimParameters::fCtoGeV(const DetId & detId) const
00059 {
00060 assert(theDbService != 0);
00061 HcalGenericDetId hcalGenDetId(detId);
00062 const HcalGain* gains = theDbService->getGain(hcalGenDetId);
00063 const HcalGainWidth* gwidths = theDbService->getGainWidth(hcalGenDetId);
00064 if (!gains || !gwidths )
00065 {
00066 edm::LogError("HcalAmplifier") << "Could not fetch HCAL conditions for channel " << hcalGenDetId;
00067 }
00068
00069 double result = gains->getValue(0);
00070
00072
00073
00074 return result;
00075 }
00076
00077 double HcalSimParameters::samplingFactor(const DetId & detId) const
00078 {
00079 HcalDetId hcalDetId(detId);
00080 return theSamplingFactors.at(hcalDetId.ietaAbs()-theFirstRing);
00081 }
00082
00083
00084 double HcalSimParameters::photoelectronsToAnalog(const DetId & detId) const
00085 {
00086 HcalDetId hcalDetId(detId);
00087 return thePE2fCByRing.at(hcalDetId.ietaAbs()-theFirstRing);
00088 }
00089
00090
00091
00092 static const double GeV2fC = 1.0/0.4;
00093
00094 void HcalSimParameters::defaultTimeSmearing() {
00095
00096 theSmearSettings.push_back(std::pair<double,double>( 4.00*GeV2fC, 4.050));
00097 theSmearSettings.push_back(std::pair<double,double>( 20.00*GeV2fC, 3.300));
00098 theSmearSettings.push_back(std::pair<double,double>( 25.00*GeV2fC, 2.925));
00099 theSmearSettings.push_back(std::pair<double,double>( 30.00*GeV2fC, 2.714));
00100 theSmearSettings.push_back(std::pair<double,double>( 37.00*GeV2fC, 2.496));
00101 theSmearSettings.push_back(std::pair<double,double>( 44.50*GeV2fC, 2.278));
00102 theSmearSettings.push_back(std::pair<double,double>( 56.00*GeV2fC, 2.138));
00103 theSmearSettings.push_back(std::pair<double,double>( 63.50*GeV2fC, 2.022));
00104 theSmearSettings.push_back(std::pair<double,double>( 81.00*GeV2fC, 1.788));
00105 theSmearSettings.push_back(std::pair<double,double>( 88.50*GeV2fC, 1.695));
00106 theSmearSettings.push_back(std::pair<double,double>(114.50*GeV2fC, 1.716));
00107 theSmearSettings.push_back(std::pair<double,double>(175.50*GeV2fC, 1.070));
00108 theSmearSettings.push_back(std::pair<double,double>(350.00*GeV2fC, 1.564));
00109 theSmearSettings.push_back(std::pair<double,double>(99999.00*GeV2fC, 1.564));
00110 }
00111
00112 double HcalSimParameters::timeSmearRMS(double ampl) const {
00113 HcalTimeSmearSettings::size_type i;
00114 double smearsigma=0;
00115
00116 for (i=0; i<theSmearSettings.size(); i++)
00117 if (theSmearSettings[i].first > ampl)
00118 break;
00119
00120
00121 if (i!=0 && (i < theSmearSettings.size())) {
00122 double energy1 = theSmearSettings[i-1].first;
00123 double sigma1 = theSmearSettings[i-1].second;
00124 double energy2 = theSmearSettings[i].first;
00125 double sigma2 = theSmearSettings[i].second;
00126
00127 if (energy2 != energy1)
00128 smearsigma = sigma1 + ((sigma2-sigma1)*(ampl-energy1)/(energy2-energy1));
00129 else
00130 smearsigma = (sigma2+sigma1)/2.;
00131 }
00132
00133 return smearsigma;
00134
00135 }