Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #include "SimCalorimetry/HcalSimAlgos/interface/HPDIonFeedbackSim.h"
00013 #include "SimCalorimetry/HcalSimAlgos/interface/HcalShape.h"
00014 #include "CondFormats/HcalObjects/interface/HcalGain.h"
00015 #include "CondFormats/HcalObjects/interface/HcalGainWidth.h"
00016 #include "DataFormats/HcalDetId/interface/HcalGenericDetId.h"
00017 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00018 #include "FWCore/Utilities/interface/RandomNumberGenerator.h"
00019 #include "FWCore/ServiceRegistry/interface/Service.h"
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 #include "FWCore/PluginManager/interface/PluginManager.h"
00022 #include "FWCore/PluginManager/interface/standard.h"
00023
00024
00025 using namespace edm;
00026 using namespace std;
00027
00028
00029 double pe2Charge = 0.333333;
00030
00031 HPDIonFeedbackSim::HPDIonFeedbackSim(const edm::ParameterSet & iConfig)
00032 : theDbService(0), theShape(0),
00033 theRandBinomial(0), theRandFlat(0), theRandGauss(0), theRandPoissonQ(0)
00034 {
00035 }
00036
00037 HPDIonFeedbackSim::~HPDIonFeedbackSim()
00038 {
00039 if(theRandBinomial) delete theRandBinomial;
00040 if (theRandFlat) delete theRandFlat;
00041 if (theRandGauss) delete theRandGauss;
00042 if (theRandPoissonQ) delete theRandPoissonQ;
00043 }
00044
00045
00046 void HPDIonFeedbackSim::setRandomEngine(CLHEP::HepRandomEngine & engine)
00047 {
00048 if(theRandBinomial) delete theRandBinomial;
00049 if (theRandFlat) delete theRandFlat;
00050 if (theRandGauss) delete theRandGauss;
00051 if (theRandPoissonQ) delete theRandPoissonQ;
00052
00053 theRandBinomial = new CLHEP::RandBinomial(engine);
00054 theRandFlat = new CLHEP::RandFlat(engine);
00055 theRandGauss = new CLHEP::RandGaussQ(engine);
00056 theRandPoissonQ = new CLHEP::RandPoissonQ(engine);
00057 }
00058
00059 double HPDIonFeedbackSim::getIonFeedback(DetId detId, double signal, double pedWidth, bool doThermal, bool isInGeV)
00060 {
00061
00062 HcalDetId id = detId;
00063
00064 double GeVperfC = 1.;
00065 if(isInGeV) GeVperfC = 1./fCtoGeV(detId);
00066
00067 double charge = signal / GeVperfC;
00068
00069 double noise = 0.;
00070 if (charge > 3. * pedWidth) {
00071 int npe = int (charge / pe2Charge);
00072 if(doThermal) {
00073 double electronEmission = 0.08;
00074 npe += theRandPoissonQ->fire(electronEmission);
00075 }
00076
00077 noise = correctPE(detId, npe) - npe;
00078 }
00079 return (noise * GeVperfC);
00080
00081 }
00082
00083
00084 double HPDIonFeedbackSim::correctPE(const DetId & detId, double npe) const
00085 {
00086 double rateInTail = 0.000211988;
00087 double rateInSecondTail = 4.61579e-06;
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098 double p4 = 2.06117e+01;
00099 double p5 = 1.09239e+01;
00100
00101
00102
00103 double p7 = 5.45548e+01;
00104 double p8 = 1.59696e+01;
00105
00106 double noise = 0.;
00107 int nFirst = (int)(theRandBinomial->fire(npe, rateInTail));
00108 int nSecond = (int)(theRandBinomial->fire(npe, rateInSecondTail));
00109
00110 for (int j = 0; j < nFirst; ++j) {
00111 noise += theRandGauss->fire(p4, p5);
00112 }
00113 for (int j = 0; j < nSecond; ++j) {
00114 noise += theRandGauss->fire(p7, p8);
00115 }
00116
00117 return npe + std::max(noise/pe2Charge, 0.);
00118 }
00119
00120
00121 void HPDIonFeedbackSim::addThermalNoise(CaloSamples & samples)
00122 {
00123
00124
00125 double meanPE = 0.02;
00126 DetId detId(samples.id());
00127 int nSamples = samples.size();
00128 for(int i = 0; i < nSamples; ++i)
00129 {
00130 double npe = theRandPoissonQ->fire(meanPE);
00131
00132 if(npe > 0.)
00133 {
00134
00135 npe = correctPE(detId, npe);
00136 for(int j = i; j < nSamples; ++j)
00137 {
00138 double timeFromPE = (j-i) * 25.;
00139 samples[j] += (*theShape)(timeFromPE) * npe;
00140 }
00141 }
00142 }
00143 }
00144
00145
00146 double HPDIonFeedbackSim::fCtoGeV(const DetId & detId) const
00147 {
00148 assert(theDbService != 0);
00149 HcalGenericDetId hcalGenDetId(detId);
00150 const HcalGain* gains = theDbService->getGain(hcalGenDetId);
00151 const HcalGainWidth* gwidths = theDbService->getGainWidth(hcalGenDetId);
00152 if (!gains || !gwidths )
00153 {
00154 edm::LogError("HcalAmplifier") << "Could not fetch HCAL conditions for channel " << hcalGenDetId;
00155 }
00156
00157 double result = gains->getValue(0);
00158 return result;
00159 }