CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TotemTestGem.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Forward
4 // Class : TotemTestGem
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author:
10 // Created: Tue May 16 10:14:34 CEST 2006
11 //
12 
13 // system include files
14 #include <iostream>
15 #include <iomanip>
16 #include <cmath>
17 
18 // user include files
21 
25 
28 
29 #include "G4SDManager.hh"
30 #include "G4HCofThisEvent.hh"
31 #include "CLHEP/Units/GlobalSystemOfUnits.h"
32 #include "CLHEP/Units/GlobalPhysicalConstants.h"
33 
34 //
35 // constructors and destructor
36 //
37 
39 
40  edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("TotemTestGem");
41  names = m_Anal.getParameter<std::vector<std::string> >("Names");
42 
43  edm::LogInfo("ForwardSim") << "TotemTestGem:: Initialised as observer of "
44  << "begin of job, begin/end events and of G4step";
45 }
46 
48 }
49 
50 //
51 // member functions
52 //
53 
55 
56  std::auto_ptr<TotemTestHistoClass> product(new TotemTestHistoClass);
57  fillEvent(*product);
58  e.put(product);
59 }
60 
62 
63  int iev = (*evt)()->GetEventID();
64  LogDebug("ForwardSim") << "TotemTestGem: Begin of event = " << iev;
65  clear();
66 
67 }
68 
69 void TotemTestGem::update(const EndOfEvent * evt) {
70 
71  evtnum = (*evt)()->GetEventID();
72  LogDebug("ForwardSim") << "TotemTestGem:: Fill event " << evtnum;
73 
74  // access to the G4 hit collections
75  G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
76 
77  int nhit = 0;
78  for (unsigned int in=0; in<names.size(); in++) {
79  int HCid = G4SDManager::GetSDMpointer()->GetCollectionID(names[in]);
80  TotemG4HitCollection* theHC = (TotemG4HitCollection*) allHC->GetHC(HCid);
81  LogDebug("ForwardSim") << "TotemTestGem :: Hit Collection for " <<names[in]
82  << " of ID " << HCid << " is obtained at " << theHC;
83 
84  if (HCid >= 0 && theHC > 0) {
85  int nentries = theHC->entries();
86  LogDebug("ForwardSim") << "TotemTestGem :: " << names[in] << " with "
87  << nentries << " entries";
88  for (int ihit = 0; ihit <nentries; ihit++) {
89  TotemG4Hit* aHit = (*theHC)[ihit];
90  hits.push_back(aHit);
91  }
92  nhit += nentries;
93  }
94  }
95 
96  // Writing the data to the Tree
97  LogDebug("ForwardSim") << "TotemTestGem:: --- after fillTree with " << nhit
98  << " Hits";
99 }
100 
102 
103  product.setEVT(evtnum);
104 
105  for (unsigned ihit = 0; ihit < hits.size(); ihit++) {
106  TotemG4Hit* aHit = hits[ihit];
107  int UID = aHit->getUnitID();
108  int Ptype = aHit->getParticleType();
109  int TID = aHit->getTrackID();
110  int PID = aHit->getParentId();
111  float ELoss = aHit->getEnergyLoss();
112  float PABS = aHit->getPabs();
113  float x = aHit->getEntry().x();
114  float y = aHit->getEntry().y();
115  float z = aHit->getEntry().z();
116  float vx = aHit->getVx();
117  float vy = aHit->getVy();
118  float vz = aHit->getVz();
119  product.fillHit(UID, Ptype, TID, PID, ELoss, PABS, vx, vy, vz, x, y,z);
120  }
121 }
122 
124 
125  evtnum = 0;
126  hits.clear();
127 }
#define LogDebug(id)
T getParameter(std::string const &) const
void fillEvent(TotemTestHistoClass &)
float getEnergyLoss() const
Definition: TotemG4Hit.cc:150
virtual void produce(edm::Event &, const edm::EventSetup &)
Definition: TotemTestGem.cc:54
math::XYZPoint getEntry() const
Definition: TotemG4Hit.cc:123
float getPabs() const
Definition: TotemG4Hit.cc:148
float getVy() const
Definition: TotemG4Hit.cc:179
void update(const BeginOfEvent *evt)
This routine will be called when the appropriate signal arrives.
Definition: TotemTestGem.cc:61
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Event.h:121
int getTrackID() const
Definition: TotemG4Hit.cc:134
std::vector< std::string > names
Definition: TotemTestGem.h:62
float getVx() const
Definition: TotemG4Hit.cc:176
float getVz() const
Definition: TotemG4Hit.cc:182
int getParentId() const
Definition: TotemG4Hit.cc:173
uint32_t getUnitID() const
Definition: TotemG4Hit.cc:137
std::vector< TotemG4Hit * > hits
Definition: TotemTestGem.h:64
void fillHit(int uID, int pType, int tID, int pID, float eLoss, float pAbs, float vX, float vY, float vZ, float x, float y, float z)
int getParticleType() const
Definition: TotemG4Hit.cc:151
TotemTestGem(const edm::ParameterSet &p)
Definition: TotemTestGem.cc:38
virtual ~TotemTestGem()
Definition: TotemTestGem.cc:47