00001
00002
00003
00004
00005
00006
00007 #include <functional>
00008 #include <algorithm>
00009
00010
00011
00012 #include "GaudiKernel/AlgFactory.h"
00013 #include "GaudiKernel/IRndmGenSvc.h"
00014 #include "GaudiKernel/RndmGenerators.h"
00015 #include "GaudiKernel/SystemOfUnits.h"
00016 #include "GaudiKernel/Point3DTypes.h"
00017
00018
00019
00020 #include "DetDesc/ITransportSvc.h"
00021
00022
00023
00024 #include "MaterialBudgetAlg.h"
00025
00026
00027
00028 #include "boost/progress.hpp"
00029
00030
00031
00039
00040
00041
00045
00046 DECLARE_ALGORITHM_FACTORY(MaterialBudgetAlg)
00047
00048
00049
00054
00055 MaterialBudgetAlg::MaterialBudgetAlg
00056 ( const std::string& name ,
00057 ISvcLocator* svc )
00058 : GaudiHistoAlg ( name , svc )
00059 , m_trSvcName ( "TransportSvc" )
00060 , m_trSvc ( 0 )
00061 , m_vrtx ( 3 , 0.0 )
00062 , m_vertex ( )
00063 , m_shots ( 1000 )
00064 , m_z ( 12 * Gaudi::Units::meter )
00065 , m_xMax ( 4 * Gaudi::Units::meter )
00066 , m_yMax ( 3 * Gaudi::Units::meter )
00067 , m_xMin ( 0 * Gaudi::Units::meter )
00068 , m_yMin ( 0 * Gaudi::Units::meter )
00069 , m_etaMax ( 5.5 )
00070 , m_phiMax ( 270. )
00071 , m_etaMin ( 2.0 )
00072 , m_phiMin ( 90. )
00073 , m_nbx ( 360 )
00074 , m_nby ( 300 )
00075 , m_grid ( 0 )
00076 , m_psrap ( 0 )
00077 , m_xbinref ( 20.0 )
00078 , m_ybinref ( 20.0 )
00079 , m_zref ( 10000.0 )
00080 {
00081 declareProperty( "TransportService" , m_trSvcName ) ;
00082 declareProperty( "ShootingPoint" , m_vrtx ) ;
00083 declareProperty( "Shots" , m_shots ) ;
00084 declareProperty( "zPlane" , m_z ) ;
00085 declareProperty( "xMax" , m_xMax ) ;
00086 declareProperty( "xMin" , m_xMin ) ;
00087 declareProperty( "yMax" , m_yMax ) ;
00088 declareProperty( "yMin" , m_yMin ) ;
00089 declareProperty( "etaMax" , m_etaMax ) ;
00090 declareProperty( "etaMin" , m_etaMin ) ;
00091 declareProperty( "phiMax" , m_phiMax ) ;
00092 declareProperty( "phiMin" , m_phiMin ) ;
00093 declareProperty( "nBx" , m_nbx ) ;
00094 declareProperty( "nBy" , m_nby ) ;
00095 declareProperty( "Grid" , m_grid ) ;
00096 declareProperty( "Rapidity" , m_psrap ) ;
00097 declareProperty( "xbinref" , m_xbinref ) ;
00098 declareProperty( "ybinref" , m_ybinref ) ;
00099 declareProperty( "zref" , m_zref ) ;
00100 };
00101
00102
00103
00104
00105
00106 MaterialBudgetAlg::~MaterialBudgetAlg() {};
00107
00108
00109
00115
00116 StatusCode MaterialBudgetAlg::initialize()
00117 {
00118 StatusCode sc = GaudiHistoAlg::initialize() ;
00119 if ( sc.isFailure() ) { return sc ; }
00120
00121 m_trSvc = svc<ITransportSvc> ( m_trSvcName , true ) ;
00122
00123 Assert ( 0 != randSvc() , "IRndmGenSvc* poitns to NULL!" );
00124
00125
00126 if ( m_vrtx.size() <= 3 )
00127 { while( 3 != m_vrtx.size() ) { m_vrtx.push_back( 0.0 ); } }
00128 else
00129 { warning() << " Ignore extra fields in 'ShootingPoint' "<< endreq ; }
00130 m_vertex.SetXYZ( m_vrtx[0], m_vrtx[1], m_vrtx[2] ) ;
00131
00132
00133 if ( m_xMin > m_xMax ) { std::swap( m_xMin , m_xMax ) ; }
00134 if ( m_yMin > m_yMax ) { std::swap( m_yMin , m_yMax ) ; }
00135
00136 if ( 0 >= m_nbx ) { m_nbx = 50 ; }
00137 if ( 0 >= m_nby ) { m_nby = 50 ; }
00138
00139 if ( m_grid != 0 && m_psrap != 0 )
00140 {
00141 return Error(" Asked for X-Y and Eta-Phi scans ");
00142 }
00143
00144
00145 if ( m_grid )
00146 {
00147 m_xMin=-(m_xbinref*m_nbx*m_z)/(2.0*m_zref);
00148 m_yMin=-(m_ybinref*m_nby*m_z)/(2.0*m_zref);
00149 m_xMax=-m_xMin;
00150 m_yMax=-m_yMin;
00151 }
00152
00153 if ( m_psrap)
00154 {
00155 m_xMin=m_etaMin;
00156 m_yMin=m_phiMin;
00157 m_xMax=m_etaMax;
00158 m_yMax=m_phiMax;
00159 }
00160
00161 return StatusCode::SUCCESS;
00162 };
00163
00164
00165
00171
00172 StatusCode MaterialBudgetAlg::execute()
00173 {
00174
00175 if ( m_grid ) { return makeGridShots () ; }
00176 else if ( m_psrap ) { return makePsrapShots () ; }
00177
00178 return makeRandomShots() ;
00179 };
00180
00181
00182
00184
00185 StatusCode MaterialBudgetAlg::makeRandomShots()
00186 {
00187
00188
00189 Rndm::Numbers x ( randSvc() , Rndm::Flat( m_xMin , m_xMax ) );
00190 Rndm::Numbers y ( randSvc() , Rndm::Flat( m_yMin , m_yMax ) );
00191
00192
00193 boost::progress_display progress ( m_shots ) ;
00194 for ( int shot = 0 ; shot < m_shots ; ++shot , ++progress )
00195 {
00196
00197 const Gaudi::XYZPoint point( x() , y() , m_z );
00198
00199 const double dist =
00200 m_trSvc -> distanceInRadUnits ( m_vertex , point );
00201
00202
00203 plot2D ( point.x() , point.y() ,
00204 1 , "Material Budget" ,
00205 m_xMin , m_xMax ,
00206 m_yMin , m_yMax ,
00207 m_nbx , m_nby ,
00208 dist ) ;
00209
00210 plot2D ( point.x() , point.y() ,
00211 2 , "Budget Normalization" ,
00212 m_xMin , m_xMax ,
00213 m_yMin , m_yMax ,
00214 m_nbx , m_nby ) ;
00215
00216 }
00217
00218 return StatusCode::SUCCESS ;
00219 };
00220
00221
00222
00224
00225 StatusCode MaterialBudgetAlg::makeGridShots()
00226 {
00227 if ( !m_grid ) { return StatusCode::FAILURE ; }
00228
00229
00230 const double dxgrid = m_xbinref * m_z / m_zref;
00231 const double dygrid = m_ybinref * m_z / m_zref;
00232
00233
00234
00235
00237 boost::progress_display progress( m_nbx * m_nby ) ;
00238
00239 for ( double y = m_yMin + dygrid/2 ; y <= m_yMax ; y += dygrid )
00240 {
00241 for ( double x = m_yMin + dxgrid/2 ; x <= m_xMax ; x += dxgrid )
00242 {
00243
00244 const Gaudi::XYZPoint point ( x, y, m_z);
00245
00246
00247 const double dist =
00248 m_trSvc -> distanceInRadUnits ( m_vertex , point );
00249
00250
00251 plot2D ( point.x() , point.y() ,
00252 1 , "Material Budget" ,
00253 m_xMin , m_xMax ,
00254 m_yMin , m_yMax ,
00255 m_nbx , m_nby ,
00256 dist ) ;
00257
00258 plot2D ( point.x() , point.y() ,
00259 2 , "Budget Normalization" ,
00260 m_xMin , m_xMax ,
00261 m_yMin , m_yMax ,
00262 m_nbx , m_nby ) ;
00263
00264
00265 ++progress ;
00266 }
00267 }
00268
00269 return StatusCode::SUCCESS ;
00270 } ;
00271
00272
00273
00274
00276
00277 StatusCode MaterialBudgetAlg::makePsrapShots()
00278 {
00279 if ( !m_psrap ) { return StatusCode::FAILURE ; }
00280
00281
00282 const double dxgrid = (m_xMax-m_xMin)/m_nbx;
00283 const double dygrid = (m_yMax-m_yMin)/m_nby;
00284
00286 boost::progress_display progress ( m_nbx * m_nby ) ;
00287 for ( double yy = m_yMin + dygrid/2 ; yy <= m_yMax ; yy += dygrid )
00288 {
00289 for ( double xx = m_yMin + dxgrid/2 ; xx <= m_xMax ; xx += dxgrid )
00290 {
00291 const double theta = 2.0*atan(exp(-1.0*xx));
00292 const double phi = yy*Gaudi::Units::degree;
00293
00294 const double x = sin(theta)*cos(phi)*m_z/cos(theta);
00295 const double y = sin(theta)*sin(phi)*m_z/cos(theta);
00296
00297
00298 const Gaudi::XYZPoint point( x, y, m_z);
00299
00300
00301 const double dist =
00302 m_trSvc -> distanceInRadUnits( m_vertex , point );
00303
00304
00305 plot2D ( xx , yy ,
00306 1 , "Material Budget" ,
00307 m_xMin , m_xMax ,
00308 m_yMin , m_yMax ,
00309 m_nbx , m_nby ,
00310 dist ) ;
00311
00312 plot2D ( x , y ,
00313 2 , "Material Budget Check" ,
00314 -600 , 600 ,
00315 -600 , 600 ,
00316 m_nbx , m_nby ) ;
00317
00318
00319 ++progress ;
00320 }
00321 }
00322
00323 return StatusCode::SUCCESS ;
00324 } ;
00325
00326
00327
00328
00329