CMS 3D CMS Logo

NjettinessAdder.cc
Go to the documentation of this file.
1 #include <memory>
2 
4 
6 
8  : src_(iConfig.getParameter<edm::InputTag>("src")),
9  src_token_(consumes<edm::View<reco::Jet>>(src_)),
10  Njets_(iConfig.getParameter<std::vector<unsigned>>("Njets")),
11  measureDefinition_(iConfig.getParameter<unsigned>("measureDefinition")),
12  beta_(iConfig.getParameter<double>("beta")),
13  R0_(iConfig.getParameter<double>("R0")),
14  Rcutoff_(iConfig.getParameter<double>("Rcutoff")),
15  axesDefinition_(iConfig.getParameter<unsigned>("axesDefinition")),
16  nPass_(iConfig.getParameter<int>("nPass")),
17  akAxesR0_(iConfig.getParameter<double>("akAxesR0")) {
18  edm::InputTag srcWeights = iConfig.getParameter<edm::InputTag>("srcWeights");
19  if (!srcWeights.label().empty())
21 
22  for (std::vector<unsigned>::const_iterator n = Njets_.begin(); n != Njets_.end(); ++n) {
23  std::ostringstream tauN_str;
24  tauN_str << "tau" << *n;
25 
26  produces<edm::ValueMap<float>>(tauN_str.str());
27  }
28 
29  // Get the measure definition
30  fastjet::contrib::NormalizedMeasure normalizedMeasure(beta_, R0_);
31  fastjet::contrib::UnnormalizedMeasure unnormalizedMeasure(beta_);
32  fastjet::contrib::OriginalGeometricMeasure geometricMeasure(beta_); // changed in 1.020
33  fastjet::contrib::NormalizedCutoffMeasure normalizedCutoffMeasure(beta_, R0_, Rcutoff_);
34  fastjet::contrib::UnnormalizedCutoffMeasure unnormalizedCutoffMeasure(beta_, Rcutoff_);
35  //fastjet::contrib::GeometricCutoffMeasure geometricCutoffMeasure (beta_,Rcutoff_); // removed in 1.020
36 
37  fastjet::contrib::MeasureDefinition const* measureDef = nullptr;
38  switch (measureDefinition_) {
40  measureDef = &unnormalizedMeasure;
41  break;
43  measureDef = &geometricMeasure;
44  break; // changed in 1.020
46  measureDef = &normalizedCutoffMeasure;
47  break;
49  measureDef = &unnormalizedCutoffMeasure;
50  break;
51  //case GeometricCutoffMeasure : measureDef = &geometricCutoffMeasure; break; // removed in 1.020
52  case NormalizedMeasure:
53  default:
54  measureDef = &normalizedMeasure;
55  break;
56  }
57 
58  // Get the axes definition
59  fastjet::contrib::KT_Axes kt_axes;
60  fastjet::contrib::CA_Axes ca_axes;
61  fastjet::contrib::AntiKT_Axes antikt_axes(akAxesR0_);
62  fastjet::contrib::WTA_KT_Axes wta_kt_axes;
63  fastjet::contrib::WTA_CA_Axes wta_ca_axes;
64  fastjet::contrib::OnePass_KT_Axes onepass_kt_axes;
65  fastjet::contrib::OnePass_CA_Axes onepass_ca_axes;
66  fastjet::contrib::OnePass_AntiKT_Axes onepass_antikt_axes(akAxesR0_);
67  fastjet::contrib::OnePass_WTA_KT_Axes onepass_wta_kt_axes;
68  fastjet::contrib::OnePass_WTA_CA_Axes onepass_wta_ca_axes;
69  fastjet::contrib::MultiPass_Axes multipass_axes(nPass_);
70 
71  fastjet::contrib::AxesDefinition const* axesDef = nullptr;
72  switch (axesDefinition_) {
73  case KT_Axes:
74  default:
75  axesDef = &kt_axes;
76  break;
77  case CA_Axes:
78  axesDef = &ca_axes;
79  break;
80  case AntiKT_Axes:
81  axesDef = &antikt_axes;
82  break;
83  case WTA_KT_Axes:
84  axesDef = &wta_kt_axes;
85  break;
86  case WTA_CA_Axes:
87  axesDef = &wta_ca_axes;
88  break;
89  case OnePass_KT_Axes:
90  axesDef = &onepass_kt_axes;
91  break;
92  case OnePass_CA_Axes:
93  axesDef = &onepass_ca_axes;
94  break;
96  axesDef = &onepass_antikt_axes;
97  break;
99  axesDef = &onepass_wta_kt_axes;
100  break;
101  case OnePass_WTA_CA_Axes:
102  axesDef = &onepass_wta_ca_axes;
103  break;
104  case MultiPass_Axes:
105  axesDef = &multipass_axes;
106  break;
107  };
108 
109  routine_ = std::make_unique<fastjet::contrib::Njettiness>(*axesDef, *measureDef);
110 }
111 
113  // read input collection
115  iEvent.getByToken(src_token_, jets);
116 
117  // Get Weights Collection
120 
121  for (std::vector<unsigned>::const_iterator n = Njets_.begin(); n != Njets_.end(); ++n) {
122  std::ostringstream tauN_str;
123  tauN_str << "tau" << *n;
124 
125  // prepare room for output
126  std::vector<float> tauN;
127  tauN.reserve(jets->size());
128 
129  for (typename edm::View<reco::Jet>::const_iterator jetIt = jets->begin(); jetIt != jets->end(); ++jetIt) {
130  edm::Ptr<reco::Jet> jetPtr = jets->ptrAt(jetIt - jets->begin());
131 
132  float t = getTau(*n, jetPtr);
133 
134  tauN.push_back(t);
135  }
136 
137  auto outT = std::make_unique<edm::ValueMap<float>>();
138  edm::ValueMap<float>::Filler fillerT(*outT);
139  fillerT.insert(jets, tauN.begin(), tauN.end());
140  fillerT.fill();
141 
142  iEvent.put(std::move(outT), tauN_str.str());
143  }
144 }
145 
146 float NjettinessAdder::getTau(unsigned num, const edm::Ptr<reco::Jet>& object) const {
147  std::vector<fastjet::PseudoJet> fjParticles;
148  for (unsigned k = 0; k < object->numberOfDaughters(); ++k) {
149  const reco::CandidatePtr& dp = object->daughterPtr(k);
150  if (dp.isNonnull() && dp.isAvailable()) {
151  // Here, the daughters are the "end" node, so this is a PFJet
152  if (dp->numberOfDaughters() == 0) {
153  if (object->isWeighted()) {
155  throw cms::Exception("MissingConstituentWeight")
156  << "ECFAdder: No weights (e.g. PUPPI) given for weighted jet collection" << std::endl;
157  float w = (*weightsHandle_)[dp];
158  fjParticles.push_back(fastjet::PseudoJet(dp->px() * w, dp->py() * w, dp->pz() * w, dp->energy() * w));
159  } else
160  fjParticles.push_back(fastjet::PseudoJet(dp->px(), dp->py(), dp->pz(), dp->energy()));
161  } else { // Otherwise, this is a BasicJet, so you need to descend further.
162  auto subjet = dynamic_cast<reco::Jet const*>(dp.get());
163  for (unsigned l = 0; l < subjet->numberOfDaughters(); ++l) {
164  if (subjet != nullptr) {
165  const reco::CandidatePtr& ddp = subjet->daughterPtr(l);
166  if (subjet->isWeighted()) {
168  throw cms::Exception("MissingConstituentWeight")
169  << "ECFAdder: No weights (e.g. PUPPI) given for weighted jet collection" << std::endl;
170  float w = (*weightsHandle_)[ddp];
171  fjParticles.push_back(fastjet::PseudoJet(ddp->px() * w, ddp->py() * w, ddp->pz() * w, ddp->energy() * w));
172  } else
173  fjParticles.push_back(fastjet::PseudoJet(ddp->px(), ddp->py(), ddp->pz(), ddp->energy()));
174  } else {
175  edm::LogWarning("MissingJetConstituent")
176  << "BasicJet constituent required for N-jettiness computation is missing!";
177  }
178  }
179  } // end if basic jet
180  } // end if daughter pointer is nonnull and available
181  else
182  edm::LogWarning("MissingJetConstituent") << "Jet constituent required for N-jettiness computation is missing!";
183  }
184 
185  return routine_->getTau(num, fjParticles);
186 }
187 
NjettinessAdder::KT_Axes
Definition: NjettinessAdder.h:26
NjettinessAdder::OnePass_WTA_KT_Axes
Definition: NjettinessAdder.h:35
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
dqmiodumpmetadata.n
n
Definition: dqmiodumpmetadata.py:28
NjettinessAdder::routine_
std::unique_ptr< fastjet::contrib::Njettiness > routine_
Definition: NjettinessAdder.h:68
sistrip::View
View
Definition: ConstantsForView.h:26
NjettinessAdder::OnePass_WTA_CA_Axes
Definition: NjettinessAdder.h:36
edm
HLT enums.
Definition: AlignableModifier.h:19
NjettinessAdder::OriginalGeometricMeasure
Definition: NjettinessAdder.h:19
NjettinessAdder::CA_Axes
Definition: NjettinessAdder.h:27
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89301
NjettinessAdder::OnePass_CA_Axes
Definition: NjettinessAdder.h:33
edm::EDGetTokenT::isUninitialized
constexpr bool isUninitialized() const noexcept
Definition: EDGetToken.h:99
singleTopDQM_cfi.jets
jets
Definition: singleTopDQM_cfi.py:42
NjettinessAdder::nPass_
int nPass_
Definition: NjettinessAdder.h:62
reco
fixed size matrix
Definition: AlignmentAlgorithmBase.h:46
NjettinessAdder::OnePass_AntiKT_Axes
Definition: NjettinessAdder.h:34
edm::Handle
Definition: AssociativeIterator.h:50
edm::LogWarning
Log< level::Warning, false > LogWarning
Definition: MessageLogger.h:122
NjettinessAdder::produce
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: NjettinessAdder.cc:112
NjettinessAdder::NormalizedCutoffMeasure
Definition: NjettinessAdder.h:20
NjettinessAdder::AntiKT_Axes
Definition: NjettinessAdder.h:28
MakerMacros.h
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Jet
Definition: Jet.py:1
NjettinessAdder::NormalizedMeasure
Definition: NjettinessAdder.h:17
Calorimetry_cff.dp
dp
Definition: Calorimetry_cff.py:158
NjettinessAdder::measureDefinition_
unsigned measureDefinition_
Definition: NjettinessAdder.h:55
w
const double w
Definition: UKUtility.cc:23
dqmdumpme.k
k
Definition: dqmdumpme.py:60
edm::ParameterSet
Definition: ParameterSet.h:47
NjettinessAdder::Rcutoff_
double Rcutoff_
Definition: NjettinessAdder.h:58
NjettinessAdder::beta_
double beta_
Definition: NjettinessAdder.h:56
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
NjettinessAdder::akAxesR0_
double akAxesR0_
Definition: NjettinessAdder.h:63
edm::EventSetup
Definition: EventSetup.h:58
NjettinessAdder::Njets_
std::vector< unsigned > Njets_
Definition: NjettinessAdder.h:52
NjettinessAdder::UnnormalizedMeasure
Definition: NjettinessAdder.h:18
HLT_FULL_cff.srcWeights
srcWeights
Definition: HLT_FULL_cff.py:8709
EgammaValidation_cff.num
num
Definition: EgammaValidation_cff.py:33
cmsLHEtoEOSManager.l
l
Definition: cmsLHEtoEOSManager.py:204
NjettinessAdder::weightsHandle_
edm::ValueMap< float > const * weightsHandle_
Definition: NjettinessAdder.h:66
NjettinessAdder::axesDefinition_
unsigned axesDefinition_
Definition: NjettinessAdder.h:61
edm::Ptr< reco::Jet >
NjettinessAdder::NjettinessAdder
NjettinessAdder(const edm::ParameterSet &iConfig)
Definition: NjettinessAdder.cc:7
NjettinessAdder::WTA_CA_Axes
Definition: NjettinessAdder.h:30
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
edm::ValueMap< float >
NjettinessAdder.h
NjettinessAdder::input_weights_token_
edm::EDGetTokenT< edm::ValueMap< float > > input_weights_token_
Definition: NjettinessAdder.h:65
NjettinessAdder::UnnormalizedCutoffMeasure
Definition: NjettinessAdder.h:21
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
NjettinessAdder
Definition: NjettinessAdder.h:14
NjettinessAdder::R0_
double R0_
Definition: NjettinessAdder.h:57
NjettinessAdder::src_token_
edm::EDGetTokenT< edm::View< reco::Jet > > src_token_
Definition: NjettinessAdder.h:51
edm::View::const_iterator
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
cms::Exception
Definition: Exception.h:70
edm::helper::Filler
Definition: ValueMap.h:22
NjettinessAdder::WTA_KT_Axes
Definition: NjettinessAdder.h:29
edm::Event
Definition: Event.h:73
NjettinessAdder::MultiPass_Axes
Definition: NjettinessAdder.h:38
submitPVValidationJobs.t
string t
Definition: submitPVValidationJobs.py:644
edm::InputTag
Definition: InputTag.h:15
NjettinessAdder::OnePass_KT_Axes
Definition: NjettinessAdder.h:32
NjettinessAdder::getTau
float getTau(unsigned num, const edm::Ptr< reco::Jet > &object) const
Definition: NjettinessAdder.cc:146