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();
178 TrackInformation* trkInfo = dynamic_cast<TrackInformation*>(theTrack->GetUserInformation());
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";
189 if (prestepLV < 0 && poststepLV >= 0
194 edm::LogVerbatim(
"DoFineCalo") <<
"Entered fine volume " << poststepLV <<
":"
195 <<
" Track " <<
id <<
" pdgid=" << theTrack->GetDefinition()->GetPDGEncoding()
196 <<
" prestepLV=" << prestepLV <<
" poststepLV=" << poststepLV
197 <<
" GetKineticEnergy[GeV]=" << theTrack->GetKineticEnergy() /
CLHEP::GeV
198 <<
" GetVertexKineticEnergy[GeV]="
199 << theTrack->GetVertexKineticEnergy() /
CLHEP::GeV <<
" prestepPosition[cm]=("
200 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().x() / CLHEP::cm <<
","
201 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().y() / CLHEP::cm <<
","
202 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().z() / CLHEP::cm <<
")"
203 <<
" poststepPosition[cm]=("
204 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().x() / CLHEP::cm <<
","
205 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().y() / CLHEP::cm <<
","
206 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().z() / CLHEP::cm <<
")"
207 <<
" position[cm]=(" << theTrack->GetPosition().x() / CLHEP::cm <<
","
208 << theTrack->GetPosition().y() / CLHEP::cm <<
","
209 << theTrack->GetPosition().z() / CLHEP::cm <<
")"
210 <<
" vertex_position[cm]=(" << theTrack->GetVertexPosition().x() / CLHEP::cm <<
","
211 << theTrack->GetVertexPosition().y() / CLHEP::cm <<
","
212 << theTrack->GetVertexPosition().z() / CLHEP::cm <<
")";
217 else if (prestepLV >= 0 && poststepLV < 0) {
220 <<
" GetKineticEnergy[GeV]=" << theTrack->GetKineticEnergy() /
CLHEP::GeV
221 <<
" GetVertexKineticEnergy[GeV]="
222 << theTrack->GetVertexKineticEnergy() /
CLHEP::GeV <<
" prestepPosition[cm]=("
223 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().x() / CLHEP::cm <<
","
224 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().y() / CLHEP::cm <<
","
225 << theTrack->GetStep()->GetPreStepPoint()->GetPosition().z() / CLHEP::cm <<
")"
226 <<
" poststepPosition[cm]=("
227 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().x() / CLHEP::cm <<
","
228 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().y() / CLHEP::cm <<
","
229 << theTrack->GetStep()->GetPostStepPoint()->GetPosition().z() / CLHEP::cm <<
")";
237 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing set IDonCaloSurface to " <<
id <<
" at step Number "
238 << theTrack->GetCurrentStepNumber();
240 trkInfo->
setIDonCaloSurface(
id, 0, 0, theTrack->GetDefinition()->GetPDGEncoding(), theTrack->GetMomentum().mag());
251 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing Entered for " <<
id <<
" at stepNumber "
252 << theTrack->GetCurrentStepNumber() <<
" IDonCaloSur.. "
257 G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
258 const G4VTouchable* post_touch = postStepPoint->GetTouchable();
267 G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
268 const G4VTouchable* post_touch = postStepPoint->GetTouchable();
271 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
272 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
274 if (inside >= 0 || (theTrack->GetCurrentStepNumber() == 1)) {
276 id, ical, inside, theTrack->GetDefinition()->GetPDGEncoding(), theTrack->GetMomentum().mag());
283 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing: set ID on Calo " << ical <<
" surface (Inside " << inside
284 <<
") to " <<
id <<
" of a Track with Kinetic Energy "
285 << theTrack->GetKineticEnergy() /
CLHEP::MeV <<
" MeV";
295 G4LogicalVolume* lv =
nullptr;
296 for (
unsigned int it = 0; it <
detectors.size(); it++) {
299 lv =
detLV(touch, lastLevel);
303 name1 = lv->GetName();
304 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing: volume " << name1 <<
" at Level " << lastLevel;
324 G4LogicalVolume* lv =
nullptr;
333 for (
int it1 =
id1; it1 <
id2; it1++) {
335 for (
unsigned int it2 = 0; it2 <
detectors_[it1].fromDets.size(); it2++) {
336 if (lastLevel !=
detectors_[it1].fromLevels[it2]) {
338 lv =
detLV(touch, lastLevel);
342 name1 = lv->GetName();
343 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing: volume " << name1 <<
" at Level " << lastLevel;
360 lv =
detLV(touch, lastLevel);
364 name1 = lv->GetName();
365 edm::LogVerbatim(
"CaloSim") <<
"CaloTrkProcessing: volume " << name1 <<
" at Level " << lastLevel;
386 return ((touch->GetHistoryDepth()) + 1);
392 G4LogicalVolume* lv =
nullptr;
394 int level = ((touch->GetHistoryDepth()) + 1);
397 lv = touch->GetVolume(
ii)->GetLogicalVolume();
410 G4VPhysicalVolume*
pv = touch->GetVolume(
i);
415 copyno[
ii] = touch->GetReplicaNumber(
i);