CMS 3D CMS Logo

HLTJetTimingProducer.h
Go to the documentation of this file.
1 
7 #ifndef HLTrigger_JetMET_plugins_HLTJetTimingProducer_h
8 #define HLTrigger_JetMET_plugins_HLTJetTimingProducer_h
9 
10 #include <memory>
11 #include <cmath>
12 
26 
27 template <typename T>
29 public:
30  explicit HLTJetTimingProducer(const edm::ParameterSet&);
31  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
32 
33 private:
34  void produce(edm::Event&, const edm::EventSetup&) override;
35  void jetTimeFromEcalCells(const T&,
37  const CaloGeometry&,
38  float&,
39  float&,
40  uint&);
41 
43  // Input collections
47 
48  // Include barrel, endcap jets or both
49  const bool barrelJets_;
50  const bool endcapJets_;
51 
52  // Configurables for timing definition
53  const double ecalCellEnergyThresh_;
54  const double ecalCellTimeThresh_;
56  const double matchingRadius2_;
57 };
58 
59 template <typename T>
61  : caloGeometryToken_(esConsumes()),
62  jetInputToken_{consumes<std::vector<T>>(iConfig.getParameter<edm::InputTag>("jets"))},
63  ecalRecHitsEBToken_{consumes<edm::SortedCollection<EcalRecHit, edm::StrictWeakOrdering<EcalRecHit>>>(
64  iConfig.getParameter<edm::InputTag>("ebRecHitsColl"))},
65  ecalRecHitsEEToken_{consumes<edm::SortedCollection<EcalRecHit, edm::StrictWeakOrdering<EcalRecHit>>>(
66  iConfig.getParameter<edm::InputTag>("eeRecHitsColl"))},
67  barrelJets_{iConfig.getParameter<bool>("barrelJets")},
68  endcapJets_{iConfig.getParameter<bool>("endcapJets")},
69  ecalCellEnergyThresh_{iConfig.getParameter<double>("ecalCellEnergyThresh")},
70  ecalCellTimeThresh_{iConfig.getParameter<double>("ecalCellTimeThresh")},
71  ecalCellTimeErrorThresh_{iConfig.getParameter<double>("ecalCellTimeErrorThresh")},
72  matchingRadius2_{std::pow(iConfig.getParameter<double>("matchingRadius"), 2)} {
73  produces<edm::ValueMap<float>>("");
74  produces<edm::ValueMap<unsigned int>>("jetCellsForTiming");
75  produces<edm::ValueMap<float>>("jetEcalEtForTiming");
76 }
77 
78 template <typename T>
80  const T& jet,
82  const CaloGeometry& caloGeometry,
83  float& weightedTimeCell,
84  float& totalEmEnergyCell,
85  uint& nCells) {
86  for (auto const& ecalRH : ecalRecHits) {
87  if (ecalRH.checkFlag(EcalRecHit::kSaturated) || ecalRH.checkFlag(EcalRecHit::kLeadingEdgeRecovered) ||
88  ecalRH.checkFlag(EcalRecHit::kPoorReco) || ecalRH.checkFlag(EcalRecHit::kWeird) ||
89  ecalRH.checkFlag(EcalRecHit::kDiWeird))
90  continue;
91  if (ecalRH.energy() < ecalCellEnergyThresh_)
92  continue;
93  if (ecalRH.timeError() <= 0. || ecalRH.timeError() > ecalCellTimeErrorThresh_)
94  continue;
95  if (std::abs(ecalRH.time()) > ecalCellTimeThresh_)
96  continue;
97  auto const pos = caloGeometry.getPosition(ecalRH.detid());
98  if (reco::deltaR2(jet, pos) > matchingRadius2_)
99  continue;
100  weightedTimeCell += ecalRH.time() * ecalRH.energy() * sin(pos.theta());
101  totalEmEnergyCell += ecalRH.energy() * sin(pos.theta());
102  nCells++;
103  }
104  if (totalEmEnergyCell > 0) {
105  weightedTimeCell /= totalEmEnergyCell;
106  }
107 }
108 
109 template <typename T>
111  auto const& caloGeometry = iSetup.getData(caloGeometryToken_);
112  auto const jets = iEvent.getHandle(jetInputToken_);
113  auto const& ecalRecHitsEB = iEvent.get(ecalRecHitsEBToken_);
114  auto const& ecalRecHitsEE = iEvent.get(ecalRecHitsEEToken_);
115 
116  std::vector<float> jetTimings;
117  std::vector<unsigned int> jetCellsForTiming;
118  std::vector<float> jetEcalEtForTiming;
119 
120  jetTimings.reserve(jets->size());
121  jetEcalEtForTiming.reserve(jets->size());
122  jetCellsForTiming.reserve(jets->size());
123 
124  for (auto const& jet : *jets) {
125  float weightedTimeCell = 0;
126  float totalEmEnergyCell = 0;
127  unsigned int nCells = 0;
128  if (barrelJets_)
129  jetTimeFromEcalCells(jet, ecalRecHitsEB, caloGeometry, weightedTimeCell, totalEmEnergyCell, nCells);
130  if (endcapJets_) {
131  weightedTimeCell *= totalEmEnergyCell;
132  jetTimeFromEcalCells(jet, ecalRecHitsEE, caloGeometry, weightedTimeCell, totalEmEnergyCell, nCells);
133  }
134 
135  // If there is at least one ecal cell passing selection, calculate timing
136  jetTimings.emplace_back(totalEmEnergyCell > 0 ? weightedTimeCell : -50);
137  jetEcalEtForTiming.emplace_back(totalEmEnergyCell);
138  jetCellsForTiming.emplace_back(nCells);
139  }
140 
141  std::unique_ptr<edm::ValueMap<float>> jetTimings_out(new edm::ValueMap<float>());
142  edm::ValueMap<float>::Filler jetTimings_filler(*jetTimings_out);
143  jetTimings_filler.insert(jets, jetTimings.begin(), jetTimings.end());
144  jetTimings_filler.fill();
145  iEvent.put(std::move(jetTimings_out), "");
146 
147  std::unique_ptr<edm::ValueMap<float>> jetEcalEtForTiming_out(new edm::ValueMap<float>());
148  edm::ValueMap<float>::Filler jetEcalEtForTiming_filler(*jetEcalEtForTiming_out);
149  jetEcalEtForTiming_filler.insert(jets, jetEcalEtForTiming.begin(), jetEcalEtForTiming.end());
150  jetEcalEtForTiming_filler.fill();
151  iEvent.put(std::move(jetEcalEtForTiming_out), "jetEcalEtForTiming");
152 
153  std::unique_ptr<edm::ValueMap<unsigned int>> jetCellsForTiming_out(new edm::ValueMap<unsigned int>());
154  edm::ValueMap<unsigned int>::Filler jetCellsForTiming_filler(*jetCellsForTiming_out);
155  jetCellsForTiming_filler.insert(jets, jetCellsForTiming.begin(), jetCellsForTiming.end());
156  jetCellsForTiming_filler.fill();
157  iEvent.put(std::move(jetCellsForTiming_out), "jetCellsForTiming");
158 }
159 
160 template <typename T>
163  desc.add<edm::InputTag>("jets", edm::InputTag(""));
164  desc.add<bool>("barrelJets", false);
165  desc.add<bool>("endcapJets", false);
166  desc.add<double>("ecalCellEnergyThresh", 0.5);
167  desc.add<double>("ecalCellTimeThresh", 12.5);
168  desc.add<double>("ecalCellTimeErrorThresh", 100.);
169  desc.add<double>("matchingRadius", 0.4);
170  desc.add<edm::InputTag>("ebRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEB"));
171  desc.add<edm::InputTag>("eeRecHitsColl", edm::InputTag("hltEcalRecHit", "EcalRecHitsEE"));
173 }
174 
175 #endif // HLTrigger_JetMET_plugins_HLTJetTimingProducer_h
HLTJetTimingProducer(const edm::ParameterSet &)
const double ecalCellEnergyThresh_
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
const edm::ESGetToken< CaloGeometry, CaloGeometryRecord > caloGeometryToken_
const double ecalCellTimeThresh_
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
void insert(const H &h, I begin, I end)
Definition: ValueMap.h:53
const double ecalCellTimeErrorThresh_
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ uint32_t const *__restrict__ nCells
std::string defaultModuleLabel()
const edm::EDGetTokenT< edm::SortedCollection< EcalRecHit, edm::StrictWeakOrdering< EcalRecHit > > > ecalRecHitsEEToken_
const edm::EDGetTokenT< edm::SortedCollection< EcalRecHit, edm::StrictWeakOrdering< EcalRecHit > > > ecalRecHitsEBToken_
int iEvent
Definition: GenABIO.cc:224
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:50
const edm::EDGetTokenT< std::vector< T > > jetInputToken_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool getData(T &iHolder) const
Definition: EventSetup.h:122
constexpr auto deltaR2(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:16
void add(std::string const &label, ParameterSetDescription const &psetDescription)
This produces timing and associated ecal cell information for calo jets.
void produce(edm::Event &, const edm::EventSetup &) override
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
void jetTimeFromEcalCells(const T &, const edm::SortedCollection< EcalRecHit, edm::StrictWeakOrdering< EcalRecHit >> &, const CaloGeometry &, float &, float &, uint &)
long double T
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:29
def move(src, dest)
Definition: eostools.py:511