CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions | Private Attributes
CandOneToOneDeltaRMatcher Class Reference
Inheritance diagram for CandOneToOneDeltaRMatcher:
edm::EDProducer edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 CandOneToOneDeltaRMatcher (const edm::ParameterSet &)
 
 ~CandOneToOneDeltaRMatcher () override
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
SerialTaskQueueglobalLuminosityBlocksQueue ()
 
SerialTaskQueueglobalRunsQueue ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducer () override
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
std::vector< edm::ProductResolverIndex > const & indiciesForPutProducts (BranchType iBranchType) const
 
 ProducerBase ()
 
std::vector< edm::ProductResolverIndex > const & putTokenIndexToProductResolverIndex () const
 
std::vector< bool > const & recordProvenanceList () const
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription const &)> registrationCallback () const
 used by the fwk to register list of products More...
 
void resolvePutIndicies (BranchType iBranchType, ModuleToResolverIndicies const &iIndicies, std::string const &moduleLabel)
 
TypeLabelList const & typeLabelList () const
 used by the fwk to register the list of products of this module More...
 
 ~ProducerBase () noexcept(false) override
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
void convertCurrentProcessAlias (std::string const &processName)
 Convert "@currentProcess" in InputTag process names to the actual current process name. More...
 
 EDConsumerBase ()
 
 EDConsumerBase (EDConsumerBase &&)=default
 
 EDConsumerBase (EDConsumerBase const &)=delete
 
ESProxyIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESProxyIndex > const & esGetTokenIndicesVector (edm::Transition iTrans) const
 
std::vector< ESRecordIndex > const & esGetTokenRecordIndicesVector (edm::Transition iTrans) const
 
ProductResolverIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductResolverIndexAndSkipBit > &) const
 
std::vector< ProductResolverIndexAndSkipBit > const & itemsToGetFrom (BranchType iType) const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesWhoseProductsAreConsumed (std::array< std::vector< ModuleDescription const * > *, NumBranchTypes > &modulesAll, std::vector< ModuleProcessName > &modulesInPreviousProcesses, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProxyIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

std::vector< int > AlgoBruteForce (int, int)
 
std::vector< int > AlgoSwitchMethod (int, int)
 
double lenght (const std::vector< int > &)
 
void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

std::string algoMethod_
 
std::vector< std::vector< float > > AllDist
 
edm::EDGetTokenT< reco::CandidateViewmatchedToken_
 
edm::EDGetTokenT< reco::CandidateViewsourceToken_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
- Public Types inherited from edm::ProducerBase
using ModuleToResolverIndicies = std::unordered_multimap< std::string, std::tuple< edm::TypeID const *, const char *, edm::ProductResolverIndex > >
 
typedef ProductRegistryHelper::TypeLabelList TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
static bool wantsGlobalLuminosityBlocks ()
 
static bool wantsGlobalRuns ()
 
static bool wantsInputProcessBlocks ()
 
static bool wantsProcessBlocks ()
 
static bool wantsStreamLuminosityBlocks ()
 
static bool wantsStreamRuns ()
 
- Protected Member Functions inherited from edm::ProducerBase
template<class ProductType >
BranchAliasSetterT< ProductType > produces ()
 declare what type of product will make and with which optional label More...
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<BranchType B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<Transition B>
BranchAliasSetter produces (const TypeID &id, std::string instanceName=std::string(), bool recordProvenance=true)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< B > consumes (edm::InputTag tag) noexcept
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes () noexcept
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag) noexcept
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 

Detailed Description

Definition at line 18 of file CandOneToOneDeltaRMatcher.cc.

Constructor & Destructor Documentation

◆ CandOneToOneDeltaRMatcher()

CandOneToOneDeltaRMatcher::CandOneToOneDeltaRMatcher ( const edm::ParameterSet cfg)

Definition at line 59 of file CandOneToOneDeltaRMatcher.cc.

60  : sourceToken_(consumes<CandidateView>(cfg.getParameter<InputTag>("src"))),
61  matchedToken_(consumes<CandidateView>(cfg.getParameter<InputTag>("matched"))),
62  algoMethod_(cfg.getParameter<string>("algoMethod")) {
63  produces<CandViewMatchMap>("src2mtc");
64  produces<CandViewMatchMap>("mtc2src");
65 }

◆ ~CandOneToOneDeltaRMatcher()

CandOneToOneDeltaRMatcher::~CandOneToOneDeltaRMatcher ( )
override

Definition at line 67 of file CandOneToOneDeltaRMatcher.cc.

67 {}

Member Function Documentation

◆ AlgoBruteForce()

