13 #include "DD4hep/Filter.h"
18 using namespace geant_units::operators;
37 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetHcalHistos: FillHisto : " << fillHistos_ <<
" PrintSummary "
38 << printSum_ <<
" == Eta plot: NX " << binEta_ <<
" Range " << -maxEta_ <<
":"
39 << maxEta_ <<
" Phi plot: NX " << binPhi_ <<
" Range " << -1._pi <<
":" << 1._pi
40 <<
" (Eta limit " << etaLow_ <<
":" << etaHigh_ <<
")"
41 <<
" Eta range (" << etaLowMin_ <<
":" << etaLowMax_ <<
"), (" << etaMidMin_ <<
":"
42 << etaMidMax_ <<
"), (" << etaHighMin_ <<
":" << etaHighMax_
43 <<
") Debug for eta range " << etaMinP_ <<
":" << etaMaxP_ <<
" FromDD4hep "
50 constexpr int32_t addLevel = 0;
57 for (
auto&
name : names) {
59 if (
std::find(sensitives_.begin(), sensitives_.end(), namx) == sensitives_.end())
60 sensitives_.emplace_back(namx);
62 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos: Names to be tested for " << attribute <<
" = "
63 << value <<
" has " << sensitives_.size() <<
" elements";
64 for (
unsigned int i = 0;
i < sensitives_.size();
i++)
66 <<
"MaterialBudgetHcalHistos: sensitives[" <<
i <<
"] = " << sensitives_[
i];
74 std::vector<double>
temp = getDDDArray(
"Levels", sv);
75 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos: Names to be tested for " << attribute <<
" = "
76 << value <<
" has " << hfNames_.size() <<
" elements";
77 for (
unsigned int i = 0;
i < hfNames_.size();
i++) {
78 int level =
static_cast<int>(temp[
i]);
79 hfLevels_.push_back(level + addLevel);
81 <<
"MaterialBudgetHcalHistos: HF[" <<
i <<
"] = " << hfNames_[
i] <<
" at level " << hfLevels_[
i];
84 const std::string ecalRO[2] = {
"EcalHitsEB",
"EcalHitsEE"};
85 attribute =
"ReadOutName";
86 for (
int k = 0;
k < 2;
k++) {
90 std::vector<std::string> senstmp =
getNames(fv3);
91 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos: Names to be tested for " << attribute
92 <<
" = " << value <<
" has " << senstmp.size() <<
" elements";
93 for (
unsigned int i = 0;
i < senstmp.size();
i++) {
95 if (
std::find(sensitiveEC_.begin(), sensitiveEC_.end(),
name) == sensitiveEC_.end())
96 sensitiveEC_.push_back(name);
99 for (
unsigned int i = 0;
i < sensitiveEC_.size();
i++)
101 <<
"MaterialBudgetHcalHistos:sensitiveEC[" <<
i <<
"] = " << sensitiveEC_[
i];
106 constexpr int32_t addLevel = 1;
113 for (
auto&
name : names) {
115 if (
std::find(sensitives_.begin(), sensitives_.end(), namx) == sensitives_.end())
116 sensitives_.emplace_back(namx);
118 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos: Names to be tested for " << attribute <<
" = "
119 << value <<
" has " << sensitives_.size() <<
" elements";
120 for (
unsigned int i = 0;
i < sensitives_.size();
i++)
122 <<
"MaterialBudgetHcalHistos: sensitives[" <<
i <<
"] = " << sensitives_[
i];
123 attribute =
"Volume";
127 std::vector<int>
temp = fv2.
get<std::vector<int> >(
"hf",
"Levels");
129 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos: Names to be tested for " << attribute <<
" = "
130 << value <<
" has " << hfNames_.size() <<
" elements";
131 for (
unsigned int i = 0;
i < hfNames_.size();
i++) {
132 hfLevels_.push_back(temp[
i] + addLevel);
134 <<
"MaterialBudgetHcalHistos: HF[" <<
i <<
"] = " << hfNames_[
i] <<
" at level " << hfLevels_[
i];
137 const std::string ecalRO[2] = {
"EcalHitsEB",
"EcalHitsEE"};
138 attribute =
"ReadOutName";
139 for (
int k = 0;
k < 2;
k++) {
143 std::vector<std::string> senstmp =
getNames(fv);
144 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos: Names to be tested for " << attribute
145 <<
" = " << value <<
" has " << senstmp.size() <<
" elements";
146 for (
unsigned int i = 0;
i < senstmp.size();
i++) {
148 if (
std::find(sensitiveEC_.begin(), sensitiveEC_.end(),
name) == sensitiveEC_.end())
149 sensitiveEC_.push_back(name);
152 for (
unsigned int i = 0;
i < sensitiveEC_.size();
i++)
154 <<
"MaterialBudgetHcalHistos:sensitiveEC[" <<
i <<
"] = " << sensitiveEC_[
i];
159 id_ =
layer_ = steps_ = 0;
160 radLen_ = intLen_ = stepLen_ = 0;
161 nlayHB_ = nlayHE_ = nlayHF_ = nlayHO_ = 0;
163 const G4ThreeVector&
dir = aTrack->GetMomentum();
164 if (dir.theta() != 0) {
170 double theEnergy = aTrack->GetTotalEnergy();
171 int theID = (int)(aTrack->GetDefinition()->GetPDGEncoding());
181 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetHcalHistos: Track " << aTrack->GetTrackID() <<
" Code "
182 << theID <<
" Energy " <<
convertUnitsTo(1._GeV, theEnergy) <<
" GeV; Eta "
188 G4Material* material = aStep->GetPreStepPoint()->GetMaterial();
189 double step = aStep->GetStepLength();
190 double radl = material->GetRadlen();
191 double intl = material->GetNuclearInterLength();
192 double density =
convertUnitsTo(1._g_per_cm3, material->GetDensity());
195 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
200 for (
unsigned int ii = 0;
ii < matList_.size();
ii++) {
201 if (matList_[
ii] == matName) {
203 radLength_[
ii] += (step / radl);
204 intLength_[
ii] += (step / intl);
210 matList_.push_back(matName);
211 stepLength_.push_back(step);
212 radLength_.push_back(step / radl);
213 intLength_.push_back(step / intl);
216 edm::LogVerbatim(
"MaterialBudget") <<
"Volume " << name <<
" id " << id_ <<
":" << idOld <<
" Step " << step
217 <<
" Material " << matName <<
" Old Length " << stepLen_ <<
" X0 "
218 << step / radl <<
":" << radLen_ <<
" Lambda " << step / intl <<
":"
222 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetHcalHistos: Step at " << name <<
" id " << id_ <<
":"
223 << idOld <<
" Length " << step <<
" in " << matName <<
" of density "
224 << density <<
" g/cc; Radiation Length " << radl <<
" mm; Interaction Length "
225 << intl <<
" mm\n Position "
226 << aStep->GetPreStepPoint()->GetPosition() <<
" Cylindrical R "
227 << aStep->GetPreStepPoint()->GetPosition().perp() <<
" Length (so far) "
228 << stepLen_ <<
" L/X0 " << step / radl <<
"/" << radLen_ <<
" L/Lambda "
229 << step / intl <<
"/" << intLen_;
232 int det = 0, lay = 0;
236 <<
"Volume " << name <<
":" << matName <<
" EC:Sensitive:HF " << isItEC(name) <<
":" << isSensitive(name) <<
":"
237 << isItHF(touch) <<
" Eta " << abseta <<
" HC " << ((touch->GetReplicaNumber(1)) / 1000) <<
":"
238 << ((touch->GetReplicaNumber(0) / 10) % 100 + 3) <<
" X0 " << (radLen_ + (step / radl)) <<
" Lambda "
239 << (intLen_ + (step / intl));
245 if (isSensitive(name)) {
252 det = (touch->GetReplicaNumber(1)) / 1000;
253 lay = (touch->GetReplicaNumber(0) / 10) % 100 + 3;
267 }
else if (lay !=
layer_) {
274 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos: Det " << det <<
" Layer " << lay <<
" Eta "
289 if ((abseta >= etaMinP_) && (abseta <= etaMaxP_))
291 <<
"MaterialBudgetHcalHistos: Step at " << name <<
" calls filHisto with " << (id_ - 1);
297 radLen_ += (step / radl);
298 intLen_ += (step / intl);
301 if (!isItHF(aStep->GetPostStepPoint()->GetTouchable())) {
302 if ((abseta >= etaMinP_) && (abseta <= etaMaxP_))
303 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetHcalHistos: After HF in " << name <<
":"
304 <<
static_cast<std::string>(dd4hep::dd::noNamespace(
305 aStep->GetPostStepPoint()->GetTouchable()->GetVolume(0)->GetName()))
306 <<
" calls fillHisto with " << id_;
317 edm::LogVerbatim(
"MaterialBudget") <<
"Number of layers hit in HB:" << nlayHB_ <<
" HE:" << nlayHE_
318 <<
" HO:" << nlayHO_ <<
" HF:" << nlayHF_;
320 fillHisto(maxSet_ - 1);
324 for (
unsigned int ii = 0;
ii < matList_.size();
ii++) {
325 edm::LogVerbatim(
"MaterialBudget") << matList_[
ii] <<
"\t" << stepLength_[
ii] <<
"\t" << radLength_[
ii] <<
"\t"
337 <<
"please add it to config file";
340 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos: Booking user histos === with " << binEta_
341 <<
" bins in eta from " << -maxEta_ <<
" to " << maxEta_ <<
" and " << binPhi_
342 <<
" bins in phi from " << -maxPhi <<
" to " <<
maxPhi;
345 std::string range0 =
"(" + std::to_string(etaMidMin_) +
":" + std::to_string(etaMidMax_) +
") ";
346 std::string range1 =
"(" + std::to_string(etaHighMin_) +
":" + std::to_string(etaHighMax_) +
") ";
347 std::string range2 =
"(" + std::to_string(etaLowMin_) +
":" + std::to_string(etaLowMax_) +
") ";
349 for (
int i = 0;
i < maxSet_;
i++) {
350 iter = std::to_string(
i);
351 me100[
i] = tfile->
make<TProfile>(
352 std::to_string(
i + 100).c_str(), (
"MB(X0) prof Eta in region " + iter).c_str(), binEta_, -maxEta_, maxEta_);
353 me200[
i] = tfile->
make<TProfile>(
354 std::to_string(
i + 200).c_str(), (
"MB(L0) prof Eta in region " + iter).c_str(), binEta_, -maxEta_, maxEta_);
355 me300[
i] = tfile->
make<TProfile>(
356 std::to_string(
i + 300).c_str(), (
"MB(Step) prof Eta in region " + iter).c_str(), binEta_, -maxEta_, maxEta_);
357 me400[
i] = tfile->
make<TH1F>(
358 std::to_string(
i + 400).c_str(), (
"Eta in region " + iter).c_str(), binEta_, -maxEta_, maxEta_);
359 me500[
i] = tfile->
make<TProfile>(
360 std::to_string(
i + 500).c_str(), (
"MB(X0) prof Ph in region " + iter).c_str(), binPhi_, -
maxPhi,
maxPhi);
361 me600[
i] = tfile->
make<TProfile>(
362 std::to_string(
i + 600).c_str(), (
"MB(L0) prof Ph in region " + iter).c_str(), binPhi_, -
maxPhi,
maxPhi);
363 me700[
i] = tfile->
make<TProfile>(
364 std::to_string(
i + 700).c_str(), (
"MB(Step) prof Ph in region " + iter).c_str(), binPhi_, -
maxPhi,
maxPhi);
366 tfile->
make<TH1F>(std::to_string(
i + 800).c_str(), (
"Phi in region " + iter).c_str(), binPhi_, -
maxPhi,
maxPhi);
367 me900[
i] = tfile->
make<TProfile2D>(std::to_string(
i + 900).c_str(),
368 (
"MB(X0) prof Eta Phi in region " + iter).c_str(),
375 me1000[
i] = tfile->
make<TProfile2D>(std::to_string(
i + 1000).c_str(),
376 (
"MB(L0) prof Eta Phi in region " + iter).c_str(),
383 me1100[
i] = tfile->
make<TProfile2D>(std::to_string(
i + 1100).c_str(),
384 (
"MB(Step) prof Eta Phi in region " + iter).c_str(),
391 me1200[
i] = tfile->
make<TH2F>(std::to_string(
i + 1200).c_str(),
392 (
"Eta vs Phi in region " + iter).c_str(),
399 me1600[
i] = tfile->
make<TProfile>(std::to_string(
i + 1600).c_str(),
400 (
"MB(X0) prof Ph in region " + range0 + iter).c_str(),
404 me1700[
i] = tfile->
make<TProfile>(std::to_string(
i + 1700).c_str(),
405 (
"MB(L0) prof Ph in region " + range0 + iter).c_str(),
409 me1800[
i] = tfile->
make<TProfile>(std::to_string(
i + 1800).c_str(),
410 (
"MB(Step) prof Ph in region " + range0 + iter).c_str(),
414 me1900[
i] = tfile->
make<TProfile>(std::to_string(
i + 1900).c_str(),
415 (
"MB(X0) prof Ph in region " + range1 + iter).c_str(),
419 me2000[
i] = tfile->
make<TProfile>(std::to_string(
i + 2000).c_str(),
420 (
"MB(L0) prof Ph in region " + range1 + iter).c_str(),
424 me2100[
i] = tfile->
make<TProfile>(std::to_string(
i + 2100).c_str(),
425 (
"MB(Step) prof Ph in region " + range1 + iter).c_str(),
429 me2200[
i] = tfile->
make<TProfile>(std::to_string(
i + 2200).c_str(),
430 (
"MB(X0) prof Ph in region " + range2 + iter).c_str(),
434 me2300[
i] = tfile->
make<TProfile>(std::to_string(
i + 2300).c_str(),
435 (
"MB(L0) prof Ph in region " + range2 + iter).c_str(),
439 me2400[
i] = tfile->
make<TProfile>(std::to_string(
i + 2400).c_str(),
440 (
"MB(Step) prof Ph in region " + range2 + iter).c_str(),
445 for (
int i = 0;
i < maxSet2_;
i++) {
446 iter = std::to_string(
i);
447 me1300[
i] = tfile->
make<TH1F>(std::to_string(
i + 1300).c_str(),
448 (
"Events with layers Hit (0 all, 1 HB, ..) for " + iter).c_str(),
452 me1400[
i] = tfile->
make<TH2F>(std::to_string(
i + 1400).c_str(),
453 (
"Eta vs Phi for layers hit in " + iter).c_str(),
460 me1500[
i] = tfile->
make<TProfile>(std::to_string(
i + 1500).c_str(),
461 (
"Number of layers crossed (0 all, 1 HB, ..) for " + iter).c_str(),
467 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetHcalHistos: Booking user histos done ===";
472 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetHcalHistos:FillHisto called with index " << ii
473 <<
" integrated step " << stepLen_ <<
" X0 " << radLen_ <<
" Lamda " << intLen_;
475 if (ii >= 0 && ii < maxSet_) {
476 me100[
ii]->Fill(eta_, radLen_);
477 me200[
ii]->Fill(eta_, intLen_);
478 me300[
ii]->Fill(eta_, stepLen_);
479 me400[
ii]->Fill(eta_);
481 if (eta_ >= etaLow_ && eta_ <= etaHigh_) {
482 me500[
ii]->Fill(phi_, radLen_);
483 me600[
ii]->Fill(phi_, intLen_);
484 me700[
ii]->Fill(phi_, stepLen_);
485 me800[
ii]->Fill(phi_);
488 me900[
ii]->Fill(eta_, phi_, radLen_);
489 me1000[
ii]->Fill(eta_, phi_, intLen_);
490 me1100[
ii]->Fill(eta_, phi_, stepLen_);
491 me1200[
ii]->Fill(eta_, phi_);
494 me1600[
ii]->Fill(phi_, radLen_);
495 me1700[
ii]->Fill(phi_, intLen_);
496 me1800[
ii]->Fill(phi_, stepLen_);
500 me1900[
ii]->Fill(phi_, radLen_);
501 me2000[
ii]->Fill(phi_, intLen_);
502 me2100[
ii]->Fill(phi_, stepLen_);
506 me2200[
ii]->Fill(phi_, radLen_);
507 me2300[
ii]->Fill(phi_, intLen_);
508 me2400[
ii]->Fill(phi_, stepLen_);
514 me1300[0]->Fill(eta_);
515 me1400[0]->Fill(eta_, phi_);
517 me1300[1]->Fill(eta_);
518 me1400[1]->Fill(eta_, phi_);
521 me1300[2]->Fill(eta_);
522 me1400[2]->Fill(eta_, phi_);
525 me1300[3]->Fill(eta_);
526 me1400[3]->Fill(eta_, phi_);
529 me1300[4]->Fill(eta_);
530 me1400[4]->Fill(eta_, phi_);
533 me1300[5]->Fill(eta_);
534 me1400[5]->Fill(eta_, phi_);
537 me1300[6]->Fill(eta_);
538 me1400[6]->Fill(eta_, phi_);
541 me1300[7]->Fill(eta_);
542 me1400[7]->Fill(eta_, phi_);
544 if (nlayHB_ > 0 || nlayHE_ > 0 || (nlayHF_ > 0 &&
std::abs(eta_) > 3.0)) {
545 me1300[8]->Fill(eta_);
546 me1400[8]->Fill(eta_, phi_);
548 me1500[0]->Fill(eta_, (
double)(nlayHB_ + nlayHO_ + nlayHE_ + nlayHF_));
549 me1500[1]->Fill(eta_, (
double)(nlayHB_));
550 me1500[2]->Fill(eta_, (
double)(nlayHE_));
551 me1500[4]->Fill(eta_, (
double)(nlayHF_));
555 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetHcalHistos: Save user histos ===";
559 std::vector<std::string>
tmp;
564 if (
std::find(tmp.begin(), tmp.end(), namx) == tmp.end())
572 std::vector<std::string>
tmp;
573 const std::vector<std::string> notIn = {
574 "CALO",
"HCal",
"MBBTL",
"MBBTR",
"MBBTC",
"MBAT",
"MBBT_R1M",
"MBBT_R1P",
"MBBT_R1MX",
"MBBT_R1PX",
"VCAL"};
577 if (
std::find(notIn.begin(), notIn.end(),
n) == notIn.end()) {
580 if (
std::find(tmp.begin(), tmp.end(), namx) == tmp.end())
588 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos:getDDDArray called for " <<
str;
592 const std::vector<double>& fvec = value.
doubles();
593 int nval = fvec.size();
595 throw cms::Exception(
"MaterialBudgetHcalHistos") <<
"nval = " << nval <<
" < 1 for array " << str <<
"\n";
600 throw cms::Exception(
"MaterialBudgetHcalHistos") <<
"cannot get array " << str <<
"\n";
605 std::vector<std::string>::const_iterator it = sensitives_.begin();
606 std::vector<std::string>::const_iterator itEnd = sensitives_.end();
607 std::string namx = (name.find(
'_') == std::string::npos) ? name : name.substr(0, name.find(
'_'));
608 for (; it != itEnd; ++it)
615 int levels = ((touch->GetHistoryDepth()) + 1);
616 for (
unsigned int it = 0; it < hfNames_.size(); it++) {
617 if (levels >= hfLevels_[it]) {
619 (
static_cast<std::string>(dd4hep::dd::noNamespace(touch->GetVolume(levels - hfLevels_[it])->GetName())))
621 if (name == hfNames_[it]) {
630 std::vector<std::string>::const_iterator it = sensitiveEC_.begin();
631 std::vector<std::string>::const_iterator itEnd = sensitiveEC_.end();
632 for (; it != itEnd; ++it)
633 if (name.substr(0, 4) == *it)
Log< level::Info, true > LogVerbatim
bool isItEC(const std::string &)
T getUntrackedParameter(std::string const &, T const &) const
static const char layer_[]
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
static std::vector< std::string > checklist log
constexpr NumType convertRadToDeg(NumType radians)
void fillPerStep(const G4Step *)
T * make(const Args &...args) const
make new ROOT object
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Compact representation of the geometrical detector hierarchy.
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
const std::string names[nVars_]
constexpr NumType convertUnitsTo(double desiredUnits, NumType val)
std::vector< std::string > getNames(DDFilteredView &fv)
void fillBeginJob(const DDCompactView &)
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
void fillStartTrack(const G4Track *)
bool next()
set current node to the next node in the filtered tree
Abs< T >::type abs(const T &t)
bool isSensitive(const std::string &)
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
std::string_view name() const
bool firstChild()
set the current node to the first child
T get(const std::string &)
extract attribute value
DDsvalues_type mergedSpecifics() const
bool firstChild()
set the current node to the first child ...
MaterialBudgetHcalHistos(const edm::ParameterSet &p)
std::vector< double > getDDDArray(const std::string &str, const DDsvalues_type &sv)
const std::string & name() const
Returns the name.
bool isItHF(const G4VTouchable *)