CbmRoot
CbmTrdParModDigi.cxx
Go to the documentation of this file.
1 #include "CbmTrdParModDigi.h"
2 
3 #include "CbmTrdAddress.h" // for CbmTrdAddress
4 #include "CbmTrdPoint.h" // for CbmTrdPoint
5 
6 #include <FairLogger.h> // for FairLogger, gLogger, Logger, LOG, Severity, Severity::debug2
7 
8 #include <TGeoManager.h> // for TGeoManager, gGeoManager
9 #include <TString.h> // for TString
10 #include <TVector3.h> // for TVector3
11 
12 #include <iomanip> // for setprecision, __iom_t5
13 #include <math.h> // for fabs
14 #include <stdio.h> // for printf
15 #include <string.h> // for strcmp
16 
17 //___________________________________________________________________
19  : CbmTrdParMod("CbmTrdParModDigi", "TRD read-out definition")
20  , fNofSectors(1)
21  , fOrientation(0)
22  , fAnodeWireOffset(0.375)
23  , fAnodeWireSpacing(0.25)
24  , fAnodeWireToPadPlaneDistance(0.35)
25  , fX(0.)
26  , fY(0.)
27  , fZ(0.)
28  , fSizeX(0)
29  , fSizeY(0)
30  , fSizeZ(0)
31  , fSectorX()
32  , fSectorY()
33  , fSectorZ()
34  , fSectorBeginX()
35  , fSectorBeginY()
36  , fSectorEndX()
37  , fSectorEndY()
38  , fSectorSizeX()
39  , fSectorSizeY()
40  , fPadSizeX()
41  , fPadSizeY() {}
42 //___________________________________________________________________
44  Double_t y,
45  Double_t z,
46  Double_t sizex,
47  Double_t sizey,
48  Double_t sizez,
49  Int_t nofSectors,
50  Int_t orientation,
51  const TArrayD& sectorSizeX,
52  const TArrayD& sectorSizeY,
53  const TArrayD& padSizeX,
54  const TArrayD& padSizeY)
55  : CbmTrdParMod("CbmTrdParModDigi", "TRD read-out definition")
56  , fNofSectors(nofSectors)
57  , fOrientation(orientation)
58  , fAnodeWireOffset(0.375)
59  , fAnodeWireSpacing(0.25)
60  , fAnodeWireToPadPlaneDistance(0.35)
61  , fX(x)
62  , fY(y)
63  , fZ(z)
64  , fSizeX(sizex)
65  , fSizeY(sizey)
66  , fSizeZ(sizez)
67  , fSectorX(nofSectors)
68  , fSectorY(nofSectors)
69  , fSectorZ(nofSectors)
70  , fSectorBeginX(nofSectors)
71  , fSectorBeginY(nofSectors)
72  , fSectorEndX(nofSectors)
73  , fSectorEndY(nofSectors)
74  , fSectorSizeX(sectorSizeX)
75  , fSectorSizeY(sectorSizeY)
76  , fPadSizeX(padSizeX)
77  , fPadSizeY(padSizeY) {
84  if (nofSectors > 1) {
85  Double_t beginx, beginy, endx, endy;
86  Double_t summed_sectsize;
87  if (sectorSizeX.GetAt(0) == 2 * sizex) { //substructure only in y-direction
88  beginx = 0;
89  endx = 2 * sizex;
90  summed_sectsize = 0;
91  for (Int_t i = 0; i < fNofSectors; i++) {
92  if (0 == i) {
93  beginy = 0.;
94  endy = sectorSizeY.GetAt(i);
95  summed_sectsize += sectorSizeY.GetAt(i);
96  } else {
97  beginy = summed_sectsize;
98  endy = summed_sectsize += sectorSizeY.GetAt(i);
99  }
100  fSectorBeginX.AddAt(beginx, i);
101  fSectorBeginY.AddAt(beginy, i);
102  fSectorEndX.AddAt(endx, i);
103  fSectorEndY.AddAt(endy, i);
104  fSectorX.AddAt(beginx + (sectorSizeX.GetAt(i) / 2.), i);
105  fSectorY.AddAt(beginy + (sectorSizeY.GetAt(i) / 2.), i);
106  fSectorZ.AddAt(fZ, i);
107  }
108  } else {
109  LOG(warn) << GetName()
110  << "::CbmTrdParModDigi - detect different information on "
111  "module size x : geometry="
112  << std::setprecision(5) << 2 * sizex
113  << " CbmTrdPads.h=" << sectorSizeX.GetAt(0);
114  beginy = 0;
115  endy = 2 * sizey;
116  summed_sectsize = 0;
117  for (Int_t i = 0; i < fNofSectors; i++) {
118  if (0 == i) {
119  beginx = 0.;
120  endx = sectorSizeX.GetAt(i);
121  summed_sectsize += sectorSizeX.GetAt(i);
122  } else {
123  beginx = summed_sectsize;
124  endx = summed_sectsize += sectorSizeX.GetAt(i);
125  }
126  fSectorBeginX.AddAt(beginx, i);
127  fSectorBeginY.AddAt(beginy, i);
128  fSectorEndX.AddAt(endx, i);
129  fSectorEndY.AddAt(endy, i);
130  fSectorX.AddAt(beginx + (sectorSizeX.GetAt(i) / 2.), i);
131  fSectorY.AddAt(beginy + (sectorSizeY.GetAt(i) / 2.), i);
132  fSectorZ.AddAt(fZ, i);
133  }
134  }
135  } else {
136  fSectorBeginX.AddAt(0., 0);
137  fSectorBeginY.AddAt(0., 0);
138  fSectorEndX.AddAt(sectorSizeX.GetAt(0), 0);
139  fSectorEndY.AddAt(sectorSizeY.GetAt(0), 0);
140  fSectorX.AddAt(x, 0);
141  fSectorY.AddAt(y, 0);
142  fSectorZ.AddAt(z, 0);
143  }
144 }
145 
146 //___________________________________________________________________________
147 void CbmTrdParModDigi::Print(Option_t* opt) const {
151  printf(" CbmTrdParModDigi @ %5d ly[%d] idLy[%3d] rotation[%3ddeg] rows[%2d] "
152  "cols[%3d]\n",
153  fModuleId,
156  fOrientation * 90,
157  GetNofRows(),
158  GetNofColumns());
159  if (strcmp(opt, "all") != 0) return;
160  printf(" center [%7.2f %7.2f %7.2f]\n"
161  " size [%7.2f %7.2f %7.2f]\n"
162  " anode pitch[%5.3f] d2PP[%5.3f] off[%5.3f]\n"
163  " pads ",
164  fX,
165  fY,
166  fZ,
167  fSizeX,
168  fSizeY,
169  fSizeZ,
173  for (Int_t isec(0); isec < fNofSectors; isec++)
174  printf(" [c(%3d) r(%2d)]x[w(%4.2f) h(%5.2f)] area[%5.2fx%5.2f] limits "
175  "x[%5.2f %5.2f] y[%5.2f %5.2f]\n ",
176  GetNofColumnsInSector(isec),
177  GetNofRowsInSector(isec),
178  fPadSizeX.At(isec),
179  fPadSizeY.At(isec),
180  fSectorSizeX[isec],
181  fSectorSizeY[isec],
182  fSectorBeginX[isec],
183  fSectorEndX[isec],
184  fSectorBeginY[isec],
185  fSectorEndY[isec]);
186  printf("\n");
187 }
188 
189 //___________________________________________________________________________
191  Double_t* local_point) const {
198  if (/*fAnodeWireOffset > 0.0 && */ fAnodeWireSpacing
199  > 0.0) { // wires must be defined defined
200 
201  // check, if the input is within the allowed range
202  if (fabs(local_point[1]) - fSizeY > 1.e-3)
203  LOG(error) << "CbmTrdParModDigi::ProjectPositionToNextAnodeWire - local "
204  "point must be within gas volume, y="
205  << std::setprecision(5) << local_point[1] << " module size "
206  << fSizeY;
207 
208  Double_t ypos = local_point[1];
209 
210  LOG(debug2) << "local y before projection: " << std::setprecision(5)
211  << local_point[1] << " cm";
212 
213  // make sure, local_point[1] is not negative (due to module center coordinate)
214  // therefore transform to local corner first and then back at the end of operation
215  local_point[1] += fSizeY; // transform to module corner coordinates
216 
217  local_point[1] =
218  Int_t(((local_point[1] - fAnodeWireOffset) / fAnodeWireSpacing) + 0.5)
220  + fAnodeWireOffset; // find closest anode wire
221 
222  if (local_point[1] > 2 * fSizeY - fAnodeWireOffset)
223  local_point[1] =
224  2 * fSizeY - fAnodeWireOffset; // move inwards to the last anode wire
225 
226  local_point[1] -= fSizeY; // transform back to module center coordinates
227 
228  LOG(debug2) << "local y after projection: " << std::setprecision(5)
229  << local_point[1] << " cm";
230 
231  // check, if we have left the anode wire grid
232  if (fabs(local_point[1]) > fSizeY - fAnodeWireOffset)
233  LOG(error) << "CbmTrdParModDigi::ProjectPositionToNextAnodeWire - local "
234  "point projected outside anode wire plane, from "
235  << std::setprecision(5) << ypos << " to "
236  << std::setprecision(5) << local_point[1]
237  << " - last anode wire at " << std::setprecision(5)
239 
240  } else {
241  LOG(error) << "CbmTrdParModDigi::ProjectPositionToNextAnodeWire: "
242  "fAnodeWireOffset and fAnodeWireSpacing not set. "
243  "ProjectPositionToNextAnodeWire can not be used.";
244  }
245 }
246 
247 //___________________________________________________________________________
248 Int_t CbmTrdParModDigi::GetSector(const Double_t* local_point) const {
256  Double_t posx, posy;
257 
258  TransformToLocalCorner(local_point, posx, posy);
259  for (Int_t i = 0; i < fNofSectors; i++) {
260  if (posx >= fSectorBeginX[i] && posx <= fSectorEndX[i]
261  && posy >= fSectorBeginY[i] && posy <= fSectorEndY[i]) {
262  return i;
263  }
264  }
265 
266  LOG(error) << "CbmTrdParModDigi::GetSector: Could not find local point ["
267  << local_point[0] << " " << local_point[1]
268  << "] in any of the sectors";
269  Print("all");
270  return -1; // This should be never reached
271 }
272 
273 //___________________________________________________________________________
274 Int_t CbmTrdParModDigi::GetSector(Int_t npady, Int_t& rowId) const {
279  if ((npady < 0) || (npady > GetNofRows() - 1)) {
280  LOG(error) << "CbmTrdParModDigi::GetSector - there is no such row number: "
281  << npady;
282  return -1;
283  }
284 
285  Int_t secRows = 0; // number of rows in sector
286  Int_t nofRows = 0; // number of rows in total
287 
288  if (fSectorSizeY.At(0) < fSizeY) { // if there are sectors in y direction
289  for (Int_t iSector = 0; iSector < fNofSectors;
290  iSector++) { // for each sector
291  secRows = (Int_t)(fSectorSizeY.At(iSector) / fPadSizeY.At(iSector)
292  + 0.5); // need to round for correct result
293  if (npady
294  < nofRows + secRows) { // if we are in the sector containing the pad
295  // note nypad = 12 is not in sector 0, with rowIds 0..11
296  rowId = npady - nofRows;
297 
298  LOG(debug2) << "npady : " << npady << " <= " << nofRows + secRows
299  << " rowId " << rowId << " nRows(sec-1) " << nofRows
300  << " sec " << iSector;
301 
302  if ((rowId < 0) || (rowId > GetNofRowsInSector(iSector) - 1))
303  LOG(fatal) << "CbmTrdParModDigi::GetModuleRow rowId " << rowId
304  << " of "
305  << GetNofRowsInSector(iSector) - 1
306  //<< " in moduleAddress " << fModuleAddress
307  << " is out of bounds!";
308 
309  return iSector; // return sector
310  }
311  nofRows += secRows; // sum up new total number of rows
312  }
313  }
314  LOG(error)
315  << "CbmTrdParModDigi::GetSector: Could not find pad in any of the sectors";
316  return -1; // This should be never reached
317 }
318 
319 
320 //___________________________________________________________________________
326  Int_t nofColumns = 0;
327  if (fSectorSizeX.At(0) < fSizeX) {
328  for (Int_t i = 0; i < fNofSectors; i++) {
329  nofColumns += (Int_t)(fSectorSizeX.At(i) / fPadSizeX.At(i)
330  + 0.5); // need to round for correct result
331  }
332  } else {
333  nofColumns = (Int_t)(fSectorSizeX.At(0) / fPadSizeX.At(0)
334  + 0.5); // need to round for correct result
335  }
336  return nofColumns;
337 }
338 
339 //___________________________________________________________________________
344  Int_t nofRows = 0;
345  if (fSectorSizeY.At(0) < fSizeY) {
346  for (Int_t i = 0; i < fNofSectors; i++) {
347  nofRows += (Int_t)(fSectorSizeY.At(i) / fPadSizeY.At(i)
348  + 0.5); // need to round for correct result
349  }
350  } else {
351  nofRows = (Int_t)(fSectorSizeY.At(0) / fPadSizeY.At(0)
352  + 0.5); // need to round for correct result
353  }
354  return nofRows;
355 }
356 
357 
358 //___________________________________________________________________________
360  return (Int_t)(fSectorSizeX.At(i) / fPadSizeX.At(i)
361  + 0.5); // need to round for correct result
362 }
363 
364 
365 //___________________________________________________________________________
367  return (Int_t)(fSectorSizeY.At(i) / fPadSizeY.At(i)
368  + 0.5); // need to round for correct result
369 }
370 
371 
372 //___________________________________________________________________________
373 Int_t CbmTrdParModDigi::GetModuleRow(Int_t& sectorId, Int_t& rowId) const {
374 
375  // check limits
376  if ((sectorId < 0) || (sectorId > GetNofSectors() - 1))
377  LOG(fatal) << "CbmTrdParModDigi::GetModuleRow sectorId " << sectorId
378  << " of "
379  << GetNofSectors() - 1
380  //<< " in moduleAddress " << fModuleAddress
381  << " is out of bounds!";
382 
383  // check limits
384  if ((rowId < 0) || (rowId > GetNofRowsInSector(sectorId) - 1))
385  LOG(fatal) << "CbmTrdParModDigi::GetModuleRow rowId " << rowId << " of "
386  << GetNofRowsInSector(sectorId) - 1
387  //<< " in moduleAddress " << fModuleAddress
388  << " is out of bounds!";
389 
390  Int_t moduleRowId = rowId;
391 
392  // calculate row number within module
393  for (Int_t iSector = 0; iSector < sectorId; iSector++) {
394  moduleRowId +=
395  (Int_t)(fSectorSizeY.At(iSector) / fPadSizeY.At(iSector) + 0.5);
396  // LOG(info) << "adding sector " << iSector << " of " << sectorId;
397  }
398 
399  // if (sectorId == 0)
400  // // do nothing
401  // if (sectorId >= 1)
402  // moduleRowId += (Int_t)(fSectorSizeY.At(0) / fPadSizeY.At(0) + 0.5);
403  // if (sectorId >= 2)
404  // moduleRowId += (Int_t)(fSectorSizeY.At(1) / fPadSizeY.At(1) + 0.5);
405 
406  return moduleRowId;
407 }
408 
409 
410 //___________________________________________________________________________
411 Int_t CbmTrdParModDigi::GetSectorRow(Int_t growId, Int_t& rowId) const {
412  // check limits
413  if ((growId < 0) || (growId >= GetNofRows()))
414  LOG(fatal) << "CbmTrdParModDigi::GetSectorRow rowId " << growId << " of "
415  << GetNofRows()
416  //<< " in moduleAddress " << fModuleAddress
417  << " is out of bounds!";
418 
419  rowId = growId;
420 
421  // calculate row number within sector
422  Int_t iSector(0);
423  for (; iSector < 3; iSector++) {
424  Int_t nr(GetNofRowsInSector(iSector));
425  if (rowId - nr + 1 > 0)
426  rowId -= nr;
427  else
428  break;
429  }
430 
431  return iSector;
432 }
433 
434 
435 //___________________________________________________________________________
436 Bool_t CbmTrdParModDigi::GetPadInfo(const Double_t* local_point,
437  Int_t& sectorId,
438  Int_t& columnId,
439  Int_t& rowId) const {
440  // check, if the input is within the allowed range
441  if (fabs(local_point[0]) > fSizeX) {
442  LOG(error) << "CbmTrdParModDigi::GetPadInfo - local point x must be within "
443  "gas volume, x="
444  << std::setprecision(8) << local_point[0]
445  << " fSizeX=" << std::setprecision(8) << fSizeX;
446  return kFALSE;
447  }
448  if (fabs(local_point[1]) > fSizeY) {
449  LOG(error) << "CbmTrdParModDigi::GetPadInfo - local point y must be within "
450  "gas volume, y="
451  << std::setprecision(8) << local_point[1]
452  << " fSizeY=" << std::setprecision(8) << fSizeY;
453  return kFALSE;
454  }
455 
456  Double_t posX, posY;
457  TransformToLocalSector(local_point, posX, posY);
458 
459  // calculate in which sector the point is
460  sectorId = GetSector(local_point);
461 
462  columnId = (Int_t)(posX / fPadSizeX.At(sectorId));
463  rowId = (Int_t)(posY / fPadSizeY.At(sectorId));
464 
465  return kTRUE;
466 }
467 
468 //___________________________________________________________________________
470  Int_t& sectorId,
471  Int_t& columnId,
472  Int_t& rowId) const {
481  Double_t x_mean = 0.5 * (trdPoint->GetXIn() + trdPoint->GetXOut());
482  Double_t y_mean = 0.5 * (trdPoint->GetYIn() + trdPoint->GetYOut());
483  Double_t z_mean = 0.5 * (trdPoint->GetZIn() + trdPoint->GetZOut());
484  gGeoManager->FindNode(x_mean, y_mean, z_mean);
485 
486  TString curNode = gGeoManager->GetPath();
487  if (!curNode.Contains("gas")) {
488  // if the point is not in the gas volume print warning
489  LOG(warn) << "This point is not in the trd gas";
490  /*
491  LOG(warn) << "x: " << std::setprecision(7) << trdPoint->GetXIn() << ", " << trdPoint->GetXOut();
492  LOG(warn) << "y: " << std::setprecision(7) << trdPoint->GetYIn() << ", " << trdPoint->GetYOut();
493  LOG(warn) << "z: " << std::setprecision(7) << trdPoint->GetZIn() << ", " << trdPoint->GetZOut();
494  */
495  sectorId = -1;
496  return;
497  }
498 
499  // Get the local point in local MC coordinates from
500  // the geomanager. This coordinate system is rotated
501  // if the chamber is rotated. This is corrected in
502  // GetModuleInformation to have a
503  // the same local coordinate system in all the chambers
504  const Double_t* global_point = gGeoManager->GetCurrentPoint();
505  Double_t local_point[3];
506 
507  gGeoManager->MasterToLocal(global_point, local_point);
508 
509  // 20131009 - DE - debuging output to check module orientation 0,1,2,3 with box generator
510  if (gLogger->IsLogNeeded(fair::Severity::debug2)) {
511  // print module orientation
512  LOG(debug2) << "module orientation: " << std::setprecision(5)
513  << fOrientation;
514 
515  // print global coordinate
516  LOG(debug2) << "global x: " << std::setprecision(5) << global_point[0]
517  << " y: " << std::setprecision(5) << global_point[1]
518  << " z: " << std::setprecision(5) << global_point[2];
519 
520  // print local coordinate - relative to module center
521  LOG(debug2) << "local x: " << std::setprecision(5) << local_point[0]
522  << " y: " << std::setprecision(5) << local_point[1]
523  << " z: " << std::setprecision(5) << local_point[2];
524 
525  // test projection to next anode wire
526  Double_t proj_point[3];
527  proj_point[0] = local_point[0];
528  proj_point[1] = local_point[1];
529  proj_point[2] = local_point[2];
530 
531  ProjectPositionToNextAnodeWire(proj_point);
532 
533  // print local coordinate - relative to module center
534  LOG(debug2) << "proj x: " << std::setprecision(5) << proj_point[0]
535  << " y: " << std::setprecision(5) << proj_point[1]
536  << " z: " << std::setprecision(5) << proj_point[2];
537 
538  Double_t corner_point[3];
539  corner_point[2] = local_point[2];
540  TransformToLocalCorner(local_point, corner_point[0], corner_point[1]);
541 
542  // print local coordinate - relative to module corner
543  LOG(debug2) << "corner x: " << std::setprecision(5) << corner_point[0]
544  << " y: " << std::setprecision(5) << corner_point[1]
545  << " z: " << std::setprecision(5) << corner_point[2];
546 
547  LOG(debug2) << "pos x: " << std::setprecision(5) << fX
548  << " y: " << std::setprecision(5) << fY
549  << " z: " << std::setprecision(5) << fZ
550  << " ori: " << std::setprecision(5) << fOrientation;
551 
552  LOG(debug2) << "size/2 x: " << std::setprecision(5) << fSizeX
553  << " y: " << std::setprecision(5) << fSizeY
554  << " z: " << std::setprecision(5) << fSizeZ;
555 
556  Double_t sector_point[3];
557  sector_point[2] = local_point[2];
558  TransformToLocalSector(local_point, sector_point[0], sector_point[1]);
559 
560  // print local coordinate - relative to module sector
561  LOG(debug2) << "sector x: " << std::setprecision(5) << sector_point[0]
562  << " y: " << std::setprecision(5) << sector_point[1]
563  << " z: " << std::setprecision(5) << sector_point[2];
564 
565  // calculate in which sector the point is
566  sectorId = GetSector(local_point);
567  LOG(debug2) << "sectornr: " << std::setprecision(5) << sectorId;
568 
569  LOG(debug2) << "ncol : " << std::setprecision(5) << GetNofColumns();
570  LOG(debug2) << "nrow : " << std::setprecision(5) << GetNofRows();
571 
572  // print local coordinate - relative to module sector
573  LOG(debug2) << "sec2 x: " << std::setprecision(5)
574  << fSectorBeginX.GetAt(2) << " y: " << std::setprecision(5)
575  << fSectorBeginY.GetAt(2);
576  LOG(debug2) << "sec1 x: " << std::setprecision(5)
577  << fSectorBeginX.GetAt(1) << " y: " << std::setprecision(5)
578  << fSectorBeginY.GetAt(1);
579  LOG(debug2) << "sec0 x: " << std::setprecision(5)
580  << fSectorBeginX.GetAt(0) << " y: " << std::setprecision(5)
581  << fSectorBeginY.GetAt(0);
582 
583  // get pad information
584  Int_t s, c, r;
585  GetPadInfo(local_point, s, c, r);
586  LOG(debug2) << "pad sec: " << s << " col: " << c << " row: " << r;
587  } // debug2
588 
589  // Int_t moduleAddress = CbmTrdAddress::GetModuleAddress(trdPoint->GetDetectorID());
591  /*moduleAddress, */ local_point, sectorId, columnId, rowId);
592 }
593 
594 
595 //___________________________________________________________________________
596 void CbmTrdParModDigi::TransformToLocalCorner(const Double_t* local_point,
597  Double_t& posX,
598  Double_t& posY) const {
609  posX = local_point[0] + fSizeX;
610  posY = local_point[1] + fSizeY;
611 }
612 
613 //___________________________________________________________________________
614 void CbmTrdParModDigi::TransformToLocalSector(const Double_t* local_point,
615  Double_t& posX,
616  Double_t& posY) const {
626  TransformToLocalCorner(local_point, posX, posY);
627  Int_t sector = GetSector(local_point);
628  posX -= fSectorBeginX.GetAt(sector);
629  posY -= fSectorBeginY.GetAt(sector);
630 }
631 
632 
633 //___________________________________________________________________________
634 void CbmTrdParModDigi::TransformToLocalPad(const Double_t* local_point,
635  Double_t& posX,
636  Double_t& posY) const {
644  Double_t sector_point[2];
645  TransformToLocalSector(local_point, sector_point[0], sector_point[1]);
646 
647  // TransformToLocalCorner(local_point, posX, posY);
648  Int_t sectorId = GetSector(local_point);
649 
650  Double_t padx = (Int_t(sector_point[0] / fPadSizeX.At(sectorId)) + 0.5)
651  * fPadSizeX.At(sectorId); // x position of pad center
652  Double_t pady = (Int_t(sector_point[1] / fPadSizeY.At(sectorId)) + 0.5)
653  * fPadSizeY.At(sectorId); // y position of pad center
654 
655  posX = sector_point[0] - padx;
656  posY = sector_point[1] - pady;
657 
658  /*
659  // print debug info
660  LOG(info) << "sector x: " << std::setprecision(5) << sector_point[0]
661  << " y: " << std::setprecision(5) << sector_point[1];
662 
663  LOG(info) << "pad x: " << std::setprecision(5) << padx
664  << " y: " << std::setprecision(5) << pady;
665 
666  LOG(info) << "diff x: " << std::setprecision(5) << posX
667  << " y: " << std::setprecision(5) << posY;
668 
669  LOG(info) << "npad x: " << std::setprecision(5) << padx / fPadSizeX.At(sectorId)
670  << " y: " << std::setprecision(5) << pady / fPadSizeY.At(sectorId);
671  */
672 }
673 
674 
675 //___________________________________________________________________________
676 void CbmTrdParModDigi::TransformHitError(TVector3& hitErr) const {
677  Double_t x, y; // ,z;
678  x = hitErr.X();
679  y = hitErr.Y();
680  // z = hitErr.Z();
681 
682  //LOG(info) << "ori : " << fOrientation;
683 
684  if ((fOrientation == 1) || (fOrientation == 3)) { // for orientations 1 or 3
685  hitErr.SetX(y); // swap errors
686  hitErr.SetY(x); // swap errors
687 
688  // LOG(info) << " swapped x and y error";
689  // LOG(info) << "ori : " << fOrientation << " swapped x and y error";
690  }
691 }
692 
693 
694 //___________________________________________________________________________
696  //Int_t moduleAddress,
697  const Double_t* local_point,
698  Int_t& sectorId,
699  Int_t& columnId,
700  Int_t& rowId) const {
701  // safety check. Up to now always correct, so could be removed.
702  // if (fModuleAddress != moduleAddress) {
703  // LOG(error) << "CbmTrdParModDigi::GetModuleInformation: This is wrong!";
704  // }
705 
706  Double_t posX, posY;
707  TransformToLocalSector(local_point, posX, posY);
708 
709  // calculate in which sector the point is
710  sectorId = GetSector(local_point);
711 
712  columnId = (Int_t)(posX / fPadSizeX.At(sectorId));
713  rowId = (Int_t)(posY / fPadSizeY.At(sectorId));
714 }
715 
716 
717 //___________________________________________________________________________
718 void CbmTrdParModDigi::GetPadPosition(const Int_t sector,
719  const Int_t col,
720  const Int_t row,
721  TVector3& padPos,
722  TVector3& padPosErr) const {
727  Double_t posX = 0;
728  Double_t posY = 0;
729  Double_t posZ = 0;
730 
731  Double_t padsizex = fPadSizeX.At(sector);
732  Double_t padsizey = fPadSizeY.At(sector);
733 
734  // calculate position in sector coordinate system
735  // with the origin in the lower left corner (looking upstream)
736  posX = (((Double_t) col + 0.5) * padsizex);
737  posY = (((Double_t) row + 0.5) * padsizey);
738 
739  // calculate position in module coordinate system
740  // with the origin in the lower left corner (looking upstream)
741  posX += fSectorBeginX.GetAt(sector);
742  posY += fSectorBeginY.GetAt(sector);
743 
744  // calculate position in the module coordinate system
745  // with origin in the middle of the module
746  posX -= fSizeX;
747  posY -= fSizeY;
748  posZ = 0;
749 
750  // check limits
751  if (fabs(posX) > fSizeX)
752  LOG(fatal) << "CbmTrdParModDigi::GetPadPosition posX=" << posX
753  << " is out of bounds!";
754  // check limits
755  if (fabs(posY) > fSizeY)
756  LOG(fatal) << "CbmTrdParModDigi::GetPadPosition posY=" << posY
757  << " is out of bounds!";
758 
759  padPos.SetXYZ(posX, posY, posZ);
760  padPosErr.SetXYZ(padsizex / 2., padsizey / 2., 0.);
761 }
762 
763 
764 //___________________________________________________________________________
765 void CbmTrdParModDigi::GetPadPosition(const Int_t padAddress,
766  TVector3& padPos,
767  TVector3& padPosErr) const {
772  // Double_t posX = 0;
773  // Double_t posY = 0;
774  // Double_t posZ = 0;
775 
776  Int_t sectorId = CbmTrdAddress::GetSectorId(padAddress);
777  Int_t rowId = CbmTrdAddress::GetRowId(padAddress);
778  Int_t columnId = CbmTrdAddress::GetColumnId(padAddress);
779 
780  return GetPadPosition(sectorId, rowId, columnId, padPos, padPosErr);
781 }
782 
783 //___________________________________________________________________________
784 void CbmTrdParModDigi::GetPadPosition(const Int_t padAddress,
785  bool isCbmTrdDigiAddress,
786  TVector3& padPos,
787  TVector3& padPosErr) const {
791  if (!isCbmTrdDigiAddress)
792  LOG(error) << "Trying to get a CbmTrd PadPosition from DigiAddress format "
793  "function without digiAddress format";
794 
795 
796  Int_t row = GetPadRow(padAddress);
797  Int_t col = GetPadColumn(padAddress);
798 
799  Int_t srow(-1);
800  Int_t sector = GetSectorRow(row, srow);
801 
802  return GetPadPosition(sector, col, srow, padPos, padPosErr);
803 }
804 
805 //___________________________________________________________________________
807  // Int_t moduleAddress,
808  Int_t sectorId,
809  Int_t columnId,
810  Int_t rowId,
811  TVector3& padPos,
812  TVector3& padSize) const {
819  // if (fModuleAddress != moduleAddress) {
820  // LOG(error) << "CbmTrdParModDigi::GetPosition This is wrong!";
821  // }
822 
823  // check limits
824  if ((sectorId < 0) || (sectorId > GetNofSectors() - 1))
825  LOG(fatal) << "CbmTrdParModDigi::GetPosition sectorId " << sectorId
826  << " of "
827  << GetNofSectors()
828  - 1 //<< " in moduleAddress " << moduleAddress
829  << " is out of bounds!";
830 
831  // check limits
832  if ((columnId < 0) || (columnId > GetNofColumnsInSector(sectorId) - 1))
833  LOG(fatal) << "CbmTrdParModDigi::GetPosition columnId " << columnId
834  << " of "
835  << GetNofColumnsInSector(sectorId) - 1
836  //<< " in moduleAddress " << moduleAddress
837  << " is out of bounds!";
838 
839  // check limits
840  if ((rowId < 0) || (rowId > GetNofRowsInSector(sectorId) - 1))
841  LOG(fatal) << "CbmTrdParModDigi::GetPosition rowId " << rowId << " of "
842  << GetNofRowsInSector(sectorId) - 1
843  //<< " in moduleAddress " << moduleAddress
844  << " is out of bounds!";
845 
846  Double_t local_point[3];
847  Double_t padsizex = fPadSizeX.At(sectorId);
848  Double_t padsizey = fPadSizeY.At(sectorId);
849 
850  // calculate position in sector coordinate system
851  // with the origin in the lower left corner (looking upstream)
852  local_point[0] = (((Double_t) columnId + 0.5) * padsizex);
853  local_point[1] = (((Double_t) rowId + 0.5) * padsizey);
854 
855  // calculate position in module coordinate system
856  // with the origin in the lower left corner (looking upstream)
857  local_point[0] += fSectorBeginX.GetAt(sectorId);
858  local_point[1] += fSectorBeginY.GetAt(sectorId);
859  // local_point[i] must be >= 0 at this point
860 
861  // check limits
862  if ((local_point[0] < 0) || (local_point[0] > 2 * fSizeX))
863  LOG(fatal) << "CbmTrdParModDigi::GetPosition local_point[0]="
864  << local_point[0]
865  //<< " in moduleAddress " << moduleAddress
866  << " is out of bounds!";
867  // check limits
868  if ((local_point[1] < 0) || (local_point[1] > 2 * fSizeY))
869  LOG(fatal) << "CbmTrdParModDigi::GetPosition local_point[1]="
870  << local_point[1]
871  //<< " in moduleAddress " << moduleAddress
872  << " is out of bounds!";
873 
874  // calculate position in the module coordinate system
875  // with origin in the middle of the module
876  local_point[0] -= fSizeX;
877  local_point[1] -= fSizeY;
878  local_point[2] = fSizeZ;
879 
880  // navigate to the correct module. (fX,fY,fZ)
881  gGeoManager->FindNode(fX, fY, fZ);
882 
883  // get the local point in local MC coordinates from
884  // the geomanager. This coordinate system is rotated,
885  // if the chamber is rotated. This is corrected in
886  // GetModuleInformation to have the same
887  // local coordinate system in all the chambers
888  Double_t global_point[3]; // global_point[3];
889  gGeoManager->LocalToMaster(local_point, global_point);
890 
891  // calculate the position in the global coordinate system
892  // with the origin in target
893  Double_t posX = global_point[0];
894  Double_t posY = global_point[1];
895  Double_t posZ = global_point[2];
896 
897  padPos.SetXYZ(posX, posY, posZ);
898  padSize.SetXYZ(padsizex, padsizey, 0.);
899 }
900 
901 //___________________________________________________________________________
902 Int_t CbmTrdParModDigi::GetPadColumn(const Int_t channelNumber) const {
903  // calculate the pad column based on
904  // the channeNumber as defined in the
905  // CbmTrdDigi
906 
907  Int_t ncols = GetNofColumns();
908  Int_t col = channelNumber % ncols;
909 
910  return col;
911 }
912 
913 //___________________________________________________________________________
914 Int_t CbmTrdParModDigi::GetPadRow(const Int_t channelNumber) const {
915  // calculate the pad row based on
916  // the channeNumber as defined in the
917  // CbmTrdDigi
918 
919  Int_t ncols = GetNofColumns();
920  Int_t row = channelNumber / ncols;
921 
922  return row;
923 }
924 
925 
CbmTrdParModDigi::ProjectPositionToNextAnodeWire
void ProjectPositionToNextAnodeWire(Double_t *local_point) const
Definition: CbmTrdParModDigi.cxx:190
CbmTrdPoint::GetYOut
Double_t GetYOut() const
Definition: CbmTrdPoint.h:67
CbmTrdPoint::GetZIn
Double_t GetZIn() const
Definition: CbmTrdPoint.h:65
CbmTrdAddress.h
Helper class to convert unique channel ID back and forth.
CbmTrdParModDigi::fSectorSizeY
TArrayD fSectorSizeY
sector size in y [cm]
Definition: CbmTrdParModDigi.h:172
CbmTrdParModDigi::GetNofRowsInSector
Int_t GetNofRowsInSector(Int_t i) const
Definition: CbmTrdParModDigi.cxx:366
CbmTrdParModDigi::TransformHitError
void TransformHitError(TVector3 &hitErr) const
Definition: CbmTrdParModDigi.cxx:676
CbmTrdParModDigi::GetNofRows
Int_t GetNofRows() const
Definition: CbmTrdParModDigi.cxx:340
CbmTrdParModDigi::GetNofColumnsInSector
Int_t GetNofColumnsInSector(Int_t i) const
Definition: CbmTrdParModDigi.cxx:359
CbmTrdAddress::GetSectorId
static UInt_t GetSectorId(UInt_t address)
Return sector ID from address.
Definition: CbmTrdAddress.h:88
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmTrdPoint::GetXOut
Double_t GetXOut() const
Definition: CbmTrdPoint.h:66
CbmTrdAddress::GetLayerId
static UInt_t GetLayerId(UInt_t address)
Return layer ID from address.
Definition: CbmTrdAddress.h:69
CbmTrdAddress::GetModuleId
static UInt_t GetModuleId(UInt_t address)
Return module ID from address.
Definition: CbmTrdAddress.h:78
CbmTrdParModDigi::fSizeZ
Double_t fSizeZ
module half size in z [cm]
Definition: CbmTrdParModDigi.h:163
CbmTrdParModDigi::GetModuleInformation
void GetModuleInformation(const Double_t *local_point, Int_t &sectorId, Int_t &columnId, Int_t &rowId) const
Definition: CbmTrdParModDigi.cxx:695
CbmTrdParModDigi::fAnodeWireToPadPlaneDistance
Double_t fAnodeWireToPadPlaneDistance
Anode Wire to PadPlane Distance [cm].
Definition: CbmTrdParModDigi.h:156
CbmTrdParModDigi::fY
Double_t fY
center of module in global c.s. [cm]
Definition: CbmTrdParModDigi.h:159
CbmTrdParModDigi::fSizeY
Double_t fSizeY
module half size in y [cm]
Definition: CbmTrdParModDigi.h:162
CbmTrdParModDigi::GetPadInfo
Bool_t GetPadInfo(const Double_t *local_point, Int_t &sectorId, Int_t &columnId, Int_t &rowId) const
Definition: CbmTrdParModDigi.cxx:436
CbmTrdParModDigi::fPadSizeY
TArrayD fPadSizeY
size of the readout pad in y [cm]
Definition: CbmTrdParModDigi.h:175
CbmTrdParModDigi::GetPadRow
Int_t GetPadRow(const Int_t channelNumber) const
Definition: CbmTrdParModDigi.cxx:914
CbmTrdParModDigi::fSectorEndX
TArrayD fSectorEndX
end of sector [cm]
Definition: CbmTrdParModDigi.h:169
CbmTrdParModDigi::fSectorSizeX
TArrayD fSectorSizeX
sector size in x [cm]
Definition: CbmTrdParModDigi.h:171
CbmTrdParModDigi::fSizeX
Double_t fSizeX
module half size in x [cm]
Definition: CbmTrdParModDigi.h:161
CbmTrdParModDigi::GetSector
Int_t GetSector(Int_t npady, Int_t &rowId) const
Definition: CbmTrdParModDigi.cxx:274
CbmTrdParModDigi::CbmTrdParModDigi
CbmTrdParModDigi()
Definition: CbmTrdParModDigi.cxx:18
CbmTrdParModDigi::GetNofSectors
Int_t GetNofSectors() const
Definition: CbmTrdParModDigi.h:49
CbmTrdParModDigi
Definition of chamber gain conversion for one TRD module.
Definition: CbmTrdParModDigi.h:14
CbmTrdParModDigi.h
CbmTrdParMod
Definition of generic parameters for one TRD module.
Definition: CbmTrdParMod.h:9
CbmTrdParModDigi::GetPadPosition
void GetPadPosition(const Int_t sector, const Int_t col, const Int_t row, TVector3 &padPos, TVector3 &padPosErr) const
Definition: CbmTrdParModDigi.cxx:718
CbmTrdParModDigi::fSectorBeginX
TArrayD fSectorBeginX
begin of sector [cm]
Definition: CbmTrdParModDigi.h:167
ClassImp
ClassImp(CbmConverterManager) InitStatus CbmConverterManager
Definition: CbmConverterManager.cxx:12
CbmTrdParModDigi::fAnodeWireSpacing
Double_t fAnodeWireSpacing
anode wire pitch [cm]
Definition: CbmTrdParModDigi.h:154
CbmTrdParModDigi::fSectorX
TArrayD fSectorX
center of sectors local c.s. [cm]
Definition: CbmTrdParModDigi.h:164
CbmTrdParModDigi::TransformToLocalCorner
void TransformToLocalCorner(const Double_t *local_point, Double_t &posX, Double_t &posY) const
Definition: CbmTrdParModDigi.cxx:596
CbmTrdPoint::GetZOut
Double_t GetZOut() const
Definition: CbmTrdPoint.h:68
CbmTrdPoint
Definition: CbmTrdPoint.h:23
CbmTrdParModDigi::TransformToLocalPad
void TransformToLocalPad(const Double_t *local_point, Double_t &posX, Double_t &posY) const
Definition: CbmTrdParModDigi.cxx:634
CbmTrdParModDigi::GetPosition
void GetPosition(Int_t sectorId, Int_t columnId, Int_t rowId, TVector3 &padPos, TVector3 &padSize) const
Definition: CbmTrdParModDigi.cxx:806
CbmTrdParModDigi::GetPadColumn
Int_t GetPadColumn(const Int_t channelNumber) const
Definition: CbmTrdParModDigi.cxx:902
CbmTrdParModDigi::fAnodeWireOffset
Double_t fAnodeWireOffset
Anode Wire Offset [cm].
Definition: CbmTrdParModDigi.h:153
CbmTrdPoint::GetXIn
Double_t GetXIn() const
Definition: CbmTrdPoint.h:63
CbmTrdParModDigi::fOrientation
Int_t fOrientation
Definition: CbmTrdParModDigi.h:151
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmTrdParModDigi::fX
Double_t fX
center of module in global c.s. [cm]
Definition: CbmTrdParModDigi.h:158
fabs
friend F32vec4 fabs(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:60
CbmTrdParModDigi::fSectorY
TArrayD fSectorY
center of sectors local c.s. [cm]
Definition: CbmTrdParModDigi.h:165
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68
CbmTrdPoint.h
CbmTrdParModDigi::fPadSizeX
TArrayD fPadSizeX
size of the readout pad in x [cm]
Definition: CbmTrdParModDigi.h:174
CbmTrdParModDigi::fSectorEndY
TArrayD fSectorEndY
end of sector [cm]
Definition: CbmTrdParModDigi.h:170
CbmTrdParModDigi::GetModuleRow
Int_t GetModuleRow(Int_t &sectorId, Int_t &rowId) const
Definition: CbmTrdParModDigi.cxx:373
CbmTrdParModDigi::Print
void Print(Option_t *opt="") const
Definition: CbmTrdParModDigi.cxx:147
CbmTrdParModDigi::fSectorZ
TArrayD fSectorZ
center of sectors local c.s. [cm]
Definition: CbmTrdParModDigi.h:166
CbmTrdParModDigi::fNofSectors
Int_t fNofSectors
number sectors for this module
Definition: CbmTrdParModDigi.h:149
CbmTrdParModDigi::fSectorBeginY
TArrayD fSectorBeginY
begin of sector [cm]
Definition: CbmTrdParModDigi.h:168
CbmTrdPoint::GetYIn
Double_t GetYIn() const
Definition: CbmTrdPoint.h:64
CbmTrdParModDigi::GetSectorRow
Int_t GetSectorRow(Int_t growId, Int_t &srowId) const
Find the sector wise row given the module row. Inverse of GetModuleRow()
Definition: CbmTrdParModDigi.cxx:411
CbmTrdParModDigi::fZ
Double_t fZ
center of module in global c.s. [cm]
Definition: CbmTrdParModDigi.h:160
CbmTrdParModDigi::TransformToLocalSector
void TransformToLocalSector(const Double_t *local_point, Double_t &posX, Double_t &posY) const
Definition: CbmTrdParModDigi.cxx:614
CbmTrdParMod::fModuleId
Int_t fModuleId
module id
Definition: CbmTrdParMod.h:20
CbmTrdParModDigi::GetNofColumns
Int_t GetNofColumns() const
Definition: CbmTrdParModDigi.cxx:321
CbmTrdAddress::GetRowId
static UInt_t GetRowId(UInt_t address)
Return row ID from address.
Definition: CbmTrdAddress.h:98
CbmTrdAddress::GetColumnId
static UInt_t GetColumnId(UInt_t address)
Return column ID from address.
Definition: CbmTrdAddress.h:107