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10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  1 //
  2 // ********************************************************************
  3 // * License and Disclaimer                                           *
  4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.                             *
 10 // *                                                                  *
 11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                                                  *
 18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // ********************************************************************
 25 //
 26 /*
 27  * ============================================================================
 28  *
 29  *       Filename:  CexmcTrackPointsDigitizer.cc
 30  *
 31  *    Description:  track points collector
 32  *
 33  *        Version:  1.0
 34  *        Created:  24.11.2009 16:34:43
 35  *       Revision:  none
 36  *       Compiler:  gcc
 37  *
 38  *         Author:  Alexey Radkov (), 
 39  *        Company:  PNPI
 40  *
 41  * ============================================================================
 42  */
 43 
 44 #include <G4DigiManager.hh>
 45 #include <G4RunManager.hh>
 46 #include <G4String.hh>
 47 #include "CexmcTrackPointsDigitizer.hh"
 48 #include "CexmcTrackPoints.hh"
 49 #include "CexmcTrackPointsInLeftRightSet.hh"
 50 #include "CexmcTrackPointsInCalorimeter.hh"
 51 #include "CexmcSensitiveDetectorsAttributes.hh"
 52 #include "CexmcCommon.hh"
 53 
 54 
 55 CexmcTrackPointsDigitizer::CexmcTrackPointsDigitizer( const G4String &  name ) :
 56     G4VDigitizerModule( name ), hasTriggered( false )
 57 {
 58     G4RunManager *      runManager( G4RunManager::GetRunManager() );
 59     const CexmcSetup *  setup( static_cast< const CexmcSetup * >(
 60                                 runManager->GetUserDetectorConstruction() ) );
 61     calorimeterGeometry = setup->GetCalorimeterGeometry();
 62 }
 63 
 64 
 65 void  CexmcTrackPointsDigitizer::InitializeData( void )
 66 {
 67     monitorTP.trackId = CexmcInvalidTrackId;
 68     targetTPBeamParticle.trackId = CexmcInvalidTrackId;
 69     targetTPOutputParticle.trackId = CexmcInvalidTrackId;
 70     targetTPNucleusParticle.trackId = CexmcInvalidTrackId;
 71     targetTPOutputParticleDecayProductParticle[ 0 ].trackId =
 72                                                         CexmcInvalidTrackId;
 73     targetTPOutputParticleDecayProductParticle[ 1 ].trackId =
 74                                                         CexmcInvalidTrackId;
 75     vetoCounterTPLeft.trackId = CexmcInvalidTrackId;
 76     vetoCounterTPRight.trackId = CexmcInvalidTrackId;
 77     calorimeterTPLeft.trackId = CexmcInvalidTrackId;
 78     calorimeterTPRight.trackId = CexmcInvalidTrackId;
 79     hasTriggered = false;
 80 }
 81 
 82 
 83 void  CexmcTrackPointsDigitizer::Digitize( void )
 84 {
 85     InitializeData();
 86 
 87     G4int     nCrystalsInColumn( calorimeterGeometry.nCrystalsInColumn );
 88     G4int     nCrystalsInRow( calorimeterGeometry.nCrystalsInRow );
 89     G4double  crystalWidth( calorimeterGeometry.crystalWidth );
 90     G4double  crystalHeight( calorimeterGeometry.crystalHeight );
 91 
 92     G4DigiManager *  digiManager( G4DigiManager::GetDMpointer() );
 93     G4int    hcId( digiManager->GetHitsCollectionID(
 94                     CexmcDetectorRoleName[ CexmcMonitorDetectorRole ] +
 95                     "/" + CexmcDetectorTypeName[ CexmcTPDetector ] ) );
 96     const CexmcTrackPointsCollection *
 97              hitsCollection( static_cast< const CexmcTrackPointsCollection * >(
 98                                     digiManager->GetHitsCollection( hcId ) ) );
 99 
100     if ( hitsCollection )
101     {
102         for ( CexmcTrackPointsCollectionData::iterator
103                   k( hitsCollection->GetMap()->begin() );
104                       k != hitsCollection->GetMap()->end(); ++k )
105         {
106             monitorTP = *k->second;
107             break;
108         }
109     }
110 
111     hcId = digiManager->GetHitsCollectionID(
112                     CexmcDetectorRoleName[ CexmcTargetDetectorRole ] +
113                     "/" + CexmcDetectorTypeName[ CexmcTPDetector ] );
114     hitsCollection = static_cast< const CexmcTrackPointsCollection * >(
115                                     digiManager->GetHitsCollection( hcId ) );
116 
117     if ( hitsCollection )
118     {
119         for ( CexmcTrackPointsCollectionData::iterator
120                   k( hitsCollection->GetMap()->begin() );
121                       k != hitsCollection->GetMap()->end(); ++k )
122         {
123             do
124             {
125                 if ( k->second->trackType == CexmcBeamParticleTrack )
126                 {
127                     targetTPBeamParticle = *k->second;
128                     break;
129                 }
130                 if ( k->second->trackType == CexmcOutputParticleTrack )
131                 {
132                     targetTPOutputParticle = *k->second;
133                     hasTriggered = targetTPOutputParticle.IsValid();
134                     break;
135                 }
136                 if ( k->second->trackType == CexmcNucleusParticleTrack )
137                 {
138                     targetTPNucleusParticle = *k->second;
139                     break;
140                 }
141                 if ( k->second->trackType ==
142                                         CexmcOutputParticleDecayProductTrack )
143                 {
144                     /* NB: if there are more than 2 output particle's decay
145                      * products then the chosen particles may differ from those
146                      * which entered calorimeters; however this is not a
147                      * critical issue as far as information about decay products
148                      * is not necessary in reconstruction and only used in some
149                      * histograming */
150                     G4int  index(
151                             targetTPOutputParticleDecayProductParticle[ 0 ].
152                                                           trackId > 0 ? 1 : 0 );
153                     targetTPOutputParticleDecayProductParticle[ index ] =
154                             *k->second;
155                     break;
156                 }
157             } while ( false );
158         }
159     }
160 
161     hcId = digiManager->GetHitsCollectionID(
162                     CexmcDetectorRoleName[ CexmcVetoCounterDetectorRole ] +
163                     "/" + CexmcDetectorTypeName[ CexmcTPDetector ] );
164     hitsCollection = static_cast< const CexmcTrackPointsCollection * >(
165                                     digiManager->GetHitsCollection( hcId ) );
166 
167     if ( hitsCollection )
168     {
169         for ( CexmcTrackPointsCollectionData::iterator
170                   k( hitsCollection->GetMap()->begin() );
171                       k != hitsCollection->GetMap()->end(); ++k )
172         {
173             if ( k->second->trackType != CexmcOutputParticleDecayProductTrack )
174                 continue;
175 
176             G4int  index( k->first );
177             CexmcSide  side( CexmcTrackPointsInLeftRightSet::GetSide(
178                                                                    index ) );
179             switch ( side )
180             {
181             case CexmcLeft :
182                 vetoCounterTPLeft = *k->second;
183                 break;
184             case CexmcRight :
185                 vetoCounterTPRight = *k->second;
186                 break;
187             default :
188                 break;
189             }
190         }
191     }
192 
193     hcId = digiManager->GetHitsCollectionID(
194                     CexmcDetectorRoleName[ CexmcCalorimeterDetectorRole ] +
195                     "/" + CexmcDetectorTypeName[ CexmcTPDetector ] );
196     hitsCollection = static_cast< const CexmcTrackPointsCollection * >(
197                                     digiManager->GetHitsCollection( hcId ) );
198 
199     if ( hitsCollection )
200     {
201         for ( CexmcTrackPointsCollectionData::iterator
202                   k( hitsCollection->GetMap()->begin() );
203                       k != hitsCollection->GetMap()->end(); ++k )
204         {
205             if ( k->second->trackType != CexmcOutputParticleDecayProductTrack )
206                 continue;
207 
208             G4int  index( k->first );
209             CexmcSide  side( CexmcTrackPointsInLeftRightSet::GetSide(
210                                                                    index ) );
211             G4int      row( CexmcTrackPointsInCalorimeter::GetRow( index ) );
212             G4int      column( CexmcTrackPointsInCalorimeter::GetColumn(
213                                                                    index ) );
214             G4double   xInCalorimeterOffset(
215                     ( G4double( column ) - G4double( nCrystalsInRow ) / 2 ) *
216                                         crystalWidth + crystalWidth / 2 );
217             G4double   yInCalorimeterOffset(
218                     ( G4double( row ) - G4double( nCrystalsInColumn ) / 2 ) *
219                                         crystalHeight + crystalHeight / 2 );
220             switch ( side )
221             {
222             case CexmcLeft :
223                 calorimeterTPLeft = *k->second;
224                 calorimeterTPLeft.positionLocal.setX( xInCalorimeterOffset +
225                                         calorimeterTPLeft.positionLocal.x() );
226                 calorimeterTPLeft.positionLocal.setY( yInCalorimeterOffset +
227                                         calorimeterTPLeft.positionLocal.y() );
228                 break;
229             case CexmcRight :
230                 calorimeterTPRight = *k->second;
231                 calorimeterTPRight.positionLocal.setX( xInCalorimeterOffset +
232                                         calorimeterTPRight.positionLocal.x() );
233                 calorimeterTPRight.positionLocal.setY( yInCalorimeterOffset +
234                                         calorimeterTPRight.positionLocal.y() );
235                 break;
236             default :
237                 break;
238             }
239         }
240     }
241 }
242 
243