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 
17 #include <gsl/gsl_sf_erf.h>
18 #include "CLHEP/Random/RandGauss.h"
19 #include "CLHEP/Random/RandFlat.h"
21 
22 #include <vector>
23 #include <iostream>
24 using namespace std;
25 
26 //#define CBOLTZ (1.38E-23)
27 //#define e_SI (1.6E-19)
28 
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")
48  << "theApplyTofCut=" << theApplyTofCut << " tofCut=" << tofCut << "\n"
49  << "FP420DigiMain theElectronPerADC=" << theElectronPerADC << " 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. + other sources of noise
55  ENC= 960.; // EquivalentNoiseCharge300um = 2160. + other sources of noise
56 
57  ldriftX = 0.050; // in mm(xytype=1)
58  ldriftY = 0.050; // in mm(xytype=2)
59  moduleThickness = 0.250; // mm(xytype=1)(xytype=2)
60 
61  pitchY= 0.050; // in mm(xytype=1)
62  pitchX= 0.050; // in mm(xytype=2)
63  //numStripsY = 200; // Y plate number of strips:200*0.050=10mm (xytype=1)
64  //numStripsX = 400; // X plate number of strips:400*0.050=20mm (xytype=2)
65  numStripsY = 144; // Y plate number of strips:144*0.050=7.2mm (xytype=1)
66  numStripsX = 160; // X plate number of strips:160*0.050=8.0mm (xytype=2)
67 
68  pitchYW= 0.400; // in mm(xytype=1)
69  pitchXW= 0.400; // in mm(xytype=2)
70  //numStripsYW = 50; // Y plate number of W strips:50 *0.400=20mm (xytype=1) - W have ortogonal projection
71  //numStripsXW = 25; // X plate number of W strips:25 *0.400=10mm (xytype=2) - W have ortogonal projection
72  numStripsYW = 20; // Y plate number of W strips:20 *0.400=8.0mm (xytype=1) - W have ortogonal projection
73  numStripsXW = 18; // X plate number of W strips:18 *0.400=7.2mm (xytype=2) - W have ortogonal projection
74 
75  // tofCut = 1350.; // Cut on the particle TOF range = 1380 - 1500
76  elossCut = 0.00003; // Cut on the particle TOF = 100 or 50
77 
78  edm::LogInfo("SimRomanPotSimFP420") << "FP420DigiMain moduleThickness=" << moduleThickness;
79 
80  float noiseRMS = ENC*moduleThickness/Thick300;
81 
83  // Y:
84  if (xytype ==1) {
85  numStrips = numStripsY; // Y plate number of strips:200*0.050=10mm --> 100*0.100=10mm
86  pitch= pitchY;
87  ldrift = ldriftX; // because drift is in local coordinates which 90 degree rotated ( for correct timeNormalization & noiseRMS calculations)
88  numStripsW = numStripsYW; // Y plate number of strips:200*0.050=10mm --> 100*0.100=10mm
89  pitchW= pitchYW;
90  }
91  // X:
92  if (xytype ==2) {
93  numStrips = numStripsX; // X plate number of strips:400*0.050=20mm --> 200*0.100=20mm
94  pitch= pitchX;
95  ldrift = ldriftY; // because drift is in local coordinates which 90 degree rotated ( for correct timeNormalization & noiseRMS calculations)
96  numStripsW = numStripsXW; // X plate number of strips:400*0.050=20mm --> 200*0.100=20mm
97  pitchW= pitchXW;
98  }
99 
101  int numPixels = numStrips*numStripsW;
102  theGNoiseFP420 = new GaussNoiseFP420(numPixels,noiseRMS,theThreshold,addNoisyPixels,verbosity);
103  theZSuppressFP420 = new ZeroSuppressFP420(conf_,noiseRMS/theElectronPerADC);
104  thePileUpFP420 = new PileUpFP420();
105  theDConverterFP420 = new DigiConverterFP420(theElectronPerADC,verbosity);
106 
107  edm::LogInfo("SimRomanPotSimFP420") << "FP420DigiMain end of constructor";
108 }
109 
111  delete theGNoiseFP420;
112  delete theZSuppressFP420;
113  delete theHitDigitizerFP420;
114  delete thePileUpFP420;
115  delete theDConverterFP420;
116 }
117 
118 // Run the algorithm
119 // ------------------
120 
121 vector <HDigiFP420> FP420DigiMain::run(const std::vector<PSimHit> &input,
122  const G4ThreeVector& bfield, unsigned int iu ) {
123 
125  bool first = true;
126 
127  // main loop
128  //
129  // First: loop on the SimHits
130  //
131  std::vector<PSimHit>::const_iterator simHitIter = input.begin();
132  std::vector<PSimHit>::const_iterator simHitIterEnd = input.end();
133  for (;simHitIter != simHitIterEnd; ++simHitIter) {
134 
135  const PSimHit ihit = *simHitIter;
136 
137  if ( first ) {
138  // detID = ihit.detUnitId();
139  first = false;
140  }
141 
142  // main part here:
143  double losenergy = ihit.energyLoss();
144  float tof = ihit.tof();
145 
146  if(verbosity>1) {
147  unsigned int unitID = ihit.detUnitId();
148  std::cout << " *******FP420DigiMain: intindex= " << iu << std::endl;
149  std::cout << " tof= " << tof << " EnergyLoss= " << losenergy << " pabs= " << ihit.pabs() << std::endl;
150  std::cout << " EntryLocalP x= " << ihit.entryPoint().x() << " EntryLocalP y= " << ihit.entryPoint().y() << std::endl;
151  std::cout << " ExitLocalP x= " << ihit.exitPoint().x() << " ExitLocalP y= " << ihit.exitPoint().y() << std::endl;
152  std::cout << " EntryLocalP z= " << ihit.entryPoint().z() << " ExitLocalP z= " << ihit.exitPoint().z() << std::endl;
153  std::cout << " unitID= " << unitID << " xytype= " << xytype << " particleType= " << ihit.particleType() << " trackId= " << ihit.trackId() << std::endl;
154  // std::cout << " det= " << det << " sector= " << sector << " zmodule= " << zmodule << std::endl;
155  std::cout << " bfield= " << bfield << std::endl;
156  }
157  if(verbosity>0) {
158  std::cout << " *******FP420DigiMain: theApplyTofCut= " << theApplyTofCut << std::endl;
159  std::cout << " tof= " << tof << " EnergyLoss= " << losenergy << " pabs= " << ihit.pabs() << std::endl;
160  std::cout << " particleType= " << ihit.particleType() << std::endl;
161  }
162 
163  if ( ( !(theApplyTofCut) || ( theApplyTofCut && abs(tof) > tofCut && abs(tof) < (tofCut+200.)) ) && losenergy > elossCut) {
164  if(verbosity>0) std::cout << " inside tof: OK " << std::endl;
165 
167 
168  thePileUpFP420->add(_temp,ihit,verbosity);
169 
170  }
171  // main part end (AZ)
172  } //for
173  // main loop end (AZ)
174 
177 
178 
179  PileUpFP420::signal_map_type afterNoise;
180 
181  if (noNoise) {
182  afterNoise = theSignal;
183  } else {
184  afterNoise = theGNoiseFP420->addNoise(theSignal);
185  // add_noise();
186  }
187  digis.clear();
188 
190  theLink,afterNoise);
191 
192  return digis; // to HDigiFP420
193 }
194 
196  const HitToDigisMapType& htd,
197  const PileUpFP420::signal_map_type& afterNoise
198  ) {
199  //
200  if(verbosity>0) {
201  std::cout << " ****FP420DigiMain: push_digis start: do for loop dm.size()=" << dm.size() << std::endl;
202  }
203 
204  digis.reserve(50);
205  digis.clear();
206  // link_coll.clear();
207  for ( DigitalMapType::const_iterator i=dm.begin(); i!=dm.end(); i++) {
208 
209  // Load digis
210  // push to digis the content of first and second words of HDigiFP420 vector for every strip pointer (*i)
211  digis.push_back( HDigiFP420( (*i).first, (*i).second));
212  ndigis++;
213  // very useful check:
214  if(verbosity>0) {
215  std::cout << " ****FP420DigiMain:push_digis: ndigis = " << ndigis << std::endl;
216  std::cout << "push_digis: strip = " << (*i).first << " adc = " << (*i).second << std::endl;
217  }
218 
219  }
220 
222 
223  // reworked to access the fraction of amplitude per simhit
224 
225  for ( HitToDigisMapType::const_iterator mi=htd.begin(); mi!=htd.end(); mi++) {
226  //
227  if (dm.find((*mi).first) != dm.end() ){
228  // --- For each channel, sum up the signals from a simtrack
229  //
230  map<const PSimHit *, Amplitude> totalAmplitudePerSimHit;
231  for (std::vector < std::pair < const PSimHit*, Amplitude > >::const_iterator simul =
232  (*mi).second.begin() ; simul != (*mi).second.end(); simul ++){
233  totalAmplitudePerSimHit[(*simul).first] += (*simul).second;
234  }
235  /*
236  //--- include the noise as well
237 
238  PileUpFP420::signal_map_type& temp1 = const_cast<PileUpFP420::signal_map_type&>(afterNoise);
239  float totalAmplitude1 = temp1[(*mi).first];
240 
241  //--- digisimlink
242  for (std::map<const PSimHit *, Amplitude>::const_iterator iter = totalAmplitudePerSimHit.begin();
243  iter != totalAmplitudePerSimHit.end(); iter++){
244 
245  float threshold = 0.;
246  if (totalAmplitudePerSimHit[(*iter).first]/totalAmplitude1 >= threshold) {
247  float fraction = totalAmplitudePerSimHit[(*iter).first]/totalAmplitude1;
248 
249  //Noise fluctuation could make fraction>1. Unphysical, set it by hand.
250  if(fraction >1.) fraction = 1.;
251 
252  link_coll.push_back(StripDigiSimLink( (*mi).first, //channel
253  ((*iter).first)->trackId(), //simhit
254  fraction)); //fraction
255  }//if
256  }//for
257  */
258  //
259  }//if
260  }//for
261 }
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
DConverterFP420::DigitalMapType DigitalMapType
Definition: FP420DigiMain.h:39
float tof() const
deprecated name for timeOfFlight()
Definition: PSimHit.h:72
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:63
std::vector< HDigiFP420 > digis
float theThreshold
Definition: FP420DigiMain.h:87
PileUpFP420::HitToDigisMapType HitToDigisMapType
Definition: FP420DigiMain.h:40
PileUpFP420::signal_map_type addNoise(const PileUpFP420::signal_map_type &)
DigitalMapType convert(const signal_map_type &)
static std::string const input
Definition: EdmProvDump.cc:44
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:38
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:71
ZSuppressFP420::DigitalMapType zeroSuppress(const DigitalMapType &, int)
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:63
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
T x() const
Definition: PV3DBase.h:62
Local3DPoint entryPoint() const
Entry point in the local Det frame.
Definition: PSimHit.h:35
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
hit_map_type processHit(const PSimHit &, const G4ThreeVector &, int, int, double, int, double, double, int)
float moduleThickness