Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:19

0001 #ifndef DATAFORMATS_HCALRECHIT_HFQIE10INFO_H
0002 #define DATAFORMATS_HCALRECHIT_HFQIE10INFO_H
0003 
0004 #include <limits>
0005 
0006 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
0007 #include "DataFormats/HcalDigi/interface/QIE10DataFrame.h"
0008 
0009 /** \class HFQIE10Info
0010 *
0011 * Class to contain the info needed to perform HF reconstruction
0012 * using QIE10 chips and dual-anode readout. Intended for use
0013 * inside HFPreRecHit.
0014 */
0015 class HFQIE10Info {
0016 public:
0017   typedef HcalDetId key_type;
0018   typedef QIE10DataFrame::Sample::wide_type raw_type;
0019 
0020   static const unsigned N_RAW_MAX = 5;
0021   static const raw_type INVALID_RAW = std::numeric_limits<raw_type>::max();
0022 
0023   constexpr HFQIE10Info()
0024       : charge_(0.f),
0025         energy_(0.f),
0026         timeRising_(0.f),
0027         timeFalling_(-1.f),
0028         raw_{INVALID_RAW, INVALID_RAW, INVALID_RAW, INVALID_RAW, INVALID_RAW},
0029         nRaw_(0),
0030         soi_(0) {}
0031 
0032   // Argument "soi" provides the index of the sample of interest
0033   // in the "rawData" array
0034   constexpr HFQIE10Info(const HcalDetId& id,
0035                         float charge,
0036                         float energy,
0037                         float timeRising,
0038                         float timeFalling,
0039                         const raw_type* rawData,
0040                         unsigned nData,
0041                         unsigned soi)
0042       : id_(id),
0043         charge_(charge),
0044         energy_(energy),
0045         timeRising_(timeRising),
0046         timeFalling_(timeFalling),
0047         raw_{INVALID_RAW, INVALID_RAW, INVALID_RAW, INVALID_RAW, INVALID_RAW},
0048         nRaw_(std::min(nData, N_RAW_MAX)),
0049         soi_(0) {
0050     if (nData) {
0051       unsigned tbegin = 0;
0052       if (soi >= nData) {
0053         // No SOI in the data. This situation is not normal
0054         // but can not be addressed in this code.
0055         if (nData > nRaw_)
0056           tbegin = nData - nRaw_;
0057         soi_ = nRaw_;
0058       } else {
0059         if (nData > nRaw_) {
0060           // Want to keep at least 2 presamples
0061           if (soi > 2U) {
0062             tbegin = soi - 2U;
0063             if (tbegin + nRaw_ > nData)
0064               tbegin = nData - nRaw_;
0065           }
0066         }
0067         soi_ = soi - tbegin;
0068       }
0069 
0070       raw_type* to = &raw_[0];
0071       const raw_type* from = rawData + tbegin;
0072       for (unsigned i = 0; i < nRaw_; ++i)
0073         *to++ = *from++;
0074     }
0075   }
0076 
0077   constexpr HcalDetId id() const { return id_; }
0078 
0079   constexpr float charge() const { return charge_; }
0080   constexpr float energy() const { return energy_; }
0081   constexpr float timeRising() const { return timeRising_; }
0082   constexpr float timeFalling() const { return timeFalling_; }
0083   constexpr unsigned nRaw() const { return nRaw_; }
0084   constexpr unsigned soi() const { return soi_; }
0085   constexpr raw_type getRaw(const unsigned which) const { return which >= nRaw_ ? INVALID_RAW : raw_[which]; }
0086 
0087   // Check whether the "ok" flag is set in the dataframe.
0088   //
0089   // If "checkAllTimeSlices" is "true" or if the raw data
0090   // does not contain the "sample of interest" time slice,
0091   // we are going to check all time slices. Otherwise only
0092   // the "sample of interest" time slice is checked.
0093   //
0094   bool isDataframeOK(bool checkAllTimeSlices = false) const {
0095     bool hardwareOK = true;
0096     if (soi_ >= nRaw_ || checkAllTimeSlices)
0097       for (unsigned i = 0; i < nRaw_ && hardwareOK; ++i) {
0098         const QIE10DataFrame::Sample s(raw_[i]);
0099         hardwareOK = s.ok();
0100       }
0101     else {
0102       const QIE10DataFrame::Sample s(raw_[soi_]);
0103       hardwareOK = s.ok();
0104     }
0105     return hardwareOK;
0106   }
0107 
0108 private:
0109   HcalDetId id_;
0110 
0111   float charge_;
0112   float energy_;
0113   float timeRising_;
0114   float timeFalling_;
0115   raw_type raw_[N_RAW_MAX];
0116   uint8_t nRaw_;
0117   uint8_t soi_;
0118 };
0119 
0120 #endif  // DATAFORMATS_HCALRECHIT_HFQIE10INFO_H