33 #include "TMVA/Reader.h"
47 typedef std::pair<TrackCandidate,std::pair<reco::TrackRef,reco::TrackRef> >
DuplicateRecord;
68 tag(tag_), tk(tk_), traj(traj_), tass(tass_) {}
71 return ThreeTokens(tag, consumes<reco::TrackCollection>(tag), consumes<std::vector<Trajectory> >(tag), consumes<TrajTrackAssociationCollection >(tag));
102 minTrkProbCut_ = 0.0;
104 if(iPara.
exists(
"minTrkProbCut"))minTrkProbCut_ = iPara.
getParameter<
double>(
"minTrkProbCut");
110 if(iPara.
exists(
"mergedMVAVals")){
113 mergedMVAVals_ =
edm::InputTag(mergedTrackSource_.tag.label(),
"MVAVals");
115 mergedMVAValsToken_ = consumes<edm::ValueMap<float> >(mergedMVAVals_);
116 if(iPara.
exists(
"originalMVAVals")){
119 originalMVAVals_ =
edm::InputTag(originalTrackSource_.tag.label(),
"MVAVals");
121 originalMVAValsToken_ = consumes<edm::ValueMap<float> >(originalMVAVals_);
125 if (iPara.
exists(
"newQuality")) {
127 if (qualityStr !=
"") {
132 produces<std::vector<reco::Track> >();
133 produces< std::vector<Trajectory> >();
134 produces< TrajTrackAssociationCollection >();
136 produces<edm::ValueMap<float> >(
"MVAVals");
139 if (makeReKeyedSeeds_){
141 produces<TrajectorySeedCollection>();
144 produces<reco::TrackExtraCollection>();
145 produces<TrackingRecHitCollection>();
160 iEvent.
getByToken(originalTrackSource_.tk,originalHandle);
162 iEvent.
getByToken(mergedTrackSource_.tk,mergedHandle);
169 iEvent.
getByToken(mergedTrackSource_.traj,mergedTrajHandle);
171 iEvent.
getByToken(mergedTrackSource_.tass,mergedTrajTrackHandle);
174 iEvent.
getByToken(originalTrackSource_.traj,originalTrajHandle);
176 iEvent.
getByToken(originalTrackSource_.tass,originalTrajTrackHandle);
179 iEvent.
getByToken(candidateSource_,candidateHandle);
181 std::auto_ptr<std::vector<reco::Track> > out_generalTracks(
new std::vector<reco::Track>());
182 out_generalTracks->reserve(originalHandle->size());
184 std::auto_ptr< std::vector<Trajectory> > outputTrajs = std::auto_ptr< std::vector<Trajectory> >(
new std::vector<Trajectory>());
185 outputTrajs->reserve(originalTrajHandle->size()+mergedTrajHandle->size());
189 std::auto_ptr<reco::TrackExtraCollection> outputTrkExtras;
191 std::auto_ptr<TrackingRecHitCollection> outputTrkHits;
193 std::auto_ptr<TrajectorySeedCollection> outputSeeds;
199 iEvent.
getByToken(originalMVAValsToken_,originalMVAStore);
200 iEvent.
getByToken(mergedMVAValsToken_,mergedMVAStore);
204 std::vector<float> mvaVec;
209 outputTrkExtras->reserve(originalHandle->size());
212 outputTrkHits->reserve(originalHandle->size()*25);
214 if (makeReKeyedSeeds_){
216 outputSeeds->
reserve(originalHandle->size());
222 std::vector<std::pair<int,const DuplicateRecord*> >
matches;
223 for(
int i = 0;
i < (int)candidateHandle->size();
i++){
225 int matchTrack = matchCandidateToTrack(duplicateRecord.first,mergedHandle);
226 if(matchTrack < 0)
continue;
227 const reco::Track& matchedTrack(mergedTracks[matchTrack]);
229 unsigned int dHits = (duplicateRecord.first.recHits().second - duplicateRecord.first.recHits().first) - matchedTrack.
recHitsSize();
230 if(dHits > diffHitsCut_)
continue;
231 matches.push_back(std::pair<int,const DuplicateRecord*>(matchTrack,&duplicateRecord));
235 std::vector<std::pair<int,const DuplicateRecord*> >::iterator matchIter0 = matches.begin();
236 std::vector<std::pair<int,const DuplicateRecord*> >::iterator matchIter1;
237 while(matchIter0 != matches.end()){
238 double nchi2 = mergedTracks[matchIter0->first].normalizedChi2();
240 for(matchIter1 = matchIter0+1; matchIter1 != matches.end(); matchIter1++){
241 const reco::Track& match0first = *(matchIter0->second->second.first.get());
242 const reco::Track& match0second = *(matchIter0->second->second.second.get());
243 const reco::Track& match1first = *(matchIter1->second->second.first.get());
244 const reco::Track& match1second = *(matchIter1->second->second.second.get());
249 double nchi2_1 = mergedTracks[matchIter1->first].
normalizedChi2();
252 matches.erase(matchIter0);
254 matches.erase(matchIter1);
259 if(advance)matchIter0++;
263 std::vector<reco::Track> inputTracks;
267 std::auto_ptr< TrajTrackAssociationCollection > outputTTAss = std::auto_ptr< TrajTrackAssociationCollection >(
new TrajTrackAssociationCollection(refTrajs, refTrks));
269 for(matchIter0 = matches.begin(); matchIter0 != matches.end(); matchIter0++){
279 inputTracks.push_back(inTrk1);
280 inputTracks.push_back(inTrk2);
281 out_generalTracks->push_back(mergedTracks[matchIter0->first]);
283 float mergedMVA = (*mergedMVAStore)[
reco::TrackRef(mergedTrackRefs,matchIter0->first)];
284 mvaVec.push_back(mergedMVA);
285 out_generalTracks->back().setAlgorithm(newTrkAlgo);
286 out_generalTracks->back().setQualityMask(combinedQualityMask);
287 out_generalTracks->back().setQuality(qualityToSet_);
290 const reco::Track& track = mergedTracks[matchIter0->first];
293 if (makeReKeyedSeeds_){
294 bool doRekeyOnThisSeed=
false;
298 if (origSeedRef->
nHits()!=0){
301 if (firstHit->isValid()){
310 doRekeyOnThisSeed=iEvent.
getByLabel(clusterRemovalInfos,CRIh);
314 if (doRekeyOnThisSeed && !(clusterRemovalInfos==
edm::InputTag(
""))) {
320 for (;iH!=iH_end;++iH){
322 refSetter.
reKey(&newRecHitContainer.
back());
343 out_generalTracks->back().setExtra(
reco::TrackExtraRef( refTrkExtras, outputTrkExtras->size() - 1) );
348 auto const firstTrackIndex = outputTrkHits->size();
349 for (
unsigned ih=0; ih<nh1; ++ih ) {
351 outputTrkHits->push_back( track.
recHit(ih)->clone() );
353 tx.
setHits( refTrkHits, firstTrackIndex, outputTrkHits->size() - firstTrackIndex );
357 if (match != mergedTrajTrackHandle->end()) {
359 outputTrajs->push_back( *trajRef );
360 if (copyExtras_ && makeReKeyedSeeds_)
361 outputTrajs->back().setSeedRef( origSeedRef );
362 outputTTAss->insert(
edm::Ref< std::vector<Trajectory> >(refTrajs, outputTrajs->size() - 1),curTrackRef );
367 for(
int i = 0;
i < (int)originalHandle->size();
i++){
370 for(
int j = 0;
j < (int)inputTracks.size() && good;
j++){
380 out_generalTracks->push_back(origTrack);
384 mvaVec.push_back((*originalMVAStore)[origTrackRef]);
390 if (makeReKeyedSeeds_){
391 bool doRekeyOnThisSeed=
false;
395 if (origSeedRef->nHits()!=0){
398 if (firstHit->isValid()){
407 doRekeyOnThisSeed=iEvent.
getByLabel(clusterRemovalInfos,CRIh);
411 if (doRekeyOnThisSeed && !(clusterRemovalInfos==
edm::InputTag(
""))) {
414 newRecHitContainer.
reserve(origSeedRef->nHits());
417 for (;iH!=iH_end;++iH){
419 refSetter.
reKey(&newRecHitContainer.
back());
421 outputSeeds->push_back(
TrajectorySeed( origSeedRef->startingState(),
423 origSeedRef->direction()));
441 out_generalTracks->back().setExtra(
reco::TrackExtraRef( refTrkExtras, outputTrkExtras->size() - 1) );
447 tx.
setHits(refTrkHits,outputTrkHits->size(),nh1);
449 outputTrkHits->push_back( (*hh)->clone() );
456 if (match != originalTrajTrackHandle->end()) {
458 outputTrajs->push_back( *trajRef );
459 if (copyExtras_ && makeReKeyedSeeds_)
460 outputTrajs->back().setSeedRef( origSeedRef );
461 outputTTAss->insert(
edm::Ref< std::vector<Trajectory> >(refTrajs, outputTrajs->size() - 1),curTrackRef );
470 fillerMVA.
insert(out_gtHandle,mvaVec.begin(),mvaVec.end());
472 iEvent.
put(vmMVA,
"MVAVals");
474 out_generalTracks->shrink_to_fit(); iEvent.
put(out_generalTracks);
476 outputTrkExtras->shrink_to_fit(); iEvent.
put(outputTrkExtras);
477 outputTrkHits->shrink_to_fit(); iEvent.
put(outputTrkHits);
478 if (makeReKeyedSeeds_) {
479 outputSeeds->shrink_to_fit(); iEvent.
put(outputSeeds);
482 outputTrajs->shrink_to_fit(); iEvent.
put(outputTrajs);
483 iEvent.
put(outputTTAss);
492 std::vector<int> rawIds;
493 RecHitContainer::const_iterator candBegin = candidate.
recHits().first;
494 RecHitContainer::const_iterator candEnd = candidate.
recHits().second;
495 for(; candBegin != candEnd; candBegin++){
496 rawIds.push_back((*(candBegin)).rawId());
500 for(
int i = 0;
i < (int)tracks->size() && track < 0;
i++){
501 if( (*tracks)[
i].seedRef() != candidate.
seedRef())
continue;
505 for(;trackRecBegin != trackRecEnd; trackRecBegin++){
506 if(
std::find(rawIds.begin(),rawIds.end(),(*(trackRecBegin))->rawId()) != rawIds.end()) match++;
508 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.