/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
GtMultiVolumePosTool Class Reference

Position events in multiple volumes (DetectorElements) More...

#include <GtMultiVolumePosTool.h>

Inheritance diagram for GtMultiVolumePosTool:
Inheritance graph
[legend]
Collaboration diagram for GtMultiVolumePosTool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 GtMultiVolumePosTool (const std::string &type, const std::string &name, const IInterface *parent)
virtual ~GtMultiVolumePosTool ()
virtual StatusCode initialize ()
virtual StatusCode finalize ()
virtual StatusCode mutate (HepMC::GenEvent &event)
 Modify the event.

Static Public Member Functions

static const InterfaceID & interfaceID ()
 Retrieve interface ID.

Private Types

typedef std::map< std::string,
double > 
VolProbMap
 Property: VolumeProbabilityMap: a map of volume (DetectorElement) name to its probability of being chosen.
typedef std::map< std::string,
IDetectorElement * > 
DEMap

Private Member Functions

IDetectorElement * pickDE ()
StatusCode pickPoint (IDetectorElement *de, std::vector< double > &local_point)
StatusCode setPosition (HepMC::GenEvent &event, std::vector< double > &point)
StatusCode toGlobal (HepMC::GenEvent &event, IDetectorElement &de)

Private Attributes

VolProbMap m_volProbMap
bool m_implicitTransform
 Property: ImplicitTransform: a boolean to indicate if the chosen vertex and directions should be implicitly transformed to global coordinates.
double m_totalProb
DEMap m_deMap
Rndm::Numbers m_uni

Detailed Description

Position events in multiple volumes (DetectorElements)

This tool will position the event in one of several given volumes (DetectorElements) based on their relative probabilities.

bv@bnl.gov Thu Jul 14 01:28:45 2011

Definition at line 29 of file GtMultiVolumePosTool.h.


Member Typedef Documentation

typedef std::map<std::string,double> GtMultiVolumePosTool::VolProbMap [private]

Property: VolumeProbabilityMap: a map of volume (DetectorElement) name to its probability of being chosen.

Definition at line 46 of file GtMultiVolumePosTool.h.

typedef std::map<std::string, IDetectorElement*> GtMultiVolumePosTool::DEMap [private]

Definition at line 74 of file GtMultiVolumePosTool.h.


Constructor & Destructor Documentation

GtMultiVolumePosTool::GtMultiVolumePosTool ( const std::string &  type,
const std::string &  name,
const IInterface *  parent 
)

Definition at line 15 of file GtMultiVolumePosTool.cc.

    : GaudiTool(type,name,parent)
    , m_volProbMap()
    , m_implicitTransform(true)
    , m_totalProb(0.0)
{
    declareInterface<IHepMCEventMutator>(this);

    declareProperty("VolumeProbabilityMap",m_volProbMap,
                    "Map from DetectorElements to relative probability of being chosen");
    declareProperty("ImplicitTransform",m_implicitTransform,
                    "Set to false if a transform to global coordinates should not be performed");
    
}
GtMultiVolumePosTool::~GtMultiVolumePosTool ( ) [virtual]

Definition at line 32 of file GtMultiVolumePosTool.cc.

{
}

Member Function Documentation

StatusCode GtMultiVolumePosTool::initialize ( ) [virtual]

Definition at line 36 of file GtMultiVolumePosTool.cc.

{
    StatusCode sc = this->GaudiTool::initialize();
    if (sc.isFailure()) return sc;

    // Set up random numbers
    IRndmGenSvc *rgs = 0;
    if (service("RndmGenSvc",rgs,true).isFailure()) {
        fatal() << "Failed to get random service" << endreq;
        return StatusCode::FAILURE;        
    }
    if (m_uni.initialize(rgs, Rndm::Flat(0,1)).isFailure()) {
        fatal() << "Failed to initialize uniform random numbers" << endreq;
        return StatusCode::FAILURE;
    }

    // Normalize probabilities and get detector elements
    m_totalProb = 0.0;
    VolProbMap::iterator it, done = m_volProbMap.end();
    for (it = m_volProbMap.begin(); it != done; ++it) {
        m_totalProb += it->second;

        IDetectorElement* de = getDet<IDetectorElement>(it->first);
        m_deMap[it->first] = de;

        debug() << "Normalized \"" << it->first << "\"" << endreq;

    }

    return StatusCode::SUCCESS;
}
StatusCode GtMultiVolumePosTool::finalize ( ) [virtual]

Definition at line 68 of file GtMultiVolumePosTool.cc.

{
    return this->GaudiTool::finalize();
}
StatusCode GtMultiVolumePosTool::mutate ( HepMC::GenEvent event) [virtual]

Modify the event.

Implements IHepMCEventMutator.

Definition at line 184 of file GtMultiVolumePosTool.cc.

{
    std::vector<double> local_point(3,0.0);
    IDetectorElement* de = pickDE();
    StatusCode sc = this->pickPoint(de,local_point);
    if (sc.isFailure()) return sc;

    debug() << "Picked DE: \"" << de->name() << "\"" << endreq;

    sc = this->setPosition(event,local_point);
    if (sc.isFailure()) return sc;

    if (!m_implicitTransform) {
        return sc;
    }

    return this->toGlobal(event, *de);
}
IDetectorElement * GtMultiVolumePosTool::pickDE ( ) [private]

Definition at line 73 of file GtMultiVolumePosTool.cc.

