/search.css" rel="stylesheet" type="text/css"/> /search.js">
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes
SimHitSplitSvc Class Reference

for preparing SimHits for digitalization More...

#include <SimHitSplitSvc.h>

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

List of all members.

Classes

class  Configure

Public Member Functions

 SimHitSplitSvc (const string &name, ISvcLocator *pSvcLocator)
virtual ~SimHitSplitSvc ()
virtual StatusCode initialize ()
virtual StatusCode queryInterface (const InterfaceID &riid, void **ppint)
StatusCode getSimHitHeader (SimHeader *sh, vector< SimHitHeader * > &shhs, vector< TimeStamp > &hites, vector< TimeStamp > &hitls)

Static Public Member Functions

static const InterfaceID & interfaceID ()

Private Member Functions

StatusCode fillHitsBuffer (SimHeader *sh)
StatusCode findGap ()
StatusCode createHitHeaders (SimHeader *sh, vector< SimHitHeader * > &shhs, vector< TimeStamp > &hites, vector< TimeStamp > &hitls)

Private Attributes

MsgStream m_log
deque< double > m_hitsGap
deque< MixSimHitm_SimHits
TimeStamp m_absTime
vector< TimeStampm_hitEarliests
vector< TimeStampm_hitLatests
double m_minTimeGap
TimeStamp m_MinTimeGap
list __all__ = ['SimHitSplitSvcConf', 'Configure']

Detailed Description

for preparing SimHits for digitalization

Zhang YiChun Dec 13 2010 yczhang@ihep.ac.cn

Definition at line 32 of file SimHitSplitSvc.h.


Constructor & Destructor Documentation

SimHitSplitSvc::SimHitSplitSvc ( const string &  name,
ISvcLocator *  pSvcLocator 
)

Definition at line 9 of file SimHitSplitSvc.cc.

               :Service(name, pSvcLocator), m_log(msgSvc(), "SimHitSplitSvc")
{
  //MiniTimeGap 
  //pre(post)TimeTolerance "ns"
  m_minTimeGap = preTimeTolerance/CLHEP::nanosecond + postTimeTolerance/CLHEP::nanosecond;
  TimeStamp timeGap(m_minTimeGap/1.0e9);
  m_MinTimeGap = timeGap;
  /*declareProperty("MinGapTime", m_mintimeGap = preTimeTolerance + postTimeTolerance,
    "Minimum width for a gap that defines a chunk of SimHits");*/

  /*m_log<< MSG::INFO<< "SimHitSplitSvc::SimHitSplitSvc(): "
    << " m_mintimeGap: "<< m_mintimeGap<< endreq;*/
}
SimHitSplitSvc::~SimHitSplitSvc ( ) [virtual]

Definition at line 24 of file SimHitSplitSvc.cc.

{
  m_log<< MSG::INFO<< "SimHitSplitSvc::~SimHitSplitSvc()..."<< endreq;
}

Member Function Documentation

StatusCode SimHitSplitSvc::initialize ( ) [virtual]

Definition at line 29 of file SimHitSplitSvc.cc.

{
  //SimHitSplit initialization
  m_log<< MSG::INFO<< "SimHitSplitSvc ininalize @"<< (void*)this<< endreq;
  StatusCode sc = Service::initialize();
  if(sc.isFailure()) 
  {
    m_log<< MSG::ERROR<< "Parent class(Service) failed to initialize!"<< endreq;
    return sc;
  }
  
  //Check the mini time gap
  m_log<< MSG::INFO<< "MinTimeGap: "<< m_minTimeGap<< " ns"<< endreq;
  m_log<< MSG::INFO<< "MinTimeGap: "<< m_MinTimeGap.GetSec()<< "s --"
       << m_MinTimeGap.GetNanoSec()<< " ns"<< endreq;

  return StatusCode::SUCCESS;
}
StatusCode SimHitSplitSvc::queryInterface ( const InterfaceID &  riid,
void **  ppint 
) [virtual]

Definition at line 48 of file SimHitSplitSvc.cc.

{
  if(IID_ISimHitSplitSvc.versionMatch(riid)) 
  {
    m_log<< MSG::DEBUG<< "queryInterface("<< riid
         << ")-->(ISimHitSplitSvc*)"<< (void*)this<< endreq;
    *ppint = (ISimHitSplitSvc*)this;
  }
  else 
  {
    return Service::queryInterface(riid, ppint);
  }
  addRef();
  return StatusCode::SUCCESS;
}
StatusCode SimHitSplitSvc::getSimHitHeader ( SimHeader sh,
vector< SimHitHeader * > &  shhs,
vector< TimeStamp > &  hites,
vector< TimeStamp > &  hitls 
) [virtual]

