33 #include "TMVA/Reader.h"
45 typedef std::pair<TrackCandidate,std::pair<reco::TrackRef,reco::TrackRef> >
DuplicateRecord;
66 tag(tag_), tk(tk_), traj(traj_), tass(tass_) {}
69 return ThreeTokens(tag, consumes<reco::TrackCollection>(tag), consumes<std::vector<Trajectory> >(tag), consumes<TrajTrackAssociationCollection >(tag));
100 minTrkProbCut_ = 0.0;
102 if(iPara.
exists(
"minTrkProbCut"))minTrkProbCut_ = iPara.
getParameter<
double>(
"minTrkProbCut");
108 if(iPara.
exists(
"mergedMVAVals")){
111 mergedMVAVals_ =
edm::InputTag(mergedTrackSource_.tag.label(),
"MVAVals");
113 mergedMVAValsToken_ = consumes<edm::ValueMap<float> >(mergedMVAVals_);
114 if(iPara.
exists(
"originalMVAVals")){
117 originalMVAVals_ =
edm::InputTag(originalTrackSource_.tag.label(),
"MVAVals");
119 originalMVAValsToken_ = consumes<edm::ValueMap<float> >(originalMVAVals_);
123 if (iPara.
exists(
"newQuality")) {
125 if (qualityStr !=
"") {
130 produces<std::vector<reco::Track> >();
131 produces< std::vector<Trajectory> >();
132 produces< TrajTrackAssociationCollection >();
134 produces<edm::ValueMap<float> >(
"MVAVals");
137 if (makeReKeyedSeeds_){
139 produces<TrajectorySeedCollection>();
142 produces<reco::TrackExtraCollection>();
143 produces<TrackingRecHitCollection>();
158 iEvent.
getByToken(originalTrackSource_.tk,originalHandle);
160 iEvent.
getByToken(mergedTrackSource_.tk,mergedHandle);
167 iEvent.
getByToken(mergedTrackSource_.traj,mergedTrajHandle);
169 iEvent.
getByToken(mergedTrackSource_.tass,mergedTrajTrackHandle);
172 iEvent.
getByToken(originalTrackSource_.traj,originalTrajHandle);
174 iEvent.
getByToken(originalTrackSource_.tass,originalTrajTrackHandle);
177 iEvent.
getByToken(candidateSource_,candidateHandle);
179 std::auto_ptr<std::vector<reco::Track> > out_generalTracks(
new std::vector<reco::Track>());
180 out_generalTracks->reserve(originalHandle->size());
182 std::auto_ptr< std::vector<Trajectory> > outputTrajs = std::auto_ptr< std::vector<Trajectory> >(
new std::vector<Trajectory>());
183 outputTrajs->reserve(originalTrajHandle->size()+mergedTrajHandle->size());
185 std::auto_ptr< TrajTrackAssociationCollection > outputTTAss = std::auto_ptr< TrajTrackAssociationCollection >(
new TrajTrackAssociationCollection());
188 std::auto_ptr<reco::TrackExtraCollection> outputTrkExtras;
190 std::auto_ptr<TrackingRecHitCollection> outputTrkHits;
192 std::auto_ptr<TrajectorySeedCollection> outputSeeds;
198 iEvent.
getByToken(originalMVAValsToken_,originalMVAStore);
199 iEvent.
getByToken(mergedMVAValsToken_,mergedMVAStore);
203 std::vector<float> mvaVec;
208 outputTrkExtras->reserve(originalHandle->size());
211 outputTrkHits->reserve(originalHandle->size()*25);
213 if (makeReKeyedSeeds_){
215 outputSeeds->
reserve(originalHandle->size());
221 std::vector<std::pair<int,const DuplicateRecord*> > matches;
222 for(
int i = 0;
i < (int)candidateHandle->size();
i++){
224 int matchTrack = matchCandidateToTrack(duplicateRecord.first,mergedHandle);
225 if(matchTrack < 0)
continue;
226 const reco::Track& matchedTrack(mergedTracks[matchTrack]);
228 unsigned int dHits = (duplicateRecord.first.recHits().second - duplicateRecord.first.recHits().first) - matchedTrack.
recHitsSize();
229 if(dHits > diffHitsCut_)
continue;
230 matches.push_back(std::pair<int,const DuplicateRecord*>(matchTrack,&duplicateRecord));
234 std::vector<std::pair<int,const DuplicateRecord*> >::iterator matchIter0 = matches.begin();
235 std::vector<std::pair<int,const DuplicateRecord*> >::iterator matchIter1;
236 while(matchIter0 != matches.end()){
237 double nchi2 = mergedTracks[matchIter0->first].normalizedChi2();
239 for(matchIter1 = matchIter0+1; matchIter1 != matches.end(); matchIter1++){
240 const reco::Track& match0first = *(matchIter0->second->second.first.get());
241 const reco::Track& match0second = *(matchIter0->second->second.second.get());
242 const reco::Track& match1first = *(matchIter1->second->second.first.get());
243 const reco::Track& match1second = *(matchIter1->second->second.second.get());
248 double nchi2_1 = mergedTracks[matchIter1->first].
normalizedChi2();
251 matches.erase(matchIter0);
253 matches.erase(matchIter1);
258 if(advance)matchIter0++;
262 std::vector<reco::Track> inputTracks;
266 for(matchIter0 = matches.begin(); matchIter0 != matches.end(); matchIter0++){
273 inputTracks.push_back(inTrk1);
274 inputTracks.push_back(inTrk2);
275 out_generalTracks->push_back(mergedTracks[matchIter0->first]);
277 float mergedMVA = (*mergedMVAStore)[
reco::TrackRef(mergedTrackRefs,matchIter0->first)];
278 mvaVec.push_back(mergedMVA);
279 out_generalTracks->back().setAlgorithm(newTrkAlgo);
280 out_generalTracks->back().setQualityMask(combinedQualityMask);
281 out_generalTracks->back().setQuality(qualityToSet_);
284 const reco::Track& track = mergedTracks[matchIter0->first];
287 if (makeReKeyedSeeds_){
288 bool doRekeyOnThisSeed=
false;
292 if (origSeedRef->
nHits()!=0){
295 if (firstHit->isValid()){
304 doRekeyOnThisSeed=iEvent.
getByLabel(clusterRemovalInfos,CRIh);
308 if (doRekeyOnThisSeed && !(clusterRemovalInfos==
edm::InputTag(
""))) {
314 for (;iH!=iH_end;++iH){
316 refSetter.
reKey(&newRecHitContainer.
back());
337 out_generalTracks->back().setExtra(
reco::TrackExtraRef( refTrkExtras, outputTrkExtras->size() - 1) );
342 auto const firstTrackIndex = outputTrkHits->size();
343 for (
unsigned ih=0; ih<nh1; ++ih ) {
345 outputTrkHits->push_back( track.
recHit(ih)->clone() );
347 tx.
setHits( refTrkHits, firstTrackIndex, outputTrkHits->size() - firstTrackIndex );
351 if (match != mergedTrajTrackHandle->end()) {
353 outputTrajs->push_back( *trajRef );
354 if (copyExtras_ && makeReKeyedSeeds_)
355 outputTrajs->back().setSeedRef( origSeedRef );
356 outputTTAss->insert(
edm::Ref< std::vector<Trajectory> >(refTrajs, outputTrajs->size() - 1),curTrackRef );
361 for(
int i = 0;
i < (int)originalHandle->size();
i++){
364 for(
int j = 0;
j < (int)inputTracks.size() && good;
j++){
374 out_generalTracks->push_back(origTrack);
378 mvaVec.push_back((*originalMVAStore)[origTrackRef]);
384 if (makeReKeyedSeeds_){
385 bool doRekeyOnThisSeed=
false;
389 if (origSeedRef->nHits()!=0){
392 if (firstHit->isValid()){
401 doRekeyOnThisSeed=iEvent.
getByLabel(clusterRemovalInfos,CRIh);
405 if (doRekeyOnThisSeed && !(clusterRemovalInfos==
edm::InputTag(
""))) {
408 newRecHitContainer.
reserve(origSeedRef->nHits());
411 for (;iH!=iH_end;++iH){
413 refSetter.
reKey(&newRecHitContainer.
back());
415 outputSeeds->push_back(
TrajectorySeed( origSeedRef->startingState(),
417 origSeedRef->direction()));
435 out_generalTracks->back().setExtra(
reco::TrackExtraRef( refTrkExtras, outputTrkExtras->size() - 1) );
441 tx.
setHits(refTrkHits,outputTrkHits->size(),nh1);
443 outputTrkHits->push_back( (*hh)->clone() );
450 if (match != originalTrajTrackHandle->end()) {
452 outputTrajs->push_back( *trajRef );
453 if (copyExtras_ && makeReKeyedSeeds_)
454 outputTrajs->back().setSeedRef( origSeedRef );
455 outputTTAss->insert(
edm::Ref< std::vector<Trajectory> >(refTrajs, outputTrajs->size() - 1),curTrackRef );
464 fillerMVA.
insert(out_gtHandle,mvaVec.begin(),mvaVec.end());
466 iEvent.
put(vmMVA,
"MVAVals");
468 out_generalTracks->shrink_to_fit(); iEvent.
put(out_generalTracks);
470 outputTrkExtras->shrink_to_fit(); iEvent.
put(outputTrkExtras);
471 outputTrkHits->shrink_to_fit(); iEvent.
put(outputTrkHits);
472 if (makeReKeyedSeeds_) {
473 outputSeeds->shrink_to_fit(); iEvent.
put(outputSeeds);
476 outputTrajs->shrink_to_fit(); iEvent.
put(outputTrajs);
477 iEvent.
put(outputTTAss);
486 std::vector<int> rawIds;
487 RecHitContainer::const_iterator candBegin = candidate.
recHits().first;
488 RecHitContainer::const_iterator candEnd = candidate.
recHits().second;
489 for(; candBegin != candEnd; candBegin++){
490 rawIds.push_back((*(candBegin)).rawId());
494 for(
int i = 0;
i < (int)tracks->size() && track < 0;
i++){
495 if( (*tracks)[
i].seedRef() != candidate.
seedRef())
continue;
499 for(;trackRecBegin != trackRecEnd; trackRecBegin++){
500 if(
std::find(rawIds.begin(),rawIds.end(),(*(trackRecBegin))->rawId()) != rawIds.end()) match++;
502 if(match != (
int)( (*tracks)[
i].recHitsSize() ) )
continue;
PropagationDirection direction() const
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
edm::OwnVector< TrackingRecHit > RecHitContainer
const Point & referencePoint() const
Reference point on the track.
bool isNonnull() const
Checks for non-null.
edm::EDGetTokenT< TrajTrackAssociationCollection > tass
friend struct const_iterator
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
TrackQuality
track quality
#define DEFINE_FWK_MODULE(type)
size_t recHitsSize() const
Get number of RecHits. (Warning, this includes invalid hits, which are not physical hits)...
edm::EDGetTokenT< edm::ValueMap< float > > originalMVAValsToken_
void reKey(TrackingRecHit *hit) const
void insert(const H &h, I begin, I end)
std::vector< Track > TrackCollection
collection of Tracks
edm::EDGetTokenT< std::vector< Trajectory > > traj
bool exists(std::string const ¶meterName) const
checks if a parameter exists
bool innerOk() const
return true if the innermost hit is valid
std::pair< TrackCandidate, std::pair< reco::TrackRef, reco::TrackRef > > DuplicateRecord
typedef container of candidate and input tracks
const Vector & momentum() const
track momentum vector
std::string const & processName() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
const math::XYZPoint & outerPosition() const
position of the outermost hit
TrackAlgorithm
track algorithm
const math::XYZPoint & innerPosition() const
position of the innermost hit
TrackAlgorithm algo() const
void produce(edm::Event &, const edm::EventSetup &) override
produce one event
virtual ~DuplicateListMerger()
destructor
edm::EDGetTokenT< edm::View< DuplicateRecord > > candidateSource_
ThreeTokens originalTrackSource_
std::vector< TrajectorySeed > TrajectorySeedCollection
double chi2() const
chi-squared of the fit
edm::InputTag originalMVAVals_
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
recHitContainer::const_iterator const_iterator
double ndof() const
number of degrees of freedom of the fit
DuplicateListMerger(const edm::ParameterSet &iPara)
constructor
CovarianceMatrix outerStateCovariance() const
outermost trajectory state curvilinear errors
edm::InputTag mergedMVAVals_
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
unsigned int diffHitsCut_
float ChiSquaredProbability(double chiSquared, double nrDOF)
T const * get() const
Returns C++ pointer to the item.
trackingRecHit_iterator recHitsBegin() const
Iterator to first hit on the track.
edm::AssociationMap< edm::OneToOne< std::vector< Trajectory >, reco::TrackCollection, unsigned short > > TrajTrackAssociationCollection
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
RefProd< PROD > getRefBeforePut()
ThreeTokens threeTokens(const edm::InputTag &tag)
edm::EDGetTokenT< reco::TrackCollection > tk
std::vector< TrackExtra > TrackExtraCollection
collection of TrackExtra objects
edm::OwnVector< TrackingRecHit > TrackingRecHitCollection
collection of TrackingRecHits
edm::RefToBase< TrajectorySeed > seedRef() const
int matchCandidateToTrack(TrackCandidate, edm::Handle< reco::TrackCollection >)
PTrajectoryStateOnDet const & startingState() const
static TrackQuality qualityByName(const std::string &name)
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
bool outerOk() const
return true if the outermost hit is valid
reco::TrackBase::TrackQuality qualityToSet_
edm::Ref< TrackCollection > TrackRef
persistent reference to a Track
CovarianceMatrix innerStateCovariance() const
innermost trajectory state curvilinear errors
std::string const & moduleLabel() const
edm::ProductID clusterProductB(const TrackingRecHit *hit)
ThreeTokens(const edm::InputTag &tag_, edm::EDGetTokenT< reco::TrackCollection > &&tk_, edm::EDGetTokenT< std::vector< Trajectory > > &&traj_, edm::EDGetTokenT< TrajTrackAssociationCollection > &&tass_)
unsigned int nHits() const
const math::XYZVector & innerMomentum() const
momentum vector at the innermost hit position
TrackingRecHitRef recHit(size_t i) const
Get i-th hit on the track.
ProductID id() const
Accessor for product ID.
const TrackResiduals & residuals() const
PropagationDirection seedDirection() const
direction of how the hits were sorted in the original seed
int charge() const
track electric charge
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
edm::EDGetTokenT< edm::ValueMap< float > > mergedMVAValsToken_
std::string const & productInstanceName() const
Provenance getProvenance(BranchID const &theID) const
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
edm::RefToBase< TrajectorySeed > seedRef() const
TrackingRecHitCollection::base::const_iterator trackingRecHit_iterator
iterator over a vector of reference to TrackingRecHit in the same collection
trackingRecHit_iterator recHitsEnd() const
Iterator to last hit on the track.