CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MaterialEffects.cc
Go to the documentation of this file.
1 
2 //Framework Headers
5 
6 //TrackingTools Headers
7 
8 // Famos Headers
13 
21 
22 #include <list>
23 #include <map>
24 #include <string>
25 
27  : PairProduction(0), Bremsstrahlung(0),MuonBremsstrahlung(0),
28  MultipleScattering(0), EnergyLoss(0),
29  NuclearInteraction(0),
30  pTmin(999.), use_hardcoded(1)
31 {
32  // Set the minimal photon energy for a Brem from e+/-
33 
34  use_hardcoded = matEff.getParameter<bool >("use_hardcoded_geometry");
35 
36  bool doPairProduction = matEff.getParameter<bool>("PairProduction");
37  bool doBremsstrahlung = matEff.getParameter<bool>("Bremsstrahlung");
38  bool doEnergyLoss = matEff.getParameter<bool>("EnergyLoss");
39  bool doMultipleScattering = matEff.getParameter<bool>("MultipleScattering");
40  bool doNuclearInteraction = matEff.getParameter<bool>("NuclearInteraction");
41  bool doG4NuclInteraction = matEff.getParameter<bool>("G4NuclearInteraction");
42  bool doMuonBremsstrahlung = matEff.getParameter<bool>("MuonBremsstrahlung");
43 
44  double A = matEff.getParameter<double>("A");
45  double Z = matEff.getParameter<double>("Z");
46  double density = matEff.getParameter<double>("Density");
47  double radLen = matEff.getParameter<double>("RadiationLength");
48 
49  // Set the minimal pT before giving up the dE/dx treatment
50 
51  if ( doPairProduction ) {
52 
53  double photonEnergy = matEff.getParameter<double>("photonEnergy");
54  PairProduction = new PairProductionSimulator(photonEnergy);
55  }
56 
57  if ( doBremsstrahlung ) {
58 
59  double bremEnergy = matEff.getParameter<double>("bremEnergy");
60  double bremEnergyFraction = matEff.getParameter<double>("bremEnergyFraction");
61  Bremsstrahlung = new BremsstrahlungSimulator(bremEnergy,
62  bremEnergyFraction);
63  }
64  //muon Brem+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
65  if ( doMuonBremsstrahlung ) {
66 
67  double bremEnergy = matEff.getParameter<double>("bremEnergy");
68  double bremEnergyFraction = matEff.getParameter<double>("bremEnergyFraction");
69  MuonBremsstrahlung = new MuonBremsstrahlungSimulator(A,Z,density,radLen,bremEnergy,
70  bremEnergyFraction);
71 
72  }
73 
74  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
75 
76  if ( doEnergyLoss ) {
77 
78  pTmin = matEff.getParameter<double>("pTmin");
79  EnergyLoss = new EnergyLossSimulator(A,Z,density,radLen);
80 
81  }
82 
83  if ( doMultipleScattering ) {
84 
85  MultipleScattering = new MultipleScatteringSimulator(A,Z,density,radLen);
86 
87  }
88 
89 
90  if ( doNuclearInteraction ) {
91 
92  // The energies simulated
93  std::vector<double> hadronEnergies
94  = matEff.getUntrackedParameter<std::vector<double> >("hadronEnergies");
95 
96  // The particle types simulated
97  std::vector<int> hadronTypes
98  = matEff.getUntrackedParameter<std::vector<int> >("hadronTypes");
99 
100  // The corresponding particle names
101  std::vector<std::string> hadronNames
102  = matEff.getUntrackedParameter<std::vector<std::string> >("hadronNames");
103 
104  // The corresponding particle masses
105  std::vector<double> hadronMasses
106  = matEff.getUntrackedParameter<std::vector<double> >("hadronMasses");
107 
108  // The smallest momentum for inelastic interactions
109  std::vector<double> hadronPMin
110  = matEff.getUntrackedParameter<std::vector<double> >("hadronMinP");
111 
112  // The interaction length / radiation length ratio for each particle type
113  std::vector<double> lengthRatio
114  = matEff.getParameter<std::vector<double> >("lengthRatio");
115  // std::map<int,double> lengthRatio;
116  // for ( unsigned i=0; i<theLengthRatio.size(); ++i )
117  // lengthRatio[ hadronTypes[i] ] = theLengthRatio[i];
118 
119  // A global fudge factor for TEC layers (which apparently do not react to
120  // hadrons the same way as all other layers...
121  theTECFudgeFactor = matEff.getParameter<double>("fudgeFactor");
122 
123  // The evolution of the interaction lengths with energy
124  std::vector<double> theRatios
125  = matEff.getUntrackedParameter<std::vector<double> >("ratios");
126  //std::map<int,std::vector<double> > ratios;
127  //for ( unsigned i=0; i<hadronTypes.size(); ++i ) {
128  // for ( unsigned j=0; j<hadronEnergies.size(); ++j ) {
129  // ratios[ hadronTypes[i] ].push_back(theRatios[ i*hadronEnergies.size() + j ]);
130  // }
131  //}
132  std::vector< std::vector<double> > ratios;
133  ratios.resize(hadronTypes.size());
134  for ( unsigned i=0; i<hadronTypes.size(); ++i ) {
135  for ( unsigned j=0; j<hadronEnergies.size(); ++j ) {
136  ratios[i].push_back(theRatios[ i*hadronEnergies.size() + j ]);
137  }
138  }
139 
140  // The smallest momentum for elastic interactions
141  double pionEnergy
142  = matEff.getParameter<double>("pionEnergy");
143 
144  // The algorithm to compute the distance between primary and secondaries
145  // when a nuclear interaction occurs
146  unsigned distAlgo
147  = matEff.getParameter<unsigned>("distAlgo");
148  double distCut
149  = matEff.getParameter<double>("distCut");
150 
151  // The file to read the starting interaction in each files
152  // (random reproducibility in case of a crash)
154  = matEff.getUntrackedParameter<std::string>("inputFile");
155 
156  // Build the ID map (i.e., what is to be considered as a proton, etc...)
157  std::map<int,int> idMap;
158  // Protons
159  std::vector<int> idProtons
160  = matEff.getUntrackedParameter<std::vector<int> >("protons");
161  for ( unsigned i=0; i<idProtons.size(); ++i )
162  idMap[idProtons[i]] = 2212;
163  // Anti-Protons
164  std::vector<int> idAntiProtons
165  = matEff.getUntrackedParameter<std::vector<int> >("antiprotons");
166  for ( unsigned i=0; i<idAntiProtons.size(); ++i )
167  idMap[idAntiProtons[i]] = -2212;
168  // Neutrons
169  std::vector<int> idNeutrons
170  = matEff.getUntrackedParameter<std::vector<int> >("neutrons");
171  for ( unsigned i=0; i<idNeutrons.size(); ++i )
172  idMap[idNeutrons[i]] = 2112;
173  // Anti-Neutrons
174  std::vector<int> idAntiNeutrons
175  = matEff.getUntrackedParameter<std::vector<int> >("antineutrons");
176  for ( unsigned i=0; i<idAntiNeutrons.size(); ++i )
177  idMap[idAntiNeutrons[i]] = -2112;
178  // K0L's
179  std::vector<int> idK0Ls
180  = matEff.getUntrackedParameter<std::vector<int> >("K0Ls");
181  for ( unsigned i=0; i<idK0Ls.size(); ++i )
182  idMap[idK0Ls[i]] = 130;
183  // K+'s
184  std::vector<int> idKplusses
185  = matEff.getUntrackedParameter<std::vector<int> >("Kplusses");
186  for ( unsigned i=0; i<idKplusses.size(); ++i )
187  idMap[idKplusses[i]] = 321;
188  // K-'s
189  std::vector<int> idKminusses
190  = matEff.getUntrackedParameter<std::vector<int> >("Kminusses");
191  for ( unsigned i=0; i<idKminusses.size(); ++i )
192  idMap[idKminusses[i]] = -321;
193  // pi+'s
194  std::vector<int> idPiplusses
195  = matEff.getUntrackedParameter<std::vector<int> >("Piplusses");
196  for ( unsigned i=0; i<idPiplusses.size(); ++i )
197  idMap[idPiplusses[i]] = 211;
198  // pi-'s
199  std::vector<int> idPiminusses
200  = matEff.getUntrackedParameter<std::vector<int> >("Piminusses");
201  for ( unsigned i=0; i<idPiminusses.size(); ++i )
202  idMap[idPiminusses[i]] = -211;
203 
204  // Construction
205  if ( doG4NuclInteraction ) {
206  NuclearInteraction = new NuclearInteractionFTFSimulator(distAlgo, distCut);
207  } else {
209  new NuclearInteractionSimulator(hadronEnergies, hadronTypes, hadronNames,
210  hadronMasses, hadronPMin, pionEnergy,
211  lengthRatio, ratios, idMap,
212  inputFile, distAlgo, distCut);
213  }
214  }
215 }
216 
218 
219  if ( PairProduction ) delete PairProduction;
220  if ( Bremsstrahlung ) delete Bremsstrahlung;
221  if ( EnergyLoss ) delete EnergyLoss;
224  //Muon Brem
226 }
227 
229  const TrackerLayer& layer,
230  ParticlePropagator& myTrack,
231  unsigned itrack,
233 
235  double radlen;
236  theEnergyLoss = 0;
237  theNormalVector = normalVector(layer,myTrack);
238  radlen = radLengths(layer,myTrack);
239 
240  //std::cout << "### MaterialEffects: for Track= " << itrack << " in layer #"
241  // << layer.layerNumber() << std::endl;
242  //std::cout << myTrack << std::endl;
243 
244 //-------------------
245 // Photon Conversion
246 //-------------------
247 
248  if ( PairProduction && myTrack.pid()==22 ) {
249 
250  //
251  PairProduction->updateState(myTrack, radlen, random);
252 
253  if ( PairProduction->nDaughters() ) {
254  //add a vertex to the mother particle
255  int ivertex = mySimEvent.addSimVertex(myTrack.vertex(),itrack,
257 
258  // Check if it is a valid vertex first:
259  if (ivertex>=0) {
260  // This was a photon that converted
261  for ( DaughterIter = PairProduction->beginDaughters();
262  DaughterIter != PairProduction->endDaughters();
263  ++DaughterIter) {
264 
265  mySimEvent.addSimTrack(&(*DaughterIter), ivertex);
266 
267  }
268  // The photon converted. Return.
269  return;
270  }
271  else {
272  edm::LogWarning("MaterialEffects") << " WARNING: A non valid vertex was found in photon conv. -> " << ivertex << std::endl;
273  }
274 
275  }
276 
277  }
278 
279  if ( myTrack.pid() == 22 ) return;
280 
281 //------------------------
282 // Nuclear interactions
283 //------------------------
284 
285  if ( NuclearInteraction && abs(myTrack.pid()) > 100
286  && abs(myTrack.pid()) < 1000000) {
287 
288  // Simulate a nuclear interaction
289  double factor = 1.0;
290  if(use_hardcoded){
291  if (layer.layerNumber() >= 19 && layer.layerNumber() <= 27 )
292  factor = theTECFudgeFactor;
293  }
294  NuclearInteraction->updateState(myTrack, radlen*factor, random);
295 
296  //std::cout << "MaterialEffects: nDaughters= "
297  // << NuclearInteraction->nDaughters() << std::endl;
298  if ( NuclearInteraction->nDaughters() ) {
299 
300  //add a end vertex to the mother particle
301  int ivertex = mySimEvent.addSimVertex(myTrack.vertex(),itrack,
303  //std::cout << "ivertex= " << ivertex << " nDaughters= "
304  // << NuclearInteraction->nDaughters() << std::endl;
305  // Check if it is a valid vertex first:
306  if (ivertex>=0) {
307  // This was a hadron that interacted inelastically
308  int idaugh = 0;
309  for ( DaughterIter = NuclearInteraction->beginDaughters();
310  DaughterIter != NuclearInteraction->endDaughters();
311  ++DaughterIter) {
312 
313  // The daughter in the event
314  int daughId = mySimEvent.addSimTrack(&(*DaughterIter), ivertex);
315 
316  // Store the closest daughter in the mother info (for later tracking purposes)
317  if ( NuclearInteraction->closestDaughterId() == idaugh ) {
318  if ( mySimEvent.track(itrack).vertex().position().Pt() < 4.0 )
319  mySimEvent.track(itrack).setClosestDaughterId(daughId);
320  }
321  ++idaugh;
322  }
323  // The hadron is destroyed. Return.
324  return;
325  }
326  else {
327  edm::LogWarning("MaterialEffects") << " WARNING: A non valid vertex was found in nucl. int. -> " << ivertex << std::endl;
328  }
329 
330  }
331 
332  }
333 
334  if ( myTrack.charge() == 0 ) return;
335 
337 
338 //----------------
339 // Bremsstrahlung
340 //----------------
341 
342  if ( Bremsstrahlung && abs(myTrack.pid())==11 ) {
343 
344  Bremsstrahlung->updateState(myTrack,radlen, random);
345 
346  if ( Bremsstrahlung->nDaughters() ) {
347 
348  // Add a vertex, but do not attach it to the electron, because it
349  // continues its way...
350  int ivertex = mySimEvent.addSimVertex(myTrack.vertex(),itrack,
352 
353  // Check if it is a valid vertex first:
354  if (ivertex>=0) {
355  for ( DaughterIter = Bremsstrahlung->beginDaughters();
356  DaughterIter != Bremsstrahlung->endDaughters();
357  ++DaughterIter) {
358  mySimEvent.addSimTrack(&(*DaughterIter), ivertex);
359  }
360  }
361  else {
362  edm::LogWarning("MaterialEffects") << " WARNING: A non valid vertex was found in brem -> " << ivertex << std::endl;
363  }
364 
365  }
366 
367  }
368 
369 //---------------------------
370 // Muon_Bremsstrahlung
371 //--------------------------
372 
373  if ( MuonBremsstrahlung && abs(myTrack.pid())==13 ) {
374 
375  MuonBremsstrahlung->updateState(myTrack, radlen, random);
376 
377  if ( MuonBremsstrahlung->nDaughters() ) {
378 
379  // Add a vertex, but do not attach it to the muon, because it
380  // continues its way...
381  int ivertex = mySimEvent.addSimVertex(myTrack.vertex(),itrack,
383 
384  // Check if it is a valid vertex first:
385  if (ivertex>=0) {
386  for ( DaughterIter = MuonBremsstrahlung->beginDaughters();
387  DaughterIter != MuonBremsstrahlung->endDaughters();
388  ++DaughterIter) {
389  mySimEvent.addSimTrack(&(*DaughterIter), ivertex);
390  }
391  }
392  else {
393  edm::LogWarning("MaterialEffects") << " WARNING: A non valid vertex was found in muon brem -> " << ivertex << std::endl;
394  }
395 
396  }
397 
398  }
399 
403 
404  if ( EnergyLoss )
405  {
406  theEnergyLoss = myTrack.E();
407  EnergyLoss->updateState(myTrack, radlen, random);
408  theEnergyLoss -= myTrack.E();
409  }
410 
411 
415 
416  if ( MultipleScattering && myTrack.Pt() > pTmin ) {
417  // MultipleScattering->setNormalVector(normalVector(layer,myTrack));
419  MultipleScattering->updateState(myTrack,radlen, random);
420  }
421 
422 }
423 
424 double
426  ParticlePropagator& myTrack) {
427 
428  // Thickness of layer
430 
431  GlobalVector P(myTrack.Px(),myTrack.Py(),myTrack.Pz());
432 
433  // Effective length of track inside layer (considering crossing angle)
434  // double radlen = theThickness / fabs(P.dot(theNormalVector)/(P.mag()*theNormalVector.mag()));
435  double radlen = theThickness / fabs(P.dot(theNormalVector)) * P.mag();
436 
437  // This is a series of fudge factors (from the geometry description),
438  // to describe the layer inhomogeneities (services, cables, supports...)
439  double rad = myTrack.R();
440  double zed = fabs(myTrack.Z());
441 
442  double factor = 1;
443 
444  // Are there fudge factors for this layer
445  if ( layer.fudgeNumber() )
446 
447  // If yes, loop on them
448  for ( unsigned int iLayer=0; iLayer < layer.fudgeNumber(); ++iLayer ) {
449 
450  // Apply to R if forward layer, to Z if barrel layer
451  if ( ( layer.forward() && layer.fudgeMin(iLayer) < rad && rad < layer.fudgeMax(iLayer) ) ||
452  ( !layer.forward() && layer.fudgeMin(iLayer) < zed && zed < layer.fudgeMax(iLayer) ) ) {
453  factor = layer.fudgeFactor(iLayer);
454  break;
455  }
456 
457  }
458 
459  theThickness *= factor;
460 
461  return radlen * factor;
462 
463 }
464 
467  ParticlePropagator& myTrack ) const {
468  return layer.forward() ?
469  layer.disk()->normalVector() :
470  GlobalVector(myTrack.X(),myTrack.Y(),0.)/myTrack.R();
471 }
472 
473 void
475 
476  // Save current nuclear interactions in the event libraries.
478 
479 }
const double Z[kNumberCalorimeter]
T getParameter(std::string const &) const
int addSimVertex(const XYZTLorentzVector &decayVertex, int im=-1, FSimVertexType::VertexType type=FSimVertexType::ANY)
Add a new vertex to the Event and to the various lists.
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
float radLen() const
RHEP_const_iter beginDaughters() const
Returns const iterator to the beginning of the daughters list.
int addSimTrack(const RawParticle *p, int iv, int ig=-1, const HepMC::GenVertex *ev=0)
Add a new track to the Event and to the various lists.
unsigned nDaughters() const
Returns the number of daughters.
unsigned int layerNumber() const
Returns the layer number.
Definition: TrackerLayer.h:82
bool forward() const
Is the layer forward ?
Definition: TrackerLayer.h:70
double fudgeFactor(unsigned iFudge) const
Definition: TrackerLayer.h:108
int closestDaughterId()
The id of the closest charged daughter (filled for nuclear interactions only)
dictionary ratios
Definition: plotFactory.py:68
void setNormalVector(const GlobalVector &normal)
Sets the vector normal to the surface traversed.
~MaterialEffects()
Default destructor.
PairProductionSimulator * PairProduction
#define P
GlobalVector normalVector(const TrackerLayer &layer, ParticlePropagator &myTrack) const
The vector normal to the surface traversed.
void setClosestDaughterId(int id)
Set the index of the closest charged daughter.
Definition: FSimTrack.h:184
void updateState(ParticlePropagator &myTrack, double radlen, RandomEngineAndDistribution const *)
Compute the material effect (calls the sub class)
int pid() const
get the HEP particle ID number
Definition: RawParticle.h:265
TRandom random
Definition: MVATrainer.cc:138
MaterialEffectsSimulator * NuclearInteraction
MuonBremsstrahlungSimulator * MuonBremsstrahlung
double R() const
vertex radius
Definition: RawParticle.h:278
double fudgeMax(unsigned iFudge) const
Definition: TrackerLayer.h:105
std::vector< RawParticle >::const_iterator RHEP_const_iter
const math::XYZTLorentzVector & position() const
Temporary (until CMSSW moves to Mathcore) - No ! Actually very useful.
Definition: FSimVertex.h:49
double Y() const
y of vertex
Definition: RawParticle.h:275
double Z() const
z of vertex
Definition: RawParticle.h:276
BoundDisk const * disk() const
Returns the surface.
Definition: TrackerLayer.h:79
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
RHEP_const_iter endDaughters() const
Returns const iterator to the end of the daughters list.
int j
Definition: DBlmapReader.cc:9
void save()
Save nuclear interaction information.
const FSimVertex & vertex() const
Origin vertex.
double charge() const
get the MEASURED charge
Definition: RawParticle.h:282
unsigned int fudgeNumber() const
Set a fudge factor for material inhomogeneities in this layer.
Definition: TrackerLayer.h:101
const BoundSurface & surface() const
Returns the surface.
Definition: TrackerLayer.h:73
const XYZTLorentzVector & vertex() const
the vertex fourvector
Definition: RawParticle.h:285
void interact(FSimEvent &simEvent, const TrackerLayer &layer, ParticlePropagator &PP, unsigned i, RandomEngineAndDistribution const *)
double radLengths(const TrackerLayer &layer, ParticlePropagator &myTrack)
The number of radiation lengths traversed.
double X() const
x of vertex
Definition: RawParticle.h:274
BremsstrahlungSimulator * Bremsstrahlung
GlobalVector theNormalVector
double fudgeMin(unsigned iFudge) const
Definition: TrackerLayer.h:102
EnergyLossSimulator * EnergyLoss
const MediumProperties & mediumProperties() const
Definition: Surface.h:120
virtual void save()
Used by NuclearInteractionSimulator to save last sampled event.
MultipleScatteringSimulator * MultipleScattering
Global3DVector GlobalVector
Definition: GlobalVector.h:10
MaterialEffects(const edm::ParameterSet &matEff)
Constructor.
FSimTrack & track(int id) const
Return track with given Id.