source: JEM-EUSO/esaf_lal/tags/v1_r0/esaf/packages/simulation/detector/electronics/src/MacroCellGeometry.cc @ 117

Last change on this file since 117 was 117, checked in by moretto, 11 years ago

ESAF version compilable on mac OS

File size: 4.7 KB
Line 
1// class MacroCellGeometry
2// $Id: MacroCellGeometry.cc 2850 2010-11-11 12:01:39Z biktem $
3// description of the geometry of a MacroCell
4//
5
6#include "MacroCellGeometry.hh"
7#include "PmtGeometry.hh"
8#include "OpticalAdaptor.hh"
9#include "MacroCell.hh"
10#include "ElementaryCell.hh"
11#include <iostream>
12
13using namespace sou;
14using namespace std;
15
16ClassImp(MacroCellGeometry)
17
18//______________________________________________________________________________
19MacroCellGeometry::MacroCellGeometry( MacroCell *parent) : pCell(parent) {
20    //
21    // ctor
22    //
23}
24
25//______________________________________________________________________________
26MacroCellGeometry::~MacroCellGeometry() {
27    //
28    // dtor
29    //
30}
31
32//#define DEBUG
33//______________________________________________________________________________
34Double_t MacroCellGeometry::IsHit(const Photon &p) const {
35    //
36    //
37    //
38
39    // check if p is // to the MC plane
40    if ( p.dir*GetNormal() > -TOLERANCE ) {
41        return -1;
42    }
43    EVector dummy=p.pos-GetCenter();
44    EVector intPoint=dummy-p.dir*((dummy*GetNormal())/(p.dir*GetNormal()));
45
46    if ( intPoint*fXAxis < fXMax && intPoint*fXAxis > fXMin &&
47         intPoint*fYAxis < fYMax && intPoint*fYAxis > fYMin ){
48
49#ifdef DEBUG
50        cout << "\nMacroCellGeometry::IsHit\n"
51             << "p.pos = " << p.pos << "   p.dir = " << p.dir << endl;
52        cout << "fCenter = " << GetCenter() << "   GetNormal() = " << GetNormal() << endl;
53        cout << "fXAxis = " << fXAxis << "   fYAxis = " << fYAxis << endl;
54
55        cout << "fXMax = " << fXMax << "   fXMin = " << fXMin
56             << "   fYMax = " << fYMax << "   fYMin = " << fYMin << endl;
57        cout << "intPoint = " << intPoint+GetCenter()<< "   intPoint*fXAxis = " << intPoint*fXAxis << "   intPoint*fYAxis = " << intPoint*fYAxis << endl;
58        cout << "DL = " << (intPoint-dummy).Mag() << endl;
59#endif /* DEBUG */
60
61        //printf("%g %g %g dist=%g\n", intPoint.X(),intPoint.Y(),intPoint.Z(),(intPoint-dummy).Mag());
62        return (intPoint-dummy).Mag();
63    }
64    return -1;
65
66}
67
68//______________________________________________________________________________
69Photomultiplier* MacroCellGeometry::FindHitPmt(const Photon &p) const{
70    //
71    // finds which pmt has been hit, if exists
72    //
73    const vector<Photomultiplier*> &PMTs=*(pCell->Pmts());
74
75    Photomultiplier *HitPMT=NULL;
76    for(size_t j=0; j<PMTs.size(); j++) {
77        // bring p on pmt cathode
78
79        Double_t DL = PMTs[j]->Geometry()->GetOA()->IsHit(p);
80
81        if( DL > 0.) {
82                HitPMT=PMTs[j];
83                break;
84        }
85    }
86    return HitPMT;
87}
88
89//______________________________________________________________________________
90void MacroCellGeometry::Compute() {
91    //
92    // Compute internal infos
93    //
94
95    if ( !Cell() ) {
96        FatalError("Invalid MacroCell pointer in MacroCellGeometry");
97    }
98
99    // number of elementary cells
100    Int_t nECs = Cell()->ECs()->size();
101    EVector n(0.,0.,0.), y_axis(0., 0., 0.);
102
103    // compute normal vector and the y axis
104    for(Int_t i=0; i<nECs; i++) {
105       const ElementaryCell *pEC = Cell()->GetEC(i);
106       if ( pEC ) {
107           n += pEC->GetNormal();
108           y_axis += pEC->GetYAxis();
109       } else {
110           FatalError("Invalid Elementary Cell in MacroCellGeometry");
111       }
112    }
113
114    fNormal = n.Unit();
115    fXAxis = (y_axis.Cross( n )).Unit();
116    fYAxis = fNormal.Cross( fXAxis );
117
118    // compute center
119    EVector center(0.,0.,0.);
120    for(Int_t i=0; i < nECs; i++) {
121        ElementaryCell *ec = Cell()->GetEC(i);
122        center += ec->GetCenter();
123    }
124    center *= (1./(double)Cell()->GetNumECs());
125
126    // compute corners and radius
127    for(Int_t i=0; i < nECs; i++) {
128        EVector d = Cell()->GetEC(i)->GetCenter() - center;
129        // d projection on the MC plane
130        if ( !i ){
131            fXMin = d.Dot(fXAxis);
132            fXMax = d.Dot(fXAxis);
133            fYMin = d.Dot(fYAxis);
134            fYMax = d.Dot(fYAxis);
135        } else {
136            if ( d.Dot(fXAxis) < fXMin ) fXMin = d.Dot(fXAxis);
137            if ( d.Dot(fXAxis) > fXMax ) fXMax = d.Dot(fXAxis);
138            if ( d.Dot(fYAxis) < fYMin ) fYMin = d.Dot(fYAxis);
139            if ( d.Dot(fYAxis) > fYMax ) fYMax = d.Dot(fYAxis);
140        }
141    }
142
143
144    // shift center of 50 mm along normal to keep the square in front of the macrocell
145    fCenter = center + 50. * fNormal.Unit()*mm;
146
147    // shift points out by two full PMT sides
148    fXMin-=2. * Cell()->GetEC(0)->GetPmt(1)->Geometry()->Side();
149    fXMax+=2. * Cell()->GetEC(0)->GetPmt(1)->Geometry()->Side();
150    fYMin-=2. * Cell()->GetEC(0)->GetPmt(1)->Geometry()->Side();
151    fYMax+=2. * Cell()->GetEC(0)->GetPmt(1)->Geometry()->Side();
152
153
154}
155
156void MacroCellGeometry::Draw() const{
157//FIXME: to be done (call EC->Draw)
158}
Note: See TracBrowser for help on using the repository browser.