CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
HiFJRhoProducer Class Reference

#include <HiJetBackground/HiFJRhoProducer/plugins/HiFJRhoProducer.cc>

Inheritance diagram for HiFJRhoProducer:
edm::stream::EDProducer<> edm::stream::EDProducerBase edm::ProducerBase edm::EDConsumerBase edm::ProductRegistryHelper

Public Member Functions

 HiFJRhoProducer (const edm::ParameterSet &)
 
 ~HiFJRhoProducer ()
 
- Public Member Functions inherited from edm::stream::EDProducer<>
 EDProducer ()=default
 
- Public Member Functions inherited from edm::stream::EDProducerBase
 EDProducerBase ()
 
ModuleDescription const & moduleDescription () const
 
virtual ~EDProducerBase ()
 
- Public Member Functions inherited from edm::ProducerBase
void callWhenNewProductsRegistered (std::function< void(BranchDescription const &)> const &func)
 
 ProducerBase ()
 
void registerProducts (ProducerBase *, ProductRegistry *, ModuleDescription const &)
 
std::function< void(BranchDescription
const &)> 
registrationCallback () const
 used by the fwk to register list of products More...
 
virtual ~ProducerBase ()
 
- Public Member Functions inherited from edm::EDConsumerBase
std::vector< ConsumesInfoconsumesInfo () const
 
 EDConsumerBase ()
 
ProductHolderIndexAndSkipBit indexFrom (EDGetToken, BranchType, TypeID const &) const
 
void itemsMayGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
void itemsToGet (BranchType, std::vector< ProductHolderIndexAndSkipBit > &) const
 
std::vector
< ProductHolderIndexAndSkipBit >
const & 
itemsToGetFromEvent () const
 
void labelsForToken (EDGetToken iToken, Labels &oLabels) const
 
void modulesDependentUpon (std::string const &iProcessName, std::string const &iModuleLabel, bool iPrint, std::vector< char const * > &oModuleLabels) const
 
void modulesWhoseProductsAreConsumed (std::vector< ModuleDescription const * > &modules, ProductRegistry const &preg, std::map< std::string, ModuleDescription const * > const &labelsToDesc, std::string const &processName) const
 
bool registeredToConsume (ProductHolderIndex, bool, BranchType) const
 
bool registeredToConsumeMany (TypeID const &, BranchType) const
 
void updateLookup (BranchType iBranchType, ProductHolderIndexHelper const &)
 
virtual ~EDConsumerBase ()
 

Static Public Member Functions

static void fillDescriptions (edm::ConfigurationDescriptions &descriptions)
 
- Static Public Member Functions inherited from edm::stream::EDProducerBase
static const std::string & baseType ()
 
static void fillDescriptions (ConfigurationDescriptions &descriptions)
 
static void prevalidate (ConfigurationDescriptions &descriptions)
 

Private Member Functions

virtual void beginStream (edm::StreamID) override
 
double calcMd (const reco::Jet *jet)
 
double calcMedian (std::vector< double > &v)
 
virtual void endStream () override
 
bool isPackedCandidate (const reco::Candidate *candidate)
 
virtual void produce (edm::Event &, const edm::EventSetup &) override
 

Private Attributes

bool checkJetCand
 
double etaMaxExcl2_
 
double etaMaxExcl_
 
std::vector< double > etaRanges
 
edm::EDGetTokenT< edm::View
< reco::Jet > > 
jetsToken_
 
unsigned int nExcl2_
 
unsigned int nExcl_
 
double ptMinExcl2_
 
double ptMinExcl_
 
edm::InputTag src_
 
bool usingPackedCand
 

Additional Inherited Members

- Public Types inherited from edm::stream::EDProducer<>
typedef CacheContexts< T...> CacheTypes
 
typedef CacheTypes::GlobalCache GlobalCache
 
typedef AbilityChecker< T...> HasAbility
 
