00001 #include "FastShowerUtils/Normalisers/SmearSoftPhotonBase.h"
00002
00003 #include "FastShowerUtils/Normalisers/DistRandomiser1D.h"
00004 #include "FastShowerUtils/ParticleParameters.h"
00005 #include "FastShowerUtils/ISingleShowererSelectorConfig.h"
00006
00007 #include <float.h>
00008 #include <cmath>
00009 #include <iostream>
00010 namespace FastShower{
00011 SmearSoftPhotonBase::SmearSoftPhotonBase(const ISingleShowererSelectorConfig* c,
00012 const std::string& s):
00013 IFnOfParticleParameters(), DebugBase(s){
00014
00015
00016 cout<<"SmearSoftPhotonBase: getting histograms ..."<<endl;
00017 m_histograms = c->histograms();
00018
00019
00020 cout<<"SmearSoftPhotonBase: setting up distributions ..."<<endl;
00021 MCItr_Type1 itr = m_histograms.begin();
00022 MCItr_Type1 end = m_histograms.end();
00023 m_energyDists[0.0] = 0;
00024 for (;itr!=end; ++itr){
00025 cout<<"SmearSoftPhotonBase: hist = \""
00026 <<(*itr).second<<"\", energy = "<<(*itr).first<<"GeV"<<endl;
00027
00028 DistRandomiser1D* randomiser = new DistRandomiser1D((*itr).second);
00029
00030 m_energyDists[(*itr).first] = randomiser;
00031 }
00032 m_energyDists[FLT_MAX] = 0;
00033 cout<<"SmearSoftPhotonBase: distributions done"<<endl;
00034 }
00035
00036 double SmearSoftPhotonBase::value(const ParticleParameters& pp) const{
00037 double energy = pp.rawEnergy();
00038
00039 energy = max((float)energy,FLT_EPSILON);
00040
00041 MCItr_Type2 floor = m_energyDists.begin();
00042 MCItr_Type2 roof = m_energyDists.end();
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 std::pair<MCItr_Type2,MCItr_Type2> luItrs = m_energyDists.equal_range(energy);
00053 MCItr_Type2 lowerBound = luItrs.first;
00054 MCItr_Type2 upperBound = luItrs.second;
00055
00056
00057 if (lowerBound==upperBound) {--lowerBound;}
00058
00059 MCItr_Type2 mapEntryPoint = ((energy - (*lowerBound).first)<
00060 ((*upperBound).first - energy))?
00061 lowerBound : upperBound;
00062
00063
00064 if (mapEntryPoint == floor) {++mapEntryPoint;}
00065
00066
00067
00068 MCItr_Type2 ceiling = --roof;
00069 assert(mapEntryPoint != ceiling);
00070
00071 DistRandomiser1D* randomiser = (*mapEntryPoint).second;
00072 double energyPoint = (*mapEntryPoint).first;
00073 double eFrac = randomiser->sample();
00074 nudge(energyPoint,energy,eFrac);
00075 return eFrac;
00076 }
00077
00078 void
00079 SmearSoftPhotonBase::nudge(const double energyPoint,
00080 const double energy, double& eFrac) const {
00081
00082 eFrac += (mean(energy) - mean(energyPoint));
00083 }
00084
00085 SmearSoftPhotonBase::~SmearSoftPhotonBase(){
00086 m_histograms.clear();
00087 std::map<double,DistRandomiser1D*>::iterator itr2 = m_energyDists.begin();
00088 std::map<double,DistRandomiser1D*>::iterator end2 = m_energyDists.end();
00089 for(; itr2!= end2; ++itr2){
00090 delete (*itr2).second;
00091 }
00092 m_energyDists.clear();
00093 }
00094 }
00095
00096
00097