Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-03-17 11:12:54

0001 /*
0002  * EmulationObserverBase.cc
0003  *
0004  *  Created on: Aug 18, 2021
0005  *      Author: kbunkow
0006  */
0007 
0008 #include "L1Trigger/L1TMuonOverlapPhase1/interface/Tools/EmulationObserverBase.h"
0009 
0010 #include "Math/VectorUtil.h"
0011 
0012 EmulationObserverBase::EmulationObserverBase(const edm::ParameterSet& edmCfg, const OMTFConfiguration* omtfConfig)
0013     : edmCfg(edmCfg), omtfConfig(omtfConfig), simMuon(nullptr) {}
0014 
0015 EmulationObserverBase::~EmulationObserverBase() {
0016   // TODO Auto-generated destructor stub
0017 }
0018 
0019 void EmulationObserverBase::observeProcesorEmulation(unsigned int iProcessor,
0020                                                      l1t::tftype mtfType,
0021                                                      const std::shared_ptr<OMTFinput>& input,
0022                                                      const AlgoMuons& algoCandidates,
0023                                                      const AlgoMuons& gbCandidates,
0024                                                      const std::vector<l1t::RegionalMuonCand>& candMuons) {
0025   unsigned int procIndx = omtfConfig->getProcIndx(iProcessor, mtfType);
0026 
0027   unsigned int i = 0;
0028   for (auto& gbCandidate : gbCandidates) {
0029     if (gbCandidate->getGoldenPatern() != nullptr &&
0030         gbCandidate->getGpResult().getFiredLayerCnt() > omtfCand->getGpResult().getFiredLayerCnt()) {
0031       //LogTrace("l1tOmtfEventPrint") <<__FUNCTION__<<":"<<__LINE__<<" gbCandidate "<<gbCandidate<<" "<<std::endl;
0032       omtfCand = gbCandidate;
0033 
0034       candProcIndx = procIndx;
0035 
0036       //should be good, as the regionalMuonCand is created for every  gbCandidate in OMTFProcessor<GoldenPatternType>::getFinalcandidates
0037       regionalMuonCand = candMuons.at(i);
0038 
0039       //this->algoCandidates = algoCandidates; //TODO uncomment if needed
0040     }
0041     i++;
0042   }
0043 
0044   //////////////////////debug printout/////////////////////////////
0045   /*if(omtfCand->isValid()) { //TODO check this condition
0046     GoldenPatternWithStat* omtfCandGp = static_cast<GoldenPatternWithStat*>(omtfCand.getGoldenPatern());
0047     if( omtfCandGp->key().thePt > 100 && exptCandGp->key().thePt <= 15 ) {
0048       //LogTrace("l1tOmtfEventPrint")  <<iEvent.id()<<std::endl;
0049       LogTrace("l1tOmtfEventPrint") <<" ptSim "<<ptSim<<" chargeSim "<<chargeSim<<std::endl;
0050       LogTrace("l1tOmtfEventPrint") <<"iProcessor "<<iProcessor<<" exptCandGp "<<exptCandGp->key()<<std::endl;
0051       LogTrace("l1tOmtfEventPrint")  <<"iProcessor "<<iProcessor<<" omtfCandGp "<<omtfCandGp->key()<<std::endl;
0052       LogTrace("l1tOmtfEventPrint")  <<"omtfResult "<<std::endl<<omtfResult<<std::endl;
0053       int refHitNum = omtfCand.getRefHitNumber();
0054       LogTrace("l1tOmtfEventPrint")  <<"other gps results"<<endl;
0055       for(auto& gp : goldenPatterns) {
0056         if(omtfResult.getFiredLayerCnt() == gp->getResults()[procIndx][iRefHit].getFiredLayerCnt() )
0057         {
0058           LogTrace("l1tOmtfEventPrint")  <<gp->key()<<std::endl<<gp->getResults()[procIndx][iRefHit]<<std::endl;
0059         }
0060       }
0061       LogTrace("l1tOmtfEventPrint")<<std::endl;
0062     }
0063   }*/
0064 }
0065 
0066 void EmulationObserverBase::observeEventBegin(const edm::Event& iEvent) {
0067   omtfCand.reset(new AlgoMuon());
0068   candProcIndx = 0xffff;
0069 
0070   simMuon = findSimMuon(iEvent);
0071   //LogTrace("l1tOmtfEventPrint") <<__FUNCTION__<<":"<<__LINE__<<" evevt "<<iEvent.id().event()<<" simMuon pt "<<simMuon->momentum().pt()<<" GeV "<<std::endl;
0072 }
0073 
0074 const SimTrack* EmulationObserverBase::findSimMuon(const edm::Event& event, const SimTrack* previous) {
0075   const SimTrack* result = nullptr;
0076   if (edmCfg.exists("simTracksTag") == false)
0077     return result;
0078 
0079   edm::Handle<edm::SimTrackContainer> simTks;
0080   event.getByLabel(edmCfg.getParameter<edm::InputTag>("simTracksTag"), simTks);
0081 
0082   //LogTrace("l1tOmtfEventPrint")<<__FUNCTION__<<" simTks->size() "<<simTks->size()<<std::endl;
0083   for (std::vector<SimTrack>::const_iterator it = simTks->begin(); it < simTks->end(); it++) {
0084     const SimTrack& aTrack = *it;
0085     if (!(aTrack.type() == 13 || aTrack.type() == -13))
0086       continue;
0087     if (previous && ROOT::Math::VectorUtil::DeltaR(aTrack.momentum(), previous->momentum()) < 0.07)
0088       continue;
0089     if (!result || aTrack.momentum().pt() > result->momentum().pt())
0090       result = &aTrack;
0091   }
0092   return result;
0093 }