/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes
TsRpcTriggerTool Class Reference

#include <TsRpcTriggerTool.h>

Inheritance diagram for TsRpcTriggerTool:
Inheritance graph
[legend]
Collaboration diagram for TsRpcTriggerTool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TsRpcTriggerTool (const std::string &type, const std::string &name, const IInterface *parent)
virtual ~TsRpcTriggerTool ()
virtual StatusCode mutate (DayaBay::SimTrigHeader *trigHeader, const DayaBay::ElecHeader &elecHeader)
 Modify the event.
virtual StatusCode initialize ()
virtual StatusCode finalize ()

Static Public Member Functions

static const InterfaceID & interfaceID ()
 Retrieve interface ID.

Private Types

enum  TriggerMode_t { kSingle3of4, kNeighbours3of4 }
typedef std::map< int,
std::vector< std::pair
< DayaBay::FecChannelId, int > > > 
ByClockTriggers_t

Private Member Functions

StatusCode processBoard (const DayaBay::ElecFecBoard *board, ByClockTriggers_t &con, ServiceMode svcMode)
StatusCode getCoincidences (const DayaBay::ElecFecBoard *board, std::vector< int > &coincidences, ServiceMode svcMode)
void addNeighbours (DayaBay::SimRpcTrigCommand *tc, DayaBay::FecChannelId &tch, DayaBay::Trigger::TriggerType_t ttype, ServiceMode svcMode)

Private Attributes

enum
TsRpcTriggerTool::TriggerMode_t 
m_triggerMode
std::vector< std::string > m_detectorsToProcess
std::string m_triggerModeString
int m_trigStretch
int m_trigDelay
std::string m_cableSvcName
ICableSvcm_cableSvc

Detailed Description

Definition at line 34 of file TsRpcTriggerTool.h.


Member Typedef Documentation

typedef std::map<int,std::vector<std::pair<DayaBay::FecChannelId,int> > > TsRpcTriggerTool::ByClockTriggers_t [private]

Definition at line 58 of file TsRpcTriggerTool.h.


Member Enumeration Documentation

Enumerator:
kSingle3of4 
kNeighbours3of4 

Definition at line 37 of file TsRpcTriggerTool.h.


Constructor & Destructor Documentation

TsRpcTriggerTool::TsRpcTriggerTool ( const std::string &  type,
const std::string &  name,
const IInterface *  parent 
)

Definition at line 17 of file TsRpcTriggerTool.cc.

    : GaudiTool(type,name,parent)
{
  declareInterface< ITsTriggerTool >(this) ;
  // for now add RPC as default.
  m_detectorsToProcess.push_back("DayaBayRPC");
  m_detectorsToProcess.push_back("LingAoRPC");
  m_detectorsToProcess.push_back("FarRPC");

  declareProperty("DetectorsToProcess",m_detectorsToProcess,
                  "List of detectors to process with this tool");
  declareProperty("TrigStretch",m_trigStretch = 8,
                  "Number of clock cycles by which to stretch the FEC output local trigger.");
  declareProperty("Delay",m_trigDelay = 0,
                  "Delay of the signal due to the trigger decision.");
  declareProperty("CableSvcName",m_cableSvcName="CableSvc",
          "Name of service to map between detector, hardware, and electronic IDs");
  declareProperty("TriggerMode",m_triggerModeString="Single3of4",
          "Trigger mode switch. Possible are: \"Single2of4\" (Default), \"Neighbours3of4\"");
}
TsRpcTriggerTool::~TsRpcTriggerTool ( ) [virtual]

Definition at line 40 of file TsRpcTriggerTool.cc.

{}

Member Function Documentation

StatusCode TsRpcTriggerTool::mutate ( DayaBay::SimTrigHeader trigHeader,
const DayaBay::ElecHeader elecHeader 
) [virtual]

Modify the event.

Implements ITsTriggerTool.

Definition at line 72 of file TsRpcTriggerTool.cc.

