CMS 3D CMS Logo

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 <cmath>
15 #include <iomanip>
16 #include <iostream>
17 #include <memory>
18 #include <string>
19 #include <vector>
20 
21 // user include files
22 
27 
29 
32 
38 
39 #include "G4SDManager.hh"
40 #include "G4Step.hh"
41 #include "G4HCofThisEvent.hh"
42 
43 #include <CLHEP/Units/GlobalSystemOfUnits.h>
44 #include <CLHEP/Units/GlobalPhysicalConstants.h>
45 
46 class TotemTestGem : public SimProducer, public Observer<const BeginOfEvent*>, public Observer<const EndOfEvent*> {
47 public:
49  ~TotemTestGem() override;
50 
51  void produce(edm::Event&, const edm::EventSetup&) override;
52 
53 protected:
54  // observer classes
55  void update(const BeginOfEvent* evt) override;
56  void update(const EndOfEvent* evt) override;
57 
58 private:
59  void clear();
61 
62  //Keep parameters and internal memory
63  std::vector<std::string> names;
64  int evtnum;
65  std::vector<TotemG4Hit*> hits;
66 };
67 
68 //
69 // constructors and destructor
70 //
71 
73  edm::ParameterSet m_Anal = p.getParameter<edm::ParameterSet>("TotemTestGem");
74  names = m_Anal.getParameter<std::vector<std::string> >("Names");
75 
76  edm::LogVerbatim("ForwardSim")
77  << "TotemTestGem:: Initialised as observer of begin of job, begin/end events and of G4step";
78 }
79 
81 
82 //
83 // member functions
84 //
85 
87  std::unique_ptr<TotemTestHistoClass> product(new TotemTestHistoClass);
88  fillEvent(*product);
89  e.put(std::move(product));
90 }
91 
93  int iev = (*evt)()->GetEventID();
94  LogDebug("ForwardSim") << "TotemTestGem: Begin of event = " << iev;
95  clear();
96 }
97 
98 void TotemTestGem::update(const EndOfEvent* evt) {
99  evtnum = (*evt)()->GetEventID();
100  LogDebug("ForwardSim") << "TotemTestGem:: Fill event " << evtnum;
101 
102  // access to the G4 hit collections
103  G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
104 
105  int nhit = 0;
106  for (unsigned int in = 0; in < names.size(); in++) {
107  int HCid = G4SDManager::GetSDMpointer()->GetCollectionID(names[in]);
108  TotemG4HitCollection* theHC = (TotemG4HitCollection*)allHC->GetHC(HCid);
109  LogDebug("ForwardSim") << "TotemTestGem :: Hit Collection for " << names[in] << " of ID " << HCid
110  << " is obtained at " << theHC;
111 
112  if (HCid >= 0 && theHC != nullptr) {
113  int nentries = theHC->entries();
114  LogDebug("ForwardSim") << "TotemTestGem :: " << names[in] << " with " << nentries << " entries";
115  for (int ihit = 0; ihit < nentries; ihit++) {
116  TotemG4Hit* aHit = (*theHC)[ihit];
117  hits.push_back(aHit);
118  }
119  nhit += nentries;
120  }
121  }
122 
123  // Writing the data to the Tree
124  LogDebug("ForwardSim") << "TotemTestGem:: --- after fillTree with " << nhit << " Hits";
125 }
126 
128  product.setEVT(evtnum);
129 
130  for (unsigned ihit = 0; ihit < hits.size(); ihit++) {
131  TotemG4Hit* aHit = hits[ihit];
132  int UID = aHit->getUnitID();
133  int Ptype = aHit->getParticleType();
134  int TID = aHit->getTrackID();
135  int PID = aHit->getParentId();
136  float ELoss = aHit->getEnergyLoss();
137  float PABS = aHit->getPabs();
138  float x = aHit->getEntry().x();
139  float y = aHit->getEntry().y();
140  float z = aHit->getEntry().z();
141  float vx = aHit->getVx();
142  float vy = aHit->getVy();
143  float vz = aHit->getVz();
144  product.fillHit(UID, Ptype, TID, PID, ELoss, PABS, vx, vy, vz, x, y, z);
145  }
146 }
147 
149  evtnum = 0;
150  hits.clear();
151 }
152 
155 
Log< level::Info, true > LogVerbatim
#define DEFINE_SIMWATCHER(type)
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void produce(edm::Event &, const edm::EventSetup &) override
Definition: TotemTestGem.cc:86
float getPabs() const
Definition: TotemG4Hit.cc:143
void fillEvent(TotemTestHistoClass &)
void update(const BeginOfEvent *evt) override
This routine will be called when the appropriate signal arrives.
Definition: TotemTestGem.cc:92
float getEnergyLoss() const
Definition: TotemG4Hit.cc:145
uint32_t getUnitID() const
Definition: TotemG4Hit.cc:129
std::vector< std::string > names
Definition: TotemTestGem.cc:63
float getVy() const
Definition: TotemG4Hit.cc:174
~TotemTestGem() override
Definition: TotemTestGem.cc:80
int getParentId() const
Definition: TotemG4Hit.cc:168
float getVz() const
Definition: TotemG4Hit.cc:177
HitContainer const *__restrict__ TkSoA const *__restrict__ Quality const *__restrict__ CAHitNtupletGeneratorKernelsGPU::HitToTuple const *__restrict__ int32_t int32_t int iev
float getVx() const
Definition: TotemG4Hit.cc:171
std::vector< TotemG4Hit * > hits
Definition: TotemTestGem.cc:65
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:146
math::XYZPoint getEntry() const
Definition: TotemG4Hit.cc:115
TotemTestGem(const edm::ParameterSet &p)
Definition: TotemTestGem.cc:72
PID
Definition: data.h:16
def move(src, dest)
Definition: eostools.py:511
int getTrackID() const
Definition: TotemG4Hit.cc:126
#define LogDebug(id)