AuxDetAction.cxx
Go to the documentation of this file.
1 //
2 // AuxDetAction.cxx
3 //
4 // Created by Brian Rebel on 11/22/16.
5 //
6 
8 #include "cetlib_except/exception.h"
9 #include "cetlib/search_path.h"
10 
11 #include <algorithm>
12 #include <regex>
13 
14 #include "TGeoMaterial.h"
15 #include "TGeoNode.h"
16 #include "TGeoBBox.h"
17 
18 // G4 includes
19 #include "Geant4/G4Event.hh"
20 #include "Geant4/G4Track.hh"
21 #include "Geant4/G4ThreeVector.hh"
22 #include "Geant4/G4ParticleDefinition.hh"
23 #include "Geant4/G4PrimaryParticle.hh"
24 #include "Geant4/G4DynamicParticle.hh"
25 #include "Geant4/G4VUserPrimaryParticleInformation.hh"
26 #include "Geant4/G4Step.hh"
27 #include "Geant4/G4StepPoint.hh"
28 #include "Geant4/G4VProcess.hh"
29 #include "Geant4/G4MaterialCutsCouple.hh"
30 #include "Geant4/G4NavigationHistory.hh"
31 #include "Geant4/G4EmSaturation.hh"
32 #include "Geant4/G4Version.hh"
33 
34 #include "GArG4/AuxDetAction.h"
36 
37 #include "CoreUtils/ServiceUtil.h"
39 namespace gar {
40 
41  namespace garg4 {
42 
43  //-------------------------------------------------------------
44  // Constructor.
45  AuxDetAction::AuxDetAction(CLHEP::HepRandomEngine* , // engine,
46  fhicl::ParameterSet const& pset)
47  {
48  fGeo = gar::providerFrom<geo::GeometryGAr>();
49  fDetProp = gar::providerFrom<detinfo::DetectorPropertiesService>();
50 
51  this->reconfigure(pset);
52  }
53 
54  //-------------------------------------------------------------
55  // Destructor.
57  {
58  // Delete anything that we created with "new'.
59  }
60 
61  //-------------------------------------------------------------
63  {
64  fLArEnergyCut = pset.get<double>("LArEnergyCut", 0.);
65  fLArVolumeName = pset.get<std::vector<std::string>>("LArVolumeName");
66  fLArMaterial = pset.get<std::string>("LArMaterial", "LAr");
67 
68  fECALMaterial = pset.get<std::string>("ECALMaterial", "Scintillator");
69  fECALVolumeName = pset.get<std::vector<std::string>>("ECALVolumeName");
70 
71  fTrackerScMaterial = pset.get<std::string>("TrackerScMaterial", "Scintillator");
72  fTrackerScVolumeName = pset.get<std::vector<std::string>>("TrackerScVolumeName");
73 
74  fMuIDMaterial = pset.get<std::string>("MuIDMaterial", "Scintillator");
75  fMuIDVolumeName = pset.get<std::vector<std::string>>("MuIDVolumeName");
76 
77  fApplyBirksLaw = pset.get<bool>("ApplyBirksLaw", true);
78 
79  // std::cout << "AuxDetAction: Name of the Volumes to track for the LArTPC" << std::endl;
80  // for(unsigned int i = 0; i < fLArVolumeName.size(); i++) std::cout << fLArVolumeName.at(i) << " ";
81  // std::cout << std::endl;
82 
84 
85  return;
86  }
87 
88  //-------------------------------------------------------------
89  void AuxDetAction::BeginOfEventAction(const G4Event*)
90  {
91  // Clear any previous information.
92  m_ECALDeposits.clear();
93  fECALDeposits.clear();
94 
95  m_TrackerScDeposits.clear();
96  fTrackerScDeposits.clear();
97 
98  m_MuIDDeposits.clear();
99  fMuIDDeposits.clear();
100 
101  fLArDeposits.clear();
102  }
103 
104  //-------------------------------------------------------------
105  void AuxDetAction::PreTrackingAction(const G4Track* /* track */)
106  {
107 
108  }
109 
110  //-------------------------------------------------------------
111  void AuxDetAction::PostTrackingAction( const G4Track* /*track*/)
112  {
113  }
114 
115  //-------------------------------------------------------------
116  // With every step, check and see if we are in an auxdet and save the energy
117  void AuxDetAction::SteppingAction(const G4Step* step)
118  {
119  MF_LOG_DEBUG("AuxDetAction")
120  << "AuxDetAction::SteppingAction";
121 
122  if(fGeo->HasLArTPCDetector())
123  this->LArSteppingAction(step);
124 
125  if(fGeo->HasECALDetector())
126  this->ECALSteppingAction(step);
127 
129  this->TrackerScSteppingAction(step);
130 
131  if(fGeo->HasMuonDetector())
132  this->MuIDSteppingAction(step);
133  }// end of AuxDetAction::SteppingAction
134 
135  //------------------------------------------------------------------------------
136  void AuxDetAction::EndOfEventAction(const G4Event*)
137  {
138  //sort per time the hits
139  if (fGeo->HasLArTPCDetector()) {
140  std::sort(fLArDeposits.begin(), fLArDeposits.end());
141  }
142 
143  if(fGeo->HasECALDetector()) {
145  std::sort(fECALDeposits.begin(), fECALDeposits.end());
146  }
147 
148  if(fGeo->HasTrackerScDetector() && nullptr != fMinervaSegAlg) {
150  std::sort(fTrackerScDeposits.begin(), fTrackerScDeposits.end());
151  }
152 
153  if(fGeo->HasMuonDetector()) {
155  std::sort(fMuIDDeposits.begin(), fMuIDDeposits.end());
156  }
157  }
158 
159  //------------------------------------------------------------------------------
161  {
162  MF_LOG_DEBUG("AuxDetAction")
163  << "AuxDetAction::LArSteppingAction";
164 
165  // Get the pointer to the track
166  G4Track *track = step->GetTrack();
167 
168  const CLHEP::Hep3Vector &start = step->GetPreStepPoint()->GetPosition();
169  const CLHEP::Hep3Vector &stop = track->GetPosition();
170 
171  // If it's a null step, don't use it.
172  if(start == stop) return;
173  if(step->GetTotalEnergyDeposit() == 0) return;
174 
175  // check that we are in the correct material to record a hit
176  const std::string VolumeName = this->GetVolumeName(track);
177  if( std::find_if( fLArVolumeName.begin(), fLArVolumeName.end(), [&VolumeName](std::string s) { return VolumeName.find(s) != std::string::npos; } ) == fLArVolumeName.end() )
178  return;
179 
180  // check the material
181  auto pos = 0.5 * (start + stop);
182  TGeoNode *node = fGeo->FindNode(pos.x()/CLHEP::cm, pos.y()/CLHEP::cm, pos.z()/CLHEP::cm);//Node in cm...
183 
184  if(nullptr == node){
185  MF_LOG_DEBUG("AuxDetAction::LArSteppingAction")
186  << "Node not found in "
187  << pos.x() << " mm "
188  << pos.y() << " mm "
189  << pos.z() << " mm";
190  return;
191  }
192 
193  std::string volmaterial = node->GetMedium()->GetMaterial()->GetName();
194  if ( ! std::regex_match(volmaterial, std::regex(fLArMaterial)) ) return;
195 
196  // only worry about energy depositions larger than the minimum required
197  if(step->GetTotalEnergyDeposit() * CLHEP::MeV / CLHEP::GeV > fLArEnergyCut){
198 
199  MF_LOG_DEBUG("AuxDetAction::LArSteppingAction")
200  << "In volume "
201  << VolumeName
202  << " Material is "
203  << volmaterial
204  << " step size is "
205  << step->GetStepLength() / CLHEP::cm
206  << " cm and deposited "
207  << step->GetTotalEnergyDeposit()
208  << " MeV of energy with a minimum of "
209  << fLArEnergyCut
210  << " required.";
211 
212  // the step mid point is used for the position of the deposit
213  auto midPoint = 0.5 * (step->GetPreStepPoint()->GetPosition() +
214  step->GetPostStepPoint()->GetPosition() );
215 
216  // get the track id for this step
217  auto trackID = ParticleListAction::GetCurrentTrackID();
218  float time = step->GetPreStepPoint()->GetGlobalTime();
219 
220  fLArDeposits.emplace_back(trackID,
221  time,//get the time of the first subhit
222  step->GetTotalEnergyDeposit() * CLHEP::MeV / CLHEP::GeV,
223  midPoint.x() / CLHEP::cm,
224  midPoint.y() / CLHEP::cm,
225  midPoint.z() / CLHEP::cm,
226  step->GetStepLength() / CLHEP::cm,
227  (trackID > 0));
228 
229  } // end if enough energy to worry about this step
230  }
231 
232  //------------------------------------------------------------------------------
234  {
235  MF_LOG_DEBUG("AuxDetAction")
236  << "AuxDetAction::ECALSteppingAction";
237 
238  // Get the pointer to the track
239  G4Track *track = step->GetTrack();
240 
241  const CLHEP::Hep3Vector &start = step->GetPreStepPoint()->GetPosition();
242  const CLHEP::Hep3Vector &stop = track->GetPosition();
243 
244  // If it's a null step, don't use it.
245  if(start == stop) return;
246  if(step->GetTotalEnergyDeposit() == 0) return;
247 
248  // check that we are in the correct material to record a hit
249  const std::string VolumeName = this->GetVolumeName(track);
250 
251  if (std::find_if(fECALVolumeName.begin(), fECALVolumeName.end(), [&VolumeName](std::string s) { return VolumeName.find(s) != std::string::npos; }) == fECALVolumeName.end())
252  return;
253 
254  // check the material
255  auto pos = 0.5 * (start + stop);
256  TGeoNode *node = fGeo->FindNode(pos.x()/CLHEP::cm, pos.y()/CLHEP::cm, pos.z()/CLHEP::cm);//Node in cm...
257 
258  if(nullptr == node){
259  MF_LOG_DEBUG("AuxDetAction::ECALSteppingAction")
260  << "Node not found in "
261  << pos.x() << " mm "
262  << pos.y() << " mm "
263  << pos.z() << " mm";
264  return;
265  }
266 
267  std::string volmaterial = node->GetMedium()->GetMaterial()->GetName();
268  if ( ! std::regex_match(volmaterial, std::regex(fECALMaterial)) ) return;
269 
270  // only worry about energy depositions larger than the minimum required
271  MF_LOG_DEBUG("AuxDetAction::ECALSteppingAction")
272  << "In volume "
273  << VolumeName
274  << " Material is "
275  << volmaterial
276  << " step size is "
277  << step->GetStepLength() / CLHEP::cm
278  << " cm and deposited "
279  << step->GetTotalEnergyDeposit()
280  << " MeV of energy";
281 
282  // the step mid point is used for the position of the deposit
283  G4ThreeVector G4Global = 0.5 * (step->GetPreStepPoint()->GetPosition() + step->GetPostStepPoint()->GetPosition() );
284 
285  //get layer and slice number from the volume name (easier for segmentation later)
286  unsigned int layer = this->GetLayerNumber(VolumeName); //get layer number
287  unsigned int slice = this->GetSliceNumber(VolumeName); // get slice number
288  unsigned int det_id = this->GetDetNumber(VolumeName); // 1 == Barrel, 2 = Endcap
289  unsigned int stave = this->GetStaveNumber(VolumeName); //get the stave number
290  unsigned int module = this->GetModuleNumber(VolumeName); //get the module number
291 
292  MF_LOG_DEBUG("AuxDetAction::ECALSteppingAction")
293  << "det_id " << det_id
294  << " stave " << stave
295  << " module " << module
296  << " layer " << layer
297  << " slice " << slice;
298 
299  //Transform from global coordinates to local coordinates in mm
300  G4ThreeVector G4Local = this->globalToLocal(step, G4Global);
301  //Transform in cm
302  std::array<double, 3> G4Localcm = {G4Local.x() / CLHEP::cm, G4Local.y() / CLHEP::cm, G4Local.z() / CLHEP::cm};
303  //Get cellID
304  raw::CellID_t cellID = fGeo->GetCellID(node, det_id, stave, module, layer, slice, G4Localcm);//encoding the cellID on 64 bits
305 
306  //Don't correct for the strip or tile position yet
307  double G4Pos[3] = {0., 0., 0.}; // in cm
308  G4Pos[0] = G4Global.x() / CLHEP::cm;
309  G4Pos[1] = G4Global.y() / CLHEP::cm;
310  G4Pos[2] = G4Global.z() / CLHEP::cm;
311 
312  // get the track id for this step
313  auto trackID = ParticleListAction::GetCurrentTrackID();
314  float time = step->GetPreStepPoint()->GetGlobalTime();
315 
316  float edep = this->GetStepEnergy(step, true) * CLHEP::MeV / CLHEP::GeV;
317 
318  MF_LOG_DEBUG("AuxDetAction::ECALSteppingAction")
319  << "Energy deposited "
320  << step->GetTotalEnergyDeposit() * CLHEP::MeV / CLHEP::GeV
321  << " GeV in cellID "
322  << cellID
323  << " after Birks "
324  << edep
325  << " GeV";
326 
327  //Create a map of cellID to SimHit
328  gar::sdp::CaloDeposit hit( trackID, time, edep, G4Pos, cellID );
329  if(m_ECALDeposits.find(cellID) != m_ECALDeposits.end())
330  m_ECALDeposits[cellID].push_back(hit);
331  else {
332  std::vector<gar::sdp::CaloDeposit> vechit;
333  vechit.push_back(hit);
334  m_ECALDeposits.emplace(cellID, vechit);
335  }
336  }
337 
338  //------------------------------------------------------------------------------
340  {
341  MF_LOG_DEBUG("AuxDetAction")
342  << "AuxDetAction::TrackerScSteppingAction";
343 
344  // Get the pointer to the track
345  G4Track *track = step->GetTrack();
346 
347  const CLHEP::Hep3Vector &start = step->GetPreStepPoint()->GetPosition();
348  const CLHEP::Hep3Vector &stop = track->GetPosition();
349 
350  // If it's a null step, don't use it.
351  if(start == stop) return;
352  if(step->GetTotalEnergyDeposit() == 0) return;
353 
354  // check that we are in the correct material to record a hit
355  const std::string VolumeName = this->GetVolumeName(track);
356  if( std::find_if( fTrackerScVolumeName.begin(), fTrackerScVolumeName.end(), [&VolumeName](std::string s) { return VolumeName.find(s) != std::string::npos; } ) == fTrackerScVolumeName.end() )
357  return;
358 
359  // check the material
360  auto pos = 0.5 * (start + stop);
361  TGeoNode *node = fGeo->FindNode(pos.x()/CLHEP::cm, pos.y()/CLHEP::cm, pos.z()/CLHEP::cm);//Node in cm...
362 
363  if (nullptr == node)
364  {
365  MF_LOG_DEBUG("AuxDetAction::TrackerScSteppingAction")
366  << "Node not found in "
367  << pos.x()/CLHEP::cm << " cm "
368  << pos.y()/CLHEP::cm << " cm "
369  << pos.z()/CLHEP::cm << " cm in volume "
370  << VolumeName;
371  return;
372  }
373 
374  std::string volmaterial = node->GetMedium()->GetMaterial()->GetName();
375  if ( ! std::regex_match(volmaterial, std::regex(fTrackerScMaterial)) ) return;
376 
377  // only worry about energy depositions larger than the minimum required
378  MF_LOG_DEBUG("AuxDetAction::TrackerScSteppingAction")
379  << "In volume "
380  << VolumeName
381  << " Material is "
382  << volmaterial
383  << " step size is "
384  << step->GetStepLength() / CLHEP::cm
385  << " cm and deposited "
386  << step->GetTotalEnergyDeposit()
387  << " MeV of energy";
388 
389  // the step mid point is used for the position of the deposit
390  G4ThreeVector G4Global = 0.5 * (step->GetPreStepPoint()->GetPosition() + step->GetPostStepPoint()->GetPosition() );
391 
392  //get layer and slice number from the volume name (easier for segmentation later)
393  unsigned int layer = this->GetLayerNumber(VolumeName); //get layer number
394  unsigned int slice = this->GetSliceNumber(VolumeName); // get slice number
395  unsigned int det_id = 3;
396 
397  MF_LOG_DEBUG("AuxDetAction::TrackerScSteppingAction")
398  << "det_id " << det_id
399  << " layer " << layer
400  << " slice " << slice;
401 
402  //Transform from global coordinates to local coordinates in mm
403  G4ThreeVector G4Local = this->globalToLocal(step, G4Global);
404  //Transform in cm
405  std::array<double, 3> G4Localcm = {G4Local.x() / CLHEP::cm, G4Local.y() / CLHEP::cm, G4Local.z() / CLHEP::cm};
406  //Get cellID
407  raw::CellID_t cellID = fGeo->GetCellID(node, det_id, 0, 0, layer, slice, G4Localcm);//encoding the cellID on 64 bits
408 
409  //Don't correct for the strip or tile position yet
410  double G4Pos[3] = {0., 0., 0.}; // in cm
411  G4Pos[0] = G4Global.x() / CLHEP::cm;
412  G4Pos[1] = G4Global.y() / CLHEP::cm;
413  G4Pos[2] = G4Global.z() / CLHEP::cm;
414 
415  // get the track id for this step
416  auto trackID = ParticleListAction::GetCurrentTrackID();
417  float time = step->GetPreStepPoint()->GetGlobalTime();
418  float edep = this->GetStepEnergy(step, true) * CLHEP::MeV / CLHEP::GeV;
419 
420  MF_LOG_DEBUG("AuxDetAction::TrackerScSteppingAction")
421  << "Energy deposited "
422  << step->GetTotalEnergyDeposit() * CLHEP::MeV / CLHEP::GeV
423  << " GeV in cellID "
424  << cellID
425  << " after Birks "
426  << edep
427  << " GeV";
428 
429  //Create a map of cellID to SimHit
430  gar::sdp::CaloDeposit hit( trackID, time, edep, G4Pos, cellID );
431  if(m_TrackerScDeposits.find(cellID) != m_TrackerScDeposits.end())
432  m_TrackerScDeposits[cellID].push_back(hit);
433  else {
434  std::vector<gar::sdp::CaloDeposit> vechit;
435  vechit.push_back(hit);
436  m_TrackerScDeposits.emplace(cellID, vechit);
437  }
438  }
439 
440  //------------------------------------------------------------------------------
442  {
443  MF_LOG_DEBUG("AuxDetAction")
444  << "AuxDetAction::MuIDSteppingAction";
445 
446  // Get the pointer to the track
447  G4Track *track = step->GetTrack();
448 
449  const CLHEP::Hep3Vector &start = step->GetPreStepPoint()->GetPosition();
450  const CLHEP::Hep3Vector &stop = track->GetPosition();
451 
452  // If it's a null step, don't use it.
453  if(start == stop) return;
454  if(step->GetTotalEnergyDeposit() == 0) return;
455 
456  // check that we are in the correct material to record a hit
457  const std::string VolumeName = this->GetVolumeName(track);
458 
459  if (std::find_if(fMuIDVolumeName.begin(), fMuIDVolumeName.end(), [&VolumeName](std::string s) { return VolumeName.find(s) != std::string::npos; }) == fMuIDVolumeName.end())
460  return;
461 
462  // check the material
463  auto pos = 0.5 * (start + stop);
464  TGeoNode *node = fGeo->FindNode(pos.x()/CLHEP::cm, pos.y()/CLHEP::cm, pos.z()/CLHEP::cm);//Node in cm...
465 
466  if (nullptr == node)
467  {
468  MF_LOG_DEBUG("AuxDetAction::MuIDSteppingAction")
469  << "Node not found in "
470  << pos.x() << " mm "
471  << pos.y() << " mm "
472  << pos.z() << " mm";
473  return;
474  }
475 
476  std::string volmaterial = node->GetMedium()->GetMaterial()->GetName();
477  if ( ! std::regex_match(volmaterial, std::regex(fMuIDMaterial)) ) return;
478 
479  // only worry about energy depositions larger than the minimum required
480  MF_LOG_DEBUG("AuxDetAction::MuIDSteppingAction")
481  << "In volume "
482  << VolumeName
483  << " Material is "
484  << volmaterial
485  << " step size is "
486  << step->GetStepLength() / CLHEP::cm
487  << " cm and deposited "
488  << step->GetTotalEnergyDeposit()
489  << " MeV of energy";
490 
491  // the step mid point is used for the position of the deposit
492  G4ThreeVector G4Global = 0.5 * (step->GetPreStepPoint()->GetPosition() + step->GetPostStepPoint()->GetPosition() );
493 
494  //get layer and slice number from the volume name (easier for segmentation later)
495  unsigned int layer = this->GetLayerNumber(VolumeName); //get layer number
496  unsigned int slice = this->GetSliceNumber(VolumeName); // get slice number
497  unsigned int det_id = this->GetDetNumber(VolumeName); // 1 == Barrel, 2 = Endcap
498  unsigned int stave = this->GetStaveNumber(VolumeName); //get the stave number
499  unsigned int module = this->GetModuleNumber(VolumeName); //get the module number
500 
501  MF_LOG_DEBUG("AuxDetAction::MuIDSteppingAction")
502  << "det_id " << det_id
503  << " stave " << stave
504  << " module " << module
505  << " layer " << layer
506  << " slice " << slice;
507 
508  //Transform from global coordinates to local coordinates in mm
509  G4ThreeVector G4Local = this->globalToLocal(step, G4Global);
510  //Transform in cm
511  std::array<double, 3> G4Localcm = {G4Local.x() / CLHEP::cm, G4Local.y() / CLHEP::cm, G4Local.z() / CLHEP::cm};
512  //Get cellID
513  raw::CellID_t cellID = fGeo->GetCellID(node, det_id, stave, module, layer, slice, G4Localcm);//encoding the cellID on 64 bits
514 
515  //Don't correct for the strip or tile position yet
516  double G4Pos[3] = {0., 0., 0.}; // in cm
517  G4Pos[0] = G4Global.x() / CLHEP::cm;
518  G4Pos[1] = G4Global.y() / CLHEP::cm;
519  G4Pos[2] = G4Global.z() / CLHEP::cm;
520 
521  // get the track id for this step
522  auto trackID = ParticleListAction::GetCurrentTrackID();
523  float time = step->GetPreStepPoint()->GetGlobalTime();
524 
525  float edep = this->GetStepEnergy(step, true) * CLHEP::MeV / CLHEP::GeV;
526 
527  MF_LOG_DEBUG("AuxDetAction::MuIDSteppingAction")
528  << "Energy deposited "
529  << step->GetTotalEnergyDeposit() * CLHEP::MeV / CLHEP::GeV
530  << " GeV in cellID "
531  << cellID
532  << " after Birks "
533  << edep
534  << " GeV";
535 
536  //Create a map of cellID to SimHit
537  gar::sdp::CaloDeposit hit( trackID, time, edep, G4Pos, cellID );
538  if(m_MuIDDeposits.find(cellID) != m_MuIDDeposits.end())
539  m_MuIDDeposits[cellID].push_back(hit);
540  else {
541  std::vector<gar::sdp::CaloDeposit> vechit;
542  vechit.push_back(hit);
543  m_MuIDDeposits.emplace(cellID, vechit);
544  }
545  }
546 
547  //------------------------------------------------------------------------------
549  {
550  std::string VolName = track->GetVolume()->GetName();
551  VolName.erase(VolName.length()-3, 3);
552  return VolName;
553  }
554 
555  //------------------------------------------------------------------------------
557  {
558  return std::atoi( (volname.substr( volname.find("layer_") + 6, 2)).c_str() );
559  }
560 
561  //------------------------------------------------------------------------------
563  {
564  return std::atoi( (volname.substr( volname.find("slice") + 5, 1)).c_str() );
565  }
566 
567  //------------------------------------------------------------------------------
569  {
570  unsigned int det_id = 0;
571 
572  if( volname.find("ECal") != std::string::npos )
573  {
574  if( volname.find("Barrel") != std::string::npos )
575  det_id = 1;
576  if( volname.find("Endcap") != std::string::npos )
577  det_id = 2;
578  }
579 
580  if( volname.find("Yoke") != std::string::npos )
581  {
582  if( volname.find("Barrel") != std::string::npos )
583  det_id = 4;
584  if( volname.find("Endcap") != std::string::npos )
585  det_id = 4;
586  }
587 
588  return det_id;
589  }
590 
591  //------------------------------------------------------------------------------
593  {
594  return std::atoi( (volname.substr( volname.find("_stave") + 6, 2)).c_str() );
595  }
596 
597  //------------------------------------------------------------------------------
599  {
600  return std::atoi( (volname.substr( volname.find("_module") + 7, 2)).c_str() );
601  }
602 
603  //------------------------------------------------------------------------------
604  G4ThreeVector AuxDetAction::globalToLocal(const G4Step* step, const G4ThreeVector& glob)
605  {
606  return step->GetPreStepPoint()->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(glob);
607  }
608 
609  //------------------------------------------------------------------------------
610  G4ThreeVector AuxDetAction::localToGlobal(const G4Step* step, const G4ThreeVector& loc)
611  {
612  return step->GetPreStepPoint()->GetTouchable()->GetHistory()->GetTopTransform().Inverse().TransformPoint(loc);
613  }
614 
615  //------------------------------------------------------------------------------
616  float AuxDetAction::GetStepEnergy(const G4Step* step, bool birks)
617  {
618  if(birks){
619  return this->birksAttenuation(step);
620  }
621  else{
622  return step->GetTotalEnergyDeposit();
623  }
624  }
625 
626  //------------------------------------------------------------------------------
628  {
629  #if G4VERSION_NUMBER >= 1001
630  static G4EmSaturation s_emSaturation(1);
631  #else
632  static G4EmSaturation s_emSaturation();
633  s_emSaturation.SetVerbose(1);
634  #endif
635 
636  #if G4VERSION_NUMBER >= 1030
637  static bool s_initialised = false;
638  if(not s_initialised) {
639  s_emSaturation.InitialiseG4Saturation();
640  s_initialised = true;
641  }
642  #endif
643 
644  double energyDeposition = step->GetTotalEnergyDeposit();
645  double length = step->GetStepLength();
646  double niel = step->GetNonIonizingEnergyDeposit();
647  const G4Track* trk = step->GetTrack();
648  const G4ParticleDefinition* particle = trk->GetDefinition();
649  const G4MaterialCutsCouple* couple = trk->GetMaterialCutsCouple();
650  double engyVis = s_emSaturation.VisibleEnergyDeposition(particle,
651  couple,
652  length,
653  energyDeposition,
654  niel);
655  return engyVis;
656  }
657 
658  //------------------------------------------------------------------------------
659  void AuxDetAction::AddHits(const std::map< gar::raw::CellID_t, std::vector<gar::sdp::CaloDeposit> > m_hits, std::vector<gar::sdp::CaloDeposit> &fDeposits)
660  {
661  //Loop over the hits in the map and add them together
662  for(auto const &it : m_hits) {
663 
664  raw::CellID_t cellID = it.first;
665  std::vector<gar::sdp::CaloDeposit> vechit = it.second;
666  std::sort(vechit.begin(), vechit.end()); //sort per time
667 
668  float esum = 0.;
669  float time = vechit.at(0).Time();
670  int trackID = vechit.at(0).TrackID();
671  double pos[3] = { vechit.at(0).X(), vechit.at(0).Y(), vechit.at(0).Z() };
672 
673  for(auto const &hit : vechit) {
674  esum += hit.Energy();
675  }
676 
677  fDeposits.emplace_back( trackID, time, esum, pos, cellID );
678  }
679  }
680  } // garg4
681 
682 } // gar
static constexpr double cm
Definition: Units.h:68
TGeoNode * FindNode(T const &x, T const &y, T const &z) const
float GetStepEnergy(const G4Step *step, bool birks)
unsigned int GetDetNumber(std::string volname)
const gar::geo::GeometryCore * fGeo
geometry information
Definition: AuxDetAction.h:112
bool HasLArTPCDetector() const
Definition: GeometryCore.h:987
std::string fLArMaterial
Material for the LArTPC.
Definition: AuxDetAction.h:88
std::vector< std::string > fECALVolumeName
volume we will record energy depositions in
Definition: AuxDetAction.h:92
std::string string
Definition: nybbler.cc:12
std::vector< std::string > fMuIDVolumeName
volume we will record energy depositions in
Definition: AuxDetAction.h:98
std::string fTrackerScMaterial
Material for the TrackerSc (GArLite)
Definition: AuxDetAction.h:94
AuxDetAction(CLHEP::HepRandomEngine *engine, fhicl::ParameterSet const &pset)
gar::raw::CellID_t GetCellID(const TGeoNode *node, const unsigned int &det_id, const unsigned int &stave, const unsigned int &module, const unsigned int &layer, const unsigned int &slice, const std::array< double, 3 > &localPosition) const
static constexpr double MeV
Definition: Units.h:129
void AddHitsMinerva(std::map< gar::raw::CellID_t, std::vector< gar::sdp::CaloDeposit > > &m_Deposits, std::vector< gar::sdp::CaloDeposit > &fDeposits) const
void LArSteppingAction(const G4Step *)
std::map< gar::raw::CellID_t, std::vector< gar::sdp::CaloDeposit > > m_ECALDeposits
Definition: AuxDetAction.h:103
unsigned int GetSliceNumber(std::string volname)
const detinfo::DetectorProperties * fDetProp
detector properties
Definition: AuxDetAction.h:113
std::map< gar::raw::CellID_t, std::vector< gar::sdp::CaloDeposit > > m_TrackerScDeposits
Definition: AuxDetAction.h:106
G4ThreeVector globalToLocal(const G4Step *step, const G4ThreeVector &glob)
void reconfigure(fhicl::ParameterSet const &pset)
void BeginOfEventAction(const G4Event *)
double fLArEnergyCut
The minimum energy in GeV for a particle to be included in the list.
Definition: AuxDetAction.h:87
fInnerVessel push_back(Point(-578.400000, 0.000000, 0.000000))
std::map< gar::raw::CellID_t, std::vector< gar::sdp::CaloDeposit > > m_MuIDDeposits
Definition: AuxDetAction.h:109
unsigned int GetModuleNumber(std::string volname)
std::string fMuIDMaterial
Material for the MuID.
Definition: AuxDetAction.h:97
static constexpr double GeV
Definition: Units.h:28
T get(std::string const &key) const
Definition: ParameterSet.h:271
unsigned int GetLayerNumber(std::string volname)
std::string GetVolumeName(const G4Track *track)
bool HasTrackerScDetector() const
Definition: GeometryCore.h:996
const gar::geo::seg::MinervaSegmentationAlg * fMinervaSegAlg
Definition: AuxDetAction.h:114
long long int CellID_t
Definition: CaloRawDigit.h:24
std::vector< gar::sdp::CaloDeposit > fMuIDDeposits
energy fDeposits for the MuID
Definition: AuxDetAction.h:110
gar::geo::seg::SegmentationAlg const * MinervaSegmentationAlg() const
Returns the object handling the Sc Tracker segmentation.
Definition: GeometryCore.h:936
Detector simulation of raw signals on wires.
std::vector< gar::sdp::LArDeposit > fLArDeposits
energy fDeposits for the LArTPC
Definition: AuxDetAction.h:101
void AddHits(const std::map< gar::raw::CellID_t, std::vector< gar::sdp::CaloDeposit > > m_hits, std::vector< gar::sdp::CaloDeposit > &fDeposits)
General GArSoft Utilities.
bool HasECALDetector() const
Definition: GeometryCore.h:993
std::string fECALMaterial
Material for the ECAL.
Definition: AuxDetAction.h:91
std::vector< std::string > fTrackerScVolumeName
volume we will record energy depositions in
Definition: AuxDetAction.h:95
void SteppingAction(const G4Step *)
bool HasMuonDetector() const
Definition: GeometryCore.h:999
void ECALSteppingAction(const G4Step *)
#define MF_LOG_DEBUG(id)
std::vector< gar::sdp::CaloDeposit > fTrackerScDeposits
energy fDeposits for the TrackerSc
Definition: AuxDetAction.h:107
void MuIDSteppingAction(const G4Step *)
std::vector< std::string > fLArVolumeName
volume we will record energy depositions in
Definition: AuxDetAction.h:89
G4ThreeVector localToGlobal(const G4Step *step, const G4ThreeVector &loc)
void EndOfEventAction(const G4Event *)
float birksAttenuation(const G4Step *step)
unsigned int GetStaveNumber(std::string volname)
void TrackerScSteppingAction(const G4Step *)
void PreTrackingAction(const G4Track *)
std::vector< gar::sdp::CaloDeposit > fECALDeposits
energy fDeposits for the ECAL
Definition: AuxDetAction.h:104
static QCString * s
Definition: config.cpp:1042
void PostTrackingAction(const G4Track *)