CMS 3D CMS Logo

TracksToTrajectories.cc
Go to the documentation of this file.
4 
11 
14 
18 
27 // In principle this should be anonymous namespace, but then
28 // DEFINE_FWK_MODULE() will yield compilation warnings, so using
29 // (hopefully) unique namespace instead.
30 // The point of the namespace is to not to pollute the global
31 // namespace (and symbol space).
33  struct Count {
35  //Using mutable since we want to update the value.
36  mutable std::atomic<int> theNTracks;
37  mutable std::atomic<int> theNFailures;
38  };
39 } // namespace tracksToTrajectories
40 using namespace tracksToTrajectories;
41 
42 class TracksToTrajectories : public edm::stream::EDProducer<edm::GlobalCache<Count>> {
43 public:
46 
48  ~TracksToTrajectories() override;
49 
50  static std::unique_ptr<Count> initializeGlobalCache(edm::ParameterSet const&) { return std::make_unique<Count>(); }
51 
52  // Operations
53  static void globalEndJob(Count const* iCount);
54 
56  void produce(edm::Event&, const edm::EventSetup&) override;
57 
58 private:
60  std::unique_ptr<TrackTransformerBase> theTrackTransformer;
61 };
62 
63 using namespace std;
64 using namespace edm;
65 
68  theTracksToken = consumes<reco::TrackCollection>(parameterSet.getParameter<InputTag>("Tracks"));
69 
70  ParameterSet trackTransformerParam = parameterSet.getParameter<ParameterSet>("TrackTransformer");
71 
72  string type = parameterSet.getParameter<string>("Type");
73 
74  if (type == "Default")
75  theTrackTransformer = std::make_unique<TrackTransformer>(trackTransformerParam);
76  else if (type == "GlobalCosmicMuonsForAlignment")
77  theTrackTransformer = std::make_unique<TrackTransformerForGlobalCosmicMuons>(trackTransformerParam);
78  else if (type == "CosmicMuonsForAlignment")
79  theTrackTransformer = std::make_unique<TrackTransformerForCosmicMuons>(trackTransformerParam);
80  else {
81  throw cms::Exception("TracksToTrajectories")
82  << "The selected algorithm does not exist"
83  << "\n"
84  << "Possible choices are:"
85  << "\n"
86  << "Type = [Default, GlobalCosmicMuonsForAlignment, CosmicMuonsForAlignment]";
87  }
88 
89  produces<vector<Trajectory>>("Refitted");
90  produces<TrajTrackAssociationCollection>("Refitted");
91 }
92 
95 
97  constexpr char metname[] = "Reco|TrackingTools|TracksToTrajectories";
98 
99  auto theNFailures = iCount->theNFailures.load();
100  auto theNTracks = iCount->theNTracks.load();
101 
102  if (theNFailures != 0)
103  LogWarning(metname) << "During the refit there were " << theNFailures << " out of " << theNTracks
104  << " tracks, i.e. failure rate is: " << double(theNFailures) / theNTracks;
105  else {
106  LogTrace(metname) << "Refit of the tracks done without any failure";
107  }
108 }
109 
112 #ifdef EDM_ML_DEBUG
113  constexpr char metname[] = "Reco|TrackingTools|TracksToTrajectories";
114 #endif
115 
116  theTrackTransformer->setServices(setup);
117 
118  // Collection of Trajectory
119  auto trajectoryCollection = std::make_unique<vector<Trajectory>>();
120 
121  // Get the reference
122  RefProd<vector<Trajectory>> trajectoryCollectionRefProd = event.getRefBeforePut<vector<Trajectory>>("Refitted");
123 
124  // Get the RecTrack collection from the event
126  event.getByToken(theTracksToken, tracks);
127 
128  // Association map between Trajectory and Track
129  auto trajTrackMap = std::make_unique<TrajTrackAssociationCollection>(trajectoryCollectionRefProd, tracks);
130 
131  Ref<vector<Trajectory>>::key_type trajectoryIndex = 0;
132  reco::TrackRef::key_type trackIndex = 0;
133 
134  // Loop over the Rec tracks
135  for (auto const& newTrack : *tracks) {
136  ++(globalCache()->theNTracks);
137 
138  auto const& trajectoriesSM = theTrackTransformer->transform(newTrack);
139 
140  if (!trajectoriesSM.empty()) {
141  // Load the trajectory in the Trajectory Container
142  trajectoryCollection->push_back(trajectoriesSM.front());
143 
144  // Make the association between the Trajectory and the original Track
145  trajTrackMap->insert(Ref<vector<Trajectory>>(trajectoryCollectionRefProd, trajectoryIndex++),
146  reco::TrackRef(tracks, trackIndex++));
147  } else {
148  LogTrace(metname) << "Error in the Track refitting. This should not happen";
149  ++(globalCache()->theNFailures);
150  }
151  }
152  LogTrace(metname) << "Load the Trajectory Collection";
153  event.put(move(trajectoryCollection), "Refitted");
154  event.put(move(trajTrackMap), "Refitted");
155 }
156 
edm::RefProd
Definition: EDProductfwd.h:25
Handle.h
PDWG_EXOHSCP_cff.tracks
tracks
Definition: PDWG_EXOHSCP_cff.py:28
MessageLogger.h
edm::EDGetTokenT< reco::TrackCollection >
edm
HLT enums.
Definition: AlignableModifier.h:19
TracksToTrajectories::theTrackTransformer
std::unique_ptr< TrackTransformerBase > theTrackTransformer
Definition: TracksToTrajectories.cc:60
tracksToTrajectories
Definition: TracksToTrajectories.cc:32
EDProducer.h
tracksToTrajectories::Count
Definition: TracksToTrajectories.cc:33
TracksToTrajectories::globalEndJob
static void globalEndJob(Count const *iCount)
Definition: TracksToTrajectories.cc:96
edm::Handle< reco::TrackCollection >
TracksToTrajectories::initializeGlobalCache
static std::unique_ptr< Count > initializeGlobalCache(edm::ParameterSet const &)
Definition: TracksToTrajectories.cc:50
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
edm::Ref
Definition: AssociativeIterator.h:58
TrackTransformerForGlobalCosmicMuons.h
MakerMacros.h
Track.h
TrackFwd.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
TrackTransformerForCosmicMuons.h
TracksToTrajectories::theTracksToken
edm::EDGetTokenT< reco::TrackCollection > theTracksToken
Definition: TracksToTrajectories.cc:59
TrajTrackAssociation.h
edm::LogWarning
Definition: MessageLogger.h:141
edm::ParameterSet
Definition: ParameterSet.h:36
TracksToTrajectories::TracksToTrajectories
TracksToTrajectories(const edm::ParameterSet &, const Count *)
Constructor.
Definition: TracksToTrajectories.cc:67
Event.h
tracksToTrajectories::Count::theNFailures
std::atomic< int > theNFailures
Definition: TracksToTrajectories.cc:37
edm::stream::EDProducer
Definition: EDProducer.h:38
TrackTransformer.h
edm::EventSetup
Definition: EventSetup.h:57
tracksToTrajectories::Count::Count
Count()
Definition: TracksToTrajectories.cc:34
edm::Ref< TrackCollection >::key_type
std::remove_cv< typename std::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:164
InputTag.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Trajectory.h
type
type
Definition: HCALResponse.h:21
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
TracksToTrajectories::produce
void produce(edm::Event &, const edm::EventSetup &) override
Convert a reco::TrackCollection into std::vector<Trajectory>
Definition: TracksToTrajectories.cc:111
TracksToTrajectories::~TracksToTrajectories
~TracksToTrajectories() override
Destructor.
Definition: TracksToTrajectories.cc:94
Exception
Definition: hltDiff.cc:246
edm::parameterSet
ParameterSet const & parameterSet(Provenance const &provenance, ProcessHistory const &history)
Definition: Provenance.cc:11
EventSetup.h
TracksToTrajectories
Definition: TracksToTrajectories.cc:42
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
ParameterSet.h
tracksToTrajectories::Count::theNTracks
std::atomic< int > theNTracks
Definition: TracksToTrajectories.cc:36
event
Definition: event.py:1
edm::Event
Definition: Event.h:73
edm::InputTag
Definition: InputTag.h:15
metname
const std::string metname
Definition: MuonSeedOrcaPatternRecognition.cc:43