{
    double arrow = 0, target = m_uni() * m_totalProb;
    VolProbMap::iterator it, done = m_volProbMap.end();
    for (it = m_volProbMap.begin(); it != done; ++it) {
        arrow += it->second;
        if (target <= arrow) {
            return m_deMap[it->first];
        }
    }
    return 0;                   // shouldn't happen
}
StatusCode GtMultiVolumePosTool::pickPoint ( IDetectorElement *  de,
std::vector< double > &  local_point 
) [private]

Definition at line 86 of file GtMultiVolumePosTool.cc.

{
    // Get volume's solid's bounding box - this could be optimized by
    // doing it once in initialize()

    IGeometryInfo* gi = de->geometry();
    const ILVolume* lvol = gi->lvolume();
    if (!lvol) {
        fatal() << "Could not get DetectorElement: \"" << de->name() << "\" " << endreq;
        return StatusCode::FAILURE;
    }

    double pos[3] = {0.0}, min[3] = {0.0}, max[3] = {0.0};
    const SolidBase* solid = dynamic_cast<const SolidBase*>(lvol->solid());
    if (!solid) {
        error() << "My detector element: \"" << de->name() << "\" has no solid with LVolume: "
                << *lvol << endreq;
        return StatusCode::FAILURE;
    }
    min[0] = solid->xMin(); max[0] = solid->xMax();
    min[1] = solid->yMin(); max[1] = solid->yMax();
    min[2] = solid->zMin(); max[2] = solid->zMax();

    debug() << "Bounding box for " << de->name() << " = ("
            << min[0] << " " << min[1] << " " << min[2] << ") --> ("
            << max[0] << " " << max[1] << " " << max[2] << ")" << endreq;
    
    for (int ind=0; ind<3; ++ind) {
        pos[ind] = m_uni() * (max[ind] - min[ind]) + min[ind];
    }

    Gaudi::XYZPoint point(pos[0],pos[1],pos[2]);
    if (lvol->isInside(point)) {
        debug() << "Local point: in " << de->name() << " (" ;
        bool ok = true;
        for (int ind=0; ind<3; ++ind) {
            local_point[ind] = pos[ind];
            debug () << " " << pos[ind];
            if (pos[ind] < min[ind] || pos[ind] > max[ind]) {
                ok = false;
            }

        }
        debug () << " )" << ok << endreq;

        return StatusCode::SUCCESS;
    }

    return this->pickPoint(de,local_point);    
}
StatusCode GtMultiVolumePosTool::setPosition ( HepMC::GenEvent event,
std::vector< double > &  point 
) [private]

Definition at line 139 of file GtMultiVolumePosTool.cc.

{
    HepMC::FourVector pos(point[0],point[1],point[2],0);
    HepMC::GenEvent::vertex_iterator vtx, done = event.vertices_end();
    for (vtx = event.vertices_begin(); vtx != done; ++vtx) {
        HepMC::FourVector position4d = pos;
        position4d.setT((*vtx)->position().t());
        (*vtx)->set_position(position4d);
    }
    return StatusCode::SUCCESS;
}
StatusCode GtMultiVolumePosTool::toGlobal ( HepMC::GenEvent event,
IDetectorElement &  de 
) [private]

Definition at line 152 of file GtMultiVolumePosTool.cc.

{
    IGeometryInfo* gi = de.geometry();

    // position
    HepMC::GenEvent::vertex_iterator vtx, done = event.vertices_end();
    for (vtx = event.vertices_begin(); vtx != done; ++vtx) {

        HepMC::FourVector pos = (*vtx)->position();
        Gaudi::XYZPoint local_point(pos.x(),pos.y(),pos.z());
        Gaudi::XYZPoint global_point = gi->toGlobal(local_point);
        pos.setX(global_point.x()); 
        pos.setY(global_point.y()); 
        pos.setZ(global_point.z());
        (*vtx)->set_position(pos);
    }

    // directions
    HepMC::GenEvent::particle_iterator pit, pdone = event.particles_end();
    for (pit = event.particles_begin(); pit != pdone; ++pit) {

        HepMC::FourVector mom = (*pit)->momentum();
        Gaudi::XYZVector lmom(mom.px(),mom.py(),mom.pz());
        Gaudi::XYZVector gmom = gi->toGlobal(lmom);
        mom.set(gmom.x(),gmom.y(),gmom.z(),mom.e());
        (*pit)->set_momentum(mom);
    }

    return StatusCode::SUCCESS;
}
const InterfaceID & IHepMCEventMutator::interfaceID ( ) [static, inherited]

Retrieve interface ID.

Definition at line 8 of file IHepMCEventMutator.cc.

{ 
    return IID_IHepMCEventMutator; 
}

Member Data Documentation

Definition at line 47 of file GtMultiVolumePosTool.h.

Property: ImplicitTransform: a boolean to indicate if the chosen vertex and directions should be implicitly transformed to global coordinates.

Default is True. Note, GtTransformTool is not compatible with this tool as it assumes a single volume.

Definition at line 54 of file GtMultiVolumePosTool.h.

Definition at line 73 of file GtMultiVolumePosTool.h.

Definition at line 75 of file GtMultiVolumePosTool.h.

Rndm::Numbers GtMultiVolumePosTool::m_uni [private]

Definition at line 76 of file GtMultiVolumePosTool.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:18:51 for GenTools by doxygen 1.7.4