26 #include "G4SDManager.hh"
29 #include "G4VProcess.hh"
30 #include "G4HCofThisEvent.hh"
32 #include <CLHEP/Random/Randomize.h>
33 #include <CLHEP/Units/GlobalSystemOfUnits.h>
34 #include <CLHEP/Units/GlobalPhysicalConstants.h>
44 public Observer<const BeginOfEvent*>,
79 std::unique_ptr<HcalTestHistoClass>
tuples_;
85 std::unique_ptr<HcalTestNumberingScheme>
org_;
109 int laygroup = m_Anal.
getParameter<
int>(
"LayerGrouping");
116 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: Initialised as observer of begin/end events"
122 for (
unsigned int i = 0;
i <
group_.size();
i++)
132 myqie_ = std::make_unique<HcalQie>(
p);
134 produces<HcalTestHistoClass>();
138 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: --------> Total number of selected entries : " <<
count_;
144 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Initialize ESGetToken for HcalDDDSimConstants";
153 std::vector<int>
temp(19);
155 int grp[19] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
156 for (
int i = 0;
i < 19;
i++)
158 }
else if (group == 2) {
159 int grp[19] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
160 for (
int i = 0;
i < 19;
i++)
162 }
else if (group == 3) {
163 int grp[19] = {1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7};
164 for (
int i = 0;
i < 19;
i++)
166 }
else if (group == 4) {
167 int grp[19] = {1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7};
168 for (
int i = 0;
i < 19;
i++)
171 int grp[19] = {1, 1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7};
172 for (
int i = 0;
i < 19;
i++)
177 for (
int i = 0;
i < 19;
i++)
183 int etac = (centre / 100) % 100;
184 int phic = (centre % 100);
187 etamin = etac - nadd;
188 etamax = etac + nadd;
194 phimin = phic - nadd;
195 phimax = phic + nadd;
202 nbuf = (etamax - etamin + 1) * (phimax - phimin + 1);
203 std::vector<int>
temp(2 * nbuf);
204 for (
int eta = etamin;
eta <= etamax;
eta++) {
206 temp[kount] = (
eta * 100 +
phi);
212 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: Towers to be considered for Central " << centre <<
" and " << nadd
213 <<
" on either side";
214 for (
int i = 0;
i < nbuf;
i++)
215 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: Tower[" << std::setw(3) <<
i <<
"] " << temp[
i] <<
" "
229 org_ = std::make_unique<HcalTestNumberingScheme>(
false);
234 int irun = (*run)()->GetRunID();
235 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: Begin of Run = " << irun;
257 }
else if (idet == static_cast<int>(
HcalBarrel)) {
259 }
else if (idet == static_cast<int>(
HcalEndcap)) {
267 <<
" corresponds to eta0 = " <<
eta0_ <<
" phi0 = " <<
phi0_;
270 G4SDManager*
sd = G4SDManager::GetSDMpointerIfExist();
272 G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(sdname);
273 if (aSD ==
nullptr) {
274 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: No SD with "
275 <<
"name " << sdname <<
" in this Setup";
278 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Finds SD with name " << theCaloSD->GetName()
282 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: set a new numbering scheme";
286 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Could not get"
294 tuples_ = std::make_unique<HcalTestHistoClass>();
300 for (i = 0; i < 20; i++)
302 for (i = 0; i < 20; i++)
305 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: Begin of event = " << (*evt)()->GetEventID();
310 if (aStep !=
nullptr) {
311 G4VPhysicalVolume* curPV = aStep->GetPreStepPoint()->GetPhysicalVolume();
312 G4String
name = curPV->GetName();
313 name.assign(name, 0, 3);
314 double edeposit = aStep->GetTotalEnergyDeposit();
318 }
else if (name ==
"EFR") {
320 }
else if (name ==
"HBS") {
321 layer = (curPV->GetCopyNo() / 10) % 100;
322 if (layer >= 0 && layer < 17) {
325 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::Error in HB " << curPV->GetName() << curPV->GetCopyNo();
328 }
else if (name ==
"HES") {
329 layer = (curPV->GetCopyNo() / 10) % 100;
330 if (layer >= 0 && layer < 19) {
333 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::Error in HE " << curPV->GetName() << curPV->GetCopyNo();
336 }
else if (name ==
"HTS") {
337 layer = (curPV->GetCopyNo() / 10) % 100;
338 if (layer >= 17 && layer < 20) {
341 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::Error in HO " << curPV->GetName() << curPV->GetCopyNo();
345 if (layer >= 0 && layer < 20) {
349 G4String
part = aStep->GetTrack()->GetDefinition()->GetParticleName();
350 if ((part ==
"mu-" || part ==
"mu+") &&
mudist_[layer] < 0) {
352 aStep->GetPreStepPoint()->GetPosition().y(),
353 aStep->GetPreStepPoint()->GetPosition().z());
354 double theta = pos.theta();
356 double phi = pos.phi();
362 if (layer >= 0 && layer < 20) {
363 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: G4Step: " << name <<
" Layer " << std::setw(3) << layer
364 <<
" Edep " << std::setw(6) << edeposit /
MeV <<
" MeV";
379 CLHEP::HepRandomEngine* engine = G4Random::getTheEngine();
385 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: --- after LayerAnalysis";
390 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: Fill event " << (*evt)()->GetEventID();
393 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
395 int nhc = 0, neb = 0, nef = 0,
j = 0;
399 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names_[0]);
401 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names_[0] <<
" of ID " << HCHCid
402 <<
" is obtained at " << theHCHC;
403 int hchc_entries = theHCHC->entries();
404 if (HCHCid >= 0 && theHCHC !=
nullptr) {
405 for (
j = 0;
j < hchc_entries;
j++) {
412 double theta = pos.theta();
414 double phi = pos.phi();
417 int subdet,
zside,
layer, etaIndex, phiIndex, lay;
418 org_->unpackHcalIndex(unitID, subdet, zside, layer, etaIndex, phiIndex, lay);
422 CaloHit hit(subdet, lay, e, eta, phi, jitter, unitID);
429 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
430 if (etaIndex <= 20) {
437 edm::LogVerbatim(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2) << layer <<
" time "
438 << std::setw(6) << time <<
" theta " << std::setw(8) << theta <<
" eta "
439 << std::setw(8) << eta <<
" phi " << std::setw(8) << phi <<
" e " << std::setw(8)
446 int EBHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names_[1]);
448 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names_[1] <<
" of ID " << EBHCid
449 <<
" is obtained at " << theEBHC;
450 int ebhc_entries = theEBHC->entries();
451 if (EBHCid >= 0 && theEBHC !=
nullptr) {
452 for (
j = 0;
j < ebhc_entries;
j++) {
460 double theta = pos.theta();
462 double phi = pos.phi();
465 uint32_t unitID =
org_->getUnitID(
id);
467 org_->unpackHcalIndex(unitID, subdet, zside, layer, ieta, iphi, lay);
470 unitID =
org_->packHcalIndex(subdet, zside, layer, ieta, iphi, lay);
471 CaloHit hit(subdet, lay, e, eta, phi, time, unitID);
474 edm::LogVerbatim(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2) << layer <<
" time "
475 << std::setw(6) << time <<
" theta " << std::setw(8) << theta <<
" eta "
476 << std::setw(8) << eta <<
" phi " << std::setw(8) << phi <<
" e " << std::setw(8)
483 int EEHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names_[2]);
485 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names_[2] <<
" of ID " << EEHCid
486 <<
" is obtained at " << theEEHC;
487 int eehc_entries = theEEHC->entries();
488 if (EEHCid >= 0 && theEEHC !=
nullptr) {
489 for (
j = 0;
j < eehc_entries;
j++) {
497 double theta = pos.theta();
499 double phi = pos.phi();
502 uint32_t unitID =
org_->getUnitID(
id);
504 org_->unpackHcalIndex(unitID, subdet, zside, layer, ieta, iphi, lay);
507 unitID =
org_->packHcalIndex(subdet, zside, layer, ieta, iphi, lay);
508 CaloHit hit(subdet, lay, e, eta, phi, time, unitID);
511 edm::LogVerbatim(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2) << layer <<
" time "
512 << std::setw(6) << time <<
" theta " << std::setw(8) << theta <<
" eta "
513 << std::setw(8) << eta <<
" phi " << std::setw(8) << phi <<
" e " << std::setw(8)
528 uint32_t unitID =
org_->getUnitID(
id);
530 org_->unpackHcalIndex(unitID, subdet, zside, layer, ieta, iphi, lay);
536 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
540 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Qie: " << det <<
" Eta " << ieta <<
" Phi " << iphi <<
" Laymax "
541 << laymax <<
" Hits " << hittot;
543 if (laymax > 0 && hittot > 0) {
544 std::vector<CaloHit> hits(hittot);
545 std::vector<double> eqielay(80, 0.0), esimlay(80, 0.0), esimtot(4, 0.0);
546 std::vector<double> eqietow(200, 0.0), esimtow(200, 0.0), eqietot(4, 0.0);
550 for (
int layr = 0; layr <
nGroup_; layr++) {
565 for (
int it = 0; it <
nTower_; it++) {
568 for (
int k1 = 0; k1 < hittot; k1++) {
570 int subdetc = hit.
det();
571 int layer = hit.
layer();
573 if (layer > 0 && layer < 20)
575 if (subdetc == subdet && group == layr + 1) {
576 int zsidec, ietac, iphic, idx;
578 org_->unpackHcalIndex(unitID, subdetc, zsidec, layer, ietac, iphic, lay);
579 if (etac > 0 && phic > 0) {
580 idx = ietac * 100 + iphic;
581 }
else if (etac > 0) {
583 }
else if (phic > 0) {
588 if (zsidec == zside && idx ==
tower_[it]) {
597 std::vector<int>
cd =
myqie_->getCode(nhit, hits, engine);
598 double eqie =
myqie_->getEnergy(cd);
600 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Qie: Energy in layer " << layr <<
" Sim " << esim
601 <<
" After QIE " << eqie;
602 for (
int i = 0;
i < 4;
i++) {
603 if (
tower_[nTower_ + it] <=
i) {
606 esimlay[20 *
i + layr] += esim;
607 eqielay[20 *
i + layr] += eqie;
608 esimtow[50 *
i + it] += esim;
609 eqietow[50 *
i + it] += eqie;
614 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Qie: Total energy " << esimtot[3] <<
" (SimHit) " << eqietot[3]
617 std::vector<double> latphi(10);
619 for (
int it = 0; it <
nt; it++)
621 for (
int i = 0;
i < 4;
i++) {
622 double scals = 1, scalq = 1;
623 std::vector<double> latfs(10, 0.), latfq(10, 0.), longs(20), longq(20);
625 scals = 1. / esimtot[
i];
627 scalq = 1. / eqietot[
i];
628 for (
int it = 0; it <
nTower_; it++) {
630 latfs[phib] += scals * esimtow[50 *
i + it];
631 latfq[phib] += scalq * eqietow[50 *
i + it];
633 for (
int layr = 0; layr <=
nGroup_; layr++) {
634 longs[layr] = scals * esimlay[20 *
i + layr];
635 longq[layr] = scalq * eqielay[20 *
i + layr];
637 tuples_->fillQie(
i, esimtot[
i], eqietot[i], nGroup_, longs, longq, nt, latphi, latfs, latfq);
645 edm::LogVerbatim(
"HcalSim") <<
"\n ===>>> HcalTestAnalysis: Energy deposit "
646 <<
"\n at EB : " << std::setw(6) <<
edepEB_ /
MeV <<
"\n at EE : " << std::setw(6)
648 <<
"\n at HE : " << std::setw(6) <<
edepHE_ /
MeV <<
"\n at HO : " << std::setw(6)
649 <<
edepHO_ /
MeV <<
"\n ---- HcalTestAnalysis: Energy deposit in Layers";
650 for (i = 0; i < 20; i++)
658 double theta = 2.0 * atan(
exp(-eta));
661 const double rLay[19] = {1836.0,
680 if (layer > 0 && layer < 20)
681 dist += rLay[layer - 1] * mm /
sin(theta);
683 const double zLay[19] = {4034.0,
702 if (layer > 0 && layer < 20)
703 dist += zLay[layer - 1] * mm /
cos(theta);
705 double tmp = dist / c_light / ns;
706 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::timeOfFlight " << tmp <<
" for det/lay " << det <<
" " << layer
707 <<
" eta/theta " << eta <<
" " << theta / deg <<
" dist " << dist;
Log< level::Info, true > LogVerbatim
#define DEFINE_SIMWATCHER(type)
math::XYZPoint getPosition() const
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
static std::vector< std::string > checklist log
std::unique_ptr< HcalTestHistoClass > tuples_
std::vector< int > layerGrouping(int)
std::unique_ptr< HcalNumberingFromDDD > numberingFromDDD_
Sin< T >::type sin(const T &t)
Geom::Theta< T > theta() const
std::vector< std::string > names_
Exp< T >::type exp(const T &t)
void beginRun(edm::EventSetup const &) override
HcalCellType::HcalCell cell(const int &det, const int &zside, const int &depth, const int &etaR, const int &iphi) const
void setNumberingScheme(HcalNumberingScheme *)
std::vector< int > towersToAdd(int centre, int nadd)
constexpr std::array< uint8_t, layerIndexSize > layer
void produce(edm::Event &, const edm::EventSetup &) override
bool getData(T &iHolder) const
double timeOfFlight(int det, int layer, double eta)
void fill(const EndOfEvent *ev)
std::vector< int > tower_
HcalTestAnalysis(const edm::ParameterSet &p)
const HcalDDDSimConstants * hcons_
Cos< T >::type cos(const T &t)
~HcalTestAnalysis() override
std::unique_ptr< HcalQie > myqie_
Tan< T >::type tan(const T &t)
Abs< T >::type abs(const T &t)
void registerConsumes(edm::ConsumesCollector) override
XYZPointD XYZPoint
point in space with cartesian internal representation
std::unique_ptr< HcalTestNumberingScheme > org_
T getParameter(std::string const &) const
std::vector< CaloHit > caloHitCache_
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
double getTimeSlice() const
edm::ESGetToken< HcalDDDSimConstants, HcalSimNumberingRecord > ddconsToken_
void update(const BeginOfRun *run) override
This routine will be called when the appropriate signal arrives.
void qieAnalysis(CLHEP::HepRandomEngine *)
uint32_t getUnitID() const
Log< level::Warning, false > LogWarning
std::vector< int > group_
double getEnergyDeposit() const