LDMX Software
ecal::EcalClusterProducer Class Reference

Simple algorithm that does clustering in the ECal. More...

#include <EcalClusterProducer.h>

Public Member Functions

 EcalClusterProducer (const std::string &name, framework::Process &process)
 
void configure (framework::config::Parameters &parameters) override
 Configure the processor using the given user specified parameters.
 
void produce (framework::Event &event) override
 Process the event and put new data products into it.
 
- Public Member Functions inherited from framework::Producer
 Producer (const std::string &name, Process &process)
 Class constructor.
 
virtual void process (Event &event) final
 Processing an event for a Producer is calling produce.
 
- Public Member Functions inherited from framework::EventProcessor
 DECLARE_FACTORY (EventProcessor, EventProcessor *, const std::string &, Process &)
 declare that we have a factory for this class
 
 EventProcessor (const std::string &name, Process &process)
 Class constructor.
 
virtual ~EventProcessor ()=default
 Class destructor.
 
virtual void beforeNewRun (ldmx::RunHeader &run_header)
 Callback for Producers to add parameters to the run header before conditions are initialized.
 
virtual void onNewRun (const ldmx::RunHeader &run_header)
 Callback for the EventProcessor to take any necessary action when the run being processed changes.
 
virtual void onFileOpen (EventFile &event_file)
 Callback for the EventProcessor to take any necessary action when a new event input ROOT file is opened.
 
virtual void onFileClose (EventFile &event_file)
 Callback for the EventProcessor to take any necessary action when a event input ROOT file is closed.
 
virtual void onProcessStart ()
 Callback for the EventProcessor to take any necessary action when the processing of events starts, such as creating histograms.
 
virtual void onProcessEnd ()
 Callback for the EventProcessor to take any necessary action when the processing of events finishes, such as calculating job-summary quantities.
 
template<class T >
const T & getCondition (const std::string &condition_name)
 Access a conditions object for the current event.
 
TDirectory * getHistoDirectory ()
 Access/create a directory in the histogram file for this event processor to create histograms and analysis tuples.
 
void setStorageHint (framework::StorageControl::Hint hint)
 Mark the current event as having the given storage control hint from this module_.
 
void setStorageHint (framework::StorageControl::Hint hint, const std::string &purposeString)
 Mark the current event as having the given storage control hint from this module and the given purpose string.
 
int getLogFrequency () const
 Get the current logging frequency from the process.
 
int getRunNumber () const
 Get the run number from the process.
 
std::string getName () const
 Get the processor name.
 
void createHistograms (const std::vector< framework::config::Parameters > &histos)
 Internal function which is used to create histograms passed from the python configuration @parma histos vector of Parameters that configure histograms to create.
 

Private Attributes

double seed_threshold_ {0}
 
double cutoff_ {0}
 
double dc_ {0}
 
double rhoc_ {0}
 
double deltac_ {0}
 
double deltao_ {0}
 
float min_hit_energy_ {1.}
 
std::string rec_hit_coll_name_
 
std::string rec_hit_pass_name_
 
std::string algo_coll_name_
 
std::string cluster_coll_name_
 
bool clue_
 
int nbr_of_layers_
 
bool reclustering_
 
TString algo_name_
 The name of the cluster algorithm used.
 

Additional Inherited Members

- Protected Member Functions inherited from framework::EventProcessor
void abortEvent ()
 Abort the event immediately.
 
- Protected Attributes inherited from framework::EventProcessor
HistogramPool histograms_
 helper object for making and filling histograms
 
NtupleManagerntuple_ {NtupleManager::getInstance()}
 Manager for any ntuples.
 
logging::logger the_log_
 The logger for this EventProcessor.
 

Detailed Description

Simple algorithm that does clustering in the ECal.

Definition at line 44 of file EcalClusterProducer.h.

Constructor & Destructor Documentation

◆ EcalClusterProducer()

ecal::EcalClusterProducer::EcalClusterProducer ( const std::string & name,
framework::Process & process )

Definition at line 13 of file EcalClusterProducer.cxx.

15 : Producer(name, process) {}
Producer(const std::string &name, Process &process)
Class constructor.
virtual void process(Event &event) final
Processing an event for a Producer is calling produce.

Member Function Documentation

◆ configure()

void ecal::EcalClusterProducer::configure ( framework::config::Parameters & parameters)
overridevirtual

Configure the processor using the given user specified parameters.

