Skip to content

Commit 1d32c17

Browse files
improve friendliness of histogram pool (#1854)
* WIP: start refactor, not compiling * rename file and get compiling To Do - check that changning how bin edges are passed doesn't seg fault - add more creation helpers - check if we are in a subdirectory? share Process handle so we can open histogram directory for the user upon creation? * pass callback for directory creation to pool, start tests * more docs and updated tests * WIP: attempt to get categorical histograms working * pool with categorical axes working - need to add more creation options - more tests of those different histogram axes - documentation - tests on weights * add ability to store sumw2 when creating * make sure weighting and 2-D categories works * start some more documentation on histograms * clang-tidy the histogram pool developments * Apply clang-format * add categorical-axis support to python config histograms - move interpretatin of pyton config parameters into HistogramPool - add ninth and final 2D create method - add x_label to 1D categorical histograms back for uniformity * Apply clang-tidy * add documentation to insert, avoid single-char variable names * Apply clang-format * convert category histograms in DQM to new interface * undo accidental clang-format * fixup category bin indexing * pass weighted through python config as well * more docs on example usage and create methods * Apply clang-format * add warning about prior naming scheme --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent d1119a2 commit 1d32c17

23 files changed

+1109
-655
lines changed

DQM/include/DQM/DarkBremInteraction.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,6 @@ class DarkBremInteraction : public framework::Producer {
3232
public:
3333
DarkBremInteraction(const std::string& n, framework::Process& p)
3434
: framework::Producer(n, p) {}
35-
/**
36-
* update the labels of some categorial histograms
37-
*
38-
* This is helpful for downstream viewers of the histograms
39-
* so that ROOT will display the bins properly.
40-
*/
41-
virtual void onProcessStart() override;
42-
4335
/**
4436
* extract the kinematics of the dark brem interaction from the SimParticles
4537
*
@@ -58,12 +50,6 @@ class DarkBremInteraction : public framework::Producer {
5850
void configure(framework::config::Parameters& parameters) override;
5951

6052
private:
61-
/**
62-
* Set the labels of the histogram of the input name with the input labels
63-
*/
64-
void setHistLabels(const std::string& name,
65-
const std::vector<std::string>& labels);
66-
6753
/**
6854
* the list of known materials assigning them to material ID numbers
6955
*

DQM/include/DQM/EcalClusterAnalyzer.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ class EcalClusterAnalyzer : public framework::Analyzer {
3434
~EcalClusterAnalyzer() override = default;
3535
void configure(framework::config::Parameters& ps) override;
3636
void analyze(const framework::Event& event) override;
37-
void onProcessStart() override;
38-
void setHistLabels(const std::string& name,
39-
const std::vector<std::string>& labels);
4037

4138
private:
4239
/// Use the number of simulated electrons

DQM/include/DQM/HcalVetoResults.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ class HcalVetoResults : public framework::Analyzer {
3232
*/
3333
virtual void configure(framework::config::Parameters& ps);
3434

35-
/**
36-
* Things to do only on process start
37-
*/
38-
virtual void onProcessStart();
39-
4035
/**
4136
* Fills histograms
4237
*/

DQM/include/DQM/PhotoNuclearDQM.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,6 @@ class PhotoNuclearDQM : public framework::Analyzer {
7575
*/
7676
void analyze(const framework::Event &event) override;
7777

78-
/// @brief Helper function to label categorical histos
79-
/// @param name : Name of the histo for the labels to set
80-
/// @param labels : Labels on the X axis
81-
void setHistLabels(const std::string &name,
82-
const std::vector<std::string> &labels);
83-
84-
/// Method executed before processing of events begins.
85-
void onProcessStart() override;
86-
8778
private:
8879
/** Method used to classify events. Note: Assumes that daughters is sorted by
8980
* kinetic energy. */

DQM/include/DQM/SampleValidation.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ class SampleValidation : public framework::Analyzer {
1919
virtual void configure(framework::config::Parameters& ps) override;
2020
virtual void analyze(const framework::Event& event) override;
2121
int pdgidLabel(const int pdgid);
22-
/// Method executed before processing of events begins.
23-
void onProcessStart() override;
2422

2523
private:
2624
std::string target_scoring_plane_passname_;

DQM/include/DQM/TrkDeDxMassEstFeatures.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,6 @@ class TrkDeDxMassEstFeatures : public framework::Analyzer {
3131
*/
3232
virtual void analyze(const framework::Event& event) override;
3333

34-
/// Method executed before processing of events begins.
35-
void onProcessStart() override;
36-
3734
private:
3835
/// Collection Name for mass estimate object
3936
std::string mass_estimate_name_;

DQM/python/dqm.py

Lines changed: 87 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ def __init__(self,name="HcalVetoResults") :
200200
self.build1DHistogram('num_valid_hits',
201201
'Total number of valid HCAL hits', 500, -0.5, 499.5)
202202
self.build1DHistogram('max_section',
203-
'Maximal PE hit section', 5, -0.5, 4.5)
203+
'Maximal PE hit section',
204+
['Back', 'Top', 'Bottom', 'Right', 'Left'])
204205
self.build1DHistogram('max_pos_z',
205206
'Maximal PE hit postion Z [mm]', 6000, 200., 6200)
206207
self.build1DHistogram('veto_pass',
@@ -646,10 +647,11 @@ def __init__(self) :
646647
# elements are hydrogen and carbon (for trigger pads) and tungsten target
647648
self.build1DHistogram('dark_brem_element',
648649
'Element in which Dark Brem Occurred',
649-
12, 0, 12)
650+
["did not happen", "H 1", "C 6", "O 8", "Na 11", "Si 14",
651+
"Ca 20", "Cu 29", "Y 39", "Lu 71", "W 74", "unlisted"])
650652
self.build1DHistogram('dark_brem_material',
651653
'Material in which Dark Brem Occurred',
652-
8, 0, 8)
654+
["Unknown", "C", "PCB", "Glue", "Si", "Al", "W / LYSO", "PVT"])
653655

654656

655657
class HCalRawDigi(ldmxcfg.Analyzer) :
@@ -736,17 +738,56 @@ def __init__(self,name='PN', count_light_ions=True) :
736738

737739
self.sim_particles_passname = ''
738740

741+
event_type_labels = [
742+
"Nothing hard", # 0
743+
"1 n", # 1
744+
"2 n", # 2
745+
"#geq 3 n", # 3
746+
"1 #pi", # 4
747+
"2 #pi", # 5
748+
"1 #pi_{0}", # 6
749+
"1 #pi A", # 7
750+
"1 #pi 2 A", # 8
751+
"2 #pi A", # 9
752+
"1 #pi_{0} A", # 10
753+
"1 #pi_{0} 2 A", # 11
754+
"#pi_{0} #pi A", # 12
755+
"1 p", # 13
756+
"2 p", # 14
757+
"pn", # 15
758+
"K^{0}_{L} X", # 16
759+
"K X", # 17
760+
"K^{0}_{S} X", # 18
761+
"exotics", # 19
762+
"multi-body", # 20
763+
]
764+
event_type_compact_labels = [
765+
"1 n", # 0
766+
"K#pm X", # 1
767+
"1 K^{0}", # 2
768+
"2 n", # 3
769+
"Soft", # 4
770+
"Other", # 5
771+
]
739772

740773
self.count_light_ions=count_light_ions
741-
self.build1DHistogram("event_type" , "", 24, -1, 23)
742-
self.build1DHistogram("event_type_500mev" , "", 24, -1, 23)
743-
self.build1DHistogram("event_type_2000mev" , "", 24, -1, 23)
744-
self.build1DHistogram("event_type_compact" , "", 8, -1, 7)
745-
self.build1DHistogram("event_type_compact_500mev" , "", 8, -1, 7)
746-
self.build1DHistogram("event_type_compact_2000mev" , "", 8, -1, 7)
747-
self.build1DHistogram("1n_event_type" , "", 7, -1, 6)
748-
self.build1DHistogram("pn_vertex_volume" , "", 13, -0.5, 12.5)
749-
self.build1DHistogram("pn_interaction_material" , "", 10, -0.5, 9.5)
774+
self.build1DHistogram("event_type" , "", event_type_labels)
775+
self.build1DHistogram("event_type_500mev" , "", event_type_labels)
776+
self.build1DHistogram("event_type_2000mev" , "", event_type_labels)
777+
self.build1DHistogram("event_type_compact" , "", event_type_compact_labels)
778+
self.build1DHistogram("event_type_compact_500mev" , "", event_type_compact_labels)
779+
self.build1DHistogram("event_type_compact_2000mev" , "", event_type_compact_labels)
780+
self.build1DHistogram("1n_event_type" , "", [
781+
"nn", "pn", "#pi^{+}n", "#pi^{0}n", "other"
782+
])
783+
self.build1DHistogram("pn_vertex_volume" , "", [
784+
"Didn't happen", "Else", "W Cooling", "C Cooling", "PCB",
785+
"CarbonBasePlate", "Absorber", "Sensor", "Glue", "Motherboard"
786+
])
787+
self.build1DHistogram("pn_interaction_material" , "", [
788+
"Didn't happen", "Else", "Si", "W", "FR4", "Steel", "Epoxy",
789+
"PVT", "Glue", "Air"
790+
])
750791
self.build1DHistogram("pn_particle_mult" , "Photo-nuclear Multiplicity", 200, 0, 200)
751792
self.build1DHistogram("pn_neutron_mult" , "Photo-nuclear Neutron Multiplicity", 200,0, 200)
752793
self.build1DHistogram("pn_gamma_energy" , "#gamma Energy [MeV]", 100, 0, 10000)
@@ -859,7 +900,7 @@ def __init__(self,name='TrkDeDxMassEstFeatures') :
859900
self.build1DHistogram("mass_estimate_very_low_p_pion", "Mass Estimate for pions [MeV]", 20, 0., 200.)
860901
self.build1DHistogram("mass_estimate_very_low_p_kaon", "Mass Estimate for kaons [MeV]", 60, 200., 800.)
861902
self.build1DHistogram("mass_estimate_very_low_p_proton", "Mass Estimate for proton [MeV]", 40, 800., 1200.)
862-
self.build1DHistogram("track_type", "Track Type", 3, 0, 3)
903+
self.build1DHistogram("track_type", "Track Type", ['Other', 'Tagger', 'Recoil'])
863904

864905

865906
class TrigScintSimDQM(ldmxcfg.Analyzer) :
@@ -998,21 +1039,43 @@ def __init__(self, name='SampleValidation') :
9981039
self.sim_particles_passname = ''
9991040
self.target_scoring_plane_passname = ''
10001041

1001-
# primary histograms
1002-
self.build1DHistogram("primaries_pdgid", "ID of primary particles", 20, 0, 20)
1042+
pdgid_bin_labels = [
1043+
"e^{+}", # 0
1044+
"e^{-}", # 1
1045+
"#mu^{+}", # 2
1046+
"#mu^{-}", # 3
1047+
"#gamma", # 4
1048+
"p^{+}", # 5
1049+
"n^{0}", # 6
1050+
"#pi^{+}", # 7
1051+
"#pi^{-}", # 8
1052+
"#pi^{0}", # 9
1053+
"K^{+}", # 10
1054+
"K^{-}", # 11
1055+
"k_{L}", # 12
1056+
"k_{S}", # 13
1057+
"light-N", # 14
1058+
"heavy-N", # 15
1059+
"#Lambda / #Sigma / #Xi", # 16
1060+
"A'", # 17
1061+
"else",
1062+
]
1063+
1064+
#primary histograms
1065+
self.build1DHistogram("primaries_pdgid", "ID of primary particles", pdgid_bin_labels)
10031066
self.build1DHistogram("primaries_energy", "Energy of primary particles [MeV]", 90, 0, 9000) # range applicable for 4 GeV beam
10041067
self.build2DHistogram("beam_smear", "x [mm]", 30, -150, 150, "y [mm]", 30, -150, 150)
1005-
self.build1DHistogram("primarydaughters_pdgid", "ID of primary daughters", 20, 0, 20)
1068+
self.build1DHistogram("primarydaughters_pdgid", "ID of primary daughters", pdgid_bin_labels)
10061069
self.build1DHistogram("daughterphoton_energy", "Energy spectrum of all photons from primary [MeV]", 170, 0, 8500)
10071070

1008-
# primary daughter of interest (brem / dark brem) histograms
1009-
self.build1DHistogram("harddaughters_pdgid", "ID of primary daughters", 20, 0, 20)
1071+
#primary daughter of interest(brem / dark brem) histograms
1072+
self.build1DHistogram("harddaughters_pdgid", "ID of primary daughters", pdgid_bin_labels)
10101073
self.build1DHistogram("harddaughters_startZ", "Start z position of hard primary daughter [mm]", 100, -500, 500)
10111074
self.build1DHistogram("harddaughters_endZ", "End z position of hard primary daughter [mm]", 100, -500, 500)
10121075
self.build1DHistogram("harddaughters_energy", "Energy spectrum of hard primary daughter [MeV]", 130, 2000, 8500)
10131076

1014-
# daughters of hard brem histograms
1015-
self.build1DHistogram("hardbremdaughters_pdgid", "ID of hard brem daughters", 20, 0, 20)
1077+
#daughters of hard brem histograms
1078+
self.build1DHistogram("hardbremdaughters_pdgid", "ID of hard brem daughters", pdgid_bin_labels)
10161079
self.build1DHistogram("hardbremdaughters_startZ", "Start z position of hard brem daughters [mm]", 200, -1000, 1000)
10171080
self.build1DHistogram("hardbremdaughters_endZ", "End z position of hard brem daughters [mm]", 70, -1000, 6000)
10181081
self.build1DHistogram("hardbremdaughters_energy", "Energy of hard brem daughters [MeV]", 170, 0, 8500)
@@ -1053,7 +1116,7 @@ def __init__(self,name='EcalClusterAnalyzer') :
10531116
self.ecal_sim_hit_coll = "EcalSimHits"
10541117
self.ecal_sim_hit_pass = "" #use whatever pass is available
10551118

1056-
# Pass name for ecal digis and rec hits
1119+
#Pass name for ecal digis and rec hits
10571120
self.rec_hit_coll_name = 'EcalRecHits'
10581121
self.rec_hit_pass_name = ''
10591122

@@ -1066,9 +1129,10 @@ def __init__(self,name='EcalClusterAnalyzer') :
10661129
self.build1DHistogram("number_of_clusters_first_layer", "Number of CLUE clusters on the first layer", 5, -0.5, 4.5)
10671130
self.build1DHistogram("number_of_clusters_per_layer", "Number of CLUE clusters per layer", 5, -0.5, 4.5)
10681131
self.build1DHistogram("number_of_clusters", "Total number of CLUE clusters", 51, -0.5, 50.5)
1069-
self.build1DHistogram("correctly_predicted_events", "Correct Cluster Count", 3, 0., 3.)
1132+
self.build1DHistogram("correctly_predicted_events", "Correct Cluster Count",
1133+
["Underpredicted", "Correct", "Overpredicted"])
10701134

1071-
# Need to mod for more than two electrons
1135+
#Need to mod for more than two electrons
10721136
self.build1DHistogram("ancestors", "Ancestors of particles", 4, 0., 4.)
10731137

10741138
self.build1DHistogram("same_ancestor", "Percentage of hits in cluster coming from the electron that produced most hits", 21, 0., 105.)

DQM/src/DQM/DarkBremInteraction.cxx

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,6 @@ static double quadsum(const std::initializer_list<double>& list) {
3434
return sqrt(sum);
3535
}
3636

37-
void DarkBremInteraction::setHistLabels(
38-
const std::string& name, const std::vector<std::string>& labels) {
39-
/**
40-
* We could probably move this into Framework since it is a relatively
41-
* common task. I could even imagine a way of constructing a StrCategory
42-
* histogram.
43-
*/
44-
auto h{histograms_.get(name)};
45-
for (std::size_t ibin{1}; ibin <= labels.size(); ibin++) {
46-
h->GetXaxis()->SetBinLabel(ibin, labels[ibin - 1].c_str());
47-
}
48-
}
49-
50-
void DarkBremInteraction::onProcessStart() {
51-
setHistLabels("dark_brem_material",
52-
{"Unknown", "C", "PCB", "Glue", "Si", "Al", "W / LYSO", "PVT"});
53-
54-
setHistLabels("dark_brem_element",
55-
{"did not happen", "H 1", "C 6", "O 8", "Na 11", "Si 14",
56-
"Ca 20", "Cu 29", "Y 39", "Lu 71", "W 74", "unlisted"});
57-
}
58-
5937
void DarkBremInteraction::produce(framework::Event& event) {
6038
histograms_.setWeight(event.getEventHeader().getWeight());
6139
const auto& particle_map{

DQM/src/DQM/EcalClusterAnalyzer.cxx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -281,20 +281,6 @@ void EcalClusterAnalyzer::analyze(const framework::Event& event) {
281281
100. * (ecal_rec_hits.size() - clustered_hits) / ecal_rec_hits.size());
282282
}
283283

284-
void EcalClusterAnalyzer::setHistLabels(
285-
const std::string& name, const std::vector<std::string>& labels) {
286-
auto histo{histograms_.get(name)};
287-
for (std::size_t ibin{1}; ibin <= labels.size(); ibin++) {
288-
histo->GetXaxis()->SetBinLabel(ibin, labels[ibin - 1].c_str());
289-
}
290-
}
291-
292-
void EcalClusterAnalyzer::onProcessStart() {
293-
setHistLabels("correctly_predicted_events",
294-
{"Underpredicted", "Correct", "Overpredicted"});
295-
296-
} // end of onProcessStart
297-
298284
} // namespace dqm
299285

300286
DECLARE_ANALYZER(dqm::EcalClusterAnalyzer)

DQM/src/DQM/HcalVetoResults.cxx

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,6 @@ void HcalVetoResults::configure(framework::config::Parameters &ps) {
1010
hcal_veto_passname_ = ps.get<std::string>("hcal_veto_passname");
1111
}
1212

13-
void HcalVetoResults::onProcessStart() {
14-
std::vector<TH1 *> hists_hca_lsector = {histograms_.get("max_section")};
15-
16-
// enum HcalSection { BACK = 0, TOP = 1, BOTTOM = 2, RIGHT = 3, LEFT = 4 };
17-
std::vector<std::string> labels_hca_lsector = {"HCAL BACK", // 1
18-
"HCAL TOP", // 2
19-
"HCAL BOTTOM", // 3
20-
"HCAL RIGHT", // 4
21-
"HCAL LEFT", // 5
22-
""};
23-
24-
for (int ilabel{1}; ilabel < labels_hca_lsector.size(); ++ilabel) {
25-
for (auto &hist : hists_hca_lsector) {
26-
hist->GetXaxis()->SetBinLabel(ilabel,
27-
labels_hca_lsector[ilabel - 1].c_str());
28-
}
29-
}
30-
}
31-
3213
void HcalVetoResults::analyze(const framework::Event &event) {
3314
// Get the veto object
3415
auto hcal_veto{

0 commit comments

Comments
 (0)