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

This is just of a copy of 'DsPullEvent' and 'DsPushKine' in dybgaudi/Simulation/DetSim/ with name changed. More...

#include <DetSimProc.h>

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

List of all members.

Public Member Functions

 DetSimProc (const std::string &name, ISvcLocator *pSvcLocator)
 pullevent
virtual ~DetSimProc ()
virtual StatusCode initialize ()
virtual StatusCode execute ()
virtual StatusCode finalize ()
StatusCode registerData (IStageData &data)
IStagethisStage ()
IStagelowerStage ()

Private Types

typedef HeaderStageData
< DayaBay::GenHeader
GnrtrData
typedef HeaderStageData
< DayaBay::SimHeader
SimData

Private Member Functions

void DS_constructor ()
 DetSim ---------------------------.
void DS_destructor ()
virtual StatusCode DS_initialize ()
virtual StatusCode DS_execute (GnrtrData *p_input, SimData *&p_output)
virtual StatusCode DS_finalize ()

Private Attributes

std::string m_location
 copy from DsPushKine
std::string m_converterName
IGiGaSvc * m_giga
IHepMCtoG4m_converter
std::string m_genLocation
 copy from DsPullEvent
IHistoryKeeperm_historyKeeper
FFTimeStamp m_CurrentTime
 The earliest (smallest) time which this has provided.
SimData::DataList m_SimDataList
 This is for Consumer&Producer only.
bool m_Start
std::string m_genPruneName
 Auxiliary.
IGenPruneToolm_genPrune

Detailed Description

This is just of a copy of 'DsPullEvent' and 'DsPushKine' in dybgaudi/Simulation/DetSim/ with name changed.

They are the two crucial algorithms which will run the G4.

Then these two algorithms are combined into a single algorithm for easy operation in Stage.

Now this is a algorithm goes into stages for Fifteen simulation.

First imported and modified by Zhe Wang, Apr. 7, 2008

Updated according to r6053 DsPullEvent. Apr. 22, 2009

Definition at line 38 of file DetSimProc.h.


Member Typedef Documentation

Definition at line 51 of file DetSimProc.h.

Definition at line 52 of file DetSimProc.h.


Constructor & Destructor Documentation

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

pullevent

pushkine MuonProphet

Definition at line 23 of file DetSimProc.cc.

    : StageProcessor<DayaBay::SimHeader>(name,pSvcLocator)
    , m_giga(0)
    , m_converter(0)
    , m_historyKeeper(0)
    , m_genPrune(0)
{
  DS_constructor();

  // Auxiliary
  declareProperty("GenPruneName",m_genPruneName = "GenPruneTool", "Name of GenHeader pruner");

}
DetSimProc::~DetSimProc ( ) [virtual]

Definition at line 37 of file DetSimProc.cc.


Member Function Documentation

StatusCode DetSimProc::initialize ( ) [virtual]

Reimplemented from StageProcessor< DayaBay::SimHeader >.

Definition at line 42 of file DetSimProc.cc.

{
  StatusCode sc = this->StageProcessor<DayaBay::SimHeader>::initialize();
  if (sc.isFailure()) return sc;

  debug()<<"DetSimProc"<<endreq;

  sc = DS_initialize();
  if (sc.isFailure()) return sc;

  // Although initialized to 0, however, no special meaning
  m_CurrentTime=0;
  m_SimDataList.clear();

  m_Start=true;

  // Auxiliary
  m_genPrune = tool<IGenPruneTool>(m_genPruneName);
  if( !m_genPrune ) {
    error() << "Failed to retrive GenPruneTool" << endreq;
    return StatusCode::FAILURE;
  }

  return StatusCode::SUCCESS;
}
StatusCode DetSimProc::execute ( ) [virtual]

delta t

=====))))) Consumer&Producer:

Principle: make sure the data provided is really the earliest (with smallest time)

the core part begins ///////// determine localtime, it is not m_CurrentTime

localtime must go beyond lower stage to make sure output is safe

pulling event from lower stage

destroy the data pulled out generate some new data This process is like to take some input after use then produce new data

Instead of being called through sysExecute, they are called explicitly here.

for this stage

In case want to prune genheader

find out the min time

get the data with smallest time push it into current stage and delete it.

Definition at line 68 of file DetSimProc.cc.