Parameters
parametersSet of parameters used to configure this processor.

Reimplemented from framework::EventProcessor.

Definition at line 17 of file EcalClusterProducer.cxx.

17 {
18 cutoff_ = ps.get<double>("cutoff");
19 seed_threshold_ = ps.get<double>("seed_threshold");
20
21 dc_ = ps.get<double>("dc");
22 rhoc_ = ps.get<double>("rhoc");
23 deltac_ = ps.get<double>("deltac");
24 deltao_ = ps.get<double>("deltao");
25
26 rec_hit_coll_name_ = ps.get<std::string>("rec_hit_coll_name");
27 rec_hit_pass_name_ = ps.get<std::string>("rec_hit_pass_name");
28 algo_coll_name_ = ps.get<std::string>("algo_coll_name");
29 algo_name_ = ps.get<std::string>("algo_name");
30 cluster_coll_name_ = ps.get<std::string>("cluster_coll_name");
31 clue_ = ps.get<bool>("CLUE");
32 nbr_of_layers_ = ps.get<int>("nbr_of_layers");
33 reclustering_ = ps.get<bool>("reclustering");
34}
TString algo_name_
The name of the cluster algorithm used.

References framework::config::Parameters::get().

◆ produce()

void ecal::EcalClusterProducer::produce ( framework::Event & event)
overridevirtual

Process the event and put new data products into it.

Parameters
eventThe Event to process.

Implements framework::Producer.

Definition at line 36 of file EcalClusterProducer.cxx.

