From 532deb21856b6d7bfab4b679b935309f4f91e5b4 Mon Sep 17 00:00:00 2001 From: Santiago Date: Tue, 14 May 2019 17:05:12 +0200 Subject: [PATCH 1/3] Factorize filter to a separate function --- .../interface/DTTrigPhase2Prod.h | 7 +- .../interface/MuonPathFilter.h | 85 ++++++++++ .../dtTriggerPhase2PrimitiveDigis_cfi.py | 2 +- .../DTPhase2Trigger/src/DTTrigPhase2Prod.cc | 124 +++----------- .../DTPhase2Trigger/src/MuonPathFilter.cc | 156 ++++++++++++++++++ 5 files changed, 265 insertions(+), 109 deletions(-) create mode 100644 L1Trigger/DTPhase2Trigger/interface/MuonPathFilter.h create mode 100644 L1Trigger/DTPhase2Trigger/src/MuonPathFilter.cc diff --git a/L1Trigger/DTPhase2Trigger/interface/DTTrigPhase2Prod.h b/L1Trigger/DTPhase2Trigger/interface/DTTrigPhase2Prod.h index c131235ee6525..71812727a3fea 100644 --- a/L1Trigger/DTPhase2Trigger/interface/DTTrigPhase2Prod.h +++ b/L1Trigger/DTPhase2Trigger/interface/DTTrigPhase2Prod.h @@ -21,6 +21,7 @@ #include "L1Trigger/DTPhase2Trigger/interface/InitialGrouping.h" #include "L1Trigger/DTPhase2Trigger/interface/MuonPathAnalyzer.h" #include "L1Trigger/DTPhase2Trigger/interface/MuonPathAnalyzerPerSL.h" +#include "L1Trigger/DTPhase2Trigger/interface/MuonPathFilter.h" #include "CalibMuon/DTDigiSync/interface/DTTTrigBaseSync.h" #include "CalibMuon/DTDigiSync/interface/DTTTrigSyncFactory.h" @@ -82,8 +83,6 @@ class DTTrigPhase2Prod: public edm::EDProducer{ std::vector> primitives; - int arePrimos(metaPrimitive primera, metaPrimitive segunda); - int rango(metaPrimitive primera); bool outer(metaPrimitive primera); bool inner(metaPrimitive primera); void printmP(metaPrimitive mP); @@ -123,7 +122,6 @@ class DTTrigPhase2Prod: public edm::EDProducer{ int min_phinhits_match_segment; bool do_correlation; int p2_df; - bool filter_primos; // txt ttrig flag bool txt_ttrig_bc0; @@ -136,7 +134,8 @@ class DTTrigPhase2Prod: public edm::EDProducer{ // Grouping attributes and methods Int_t grcode; // Grouping code MotherGrouping* grouping_obj; - MuonPathAnalyzer* mpathanalyzer; +MuonPathAnalyzer* mpathanalyzer; +MuonPathFilter* mpathfilter; }; diff --git a/L1Trigger/DTPhase2Trigger/interface/MuonPathFilter.h b/L1Trigger/DTPhase2Trigger/interface/MuonPathFilter.h new file mode 100644 index 0000000000000..84c179e7490b5 --- /dev/null +++ b/L1Trigger/DTPhase2Trigger/interface/MuonPathFilter.h @@ -0,0 +1,85 @@ +#ifndef Phase2L1Trigger_DTTrigger_MuonPathFilter_cc +#define Phase2L1Trigger_DTTrigger_MuonPathFilter_cc + +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/EDProducer.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/Run.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "DataFormats/MuonDetId/interface/DTChamberId.h" +#include "DataFormats/MuonDetId/interface/DTSuperLayerId.h" +#include "DataFormats/MuonDetId/interface/DTLayerId.h" +#include "DataFormats/MuonDetId/interface/DTWireId.h" +#include "DataFormats/DTDigi/interface/DTDigiCollection.h" +#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h" +#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhDigi.h" +#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThContainer.h" +#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThDigi.h" + +#include "L1Trigger/DTPhase2Trigger/interface/muonpath.h" +#include "L1Trigger/DTPhase2Trigger/interface/analtypedefs.h" +#include "L1Trigger/DTPhase2Trigger/interface/constants.h" +#include "L1Trigger/DTPhase2Trigger/interface/MuonPathFilter.h" + +#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambContainer.h" +#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambDigi.h" + +#include "CalibMuon/DTDigiSync/interface/DTTTrigBaseSync.h" +#include "CalibMuon/DTDigiSync/interface/DTTTrigSyncFactory.h" + +#include "L1Trigger/DTSectorCollector/interface/DTSectCollPhSegm.h" +#include "L1Trigger/DTSectorCollector/interface/DTSectCollThSegm.h" + +#include "Geometry/Records/interface/MuonGeometryRecord.h" +#include "Geometry/DTGeometry/interface/DTGeometry.h" +#include "Geometry/DTGeometry/interface/DTLayer.h" + +#include +#include + + +// =============================================================================== +// Previous definitions and declarations +// =============================================================================== + +// =============================================================================== +// Class declarations +// =============================================================================== + +class MuonPathFilter { + public: + // Constructors and destructor + MuonPathFilter(const edm::ParameterSet& pset); + virtual ~MuonPathFilter(); + + // Main methods + void initialise(const edm::EventSetup& iEventSetup); + void run(edm::Event& iEvent, const edm::EventSetup& iEventSetup, std::vector &inMPath, std::vector &outMPath); + + void finish(); + + // Other public methods + + // Public attributes + int areCousins(metaPrimitive mp1, metaPrimitive mp2); + int rango(metaPrimitive mp); + void printmP(metaPrimitive mP); + + private: + // Private methods + void filterCousins(std::vector &inMPath, std::vector &outMPath); + void filterTanPhi(std::vector &inMPath, std::vector &outMPath); + + + // Private attributes + Bool_t debug; + bool filter_cousins; + double tanPhiTh; +}; + + +#endif diff --git a/L1Trigger/DTPhase2Trigger/python/dtTriggerPhase2PrimitiveDigis_cfi.py b/L1Trigger/DTPhase2Trigger/python/dtTriggerPhase2PrimitiveDigis_cfi.py index 90c1d4a184fec..4aadc139b6d35 100644 --- a/L1Trigger/DTPhase2Trigger/python/dtTriggerPhase2PrimitiveDigis_cfi.py +++ b/L1Trigger/DTPhase2Trigger/python/dtTriggerPhase2PrimitiveDigis_cfi.py @@ -11,7 +11,7 @@ dT0_correlate_TP = cms.untracked.double(25.), minx_match_2digis = cms.untracked.double(2.1), p2_df = cms.untracked.int32(2), #1 for phase-1, 2 for slice-test, 3 for phase-2 carlo-federica - filter_primos = cms.untracked.bool(True), + filter_cousins = cms.untracked.bool(True), apply_txt_ttrig_bc0 = cms.untracked.bool(False), ttrig_filename = cms.untracked.string('data/wire_rawId_ttrig.txt'), z_filename = cms.untracked.string('data/wire_rawId_z.txt'), diff --git a/L1Trigger/DTPhase2Trigger/src/DTTrigPhase2Prod.cc b/L1Trigger/DTPhase2Trigger/src/DTTrigPhase2Prod.cc index 3d0d29ba812d7..e39f10c135002 100644 --- a/L1Trigger/DTPhase2Trigger/src/DTTrigPhase2Prod.cc +++ b/L1Trigger/DTPhase2Trigger/src/DTTrigPhase2Prod.cc @@ -84,7 +84,6 @@ DTTrigPhase2Prod::DTTrigPhase2Prod(const ParameterSet& pset){ do_correlation = pset.getUntrackedParameter("do_correlation"); p2_df = pset.getUntrackedParameter("p2_df"); - filter_primos = pset.getUntrackedParameter("filter_primos"); txt_ttrig_bc0 = pset.getUntrackedParameter("apply_txt_ttrig_bc0"); @@ -103,6 +102,7 @@ DTTrigPhase2Prod::DTTrigPhase2Prod(const ParameterSet& pset){ } mpathanalyzer = new MuonPathAnalyzerPerSL(pset); + mpathfilter = new MuonPathFilter(pset); int rawId; @@ -154,7 +154,8 @@ DTTrigPhase2Prod::~DTTrigPhase2Prod(){ if(debug) std::cout<<"DTp2: calling destructor"<().get( dtConfig ); grouping_obj->initialise(iEventSetup); // Grouping object initialisation - mpathanalyzer->initialise(iEventSetup); // Grouping object initialisation + mpathanalyzer->initialise(iEventSetup); // Analyzer object initialisation + mpathfilter->initialise(iEventSetup); // Filter object initialisation //trigGeomUtils = new DTTrigGeomUtils(dtGeo); @@ -232,7 +234,7 @@ void DTTrigPhase2Prod::produce(Event & iEvent, const EventSetup& iEventSetup){ for (unsigned int i=0; i filteredMetaPrimitives; - - if(filter_primos){ - - if(debug) std::cout<<"filtering: starting primos filtering"<run(iEvent, iEventSetup, metaPrimitives, filteredMetaPrimitives); // New grouping implementation - int primo_index=0; - bool oneof4=false; - // for (auto metaPrimitiveIt = metaPrimitives.begin(); metaPrimitiveIt != metaPrimitives.end(); ++metaPrimitiveIt){ - if(metaPrimitives.size()==1){ - if(debug){ - std::cout<<"filtering:"; - printmP(metaPrimitives[0]); - std::cout<<" \t is:"<<0<<" "<finish(); mpathanalyzer->finish(); + mpathfilter->finish(); }; - -int DTTrigPhase2Prod::arePrimos(metaPrimitive primera, metaPrimitive segunda) { - if(primera.rawId!=segunda.rawId) return 0; - if(primera.wi1==segunda.wi1 and primera.tdc1==segunda.tdc1 and primera.wi1!=-1 and primera.tdc1!=-1) return 1; - if(primera.wi2==segunda.wi2 and primera.tdc2==segunda.tdc2 and primera.wi2!=-1 and primera.tdc2!=-1) return 2; - if(primera.wi3==segunda.wi3 and primera.tdc3==segunda.tdc3 and primera.wi3!=-1 and primera.tdc3!=-1) return 3; - if(primera.wi4==segunda.wi4 and primera.tdc4==segunda.tdc4 and primera.wi4!=-1 and primera.tdc4!=-1) return 4; - return 0; -} - - -void DTTrigPhase2Prod::printmP(metaPrimitive mP){ - DTSuperLayerId slId(mP.rawId); - std::cout<("debug"); + filter_cousins = pset.getUntrackedParameter("filter_cousins"); + tanPhiTh = pset.getUntrackedParameter("tanPhiTh"); + if (debug) cout <<"MuonPathFilter: constructor" << endl; +} + + +MuonPathFilter::~MuonPathFilter() { + if (debug) cout <<"MuonPathFilter: destructor" << endl; +} + + + +// ============================================================================ +// Main methods (initialise, run, finish) +// ============================================================================ +void MuonPathFilter::initialise(const edm::EventSetup& iEventSetup) { + if(debug) cout << "MuonPathFilter::initialiase" << endl; +} + +int MuonPathFilter::areCousins(metaPrimitive primera, metaPrimitive segunda) { + if(primera.rawId!=segunda.rawId) return 0; + if(primera.wi1==segunda.wi1 and primera.tdc1==segunda.tdc1 and primera.wi1!=-1 and primera.tdc1!=-1) return 1; + if(primera.wi2==segunda.wi2 and primera.tdc2==segunda.tdc2 and primera.wi2!=-1 and primera.tdc2!=-1) return 2; + if(primera.wi3==segunda.wi3 and primera.tdc3==segunda.tdc3 and primera.wi3!=-1 and primera.tdc3!=-1) return 3; + if(primera.wi4==segunda.wi4 and primera.tdc4==segunda.tdc4 and primera.wi4!=-1 and primera.tdc4!=-1) return 4; + return 0; +} +int MuonPathFilter::rango(metaPrimitive primera) { + int rango=0; + if(primera.wi1!=-1)rango++; + if(primera.wi2!=-1)rango++; + if(primera.wi3!=-1)rango++; + if(primera.wi4!=-1)rango++; + return rango; +} + +void MuonPathFilter::run(edm::Event& iEvent, const edm::EventSetup& iEventSetup, + std::vector &inMPaths, + std::vector &outMPaths) +{ + + if (debug) cout <<"MuonPathFilter: run" << endl; + + if(filter_cousins) + filterCousins(inMPaths,outMPaths); + else + filterTanPhi(inMPaths,outMPaths); + + if (debug) cout <<"MuonPathFilter: done" << endl; +} + +void MuonPathFilter::filterCousins(std::vector &inMPaths, + std::vector &outMPaths) +{ + if(debug) std::cout<<"filtering: starting cousins filtering"< Date: Tue, 14 May 2019 18:59:40 +0200 Subject: [PATCH 2/3] Factorize Muon path correlation --- .../interface/DTTrigPhase2Prod.h | 24 +- .../interface/MuonPathAssociator.h | 83 +++ .../DTPhase2Trigger/src/DTTrigPhase2Prod.cc | 696 +++++------------- .../DTPhase2Trigger/src/MuonPathAssociator.cc | 419 +++++++++++ 4 files changed, 675 insertions(+), 547 deletions(-) create mode 100644 L1Trigger/DTPhase2Trigger/interface/MuonPathAssociator.h create mode 100644 L1Trigger/DTPhase2Trigger/src/MuonPathAssociator.cc diff --git a/L1Trigger/DTPhase2Trigger/interface/DTTrigPhase2Prod.h b/L1Trigger/DTPhase2Trigger/interface/DTTrigPhase2Prod.h index 71812727a3fea..7697455b28939 100644 --- a/L1Trigger/DTPhase2Trigger/interface/DTTrigPhase2Prod.h +++ b/L1Trigger/DTPhase2Trigger/interface/DTTrigPhase2Prod.h @@ -22,6 +22,7 @@ #include "L1Trigger/DTPhase2Trigger/interface/MuonPathAnalyzer.h" #include "L1Trigger/DTPhase2Trigger/interface/MuonPathAnalyzerPerSL.h" #include "L1Trigger/DTPhase2Trigger/interface/MuonPathFilter.h" +#include "L1Trigger/DTPhase2Trigger/interface/MuonPathAssociator.h" #include "CalibMuon/DTDigiSync/interface/DTTTrigBaseSync.h" #include "CalibMuon/DTDigiSync/interface/DTTTrigSyncFactory.h" @@ -67,20 +68,6 @@ class DTTrigPhase2Prod: public edm::EDProducer{ edm::ESHandle dtGeo; - //ttrig - std::string ttrig_filename; - std::map ttriginfo; - - //z - std::string z_filename; - std::map zinfo; - - //shift - std::string shift_filename; - std::map shiftinfo; - - int chosen_sl; - std::vector> primitives; bool outer(metaPrimitive primera); @@ -115,10 +102,7 @@ class DTTrigPhase2Prod: public edm::EDProducer{ // Debug Flag bool debug; bool dump; - double tanPhiTh; double dT0_correlate_TP; - double min_dT0_match_segment; - double minx_match_2digis; int min_phinhits_match_segment; bool do_correlation; int p2_df; @@ -134,8 +118,10 @@ class DTTrigPhase2Prod: public edm::EDProducer{ // Grouping attributes and methods Int_t grcode; // Grouping code MotherGrouping* grouping_obj; -MuonPathAnalyzer* mpathanalyzer; -MuonPathFilter* mpathfilter; + MuonPathAnalyzer* mpathanalyzer; + MuonPathFilter* mpathfilter; + MuonPathAssociator* mpathassociator; + }; diff --git a/L1Trigger/DTPhase2Trigger/interface/MuonPathAssociator.h b/L1Trigger/DTPhase2Trigger/interface/MuonPathAssociator.h new file mode 100644 index 0000000000000..5aec7754c9dc0 --- /dev/null +++ b/L1Trigger/DTPhase2Trigger/interface/MuonPathAssociator.h @@ -0,0 +1,83 @@ +#ifndef Phase2L1Trigger_DTTrigger_MuonPathAssociator_cc +#define Phase2L1Trigger_DTTrigger_MuonPathAssociator_cc + +#include "FWCore/Framework/interface/MakerMacros.h" +#include "FWCore/Framework/interface/EDProducer.h" +#include "FWCore/Framework/interface/ESHandle.h" +#include "FWCore/Framework/interface/Event.h" +#include "FWCore/Framework/interface/Frameworkfwd.h" +#include "FWCore/Framework/interface/EventSetup.h" +#include "FWCore/Framework/interface/Run.h" +#include "FWCore/ParameterSet/interface/ParameterSet.h" + +#include "DataFormats/MuonDetId/interface/DTChamberId.h" +#include "DataFormats/MuonDetId/interface/DTSuperLayerId.h" +#include "DataFormats/MuonDetId/interface/DTLayerId.h" +#include "DataFormats/MuonDetId/interface/DTWireId.h" +#include "DataFormats/DTDigi/interface/DTDigiCollection.h" +//#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhContainer.h" +//#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambPhDigi.h" +//#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThContainer.h" +//#include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThDigi.h" +// +#include "L1Trigger/DTPhase2Trigger/interface/muonpath.h" +#include "L1Trigger/DTPhase2Trigger/interface/analtypedefs.h" +#include "L1Trigger/DTPhase2Trigger/interface/constants.h" + +#include "Geometry/Records/interface/MuonGeometryRecord.h" +#include "Geometry/DTGeometry/interface/DTGeometry.h" +#include "Geometry/DTGeometry/interface/DTLayer.h" + +#include +#include + +// =============================================================================== +// Previous definitions and declarations +// =============================================================================== + +// =============================================================================== +// Class declarations +// =============================================================================== + +class MuonPathAssociator { + public: + // Constructors and destructor + MuonPathAssociator(const edm::ParameterSet& pset); + virtual ~MuonPathAssociator(); + + // Main methods + void initialise(const edm::EventSetup& iEventSetup); + void run(edm::Event& iEvent, const edm::EventSetup& iEventSetup, edm::Handle digis, + std::vector &inMPaths, std::vector &outMPaths); + + + void finish(); + + // Other public methods + + // Public attributes + edm::ESHandle dtGeo; + + +private: + + // Private methods + void correlateMPaths(edm::Handle digis, std::vector &inMPaths, std::vector &outMPaths); + + // void associate(metaPrimitive MP, std::vector &outMP); + + bool hasPosRF(int wh,int sec) { return wh>0 || (wh==0 && sec%4>1); } + + // Private attributes + double dT0_correlate_TP; + double minx_match_2digis; + Bool_t debug; + + //shift + std::string shift_filename; + std::map shiftinfo; + +}; + + +#endif diff --git a/L1Trigger/DTPhase2Trigger/src/DTTrigPhase2Prod.cc b/L1Trigger/DTPhase2Trigger/src/DTTrigPhase2Prod.cc index e39f10c135002..dfa4b02c8ef68 100644 --- a/L1Trigger/DTPhase2Trigger/src/DTTrigPhase2Prod.cc +++ b/L1Trigger/DTPhase2Trigger/src/DTTrigPhase2Prod.cc @@ -76,11 +76,7 @@ DTTrigPhase2Prod::DTTrigPhase2Prod(const ParameterSet& pset){ debug = pset.getUntrackedParameter("debug"); dump = pset.getUntrackedParameter("dump"); - tanPhiTh = pset.getUntrackedParameter("tanPhiTh"); - dT0_correlate_TP = pset.getUntrackedParameter("dT0_correlate_TP"); - min_dT0_match_segment = pset.getUntrackedParameter("min_dT0_match_segment"); min_phinhits_match_segment = pset.getUntrackedParameter("min_phinhits_match_segment"); - minx_match_2digis = pset.getUntrackedParameter("minx_match_2digis"); do_correlation = pset.getUntrackedParameter("do_correlation"); p2_df = pset.getUntrackedParameter("p2_df"); @@ -101,48 +97,11 @@ DTTrigPhase2Prod::DTTrigPhase2Prod(const ParameterSet& pset){ grouping_obj = new InitialGrouping(pset); } - mpathanalyzer = new MuonPathAnalyzerPerSL(pset); - mpathfilter = new MuonPathFilter(pset); - - - int rawId; - - //ttrig - ttrig_filename = pset.getUntrackedParameter("ttrig_filename"); - if(txt_ttrig_bc0){ - std::ifstream ifin(ttrig_filename.c_str()); - double ttrig; - while (ifin.good()){ - ifin >> rawId >> ttrig; - ttriginfo[rawId]=ttrig; - } - } - - //z - z_filename = pset.getUntrackedParameter("z_filename"); - std::ifstream ifin2(z_filename.c_str()); - double z; - while (ifin2.good()){ - ifin2 >> rawId >> z; - zinfo[rawId]=z; - } - - //shift - shift_filename = pset.getUntrackedParameter("shift_filename"); - std::ifstream ifin3(shift_filename.c_str()); - double shift; - while (ifin3.good()){ - ifin3 >> rawId >> shift; - shiftinfo[rawId]=shift; - } - - - chosen_sl = pset.getUntrackedParameter("trigger_with_sl"); - - if(chosen_sl!=1 && chosen_sl!=3 && chosen_sl!=4){ - std::cout<<"chosen sl must be 1,3 or 4(both superlayers)"<initialise(iEventSetup); // Grouping object initialisation mpathanalyzer->initialise(iEventSetup); // Analyzer object initialisation mpathfilter->initialise(iEventSetup); // Filter object initialisation + mpathassociator->initialise(iEventSetup); // Associator object initialisation //trigGeomUtils = new DTTrigGeomUtils(dtGeo); @@ -242,47 +203,6 @@ void DTTrigPhase2Prod::produce(Event & iEvent, const EventSetup& iEventSetup){ << endl; } } - /* - //filtro por groupos de TDC times en las mismas celdas... corrobarar si sucede... esta implementacion no existe en software pero existe en firmware - // loop over vector of muonpahts produced by grouping - int iGroup=1; - std::vector metaPrimitives; - for(auto muonpath = muonpaths.begin();muonpath!=muonpaths.end();++muonpath){ - DTPrimitive testPrim0((*muonpath)->getPrimitive(0)); - DTPrimitive testPrim1((*muonpath)->getPrimitive(1)); - DTPrimitive testPrim2((*muonpath)->getPrimitive(2)); - DTPrimitive testPrim3((*muonpath)->getPrimitive(3)); - - if(debug){ - std::cout<<"test_grouping:group # "< outPhi; - vector outP2; - vector outP2Ph; - - for (auto metaPrimitiveIt = filteredMetaPrimitives.begin(); metaPrimitiveIt != filteredMetaPrimitives.end(); ++metaPrimitiveIt){ - DTSuperLayerId slId((*metaPrimitiveIt).rawId); - if(debug) std::cout<<"looping in final vector: SuperLayerId"< resultPhi (new L1MuDTChambPhContainer); - resultPhi->setContainer(outPhi); iEvent.put(std::move(resultPhi)); - outPhi.clear(); - outPhi.erase(outPhi.begin(),outPhi.end()); - }else if(p2_df==1){ - std::unique_ptr resultP2 (new L1MuDTChambContainer); - resultP2->setContainer(outP2); iEvent.put(std::move(resultP2)); - outP2.clear(); - outP2.erase(outP2.begin(),outP2.end()); - }else if(p2_df==2){ - std::unique_ptr resultP2Ph (new L1Phase2MuDTPhContainer); - resultP2Ph->setContainer(outP2Ph); iEvent.put(std::move(resultP2Ph)); - outP2Ph.clear(); - outP2Ph.erase(outP2Ph.begin(),outP2Ph.end()); - } - - }else{ - //Silvia's code for correlationg filteredMetaPrimitives + if(debug) std::cout<<"DTp2 in event:"< outPhi; + vector outP2; + vector outP2Ph; + + for (auto metaPrimitiveIt = filteredMetaPrimitives.begin(); metaPrimitiveIt != filteredMetaPrimitives.end(); ++metaPrimitiveIt){ + DTSuperLayerId slId((*metaPrimitiveIt).rawId); + if(debug) std::cout<<"looping in final vector: SuperLayerId"< correlatedMetaPrimitives; - - for(int wh=-2;wh<=2;wh++){ - for(int st=1;st<=4;st++){ - for(int se=1;se<=14;se++){ - if(se>=13&&st!=4)continue; - - DTChamberId ChId(wh,st,se); - DTSuperLayerId sl1Id(wh,st,se,1); - DTSuperLayerId sl3Id(wh,st,se,3); - - //filterSL1 - std::vector SL1metaPrimitives; - for(auto metaprimitiveIt = filteredMetaPrimitives.begin();metaprimitiveIt!=filteredMetaPrimitives.end();++metaprimitiveIt) - if(metaprimitiveIt->rawId==sl1Id.rawId()) - SL1metaPrimitives.push_back(*metaprimitiveIt); - - //filterSL3 - std::vector SL3metaPrimitives; - for(auto metaprimitiveIt = filteredMetaPrimitives.begin();metaprimitiveIt!=filteredMetaPrimitives.end();++metaprimitiveIt) - if(metaprimitiveIt->rawId==sl3Id.rawId()) - SL3metaPrimitives.push_back(*metaprimitiveIt); - - if(SL1metaPrimitives.size()==0 and SL3metaPrimitives.size()==0) continue; - - if(debug) std::cout<<"correlating "<t0-SL3metaPrimitive->t0) < dT0_correlate_TP){//time match - double PosSL1=SL1metaPrimitive->x; - double PosSL3=SL3metaPrimitive->x; - double NewSlope=(PosSL1-PosSL3)/23.5; - double MeanT0=(SL1metaPrimitive->t0+SL3metaPrimitive->t0)/2; - double MeanPos=(PosSL3+PosSL1)/2; - double newChi2=(SL1metaPrimitive->chi2+SL3metaPrimitive->chi2)*0.5;//to be recalculated - int quality = 0; - if(SL3metaPrimitive->quality <= 2 and SL1metaPrimitive->quality <=2) quality=6; - - if((SL3metaPrimitive->quality >= 3 && SL1metaPrimitive->quality <=2) - or (SL1metaPrimitive->quality >= 3 && SL3metaPrimitive->quality <=2) ) quality=8; - - if(SL3metaPrimitive->quality >= 3 && SL1metaPrimitive->quality >=3) quality=9; - - GlobalPoint jm_x_cmssw_global = dtGeo->chamber(ChId)->toGlobal(LocalPoint(MeanPos,0.,0.));//jm_x is already extrapolated to the middle of the SL - int thisec = ChId.sector(); - if(se==13) thisec = 4; - if(se==14) thisec = 10; - double phi= jm_x_cmssw_global.phi()-0.5235988*(thisec-1); - double psi=atan(NewSlope); - double phiB=hasPosRF(ChId.wheel(),ChId.sector()) ? psi-phi :-psi-phi ; - - correlatedMetaPrimitives.push_back(metaPrimitive({ChId.rawId(),MeanT0,MeanPos,NewSlope,phi,phiB,newChi2,quality, - SL1metaPrimitive->wi1,SL1metaPrimitive->tdc1, - SL1metaPrimitive->wi2,SL1metaPrimitive->tdc2, - SL1metaPrimitive->wi3,SL1metaPrimitive->tdc3, - SL1metaPrimitive->wi4,SL1metaPrimitive->tdc4, - SL3metaPrimitive->wi1,SL3metaPrimitive->tdc1, - SL3metaPrimitive->wi2,SL3metaPrimitive->tdc2, - SL3metaPrimitive->wi3,SL3metaPrimitive->tdc3, - SL3metaPrimitive->wi4,SL3metaPrimitive->tdc4 - })); - at_least_one_correlation=true; - } - } - - if(at_least_one_correlation==false){//no correlation was found, trying with pairs of two digis in the other SL - - int matched_digis=0; - double minx=minx_match_2digis; - int best_tdc=-1; - int next_tdc=-1; - int best_wire=-1; - int next_wire=-1; - int best_layer=-1; - int next_layer=-1; - - for (auto dtLayerId_It=dtdigis->begin(); dtLayerId_It!=dtdigis->end(); ++dtLayerId_It){ - const DTLayerId dtLId = (*dtLayerId_It).first; - DTSuperLayerId dtSLId(dtLId); - if(dtSLId.rawId()!=sl3Id.rawId()) continue; - double l_shift=0; - if(dtLId.layer()==4)l_shift=1.95; - if(dtLId.layer()==3)l_shift=0.65; - if(dtLId.layer()==2)l_shift=-0.65; - if(dtLId.layer()==1)l_shift=-1.95; - double x_inSL3=SL1metaPrimitive->x-SL1metaPrimitive->tanPhi*(23.5+l_shift); - for (auto digiIt = ((*dtLayerId_It).second).first;digiIt!=((*dtLayerId_It).second).second; ++digiIt){ - DTWireId wireId(dtLId,(*digiIt).wire()); - int x_wire = shiftinfo[wireId.rawId()]+((*digiIt).time()-SL1metaPrimitive->t0)*0.00543; - int x_wire_left = shiftinfo[wireId.rawId()]-((*digiIt).time()-SL1metaPrimitive->t0)*0.00543; - if(fabs(x_inSL3-x_wire)>fabs(x_inSL3-x_wire_left)) x_wire=x_wire_left; //choose the closest laterality - if(fabs(x_inSL3-x_wire)=2 and best_layer!=-1 and next_layer!=-1){ - int new_quality=7; - if(SL1metaPrimitive->quality<=2) new_quality=5; - - int wi1=-1;int tdc1=-1; - int wi2=-1;int tdc2=-1; - int wi3=-1;int tdc3=-1; - int wi4=-1;int tdc4=-1; - - if(next_layer==1) {wi1=next_wire; tdc1=next_tdc; } - if(next_layer==2) {wi2=next_wire; tdc2=next_tdc; } - if(next_layer==3) {wi3=next_wire; tdc3=next_tdc; } - if(next_layer==4) {wi4=next_wire; tdc4=next_tdc; } - - if(best_layer==1) {wi1=best_wire; tdc1=best_tdc; } - if(best_layer==2) {wi2=best_wire; tdc2=best_tdc; } - if(best_layer==3) {wi3=best_wire; tdc3=best_tdc; } - if(best_layer==4) {wi4=best_wire; tdc4=best_tdc; } - - - - correlatedMetaPrimitives.push_back(metaPrimitive({ChId.rawId(),SL1metaPrimitive->t0,SL1metaPrimitive->x,SL1metaPrimitive->tanPhi,SL1metaPrimitive->phi,SL1metaPrimitive->phiB,SL1metaPrimitive->chi2, - new_quality, - SL1metaPrimitive->wi1,SL1metaPrimitive->tdc1, - SL1metaPrimitive->wi2,SL1metaPrimitive->tdc2, - SL1metaPrimitive->wi3,SL1metaPrimitive->tdc3, - SL1metaPrimitive->wi4,SL1metaPrimitive->tdc4, - wi1,tdc1, - wi2,tdc2, - wi3,tdc3, - wi4,tdc4 - })); - at_least_one_correlation=true; - } - } - } - - //finish SL1-SL3 - - //SL3-SL1 - for (auto SL3metaPrimitive = SL3metaPrimitives.begin(); SL3metaPrimitive != SL3metaPrimitives.end(); ++SL3metaPrimitive){ - for (auto SL1metaPrimitive = SL1metaPrimitives.begin(); SL1metaPrimitive != SL1metaPrimitives.end(); ++SL1metaPrimitive){ - if(fabs(SL1metaPrimitive->t0-SL3metaPrimitive->t0) < dT0_correlate_TP){//time match - //this comb was already filled up in the previous loop now we just want to know if there was at least one match - at_least_one_correlation=true; - } - } - - if(at_least_one_correlation==false){//no correlation was found, trying with pairs of two digis in the other SL - - int matched_digis=0; - double minx=minx_match_2digis; - int best_tdc=-1; - int next_tdc=-1; - int best_wire=-1; - int next_wire=-1; - int best_layer=-1; - int next_layer=-1; - - for (auto dtLayerId_It=dtdigis->begin(); dtLayerId_It!=dtdigis->end(); ++dtLayerId_It){ - const DTLayerId dtLId = (*dtLayerId_It).first; - DTSuperLayerId dtSLId(dtLId); - if(dtSLId.rawId()!=sl1Id.rawId()) continue; - double l_shift=0; - if(dtLId.layer()==4)l_shift=1.95; - if(dtLId.layer()==3)l_shift=0.65; - if(dtLId.layer()==2)l_shift=-0.65; - if(dtLId.layer()==1)l_shift=-1.95; - double x_inSL1=SL3metaPrimitive->x+SL3metaPrimitive->tanPhi*(23.5-l_shift); - for (auto digiIt = ((*dtLayerId_It).second).first;digiIt!=((*dtLayerId_It).second).second; ++digiIt){ - DTWireId wireId(dtLId,(*digiIt).wire()); - int x_wire = shiftinfo[wireId.rawId()]+((*digiIt).time()-SL3metaPrimitive->t0)*0.00543; - int x_wire_left = shiftinfo[wireId.rawId()]-((*digiIt).time()-SL3metaPrimitive->t0)*0.00543; - if(fabs(x_inSL1-x_wire)>fabs(x_inSL1-x_wire_left)) x_wire=x_wire_left; //choose the closest laterality - if(fabs(x_inSL1-x_wire)=2 and best_layer!=-1 and next_layer!=-1){ - int new_quality=7; - if(SL3metaPrimitive->quality<=2) new_quality=5; - - int wi1=-1;int tdc1=-1; - int wi2=-1;int tdc2=-1; - int wi3=-1;int tdc3=-1; - int wi4=-1;int tdc4=-1; - - if(next_layer==1) {wi1=next_wire; tdc1=next_tdc; } - if(next_layer==2) {wi2=next_wire; tdc2=next_tdc; } - if(next_layer==3) {wi3=next_wire; tdc3=next_tdc; } - if(next_layer==4) {wi4=next_wire; tdc4=next_tdc; } - - if(best_layer==1) {wi1=best_wire; tdc1=best_tdc; } - if(best_layer==2) {wi2=best_wire; tdc2=best_tdc; } - if(best_layer==3) {wi3=best_wire; tdc3=best_tdc; } - if(best_layer==4) {wi4=best_wire; tdc4=best_tdc; } - - - - correlatedMetaPrimitives.push_back(metaPrimitive({ChId.rawId(),SL3metaPrimitive->t0,SL3metaPrimitive->x,SL3metaPrimitive->tanPhi,SL3metaPrimitive->phi,SL3metaPrimitive->phiB,SL3metaPrimitive->chi2, - new_quality, - wi1,tdc1, - wi2,tdc2, - wi3,tdc3, - wi4,tdc4, - SL3metaPrimitive->wi1,SL3metaPrimitive->tdc1, - SL3metaPrimitive->wi2,SL3metaPrimitive->tdc2, - SL3metaPrimitive->wi3,SL3metaPrimitive->tdc3, - SL3metaPrimitive->wi4,SL3metaPrimitive->tdc4 - })); - at_least_one_correlation=true; - } - } - } - - //finish SL3-SL1 - - if(at_least_one_correlation==false){ - if(debug) std::cout<<"correlation we found zero correlations, adding both collections as they are to the correlatedMetaPrimitives"<rawId); - DTChamberId(SLId.wheel(),SLId.station(),SLId.sector()); - correlatedMetaPrimitives.push_back(metaPrimitive({ChId.rawId(),SL1metaPrimitive->t0,SL1metaPrimitive->x,SL1metaPrimitive->tanPhi,SL1metaPrimitive->phi,SL1metaPrimitive->phiB,SL1metaPrimitive->chi2,SL1metaPrimitive->quality, - SL1metaPrimitive->wi1,SL1metaPrimitive->tdc1, - SL1metaPrimitive->wi2,SL1metaPrimitive->tdc2, - SL1metaPrimitive->wi3,SL1metaPrimitive->tdc3, - SL1metaPrimitive->wi4,SL1metaPrimitive->tdc4, - -1,-1, - -1,-1, - -1,-1, - -1,-1 - })); - } - for (auto SL3metaPrimitive = SL3metaPrimitives.begin(); SL3metaPrimitive != SL3metaPrimitives.end(); ++SL3metaPrimitive){ - DTSuperLayerId SLId(SL3metaPrimitive->rawId); - DTChamberId(SLId.wheel(),SLId.station(),SLId.sector()); - correlatedMetaPrimitives.push_back(metaPrimitive({ChId.rawId(),SL3metaPrimitive->t0,SL3metaPrimitive->x,SL3metaPrimitive->tanPhi,SL3metaPrimitive->phi,SL3metaPrimitive->phiB,SL3metaPrimitive->chi2,SL3metaPrimitive->quality, - -1,-1, - -1,-1, - -1,-1, - -1,-1, - SL3metaPrimitive->wi1,SL3metaPrimitive->tdc1, - SL3metaPrimitive->wi2,SL3metaPrimitive->tdc2, - SL3metaPrimitive->wi3,SL3metaPrimitive->tdc3, - SL3metaPrimitive->wi4,SL3metaPrimitive->tdc4 - })); - } - } - - SL1metaPrimitives.clear(); - SL1metaPrimitives.erase(SL1metaPrimitives.begin(),SL1metaPrimitives.end()); - SL3metaPrimitives.clear(); - SL3metaPrimitives.erase(SL3metaPrimitives.begin(),SL3metaPrimitives.end()); - } - } + if(p2_df==0){ + outPhi.push_back(L1MuDTChambPhDigi((*metaPrimitiveIt).t0, + slId.wheel(), + sectorTP, + slId.station(), + (int)round((*metaPrimitiveIt).phi*65536./0.8), + (int)round((*metaPrimitiveIt).phiB*2048./1.4), + (*metaPrimitiveIt).quality, + 1, + 0 + )); } - - filteredMetaPrimitives.clear(); - filteredMetaPrimitives.erase(filteredMetaPrimitives.begin(),filteredMetaPrimitives.end()); - - if(debug) std::cout<<"DTp2 in event:"< resultPhi (new L1MuDTChambPhContainer); + resultPhi->setContainer(outPhi); iEvent.put(std::move(resultPhi)); + outPhi.clear(); + outPhi.erase(outPhi.begin(),outPhi.end()); + }else if(p2_df==1){ + std::unique_ptr resultP2 (new L1MuDTChambContainer); + resultP2->setContainer(outP2); iEvent.put(std::move(resultP2)); + outP2.clear(); + outP2.erase(outP2.begin(),outP2.end()); + }else if(p2_df==2){ + std::unique_ptr resultP2Ph (new L1Phase2MuDTPhContainer); + resultP2Ph->setContainer(outP2Ph); iEvent.put(std::move(resultP2Ph)); + outP2Ph.clear(); + outP2Ph.erase(outP2Ph.begin(),outP2Ph.end()); + } + } + else { + std::vector correlatedMetaPrimitives; + mpathassociator->run(iEvent, iEventSetup, dtdigis, filteredMetaPrimitives, correlatedMetaPrimitives); + + filteredMetaPrimitives.clear(); + filteredMetaPrimitives.erase(filteredMetaPrimitives.begin(),filteredMetaPrimitives.end()); + + if(debug) std::cout<<"DTp2 in event:"< outPhiCH; + vector outP2CH; + vector outP2PhCH; + + for (auto metaPrimitiveIt = correlatedMetaPrimitives.begin(); metaPrimitiveIt != correlatedMetaPrimitives.end(); ++metaPrimitiveIt){ + DTChamberId chId((*metaPrimitiveIt).rawId); + if(debug) std::cout<<"looping in final vector: SuperLayerId"< resultPhiCH (new L1MuDTChambPhContainer); - resultPhiCH->setContainer(outPhiCH); iEvent.put(std::move(resultPhiCH)); - outPhiCH.clear(); - outPhiCH.erase(outPhiCH.begin(),outPhiCH.end()); + if(p2_df==0){ + outPhiCH.push_back(thisTP); }else if(p2_df==1){ - std::unique_ptr resultP2CH (new L1MuDTChambContainer); - resultP2CH->setContainer(outP2CH); iEvent.put(std::move(resultP2CH)); - outP2CH.clear(); - outP2CH.erase(outP2CH.begin(),outP2CH.end()); + if(debug)std::cout<<"pushing back slice-test dataformat"< resultP2PhCH (new L1Phase2MuDTPhContainer); - resultP2PhCH->setContainer(outP2PhCH); iEvent.put(std::move(resultP2PhCH)); - outP2PhCH.clear(); - outP2PhCH.erase(outP2PhCH.begin(),outP2PhCH.end()); + if(debug)std::cout<<"pushing back carlo-federica dataformat"< resultPhiCH (new L1MuDTChambPhContainer); + resultPhiCH->setContainer(outPhiCH); iEvent.put(std::move(resultPhiCH)); + outPhiCH.clear(); + outPhiCH.erase(outPhiCH.begin(),outPhiCH.end()); + }else if(p2_df==1){ + std::unique_ptr resultP2CH (new L1MuDTChambContainer); + resultP2CH->setContainer(outP2CH); iEvent.put(std::move(resultP2CH)); + outP2CH.clear(); + outP2CH.erase(outP2CH.begin(),outP2CH.end()); + }else if(p2_df==2){ + std::unique_ptr resultP2PhCH (new L1Phase2MuDTPhContainer); + resultP2PhCH->setContainer(outP2PhCH); iEvent.put(std::move(resultP2PhCH)); + outP2PhCH.clear(); + outP2PhCH.erase(outP2PhCH.begin(),outP2PhCH.end()); + } } + + } void DTTrigPhase2Prod::endRun(edm::Run const& iRun, const edm::EventSetup& iEventSetup) { grouping_obj->finish(); mpathanalyzer->finish(); mpathfilter->finish(); + mpathassociator->finish(); }; diff --git a/L1Trigger/DTPhase2Trigger/src/MuonPathAssociator.cc b/L1Trigger/DTPhase2Trigger/src/MuonPathAssociator.cc new file mode 100644 index 0000000000000..ea78675a6641c --- /dev/null +++ b/L1Trigger/DTPhase2Trigger/src/MuonPathAssociator.cc @@ -0,0 +1,419 @@ +#include "L1Trigger/DTPhase2Trigger/interface/MuonPathAssociator.h" +#include "L1Trigger/DTPhase2Trigger/interface/MuonPathAnalyzerPerSL.h" + +using namespace edm; +using namespace std; + + + +// ============================================================================ +// Constructors and destructor +// ============================================================================ +MuonPathAssociator::MuonPathAssociator(const ParameterSet& pset) { + // Obtention of parameters + debug = pset.getUntrackedParameter("debug"); + dT0_correlate_TP = pset.getUntrackedParameter("dT0_correlate_TP"); + minx_match_2digis = pset.getUntrackedParameter("minx_match_2digis"); + if (debug) cout <<"MuonPathAssociator: constructor" << endl; + + //shift + int rawId; + shift_filename = pset.getUntrackedParameter("shift_filename"); + std::ifstream ifin3(shift_filename.c_str()); + double shift; + while (ifin3.good()){ + ifin3 >> rawId >> shift; + shiftinfo[rawId]=shift; + } + + + +} + + +MuonPathAssociator::~MuonPathAssociator() { + if (debug) cout <<"MuonPathAssociator: destructor" << endl; +} + + + +// ============================================================================ +// Main methods (initialise, run, finish) +// ============================================================================ +void MuonPathAssociator::initialise(const edm::EventSetup& iEventSetup) { + if(debug) cout << "MuonPathAssociator::initialiase" << endl; + + iEventSetup.get().get(dtGeo);//1103 +} + + +void MuonPathAssociator::run(edm::Event& iEvent, const edm::EventSetup& iEventSetup, + edm::Handle digis, + std::vector &inMPaths, + std::vector &outMPaths) +{ + + correlateMPaths(digis, inMPaths,outMPaths); +} + +void MuonPathAssociator::finish() { + if (debug) cout <<"MuonPathAssociator: finish" << endl; +}; + +void MuonPathAssociator::correlateMPaths(edm::Handle dtdigis, + std::vector &inMPaths, + std::vector &outMPaths) { + + + //Silvia's code for correlationg filteredMetaPrimitives + + if(debug) std::cout<<"starting correlation"<=13&&st!=4)continue; + + DTChamberId ChId(wh,st,se); + DTSuperLayerId sl1Id(wh,st,se,1); + DTSuperLayerId sl3Id(wh,st,se,3); + + //filterSL1 + std::vector SL1metaPrimitives; + for(auto metaprimitiveIt = inMPaths.begin();metaprimitiveIt!=inMPaths.end();++metaprimitiveIt) + if(metaprimitiveIt->rawId==sl1Id.rawId()) + SL1metaPrimitives.push_back(*metaprimitiveIt); + + //filterSL3 + std::vector SL3metaPrimitives; + for(auto metaprimitiveIt = inMPaths.begin();metaprimitiveIt!=inMPaths.end();++metaprimitiveIt) + if(metaprimitiveIt->rawId==sl3Id.rawId()) + SL3metaPrimitives.push_back(*metaprimitiveIt); + + if(SL1metaPrimitives.size()==0 and SL3metaPrimitives.size()==0) continue; + + if(debug) std::cout<<"correlating "<t0-SL3metaPrimitive->t0) < dT0_correlate_TP){//time match + double PosSL1=SL1metaPrimitive->x; + double PosSL3=SL3metaPrimitive->x; + double NewSlope=(PosSL1-PosSL3)/23.5; + double MeanT0=(SL1metaPrimitive->t0+SL3metaPrimitive->t0)/2; + double MeanPos=(PosSL3+PosSL1)/2; + double newChi2=(SL1metaPrimitive->chi2+SL3metaPrimitive->chi2)*0.5;//to be recalculated + int quality = 0; + if(SL3metaPrimitive->quality <= 2 and SL1metaPrimitive->quality <=2) quality=6; + + if((SL3metaPrimitive->quality >= 3 && SL1metaPrimitive->quality <=2) + or (SL1metaPrimitive->quality >= 3 && SL3metaPrimitive->quality <=2) ) quality=8; + + if(SL3metaPrimitive->quality >= 3 && SL1metaPrimitive->quality >=3) quality=9; + + GlobalPoint jm_x_cmssw_global = dtGeo->chamber(ChId)->toGlobal(LocalPoint(MeanPos,0.,0.));//jm_x is already extrapolated to the middle of the SL + int thisec = ChId.sector(); + if(se==13) thisec = 4; + if(se==14) thisec = 10; + double phi= jm_x_cmssw_global.phi()-0.5235988*(thisec-1); + double psi=atan(NewSlope); + double phiB=hasPosRF(ChId.wheel(),ChId.sector()) ? psi-phi :-psi-phi ; + + outMPaths.push_back(metaPrimitive({ChId.rawId(),MeanT0,MeanPos,NewSlope,phi,phiB,newChi2,quality, + SL1metaPrimitive->wi1,SL1metaPrimitive->tdc1, + SL1metaPrimitive->wi2,SL1metaPrimitive->tdc2, + SL1metaPrimitive->wi3,SL1metaPrimitive->tdc3, + SL1metaPrimitive->wi4,SL1metaPrimitive->tdc4, + SL3metaPrimitive->wi1,SL3metaPrimitive->tdc1, + SL3metaPrimitive->wi2,SL3metaPrimitive->tdc2, + SL3metaPrimitive->wi3,SL3metaPrimitive->tdc3, + SL3metaPrimitive->wi4,SL3metaPrimitive->tdc4 + })); + at_least_one_correlation=true; + } + } + + if(at_least_one_correlation==false){//no correlation was found, trying with pairs of two digis in the other SL + int matched_digis=0; + double minx=minx_match_2digis; + int best_tdc=-1; + int next_tdc=-1; + int best_wire=-1; + int next_wire=-1; + int best_layer=-1; + int next_layer=-1; + + for (auto dtLayerId_It=dtdigis->begin(); dtLayerId_It!=dtdigis->end(); ++dtLayerId_It){ + const DTLayerId dtLId = (*dtLayerId_It).first; + DTSuperLayerId dtSLId(dtLId); + if(dtSLId.rawId()!=sl3Id.rawId()) continue; + double l_shift=0; + if(dtLId.layer()==4)l_shift=1.95; + if(dtLId.layer()==3)l_shift=0.65; + if(dtLId.layer()==2)l_shift=-0.65; + if(dtLId.layer()==1)l_shift=-1.95; + double x_inSL3=SL1metaPrimitive->x-SL1metaPrimitive->tanPhi*(23.5+l_shift); + for (auto digiIt = ((*dtLayerId_It).second).first;digiIt!=((*dtLayerId_It).second).second; ++digiIt){ + DTWireId wireId(dtLId,(*digiIt).wire()); + int x_wire = shiftinfo[wireId.rawId()]+((*digiIt).time()-SL1metaPrimitive->t0)*0.00543; + int x_wire_left = shiftinfo[wireId.rawId()]-((*digiIt).time()-SL1metaPrimitive->t0)*0.00543; + if(fabs(x_inSL3-x_wire)>fabs(x_inSL3-x_wire_left)) x_wire=x_wire_left; //choose the closest laterality + if(fabs(x_inSL3-x_wire)=2 and best_layer!=-1 and next_layer!=-1){ + int new_quality=7; + if(SL1metaPrimitive->quality<=2) new_quality=5; + + int wi1=-1;int tdc1=-1; + int wi2=-1;int tdc2=-1; + int wi3=-1;int tdc3=-1; + int wi4=-1;int tdc4=-1; + + if(next_layer==1) {wi1=next_wire; tdc1=next_tdc; } + if(next_layer==2) {wi2=next_wire; tdc2=next_tdc; } + if(next_layer==3) {wi3=next_wire; tdc3=next_tdc; } + if(next_layer==4) {wi4=next_wire; tdc4=next_tdc; } + + if(best_layer==1) {wi1=best_wire; tdc1=best_tdc; } + if(best_layer==2) {wi2=best_wire; tdc2=best_tdc; } + if(best_layer==3) {wi3=best_wire; tdc3=best_tdc; } + if(best_layer==4) {wi4=best_wire; tdc4=best_tdc; } + + + + outMPaths.push_back(metaPrimitive({ChId.rawId(),SL1metaPrimitive->t0,SL1metaPrimitive->x,SL1metaPrimitive->tanPhi,SL1metaPrimitive->phi,SL1metaPrimitive->phiB,SL1metaPrimitive->chi2, + new_quality, + SL1metaPrimitive->wi1,SL1metaPrimitive->tdc1, + SL1metaPrimitive->wi2,SL1metaPrimitive->tdc2, + SL1metaPrimitive->wi3,SL1metaPrimitive->tdc3, + SL1metaPrimitive->wi4,SL1metaPrimitive->tdc4, + wi1,tdc1, + wi2,tdc2, + wi3,tdc3, + wi4,tdc4 + })); + at_least_one_correlation=true; + } + } + } + + //finish SL1-SL3 + + //SL3-SL1 + for (auto SL3metaPrimitive = SL3metaPrimitives.begin(); SL3metaPrimitive != SL3metaPrimitives.end(); ++SL3metaPrimitive){ + for (auto SL1metaPrimitive = SL1metaPrimitives.begin(); SL1metaPrimitive != SL1metaPrimitives.end(); ++SL1metaPrimitive){ + if(fabs(SL1metaPrimitive->t0-SL3metaPrimitive->t0) < dT0_correlate_TP){//time match + //this comb was already filled up in the previous loop now we just want to know if there was at least one match + at_least_one_correlation=true; + } + } + + if(at_least_one_correlation==false){//no correlation was found, trying with pairs of two digis in the other SL + + int matched_digis=0; + double minx=minx_match_2digis; + int best_tdc=-1; + int next_tdc=-1; + int best_wire=-1; + int next_wire=-1; + int best_layer=-1; + int next_layer=-1; + + for (auto dtLayerId_It=dtdigis->begin(); dtLayerId_It!=dtdigis->end(); ++dtLayerId_It){ + const DTLayerId dtLId = (*dtLayerId_It).first; + DTSuperLayerId dtSLId(dtLId); + if(dtSLId.rawId()!=sl1Id.rawId()) continue; + double l_shift=0; + if(dtLId.layer()==4)l_shift=1.95; + if(dtLId.layer()==3)l_shift=0.65; + if(dtLId.layer()==2)l_shift=-0.65; + if(dtLId.layer()==1)l_shift=-1.95; + double x_inSL1=SL3metaPrimitive->x+SL3metaPrimitive->tanPhi*(23.5-l_shift); + for (auto digiIt = ((*dtLayerId_It).second).first;digiIt!=((*dtLayerId_It).second).second; ++digiIt){ + DTWireId wireId(dtLId,(*digiIt).wire()); + int x_wire = shiftinfo[wireId.rawId()]+((*digiIt).time()-SL3metaPrimitive->t0)*0.00543; + int x_wire_left = shiftinfo[wireId.rawId()]-((*digiIt).time()-SL3metaPrimitive->t0)*0.00543; + if(fabs(x_inSL1-x_wire)>fabs(x_inSL1-x_wire_left)) x_wire=x_wire_left; //choose the closest laterality + if(fabs(x_inSL1-x_wire)=2 and best_layer!=-1 and next_layer!=-1){ + int new_quality=7; + if(SL3metaPrimitive->quality<=2) new_quality=5; + + int wi1=-1;int tdc1=-1; + int wi2=-1;int tdc2=-1; + int wi3=-1;int tdc3=-1; + int wi4=-1;int tdc4=-1; + + if(next_layer==1) {wi1=next_wire; tdc1=next_tdc; } + if(next_layer==2) {wi2=next_wire; tdc2=next_tdc; } + if(next_layer==3) {wi3=next_wire; tdc3=next_tdc; } + if(next_layer==4) {wi4=next_wire; tdc4=next_tdc; } + + if(best_layer==1) {wi1=best_wire; tdc1=best_tdc; } + if(best_layer==2) {wi2=best_wire; tdc2=best_tdc; } + if(best_layer==3) {wi3=best_wire; tdc3=best_tdc; } + if(best_layer==4) {wi4=best_wire; tdc4=best_tdc; } + + + + outMPaths.push_back(metaPrimitive({ChId.rawId(),SL3metaPrimitive->t0,SL3metaPrimitive->x,SL3metaPrimitive->tanPhi,SL3metaPrimitive->phi,SL3metaPrimitive->phiB,SL3metaPrimitive->chi2, + new_quality, + wi1,tdc1, + wi2,tdc2, + wi3,tdc3, + wi4,tdc4, + SL3metaPrimitive->wi1,SL3metaPrimitive->tdc1, + SL3metaPrimitive->wi2,SL3metaPrimitive->tdc2, + SL3metaPrimitive->wi3,SL3metaPrimitive->tdc3, + SL3metaPrimitive->wi4,SL3metaPrimitive->tdc4 + })); + at_least_one_correlation=true; + } + } + } + + //finish SL3-SL1 + if(at_least_one_correlation==false){ + if(debug) std::cout<<"correlation we found zero correlations, adding both collections as they are to the outMPaths"<rawId); + DTChamberId(SLId.wheel(),SLId.station(),SLId.sector()); + outMPaths.push_back(metaPrimitive({ChId.rawId(),SL1metaPrimitive->t0,SL1metaPrimitive->x,SL1metaPrimitive->tanPhi,SL1metaPrimitive->phi,SL1metaPrimitive->phiB,SL1metaPrimitive->chi2,SL1metaPrimitive->quality, + SL1metaPrimitive->wi1,SL1metaPrimitive->tdc1, + SL1metaPrimitive->wi2,SL1metaPrimitive->tdc2, + SL1metaPrimitive->wi3,SL1metaPrimitive->tdc3, + SL1metaPrimitive->wi4,SL1metaPrimitive->tdc4, + -1,-1, + -1,-1, + -1,-1, + -1,-1 + })); + } + for (auto SL3metaPrimitive = SL3metaPrimitives.begin(); SL3metaPrimitive != SL3metaPrimitives.end(); ++SL3metaPrimitive){ + DTSuperLayerId SLId(SL3metaPrimitive->rawId); + DTChamberId(SLId.wheel(),SLId.station(),SLId.sector()); + outMPaths.push_back(metaPrimitive({ChId.rawId(),SL3metaPrimitive->t0,SL3metaPrimitive->x,SL3metaPrimitive->tanPhi,SL3metaPrimitive->phi,SL3metaPrimitive->phiB,SL3metaPrimitive->chi2,SL3metaPrimitive->quality, + -1,-1, + -1,-1, + -1,-1, + -1,-1, + SL3metaPrimitive->wi1,SL3metaPrimitive->tdc1, + SL3metaPrimitive->wi2,SL3metaPrimitive->tdc2, + SL3metaPrimitive->wi3,SL3metaPrimitive->tdc3, + SL3metaPrimitive->wi4,SL3metaPrimitive->tdc4 + })); + } + } + + SL1metaPrimitives.clear(); + SL1metaPrimitives.erase(SL1metaPrimitives.begin(),SL1metaPrimitives.end()); + SL3metaPrimitives.clear(); + SL3metaPrimitives.erase(SL3metaPrimitives.begin(),SL3metaPrimitives.end()); + } + } + } +} + +/* +void MuonPathAssociator::associate(MuonPath *mpath) { + + // First try to match + if (mpath->getNPrimitivesUp()>=3 && mpath->getNPrimitivesDown()>=3) { + if(fabs(mpath->getBxTimeValue(0)-mpath->getBxTimeValue(2)) < dT0_correlate_TP) { //time match + float PosSL1=mpath->getHorizPos(0); + float PosSL3=mpath->getHorizPos(2); + float NewSlope=(PosSL1-PosSL3)/23.5; + float MeanT0=(mpath->getBxTimeValue(0)+mpath->getBxTimeValue(2))/2; + float MeanPos=(PosSL3+PosSL1)/2; + float newChi2=(mpath->getChiSq(0)+mpath->getChiSq(2))*0.5;//to be recalculated + MP_QUALITY quality=NOPATH; + + if (mpath->getQuality(0) <=LOWQ and mpath->getQuality(2) <=LOWQ) quality=LOWLOWQ; + if ((mpath->getQuality(0) >=HIGHQ and mpath->getQuality(2) <=LOWQ) or + (mpath->getQuality(0) <=LOWQ and mpath->getQuality(2) >=HIGHQ)) + quality=HIGHLOWQ; + if (mpath->getQuality(0) >=3 and mpath->getQuality(2) >=3) quality=HIGHHIGHQ; + + DTChamberId ChId(mpath->getRawId()); + GlobalPoint jm_x_cmssw_global = dtGeo->chamber(ChId)->toGlobal(LocalPoint(MeanPos,0.,0.));//jm_x is already extrapolated to the middle of the SL + int thisec = ChId.sector(); + float phi= jm_x_cmssw_global.phi()-0.5235988*(thisec-1); + float psi=atan(NewSlope); + float phiB=(hasPosRF(ChId.wheel(),ChId.sector())) ? psi-phi :-psi-phi ; + + mpath->setBxTimeValue(MeanT0); + mpath->setTanPhi(NewSlope); + mpath->setHorizPos(MeanPos); + mpath->setPhi(phi); + mpath->setPhiB(phiB); + mpath->setChiSq(newChi2); + mpath->setQuality(quality); + } + } + else if (mpath->getNPrimitivesUp()>=3 && mpath->getNPrimitivesDown()<3 && mpath->getNPrimitivesDown()>0 ) { + // IF this is not the case try to confirm with other SL: + mpath->setBxTimeValue(mpath->getBxTimeValue(2)); + mpath->setTanPhi(mpath->getTanPhi(2)); + mpath->setHorizPos(mpath->getHorizPos(2)); + mpath->setPhi(mpath->getPhi(2)); + mpath->setPhiB(mpath->getPhiB(2)); + mpath->setChiSq(mpath->getChiSq(2)); + + if (mpath->getQuality(2) == HIGHQ) + mpath->setQuality(CHIGHQ); + else if (mpath->getQuality(2) == LOWQ) + mpath->setQuality(CLOWQ); + + } + else if (mpath->getNPrimitivesDown()>=3 && mpath->getNPrimitivesDown()<3 && mpath->getNPrimitivesDown()>0 ) { + // IF this is not the case try to confirm with other SL: + mpath->setBxTimeValue(mpath->getBxTimeValue(2)); + mpath->setTanPhi(mpath->getTanPhi(2)); + mpath->setHorizPos(mpath->getHorizPos(2)); + mpath->setPhi(mpath->getPhi(2)); + mpath->setPhiB(mpath->getPhiB(2)); + mpath->setChiSq(mpath->getChiSq(2)); + mpath->setQuality(CHIGHQ); + + if (mpath->getQuality(0) == HIGHQ) + mpath->setQuality(CHIGHQ); + else if (mpath->getQuality(0) == LOWQ) + mpath->setQuality(CLOWQ); + + } + +} + +*/ + From af564caea0037566fb8d4d3be4bf9a3719e8dd49 Mon Sep 17 00:00:00 2001 From: Santiago Date: Wed, 15 May 2019 12:23:28 +0200 Subject: [PATCH 3/3] Adding Associator and further cleanup --- .../DTPhase2Trigger/src/DTTrigPhase2Prod.cc | 264 +++++++----------- .../DTPhase2Trigger/src/MuonPathAssociator.cc | 6 +- 2 files changed, 105 insertions(+), 165 deletions(-) diff --git a/L1Trigger/DTPhase2Trigger/src/DTTrigPhase2Prod.cc b/L1Trigger/DTPhase2Trigger/src/DTTrigPhase2Prod.cc index dfa4b02c8ef68..0a60f0507c1f7 100644 --- a/L1Trigger/DTPhase2Trigger/src/DTTrigPhase2Prod.cc +++ b/L1Trigger/DTPhase2Trigger/src/DTTrigPhase2Prod.cc @@ -237,181 +237,117 @@ void DTTrigPhase2Prod::produce(Event & iEvent, const EventSetup& iEventSetup){ metaPrimitives.clear(); metaPrimitives.erase(metaPrimitives.begin(),metaPrimitives.end()); - + if(debug) std::cout<<"DTp2 in event:"< outPhi; - vector outP2; - vector outP2Ph; - - for (auto metaPrimitiveIt = filteredMetaPrimitives.begin(); metaPrimitiveIt != filteredMetaPrimitives.end(); ++metaPrimitiveIt){ - DTSuperLayerId slId((*metaPrimitiveIt).rawId); - if(debug) std::cout<<"looping in final vector: SuperLayerId"< resultPhi (new L1MuDTChambPhContainer); - resultPhi->setContainer(outPhi); iEvent.put(std::move(resultPhi)); - outPhi.clear(); - outPhi.erase(outPhi.begin(),outPhi.end()); - }else if(p2_df==1){ - std::unique_ptr resultP2 (new L1MuDTChambContainer); - resultP2->setContainer(outP2); iEvent.put(std::move(resultP2)); - outP2.clear(); - outP2.erase(outP2.begin(),outP2.end()); - }else if(p2_df==2){ - std::unique_ptr resultP2Ph (new L1Phase2MuDTPhContainer); - resultP2Ph->setContainer(outP2Ph); iEvent.put(std::move(resultP2Ph)); - outP2Ph.clear(); - outP2Ph.erase(outP2Ph.begin(),outP2Ph.end()); + + //// CORRELATION: + std::vector correlatedMetaPrimitives; + mpathassociator->run(iEvent, iEventSetup, dtdigis, filteredMetaPrimitives, correlatedMetaPrimitives); + + filteredMetaPrimitives.clear(); + filteredMetaPrimitives.erase(filteredMetaPrimitives.begin(),filteredMetaPrimitives.end()); + + if(debug) std::cout<<"DTp2 in event:"< correlatedMetaPrimitives; - mpathassociator->run(iEvent, iEventSetup, dtdigis, filteredMetaPrimitives, correlatedMetaPrimitives); - - filteredMetaPrimitives.clear(); - filteredMetaPrimitives.erase(filteredMetaPrimitives.begin(),filteredMetaPrimitives.end()); - - if(debug) std::cout<<"DTp2 in event:"< outPhi; + vector outP2; + vector outP2Ph; + + for (auto metaPrimitiveIt = correlatedMetaPrimitives.begin(); metaPrimitiveIt != correlatedMetaPrimitives.end(); ++metaPrimitiveIt){ + DTChamberId chId((*metaPrimitiveIt).rawId); + if(debug) std::cout<<"looping in final vector: SuperLayerId"< resultPhiCH (new L1MuDTChambPhContainer); - resultPhiCH->setContainer(outPhiCH); iEvent.put(std::move(resultPhiCH)); - outPhiCH.clear(); - outPhiCH.erase(outPhiCH.begin(),outPhiCH.end()); - }else if(p2_df==1){ - std::unique_ptr resultP2CH (new L1MuDTChambContainer); - resultP2CH->setContainer(outP2CH); iEvent.put(std::move(resultP2CH)); - outP2CH.clear(); - outP2CH.erase(outP2CH.begin(),outP2CH.end()); - }else if(p2_df==2){ - std::unique_ptr resultP2PhCH (new L1Phase2MuDTPhContainer); - resultP2PhCH->setContainer(outP2PhCH); iEvent.put(std::move(resultP2PhCH)); - outP2PhCH.clear(); - outP2PhCH.erase(outP2PhCH.begin(),outP2PhCH.end()); + else if(p2_df==1){ + if(debug)std::cout<<"pushing back phase-2 dataformat agreement with Oscar for comparison with slice test"< resultPhi (new L1MuDTChambPhContainer); + resultPhi->setContainer(outPhi); iEvent.put(std::move(resultPhi)); + outPhi.clear(); + outPhi.erase(outPhi.begin(),outPhi.end()); + } + else if(p2_df==1){ + std::unique_ptr resultP2 (new L1MuDTChambContainer); + resultP2->setContainer(outP2); iEvent.put(std::move(resultP2)); + outP2.clear(); + outP2.erase(outP2.begin(),outP2.end()); + } + else if(p2_df==2){ + std::unique_ptr resultP2Ph (new L1Phase2MuDTPhContainer); + resultP2Ph->setContainer(outP2Ph); iEvent.put(std::move(resultP2Ph)); + outP2Ph.clear(); + outP2Ph.erase(outP2Ph.begin(),outP2Ph.end()); + } } + void DTTrigPhase2Prod::endRun(edm::Run const& iRun, const edm::EventSetup& iEventSetup) { grouping_obj->finish(); mpathanalyzer->finish(); diff --git a/L1Trigger/DTPhase2Trigger/src/MuonPathAssociator.cc b/L1Trigger/DTPhase2Trigger/src/MuonPathAssociator.cc index ea78675a6641c..2788be220965c 100644 --- a/L1Trigger/DTPhase2Trigger/src/MuonPathAssociator.cc +++ b/L1Trigger/DTPhase2Trigger/src/MuonPathAssociator.cc @@ -53,7 +53,11 @@ void MuonPathAssociator::run(edm::Event& iEvent, const edm::EventSetup& iEventSe std::vector &outMPaths) { - correlateMPaths(digis, inMPaths,outMPaths); + if (dT0_correlate_TP) correlateMPaths(digis, inMPaths,outMPaths); + else { + for (auto metaPrimitiveIt = inMPaths.begin(); metaPrimitiveIt != inMPaths.end(); ++metaPrimitiveIt) + outMPaths.push_back(*metaPrimitiveIt); + } } void MuonPathAssociator::finish() {