CMS 3D CMS Logo

FP420DigiMain.cc
Go to the documentation of this file.
1 // File: FP420DigiMain.cc
3 // Date: 12.2006
4 // Description: FP420DigiMain for FP420
5 // Modifications:
10 
13 
15 
16 #include "CLHEP/Random/RandFlat.h"
17 #include "CLHEP/Random/RandGauss.h"
20 #include <gsl/gsl_sf_erf.h>
21 
22 #include <iostream>
23 #include <vector>
24 using namespace std;
25 
26 //#define CBOLTZ (1.38E-23)
27 //#define e_SI (1.6E-19)
28 
29 FP420DigiMain::FP420DigiMain(const edm::ParameterSet &conf) : conf_(conf) {
30  edm::LogInfo("SimRomanPotSimFP420") << "Creating a FP420DigiMain";
31  ndigis = 0;
32  verbosity = conf_.getUntrackedParameter<int>("VerbosityLevel");
33  theElectronPerADC = conf_.getParameter<double>("ElectronFP420PerAdc");
34  theThreshold = conf_.getParameter<double>("AdcFP420Threshold");
35  noNoise = conf_.getParameter<bool>("NoFP420Noise");
36  addNoisyPixels = conf_.getParameter<bool>("AddNoisyPixels");
37  thez420 = conf_.getParameter<double>("z420");
38  thezD2 = conf_.getParameter<double>("zD2");
39  thezD3 = conf_.getParameter<double>("zD3");
40  theApplyTofCut = conf_.getParameter<bool>("ApplyTofCut");
41  tofCut = conf_.getParameter<double>("LowtofCutAndTo200ns");
42  // sn0 = 3;// number of stations
43  // pn0 = 6;// number of superplanes
44  // rn0 = 3; // number of sensors in superlayer
45  xytype = 2;
46 
47  edm::LogInfo("SimRomanPotSimFP420") << "theApplyTofCut=" << theApplyTofCut << " tofCut=" << tofCut << "\n"
48  << "FP420DigiMain theElectronPerADC=" << theElectronPerADC
49  << " theThreshold=" << theThreshold << " noNoise=" << noNoise;
50 
51  // X (or Y)define type of sensor (xytype=1 or 2 used to derive it: 1-Y, 2-X)
52  // for every type there is normal pixel size=0.05 and Wide 0.400 mm
53  Thick300 = 0.300; // = 0.300 mm normalized to 300micron Silicon
54  // ENC= 2160.; // EquivalentNoiseCharge300um = 2160. +
55  // other sources of noise
56  ENC = 960.; // EquivalentNoiseCharge300um = 2160. + other sources of
57  // noise
58 
59  ldriftX = 0.050; // in mm(xytype=1)
60  ldriftY = 0.050; // in mm(xytype=2)
61  moduleThickness = 0.250; // mm(xytype=1)(xytype=2)
62 
63  pitchY = 0.050; // in mm(xytype=1)
64  pitchX = 0.050; // in mm(xytype=2)
65  // numStripsY = 200; // Y plate number of strips:200*0.050=10mm
66  // (xytype=1) numStripsX = 400; // X plate number of
67  // strips:400*0.050=20mm (xytype=2)
68  numStripsY = 144; // Y plate number of strips:144*0.050=7.2mm (xytype=1)
69  numStripsX = 160; // X plate number of strips:160*0.050=8.0mm (xytype=2)
70 
71  pitchYW = 0.400; // in mm(xytype=1)
72  pitchXW = 0.400; // in mm(xytype=2)
73  // numStripsYW = 50; // Y plate number of W strips:50 *0.400=20mm
74  // (xytype=1) - W have ortogonal projection numStripsXW = 25; // X
75  // plate number of W strips:25 *0.400=10mm (xytype=2) - W have ortogonal
76  // projection
77  numStripsYW = 20; // Y plate number of W strips:20 *0.400=8.0mm (xytype=1) - W
78  // have ortogonal projection
79  numStripsXW = 18; // X plate number of W strips:18 *0.400=7.2mm (xytype=2) - W
80  // have ortogonal projection
81 
82  // tofCut = 1350.; // Cut on the particle TOF range = 1380 - 1500
83  elossCut = 0.00003; // Cut on the particle TOF = 100 or 50
84 
85  edm::LogInfo("SimRomanPotSimFP420") << "FP420DigiMain moduleThickness=" << moduleThickness;
86 
87  float noiseRMS = ENC * moduleThickness / Thick300;
88 
90  // Y:
91  if (xytype == 1) {
92  numStrips = numStripsY; // Y plate number of strips:200*0.050=10mm -->
93  // 100*0.100=10mm
94  pitch = pitchY;
95  ldrift = ldriftX; // because drift is in local coordinates which 90 degree
96  // rotated ( for correct timeNormalization & noiseRMS
97  // calculations)
98  numStripsW = numStripsYW; // Y plate number of strips:200*0.050=10mm -->
99  // 100*0.100=10mm
100  pitchW = pitchYW;
101  }
102  // X:
103  if (xytype == 2) {
104  numStrips = numStripsX; // X plate number of strips:400*0.050=20mm -->
105  // 200*0.100=20mm
106  pitch = pitchX;
107  ldrift = ldriftY; // because drift is in local coordinates which 90 degree
108  // rotated ( for correct timeNormalization & noiseRMS
109  // calculations)
110  numStripsW = numStripsXW; // X plate number of strips:400*0.050=20mm -->
111  // 200*0.100=20mm
112  pitchW = pitchXW;
113  }
114 
116  new HitDigitizerFP420(moduleThickness, ldrift, ldriftY, ldriftX, thez420, thezD2, thezD3, verbosity);
117  int numPixels = numStrips * numStripsW;
118  theGNoiseFP420 = new GaussNoiseFP420(numPixels, noiseRMS, theThreshold, addNoisyPixels, verbosity);
119  theZSuppressFP420 = new ZeroSuppressFP420(conf_, noiseRMS / theElectronPerADC);
120  thePileUpFP420 = new PileUpFP420();
121  theDConverterFP420 = new DigiConverterFP420(theElectronPerADC, verbosity);
122 
123  edm::LogInfo("SimRomanPotSimFP420") << "FP420DigiMain end of constructor";
124 }
125 
127  delete theGNoiseFP420;
128  delete theZSuppressFP420;
129  delete theHitDigitizerFP420;
130  delete thePileUpFP420;
131  delete theDConverterFP420;
132 }
133 
134 // Run the algorithm
135 // ------------------
136 
137 vector<HDigiFP420> FP420DigiMain::run(const std::vector<PSimHit> &input, const G4ThreeVector &bfield, unsigned int iu) {
139  bool first = true;
140 
141  // main loop
142  //
143  // First: loop on the SimHits
144  //
145  std::vector<PSimHit>::const_iterator simHitIter = input.begin();
146  std::vector<PSimHit>::const_iterator simHitIterEnd = input.end();
147  for (; simHitIter != simHitIterEnd; ++simHitIter) {
148  const PSimHit ihit = *simHitIter;
149 
150  if (first) {
151  // detID = ihit.detUnitId();
152  first = false;
153  }
154 
155  // main part here:
156  double losenergy = ihit.energyLoss();
157  float tof = ihit.tof();
158 
159  if (verbosity > 1) {
160  unsigned int unitID = ihit.detUnitId();
161  std::cout << " *******FP420DigiMain: intindex= " << iu << std::endl;
162  std::cout << " tof= " << tof << " EnergyLoss= " << losenergy << " pabs= " << ihit.pabs() << std::endl;
163  std::cout << " EntryLocalP x= " << ihit.entryPoint().x() << " EntryLocalP y= " << ihit.entryPoint().y()
164  << std::endl;
165  std::cout << " ExitLocalP x= " << ihit.exitPoint().x() << " ExitLocalP y= " << ihit.exitPoint().y() << std::endl;
166  std::cout << " EntryLocalP z= " << ihit.entryPoint().z() << " ExitLocalP z= " << ihit.exitPoint().z()
167  << std::endl;
168  std::cout << " unitID= " << unitID << " xytype= " << xytype << " particleType= " << ihit.particleType()
169  << " trackId= " << ihit.trackId() << std::endl;
170  // std::cout << " det= " << det << " sector= " << sector << " zmodule=
171  // " << zmodule << std::endl;
172  std::cout << " bfield= " << bfield << std::endl;
173  }
174  if (verbosity > 0) {
175  std::cout << " *******FP420DigiMain: theApplyTofCut= " << theApplyTofCut << std::endl;
176  std::cout << " tof= " << tof << " EnergyLoss= " << losenergy << " pabs= " << ihit.pabs() << std::endl;
177  std::cout << " particleType= " << ihit.particleType() << std::endl;
178  }
179 
180  if ((!(theApplyTofCut) || (theApplyTofCut && abs(tof) > tofCut && abs(tof) < (tofCut + 200.))) &&
181  losenergy > elossCut) {
182  if (verbosity > 0)
183  std::cout << " inside tof: OK " << std::endl;
184 
187 
188  thePileUpFP420->add(_temp, ihit, verbosity);
189  }
190  // main part end (AZ)
191  } // for
192  // main loop end (AZ)
193 
196 
197  PileUpFP420::signal_map_type afterNoise;
198 
199  if (noNoise) {
200  afterNoise = theSignal;
201  } else {
202  afterNoise = theGNoiseFP420->addNoise(theSignal);
203  // add_noise();
204  }
205  digis.clear();
206 
207  push_digis(theZSuppressFP420->zeroSuppress(theDConverterFP420->convert(afterNoise), verbosity), theLink, afterNoise);
208 
209  return digis; // to HDigiFP420
210 }
211 
213  const HitToDigisMapType &htd,
214  const PileUpFP420::signal_map_type &afterNoise) {
215  //
216  if (verbosity > 0) {
217  std::cout << " ****FP420DigiMain: push_digis start: do for loop dm.size()=" << dm.size() << std::endl;
218  }
219 
220  digis.reserve(50);
221  digis.clear();
222  // link_coll.clear();
223  for (DigitalMapType::const_iterator i = dm.begin(); i != dm.end(); i++) {
224  // Load digis
225  // push to digis the content of first and second words of HDigiFP420 vector
226  // for every strip pointer (*i)
227  digis.push_back(HDigiFP420((*i).first, (*i).second));
228  ndigis++;
229  // very useful check:
230  if (verbosity > 0) {
231  std::cout << " ****FP420DigiMain:push_digis: ndigis = " << ndigis << std::endl;
232  std::cout << "push_digis: strip = " << (*i).first << " adc = " << (*i).second << std::endl;
233  }
234  }
235 
237 
238  // reworked to access the fraction of amplitude per simhit
239 
240  for (HitToDigisMapType::const_iterator mi = htd.begin(); mi != htd.end(); mi++) {
241  //
242  if (dm.find((*mi).first) != dm.end()) {
243  // --- For each channel, sum up the signals from a simtrack
244  //
245  map<const PSimHit *, Amplitude> totalAmplitudePerSimHit;
246  for (std::vector<std::pair<const PSimHit *, Amplitude>>::const_iterator simul = (*mi).second.begin();
247  simul != (*mi).second.end();
248  simul++) {
249  totalAmplitudePerSimHit[(*simul).first] += (*simul).second;
250  }
251  /*
252  //--- include the noise as well
253 
254  PileUpFP420::signal_map_type& temp1 =
255  const_cast<PileUpFP420::signal_map_type&>(afterNoise); float
256  totalAmplitude1 = temp1[(*mi).first];
257 
258  //--- digisimlink
259  for (std::map<const PSimHit *, Amplitude>::const_iterator iter =
260  totalAmplitudePerSimHit.begin(); iter != totalAmplitudePerSimHit.end();
261  iter++){
262 
263  float threshold = 0.;
264  if (totalAmplitudePerSimHit[(*iter).first]/totalAmplitude1 >= threshold) {
265  float fraction = totalAmplitudePerSimHit[(*iter).first]/totalAmplitude1;
266 
267  //Noise fluctuation could make fraction>1. Unphysical, set it by hand.
268  if(fraction >1.) fraction = 1.;
269 
270  link_coll.push_back(StripDigiSimLink( (*mi).first, //channel
271  ((*iter).first)->trackId(), //simhit
272  fraction)); //fraction
273  }//if
274  }//for
275  */
276  //
277  } // if
278  } // for
279 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
DConverterFP420::DigitalMapType DigitalMapType
Definition: FP420DigiMain.h:36
float tof() const
deprecated name for timeOfFlight()
Definition: PSimHit.h:76
GaussNoiseFP420 * theGNoiseFP420
edm::ParameterSet conf_
Definition: FP420DigiMain.h:54
void reset()
Definition: PileUpFP420.h:20
std::map< int, float, std::less< int > > hit_map_type
ZSuppressFP420::DigitalMapType zeroSuppress(const DigitalMapType &, int) override
T y() const
Definition: PV3DBase.h:63
std::vector< HDigiFP420 > digis
float theThreshold
Definition: FP420DigiMain.h:86
PileUpFP420::HitToDigisMapType HitToDigisMapType
Definition: FP420DigiMain.h:37
static std::string const input
Definition: EdmProvDump.cc:48
std::vector< HDigiFP420 > run(const std::vector< PSimHit > &input, const G4ThreeVector &, unsigned int)
Local3DPoint exitPoint() const
Exit point in the local Det frame.
Definition: PSimHit.h:46
virtual void add(const HitDigitizerFP420::hit_map_type &, const PSimHit &hit, int)
Definition: PileUpFP420.cc:13
DigiConverterFP420 * theDConverterFP420
T z() const
Definition: PV3DBase.h:64
float theElectronPerADC
Definition: FP420DigiMain.h:70
FP420DigiMain(const edm::ParameterSet &conf)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
float pabs() const
fast and more accurate access to momentumAtEntry().mag()
Definition: PSimHit.h:67
std::map< int, Amplitude, std::less< int > > signal_map_type
Definition: PileUpFP420.h:13
ZeroSuppressFP420 * theZSuppressFP420
std::map< int, std::vector< std::pair< const PSimHit *, Amplitude > >, std::less< int > > HitToDigisMapType
Definition: PileUpFP420.h:14
signal_map_type dumpSignal()
Definition: PileUpFP420.h:24
float energyLoss() const
The energy deposit in the PSimHit, in ???.
Definition: PSimHit.h:79
int particleType() const
Definition: PSimHit.h:89
void push_digis(const DigitalMapType &, const HitToDigisMapType &, const PileUpFP420::signal_map_type &)
PileUpFP420 * thePileUpFP420
unsigned int trackId() const
Definition: PSimHit.h:106
DigitalMapType convert(const signal_map_type &) override
T x() const
Definition: PV3DBase.h:62
PileUpFP420::signal_map_type addNoise(const PileUpFP420::signal_map_type &) override
Local3DPoint entryPoint() const
Entry point in the local Det frame.
Definition: PSimHit.h:43
HitToDigisMapType dumpLink()
Definition: PileUpFP420.h:25
HitDigitizerFP420 * theHitDigitizerFP420
unsigned int detUnitId() const
Definition: PSimHit.h:97
hit_map_type processHit(const PSimHit &, const G4ThreeVector &, int, int, double, int, double, double, int)
float moduleThickness