test
CMS 3D CMS Logo

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