1  /* ======================================================================== *\


2  !


3  ! *


4  ! * This file is part of MARS, the MAGIC Analysis and Reconstruction


5  ! * Software. It is distributed to you in the hope that it can be a useful


6  ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.


7  ! * It is distributed WITHOUT ANY WARRANTY.


8  ! *


9  ! * Permission to use, copy, modify and distribute this software and its


10  ! * documentation for any purpose is hereby granted without fee,


11  ! * provided that the above copyright notice appear in all copies and


12  ! * that both that copyright notice and this permission notice appear


13  ! * in supporting documentation. It is provided "as is" without express


14  ! * or implied warranty.


15  ! *


16  !


17  !


18  ! Author(s): Thomas Bretz 03/2007 <mailto:tbretz@astro.uniwuerzburg.de>


19  ! Author(s): Michael Backes 03/2007 <mailto:michael.backes@udo.edu>


20  !


21  ! Copyright: MAGIC Software Development, 20002008


22  !


23  !


24  \* ======================================================================== */


25 


26  /////////////////////////////////////////////////////////////////////////////


27  //


28  // MGeomCamDwarf


29  //


30  // This class stores the geometry information of the Dwarf camera.


31  // MGeomCamDwarf cam; // Creates the 313 pixel dwarf camera


32  //


33  // It can also be used to create a hexagonal camera with identical sized


34  // pixels and n rings (while the central pixel is counted as ring 0).


35  // MGeomCamDwarf cam(9, 21); // Creates the CT3 camera


36  //


37  // Or it can be used to create a roundish camera, similar to a


38  // hexagonal camera, but the edges filled with additional pixels


39  // inside a circle.


40  // MGeomCamDwarf cam(209.5, 13.2);


41  //


42  ////////////////////////////////////////////////////////////////////////////


43  #include "MGeomCamDwarf.h"


44 


45  #include <TMath.h>


46 


47  #include "MGeomPix.h"


48 


49  ClassImp(MGeomCamDwarf);


50 


51  using namespace std;


52 


53  // 


54  //


55  // Dwarf camera has 313 pixels. For geometry and Next Neighbor info see


56  // CreateCam and CreateNN


57  //


58  MGeomCamDwarf::MGeomCamDwarf(const char *name)


59  : MGeomCam(CalcNumPix(9.5), 4.57, name, "Geometry information of Dwarf Camera")


60  {


61  CreateCam(21, 9.5);


62  InitGeometry();


63  }


64 


65  // 


66  //


67  // Use this to create a camera with a roundish shape and a radius rad in


68  // millimeter containing the pixel centers. The pixel will have a diameter


69  // diameter in millimeters, and a distance dist in meters.


70  //


71  MGeomCamDwarf::MGeomCamDwarf(Double_t rad, Double_t diameter, Double_t dist, const char *name)


72  : MGeomCam(CalcNumPix(diameter<=0 ? rad : rad/diameter), dist, name, "Geometry information for a roundish camera")


73  {


74  CreateCam(diameter, diameter<=0 ? rad : rad/diameter);


75  InitGeometry();


76  }


77 


78  // 


79  //


80  // Use this to create a camera with a hexagonal shape and rings rings.


81  // The first ring around the central pixel is 1. The pixel will have a


82  // diameter diameter in millimeters, and a distance dist in meters.


83  //


84  MGeomCamDwarf::MGeomCamDwarf(Int_t rings, Double_t diameter, Double_t dist, const char *name)


85  : MGeomCam(CalcNumPix(rings), dist, name, "Geometry information for a hexagonal camera")


86  {


87  CreateCam(diameter, rings);


88  InitGeometry();


89  }


90 


91  // 


92  //


93  // Check if the photon which is flying along the trajectory u has passed


94  // (or will pass) the frame of the camera (and consequently get


95  // absorbed). The position p and direction u must be in the


96  // telescope coordinate frame, which is z parallel to the focal plane,


97  // x to the right and y upwards, looking from the mirror towards the camera.


98  //


99  // The units are cm.


100  //


