/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
ADCoincFilter Class Reference

#include <ADCoincFilter.h>

Collaboration diagram for ADCoincFilter:
Collaboration graph
[legend]

List of all members.

Public Member Functions

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

Private Attributes

IJobInfoSvcm_jobInfoSvc
IDataProviderSvc * m_archiveSvc
std::map
< DetectorId::DetectorId_t,
std::vector< const
DayaBay::IHeader * > > 
m_inputHeaders
std::map
< DetectorId::DetectorId_t,
TimeStamp
m_lastTimeStamp
int m_nTagged
int m_nSeen
int m_nKept
int m_nKeptMuon
bool m_unPhysicalRun
std::string m_tagADLoc
std::string m_tagMuonLoc
std::string m_recHeaderLoc
double m_timeWindow
double m_muonVetoWindow
double m_muonKeptWindow
double m_maxCoincFraction

Detailed Description

Definition at line 15 of file ADCoincFilter.h.


Constructor & Destructor Documentation

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

Constructor has to be in this form.

Definition at line 21 of file ADCoincFilter.cc.

    : GaudiAlgorithm(name, svcloc),
    m_nTagged(0), m_nSeen(0), m_nKept(0), m_unPhysicalRun(false)
{
    declareProperty("RecLocation", m_recHeaderLoc="/Event/Rec/AdSimple",
            "the TES path of rec header location");
    declareProperty("TagADLocation", m_tagADLoc="/Event/Tag/Physics/CoincidenceTight",
            "the TES path of AD Coincidenc tag header location");
    declareProperty("TagMuonLocation", m_tagMuonLoc="/Event/Tag/Physics/CoincidenceTightRelated",
            "the TES path of Correlated Muon tag header location");
    declareProperty("TimeWindow", m_timeWindow=300*Units::microsecond,
        "AD coincidence time window");
    declareProperty("MuonVetoWindow", m_muonVetoWindow=10*Units::microsecond,
        "muon veto time window");
    declareProperty("MuonKeptWindow", m_muonKeptWindow=300*Units::microsecond,
        "muon kept time window");
    declareProperty("MaxCoincFraction", m_maxCoincFraction=0.5,
        "maximum allowed coincident trigger fraction");
}
ADCoincFilter::~ADCoincFilter ( ) [virtual]

Definition at line 42 of file ADCoincFilter.cc.

{
}

Member Function Documentation

StatusCode ADCoincFilter::initialize ( )

Three mandatory member functions of any algorithm.

Definition at line 47 of file ADCoincFilter.cc.

{
    info() << "initialize: time window: " << m_timeWindow/Units::microsecond << " microseconds" << endreq;    
    info() << "initialize: veto window: " << m_muonVetoWindow/Units::microsecond << " microseconds" << endreq;    

    m_jobInfoSvc = svc<IJobInfoSvc>("JobInfoSvc", true);
    if(!m_jobInfoSvc) {
        error() << "Failed to initialize JobInfoSvc" << endreq;
        return StatusCode::FAILURE;
    }
    
    // init archive event store
    StatusCode sc = service("EventDataArchiveSvc", m_archiveSvc);
    if(sc.isFailure()){
      error() << "Failed to access the Archive event store" << endreq;
      return sc;
    }
    
    // initialize
    m_inputHeaders[DetectorId::kAD1] = vector<const IHeader*>();
    m_inputHeaders[DetectorId::kAD2] = vector<const IHeader*>();
    m_inputHeaders[DetectorId::kAD3] = vector<const IHeader*>();
    m_inputHeaders[DetectorId::kAD4] = vector<const IHeader*>();
    
    return StatusCode::SUCCESS;
}
StatusCode ADCoincFilter::execute ( )

Definition at line 76 of file ADCoincFilter.cc.

