/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 Member Functions | Private Attributes
IBDSelectAlg Class Reference

#include <IBDSelectAlg.h>

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

List of all members.

Public Member Functions

 IBDSelectAlg (const std::string &name)
virtual ~IBDSelectAlg ()
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 Member Functions

bool fillIbd (const std::vector< PhyEvent * > &evtGroup)
bool fillSingles (const std::vector< PhyEvent * > &evtGroup)
bool isVetoedByWp (PhyEvent *event)

Private Attributes

PhyEventBufm_buffer
LiveTimeSvcm_liveTimeSvc
MuonVetom_muonVeto
std::vector< PhyEvent * > m_adBuf [4]
TTree * m_tree
double m_tep
double m_txp
double m_typ
double m_tzp
double m_ten
double m_txn
double m_tyn
double m_tzn
double m_tdt
int m_tdet
int m_tpfile
int m_tpentry
int m_tnfile
int m_tnentry
int m_tptrignum
int m_tntrignum
int m_tn
TH1F * m_ibdNum [4]
TH1F * m_hPSingles [4]
TH1F * m_hNSingles [4]
bool m_saveTree
double m_eplow
double m_ephigh
double m_edlow
double m_edhigh
double m_dtlow
double m_dthigh
long int m_nibd [4]
long int m_npsingles [4]
long int m_nnsingles [4]

Detailed Description

Definition at line 14 of file IBDSelectAlg.h.


Constructor & Destructor Documentation

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

Definition at line 16 of file IBDSelectAlg.cc.

: AlgBase(name)
{
  setOption("SaveTree",m_saveTree=true);  
  setOption("PromptEngLow",m_eplow=0.7);  
  setOption("PromptEngHigh",m_ephigh=12.);  
  setOption("DelayedEngLow",m_edlow=6.);  
  setOption("DelayedEngHigh",m_edhigh=12.);  
  setOption("DtLow",m_dtlow=1.e-6);  
  setOption("DtHigh",m_dthigh=2.e-4);  

  for(int det=1;det<=GlobalVar::NumADs;det++) {
    m_adBuf[det-1].clear();    
    m_nibd[det-1] = 0;
    m_npsingles[det-1] = 0;
    m_nnsingles[det-1] = 0;
  }
}
virtual IBDSelectAlg::~IBDSelectAlg ( ) [inline, virtual]

Definition at line 18 of file IBDSelectAlg.h.

{}

Member Function Documentation

bool IBDSelectAlg::initialize ( ) [virtual]

Implements AlgBase.

Definition at line 35 of file IBDSelectAlg.cc.

