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

PSFanalysis.cxx

Go to the documentation of this file.
00001 // PSFanalysis.cxx
00002 // June 12, 2001 - rename variables to TKR_...  TU
00003 
00004 #include "PSFanalysis.h"
00005 
00006 #include <cmath>
00007 #include <iomanip>
00008 
00009 using namespace std;
00010 
00011 inline static double sqr(double x){return x*x;}
00012 
00013 PSFanalysis::PSFanalysis(const Tuple& t, double emin, double emax)
00014         : Analyze(t, "MC_Gamma_Err" , "PSF analysis" )
00015         , RebinHist("PSF", 0, 3.0, 0.1 )
00016         , m_sigma(-1)
00017         , m_energy(t, "MC_Energy", "energy")
00018         , m_first_layer(t, "TKR_First_XHit", "first hit layer")
00019         , m_emin(emin), m_emax(emax)
00020 {}
00021 
00022 bool  PSFanalysis::apply ()
00023 {
00024 
00025     m_energy();
00026     double e = m_energy.item();
00027     if( m_emax > m_emin && (e < m_emin || e>m_emax)) return true;
00028     m_loge += log(e);
00029 
00030     double  theta_squared = sqr(item());
00031     fill(theta_squared);
00032 
00033     return true;
00034 }
00035 void PSFanalysis::clear()
00036 {
00037     Analyze::clear();
00038     RebinHist::clear();
00039     m_sigma = -1;
00040 }
00041 
00042 unsigned PSFanalysis::count () const
00043 {
00044     return static_cast<unsigned int>(Histogram::total()) ;
00045 }
00046 
00047 
00048 double PSFanalysis::percentile(double percent)
00049 {
00050     return sqrt(RebinHist::percentile(percent));
00051 }
00052 double PSFanalysis::sigma()
00053 {
00054     if( m_sigma >=0) return m_sigma;
00055 
00056     // rebin according to mean
00057     double mean = Histogram::mean();
00058     double binsize = mean/25;
00059     RebinHist::rebin(0, 200*binsize, binsize);
00060         //out << "Sigma from mean: " << 0.5*sqrt(mean) << '\n';
00061 
00062     // make sure first bin not too full (less than 20% of total)
00063     while( (*this)[0] > 0.2* Histogram::total() && binsize>1e-6) {
00064         binsize *= 0.5;
00065         RebinHist::rebin(0, 200*binsize, binsize);
00066     }
00067         //out << "\nHistogram (binsize= " << binsize << ')';
00068         //for(int i=0; i<20;i++) out << m_psf_hist[i] << ", "; out << "...\n";
00069         
00070     // form estimate of sigma (effective) from sum of bin contents squared
00071     Histogram::const_iterator h = Histogram::begin();
00072     double sum1=0, sum2=0;
00073     for(; h != Histogram::end(); ++h) {
00074             sum1 += *h;
00075             sum2 += sqr(*h);
00076     }
00077     return  (m_sigma =sum1*sqrt(Histogram::step() / sum2 )/2.0 );
00078 }
00079 
00080 void PSFanalysis::report(ostream& out)
00081 {
00082     if( Histogram::total()==0 ) return;
00083 
00084     // calculate stuff we need
00085     double sig = sigma();
00086     double ang68 = percentile(68);
00087     double ang95 = percentile(95);
00088 
00089     if( m_emax > m_emin) {
00090         out << endl << Analyze::make_label("PSF:            Events")
00091             << setw(6)<< setprecision(6)<< Histogram::total() ;
00092         out << endl << Analyze::make_label("exp<log(E)>") 
00093             << setprecision(3)<<setw(6) << exp(m_loge.mean()) << " GeV";
00094     }
00095 
00096     out << "\n" << Analyze::make_label("eff. proj. sigma")
00097         << setw(6) << setprecision(3)
00098         << sig*180/3.14159 << " deg = "
00099         << sigma()*180*60/3.14159 << " arc-min";
00100 
00101     out <<  "\n" << Analyze::make_label("68% contained")
00102         << setw(6) << ang68*180/3.14159 << " deg = "
00103         << setw(4) << ang68/sig/1.51 << "*(1.51*sigma)" ;
00104 
00105     out << "\n" << Analyze::make_label("95% contained")
00106         << setw(6) << ang95*180/3.14159 << " deg = "
00107         << setw(4) << ang95/sig/2.447 << "*(2.45*sigma)" ;
00108 
00109 }
00110 void PSFanalysis::row_report(ostream&out)
00111 {
00112     out << '\n';
00113     out<< setprecision(6)<< Histogram::total()  << '\t' ;
00114     if( Histogram::total()>10) {
00115         out << setw(6) << setprecision(3)
00116             << exp(m_loge.mean()) << '\t' 
00117             << sigma()*180/3.14159    << '\t'
00118             << percentile(68)*180/3.14159  << '\t'
00119             << percentile(95)*180/3.14159;
00120     }
00121 }

Generated at Wed Nov 21 12:20:39 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000