CMS 3D CMS Logo

FP420SD.cc
Go to the documentation of this file.
1 // File: FP420SD.cc
3 // Date: 02.2006
4 // Description: Sensitive Detector class for FP420
5 // Modifications:
7 
12 
16 
21 
25 
28 
29 #include "G4Track.hh"
30 #include "G4SDManager.hh"
31 #include "G4VProcess.hh"
32 #include "G4EventManager.hh"
33 #include "G4Step.hh"
34 #include "G4ParticleTable.hh"
35 
36 #include "G4SystemOfUnits.hh"
37 
38 #include <string>
39 #include <vector>
40 #include <iostream>
41 
43 
44 //#define debug
45 //-------------------------------------------------------------------
47  const DDCompactView& cpv,
48  const SensitiveDetectorCatalog& clg,
49  edm::ParameterSet const& p,
50  const SimTrackManager* manager)
51  : SensitiveTkDetector(name, cpv, clg, p),
53  hcID(-1),
54  theHC(nullptr),
55  theManager(manager),
56  currentHit(nullptr),
57  theTrack(nullptr),
58  currentPV(nullptr),
59  unitID(0),
60  previousUnitID(0),
61  preStepPoint(nullptr),
62  postStepPoint(nullptr),
63  eventno(0) {
64  //Parameters
66  int verbn = m_p.getUntrackedParameter<int>("Verbosity");
67  //int verbn = 1;
68 
69  SetVerboseLevel(verbn);
70 
71  slave = new TrackingSlaveSD(name);
72 
73  if (name == "FP420SI") {
74  if (verbn > 0) {
75  edm::LogInfo("FP420Sim") << "name = FP420SI and new FP420NumberingSchem";
76  }
78  } else {
79  edm::LogWarning("FP420Sim") << "FP420SD: ReadoutName not supported\n";
80  }
81 }
82 
84  delete slave;
85  delete numberingScheme;
86 }
87 
88 double FP420SD::getEnergyDeposit(G4Step* aStep) { return aStep->GetTotalEnergyDeposit(); }
89 
90 void FP420SD::Initialize(G4HCofThisEvent* HCE) {
91 #ifdef debug
92  LogDebug("FP420Sim") << "FP420SD : Initialize called for " << name << std::endl;
93 #endif
94 
95  theHC = new FP420G4HitCollection(GetName(), collectionName[0]);
96  if (hcID < 0)
97  hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
98  HCE->AddHitsCollection(hcID, theHC);
99 
100  tsID = -2;
101  // primID = -2;
102  primID = 0;
103 
105 }
106 
107 bool FP420SD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
108  if (aStep == nullptr) {
109  return true;
110  } else {
111  GetStepInfo(aStep);
112  // LogDebug("FP420Sim") << edeposit <<std::endl;
113 
114  //AZ
115 #ifdef debug
116  LogDebug("FP420Sim") << "FP420SD : number of hits = " << theHC->entries() << std::endl;
117 #endif
118 
119  if (HitExists() == false && edeposit > 0. && theHC->entries() < 200) {
120  CreateNewHit();
121  return true;
122  }
123  }
124  return true;
125 }
126 
127 void FP420SD::GetStepInfo(G4Step* aStep) {
128  preStepPoint = aStep->GetPreStepPoint();
129  postStepPoint = aStep->GetPostStepPoint();
130  theTrack = aStep->GetTrack();
131  hitPoint = preStepPoint->GetPosition();
132  currentPV = preStepPoint->GetPhysicalVolume();
133  hitPointExit = postStepPoint->GetPosition();
134 
135  hitPointLocal = preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
136  hitPointLocalExit = preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPointExit);
137 
138  G4int particleCode = theTrack->GetDefinition()->GetPDGEncoding();
139  if (particleCode == emPDG || particleCode == epPDG || particleCode == gammaPDG) {
140  edepositEM = getEnergyDeposit(aStep);
141  edepositHAD = 0.;
142  } else {
143  edepositEM = 0.;
144  edepositHAD = getEnergyDeposit(aStep);
145  }
146  edeposit = aStep->GetTotalEnergyDeposit();
147  tSlice = (postStepPoint->GetGlobalTime()) / nanosecond;
148  tSliceID = (int)tSlice;
149  unitID = setDetUnitId(aStep);
150 #ifdef debug
151  LogDebug("FP420Sim") << "unitID=" << unitID << std::endl;
152 #endif
153  primaryID = theTrack->GetTrackID();
154  // Position = hitPoint;
155  Pabs = aStep->GetPreStepPoint()->GetMomentum().mag() / GeV;
156  //Tof = 1400. + aStep->GetPostStepPoint()->GetGlobalTime()/nanosecond;
157  Tof = aStep->GetPostStepPoint()->GetGlobalTime() / nanosecond;
158  Eloss = aStep->GetTotalEnergyDeposit() / GeV;
159  ParticleType = theTrack->GetDefinition()->GetPDGEncoding();
160  ThetaAtEntry = aStep->GetPreStepPoint()->GetPosition().theta() / deg;
161  PhiAtEntry = aStep->GetPreStepPoint()->GetPosition().phi() / deg;
162 
163  ParentId = theTrack->GetParentID();
164  Vx = theTrack->GetVertexPosition().x();
165  Vy = theTrack->GetVertexPosition().y();
166  Vz = theTrack->GetVertexPosition().z();
167  X = hitPoint.x();
168  Y = hitPoint.y();
169  Z = hitPoint.z();
170 }
171 
172 uint32_t FP420SD::setDetUnitId(const G4Step* aStep) {
173  return (numberingScheme == nullptr ? 0 : numberingScheme->getUnitID(aStep));
174 }
175 
177  if (primaryID < 1) {
178  edm::LogWarning("FP420Sim") << "***** FP420SD error: primaryID = " << primaryID << " maybe detector name changed";
179  }
180 
181  // Update if in the same detector, time-slice and for same track
182  // if (primaryID == primID && tSliceID == tsID && unitID==previousUnitID) {
183  if (tSliceID == tsID && unitID == previousUnitID) {
184  //AZ:
185  UpdateHit();
186  return true;
187  }
188  // Reset entry point for new primary
189  if (primaryID != primID)
191 
192  //look in the HitContainer whether a hit with the same primID, unitID,
193  //tSliceID already exists:
194 
195  G4bool found = false;
196 
197  // LogDebug("FP420Sim") << "FP420SD: HCollection= " << theHC->entries() <<std::endl;
198 
199  for (int j = 0; j < theHC->entries() && !found; j++) {
200  FP420G4Hit* aPreviousHit = (*theHC)[j];
201  if (aPreviousHit->getTrackID() == primaryID && aPreviousHit->getTimeSliceID() == tSliceID &&
202  aPreviousHit->getUnitID() == unitID) {
203  //AZ:
204  currentHit = aPreviousHit;
205  found = true;
206  }
207  }
208 
209  if (found) {
210  //AZ:
211  UpdateHit();
212  return true;
213  } else {
214  return false;
215  }
216 }
217 
221  incidentEnergy = preStepPoint->GetKineticEnergy();
222 }
223 
225  // if (primID<0) return;
226  if (hit == nullptr) {
227  edm::LogWarning("FP420Sim") << "FP420SD: hit to be stored is NULL !!";
228  return;
229  }
230 
231  theHC->insert(hit);
232 }
233 
235 #ifdef debug
236  // << " MVid = " << currentPV->GetMother()->GetCopyNo()
237  LogDebug("FP420Sim") << "FP420SD CreateNewHit for"
238  << " PV " << currentPV->GetName() << " PVid = " << currentPV->GetCopyNo() << " Unit " << unitID
239  << std::endl;
240  LogDebug("FP420Sim") << " primary " << primaryID << " time slice " << tSliceID << " For Track "
241  << theTrack->GetTrackID() << " which is a " << theTrack->GetDefinition()->GetParticleName();
242 
243  if (theTrack->GetTrackID() == 1) {
244  LogDebug("FP420Sim") << " of energy " << theTrack->GetTotalEnergy();
245  } else {
246  LogDebug("FP420Sim") << " daughter of part. " << theTrack->GetParentID();
247  }
248 
249  LogDebug("FP420Sim") << " and created by ";
250  if (theTrack->GetCreatorProcess() != NULL)
251  LogDebug("FP420Sim") << theTrack->GetCreatorProcess()->GetProcessName();
252  else
253  LogDebug("FP420Sim") << "NO process";
254  LogDebug("FP420Sim") << std::endl;
255 #endif
256 
257  currentHit = new FP420G4Hit;
262 
269 
270  // currentHit->setEntry(entrancePoint);
272 
275 
277  currentHit->setVx(Vx);
278  currentHit->setVy(Vy);
279  currentHit->setVz(Vz);
280 
281  currentHit->setX(X);
282  currentHit->setY(Y);
283  currentHit->setZ(Z);
284  //AZ:12.10.2007
285  // UpdateHit();
286  // buffer for next steps:
287  tsID = tSliceID;
288  primID = primaryID;
290 
292 }
293 
295  //
296  if (Eloss > 0.) {
298 
299 #ifdef debug
300  LogDebug("FP420Sim") << "updateHit: add eloss " << Eloss << std::endl;
301  LogDebug("FP420Sim") << "CurrentHit=" << currentHit << ", PostStepPoint=" << postStepPoint->GetPosition()
302  << std::endl;
303 #endif
304  //AZ
305  // currentHit->setEnergyLoss(Eloss);
307  }
308 
309  // buffer for next steps:
310  tsID = tSliceID;
311  primID = primaryID;
313 }
314 
315 G4ThreeVector FP420SD::SetToLocal(const G4ThreeVector& global) {
316  const G4VTouchable* touch = preStepPoint->GetTouchable();
317  theEntryPoint = touch->GetHistory()->GetTopTransform().TransformPoint(global);
318  return theEntryPoint;
319 }
320 
321 G4ThreeVector FP420SD::SetToLocalExit(const G4ThreeVector& globalPoint) {
322  const G4VTouchable* touch = postStepPoint->GetTouchable();
323  theExitPoint = touch->GetHistory()->GetTopTransform().TransformPoint(globalPoint);
324  return theExitPoint;
325 }
326 
327 void FP420SD::EndOfEvent(G4HCofThisEvent*) {
328  // here we loop over transient hits and make them persistent
329 
330  // if(theHC->entries() > 100){
331  // LogDebug("FP420Sim") << "FP420SD: warning!!! Number of hits exceed 100 and =" << theHC->entries() << "\n";
332  // }
333  // for (int j=0; j<theHC->entries() && j<100; j++) {
334  int nhitsHPS240 = 0;
335  int nhitsFP420 = 0;
336  for (int j = 0; j < theHC->entries(); j++) {
337  FP420G4Hit* aHit = (*theHC)[j];
338  if ((fabs(aHit->getTof()) > 780. && fabs(aHit->getTof()) < 840.))
339  ++nhitsHPS240;
340  if ((fabs(aHit->getTof()) > 1380. && fabs(aHit->getTof()) < 1450.))
341  ++nhitsFP420;
342  // if(fabs(aHit->getTof()) < 1700.) {
343  if ((fabs(aHit->getTof()) > 780. && fabs(aHit->getTof()) < 840. && nhitsHPS240 < 200.) ||
344  (fabs(aHit->getTof()) > 1380. && fabs(aHit->getTof()) < 1450. && nhitsFP420 < 200.)) {
345 #ifdef ddebug
346  // LogDebug("FP420SD") << " FP420Hit " << j << " " << *aHit << std::endl;
347  LogDebug("FP420Sim") << "hit number" << j << "unit ID = " << aHit->getUnitID() << "\n";
348  LogDebug("FP420Sim") << "entry z " << aHit->getEntry().z() << "\n";
349  LogDebug("FP420Sim") << "entr theta " << aHit->getThetaAtEntry() << "\n";
350 #endif
351 
352  // Local3DPoint locExitPoint(0,0,0);
353  // Local3DPoint locEntryPoint(aHit->getEntry().x(),
354  // aHit->getEntry().y(),
355  // aHit->getEntry().z());
356  Local3DPoint locExitPoint(aHit->getExitLocalP().x(), aHit->getExitLocalP().y(), aHit->getExitLocalP().z());
357  Local3DPoint locEntryPoint(aHit->getEntryLocalP().x(), aHit->getEntryLocalP().y(), aHit->getEntryLocalP().z());
358  // implicit conversion (slicing) to PSimHit!!!
359  slave->processHits(PSimHit(locEntryPoint,
360  locExitPoint, //entryPoint(), exitPoint() Local3DPoint
361  aHit->getPabs(), // pabs() float
362  aHit->getTof(), // tof() float
363  aHit->getEnergyLoss(), // energyLoss() float
364  aHit->getParticleType(), // particleType() int
365  aHit->getUnitID(), // detUnitId() unsigned int
366  aHit->getTrackID(), // trackId() unsigned int
367  aHit->getThetaAtEntry(), // thetaAtEntry() float
368  aHit->getPhiAtEntry())); // phiAtEntry() float
369 
370  //PSimHit( const Local3DPoint& entry, const Local3DPoint& exit,
371  // float pabs, float tof, float eloss, int particleType,
372  // unsigned int detId, unsigned int trackId,
373  // float theta, float phi, unsigned short processType=0) :
374 
375  // LocalVector direction = hit.exitPoint() - hit.entryPoint();
376  //hit.energyLoss
377 
378  /*
379  aHit->getEM(), -
380  aHit->getHadr(), -
381  aHit->getIncidentEnergy(), -
382  aHit->getTimeSlice(), -
383  aHit->getEntry(), -
384  aHit->getParentId(),
385  aHit->getEntryLocalP(), -
386  aHit->getExitLocalP(), -
387  aHit->getX(), -
388  aHit->getY(), -
389  aHit->getZ(), -
390  aHit->getVx(), -
391  aHit->getVy(), -
392  aHit->getVz())); -
393  */
394  } //if Tof<1600. if nhits<100
395  } // for loop on hits
396 
397  Summarize();
398 }
399 
401 
402 void FP420SD::clear() {}
403 
405 
407  LogDebug("FP420Sim") << "FP420SD: Collection " << theHC->GetName() << "\n";
408  theHC->PrintAllHits();
409 }
410 
411 //void FP420SD::SetNumberingScheme(FP420NumberingScheme* scheme){
412 //
413 // if (numberingScheme)
414 // delete numberingScheme;
415 // numberingScheme = scheme;
416 //
417 //}
418 
420  if (slave->name() == hname) {
421  cc = slave->hits();
422  }
423 }
424 
426  LogDebug("ForwardSim") << " Dispatched BeginOfEvent for " << GetName() << " !";
427  clearHits();
428  eventno = (*i)()->GetEventID();
429 }
430 
432  G4ParticleTable* theParticleTable = G4ParticleTable::GetParticleTable();
433  G4String particleName;
434  emPDG = theParticleTable->FindParticle(particleName = "e-")->GetPDGEncoding();
435  epPDG = theParticleTable->FindParticle(particleName = "e+")->GetPDGEncoding();
436  gammaPDG = theParticleTable->FindParticle(particleName = "gamma")->GetPDGEncoding();
437 }
438 
439 void FP420SD::update(const ::EndOfEvent*) {}
440 
442  //AZ:
443  slave->Initialize();
444 }
#define LogDebug(id)
int eventno
Definition: FP420SD.h:131
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
G4ThreeVector theExitPoint
Definition: FP420SD.h:89
G4int emPDG
Definition: FP420SD.h:135
void setY(float t)
Definition: FP420G4Hit.cc:159
const double GeV
Definition: MathUtil.h:16
G4ThreeVector SetToLocalExit(const G4ThreeVector &globalPoint)
Definition: FP420SD.cc:321
void setPhiAtEntry(float f)
Definition: FP420G4Hit.cc:153
float getTof() const
Definition: FP420G4Hit.cc:139
void DrawAll() override
Definition: FP420SD.cc:404
float ThetaAtEntry
Definition: FP420SD.h:121
void setVz(float p)
Definition: FP420G4Hit.cc:174
void setEntry(const G4ThreeVector &xyz)
Definition: FP420G4Hit.cc:104
virtual double getEnergyDeposit(G4Step *step)
Definition: FP420SD.cc:88
G4ThreeVector hitPointExit
Definition: FP420SD.h:113
std::string name() const
G4ThreeVector getExitLocalP() const
Definition: FP420G4Hit.cc:109
void setZ(float t)
Definition: FP420G4Hit.cc:162
#define nullptr
float Pabs
Definition: FP420SD.h:116
void setPabs(float e)
Definition: FP420G4Hit.cc:143
TrackingSlaveSD * slave
Definition: FP420SD.h:84
#define NULL
Definition: scimark2.h:8
G4StepPoint * preStepPoint
Definition: FP420SD.h:108
void ResetForNewPrimary()
Definition: FP420SD.cc:218
float getPabs() const
Definition: FP420G4Hit.cc:138
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
void setVx(float p)
Definition: FP420G4Hit.cc:168
G4int hcID
Definition: FP420SD.h:93
void setTrackID(int i)
Definition: FP420G4Hit.cc:122
unsigned int getTrackID() const
Definition: FP420G4Hit.cc:121
void addEnergyDeposit(double em, double hd)
Definition: FP420G4Hit.cc:131
G4int tsID
Definition: FP420SD.h:97
static TrackerG4SimHitNumberingScheme & numberingScheme(const DDCompactView &cpv, const GeometricDet &det)
unsigned int primaryID
Definition: FP420SD.h:104
float Eloss
Definition: FP420SD.h:118
unsigned int primID
Definition: FP420SD.h:104
float getPhiAtEntry() const
Definition: FP420G4Hit.cc:150
G4ThreeVector exitPoint
Definition: FP420SD.h:87
float edeposit
Definition: FP420SD.h:110
unsigned int getUnitID() const
Definition: FP420G4Hit.cc:124
void setEnergyLoss(float e)
Definition: FP420G4Hit.cc:146
std::vector< PSimHit > & hits()
void clearHits() override
Definition: FP420SD.cc:441
std::string const collectionName[nCollections]
Definition: Collections.h:47
G4ThreeVector theEntryPoint
Definition: FP420SD.h:88
void setTof(float e)
Definition: FP420G4Hit.cc:144
virtual void Initialize()
float edepositHAD
Definition: FP420SD.h:134
float Vz
Definition: FP420SD.h:125
void GetStepInfo(G4Step *aStep)
Definition: FP420SD.cc:127
void fillHits(edm::PSimHitContainer &, const std::string &) override
Definition: FP420SD.cc:419
G4int gammaPDG
Definition: FP420SD.h:137
FP420G4HitCollection * theHC
Definition: FP420SD.h:94
void CreateNewHit()
Definition: FP420SD.cc:234
G4Track * theTrack
Definition: FP420SD.h:99
void Summarize()
Definition: FP420SD.cc:400
G4int tSliceID
Definition: FP420SD.h:103
G4ThreeVector getEntryLocalP() const
Definition: FP420G4Hit.cc:106
G4bool HitExists()
Definition: FP420SD.cc:176
void update(const BeginOfRun *) override
This routine will be called when the appropriate signal arrives.
Definition: FP420SD.cc:431
void setTimeSlice(double d)
Definition: FP420G4Hit.cc:128
virtual unsigned int getUnitID(const G4Step *aStep) const
float getEnergyLoss() const
Definition: FP420G4Hit.cc:140
void setEntryLocalP(const G4ThreeVector &xyz1)
Definition: FP420G4Hit.cc:107
uint32_t setDetUnitId(const G4Step *) override
Definition: FP420SD.cc:172
G4THitsCollection< FP420G4Hit > FP420G4HitCollection
void setIncidentEnergy(double e)
Definition: FP420G4Hit.cc:119
uint32_t previousUnitID
Definition: FP420SD.h:102
int getTimeSliceID() const
Definition: FP420G4Hit.cc:129
G4VPhysicalVolume * currentPV
Definition: FP420SD.h:100
void Initialize(G4HCofThisEvent *HCE) override
Definition: FP420SD.cc:90
FP420SD(const std::string &, const DDCompactView &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
Definition: FP420SD.cc:46
void setX(float t)
Definition: FP420G4Hit.cc:156
float Tof
Definition: FP420SD.h:117
void setExitLocalP(const G4ThreeVector &xyz1)
Definition: FP420G4Hit.cc:110
void clear() override
Definition: FP420SD.cc:402
int getParticleType() const
Definition: FP420G4Hit.cc:141
uint32_t unitID
Definition: FP420SD.h:102
float PhiAtEntry
Definition: FP420SD.h:122
float edepositEM
Definition: FP420SD.h:134
short ParticleType
Definition: FP420SD.h:119
void setParticleType(short i)
Definition: FP420G4Hit.cc:147
void setThetaAtEntry(float t)
Definition: FP420G4Hit.cc:152
G4ThreeVector hitPointLocalExit
Definition: FP420SD.h:115
FP420NumberingScheme * numberingScheme
Definition: FP420SD.h:85
G4double tSlice
Definition: FP420SD.h:106
bool ProcessHits(G4Step *, G4TouchableHistory *) override
Definition: FP420SD.cc:107
void PrintAll() override
Definition: FP420SD.cc:406
G4ThreeVector SetToLocal(const G4ThreeVector &global)
Definition: FP420SD.cc:315
float incidentEnergy
Definition: FP420SD.h:91
void setUnitID(unsigned int i)
Definition: FP420G4Hit.cc:125
int ParentId
Definition: FP420SD.h:124
G4ThreeVector entrancePoint
Definition: FP420SD.h:87
float Z
Definition: FP420SD.h:126
float Vy
Definition: FP420SD.h:125
virtual bool processHits(const PSimHit &)
void UpdateHit()
Definition: FP420SD.cc:294
std::vector< PSimHit > PSimHitContainer
G4ThreeVector getEntry() const
Definition: FP420G4Hit.cc:103
~FP420SD() override
Definition: FP420SD.cc:83
G4int epPDG
Definition: FP420SD.h:136
G4StepPoint * postStepPoint
Definition: FP420SD.h:109
void setParentId(int p)
Definition: FP420G4Hit.cc:165
float X
Definition: FP420SD.h:126
FP420G4Hit * currentHit
Definition: FP420SD.h:98
G4ThreeVector hitPointLocal
Definition: FP420SD.h:114
G4ThreeVector hitPoint
Definition: FP420SD.h:112
void addEnergyLoss(float e)
Definition: FP420G4Hit.cc:145
float getThetaAtEntry() const
Definition: FP420G4Hit.cc:149
float Y
Definition: FP420SD.h:126
void StoreHit(FP420G4Hit *)
Definition: FP420SD.cc:224
void setVy(float p)
Definition: FP420G4Hit.cc:171
float Vx
Definition: FP420SD.h:125
void EndOfEvent(G4HCofThisEvent *eventHC) override
Definition: FP420SD.cc:327