Implements ISimHitSplitSvc.

Definition at line 65 of file SimHitSplitSvc.cc.

{
  m_log<< MSG::DEBUG<< "Now in the getSimHitHeaders()."<< endreq;

  //Judge if need to do SimHit split
  TimeStamp TimeRange = sh->latest() - sh->earliest();
  m_log<< MSG::DEBUG<< "The SimHeader's range: "
       << TimeRange.GetSec()<< "--"<< TimeRange.GetNanoSec()<< endreq;

  /*if(TimeRange < m_MinTimeGap)
  {
    shhs.push_back(const_cast<SimHitHeader*>(sh->hits()));
    hites.push_back(sh->earliest());
    hitls.push_back(sh->latest());
    return StatusCode::SUCCESS;   
    }*/

  //Fill SimHits buffer with the current SimHeader
  StatusCode sc = this->fillHitsBuffer(sh);
  if(sc.isFailure())
  {
    m_log<< MSG::ERROR<< "Error when filling the SimHits!"<< endreq;
    return sc;
  }
  
  //Create SimHitHeaders
  sc = this->createHitHeaders(sh, shhs, hites, hitls);
  if(sc.isFailure())
  {
    m_log<< MSG::ERROR<< "Error when creating the new SimHitHeaders!"<< endreq;
    return sc;
  }

  return StatusCode::SUCCESS;
}
StatusCode SimHitSplitSvc::fillHitsBuffer ( SimHeader sh) [private]

Definition at line 102 of file SimHitSplitSvc.cc.

{
  m_log<< MSG::DEBUG<< "Fill SimHits buffer"<< endreq;

  //Get the SimHitHeader
  const SimHitHeader* shh = sh->hits();
  map<short int, SimHitCollection*> mshc = shh->hitCollection();
  if(0 == mshc.size())
  {
    m_log<< MSG::WARNING<< "Empty SimHitHeader without SimHitCollection!"<< endreq;
    return StatusCode::SUCCESS;
  }

  m_absTime = sh->timeStamp();
  m_log<< MSG::DEBUG<< "The SimHeader TimeStamp: "<< m_absTime.GetSec()
       << "--"<< m_absTime.GetNanoSec()<< endreq;
  m_log<< MSG::DEBUG<< "The SimHeader Earliest: "<< sh->earliest().GetSec()
       << "--"<< sh->earliest().GetNanoSec()<< endreq;
  m_log<< MSG::DEBUG<< "The SimHeader Latest: "<< sh->latest().GetSec()
       << "--"<< sh->latest().GetNanoSec()<< endreq;
 
  //Fill the SimHits buffer
  //m_log<< MSG::DEBUG<< "m_SimHits' size is: "<< m_SimHits.size()<< "!"<< endreq;

  map<short int, SimHitCollection*>::iterator mit;
  for(mit = mshc.begin(); mit != mshc.end(); mit++)
  {
    //Get the SimHitCollection
    m_log<< MSG::DEBUG<< "In Det: "<< mit->first<< ", there are "<< mit->second->collection().size()<< " SimHits."<< endreq;

    SimHitCollection* shc = mit->second;
    vector<SimHit*> hits = shc->collection();
    /*if(0 == hits.size())
    {
      m_log<< MSG::DEBUG<< "No SimHits in Det:"<< mit->first<< endreq;
      return StatusCode::SUCCESS;
      }*/

    //Fill the Hits buffer
    for(vector<SimHit*>::iterator vit = hits.begin(); vit != hits.end(); vit++) 
    {
      MixSimHit mixhit;
      mixhit.setHit(*vit);
      m_log<< MSG::DEBUG<< "SimHit Time: "<< mixhit.sht->hitTime()<< endreq;
      m_SimHits.push_back(mixhit); //deep copy need?
    }
  }

  if(0 == m_SimHits.size()) 
  {
    m_log<< MSG::WARNING<< "Empty SimHitHeader with no SimHits!"<< endreq;
    m_hitsGap.clear();
    return StatusCode::SUCCESS;
  }

  sort(m_SimHits.begin(), m_SimHits.end());

  deque<MixSimHit>::size_type mixsize = m_SimHits.size();
  mixsize--;
  TimeStamp ET(m_SimHits[0].sht->hitTime()/1.0e9);
  TimeStamp LT(m_SimHits[mixsize].sht->hitTime()/1.0e9);
  ET.Add(m_absTime);
  LT.Add(m_absTime);

  m_log<< MSG::DEBUG<< "The earliest SimHit time: "<< ET.GetSec()
       << "--"<< ET.GetNanoSec()<< " from "<< m_SimHits[0].sht->hc()->detector().detName()<< endreq;
  m_log<< MSG::DEBUG<< "The latest SimHit time: "<< LT.GetSec()
       << "--"<< LT.GetNanoSec()<< " from "<< m_SimHits[mixsize].sht->hc()->detector().detName()<< endreq;

  m_log<< MSG::DEBUG<< "After sorting....."<< endreq;
  for(deque<MixSimHit>::iterator vit = m_SimHits.begin(); vit != m_SimHits.end(); vit++)
  {
    //m_log<< MSG::DEBUG<< "SimHit time: "<< vit->sht->hitTime()<< endreq;
    m_log<< MSG::DEBUG<< "SimHit time in m_SimHits: "<< vit->sht->hitTime()<< endreq;
  }

  //Update the gap vector
  StatusCode sc = this->findGap();
  if(sc.isFailure())
  {
    m_log<< MSG::ERROR<< "Error in findGap()!"<< endreq;
    return StatusCode::FAILURE;
  }

  return StatusCode::SUCCESS;
}
StatusCode SimHitSplitSvc::findGap ( ) [private]

