71 void assignTimeToCandidates(std::vector<TICLCandidate> &resultCandidates,
106 const float tkEnergyCut_ = 2.0f;
112 static constexpr float c_light_ = CLHEP::c_light * CLHEP::ns / CLHEP::cm;
122 useMTDTiming_(ps.getParameter<
bool>(
"useMTDTiming")),
123 useTimingAverage_(ps.getParameter<
bool>(
"useTimingAverage")),
124 timingQualityThreshold_(ps.getParameter<double>(
"timingQualityThreshold")),
127 detector_(ps.getParameter<
std::
string>(
"detector")),
128 propName_(ps.getParameter<
std::
string>(
"propagator")),
131 trackingGeometry_token_(
133 cutTk_(ps.getParameter<
std::
string>(
"cutTk")) {
135 for (
auto const &
tag : ps.
getParameter<std::vector<edm::InputTag>>(
"egamma_tracksters_collections")) {
140 for (
auto const &
tag : ps.
getParameter<std::vector<edm::InputTag>>(
"egamma_tracksterlinks_collections")) {
149 for (
auto const &
tag : ps.
getParameter<std::vector<edm::InputTag>>(
"general_tracksters_collections")) {
153 for (
auto const &
tag : ps.
getParameter<std::vector<edm::InputTag>>(
"general_tracksterlinks_collections")) {
161 for (
auto const &
tag : ps.
getParameter<std::vector<edm::InputTag>>(
"original_masks")) {
165 std::string detectorName_ = (
detector_ ==
"HFNose") ?
"HGCalHFNoseSensitive" :
"HGCalEESensitive";
167 esConsumes<HGCalDDDConstants, IdealGeometryRecord, edm::Transition::BeginRun>(
edm::ESInputTag(
"", detectorName_));
172 produces<std::vector<TICLCandidate>>();
175 produces<std::vector<Trackster>>();
198 const edm::Handle<std::vector<reco::Muon>> &muons_h,
200 const float tkEnergyCut_,
201 std::vector<bool> &maskTracks) {
202 auto const &
tracks = *tkH;
203 for (
unsigned i = 0;
i <
tracks.size(); ++
i) {
211 if (!cutTk_((tk))
or (muId != -1 and
PFMuonAlgo::isMuon(muonref) and not(*muons_h)[muId].isTrackerMuon())) {
212 maskTracks[
i] =
false;
218 maskTracks[
i] =
false;
223 maskTracks[
i] =
true;
228 auto resultTracksters = std::make_unique<std::vector<Trackster>>();
229 auto resultTrackstersMerged = std::make_unique<std::vector<Trackster>>();
230 auto linkedResultTracksters = std::make_unique<std::vector<std::vector<unsigned int>>>();
239 const auto &
tracks = *tracks_h;
245 inputTimingView = (*inputTiming_h).const_view();
253 std::vector<float> original_global_mask(
layerClusters.size(), 1.f);
256 for (
unsigned int j = 0;
j < tmp_mask.size(); ++
j) {
257 original_global_mask[
j] *= tmp_mask[
j];
261 auto resultMask = std::make_unique<std::vector<float>>(original_global_mask);
268 generalTrackstersManager.addVector(*general_tracksters_h[
i]);
271 std::vector<edm::Handle<std::vector<std::vector<unsigned>>>> general_tracksterlinks_h(
273 std::vector<std::vector<unsigned>> generalTracksterLinksGlobalId;
276 for (
unsigned int j = 0;
j < general_tracksterlinks_h[
i]->size(); ++
j) {
277 generalTracksterLinksGlobalId.emplace_back();
278 auto &links_vector = generalTracksterLinksGlobalId.back();
279 links_vector.resize((*general_tracksterlinks_h[
i])[
j].
size());
280 for (
unsigned int k = 0;
k < links_vector.size(); ++
k) {
281 links_vector[
k] = generalTrackstersManager.getGlobalIndex(
i, (*general_tracksterlinks_h[
i])[
j][
k]);
286 std::vector<bool> maskTracks;
287 maskTracks.resize(
tracks.size());
294 generalTrackstersManager,
295 generalTracksterLinksGlobalId,
299 auto resultCandidates = std::make_unique<std::vector<TICLCandidate>>();
300 std::vector<int> trackstersInTrackIndices(
tracks.size(), -1);
315 std::vector<bool> maskTracksters(resultTracksters->size(),
true);
318 for (
size_t iTrack = 0; iTrack <
tracks.size(); iTrack++) {
319 if (maskTracks[iTrack]) {
320 auto const tracksterId = trackstersInTrackIndices[iTrack];
322 if (tracksterId != -1 and !maskTracksters.empty()) {
325 resultCandidates->push_back(chargedCandidate);
326 maskTracksters[tracksterId] =
false;
334 if (muonRef.
isNonnull() and muonRef->isGlobalMuon()) {
336 chargedCandidate.
setPdgId(13 * trackPtr.get()->charge());
338 resultCandidates->push_back(chargedCandidate);
344 for (
size_t iTrackster = 0; iTrackster < maskTracksters.size(); iTrackster++) {
345 if (maskTracksters[iTrackster]) {
349 resultCandidates->push_back(neutralCandidate);
364 float pathlength =
propagator->propagateWithPath(stateAtBeamspot, surf_inn.surface()).
second;
367 const auto &t_inn_out =
propagator->propagateWithPath(fts_inn, surf_out.surface());
369 if (t_inn_out.first.isValid()) {
370 pathlength += t_inn_out.second;
372 std::pair<float, float> rMinMax =
hgcons_->
rangeR(zVal,
true);
375 float zSide = (iSide == 0) ? (-1. * zVal) : zVal;
376 const auto &disk = std::make_unique<GeomDet>(
381 const auto &tsos =
propagator->propagateWithPath(fts_out, disk->surface());
383 if (tsos.first.isValid()) {
384 pathlength += tsos.second;
391 <<
"Not able to use the track to compute the path length. A straight line will be used instead.";
401 template <
typename F>
406 for (
auto &
cand : resultCandidates) {
409 float invTimeErr = 0.f;
410 float timeErr = -1.f;
412 for (
const auto &tr :
cand.tracksters()) {
413 if (tr->timeError() > 0) {
414 const auto invTimeESq =
pow(tr->timeError(), -2);
415 const auto x = tr->barycenter().X();
416 const auto y = tr->barycenter().Y();
417 const auto z = tr->barycenter().Z();
419 if (
cand.trackPtr().get() !=
nullptr) {
421 if (
useMTDTiming_ and inputTimingView.timeErr()[trackIndex] > 0) {
422 const auto xMtd = inputTimingView.posInMTD_x()[trackIndex];
423 const auto yMtd = inputTimingView.posInMTD_y()[trackIndex];
424 const auto zMtd = inputTimingView.posInMTD_z()[trackIndex];
426 beta = inputTimingView.beta()[trackIndex];
427 path =
std::sqrt((
x - xMtd) * (
x - xMtd) + (
y - yMtd) * (
y - yMtd) + (
z - zMtd) * (
z - zMtd)) +
428 inputTimingView.pathLength()[trackIndex];
430 float pathLength =
func(*(
cand.trackPtr().get()),
z);
437 invTimeErr += invTimeESq;
440 if (invTimeErr > 0) {
443 timeErr =
sqrt(1.
f / invTimeErr);
454 const auto timeHGC =
cand.time();
455 const auto timeEHGC =
cand.timeError();
456 const auto timeMTD = inputTimingView.time0()[trackIndex];
457 const auto timeEMTD = inputTimingView.time0Err()[trackIndex];
461 const auto invTimeESqHGC =
pow(timeEHGC, -2);
462 const auto invTimeESqMTD =
pow(timeEMTD, -2);
463 timeErr = 1.f / (invTimeESqHGC + invTimeESqMTD);
464 time = (timeHGC * invTimeESqHGC + timeMTD * invTimeESqMTD) * timeErr;
465 timeErr =
sqrt(timeErr);
466 }
else if (timeEMTD > 0) {
472 cand.setMTDTime(inputTimingView.time()[trackIndex], inputTimingView.timeErr()[trackIndex]);
482 desc.add<std::vector<edm::InputTag>>(
"egamma_tracksters_collections", {
edm::InputTag(
"ticlTracksterLinks")});
483 desc.add<std::vector<edm::InputTag>>(
"egamma_tracksterlinks_collections", {
edm::InputTag(
"ticlTracksterLinks")});
484 desc.add<std::vector<edm::InputTag>>(
"general_tracksters_collections", {
edm::InputTag(
"ticlTracksterLinks")});
485 desc.add<std::vector<edm::InputTag>>(
"general_tracksterlinks_collections", {
edm::InputTag(
"ticlTracksterLinks")});
486 desc.add<std::vector<edm::InputTag>>(
"original_masks",
487 {
edm::InputTag(
"hgcalMergeLayerClusters",
"InitialLayerClustersMask")});
495 desc.add<
bool>(
"useMTDTiming",
true);
496 desc.add<
bool>(
"useTimingAverage",
true);
497 desc.add<
double>(
"timingQualityThreshold", 0.5);
499 "1.48 < abs(eta) < 3.0 && pt > 1. && quality(\"highPurity\") && " 500 "hitPattern().numberOfLostHits(\"MISSING_OUTER_HITS\") < 5");
501 descriptions.
add(
"ticlCandidateProducer",
desc);
static DiskPointer build(Args &&... args)
static int muAssocToTrack(const reco::TrackRef &trackref, const reco::MuonCollection &muons)
TICLCandidateProducer(const edm::ParameterSet &ps)
T getParameter(std::string const &) const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
bool get(ProductID const &oid, Handle< PROD > &result) const
void beginRun(edm::Run const &iEvent, edm::EventSetup const &es) override
const StringCutObjectSelector< reco::Track > cutTk_
static bool isMuon(const reco::PFBlockElement &elt)
std::once_flag initializeGeometry_
const edm::EDGetTokenT< edm::ValueMap< std::pair< float, float > > > clustersTime_token_
void assignTimeToCandidates(std::vector< TICLCandidate > &resultCandidates, edm::Handle< std::vector< reco::Track >> track_h, MtdHostCollection::ConstView &inputTimingView, F func) const
Global3DPoint GlobalPoint
ParameterDescriptionNode * addNode(ParameterDescriptionNode const &node)
bool isNonnull() const
Checks for non-null.
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::ESGetToken< MagneticField, IdealMagneticFieldRecord > bfield_token_
const edm::EDGetTokenT< std::vector< reco::Track > > tracks_token_
static std::string const input
const float timingQualityThreshold_
edm::ESHandle< Propagator > propagator_
U second(std::pair< T, U > const &p)
~TICLCandidateProducer() override
const edm::ESGetToken< Propagator, TrackingComponentsRecord > propagator_token_
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
const bool useTimingAverage_
edm::ESHandle< GlobalTrackingGeometry > trackingGeometry_
T const * product() const
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
edm::Ref< MuonCollection > MuonRef
presistent reference to a Muon
#define DEFINE_FWK_MODULE(type)
edm::ESGetToken< HGCalDDDConstants, IdealGeometryRecord > hdc_token_
void produce(edm::Event &, const edm::EventSetup &) override
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
std::vector< edm::EDGetTokenT< std::vector< Trackster > > > general_tracksters_tokens_
std::pair< double, double > rangeR(double z, bool reco) const
hgcal::RecHitTools rhtools_
typename Layout::ConstView ConstView
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
std::vector< edm::EDGetTokenT< std::vector< Trackster > > > egamma_tracksters_tokens_
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
void add(std::string const &label, ParameterSetDescription const &psetDescription)
const std::string detector_
const edm::ESGetToken< GlobalTrackingGeometry, GlobalTrackingGeometryRecord > trackingGeometry_token_
const edm::EDGetTokenT< std::vector< reco::CaloCluster > > clusters_token_
const HGCalDDDConstants * hgcons_
const std::string propName_
static constexpr float c_light_
std::vector< edm::EDGetTokenT< std::vector< std::vector< unsigned > > > > general_tracksterlinks_tokens_
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > geometry_token_
edm::EDGetTokenT< MtdHostCollection > inputTimingToken_
std::vector< edm::EDGetTokenT< std::vector< float > > > original_masks_tokens_
std::unique_ptr< TICLInterpretationAlgoBase< reco::Track > > generalInterpretationAlgo_
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
edm::ESHandle< MagneticField > bfield_
static constexpr float timeRes
void setPdgId(int pdgId) final
std::vector< edm::EDGetTokenT< std::vector< std::vector< unsigned > > > > egamma_tracksterlinks_tokens_
void filterTracks(edm::Handle< std::vector< reco::Track >> tkH, const edm::Handle< std::vector< reco::Muon >> &muons_h, const StringCutObjectSelector< reco::Track > cutTk_, const float tkEnergyCut_, std::vector< bool > &maskTracks)
Power< A, B >::type pow(const A &a, const B &b)
const edm::EDGetTokenT< std::vector< reco::Muon > > muons_token_
Global3DVector GlobalVector