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

HadEcalHcalSharesBase.cxx

Go to the documentation of this file.
00001 #include "FastShowerUtils/Normalisers/HadEcalHcalSharesBase.h"
00002 
00003 #include "FastShowerUtils/Normalisers/DistRandomiser2D.h"
00004 #include "FastShowerUtils/ParticleParameters.h"
00005 //#include "FastShowerUtils/IDoubleShowererSelectorConfig.h"
00006 #include "FastShowerUtils/ITripleShowererSelectorConfig.h"
00007 
00008 #include <float.h>
00009 #include <cmath>
00010 #include <iostream>
00011 namespace FastShower{
00012   //
00013   //HadEcalHcalSharesBase::HadEcalHcalSharesBase(const IDoubleShowererSelectorConfig* c, 
00014   //                                             const std::string& s):
00015   HadEcalHcalSharesBase::HadEcalHcalSharesBase(const ITripleShowererSelectorConfig* c, 
00016                                                const std::string& s):
00017     IFnOfParticleParameters2(), DebugBase(s){
00018 
00019     // get histograms' file-names and energies
00020     cout<<"HadEcalHcalSharesBase: getting histograms ..."<<endl;
00021     m_histograms = c->histograms();
00022 
00023     // loop through files, and setup 2d-dist-randomiser
00024     cout<<"HadEcalHcalSharesBase: setting up distributions ..."<<endl;
00025     MCItr_Type1 itr = m_histograms.begin();
00026     MCItr_Type1 end = m_histograms.end();
00027     m_energyDists[0.0] = 0;  // null pointers for end-points
00028     for (;itr!=end; ++itr){
00029       cout<<"HadEcalHcalSharesBase:  hist = \""
00030           <<(*itr).second<<"\",  energy = "<<(*itr).first<<"GeV"<<endl;
00031       // pass histogram-file-name to 2d-dist-randomiser
00032       DistRandomiser2D* randomiser = new DistRandomiser2D((*itr).second);
00033       // set the corresponding energy (energy point)
00034       m_energyDists[(*itr).first] = randomiser;
00035     }
00036     m_energyDists[FLT_MAX] = 0;  // null pointers for end-points
00037     cout<<"HadEcalHcalSharesBase: distributions done"<<endl;
00038   }
00039   //
00040   std::pair<double,double> 
00041   HadEcalHcalSharesBase::value(const ParticleParameters& pp) const {
00042     double energy = pp.rawEnergy();
00043     
00044     energy = max((float)energy, FLT_EPSILON);
00045 
00046     MCItr_Type2 floor = m_energyDists.begin();
00047     MCItr_Type2 roof  = m_energyDists.end();
00048 
00049     /* 
00050      * usual case: energy differs from key values in the map => lower==upper
00051      * rare case: energy overlaps with a key entry in the map => lower==upper-1
00052      * energies below/above the floor/roof  =>  valid iterators
00053      * energies overlapping with an energyPoint (i.e. a key) are special!
00054      */
00055 
00056     // the following logic works only if the map has at least 3 entries, 
00057     // i.e. at least 1 valid entry
00058     std::pair<MCItr_Type2,MCItr_Type2> luItrs = m_energyDists.equal_range(energy);
00059     MCItr_Type2 lowerBound = luItrs.first;
00060     MCItr_Type2 upperBound = luItrs.second;
00061 
00062     // force the lower/upperBound iterators to point at 2 consecutive entries
00063     if (lowerBound==upperBound) {--lowerBound;}  // takes care of the usual case
00064     // find the closest boundary
00065     MCItr_Type2 mapEntryPoint = ((energy - (*lowerBound).first)<
00066                          ((*upperBound).first - energy))? 
00067       lowerBound : upperBound;
00068 
00069     // move up to the 1st valid point if energy is between 0 and the 1st valid point
00070     if (mapEntryPoint == floor) {++mapEntryPoint;}
00071 
00072     // check for strange condition that energy is closer to FLT_MAX 
00073     // than to the last valid point
00074     MCItr_Type2 ceiling = --roof;
00075     assert(mapEntryPoint != ceiling);
00076 
00077     DistRandomiser2D* randomiser = (*mapEntryPoint).second;
00078     double energyPoint = (*mapEntryPoint).first;
00079     std::pair<double,double> ehFracs = randomiser->sample();
00080 
00081     nudge(energyPoint,energy,ehFracs);
00082 
00083     return ehFracs;
00084   }
00085   //
00086   void HadEcalHcalSharesBase::nudge(const double energyPoint, 
00087                                     const double energy,
00088                                     std::pair<double,double>& ehFracs) const {
00089 
00090     double energyPointFracSum = ehFracs.first + ehFracs.second;
00091     double energyFracSum = energyPointFracSum;
00092     
00093     if (energy<=0.15) {
00094     // no interpolation at very small Energies
00095     } else if (energy<=1.0) {
00096     // interpolate mean but not sigma
00097       energyFracSum = energyPointFracSum - mean(energyPoint) + mean(energy);
00098     } else {
00099     // interpolate both mean and sigma
00100       double sigmaScale = sigma(energy)/sigma(energyPoint);
00101       energyFracSum = (energyPointFracSum - mean(energyPoint))*sigmaScale 
00102                      + mean(energy);
00103     }
00104     ehFracs.first *= (energyFracSum/energyPointFracSum);
00105     ehFracs.second *= (energyFracSum/energyPointFracSum);
00106   }
00107   //
00108   HadEcalHcalSharesBase::~HadEcalHcalSharesBase(){
00109     std::map<double, DistRandomiser2D*>::iterator itr = m_energyDists.begin();
00110     std::map<double, DistRandomiser2D*>::iterator end = m_energyDists.end();
00111     for(; itr!= end; ++itr){
00112       delete (*itr).second;
00113     }
00114     m_energyDists.clear();
00115   }
00116 }//namespace
00117 
00118 

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