{
  LogInfo << "initialize()" << endl;
  m_buffer = dynamic_cast<PhyEventBuf*>(service("Cycler"));
  m_liveTimeSvc = dynamic_cast<LiveTimeSvc*>(service("LiveTimeSvc"));
  if(!m_liveTimeSvc) {
    LogError << "Can't get LiveTimeSvc." << endl;
    return false;
  }
  m_muonVeto = MuonVeto::instance();

  for(int det=1;det<=GlobalVar::NumADs;det++) {
    ostringstream sibd;
    sibd << "AD" << det << "IbdNum";
    m_ibdNum[det-1] = new TH1F(sibd.str().c_str(),"IBD number",
        m_liveTimeSvc->nBins(),
        m_liveTimeSvc->startTime().AsDouble(),
        m_liveTimeSvc->endTime().AsDouble()
        );
    ostringstream sps,sns;
    sps << "AD" << det << "ps";
    sns << "AD" << det << "ns";
    m_hPSingles[det-1] = new TH1F(sps.str().c_str(),"Prompt like singles",100,m_eplow,m_ephigh);
    m_hNSingles[det-1] = new TH1F(sns.str().c_str(),"Neutron like singles",100,m_edlow,m_edhigh);
    ntupleSvc()->attach("FILE1/hem/IBD/",m_ibdNum[det-1]);
    ntupleSvc()->attach("FILE1/hem/Singles/",m_hPSingles[det-1]);
    ntupleSvc()->attach("FILE1/hem/Singles/",m_hNSingles[det-1]);
  }

  if(m_saveTree) {
    m_tree = new TTree("ibd","ibd");
    m_tree->Branch("ep",&m_tep,"ep/D");
    m_tree->Branch("xp",&m_txp,"xp/D");
    m_tree->Branch("yp",&m_typ,"yp/D");
    m_tree->Branch("zp",&m_tzp,"zp/D");
    m_tree->Branch("en",&m_ten,"en/D");
    m_tree->Branch("xn",&m_txn,"xn/D");
    m_tree->Branch("yn",&m_tyn,"yn/D");
    m_tree->Branch("zn",&m_tzn,"zn/D");
    m_tree->Branch("dt",&m_tdt,"dt/D");
    m_tree->Branch("det",&m_tdet,"det/I");
    m_tree->Branch("pfile",&m_tpfile,"pfile/I");
    m_tree->Branch("pentry",&m_tpentry,"pentry/I");
    m_tree->Branch("nfile",&m_tnfile,"nfile/I");
    m_tree->Branch("nentry",&m_tnentry,"nentry/I");
    m_tree->Branch("ptrignum",&m_tptrignum,"ptrignum/I");
    m_tree->Branch("ntrignum",&m_tntrignum,"ntrignum/I");
    m_tree->Branch("tn",&m_tn,"tn/I");
    ntupleSvc()->attach("FILE1/hem/tree/",m_tree);
  }

  return true;
}
bool IBDSelectAlg::execute ( ) [virtual]

Implements AlgBase.

Definition at line 102 of file IBDSelectAlg.cc.