36 {
37 const auto& ecal_hits{event.getCollection<ldmx::EcalHit>(rec_hit_coll_name_,
38 rec_hit_pass_name_)};
39 if (ecal_hits.size() == 0) {
40 // don't do anything if there are no ECal hits
41 ldmx_log(fatal) << "No ECal hits found... exiting";
42 return;
43 }
44
45 if (clue_) {
46 ldmx_log(info) << "Using CLUE clustering algorithm";
47 CLUE cf;
48 cf.cluster(ecal_hits, dc_, rhoc_, deltac_, deltao_, nbr_of_layers_,
49 reclustering_);
50 ldmx_log(debug) << "CLUE algorithm finished clustering";
51 std::vector<IntermediateCluster> interm_cluster = cf.getClusters();
52 std::vector<IntermediateCluster> f_interm_cluster =
53 cf.getFirstLayerCentroids();
54 ldmx_log(debug) << "Got " << interm_cluster.size() << " clusters with "
55 << f_interm_cluster.size() << " first layer centroids";
56
57 auto n_loops = cf.getNLoops();
58 ldmx_log(debug) << "Number of clustering loops: " << n_loops;
59
60 if (reclustering_) {
61 ldmx_log(debug) << "Reclustererd initial number of clusters: "
62 << cf.getInitialClusterNbr()
63 << ", final number of clusters: "
64 << interm_cluster.size();
65 }
66
67 std::vector<ldmx::EcalCluster> ecal_clusters;
68 ldmx_log(debug) << "Filling " << interm_cluster.size()
69 << " clusters into ecal_clusters";
70 for (int cluster_indx = 0; cluster_indx < interm_cluster.size();
71 cluster_indx++) {
72 ldmx::EcalCluster cluster;
73
74 cluster.setEnergy(interm_cluster[cluster_indx].centroid().E());
75 cluster.setCentroidXYZ(interm_cluster[cluster_indx].centroid().x(),
76 interm_cluster[cluster_indx].centroid().y(),
77 interm_cluster[cluster_indx].centroid().z());
78 cluster.setFirstLayerCentroidXYZ(
79 f_interm_cluster[cluster_indx].centroid().x(),
80 f_interm_cluster[cluster_indx].centroid().y(),
81 f_interm_cluster[cluster_indx].centroid().z());
82 cluster.setNHits(interm_cluster[cluster_indx].getHits().size());
83 cluster.addHits(interm_cluster[cluster_indx].getHits());
84 cluster.addFirstLayerHits(f_interm_cluster[cluster_indx].getHits());
85
86 float cl_x(0), cl_y(0), cl_z(0), cl_xx(0), cl_yy(0), cl_zz(0);
87 float cl_w = 1; // weight
88 float sumw = 0;
89
90 for (auto hit : interm_cluster[cluster_indx].getHits()) {
91 if (hit->getEnergy() < min_hit_energy_) continue;
92 cl_w = log(hit->getEnergy()) - log(min_hit_energy_);
93 cl_x += cl_w * hit->getXPos();
94 cl_y += cl_w * hit->getYPos();
95 cl_z += cl_w * hit->getZPos();
96 cl_xx += cl_w * hit->getXPos() * hit->getXPos();
97 cl_yy += cl_w * hit->getYPos() * hit->getYPos();
98 cl_zz += cl_w * hit->getZPos() * hit->getZPos();
99 sumw += cl_w;
100 } // over hits
101 // could probably get this as cluster.getCentroidX() instead
102 cl_x /= sumw; // now is <x_>
103 cl_y /= sumw;
104 cl_z /= sumw;
105 cl_xx /= sumw; // now is <x_^2>
106 cl_yy /= sumw;
107 cl_zz /= sumw;
108 cl_xx = sqrt(cl_xx - cl_x * cl_x); // now is sqrt(<x_^2>-<x_>^2)
109 cl_yy = sqrt(cl_yy - cl_y * cl_y);
110 cl_zz = sqrt(cl_zz - cl_z * cl_z);
111
112 cluster.setRMSXYZ(cl_xx, cl_yy, cl_zz);
113 cluster.setLayer(interm_cluster[cluster_indx].getLayer());
114 ldmx_log(trace) << "Cluster " << cluster_indx
115 << " energy: " << cluster.getEnergy()
116 << ", nHits: " << cluster.getNHits() << ", centroid: ("
117 << cluster.getCentroidX() << ", "
118 << cluster.getCentroidY() << ", "
119 << cluster.getCentroidZ() << "), " << "RMS : ("
120 << cluster.getRMSX() << ", " << cluster.getRMSY() << ", "
121 << cluster.getRMSZ() << ")" << ", first layer centroid: ("
122 << cluster.getFirstLayerCentroidX() << ", "
123 << cluster.getFirstLayerCentroidY() << ", "
124 << cluster.getFirstLayerCentroidZ() << ")";
125
126 ecal_clusters.push_back(cluster);
127 }
128 ldmx_log(debug) << "Filled " << ecal_clusters.size()
129 << " clusters into ecal_clusters";
130 event.add(cluster_coll_name_, ecal_clusters);
131 } else {
132 ldmx_log(info) << "Using simple clustering algorithm " << algo_name_;
133 TemplatedClusterFinder<MyClusterWeight> cf;
134
135 for (const ldmx::EcalHit& hit : ecal_hits) {
136 // Skip zero energy digis.
137 if (hit.getEnergy() == 0) {
138 continue;
139 }
140 cf.add(hit);
141 }
142
143 cf.cluster(seed_threshold_, cutoff_);
144 std::vector<IntermediateCluster> interm_cluster = cf.getClusters();
145 std::map<int, double> c_weights = cf.getWeights();
146
147 ldmx::ClusterAlgoResult algo_result;
148 algo_result.set(algo_name_, 3, c_weights.rbegin()->first);
149 algo_result.setAlgoVar(0, cutoff_);
150 algo_result.setAlgoVar(1, seed_threshold_);
151 algo_result.setAlgoVar(2, cf.getNSeeds());
152
153 std::map<int, double>::iterator it = c_weights.begin();
154 for (it = c_weights.begin(); it != c_weights.end(); it++) {
155 algo_result.setWeight(it->first, it->second / 100);
156 }
157
158 std::vector<ldmx::EcalCluster> ecal_clusters;
159 for (int cluster_indx = 0; cluster_indx < interm_cluster.size();
160 cluster_indx++) {
161 ldmx::EcalCluster cluster;
162
163 cluster.setEnergy(interm_cluster[cluster_indx].centroid().E());
164 cluster.setCentroidXYZ(interm_cluster[cluster_indx].centroid().x(),
165 interm_cluster[cluster_indx].centroid().y(),
166 interm_cluster[cluster_indx].centroid().z());
167 cluster.setLayer(interm_cluster[cluster_indx].getLayer());
168 std::cout << "Cluster layer: " << cluster.getLayer() << std::endl;
169 cluster.setNHits(interm_cluster[cluster_indx].getHits().size());
170 cluster.addHits(interm_cluster[cluster_indx].getHits());
171 ecal_clusters.push_back(cluster);
172 }
173
174 event.add(cluster_coll_name_, ecal_clusters);
175 event.add(algo_coll_name_, algo_result);
176 } // end on simple clustering
177}
double getRMSX() const
rms in x
void setNHits(int nHits)
Sets total number of hits in the cluster.
Definition CaloCluster.h:65
double getCentroidZ() const
centroid z-location
double getCentroidX() const
centroid x-location
void setCentroidXYZ(double centroid_x, double centroid_y, double centroid_z)
Sets the three coordinates of the cluster centroid.
Definition CaloCluster.h:85
int getLayer() const
layer of the cluster centroid
double getRMSZ() const
rms in z
double getRMSY() const
rms in y
void setEnergy(double energy)
Sets total energy for the cluster.
Definition CaloCluster.h:59
double getCentroidY() const
centroid y-location
Contains details about the clustering algorithm.
void setAlgoVar(int element, double value)
Set an algorithm variable.
void set(const TString &name, int nvar)
Set name and number of variables of cluster algo.
void setWeight(int nClusters, double weight)
Set a weight when number of clusters reached.
Stores cluster information from the ECal.
Definition EcalCluster.h:20
void addHits(const std::vector< const ldmx::EcalHit * > &hits)
Take in the hits that make up the cluster.
Stores reconstructed hit information from the ECAL.
Definition EcalHit.h:19