{
    debug() << "Running mutate()." << endreq;
    DayaBay::SimTrigCommandHeader* trigCH =
        const_cast<DayaBay::SimTrigCommandHeader*>(trigHeader->commandHeader());

    const DayaBay::ElecCrateHeader* crateHeader = elecHeader.crateHeader();
    DayaBay::ElecCrateHeader::CrateMap cmap = crateHeader->crates();
    DayaBay::ElecCrateHeader::CrateMap::iterator detIterator;

    std::vector<std::string>::iterator it;
    debug() << "mutate(): Processing " << m_detectorsToProcess.size() << " detectors." << endreq;
    verbose()<<"mutate(): The detectors to process are: "<<m_detectorsToProcess<<endreq;

    // loop over detectors
    for(it = m_detectorsToProcess.begin();
        it != m_detectorsToProcess.end();
        ++it) {
        // Prepare detector representation
        short int m_detId =  DayaBay::Detector::siteDetPackedFromString(*it);
        DayaBay::Detector det(m_detId);
        DetectorId::DetectorId_t detId = det.detectorId();

        // Create context
        Site::Site_t  site = det.site();
        TimeStamp elecTime;
        Context context(site, SimFlag::kMC,
              elecTime, detId);
        int task = 0;
        ServiceMode svcMode(context, task);

        // Process the detector
        debug() << "mutate(): Processing " << *it << " which is " << det << endreq;

        const DayaBay::SimTrigCommandHeader::detCollMap trigCollMap = trigCH->collections();

        detIterator = cmap.find(det);
        if(detIterator == cmap.end()) {
            // No crate for given detector
            debug()<<"mutate(): Crate for the detector "<<det
                <<" not found. Will continue with next detector."<<endreq;
            continue;
        } else {
            // A crate was found for this detector
            debug() << "mutate(): A crate was found for " << det
                  << " processing..." << endreq;
            // Only create and add triggers if there is a crate for it...

            if(trigCollMap.find(det) == trigCollMap.end()){
                // No trigger command collection fot the detector yet,
                // create one.
                DayaBay::SimTrigCommandCollection *tcc = new DayaBay::SimTrigCommandCollection();
                tcc->setHeader(trigCH);
                tcc->setDetector(det);
                trigCH->addCollection(tcc);
                debug() << "mutate(): Created trigger command collection for this detector: "
                    << det << endreq;
            }

            DayaBay::ElecFecCrate *crate
                = dynamic_cast<DayaBay::ElecFecCrate*>(detIterator->second); //cmap[det]);
            if (!crate) {
                // This is not FEC crate.
                error()<<"mutate(): The crate for this detector, "<<det
                    <<", is not FEC crate. It is not intended to be "
                    <<"processed by this tool.";
                error()<<"Mismatched detector/crate map?"<<endreq;
                return StatusCode::FAILURE;
            }

            // Create container for pair info about coincidence number for triggered RPCs
            ByClockTriggers_t con;
            // Iterate over all boards in the crate
            DayaBay::ElecFecCrate::FecBoardMap boards = crate->fecBoards();
            DayaBay::ElecFecCrate::FecBoardMap::iterator bIter, bDone = boards.end();
            for (bIter = boards.begin(); bIter != bDone; bIter++) {
                DayaBay::ElecFecBoard& board = bIter->second;

                StatusCode sc = processBoard(&board, con, svcMode);
                if ( sc.isFailure() ) {
                    error()<<"mutate(): The board "<<board.boardId()
                        <<" could not be processed."<<endreq;
                    return StatusCode::FAILURE;
                }
            } // board loop

            debug()<<"mutate(): Collected "<<con.size()<<" triggers for "<<det<<endreq;

            // Loop over clock cycles and produce trigger comands accordingly
            ByClockTriggers_t::iterator clIt, clDone = con.end();
            for (clIt = con.begin(); clIt != clDone; clIt++) {
                // Create a trigger command
                DayaBay::SimRpcTrigCommand *tc =
                    new DayaBay::SimRpcTrigCommand(det,DayaBay::Trigger::kRPC2of4,clIt->first);
                if (msgLevel(MSG::VERBOSE))
                    verbose() << "mutate(): created new trigger command for detector "
                              << det << std::endl
                              << "intial inTriggers/outTriggers size: "<<tc->inTriggers().size()
                              <<"/"<<tc->outTriggers().size()<<endreq;
                trigCH->addCommand(tc);
                // Now loop over all boards triggered in this clock
                // and create local and readout triggers in the trigger
                // command
                ByClockTriggers_t::mapped_type::iterator chIt, chDone = clIt->second.end();
                for (chIt = clIt->second.begin(); chIt != chDone; chIt++) {
                    DayaBay::FecChannelId tch = chIt->first; // triggered channel
                    if (tch.bogus()) {
                        error()<<"mutate(): "
                            <<"Triggered channel is a bogus channel: "
                            <<tch<<endreq;
                        return StatusCode::FAILURE;
                    }
                    DayaBay::Trigger::TriggerType_t ttype;
                    if (chIt->second > 2) {
                        ttype = DayaBay::Trigger::kRPC3of4;
                        tc->setType( DayaBay::Trigger::TriggerType_t(
                                         DayaBay::Trigger::kRPC3of4|DayaBay::Trigger::kRPC2of4));
                    } else
                        ttype = DayaBay::Trigger::kRPC2of4;

                    tc->addInChannel(tch, ttype);
                    tc->addOutChannel(tch, ttype);

                    if (m_triggerMode == kNeighbours3of4) {
                        // add neighbours (as viewed from above the structure, electronics room at bottom)
                        addNeighbours(tc, tch, ttype, svcMode);
                    }

                } // board loop
                debug()<<"mutate(): Created "<<tc->inTriggers().size()<<" local and "<<tc->outTriggers().size()
                       <<" readout triggers"<<endreq;
                verbose()<<"mutate(): Locals: "<<tc->inTriggers()<<std::endl
                         <<"Readouts: "<<tc->outTriggers()<<endreq;
            } // clock loop
            //debug()<<"mutate(): Created "<<trigCH->collections().at(det)->commands().size()
            //   <<" trigger commands for detector "<<det<<endreq;
        } // if crate for this detector
    } // detector loop


    return StatusCode::SUCCESS;
}
StatusCode TsRpcTriggerTool::initialize ( ) [virtual]

