Commit 93a829a3 authored by Carlos Moreno Martinez's avatar Carlos Moreno Martinez Committed by Vakhtang Tsulaia
Browse files

Simulation of L1Topo interfaces for multiplicity triggers

parent 7e01a0a6
......@@ -15,7 +15,7 @@ string( REPLACE "-Wl,--as-needed" "" CMAKE_EXE_LINKER_FLAGS
atlas_add_library( L1TopoAlgorithms
L1TopoAlgorithms/*.h Root/*.cxx
PUBLIC_HEADERS L1TopoAlgorithms
LINK_LIBRARIES L1TopoEvent L1TopoInterfaces
LINK_LIBRARIES L1TopoEvent L1TopoInterfaces TrigConfBase TrigConfIO TrigConfData
PRIVATE_LINK_LIBRARIES ${ROOT_LIBRARIES} L1TopoCommon L1TopoSimulationUtils )
atlas_add_executable( TrigConfL1TopoGenPyAlg
......
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
// EmMultiplicity.h
// TopoCore
// Created by Carlos Moreno on 05/05/20.
#ifndef __TopoCore__EMMultiplicity__
#define __TopoCore__EMMultiplicity__
#include <iostream>
#include <vector>
#include "L1TopoInterfaces/CountingAlg.h"
#include "L1TopoEvent/TOBArray.h"
#include "TrigConfData/L1Threshold.h"
class TH2;
namespace TCS {
class EMMultiplicity : public CountingAlg {
public:
EMMultiplicity(const std::string & name);
virtual ~EMMultiplicity();
virtual StatusCode initialize();
virtual StatusCode processBitCorrect( const TCS::InputTOBArray & input,
Count & count ) override final ;
virtual StatusCode process( const TCS::InputTOBArray & input,
Count & count ) override final ;
private:
TrigConf::L1Threshold const * m_threshold{nullptr};
};
}
#endif
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
/*********************************
* EMMultiplicity.cpp
* Created by Carlos Moreno on 05/06/20.
*
* @brief algorithm that computes the multiplicity for a specified list and ET threshold
* line 1: 0 or 1, line 1 and 2 : 2 or more, uses 2 bits
*
* @param NumberLeading MinET
**********************************/
#include <cmath>
#include "L1TopoAlgorithms/EMMultiplicity.h"
#include "L1TopoCommon/Exception.h"
#include "L1TopoInterfaces/Count.h"
#include "L1TopoEvent/TOBArray.h"
#include "L1TopoEvent/ClusterTOBArray.h"
#include "L1TopoEvent/GenericTOB.h"
#include "TH1F.h"
#include "TH2F.h"
REGISTER_ALG_TCS(EMMultiplicity)
using namespace std;
TCS::EMMultiplicity::EMMultiplicity(const std::string & name) : CountingAlg(name)
{
setNumberOutputBits(12); //To-Do: Make this flexible to addapt to the menu. Each counting requires more than one bit
}
TCS::EMMultiplicity::~EMMultiplicity(){}
TCS::StatusCode
TCS::EMMultiplicity::initialize() {
m_threshold = getThreshold();
// book histograms
std::string hname_accept = "hEMMultiplicity_accept_"+m_threshold->name();
bookHist(m_histAccept, hname_accept, "eta vs pT", 100, -49., 49., 25, 0., 25.);
hname_accept = "hEMMultiplicity_accept_counts_"+m_threshold->name();
bookHist(m_histAccept, hname_accept, "Counts", 10, 0., 10. );
return StatusCode::SUCCESS;
}
TCS::StatusCode
TCS::EMMultiplicity::processBitCorrect( const TCS::InputTOBArray & input,
Count & count)
{
return process(input, count);
}
TCS::StatusCode
TCS::EMMultiplicity::process( const TCS::InputTOBArray & input,
Count & count )
{
// Grab the threshold and cast it into the right type
auto eEMThr = dynamic_cast<const TrigConf::L1Threshold_eEM &>(*m_threshold);
// TO-DO: Add isolation cuts - need to be implemented in the L1Calo EDM first
//cout << "reta: " << TrigConf::Selection::wpToString(eEMThr.reta()) << endl;
//cout << "rhad: " << TrigConf::Selection::wpToString(eEMThr.rhad()) << endl;
//cout << "wstot: " << TrigConf::Selection::wpToString(eEMThr.wstot()) << endl;
// Grab inputs
const ClusterTOBArray & clusters = dynamic_cast<const ClusterTOBArray&>(input);
int counting = 0;
float MEV = 1000.;
// loop over input TOBs
for(ClusterTOBArray::const_iterator cl = clusters.begin();
cl != clusters.end();
++cl ) {
const GenericTOB gtob(**cl);
bool passed = false;
for(auto & rv : eEMThr.thrValues())
if ( (gtob.eta() < rv.etaMax()) && (gtob.eta() >= rv.etaMin()) && (gtob.Et()/MEV> static_cast<unsigned int>(rv.value())) ) passed = true;
if (passed) {
counting++;
fillHist2D( m_histAccept[0], gtob.eta(), gtob.Et()/MEV );
}
}
fillHist1D( m_histAccept[1], counting);
// Pass counting to TCS::Count object - output bits are composed there
count.setSizeCount(counting);
return TCS::StatusCode::SUCCESS;
}
......@@ -22,7 +22,7 @@ TCS::inputTypeAsString(TCS::inputTOBType_t type) {
TCS::inputTOBType_t
TCS::inputType(const std::string& input) {
if ( input == "Clusters" || input == "EmTobArray" )
if ( input == "Clusters" || input == "EmTobArray" || input == "eEM")
return TCS::CLUSTER;
if ( input == "Jets" || input == "JetTobArray" )
......
......@@ -22,7 +22,7 @@ namespace TCS {
class Connector {
public:
enum ConnectorType { NONE=0, INPUT, SORT, DECISION };
enum ConnectorType { NONE=0, INPUT, SORT, DECISION, COUNT };
// standard connector
Connector( const std::string & name,
......@@ -39,6 +39,7 @@ namespace TCS {
bool isInputConnector() const { return m_conntype == INPUT; }
bool isSortingConnector() const { return m_conntype == SORT; }
bool isDecisionConnector() const { return m_conntype == DECISION; }
bool isCountingConnector() const { return m_conntype == COUNT; }
const std::string & name() const { return m_name; }
const std::string & algorithmName() const { return m_algorithmName; }
......
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#ifndef L1TopoCoreSim_CountingConnector
#define L1TopoCoreSim_CountingConnector
#include "L1TopoCoreSim/Connector.h"
#include "L1TopoInterfaces/Count.h"
#include "L1TopoConfig/L1TopoConfigOutputList.h"
#include "L1TopoCommon/StatusCode.h"
#include "L1TopoCommon/Types.h"
#include "TrigConfData/L1Connector.h"
#include <vector>
#include <string>
namespace TCS {
class TOBArray;
class CountingAlg;
class InputConnector;
//special connector for Multiplicity Algorithms
class CountingConnector : public Connector {
public:
CountingConnector(const std::string & name,
const std::string & input,
const std::string & algorithm,
const std::string & output);
virtual ~CountingConnector();
InputConnector* inputConnector() const;
virtual bool isCountingConnector() const { return true; }
TCS::CountingAlg* countingAlgorithm() const { return m_countingAlgorithm; }
virtual StatusCode clearOutput();
const Count & count() const { return m_count; }
const std::vector<TrigConf::TriggerLine> & triggers() const { return m_triggers; }
//output data
void attachOutputData(const std::vector<TOBArray *>&);
TOBArray const * output(const std::string & trigger) const;
const std::vector<TOBArray const *> & outputData() const { return m_outputData; }
private: // functions
friend class TopoSteering;
friend class TopoSteeringStructure;
void setAlgorithm(TCS::ConfigurableAlg* alg);
void setFirstOutputBit(unsigned int firstOutputBit);
private: // data
// the count bit array
Count m_count;
TCS::CountingAlg* m_countingAlgorithm;
std::vector<TrigConf::TriggerLine> m_triggers;
// attached output data
std::vector<TOBArray const *> m_outputData;
};
std::ostream & operator<<(std::ostream &, const TCS::CountingConnector&);
}
#endif
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#ifndef L1TopoCoreSim_GlobalOutput
#define L1TopoCoreSim_GlobalOutput
#include "TrigConfBase/TrigConfMessaging.h"
#include "L1TopoCommon/StatusCode.h"
#include "L1TopoConfig/L1TopoConfigOutputList.h"
#include "TrigConfData/L1Connector.h"
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <vector>
#include <stdint.h>
namespace TCS {
class GlobalOutput;
}
namespace TCS {
std::ostream& operator<<(std::ostream&, const TCS::GlobalOutput &);
class Decision;
class DecisionConnector;
class Count;
class CountingConnector;
class GlobalOutput : public TrigConf::TrigConfMessaging {
public:
GlobalOutput(const std::string & name = "L1TopoGlobalOutput");
uint64_t decision_field(const std::string & l1connName) const;
uint32_t decision_field(std::string l1connName, unsigned int clock) const;
bool passed(std::string connName, unsigned int bit) const { return ( ( (uint64_t)0x1 << bit) & m_decision.find(connName)->second) != 0; }
uint64_t overflow_field(std::string l1connName) const;
uint32_t overflow_field(std::string l1connName, unsigned int clock) const;
bool overflowed(std::string l1connName, unsigned int bit) const { return ( ( (uint64_t)0x1 << bit) & m_overflow.find(l1connName)->second) != 0; }
std::bitset<128> count_field(std::string l1connName) const;
const Decision & decision(const std::string & algName) const;
bool isValid() const { return m_valid; }
void setDecisionTriggerLines(const std::vector<TrigConf::TriggerLine> & triggers);
void setMultiplicityTriggerLines(const std::vector<TrigConf::TriggerLine> & triggers);
StatusCode collectOutput(const std::set<DecisionConnector*> & outConn, const std::set<CountingConnector*> & countConn);
StatusCode resetOutput();
void print() const;
private:
friend std::ostream& operator<<(std::ostream&, const TCS::GlobalOutput &);
// 64 bit decision bit field - map L1Connector name-decision field
std::map<std::string,uint64_t> m_decision;
// 64 bit overflow bit field - map L1Connector name-overflow field
std::map<std::string,uint64_t> m_overflow;
// 128 bit multiplicity bit field - map L1Connector name-multiplicity field
std::map<std::string,std::bitset<128>> m_count;
// flags if the decision field is up to date
// set by @collectDecision(), unset by @reset()
bool m_valid {false};
// trigger lines
std::vector<TrigConf::TriggerLine> m_triggersDec;
std::vector<TrigConf::TriggerLine> m_triggersCount;
};
}
#endif
......@@ -14,7 +14,7 @@
#include <iostream>
#include "L1TopoCommon/StatusCode.h"
#include "L1TopoCoreSim/GlobalDecision.h"
#include "L1TopoCoreSim/GlobalOutput.h"
#include <vector>
#include <map>
#include <set>
......@@ -31,6 +31,7 @@ namespace TCS {
class TOBArray;
class DecisionConnector;
class CountingConnector;
class TopoCoreSimResult : public TrigConf::TrigConfMessaging {
public:
......@@ -41,13 +42,13 @@ namespace TCS {
const TCS::TOBArray* triggerOutput(const std::string & triggerName) const;
const GlobalDecision& globalDecision() const { return m_globalDecision; }
const GlobalOutput& globalOutput() const { return m_globalOutput; }
const std::vector<const TCS::TOBArray*> & output(const std::string & connName) const;
StatusCode setupFromMenu(const std::map<std::string, TCS::DecisionConnector*>& outputConnectorMap);
StatusCode setupFromMenu(const std::map<std::string, TCS::DecisionConnector*>& outputConnectorMap, const std::map<std::string, TCS::CountingConnector*>& countConnectorMap);
StatusCode collectResult(TCS::DecisionConnector* outputConn = nullptr );
StatusCode collectResult(TCS::DecisionConnector* outputConn = nullptr, TCS::CountingConnector* countConn = nullptr );
StatusCode reset();
......@@ -56,16 +57,25 @@ namespace TCS {
private:
friend std::ostream& ::operator<<(std::ostream&, const TCS::TopoCoreSimResult &);
GlobalDecision m_globalDecision;
GlobalOutput m_globalOutput;
// map from connector name to decision connectors
std::map<std::string, TCS::DecisionConnector*> m_outputConnectorMap;
// map from trigger name to decision connectors
std::map<std::string, TCS::DecisionConnector*> m_triggerLocation;
std::map<std::string, TCS::DecisionConnector*> m_triggerLocationDec;
std::set<TCS::DecisionConnector*> m_outputConnectors;
// map from connector name to counting connectors
std::map<std::string, TCS::CountingConnector*> m_countConnectorMap;
// map from trigger name to counting connectors
std::map<std::string, TCS::CountingConnector*> m_triggerLocationCount;
std::set<TCS::CountingConnector*> m_countConnectors;
};
}
......
......@@ -33,10 +33,13 @@ namespace TCS {
class InputConnector;
class SortingConnector;
class DecisionConnector;
class CountingConnector;
class ConfigurableAlg;
class SortingAlg;
class Decision;
class DecisionAlg;
class Count;
class CountingAlg;
class TopoSteering : public TrigConf::TrigConfMessaging {
public:
......@@ -134,6 +137,8 @@ namespace TCS {
StatusCode executeSortingConnector(TCS::SortingConnector *conn);
StatusCode executeDecisionConnector(TCS::DecisionConnector *conn);
StatusCode executeCountingConnector(TCS::CountingConnector *conn);
StatusCode executeAlgorithm(ConfigurableAlg *alg, Connector* connector);
......@@ -141,6 +146,8 @@ namespace TCS {
StatusCode executeDecisionAlgorithm(TCS::DecisionAlg *alg, const std::vector<Connector*> & inputConnectors, const std::vector<TCS::TOBArray *> & output, Decision & decsion);
StatusCode executeCountingAlgorithm(TCS::CountingAlg *alg, TCS::InputConnector* inputConnector, Count & count);
private:
......
......@@ -19,6 +19,7 @@ namespace TCS {
class Connector;
class DecisionConnector;
class SortingConnector;
class CountingConnector;
class InputConnector;
class ParameterSpace;
// class DecisionAlg;
......@@ -40,10 +41,14 @@ namespace TCS {
const std::map<std::string, TCS::DecisionConnector*> & outputConnectors() const { return m_outputLookup; }
const std::map<std::string, TCS::CountingConnector*> & countConnectors() const { return m_countLookup; }
Connector* connector(const std::string & connectorName) const;
DecisionConnector* outputConnector(const std::string & output) const;
CountingConnector* countingConnector(const std::string & output) const;
// resets the connectors (status, intermediate TOBs, and decision of algs)
StatusCode reset();
......@@ -60,6 +65,8 @@ namespace TCS {
StatusCode addSortingConnector(SortingConnector * conn);
StatusCode addCountingConnector(CountingConnector * conn);
StatusCode linkConnectors();
StatusCode instantiateAlgorithms(bool debug);
......@@ -74,6 +81,8 @@ namespace TCS {
std::map<std::string, TCS::SortingConnector*> m_sortedLookup; // sorting connectors (subset of m_connectors) by connector name
std::map<std::string, TCS::CountingConnector*> m_countLookup; // counting connectors (subset of m_connectors) by connector name
std::map<std::string, TCS::InputConnector*> m_inputLookup; // input connectors (subset of m_connectors) by connector name
std::vector<TCS::ParameterSpace*> m_parameters;
......
/*
Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
*/
#include "L1TopoCoreSim/CountingConnector.h"
#include "L1TopoCoreSim/InputConnector.h"
#include "L1TopoCommon/StringUtils.h"
#include "L1TopoCommon/Exception.h"
#include "L1TopoInterfaces/CountingAlg.h"
using namespace std;
using namespace TCS;
CountingConnector::CountingConnector(const string & name,
const string & input,
const string & algorithm,
const string & output) :
Connector(name, {input}, algorithm, {output}, COUNT),
m_countingAlgorithm(0)
{}
CountingConnector::~CountingConnector() {
clearOutput();
}
// TO-DO: Add function to return the counts, but format?
TCS::TOBArray const *
TCS::CountingConnector::output(const std::string & trigger) const {
unsigned int index(0);
for(const TrigConf::TriggerLine & tl : m_triggers) {
if(tl.name() == trigger)
return m_outputData[index];
++index;
}
TCS_EXCEPTION("Counting connector '" << name() << "' has no output trigger '" << trigger << "'");
return nullptr;
}
TCS::StatusCode
TCS::CountingConnector::clearOutput() {
for(TOBArray const * x : m_outputData) {
delete x;
}
m_outputData.clear();
// set counting to 0
m_count.reset();
return StatusCode::SUCCESS;
}
InputConnector*
CountingConnector::inputConnector() const {
return dynamic_cast<InputConnector*>(m_inputConnectors[0]);
}
void
CountingConnector::setAlgorithm(TCS::ConfigurableAlg* alg) {
Connector::setAlgorithm(alg);
m_countingAlgorithm = dynamic_cast<CountingAlg*>(alg);
if( ! m_countingAlgorithm ) {
TCS_EXCEPTION("Error: algorithm " << alg->name() << " is not a CountingAlg");
}
}
// attaches the selected data to the connector (does take ownership)
void
CountingConnector::attachOutputData(const std::vector<TOBArray *>& data) {
if(m_outputData.size() != 0) {
TCS_EXCEPTION("Trying to attach data to multiplicity connector '" << name() <<"' which has already data attached");
}
for(TOBArray * x : data)
m_outputData.push_back( dynamic_cast<const TOBArray*>(x) );
}
void
CountingConnector::