00001
00002
00003
00004
00005
00006
00007
00009
00010
00011
00012 #include <mMuiResponse.h>
00013 #include <mMuiResponsePar.h>
00014 #include <TMuiMCHitMapO.h>
00015 #include <TMutMCTrkMap.h>
00016 #include <TMuiHitMapO.h>
00017 #include <TMutNode.h>
00018 #include <PHException.h>
00019 #include <MUIOO.h>
00020 #include <PHTimer.h>
00021 #include <TMutGeo.h>
00022 #include <TMuiHVMask.h>
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include <iostream>
00032 #include <string>
00033 #include <gsl/gsl_randist.h>
00034
00038 mMuiResponse::mMuiResponse() :
00039 _rng(0),
00040 _timer( PHTimeServer::get()->insert_new( "mMuiResponse" ) )
00041 {
00042 name = "mMuiResponse";
00043 MUIOO::TRACE("initializing module " + std::string(name.getString()));
00044 }
00045
00046
00047
00048 mMuiResponse::~mMuiResponse() { }
00049
00050
00051
00052 PHBoolean mMuiResponse::event(PHCompositeNode* top_node)
00053 {
00054 _timer.get()->restart();
00055 try {
00056
00057
00058 set_interface_ptrs(top_node);
00059
00060
00061
00062
00063 static bool rng_initialized = initialize_rng();
00064 if(rng_initialized != true) throw std::runtime_error(DESCRIPTION("mMuiResponse::event: failed to initialize rng"));
00065
00066
00067
00068 response_loop();
00069
00070 } catch(std::exception& e) {
00071 MUIOO::TRACE(e.what());
00072 return False;
00073 }
00074
00075
00076 _timer.get()->stop();
00077 if(_mod_par->get_verbosity() >= MUIOO::ALOT) _hit_map->print();
00078 if(_mod_par->get_verbosity() >= MUIOO::SOME) _timer.get()->print();
00079 return True;
00080 }
00081
00083 void
00084 mMuiResponse::set_interface_ptrs(PHCompositeNode* top_node)
00085 {
00086
00087
00088 _mod_par = TMutNode<mMuiResponsePar>::find_node(top_node,"mMuiResponsePar");
00089
00090
00091
00092 _mc_hit_map = TMutNode<TMuiMCHitMapO>::find_node(top_node,"TMuiMCHitMapO");
00093 _mc_trk_map = TMutNode<TMutMCTrkMap>::find_node(top_node,"TMutMCTrkMap");
00094 _hit_map = TMutNode<TMuiHitMapO>::find_node(top_node,"TMuiHitMapO");
00095 }
00096
00097 void
00098 mMuiResponse::response_loop()
00099 {
00100
00101
00102 TMuiMCHitMapO::iterator mc_hit_iter = _mc_hit_map->range();
00103
00104
00105 while(TMuiMCHitMapO::pointer mc_hit_ptr = mc_hit_iter.next()){
00106
00107
00108 fill_hit(mc_hit_ptr);
00109 }
00110 }
00111
00112 bool
00113 mMuiResponse::is_alive(TMuiMCHitMapO::const_pointer mc_hit_ptr)
00114 {
00115
00116
00117
00118
00119
00120
00121
00122 double x = gsl_ran_flat(_rng,0.0,100.0);
00123 if (x > _mod_par->get_twopack_eff()) return false;
00124 if(_mod_par->get_verbosity() >= MUIOO::ALOT) {
00125 cout <<" ######## check gsl_ran in mMuiRespose ######### " << endl;
00126 cout <<" # gsl_ran_uniform = " << x << " in mMuiRespose #" << endl;
00127 cout <<" # twopack efficiency = "<<_mod_par->get_twopack_eff() <<" #" << endl;
00128 cout <<" #####################################################" <<endl;
00129 }
00130 return true;
00131 }
00132
00133 void
00134 mMuiResponse::fill_hit(TMuiMCHitMapO::pointer mc_hit_ptr)
00135 {
00136 UShort_t arm = mc_hit_ptr->get()->get_arm();
00137 UShort_t plane = mc_hit_ptr->get()->get_plane();
00138
00139 typedef TMuiMCHitO::twopack_list twopack_list;
00140 typedef TMuiMCHitO::twopack_list::iterator twopack_iterator;
00141
00142
00143
00144 twopack_list* twopacks = mc_hit_ptr->get()->get_mutable_twopack_list();
00145 twopack_iterator twopack_iter = twopacks->begin();
00146
00147 for(;twopack_iter!=twopacks->end();++twopack_iter){
00148
00149
00150
00151
00152 UShort_t panel = twopack_iter->get_panel();
00153 UShort_t orientation = twopack_iter->get_orient();
00154 UShort_t twopack = twopack_iter->get_twopack_index();
00155
00156
00157
00158
00159 if(_mod_par->get_use_hv_mask() &&
00160 !check_efficiency(arm,plane,panel,orientation,twopack)){
00161 twopack_iter->set_status(TMuiMCTwoPack::MASKED);
00162 continue;
00163 }
00164 TMuiHitMapO::iterator hit_iter = _hit_map->get(arm,
00165 plane,
00166 panel,
00167 orientation,
00168 twopack);
00169
00170
00171
00172
00173 if(hit_iter.at_end()){
00174 hit_iter = _hit_map->insert_new(arm,
00175 plane,
00176 panel,
00177 orientation,
00178 twopack);
00179
00180 }
00181
00182 associate_mc(hit_iter, mc_hit_ptr);
00183 }
00184
00185 }
00186
00187 void
00188 mMuiResponse::associate_mc(TMuiHitMapO::iterator hit_iter,
00189 TMuiMCHitMapO::const_pointer mc_hit_ptr)
00190 {
00191 TMuiHitMapO::pointer hit_ptr = hit_iter.current();
00192 PHKey::associate(TMuiMCHitMapO::pointer(mc_hit_ptr), hit_ptr);
00193 }
00194
00195
00196 bool
00197 mMuiResponse::initialize_rng()
00198 {
00199 const gsl_rng_type *T;
00200 gsl_rng_env_setup();
00201 T = gsl_rng_default;
00202 _rng = gsl_rng_alloc(T);
00203
00204 return true;
00205 }
00206
00207
00208 bool
00209 mMuiResponse::check_efficiency(UShort_t arm,
00210 UShort_t plane,
00211 UShort_t panel,
00212 UShort_t orientation,
00213 UShort_t twopack) const
00214 {
00215
00216
00217 if(_mod_par->get_use_hv_mask()){
00218
00219
00220 double random = gsl_ran_flat(_rng,0.0,1.0);
00221 double effic = TMuiHVMask::get_effic_twopack(arm,plane,panel,orientation,twopack);
00222 if (random > effic) return false;
00223 }
00224
00225
00226
00227 double random = gsl_ran_flat(_rng,0.0,1.0);
00228 double effic = _mod_par->get_twopack_eff();
00229 if (random > effic) return false;
00230
00231 return true;
00232 }
00233
00234
00235
00236
00237