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/Units/GlobalSystemOfUnits.h"
52 #include "CLHEP/Units/GlobalPhysicalConstants.h"
53 #include "Randomize.hh"
58 class HepRandomEngine;
82 std::unique_ptr<HcalTB02Histo>
histo;
112 produces<HcalTB02HistoClass>();
114 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB02Analysis:: Initialised as observer of "
115 <<
"BeginOfJob/BeginOfEvent/EndOfEvent with "
116 <<
"Parameter values:\n \thcalOnly = " <<
hcalOnly;
118 histo = std::make_unique<HcalTB02Histo>(m_Anal);
135 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB02Analysis: =====> Begin of event = " << (*evt)()->GetEventID();
141 CLHEP::HepRandomEngine* engine = G4Random::getTheEngine();
142 CLHEP::RandGaussQ randGauss(*engine);
145 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis::Fill event " << (*evt)()->GetEventID();
148 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
153 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
sd);
155 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Hit Collection for " <<
sd <<
" of ID " << HCHCid <<
" is obtained at "
159 nentries = theHCHC->entries();
170 XTALSid = G4SDManager::GetSDMpointer()->GetCollectionID(
sd);
172 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Hit Collection for " <<
sd <<
" of ID " << XTALSid
173 <<
" is obtained at " << theXTHC;
174 xentries = theXTHC->entries();
179 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: There are " << nentries <<
" HCal hits, and" << xentries
182 float ETot = 0., xETot = 0.;
183 int scintID = 0, xtalID = 0;
188 if (HCHCid >= 0 && theHCHC !=
nullptr) {
189 for (ihit = 0; ihit < nentries; ihit++) {
192 int layer = org->getlayerID(scintID);
193 float enEm = aHit->
getEM();
213 float TowerEne[8][18], TowerEneCF[8][18], LayerEne[19], EnRing[100];
221 for (
int ilayer = 0; ilayer < 19; ilayer++)
222 LayerEne[ilayer] = 0.;
223 for (
int iring = 0; iring < 100; iring++)
229 int layer = org->getlayerID((*is).first);
232 float eta = org->getetaID((*is).first);
233 float phi = org->getphiID((*is).first);
238 TowerEneCF[(
int)
phi][(
int)
eta] += ETot * (1. + 0.1 * randGauss.fire());
240 EnRing[(
int)(
dR / 0.01)] += ETot;
243 LayerEne[
layer] += ETot;
246 for (
int ilayer = 0; ilayer < 19; ilayer++) {
247 histo->fillProfile(ilayer, LayerEne[ilayer] /
GeV);
250 for (
int iring = 0; iring < 100; iring++)
251 histo->fillTransProf(0.01 * iring + 0.005, EnRing[iring] /
GeV);
257 double Rand = 3. * randGauss.fire();
279 G4PrimaryParticle* thePrim =
nullptr;
280 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
281 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Event has " << nvertex <<
" vertex";
284 <<
"ERROR: no vertex";
286 for (
int i = 0;
i < nvertex;
i++) {
287 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
288 if (avertex ==
nullptr) {
290 <<
"ERROR: pointer to vertex = 0";
292 int npart = avertex->GetNumberOfParticle();
293 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis::Vertex number :" <<
i <<
" with " <<
npart <<
" particles";
294 if (thePrim ==
nullptr)
295 thePrim = avertex->GetPrimary(trackID);
299 double px = 0.,
py = 0., pz = 0.;
301 if (thePrim !=
nullptr) {
302 px = thePrim->GetPx();
303 py = thePrim->GetPy();
304 pz = thePrim->GetPz();
308 <<
" ERROR: primary has p=0 ";
310 float costheta = pz /
pInit;
318 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis:: End Of Event ERROR: could"
319 <<
" not find primary ";
330 if (XTALSid >= 0 && theXTHC !=
nullptr) {
331 for (
int xihit = 0; xihit < xentries; xihit++) {
334 float xenEm = xaHit->
getEM();
335 float xenhad = xaHit->
getHadr();
341 float xCrysEne[7][7];
342 for (
int irow = 0; irow < 7; irow++) {
343 for (
int jcol = 0; jcol < 7; jcol++) {
344 xCrysEne[irow][jcol] = 0.;
349 int xtalID = (*is).first;
350 xETot = (*is).second;
352 int irow = (
int)(xtalID / 100.);
353 int jcol = (
int)(xtalID - 100. * irow);
356 xCrysEne[irow][jcol] = xETot;
358 float dR =
std::sqrt(0.01619 * 0.01619 * (jcol - 3) * (jcol - 3) + 0.01606 * 0.01606 * (irow - 3) * (irow - 3));
359 histo->fillTransProf(
dR, xETot * 1.05);
361 if ((irow > 0) && (irow < 6)) {
362 if ((jcol > 0) && (jcol < 6)) {
364 xE5x5MatrixN += xCrysEne[irow][jcol] + 108.5 * randGauss.fire();
366 if ((irow > 1) && (irow < 5)) {
367 if ((jcol > 1) && (jcol < 5)) {
369 xE3x3MatrixN += xCrysEne[irow][jcol] + 108.5 * randGauss.fire();
378 if (theXTHC !=
nullptr) {
387 int iEvt = (*evt)()->GetEventID();
389 std::cout <<
" Event " << iEvt << std::endl;
390 else if ((iEvt < 100) && (iEvt % 10 == 0))
391 std::cout <<
" Event " << iEvt << std::endl;
392 else if ((iEvt < 1000) && (iEvt % 100 == 0))
393 std::cout <<
" Event " << iEvt << std::endl;
394 else if ((iEvt < 10000) && (iEvt % 1000 == 0))
395 std::cout <<
" Event " << iEvt << std::endl;