Definition at line 189 of file SimHitSplitSvc.cc.

{
  m_log<< MSG::DEBUG<< "Find gap here(update the Gap Vector)..."<< endreq;

  //Prepare the Gap vector
  m_hitsGap.clear();

  //If it can find the Gap
  if(m_SimHits.size() < 2) //at least two hits. Actually, now there is just one.
  {
    m_log<< MSG::DEBUG<< "No enough SimHits in m_SimHits! Be carefull!"<< endreq;

    m_hitsGap.push_back(m_SimHits[0].sht->hitTime());

    for(vector<double>::size_type ind = 0; ind != m_hitsGap.size(); ind++)
    {
      m_log<< MSG::DEBUG<< "Time Gap: "<< m_hitsGap[ind]<< endreq;
    }

    return StatusCode::SUCCESS;
  }

  //________hhhhhh__hh______hhhhh_h______________hhhh_h_hhh_hhhhhhh___
  //PmtSimHit situation

  //Standalone test
  deque<MixSimHit>::iterator dit, ddit, dend;
  dend = m_SimHits.end();
  dend--;
  for(dit = m_SimHits.begin(); dit != dend; dit++)
  {
    ddit = dit + 1;
    double timeinter = ddit->sht->hitTime() - dit->sht->hitTime();
    
    //There is one gap.
    if(timeinter > m_minTimeGap)
    {
      m_log<< MSG::DEBUG<< "There is one gap!"<< endreq;

      m_hitsGap.push_back(dit->sht->hitTime());
    }
  }

  //Last "Gap"
  m_log<< MSG::DEBUG<< "There is the last gap!"<< endreq;
  m_hitsGap.push_back(dend->sht->hitTime());

  for(vector<double>::size_type ind = 0; ind != m_hitsGap.size(); ind++)
  {
    m_log<< MSG::DEBUG<< "Time Gap: "<< m_hitsGap[ind]<< endreq;
  }

  return StatusCode::SUCCESS;
}
StatusCode SimHitSplitSvc::createHitHeaders ( SimHeader sh,
vector< SimHitHeader * > &  shhs,
vector< TimeStamp > &  hites,
vector< TimeStamp > &  hitls 
) [private]

Definition at line 244 of file SimHitSplitSvc.cc.

