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

#include <EvtDspAlg.h>

Collaboration diagram for EvtDspAlg:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 EvtDspAlg (const std::string &name, ISvcLocator *pSvcLocator)
 EvtDspAlg.
virtual ~EvtDspAlg ()
virtual StatusCode initialize ()
virtual StatusCode execute ()
virtual StatusCode finalize ()

Private Member Functions

StatusCode processSimHeader (const SimHeader *pSimHeader)
StatusCode processReadoutHeader (const ReadoutHeader *pReadoutHeader)
StatusCode processCalibReadoutHeader (const CalibReadoutHeader *pCalibReadoutHeader)

Private Attributes

TimeStamp m_t0
 t0 of this set of data
string m_headerName
 The header object's name to display.
CLID m_headerType
string m_headerPath
bool m_selection
 Do some simple selection (add some cuts and/or calibration)?
IEvtDspm_evtDsp
 Evt Dsp tool;.
ICableSvcm_cableSvc
 Cable mapping service.
TimeStamp m_lastTriggerT
 Event grouper.
double m_deltaT
map< DetectorId::DetectorId_t,
bool > 
m_cvsOccupied

Detailed Description

Definition at line 24 of file EvtDspAlg.h.


Constructor & Destructor Documentation

EvtDspAlg::EvtDspAlg ( const std::string &  name,
ISvcLocator *  pSvcLocator 
)

EvtDspAlg.

Aug. 5, 2009 created by Zhe Wang

Definition at line 14 of file EvtDspAlg.cc.

                                                                   :
  GaudiAlgorithm(name, pSvcLocator)
{
  declareProperty("Header", m_headerName = "ReadoutHeader",
                  "HeaderObject to display: ReadoutHeader and SimHeader");
  declareProperty("Selection", m_selection = true,
                  "Apply some cuts and do some simple calibration");

}
EvtDspAlg::~EvtDspAlg ( ) [virtual]

Definition at line 24 of file EvtDspAlg.cc.

{
}

Member Function Documentation

StatusCode EvtDspAlg::initialize ( ) [virtual]

Display tool

Cable service

The header type to use

Definition at line 28 of file EvtDspAlg.cc.

{
  StatusCode sc;

  sc = toolSvc()->retrieveTool("EvtDsp","EvtDsp",m_evtDsp);
  if( sc.isFailure() ) {
    error() << "Error retrieving the tool"<< "EvtDsp" << endreq;
    return sc;
  }

  sc = service("StaticCableSvc",m_cableSvc);
  if( sc.isFailure() ) {
    error() << "Can't get StaticCableSvc" << endreq;
    return sc;
  }
  
  if( m_headerName == "ReadoutHeader" )  {
    m_headerType = CLID_ReadoutHeader;
    m_headerPath = ReadoutHeader::defaultLocation();
  } else if ( m_headerName == "SimHeader" )  {
    m_headerType = CLID_SimHeader;
    m_headerPath = SimHeader::defaultLocation();
  } else if ( m_headerName == "CalibReadoutHeader" )  {
    m_headerType = CLID_CalibReadoutHeader;
    m_headerPath = CalibReadoutHeader::defaultLocation();
  }

  m_lastTriggerT = TimeStamp::GetBOT();
  m_deltaT = 2e-6;             // 1 micro second
  m_cvsOccupied.clear();       // No canvas is in use at the beginning
    
  return this->GaudiAlgorithm::initialize();  
}
StatusCode EvtDspAlg::execute ( ) [virtual]

Check SimHeader

Check ReadoutHeader

Check CalibReadoutHeader

Decide when to pause and then flush last plots ----------------------------------------------

only plot stuff belong to one event! Otherwise jump to next event.

this detector is going to be plotted

Add plot for new readouts Check SimHeader

Check ReadoutHeader

CalibReadoutHeader

Definition at line 65 of file EvtDspAlg.cc.

