EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EtmDetectorStack.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EtmDetectorStack.cc
1 
2 #include <math.h>
3 
4 #include <EtmDetectorStack.h>
5 #include <EicToyModel.h>
6 
7 // ---------------------------------------------------------------------------------------
8 // ---------------------------------------------------------------------------------------
9 
10 EtmDetectorStack::EtmDetectorStack(const char *label, double etamin, double etamax):
11  mStartingDistance(0.0), mFullLength(0.0)
12 {
13  if (label) mLabel = label;
14 
15  for(unsigned bf=0; bf<2; bf++)
16  mEtaBoundaries[bf] = new EtmEtaBoundary();
17 
18  SetEtaBoundaries(etamin, etamax);
19 
20  mDummyDetector = new EtmDetector(this, 0, 0, kBlack, 0.0);
21 } // EtmDetectorStack::EtmDetectorStack()
22 
23 // ---------------------------------------------------------------------------------------
24 
26 {
27  mEtaBoundaries[0]->SetEta(min); mEtaBoundaries[1]->SetEta(max);
28 
29  if (min && max) CalculateAlignmentAxis();
30 } // EtmDetectorStack::SetEtaBoundaries()
31 
32 // ---------------------------------------------------------------------------------------
33 // ---------------------------------------------------------------------------------------
34 
35 void EtmDetectorStack::offset(double dstart)
36 {
37  if (dstart >= 0.0) mStartingDistance = dstart;
38 } // EtmDetectorStack::offset()
39 
40 // ---------------------------------------------------------------------------------------
41 
43 {
44  auto eic = EicToyModel::Instance();
45  int color = eic->Palette().GetColor(tag);
46  if (color == -1) {
47  printf("Tag '%s' does not exist!\n", tag);
48  return 0;
49  } //if
50 
51  // FIXME: this is indeed a hack;
52  if (eic->mUseDetectorHighlighting) {
53  auto det = new EtmDetector(this, tag, color, kBlack, length);
54  det->SetLineWidth(7);
55 
56  return det;
57  } else {
58  auto det = new EtmDetector(this, tag, color, kWhite, length);
59  det->SetLineWidth(3);
60 
61  return det;
62  } //if
63 } // EtmDetectorStack::CreateDetector()
64 
65 // ---------------------------------------------------------------------------------------
66 
68 {
69  auto det = CreateDetector(tag, length);
70 
71  if (!det) return 0;
72 
73  mDetectors.push_back(det);
74 
76 
77  return det;
78 } // EtmDetectorStack::add()
79 
80 // ---------------------------------------------------------------------------------------
81 
82 EtmDetector *EtmDetectorStack::add(const char *tag, int color, double length)
83 {
84  // Not the most efficient call, but no cut'n'paste;
85  return (EicToyModel::Instance()->Palette().AddEntry(tag, color) ? add(tag, length) : 0);
86 } // EtmDetectorStack::add()
87 
88 // ---------------------------------------------------------------------------------------
89 
91 {
92  auto marker = get(_MARKER_);
93 
94  if (marker != mDummyDetector) {
95  printf("'%s' detector must be unique (one per stack)!\n", _MARKER_);
96  return marker;
97  } //if
98 
99  return add(_MARKER_, 0.0);
100 } // EtmDetectorStack::marker()
101 
102 // ---------------------------------------------------------------------------------------
103 
105  const char *before, unsigned order)
106 {
107  auto det = CreateDetector(tag, length);
108  if (!det) return 0;
109 
110  auto eic = EicToyModel::Instance();
111  unsigned counter = 0;
112 
113  for (auto it = mDetectors.begin(); it != mDetectors.end(); it++)
114  if (*(*it)->GetLabel() == before && order == counter++) {
115  mDetectors.insert(it, det);
116 
117  eic->home();
118 
119  return det;
120  } //for it .. if
121 
122  // FIXME: memory leak;
123  return 0;
124 } // EtmDetectorStack::insert()
125 
126 // ---------------------------------------------------------------------------------------
127 
129 {
130  // FIXME: this is not clean, but should suffice;
131  double alignment_theta = mEtaBoundaries[0]->GetEta()*mEtaBoundaries[1]->GetEta() >= 0.0 ?
132  (mEtaBoundaries[0]->GetEta() > 0.0 ? 0.0 : M_PI) : M_PI/2;
133 
134  mAlignmentAxis = TVector2(cos(alignment_theta), sin(alignment_theta));
135 } // EtmDetectorStack::CalculateAlignmentAxis()
136 
137 // ---------------------------------------------------------------------------------------
138 // ---------------------------------------------------------------------------------------
139 
140 //
141 // FIXME: unify all these later;
142 //
143 
144 void EtmDetectorStack::rm(const char *dname)
145 {
146  if (!dname) return;
147 
148  auto eic = EicToyModel::Instance();
149  unsigned counter = 0;
150 
151  for(auto det: mDetectors)
152  if (*det->GetLabel() == dname)
153  counter++;
154 
155  if (counter == 1)
156  for (auto it = mDetectors.begin(); it != mDetectors.end(); )
157  (*(*it)->GetLabel() == dname) ? it = mDetectors.erase(it) : it++;
158 
159  eic->home();
160 } // EtmDetectorStack::rm()
161 
162 // ---------------------------------------------------------------------------------------
163 
164 void EtmDetectorStack::rm(const char *dname, unsigned order)
165 {
166  if (!dname) return;
167 
168  auto eic = EicToyModel::Instance();
169  unsigned counter = 0;
170 
171  for (auto it = mDetectors.begin(); it != mDetectors.end(); )
172  (*(*it)->GetLabel() == dname && order == counter++) ? it = mDetectors.erase(it) : it++;
173 
174  eic->home();
175 } // EtmDetectorStack::rm()
176 
177 // ---------------------------------------------------------------------------------------
178 
179 EtmDetector *EtmDetectorStack::get(const char *dname, unsigned order) const
180 {
181  if (!dname) return mDummyDetector;//0;
182 
183  unsigned counter = 0;
184 
185  for(auto det: mDetectors)
186  if (*det->GetLabel() == dname)
187  if (order == counter++)
188  return det;
189 
190  // FIXME: printf a message and return dummy pointer rather than crash;
191  //return 0;
192  return mDummyDetector;
193 } // EtmDetectorStack::get()
194 
195 // ---------------------------------------------------------------------------------------
196 // ---------------------------------------------------------------------------------------
197 
199 {
200  auto eic = EicToyModel::Instance();
202 
203  // Kind of regularization;
204  if (this == eic->mid() && mStartingDistance < eic->vtx()->FullLength())
205  mFullLength = eic->vtx()->FullLength();
206 
207  for(auto det: mDetectors) {
208  det->mActualDistance = mFullLength + det->length()/2;
209  mFullLength += det->length();
210  } //for det
211 } // EtmDetectorStack::CalculateActualDistances()
212 
213 // ---------------------------------------------------------------------------------------
214 
216 {
217  for(auto det: mDetectors)
218  det->Build();
219 } // EtmDetectorStack::Build()
220 
221 // ---------------------------------------------------------------------------------------
222 // ---------------------------------------------------------------------------------------
223