CMS 3D CMS Logo

List of all members | Public Member Functions | Private Types | Private Member Functions | Private Attributes
tnp::TagProbePairMaker Class Reference

#include <TagProbePairMaker.h>

Public Member Functions

TagProbePairs run (const edm::Event &iEvent) const
 fill in tghe T&P pairs for this event More...
 
 TagProbePairMaker (const edm::ParameterSet &iConfig, edm::ConsumesCollector &&iC)
 
 ~TagProbePairMaker ()
 

Private Types

enum  Arbitration {
  None, OneProbe, BestMass, Random2,
  NonDuplicate, OnePair, HighestPt
}
 

Private Member Functions

void arbitrate (TagProbePairs &pairs) const
 
void phiCutByEventNumber (TagProbePairs &pairs, int eventNumber) const
 

Private Attributes

Arbitration arbitration_
 
double arbitrationMass_
 
bool phiCutForTwoLeg_
 
TRandom2 * randGen_
 
edm::EDGetTokenT< reco::CandidateViewsrcToken_
 

Detailed Description

Definition at line 26 of file TagProbePairMaker.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

tnp::TagProbePairMaker::TagProbePairMaker ( const edm::ParameterSet iConfig,
edm::ConsumesCollector &&  iC 
)

Definition at line 4 of file TagProbePairMaker.cc.

References arbitration_, arbitrationMass_, BestMass, Exception, edm::ParameterSet::existsAs(), edm::ParameterSet::getParameter(), HighestPt, NonDuplicate, None, OnePair, OneProbe, phiCutForTwoLeg_, randGen_, Random2, and AlCaHLTBitMon_QueryRunRegistry::string.

4  :
5  srcToken_(iC.consumes<reco::CandidateView>(iConfig.getParameter<edm::InputTag>("tagProbePairs"))),
6  randGen_(nullptr)
7 {
8  std::string arbitration = iConfig.getParameter<std::string>("arbitration");
9  if (arbitration == "None") {
11  } else if (arbitration == "OneProbe") {
13  } else if (arbitration == "OnePair") {
15  } else if (arbitration == "NonDuplicate") {
17  } else if (arbitration == "BestMass") {
19  arbitrationMass_ = iConfig.getParameter<double>("massForArbitration");
20  } else if (arbitration == "Random2") {
22  randGen_ = new TRandom2(7777);
23  } else if (arbitration == "HighestPt") {
25  } else throw cms::Exception("Configuration") << "TagProbePairMakerOnTheFly: the only currently "
26  << "allowed values for 'arbitration' are "
27  << "'None', 'OneProbe', 'BestMass', 'Random2'\n";
28 
29  if (iConfig.existsAs<bool>("phiCutForTwoLeg")) {
30  phiCutForTwoLeg_ = iConfig.getParameter<bool>("phiCutForTwoLeg");
31  //std::cout << "Set phiCutForTwoLeg_ to " << phiCutForTwoLeg_ << std::endl;
32  } else {
33  phiCutForTwoLeg_ = false;
34  //std::cout << "Set phiCutForTwoLeg_ to default " << phiCutForTwoLeg_ << std::endl;
35  }
36 }
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
T getParameter(std::string const &) const
bool existsAs(std::string const &parameterName, bool trackiness=true) const
checks if a parameter exists as a given type
Definition: ParameterSet.h:161
edm::EDGetTokenT< reco::CandidateView > srcToken_
tnp::TagProbePairMaker::~TagProbePairMaker ( )
inline

Definition at line 31 of file TagProbePairMaker.h.

References iEvent, and writedatasetfile::run.

31 {delete randGen_;}

Member Function Documentation

void tnp::TagProbePairMaker::arbitrate ( TagProbePairs pairs) const
private

Definition at line 115 of file TagProbePairMaker.cc.

References funct::abs(), arbitration_, arbitrationMass_, BestMass, MillePedeFileConverter_cfg::e, HighestPt, NonDuplicate, OnePair, OneProbe, randGen_, Random2, and std::swap().

Referenced by run().

