CMS 3D CMS Logo

List of all members | Public Types | Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes
CandOneToOneDeltaRMatcher Class Reference
Inheritance diagram for CandOneToOneDeltaRMatcher:
edm::global::EDProducer<> edm::global::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Types

enum  Algo { Algo::kBruteForce, Algo::kSwitchMode, Algo::kMixMode }
 
using AllDist = std::vector< std::vector< float > >
 
- Public Types inherited from edm::global::EDProducerBase
typedef EDProducerBase ModuleType
 
- Public Types inherited from edm::ProducerBase
template<typename T >
using BranchAliasSetterT = ProductRegistryHelper::BranchAliasSetterT< T >
 
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
 

Public Member Functions

 CandOneToOneDeltaRMatcher (const edm::ParameterSet &)
 
- Public Member Functions inherited from edm::global::EDProducer<>
 EDProducer ()=default
 
 EDProducer (const EDProducer &)=delete
 
bool hasAbilityToProduceInBeginLumis () const final
 
bool hasAbilityToProduceInBeginProcessBlocks () const final
 
bool hasAbilityToProduceInBeginRuns () const final
 
bool hasAbilityToProduceInEndLumis () const final
 
bool hasAbilityToProduceInEndProcessBlocks () const final
 
bool hasAbilityToProduceInEndRuns () const final
 
EDProduceroperator= (const EDProducer &)=delete
 
bool wantsGlobalLuminosityBlocks () const noexcept final
 
bool wantsGlobalRuns () const noexcept final
 
bool wantsInputProcessBlocks () const noexcept final
 
bool wantsProcessBlocks () const noexcept final
 
bool wantsStreamLuminosityBlocks () const noexcept final
 
bool wantsStreamRuns () const noexcept final
 
- Public Member Functions inherited from edm::global::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
 ~EDProducerBase () 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 const &)=delete
 
 EDConsumerBase (EDConsumerBase &&)=default
 
ESResolverIndex const * esGetTokenIndices (edm::Transition iTrans) const
 
std::vector< ESResolverIndex > 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
 
EDConsumerBase const & operator= (EDConsumerBase const &)=delete
 
EDConsumerBaseoperator= (EDConsumerBase &&)=default
 
bool registeredToConsume (ProductResolverIndex, bool, BranchType) const
 
void selectInputProcessBlocks (ProductRegistry const &productRegistry, ProcessBlockHelperBase const &processBlockHelperBase)
 
ProductResolverIndexAndSkipBit uncheckedIndexFrom (EDGetToken) const
 
void updateLookup (BranchType iBranchType, ProductResolverIndexHelper const &, bool iPrefetchMayGet)
 
void updateLookup (eventsetup::ESRecordsToProductResolverIndices const &)
 
virtual ~EDConsumerBase () noexcept(false)
 

Private Member Functions

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

Static Private Member Functions

static Algo algo (std::string const &)
 
static const char * algoName (Algo)
 

Private Attributes

const Algo algoMethod_
 
const edm::EDGetTokenT< reco::CandidateViewmatchedToken_
 
const edm::EDGetTokenT< reco::CandidateViewsourceToken_
 

Additional Inherited Members

- Static Public Member Functions inherited from edm::global::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::ProducerBase
template<Transition Tr = Transition::Event>
auto produces (std::string instanceName) noexcept
 declare what type of product will make and with which optional label More...
 
template<Transition B>
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)
 
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 ()
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , BranchType B>
BranchAliasSetterT< ProductType > produces ()
 
template<class ProductType >
BranchAliasSetterT< ProductType > produces (std::string instanceName)
 
template<typename ProductType , Transition B>
BranchAliasSetterT< ProductType > produces ()
 
template<Transition Tr = Transition::Event>
auto produces () noexcept
 
ProducesCollector producesCollector ()
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
template<BranchType B = InEvent>
EDConsumerBaseAdaptor< Bconsumes (edm::InputTag tag) noexcept
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
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 ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes ()
 
template<typename ESProduct , typename ESRecord , Transition Tr = Transition::Event>
auto esConsumes (ESInputTag const &tag)
 
template<Transition Tr = Transition::Event>
constexpr auto esConsumes ()
 
template<Transition Tr = Transition::Event>
auto esConsumes (ESInputTag tag)
 
