38 : omtfConfig(omtfConfig), muonGeometryTokens(muonGeometryTokens) {
58 "stubsInLayersCntByPdgId;;OMTF layer;",
68 "firedLayersCntByPdgId",
77 ptByPdgId = subDir.
make<TH2I>(
"ptByPdgId",
"ptByPdgId bestMatched;;pT [GeV];#", 3, 0, 3, 20, 0, 10);
80 rhoByPdgId = subDir.
make<TH2I>(
"rhoByPdgId",
"rhoByPdgId bestMatched;;Rho [cm];#", 3, 0, 3, 50, 0, 500);
97 std::ostringstream& ostr) {
98 ostr <<
"stubsSimHitsMatching ---------------" << std::endl;
102 ostr <<
"rpcSimHitsHandle: size: " << rpcSimHitsHandle->size() << std::endl;
106 ostr << std::endl <<
"dtSimHitsHandle: size: " << dtSimHitsHandle->size() << std::endl;
110 ostr << std::endl <<
"cscSimHitsHandle: size: " << cscSimHitsHandle->size() << std::endl;
114 ostr <<
"rpcDigiSimLinkHandle: size: " << rpcDigiSimLinkHandle->size() << std::endl;
118 ostr <<
"cscStripDigiSimLinkHandle: size: " << cscStripDigiSimLinkHandle->size() << std::endl;
127 if (procMuon->isValid() && omtfCand) {
131 std::set<MatchedTrackInfo> matchedTrackInfos;
132 ostr << board.name() <<
" " << *procMuon << std::endl;
134 auto& gpResult = procMuon->getGpResult();
135 for (
unsigned int iLogicLayer = 0; iLogicLayer < gpResult.getStubResults().size(); ++iLogicLayer) {
136 auto& stub = gpResult.getStubResults()[iLogicLayer].getMuonStub();
137 if (stub && gpResult.isLayerFired(iLogicLayer)) {
141 DetId stubDetId(stub->detId);
144 <<
"!!!!!!!!!!!!!!!!!!!!!!!! PROBLEM: hit in unknown Det, detID: " << stubDetId.
det() << std::endl;
149 ostr << (*stub) <<
"\nstubGlobalPhi " << stubGlobalPhi << std::endl;
151 int matchedMuonHits = 0;
152 int matchedNotMuonHits = 0;
158 for (
auto& simHit : *(rpcSimHitsHandle.
product())) {
159 if (stubDetId.
rawId() == simHit.detUnitId()) {
161 auto strip = roll->
strip(simHit.localPosition());
164 if (
abs(stubGlobalPhi - simHitStripGlobalPhi) < 0.02) {
165 if (
abs(simHit.particleType()) == 13)
168 matchedNotMuonHits++;
171 matchedTrackInfos.insert(
MatchedTrackInfo(simHit.eventId().event(), simHit.trackId()));
174 ostr <<
" simHitStripGlobalPhi " << std::setw(10) << simHitStripGlobalPhi <<
" strip " << strip
175 <<
" particleType: " << simHit.particleType() <<
" event: " << simHit.eventId().event()
176 <<
" trackId " << simHit.trackId() <<
" processType " << simHit.processType() <<
" detUnitId "
177 << simHit.detUnitId() <<
" "
182 <<
" entryPoint: x " << std::setw(10) << simHit.entryPoint().x() <<
" y " << std::setw(10)
183 << simHit.entryPoint().y() <<
" timeOfFlight " << simHit.timeOfFlight() << std::endl;
187 auto rpcDigiSimLinkDetSet = rpcDigiSimLinkHandle.
product()->find(stub->detId);
189 if (rpcDigiSimLinkDetSet != rpcDigiSimLinkHandle.
product()->end()) {
190 ostr <<
"rpcDigiSimLinkDetSet: detId " << rpcDigiSimLinkDetSet->detId() <<
" size "
191 << rpcDigiSimLinkDetSet->size() <<
"\n";
192 for (
auto& rpcDigiSimLink : *rpcDigiSimLinkDetSet) {
194 auto strip = rpcDigiSimLink.getStrip();
197 if (
abs(stubGlobalPhi - simHitStripGlobalPhi) < 0.02) {
198 auto matchedTrackInfo = matchedTrackInfos.insert(
199 MatchedTrackInfo(rpcDigiSimLink.getEventId().event(), rpcDigiSimLink.getTrackId()));
200 matchedTrackInfo.first->matchedDigiCnt.at(iLogicLayer)++;
203 ostr <<
" simHitStripGlobalPhi " << std::setw(10) << simHitStripGlobalPhi <<
" strip " << strip
204 <<
" particleType: " << rpcDigiSimLink.getParticleType()
205 <<
" event: " << rpcDigiSimLink.getEventId().event() <<
" trackId " << rpcDigiSimLink.getTrackId()
206 <<
" processType " << rpcDigiSimLink.getProcessType() <<
" detUnitId "
207 << rpcDigiSimLink.getDetUnitId() <<
" "
212 <<
" entryPoint: x " << std::setw(10) << rpcDigiSimLink.getEntryPoint().x() <<
" y "
213 << std::setw(10) << rpcDigiSimLink.getEntryPoint().y() <<
" timeOfFlight "
214 << rpcDigiSimLink.getTimeOfFlight() << std::endl;
222 for (
auto& simHit : *(dtSimHitsHandle.
product())) {
227 auto simHitGlobalPoint = layer->
toGlobal(simHit.localPosition());
229 ostr <<
" simHitGlobalPoint.phi " << std::setw(10)
230 << simHitGlobalPoint.
phi()
232 <<
" particleType: " << simHit.particleType() <<
" event: " << simHit.eventId().event()
233 <<
" trackId " << simHit.trackId() <<
" processType " << simHit.processType() <<
" detUnitId "
234 << simHit.detUnitId() <<
" "
239 <<
" localPosition: x " << std::setw(10) << simHit.localPosition().x() <<
" y " << std::setw(10)
240 << simHit.localPosition().y() <<
" timeOfFlight " << simHit.timeOfFlight() << std::endl;
245 for (
auto superlayer : chamber->superLayers()) {
246 if (superlayer->id().superLayer() == 2)
248 for (
auto layer : superlayer->layers()) {
249 auto dtDigiSimLinks = dtDigiSimLinkHandle.
product()->get(
layer->id());
250 ostr <<
"dt layer " <<
layer->id() <<
"\n";
251 auto dtDigiSimLink = dtDigiSimLinks.first;
253 for (; dtDigiSimLink != dtDigiSimLinks.second; dtDigiSimLink++) {
255 auto wire = dtDigiSimLink->wire();
257 auto wireX =
layer->specificTopology().wirePosition(wire);
260 auto digiWireGlobal =
layer->toGlobal(point);
262 if (
abs(stubGlobalPhi - digiWireGlobal.phi()) < 0.03) {
263 auto matchedTrackInfo = matchedTrackInfos.insert(
264 MatchedTrackInfo(dtDigiSimLink->eventId().event(), dtDigiSimLink->SimTrackId()));
265 matchedTrackInfo.first->matchedDigiCnt.at(iLogicLayer)++;
269 <<
" digiWireGlobalPhi " << std::setw(10) << digiWireGlobal.phi() <<
" wire "
272 <<
" event: " << dtDigiSimLink->eventId().event() <<
" trackId "
273 << dtDigiSimLink->SimTrackId()
292 for (
auto& simHit : *(cscSimHitsHandle.
product())) {
294 auto chamber = layer->
chamber();
295 if (stubDetId.
rawId() == chamber->id().rawId()) {
296 auto simHitStrip = layer->
geometry()->
strip(simHit.localPosition());
297 auto simHitGlobalPoint = layer->
toGlobal(simHit.localPosition());
300 ostr <<
" simHit: gloablPoint phi " << simHitGlobalPoint.
phi() <<
" stripGlobalPhi "
301 << simHitStripGlobalPhi.phi() <<
" strip " << simHitStrip
302 <<
" particleType: " << simHit.particleType() <<
" event: " << simHit.eventId().event()
303 <<
" trackId " << simHit.trackId() <<
" processType " << simHit.processType() <<
" detUnitId "
304 << simHit.detUnitId() <<
" "
309 << simHit.timeOfFlight()
311 <<
" x " << simHit.localPosition().x() <<
" y " << simHit.localPosition().y()
318 for (
auto*
layer : chamber->layers()) {
319 auto cscDigiSimLinkDetSet = cscStripDigiSimLinkHandle.
product()->find(
layer->id());
320 if (cscDigiSimLinkDetSet != cscStripDigiSimLinkHandle.
product()->end()) {
321 ostr <<
"cscDigiSimLinkDetSet: detId " << cscDigiSimLinkDetSet->detId() <<
" " <<
layer->id()
322 <<
" size " << cscDigiSimLinkDetSet->size() <<
"\n";
323 for (
auto& cscDigiSimLink : *cscDigiSimLinkDetSet) {
325 auto strip = cscDigiSimLink.channel();
326 auto digiStripGlobalPhi =
layer->centerOfStrip(
strip).phi();
328 if (
abs(stubGlobalPhi - digiStripGlobalPhi) < 0.03) {
329 auto matchedTrackInfo = matchedTrackInfos.insert(
330 MatchedTrackInfo(cscDigiSimLink.eventId().event(), cscDigiSimLink.SimTrackId()));
331 matchedTrackInfo.first->matchedDigiCnt.at(iLogicLayer)++;
334 <<
" digiStripGlobalPhi " << std::setw(10) << digiStripGlobalPhi <<
" strip "
337 <<
" event: " << cscDigiSimLink.eventId().event() <<
" trackId "
338 << cscDigiSimLink.SimTrackId()
351 ostr <<
"cscDigiSimLinkDetSet not found for detId " <<
layer->id();
358 ostr <<
"" << std::endl;
362 ostr << board.name() <<
" " << *procMuon << std::endl;
363 ostr << procMuon->getGpResult() << std::endl << std::endl;
365 int maxMatchedStubs = 0;
367 for (
auto matchedTrackInfo : matchedTrackInfos) {
368 ostr <<
"matchedTrackInfo eventNum " << matchedTrackInfo.eventNum <<
" trackId " << matchedTrackInfo.trackId
372 for (
auto& trackingParticle :
373 *trackingParticleHandle.
product()) {
374 if (trackingParticle.eventId().event() == matchedTrackInfo.eventNum &&
375 trackingParticle.g4Tracks().at(0).trackId() == matchedTrackInfo.trackId) {
377 matchedPart = &trackingParticle;
379 ostr <<
"trackingParticle: pdgId " << std::setw(3) << trackingParticle.
pdgId() <<
" event " << std::setw(4)
380 << trackingParticle.eventId().event() <<
" trackId " << std::setw(8)
381 << trackingParticle.g4Tracks().at(0).trackId() <<
" pt " << std::setw(9) << trackingParticle.pt()
382 <<
" eta " << std::setw(9) << trackingParticle.momentum().eta() <<
" phi " << std::setw(9)
383 << trackingParticle.momentum().phi() << std::endl;
385 if (trackingParticle.parentVertex().isNonnull()) {
386 ostr <<
"parentVertex Rho " << trackingParticle.parentVertex()->position().Rho() <<
" z "
387 << trackingParticle.parentVertex()->position().z() <<
" R "
388 << trackingParticle.parentVertex()->position().R() <<
" eta "
389 << trackingParticle.parentVertex()->position().eta() <<
" phi "
390 << trackingParticle.parentVertex()->position().phi() << std::endl;
392 for (
auto& parentTrack : trackingParticle.parentVertex()->sourceTracks()) {
393 ostr <<
"parentTrack: pdgId " << std::setw(3) << parentTrack->pdgId() <<
" event " << std::setw(4)
394 << parentTrack->eventId().event() <<
" trackId " << std::setw(8)
395 << parentTrack->g4Tracks().at(0).trackId() <<
" pt " << std::setw(9) << parentTrack->pt() <<
" eta "
396 << std::setw(9) << parentTrack->momentum().eta() <<
" phi " << std::setw(9)
397 << parentTrack->momentum().phi() << std::endl;
405 int matchedStubsCnt = 0;
406 for (
unsigned int iLayer = 0; iLayer < matchedTrackInfo.matchedDigiCnt.size(); iLayer++) {
407 ostr <<
" matchedDigiCnt in layer " << iLayer <<
" " << matchedTrackInfo.matchedDigiCnt[iLayer] <<
"\n";
408 if (matchedTrackInfo.matchedDigiCnt[iLayer] > 0) {
418 if (maxMatchedStubs < matchedStubsCnt) {
419 maxMatchedStubs = matchedStubsCnt;
420 bestMatchedPart = matchedPart;
423 if (bestMatchedPart) {
428 ptByPdgId->Fill(str.c_str(), bestMatchedPart->
pt(), 1);
434 ostr <<
"bestMatchedPart: pdgId " << std::setw(3) << bestMatchedPart->
pdgId() <<
" event " << std::setw(4)
435 << bestMatchedPart->
eventId().
event() <<
" trackId " << std::setw(8)
436 << bestMatchedPart->
g4Tracks().at(0).trackId() <<
"\n\n";
float strip(const LocalPoint &lp) const
LocalPoint centreOfStrip(int strip) const
bool isNonnull() const
Checks for non-null.
int event() const
get the contents of the subdetector field (should be protected?)
const std::vector< SimTrack > & g4Tracks() const
edm::ESGetToken< CSCGeometry, MuonGeometryRecord > cscGeometryEsToken
DTLayerId id() const
Return the DetId of this SL.
int pdgId() const
PDG ID.
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
virtual ~StubsSimHitsMatcher()
edm::ESWatcher< MuonGeometryRecord > muonGeometryRecordWatcher
muonGeometryTokens({esConsumes< RPCGeometry, MuonGeometryRecord, edm::Transition::BeginRun >(), esConsumes< CSCGeometry, MuonGeometryRecord, edm::Transition::BeginRun >(), esConsumes< DTGeometry, MuonGeometryRecord, edm::Transition::BeginRun >()})
Geom::Phi< T > phi() const
constexpr uint32_t rawId() const
get the raw id
edm::ESHandle< RPCGeometry > _georpc
double pt() const
Transverse momentum. Note this is taken from the first SimTrack only.
std::string to_string(const V &value)
unsigned int nLayers() const
Log< level::Error, false > LogError
TH2I * stubsInLayersCntByPdgId
constexpr std::array< uint8_t, layerIndexSize > layer
edm::ESGetToken< RPCGeometry, MuonGeometryRecord > rpcGeometryEsToken
double procHwPhiToGlobalPhi(int procHwPhi, int procHwPhi0) const
edm::ESHandle< CSCGeometry > _geocsc
StubsSimHitsMatcher(const edm::ParameterSet &edmCfg, const OMTFConfiguration *omtfConfig, const MuonGeometryTokens &muonGeometryTokens)
const OMTFConfiguration * omtfConfig
TH2I * firedLayersCntByPdgId
DTChamberId id() const
Return the DTChamberId of this chamber.
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum) ...
const MuonGeometryTokens & muonGeometryTokens
Abs< T >::type abs(const T &t)
edm::InputTag rpcDigiSimLinkInputTag
float strip(const LocalPoint &lp) const
T * make(const Args &...args) const
make new ROOT object
const TrackingVertexRef & parentVertex() const
edm::InputTag cscStripDigiSimLinksInputTag
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
TH1I * bestMatchedTracksPdgIds
edm::InputTag rpcSimHitsInputTag
edm::InputTag dtDigiSimLinksInputTag
const tftype trackFinderType() const
Get track-finder which found the muon (bmtf, emtf_pos/emtf_neg or omtf_pos/omtf_neg) ...
edm::ESHandle< DTGeometry > _geodt
GlobalPoint centerOfStrip(int strip) const
const int processor() const
Get processor ID on which the candidate was found (0..5 for OMTF/EMTF; 0..11 for BMTF) ...
edm::ESGetToken< DTGeometry, MuonGeometryRecord > dtGeometryEsToken
edm::InputTag cscSimHitsInputTag
T const * product() const
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
edm::InputTag trackingParticleTag
T getParameter(std::string const &) const
const DTChamber * chamber() const
TH1I * allMatchedTracksPdgIds
bool check(const edm::EventSetup &iSetup)
EncodedEventId eventId() const
Signal source, crossing number.
void beginRun(edm::EventSetup const &eventSetup)
Monte Carlo truth information used for tracking validation.
void match(const edm::Event &iEvent, const l1t::RegionalMuonCand *omtfCand, const AlgoMuonPtr &procMuon, std::ostringstream &ostr)
std::shared_ptr< AlgoMuon > AlgoMuonPtr
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
const CSCChamber * chamber() const
const CSCLayerGeometry * geometry() const
edm::InputTag dtSimHitsInputTag
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
bool isBendingLayer(unsigned int iLayer) const override
constexpr Detector det() const
get the detector field from this detid