101  Bool_t MGeomCamDwarf::HitFrame(MQuaternion p, const MQuaternion &u) const


102  {


103  // Add 10% to the max radius and convert from mm to cm


104  // FIXME: Why does the compiler complain without this cast?


105  return static_cast<const MGeomCam*>(this)>HitFrame(p, u, GetMaxRadius()*0.11);


106  }


107 


108  // 


109  //


110  // Calculate in the direction 05 (kind of sector) in the ringth ring


111  // the x and y coordinate of the ith pixel. The units are unity,


112  // distance to (0,0) is retruned.


113  //


114  Int_t MGeomCamDwarf::CalcNumPix(Int_t rings)


115  {


116  //


117  // add the first pixel to the list


118  //


119  Int_t cnt = 1;


120 


121  for (Int_t ring=0; ring<rings; ring++)


122  cnt += 6*(ring+1);


123 


124  return cnt;


125  }


126 


127  // 


128  //


129  // Calculate in the direction 05 (kind of sector) in the ringth ring


130  // the x and y coordinate of the ith pixel. The unitx are unity,


131  // distance to (0,0) is retruned.


132  //


133  // Due to possible rounding errors we need to use exactly the same


134  // algorithm as for creating the pixels!


135  //


136  Int_t MGeomCamDwarf::CalcNumPix(Double_t rad)


137  {


138  const Double_t r2 = rad*rad;


139 


140  //


141  // add the first pixel to the list


142  //


143  Int_t cnt = 1;


144  Int_t ring = 1;


145  while (1)


146  {


147  Int_t n = 0;


148 


149  //


150  // calc. coords for this ring counting from the


151  // starting number to the ending number


152  //


153  for (Int_t dir=MGeomPix::kDirNE; dir<=MGeomPix::kDirSE; dir++)


154  {


155  for (int i=0; i<ring; i++)


156  {


157  Double_t x, y;


158  if (MGeomPix::CalcXY(dir, ring, i, x, y)<r2)


159  n++;


160  }


161  }


162 


163  if (n==0)


164  return cnt;


165 


166  ring++;


167  cnt += n;


168  }


169 


170  return cnt;


171  }


172 


173 


174  // 


175  //


176  // This fills the geometry information for a hexagonal camera


177  //


178  void MGeomCamDwarf::CreateCam(Double_t diameter, Int_t rings)


179  {


180  // units for diameter are mm


181 


182  //


183  // add the first pixel to the list


184  //


185  SetAt(0, MGeomPix(0, 0, diameter));


186 


187  Int_t cnt = 1;


188 


189  for (int ring=1; ring<=rings; ring++)


190  {


191  for (Int_t dir=MGeomPix::kDirNE; dir<=MGeomPix::kDirSE; dir++)


192  {


193  for (int i=0; i<ring; i++)


194  {


195  Double_t x, y;


196  MGeomPix::CalcXY(dir, ring, i, x, y);


197  SetAt(cnt++, MGeomPix(x*diameter, y*diameter, diameter));


198  }


199  }


200  }


201  }


202 


203  // 


204  //


205  // This fills the geometry information for a roundish camera


206  //


207  void MGeomCamDwarf::CreateCam(Double_t diameter, Double_t rad)


208  {


209  // units for diameter are mm


210 


211  const Double_t r2 = rad*rad;


212 


213  //


214  // add the first pixel to the list


215  //


216  SetAt(0, MGeomPix(0, 0, diameter));


217 


218  Int_t cnt = 1;


219  Int_t ring = 1;


220 


221  while (1)


222  {


223  Int_t n = 0;


224 


225  for (Int_t dir=MGeomPix::kDirNE; dir<=MGeomPix::kDirSE; dir++)


226  {


227  for (int i=0; i<ring; i++)


228  {


229  Double_t x, y;


230  if (MGeomPix::CalcXY(dir, ring, i, x, y)<r2)


231  SetAt(cnt+n++, MGeomPix(x*diameter, y*diameter, diameter));


232  }


233  }


234 


235  if (n==0)


236  return;


237 


238  ring++;


239  cnt += n;


240  }


241  }

