CMS 3D CMS Logo

BPHRecoBuilder.cc
Go to the documentation of this file.
1 /*
2  * See header file for a description of this class.
3  *
4  * \author Paolo Ronchese INFN Padova
5  *
6  */
7 
8 //-----------------------
9 // This Class' Header --
10 //-----------------------
12 
13 //-------------------------------
14 // Collaborating Class Headers --
15 //-------------------------------
24 
25 //---------------
26 // C++ Headers --
27 //---------------
28 #include <iostream>
29 #include <map>
30 
31 using namespace std;
32 
33 //-------------------
34 // Initializations --
35 //-------------------
36 
37 
38 //----------------
39 // Constructors --
40 //----------------
42  evSetup( &es ),
43  minPDiff( -1.0 ) {
44  msList.reserve( 5 );
45  vsList.reserve( 5 );
46 }
47 
48 //--------------
49 // Destructor --
50 //--------------
52  int n = sourceList.size();
53  while ( n-- ) {
54  delete sourceList[n]->collection;
55  delete sourceList[n];
56  }
57  int m = srCompList.size();
58  while ( m-- )
59  delete srCompList[m];
60  while ( !compCollectList.empty() ) {
61  const vector<BPHRecoConstCandPtr>* cCollection = *compCollectList.begin();
62  delete cCollection;
63  compCollectList.erase( cCollection );
64  }
65 }
66 
67 //--------------
68 // Operations --
69 //--------------
71  const vector<const reco::Candidate*>&
72  candList,
73  const string& list ) {
75  candList, list );
76 }
77 
78 
79 template<>
80 const reco::Candidate&
82  const reco::Candidate*> >::get( int i )
83  const {
84  return *(*cPtr)[i];
85 }
86 
87 
88 void BPHRecoBuilder::filter( const string& name,
89  const BPHRecoSelect& sel ) const {
90  map<string,int>::const_iterator iter = sourceId.find( name );
91  if ( iter == sourceId.end() ) return;
92  BPHRecoSource* rs = sourceList[iter->second];
93  rs->selector.push_back( &sel );
94  return;
95 }
96 
97 
98 void BPHRecoBuilder::filter( const string& name,
99  const BPHMomentumSelect& sel ) const {
100  map<string,int>::const_iterator iter = srCompId.find( name );
101  if ( iter == sourceId.end() ) return;
102  BPHCompSource* cs = srCompList[iter->second];
103  cs->momSelector.push_back( &sel );
104  return;
105 }
106 
107 
108 void BPHRecoBuilder::filter( const string& name,
109  const BPHVertexSelect& sel ) const {
110  map<string,int>::const_iterator iter = srCompId.find( name );
111  if ( iter == sourceId.end() ) return;
112  BPHCompSource* cs = srCompList[iter->second];
113  cs->vtxSelector.push_back( &sel );
114  return;
115 }
116 
117 
118 void BPHRecoBuilder::filter( const string& name,
119  const BPHFitSelect& sel ) const {
120  map<string,int>::const_iterator iter = srCompId.find( name );
121  if ( iter == sourceId.end() ) return;
122  BPHCompSource* cs = srCompList[iter->second];
123  cs->fitSelector.push_back( &sel );
124  return;
125 }
126 
127 
129  msList.push_back( &sel );
130  return;
131 }
132 
133 
135  vsList.push_back( &sel );
136  return;
137 }
138 
139 
141  fsList.push_back( &sel );
142  return;
143 }
144 
145 
147  int i;
148  int n;
149  n = msList.size();
150  for ( i = 0; i < n; ++i ) {
151  if ( !msList[i]->accept( cand ) ) return false;
152  }
153  n = vsList.size();
154  for ( i = 0; i < n; ++i ) {
155  if ( !vsList[i]->accept( cand ) ) return false;
156  }
157  n = fsList.size();
158  for ( i = 0; i < n; ++i ) {
159  if ( !fsList[i]->accept( cand ) ) return false;
160  }
161  return true;
162 }
163 
164 
166  minPDiff = pMin;
167  return;
168 }
169 
170 
171 vector<BPHRecoBuilder::ComponentSet> BPHRecoBuilder::build() const {
172  daugMap.clear();
173  compMap.clear();
174  vector<ComponentSet> candList;
175  ComponentSet compSet;
176  build( candList, compSet,
177  sourceList.begin(), sourceList.end(),
178  srCompList.begin(), srCompList.end() );
179  return candList;
180 }
181 
182 
184  return evSetup;
185 }
186 
187 
189  const reco::Candidate* rCand,
190  double minPDifference ) {
191  const reco::Track* lrcTrack = BPHTrackReference::getFromRC( *lCand );
192  const reco::Track* rrcTrack = BPHTrackReference::getFromRC( *rCand );
193  const reco::Track* lpfTrack = BPHTrackReference::getFromPF( *lCand );
194  const reco::Track* rpfTrack = BPHTrackReference::getFromPF( *rCand );
195  if ( ( lrcTrack != nullptr ) &&
196  ( ( lrcTrack == rrcTrack ) ||
197  ( lrcTrack == rpfTrack ) ) ) return true;
198  if ( ( lpfTrack != nullptr ) &&
199  ( ( lpfTrack == rrcTrack ) ||
200  ( lpfTrack == rpfTrack ) ) ) return true;
201  reco::Candidate::Vector pDiff = ( lCand->momentum() -
202  rCand->momentum() );
203  reco::Candidate::Vector pMean = ( lCand->momentum() +
204  rCand->momentum() );
205  double pDMod = pDiff.mag2();
206  double pMMod = pMean.mag2();
207  if ( ( ( pDMod / pMMod ) < minPDifference ) &&
208  ( lCand->charge() == rCand->charge() ) ) return true;
209  return false;
210 }
211 
212 
213 void BPHRecoBuilder::add( const string& name,
215  double mass,
216  double msig ) {
217  BPHRecoSource* rs;
218  if ( sourceId.find( name ) != sourceId.end() ) {
219  edm::LogPrint( "TooManyParticles" )
220  << "BPHRecoBuilder::add: "
221  << "Decay product already inserted with name " << name
222  << " , skipped";
223  return;
224  }
225  rs = new BPHRecoSource;
226  rs->name =
227  &sourceId.insert( make_pair( name, sourceList.size() ) ).first->first;
228  rs->collection = collection;
229  rs->selector.reserve( 5 );
230  rs->mass = mass;
231  rs->msig = msig;
232  sourceList.push_back( rs );
233  return;
234 }
235 
236 
237 void BPHRecoBuilder::add( const string& name,
238  const vector<BPHRecoConstCandPtr>& collection ) {
239  BPHCompSource* cs;
240  if ( srCompId.find( name ) != srCompId.end() ) {
241  edm::LogPrint( "TooManyParticles" )
242  << "BPHRecoBuilder::add: "
243  << "Decay product already inserted with name " << name
244  << " , skipped";
245  return;
246  }
247  cs = new BPHCompSource;
248  cs->name =
249  &srCompId.insert( make_pair( name, srCompList.size() ) ).first->first;
250  cs->collection = &collection;
251  srCompList.push_back( cs );
252  return;
253 }
254 
255 
256 void BPHRecoBuilder::build( vector<ComponentSet>& compList,
257  ComponentSet& compSet,
258  vector<BPHRecoSource*>::const_iterator r_iter,
259  vector<BPHRecoSource*>::const_iterator r_iend,
260  vector<BPHCompSource*>::const_iterator c_iter,
261  vector<BPHCompSource*>::const_iterator c_iend ) const {
262  if ( r_iter == r_iend ) {
263  if ( c_iter == c_iend ) {
264  compSet.compMap = compMap;
265  compList.push_back( compSet );
266  return;
267  }
268  BPHCompSource* source = *c_iter++;
269  const
270  vector<BPHRecoConstCandPtr>* collection = source->collection;
271  vector<const BPHMomentumSelect*> momSelector = source->momSelector;
272  vector<const BPHVertexSelect*> vtxSelector = source->vtxSelector;
273  vector<const BPHFitSelect*> fitSelector = source->fitSelector;
274  int i;
275  int j;
276  int n = collection->size();
277  int m;
278  bool skip;
279  for ( i = 0; i < n; ++i ) {
280  skip = false;
281  BPHRecoConstCandPtr cand = collection->at( i );
282  if ( contained( compSet, cand ) ) continue;
283  m = momSelector.size();
284  for ( j = 0; j < m; ++j ) {
285  if ( !momSelector[j]->accept( *cand ) ) skip = true;
286  }
287  m = vtxSelector.size();
288  for ( j = 0; j < m; ++j ) {
289  if ( !vtxSelector[j]->accept( *cand ) ) skip = true;
290  }
291  m = fitSelector.size();
292  for ( j = 0; j < m; ++j ) {
293  if ( !fitSelector[j]->accept( *cand ) ) skip = true;
294  }
295  if ( skip ) continue;
296  compMap[*source->name] = cand;
297  build( compList, compSet,
298  r_iter, r_iend,
299  c_iter, c_iend );
300  compMap.erase( *source->name );
301  }
302  return;
303  }
304  BPHRecoSource* source = *r_iter++;
305  const BPHGenericCollection* collection = source->collection;
306  vector<const BPHRecoSelect*>& selector = source->selector;
307  int i;
308  int j;
309  int n = collection->size();
310  int m = selector.size();
311  bool skip;
312  for ( i = 0; i < n; ++i ) {
313  const reco::Candidate& cand = collection->get( i );
314  if ( contained( compSet, &cand ) ) continue;
315  skip = false;
316  for ( j = 0; j < m; ++j ) {
317  if ( !selector[j]->accept( cand, this ) ) skip = true;
318  }
319  if ( skip ) continue;
321  comp.cand = &cand;
322  comp.mass = source->mass;
323  comp.msig = source->msig;
324  comp.searchList = collection->searchList();
325  compSet.daugMap[*source->name] = comp;
326  daugMap[*source->name] = &cand;
327  build( compList, compSet,
328  r_iter, r_iend,
329  c_iter, c_iend );
330  daugMap.erase( *source->name );
331  compSet.daugMap.erase( *source->name );
332  }
333  return;
334 }
335 
336 
338  const reco::Candidate* cand ) const {
339  map<string,BPHDecayMomentum::Component>& dMap = compSet.daugMap;
340  map<string,BPHDecayMomentum::Component>::const_iterator d_iter;
341  map<string,BPHDecayMomentum::Component>::const_iterator d_iend = dMap.end();
342  for ( d_iter = dMap.begin(); d_iter != d_iend; ++d_iter ) {
343  const reco::Candidate* cChk = d_iter->second.cand;
344  if ( cand == cChk ) return true;
345  if ( sameTrack( cand, cChk ) ) return true;
346  }
347  return false;
348 
349 }
350 
351 
353  BPHRecoConstCandPtr cCand ) const {
354 
355  map<string,BPHRecoConstCandPtr>::const_iterator c_iter;
356  map<string,BPHRecoConstCandPtr>::const_iterator c_iend = compMap.end();
357  const vector<const reco::Candidate*>& dCand = cCand->daughFull();
358  int j;
359  int m = dCand.size();
360  int k;
361  int l;
362  for ( j = 0; j < m; ++j ) {
363 
364  const reco::Candidate* cand = cCand->originalReco( dCand[j] );
365  map<string,BPHDecayMomentum::Component>& dMap = compSet.daugMap;
366  map<string,BPHDecayMomentum::Component>::const_iterator d_iter;
367  map<string,BPHDecayMomentum::Component>::const_iterator d_iend = dMap.end();
368  for ( d_iter = dMap.begin(); d_iter != d_iend; ++d_iter ) {
369  const reco::Candidate* cChk = d_iter->second.cand;
370  if ( cand == cChk ) return true;
371  if ( sameTrack( cand, cChk ) ) return true;
372  }
373 
374  for ( c_iter = compMap.begin(); c_iter != c_iend; ++c_iter ) {
375  const pair<string,BPHRecoConstCandPtr>& entry = *c_iter;
376  BPHRecoConstCandPtr cCChk = entry.second;
377  const vector<const reco::Candidate*>& dCChk = cCChk->daughFull();
378  l = dCChk.size();
379  for ( k = 0; k < l; ++k ) {
380  const reco::Candidate* cChk = cCChk->originalReco( dCChk[k] );
381  if ( cand == cChk ) return true;
382  if ( sameTrack( cand, cChk ) ) return true;
383  }
384  }
385 
386  }
387 
388  return false;
389 
390 }
391 
392 
394  const reco::Candidate* rCand ) const {
395  return sameTrack( lCand, rCand, minPDiff );
396 }
397 
std::vector< const BPHRecoSelect * > selector
const reco::Candidate * cand
static bool sameTrack(const reco::Candidate *lCand, const reco::Candidate *rCand, double minPDifference)
void setMinPDiffererence(double pMin)
static const reco::Track * getFromPF(const reco::Candidate &rc)
auto_ptr< ClusterSequence > cs
std::vector< const BPHVertexSelect * > vsList
math::XYZVector Vector
point in the space
Definition: Candidate.h:43
BPHGenericPtr< const BPHRecoCandidate >::type BPHRecoConstCandPtr
std::map< std::string, BPHRecoConstCandPtr > compMap
virtual ~BPHRecoBuilder()
std::vector< ComponentSet > build() const
build a set of combinations of particles fulfilling the selections
const std::vector< BPHRecoConstCandPtr > * collection
std::map< std::string, int > sourceId
const edm::EventSetup * evSetup
bool accept(const BPHRecoCandidate &cand) const
std::vector< BPHCompSource * > srCompList
std::vector< const BPHFitSelect * > fsList
const BPHGenericCollection * collection
const edm::EventSetup * eventSetup() const
get the EventSetup set in the constructor
static BPHGenericCollection * createCollection(const edm::Handle< T > &collection, const std::string &list="cfhpmig")
static const reco::Track * getFromRC(const reco::Candidate &rc)
std::vector< const BPHFitSelect * > fitSelector
std::vector< const BPHVertexSelect * > vtxSelector
std::map< std::string, const reco::Candidate * > daugMap
std::vector< BPHRecoSource * > sourceList
int k[5][pyjets_maxn]
void add(const std::string &name, const BPHGenericCollection *collection, double mass=-1.0, double msig=-1.0)
std::map< std::string, BPHDecayMomentum::Component > daugMap
const std::string & searchList() const
std::vector< const BPHMomentumSelect * > momSelector
virtual Vector momentum() const =0
spatial momentum vector
std::map< std::string, int > srCompId
virtual const reco::Candidate & get(int i) const =0
virtual int charge() const =0
electric charge
void filter(const std::string &name, const BPHRecoSelect &sel) const
std::vector< const BPHMomentumSelect * > msList
bool contained(ComponentSet &compSet, const reco::Candidate *cand) const
std::set< const std::vector< BPHRecoConstCandPtr > * > compCollectList
BPHRecoBuilder(const edm::EventSetup &es)
std::map< std::string, BPHRecoConstCandPtr > compMap
static std::string const source
Definition: EdmProvDump.cc:43
T get(const Candidate &c)
Definition: component.h:55
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger list("!*","!HLTx*"if it matches 2 triggers or more) will accept the event if all the matching triggers are FAIL.It will reject the event if any of the triggers are PASS or EXCEPTION(this matches the behavior of"!*"before the partial wildcard feature was incorporated).Triggers which are in the READY state are completely ignored.(READY should never be returned since the trigger paths have been run