CMS 3D CMS Logo

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