~mbogomilov/maus/devel3

« back to all changes in this revision

Viewing changes to src/legacy/FILES/Models/Modules/MakeEMR.py

  • Committer: Durga Rajaram
  • Date: 2013-11-19 02:09:06 UTC
  • mfrom: (659.1.77 rc)
  • Revision ID: durga@fnal.gov-20131119020906-t2vxx4h2yr0f09tj
Tags: MAUS-v0.7.4
MAUS-v0.7.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import sys
2
 
import math
 
1
"""MakeEMR creates EMR geometry MICEModules."""
 
2
 
 
3
#pylint:disable=C0102, C0103, R0902, R0913, W0231
3
4
 
4
5
NumberOfLayers = 48
5
6
BarsPerLayer = 59
7
8
WithBars = 1
8
9
 
9
10
class G4MiceGeoBase:
10
 
    def __init__( self, Name ):#pylint:disable=C0103
 
11
    """
 
12
    @class G3MiceGeoBase This class controls the global positions and dimensions of the EMR
 
13
    """
 
14
    def __init__( self, Name ):
11
15
        self.Name = Name
12
16
        self.Height = 0.0
13
17
        self.Length = 0.0
20
24
        self.Psi = 0.0
21
25
 
22
26
    def SetDimensions( self, Length, Width, Height ):
 
27
        """
 
28
        @method SetDimensions This method sets the dimensions of the EMR detector
 
29
        """
23
30
        self.Length = Length
24
31
        self.Width = Width
25
32
        self.Height = Height
26
33
 
27
34
    def SetPosition( self, X, Y, Z ):
 
35
        """
 
36
        @method SetRotation This method sets the global position of the Detector with Tait-Bryan angles
 
37
        """
28
38
        self.X = X
29
39
        self.Y = Y
30
40
        self.Z = Z
31
41
 
32
42
    def SetRotation( self, Phi, Theta, Psi ):
 
43
        """
 
44
        @method SetRotation This method sets the global rotation of the Detector with Tait-Bryan angles
 
45
        """
33
46
        self.Phi = Phi
34
47
        self.Theta = Theta
35
48
        self.Psi = Psi
38
51
        message = """Name: %s
39
52
          Dimensions: %d %d %d
40
53
          Position: %d %d %d
41
 
          Rotation:
42
 
        """% ( self.Name, self.Width, self.Height, self.Length, self.X, self.Y, self.Z )
 
54
          Rotation: """% ( self.Name, self.Width, self.Height, self.Length,
 
55
                           self.X, self.Y, self.Z )
43
56
        return message
44
57
 
45
58
class EMRBar( G4MiceGeoBase ):
 
59
    """
 
60
    @class EMRBar This class defines an EMR Bar within the detector geometry and writes
 
61
    a MICEModule file. 
 
62
    """
46
63
    def __init__( self, LayerId, BarId, BarLength, BarHeight, BarWidth ):
47
64
        self.Name = "EMRLayer%dBar%d" % ( LayerId, BarId )
48
65
        self.BarId = BarId
59
76
 
60
77
 
61
78
    def Export( self ):
 
79
        """
 
80
        @method Export This method writes a MICE module describing an EMR bar
 
81
        """
62
82
 
63
83
    #  if( self.BarId % 2 ):
64
84
    #    Y1HalfLength = 0
99
119
                self.BarId,
100
120
                self.Name )
101
121
 
102
 
        #% ( ExportFolder, self.Name, self.Name, XHalfLength, XHalfLength, Y1HalfLength,
103
 
        #Y2HalfLength, ZHalfLength, self.LayerId, self.BarId, self.Name )
 
122
        #% ( ExportFolder, self.Name, self.Name, XHalfLength, XHalfLength,
 
123
        #    Y1HalfLength, Y2HalfLength, ZHalfLength, self.LayerId,
 
124
        #    self.BarId, self.Name )
104
125
 
105
126
        BarFile = open( ExportFolder + self.Name + ".dat", 'w' )
106
127
        BarFile.write( Content )
137
158
        SciFile.close()
138
159
 
139
160
class EMRLayer( G4MiceGeoBase ):
 
161
    """
 
162
    @class EMRLayer This class defines a layer of bars within the EMR
 
163
    """
140
164
    def __init__(self, LayerId, BarCount, BarLength, BarHeight, BarWidth ):
141
165
        self.Bars = []
142
166
        self.LayerId = LayerId
157
181
        HalfLayerLength = ( ( self.BarWidth / 2 ) * (self.BarCount - 1) ) / 2
158
182
        if WithBars == 1 :
159
183
            for i in range( self.BarCount ):
160
 
                b = EMRBar( self.LayerId, i, self.BarLength, self.BarHeight, self.BarWidth )
 
184
                b = EMRBar( self.LayerId, i, self.BarLength,
 
185
                            self.BarHeight, self.BarWidth )
161
186
                #if not( self.LayerId % 2 ):
162
187
                #  XPos = 0.0
163
188
                #  YPos = ( -HalfLayerLength + ( i * ( b.Width / 2 ) ) )
165
190
                #  XPos = ( -HalfLayerLength + ( i * ( b.Width / 2 ) ) )
166
191
                #  YPos = 0.0
167
192
                #b.SetPosition( XPos, YPos, 0.0 )
168
 
                b.SetPosition( 0.0, ( -HalfLayerLength + ( i * ( b.Width / 2 ) ) ), 0.0 )
 
193
                b.SetPosition(0.0, 
 
194
                             (-HalfLayerLength + (i * (b.Width / 2))), 0.0)
169
195
                if i % 2 == 0:
170
196
                    b.SetRotation( 0.0, 0.0, 0.0 )
171
197
                else:
173
199
                self.Bars.insert( i, b )
174
200
 
175
201
    def IsVertical( self ):
 
202
        """
 
