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

#include <TimeShiftAlg.h>

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

List of all members.

Public Member Functions

 TimeShiftAlg (const std::string &name)
virtual ~TimeShiftAlg ()
virtual bool initialize ()
virtual bool execute ()
virtual bool finalize ()
const std::string & name ()
SvcBaseservice (const std::string &name)
TOutputSvcntupleSvc ()
bool setOption (const std::string &option, Type &var)

Protected Attributes

std::string m_name

Private Attributes

PhyEventBufm_buffer
PhyEventBufm_muonBuf
int m_tw
int m_stdDet
int m_mulCut
bool m_savePlot
int m_site
TH1I * m_hist [7]
std::string m_rpath

Detailed Description

Definition at line 8 of file TimeShiftAlg.h.


Constructor & Destructor Documentation

TimeShiftAlg::TimeShiftAlg ( const std::string &  name)

Definition at line 13 of file TimeShiftAlg.cc.

    : AlgBase(name),
      m_site(-1)
{
    setOption("TimeWindow", m_tw = 1000);
    setOption("StandardDet", m_stdDet = 5);
    setOption("MultiDet",  m_mulCut = 3);
    setOption("SavePlot",  m_savePlot = false);
    setOption("OutputPrefix",  m_rpath = "");
}
TimeShiftAlg::~TimeShiftAlg ( ) [virtual]

Definition at line 24 of file TimeShiftAlg.cc.

{
}

Member Function Documentation

bool TimeShiftAlg::initialize ( ) [virtual]

Implements AlgBase.

Definition at line 28 of file TimeShiftAlg.cc.

{
    m_buffer = dynamic_cast<PhyEventBuf*>(service("Cycler"));
    m_muonBuf = UserBufMgr::bufWithSelector("MuonSelector");

    char* detName[7] = { "AD1", "AD2", "AD3", "AD4", "IWS", "OWS", "RPC" };
    for ( int i = 0; i < 7; ++i ) {
        if ( i == (m_stdDet-1) ) {
            m_hist[i] = 0;
            continue;
        }
        std::string hName = std::string(detName[i]) + "#rightarrow" + detName[m_stdDet-1];
        m_hist[i] = new TH1I(hName.c_str(), hName.c_str(), 2*m_tw, -m_tw, m_tw);
    }
    return true;
}
bool TimeShiftAlg::execute ( ) [virtual]

Implements AlgBase.

Definition at line 45 of file TimeShiftAlg.cc.

{
    if ( m_muonBuf->totalSize() < 3 ) return true;

    PhyEvent *event = m_muonBuf->curEvt();
    LogDebug << "Muon Buffer size: " << m_muonBuf->totalSize() 
                  << "  Det-" << event->m_det << std::endl;
    if ( event != m_buffer->curEvt() || event->m_det != m_stdDet ) return true;

    int multi = 1;
    int dt[7] = { 9999, 9999, 9999, 9999, 9999, 9999, 9999 };

    for ( PhyEventBuf::Iterator it = m_muonBuf->begin(); it < m_muonBuf->end(); ++it ) {
        LogDebug << "Detector-" << (*it)->m_det << std::endl;
        if ( *it == event ) continue;

        int iDt = int(((*it)->m_trigTime - event->m_trigTime) * 1.e9);

        if ( iDt <= -m_tw ) continue;
        if ( iDt >= m_tw ) break;

        int iDet = (*it)->m_det - 1;
        if ( iDet == (event->m_det-1) || dt[iDet] != 9999 ) continue ;

        dt[iDet] = iDt;
        ++multi;
    }

    if ( multi >= m_mulCut ) {
        for ( int i = 0; i < 7; ++i ) {
            if ( dt[i] != 9999 ) {
                m_hist[i]->Fill(dt[i]);
            }
        }
    }

    if ( m_site < 0 ) m_site = event->m_site;

    return true;
}
bool TimeShiftAlg::finalize ( ) [virtual]

Implements AlgBase.

Definition at line 86 of file TimeShiftAlg.cc.

{
    std::string pshift = m_rpath;
    if ( m_rpath.empty() ) {
        pshift = "TimeShift";
    }

    mkdir(pshift.c_str(), S_IRWXU | S_IRWXG | S_IRWXO );

    if ( m_savePlot ) {
        TCanvas cav("cav", "cav", 1200, 640);
        cav.Divide(3, 2);

        int iPad = 0;
        for ( int i = 0; i < 7; ++i ) {
            if ( m_hist[i] != 0 ) {
                cav.cd(++iPad);
                m_hist[i]->Draw();
            }
        }

        cav.Print( (pshift + "/" + pshift + ".png").c_str() );
    }

    char* siteName[5] = { "Unknown", "DayaBay", "LingAo", "Keep", "Far" };
    char* detName[7]  = { "AD1", "AD2", "AD3", "AD4", "IWS", "OWS", "RPC" };

    for ( int i = 0; i < 7; ++i ) {
        double mean = 0.0;
        if ( m_hist[i] != 0 && m_hist[i]->GetEntries() != 0 ) {
            int mid = m_hist[i]->GetMaximumBin();
            m_hist[i]->GetXaxis()->SetRange(mid-100, mid+100);
            mean = m_hist[i]->GetMean();
            delete m_hist[i];
        }

        std::ofstream ofs( (pshift + '/' + siteName[m_site] + '_' + detName[i] + "_Data.csv").c_str() );
        ofs << "#Table  of  Time Latency between detectors" << std::endl
            << "#[Latency]" << std::endl
            << std::setiosflags(std::ios::fixed) << std::setprecision(1)
            << mean
            << std::endl;
    }

    return true;
}

Member Data Documentation

Definition at line 21 of file TimeShiftAlg.h.

Definition at line 22 of file TimeShiftAlg.h.

int TimeShiftAlg::m_tw [private]

Definition at line 24 of file TimeShiftAlg.h.

int TimeShiftAlg::m_stdDet [private]

Definition at line 25 of file TimeShiftAlg.h.

int TimeShiftAlg::m_mulCut [private]

Definition at line 26 of file TimeShiftAlg.h.

bool TimeShiftAlg::m_savePlot [private]

Definition at line 27 of file TimeShiftAlg.h.

int TimeShiftAlg::m_site [private]

Definition at line 29 of file TimeShiftAlg.h.

TH1I* TimeShiftAlg::m_hist[7] [private]

Definition at line 30 of file TimeShiftAlg.h.

std::string TimeShiftAlg::m_rpath [private]

Definition at line 32 of file TimeShiftAlg.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 09:50:23 for TimeShiftAlg by doxygen 1.7.4