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 ){
165 MuonBaseNumber <<
"MuonNumbering :: number of levels = "<<num.
getLevels()<<std::endl;
166 MuonBaseNumber <<
"Level \t SuperNo \t BaseNo"<<std::endl;
173 LogDebug(
"MuonSimDebug") <<
"MuonSensitiveDetector::setDetUnitId :: "<<MuonBaseNumbr;
195 G4VPhysicalVolume*
pv = aStep->GetPreStepPoint()->GetPhysicalVolume();
196 G4Track *
t = aStep->GetTrack();
203 G4VPhysicalVolume*
pv = aStep->GetPreStepPoint()->GetPhysicalVolume();
204 G4Track *
t = aStep->GetTrack();
206 LogDebug(
"MuonSimDebug") <<
"MuonSensitiveDetector::newHit :: currentUnitId = "<<currentUnitId;
207 unsigned int currentTrackID=t->GetTrackID();
209 bool changed=((pv!=
thePV) ||
217 G4Track * theTrack = aStep->GetTrack();
229 float zentry = theEntryPoint.
z();
230 float zexit = theExitPoint.
z();
234 theEntryPoint =
Local3DPoint( tempEntryPoint.
x(), tempEntryPoint.
y(), zentry );
235 theExitPoint =
Local3DPoint( tempExitPoint.
x(), tempExitPoint.
y(), zexit );
241 float thePabs = aStep->GetPreStepPoint()->GetMomentum().mag()/
GeV;
242 float theTof = aStep->GetPreStepPoint()->GetGlobalTime()/nanosecond;
243 float theEnergyLoss = aStep->GetTotalEnergyDeposit()/
GeV;
246 G4ThreeVector gmd = aStep->GetPreStepPoint()->GetMomentumDirection();
247 G4ThreeVector lmd = ((
const G4TouchableHistory *)(aStep->GetPreStepPoint()->GetTouchable()))->GetHistory()
248 ->GetTopTransform().TransformAxis(gmd);
250 float theThetaAtEntry = lnmd.
theta();
251 float thePhiAtEntry = lnmd.
phi();
261 G4StepPoint * preStepPoint = aStep->GetPreStepPoint();
262 const G4TouchableHistory * theTouchable=(
const G4TouchableHistory *)
263 (preStepPoint->GetTouchable());
269 LogDebug(
"MuonSimDebug") <<
"MuonSensitiveDetector::createHit UpdatablePSimHit"<<std::endl;
277 LogDebug(
"MuonSimDebug") <<
"=== NEW ==================> ELOSS = "<<theEnergyLoss<<
" "
278 <<
thePV->GetLogicalVolume()->GetName()<<std::endl;
279 const G4VProcess*
p = aStep->GetPostStepPoint()->GetProcessDefinedStep();
280 const G4VProcess*
p2 = aStep->GetPreStepPoint()->GetProcessDefinedStep();
282 LogDebug(
"MuonSimDebug") <<
" POST PROCESS = "<<p->GetProcessName()<<std::endl;
284 LogDebug(
"MuonSimDebug") <<
" PRE PROCESS = "<<p2->GetProcessName()<<std::endl;
285 LogDebug(
"MuonSimDebug") <<
"newhit theta " << theThetaAtEntry<<std::endl;
286 LogDebug(
"MuonSimDebug") <<
"newhit phi " << thePhiAtEntry<<std::endl;
287 LogDebug(
"MuonSimDebug") <<
"newhit pabs " << thePabs<<std::endl;
288 LogDebug(
"MuonSimDebug") <<
"newhit tof " << theTof<<std::endl;
290 LogDebug(
"MuonSimDebug") <<
"newhit entry " << theEntryPoint<<std::endl;
291 LogDebug(
"MuonSimDebug") <<
"newhit exit " << theExitPoint<<std::endl;
292 LogDebug(
"MuonSimDebug") <<
"newhit eloss " << theEnergyLoss << std::endl;
294 LogDebug(
"MuonSimDebug") <<
"newhit delta " << (theExitPoint-theEntryPoint)<<std::endl;
295 LogDebug(
"MuonSimDebug") <<
"newhit deltu " << (theExitPoint-theEntryPoint).
unit();
296 LogDebug(
"MuonSimDebug") <<
" " << (theExitPoint-theEntryPoint).
mag()<<std::endl;
298 LogDebug(
"MuonSimDebug") <<
"newhit dpos " << theGlobalPos<<std::endl;
299 LogDebug(
"MuonSimDebug") <<
"newhit drot " << std::endl;
306 int thePID = theTrack->GetDefinition()->GetPDGEncoding();
307 LogDebug(
"MuonSimDebug") <<
" checking simtrack " << thePID <<
" " << thePabs <<
" STenergyPersistentCut " <<
STenergyPersistentCut << std::endl;
312 LogDebug(
"MuonSimDebug") <<
" track leaving hit in muons made selected for persistency"<<std::endl;
331 float zexit = theExitPoint.
z();
333 theExitPoint =
Local3DPoint( tempExitPoint.
x(), tempExitPoint.
y(), zexit );
338 float theEnergyLoss = aStep->GetTotalEnergyDeposit()/
GeV;
341 std::cerr <<
"!!ERRROR in MuonSensitiveDetector::updateHit. It is called when there is no hit " << std::endl;
347 LogDebug(
"MuonSimDebug") <<
"=== UPDATE ===============> ELOSS = "<<theEnergyLoss<<
" "
348 <<
thePV->GetLogicalVolume()->GetName()<<std::endl;
349 const G4VProcess*
p = aStep->GetPostStepPoint()->GetProcessDefinedStep();
350 const G4VProcess*
p2 = aStep->GetPreStepPoint()->GetProcessDefinedStep();
352 LogDebug(
"MuonSimDebug") <<
" POST PROCESS = "<<p->GetProcessName()<<std::endl;
354 LogDebug(
"MuonSimDebug") <<
" PRE PROCESS = "<<p2->GetProcessName()<<std::endl;
355 LogDebug(
"MuonSimDebug") <<
"updhit exit " << theExitPoint<<std::endl;
387 G4VUserTrackInformation*
temp = gTrack->GetUserInformation();
389 std::cerr <<
" ERROR: no G4VUserTrackInformation available"<<std::endl;
394 std::cerr <<
" ERROR: TkSimTrackSelection: the UserInformation does not appear to be a TrackInformation"<<std::endl;
419 std::vector<std::string>
temp;
426 G4StepPoint * preStepPoint = currentStep->GetPreStepPoint();
427 G4ThreeVector globalCoordinates = preStepPoint->GetPosition();
429 const G4TouchableHistory * theTouchable=(
const G4TouchableHistory *)
430 (preStepPoint->GetTouchable());
432 G4int
depth = theTouchable->GetHistory()->GetDepth();
433 G4ThreeVector localCoordinates = theTouchable->GetHistory()
434 ->GetTransform(depth-levelsUp).TransformPoint(globalCoordinates);
441 G4StepPoint * postStepPoint = currentStep->GetPostStepPoint();
442 G4StepPoint * preStepPoint = currentStep->GetPreStepPoint();
443 G4ThreeVector globalCoordinates = postStepPoint->GetPosition();
445 const G4TouchableHistory * theTouchable = (
const G4TouchableHistory *)
446 (preStepPoint->GetTouchable());
448 G4int
depth = theTouchable->GetHistory()->GetDepth();
449 G4ThreeVector localCoordinates = theTouchable->GetHistory()
450 ->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())
int getBaseNo(int level) const
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 *)
int getSuperNo(int level) const
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