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 }
std::vector< MapItem > rechitMap_
std::vector< const HBHERecHit * > ptrbuf_
static const unsigned MASK_NSAMPLES
constexpr void orBit(uint32_t *u, const unsigned bitnum, const bool b)
constexpr void setField(uint32_t *u, const unsigned mask, const unsigned offset, const unsigned value)
constexpr float chi2() const
Definition: HBHERecHit.h:44
static const unsigned OFF_SOI
static const unsigned MASK_CAPID
void push_back(T const &t)
assert(be >=bs)
static const unsigned OFF_NSAMPLES
static const unsigned OFF_DROPPED
constexpr void setChiSquared(const float chi2)
Definition: HBHERecHit.h:43
constexpr float energy() const
Definition: CaloRecHit.h:29
constexpr void setAuxEnergy(const float en)
Definition: HBHERecHit.h:49
static const unsigned OFF_CAPID
constexpr void setAuxPhase1(const uint32_t aux)
Definition: HBHERecHit.h:55
U second(std::pair< T, U > const &p)
static const unsigned OFF_TDC_TIME
virtual HcalDetId mapRechit(HcalDetId from) const
constexpr float eaux() const
Definition: HBHERecHit.h:50
constexpr float timeFalling() const
get the hit falling time
Definition: HBHERecHit.h:38
static const unsigned OFF_CAPID_ERR
constexpr uint32_t flags() const
Definition: CaloRecHit.h:34
static float energyWeightedAverage(const FPair *data, unsigned len, float valueToReturnOnFailure)
static const unsigned OFF_LINK_ERR
constexpr float eraw() const
Definition: HBHERecHit.h:47
static const unsigned OFF_ADC
constexpr uint32_t auxPhase1() const
Definition: HBHERecHit.h:56
constexpr unsigned getField(const uint32_t u, const unsigned mask, const unsigned offset)
constexpr void setAuxHBHE(const uint32_t aux)
Definition: HBHERecHit.h:52
std::pair< HcalDetId, const HBHERecHit * > MapItem
static const unsigned MASK_SOI
std::pair< float, float > FPair
constexpr bool isSpecial(const float t)
void setBit(int &_bitArray, unsigned _iBit)
constexpr bool getBit(const uint32_t u, const unsigned bitnum)
constexpr HcalDetId id() const
get the id
Definition: HBHERecHit.h:41
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
constexpr float time() const
Definition: CaloRecHit.h:31
virtual HBHERecHit makeRechit(HcalDetId idToMake, const std::vector< const HBHERecHit *> &rechits) const
HcalDetId mergedDepthDetId(const HcalDetId &id) const
Definition: HcalTopology.h:166
constexpr float UNKNOWN_T_NOTDC
virtual void combineAuxInfo(const std::vector< const HBHERecHit *> &rechits, HBHERecHit *rh) const
static const unsigned OFF_COMBINED
void combine(HBHERecHitCollection *toFill) override
constexpr void setFlags(uint32_t flags)
Definition: CaloRecHit.h:35
bool getBit(int &_bitArray, unsigned _iBit)
constexpr void setRawEnergy(const float en)
Definition: HBHERecHit.h:46
void add(const HBHERecHit &rh) override
void setTopo(const HcalTopology *topo) override