61 static std::unique_ptr<TrackstersCache> initializeGlobalCache(
const edm::ParameterSet &);
75 void energyRegressionAndID(
const std::vector<reco::CaloCluster> &
layerClusters,
76 const tensorflow::Session *,
77 std::vector<Trackster> &
result)
const;
78 void printTrackstersDebug(
const std::vector<Trackster> &,
const char *
label)
const;
79 void assignTimeToCandidates(std::vector<TICLCandidate> &resultCandidates)
const;
80 void dumpTrackster(
const Trackster &)
const;
130 std::unique_ptr<GeomDet> firstDisk_[2];
147 tfDnnLabel_(ps.getParameter<
std::
string>(
"tfDnnLabel")),
151 detector_(ps.getParameter<
std::
string>(
"detector")),
152 propName_(ps.getParameter<
std::
string>(
"propagator")),
156 optimiseAcrossTracksters_(ps.getParameter<
bool>(
"optimiseAcrossTracksters")),
157 useMTDTiming_(ps.getParameter<
bool>(
"useMTDTiming")),
158 eta_bin_window_(ps.getParameter<
int>(
"eta_bin_window")),
159 phi_bin_window_(ps.getParameter<
int>(
"phi_bin_window")),
160 pt_sigma_high_(ps.getParameter<double>(
"pt_sigma_high")),
161 pt_sigma_low_(ps.getParameter<double>(
"pt_sigma_low")),
162 halo_max_distance2_(ps.getParameter<double>(
"halo_max_distance2")),
163 track_min_pt_(ps.getParameter<double>(
"track_min_pt")),
164 track_min_eta_(ps.getParameter<double>(
"track_min_eta")),
165 track_max_eta_(ps.getParameter<double>(
"track_max_eta")),
166 track_max_missing_outerhits_(ps.getParameter<
int>(
"track_max_missing_outerhits")),
167 cosangle_align_(ps.getParameter<double>(
"cosangle_align")),
168 e_over_h_threshold_(ps.getParameter<double>(
"e_over_h_threshold")),
169 pt_neutral_threshold_(ps.getParameter<double>(
"pt_neutral_threshold")),
170 resol_calo_offset_had_(ps.getParameter<double>(
"resol_calo_offset_had")),
171 resol_calo_scale_had_(ps.getParameter<double>(
"resol_calo_scale_had")),
172 resol_calo_offset_em_(ps.getParameter<double>(
"resol_calo_offset_em")),
173 resol_calo_scale_em_(ps.getParameter<double>(
"resol_calo_scale_em")),
174 eidInputName_(ps.getParameter<
std::
string>(
"eid_input_name")),
175 eidOutputNameEnergy_(ps.getParameter<
std::
string>(
"eid_output_name_energy")),
176 eidOutputNameId_(ps.getParameter<
std::
string>(
"eid_output_name_id")),
177 eidMinClusterEnergy_(ps.getParameter<double>(
"eid_min_cluster_energy")),
178 eidNLayers_(ps.getParameter<
int>(
"eid_n_layers")),
179 eidNClusters_(ps.getParameter<
int>(
"eid_n_clusters")),
180 eidSession_(nullptr) {
181 produces<std::vector<Trackster>>();
182 produces<std::vector<TICLCandidate>>();
190 std::string detectorName_ = (
detector_ ==
"HFNose") ?
"HGCalHFNoseSensitive" :
"HGCalEESensitive";
192 esConsumes<HGCalDDDConstants, IdealGeometryRecord, edm::Transition::BeginRun>(
edm::ESInputTag(
"", detectorName_));
217 const std::vector<Trackster> &tracksters,
220 for (
auto const &
t : tracksters) {
221 tracksterTile.
fill(tracksterIteration,
t.barycenter().eta(),
t.barycenter().phi(), tracksterId);
222 LogDebug(
"TrackstersMergeProducer") <<
"Adding tracksterId: " << tracksterId <<
" into bin [eta,phi]: [ " 223 << tracksterTile[tracksterIteration].etaBin(
t.barycenter().eta()) <<
", " 224 << tracksterTile[tracksterIteration].
phiBin(
t.barycenter().phi())
225 <<
"] for iteration: " << tracksterIteration << std::endl;
232 auto e_over_h = (
t.raw_em_pt() / ((
t.raw_pt() -
t.raw_em_pt()) != 0. ? (
t.raw_pt() -
t.raw_em_pt()) : 1.));
234 <<
"\nTrackster raw_pt: " <<
t.raw_pt() <<
" raw_em_pt: " <<
t.raw_em_pt() <<
" eoh: " << e_over_h
235 <<
" barycenter: " <<
t.barycenter() <<
" eta,phi (baricenter): " <<
t.barycenter().eta() <<
", " 236 <<
t.barycenter().phi() <<
" eta,phi (eigen): " <<
t.eigenvectors(0).eta() <<
", " <<
t.eigenvectors(0).phi()
237 <<
" pt(eigen): " <<
std::sqrt(
t.eigenvectors(0).Unit().perp2()) *
t.raw_energy() <<
" seedID: " <<
t.seedID()
238 <<
" seedIndex: " <<
t.seedIndex() <<
" size: " <<
t.vertices().size() <<
" average usage: " 239 << (std::accumulate(std::begin(
t.vertex_multiplicity()), std::end(
t.vertex_multiplicity()), 0.) /
240 (
float)
t.vertex_multiplicity().size())
241 <<
" raw_energy: " <<
t.raw_energy() <<
" regressed energy: " <<
t.regressed_energy()
242 <<
" probs(ga/e/mu/np/cp/nh/am/unk): ";
243 for (
auto const &
p :
t.id_probabilities()) {
246 LogDebug(
"TrackstersMergeProducer") <<
" sigmas: ";
247 for (
auto const &
s :
t.sigmas()) {
248 LogDebug(
"TrackstersMergeProducer") <<
s <<
" ";
250 LogDebug(
"TrackstersMergeProducer") << std::endl;
254 auto resultTrackstersMerged = std::make_unique<std::vector<Trackster>>();
255 auto resultCandidates = std::make_unique<std::vector<TICLCandidate>>();
256 auto resultFromTracks = std::make_unique<std::vector<TICLCandidate>>();
264 const auto &
tracks = *track_h;
290 LogDebug(
"TrackstersMergeProducer") <<
"Results from the linking step : " << std::endl
291 <<
"No. of Tracks : " <<
tracks.size()
292 <<
" No. of Tracksters : " << (*trackstersclue3d_h).size() << std::endl
293 <<
"(neutral candidates have track id -1)" << std::endl;
295 std::vector<TICLCandidate> &
candidates = *resultCandidates;
297 auto track_ptr =
cand.trackPtr();
298 auto trackster_ptrs =
cand.tracksters();
301 track_idx = (track_ptr.isNull()) ? -1 : track_idx;
303 LogDebug(
"TrackstersMergeProducer") <<
"PDG ID " <<
cand.pdgId() <<
" charge " <<
cand.charge() <<
" p " <<
cand.p()
305 LogDebug(
"TrackstersMergeProducer") <<
"track id (p) : " << track_idx <<
" (" 306 << (track_ptr.isNull() ? -1 : track_ptr->p()) <<
") " 307 <<
" trackster ids (E) : ";
313 auto updated_size = 0;
314 for (
const auto &ts_ptr : trackster_ptrs) {
317 LogDebug(
"TrackstersMergeProducer") << ts_idx <<
" (" << ts_ptr->raw_energy() <<
") ";
320 auto &thisTrackster = *ts_ptr;
321 updated_size += thisTrackster.vertices().size();
322 outTrackster.vertices().reserve(updated_size);
323 outTrackster.vertex_multiplicity().reserve(updated_size);
324 std::copy(std::begin(thisTrackster.vertices()),
325 std::end(thisTrackster.vertices()),
326 std::back_inserter(outTrackster.vertices()));
327 std::copy(std::begin(thisTrackster.vertex_multiplicity()),
328 std::end(thisTrackster.vertex_multiplicity()),
329 std::back_inserter(outTrackster.vertex_multiplicity()));
332 LogDebug(
"TrackstersMergeProducer") << std::endl;
335 auto &orig_vtx = outTrackster.vertices();
336 auto vtx_sorted{orig_vtx};
337 std::sort(std::begin(vtx_sorted), std::end(vtx_sorted));
338 for (
unsigned int iLC = 1; iLC < vtx_sorted.size(); ++iLC) {
339 if (vtx_sorted[iLC] == vtx_sorted[iLC - 1]) {
341 const auto lcIdx = vtx_sorted[iLC];
342 const auto firstEl =
std::find(orig_vtx.begin(), orig_vtx.end(), lcIdx);
343 const auto firstPos =
std::distance(std::begin(orig_vtx), firstEl);
345 while (iDup != orig_vtx.end()) {
346 orig_vtx.erase(iDup);
347 outTrackster.vertex_multiplicity().erase(outTrackster.vertex_multiplicity().begin() +
349 outTrackster.vertex_multiplicity()[firstPos] -= 1;
355 outTrackster.zeroProbabilities();
356 if (!outTrackster.vertices().empty()) {
357 resultTrackstersMerged->push_back(outTrackster);
369 assert(resultTrackstersMerged->size() == resultCandidates->size());
371 auto isHad = [](
const Trackster &tracksterMerge) {
376 for (
size_t i = 0;
i < resultTrackstersMerged->size();
i++) {
377 auto const &tm = (*resultTrackstersMerged)[
i];
378 auto &
cand = (*resultCandidates)[
i];
380 cand.setIdProbabilities(tm.id_probabilities());
382 if (!
cand.trackPtr().isNull()) {
383 auto pdgId = isHad(tm) ? 211 : 11;
384 auto const &tk =
cand.trackPtr().get();
386 cand.setCharge(tk->charge());
387 cand.setRawEnergy(tm.raw_energy());
388 auto const ®rE = tm.regressed_energy();
390 regrE * tk->momentum().unit().y(),
391 regrE * tk->momentum().unit().z(),
395 auto pdgId = isHad(tm) ? 130 : 22;
398 cand.setRawEnergy(tm.raw_energy());
399 const float ®rE = tm.regressed_energy();
401 regrE * tm.barycenter().unit().y(),
402 regrE * tm.barycenter().unit().z(),
407 for (
auto &
cand : *resultFromTracks) {
408 auto const &tk =
cand.trackPtr().get();
409 cand.setPdgId(211 * tk->charge());
410 cand.setCharge(tk->charge());
417 resultCandidates->insert(resultCandidates->end(), resultFromTracks->begin(), resultFromTracks->end());
425 const tensorflow::Session *eidSession,
426 std::vector<Trackster> &tracksters)
const {
454 for (
auto &
t : tracksters) {
455 t.setRegressedEnergy(0.
f);
456 t.zeroProbabilities();
461 tensorflow::Tensor
input(tensorflow::DT_FLOAT,
shape);
465 std::vector<tensorflow::Tensor>
outputs;
482 std::vector<int> clusterIndices(trackster.
vertices().size());
484 clusterIndices[
k] =
k;
486 sort(clusterIndices.begin(), clusterIndices.end(), [&
layerClusters, &trackster](
const int &
a,
const int &
b) {
494 for (
const int &
k : clusterIndices) {
532 float regressedEnergy =
534 tracksters[
i].setRegressedEnergy(regressedEnergy);
542 float *probs =
outputs[probsIdx].flat<
float>().
data();
543 int probsNumber = tracksters[0].id_probabilities().size();
545 tracksters[
i].setProbabilities(&probs[
i * probsNumber]);
551 for (
auto &
cand : resultCandidates) {
552 if (
cand.tracksters().size() > 1) {
554 float invTimeErr = 0.f;
555 for (
const auto &tr :
cand.tracksters()) {
556 if (tr->timeError() > 0) {
557 auto invTimeESq =
pow(tr->timeError(), -2);
558 time += tr->time() * invTimeESq;
559 invTimeErr += invTimeESq;
562 if (invTimeErr > 0) {
572 for (
auto const &
t : tracksters) {
574 <<
counter++ <<
" TrackstersMergeProducer (" <<
label <<
") obj barycenter: " <<
t.barycenter()
575 <<
" eta,phi (baricenter): " <<
t.barycenter().eta() <<
", " <<
t.barycenter().phi()
576 <<
" eta,phi (eigen): " <<
t.eigenvectors(0).eta() <<
", " <<
t.eigenvectors(0).phi()
577 <<
" pt(eigen): " <<
std::sqrt(
t.eigenvectors(0).Unit().perp2()) *
t.raw_energy() <<
" seedID: " <<
t.seedID()
578 <<
" seedIndex: " <<
t.seedIndex() <<
" size: " <<
t.vertices().size() <<
" average usage: " 579 << (std::accumulate(std::begin(
t.vertex_multiplicity()), std::end(
t.vertex_multiplicity()), 0.) /
580 (
float)
t.vertex_multiplicity().size())
581 <<
" raw_energy: " <<
t.raw_energy() <<
" regressed energy: " <<
t.regressed_energy()
582 <<
" probs(ga/e/mu/np/cp/nh/am/unk): ";
583 for (
auto const &
p :
t.id_probabilities()) {
586 LogDebug(
"TrackstersMergeProducer") <<
" sigmas: ";
587 for (
auto const &
s :
t.sigmas()) {
588 LogDebug(
"TrackstersMergeProducer") <<
s <<
" ";
590 LogDebug(
"TrackstersMergeProducer") << std::endl;
612 desc.add<
bool>(
"optimiseAcrossTracksters",
true);
613 desc.add<
bool>(
"useMTDTiming",
true);
614 desc.add<
int>(
"eta_bin_window", 1);
615 desc.add<
int>(
"phi_bin_window", 1);
616 desc.add<
double>(
"pt_sigma_high", 2.);
617 desc.add<
double>(
"pt_sigma_low", 2.);
618 desc.add<
double>(
"halo_max_distance2", 4.);
619 desc.add<
double>(
"track_min_pt", 1.);
620 desc.add<
double>(
"track_min_eta", 1.48);
621 desc.add<
double>(
"track_max_eta", 3.);
622 desc.add<
int>(
"track_max_missing_outerhits", 5);
623 desc.add<
double>(
"cosangle_align", 0.9945);
624 desc.add<
double>(
"e_over_h_threshold", 1.);
625 desc.add<
double>(
"pt_neutral_threshold", 2.);
626 desc.add<
double>(
"resol_calo_offset_had", 1.5);
627 desc.add<
double>(
"resol_calo_scale_had", 0.15);
628 desc.add<
double>(
"resol_calo_offset_em", 1.5);
629 desc.add<
double>(
"resol_calo_scale_em", 0.15);
632 desc.add<
std::string>(
"eid_output_name_energy",
"output/regressed_energy");
633 desc.add<
std::string>(
"eid_output_name_id",
"output/id_probabilities");
634 desc.add<
double>(
"eid_min_cluster_energy", 2.5);
635 desc.add<
int>(
"eid_n_layers", 50);
636 desc.add<
int>(
"eid_n_clusters", 10);
637 descriptions.
add(
"trackstersMergeProducer",
desc);
ticl::Trackster::IterationIndex TracksterIterIndex
std::vector< NamedTensor > NamedTensorList
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
void fillTile(TICLTracksterTiles &, const std::vector< Trackster > &, TracksterIterIndex)
const std::vector< std::pair< DetId, float > > & hitsAndFractions() const
void setTrackIdx(int index)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
const double cosangle_align_
bool get(ProductID const &oid, Handle< PROD > &result) const
const edm::EDGetTokenT< std::vector< Trackster > > tracksters_clue3d_token_
edm::EDGetTokenT< edm::ValueMap< float > > tracks_time_token_
void assignTimeToCandidates(std::vector< TICLCandidate > &resultCandidates) const
tensorflow::Session * eidSession_
const double halo_max_distance2_
const tensorflow::Session * tfSession_
void produce(edm::Event &, const edm::EventSetup &) override
const std::string detector_
void printTrackstersDebug(const std::vector< Trackster > &, const char *label) const
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
hgcal::RecHitTools rhtools_
void assignPCAtoTracksters(std::vector< Trackster > &tracksters, const std::vector< reco::CaloCluster > &layerClusters, const edm::ValueMap< std::pair< float, float >> &layerClustersTime, double z_limit_em, hgcal::RecHitTools const &rhTools, bool computeLocalTime=false, bool energyWeight=true, bool clean=false, int minLayer=10, int maxLayer=10)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
const edm::EDGetTokenT< std::vector< reco::CaloCluster > > clusters_token_
const double track_min_eta_
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geometry_token_
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
double phi() const
azimuthal angle of cluster centroid
static std::string const input
PtEtaPhiMLorentzVectorD PtEtaPhiMLorentzVector
Lorentz vector with cartesian internal representation.
const float eidMinClusterEnergy_
XYZTLorentzVectorD XYZTLorentzVector
Lorentz vector with cylindrical internal representation using pseudorapidity.
const std::string eidOutputNameId_
const double pt_sigma_low_
static constexpr int eidNFeatures_
const double pt_neutral_threshold_
T const * product() const
std::vector< float > features(const reco::PreId &ecal, const reco::PreId &hcal, double rho, const reco::BeamSpot &spot, noZS::EcalClusterLazyTools &ecalTools)
const double e_over_h_threshold_
void beginRun(edm::Run const &iEvent, edm::EventSetup const &es) override
const double resol_calo_scale_had_
void energyRegressionAndID(const std::vector< reco::CaloCluster > &layerClusters, const tensorflow::Session *, std::vector< Trackster > &result) const
edm::EDGetTokenT< edm::ValueMap< float > > tracks_time_quality_token_
std::once_flag initializeGeometry_
const bool optimiseAcrossTracksters_
const int phi_bin_window_
void run(Session *session, const NamedTensorList &inputs, const std::vector< std::string > &outputNames, std::vector< Tensor > *outputs, const thread::ThreadPoolOptions &threadPoolOptions)
Abs< T >::type abs(const T &t)
const edm::EDGetTokenT< std::vector< reco::Muon > > muons_token_
void fill(int index, float eta, float phi, unsigned int objectId)
#define DEFINE_FWK_MODULE(type)
const double resol_calo_offset_em_
~TrackstersMergeProducer() override
void dumpTrackster(const Trackster &) const
const edm::EDGetTokenT< edm::ValueMap< std::pair< float, float > > > clustersTime_token_
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
const int track_max_missing_outerhits_
const std::string propName_
const std::string tfDnnLabel_
double energy() const
cluster energy
const edm::EDGetTokenT< std::vector< reco::Track > > tracks_token_
std::vector< unsigned int > & vertices()
const std::string eidOutputNameEnergy_
std::unique_ptr< LinkingAlgoBase > linkingAlgo_
const edm::ESGetToken< MagneticField, IdealMagneticFieldRecord > bfield_token_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const std::string eidInputName_
TrackstersMergeProducer(const edm::ParameterSet &ps)
edm::ESGetToken< HGCalDDDConstants, IdealGeometryRecord > hdc_token_
std::vector< float > & vertex_multiplicity()
edm::EDGetTokenT< edm::ValueMap< float > > tracks_time_err_token_
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const double pt_sigma_high_
const double track_max_eta_
const HGCalDDDConstants * hgcons_
const double resol_calo_offset_had_
char data[epos_bytes_allocation]
const edm::ESGetToken< Propagator, TrackingComponentsRecord > propagator_token_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const double track_min_pt_
double eta() const
pseudorapidity of cluster centroid
const double resol_calo_scale_em_
Power< A, B >::type pow(const A &a, const B &b)
const edm::ESGetToken< TfGraphDefWrapper, TfGraphRecord > tfDnnToken_
const int eta_bin_window_