116 {
117  size_t nclean = pairs.size();
118  for (TagProbePairs::iterator it = pairs.begin(), ed = pairs.end(); it != ed; ++it) {
119  if (it->tag.isNull()) continue; // skip already invalidated pairs
120 
121  bool TTpair=false;
122  for (TagProbePairs::iterator it2 = pairs.begin(); it2 != ed; ++it2) { // first check for Tag-Tag pairs
123  if (it2->tag.isNull()) continue; // skip already invalidated pairs
124  if(it!=it2 && it->probe==it2->tag && it->tag==it2->probe){
125  //std::cout << "----------> probe is tag!!!!" << std::endl;
126  TTpair=true;
127  }
128  }
129  //if(!TTpair) std::cout << "this is not TT!" << std::endl;
130  bool invalidateThis = false;
131  int numberOfProbes=0;
132  for (TagProbePairs::iterator it2 = it + 1; it2 != ed; ++it2) { // it+1 <= ed, otherwise we don't arrive here
133  // arbitrate the case where multiple probes are matched to the same tag
134  if ((arbitration_ != NonDuplicate) && (it->tag == it2->tag)) {
135  if(TTpair){ // we already have found a TT pair, no need to guess
136  it2->tag = reco::CandidateBaseRef(); --nclean;
137  //std::cout << "remove unnecessary pair! -----------" << std::endl;
138  continue;
139  }
140 
141  if (arbitration_ == OneProbe) {
142  // invalidate this one
143  it2->tag = reco::CandidateBaseRef(); --nclean;
144  // remember to invalidate also the other one (but after finishing to check for duplicates)
145  invalidateThis = true;
146  } else if (arbitration_ == BestMass) {
147  // but the best one in the first iterator
148  if (fabs(it2->mass-arbitrationMass_) < fabs(it->mass-arbitrationMass_)) {
149  std::swap(*it, *it2);
150  }
151  // and invalidate it2
152  it2->tag = reco::CandidateBaseRef(); --nclean;
153  } else if (arbitration_ == HighestPt) {
154  // but the best one in the first iterator
155  if ( it2->probe->pt() > it->probe->pt() ) {
156  std::swap(*it, *it2);
157  }
158  // and invalidate it2
159  it2->tag = reco::CandidateBaseRef(); --nclean;
160  } else if (arbitration_ == Random2) {
161  numberOfProbes++;
162  if (numberOfProbes>1) {
163  //std::cout << "more than 2 probes!" << std::endl;
164  invalidateThis=true;
165  it2->tag = reco::CandidateBaseRef();
166  --nclean;
167  } else{
168  // do a coin toss to decide if we want to swap them
169  if (randGen_->Rndm()>0.5) {
170  std::swap(*it, *it2);
171  }
172  // and invalidate it2
173  it2->tag = reco::CandidateBaseRef();
174  --nclean;
175  }
176  }
177  }
178  // arbitrate the case where the same probe is associated to more then one tag
179  if ((arbitration_ == NonDuplicate) && (it->probe == it2->probe)) {
180  // invalidate the pair in which the tag has lower pT
181  if (it2->tag->pt() > it->tag->pt()) std::swap(*it, *it2);
182  it2->tag = reco::CandidateBaseRef(); --nclean;
183  }
184  // arbitrate the OnePair case: disallow the same pair to enter the lineshape twice
185  // this can't be done by reference, unfortunately, so we resort to a simple matching
186  if ((arbitration_ == OnePair) &&
187  std::abs(it->mass - it2->mass) < 1e-4 &&
188  std::abs( it->probe->phi() - it2->tag->phi()) < 1e-5 &&
189  std::abs( it->probe->eta() - it2->tag->eta()) < 1e-5 &&
190  std::abs( it->probe->pt() - it2->tag->pt() ) < 1e-5 &&
191  std::abs(it2->probe->phi() - it->tag->phi()) < 1e-5 &&
192  std::abs(it2->probe->eta() - it->tag->eta()) < 1e-5 &&
193  std::abs(it2->probe->pt() - it->tag->pt() ) < 1e-5) {
194  it2->tag = reco::CandidateBaseRef(); --nclean;
195  }
196  }
197  if (invalidateThis) { it->tag = reco::CandidateBaseRef(); --nclean; }
198  }
199 
200  if (nclean == 0) {
201  pairs.clear();
202  } else if (nclean < pairs.size()) {
203  TagProbePairs cleaned; cleaned.reserve(nclean);
204  for (TagProbePairs::iterator it = pairs.begin(), ed = pairs.end(); it != ed; ++it) {
205  if (it->tag.isNonnull()) cleaned.push_back(*it);
206  }
207  pairs.swap(cleaned);
208  }
209 }
std::vector< TagProbePair > TagProbePairs
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
edm::RefToBase< Candidate > CandidateBaseRef
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:31
void tnp::TagProbePairMaker::phiCutByEventNumber ( TagProbePairs pairs,
int  eventNumber 
) const
private

Definition at line 73 of file TagProbePairMaker.cc.

References gather_cfg::cout.

Referenced by run().

