CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PLTSensitiveDetector.cc
Go to the documentation of this file.
2 
5 
9 
12 
14 
19 
20 #include "G4Track.hh"
21 #include "G4SDManager.hh"
22 #include "G4VProcess.hh"
23 #include "G4EventManager.hh"
24 #include "G4Event.hh"
25 #include "G4VProcess.hh"
26 
27 #include "G4SystemOfUnits.hh"
28 
29 #include <string>
30 #include <vector>
31 #include <iostream>
32 
33 
35  const DDCompactView & cpv,
37  edm::ParameterSet const & p,
38  const SimTrackManager* manager) :
39  SensitiveTkDetector(name, cpv, clg, p), myName(name), mySimHit(0),
40  oldVolume(0), lastId(0), lastTrack(0), eventno(0) {
41 
42  edm::ParameterSet m_TrackerSD = p.getParameter<edm::ParameterSet>("PltSD");
43  energyCut = m_TrackerSD.getParameter<double>("EnergyThresholdForPersistencyInGeV")*GeV; //default must be 0.5
44  energyHistoryCut = m_TrackerSD.getParameter<double>("EnergyThresholdForHistoryInGeV")*GeV;//default must be 0.05
45 
46  edm::LogInfo("PLTSensitiveDetector") <<"Criteria for Saving Tracker SimTracks: \n "
47  <<" History: "<<energyHistoryCut<< " MeV ; Persistency: "<< energyCut<<" MeV\n"
48  <<" Constructing a PLTSensitiveDetector with ";
49 
50  slave = new TrackingSlaveSD(name);
51 
52  // Now attach the right detectors (LogicalVolumes) to me
53  std::vector<std::string> lvNames = clg.logicalNames(name);
54  this->Register();
55  for (std::vector<std::string>::iterator it = lvNames.begin();
56  it != lvNames.end(); it++) {
57  edm::LogInfo("PLTSensitiveDetector")<< name << " attaching LV " << *it;
58  this->AssignSD(*it);
59  }
60 
63 }
64 
66  delete slave;
68  delete myG4TrackToParticleID;
69 }
70 
71 bool PLTSensitiveDetector::ProcessHits(G4Step * aStep, G4TouchableHistory *) {
72 
73  LogDebug("PLTSensitiveDetector") << " Entering a new Step "
74  << aStep->GetTotalEnergyDeposit() << " "
75  << aStep->GetPreStepPoint()->GetPhysicalVolume()->GetLogicalVolume()->GetName();
76 
77  G4Track * gTrack = aStep->GetTrack();
78  if ((unsigned int)(gTrack->GetTrackID()) != lastTrack) {
79 
80  if (gTrack->GetKineticEnergy() > energyCut){
82  info->storeTrack(true);
83  }
84  if (gTrack->GetKineticEnergy() > energyHistoryCut){
86  info->putInHistory();
87  }
88  }
89 
90  if (aStep->GetTotalEnergyDeposit()>0.) {
91  if (newHit(aStep) == true) {
92  sendHit();
93  createHit(aStep);
94  } else {
95  updateHit(aStep);
96  }
97  return true;
98  }
99  return false;
100 }
101 
103 
104  unsigned int detId = 0;
105 
106  LogDebug("PLTSensitiveDetector")<< " DetID = "<<detId;
107 
108  return detId;
109 }
110 
111 void PLTSensitiveDetector::EndOfEvent(G4HCofThisEvent *) {
112 
113  LogDebug("PLTSensitiveDetector")<< " Saving the last hit in a ROU " << myName;
114 
115  if (mySimHit == 0) return;
116  sendHit();
117 }
118 
120  if (slave->name() == n) c=slave->hits();
121 }
122 
124  if (mySimHit == 0) return;
125  LogDebug("PLTSensitiveDetector") << " Storing PSimHit: " << pname << " " << mySimHit->detUnitId()
126  << " " << mySimHit->trackId() << " " << mySimHit->energyLoss()
127  << " " << mySimHit->entryPoint() << " " << mySimHit->exitPoint();
128 
130 
131  // clean up
132  delete mySimHit;
133  mySimHit = 0;
134  lastTrack = 0;
135  lastId = 0;
136 }
137 
138 void PLTSensitiveDetector::updateHit(G4Step * aStep) {
139 
141  float theEnergyLoss = aStep->GetTotalEnergyDeposit()/GeV;
142  mySimHit->setExitPoint(theExitPoint);
143  LogDebug("PLTSensitiveDetector")<< " Before : " << mySimHit->energyLoss();
144  mySimHit->addEnergyLoss(theEnergyLoss);
146 
147  LogDebug("PLTSensitiveDetector") << " Updating: new exitpoint " << pname << " "
148  << theExitPoint << " new energy loss " << theEnergyLoss
149  << "\n Updated PSimHit: " << mySimHit->detUnitId()
150  << " " << mySimHit->trackId()
151  << " " << mySimHit->energyLoss() << " "
152  << mySimHit->entryPoint() << " " << mySimHit->exitPoint();
153 }
154 
155 bool PLTSensitiveDetector::newHit(G4Step * aStep) {
156 
157  G4Track * theTrack = aStep->GetTrack();
158  uint32_t theDetUnitId = setDetUnitId(aStep);
159  unsigned int theTrackID = theTrack->GetTrackID();
160 
161  LogDebug("PLTSensitiveDetector") << " OLD (d,t) = (" << lastId << "," << lastTrack
162  << "), new = (" << theDetUnitId << "," << theTrackID << ") return "
163  << ((theTrackID == lastTrack) && (lastId == theDetUnitId));
164  if ((mySimHit != 0) && (theTrackID == lastTrack) && (lastId == theDetUnitId) && closeHit(aStep))
165  return false;
166  return true;
167 }
168 
169 bool PLTSensitiveDetector::closeHit(G4Step * aStep) {
170 
171  if (mySimHit == 0) return false;
172  const float tolerance = 0.05 * mm; // 50 micron are allowed between the exit
173  // point of the current hit and the entry point of the new hit
175  LogDebug("PLTSensitiveDetector")<< " closeHit: distance = " << (mySimHit->exitPoint()-theEntryPoint).mag();
176 
177  if ((mySimHit->exitPoint()-theEntryPoint).mag()<tolerance) return true;
178  return false;
179 }
180 
181 void PLTSensitiveDetector::createHit(G4Step * aStep) {
182 
183  if (mySimHit != 0) {
184  delete mySimHit;
185  mySimHit=0;
186  }
187 
188  G4Track * theTrack = aStep->GetTrack();
189  G4VPhysicalVolume * v = aStep->GetPreStepPoint()->GetPhysicalVolume();
190 
193 
194  float thePabs = aStep->GetPreStepPoint()->GetMomentum().mag()/GeV;
195  float theTof = aStep->GetPreStepPoint()->GetGlobalTime()/nanosecond;
196  float theEnergyLoss = aStep->GetTotalEnergyDeposit()/GeV;
197  int theParticleType = myG4TrackToParticleID->particleID(theTrack);
198  uint32_t theDetUnitId = setDetUnitId(aStep);
199 
202  pname = theTrack->GetDynamicParticle()->GetDefinition()->GetParticleName();
203 
204  unsigned int theTrackID = theTrack->GetTrackID();
205 
206  G4ThreeVector gmd = aStep->GetPreStepPoint()->GetMomentumDirection();
207  // convert it to local frame
208  G4ThreeVector lmd = ((G4TouchableHistory *)(aStep->GetPreStepPoint()->GetTouchable()))->GetHistory()->GetTopTransform().TransformAxis(gmd);
210  float theThetaAtEntry = lnmd.theta();
211  float thePhiAtEntry = lnmd.phi();
212 
213  mySimHit = new UpdatablePSimHit(theEntryPoint,theExitPoint,thePabs,theTof,
214  theEnergyLoss,theParticleType,theDetUnitId,
215  theTrackID,theThetaAtEntry,thePhiAtEntry,
216  theG4ProcessTypeEnumerator->processId(theTrack->GetCreatorProcess()));
217 
218  LogDebug("PLTSensitiveDetector") << " Created PSimHit: " << pname << " "
219  << mySimHit->detUnitId() << " " << mySimHit->trackId()
220  << " " << mySimHit->energyLoss() << " "
221  << mySimHit->entryPoint() << " " << mySimHit->exitPoint();
222  lastId = theDetUnitId;
223  lastTrack = theTrackID;
224  oldVolume = v;
225 }
226 
228 
230 
231  clearHits();
232  eventno = (*i)()->GetEventID();
233  mySimHit = 0;
234 }
235 
237 
238  const G4Track* gTrack = (*bot)();
239  pname = gTrack->GetDynamicParticle()->GetDefinition()->GetParticleName();
240 }
241 
243  slave->Initialize();
244 }
245 
247  G4VUserTrackInformation* temp = gTrack->GetUserInformation();
248  if (temp == 0){
249  edm::LogError("PLTSensitiveDetector") <<" ERROR: no G4VUserTrackInformation available";
250  abort();
251  }else{
252  TrackInformation* info = dynamic_cast<TrackInformation*>(temp);
253  if (info == 0){
254  edm::LogError("PLTSensitiveDetector") <<" ERROR: TkSimTrackSelection: the UserInformation does not appear to be a TrackInformation";
255  abort();
256  }
257  return info;
258  }
259 }
#define LogDebug(id)
T getParameter(std::string const &) const
int i
Definition: DBlmapReader.cc:9
UpdatablePSimHit * mySimHit
virtual void createHit(G4Step *)
std::vector< std::string > logicalNames(std::string &readoutName)
static const TGPicture * info(bool iBackgroundIsBlack)
G4TrackToParticleID * myG4TrackToParticleID
bool storeTrack() const
void update(const BeginOfEvent *)
This routine will be called when the appropriate signal arrives.
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
std::string name() const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
TrackInformation * getOrCreateTrackInformation(const G4Track *)
void setExitPoint(const Local3DPoint &exit)
G4ProcessTypeEnumerator * theG4ProcessTypeEnumerator
G4VPhysicalVolume * oldVolume
type of data representation of DDCompactView
Definition: DDCompactView.h:77
virtual bool newHit(G4Step *)
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
virtual bool closeHit(G4Step *)
std::vector< PSimHit > & hits()
Local3DPoint exitPoint() const
Exit point in the local Det frame.
Definition: PSimHit.h:38
Local3DPoint ConvertToLocal3DPoint(const G4ThreeVector &point)
virtual void Initialize()
TrackingSlaveSD * slave
virtual void updateHit(G4Step *)
void fillHits(edm::PSimHitContainer &, std::string use)
static int particleID(const G4Track *)
virtual uint32_t setDetUnitId(G4Step *)
void addEnergyLoss(float eloss)
unsigned int processId(const G4VProcess *)
virtual void AssignSD(std::string &vname)
float energyLoss() const
The energy deposit in the PSimHit, in ???.
Definition: PSimHit.h:75
virtual void EndOfEvent(G4HCofThisEvent *)
unsigned int trackId() const
Definition: PSimHit.h:102
virtual bool ProcessHits(G4Step *, G4TouchableHistory *)
virtual bool processHits(const PSimHit &)
PLTSensitiveDetector(std::string, const DDCompactView &, SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
std::vector< PSimHit > PSimHitContainer
Local3DPoint FinalStepPosition(G4Step *s, coordinates)
Local3DPoint entryPoint() const
Entry point in the local Det frame.
Definition: PSimHit.h:35
Local3DPoint InitialStepPosition(G4Step *s, coordinates)
unsigned int detUnitId() const
Definition: PSimHit.h:93