test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
NjettinessAdder.cc
Go to the documentation of this file.
2 
3 
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  measureDefinition_(iConfig.getParameter<unsigned >("measureDefinition")),
11  beta_(iConfig.getParameter<double>("beta")),
12  R0_(iConfig.getParameter<double>("R0")),
13  Rcutoff_(iConfig.getParameter<double>("Rcutoff")),
14  axesDefinition_(iConfig.getParameter< unsigned >("axesDefinition")),
15  nPass_(iConfig.getParameter<int>("nPass")),
16  akAxesR0_(iConfig.getParameter<double>("akAxesR0"))
17 {
18  for ( std::vector<unsigned>::const_iterator n = Njets_.begin(); n != Njets_.end(); ++n )
19  {
20  std::ostringstream tauN_str;
21  tauN_str << "tau" << *n;
22 
23  produces<edm::ValueMap<float> >(tauN_str.str().c_str());
24  }
25 
26 
27  // Get the measure definition
28  fastjet::contrib::NormalizedMeasure normalizedMeasure (beta_,R0_);
29  fastjet::contrib::UnnormalizedMeasure unnormalizedMeasure (beta_);
30  fastjet::contrib::OriginalGeometricMeasure geometricMeasure (beta_);// changed in 1.020
31  fastjet::contrib::NormalizedCutoffMeasure normalizedCutoffMeasure (beta_,R0_,Rcutoff_);
32  fastjet::contrib::UnnormalizedCutoffMeasure unnormalizedCutoffMeasure(beta_,Rcutoff_);
33  //fastjet::contrib::GeometricCutoffMeasure geometricCutoffMeasure (beta_,Rcutoff_); // removed in 1.020
34 
35  fastjet::contrib::MeasureDefinition const * measureDef = 0;
36  switch ( measureDefinition_ ) {
37  case UnnormalizedMeasure : measureDef = &unnormalizedMeasure; break;
38  case OriginalGeometricMeasure : measureDef = &geometricMeasure; break;// changed in 1.020
39  case NormalizedCutoffMeasure : measureDef = &normalizedCutoffMeasure; break;
40  case UnnormalizedCutoffMeasure : measureDef = &unnormalizedCutoffMeasure; break;
41  //case GeometricCutoffMeasure : measureDef = &geometricCutoffMeasure; break; // removed in 1.020
42  case NormalizedMeasure : default : measureDef = &normalizedMeasure; break;
43  }
44 
45  // Get the axes definition
46  fastjet::contrib::KT_Axes kt_axes;
47  fastjet::contrib::CA_Axes ca_axes;
48  fastjet::contrib::AntiKT_Axes antikt_axes (akAxesR0_);
49  fastjet::contrib::WTA_KT_Axes wta_kt_axes;
50  fastjet::contrib::WTA_CA_Axes wta_ca_axes;
51  fastjet::contrib::OnePass_KT_Axes onepass_kt_axes;
52  fastjet::contrib::OnePass_CA_Axes onepass_ca_axes;
53  fastjet::contrib::OnePass_AntiKT_Axes onepass_antikt_axes (akAxesR0_);
54  fastjet::contrib::OnePass_WTA_KT_Axes onepass_wta_kt_axes;
55  fastjet::contrib::OnePass_WTA_CA_Axes onepass_wta_ca_axes;
56  fastjet::contrib::MultiPass_Axes multipass_axes (nPass_);
57 
58  fastjet::contrib::AxesDefinition const * axesDef = 0;
59  switch ( axesDefinition_ ) {
60  case KT_Axes : default : axesDef = &kt_axes; break;
61  case CA_Axes : axesDef = &ca_axes; break;
62  case AntiKT_Axes : axesDef = &antikt_axes; break;
63  case WTA_KT_Axes : axesDef = &wta_kt_axes; break;
64  case WTA_CA_Axes : axesDef = &wta_ca_axes; break;
65  case OnePass_KT_Axes : axesDef = &onepass_kt_axes; break;
66  case OnePass_CA_Axes : axesDef = &onepass_ca_axes; break;
67  case OnePass_AntiKT_Axes : axesDef = &onepass_antikt_axes; break;
68  case OnePass_WTA_KT_Axes : axesDef = &onepass_wta_kt_axes; break;
69  case OnePass_WTA_CA_Axes : axesDef = &onepass_wta_ca_axes; break;
70  case MultiPass_Axes : axesDef = &multipass_axes; break;
71  };
72 
73  routine_ = std::auto_ptr<fastjet::contrib::Njettiness> ( new fastjet::contrib::Njettiness( *axesDef, *measureDef ) );
74 
75 }
76 
78  // read input collection
80  iEvent.getByToken(src_token_, jets);
81 
82  for ( std::vector<unsigned>::const_iterator n = Njets_.begin(); n != Njets_.end(); ++n )
83  {
84  std::ostringstream tauN_str;
85  tauN_str << "tau" << *n;
86 
87  // prepare room for output
88  std::vector<float> tauN;
89  tauN.reserve(jets->size());
90 
91  for ( typename edm::View<reco::Jet>::const_iterator jetIt = jets->begin() ; jetIt != jets->end() ; ++jetIt ) {
92 
93  edm::Ptr<reco::Jet> jetPtr = jets->ptrAt(jetIt - jets->begin());
94 
95  float t=getTau( *n, jetPtr );
96 
97  tauN.push_back(t);
98  }
99 
100  std::auto_ptr<edm::ValueMap<float> > outT(new edm::ValueMap<float>());
101  edm::ValueMap<float>::Filler fillerT(*outT);
102  fillerT.insert(jets, tauN.begin(), tauN.end());
103  fillerT.fill();
104 
105  iEvent.put(outT,tauN_str.str().c_str());
106  }
107 }
108 
109 float NjettinessAdder::getTau(unsigned num, const edm::Ptr<reco::Jet> & object) const
110 {
111  std::vector<fastjet::PseudoJet> FJparticles;
112  for (unsigned k = 0; k < object->numberOfDaughters(); ++k)
113  {
114  const reco::CandidatePtr & dp = object->daughterPtr(k);
115  if ( dp.isNonnull() && dp.isAvailable() )
116  FJparticles.push_back( fastjet::PseudoJet( dp->px(), dp->py(), dp->pz(), dp->energy() ) );
117  else
118  edm::LogWarning("MissingJetConstituent") << "Jet constituent required for N-subjettiness computation is missing!";
119  }
120 
121  return routine_->getTau(num, FJparticles);
122 }
123 
124 
125 
std::auto_ptr< fastjet::contrib::Njettiness > routine_
unsigned measureDefinition_
unsigned axesDefinition_
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool isAvailable() const
Definition: Ptr.h:259
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:52
int iEvent
Definition: GenABIO.cc:230
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
vector< PseudoJet > jets
std::vector< unsigned > Njets_
bool isNonnull() const
Checks for non-null.
Definition: Ptr.h:169
auto dp
Definition: deltaR.h:22
float getTau(unsigned num, const edm::Ptr< reco::Jet > &object) const
boost::indirect_iterator< typename seq_t::const_iterator > const_iterator
Definition: View.h:81
void produce(edm::Event &iEvent, const edm::EventSetup &iSetup)
NjettinessAdder(const edm::ParameterSet &iConfig)
edm::EDGetTokenT< edm::View< reco::Jet > > src_token_