CMS 3D CMS Logo

TotemRPSD.cc
Go to the documentation of this file.
1 // File: TotemRPSD.cc
2 // Date: 18.10.2005
3 // Description: Sensitive Detector class for TOTEM RP Detectors
4 // Modifications:
7 
10 
15 
17 
20 
21 #include "G4SDManager.hh"
22 #include "G4Step.hh"
23 #include "G4Track.hh"
24 #include "G4VProcess.hh"
25 
26 #include "G4PhysicalConstants.hh"
27 #include "G4SystemOfUnits.hh"
28 
29 #include <iostream>
30 #include <vector>
31 #include <string>
32 
34  const edm::EventSetup& es,
35  const SensitiveDetectorCatalog& clg,
36  edm::ParameterSet const& p,
37  const SimTrackManager* manager)
38  : SensitiveTkDetector(name_, es, clg, p),
39  numberingScheme_(nullptr),
40  hcID_(-1),
41  theHC_(nullptr),
42  currentHit_(nullptr),
43  theTrack_(nullptr),
44  currentPV_(nullptr),
45  unitID_(0),
46  preStepPoint_(nullptr),
47  postStepPoint_(nullptr),
48  eventno_(0) {
49  collectionName.insert(name_);
50 
51  edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("TotemRPSD");
52  verbosity_ = m_Anal.getParameter<int>("Verbosity");
53 
54  slave_ = std::make_unique<TrackingSlaveSD>(name_);
55 
56  if (name_ == "TotemHitsRP") {
57  numberingScheme_ = std::make_unique<PPSStripNumberingScheme>(3);
58  } else {
59  edm::LogWarning("TotemRP") << "TotemRPSD: ReadoutName not supported\n";
60  }
61 
62  edm::LogInfo("TotemRP") << "TotemRPSD: Instantiation completed";
63 }
64 
66 
67 void TotemRPSD::Initialize(G4HCofThisEvent* HCE) {
68  LogDebug("TotemRP") << "TotemRPSD : Initialize called for " << name_;
69 
70  theHC_ = new TotemRPG4HitCollection(GetName(), collectionName[0]);
71  G4SDManager::GetSDMpointer()->AddNewCollection(name_, collectionName[0]);
72 
73  if (hcID_ < 0)
74  hcID_ = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
75  HCE->AddHitsCollection(hcID_, theHC_);
76 }
77 
79  LogDebug("TotemRP") << theTrack_->GetDefinition()->GetParticleName() << " TotemRPSD CreateNewHit for"
80  << " PV " << currentPV_->GetName() << " PVid = " << currentPV_->GetCopyNo() << " Unit "
81  << unitID_;
82  LogDebug("TotemRP") << " primary " << primaryID_ << " time slice " << tSliceID_ << " of energy "
83  << theTrack_->GetTotalEnergy() << " Eloss_ " << Eloss_ << " positions ";
84  printf("(%10f,%10f,%10f)",
85  preStepPoint_->GetPosition().x(),
86  preStepPoint_->GetPosition().y(),
87  preStepPoint_->GetPosition().z());
88  printf("(%10f,%10f,%10f)",
89  postStepPoint_->GetPosition().x(),
90  postStepPoint_->GetPosition().y(),
91  postStepPoint_->GetPosition().z());
92  LogDebug("TotemRP") << " positions "
93  << "(" << postStepPoint_->GetPosition().x() << "," << postStepPoint_->GetPosition().y() << ","
94  << postStepPoint_->GetPosition().z() << ")"
95  << " For Track " << theTrack_->GetTrackID() << " which is a "
96  << theTrack_->GetDefinition()->GetParticleName();
97 
98  if (theTrack_->GetTrackID() == 1) {
99  LogDebug("TotemRP") << " primary particle ";
100  } else {
101  LogDebug("TotemRP") << " daughter of part. " << theTrack_->GetParentID();
102  }
103 
104  LogDebug("TotemRP") << " and created by ";
105 
106  if (theTrack_->GetCreatorProcess() != nullptr)
107  LogDebug("TotemRP") << theTrack_->GetCreatorProcess()->GetProcessName();
108  else
109  LogDebug("TotemRP") << "NO process";
110 
111  LogDebug("TotemRP") << std::endl;
112 }
113 
114 bool TotemRPSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
115  if (aStep == nullptr) {
116  return true;
117  } else {
118  stepInfo(aStep);
119 
120  createNewHit();
121  return true;
122  }
123 }
124 
125 void TotemRPSD::stepInfo(const G4Step* aStep) {
126  preStepPoint_ = aStep->GetPreStepPoint();
127  postStepPoint_ = aStep->GetPostStepPoint();
128  theTrack_ = aStep->GetTrack();
129  hitPoint_ = preStepPoint_->GetPosition();
130  exitPoint_ = postStepPoint_->GetPosition();
131  currentPV_ = preStepPoint_->GetPhysicalVolume();
134 
135  G4String name_ = currentPV_->GetName();
136  name_.assign(name_, 0, 4);
137  G4String particleType = theTrack_->GetDefinition()->GetParticleName();
138  tSlice_ = (postStepPoint_->GetGlobalTime()) / nanosecond;
139  tSliceID_ = (int)tSlice_;
140  unitID_ = setDetUnitId(aStep);
141 
142  if (verbosity_)
143  LogDebug("TotemRP") << "UNIT " << unitID_ << std::endl;
144 
145  primaryID_ = theTrack_->GetTrackID();
146 
147  Pabs_ = (aStep->GetPreStepPoint()->GetMomentum().mag()) / GeV;
148  thePx_ = (aStep->GetPreStepPoint()->GetMomentum().x()) / GeV;
149  thePy_ = (aStep->GetPreStepPoint()->GetMomentum().y()) / GeV;
150  thePz_ = (aStep->GetPreStepPoint()->GetMomentum().z()) / GeV;
151 
152  Tof_ = aStep->GetPostStepPoint()->GetGlobalTime() / nanosecond;
153  Eloss_ = aStep->GetTotalEnergyDeposit() / GeV;
154  ParticleType_ = theTrack_->GetDefinition()->GetPDGEncoding();
155 
156  //corrected phi and theta treatment
157  G4ThreeVector gmd = aStep->GetPreStepPoint()->GetMomentumDirection();
158  // convert it to local frame
159  G4ThreeVector lmd = ((G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable()))
160  ->GetHistory()
161  ->GetTopTransform()
162  .TransformAxis(gmd);
164  ThetaAtEntry_ = lnmd.theta();
165  PhiAtEntry_ = lnmd.phi();
166 
167  if (isPrimary(theTrack_))
168  ParentId_ = 0;
169  else
170  ParentId_ = theTrack_->GetParentID();
171 
172  Vx_ = theTrack_->GetVertexPosition().x() / mm;
173  Vy_ = theTrack_->GetVertexPosition().y() / mm;
174  Vz_ = theTrack_->GetVertexPosition().z() / mm;
175 }
176 
177 uint32_t TotemRPSD::setDetUnitId(const G4Step* aStep) {
178  return (numberingScheme_ == nullptr ? 0 : numberingScheme_->unitID(aStep));
179 }
180 
182  if (hit == nullptr) {
183  if (verbosity_)
184  LogDebug("TotemRP") << "TotemRPSD: hit to be stored is NULL !!" << std::endl;
185  return;
186  }
187  theHC_->insert(hit);
188 }
189 
191  // Protect against creating hits in detectors not inserted
192  double outrangeX = hitPoint_.x();
193  double outrangeY = hitPoint_.y();
194  if (fabs(outrangeX) > rp_garage_position_)
195  return;
196  if (fabs(outrangeY) > rp_garage_position_)
197  return;
198  // end protection
199 
205 
212 
217 
222 
226 
228 }
229 
230 G4ThreeVector TotemRPSD::setToLocal(const G4ThreeVector& global) {
231  G4ThreeVector localPoint;
232  const G4VTouchable* touch = preStepPoint_->GetTouchable();
233  localPoint = touch->GetHistory()->GetTopTransform().TransformPoint(global);
234  return localPoint;
235 }
236 
237 void TotemRPSD::EndOfEvent(G4HCofThisEvent*) {
238  // here we loop over transient hits and make them persistent
239  for (unsigned int j = 0; j < (unsigned int)theHC_->entries() && j < maxTotemHits_; j++) {
240  TotemRPG4Hit* aHit = (*theHC_)[j];
241 
242  Local3DPoint entry(aHit->localEntry().x(), aHit->localEntry().y(), aHit->localEntry().z());
243  Local3DPoint exit(aHit->localExit().x(), aHit->localExit().y(), aHit->localExit().z());
244  slave_->processHits(PSimHit(entry,
245  exit,
246  aHit->p(),
247  aHit->tof(),
248  aHit->energyLoss(),
249  aHit->particleType(),
250  aHit->unitID(),
251  aHit->trackID(),
252  aHit->thetaAtEntry(),
253  aHit->phiAtEntry()));
254  }
255  summarize();
256 }
257 
259 
261 
263 
265  LogDebug("TotemRP") << "TotemRPSD: Collection " << theHC_->GetName() << std::endl;
266  theHC_->PrintAllHits();
267 }
268 
270  if (slave_->name() == n) {
271  c = slave_->hits();
272  }
273 }
275  if (scheme) {
276  LogDebug("TotemRP") << "TotemRPSD: updates numbering scheme for " << GetName();
277  numberingScheme_.reset(scheme);
278  }
279 }
281  clearHits();
282  eventno_ = (*i)()->GetEventID();
283 }
284 
285 void TotemRPSD::update(const ::EndOfEvent*) {}
286 
287 void TotemRPSD::clearHits() { slave_->Initialize(); }
288 
289 bool TotemRPSD::isPrimary(const G4Track* track) {
290  TrackInformation* info = dynamic_cast<TrackInformation*>(track->GetUserInformation());
291  return info && info->isPrimary();
292 }
#define LogDebug(id)
void setEntry(G4ThreeVector xyz)
Definition: TotemRPG4Hit.cc:76
G4ThreeVector localEntry() const
Definition: TotemRPG4Hit.cc:81
T getParameter(std::string const &) const
void fillHits(edm::PSimHitContainer &, const std::string &) override
Definition: TotemRPSD.cc:269
unsigned int trackID() const
Definition: TotemRPG4Hit.cc:89
int particleType() const
static const TGPicture * info(bool iBackgroundIsBlack)
const double GeV
Definition: MathUtil.h:16
G4Track * theTrack_
Definition: TotemRPSD.h:87
void DrawAll() override
Definition: TotemRPSD.cc:262
void setTof(double e)
G4THitsCollection< TotemRPG4Hit > TotemRPG4HitCollection
Local3DPoint ConvertToLocal3DPoint(const G4ThreeVector &point) const
void setP(double e)
double Tof_
Definition: TotemRPSD.h:102
G4ThreeVector setToLocal(const G4ThreeVector &globalPoint)
Definition: TotemRPSD.cc:230
void createNewHit()
Definition: TotemRPSD.cc:190
void setIncidentEnergy(double e)
Definition: TotemRPG4Hit.cc:87
G4int tSliceID_
Definition: TotemRPSD.h:90
G4VPhysicalVolume * currentPV_
Definition: TotemRPSD.h:88
std::unique_ptr< TotemRPVDetectorOrganization > numberingScheme_
Definition: TotemRPSD.h:58
void storeHit(TotemRPG4Hit *)
Definition: TotemRPSD.cc:181
#define nullptr
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
bool ProcessHits(G4Step *step, G4TouchableHistory *tHistory) override
Definition: TotemRPSD.cc:114
void PrintAll() override
Definition: TotemRPSD.cc:264
int unitID() const
Definition: TotemRPG4Hit.cc:92
int eventno_
Definition: TotemRPSD.h:114
void setVx(double p)
TotemRPSD(const std::string &, const edm::EventSetup &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
Definition: TotemRPSD.cc:33
void setPy(double p)
TotemRPG4HitCollection * theHC_
Definition: TotemRPSD.h:84
double p() const
Definition: TotemRPG4Hit.cc:99
double Pabs_
Definition: TotemRPSD.h:100
G4double tSlice_
Definition: TotemRPSD.h:91
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
void setLocalEntry(const G4ThreeVector &theLocalEntryPoint)
Definition: TotemRPG4Hit.cc:82
void stepInfo(const G4Step *aStep)
Definition: TotemRPSD.cc:125
void clearHits() override
Definition: TotemRPSD.cc:287
void printHitInfo()
Definition: TotemRPSD.cc:78
void Initialize(G4HCofThisEvent *HCE) override
Definition: TotemRPSD.cc:67
void EndOfEvent(G4HCofThisEvent *eventHC) override
Definition: TotemRPSD.cc:237
double phiAtEntry() const
void setExit(G4ThreeVector xyz)
Definition: TotemRPG4Hit.cc:79
void clear() override
Definition: TotemRPSD.cc:260
G4ThreeVector theLocalEntryPoint_
Definition: TotemRPSD.h:97
int ParentId_
Definition: TotemRPSD.h:109
uint32_t setDetUnitId(const G4Step *step) override
Definition: TotemRPSD.cc:177
short ParticleType_
Definition: TotemRPSD.h:104
G4StepPoint * postStepPoint_
Definition: TotemRPSD.h:94
int verbosity_
Definition: TotemRPSD.h:61
unsigned int unitID_
Definition: TotemRPSD.h:89
G4int primaryID_
Definition: TotemRPSD.h:90
void setLocalExit(const G4ThreeVector &theLocalExitPoint)
Definition: TotemRPG4Hit.cc:84
void setThetaAtEntry(double t)
void setNumberingScheme(TotemRPVDetectorOrganization *scheme)
Definition: TotemRPSD.cc:274
G4StepPoint * preStepPoint_
Definition: TotemRPSD.h:93
void setUnitID(unsigned int i)
Definition: TotemRPG4Hit.cc:93
static unsigned int maxTotemHits_
Definition: TotemRPSD.h:48
double energyLoss() const
static double rp_garage_position_
Definition: TotemRPSD.h:45
double PhiAtEntry_
Definition: TotemRPSD.h:107
double Vy_
Definition: TotemRPSD.h:110
G4ThreeVector theLocalExitPoint_
Definition: TotemRPSD.h:98
double ThetaAtEntry_
Definition: TotemRPSD.h:106
double Vz_
Definition: TotemRPSD.h:110
double thetaAtEntry() const
void setPhiAtEntry(double f)
bool isPrimary() const
double thePz_
Definition: TotemRPSD.h:101
G4ThreeVector localExit() const
Definition: TotemRPG4Hit.cc:83
void setVz(double p)
double thePx_
Definition: TotemRPSD.h:101
double incidentEnergy_
Definition: TotemRPSD.h:80
double tof() const
void setParentId(int p)
void setTrackID(int i)
Definition: TotemRPG4Hit.cc:90
G4ThreeVector exitPoint_
Definition: TotemRPSD.h:96
void setPz(double p)
void update(const BeginOfEvent *) override
This routine will be called when the appropriate signal arrives.
Definition: TotemRPSD.cc:280
void summarize()
Definition: TotemRPSD.cc:258
void setParticleType(short i)
G4int hcID_
Definition: TotemRPSD.h:83
std::vector< PSimHit > PSimHitContainer
bool isPrimary(const G4Track *track)
Definition: TotemRPSD.cc:289
~TotemRPSD() override
Definition: TotemRPSD.cc:65
double Eloss_
Definition: TotemRPSD.h:103
void setEnergyLoss(double e)
std::unique_ptr< TrackingSlaveSD > slave_
Definition: TotemRPSD.h:57
void setVy(double p)
double thePy_
Definition: TotemRPSD.h:101
void setPx(double p)
G4ThreeVector hitPoint_
Definition: TotemRPSD.h:95
TotemRPG4Hit * currentHit_
Definition: TotemRPSD.h:86
double Vx_
Definition: TotemRPSD.h:110
G4String name_
Definition: TotemRPSD.h:82
void setTimeSlice(double d)
Definition: TotemRPG4Hit.cc:96
def exit(msg="")