69 {
70
71
72 gErrorIgnoreLevel = kFatal;
73
74 G4double edep = aStep->GetTotalEnergyDeposit();
75 G4double stepl = aStep->GetStepLength();
76 if ( ( edep == 0. ) && ( stepl == 0. ) ) return false;
77
78 G4TouchableHistory* theTouchable =
79 (G4TouchableHistory*)( aStep->GetPreStepPoint()->GetTouchable() );
80 G4VPhysicalVolume* physVol = theTouchable->GetVolume();
81
82 if ( physVol->GetName().contains( "physicalCrystal" ) )
83 {
84 PartId = 1;
85 CryNumberPhi = theTouchable->GetReplicaNumber( 2 );
86 CryNumberTheta = theTouchable->GetReplicaNumber( 1 );
87 }
88 else if ( physVol->GetName().contains( "logicalCrystal" ) )
89 {
90 PartId = 1;
91 std::istringstream thetaBuf( ( theTouchable->GetVolume( 1 )->GetName() ).substr( 16, 2 ) );
92 thetaBuf >> CryNumberTheta;
93 CryNumberPhi = 308 - theTouchable->GetCopyNumber( 2 );
94 }
95 else if ( physVol->GetName().contains( "physicalEndCrystal" ) )
96 {
97 PartId = theTouchable->GetReplicaNumber( 3 );
98 G4int endSector = theTouchable->GetReplicaNumber( 2 );
99 G4int endNb = theTouchable->GetReplicaNumber( 0 );
101 }
102 else if ( physVol->GetName().contains( "logicalEndCrystal" ) )
103 {
104 PartId = 2 - 2 * theTouchable->GetCopyNumber( 3 );
105 G4int endSector = theTouchable->GetCopyNumber( 2 );
106 G4int endNb, endNbGDML;
107 std::istringstream thetaBuf( ( theTouchable->GetVolume( 0 )->GetName() ).substr( 20, 2 ) );
108 thetaBuf >> endNb;
112 }
113 else if ( physVol->GetName().contains( "physicalPD" ) )
114 {
115 edep *= 50.;
116 PartId = 1;
117 CryNumberPhi = theTouchable->GetReplicaNumber( 2 );
118 CryNumberTheta = theTouchable->GetReplicaNumber( 1 );
119 }
120 else if ( physVol->GetName().contains( "logicalPD" ) )
121 {
122 edep *= 50.;
123 PartId = 1;
124 G4int nb = theTouchable->GetCopyNumber( 1 );
125 if ( nb == 216 ) { CryNumberTheta = 0; }
126 else { CryNumberTheta = 43 - ( nb - 2 ) / 5; }
127 CryNumberPhi = 308 - theTouchable->GetCopyNumber( 2 );
128 }
129
130 if ( verboseLevel > 1 )
131 G4cout << "(Check ID)New EMC Hit on crystal: " << CryNumberPhi << "(phi)" << CryNumberTheta
132 << "(theta)"
133 << " and the volume is " << physVol->GetName() << G4endl;
134
135
136 G4int trackId = aStep->GetTrack()->GetTrackID();
137
138 BesEmcHit* calHit = new BesEmcHit();
143 calHit->
SetPosCrystal( aStep->GetPreStepPoint()->GetPosition() );
144 calHit->
SetTimeCrystal( aStep->GetPreStepPoint()->GetGlobalTime() );
145 calHit->
SetMomentum( aStep->GetPreStepPoint()->GetMomentum() );
146 calHit->
SetNumCrystal( PartId, CryNumberTheta, CryNumberPhi );
147
148 if ( edep > 0 )
149 {
150 G4int idhit = CalCollection->insert( calHit ) - 1;
151 if ( nHit < 40000 ) HitID[nHit] = idhit;
152 nHit++;
153 }
154 else
155 {
156 delete calHit;
157
158
159 }
160
161
162 if ( CalList )
163 {
164 G4int trackIndex, g4TrackId;
167
168 if ( m_trackIndex != trackIndex )
169 {
170 m_trackIndex = trackIndex;
171
173 G4int pdg =
abs( aStep->GetTrack()->GetDefinition()->GetPDGEncoding() );
174 if ( pdg == 12 || pdg == 14 || pdg == 16 )
175 {
177 }
178
179 if (
flag && aStep->GetTrack()->GetTrackID() == g4TrackId )
180 {
181 BesEmcHit* truHit = new BesEmcHit();
186 truHit->
SetPosCrystal( aStep->GetPreStepPoint()->GetPosition() );
187 truHit->
SetTimeCrystal( aStep->GetPreStepPoint()->GetGlobalTime() );
188 truHit->
SetMomentum( aStep->GetPreStepPoint()->GetMomentum() );
189 truHit->
SetNumCrystal( PartId, CryNumberTheta, CryNumberPhi );
190 CalList->insert( truHit );
191 }
192 }
193
194 else if ( m_trackIndex == trackIndex )
195 {
196 G4int length = CalList->entries();
197 if ( length >= 1 )
198 {
199 for ( G4int i = 0; i < length; i++ )
200 {
201 BesEmcHit* oldHit = ( *CalList )[i];
203 {
205 break;
206 }
207 }
208 }
209 }
210 }
211
212
213 if ( CalTruthList )
214 {
215 G4int trackIndex, g4TrackId;
218
220 if ( CalTruthList->entries() > 0 )
221 {
222 for ( G4int i = 0; i < CalTruthList->entries(); i++ )
223 {
224 BesEmcTruthHit* oldHit = ( *CalTruthList )[i];
226 {
229 if ( oldHit->
Find(
id ) != oldHit->
End() ) { oldHit->
AddEHit(
id, edep ); }
230 else { oldHit->
Insert(
id, edep ); }
231 break;
232 }
233 }
234 }
235
237 {
238 G4int pdg =
abs( aStep->GetTrack()->GetDefinition()->GetPDGEncoding() );
239 if ( !( pdg == 12 || pdg == 14 || pdg == 16 ) )
240 {
241 BesEmcTruthHit* truHit = new BesEmcTruthHit;
246 truHit->
Insert(
id, edep );
247
248 if ( aStep->GetTrack()->GetTrackID() == g4TrackId )
249 {
251 truHit->
SetPDGCode( aStep->GetTrack()->GetDefinition()->GetPDGEncoding() );
252 truHit->
SetPDGCharge( aStep->GetTrack()->GetDefinition()->GetPDGCharge() );
253 truHit->
SetParticleName( aStep->GetTrack()->GetDefinition()->GetParticleName() );
254 truHit->
SetTime( aStep->GetPreStepPoint()->GetGlobalTime() );
255 truHit->
SetPosition( aStep->GetPreStepPoint()->GetPosition() );
256 truHit->
SetMomentum( aStep->GetPreStepPoint()->GetMomentum() );
257 }
258 else
259 {
260
262 std::vector<BesTruthTrack*>* trackList = sensitiveManager->
GetTrackList();
263
264 for ( unsigned i = 0; i < trackList->size(); i++ )
265 {
266 BesTruthTrack* truthTrack = ( *trackList )[i];
267
268 if ( trackIndex == truthTrack->
GetIndex() )
269 {
274
276 {
279 }
280 else
281 {
283 truHit->
SetPosition( G4ThreeVector( -99, -99, -99 ) );
284 }
285
286 break;
287 }
288 }
289 }
290
291 CalTruthList->insert( truHit );
292 }
293 }
294 }
295
296 return true;
297}
void SetNumCrystal(G4int id, G4int numTheta, G4int numPhi)
void SetEdepCrystal(G4double de)
void SetMomentum(G4ThreeVector momen)
G4double GetEdepCrystal()
void SetPosCrystal(G4ThreeVector position)
void SetTimeCrystal(G4double t)
void SetTrakCrystal(G4double dl)
void SetG4Index(G4int index)
void SetTrackIndex(G4int index)
G4int ComputeEndCopyNb(G4int)
void ComputeThetaPhi(G4int, G4int, G4int)
G4int EndPhiNumberForGDML(G4int)
void SetIdentify(Identifier id)
G4int GetTrackIndex() const
void SetMomentum(G4ThreeVector p)
void SetPosition(G4ThreeVector pos)
void AddEHit(Identifier, G4double)
void SetPDGCode(G4int code)
void SetTrackIndex(G4int index)
std::map< Identifier, G4double >::const_iterator End() const
std::map< Identifier, G4double >::const_iterator Find(Identifier) const
void Insert(Identifier, G4double)
void SetG4TrackId(G4int trackId)
void SetEDep(G4double de)
void SetParticleName(G4String name)
void SetTime(G4double time)
void SetPDGCharge(G4double charge)
void GetCurrentTrackIndex(G4int &trackIndex, G4int &g4TrackId) const
std::vector< BesTruthTrack * > * GetTrackList()
static BesSensitiveManager * GetSensitiveManager()
BesTruthVertex * GetTerminalVertex() const
G4double GetPDGCharge() const
G4String GetParticleName() const
G4ThreeVector GetPosition() const
static Identifier crystal_id(const unsigned int barrel_ec, const unsigned int theta_module, const unsigned int phi_module)
For a single crystal.