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"
56 class HepRandomEngine;
80 std::unique_ptr<HcalTB02Histo>
histo;
110 produces<HcalTB02HistoClass>();
112 edm::LogInfo(
"HcalTBSim") <<
"HcalTB02Analysis:: Initialised as observer of "
113 <<
"BeginOfJob/BeginOfEvent/EndOfEvent with "
114 <<
"Parameter values:\n \thcalOnly = " <<
hcalOnly;
116 histo = std::make_unique<HcalTB02Histo>(m_Anal);
132 edm::LogInfo(
"HcalTBSim") <<
"HcalTB02Analysis: =====> Begin of event = " << (*evt)()->GetEventID();
137 CLHEP::HepRandomEngine* engine = G4Random::getTheEngine();
138 CLHEP::RandGaussQ randGauss(*engine);
141 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis::Fill event " << (*evt)()->GetEventID();
144 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
149 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
sd);
151 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Hit Collection for " <<
sd <<
" of ID " << HCHCid <<
" is obtained at "
155 nentries = theHCHC->entries();
166 XTALSid = G4SDManager::GetSDMpointer()->GetCollectionID(
sd);
168 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Hit Collection for " <<
sd <<
" of ID " << XTALSid
169 <<
" is obtained at " << theXTHC;
170 xentries = theXTHC->entries();
175 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: There are " << nentries <<
" HCal hits, and" << xentries
178 float ETot = 0., xETot = 0.;
179 int scintID = 0, xtalID = 0;
184 if (HCHCid >= 0 && theHCHC !=
nullptr) {
185 for (ihit = 0; ihit < nentries; ihit++) {
188 int layer = org->getlayerID(scintID);
189 float enEm = aHit->
getEM();
209 float TowerEne[8][18], TowerEneCF[8][18], LayerEne[19], EnRing[100];
217 for (
int ilayer = 0; ilayer < 19; ilayer++)
218 LayerEne[ilayer] = 0.;
219 for (
int iring = 0; iring < 100; iring++)
225 int layer = org->getlayerID((*is).first);
227 if ((layer != 17) && (layer != 18)) {
228 float eta = org->getetaID((*is).first);
229 float phi = org->getphiID((*is).first);
234 TowerEneCF[(
int)
phi][(
int)
eta] += ETot * (1. + 0.1 * randGauss.fire());
236 EnRing[(
int)(
dR / 0.01)] += ETot;
239 LayerEne[layer] += ETot;
242 for (
int ilayer = 0; ilayer < 19; ilayer++) {
243 histo->fillProfile(ilayer, LayerEne[ilayer] /
GeV);
246 for (
int iring = 0; iring < 100; iring++)
247 histo->fillTransProf(0.01 * iring + 0.005, EnRing[iring] /
GeV);
253 double Rand = 3. * randGauss.fire();
275 G4PrimaryParticle* thePrim =
nullptr;
276 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
277 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis :: Event has " << nvertex <<
" vertex";
280 <<
"ERROR: no vertex";
282 for (
int i = 0;
i < nvertex;
i++) {
283 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
284 if (avertex ==
nullptr) {
286 <<
"ERROR: pointer to vertex = 0";
288 int npart = avertex->GetNumberOfParticle();
289 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis::Vertex number :" <<
i <<
" with " <<
npart <<
" particles";
290 if (thePrim ==
nullptr)
291 thePrim = avertex->GetPrimary(trackID);
295 double px = 0.,
py = 0., pz = 0.;
297 if (thePrim !=
nullptr) {
298 px = thePrim->GetPx();
299 py = thePrim->GetPy();
300 pz = thePrim->GetPz();
304 <<
" ERROR: primary has p=0 ";
306 float costheta = pz /
pInit;
314 LogDebug(
"HcalTBSim") <<
"HcalTB02Analysis:: End Of Event ERROR: could"
315 <<
" not find primary ";
326 if (XTALSid >= 0 && theXTHC !=
nullptr) {
327 for (
int xihit = 0; xihit < xentries; xihit++) {
330 float xenEm = xaHit->
getEM();
331 float xenhad = xaHit->
getHadr();
337 float xCrysEne[7][7];
338 for (
int irow = 0; irow < 7; irow++) {
339 for (
int jcol = 0; jcol < 7; jcol++) {
340 xCrysEne[irow][jcol] = 0.;
345 int xtalID = (*is).first;
346 xETot = (*is).second;
348 int irow = (
int)(xtalID / 100.);
349 int jcol = (
int)(xtalID - 100. * irow);
352 xCrysEne[irow][jcol] = xETot;
354 float dR =
std::sqrt(0.01619 * 0.01619 * (jcol - 3) * (jcol - 3) + 0.01606 * 0.01606 * (irow - 3) * (irow - 3));
355 histo->fillTransProf(
dR, xETot * 1.05);
357 if ((irow > 0) && (irow < 6)) {
358 if ((jcol > 0) && (jcol < 6)) {
360 xE5x5MatrixN += xCrysEne[irow][jcol] + 108.5 * randGauss.fire();
362 if ((irow > 1) && (irow < 5)) {
363 if ((jcol > 1) && (jcol < 5)) {
365 xE3x3MatrixN += xCrysEne[irow][jcol] + 108.5 * randGauss.fire();
374 if (theXTHC !=
nullptr) {
383 int iEvt = (*evt)()->GetEventID();
385 std::cout <<
" Event " << iEvt << std::endl;
386 else if ((iEvt < 100) && (iEvt % 10 == 0))
387 std::cout <<
" Event " << iEvt << std::endl;
388 else if ((iEvt < 1000) && (iEvt % 100 == 0))
389 std::cout <<
" Event " << iEvt << std::endl;
390 else if ((iEvt < 10000) && (iEvt % 1000 == 0))
391 std::cout <<
" Event " << iEvt << std::endl;