19 del_tk_ts_layer1_(conf.getParameter<double>(
"delta_tk_ts_layer1")),
20 del_tk_ts_int_(conf.getParameter<double>(
"delta_tk_ts_interface")),
21 del_ts_em_had_(conf.getParameter<double>(
"delta_ts_em_had")),
22 del_ts_had_had_(conf.getParameter<double>(
"delta_ts_had_had")),
23 timing_quality_threshold_(conf.getParameter<double>(
"track_time_quality_threshold")),
24 cutTk_(conf.getParameter<
std::
string>(
"cutTk")) {}
43 std::array<TICLLayerTile, 2> &tracksterTiles) {
46 Vector const &baryc =
t.barycenter();
47 Vector directnv =
t.eigenvectors(0);
56 directnv = baryc.unit();
58 zVal *= (baryc.Z() > 0) ? 1 : -1;
60 float par = (zVal - baryc.Z()) / directnv.Z();
61 float xOnSurface = par * directnv.X() + baryc.X();
62 float yOnSurface = par * directnv.Y() + baryc.Y();
63 Vector tPoint(xOnSurface, yOnSurface, zVal);
65 tracksterTiles[1].
fill(tPoint.Eta(), tPoint.Phi(),
idx);
67 else if (tPoint.Eta() < 0)
68 tracksterTiles[0].
fill(tPoint.Eta(), tPoint.Phi(),
idx);
74 const std::vector<std::pair<Vector, unsigned>> &seedingCollection,
75 const std::array<TICLLayerTile, 2> &tracksterTiles,
76 const std::vector<Vector> &tracksterPropPoints,
78 unsigned trackstersSize,
79 std::vector<std::vector<unsigned>> &resultCollection,
80 bool useMask =
false) {
86 std::vector<int>
mask(trackstersSize, 0);
89 for (
auto &
i : seedingCollection) {
90 float seed_eta =
i.first.Eta();
91 float seed_phi =
i.first.Phi();
93 auto sideZ = seed_eta > 0;
101 std::vector<unsigned> in_delta;
102 std::vector<float> distances2;
103 for (
int eta_i = search_box[0]; eta_i <= search_box[1]; ++eta_i) {
104 for (
int phi_i = search_box[2]; phi_i <= search_box[3]; ++phi_i) {
106 for (
const unsigned &t_i : in_tile) {
108 auto sep2 = (tracksterPropPoints[t_i].Eta() - seed_eta) * (tracksterPropPoints[t_i].Eta() - seed_eta) +
109 (tracksterPropPoints[t_i].
Phi() - seed_phi) * (tracksterPropPoints[t_i].
Phi() - seed_phi);
111 in_delta.push_back(t_i);
112 distances2.push_back(sep2);
119 std::vector<unsigned>
indices(in_delta.size());
125 const auto &t_i = in_delta[
index];
127 resultCollection[
seedId].push_back(t_i);
141 const float &tkTimeQual,
148 return energyCompatible;
153 float tsT = trackster.
time();
156 bool timeCompatible =
false;
159 timeCompatible =
true;
165 if (!(energyCompatible))
166 LogDebug(
"LinkingAlgoByDirectionGeometric")
167 <<
"energy incompatible : track p " <<
track.p() <<
" trackster energy " << trackster.
raw_energy() <<
"\n";
168 if (!(timeCompatible))
169 LogDebug(
"LinkingAlgoByDirectionGeometric") <<
"time incompatible : track time " << tkT <<
" +/- " << tkTErr
170 <<
" trackster time " << tsT <<
" +/- " << tsTErr <<
"\n";
172 return energyCompatible && timeCompatible;
176 const std::vector<Trackster> &tracksters,
178 std::vector<unsigned> &ts_mask,
179 float &energy_in_candidate,
185 energy_in_candidate += tracksters[ts].raw_energy();
189 const char *
label)
const {
194 LogDebug(
"LinkingAlgoByDirectionGeometric") <<
"All links found - " <<
label <<
"\n";
195 LogDebug(
"LinkingAlgoByDirectionGeometric") <<
"(seed can either be a track or trackster depending on the step)\n";
196 for (
unsigned i = 0;
i < resultCollection.size(); ++
i) {
197 LogDebug(
"LinkingAlgoByDirectionGeometric") <<
"seed " <<
i <<
" - tracksters : ";
198 const auto &
links = resultCollection[
i];
199 for (
unsigned j = 0;
j <
links.size(); ++
j) {
200 LogDebug(
"LinkingAlgoByDirectionGeometric") <<
j;
202 LogDebug(
"LinkingAlgoByDirectionGeometric") <<
"\n";
204 #endif // EDM_ML_DEBUG 211 std::pair<float, float> rMinMax =
hgcons_->
rangeR(zVal,
true);
214 std::pair<float, float> rMinMax_interface =
hgcons_->
rangeR(zVal_interface,
true);
216 for (
int iSide = 0; iSide < 2; ++iSide) {
217 float zSide = (iSide == 0) ? (-1. * zVal) : zVal;
224 zSide = (iSide == 0) ? (-1. * zVal_interface) : zVal_interface;
228 SimpleDiskBounds(rMinMax_interface.first, rMinMax_interface.second, zSide - 0.5, zSide + 0.5))
237 const std::vector<reco::Muon> &
muons,
240 std::vector<TICLCandidate> &resultLinked,
241 std::vector<TICLCandidate> &chargedHadronsFromTk) {
242 const auto &
tracks = *tkH;
243 const auto &tracksters = *tsH;
251 std::vector<std::pair<Vector, unsigned>> trackPColl;
252 std::vector<std::pair<Vector, unsigned>> tkPropIntColl;
253 std::vector<std::pair<Vector, unsigned>> tsPropIntColl;
254 std::vector<std::pair<Vector, unsigned>> tsHadPropIntColl;
255 trackPColl.reserve(
tracks.size());
256 tkPropIntColl.reserve(
tracks.size());
257 tsPropIntColl.reserve(tracksters.size());
258 tsHadPropIntColl.reserve(tracksters.size());
260 std::array<TICLLayerTile, 2> tracksterPropTiles = {};
261 std::array<TICLLayerTile, 2> tsPropIntTiles = {};
262 std::array<TICLLayerTile, 2> tsHadPropIntTiles = {};
265 auto isHadron = [&](
const Trackster &
t) ->
bool {
267 return (
std::abs(
t.barycenter().Z()) > boundary_z);
271 LogDebug(
"LinkingAlgoByDirectionGeometric") <<
"------- Geometric Linking ------- \n";
274 std::vector<unsigned> candidateTrackIds;
275 candidateTrackIds.reserve(
tracks.size());
276 for (
unsigned i = 0;
i <
tracks.size(); ++
i) {
285 LogDebug(
"LinkingAlgoByDirectionGeometric")
286 <<
"track " <<
i <<
" - eta " << tk.eta() <<
" phi " << tk.phi() <<
" time " 288 <<
" muid " << muId <<
"\n";
290 LogDebug(
"LinkingAlgoByDirectionGeometric")
291 <<
"track " <<
i <<
" - eta " << tk.eta() <<
" phi " << tk.phi() <<
" muid " << muId <<
"\n";
299 candidateTrackIds.push_back(
i);
305 int iSide =
int(tk.eta() > 0);
309 if (tsos.isValid()) {
310 Vector trackP(tsos.globalPosition().x(), tsos.globalPosition().y(), tsos.globalPosition().z());
311 trackPColl.emplace_back(trackP,
i);
315 if (tsos_int.isValid()) {
316 Vector trackP(tsos_int.globalPosition().x(), tsos_int.globalPosition().y(), tsos_int.globalPosition().z());
317 tkPropIntColl.emplace_back(trackP,
i);
320 tkPropIntColl.shrink_to_fit();
321 trackPColl.shrink_to_fit();
322 candidateTrackIds.shrink_to_fit();
329 std::vector<Vector> tsAllProp;
330 std::vector<Vector> tsAllPropInt;
331 tsAllProp.reserve(tracksters.size());
332 tsAllPropInt.reserve(tracksters.size());
334 for (
unsigned i = 0;
i < tracksters.size(); ++
i) {
335 const auto &
t = tracksters[
i];
337 LogDebug(
"LinkingAlgoByDirectionGeometric")
338 <<
"trackster " <<
i <<
" - eta " <<
t.barycenter().eta() <<
" phi " <<
t.barycenter().phi() <<
" time " 339 <<
t.time() <<
" energy " <<
t.raw_energy() <<
"\n";
344 tsAllProp.emplace_back(tsP);
349 tsAllPropInt.emplace_back(tsP);
352 tsPropIntColl.emplace_back(tsP,
i);
354 tsHadPropIntTiles[(
t.barycenter().Z() > 0) ? 1 : 0].
fill(tsP.Eta(), tsP.Phi(),
i);
355 tsHadPropIntColl.emplace_back(tsP,
i);
358 tsPropIntColl.shrink_to_fit();
359 tsHadPropIntColl.shrink_to_fit();
364 std::vector<std::vector<unsigned>> tsNearTk(
tracks.size());
369 std::vector<std::vector<unsigned>> tsNearTkAtInt(
tracks.size());
375 std::vector<std::vector<unsigned>> tsNearAtInt(tracksters.size());
377 tsPropIntColl, tsHadPropIntTiles, tsAllPropInt,
del_ts_em_had_, tracksters.size(), tsNearAtInt);
381 std::vector<std::vector<unsigned>> tsHadNearAtInt(tracksters.size());
383 tsHadPropIntColl, tsHadPropIntTiles, tsAllPropInt,
del_ts_had_had_, tracksters.size(), tsHadNearAtInt);
387 dumpLinksFound(tsNearTkAtInt,
"track -> tracksters at lastLayerEE");
388 dumpLinksFound(tsNearAtInt,
"EM -> HAD tracksters at lastLayerEE");
389 dumpLinksFound(tsHadNearAtInt,
"HAD -> HAD tracksters at lastLayerEE");
390 #endif //EDM_ML_DEBUG 394 std::vector<TICLCandidate> chargedCandidates;
395 std::vector<unsigned int> chargedMask(tracksters.size(), 0);
396 for (
unsigned &
i : candidateTrackIds) {
397 if (tsNearTk[
i].
empty() && tsNearTkAtInt[
i].empty()) {
400 chargedHadronsFromTk.push_back(chargedHad);
405 float total_raw_energy = 0.;
408 float track_time = 0.f;
409 float track_timeErr = 0.f;
410 float track_timeQual = 0.f;
412 track_time = (*tkTime_h)[tkRef];
413 track_timeErr = (*tkTimeErr_h)[tkRef];
414 track_timeQual = (*tkTimeQual_h)[tkRef];
417 for (
const unsigned ts3_idx : tsNearTk[
i]) {
425 recordTrackster(ts3_idx, tracksters, tsH, chargedMask, total_raw_energy, chargedCandidate);
427 for (
const unsigned ts2_idx : tsNearAtInt[ts3_idx]) {
435 recordTrackster(ts2_idx, tracksters, tsH, chargedMask, total_raw_energy, chargedCandidate);
437 for (
const unsigned ts1_idx : tsHadNearAtInt[ts2_idx]) {
445 recordTrackster(ts1_idx, tracksters, tsH, chargedMask, total_raw_energy, chargedCandidate);
449 for (
const unsigned ts1_idx : tsHadNearAtInt[ts3_idx]) {
457 recordTrackster(ts1_idx, tracksters, tsH, chargedMask, total_raw_energy, chargedCandidate);
461 for (
const unsigned ts4_idx : tsNearTkAtInt[
i]) {
469 recordTrackster(ts4_idx, tracksters, tsH, chargedMask, total_raw_energy, chargedCandidate);
471 for (
const unsigned ts2_idx : tsNearAtInt[ts4_idx]) {
479 recordTrackster(ts2_idx, tracksters, tsH, chargedMask, total_raw_energy, chargedCandidate);
481 for (
const unsigned ts1_idx : tsHadNearAtInt[ts2_idx]) {
489 recordTrackster(ts1_idx, tracksters, tsH, chargedMask, total_raw_energy, chargedCandidate);
493 for (
const unsigned ts1_idx : tsHadNearAtInt[ts4_idx]) {
501 recordTrackster(ts1_idx, tracksters, tsH, chargedMask, total_raw_energy, chargedCandidate);
510 chargedCandidates.push_back(chargedCandidate);
514 chargedHadronsFromTk.push_back(chargedHad);
518 std::vector<TICLCandidate> neutralCandidates;
519 std::vector<int> neutralMask(tracksters.size(), 0);
520 for (
unsigned i = 0;
i < tracksters.size(); ++
i) {
525 if (tsNearAtInt[
i].
empty() && tsHadNearAtInt[
i].empty() && !neutralMask[
i]) {
528 neutralCandidates.push_back(neutralCandidate);
531 if (!neutralMask[
i]) {
535 for (
const unsigned ts2_idx : tsNearAtInt[
i]) {
536 if (chargedMask[ts2_idx])
538 if (!neutralMask[ts2_idx]) {
540 neutralMask[ts2_idx] = 1;
542 for (
const unsigned ts1_idx : tsHadNearAtInt[ts2_idx]) {
543 if (chargedMask[ts1_idx])
545 if (!neutralMask[ts1_idx]) {
547 neutralMask[ts1_idx] = 1;
551 for (
const unsigned ts1_idx : tsHadNearAtInt[
i]) {
552 if (chargedMask[ts1_idx])
554 if (!neutralMask[ts1_idx]) {
556 neutralMask[ts1_idx] = 1;
561 neutralCandidates.push_back(neutralCandidate);
565 resultLinked.insert(std::end(resultLinked), std::begin(neutralCandidates), std::end(neutralCandidates));
566 resultLinked.insert(std::end(resultLinked), std::begin(chargedCandidates), std::end(chargedCandidates));
572 "1.48 < abs(eta) < 3.0 && pt > 1. && quality(\"highPurity\") && " 573 "hitPattern().numberOfLostHits(\"MISSING_OUTER_HITS\") < 5");
574 desc.add<
double>(
"delta_tk_ts_layer1", 0.02);
575 desc.add<
double>(
"delta_tk_ts_interface", 0.03);
576 desc.add<
double>(
"delta_ts_em_had", 0.03);
577 desc.add<
double>(
"delta_ts_had_had", 0.03);
578 desc.add<
double>(
"track_time_quality_threshold", 0.5);
void linkTracksters(const edm::Handle< std::vector< reco::Track >>, const edm::Handle< edm::ValueMap< float >>, const edm::Handle< edm::ValueMap< float >>, const edm::Handle< edm::ValueMap< float >>, const std::vector< reco::Muon > &, const edm::Handle< std::vector< Trackster >>, const bool useMTDTiming, std::vector< TICLCandidate > &, std::vector< TICLCandidate > &) override
double waferZ(int layer, bool reco) const
static DiskPointer build(Args &&... args)
static int muAssocToTrack(const reco::TrackRef &trackref, const reco::MuonCollection &muons)
ticl::Trackster::Vector Vector
static constexpr int nPhiBins
static constexpr float maxEta
const float del_tk_ts_int_
edm::ESHandle< Propagator > propagator_
hgcal::RecHitTools rhtools_
muons
the two sets of parameters below are mutually exclusive, depending if RECO or ALCARECO is used the us...
const float del_ts_em_had_
TrajectoryStateOnSurface propagate(STA const &state, SUR const &surface) const
static void fillPSetDescription(edm::ParameterSetDescription &desc)
const float timeError() const
T const * product() const
Vector propagateTrackster(const Trackster &t, const unsigned idx, float zVal, std::array< TICLLayerTile, 2 > &tracksterTiles)
const StringCutObjectSelector< reco::Track > cutTk_
void recordTrackster(const unsigned ts, const std::vector< Trackster > &tracksters, const edm::Handle< std::vector< Trackster >> tsH, std::vector< unsigned > &ts_mask, float &energy_in_candidate, TICLCandidate &candidate)
const float raw_energy() const
edm::ESHandle< MagneticField > bfield_
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
void initialize(const HGCalDDDConstants *hgcons, const hgcal::RecHitTools rhtools, const edm::ESHandle< MagneticField > bfieldH, const edm::ESHandle< Propagator > propH) override
Abs< T >::type abs(const T &t)
static void fillPSetDescription(edm::ParameterSetDescription &desc)
const float del_ts_had_had_
static constexpr float minEta
std::pair< double, double > rangeR(double z, bool reco) const
LinkingAlgoByDirectionGeometric(const edm::ParameterSet &conf)
const float del_tk_ts_layer1_
void dumpLinksFound(std::vector< std::vector< unsigned >> &resultCollection, const char *label) const
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
const float timing_quality_threshold_
void findTrackstersInWindow(const std::vector< std::pair< Vector, unsigned >> &seedingCollection, const std::array< TICLLayerTile, 2 > &tracksterTiles, const std::vector< Vector > &tracksterPropPoints, float delta, unsigned trackstersSize, std::vector< std::vector< unsigned >> &resultCollection, bool useMask)
const HGCalDDDConstants * hgcons_
void addTrackster(const edm::Ptr< ticl::Trackster > &trackster)
std::unique_ptr< GeomDet > interfaceDisk_[2]
std::unique_ptr< GeomDet > firstDisk_[2]
bool timeAndEnergyCompatible(float &total_raw_energy, const reco::Track &track, const Trackster &trackster, const float &tkTime, const float &tkTimeErr, const float &tkTimeQual, bool useMTDTiming)
~LinkingAlgoByDirectionGeometric() override
const std::vector< edm::Ptr< ticl::Trackster > > tracksters() const
void setTrackPtr(const edm::Ptr< reco::Track > &trackPtr)