74 {
75  unsigned int currentNum = 0;
76 
77  size_t nclean = pairs.size();
78  for (TagProbePairs::iterator it = pairs.begin(), ed = pairs.end(); it != ed; ++it) {
79  if (it->tag.isNull()) continue; // skip already invalidated pairs
80  if (eventNumber%2) {
81  std::cout << "Odd event number " << eventNumber << ", require 0 < phi(tag) < pi... ";
82  if (!(it->tag->phi() > 0. && it->tag->phi() < 3.141592654)) {
83  std::cout << "Rejecting pair number " << currentNum++ << " with tag phi " << it->tag->phi();
84  nclean--;
85  it->tag = reco::CandidateBaseRef(); --nclean;
86  } else {
87  std::cout << "Keeping pair number " << currentNum++ << " with tag phi " << it->tag->phi();
88  }
89  } else {
90  std::cout << "Even event number " << eventNumber << ", require -pi < phi(tag) < 0... ";
91  // if (!(it->tag->phi() > 3.141592654 && it->tag->phi() < 2*3.141592654)) {
92  if (!(it->tag->phi() > -3.141592654 && it->tag->phi() < 0)) {
93  std::cout << "Rejecting pair number " << currentNum++ << " with tag phi " << it->tag->phi();
94  nclean--;
95  it->tag = reco::CandidateBaseRef(); --nclean;
96  } else {
97  std::cout << "Keeping pair number " << currentNum++ << " with tag phi " << it->tag->phi();
98  }
99  }
100  std::cout << std::endl;
101  }
102 
103  if (nclean == 0) {
104  pairs.clear();
105  } else if (nclean < pairs.size()) {
106  TagProbePairs cleaned; cleaned.reserve(nclean);
107  for (TagProbePairs::iterator it = pairs.begin(), ed = pairs.end(); it != ed; ++it) {
108  if (it->tag.isNonnull()) cleaned.push_back(*it);
109  }
110  pairs.swap(cleaned);
111  }
112 }
std::vector< TagProbePair > TagProbePairs
edm::RefToBase< Candidate > CandidateBaseRef
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:31
tnp::TagProbePairs tnp::TagProbePairMaker::run ( const edm::Event iEvent) const

fill in tghe T&P pairs for this event

Definition at line 40 of file TagProbePairMaker.cc.

References arbitrate(), arbitration_, edm::View< T >::begin(), gather_cfg::cout, reco::Candidate::daughter(), edm::View< T >::end(), edm::EventID::event(), edm::Event::getByToken(), edm::EventBase::id(), reco::Candidate::mass(), reco::Candidate::masterClone(), None, reco::Candidate::numberOfDaughters(), phiCutByEventNumber(), phiCutForTwoLeg_, edm::View< T >::refAt(), TrackRefitter_38T_cff::src, and srcToken_.

Referenced by TagProbeFitTreeProducer::analyze().

41 {
42  // declare output
43  tnp::TagProbePairs pairs;
44 
45  // read from event
47  iEvent.getByToken(srcToken_, src);
48 
49  // convert
50  for (reco::CandidateView::const_iterator it = src->begin(), ed = src->end(); it != ed; ++it) {
51  const reco::Candidate & mother = *it;
52  if (mother.numberOfDaughters() != 2) throw cms::Exception("CorruptData") << "Tag&Probe pair with " << mother.numberOfDaughters() << " daughters\n";
53  pairs.push_back(tnp::TagProbePair(mother.daughter(0)->masterClone(), mother.daughter(1)->masterClone(),
54  src->refAt(it - src->begin()), mother.mass()));
55  }
56 
57  if ((arbitration_ != None) && (pairs.size() > 1)) {
58  // might need to clean up
59  arbitrate(pairs);
60  }
61 
62  if (phiCutForTwoLeg_ && !pairs.empty()) {
63  int eventNum = iEvent.id().event();
64  std::cout << "Calling phiCutByEventNumber on eventNum=" << eventNum << std::endl;
65  phiCutByEventNumber(pairs,eventNum);
66  }
67 
68  // return
69  return pairs;
70 }
EventNumber_t event() const
Definition: EventID.h:41
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:517
std::vector< TagProbePair > TagProbePairs
virtual const Candidate * daughter(size_type i) const =0
return daughter at a given position, i = 0, ... numberOfDaughters() - 1 (read only mode) ...
RefToBase< value_type > refAt(size_type i) const
const_iterator begin() const
edm::EDGetTokenT< reco::CandidateView > srcToken_
virtual const CandidateBaseRef & masterClone() const =0
virtual double mass() const =0
mass
edm::EventID id() const
Definition: EventBase.h:59
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
const_iterator end() const
a simple struct to hold tag, probe and mass
virtual size_type numberOfDaughters() const =0
number of daughters
void phiCutByEventNumber(TagProbePairs &pairs, int eventNumber) const
void arbitrate(TagProbePairs &pairs) const

Member Data Documentation

Arbitration tnp::TagProbePairMaker::arbitration_
private

Definition at line 37 of file TagProbePairMaker.h.

Referenced by arbitrate(), run(), and TagProbePairMaker().

double tnp::TagProbePairMaker::arbitrationMass_
private

Definition at line 38 of file TagProbePairMaker.h.

Referenced by arbitrate(), and TagProbePairMaker().

bool tnp::TagProbePairMaker::phiCutForTwoLeg_
private

Definition at line 43 of file TagProbePairMaker.h.

Referenced by run(), and TagProbePairMaker().

TRandom2* tnp::TagProbePairMaker::randGen_
private

Definition at line 40 of file TagProbePairMaker.h.

Referenced by arbitrate(), and TagProbePairMaker().

edm::EDGetTokenT<reco::CandidateView> tnp::TagProbePairMaker::srcToken_
private

Definition at line 35 of file TagProbePairMaker.h.

Referenced by run().