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