FairRoot/PandaRoot
PndSdsCalcPixelDif.cxx
Go to the documentation of this file.
1 #include "PndSdsCalcPixelDif.h"
2 #include "PndSdsPixelDigiPar.h"
3 #include <sstream>
4 #include <cmath>
5 #include "TRandom.h"
6 #include <map>
7 
9  fPixels(), fActivePixel(), fPixelSizeX(0.), fPixelSizeY(0.), fRows(0.), fCols(0.), fThreshold(0.), fNoise(
10  0.), fQspread(0.), fEnergy(0.), fVerboseLevel(0) {
11 }
12 
14  fPixels(), fActivePixel(), fPixelSizeX(digi_par.GetXPitch()), fPixelSizeY(digi_par.GetYPitch()), fRows(
15  digi_par.GetFERows() * digi_par.GetMaxFEperRow()), fCols(
16  digi_par.GetFECols() * digi_par.GetMaxFEperCol()), fThreshold(digi_par.GetThreshold()), fNoise(
17  digi_par.GetNoise()), fQspread(digi_par.GetQCloudSigma()), fEnergy(0.), fVerboseLevel(0) {
18 }
19 
21  fPixels(),
22  fActivePixel(),
23  fPixelSizeX(lx),
24  fPixelSizeY(ly),
25  fRows(nrows),
26  fCols(ncols),
27  fThreshold(threshold),
28  fNoise(noise),
29  fQspread(qspread),
30  fEnergy(0.),
31  fVerboseLevel(0)
32 {}
33 
35  Double_t energy, std::vector<Int_t>& cols, std::vector<Int_t>& rows,
36  std::vector<Double_t>& charges) {
37  std::vector<PndSdsPixel> pixels = GetPixels(inx, iny, outx, outy, energy);
38  Int_t npix = pixels.size();
39  for (Int_t i = 0; i < npix; i++) {
40  if (fVerboseLevel > 2) Info("PndSdsCalcPixelDif::GetPixelsAlternative()",
41  "pass this pixel: i=%i, c=%i, r=%i, q=%f", i, pixels[i].GetCol(), pixels[i].GetRow(),
42  pixels[i].GetCharge());
43  cols.push_back(pixels[i].GetCol());
44  rows.push_back(pixels[i].GetRow());
45  charges.push_back(pixels[i].GetCharge());
46  }
47  return npix;
48 }
49 
50 std::vector<PndSdsPixel> PndSdsCalcPixelDif::GetPixels(Double_t inx, Double_t iny, Double_t outx,
51  Double_t outy, Double_t dE) {
52  fPixels.clear();
53  if (0 >= fPixelSizeX || 0 >= fPixelSizeY) {
54  Error("PndSdsCalcPixelDif::GetPixels()", "Invalid Pixel sizes: fPixelSizeX=%g,fPixelSizeY=%g",
56  return fPixels;
57  }
58 
59  // determine box digis which can get charge
60  double max_charge_diffusion_distance(3.0 * fQspread);
61  double min_x(inx);
62  double max_x(outx);
63  if (outx < inx) {
64  min_x = outx;
65  max_x = inx;
66  }
67  double min_y(iny);
68  double max_y(outy);
69  if (outy < iny) {
70  min_y = outy;
71  max_y = iny;
72  }
73  min_x -= max_charge_diffusion_distance;
74  min_y -= max_charge_diffusion_distance;
75  max_x += max_charge_diffusion_distance;
76  max_y += max_charge_diffusion_distance;
77 
78  double track_dx = outx - inx;
79  double track_dy = outy - iny;
80  unsigned int cols(
81  ((unsigned int) std::fabs(max_x / fPixelSizeX)) - ((unsigned int) std::fabs(min_x / fPixelSizeX))
82  + 1);
83  unsigned int rows(
84  ((unsigned int) std::fabs(max_y / fPixelSizeY)) - ((unsigned int) std::fabs(min_y / fPixelSizeY))
85  + 1);
86  // we gain a lot of speed by using a fixed vector
87  // and using a fixed mapping between row+col and vector index
88  int start_col(min_x / fPixelSizeX);
89  int start_row(min_y / fPixelSizeY);
90  double difx = 0, dify = 0;
91  int row = 0, col = 0;
92  double t = 0;
93  std::vector<int> hitstorage(cols * rows, 0);
94  double Q = ChargeFromEloss(dE); // in electrons
95  unsigned int samples(Q); // sample amount (can be chosen independent of charge electrons Q)
96  // do hit&miss mc sampling, if we have more than 1 possible cell
97  if (hitstorage.size() == 1) {
98  InjectPixelCharge(start_col, start_row, Q);
99  }
100  else {
101  for (unsigned int i = 0; i < samples; ++i) {
102  t = gRandom->Rndm();
103  difx = gRandom->Gaus(0, fQspread);
104  dify = gRandom->Gaus(0, fQspread);
105  // if the electron diffused outside of the boundary just ignore it
106  if (std::abs(difx) > max_charge_diffusion_distance
107  || std::abs(dify) > max_charge_diffusion_distance) continue;
108  col = (inx + t * track_dx + difx) / fPixelSizeX;
109  row = (iny + t * track_dy + dify) / fPixelSizeY;
110  hitstorage[(row - start_row) * cols + (col - start_col)]++;
111  }
112  // distribute electrons based on the distribution from the hit&miss
113  for (unsigned int i = 0; i < hitstorage.size(); ++i) {
114  if (hitstorage[i] > 0) {
115  row = i / cols + start_row;
116  col = i % cols + start_col;
117  InjectPixelCharge(col, row, Q * hitstorage[i] / samples);
118  }
119  }
120  }
121  return fPixels;
122 }
123 
124 //______________________________________________________________________________
126  // cut if out of range
127  if (col < 0 || row < 0 || col > fCols || row > fRows) {
128  if (fVerboseLevel > 2) {
129  std::stringstream ss;
130  ss << " (col=" << col << ",row=" << row << " values exceed sensor boundaries: cols=[0-" << fCols
131  << "] rows=[0-" << fRows << "]";
132  Info("PndSdsCalcPixelDif::PndSdsCalcPixelDif::InjectPixelCharge:", ss.str().c_str());
133  }
134  }
135  Double_t smearedCharge = gRandom->Gaus(charge, fNoise);
136  if (fVerboseLevel > 3) std::cout << " charge = " << charge << ", smeared = " << smearedCharge
137  << std::endl;
138  if (smearedCharge > fThreshold) {
139  if (fVerboseLevel > 3) Info("PndSdsCalcPixelDif::InjectPixelCharge", "col=%i, row=%i,charge=%f", col,
140  row, charge);
141  fActivePixel.SetCol(col); // x axis
142  fActivePixel.SetRow(row); // y axis
143  fActivePixel.SetCharge(smearedCharge);
144  fPixels.push_back(fActivePixel); // fActivePixel content will be copied
145  }
146  return;
147 }
148 
149 //______________________________________________________________________________
151  out << "fPixelSizeX: " << fPixelSizeX << " fPixelSizeY: " << fPixelSizeY << std::endl;
152 
153  return out;
154 }
155 
int row
Definition: anaLmdDigi.C:67
std::vector< PndSdsPixel > GetPixels(Double_t inx, Double_t iny, Double_t outx, Double_t outy, Double_t energy)
Main function to calculate the vector of fired pixel.
Int_t GetPixelsAlternative(Double_t inx, Double_t iny, Double_t outx, Double_t outy, Double_t energy, std::vector< Int_t > &cols, std::vector< Int_t > &rows, std::vector< Double_t > &charges)
Int_t i
Definition: run_full.C:25
int col
Definition: anaLmdDigi.C:67
void SetCol(Int_t col)
Definition: PndSdsPixel.h:34
Double_t ChargeFromEloss(Double_t eloss) const
void SetCharge(Double_t charge)
Definition: PndSdsPixel.h:36
Double_t lx
Double_t
Double_t dE
Definition: anasim.C:58
int cols[10]
Definition: evaltrig.C:69
void SetRow(Int_t row)
Definition: PndSdsPixel.h:35
friend F32vec4 fabs(const F32vec4 &a)
Definition: P4_F32vec4.h:47
TFile * out
Definition: reco_muo.C:20
double threshold
Double_t ly
std::ostream & operator<<(std::ostream &out)
PndSdsCalcPixelDif()
Default constructor.
TTree * t
Definition: bump_analys.C:13
double noise
void InjectPixelCharge(Int_t col, Int_t row, Double_t charge)
std::vector< PndSdsPixel > fPixels
Double_t energy
Definition: plot_dirc.C:15
Digitization Parameter Class for SDS-Pixel part.