CMS 3D CMS Logo

SimplePlan1RechitCombiner.cc
Go to the documentation of this file.
1 #include <cassert>
2 #include <algorithm>
3 
7 
9 
11 
13 
15 
17 
19 
22  rechitMap_.push_back(MapItem(mapRechit(rh.id()), &rh));
23 }
24 
26  if (!rechitMap_.empty()) {
27  std::sort(rechitMap_.begin(), rechitMap_.end());
28 
29  HcalDetId oldId(rechitMap_[0].first);
30  ptrbuf_.clear();
31  ptrbuf_.push_back(rechitMap_[0].second);
32 
33  const std::size_t nInput = rechitMap_.size();
34  for (std::size_t i = 1; i < nInput; ++i) {
35  if (rechitMap_[i].first != oldId) {
36  const HBHERecHit& rh = makeRechit(oldId, ptrbuf_);
37  if (rh.id().rawId())
38  toFill->push_back(rh);
39  oldId = rechitMap_[i].first;
40  ptrbuf_.clear();
41  }
42  ptrbuf_.push_back(rechitMap_[i].second);
43  }
44 
45  const HBHERecHit& rh = makeRechit(oldId, ptrbuf_);
46  if (rh.id().rawId())
47  toFill->push_back(rh);
48  }
49 }
50 
52 
54  const std::vector<const HBHERecHit*>& rechits) const {
55  constexpr unsigned MAXLEN = 8U; // Should be >= max # of Phase 1 HCAL depths
56  constexpr float TIME_IF_NO_ENERGY = -999.f;
57 
58  const unsigned nRecHits = rechits.size();
59  assert(nRecHits);
60  assert(nRecHits <= MAXLEN);
61 
62  // Combine energies, times, and fit chi-square
63  double energy = 0.0, eraw = 0.0, eaux = 0.0, chisq = 0.0;
64  FPair times[MAXLEN], adctimes[MAXLEN];
65  unsigned nADCTimes = 0;
66 
67  for (unsigned i = 0; i < nRecHits; ++i) {
68  const HBHERecHit& rh(*rechits[i]);
69  const float e = rh.energy();
70  energy += e;
71  eraw += rh.eraw();
72  eaux += rh.eaux();
73  chisq += rh.chi2();
74  times[i].first = rh.time();
75  times[i].second = e;
76 
77  const float tADC = rh.timeFalling();
78  if (!HcalSpecialTimes::isSpecial(tADC)) {
79  adctimes[nADCTimes].first = tADC;
80  adctimes[nADCTimes].second = e;
81  ++nADCTimes;
82  }
83  }
84 
85  HBHERecHit rh(idToMake,
86  energy,
87  energyWeightedAverage(times, nRecHits, TIME_IF_NO_ENERGY),
89  rh.setRawEnergy(eraw);
90  rh.setAuxEnergy(eaux);
91  rh.setChiSquared(chisq);
92 
93  // Combine the auxiliary information
94  combineAuxInfo(rechits, &rh);
95 
96  return rh;
97 }
98 
99 void SimplePlan1RechitCombiner::combineAuxInfo(const std::vector<const HBHERecHit*>& rechits, HBHERecHit* rh) const {
100  using namespace CaloRecHitAuxSetter;
101  using namespace HcalPhase1FlagLabels;
102 
103  // The number of rechits should be not larger than the
104  // number of half-bytes in a 32-bit word
105  constexpr unsigned MAXLEN = 8U;
106 
107  const unsigned nRecHits = rechits.size();
108  assert(nRecHits);
109  assert(nRecHits <= MAXLEN);
110 
111  uint32_t flags = 0, auxPhase1 = 0;
112  unsigned tripleFitCount = 0;
113  unsigned soiVote[HBHERecHitAuxSetter::MASK_SOI + 1U] = {0};
114  unsigned capidVote[HBHERecHitAuxSetter::MASK_CAPID + 1U] = {0};
115 
116  // Combine various status bits
117  for (unsigned i = 0; i < nRecHits; ++i) {
118  const HBHERecHit& rh(*rechits[i]);
119  const uint32_t rhflags = rh.flags();
120  const uint32_t rhAuxPhase1 = rh.auxPhase1();
121 
124 
125  const unsigned soi = getField(rhAuxPhase1, HBHERecHitAuxSetter::MASK_SOI, HBHERecHitAuxSetter::OFF_SOI);
126  soiVote[soi]++;
127 
128  const unsigned capid = getField(rhAuxPhase1, HBHERecHitAuxSetter::MASK_CAPID, HBHERecHitAuxSetter::OFF_CAPID);
129  capidVote[capid]++;
130 
132  ++tripleFitCount;
133 
134  // Status flags are simply ORed for now. Might want
135  // to rethink this in the future.
136  flags |= rhflags;
137  }
138 
139  unsigned* pmaxsoi = std::max_element(soiVote, soiVote + sizeof(soiVote) / sizeof(soiVote[0]));
140  const unsigned soi = std::distance(&soiVote[0], pmaxsoi);
142 
143  unsigned* pmaxcapid = std::max_element(capidVote, capidVote + sizeof(capidVote) / sizeof(capidVote[0]));
144  const unsigned capid = std::distance(&capidVote[0], pmaxcapid);
146 
147  // A number that can be later used to calculate chi-square NDoF
149 
150  // How many rechits were combined?
152 
153  // Should combine QIE11 data only
154  setBit(&auxPhase1, HBHERecHitAuxSetter::OFF_TDC_TIME, true);
155 
156  // Indicate that this rechit is combined
157  setBit(&auxPhase1, HBHERecHitAuxSetter::OFF_COMBINED, true);
158 
159  // Copy the aux words into the rechit
160  rh->setFlags(flags);
161  rh->setAuxPhase1(auxPhase1);
162 
163  // Sort the depth values of the combined rechits
164  // in the increasing order
165  unsigned depthValues[MAXLEN];
166  for (unsigned i = 0; i < nRecHits; ++i)
167  depthValues[i] = rechits[i]->id().depth();
168  if (nRecHits > 1U)
169  std::sort(depthValues, depthValues + nRecHits);
170 
171  // Pack the information about the depth of the rechits
172  // that we are combining into the "auxHBHE" word
173  uint32_t auxHBHE = 0;
174  for (unsigned i = 0; i < nRecHits; ++i)
175  setField(&auxHBHE, 0xf, i * 4, depthValues[i]);
176  rh->setAuxHBHE(auxHBHE);
177 }
HBHERecHitAuxSetter::MASK_CAPID
static const unsigned MASK_CAPID
Definition: HBHERecHitAuxSetter.h:31
CaloRecHitAuxSetter::setField
constexpr void setField(uint32_t *u, const unsigned mask, const unsigned offset, const unsigned value)
Definition: CaloRecHitAuxSetter.h:8
HBHERecHitAuxSetter::OFF_COMBINED
static const unsigned OFF_COMBINED
Definition: HBHERecHitAuxSetter.h:41
mps_fire.i
i
Definition: mps_fire.py:355
SimplePlan1RechitCombiner::combine
void combine(HBHERecHitCollection *toFill) override
Definition: SimplePlan1RechitCombiner.cc:25
HcalSpecialTimes::isSpecial
constexpr bool isSpecial(const float t)
Definition: HcalSpecialTimes.h:53
CaloRecHit::energy
constexpr float energy() const
Definition: CaloRecHit.h:29
HBHERecHit::setAuxEnergy
constexpr void setAuxEnergy(const float en)
Definition: HBHERecHit.h:47
HBHERecHit::eraw
constexpr float eraw() const
Definition: HBHERecHit.h:45
CaloRecHitAuxSetter::orBit
constexpr void orBit(uint32_t *u, const unsigned bitnum, const bool b)
Definition: CaloRecHitAuxSetter.h:25
HcalSpecialTimes.h
HBHERecHit
Definition: HBHERecHit.h:13
SimplePlan1RechitCombiner.h
HcalTopology
Definition: HcalTopology.h:26
HBHERecHitAuxSetter.h
cms::cuda::assert
assert(be >=bs)
HLT_2018_cff.distance
distance
Definition: HLT_2018_cff.py:6417
HBHERecHitAuxSetter::OFF_CAPID_ERR
static const unsigned OFF_CAPID_ERR
Definition: HBHERecHitAuxSetter.h:38
edm::SortedCollection
Definition: SortedCollection.h:49
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:215
HBHERecHitAuxSetter::OFF_TDC_TIME
static const unsigned OFF_TDC_TIME
Definition: HBHERecHitAuxSetter.h:35
HcalPhase1FlagLabels.h
AbsPlan1RechitCombiner::FPair
std::pair< float, float > FPair
Definition: AbsPlan1RechitCombiner.h:35
HBHERecHit::chi2
constexpr float chi2() const
Definition: HBHERecHit.h:42
getBit
bool getBit(int &_bitArray, unsigned _iBit)
Definition: EcalCondDBWriter.cc:17
HcalTopology::mergedDepthDetId
HcalDetId mergedDepthDetId(const HcalDetId &id) const
Definition: HcalTopology.h:166
HBHERecHitAuxSetter::OFF_DROPPED
static const unsigned OFF_DROPPED
Definition: HBHERecHitAuxSetter.h:36
HBHERecHit::timeFalling
constexpr float timeFalling() const
get the hit falling time
Definition: HBHERecHit.h:36
SimplePlan1RechitCombiner::makeRechit
virtual HBHERecHit makeRechit(HcalDetId idToMake, const std::vector< const HBHERecHit * > &rechits) const
Definition: SimplePlan1RechitCombiner.cc:53
edm::SortedCollection::push_back
void push_back(T const &t)
Definition: SortedCollection.h:188
dqmdumpme.first
first
Definition: dqmdumpme.py:55
HBHERecHitAuxSetter::OFF_CAPID
static const unsigned OFF_CAPID
Definition: HBHERecHitAuxSetter.h:32
HBHERecHitAuxSetter::MASK_NSAMPLES
static const unsigned MASK_NSAMPLES
Definition: HBHERecHitAuxSetter.h:23
HBHERecHit::setAuxHBHE
constexpr void setAuxHBHE(const uint32_t aux)
Definition: HBHERecHit.h:50
SimplePlan1RechitCombiner::rechitMap_
std::vector< MapItem > rechitMap_
Definition: SimplePlan1RechitCombiner.h:35
SimplePlan1RechitCombiner::ptrbuf_
std::vector< const HBHERecHit * > ptrbuf_
Definition: SimplePlan1RechitCombiner.h:36
SimplePlan1RechitCombiner::clear
void clear() override
Definition: SimplePlan1RechitCombiner.cc:18
setBit
void setBit(int &_bitArray, unsigned _iBit)
Definition: EcalCondDBWriter.cc:15
AbsPlan1RechitCombiner::energyWeightedAverage
static float energyWeightedAverage(const FPair *data, unsigned len, float valueToReturnOnFailure)
Definition: AbsPlan1RechitCombiner.cc:3
HcalSpecialTimes::UNKNOWN_T_NOTDC
constexpr float UNKNOWN_T_NOTDC
Definition: HcalSpecialTimes.h:42
SimplePlan1RechitCombiner::mapRechit
virtual HcalDetId mapRechit(HcalDetId from) const
Definition: SimplePlan1RechitCombiner.cc:51
HCALHighEnergyHPDFilter_cfi.energy
energy
Definition: HCALHighEnergyHPDFilter_cfi.py:5
HBHERecHitAuxSetter::MASK_SOI
static const unsigned MASK_SOI
Definition: HBHERecHitAuxSetter.h:27
CaloRecHitAuxSetter::getField
constexpr unsigned getField(const uint32_t u, const unsigned mask, const unsigned offset)
Definition: CaloRecHitAuxSetter.h:13
mitigatedMETSequence_cff.U
U
Definition: mitigatedMETSequence_cff.py:36
CaloRecHit::time
constexpr float time() const
Definition: CaloRecHit.h:31
HBHERecHit::setChiSquared
constexpr void setChiSquared(const float chi2)
Definition: HBHERecHit.h:41
HBHERecHit::setRawEnergy
constexpr void setRawEnergy(const float en)
Definition: HBHERecHit.h:44
SimplePlan1RechitCombiner::combineAuxInfo
virtual void combineAuxInfo(const std::vector< const HBHERecHit * > &rechits, HBHERecHit *rh) const
Definition: SimplePlan1RechitCombiner.cc:99
TrackInfoProducer_cfi.rechits
rechits
Definition: TrackInfoProducer_cfi.py:9
CaloRecHit::setFlags
constexpr void setFlags(uint32_t flags)
Definition: CaloRecHit.h:35
HcalDetId
Definition: HcalDetId.h:12
SimplePlan1RechitCombiner::topo_
const HcalTopology * topo_
Definition: SimplePlan1RechitCombiner.h:28
HBHERecHit::auxPhase1
constexpr uint32_t auxPhase1() const
Definition: HBHERecHit.h:54
CaloRecHitAuxSetter::getBit
constexpr bool getBit(const uint32_t u, const unsigned bitnum)
Definition: CaloRecHitAuxSetter.h:37
HBHERecHitAuxSetter::OFF_ADC
static const unsigned OFF_ADC
Definition: HBHERecHitAuxSetter.h:20
SimplePlan1RechitCombiner::SimplePlan1RechitCombiner
SimplePlan1RechitCombiner()
Definition: SimplePlan1RechitCombiner.cc:14
HcalCaloFlagLabels::HBHEPulseFitBit
Definition: HcalCaloFlagLabels.h:27
HcalTopology.h
HcalPhase1FlagLabels
Definition: HcalPhase1FlagLabels.h:6
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
SimplePlan1RechitCombiner::MapItem
std::pair< HcalDetId, const HBHERecHit * > MapItem
Definition: SimplePlan1RechitCombiner.h:33
SimplePlan1RechitCombiner::add
void add(const HBHERecHit &rh) override
Definition: SimplePlan1RechitCombiner.cc:20
HBHERecHitAuxSetter::OFF_NSAMPLES
static const unsigned OFF_NSAMPLES
Definition: HBHERecHitAuxSetter.h:24
HBHERecHitAuxSetter::OFF_LINK_ERR
static const unsigned OFF_LINK_ERR
Definition: HBHERecHitAuxSetter.h:37
SimplePlan1RechitCombiner::setTopo
void setTopo(const HcalTopology *topo) override
Definition: SimplePlan1RechitCombiner.cc:16
HBHERecHit::id
constexpr HcalDetId id() const
get the id
Definition: HBHERecHit.h:39
HBHERecHitAuxSetter::OFF_SOI
static const unsigned OFF_SOI
Definition: HBHERecHitAuxSetter.h:28
HLT_2018_cff.flags
flags
Definition: HLT_2018_cff.py:11758
CaloRecHitAuxSetter.h
HBHERecHit::eaux
constexpr float eaux() const
Definition: HBHERecHit.h:48
CaloRecHitAuxSetter
Definition: CaloRecHitAuxSetter.h:7
CaloRecHit::flags
constexpr uint32_t flags() const
Definition: CaloRecHit.h:34
MillePedeFileConverter_cfg.e
e
Definition: MillePedeFileConverter_cfg.py:37
HBHERecHit::setAuxPhase1
constexpr void setAuxPhase1(const uint32_t aux)
Definition: HBHERecHit.h:53