Geant4  10.03
CCaloSD.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
27 // File: CCaloSD.cc
28 // Description: Stores hits of calorimetric type in appropriate container
30 
31 #include "CCaloSD.hh"
32 #include "G4SystemOfUnits.hh"
33 #include "G4VProcess.hh"
34 #include "G4SDManager.hh"
35 #include "G4VTouchable.hh"
36 #include "CCalVOrganization.hh"
37 #include "CCalSDList.hh"
38 
39 //#define debug
40 //#define ddebug
41 
43  G4VSensitiveDetector(name), HCID(-1), SDname(name), theHC(0),
44  CurrentHit(0), theTrack(0), CurrentPV(0), PreviousPV(0), UnitID(0),
45  PreviousUnitID(0), PreStepPoint(0), PostStepPoint(0),
46  theDescription(numberingScheme) {
47 
48  collectionName.insert(name);
49 
50  G4cout << "*******************************************************" << G4endl;
51  G4cout << "* *" << G4endl;
52  G4cout << "* Constructing a CCaloSD with name " << name << G4endl;
53  G4cout << "* *" << G4endl;
54  G4cout << "*******************************************************" << G4endl;
55 
57 }
58 
59 
61  G4cout << "CCaloSD: " << SDname << " deleted" << G4endl;
62  if (theDescription)
63  delete theDescription;
64 }
65 
66 
68 
69 #ifdef debug
70  G4cout << "CCaloSD : Initialize called for " << SDname << G4endl;
71 #endif
72  //This initialization is performed at the beginning of an event
73  //------------------------------------------------------------
74 
76  if (HCID<0)
78  HCE->AddHitsCollection( HCID, theHC );
79 
80  TSID = -2;
81  PrimID = -2;
83 }
84 
85 
87 
88  if (aStep == NULL) return true;
89 
90  getStepInfo(aStep);
91  if (hitExists() == false && EdepositEM+EdepositEHAD>0.)
92  createNewHit();
93 
94  return true;
95 }
96 
97 
99 
100  PreStepPoint = aStep->GetPreStepPoint();
101  PostStepPoint= aStep->GetPostStepPoint();
103 
104  theTrack = aStep->GetTrack();
106 
107  G4String particleType = theTrack->GetDefinition()->GetParticleName();
108 
109  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
110  G4double weight;
111  if (touch->GetVolume(0)->GetName() == "CrystalMatrixCrystal")
112  weight = curve_LY(PreStepPoint);
113  else
114  weight = 1.;
115 
116  if (particleType == "e-" ||
117  particleType == "e+" ||
118  particleType == "gamma" ){
119  EdepositEM = weight*(aStep->GetTotalEnergyDeposit());
120  EdepositEHAD = 0.;
121  } else {
122  EdepositEM = 0.;
123  EdepositEHAD = weight*(aStep->GetTotalEnergyDeposit());
124  }
125 
127 
128  if ( TSlice > 1.0E9 ) TSliceID = 999999999;
129  else TSliceID = (int) TSlice;
130 
131  if (theDescription!=0)
132  UnitID = theDescription->GetUnitID(aStep);
133  else
134  UnitID = 0;
135 
136 }
137 
138 
140 
141  if (PrimaryID<1) {
142  G4cerr << "***** CCaloSD error: PrimaryID = " << PrimaryID
143  << " Maybe detector name changed"
144  << G4endl;
145  }
146 
147 
148  if ( CurrentPV==PreviousPV && PrimaryID == PrimID && TSliceID == TSID &&
150  updateHit();
151  return true;
152  }
153 
154 
155  if (PrimaryID != PrimID)
157 
158 
159  //look in HC whether a hit with the same primID,UnitID,TSliceID exists already:
160 
161  G4bool found = false;
162  for (G4int j=0; j<theHC->entries()&&!found; j++) {
163 
164  CCalG4Hit* aPreviousHit = (*theHC)[j];
165  if (aPreviousHit->getTrackID() == PrimaryID &&
166  aPreviousHit->getTimeSliceID() == TSliceID &&
167  aPreviousHit->getUnitID()== UnitID ) {
168  CurrentHit = aPreviousHit;
169  found = true;
170  }
171  }
172 
173  if (found) {
174  updateHit();
175  return true;
176  } else {
177  return false;
178  }
179 }
180 
181 
183 
186 
187 }
188 
189 
191 
192  if (PrimID<0) return;
193  if (hit == 0 ) {
194  G4cout << "CCaloSD: hit to be stored is NULL !!" <<G4endl;
195  return;
196  }
197 
198  theHC->insert( hit );
199 }
200 
201 
203 
204 #ifdef debug
205  G4int currentCopyNo = -999;
206  G4int motherCopyNo = -999;
207  G4TouchableHistory* theTouchable
209  if ( theTouchable ) {
210  currentCopyNo = theTouchable->GetReplicaNumber( 0 );
211  if ( theTouchable->GetHistoryDepth() > 0 ) {
212  motherCopyNo = theTouchable->GetReplicaNumber( 1 );
213  }
214  }
215  G4cout << "CCaloSD createNewHit for"
216  << " PV " << CurrentPV->GetName()
217  << " PVid = " << currentCopyNo
218  << " MVid = " << motherCopyNo
219  << " Unit " << UnitID <<G4endl;
220  G4cout << " primary " << PrimaryID
221  << " time slice " << TSliceID
222  << " For Track " << theTrack->GetTrackID()
223  << " which is a " << theTrack->GetDefinition()->GetParticleName();
224 
225  if (theTrack->GetTrackID()==1) {
226  G4cout << " of energy " << theTrack->GetTotalEnergy();
227  } else {
228  G4cout << " daughter of part. " << theTrack->GetParentID();
229  }
230 
231  G4cout << " and created by " ;
232  if (theTrack->GetCreatorProcess()!=NULL)
234  else
235  G4cout << "NO process";
236  G4cout << G4endl;
237 #endif
238 
239 
240  CurrentHit = new CCalG4Hit;
246  updateHit();
247 
249 
250 }
251 
252 
254  if (EdepositEM+EdepositEHAD != 0) {
256 #ifdef debug
257  G4cout << "Energy deposit in Unit " << UnitID << " em " << EdepositEM/MeV
258  << " hadronic " << EdepositEHAD/MeV << " MeV" << G4endl;
259 #endif
260  }
261 
262  // buffer for next steps:
263  TSID = TSliceID;
264  PrimID = PrimaryID;
267 }
268 
269 
271 
272  G4ThreeVector localPoint;
273  const G4VTouchable* touch= PreStepPoint->GetTouchable();
274  localPoint=touch->GetHistory()->GetTopTransform().TransformPoint(global);
275 
276  return localPoint;
277 
278 }
279 
280 
282  summarize();
283 }
284 
285 
287 }
288 
289 
291 }
292 
293 
295 }
296 
297 
299  G4cout << "CCaloSD: Collection " << theHC->GetName() << G4endl;
300  theHC->PrintAllHits();
301 }
302 
303 
305 
306  if (theDescription!=0)
307  delete theDescription;
308  theDescription = org;
309 }
310 
311 
313 
314  G4double weight = 1.;
315  G4ThreeVector localPoint = SetToLocal(stepPoint->GetPosition());
316  G4double crlength = 230.;
317  G4double dapd = 0.5 * crlength - localPoint.z();
318  if (dapd >= -0.1 || dapd <= crlength+0.1) {
319  if (dapd <= 100.)
320  weight = 1.05 - dapd * 0.0005;
321  } else {
322  G4cout << "CCaloSD, light coll curve : wrong distance to APD " << dapd
323  << " crlength = " << crlength
324  << " z of localPoint = " << localPoint.z()
325  << " take weight = " << weight << G4endl;
326  }
327 #ifdef ddebug
328  G4cout << "CCaloSD, light coll curve : " << dapd
329  << " crlength = " << crlength
330  << " z of localPoint = " << localPoint.z()
331  << " take weight = " << weight << G4endl;
332 #endif
333  return weight;
334 }
CCalVOrganization * theDescription
Definition: CCaloSD.hh:126
G4ParticleDefinition * GetDefinition() const
G4int GetParentID() const
G4double curve_LY(G4StepPoint *stepPoint)
Definition: CCaloSD.cc:312
void createNewHit()
Definition: CCaloSD.cc:202
void getStepInfo(G4Step *aStep)
Definition: CCaloSD.cc:98
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:135
G4int GetHistoryDepth() const
CLHEP::Hep3Vector G4ThreeVector
CCalG4HitCollection * theHC
Definition: CCaloSD.hh:97
void PrintAll()
Definition: CCaloSD.cc:298
G4THitsCollection< CCalG4Hit > CCalG4HitCollection
unsigned int UnitID
Definition: CCaloSD.hh:104
G4StepPoint * PreStepPoint
Definition: CCaloSD.hh:108
G4int PrimID
Definition: CCaloSD.hh:91
static CCalSDList * getInstance()
Definition: CCalSDList.cc:37
float EdepositEM
Definition: CCaloSD.hh:110
void setIncidentEnergy(double e)
Definition: CCalHit.cc:69
virtual void PrintAllHits()
void SetOrganization(CCalVOrganization *org)
Definition: CCaloSD.cc:304
G4int entries() const
void StoreHit(CCalG4Hit *ahit)
Definition: CCaloSD.cc:190
virtual const G4NavigationHistory * GetHistory() const
Definition: G4VTouchable.cc:86
G4ThreeVector SetToLocal(G4ThreeVector globalPoint)
Definition: CCaloSD.cc:270
G4int insert(T *aHit)
void setEntry(CLHEP::Hep3Vector xyz)
Definition: CCalHit.cc:66
const char * name(G4int ptype)
G4VPhysicalVolume * CurrentPV
Definition: CCaloSD.hh:102
const G4VTouchable * GetTouchable() const
int G4int
Definition: G4Types.hh:78
static constexpr double nanosecond
Definition: G4SIunits.hh:158
G4String SDname
Definition: CCaloSD.hh:96
const G4String & GetParticleName() const
float IncidentEnergy
Definition: CCaloSD.hh:90
CCaloSD(G4String aSDname, CCalVOrganization *numberingScheme)
Definition: CCaloSD.cc:42
G4StepPoint * GetPreStepPoint() const
void EndOfEvent(G4HCofThisEvent *HCE)
Definition: CCaloSD.cc:281
const G4VProcess * GetCreatorProcess() const
G4Track * theTrack
Definition: CCaloSD.hh:101
void setTrackID(int i)
Definition: CCalHit.cc:72
G4GLOB_DLL std::ostream G4cout
G4VPhysicalVolume * GetPhysicalVolume() const
G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist)
Definition: CCaloSD.cc:86
const G4String & GetName() const
float EdepositEHAD
Definition: CCaloSD.hh:110
const G4ThreeVector & GetPosition() const
G4bool hitExists()
Definition: CCaloSD.cc:139
int getTrackID() const
Definition: CCalHit.cc:71
bool G4bool
Definition: G4Types.hh:79
void addCalo(nameType name)
Definition: CCalSDList.cc:44
G4int GetReplicaNumber(G4int depth=0) const
void ResetForNewPrimary()
Definition: CCaloSD.cc:182
virtual unsigned int GetUnitID(const G4Step *aStep) const =0
Definition: G4Step.hh:76
G4int GetTrackID() const
void setTimeSlice(double d)
Definition: CCalHit.cc:78
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
G4double GetTotalEnergyDeposit() const
void AddHitsCollection(G4int HCID, G4VHitsCollection *aHC)
G4int TSID
Definition: CCaloSD.hh:99
G4int TSliceID
Definition: CCaloSD.hh:105
void clear()
Definition: CCaloSD.cc:290
virtual ~CCaloSD()
Definition: CCaloSD.cc:60
G4int HCID
Definition: CCaloSD.hh:95
G4StepPoint * PostStepPoint
Definition: CCaloSD.hh:109
void DrawAll()
Definition: CCaloSD.cc:294
G4ThreeVector TransformPoint(const G4ThreeVector &vec) const
G4ThreeVector EntrancePoint
Definition: CCaloSD.hh:89
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
Definition: G4VTouchable.cc:44
const G4VTouchable * GetTouchable() const
unsigned int PreviousUnitID
Definition: CCaloSD.hh:104
G4StepPoint * GetPostStepPoint() const
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
CCalG4Hit * CurrentHit
Definition: CCaloSD.hh:100
void updateHit()
Definition: CCaloSD.cc:253
G4double GetTotalEnergy() const
unsigned int getUnitID() const
Definition: CCalHit.cc:74
void summarize()
Definition: CCaloSD.cc:286
#define G4endl
Definition: G4ios.hh:61
void setUnitID(unsigned int i)
Definition: CCalHit.cc:75
G4double GetGlobalTime() const
static constexpr double MeV
Definition: G4SIunits.hh:214
const G4AffineTransform & GetTopTransform() const
void addEnergyDeposit(const CCalG4Hit &aHit)
Definition: CCalG4Hit.cc:63
G4CollectionNameVector collectionName
G4double GetKineticEnergy() const
double G4double
Definition: G4Types.hh:76
G4VPhysicalVolume * PreviousPV
Definition: CCaloSD.hh:103
G4Track * GetTrack() const
void Initialize(G4HCofThisEvent *HCE)
Definition: CCaloSD.cc:67
int getTimeSliceID() const
Definition: CCalHit.cc:79
G4int PrimaryID
Definition: CCaloSD.hh:105
G4double TSlice
Definition: CCaloSD.hh:106
G4GLOB_DLL std::ostream G4cerr
G4ThreeVector HitPoint
Definition: CCaloSD.hh:111