CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Private Member Functions | Private Attributes
CandOneToOneDeltaRMatcher Class Reference
Inheritance diagram for CandOneToOneDeltaRMatcher:
edm::EDProducer edm::ProducerBase edm::ProductRegistryHelper

Public Member Functions

 CandOneToOneDeltaRMatcher (const edm::ParameterSet &)
 
 ~CandOneToOneDeltaRMatcher ()
 
- Public Member Functions inherited from edm::EDProducer
 EDProducer ()
 
virtual ~EDProducer ()
 
- Public Member Functions inherited from edm::ProducerBase
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
boost::function< void(const
BranchDescription &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 

Private Member Functions

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

Private Attributes

std::string algoMethod_
 
std::vector< std::vector< float > > AllDist
 
edm::InputTag matched_
 
edm::InputTag source_
 

Additional Inherited Members

- Public Types inherited from edm::EDProducer
typedef EDProducer ModuleType
 
typedef WorkerT< EDProducerWorkerType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Static Public Member Functions inherited from edm::EDProducer
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 
- Protected Member Functions inherited from edm::EDProducer
CurrentProcessingContext const * currentContext () const
 
- Protected Member Functions inherited from edm::ProducerBase
template<class TProducer , class TMethod >
void callWhenNewProductsRegistered (TProducer *iProd, TMethod iMethod)
 

Detailed Description

Definition at line 17 of file CandOneToOneDeltaRMatcher.cc.

Constructor & Destructor Documentation

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

Definition at line 59 of file CandOneToOneDeltaRMatcher.cc.

59  :
60  source_( cfg.getParameter<InputTag>( "src" ) ),
61  matched_( cfg.getParameter<InputTag>( "matched" ) ),
62  algoMethod_( cfg.getParameter<string>( "algoMethod" ) ) {
63  produces<CandViewMatchMap>("src2mtc");
64  produces<CandViewMatchMap>("mtc2src");
65 }
T getParameter(std::string const &) const
CandOneToOneDeltaRMatcher::~CandOneToOneDeltaRMatcher ( )

Definition at line 67 of file CandOneToOneDeltaRMatcher.cc.

67  {
68 }

Member Function Documentation

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

Definition at line 219 of file CandOneToOneDeltaRMatcher.cc.

References lenght(), and stdcomb::next_combination().

Referenced by produce().

219  {
220 
221  vector<int> ca;
222  vector<int> cb;
223  vector<int> bestCB;
224  float totalDeltaR=0;
225  float BestTotalDeltaR=1000;
226 
227  for(int i1=0; i1<nMax; i1++) ca.push_back(i1);
228  for(int i1=0; i1<nMin; i1++) cb.push_back(i1);
229 
230  do
231  {
232  //do your processing on the new combination here
233  for(int cnt=0;cnt<TMath::Factorial(nMin); cnt++)
234  {
235  totalDeltaR = lenght(cb);
236  if ( totalDeltaR < BestTotalDeltaR ) {
237  BestTotalDeltaR = totalDeltaR;
238  bestCB=cb;
239  }
240  next_permutation( cb.begin() , cb.end() );
241  }
242  }
243  while(next_combination( ca.begin() , ca.end() , cb.begin() , cb.end() ));
244 
245  return bestCB;
246 }
double lenght(std::vector< int >)
bool next_combination(BidIt n_begin, BidIt n_end, BidIt r_begin, BidIt r_end)
Definition: combination.h:22
vector< int > CandOneToOneDeltaRMatcher::AlgoSwitchMethod ( int  nMin,
int  nMax 
)
private

Definition at line 259 of file CandOneToOneDeltaRMatcher.cc.

References AllDist.

Referenced by produce().

259  {
260 
261  vector<int> bestCB;
262  for(int i1=0; i1<nMin; i1++) {
263  int minInd=0;
264  for(int i2=1; i2<nMax; i2++) if( AllDist[i1][i2] < AllDist[i1][minInd] ) minInd = i2;
265  bestCB.push_back(minInd);
266  }
267 
268  bool inside = true;
269  while( inside ) {
270  inside = false;
271  for(int i1=0;i1<nMin;i1++){
272  for(int i2=i1+1;i2<nMin;i2++){
273  if ( bestCB[i1] == bestCB[i2] ) {
274  inside = true;
275  if ( AllDist[i1][(bestCB[i1])] <= AllDist[i2][(bestCB[i2])]) {
276  AllDist[i2][(bestCB[i2])]= 1000;
277  int minInd=0;
278  for(int i3=1; i3<nMax; i3++) if( AllDist[i2][i3] < AllDist[i2][minInd] ) minInd = i3;
279  bestCB[i2]= minInd;
280  } else {
281  AllDist[i1][(bestCB[i1])]= 1000;
282  int minInd=0;
283  for(int i3=1; i3<nMax; i3++) if( AllDist[i1][i3] < AllDist[i1][minInd] ) minInd = i3;
284  bestCB[i1]= minInd;
285  }
286  } // End if
287  }
288  }
289  } // End while
290 
291  return bestCB;
292 
293 }
std::vector< std::vector< float > > AllDist
double CandOneToOneDeltaRMatcher::lenght ( std::vector< int >  best)
private

Definition at line 200 of file CandOneToOneDeltaRMatcher.cc.

References AllDist.

Referenced by AlgoBruteForce().

200  {
201  double myLenght=0;
202  int row=0;
203  for(vector<int>::iterator it=best.begin(); it!=best.end(); it++ ) {
204  myLenght+=AllDist[row][*it];
205  row++;
206  }
207  return myLenght;
208 }
std::vector< std::vector< float > > AllDist
void CandOneToOneDeltaRMatcher::produce ( edm::Event evt,
const edm::EventSetup es 
)
privatevirtual

Implements edm::EDProducer.

Definition at line 70 of file CandOneToOneDeltaRMatcher.cc.

References AlgoBruteForce(), algoMethod_, AlgoSwitchMethod(), AllDist, trackerHits::c, edm::hlt::Exception, edm::Event::getByLabel(), matched_, max(), min, edm::Event::put(), LaserTracksInput_cfi::source, and source_.

70  {
71 
73  Handle<CandidateView> matched;
74  evt.getByLabel( source_, source ) ;
75  evt.getByLabel( matched_, matched ) ;
76 
77  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "======== Source Collection =======";
78  for( CandidateView::const_iterator c = source->begin(); c != source->end(); ++c ) {
79  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << " pt source " << c->pt() << " " << c->eta() << " " << c->phi() << endl;
80  }
81  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "======== Matched Collection =======";
82  for( CandidateView::const_iterator c = matched->begin(); c != matched->end(); ++c ) {
83  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << " 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 ) return;
92 
93  if( nSrc <= nMtc ) {
94  for(CandidateView::const_iterator iSr = source->begin();
95  iSr != source->end();
96  iSr++) {
97  vector <float> tempAllDist;
98  for(CandidateView::const_iterator iMt = matched->begin();
99  iMt != matched->end();
100  iMt++) {
101  tempAllDist.push_back(DeltaR( iSr->p4() , iMt->p4() ) );
102  }
103  AllDist.push_back(tempAllDist);
104  tempAllDist.clear();
105  }
106  } else {
107  for(CandidateView::const_iterator iMt = matched->begin();
108  iMt != matched->end();
109  iMt++) {
110  vector <float> tempAllDist;
111  for(CandidateView::const_iterator iSr = source->begin();
112  iSr != source->end();
113  iSr++) {
114  tempAllDist.push_back(DeltaR( iSr->p4() , iMt->p4() ) );
115  }
116  AllDist.push_back(tempAllDist);
117  tempAllDist.clear();
118  }
119  }
120 
121  /*
122  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "======== The DeltaR Matrix =======";
123  for(int m0=0; m0<nMin; m0++) {
124  // for(int m1=0; m1<nMax; m1++) {
125  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << setprecision(2) << fixed << (m1 AllDist[m0][m1] ;
126  //}
127  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "\n";
128  }
129  */
130 
131  // Loop size if Brute Force
132  int nLoopToDo = (int) ( TMath::Factorial(nMax) / TMath::Factorial(nMax - nMin) );
133  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "nLoop:" << nLoopToDo << endl;
134  edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "Choosen Algo is:" << algoMethod_ ;
135  vector<int> bestCB;
136 
137  // Algo is Brute Force
138  if( algoMethod_ == "BruteForce") {
139 
140  bestCB = AlgoBruteForce(nMin,nMax);
141 
142  // Algo is Switch Method
143  } else if( algoMethod_ == "SwitchMode" ) {
144 
145  bestCB = AlgoSwitchMethod(nMin,nMax);
146 
147  // Algo is Brute Force if nLoop < 10000
148  } else if( algoMethod_ == "MixMode" ) {
149 
150  if( nLoopToDo < 10000 ) {
151  bestCB = AlgoBruteForce(nMin,nMax);
152  } else {
153  bestCB = AlgoSwitchMethod(nMin,nMax);
154  }
155 
156  } else {
157  throw cms::Exception("OneToOne Constructor") << "wrong matching method in ParameterSet";
158  }
159 
160  for(int i1=0; i1<nMin; i1++) edm::LogVerbatim("CandOneToOneDeltaRMatcher") << "min: " << i1 << " " << bestCB[i1] << " " << AllDist[i1][bestCB[i1]];
161 
162 /*
163  auto_ptr<CandViewMatchMap> matchMapSrMt( new CandViewMatchMap( CandViewMatchMap::ref_type( CandidateRefProd( source ),
164  CandidateRefProd( matched ) ) ) );
165  auto_ptr<CandViewMatchMap> matchMapMtSr( new CandViewMatchMap( CandViewMatchMap::ref_type( CandidateRefProd( matched ),
166  CandidateRefProd( source ) ) ) );
167 */
168 
169  auto_ptr<CandViewMatchMap> matchMapSrMt( new CandViewMatchMap() );
170  auto_ptr<CandViewMatchMap> matchMapMtSr( new CandViewMatchMap() );
171 
172  for( int c = 0; c != nMin; c ++ ) {
173  if( source->size() <= matched->size() ) {
174  matchMapSrMt->insert( source ->refAt(c ), matched->refAt(bestCB[c] ) );
175  matchMapMtSr->insert( matched->refAt(bestCB[c] ), source ->refAt(c ) );
176  } else {
177  matchMapSrMt->insert( source ->refAt(bestCB[c] ), matched->refAt(c ) );
178  matchMapMtSr->insert( matched->refAt(c ), source ->refAt(bestCB[c] ) );
179  }
180  }
181 
182 /*
183  for( int c = 0; c != nMin; c ++ ) {
184  if( source->size() <= matched->size() ) {
185  matchMapSrMt->insert( CandidateRef( source, c ), CandidateRef( matched, bestCB[c] ) );
186  matchMapMtSr->insert( CandidateRef( matched, bestCB[c] ), CandidateRef( source, c ) );
187  } else {
188  matchMapSrMt->insert( CandidateRef( source, bestCB[c] ), CandidateRef( matched, c ) );
189  matchMapMtSr->insert( CandidateRef( matched, c ), CandidateRef( source, bestCB[c] ) );
190  }
191  }
192 */
193  evt.put( matchMapSrMt, "src2mtc" );
194  evt.put( matchMapMtSr, "mtc2src" );
195 
196  AllDist.clear();
197 }
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
std::vector< std::vector< float > > AllDist
Definition: deltaR.h:51
std::vector< int > AlgoSwitchMethod(int, int)
#define min(a, b)
Definition: mlp_lapack.h:161
std::vector< int > AlgoBruteForce(int, int)
const T & max(const T &a, const T &b)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:85
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
edm::AssociationMap< edm::OneToOneGeneric< reco::CandidateView, reco::CandidateView > > CandViewMatchMap
Definition: CandMatchMap.h:25

Member Data Documentation

std::string CandOneToOneDeltaRMatcher::algoMethod_
private

Definition at line 30 of file CandOneToOneDeltaRMatcher.cc.

Referenced by produce().

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

Definition at line 29 of file CandOneToOneDeltaRMatcher.cc.

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

edm::InputTag CandOneToOneDeltaRMatcher::matched_
private

Definition at line 28 of file CandOneToOneDeltaRMatcher.cc.

Referenced by produce().

edm::InputTag CandOneToOneDeltaRMatcher::source_
private