00001 #ifndef SiPixelDigitizerAlgorithm_h
00002 #define SiPixelDigitizerAlgorithm_h
00003
00004 #include <string>
00005 #include <map>
00006
00007 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00008 #include "DataFormats/SiPixelDigi/interface/PixelDigi.h"
00009 #include "DataFormats/SiPixelDigi/interface/PixelDigiCollection.h"
00010 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00011 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00012
00013
00014
00015
00016 #include "SimTracker/Common/interface/SiG4UniversalFluctuation.h"
00017 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00018 #include "DataFormats/DetId/interface/DetId.h"
00019 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00020 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
00021 #include "Geometry/CommonDetUnit/interface/GeomDetType.h"
00022
00023 #include "SimGeneral/NoiseGenerators/interface/GaussianTailNoiseGenerator.h"
00024
00025
00026 #include "SimDataFormats/TrackerDigiSimLink/interface/PixelDigiSimLink.h"
00027
00028 #include "DataFormats/Common/interface/DetSetVector.h"
00029
00030 #include "CondFormats/SiPixelObjects/interface/PixelIndices.h"
00031
00032
00033 #include "CondTools/SiPixel/interface/SiPixelGainCalibrationOfflineService.h"
00034
00035
00036 #include "CondFormats/SiPixelObjects/interface/SiPixelLorentzAngle.h"
00037 #include "CondFormats/DataRecord/interface/SiPixelLorentzAngleRcd.h"
00038
00039
00040
00041
00042
00043
00044
00045 namespace CLHEP {
00046 class RandGaussQ;
00047 class RandFlat;
00048 }
00049
00050 class SiPixelDigitizerAlgorithm {
00051 public:
00052
00053 SiPixelDigitizerAlgorithm(const edm::ParameterSet& conf);
00054 ~SiPixelDigitizerAlgorithm();
00055
00056
00057 edm::DetSet<PixelDigi>::collection_type
00058 run(const std::vector<PSimHit> &input,PixelGeomDetUnit *pixdet,GlobalVector);
00059
00060
00061 std::vector<PixelDigiSimLink> make_link() {
00062 return link_coll; }
00063 void init(const edm::EventSetup& es);
00064 void fillDeadModules(const edm::EventSetup& es);
00065 void fillLorentzAngle(const edm::EventSetup& es);
00066
00067 private:
00068
00069
00070 edm::ESHandle<SiPixelLorentzAngle> SiPixelLorentzAngle_;
00071
00072
00073
00074
00075
00076
00077 typedef std::vector<edm::ParameterSet> Parameters;
00078 Parameters DeadModules;
00079
00080
00081
00082
00083
00084 class CalParameters {
00085 public:
00086 float p0;
00087 float p1;
00088 float p2;
00089 float p3;
00090 };
00091
00092
00093
00097 class EnergyDepositUnit{
00098 public:
00099 EnergyDepositUnit(): _energy(0),_position(0,0,0){}
00100 EnergyDepositUnit(float energy,float x, float y, float z):
00101 _energy(energy),_position(x,y,z){}
00102 EnergyDepositUnit(float energy, Local3DPoint position):
00103 _energy(energy),_position(position){}
00104 float x() const{return _position.x();}
00105 float y() const{return _position.y();}
00106 float z() const{return _position.z();}
00107 float energy() const { return _energy;}
00108 private:
00109 float _energy;
00110 Local3DPoint _position;
00111 };
00112
00113
00114
00115
00120 class SignalPoint {
00121 public:
00122 SignalPoint() : _pos(0,0), _time(0), _amplitude(0),
00123 _sigma_x(1.), _sigma_y(1.), _hitp(0) {}
00124
00125 SignalPoint( float x, float y, float sigma_x, float sigma_y,
00126 float t, float a=1.0) :
00127 _pos(x,y), _time(t), _amplitude(a), _sigma_x(sigma_x),
00128 _sigma_y(sigma_y), _hitp(0) {}
00129
00130 SignalPoint( float x, float y, float sigma_x, float sigma_y,
00131 float t, const PSimHit& hit, float a=1.0) :
00132 _pos(x,y), _time(t), _amplitude(a), _sigma_x(sigma_x),
00133 _sigma_y(sigma_y),_hitp(&hit) {}
00134
00135 const LocalPoint& position() const { return _pos;}
00136 float x() const { return _pos.x();}
00137 float y() const { return _pos.y();}
00138 float sigma_x() const { return _sigma_x;}
00139 float sigma_y() const { return _sigma_y;}
00140 float time() const { return _time;}
00141 float amplitude() const { return _amplitude;}
00142 const PSimHit& hit() { return *_hitp;}
00143 SignalPoint& set_amplitude( float amp) { _amplitude = amp; return *this;}
00144
00145
00146
00147 private:
00148 LocalPoint _pos;
00149 float _time;
00150 float _amplitude;
00151 float _sigma_x;
00152 float _sigma_y;
00153 const PSimHit* _hitp;
00154 };
00155
00156
00157
00158
00163 class Amplitude {
00164 public:
00165 Amplitude() : _amp(0.0) { _hits.reserve(1);}
00166 Amplitude( float amp, const PSimHit* hitp, float frac) :
00167 _amp(amp), _hits(1, hitp), _frac(1,frac) {
00168
00169
00170 if (_frac[0]<-0.5) {
00171 _frac.pop_back();
00172 _hits.pop_back();
00173 }
00174 }
00175
00176
00177 operator float() const { return _amp;}
00178 float ampl() const {return _amp;}
00179 std::vector<float> individualampl() const {return _frac;}
00180 const std::vector<const PSimHit*>& hits() { return _hits;}
00181
00182 void operator+=( const Amplitude& other) {
00183 _amp += other._amp;
00184
00185
00186 if (other._frac[0]>-0.5){
00187 _hits.insert( _hits.end(), other._hits.begin(), other._hits.end());
00188 _frac.insert(_frac.end(), other._frac.begin(), other._frac.end());
00189 }
00190 }
00191
00192 void operator+=( const float& amp) {
00193 _amp += amp;
00194 }
00195
00196 void set (const float amplitude) {
00197 _amp = amplitude;
00198 }
00199
00200
00201
00202 private:
00203 float _amp;
00204 std::vector<const PSimHit*> _hits;
00205 std::vector<float> _frac;
00206 };
00207
00208
00209 private:
00210
00211
00212 typedef std::map< int, Amplitude, std::less<int> > signal_map_type;
00213 typedef signal_map_type::iterator signal_map_iterator;
00214 typedef std::map<unsigned int, std::vector<float>,std::less<unsigned int> >
00215 simlink_map;
00216 typedef GloballyPositioned<double> Frame;
00217
00218
00219 edm::ParameterSet conf_;
00220
00221
00222 int NumberOfSegments;
00223
00224 float GeVperElectron;
00225
00226
00227 float Sigma0;
00228 float Dist300;
00229 bool alpha2Order;
00230
00231
00232
00233
00234 float ClusterWidth;
00235
00236 float theElectronPerADC;
00237 int theAdcFullScale;
00238 float theNoiseInElectrons;
00239 float theReadoutNoise;
00240
00241 float thePixelThreshold;
00242
00243 float thePixelThresholdInE;
00244
00245 float theThresholdInE_FPix;
00246 float theThresholdInE_BPix;
00247
00248 double theThresholdSmearing_FPix;
00249 double theThresholdSmearing_BPix;
00250
00251 double electronsPerVCAL;
00252 double electronsPerVCAL_Offset;
00253
00254 float theTofLowerCut;
00255 float theTofUpperCut;
00256 float tanLorentzAnglePerTesla_FPix;
00257 float tanLorentzAnglePerTesla_BPix;
00258
00259
00260
00261
00262 bool addNoise;
00263 bool addNoisyPixels;
00264 bool fluctuateCharge;
00265 bool addPixelInefficiency;
00266
00267 bool pixelInefficiency;
00268 int thePixelLuminosity;
00269
00270 bool addThresholdSmearing;
00271
00272 int theColsInChip;
00273 int theRowsInChip;
00274
00275 int numColumns;
00276 int numRows;
00277 float moduleThickness;
00278
00279 const PixelGeomDetUnit* _detp;
00280 uint32_t detID;
00281
00282
00283 std::vector<PSimHit> _PixelHits;
00284 const PixelTopology* topol;
00285
00286 std::vector<PixelDigi> internal_coll;
00287
00288 std::vector<PixelDigiSimLink> link_coll;
00289 GlobalVector _bfield;
00290
00291 float PixelEff;
00292 float PixelColEff;
00293 float PixelChipEff;
00294 float PixelEfficiency;
00295 float PixelColEfficiency;
00296 float PixelChipEfficiency;
00297 float thePixelEfficiency[6];
00298 float thePixelColEfficiency[6];
00299 float thePixelChipEfficiency[6];
00300
00301
00302 bool doMissCalibrate;
00303 float theGainSmearing;
00304 float theOffsetSmearing;
00305
00306
00307
00308
00309
00310
00311
00312 double tMax;
00313
00314
00315 SiG4UniversalFluctuation * fluctuate;
00316 GaussianTailNoiseGenerator * theNoiser;
00317
00318
00319
00320
00321 PixelIndices * pIndexConverter;
00322
00323 std::vector<EnergyDepositUnit> _ionization_points;
00324 std::vector<SignalPoint> _collection_points;
00325
00326 simlink_map simi;
00327 signal_map_type _signal;
00328
00329
00330 std::map<int,CalParameters,std::less<int> > calmap;
00331
00332
00333
00334
00335 void primary_ionization( const PSimHit& hit);
00336 std::vector<PixelDigi> digitize(PixelGeomDetUnit *det);
00337 void drift(const PSimHit& hit);
00338 void induce_signal( const PSimHit& hit);
00339 void fluctuateEloss(int particleId, float momentum, float eloss,
00340 float length, int NumberOfSegments,
00341 float elossVector[]);
00342 void add_noise();
00343 void make_digis();
00344 void pixel_inefficiency();
00345 bool use_ineff_from_db_;
00346
00347 bool use_module_killing_;
00348 bool use_deadmodule_DB_;
00349 bool use_LorentzAngle_DB_;
00350
00351 void pixel_inefficiency_db();
00352
00353 SiPixelGainCalibrationOfflineService * theSiPixelGainCalibrationService_;
00354 float missCalibrate(int col, int row, float amp) const;
00355 LocalVector DriftDirection();
00356
00357 void module_killing_conf();
00358 void module_killing_DB();
00359
00360
00361 CLHEP::RandFlat *flatDistribution_;
00362 CLHEP::RandGaussQ *gaussDistribution_;
00363
00364
00365 CLHEP::RandGaussQ *smearedThreshold_FPix_;
00366 CLHEP::RandGaussQ *smearedThreshold_BPix_;
00367
00368
00369
00370 CLHEP::RandGaussQ* theGaussianDistribution;
00371
00372 };
00373
00374 #endif