{

  // Get current event
  PhyEvent *event = m_buffer->curEvt();
  //event->print();

  LogDebug << "------entry=" << event->m_entry
    << ", " << event
    << ", fileNum=" << event->m_fileNum
    << ", local entry=" << event->m_localEntry
    << ", trigtime=" << event->m_trigTime
    << ", trigNum=" << event->m_trigNum
    << ", det=" << event->m_det 
    << ", energy=" << event->energy()
    << ", flasherTag=" << event->m_flasherTag 
    << ", 2inchFlasherTag=" << event->m_2inchFlasherTag
    << ", forceTrigTag=" << event->m_forceTrigTag
    << ", crossTrigTag=" << event->m_crossTrigTag
    << ", rpcNoiseTag=" << event->m_rpcNoiseTag
    << ", adLowEnergyTag=" << event->m_adLowEnergyTag
    << ", goodevent=" << event->m_good
    << ", muontag=" << event->m_muonTag
    << endl;

  LogDebug << "Print event in buffer." << endl;
  for(int det=1;det<=GlobalVar::NumADs;det++) {
    LogDebug << "Det: " << det << endl;
    for(unsigned int j=0;j<m_adBuf[det-1].size();j++) {
      LogDebug << j << "," << m_adBuf[det-1][j] << "," 
        << m_adBuf[det-1][j]->m_det << "," << m_adBuf[det-1][j]->m_entry << endl;
    }
  }

  if(!event->isAD()) {
    LogDebug << "Skip none AD event." << endl;
    return true;
  }

  if(!event->m_good) {
    // 5 types of events are defined as "bad" by default: 
    // flasher, force trigger, cross trigger, RPC 2/4, AD energy < 0.7MeV
    // you can use following equivalent statement:
    //if(event->m_flasherTag || event->m_2inchFlasherTag
    //    || event->energy < m_eplow || event->m_rpcNoiseTag
    //    || event->m_forceTrigTag || event->m_crossTrigTag) 
    LogDebug << "Skip bad event." << endl;
    return true;
  }

  if(event->isMuon()) {
    LogDebug << "Skip muon event." << endl;
    return true;
  }

  // Veto [-2us,200us] for WP muon
  DataBuffer<PhyEvent>::Iterator it=m_buffer->find(event);
  it--;
  while ( it >= m_buffer->begin() ) {
    PhyEvent* evt = (*it);
    double dt = event->m_trigTime - evt->m_trigTime;
    if(dt>2.e-4) break;
    if(evt->isMuon() && (evt->m_det==5 || evt->m_det==6)) {
      if(dt <= 2.e-4) {
        LogDebug << "Veto this event by WP muon in the first step." << endl;
        return true;
      }
    }
    it--;
  }

  it=m_buffer->find(event);
  it++;
  while ( it < m_buffer->end() ) {
    PhyEvent* evt = (*it);
    double dt = evt->m_trigTime - event->m_trigTime;
    if(dt>2.e-6) break;
    if(evt->isMuon() && (evt->m_det==5 || evt->m_det==6)) {
      if(dt <= 2.e-6) {
        LogDebug << "Veto this event by WP muon in the first step." << endl;
        return true;
      }
    }
    it++;
  }

  // Make a user tag if this event is vetoed by 
  // WP muon: [-2us,600us]
  // AD muon: [0,1ms]
  // AD shower muon: [0,1s]
  event->m_userTag["MuonVeto"] = 0.;
  if(m_muonVeto->veto(event)) {
    LogDebug << "This event is in muon veto window." << endl;
    event->m_userTag["MuonVeto"] = 1.;
  }

  // Multi-coincidence(event group) selection
  PhyEvent *lastEvt = 0;
  if(!m_adBuf[event->m_det-1].empty()) {
    lastEvt = m_adBuf[event->m_det-1][m_adBuf[event->m_det-1].size()-1];
  } else {
    LogDebug << "push_back: " << event->m_entry << endl;
    LogDebug << "Empty buffer. Either this is the first event or something wrong." << endl;
    // GrabInstance() is used as a smart pointer, 
    // to make sure event in local buffer will not be deleted,
    // even if it's out of the buffer time window
    m_adBuf[event->m_det-1].push_back(event->GrabInstance());
    return true;
  }

  if(lastEvt) {
    double t2last = event->m_trigTime - lastEvt->m_trigTime;
    if(t2last > m_dthigh) { // find a time gap, deal with events in buffer
      if(m_adBuf[event->m_det-1].size()==2) {
        fillIbd(m_adBuf[event->m_det-1]);
      } else if(m_adBuf[event->m_det-1].size()==1) {
        fillSingles(m_adBuf[event->m_det-1]);
      }
      // Release the smart pointer when this event is removed from local buffer,
      // to make sure no memory leak
      for(unsigned int i=0;i<m_adBuf[event->m_det-1].size();i++) {
        m_adBuf[event->m_det-1][i]->ReleaseInstance();
      }
      m_adBuf[event->m_det-1].clear();
    } 
    LogDebug << "push_back: " << event->m_entry << endl;
    m_adBuf[event->m_det-1].push_back(event->GrabInstance());
  } else {
    LogError << "Can't find last event. Check your code." << endl;
  }

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

Implements AlgBase.

Definition at line 89 of file IBDSelectAlg.cc.

{
  LogInfo << "finalize()" << endl;
  for(int det=1;det<=GlobalVar::NumADs;det++) {
    LogInfo << "IBD candidates in AD " << det << ": " << m_nibd[det-1] << endl;
    LogInfo << "Prompt-like singles in AD " << det << ": " << m_npsingles[det-1] 
      << " (" << m_npsingles[det-1]/m_liveTimeSvc->hLiveTime(det)->Integral() << " Hz)" << endl;
    LogInfo << "Neutron-like singles in AD " << det << ": " << m_nnsingles[det-1]
      << ", (" << 86400.*m_nnsingles[det-1]/m_liveTimeSvc->hLiveTime(det)->Integral() << " /day)" << endl;
  }
  return true;
}
bool IBDSelectAlg::fillIbd ( const std::vector< PhyEvent * > &  evtGroup) [private]

Definition at line 158 of file DMCIBDSelectAlg.cc.

                                                               {

  LogDebug << "Multiplicity of event group: " << evtGroup.size() << endl;

  // for each neutron-like event, find "e+"-like coincidence
  for(unsigned i=1;i<evtGroup.size();i++) { // the first event can't be neutron

    // Find neutron-like event
    if(evtGroup[i]->energy()<=m_edlow) {
      LogDebug << "This is not a neutron(E<6MeV)." << endl;
      continue;
    }

    // Apply muon veto on neutron-like event
    if(evtGroup[i]->m_userTag["MuonVeto"]>0) {
      LogDebug << "Veto delayed signal by muon." << endl;
      continue;
    }

    // Time interval cut: 1us~200us
    double dt = evtGroup[i]->m_trigTime - evtGroup[i-1]->m_trigTime;
    if(dt<=m_dtlow || dt>=m_dthigh) {
      LogDebug << "Time interval cut(1us~200us) is not satisfied: " 
        << dt*1.e6 << " us" << endl;
      continue;
    }

    // No more "e+"-like event before neutron in 400us window
    if(i>=2) {
      dt = evtGroup[i]->m_trigTime - evtGroup[i-2]->m_trigTime;
      if(dt<=2*m_dthigh) {
        LogDebug << "Find another prompt signal in previous 400us window: "
          << dt*1.e6 << " us" << endl;
        continue;
      }
    }

    // No neutron-like event after neutron in 200us window
    // If this neutron-like event is vetoed by muon, it will be ignored.
    if(i<evtGroup.size()-1) {
      if(evtGroup[i+1]->energy()>m_edlow && !(evtGroup[i+1]->m_userTag["MuonVeto"]>0)) {
        dt = evtGroup[i+1]->m_trigTime - evtGroup[i]->m_trigTime;
        if(dt<=m_dthigh) {
          LogDebug << "Find another delayed signal in following 200us window: "
            << dt*1.e6 << " us" << endl;
          continue;
        }
      }
    }

    // Find an IBD candidate
    PhyEvent *dEvt = evtGroup[i];
    PhyEvent *pEvt = evtGroup[i-1];
    dt = (dEvt->m_trigTime - pEvt->m_trigTime)*1.e6;

    m_tep = pEvt->energy();
    m_txp = pEvt->m_x;
    m_typ = pEvt->m_y;
    m_tzp = pEvt->m_z;
    m_ten = dEvt->energy();
    m_txn = dEvt->m_x;
    m_tyn = dEvt->m_y;
    m_tzn = dEvt->m_z;
    m_tdt = dt;
    m_tdet = dEvt->m_det;
    m_tpfile = pEvt->m_fileNum;
    m_tpentry = pEvt->m_localEntry;
    m_tnfile = dEvt->m_fileNum;
    m_tnentry = dEvt->m_localEntry;
    m_tptrignum = pEvt->m_trigNum;
    m_tntrignum = dEvt->m_trigNum;
    m_tn = dEvt->m_trigTime.GetSec();
    m_tree->Fill();

    LogInfo << "Find an IBD candidate in file " << pEvt->m_fileNum
      << ", local entry " << pEvt->m_localEntry << ", trigNum " << pEvt->m_trigNum
      << ", and file " << dEvt->m_fileNum
      << ", local entry " << dEvt->m_localEntry << ", trigNum " << dEvt->m_trigNum
      << endl;
    LogInfo << "Find an IBD candidate with (det, ep, ed, dt) = ("
      << pEvt->m_det << "," << pEvt->energy() << "," << dEvt->energy()
      << "," << dt << ")" << endl;
  }

  return true;
}
bool IBDSelectAlg::fillSingles ( const std::vector< PhyEvent * > &  evtGroup) [private]

Definition at line 303 of file IBDSelectAlg.cc.

                                                                {

  PhyEvent *evt = evtGroup[0];

  //Apply muon veto on delayed signal
  if(evt->m_userTag["MuonVeto"]>0) {
    LogDebug << "Veto delayed signal by muon." << endl;
    return true;
  }

  // energy cut for prompt like singles
  if(evt->energy()>m_eplow && evt->energy()<m_ephigh) {
    m_npsingles[evt->m_det-1]++;
    m_hPSingles[evt->m_det-1]->Fill(evt->energy());
  }

  // energy cut for neutron like singles
  if(evt->energy()>m_edlow && evt->energy()<m_edhigh) {
    m_nnsingles[evt->m_det-1]++;
    m_hNSingles[evt->m_det-1]->Fill(evt->energy());
  }

  return true;
}
bool IBDSelectAlg::isVetoedByWp ( PhyEvent event) [private]

Member Data Documentation

Definition at line 32 of file IBDSelectAlg.h.

Definition at line 33 of file IBDSelectAlg.h.

Definition at line 34 of file IBDSelectAlg.h.

std::vector<PhyEvent*> IBDSelectAlg::m_adBuf[4] [private]

Definition at line 37 of file IBDSelectAlg.h.

TTree* IBDSelectAlg::m_tree [private]

Definition at line 40 of file IBDSelectAlg.h.

double IBDSelectAlg::m_tep [private]

Definition at line 41 of file IBDSelectAlg.h.

double IBDSelectAlg::m_txp [private]

Definition at line 42 of file IBDSelectAlg.h.

double IBDSelectAlg::m_typ [private]

Definition at line 43 of file IBDSelectAlg.h.

double IBDSelectAlg::m_tzp [private]

Definition at line 44 of file IBDSelectAlg.h.

double IBDSelectAlg::m_ten [private]

Definition at line 45 of file IBDSelectAlg.h.

double IBDSelectAlg::m_txn [private]

Definition at line 46 of file IBDSelectAlg.h.

double IBDSelectAlg::m_tyn [private]

Definition at line 47 of file IBDSelectAlg.h.

double IBDSelectAlg::m_tzn [private]

Definition at line 48 of file IBDSelectAlg.h.

double IBDSelectAlg::m_tdt [private]

Definition at line 49 of file IBDSelectAlg.h.

int IBDSelectAlg::m_tdet [private]

Definition at line 50 of file IBDSelectAlg.h.

int IBDSelectAlg::m_tpfile [private]

Definition at line 51 of file IBDSelectAlg.h.

int IBDSelectAlg::m_tpentry [private]

Definition at line 52 of file IBDSelectAlg.h.

int IBDSelectAlg::m_tnfile [private]

Definition at line 53 of file IBDSelectAlg.h.

int IBDSelectAlg::m_tnentry [private]

Definition at line 54 of file IBDSelectAlg.h.

Definition at line 55 of file IBDSelectAlg.h.

Definition at line 56 of file IBDSelectAlg.h.

int IBDSelectAlg::m_tn [private]

Definition at line 57 of file IBDSelectAlg.h.

TH1F* IBDSelectAlg::m_ibdNum[4] [private]

Definition at line 60 of file IBDSelectAlg.h.

TH1F* IBDSelectAlg::m_hPSingles[4] [private]

Definition at line 61 of file IBDSelectAlg.h.

TH1F* IBDSelectAlg::m_hNSingles[4] [private]

Definition at line 62 of file IBDSelectAlg.h.

bool IBDSelectAlg::m_saveTree [private]

Definition at line 65 of file IBDSelectAlg.h.

double IBDSelectAlg::m_eplow [private]

Definition at line 66 of file IBDSelectAlg.h.

double IBDSelectAlg::m_ephigh [private]

Definition at line 67 of file IBDSelectAlg.h.

double IBDSelectAlg::m_edlow [private]

Definition at line 68 of file IBDSelectAlg.h.

double IBDSelectAlg::m_edhigh [private]

Definition at line 69 of file IBDSelectAlg.h.

double IBDSelectAlg::m_dtlow [private]

Definition at line 70 of file IBDSelectAlg.h.

double IBDSelectAlg::m_dthigh [private]

Definition at line 71 of file IBDSelectAlg.h.

long int IBDSelectAlg::m_nibd[4] [private]

Definition at line 74 of file IBDSelectAlg.h.

long int IBDSelectAlg::m_npsingles[4] [private]

Definition at line 75 of file IBDSelectAlg.h.

long int IBDSelectAlg::m_nnsingles[4] [private]

Definition at line 76 of file IBDSelectAlg.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:43 for IBDSelectAlg by doxygen 1.7.4