vector< int > CandOneToOneDeltaRMatcher::AlgoBruteForce ( int  nMin,
int  nMax 
)
private

Definition at line 210 of file CandOneToOneDeltaRMatcher.cc.

210  {
211  vector<int> ca;
212  vector<int> cb;
213  vector<int> bestCB;
214  float totalDeltaR = 0;
215  float BestTotalDeltaR = 1000;
216 
217  ca.reserve(nMax);
218  for (int i1 = 0; i1 < nMax; i1++)
219  ca.push_back(i1);
220  cb.reserve(nMin);
221  for (int i1 = 0; i1 < nMin; i1++)
222  cb.push_back(i1);
223 
224  do {
225  //do your processing on the new combination here
226  for (int cnt = 0; cnt < TMath::Factorial(nMin); cnt++) {
227  totalDeltaR = lenght(cb);
228  if (totalDeltaR < BestTotalDeltaR) {
229  BestTotalDeltaR = totalDeltaR;
230  bestCB = cb;
231  }
232  next_permutation(cb.begin(), cb.end());
233  }
234  } while (next_combination(ca.begin(), ca.end(), cb.begin(), cb.end()));
235 
236  return bestCB;
237 }

References testProducerWithPsetDescEmpty_cfi::i1, lenght(), stdcomb::next_combination(), metDiagnosticParameterSet_cfi::nMax, and metDiagnosticParameterSet_cfi::nMin.

Referenced by produce().

◆ AlgoSwitchMethod()

vector< int > CandOneToOneDeltaRMatcher::AlgoSwitchMethod ( int  nMin,
int  nMax 
)
private

Definition at line 250 of file CandOneToOneDeltaRMatcher.cc.

250  {
251  vector<int> bestCB;
252  for (int i1 = 0; i1 < nMin; i1++) {
253  int minInd = 0;
254  for (int i2 = 1; i2 < nMax; i2++)
255  if (AllDist[i1][i2] < AllDist[i1][minInd])
256  minInd = i2;
257  bestCB.push_back(minInd);
258  }
259 
260  bool inside = true;
261  while (inside) {
262  inside = false;
263  for (int i1 = 0; i1 < nMin; i1++) {
264  for (int i2 = i1 + 1; i2 < nMin; i2++) {
265  if (bestCB[i1] == bestCB[i2]) {
266  inside = true;
267  if (AllDist[i1][(bestCB[i1])] <= AllDist[i2][(bestCB[i2])]) {
268  AllDist[i2][(bestCB[i2])] = 1000;
269  int minInd = 0;
270  for (int i3 = 1; i3 < nMax; i3++)
271  if (AllDist[i2][i3] < AllDist[i2][minInd])
272  minInd = i3;
273  bestCB[i2] = minInd;
274  } else {
275  AllDist[i1][(bestCB[i1])] = 1000;
276  int minInd = 0;
277  for (int i3 = 1; i3 < nMax; i3++)
278  if (AllDist[i1][i3] < AllDist[i1][minInd])
279  minInd = i3;
280  bestCB[i1] = minInd;
281  }
282  } // End if
283  }
284  }
285  } // End while
286 
287  return bestCB;
288 }

References AllDist, testProducerWithPsetDescEmpty_cfi::i1, testProducerWithPsetDescEmpty_cfi::i2, testProducerWithPsetDescEmpty_cfi::i3, metDiagnosticParameterSet_cfi::nMax, and metDiagnosticParameterSet_cfi::nMin.

Referenced by produce().

◆ lenght()

double CandOneToOneDeltaRMatcher::lenght ( const std::vector< int > &  best)
private

Definition at line 191 of file CandOneToOneDeltaRMatcher.cc.

191  {
192  double myLenght = 0;
193  int row = 0;
194  for (vector<int>::const_iterator it = best.begin(); it != best.end(); it++) {
195  myLenght += AllDist[row][*it];
196  row++;
197  }
198  return myLenght;
199 }

References AllDist.

Referenced by AlgoBruteForce().

◆ produce()

void CandOneToOneDeltaRMatcher::produce ( edm::Event evt,
const edm::EventSetup es 
)
overrideprivatevirtual

Implements edm::EDProducer.

Definition at line 69 of file CandOneToOneDeltaRMatcher.cc.

