Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

SmearSoftPhotonBase.cxx

Go to the documentation of this file.
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     // get histograms' file-names and energies
00016     cout<<"SmearSoftPhotonBase: getting histograms ..."<<endl;
00017     m_histograms = c->histograms();
00018 
00019     // loop through files, and setup 1d-dist-randomiser
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;  // null pointers for end-points
00024     for (;itr!=end; ++itr){
00025       cout<<"SmearSoftPhotonBase:  hist = \""
00026           <<(*itr).second<<"\",  energy = "<<(*itr).first<<"GeV"<<endl;
00027       // pass histogram-file-name to 1d-dist-randomiser
00028       DistRandomiser1D* randomiser = new DistRandomiser1D((*itr).second);
00029       // set the corresponding energy (energy point)
00030       m_energyDists[(*itr).first] = randomiser;
00031     }
00032     m_energyDists[FLT_MAX] = 0;  // null pointers for end-points
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      * usual case: energy differs from key values in the map => lower==upper
00045      * rare case: energy overlaps with a key entry in the map => lower==upper-1
00046      * energies below/above the floor/roof  =>  valid iterators
00047      * energies overlapping with an energyPoint (i.e. a key) are special!
00048      */
00049 
00050     // the following logic works only if the map has at least 3 entries, 
00051     // i.e. at least 1 valid entry
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     // force the lower/upperBound iterators to point at 2 consecutive entries
00057     if (lowerBound==upperBound) {--lowerBound;}  // takes care of the usual case
00058     // find the closest boundary
00059     MCItr_Type2 mapEntryPoint = ((energy - (*lowerBound).first)<
00060                          ((*upperBound).first - energy))? 
00061       lowerBound : upperBound;
00062 
00063     // move up to the 1st valid point if energy is between 0 and the 1st valid point
00064     if (mapEntryPoint == floor) {++mapEntryPoint;}
00065 
00066     // check for strange condition that energy is closer to FLT_MAX 
00067     // than to the last valid point
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     // interpolation
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 }//namespace
00095 
00096 
00097 

Generated on Tue Mar 18 11:50:05 2003 for FastShowerUtils by doxygen1.3-rc1