CMS 3D CMS Logo

QualityFilter.cc
Go to the documentation of this file.
1 #include <memory>
2 
3 // user include files
10 
12  public:
13  explicit QualityFilter(const edm::ParameterSet&);
14  ~QualityFilter() override;
15 
16  private:
17  void produce(edm::Event&, const edm::EventSetup&) override;
18  virtual void endJob() ;
19 
20  // ----------member data ---------------------------
21  private:
22 
26  bool copyExtras_;
27 };
28 
35 
36 //
37 // class decleration
38 //
39 
40 using namespace edm;
41 using namespace reco;
42 using namespace std;
43 
44 
46 {
47  copyExtras_ = iConfig.getUntrackedParameter<bool>("copyExtras", false);
48 
49  produces<reco::TrackCollection>();
50  if (copyExtras_) {
51  produces<TrackingRecHitCollection>();
52  produces<reco::TrackExtraCollection>();
53  }
54  produces<std::vector<Trajectory> >();
55  produces<TrajTrackAssociationCollection>();
56 
57  trajTag = consumes<std::vector<Trajectory> >(iConfig.getParameter<edm::InputTag>("recTracks"));
58  tassTag = consumes<TrajTrackAssociationCollection>(iConfig.getParameter<edm::InputTag>("recTracks"));
59  trackQuality_=TrackBase::qualityByName(iConfig.getParameter<std::string>("TrackQuality"));
60 }
61 
62 
64 {
65 
66  // do anything here that needs to be done at desctruction time
67  // (e.g. close files, deallocate resources etc.)
68 
69 }
70 
71 
72 //
73 // member functions
74 //
75 
76 // ------------ method called to produce the data ------------
77 void
79 {
80 
81 
82  unique_ptr<TrackCollection> selTracks(new TrackCollection);
83  unique_ptr<TrackingRecHitCollection> selHits(copyExtras_ ? new TrackingRecHitCollection() : nullptr);
84  unique_ptr<TrackExtraCollection> selTrackExtras(copyExtras_ ? new TrackExtraCollection() : nullptr);
85  unique_ptr<vector<Trajectory> > outputTJ(new vector<Trajectory> );
86  unique_ptr<TrajTrackAssociationCollection> trajTrackMap( new TrajTrackAssociationCollection() );
87 
88 
89  TrackExtraRefProd rTrackExtras;
91  if (copyExtras_) {
92  rTrackExtras = iEvent.getRefBeforePut<TrackExtraCollection>();
93  rHits = iEvent.getRefBeforePut<TrackingRecHitCollection>();
94  }
95 
98 
99  iEvent.getByToken(trajTag,TrajectoryCollection);
100  iEvent.getByToken(tassTag,assoMap);
101 
102 
103 
106  for( ; it != lastAssoc; ++it ) {
107  const Ref<vector<Trajectory> > traj = it->key;
108  const reco::TrackRef itc = it->val;
109  bool goodTk = (itc->quality(trackQuality_));
110 
111 
112  if (goodTk){
113  auto const & track =(*itc);
114  //tracks and trajectories
115  selTracks->push_back( track );
116  outputTJ->push_back( *traj );
117  if (copyExtras_) {
118  //TRACKING HITS
119  trackingRecHit_iterator irhit =(*itc).recHitsBegin();
120  trackingRecHit_iterator lasthit =(*itc).recHitsEnd();
121  for (; irhit!=lasthit; ++irhit) {
122  selHits->push_back((*irhit)->clone() );
123  }
124  }
125 
126  }
127 
128  }
129 
130  unsigned nTracks = selTracks->size();
131  if (copyExtras_) {
132  //PUT TRACKING HITS IN THE EVENT
133  OrphanHandle<TrackingRecHitCollection> theRecoHits = iEvent.put(std::move(selHits) );
134  edm::RefProd<TrackingRecHitCollection> theRecoHitsProd(theRecoHits);
135 
136  //PUT TRACK EXTRA IN THE EVENT
137  selTrackExtras->reserve(nTracks);
138  unsigned hits=0;
139 
140  for ( unsigned index = 0; index<nTracks; ++index ) {
141  auto const & aTrack = (*selTracks)[index];
142  selTrackExtras->emplace_back(aTrack.outerPosition(),
143  aTrack.outerMomentum(),
144  aTrack.outerOk(),
145  aTrack.innerPosition(),
146  aTrack.innerMomentum(),
147  aTrack.innerOk(),
148  aTrack.outerStateCovariance(),
149  aTrack.outerDetId(),
150  aTrack.innerStateCovariance(),
151  aTrack.innerDetId(),
152  aTrack.seedDirection(),
153  aTrack.seedRef()
154  );
155 
156  auto & aTrackExtra = selTrackExtras->back();
157  //unsigned nHits = aTrack.numberOfValidHits();
158  auto nHits = aTrack.recHitsSize();
159  aTrackExtra.setHits(theRecoHitsProd, hits, nHits);
160  hits += nHits;
161  selTrackExtras->push_back(aTrackExtra);
162  }
163 
164  //CORRECT REF TO TRACK
165  OrphanHandle<TrackExtraCollection> theRecoTrackExtras = iEvent.put(std::move(selTrackExtras));
166  for ( unsigned index = 0; index<nTracks; ++index ) {
167  const reco::TrackExtraRef theTrackExtraRef(theRecoTrackExtras,index);
168  (*selTracks)[index].setExtra(theTrackExtraRef);
169  }
170  } // END IF COPY EXTRAS
171 
172  //TRACKS AND TRAJECTORIES
173  OrphanHandle<TrackCollection> theRecoTracks = iEvent.put(std::move(selTracks));
174  OrphanHandle<vector<Trajectory> > theRecoTrajectories = iEvent.put(std::move(outputTJ));
175 
176  //TRACKS<->TRAJECTORIES MAP
177  nTracks = theRecoTracks->size();
178  for ( unsigned index = 0; index<nTracks; ++index ) {
179  Ref<vector<Trajectory> > trajRef( theRecoTrajectories, index );
180  Ref<TrackCollection> tkRef( theRecoTracks, index );
181  trajTrackMap->insert(trajRef,tkRef);
182  }
183  //MAP IN THE EVENT
184  iEvent.put( std::move(trajTrackMap) );
185 }
186 
187 // ------------ method called once each job just after ending the event loop ------------
188 void
190 }
191 
192 
193 
195 
T getParameter(std::string const &) const
reco::TrackBase::TrackQuality trackQuality_
T getUntrackedParameter(std::string const &, T const &) const
const unsigned int nTracks(const reco::Vertex &sv)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:125
const_iterator end() const
last iterator over the map (read only)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
TrackQuality
track quality
Definition: TrackBase.h:151
void produce(edm::Event &, const edm::EventSetup &) override
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:15
edm::EDGetTokenT< std::vector< Trajectory > > trajTag
key_type key() const
Accessor for product key.
Definition: Ref.h:263
~QualityFilter() override
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< TrajTrackAssociationCollection > tassTag
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > > TrajTrackAssociationCollection
RefProd< PROD > getRefBeforePut()
Definition: Event.h:150
#define dso_hidden
Definition: Visibility.h:12
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
edm::OwnVector< TrackingRecHit > TrackingRecHitCollection
collection of TrackingRecHits
std::vector< Trajectory > TrajectoryCollection
fixed size matrix
HLT enums.
const_iterator begin() const
first iterator over the map (read only)
QualityFilter(const edm::ParameterSet &)
virtual void endJob()
def move(src, dest)
Definition: eostools.py:511