00001
00002
00003
00004
00005
00007 #include "SimDataFormats/TrackingHit/interface/PSimHit.h"
00008 #include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
00009
00010
00011
00012 #include "SimRomanPot/SimFP420/interface/FP420DigiMain.h"
00013
00014 #include "SimRomanPot/SimFP420/interface/ChargeDrifterFP420.h"
00015 #include "SimRomanPot/SimFP420/interface/ChargeDividerFP420.h"
00016
00017
00018 #include "DataFormats/FP420Digi/interface/HDigiFP420.h"
00019
00020
00021
00022
00023
00024
00025
00026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00027 #include <gsl/gsl_sf_erf.h>
00028 #include "CLHEP/Random/RandGauss.h"
00029 #include "CLHEP/Random/RandFlat.h"
00030 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00031
00032
00033
00034 #include <vector>
00035 #include <iostream>
00036 using namespace std;
00037
00038
00039
00040
00041
00042
00043 FP420DigiMain::FP420DigiMain(const edm::ParameterSet& conf):conf_(conf){
00044 std::cout << "Creating a FP420DigiMain" << std::endl;
00045 ndigis=0;
00046 verbosity = conf_.getUntrackedParameter<int>("VerbosityLevel");
00047 theElectronPerADC= conf_.getParameter<double>("ElectronFP420PerAdc");
00048 theThreshold = conf_.getParameter<double>("AdcFP420Threshold");
00049 noNoise = conf_.getParameter<bool>("NoFP420Noise");
00050 addNoisyPixels = conf_.getParameter<bool>("AddNoisyPixels");
00051 thez420 = conf_.getParameter<double>("z420");
00052 thezD2 = conf_.getParameter<double>("zD2");
00053 thezD3 = conf_.getParameter<double>("zD3");
00054 theApplyTofCut = conf_.getParameter<bool>("ApplyTofCut");
00055 tofCut = conf_.getParameter<double>("LowtofCutAndTo200ns");
00056 xytype=2;
00057
00058 if(verbosity>0) {
00059 std::cout << "theApplyTofCut=" << theApplyTofCut << " tofCut=" << tofCut << std::endl;
00060 std::cout << "FP420DigiMain theElectronPerADC=" << theElectronPerADC << " theThreshold=" << theThreshold << " noNoise=" << noNoise << std::endl;
00061 }
00062
00063
00064 Thick300 = 0.300;
00065
00066 ENC= 960.;
00067
00068 ldriftX = 0.050;
00069 ldriftY = 0.050;
00070 moduleThickness = 0.250;
00071
00072 pitchY= 0.050;
00073 pitchX= 0.050;
00074 numStripsY = 201;
00075 numStripsX = 401;
00076
00077 pitchYW= 0.400;
00078 pitchXW= 0.400;
00079 numStripsYW = 51;
00080 numStripsXW = 26;
00081
00082
00083 elossCut = 0.00003;
00084
00085
00086 if(verbosity>0) {
00087 std::cout << "FP420DigiMain moduleThickness=" << moduleThickness << std::endl;
00088 }
00089
00090
00091
00092 theFP420NumberingScheme = new FP420NumberingScheme();
00093
00094 float noiseRMS = ENC*moduleThickness/Thick300;
00095
00096 theZSuppressFP420 = new ZeroSuppressFP420(conf_,noiseRMS/theElectronPerADC);
00097 thePileUpFP420 = new PileUpFP420();
00098 theDConverterFP420 = new DigiConverterFP420(theElectronPerADC);
00099
00100 if(verbosity>0) {
00101 std::cout << "FP420DigiMain end of constructor" << std::endl;
00102 }
00103 }
00104 FP420DigiMain::~FP420DigiMain(){
00105 if(verbosity>0) {
00106 std::cout << "Destroying a FP420DigiMain" << std::endl;
00107 }
00108 delete theGNoiseFP420;
00109 delete theZSuppressFP420;
00110 delete theHitDigitizerFP420;
00111 delete thePileUpFP420;
00112 delete theDConverterFP420;
00113
00114 }
00115
00116
00117
00118
00119
00120
00121 vector <HDigiFP420> FP420DigiMain::run(const std::vector<PSimHit> &input,
00122 G4ThreeVector bfield, unsigned int iu ) {
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 if (xytype ==1) {
00137 numStrips = numStripsY;
00138 pitch= pitchY;
00139 ldrift = ldriftX;
00140 numStripsW = numStripsYW;
00141 pitchW= pitchYW;
00142 }
00143
00144 if (xytype ==2) {
00145 numStrips = numStripsX;
00146 pitch= pitchX;
00147 ldrift = ldriftY;
00148 numStripsW = numStripsXW;
00149 pitchW= pitchXW;
00150 }
00151
00152 float noiseRMS = ENC*moduleThickness/Thick300;
00153
00154
00155 theHitDigitizerFP420 = new HitDigitizerFP420(moduleThickness,ldrift,ldriftY,ldriftX,thez420,thezD2,thezD3);
00156 int numPixels = numStrips*numStripsW;
00157 theGNoiseFP420 = new GaussNoiseFP420(numPixels,noiseRMS,theThreshold,addNoisyPixels);
00158
00159
00160
00161
00162
00163 thePileUpFP420->reset();
00164
00165
00166 bool first = true;
00167
00168
00169
00170
00171
00172 vector<PSimHit>::const_iterator simHitIter = input.begin();
00173 vector<PSimHit>::const_iterator simHitIterEnd = input.end();
00174 for (;simHitIter != simHitIterEnd; ++simHitIter) {
00175
00176 const PSimHit ihit = *simHitIter;
00177
00178 if ( first ) {
00179
00180 first = false;
00181 }
00182
00183 double losenergy = ihit.energyLoss();
00184 float tof = ihit.tof();
00185
00186
00187 if(verbosity>0) {
00188 unsigned int unitID = ihit.detUnitId();
00189
00190
00191
00192
00193
00194
00195 std::cout << " *******FP420DigiMain: intindex= " << iu << std::endl;
00196 std::cout << " tof= " << tof << " EnergyLoss= " << losenergy << " pabs= " << ihit.pabs() << std::endl;
00197 std::cout << " EntryLocalP x= " << ihit.entryPoint().x() << " EntryLocalP y= " << ihit.entryPoint().y() << std::endl;
00198 std::cout << " ExitLocalP x= " << ihit.exitPoint().x() << " ExitLocalP y= " << ihit.exitPoint().y() << std::endl;
00199 std::cout << " EntryLocalP z= " << ihit.entryPoint().z() << " ExitLocalP z= " << ihit.exitPoint().z() << std::endl;
00200 std::cout << " unitID= " << unitID << " xytype= " << xytype << " particleType= " << ihit.particleType() << " trackId= " << ihit.trackId() << std::endl;
00201
00202 std::cout << " bfield= " << bfield << std::endl;
00203 }
00204
00205 if(verbosity>0) {
00206 std::cout << " *******FP420DigiMain: theApplyTofCut= " << theApplyTofCut << std::endl;
00207 std::cout << " tof= " << tof << " EnergyLoss= " << losenergy << " pabs= " << ihit.pabs() << std::endl;
00208 std::cout << " particleType= " << ihit.particleType() << std::endl;
00209 }
00210 if ( ( !(theApplyTofCut) || (theApplyTofCut && tofCut < abs(tof) < (tofCut+200.)) ) && losenergy > elossCut) {
00211
00212
00213 if(verbosity>0) std::cout << " inside tof: OK " << std::endl;
00214
00215
00216
00217 HitDigitizerFP420::hit_map_type _temp = theHitDigitizerFP420->processHit(ihit,bfield,xytype,numStrips,pitch,numStripsW,pitchW,moduleThickness);
00218
00219
00220
00221 thePileUpFP420->add(_temp,ihit);
00222
00223 }
00224 else {
00225
00226 }
00227
00228 }
00229
00230
00231 PileUpFP420::signal_map_type theSignal = thePileUpFP420->dumpSignal();
00232 PileUpFP420::HitToDigisMapType theLink = thePileUpFP420->dumpLink();
00233
00234
00235 PileUpFP420::signal_map_type afterNoise;
00236
00237 if (noNoise) {
00238 afterNoise = theSignal;
00239 } else {
00240 afterNoise = theGNoiseFP420->addNoise(theSignal);
00241
00242 }
00243
00244
00245
00246
00247
00248
00249 digis.clear();
00250
00251
00252
00253
00254 push_digis(theZSuppressFP420->zeroSuppress(theDConverterFP420->convert(afterNoise)),
00255 theLink,afterNoise);
00256
00257
00258
00259 return digis;
00260 }
00261
00262
00263
00264
00265
00266 void FP420DigiMain::push_digis(const DigitalMapType& dm,
00267 const HitToDigisMapType& htd,
00268 const PileUpFP420::signal_map_type& afterNoise
00269 ) {
00270
00271 if(verbosity>0) {
00272 std::cout << " ****FP420DigiMain: push_digis start: do for loop dm.size()=" << dm.size() << std::endl;
00273 }
00274
00275
00276 digis.reserve(50);
00277 digis.clear();
00278
00279 for ( DigitalMapType::const_iterator i=dm.begin(); i!=dm.end(); i++) {
00280
00281
00282
00283 digis.push_back( HDigiFP420( (*i).first, (*i).second));
00284 ndigis++;
00285
00286 if(verbosity>0) {
00287 std::cout << " ****FP420DigiMain:push_digis: ndigis = " << ndigis << std::endl;
00288 std::cout << "push_digis: strip = " << (*i).first << " adc = " << (*i).second << std::endl;
00289 }
00290
00291 }
00292
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00321
00322
00323
00324 for ( HitToDigisMapType::const_iterator mi=htd.begin(); mi!=htd.end(); mi++) {
00325
00326 if ((*((const_cast<DigitalMapType * >(&dm)))).find((*mi).first) != (*((const_cast<DigitalMapType * >(&dm)))).end() ){
00327
00328
00329 map<const PSimHit *, Amplitude> totalAmplitudePerSimHit;
00330 for (vector < pair < const PSimHit*, Amplitude > >::const_iterator simul =
00331 (*mi).second.begin() ; simul != (*mi).second.end(); simul ++){
00332 totalAmplitudePerSimHit[(*simul).first] += (*simul).second;
00333 }
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358 }
00359 }
00360
00361
00363
00364
00365
00366 }