Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 09:21:54

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /*
0027  * ============================================================================
0028  *
0029  *       Filename:  CexmcTrackPoints.cc
0030  *
0031  *    Description:  track points collection
0032  *
0033  *        Version:  1.0
0034  *        Created:  16.11.2009 13:03:03
0035  *       Revision:  none
0036  *       Compiler:  gcc
0037  *
0038  *         Author:  Alexey Radkov (), 
0039  *        Company:  PNPI
0040  *
0041  * ============================================================================
0042  */
0043 
0044 #include <G4HCofThisEvent.hh>
0045 #include <G4AffineTransform.hh>
0046 #include <G4UnitsTable.hh>
0047 #include "CexmcTrackPoints.hh"
0048 #include "CexmcTrackInfo.hh"
0049 
0050 
0051 CexmcTrackPoints::CexmcTrackPoints( const G4String &  name ) :
0052     CexmcPrimitiveScorer( name ), hcId( -1 )
0053 {
0054 }
0055 
0056 
0057 G4int  CexmcTrackPoints::GetTrackId( G4Step *  step )
0058 {
0059     /* NB: trackInfo for these tracks shall always exist as far as
0060      * track points filter decline tracks without it */
0061     CexmcTrackInfo *  trackInfo( static_cast< CexmcTrackInfo * >(
0062                                     step->GetTrack()->GetUserInformation() ) );
0063 
0064     G4int  ret( trackInfo->GetTrackType() );
0065 
0066     if ( ret == CexmcOutputParticleDecayProductTrack )
0067         ret += trackInfo->GetCopyNumber();
0068 
0069     return ret;
0070 }
0071 
0072 
0073 G4int  CexmcTrackPoints::GetIndex( G4Step *  step )
0074 {
0075     return GetTrackId( step );
0076 }
0077 
0078 
0079 G4bool  CexmcTrackPoints::ProcessHits( G4Step *  step, G4TouchableHistory * )
0080 {
0081     G4int  index( GetIndex( step ) );
0082 
0083     if ( ( *eventMap )[ index ] )
0084         return false;
0085 
0086     G4Track *               track( step->GetTrack() );
0087     G4ParticleDefinition *  particle( track->GetDefinition() );
0088     CexmcTrackType          trackType( CexmcInsipidTrack );
0089 
0090     G4StepPoint *           preStepPoint( step->GetPreStepPoint() );
0091     G4ThreeVector           position( preStepPoint->GetPosition() );
0092     G4ThreeVector           direction( preStepPoint->GetMomentumDirection() );
0093 
0094     const G4AffineTransform &  transform( preStepPoint->GetTouchable()->
0095                                           GetHistory()->GetTopTransform() );
0096 
0097     CexmcTrackInfo *  trackInfo( static_cast< CexmcTrackInfo * >(
0098                                                 track->GetUserInformation() ) );
0099     trackType = trackInfo->GetTrackType();
0100 
0101     CexmcTrackPointInfo  trackPointInfo( transform.TransformPoint( position ),
0102                                          position,
0103                                          transform.TransformAxis( direction ),
0104                                          direction,
0105                                          preStepPoint->GetMomentum().mag(),
0106                                          particle, track->GetTrackID(),
0107                                          trackType );
0108 
0109     eventMap->set( index, trackPointInfo );
0110 
0111     return true; 
0112 }
0113 
0114 
0115 void  CexmcTrackPoints::Initialize( G4HCofThisEvent *  hcOfEvent )
0116 {
0117     eventMap = new CexmcTrackPointsCollection( detector->GetName(),
0118                                                primitiveName );
0119 
0120     if ( hcId < 0 )
0121         hcId = GetCollectionID( 0 );
0122 
0123     hcOfEvent->AddHitsCollection( hcId, eventMap );
0124 }
0125 
0126 
0127 void  CexmcTrackPoints::EndOfEvent( G4HCofThisEvent * )
0128 {
0129     if ( GetVerboseLevel() > 0 )
0130         PrintAll();
0131 }
0132 
0133 
0134 void  CexmcTrackPoints::clear( void )
0135 {
0136     eventMap->clear();
0137 }
0138 
0139 
0140 void  CexmcTrackPoints::DrawAll( void )
0141 {
0142 }
0143 
0144 
0145 void  CexmcTrackPoints::PrintAll( void )
0146 {
0147     G4int   nmbOfEntries( eventMap->entries() );
0148 
0149     if ( nmbOfEntries == 0 )
0150         return;
0151 
0152     PrintHeader( nmbOfEntries );
0153 
0154     for ( CexmcTrackPointsCollectionData::iterator
0155                          itr( eventMap->GetMap()->begin() );
0156                                      itr != eventMap->GetMap()->end(); ++itr )
0157     {
0158         G4cout << "       track id " << itr->first << G4endl;
0159         G4cout << "         , position: " <<
0160                 G4BestUnit( itr->second->positionLocal, "Length" ) << G4endl;
0161         G4cout << "         , direction: " <<
0162                 itr->second->directionLocal << G4endl;
0163         G4cout << "         , momentum: " <<
0164                 G4BestUnit( itr->second->momentumAmp, "Energy" ) << G4endl;
0165         G4cout << "         , particle: " <<
0166                 itr->second->particle->GetParticleName() << G4endl;
0167     }
0168 }
0169