Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:26:15

0001 #include "RPCCluster.h"
0002 #include <iostream>
0003 #include <fstream>
0004 #include <cmath>
0005 
0006 using namespace std;
0007 
0008 RPCCluster::RPCCluster()
0009     : fstrip(0), lstrip(0), bunchx(0), sumTime(0), sumTime2(0), nTime(0), sumY(0), sumY2(0), nY(0) {}
0010 
0011 RPCCluster::RPCCluster(int fs, int ls, int bx)
0012     : fstrip(fs), lstrip(ls), bunchx(bx), sumTime(0), sumTime2(0), nTime(0), sumY(0), sumY2(0), nY(0) {}
0013 
0014 RPCCluster::~RPCCluster() {}
0015 
0016 int RPCCluster::firstStrip() const { return fstrip; }
0017 int RPCCluster::lastStrip() const { return lstrip; }
0018 int RPCCluster::clusterSize() const { return lstrip - fstrip + 1; }
0019 int RPCCluster::bx() const { return bunchx; }
0020 
0021 bool RPCCluster::hasTime() const { return nTime > 0; }
0022 float RPCCluster::time() const { return hasTime() ? sumTime / nTime : 0; }
0023 float RPCCluster::timeRMS() const {
0024   return hasTime() ? sqrt(max(0.F, sumTime2 * nTime - sumTime * sumTime)) / nTime : -1;
0025 }
0026 
0027 bool RPCCluster::hasY() const { return nY > 0; }
0028 float RPCCluster::y() const { return hasY() ? sumY / nY : 0; }
0029 float RPCCluster::yRMS() const { return hasY() ? sqrt(max(0.F, sumY2 * nY - sumY * sumY)) / nY : -1; }
0030 
0031 bool RPCCluster::isAdjacent(const RPCCluster& cl) const {
0032   return ((cl.firstStrip() == this->firstStrip() - 1) && (cl.bx() == this->bx()));
0033 }
0034 
0035 void RPCCluster::addTime(const float time) {
0036   ++nTime;
0037   sumTime += time;
0038   sumTime2 += time * time;
0039 }
0040 
0041 void RPCCluster::addY(const float y) {
0042   ++nY;
0043   sumY += y;
0044   sumY2 += y * y;
0045 }
0046 
0047 void RPCCluster::merge(const RPCCluster& cl) {
0048   if (!this->isAdjacent(cl))
0049     return;
0050 
0051   fstrip = cl.firstStrip();
0052 
0053   nTime += cl.nTime;
0054   sumTime += cl.sumTime;
0055   sumTime2 += cl.sumTime2;
0056 
0057   nY += cl.nY;
0058   sumY += cl.sumY;
0059   sumY2 += cl.sumY2;
0060 }
0061 
0062 bool RPCCluster::operator<(const RPCCluster& cl) const {
0063   if (cl.bx() == this->bx())
0064     return cl.firstStrip() < this->firstStrip();
0065 
0066   return cl.bx() < this->bx();
0067 }
0068 
0069 bool RPCCluster::operator==(const RPCCluster& cl) const {
0070   return ((this->clusterSize() == cl.clusterSize()) && (this->bx() == cl.bx()) &&
0071           (this->firstStrip() == cl.firstStrip()));
0072 }