CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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).
32 namespace tracksToTrajectories {
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 }
40 using namespace tracksToTrajectories;
41 
42 class TracksToTrajectories: public edm::stream::EDProducer<edm::GlobalCache<Count>> {
43 public:
44 
47 
49  virtual ~TracksToTrajectories();
50 
51  static std::unique_ptr<Count> initializeGlobalCache(edm::ParameterSet const&) {
52  return std::make_unique<Count>();
53  }
54 
55  // Operations
56  static void globalEndJob(Count const* iCount);
57 
59  virtual void produce(edm::Event&, const edm::EventSetup&) override;
60 
61  private:
62 
64  std::unique_ptr<TrackTransformerBase> theTrackTransformer;
65 };
66 
67 
68 using namespace std;
69 using namespace edm;
70 
73 
74  theTracksToken = consumes<reco::TrackCollection>(parameterSet.getParameter<InputTag>("Tracks"));
75 
76  ParameterSet trackTransformerParam = parameterSet.getParameter<ParameterSet>("TrackTransformer");
77 
78  string type = parameterSet.getParameter<string>("Type");
79 
80  if(type == "Default") theTrackTransformer = std::make_unique<TrackTransformer>(trackTransformerParam);
81  else if(type == "GlobalCosmicMuonsForAlignment") theTrackTransformer = std::make_unique<TrackTransformerForGlobalCosmicMuons>(trackTransformerParam);
82  else if(type == "CosmicMuonsForAlignment") theTrackTransformer = std::make_unique<TrackTransformerForCosmicMuons>(trackTransformerParam);
83  else{
84  throw cms::Exception("TracksToTrajectories")
85  <<"The selected algorithm does not exist"
86  << "\n"
87  << "Possible choices are:"
88  << "\n"
89  << "Type = [Default, GlobalCosmicMuonsForAlignment, CosmicMuonsForAlignment]";
90  }
91 
92  produces<vector<Trajectory> >("Refitted");
93  produces<TrajTrackAssociationCollection>("Refitted");
94 }
95 
96 
99 
101  constexpr char metname[] = "Reco|TrackingTools|TracksToTrajectories";
102 
103  auto theNFailures = iCount->theNFailures.load();
104  auto theNTracks = iCount->theNTracks.load();
105 
106  if(theNFailures!=0)
107  LogWarning(metname) << "During the refit there were "
108  << theNFailures << " out of " << theNTracks << " tracks, i.e. failure rate is: " << double(theNFailures)/theNTracks;
109  else{
110  LogTrace(metname) << "Refit of the tracks done without any failure";
111  }
112 }
113 
114 
117 #ifdef EDM_ML_DEBUG
118  constexpr char metname[] = "Reco|TrackingTools|TracksToTrajectories";
119 #endif
120 
121  theTrackTransformer->setServices(setup);
122 
123  // Collection of Trajectory
124  unique_ptr<vector<Trajectory> > trajectoryCollection(new vector<Trajectory>);
125 
126  // Get the reference
127  RefProd<vector<Trajectory> > trajectoryCollectionRefProd
128  = event.getRefBeforePut<vector<Trajectory> >("Refitted");
129 
130  // Get the RecTrack collection from the event
132  event.getByToken(theTracksToken, tracks);
133 
134  // Association map between Trajectory and Track
135  unique_ptr<TrajTrackAssociationCollection> trajTrackMap(new TrajTrackAssociationCollection(trajectoryCollectionRefProd, tracks));
136 
137  Ref<vector<Trajectory> >::key_type trajectoryIndex = 0;
138  reco::TrackRef::key_type trackIndex = 0;
139 
140  // Loop over the Rec tracks
141  for (reco::TrackCollection::const_iterator newTrack = tracks->begin();
142  newTrack != tracks->end(); ++newTrack) {
143 
144  ++(globalCache()->theNTracks);
145 
146  vector<Trajectory> trajectoriesSM = theTrackTransformer->transform(*newTrack);
147 
148  if(!trajectoriesSM.empty()){
149  // Load the trajectory in the Trajectory Container
150  trajectoryCollection->push_back(trajectoriesSM.front());
151 
152  // Make the association between the Trajectory and the original Track
153  trajTrackMap->insert(Ref<vector<Trajectory> >(trajectoryCollectionRefProd,trajectoryIndex++),
154  reco::TrackRef(tracks,trackIndex++));
155  }
156  else{
157  LogTrace(metname) << "Error in the Track refitting. This should not happen";
158  ++(globalCache()->theNFailures);
159  }
160  }
161  LogTrace(metname)<<"Load the Trajectory Collection";
162  event.put(move(trajectoryCollection),"Refitted");
163  event.put(move(trajTrackMap),"Refitted");
164 }
165 
type
Definition: HCALResponse.h:21
T getParameter(std::string const &) const
virtual ~TracksToTrajectories()
Destructor.
const std::string metname
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< reco::TrackCollection > theTracksToken
#define constexpr
TracksToTrajectories(const edm::ParameterSet &, const Count *)
Constructor.
def move
Definition: eostools.py:510
std::unique_ptr< TrackTransformerBase > theTrackTransformer
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > > TrajTrackAssociationCollection
#define LogTrace(id)
tuple tracks
Definition: testEve_cfg.py:39
virtual void produce(edm::Event &, const edm::EventSetup &) override
Convert a reco::TrackCollection into std::vector&lt;Trajectory&gt;
static void globalEndJob(Count const *iCount)
static std::unique_ptr< Count > initializeGlobalCache(edm::ParameterSet const &)
ParameterSet const & parameterSet(Provenance const &provenance)
Definition: Provenance.cc:11
boost::remove_cv< typename boost::remove_reference< argument_type >::type >::type key_type
Definition: Ref.h:168