CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
PPSDiamondSD.cc
Go to the documentation of this file.
1 //Author: Seyed Mohsen Etesami
3 // setesami@cern.ch
4 // 2016 Nov
15 #include "G4SDManager.hh"
16 #include "G4Step.hh"
17 #include "G4Track.hh"
18 #include "G4VProcess.hh"
19 #include "G4ParticleDefinition.hh"
20 #include "G4ParticleTypes.hh"
22 #include "G4PhysicalConstants.hh"
23 #include "G4SystemOfUnits.hh"
24 #include <iostream>
25 #include <vector>
26 #include <string>
27 
29  const SensitiveDetectorCatalog& clg,
30  edm::ParameterSet const& p,
31  const SimTrackManager* manager)
32  : SensitiveTkDetector(name_, clg),
33  numberingScheme_(nullptr),
34  hcID_(-1),
35  theHC_(nullptr),
36  currentHit_(nullptr),
37  theTrack_(nullptr),
38  currentPV_(nullptr),
39  unitID_(0),
40  preStepPoint_(nullptr),
41  postStepPoint_(nullptr),
42  eventno_(0) {
43  collectionName.insert(name_);
44  edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("PPSDiamondSD");
45  verbosity_ = m_Anal.getParameter<int>("Verbosity");
46 
47  LogDebug("PPSSimDiamond") << "*******************************************************\n"
48  << "* *\n"
49  << "* Constructing a PPSDiamondSD with name " << name_ << "\n"
50  << "* *\n"
51  << "*******************************************************"
52  << "\n";
53 
54  slave_ = std::make_unique<TrackingSlaveSD>(name_);
55 
56  if (name_ == "CTPPSTimingHits") {
57  numberingScheme_ = std::make_unique<PPSDiamondNumberingScheme>();
58  edm::LogInfo("PPSSimDiamond") << "Find CTPPSDiamondHits as name";
59  } else {
60  edm::LogWarning("PPSSimDiamond") << "PPSDiamondSD: ReadoutName not supported\n";
61  }
62 
63  edm::LogInfo("PPSSimDiamond") << "PPSDiamondSD: Instantiation completed";
64 }
65 
67 
68 void PPSDiamondSD::Initialize(G4HCofThisEvent* HCE) {
69  LogDebug("PPSSimDiamond") << "PPSDiamondSD : Initialize called for " << name_;
70 
72  G4SDManager::GetSDMpointer()->AddNewCollection(name_, collectionName[0]);
73  if (hcID_ < 0)
74  hcID_ = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]);
75  HCE->AddHitsCollection(hcID_, theHC_);
76 }
77 
79  LogDebug("PPSSimDiamond") << theTrack_->GetDefinition()->GetParticleName() << " PPS_Timing_SD CreateNewHit for"
80  << " PV " << currentPV_->GetName() << " PVid = " << currentPV_->GetCopyNo() << " Unit "
81  << unitID_ << "\n";
82  LogDebug("PPSSimDiamond") << " primary " << primaryID_ << " time slice " << tSliceID_ << " of energy "
83  << theTrack_->GetTotalEnergy() << " Eloss_ " << Eloss_ << " positions "
84  << "\n";
85  printf(" PreStepPoint(%10f,%10f,%10f)",
86  preStepPoint_->GetPosition().x(),
87  preStepPoint_->GetPosition().y(),
88  preStepPoint_->GetPosition().z());
89  printf(" PosStepPoint(%10f,%10f,%10f)\n",
90  postStepPoint_->GetPosition().x(),
91  postStepPoint_->GetPosition().y(),
92  postStepPoint_->GetPosition().z());
93  LogDebug("PPSSimDiamond") << " positions "
94  << "(" << postStepPoint_->GetPosition().x() << "," << postStepPoint_->GetPosition().y()
95  << "," << postStepPoint_->GetPosition().z() << ")"
96  << " For Track " << theTrack_->GetTrackID() << " which is a "
97  << theTrack_->GetDefinition()->GetParticleName() << " ParentID is "
98  << theTrack_->GetParentID() << "\n";
99 
100  if (theTrack_->GetTrackID() == 1) {
101  LogDebug("PPSSimDiamond") << " primary particle ";
102  } else {
103  LogDebug("PPSSimDiamond") << " daughter of part. " << theTrack_->GetParentID();
104  }
105 
106  LogDebug("PPSSimDiamond") << " and created by ";
107 
108  if (theTrack_->GetCreatorProcess() != nullptr)
109  LogDebug("PPSSimDiamond") << theTrack_->GetCreatorProcess()->GetProcessName();
110  else
111  LogDebug("PPSSimDiamond") << "NO process";
112 
113  LogDebug("PPSSimDiamond") << "\n";
114 }
115 
116 bool PPSDiamondSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) {
117  if (aStep == nullptr) {
118  LogDebug("PPSSimDiamond") << " There is no hit to process ";
119  return true;
120  } else {
121  LogDebug("PPSSimDiamond") << "*******************************************************\n"
122  << "* *\n"
123  << "* PPS Diamond Hit initialized with name " << name_ << "\n"
124  << "* *\n"
125  << "*******************************************************"
126  << "\n";
127 
128  stepInfo(aStep);
129 
130  if (theTrack_->GetDefinition()->GetPDGEncoding() == 2212) {
131  importInfoToHit(); //in addtion to import info to hit it STORE hit as well
132  LogDebug("PPSSimDiamond") << " information imported to the hit ";
133  }
134 
135  return true;
136  }
137 }
138 
139 void PPSDiamondSD::stepInfo(const G4Step* aStep) {
140  theTrack_ = aStep->GetTrack();
141  preStepPoint_ = aStep->GetPreStepPoint();
142  postStepPoint_ = aStep->GetPostStepPoint();
143  hitPoint_ = preStepPoint_->GetPosition();
144  exitPoint_ = postStepPoint_->GetPosition();
145  currentPV_ = preStepPoint_->GetPhysicalVolume();
148  theglobaltimehit_ = preStepPoint_->GetGlobalTime() / nanosecond;
149  incidentEnergy_ = (aStep->GetPreStepPoint()->GetTotalEnergy() / eV);
150  tSlice_ = (postStepPoint_->GetGlobalTime()) / nanosecond;
151  tSliceID_ = (int)tSlice_;
152  unitID_ = setDetUnitId(aStep);
153 
154  if (verbosity_)
155  LogDebug("PPSSimDiamond") << "UNIT " << unitID_ << "\n";
156 
157  primaryID_ = theTrack_->GetTrackID();
158  Pabs_ = (aStep->GetPreStepPoint()->GetMomentum().mag()) / GeV;
159  thePx_ = (aStep->GetPreStepPoint()->GetMomentum().x()) / GeV;
160  thePy_ = (aStep->GetPreStepPoint()->GetMomentum().y()) / GeV;
161  thePz_ = (aStep->GetPreStepPoint()->GetMomentum().z()) / GeV;
162  Tof_ = aStep->GetPreStepPoint()->GetGlobalTime() / nanosecond;
163  Eloss_ = (aStep->GetPreStepPoint()->GetTotalEnergy() / eV); //pps added
164  ParticleType_ = theTrack_->GetDefinition()->GetPDGEncoding();
165 
166  //corrected phi and theta treatment
167  G4ThreeVector gmd = aStep->GetPreStepPoint()->GetMomentumDirection();
168  // convert it to local frame
169  G4ThreeVector lmd = ((G4TouchableHistory*)(aStep->GetPreStepPoint()->GetTouchable()))
170  ->GetHistory()
171  ->GetTopTransform()
172  .TransformAxis(gmd);
174  ThetaAtEntry_ = lnmd.theta();
175  PhiAtEntry_ = lnmd.phi();
176 
177  if (isPrimary(theTrack_))
178  ParentId_ = 0;
179  else
180  ParentId_ = theTrack_->GetParentID();
181 
182  Vx_ = theTrack_->GetVertexPosition().x() / mm;
183  Vy_ = theTrack_->GetVertexPosition().y() / mm;
184  Vz_ = theTrack_->GetVertexPosition().z() / mm;
185 }
186 
187 uint32_t PPSDiamondSD::setDetUnitId(const G4Step* aStep) {
188  return (numberingScheme_ == nullptr ? 0 : numberingScheme_->unitID(aStep));
189 }
190 
192  if (hit == nullptr) {
193  if (verbosity_)
194  LogDebug("PPSSimDiamond") << "PPSDiamond: hit to be stored is NULL !!"
195  << "\n";
196  return;
197  }
198 
199  theHC_->insert(hit);
200 }
201 
226 
228  LogDebug("PPSSimDiamond") << "STORED HIT IN: " << unitID_ << "\n";
229 }
230 
231 G4ThreeVector PPSDiamondSD::setToLocal(const G4ThreeVector& global) {
232  G4ThreeVector localPoint;
233  const G4VTouchable* touch = preStepPoint_->GetTouchable();
234  localPoint = touch->GetHistory()->GetTopTransform().TransformPoint(global);
235 
236  return localPoint;
237 }
238 
239 void PPSDiamondSD::EndOfEvent(G4HCofThisEvent*) {
240  // here we loop over transient hits and make them persistent
241  for (unsigned int j = 0; j < (unsigned int)theHC_->entries() && j < maxDiamondHits_; j++) {
242  PPSDiamondG4Hit* aHit = (*theHC_)[j];
243 
244  Local3DPoint entry(aHit->localEntry().x(), aHit->localEntry().y(), aHit->localEntry().z());
245  Local3DPoint exit(aHit->localExit().x(), aHit->localExit().y(), aHit->localExit().z());
246  slave_->processHits(PSimHit(entry,
247  exit,
248  aHit->p(),
249  aHit->tof(),
250  aHit->energyLoss(),
251  aHit->particleType(),
252  aHit->unitID(),
253  aHit->trackID(),
254  aHit->thetaAtEntry(),
255  aHit->phiAtEntry()));
256  }
257  summarize();
258 }
259 
261 
263 
265 
267  LogDebug("PPSSimDiamond") << "PPSDiamond: Collection " << theHC_->GetName() << "\n";
268  theHC_->PrintAllHits();
269 }
270 
272  if (slave_->name() == n)
273  c = slave_->hits();
274 }
276  if (scheme) {
277  LogDebug("PPSDiamond") << "PPSDiamondSD: updates numbering scheme for " << GetName();
278  numberingScheme_.reset(scheme);
279  }
280 }
282  LogDebug("PPSSimDiamond") << " Dispatched BeginOfEvent !"
283  << "\n";
284  clearHits();
285  eventno_ = (*i)()->GetEventID();
286 }
287 
288 void PPSDiamondSD::update(const ::EndOfEvent*) {}
289 
290 void PPSDiamondSD::clearTrack(G4Track* track) { track->SetTrackStatus(fStopAndKill); }
291 
292 void PPSDiamondSD::clearHits() { slave_->Initialize(); }
293 
294 bool PPSDiamondSD::isPrimary(const G4Track* track) {
295  TrackInformation* info = dynamic_cast<TrackInformation*>(track->GetUserInformation());
296  return info && info->isPrimary();
297 }
bool isPrimary(const G4Track *track)
G4VPhysicalVolume * currentPV_
Definition: PPSDiamondSD.h:80
unsigned int unitID_
Definition: PPSDiamondSD.h:81
G4ThreeVector setToLocal(const G4ThreeVector &globalPoint)
void setP(double e)
static const TGPicture * info(bool iBackgroundIsBlack)
const edm::EventSetup & c
const G4ThreeVector & localEntry() const
PPSDiamondG4Hit * currentHit_
Definition: PPSDiamondSD.h:78
void stepInfo(const G4Step *aStep)
void setTof(double e)
G4ThreeVector hitPoint_
Definition: PPSDiamondSD.h:87
void setVy(double p)
Local3DPoint ConvertToLocal3DPoint(const G4ThreeVector &point) const
double tof() const
const G4ThreeVector & localExit() const
void setPz(double p)
double energyLoss() const
unsigned int trackID() const
G4int primaryID_
Definition: PPSDiamondSD.h:82
std::unique_ptr< TrackingSlaveSD > slave_
Definition: PPSDiamondSD.h:57
std::unique_ptr< PPSVDetectorOrganization > numberingScheme_
Definition: PPSDiamondSD.h:58
double p() const
void setEntry(const G4ThreeVector &xyz)
Geom::Phi< T > phi() const
Definition: PV3DBase.h:66
double ThetaAtEntry_
Definition: PPSDiamondSD.h:96
G4ThreeVector theLocalEntryPoint_
Definition: PPSDiamondSD.h:89
void fillHits(edm::PSimHitContainer &, const std::string &) override
PPSDiamondSD(const std::string &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
Definition: PPSDiamondSD.cc:28
void setIncidentEnergy(double e)
G4String name_
Definition: PPSDiamondSD.h:75
void setThetaAtEntry(double t)
void setVz(double p)
static constexpr unsigned int maxDiamondHits_
Definition: PPSDiamondSD.h:48
G4ThreeVector theLocalExitPoint_
Definition: PPSDiamondSD.h:90
void clearHits() override
void setPy(double p)
bool ProcessHits(G4Step *step, G4TouchableHistory *tHistory) override
void EndOfEvent(G4HCofThisEvent *eventHC) override
uint32_t setDetUnitId(const G4Step *step) override
double Eloss_
Definition: PPSDiamondSD.h:94
double theglobaltimehit_
Definition: PPSDiamondSD.h:101
void Initialize(G4HCofThisEvent *HCE) override
Definition: PPSDiamondSD.cc:68
Geom::Theta< T > theta() const
Definition: PV3DBase.h:72
int particleType() const
void setUnitID(unsigned int i)
void setEnergyLoss(double e)
void clear() override
short ParticleType_
Definition: PPSDiamondSD.h:95
void setExit(const G4ThreeVector &xyz)
std::string const collectionName[nCollections]
Definition: Collections.h:59
void update(const BeginOfEvent *) override
This routine will be called when the appropriate signal arrives.
void setVx(double p)
G4ThreeVector exitPoint_
Definition: PPSDiamondSD.h:88
void summarize()
void PrintAll() override
double thePy_
Definition: PPSDiamondSD.h:92
printf("params %d %f %f %f\n", minT, eps, errmax, chi2max)
double PhiAtEntry_
Definition: PPSDiamondSD.h:97
G4double tSlice_
Definition: PPSDiamondSD.h:83
void storeHit(PPSDiamondG4Hit *)
void setPhiAtEntry(double f)
G4Track * theTrack_
Definition: PPSDiamondSD.h:79
void DrawAll() override
void setTrackID(int i)
PPSDiamondG4HitCollection * theHC_
Definition: PPSDiamondSD.h:77
void setParticleType(short i)
Log< level::Info, false > LogInfo
void setParentId(int p)
void setNumberingScheme(PPSVDetectorOrganization *scheme)
void setGlobalTimehit(double h)
void setLocalEntry(const G4ThreeVector &theLocalEntryPoint)
double Globaltimehit_
Definition: PPSDiamondSD.h:100
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
double thePz_
Definition: PPSDiamondSD.h:92
bool isPrimary() const
G4THitsCollection< PPSDiamondG4Hit > PPSDiamondG4HitCollection
G4StepPoint * postStepPoint_
Definition: PPSDiamondSD.h:86
double incidentEnergy_
Definition: PPSDiamondSD.h:74
list entry
Definition: mps_splice.py:68
G4StepPoint * preStepPoint_
Definition: PPSDiamondSD.h:85
double thetaAtEntry() const
double thePx_
Definition: PPSDiamondSD.h:92
double Pabs_
Definition: PPSDiamondSD.h:91
std::vector< PSimHit > PSimHitContainer
G4int tSliceID_
Definition: PPSDiamondSD.h:82
Log< level::Warning, false > LogWarning
void importInfoToHit()
int unitID() const
void setLocalExit(const G4ThreeVector &theLocalExitPoint)
void printHitInfo()
Definition: PPSDiamondSD.cc:78
~PPSDiamondSD() override
Definition: PPSDiamondSD.cc:66
double phiAtEntry() const
void clearTrack(G4Track *Track)
void setPx(double p)
void setTimeSlice(double d)
#define LogDebug(id)