CMS 3D CMS Logo

PFClusterProducerFromHGC3DClusters.cc
Go to the documentation of this file.
1 #include <memory>
2 
8 
15 
16 namespace l1tpf {
18  public:
21 
22  private:
24 
27  bool emOnly_;
28  double etCut_;
31  bool hasEmId_;
34 
35  void produce(edm::Event &, const edm::EventSetup &) override;
36 
37  }; // class
38 } // namespace l1tpf
39 
41  : src_(consumes<l1t::HGCalMulticlusterBxCollection>(iConfig.getParameter<edm::InputTag>("src"))),
42  scenario_(UseEmInterp::No),
43  emOnly_(iConfig.getParameter<bool>("emOnly")),
44  etCut_(iConfig.getParameter<double>("etMin")),
45  preEmId_(iConfig.getParameter<std::string>("preEmId")),
46  emVsPionID_(iConfig.getParameter<edm::ParameterSet>("emVsPionID")),
47  emVsPUID_(iConfig.getParameter<edm::ParameterSet>("emVsPUID")),
48  hasEmId_((iConfig.existsAs<std::string>("preEmId") && !iConfig.getParameter<std::string>("preEmId").empty()) ||
49  !emVsPionID_.method().empty()),
50  corrector_(iConfig.getParameter<std::string>("corrector"),
51  emOnly_ || iConfig.getParameter<std::string>("corrector").empty()
52  ? -1
53  : iConfig.getParameter<double>("correctorEmfMax")),
54  resol_(iConfig.getParameter<edm::ParameterSet>("resol")) {
55  if (!emVsPionID_.method().empty()) {
57  }
58  if (!emVsPUID_.method().empty()) {
60  }
61 
62  produces<l1t::PFClusterCollection>();
63  produces<l1t::PFClusterCollection>("egamma");
64  if (hasEmId_) {
65  produces<l1t::PFClusterCollection>("em");
66  produces<l1t::PFClusterCollection>("had");
67  }
68 
69  std::string scenario = iConfig.getParameter<std::string>("useEMInterpretation");
70  if (scenario == "emOnly") {
72  } else if (scenario == "allKeepHad") {
74  if (emOnly_) {
75  throw cms::Exception("Configuration", "Unsupported emOnly = True when useEMInterpretation is " + scenario);
76  }
77  } else if (scenario == "allKeepTot") {
79  if (emOnly_) {
80  throw cms::Exception("Configuration", "Unsupported emOnly = True when useEMInterpretation is " + scenario);
81  }
82  } else if (scenario != "no") {
83  throw cms::Exception("Configuration", "Unsupported useEMInterpretation scenario " + scenario);
84  }
85 }
86 
88  auto out = std::make_unique<l1t::PFClusterCollection>();
89  auto outEgamma = std::make_unique<l1t::PFClusterCollection>();
90  std::unique_ptr<l1t::PFClusterCollection> outEm, outHad;
91  if (hasEmId_) {
92  outEm = std::make_unique<l1t::PFClusterCollection>();
93  outHad = std::make_unique<l1t::PFClusterCollection>();
94  }
96  iEvent.getByToken(src_, multiclusters);
97 
98  for (auto it = multiclusters->begin(0), ed = multiclusters->end(0); it != ed; ++it) {
99  float pt = it->pt(), hoe = it->hOverE();
100  bool isEM = hasEmId_ ? preEmId_(*it) : emOnly_;
101  if (emOnly_) {
102  if (hoe == -1)
103  continue;
104  pt /= (1 + hoe);
105  hoe = 0;
106  }
107  if (pt <= etCut_)
108  continue;
109 
110  // this block below is to support the older EG emulators, and is not used in newer ones
111  if (it->hwQual()) { // this is the EG ID shipped with the HGC TPs
112  // we use the EM interpretation of the cluster energy
113  l1t::PFCluster egcluster(
114  it->iPt(l1t::HGCalMulticluster::EnergyInterpretation::EM), it->eta(), it->phi(), hoe, false);
115  egcluster.setHwQual(it->hwQual());
116  egcluster.addConstituent(edm::Ptr<l1t::L1Candidate>(multiclusters, multiclusters->key(it)));
117  outEgamma->push_back(egcluster);
118  }
119 
120  l1t::PFCluster cluster(pt, it->eta(), it->phi(), hoe);
121  if (scenario_ == UseEmInterp::EmOnly) { // for emID objs, use EM interp as pT and set H = 0
122  if (isEM) {
123  float pt_new = it->iPt(l1t::HGCalMulticluster::EnergyInterpretation::EM);
124  float hoe_new = 0.;
125  cluster = l1t::PFCluster(pt_new, it->eta(), it->phi(), hoe_new, /*isEM=*/isEM);
126  }
127  } else if (scenario_ == UseEmInterp::AllKeepHad) { // for all objs, replace EM part with EM interp, preserve H
128  float had_old = pt - cluster.emEt();
129  //float em_old = cluster.emEt();
130  float em_new = it->iPt(l1t::HGCalMulticluster::EnergyInterpretation::EM);
131  float pt_new = had_old + em_new;
132  float hoe_new = em_new > 0 ? (had_old / em_new) : -1;
133  cluster = l1t::PFCluster(pt_new, it->eta(), it->phi(), hoe_new, /*isEM=*/isEM);
134  //printf("Scenario %d: pt %7.2f eta %+5.3f em %7.2f, EMI %7.2f, h/e % 8.3f --> pt %7.2f, em %7.2f, h/e % 8.3f\n",
135  // 2, pt, it->eta(), em_old, em_new, hoe, cluster.pt(), cluster.emEt(), cluster.hOverE());
136  } else if (scenario_ == UseEmInterp::AllKeepTot) { // for all objs, replace EM part with EM interp, preserve pT
137  //float em_old = cluster.emEt();
138  float em_new = it->iPt(l1t::HGCalMulticluster::EnergyInterpretation::EM);
139  float hoe_new = em_new > 0 ? (it->pt() / em_new - 1) : -1;
140  cluster = l1t::PFCluster(it->pt(), it->eta(), it->phi(), hoe_new, /*isEM=*/isEM);
141  //printf("Scenario %d: pt %7.2f eta %+5.3f em %7.2f, EMI %7.2f, h/e % 8.3f --> pt %7.2f, em %7.2f, h/e % 8.3f\n",
142  // 3, pt, it->eta(), em_old, em_new, hoe, cluster.pt(), cluster.emEt(), cluster.hOverE());
143  }
144 
145  if (!emVsPUID_.method().empty()) {
146  if (!emVsPUID_.passID(*it, cluster)) {
147  continue;
148  }
149  }
150  if (!emOnly_ && !emVsPionID_.method().empty()) {
151  isEM = emVsPionID_.passID(*it, cluster);
152  }
153  cluster.setHwQual((isEM ? 1 : 0) + (it->hwQual() << 1));
154 
155  if (corrector_.valid())
156  corrector_.correctPt(cluster);
157  cluster.setPtError(resol_(cluster.pt(), std::abs(cluster.eta())));
158 
159  out->push_back(cluster);
160  out->back().addConstituent(edm::Ptr<l1t::L1Candidate>(multiclusters, multiclusters->key(it)));
161  if (hasEmId_) {
162  (isEM ? outEm : outHad)->push_back(out->back());
163  }
164  }
165 
166  iEvent.put(std::move(out));
167  iEvent.put(std::move(outEgamma), "egamma");
168  if (hasEmId_) {
169  iEvent.put(std::move(outEm), "em");
170  iEvent.put(std::move(outHad), "had");
171  }
172 }
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
unsigned int key(const_iterator &iter) const
Definition: BXVector.h:101
void setHwQual(int qual)
Definition: L1Candidate.h:31
delete x;
Definition: CaloConfig.h:22
scenario
Definition: constants.h:173
const_iterator begin(int bx) const
int iEvent
Definition: GenABIO.cc:224
BXVector< HGCalMulticluster > HGCalMulticlusterBxCollection
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< l1t::HGCalMulticlusterBxCollection > src_
deadvectors [0] push_back({0.0175431, 0.538005, 6.80997, 13.29})
const_iterator end(int bx) const
HLT enums.
void produce(edm::Event &, const edm::EventSetup &) override
StringCutObjectSelector< l1t::HGCalMulticluster > preEmId_
def move(src, dest)
Definition: eostools.py:511