{
  //Create SimHitHeaders
  m_log<< MSG::DEBUG<< "Create new SimHitHeaders."<< endreq;

  //Loop over the Gap vector
  if(0 == m_hitsGap.size())
  {
    shhs.push_back(const_cast<SimHitHeader*>(sh->hits()));
    hites.push_back(sh->earliest());
    hitls.push_back(sh->latest());
    return StatusCode::SUCCESS;
  }

  deque<double>::size_type iind;
  while ( ! m_hitsGap.empty() )
  {
    //One SimHitHeader each Gap
    m_log<< MSG::DEBUG<< "Create one SimHitHeader before SimHit("<< m_hitsGap[0]<< ")."<< endreq;

    //Bookkeeping the SimHitHeader's time range
    TimeStamp HitE(m_SimHits[0].sht->hitTime()/1.0e9);
    HitE.Add(m_absTime);
    TimeStamp HitL(m_hitsGap[0]/1.0e9);
    HitL.Add(m_absTime);
    m_hitEarliests.push_back(HitE);
    m_hitLatests.push_back(HitL);

    SimHitHeader* shh = new SimHitHeader();

    if(0 == shh)
    {
      m_log<< MSG::ERROR<< "Can not create a new SimHitHeader!"<< endreq;
      return StatusCode::FAILURE;
    }
    m_log<< MSG::DEBUG<< "Create a new SimHitHeader: "<< shh<< endreq;

    //mshc(reference)
    map<short int, SimHitCollection*>& mshc = shh->hitCollection();
    
    //Loop over the SimHits buffer
    for( ; ; )
    {
      m_log<< MSG::DEBUG<< "The SimHit buffer size is: "<< m_SimHits.size()<< endreq;

      deque<MixSimHit>::iterator dit = m_SimHits.begin();
      if(dit == m_SimHits.end())
      {
        m_log<< MSG::DEBUG<< "The SimHits Buffer is empty!"<< endreq;
        break;
      }
        
      if(dit->sht->hitTime() <= m_hitsGap[0])
      {
        Detector Det  = dit->sht->hc()->detector();
        short int det = Det.siteDetPackedData();
        
        m_log<< MSG::DEBUG<< "This hit is from detector: "<< AsString(Det.detectorId())<< endreq;

        //There is a new detector!
        if(0 == mshc.size() || mshc.find(det) == mshc.end())
        {
          m_log<< MSG::DEBUG<< "map<short int, SimHitCollection*> size: "
               << mshc.size()<< " new detectorId: "<< AsString(Det.detectorId())<< endreq;

          //Create a new SimHitCollection
          SimHitCollection* shc = new SimHitCollection();
          shc->setHeader(shh);
          shc->setDetector(Det);
          //shts(reference)
          vector<SimHit*>& shts = shc->collection();
          shts.push_back(dit->sht);
          mshc[det] = shc;
          
          m_log<< MSG::DEBUG<< "Now the map size is: "<< mshc.size()<< endreq;
          
          m_SimHits.pop_front();
          continue;
        }
        else
        {
          m_log<< MSG::DEBUG<< "map<short int, SimHitCollection*> size: "
               << mshc.size()<< "  detectorId: "<< AsString(Det.detectorId())<< endreq;
          //shts(reference)
          vector<SimHit*>& shts = mshc[det]->collection();
          shts.push_back(dit->sht);

          m_SimHits.pop_front();
          continue;
        }
      }
      else 
      {
        m_log<< MSG::DEBUG<< "Now create the next SimHitHeader!"<< endreq;
        break;
      }
    }
    
    m_log<< MSG::DEBUG<< "Get one SimHitHeader: "<< shh<< " with "<< shh->hitCollection().size()<< endreq;

    m_log<< MSG::DEBUG<< "Now prepare the SimHitHeader: "<< endreq;
    shhs.push_back(shh);
    m_hitsGap.pop_front();
  } //Top for cycle

  vector<SimHitHeader*>::iterator vsit = shhs.begin();
  vector<TimeStamp>::iterator veit = m_hitEarliests.begin();
  vector<TimeStamp>::iterator vlit = m_hitLatests.begin();
  for( ; vsit != shhs.end(); vsit++)
  {
    m_log<< MSG::DEBUG<< "Created SimHitHeader with : "<< shhs.size()<< " SimHitHeaders!"<< endreq;
    m_log<< MSG::DEBUG<< "Earliest: "<< veit->GetSec()
         << "--"<< veit->GetNanoSec()<< endreq;
    m_log<< MSG::DEBUG<< "Latest: "<< vlit->GetSec()
         << "--"<< vlit->GetNanoSec()<< endreq;
  }

  hites = m_hitEarliests;
  hitls = m_hitLatests;

  m_hitEarliests.clear();
  m_hitLatests.clear();
  m_SimHits.clear();

  return StatusCode::SUCCESS;
}
static const InterfaceID& ISimHitSplitSvc::interfaceID ( ) [inline, static, inherited]

Definition at line 36 of file ISimHitSplitSvc.h.

                             { return  IID_ISimHitSplitSvc; }

Member Data Documentation

MsgStream SimHitSplitSvc::m_log [mutable, private]

Definition at line 46 of file SimHitSplitSvc.h.

deque<double> SimHitSplitSvc::m_hitsGap [private]

Definition at line 49 of file SimHitSplitSvc.h.

Definition at line 50 of file SimHitSplitSvc.h.

Definition at line 63 of file SimHitSplitSvc.h.

Definition at line 65 of file SimHitSplitSvc.h.

Definition at line 66 of file SimHitSplitSvc.h.

double SimHitSplitSvc::m_minTimeGap [private]

Definition at line 68 of file SimHitSplitSvc.h.

Definition at line 69 of file SimHitSplitSvc.h.

list SimHitSplitSvc::__all__ = ['SimHitSplitSvcConf', 'Configure'] [private]

Definition at line 3 of file __init__.py.


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:14:42 for SimHitSplitSvc by doxygen 1.7.4