NearDetDAQChannelMap.cpp
Go to the documentation of this file.
1 ///
2 /// \file NearDetDAQChannelMap.h
3 /// \brief Channel map specific to the 3x3 near detector
4 /// \version $Id: NearDetDAQChannelMap.cpp,v 1.1 2014/06/17 19:28:53 messier Exp $
5 /// \author Hayes Merritt <hdmerrit@indiana.edu>
6 ///
7 #include <cstdlib>
8 #include <cstdio>
9 #include <iostream>
10 #include "DAQChannelMap/NearDetDAQChannelMap.h"
11 #include "DAQChannelMap/NearDetDAQChannelMapConstants.h"
12 #include "DAQChannelMap/BitFields.h"
13 #include "DAQChannelMap/boundscheck.h"
14 #include "NovaDAQConventions/DAQConventions.h"
15 using namespace daqchannelmap;
16 
18 
19 //......................................................................
20 
22 
23 //......................................................................
24 
26 {
27  const int detector = getDetector(logicalchan);
28  const plane_t plane = getPlane(logicalchan);
29  const cell_t cell = getCell(logicalchan);
30  const diblock_t diblock = (plane/ND_NUM_PLANES_DIBLOCK) + 1;
31 
32  //
33  // Initialize the fiber id to an illegal value
34  //
35  fiber_t fiber = -1;
36 
37  //
38  // Fiber and cell differ only for horizontal modules (even planes)
39  //
40  if (plane%2==0) {
41  //
42  // Fiber calculation for all diblocks excluding the Muon Catcher
43  // (diblock<4)
44  //
45  if (diblock<4) {
46  fiber = ND_NUM_CELLS_PLANE - 1 - cell;
47  }
48  else {
49  //
50  // Fiber calculation for Muon Catcher. MC is 2 modules tall
51  // hence ND_NUM_CELLS_XPLANE_MC replaces ND_NUM_CELLS_PLANE.
52  //
53  fiber = ND_NUM_CELLS_XPLANE_MC - 1 - cell;
54  }
55  }
56  else {
57  //
58  // Vertical modules, simple case
59  //
60  fiber = cell;
61  }
62 
63  dcm_id_t dcm = computeDCM(plane, fiber, diblock);
64  feb_t feb = computeFEB(plane, fiber, diblock);
65  pixel_t pixel = computePixel(fiber);
66 
67  return DAQChannelMap::encodeDChan(detector, diblock, dcm, feb, pixel);
68 }
69 
70 //......................................................................
71 
73 {
74  const int detector = getDetector(daqchan);
75  const diblock_t diblock = getDiBlock(daqchan);
76  const dcm_id_t dcm = getDCM(daqchan);
77  const feb_t feb = getFEB(daqchan);
78  const pixel_t pixel = getPixel(daqchan);
79 
80  const plane_t plane = computePlane(diblock, dcm, feb);
81  const cell_t cell = computeCell(diblock, dcm, feb, pixel);
82 
83  return DAQChannelMap::encodeLChan(detector, plane, cell);
84 }
85 
86 //......................................................................
87 
89 {
90  if (getDiBlock(d)<4) {
91  //
92  // Upstream of muon catcher, 4 DCMs, 2 on top, 2 on side
93  //
94  if (getDCM(d)<3) return X_VIEW;
95  else return Y_VIEW;
96  }
97  else {
98  //
99  // In muon catcher, 2 DCMs 1 on top, 1 on side
100  //
101  if (getDCM(d)==1) return X_VIEW;
102  else return Y_VIEW;
103  }
104  //
105  // All legal cases handled above -- should never reach here.
106  //
107  abort();
108  return INIT;
109 }
110 
111 //......................................................................
112 //
113 // DCM number calculation using global plane number and fiber number.
114 //
116  fiber_t fiber,
117  diblock_t diblock) const
118 {
119  //
120  // Handle diblocks upstream of the muon catcher (diblock<4)
121  //
122  if (diblock < 4){
123  //
124  // Even planes are horizontal modules
125  //
126  if (plane%2==0){
127  dcm_id_t dcm_id = 0;
128  if (fiber< 64) dcm_id = 3;
129  else if (fiber>=64) dcm_id = 4;
130  return dcm_id;
131  }
132  else {
133  //
134  // plane is odd corresponding to vertical modules.
135  //
136  dcm_id_t dcm_id = 0;
137  if (fiber< 32) dcm_id = 1;
138  else if (fiber>=32) dcm_id = 2;
139  return dcm_id;
140  }
141  }
142  else {
143  //
144  // Handle the muon catcher here
145  //
146  if (plane%2 == 0){
147  //
148  // Plane is event, horizontal modules
149  //
150  dcm_id_t dcm_id = 2;
151  return dcm_id;
152  }
153  else {
154  //
155  // Plane is odd corresponding to vertical modules.
156  //
157  dcm_id_t dcm_id = 1;
158  return dcm_id;
159  }
160  }
161  return 0;
162 }
163 
164 //......................................................................
165 
167  fiber_t fiber,
168  diblock_t diblock) const
169 {
170  feb_t feb = -1;
171 
172  if (diblock < 4) {
173  //
174  // First handle diblocks upstream of the muon catcher (diblock<4)
175  //
176  if (plane%2==0) {
177  //
178  // Plane is even corresponding to horizontal modules.
179  //
180  if (fiber<32) feb = (plane%64)/2 + 32;
181  else feb = (plane%64)/2;
182  }
183  else {
184  //
185  // plane is odd corresponding to vertical modules.
186  //
187  if (fiber < 64) feb = (plane%64)/2;
188  else feb = (plane%64)/2 + 32;
189  }
190  }
191  else if(diblock==4) {
192  //
193  // Diblock 4 is the Muon Catcher. FEB calculation is slightly
194  // different when compared to other diblocks.
195  //
196  if (plane%2!=0){
197  //
198  // Plane is odd corresponding to vertical modules.
199  //
200  if (fiber<32) feb = (plane%64)/2;
201  else if (fiber>=32 && fiber<64) feb = (plane%64)/2 + 11;
202  else if (fiber>=64) feb = (plane%64)/2 + 22;
203  }
204  else {
205  //
206  // Plane is even corresponding to horizontal modules.
207  //
208  if (fiber<32) feb = (plane%64)/2;
209  else feb = (plane%64)/2 + 11;
210  }
211  }
212  return feb;
213 }
214 
215 //......................................................................
216 
218 {
219  fiber_t local_fiber = fiber%32;
220  pixel_t pixel = FiberToPixel(local_fiber);
221  return pixel;
222 }
223 
224 //......................................................................
225 
227  dcm_id_t dcm,
228  feb_t feb) const
229 {
230  //
231  // Handle diblocks upstream of the muon catcher (diblock<4)
232  //
233  if (diblock < 4) {
234  if (dcm < 3) {
235  //
236  // Vertical modules
237  //
238  plane_t plane = (feb % 32)*2 + 1 + (diblock-1)*64;
239  return plane;
240  }
241  else {
242  //
243  // Horizontal modules.
244  //
245  plane_t plane = (feb % 32)*2 + (diblock-1)*64;
246  return plane;
247  }
248  }
249  else {
250  //
251  // feb number is modded with 11 because there are 11 planes in
252  // each view in the Muon Catcher.
253  //
254  if (dcm==1) {
255  plane_t plane = (feb % 11)*2 + 1 + (diblock-1)*64;
256  return plane;
257  }
258  else {
259  plane_t plane = (feb % 11)*2 + (diblock-1)*64;
260  return plane;
261  }
262  }
263  return 0;
264 }
265 
266 //......................................................................
267 
269  dcm_id_t dcm,
270  feb_t feb,
271  pixel_t pixel) const
272 {
273  //
274  // Handle diblocks upsteam of the muon catcher (diblock<4)
275  //
276  if (diblock < 4) {
277  if (dcm < 3) {
278  //
279  // Vertical modules.
280  //
281  cell_t cell = ((dcm - 1)*32 + (feb/32)*32 + PixelToFiber(pixel));
282  return cell;
283  }
284  else {
285  //
286  // Horizontal modules.
287  //
288  cell_t cell =
289  (ND_NUM_CELLS_PLANE-1) -
290  ((dcm - 3)*64 + (1- feb/32 - dcm/4)*32 + PixelToFiber(pixel));
291  return cell;
292  }
293  }
294  else {
295  //
296  // In Muon Catcher.
297  //
298  if (dcm==1) {
299  cell_t cell = (feb/11)*32 + PixelToFiber(pixel);
300  return cell;
301  }
302  else {
303  cell_t cell =
305  ((feb/11)*32 + PixelToFiber(pixel));
306  return cell;
307  }
308  }
309  return 0;
310 }
311 
312 //......................................................................
313 
315 {
316  plane_t plane = getPlane(logicalchan);
317  return plane/ND_NUM_PLANES_BLOCK;
318 }
319 
320 //......................................................................
321 
323 {
324  return pixel2fiber[pixel];
325 }
326 
327 //......................................................................
328 
330 {
331  return fiber2pixel[fiber];
332 }
333 
334 //......................................................................
335 
337 {
338  plane_t plane = getPlane(logicalchan);
339 
340  // Blocks in the near detector are constructed as 24 plane objects
341  plane_t plane_in_block = plane % 24;
342  return plane_in_block;
343 }
344 
345 //......................................................................
346 
347 unsigned int NearDetDAQChannelMap::computeModule(lchan logicalchan) const
348 {
349  cell_t cell = getCell(logicalchan);
350  return cell/32;
351 }
352 
353 //......................................................................
354 
356 {
357  pixel_t pixel = getPixel(daqchan);
358  fiber_t fiber = PixelToFiber(pixel);
359 
360  return fiber;
361 }
362 
363 //......................................................................
364 
366 {
367  return ND_NUM_DIBLOCKS;
368 }
369 
370 //......................................................................
371 
373 {
374  return ND_NUM_DCMS;
375 }
376 
377 //......................................................................
378 
380 {
381  unsigned diblock = getDiBlock(chan);
382  if (diblock<4) return AFULLAFULL_DIBLOCK;
383  return MC_ND_DIBLOCK;
384 }
385 
386 ////////////////////////////////////////////////////////////////////////
fiber_t PixelToFiber(pixel_t pixel) const
int getDetector(uint32_t anychan) const
diblock
print "ROW IS " print row
Definition: geo2elec.py:31
DiBlock_TYPE getDiBlockType(dchan chan) const
What format is the diblock? Only relevant in NDOS.
unsigned int getTotalNumberOfDiblocks() const
How many diblocks does the detector have?
Identifider for NearDet Muon catcher.
plane_t computePlane(diblock_t diblock, dcm_id_t dcm, feb_t feb) const
uint32_t pixel_t
Type for physical pixel on APD.
pixel_t computePixel(fiber_t fiber) const
cell_t computeCell(diblock_t diblock, dcm_id_t dcm, feb_t feb, pixel_t pixel) const
dcm_id_t computeDCM(plane_t plane, fiber_t fiber, diblock_t diblock) const
unsigned int computeModule(lchan logicalchan) const
Which module in this lchan in?
cell_t getCell(lchan logicalchan) const
Decode the cell number from an lchan.
lchan encodeLChan(int detId, plane_t plane, cell_t cell) const
Identifier for the Y measuring view of the detector (side)
feb_t computeFEB(plane_t plane, fiber_t fiber, diblock_t diblock) const
dchan encodeDChan(lchan logicalchan) const
Convert a logical channel ID to a DAQ channel id.
Identifier for the X measuring view of the detector (top)
lchan encodeLChan(dchan daqchan) const
Convert a DAQ channel ID to a logical channel id.
unsigned int getNumberOfDCM(DiBlock_TYPE dbt) const
How many DCMs does this diblock have?
Float_t d
Definition: plot.C:236
uint32_t feb_t
Type for DCM link port. Counts from 0.
block_t computeBlock(lchan logicalchan) const
Which block is this lchan in?
Identifier for diblocks using a 32/32 configuration.
DetView_TYPE getView(dchan daqchan) const
Which view (X or Y) does this daq channel readout?
fiber_t computeFiberInModule(dchan daqchan) const
Which fiber does this dchan readout?
const unsigned int pixel2fiber[]
uint32_t dcm_id_t
Type for DCM number, counts from 1.
pixel_t getPixel(dchan daqchan) const
Decode the pixel id from a dchan.
uint32_t plane_t
Type for plane.
DetView_TYPE
Types of Detector View.
plane_t getPlane(lchan logicalchan) const
Decode the plane number from an lchan.
uint32_t diblock_t
Type for diblocks and blocks.
dcm_id_t getDCM(dchan daqchan) const
Decode the dcm ID from a dchan.
dchan encodeDChan(int detID, diblock_t diblock, dcm_id_t dcm, feb_t feb, pixel_t pixel) const
DiBlock_TYPE
Types of Diblock.
uint32_t dchan
< DAQ Channel Map Package
diblock_t getDiBlock(dchan daqchan) const
Decode the diblock ID from a dchan.
const unsigned int fiber2pixel[]
plane_t computePlaneInBlock(lchan logicalchan) const
Which global plane in this lchan in?
pixel_t FiberToPixel(fiber_t fiber) const
feb_t getFEB(dchan daqchan) const
Decode the feb id from a dchan.