{   
    if (m_unPhysicalRun) {
        return StatusCode::SUCCESS; // looks like not a physical run, skip.
    }
    
    RecHeader* recHeader = get<RecHeader>(m_recHeaderLoc);
    if ( !recHeader ) {
        warning() << "Cannot find header at " << m_recHeaderLoc << endreq;
        return StatusCode::FAILURE;
    } 
    
    TimeStamp ts = recHeader->context().GetTimeStamp();
    DetectorId::DetectorId_t detectorId = recHeader->context().GetDetId();
    
    TimeStamp lastTS = ts;
    
    if(m_lastTimeStamp.find(detectorId) != m_lastTimeStamp.end()){
        lastTS = m_lastTimeStamp[detectorId];
    }       
    m_lastTimeStamp[detectorId] = ts;
    
    // info() << detectorId << " " << ts.GetNanoSec() << endreq;
    
    // only look for AD Coincidence
    if (   detectorId == DetectorId::kIWS 
        || detectorId == DetectorId::kOWS 
        || detectorId == DetectorId::kRPC) {
        return StatusCode::SUCCESS; 
    }
    
    TimeStamp dt = TimeStamp(ts);
    dt.Subtract(lastTS);
    if (dt.GetSeconds()*Units::second > m_timeWindow) {
        int multiplicity = m_inputHeaders[detectorId].size();
        if (multiplicity < 2) {
            // found singles, clear the inputHeaders
            m_inputHeaders[detectorId].clear();
        }
        else {
            // found a gap, save last conincidence's multiplets         
            HeaderObject *header = new HeaderObject();
            vector<const IHeader*>& inputHeaders = m_inputHeaders[detectorId];
            header->setInputHeaders(inputHeaders);
            header->setExecNumber(recHeader->execNumber());
            header->setContext(dynamic_cast<const HeaderObject*>(inputHeaders.at(0))->context());
            header->setEarliest(dynamic_cast<const HeaderObject*>(inputHeaders.at(0))->earliest());
            header->setLatest(dynamic_cast<const HeaderObject*>(inputHeaders.at(inputHeaders.size()-1))->latest());
            header->setJobId(m_jobInfoSvc->currentJobInfo()->jobId());

            put(header, m_tagADLoc);
            m_nTagged++;
            m_nKept += multiplicity;
            // info() << "found one: multiplicty: " << multiplicity << endreq;
            
            
            // create correlated muon tags
            HeaderObject *header2 = new HeaderObject();
            vector<const IHeader*> muonInputHeaders = vector<const IHeader*>();
            DybArchiveList* arcList = get<DybArchiveList*>(m_archiveSvc, "/Event/Readout/ReadoutHeader");
            if(!arcList){
                error() << "Failed to get archive of ReadoutHeader" << endreq;
                return StatusCode::FAILURE;
            }
            TimeStamp firstCoincTS = dynamic_cast<const HeaderObject*>(inputHeaders.at(0))->timeStamp();
            TimeStamp lastCoincTS  = dynamic_cast<const HeaderObject*>(inputHeaders.at(inputHeaders.size()-1))->timeStamp();
            for(unsigned int headerIdx=0; headerIdx<arcList->size(); headerIdx++){
                  ReadoutHeader* arcHeader = dynamic_cast<ReadoutHeader*>(arcList->dataObject(headerIdx));
                  if(!arcHeader) {
                      error() << "Invalid ReadoutHeader in AES!" << endreq;
                      return StatusCode::FAILURE;
                  }
                  DetectorId::DetectorId_t detId = arcHeader->context().GetDetId();
                  if ( detId == DetectorId::kIWS || detId == DetectorId::kOWS || detId == DetectorId::kRPC) {
                      TimeStamp arcTS = arcHeader->timeStamp();
                      TimeStamp dtLastCoinc = TimeStamp(arcTS);
                      dtLastCoinc.Subtract(lastCoincTS);
                      TimeStamp dtFirstCoinc = TimeStamp(arcTS);
                      dtFirstCoinc.Subtract(firstCoincTS);
                      if (dtLastCoinc.GetSeconds() > 0) { 
                          continue; 
                      }
                      else if (dtLastCoinc.GetSeconds()*Units::second > -m_muonKeptWindow ) {
                          // info() << "muon saved: " << detId << " " << arcTS.GetNanoSec() << endreq;
                          muonInputHeaders.push_back(arcHeader);
                      }
                      else { 
                          break; 
                      }
                  }
            }
            header2->setInputHeaders(muonInputHeaders); // muonHeaders may be empty
            header2->setExecNumber(recHeader->execNumber());
            header2->setContext(recHeader->context());
            header2->setEarliest(recHeader->earliest());
            header2->setLatest(recHeader->latest());
            header2->setJobId(m_jobInfoSvc->currentJobInfo()->jobId());
            put(header2, m_tagMuonLoc);
            m_nKeptMuon += muonInputHeaders.size();
            
            // clear the inputHeaders
            m_inputHeaders[detectorId].clear();
        }
    }
    
    // muon veto
    TimeStamp dt_IWS = TimeStamp(ts);
    if(m_lastTimeStamp.find(DetectorId::kIWS) != m_lastTimeStamp.end()){
        dt_IWS.Subtract(m_lastTimeStamp[DetectorId::kIWS]);
    }
    TimeStamp dt_OWS = TimeStamp(ts);
    if(m_lastTimeStamp.find(DetectorId::kOWS) != m_lastTimeStamp.end()){
        dt_OWS.Subtract(m_lastTimeStamp[DetectorId::kOWS]);
    }
    if (!(dt_IWS*Units::second < m_muonVetoWindow && dt_OWS*Units::second < m_muonVetoWindow)) {
        m_inputHeaders[detectorId].push_back(recHeader);    
    }
    
    // catch unphysical runs
    m_nSeen++;
    if (float(m_nKept)/m_nSeen > m_maxCoincFraction && m_nSeen > 1000) {
        m_unPhysicalRun = true;
        warning() << "saw " << m_nKept << " coincident triggers out of " << m_nSeen
            << " total. This is unphysical, disabling IBD Filter Tag" << endreq;
    }

    return StatusCode::SUCCESS;
}
StatusCode ADCoincFilter::finalize ( )