69  {
74 
75  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "======== Source Collection =======";
76  for (CandidateView::const_iterator c = source->begin(); c != source->end(); ++c) {
77  edm::LogVerbatim("CandOneToOneDeltaRMatcher")
78  << " pt source " << c->pt() << " " << c->eta() << " " << c->phi() << endl;
79  }
80  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "======== Matched Collection =======";
81  for (CandidateView::const_iterator c = matched->begin(); c != matched->end(); ++c) {
82  edm::LogVerbatim("CandOneToOneDeltaRMatcher")
83  << " pt source " << c->pt() << " " << c->eta() << " " << c->phi() << endl;
84  }
85 
86  const int nSrc = source->size();
87  const int nMtc = matched->size();
88 
89  const int nMin = min(source->size(), matched->size());
90  const int nMax = max(source->size(), matched->size());
91  if (nMin < 1)
92  return;
93 
94  if (nSrc <= nMtc) {
95  for (CandidateView::const_iterator iSr = source->begin(); iSr != source->end(); iSr++) {
96  vector<float> tempAllDist;
97  for (CandidateView::const_iterator iMt = matched->begin(); iMt != matched->end(); iMt++) {
98  tempAllDist.push_back(DeltaR(iSr->p4(), iMt->p4()));
99  }
100  AllDist.push_back(tempAllDist);
101  tempAllDist.clear();
102  }
103  } else {
104  for (CandidateView::const_iterator iMt = matched->begin(); iMt != matched->end(); iMt++) {
105  vector<float> tempAllDist;
106  for (CandidateView::const_iterator iSr = source->begin(); iSr != source->end(); iSr++) {
107  tempAllDist.push_back(DeltaR(iSr->p4(), iMt->p4()));
108  }
109  AllDist.push_back(tempAllDist);
110  tempAllDist.clear();
111  }
112  }
113 
114  /*
115  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "======== The DeltaR Matrix =======";
116  for(int m0=0; m0<nMin; m0++) {
117  // for(int m1=0; m1<nMax; m1++) {
118  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << setprecision(2) << fixed << (m1 AllDist[m0][m1] ;
119  //}
120  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "\n";
121  }
122  */
123 
124  // Loop size if Brute Force
125  int nLoopToDo = (int)(TMath::Factorial(nMax) / TMath::Factorial(nMax - nMin));
126  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "nLoop:" << nLoopToDo << endl;
127  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "Choosen Algo is:" << algoMethod_;
128  vector<int> bestCB;
129 
130  // Algo is Brute Force
131  if (algoMethod_ == "BruteForce") {
132  bestCB = AlgoBruteForce(nMin, nMax);
133 
134  // Algo is Switch Method
135  } else if (algoMethod_ == "SwitchMode") {
136  bestCB = AlgoSwitchMethod(nMin, nMax);
137 
138  // Algo is Brute Force if nLoop < 10000
139  } else if (algoMethod_ == "MixMode") {
140  if (nLoopToDo < 10000) {
141  bestCB = AlgoBruteForce(nMin, nMax);
142  } else {
143  bestCB = AlgoSwitchMethod(nMin, nMax);
144  }
145 
146  } else {
147  throw cms::Exception("OneToOne Constructor") << "wrong matching method in ParameterSet";
148  }
149 
150  for (int i1 = 0; i1 < nMin; i1++)
151  edm::LogVerbatim("CandOneToOneDeltaRMatcher")
152  << "min: " << i1 << " " << bestCB[i1] << " " << AllDist[i1][bestCB[i1]];
153 
154  /*
155  auto matchMapSrMt = std::make_unique<CandViewMatchMap>(CandViewMatchMap::ref_type( CandidateRefProd( source ),
156  CandidateRefProd( matched ) ) );
157  auto matchMapMtSr = std::make_unique<CandViewMatchMap>(CandViewMatchMap::ref_type( CandidateRefProd( matched ),
158  CandidateRefProd( source ) ) );
159 */
160 
161  auto matchMapSrMt = std::make_unique<CandViewMatchMap>();
162  auto matchMapMtSr = std::make_unique<CandViewMatchMap>();
163 
164  for (int c = 0; c != nMin; c++) {
165  if (source->size() <= matched->size()) {
166  matchMapSrMt->insert(source->refAt(c), matched->refAt(bestCB[c]));
167  matchMapMtSr->insert(matched->refAt(bestCB[c]), source->refAt(c));
168  } else {
169  matchMapSrMt->insert(source->refAt(bestCB[c]), matched->refAt(c));
170  matchMapMtSr->insert(matched->refAt(c), source->refAt(bestCB[c]));
171  }
172  }
173 
174  /*
175  for( int c = 0; c != nMin; c ++ ) {
176  if( source->size() <= matched->size() ) {
177  matchMapSrMt->insert( CandidateRef( source, c ), CandidateRef( matched, bestCB[c] ) );
178  matchMapMtSr->insert( CandidateRef( matched, bestCB[c] ), CandidateRef( source, c ) );
179  } else {
180  matchMapSrMt->insert( CandidateRef( source, bestCB[c] ), CandidateRef( matched, c ) );
181  matchMapMtSr->insert( CandidateRef( matched, c ), CandidateRef( source, bestCB[c] ) );
182  }
183  }
184 */
185  evt.put(std::move(matchMapSrMt), "src2mtc");
186  evt.put(std::move(matchMapMtSr), "mtc2src");
187 
188  AllDist.clear();
189 }

