CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ECFAdder.cc
Go to the documentation of this file.
2 #include "fastjet/PseudoJet.hh"
3 #include "fastjet/ClusterSequence.hh"
5 
7  src_(iConfig.getParameter<edm::InputTag>("src")),
8  src_token_(consumes<edm::View<reco::Jet>>(src_)),
9  Njets_(iConfig.getParameter<std::vector<unsigned> >("Njets")),
10  beta_(iConfig.getParameter<double>("beta"))
11 {
12  for ( std::vector<unsigned>::const_iterator n = Njets_.begin(); n != Njets_.end(); ++n )
13  {
14  std::ostringstream ecfN_str;
15  ecfN_str << "ecf" << *n;
16  variables_.push_back(ecfN_str.str());
17  produces<edm::ValueMap<float> >(ecfN_str.str().c_str());
18  routine_.push_back(std::auto_ptr<fastjet::contrib::EnergyCorrelator> ( new fastjet::contrib::EnergyCorrelator( *n, beta_, fastjet::contrib::EnergyCorrelator::pt_R ) ));
19  }
20 }
21 
23  // read input collection
25  iEvent.getByToken(src_token_, jets);
26 
27  unsigned i=0;
28  for ( std::vector<unsigned>::const_iterator n = Njets_.begin(); n != Njets_.end(); ++n )
29  {
30  // prepare room for output
31  std::vector<float> ecfN;
32  ecfN.reserve(jets->size());
33 
34  for ( typename edm::View<reco::Jet>::const_iterator jetIt = jets->begin() ; jetIt != jets->end() ; ++jetIt ) {
35 
36  edm::Ptr<reco::Jet> jetPtr = jets->ptrAt(jetIt - jets->begin());
37 
38  float t=getECF( i, jetPtr );
39 
40  ecfN.push_back(t);
41  }
42 
43  auto outT = std::make_unique<edm::ValueMap<float>>();
44  edm::ValueMap<float>::Filler fillerT(*outT);
45  fillerT.insert(jets, ecfN.begin(), ecfN.end());
46  fillerT.fill();
47 
48  iEvent.put(std::move(outT),variables_[i].c_str());
49  ++i;
50  }
51 }
52 
53 float ECFAdder::getECF(unsigned index, const edm::Ptr<reco::Jet> & object) const
54 {
55  std::vector<fastjet::PseudoJet> FJparticles;
56  for (unsigned k = 0; k < object->numberOfDaughters(); ++k)
57  {
58  const reco::CandidatePtr & dp = object->daughterPtr(k);
59  if ( dp.isNonnull() && dp.isAvailable() )
60  FJparticles.push_back( fastjet::PseudoJet( dp->px(), dp->py(), dp->pz(), dp->energy() ) );
61  else
62  edm::LogWarning("MissingJetConstituent") << "Jet constituent required for ECF computation is missing!";
63  }
64  fastjet::JetDefinition jetDef(fastjet::antikt_algorithm, 999);
65  fastjet::ClusterSequence thisClustering_basic(FJparticles, jetDef);
66  std::vector<fastjet::PseudoJet> out_jets_basic = thisClustering_basic.inclusive_jets(0);
67  if(out_jets_basic.size()!=1) return -1;
68  return routine_[index]->result(out_jets_basic[0]);
69 }
70 
71 
72 
int i
Definition: DBlmapReader.cc:9
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
Definition: Event.h:122
ECFAdder(const edm::ParameterSet &iConfig)
Definition: ECFAdder.cc:6
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool isAvailable() const
Definition: Ptr.h:259
float getECF(unsigned index, const edm::Ptr< reco::Jet > &object) const
Definition: ECFAdder.cc:53
std::vector< std::string > variables_
Definition: ECFAdder.h:26
int iEvent
Definition: GenABIO.cc:230
double beta_
Definition: ECFAdder.h:27
std::vector< std::auto_ptr< fastjet::contrib::EnergyCorrelator > > routine_
Definition: ECFAdder.h:29
vector< PseudoJet > jets
def move
Definition: eostools.py:510
edm::EDGetTokenT< edm::View< reco::Jet > > src_token_
Definition: ECFAdder.h:24
std::vector< unsigned > Njets_
Definition: ECFAdder.h:25
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:169
auto dp
Definition: deltaR.h:22
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup) override
Definition: ECFAdder.cc:22
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81