43 #include "G4HCofThisEvent.hh"
44 #include "G4SDManager.hh"
47 #include "G4ThreeVector.hh"
48 #include "G4VProcess.hh"
50 #include <CLHEP/Random/RandGaussQ.h>
51 #include <CLHEP/Random/Randomize.h>
52 #include <CLHEP/Units/GlobalSystemOfUnits.h>
53 #include <CLHEP/Units/GlobalPhysicalConstants.h>
58 class HepRandomEngine;
81 std::unique_ptr<HcalTB02Histo>
histo;
111 produces<HcalTB02HistoClass>();
113 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB02Analysis:: Initialised as observer of "
114 <<
"BeginOfJob/BeginOfEvent/EndOfEvent with "
115 <<
"Parameter values:\n \thcalOnly = " <<
hcalOnly;
117 histo = std::make_unique<HcalTB02Histo>(m_Anal);
134 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB02Analysis: =====> Begin of event = " << (*evt)()->GetEventID();
140 CLHEP::HepRandomEngine* engine = G4Random::getTheEngine();
141 CLHEP::RandGaussQ randGauss(*engine);
144 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis::Fill event " << (*evt)()->GetEventID();
147 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
152 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(sd);
154 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Hit Collection for " << sd <<
" of ID " << HCHCid <<
" is obtained at "
158 nentries = theHCHC->entries();
169 XTALSid = G4SDManager::GetSDMpointer()->GetCollectionID(sd);
171 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Hit Collection for " << sd <<
" of ID " << XTALSid
172 <<
" is obtained at " << theXTHC;
173 xentries = theXTHC->entries();
178 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: There are " << nentries <<
" HCal hits, and" << xentries
181 float ETot = 0., xETot = 0.;
182 int scintID = 0, xtalID = 0;
187 if (HCHCid >= 0 && theHCHC !=
nullptr) {
188 for (ihit = 0; ihit < nentries; ihit++) {
191 int layer = org->getlayerID(scintID);
192 float enEm = aHit->
getEM();
205 histo->fillAllTime(time);
212 float TowerEne[8][18], TowerEneCF[8][18], LayerEne[19], EnRing[100];
213 for (
int iphi = 0; iphi < 8; iphi++) {
214 for (
int jeta = 0; jeta < 18; jeta++) {
215 TowerEne[iphi][jeta] = 0.;
216 TowerEneCF[iphi][jeta] = 0.;
220 for (
int ilayer = 0; ilayer < 19; ilayer++)
221 LayerEne[ilayer] = 0.;
222 for (
int iring = 0; iring < 100; iring++)
228 int layer = org->getlayerID((*is).first);
230 if ((layer != 17) && (layer != 18)) {
231 float eta = org->getetaID((*is).first);
232 float phi = org->getphiID((*is).first);
235 TowerEne[(int)phi][(
int)
eta] += ETot;
237 TowerEneCF[(int)phi][(
int)
eta] += ETot * (1. + 0.1 * randGauss.fire());
238 double dR = 0.08727 *
std::sqrt((eta - 8.) * (eta - 8.) + (phi - 3.) * (phi - 3.));
239 EnRing[(int)(dR / 0.01)] += ETot;
242 LayerEne[
layer] += ETot;
245 for (
int ilayer = 0; ilayer < 19; ilayer++) {
246 histo->fillProfile(ilayer, LayerEne[ilayer] /
GeV);
249 for (
int iring = 0; iring < 100; iring++)
250 histo->fillTransProf(0.01 * iring + 0.005, EnRing[iring] /
GeV);
252 for (
int iphi = 0; iphi < 8; iphi++) {
253 for (
int jeta = 0; jeta < 18; jeta++) {
254 SEnergyN += TowerEneCF[iphi][jeta] + 3. * randGauss.fire();
256 double Rand = 3. * randGauss.fire();
258 if ((iphi >= 0) && (iphi < 7)) {
259 if ((jeta >= 5) && (jeta < 12)) {
263 if ((iphi >= 1) && (iphi < 6)) {
264 if ((jeta >= 6) && (jeta < 11)) {
278 G4PrimaryParticle* thePrim =
nullptr;
279 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
280 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Event has " << nvertex <<
" vertex";
283 <<
"ERROR: no vertex";
285 for (
int i = 0;
i < nvertex;
i++) {
286 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
287 if (avertex ==
nullptr) {
289 <<
"ERROR: pointer to vertex = 0";
291 int npart = avertex->GetNumberOfParticle();
292 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis::Vertex number :" <<
i <<
" with " << npart <<
" particles";
293 if (thePrim ==
nullptr)
294 thePrim = avertex->GetPrimary(trackID);
298 double px = 0., py = 0., pz = 0.;
300 if (thePrim !=
nullptr) {
301 px = thePrim->GetPx();
302 py = thePrim->GetPy();
303 pz = thePrim->GetPz();
307 <<
" ERROR: primary has p=0 ";
309 float costheta = pz /
pInit;
317 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis:: End Of Event ERROR: could"
318 <<
" not find primary ";
329 if (XTALSid >= 0 && theXTHC !=
nullptr) {
330 for (
int xihit = 0; xihit < xentries; xihit++) {
333 float xenEm = xaHit->
getEM();
334 float xenhad = xaHit->
getHadr();
340 float xCrysEne[7][7];
341 for (
int irow = 0; irow < 7; irow++) {
342 for (
int jcol = 0; jcol < 7; jcol++) {
343 xCrysEne[irow][jcol] = 0.;
348 int xtalID = (*is).first;
349 xETot = (*is).second;
351 int irow = (int)(xtalID / 100.);
352 int jcol = (int)(xtalID - 100. * irow);
355 xCrysEne[irow][jcol] = xETot;
357 float dR =
std::sqrt(0.01619 * 0.01619 * (jcol - 3) * (jcol - 3) + 0.01606 * 0.01606 * (irow - 3) * (irow - 3));
358 histo->fillTransProf(dR, xETot * 1.05);
360 if ((irow > 0) && (irow < 6)) {
361 if ((jcol > 0) && (jcol < 6)) {
363 xE5x5MatrixN += xCrysEne[irow][jcol] + 108.5 * randGauss.fire();
365 if ((irow > 1) && (irow < 5)) {
366 if ((jcol > 1) && (jcol < 5)) {
368 xE3x3MatrixN += xCrysEne[irow][jcol] + 108.5 * randGauss.fire();
377 if (theXTHC !=
nullptr) {
386 int iEvt = (*evt)()->GetEventID();
389 else if ((iEvt < 100) && (iEvt % 10 == 0))
391 else if ((iEvt < 1000) && (iEvt % 100 == 0))
393 else if ((iEvt < 10000) && (iEvt % 1000 == 0))
std::string fileNameTuple
Log< level::Info, true > LogVerbatim
void set_Ntimesli(float v)
T getUntrackedParameter(std::string const &, T const &) const
#define DEFINE_SIMWATCHER(type)
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
static std::vector< std::string > checklist log
std::map< int, float > energyInScints
void set_xEentry(float v)
~HcalTB02Analysis() override
Geom::Theta< T > theta() const
double getIncidentEnergy() const
const HcalTB02Analysis & operator=(const HcalTB02Analysis &)=delete
void produce(edm::Event &, const edm::EventSetup &) override
constexpr std::array< uint8_t, layerIndexSize > layer
void fillEvent(HcalTB02HistoClass &)
HcalTB02Analysis(const edm::ParameterSet &p)
void update(const BeginOfEvent *evt) override
This routine will be called when the appropriate signal arrives.
std::unique_ptr< HcalTB02Histo > histo
Tan< T >::type tan(const T &t)
std::map< int, float > primaries
T getParameter(std::string const &) const
void set_partType(float v)
int getTimeSliceID() const
std::vector< std::string > names
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
uint32_t getUnitID() const
Log< level::Warning, false > LogWarning
Power< A, B >::type pow(const A &a, const B &b)
std::map< int, float > energyInCrystals