@@ -136,8 +136,8 @@ MuonIdProducer::MuonIdProducer(const edm::ParameterSet& iConfig)
136136 throw cms::Exception (" ConfigurationError" )
137137 << " Number of input collection labels is different from number of types. "
138138 << " For each collection label there should be exactly one collection type specified." ;
139- if (inputCollectionLabels_.size () > 7 || inputCollectionLabels_.empty ())
140- throw cms::Exception (" ConfigurationError" ) << " Number of input collections should be from 1 to 7 ." ;
139+ if (inputCollectionLabels_.size () > 8 || inputCollectionLabels_.empty ())
140+ throw cms::Exception (" ConfigurationError" ) << " Number of input collections should be from 1 to 8 ." ;
141141
142142 debugWithTruthMatching_ = iConfig.getParameter <bool >(" debugWithTruthMatching" );
143143 if (debugWithTruthMatching_) {
@@ -180,8 +180,10 @@ MuonIdProducer::MuonIdProducer(const edm::ParameterSet& iConfig)
180180
181181 if (inputType == ICTypes::INNER_TRACKS) {
182182 innerTrackCollectionToken_ = consumes<reco::TrackCollection>(inputLabel);
183- } else if (inputType == ICTypes::OUTER_TRACKS) {
183+ } else if (inputType == ICTypes::OUTER_TRACKS && outerTrackCollectionToken_. isUninitialized () ) {
184184 outerTrackCollectionToken_ = consumes<reco::TrackCollection>(inputLabel);
185+ } else if (inputType == ICTypes::OUTER_TRACKS) {
186+ outerTrackSecondaryCollectionToken_ = consumes<reco::TrackCollection>(inputLabel);
185187 } else if (inputType == ICTypes::LINKS) {
186188 linkCollectionToken_ = consumes<reco::MuonTrackLinksCollection>(inputLabel);
187189 } else if (inputType == ICTypes::MUONS) {
@@ -205,6 +207,7 @@ MuonIdProducer::~MuonIdProducer() {
205207void MuonIdProducer::init (edm::Event& iEvent, const edm::EventSetup& iSetup) {
206208 innerTrackCollectionHandle_.clear ();
207209 outerTrackCollectionHandle_.clear ();
210+ outerTrackSecondaryCollectionHandle_.clear ();
208211 linkCollectionHandle_.clear ();
209212 muonCollectionHandle_.clear ();
210213
@@ -225,11 +228,17 @@ void MuonIdProducer::init(edm::Event& iEvent, const edm::EventSetup& iSetup) {
225228 if (!innerTrackCollectionHandle_.isValid ())
226229 throw cms::Exception (" FatalError" ) << " Failed to get input track collection with label: " << inputLabel;
227230 LogTrace (" MuonIdentification" ) << " Number of input inner tracks: " << innerTrackCollectionHandle_->size ();
228- } else if (inputType == ICTypes::OUTER_TRACKS) {
231+ } else if (inputType == ICTypes::OUTER_TRACKS && !outerTrackCollectionHandle_. isValid () ) {
229232 iEvent.getByToken (outerTrackCollectionToken_, outerTrackCollectionHandle_);
230233 if (!outerTrackCollectionHandle_.isValid ())
231234 throw cms::Exception (" FatalError" ) << " Failed to get input track collection with label: " << inputLabel;
232235 LogTrace (" MuonIdentification" ) << " Number of input outer tracks: " << outerTrackCollectionHandle_->size ();
236+ } else if (inputType == ICTypes::OUTER_TRACKS) {
237+ iEvent.getByToken (outerTrackSecondaryCollectionToken_, outerTrackSecondaryCollectionHandle_);
238+ if (!outerTrackSecondaryCollectionHandle_.isValid ())
239+ throw cms::Exception (" FatalError" ) << " Failed to get input track collection with label: " << inputLabel;
240+ LogTrace (" MuonIdentification" ) << " Number of input outer secondary tracks: "
241+ << outerTrackSecondaryCollectionHandle_->size ();
233242 } else if (inputType == ICTypes::LINKS) {
234243 iEvent.getByToken (linkCollectionToken_, linkCollectionHandle_);
235244 if (!linkCollectionHandle_.isValid ())
@@ -629,8 +638,14 @@ void MuonIdProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
629638 // and at last the stand alone muons
630639 if (outerTrackCollectionHandle_.isValid ()) {
631640 LogTrace (" MuonIdentification" ) << " Looking for new muons among stand alone muon tracks" ;
632- for (unsigned int i = 0 ; i < outerTrackCollectionHandle_->size (); ++i) {
633- const auto & outerTrack = outerTrackCollectionHandle_->at (i);
641+ const unsigned int nouter = outerTrackCollectionHandle_->size ();
642+ const unsigned int nsecond =
643+ (outerTrackSecondaryCollectionHandle_.isValid ()) ? outerTrackSecondaryCollectionHandle_->size () : 0 ;
644+ for (unsigned int i = 0 ; i < nouter + nsecond; ++i) {
645+ const auto & outerTrack =
646+ (i < nouter) ? outerTrackCollectionHandle_->at (i) : outerTrackSecondaryCollectionHandle_->at (i - nouter);
647+ reco::TrackRef refToTrack = (i < nouter) ? reco::TrackRef (outerTrackCollectionHandle_, i)
648+ : reco::TrackRef (outerTrackSecondaryCollectionHandle_, i - nouter);
634649
635650 // check if this muon is already in the list of global muons
636651 bool newMuon = true ;
@@ -654,16 +669,15 @@ void MuonIdProducer::produce(edm::Event& iEvent, const edm::EventSetup& iSetup)
654669 if (overlap (muon, outerTrack) > 0 ) {
655670 LogTrace (" MuonIdentification" ) << " Found associated tracker muon. Set a reference and move on" ;
656671 newMuon = false ;
657- muon.setOuterTrack (reco::TrackRef (outerTrackCollectionHandle_, i) );
672+ muon.setOuterTrack (refToTrack );
658673 muon.setType (muon.type () | reco::Muon::StandAloneMuon);
659674 break ;
660675 }
661676 }
662677 }
663678 if (newMuon) {
664679 LogTrace (" MuonIdentification" ) << " No associated stand alone track is found. Making a muon" ;
665- outputMuons->push_back (
666- makeMuon (iEvent, iSetup, reco::TrackRef (outerTrackCollectionHandle_, i), reco::Muon::OuterTrack));
680+ outputMuons->push_back (makeMuon (iEvent, iSetup, refToTrack, reco::Muon::OuterTrack));
667681 outputMuons->back ().setType (reco::Muon::StandAloneMuon);
668682 }
669683 }
0 commit comments