00001
00002 #include "FastShowerUtils/Gridlet.h"
00003
00004 #include "FastShowerUtils/Phi.h"
00005 #include <iostream>
00006 #include <iomanip>
00007 #include <numeric>
00008 #include <iterator>
00009 #include <algorithm>
00010 namespace FastShower{
00011
00012 const double Gridlet::s_etaStep(0.1);
00013 const double Gridlet::s_phiStep(0.1);
00015 Gridlet::Gridlet(double eta, double phi):
00016 m_eta0 ( eta ),
00017 m_phi0 ( phi ),
00018 m_eDeps ( DepositsType() ),
00019 m_hDeps ( DepositsType() ),
00020 m_eDepIters( m_eDeps.begin(), m_eDeps.end() ),
00021 m_hDepIters( m_hDeps.begin(), m_hDeps.end() )
00022 {
00023 }
00025 double Gridlet::phi0() const { return m_phi0;}
00027 double Gridlet::eta0() const { return m_eta0;}
00029 double Gridlet::phi(int index) const {
00030 int dim = this->dimension();
00031 return Phi( m_phi0 +((index/dim) - (dim/2) )*s_phiStep);
00032 }
00034 double Gridlet::eta(int index) const {
00035 int dim = this->dimension();
00036 return (m_eta0 +((index%dim) - (dim/2) )*s_etaStep);
00037 }
00039 class FillGridletElementVector{
00040 public:
00041 FillGridletElementVector(const Gridlet* g): m_g(g), m_ind(0){}
00042 void operator()(double e){
00043
00044 if(e > 0.){
00045 m_elements.push_back(
00046 new GridletElement(m_g->phi(m_ind),
00047 m_g->eta(m_ind),
00048 e
00049 )
00050 );
00051 }
00052 ++m_ind;
00053 }
00054 std::vector<GridletElement*> elements() const {return m_elements;}
00055 private:
00056 const Gridlet* m_g;
00057 int m_ind;
00058 std::vector<GridletElement*> m_elements;
00059 };
00060
00062 std::vector<GridletElement*> Gridlet::eElements() const {
00063
00064 DepIterPair dip = this->eIters();
00065
00066 FillGridletElementVector fv( this);
00067
00068 return ( (std::for_each(dip.first, dip.second, fv)).elements() );
00069 }
00071 std::vector<GridletElement*> Gridlet::hElements() const {
00072
00073 DepIterPair dip = this->hIters();
00074
00075 FillGridletElementVector fv( this);
00076
00077 return ( (std::for_each(dip.first, dip.second, fv)).elements() );
00078 }
00081 double Gridlet::eSumE() const{
00082 double sum = 0.0;
00083 std::vector<GridletElement*> elements = eElements();
00084 std::vector<GridletElement*>::const_iterator itr, end;
00085 itr = elements.begin();
00086 end = elements.end();
00087 while (itr != end)
00088 sum += (*itr++)->e();
00089 return sum;
00090 }
00091 double Gridlet::hSumE() const{
00092 double sum = 0.0;
00093 std::vector<GridletElement*> elements = hElements();
00094 std::vector<GridletElement*>::const_iterator itr, end;
00095 itr = elements.begin();
00096 end = elements.end();
00097 while (itr != end)
00098 sum += (*itr++)->e();
00099 return sum;
00100 }
00101
00103 double Gridlet::eSumEt() const{
00104 double sum = 0.0;
00105 std::vector<GridletElement*> elements = eElements();
00106 std::vector<GridletElement*>::const_iterator itr, end;
00107 itr = elements.begin();
00108 end = elements.end();
00109 while (itr != end)
00110 sum += (*itr++)->et();
00111 return sum;
00112 }
00113 double Gridlet::hSumEt() const{
00114 double sum = 0.0;
00115 std::vector<GridletElement*> elements = hElements();
00116 std::vector<GridletElement*>::const_iterator itr, end;
00117 itr = elements.begin();
00118 end = elements.end();
00119 while (itr != end)
00120 sum += (*itr++)->et();
00121 return sum;
00122 }
00123
00124
00125
00126 std::ostream& operator<<(ostream& out, Gridlet& g){
00127 int dim = g.dimension();
00128
00129 class PrintLine{
00130 public:
00131 std::ostream& operator()(Gridlet::DepositsType::ConstIter iter,
00132 int dim,
00133 std::ostream& out){
00134 out<<setiosflags(ios::fixed);
00135 for(;dim !=0; --dim){ out<<setw(8)<<setprecision(3)<<*iter++<<" ";}
00136 out<<endl;
00137 return out;
00138 }
00139 };
00140
00141
00142 double sumE = std::accumulate(g.eIters().first, g.eIters().second, 0.0);
00143
00144
00145 double sumH = std::accumulate(g.hIters().first, g.hIters().second, 0.0);
00146
00147
00148 int row;
00149 out<<setw(8);
00150 out<<setprecision(3);
00151
00152 PrintLine p;
00153
00154 Gridlet::DepositsType::ConstIter iter;
00155
00156 out<<" phi"<<endl;
00157 out<<" ^"<<endl;
00158 out<<" |"<<endl;
00159 out<<" |"<<endl;
00160 out<<" ---> eta "<<endl;
00161
00162 out<<endl<<"Hit cell: phi, eta "<<g.phi0()<<" "<<g.eta0()<<" "<<endl;
00163 out<<endl<<"Ecal: E/Et sum = "<<sumE<<" / "<<g.eSumEt()<<endl<<endl;
00164
00165 iter = g.eIters().second;
00166 for(row=dim; row!=0; --row){
00167 std::advance( iter, -dim);
00168 p(iter, dim, out);
00169
00170 }
00171
00172
00173 out<<endl<<"Hcal: E/Et sum = "<<sumH<<" / "<<g.hSumEt()<<endl<<endl;
00174
00175 iter = g.hIters().second;
00176 for(row=dim; row!=0; --row){
00177 std::advance( iter, -dim);
00178 p(iter, dim, out);
00179
00180 }
00181
00182 out<<"============================================="<<endl;
00183 out<<endl;
00184 return out;
00185 }
00187 std::ostream& operator<<(ostream& out, Gridlet* g){
00188 out<<*g;
00189 return out;
00190 }
00192
00193
00194 }
00195
00196
00197
00198