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*>,
76 std::unique_ptr<HcalTestHistoClass>
tuples_;
82 const std::vector<std::string>
names_;
90 std::unique_ptr<HcalTestNumberingScheme>
org_;
106 m_Anal(p.getParameter<edm::
ParameterSet>(
"HcalTestAnalysis")),
107 eta0_(m_Anal.getParameter<double>(
"Eta0")),
108 phi0_(m_Anal.getParameter<double>(
"Phi0")),
109 laygroup_(m_Anal.getParameter<int>(
"LayerGrouping")),
110 centralTower_(m_Anal.getParameter<int>(
"CentralTower")),
111 names_(m_Anal.getParameter<std::
vector<std::
string> >(
"Names")),
112 fileName_(m_Anal.getParameter<std::
string>(
"FileName")),
118 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: Initialised as observer of begin/end events"
124 for (
unsigned int i = 0;
i <
group_.size();
i++)
134 myqie_ = std::make_unique<HcalQie>(
p);
136 produces<HcalTestHistoClass>();
140 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: --------> Total number of selected entries : " <<
count_;
146 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Initialize ESGetToken for HcalDDDSimConstants";
155 std::vector<int>
temp(19);
157 int grp[19] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
158 for (
int i = 0;
i < 19;
i++)
160 }
else if (group == 2) {
161 int grp[19] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
162 for (
int i = 0;
i < 19;
i++)
164 }
else if (group == 3) {
165 int grp[19] = {1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7};
166 for (
int i = 0;
i < 19;
i++)
168 }
else if (group == 4) {
169 int grp[19] = {1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7};
170 for (
int i = 0;
i < 19;
i++)
173 int grp[19] = {1, 1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7};
174 for (
int i = 0;
i < 19;
i++)
179 for (
int i = 0;
i < 19;
i++)
185 int etac = (centre / 100) % 100;
186 int phic = (centre % 100);
189 etamin = etac - nadd;
190 etamax = etac + nadd;
196 phimin = phic - nadd;
197 phimax = phic + nadd;
204 nbuf = (etamax - etamin + 1) * (phimax - phimin + 1);
205 std::vector<int>
temp(2 * nbuf);
206 for (
int eta = etamin;
eta <= etamax;
eta++) {
208 temp[kount] = (
eta * 100 +
phi);
214 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: Towers to be considered for Central " << centre <<
" and " << nadd
215 <<
" on either side";
216 for (
int i = 0;
i < nbuf;
i++)
217 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: Tower[" << std::setw(3) <<
i <<
"] " << temp[
i] <<
" "
231 org_ = std::make_unique<HcalTestNumberingScheme>(
false);
236 int irun = (*run)()->GetRunID();
237 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: Begin of Run = " << irun;
259 }
else if (idet == static_cast<int>(
HcalBarrel)) {
261 }
else if (idet == static_cast<int>(
HcalEndcap)) {
269 <<
" corresponds to eta0 = " <<
eta0_ <<
" phi0 = " <<
phi0_;
272 G4SDManager*
sd = G4SDManager::GetSDMpointerIfExist();
274 G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(sdname);
275 if (aSD ==
nullptr) {
276 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: No SD with "
277 <<
"name " << sdname <<
" in this Setup";
280 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Finds SD with name " << theCaloSD->GetName()
284 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: set a new numbering scheme";
288 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Could not get"
296 tuples_ = std::make_unique<HcalTestHistoClass>();
302 for (i = 0; i < 20; i++)
304 for (i = 0; i < 20; i++)
307 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: Begin of event = " << (*evt)()->GetEventID();
312 if (aStep !=
nullptr) {
313 G4VPhysicalVolume* curPV = aStep->GetPreStepPoint()->GetPhysicalVolume();
314 G4String
name = curPV->GetName();
315 name.assign(name, 0, 3);
316 double edeposit = aStep->GetTotalEnergyDeposit();
320 }
else if (name ==
"EFR") {
322 }
else if (name ==
"HBS") {
323 layer = (curPV->GetCopyNo() / 10) % 100;
324 if (layer >= 0 && layer < 17) {
327 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::Error in HB " << curPV->GetName() << curPV->GetCopyNo();
330 }
else if (name ==
"HES") {
331 layer = (curPV->GetCopyNo() / 10) % 100;
332 if (layer >= 0 && layer < 19) {
335 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::Error in HE " << curPV->GetName() << curPV->GetCopyNo();
338 }
else if (name ==
"HTS") {
339 layer = (curPV->GetCopyNo() / 10) % 100;
340 if (layer >= 17 && layer < 20) {
343 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::Error in HO " << curPV->GetName() << curPV->GetCopyNo();
347 if (layer >= 0 && layer < 20) {
351 G4String
part = aStep->GetTrack()->GetDefinition()->GetParticleName();
352 if ((part ==
"mu-" || part ==
"mu+") &&
mudist_[layer] < 0) {
354 aStep->GetPreStepPoint()->GetPosition().y(),
355 aStep->GetPreStepPoint()->GetPosition().z());
356 double theta = pos.theta();
358 double phi = pos.phi();
364 if (layer >= 0 && layer < 20) {
365 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: G4Step: " << name <<
" Layer " << std::setw(3) << layer
366 <<
" Edep " << std::setw(6) << edeposit / MeV <<
" MeV";
381 CLHEP::HepRandomEngine* engine = G4Random::getTheEngine();
387 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: --- after LayerAnalysis";
392 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: Fill event " << (*evt)()->GetEventID();
395 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
397 int nhc = 0, neb = 0, nef = 0,
j = 0;
401 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names_[0]);
403 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names_[0] <<
" of ID " << HCHCid
404 <<
" is obtained at " << theHCHC;
405 int hchc_entries = theHCHC->entries();
406 if (HCHCid >= 0 && theHCHC !=
nullptr) {
407 for (
j = 0;
j < hchc_entries;
j++) {
414 double theta = pos.theta();
416 double phi = pos.phi();
419 int subdet,
zside,
layer, etaIndex, phiIndex, lay;
420 org_->unpackHcalIndex(unitID, subdet, zside, layer, etaIndex, phiIndex, lay);
424 CaloHit hit(subdet, lay, e, eta, phi, jitter, unitID);
431 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
432 if (etaIndex <= 20) {
439 edm::LogVerbatim(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2) << layer <<
" time "
440 << std::setw(6) << time <<
" theta " << std::setw(8) << theta <<
" eta "
441 << std::setw(8) << eta <<
" phi " << std::setw(8) << phi <<
" e " << std::setw(8)
448 int EBHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names_[1]);
450 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names_[1] <<
" of ID " << EBHCid
451 <<
" is obtained at " << theEBHC;
452 int ebhc_entries = theEBHC->entries();
453 if (EBHCid >= 0 && theEBHC !=
nullptr) {
454 for (
j = 0;
j < ebhc_entries;
j++) {
462 double theta = pos.theta();
464 double phi = pos.phi();
467 uint32_t unitID =
org_->getUnitID(
id);
469 org_->unpackHcalIndex(unitID, subdet, zside, layer, ieta, iphi, lay);
472 unitID =
org_->packHcalIndex(subdet, zside, layer, ieta, iphi, lay);
473 CaloHit hit(subdet, lay, e, eta, phi, time, unitID);
476 edm::LogVerbatim(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2) << layer <<
" time "
477 << std::setw(6) << time <<
" theta " << std::setw(8) << theta <<
" eta "
478 << std::setw(8) << eta <<
" phi " << std::setw(8) << phi <<
" e " << std::setw(8)
485 int EEHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names_[2]);
487 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names_[2] <<
" of ID " << EEHCid
488 <<
" is obtained at " << theEEHC;
489 int eehc_entries = theEEHC->entries();
490 if (EEHCid >= 0 && theEEHC !=
nullptr) {
491 for (
j = 0;
j < eehc_entries;
j++) {
499 double theta = pos.theta();
501 double phi = pos.phi();
504 uint32_t unitID =
org_->getUnitID(
id);
506 org_->unpackHcalIndex(unitID, subdet, zside, layer, ieta, iphi, lay);
509 unitID =
org_->packHcalIndex(subdet, zside, layer, ieta, iphi, lay);
510 CaloHit hit(subdet, lay, e, eta, phi, time, unitID);
513 edm::LogVerbatim(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2) << layer <<
" time "
514 << std::setw(6) << time <<
" theta " << std::setw(8) << theta <<
" eta "
515 << std::setw(8) << eta <<
" phi " << std::setw(8) << phi <<
" e " << std::setw(8)
530 uint32_t unitID =
org_->getUnitID(
id);
532 org_->unpackHcalIndex(unitID, subdet, zside, layer, ieta, iphi, lay);
538 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
542 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Qie: " << det <<
" Eta " << ieta <<
" Phi " << iphi <<
" Laymax "
543 << laymax <<
" Hits " << hittot;
545 if (laymax > 0 && hittot > 0) {
546 std::vector<CaloHit> hits(hittot);
547 std::vector<double> eqielay(80, 0.0), esimlay(80, 0.0), esimtot(4, 0.0);
548 std::vector<double> eqietow(200, 0.0), esimtow(200, 0.0), eqietot(4, 0.0);
552 for (
int layr = 0; layr <
nGroup_; layr++) {
567 for (
int it = 0; it <
nTower_; it++) {
570 for (
int k1 = 0; k1 < hittot; k1++) {
572 int subdetc = hit.
det();
573 int layer = hit.
layer();
575 if (layer > 0 && layer < 20)
577 if (subdetc == subdet && group == layr + 1) {
578 int zsidec, ietac, iphic, idx;
580 org_->unpackHcalIndex(unitID, subdetc, zsidec, layer, ietac, iphic, lay);
581 if (etac > 0 && phic > 0) {
582 idx = ietac * 100 + iphic;
583 }
else if (etac > 0) {
585 }
else if (phic > 0) {
590 if (zsidec == zside && idx ==
tower_[it]) {
599 std::vector<int>
cd =
myqie_->getCode(nhit, hits, engine);
600 double eqie =
myqie_->getEnergy(cd);
602 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Qie: Energy in layer " << layr <<
" Sim " << esim
603 <<
" After QIE " << eqie;
604 for (
int i = 0;
i < 4;
i++) {
605 if (
tower_[nTower_ + it] <=
i) {
608 esimlay[20 *
i + layr] += esim;
609 eqielay[20 *
i + layr] += eqie;
610 esimtow[50 *
i + it] += esim;
611 eqietow[50 *
i + it] += eqie;
616 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Qie: Total energy " << esimtot[3] <<
" (SimHit) " << eqietot[3]
619 std::vector<double> latphi(10);
621 for (
int it = 0; it <
nt; it++)
623 for (
int i = 0;
i < 4;
i++) {
624 double scals = 1, scalq = 1;
625 std::vector<double> latfs(10, 0.), latfq(10, 0.), longs(20), longq(20);
627 scals = 1. / esimtot[
i];
629 scalq = 1. / eqietot[
i];
630 for (
int it = 0; it <
nTower_; it++) {
632 latfs[phib] += scals * esimtow[50 *
i + it];
633 latfq[phib] += scalq * eqietow[50 *
i + it];
635 for (
int layr = 0; layr <=
nGroup_; layr++) {
636 longs[layr] = scals * esimlay[20 *
i + layr];
637 longq[layr] = scalq * eqielay[20 *
i + layr];
639 tuples_->fillQie(
i, esimtot[
i], eqietot[i], nGroup_, longs, longq, nt, latphi, latfs, latfq);
647 edm::LogVerbatim(
"HcalSim") <<
"\n ===>>> HcalTestAnalysis: Energy deposit "
648 <<
"\n at EB : " << std::setw(6) <<
edepEB_ / MeV <<
"\n at EE : " << std::setw(6)
649 <<
edepEE_ / MeV <<
"\n at HB : " << std::setw(6) <<
edepHB_ / MeV
650 <<
"\n at HE : " << std::setw(6) <<
edepHE_ / MeV <<
"\n at HO : " << std::setw(6)
651 <<
edepHO_ / MeV <<
"\n ---- HcalTestAnalysis: Energy deposit in Layers";
652 for (i = 0; i < 20; i++)
653 edm::LogVerbatim(
"HcalSim") <<
" Layer " << std::setw(2) << i <<
" E " << std::setw(8) <<
edepl_[
i] / MeV <<
" MeV";
660 double theta = 2.0 * atan(
exp(-eta));
663 const double rLay[19] = {1836.0,
682 if (layer > 0 && layer < 20)
683 dist += rLay[layer - 1] * mm /
sin(theta);
685 const double zLay[19] = {4034.0,
704 if (layer > 0 && layer < 20)
705 dist += zLay[layer - 1] * mm /
cos(theta);
707 double tmp = dist / c_light / ns;
708 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::timeOfFlight " << tmp <<
" for det/lay " << det <<
" " << layer
709 <<
" 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
const std::vector< std::string > names_
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
const edm::ParameterSet m_Anal
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)
const std::string fileName_
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_
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