19 #include "G4SDManager.hh" 22 #include "G4VProcess.hh" 23 #include "G4HCofThisEvent.hh" 24 #include "CLHEP/Units/GlobalSystemOfUnits.h" 25 #include "CLHEP/Units/GlobalPhysicalConstants.h" 26 #include "Randomize.hh" 37 int laygroup = m_Anal.
getParameter<
int>(
"LayerGrouping");
44 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: Initialised as observer of begin/end events" 50 for (
unsigned int i = 0;
i <
group_.size();
i++)
64 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: --------> Total number of selected entries : " <<
count_;
69 std::vector<int>
temp(19);
71 int grp[19] = {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
72 for (
int i = 0;
i < 19;
i++)
74 }
else if (group == 2) {
75 int grp[19] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19};
76 for (
int i = 0;
i < 19;
i++)
78 }
else if (group == 3) {
79 int grp[19] = {1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7};
80 for (
int i = 0;
i < 19;
i++)
82 }
else if (group == 4) {
83 int grp[19] = {1, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7};
84 for (
int i = 0;
i < 19;
i++)
87 int grp[19] = {1, 1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7};
88 for (
int i = 0;
i < 19;
i++)
93 for (
int i = 0;
i < 19;
i++)
99 int etac = (centre / 100) % 100;
100 int phic = (centre % 100);
103 etamin = etac - nadd;
104 etamax = etac + nadd;
110 phimin = phic - nadd;
111 phimax = phic + nadd;
118 nbuf = (etamax - etamin + 1) * (phimax - phimin + 1);
119 std::vector<int>
temp(2 * nbuf);
120 for (
int eta = etamin;
eta <= etamax;
eta++) {
122 temp[kount] = (
eta * 100 +
phi);
128 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: Towers to be considered for Central " << centre <<
" and " << nadd
129 <<
" on either side";
130 for (
int i = 0;
i < nbuf;
i++)
131 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: Tower[" << std::setw(3) <<
i <<
"] " << temp[
i] <<
" " 141 (*job)()->get<HcalSimNumberingRecord>().get(hdc);
155 int irun = (*run)()->GetRunID();
156 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: Begin of Run = " << irun;
178 }
else if (idet == static_cast<int>(
HcalBarrel)) {
180 }
else if (idet == static_cast<int>(
HcalEndcap)) {
188 <<
" corresponds to eta0 = " <<
eta0_ <<
" phi0 = " <<
phi0_;
191 G4SDManager*
sd = G4SDManager::GetSDMpointerIfExist();
193 G4VSensitiveDetector* aSD = sd->FindSensitiveDetector(sdname);
194 if (aSD ==
nullptr) {
195 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: No SD with " 196 <<
"name " << sdname <<
" in this Setup";
199 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Finds SD with name " << theCaloSD->GetName()
203 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: set a new numbering scheme";
207 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::beginOfRun: Could not get" 221 for (i = 0; i < 20; i++)
223 for (i = 0; i < 20; i++)
226 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: Begin of event = " << (*evt)()->GetEventID();
231 if (aStep !=
nullptr) {
232 G4VPhysicalVolume* curPV = aStep->GetPreStepPoint()->GetPhysicalVolume();
233 G4String
name = curPV->GetName();
234 name.assign(name, 0, 3);
235 double edeposit = aStep->GetTotalEnergyDeposit();
239 }
else if (name ==
"EFR") {
241 }
else if (name ==
"HBS") {
242 layer = (curPV->GetCopyNo() / 10) % 100;
243 if (layer >= 0 && layer < 17) {
246 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::Error in HB " << curPV->GetName() << curPV->GetCopyNo();
249 }
else if (name ==
"HES") {
250 layer = (curPV->GetCopyNo() / 10) % 100;
251 if (layer >= 0 && layer < 19) {
254 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::Error in HE " << curPV->GetName() << curPV->GetCopyNo();
257 }
else if (name ==
"HTS") {
258 layer = (curPV->GetCopyNo() / 10) % 100;
259 if (layer >= 17 && layer < 20) {
262 edm::LogWarning(
"HcalSim") <<
"HcalTestAnalysis::Error in HO " << curPV->GetName() << curPV->GetCopyNo();
266 if (layer >= 0 && layer < 20) {
267 edepl_[layer] += edeposit;
270 G4String
part = aStep->GetTrack()->GetDefinition()->GetParticleName();
271 if ((part ==
"mu-" || part ==
"mu+") &&
mudist_[layer] < 0) {
273 aStep->GetPreStepPoint()->GetPosition().y(),
274 aStep->GetPreStepPoint()->GetPosition().z());
283 if (layer >= 0 && layer < 20) {
284 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: G4Step: " << name <<
" Layer " << std::setw(3) << layer
285 <<
" Edep " << std::setw(6) << edeposit /
MeV <<
" MeV";
300 CLHEP::HepRandomEngine* engine = G4Random::getTheEngine();
306 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis:: --- after LayerAnalysis";
316 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis: Fill event " << (*evt)()->GetEventID();
319 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
321 int nhc = 0, neb = 0, nef = 0, j = 0;
325 int HCHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names_[0]);
327 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names_[0] <<
" of ID " << HCHCid
328 <<
" is obtained at " << theHCHC;
329 if (HCHCid >= 0 && theHCHC !=
nullptr) {
330 for (j = 0; j < theHCHC->entries(); j++) {
337 double theta = pos.theta();
339 double phi = pos.phi();
342 int subdet,
zside, layer, etaIndex, phiIndex, lay;
347 CaloHit hit(subdet, lay, e, eta, phi, jitter, unitID);
354 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
355 if (etaIndex <= 20) {
362 edm::LogVerbatim(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2) << layer <<
" time " 363 << std::setw(6) << time <<
" theta " << std::setw(8) << theta <<
" eta " 364 << std::setw(8) << eta <<
" phi " << std::setw(8) << phi <<
" e " << std::setw(8)
371 int EBHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names_[1]);
373 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names_[1] <<
" of ID " << EBHCid
374 <<
" is obtained at " << theEBHC;
375 if (EBHCid >= 0 && theEBHC !=
nullptr) {
376 for (j = 0; j < theEBHC->entries(); j++) {
384 double theta = pos.theta();
386 double phi = pos.phi();
390 int subdet,
zside, layer, ieta, iphi, lay;
395 CaloHit hit(subdet, lay, e, eta, phi, time, unitID);
398 edm::LogVerbatim(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2) << layer <<
" time " 399 << std::setw(6) << time <<
" theta " << std::setw(8) << theta <<
" eta " 400 << std::setw(8) << eta <<
" phi " << std::setw(8) << phi <<
" e " << std::setw(8)
407 int EEHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
names_[2]);
409 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis :: Hit Collection for " <<
names_[2] <<
" of ID " << EEHCid
410 <<
" is obtained at " << theEEHC;
411 if (EEHCid >= 0 && theEEHC !=
nullptr) {
412 for (j = 0; j < theEEHC->entries(); j++) {
420 double theta = pos.theta();
422 double phi = pos.phi();
426 int subdet,
zside, layer, ieta, iphi, lay;
431 CaloHit hit(subdet, lay, e, eta, phi, time, unitID);
434 edm::LogVerbatim(
"HcalSim") <<
"HcalTest: " << det <<
" layer " << std::setw(2) << layer <<
" time " 435 << std::setw(6) << time <<
" theta " << std::setw(8) << theta <<
" eta " 436 << std::setw(8) << eta <<
" phi " << std::setw(8) << phi <<
" e " << std::setw(8)
452 int subdet,
zside, layer, ieta, iphi, lay;
459 }
else if (subdet == static_cast<int>(
HcalEndcap)) {
463 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Qie: " << det <<
" Eta " << ieta <<
" Phi " << iphi <<
" Laymax " 464 << laymax <<
" Hits " << hittot;
466 if (laymax > 0 && hittot > 0) {
467 std::vector<CaloHit>
hits(hittot);
468 std::vector<double> eqielay(80, 0.0), esimlay(80, 0.0), esimtot(4, 0.0);
469 std::vector<double> eqietow(200, 0.0), esimtow(200, 0.0), eqietot(4, 0.0);
473 for (
int layr = 0; layr <
nGroup_; layr++) {
488 for (
int it = 0; it <
nTower_; it++) {
491 for (
int k1 = 0; k1 < hittot; k1++) {
493 int subdetc = hit.
det();
494 int layer = hit.
layer();
496 if (layer > 0 && layer < 20)
498 if (subdetc == subdet && group == layr + 1) {
499 int zsidec, ietac, iphic,
idx;
502 if (etac > 0 && phic > 0) {
503 idx = ietac * 100 + iphic;
504 }
else if (etac > 0) {
506 }
else if (phic > 0) {
511 if (zsidec == zside && idx ==
tower_[it]) {
520 std::vector<int>
cd =
myqie_->getCode(nhit, hits, engine);
521 double eqie =
myqie_->getEnergy(cd);
523 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Qie: Energy in layer " << layr <<
" Sim " << esim
524 <<
" After QIE " << eqie;
525 for (
int i = 0;
i < 4;
i++) {
526 if (
tower_[nTower_ + it] <=
i) {
529 esimlay[20 *
i + layr] += esim;
530 eqielay[20 *
i + layr] += eqie;
531 esimtow[50 *
i + it] += esim;
532 eqietow[50 *
i + it] += eqie;
537 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::Qie: Total energy " << esimtot[3] <<
" (SimHit) " << eqietot[3]
540 std::vector<double> latphi(10);
542 for (
int it = 0; it <
nt; it++)
544 for (
int i = 0;
i < 4;
i++) {
545 double scals = 1, scalq = 1;
546 std::vector<double> latfs(10, 0.), latfq(10, 0.), longs(20), longq(20);
548 scals = 1. / esimtot[
i];
550 scalq = 1. / eqietot[
i];
551 for (
int it = 0; it <
nTower_; it++) {
553 latfs[phib] += scals * esimtow[50 *
i + it];
554 latfq[phib] += scalq * eqietow[50 *
i + it];
556 for (
int layr = 0; layr <=
nGroup_; layr++) {
557 longs[layr] = scals * esimlay[20 *
i + layr];
558 longq[layr] = scalq * eqielay[20 *
i + layr];
560 tuples_->
fillQie(
i, esimtot[
i], eqietot[i], nGroup_, longs, longq, nt, latphi, latfs, latfq);
568 edm::LogVerbatim(
"HcalSim") <<
"\n ===>>> HcalTestAnalysis: Energy deposit " 569 <<
"\n at EB : " << std::setw(6) <<
edepEB_ /
MeV <<
"\n at EE : " << std::setw(6)
571 <<
"\n at HE : " << std::setw(6) <<
edepHE_ /
MeV <<
"\n at HO : " << std::setw(6)
572 <<
edepHO_ /
MeV <<
"\n ---- HcalTestAnalysis: Energy deposit in Layers";
573 for (i = 0; i < 20; i++)
581 double theta = 2.0 * atan(
exp(-eta));
584 const double rLay[19] = {1836.0,
603 if (layer > 0 && layer < 20)
604 dist += rLay[layer - 1] * mm /
sin(theta);
606 const double zLay[19] = {4034.0,
625 if (layer > 0 && layer < 20)
626 dist += zLay[layer - 1] * mm /
cos(theta);
628 double tmp = dist / c_light / ns;
629 edm::LogVerbatim(
"HcalSim") <<
"HcalTestAnalysis::timeOfFlight " << tmp <<
" for det/lay " << det <<
" " << layer
630 <<
" eta/theta " << eta <<
" " << theta / deg <<
" dist " << dist;
void fillQie(int id, double esimtot, double eqietot, int nGroup, const std::vector< double > &longs, const std::vector< double > &longq, int nTower, const std::vector< double > &latphi, const std::vector< double > &latfs, const std::vector< double > &latfq)
T getParameter(std::string const &) const
HcalTestNumberingScheme * org_
math::XYZPoint getPosition() const
void fillLayers(double el[], double ho, double hbhe, double muxy[])
std::vector< int > layerGrouping(int)
std::unique_ptr< HcalNumberingFromDDD > numberingFromDDD_
Sin< T >::type sin(const T &t)
Geom::Theta< T > theta() const
void fillHits(std::vector< CaloHit > &)
std::vector< std::string > names_
void update(const BeginOfJob *run) override
This routine will be called when the appropriate signal arrives.
HcalCellType::HcalCell cell(const int &det, const int &zside, const int &depth, const int &etaR, const int &iphi) const
void setNumberingScheme(HcalNumberingScheme *)
HcalTestHistoClass * tuples_
std::vector< int > towersToAdd(int centre, int nadd)
double timeOfFlight(int det, int layer, double eta)
void fill(const EndOfEvent *ev)
static uint32_t packHcalIndex(int det, int z, int depth, int eta, int phi, int lay)
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)
XYZPointD XYZPoint
point in space with cartesian internal representation
std::vector< std::vector< double > > tmp
std::vector< CaloHit > caloHitCache_
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
static void unpackHcalIndex(const uint32_t &idx, int &det, int &z, int &depth, int &eta, int &phi, int &lay)
double getTimeSlice() const
void qieAnalysis(CLHEP::HepRandomEngine *)
uint32_t getUnitID() const
std::vector< int > group_
T const * product() const
std::unique_ptr< HcalTestHistoManager > tuplesManager_
double getEnergyDeposit() const
uint32_t getUnitID(const HcalNumberingFromDDD::HcalID &id) override