114 #include "CLHEP/Vector/LorentzVector.h"
137 #include "CLHEP/Units/GlobalPhysicalConstants.h"
138 #include "CLHEP/Units/GlobalSystemOfUnits.h"
166 std::unique_ptr<HOCalibVariableCollection>& hostore,
175 void findHOEtaPhi(
int iphsect,
int& ietaho,
int& iphiho);
272 tok_geom_ = esConsumes<CaloGeometry, CaloGeometryRecord>();
274 tok_magField_ = esConsumes<MagneticField, IdealMagneticFieldRecord>();
276 produces<HOCalibVariableCollection>(
"HOCalibVariableCollection").setBranchAlias(
"HOCalibVariableCollection");
283 for (
int ij = 0; ij < 5; ij++) {
284 sprintf(
title,
"ho_occupency (>%i #sigma)", ij + 2);
297 int irun =
iEvent.id().run();
304 <<
" " <<
iEvent.id().event();
308 auto hostore = std::make_unique<HOCalibVariableCollection>();
315 tmpHOCalib.
nprim = -1;
320 muonOK = (cosmicmuon.
isValid() && !cosmicmuon->empty());
323 muonOK = (collisionmuon.
isValid() && !collisionmuon->empty());
325 if (
iEvent.isRealData()) {
348 int Noccu_old =
Noccu;
360 for (reco::TrackCollection::const_iterator ncosm = cosmicmuon->begin(); ncosm != cosmicmuon->end();
362 if ((*ncosm).ndof() < 15)
364 if ((*ncosm).normalizedChi2() > 30.0)
367 fillHOStore(tRef, tmpHOCalib, hostore, Noccu_old, indx, cosmicmuon, muon1,
iEvent, gHO, magField);
370 for (muon1 = collisionmuon->begin(); muon1 < collisionmuon->end(); muon1++) {
371 if ((!muon1->isGlobalMuon()) || (!muon1->isTrackerMuon()))
374 fillHOStore(ncosm, tmpHOCalib, hostore, Noccu_old, 0, cosmicmuon, muon1,
iEvent, gHO, magField);
392 for (
int ij = 0; ij < 5; ij++) {
401 std::unique_ptr<HOCalibVariableCollection>& hostore,
412 int charge = ncosm->charge();
414 double innerr = (*ncosm).innerPosition().Perp2();
415 double outerr = (*ncosm).outerPosition().Perp2();
416 int iiner = (innerr < outerr) ? 1 : 0;
427 double posx, posy, posz;
428 double momx, momy, momz;
431 posx = (*ncosm).innerPosition().X();
432 posy = (*ncosm).innerPosition().Y();
433 posz = (*ncosm).innerPosition().Z();
435 momx = (*ncosm).innerMomentum().X();
436 momy = (*ncosm).innerMomentum().Y();
437 momz = (*ncosm).innerMomentum().Z();
440 posx = (*ncosm).outerPosition().X();
441 posy = (*ncosm).outerPosition().Y();
442 posz = (*ncosm).outerPosition().Z();
444 momx = (*ncosm).outerMomentum().X();
445 momy = (*ncosm).outerMomentum().Y();
446 momz = (*ncosm).outerMomentum().Z();
451 CLHEP::Hep3Vector tmpmuon3v(posx, posy, posz);
452 CLHEP::Hep3Vector tmpmuondir(momx, momy, momz);
454 bool samedir = (tmpmuon3v.dot(tmpmuondir) > 0) ?
true :
false;
455 for (
int ij = 0; ij < 3; ij++) {
456 tmpHOCalib.
caloen[ij] = 0.0;
463 for (reco::TrackCollection::const_iterator ncosmcor = cosmicmuon->begin(); ncosmcor != cosmicmuon->end();
467 CLHEP::Hep3Vector tmpmuon3vcor;
468 CLHEP::Hep3Vector tmpmom3v;
470 tmpmuon3vcor = CLHEP::Hep3Vector(
471 (*ncosmcor).innerPosition().X(), (*ncosmcor).innerPosition().Y(), (*ncosmcor).innerPosition().Z());
472 tmpmom3v = CLHEP::Hep3Vector(
473 (*ncosmcor).innerMomentum().X(), (*ncosmcor).innerMomentum().Y(), (*ncosmcor).innerMomentum().Z());
475 tmpmuon3vcor = CLHEP::Hep3Vector(
476 (*ncosmcor).outerPosition().X(), (*ncosmcor).outerPosition().Y(), (*ncosmcor).outerPosition().Z());
477 tmpmom3v = CLHEP::Hep3Vector(
478 (*ncosmcor).outerMomentum().X(), (*ncosmcor).outerMomentum().Y(), (*ncosmcor).outerMomentum().Z());
481 if (tmpmom3v.mag() < 0.2 || (*ncosmcor).ndof() < 5)
484 double angle = tmpmuon3v.angle(tmpmuon3vcor);
485 if (
angle < 7.5 * CLHEP::deg) {
490 if (
angle < 7.5 * CLHEP::deg) {
491 tmpHOCalib.
caloen[0] += 1.;
493 if (
angle < 15.0 * CLHEP::deg) {
494 tmpHOCalib.
caloen[1] += 1.;
496 if (
angle < 35.0 * CLHEP::deg) {
497 tmpHOCalib.
caloen[2] += 1.;
507 double ith = (*calt).momentum().theta();
508 double iph = (*calt).momentum().phi();
510 CLHEP::Hep3Vector calo3v(
sin(ith) *
cos(iph),
sin(ith) *
sin(iph),
cos(ith));
512 double angle = tmpmuon3v.angle(calo3v);
514 if (
angle < 7.5 * CLHEP::deg) {
515 tmpHOCalib.
caloen[0] += calt->emEnergy() + calt->hadEnergy();
517 if (
angle < 15 * CLHEP::deg) {
518 tmpHOCalib.
caloen[1] += calt->emEnergy() + calt->hadEnergy();
520 if (
angle < 35 * CLHEP::deg) {
521 tmpHOCalib.
caloen[2] += calt->emEnergy() + calt->hadEnergy();
528 double mom =
sqrt(momx * momx + momy * momy + momz * momz);
536 tmpHOCalib.
trkdr = (*ncosm).d0();
537 tmpHOCalib.
trkdz = (*ncosm).dz();
539 tmpHOCalib.
trkvx = glbpt.
x();
540 tmpHOCalib.
trkvy = glbpt.
y();
541 tmpHOCalib.
trkvz = glbpt.
z();
546 tmpHOCalib.
isect = -2;
547 tmpHOCalib.
hodx = -100;
548 tmpHOCalib.
hody = -100;
549 tmpHOCalib.
hoang = -2.0;
551 tmpHOCalib.
ndof = (inearbymuon == 0) ? (
int)(*ncosm).ndof() : -(
int)(*ncosm).ndof();
552 tmpHOCalib.
chisq = (*ncosm).normalizedChi2();
562 tmpHOCalib.
therr = 0.;
563 tmpHOCalib.
pherr = 0.;
566 tmpHOCalib.
therr = innercov(1, 1);
567 tmpHOCalib.
pherr = innercov(2, 2);
570 tmpHOCalib.
therr = outercov(1, 1);
571 tmpHOCalib.
pherr = outercov(2, 2);
577 double phiho = trkpos.
phi();
579 phiho += CLHEP::twopi;
581 int iphisect_dt =
int(6 * (phiho + 10.0 * CLHEP::deg) /
CLHEP::pi);
582 if (iphisect_dt >= 12)
587 for (
int kl = 0; kl <= 2; kl++) {
588 int iphisecttmp = (kl < 2) ? iphisect_dt + kl : iphisect_dt - 1;
591 if (iphisecttmp >= 12)
594 double phipos = iphisecttmp *
CLHEP::pi / 6.;
595 double phirot = phipos;
606 for (
int ik = 1; ik >= 0; ik--) {
608 double radial =
rHOL1;
620 if (steppingHelixstateinfo_.
isValid()) {
627 int ixeta = ClosestCell.
ieta();
628 int ixphi = ClosestCell.
iphi();
635 CLHEP::Hep3Vector hotrkdir2(steppingHelixstateinfo_.
momentum().
x(),
641 double xx = lclvt0.x();
642 double yy = lclvt0.y();
648 iphisect = iphisecttmp;
652 if (iphisect != iphisecttmp)
663 tmpHOCalib.
momatho = hotrkdir2.mag();
664 tmpHOCalib.
hoang = CLHEP::Hep3Vector(zLocal.
x(), zLocal.
y(), zLocal.
z()).
dot(hotrkdir2.unit());
681 for (
int ij = 0; ij < 9; ij++) {
682 tmpHOCalib.
hosig[ij] = -100.0;
684 for (
int ij = 0; ij < 18; ij++) {
687 for (
int ij = 0; ij < 9; ij++) {
688 tmpHOCalib.
hbhesig[ij] = -100.0;
690 tmpHOCalib.
hocro = -100;
691 tmpHOCalib.
htime = -1000;
705 tmpHOCalib.
isect = isect;
737 phimx = 2 *
int((iphiho + 1) / 2.);
740 phimn = 3 *
int((iphiho + 1) / 3.) - 1;
750 for (
int ij = 0; ij < 9; ij++) {
751 tmpHOCalib.
hbhesig[ij] = -100.0;
757 if (!(*hbheht).empty()) {
758 if ((*hbheht).empty())
759 throw(
int)(*hbheht).size();
763 int tmpeta =
id.
ieta();
764 int tmpphi =
id.iphi();
766 int deta = tmpeta - ietaho;
767 if (tmpeta < 0 && ietaho > 0)
769 if (tmpeta > 0 && ietaho < 0)
775 int dphi = tmpphi - iphiho;
789 float signal = (*jk).energy();
791 if (signal > -100 &&
Noccu == Noccu_old) {
792 for (
int ij = 0; ij < 5; ij++) {
793 if (signal > (ij + 2) *
m_sigma) {
804 float signal = (*jk).energy();
806 if (3 * (deta + 1) + dphi + 1 < 9)
807 tmpHOCalib.
hbhesig[3 * (deta + 1) + dphi + 1] = signal;
815 if (!(*hoht).empty()) {
818 int tmpeta =
id.
ieta();
819 int tmpphi =
id.iphi();
822 if (tmpeta >= etamn && tmpeta <= etamx) {
824 ipass1 = (tmpphi >= phimn && tmpphi <= phimx) ? 1 : 0;
826 ipass1 = (tmpphi == 71 || tmpphi == 72 || tmpphi == 1) ? 1 : 0;
830 int deta = tmpeta - ietaho;
831 int dphi = tmpphi - iphiho;
833 if (tmpeta < 0 && ietaho > 0)
835 if (tmpeta > 0 && ietaho < 0)
851 float signal = (*jk).energy();
855 if (ipass1 == 0 && ipass2 == 0)
859 int tmpdph = tmpphi - phimn;
863 int ilog = 2 * (tmpeta - etamn) + tmpdph;
866 ilog = 3 * (tmpeta - etamn) + tmpdph;
868 ilog = 3 * (etamx - tmpeta) + tmpdph;
871 if (ilog > -1 && ilog < 18) {
877 if (3 * (deta + 1) + dphi + 1 < 9) {
878 tmpHOCalib.
hosig[3 * (deta + 1) + dphi + 1] = signal;
882 if (deta == 0 && dphi == 0) {
883 tmpHOCalib.
htime = (*jk).time();
884 tmpHOCalib.
hoflag = (*jk).flags();
890 tmpHOCalib.
hoflag = hitSeverity;
891 int crphi = tmpphi + 6;
898 int etacr = idcr.
ieta();
899 int phicr = idcr.
iphi();
900 if (tmpeta == etacr && crphi == phicr) {
910 if (
Noccu == Noccu_old)
912 hostore->push_back(tmpHOCalib);
920 const double etalow[16] = {0.025,
936 const double etahgh[16] = {35.145,
953 const double philow[6] = {-76.27, -35.11, 0.35, 35.81, 71.77, 108.93};
954 const double phihgh[6] = {-35.81, -0.35, 35.11, 71.07, 108.23, 140.49};
956 const double philow00[6] = {-60.27, -32.91, 0.35, 33.61, 67.37, 102.23};
957 const double phihgh00[6] = {-33.61, -0.35, 32.91, 66.67, 101.53, 129.49};
959 const double philow01[6] = {-64.67, -34.91, 0.35, 35.61, 71.37, 108.33};
960 const double phihgh01[6] = {-35.61, -0.35, 34.91, 70.67, 107.63, 138.19};
965 for (
int ij = 0; ij <
netabin; ij++) {
966 if (tmpdy > etalow[ij] && tmpdy < etahgh[ij]) {
968 float tmp1 = fabs(tmpdy - etalow[ij]);
969 float tmp2 = fabs(tmpdy - etahgh[ij]);
977 if (ij >= 4 && ij < 10)
989 for (
int ij = 0; ij < 6; ij++) {
990 if (
xhor1 > philow[ij] &&
xhor1 < phihgh[ij]) {
992 float tmp1 = fabs(
xhor1 - philow[ij]);
993 float tmp2 = fabs(
xhor1 - phihgh[ij]);
999 for (
int ij = 0; ij < 6; ij++) {
1000 if (
xhor1 > philow01[ij] &&
xhor1 < phihgh01[ij]) {
1002 float tmp1 = fabs(
xhor1 - philow01[ij]);
1003 float tmp2 = fabs(
xhor1 - phihgh01[ij]);
1009 for (
int ij = 0; ij < 6; ij++) {
1010 if (
xhor0 > philow00[ij] &&
xhor0 < phihgh00[ij]) {
1012 float tmp1 = fabs(
xhor0 - philow00[ij]);
1013 float tmp2 = fabs(
xhor0 - phihgh00[ij]);
1015 if (tmpphi != tmpphi0)
1022 for (
int ij = 0; ij < 4; ij++) {
1023 if (tmpdy > etalow[ij] && tmpdy < etahgh[ij]) {
1024 float tmp1 = fabs(tmpdy - etalow[ij]);
1025 float tmp2 = fabs(tmpdy - etahgh[ij]);
1029 if (ij + 1 != ietaho)
1037 iphiho = 6 * iphisect - 2 + tmpphi;