-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29603 from mileva/cppfClusterizerRefactoring
CPPF emulator refactoring
- Loading branch information
Showing
14 changed files
with
823 additions
and
435 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "CPPFCluster.h" | ||
#include <iostream> | ||
#include <fstream> | ||
#include <cmath> | ||
|
||
using namespace std; | ||
|
||
CPPFCluster::CPPFCluster() | ||
: fstrip(0), lstrip(0), bunchx(0), sumTime(0), sumTime2(0), nTime(0), sumY(0), sumY2(0), nY(0) {} | ||
|
||
CPPFCluster::CPPFCluster(int fs, int ls, int bx) | ||
: fstrip(fs), lstrip(ls), bunchx(bx), sumTime(0), sumTime2(0), nTime(0), sumY(0), sumY2(0), nY(0) {} | ||
|
||
CPPFCluster::~CPPFCluster() {} | ||
|
||
int CPPFCluster::firstStrip() const { return fstrip; } | ||
int CPPFCluster::lastStrip() const { return lstrip; } | ||
int CPPFCluster::clusterSize() const { return lstrip - fstrip + 1; } | ||
int CPPFCluster::bx() const { return bunchx; } | ||
|
||
bool CPPFCluster::hasTime() const { return nTime > 0; } | ||
float CPPFCluster::time() const { return hasTime() ? sumTime / nTime : 0; } | ||
float CPPFCluster::timeRMS() const { | ||
return hasTime() ? sqrt(max(0.F, sumTime2 * nTime - sumTime * sumTime)) / nTime : -1; | ||
} | ||
|
||
bool CPPFCluster::hasY() const { return nY > 0; } | ||
float CPPFCluster::y() const { return hasY() ? sumY / nY : 0; } | ||
float CPPFCluster::yRMS() const { return hasY() ? sqrt(max(0.F, sumY2 * nY - sumY * sumY)) / nY : -1; } | ||
|
||
bool CPPFCluster::isAdjacent(const CPPFCluster& cl) const { | ||
return ((cl.firstStrip() == this->firstStrip() - 1) && (cl.bx() == this->bx())); | ||
} | ||
|
||
void CPPFCluster::addTime(const float time) { | ||
++nTime; | ||
sumTime += time; | ||
sumTime2 += time * time; | ||
} | ||
|
||
void CPPFCluster::addY(const float y) { | ||
++nY; | ||
sumY += y; | ||
sumY2 += y * y; | ||
} | ||
|
||
void CPPFCluster::merge(const CPPFCluster& cl) { | ||
if (!this->isAdjacent(cl)) | ||
return; | ||
|
||
fstrip = cl.firstStrip(); | ||
|
||
nTime += cl.nTime; | ||
sumTime += cl.sumTime; | ||
sumTime2 += cl.sumTime2; | ||
|
||
nY += cl.nY; | ||
sumY += cl.sumY; | ||
sumY2 += cl.sumY2; | ||
} | ||
|
||
bool CPPFCluster::operator<(const CPPFCluster& cl) const { | ||
if (cl.bx() == this->bx()) | ||
return cl.firstStrip() < this->firstStrip(); | ||
|
||
return cl.bx() < this->bx(); | ||
} | ||
|
||
bool CPPFCluster::operator==(const CPPFCluster& cl) const { | ||
return ((this->clusterSize() == cl.clusterSize()) && (this->bx() == cl.bx()) && | ||
(this->firstStrip() == cl.firstStrip())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <cstdint> | ||
#ifndef L1Trigger_CPPFCluster_h | ||
#define L1Trigger_CPPFCluster_h | ||
class CPPFCluster { | ||
public: | ||
CPPFCluster(); | ||
CPPFCluster(int fs, int ls, int bx); | ||
~CPPFCluster(); | ||
|
||
int firstStrip() const; | ||
int lastStrip() const; | ||
int clusterSize() const; | ||
int bx() const; | ||
|
||
bool hasTime() const; | ||
float time() const; | ||
float timeRMS() const; | ||
|
||
bool hasY() const; | ||
float y() const; | ||
float yRMS() const; | ||
|
||
void addTime(const float time); | ||
void addY(const float y); | ||
void merge(const CPPFCluster& cl); | ||
|
||
bool operator<(const CPPFCluster& cl) const; | ||
bool operator==(const CPPFCluster& cl) const; | ||
bool isAdjacent(const CPPFCluster& cl) const; | ||
|
||
private: | ||
uint16_t fstrip; | ||
uint16_t lstrip; | ||
int16_t bunchx; | ||
|
||
float sumTime, sumTime2; | ||
uint16_t nTime; | ||
|
||
float sumY, sumY2; | ||
uint16_t nY; | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#ifndef L1Trigger_CPPFClusterContainer_h | ||
#define L1Trigger_CPPFClusterContainer_h | ||
#include <set> | ||
class CPPFCluster; | ||
typedef std::set<CPPFCluster> CPPFClusterContainer; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#include "CPPFClusterizer.h" | ||
|
||
CPPFClusterContainer CPPFClusterizer::doAction(const RPCDigiCollection::Range& digiRange) { | ||
CPPFClusterContainer initialCluster, finalCluster; | ||
// Return empty container for null input | ||
if (std::distance(digiRange.second, digiRange.first) == 0) | ||
return finalCluster; | ||
|
||
// Start from single digi recHits | ||
for (auto digi = digiRange.first; digi != digiRange.second; ++digi) { | ||
CPPFCluster cl(digi->strip(), digi->strip(), digi->bx()); | ||
if (digi->hasTime()) | ||
cl.addTime(digi->time()); | ||
if (digi->hasY()) | ||
cl.addY(digi->coordinateY()); | ||
initialCluster.insert(cl); | ||
} | ||
if (initialCluster.empty()) | ||
return finalCluster; // Confirm the collection is valid | ||
|
||
// Start from the first initial cluster | ||
CPPFCluster prev = *initialCluster.begin(); | ||
|
||
// Loop over the remaining digis | ||
// Note that the last one remains as open in this loop | ||
for (auto cl = std::next(initialCluster.begin()); cl != initialCluster.end(); ++cl) { | ||
if (prev.isAdjacent(*cl)) { | ||
// Merged digi to the previous one | ||
prev.merge(*cl); | ||
} else { | ||
// Close the previous cluster and start new cluster | ||
finalCluster.insert(prev); | ||
prev = *cl; | ||
} | ||
} | ||
|
||
// Finalize by adding the last cluster | ||
finalCluster.insert(prev); | ||
|
||
return finalCluster; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef L1Trigger_CPPFClusterizer_h | ||
#define L1Trigger_CPPFClusterizer_h | ||
/** \class CPPFClusterizer | ||
* \author M. Maggi -- INFN Bari | ||
*/ | ||
|
||
#include "CPPFClusterContainer.h" | ||
#include "CPPFCluster.h" | ||
#include "DataFormats/RPCDigi/interface/RPCDigiCollection.h" | ||
|
||
class CPPFClusterizer { | ||
public: | ||
CPPFClusterizer(){}; | ||
~CPPFClusterizer(){}; | ||
CPPFClusterContainer doAction(const RPCDigiCollection::Range& digiRange); | ||
}; | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** \Class CPPFMaskReClusterizer | ||
* \author R. Hadjiiska -- INRNE-BAS, Sofia | ||
*/ | ||
|
||
#include "CPPFCluster.h" | ||
#include "CPPFClusterizer.h" | ||
#include "CPPFMaskReClusterizer.h" | ||
|
||
CPPFClusterContainer CPPFMaskReClusterizer::doAction(const RPCDetId& id, | ||
CPPFClusterContainer& initClusters, | ||
const CPPFRollMask& mask) const { | ||
CPPFClusterContainer finClusters; | ||
if (initClusters.empty()) | ||
return finClusters; | ||
|
||
CPPFCluster prev = *initClusters.begin(); | ||
for (auto cl = std::next(initClusters.begin()); cl != initClusters.end(); ++cl) { | ||
// Merge this cluster if it is adjacent by 1 masked strip | ||
// Note that the CPPFClusterContainer collection is sorted in DECREASING ORDER of strip # | ||
// So the prev. cluster is placed after the current cluster (check the < operator of CPPFCluster carefully) | ||
if ((prev.firstStrip() - cl->lastStrip()) == 2 and this->get(mask, cl->lastStrip() + 1) and prev.bx() == cl->bx()) { | ||
CPPFCluster merged(cl->firstStrip(), prev.lastStrip(), cl->bx()); | ||
prev = merged; | ||
} else { | ||
finClusters.insert(prev); | ||
prev = *cl; | ||
} | ||
} | ||
|
||
// Finalize by putting the last cluster to the collection | ||
finClusters.insert(prev); | ||
|
||
return finClusters; | ||
} | ||
|
||
bool CPPFMaskReClusterizer::get(const CPPFRollMask& mask, int strip) const { return mask.test(strip - 1); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef L1Trigger_CPPFMaskReClusterizer_h | ||
#define L1Trigger_CPPFMaskReClusterizer_h | ||
|
||
/** \Class CPPFMaskReClusterizer | ||
* \author R. Hadjiiska -- INRNE-BAS, Sofia | ||
*/ | ||
|
||
#include "CPPFRPCRollMask.h" | ||
#include "CPPFClusterContainer.h" | ||
#include "DataFormats/MuonDetId/interface/RPCDetId.h" | ||
|
||
class CPPFMaskReClusterizer { | ||
public: | ||
CPPFMaskReClusterizer(){}; | ||
~CPPFMaskReClusterizer(){}; | ||
CPPFClusterContainer doAction(const RPCDetId& id, CPPFClusterContainer& initClusters, const CPPFRollMask& mask) const; | ||
bool get(const CPPFRollMask& mask, int strip) const; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#ifndef L1Trigger_CPPFRPCRollMask_h | ||
#define L1Trigger_CPPFRPCRollMask_h | ||
|
||
#include <bitset> | ||
|
||
const int maskCPPFSIZE = 192; | ||
typedef std::bitset<maskCPPFSIZE> CPPFRollMask; | ||
|
||
#endif |
Oops, something went wrong.