From 5fb9eb43542c479c674573fda9269de808e06f87 Mon Sep 17 00:00:00 2001 From: Marcin Date: Sun, 21 Feb 2016 18:07:21 +0100 Subject: [PATCH 1/3] changes from Pawel towards separation of object, definitely not final --- L1Trigger/L1TMuonOverlap/interface/AlgoMuon.h | 61 +++++ .../L1TMuonOverlap/interface/GhostBuster.h | 21 ++ .../L1TMuonOverlap/interface/InternalObj.h | 32 --- .../interface/OMTFReconstruction.h | 81 ++++++ .../L1TMuonOverlap/interface/OMTFResult.h | 6 + .../L1TMuonOverlap/interface/OMTFSorter.h | 37 ++- .../interface/XMLConfigWriter.h | 4 +- .../plugins/L1TMuonOverlapTrackProducer.cc | 131 ++------- .../plugins/L1TMuonOverlapTrackProducer.h | 29 +- L1Trigger/L1TMuonOverlap/src/AlgoMuon.cc | 28 ++ L1Trigger/L1TMuonOverlap/src/GhostBuster.cc | 62 +++++ L1Trigger/L1TMuonOverlap/src/InternalObj.cc | 18 -- L1Trigger/L1TMuonOverlap/src/OMTFProcessor.cc | 35 +-- .../L1TMuonOverlap/src/OMTFReconstruction.cc | 253 ++++++++++++++++++ L1Trigger/L1TMuonOverlap/src/OMTFResult.cc | 8 + L1Trigger/L1TMuonOverlap/src/OMTFSorter.cc | 241 ++++++++--------- .../L1TMuonOverlap/src/XMLConfigWriter.cc | 30 ++- 17 files changed, 718 insertions(+), 359 deletions(-) create mode 100644 L1Trigger/L1TMuonOverlap/interface/AlgoMuon.h create mode 100644 L1Trigger/L1TMuonOverlap/interface/GhostBuster.h delete mode 100644 L1Trigger/L1TMuonOverlap/interface/InternalObj.h create mode 100644 L1Trigger/L1TMuonOverlap/interface/OMTFReconstruction.h create mode 100644 L1Trigger/L1TMuonOverlap/src/AlgoMuon.cc create mode 100644 L1Trigger/L1TMuonOverlap/src/GhostBuster.cc delete mode 100644 L1Trigger/L1TMuonOverlap/src/InternalObj.cc create mode 100644 L1Trigger/L1TMuonOverlap/src/OMTFReconstruction.cc diff --git a/L1Trigger/L1TMuonOverlap/interface/AlgoMuon.h b/L1Trigger/L1TMuonOverlap/interface/AlgoMuon.h new file mode 100644 index 0000000000000..a213054047871 --- /dev/null +++ b/L1Trigger/L1TMuonOverlap/interface/AlgoMuon.h @@ -0,0 +1,61 @@ +#ifndef AlgoMuon_H +#define AlgoMuon_H + +#include + +class AlgoMuon{ + + public: + + // AlgoMuon() : pt(-1.), eta(99.), phi(9999.), disc(-999), bx(0), q(-1), charge(99), refLayer(-1), hits(0) {} // the old one version + AlgoMuon() : m_disc(-999), m_phi(9999), m_eta(99), m_refLayer(-1), m_hits(0), m_q(-1), m_bx(0), m_pt(-1), m_charge(99) {} + AlgoMuon(int disc=-999, int phi=9999, int eta=99, int refLayer=-1, + int hits=0, int q=-1, int bx=0, int pt=-1, int charge=99): + m_disc(disc), m_phi(phi), m_eta(eta), m_refLayer(refLayer), + m_hits(hits), m_q(q), m_bx(bx), m_pt(pt), m_charge(charge) {} + + int getDisc() const { return m_disc; } + int getPhi() const { return m_phi; } + int getEta() const { return m_eta; } + int getRefLayer() const { return m_refLayer; } + int getHits() const { return m_hits; } + int getQ() const { return m_q; } + int getBx() const { return m_bx; } + int getPt() const { return m_pt; } + int getCharge() const { return m_charge; } + int getPhiRHit() const { return m_phiRHit; } + + void setDisc(int disc) { m_disc = disc; } + void setPhi(int phi) { m_phi = phi; } + void setEta(int eta) { m_eta = eta; } + void setRefLayer(int refLayer) { m_refLayer = refLayer; } + void setHits(int hits) { m_hits = hits; } + void setQ(int q) { m_q = q; } + void setBx(int bx) { m_bx = bx; } + void setPt(int pt) { m_pt = pt; } + void setCharge(int charge) { m_charge = charge; } + void setPhiRHit(int phiRHit) { m_phiRHit = phiRHit; } + + bool isValid() const; + + bool operator< (const AlgoMuon & o) const; + + friend std::ostream & operator<< (std::ostream &out, const AlgoMuon &o); + + private: + + int m_disc; + int m_phi; + int m_eta; + int m_refLayer; + int m_hits; + int m_q; + int m_bx; + int m_pt; + int m_charge; + int m_phiRHit; + // to add + // int m_pdf; + +}; +#endif diff --git a/L1Trigger/L1TMuonOverlap/interface/GhostBuster.h b/L1Trigger/L1TMuonOverlap/interface/GhostBuster.h new file mode 100644 index 0000000000000..5b9fa735045b6 --- /dev/null +++ b/L1Trigger/L1TMuonOverlap/interface/GhostBuster.h @@ -0,0 +1,21 @@ +#ifndef OMTF_GhostBuster_H +#define OMTF_GhostBuster_H + +#include +#include + +#include +#include + +#include + +#include "L1Trigger/L1TMuonOverlap/interface/AlgoMuon.h" + +class OMTFGhostBuster { + + public: + + void select(std::vector & refHitCands, int charge=0); + +}; +#endif \ No newline at end of file diff --git a/L1Trigger/L1TMuonOverlap/interface/InternalObj.h b/L1Trigger/L1TMuonOverlap/interface/InternalObj.h deleted file mode 100644 index 6651fee6cb9d4..0000000000000 --- a/L1Trigger/L1TMuonOverlap/interface/InternalObj.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef InternalObj_H -#define InternalObj_H - -#include - -struct InternalObj{ - - float pt, eta, phi; - float disc; - int bx, q, charge; - int refLayer; - int hits; - - InternalObj() : pt(-1.), eta(99.), phi(9999.), disc(-999), bx(0), q(-1), charge(99), refLayer(-1) {} - InternalObj(float pt, float eta, float phi, - float disc=-999, int bx=0, int q=-1, - int charge=99, int refLayer=-1) : - pt(pt), eta(eta), phi(phi), disc(disc), bx(bx), q(q), charge(charge), refLayer(refLayer), hits(0) {} - - bool isValid() const { return q >= 0;} - - bool operator< (const InternalObj & o) const { - if(q > o.q) return true; - else if(q==o.q && disc > o.disc) return true; - else return false; - - } - - friend std::ostream & operator<< (std::ostream &out, const InternalObj &o); - -}; -#endif diff --git a/L1Trigger/L1TMuonOverlap/interface/OMTFReconstruction.h b/L1Trigger/L1TMuonOverlap/interface/OMTFReconstruction.h new file mode 100644 index 0000000000000..876ba90932b70 --- /dev/null +++ b/L1Trigger/L1TMuonOverlap/interface/OMTFReconstruction.h @@ -0,0 +1,81 @@ +#ifndef OMTFReconstruction_H +#define OMTFReconstruction_H + +#include "xercesc/util/XercesDefs.hpp" + +#include "DataFormats/L1TMuon/interface/RegionalMuonCand.h" +#include "DataFormats/L1TMuon/interface/RegionalMuonCandFwd.h" + +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" +#include "FWCore/Framework/interface/EDProducer.h" + +#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h" +#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThContainer.h" +#include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h" +#include "DataFormats/RPCDigi/interface/RPCDigiCollection.h" + +#include "L1Trigger/L1TMuonOverlap/interface/OMTFinputMaker.h" +#include "L1Trigger/L1TMuonOverlap/interface/OMTFSorter.h" +#include "L1Trigger/L1TMuonOverlap/interface/GhostBuster.h" + +class L1TMuonOverlapParams; +class OMTFProcessor; +class OMTFConfiguration; +class OMTFConfigMaker; +class XMLConfigWriter; + +namespace XERCES_CPP_NAMESPACE{ + class DOMElement; + class DOMDocument; + class DOMImplementation; +} + +typedef std::vector< std::pair > > AlgoMuonResults; + +class OMTFReconstruction { + public: + OMTFReconstruction(); + + OMTFReconstruction(const edm::ParameterSet&); + + ~OMTFReconstruction(); + + void beginJob(); + + void endJob(); + + void beginRun(edm::Run const& run, edm::EventSetup const& iSetup); + + void algoBeginJob(); + + // not working + AlgoMuonResults algoReconstruct(const edm::Event&, const edm::EventSetup&); + + std::auto_ptr reconstruct(const edm::Event&, const edm::EventSetup&); + + // std::auto_ptr getAlgoMuonResults(); + + // private: + + edm::ParameterSet m_Config; + bool dumpResultToXML, dumpDetailedResultToXML; + + ///OMTF objects + OMTFConfiguration *m_OMTFConfig; + OMTFinputMaker m_InputMaker; + OMTFSorter m_Sorter; + OMTFGhostBuster m_GhostBuster; + OMTFProcessor *m_OMTF; + OMTFProcessor *m_AlgoOMTF; + AlgoMuonResults m_AlgoMuonResults; + /// + xercesc::DOMElement *aTopElement; + OMTFConfigMaker *m_OMTFConfigMaker; + XMLConfigWriter *m_Writer; + +}; + +#endif \ No newline at end of file diff --git a/L1Trigger/L1TMuonOverlap/interface/OMTFResult.h b/L1Trigger/L1TMuonOverlap/interface/OMTFResult.h index d3338290d708a..2fd35a3386661 100644 --- a/L1Trigger/L1TMuonOverlap/interface/OMTFResult.h +++ b/L1Trigger/L1TMuonOverlap/interface/OMTFResult.h @@ -25,6 +25,9 @@ class OMTFResult{ const OMTFResult::vector1D & getHitsWord() const { return hitsBits;} + const OMTFResult::vector1D & getRefPhiRHits() const {return refPhiRHit1D;} + + void setRefPhiRHits(unsigned int iRefLayer, int iRefPhiRHit); void addResult(unsigned int iRefLayer, unsigned int iLayer, @@ -60,6 +63,9 @@ class OMTFResult{ ///Words representing nimber of hit layers for each reference layer vector1D hitsBits; + + ///Reference phi for each reference layer - the input value + vector1D refPhiRHit1D; }; diff --git a/L1Trigger/L1TMuonOverlap/interface/OMTFSorter.h b/L1Trigger/L1TMuonOverlap/interface/OMTFSorter.h index a5d1c2ae51807..8f668966f0a92 100644 --- a/L1Trigger/L1TMuonOverlap/interface/OMTFSorter.h +++ b/L1Trigger/L1TMuonOverlap/interface/OMTFSorter.h @@ -9,8 +9,8 @@ #include "L1Trigger/L1TMuonOverlap/interface/OMTFResult.h" #include "L1Trigger/L1TMuonOverlap/interface/OMTFProcessor.h" -#include "L1Trigger/L1TMuonOverlap/interface/InternalObj.h" - +#include "L1Trigger/L1TMuonOverlap/interface/AlgoMuon.h" +#include "L1Trigger/L1TMuonOverlap/interface/GhostBuster.h" class OMTFSorter{ @@ -20,30 +20,39 @@ class OMTFSorter{ ///First for each region cone find a best candidate using sortRegionResults() ///Then select best candidate amongs found for each logic region. ///The sorting is made for candidates with a given charge - InternalObj sortProcessorResults(const std::vector & procResults, + void sortProcessorResults(const std::vector & procResults, + std::vector & refHitCands, int charge=0); - // - void sortProcessorResults(const std::vector & procResults, - std::vector & refHitCleanCands, + + AlgoMuon sortProcessorResults(const std::vector & procResults, + int charge=0); + + + void sortRefHitResults(const std::vector & procResults, + std::vector & refHitCleanCands, int charge=0); + + void processCandidates(unsigned int iProcessor, int bx, + std::auto_ptr & myCands, + const l1t::RegionalMuonCandBxCollection & myOTFCandidates, + l1t::tftype mtfType); + ///Sort all processor results. ///First for each region cone find a best candidate using sortRegionResults() ///Then select best candidate amongs found for each logic region l1t::RegionalMuonCand sortProcessor(const std::vector & procResults, - int charge=0); - + int charge=0); // - void sortProcessorAndFillCandidates(unsigned int iProcessor, l1t::tftype mtfType, - const std::vector & procResults, - l1t::RegionalMuonCandBxCollection & sortedCands, - int bx, int charge=0); + void rewriteToRegionalMuon(const std::vector & AlgoCands, + l1t::RegionalMuonCandBxCollection & sortedCands, + int bx, int charge=0); ///Sort results from a single reference hit. ///Select candidate with highest number of hit layers ///Then select a candidate with largest likelihood value and given charge ///as we allow two candidates with opposite charge from single 10deg region - InternalObj sortRefHitResults(const OMTFProcessor::resultsMap & aResultsMap, + AlgoMuon sortRefHitResults(const OMTFProcessor::resultsMap & aResultsMap, int charge=0); private: @@ -61,7 +70,7 @@ class OMTFSorter{ ///The output tuple contains (nHitsMax, pdfValMax, refPhi, refLayer, hitsWord, refEta) ///hitsWord codes number of layers hit: hitsWord= sum 2**iLogicLayer, ///where sum runs over layers which were hit - std::tuple sortSingleResult(const OMTFResult & aResult); + AlgoMuon sortSingleResult(const OMTFResult & aResult); }; diff --git a/L1Trigger/L1TMuonOverlap/interface/XMLConfigWriter.h b/L1Trigger/L1TMuonOverlap/interface/XMLConfigWriter.h index f9840ee4893e9..6126da843b240 100644 --- a/L1Trigger/L1TMuonOverlap/interface/XMLConfigWriter.h +++ b/L1Trigger/L1TMuonOverlap/interface/XMLConfigWriter.h @@ -12,7 +12,7 @@ class GoldenPattern; class OMTFConfiguration; class OMTFinput; class OMTFResult; -class InternalObj; +class AlgoMuon; struct Key; namespace XERCES_CPP_NAMESPACE{ @@ -40,7 +40,7 @@ class XMLConfigWriter{ void writeCandidateData(xercesc::DOMElement *aTopElement, unsigned int iRefHit, - const InternalObj & aCand); + const AlgoMuon & aCand); void writeResultsData(xercesc::DOMElement *aTopElement, unsigned int iRegion, diff --git a/L1Trigger/L1TMuonOverlap/plugins/L1TMuonOverlapTrackProducer.cc b/L1Trigger/L1TMuonOverlap/plugins/L1TMuonOverlapTrackProducer.cc index dab3303e7298b..90eb184a948f3 100644 --- a/L1Trigger/L1TMuonOverlap/plugins/L1TMuonOverlapTrackProducer.cc +++ b/L1Trigger/L1TMuonOverlap/plugins/L1TMuonOverlapTrackProducer.cc @@ -4,6 +4,9 @@ #include "FWCore/MessageLogger/interface/MessageLogger.h" +#include "DataFormats/L1TMuon/interface/RegionalMuonCand.h" +#include "DataFormats/L1TMuon/interface/RegionalMuonCandFwd.h" + #include "CondFormats/DataRecord/interface/L1TMuonOverlapParamsRcd.h" #include "CondFormats/L1TObjects/interface/L1TMuonOverlapParams.h" @@ -16,7 +19,7 @@ #include "L1Trigger/RPCTrigger/interface/RPCConst.h" L1TMuonOverlapTrackProducer::L1TMuonOverlapTrackProducer(const edm::ParameterSet& cfg) - :theConfig(cfg), myOMTFConfig(0), myOMTF(0), aTopElement(0), myOMTFConfigMaker(0), myWriter(0) { + :theConfig(cfg), m_Reconstruction(cfg) { produces("OMTF"); @@ -25,149 +28,49 @@ L1TMuonOverlapTrackProducer::L1TMuonOverlapTrackProducer(const edm::ParameterSet inputTokenCSC = consumes(theConfig.getParameter("srcCSC")); inputTokenRPC = consumes(theConfig.getParameter("srcRPC")); - if(!theConfig.exists("omtf")){ - edm::LogError("L1TMuonOverlapTrackProducer")<<"omtf configuration not found in cfg.py"; - } - - dumpResultToXML = theConfig.getParameter("dumpResultToXML"); - dumpDetailedResultToXML = theConfig.getParameter("dumpDetailedResultToXML"); - theConfig.getParameter("XMLDumpFileName"); - - if(dumpResultToXML){ - myWriter = new XMLConfigWriter(); - std::string fName = "OMTF"; - myWriter->initialiseXMLDocument(fName); - } } ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// -L1TMuonOverlapTrackProducer::~L1TMuonOverlapTrackProducer(){ - - delete myOMTFConfig; - delete myOMTF; - - if (myWriter) delete myWriter; - +L1TMuonOverlapTrackProducer::~L1TMuonOverlapTrackProducer(){ } ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// void L1TMuonOverlapTrackProducer::beginJob(){ - if(theConfig.exists("omtf")){ - myOMTFConfig = new OMTFConfiguration(theConfig.getParameter("omtf")); - myOMTF = new OMTFProcessor(theConfig.getParameter("omtf")); - } + m_Reconstruction.beginJob(); + } ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// void L1TMuonOverlapTrackProducer::endJob(){ - if(dumpResultToXML){ - std::string fName = theConfig.getParameter("XMLDumpFileName"); - myWriter->finaliseXMLDocument(fName); - } + m_Reconstruction.endJob(); + } ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// void L1TMuonOverlapTrackProducer::beginRun(edm::Run const& run, edm::EventSetup const& iSetup){ - ///If configuration is read from XML do not look at the DB. - if(theConfig.getParameter("omtf").getParameter("configFromXML")) return; - - const L1TMuonOverlapParamsRcd& omtfParamsRcd = iSetup.get(); - - edm::ESHandle omtfParamsHandle; - omtfParamsRcd.get(omtfParamsHandle); - - const L1TMuonOverlapParams* omtfParams = omtfParamsHandle.product(); - if (!omtfParams) { - edm::LogError("L1TMuonOverlapTrackProducer") << "Could not retrieve parameters from Event Setup" << std::endl; - } - - myOMTFConfig->configure(omtfParams); - myOMTF->configure(omtfParams); - + m_Reconstruction.beginRun(run, iSetup); } ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// void L1TMuonOverlapTrackProducer::produce(edm::Event& iEvent, const edm::EventSetup& evSetup){ - std::ostringstream myStr; - - myInputMaker.initialize(evSetup); //FIXME shoun't it be in beginRun? - - loadAndFilterDigis(iEvent); - - if(dumpResultToXML) aTopElement = myWriter->writeEventHeader(iEvent.id().event()); + std::ostringstream str; + + std::auto_ptr candidates = m_Reconstruction.reconstruct(iEvent, evSetup); - // NOTE: assuming all is for bx 0 int bx = 0; + //dumpResultToXML = true; + str<<" Number of candidates: "<size(bx); + edm::LogInfo("OMTFOMTFProducer")< myCandidates(new l1t::RegionalMuonCandBxCollection); - ///The order is iportant: first put omtf_pos candidates, then omtf_neg. - for(unsigned int iProcessor=0;iProcessorsize(bx); - edm::LogInfo("OMTFOMTFProducer")<("dropDTPrimitives")){ - iEvent.getByToken(inputTokenDTPh,dtPhDigis); - iEvent.getByToken(inputTokenDTTh,dtThDigis); - } - if(!theConfig.getParameter("dropRPCPrimitives")) iEvent.getByToken(inputTokenRPC,rpcDigis); - if(!theConfig.getParameter("dropCSCPrimitives")) iEvent.getByToken(inputTokenCSC,cscDigis); - + iEvent.put(candidates, "OMTF"); } -///////////////////////////////////////////////////// -///////////////////////////////////////////////////// -void L1TMuonOverlapTrackProducer::getProcessorCandidates(unsigned int iProcessor, l1t::tftype mtfType, int bx, - l1t::RegionalMuonCandBxCollection & myOTFCandidates){ - - OMTFinput myInput = myInputMaker.buildInputForProcessor(dtPhDigis.product(), - dtThDigis.product(), - cscDigis.product(), - rpcDigis.product(), - iProcessor, mtfType); - - const std::vector & myResults = myOMTF->processInput(iProcessor,myInput); - mySorter.sortProcessorAndFillCandidates(iProcessor, mtfType, myResults, myOTFCandidates, bx); - - writeResultToXML(iProcessor, myInput, myResults); -} -///////////////////////////////////////////////////// -///////////////////////////////////////////////////// -void L1TMuonOverlapTrackProducer::writeResultToXML(unsigned int iProcessor, const OMTFinput &myInput, - const std::vector & myResults){ - - ///Write data to XML file - if(dumpResultToXML){ - xercesc::DOMElement * aProcElement = myWriter->writeEventData(aTopElement,iProcessor,myInput); - for(unsigned int iRefHit=0;iRefHitwriteCandidateData(aProcElement,iRefHit,myCand); - if(dumpDetailedResultToXML){ - for(auto & itKey: myResults[iRefHit]) myWriter->writeResultsData(aProcElement, - iRefHit, - itKey.first,itKey.second); - } - } - } - } -} ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// #include "FWCore/Framework/interface/MakerMacros.h" DEFINE_FWK_MODULE(L1TMuonOverlapTrackProducer); - diff --git a/L1Trigger/L1TMuonOverlap/plugins/L1TMuonOverlapTrackProducer.h b/L1Trigger/L1TMuonOverlap/plugins/L1TMuonOverlapTrackProducer.h index 8a5b5aa8b2eec..7c5a1ef15b661 100644 --- a/L1Trigger/L1TMuonOverlap/plugins/L1TMuonOverlapTrackProducer.h +++ b/L1Trigger/L1TMuonOverlap/plugins/L1TMuonOverlapTrackProducer.h @@ -17,12 +17,12 @@ #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h" #include "DataFormats/RPCDigi/interface/RPCDigiCollection.h" -#include "DataFormats/L1TMuon/interface/RegionalMuonCand.h" -#include "DataFormats/L1TMuon/interface/RegionalMuonCandFwd.h" - +#include "L1Trigger/L1TMuonOverlap/interface/OMTFReconstruction.h" #include "L1Trigger/L1TMuonOverlap/interface/OMTFinputMaker.h" #include "L1Trigger/L1TMuonOverlap/interface/OMTFSorter.h" + + class L1TMuonOverlapParams; class OMTFProcessor; class OMTFConfiguration; @@ -61,30 +61,9 @@ class L1TMuonOverlapTrackProducer : public edm::EDProducer { edm::EDGetTokenT inputTokenCSC; edm::EDGetTokenT inputTokenRPC; - void loadAndFilterDigis(edm::Event& iEvent); - - void getProcessorCandidates(unsigned int iProcessor, l1t::tftype mtfType, int bx, - l1t::RegionalMuonCandBxCollection & myCandidates); - - void writeResultToXML(unsigned int iProcessor, const OMTFinput &myInput, - const std::vector & myResults); - bool dumpResultToXML, dumpDetailedResultToXML; - edm::Handle dtPhDigis; - edm::Handle dtThDigis; - edm::Handle cscDigis; - edm::Handle rpcDigis; - - ///OMTF objects - OMTFConfiguration *myOMTFConfig; - OMTFinputMaker myInputMaker; - OMTFSorter mySorter; - OMTFProcessor *myOMTF; - /// - xercesc::DOMElement *aTopElement; - OMTFConfigMaker *myOMTFConfigMaker; - XMLConfigWriter *myWriter; + OMTFReconstruction m_Reconstruction; }; diff --git a/L1Trigger/L1TMuonOverlap/src/AlgoMuon.cc b/L1Trigger/L1TMuonOverlap/src/AlgoMuon.cc new file mode 100644 index 0000000000000..503cad847bae8 --- /dev/null +++ b/L1Trigger/L1TMuonOverlap/src/AlgoMuon.cc @@ -0,0 +1,28 @@ +#include "L1Trigger/L1TMuonOverlap/interface/AlgoMuon.h" + +#include +#include + +bool AlgoMuon::isValid() const{ + return m_q >= 0; +} + +bool AlgoMuon::operator< (const AlgoMuon & o) const{ + if(this->getQ() > o.getQ()) return false; + else if(this->getQ()==o.getQ() && this->getDisc() > o.getDisc()) return false; + else return true; +} + +std::ostream & operator<< (std::ostream &out, const AlgoMuon &o){ + out <<"AlgoMuon: "; + out << " pt: " << o.getPt() + << ", phi: " << o.getPhi() + << ", eta: " << o.getEta()*2.61/240 + << ", hits: " << std::bitset<18>(o.getHits()).to_string() + << ", q: " << o.getQ() + << ", bx: " << o.getBx() + << ", charge: "<< o.getCharge() + << ", disc: " << o.getDisc() << " refLayer: " << o.getRefLayer(); + + return out; +} diff --git a/L1Trigger/L1TMuonOverlap/src/GhostBuster.cc b/L1Trigger/L1TMuonOverlap/src/GhostBuster.cc new file mode 100644 index 0000000000000..c5dd1c6a0f927 --- /dev/null +++ b/L1Trigger/L1TMuonOverlap/src/GhostBuster.cc @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +#include "L1Trigger/L1TMuonOverlap/interface/OMTFConfiguration.h" +#include "L1Trigger/L1TMuonOverlap/interface/GhostBuster.h" + +void OMTFGhostBuster::select(std::vector & refHitCands, int charge){ + + std::vector refHitCleanCands; + // Sort candidates with decreased goodness, + // where goodness definied in < operator of AlgoMuon + std::sort( refHitCands.rbegin(), refHitCands.rend() ); + + for(std::vector::iterator it1 = refHitCands.begin(); + it1 != refHitCands.end(); ++it1){ + bool isGhost=false; + for(std::vector::iterator it2 = refHitCleanCands.begin(); + it2 != refHitCleanCands.end(); ++it2){ + //do not accept candidates with similar phi (any charge combination) + //veto window 5deg(=half of logic cone)=5/360*5760=80"logic strips" + if(std::abs(it1->getPhi() - it2->getPhi())<5/360.0*OMTFConfiguration::nPhiBins){ + isGhost=true; + break; + } + } + if(it1->getQ()>0 && !isGhost) refHitCleanCands.push_back(*it1); + } + + refHitCleanCands.resize( 3, AlgoMuon(0,999,9999,0,0,0,0,0) ); + + std::ostringstream myStr; + bool hasCandidates = false; + for(unsigned int iRefHit=0;iRefHit - -std::ostream & operator<< (std::ostream &out, const InternalObj &o){ - out<<"InternalObj: "; - out <<" pt: "<(o.hits).to_string() - <<", bx: "< >("patternsXMLFiles")){ fileNames.push_back(it.getParameter("patternsXMLFile").fullPath()); } - - resetConfiguration(); + resetConfiguration(); XMLConfigReader myReader; for(auto it: fileNames){ myReader.setPatternsFile(it); @@ -72,7 +71,7 @@ bool OMTFProcessor::configure(XMLConfigReader *aReader){ bool OMTFProcessor::configure(const L1TMuonOverlapParams* omtfParams){ resetConfiguration(); - + myResults.assign(OMTFConfiguration::nTestRefHits,OMTFProcessor::resultsMap()); const l1t::LUT* chargeLUT = omtfParams->chargeLUT(); @@ -185,10 +184,10 @@ void OMTFProcessor::averagePatterns(int charge){ for(unsigned int iLayer=0;iLayer & OMTFProcessor::processInput(unsig if(OMTFConfiguration::bendingLayers.count(iLayer)) phiRef = 0; const OMTFinput::vector1D restrictedLayerHits = restrictInput(iProcessor, iRegion, iLayer,layerHits); for(auto itGP: theGPs){ - GoldenPattern::layerResult aLayerResult = itGP.second->process1Layer1RefLayer(aRefHitDef.iRefLayer,iLayer, - phiRef, - restrictedLayerHits); - - int phiRefSt2 = itGP.second->propagateRefPhi(phiRef, etaRef, aRefHitDef.iRefLayer); - myResults[OMTFConfiguration::nTestRefHits-nTestedRefHits-1][itGP.second->key()].addResult(aRefHitDef.iRefLayer,iLayer, - aLayerResult.first, - phiRefSt2,etaRef); + GoldenPattern::layerResult aLayerResult = itGP.second->process1Layer1RefLayer(aRefHitDef.iRefLayer,iLayer, + phiRef, + restrictedLayerHits); + + // if(itGP.second->pdfValue(1,0,0)) + // std::cout << itGP.second->pdfValue(1,0,0) << std::endl; + + int phiRefSt2 = itGP.second->propagateRefPhi(phiRef, etaRef, aRefHitDef.iRefLayer); + myResults[OMTFConfiguration::nTestRefHits-nTestedRefHits-1][itGP.second->key()].setRefPhiRHits(aRefHitDef.iRefLayer, phiRef); + myResults[OMTFConfiguration::nTestRefHits-nTestedRefHits-1][itGP.second->key()].addResult(aRefHitDef.iRefLayer,iLayer, + aLayerResult.first, + phiRefSt2,etaRef); } } - } + } ////////////////////////////////////// ////////////////////////////////////// for(auto & itRefHit: myResults) for(auto & itKey: itRefHit) itKey.second.finalise(); diff --git a/L1Trigger/L1TMuonOverlap/src/OMTFReconstruction.cc b/L1Trigger/L1TMuonOverlap/src/OMTFReconstruction.cc new file mode 100644 index 0000000000000..756453f74fc9e --- /dev/null +++ b/L1Trigger/L1TMuonOverlap/src/OMTFReconstruction.cc @@ -0,0 +1,253 @@ +#include "FWCore/MessageLogger/interface/MessageLogger.h" + +#include "DataFormats/L1TMuon/interface/RegionalMuonCand.h" +#include "DataFormats/L1TMuon/interface/RegionalMuonCandFwd.h" + +#include "CondFormats/DataRecord/interface/L1TMuonOverlapParamsRcd.h" +#include "CondFormats/L1TObjects/interface/L1TMuonOverlapParams.h" + +#include "L1Trigger/L1TMuonOverlap/plugins/L1TMuonOverlapTrackProducer.h" +#include "L1Trigger/L1TMuonOverlap/interface/OMTFProcessor.h" +#include "L1Trigger/L1TMuonOverlap/interface/OMTFinput.h" +#include "L1Trigger/L1TMuonOverlap/interface/OMTFReconstruction.h" +#include "L1Trigger/L1TMuonOverlap/interface/OMTFConfiguration.h" +#include "L1Trigger/L1TMuonOverlap/interface/XMLConfigWriter.h" + +#include "L1Trigger/RPCTrigger/interface/RPCConst.h" + +OMTFReconstruction::OMTFReconstruction() : + m_OMTFConfig(0), m_OMTF(0), aTopElement(0), m_OMTFConfigMaker(0), m_Writer(0){} + +OMTFReconstruction::OMTFReconstruction(const edm::ParameterSet& theConfig) : + m_Config(theConfig), m_OMTFConfig(0), m_OMTF(0), aTopElement(0), m_OMTFConfigMaker(0), m_Writer(0) { + + + if(!m_Config.exists("omtf")){ + edm::LogError("L1TMuonOverlapTrackProducer")<<"omtf configuration not found in cfg.py"; + } + + dumpResultToXML = m_Config.getParameter("dumpResultToXML"); + dumpDetailedResultToXML = m_Config.getParameter("dumpDetailedResultToXML"); + m_Config.getParameter("XMLDumpFileName"); + + if(dumpResultToXML){ + m_Writer = new XMLConfigWriter(); + std::string fName = "OMTF"; + m_Writer->initialiseXMLDocument(fName); + } +} + +///////////////////////////////////////////////////// +///////////////////////////////////////////////////// +OMTFReconstruction::~OMTFReconstruction(){ + + delete m_OMTFConfig; + delete m_OMTF; + + if (m_Writer) delete m_Writer; +} + +///////////////////////////////////////////////////// +///////////////////////////////////////////////////// +void OMTFReconstruction::beginJob() { + + if(m_Config.exists("omtf")){ + m_OMTFConfig = new OMTFConfiguration(m_Config.getParameter("omtf")); + m_OMTF = new OMTFProcessor(m_Config.getParameter("omtf")); + } +} + +///////////////////////////////////////////////////// +///////////////////////////////////////////////////// +void OMTFReconstruction::endJob(){ + + if(dumpResultToXML){ + std::string fName = m_Config.getParameter("XMLDumpFileName"); + m_Writer->finaliseXMLDocument(fName); + } +} + +///////////////////////////////////////////////////// +///////////////////////////////////////////////////// +void OMTFReconstruction::beginRun(edm::Run const& run, edm::EventSetup const& iSetup) { + + ///If configuration is read from XML do not look at the DB. + if(m_Config.getParameter("omtf").getParameter("configFromXML")) return; + + const L1TMuonOverlapParamsRcd& omtfParamsRcd = iSetup.get(); + + edm::ESHandle omtfParamsHandle; + omtfParamsRcd.get(omtfParamsHandle); + + const L1TMuonOverlapParams* omtfParams = omtfParamsHandle.product(); + if (!omtfParams) { + edm::LogError("L1TMuonOverlapTrackProducer") << "Could not retrieve parameters from Event Setup" << std::endl; + } + + m_OMTFConfig->configure(omtfParams); + m_OMTF->configure(omtfParams); +} + +void OMTFReconstruction::algoBeginJob() { + + m_OMTF = new OMTFProcessor(m_Config.getParameter("omtf")); +} + +///////////////////////////////////////////////////// +///////////////////////////////////////////////////// +AlgoMuonResults OMTFReconstruction::algoReconstruct(const edm::Event& iEvent, const edm::EventSetup& evSetup) { + + const L1TMuonOverlapParamsRcd& omtfParamsRcd = evSetup.get(); + + edm::ESHandle omtfParamsHandle; + omtfParamsRcd.get(omtfParamsHandle); + + const L1TMuonOverlapParams* omtfParams = omtfParamsHandle.product(); + if (!omtfParams) { + edm::LogError("L1TMuonOverlapTrackProducer") << "Could not retrieve parameters from Event Setup" << std::endl; + } + + m_OMTF = new OMTFProcessor(m_Config.getParameter("omtf")); + m_OMTF->configure(omtfParams); + + m_InputMaker.initialize(evSetup); + + edm::Handle dtPhDigis; + edm::Handle dtThDigis; + edm::Handle cscDigis; + edm::Handle rpcDigis; + + if(!m_Config.getParameter("dropDTPrimitives")){ + iEvent.getByLabel(m_Config.getParameter("srcDTPh"),dtPhDigis); + iEvent.getByLabel(m_Config.getParameter("srcDTTh"),dtThDigis); + } + if(!m_Config.getParameter("dropRPCPrimitives")) iEvent.getByLabel(m_Config.getParameter("srcRPC"),rpcDigis); + if(!m_Config.getParameter("dropCSCPrimitives")) iEvent.getByLabel(m_Config.getParameter("srcCSC"),cscDigis); + + AlgoMuonResults algoMuonResults; + algoMuonResults.clear(); + + ///Loop over all processors, each covering 60 deg in phi + for(unsigned int iProcessor=0;iProcessor<6;++iProcessor){ + + OMTFinput inputPos = m_InputMaker.buildInputForProcessor(dtPhDigis.product(), + dtThDigis.product(), + cscDigis.product(), + rpcDigis.product(), + iProcessor, + l1t::tftype::omtf_pos); + OMTFinput inputNeg = m_InputMaker.buildInputForProcessor(dtPhDigis.product(), + dtThDigis.product(), + cscDigis.product(), + rpcDigis.product(), + iProcessor, + l1t::tftype::omtf_neg); + + std::vector algoCandidatesPos, algoCandidatesNeg; + + const std::vector & resultsPos = m_OMTF->processInput(iProcessor, inputPos); + m_Sorter.sortRefHitResults(resultsPos, algoCandidatesPos); + algoMuonResults.push_back(make_pair(iProcessor*2, algoCandidatesPos)); + + const std::vector & resultsNeg = m_OMTF->processInput(iProcessor, inputNeg); + m_Sorter.sortRefHitResults(resultsNeg, algoCandidatesNeg); + algoMuonResults.push_back(make_pair(iProcessor*2 + 1, algoCandidatesNeg)); + } + + delete m_OMTF; + return algoMuonResults; +} + + +///////////////////////////////////////////////////// +///////////////////////////////////////////////////// +std::auto_ptr OMTFReconstruction::reconstruct(const edm::Event& iEvent, const edm::EventSetup& evSetup) { + + m_InputMaker.initialize(evSetup); //FIXME shoun't it be in beginRun? + + edm::Handle dtPhDigis; + edm::Handle dtThDigis; + edm::Handle cscDigis; + edm::Handle rpcDigis; + + ///Filter digis by dropping digis from selected (by cfg.py) subsystems + if(!m_Config.getParameter("dropDTPrimitives")){ + iEvent.getByLabel(m_Config.getParameter("srcDTPh"),dtPhDigis); + iEvent.getByLabel(m_Config.getParameter("srcDTTh"),dtThDigis); + } + if(!m_Config.getParameter("dropRPCPrimitives")) iEvent.getByLabel(m_Config.getParameter("srcRPC"),rpcDigis); + if(!m_Config.getParameter("dropCSCPrimitives")) iEvent.getByLabel(m_Config.getParameter("srcCSC"),cscDigis); + + std::auto_ptr candidates(new l1t::RegionalMuonCandBxCollection); + if(dumpResultToXML) aTopElement = m_Writer->writeEventHeader(iEvent.id().event()); + + // NOTE: assuming all is for bx 0 + int bx = 0; + m_AlgoMuonResults.clear(); + + ///Loop over all processors, each covering 60 deg in phi + for(unsigned int iProcessor=0;iProcessor<6;++iProcessor){ + + ///Input data with phi ranges shifted for each processor, so it fits 11 bits range + OMTFinput inputPos = m_InputMaker.buildInputForProcessor(dtPhDigis.product(), + dtThDigis.product(), + cscDigis.product(), + rpcDigis.product(), + iProcessor, + l1t::tftype::omtf_pos); + + OMTFinput inputNeg = m_InputMaker.buildInputForProcessor(dtPhDigis.product(), + dtThDigis.product(), + cscDigis.product(), + rpcDigis.product(), + iProcessor, + l1t::tftype::omtf_neg); + + l1t::RegionalMuonCandBxCollection OTFCandidatesPos, OTFCandidatesNeg; + std::vector algoCandidatesPos, algoCandidatesNeg; + + //==================== + // positive + //==================== + ///Results for each GP in each logic region of given processor + //Retreive all candidates returned by sorter: upto 3 non empty ones with different phi or charge + const std::vector & resultsPos = m_OMTF->processInput(iProcessor, inputPos); + m_Sorter.sortRefHitResults(resultsPos, algoCandidatesPos); + m_AlgoMuonResults.push_back(make_pair(iProcessor*2, algoCandidatesPos)); + // m_GhostBuster.select(algoCandidatesPos); + m_Sorter.rewriteToRegionalMuon(algoCandidatesPos, OTFCandidatesPos, bx); // rewrite AlgoMuon to RegionalMuon + ///Shift phi scales, and put MicroGMT candidates into candidates collection + m_Sorter.processCandidates(iProcessor, bx, candidates, OTFCandidatesPos, l1t::tftype::omtf_pos); + + //==================== + // negative + //==================== + const std::vector & resultsNeg = m_OMTF->processInput(iProcessor, inputNeg); + m_Sorter.sortRefHitResults(resultsNeg, algoCandidatesNeg); + m_AlgoMuonResults.push_back(make_pair(iProcessor*2 + 1, algoCandidatesNeg)); + // m_GhostBuster.select(algoCandidatesNeg); + m_Sorter.rewriteToRegionalMuon(algoCandidatesNeg, OTFCandidatesNeg, bx); // rewrite AlgoMuon to RegionalMuon + ///Shift phi scales, and put MicroGMT candidates into m_Cands collection + m_Sorter.processCandidates(iProcessor, bx, candidates, OTFCandidatesNeg, l1t::tftype::omtf_neg); + + ///Write data to XML file + // if(dumpResultToXML){ + // xercesc::DOMElement * aProcElement = m_Writer->writeEventData(aTopElement,iProcessor,inputPos); + // for(unsigned int iRefHit=0; iRefHit < OMTFConfiguration::nTestRefHits; ++iRefHit){ + // ///Dump only regions, where a candidate was found + // // AlgoMuon m_Cand = m_Sorter.sortRefHitResults(resultsPos[iRefHit],0);//charge=0 means ignore charge + // AlgoMuon algoCand = algoCandidatesPos[iRefHit]; + // if(algoCand.getPt()){ + // m_Writer->writeCandidateData(aProcElement, iRefHit, algoCand); + // if(dumpDetailedResultToXML){ + // for(auto & itKey: resultsNeg[iRefHit]) m_Writer->writeResultsData(aProcElement, + // iRefHit, + // itKey.first,itKey.second); + // } + // } + // } + // } + + } + return candidates; + } diff --git a/L1Trigger/L1TMuonOverlap/src/OMTFResult.cc b/L1Trigger/L1TMuonOverlap/src/OMTFResult.cc index fe9a43719a121..ea6c4952b9a77 100644 --- a/L1Trigger/L1TMuonOverlap/src/OMTFResult.cc +++ b/L1Trigger/L1TMuonOverlap/src/OMTFResult.cc @@ -14,6 +14,13 @@ OMTFResult::OMTFResult(){ } //////////////////////////////////////////// //////////////////////////////////////////// + +void OMTFResult::setRefPhiRHits(unsigned int iRefLayer, int iRefPhiRHit){ + refPhiRHit1D[iRefLayer] = iRefPhiRHit; +} +//////////////////////////////////////////// +//////////////////////////////////////////// + void OMTFResult::addResult(unsigned int iRefLayer, unsigned int iLayer, unsigned int val, @@ -35,6 +42,7 @@ void OMTFResult::clear(){ refPhi1D.assign(OMTFConfiguration::nRefLayers,1024); refEta1D.assign(OMTFConfiguration::nRefLayers,1024); hitsBits.assign(OMTFConfiguration::nRefLayers,0); + refPhiRHit1D.assign(OMTFConfiguration::nRefLayers,1024); } //////////////////////////////////////////// //////////////////////////////////////////// diff --git a/L1Trigger/L1TMuonOverlap/src/OMTFSorter.cc b/L1Trigger/L1TMuonOverlap/src/OMTFSorter.cc index 5b65fd391769b..9f5745312a12e 100644 --- a/L1Trigger/L1TMuonOverlap/src/OMTFSorter.cc +++ b/L1Trigger/L1TMuonOverlap/src/OMTFSorter.cc @@ -13,13 +13,14 @@ #include "L1Trigger/RPCTrigger/interface/RPCConst.h" /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// -std::tuple OMTFSorter::sortSingleResult(const OMTFResult & aResult){ +AlgoMuon OMTFSorter::sortSingleResult(const OMTFResult & aResult){ OMTFResult::vector1D pdfValsVec = aResult.getSummaryVals(); OMTFResult::vector1D nHitsVec = aResult.getSummaryHits(); OMTFResult::vector1D refPhiVec = aResult.getRefPhis(); OMTFResult::vector1D refEtaVec = aResult.getRefEtas(); OMTFResult::vector1D hitsVec = aResult.getHitsWord(); + OMTFResult::vector1D refPhiRHitVec = aResult.getRefPhiRHits(); assert(pdfValsVec.size()==nHitsVec.size()); @@ -29,15 +30,10 @@ std::tuple OMTFSorter::s int refPhi = 1024; int refEta = -10; int refLayer = -1; + int refPhiRHit = 1024; - std::tuple sortedResult; - std::get<0>(sortedResult) = nHitsMax; - std::get<1>(sortedResult) = pdfValMax; - std::get<2>(sortedResult) = refPhi; - std::get<3>(sortedResult) = refLayer; - std::get<4>(sortedResult) = hitsWord; - std::get<5>(sortedResult) = refEta; - + AlgoMuon sortedResult(pdfValMax, refPhi, refEta, refLayer, hitsWord, nHitsMax); + ///Find a result with biggest number of hits for(auto itHits: nHitsVec){ if(itHits>nHitsMax) nHitsMax = itHits; @@ -48,26 +44,29 @@ std::tuple OMTFSorter::s for(unsigned int ipdfVal=0;ipdfValpdfValMax){ - pdfValMax = pdfValsVec[ipdfVal]; - refPhi = refPhiVec[ipdfVal]; - refEta = refEtaVec[ipdfVal]; - refLayer = ipdfVal; - hitsWord = hitsVec[ipdfVal]; + pdfValMax = pdfValsVec[ipdfVal]; + refPhi = refPhiVec[ipdfVal]; + refEta = refEtaVec[ipdfVal]; + refLayer = ipdfVal; + hitsWord = hitsVec[ipdfVal]; + refPhiRHit = refPhiRHitVec[ipdfVal]; } } } - std::get<0>(sortedResult) = nHitsMax; - std::get<1>(sortedResult) = pdfValMax; - std::get<2>(sortedResult) = refPhi; - std::get<3>(sortedResult) = refLayer; - std::get<4>(sortedResult) = hitsWord; - std::get<5>(sortedResult) = refEta; + sortedResult.setDisc(pdfValMax); + sortedResult.setPhi(refPhi); + sortedResult.setEta(refEta); + sortedResult.setRefLayer(refLayer); + sortedResult.setHits(hitsWord); + sortedResult.setQ(nHitsMax); + sortedResult.setPhiRHit(refPhiRHit); + return sortedResult; } /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// -InternalObj OMTFSorter::sortRefHitResults(const OMTFProcessor::resultsMap & aResultsMap, +AlgoMuon OMTFSorter::sortRefHitResults(const OMTFProcessor::resultsMap & aResultsMap, int charge){ unsigned int pdfValMax = 0; @@ -76,57 +75,62 @@ InternalObj OMTFSorter::sortRefHitResults(const OMTFProcessor::resultsMap & aRes int refPhi = 9999; int refEta = 999; int refLayer = -1; + int refPhiRHit = 9999; Key bestKey; + for(auto itKey: aResultsMap){ if(charge!=0 && itKey.first.theCharge!=charge) continue; //charge==0 means ignore charge - std::tuple val = sortSingleResult(itKey.second); + AlgoMuon val = sortSingleResult(itKey.second); ///Accept only candidates with >2 hits - if(std::get<0>(val)<3) continue; - if( std::get<0>(val)>nHitsMax){ - nHitsMax = std::get<0>(val); - pdfValMax = std::get<1>(val); - refPhi = std::get<2>(val); - refEta = std::get<5>(val); - refLayer = std::get<3>(val); - hitsWord = std::get<4>(val); + if(val.getQ() < 3) continue; + if(val.getQ() > (int)nHitsMax){ + nHitsMax = val.getQ(); + pdfValMax = val.getDisc(); + refPhi = val.getPhi(); + refEta = val.getEta(); + refLayer = val.getRefLayer(); + hitsWord = val.getHits(); + refPhiRHit = val.getPhiRHit(); bestKey = itKey.first; } - else if(std::get<0>(val)==nHitsMax && std::get<1>(val)>pdfValMax){ - pdfValMax = std::get<1>(val); - refPhi = std::get<2>(val); - refEta = std::get<5>(val); - refLayer = std::get<3>(val); - hitsWord = std::get<4>(val); + else if(val.getQ() == (int)nHitsMax && val.getDisc() > (int)pdfValMax){ + pdfValMax = val.getDisc(); + refPhi = val.getPhi(); + refEta = val.getEta(); + refLayer = val.getRefLayer(); + hitsWord = val.getHits(); + refPhiRHit = val.getPhiRHit(); bestKey = itKey.first; } - else if(std::get<0>(val)==nHitsMax && std::get<1>(val)==pdfValMax && - itKey.first.thePtCode(val); - refPhi = std::get<2>(val); - refEta = std::get<5>(val); - refLayer = std::get<3>(val); - hitsWord = std::get<4>(val); + else if(val.getQ() == (int)nHitsMax && val.getDisc() == (int)pdfValMax && + itKey.first.thePtCode < bestKey.thePtCode){ + pdfValMax = val.getDisc(); + refPhi = val.getPhi(); + refEta = val.getEta(); + refLayer = val.getRefLayer(); + hitsWord = val.getHits(); + refPhiRHit = val.getPhiRHit(); bestKey = itKey.first; } } - InternalObj candidate(bestKey.thePtCode, refEta, refPhi, - pdfValMax, 0, nHitsMax, - bestKey.theCharge, refLayer); + AlgoMuon candidate(pdfValMax, refPhi, refEta, refLayer, + hitsWord, nHitsMax, 0, + bestKey.thePtCode, bestKey.theCharge); - candidate.hits = hitsWord; + candidate.setPhiRHit(refPhiRHit); // for backward compatibility return candidate; } /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// -InternalObj OMTFSorter::sortProcessorResults(const std::vector & procResults, +AlgoMuon OMTFSorter::sortProcessorResults(const std::vector & procResults, int charge){ //method kept for backward compatibility - std::vector sortedCandidates; + std::vector sortedCandidates; sortProcessorResults(procResults, sortedCandidates, charge); - InternalObj candidate = sortedCandidates.size()>0 ? sortedCandidates[0] : InternalObj(0,999,9999,0,0,0,0,-1); + AlgoMuon candidate = sortedCandidates.size()>0 ? sortedCandidates[0] : AlgoMuon(0,999,9999,0,0,0,0,-1); std::ostringstream myStr; myStr<<"Selected Candidate with charge: "< & procResults, + std::vector & refHitCands, + int charge){ + + for(auto itRefHit: procResults) refHitCands.push_back(sortRefHitResults(itRefHit,charge)); +} + /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// void OMTFSorter::sortProcessorResults(const std::vector & procResults, - std::vector & refHitCleanCands, + std::vector & refHitCleanCands, int charge){ refHitCleanCands.clear(); - std::vector refHitCands; + std::vector refHitCands; for(auto itRefHit: procResults) refHitCands.push_back(sortRefHitResults(itRefHit,charge)); - // Sort candidates with decreased goodness, - // where goodness definied in < operator of InternalObj - std::sort( refHitCands.begin(), refHitCands.end() ); - - // Clean candidate list by removing dupicates basing on Phi distance. - // Assumed that the list is ordered - for(std::vector::iterator it1 = refHitCands.begin(); - it1 != refHitCands.end(); ++it1){ - bool isGhost=false; - for(std::vector::iterator it2 = refHitCleanCands.begin(); - it2 != refHitCleanCands.end(); ++it2){ - //do not accept candidates with similar phi (any charge combination) - //veto window 5deg(=half of logic cone)=5/360*5760=80"logic strips" - if(std::abs(it1->phi - it2->phi)<5/360.0*OMTFConfiguration::nPhiBins){ - isGhost=true; - break; - } - } - if(it1->q>0 && !isGhost) refHitCleanCands.push_back(*it1); - } - //return 3 candidates (adding empty ones if needed) - refHitCleanCands.resize( 3, InternalObj(0,999,9999,0,0,0,0,0) ); - - std::ostringstream myStr; - bool hasCandidates = false; - for(unsigned int iRefHit=0;iRefHit & procResults, int charge){ //method kept for backward compatibility - InternalObj myCand = sortProcessorResults(procResults, charge); + AlgoMuon myCand = sortProcessorResults(procResults, charge); l1t::RegionalMuonCand candidate; - std::bitset<17> bits(myCand.hits); - int ipt = myCand.pt+1; + std::bitset<17> bits(myCand.getHits()); + int ipt = myCand.getPt()+1; if(ipt>31) ipt=31; candidate.setHwPt(RPCConst::ptFromIpt(ipt)*2.0);//MicroGMT has 0.5 GeV pt bins - candidate.setHwEta(myCand.eta);//eta scale set during input making in OMTFInputmaker - candidate.setHwPhi(myCand.phi); - candidate.setHwSign(myCand.charge+1*(myCand.charge<0)); + candidate.setHwEta(myCand.getEta());//eta scale set during input making in OMTFInputmaker + candidate.setHwPhi(myCand.getPhi()); + candidate.setHwSign(myCand.getCharge()+1*(myCand.getCharge()<0)); candidate.setHwQual(bits.count()); std::map trackAddr; - trackAddr[0] = myCand.hits; - trackAddr[1] = myCand.refLayer; - trackAddr[2] = myCand.disc; + trackAddr[0] = myCand.getHits(); + trackAddr[1] = myCand.getRefLayer(); + trackAddr[2] = myCand.getDisc(); candidate.setTrackAddress(trackAddr); return candidate; @@ -228,42 +201,56 @@ bool OMTFSorter::checkHitPatternValidity(unsigned int hits){ } /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// -void OMTFSorter::sortProcessorAndFillCandidates(unsigned int iProcessor, l1t::tftype mtfType, - const std::vector & procResults, - l1t::RegionalMuonCandBxCollection & sortedCands, - int bx, int charge){ - - std::vector mySortedCands; - sortProcessorResults(procResults, mySortedCands, charge); +void OMTFSorter::rewriteToRegionalMuon(const std::vector & AlgoCands, + l1t::RegionalMuonCandBxCollection & sortedCands, + int bx, int charge){ - for(auto myCand: mySortedCands){ - l1t::RegionalMuonCand candidate; - std::bitset<17> bits(myCand.hits); - candidate.setHwPt(myCand.pt); - candidate.setHwEta(myCand.eta); + sortedCands.clear(); + // std::vector mySortedCands; + // sortProcessorResults(procResults, mySortedCands, charge); - float phiValue = myCand.phi; - if(phiValue>=(int)OMTFConfiguration::nPhiBins) phiValue-=OMTFConfiguration::nPhiBins; - ///conversion factor from OMTF to uGMT scale: 5400/576 - phiValue/=9.375; - candidate.setHwPhi(phiValue); - - candidate.setHwSign(myCand.charge<0 ? 1:0 ); + for(auto myCand: AlgoCands){ + l1t::RegionalMuonCand candidate; + std::bitset<17> bits(myCand.getHits()); + candidate.setHwPt(myCand.getPt()); + candidate.setHwEta(myCand.getEta()); + candidate.setHwPhi(myCand.getPhi()); + candidate.setHwSign(myCand.getCharge()<0 ? 1:0 ); ///Quality is set to number of leayers hit. ///DT bending and position hit is counted as one. ///thus we subtract 1 for each DT station hit. candidate.setHwQual(bits.count() - bits.test(0) - bits.test(2) - bits.test(4)); ///Candidates with bad hit patterns get quality 0. - if(!checkHitPatternValidity(myCand.hits)) candidate.setHwQual(0); + if(!checkHitPatternValidity(myCand.getHits())) candidate.setHwQual(0); std::map trackAddr; - trackAddr[0] = myCand.hits; - trackAddr[1] = myCand.refLayer; - trackAddr[2] = myCand.disc; + trackAddr[0] = myCand.getHits(); + trackAddr[1] = myCand.getRefLayer(); + trackAddr[2] = myCand.getDisc(); candidate.setTrackAddress(trackAddr); - candidate.setTFIdentifiers(iProcessor,mtfType); - if(candidate.hwPt()) sortedCands.push_back(bx, candidate); + + sortedCands.push_back(bx, candidate); } + + return; } /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// +void OMTFSorter::processCandidates(unsigned int iProcessor, int bx, + std::auto_ptr & myCands, + const l1t::RegionalMuonCandBxCollection & myOTFCandidates, + l1t::tftype mtfType){ + + for(unsigned int iCand=0; iCand=(int)OMTFConfiguration::nPhiBins) phiValue-=OMTFConfiguration::nPhiBins; + ///conversion factor from OMTF to uGMT scale: 5400/576 + phiValue/=9.375; + cand.setHwPhi(phiValue); + cand.setTFIdentifiers(iProcessor,mtfType); + + // store candidate + if(cand.hwPt()) myCands->push_back(bx, cand); + } +} diff --git a/L1Trigger/L1TMuonOverlap/src/XMLConfigWriter.cc b/L1Trigger/L1TMuonOverlap/src/XMLConfigWriter.cc index 9a622884fa5da..91dcb79d58b77 100644 --- a/L1Trigger/L1TMuonOverlap/src/XMLConfigWriter.cc +++ b/L1Trigger/L1TMuonOverlap/src/XMLConfigWriter.cc @@ -6,13 +6,14 @@ #include "L1Trigger/L1TMuonOverlap/interface/OMTFConfiguration.h" #include "L1Trigger/L1TMuonOverlap/interface/OMTFResult.h" -#include "L1Trigger/L1TMuonOverlap/interface/InternalObj.h" +#include "L1Trigger/L1TMuonOverlap/interface/AlgoMuon.h" #include #include #include #include #include +#include #include "xercesc/framework/StdOutFormatTarget.hpp" #include "xercesc/framework/LocalFileFormatTarget.hpp" @@ -180,35 +181,42 @@ xercesc::DOMElement * XMLConfigWriter::writeEventData(xercesc::DOMElement *aTopE ////////////////////////////////////////////////// void XMLConfigWriter::writeCandidateData(xercesc::DOMElement *aTopElement, unsigned int iRefHit, - const InternalObj & aCand){ + const AlgoMuon & aCand){ - xercesc::DOMElement* aResult = theDoc->createElement(_toDOMS("Candidate")); + xercesc::DOMElement* aResult = theDoc->createElement(_toDOMS("AlgoMuon")); std::ostringstream stringStr; stringStr.str(""); stringStr<setAttribute(_toDOMS("iRefHit"),_toDOMS(stringStr.str())); stringStr.str(""); - stringStr<setAttribute(_toDOMS("ptCode"),_toDOMS(stringStr.str())); stringStr.str(""); - stringStr<setAttribute(_toDOMS("phiCode"),_toDOMS(stringStr.str())); stringStr.str(""); - stringStr<setAttribute(_toDOMS("etaCode"),_toDOMS(stringStr.str())); stringStr.str(""); - stringStr<setAttribute(_toDOMS("charge"),_toDOMS(stringStr.str())); stringStr.str(""); - stringStr<setAttribute(_toDOMS("nHits"), _toDOMS(stringStr.str())); stringStr.str(""); - stringStr<setAttribute(_toDOMS("disc"), _toDOMS(stringStr.str())); stringStr.str(""); - stringStr<setAttribute(_toDOMS("iRefLayer"), _toDOMS(stringStr.str())); - aTopElement->appendChild(aResult); + stringStr.str(""); + stringStr<(aCand.getHits()); + aResult->setAttribute(_toDOMS("layers"),_toDOMS(stringStr.str())); + stringStr.str(""); + stringStr<setAttribute(_toDOMS("phiRHit"),_toDOMS(stringStr.str())); + + aTopElement->appendChild(aResult); } ////////////////////////////////////////////////// ////////////////////////////////////////////////// From dc1d9d664b4ecff68caff2d921b72232c9219836 Mon Sep 17 00:00:00 2001 From: Marcin Date: Mon, 22 Feb 2016 14:49:37 +0100 Subject: [PATCH 2/3] changes from Pawel to accomodate recent changes from Artur --- .../interface/OMTFReconstruction.h | 28 +-- .../L1TMuonOverlap/interface/OMTFSorter.h | 44 ++-- .../L1TMuonOverlap/src/OMTFReconstruction.cc | 196 +++++------------- L1Trigger/L1TMuonOverlap/src/OMTFSorter.cc | 186 +++++++++-------- 4 files changed, 198 insertions(+), 256 deletions(-) diff --git a/L1Trigger/L1TMuonOverlap/interface/OMTFReconstruction.h b/L1Trigger/L1TMuonOverlap/interface/OMTFReconstruction.h index 876ba90932b70..16e42f853dfd4 100644 --- a/L1Trigger/L1TMuonOverlap/interface/OMTFReconstruction.h +++ b/L1Trigger/L1TMuonOverlap/interface/OMTFReconstruction.h @@ -33,8 +33,6 @@ namespace XERCES_CPP_NAMESPACE{ class DOMImplementation; } -typedef std::vector< std::pair > > AlgoMuonResults; - class OMTFReconstruction { public: OMTFReconstruction(); @@ -49,18 +47,26 @@ class OMTFReconstruction { void beginRun(edm::Run const& run, edm::EventSetup const& iSetup); - void algoBeginJob(); + std::auto_ptr reconstruct(const edm::Event&, const edm::EventSetup&); - // not working - AlgoMuonResults algoReconstruct(const edm::Event&, const edm::EventSetup&); + private: - std::auto_ptr reconstruct(const edm::Event&, const edm::EventSetup&); + edm::ParameterSet m_Config; - // std::auto_ptr getAlgoMuonResults(); + edm::Handle dtPhDigis; + edm::Handle dtThDigis; + edm::Handle cscDigis; + edm::Handle rpcDigis; + + void loadAndFilterDigis(const edm::Event&); + + void getProcessorCandidates(unsigned int iProcessor, l1t::tftype mtfType, int bx, + l1t::RegionalMuonCandBxCollection & myCandidates); + + void writeResultToXML(unsigned int iProcessor, const OMTFinput &myInput, + const std::vector & myResults); - // private: - edm::ParameterSet m_Config; bool dumpResultToXML, dumpDetailedResultToXML; ///OMTF objects @@ -68,9 +74,7 @@ class OMTFReconstruction { OMTFinputMaker m_InputMaker; OMTFSorter m_Sorter; OMTFGhostBuster m_GhostBuster; - OMTFProcessor *m_OMTF; - OMTFProcessor *m_AlgoOMTF; - AlgoMuonResults m_AlgoMuonResults; + OMTFProcessor *m_OMTF; /// xercesc::DOMElement *aTopElement; OMTFConfigMaker *m_OMTFConfigMaker; diff --git a/L1Trigger/L1TMuonOverlap/interface/OMTFSorter.h b/L1Trigger/L1TMuonOverlap/interface/OMTFSorter.h index 8f668966f0a92..e2bb6f96102b5 100644 --- a/L1Trigger/L1TMuonOverlap/interface/OMTFSorter.h +++ b/L1Trigger/L1TMuonOverlap/interface/OMTFSorter.h @@ -16,37 +16,37 @@ class OMTFSorter{ public: + ///////////////////////////////////////////////////////////// + // method not used + ///////////////////////////////////////////////////////////// ///Sort all processor results. ///First for each region cone find a best candidate using sortRegionResults() ///Then select best candidate amongs found for each logic region. ///The sorting is made for candidates with a given charge - void sortProcessorResults(const std::vector & procResults, - std::vector & refHitCands, - int charge=0); - - AlgoMuon sortProcessorResults(const std::vector & procResults, - int charge=0); - + // AlgoMuon sortProcessorResults(const std::vector & procResults, + // int charge=0); + // + // void sortProcessorResults(const std::vector & procResults, + // std::vector & refHitCands, + // int charge=0); + // + ///Sort all processor results. + ///First for each region cone find a best candidate using sortRegionResults() + ///Then select best candidate amongs found for each logic region + // l1t::RegionalMuonCand sortProcessor(const std::vector & procResults, + // int charge=0); + ///////////////////////////////////////////////////////////// void sortRefHitResults(const std::vector & procResults, - std::vector & refHitCleanCands, - int charge=0); + std::vector & refHitCleanCands, + int charge=0); - void processCandidates(unsigned int iProcessor, int bx, - std::auto_ptr & myCands, - const l1t::RegionalMuonCandBxCollection & myOTFCandidates, - l1t::tftype mtfType); + void sortProcessorAndFillCandidates(unsigned int iProcessor, l1t::tftype mtfType, + const std::vector & algoCands, + l1t::RegionalMuonCandBxCollection & sortedCands, + int bx, int charge=0); - ///Sort all processor results. - ///First for each region cone find a best candidate using sortRegionResults() - ///Then select best candidate amongs found for each logic region - l1t::RegionalMuonCand sortProcessor(const std::vector & procResults, - int charge=0); - // - void rewriteToRegionalMuon(const std::vector & AlgoCands, - l1t::RegionalMuonCandBxCollection & sortedCands, - int bx, int charge=0); ///Sort results from a single reference hit. ///Select candidate with highest number of hit layers diff --git a/L1Trigger/L1TMuonOverlap/src/OMTFReconstruction.cc b/L1Trigger/L1TMuonOverlap/src/OMTFReconstruction.cc index 756453f74fc9e..480cc9e410914 100644 --- a/L1Trigger/L1TMuonOverlap/src/OMTFReconstruction.cc +++ b/L1Trigger/L1TMuonOverlap/src/OMTFReconstruction.cc @@ -88,166 +88,84 @@ void OMTFReconstruction::beginRun(edm::Run const& run, edm::EventSetup const& iS m_OMTF->configure(omtfParams); } -void OMTFReconstruction::algoBeginJob() { - - m_OMTF = new OMTFProcessor(m_Config.getParameter("omtf")); -} - ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// -AlgoMuonResults OMTFReconstruction::algoReconstruct(const edm::Event& iEvent, const edm::EventSetup& evSetup) { +std::auto_ptr OMTFReconstruction::reconstruct(const edm::Event& iEvent, const edm::EventSetup& evSetup) { - const L1TMuonOverlapParamsRcd& omtfParamsRcd = evSetup.get(); - - edm::ESHandle omtfParamsHandle; - omtfParamsRcd.get(omtfParamsHandle); + m_InputMaker.initialize(evSetup); //FIXME shoun't it be in beginRun? - const L1TMuonOverlapParams* omtfParams = omtfParamsHandle.product(); - if (!omtfParams) { - edm::LogError("L1TMuonOverlapTrackProducer") << "Could not retrieve parameters from Event Setup" << std::endl; - } + loadAndFilterDigis(iEvent); - m_OMTF = new OMTFProcessor(m_Config.getParameter("omtf")); - m_OMTF->configure(omtfParams); + if(dumpResultToXML) aTopElement = m_Writer->writeEventHeader(iEvent.id().event()); + + // NOTE: assuming all is for bx 0 + int bx = 0; + std::auto_ptr candidates(new l1t::RegionalMuonCandBxCollection); + + ///The order is important: first put omtf_pos candidates, then omtf_neg. + for(unsigned int iProcessor=0; iProcessor dtPhDigis; - edm::Handle dtThDigis; - edm::Handle cscDigis; - edm::Handle rpcDigis; +///////////////////////////////////////////////////// +///////////////////////////////////////////////////// +void OMTFReconstruction::loadAndFilterDigis(const edm::Event& iEvent){ + // Filter digis by dropping digis from selected (by cfg.py) subsystems if(!m_Config.getParameter("dropDTPrimitives")){ iEvent.getByLabel(m_Config.getParameter("srcDTPh"),dtPhDigis); iEvent.getByLabel(m_Config.getParameter("srcDTTh"),dtThDigis); } if(!m_Config.getParameter("dropRPCPrimitives")) iEvent.getByLabel(m_Config.getParameter("srcRPC"),rpcDigis); if(!m_Config.getParameter("dropCSCPrimitives")) iEvent.getByLabel(m_Config.getParameter("srcCSC"),cscDigis); - - AlgoMuonResults algoMuonResults; - algoMuonResults.clear(); - - ///Loop over all processors, each covering 60 deg in phi - for(unsigned int iProcessor=0;iProcessor<6;++iProcessor){ - - OMTFinput inputPos = m_InputMaker.buildInputForProcessor(dtPhDigis.product(), - dtThDigis.product(), - cscDigis.product(), - rpcDigis.product(), - iProcessor, - l1t::tftype::omtf_pos); - OMTFinput inputNeg = m_InputMaker.buildInputForProcessor(dtPhDigis.product(), - dtThDigis.product(), - cscDigis.product(), - rpcDigis.product(), - iProcessor, - l1t::tftype::omtf_neg); - - std::vector algoCandidatesPos, algoCandidatesNeg; - - const std::vector & resultsPos = m_OMTF->processInput(iProcessor, inputPos); - m_Sorter.sortRefHitResults(resultsPos, algoCandidatesPos); - algoMuonResults.push_back(make_pair(iProcessor*2, algoCandidatesPos)); - - const std::vector & resultsNeg = m_OMTF->processInput(iProcessor, inputNeg); - m_Sorter.sortRefHitResults(resultsNeg, algoCandidatesNeg); - algoMuonResults.push_back(make_pair(iProcessor*2 + 1, algoCandidatesNeg)); - } - - delete m_OMTF; - return algoMuonResults; + } - ///////////////////////////////////////////////////// ///////////////////////////////////////////////////// -std::auto_ptr OMTFReconstruction::reconstruct(const edm::Event& iEvent, const edm::EventSetup& evSetup) { +void OMTFReconstruction::getProcessorCandidates(unsigned int iProcessor, l1t::tftype mtfType, int bx, + l1t::RegionalMuonCandBxCollection & OTFCandidates){ + + OMTFinput input = m_InputMaker.buildInputForProcessor(dtPhDigis.product(), + dtThDigis.product(), + cscDigis.product(), + rpcDigis.product(), + iProcessor, mtfType); + + const std::vector & results = m_OMTF->processInput(iProcessor,input); - m_InputMaker.initialize(evSetup); //FIXME shoun't it be in beginRun? + std::vector algoCandidates; - edm::Handle dtPhDigis; - edm::Handle dtThDigis; - edm::Handle cscDigis; - edm::Handle rpcDigis; + m_Sorter.sortRefHitResults(results, algoCandidates); + m_GhostBuster.select(algoCandidates); + m_Sorter.sortProcessorAndFillCandidates(iProcessor, mtfType, algoCandidates, OTFCandidates, bx); - ///Filter digis by dropping digis from selected (by cfg.py) subsystems - if(!m_Config.getParameter("dropDTPrimitives")){ - iEvent.getByLabel(m_Config.getParameter("srcDTPh"),dtPhDigis); - iEvent.getByLabel(m_Config.getParameter("srcDTTh"),dtThDigis); - } - if(!m_Config.getParameter("dropRPCPrimitives")) iEvent.getByLabel(m_Config.getParameter("srcRPC"),rpcDigis); - if(!m_Config.getParameter("dropCSCPrimitives")) iEvent.getByLabel(m_Config.getParameter("srcCSC"),cscDigis); + writeResultToXML(iProcessor, input, results); +} - std::auto_ptr candidates(new l1t::RegionalMuonCandBxCollection); - if(dumpResultToXML) aTopElement = m_Writer->writeEventHeader(iEvent.id().event()); - - // NOTE: assuming all is for bx 0 - int bx = 0; - m_AlgoMuonResults.clear(); - - ///Loop over all processors, each covering 60 deg in phi - for(unsigned int iProcessor=0;iProcessor<6;++iProcessor){ - - ///Input data with phi ranges shifted for each processor, so it fits 11 bits range - OMTFinput inputPos = m_InputMaker.buildInputForProcessor(dtPhDigis.product(), - dtThDigis.product(), - cscDigis.product(), - rpcDigis.product(), - iProcessor, - l1t::tftype::omtf_pos); - - OMTFinput inputNeg = m_InputMaker.buildInputForProcessor(dtPhDigis.product(), - dtThDigis.product(), - cscDigis.product(), - rpcDigis.product(), - iProcessor, - l1t::tftype::omtf_neg); - - l1t::RegionalMuonCandBxCollection OTFCandidatesPos, OTFCandidatesNeg; - std::vector algoCandidatesPos, algoCandidatesNeg; - - //==================== - // positive - //==================== - ///Results for each GP in each logic region of given processor - //Retreive all candidates returned by sorter: upto 3 non empty ones with different phi or charge - const std::vector & resultsPos = m_OMTF->processInput(iProcessor, inputPos); - m_Sorter.sortRefHitResults(resultsPos, algoCandidatesPos); - m_AlgoMuonResults.push_back(make_pair(iProcessor*2, algoCandidatesPos)); - // m_GhostBuster.select(algoCandidatesPos); - m_Sorter.rewriteToRegionalMuon(algoCandidatesPos, OTFCandidatesPos, bx); // rewrite AlgoMuon to RegionalMuon - ///Shift phi scales, and put MicroGMT candidates into candidates collection - m_Sorter.processCandidates(iProcessor, bx, candidates, OTFCandidatesPos, l1t::tftype::omtf_pos); - - //==================== - // negative - //==================== - const std::vector & resultsNeg = m_OMTF->processInput(iProcessor, inputNeg); - m_Sorter.sortRefHitResults(resultsNeg, algoCandidatesNeg); - m_AlgoMuonResults.push_back(make_pair(iProcessor*2 + 1, algoCandidatesNeg)); - // m_GhostBuster.select(algoCandidatesNeg); - m_Sorter.rewriteToRegionalMuon(algoCandidatesNeg, OTFCandidatesNeg, bx); // rewrite AlgoMuon to RegionalMuon - ///Shift phi scales, and put MicroGMT candidates into m_Cands collection - m_Sorter.processCandidates(iProcessor, bx, candidates, OTFCandidatesNeg, l1t::tftype::omtf_neg); - - ///Write data to XML file - // if(dumpResultToXML){ - // xercesc::DOMElement * aProcElement = m_Writer->writeEventData(aTopElement,iProcessor,inputPos); - // for(unsigned int iRefHit=0; iRefHit < OMTFConfiguration::nTestRefHits; ++iRefHit){ - // ///Dump only regions, where a candidate was found - // // AlgoMuon m_Cand = m_Sorter.sortRefHitResults(resultsPos[iRefHit],0);//charge=0 means ignore charge - // AlgoMuon algoCand = algoCandidatesPos[iRefHit]; - // if(algoCand.getPt()){ - // m_Writer->writeCandidateData(aProcElement, iRefHit, algoCand); - // if(dumpDetailedResultToXML){ - // for(auto & itKey: resultsNeg[iRefHit]) m_Writer->writeResultsData(aProcElement, - // iRefHit, - // itKey.first,itKey.second); - // } - // } - // } - // } - +///////////////////////////////////////////////////// +///////////////////////////////////////////////////// +void OMTFReconstruction::writeResultToXML(unsigned int iProcessor, const OMTFinput &input, + const std::vector & results){ + + //Write data to XML file + if(dumpResultToXML){ + xercesc::DOMElement * aProcElement = m_Writer->writeEventData(aTopElement,iProcessor,input); + for(unsigned int iRefHit=0;iRefHitwriteCandidateData(aProcElement,iRefHit,myCand); + if(dumpDetailedResultToXML){ + for(auto & itKey: results[iRefHit]) + m_Writer->writeResultsData(aProcElement, iRefHit, itKey.first,itKey.second); + } + } } - return candidates; } +} \ No newline at end of file diff --git a/L1Trigger/L1TMuonOverlap/src/OMTFSorter.cc b/L1Trigger/L1TMuonOverlap/src/OMTFSorter.cc index 9f5745312a12e..d25cce390bf5c 100644 --- a/L1Trigger/L1TMuonOverlap/src/OMTFSorter.cc +++ b/L1Trigger/L1TMuonOverlap/src/OMTFSorter.cc @@ -124,68 +124,108 @@ AlgoMuon OMTFSorter::sortRefHitResults(const OMTFProcessor::resultsMap & aResult } /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// -AlgoMuon OMTFSorter::sortProcessorResults(const std::vector & procResults, - int charge){ //method kept for backward compatibility - - std::vector sortedCandidates; - sortProcessorResults(procResults, sortedCandidates, charge); - - AlgoMuon candidate = sortedCandidates.size()>0 ? sortedCandidates[0] : AlgoMuon(0,999,9999,0,0,0,0,-1); - - std::ostringstream myStr; - myStr<<"Selected Candidate with charge: "< & procResults, std::vector & refHitCands, int charge){ for(auto itRefHit: procResults) refHitCands.push_back(sortRefHitResults(itRefHit,charge)); } - /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// -void OMTFSorter::sortProcessorResults(const std::vector & procResults, - std::vector & refHitCleanCands, - int charge){ +// AlgoMuon OMTFSorter::sortProcessorResults(const std::vector & procResults, +// int charge){ //method kept for backward compatibility - refHitCleanCands.clear(); - std::vector refHitCands; +// std::vector sortedCandidates; +// sortProcessorResults(procResults, sortedCandidates, charge); - for(auto itRefHit: procResults) refHitCands.push_back(sortRefHitResults(itRefHit,charge)); +// AlgoMuon candidate = sortedCandidates.size()>0 ? sortedCandidates[0] : AlgoMuon(0,999,9999,0,0,0,0,-1); + +// std::ostringstream myStr; +// myStr<<"Selected Candidate with charge: "< & procResults, +// std::vector & refHitCleanCands, +// int charge){ + +// refHitCleanCands.clear(); +// std::vector refHitCands; + +// for(auto itRefHit: procResults) refHitCands.push_back(sortRefHitResults(itRefHit,charge)); + +// // Sort candidates with decreased goodness, +// // where goodness definied in < operator of AlgoMuon +// std::sort( refHitCands.begin(), refHitCands.end() ); + +// // Clean candidate list by removing dupicates basing on Phi distance. +// // Assumed that the list is ordered +// for(std::vector::iterator it1 = refHitCands.begin(); +// it1 != refHitCands.end(); ++it1){ +// bool isGhost=false; +// for(std::vector::iterator it2 = refHitCleanCands.begin(); +// it2 != refHitCleanCands.end(); ++it2){ +// //do not accept candidates with similar phi (any charge combination) +// //veto window 5deg(=half of logic cone)=5/360*5760=80"logic strips" +// if(std::abs(it1->phi - it2->phi)<5/360.0*OMTFConfiguration::nPhiBins){ +// isGhost=true; +// break; +// } +// } +// if(it1->q>0 && !isGhost) refHitCleanCands.push_back(*it1); +// } +// //return 3 candidates (adding empty ones if needed) +// refHitCleanCands.resize( 3, AlgoMuon(0,999,9999,0,0,0,0,0) ); + +// std::ostringstream myStr; +// bool hasCandidates = false; +// for(unsigned int iRefHit=0;iRefHit & procResults, - int charge){ //method kept for backward compatibility - - AlgoMuon myCand = sortProcessorResults(procResults, charge); - - l1t::RegionalMuonCand candidate; - std::bitset<17> bits(myCand.getHits()); - int ipt = myCand.getPt()+1; - if(ipt>31) ipt=31; - candidate.setHwPt(RPCConst::ptFromIpt(ipt)*2.0);//MicroGMT has 0.5 GeV pt bins - candidate.setHwEta(myCand.getEta());//eta scale set during input making in OMTFInputmaker - candidate.setHwPhi(myCand.getPhi()); - candidate.setHwSign(myCand.getCharge()+1*(myCand.getCharge()<0)); - candidate.setHwQual(bits.count()); - std::map trackAddr; - trackAddr[0] = myCand.getHits(); - trackAddr[1] = myCand.getRefLayer(); - trackAddr[2] = myCand.getDisc(); - candidate.setTrackAddress(trackAddr); +// l1t::RegionalMuonCand OMTFSorter::sortProcessor(const std::vector & procResults, +// int charge){ //method kept for backward compatibility + +// AlgoMuon myCand = sortProcessorResults(procResults, charge); + +// l1t::RegionalMuonCand candidate; +// std::bitset<17> bits(myCand.getHits()); +// int ipt = myCand.getPt()+1; +// if(ipt>31) ipt=31; +// candidate.setHwPt(RPCConst::ptFromIpt(ipt)*2.0);//MicroGMT has 0.5 GeV pt bins +// candidate.setHwEta(myCand.getEta());//eta scale set during input making in OMTFInputmaker +// candidate.setHwPhi(myCand.getPhi()); +// candidate.setHwSign(myCand.getCharge()+1*(myCand.getCharge()<0)); +// candidate.setHwQual(bits.count()); +// std::map trackAddr; +// trackAddr[0] = myCand.getHits(); +// trackAddr[1] = myCand.getRefLayer(); +// trackAddr[2] = myCand.getDisc(); +// candidate.setTrackAddress(trackAddr); - return candidate; -} +// return candidate; +// } /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// bool OMTFSorter::checkHitPatternValidity(unsigned int hits){ @@ -201,20 +241,23 @@ bool OMTFSorter::checkHitPatternValidity(unsigned int hits){ } /////////////////////////////////////////////////////// /////////////////////////////////////////////////////// -void OMTFSorter::rewriteToRegionalMuon(const std::vector & AlgoCands, - l1t::RegionalMuonCandBxCollection & sortedCands, - int bx, int charge){ - - sortedCands.clear(); - // std::vector mySortedCands; - // sortProcessorResults(procResults, mySortedCands, charge); +void OMTFSorter::sortProcessorAndFillCandidates(unsigned int iProcessor, l1t::tftype mtfType, + const std::vector & algoCands, + l1t::RegionalMuonCandBxCollection & sortedCands, + int bx, int charge){ - for(auto myCand: AlgoCands){ + for(auto myCand: algoCands){ l1t::RegionalMuonCand candidate; std::bitset<17> bits(myCand.getHits()); candidate.setHwPt(myCand.getPt()); candidate.setHwEta(myCand.getEta()); - candidate.setHwPhi(myCand.getPhi()); + + float phiValue = myCand.getPhi(); + if(phiValue>=(int)OMTFConfiguration::nPhiBins) phiValue-=OMTFConfiguration::nPhiBins; + ///conversion factor from OMTF to uGMT scale: 5400/576 + phiValue/=9.375; + candidate.setHwPhi(phiValue); + candidate.setHwSign(myCand.getCharge()<0 ? 1:0 ); ///Quality is set to number of leayers hit. ///DT bending and position hit is counted as one. @@ -227,30 +270,7 @@ void OMTFSorter::rewriteToRegionalMuon(const std::vector & AlgoCands, trackAddr[1] = myCand.getRefLayer(); trackAddr[2] = myCand.getDisc(); candidate.setTrackAddress(trackAddr); - - sortedCands.push_back(bx, candidate); + candidate.setTFIdentifiers(iProcessor,mtfType); + if(candidate.hwPt()) sortedCands.push_back(bx, candidate); } - - return; -} -/////////////////////////////////////////////////////// -/////////////////////////////////////////////////////// -void OMTFSorter::processCandidates(unsigned int iProcessor, int bx, - std::auto_ptr & myCands, - const l1t::RegionalMuonCandBxCollection & myOTFCandidates, - l1t::tftype mtfType){ - - for(unsigned int iCand=0; iCand=(int)OMTFConfiguration::nPhiBins) phiValue-=OMTFConfiguration::nPhiBins; - ///conversion factor from OMTF to uGMT scale: 5400/576 - phiValue/=9.375; - cand.setHwPhi(phiValue); - cand.setTFIdentifiers(iProcessor,mtfType); - - // store candidate - if(cand.hwPt()) myCands->push_back(bx, cand); - } -} - +} \ No newline at end of file From 5834e9ea44f1909722c131e01552c152a4aa2b4a Mon Sep 17 00:00:00 2001 From: Marcin Date: Fri, 4 Mar 2016 00:33:43 +0100 Subject: [PATCH 3/3] fix quality, now based on hit pattern --- L1Trigger/L1TMuonOverlap/src/OMTFSorter.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/L1Trigger/L1TMuonOverlap/src/OMTFSorter.cc b/L1Trigger/L1TMuonOverlap/src/OMTFSorter.cc index d25cce390bf5c..53636d1337ce1 100644 --- a/L1Trigger/L1TMuonOverlap/src/OMTFSorter.cc +++ b/L1Trigger/L1TMuonOverlap/src/OMTFSorter.cc @@ -259,12 +259,20 @@ void OMTFSorter::sortProcessorAndFillCandidates(unsigned int iProcessor, l1t::tf candidate.setHwPhi(phiValue); candidate.setHwSign(myCand.getCharge()<0 ? 1:0 ); + //FIXME: Obsolete ///Quality is set to number of leayers hit. ///DT bending and position hit is counted as one. ///thus we subtract 1 for each DT station hit. - candidate.setHwQual(bits.count() - bits.test(0) - bits.test(2) - bits.test(4)); + //candidate.setHwQual(bits.count() - bits.test(0) - bits.test(2) - bits.test(4)); ///Candidates with bad hit patterns get quality 0. - if(!checkHitPatternValidity(myCand.getHits())) candidate.setHwQual(0); + //if(!checkHitPatternValidity(myCand.getHits())) candidate.setHwQual(0); + + /// Now quality based on hit pattern + /// + unsigned int quality = checkHitPatternValidity(myCand.getHits()) ? 0 | (1 << 2) | (1 << 3) + : 0 | (1 << 2); + candidate.setHwQual ( quality); + std::map trackAddr; trackAddr[0] = myCand.getHits(); trackAddr[1] = myCand.getRefLayer(); @@ -273,4 +281,4 @@ void OMTFSorter::sortProcessorAndFillCandidates(unsigned int iProcessor, l1t::tf candidate.setTFIdentifiers(iProcessor,mtfType); if(candidate.hwPt()) sortedCands.push_back(bx, candidate); } -} \ No newline at end of file +}