template<Transition Tr = Transition::Event>
ESGetTokenGeneric esConsumes (eventsetup::EventSetupRecordKey const &iRecord, eventsetup::DataKey const &iKey)
 Used with EventSetupRecord::doGet. More...
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
void resetItemsToGetFrom (BranchType iType)
 

Detailed Description

Definition at line 18 of file CandOneToOneDeltaRMatcher.cc.

Member Typedef Documentation

◆ AllDist

using CandOneToOneDeltaRMatcher::AllDist = std::vector<std::vector<float> >

Definition at line 22 of file CandOneToOneDeltaRMatcher.cc.

Member Enumeration Documentation

◆ Algo

Enumerator
kBruteForce 
kSwitchMode 
kMixMode 

Definition at line 24 of file CandOneToOneDeltaRMatcher.cc.

24 { kBruteForce, kSwitchMode, kMixMode };

Constructor & Destructor Documentation

◆ CandOneToOneDeltaRMatcher()

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

Definition at line 88 of file CandOneToOneDeltaRMatcher.cc.

89  : sourceToken_(consumes<CandidateView>(cfg.getParameter<InputTag>("src"))),
90  matchedToken_(consumes<CandidateView>(cfg.getParameter<InputTag>("matched"))),
91  algoMethod_(algo(cfg.getParameter<string>("algoMethod"))) {
92  produces<CandViewMatchMap>("src2mtc");
93  produces<CandViewMatchMap>("mtc2src");
94 }
static Algo algo(std::string const &)
const edm::EDGetTokenT< reco::CandidateView > sourceToken_
const edm::EDGetTokenT< reco::CandidateView > matchedToken_

Member Function Documentation

◆ algo()

CandOneToOneDeltaRMatcher::Algo CandOneToOneDeltaRMatcher::algo ( std::string const &  algoName)
staticprivate

Definition at line 63 of file CandOneToOneDeltaRMatcher.cc.

References MillePedeAlignmentAlgorithm_cfi::algoName, and Exception.

63  {
64  if (algoName == "BruteForce") {
65  return Algo::kBruteForce;
66  } else if (algoName == "SwitchMode") {
67  return Algo::kSwitchMode;
68  } else if (algoName == "MixMode") {
69  return Algo::kMixMode;
70  } else {
71  throw cms::Exception("OneToOne Constructor") << "wrong matching method in ParameterSet";
72  }
73 }
static const char * algoName(Algo)

◆ AlgoBruteForce()

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

Definition at line 236 of file CandOneToOneDeltaRMatcher.cc.

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

Referenced by produce().

236  {
237  vector<int> ca;
238  vector<int> cb;
239  vector<int> bestCB;
240  float totalDeltaR = 0;
241  float BestTotalDeltaR = 1000;
242 
243  ca.reserve(nMax);
244  for (int i1 = 0; i1 < nMax; i1++)
245  ca.push_back(i1);
246  cb.reserve(nMin);
247  for (int i1 = 0; i1 < nMin; i1++)
248  cb.push_back(i1);
249 
250  do {
251  //do your processing on the new combination here
252  for (int cnt = 0; cnt < TMath::Factorial(nMin); cnt++) {
253  totalDeltaR = length(cb, allDist);
254  if (totalDeltaR < BestTotalDeltaR) {
255  BestTotalDeltaR = totalDeltaR;
256  bestCB = cb;
257  }
258  next_permutation(cb.begin(), cb.end());
259  }
260  } while (next_combination(ca.begin(), ca.end(), cb.begin(), cb.end()));
261 
262  return bestCB;
263 }
double length(const std::vector< int > &, const AllDist &) const
bool next_combination(BidIt n_begin, BidIt n_end, BidIt r_begin, BidIt r_end)
Definition: combination.h:19

◆ algoName()

const char * CandOneToOneDeltaRMatcher::algoName ( Algo  iAlgo)
staticprivate

Definition at line 75 of file CandOneToOneDeltaRMatcher.cc.

Referenced by produce().

75  {
76  switch (iAlgo) {
77  case Algo::kBruteForce:
78  return "BruteForce";
79  case Algo::kSwitchMode:
80  return "SwitchMode";
81  case Algo::kMixMode:
82  return "MixMode";
83  }
84  //can not get here
85  return "";
86 }

◆ AlgoSwitchMethod()

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

Definition at line 276 of file CandOneToOneDeltaRMatcher.cc.

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

Referenced by produce().

