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 etaMinP_ =
p.getUntrackedParameter<
double>(
"EtaMinP", 5.2);
29 etaMaxP_ =
p.getUntrackedParameter<
double>(
"EtaMaxP", 0.0);
30 etaLowMin_ =
p.getUntrackedParameter<
double>(
"EtaLowMin", 0.783);
31 etaLowMax_ =
p.getUntrackedParameter<
double>(
"EtaLowMax", 0.870);
32 etaMidMin_ =
p.getUntrackedParameter<
double>(
"EtaMidMin", 2.650);
33 etaMidMax_ =
p.getUntrackedParameter<
double>(
"EtaMidMax", 2.868);
34 etaHighMin_ =
p.getUntrackedParameter<
double>(
"EtaHighMin", 2.868);
35 etaHighMax_ =
p.getUntrackedParameter<
double>(
"EtaHighMax", 3.000);
36 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetHcalHistos: FillHisto : " << fillHistos_ <<
" PrintSummary "
37 << printSum_ <<
" == Eta plot: NX " << binEta_ <<
" Range " << -maxEta_ <<
":"
38 << maxEta_ <<
" Phi plot: NX " << binPhi_ <<
" Range " << -1._pi <<
":" << 1._pi
39 <<
" (Eta limit " << etaLow_ <<
":" << etaHigh_ <<
")"
40 <<
" Eta range (" << etaLowMin_ <<
":" << etaLowMax_ <<
"), (" << etaMidMin_ <<
":"
41 << etaMidMax_ <<
"), (" << etaHighMin_ <<
":" << etaHighMax_
42 <<
") Debug for eta range " << etaMinP_ <<
":" << etaMaxP_;
48 constexpr int32_t addLevel = 0;
55 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos: Names to be tested for " << attribute <<
" = "
56 <<
value <<
" has " << sensitives_.size() <<
" elements";
57 for (
unsigned int i = 0;
i < sensitives_.size();
i++)
59 <<
"MaterialBudgetHcalHistos: sensitives[" <<
i <<
"] = " << sensitives_[
i];
67 std::vector<double>
temp = getDDDArray(
"Levels",
sv);
68 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos: Names to be tested for " << attribute <<
" = "
69 <<
value <<
" has " << hfNames_.size() <<
" elements";
70 for (
unsigned int i = 0;
i < hfNames_.size();
i++) {
72 hfLevels_.push_back(
level + addLevel);
74 <<
"MaterialBudgetHcalHistos: HF[" <<
i <<
"] = " << hfNames_[
i] <<
" at level " << hfLevels_[
i];
77 const std::string ecalRO[2] = {
"EcalHitsEB",
"EcalHitsEE"};
78 attribute =
"ReadOutName";
79 for (
int k = 0;
k < 2;
k++) {
83 std::vector<std::string> senstmp =
getNames(fv3);
84 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos: Names to be tested for " << attribute
85 <<
" = " <<
value <<
" has " << senstmp.size() <<
" elements";
86 for (
unsigned int i = 0;
i < senstmp.size();
i++)
87 sensitiveEC_.push_back(senstmp[
i]);
89 for (
unsigned int i = 0;
i < sensitiveEC_.size();
i++)
91 <<
"MaterialBudgetHcalHistos:sensitiveEC[" <<
i <<
"] = " << sensitiveEC_[
i];
96 constexpr int32_t addLevel = 1;
103 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos: Names to be tested for " << attribute <<
" = "
104 <<
value <<
" has " << sensitives_.size() <<
" elements";
105 for (
unsigned int i = 0;
i < sensitives_.size();
i++)
107 <<
"MaterialBudgetHcalHistos: sensitives[" <<
i <<
"] = " << sensitives_[
i];
108 attribute =
"Volume";
112 std::vector<int>
temp = fv2.
get<std::vector<int> >(
"hf",
"Levels");
114 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos: Names to be tested for " << attribute <<
" = "
115 <<
value <<
" has " << hfNames_.size() <<
" elements";
116 for (
unsigned int i = 0;
i < hfNames_.size();
i++) {
117 hfLevels_.push_back(
temp[
i] + addLevel);
119 <<
"MaterialBudgetHcalHistos: HF[" <<
i <<
"] = " << hfNames_[
i] <<
" at level " << hfLevels_[
i];
122 const std::string ecalRO[2] = {
"EcalHitsEB",
"EcalHitsEE"};
123 attribute =
"ReadOutName";
124 for (
int k = 0;
k < 2;
k++) {
128 std::vector<std::string> senstmp =
getNames(fv);
129 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos: Names to be tested for " << attribute
130 <<
" = " <<
value <<
" has " << senstmp.size() <<
" elements";
131 for (
unsigned int i = 0;
i < senstmp.size();
i++)
132 sensitiveEC_.push_back(senstmp[
i]);
134 for (
unsigned int i = 0;
i < sensitiveEC_.size();
i++)
136 <<
"MaterialBudgetHcalHistos:sensitiveEC[" <<
i <<
"] = " << sensitiveEC_[
i];
141 id_ =
layer_ = steps_ = 0;
142 radLen_ = intLen_ = stepLen_ = 0;
143 nlayHB_ = nlayHE_ = nlayHF_ = nlayHO_ = 0;
145 const G4ThreeVector&
dir = aTrack->GetMomentum();
146 if (
dir.theta() != 0) {
152 double theEnergy = aTrack->GetTotalEnergy();
153 int theID = (
int)(aTrack->GetDefinition()->GetPDGEncoding());
163 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetHcalHistos: Track " << aTrack->GetTrackID() <<
" Code "
164 << theID <<
" Energy " <<
convertUnitsTo(1._GeV, theEnergy) <<
" GeV; Eta "
170 G4Material* material = aStep->GetPreStepPoint()->GetMaterial();
171 double step = aStep->GetStepLength();
172 double radl = material->GetRadlen();
173 double intl = material->GetNuclearInterLength();
177 const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
178 std::string name = (static_cast<std::string>(dd4hep::dd::noNamespace(touch->GetVolume(0)->GetName())));
179 std::string matName = (static_cast<std::string>(dd4hep::dd::noNamespace(material->GetName())));
182 for (
unsigned int ii = 0;
ii < matList_.size();
ii++) {
183 if (matList_[
ii] == matName) {
185 radLength_[
ii] += (
step / radl);
186 intLength_[
ii] += (
step / intl);
192 matList_.push_back(matName);
193 stepLength_.push_back(
step);
194 radLength_.push_back(
step / radl);
195 intLength_.push_back(
step / intl);
199 <<
" Material " << matName <<
" Old Length " << stepLen_ <<
" X0 "
200 <<
step / radl <<
":" << radLen_ <<
" Lambda " <<
step / intl <<
":"
204 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetHcalHistos: Step at " <<
name <<
" id " << id_ <<
":"
205 << idOld <<
" Length " <<
step <<
" in " << matName <<
" of density "
206 <<
density <<
" g/cc; Radiation Length " << radl <<
" mm; Interaction Length "
207 << intl <<
" mm\n Position "
208 << aStep->GetPreStepPoint()->GetPosition() <<
" Cylindrical R "
209 << aStep->GetPreStepPoint()->GetPosition().perp() <<
" Length (so far) "
210 << stepLen_ <<
" L/X0 " <<
step / radl <<
"/" << radLen_ <<
" L/Lambda "
211 <<
step / intl <<
"/" << intLen_;
214 int det = 0, lay = 0;
221 if (isSensitive(
name)) {
228 det = (touch->GetReplicaNumber(1)) / 1000;
229 lay = (touch->GetReplicaNumber(0) / 10) % 100 + 3;
243 }
else if (lay !=
layer_) {
250 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos: Det " << det <<
" Layer " << lay <<
" Eta "
265 if ((abseta >= etaMinP_) && (abseta <= etaMaxP_))
267 <<
"MaterialBudgetHcalHistos: Step at " <<
name <<
" calls filHisto with " << (id_ - 1);
273 radLen_ += (
step / radl);
274 intLen_ += (
step / intl);
277 if (!isItHF(aStep->GetPostStepPoint()->GetTouchable())) {
278 if ((abseta >= etaMinP_) && (abseta <= etaMaxP_))
280 << static_cast<std::string>(dd4hep::dd::noNamespace(
281 aStep->GetPostStepPoint()->GetTouchable()->GetVolume(0)->GetName()))
282 <<
" calls fillHisto with " << id_;
293 edm::LogVerbatim(
"MaterialBudget") <<
"Number of layers hit in HB:" << nlayHB_ <<
" HE:" << nlayHE_
294 <<
" HO:" << nlayHO_ <<
" HF:" << nlayHF_;
296 fillHisto(maxSet_ - 1);
300 for (
unsigned int ii = 0;
ii < matList_.size();
ii++) {
301 edm::LogVerbatim(
"MaterialBudget") << matList_[
ii] <<
"\t" << stepLength_[
ii] <<
"\t" << radLength_[
ii] <<
"\t"
311 if (!
tfile.isAvailable())
313 <<
"please add it to config file";
316 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos: Booking user histos === with " << binEta_
317 <<
" bins in eta from " << -maxEta_ <<
" to " << maxEta_ <<
" and " << binPhi_
321 std::string range0 =
"(" + std::to_string(etaMidMin_) +
":" + std::to_string(etaMidMax_) +
") ";
322 std::string range1 =
"(" + std::to_string(etaHighMin_) +
":" + std::to_string(etaHighMax_) +
") ";
323 std::string range2 =
"(" + std::to_string(etaLowMin_) +
":" + std::to_string(etaLowMax_) +
") ";
325 for (
int i = 0;
i < maxSet_;
i++) {
326 iter = std::to_string(
i);
327 me100[
i] =
tfile->make<TProfile>(
328 std::to_string(
i + 100).c_str(), (
"MB(X0) prof Eta in region " + iter).c_str(), binEta_, -maxEta_, maxEta_);
329 me200[
i] =
tfile->make<TProfile>(
330 std::to_string(
i + 200).c_str(), (
"MB(L0) prof Eta in region " + iter).c_str(), binEta_, -maxEta_, maxEta_);
331 me300[
i] =
tfile->make<TProfile>(
332 std::to_string(
i + 300).c_str(), (
"MB(Step) prof Eta in region " + iter).c_str(), binEta_, -maxEta_, maxEta_);
333 me400[
i] =
tfile->make<TH1F>(
334 std::to_string(
i + 400).c_str(), (
"Eta in region " + iter).c_str(), binEta_, -maxEta_, maxEta_);
335 me500[
i] =
tfile->make<TProfile>(
336 std::to_string(
i + 500).c_str(), (
"MB(X0) prof Ph in region " + iter).c_str(), binPhi_, -
maxPhi,
maxPhi);
337 me600[
i] =
tfile->make<TProfile>(
338 std::to_string(
i + 600).c_str(), (
"MB(L0) prof Ph in region " + iter).c_str(), binPhi_, -
maxPhi,
maxPhi);
339 me700[
i] =
tfile->make<TProfile>(
340 std::to_string(
i + 700).c_str(), (
"MB(Step) prof Ph in region " + iter).c_str(), binPhi_, -
maxPhi,
maxPhi);
342 tfile->make<TH1F>(std::to_string(
i + 800).c_str(), (
"Phi in region " + iter).c_str(), binPhi_, -
maxPhi,
maxPhi);
343 me900[
i] =
tfile->make<TProfile2D>(std::to_string(
i + 900).c_str(),
344 (
"MB(X0) prof Eta Phi in region " + iter).c_str(),
351 me1000[
i] =
tfile->make<TProfile2D>(std::to_string(
i + 1000).c_str(),
352 (
"MB(L0) prof Eta Phi in region " + iter).c_str(),
359 me1100[
i] =
tfile->make<TProfile2D>(std::to_string(
i + 1100).c_str(),
360 (
"MB(Step) prof Eta Phi in region " + iter).c_str(),
367 me1200[
i] =
tfile->make<TH2F>(std::to_string(
i + 1200).c_str(),
368 (
"Eta vs Phi in region " + iter).c_str(),
375 me1600[
i] =
tfile->make<TProfile>(std::to_string(
i + 1600).c_str(),
376 (
"MB(X0) prof Ph in region " + range0 + iter).c_str(),
380 me1700[
i] =
tfile->make<TProfile>(std::to_string(
i + 1700).c_str(),
381 (
"MB(L0) prof Ph in region " + range0 + iter).c_str(),
385 me1800[
i] =
tfile->make<TProfile>(std::to_string(
i + 1800).c_str(),
386 (
"MB(Step) prof Ph in region " + range0 + iter).c_str(),
390 me1900[
i] =
tfile->make<TProfile>(std::to_string(
i + 1900).c_str(),
391 (
"MB(X0) prof Ph in region " + range1 + iter).c_str(),
395 me2000[
i] =
tfile->make<TProfile>(std::to_string(
i + 2000).c_str(),
396 (
"MB(L0) prof Ph in region " + range1 + iter).c_str(),
400 me2100[
i] =
tfile->make<TProfile>(std::to_string(
i + 2100).c_str(),
401 (
"MB(Step) prof Ph in region " + range1 + iter).c_str(),
405 me2200[
i] =
tfile->make<TProfile>(std::to_string(
i + 2200).c_str(),
406 (
"MB(X0) prof Ph in region " + range2 + iter).c_str(),
410 me2300[
i] =
tfile->make<TProfile>(std::to_string(
i + 2300).c_str(),
411 (
"MB(L0) prof Ph in region " + range2 + iter).c_str(),
415 me2400[
i] =
tfile->make<TProfile>(std::to_string(
i + 2400).c_str(),
416 (
"MB(Step) prof Ph in region " + range2 + iter).c_str(),
421 for (
int i = 0;
i < maxSet2_;
i++) {
422 iter = std::to_string(
i);
423 me1300[
i] =
tfile->make<TH1F>(std::to_string(
i + 1300).c_str(),
424 (
"Events with layers Hit (0 all, 1 HB, ..) for " + iter).c_str(),
428 me1400[
i] =
tfile->make<TH2F>(std::to_string(
i + 1400).c_str(),
429 (
"Eta vs Phi for layers hit in " + iter).c_str(),
436 me1500[
i] =
tfile->make<TProfile>(std::to_string(
i + 1500).c_str(),
437 (
"Number of layers crossed (0 all, 1 HB, ..) for " + iter).c_str(),
443 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetHcalHistos: Booking user histos done ===";
448 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetHcalHistos:FillHisto called with index " <<
ii
449 <<
" integrated step " << stepLen_ <<
" X0 " << radLen_ <<
" Lamda " << intLen_;
451 if (
ii >= 0 &&
ii < maxSet_) {
452 me100[
ii]->Fill(eta_, radLen_);
453 me200[
ii]->Fill(eta_, intLen_);
454 me300[
ii]->Fill(eta_, stepLen_);
455 me400[
ii]->Fill(eta_);
457 if (eta_ >= etaLow_ && eta_ <= etaHigh_) {
458 me500[
ii]->Fill(phi_, radLen_);
459 me600[
ii]->Fill(phi_, intLen_);
460 me700[
ii]->Fill(phi_, stepLen_);
461 me800[
ii]->Fill(phi_);
464 me900[
ii]->Fill(eta_, phi_, radLen_);
465 me1000[
ii]->Fill(eta_, phi_, intLen_);
466 me1100[
ii]->Fill(eta_, phi_, stepLen_);
467 me1200[
ii]->Fill(eta_, phi_);
470 me1600[
ii]->Fill(phi_, radLen_);
471 me1700[
ii]->Fill(phi_, intLen_);
472 me1800[
ii]->Fill(phi_, stepLen_);
476 me1900[
ii]->Fill(phi_, radLen_);
477 me2000[
ii]->Fill(phi_, intLen_);
478 me2100[
ii]->Fill(phi_, stepLen_);
482 me2200[
ii]->Fill(phi_, radLen_);
483 me2300[
ii]->Fill(phi_, intLen_);
484 me2400[
ii]->Fill(phi_, stepLen_);
490 me1300[0]->Fill(eta_);
491 me1400[0]->Fill(eta_, phi_);
493 me1300[1]->Fill(eta_);
494 me1400[1]->Fill(eta_, phi_);
497 me1300[2]->Fill(eta_);
498 me1400[2]->Fill(eta_, phi_);
501 me1300[3]->Fill(eta_);
502 me1400[3]->Fill(eta_, phi_);
505 me1300[4]->Fill(eta_);
506 me1400[4]->Fill(eta_, phi_);
509 me1300[5]->Fill(eta_);
510 me1400[5]->Fill(eta_, phi_);
513 me1300[6]->Fill(eta_);
514 me1400[6]->Fill(eta_, phi_);
517 me1300[7]->Fill(eta_);
518 me1400[7]->Fill(eta_, phi_);
520 if (nlayHB_ > 0 || nlayHE_ > 0 || (nlayHF_ > 0 &&
std::abs(eta_) > 3.0)) {
521 me1300[8]->Fill(eta_);
522 me1400[8]->Fill(eta_, phi_);
524 me1500[0]->Fill(eta_, (
double)(nlayHB_ + nlayHO_ + nlayHE_ + nlayHF_));
525 me1500[1]->Fill(eta_, (
double)(nlayHB_));
526 me1500[2]->Fill(eta_, (
double)(nlayHE_));
527 me1500[4]->Fill(eta_, (
double)(nlayHF_));
531 edm::LogVerbatim(
"MaterialBudget") <<
"MaterialBudgetHcalHistos: Save user histos ===";
535 std::vector<std::string>
tmp;
548 std::vector<std::string>
tmp;
549 const std::vector<std::string> notIn = {
"CALO",
563 if (
std::find(notIn.begin(), notIn.end(),
n) == notIn.end()) {
574 edm::LogVerbatim(
"MaterialBudgetFull") <<
"MaterialBudgetHcalHistos:getDDDArray called for " <<
str;
578 const std::vector<double>& fvec =
value.doubles();
579 int nval = fvec.size();
581 throw cms::Exception(
"MaterialBudgetHcalHistos") <<
"nval = " << nval <<
" < 1 for array " <<
str <<
"\n";
586 throw cms::Exception(
"MaterialBudgetHcalHistos") <<
"cannot get array " <<
str <<
"\n";
591 std::vector<std::string>::const_iterator it = sensitives_.begin();
592 std::vector<std::string>::const_iterator itEnd = sensitives_.end();
593 for (; it != itEnd; ++it)
600 int levels = ((touch->GetHistoryDepth()) + 1);
601 for (
unsigned int it = 0; it < hfNames_.size(); it++) {
602 if (
levels >= hfLevels_[it]) {
604 (static_cast<std::string>(dd4hep::dd::noNamespace(touch->GetVolume(
levels - hfLevels_[it])->GetName())));
605 if (
name == hfNames_[it]) {
614 std::vector<std::string>::const_iterator it = sensitiveEC_.begin();
615 std::vector<std::string>::const_iterator itEnd = sensitiveEC_.end();
616 for (; it != itEnd; ++it)