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();
232 theVertex.SetCoordinates(x0, y0, z0, t0);
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 for (
int j = 0; j < theEBHC->entries(); j++) {
293 float htheta = hpos.theta();
294 float heta = -
log(
tan(htheta * 0.5));
295 float hphi = hpos.phi();
308 MapType eemap, eezpmap, eezmmap;
310 for (
int j = 0; j < theEEHC->entries(); j++) {
317 float htheta = hpos.theta();
318 float heta = -
log(
tan(htheta * 0.5));
319 float hphi = hpos.phi();
327 if (myEEid.
zside() == -1) {
332 if (myEEid.
zside() == 1) {
345 for (
int j = 0; j < theSEHC->entries(); j++) {
350 if (esid.
zside() == -1) {
353 if (esid.
plane() == 1) {
356 }
else if (esid.
plane() == 2) {
361 if (esid.
zside() == 1) {
364 if (esid.
plane() == 1) {
367 }
else if (esid.
plane() == 2) {
376 if (eemap[eemaxid] > ebmap[ebmaxid]) {
379 int ix = myEEid.
ix();
380 int iy = myEEid.
iy();
381 int iz = myEEid.
zside();
397 int by = myEBid.
iphi();
398 int bz = myEBid.
zside();
414 G4StepPoint *preStepPoint = aStep->GetPreStepPoint();
415 const G4ThreeVector &hitPoint = preStepPoint->GetPosition();
416 G4VPhysicalVolume *currentPV = preStepPoint->GetPhysicalVolume();
417 const G4String &
name = currentPV->GetName();
419 crystal.assign(name, 0, 4);
421 float Edeposit = aStep->GetTotalEnergyDeposit();
422 if (crystal ==
"EFRY" && Edeposit > 0.0) {
423 float z = hitPoint.z();
424 float detz = fabs(fabs(z) - 3200);
425 int x0 = (
int)floor(detz / 8.9);
427 eEX0[x0] += Edeposit;
430 if (crystal ==
"EBRY" && Edeposit > 0.0) {
431 float x = hitPoint.x();
432 float y = hitPoint.y();
433 float r =
sqrt(x * x + y * y);
434 float detr = r - 1290;
435 int x0 = (
int)floor(detr / 8.9);
436 eBX0[x0] += Edeposit;
441 int nCellInEta,
int nCellInPhi,
int CentralEta,
int CentralPhi,
int CentralZ,
MapType &fillmap,
MapType &themap) {
442 int goBackInEta = nCellInEta / 2;
443 int goBackInPhi = nCellInPhi / 2;
445 int startEta = CentralEta - goBackInEta;
446 int startPhi = CentralPhi - goBackInPhi;
449 for (
int ieta = startEta; ieta < startEta + nCellInEta; ieta++) {
450 for (
int iphi = startPhi; iphi < startPhi + nCellInPhi; iphi++) {
459 fillmap[i++] = themap[
index];
464 if (fillmap[i / 2] == themap[centerid])
471 int nCellInEta,
int nCellInPhi,
int CentralEta,
int CentralPhi,
int CentralZ,
MapType &fillmap,
MapType &themap) {
472 int goBackInEta = nCellInEta / 2;
473 int goBackInPhi = nCellInPhi / 2;
475 int startEta = CentralZ * CentralEta - goBackInEta;
476 int startPhi = CentralPhi - goBackInPhi;
479 for (
int ieta = startEta; ieta < startEta + nCellInEta; ieta++) {
480 for (
int iphi = startPhi; iphi < startPhi + nCellInPhi; iphi++) {
482 if (
abs(ieta) > 85 ||
abs(ieta) < 1) {
487 }
else if (iphi > 360) {
492 fillmap[i++] = themap[
index];
498 if (fillmap[i / 2] == themap[ebcenterid])
506 float e012 = themap[0] + themap[1] + themap[2];
507 float e036 = themap[0] + themap[3] + themap[6];
508 float e678 = themap[6] + themap[7] + themap[8];
509 float e258 = themap[2] + themap[5] + themap[8];
511 if ((e012 > e678 || e012 == e678) && (e036 > e258 || e036 == e258))
512 return E22 = themap[0] + themap[1] + themap[3] + themap[4];
513 else if ((e012 > e678 || e012 == e678) && (e036 < e258 || e036 == e258))
514 return E22 = themap[1] + themap[2] + themap[4] + themap[5];
515 else if ((e012 < e678 || e012 == e678) && (e036 > e258 || e036 == e258))
516 return E22 = themap[3] + themap[4] + themap[6] + themap[7];
517 else if ((e012 < e678 || e012 == e678) && (e036 < e258 || e036 == e258))
518 return E22 = themap[4] + themap[5] + themap[7] + themap[8];
526 float e0_4 = themap[0] + themap[1] + themap[2] + themap[3] + themap[4];
527 float e0_20 = themap[0] + themap[5] + themap[10] + themap[15] + themap[20];
528 float e4_24 = themap[4] + themap[9] + themap[14] + themap[19] + themap[24];
529 float e0_24 = themap[20] + themap[21] + themap[22] + themap[23] + themap[24];
531 if ((e0_4 > e0_24 || e0_4 == e0_24) && (e0_20 > e4_24 || e0_20 == e4_24))
532 return E44 = e33 + themap[0] + themap[1] + themap[2] + themap[3] + themap[5] + themap[10] + themap[15];
533 else if ((e0_4 > e0_24 || e0_4 == e0_24) && (e0_20 < e4_24 || e0_20 == e4_24))
534 return E44 = e33 + themap[1] + themap[2] + themap[3] + themap[4] + themap[9] + themap[14] + themap[19];
535 else if ((e0_4 < e0_24 || e0_4 == e0_24) && (e0_20 > e4_24 || e0_20 == e4_24))
536 return E44 = e33 + themap[5] + themap[10] + themap[15] + themap[20] + themap[21] + themap[22] + themap[23];
537 else if ((e0_4 < e0_24 || e0_4 == e0_24) && (e0_20 < e4_24 || e0_20 == e4_24))
538 return E44 = e33 + themap[21] + themap[22] + themap[23] + themap[24] + themap[9] + themap[14] + themap[19];
545 int nCellInX,
int nCellInY,
int centralX,
int centralY,
int centralZ,
MapType &themap) {
547 float totalEnergy = 0.;
549 int goBackInX = nCellInX / 2;
550 int goBackInY = nCellInY / 2;
551 int startX = centralX - goBackInX;
552 int startY = centralY - goBackInY;
554 for (
int ix = startX; ix < startX + nCellInX; ix++) {
555 for (
int iy = startY; iy < startY + nCellInY; iy++) {
563 totalEnergy += themap[
index];
566 LogDebug(
"EcalSimHitsValidProducer")
567 <<
" EnergyInEEMatrix: ix - iy - E = " << ix <<
" " << iy <<
" " << themap[
index];
571 LogDebug(
"EcalSimHitsValidProducer") <<
" EnergyInEEMatrix: energy in " << nCellInX <<
" cells in x times " 572 << nCellInY <<
" cells in y matrix = " << totalEnergy <<
" for " << ncristals
579 int nCellInEta,
int nCellInPhi,
int centralEta,
int centralPhi,
int centralZ,
MapType &themap) {
581 float totalEnergy = 0.;
583 int goBackInEta = nCellInEta / 2;
584 int goBackInPhi = nCellInPhi / 2;
585 int startEta = centralZ * centralEta - goBackInEta;
586 int startPhi = centralPhi - goBackInPhi;
588 for (
int ieta = startEta; ieta < startEta + nCellInEta; ieta++) {
589 for (
int iphi = startPhi; iphi < startPhi + nCellInPhi; iphi++) {
591 if (
abs(ieta) > 85 ||
abs(ieta) < 1) {
596 }
else if (iphi > 360) {
602 totalEnergy += themap[
index];
605 LogDebug(
"EcalSimHitsValidProducer")
606 <<
" EnergyInEBMatrix: ieta - iphi - E = " << ieta <<
" " << iphi <<
" " << themap[
index];
610 LogDebug(
"EcalSimHitsValidProducer") <<
" EnergyInEBMatrix: energy in " << nCellInEta <<
" cells in eta times " 611 << nCellInPhi <<
" cells in phi matrix = " << totalEnergy <<
" for " << ncristals
618 uint32_t unitWithMaxEnergy = 0;
621 MapType::iterator iter;
622 for (iter = themap.begin(); iter != themap.end(); iter++) {
623 if (maxEnergy < (*iter).second) {
624 maxEnergy = (*iter).second;
625 unitWithMaxEnergy = (*iter).first;
629 LogDebug(
"EcalSimHitsValidProducer") <<
" Max energy of " << maxEnergy <<
" MeV was found in Unit id 0x" << std::hex
632 return unitWithMaxEnergy;
FloatVector eOfEEMinusCaloG4Hit
FloatVector eOfESCaloG4Hit
void update(const BeginOfEvent *) override
This routine will be called when the appropriate signal arrives.
OrphanHandle< PROD > put(std::unique_ptr< PROD > product)
Put a new product.
FloatVector eOfEEPlusCaloG4Hit
FloatVector phiOfEECaloG4Hit
FloatVector eOfEEMinusCaloG4Hit
FloatVector tOfEECaloG4Hit
constexpr uint32_t rawId() const
get the raw id
FloatVector etaOfEECaloG4Hit
FloatVector phiOfEBCaloG4Hit
math::XYZTLorentzVector theMomentum
FloatVector eOfESCaloG4Hit
bool fillEEMatrix(int nCellInEta, int nCellInPhi, int CentralEta, int CentralPhi, int CentralZ, MapType &fillmap, MapType &themap)
FloatVector etaOfEBCaloG4Hit
math::XYZTLorentzVector theVertex
math::XYZTLorentzVector theMomentum
FloatVector etaOfESCaloG4Hit
int iphi() const
get the crystal iphi
FloatVector eOfEBCaloG4Hit
void fillEventInfo(PEcalValidInfo &)
uint32_t getUnitWithMaxEnergy(MapType &themap)
bool fillEBMatrix(int nCellInEta, int nCellInPhi, int CentralEta, int CentralPhi, int CentralZ, MapType &fillmap, MapType &themap)
FloatVector eOfEBCaloG4Hit
float energyInEBMatrix(int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType &themap)
Tan< T >::type tan(const T &t)
Abs< T >::type abs(const T &t)
FloatVector etaOfEBCaloG4Hit
FloatVector phiOfEECaloG4Hit
FloatVector phiOfESCaloG4Hit
FloatVector eOfEEPlusCaloG4Hit
std::map< uint32_t, float, std::less< uint32_t > > MapType
FloatVector phiOfEBCaloG4Hit
float energyInEEMatrix(int nCellInX, int nCellInY, int centralX, int centralY, int centralZ, MapType &themap)
FloatVector tOfEECaloG4Hit
FloatVector tOfESCaloG4Hit
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
XYZPointD XYZPoint
point in space with cartesian internal representation
math::XYZTLorentzVector theVertex
void produce(edm::Event &, const edm::EventSetup &) override
FloatVector etaOfESCaloG4Hit
FloatVector eOfEECaloG4Hit
float eCluster2x2(MapType &themap)
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
double getTimeSlice() const
~EcalSimHitsValidProducer() override
math::XYZPoint getEntry() const
FloatVector tOfESCaloG4Hit
FloatVector phiOfESCaloG4Hit
uint32_t getUnitID() const
FloatVector etaOfEECaloG4Hit
EcalSimHitsValidProducer(const edm::ParameterSet &)
FloatVector tOfEBCaloG4Hit
FloatVector eOfEECaloG4Hit
int ietaAbs() const
get the absolute value of the crystal ieta
Power< A, B >::type pow(const A &a, const B &b)
FloatVector tOfEBCaloG4Hit
double getEnergyDeposit() const
int zside() const
get the z-side of the crystal (1/-1)
float eCluster4x4(float e33, MapType &themap)