File indexing completed on 2024-04-06 12:08:38
0001 #include <vector>
0002 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
0003 #include "DQM/SiStripCommon/interface/APVShot.h"
0004 #include "FWCore/Utilities/interface/Exception.h"
0005 #include <algorithm>
0006
0007 APVShot::APVShot() : _zs(true), _apv(-1), _nstrips(0), _median(-1), _detid() {}
0008
0009 APVShot::APVShot(const bool zs) : _zs(zs), _apv(-1), _nstrips(0), _median(-1), _detid() {}
0010
0011 APVShot::APVShot(const std::vector<SiStripDigi>& digis, const DetId& detid, const bool zs)
0012 : _zs(zs), _apv(-1), _nstrips(0), _median(-1), _detid() {
0013 computeShot(digis, detid, zs);
0014 }
0015
0016 void APVShot::computeShot(const std::vector<SiStripDigi>& digis, const DetId& detid, const bool zs) {
0017 _zs = zs;
0018 _detid = detid;
0019
0020 _nstrips = 0;
0021 _apv = -1;
0022 _median = -1;
0023
0024 std::vector<unsigned int> charge;
0025 for (std::vector<SiStripDigi>::const_iterator digi = digis.begin(); digi != digis.end(); ++digi) {
0026 if (!_zs || digi->adc() > 0) {
0027 int oldapv = _apv;
0028 _apv = digi->strip() / 128;
0029 if (oldapv >= 0 && oldapv != _apv)
0030 throw cms::Exception("WrongDigiVector") << "Digis from Different APVs";
0031
0032 charge.push_back(digi->adc());
0033 ++_nstrips;
0034 }
0035 }
0036
0037
0038
0039 std::sort(charge.begin(), charge.end());
0040 std::reverse(charge.begin(), charge.end());
0041
0042 if (charge.size() > 64) {
0043 _median = float(charge[64]);
0044 }
0045 }
0046
0047 const bool APVShot::isGenuine() const { return (_nstrips > _threshold); }
0048
0049 const int APVShot::apvNumber() const { return _apv; }
0050
0051 const int APVShot::nStrips() const { return _nstrips; }
0052
0053 const float APVShot::median() const { return _median; }
0054
0055 const int APVShot::subDet() const { return _detid.subdetId(); }
0056
0057 const unsigned int APVShot::detId() const { return _detid.rawId(); }
0058
0059 const int APVShot::_threshold = 64;