12 #include "G4PrimaryParticle.hh"
13 #include "G4PrimaryVertex.hh"
14 #include "G4SDManager.hh"
51 label(iPSet.getUntrackedParameter<
std::
string>(
"instanceLabel",
"EcalValidInfo")) {
52 produces<PEcalValidInfo>(
label);
54 for (
int i = 0;
i < 26;
i++) {
75 for (
int i = 0;
i < 26;
i++) {
86 for (
int i = 0;
i < 26;
i++) {
184 for (
int i = 0;
i < 26;
i++) {
218 G4PrimaryParticle *thePrim =
nullptr;
219 int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
221 edm::LogWarning(
"EcalSimHitsValidProducer") <<
" No Vertex in this Event!";
223 for (
int i = 0;
i < nvertex;
i++) {
224 G4PrimaryVertex *avertex = (*evt)()->GetPrimaryVertex(
i);
225 if (avertex ==
nullptr)
226 edm::LogWarning(
"EcalSimHitsValidProducer") <<
" Pointer to vertex is NULL!";
228 float x0 = avertex->GetX0();
229 float y0 = avertex->GetY0();
230 float z0 = avertex->GetZ0();
231 float t0 = avertex->GetT0();
234 int npart = avertex->GetNumberOfParticle();
236 edm::LogWarning(
"EcalSimHitsValidProducer") <<
" No primary particle in this event";
238 if (thePrim ==
nullptr)
239 thePrim = avertex->GetPrimary(trackID);
246 if (thePrim !=
nullptr) {
247 double px = thePrim->GetPx();
248 double py = thePrim->GetPy();
249 double pz = thePrim->GetPz();
254 edm::LogWarning(
"EcalSimHitsValidProducer") <<
" Primary has p = 0 ; ";
264 thePID = thePrim->GetPDGcode();
266 edm::LogWarning(
"EcalSimHitsValidProducer") <<
" Could not find the primary particle!!";
270 G4HCofThisEvent *allHC = (*evt)()->GetHCofThisEvent();
271 int EBHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
"EcalHitsEB");
272 int EEHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
"EcalHitsEE");
273 int SEHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
"EcalHitsES");
286 int theebhc_entries = theEBHC->entries();
287 for (
int j = 0;
j < theebhc_entries;
j++) {
294 float htheta = hpos.theta();
295 float heta = -
log(
tan(htheta * 0.5));
296 float hphi = hpos.phi();
309 MapType eemap, eezpmap, eezmmap;
310 int theeehc_entries = theEEHC->entries();
311 for (
int j = 0;
j < theeehc_entries;
j++) {
318 float htheta = hpos.theta();
319 float heta = -
log(
tan(htheta * 0.5));
320 float hphi = hpos.phi();
328 if (myEEid.
zside() == -1) {
333 if (myEEid.
zside() == 1) {
346 int thesehc_entries = theSEHC->entries();
347 for (
int j = 0;
j < thesehc_entries;
j++) {
352 if (esid.
zside() == -1) {
355 if (esid.
plane() == 1) {
358 }
else if (esid.
plane() == 2) {
363 if (esid.
zside() == 1) {
366 if (esid.
plane() == 1) {
369 }
else if (esid.
plane() == 2) {
378 if (eemap[eemaxid] > ebmap[ebmaxid]) {
381 int ix = myEEid.
ix();
382 int iy = myEEid.
iy();
383 int iz = myEEid.
zside();
399 int by = myEBid.
iphi();
400 int bz = myEBid.
zside();
416 G4StepPoint *preStepPoint = aStep->GetPreStepPoint();
417 const G4ThreeVector &hitPoint = preStepPoint->GetPosition();
418 G4VPhysicalVolume *currentPV = preStepPoint->GetPhysicalVolume();
419 const G4String &
name = currentPV->GetName();
421 crystal.assign(
name, 0, 4);
423 float Edeposit = aStep->GetTotalEnergyDeposit();
424 if (crystal ==
"EFRY" && Edeposit > 0.0) {
425 float z = hitPoint.z();
426 float detz = fabs(fabs(
z) - 3200);
427 int x0 = (
int)floor(detz / 8.9);
429 eEX0[x0] += Edeposit;
432 if (crystal ==
"EBRY" && Edeposit > 0.0) {
433 float x = hitPoint.x();
434 float y = hitPoint.y();
436 float detr =
r - 1290;
437 int x0 = (
int)floor(detr / 8.9);
438 eBX0[x0] += Edeposit;
443 int nCellInEta,
int nCellInPhi,
int CentralEta,
int CentralPhi,
int CentralZ,
MapType &fillmap,
MapType &themap) {
444 int goBackInEta = nCellInEta / 2;
445 int goBackInPhi = nCellInPhi / 2;
447 int startEta = CentralEta - goBackInEta;
448 int startPhi = CentralPhi - goBackInPhi;
451 for (
int ieta = startEta;
ieta < startEta + nCellInEta;
ieta++) {
452 for (
int iphi = startPhi;
iphi < startPhi + nCellInPhi;
iphi++) {
461 fillmap[
i++] = themap[
index];
466 if (fillmap[
i / 2] == themap[centerid])
473 int nCellInEta,
int nCellInPhi,
int CentralEta,
int CentralPhi,
int CentralZ,
MapType &fillmap,
MapType &themap) {
474 int goBackInEta = nCellInEta / 2;
475 int goBackInPhi = nCellInPhi / 2;
477 int startEta = CentralZ * CentralEta - goBackInEta;
478 int startPhi = CentralPhi - goBackInPhi;
481 for (
int ieta = startEta;
ieta < startEta + nCellInEta;
ieta++) {
482 for (
int iphi = startPhi;
iphi < startPhi + nCellInPhi;
iphi++) {
489 }
else if (
iphi > 360) {
494 fillmap[
i++] = themap[
index];
500 if (fillmap[
i / 2] == themap[ebcenterid])
508 float e012 = themap[0] + themap[1] + themap[2];
509 float e036 = themap[0] + themap[3] + themap[6];
510 float e678 = themap[6] + themap[7] + themap[8];
511 float e258 = themap[2] + themap[5] + themap[8];
513 if ((e012 > e678 || e012 == e678) && (e036 > e258 || e036 == e258))
514 return E22 = themap[0] + themap[1] + themap[3] + themap[4];
515 else if ((e012 > e678 || e012 == e678) && (e036 < e258 || e036 == e258))
516 return E22 = themap[1] + themap[2] + themap[4] + themap[5];
517 else if ((e012 < e678 || e012 == e678) && (e036 > e258 || e036 == e258))
518 return E22 = themap[3] + themap[4] + themap[6] + themap[7];
519 else if ((e012 < e678 || e012 == e678) && (e036 < e258 || e036 == e258))
520 return E22 = themap[4] + themap[5] + themap[7] + themap[8];
528 float e0_4 = themap[0] + themap[1] + themap[2] + themap[3] + themap[4];
529 float e0_20 = themap[0] + themap[5] + themap[10] + themap[15] + themap[20];
530 float e4_24 = themap[4] + themap[9] + themap[14] + themap[19] + themap[24];
531 float e0_24 = themap[20] + themap[21] + themap[22] + themap[23] + themap[24];
533 if ((e0_4 > e0_24 || e0_4 == e0_24) && (e0_20 > e4_24 || e0_20 == e4_24))
534 return E44 = e33 + themap[0] + themap[1] + themap[2] + themap[3] + themap[5] + themap[10] + themap[15];
535 else if ((e0_4 > e0_24 || e0_4 == e0_24) && (e0_20 < e4_24 || e0_20 == e4_24))
536 return E44 = e33 + themap[1] + themap[2] + themap[3] + themap[4] + themap[9] + themap[14] + themap[19];
537 else if ((e0_4 < e0_24 || e0_4 == e0_24) && (e0_20 > e4_24 || e0_20 == e4_24))
538 return E44 = e33 + themap[5] + themap[10] + themap[15] + themap[20] + themap[21] + themap[22] + themap[23];
539 else if ((e0_4 < e0_24 || e0_4 == e0_24) && (e0_20 < e4_24 || e0_20 == e4_24))
540 return E44 = e33 + themap[21] + themap[22] + themap[23] + themap[24] + themap[9] + themap[14] + themap[19];
547 int nCellInX,
int nCellInY,
int centralX,
int centralY,
int centralZ,
MapType &themap) {
549 float totalEnergy = 0.;
551 int goBackInX = nCellInX / 2;
552 int goBackInY = nCellInY / 2;
553 int startX = centralX - goBackInX;
554 int startY = centralY - goBackInY;
556 for (
int ix = startX; ix < startX + nCellInX; ix++) {
557 for (
int iy = startY; iy < startY + nCellInY; iy++) {
565 totalEnergy += themap[
index];
568 LogDebug(
"EcalSimHitsValidProducer")
569 <<
" EnergyInEEMatrix: ix - iy - E = " << ix <<
" " << iy <<
" " << themap[
index];
573 LogDebug(
"EcalSimHitsValidProducer") <<
" EnergyInEEMatrix: energy in " << nCellInX <<
" cells in x times "
574 << nCellInY <<
" cells in y matrix = " << totalEnergy <<
" for " << ncristals
581 int nCellInEta,
int nCellInPhi,
int centralEta,
int centralPhi,
int centralZ,
MapType &themap) {
583 float totalEnergy = 0.;
585 int goBackInEta = nCellInEta / 2;
586 int goBackInPhi = nCellInPhi / 2;
587 int startEta = centralZ * centralEta - goBackInEta;
588 int startPhi = centralPhi - goBackInPhi;
590 for (
int ieta = startEta;
ieta < startEta + nCellInEta;
ieta++) {
591 for (
int iphi = startPhi;
iphi < startPhi + nCellInPhi;
iphi++) {
598 }
else if (
iphi > 360) {
604 totalEnergy += themap[
index];
607 LogDebug(
"EcalSimHitsValidProducer")
608 <<
" EnergyInEBMatrix: ieta - iphi - E = " <<
ieta <<
" " <<
iphi <<
" " << themap[
index];
612 LogDebug(
"EcalSimHitsValidProducer") <<
" EnergyInEBMatrix: energy in " << nCellInEta <<
" cells in eta times "
613 << nCellInPhi <<
" cells in phi matrix = " << totalEnergy <<
" for " << ncristals
620 uint32_t unitWithMaxEnergy = 0;
623 MapType::iterator iter;
624 for (iter = themap.begin(); iter != themap.end(); iter++) {
627 unitWithMaxEnergy = (*iter).first;
631 LogDebug(
"EcalSimHitsValidProducer") <<
" Max energy of " <<
maxEnergy <<
" MeV was found in Unit id 0x" << std::hex
634 return unitWithMaxEnergy;