Skip to content

Commit 12dfd48

Browse files
mfasDashahor02
authored andcommitted
[EMCAL-700] Replace multiple-if by switch
- Replace multiple if condition for GetSMType by switch condition - Add missing { in one if-condition requested by full CI
1 parent 0f6a442 commit 12dfd48

1 file changed

Lines changed: 105 additions & 74 deletions

File tree

Detectors/EMCAL/base/src/Geometry.cxx

Lines changed: 105 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -594,18 +594,26 @@ void Geometry::DefineEMC(std::string_view mcname, std::string_view mctitle)
594594
} else {
595595
// changed SM Type, redefine the [2*i+1] Boundaries
596596
tmpSMType = GetSMType(2 * i);
597-
if (GetSMType(2 * i) == EMCAL_STANDARD) {
598-
mPhiBoundariesOfSM[2 * i + 1] = mPhiBoundariesOfSM[2 * i] + kfSupermodulePhiWidth;
599-
} else if (GetSMType(2 * i) == EMCAL_HALF) {
600-
mPhiBoundariesOfSM[2 * i + 1] = mPhiBoundariesOfSM[2 * i] + 2. * TMath::ATan2((mParSM[1]) / 2, mIPDistance);
601-
} else if (GetSMType(2 * i) == EMCAL_THIRD) {
602-
mPhiBoundariesOfSM[2 * i + 1] = mPhiBoundariesOfSM[2 * i] + 2. * TMath::ATan2((mParSM[1]) / 3, mIPDistance);
603-
} else if (GetSMType(2 * i) == DCAL_STANDARD) { // jump the gap
604-
mPhiBoundariesOfSM[2 * i] = (mDCALPhiMin - mArm1PhiMin) * TMath::DegToRad() + mPhiBoundariesOfSM[0];
605-
mPhiBoundariesOfSM[2 * i + 1] = (mDCALPhiMin - mArm1PhiMin) * TMath::DegToRad() + mPhiBoundariesOfSM[1];
606-
} else if (GetSMType(2 * i) == DCAL_EXT) {
607-
mPhiBoundariesOfSM[2 * i + 1] = mPhiBoundariesOfSM[2 * i] + 2. * TMath::ATan2((mParSM[1]) / 3, mIPDistance);
608-
}
597+
switch (GetSMType(2 * i)) {
598+
case EMCAL_STANDARD:
599+
mPhiBoundariesOfSM[2 * i + 1] = mPhiBoundariesOfSM[2 * i] + kfSupermodulePhiWidth;
600+
break;
601+
case EMCAL_HALF:
602+
mPhiBoundariesOfSM[2 * i + 1] = mPhiBoundariesOfSM[2 * i] + 2. * TMath::ATan2((mParSM[1]) / 2, mIPDistance);
603+
break;
604+
case EMCAL_THIRD:
605+
mPhiBoundariesOfSM[2 * i + 1] = mPhiBoundariesOfSM[2 * i] + 2. * TMath::ATan2((mParSM[1]) / 3, mIPDistance);
606+
break;
607+
case DCAL_STANDARD:
608+
mPhiBoundariesOfSM[2 * i] = (mDCALPhiMin - mArm1PhiMin) * TMath::DegToRad() + mPhiBoundariesOfSM[0];
609+
mPhiBoundariesOfSM[2 * i + 1] = (mDCALPhiMin - mArm1PhiMin) * TMath::DegToRad() + mPhiBoundariesOfSM[1];
610+
break;
611+
case DCAL_EXT:
612+
mPhiBoundariesOfSM[2 * i + 1] = mPhiBoundariesOfSM[2 * i] + 2. * TMath::ATan2((mParSM[1]) / 3, mIPDistance);
613+
break;
614+
default:
615+
break;
616+
};
609617
}
610618
mPhiCentersOfSM[i] = (mPhiBoundariesOfSM[2 * i] + mPhiBoundariesOfSM[2 * i + 1]) / 2.;
611619
mPhiCentersOfSMSec[i] = mPhiBoundariesOfSM[2 * i] + TMath::ATan2(mParSM[1], mIPDistance);
@@ -614,7 +622,7 @@ void Geometry::DefineEMC(std::string_view mcname, std::string_view mctitle)
614622

