/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 | Private Attributes
MuonTag Class Reference

#include <MuonTag.h>

Collaboration diagram for MuonTag:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 MuonTag (const std::string &name, ISvcLocator *svcloc)
 Constructor has to be in this form.
virtual ~MuonTag ()
StatusCode initialize ()
 Three mandatory member functions of any algorithm.
StatusCode execute ()
StatusCode finalize ()

Private Attributes

IJobInfoSvcm_jobInfoSvc
std::vector< const
DayaBay::IHeader * > 
m_inputHeaders
std::map
< DetectorId::DetectorId_t,
TimeStamp
m_lastMuonTime
TimeStamp m_firstMuonTime
TimeStamp m_lastTriggerTime
bool m_startCounter
std::string m_calibHeaderLocation
std::string m_calibStatsLocation
std::string m_adrecHeaderLocation
std::string m_poolrecHeaderLocation
std::string m_rpcrecHeaderLocation
std::string m_muonAnyLocation
std::string m_firstMuonTriggerLocation
std::string m_retriggerLocation
std::string m_muonAllLocation
std::string m_muonTagLocation
float m_dtPromptCut
float m_dtRetriggerCut
int m_owsNhitCut
int m_iwsNhitCut
float m_adChargeCut

Detailed Description

Definition at line 17 of file MuonTag.h.


Constructor & Destructor Documentation

MuonTag::MuonTag ( const std::string &  name,
ISvcLocator *  svcloc 
)

Constructor has to be in this form.

Definition at line 15 of file MuonTag.cc.

: GaudiAlgorithm(name, svcloc)
{
  declareProperty("CalibHeaderLocation", m_calibHeaderLocation="/Event/CalibReadout/CalibReadoutHeader",
                  "Location of the CalibReadoutHeader");
  declareProperty("CalibStatsLocation", m_calibStatsLocation="/Event/Data/CalibStats",
                  "Location of the CalibStats User data");
  declareProperty("ADRecHeaderLocation", m_adrecHeaderLocation="/Event/Rec/AdSimple",
                  "Location of the AD RecHeader");
  declareProperty("PoolRecHeaderLocation", m_poolrecHeaderLocation="/Event/Rec/PoolSimple",
                  "Location of the Pool RecHeader");
  declareProperty("RPCRecHeaderLocation", m_rpcrecHeaderLocation="/Event/Rec/RpcSimple",
                  "Location of the RPC RecHeader");
  declareProperty("MuonAnyLocation", m_muonAnyLocation="/Event/Tag/Muon/MuonAny",
                  "Location of the MuonAny tag");
  declareProperty("FirstMuonTriggerLocation",m_firstMuonTriggerLocation="/Event/Tag/Muon/FirstMuonTrigger",
                  "Location of FirstMuonTrigger tag");
  declareProperty("RetriggerLocation", m_retriggerLocation="/Event/Tag/Muon/Retrigger",
                  "Location of Retrigger tag");
  declareProperty("MuonAllLocation", m_muonAllLocation="/Event/Tag/Muon/MuonAll",
                  "Location of MuonAll tag");
  declareProperty("MuonTagLocation", m_muonTagLocation="/Event/Tag/Physics/MuonLoose",
                  "Location of Muon Tag");

  declareProperty("DtPromptCut", m_dtPromptCut = 300*Gaudi::Units::nanosecond,
                  "Muon prompt time window");
  declareProperty("DtRetriggerCut", m_dtRetriggerCut = 10*Gaudi::Units::microsecond,
                  "Muon retrigger time window");
  declareProperty("IwsNhitCut", m_iwsNhitCut = 6,
                  "IWS Nhit cut");
  declareProperty("OwsNhitCut", m_owsNhitCut = 8,
                  "OWS Nhit cut");
  declareProperty("AdChargeCut", m_adChargeCut = 3000,
                  "AD muon charge cut");

  m_inputHeaders.clear();
  m_lastMuonTime.clear();

  m_firstMuonTime = TimeStamp(0,0);
  m_lastTriggerTime = TimeStamp(0,0);
  m_startCounter = false;
}
MuonTag::~MuonTag ( ) [virtual]

Definition at line 58 of file MuonTag.cc.

{
}

Member Function Documentation

StatusCode MuonTag::initialize ( )

Three mandatory member functions of any algorithm.

Definition at line 62 of file MuonTag.cc.

{
  debug() << "initialize()" << endreq;

  m_jobInfoSvc = svc<IJobInfoSvc>("JobInfoSvc",true);
  if(!m_jobInfoSvc) {
    error() << "Failed to initialize JobInfoSvc" << endreq;
    return StatusCode::FAILURE;
  }
  
  m_inputHeaders.clear();
  m_lastMuonTime.clear();

  m_firstMuonTime = TimeStamp(0,0);
  m_lastTriggerTime = TimeStamp(0,0);
  m_startCounter = false;

  return StatusCode::SUCCESS;
}
StatusCode MuonTag::execute ( )

