219 if (!hTracks->empty())
234 if (hOpticalFunctions->empty()) {
235 edm::LogInfo(
"CTPPSProtonProducer") <<
"No optical functions available, reconstruction disabled.";
249 std::ostringstream ssLog;
251 ssLog <<
"* input tracks:" << std::endl;
254 std::map<unsigned int, std::vector<unsigned int>> trackingSelection, timingSelection;
256 for (
unsigned int idx = 0;
idx < hTracks->size(); ++
idx)
258 const auto& tr = hTracks->at(
idx);
268 <<
"[" <<
idx <<
"] " 269 << tr.getRPId() <<
" (" << (
rpId.arm()*100 +
rpId.station()*10 +
rpId.rp()) <<
"): " 270 <<
"x=" << tr.getX() <<
" +- " << tr.getXUnc() <<
" mm, " 271 <<
"y=" << tr.getY() <<
" +- " << tr.getYUnc() <<
" mm" << std::endl;
276 trackingSelection[
rpId.arm()].push_back(
idx);
278 timingSelection[
rpId.arm()].push_back(
idx);
282 for (
const auto &arm_it : trackingSelection)
284 const auto &indices = arm_it.second;
289 std::map<unsigned int, reco::ForwardProton> singleRPResultsIndexed;
292 for (
const auto &
idx : indices)
295 ssLog << std::endl <<
"* reconstruction from track " <<
idx << std::endl;
304 std::set<unsigned int>
rpIds;
305 for (
const auto &
idx : indices)
306 rpIds.insert(hTracks->at(
idx).getRPId());
312 std::vector<std::pair<unsigned int, unsigned int>> idx_pairs;
313 std::map<unsigned int, unsigned int> idx_pair_multiplicity;
314 for (
const auto &
i : indices)
316 for (
const auto &j : indices)
321 const auto &tr_i = hTracks->at(
i);
322 const auto &tr_j = hTracks->at(j);
324 const auto &pr_i = singleRPResultsIndexed[
i];
325 const auto &pr_j = singleRPResultsIndexed[j];
327 if (tr_i.getRPId() == tr_j.getRPId())
332 if (ac.x_cut_apply &&
std::abs(tr_i.getX() - tr_j.getX()) > ac.x_cut_value)
334 if (ac.y_cut_apply &&
std::abs(tr_i.getY() - tr_j.getY()) > ac.y_cut_value)
336 if (ac.xi_cut_apply &&
std::abs(pr_i.xi() - pr_j.xi()) > ac.xi_cut_value)
338 if (ac.th_y_cut_apply &&
std::abs(pr_i.thetaY() - pr_j.thetaY()) > ac.th_y_cut_value)
344 idx_pairs.emplace_back(
i, j);
345 idx_pair_multiplicity[
i]++;
346 idx_pair_multiplicity[j]++;
351 std::map<unsigned int, unsigned int> timing_RP_track_multiplicity;
352 for (
const auto &ti : timingSelection[arm_it.first])
354 const auto &tr = hTracks->at(ti);
355 timing_RP_track_multiplicity[tr.getRPId()]++;
359 std::map<unsigned int, std::vector<unsigned int>> matched_timing_track_indices;
360 std::map<unsigned int, unsigned int> matched_timing_track_multiplicity;
361 for (
unsigned int pr_idx = 0; pr_idx < idx_pairs.size(); ++pr_idx)
363 const auto &
i = idx_pairs[pr_idx].first;
364 const auto &j = idx_pairs[pr_idx].second;
367 if (idx_pair_multiplicity[
i] > 1 || idx_pair_multiplicity[j] > 1)
370 const auto &tr_i = hTracks->at(
i);
371 const auto &tr_j = hTracks->at(j);
376 for (
const auto &ti : timingSelection[arm_it.first])
378 const auto &tr_ti = hTracks->at(ti);
386 const double f_i = (z_ti - z_j) / (z_i - z_j), f_j = (z_i - z_ti) / (z_i - z_j);
387 const double x_inter = f_i * tr_i.getX() + f_j * tr_j.getX();
388 const double x_inter_unc_sq = f_i*f_i * tr_i.getXUnc()*tr_i.getXUnc() + f_j*f_j * tr_j.getXUnc()*tr_j.getXUnc();
390 const double de_x = tr_ti.getX() - x_inter;
391 const double de_x_unc =
sqrt(tr_ti.getXUnc()*tr_ti.getXUnc() + x_inter_unc_sq);
392 const double r = (de_x_unc > 0.) ? de_x / de_x_unc : 1E100;
394 const bool matching = (ac.ti_tr_min < r && r < ac.ti_tr_max);
397 ssLog <<
"ti=" << ti <<
", i=" <<
i <<
", j=" << j
398 <<
" | z_ti=" << z_ti <<
", z_i=" << z_i <<
", z_j=" << z_j
399 <<
" | x_ti=" << tr_ti.getX() <<
", x_inter=" << x_inter <<
", de_x=" << de_x <<
", de_x_unc=" << de_x_unc
400 <<
", matching=" << matching << std::endl;
405 matched_timing_track_indices[pr_idx].push_back(ti);
406 matched_timing_track_multiplicity[ti]++;
411 for (
unsigned int pr_idx = 0; pr_idx < idx_pairs.size(); ++pr_idx)
413 const auto &
i = idx_pairs[pr_idx].first;
414 const auto &j = idx_pairs[pr_idx].second;
417 if (idx_pair_multiplicity[
i] > 1 || idx_pair_multiplicity[j] > 1)
421 ssLog << std::endl <<
"* reconstruction from tracking-RP tracks: " <<
i <<
", " << j <<
" and timing-RP tracks: ";
431 double sw=0., swt=0.;
432 for (
const auto &ti : matched_timing_track_indices[pr_idx])
435 if (matched_timing_track_multiplicity[ti] > 1)
443 const auto &tr = hTracks->at(ti);
444 const double t_unc = tr.getTimeUnc();
445 const double w = (t_unc > 0.) ? 1./t_unc/t_unc : 1.;
447 swt += w * tr.getTime();
450 float time = 0., time_unc = 0.;
454 time_unc = 1. /
sqrt(sw);
458 ssLog << std::endl <<
" time = " << time <<
" +- " << time_unc << std::endl;
468 pOutMultiRP->emplace_back(proton);
473 for (
const auto &
p : singleRPResultsIndexed)
474 pOutSingleRP->emplace_back(
std::move(
p.second));
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
std::string lhcInfoLabel_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
reco::ForwardProton reconstructFromSingleRP(const CTPPSLocalTrackLiteRef &track, const LHCInfo &lhcInfo, std::ostream &os) const
run proton reconstruction using single-RP strategy
bool doMultiRPReconstruction_
unsigned int max_n_timing_tracks_
Event setup record containing the real (actual) geometry information.
void init(const LHCInterpolatedOpticalFunctionsSetCollection &opticalFunctions)
void setTimeError(float time_err)
reco::ForwardProton reconstructFromMultiRP(const CTPPSLocalTrackLiteRefVector &tracks, const LHCInfo &lhcInfo, std::ostream &os) const
run proton reconstruction using multiple-RP strategy
edm::ESWatcher< CTPPSInterpolatedOpticsRcd > opticsWatcher_
Abs< T >::type abs(const T &t)
edm::Ref< CTPPSLocalTrackLiteCollection > CTPPSLocalTrackLiteRef
Persistent reference to a CTPPSLocalTrackLite.
std::map< unsigned int, AssociationCuts > association_cuts_
CLHEP::Hep3Vector getRPTranslation(unsigned int id) const
bool check(const edm::EventSetup &iSetup)
Base class for CTPPS detector IDs.
ProtonReconstructionAlgorithm algorithm_
void push_back(value_type const &ref)
Add a Ref<C, T> to the RefVector.
std::vector< ForwardProton > ForwardProtonCollection
Collection of ForwardProton objects.
void setContributingLocalTracks(const CTPPSLocalTrackLiteRefVector &v)
store the list of RP tracks that contributed to this global track
std::string singleRPReconstructionLabel_
std::string multiRPReconstructionLabel_
bool doSingleRPReconstruction_
edm::EDGetTokenT< CTPPSLocalTrackLiteCollection > tracksToken_