Skip to content

Commit aaf7e0d

Browse files
"Beautify" the examples slightly
1 parent 6a09935 commit aaf7e0d

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

examples/B4/exampleB4c.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def Initialize(self, hce):
269269

270270
# Create hits
271271
# fNofCells for cells + one more for total sums
272-
for i in range(0, self.fNofCells + 1):
272+
for i in range(self.fNofCells + 1):
273273
self.fHitsCollection.insert(B4cCalorHit())
274274

275275
def ProcessHits(self, step, history):
@@ -311,7 +311,7 @@ def EndOfEvent(self, hCofThisEvent):
311311
print("")
312312
print("-------->Hits Collection: in this event they are", nofHits, end="")
313313
print(" hits in the tracker chambers: ")
314-
for i in range(0, nofHits):
314+
for i in range(nofHits):
315315
self.fHitsCollection[i].Print()
316316

317317

examples/B5/exampleB5.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self):
2222
super().__init__()
2323
self.fXCell = [0] * kNofEmCells
2424
self.fYCell = [0] * kNofEmCells
25-
for copyNo in range(0, kNofEmCells):
25+
for copyNo in range(kNofEmCells):
2626
column = int(copyNo / kNofEmRows)
2727
row = copyNo % kNofEmRows
2828
self.fXCell[copyNo] = (column-9)*15*cm - 7.5*cm
@@ -189,7 +189,7 @@ def Construct(self):
189189
self.fHodoscope1Logical = G4LogicalVolume(
190190
hodoscope1Solid, scintillator, "hodoscope1Logical")
191191

