FairRoot/PandaRoot
PndDiscNoiseGeneration.cxx
Go to the documentation of this file.
1 //------------------------------------------------------------------------
2 // Author: Oliver Merle (Oliver.Merle@exp2.physik.uni-giessen.de)
3 // Changes: Mustafa Schmidt (Mustafa.A.Schmidt@physik.uni-giessen.de)
4 // Date: 30.11.2015
5 // Description: Class to emulate noise for the readout electronics
6 //------------------------------------------------------------------------
7 
9 #include "PndDiscDigitizedHit.h"
10 
11 
12 #include "TString.h"
13 
14 
15 #include "TGeoManager.h"
16 #include "TRandom.h"
17 
18 
19 #include <cstdlib>
20 
21 
22 
24  : current_index(0), n_detectors(0), n_readout_modules(0), n_sensors(0),
25  n_sensor_tiles_x(1), n_sensor_tiles_y(1),
26  half_sensor_width(1.0), half_sensor_height(1.0),
27  n_pixel_x(1), n_pixel_y(1), pitch_x(1.0), pitch_y(1.0),
28  dcr_per_pixel(0.0)
29 {
30  noise_digits = new TClonesArray("PndDiscDigitizedHit");
31 }
32 
33 
35  if(noise_digits != NULL) delete noise_digits;
36 }
37 
38 
39 void PndDiscNoiseGeneration::SetNumberOfSensors(int n_detectors_, int n_readout_modules_, int n_sensors_) {
40  // note: a sensor can also be tiled - this is actually the sensitive area at a focusing element.
41  n_detectors = n_detectors_;
42  n_readout_modules = n_readout_modules_;
43  n_sensors = n_sensors_;
44 }
45 
46 
47 void PndDiscNoiseGeneration::SetSensorGrid( double sensor_width_, double sensor_height_,
48  int n_pixel_x_, int n_pixel_y_)
49 {
50  half_sensor_width = 0.5*sensor_width_;
51  half_sensor_height = 0.5*sensor_height_;
52  n_pixel_x = n_pixel_x_;
53  n_pixel_y = n_pixel_y_;
54 
55  pitch_x = sensor_width_ / double(n_pixel_x);
56  pitch_y = sensor_height_ / double(n_pixel_y);
57 
59 
60 }
61 
62 
63 void PndDiscNoiseGeneration::SetSensorTiling(int sensor_tiles_x, int sensor_tiles_y) {
64  n_sensor_tiles_x = sensor_tiles_x;
65  n_sensor_tiles_y = sensor_tiles_y;
66 }
67 
68 
69 bool PndDiscNoiseGeneration::GetPixelPosition(int n_pixel, double & pos_x, double & pos_y) {
70  if(n_pixel >= n_pixel_total) return false;
71  pos_x = -half_sensor_width + (double(n_pixel % n_pixel_x)+0.5) * pitch_x;
72  pos_y = -half_sensor_height + (double(n_pixel / n_pixel_x)+0.5) * pitch_y;
73  return true;
74 }
75 
76 
77 int PndDiscNoiseGeneration::GenerateNoise(double t_start_ns, double t_end_ns) {
78  Clear(); // clear buffer and reset the counter
79 
80  // fill buffer with new noise digits
81  double n_hits_avg = dcr_per_pixel * (t_end_ns - t_start_ns); // average number of hits in time window
82 
83  // compute the tile pitch
84  double tile_pitch_x = half_sensor_width *2.0 / double(n_sensor_tiles_x);
85  double tile_pitch_y = half_sensor_height*2.0 / double(n_sensor_tiles_y);
86 
87  // loop over all sensors:
88  int n_pixel, n_hits, hit, n_total_hits = 0;
89  int sensor_nx, sensor_ny, detector_id, readout_id, sensor_id, sensor_vid;
90  double hit_time, pos_x, pos_y;
91 
92  for(detector_id=0; detector_id<n_detectors; detector_id++) {
93  for(readout_id=0; readout_id < n_readout_modules; readout_id++) {
94  for(sensor_vid=0; sensor_vid<n_sensors; sensor_vid++) {
95  // loop over all pixels of the sensor:
96  for(n_pixel=0; GetPixelPosition(n_pixel, pos_x, pos_y); n_pixel++) {
97  // compute the sensor identifier (tile grouping for dead time handling):
98  sensor_nx = (int)(pos_x + half_sensor_width)/tile_pitch_x;
99  sensor_ny = (int)(pos_y + half_sensor_height)/tile_pitch_y;
100  //sensor_nx = (pos_x < 0 ? 0 : 1);
101  //sensor_ny = (pos_y < 0 ? 0 : 1);
102  sensor_id = sensor_vid*(n_sensor_tiles_x*n_sensor_tiles_y) + sensor_ny*(n_sensor_tiles_x) + sensor_nx + 1;
103 
104  // compute number of hits and distribute these in the time window:
105  n_hits = gRandom->Poisson(n_hits_avg); // hits on this pixel in the given time window
106  for(hit=0; hit < n_hits; hit++) {
107  hit_time = gRandom->Uniform(t_start_ns, t_end_ns);
108  // store noise hit:
109  new ((*noise_digits)[n_total_hits++]) PndDiscDigitizedHit(FairLink(), detector_id, readout_id, sensor_id, sensor_id, n_pixel/n_pixel_x, pos_y, hit_time, hit_time, 1);
110  }
111  }
112  }
113  }
114  }
115  return noise_digits->GetEntries();
116 }
117 
118 
120  if(current_index < noise_digits->GetEntries())
121  return (PndDiscDigitizedHit*)(*noise_digits)[current_index++];
122  else
123  return NULL;
124 }
125 
126 
128  noise_digits->Clear();
129  current_index = 0;
130 }
131 
132 
133 
135 
void SetSensorTiling(int sensor_tiles_x, int sensor_tiles_y)
Set a logical tiling (used for dead time handling)
int n_sensor_tiles_x
number of sensor tiles = number of dies
int n_readout_modules
number of readout modules on a detector
void SetSensorGrid(double sensor_width_, double sensor_height_, int n_pixel_x_, int n_pixel_y_)
Set the pixel grid on the sensors.
void SetNumberOfSensors(int n_detectors_, int n_readout_modules_, int n_sensors_)
Set the number of sensors for the whole apparatus.
TClonesArray * noise_digits
Memory pool to store the digits.
bool GetPixelPosition(int n_pixel, double &pos_x, double &pos_y)
int n_sensor_tiles_y
number of sensor tiles = number of dies
int n_sensors
number of sensors (untiled) at a readout module
cout<<"will loop over "<< t-> GetEntries()
Definition: root2ascii.C:17
PndDiscDigitizedHit * GetNextNoiseDigit()
Iterate over all generated hits.
int n_detectors
number of detectors
void Clear()
Clears the digit buffer.
ClassImp(PndAnaContFact)
PndSdsMCPoint * hit
Definition: anasim.C:70
int GenerateNoise(double t_start_ns, double t_end_ns)
Generate noise pattern in time window given by t_start, t_end.
int current_index
current index in pool (used in iteration)