CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SensitiveDetector.cc
Go to the documentation of this file.
2 
3 #include "G4SDManager.hh"
4 #include "G4Step.hh"
5 #include "G4StepPoint.hh"
6 #include "G4Transform3D.hh"
7 #include "G4LogicalVolumeStore.hh"
8 
11 
12 using std::string;
13 
16  edm::ParameterSet const & p) :
17  G4VSensitiveDetector(iname), name(iname) {}
18 
20 
21 void SensitiveDetector::Initialize(G4HCofThisEvent * eventHC) {}
22 
24 {
25  G4SDManager * SDman = G4SDManager::GetSDMpointer();
26  SDman->AddNewDetector(this);
27 }
28 
29 void SensitiveDetector::AssignSD(string & vname)
30 {
31  G4LogicalVolumeStore * theStore = G4LogicalVolumeStore::GetInstance();
32  G4LogicalVolumeStore::const_iterator it;
33  for (it = theStore->begin(); it != theStore->end(); it++)
34  {
35  G4LogicalVolume * v = *it;
36  if (vname==v->GetName()) v->SetSensitiveDetector(this);
37  }
38 }
39 
40 void SensitiveDetector::EndOfEvent(G4HCofThisEvent * eventHC) {}
41 
42 #include "G4TouchableHistory.hh"
43 
45 {
46  currentStep = s;
47  G4StepPoint * preStepPoint = currentStep->GetPreStepPoint();
48  G4ThreeVector globalCoordinates = preStepPoint->GetPosition();
49  if (c == WorldCoordinates) return ConvertToLocal3DPoint(globalCoordinates);
50  G4TouchableHistory * theTouchable=(G4TouchableHistory *)
51  (preStepPoint->GetTouchable());
52  G4ThreeVector localCoordinates = theTouchable->GetHistory()
53  ->GetTopTransform().TransformPoint(globalCoordinates);
54  return ConvertToLocal3DPoint(localCoordinates);
55 }
56 
58 {
59  currentStep = s;
60  G4StepPoint * postStepPoint = currentStep->GetPostStepPoint();
61  G4StepPoint * preStepPoint = currentStep->GetPreStepPoint();
62  G4ThreeVector globalCoordinates = postStepPoint->GetPosition();
63  if (c == WorldCoordinates) return ConvertToLocal3DPoint(globalCoordinates);
64  G4TouchableHistory * theTouchable = (G4TouchableHistory *)
65  (preStepPoint->GetTouchable());
66  G4ThreeVector localCoordinates = theTouchable->GetHistory()
67  ->GetTopTransform().TransformPoint(globalCoordinates);
68  return ConvertToLocal3DPoint(localCoordinates);
69 }
70 
72 {
73  return Local3DPoint(p.x(),p.y(),p.z());
74 }
75 
76 void SensitiveDetector::NaNTrap( G4Step* aStep )
77 {
78 
79  if ( aStep == NULL ) return ;
80 
81  G4Track* CurrentTrk = aStep->GetTrack() ;
82  G4ThreeVector CurrentPos = CurrentTrk->GetPosition() ;
83  G4ThreeVector CurrentMom = CurrentTrk->GetMomentum() ;
84  G4VPhysicalVolume* pCurrentVol = CurrentTrk->GetVolume() ;
85  G4String NameOfVol ;
86  if ( pCurrentVol != NULL )
87  {
88  NameOfVol = pCurrentVol->GetName() ;
89  }
90  else
91  {
92  NameOfVol = "CorruptedVolumeInfo" ;
93  }
94 
95  // for simplicity... maybe edm::isNotFinite() will work on the 3-vector directly...
96  //
97  double xyz[3] ;
98  xyz[0] = CurrentPos.x() ;
99  xyz[1] = CurrentPos.y() ;
100  xyz[2] = CurrentPos.z() ;
101 
102  //
103  // this is another trick to check on a NaN, maybe it's even CPU-faster...
104  // but ler's stick to system function edm::isNotFinite(...) for now
105  //
106  // if ( !(xyz[0]==xyz[0]) || !(xyz[1]==xyz[1]) || !(xyz[2]==xyz[2]) )
107  if( edm::isNotFinite(xyz[0]+xyz[1]+xyz[2]) != 0 )
108  {
109  // std::cout << " NaN detected in volume " << NameOfVol << std::endl ;
110  throw SimG4Exception( "SimG4CoreSensitiveDetector: Corrupted Event - NaN detected (position)" ) ;
111  }
112 
113  xyz[0] = CurrentMom.x() ;
114  xyz[1] = CurrentMom.y() ;
115  xyz[2] = CurrentMom.z() ;
116  if ( !(xyz[0]==xyz[0]) || !(xyz[1]==xyz[1]) || !(xyz[2]==xyz[2]) ||
117  edm::isNotFinite(xyz[0]) != 0 || edm::isNotFinite(xyz[1]) != 0 || edm::isNotFinite(xyz[2]) != 0 )
118  {
119  std::cout << " NaN detected in volume " << NameOfVol << std::endl ;
120  throw SimG4Exception( "SimG4CoreSensitiveDetector: Corrupted Event - NaN detected (3-momentum)" ) ;
121  }
122 
123  return ;
124 
125 }
126 
127 
128 
virtual ~SensitiveDetector()
Local3DPoint ConvertToLocal3DPoint(G4ThreeVector point)
SensitiveDetector(std::string &iname, const DDCompactView &cpv, SensitiveDetectorCatalog &, edm::ParameterSet const &p)
#define NULL
Definition: scimark2.h:8
type of data representation of DDCompactView
Definition: DDCompactView.h:77
bool isNotFinite(T x)
Definition: isFinite.h:10
void NaNTrap(G4Step *step)
Point3DBase< float, LocalTag > Local3DPoint
Definition: LocalPoint.h:9
virtual void AssignSD(std::string &vname)
virtual void EndOfEvent(G4HCofThisEvent *eventHC)
tuple cout
Definition: gather_cfg.py:121
Local3DPoint FinalStepPosition(G4Step *s, coordinates)
Local3DPoint InitialStepPosition(G4Step *s, coordinates)
virtual void Initialize(G4HCofThisEvent *eventHC)