21 #include "G4SDManager.hh"
22 #include "G4VProcess.hh"
23 #include "G4EventManager.hh"
24 #include "G4SystemOfUnits.hh"
36 thePV(0), theHit(0), theDetUnitId(0), theTrackID(0), theManager(manager)
47 LogDebug(
"MuonSimDebug") <<
"create MuonSubDetector "<<name<<std::endl;
51 LogDebug(
"MuonSimDebug") <<
"create MuonFrameRotation"<<std::endl;
65 LogDebug(
"MuonSimDebug") <<
"create MuonSlaveSD"<<std::endl;
67 LogDebug(
"MuonSimDebug") <<
"create MuonSimHitNumberingScheme"<<std::endl;
75 std::vector<std::string> lvNames = clg.
logicalNames(name);
77 for (std::vector<std::string>::iterator it = lvNames.begin(); it != lvNames.end(); it++){
78 LogDebug(
"MuonSimDebug") << name <<
" MuonSensitiveDetector:: attaching SD to LV " << *it << std::endl;
87 LogDebug(
"MuonSimDebug") <<
" EnergyThresholdForPersistency " << STenergyPersistentCut <<
" AllMuonsPersistent " << STallMuonsPersistent << std::endl;
125 LogDebug(
"MuonSimDebug") <<
"MuonSensitiveDetector::clearHits"<<std::endl;
135 if (aStep->GetTotalEnergyDeposit()>0.){
137 if( aStep->GetTrack()->GetDynamicParticle()->GetCharge() != 0 ){
178 G4VPhysicalVolume* pv = aStep->GetPreStepPoint()->GetPhysicalVolume();
179 G4Track *
t = aStep->GetTrack();
186 G4VPhysicalVolume* pv = aStep->GetPreStepPoint()->GetPhysicalVolume();
187 G4Track *
t = aStep->GetTrack();
189 unsigned int currentTrackID=t->GetTrackID();
191 bool changed=((pv!=
thePV) ||
199 G4Track * theTrack = aStep->GetTrack();
211 float zentry = theEntryPoint.
z();
212 float zexit = theExitPoint.
z();
216 theEntryPoint =
Local3DPoint( tempEntryPoint.
x(), tempEntryPoint.
y(), zentry );
217 theExitPoint =
Local3DPoint( tempExitPoint.
x(), tempExitPoint.
y(), zexit );
223 float thePabs = aStep->GetPreStepPoint()->GetMomentum().mag()/
GeV;
224 float theTof = aStep->GetPreStepPoint()->GetGlobalTime()/nanosecond;
225 float theEnergyLoss = aStep->GetTotalEnergyDeposit()/
GeV;
228 G4ThreeVector gmd = aStep->GetPreStepPoint()->GetMomentumDirection();
229 G4ThreeVector lmd = ((
const G4TouchableHistory *)(aStep->GetPreStepPoint()->GetTouchable()))->GetHistory()
230 ->GetTopTransform().TransformAxis(gmd);
232 float theThetaAtEntry = lnmd.
theta();
233 float thePhiAtEntry = lnmd.
phi();
243 G4StepPoint * preStepPoint = aStep->GetPreStepPoint();
244 const G4TouchableHistory * theTouchable=(
const G4TouchableHistory *)
245 (preStepPoint->GetTouchable());
251 LogDebug(
"MuonSimDebug") <<
"MuonSensitiveDetector::createHit UpdatablePSimHit"<<std::endl;
259 LogDebug(
"MuonSimDebug") <<
"=== NEW ==================> ELOSS = "<<theEnergyLoss<<
" "
260 <<
thePV->GetLogicalVolume()->GetName()<<std::endl;
261 const G4VProcess*
p = aStep->GetPostStepPoint()->GetProcessDefinedStep();
262 const G4VProcess*
p2 = aStep->GetPreStepPoint()->GetProcessDefinedStep();
264 LogDebug(
"MuonSimDebug") <<
" POST PROCESS = "<<p->GetProcessName()<<std::endl;
266 LogDebug(
"MuonSimDebug") <<
" PRE PROCESS = "<<p2->GetProcessName()<<std::endl;
267 LogDebug(
"MuonSimDebug") <<
"newhit theta " << theThetaAtEntry<<std::endl;
268 LogDebug(
"MuonSimDebug") <<
"newhit phi " << thePhiAtEntry<<std::endl;
269 LogDebug(
"MuonSimDebug") <<
"newhit pabs " << thePabs<<std::endl;
270 LogDebug(
"MuonSimDebug") <<
"newhit tof " << theTof<<std::endl;
272 LogDebug(
"MuonSimDebug") <<
"newhit entry " << theEntryPoint<<std::endl;
273 LogDebug(
"MuonSimDebug") <<
"newhit exit " << theExitPoint<<std::endl;
274 LogDebug(
"MuonSimDebug") <<
"newhit eloss " << theEnergyLoss << std::endl;
276 LogDebug(
"MuonSimDebug") <<
"newhit delta " << (theExitPoint-theEntryPoint)<<std::endl;
277 LogDebug(
"MuonSimDebug") <<
"newhit deltu " << (theExitPoint-theEntryPoint).
unit();
278 LogDebug(
"MuonSimDebug") <<
" " << (theExitPoint-theEntryPoint).
mag()<<std::endl;
280 LogDebug(
"MuonSimDebug") <<
"newhit dpos " << theGlobalPos<<std::endl;
281 LogDebug(
"MuonSimDebug") <<
"newhit drot " << std::endl;
288 int thePID = theTrack->GetDefinition()->GetPDGEncoding();
289 LogDebug(
"MuonSimDebug") <<
" checking simtrack " << thePID <<
" " << thePabs <<
" STenergyPersistentCut " <<
STenergyPersistentCut << std::endl;
294 LogDebug(
"MuonSimDebug") <<
" track leaving hit in muons made selected for persistency"<<std::endl;
313 float zexit = theExitPoint.
z();
315 theExitPoint =
Local3DPoint( tempExitPoint.
x(), tempExitPoint.
y(), zexit );
320 float theEnergyLoss = aStep->GetTotalEnergyDeposit()/
GeV;
323 std::cerr <<
"!!ERRROR in MuonSensitiveDetector::updateHit. It is called when there is no hit " << std::endl;
329 LogDebug(
"MuonSimDebug") <<
"=== UPDATE ===============> ELOSS = "<<theEnergyLoss<<
" "
330 <<
thePV->GetLogicalVolume()->GetName()<<std::endl;
331 const G4VProcess*
p = aStep->GetPostStepPoint()->GetProcessDefinedStep();
332 const G4VProcess*
p2 = aStep->GetPreStepPoint()->GetProcessDefinedStep();
334 LogDebug(
"MuonSimDebug") <<
" POST PROCESS = "<<p->GetProcessName()<<std::endl;
336 LogDebug(
"MuonSimDebug") <<
" PRE PROCESS = "<<p2->GetProcessName()<<std::endl;
337 LogDebug(
"MuonSimDebug") <<
"updhit exit " << theExitPoint<<std::endl;
369 G4VUserTrackInformation*
temp = gTrack->GetUserInformation();
371 std::cerr <<
" ERROR: no G4VUserTrackInformation available"<<std::endl;
376 std::cerr <<
" ERROR: TkSimTrackSelection: the UserInformation does not appear to be a TrackInformation"<<std::endl;
401 std::vector<std::string>
temp;
408 G4StepPoint * preStepPoint = currentStep->GetPreStepPoint();
409 G4ThreeVector globalCoordinates = preStepPoint->GetPosition();
411 const G4TouchableHistory * theTouchable=(
const G4TouchableHistory *)
412 (preStepPoint->GetTouchable());
414 G4int depth = theTouchable->GetHistory()->GetDepth();
415 G4ThreeVector localCoordinates = theTouchable->GetHistory()
416 ->GetTransform(depth-levelsUp).TransformPoint(globalCoordinates);
423 G4StepPoint * postStepPoint = currentStep->GetPostStepPoint();
424 G4StepPoint * preStepPoint = currentStep->GetPreStepPoint();
425 G4ThreeVector globalCoordinates = postStepPoint->GetPosition();
427 const G4TouchableHistory * theTouchable = (
const G4TouchableHistory *)
428 (preStepPoint->GetTouchable());
430 G4int depth = theTouchable->GetHistory()->GetDepth();
431 G4ThreeVector localCoordinates = theTouchable->GetHistory()
432 ->GetTransform(depth-levelsUp).TransformPoint(globalCoordinates);
T getParameter(std::string const &) const
Local3DPoint FinalStepPositionVsParent(G4Step *currentStep, G4int levelsUp)
std::vector< std::string > logicalNames(std::string &readoutName)
void printLocal(LocalPoint, LocalPoint) const
T mag() const
The vector magnitude. Equivalent to sqrt(vec.mag2())
Geom::Phi< T > phi() const
void fillHits(edm::PSimHitContainer &, std::string use)
virtual Local3DPoint transformPoint(const Local3DPoint &, const G4Step *) const =0
type of data representation of DDCompactView
MuonSubDetector * detector
virtual void EndOfEvent(G4HCofThisEvent *)
bool STallMuonsPersistent
unsigned int processId(const G4VProcess *p)
Geom::Theta< T > theta() const
std::vector< PSimHit > & hits()
Point3DBase< float, GlobalTag > Global3DPoint
Local3DPoint exitPoint() const
Exit point in the local Det frame.
virtual ~MuonSensitiveDetector()
Local3DPoint ConvertToLocal3DPoint(const G4ThreeVector &point)
void updateExitPoint(const Local3DPoint &exit)
virtual void Initialize()
G4ProcessTypeEnumerator * theG4ProcessTypeEnumerator
Global3DPoint theGlobalEntry
Local3DPoint toOrcaUnits(Local3DPoint)
Abs< T >::type abs(const T &t)
std::vector< std::string > getNames()
const SimTrackManager * theManager
void printGlobal(GlobalPoint) const
static int particleID(const G4Track *)
MuonFrameRotation * theRotation
virtual int baseNumberToUnitNumber(const MuonBaseNumber &)
MuonBaseNumber PhysicalVolumeToBaseNumber(const G4Step *aStep)
double STenergyPersistentCut
Point3DBase< float, LocalTag > Local3DPoint
void addEnergyLoss(float eloss)
void startNewSimHit(std::string)
MuonSimHitNumberingScheme * numbering
MuonSensitiveDetector(std::string, const DDCompactView &, SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
Local3DPoint toOrcaRef(Local3DPoint in, G4Step *s)
G4TrackToParticleID * myG4TrackToParticleID
virtual void AssignSD(std::string &vname)
float energyLoss() const
The energy deposit in the PSimHit, in ???.
G4VPhysicalVolume * thePV
virtual bool processHits(const PSimHit &)
void update(const BeginOfEvent *)
This routine will be called when the appropriate signal arrives.
std::vector< PSimHit > PSimHitContainer
Local3DPoint InitialStepPositionVsParent(G4Step *currentStep, G4int levelsUp)
Local3DPoint FinalStepPosition(G4Step *s, coordinates)
virtual uint32_t setDetUnitId(G4Step *)
void storeVolumeAndTrack(G4Step *)
TrackInformation * getOrCreateTrackInformation(const G4Track *theTrack)
Local3DPoint entryPoint() const
Entry point in the local Det frame.
Local3DPoint InitialStepPosition(G4Step *s, coordinates)
unsigned int detUnitId() const
UpdatablePSimHit * theHit
MuonG4Numbering * g4numbering
virtual G4bool ProcessHits(G4Step *, G4TouchableHistory *)
SimHitPrinter * thePrinter