15 #include <DDG4/Geant4SensDetAction.inl>
18 #include <G4OpticalPhoton.hh>
19 #include <G4VProcess.hh>
29 struct Geant4VoidSensitive {};
52 G4TouchableHistory* ) {
59 G4TouchableHistory* ) {
78 m_collectionID = declareReadoutFilteredCollection<Geant4Tracker::Hit>();
88 auto contrib = Hit::extractContribution(step);
90 double hit_deposit = h.
deposit();
91 Hit* hit =
new Hit(contrib, hit_momentum, hit_deposit);
93 hit->cellID = cellID(step);
94 if ( 0 == hit->cellID ) {
95 hit->cellID = volumeID(step);
96 except(
"+++ Invalid CELL ID for hit!");
98 collection(m_collectionID)->add(hit);
100 print(
"Hit with deposit:%f Pos:%f %f %f ID=%016X",
101 hit->energyDeposit,hit->position.X(),hit->position.Y(),hit->position.Z(),(
void*)hit->cellID);
103 print(
" Geant4 path:%s",handler.
path().c_str());
110 G4TouchableHistory* )
114 auto contrib = Hit::extractContribution(spot);
118 if ( 0 == hit->cellID ) {
120 except(
"+++ Invalid CELL ID for hit!");
122 collection(m_collectionID)->add(hit);
124 print(
"Hit with deposit:%f Pos:%f %f %f ID=%016X",
125 hit->energyDeposit,hit->position.X(),hit->position.Y(),hit->position.Z(),(
void*)hit->cellID);
127 print(
" Geant4 path:%s",handler.
path().c_str());
151 m_collectionID = declareReadoutFilteredCollection<Geant4Tracker::Hit>();
161 auto contrib = Hit::extractContribution(step);
163 double hit_deposit = contrib.deposit;
164 Hit* hit =
new Hit(contrib, hit_momentum, hit_deposit);
166 if (h.
trackDef() == G4OpticalPhoton::OpticalPhotonDefinition()) {
167 step->GetTrack()->SetTrackStatus(fStopAndKill);
169 hit->cellID = cellID(step);
170 if ( 0 == hit->cellID ) {
171 hit->cellID = volumeID( step ) ;
172 except(
"+++ Invalid CELL ID for hit!");
174 collection(m_collectionID)->add(hit);
176 print(
"Hit with deposit:%f Pos:%f %f %f ID=%016X",
177 hit->energyDeposit,hit->position.X(),hit->position.Y(),hit->position.Z(),(
void*)hit->cellID);
179 print(
" Geant4 path:%s",handler.
path().c_str());
186 G4TouchableHistory* )
190 auto contrib = Hit::extractContribution(spot);
191 Hit* hit =
new Hit(contrib, h.
momentum(), contrib.deposit);
194 if ( 0 == hit->cellID ) {
196 except(
"+++ Invalid CELL ID for hit!");
198 collection(m_collectionID)->add(hit);
200 print(
"Hit with deposit:%f Pos:%f %f %f ID=%016X",
201 hit->energyDeposit,hit->position.X(),hit->position.Y(),hit->position.Z(),(
void*)hit->cellID);
203 print(
" Geant4 path:%s",handler.
path().c_str());
223 m_collectionID = declareReadoutFilteredCollection<Geant4Calorimeter::Hit>();
231 HitContribution contrib = Hit::extractContribution(step);
237 }
catch(std::runtime_error &e) {
238 std::stringstream out;
239 out << std::setprecision(20) << std::scientific;
240 out <<
"ERROR: " << e.what() << std::endl;
242 <<
"Pre (" << std::setw(24) << step->GetPreStepPoint()->GetPosition() <<
") "
243 <<
"Post (" << std::setw(24) << step->GetPostStepPoint()->GetPosition() <<
") "
246 <<
" Pre (" <<std::setw(24) << step->GetPreStepPoint() ->GetMomentum() <<
") "
247 <<
" Post (" <<std::setw(24) << step->GetPostStepPoint()->GetMomentum() <<
") "
249 std::cout << out.str();
259 hit =
new Hit(global);
261 coll->
add(cell, hit);
262 printM2(
"%s> CREATE hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f %s [%s]",
263 c_name(),contrib.deposit,pos.
X,pos.
Y,pos.
Z,handler.
path().c_str(),
264 coll->GetName().c_str());
265 if ( 0 == hit->cellID ) {
266 hit->cellID = cellID(step);
267 except(
"+++ Invalid CELL ID for hit!");
270 hit->truth.emplace_back(contrib);
271 hit->energyDeposit += contrib.deposit;
278 G4TouchableHistory* )
282 HitContribution contrib = Hit::extractContribution(spot);
288 }
catch(std::runtime_error &e) {
289 std::stringstream out;
290 out << std::setprecision(20) << std::scientific;
291 out <<
"ERROR: " << e.what() << std::endl;
292 out <<
"Position: (" << std::setw(24) << h.
avgPositionG4() <<
") " << std::endl;
293 out <<
"Momentum: (" << std::setw(24) << h.
momentumG4() <<
") " << std::endl;
294 std::cout << out.str();
302 hit =
new Hit(global);
304 coll->
add(cell, hit);
305 printM2(
"%s> CREATE hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f %s [%s]",
306 c_name(),contrib.deposit,pos.
X,pos.
Y,pos.
Z,handler.
path().c_str(),
307 coll->GetName().c_str());
308 if ( 0 == hit->cellID ) {
310 except(
"+++ Invalid CELL ID for hit!");
313 hit->truth.emplace_back(contrib);
314 hit->energyDeposit += contrib.deposit;
342 m_collectionID = declareReadoutFilteredCollection<Geant4Calorimeter::Hit>();
347 G4Track * track = step->GetTrack();
349 if( track->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition() ) {
352 else if ( track->GetCreatorProcess()->G4VProcess::GetProcessName() !=
"Cerenkov") {
353 track->SetTrackStatus(fStopAndKill);
360 HitContribution contrib = Hit::extractContribution(step);
365 hit->cellID = volumeID(step);
367 if ( 0 == hit->cellID ) {
368 hit->cellID = volumeID(step);
369 except(
"+++ Invalid CELL ID for hit!");
372 hit->energyDeposit += contrib.deposit;
373 hit->truth.emplace_back(contrib);
374 track->SetTrackStatus(fStopAndKill);
383 G4TouchableHistory* )
387 const G4Track* track = h.
track;
388 if( track->GetDefinition() != G4OpticalPhoton::OpticalPhotonDefinition() ) {
391 else if ( track->GetCreatorProcess()->G4VProcess::GetProcessName() !=
"Cerenkov") {
396 HitContribution contrib = Hit::extractContribution(spot);
403 if ( 0 == hit->cellID ) {
405 except(
"+++ Invalid CELL ID for hit!");
408 hit->energyDeposit += contrib.deposit;
409 hit->truth.emplace_back(contrib);
438 m_collectionID = declareReadoutFilteredCollection<Geant4Calorimeter::Hit>();
445 HitContribution contrib = Hit::extractContribution(step,
true);
450 }
catch(std::runtime_error &e) {
451 std::stringstream out;
452 out << std::setprecision(20) << std::scientific;
453 out <<
"ERROR: " << e.what() << std::endl;
455 <<
"Pre (" << std::setw(24) << step->GetPreStepPoint()->GetPosition() <<
") "
456 <<
"Post (" << std::setw(24) << step->GetPostStepPoint()->GetPosition() <<
") "
459 <<
" Pre (" <<std::setw(24) << step->GetPreStepPoint() ->GetMomentum() <<
") "
460 <<
" Post (" <<std::setw(24) << step->GetPostStepPoint()->GetMomentum() <<
") "
462 std::cout << out.str();
470 hit =
new Hit(global);
472 coll->
add(cell, hit);
473 printM2(
"CREATE hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f %s",
474 contrib.deposit,pos.
X,pos.
Y,pos.
Z,handler.
path().c_str());
475 if ( 0 == hit->cellID ) {
476 hit->cellID = cellID(step);
477 except(
"+++ Invalid CELL ID for hit!");
480 hit->truth.emplace_back(contrib);
481 hit->energyDeposit += contrib.deposit;
489 G4TouchableHistory* )
493 HitContribution contrib = Hit::extractContribution(spot);
499 }
catch(std::runtime_error &e) {
500 std::stringstream out;
501 out << std::setprecision(20) << std::scientific;
502 out <<
"ERROR: " << e.what() << std::endl;
503 out <<
"Position: (" << std::setw(24) << h.
avgPositionG4() <<
") " << std::endl;
504 out <<
"Momentum: (" << std::setw(24) << h.
momentumG4() <<
") " << std::endl;
505 std::cout << out.str();
513 hit =
new Hit(global);
515 coll->
add(cell, hit);
516 printM2(
"CREATE hit with deposit:%e MeV Pos:%8.2f %8.2f %8.2f %s",
517 contrib.deposit,pos.
X,pos.
Y,pos.
Z,handler.
path().c_str());
518 if ( 0 == hit->cellID ) {
520 except(
"+++ Invalid CELL ID for hit!");
523 hit->truth.emplace_back(contrib);
524 hit->energyDeposit += contrib.deposit;
578 void start(
const G4Step* step,
const G4StepPoint* point) {
581 firstSpotVolume = step->GetPreStepPoint()->GetTouchableHandle()->GetVolume();
642 depo, time, path_len, pos, mom);
644 collection->
add(hit);
645 sensitive->
printM2(
"+++ TrackID:%6d [%s] CREATE hit combination with %2d deposit(s):"
646 " %e MeV Pos:%8.2f %8.2f %8.2f",
648 pos.X()/CLHEP::mm,pos.Y()/CLHEP::mm,pos.Z()/CLHEP::mm);
654 G4bool
process(
const G4Step* step, G4TouchableHistory* ) {
672 if ( prePV != postPV ) {
673 void* postSD = h.
sd(h.
post);
676 void* preSD = h.
sd(h.
pre);
677 if ( preSD == postSD ) {
682 else if ( h.
track->GetTrackStatus() == fStopAndKill ) {
705 void* postSD = h.
sd();
708 void* preSD = prePV ? prePV->GetLogicalVolume()->GetSensitiveDetector() :
nullptr;
709 if ( preSD == postSD ) {
714 else if ( h.
track->GetTrackStatus() == fStopAndKill ) {
738 m_userData.e_cut = m_sensitive.energyCutoff();
739 m_userData.sensitive =
this;
744 m_collectionID = declareReadoutFilteredCollection<Geant4Tracker::Hit>();
755 return m_userData.process(step, history);
761 G4TouchableHistory* history) {
762 return m_userData.process(spot, history);