18 del_tk_ts_layer1_(conf.getParameter<double>(
"delta_tk_ts_layer1")),
19 del_tk_ts_int_(conf.getParameter<double>(
"delta_tk_ts_interface")),
20 del_ts_em_had_(conf.getParameter<double>(
"delta_ts_em_had")),
21 del_ts_had_had_(conf.getParameter<double>(
"delta_ts_had_had")),
22 timing_quality_threshold_(conf.getParameter<double>(
"track_time_quality_threshold")),
23 cutTk_(conf.getParameter<
std::
string>(
"cutTk")) {}
42 std::array<TICLLayerTile, 2> &tracksterTiles) {
45 Vector const &baryc =
t.barycenter();
46 Vector directnv =
t.eigenvectors(0);
55 directnv = baryc.unit();
57 zVal *= (baryc.Z() > 0) ? 1 : -1;
59 float par = (zVal - baryc.Z()) / directnv.Z();
60 float xOnSurface = par * directnv.X() + baryc.X();
61 float yOnSurface = par * directnv.Y() + baryc.Y();
62 Vector tPoint(xOnSurface, yOnSurface, zVal);
64 tracksterTiles[1].
fill(tPoint.Eta(), tPoint.Phi(),
idx);
66 else if (tPoint.Eta() < 0)
67 tracksterTiles[0].
fill(tPoint.Eta(), tPoint.Phi(),
idx);
73 const std::vector<std::pair<Vector, unsigned>> &seedingCollection,
74 const std::array<TICLLayerTile, 2> &tracksterTiles,
75 const std::vector<Vector> &tracksterPropPoints,
77 unsigned trackstersSize,
78 std::vector<std::vector<unsigned>> &resultCollection,
79 bool useMask =
false) {
85 std::vector<int>
mask(trackstersSize, 0);
88 for (
auto &
i : seedingCollection) {
89 float seed_eta =
i.first.Eta();
90 float seed_phi =
i.first.Phi();
91 unsigned seedId =
i.second;
92 auto sideZ = seed_eta > 0;
100 std::vector<unsigned> in_delta;
101 std::vector<float> distances2;
102 for (
int eta_i = search_box[0]; eta_i <= search_box[1]; ++eta_i) {
103 for (
int phi_i = search_box[2]; phi_i <= search_box[3]; ++phi_i) {
105 for (
const unsigned &t_i : in_tile) {
107 auto sep2 = (tracksterPropPoints[t_i].Eta() - seed_eta) * (tracksterPropPoints[t_i].Eta() - seed_eta) +
108 (tracksterPropPoints[t_i].
Phi() - seed_phi) * (tracksterPropPoints[t_i].
Phi() - seed_phi);
110 in_delta.push_back(t_i);
111 distances2.push_back(sep2);
118 std::vector<unsigned>
indices(in_delta.size());
124 const auto &t_i = in_delta[
index];
126 resultCollection[seedId].push_back(t_i);
140 const float &tkTimeQual) {
147 float tsT = trackster.
time();
150 bool timeCompatible =
false;
153 timeCompatible =
true;
159 if (!(energyCompatible))
160 LogDebug(
"LinkingAlgoByDirectionGeometric")
161 <<
"energy incompatible : track p " <<
track.p() <<
" trackster energy " << trackster.
raw_energy() <<
"\n";
162 if (!(timeCompatible))
163 LogDebug(
"LinkingAlgoByDirectionGeometric") <<
"time incompatible : track time " << tkT <<
" +/- " << tkTErr
164 <<
" trackster time " << tsT <<
" +/- " << tsTErr <<
"\n";
166 return energyCompatible && timeCompatible;
170 const std::vector<Trackster> &tracksters,
172 std::vector<unsigned> &ts_mask,
173 float &energy_in_candidate,
179 energy_in_candidate += tracksters[ts].raw_energy();
183 const char *
label)
const {
188 LogDebug(
"LinkingAlgoByDirectionGeometric") <<
"All links found - " <<
label <<
"\n";
189 LogDebug(
"LinkingAlgoByDirectionGeometric") <<
"(seed can either be a track or trackster depending on the step)\n";
190 for (
unsigned i = 0;
i < resultCollection.size(); ++
i) {
191 LogDebug(
"LinkingAlgoByDirectionGeometric") <<
"seed " <<
i <<
" - tracksters : ";
192 const auto &
links = resultCollection[
i];
193 for (
unsigned j = 0;
j <
links.size(); ++
j) {
194 LogDebug(
"LinkingAlgoByDirectionGeometric") <<
j;
196 LogDebug(
"LinkingAlgoByDirectionGeometric") <<
"\n";
198 #endif // EDM_ML_DEBUG 205 std::pair<float, float> rMinMax =
hgcons_->
rangeR(zVal,
true);
208 std::pair<float, float> rMinMax_interface =
hgcons_->
rangeR(zVal_interface,
true);
210 for (
int iSide = 0; iSide < 2; ++iSide) {
211 float zSide = (iSide == 0) ? (-1. * zVal) : zVal;
218 zSide = (iSide == 0) ? (-1. * zVal_interface) : zVal_interface;
222 SimpleDiskBounds(rMinMax_interface.first, rMinMax_interface.second, zSide - 0.5, zSide + 0.5))
231 const std::vector<reco::Muon> &
muons,
233 std::vector<TICLCandidate> &resultLinked,
234 std::vector<TICLCandidate> &chargedHadronsFromTk) {
235 const auto &
tracks = *tkH;
236 const auto &tracksters = *tsH;
244 std::vector<std::pair<Vector, unsigned>> trackPColl;
245 std::vector<std::pair<Vector, unsigned>> tkPropIntColl;
246 std::vector<std::pair<Vector, unsigned>> tsPropIntColl;
247 std::vector<std::pair<Vector, unsigned>> tsHadPropIntColl;
248 trackPColl.reserve(
tracks.size());
249 tkPropIntColl.reserve(
tracks.size());
250 tsPropIntColl.reserve(tracksters.size());
251 tsHadPropIntColl.reserve(tracksters.size());
253 std::array<TICLLayerTile, 2> tracksterPropTiles = {};
254 std::array<TICLLayerTile, 2> tsPropIntTiles = {};
255 std::array<TICLLayerTile, 2> tsHadPropIntTiles = {};
258 auto isHadron = [&](
const Trackster &
t) ->
bool {
260 return (
std::abs(
t.barycenter().Z()) > boundary_z);
264 LogDebug(
"LinkingAlgoByDirectionGeometric") <<
"------- Geometric Linking ------- \n";
267 std::vector<unsigned> candidateTrackIds;
268 candidateTrackIds.reserve(
tracks.size());
269 for (
unsigned i = 0;
i <
tracks.size(); ++
i) {
277 LogDebug(
"LinkingAlgoByDirectionGeometric")
278 <<
"track " <<
i <<
" - eta " << tk.eta() <<
" phi " << tk.phi() <<
" time " << tkTime[
reco::TrackRef(tkH,
i)]
279 <<
" time qual " << tkTimeQual[
reco::TrackRef(tkH,
i)] <<
" muid " << muId <<
"\n";
285 candidateTrackIds.push_back(
i);
291 int iSide =
int(tk.eta() > 0);
295 if (tsos.isValid()) {
296 Vector trackP(tsos.globalPosition().x(), tsos.globalPosition().y(), tsos.globalPosition().z());
297 trackPColl.emplace_back(trackP,
i);
301 if (tsos_int.isValid()) {
302 Vector trackP(tsos_int.globalPosition().x(), tsos_int.globalPosition().y(), tsos_int.globalPosition().z());
303 tkPropIntColl.emplace_back(trackP,
i);
306 tkPropIntColl.shrink_to_fit();
307 trackPColl.shrink_to_fit();
308 candidateTrackIds.shrink_to_fit();
315 std::vector<Vector> tsAllProp;
316 std::vector<Vector> tsAllPropInt;
317 tsAllProp.reserve(tracksters.size());
318 tsAllPropInt.reserve(tracksters.size());
320 for (
unsigned i = 0;
i < tracksters.size(); ++
i) {
321 const auto &
t = tracksters[
i];
323 LogDebug(
"LinkingAlgoByDirectionGeometric")
324 <<
"trackster " <<
i <<
" - eta " <<
t.barycenter().eta() <<
" phi " <<
t.barycenter().phi() <<
" time " 325 <<
t.time() <<
" energy " <<
t.raw_energy() <<
"\n";
330 tsAllProp.emplace_back(tsP);
335 tsAllPropInt.emplace_back(tsP);
338 tsPropIntColl.emplace_back(tsP,
i);
340 tsHadPropIntTiles[(
t.barycenter().Z() > 0) ? 1 : 0].
fill(tsP.Eta(), tsP.Phi(),
i);
341 tsHadPropIntColl.emplace_back(tsP,
i);
344 tsPropIntColl.shrink_to_fit();
345 tsHadPropIntColl.shrink_to_fit();
350 std::vector<std::vector<unsigned>> tsNearTk(
tracks.size());
355 std::vector<std::vector<unsigned>> tsNearTkAtInt(
tracks.size());
361 std::vector<std::vector<unsigned>> tsNearAtInt(tracksters.size());
363 tsPropIntColl, tsHadPropIntTiles, tsAllPropInt,
del_ts_em_had_, tracksters.size(), tsNearAtInt);
367 std::vector<std::vector<unsigned>> tsHadNearAtInt(tracksters.size());
369 tsHadPropIntColl, tsHadPropIntTiles, tsAllPropInt,
del_ts_had_had_, tracksters.size(), tsHadNearAtInt);
373 dumpLinksFound(tsNearTkAtInt,
"track -> tracksters at lastLayerEE");
374 dumpLinksFound(tsNearAtInt,
"EM -> HAD tracksters at lastLayerEE");
375 dumpLinksFound(tsHadNearAtInt,
"HAD -> HAD tracksters at lastLayerEE");
376 #endif //EDM_ML_DEBUG 380 std::vector<TICLCandidate> chargedCandidates;
381 std::vector<unsigned int> chargedMask(tracksters.size(), 0);
382 for (
unsigned &
i : candidateTrackIds) {
383 if (tsNearTk[
i].
empty() && tsNearTkAtInt[
i].empty()) {
386 chargedHadronsFromTk.push_back(chargedHad);
391 float total_raw_energy = 0.;
394 auto track_time = tkTime[tkRef];
395 auto track_timeErr = tkTimeErr[tkRef];
396 auto track_timeQual = tkTimeQual[tkRef];
398 for (
const unsigned ts3_idx : tsNearTk[
i]) {
400 total_raw_energy,
tracks[
i], tracksters[ts3_idx], track_time, track_timeErr, track_timeQual)) {
401 recordTrackster(ts3_idx, tracksters, tsH, chargedMask, total_raw_energy, chargedCandidate);
403 for (
const unsigned ts2_idx : tsNearAtInt[ts3_idx]) {
405 total_raw_energy,
tracks[
i], tracksters[ts2_idx], track_time, track_timeErr, track_timeQual)) {
406 recordTrackster(ts2_idx, tracksters, tsH, chargedMask, total_raw_energy, chargedCandidate);
408 for (
const unsigned ts1_idx : tsHadNearAtInt[ts2_idx]) {
410 total_raw_energy,
tracks[
i], tracksters[ts1_idx], track_time, track_timeErr, track_timeQual)) {
411 recordTrackster(ts1_idx, tracksters, tsH, chargedMask, total_raw_energy, chargedCandidate);
415 for (
const unsigned ts1_idx : tsHadNearAtInt[ts3_idx]) {
417 total_raw_energy,
tracks[
i], tracksters[ts1_idx], track_time, track_timeErr, track_timeQual)) {
418 recordTrackster(ts1_idx, tracksters, tsH, chargedMask, total_raw_energy, chargedCandidate);
422 for (
const unsigned ts4_idx : tsNearTkAtInt[
i]) {
424 total_raw_energy,
tracks[
i], tracksters[ts4_idx], track_time, track_timeErr, track_timeQual)) {
425 recordTrackster(ts4_idx, tracksters, tsH, chargedMask, total_raw_energy, chargedCandidate);
427 for (
const unsigned ts2_idx : tsNearAtInt[ts4_idx]) {
429 total_raw_energy,
tracks[
i], tracksters[ts2_idx], track_time, track_timeErr, track_timeQual)) {
430 recordTrackster(ts2_idx, tracksters, tsH, chargedMask, total_raw_energy, chargedCandidate);
432 for (
const unsigned ts1_idx : tsHadNearAtInt[ts2_idx]) {
434 total_raw_energy,
tracks[
i], tracksters[ts1_idx], track_time, track_timeErr, track_timeQual)) {
435 recordTrackster(ts1_idx, tracksters, tsH, chargedMask, total_raw_energy, chargedCandidate);
439 for (
const unsigned ts1_idx : tsHadNearAtInt[ts4_idx]) {
441 total_raw_energy,
tracks[
i], tracksters[ts1_idx], track_time, track_timeErr, track_timeQual)) {
442 recordTrackster(ts1_idx, tracksters, tsH, chargedMask, total_raw_energy, chargedCandidate);
451 chargedCandidates.push_back(chargedCandidate);
455 chargedHadronsFromTk.push_back(chargedHad);
459 std::vector<TICLCandidate> neutralCandidates;
460 std::vector<int> neutralMask(tracksters.size(), 0);
461 for (
unsigned i = 0;
i < tracksters.size(); ++
i) {
466 if (tsNearAtInt[
i].
empty() && tsHadNearAtInt[
i].empty() && !neutralMask[
i]) {
469 neutralCandidates.push_back(neutralCandidate);
472 if (!neutralMask[
i]) {
476 for (
const unsigned ts2_idx : tsNearAtInt[
i]) {
477 if (chargedMask[ts2_idx])
479 if (!neutralMask[ts2_idx]) {
481 neutralMask[ts2_idx] = 1;
483 for (
const unsigned ts1_idx : tsHadNearAtInt[ts2_idx]) {
484 if (chargedMask[ts1_idx])
486 if (!neutralMask[ts1_idx]) {
488 neutralMask[ts1_idx] = 1;
492 for (
const unsigned ts1_idx : tsHadNearAtInt[
i]) {
493 if (chargedMask[ts1_idx])
495 if (!neutralMask[ts1_idx]) {
497 neutralMask[ts1_idx] = 1;
502 neutralCandidates.push_back(neutralCandidate);
506 resultLinked.insert(std::end(resultLinked), std::begin(neutralCandidates), std::end(neutralCandidates));
507 resultLinked.insert(std::end(resultLinked), std::begin(chargedCandidates), std::end(chargedCandidates));
513 "1.48 < abs(eta) < 3.0 && pt > 1. && quality(\"highPurity\") && " 514 "hitPattern().numberOfLostHits(\"MISSING_OUTER_HITS\") < 5");
515 desc.add<
double>(
"delta_tk_ts_layer1", 0.02);
516 desc.add<
double>(
"delta_tk_ts_interface", 0.03);
517 desc.add<
double>(
"delta_ts_em_had", 0.03);
518 desc.add<
double>(
"delta_ts_had_had", 0.03);
519 desc.add<
double>(
"track_time_quality_threshold", 0.5);
double waferZ(int layer, bool reco) const
static DiskPointer build(Args &&... args)
static int muAssocToTrack(const reco::TrackRef &trackref, const reco::MuonCollection &muons)
void linkTracksters(const edm::Handle< std::vector< reco::Track >>, const edm::ValueMap< float > &, const edm::ValueMap< float > &, const edm::ValueMap< float > &, const std::vector< reco::Muon > &, const edm::Handle< std::vector< Trackster >>, std::vector< TICLCandidate > &, std::vector< TICLCandidate > &) override
math::XYZVector propagateTrackster(const Trackster &t, const unsigned idx, float zVal, std::array< TICLLayerTile, 2 > &tracksterTiles)
static constexpr int nPhiBins
bool timeAndEnergyCompatible(float &total_raw_energy, const reco::Track &track, const Trackster &trackster, const float &tkTime, const float &tkTimeErr, const float &tkTimeQual)
static constexpr float maxEta
const float del_tk_ts_int_
edm::ESHandle< Propagator > propagator_
hgcal::RecHitTools rhtools_
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
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
XYZVectorD XYZVector
spatial vector with cartesian internal representation
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]
~LinkingAlgoByDirectionGeometric() override
const std::vector< edm::Ptr< ticl::Trackster > > tracksters() const
void setTrackPtr(const edm::Ptr< reco::Track > &trackPtr)