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 
92  float noiseRMS = ENC*moduleThickness/Thick300;
93 
94 
95 
97  // Y:
98  if (xytype ==1) {
99  numStrips = numStripsY; // Y plate number of strips:200*0.050=10mm --> 100*0.100=10mm
100  pitch= pitchY;
101  ldrift = ldriftX; // because drift is in local coordinates which 90 degree rotated ( for correct timeNormalization & noiseRMS calculations)
102  numStripsW = numStripsYW; // Y plate number of strips:200*0.050=10mm --> 100*0.100=10mm
103  pitchW= pitchYW;
104  }
105  // X:
106  if (xytype ==2) {
107  numStrips = numStripsX; // X plate number of strips:400*0.050=20mm --> 200*0.100=20mm
108  pitch= pitchX;
109  ldrift = ldriftY; // because drift is in local coordinates which 90 degree rotated ( for correct timeNormalization & noiseRMS calculations)
110  numStripsW = numStripsXW; // X plate number of strips:400*0.050=20mm --> 200*0.100=20mm
111  pitchW= pitchXW;
112  }
113 
114  // float noiseRMS = ENC*moduleThickness/Thick300;
115 
116 
118  int numPixels = numStrips*numStripsW;
119  theGNoiseFP420 = new GaussNoiseFP420(numPixels,noiseRMS,theThreshold,addNoisyPixels,verbosity);
120  // theGNoiseFP420 = new GaussNoiseFP420(numStrips,noiseRMS,theThreshold,addNoisyPixels);
122 
123 
124 
125 
126  theZSuppressFP420 = new ZeroSuppressFP420(conf_,noiseRMS/theElectronPerADC);
127  thePileUpFP420 = new PileUpFP420();
128  theDConverterFP420 = new DigiConverterFP420(theElectronPerADC,verbosity);
129 
130  if(verbosity>0) std::cout << "FP420DigiMain end of constructor" << std::endl;
131 
132 }
133 
134 
135 
136 
137 
138 
139 
141  if(verbosity>0) {
142  std::cout << "Destroying a FP420DigiMain" << std::endl;
143  }
144  delete theGNoiseFP420;
145  delete theZSuppressFP420;
146  delete theHitDigitizerFP420;
147  delete thePileUpFP420;
148  delete theDConverterFP420;
149 
150 }
151 
152 
153 
154 // Run the algorithm
155 // ------------------
156 
157 vector <HDigiFP420> FP420DigiMain::run(const std::vector<PSimHit> &input,
158  const G4ThreeVector& bfield, unsigned int iu ) {
159 
161  // unsigned int detID = det->globalId().rawId();
162  // unsigned int detID = 1;
163  bool first = true;
164 
165  // main loop
166  //
167  // First: loop on the SimHits
168  //
169  std::vector<PSimHit>::const_iterator simHitIter = input.begin();
170  std::vector<PSimHit>::const_iterator simHitIterEnd = input.end();
171  for (;simHitIter != simHitIterEnd; ++simHitIter) {
172 
173  const PSimHit ihit = *simHitIter;
174 
175  if ( first ) {
176  // detID = ihit.detUnitId();
177  first = false;
178  }
179 
180  // main part here:
181  double losenergy = ihit.energyLoss();
182  float tof = ihit.tof();
183 
184  if(verbosity>1) {
185  unsigned int unitID = ihit.detUnitId();
186  std::cout << " *******FP420DigiMain: intindex= " << iu << std::endl;
187  std::cout << " tof= " << tof << " EnergyLoss= " << losenergy << " pabs= " << ihit.pabs() << std::endl;
188  std::cout << " EntryLocalP x= " << ihit.entryPoint().x() << " EntryLocalP y= " << ihit.entryPoint().y() << std::endl;
189  std::cout << " ExitLocalP x= " << ihit.exitPoint().x() << " ExitLocalP y= " << ihit.exitPoint().y() << std::endl;
190  std::cout << " EntryLocalP z= " << ihit.entryPoint().z() << " ExitLocalP z= " << ihit.exitPoint().z() << std::endl;
191  std::cout << " unitID= " << unitID << " xytype= " << xytype << " particleType= " << ihit.particleType() << " trackId= " << ihit.trackId() << std::endl;
192  // std::cout << " det= " << det << " sector= " << sector << " zmodule= " << zmodule << std::endl;
193  std::cout << " bfield= " << bfield << std::endl;
194  }
195  if(verbosity>0) {
196  std::cout << " *******FP420DigiMain: theApplyTofCut= " << theApplyTofCut << std::endl;
197  std::cout << " tof= " << tof << " EnergyLoss= " << losenergy << " pabs= " << ihit.pabs() << std::endl;
198  std::cout << " particleType= " << ihit.particleType() << std::endl;
199  }
200 
201  //
202 
203  // if ( ( !(theApplyTofCut) || (theApplyTofCut && tofCut < abs(tof) < (tofCut+200.)) ) && losenergy > elossCut) {
204  if ( ( !(theApplyTofCut) || ( theApplyTofCut && abs(tof) > tofCut && abs(tof) < (tofCut+200.)) ) && losenergy > elossCut) {
205  // if ( abs(tof) < tofCut && losenergy > elossCut) {
206  // if ( losenergy>0) {
207  if(verbosity>0) std::cout << " inside tof: OK " << std::endl;
208 
209  // xytype = 1 - Y strips; =2 - X strips;
210  // HitDigitizerFP420::hit_map_type _temp = theHitDigitizerFP420->processHit(ihit,bfield,xytype,numStrips,pitch);
212 
213 
214 
215  thePileUpFP420->add(_temp,ihit,verbosity);
216 
217  }// if
218 
219  else {
220  // std::cout << " *******FP420DigiMain: ERROR??? losenergy = " << losenergy << std::endl;
221  }
222  // main part end (AZ)
223  } //for
224  // main loop end (AZ)
225 
228 
229 
230  PileUpFP420::signal_map_type afterNoise;
231 
232  if (noNoise) {
233  afterNoise = theSignal;
234  } else {
235  afterNoise = theGNoiseFP420->addNoise(theSignal);
236  // add_noise();
237  }
238 
239  // if((pixelInefficiency>0) && (_signal.size()>0))
240  // pixel_inefficiency(); // Kill some pixels
241 
242 
243 
244  digis.clear();
245 
246 
247 
248  // !!!!!
250  theLink,afterNoise);
251 
252 
253 
254  return digis; // to HDigiFP420
255 }
256 
257 
258 
259 
260 
262  const HitToDigisMapType& htd,
263  const PileUpFP420::signal_map_type& afterNoise
264  ) {
265  //
266  if(verbosity>0) {
267  std::cout << " ****FP420DigiMain: push_digis start: do for loop dm.size()=" << dm.size() << std::endl;
268  }
269 
270 
271  digis.reserve(50);
272  digis.clear();
273  // link_coll.clear();
274  for ( DigitalMapType::const_iterator i=dm.begin(); i!=dm.end(); i++) {
275 
276  // Load digis
277  // push to digis the content of first and second words of HDigiFP420 vector for every strip pointer (*i)
278  digis.push_back( HDigiFP420( (*i).first, (*i).second));
279  ndigis++;
280  // very useful check:
281  if(verbosity>0) {
282  std::cout << " ****FP420DigiMain:push_digis: ndigis = " << ndigis << std::endl;
283  std::cout << "push_digis: strip = " << (*i).first << " adc = " << (*i).second << std::endl;
284  }
285 
286  }
287 
289  /*
290  //
291  // reworked to access the fraction of amplitude per simhit PSimHit
292  //
293  for ( HitToDigisMapType::const_iterator mi=htd.begin(); mi!=htd.end(); mi++) {
294  #ifdef mydigidebug1
295  std::cout << " ****push_digis:first for: (*mi).first = " << (*mi).first << std::endl;
296  std::cout << " if condition = " << (*((const_cast<DigitalMapType * >(&dm))))[(*mi).first] << std::endl;
297  #endif
298  // if ((*((const_cast<DigitalMapType * >(&dm))))[(*mi).first] != 0){
299  if ((*((const_cast<DigitalMapType * >(&dm)))).find((*mi).first) != (*((const_cast<DigitalMapType * >(&dm)))).end() ){
300  //
301  // For each channel, sum up the signals from a simtrack
302  //
303  std::map<const PSimHit *, Amplitude> totalAmplitudePerSimHit;
304  for (std::vector < std::pair < const PSimHit*, Amplitude > >::const_iterator simul =
305  (*mi).second.begin() ; simul != (*mi).second.end(); simul ++){
306  #ifdef mydigidebug1
307  std::cout << " ****push_digis:inside last for: (*simul).second= " << (*simul).second << std::endl;
308  #endif
309  totalAmplitudePerSimHit[(*simul).first] += (*simul).second;
310  } // for
311  } // if
312  } // for
313  */
314 
316 
317  // reworked to access the fraction of amplitude per simhit
318 
319  for ( HitToDigisMapType::const_iterator mi=htd.begin(); mi!=htd.end(); mi++) {
320  //
321  if ((*((const_cast<DigitalMapType * >(&dm)))).find((*mi).first) != (*((const_cast<DigitalMapType * >(&dm)))).end() ){
322  // --- For each channel, sum up the signals from a simtrack
323  //
324  map<const PSimHit *, Amplitude> totalAmplitudePerSimHit;
325  for (std::vector < std::pair < const PSimHit*, Amplitude > >::const_iterator simul =
326  (*mi).second.begin() ; simul != (*mi).second.end(); simul ++){
327  totalAmplitudePerSimHit[(*simul).first] += (*simul).second;
328  }
329  /*
330  //--- include the noise as well
331 
332  PileUpFP420::signal_map_type& temp1 = const_cast<PileUpFP420::signal_map_type&>(afterNoise);
333  float totalAmplitude1 = temp1[(*mi).first];
334 
335  //--- digisimlink
336  for (std::map<const PSimHit *, Amplitude>::const_iterator iter = totalAmplitudePerSimHit.begin();
337  iter != totalAmplitudePerSimHit.end(); iter++){
338 
339  float threshold = 0.;
340  if (totalAmplitudePerSimHit[(*iter).first]/totalAmplitude1 >= threshold) {
341  float fraction = totalAmplitudePerSimHit[(*iter).first]/totalAmplitude1;
342 
343  //Noise fluctuation could make fraction>1. Unphysical, set it by hand.
344  if(fraction >1.) fraction = 1.;
345 
346  link_coll.push_back(StripDigiSimLink( (*mi).first, //channel
347  ((*iter).first)->trackId(), //simhit
348  fraction)); //fraction
349  }//if
350  }//for
351  */
352  //
353  }//if
354  }//for
355  //
356  //
358  //
359  //
360  //
361  }
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
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
tuple dm
Definition: symbols.py:65
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
tuple cout
Definition: gather_cfg.py:145
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