LDMX Software
recon::PFTrackProducer Class Reference

Selects the tracks passed to ParticleFlow. More...

#include <PFTrackProducer.h>

Public Member Functions

 PFTrackProducer (const std::string &name, framework::Process &process)
 
virtual void configure (framework::config::Parameters &ps)
 Callback for the EventProcessor to configure itself from the given set of parameters.
 
virtual void produce (framework::Event &event)
 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 Member Functions

void produceTruth (framework::Event &event)
 
void produceReco (framework::Event &event)
 

Private Attributes

bool truth_tracking_ {false}
 
std::string input_track_coll_name_
 
std::string input_pass_name_
 
std::string output_track_coll_name_
 
bool do_electron_tracking_ {}
 
double min_electron_momentum_z_ {}
 
int max_electron_track_id_ {}
 
std::string reco_track_coll_name_
 
std::string reco_track_pass_name_
 
int min_n_hits_ {}
 
double max_chi2_ndf_ {}
 
double min_momentum_ {}
 
double max_shared_frac_ {}
 

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
 
NtupleManager & ntuple_ {NtupleManager::getInstance()}
 Manager for any ntuples.
 
logging::logger the_log_
 The logger for this EventProcessor.
 

Detailed Description

Selects the tracks passed to ParticleFlow.

Outputs ldmx::Track in both modes. In truth mode, Ecal scoring plane hits are wrapped into tracks with a single AtECAL state. In reco mode, tracks are selected from a reconstructed collection and must have an AtECAL state.

Definition at line 25 of file PFTrackProducer.h.

Constructor & Destructor Documentation

◆ PFTrackProducer()

recon::PFTrackProducer::PFTrackProducer ( const std::string & name,
framework::Process & process )
inline

Definition at line 27 of file PFTrackProducer.h.

Base class for a module which produces a data product.
virtual void process(Event &event) final
Processing an event for a Producer is calling produce.

Member Function Documentation

◆ configure()

void recon::PFTrackProducer::configure ( framework::config::Parameters & parameters)
virtual

Callback for the EventProcessor to configure itself from the given set of parameters.

The parameters a processor has access to are the member variables of the python class in the sequence that has class_name equal to the EventProcessor class name.

For an example, look at MyProcessor.

Parameters
parametersParameters for configuration.

Reimplemented from framework::EventProcessor.

Definition at line 12 of file PFTrackProducer.cxx.

12 {
13 truth_tracking_ = ps.get<bool>("truth_tracking");
14 input_track_coll_name_ = ps.get<std::string>("input_track_coll_name");
15 input_pass_name_ = ps.get<std::string>("input_pass_name");
16 output_track_coll_name_ = ps.get<std::string>("output_track_coll_name");
17 do_electron_tracking_ = ps.get<bool>("do_electron_tracking");
18 min_electron_momentum_z_ = ps.get<double>("min_electron_momentum_z");
19 max_electron_track_id_ = ps.get<int>("max_electron_track_id");
20 reco_track_coll_name_ = ps.get<std::string>("reco_track_coll_name");
21 reco_track_pass_name_ = ps.get<std::string>("reco_track_pass_name");
22 min_n_hits_ = ps.get<int>("min_n_hits");
23 max_chi2_ndf_ = ps.get<double>("max_chi2_ndf");
24 min_momentum_ = ps.get<double>("min_momentum");
25 max_shared_frac_ = ps.get<double>("max_shared_frac");
26}

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

◆ produce()

void recon::PFTrackProducer::produce ( framework::Event & event)
virtual

Process the event and put new data products into it.

Parameters
eventThe Event to process.

Implements framework::Producer.

Definition at line 74 of file PFTrackProducer.cxx.

74 {
75 if (truth_tracking_)
76 produceTruth(event);
77 else
78 produceReco(event);
79}

◆ produceReco()

void recon::PFTrackProducer::produceReco ( framework::Event & event)
private

Definition at line 130 of file PFTrackProducer.cxx.

