CMS 3D CMS Logo

TotemTestGem.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:     Forward
00004 // Class  :     TotemTestGem
00005 //
00006 // Implementation:
00007 //     <Notes on implementation>
00008 //
00009 // Original Author: 
00010 //         Created:  Tue May 16 10:14:34 CEST 2006
00011 // $Id: TotemTestGem.cc,v 1.2 2006/11/16 16:54:12 sunanda Exp $
00012 //
00013 
00014 // system include files
00015 #include <iostream>
00016 #include <iomanip>
00017 #include <cmath>
00018 
00019 // user include files
00020 #include "SimG4Core/Notification/interface/BeginOfEvent.h"
00021 #include "SimG4Core/Notification/interface/EndOfEvent.h"
00022  
00023 #include "FWCore/Framework/interface/Event.h"
00024 #include "FWCore/Framework/interface/EventSetup.h"
00025 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00026 
00027 #include "SimG4CMS/Forward/interface/TotemTestGem.h"
00028 #include "SimG4CMS/Forward/interface/TotemG4HitCollection.h"
00029 
00030 #include "G4SDManager.hh"
00031 #include "G4HCofThisEvent.hh"
00032 #include "CLHEP/Units/SystemOfUnits.h"
00033 #include "CLHEP/Units/PhysicalConstants.h"
00034 
00035 //
00036 // constructors and destructor
00037 //
00038 
00039 TotemTestGem::TotemTestGem(const edm::ParameterSet &p) {
00040   
00041   edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("TotemTestGem");
00042   names        = m_Anal.getParameter<std::vector<std::string> >("Names");
00043  
00044   edm::LogInfo("ForwardSim") << "TotemTestGem:: Initialised as observer of "
00045                              << "begin of job, begin/end events and of G4step";
00046 }
00047 
00048 TotemTestGem::~TotemTestGem() {
00049 }
00050  
00051 //
00052 // member functions
00053 //
00054 
00055 void TotemTestGem::produce(edm::Event& e, const edm::EventSetup&) {
00056 
00057   std::auto_ptr<TotemTestHistoClass> product(new TotemTestHistoClass);
00058   fillEvent(*product);
00059   e.put(product);
00060 }
00061 
00062 void TotemTestGem::update(const BeginOfEvent * evt) {
00063 
00064   int iev = (*evt)()->GetEventID();
00065   LogDebug("ForwardSim") << "TotemTestGem: Begin of event = " << iev;
00066   clear();
00067 
00068 }
00069 
00070 void TotemTestGem::update(const EndOfEvent * evt) {  
00071 
00072   evtnum = (*evt)()->GetEventID();
00073   LogDebug("ForwardSim") << "TotemTestGem:: Fill event " << evtnum;
00074 
00075   // access to the G4 hit collections 
00076   G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
00077   
00078   int nhit = 0;
00079   for (unsigned int in=0; in<names.size(); in++) {
00080     int HCid = G4SDManager::GetSDMpointer()->GetCollectionID(names[in]);
00081     TotemG4HitCollection* theHC = (TotemG4HitCollection*) allHC->GetHC(HCid);
00082     LogDebug("ForwardSim") << "TotemTestGem :: Hit Collection for " <<names[in]
00083                            << " of ID " << HCid << " is obtained at " << theHC;
00084 
00085     if (HCid >= 0 && theHC > 0) {
00086       int nentries = theHC->entries();
00087       LogDebug("ForwardSim") << "TotemTestGem :: " << names[in] << " with "
00088                              << nentries << " entries";
00089       for (int ihit = 0; ihit <nentries; ihit++) {
00090         TotemG4Hit* aHit = (*theHC)[ihit];
00091         hits.push_back(aHit);
00092       }
00093       nhit += nentries;
00094     }
00095   }
00096  
00097   // Writing the data to the Tree
00098   LogDebug("ForwardSim") << "TotemTestGem:: --- after fillTree with " << nhit
00099                          << " Hits";
00100 }
00101  
00102 void TotemTestGem::fillEvent(TotemTestHistoClass& product) {
00103 
00104   product.setEVT(evtnum);
00105   
00106   for (unsigned ihit = 0; ihit < hits.size(); ihit++) {
00107     TotemG4Hit* aHit = hits[ihit];
00108     int UID     = aHit->getUnitID();
00109     int Ptype   = aHit->getParticleType();
00110     int TID     = aHit->getTrackID();
00111     int PID     = aHit->getParentId();
00112     float ELoss = aHit->getEnergyLoss();
00113     float PABS  = aHit->getPabs();
00114     float x     = aHit->getEntry().x();
00115     float y     = aHit->getEntry().y();
00116     float z     = aHit->getEntry().z();
00117     float vx    = aHit->getVx();
00118     float vy    = aHit->getVy();
00119     float vz    = aHit->getVz();
00120     product.fillHit(UID, Ptype, TID, PID, ELoss, PABS, vx, vy, vz, x, y,z);
00121   }
00122 } 
00123 
00124 void TotemTestGem::clear() {
00125 
00126   evtnum = 0;
00127   hits.clear();
00128 }

Generated on Tue Jun 9 17:46:57 2009 for CMSSW by  doxygen 1.5.4