32 const G4bool circularMachine)
38 if (beamline->
empty())
46 G4int currentIndex = 0;
47 for (
auto element : *beamline)
50 const auto accComponentTO = element->GetTiltOffset();
52 const auto endPieceAfter = accComponent->EndPieceAfter();
54 G4bool placeBefore =
true;
55 G4bool placeAfter =
true;
56 if (!endPieceBefore && !endPieceAfter)
61 else if (!endPieceBefore)
62 {placeBefore =
false;}
63 else if (!endPieceAfter)
66 G4double requiredBeforeLength = 0;
67 G4double requiredAfterLength = 0;
69 {requiredBeforeLength = endPieceBefore->
GetChordLength() + 2*lengthSafetyLarge;}
71 {requiredAfterLength = endPieceAfter->GetChordLength() + 2*lengthSafetyLarge;}
79 G4bool keepGoing =
true;
81 G4double availableLength = 0;
82 G4double previousNonDriftEndPieceL = 0;
83 G4bool driftIsFirstItem =
false;
84 BDSExtent endPieceInnerExtent = endPieceBefore->GetInnerExtent();
85 G4bool driftsAreTooBigBefore =
false;
88 inspectedElement = beamline->
GetPrevious(inspectedElement);
91 G4String inspectedElementType = inspectedElement->
GetType();
92 if (inspectedElementType ==
"drift" || inspectedElementType ==
"dipolefringe" || inspectedElementType ==
"element")
96 G4double tiltPipe = inspectedElement->
GetTilt();
98 {extPipe = extPipe.
Tilted(accComponentTO->GetTilt() - tiltPipe);}
102 if (inspectedElementType !=
"element")
103 {driftsAreTooBigBefore =
true;}
108 driftIsFirstItem = inspectedElement == firstItem;
115 if (previousNonDriftAccCompEndPiece)
116 {previousNonDriftEndPieceL = previousNonDriftAccCompEndPiece->
GetChordLength();}
124 if (requiredBeforeLength > (availableLength - previousNonDriftEndPieceL))
125 {placeBefore =
false;}
128 if (driftsAreTooBigBefore)
129 {placeBefore =
false;}
133 if ( (element == firstItem) || (driftIsFirstItem && !driftsAreTooBigBefore) )
134 {placeBefore =
true;}
139 if ( (element == firstItem) && circularMachine )
140 {placeBefore =
false;}
145 if (placeBefore && !endPieces->
empty() )
151 BDSExtent extOF = endPieceBefore->GetExtent();
153 G4ThreeVector oFNormal = endPieceBefore->InputFaceNormal();
156 G4double zSeparation = availableLength - requiredBeforeLength - lastEndPieceL;
157 G4bool willIntersect =
BDS::WillIntersect(iFNormal, oFNormal, zSeparation, extIF, extOF);
159 {placeBefore =
false;}
176 auto beforeEl = beamline->ProvideEndPieceElementBefore(endPieceBefore,
188 G4bool keepGoing =
true;
190 G4double availableLength = 0;
191 G4double nextNonDriftEndPieceL = 0;
192 G4bool driftIsLastItem =
false;
193 BDSExtent endPieceInnerExtent = endPieceAfter->GetInnerExtent();
194 G4bool driftsAreTooBigAfter =
false;
197 inspectedElement = beamline->GetNext(inspectedElement);
198 if (inspectedElement)
200 G4String inspectedElementType = inspectedElement->
GetType();
201 if (inspectedElementType ==
"drift" || inspectedElementType ==
"dipolefringe" || inspectedElementType ==
"element")
205 G4double tiltPipe = inspectedElement->
GetTilt();
207 {extPipe = extPipe.
Tilted(accComponentTO->GetTilt() - tiltPipe);}
211 if (inspectedElementType !=
"element")
212 {driftsAreTooBigAfter =
true;}
217 driftIsLastItem = inspectedElement == lastItem;
224 if (nextNonDriftAccCompEndPiece)
225 {nextNonDriftEndPieceL = nextNonDriftAccCompEndPiece->
GetChordLength();}
233 if (requiredAfterLength > (availableLength - nextNonDriftEndPieceL))
234 {placeAfter =
false;}
237 if (driftsAreTooBigAfter)
238 {placeAfter =
false;}
242 if ( (element == lastItem) || (driftIsLastItem && !driftsAreTooBigAfter) )
247 G4bool flip = endPieceAfter == endPieceBefore;