Skip to content

Commit

Permalink
Merge pull request #29603 from mileva/cppfClusterizerRefactoring
Browse files Browse the repository at this point in the history
CPPF emulator refactoring
  • Loading branch information
cmsbuild authored May 17, 2020
2 parents 1f30a93 + a56f00c commit 83042dd
Show file tree
Hide file tree
Showing 14 changed files with 823 additions and 435 deletions.
4 changes: 4 additions & 0 deletions L1Trigger/L1TMuonCPPF/interface/EmulateCPPF.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "FWCore/Framework/interface/ConsumesCollector.h"
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "DataFormats/Common/interface/DetSetVector.h"

class EmulateCPPF {
public:
Expand All @@ -24,7 +25,10 @@ class EmulateCPPF {
// separate entities
std::array<RecHitProcessor, 1> recHit_processors_;

const edm::EDGetToken rpcDigiToken_;
const edm::EDGetToken recHitToken_;
const edm::EDGetToken rpcDigiSimLinkToken_;

enum class CppfSource { File, EventSetup } cppfSource_;
std::vector<RecHitProcessor::CppfItem> CppfVec_1;
int MaxClusterSize_;
Expand Down
7 changes: 7 additions & 0 deletions L1Trigger/L1TMuonCPPF/interface/RecHitProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
#include "DataFormats/L1TMuon/interface/CPPFDigi.h"
#include "DataFormats/MuonDetId/interface/RPCDetId.h"
#include "DataFormats/RPCRecHit/interface/RPCRecHitCollection.h"
#include "DataFormats/RPCDigi/interface/RPCDigiCollection.h"
#include "SimDataFormats/RPCDigiSimLink/interface/RPCDigiSimLink.h"

#include "CondFormats/RPCObjects/interface/RPCDeadStrips.h"
#include "CondFormats/RPCObjects/interface/RPCMaskedStrips.h"

#include "CondFormats/Serialization/interface/Serializable.h"
#include "L1Trigger/L1TMuonEndCap/interface/TrackTools.h"

#include <boost/cstdint.hpp>
#include <iostream>
#include <memory>
#include <sstream>
Expand Down Expand Up @@ -50,6 +53,8 @@ class RecHitProcessor {
const edm::Event &iEvent,
const edm::EventSetup &iSetup,
const edm::EDGetToken &recHitToken,
const edm::EDGetToken &rpcDigiToken,
const edm::EDGetToken &rpcDigiSimLinkToken,
std::vector<RecHitProcessor::CppfItem> &CppfVec1,
// Output
l1t::CPPFDigiCollection &cppfDigis,
Expand All @@ -60,6 +65,8 @@ class RecHitProcessor {
const edm::Event &iEvent,
const edm::EventSetup &iSetup,
const edm::EDGetToken &recHitToken,
const edm::EDGetToken &rpcDigiToken,
const edm::EDGetToken &rpcDigiSimLinkToken,
// Output
l1t::CPPFDigiCollection &cppfDigis) const;

Expand Down
5 changes: 3 additions & 2 deletions L1Trigger/L1TMuonCPPF/python/emulatorCppfDigis_cfi.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import FWCore.ParameterSet.Config as cms

emulatorCppfDigis = cms.EDProducer("L1TMuonCPPFDigiProducer",

emulatorCppfDigis = cms.EDProducer("L1TMuonCPPFDigiProducer",
## Input collection
recHitLabel = cms.InputTag("rpcRecHits"),
rpcDigiLabel = cms.InputTag("simMuonRPCDigis"),
rpcDigiSimLinkLabel = cms.InputTag("simMuonRPCDigis", "RPCDigiSimLink"),
MaxClusterSize = cms.int32(3),
# cppfSource = cms.string('Geo'), #'File' for Look up table and 'Geo' for CMSSW Geometry
cppfSource = cms.string('File'), #'File' for Look up table and 'Geo' for CMSSW Geometry
Expand Down
72 changes: 72 additions & 0 deletions L1Trigger/L1TMuonCPPF/src/CPPFCluster.cc
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()));
}
42 changes: 42 additions & 0 deletions L1Trigger/L1TMuonCPPF/src/CPPFCluster.h
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
6 changes: 6 additions & 0 deletions L1Trigger/L1TMuonCPPF/src/CPPFClusterContainer.h
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
41 changes: 41 additions & 0 deletions L1Trigger/L1TMuonCPPF/src/CPPFClusterizer.cc
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;
}
17 changes: 17 additions & 0 deletions L1Trigger/L1TMuonCPPF/src/CPPFClusterizer.h
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
36 changes: 36 additions & 0 deletions L1Trigger/L1TMuonCPPF/src/CPPFMaskReClusterizer.cc
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); }
20 changes: 20 additions & 0 deletions L1Trigger/L1TMuonCPPF/src/CPPFMaskReClusterizer.h
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
9 changes: 9 additions & 0 deletions L1Trigger/L1TMuonCPPF/src/CPPFRPCRollMask.h
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
Loading

0 comments on commit 83042dd

Please sign in to comment.