Definition at line 42 of file TsRpcTriggerTool.cc.

{
  std::vector<std::string>::iterator it;

  // loop over detectors
  for(it = m_detectorsToProcess.begin();
      it != m_detectorsToProcess.end();
      ++it){
                short int detId =  DayaBay::Detector::siteDetPackedFromString(*it);
            DayaBay::Detector det(detId);
            info() << det << " is setup. " << endreq;
        }

    if (m_triggerModeString.find("Single3of4") != std::string::npos)
        m_triggerMode = kSingle3of4;
    else if (m_triggerModeString.find("Neighbours3of4") != std::string::npos)
        m_triggerMode = kNeighbours3of4;

    m_cableSvc = svc<ICableSvc>(m_cableSvcName,true);

    return StatusCode::SUCCESS;
}
StatusCode TsRpcTriggerTool::finalize ( ) [virtual]

Definition at line 65 of file TsRpcTriggerTool.cc.

{
  return StatusCode::SUCCESS;
}
StatusCode TsRpcTriggerTool::processBoard ( const DayaBay::ElecFecBoard board,
ByClockTriggers_t con,
ServiceMode  svcMode 
) [private]

Definition at line 216 of file TsRpcTriggerTool.cc.

{
    if (msgLevel(MSG::VERBOSE)) {
        verbose() << "processBoard(): processing board " << board->boardId() << endreq;
    }

    DayaBay::Detector det(svcMode.context().GetDetId());

    // create vector coincidences (numbers of hit layers for every cycle)
    std::vector<int> coincidences;
    StatusCode sc = getCoincidences(board, coincidences, svcMode);
    if (sc.isFailure()) {
        error()<<"processBoard(): Could not get coincidence numbers for this board: "
            <<board->boardId()<<endreq;
        return StatusCode::FAILURE;
    }

    // loop over coincidences and decide the trigger
    std::vector<int>::iterator cit, cdone = coincidences.end();
    int clock = 0;
    int lasttrig2 = -m_trigStretch;
    int lasttrig3 = -m_trigStretch;
    int trig2count = 0;
    int trig3count = 0;

    for (cit = coincidences.begin(); cit != cdone; cit++, clock++) {
        int lcount = (*cit);
        if (lcount > 2) { // we have coincidence
            if (clock >= lasttrig3 + m_trigStretch) { // it is not in the stretch window of the previous trigger
                // set new 2of4 trigger
                con[clock].push_back(std::pair<DayaBay::FecChannelId, int> (board->boardId(), 3));
                lasttrig3 = clock;
                trig3count++;
            }
        } else if (lcount == 2) {
            if (clock >= lasttrig2 + m_trigStretch){
                con[clock].push_back(std::pair<DayaBay::FecChannelId, int> (board->boardId(), 2));
                lasttrig2 = clock;
                trig2count++;
            }
        }
    }

    if (msgLevel(MSG::VERBOSE)) {
        if (trig2count || trig3count)
            verbose() << "processBoard(): Got " << trig2count
                << " 2of4 triggers and " << trig3count << " 3of4 triggers for this board: "
                << board->boardId() << endreq;
    }

    return StatusCode::SUCCESS;
}
StatusCode TsRpcTriggerTool::getCoincidences ( const DayaBay::ElecFecBoard board,
std::vector< int > &  coincidences,
ServiceMode  svcMode 
) [private]

