Analyses/src/ReadBack_module.cc
void ReadBack::doStoppingTarget(const art::Event& event) {

    // Find original G4 steps in the stopping target
    art::Handle<StepPointMCCollection> sthits;
    event.getByLabel(_g4ModuleLabel,_targetStepPoints,sthits);

    // SimParticles container
    art::Handle<SimParticleCollection> simParticles;
    event.getByLabel(_g4ModuleLabel,simParticles);
    if( !(simParticles.isValid()) || simParticles->empty() ) return;

    // Loop over all hits in the stopping target. Check, that the
    // hit belongs to primary particle. If so, calculate total energy
    // deposition in the target, total path length and the number of
    // foils, crossed by the electron.

    int id_start = -1;
    double eDep=0.0, pathLength=0.0;
    map<int,int> foils;

    // Loop over all hits in the stopping target
    for ( size_t i=0; i<sthits->size(); ++i ){

      // This is G4 hit (step) in the target
      const StepPointMC& hit = (*sthits)[i];

      // Here we select only those hits, which are generated by
      // the primary track - which is assumed to be the original
      // particle, generated by ConversionGun
      SimParticleCollection::key_type trackId = hit.trackId();
      if( trackId.asInt() != 1 ) continue;

      // Here we require that there is information about the primary
      // particle in the SimParticle collection. It is not neccessary for
      // this example, but it is typical requirement in the real analysis
      SimParticle const* sim = simParticles->getOrNull(trackId);
      if( !sim ) continue;

      // Get the foil id where the hit occured. If it is the first hit,
      // remember this id as the source foil id.
      int id = hit.volumeId();
      if( id_start<0 ) id_start=id;

      // Here we calculate number of steps in each foil. There could be
      // many hits in each foil. This number is not used in the example,
      // it is calculated here just as an example. But we use this map to
      // calculate number of foils with the hits. Be aware, that if particle
      // crosses foil without energy deposition (just passes it), it still
      // counts as a hit. Here we record all foils particle crosses.
      // If we want to record only those foils where particle had
      // interactions, we would need to do the following:
      //      if( hit.totalEDep()>0 ) foils[id]++;
      foils[id]++;

      // Calculate total energy loss and path length primary particle
      // has in the target.
      eDep += hit.totalEDep();
      pathLength += hit.stepLength();

    }

    // Number of crossed foils
    int nfoil = foils.size();

    // Fill histograms
    if( id_start>=0 ) {
      _hTargetEdep->Fill(eDep);
      _hTargetPathLength->Fill(pathLength);
      _hTargetNfoils->Fill(nfoil);
      _hTargetNfoils2D->Fill(id_start,nfoil);
    }

  }
//
// Example of how to read information about stopping target
//
// Here we assume that the primary particles are the conversion
// electrons generated in the stopping target.
//
Example of how to read information about stopping target
Here we assume that the primary particles are the conversion
electrons generated in the stopping target.
Example of how to read information about stopping target Here we assume that the primary particles are the conversion electrons generated in the stopping target .
void ReadBack::doStoppingTarget(const art::Event& event) {
    art::Handle<StepPointMCCollection> sthits;
    event.getByLabel(_g4ModuleLabel,_targetStepPoints,sthits);
    art::Handle<SimParticleCollection> simParticles;
    event.getByLabel(_g4ModuleLabel,simParticles);
    if( !(simParticles.isValid()) || simParticles->empty() ) return;
    int id_start = -1;
    double eDep=0.0, pathLength=0.0;
    map<int,int> foils;
    for ( size_t i=0; i<sthits->size(); ++i ){
      const StepPointMC& hit = (*sthits)[i];
      SimParticleCollection::key_type trackId = hit.trackId();
      if( trackId.asInt() != 1 ) continue;
      SimParticle const* sim = simParticles->getOrNull(trackId);
      if( !sim ) continue;
      int id = hit.volumeId();
      if( id_start<0 ) id_start=id;
      foils[id]++;
      eDep += hit.totalEDep();
      pathLength += hit.stepLength();
    }
    int nfoil = foils.size();
    if( id_start>=0 ) {
      _hTargetEdep->Fill(eDep);
      _hTargetPathLength->Fill(pathLength);
      _hTargetNfoils->Fill(nfoil);
      _hTargetNfoils2D->Fill(id_start,nfoil);
    }
  }
void ReadBack :: doStoppingTarget ( const art :: Event & event ) { art :: Handle < StepPointMCCollection > sthits ; event . getByLabel ( _g4ModuleLabel , _targetStepPoints , sthits ) ; art :: Handle < SimParticleCollection > simParticles ; event . getByLabel ( _g4ModuleLabel , simParticles ) ; if ( ! ( simParticles . isValid ( ) ) || simParticles -> empty ( ) ) return ; int id_start = -1 ; double eDep = 0.0 , pathLength = 0.0 ; map < int , int > foils ; for ( size_t i = 0 ; i < sthits -> size ( ) ; ++ i ) { const StepPointMC & hit = ( * sthits ) [ i ] ; SimParticleCollection :: key_type trackId = hit . trackId ( ) ; if ( trackId . asInt ( ) != 1 ) continue ; SimParticle const * sim = simParticles -> getOrNull ( trackId ) ; if ( ! sim ) continue ; int id = hit . volumeId ( ) ; if ( id_start < 0 ) id_start = id ; foils [ id ] ++ ; eDep += hit . totalEDep ( ) ; pathLength += hit . stepLength ( ) ; } int nfoil = foils . size ( ) ; if ( id_start >= 0 ) { _hTargetEdep -> Fill ( eDep ) ; _hTargetPathLength -> Fill ( pathLength ) ; _hTargetNfoils -> Fill ( nfoil ) ; _hTargetNfoils2D -> Fill ( id_start , nfoil ) ; } }
Example of how to read information about stopping target
Here we assume that the primary particles are the conversion
electrons generated in the stopping target.
Example of how to read information about stopping target Here we assume that the primary particles are the conversion electrons generated in the stopping target .
// Find original G4 steps in the stopping target // SimParticles container // Loop over all hits in the stopping target. Check, that the // hit belongs to primary particle. If so, calculate total energy // deposition in the target, total path length and the number of // foils, crossed by the electron. // Loop over all hits in the stopping target // This is G4 hit (step) in the target // Here we select only those hits, which are generated by // the primary track - which is assumed to be the original // particle, generated by ConversionGun // Here we require that there is information about the primary // particle in the SimParticle collection. It is not neccessary for // this example, but it is typical requirement in the real analysis // Get the foil id where the hit occured. If it is the first hit, // remember this id as the source foil id. // Here we calculate number of steps in each foil. There could be // many hits in each foil. This number is not used in the example, // it is calculated here just as an example. But we use this map to // calculate number of foils with the hits. Be aware, that if particle // crosses foil without energy deposition (just passes it), it still // counts as a hit. Here we record all foils particle crosses. // If we want to record only those foils where particle had // interactions, we would need to do the following: //      if( hit.totalEDep()>0 ) foils[id]++; // Calculate total energy loss and path length primary particle // has in the target. // Number of crossed foils // Fill histograms