CMS 3D CMS Logo

PPSPixelSD.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: PPS
4 // Class : PPSPixelSD
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: F.Ferro
10 // Created: May 4, 2015
11 //
12 
13 // system include files
14 
15 // user include files
18 
22 
25 
28 
29 #include "G4SDManager.hh"
30 #include "G4Step.hh"
31 #include "G4Track.hh"
32 #include "G4VProcess.hh"
33 
34 #include "G4PhysicalConstants.hh"
35 #include "G4SystemOfUnits.hh"
36 
38  const SensitiveDetectorCatalog& clg,
39  edm::ParameterSet const& p,
40  SimTrackManager const* manager)
41  : SensitiveTkDetector(name_, clg),
42  numberingScheme_(nullptr),
43  hcID_(-1),
44  theHC_(nullptr),
45  theManager_(manager),
46  currentHit_(nullptr),
47  theTrack_(nullptr),
48  currentPV_(nullptr),
49  unitID_(0),
50  previousUnitID_(0),
51  preStepPoint_(nullptr),
52  postStepPoint_(nullptr),
53  eventno_(0) {
54  //Add PPS Sentitive Detector Names
55  collectionName.insert(name_);
56 
57  //Parameters
58  edm::ParameterSet m_p = p.getParameter<edm::ParameterSet>("PPSPixelSD");
59  int verbn = m_p.getUntrackedParameter<int>("Verbosity");
60  SetVerboseLevel(verbn);
61  slave_ = std::make_unique<TrackingSlaveSD>(name_);
62  if (name_ == "CTPPSPixelHits") {
63  numberingScheme_ = std::make_unique<PPSPixelNumberingScheme>();
64  } else {
65  edm::LogWarning("PPSSim") << "PPSPixelSD: ReadoutName not supported\n";
66  }
67 
68  edm::LogInfo("PPSSim") << "PPSPixelSD: Instantiation completed";
69 }
70 
72 
73 bool PPSPixelSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
74  if (!aStep)
75  return true;
76 
77  stepInfo(aStep);
78  if (!hitExists() && edeposit_ > 0.)
79  createNewHit();
80  return true;
81 }
82 
83 uint32_t PPSPixelSD::setDetUnitId(const G4Step* aStep) {
84  return (numberingScheme_ == nullptr ? 0 : numberingScheme_->unitID(aStep));
85 }
86 
87 void PPSPixelSD::Initialize(G4HCofThisEvent* HCE) {
88  LogDebug("PPSSim") << "PPSPixelSD : Initialize called for " << name_;
89 
90  theHC_ = new PPSPixelG4HitCollection(GetName(), collectionName[0]);
91  G4SDManager::GetSDMpointer()->AddNewCollection(name_, collectionName[0]);
92 
93  if (hcID_ < 0)
94  hcID_ = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
95  HCE->AddHitsCollection(hcID_, theHC_);
96 
97  tsID_ = -2;
98  primID_ = -2;
99 }
100 
101 void PPSPixelSD::EndOfEvent(G4HCofThisEvent*) {
102  // here we loop over transient hits and make them persistent
103  for (unsigned int j = 0; j < (unsigned int)theHC_->entries() && j < maxPixelHits_; j++) {
104  PPSPixelG4Hit* aHit = (*theHC_)[j];
105 #ifdef debug
106  LogDebug("PPSSim") << "HIT NUMERO " << j << "unit ID = " << aHit->unitID() << "\n"
107  << " "
108  << "enrty z " << aHit->entry().z() << "\n"
109  << " "
110  << "theta " << aHit->thetaAtEntry() << "\n";
111 #endif
112 
113  Local3DPoint Enter(aHit->entryPoint().x(), aHit->entryPoint().y(), aHit->entryPoint().z());
114  Local3DPoint Exit(aHit->exitPoint().x(), aHit->exitPoint().y(), aHit->exitPoint().z());
115  slave_->processHits(PSimHit(Enter,
116  Exit,
117  aHit->p(),
118  aHit->tof(),
119  aHit->energyLoss(),
120  aHit->particleType(),
121  aHit->unitID(),
122  aHit->trackID(),
123  aHit->thetaAtEntry(),
124  aHit->phiAtEntry()));
125  }
126  summarize();
127 }
128 
130 
132 
134  LogDebug("PPSSim") << "PPSPixelSD: Collection " << theHC_->GetName();
135  theHC_->PrintAllHits();
136 }
137 
139  if (slave_->name() == n) {
140  c = slave_->hits();
141  }
142 }
143 
145  LogDebug("PPSSim") << " Dispatched BeginOfEvent for " << GetName() << " !";
146  clearHits();
147  eventno_ = (*i)()->GetEventID();
148 }
149 
150 void PPSPixelSD::update(const ::EndOfEvent*) {}
151 
152 void PPSPixelSD::clearHits() { slave_->Initialize(); }
153 
154 G4ThreeVector PPSPixelSD::setToLocal(const G4ThreeVector& global) {
155  G4ThreeVector localPoint;
156  const G4VTouchable* touch = preStepPoint_->GetTouchable();
157  localPoint = touch->GetHistory()->GetTopTransform().TransformPoint(global);
158  return localPoint;
159 }
160 
161 void PPSPixelSD::stepInfo(const G4Step* aStep) {
162  preStepPoint_ = aStep->GetPreStepPoint();
163  postStepPoint_ = aStep->GetPostStepPoint();
164  theTrack_ = aStep->GetTrack();
167 
168 #ifdef _PRINT_HITS_
169  LogDebug("PPSSim") << "theEntryPoint_ " << TheEntryPoint << "\n";
170  LogDebug("PPSSim") << "position " << preStepPoint_->GetPosition() << "\n";
171 #endif
172  hitPoint_ = preStepPoint_->GetPosition();
173  currentPV_ = preStepPoint_->GetPhysicalVolume();
174 
175  G4String name_ = currentPV_->GetName();
176  name_.assign(name_, 0, 4);
177  G4String particleType = theTrack_->GetDefinition()->GetParticleName();
178  edeposit_ = aStep->GetTotalEnergyDeposit();
179 
180  tSlice_ = (postStepPoint_->GetGlobalTime()) / nanosecond;
181  tSliceID_ = (int)tSlice_;
182  unitID_ = setDetUnitId(aStep);
183 #ifdef debug
184  LogDebug("PPSSim") << "UNIT ID " << unitID_;
185 #endif
186  primaryID_ = theTrack_->GetTrackID();
187 
188  theEntryPoint_.setX(TheEntryPoint.x());
189  theEntryPoint_.setY(TheEntryPoint.y());
190  theEntryPoint_.setZ(TheEntryPoint.z());
191  theExitPoint_.setX(TheExitPoint.x());
192  theExitPoint_.setY(TheExitPoint.y());
193  theExitPoint_.setZ(TheExitPoint.z());
194 
196  Pabs_ = aStep->GetPreStepPoint()->GetMomentum().mag() / GeV;
197  Tof_ = aStep->GetPostStepPoint()->GetGlobalTime() / nanosecond;
198 
199  Eloss_ = aStep->GetTotalEnergyDeposit() / GeV;
200  ParticleType_ = theTrack_->GetDefinition()->GetPDGEncoding();
201 
202  ThetaAtEntry_ = aStep->GetPreStepPoint()->GetPosition().theta();
203  PhiAtEntry_ = aStep->GetPreStepPoint()->GetPosition().phi();
204 
205  ParentId_ = theTrack_->GetParentID();
206  Vx_ = theTrack_->GetVertexPosition().x();
207  Vy_ = theTrack_->GetVertexPosition().y();
208  Vz_ = theTrack_->GetVertexPosition().z();
209 }
210 
212  if (primaryID_ < 1) {
213  edm::LogWarning("PPSSim") << "***** PPSPixelSD error: primaryID = " << primaryID_ << " maybe detector name changed";
214  }
215 
216  // Update if in the same detector, time-slice and for same track
217  if (tSliceID_ == tsID_ && unitID_ == previousUnitID_) {
218  updateHit();
219  return true;
220  }
221 
222  // Reset entry point for new primary
223  if (primaryID_ != primID_)
225 
226  //look in the HitContainer whether a hit with the same primID_, unitID_,
227  //tSliceID_ already exists:
228  bool found = false;
229  int nhits = theHC_->entries();
230  for (int j = 0; j < nhits && !found; j++) {
231  PPSPixelG4Hit* aPreviousHit = (*theHC_)[j];
232  if (aPreviousHit->trackID() == primaryID_ && aPreviousHit->timeSliceID() == tSliceID_ &&
233  aPreviousHit->unitID() == unitID_) {
234  currentHit_ = aPreviousHit;
235  found = true;
236  }
237  }
238 
239  if (found) {
240  updateHit();
241  return true;
242  }
243  return false;
244 }
245 
247 #ifdef debug
248  LogDebug("PPSSim") << "PPSPixelSD CreateNewHit for"
249  << " PV " << currentPV_->GetName() << " PVid = " << currentPV_->GetCopyNo()
250  << " MVid = " << currentPV_->GetMother()->GetCopyNo() << " Unit " << unitID_ << "\n"
251  << " primary " << primaryID_ << " time slice " << tSliceID_ << " For Track "
252  << theTrack_->GetTrackID() << " which is a " << theTrack_->GetDefinition()->GetParticleName();
253 
254  if (theTrack_->GetTrackID() == 1) {
255  LogDebug("PPSSim") << " of energy " << theTrack_->GetTotalEnergy();
256  } else {
257  LogDebug("PPSSim") << " daughter of part. " << theTrack_->GetParentID();
258  }
259 
260  if (theTrack_->GetCreatorProcess() != NULL)
261  LogDebug("PPSSim") << theTrack_->GetCreatorProcess()->GetProcessName();
262  else
263  LogDebug("PPSSim") << "NO process";
264 #endif
265 
271 
278 
282 
287 
288  updateHit();
289 
291 }
292 
294  if (Eloss_ > 0.) {
295 #ifdef debug
296  LogDebug("PPSSim") << "G4PPSPixelSD updateHit: add eloss " << Eloss_ << "\nCurrentHit=" << currentHit_
297  << ", PostStepPoint=" << postStepPoint_->GetPosition();
298 #endif
300  }
301  // buffer for next steps:
302  tsID_ = tSliceID_;
305 }
306 
308  if (primID_ < 0)
309  return;
310  if (hit == nullptr) {
311  edm::LogWarning("PPSSim") << "PPSPixelSD: hit to be stored is NULL !!";
312  return;
313  }
314 
315  theHC_->insert(hit);
316 }
317 
320 
321  incidentEnergy_ = preStepPoint_->GetKineticEnergy();
322 }
323 
PPSPixelG4Hit::setTrackID
void setTrackID(int i)
Definition: PPSPixelG4Hit.cc:147
PPSPixelG4Hit::setParentId
void setParentId(int p)
Definition: PPSPixelG4Hit.cc:201
PPSPixelG4Hit::setTimeSlice
void setTimeSlice(double d)
Definition: PPSPixelG4Hit.cc:153
SimTrackManager
Definition: SimTrackManager.h:35
PPSPixelSD::ParticleType_
short ParticleType_
Definition: PPSPixelSD.h:117
mps_fire.i
i
Definition: mps_fire.py:428
PPSPixelSD::storeHit
void storeHit(PPSPixelG4Hit *)
Definition: PPSPixelSD.cc:307
MessageLogger.h
PPSPixelSD::ProcessHits
bool ProcessHits(G4Step *, G4TouchableHistory *) override
Definition: PPSPixelSD.cc:73
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
PPSPixelSD::currentHit_
PPSPixelG4Hit * currentHit_
Definition: PPSPixelSD.h:99
PPSPixelG4Hit::setThetaAtEntry
void setThetaAtEntry(float t)
Definition: PPSPixelG4Hit.cc:188
PPSPixelG4Hit::setVz
void setVz(float p)
Definition: PPSPixelG4Hit.cc:210
PV3DBase::x
T x() const
Definition: PV3DBase.h:59
PPSPixelSD::Initialize
void Initialize(G4HCofThisEvent *HCE) override
Definition: PPSPixelSD.cc:87
PPSPixelG4Hit::energyLoss
float energyLoss() const
Definition: PPSPixelG4Hit.cc:165
PPSPixelSD::update
void update(const BeginOfEvent *) override
This routine will be called when the appropriate signal arrives.
Definition: PPSPixelSD.cc:144
PPSPixelSD::EndOfEvent
void EndOfEvent(G4HCofThisEvent *eventHC) override
Definition: PPSPixelSD.cc:101
SensitiveTkDetector
Definition: SensitiveTkDetector.h:8
PPSPixelG4Hit
Definition: PPSPixelG4Hit.h:38
PPSPixelSD::primaryID_
int primaryID_
Definition: PPSPixelSD.h:103
PPSPixelG4Hit::tof
float tof() const
Definition: PPSPixelG4Hit.cc:164
PPSPixelSD::eventno_
int eventno_
Definition: PPSPixelSD.h:125
PPSPixelSD::primID_
G4int primID_
Definition: PPSPixelSD.h:91
PPSPixelSD::hitPoint_
G4ThreeVector hitPoint_
Definition: PPSPixelSD.h:109
PPSPixelG4Hit::thetaAtEntry
float thetaAtEntry() const
Definition: PPSPixelG4Hit.cc:185
PPSPixelSD::hitExists
bool hitExists()
Definition: PPSPixelSD.cc:211
PPSPixelSD::postStepPoint_
G4StepPoint * postStepPoint_
Definition: PPSPixelSD.h:107
PPSPixelNumberingScheme.h
PPSPixelSD::summarize
void summarize()
Definition: PPSPixelSD.cc:324
edm::ParameterSet::getUntrackedParameter
T getUntrackedParameter(std::string const &, T const &) const
PPSPixelSD::tSlice_
double tSlice_
Definition: PPSPixelSD.h:104
TrackingSlaveSD.h
PPSPixelSD::edeposit_
float edeposit_
Definition: PPSPixelSD.h:108
edm::LogInfo
Log< level::Info, false > LogInfo
Definition: MessageLogger.h:125
PPSPixelSD::updateHit
void updateHit()
Definition: PPSPixelSD.cc:293
PPSPixelG4Hit::setUnitID
void setUnitID(uint32_t i)
Definition: PPSPixelG4Hit.cc:150
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
PPSPixelG4Hit::setParticleType
void setParticleType(short i)
Definition: PPSPixelG4Hit.cc:183
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
PPSPixelG4Hit::setVy
void setVy(float p)
Definition: PPSPixelG4Hit.cc:207
PPSPixelSD::ThetaAtEntry_
float ThetaAtEntry_
Definition: PPSPixelSD.h:119
PPSPixelSD::Vz_
float Vz_
Definition: PPSPixelSD.h:123
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
PPSPixelSD::numberingScheme_
std::unique_ptr< PPSVDetectorOrganization > numberingScheme_
Definition: PPSPixelSD.h:82
PPSPixelG4Hit::exitPoint
const G4ThreeVector & exitPoint() const
Definition: PPSPixelG4Hit.cc:133
PPSPixelG4Hit::unitID
uint32_t unitID() const
Definition: PPSPixelG4Hit.cc:149
PPSPixelSD::previousUnitID_
uint32_t previousUnitID_
Definition: PPSPixelSD.h:102
PPSPixelSD.h
PPSPixelSD::stepInfo
void stepInfo(const G4Step *aStep)
Definition: PPSPixelSD.cc:161
PPSPixelSD::PhiAtEntry_
float PhiAtEntry_
Definition: PPSPixelSD.h:120
PPSPixelSD::PPSPixelSD
PPSPixelSD(const std::string &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, SimTrackManager const *)
Definition: PPSPixelSD.cc:37
PPSPixelSD::~PPSPixelSD
~PPSPixelSD() override
Definition: PPSPixelSD.cc:71
PPSPixelSD::hcID_
G4int hcID_
Definition: PPSPixelSD.h:94
G4ProcessTypeEnumerator.h
PPSPixelG4Hit::setMeanPosition
void setMeanPosition(const G4ThreeVector &a)
Definition: PPSPixelG4Hit.h:54
PPSPixelSD::theEntryPoint_
G4ThreeVector theEntryPoint_
Definition: PPSPixelSD.h:112
PPSPixelG4Hit::setExitPoint
void setExitPoint(const G4ThreeVector &)
Definition: PPSPixelG4Hit.cc:135
PPSPixelSD::Pabs_
float Pabs_
Definition: PPSPixelSD.h:114
SensitiveDetectorCatalog
Definition: SensitiveDetectorCatalog.h:10
PPSPixelSD::theExitPoint_
G4ThreeVector theExitPoint_
Definition: PPSPixelSD.h:113
PPSPixelSD::fillHits
void fillHits(edm::PSimHitContainer &, const std::string &) override
Definition: PPSPixelSD.cc:138
Point3DBase< float, LocalTag >
bysipixelclustmulteventfilter_cfi.collectionName
collectionName
Definition: bysipixelclustmulteventfilter_cfi.py:5
nhits
Definition: HIMultiTrackSelector.h:42
SensitiveDetector::FinalStepPosition
Local3DPoint FinalStepPosition(const G4Step *step, coordinates) const
Definition: SensitiveDetector.cc:66
PPSPixelSD::position_
G4ThreeVector position_
Definition: PPSPixelSD.h:111
SensitiveDetector::InitialStepPosition
Local3DPoint InitialStepPosition(const G4Step *step, coordinates) const
Definition: SensitiveDetector.cc:54
PPSPixelG4HitCollection
G4THitsCollection< PPSPixelG4Hit > PPSPixelG4HitCollection
Definition: PPSPixelG4HitCollection.h:26
PPSPixelG4Hit::phiAtEntry
float phiAtEntry() const
Definition: PPSPixelG4Hit.cc:186
PPSPixelSD::tSliceID_
int tSliceID_
Definition: PPSPixelSD.h:103
PPSPixelG4Hit::z
float z() const
Definition: PPSPixelG4Hit.cc:197
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
PPSPixelSD::maxPixelHits_
static constexpr unsigned int maxPixelHits_
Definition: PPSPixelSD.h:70
PPSPixelG4Hit::particleType
int particleType() const
Definition: PPSPixelG4Hit.cc:166
PPSPixelSD::Vy_
float Vy_
Definition: PPSPixelSD.h:123
GeV
const double GeV
Definition: MathUtil.h:16
PPSPixelSD::entrancePoint_
G4ThreeVector entrancePoint_
Definition: PPSPixelSD.h:89
PPSPixelG4Hit::setIncidentEnergy
void setIncidentEnergy(double e)
Definition: PPSPixelG4Hit.cc:144
PPSPixelSD::createNewHit
void createNewHit()
Definition: PPSPixelSD.cc:246
PPSPixelG4Hit::timeSliceID
int timeSliceID() const
Definition: PPSPixelG4Hit.cc:154
PV3DBase::y
T y() const
Definition: PV3DBase.h:60
SensitiveDetector::LocalCoordinates
Definition: SensitiveDetector.h:38
createfilelist.int
int
Definition: createfilelist.py:10
PPSPixelSD::unitID_
uint32_t unitID_
Definition: PPSPixelSD.h:102
UpdatablePSimHit.h
PPSPixelG4Hit::setEnergyLoss
void setEnergyLoss(float e)
Definition: PPSPixelG4Hit.cc:182
BeginOfEvent
Definition: BeginOfEvent.h:6
TrackInformation.h
PPSPixelSD::DrawAll
void DrawAll() override
Definition: PPSPixelSD.cc:131
PPSPixelSD::ParentId_
int ParentId_
Definition: PPSPixelSD.h:122
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
PPSPixelG4Hit::p
float p() const
Definition: PPSPixelG4Hit.cc:163
NULL
#define NULL
Definition: scimark2.h:8
PPSPixelSD::theTrack_
G4Track * theTrack_
Definition: PPSPixelSD.h:100
PPSPixelG4Hit::entryPoint
const G4ThreeVector & entryPoint() const
Definition: PPSPixelG4Hit.cc:129
PPSPixelSD::Vx_
float Vx_
Definition: PPSPixelSD.h:123
PPSPixelSD::tsID_
int tsID_
Definition: PPSPixelSD.h:98
PPSPixelSD::setDetUnitId
uint32_t setDetUnitId(const G4Step *) override
Definition: PPSPixelSD.cc:83
G4TrackToParticleID.h
PPSPixelSD::resetForNewPrimary
void resetForNewPrimary()
Definition: PPSPixelSD.cc:318
PPSPixelSD::Tof_
float Tof_
Definition: PPSPixelSD.h:115
PPSPixelG4Hit::trackID
int trackID() const
Definition: PPSPixelG4Hit.cc:146
PPSPixelSD::clearHits
void clearHits() override
Definition: PPSPixelSD.cc:152
PPSPixelG4Hit::setP
void setP(float e)
Definition: PPSPixelG4Hit.cc:174
PPSPixelSD::setToLocal
G4ThreeVector setToLocal(const G4ThreeVector &globalPoint)
Definition: PPSPixelSD.cc:154
PPSPixelG4Hit::setTof
void setTof(float e)
Definition: PPSPixelG4Hit.cc:181
PPSPixelSD::incidentEnergy_
float incidentEnergy_
Definition: PPSPixelSD.h:90
PPSPixelSD::clear
void clear() override
Definition: PPSPixelSD.cc:129
PPSPixelSD::Eloss_
float Eloss_
Definition: PPSPixelSD.h:116
PPSPixelSD::slave_
std::unique_ptr< TrackingSlaveSD > slave_
Definition: PPSPixelSD.h:81
PPSPixelSD::preStepPoint_
G4StepPoint * preStepPoint_
Definition: PPSPixelSD.h:106
PPSPixelSD::name_
std::string name_
Definition: PPSPixelSD.h:93
edm::PSimHitContainer
std::vector< PSimHit > PSimHitContainer
Definition: PSimHitContainer.h:11
ParameterSet.h
PPSPixelG4Hit::setEntryPoint
void setEntryPoint(const G4ThreeVector &)
Definition: PPSPixelG4Hit.cc:131
PSimHit
Definition: PSimHit.h:15
PbPb_ZMuSkimMuonDPG_cff.particleType
particleType
Definition: PbPb_ZMuSkimMuonDPG_cff.py:27
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:56
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
PPSPixelSD::PrintAll
void PrintAll() override
Definition: PPSPixelSD.cc:133
PPSPixelSD::theHC_
PPSPixelG4HitCollection * theHC_
Definition: PPSPixelSD.h:95
PPSPixelSD::currentPV_
G4VPhysicalVolume * currentPV_
Definition: PPSPixelSD.h:101
hit
Definition: SiStripHitEffFromCalibTree.cc:88
PPSPixelG4Hit::setPhiAtEntry
void setPhiAtEntry(float f)
Definition: PPSPixelG4Hit.cc:189
PPSPixelG4Hit::setVx
void setVx(float p)
Definition: PPSPixelG4Hit.cc:204