130 {
131 if (!event.exists(reco_track_coll_name_, reco_track_pass_name_)) {
132 ldmx_log(fatal) << "Couldn't find input collection "
133 << reco_track_coll_name_ << "_" << reco_track_pass_name_;
134 return;
135 }
136 const auto tracks = event.getCollection<ldmx::Track>(reco_track_coll_name_,
137 reco_track_pass_name_);
138
139 // best tracks first: more hits, then lower chi2/ndf
140 std::vector<const ldmx::Track*> ranked;
141 for (const auto& tk : tracks) ranked.push_back(&tk);
142 auto chi2ndf = [](const ldmx::Track* t) {
143 return t->getNdf() > 0 ? t->getChi2() / t->getNdf() : 9e9;
144 };
145 std::stable_sort(ranked.begin(), ranked.end(), [&](auto a, auto b) {
146 if (a->getNhits() != b->getNhits()) return a->getNhits() > b->getNhits();
147 return chi2ndf(a) < chi2ndf(b);
148 });
149
150 std::vector<ldmx::Track> pf_tracks;
151 std::vector<std::set<unsigned int>> used_hits;
152 for (const auto* tk_ptr : ranked) {
153 const auto& tk = *tk_ptr;
154 // need the Ecal face state for linking
155 auto mom = tk.getMomentum(ldmx::AtECAL);
156 if (mom.empty()) {
157 ldmx_log(debug) << "Dropping track without AtECAL state";
158 continue;
159 }
160 if (mom[2] <= 0) continue;
161 if (tk.getNhits() < min_n_hits_) continue;
162 if (max_chi2_ndf_ >= 0 &&
163 (tk.getNdf() <= 0 || tk.getChi2() / tk.getNdf() > max_chi2_ndf_))
164 continue;
165 if (getP(mom) < min_momentum_) continue;
166 // drop duplicates sharing most hits with a better track
167 auto idxs = tk.getMeasurementsIdxs();
168 std::set<unsigned int> hits(idxs.begin(), idxs.end());
169 bool duplicate = false;
170 for (const auto& prev : used_hits) {
171 int n_shared = 0;
172 for (auto h : hits) n_shared += prev.count(h);
173 if (!hits.empty() && n_shared > max_shared_frac_ * hits.size()) {
174 duplicate = true;
175 break;
176 }
177 }
178 if (duplicate) continue;
179 used_hits.push_back(hits);
180 pf_tracks.push_back(tk);
181 ldmx_log(debug) << "Adding track: nhits=" << tk.getNhits()
182 << ", p = " << getP(mom) << ", trackID=" << tk.getTrackID();
183 }
184 std::sort(pf_tracks.begin(), pf_tracks.end(),
185 [](const ldmx::Track& a, const ldmx::Track& b) {
186 return getP(a) > getP(b);
187 });
188 event.add(output_track_coll_name_, pf_tracks);
189}
bool exists(const std::string &name, const std::string &passName, bool unique=true) const
Check for the existence of an object or collection with the given name and pass name in the event.
Definition Event.cxx:107
Implementation of a track object.
Definition Track.h:54

◆ produceTruth()

void recon::PFTrackProducer::produceTruth ( framework::Event & event)
private

Definition at line 81 of file PFTrackProducer.cxx.