Definition at line 270 of file TsRpcTriggerTool.cc.

{
    DayaBay::DigitalSignal* layers[4];

    // Create signal vectors for each layer.
    int size = board->channels().begin()->second.hits().size();
    for (int i = 0; i < 4; i++) {
        layers[i] = new DayaBay::DigitalSignal(size, 0); // needs to be deleted!
    }

    // Loop over all connectors in the board.
    DayaBay::ElecFecBoard::ChannelMap::const_iterator it, done = board->channels().end();
    for (it = board->channels().begin(); it != done; it++) {
        // which layer this channel belongs to
        // layers should be numbered 1..4, then index should go
        // 0..3.
        // vvv FixMe : this is hardcoded convention! vvv
        int ilayer = m_cableSvc->rpcSensor(it->first, svcMode).layer() - 1;

        // process the channel
        const DayaBay::DigitalSignal& signal = it->second.hits();
        if (signal.size() != size) {
            error()<<"getCoincidences(): Channel "<<it->first
                <<" does not have signal vector"
                <<" of the same size as the first channel in the board - "
                <<signal.size()<<" vs. "<<size<<endreq;
            return StatusCode::FAILURE;
        }
        for (int i = 0; i < size; i++) {
            if (signal[i]) {
                // Update the layer to which the channel belongs.
                (*(layers[ilayer]))[i] = 1;
            }
        }
    }

    // now, check the layers for signal overlaps
        if (coincidences.size() == 0) {
        coincidences.insert(coincidences.end(), size, 0);
    }
    if (coincidences.size() != size) {
        error()<<"getCoincidences(): The size of vector for coincidences does not match"
            <<" the size of DigitalSignal. "
            <<coincidences.size()<<" vs. "<<size<<endreq;
        return StatusCode::FAILURE;
    }

    DayaBay::DigitalSignal::iterator layeriters[4];
    std::vector<int>::iterator cit, cdone = coincidences.end();
    for (int i = 0; i < 4; i++)
        layeriters[i] = layers[i]->begin();

    // simply add 1 when there was a hit in the layer for the particular clock
    for (cit = coincidences.begin(); cit != cdone; cit++) {
        for (int i = 0; i < 4; i++) {
            (*cit) += (*(layeriters[i]));
            layeriters[i]++;
        }
    }

    if (msgLevel(MSG::VERBOSE)) {
                verbose() << "getCoincidences(): Got these coincidences: \n[";
        for (int i = 0; i < 10; i++) {
            verbose() << coincidences[i] << ", ";
        }
        verbose()<< "...]\n for the module " << board->boardId() <<" (only 10 clocks printed)" << endreq;
    }

    for (int i = 0; i < 4; i++) {
        delete layers[i]; // removing garbage
    }

    return StatusCode::SUCCESS;
}
void TsRpcTriggerTool::addNeighbours ( DayaBay::SimRpcTrigCommand tc,
DayaBay::FecChannelId tch,
DayaBay::Trigger::TriggerType_t  ttype,
ServiceMode  svcMode 
) [private]

