22 #include "G4SDManager.hh"
23 #include "G4VProcess.hh"
24 #include "G4EventManager.hh"
25 #include "G4SystemOfUnits.hh"
37 thePV(0), theHit(0), theDetUnitId(0), theTrackID(0), theManager(manager)
48 LogDebug(
"MuonSimDebug") <<
"create MuonSubDetector "<<name<<std::endl;
52 LogDebug(
"MuonSimDebug") <<
"create MuonFrameRotation"<<std::endl;
69 LogDebug(
"MuonSimDebug") <<
"create MuonSlaveSD"<<std::endl;
71 LogDebug(
"MuonSimDebug") <<
"create MuonSimHitNumberingScheme"<<std::endl;
79 const std::vector<std::string>& lvNames = clg.
logicalNames(name);
81 for (std::vector<std::string>::const_iterator it = lvNames.begin(); it != lvNames.end(); it++){
82 LogDebug(
"MuonSimDebug") << name <<
" MuonSensitiveDetector:: attaching SD to LV " << *it << std::endl;
91 LogDebug(
"MuonSimDebug") <<
" EnergyThresholdForPersistency " << STenergyPersistentCut <<
" AllMuonsPersistent " << STallMuonsPersistent << std::endl;
129 LogDebug(
"MuonSimDebug") <<
"MuonSensitiveDetector::clearHits"<<std::endl;
139 if (aStep->GetTotalEnergyDeposit()>0.){
141 if( aStep->GetTrack()->GetDynamicParticle()->GetCharge() != 0 ){
182 G4VPhysicalVolume*
pv = aStep->GetPreStepPoint()->GetPhysicalVolume();
183 G4Track *
t = aStep->GetTrack();
190 G4VPhysicalVolume*
pv = aStep->GetPreStepPoint()->GetPhysicalVolume();
191 G4Track *
t = aStep->GetTrack();
193 unsigned int currentTrackID=t->GetTrackID();
195 bool changed=((pv!=
thePV) ||
203 G4Track * theTrack = aStep->GetTrack();
215 float zentry = theEntryPoint.
z();
216 float zexit = theExitPoint.
z();
220 theEntryPoint =
Local3DPoint( tempEntryPoint.
x(), tempEntryPoint.
y(), zentry );
221 theExitPoint =
Local3DPoint( tempExitPoint.
x(), tempExitPoint.
y(), zexit );
227 float thePabs = aStep->GetPreStepPoint()->GetMomentum().mag()/
GeV;
228 float theTof = aStep->GetPreStepPoint()->GetGlobalTime()/nanosecond;
229 float theEnergyLoss = aStep->GetTotalEnergyDeposit()/
GeV;
232 G4ThreeVector gmd = aStep->GetPreStepPoint()->GetMomentumDirection();
233 G4ThreeVector lmd = ((
const G4TouchableHistory *)(aStep->GetPreStepPoint()->GetTouchable()))->GetHistory()
234 ->GetTopTransform().TransformAxis(gmd);
236 float theThetaAtEntry = lnmd.
theta();
237 float thePhiAtEntry = lnmd.
phi();
247 G4StepPoint * preStepPoint = aStep->GetPreStepPoint();
248 const G4TouchableHistory * theTouchable=(
const G4TouchableHistory *)
249 (preStepPoint->GetTouchable());
255 LogDebug(
"MuonSimDebug") <<
"MuonSensitiveDetector::createHit UpdatablePSimHit"<<std::endl;
263 LogDebug(
"MuonSimDebug") <<
"=== NEW ==================> ELOSS = "<<theEnergyLoss<<
" "
264 <<
thePV->GetLogicalVolume()->GetName()<<std::endl;
265 const G4VProcess*
p = aStep->GetPostStepPoint()->GetProcessDefinedStep();
266 const G4VProcess*
p2 = aStep->GetPreStepPoint()->GetProcessDefinedStep();
268 LogDebug(
"MuonSimDebug") <<
" POST PROCESS = "<<p->GetProcessName()<<std::endl;
270 LogDebug(
"MuonSimDebug") <<
" PRE PROCESS = "<<p2->GetProcessName()<<std::endl;
271 LogDebug(
"MuonSimDebug") <<
"newhit theta " << theThetaAtEntry<<std::endl;
272 LogDebug(
"MuonSimDebug") <<
"newhit phi " << thePhiAtEntry<<std::endl;
273 LogDebug(
"MuonSimDebug") <<
"newhit pabs " << thePabs<<std::endl;
274 LogDebug(
"MuonSimDebug") <<
"newhit tof " << theTof<<std::endl;
276 LogDebug(
"MuonSimDebug") <<
"newhit entry " << theEntryPoint<<std::endl;
277 LogDebug(
"MuonSimDebug") <<
"newhit exit " << theExitPoint<<std::endl;
278 LogDebug(
"MuonSimDebug") <<
"newhit eloss " << theEnergyLoss << std::endl;
280 LogDebug(
"MuonSimDebug") <<
"newhit delta " << (theExitPoint-theEntryPoint)<<std::endl;
281 LogDebug(
"MuonSimDebug") <<
"newhit deltu " << (theExitPoint-theEntryPoint).
unit();
282 LogDebug(
"MuonSimDebug") <<
" " << (theExitPoint-theEntryPoint).
mag()<<std::endl;
284 LogDebug(
"MuonSimDebug") <<
"newhit dpos " << theGlobalPos<<std::endl;
285 LogDebug(
"MuonSimDebug") <<
"newhit drot " << std::endl;
292 int thePID = theTrack->GetDefinition()->GetPDGEncoding();
293 LogDebug(
"MuonSimDebug") <<
" checking simtrack " << thePID <<
" " << thePabs <<
" STenergyPersistentCut " <<
STenergyPersistentCut << std::endl;
298 LogDebug(
"MuonSimDebug") <<
" track leaving hit in muons made selected for persistency"<<std::endl;
317 float zexit = theExitPoint.
z();
319 theExitPoint =
Local3DPoint( tempExitPoint.
x(), tempExitPoint.
y(), zexit );
324 float theEnergyLoss = aStep->GetTotalEnergyDeposit()/
GeV;
327 std::cerr <<
"!!ERRROR in MuonSensitiveDetector::updateHit. It is called when there is no hit " << std::endl;
333 LogDebug(
"MuonSimDebug") <<
"=== UPDATE ===============> ELOSS = "<<theEnergyLoss<<
" "
334 <<
thePV->GetLogicalVolume()->GetName()<<std::endl;
335 const G4VProcess*
p = aStep->GetPostStepPoint()->GetProcessDefinedStep();
336 const G4VProcess*
p2 = aStep->GetPreStepPoint()->GetProcessDefinedStep();
338 LogDebug(
"MuonSimDebug") <<
" POST PROCESS = "<<p->GetProcessName()<<std::endl;
340 LogDebug(
"MuonSimDebug") <<
" PRE PROCESS = "<<p2->GetProcessName()<<std::endl;
341 LogDebug(
"MuonSimDebug") <<
"updhit exit " << theExitPoint<<std::endl;
373 G4VUserTrackInformation*
temp = gTrack->GetUserInformation();
375 std::cerr <<
" ERROR: no G4VUserTrackInformation available"<<std::endl;
380 std::cerr <<
" ERROR: TkSimTrackSelection: the UserInformation does not appear to be a TrackInformation"<<std::endl;
405 std::vector<std::string>
temp;
412 G4StepPoint * preStepPoint = currentStep->GetPreStepPoint();
413 G4ThreeVector globalCoordinates = preStepPoint->GetPosition();
415 const G4TouchableHistory * theTouchable=(
const G4TouchableHistory *)
416 (preStepPoint->GetTouchable());
418 G4int depth = theTouchable->GetHistory()->GetDepth();
419 G4ThreeVector localCoordinates = theTouchable->GetHistory()
420 ->GetTransform(depth-levelsUp).TransformPoint(globalCoordinates);
427 G4StepPoint * postStepPoint = currentStep->GetPostStepPoint();
428 G4StepPoint * preStepPoint = currentStep->GetPreStepPoint();
429 G4ThreeVector globalCoordinates = postStepPoint->GetPosition();
431 const G4TouchableHistory * theTouchable = (
const G4TouchableHistory *)
432 (preStepPoint->GetTouchable());
434 G4int depth = theTouchable->GetHistory()->GetDepth();
435 G4ThreeVector localCoordinates = theTouchable->GetHistory()
436 ->GetTransform(depth-levelsUp).TransformPoint(globalCoordinates);
T getParameter(std::string const &) const
Local3DPoint FinalStepPositionVsParent(G4Step *currentStep, G4int levelsUp)
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
const std::vector< std::string > & logicalNames(const std::string &readoutName) const
type of data representation of DDCompactView
virtual void AssignSD(const std::string &vname)
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
Local3DPoint toOrcaRef(Local3DPoint in, G4Step *s)
G4TrackToParticleID * myG4TrackToParticleID
float energyLoss() const
The energy deposit in the PSimHit, in ???.
MuonSensitiveDetector(std::string, const DDCompactView &, const SensitiveDetectorCatalog &, edm::ParameterSet const &, const SimTrackManager *)
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