typedef
CacheTypes::LuminosityBlockCache 
LuminosityBlockCache
 
typedef
LuminosityBlockContextT
< LuminosityBlockCache,
RunCache, GlobalCache
LuminosityBlockContext
 
typedef
CacheTypes::LuminosityBlockSummaryCache 
LuminosityBlockSummaryCache
 
typedef CacheTypes::RunCache RunCache
 
typedef RunContextT< RunCache,
GlobalCache
RunContext
 
typedef CacheTypes::RunSummaryCache RunSummaryCache
 
- Public Types inherited from edm::stream::EDProducerBase
typedef EDProducerAdaptorBase ModuleType
 
- Public Types inherited from edm::ProducerBase
typedef
ProductRegistryHelper::TypeLabelList 
TypeLabelList
 
- Public Types inherited from edm::EDConsumerBase
typedef ProductLabels Labels
 
- Protected Member Functions inherited from edm::EDConsumerBase
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > consumes (edm::InputTag const &tag)
 
EDGetToken consumes (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken consumes (TypeToGet const &id, edm::InputTag const &tag)
 
ConsumesCollector consumesCollector ()
 Use a ConsumesCollector to gather consumes information from helper functions. More...
 
template<typename ProductType , BranchType B = InEvent>
void consumesMany ()
 
void consumesMany (const TypeToGet &id)
 
template<BranchType B>
void consumesMany (const TypeToGet &id)
 
template<typename ProductType , BranchType B = InEvent>
EDGetTokenT< ProductType > mayConsume (edm::InputTag const &tag)
 
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 
template<BranchType B>
EDGetToken mayConsume (const TypeToGet &id, edm::InputTag const &tag)
 

Detailed Description

Description: [one line class summary]

Implementation: [Notes on implementation]

Definition at line 26 of file HiFJRhoProducer.h.

Constructor & Destructor Documentation

HiFJRhoProducer::HiFJRhoProducer ( const edm::ParameterSet iConfig)
explicit

Definition at line 51 of file HiFJRhoProducer.cc.

References etaRanges, edm::ParameterSet::getParameter(), jetsToken_, and src_.

51  :
52  src_(iConfig.getParameter<edm::InputTag>("jetSource")),
53  nExcl_(iConfig.getParameter<int>("nExcl")),
54  etaMaxExcl_(iConfig.getParameter<double>("etaMaxExcl")),
55  ptMinExcl_(iConfig.getParameter<double>("ptMinExcl")),
56  nExcl2_(iConfig.getParameter<int>("nExcl2")),
57  etaMaxExcl2_(iConfig.getParameter<double>("etaMaxExcl2")),
58  ptMinExcl2_(iConfig.getParameter<double>("ptMinExcl2")),
59  checkJetCand(true),
60  usingPackedCand(false)
61 {
62  jetsToken_ = consumes<edm::View<reco::Jet> >(src_);
63 
64  //register your products
65  produces<std::vector<double > >("mapEtaEdges");
66  produces<std::vector<double > >("mapToRho");
67  produces<std::vector<double > >("mapToRhoM");
68  produces<std::vector<double > >("ptJets");
69  produces<std::vector<double > >("areaJets");
70  produces<std::vector<double > >("etaJets");
71  etaRanges = iConfig.getParameter<std::vector<double> >("etaRanges");
72 
73 }
T getParameter(std::string const &) const
edm::InputTag src_
std::vector< double > etaRanges
unsigned int nExcl_
edm::EDGetTokenT< edm::View< reco::Jet > > jetsToken_
unsigned int nExcl2_
HiFJRhoProducer::~HiFJRhoProducer ( )

Definition at line 76 of file HiFJRhoProducer.cc.

77 {
78 
79  // do anything here that needs to be done at desctruction time
80  // (e.g. close files, deallocate resources etc.)
81 
82 }

Member Function Documentation

void HiFJRhoProducer::beginStream ( edm::StreamID  )
overrideprivatevirtual

Reimplemented from edm::stream::EDProducerBase.

Definition at line 186 of file HiFJRhoProducer.cc.

187 {
188 }
double HiFJRhoProducer::calcMd ( const reco::Jet jet)
private

Definition at line 195 of file HiFJRhoProducer.cc.

References reco::Jet::getJetConstituentsQuick(), isPackedCandidate(), and mathSSE::sqrt().

Referenced by produce().

195  {
196  //
197  //get md as defined in http://arxiv.org/pdf/1211.2811.pdf
198  //
199 
200  //Loop over the jet constituents
201  double sum = 0.;
202  for(auto daughter : jet->getJetConstituentsQuick()){
203  if(isPackedCandidate(daughter)){ //packed candidate situation
204  auto part = static_cast<const pat::PackedCandidate*>(daughter);
205  sum += sqrt(part->mass()*part->mass() + part->pt()*part->pt()) - part->pt();
206  } else {
207  auto part = static_cast<const reco::PFCandidate*>(daughter);
208  sum += sqrt(part->mass()*part->mass() + part->pt()*part->pt()) - part->pt();
209  }
210  }
211 
212  return sum;
213 }
bool isPackedCandidate(const reco::Candidate *candidate)
T sqrt(T t)
Definition: SSEVec.h:18
part
Definition: HCALResponse.h:20
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
virtual std::vector< const reco::Candidate * > getJetConstituentsQuick() const
quick list of constituents
double HiFJRhoProducer::calcMedian ( std::vector< double > &  v)
private

Definition at line 240 of file HiFJRhoProducer.cc.

References gen::n.

Referenced by produce().

241 {
242  //post-condition: After returning, the elements in v may be reordered and the resulting order is implementation defined.
243  //works for even and odd collections
244  if(v.empty()) {
245  return 0.0;
246  }
247  auto n = v.size() / 2;
248  std::nth_element(v.begin(), v.begin()+n, v.end());
249  auto med = v[n];
250  if(!(v.size() & 1)) { //If the set size is even
251  auto max_it = std::max_element(v.begin(), v.begin()+n);
252  med = (*max_it + med) / 2.0;
253  }
254  return med;
255 }
void HiFJRhoProducer::endStream ( )
overrideprivatevirtual

Reimplemented from edm::stream::EDProducerBase.

Definition at line 192 of file HiFJRhoProducer.cc.

192  {
193 }
void HiFJRhoProducer::fillDescriptions ( edm::ConfigurationDescriptions descriptions)
static

Definition at line 225 of file HiFJRhoProducer.cc.

References edm::ConfigurationDescriptions::add(), edm::ParameterSetDescription::add(), and HLT_25ns10e33_v2_cff::InputTag.

225  {
227  desc.add<edm::InputTag>("jetSource",edm::InputTag("kt4PFJets"));
228  desc.add<int>("nExcl", 2);
229  desc.add<double>("etaMaxExcl",2.);
230  desc.add<double>("ptMinExcl",20.);
231  desc.add<int>("nExcl2", 2);
232  desc.add<double>("etaMaxExcl2",2.);
233  desc.add<double>("ptMinExcl2",20.);
234  desc.add<std::vector<double> >("etaRanges");
235  descriptions.add("hiFJRhoProducer",desc);
236 }
ParameterDescriptionBase * add(U const &iLabel, T const &value)
void add(std::string const &label, ParameterSetDescription const &psetDescription)
bool HiFJRhoProducer::isPackedCandidate ( const reco::Candidate candidate)
private

Definition at line 215 of file HiFJRhoProducer.cc.

References checkJetCand, Exception, and usingPackedCand.

Referenced by calcMd().

215  {
216  if(checkJetCand) {
217  if(typeid(pat::PackedCandidate)==typeid(*candidate)) usingPackedCand = true;
218  else if(typeid(reco::PFCandidate)==typeid(*candidate)) usingPackedCand = false;
219  else throw cms::Exception("WrongJetCollection", "Jet constituents are not particle flow candidates");
220  checkJetCand = false;
221  }
222  return usingPackedCand;
223 }
Particle reconstructed by the particle flow algorithm.
Definition: PFCandidate.h:39
void HiFJRhoProducer::produce ( edm::Event iEvent,
const edm::EventSetup iSetup 
)
overrideprivatevirtual

Implements edm::stream::EDProducerBase.

Definition at line 85 of file HiFJRhoProducer.cc.

References calcMd(), calcMedian(), alignCSCRings::e, eta, HLT_25ns10e33_v2_cff::etaMax, etaMaxExcl2_, etaMaxExcl_, HLT_25ns10e33_v2_cff::etaMin, etaRanges, edm::Event::getByToken(), i, metsig::jet, fwrapper::jets, jetsToken_, eostools::move(), nExcl2_, nExcl_, HLT_25ns10e33_v2_cff::njets, EnergyCorrector::pt, ptMinExcl2_, ptMinExcl_, edm::Event::put(), and CosmicsPD_Skims::radius.

86 {
87  // Get the vector of jets
89  iEvent.getByToken(jetsToken_, jets);
90 
91  int neta = (int)etaRanges.size();
92  std::unique_ptr<std::vector<double>> mapEtaRangesOut ( new std::vector<double>(neta,-999.));
93 
94  for(int ieta = 0; ieta < neta; ieta++){
95  mapEtaRangesOut->at(ieta) = etaRanges[ieta];
96  }
97  std::unique_ptr<std::vector<double>> mapToRhoOut ( new std::vector<double>(neta-1,1e-6));
98  std::unique_ptr<std::vector<double>> mapToRhoMOut ( new std::vector<double>(neta-1,1e-6));
99 
100  int njets = jets->size();
101 
102  std::unique_ptr<std::vector<double>> ptJetsOut ( new std::vector<double>(njets,1e-6));
103  std::unique_ptr<std::vector<double>> areaJetsOut ( new std::vector<double>(njets,1e-6));
104  std::unique_ptr<std::vector<double>> etaJetsOut ( new std::vector<double>(njets,1e-6));
105 
106  double rhoVec[999];
107  double rhomVec[999];
108  double etaVec[999];
109 
110  // int neta = (int)mapEtaRangesOut->size();
111  int nacc = 0;
112  unsigned int njetsEx = 0;
113  unsigned int njetsEx2 = 0;
114  for(auto jet = jets->begin(); jet != jets->end(); ++jet) {
115  if(njetsEx<nExcl_ && fabs(jet->eta())<etaMaxExcl_ && jet->pt()>ptMinExcl_) {
116  njetsEx++;
117  continue;
118  }
119  if(njetsEx2<nExcl2_ && fabs(jet->eta())<etaMaxExcl2_ && fabs(jet->eta())>etaMaxExcl_ && jet->pt()>ptMinExcl2_) {
120  njetsEx2++;
121  continue;
122  }
123  float pt = jet->pt();
124  float area = jet->jetArea();
125  float eta = jet->eta();
126 
127  if(eta<mapEtaRangesOut->at(0) || eta>mapEtaRangesOut->at(neta-1)) continue;
128  if(area>0.) {
129  rhoVec[nacc] = pt/area;
130  rhomVec[nacc] = calcMd(&*jet)/area;
131  etaVec[nacc] = eta;
132  ptJetsOut->at(nacc) = pt;
133  areaJetsOut->at(nacc) = area;
134  etaJetsOut->at(nacc) = eta;
135  ++nacc;
136  }
137  }
138 
139  ptJetsOut->resize(nacc);
140  areaJetsOut->resize(nacc);
141  etaJetsOut->resize(nacc);
142  //calculate rho and rhom in eta ranges
143  double radius = 0.2; //distance kt clusters needs to be from edge
144  for(int ieta = 0; ieta<(neta-1); ieta++) {
145  std::vector<double> rhoVecCur;
146  std::vector<double> rhomVecCur;
147 
148  double etaMin = mapEtaRangesOut->at(ieta)+radius;
149  double etaMax = mapEtaRangesOut->at(ieta+1)-radius;
150 
151  int naccCur = 0 ;
152  double rhoCurSum = 0.;
153  double rhomCurSum = 0.;
154  for(int i = 0; i<nacc; i++) {
155  if(etaVec[i]>=etaMin && etaVec[i]<etaMax) {
156  rhoVecCur.push_back(rhoVec[i]);
157  rhomVecCur.push_back(rhomVec[i]);
158 
159  rhoCurSum += rhoVec[i];
160  rhomCurSum += rhomVec[i];
161  ++naccCur;
162  }//eta selection
163  }//accepted jet loop
164 
165  if(naccCur>0) {
166  double rhoCur = calcMedian(rhoVecCur);
167  double rhomCur = calcMedian(rhomVecCur);
168  mapToRhoOut->at(ieta) = rhoCur;
169  mapToRhoMOut->at(ieta) = rhomCur;
170  }
171  }//eta ranges
172 
173  iEvent.put(std::move(mapEtaRangesOut),"mapEtaEdges");
174  iEvent.put(std::move(mapToRhoOut),"mapToRho");
175  iEvent.put(std::move(mapToRhoMOut),"mapToRhoM");
176 
177  iEvent.put(std::move(ptJetsOut),"ptJets");
178  iEvent.put(std::move(areaJetsOut),"areaJets");
179  iEvent.put(std::move(etaJetsOut),"etaJets");
180 
181  return;
182 }
int i
Definition: DBlmapReader.cc:9
double calcMedian(std::vector< double > &v)
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:462
std::vector< double > etaRanges
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
vector< PseudoJet > jets
def move
Definition: eostools.py:510
unsigned int nExcl_
double calcMd(const reco::Jet *jet)
edm::EDGetTokenT< edm::View< reco::Jet > > jetsToken_
unsigned int nExcl2_

Member Data Documentation

bool HiFJRhoProducer::checkJetCand
private

Definition at line 55 of file HiFJRhoProducer.h.

Referenced by isPackedCandidate().

double HiFJRhoProducer::etaMaxExcl2_
private

Definition at line 52 of file HiFJRhoProducer.h.

Referenced by produce().

double HiFJRhoProducer::etaMaxExcl_
private

Definition at line 49 of file HiFJRhoProducer.h.

Referenced by produce().

std::vector<double> HiFJRhoProducer::etaRanges
private

Definition at line 54 of file HiFJRhoProducer.h.

Referenced by HiFJRhoProducer(), and produce().

edm::EDGetTokenT<edm::View<reco::Jet> > HiFJRhoProducer::jetsToken_
private

Definition at line 44 of file HiFJRhoProducer.h.

Referenced by HiFJRhoProducer(), and produce().

unsigned int HiFJRhoProducer::nExcl2_
private

Definition at line 51 of file HiFJRhoProducer.h.

Referenced by produce().

unsigned int HiFJRhoProducer::nExcl_
private

Definition at line 48 of file HiFJRhoProducer.h.

Referenced by produce().

double HiFJRhoProducer::ptMinExcl2_
private

Definition at line 53 of file HiFJRhoProducer.h.

Referenced by produce().

double HiFJRhoProducer::ptMinExcl_
private

Definition at line 50 of file HiFJRhoProducer.h.

Referenced by produce().

edm::InputTag HiFJRhoProducer::src_
private

Definition at line 47 of file HiFJRhoProducer.h.

Referenced by HiFJRhoProducer().

bool HiFJRhoProducer::usingPackedCand
private

Definition at line 55 of file HiFJRhoProducer.h.

Referenced by isPackedCandidate().