Definition at line 346 of file TsRpcTriggerTool.cc.

{

    DayaBay::RpcSensor center = m_cableSvc->rpcSensor(tch, svcMode);
    int row = center.panelRow();
    int col = center.panelColumn();
    Site::Site_t site = tch.site();
    DetectorId::DetectorId_t detector = tch.detectorId();

    verbose()<<"addNeighbours(): got a Trigger for sensor "<<center<<endreq;

    // left neighbour
    DayaBay::RpcSensor l(row, col -1, 0,0, site, detector);
    if (!l.bogus()) {
        DayaBay::FecChannelId brdId = m_cableSvc->fecChannelId(l, svcMode);
        if ( brdId.fullPackedData()!=0 ) {
            if (msgLevel(MSG::VERBOSE))
                verbose()<<"addNeighbours(): Adding left neighbour of triggered rpc: "<<l<<"/"<<brdId<<endreq;
            tc->addOutChannel(brdId, ttype);// convert and add to the output triggers
        }
    }
    // right neighbour
    DayaBay::RpcSensor r(row, col + 1, 0,0, site, detector);
    if (!r.bogus()) {
        DayaBay::FecChannelId brdId = m_cableSvc->fecChannelId(r, svcMode);
        if ( brdId.fullPackedData()!=0 ) {
            if (msgLevel(MSG::VERBOSE))
                verbose()<<"addNeighbours(): Adding right neighbour of triggered rpc: "<<r<<"/"<<brdId<<endreq;
            tc->addOutChannel(brdId, ttype);
        }
    }
    // top neighbour
    DayaBay::RpcSensor t(row + 1, col, 0,0, site, detector);
    if (!t.bogus()) {
        DayaBay::FecChannelId brdId = m_cableSvc->fecChannelId(t, svcMode);
        if ( brdId.fullPackedData()!=0 ) {
            if (msgLevel(MSG::VERBOSE))
                verbose()<<"addNeighbours(): Adding top neighbour of triggered rpc: "<<t<<"/"<<brdId<<endreq;
            tc->addOutChannel(brdId, ttype);
        }
    }
    // bottom neighbour
    DayaBay::RpcSensor b(row - 1, col, 0,0, site, detector);
    if (!b.bogus()) {
        DayaBay::FecChannelId brdId = m_cableSvc->fecChannelId(b, svcMode);
        if ( brdId.fullPackedData()!=0 ) {
            if (msgLevel(MSG::VERBOSE))
                verbose()<<"addNeighbours(): Adding bottom neighbour of triggered rpc: "<<b<<"/"<<brdId<<endreq;
            tc->addOutChannel(brdId, ttype);
        }
    }
}
const InterfaceID & ITsTriggerTool::interfaceID ( ) [static, inherited]

Retrieve interface ID.

Definition at line 8 of file ITsTriggerTool.cc.

{ 
    return IID_ITsTriggerTool; 
}

Member Data Documentation

std::vector<std::string> TsRpcTriggerTool::m_detectorsToProcess [private]

Definition at line 69 of file TsRpcTriggerTool.h.

Definition at line 70 of file TsRpcTriggerTool.h.

Definition at line 71 of file TsRpcTriggerTool.h.

Definition at line 72 of file TsRpcTriggerTool.h.

std::string TsRpcTriggerTool::m_cableSvcName [private]

Definition at line 74 of file TsRpcTriggerTool.h.

Definition at line 75 of file TsRpcTriggerTool.h.


The documentation for this class was generated from the following files:
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Fri May 16 2014 10:16:52 for TrigSim by doxygen 1.7.4