FairRoot/PandaRoot
PndHypCalcStrip.cxx
Go to the documentation of this file.
1 //
2 // C++ Implementation: MvdCalcStrip
3 //
4 // Description:
5 //
6 //
7 // Author: HG Zaunick <hg.zaunick@physik.tu-dresden.de>, (C) 2007
8 //
9 // Copyright: See COPYING file that comes with this distribution
10 // modified by A. Sanchez for Hyp detector
11 //
12 #include <cmath>
13 
14 #include "PndHypCalcStrip.h"
15 #include "TRandom3.h"
16 //#include "FairGeoVector.h"
17 
18 //static const int CH_PER_FE = 128;
19 
21  fPitch = 0.;
22  fOrient = 0.;
23  fAnchor = TVector2(0.,0.);
24  fNrStrips = 0;
25  fThreshold = 0.;
26  fNoise = 0.;
27  fVerboseLevel = 1;
28  fRNG = new TRandom3();
29 }
30 
32  Int_t nrStrips, Int_t nrFeChannels,
33  const TVector2& firstStripAnchor,
35  : fPitch(pitch), fOrient(orient),
36  fNrStrips(nrStrips), fNrFeChannels(nrFeChannels),
37  fThreshold(threshold), fNoise(noise),
38  fAnchor(firstStripAnchor)
39 {
42  fVerboseLevel = 1;
43  fRNG = new TRandom3();
44  //Print();
45 }
46 
48 {
49  if(side == kTOP)
50  {
51  fPitch = digipar->GetTopPitch();
52  fOrient = digipar->GetOrient();
53  fAnchor = digipar->GetTopAnchor();
54  fNrStrips = digipar->GetNrTopFE()*digipar->GetNrFECh();
55  }
56  else if(side == kBOTTOM)
57  {
58  fPitch = digipar->GetBotPitch();
59  fOrient = digipar->GetOrient() + digipar->GetSkew();
60  fAnchor = digipar->GetBotAnchor();
61  fNrStrips = digipar->GetNrBotFE()*digipar->GetNrFECh();
62  }
63  fNrFeChannels = digipar->GetNrFECh();
64  fThreshold = digipar->GetThreshold();
65  fNoise = digipar->GetNoise();
66 
69  fVerboseLevel = 1;
70  fRNG = new TRandom3();
71  //Print();
72 
73 }
74 
75 
76 std::vector<PndHypStrip>
78  Double_t outx, Double_t outy, Double_t ,
79  Double_t eLoss,int ) //inz outz id//[R.K.03/2017] unused variable(s)
80 {//1
81  if (fVerboseLevel > 2) std::cout<<"-I- PndHypCalcStrip::GetStrips "<<std::endl;
82 
83  // 2d-Projection of trajectory
84  //mvd local c.s(x,y);hyp local c.s(x-z);3.03.08 new hyp cs(xy)
85  TVector2 in(inx,iny);//TVector2 in(inx,inz);
86  TVector2 out(outx,outy);//TVector2 out(outx,outz);
87  TVector2 path=out-in;
88 
89  if (fVerboseLevel > 2){
90  std::cout<<" InPoint: ("<<in.X()<<","<<in.Y()<<std::endl;
91  std::cout<<" OutPoint: ("<<out.X()<<","<<out.Y()<<std::endl;
92  }
93 
94  std::vector<PndHypStrip> strips;
95  Double_t SmearedQ;
96 
97  if (path.Mod()<1E-18) {
98  std::cout<<"-W- PndHypCalcStrip::GetStrips : No Trajectory inside Sensor!"<<path.Mod()<<std::endl;
99  return strips;
100  }
101 
102  if (fVerboseLevel > 1) std::cout<<" pathlength: "<<path.Mod()<<std::endl;
103 
104  Double_t nuIn = CalcStripFromPoint(inx,iny);
105  Double_t nuOut = CalcStripFromPoint(outx,outy);
106 
107  if (fVerboseLevel > 2) std::cout<<" nuIn = "<<nuIn<<" ; nuOut = "<<nuOut<<std::endl;
108 
109  //Double_t dir = 0.;
110  //if (nuOut>nuIn) dir=1.;
111  //else dir = -1.;
112 
113  Double_t Q = ChargeFromEloss(eLoss);//*1E9/3.61; // 3.6 Electrons/eV in Silicon
114  if (fVerboseLevel > 1) std::cout<<" integral charge = "<<Q<<std::endl;
115 
116  // did we hit the active area ?
117  //if ( (nuIn<0.5 && nuOut<0.5) ||
118  // (((nuIn+0.5) >Double_t(fNrStrips-1)) && ((nuOut+0.5) > Double_t(fNrStrips-1))))
119 
120  if ( (nuIn<0. && nuOut<0.) || ((nuIn >Double_t(fNrStrips)) && (nuOut > Double_t(fNrStrips))))
121  {
122  if (fVerboseLevel > 1) std::cout<<" Hit outside active area."<<std::endl;
123  return strips;
124  }
125 
126  // is the In-Point inside active area ?// only charge fraction inside active area taken
127  if (nuIn<0.){
128  Q *= (nuOut)/(nuOut-nuIn);
129  nuIn = 0.;
130  } else if (nuIn > (Double_t(fNrStrips))){
131  Q *= ((Double_t)fNrStrips-nuOut)/(-nuOut+nuIn);
132  nuIn = Double_t(fNrStrips);
133  }
134 
135  // is the Out-Point inside active area ?
136  if (nuOut<0.){
137  Q *= (nuIn)/(-nuOut+nuIn);
138  nuOut = 0.;
139 
140  } else if (nuOut > (Double_t(fNrStrips))){
141  Q *= ((Double_t)fNrStrips-nuIn)/(nuOut-nuIn);
142  nuOut = Double_t(fNrStrips);
143  }
144 
145  // only one strip hit ?
146  if (Int_t(nuIn) == Int_t(nuOut))
147  {
148  // this strip collected the entire charge
149  SmearedQ = SmearCharge(Q);
150  if (SmearedQ >= fThreshold)strips.push_back(PndHypStrip(Int_t(nuOut),SmearedQ));
151 
152  if (fVerboseLevel > 1) std::cout<<" -> 1 strip hit."<<std::endl;
153  //return strips;
154  }
155  else {
156 
157  Int_t nrHits = 0;
158  Double_t dQ=Q/std::fabs(nuOut-nuIn);
159  Double_t dir = (nuOut>nuIn) ? 1. : -1.;
160  // calculate portion of track in first strip
161  Int_t nextIn = Int_t(nuIn + 0.5+0.5*dir);
162  Double_t Q1 = dQ*std::fabs(nextIn-nuIn);
163 
164  if (fVerboseLevel > 2)
165  {
166  std::cout<<" part of first strip : "<<nextIn-nuIn<<std::endl ;
167  std::cout<<" charge : "<<Q1<<std::endl ;
168  std::cout<<" next strip : "<<nextIn<<std::endl ;
169  }
170  SmearedQ = SmearCharge(Q1);
171  if (SmearedQ >= fThreshold)strips.push_back(PndHypStrip(Int_t(nuIn),SmearedQ));
172  nrHits++;
173  Q -= Q1;
174 
175 
176 
177  // calculate portion of track in last strip
178  Int_t prevOut = Int_t(nuOut + 0.5-0.5*dir);
179  Double_t Q2 = dQ*std::fabs(nuOut-prevOut);
180 
181  if (fVerboseLevel > 2){
182  std::cout<<" part of last strip : "<<(nuOut-prevOut)<<std::endl ;
183  std::cout<<" charge : "<<Q2<<std::endl ;
184  std::cout<<" end of previous strip : "<<prevOut<<std::endl ;
185  }
186  SmearedQ = SmearCharge(Q2);
187 
188  if (SmearedQ >= fThreshold)strips.push_back(PndHypStrip(Int_t(nuOut),SmearedQ));
189  nrHits++;
190  Q -= Q2;
191 
192 
193 
194  // Distribute the charge among the intermediate strips
195  nextIn = Int_t(nextIn - 0.5 + 0.5*dir);
196  prevOut = Int_t(prevOut - 0.5 + 0.5*dir);
197 
198 
199  if (fVerboseLevel > 2) {
200  std::cout<<" dir="<<Int_t((dir))<<std::endl;
201  std::cout<<" begin="<<nextIn<<" end="<<prevOut<<std::endl;
202  }
203 
204  for (Int_t n = nextIn ; n != prevOut; n += Int_t(dir) )
205  {
206 
207  if (fVerboseLevel > 2) std::cout<<" n = "<<n<<std::endl;
208  SmearedQ = SmearCharge(dQ);
209  if (SmearedQ >= fThreshold)strips.push_back(PndHypStrip(n,SmearedQ));
210  nrHits++;
211  Q -= dQ; //std::cout<<" loop over MORE strips : charge "<<Q<<" dQ "<<dQ<<std::endl;
212  }
213  if (fVerboseLevel > 2)if (fabs(Q)>1.) std::cout<<" charge Q = "<<Q<<" not detected!"<<std::endl;
214  if (fVerboseLevel > 1) std::cout<<" -> "<<nrHits<<" strips hit."<<std::endl;
215  }
216 
217 
218 
219  return strips;
220 }
221 
223 {
224  Double_t smeared = fRNG->Gaus(charge,fNoise);
225  if (fVerboseLevel > 2) std::cout<<" charge = "<<charge<<", smeared = "<<smeared<<std::endl;
226  return smeared;//fRNG->Gaus(charge,fNoise);//smeared;
227 }
228 
230  {
231  return ( (x-fAnchor.X())*fOrthoDir.Y()
232  -(y-fAnchor.Y())*fOrthoDir.X() )/fPitch;
233  //std::cout<<" nrstrip "
234  // <<( (x-fAnchor.X())*fStripDir.Y()-(y-fAnchor.Y())*fStripDir.X() )/fPitch<<std::endl;
235 
236  }
237 
238  Int_t PndHypCalcStrip::CalcFEfromStrip(Int_t stripNr) const{ return (stripNr/fNrFeChannels); }
239 
240  Int_t PndHypCalcStrip::CalcChannelfromStrip(Int_t stripNr) const{ return (stripNr%fNrFeChannels); }
241 
242  void PndHypCalcStrip::CalcFeChToStrip(Int_t fe, Int_t channel, Int_t& strip, enum SensorSide& side)const
243  {
244  Int_t nr = fe * fNrFeChannels + channel;
245  // if (nr > fNrStrips) {
246 // nr -= fNrStrips;
247 // side = kBOTTOM;
248 // } else side = kTOP;
249 
250  if (nr < fNrStrips) {
251  side = kTOP;
252  } else {
253  nr -= fNrStrips;
254  side = kBOTTOM;
255  }
256  strip = nr;
257  //std::cout<< "strip "<<strip<<"side "<<side<<" chan "<<channel<<std::endl;
258 
259  }
260 
261 
263 {
264  point = fAnchor + ( fPitch * (strip+0.5) * fOrthoDir ) ;
265 }
266 
267 
269 {
270  std::cout<<"-I- PndHypCalcStrip Info :"<<std::endl;
271  std::cout<<" Pitch = "<<fPitch*10000.<<" um"<<std::endl;
272  std::cout<<" Orientation = "<<fOrient/TMath::Pi()*180.<<" deg"<<std::endl;
273  std::cout<<" Nr Strips = "<<fNrStrips<<std::endl;
274  std::cout<<" nr of channels per FE = "<<fNrFeChannels<<std::endl;
275  std::cout<<" nr of frontends = "<<fNrStrips/fNrFeChannels<<std::endl;
276  std::cout<<" Anchor Point = "<<fAnchor.X()<<","<<fAnchor.Y()<<")"<<std::endl;
277  std::cout<<" Strip Vector = ("<<fStripDir.X()<<","<<fStripDir.Y()<<")"<<std::endl;
278 }
279 
Int_t fNrStrips
strip orientation angle
friend F32vec4 cos(const F32vec4 &a)
Definition: P4_F32vec4.h:112
Double_t GetSkew() const
TVector2 GetTopAnchor() const
Double_t GetNoise() const
Double_t GetBotPitch() const
Int_t CalcFEfromStrip(Int_t stripNr) const
Int_t GetNrFECh() const
friend F32vec4 sin(const F32vec4 &a)
Definition: P4_F32vec4.h:111
int n
void print() const
TVector2 GetBotAnchor() const
void CalcStripPointOnLine(const Double_t strip, TVector2 &point) const
int nrStrips
Definition: anaLmdDigi.C:76
Int_t CalcChannelfromStrip(Int_t stripNr) const
Double_t fNoise
charge threshold
TVector2 fOrthoDir
vector perpendicular to strip direction
Double_t ChargeFromEloss(Double_t eloss) const
int strip
Definition: anaMvdDigi.C:135
Double_t GetThreshold() const
TRandom3 * fRNG
vector orthogonal to strip direction
Double_t
int nrFeChannels
Definition: anaLmdDigi.C:75
std::vector< PndHypStrip > GetStrips(Double_t inx, Double_t iny, Double_t inz, Double_t outx, Double_t outy, Double_t outz, Double_t eLoss, int id)
SensorSide
Double_t SmearCharge(Double_t charge)
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
TFile * out
Definition: reco_muo.C:20
Int_t fNrFeChannels
Nr. of strips on active area.
double threshold
Double_t CalcStripFromPoint(Double_t x, Double_t y)
TVector2 fAnchor
ENC.
Int_t fVerboseLevel
Random Number Generator.
TVector2 fStripDir
anchor point on first strip
Double_t x
Int_t GetNrTopFE() const
Double_t fThreshold
Nr of Channels per FE.
int fe
Definition: anaLmdDigi.C:67
void CalcFeChToStrip(Int_t fe, Int_t channel, Int_t &strip, enum SensorSide &side) const
Double_t GetOrient() const
double orient
Double_t y
Double_t GetTopPitch() const
Double_t Pi
double noise
Double_t fOrient
strip pitch (cm)
Int_t GetNrBotFE() const
PndSdsMCPoint * point
Definition: anaLmdCluster.C:72