References AlgoBruteForce(), algoMethod_, AlgoSwitchMethod(), AllDist, c, electronAnalyzer_cfi::DeltaR, Exception, edm::Event::getByToken(), testProducerWithPsetDescEmpty_cfi::i1, createfilelist::int, muonTagProbeFilters_cff::matched, matchedToken_, SiStripPI::max, min(), eostools::move(), metDiagnosticParameterSet_cfi::nMax, metDiagnosticParameterSet_cfi::nMin, edm::Event::put(), source, and sourceToken_.

Member Data Documentation

◆ algoMethod_

std::string CandOneToOneDeltaRMatcher::algoMethod_
private

Definition at line 32 of file CandOneToOneDeltaRMatcher.cc.

Referenced by produce().

◆ AllDist

std::vector<std::vector<float> > CandOneToOneDeltaRMatcher::AllDist
private

Definition at line 31 of file CandOneToOneDeltaRMatcher.cc.

Referenced by AlgoSwitchMethod(), lenght(), and produce().

◆ matchedToken_

edm::EDGetTokenT<reco::CandidateView> CandOneToOneDeltaRMatcher::matchedToken_
private

Definition at line 30 of file CandOneToOneDeltaRMatcher.cc.

Referenced by produce().

◆ sourceToken_

edm::EDGetTokenT<reco::CandidateView> CandOneToOneDeltaRMatcher::sourceToken_
private

Definition at line 29 of file CandOneToOneDeltaRMatcher.cc.

Referenced by produce().

muonTagProbeFilters_cff.matched
matched
Definition: muonTagProbeFilters_cff.py:62
CandOneToOneDeltaRMatcher::sourceToken_
edm::EDGetTokenT< reco::CandidateView > sourceToken_
Definition: CandOneToOneDeltaRMatcher.cc:29
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
testProducerWithPsetDescEmpty_cfi.i3
i3
Definition: testProducerWithPsetDescEmpty_cfi.py:47
metDiagnosticParameterSet_cfi.nMin
nMin
Definition: metDiagnosticParameterSet_cfi.py:10
CandOneToOneDeltaRMatcher::AlgoSwitchMethod
std::vector< int > AlgoSwitchMethod(int, int)
Definition: CandOneToOneDeltaRMatcher.cc:250
min
T min(T a, T b)
Definition: MathUtil.h:58
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
CandOneToOneDeltaRMatcher::AllDist
std::vector< std::vector< float > > AllDist
Definition: CandOneToOneDeltaRMatcher.cc:31
edm::Handle
Definition: AssociativeIterator.h:50
CandOneToOneDeltaRMatcher::matchedToken_
edm::EDGetTokenT< reco::CandidateView > matchedToken_
Definition: CandOneToOneDeltaRMatcher.cc:30
source
static const std::string source
Definition: EdmProvDump.cc:47
edm::Event::getByToken
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:535
SiStripPI::max
Definition: SiStripPayloadInspectorHelper.h:169
createfilelist.int
int
Definition: createfilelist.py:10
CandOneToOneDeltaRMatcher::algoMethod_
std::string algoMethod_
Definition: CandOneToOneDeltaRMatcher.cc:32
edm::Event::put
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
electronAnalyzer_cfi.DeltaR
DeltaR
Definition: electronAnalyzer_cfi.py:33
looper.cfg
cfg
Definition: looper.py:297
eostools.move
def move(src, dest)
Definition: eostools.py:511
stdcomb::next_combination
bool next_combination(BidIt n_begin, BidIt n_end, BidIt r_begin, BidIt r_end)
Definition: combination.h:19
CandOneToOneDeltaRMatcher::lenght
double lenght(const std::vector< int > &)
Definition: CandOneToOneDeltaRMatcher.cc:191
CandOneToOneDeltaRMatcher::AlgoBruteForce
std::vector< int > AlgoBruteForce(int, int)
Definition: CandOneToOneDeltaRMatcher.cc:210
edm::LogVerbatim
Log< level::Info, true > LogVerbatim
Definition: MessageLogger.h:128
Exception
Definition: hltDiff.cc:245
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
edm::Log
Definition: MessageLogger.h:70
edm::InputTag
Definition: InputTag.h:15
metDiagnosticParameterSet_cfi.nMax
nMax
Definition: metDiagnosticParameterSet_cfi.py:11