|
| 1 | +#ifndef _SENSOR_H_ |
| 2 | +#define _SENSOR_H_ |
| 3 | + |
| 4 | +#include <vector> |
| 5 | +#include <time.h> |
| 6 | +#include <TRandom3.h> |
| 7 | +#include <cmath> |
| 8 | +#include <cstdlib> |
| 9 | + |
| 10 | +#define RANDOM_SEED 42 |
| 11 | + |
| 12 | +typedef std::vector<double> digiV; |
| 13 | + |
| 14 | +extern inline int maxValue(int a, int b) { |
| 15 | + return a > b ? a : b; |
| 16 | +} |
| 17 | + |
| 18 | +// The following parameter determines how many tracks left and right the good one |
| 19 | +// will be generated to simulate the charge drift |
| 20 | +#define DRIFT_WING 1 // n left and n right |
| 21 | +#define N_TRACCE ((2*DRIFT_WING)+1) |
| 22 | + |
| 23 | +class Sensor { |
| 24 | + public: |
| 25 | + enum { blockSharing, linearSharing, nSharing }; |
| 26 | + |
| 27 | + private: |
| 28 | + TRandom3 myDice; |
| 29 | + int trackHitElement_old(double impact, double theta, digiV &result); |
| 30 | + void trackHitElement_old2(double& x, double& y, double theta, double& prevCharge, double& thisCharge, double& nextCharge); |
| 31 | + void trackHitElement(double& x, double& y, double theta, double& prevCharge, double& thisCharge, double& nextCharge); |
| 32 | + double wallHit(double x, double y, double theta, double width, double height, double& x1, double& y1); |
| 33 | + double landau(double mpv); |
| 34 | + double stripNoise(); |
| 35 | + digiV myDigis_; |
| 36 | + double pitch_; |
| 37 | + double chargeDensity_; |
| 38 | + double saturation_; |
| 39 | + int adcBits_; |
| 40 | + double driftZone_; |
| 41 | + double transverseDrift_; |
| 42 | + double thickness_; |
| 43 | + double eta_; |
| 44 | + double etaZs_; |
| 45 | + double seed_cut_; |
| 46 | + double neighbour_cut_; |
| 47 | + double total_cut_; |
| 48 | + double noise_rms_; |
| 49 | + double xTalk_l_; |
| 50 | + double xTalk_c_; |
| 51 | + double xTalk_r_; |
| 52 | + double rndmXTalk_l_; |
| 53 | + double rndmXTalk_c_; |
| 54 | + double rndmXTalk_r_; |
| 55 | + double binaryThreshold_; |
| 56 | + unsigned int sharingMethod_; |
| 57 | + |
| 58 | + // Landau with parameter expressed |
| 59 | + // in units of MPV |
| 60 | + double landauWidth_; |
| 61 | + |
| 62 | + // Default parameters in the sensor simulation |
| 63 | + static const double defaultPitch = 80.; |
| 64 | + static const double defaultTransverseDrift = 0.; // Obsolete. do not use |
| 65 | + static const double defaultDriftZone = 10.; |
| 66 | + static const double defaultThickness = 200.; |
| 67 | + static const double defaultChargeDensity = 0.3; |
| 68 | + static const double defaultSaturation = 135; |
| 69 | + static const int defaultAdcBits = 4; |
| 70 | + static const double defaultNoiseRms = 4.; |
| 71 | + static const double defaultSeedCut = 4.; |
| 72 | + static const double defaultNeighbourCut = 3.; |
| 73 | + static const double defaultTotalCut = 5.; // Unused |
| 74 | + static const double defaultRndmXTalkL = 0.00; // Fraction of charge that can randomly cross talk between strips |
| 75 | + static const double defaultRndmXTalkC = 1.00; // Fraction of charge that can randomly cross talk between strips |
| 76 | + static const double defaultRndmXTalkR = 0.00; // Fraction of charge that can randomly cross talk between strips |
| 77 | + static const double defaultXTalkL = 0.10; // Cross talk between strips |
| 78 | + static const double defaultXTalkC = 0.80; // each strip shares 20% of its charge |
| 79 | + static const double defaultXTalkR = 0.10; // with the neighbours TODO: make this adjustable |
| 80 | + static const double defaultLandauWidth = 0.08; // width is MPV/12.5 |
| 81 | + static const double defaultBinaryThreshold = 16; // width is MPV/12.5 |
| 82 | + static const unsigned int defaultSharingMethod = linearSharing; // All charge released proportionally to the distance (within charge sharing zone) |
| 83 | + |
| 84 | + |
| 85 | + // Simulation parameters |
| 86 | + static const int cycle_gauss = 5; // Number of flat distributions used to simulate a Gaussian |
| 87 | + |
| 88 | + public: |
| 89 | + // Constructors and destructor |
| 90 | + ~Sensor(); |
| 91 | + Sensor(); |
| 92 | + Sensor(double thickness, double pitch, double chargeDensity, double transverseDrift); |
| 93 | + Sensor(double thickness, double pitch, double chargeDensity, double transverseDrift, double, double, double, double); |
| 94 | + |
| 95 | + |
| 96 | + // Creates digi correspondent to a specific angle/impact point |
| 97 | + int trackHit_old(double impact, double theta); // old: deprecated |
| 98 | + int trackHit(double impact, double theta); |
| 99 | + |
| 100 | + // pure binary cluster search |
| 101 | + bool binaryCluster(int& nStrip, int& clusterWidth, const bool& onlyLeading, double& baricenter, double& baricenter_ext, double& totalCharge); |
| 102 | + |
| 103 | + |
| 104 | + // Compute cluster on the present digi |
| 105 | + // it reports the number of strips involved and the total |
| 106 | + // (digitised) charge of the cluster |
| 107 | + void clusterize(int& nClus, int& totCharge); |
| 108 | + |
| 109 | + // Modifies the digi according to the cross-talk |
| 110 | + void crossTalk(); |
| 111 | + |
| 112 | + // Get the eta produced by the last clusterizing |
| 113 | + // Computed on raw data, or zero-suppressed |
| 114 | + double getEta(); |
| 115 | + double getEtaZs(); |
| 116 | + |
| 117 | + // Parameter get |
| 118 | + double getNoiseRms() { return noise_rms_; }; |
| 119 | + double getThickness() { return thickness_; }; |
| 120 | + double getPitch() { return pitch_; }; |
| 121 | + double getChargeDensity() { return chargeDensity_; }; |
| 122 | + double getSaturation() { return saturation_; }; |
| 123 | + int getAdcBits() { return adcBits_; }; |
| 124 | + double getTransverseDrift() { return transverseDrift_; }; // obsolete. do not use |
| 125 | + double getDriftZone() { return driftZone_*2; }; |
| 126 | + double getSeedCut() { return seed_cut_; }; |
| 127 | + double getNeighbourCut() { return neighbour_cut_; }; |
| 128 | + double getTotalCut() { return total_cut_; }; |
| 129 | + double getXTalk() { return (1-xTalk_c_); }; |
| 130 | + double getRndmXTalk() { return (1-rndmXTalk_c_); }; |
| 131 | + double getLandauWidth() { return landauWidth_; } |
| 132 | + double getBinaryThreshold() { return binaryThreshold_; } |
| 133 | + |
| 134 | + // Parameter set |
| 135 | + bool setSharingMethod(unsigned int newValue); |
| 136 | + void setNoiseRms(double newValue) { noise_rms_ = newValue; }; |
| 137 | + void setThickness(double newValue) { thickness_ = newValue; }; |
| 138 | + void setPitch(double newValue) { pitch_ = newValue; }; |
| 139 | + void setChargeDensity(double newValue) { chargeDensity_ = newValue; }; |
| 140 | + void setSaturation(double newValue) { saturation_ = newValue; }; |
| 141 | + void setAdcBits(int newValue) { adcBits_ = newValue; }; |
| 142 | + void setTransverseDrift(double newValue) { transverseDrift_ = newValue; }; // obsolete. do not use |
| 143 | + void setDriftZone(double newValue) { driftZone_ = newValue/2; }; |
| 144 | + void setSeedCut(double newValue) { seed_cut_ = newValue; }; |
| 145 | + void setNeighbourCut(double newValue) { neighbour_cut_ = newValue; }; |
| 146 | + void setTotalCut(double newValue) { total_cut_ = newValue; }; |
| 147 | + void setXTalk(double newValue) { |
| 148 | + if ((newValue>=0)&&(newValue<=1)) { |
| 149 | + xTalk_c_ = 1 - newValue; |
| 150 | + xTalk_r_ = newValue/2.; |
| 151 | + xTalk_l_ = newValue/2.; |
| 152 | + } |
| 153 | + } |
| 154 | + void setRndmXTalk(double newValue) { |
| 155 | + if ((newValue>=0)&&(newValue<=1)) { |
| 156 | + rndmXTalk_c_ = 1 - newValue; |
| 157 | + rndmXTalk_r_ = newValue/2.; |
| 158 | + rndmXTalk_l_ = newValue/2.; |
| 159 | + } |
| 160 | + } |
| 161 | + void setLandauWidth(double newValue) { landauWidth_ = newValue; } |
| 162 | + double setBinaryThreshold(const double& newValue ) { binaryThreshold_ = newValue; } |
| 163 | + void addNeighbourNoise(int nStrips); |
| 164 | + |
| 165 | + void printDigis() { |
| 166 | + for (int i=0; i<myDigis_.size(); ++i) std::cerr << myDigis_[i] <<", "; |
| 167 | + std::cerr << std::endl; |
| 168 | + } |
| 169 | +}; |
| 170 | + |
| 171 | + |
| 172 | + |
| 173 | +#endif |
0 commit comments