276  {
277  vector<int> bestCB;
278  for (int i1 = 0; i1 < nMin; i1++) {
279  int minInd = 0;
280  for (int i2 = 1; i2 < nMax; i2++)
281  if (allDist[i1][i2] < allDist[i1][minInd])
282  minInd = i2;
283  bestCB.push_back(minInd);
284  }
285 
286  bool inside = true;
287  while (inside) {
288  inside = false;
289  for (int i1 = 0; i1 < nMin; i1++) {
290  for (int i2 = i1 + 1; i2 < nMin; i2++) {
291  if (bestCB[i1] == bestCB[i2]) {
292  inside = true;
293  if (allDist[i1][(bestCB[i1])] <= allDist[i2][(bestCB[i2])]) {
294  allDist[i2][(bestCB[i2])] = 1000;
295  int minInd = 0;
296  for (int i3 = 1; i3 < nMax; i3++)
297  if (allDist[i2][i3] < allDist[i2][minInd])
298  minInd = i3;
299  bestCB[i2] = minInd;
300  } else {
301  allDist[i1][(bestCB[i1])] = 1000;
302  int minInd = 0;
303  for (int i3 = 1; i3 < nMax; i3++)
304  if (allDist[i1][i3] < allDist[i1][minInd])
305  minInd = i3;
306  bestCB[i1] = minInd;
307  }
308  } // End if
309  }
310  }
311  } // End while
312 
313  return bestCB;
314 }

◆ length()

double CandOneToOneDeltaRMatcher::length ( const std::vector< int > &  best,
const AllDist allDist 
) const
private

Definition at line 217 of file CandOneToOneDeltaRMatcher.cc.

References ALPAKA_ACCELERATOR_NAMESPACE::vertexFinder::it.

Referenced by AlgoBruteForce().

217  {
218  double myLength = 0;
219  int row = 0;
220  for (vector<int>::const_iterator it = best.begin(); it != best.end(); it++) {
221  myLength += allDist[row][*it];
222  row++;
223  }
224  return myLength;
225 }

◆ produce()

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

Implements edm::global::EDProducerBase.

Definition at line 96 of file CandOneToOneDeltaRMatcher.cc.

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

