13 #include "DD4hep/Filter.h" 21 binEta_ =
p.getUntrackedParameter<
int>(
"NBinEta", 260);
22 binPhi_ =
p.getUntrackedParameter<
int>(
"NBinPhi", 180);
23 maxEta_ =
p.getUntrackedParameter<
double>(
"MaxEta", 5.2);
24 etaLow_ =
p.getUntrackedParameter<
double>(
"EtaLow", -5.2);
25 etaHigh_ =
p.getUntrackedParameter<
double>(
"EtaHigh", 5.2);
26 fillHistos_ =
p.getUntrackedParameter<
bool>(
"FillHisto",
true);
27 printSum_ =
p.getUntrackedParameter<
bool>(
"PrintSummary",
false);
28 fromdd4hep_ =
p.getUntrackedParameter<
bool>(
"Fromdd4hep",
false);
29 etaMinP_ =
p.getUntrackedParameter<
double>(
"EtaMinP", 5.2);
30 etaMaxP_ =
p.getUntrackedParameter<
double>(
"EtaMaxP", 0.0);
31 etaLowMin_ =
p.getUntrackedParameter<
double>(
"EtaLowMin", 0.783);
32 etaLowMax_ =
p.getUntrackedParameter<
double>(
"EtaLowMax", 0.870);
33 etaMidMin_ =
p.getUntrackedParameter<
double>(
"EtaMidMin", 2.650);
34 etaMidMax_ =
p.getUntrackedParameter<
double>(
"EtaMidMax", 2.868);
35 etaHighMin_ =
p.getUntrackedParameter<
double>(
"EtaHighMin", 2.868);
36 etaHighMax_ =
p.getUntrackedParameter<
double>(
"EtaHighMax", 3.000);
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;
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++) {
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;
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();
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);
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_))
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" 335 if (!
tfile.isAvailable())
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_
349 for (
int i = 0;
i < maxSet_;
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>(
361 me600[
i] =
tfile->make<TProfile>(
363 me700[
i] =
tfile->make<TProfile>(
368 (
"MB(X0) prof Eta Phi in region " + iter).c_str(),
376 (
"MB(L0) prof Eta Phi in region " + iter).c_str(),
384 (
"MB(Step) prof Eta Phi in region " + iter).c_str(),
392 (
"Eta vs Phi in region " + iter).c_str(),
400 (
"MB(X0) prof Ph in region " + range0 + iter).c_str(),
405 (
"MB(L0) prof Ph in region " + range0 + iter).c_str(),
410 (
"MB(Step) prof Ph in region " + range0 + iter).c_str(),
415 (
"MB(X0) prof Ph in region " + range1 + iter).c_str(),
420 (
"MB(L0) prof Ph in region " + range1 + iter).c_str(),
425 (
"MB(Step) prof Ph in region " + range1 + iter).c_str(),
430 (
"MB(X0) prof Ph in region " + range2 + iter).c_str(),
435 (
"MB(L0) prof Ph in region " + range2 + iter).c_str(),
440 (
"MB(Step) prof Ph in region " + range2 + iter).c_str(),
445 for (
int i = 0;
i < maxSet2_;
i++) {
448 (
"Events with layers Hit (0 all, 1 HB, ..) for " + iter).c_str(),
453 (
"Eta vs Phi for layers hit in " + iter).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;
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()) {
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();
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 &)
static const char layer_[]
constexpr NumType convertRadToDeg(NumType radians)
void fillPerStep(const G4Step *)
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_]
static std::string to_string(const XMLCh *ch)
constexpr NumType convertUnitsTo(double desiredUnits, NumType val)
std::vector< std::string > getNames(DDFilteredView &fv)
std::string_view name() const
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 ...
bool firstChild()
set the current node to the first child
DDsvalues_type mergedSpecifics() const
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
T get(const std::string &)
extract attribute value
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)
bool isItHF(const G4VTouchable *)