15 #include "G4EventManager.hh" 17 #include "G4LogicalVolumeStore.hh" 18 #include "G4LogicalVolume.hh" 22 #include "G4SystemOfUnits.hh" 32 m_trackManager(manager) {
40 edm::LogInfo(
"CaloSim") <<
"CaloTrkProcessing: Initailised with TestBeam = " 41 << testBeam <<
" Emin = " << eMin <<
" MeV and" 45 G4String attribute =
"ReadOutName";
51 G4String
value =
"Calorimeter";
52 std::vector<std::string> caloNames =
getNames (value, sv);
54 LogDebug(
"CaloSim") <<
"CaloTrkProcessing: Names for " << value <<
":";
55 for (
unsigned int i=0;
i<caloNames.size();
i++)
56 LogDebug(
"CaloSim") <<
" (" <<
i <<
") " << caloNames[
i];
62 LogDebug(
"CaloSim") <<
"CaloTrkProcessing: Names for " << value <<
":";
63 for (
unsigned int i=0;
i<levels.size();
i++)
64 LogDebug(
"CaloSim") <<
" (" <<
i <<
") " << levels[
i];
68 std::vector<double> neighbours =
getNumbers (value, sv);
70 LogDebug(
"CaloSim") <<
"CaloTrkProcessing: Names for " << value <<
":";
71 for (
unsigned int i=0;
i<neighbours.size();
i++)
72 LogDebug(
"CaloSim") <<
" (" <<
i <<
") " << neighbours[
i];
76 std::vector<std::string> insideNames =
getNames (value, sv);
78 LogDebug(
"CaloSim") <<
"CaloTrkProcessing: Names for " << value <<
":";
79 for (
unsigned int i=0;
i<insideNames.size();
i++)
80 LogDebug(
"CaloSim") <<
" (" <<
i <<
") " << insideNames[
i];
83 value =
"InsideLevel";
84 std::vector<double> insideLevel =
getNumbers (value, sv);
86 LogDebug(
"CaloSim") <<
"CaloTrkProcessing: Names for " << value <<
":";
87 for (
unsigned int i=0;
i<insideLevel.size();
i++)
88 LogDebug(
"CaloSim") <<
" (" <<
i <<
") " << insideLevel[
i];
91 if (caloNames.size() < neighbours.size()) {
92 edm::LogError(
"CaloSim") <<
"CaloTrkProcessing: # of Calorimeter bins " 93 << caloNames.size() <<
" does not match with " 94 << neighbours.size() <<
" ==> illegal ";
96 <<
"Calorimeter array size does not match with size of neighbours\n";
99 const G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
100 std::vector<G4LogicalVolume *>::const_iterator lvcite;
102 for (
unsigned int i=0;
i<caloNames.size();
i++) {
103 G4LogicalVolume* lv =
nullptr;
104 G4String name = caloNames[
i];
105 int number =
static_cast<int>(neighbours[
i]);
106 for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
107 if ((*lvcite)->GetName() ==
name) {
116 detector.
level =
static_cast<int>(levels[
i]);
117 if (istart+number > (
int)(insideNames.size())) {
118 edm::LogError(
"CaloSim") <<
"CaloTrkProcessing: # of InsideNames bins " 119 << insideNames.size() <<
" too few compaerd to " 120 << istart+number <<
" requested ==> illegal ";
122 <<
"InsideNames array size does not match with list of neighbours\n";
124 std::vector<std::string> inside;
125 std::vector<G4LogicalVolume*> insideLV;
126 std::vector<int> insideLevels;
127 for (
int k = 0;
k < number;
k++) {
129 name = insideNames[istart+
k];
130 for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++)
131 if ((*lvcite)->GetName() ==
name) {
135 inside.push_back(name);
136 insideLV.push_back(lv);
137 insideLevels.push_back(static_cast<int>(insideLevel[istart+
k]));
148 <<
" calorimetric volumes";
150 edm::LogInfo(
"CaloSim") <<
"CaloTrkProcessing: Calorimeter volume " <<
i 154 <<
detectors[
i].fromDets.size() <<
" neighbours";
164 edm::LogInfo(
"CaloSim") <<
"CaloTrkProcessing: Deleted";
175 G4Track* theTrack = aStep->GetTrack();
176 int id = theTrack->GetTrackID();
179 (theTrack->GetUserInformation());
181 if (trkInfo ==
nullptr) {
182 edm::LogError(
"CaloSim") <<
"CaloTrkProcessing: No trk info !!!! abort ";
184 <<
"cannot get trkInfo for Track " <<
id <<
"\n";
190 LogDebug(
"CaloSim") <<
"CaloTrkProcessing set IDonCaloSurface to " <<
id 191 <<
" at step Number " 192 << theTrack->GetCurrentStepNumber();
195 theTrack->GetDefinition()->GetPDGEncoding(),
196 theTrack->GetMomentum().mag());
198 if (theTrack->GetKineticEnergy()/
MeV >
eMin)
207 LogDebug(
"CaloSim") <<
"CaloTrkProcessing Entered for " <<
id 208 <<
" at stepNumber "<< theTrack->GetCurrentStepNumber()
214 G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
215 const G4VTouchable* post_touch = postStepPoint->GetTouchable();
225 G4StepPoint* postStepPoint = aStep->GetPostStepPoint();
226 const G4VTouchable* post_touch = postStepPoint->GetTouchable();
229 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
230 const G4VTouchable* pre_touch = preStepPoint->GetTouchable();
232 if (inside >= 0 || (theTrack->GetCurrentStepNumber()==1)) {
234 theTrack->GetDefinition()->GetPDGEncoding(),
235 theTrack->GetMomentum().mag());
240 LogDebug(
"CaloSim") <<
"CaloTrkProcessing: set ID on Calo " << ical
241 <<
" surface (Inside " << inside <<
") to " 242 <<
id <<
" of a Track with Kinetic Energy " 243 << theTrack->GetKineticEnergy()/
MeV <<
" MeV";
255 LogDebug(
"CaloSim") <<
"CaloTrkProcessing::getNames called for " <<
str;
262 const std::vector<std::string> & fvec = value.
strings();
263 int nval = fvec.size();
266 edm::LogError(
"CaloSim") <<
"CaloTrkProcessing: # of " << str
267 <<
" bins " << nval <<
" < 1 ==> illegal ";
269 <<
"nval < 2 for array " << str <<
"\n";
276 <<
"cannot get array " << str <<
"\n";
284 LogDebug(
"CaloSim") <<
"CaloTrkProcessing::getNumbers called for " <<
str;
291 const std::vector<double> & fvec = value.
doubles();
292 int nval = fvec.size();
294 edm::LogError(
"CaloSim") <<
"CaloTrkProcessing: # of " << str
295 <<
" bins " << nval <<
" < 1 ==> illegal ";
297 <<
"nval < 2 for array " << str <<
"\n";
304 <<
"cannot get array " << str <<
"\n";
311 G4LogicalVolume* lv=
nullptr;
312 for (
unsigned int it=0; it <
detectors.size(); it++) {
315 lv =
detLV(touch, lastLevel);
318 if (lv != 0) name1 = lv->GetName();
319 LogDebug(
"CaloSim") <<
"CaloTrkProcessing: volume " << name1
320 <<
" at Level " << lastLevel;
323 G4String name2[20];
int copyno2[20];
325 for (
int i2=0; i2<
levels; i2++)
326 LogDebug(
"CaloSim") <<
" " << i2 <<
" " << name2[i2] <<
" " 340 G4LogicalVolume* lv=
nullptr;
342 if (idcal < 0) {id1 = 0; id2 =
static_cast<int>(
detectors.size());}
343 else {id1 = idcal; id2 = id1+1;}
344 for (
int it1 = id1; it1 <
id2; it1++) {
346 for (
unsigned int it2 = 0; it2 <
detectors[it1].fromDets.size(); it2++) {
347 if (lastLevel !=
detectors[it1].fromLevels[it2]) {
348 lastLevel =
detectors[it1].fromLevels[it2];
349 lv =
detLV(touch,lastLevel);
352 if (lv != 0) name1 = lv->GetName();
353 LogDebug(
"CaloSim") <<
"CaloTrkProcessing: volume " << name1
354 <<
" at Level " << lastLevel;
357 G4String name2[20];
int copyno2[20];
359 for (
int i2=0; i2<
levels; i2++)
360 LogDebug(
"CaloSim") <<
" " << i2 <<
" " << name2[i2] <<
" " 369 lastLevel =
detectors[it1].fromLevels[idin];
370 lv =
detLV(touch,lastLevel);
373 if (lv != 0) name1 = lv->GetName();
374 LogDebug(
"CaloSim") <<
"CaloTrkProcessing: volume " << name1
375 <<
" at Level " << lastLevel;
378 G4String name2[20];
int copyno2[20];
380 for (
int i2=0; i2<
levels; i2++)
381 LogDebug(
"CaloSim") <<
" " << i2 <<
" " << name2[i2] <<
" " 396 return ((touch->GetHistoryDepth())+1);
402 int currentlevel)
const {
404 G4LogicalVolume* lv=
nullptr;
406 int level = ((touch->GetHistoryDepth())+1);
407 if (level > 0 && level >= currentlevel) {
408 int ii = level - currentlevel;
409 lv = touch->GetVolume(ii)->GetLogicalVolume();
417 int* copyno, G4String*
name)
const {
423 int i = level -
ii - 1;
424 G4VPhysicalVolume*
pv = touch->GetVolume(i);
426 name[
ii] = pv->GetName();
429 copyno[
ii] = touch->GetReplicaNumber(i);
void update(const BeginOfEvent *evt) override
This routine will be called when the appropriate signal arrives.
T getParameter(std::string const &) const
G4LogicalVolume * detLV(const G4VTouchable *, int) const
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
CaloTrkProcessing(const std::string &aSDname, const DDCompactView &cpv, const SensitiveDetectorCatalog &clg, edm::ParameterSet const &p, const SimTrackManager *)
int detLevels(const G4VTouchable *) const
int isItCalo(const G4VTouchable *)
type of data representation of DDCompactView
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
void detectorLevel(const G4VTouchable *, int &, int *, G4String *) const
int isItInside(const G4VTouchable *, int, int)
const std::vector< std::string > & getNames() const
std::vector< int > fromLevels
std::vector< Detector > detectors
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
std::maps an index to a DDValue. The index corresponds to the index assigned to the name of the std::...
std::vector< double > getNumbers(G4String, const DDsvalues_type &)
std::vector< G4LogicalVolume * > fromDetL
std::vector< std::string > fromDets
const std::vector< std::string > & strings() const
a reference to the std::string-valued values stored in the given instance of DDValue ...
~CaloTrkProcessing() override
DDsvalues_type mergedSpecifics() const
bool firstChild()
set the current node to the first child ...