81 {
82 if (!event.exists(input_track_coll_name_, input_pass_name_)) {
83 ldmx_log(fatal) << "Couldn't find input collection "
84 << input_track_coll_name_ << "_" << input_pass_name_;
85 return;
86 }
87 const auto ecal_sp_hits = event.getCollection<ldmx::SimTrackerHit>(
88 input_track_coll_name_, input_pass_name_);
89
90 std::vector<ldmx::Track> pf_tracks;
91 for (const auto& sp_hit : ecal_sp_hits) {
92 if (sp_hit.getPdgID() == 22 || sp_hit.getPdgID() == 2112) continue;
93 if (fabs(240 - sp_hit.getPosition()[2]) > 0.1) continue;
94 if (do_electron_tracking_) { // only select electron SP hits_
95 if (sp_hit.getPdgID() != 11) continue;
96 if (sp_hit.getTrackID() < 2 &&
97 sp_hit.getMomentum()[2] > min_electron_momentum_z_) {
98 // this is almost guaranteed to be a pileup beam electron! keep it
99 pf_tracks.push_back(trackFromSPHit(sp_hit));
100 ldmx_log(debug) << "Added beam electron SP hit: trackID="
101 << sp_hit.getTrackID()
102 << ", pz = " << sp_hit.getMomentum()[2];
103 } else if (sp_hit.getTrackID() <= max_electron_track_id_ &&
104 sp_hit.getMomentum()[2] > 5) {
105 // require more than minimum forward momentum to catch recoil electron
106 // candidates
107 pf_tracks.push_back(trackFromSPHit(sp_hit));
108 ldmx_log(debug) << "Adding SP hit: trackID=" << sp_hit.getTrackID()
109 << ", pdgID= " << sp_hit.getPdgID()
110 << ", pz = " << sp_hit.getMomentum()[2];
111 continue;
112 }
113 } // if electron tracking
114 else {
115 if (sp_hit.getTrackID() != 1 || sp_hit.getMomentum()[2] < 0) continue;
116 pf_tracks.push_back(trackFromSPHit(sp_hit));
117 ldmx_log(debug) << "Adding SP hit: trackID=" << sp_hit.getTrackID()
118 << ", pdgID= " << sp_hit.getPdgID()
119 << ", pz = " << sp_hit.getMomentum()[2];
120 break;
121 }
122 } // over SP hits_
123 std::sort(pf_tracks.begin(), pf_tracks.end(),
124 [](const ldmx::Track& a, const ldmx::Track& b) {
125 return getP(a) > getP(b);
126 });
127 event.add(output_track_coll_name_, pf_tracks);
128}
Represents a simulated tracker hit in the simulation.

Member Data Documentation

◆ do_electron_tracking_

bool recon::PFTrackProducer::do_electron_tracking_ {}
private

Definition at line 51 of file PFTrackProducer.h.

51{};

◆ input_pass_name_

std::string recon::PFTrackProducer::input_pass_name_
private

Definition at line 44 of file PFTrackProducer.h.

◆ input_track_coll_name_

std::string recon::PFTrackProducer::input_track_coll_name_
private

Definition at line 42 of file PFTrackProducer.h.

◆ max_chi2_ndf_

double recon::PFTrackProducer::max_chi2_ndf_ {}
private

Definition at line 64 of file PFTrackProducer.h.

64{};

◆ max_electron_track_id_

int recon::PFTrackProducer::max_electron_track_id_ {}
private

Definition at line 55 of file PFTrackProducer.h.

55{};

◆ max_shared_frac_

double recon::PFTrackProducer::max_shared_frac_ {}
private

Definition at line 68 of file PFTrackProducer.h.

68{};

◆ min_electron_momentum_z_

double recon::PFTrackProducer::min_electron_momentum_z_ {}
private

Definition at line 53 of file PFTrackProducer.h.

53{};

◆ min_momentum_

double recon::PFTrackProducer::min_momentum_ {}
private

Definition at line 66 of file PFTrackProducer.h.

66{};

◆ min_n_hits_

int recon::PFTrackProducer::min_n_hits_ {}
private

Definition at line 62 of file PFTrackProducer.h.

62{};

◆ output_track_coll_name_

std::string recon::PFTrackProducer::output_track_coll_name_
private

Definition at line 46 of file PFTrackProducer.h.

◆ reco_track_coll_name_

std::string recon::PFTrackProducer::reco_track_coll_name_
private

Definition at line 59 of file PFTrackProducer.h.

◆ reco_track_pass_name_

std::string recon::PFTrackProducer::reco_track_pass_name_
private

Definition at line 60 of file PFTrackProducer.h.

◆ truth_tracking_

bool recon::PFTrackProducer::truth_tracking_ {false}
private

Definition at line 39 of file PFTrackProducer.h.

39{false};

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