10 #include "G4EventManager.hh"
11 #include "G4LogicalVolumeStore.hh"
12 #include "G4LogicalVolume.hh"
15 #include "G4SystemOfUnits.hh"
16 #include "DD4hep/Filter.h"
30 const std::vector<std::string>& fineNames,
31 const std::vector<int>& fineLevels,
32 const std::vector<int>& useFines,
37 putHistory_(putHistory),
38 doFineCalo_(doFineCalo),
46 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing: Have a possibility of " << fineNames.size()
47 <<
" fine calorimeters of which " << useFines.size() <<
" are selected";
48 for (
unsigned int k = 0;
k < fineNames.size(); ++
k)
50 std::ostringstream st1;
51 for (
unsigned int k = 0;
k < useFines.size(); ++
k)
52 st1 <<
" [" <<
k <<
"] " << useFines[
k] <<
":" << fineNames[useFines[
k]];
53 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing used calorimeters" << st1.str();
60 for (
unsigned int i = 0;
i < csps.
levels_.size();
i++)
74 <<
" does not match with " << csps.
neighbours_.size() <<
" ==> illegal ";
76 <<
"Calorimeter array size does not match with size of neighbours\n";
79 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
80 std::vector<G4LogicalVolume*>::const_iterator lvcite;
83 G4LogicalVolume* lv =
nullptr;
85 for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
86 G4String namx(static_cast<std::string>(dd4hep::dd::noNamespace((*lvcite)->GetName())));
99 <<
" too few compaerd to " << istart + csps.
neighbours_[
i]
100 <<
" requested ==> illegal ";
102 <<
"InsideNames array size does not match with list of neighbours\n";
104 std::vector<std::string> inside;
105 std::vector<G4LogicalVolume*> insideLV;
106 std::vector<int> insideLevels;
110 for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
111 G4String namx(static_cast<std::string>(dd4hep::dd::noNamespace((*lvcite)->GetName())));
117 inside.push_back(name);
118 insideLV.push_back(lv);
129 for (
unsigned int i = 0;
i < useFines.size();
i++) {
130 G4LogicalVolume* lv =
nullptr;
131 G4String name =
static_cast<G4String
>(fineNames[useFines[
i]]);
132 for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
133 G4String namx(static_cast<std::string>(dd4hep::dd::noNamespace((*lvcite)->GetName())));
143 detector.
level = fineLevels[useFines[
i]];
175 G4Track* theTrack = aStep->GetTrack();
176 int id = theTrack->GetTrackID();
180 if (trkInfo ==
nullptr) {
181 edm::LogError(
"CaloSim") <<
"CaloTrkProcessing: No trk info !!!! abort ";
182 throw cms::Exception(
"Unknown",
"CaloTrkProcessing") <<
"cannot get trkInfo for Track " <<
id <<
"\n";
194 if (prestepLV < 0 && poststepLV >= 0) {
196 edm::LogVerbatim(
"DoFineCalo") <<
"Track " <<
id <<
" entered a fine volume:"
197 <<
" pdgid=" << theTrack->GetDefinition()->GetPDGEncoding()
198 <<
" theTrack->GetCurrentStepNumber()=" << theTrack->GetCurrentStepNumber()
199 <<
" prestepLV=" << prestepLV <<
" poststepLV=" << poststepLV
200 <<
" GetKineticEnergy[GeV]=" << theTrack->GetKineticEnergy() / CLHEP::GeV
201 <<
" prestepPosition[cm]=("
202 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().x() / CLHEP::cm <<
","
203 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().y() / CLHEP::cm <<
","
204 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().z() / CLHEP::cm <<
")"
205 <<
" poststepPosition[cm]=("
206 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().x() / CLHEP::cm <<
","
207 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().y() / CLHEP::cm <<
","
208 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().z() / CLHEP::cm <<
")"
209 <<
" position[cm]=(" << theTrack->GetPosition().x() / CLHEP::cm <<
","
210 << theTrack->GetPosition().y() / CLHEP::cm <<
","
211 << theTrack->GetPosition().z() / CLHEP::cm <<
")"
212 <<
" vertex_position[cm]=(" << theTrack->GetVertexPosition().x() / CLHEP::cm <<
","
213 << theTrack->GetVertexPosition().y() / CLHEP::cm <<
","
214 << theTrack->GetVertexPosition().z() / CLHEP::cm <<
")"
215 <<
" GetVertexKineticEnergy[GeV]="
216 << theTrack->GetVertexKineticEnergy() / CLHEP::GeV;
221 edm::LogVerbatim(
"DoFineCalo") <<
"Track " <<
id <<
" marked as boundary-crossing; sanity check:"
222 <<
" theTrack->GetTrackID()=" << theTrack->GetTrackID()
228 edm::LogVerbatim(
"DoFineCalo") <<
"Track " <<
id <<
" REENTERED a fine volume;"
229 <<
" not counting this boundary crossing!";
235 else if (prestepLV >= 0 && poststepLV < 0) {
236 edm::LogVerbatim(
"DoFineCalo") <<
"Track " <<
id <<
" exited a fine volume:"
237 <<
" theTrack->GetCurrentStepNumber()=" << theTrack->GetCurrentStepNumber()
238 <<
" prestepLV=" << prestepLV <<
" poststepLV=" << poststepLV
239 <<
" GetKineticEnergy[GeV]=" << theTrack->GetKineticEnergy() / CLHEP::GeV
240 <<
" prestepPosition[cm]=("
241 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().x() / CLHEP::cm <<
","
242 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().y() / CLHEP::cm <<
","
243 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().z() / CLHEP::cm <<
")"
244 <<
" poststepPosition[cm]=("
245 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().x() / CLHEP::cm <<
","
246 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().y() / CLHEP::cm <<
","
247 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().z() / CLHEP::cm <<
")";
255 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing set IDonCaloSurface to " <<
id <<
" at step Number "
256 << theTrack->GetCurrentStepNumber();
258 trkInfo->
setIDonCaloSurface(
id, 0, 0, theTrack->GetDefinition()->GetPDGEncoding(), theTrack->GetMomentum().mag());
260 if (theTrack->GetKineticEnergy() / CLHEP::MeV >
eMin_)
269 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing Entered for " <<
id <<
" at stepNumber "
270 << theTrack->GetCurrentStepNumber() <<
" IDonCaloSur.. "
275 G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
276 const G4VTouchable* post_touch = postStepPoint->GetTouchable();
285 G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
286 const G4VTouchable* post_touch = postStepPoint->GetTouchable();
289 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
290 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
292 if (inside >= 0 || (theTrack->GetCurrentStepNumber() == 1)) {
294 id, ical, inside, theTrack->GetDefinition()->GetPDGEncoding(), theTrack->GetMomentum().mag());
299 if (theTrack->GetKineticEnergy() / CLHEP::MeV >
eMin_)
302 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing: set ID on Calo " << ical <<
" surface (Inside " << inside
303 <<
") to " <<
id <<
" of a Track with Kinetic Energy "
304 << theTrack->GetKineticEnergy() / CLHEP::MeV <<
" MeV";
314 G4LogicalVolume* lv =
nullptr;
315 for (
unsigned int it = 0; it < detectors.size(); it++) {
316 if (lastLevel != detectors[it].
level) {
317 lastLevel = detectors[it].level;
318 lv =
detLV(touch, lastLevel);
322 name1 = lv->GetName();
323 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing: volume " << name1 <<
" at Level " << lastLevel;
329 for (
int i2 = 0; i2 <
levels; i2++)
330 edm::LogVerbatim(
"CaloSim") <<
" " << i2 <<
" " << name2[i2] <<
" " << copyno2[i2];
334 bool ok = (lv == detectors[it].lv);
343 G4LogicalVolume* lv =
nullptr;
352 for (
int it1 = id1; it1 < id2; it1++) {
354 for (
unsigned int it2 = 0; it2 <
detectors_[it1].fromDets.size(); it2++) {
355 if (lastLevel !=
detectors_[it1].fromLevels[it2]) {
357 lv =
detLV(touch, lastLevel);
361 name1 = lv->GetName();
362 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing: volume " << name1 <<
" at Level " << lastLevel;
368 for (
int i2 = 0; i2 <
levels; i2++)
369 edm::LogVerbatim(
"CaloSim") <<
" " << i2 <<
" " << name2[i2] <<
" " << copyno2[i2];
379 lv =
detLV(touch, lastLevel);
383 name1 = lv->GetName();
384 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing: volume " << name1 <<
" at Level " << lastLevel;
390 for (
int i2 = 0; i2 <
levels; i2++)
391 edm::LogVerbatim(
"CaloSim") <<
" " << i2 <<
" " << name2[i2] <<
" " << copyno2[i2];
405 return ((touch->GetHistoryDepth()) + 1);
411 G4LogicalVolume* lv =
nullptr;
413 int level = ((touch->GetHistoryDepth()) + 1);
414 if (level > 0 && level >= currentlevel) {
415 int ii = level - currentlevel;
416 lv = touch->GetVolume(ii)->GetLogicalVolume();
428 int i = level -
ii - 1;
429 G4VPhysicalVolume*
pv = touch->GetVolume(i);
431 name[
ii] = pv->GetName();
434 copyno[
ii] = touch->GetReplicaNumber(i);
439 <<
" with " << level <<
":" <<
detLevels(touch) <<
" levels";
void update(const BeginOfEvent *evt) override
This routine will be called when the appropriate signal arrives.
Log< level::Info, true > LogVerbatim
G4LogicalVolume * detLV(const G4VTouchable *, int) const
std::vector< std::string > insideNames_
uint16_t *__restrict__ id
int detLevels(const G4VTouchable *) const
std::vector< int > levels_
std::vector< int > insideLevel_
Log< level::Error, false > LogError
void detectorLevel(const G4VTouchable *, int &, int *, G4String *) const
int isItInside(const G4VTouchable *, int, int)
std::vector< int > neighbours_
std::vector< int > fromLevels
std::vector< Detector > fineDetectors_
std::vector< G4LogicalVolume * > fromDetL
std::vector< std::string > fromDets
CaloTrkProcessing(const std::string &aSDname, const CaloSimulationParameters &csps, const SensitiveDetectorCatalog &clg, bool testBeam, double eMin, bool putHistory, bool doFineCalo, double eMinFine, int addlevel, const std::vector< std::string > &fineNames, const std::vector< int > &fineLevels, const std::vector< int > &useFines, const SimTrackManager *)
int isItCalo(const G4VTouchable *, const std::vector< Detector > &)
~CaloTrkProcessing() override
std::vector< std::string > caloNames_
std::vector< Detector > detectors_