CMS 3D CMS Logo

ParticleTowerProducer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: RecoHI/HiJetAlgos
4 // Class: ParticleTowerProducer
5 //
11 //
12 // Original Author: Yetkin Yilmaz,32 4-A08,+41227673039,
13 // Created: Thu Jan 20 19:53:58 CET 2011
14 //
15 //
16 
39 
40 #include <cmath>
41 #include <cstdlib>
42 #include <memory>
43 #include <string>
44 #include <vector>
45 #include <map>
46 #include <utility>
47 
48 template <class T>
50 public:
52  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
53 
54 private:
55  void produce(edm::Event&, const edm::EventSetup&) override;
56  int eta2ieta(double eta) const;
57  int phi2iphi(double phi, int ieta) const;
58  double ieta2eta(int ieta) const;
59  double iphi2phi(int iphi, int ieta) const;
60  // ----------member data ---------------------------
61 
63  const bool useHF_;
64 
65  // tower edges from fast sim, used starting at index 30 for the HF
66  static constexpr int ietaMax = 42;
67 };
68 //
69 // constructors and destructor
70 //
71 template <class T>
73  : src_(consumes<typename edm::View<T> >(iConfig.getParameter<edm::InputTag>("src"))),
74  useHF_(iConfig.getParameter<bool>("useHF")) {
75  produces<CaloTowerCollection>();
76 }
77 
78 //
79 // member functions
80 //
81 
82 // ------------ method called to produce the data ------------
83 template <class T>
85  using namespace edm;
86 
87  typedef std::pair<int, int> EtaPhi;
88  typedef std::map<EtaPhi, double> EtaPhiMap;
89  EtaPhiMap towers_;
90  towers_.clear();
91 
92  auto const& inputs = iEvent.get(src_);
93  for (auto const& particle : inputs) {
94  double eta = particle.eta();
95 
96  int ieta = eta2ieta(eta);
97  int iphi = phi2iphi(particle.phi(), ieta);
98 
99  if (!useHF_ && abs(ieta) > 29)
100  continue;
101 
102  EtaPhi ep(ieta, iphi);
103  towers_[ep] += particle.et();
104  }
105 
106  auto prod = std::make_unique<CaloTowerCollection>();
107  prod->reserve(towers_.size());
108  for (auto const& tower : towers_) {
109  EtaPhi ep = tower.first;
110  double et = tower.second;
111 
112  int ieta = ep.first;
113  int iphi = ep.second;
114 
115  CaloTowerDetId newTowerId(ieta, iphi); // totally dummy id
116 
117  // currently sets et = pt, mass to zero
118  // pt, eta, phi, mass
119  reco::Particle::PolarLorentzVector p4(et, ieta2eta(ieta), iphi2phi(iphi, ieta), 0.);
120  GlobalPoint point(p4.x(), p4.y(), p4.z());
121  prod->emplace_back(newTowerId, p4.e(), 0, 0, 0, 0, p4, point, point);
122  }
123 
124  iEvent.put(std::move(prod));
125 }
126 
127 // Taken from FastSimulation/CalorimeterProperties/src/HCALProperties.cc
128 // Note this returns an abs(ieta)
129 template <class T>
131  // binary search in the array of towers eta edges
132 
133  int ieta = 1;
134  double xeta = fabs(eta);
135  while (xeta > hi::etaedge[ieta] && ieta < ietaMax - 1) {
136  ++ieta;
137  }
138 
139  if (eta < 0)
140  ieta = -ieta;
141  return ieta;
142 }
143 
144 template <class T>
147  int nphi = 72;
148  int n = 1;
149  if (abs(ieta) > 20)
150  n = 2;
151  if (abs(ieta) >= 40)
152  n = 4;
153 
154  int iphi = (int)std::ceil(phi / 2.0 / M_PI * nphi / n);
155 
156  iphi = n * (iphi - 1) + 1;
157 
158  return iphi;
159 }
160 
161 template <class T>
163  double phi = 0;
164  int nphi = 72;
165 
166  int n = 1;
167  if (abs(ieta) > 20)
168  n = 2;
169  if (abs(ieta) >= 40)
170  n = 4;
171 
172  int myphi = (iphi - 1) / n + 1;
173 
174  phi = 2. * M_PI * (myphi - 0.5) / nphi * n;
175  while (phi > M_PI)
176  phi -= 2. * M_PI;
177 
178  return phi;
179 }
180 
181 template <class T>
183  int sign = 1;
184  if (ieta < 0) {
185  sign = -1;
186  ieta = -ieta;
187  }
188 
189  double eta = sign * (hi::etaedge[ieta] + hi::etaedge[ieta - 1]) / 2.;
190  return eta;
191 }
192 
193 template <class T>
196  desc.add<bool>("useHF", true);
197  if (typeid(T) == typeid(reco::PFCandidate)) {
198  desc.add<edm::InputTag>("src", edm::InputTag("particleFlow"));
199  descriptions.add("PFTowers", desc);
200  }
201  if (typeid(T) == typeid(pat::PackedCandidate)) {
202  desc.add<edm::InputTag>("src", edm::InputTag("packedPFCandidates"));
203  descriptions.add("PackedPFTowers", desc);
204  }
205 }
206 
209 
210 // define this as a plug-in
double iphi2phi(int iphi, int ieta) const
const int nphi
constexpr int32_t ceil(float num)
ParticleTowerProducer(const edm::ParameterSet &)
static constexpr int ietaMax
int eta2ieta(double eta) const
int iEvent
Definition: GenABIO.cc:224
edm::EDGetTokenT< typename edm::View< T > > src_
ParticleTowerProducer< reco::PFCandidate > PFTowers
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
#define M_PI
ParticleTowerProducer< pat::PackedCandidate > PackedPFTowers
void produce(edm::Event &, const edm::EventSetup &) override
constexpr valType make0To2pi(valType angle)
Definition: deltaPhi.h:67
void add(std::string const &label, ParameterSetDescription const &psetDescription)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
HLT enums.
int phi2iphi(double phi, int ieta) const
math::PtEtaPhiMLorentzVector PolarLorentzVector
Lorentz vector.
Definition: Particle.h:23
double ieta2eta(int ieta) const
long double T
constexpr std::array< double, 42 > etaedge
Definition: HITowerHelper.h:5
def move(src, dest)
Definition: eostools.py:511
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5