// DetectorSimulator.cpp #include "DetectorSimulator.h" #include #include "trfutil/trfstream.h" #include "LayerSimulator.h" using trf::Layer; using trf::Detector; using trf::LayerSimulator; using trf::DetectorSimulator; //********************************************************************** // Constructor. DetectorSimulator::DetectorSimulator(const DetectorPtr& pdet) : _pdet(pdet) { assert( _pdet != 0 ); } //********************************************************************** // Destructor. DetectorSimulator::~DetectorSimulator() { } //********************************************************************** // Output stream. void DetectorSimulator::ostr(ostream& stream) const { stream << begin_object; int size = _lsims.size(); stream << "Detector Simulator with " << size << " layer generator"; if ( size != 1 ) stream << "s"; if ( size == 0 ) { stream << "."; } else { stream << ":"; print_generators(stream); } stream << end_object; } //********************************************************************** // write out the list of generators. void DetectorSimulator::print_generators(ostream& stream) const { if ( _lsims.size() == 0 ) { stream << "There are no generators."; return; } for ( LayerSimulatorMap::const_iterator ilsim=_lsims.begin(); ilsim!=_lsims.end(); ++ilsim ) { LayerName name = (*ilsim).first; LayerSimulatorPtr plsim = (*ilsim).second; stream << new_line; stream << name << ": " << *plsim; } } //********************************************************************** // Return the list of generators. RandomSimulator::GeneratorList DetectorSimulator::get_generators() { GeneratorList gens; // Loop over layer simulators. LayerSimulatorMap::const_iterator ilsim; for ( ilsim=_lsims.begin(); ilsim!=_lsims.end(); ++ilsim ) { LayerSimulatorPtr plsim = (*ilsim).second; GeneratorList newgens = plsim->get_generators(); GeneratorList::iterator igen; for ( igen=newgens.begin(); igen!=newgens.end(); ++igen ) { gens.push_back(*igen); } } return gens; } //********************************************************************** // Add a layer simulator by name. // Name must be known to the detector. // Detector and layer simulator must reference the same layer object. // Return nonzero for error. DetectorSimulator::ReturnStatus DetectorSimulator:: add_layer_simulator(LayerName name, LayerSimulatorPtr plsim) { // Check the name. if ( ! _pdet->is_assigned(name) ) return UNKNOWN_NAME; // Fetch the layers and check for match. const Layer& detlyr = _pdet->get_layer(name); const Layer& simlyr = plsim->get_layer(); if ( &detlyr != &simlyr ) return LAYER_MISMATCH; _lsims[name] = plsim; return OK; } //********************************************************************** // Add all the layer simulators from a detector simulator. // Each name must be known to the local detector. // Detector and each layer simulator must reference the same // layer object. // Return nonzero for error. DetectorSimulator::ReturnStatus DetectorSimulator:: add_detector_simulator(const DetectorSimulator& dsim) { // Loop over layer simulators. LayerSimulatorMap::const_iterator ilsim; for ( ilsim=dsim._lsims.begin(); ilsim!=dsim._lsims.end(); ++ilsim ) { LayerName name = (*ilsim).first; LayerSimulatorPtr plsim = (*ilsim).second; ReturnStatus stat = add_layer_simulator(name,plsim); if ( stat != OK ) return stat; } return OK; } //********************************************************************** // Use the specified track to add clusters with each layer simulator. void DetectorSimulator::add_clusters(const VTrack& trv) { // Loop over layer simulators. LayerSimulatorMap::const_iterator ilsim; for ( ilsim=_lsims.begin(); ilsim!=_lsims.end(); ++ilsim ) { LayerSimulatorPtr plsim = (*ilsim).second; plsim->add_clusters(trv); } } //********************************************************************** // Use the specified track to drop clusters with each layer simulator. void DetectorSimulator::drop_clusters() { // Loop over layer simulators. LayerSimulatorMap::const_iterator ilsim; for ( ilsim=_lsims.begin(); ilsim!=_lsims.end(); ++ilsim ) { LayerSimulatorPtr plsim = (*ilsim).second; plsim->drop_clusters(); } } //********************************************************************** // output stream ostream& trf::operator<<(ostream& stream, const DetectorSimulator& dsim) { dsim.ostr(stream); return stream; } //**********************************************************************