96  {
101 
102  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "======== Source Collection =======";
103  for (CandidateView::const_iterator c = source->begin(); c != source->end(); ++c) {
104  edm::LogVerbatim("CandOneToOneDeltaRMatcher")
105  << " pt source " << c->pt() << " " << c->eta() << " " << c->phi() << endl;
106  }
107  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "======== Matched Collection =======";
108  for (CandidateView::const_iterator c = matched->begin(); c != matched->end(); ++c) {
109  edm::LogVerbatim("CandOneToOneDeltaRMatcher")
110  << " pt source " << c->pt() << " " << c->eta() << " " << c->phi() << endl;
111  }
112 
113  const int nSrc = source->size();
114  const int nMtc = matched->size();
115 
116  const int nMin = min(source->size(), matched->size());
117  const int nMax = max(source->size(), matched->size());
118  if (nMin < 1)
119  return;
120 
121  std::vector<std::vector<float>> allDist;
122 
123  if (nSrc <= nMtc) {
124  allDist.reserve(source->size());
125  for (CandidateView::const_iterator iSr = source->begin(); iSr != source->end(); iSr++) {
126  vector<float> tempAllDist;
127  tempAllDist.reserve(matched->size());
128  for (CandidateView::const_iterator iMt = matched->begin(); iMt != matched->end(); iMt++) {
129  tempAllDist.push_back(DeltaR(iSr->p4(), iMt->p4()));
130  }
131  allDist.emplace_back(std::move(tempAllDist));
132  }
133  } else {
134  allDist.reserve(matched->size());
135  for (CandidateView::const_iterator iMt = matched->begin(); iMt != matched->end(); iMt++) {
136  vector<float> tempAllDist;
137  tempAllDist.reserve(source->size());
138  for (CandidateView::const_iterator iSr = source->begin(); iSr != source->end(); iSr++) {
139  tempAllDist.push_back(DeltaR(iSr->p4(), iMt->p4()));
140  }
141  allDist.emplace_back(std::move(tempAllDist));
142  }
143  }
144 
145  /*
146  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "======== The DeltaR Matrix =======";
147  for(int m0=0; m0<nMin; m0++) {
148  // for(int m1=0; m1<nMax; m1++) {
149  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << setprecision(2) << fixed << (m1 AllDist[m0][m1] ;
150  //}
151  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "\n";
152  }
153  */
154 
155  // Loop size if Brute Force
156  int nLoopToDo = (int)(TMath::Factorial(nMax) / TMath::Factorial(nMax - nMin));
157  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "nLoop:" << nLoopToDo << endl;
158  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "Choosen Algo is:" << algoName(algoMethod_);
159  vector<int> bestCB;
160 
161  // Algo is Brute Force
163  bestCB = AlgoBruteForce(nMin, nMax, allDist);
164 
165  // Algo is Switch Method
166  } else if (algoMethod_ == Algo::kSwitchMode) {
167  bestCB = AlgoSwitchMethod(nMin, nMax, allDist);
168 
169  // Algo is Brute Force if nLoop < 10000
170  } else if (algoMethod_ == Algo::kMixMode) {
171  if (nLoopToDo < 10000) {
172  bestCB = AlgoBruteForce(nMin, nMax, allDist);
173  } else {
174  bestCB = AlgoSwitchMethod(nMin, nMax, allDist);
175  }
176  }
177 
178  for (int i1 = 0; i1 < nMin; i1++)
179  edm::LogVerbatim("CandOneToOneDeltaRMatcher")
180  << "min: " << i1 << " " << bestCB[i1] << " " << allDist[i1][bestCB[i1]];
181 
182  /*
183  auto matchMapSrMt = std::make_unique<CandViewMatchMap>(CandViewMatchMap::ref_type( CandidateRefProd( source ),
184  CandidateRefProd( matched ) ) );
185  auto matchMapMtSr = std::make_unique<CandViewMatchMap>(CandViewMatchMap::ref_type( CandidateRefProd( matched ),
186  CandidateRefProd( source ) ) );
187 */
188 
189  auto matchMapSrMt = std::make_unique<CandViewMatchMap>();
190  auto matchMapMtSr = std::make_unique<CandViewMatchMap>();
191 
192  for (int c = 0; c != nMin; c++) {
193  if (source->size() <= matched->size()) {
194  matchMapSrMt->insert(source->refAt(c), matched->refAt(bestCB[c]));
195  matchMapMtSr->insert(matched->refAt(bestCB[c]), source->refAt(c));
196  } else {
197  matchMapSrMt->insert(source->refAt(bestCB[c]), matched->refAt(c));
198  matchMapMtSr->insert(matched->refAt(c), source->refAt(bestCB[c]));
199  }
200  }
201 
202  /*
203  for( int c = 0; c != nMin; c ++ ) {
204  if( source->size() <= matched->size() ) {
205  matchMapSrMt->insert( CandidateRef( source, c ), CandidateRef( matched, bestCB[c] ) );
206  matchMapMtSr->insert( CandidateRef( matched, bestCB[c] ), CandidateRef( source, c ) );
207  } else {
208  matchMapSrMt->insert( CandidateRef( source, bestCB[c] ), CandidateRef( matched, c ) );
209  matchMapMtSr->insert( CandidateRef( matched, c ), CandidateRef( source, bestCB[c] ) );
210  }
211  }
212 */
213  evt.put(std::move(matchMapSrMt), "src2mtc");
214  evt.put(std::move(matchMapMtSr), "mtc2src");
215 }
Log< level::Info, true > LogVerbatim
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:133
std::vector< int > AlgoBruteForce(int, int, const AllDist &) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:526
std::vector< int > AlgoSwitchMethod(int, int, AllDist &) const
const edm::EDGetTokenT< reco::CandidateView > sourceToken_
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:88
const edm::EDGetTokenT< reco::CandidateView > matchedToken_
static const char * algoName(Algo)
static std::string const source
Definition: EdmProvDump.cc:49
def move(src, dest)
Definition: eostools.py:511

Member Data Documentation

◆ algoMethod_

const Algo CandOneToOneDeltaRMatcher::algoMethod_
private

Definition at line 36 of file CandOneToOneDeltaRMatcher.cc.

Referenced by produce().

◆ matchedToken_

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

Definition at line 35 of file CandOneToOneDeltaRMatcher.cc.

Referenced by produce().

◆ sourceToken_

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

Definition at line 34 of file CandOneToOneDeltaRMatcher.cc.

Referenced by produce().