EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicToyModel.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicToyModel.h
1 
2 #include <set>
3 #include <map>
4 
5 #include <TCanvas.h>
6 
7 #ifndef _EIC_TOY_MODEL_
8 #define _EIC_TOY_MODEL_
9 
10 #include <EtmPalette.h>
11 #include <EtmAzimuthalScan.h>
12 #include <EtmVacuumChamber.h>
13 #include <EtmDetectorStack.h>
14 
15 // +/-4.5 m; up to ~4m radius suffices?; can be changed in the ctor (only);
16 #define _IR_REGION_LENGTH_DEFAULT_ (900.0)
17 #define _IR_REGION_RADIUS_DEFAULT_ (400.0)
18 
19 class EicToyModel: public TObject {
20  // Here and in other "main" classes: more concerned to prevent user access to the non-const
21  // methods, which they are not supposed to use rather than anything else; so consider
22  // to define friend classes rather than keeping these methods public;
23  friend class EtmDetector;
24  friend class EtmDetectorStack;
25  friend class EtmAzimuthalScan;
26  friend class EtmVacuumChamber;
27 
28  public:
30 
31  // == User commands === just the shortcuts for the "interactive" ones ==========================
32  //
33  // -- Geometry ---------------------------------------------------------------------------------
34  // Vacuum chamber derived class and eta *boundaries* can still be modified later (either
35  // interactively or after model export-import), but not the *number* of different
36  // stacks; too much of a trouble to re-create the stack structure dynamically (in other
37  // words to guarantee that the meaning of bck(), mid() & fwd() stays the same), so eta()
38  // calls beyond LockGeometry() will not work;
39  EicToyModel *acceptance(double eta0, double eta1, double eta2, double eta3,
40  bool reset_stacks = false, bool redraw = true);
42  //EicToyModel *DefineVacuumChamber(const char *fname);
43  //
44  // Nominal IP along the beam line direction; negative values correspond to the e-endcap direction;
45  EicToyModel *ip(double offset, bool redraw = true);
46  EicToyModel *ir(double length, double radius, bool redraw = true);
47  //
48  // Access to backward endcap, mid rapidity and forward endcap stacks;
49  EtmDetectorStack *vtx( void ); EtmDetectorStack *vertex ( void ) { return vtx(); };
50  EtmDetectorStack *bck( void ); EtmDetectorStack *backward( void ) { return bck(); };
51  EtmDetectorStack *mid( void ); EtmDetectorStack *barrel ( void ) { return mid(); };
52  EtmDetectorStack *fwd( void ); EtmDetectorStack *forward ( void ) { return fwd(); };
53  //
54  // Calls describing the outline of the vacuum chamber;
55  EicToyModel *SetCrossingAngle(double value, bool redraw = true);
56  //
57  // -- Visualization ----------------------------------------------------------------------------
58  //
59  // May want to set a different canvas width;
60  EicToyModel *width(unsigned width);
61  //
62  // Enable/disable mirror image; NB: top and bottom halves will look differently in the H-section;
63  EicToyModel *mirror(bool what = true, bool redraw = true);
64  // Either full view or only the left (right) halves;
65  EicToyModel *full (bool redraw = true) { mOneSideMode = EicToyModel::kOff; home(redraw); return this; };
66  EicToyModel *left (bool redraw = true) { mOneSideMode = EicToyModel::kLeft; home(redraw); return this; };
67  EicToyModel *right(bool redraw = true) { mOneSideMode = EicToyModel::kRight; home(redraw); return this; };
68  //
69  // Enable/disable the legend;
70  EicToyModel *legend(bool what = true, bool redraw = true);
71  //
72  // Draw the view (either vertical or horizontal section);
73  void vdraw( void ) { DrawMe(EicToyModel::kVertical); };
74  void hdraw( void ) { DrawMe(EicToyModel::kHorizontal); };
75  void draw( void ) { DrawMe(EicToyModel::kCurrent); };
76  //
77  // Camera home;
78  void home(bool redraw = true);
79  // Zoom view;
80  void zoom(double blX, double blY, double trX, double trY, bool redraw = true);
81  //
82  // Add an extra eta line for drawing; perhaps either with no actual line or no label;
83  EicToyModel *AddEtaLine(double value, bool line = true, bool label = true, bool redraw = true);
84  // Remove an eta line; NB: this only removes *currently*defined* eta lines; the next
85  // acceptance() call will call 4x AddEtaLine() internally;
86  EicToyModel *RemoveEtaLine(double eta) { mEtaLines.erase(eta); return this; };
87  // May want to draw IP6 hall boundaries;
88  void DrawIP6boundaries( void ) { mDrawIP6boundaries = true; };
89  //
90  // -- Other ------------------------------------------------------------------------------------
91  //
92  // Save the current state and TGeo model in a .root file;
93  void write(bool everything = false, bool lock = false);
94  //void Write( void ) { write(); };
95  //
96  // This call also defines the output files basenames;
97  EicToyModel *SetName( const char *name) { mName = name; return this; };
98  //
99  // Safety clearance will affect the minimal gaps introduced between the integration volumes;
100  //EicToyModel *SafetyClearance(double value) { mSafetyClearance = fabs(value); return this; };
101  // Visual clearance will only affect the display picture;
102  //EicToyModel *VisualClearance(double value) { mVisualClearance = fabs(value); return this; };
103  //
104  // If the marker() objects (kind of indicating the locations of the last silicon stations,
105  // which can be achieved in this detector composition) are defined in the forward and backward
106  // endcaps, regions where the field is supposed to better be aligned with the solenoid axis will
107  // be shown;
109 
110  void ApplyStandardTrimming( void );
111 
112  // FIXME: this is not clean; determine dynamically;
114  // =============================================================================================
115 
116  static EicToyModel *Instance( void ) { return mInstance; };
117 
118  // Conversion to canvas coordinates; cnv() is for less typing, sorry;
119  TVector2 cnv(const TVector2 &world) const;
120 
121  // In world coordinates;
122  TVector2 GetIpLocation( void ) const { return TVector2(mIpOffset, 0.0); };
123 
124  double GetCrossingAngle( void ) const { return mCrossingAngle; };
125  double GetIrRegionLength( void ) const { return mIrRegionLength; };
126  double GetIrRegionRadius( void ) const { return mIrRegionRadius; };
127 
128  static std::pair<std::vector<TVector2>, std::vector<TVector2> >
129  GetIntersection(const std::vector<TVector2> &chain, const EtmLine2D &line);
130 
131  void Construct( void ) { DrawMe(EicToyModel::kUndefined, false); };
132  // Well, 'world' here means some 'parent' volume, actually;
133  void PlaceG4Volumes(G4LogicalVolume *world);
134  void PlaceG4Volumes(G4VPhysicalVolume *world);
135  void Export(const char *fname, bool everything = false, bool lock = false);
136  void ExportVacuumChamber(const char *fname = 0);
137  G4VPhysicalVolume *ConstructG4World( void );
138  void DefineG4World(G4LogicalVolume *world) { mG4LogicalWorld = world; };
139  G4LogicalVolume *GetG4World( void ) const { return mG4LogicalWorld; };
140 
141  static EicToyModel *Import(const char *fname);
142  // There is no good reason to Get() the TGeoManager instance sitting in the same
143  // .root file -> re-create it from scratch;
145 
146  void SetAzimuthalSegmentation(unsigned value) {
148  };
149  unsigned GetAzimuthalSegmentation( void ) const { return mAzimuthalSegmentation; };
150 
151  //const TString &GetName( void ) const { return mName; };
152  //const char *GetName( void ) const { return mName.Data(); };
153 
154  private:
156 
159 
160  EicToyModel::View GetCurrentView( void ) const { return mCurrentView; };
161 
162  void DrawPolygon(unsigned dim, const double xx[], const double yy[],
163  int color, bool line = true) const;
164 
165  EtmPalette &Palette( void ) { return mPalette; };
166 
168 
169  void ExportCADmodel(const char *fname);
170  void ExportCADmodelCore(std::vector<std::pair<const TColor*, const TopoDS_Shape*> > shapes,
171  const char *fname);
172 
173  //double SafetyClearance( void ) const { return mSafetyClearance; };
174  //double VisualClearance( void ) const { return mVisualClearance; };
175 
176  const char *GetName( void ) const { return mName.Data(); };
177 
179  std::vector<TVector2> RebuildCrack(const std::vector<TVector2> &chain,
180  const EtmLine2D &am, const EtmLine2D &ap,
181  const EtmLine2D &cut, etm::Stretch how);
182  void AppendChain(std::vector<TVector2> &chain, const std::vector<TVector2> &add);
183 
184  std::vector<TVector2> Band(const std::vector<TVector2> &chain,
185  const EtmLine2D &from, const EtmLine2D &to);
186 
187  TVector2 CalculateEtaStartPoint(double eta, unsigned vh, unsigned tb,
188  bool account_crossing_angle);
189  std::pair<TVector2, bool> CalculateEtaEndPoint(double eta, unsigned vh, unsigned tb,
190  bool account_crossing_angle);
191 
192  // Access to a stack by eta;
193  EtmDetectorStack *GetStack(double eta);
194 
195  void WriteText(const TVector2 &where, const TString &what, int color = kBlack) const;
196 
197  void DrawSingleLine(const TVector2 &from, const TVector2 &to, int color = kBlack,
198  int width = 1, etm::LineStyle style = etm::solid) const;
199 
200  EicToyModel *Enable(const char *tag) { mEnabledColorTags.insert(tag); return this; };
201 
202  EicToyModel *RebuildEverything(bool redraw);
203 
204  // It looks impractical to have EtmDetector::DrawMe() like classes, since
205  // this introduces backdoor dependencies; so just do all the loops in this single call;
206  void DrawMe(EicToyModel::View view = EicToyModel::kCurrent, bool draw = true);
207 
208  // Two ends and a couple of attributes;
209  void DrawSingleEtaLine(double eta, const TVector2 &to, std::pair<bool, bool> what, bool side) const;
210 
211  TVector2 GetCanvasCoordinates(const TVector2 &world) const { return cnv(world); };
212 
213  // FIXME: remove xx[],yy[] -> TVector2 re-shuffling later;
214  void DrawRectangle(const TVector2 &bl, const TVector2 &tr, int color, bool line = true) const;
215 
216  void DrawEtaLines( void );
217  void DrawEtaBoundaries( void );
218  void DrawBeamLine( void );
219  void DrawAxisTicks( void );
220  void DrawColorLegend(unsigned rows = 1);
221  void DrawMarkers( void );
222 
223  void DrawFlatFieldLines( void );
224 
226  double toffset, etm::Stretch how);
228  void PurgeBoundaryVertexArrays( void );
229  void AccountServiceMaterials( void );
230 
232 
233  // Want this to be a vector, just in case far forward part is added later;
234  std::vector<EtmDetectorStack*> mStacks;
235 
236  TString mName;
237 
239 
241 
242  // Nominal IP offset; in order to avoid any further complications, certain assumptions are made
243  // about the coordinate system and axis orietation:
244  //
245  // - Z-axis of the coordinate system is aligned with the outgoing electron beam (Z- direction);
246  // - crossing angle is only considered in the horizontal plane (even if later on a small Y-slope
247  // due to the solenoid compensation scheme will become needed);
248  // - pseudo-rapidities are counted with respect to the outgoing electron direction
249  // for negative values, and with respect to the outgoing hadron direction for positive values;
250  // this means that the h-endcap ranges will be rotated by 25mrad in the horizontal projection;
251  // - endcap detector integration volumes will be orthogonal to Z- direction for both arms (nobody
252  // knows yet, how they will be installed in reality, and h-endcap polygons will look ugly
253  // if aligned at 25mrad);
254  // - IP offset is only considered along Z-axis; X=Y=0 per definition; if this ever becomes a problem,
255  // it is easier to offset the vacuum chamber;
256  // - Z=0 is the center of the "nominal" +/-4.5m region;
257  // - exported integration volumes will be axially symmetric with respect to the Z-axis TGeoPolycon
258  // objects, perhaps at a non-zero X-offset, with a hole matching the layout of the vacuum chamber;
259  // the shape will be taken as a "boolean &" of the phi=0,90,180,270 degree projections with respect
260  // to the guessed "center" (X-offset);
261  double mIpOffset;
262 
263  // XY-size of the canvas;
264  unsigned mXdim, mYdim;
265  // XY-scale and offsets used in GetCanvasCoordinates();
266  double mXsize, mYsize, mX0, mY0;
267 
269 
270  // A set of boundary and user-defined eta lines to be drawn; <eta, <line,label>>;
271  std::map<double, std::pair<bool, bool> > mEtaLines;
272 
273  TCanvas *mCanvas;
274 
276 
278 
281 
283 
284  std::set<TString> mEnabledColorTags;
285 
286  // The first one will be used to generate mBoundaries[] array and the
287  // integration volumes; the second one is a guaranteed gap between
288  // objects in the TCanvas representation;
289  //double mSafetyClearance, mVisualClearance;
290 
292 
293  std::set<double> mFlatFieldLinesEta;
294 
295  std::vector<EtmBoundaryModificationRequest*> mBoundaryModificationRequests;
296 
297  // A naive way to lock the geometry, so that the .root file can be imported, and
298  // even the commands changing the internal structure will seemingly work, but 1) none
299  // of the methods, which actually modify the "final" geometry dynamically will have
300  // any effect, 2) for the sake of completeness, write() call will be disabled; this
301  // call is intentionally "irreversible"; does not prevent a smart user from writing
302  // UnlockGeometry() method of course, but un-intentional changes can not happen;
304 
306 
307  G4LogicalVolume *mG4LogicalWorld;
308 
309  public:
311 
312  ClassDef(EicToyModel, 1)
313 };
314 
315 #endif