Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12382 from calabria/assoByHits_porting_76X
AssoByHits with GEM hits porting 8XY
- Loading branch information
Showing
14 changed files
with
337 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#ifndef MCTruth_GEMHitAssociator_h | ||
#define MCTruth_GEMHitAssociator_h | ||
|
||
#include "FWCore/Framework/interface/Event.h" | ||
#include "FWCore/Framework/interface/ESHandle.h" | ||
#include "FWCore/Utilities/interface/InputTag.h" | ||
#include "DataFormats/Common/interface/Handle.h" | ||
#include "SimDataFormats/EncodedEventId/interface/EncodedEventId.h" | ||
#include "SimDataFormats/TrackingHit/interface/PSimHit.h" | ||
#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h" | ||
#include "DataFormats/TrackingRecHit/interface/TrackingRecHit.h" | ||
#include "DataFormats/MuonDetId/interface/GEMDetId.h" | ||
#include "SimDataFormats/TrackerDigiSimLink/interface/StripDigiSimLink.h" | ||
#include "FWCore/Framework/interface/ConsumesCollector.h" | ||
|
||
#include <vector> | ||
#include <map> | ||
#include <string> | ||
#include <set> | ||
|
||
#include "SimDataFormats/CrossingFrame/interface/CrossingFrame.h" | ||
#include "SimDataFormats/CrossingFrame/interface/MixCollection.h" | ||
#include "DataFormats/DetId/interface/DetId.h" | ||
#include "DataFormats/MuonDetId/interface/MuonSubdetId.h" | ||
#include "DataFormats/GEMDigi/interface/GEMDigiCollection.h" | ||
#include "DataFormats/GEMRecHit/interface/GEMRecHitCollection.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
#include "Geometry/Records/interface/MuonGeometryRecord.h" | ||
#include "Geometry/GEMGeometry/interface/GEMGeometry.h" | ||
#include "DataFormats/Common/interface/DetSetVector.h" | ||
|
||
class GEMHitAssociator { | ||
|
||
public: | ||
|
||
typedef edm::DetSetVector<StripDigiSimLink> DigiSimLinks; | ||
typedef edm::DetSet<StripDigiSimLink> LayerLinks; | ||
typedef std::pair<uint32_t, EncodedEventId> SimHitIdpr; | ||
|
||
// Constructor with configurable parameters | ||
GEMHitAssociator(const edm::ParameterSet&, edm::ConsumesCollector && ic); | ||
GEMHitAssociator(const edm::Event& e, const edm::EventSetup& eventSetup, const edm::ParameterSet& conf); | ||
|
||
void initEvent(const edm::Event&, const edm::EventSetup&); | ||
|
||
// Destructor | ||
~GEMHitAssociator(){} | ||
|
||
std::vector<SimHitIdpr> associateRecHit(const TrackingRecHit & hit) const; | ||
|
||
private: | ||
|
||
const DigiSimLinks * theDigiSimLinks; | ||
edm::InputTag GEMdigisimlinkTag; | ||
|
||
bool crossingframe; | ||
bool useGEMs_; | ||
edm::InputTag GEMsimhitsTag; | ||
edm::InputTag GEMsimhitsXFTag; | ||
|
||
edm::EDGetTokenT<CrossingFrame<PSimHit> > GEMsimhitsXFToken_; | ||
edm::EDGetTokenT<edm::PSimHitContainer> GEMsimhitsToken_; | ||
edm::EDGetTokenT<edm::DetSetVector<StripDigiSimLink> > GEMdigisimlinkToken_; | ||
|
||
std::map<unsigned int, edm::PSimHitContainer> _SimHitMap; | ||
|
||
}; | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#include "SimMuon/MCTruth/interface/GEMHitAssociator.h" | ||
|
||
using namespace std; | ||
|
||
// Constructor | ||
GEMHitAssociator::GEMHitAssociator( const edm::ParameterSet& conf, | ||
edm::ConsumesCollector && iC): | ||
GEMdigisimlinkTag(conf.getParameter<edm::InputTag>("GEMdigisimlinkTag")), | ||
// CrossingFrame used or not ? | ||
crossingframe(conf.getParameter<bool>("crossingframe")), | ||
useGEMs_(conf.getParameter<bool>("useGEMs")), | ||
GEMsimhitsTag(conf.getParameter<edm::InputTag>("GEMsimhitsTag")), | ||
GEMsimhitsXFTag(conf.getParameter<edm::InputTag>("GEMsimhitsXFTag")) | ||
{ | ||
if (crossingframe){ | ||
GEMsimhitsXFToken_=iC.consumes<CrossingFrame<PSimHit> >(GEMsimhitsXFTag); | ||
} else if (!GEMsimhitsTag.label().empty()) { | ||
GEMsimhitsToken_=iC.consumes<edm::PSimHitContainer>(GEMsimhitsTag); | ||
} | ||
|
||
GEMdigisimlinkToken_=iC.consumes< edm::DetSetVector<StripDigiSimLink> >(GEMdigisimlinkTag); | ||
} | ||
|
||
GEMHitAssociator::GEMHitAssociator(const edm::Event& e, const edm::EventSetup& eventSetup, const edm::ParameterSet& conf ): | ||
GEMdigisimlinkTag(conf.getParameter<edm::InputTag>("GEMdigisimlinkTag")), | ||
// CrossingFrame used or not ? | ||
crossingframe(conf.getParameter<bool>("crossingframe")), | ||
useGEMs_(conf.getParameter<bool>("useGEMs")), | ||
GEMsimhitsTag(conf.getParameter<edm::InputTag>("GEMsimhitsTag")), | ||
GEMsimhitsXFTag(conf.getParameter<edm::InputTag>("GEMsimhitsXFTag")) | ||
{ | ||
initEvent(e,eventSetup); | ||
} | ||
|
||
void GEMHitAssociator::initEvent(const edm::Event& e, const edm::EventSetup& eventSetup) | ||
{ | ||
|
||
if(useGEMs_){ | ||
|
||
if (crossingframe) { | ||
|
||
edm::Handle<CrossingFrame<PSimHit> > cf; | ||
LogTrace("GEMHitAssociator") <<"getting CrossingFrame<PSimHit> collection - "<<GEMsimhitsXFTag; | ||
e.getByLabel(GEMsimhitsXFTag, cf); | ||
|
||
std::auto_ptr<MixCollection<PSimHit> > | ||
GEMsimhits( new MixCollection<PSimHit>(cf.product()) ); | ||
LogTrace("GEMHitAssociator") <<"... size = "<<GEMsimhits->size(); | ||
|
||
// MixCollection<PSimHit> & simHits = *hits; | ||
|
||
for(MixCollection<PSimHit>::MixItr hitItr = GEMsimhits->begin(); | ||
hitItr != GEMsimhits->end(); ++hitItr) | ||
{ | ||
_SimHitMap[hitItr->detUnitId()].push_back(*hitItr); | ||
} | ||
|
||
} else if (!GEMsimhitsTag.label().empty()) { | ||
edm::Handle<edm::PSimHitContainer> GEMsimhits; | ||
LogTrace("GEMHitAssociator") <<"getting PSimHit collection - "<<GEMsimhitsTag; | ||
e.getByLabel(GEMsimhitsTag, GEMsimhits); | ||
LogTrace("GEMHitAssociator") <<"... size = "<<GEMsimhits->size(); | ||
|
||
// arrange the hits by detUnit | ||
for(edm::PSimHitContainer::const_iterator hitItr = GEMsimhits->begin(); | ||
hitItr != GEMsimhits->end(); ++hitItr) | ||
{ | ||
_SimHitMap[hitItr->detUnitId()].push_back(*hitItr); | ||
} | ||
} | ||
|
||
edm::Handle<DigiSimLinks> digiSimLinks; | ||
LogTrace("GEMHitAssociator") <<"getting GEM Strip DigiSimLink collection - "<<GEMdigisimlinkTag; | ||
e.getByLabel(GEMdigisimlinkTag, digiSimLinks); | ||
theDigiSimLinks = digiSimLinks.product(); | ||
|
||
} | ||
|
||
} | ||
// end of constructor | ||
|
||
std::vector<GEMHitAssociator::SimHitIdpr> GEMHitAssociator::associateRecHit(const TrackingRecHit & hit) const { | ||
|
||
std::vector<SimHitIdpr> matched; | ||
|
||
if(useGEMs_){ | ||
|
||
//std::cout<<"gemboo "<<useGEMs_<<std::endl; | ||
|
||
const TrackingRecHit * hitp = &hit; | ||
const GEMRecHit * gemrechit = dynamic_cast<const GEMRecHit *>(hitp); | ||
|
||
if (gemrechit) { | ||
|
||
GEMDetId gemDetId = gemrechit->gemId(); | ||
int fstrip = gemrechit->firstClusterStrip(); | ||
int cls = gemrechit->clusterSize(); | ||
//int bx = gemrechit->BunchX(); | ||
|
||
DigiSimLinks::const_iterator layerLinks = theDigiSimLinks->find(gemDetId); | ||
|
||
if (layerLinks != theDigiSimLinks->end()) { | ||
|
||
for(int i = fstrip; i < (fstrip+cls); ++i) { | ||
|
||
for(LayerLinks::const_iterator itlink = layerLinks->begin(); itlink != layerLinks->end(); ++itlink) { | ||
|
||
int ch = static_cast<int>(itlink->channel()); | ||
if(ch != i) continue; | ||
|
||
SimHitIdpr currentId(itlink->SimTrackId(), itlink->eventId()); | ||
if(find(matched.begin(),matched.end(),currentId ) == matched.end()) | ||
matched.push_back(currentId); | ||
|
||
} | ||
|
||
} | ||
|
||
}else edm::LogWarning("GEMHitAssociator") | ||
<<"*** WARNING in GEMHitAssociator: GEM layer "<<gemDetId<<" has no DigiSimLinks !"<<std::endl; | ||
|
||
} else edm::LogWarning("GEMHitAssociator")<<"*** WARNING in GEMHitAssociator::associateRecHit, null dynamic_cast !"; | ||
|
||
} | ||
|
||
return matched; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.