CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ChargeDividerFP420.cc
Go to the documentation of this file.
1 // File: ChargeDividerFP420
3 // Date: 12.2006
4 // Description: ChargeDividerFP420 for FP420
5 // Modifications: std::
10 
11 //#include "SimDataFormats/TrackingHit/interface/PSimHit.h"
12 //#include "SimDataFormats/TrackingHit/interface/PSimHitContainer.h"
13 
14 using namespace std;
15 #include<vector>
16 
17 // unpacking variable - zside - Left or Right planes
18 
19 //DigitizerFP420::DigitizerFP420(const edm::ParameterSet& conf):conf_(conf),stripDigitizer_(new FP420DigiMain(conf))
20 ChargeDividerFP420::ChargeDividerFP420(double pit, double az420, double azD2, double azD3,int ver){
21 
22  verbosity=ver;
23  // pit - is really moduleThickness here !!!
24  if(verbosity>0) {
25  std::cout << "ChargeDividerFP420.h: constructor" << std::endl;
26  std::cout << "peakMode = " << peakMode << "fluctuateCharge= "<< fluctuateCharge << "chargedivisionsPerHit = " << chargedivisionsPerHit << "deltaCut= "<< deltaCut << std::endl;
27  }
28  // Initialization:
29  theFP420NumberingScheme = new FP420NumberingScheme();
30 
31 
32  // Run APV in peak instead of deconvolution mode, which degrades the time resolution
33  // peakMode=true ; // APVpeakmode
34  peakMode=false; // peakMode=true --> APVconvolutionmode
35  decoMode=false;// decoMode=true --> deconvolution mode
36  // Enable interstrip Landau fluctuations within a cluster.
37  fluctuateCharge=true;
38 
39  // Number of segments per strip into which charge is divided during simulation.
40  // If large the precision of simulation improves.
41  chargedivisionsPerHit=10; // = or =20
42 
43  // delta cutoff in MeV, has to be same as in OSCAR (0.120425 MeV corresponding // to 100um range for electrons)
44  //SimpleConfigurable<double> ChargeDividerFP420::deltaCut(0.120425,
45  deltaCut=0.120425; // DeltaProductionCut
46 
47  pitchcur= pit;// pitchcur - is really moduleThickness here !!!
48 
49  // but position before Stations:
50  z420 = az420; // dist between centers of 1st and 2nd stations
51  zD2 = azD2; // dist between centers of 1st and 2nd stations
52  zD3 = azD3; // dist between centers of 1st and 3rd stations
53 
54 
55 
56  // .
57  // .
58  // -300 -209.2 -150 -90.8 0 +300
59  // .
60  // X | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | X station .
61  // 8*13.3+ 2*6 = 118.4 center .
62  // .
63  //zStationBegPos[0] = -150. - (118.4+10.)/2 + z420; // 10. -arbitrary
64  zStationBegPos[0] = -40. + z420; // 5 superplanes per station 79.7mm: -40.- left edge of Station
65  zStationBegPos[1] = zStationBegPos[0]+zD2;
66  zStationBegPos[2] = zStationBegPos[0]+zD3;
67  zStationBegPos[3] = zStationBegPos[0]+2*zD3;
68 
69 }
70 
71 // Virtual destructor needed.
73  // if(verbosity>0) {
74  // std::cout << "Destroying a ChargeDividerFP420" << std::endl;
75  // }
76  delete theFP420NumberingScheme;
77 
78 }
81  const PSimHit& hit, const double& pitchcur) {
82  // !!!
83  // pitchcur - is really moduleThickness here !!!
84  // !!!
85 
86 
87 
88  // sign "-" mean not the same as "+" for middle point !!!
89  // G4ThreeVector direction = hit.getExitLocalP() - hit.getEntryLocalP();
90  LocalVector direction = hit.exitPoint() - hit.entryPoint();
91  // G4ThreeVector direction = hit.exitPoint() - hit.entryPoint();
92 
93  // LocalVector direction = hit.exitPoint() - hit.entryPoint();
94  // direction.mag() - length or (size of path) of the hit; direction/direction.mag() - cosines of direction
95 
96  if(verbosity>0) {
97  std::cout << " CDividerFP420::ChargeDividerFP420:divide: direction= " << direction << std::endl;
98  std::cout << " CDividerFP420::ChargeDividerFP420:divide: direction.mag = " << direction.mag() << std::endl;
99  std::cout << " obtained as ExitLocalP = " << hit.exitPoint() << " - "<< " EntryLocalP = " << hit.entryPoint() << std::endl;
100  std::cout << " pitchcur= " << pitchcur << std::endl;
101  std::cout << " peakMode = " << peakMode << " decoMode = " << decoMode << " fluctuateCharge= "<< fluctuateCharge << " chargedivisionsPerHit = " << chargedivisionsPerHit << " deltaCut= "<< deltaCut << std::endl;
102  }
103 
104  int NumberOfSegmentation =
105 
106  // (int)(1+chargedivisionsPerHit*fabs(direction.x())/pitchcur); // equidistant in X
107  // (int)(1+chargedivisionsPerHit*fabs(direction.z())/pitchcur); // equidistant in Z, but why?
108 
109  (int)(1+chargedivisionsPerHit*direction.mag()/pitchcur); // equidistant over hit path
110 
111 
112  if(verbosity>0) {
113  std::cout << "NumberOfSegmentation= " << NumberOfSegmentation << std::endl;
114  }
115 
116  float eLoss = hit.energyLoss(); // Eloss in GeV
117  // float eLoss = hit.getEnergyLoss(); // Eloss in GeV
118 
119  if(verbosity>0) {
120  std::cout << "CDividerFP420::ChargeDividerFP420:divide: eLoss= " << eLoss << std::endl;
121  }
122 
123  //
124  // return the energyLoss weighted CR-RC shape peaked at t0.(PeakShape)
125  // return the energyLoss weighted with a gaussian centered at t0 (DeconvolutionShape)
126  float decSignal = TimeResponse(hit);
127  if(verbosity>0) {
128  std::cout << "CDividerFP420::ChargeDividerFP420:divide: decSignal= " << decSignal << std::endl;
129  }
130 
131  ionization_type _ionization_points;
132 
133  _ionization_points.resize(NumberOfSegmentation);
134 
135  float energy;
136 
137  // Fluctuate charge in track subsegments
138  float* eLossVector = new float[NumberOfSegmentation];
139 
140 
141  if(verbosity>0) {
142  std::cout << "CDividerFP420::ChargeDividerFP420:divide: resize done; then, fluctuateCharge ? = " << fluctuateCharge << std::endl;
143  }
144  if( fluctuateCharge ) {
145  // int pid = hit.getParticleType();
146  // float momentum = hit.getPabs();
147  int pid = hit.particleType();
148  float momentum = hit.pabs();
149  float length = direction.mag(); // length or (size of path) of the hit;
150 
151  if(verbosity>0) {
152  std::cout << "pid= " << pid << "momentum= " << momentum << "eLoss= " << eLoss << "length= " << length << std::endl;
153  }
154  fluctuateEloss(pid, momentum, eLoss, length, NumberOfSegmentation, eLossVector);
155  }
156 
157  for ( int i = 0; i != NumberOfSegmentation; ++i) {
158  if( fluctuateCharge ) {
159  energy=eLossVector[i]*decSignal/eLoss;
160  EnergySegmentFP420 edu(energy,hit.entryPoint()+float((i+0.5)/NumberOfSegmentation)*direction);//take energy value from vector eLossVector
161  // EnergySegmentFP420 edu(energy,hit.getEntryLocalP()+float((i+0.5)/NumberOfSegmentation)*direction);//take energy value from vector eLossVector
162  _ionization_points[i] = edu; //save
163  }else{
164  energy=decSignal/float(NumberOfSegmentation);
165  EnergySegmentFP420 edu(energy,hit.entryPoint()+float((i+0.5)/NumberOfSegmentation)*direction);//take energy value from eLoss average over n.segments
166  // EnergySegmentFP420 edu(energy,hit.getEntryLocalP()+float((i+0.5)/NumberOfSegmentation)*direction);//take energy value from eLoss average over n.segments
167  _ionization_points[i] = edu; //save
168  }
169  }
170 
171  if(verbosity>0) {
172  std::cout << "CDividerFP420::ChargeDividerFP420:divide: !!! RESULT !!!" << std::endl;
173  std::cout << " _ionization_points size = " << _ionization_points.size() << std::endl;
174  for(unsigned int i = 0; i < _ionization_points.size(); ++i ) {
175  std::cout << " eLossVector[i] i = " << i << eLossVector[i] << std::endl;
176  }
177  }
178 
179  delete[] eLossVector;
180  return _ionization_points;
181 }
182 
183 void ChargeDividerFP420::fluctuateEloss(int pid, float particleMomentum,
184  float eloss, float length,
185  int NumberOfSegs,float elossVector[]) {
186 
187  if(verbosity>0) {
188  std::cout << "fluctuateEloss: eloss= " << eloss << "length= " << length << "NumberOfSegs= " << NumberOfSegs << std::endl;
189  }
190 
191  // double particleMass = 139.57; // Mass in MeV, Assume pion
192  double particleMass = 938.271; // Mass in MeV, Assume proton ---- AZ
193  // if( particleTable->getParticleData(pid) ) { // Get mass from the PDTable
194  // particleMass = 1000. * particleTable->getParticleData(pid)->mass(); //Conv. GeV to MeV
195  // }
196  pid = abs(pid);
197  if(pid==11) particleMass = 0.511; // Mass in MeV
198  else if(pid==13) particleMass = 105.658;
199  else if(pid==211) particleMass = 139.570;
200  // else if(pid==2212) particleMass = 938.271;
201 
202  float segmentLength = length/NumberOfSegs;
203 
204  // Generate charge fluctuations.
205  float de=0.;
206  float sum=0.;
207  double segmentEloss = (1000.*eloss)/NumberOfSegs; //eloss in MeV
208  if(verbosity>0) {
209  std::cout << "segmentLength= " << segmentLength << "segmentEloss= " << segmentEloss << std::endl;
210  }
211 
212  for (int i=0;i<NumberOfSegs;++i) {
213  // The G4 routine needs momentum in MeV, mass in Mev, delta-cut in MeV,
214  // track segment length in mm(!!!), segment eloss in MeV
215  // Returns fluctuated eloss in MeV
216  // double deltaCutoff = deltaCut.value(); // the cutoff is sometimes redefined inside, so fix it.
217  double deltaCutoff = deltaCut;
218  de = fluctuate.SampleFluctuations(double(particleMomentum*1000.),
219  particleMass, deltaCutoff,
220  double(segmentLength),
221  segmentEloss )/1000.; //convert to GeV
222  elossVector[i]=de;
223  sum +=de;
224  }
225 
226  if(verbosity>0) {
227  std::cout << "sum= " << sum << std::endl;
228  }
229  if(sum>0.) { // If fluctuations give eloss>0.
230  // Rescale to the same total eloss
231  float ratio = eloss/sum;
232  for (int ii=0;ii<NumberOfSegs;++ii) elossVector[ii]= ratio*elossVector[ii];
233  } else { // If fluctuations gives 0 eloss
234  float averageEloss = eloss/NumberOfSegs;
235  for (int ii=0;ii<NumberOfSegs;++ii) elossVector[ii]= averageEloss;
236  }
237  return;
238 }
239 
241  if (peakMode) {
242 
243  if(verbosity>0) {
244  std::cout << "ChargeDividerFP420:TimeResponse: call of PeakShape" << std::endl;
245  }
246  return this->PeakShape( hit );
247  } else if (decoMode) {
248 
249  if(verbosity>0) {
250  std::cout << "ChargeDividerFP420:TimeResponse: call of DeconvolutionShape" << std::endl;
251  }
252  return this->DeconvolutionShape( hit );
253  } else {
254 
255  if(verbosity>0) {
256  std::cout << "ChargeDividerFP420:TimeResponse: no any Shape" << std::endl;
257  }
258  // return hit.getEnergyLoss();
259  return hit.energyLoss();
260 
261  }
262 }
264  //
265  // Aim: return the energyLoss weighted CR-RC shape peaked at t0.
266  //
267 
268  // float xEntry = hit.getX() - hit.getVx();
269  // float yEntry = hit.getY() - hit.getVy();
270  // float zEntry = hit.getZ() - hit.getVz();
271  float xEntry = 0.5;
272  float yEntry = 0.5;
273  float zEntry = 1000.;
274 
275  // unsigned int unitID = hit.getUnitID();
276  unsigned int unitID = hit.detUnitId();
277  // int sScale = 20;
278  int det, zside, sector, zmodule;
279  FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
280  // intindex is a continues numbering of FP420
281  // int zScale=2; unsigned int intindex = sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
282  // int zScale=10; unsigned int intindex = sScale*(sector - 1)+zScale*(zside - 1)+zmodule;
283 
284  float RRR = sqrt(xEntry*xEntry + yEntry*yEntry + zEntry*zEntry);
285  float costheta = zEntry / RRR ;
286  // float theta = acos(min(max(costheta,float(-1.)),float(1.)));
287  // float dist = hit.det().position().mag();
288  // float dist = hit.localPosition().mag();//AZ
289  // float dist = hit.getEntry().mag();
290  // float dist = hit.getEntryLocalP().mag();
291  float dist = (zStationBegPos[sector-1] - 420000.) / costheta;
292  // float dist = (zStationBegPos[sector-1] - hit.getVz()) / costheta;
293  dist = dist/10.;// mm --> cm as light velocity = 30 cm/ns
294 
295  if(verbosity>0) {
296  std::cout << "sector=" << sector << std::endl;
297  std::cout << "zmodule=" << zmodule << std::endl;
298  std::cout << "zStationBegPos[sector-1]=" << zStationBegPos[sector-1] << std::endl;
299  std::cout << "RRR=" << RRR << std::endl;
300  std::cout << "costheta=" << costheta << std::endl;
301  std::cout << "unitID=" << unitID << std::endl;
302  //std::cout << "thetaEntry=" << thetaEntry << std::endl;
303  //std::cout << "my theta=" << theta*180./3.1415927 << std::endl;
304  std::cout << "dist found =" << dist << std::endl;
305  }
306 
307  // Time when read out relative to time hit produced.
308  float t0 = dist/30.; // light velocity = 30 cm/ns
309  float SigmaShape = 52.17;
310  // float tofNorm = (hit.getTof() - t0)/SigmaShape;
311  float tofNorm = (hit.tof() - t0)/SigmaShape;
312 
313  float readTimeNorm = -tofNorm;
314  // return the energyLoss weighted with CR-RC shape peaked at t0.
315 
316  if(verbosity>0) {
317  std::cout << "ChargeDividerFP420:PeakShape::dist=" << dist << std::endl;
318  std::cout << "t0=" <<t0 << std::endl;
319  std::cout << "hit.getTof()=" << hit.tof() << std::endl;
320  std::cout << "tofNorm=" << tofNorm << std::endl;
321  std::cout << "1 + readTimeNorm=" << 1 + readTimeNorm << std::endl;
322  std::cout << "hit.getEnergyLoss()=" << hit.energyLoss() << std::endl;
323  std::cout << "(1 + readTimeNorm)*exp(-readTimeNorm)=" << (1 + readTimeNorm)*exp(-readTimeNorm) << std::endl;
324  std::cout << "return=" << hit.energyLoss()*(1 + readTimeNorm)*exp(-readTimeNorm) << std::endl;
325  }
326  if (1 + readTimeNorm > 0) {
327  // return hit.energyLoss()*(1 + readTimeNorm)*exp(-readTimeNorm);
328  return hit.energyLoss()*(1 + readTimeNorm)*exp(-readTimeNorm);
329  // return hit.getEnergyLoss()*(1 + readTimeNorm)*exp(-readTimeNorm);
330  } else {
331  return 0.;
332  }
333 }
334 
336  //
337  // Aim: return the energyLoss weighted with a gaussian centered at t0
338  //
339  // float xEntry = hit.getX() - hit.getVx();
340  // float yEntry = hit.getY() - hit.getVy();
341  // float zEntry = hit.getZ() - hit.getVz();
342  float xEntry = 0.5;
343  float yEntry = 0.5;
344  float zEntry = 1000.;
345 
346  // unsigned int unitID = hit.getUnitID();
347  unsigned int unitID = hit.detUnitId();
348  // int sScale = 20;
349  int det, zside, sector, zmodule;
350  FP420NumberingScheme::unpackFP420Index(unitID, det, zside, sector, zmodule);
351  // intindex is a continues numbering of FP420
352  // int zScale=2; unsigned int intindex = sScale*(sector - 1)+zScale*(zmodule - 1)+zside;
353  // int zScale=10; unsigned int intindex = sScale*(sector - 1)+zScale*(zside - 1)+zmodule;
354 
355  float RRR = sqrt(xEntry*xEntry + yEntry*yEntry + zEntry*zEntry);
356  float costheta = zEntry / RRR ;
357  // float theta = acos(min(max(costheta,float(-1.)),float(1.)));
358  // float dist = hit.det().position().mag();
359  // float dist = hit.localPosition().mag();//AZ
360  // float dist = hit.getEntry().mag();
361  // float dist = hit.getEntryLocalP().mag();
362  float dist = (zStationBegPos[sector-1] - 420000.) / costheta;
363  // float dist = (zStationBegPos[sector-1] - hit.getVz()) / costheta;
364  dist = dist/10.;// mm --> cm as light velocity = 30 cm/ns
365 
366  if(verbosity>0) {
367  std::cout << "sector=" << sector << std::endl;
368  std::cout << "zmodule=" << zmodule << std::endl;
369  std::cout << "zStationBegPos[sector-1]=" << zStationBegPos[sector-1] << std::endl;
370  std::cout << "RRR=" << RRR << std::endl;
371  std::cout << "costheta=" << costheta << std::endl;
372  std::cout << "unitID=" << unitID << std::endl;
373  //std::cout << "thetaEntry=" << thetaEntry << std::endl;
374  //std::cout << "my theta=" << theta*180./3.1415927 << std::endl;
375  std::cout << "dist found =" << dist << std::endl;
376  }
377 
378  float t0 = dist/30.; // light velocity = 30 cm/ns
379  float SigmaShape = 12.;
380  //fun/pl 1*exp(-0.5*((0.1/30-x)/0.1)**2) 0. 0.08
381  // float SigmaShape = 22.;
382  // float tofNorm = (hit.tof() - t0)/SigmaShape;
383  float tofNorm = (hit.tof() - t0)/SigmaShape;
384  // Time when read out relative to time hit produced.
385  float readTimeNorm = -tofNorm;
386  // return the energyLoss weighted with a gaussian centered at t0
387  // return hit.energyLoss()*exp(-0.5*readTimeNorm*readTimeNorm);
388 
389  if(verbosity>0) {
390  std::cout << "ChargeDividerFP420:DeconvolutionShape::dist=" << dist << std::endl;
391  std::cout << "t0=" <<t0 << std::endl;
392  std::cout << "hit.getTof()=" << hit.tof() << std::endl;
393  std::cout << "tofNorm=" << tofNorm << std::endl;
394  std::cout << "hit.getEnergyLoss()=" << hit.energyLoss() << std::endl;
395  std::cout << "exp(-0.5*readTimeNorm*readTimeNorm)=" << exp(-0.5*readTimeNorm*readTimeNorm) << std::endl;
396  std::cout << "return=" << hit.energyLoss()*exp(-0.5*readTimeNorm*readTimeNorm) << std::endl;
397  }
398  return hit.energyLoss()*exp(-0.5*readTimeNorm*readTimeNorm);
399  // return hit.getEnergyLoss();
400 }
401 
int i
Definition: DBlmapReader.cc:9
float tof() const
deprecated name for timeOfFlight()
Definition: PSimHit.h:72
ChargeDividerFP420(double pit, double az420, double azD2, double azD3, int)
static void unpackFP420Index(const unsigned int &idx, int &det, int &zside, int &station, int &superplane)
int zside(DetId const &)
std::vector< EnergySegmentFP420 > ionization_type
Definition: CDividerFP420.h:16
int ii
Definition: cuy.py:588
Local3DPoint exitPoint() const
Exit point in the local Det frame.
Definition: PSimHit.h:38
T mag() const
Definition: PV3DBase.h:67
float DeconvolutionShape(const PSimHit &)
CDividerFP420::ionization_type divide(const PSimHit &, const double &)
T sqrt(T t)
Definition: SSEVec.h:48
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
void fluctuateEloss(int particleId, float momentum, float eloss, float length, int NumberOfSegmentation, float elossVector[])
float TimeResponse(const PSimHit &)
tuple pid
Definition: sysUtil.py:22
float PeakShape(const PSimHit &)
float energyLoss() const
The energy deposit in the PSimHit, in ???.
Definition: PSimHit.h:75
int particleType() const
Definition: PSimHit.h:85
tuple cout
Definition: gather_cfg.py:121
Local3DPoint entryPoint() const
Entry point in the local Det frame.
Definition: PSimHit.h:35
unsigned int detUnitId() const
Definition: PSimHit.h:93