{
  debug()<<"Executing ... "<<endreq;

  StatusCode   sc;
  DataObject   *pObject;

  DetectorId::DetectorId_t current_det;
  TimeStamp current_T;
  
  const SimHeader        *pSimHeader=0;
  if( m_headerType == CLID_SimHeader ) {

    sc=eventSvc()->retrieveObject( m_headerPath, pObject );
    if(sc.isFailure()) {
      error()<<"No SimHeader for this event"<<endreq;
      return StatusCode::FAILURE;
    }

    const GenHeader        *pGenHeader=0;
    
    const IHeader* firstHeader=0;
    
    pSimHeader = dynamic_cast<SimHeader*>(pObject);
    
    // get the header object pointer of it lower stages
    // only the first one, for low event rate, it is enough
    if(pSimHeader!=0) {
      // GenHeader
      if(pSimHeader->inputHeaders().size() != 0) {
        firstHeader=*((pSimHeader->inputHeaders()).begin());
        pGenHeader= dynamic_cast<const GenHeader*>(firstHeader);
      }
    }  
  }

  const ReadoutHeader* pReadoutHeader=0;
  if( m_headerType == CLID_ReadoutHeader ) {
    
    sc=eventSvc()->retrieveObject( m_headerPath, pObject );
    if(sc.isFailure()) {
      error()<<"No ReadoutHeader for this event"<<endreq;
      return StatusCode::FAILURE;
    }

    pReadoutHeader = dynamic_cast<ReadoutHeader*>(pObject);
    const DaqCrate* daqCrate = pReadoutHeader->daqCrate();
    current_T = daqCrate->triggerTime();
    current_det = daqCrate->detector().detectorId();
  }

  const CalibReadoutHeader* pCalibReadoutHeader=0;
  if( m_headerType == CLID_CalibReadoutHeader ) {

    sc=eventSvc()->retrieveObject( m_headerPath, pObject );
    if(sc.isFailure()) {
      error()<<"No CalibReadoutHeader for this event"<<endreq;
      return StatusCode::FAILURE;
    }

    pCalibReadoutHeader = dynamic_cast<CalibReadoutHeader*>(pObject);
    const CalibReadout* calibReadout = pCalibReadoutHeader->calibReadout();
    current_T = calibReadout->triggerTime();
    current_det = calibReadout->detector().detectorId();
  }

  bool occupied = false;
  map<DetectorId::DetectorId_t, bool>::iterator it;
  it = m_cvsOccupied.find(current_det);
  if( it == m_cvsOccupied.end() ) {   /* for the first time */
    m_cvsOccupied[current_det] = false;
  }
  
  occupied = m_cvsOccupied[current_det];
  
  if( (current_T - m_lastTriggerT).GetSeconds() > m_deltaT || occupied ) {
      m_evtDsp->pause();
      for(it = m_cvsOccupied.begin(); it!=m_cvsOccupied.end(); it++) {
        (*it).second = false;
      }
  }
  
  m_cvsOccupied[current_det] = true;
  m_lastTriggerT = current_T;

  if( m_headerType == CLID_SimHeader ) {
    sc = processSimHeader(pSimHeader);
    if(sc.isFailure()) return StatusCode::FAILURE;
  }

  if( m_headerType == CLID_ReadoutHeader ) {
    sc = processReadoutHeader( pReadoutHeader );
    if(sc.isFailure()) return StatusCode::FAILURE;
  }

  if( m_headerType == CLID_CalibReadoutHeader ) {
    sc = processCalibReadoutHeader( pCalibReadoutHeader );
    if(sc.isFailure()) return StatusCode::FAILURE;
  }

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

Definition at line 180 of file EvtDspAlg.cc.

{
  return this->GaudiAlgorithm::finalize();
}
StatusCode EvtDspAlg::processSimHeader ( const SimHeader pSimHeader) [private]

SimHeader -> SimHitHeader -> hcmap -> SimhitCollection -> SimHit

typedef std::map<short int,SimHitCollection*> hc_map

loop over every SimHitCollection

loop over every SimHit

get ring and column

Add info line

Definition at line 189 of file EvtDspAlg.cc.

{
  // check SimHeader info if available
  if( pSimHeader==0 ) {
    return StatusCode::SUCCESS;
  }

  const SimHitHeader* simhitheader = pSimHeader->hits();
  const SimHitHeader::hc_map& hcmap = simhitheader->hitCollection();
  SimHitHeader::hc_map::const_iterator it;

  debug()<<"size of hit collection "<< hcmap.size()<<endreq;
  for (it=hcmap.begin(); it != hcmap.end(); ++it) {

    Detector det(it->first);
    const std::vector<SimHit*>& hitvec=it->second->collection();
    debug() <<det.detName()<<" has "<<hitvec.size()<<" hits."<<endreq;

    // process Dayabay AD1 or AD2 hits
    if( det.isAD() )  {

      int ring,clmn;

      // create a charge-time array
      double npe[8][24];
      double tpe[8][24];
      // initialize them
      for(ring=0;ring<8;ring++) {
        for(clmn=0;clmn<24;clmn++) {
          npe[ring][clmn]=InvalidChrg;  // Start from 0
          tpe[ring][clmn]=InvalidTime;  // Start from 0
        }
      }
      

      // loop over each SimHit
      std::vector<SimHit*>::const_iterator it_hvec;
      std::vector<SimHit*>::const_iterator hvec_end=hitvec.end();
      for (it_hvec=hitvec.begin(); it_hvec!=hvec_end; ++it_hvec) {
        AdPmtSensor pmtId = AdPmtSensor((*it_hvec)->sensDetId());
        ring=pmtId.ring()-1;
        clmn=pmtId.column()-1;
        
        if(ring<0 || ring >7)  continue;
        if(clmn<0 || clmn >23) continue;
        
        if( npe[ring][clmn] == InvalidChrg )  {
          npe[ring][clmn] = 0; // valid now
          tpe[ring][clmn]=(*it_hvec)->hitTime(); // valid now, set initial value
        }
        
        // counting
        npe[ring][clmn] += 1;

        if( (*it_hvec)->hitTime() < tpe[ring][clmn] ) {
          tpe[ring][clmn]=(*it_hvec)->hitTime();
        }
        verbose()<<"("<<ring<<","<<clmn<<") "<<(*it_hvec)->hitTime()<<" "<<tpe[ring][clmn]<<" "<<npe[ring][clmn]<<endreq;
      }

      string info;
      info += det.detName();
      info += " SimHeader ";
      info += " Run ";
      info += " Event ";
      info += i2a(pSimHeader->execNumber());
      info += " ";
      info += pSimHeader->earliest().AsString();

      m_evtDsp->plotAD(det,npe,tpe,"PE","s",info.c_str());
    } // end of each AD
 
  } // loop over each hit collection 

  return StatusCode::SUCCESS;
} // end of pSimHeader
StatusCode EvtDspAlg::processReadoutHeader ( const ReadoutHeader pReadoutHeader) [private]

check AD or water pool

Loop over channel data

Add info line

Definition at line 275 of file EvtDspAlg.cc.

{
  const DaqCrate* daqCrate = pReadoutHeader->daqCrate();

  if(!daqCrate) {
    error()<<"Failed to get daqCrate from header"<<endreq;
    return StatusCode::FAILURE;
  }

  if( !(daqCrate->detector().isRPC()) )  {
    
    const DaqPmtCrate* pmtCrate = daqCrate->asPmtCrate();
    if (!pmtCrate) {
      error()<<"Failed to get DaqPmtCrate"<<endreq;
      return StatusCode::FAILURE;
    }
    
    Detector det = pmtCrate->detector();
    ServiceMode svcMode( pReadoutHeader->context(),0 );
    
    const DaqPmtCrate::PmtChannelPtrList& channels = pmtCrate->pmtChannelReadouts();
    DaqPmtCrate::PmtChannelPtrList::const_iterator ci, ci_end = channels.end();
        
    double chrg[8][24];
    double time[8][24];
    for(int ring=0; ring<8; ring++)  {
      for(int clmn=0; clmn<24; clmn++)  {
        chrg[ring][clmn] = InvalidChrg;
        time[ring][clmn] = InvalidTime;
      }
    }
    
    double pl_chrg[9][24][2];
    double pl_time[9][24][2];
    for(int wall=0; wall<9; wall++) {
      for(int spot=0; spot<24; spot++) {
        for(int inwd=0; inwd<2; inwd++) {
          pl_chrg[wall][spot][inwd] = InvalidChrg;
          pl_time[wall][spot][inwd] = InvalidTime;
        }
      }
    }

    for(ci = channels.begin(); ci!=ci_end; ci++) {
      
      const DaqPmtChannel* channel = *ci;
      FeeChannelId channelId = channel->channelId();
    
      int ring,clmn;
      int wall,spot,inwd;
      if( det.isAD() ) {
        // ring and column
        AdPmtSensor pmtId = m_cableSvc->adPmtSensor( channelId, svcMode );
        ring = pmtId.ring();
        clmn = pmtId.column();
        /* bogus */
        if( pmtId.bogus() ) continue;
        if( ring == 0 ) continue;
      }
      if( det.isWaterShield() ) {
        // wall, spot and inward
        PoolPmtSensor pmtId = m_cableSvc->poolPmtSensor( channelId, svcMode );
        wall = pmtId.wallNumber();
        spot = pmtId.wallSpot();
        inwd = pmtId.inwardFacing();
        /* bogus */
        if( pmtId.bogus() ) continue;
      }
  
      // number of hits in this readout
      unsigned int multi = channel->hitCount();
      for(unsigned int nr = 0; nr<multi; ++nr) {
        // TDC data by channel
        int tdc = channel->tdc(nr);
        // ADC data by channel
        int adc = channel->adc(nr);
        // cycle
        int cycle = channel->peakCycle(nr);
        // PreAdc
        double preAdc = channel->preAdcAvg(nr);
        // range
        int highGain = channel->isHighGainAdc(nr);
        // tdc count
        int hitCount = nr;
        
        double relaGain = (highGain==1) ? 1 : 1/19. ;
        double quasiAdc = (adc - preAdc) / relaGain;
        
        if( det.isAD() ) {
          if( chrg[ring-1][clmn-1] == InvalidChrg ) {  // Only take the first one
            chrg[ring-1][clmn-1] = quasiAdc;
            time[ring-1][clmn-1] = tdc;
          }
        }
        if( det.isWaterShield() ) {
          if( pl_chrg[wall-1][spot-1][inwd-1] == InvalidChrg ) {  // Only take the first one
            pl_chrg[wall-1][spot-1][inwd] = quasiAdc;
            pl_time[wall-1][spot-1][inwd] = tdc;
          }
        }
      } // end of multi Tdc
    } // end of channels 
     
    int Run,Event;
    Run = daqCrate->runNumber();
    Event = daqCrate->eventNumber();
    
    string info;
    info += det.detName();
    info += " Run";
    info += i2a( Run );
    info += " Event";
    info += i2a( Event );
    info += " ";
    TimeStamp triggerT = daqCrate->triggerTime() + MiniDryRunTimeCorrection( Run );
    info += triggerT.AsString();
    
    if( det.isAD() ) {
      m_evtDsp->plotAD(det,chrg,time,"ADC","TDC",info.c_str());
    }
    if( det.isWaterShield() ) {
      m_evtDsp->plotPool(det,pl_chrg,pl_time,"ADC","TDC",info.c_str());
    }
  }    
    
  return StatusCode::SUCCESS;
}
StatusCode EvtDspAlg::processCalibReadoutHeader ( const CalibReadoutHeader pCalibReadoutHeader) [private]

check AD or water pool

Loop over channel data

Add info line Get run, event

Definition at line 407 of file EvtDspAlg.cc.

{
  const CalibReadout* calibReadout = pCalibReadoutHeader->calibReadout();
  if(!calibReadout) {
    error()<<"Failed to get CalibReadout from header"<<endreq;
    return StatusCode::FAILURE;
  }

  if( !(calibReadout->detector().isRPC()) ) {

    const CalibReadoutPmtCrate* pCalibPmtCrate = 0;

    pCalibPmtCrate = dynamic_cast< const DayaBay::CalibReadoutPmtCrate* > ( calibReadout );
    if(!pCalibPmtCrate) {
      error()<<"Failed to get CalibReadoutPmtCrate"<<endreq;
      return StatusCode::FAILURE;
    }

    Detector det = pCalibPmtCrate->detector();
    ServiceMode svcMode( pCalibReadoutHeader->context(),0 );
    
    CalibReadoutPmtCrate::PmtChannelReadouts channels = pCalibPmtCrate->channelReadout();
    CalibReadoutPmtCrate::PmtChannelReadouts::iterator ci, ci_end = channels.end();
    
    double chrg[8][24];
    double time[8][24];
    for(int ring=0; ring<8; ring++)  {
      for(int clmn=0; clmn<24; clmn++)  {
        chrg[ring][clmn] = InvalidChrg;
        time[ring][clmn] = InvalidTime;
      }
    }
    
    double pl_chrg[9][24][2];
    double pl_time[9][24][2];
    for(int wall=0; wall<9; wall++) {
      for(int spot=0; spot<24; spot++) {
        for(int inwd=0; inwd<2; inwd++) {
          pl_chrg[wall][spot][inwd] = InvalidChrg;
          pl_time[wall][spot][inwd] = InvalidTime;
        }
      }
    }

    for(ci = channels.begin(); ci!=ci_end; ci++) {
      
      CalibReadoutPmtChannel channel = (*ci);
      
      int ring,clmn;
      int wall,spot,inwd;
      if( det.isAD() ) {
        // ring and column
        const AdPmtSensor pmtId ( channel.pmtSensorId().fullPackedData() );
        ring = pmtId.ring();
        clmn = pmtId.column();
        /* bogus */
        if( pmtId.bogus() ) continue;
        if( ring == 0 ) continue;
      }
      if( det.isWaterShield() ) {
        // wall, spot and inward
        const PoolPmtSensor pmtId ( channel.pmtSensorId().fullPackedData() );
        wall = pmtId.wallNumber();
        spot = pmtId.wallSpot();
        inwd = pmtId.inwardFacing();
        /* bogus */
        if( pmtId.bogus() ) continue;
      }

      // TDC data by channel
      double t = channel.earliestTime();
      
      // ADC data by channel
      double c = channel.earliestCharge();
      
      if( det.isAD() ) {
        if( chrg[ring-1][clmn-1] == InvalidChrg ) {  // Only take the first one                                                                    
          chrg[ring-1][clmn-1] = c;
          time[ring-1][clmn-1] = t;
        }
      }
      if( det.isWaterShield() ) {
        if( pl_chrg[wall-1][spot-1][inwd-1] == InvalidChrg ) {  // Only take the first one                                                         
          pl_chrg[wall-1][spot-1][inwd] = c;
          pl_time[wall-1][spot-1][inwd] = t;
        }
      }
    } // end of channels

    int Run(-1),Event(-1);
    if(pCalibReadoutHeader->inputHeaders().size() != 0) {
      const IHeader* firstHeader = *((pCalibReadoutHeader->inputHeaders()).begin());
      const ReadoutHeader* pReadoutHeader= dynamic_cast<const ReadoutHeader*>(firstHeader);
      const DaqCrate* daqCrate = pReadoutHeader->daqCrate();
      Run = daqCrate->runNumber();
      Event = daqCrate->eventNumber();
    }

    string info;
    info += det.detName();
    info += " CalibReadout ";
    info += " Run";
    info += i2a( Run );
    info += " Event";
    info += i2a( Event );
    info += " ";
    TimeStamp triggerT = calibReadout->triggerTime() + MiniDryRunTimeCorrection(Run);
    info += triggerT.AsString();


    if( det.isAD() ) {
      m_evtDsp->plotAD(det,chrg,time,"PE","ns",info.c_str());
    }
    if( det.isWaterShield() ) {
      m_evtDsp->plotPool(det,pl_chrg,pl_time,"PE","ns",info.c_str());
    }
  }

  return StatusCode::SUCCESS;
}

Member Data Documentation

t0 of this set of data

Definition at line 41 of file EvtDspAlg.h.

string EvtDspAlg::m_headerName [private]

The header object's name to display.

Definition at line 44 of file EvtDspAlg.h.

CLID EvtDspAlg::m_headerType [private]

Definition at line 45 of file EvtDspAlg.h.

string EvtDspAlg::m_headerPath [private]

Definition at line 46 of file EvtDspAlg.h.

bool EvtDspAlg::m_selection [private]

Do some simple selection (add some cuts and/or calibration)?

Definition at line 49 of file EvtDspAlg.h.

Evt Dsp tool;.

Definition at line 52 of file EvtDspAlg.h.

Cable mapping service.

Definition at line 55 of file EvtDspAlg.h.

Event grouper.

Definition at line 58 of file EvtDspAlg.h.

double EvtDspAlg::m_deltaT [private]

Definition at line 59 of file EvtDspAlg.h.

Definition at line 60 of file EvtDspAlg.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:06:33 for EvtDsp by doxygen 1.7.4