13 #include "G4SDManager.hh"
14 #include "G4PrimaryParticle.hh"
15 #include "G4PrimaryVertex.hh"
21 ee1(0.0),ee4(0.0),ee9(0.0),ee16(0.0),ee25(0.0),
22 eb1(0.0),eb4(0.0),eb9(0.0),eb16(0.0),eb25(0.0),
23 totalEInEE(0.0),totalEInEB(0),totalEInES(0.0),totalEInEEzp(0.0),totalEInEEzm(0.0),
24 totalEInESzp(0.0),totalEInESzm(0.0),
25 totalHits(0),nHitsInEE(0),nHitsInEB(0),nHitsInES(0),nHitsIn1ES(0),nHitsIn2ES(0),
26 nCrystalInEB(0),nCrystalInEEzp(0),nCrystalInEEzm(0),
27 nHitsIn1ESzp(0),nHitsIn1ESzm(0),nHitsIn2ESzp(0),nHitsIn2ESzm(0),
29 label(iPSet.getUntrackedParameter<std::
string>(
"instanceLabel",
"EcalValidInfo") )
31 produces<PEcalValidInfo>(
label);
33 for (
int i = 0;
i<26;
i++ ) {
62 for (
int i = 0;
i<26;
i++ ) {
73 for (
int i = 0;
i<26;
i++ ) {
176 for (
int i = 0;
i<26;
i++ ) {
212 G4PrimaryParticle * thePrim = 0;
213 int nvertex = (*evt)()->GetNumberOfPrimaryVertex();
216 <<
" No Vertex in this Event!";
218 for (
int i = 0;
i< nvertex;
i++){
219 G4PrimaryVertex * avertex =(*evt)()->GetPrimaryVertex(
i);
222 <<
" Pointer to vertex is NULL!";
224 float x0 = avertex->GetX0();
225 float y0 = avertex->GetY0();
226 float z0 = avertex->GetZ0();
227 float t0 = avertex->GetT0();
230 int npart = avertex->GetNumberOfParticle();
233 <<
" No primary particle in this event";
236 thePrim = avertex->GetPrimary(trackID);
244 double px = thePrim -> GetPx();
245 double py = thePrim -> GetPy();
246 double pz = thePrim -> GetPz();
252 <<
" Primary has p = 0 ; ";
262 thePID = thePrim->GetPDGcode();
265 <<
" Could not find the primary particle!!";
269 G4HCofThisEvent* allHC = (*evt)()->GetHCofThisEvent();
270 int EBHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
"EcalHitsEB");
271 int EEHCid = G4SDManager::GetSDMpointer()->GetCollectionID(
"EcalHitsEE");
272 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();
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 ) {
346 for (
int j=0;
j<theSEHC->entries();
j++) {
351 if (esid.
zside() == -1) {
355 if (esid.
plane() == 1) {
358 }
else if ( esid.
plane() == 2){
363 if (esid.
zside() == 1) {
367 if (esid.
plane() == 1) {
370 }
else if ( esid.
plane() == 2){
382 if ( eemap[eemaxid] > ebmap[ebmaxid] ) {
385 int ix = myEEid.
ix();
386 int iy = myEEid.
iy();
387 int iz = myEEid.
zside();
403 int by = myEBid.
iphi();
404 int bz = myEBid.
zside();
422 G4StepPoint* preStepPoint = aStep->GetPreStepPoint();
423 G4ThreeVector hitPoint = preStepPoint->GetPosition();
424 G4VPhysicalVolume* currentPV = preStepPoint->GetPhysicalVolume();
425 G4String
name = currentPV->GetName();
427 crystal.assign(name,0,4);
429 float Edeposit = aStep->GetTotalEnergyDeposit();
430 if ( crystal ==
"EFRY"&& Edeposit > 0.0){
431 float z = hitPoint.z();
432 float detz = fabs(fabs(z)-3200);
433 int x0 = (int)floor( detz/8.9 );
435 eEX0[x0] += Edeposit;
438 if(crystal ==
"EBRY" && Edeposit > 0.0) {
439 float x = hitPoint.x();
440 float y = hitPoint.y();
441 float r =
sqrt(x*x +y*y);
442 float detr = r -1290;
443 int x0 = (int)floor( detr/8.9);
444 eBX0[x0] += Edeposit;
450 int CentralEta,
int CentralPhi,
int CentralZ,
453 int goBackInEta = nCellInEta/2;
454 int goBackInPhi = nCellInPhi/2;
456 int startEta = CentralEta - goBackInEta;
457 int startPhi = CentralPhi - goBackInPhi;
460 for (
int ieta = startEta; ieta < startEta+nCellInEta; ieta ++ ) {
462 for(
int iphi = startPhi; iphi < startPhi + nCellInPhi; iphi++ ) {
469 fillmap[i++] = themap[
index];
474 if ( fillmap[i/2] == themap[centerid] )
481 int CentralEta,
int CentralPhi,
int CentralZ,
484 int goBackInEta = nCellInEta/2;
485 int goBackInPhi = nCellInPhi/2;
487 int startEta = CentralZ*CentralEta - goBackInEta;
488 int startPhi = CentralPhi - goBackInPhi;
491 for (
int ieta = startEta; ieta < startEta+nCellInEta; ieta ++ ) {
492 for(
int iphi = startPhi; iphi < startPhi + nCellInPhi; iphi++ ) {
494 if (
abs(ieta) > 85 ||
abs(ieta)<1 ) {
continue; }
495 if (iphi< 1) { index =
EBDetId(ieta,iphi+360).
rawId(); }
496 else if(iphi>360) { index =
EBDetId(ieta,iphi-360).
rawId(); }
498 fillmap[i++] = themap[
index];
504 if ( fillmap[i/2] == themap[ebcenterid] )
513 float e012 = themap[0]+themap[1]+themap[2];
514 float e036 = themap[0]+themap[3]+themap[6];
515 float e678 = themap[6]+themap[7]+themap[8];
516 float e258 = themap[2]+themap[5]+themap[8];
518 if ( (e012>e678 || e012==e678) && (e036>e258 || e036==e258))
519 return E22=themap[0]+themap[1]+themap[3]+themap[4];
520 else if ( (e012>e678 || e012==e678) && (e036<e258 || e036==e258) )
521 return E22=themap[1]+themap[2]+themap[4]+themap[5];
522 else if ( (e012<e678 || e012==e678) && (e036>e258 || e036==e258))
523 return E22=themap[3]+themap[4]+themap[6]+themap[7];
524 else if ( (e012<e678|| e012==e678) && (e036<e258|| e036==e258) )
525 return E22=themap[4]+themap[5]+themap[7]+themap[8];
533 float e0_4 = themap[0]+themap[1]+themap[2]+themap[3]+themap[4];
534 float e0_20 = themap[0]+themap[5]+themap[10]+themap[15]+themap[20];
535 float e4_24 = themap[4]+themap[9]+themap[14]+themap[19]+themap[24];
536 float e0_24 = themap[20]+themap[21]+themap[22]+themap[23]+themap[24];
538 if ((e0_4>e0_24 || e0_4==e0_24) && (e0_20>e4_24|| e0_20==e4_24))
539 return E44=e33+themap[0]+themap[1]+themap[2]+themap[3]+themap[5]+themap[10]+themap[15];
540 else if ((e0_4>e0_24 || e0_4==e0_24) && (e0_20<e4_24 || e0_20==e4_24))
541 return E44=e33+themap[1]+themap[2]+themap[3]+themap[4]+themap[9]+themap[14]+themap[19];
542 else if ((e0_4<e0_24|| e0_4==e0_24) && (e0_20>e4_24 || e0_20==e4_24))
543 return E44=e33+themap[5]+themap[10]+themap[15]+themap[20]+themap[21]+themap[22]+themap[23];
544 else if ((e0_4<e0_24|| e0_4==e0_24) && (e0_20<e4_24 || e0_20==e4_24))
545 return E44=e33+themap[21]+themap[22]+themap[23]+themap[24]+themap[9]+themap[14]+themap[19];
552 int centralX,
int centralY,
553 int centralZ,
MapType& themap){
556 float totalEnergy = 0.;
558 int goBackInX = nCellInX/2;
559 int goBackInY = nCellInY/2;
560 int startX = centralX-goBackInX;
561 int startY = centralY-goBackInY;
563 for (
int ix=startX; ix<startX+nCellInX; ix++) {
564 for (
int iy=startY; iy<startY+nCellInY; iy++) {
571 totalEnergy += themap[
index];
574 LogDebug(
"EcalSimHitsValidProducer")
575 <<
" EnergyInEEMatrix: ix - iy - E = " << ix
576 <<
" " << iy <<
" " << themap[
index] ;
581 LogDebug(
"EcalSimHitsValidProducer")
582 <<
" EnergyInEEMatrix: energy in " << nCellInX
583 <<
" cells in x times " << nCellInY
584 <<
" cells in y matrix = " << totalEnergy
585 <<
" for " << ncristals <<
" crystals";
592 int centralEta,
int centralPhi,
593 int centralZ,
MapType& themap){
596 float totalEnergy = 0.;
598 int goBackInEta = nCellInEta/2;
599 int goBackInPhi = nCellInPhi/2;
600 int startEta = centralZ*centralEta-goBackInEta;
601 int startPhi = centralPhi-goBackInPhi;
603 for (
int ieta=startEta; ieta<startEta+nCellInEta; ieta++) {
604 for (
int iphi=startPhi; iphi<startPhi+nCellInPhi; iphi++) {
607 if (
abs(ieta) > 85 ||
abs(ieta)<1 ) {
continue; }
608 if (iphi< 1) { index =
EBDetId(ieta,iphi+360).
rawId(); }
609 else if(iphi>360) { index =
EBDetId(ieta,iphi-360).
rawId(); }
612 totalEnergy += themap[
index];
615 LogDebug(
"EcalSimHitsValidProducer")
616 <<
" EnergyInEBMatrix: ieta - iphi - E = " << ieta
617 <<
" " << iphi <<
" " << themap[
index];
622 LogDebug(
"EcalSimHitsValidProducer")
623 <<
" EnergyInEBMatrix: energy in " << nCellInEta
624 <<
" cells in eta times " << nCellInPhi
625 <<
" cells in phi matrix = " << totalEnergy
626 <<
" for " << ncristals <<
" crystals";
634 uint32_t unitWithMaxEnergy = 0;
635 float maxEnergy = 0.;
637 MapType::iterator
iter;
638 for (iter = themap.begin(); iter != themap.end(); iter++) {
640 if (maxEnergy < (*iter).second) {
641 maxEnergy = (*iter).second;
642 unitWithMaxEnergy = (*iter).first;
647 LogDebug(
"EcalSimHitsValidProducer")
648 <<
" Max energy of " << maxEnergy
649 <<
" MeV was found in Unit id 0x" << std::hex
652 return unitWithMaxEnergy;
FloatVector eOfEEMinusCaloG4Hit
FloatVector eOfESCaloG4Hit
FloatVector eOfEEPlusCaloG4Hit
FloatVector phiOfEECaloG4Hit
FloatVector eOfEEMinusCaloG4Hit
FloatVector tOfEECaloG4Hit
void produce(edm::Event &, const edm::EventSetup &)
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)
virtual ~EcalSimHitsValidProducer()
FloatVector etaOfEBCaloG4Hit
math::XYZTLorentzVector theVertex
math::XYZTLorentzVector theMomentum
FloatVector etaOfESCaloG4Hit
void update(const BeginOfEvent *)
This routine will be called when the appropriate signal arrives.
int iphi() const
get the crystal iphi
FloatVector eOfEBCaloG4Hit
uint32_t rawId() const
get the raw id
std::map< uint32_t, float, std::less< uint32_t > > MapType
void fillEventInfo(PEcalValidInfo &)
uint32_t getUnitWithMaxEnergy(MapType &themap)
OrphanHandle< PROD > put(std::auto_ptr< PROD > product)
Put a new product.
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
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
FloatVector etaOfESCaloG4Hit
FloatVector eOfEECaloG4Hit
float eCluster2x2(MapType &themap)
G4THitsCollection< CaloG4Hit > CaloG4HitCollection
double getTimeSlice() const
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)