Definition at line 206 of file ADCoincFilter.cc.

{
    info() << m_nTagged << " multiplets (" << m_nKept << " triggers) tagged at " << m_tagADLoc 
           << " out of " << m_nSeen << " triggers" << endreq;
    info() << m_nKeptMuon << " muon triggers kept"<< endreq;

    return StatusCode::SUCCESS;
}

Member Data Documentation

Definition at line 28 of file ADCoincFilter.h.

IDataProviderSvc* ADCoincFilter::m_archiveSvc [private]

Definition at line 29 of file ADCoincFilter.h.

std::map<DetectorId::DetectorId_t, std::vector<const DayaBay::IHeader*> > ADCoincFilter::m_inputHeaders [private]

Definition at line 30 of file ADCoincFilter.h.

Definition at line 31 of file ADCoincFilter.h.

int ADCoincFilter::m_nTagged [private]

Definition at line 32 of file ADCoincFilter.h.

int ADCoincFilter::m_nSeen [private]

Definition at line 33 of file ADCoincFilter.h.

int ADCoincFilter::m_nKept [private]

Definition at line 34 of file ADCoincFilter.h.

Definition at line 35 of file ADCoincFilter.h.

Definition at line 36 of file ADCoincFilter.h.

std::string ADCoincFilter::m_tagADLoc [private]

Definition at line 39 of file ADCoincFilter.h.

std::string ADCoincFilter::m_tagMuonLoc [private]

Definition at line 40 of file ADCoincFilter.h.

std::string ADCoincFilter::m_recHeaderLoc [private]

Definition at line 41 of file ADCoincFilter.h.

double ADCoincFilter::m_timeWindow [private]

Definition at line 42 of file ADCoincFilter.h.

Definition at line 43 of file ADCoincFilter.h.

Definition at line 44 of file ADCoincFilter.h.

Definition at line 45 of file ADCoincFilter.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:46 for ADCoincTagging by doxygen 1.7.4