615623
// inner extend in eta (same as outer part) for DCal (0.189917), //calculated from the smallest gap (1# cell to the
616624
// 80-degree-edge),
617-
Double_t innerExtandedPhi =
625+
const double INNNER_EXTENDED_PHI =
618626
1.102840997; // calculated from the smallest gap (1# cell to the 80-degree-edge), too complicatd to explain...
619627
mDCALInnerExtandedEta = -TMath::Log(
620628
TMath::Tan((TMath::Pi() / 2. - 8 * mTrd1Angle * TMath::DegToRad() +
@@ -624,20 +632,27 @@ void Geometry::DefineEMC(std::string_view mcname, std::string_view mctitle)
624632
mEMCALPhiMax = mArm1PhiMin;
625633
mDCALPhiMax = mDCALPhiMin; // DCAl extention will not be included
626634
for (Int_t i = 0; i < mNumberOfSuperModules; i += 2) {
627-
if (GetSMType(i) == EMCAL_STANDARD) {
628-
mEMCALPhiMax += 20.;
629-
} else if (GetSMType(i) == EMCAL_HALF) {
630-
mEMCALPhiMax += mPhiSuperModule / 2. + innerExtandedPhi;
631-
} else if (GetSMType(i) == EMCAL_THIRD) {
632-
mEMCALPhiMax += mPhiSuperModule / 3. + 4.0 * innerExtandedPhi / 3.0;
633-
} else if (GetSMType(i) == DCAL_STANDARD) {
634-
mDCALPhiMax += 20.;
635-
mDCALStandardPhiMax = mDCALPhiMax;
636-
} else if (GetSMType(i) == DCAL_EXT) {
637-
mDCALPhiMax += mPhiSuperModule / 3. + 4.0 * innerExtandedPhi / 3.0;
638-
} else {
639-
LOG(ERROR) << "Unkown SM Type!!\n";
640-
}
635+
switch (GetSMType(i)) {
636+
case EMCAL_STANDARD:
637+
mEMCALPhiMax += 20.;
638+
break;
639+
case EMCAL_HALF:
640+
mEMCALPhiMax += mPhiSuperModule / 2. + INNNER_EXTENDED_PHI;
641+
break;
642+
case EMCAL_THIRD:
643+
mEMCALPhiMax += mPhiSuperModule / 3. + 4.0 * INNNER_EXTENDED_PHI / 3.0;
644+
break;
645+
case DCAL_STANDARD:
646+
mDCALPhiMax += 20.;
647+
mDCALStandardPhiMax = mDCALPhiMax;
648+
break;
649+
case DCAL_EXT:
650+
mDCALPhiMax += mPhiSuperModule / 3. + 4.0 * INNNER_EXTENDED_PHI / 3.0;
651+
break;
652+
default:
653+
LOG(ERROR) << "Unkown SM Type!!\n";
654+
break;
655+
};
641656
}
642657
// for compatible reason
643658
// if(fNumberOfSuperModules == 4) {fEMCALPhiMax = fArm1PhiMax ;}
@@ -716,26 +731,33 @@ int Geometry::GetAbsCellId(int supermoduleID, int moduleID, int phiInModule, int
716731
// 0 <= absid < fNCells
717732
int cellid = 0; // have to change from 0 to fNCells-1
718733
for (int i = 0; i < supermoduleID; i++) {
719-
if (GetSMType(i) == EMCAL_STANDARD) {
720-
cellid += mNCellsInSupMod;
721-
} else if (GetSMType(i) == EMCAL_HALF) {
722-
cellid += mNCellsInSupMod / 2;
723-
} else if (GetSMType(i) == EMCAL_THIRD) {
724-
cellid += mNCellsInSupMod / 3;
725-
} else if (GetSMType(i) == DCAL_STANDARD) {
726-
cellid += 2 * mNCellsInSupMod / 3;
727-
} else if (GetSMType(i) == DCAL_EXT) {
728-
cellid += mNCellsInSupMod / 3;
729-
} else {
730-
throw InvalidSupermoduleTypeException();
731-
}
734+
switch (GetSMType(i)) {
735+
case EMCAL_STANDARD:
736+
cellid += mNCellsInSupMod;
737+
break;
738+
case EMCAL_HALF:
739+
cellid += mNCellsInSupMod / 2;
740+
break;
741+
case EMCAL_THIRD:
742+
cellid += mNCellsInSupMod / 3;
743+
break;
744+
case DCAL_STANDARD:
745+
cellid += 2 * mNCellsInSupMod / 3;
746+
break;
747+
case DCAL_EXT:
748+
cellid += mNCellsInSupMod / 3;
749+
break;
750+
default:
751+
throw InvalidSupermoduleTypeException();
752+
};
732753
}
733754

734755
cellid += mNCellsInModule * moduleID;
735756
cellid += mNPHIdiv * phiInModule;
736757
cellid += etaInModule;
737-
if (!CheckAbsCellId(cellid))
758+
if (!CheckAbsCellId(cellid)) {
738759
throw InvalidCellIDException(cellid);
760+
}
739761

740762
return cellid;
741763
}
@@ -749,9 +771,8 @@ std::tuple<int, int, int> Geometry::GetModuleIndexesFromCellIndexesInSModule(int
749771
moduleID = moduleEta * nModulesInSMPhi + modulePhi;
750772
int etaInModule = etaInSupermodule % mNETAdiv,
751773
phiInModule = phiInSupermodule % mNPHIdiv;
752-
phiInModule = phiInSupermodule % mNPHIdiv;
753-
return std::make_tuple(modulePhi, moduleEta, moduleID);
754-
//return std::make_tuple(phiInModule, etaInModule, moduleID);
774+
//return std::make_tuple(modulePhi, moduleEta, moduleID);
775+
return std::make_tuple(phiInModule, etaInModule, moduleID);
755776
}
756777

757778
Int_t Geometry::GetAbsCellIdFromCellIndexes(Int_t nSupMod, Int_t iphi, Int_t ieta) const
@@ -903,13 +924,17 @@ Int_t Geometry::GetAbsCellIdFromEtaPhi(Double_t eta, Double_t phi) const
903924
phi = TVector2::Phi_0_2pi(phi);
904925
Double_t phiLoc = phi - mPhiCentersOfSMSec[nSupMod / 2];
905926
Int_t nphi = mPhiCentersOfCells.size();
906-
if (GetSMType(nSupMod) == EMCAL_HALF) {
907-
nphi /= 2;
908-
} else if (GetSMType(nSupMod) == EMCAL_THIRD) {
909-
nphi /= 3;
910-
} else if (GetSMType(nSupMod) == DCAL_EXT) {
911-
nphi /= 3;
912-
}
927+
switch (GetSMType(nSupMod)) {
928+
case EMCAL_HALF:
929+
nphi /= 2;
930+
case EMCAL_THIRD:
931+
case DCAL_EXT:
932+
nphi /= 3;
933+
break;
934+
default:
935+
// All other supermodules have full number of cells in phi
936+
break;
937+
};
913938

914939
Double_t dmin = TMath::Abs(mPhiCentersOfCells[0] - phiLoc),
915940
d = 0.;
@@ -973,19 +998,23 @@ std::tuple<int, int, int, int> Geometry::CalculateCellIndex(Int_t absId) const
973998
for (nSupMod = -1; test >= 0;) {
974999
nSupMod++;
9751000
tmp = test;
976-
if (GetSMType(nSupMod) == EMCAL_STANDARD) {
977-
test -= mNCellsInSupMod;
978-
} else if (GetSMType(nSupMod) == EMCAL_HALF) {
979-
test -= mNCellsInSupMod / 2;
980-
} else if (GetSMType(nSupMod) == EMCAL_THIRD) {
981-
test -= mNCellsInSupMod / 3;
982-
} else if (GetSMType(nSupMod) == DCAL_STANDARD) {
983-
test -= 2 * mNCellsInSupMod / 3;
984-
} else if (GetSMType(nSupMod) == DCAL_EXT) {
985-
test -= mNCellsInSupMod / 3;
986-
} else {
987-
throw InvalidSupermoduleTypeException();
988-
}
1001+
switch (GetSMType(nSupMod)) {
1002+
case EMCAL_STANDARD:
1003+
test -= mNCellsInSupMod;
1004+
break;
1005+
case EMCAL_HALF:
1006+
test -= mNCellsInSupMod / 2;
1007+
break;
1008+
case DCAL_STANDARD:
1009+
test -= 2 * mNCellsInSupMod / 3;
1010+
break;
1011+
case EMCAL_THIRD:
1012+
case DCAL_EXT:
1013+
test -= mNCellsInSupMod / 3;
1014+
break;
1015+
default:
1016+
throw InvalidSupermoduleTypeException();
1017+
};
9891018
}
9901019

9911020
Int_t nModule = tmp / mNCellsInModule;
@@ -1007,16 +1036,18 @@ Int_t Geometry::GetSuperModuleNumber(Int_t absId) const { return std::get<0>(Get
10071036
std::tuple<int, int> Geometry::GetModulePhiEtaIndexInSModule(int supermoduleID, int moduleID) const
10081037
{
10091038
int nModulesInPhi = -1;
1010-
if (GetSMType(supermoduleID) == EMCAL_HALF) {
1011-
nModulesInPhi = mNPhi / 2; // halfSM
1012-
} else if (GetSMType(supermoduleID) == EMCAL_THIRD) {
1013-
nModulesInPhi = mNPhi / 3; // 1/3 SM
1014-
} else if (GetSMType(supermoduleID) == DCAL_EXT) {
1015-
nModulesInPhi = mNPhi / 3; // 1/3 SM
1016-
} else {
1017-
nModulesInPhi = mNPhi; // full SM
1018-
}
1019-
1039+
switch (GetSMType(supermoduleID)) {
1040+
case EMCAL_HALF:
1041+
nModulesInPhi = mNPhi / 2; // halfSM
1042+
break;
1043+
case EMCAL_THIRD:
1044+
case DCAL_EXT:
1045+
nModulesInPhi = mNPhi / 3; // 1/3 SM
1046+
break;
1047+
default:
1048+
nModulesInPhi = mNPhi; // full SM
1049+
break;
1050+
};
10201051
return std::make_tuple(int(moduleID % nModulesInPhi), int(moduleID / nModulesInPhi));
10211052
}
10221053

0 commit comments

Comments
 (0)