test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FastTimerSD.cc
Go to the documentation of this file.
4 
8 
12 
15 
16 #include "G4Track.hh"
17 #include "G4SDManager.hh"
18 #include "G4VProcess.hh"
19 #include "G4EventManager.hh"
20 #include "G4Step.hh"
21 #include "G4ParticleTable.hh"
22 
23 #include <string>
24 #include <vector>
25 #include <iostream>
26 
28 
29 //#define DebugLog
30 //-------------------------------------------------------------------
32  const SensitiveDetectorCatalog & clg,
33  edm::ParameterSet const & p,
34  const SimTrackManager* manager) :
35  SensitiveTkDetector(name, cpv, clg, p), ftcons(0), name(name),
36  hcID(-1), theHC(0), theManager(manager), currentHit(0), theTrack(0),
37  currentPV(0), unitID(0), previousUnitID(0), preStepPoint(0),
38  postStepPoint(0), eventno(0){
39 
40  //Add FastTimer Sentitive Detector Name
41  collectionName.insert(name);
42 
43 
44  //Parameters
45  edm::ParameterSet m_p = p.getParameter<edm::ParameterSet>("FastTimerSD");
46  int verbn = m_p.getUntrackedParameter<int>("Verbosity");
47  //int verbn = 1;
48 
49  SetVerboseLevel(verbn);
50 #ifdef DebugLog
51  LogDebug("FastTimerSim")
52  << "*******************************************************\n"
53  << "* *\n"
54  << "* Constructing a FastTimerSD with name " << name << "\n"
55  << "* *\n"
56  << "*******************************************************";
57 #endif
58 
59  slave = new TrackingSlaveSD(name);
60 
61  //
62  // attach detectors (LogicalVolumes)
63  //
64  std::vector<std::string> lvNames = clg.logicalNames(name);
65 
66  this->Register();
67 
68  for (std::vector<std::string>::iterator it=lvNames.begin();
69  it !=lvNames.end(); it++) {
70  this->AssignSD(*it);
71  edm::LogInfo("FastTimerSim") << "FastTimerSD : Assigns SD to LV " << (*it);
72  }
73 
74  ftcons = new FastTimeDDDConstants(cpv) ;
75  type = ftcons->getType();
76 
77  edm::LogInfo("FastTimerSim") << "FastTimerSD: Instantiation completed";
78 }
79 
80 
82 
83  if (slave) delete slave;
84  if (ftcons) delete ftcons;
85 }
86 
87 double FastTimerSD::getEnergyDeposit(G4Step* aStep) {
88  return aStep->GetTotalEnergyDeposit();
89 }
90 
91 void FastTimerSD::Initialize(G4HCofThisEvent * HCE) {
92 #ifdef DebugLog
93  LogDebug("FastTimerSim") << "FastTimerSD : Initialize called for " << name;
94 #endif
95 
97  if (hcID<0)
98  hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
99  HCE->AddHitsCollection(hcID, theHC);
100 
101  tsID = -2;
102  primID = -2;
103 }
104 
105 
106 bool FastTimerSD::ProcessHits(G4Step * aStep, G4TouchableHistory * ) {
107 
108  if (aStep == NULL) {
109  return true;
110  } else {
111  GetStepInfo(aStep);
112 #ifdef DebugLog
113  LogDebug("FastTimerSim") << "FastTimerSD : number of hits = "
114  << theHC->entries();
115 #endif
116  if (HitExists() == false && edeposit>0. ){
117  CreateNewHit();
118  return true;
119  }
120  }
121  return true;
122 }
123 
124 void FastTimerSD::GetStepInfo(G4Step* aStep) {
125 
126  preStepPoint = aStep->GetPreStepPoint();
127  postStepPoint= aStep->GetPostStepPoint();
128  theTrack = aStep->GetTrack();
129  hitPoint = preStepPoint->GetPosition();
130  currentPV = preStepPoint->GetPhysicalVolume();
131  hitPointExit = postStepPoint->GetPosition();
132 
133  hitPointLocal = preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPoint);
134  hitPointLocalExit = preStepPoint->GetTouchable()->GetHistory()->GetTopTransform().TransformPoint(hitPointExit);
135 
136 
137  G4int particleCode = theTrack->GetDefinition()->GetPDGEncoding();
138 #ifdef DebugLog
139  edm::LogInfo("FastTimerSim") << "FastTimerSD :particleType = "
140  << theTrack->GetDefinition()->GetParticleName();
141 #endif
142  if (particleCode == emPDG ||
143  particleCode == epPDG ||
144  particleCode == gammaPDG ) {
145  edepositEM = getEnergyDeposit(aStep); edepositHAD = 0.;
146  } else {
147  edepositEM = 0.; edepositHAD = getEnergyDeposit(aStep);
148  }
149  edeposit = aStep->GetTotalEnergyDeposit();
150  tSlice = (100*postStepPoint->GetGlobalTime() )/CLHEP::nanosecond;
151  tSliceID = (int) tSlice;
152  unitID = setDetUnitId(aStep);
153 #ifdef DebugLog
154  LogDebug("FastTimerSim") << "FastTimerSD:unitID = " << std::hex << unitID
155  << std::dec;
156 #endif
157  primaryID = theTrack->GetTrackID();
158  // Position = hitPoint;
159  Pabs = aStep->GetPreStepPoint()->GetMomentum().mag()/CLHEP::GeV;
160  Tof = aStep->GetPostStepPoint()->GetGlobalTime()/CLHEP::nanosecond;
161  Eloss = aStep->GetTotalEnergyDeposit()/CLHEP::GeV;
162  ParticleType = theTrack->GetDefinition()->GetPDGEncoding();
163  ThetaAtEntry = aStep->GetPreStepPoint()->GetPosition().theta()/CLHEP::deg;
164  PhiAtEntry = aStep->GetPreStepPoint()->GetPosition().phi()/CLHEP::deg;
165 
166  ParentId = theTrack->GetParentID();
167  Vx = theTrack->GetVertexPosition().x();
168  Vy = theTrack->GetVertexPosition().y();
169  Vz = theTrack->GetVertexPosition().z();
170  X = hitPoint.x();
171  Y = hitPoint.y();
172  Z = hitPoint.z();
173 }
174 
175 uint32_t FastTimerSD::setDetUnitId(G4Step * aStep) {
176 
177  //Find the depth segment
178  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
179  float globalZ = aStep->GetPreStepPoint()->GetPosition().z();
180  int iz = (globalZ > 0) ? 1 : -1;
181  std::pair<int,int> ixy;
182  if (type == 1) {
183  ixy = ftcons->getXY(touch->GetReplicaNumber(0));
184  } else {
185  ixy = ftcons->getXY(hitPointLocal.x(),hitPointLocal.y());
186  }
187  uint32_t id = FastTimeDetId(ixy.first,ixy.second,iz).rawId();
188 #ifdef DebugLog
189  edm::LogInfo("FastTimerSim") << "Levels " << touch->GetReplicaNumber(0) <<":"
190  << globalZ << " Ixyz " << ixy.first << ":"
191  << ixy.second << ":" << iz << " id "
192  << std::hex << id << std::dec;
193 #endif
194  return id;
195 }
196 
197 
199  if (primaryID<1) {
200  edm::LogWarning("FastTimerSim") << "***** FastTimerSD error: primaryID = "
201  << primaryID
202  << " maybe detector name changed";
203  }
204 
205  // Update if in the same detector, time-slice and for same track
206  if (tSliceID == tsID && unitID==previousUnitID) {
207  UpdateHit();
208  return true;
209  }
210  // Reset entry point for new primary
211  if (primaryID != primID)
213 
214  //look in the HitContainer whether a hit with the same primID, unitID,
215  //tSliceID already exists:
216 
217  G4bool found = false;
218 
219  for (int j=0; j<theHC->entries()&&!found; j++) {
220  BscG4Hit* aPreviousHit = (*theHC)[j];
221  if (aPreviousHit->getTrackID() == primaryID &&
222  aPreviousHit->getTimeSliceID() == tSliceID &&
223  aPreviousHit->getUnitID() == unitID ) {
224  currentHit = aPreviousHit;
225  found = true;
226  }
227  }
228 
229  if (found) {
230  UpdateHit();
231  return true;
232  } else {
233  return false;
234  }
235 }
236 
237 
239 
242  incidentEnergy = preStepPoint->GetKineticEnergy();
243 }
244 
245 
247 
248  if (primID<0) return;
249  if (hit == 0) {
250  edm::LogWarning("FastTimerSim") << "FastTimerSD: hit to be stored is NULL !!";
251  } else {
252  theHC->insert( hit );
253  }
254 }
255 
256 
258 
259 #ifdef DebugLog
260  LogDebug("FastTimerSim") << "FastTimerSD CreateNewHit for"
261  << " PV " << currentPV->GetName()
262  << " PVid = " << currentPV->GetCopyNo()
263  << " Unit " << unitID <<std::endl;
264  LogDebug("FastTimerSim") << " primary " << primaryID
265  << " time slice " << tSliceID
266  << " For Track " << theTrack->GetTrackID()
267  << " which is a " << theTrack->GetDefinition()->GetParticleName();
268 
269  if (theTrack->GetTrackID()==1) {
270  LogDebug("FastTimerSim") << " of energy " << theTrack->GetTotalEnergy();
271  } else {
272  LogDebug("FastTimerSim") << " daughter of part. " << theTrack->GetParentID();
273  }
274 
275  LogDebug("FastTimerSim") << " and created by " ;
276  if (theTrack->GetCreatorProcess()!=NULL)
277  LogDebug("FastTimerSim") << theTrack->GetCreatorProcess()->GetProcessName() ;
278  else
279  LogDebug("FastTimerSim") << "NO process";
280  LogDebug("FastTimerSim") << std::endl;
281 #endif
282 
283  currentHit = new BscG4Hit;
288 
295 
297 
300 
302  currentHit->setVx(Vx);
303  currentHit->setVy(Vy);
304  currentHit->setVz(Vz);
305 
306  currentHit->setX(X);
307  currentHit->setY(Y);
308  currentHit->setZ(Z);
309 
310  UpdateHit();
311 
313 }
314 
315 
317 
318  if (Eloss > 0.) {
320 
321 #ifdef DebugLog
322  LogDebug("FastTimerSim") << "updateHit: add eloss " << Eloss <<std::endl;
323  LogDebug("FastTimerSim") << "CurrentHit="<< currentHit<< ", PostStepPoint="
324  << postStepPoint->GetPosition();
325 #endif
327  }
328 
329  // buffer for next steps:
330  tsID = tSliceID;
331  primID = primaryID;
333 }
334 
335 
336 G4ThreeVector FastTimerSD::SetToLocal(const G4ThreeVector& global){
337 
338  const G4VTouchable* touch= preStepPoint->GetTouchable();
339  theEntryPoint = touch->GetHistory()->GetTopTransform().TransformPoint(global);
340  return theEntryPoint;
341 }
342 
343 
344 G4ThreeVector FastTimerSD::SetToLocalExit(const G4ThreeVector& globalPoint){
345 
346  const G4VTouchable* touch= postStepPoint->GetTouchable();
347  theExitPoint = touch->GetHistory()->GetTopTransform().TransformPoint(globalPoint);
348  return theExitPoint;
349 }
350 
351 
352 void FastTimerSD::EndOfEvent(G4HCofThisEvent* ) {
353 
354  // here we loop over transient hits and make them persistent
355  for (int j=0; j<theHC->entries(); j++) {
356  BscG4Hit* aHit = (*theHC)[j];
357 #ifdef DebugLog
358  edm::LogInfo("FastTimerSim") << "hit number " << j << " unit ID = "
359  << std::hex << aHit->getUnitID() << std::dec
360  << " entry z " << aHit->getEntry().z()
361  << " entry theta " << aHit->getThetaAtEntry();
362 #endif
363  Local3DPoint locExitPoint(0,0,0);
364  Local3DPoint locEntryPoint(aHit->getEntry().x(),
365  aHit->getEntry().y(),
366  aHit->getEntry().z());
367  slave->processHits(PSimHit(locEntryPoint,locExitPoint,
368  aHit->getPabs(),
369  aHit->getTof(),
370  aHit->getEnergyLoss(),
371  aHit->getParticleType(),
372  aHit->getUnitID(),
373  aHit->getTrackID(),
374  aHit->getThetaAtEntry(),
375  aHit->getPhiAtEntry()));
376  }
377  Summarize();
378 }
379 
381 
383 
385 
387 #ifdef DebugLog
388  edm::LogInfo("FastTimerSim") << "FastTimerSD: Collection "<<theHC->GetName();
389 #endif
390  theHC->PrintAllHits();
391 }
392 
394  if (slave->name() == n) c=slave->hits();
395 }
396 
398 #ifdef DebugLog
399  edm::LogInfo("FastTimerSim") << "Dispatched BeginOfEvent for " << GetName()
400  << " !" ;
401 #endif
402  clearHits();
403  eventno = (*i)()->GetEventID();
404 }
405 
407 
408  G4ParticleTable * theParticleTable = G4ParticleTable::GetParticleTable();
409  G4String particleName;
410  emPDG = theParticleTable->FindParticle(particleName="e-")->GetPDGEncoding();
411  epPDG = theParticleTable->FindParticle(particleName="e+")->GetPDGEncoding();
412  gammaPDG = theParticleTable->FindParticle(particleName="gamma")->GetPDGEncoding();
413 
414 }
415 
416 void FastTimerSD::update (const ::EndOfEvent*) {}
417 
419  slave->Initialize();
420 }
421 
422 std::vector<std::string> FastTimerSD::getNames(){
423  std::vector<std::string> temp;
424  temp.push_back(slave->name());
425  return temp;
426 }
#define LogDebug(id)
std::string name
Definition: FastTimerSD.h:92
G4ThreeVector hitPoint
Definition: FastTimerSD.h:109
type
Definition: HCALResponse.h:21
void setTof(float e)
Definition: BSCG4Hit.cc:154
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
G4ThreeVector hitPointExit
Definition: FastTimerSD.h:110
int i
Definition: DBlmapReader.cc:9
void setEntry(const G4ThreeVector &xyz)
Definition: BSCG4Hit.cc:116
const double GeV
Definition: MathUtil.h:16
float getPhiAtEntry() const
Definition: BSCG4Hit.cc:159
virtual void clear()
Definition: FastTimerSD.cc:382
void setVx(float p)
Definition: BSCG4Hit.cc:177
G4ThreeVector SetToLocalExit(const G4ThreeVector &globalPoint)
Definition: FastTimerSD.cc:344
int getParticleType() const
Definition: BSCG4Hit.cc:151
G4int getTrackID() const
Definition: BSCG4Hit.cc:133
void update(const BeginOfRun *)
This routine will be called when the appropriate signal arrives.
Definition: FastTimerSD.cc:406
float edepositHAD
Definition: FastTimerSD.h:126
G4ThreeVector theEntryPoint
Definition: FastTimerSD.h:87
G4int tSliceID
Definition: FastTimerSD.h:102
virtual void Initialize(G4HCofThisEvent *HCE)
Definition: FastTimerSD.cc:91
virtual double getEnergyDeposit(G4Step *step)
Definition: FastTimerSD.cc:87
std::string name() const
void setTrackID(int i)
Definition: BSCG4Hit.cc:134
void setEnergyLoss(float e)
Definition: BSCG4Hit.cc:155
void setParentId(int p)
Definition: BSCG4Hit.cc:174
void UpdateHit()
Definition: FastTimerSD.cc:316
#define NULL
Definition: scimark2.h:8
BscG4Hit * currentHit
Definition: FastTimerSD.h:98
void setUnitID(unsigned int i)
Definition: BSCG4Hit.cc:137
float getTof() const
Definition: BSCG4Hit.cc:149
float getPabs() const
Definition: BSCG4Hit.cc:148
uint32_t unitID
Definition: FastTimerSD.h:101
float edeposit
Definition: FastTimerSD.h:107
const std::vector< std::string > & logicalNames(const std::string &readoutName) const
void setVy(float p)
Definition: BSCG4Hit.cc:180
void setY(float t)
Definition: BSCG4Hit.cc:168
short ParticleType
Definition: FastTimerSD.h:115
type of data representation of DDCompactView
Definition: DDCompactView.h:77
unsigned int getUnitID() const
Definition: BSCG4Hit.cc:136
virtual void AssignSD(const std::string &vname)
int getTimeSliceID() const
Definition: BSCG4Hit.cc:141
G4int tsID
Definition: FastTimerSD.h:97
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
void setThetaAtEntry(float t)
Definition: BSCG4Hit.cc:161
G4ThreeVector SetToLocal(const G4ThreeVector &global)
Definition: FastTimerSD.cc:336
void setX(float t)
Definition: BSCG4Hit.cc:165
void setPabs(float e)
Definition: BSCG4Hit.cc:153
virtual void PrintAll()
Definition: FastTimerSD.cc:386
G4bool HitExists()
Definition: FastTimerSD.cc:198
void setEntryLocalP(const G4ThreeVector &xyz1)
Definition: BSCG4Hit.cc:119
std::vector< PSimHit > & hits()
TrackingSlaveSD * slave
Definition: FastTimerSD.h:82
G4int gammaPDG
Definition: FastTimerSD.h:129
std::string const collectionName[nCollections]
Definition: Collections.h:45
G4int primID
Definition: FastTimerSD.h:90
virtual void Initialize()
virtual ~FastTimerSD()
Definition: FastTimerSD.cc:81
FastTimerSD(std::string, const DDCompactView &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
Definition: FastTimerSD.cc:31
void setPhiAtEntry(float f)
Definition: BSCG4Hit.cc:162
G4StepPoint * postStepPoint
Definition: FastTimerSD.h:106
G4ThreeVector hitPointLocalExit
Definition: FastTimerSD.h:112
int j
Definition: DBlmapReader.cc:9
G4VPhysicalVolume * currentPV
Definition: FastTimerSD.h:100
void ResetForNewPrimary()
Definition: FastTimerSD.cc:238
void StoreHit(BscG4Hit *)
Definition: FastTimerSD.cc:246
FastTimeDDDConstants * ftcons
Definition: FastTimerSD.h:83
virtual void DrawAll()
Definition: FastTimerSD.cc:384
G4ThreeVector hitPointLocal
Definition: FastTimerSD.h:111
G4Track * theTrack
Definition: FastTimerSD.h:99
float incidentEnergy
Definition: FastTimerSD.h:89
float getThetaAtEntry() const
Definition: BSCG4Hit.cc:158
BscG4HitCollection * theHC
Definition: FastTimerSD.h:94
void addEnergyDeposit(double em, double hd)
Definition: BSCG4Hit.cc:143
virtual bool ProcessHits(G4Step *, G4TouchableHistory *)
Definition: FastTimerSD.cc:106
std::vector< std::string > getNames()
Definition: FastTimerSD.cc:422
G4StepPoint * preStepPoint
Definition: FastTimerSD.h:105
void setTimeSlice(double d)
Definition: BSCG4Hit.cc:140
void setParticleType(short i)
Definition: BSCG4Hit.cc:156
void fillHits(edm::PSimHitContainer &, std::string use)
Definition: FastTimerSD.cc:393
void setVz(float p)
Definition: BSCG4Hit.cc:183
G4ThreeVector entrancePoint
Definition: FastTimerSD.h:86
G4ThreeVector theExitPoint
Definition: FastTimerSD.h:87
uint32_t previousUnitID
Definition: FastTimerSD.h:101
float PhiAtEntry
Definition: FastTimerSD.h:116
G4ThreeVector getEntry() const
Definition: BSCG4Hit.cc:115
float edepositEM
Definition: FastTimerSD.h:126
G4double tSlice
Definition: FastTimerSD.h:103
void setZ(float t)
Definition: BSCG4Hit.cc:171
virtual uint32_t setDetUnitId(G4Step *)
Definition: FastTimerSD.cc:175
virtual bool processHits(const PSimHit &)
std::vector< PSimHit > PSimHitContainer
void setExitLocalP(const G4ThreeVector &xyz1)
Definition: BSCG4Hit.cc:122
G4THitsCollection< BscG4Hit > BscG4HitCollection
void setIncidentEnergy(double e)
Definition: BSCG4Hit.cc:131
float ThetaAtEntry
Definition: FastTimerSD.h:116
void Summarize()
Definition: FastTimerSD.cc:380
virtual void EndOfEvent(G4HCofThisEvent *eventHC)
Definition: FastTimerSD.cc:352
std::pair< int, int > getXY(int copy) const
G4int hcID
Definition: FastTimerSD.h:93
G4ThreeVector exitPoint
Definition: FastTimerSD.h:86
virtual void clearHits()
Definition: FastTimerSD.cc:418
void CreateNewHit()
Definition: FastTimerSD.cc:257
float getEnergyLoss() const
Definition: BSCG4Hit.cc:150
G4int primaryID
Definition: FastTimerSD.h:102
void GetStepInfo(G4Step *aStep)
Definition: FastTimerSD.cc:124