14 #include "G4EventManager.hh"
15 #include "G4LogicalVolumeStore.hh"
16 #include "G4LogicalVolume.hh"
19 #include "G4SystemOfUnits.hh"
20 #include "DD4hep/Filter.h"
32 bool dd4hep =
p.getParameter<
bool>(
"g4GeometryDD4hepSource");
33 int addlevel =
dd4hep ? 1 : 0;
40 std::vector<std::string> fineNames = m_p.
getParameter<std::vector<std::string> >(
"FineCaloNames");
41 std::vector<int> fineLevels = m_p.
getParameter<std::vector<int> >(
"FineCaloLevels");
42 std::vector<int> useFines = m_p.
getParameter<std::vector<int> >(
"UseFineCalo");
43 for (
auto&
level : fineLevels)
48 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing: Have a possibility of " << fineNames.size()
49 <<
" fine calorimeters of which " << useFines.size() <<
" are selected";
50 for (
unsigned int k = 0;
k < fineNames.size(); ++
k)
52 std::ostringstream st1;
53 for (
unsigned int k = 0;
k < useFines.size(); ++
k)
54 st1 <<
" [" <<
k <<
"] " << useFines[
k] <<
":" << fineNames[useFines[
k]];
55 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing used calorimeters" << st1.str();
67 for (
unsigned int i = 0;
i < csp->
levels_.size();
i++)
82 <<
" does not match with " << csp->
neighbours_.size() <<
" ==> illegal ";
84 <<
"Calorimeter array size does not match with size of neighbours\n";
87 const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
88 std::vector<G4LogicalVolume*>::const_iterator lvcite;
91 G4LogicalVolume* lv =
nullptr;
93 for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
94 G4String namx(static_cast<std::string>(dd4hep::dd::noNamespace((*lvcite)->GetName())));
107 <<
" too few compaerd to " << istart + csp->
neighbours_[
i]
108 <<
" requested ==> illegal ";
110 <<
"InsideNames array size does not match with list of neighbours\n";
112 std::vector<std::string> inside;
113 std::vector<G4LogicalVolume*> insideLV;
114 std::vector<int> insideLevels;
118 for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
119 G4String namx(static_cast<std::string>(dd4hep::dd::noNamespace((*lvcite)->GetName())));
125 inside.push_back(
name);
126 insideLV.push_back(lv);
127 insideLevels.push_back(csp->
insideLevel_[istart +
k] + addlevel);
137 for (
unsigned int i = 0;
i < useFines.size();
i++) {
138 G4LogicalVolume* lv =
nullptr;
139 G4String
name = static_cast<G4String>(fineNames[useFines[
i]]);
140 for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
141 G4String namx(static_cast<std::string>(dd4hep::dd::noNamespace((*lvcite)->GetName())));
151 detector.level = fineLevels[useFines[
i]];
159 edm::LogError(
"CaloSim") <<
"CaloTrkProcessing: Cannot find CaloSimulationParameters";
160 throw cms::Exception(
"Unknown",
"CaloTrkProcessing") <<
"Cannot find CaloSimulationParameters\n";
187 G4Track* theTrack = aStep->GetTrack();
188 int id = theTrack->GetTrackID();
190 TrackInformation* trkInfo = dynamic_cast<TrackInformation*>(theTrack->GetUserInformation());
192 if (trkInfo ==
nullptr) {
193 edm::LogError(
"CaloSim") <<
"CaloTrkProcessing: No trk info !!!! abort ";
194 throw cms::Exception(
"Unknown",
"CaloTrkProcessing") <<
"cannot get trkInfo for Track " <<
id <<
"\n";
201 if (prestepLV < 0 && poststepLV >= 0
206 edm::LogVerbatim(
"DoFineCalo") <<
"Entered fine volume " << poststepLV <<
":"
207 <<
" Track " <<
id <<
" pdgid=" << theTrack->GetDefinition()->GetPDGEncoding()
208 <<
" prestepLV=" << prestepLV <<
" poststepLV=" << poststepLV
209 <<
" GetKineticEnergy[GeV]=" << theTrack->GetKineticEnergy() /
CLHEP::GeV
210 <<
" GetVertexKineticEnergy[GeV]="
211 << theTrack->GetVertexKineticEnergy() /
CLHEP::GeV <<
" prestepPosition[cm]=("
212 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().x() / CLHEP::cm <<
","
213 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().y() / CLHEP::cm <<
","
214 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().z() / CLHEP::cm <<
")"
215 <<
" poststepPosition[cm]=("
216 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().x() / CLHEP::cm <<
","
217 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().y() / CLHEP::cm <<
","
218 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().z() / CLHEP::cm <<
")"
219 <<
" position[cm]=(" << theTrack->GetPosition().x() / CLHEP::cm <<
","
220 << theTrack->GetPosition().y() / CLHEP::cm <<
","
221 << theTrack->GetPosition().z() / CLHEP::cm <<
")"
222 <<
" vertex_position[cm]=(" << theTrack->GetVertexPosition().x() / CLHEP::cm <<
","
223 << theTrack->GetVertexPosition().y() / CLHEP::cm <<
","
224 << theTrack->GetVertexPosition().z() / CLHEP::cm <<
")";
229 else if (prestepLV >= 0 && poststepLV < 0) {
232 <<
" GetKineticEnergy[GeV]=" << theTrack->GetKineticEnergy() /
CLHEP::GeV
233 <<
" GetVertexKineticEnergy[GeV]="
234 << theTrack->GetVertexKineticEnergy() /
CLHEP::GeV <<
" prestepPosition[cm]=("
235 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().x() / CLHEP::cm <<
","
236 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().y() / CLHEP::cm <<
","
237 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().z() / CLHEP::cm <<
")"
238 <<
" poststepPosition[cm]=("
239 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().x() / CLHEP::cm <<
","
240 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().y() / CLHEP::cm <<
","
241 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().z() / CLHEP::cm <<
")";
249 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing set IDonCaloSurface to " <<
id <<
" at step Number "
250 << theTrack->GetCurrentStepNumber();
252 trkInfo->
setIDonCaloSurface(
id, 0, 0, theTrack->GetDefinition()->GetPDGEncoding(), theTrack->GetMomentum().mag());
263 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing Entered for " <<
id <<
" at stepNumber "
264 << theTrack->GetCurrentStepNumber() <<
" IDonCaloSur.. "
269 G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
270 const G4VTouchable* post_touch = postStepPoint->GetTouchable();
279 G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
280 const G4VTouchable* post_touch = postStepPoint->GetTouchable();
283 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
284 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
286 if (inside >= 0 || (theTrack->GetCurrentStepNumber() == 1)) {
288 id, ical, inside, theTrack->GetDefinition()->GetPDGEncoding(), theTrack->GetMomentum().mag());
295 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing: set ID on Calo " << ical <<
" surface (Inside " << inside
296 <<
") to " <<
id <<
" of a Track with Kinetic Energy "
297 << theTrack->GetKineticEnergy() /
CLHEP::MeV <<
" MeV";
307 G4LogicalVolume* lv =
nullptr;
308 for (
unsigned int it = 0; it <
detectors.size(); it++) {
311 lv =
detLV(touch, lastLevel);
315 name1 = lv->GetName();
316 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing: volume " << name1 <<
" at Level " << lastLevel;
336 G4LogicalVolume* lv =
nullptr;
345 for (
int it1 =
id1; it1 <
id2; it1++) {
347 for (
unsigned int it2 = 0; it2 <
detectors_[it1].fromDets.size(); it2++) {
348 if (lastLevel !=
detectors_[it1].fromLevels[it2]) {
350 lv =
detLV(touch, lastLevel);
354 name1 = lv->GetName();
355 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing: volume " << name1 <<
" at Level " << lastLevel;
372 lv =
detLV(touch, lastLevel);
376 name1 = lv->GetName();
377 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing: volume " << name1 <<
" at Level " << lastLevel;
398 return ((touch->GetHistoryDepth()) + 1);
404 G4LogicalVolume* lv =
nullptr;
406 int level = ((touch->GetHistoryDepth()) + 1);
409 lv = touch->GetVolume(
ii)->GetLogicalVolume();
422 G4VPhysicalVolume*
pv = touch->GetVolume(
i);
427 copyno[
ii] = touch->GetReplicaNumber(
i);