Definition at line 82 of file MuonTag.cc.

{
  debug() << "execute() ______________________________ start" << endreq;

  const DayaBay::CalibReadoutHeader *calibReadoutHdr = 0;  // DayaBay::CLID_CalibReadoutHeader
  DayaBay::UserDataHeader *calibStatsHdr = 0;  //
  const DayaBay::RecHeader *adrecHdr = 0; 
  const DayaBay::RecHeader *poolrecHdr = 0;
  const DayaBay::RecRpcHeader *rpcrecHdr = 0;

  bool isMuon = false;
  bool isRetrigger = false;
  bool isPreviousMuFinished = false;
  bool isFirstMuonTrigger = false;
  
  if ( !exist<DayaBay::CalibReadoutHeader>(evtSvc(), m_calibHeaderLocation)) {
    warning() << "Cannot find header at " << m_calibHeaderLocation << endreq;
    return StatusCode::FAILURE;
  } else {
    calibReadoutHdr = get<DayaBay::CalibReadoutHeader>(m_calibHeaderLocation);
  } 
       
  if (!exist<DayaBay::UserDataHeader>(evtSvc(), m_calibStatsLocation)) {
    warning() << "Cannot find header at " << m_calibStatsLocation << endreq;
    return StatusCode::FAILURE;
  } else {
    calibStatsHdr = get<DayaBay::UserDataHeader>(m_calibStatsLocation);
  }

  if (!exist<DayaBay::RecHeader>(evtSvc(), m_adrecHeaderLocation)) {
    warning() << "Cannot find header at " << m_adrecHeaderLocation << endreq;
    return StatusCode::FAILURE;
  } else {
    adrecHdr = get<DayaBay::RecHeader>(m_adrecHeaderLocation);
  }

  if (!exist<DayaBay::RecHeader>(evtSvc(), m_poolrecHeaderLocation)) {
    warning() << "Cannot find header at " << m_poolrecHeaderLocation << endreq;
    return StatusCode::FAILURE;
  } else {
    poolrecHdr = get<DayaBay::RecHeader>(m_poolrecHeaderLocation);
  }


  if (!exist<DayaBay::RecRpcHeader>(evtSvc(), m_rpcrecHeaderLocation)) {
    warning() << "Cannot find header at " << m_rpcrecHeaderLocation << endreq;
    return StatusCode::FAILURE;
  } else {
    rpcrecHdr = get<DayaBay::RecRpcHeader>(m_rpcrecHeaderLocation);
  }

  float nPESum = calibStatsHdr->getFloat("NominalCharge");
  int nHit = calibStatsHdr->getInt("nHit");
  
  isMuon = false;

  DetectorId::DetectorId_t detectorId = calibReadoutHdr->context().GetDetId(); 

  const DayaBay::CalibReadout* calibReadout = calibReadoutHdr->calibReadout();

  if (!calibReadout) {
    warning() << "No CalibReadout retrieved this cycle." << endreq;
    return StatusCode::FAILURE;
  }
    
  const DayaBay::Trigger::TriggerType_t triggerType 
    = calibReadout->triggerType();

  bool isMultiTrigger = (triggerType & DayaBay::Trigger::kMult) != DayaBay::Trigger::kNone;
  bool isCrossTrigger = (triggerType & DayaBay::Trigger::kCross) != DayaBay::Trigger::kNone;

  if (detectorId == DetectorId::kIWS) {
    if ((nHit >= m_iwsNhitCut) && (isMultiTrigger && (!isCrossTrigger))) isMuon = true;
  } else if (detectorId == DetectorId::kOWS) {
    if ((nHit >= m_owsNhitCut) && (isMultiTrigger && (!isCrossTrigger))) isMuon = true;
  } else if (detectorId == DetectorId::kRPC) {
    if((triggerType & DayaBay::Trigger::kRPC3of4) != DayaBay::Trigger::kNone) {
      isMuon = true;
    }
  } else if (detectorId==DetectorId::kAD1 || detectorId == DetectorId::kAD2
             || detectorId == DetectorId::kAD3 || detectorId == DetectorId::kAD4) {
    if (nPESum > m_adChargeCut) isMuon = true;
  } else {
    warning() << "Unknown detector of this Readout:" << detectorId << endreq;
    return StatusCode::FAILURE;
  }

  if (isMuon) {
    DayaBay::HeaderObject *header = new DayaBay::HeaderObject();
    std::vector<const DayaBay::IHeader*> inputHeaders;
    inputHeaders.push_back(calibReadoutHdr);
    inputHeaders.push_back(calibStatsHdr);
    inputHeaders.push_back(adrecHdr);
    inputHeaders.push_back(poolrecHdr);
    inputHeaders.push_back(rpcrecHdr);
    header->setInputHeaders(inputHeaders);
    header->setExecNumber(calibReadoutHdr->execNumber());
    header->setContext(calibReadoutHdr->context());
    header->setEarliest(calibReadoutHdr->earliest());
    header->setLatest(calibReadoutHdr->latest());

    const DayaBay::JobId &m_currentJobId = m_jobInfoSvc->currentJobInfo()->jobId();
    header->setJobId(m_currentJobId);

    put(header, m_muonAnyLocation);
  }

  isRetrigger = false;

  std::map<DetectorId::DetectorId_t, TimeStamp>::const_iterator iter = m_lastMuonTime.find(detectorId);

  if (iter!=m_lastMuonTime.end()) {
    TimeStamp tsp = calibReadoutHdr->context().GetTimeStamp();
    tsp.Subtract(iter->second);
    
    if (tsp.GetSeconds()*Gaudi::Units::second < m_dtRetriggerCut) {
      DayaBay::HeaderObject *header = new DayaBay::HeaderObject();
      std::vector<const DayaBay::IHeader*> inputHeaders;
      inputHeaders.push_back(calibReadoutHdr);
      inputHeaders.push_back(calibStatsHdr);
      inputHeaders.push_back(adrecHdr);
      inputHeaders.push_back(poolrecHdr);
      inputHeaders.push_back(rpcrecHdr);
      header->setInputHeaders(inputHeaders);
      header->setExecNumber(calibReadoutHdr->execNumber());
      header->setContext(calibReadoutHdr->context());
      header->setEarliest(calibReadoutHdr->earliest());
      header->setLatest(calibReadoutHdr->latest());
      
      const DayaBay::JobId &m_currentJobId = m_jobInfoSvc->currentJobInfo()->jobId();
      header->setJobId(m_currentJobId);

      put(header, m_retriggerLocation);

      isRetrigger = true;
    }
  }
  
  isPreviousMuFinished = false;
  
  if ( !m_firstMuonTime.IsNull() && m_startCounter ) {
    
    TimeStamp tsp = calibReadoutHdr->context().GetTimeStamp();
    tsp.Subtract(m_firstMuonTime);
    
    if (tsp.GetSeconds()*Gaudi::Units::second > m_dtPromptCut) {
      if (m_inputHeaders.size()>0) {
        {
          DayaBay::HeaderObject *header = new DayaBay::HeaderObject();
          header->setInputHeaders(m_inputHeaders);
          header->setExecNumber(calibReadoutHdr->execNumber());
          header->setContext( dynamic_cast<const DayaBay::HeaderObject*>(m_inputHeaders[0])->context() );
          header->setEarliest( dynamic_cast<const DayaBay::HeaderObject*>(m_inputHeaders[0])->earliest() );
          header->setLatest( dynamic_cast<const DayaBay::HeaderObject*>(m_inputHeaders[m_inputHeaders.size()-1])->latest() );

          const DayaBay::JobId &m_currentJobId = m_jobInfoSvc->currentJobInfo()->jobId();
          header->setJobId(m_currentJobId);
          put(header, m_muonAllLocation);
        }
        
        {
          DayaBay::HeaderObject *header = new DayaBay::HeaderObject();
          header->setInputHeaders(m_inputHeaders);
          header->setExecNumber(calibReadoutHdr->execNumber());
          header->setContext( dynamic_cast<const DayaBay::HeaderObject*>(m_inputHeaders[0])->context() );
          header->setEarliest( dynamic_cast<const DayaBay::HeaderObject*>(m_inputHeaders[0])->earliest() );
          header->setLatest( dynamic_cast<const DayaBay::HeaderObject*>(m_inputHeaders[m_inputHeaders.size()-1])->latest() );

          const DayaBay::JobId &m_currentJobId = m_jobInfoSvc->currentJobInfo()->jobId();
          header->setJobId(m_currentJobId);
          put(header, m_muonTagLocation);
        }

        m_startCounter = false;
        m_inputHeaders.clear();
        isPreviousMuFinished = true;
      }
    }
  }

  isFirstMuonTrigger = false;

  if (isMuon && !isRetrigger) {
    const DayaBay::HeaderObject* muonAnyHeader = get<DayaBay::HeaderObject>(m_muonAnyLocation);
    const std::vector<const DayaBay::IHeader *> inputheaders = muonAnyHeader->inputHeaders();
    
    for (unsigned int iheader=0; iheader<inputheaders.size(); iheader++) {
      m_inputHeaders.push_back(inputheaders[iheader]);
    }
    
    if (m_firstMuonTime.IsNull()) {
      isFirstMuonTrigger = true;
    } else {
      TimeStamp tsp = calibReadoutHdr->context().GetTimeStamp();
      tsp.Subtract(m_firstMuonTime);
      
      if (tsp.GetSeconds()*Gaudi::Units::second > m_dtPromptCut) {
        isFirstMuonTrigger = true;
      }
    }
    
    if (isFirstMuonTrigger) {
      DayaBay::HeaderObject *header = new DayaBay::HeaderObject();
      std::vector<const DayaBay::IHeader*> inputHeaders;
      inputHeaders.push_back(calibReadoutHdr);
      inputHeaders.push_back(calibStatsHdr);
      inputHeaders.push_back(adrecHdr);
      inputHeaders.push_back(poolrecHdr);
      inputHeaders.push_back(rpcrecHdr);
      header->setInputHeaders(inputHeaders);
      header->setExecNumber(calibReadoutHdr->execNumber());
      header->setContext(calibReadoutHdr->context());
      header->setEarliest(calibReadoutHdr->earliest());
      header->setLatest(calibReadoutHdr->latest());

      const DayaBay::JobId &m_currentJobId = m_jobInfoSvc->currentJobInfo()->jobId();
      header->setJobId(m_currentJobId);

      put(header, m_firstMuonTriggerLocation);
      m_startCounter = true;
    }
  }

  float dtTrig = 0;
 
  if (!m_lastTriggerTime.IsNull()) {
    TimeStamp tsp = calibReadoutHdr->context().GetTimeStamp();
    tsp.Subtract(m_lastTriggerTime);
    dtTrig = tsp.GetSeconds() * Gaudi::Units::second / Gaudi::Units::microsecond;
  }

  debug() << dtTrig << " " << detectorId;
  
  if (isFirstMuonTrigger) {
    debug () << " FirstMu ";
  }

  if (isMuon) {
    debug() << " AnyMu";
  }

  if (isRetrigger) {
    debug() << " Retrigger";
  }

  if (isPreviousMuFinished) {
    debug() << " PreviousMuFinished";
  }
  debug() << endreq;
  
  if (isMuon && !isRetrigger) {
    m_lastMuonTime[detectorId] = calibReadoutHdr->context().GetTimeStamp();
    if (isFirstMuonTrigger) {
      m_firstMuonTime = calibReadoutHdr->context().GetTimeStamp();
    }
  }

  m_lastTriggerTime = calibReadoutHdr->context().GetTimeStamp();
  
  debug() << "execute() ______________________________ end" << endreq;
  return StatusCode::SUCCESS;
}
StatusCode MuonTag::finalize ( )

