CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RecoTrackAccumulator.cc
Go to the documentation of this file.
7 
8 
10  signalTracksTag(conf.getParameter<edm::InputTag>("signalTracks")),
11  signalMVAValuesTag(conf.getParameter<edm::InputTag>("signalMVAValues")),
12  pileUpTracksTag(conf.getParameter<edm::InputTag>("pileUpTracks")),
13  pileUpMVAValuesTag(conf.getParameter<edm::InputTag>("pileUpMVAValues")),
14  outputLabel(conf.getParameter<std::string>("outputLabel")),
15  MVAOutputLabel(conf.getParameter<std::string>("MVAOutputLabel"))
16 {
17  mixMod.produces<reco::TrackCollection>(outputLabel);
18  mixMod.produces<TrackingRecHitCollection>(outputLabel);
19  mixMod.produces<reco::TrackExtraCollection>(outputLabel);
20  mixMod.produces<edm::ValueMap<float> >(MVAOutputLabel);
21 
26 }
27 
29 
30 }
31 
33 
34  newTracks_ = std::auto_ptr<reco::TrackCollection>(new reco::TrackCollection);
35  newHits_ = std::auto_ptr<TrackingRecHitCollection>(new TrackingRecHitCollection);
36  newTrackExtras_ = std::auto_ptr<reco::TrackExtraCollection>(new reco::TrackExtraCollection);
37  newMVAVals_.clear();
38 
39  // this is needed to get the ProductId of the TrackExtra and TrackingRecHit and Track collections
40  rNewTracks=const_cast<edm::Event&>( e ).getRefBeforePut<reco::TrackCollection>(outputLabel);
41  rNewTrackExtras=const_cast<edm::Event&>( e ).getRefBeforePut<reco::TrackExtraCollection>(outputLabel);
42  rNewHits=const_cast<edm::Event&>( e ).getRefBeforePut<TrackingRecHitCollection>(outputLabel);
43 }
44 
47 }
48 
50  if (e.bunchCrossing()==0) {
52  }
53 }
54 
56 
57  std::auto_ptr< edm::ValueMap<float> > _newMVAVals(new edm::ValueMap<float>);
58  edm::ValueMap<float>::Filler filler(*_newMVAVals);
60  filler.insert(newTracksHandle,newMVAVals_.begin(),newMVAVals_.end());
61  filler.fill();
63  e.put( newHits_, outputLabel );
65  e.put(_newMVAVals,MVAOutputLabel);
66 }
67 
68 
69 template<class T> void RecoTrackAccumulator::accumulateEvent(const T& e, edm::EventSetup const& iSetup,const edm::InputTag & label,const edm::InputTag & MVALabel) {
70 
75  if(!(e.getByLabel(label, tracks) and e.getByLabel(label, hits) and e.getByLabel(label, trackExtras))){
76  edm::LogError ("RecoTrackAccumulator") << "Failed to find track, hit or trackExtra collections with inputTag " << label;
77  exit(1);
78  }
79  else if(!e.getByLabel(MVALabel,mvaVals)){
80  edm::LogError ("RecoTrackAccumulator") << "Failed to find mva values with inputTag" << MVALabel;
81  exit(1);
82  }
83 
84  if(tracks->size() != mvaVals->size()){
85  edm::LogError("RecoTrackAccumulator") << "RecoTrackAccumulator expects the track collection and the MVA values to have the same number of entries" << std::endl;
86  }
87  if (tracks->size()==0)
88  return;
89 
90  // crude way to get the track product id
91  // (for PU events, the usual reco::TrackRef(tracks,t) does not result in a proper product id in the TrackRef)
92  edm::ProductID tracksProdId = mvaVals->begin().id();
93 
94  for (size_t t = 0; t < tracks->size();++t){
95  const reco::Track & track = tracks->at(t);
96  newTracks_->push_back(track);
97  // track extras:
98  auto const& extra = trackExtras->at(track.extra().key());
99  newTrackExtras_->emplace_back(extra.outerPosition(), extra.outerMomentum(), extra.outerOk(),
100  extra.innerPosition(),extra.innerMomentum(), extra.innerOk(),
101  extra.outerStateCovariance(), extra.outerDetId(),
102  extra.innerStateCovariance(), extra.innerDetId(),
103  extra.seedDirection(),
104  //If TrajectorySeeds are needed, then their list must be gotten from the
105  // secondary event directly and looked up similarly to TrackExtras.
106  //We can't use a default constructed RefToBase due to a bug in RefToBase
107  // which causes an seg fault when calling isAvailable on a default constructed one.
109  newTracks_->back().setExtra( reco::TrackExtraRef( rNewTrackExtras, newTracks_->size() - 1) );
110  // rechits:
111  // note: extra.recHit(i) does not work for pileup events
112  // probably the Ref does not know its product id applies on a pileup event
113  auto & newExtra = newTrackExtras_->back();
114  auto const firstTrackIndex = newHits_->size();
115  for(unsigned int i = 0;i<extra.recHitsSize();i++){
116  newHits_->push_back( (*hits)[extra.recHit(i).key()] );
117  }
118  newExtra.setHits( rNewHits, firstTrackIndex, newHits_->size() - firstTrackIndex);
119  // crude way to get the mva value that belongs to the track
120  // the usual way valueMap[trackref] does not work in PU events,
121  // see earlier comment about track id
122  float _val = mvaVals->get(tracksProdId,t);
123  newMVAVals_.push_back(_val);
124  }
125 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
int i
Definition: DBlmapReader.cc:9
const TrackExtraRef & extra() const
reference to &quot;extra&quot; object
Definition: Track.h:189
ProductID id() const
Definition: HandleBase.cc:15
edm::InputTag signalMVAValuesTag
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
std::vector< Track > TrackCollection
collection of Tracks
Definition: TrackFwd.h:13
key_type key() const
Accessor for product key.
Definition: Ref.h:266
RecoTrackAccumulator(const edm::ParameterSet &conf, edm::one::EDProducerBase &mixMod, edm::ConsumesCollector &iC)
virtual void accumulate(edm::Event const &e, edm::EventSetup const &c)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:113
TrackingRecHitRefProd rNewHits
reco::TrackRefProd rNewTracks
edm::InputTag pileUpMVAValuesTag
void accumulateEvent(const T &e, edm::EventSetup const &c, const edm::InputTag &label, const edm::InputTag &MVALabel)
tuple conf
Definition: dbtoconf.py:185
std::vector< float > newMVAVals_
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
Definition: TrackExtraFwd.h:11
edm::OwnVector< TrackingRecHit > TrackingRecHitCollection
collection of TrackingRecHits
std::auto_ptr< reco::TrackExtraCollection > newTrackExtras_
tuple tracks
Definition: testEve_cfg.py:39
virtual void finalizeEvent(edm::Event &e, edm::EventSetup const &c)
virtual void initializeEvent(edm::Event const &e, edm::EventSetup const &c)
ProductID id() const
Accessor for product ID.
Definition: RefProd.h:140
std::auto_ptr< TrackingRecHitCollection > newHits_
std::auto_ptr< reco::TrackCollection > newTracks_
long double T
reco::TrackExtraRefProd rNewTrackExtras