203
        @method IsVertical Returns a 1 for a vertical layer based on the LayerID number
 
204
        """
176
205
        return self.LayerId % 2
177
206
 
178
207
    def Export( self ):
 
208
        """
 
209
        @method Export This method writes a MICEModule file describing the EMR layer
 
210
        """
179
211
        #Calculating trapezoid halflengths
180
212
        #ZHL = ( self.BarHeight / 2 )
181
213
        #if not self.IsVertical():
182
214
        #  X1HL = self.BarLength / 2
183
215
        #  X2HL = self.BarLength / 2
184
216
        #  Y1HL = ( self.BarWidth * ( self.BarCount / 2 ) ) / 2
185
 
        #  Y2HL = ( self.BarWidth * ( ( self.BarCount / 2 ) + ( self.BarCount % 2 ) ) ) / 2
 
217
        #  Y2HL = ( self.BarWidth * ( ( self.BarCount / 2 ) + 
 
218
        #                           ( self.BarCount % 2 ) ) ) / 2
186
219
        #else:
187
220
        #  X1HL = ( self.BarWidth * ( self.BarCount / 2 ) ) / 2;
188
 
        #  X2HL = ( self.BarWidth * ( ( self.BarCount / 2 ) + ( self.BarCount % 2 ) ) ) / 2
 
221
        #  X2HL = ( self.BarWidth * ( ( self.BarCount / 2 ) +
 
222
        #         ( self.BarCount % 2 ) ) ) / 2
189
223
        #  Y1HL = self.BarLength / 2
190
224
        #  Y2HL = self.BarLength / 2
191
225
 
208
242
                 self.Name,
209
243
                 self.Length / 2,
210
244
                 self.Length / 2,
211
 
                 ( self.BarWidth * ( self.BarCount / 2 ) ) / 2,
212
 
                 ( self.BarWidth * ( ( self.BarCount / 2 ) + ( self.BarCount % 2 ) ) ) / 2,
 
245
                 ( self.BarWidth * (self.BarCount / 2)) / 2,
 
246
                 ( self.BarWidth * ((self.BarCount / 2) + 
 
247
                                   (self.BarCount % 2))) / 2,
213
248
                 self.Height / 2,
214
249
                 self.LayerId,
215
250
                 self.BarCount,
216
251
                 self.BarCount )
217
 
            #% ( ExportFolder, self.Name, self.Name, X1HL, X2HL, Y1HL, Y2HL, ZHL,
 
252
            #% ( ExportFolder, self.Name, self.Name, X1HL, X2HL,
 
253
            #    Y1HL, Y2HL, ZHL,
218
254
            #self.LayerId, self.BarCount, self.BarCount )
219
255
        if WithBars == 1:
220
256
            for bar in self.Bars:
223
259
                  Position %.2f %.2f %.2f cm
224
260
                  Rotation %.2f %.2f %.2f degree
225
261
                }
226
 
                """ % ( ExportFolder, bar.Name, bar.X, bar.Y, bar.Z, bar.Phi, bar.Theta, bar.Psi )
 
262
                """ % ( ExportFolder, bar.Name, bar.X, bar.Y, bar.Z,
 
263
                        bar.Phi, bar.Theta, bar.Psi )
227
264
                bar.Export()
228
265
        Content += "}"
229
266
        LayerFile = open( ExportFolder + self.Name + ".dat", 'w' )
231
268
        LayerFile.close()
232
269
 
233
270
class EMRGeometry( G4MiceGeoBase ):
 
271
    """
 
272
    @class EMRGeometry This class defines the global geometry of the EMR
 
273
    """
234
274
    def __init__(self, NumLayers, NumBars, BarLength, BarHeight, BarWidth ):
235
275
        self.Layers = []
236
276
        self.Name = "Calorimeter"
256
296
 
257
297
        HalfEMRLength = ( self.BarHeight * (self.LayersCount - 1 ) ) / 2
258
298
        for i in range( self.LayersCount ):
259
 
            l = EMRLayer( i, self.BarsCount, self.BarLength, self.BarHeight, self.BarWidth )
 
299
            l = EMRLayer( i, self.BarsCount, self.BarLength,
 
300
                          self.BarHeight, self.BarWidth )
260
301
            l.SetPosition( 0.0, 0.0, - HalfEMRLength + ( i * self.BarHeight ) )
261
302
            if i % 2 == 0:
262
303
                l.SetRotation( 0.0, 0.0, 0.0 )
265
306
            self.Layers.insert( i, l )
266
307
 
267
308
    def Export( self ):
 
309
        """
 
310
        @method Export This method writes a MICEModule file describing the EMR geometry
 
311
        """
268
312
        Content = """// FILES/Models/Modules/%s%s.dat
269
313
        //
270
314
        //
319
363
#print Layer
320
364
#Layer.Export()
321
365
 
322
 
EMR = EMRGeometry( NumberOfLayers, BarsPerLayer, 110.0, 1.7, 3.3 );
 
366
EMR = EMRGeometry( NumberOfLayers, BarsPerLayer, 110.0, 1.7, 3.3 )
323
367
print EMR
324
368
EMR.Export()