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;
86 const std::vector<std::string>
names;
107 : m_Anal(p.getParameter<edm::
ParameterSet>(
"HcalTB02Analysis")),
108 hcalOnly(m_Anal.getUntrackedParameter<bool>(
"HcalClusterOnly",
true)),
110 produces<HcalTB02HistoClass>();
112 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB02Analysis:: Initialised as observer of "
113 <<
"BeginOfJob/BeginOfEvent/EndOfEvent with "
114 <<
"Parameter values:\n \thcalOnly = " <<
hcalOnly;
133 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB02Analysis: =====> Begin of event = " << (*evt)()->GetEventID();
139 CLHEP::HepRandomEngine* engine = G4Random::getTheEngine();
140 CLHEP::RandGaussQ randGauss(*engine);
144 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB02Analysis::Fill event " << (*evt)()->GetEventID();
147 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
152 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(sd);
155 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB02Analysis :: Hit Collection for " << sd <<
" of ID " << HCHCid
156 <<
" is obtained at " << theHCHC;
159 nentries = theHCHC->entries();
170 XTALSid = G4SDManager::GetSDMpointer()->GetCollectionID(sd);
173 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB02Analysis :: Hit Collection for " << sd <<
" of ID " << XTALSid
174 <<
" is obtained at " << theXTHC;
176 xentries = theXTHC->entries();
182 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB02Analysis :: There are " << nentries <<
" HCal hits, and" << xentries
185 float ETot = 0., xETot = 0.;
186 int scintID = 0, xtalID = 0;
191 if (HCHCid >= 0 && theHCHC !=
nullptr) {
192 for (ihit = 0; ihit < nentries; ihit++) {
195 int layer = org->getlayerID(scintID);
196 float enEm = aHit->
getEM();
208 maxTime =
static_cast<int>(time);
209 histo->fillAllTime(time);
216 float TowerEne[8][18], TowerEneCF[8][18], LayerEne[19], EnRing[100];
217 for (
int iphi = 0; iphi < 8; iphi++) {
218 for (
int jeta = 0; jeta < 18; jeta++) {
219 TowerEne[iphi][jeta] = 0.;
220 TowerEneCF[iphi][jeta] = 0.;
224 for (
int ilayer = 0; ilayer < 19; ilayer++)
225 LayerEne[ilayer] = 0.;
226 for (
int iring = 0; iring < 100; iring++)
232 int layer = org->getlayerID((*is).first);
234 if ((layer != 17) && (layer != 18)) {
235 float eta = org->getetaID((*is).first);
236 float phi = org->getphiID((*is).first);
239 int iphi =
static_cast<int>(
phi);
240 int ieta =
static_cast<int>(
eta);
241 TowerEne[iphi][ieta] += ETot;
243 TowerEneCF[iphi][ieta] += ETot * (1. + 0.1 * randGauss.fire());
244 double dR = 0.08727 *
std::sqrt((eta - 8.) * (eta - 8.) + (phi - 3.) * (phi - 3.));
245 EnRing[
static_cast<int>(dR / 0.01)] += ETot;
248 LayerEne[
layer] += ETot;
251 for (
int ilayer = 0; ilayer < 19; ilayer++) {
252 histo->fillProfile(ilayer, LayerEne[ilayer] / GeV);
255 for (
int iring = 0; iring < 100; iring++)
256 histo->fillTransProf(0.01 * iring + 0.005, EnRing[iring] / GeV);
258 for (
int iphi = 0; iphi < 8; iphi++) {
259 for (
int jeta = 0; jeta < 18; jeta++) {
260 SEnergyN += TowerEneCF[iphi][jeta] + 3. * randGauss.fire();
262 double Rand = 3. * randGauss.fire();
264 if ((iphi >= 0) && (iphi < 7)) {
265 if ((jeta >= 5) && (jeta < 12)) {
269 if ((iphi >= 1) && (iphi < 6)) {
270 if ((jeta >= 6) && (jeta < 11)) {
284 G4PrimaryParticle* thePrim =
nullptr;
285 G4int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
287 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB02Analysis :: Event has " << nvertex <<
" vertex";
291 <<
"ERROR: no vertex";
293 for (
int i = 0;
i < nvertex;
i++) {
294 G4PrimaryVertex* avertex = (*evt)()->GetPrimaryVertex(
i);
295 if (avertex ==
nullptr) {
297 <<
"ERROR: pointer to vertex = 0";
300 int npart = avertex->GetNumberOfParticle();
301 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB02Analysis::Vertex number :" <<
i <<
" with " << npart <<
" particles";
303 if (thePrim ==
nullptr)
304 thePrim = avertex->GetPrimary(trackID);
308 double px = 0., py = 0., pz = 0.;
310 if (thePrim !=
nullptr) {
311 px = thePrim->GetPx();
312 py = thePrim->GetPy();
313 pz = thePrim->GetPz();
317 <<
" ERROR: primary has p=0 ";
319 float costheta = pz /
pInit;
323 phi = std::atan(py / px);
328 edm::LogVerbatim(
"HcalTBSim") <<
"HcalTB02Analysis:: End Of Event ERROR: could not find primary ";
340 if (XTALSid >= 0 && theXTHC !=
nullptr) {
341 for (
int xihit = 0; xihit < xentries; xihit++) {
344 float xenEm = xaHit->
getEM();
345 float xenhad = xaHit->
getHadr();
351 float xCrysEne[7][7];
352 for (
int irow = 0; irow < 7; irow++) {
353 for (
int jcol = 0; jcol < 7; jcol++) {
354 xCrysEne[irow][jcol] = 0.;
359 int xtalID = (*is).first;
360 xETot = (*is).second;
362 int irow =
static_cast<int>(xtalID / 100.);
363 int jcol =
static_cast<int>(xtalID - 100. * irow);
366 xCrysEne[irow][jcol] = xETot;
368 float dR =
std::sqrt(0.01619 * 0.01619 * (jcol - 3) * (jcol - 3) + 0.01606 * 0.01606 * (irow - 3) * (irow - 3));
369 histo->fillTransProf(dR, xETot * 1.05);
371 if ((irow > 0) && (irow < 6)) {
372 if ((jcol > 0) && (jcol < 6)) {
374 xE5x5MatrixN += xCrysEne[irow][jcol] + 108.5 * randGauss.fire();
376 if ((irow > 1) && (irow < 5)) {
377 if ((jcol > 1) && (jcol < 5)) {
379 xE3x3MatrixN += xCrysEne[irow][jcol] + 108.5 * randGauss.fire();
388 if (theXTHC !=
nullptr) {
397 int iEvt = (*evt)()->GetEventID();
400 else if ((iEvt < 100) && (iEvt % 10 == 0))
402 else if ((iEvt < 1000) && (iEvt % 100 == 0))
404 else if ((iEvt < 10000) && (iEvt % 1000 == 0))
Log< level::Info, true > LogVerbatim
void set_Ntimesli(float v)
#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
const std::string names[nVars_]
constexpr std::array< uint8_t, layerIndexSize > layer
void fillEvent(HcalTB02HistoClass &)
const edm::ParameterSet m_Anal
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
const std::vector< std::string > names
void set_partType(float v)
int getTimeSliceID() const
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