CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FP420DigiMain.cc
Go to the documentation of this file.
1 // File: FP420DigiMain.cc
3 // Date: 12.2006
4 // Description: FP420DigiMain for FP420
5 // Modifications:
9 
10 //#include "SimG4CMS/FP420/interface/FP420G4HitCollection.h"
11 //#include "SimG4CMS/FP420/interface/FP420G4Hit.h"
12 //#include "SimRomanPot/SimFP420/interface/SimRPUtil.h"
14 
17 
18 //#include "SimRomanPot/SimFP420/interface/HDigiFP420.h"
20 //#include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
21 //#include "DataFormats/Common/interface/DetSetVector.h"
22 //#include "SimDataFormats/TrackerDigiSimLink/interface/StripDigiSimLink.h"
23 
24 
25 
26 
28 #include <gsl/gsl_sf_erf.h>
29 #include "CLHEP/Random/RandGauss.h"
30 #include "CLHEP/Random/RandFlat.h"
32 
33 #include <vector>
34 #include <iostream>
35 using namespace std;
36 
37 //#define CBOLTZ (1.38E-23)
38 //#define e_SI (1.6E-19)
39 
40 
41 
43  std::cout << "Creating a FP420DigiMain" << std::endl;
44  ndigis=0;
45  verbosity = conf_.getUntrackedParameter<int>("VerbosityLevel");
46  theElectronPerADC= conf_.getParameter<double>("ElectronFP420PerAdc");
47  theThreshold = conf_.getParameter<double>("AdcFP420Threshold");
48  noNoise = conf_.getParameter<bool>("NoFP420Noise");
49  addNoisyPixels = conf_.getParameter<bool>("AddNoisyPixels");
50  thez420 = conf_.getParameter<double>("z420");
51  thezD2 = conf_.getParameter<double>("zD2");
52  thezD3 = conf_.getParameter<double>("zD3");
53  theApplyTofCut = conf_.getParameter<bool>("ApplyTofCut");
54  tofCut = conf_.getParameter<double>("LowtofCutAndTo200ns");
55  // sn0 = 3;// number of stations
56  // pn0 = 6;// number of superplanes
57  // rn0 = 3; // number of sensors in superlayer
58  xytype = 2;
59  if(verbosity>0) {
60  std::cout << "theApplyTofCut=" << theApplyTofCut << " tofCut=" << tofCut << std::endl;
61  std::cout << "FP420DigiMain theElectronPerADC=" << theElectronPerADC << " theThreshold=" << theThreshold << " noNoise=" << noNoise << std::endl;
62  }
63  // X (or Y)define type of sensor (xytype=1 or 2 used to derive it: 1-Y, 2-X)
64  // for every type there is normal pixel size=0.05 and Wide 0.400 mm
65  Thick300 = 0.300; // = 0.300 mm normalized to 300micron Silicon
66  //ENC= 2160.; // EquivalentNoiseCharge300um = 2160. + other sources of noise
67  ENC= 960.; // EquivalentNoiseCharge300um = 2160. + other sources of noise
68 
69  ldriftX = 0.050; // in mm(xytype=1)
70  ldriftY = 0.050; // in mm(xytype=2)
71  moduleThickness = 0.250; // mm(xytype=1)(xytype=2)
72 
73  pitchY= 0.050; // in mm(xytype=1)
74  pitchX= 0.050; // in mm(xytype=2)
75  //numStripsY = 200; // Y plate number of strips:200*0.050=10mm (xytype=1)
76  //numStripsX = 400; // X plate number of strips:400*0.050=20mm (xytype=2)
77  numStripsY = 144; // Y plate number of strips:144*0.050=7.2mm (xytype=1)
78  numStripsX = 160; // X plate number of strips:160*0.050=8.0mm (xytype=2)
79 
80  pitchYW= 0.400; // in mm(xytype=1)
81  pitchXW= 0.400; // in mm(xytype=2)
82  //numStripsYW = 50; // Y plate number of W strips:50 *0.400=20mm (xytype=1) - W have ortogonal projection
83  //numStripsXW = 25; // X plate number of W strips:25 *0.400=10mm (xytype=2) - W have ortogonal projection
84  numStripsYW = 20; // Y plate number of W strips:20 *0.400=8.0mm (xytype=1) - W have ortogonal projection
85  numStripsXW = 18; // X plate number of W strips:18 *0.400=7.2mm (xytype=2) - W have ortogonal projection
86 
87  // tofCut = 1350.; // Cut on the particle TOF range = 1380 - 1500
88  elossCut = 0.00003; // Cut on the particle TOF = 100 or 50
89 
90  if(verbosity>0) std::cout << "FP420DigiMain moduleThickness=" << moduleThickness << std::endl;
91 
93 
94  float noiseRMS = ENC*moduleThickness/Thick300;
95 
96 
97 
99  // Y:
100  if (xytype ==1) {
101  numStrips = numStripsY; // Y plate number of strips:200*0.050=10mm --> 100*0.100=10mm
102  pitch= pitchY;
103  ldrift = ldriftX; // because drift is in local coordinates which 90 degree rotated ( for correct timeNormalization & noiseRMS calculations)
104  numStripsW = numStripsYW; // Y plate number of strips:200*0.050=10mm --> 100*0.100=10mm
105  pitchW= pitchYW;
106  }
107  // X:
108  if (xytype ==2) {
109  numStrips = numStripsX; // X plate number of strips:400*0.050=20mm --> 200*0.100=20mm
110  pitch= pitchX;
111  ldrift = ldriftY; // because drift is in local coordinates which 90 degree rotated ( for correct timeNormalization & noiseRMS calculations)
112  numStripsW = numStripsXW; // X plate number of strips:400*0.050=20mm --> 200*0.100=20mm
113  pitchW= pitchXW;
114  }
115 
116  // float noiseRMS = ENC*moduleThickness/Thick300;
117 
118 
120  int numPixels = numStrips*numStripsW;
121  theGNoiseFP420 = new GaussNoiseFP420(numPixels,noiseRMS,theThreshold,addNoisyPixels,verbosity);
122  // theGNoiseFP420 = new GaussNoiseFP420(numStrips,noiseRMS,theThreshold,addNoisyPixels);
124 
125 
126 
127 
128  theZSuppressFP420 = new ZeroSuppressFP420(conf_,noiseRMS/theElectronPerADC);
129  thePileUpFP420 = new PileUpFP420();
130  theDConverterFP420 = new DigiConverterFP420(theElectronPerADC,verbosity);
131 
132  if(verbosity>0) std::cout << "FP420DigiMain end of constructor" << std::endl;
133 
134 }
135 
136 
137 
138 
139 
140 
141 
143  if(verbosity>0) {
144  std::cout << "Destroying a FP420DigiMain" << std::endl;
145  }
146  delete theGNoiseFP420;
147  delete theZSuppressFP420;
148  delete theHitDigitizerFP420;
149  delete thePileUpFP420;
150  delete theDConverterFP420;
151 
152 }
153 
154 
155 
156 // Run the algorithm
157 // ------------------
158 
159 vector <HDigiFP420> FP420DigiMain::run(const std::vector<PSimHit> &input,
160  G4ThreeVector bfield, unsigned int iu ) {
161 
162  /*
163  int det, zside, sector, zmodule;
164  // theFP420NumberingScheme->FP420NumberingScheme::unpackMYIndex(iu, rn0, pn0, sn0, det, zside, sector, zmodule);
165  theFP420NumberingScheme->unpackMYIndex(iu, rn0, pn0, sn0, det, zside, sector, zmodule);
166 */
168  // unsigned int detID = det->globalId().rawId();
169  // unsigned int detID = 1;
170  bool first = true;
171 
172  // main loop
173  //
174  // First: loop on the SimHits
175  //
176  std::vector<PSimHit>::const_iterator simHitIter = input.begin();
177  std::vector<PSimHit>::const_iterator simHitIterEnd = input.end();
178  for (;simHitIter != simHitIterEnd; ++simHitIter) {
179 
180  const PSimHit ihit = *simHitIter;
181 
182  if ( first ) {
183  // detID = ihit.detUnitId();
184  first = false;
185  }
186 
187  // main part here:
188  double losenergy = ihit.energyLoss();
189  float tof = ihit.tof();
190 
191  if(verbosity>1) {
192  unsigned int unitID = ihit.detUnitId();
193  std::cout << " *******FP420DigiMain: intindex= " << iu << std::endl;
194  std::cout << " tof= " << tof << " EnergyLoss= " << losenergy << " pabs= " << ihit.pabs() << std::endl;
195  std::cout << " EntryLocalP x= " << ihit.entryPoint().x() << " EntryLocalP y= " << ihit.entryPoint().y() << std::endl;
196  std::cout << " ExitLocalP x= " << ihit.exitPoint().x() << " ExitLocalP y= " << ihit.exitPoint().y() << std::endl;
197  std::cout << " EntryLocalP z= " << ihit.entryPoint().z() << " ExitLocalP z= " << ihit.exitPoint().z() << std::endl;
198  std::cout << " unitID= " << unitID << " xytype= " << xytype << " particleType= " << ihit.particleType() << " trackId= " << ihit.trackId() << std::endl;
199  // std::cout << " det= " << det << " sector= " << sector << " zmodule= " << zmodule << std::endl;
200  std::cout << " bfield= " << bfield << std::endl;
201  }
202  if(verbosity>0) {
203  std::cout << " *******FP420DigiMain: theApplyTofCut= " << theApplyTofCut << std::endl;
204  std::cout << " tof= " << tof << " EnergyLoss= " << losenergy << " pabs= " << ihit.pabs() << std::endl;
205  std::cout << " particleType= " << ihit.particleType() << std::endl;
206  }
207 
208  //
209 
210  // if ( ( !(theApplyTofCut) || (theApplyTofCut && tofCut < abs(tof) < (tofCut+200.)) ) && losenergy > elossCut) {
211  if ( ( !(theApplyTofCut) || ( theApplyTofCut && abs(tof) > tofCut && abs(tof) < (tofCut+200.)) ) && losenergy > elossCut) {
212  // if ( abs(tof) < tofCut && losenergy > elossCut) {
213  // if ( losenergy>0) {
214  if(verbosity>0) std::cout << " inside tof: OK " << std::endl;
215 
216  // xytype = 1 - Y strips; =2 - X strips;
217  // HitDigitizerFP420::hit_map_type _temp = theHitDigitizerFP420->processHit(ihit,bfield,xytype,numStrips,pitch);
219 
220 
221 
222  thePileUpFP420->add(_temp,ihit,verbosity);
223 
224  }// if
225 
226  else {
227  // std::cout << " *******FP420DigiMain: ERROR??? losenergy = " << losenergy << std::endl;
228  }
229  // main part end (AZ)
230  } //for
231  // main loop end (AZ)
232 
235 
236 
237  PileUpFP420::signal_map_type afterNoise;
238 
239  if (noNoise) {
240  afterNoise = theSignal;
241  } else {
242  afterNoise = theGNoiseFP420->addNoise(theSignal);
243  // add_noise();
244  }
245 
246  // if((pixelInefficiency>0) && (_signal.size()>0))
247  // pixel_inefficiency(); // Kill some pixels
248 
249 
250 
251  digis.clear();
252 
253 
254 
255  // !!!!!
257  theLink,afterNoise);
258 
259 
260 
261  return digis; // to HDigiFP420
262 }
263 
264 
265 
266 
267 
269  const HitToDigisMapType& htd,
270  const PileUpFP420::signal_map_type& afterNoise
271  ) {
272  //
273  if(verbosity>0) {
274  std::cout << " ****FP420DigiMain: push_digis start: do for loop dm.size()=" << dm.size() << std::endl;
275  }
276 
277 
278  digis.reserve(50);
279  digis.clear();
280  // link_coll.clear();
281  for ( DigitalMapType::const_iterator i=dm.begin(); i!=dm.end(); i++) {
282 
283  // Load digis
284  // push to digis the content of first and second words of HDigiFP420 vector for every strip pointer (*i)
285  digis.push_back( HDigiFP420( (*i).first, (*i).second));
286  ndigis++;
287  // very useful check:
288  if(verbosity>0) {
289  std::cout << " ****FP420DigiMain:push_digis: ndigis = " << ndigis << std::endl;
290  std::cout << "push_digis: strip = " << (*i).first << " adc = " << (*i).second << std::endl;
291  }
292 
293  }
294 
296  /*
297  //
298  // reworked to access the fraction of amplitude per simhit PSimHit
299  //
300  for ( HitToDigisMapType::const_iterator mi=htd.begin(); mi!=htd.end(); mi++) {
301  #ifdef mydigidebug1
302  std::cout << " ****push_digis:first for: (*mi).first = " << (*mi).first << std::endl;
303  std::cout << " if condition = " << (*((const_cast<DigitalMapType * >(&dm))))[(*mi).first] << std::endl;
304  #endif
305  // if ((*((const_cast<DigitalMapType * >(&dm))))[(*mi).first] != 0){
306  if ((*((const_cast<DigitalMapType * >(&dm)))).find((*mi).first) != (*((const_cast<DigitalMapType * >(&dm)))).end() ){
307  //
308  // For each channel, sum up the signals from a simtrack
309  //
310  std::map<const PSimHit *, Amplitude> totalAmplitudePerSimHit;
311  for (std::vector < std::pair < const PSimHit*, Amplitude > >::const_iterator simul =
312  (*mi).second.begin() ; simul != (*mi).second.end(); simul ++){
313  #ifdef mydigidebug1
314  std::cout << " ****push_digis:inside last for: (*simul).second= " << (*simul).second << std::endl;
315  #endif
316  totalAmplitudePerSimHit[(*simul).first] += (*simul).second;
317  } // for
318  } // if
319  } // for
320  */
321 
323 
324  // reworked to access the fraction of amplitude per simhit
325 
326  for ( HitToDigisMapType::const_iterator mi=htd.begin(); mi!=htd.end(); mi++) {
327  //
328  if ((*((const_cast<DigitalMapType * >(&dm)))).find((*mi).first) != (*((const_cast<DigitalMapType * >(&dm)))).end() ){
329  // --- For each channel, sum up the signals from a simtrack
330  //
331  map<const PSimHit *, Amplitude> totalAmplitudePerSimHit;
332  for (std::vector < std::pair < const PSimHit*, Amplitude > >::const_iterator simul =
333  (*mi).second.begin() ; simul != (*mi).second.end(); simul ++){
334  totalAmplitudePerSimHit[(*simul).first] += (*simul).second;
335  }
336  /*
337  //--- include the noise as well
338 
339  PileUpFP420::signal_map_type& temp1 = const_cast<PileUpFP420::signal_map_type&>(afterNoise);
340  float totalAmplitude1 = temp1[(*mi).first];
341 
342  //--- digisimlink
343  for (std::map<const PSimHit *, Amplitude>::const_iterator iter = totalAmplitudePerSimHit.begin();
344  iter != totalAmplitudePerSimHit.end(); iter++){
345 
346  float threshold = 0.;
347  if (totalAmplitudePerSimHit[(*iter).first]/totalAmplitude1 >= threshold) {
348  float fraction = totalAmplitudePerSimHit[(*iter).first]/totalAmplitude1;
349 
350  //Noise fluctuation could make fraction>1. Unphysical, set it by hand.
351  if(fraction >1.) fraction = 1.;
352 
353  link_coll.push_back(StripDigiSimLink( (*mi).first, //channel
354  ((*iter).first)->trackId(), //simhit
355  fraction)); //fraction
356  }//if
357  }//for
358  */
359  //
360  }//if
361  }//for
362  //
363  //
365  //
366  //
367  //
368  }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
DConverterFP420::DigitalMapType DigitalMapType
Definition: FP420DigiMain.h:39
int i
Definition: DBlmapReader.cc:9
float tof() const
deprecated name for timeOfFlight()
Definition: PSimHit.h:72
std::vector< HDigiFP420 > run(const std::vector< PSimHit > &input, G4ThreeVector, unsigned int)
GaussNoiseFP420 * theGNoiseFP420
edm::ParameterSet conf_
Definition: FP420DigiMain.h:56
void reset()
Definition: PileUpFP420.h:22
std::map< int, float, std::less< int > > hit_map_type
T y() const
Definition: PV3DBase.h:62
#define abs(x)
Definition: mlp_lapack.h:159
std::vector< HDigiFP420 > digis
float theThreshold
Definition: FP420DigiMain.h:87
PileUpFP420::HitToDigisMapType HitToDigisMapType
Definition: FP420DigiMain.h:40
virtual void add(HitDigitizerFP420::hit_map_type, const PSimHit &hit, int)
Definition: PileUpFP420.cc:13
hit_map_type processHit(const PSimHit &, G4ThreeVector, int, int, double, int, double, double, int)
DigitalMapType convert(const signal_map_type &)
Local3DPoint exitPoint() const
Exit point in the local Det frame.
Definition: PSimHit.h:38
DigiConverterFP420 * theDConverterFP420
T z() const
Definition: PV3DBase.h:63
float theElectronPerADC
Definition: FP420DigiMain.h:71
ZSuppressFP420::DigitalMapType zeroSuppress(const DigitalMapType &, int)
FP420DigiMain(const edm::ParameterSet &conf)
FP420NumberingScheme * theFP420NumberingScheme
float pabs() const
fast and more accurate access to momentumAtEntry().mag()
Definition: PSimHit.h:63
bool first
Definition: L1TdeRCT.cc:94
tuple conf
Definition: dbtoconf.py:185
ZeroSuppressFP420 * theZSuppressFP420
signal_map_type dumpSignal()
Definition: PileUpFP420.h:23
float energyLoss() const
The energy deposit in the PSimHit, in ???.
Definition: PSimHit.h:75
int particleType() const
Definition: PSimHit.h:85
void push_digis(const DigitalMapType &, const HitToDigisMapType &, const PileUpFP420::signal_map_type &)
std::map< int, Amplitude, std::less< int > > signal_map_type
Definition: PileUpFP420.h:15
PileUpFP420 * thePileUpFP420
unsigned int trackId() const
Definition: PSimHit.h:102
tuple cout
Definition: gather_cfg.py:121
T x() const
Definition: PV3DBase.h:61
Local3DPoint entryPoint() const
Entry point in the local Det frame.
Definition: PSimHit.h:35
PileUpFP420::signal_map_type addNoise(PileUpFP420::signal_map_type)
HitToDigisMapType dumpLink()
Definition: PileUpFP420.h:24
std::map< int, std::vector< std::pair< const PSimHit *, Amplitude > >, std::less< int > > HitToDigisMapType
Definition: PileUpFP420.h:16
HitDigitizerFP420 * theHitDigitizerFP420
unsigned int detUnitId() const
Definition: PSimHit.h:93
float moduleThickness