32 constexpr std::array<int, 10> s_quadrants = {{2, 3, 4, 5, 6, 7, 8, 9, 10, 11}};
36 constexpr std::array<int, 5> wheelTtu = {{3, 3, 2, 1, 1}};
41 m_useEventSetup{iConfig.getUntrackedParameter<
int>(
"UseEventSetup", 0)},
42 m_ttBits{iConfig.getParameter<std::vector<unsigned>>(
"BitNumbers")},
43 m_ttNames{iConfig.getParameter<std::vector<std::string>>(
"BitNames")},
44 m_rpcDigiLabel{iConfig.getParameter<
edm::InputTag>(
"RPCDigiLabel")},
45 m_rpcDigiToken{consumes<RPCDigiCollection>(m_rpcDigiLabel)},
46 m_useRPCSimLink{iConfig.getUntrackedParameter<
int>(
"UseRPCSimLink", 0)},
47 m_rpcGeometryToken(esConsumes<RPCGeometry, MuonGeometryRecord>()) {
51 m_configFile =
f1.fullPath();
54 LogTrace(
"RPCTechnicalTrigger") << m_rpcDigiLabel <<
'\n' << std::endl;
56 LogTrace(
"RPCTechnicalTrigger") <<
"\nConfiguration file used for UseEventSetup = 0 \n" 57 << m_configFile <<
'\n' 65 constexpr std::array<int, 3> boardIndex = {{1, 2, 3}};
66 constexpr std::array<int, 3> nWheels = {{2, 1, 2}};
73 m_ttuRbcLine[0] =
TTUEmulator(boardIndex[0], nWheels[0]);
74 m_ttuRbcLine[1] =
TTUEmulator(boardIndex[1], nWheels[1]);
75 m_ttuRbcLine[2] =
TTUEmulator(boardIndex[2], nWheels[2]);
80 produces<L1GtTechnicalTriggerRecord>();
81 consumes<edm::DetSetVector<RPCDigiSimLink>>(
edm::InputTag(
"simMuonRPCDigis",
"RPCDigiSimLink",
""));
82 if (m_useEventSetup >= 1) {
83 m_pRBCSpecsToken = esConsumes<RBCBoardSpecs, RBCBoardSpecsRcd, edm::Transition::BeginRun>();
84 m_pTTUSpecsToken = esConsumes<TTUBoardSpecs, TTUBoardSpecsRcd, edm::Transition::BeginRun>();
103 std::unique_ptr<ProcessInputSignal> signal;
112 signal = std::make_unique<RBCProcessRPCDigis>(rpcGeometry, pIn);
115 iEvent.getByLabel(
"simMuonRPCDigis",
"RPCDigiSimLink", simIn);
122 signal = std::make_unique<RBCProcessRPCSimDigis>(rpcGeometry, simIn);
125 LogDebug(
"RPCTechnicalTrigger") <<
"signal object created" <<
'\n';
128 edm::LogError(
"RPCTechnicalTrigger") <<
"cannot read hardware configuration \n";
140 auto*
input = signal->retrievedata();
142 std::vector<L1GtTechnicalTrigger> ttVec(
m_ttBits.size());
145 std::bitset<5> triggerbits;
147 std::vector<std::unique_ptr<TTUResults>> serializedInfoLine1;
148 std::vector<std::unique_ptr<TTUResults>> serializedInfoLine2;
154 for (
auto firstSector : s_quadrants)
158 for (
auto const&
out :
m_ttu[
k].m_triggerBxVec)
159 serializedInfoLine1.emplace_back(std::make_unique<TTUResults>(
k,
out.m_bx,
out.m_trigger[0],
out.m_trigger[1]));
160 m_ttu[
k].clearTriggerResponse();
164 serializedInfoLine2.push_back(
165 std::make_unique<TTUResults>(
k,
out.m_bx,
out.m_trigger[0],
out.m_trigger[1],
out.m_wedge));
174 infoSize = serializedInfoLine1.size();
176 auto sortByBx = [](
auto& iLHS,
auto& iRHS) {
return iLHS->m_bx < iRHS->m_bx; };
177 std::sort(serializedInfoLine1.begin(), serializedInfoLine1.end(), sortByBx);
180 for (
auto& ttu : serializedInfoLine1) {
181 if (
abs(ttu->m_bx) <= 1)
182 std::cout <<
"RPCTechnicalTrigger> " << ttu->m_ttuidx <<
'\t' << ttu->m_bx <<
'\t' << ttu->m_trigWheel1 <<
'\t' 183 << ttu->m_trigWheel2 <<
'\n';
187 bool has_bx0 =
false;
190 bx = serializedInfoLine1[
k]->m_bx;
193 triggerbits.set(0, serializedInfoLine1[
k]->m_trigWheel2);
194 triggerbits.set(1, serializedInfoLine1[
k]->m_trigWheel1);
195 triggerbits.set(2, serializedInfoLine1[
k + 1]->m_trigWheel1);
196 triggerbits.set(3, serializedInfoLine1[
k + 2]->m_trigWheel1);
197 triggerbits.set(4, serializedInfoLine1[
k + 2]->m_trigWheel2);
199 bool five_wheels_OR = triggerbits.any();
219 std::sort(serializedInfoLine2.begin(), serializedInfoLine2.end(), sortByBx);
222 for (
auto& ttu : serializedInfoLine2) {
223 if (
abs(ttu->m_bx) <= 1)
224 std::cout <<
"RPCTechnicalTrigger> " << ttu->m_ttuidx <<
'\t' << ttu->m_bx <<
'\t' << ttu->m_trigWheel1 <<
'\t' 225 << ttu->m_trigWheel2 <<
'\t' << ttu->m_wedge <<
'\n';
229 auto ttuResultsByQuadrant =
convertToMap(serializedInfoLine2);
231 std::bitset<8> triggerCoincidence;
232 triggerCoincidence.reset();
236 triggerCoincidence.set(0,
result);
240 triggerCoincidence.set(1,
result);
244 triggerCoincidence.set(2,
result);
248 triggerCoincidence.set(3,
result);
252 triggerCoincidence.set(4,
result);
256 triggerCoincidence.set(5,
result);
260 triggerCoincidence.set(6,
result);
264 triggerCoincidence.set(7,
result);
266 bool five_wheels_OR = triggerCoincidence.any();
269 std::cout <<
"RPCTechnicalTrigger> pointing trigger: " << five_wheels_OR <<
'\n';
274 triggerCoincidence.reset();
280 LogDebug(
"RPCTechnicalTrigger") <<
"RPCTechnicalTrigger> end of event loop" << std::endl;
284 output->setGtTechnicalTrigger(ttVec);
289 LogDebug(
"RPCTechnicalTrigger") <<
"RPCTechnicalTrigger> end of event loop" << std::endl;
293 LogDebug(
"RPCTechnicalTrigger") <<
"RPCTechnicalTrigger::beginRun> starts" << std::endl;
303 edm::LogError(
"RPCTechnicalTrigger") <<
"can't find RBC/TTU BoardSpecsRcd" <<
'\n';
344 const std::vector<std::unique_ptr<TTUResults>>& ttuResults)
const {
345 std::map<int, TTUResults*> returnValue;
346 auto itr = ttuResults.begin();
348 while (itr != ttuResults.end()) {
349 if ((*itr)->m_bx != 0) {
355 key = 1000 * ((*itr)->m_ttuidx + 1) + 1 * (*itr)->m_wedge;
356 returnValue[
key] = itr->get();
366 std::map<int, TTUResults*>
const& ttuResultsByQuadrant)
const {
367 std::map<int, TTUResults*>::const_iterator itr;
368 bool topRight(
false);
371 int indxW1 = wheelTtu[wheel1 + kWheelOffset];
372 int indxW2 = wheelTtu[wheel2 + kWheelOffset];
376 bool finalTrigger(
false);
377 int maxTopQuadrants = 4;
381 for (
auto firstSector : s_quadrants) {
382 key = 1000 * (indxW1) + firstSector;
384 itr = ttuResultsByQuadrant.find(
key);
385 if (itr != ttuResultsByQuadrant.end())
386 topRight = (*itr).second->getTriggerForWheel(wheel1);
390 key = 1000 * (indxW2) + firstSector + 5;
392 itr = ttuResultsByQuadrant.find(
key);
394 if (itr != ttuResultsByQuadrant.end())
395 botLeft = (*itr).second->getTriggerForWheel(wheel2);
399 finalTrigger |= (topRight && botLeft);
403 if (
k > maxTopQuadrants)
411 for (
auto firstSector : s_quadrants) {
412 key = 1000 * (indxW2) + firstSector;
414 itr = ttuResultsByQuadrant.find(
key);
415 if (itr != ttuResultsByQuadrant.end())
416 topRight = (*itr).second->getTriggerForWheel(wheel1);
420 key = 1000 * (indxW1) + firstSector + 5;
422 itr = ttuResultsByQuadrant.find(
key);
424 if (itr != ttuResultsByQuadrant.end())
425 botLeft = (*itr).second->getTriggerForWheel(wheel2);
429 finalTrigger |= (topRight && botLeft);
433 if (
k > maxTopQuadrants)
443 LogDebug(
"RPCTechnicalTrigger") <<
"RPCTechnicalTrigger::Printing TTU emulators info>" << std::endl;
void beginRun(edm::Run const &, const edm::EventSetup &) final
std::unique_ptr< TTUConfigurator > m_readConfig
const edm::InputTag m_rpcDigiLabel
const int m_useRPCSimLink
std::map< int, TTUResults * > convertToMap(const std::vector< std::unique_ptr< TTUResults >> &) const
~RPCTechnicalTrigger() override
Log< level::Error, false > LogError
const int m_useEventSetup
static std::string const input
static constexpr int kMaxTtuBoards
T getUntrackedParameter(std::string const &, T const &) const
T const * product() const
edm::ESGetToken< RPCGeometry, MuonGeometryRecord > m_rpcGeometryToken
RPCTechnicalTrigger(const edm::ParameterSet &)
Abs< T >::type abs(const T &t)
key
prepare the HTCondor submission files and eventually submit them
#define DEFINE_FWK_MODULE(type)
ESHandle< T > getHandle(const ESGetToken< T, R > &iToken) const
const TTUBoardSpecs * m_ttuspecs
bool searchCoincidence(int, int, std::map< int, TTUResults *> const &ttuResultsByQuandrant) const
std::array< TTUEmulator, kMaxTtuBoards > m_ttu
const edm::EDGetTokenT< RPCDigiCollection > m_rpcDigiToken
const std::vector< unsigned > m_ttBits
const RBCBoardSpecs * m_rbcspecs
edm::ESGetToken< RBCBoardSpecs, RBCBoardSpecsRcd > m_pRBCSpecsToken
const std::vector< std::string > m_ttNames
edm::ESGetToken< TTUBoardSpecs, TTUBoardSpecsRcd > m_pTTUSpecsToken
std::array< TTUEmulator, kMaxTtuBoards > m_ttuRbcLine
void produce(edm::Event &, const edm::EventSetup &) override