{
  debug()<<"DetSimProc"<<endreq;

  SimData::DataList::iterator psimdatalist;

  FFTimeStamp tm(0,0);
  FFTimeStamp dt(0,0); 
  FFTimeStamp localtime(0,0);

  if(lowerStage()) {
    debug() << "Consumer&Producer" << endreq;
    if(m_Start||m_CurrentTime<=thisStage()->currentTime()) {

      if(m_Start) {
        // nothing to do here
      } else {
        psimdatalist=m_SimDataList.begin();
        localtime=psimdatalist->first;
      }

      //debug()<<"A: local time= "<<localtime<<endreq;
      //debug()<<"A: lower stage time= "<<m_LowerStage->currentTime()<<endreq;
      while(m_Start||localtime>=lowerStage()->currentTime()) {
        m_Start=false;
        //debug() << "In while loop, pulling data from lower Stage ......" << endreq;

        IStageData* pIStageData=0;
        StatusCode sc = lowerStage()->nextElement(pIStageData);  // pulling out
        if (sc.isFailure()) {
          error() << "Failed to pull kinematics" << endreq;
          return sc;
        }
        
        GnrtrData* pGnrtrData=0;
        try{
          pGnrtrData = dynamic_cast<GnrtrData*>(pIStageData);
        }
        catch(...) {
          error() << "Failed to get GnrtrData pointer" <<endreq;
        }

        //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        // delete the used one
        tm=pGnrtrData->time();
        //debug() << "data pulled out from lower stage has time: "<<tm<<endreq;

        preExecute();
        SimData*   pSimData=0;   
        DS_execute(pGnrtrData,pSimData);
        this->AppendInputHeader(&pGnrtrData->header());
        //m_genPrune->prune( &pGnrtrData->header() );
        //
        postExecute();
        delete pGnrtrData; pGnrtrData=0;

        //debug() << "new data generated at time: "<< pSimData->time()<< endreq;
        //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

        // push back into a local store
        m_SimDataList.insert(SimData::DataList::value_type(pSimData->time(),pSimData));

        psimdatalist=m_SimDataList.begin();
        localtime=psimdatalist->first;
        //debug()<<"B: local time= "<<localtime<<endreq;
        //debug()<<"B: lower stage time= "<<m_LowerStage->currentTime()<<endreq;        
      }

      m_CurrentTime=localtime;
      //debug() << "m_CurrentTime= "<< m_CurrentTime << endreq;

      psimdatalist=m_SimDataList.begin();
      debug() << "to grep: new data pushed out at time " << psimdatalist->first << endreq;
      thisStage()->pushElement(psimdatalist->second);
      this->registerData(*(psimdatalist->second));
      m_SimDataList.erase(psimdatalist);

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

Definition at line 170 of file DetSimProc.cc.

{
  DS_finalize();

  return StatusCode::SUCCESS;
}
void DetSimProc::DS_constructor ( ) [private]

DetSim ---------------------------.

following is a copy from DsPushKine and DsPullEvent

DsPushKine

DsPullEvent

Definition at line 178 of file DetSimProc.cc.

{
  declareProperty("Converter",m_converterName="HepMCtoG4",
                  "Name of tool to convert HepMCEvents to G4PrimaryVertex");

  declareProperty("GenLocation",m_genLocation=DayaBay::GenHeaderLocation::Default,
                  "Location in the TES where the input GenHeader is to be found.");
}
void DetSimProc::DS_destructor ( ) [private]

Definition at line 189 of file DetSimProc.cc.

{}
StatusCode DetSimProc::DS_initialize ( ) [private, virtual]

DsPushKine

DsPullEvent

Definition at line 192 of file DetSimProc.cc.

{

  m_giga = svc<IGiGaSvc>("GiGa",true);
  try {
    m_converter = tool<IHepMCtoG4>(m_converterName);
  }
  catch (const GaudiException& gex) {
    fatal() << "Failed to get converter tool \""
            << m_converterName << "\"" << endreq;
    return StatusCode::FAILURE;
  }

  m_historyKeeper = svc<IHistoryKeeper>("HistoryKeeper",true);

  return StatusCode::SUCCESS;
}
StatusCode DetSimProc::DS_execute ( GnrtrData p_input,
SimData *&  p_output 
) [private, virtual]

The input and output are now controled by Stage. That is the only difference with DsPushKine and DsPullEvent

DsPushKine

DsPullEvent

Really got some hit through simulation

Note that other setTimeStamp which is different from old context must comes after setContext, otherwise it will be overwritten.

When there is a MuonProphet muon, make sure that the earliest is the genHeader time, i.e. muon time, which is the earliest.

end of DsPullEvent

Definition at line 212 of file DetSimProc.cc.

{

//DayaBay::GenHeader* gen_header = get<DayaBay::GenHeader>(m_location);
  DayaBay::GenHeader* gen_header = &p_input->header();

  //debug()<<"genheader, timeStamp: "<<gen_header->timeStamp()<<endreq;
  //debug()<<"genheader, earliest: "<<gen_header->earliest()<<endreq;

  HepMC::GenEvent* genevt = gen_header->event();
  std::vector<G4PrimaryVertex*> g4verts;
  m_converter->convert(*genevt,g4verts);

  debug() << "Got " << g4verts.size() << " primary vertices" << endreq;

  for (size_t ind=0; ind < g4verts.size(); ++ind) {

    *m_giga << g4verts[ind];

  }

  debug() << "Pushed " << gen_header->generatorName()
         << " to giga" << endreq;

  DayaBay::SimHeader* header = MakeHeaderObject();

  // Just pass through GenHeader's timestamp.  This also causes
  // GenHeader to be registered as input, something that would
  // normally just happen if DsPushKine and DsPullEvent were the
  // same algorithm.
  //  DayaBay::GenHeader* gen_header = getTES<DayaBay::GenHeader>(m_genLocation);
  header->setTimeStamp(gen_header->timeStamp());

  // Primary event vertices.
  const G4Event* g4event = 0;
  m_giga->retrieveEvent(g4event);
  if (!g4event) {
    error() << "No G4Event!" << endreq;
    return StatusCode::FAILURE;
  }

  int nverts = g4event->GetNumberOfPrimaryVertex();
  if( nverts == 0 ) {
    warning() << "The g4event has zero primary vertices!" << endreq;
  }
  debug() << "Pulled event with " << nverts
         << " primary vertices, event id:" << g4event->GetEventID() << endreq;

  G4PrimaryVertex* g4vtx = g4event->GetPrimaryVertex(0);
  while (g4vtx) {
    debug() << "\n\tat (" << g4vtx->GetX0() << "," << g4vtx->GetY0() << "," << g4vtx->GetZ0() << ")";
    g4vtx = g4vtx->GetNext();
    break;
  }
  debug() << endreq;

  // particle histories.
  // Do this first so we can use it below.
  DayaBay::SimParticleHistory* history =0;
  m_historyKeeper->ClaimCurrentHistory(history); // This takes ownership from the Keeper.
  header->setParticleHistory(history);

  // Unobservable Statistics
  DayaBay::SimUnobservableStatisticsHeader* unobs =0;
  m_historyKeeper->ClaimCurrentUnobservable(unobs); // This takes ownership from the Keeper.
  header->setUnobservableStatistics(unobs);

  // introduce the headers to each other
  DayaBay::SimHitHeader* hit_header = 0;

  double earliestTime = 0;
  double latestTime = 0;
  Context context;
  context.SetSimFlag(SimFlag::kMC);
  bool firstDetector = true;
  int hitcount=0;  // deal with no hits situation

  // Hit collections.
  G4HCofThisEvent* hcs = g4event->GetHCofThisEvent();
  if (!hcs) {
    debug() << "No HitCollections in this event" << endreq;
  }  else  {
    int nhc = hcs->GetNumberOfCollections();
    if (!nhc) {
      debug() << "Number of HitCollections is zero" << endreq;
    }  else  {
      debug () << "# HitCollections = " << nhc << endreq;

      hit_header = new DayaBay::SimHitHeader(header);
      for (int ihc=0; ihc<nhc; ++ihc) {
        G4DhHitCollection* g4hc = dynamic_cast<G4DhHitCollection*>(hcs->GetHC(ihc));
        if (!g4hc) {
          error() << "Failed to get hit collection #" << ihc << endreq;
          return StatusCode::FAILURE;
        }
        
        // DetSim produces hit collections even for unsimulated detectors
        size_t nhits = g4hc->GetSize();
        hitcount+=nhits;
        if (!nhits) continue;
        
        bool firstHit = true;
        DayaBay::SimHitCollection::hit_container hits;
        DayaBay::Detector detector;
        DayaBay::SimHitCollection* shc =
          new DayaBay::SimHitCollection(hit_header,detector,hits);
        for (size_t ihit=0; ihit<nhits; ++ihit) {
          DayaBay::SimHit* simhit = (*g4hc)[ihit]->get();

          // A protection on time overflow or underflow.
          // Kill the hit over two years.
          // It is impossible to simulate them with full Geant4 simulation.
          // See Trac#489.
          if( abs(simhit->hitTime()) > 6.3e16 ) {
            warning() << "Eccentric long hit time "<<simhit->hitTime()<<"ns. Skipped."<<endreq;
            hitcount--;
            continue;
          }

          if(history) {
            int trackid = (*g4hc)[ihit]->trackId();
            simhit->setAncestor(history->track(trackid));
          }
          // Set detector and site using first hit
          if(firstHit){
            detector = DayaBay::Detector(simhit->sensDetId()).siteDetPackedData();
            if(firstDetector){
              // Keep track of sites/detectors in this simulation for context
              context.SetSite(detector.site());
              context.SetDetId(detector.detectorId());
            }
            if(context.GetSite() != detector.site()){
              // Simulation contains multiple sites, unset
              context.SetSite(Site::kUnknown);
            }
            if(context.GetDetId() != detector.detectorId()){
              // Simulation contains multiple detectors, unset
              context.SetDetId(DetectorId::kUnknown);
            }
          }
          // Record earliest/latest simhit
          debug() << "Hit Time: " << simhit->hitTime() << endreq;
          if((firstHit && firstDetector) || simhit->hitTime() < earliestTime)
            earliestTime = simhit->hitTime();
          if((firstHit && firstDetector) || simhit->hitTime() > latestTime)
            latestTime = simhit->hitTime();
          firstHit = false;

          simhit->setHc(shc);
          hits.push_back(simhit);
        }
        firstDetector = false;
        
        shc->setDetector(detector);
        shc->setCollection(hits);
        debug() << "Adding " << detector.detName() << " hits ("
                << shc->collection().size() << ") to header." << endreq;
        hit_header->addHitCollection(shc);
      }
    }
  }

  header->setHits(hit_header);
  context.SetTimeStamp(gen_header->timeStamp());
  header->setContext(context);

  // Set header time range based on hit times
  debug() << "Header Time sec, nanosec: " << header->timeStamp().GetSec()
          << "  " << header->timeStamp().GetNanoSec() << endreq;
  debug() << "Earliest Hit: " << earliestTime << endreq;
  debug() << "Latest Hit: " << latestTime << endreq;
  TimeStamp earliestTS(header->timeStamp());
  TimeStamp latestTS(header->timeStamp());
  earliestTS.Add(earliestTime * 1e-9);
  latestTS.Add(latestTime * 1e-9);
  debug() << "Earliest Time sec, nanosec: " << earliestTS.GetSec()
          << "  " << earliestTS.GetNanoSec() << endreq;
  debug() << "Latest Time sec, nanosec: " << latestTS.GetSec()
          << "  " << latestTS.GetNanoSec() << endreq;
  header->setEarliest(earliestTS);
  header->setLatest(latestTS);
  debug() << "Earliest Time sec, nanosec: " << header->earliest().GetSec()
          << "  " << header->earliest().GetNanoSec() << endreq;
  debug() << "Latest Time sec, nanosec: " << header->latest().GetSec()
          << "  " << header->latest().GetNanoSec() << endreq;

  HepMC::GenEvent::particle_const_iterator pci, pci_end = genevt->particles_end();

  for( pci = genevt->particles_begin(); pci != pci_end; ++pci ) {
    if( (*pci)->pdg_id() == 13 || (*pci)->pdg_id() == -13 ) {   // muon                                            
      if( (*pci)->status() != MpMuonFate::kNeedSim ) {   //  geant4-noble particle
        header->setEarliest(gen_header->timeStamp());
      }
    }
  }

  if(hitcount==0) {  // when there is no hit, set time stamp to genheader's earliest() to save causality
    header->setTimeStamp(gen_header->earliest());
    header->setEarliest(gen_header->earliest());
    header->setLatest(gen_header->earliest());
  }

  p_output=new SimData(*header);

  return StatusCode::SUCCESS;

}
StatusCode DetSimProc::DS_finalize ( ) [private, virtual]

Definition at line 434 of file DetSimProc.cc.

{
  return StatusCode::SUCCESS;
}
StatusCode StageProcessor< class >::registerData ( IStageData data) [inherited]
IStage * StageProcessor< class >::thisStage ( ) [inherited]
IStage * StageProcessor< class >::lowerStage ( ) [inherited]

Member Data Documentation

std::string DetSimProc::m_location [private]

copy from DsPushKine

Definition at line 64 of file DetSimProc.h.

std::string DetSimProc::m_converterName [private]

Definition at line 65 of file DetSimProc.h.

IGiGaSvc* DetSimProc::m_giga [private]

Definition at line 67 of file DetSimProc.h.

Definition at line 68 of file DetSimProc.h.

std::string DetSimProc::m_genLocation [private]

copy from DsPullEvent

Property GenLocation - location in TES where the input GenHeader is to be found. Default is DayaBay::GenHeader::Default

Definition at line 75 of file DetSimProc.h.

Definition at line 76 of file DetSimProc.h.

The earliest (smallest) time which this has provided.

Definition at line 79 of file DetSimProc.h.

This is for Consumer&Producer only.

For new generated data.

Definition at line 83 of file DetSimProc.h.

bool DetSimProc::m_Start [private]

Definition at line 86 of file DetSimProc.h.

std::string DetSimProc::m_genPruneName [private]

Auxiliary.

Definition at line 89 of file DetSimProc.h.

Definition at line 90 of file DetSimProc.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:22:12 for DetSimProc by doxygen 1.7.4