Definition at line 345 of file MuonTag.cc.

{
  debug() << "finalize()" << endreq;
  return StatusCode::SUCCESS;
}

Member Data Documentation

Definition at line 30 of file MuonTag.h.

std::vector<const DayaBay::IHeader*> MuonTag::m_inputHeaders [private]

Definition at line 31 of file MuonTag.h.

Definition at line 32 of file MuonTag.h.

Definition at line 33 of file MuonTag.h.

Definition at line 34 of file MuonTag.h.

bool MuonTag::m_startCounter [private]

Definition at line 35 of file MuonTag.h.

std::string MuonTag::m_calibHeaderLocation [private]

Definition at line 36 of file MuonTag.h.

std::string MuonTag::m_calibStatsLocation [private]

Definition at line 37 of file MuonTag.h.

std::string MuonTag::m_adrecHeaderLocation [private]

Definition at line 38 of file MuonTag.h.

std::string MuonTag::m_poolrecHeaderLocation [private]

Definition at line 39 of file MuonTag.h.

std::string MuonTag::m_rpcrecHeaderLocation [private]

Definition at line 40 of file MuonTag.h.

std::string MuonTag::m_muonAnyLocation [private]

Definition at line 41 of file MuonTag.h.

std::string MuonTag::m_firstMuonTriggerLocation [private]

Definition at line 42 of file MuonTag.h.

std::string MuonTag::m_retriggerLocation [private]

Definition at line 43 of file MuonTag.h.

std::string MuonTag::m_muonAllLocation [private]

Definition at line 44 of file MuonTag.h.

std::string MuonTag::m_muonTagLocation [private]

Definition at line 45 of file MuonTag.h.

float MuonTag::m_dtPromptCut [private]

Definition at line 46 of file MuonTag.h.

float MuonTag::m_dtRetriggerCut [private]

Definition at line 47 of file MuonTag.h.

int MuonTag::m_owsNhitCut [private]

Definition at line 48 of file MuonTag.h.

int MuonTag::m_iwsNhitCut [private]

Definition at line 49 of file MuonTag.h.

float MuonTag::m_adChargeCut [private]

Definition at line 50 of file MuonTag.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:10:28 for MuonTagging by doxygen 1.7.4