CMS 3D CMS Logo

ECFAdder.cc
Go to the documentation of this file.
2 #include "fastjet/PseudoJet.hh"
3 #include "fastjet/ClusterSequence.hh"
8 
10  src_(iConfig.getParameter<edm::InputTag>("src")),
11  src_token_(consumes<edm::View<reco::Jet>>(src_)),
12  Njets_(iConfig.getParameter<std::vector<unsigned> >("Njets")),
13  cuts_(iConfig.getParameter<std::vector<std::string>>("cuts")),
14  ecftype_(iConfig.getParameter<std::string>("ecftype")),
15  alpha_(iConfig.getParameter<double>("alpha")),
16  beta_(iConfig.getParameter<double>("beta"))
17 {
18 
19  if ( cuts_.size() != Njets_.size() ) {
20  throw cms::Exception("ConfigurationError") << "cuts and Njets must be the same size in ECFAdder" << std::endl;
21  }
22 
23  for ( std::vector<unsigned>::const_iterator n = Njets_.begin(); n != Njets_.end(); ++n )
24  {
25  std::ostringstream ecfN_str;
26  std::shared_ptr<fastjet::FunctionOfPseudoJet<double> > pfunc;
27 
28  if ( ecftype_ == "ECF" || ecftype_ == "" ) {
29  ecfN_str << "ecf" << *n;
30  pfunc.reset( new fastjet::contrib::EnergyCorrelator( *n, beta_, fastjet::contrib::EnergyCorrelator::pt_R ) );
31  }
32  else if ( ecftype_ == "C" ) {
33  ecfN_str << "ecfC" << *n;
34  pfunc.reset( new fastjet::contrib::EnergyCorrelatorCseries( *n, beta_, fastjet::contrib::EnergyCorrelator::pt_R ) );
35  }
36  else if ( ecftype_ == "D" ) {
37  ecfN_str << "ecfD" << *n;
38  pfunc.reset( new fastjet::contrib::EnergyCorrelatorGeneralizedD2( alpha_, beta_, fastjet::contrib::EnergyCorrelator::pt_R ) );
39  }
40  else if ( ecftype_ == "N" ) {
41  ecfN_str << "ecfN" << *n;
42  pfunc.reset( new fastjet::contrib::EnergyCorrelatorNseries( *n, beta_, fastjet::contrib::EnergyCorrelator::pt_R ) );
43  }
44  else if ( ecftype_ == "M" ) {
45  ecfN_str << "ecfM" << *n;
46  pfunc.reset( new fastjet::contrib::EnergyCorrelatorMseries( *n, beta_, fastjet::contrib::EnergyCorrelator::pt_R ) );
47  }
48  else if ( ecftype_ == "U" ) {
49  ecfN_str << "ecfU" << *n;
50  pfunc.reset( new fastjet::contrib::EnergyCorrelatorUseries( *n, beta_, fastjet::contrib::EnergyCorrelator::pt_R ) );
51  }
52  variables_.push_back(ecfN_str.str());
53  produces<edm::ValueMap<float> >(ecfN_str.str());
54  routine_.push_back(pfunc);
55 
56 
57 
58  selectors_.push_back( StringCutObjectSelector<reco::Jet>( cuts_[ n - Njets_.begin()] ) );
59  }
60 
61 
62 
63 }
64 
66  // read input collection
68  iEvent.getByToken(src_token_, jets);
69 
70  unsigned i=0;
71  for ( std::vector<unsigned>::const_iterator n = Njets_.begin(); n != Njets_.end(); ++n )
72  {
73  // prepare room for output
74  std::vector<float> ecfN;
75  ecfN.reserve(jets->size());
76 
77  for ( typename edm::View<reco::Jet>::const_iterator jetIt = jets->begin() ; jetIt != jets->end() ; ++jetIt ) {
78 
79  edm::Ptr<reco::Jet> jetPtr = jets->ptrAt(jetIt - jets->begin());
80 
81 
82  float t= -1.0;
83  if ( selectors_[n - Njets_.begin()] (*jetIt) )
84  t = getECF( i, jetPtr );
85 
86  ecfN.push_back(t);
87  }
88 
89  auto outT = std::make_unique<edm::ValueMap<float>>();
90  edm::ValueMap<float>::Filler fillerT(*outT);
91  fillerT.insert(jets, ecfN.begin(), ecfN.end());
92  fillerT.fill();
93 
94  iEvent.put(std::move(outT),variables_[i]);
95  ++i;
96  }
97 }
98 
99 float ECFAdder::getECF(unsigned index, const edm::Ptr<reco::Jet> & object) const
100 {
101  std::vector<fastjet::PseudoJet> FJparticles;
102  for (unsigned k = 0; k < object->numberOfDaughters(); ++k)
103  {
104  const reco::CandidatePtr & dp = object->daughterPtr(k);
105  if ( dp.isNonnull() && dp.isAvailable() ){
106 
107  // Here, the daughters are the "end" node, so this is a PFJet
108  if ( dp->numberOfDaughters() == 0 ) {
109  FJparticles.push_back( fastjet::PseudoJet( dp->px(), dp->py(), dp->pz(), dp->energy() ) );
110  } else { // Otherwise, this is a BasicJet, so you need to descend further.
111  auto subjet = dynamic_cast<reco::Jet const * >( dp.get() );
112  for ( unsigned l = 0; l < subjet->numberOfDaughters(); ++l ) {
113  if ( subjet != nullptr ) {
114  const reco::CandidatePtr & ddp = subjet->daughterPtr(l);
115  FJparticles.push_back( fastjet::PseudoJet( ddp->px(), ddp->py(), ddp->pz(), ddp->energy() ) );
116  } else {
117  edm::LogWarning("MissingJetConstituent") << "BasicJet constituent required for ECF computation is missing!";
118  }
119  }
120  } // end if basic jet
121  } // end if daughter pointer is nonnull and available
122  else
123  edm::LogWarning("MissingJetConstituent") << "Jet constituent required for ECF computation is missing!";
124  }
125  if ( FJparticles.size() > Njets_[index] )
126  {
127  return routine_[index]->result(join(FJparticles));
128  }
129  else
130  {
131  return -1.0;
132  }
133 }
134 
135 
136 // ParameterSet description for module
138 {
140  iDesc.setComment("Energy Correlation Functions adder");
141 
142  iDesc.add<edm::InputTag>("src", edm::InputTag("no default"))->setComment("input collection");
143  iDesc.add<std::vector<unsigned> >("Njets", {1,2,3} )->setComment("Number of jets to emulate");
144  iDesc.add<std::vector<std::string>> ("cuts", {"", "", ""})->setComment("Jet selections for each N value. Size must match Njets.");
145  iDesc.add<double>("alpha",1.0)->setComment("alpha factor, only valid for N2");
146  iDesc.add<double>("beta",1.0)->setComment("angularity factor");
147  iDesc.add<std::string>("ecftype","")->setComment("ECF type: ECF or empty; C; D; N; M; U;");
148  descriptions.add("ECFAdder", iDesc);
149 }
150 
void setComment(std::string const &value)
std::vector< std::shared_ptr< fastjet::FunctionOfPseudoJet< double > > > routine_
Definition: ECFAdder.h:35
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
Definition: ECFAdder.cc:137
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:127
ECFAdder(const edm::ParameterSet &iConfig)
Definition: ECFAdder.cc:9
std::string ecftype_
Definition: ECFAdder.h:30
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:508
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
T const * get() const
Returns C++ pointer to the item.
Definition: Ptr.h:159
Base class for all types of Jets.
Definition: Jet.h:20
bool isAvailable() const
Definition: Ptr.h:258
float getECF(unsigned index, const edm::Ptr< reco::Jet > &object) const
Definition: ECFAdder.cc:99
std::vector< StringCutObjectSelector< reco::Jet > > selectors_
Definition: ECFAdder.h:36
std::vector< std::string > variables_
Definition: ECFAdder.h:31
std::vector< std::string > cuts_
Definition: ECFAdder.h:29
void setComment(std::string const &value)
int iEvent
Definition: GenABIO.cc:230
double beta_
Definition: ECFAdder.h:33
Definition: Jet.py:1
vector< PseudoJet > jets
edm::EDGetTokenT< edm::View< reco::Jet > > src_token_
Definition: ECFAdder.h:27
ParameterDescriptionBase * add(U const &iLabel, T const &value)
std::vector< unsigned > Njets_
Definition: ECFAdder.h:28
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:168
int k[5][pyjets_maxn]
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
auto dp
Definition: deltaR.h:22
void add(std::string const &label, ParameterSetDescription const &psetDescription)
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: ECFAdder.cc:65
fixed size matrix
HLT enums.
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:86
double alpha_
Definition: ECFAdder.h:32
def move(src, dest)
Definition: eostools.py:510