BOSS 8.0.0
BESIII Offline Software System
Loading...
Searching...
No Matches
BesTofSD.cc
Go to the documentation of this file.
1//---------------------------------------------------------------------------//
2// BOOST --- BESIII Object_Oriented Simulation Tool //
3//---------------------------------------------------------------------------//
4// Description:
5// Author: Dengzy
6// Created: Mar, 2004
7// Modified:
8// Comment:
9//---------------------------------------------------------------------------//
10//$Id: BesTofSD.cc
11
12#include "TofSim/BesTofSD.hh"
13#include "G4ElectronIonPair.hh"
14#include "G4Event.hh"
15#include "G4HCofThisEvent.hh"
16#include "G4LossTableManager.hh"
17#include "G4PhysicalConstants.hh"
18#include "G4SDManager.hh"
19#include "G4Step.hh"
20#include "G4SystemOfUnits.hh"
21#include "G4ThreeVector.hh"
22#include "G4UnitsTable.hh"
23#include "G4ios.hh"
24#include "GaudiKernel/Bootstrap.h"
25#include "GaudiKernel/IDataProviderSvc.h"
26#include "GaudiKernel/ISvcLocator.h"
27#include "GaudiKernel/MsgStream.h"
28#include "GaudiKernel/PropertyMgr.h"
29#include "SimUtil/ReadBoostRoot.hh"
30using namespace CLHEP;
31//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32
33BesTofSD::BesTofSD( G4String name ) : BesSensitiveDetector( name ), m_besTofList( 0 ) {
34 collectionName.insert( "BesTofHitsCollection" );
35 collectionName.insert( "BesTofHitsList" );
36 elIonPair = new G4ElectronIonPair( 1 );
37
38 PropertyMgr m_propMgr;
39 m_propMgr.declareProperty( "FanoFactor", m_fanoFactor = 0.2 );
40 m_propMgr.declareProperty( "nionOff", m_nionOff = 0.5 );
41
42 /*maqmIJobOptionsSvc* jobSvc;
43 Gaudi::svcLocator()->service("JobOptionsSvc", jobSvc);
44 jobSvc->setMyProperties("BesTofSD", &m_propMgr);
45*/
46 cout << "BesTofSD Property:" << endl
47 << " FanoFactor= " << m_fanoFactor << " nionOff= " << m_nionOff << endl;
48}
49
50//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
51
53
54//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55
56void BesTofSD::Initialize( G4HCofThisEvent* ) {
57 m_besTofCollection = new BesTofHitsCollection( SensitiveDetectorName, collectionName[0] );
58 // elIonPair = G4LossTableManager::Instance()->ElectronIonPair();
59}
60
61// for MC Truth
62void BesTofSD::BeginOfTruthEvent( const G4Event* evt ) {
63 m_event = evt->GetEventID();
64 m_besTofList = new BesTofHitsCollection( SensitiveDetectorName, collectionName[1] );
65 m_trackIndexes.clear();
66 m_trackIndex = -99;
67}
68
69void BesTofSD::EndOfTruthEvent( const G4Event* evt ) {
70 static G4int HLID = -1;
71 if ( HLID < 0 )
72 { HLID = G4SDManager::GetSDMpointer()->GetCollectionID( collectionName[1] ); }
73 G4HCofThisEvent* HCE = evt->GetHCofThisEvent();
74 HCE->AddHitsCollection( HLID, m_besTofList );
75}
76
77//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
78
79G4bool BesTofSD::ProcessHits( G4Step* aStep, G4TouchableHistory* ) {
80
81 G4double chg = aStep->GetTrack()->GetDefinition()->GetPDGCharge();
82 G4double edep = aStep->GetTotalEnergyDeposit();
83 G4double stepL = aStep->GetStepLength();
84 G4double deltaT = aStep->GetDeltaTime();
85 G4StepPoint* preStep = aStep->GetPreStepPoint();
86 G4ThreeVector pDirection = preStep->GetMomentumDirection();
87 G4String particleName = aStep->GetTrack()->GetDefinition()->GetParticleName();
88 G4Material* scinMaterial = aStep->GetTrack()->GetMaterial();
89 G4double charge = aStep->GetTrack()->GetDefinition()->GetPDGCharge();
90 G4int pdgcode = aStep->GetTrack()->GetDefinition()->GetPDGEncoding();
91
92 if ( chg == 0 && edep == 0 && stepL == 0 ) { return false; }
93
94 BesTofHit* newHit = new BesTofHit();
95 G4int trackId = aStep->GetTrack()->GetTrackID();
96
97 newHit->SetEvent( m_event );
98 newHit->SetTrackIndex( -99 );
99 newHit->SetG4Index( aStep->GetTrack()->GetTrackID() );
100 newHit->SetEdep( edep );
101 newHit->SetStepL( stepL );
102 // newHit->SetPName(particleName);
103 newHit->SetTrackL( aStep->GetTrack()->GetTrackLength() );
104 G4ThreeVector pos = preStep->GetPosition();
105 newHit->SetPos( pos );
106 G4double globalTime = preStep->GetGlobalTime();
107 newHit->SetTime( globalTime );
108 newHit->SetDeltaT( deltaT );
109 newHit->SetPDirection( pDirection );
110 newHit->SetMomentum( preStep->GetMomentum() );
111 // newHit->SetMaterial(scinMaterial);
112 newHit->SetCharge( charge );
113 newHit->SetPDGcode( pdgcode );
114
115 // Get local position in sensitive detector, add by anff
116 G4ThreeVector locPos( 0, 0, 0 );
117 G4TouchableHistory* theTouchable = (G4TouchableHistory*)( preStep->GetTouchable() );
118 // partId: barrel(1), east endcap(0), west endcap(2);
119 // scinNb: barrel(0-175),east endcap(0-47), west endcap(0-47)
120 // partId: mrpc: east(3), west(4),
121
122 G4String name;
123 // for(G4int i=0; i<theTouchable->GetHistoryDepth(); i++)
124 //{
125 // name = theTouchable->GetVolume(i)->GetName();
126 // G4cout<<"********* name of the "<<i<<" volume: "<<name<<" ***************"<<G4endl;
127 // }
128 name = theTouchable->GetVolume( 0 )->GetName();
129
130 G4int partId = -1, scinNb = -1, gapNb = -1, number = -1;
131 G4int strip = -1;
132 gapNb = theTouchable->GetReplicaNumber( 0 );
133 number = theTouchable->GetReplicaNumber( 2 ); // This is valid only for scintillator
134
135 // MRPC ENDCAPS construct by geant4 code
136 if ( name.contains( "physical_gasLayer" ) )
137 {
138 locPos = theTouchable->GetHistory()->GetTopTransform().TransformPoint( pos );
139 number = theTouchable->GetReplicaNumber( 3 );
140 scinNb = number;
141
142 G4String name1 = theTouchable->GetVolume( 4 )->GetName();
143 if ( name1 == "physicalEcTofEast" ) partId = 3;
144 else if ( name1 == "physicalEcTofWest" ) partId = 4;
145 // G4cout<<"scinNb= "<<scinNb<<" gapNb= "<<gapNb<<" partId="<<partId<<G4endl;
146 }
147 // MRPC ENDCAPS construct by GDML
148 else if ( name == "logical_gasLayer" )
149 {
150 locPos = theTouchable->GetHistory()->GetTopTransform().TransformPoint( pos );
151 number = theTouchable->GetReplicaNumber( 3 );
152 scinNb = 35 - number;
153
154 G4String name1 = theTouchable->GetVolume( 4 )->GetName();
155 if ( name1 == "logicalEcTofEast" ) partId = 3;
156 else if ( name1 == "logicalEcTofWest" ) partId = 4;
157 // G4cout<<"scinNb= "<<scinNb<<" gapNb= "<<gapNb<<" partId="<<partId<<G4endl;
158 }
159
160 // Scintillator
161 else if ( name == "physicalScinBr1" )
162 {
163 partId = 1;
164 scinNb = number;
165 // G4cout<<"scinNb= "<<scinNb<<" partId="<<partId<<G4endl;
166 }
167 else if ( name == "physicalScinBr2" )
168 {
169 partId = 1;
170 scinNb = number + 88;
171 // G4cout<<"scinNb= "<<scinNb<<" partId="<<partId<<G4endl;
172 }
173 else if ( name == "physicalScinEcWest" )
174 {
175 partId = 2;
176 scinNb = number;
177 // G4cout<<"scinNb= "<<scinNb<<" partId="<<partId<<G4endl;
178 }
179 else if ( name == "physicalScinEcEast" )
180 {
181 partId = 0;
182 scinNb = number;
183 // G4cout<<"scinNb= "<<scinNb<<" partId="<<partId<<G4endl;
184 }
185
186 // if construct by gdml files
187 else if ( name == "logicalScinBr1" || name == "logicalScinBr2" )
188 {
189 partId = 1;
190 scinNb = ( 527 - number ) / 3;
191 }
192 // copy number: east:1-95(scinNb:47-0), west:1-95(scinNb:47-0)
193 else if ( name == "logicalScinEcEast" )
194 {
195 partId = 0;
196 scinNb = ( 95 - number ) / 2;
197 }
198 else if ( name == "logicalScinEcWest" )
199 {
200 partId = 2;
201 scinNb = ( 95 - number ) / 2;
202 }
203 else { return false; }
204
205 if ( name.contains( "physical_gasLayer" ) || name.contains( "logical_gasLayer" ) )
206 {
207 G4double zz = locPos.z() - 0.5 * mm +
208 ( 24 + 3 ) * mm * 6; // 0.5mm is the offset between strip and gasLayer
209 if ( zz <= 0 ) { strip = 0; }
210 else if ( zz > 0 && zz < 12 * 27 * mm )
211 {
212 for ( G4int i = 0; i < 12; i++ )
213 {
214 if ( zz > i * 27 * mm && zz <= ( i + 1 ) * 27 * mm )
215 {
216 strip = i;
217 // G4cout<<"Local z is "<<locPos.z()<<" strip number is: "<<strip<<" !!!"<<G4endl;
218 break;
219 }
220 }
221 }
222 else { strip = 11; }
223 if ( strip < 0 ) strip = 0;
224 if ( strip > 11 ) strip = 11;
225 }
226
227 newHit->SetPartId( partId );
228 newHit->SetScinNb( scinNb );
229 newHit->SetGapNb( gapNb );
230 newHit->SetLocPos( locPos );
231 newHit->SetModule( scinNb );
232 newHit->SetStrip( strip );
233 // newHit->SetIons(elIonPair->SampleNumberOfIonsAlongStep(aStep));
234 newHit->SetIons( SampleNumberOfIonsAlongStep( aStep, elIonPair ) );
235 // newHit->Draw();
236
237 G4int trackIndex, g4TrackId;
238 GetCurrentTrackIndex( trackIndex, g4TrackId );
239 newHit->SetTrackIndex( trackIndex );
240 // newHit->Print();
241 if ( edep > 0 ) { m_besTofCollection->insert( newHit ); }
242
243 // for mc truth
244 if ( m_besTofList )
245 {
246 G4int trackIndex, g4TrackId;
247 GetCurrentTrackIndex( trackIndex, g4TrackId );
248 newHit->SetTrackIndex( trackIndex );
249 if ( m_trackIndex != trackIndex )
250 {
251 m_trackIndex = trackIndex;
252 // G4int size = m_trackIndexes.size();
253 // G4int flag=1;
254 // if(size>0)
255 //{
256 // for(G4int i=0;i<size;i++)
257 // if(m_trackIndexes[i] == trackIndex )
258 // {flag =0; break;}
259 // }
260 // if(flag && aStep->GetTrack()->GetTrackID()==g4TrackId )
261 G4int flag = 1;
262 G4int pdg = abs( aStep->GetTrack()->GetDefinition()->GetPDGEncoding() );
263 if ( pdg == 12 || pdg == 14 || pdg == 16 ) { flag = 0; }
264 if ( flag && aStep->GetTrack()->GetTrackID() == g4TrackId )
265 {
266 m_trackIndexes.push_back( trackIndex );
267 BesTofHit* truHit = new BesTofHit();
268 *truHit = *newHit;
269 m_besTofList->insert( truHit );
270 }
271 }
272 }
273 if ( edep <= 0 ) { delete newHit; }
274
275 return true;
276
277} // Close Process Hits
278
279//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
280
281void BesTofSD::EndOfEvent( G4HCofThisEvent* HCE ) {
282 static G4int HCID = -1;
283 if ( HCID < 0 )
284 { HCID = G4SDManager::GetSDMpointer()->GetCollectionID( collectionName[0] ); }
285 HCE->AddHitsCollection( HCID, m_besTofCollection );
286}
287
288//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
289
290G4int BesTofSD::SampleNumberOfIonsAlongStep( const G4Step* step, G4ElectronIonPair* eipair ) {
291 G4double FanoFactor = m_fanoFactor; // 0.2; //Is this value appropiate?
292 G4double meanion = eipair->MeanNumberOfIonsAlongStep( step );
293 G4double sig = std::sqrt( FanoFactor * meanion ); // Be carefull : In originally Geant4 code
294 // this calculatin is wrong!
295 G4int nion = G4int( G4RandGauss::shoot( meanion, sig ) + m_nionOff ); // 0.5);
296 return nion;
297}
G4THitsCollection< BesTofHit > BesTofHitsCollection
void GetCurrentTrackIndex(G4int &trackIndex, G4int &g4TrackId) const
BesSensitiveDetector(const G4String name)
void BeginOfTruthEvent(const G4Event *)
Definition BesTofSD.cc:62
virtual void Initialize(G4HCofThisEvent *HCE)
Definition BesTofSD.cc:56
virtual void EndOfEvent(G4HCofThisEvent *HCE)
Definition BesTofSD.cc:281
BesTofSD(G4String name)
Definition BesTofSD.cc:33
virtual ~BesTofSD()
Definition BesTofSD.cc:52
void EndOfTruthEvent(const G4Event *)
Definition BesTofSD.cc:69
G4int SampleNumberOfIonsAlongStep(const G4Step *, G4ElectronIonPair *)
Definition BesTofSD.cc:290
virtual G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *)
Definition BesTofSD.cc:79