References ldmx::EcalCluster::addHits(), ldmx::CaloCluster::getCentroidX(), ldmx::CaloCluster::getCentroidY(), ldmx::CaloCluster::getCentroidZ(), ldmx::CaloCluster::getLayer(), ldmx::CaloCluster::getRMSX(), ldmx::CaloCluster::getRMSY(), ldmx::CaloCluster::getRMSZ(), ldmx::ClusterAlgoResult::set(), ldmx::ClusterAlgoResult::setAlgoVar(), ldmx::CaloCluster::setCentroidXYZ(), ldmx::CaloCluster::setEnergy(), ldmx::CaloCluster::setNHits(), and ldmx::ClusterAlgoResult::setWeight().

Member Data Documentation

◆ algo_coll_name_

std::string ecal::EcalClusterProducer::algo_coll_name_
private

Definition at line 71 of file EcalClusterProducer.h.

◆ algo_name_

TString ecal::EcalClusterProducer::algo_name_
private

The name of the cluster algorithm used.

Definition at line 79 of file EcalClusterProducer.h.

◆ clue_

bool ecal::EcalClusterProducer::clue_
private

Definition at line 74 of file EcalClusterProducer.h.

◆ cluster_coll_name_

std::string ecal::EcalClusterProducer::cluster_coll_name_
private

Definition at line 72 of file EcalClusterProducer.h.

◆ cutoff_

double ecal::EcalClusterProducer::cutoff_ {0}
private

Definition at line 60 of file EcalClusterProducer.h.

60{0};

◆ dc_

double ecal::EcalClusterProducer::dc_ {0}
private

Definition at line 62 of file EcalClusterProducer.h.

62{0};

◆ deltac_

double ecal::EcalClusterProducer::deltac_ {0}
private

Definition at line 64 of file EcalClusterProducer.h.

64{0};

◆ deltao_

double ecal::EcalClusterProducer::deltao_ {0}
private

Definition at line 65 of file EcalClusterProducer.h.

65{0};

◆ min_hit_energy_

float ecal::EcalClusterProducer::min_hit_energy_ {1.}
private

Definition at line 67 of file EcalClusterProducer.h.

67{1.};

◆ nbr_of_layers_

int ecal::EcalClusterProducer::nbr_of_layers_
private

Definition at line 75 of file EcalClusterProducer.h.

◆ rec_hit_coll_name_

std::string ecal::EcalClusterProducer::rec_hit_coll_name_
private

Definition at line 69 of file EcalClusterProducer.h.

◆ rec_hit_pass_name_

std::string ecal::EcalClusterProducer::rec_hit_pass_name_
private

Definition at line 70 of file EcalClusterProducer.h.

◆ reclustering_

bool ecal::EcalClusterProducer::reclustering_
private

Definition at line 76 of file EcalClusterProducer.h.

◆ rhoc_

double ecal::EcalClusterProducer::rhoc_ {0}
private

Definition at line 63 of file EcalClusterProducer.h.

63{0};

◆ seed_threshold_

double ecal::EcalClusterProducer::seed_threshold_ {0}
private

Definition at line 59 of file EcalClusterProducer.h.

59{0};

The documentation for this class was generated from the following files: