Hall-D Software  alpha
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DBCALGeometry.cc
Go to the documentation of this file.
1 // File: DBCALGeometry.h
2 // Created: Fri Nov 26 15:10:51 CST 2010
3 // Creator: dwbennet
4 
5 /// MMD: Looking at the code for the DBCALGeometry::phi( int fADC_cell ) method,
6 /// I have to conclude that sectors are numbered 1 through 4.
7 /// Judging by what else I've seen, I have to conclude that layers are numbered 1 through 4 or 1 through 10.
8 /// This is now the standard that I will use.
9 
10 
11 #include <cmath>
12 #include <TMath.h>
13 #include "DBCALGeometry.h"
14 
15 #include <HDGEOMETRY/DGeometry.h>
16 
17 
19 {
20  /// End if groupings do not evenly divide SiPM cells
21  bool goodGeometry=true;
22 
23  //if (NSUMSECSIN <= 0) goodGeometry=false;
24  //if (4 % NSUMSECSIN != 0) goodGeometry=false;
25  //if (NSUMSECSOUT <= 0) goodGeometry=false;
26  //if (4 % NSUMSECSOUT != 0) goodGeometry=false;
27 
28  int totalLayersIn=0;
29  for (int i=0;i<NBCALLAYSIN;i++) {
30  if (NSUMLAYSIN[i] <= 0) goodGeometry=false;
31  totalLayersIn += NSUMLAYSIN[i];
32  }
33 
34  int totalLayersOut=0;
35  for (int i=0;i<NBCALLAYSOUT;i++) {
36  if (NSUMLAYSOUT[i] <= 0) goodGeometry=false;
37  totalLayersOut += NSUMLAYSOUT[i];
38  }
39 
40  if (totalLayersIn != BCALMID-1) goodGeometry=false;
41  if (totalLayersOut != 10-(BCALMID-1)) goodGeometry=false;
42 
43  if(!goodGeometry) {
44  std::cout<<"ERROR: Bad BCAL fADC groupings, do not evenly divide cells";
45  assert (false);
46  }
47 
48  // Initialize DBCALGeometry variables
49  Initialize(runnumber);
50 
51 }
52 
53 void
54 DBCALGeometry::Initialize(int runnumber) {
55  //Get pointer to DGeometry object
56  DApplication* dapp=dynamic_cast<DApplication*>(japp);
57  const DGeometry *dgeom = dapp->GetDGeometry(runnumber);
58 
59  // Get inner rad of BCAL (including the support plate)
60  float my_BCALINNERRAD;
61  dgeom->GetBCALRmin(my_BCALINNERRAD);
62  BCALINNERRAD = my_BCALINNERRAD;
63 
64  // Get layer radii (4 layers)
65  vector<float> bcal_fadc_radii;
66  dgeom->GetBCALfADCRadii(bcal_fadc_radii);
67  if(bcal_fadc_radii.size()==5){
68  for(uint32_t i=0; i<bcal_fadc_radii.size(); i++){
69  fADC_radius[i] = bcal_fadc_radii[i];
70  }
71  }
72  else{
73  jerr<<"Did not retrieve 5 values for BCAL fADC radii!!!" << endl;
74  exit(-1);
75  }
76 
77  // Get BCAL Global Center
78  float my_GLOBAL_CENTER;
79  dgeom->GetBCALCenterZ(my_GLOBAL_CENTER);
80  GLOBAL_CENTER = my_GLOBAL_CENTER;
81 
82  // Get BCAL fiber length
83  float my_BCALFIBERLENGTH;
84  dgeom->GetBCALLength(my_BCALFIBERLENGTH);
85  BCALFIBERLENGTH = my_BCALFIBERLENGTH;
86 
87  // Get overall phi shift of BCAL
88  float my_BCAL_PHI_SHIFT;
89  dgeom->GetBCALPhiShift(my_BCAL_PHI_SHIFT);
90  BCAL_PHI_SHIFT = my_BCAL_PHI_SHIFT*TMath::Pi()/180.0; // convert to radians
91 }
92 
93 float
95  return BCALINNERRAD;
96 }
97 
98 const float*
100  return fADC_radius;
101  //return &(fADC_radius[0]);
102 }
103 
104 float
106  return GLOBAL_CENTER;
107 }
108 
109 float
111  return BCALFIBERLENGTH;
112 }
113 
114 float
116  return BCAL_PHI_SHIFT;
117 }
118 
119 //--------------
120 // module
121 //--------------
122 int
123 DBCALGeometry::module( int cellId ) const {
124 
125  return ( cellId & MODULE_MASK ) >> MODULE_SHIFT;
126 }
127 
128 //--------------
129 // layer
130 //--------------
131 int
132 DBCALGeometry::layer( int cellId ) const {
133 
134  return ( cellId & LAYER_MASK ) >> LAYER_SHIFT;
135 }
136 
137 //--------------
138 // sector
139 //--------------
140 int
141 DBCALGeometry::sector( int cellId ) const {
142 
143  return ( cellId & SECTOR_MASK ) >> SECTOR_SHIFT;
144 }
145 
146 //--------------
147 // cellId
148 //--------------
149 int
150 DBCALGeometry::cellId( int module, int layer, int sector ) const {
151 
152  return ( ( module << MODULE_SHIFT ) |
153  ( layer << LAYER_SHIFT ) |
154  ( sector << SECTOR_SHIFT ) );
155 }
156 
157 //--------------
158 // fADC_layer
159 //--------------
160 int
161 DBCALGeometry::fADC_layer( int SiPM_cellId ) const {
162 
163  int cell_layer = DBCALGeometry::layer( SiPM_cellId );
164  int fADC_layer = 0;
165  int tally=0;
166  if (cell_layer < BCALMID) {
167  for (int i=0;i<NBCALLAYSIN;i++) {
168  tally+=NSUMLAYSIN[i];
169  if (cell_layer <= tally) {
170  fADC_layer=i+1;
171  break;
172  }
173  }
174  } else {
175  tally=BCALMID-1;
176  for (int i=0;i<NBCALLAYSOUT;i++) {
177  tally+=NSUMLAYSOUT[i];
178  if (cell_layer <= tally) {
179  fADC_layer=NBCALLAYSIN+i+1;
180  break;
181  }
182  }
183  }
184  return fADC_layer;
185 }
186 
187 //--------------
188 // fADC_sector
189 //--------------
190 int
191 DBCALGeometry::fADC_sector( int SiPM_cellId ) const {
192 
193  int cell_layer = DBCALGeometry::layer( SiPM_cellId );
194  int cell_sector = DBCALGeometry::sector( SiPM_cellId );
195  int fADC_sector;
196 
197  if (cell_layer < BCALMID) {
198  //fADC_sector = 1 + (cell_sector-1)/NSUMSECSIN;
199  fADC_sector = 1 + (cell_sector-1);
200  } else {
201  //fADC_sector = 1 + (cell_sector-1)/NSUMSECSOUT;
202  fADC_sector = 1 + (cell_sector-1);
203  }
204 
205  return fADC_sector;
206 }
207 
208 //--------------
209 // fADCId
210 //--------------
211 int
212 DBCALGeometry::fADCId( int module, int SiPM_layer, int SiPM_sector ) const {
213  // This is used to return the readout channel ID which may
214  // differ from the cellID if summing is implemented.
215  //
216  // (5/12/2011 DL)
217 
218  int SiPM_cell = cellId(module, SiPM_layer, SiPM_sector);
219 
220  int fADC_lay = fADC_layer(SiPM_cell);
221  int fADC_sect = fADC_sector(SiPM_cell);
222 
223  return cellId(module, fADC_lay, fADC_sect);
224 }
225 
226 //--------------
227 // NSiPMs
228 //--------------
229 int
230 DBCALGeometry::NSiPMs(int fADCId) const
231 {
232  /// Return the number of SiPMs summed for the given fADCId
233  int fadc_lay = layer(fADCId);
234 
235  if(fadc_lay<1 || fadc_lay>(NBCALLAYSOUT+NBCALLAYSIN))return 0;
236 
237  if(fadc_lay <= NBCALLAYSIN){
238  // inner
239  //return NSUMLAYSIN[fadc_lay-1]*NSUMSECSIN;
240  return NSUMLAYSIN[fadc_lay-1];
241  }else{
242  // outer
243  //return NSUMLAYSOUT[fadc_lay-NBCALLAYSIN-1]*NSUMSECSOUT;
244  return NSUMLAYSOUT[fadc_lay-NBCALLAYSIN-1];
245  }
246 }
247 
248 //--------------
249 // r
250 //--------------
251 float
252 DBCALGeometry::r( int fADC_cell ) const {
253 
254  int fADC_lay = layer( fADC_cell );
255 
256  float innerRad;
257  float outerRad;
258 
259  if (fADC_lay <= NBCALLAYSIN) {
260  innerRad=m_radius[0];
261  outerRad=m_radius[0];
262  int innerIndex=0;
263  for (int i=0;i<fADC_lay;i++) {
264  innerRad=outerRad;
265  outerRad=m_radius[innerIndex+NSUMLAYSIN[i]];
266  innerIndex=innerIndex+NSUMLAYSIN[i];
267  }
268  } else {
269  innerRad=m_radius[BCALMID-1];
270  outerRad=m_radius[BCALMID-1];
271  int innerIndex=BCALMID-1;
272  for (int i=0;i < (fADC_lay-NBCALLAYSIN);i++) {
273  innerRad=outerRad;
274  outerRad=m_radius[innerIndex+NSUMLAYSOUT[i]];
275  innerIndex=innerIndex+NSUMLAYSOUT[i];
276  }
277  }
278 
279  return 0.5 * ( innerRad + outerRad );
280 }
281 
282 //--------------
283 // rSize
284 //--------------
285 float
286 DBCALGeometry::rSize( int fADC_cell ) const {
287 
288  int fADC_lay = layer( fADC_cell );
289 
290  float innerRad;
291  float outerRad;
292 
293  if (fADC_lay <= NBCALLAYSIN) {
294  innerRad=m_radius[0];
295  outerRad=m_radius[0];
296  int innerIndex=0;
297  for (int i=0;i<fADC_lay;i++) {
298  innerRad=outerRad;
299  outerRad=m_radius[innerIndex+NSUMLAYSIN[i]];
300  innerIndex=innerIndex+NSUMLAYSIN[i];
301  }
302  } else {
303  innerRad=m_radius[BCALMID-1];
304  outerRad=m_radius[BCALMID-1];
305  int innerIndex=BCALMID-1;
306  for (int i=0;i < (fADC_lay-NBCALLAYSIN);i++) {
307  innerRad=outerRad;
308  outerRad=m_radius[innerIndex+NSUMLAYSOUT[i]];
309  innerIndex=innerIndex+NSUMLAYSOUT[i];
310  }
311  }
312 
313  return ( outerRad - innerRad );
314 }
315 
316 //--------------
317 // phi
318 //--------------
319 float
320 DBCALGeometry::phi( int fADC_cell ) const {
321 
322  // int fADC_lay = layer( fADC_cell );
323  // int fADC_sect = sector( fADC_cell );
324 
325  // float sectSize;
326 
327  // int nSects;
328  // if (fADC_lay <= NBCALLAYSIN) {
329  // nSects = 4/NSUMSECSIN;
330  // } else {
331  // nSects = 4/NSUMSECSOUT;
332  // }
333 
334  // fADC_sect += nSects * ( module( fADC_cell ) - 1 );
335  // sectSize = 2 * M_PI / (NBCALMODS*nSects);
336 
337  // float my_phi = sectSize * ( (float)fADC_sect - 0.5 );
338  // my_phi += BCAL_PHI_SHIFT - 2.0*sectSize; // adjust for center of module and overall BCAL shift
339 
340  float globsect = getglobalsector(module(fADC_cell), sector(fADC_cell));
341  float sectSize = 2. * M_PI / 48. / 4;
342  // The first 2 sectors (half of mudule 1) have negative phi
343  float my_phi = sectSize * (globsect-2.5);
344  if (my_phi < 0) my_phi += 2 * M_PI;
345  return my_phi;
346 
347 }
348 
349 //--------------
350 // phiSize
351 //--------------
352 float
353 DBCALGeometry::phiSize( int fADC_cell ) const {
354 
355  // int fADC_lay = layer( fADC_cell );
356 
357  // int nSects;
358  // if (fADC_lay <= NBCALLAYSIN) {
359  // nSects = 4/NSUMSECSIN;
360  // } else {
361  // nSects = 4/NSUMSECSOUT;
362  // }
363 
364  // float sectSize = 2 * M_PI / ( NBCALMODS * nSects );
365 
366  float sectSize = 2 * M_PI / 48 / 4;
367 
368  return sectSize;
369 }
370 
371 //--------------
372 /// fADCcellId_rphi
373 //--------------
374 /// Method to get the fADC cell ID from an (R, phi) combination. R in cm and phi in radians.
375 int
376 DBCALGeometry::fADCcellId_rphi( float r, float phi ) const {
377  int fADC_cellId = 0;
378  int SiPM_layer = 0;
379 
380  if (r < BCALINNERRAD) return 0;
381  else if (r > BCALOUTERRAD) return 0;
382 
383  float modulephiSize = (2 * M_PI) / 48;
384  float sectorphiSize = modulephiSize / 4;
385  float phi_nooffset = (phi + 2.0*sectorphiSize);
386  if (phi_nooffset < 0) return 0;
387  else if (phi_nooffset > 2 * M_PI) return 0;
388 
389  if (r < m_radius[1]) SiPM_layer = 1;
390  else if (r < m_radius[2]) SiPM_layer = 2;
391  else if (r < m_radius[3]) SiPM_layer = 3;
392  else if (r < m_radius[4]) SiPM_layer = 4;
393  else if (r < m_radius[5]) SiPM_layer = 5;
394  else if (r < m_radius[6]) SiPM_layer = 6;
395  else if (r < m_radius[7]) SiPM_layer = 7;
396  else if (r < m_radius[8]) SiPM_layer = 8;
397  else if (r < m_radius[9]) SiPM_layer = 9;
398  else SiPM_layer = 10;
399 
400  float modulefloat = 1 + phi_nooffset / modulephiSize;
401  int module = (int)modulefloat;
402  float sectorfloat = 1 + ((phi_nooffset - (module-1)*modulephiSize) / sectorphiSize);
403  int sector = (int)sectorfloat;
404 
405  fADC_cellId = DBCALGeometry::fADCId(module, SiPM_layer, sector);
406  return fADC_cellId;
407 }
408 
409 int DBCALGeometry::getglobalchannelnumber(int module, int layer, int sector, int end) const {
410  if (module<=0 || layer<=0 || sector<=0) return 0;
411  else return (module-1)*32 + (layer-1)*8 + (sector-1)*2 + end + 1;
412 }
413 
414 int DBCALGeometry::getendchannelnumber(int module, int layer, int sector) const {
415  if (module<=0 || layer<=0 || sector<=0) return 0;
416  else return (module-1)*16 + (layer-1)*4 + sector;
417 }
418 
419 int DBCALGeometry::getglobalsector(int module, int sector) const {
420  if (module<=0 || sector<=0) return 0;
421  else return (module-1)*4 + sector;
422 }
423 
424 int DBCALGeometry::getsector(int globalsector) const {
425  if (globalsector<=0) return 0;
426  int sector = globalsector%4;
427  if (sector==0) sector=4;
428  return sector;
429 }
430 
431 int DBCALGeometry::getmodule(int globalsector) const {
432  if (globalsector<=0) return 0;
433  else return (globalsector-1)/4+1;
434 }
const int NBCALLAYSIN
number of readout layers in inner BCAL (first 6 SiPM layers)
int getmodule(int globalsector) const
int fADCcellId_rphi(float r, float phi) const
these are missing functions that fill in some previous gaps.
vector< int > NSUMLAYSIN
number of radial SiPM layers summed for digitization in each inner readout layer
DApplication * dapp
float BCALINNERRAD
innner radius of BCAL in cm
#define LAYER_SHIFT
Definition: DBCALGeometry.h:21
Int_t layer
float BCALOUTERRAD
outer radius of BCAL in cm
float rSize(int fADC_cellId) const
bool GetBCALRmin(float &bcal_rmin) const
minimum distance of BCAL module from beam line
Definition: DGeometry.cc:1544
#define LAYER_MASK
Definition: DBCALGeometry.h:22
float GetBCAL_phi_shift() const
int fADC_sector(int SiPM_cellId) const
void Initialize(int runnumber)
const int BCALMID
first outer layer (default 7)
float phi(int fADC_cellId) const
these functions are about the physical location and dimensions of a readout cell
JApplication * japp
#define MODULE_SHIFT
Definition: DBCALGeometry.h:19
float GetBCAL_length() const
int getglobalchannelnumber(int module, int layer, int sector, int end) const
Return a BCAL channel number, in order of significance (module, layer, sector, end).
float fADC_radius[5]
BCAL layer radii (4 layers total)
int fADCId(int module, int SiPM_layer, int SiPM_sector) const
bool GetBCALLength(float &bcal_length) const
length of BCAL module in cm
Definition: DGeometry.cc:1635
bool GetBCALCenterZ(float &bcal_center_z) const
z-location of center of BCAL module in cm
Definition: DGeometry.cc:1611
DGeometry * GetDGeometry(unsigned int run_number)
#define SECTOR_MASK
Definition: DBCALGeometry.h:24
float GetBCAL_inner_rad() const
float phiSize(int fADC_cellId) const
float r(int fADC_cellId) const
int NSiPMs(int fADCId) const
int getglobalsector(int module, int sector) const
int layer(int cellId) const
This method can be used for the SiPM ID or for the fADC ID since they are defined in the same way...
bool GetBCALPhiShift(float &bcal_phi_shift) const
phi angle in degrees that first BCAL module is shifted from being centered at ph=0.0
Definition: DGeometry.cc:1683
int sector(int cellId) const
This method can be used for the SiPM ID or for the fADC ID since they are defined in the same way...
float GetBCAL_center() const
float BCAL_PHI_SHIFT
overall phi roation of BCAL in radians
const float * GetBCAL_radii() const
int cellId(int module, int layer, int sector) const
these functions are about encoding/decoding module/layer/sector info in a cellId
float BCALFIBERLENGTH
BCAL Scintilator fiber lenth in cm.
float m_radius[11]
#define MODULE_MASK
Definition: DBCALGeometry.h:20
bool GetBCALfADCRadii(vector< float > &fADC_radii) const
fADC radii including the outer radius of the last layer
Definition: DGeometry.cc:1567
int getsector(int globalsector) const
float GLOBAL_CENTER
center of BCAL in gloobal coordinate system
#define SECTOR_SHIFT
Definition: DBCALGeometry.h:23
int module(int cellId) const
This method can be used for the SiPM ID or for the fADC ID since they are defined in the same way...
int getendchannelnumber(int module, int layer, int sector) const
Return a channel number for either end, in order of significance (module, layer, sector).
const int NBCALLAYSOUT
number of readout layers in outer BCAL (outer 4 SiPM layers)
vector< int > NSUMLAYSOUT
number of radial SiPM layers summed for digitization in each outer readout layer
int fADC_layer(int SiPM_cellId) const
these functions are about finding which readout cell contains a specific SiPM cell ...