192-
for i in range(0, kNofHodoscopes1):
192+
for i in range(kNofHodoscopes1):
193193
x1 = (i-int(kNofHodoscopes1/2))*10*cm
194194
G4PVPlacement(None, G4ThreeVector(x1, 0, -1.5*m), self.fHodoscope1Logical,
195195
"hodoscope1Physical", firstArmLogical,
@@ -198,7 +198,7 @@ def Construct(self):
198198
# drift chambers in first arm
199199
chamber1Solid = G4Box("chamber1Box", 1*m, 30*cm, 1*cm)
200200
chamber1Logical = G4LogicalVolume(chamber1Solid, argonGas, "chamber1Logical")
201-
for i in range(0, kNofChambers):
201+
for i in range(kNofChambers):
202202
z1 = (i-int(kNofChambers/2))*0.5*m
203203
G4PVPlacement(None, G4ThreeVector(0, 0, z1), chamber1Logical,
204204
"chamber1Physical", firstArmLogical, False, i, checkOverlaps)
@@ -214,7 +214,7 @@ def Construct(self):
214214
self.fHodoscope2Logical = G4LogicalVolume(
215215
hodoscope2Solid, scintillator, "hodoscope2Logical")
216216

217-
for i in range(0, kNofHodoscopes2):
217+
for i in range(kNofHodoscopes2):
218218
x2 = (i-int(kNofHodoscopes2/2))*10*cm
219219
G4PVPlacement(None, G4ThreeVector(x2, 0, 0), self.fHodoscope2Logical,
220220
"hodoscope2Physical", secondArmLogical, False, i, checkOverlaps)
@@ -223,7 +223,7 @@ def Construct(self):
223223
chamber2Solid = G4Box("chamber2Box", 1.5*m, 30*cm, 1*cm)
224224
chamber2Logical = G4LogicalVolume(chamber2Solid, argonGas, "chamber2Logical")
225225

226-
for i in range(0, kNofChambers):
226+
for i in range(kNofChambers):
227227
z2 = (i-int(kNofChambers/2))*0.5*m - 1.5*m
228228
G4PVPlacement(None, G4ThreeVector(0, 0, z2), chamber2Logical,
229229
"chamber2Physical", secondArmLogical, False, i, checkOverlaps)
@@ -552,7 +552,7 @@ def Initialize(self, hce):
552552
hce.AddHitsCollection(self.fHCID, self.fHitsCollection)
553553

554554
# fill calorimeter hits with zero energy deposition
555-
for i in range(0, kNofEmCells):
555+
for i in range(kNofEmCells):
556556
self.fHitsCollection.insert(B5EmCalorimeterHit(i))
557557

558558
def ProcessHits(self, step, touchableHist):
@@ -640,8 +640,8 @@ def Initialize(self, hce):
640640
hce.AddHitsCollection(self.fHCID, self.fHitsCollection)
641641

642642
# fill calorimeter hits with zero energy deposition
643-
for column in range(0, kNofHadColumns):
644-
for row in range(0, kNofHadRows):
643+
for column in range(kNofHadColumns):
644+
for row in range(kNofHadRows):
645645
self.fHitsCollection.insert(B5HadCalorimeterHit())
646646

647647
def ProcessHits(self, step, touchableHist):
@@ -748,8 +748,8 @@ def ProcessHits(self, step, touchableHist):
748748

749749
# check if this finger already has a hit
750750
ix = -1
751-
for i in range(0, self.fHitsCollection.GetSize()):
752-
if self.fHitsCollection[i].fId == copyNo:
751+
for i, hit in enumerate(self.fHitsCollection):
752+
if hit.fId == copyNo:
753753
ix = i
754754
break
755755

@@ -893,7 +893,7 @@ def BeginOfEventAction(self, event):
893893
# histograms names
894894
histoName = [["Chamber1", "Chamber2"], ["Chamber1 XY", "Chamber2 XY"]]
895895

896-
for iDet in range(0, 2):
896+
for iDet in range(2):
897897
# hit collections IDs
898898
self.fHodHCID[iDet] = sdManager.GetCollectionID(hHCName[iDet])
899899
self.fDriftHCID[iDet] = sdManager.GetCollectionID(dHCName[iDet])
@@ -923,7 +923,7 @@ def EndOfEventAction(self, event):
923923
analysisManager = G4AnalysisManager.Instance()
924924

925925
# Drift chambers hits
926-
for iDet in range(0, 2):
926+
for iDet in range(2):
927927
hc = self.GetHC(event, self.fDriftHCID[iDet])
928928

929929
if hc == None:
@@ -943,13 +943,13 @@ def EndOfEventAction(self, event):
943943
totalCalHit = [0, 0]
944944
totalCalEdep = [0, 0]
945945

946-
for iDet in range(0, 2):
946+
for iDet in range(2):
947947
hc = self.GetHC(event, self.fCalHCID[iDet])
948948
if hc == None:
949949
return
950950

951-
for i in range(0, hc.GetSize()):
952-
edep = hc[i].fEdep
951+
for i, hit in enumerate(hc):
952+
edep = hit.fEdep
953953

954954
if edep > 0:
955955
totalCalHit[iDet] += 1
@@ -961,7 +961,7 @@ def EndOfEventAction(self, event):
961961
analysisManager.FillNtupleDColumn(iDet + 2, totalCalEdep[iDet])
962962

963963
# Hodoscopes hits
964-
for iDet in range(0, 2):
964+
for iDet in range(2):
965965
hc = self.GetHC(event, self.fHodHCID[iDet])
966966
if hc == None:
967967
return
@@ -987,7 +987,7 @@ def EndOfEventAction(self, event):
987987
primary.GetMomentum())
988988

989989
# Hodoscopes
990-
for iDet in range(0, 2):
990+
for iDet in range(2):
991991
hc = self.GetHC(event, self.fHodHCID[iDet])
992992
if hc == None:
993993
return
@@ -997,20 +997,20 @@ def EndOfEventAction(self, event):
997997
hit.Print()
998998

999999
# Drift chambers
1000-
for iDet in range(0, 2):
1000+
for iDet in range(2):
10011001
hc = self.GetHC(event, self.fDriftHCID[iDet])
10021002
if hc == None:
10031003
return
10041004

10051005
print("Drift Chamber", iDet + 1, "has", hc.GetSize(), "hits.")
1006-
for layer in range(0, kNofChambers):
1006+
for layer in range(kNofChambers):
10071007
for hit in hc:
10081008
if hit.fLayerID == layer:
10091009
hit.Print()
10101010

10111011
# Calorimeters
10121012
calName = ["EM", "Hadron"]
1013-
for iDet in range(0, 2):
1013+
for iDet in range(2):
10141014
print(calName[iDet], "Calorimeter has", totalCalHit[iDet],
10151015
"hits.", "Total Edep is", totalCalEdep[iDet]/MeV, "(MeV)")
10161016

0 commit comments

Comments
 (0)