CMS 3D CMS Logo

MaterialBudgetData.cc
Go to the documentation of this file.
2 
4 
5 #include "G4Step.hh"
6 #include "G4Material.hh"
7 #include "G4EventManager.hh"
8 #include "G4Event.hh"
9 
10 //#define TREE_DEBUG
11 
13 {
14  //instantiate categorizer to assign an ID to volumes and materials
16  allStepsToTree = false;
17  densityConvertionFactor = 6.24E18;
18 }
19 
21 }
22 
24 {
25  allStepsToTree = true;
26  MAXNUMBERSTEPS = 0;
27  MAXNUMBERSTEPS = 10000;
28  theDmb = new float[MAXNUMBERSTEPS];
29  theDil = new float[MAXNUMBERSTEPS];
30  // rr
31  theSupportDmb = new float[MAXNUMBERSTEPS];
32  theSensitiveDmb = new float[MAXNUMBERSTEPS];
33  theCablesDmb = new float[MAXNUMBERSTEPS];
34  theCoolingDmb = new float[MAXNUMBERSTEPS];
35  theElectronicsDmb = new float[MAXNUMBERSTEPS];
36  theOtherDmb = new float[MAXNUMBERSTEPS];
37  theAirDmb = new float[MAXNUMBERSTEPS];
38  theSupportDil = new float[MAXNUMBERSTEPS];
39  theSensitiveDil = new float[MAXNUMBERSTEPS];
40  theCablesDil = new float[MAXNUMBERSTEPS];
41  theCoolingDil = new float[MAXNUMBERSTEPS];
42  theElectronicsDil = new float[MAXNUMBERSTEPS];
43  theOtherDil = new float[MAXNUMBERSTEPS];
44  theAirDil = new float[MAXNUMBERSTEPS];
45  // rr
46  theInitialX = new double[MAXNUMBERSTEPS];
47  theInitialY = new double[MAXNUMBERSTEPS];
48  theInitialZ = new double[MAXNUMBERSTEPS];
49  theFinalX = new double[MAXNUMBERSTEPS];
50  theFinalY = new double[MAXNUMBERSTEPS];
51  theFinalZ = new double[MAXNUMBERSTEPS];
52  // rr
53  theVolumeID = new int[MAXNUMBERSTEPS];
55  theVolumeCopy = new int[MAXNUMBERSTEPS];
56  theVolumeX = new float[MAXNUMBERSTEPS];
57  theVolumeY = new float[MAXNUMBERSTEPS];
58  theVolumeZ = new float[MAXNUMBERSTEPS];
59  theVolumeXaxis1 = new float[MAXNUMBERSTEPS];
60  theVolumeXaxis2 = new float[MAXNUMBERSTEPS];
61  theVolumeXaxis3 = new float[MAXNUMBERSTEPS];
62  theVolumeYaxis1 = new float[MAXNUMBERSTEPS];
63  theVolumeYaxis2 = new float[MAXNUMBERSTEPS];
64  theVolumeYaxis3 = new float[MAXNUMBERSTEPS];
65  theVolumeZaxis1 = new float[MAXNUMBERSTEPS];
66  theVolumeZaxis2 = new float[MAXNUMBERSTEPS];
67  theVolumeZaxis3 = new float[MAXNUMBERSTEPS];
68  theMaterialID = new int[MAXNUMBERSTEPS];
70  theMaterialX0 = new float[MAXNUMBERSTEPS];
73  theStepID = new int[MAXNUMBERSTEPS];
74  theStepInitialPt = new float[MAXNUMBERSTEPS];
75  theStepInitialEta = new float[MAXNUMBERSTEPS];
76  theStepInitialPhi = new float[MAXNUMBERSTEPS];
78  theStepInitialPx = new float[MAXNUMBERSTEPS];
79  theStepInitialPy = new float[MAXNUMBERSTEPS];
80  theStepInitialPz = new float[MAXNUMBERSTEPS];
84  theStepFinalPt = new float[MAXNUMBERSTEPS];
85  theStepFinalEta = new float[MAXNUMBERSTEPS];
86  theStepFinalPhi = new float[MAXNUMBERSTEPS];
88  theStepFinalPx = new float[MAXNUMBERSTEPS];
89  theStepFinalPy = new float[MAXNUMBERSTEPS];
90  theStepFinalPz = new float[MAXNUMBERSTEPS];
91  theStepFinalBeta = new float[MAXNUMBERSTEPS];
92  theStepFinalGamma = new float[MAXNUMBERSTEPS];
93  theStepFinalMass = new float[MAXNUMBERSTEPS];
96  // rr
97 }
98 
99 
100 void MaterialBudgetData::dataStartTrack( const G4Track* aTrack )
101 {
102  const G4ThreeVector& dir = aTrack->GetMomentum() ;
103 
105 
106  theStepN=0;
107  theTotalMB=0;
108  theTotalIL=0;
109  theEta=0;
110  thePhi=0;
111 
112  // rr
113  theID=0;
114  thePt=0;
115  theEnergy=0;
116  theMass=0;
117 
118  theSupportMB = 0.;
119  theSensitiveMB = 0.;
120  theCablesMB = 0.;
121  theCoolingMB = 0.;
122  theElectronicsMB = 0.;
123  theOtherMB = 0.;
124  theAirMB = 0.;
125  theSupportIL = 0.;
126  theSensitiveIL = 0.;
127  theCablesIL = 0.;
128  theCoolingIL = 0.;
129  theElectronicsIL = 0.;
130  theOtherIL = 0.;
131  theAirIL = 0.;
134  theCablesFractionMB = 0.;
137  theOtherFractionMB = 0.;
138  theAirFractionMB = 0.;
141  theCablesFractionIL = 0.;
144  theOtherFractionIL = 0.;
145  theAirFractionIL = 0.;
146  // rr
147 
148  theID = (int)(aTrack->GetDefinition()->GetPDGEncoding());
149  thePt = dir.perp();
150  if( dir.theta() != 0 ) {
151  theEta = dir.eta();
152  } else {
153  theEta = -99;
154  }
155  // thePhi = dir.phi()/deg; // better not to store in deg
156  thePhi = dir.phi();
157  theEnergy = aTrack->GetTotalEnergy();
158  theMass = aTrack->GetDefinition()->GetPDGMass();
159 
160 }
161 
162 
163 void MaterialBudgetData::dataEndTrack( const G4Track* aTrack )
164 {
165  //- std::cout << "[OVAL] MaterialBudget " << G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID() << " " << theEta << " " << thePhi << " " << theTotalMB << std::endl;
166  // rr
167  std::cout << "Recorded steps " << theStepN << std::endl;
168  std::cout << " Material Budget: Radiation Length " << "G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID()" << " eta " << theEta << " phi " << thePhi << " total X " << theTotalMB << " SUP " << theSupportMB << " SEN " << theSensitiveMB << " CAB " << theCablesMB << " COL " << theCoolingMB << " ELE " << theElectronicsMB << " other " << theOtherMB << " Air " << theAirMB << std::endl;
169  std::cout << " Material Budget: Interaction Length " << "G4EventManager::GetEventManager()->GetConstCurrentEvent()->GetEventID()" << " eta " << theEta << " phi " << thePhi << " total L " << theTotalIL << " SUP " << theSupportIL << " SEN " << theSensitiveIL << " CAB " << theCablesIL << " COL " << theCoolingIL << " ELE " << theElectronicsIL << " other " << theOtherIL << " Air " << theAirIL << std::endl;
170  // rr
171 }
172 
173 void MaterialBudgetData::dataPerStep( const G4Step* aStep )
174 {
175  assert(aStep);
176  G4StepPoint* prePoint = aStep->GetPreStepPoint();
177  G4StepPoint* postPoint = aStep->GetPostStepPoint();
178  assert(prePoint);
179  assert(postPoint);
180  G4Material * theMaterialPre = prePoint->GetMaterial();
181  assert(theMaterialPre);
182 
183  CLHEP::Hep3Vector prePos = prePoint->GetPosition();
184  CLHEP::Hep3Vector postPos = postPoint->GetPosition();
185 
186  G4double steplen = aStep->GetStepLength();
187 
188  G4double radlen = theMaterialPre->GetRadlen();
189  G4double intlen = theMaterialPre->GetNuclearInterLength();
190  G4double density = theMaterialPre->GetDensity() / densityConvertionFactor; // always g/cm3
191 
192  G4String materialName = theMaterialPre->GetName();
193  std::cout << " steplen " << steplen << " radlen " << radlen << " mb " << steplen/radlen << " mate " << theMaterialPre->GetName() << std::endl;
194 
195  G4String volumeName = aStep->GetPreStepPoint()->GetTouchable()->GetVolume(0)->GetLogicalVolume()->GetName();
196  std::cout << " Volume " << volumeName << "\n";
197  std::cout << " Material " << materialName << "\n";
198 
199  // instantiate the categorizer
201  int volumeID = myMaterialBudgetCategorizer->volume( volumeName );
202  int materialID = myMaterialBudgetCategorizer->material( materialName );
203  std::cout << "Volume ID " << volumeID << " and material ID " << materialID << "\n";
204 
205  // FIXME: Both volume ID and material ID are zeros, so this part is not executed leaving all
206  // values as zeros.
207  if(!myMaterialBudgetCategorizer->x0fraction(materialName).empty())
208  {
216 
217  if(theOtherFractionMB!=0) std::cout << " material found with no category " << materialName
218  << " in volume " << volumeName << std::endl;
226  if(theOtherFractionIL!=0) std::cout << " material found with no category " << materialName
227  << " in volume " << volumeName << std::endl;
228  }
229  else
230  {
231  theOtherFractionMB = 1;
232  theOtherFractionIL = 1;
233  }
234  // if(theOtherFractionMB!=0) LogDebug("MaterialBudgetData") << " material found with no category " << name
235  // << " in volume " << lv->GetName();
236  // rr
237 
238  float dmb = steplen/radlen;
239  float dil = steplen/intlen;
240 
241  G4VPhysicalVolume* pv = aStep->GetPreStepPoint()->GetPhysicalVolume();
242  const G4VTouchable* t = aStep->GetPreStepPoint()->GetTouchable();
243  const G4ThreeVector& objectTranslation = t->GetTranslation();
244  const G4RotationMatrix* objectRotation = t->GetRotation();
245  const G4VProcess* interactionPre = prePoint->GetProcessDefinedStep();
246  const G4VProcess* interactionPost = postPoint->GetProcessDefinedStep();
247 
248  G4Track* track = aStep->GetTrack();
249  if(theStepN==0) std::cout << " Simulated Particle " << theID << "\tMass " << theMass << " MeV/c2"
250  << "\tPt = " << thePt << " MeV/c" << "\tEta = " << theEta << "\tPhi = " << thePhi
251  << "\tEnergy = " << theEnergy << " MeV"
252  // << std::endl
253  // << "\tMagnetic Field at (0,0,0): (" << B000[0] << "," < B000[1] << "," << B000[2] << ")"
254  << std::endl;
255 
256  //fill data per step
257  if( allStepsToTree ){
259  theDmb[theStepN] = dmb;
260  theDil[theStepN] = dil;
275  theInitialX[theStepN] = prePos.x();
276  theInitialY[theStepN] = prePos.y();
277  theInitialZ[theStepN] = prePos.z();
278  theFinalX[theStepN] = postPos.x();
279  theFinalY[theStepN] = postPos.y();
280  theFinalZ[theStepN] = postPos.z();
281  theVolumeID[theStepN] = volumeID;
282  theVolumeName[theStepN] = volumeName;
283  theVolumeCopy[theStepN] = pv->GetCopyNo();
284  theVolumeX[theStepN] = objectTranslation.x();
285  theVolumeY[theStepN] = objectTranslation.y();
286  theVolumeZ[theStepN] = objectTranslation.z();
287  theVolumeXaxis1[theStepN] = objectRotation->xx();
288  theVolumeXaxis2[theStepN] = objectRotation->xy();
289  theVolumeXaxis3[theStepN] = objectRotation->xz();
290  theVolumeYaxis1[theStepN] = objectRotation->yx();
291  theVolumeYaxis2[theStepN] = objectRotation->yy();
292  theVolumeYaxis3[theStepN] = objectRotation->yz();
293  theVolumeZaxis1[theStepN] = objectRotation->zx();
294  theVolumeZaxis2[theStepN] = objectRotation->zy();
295  theVolumeZaxis3[theStepN] = objectRotation->zz();
296  theMaterialID[theStepN] = materialID;
297  theMaterialName[theStepN] = materialName;
298  theMaterialX0[theStepN] = radlen;
299  theMaterialLambda0[theStepN] = intlen;
300  theMaterialDensity[theStepN] = density;
301  theStepID[theStepN] = track->GetDefinition()->GetPDGEncoding();
302  theStepInitialPt[theStepN] = prePoint->GetMomentum().perp();
303  theStepInitialEta[theStepN] = prePoint->GetMomentum().eta();
304  theStepInitialPhi[theStepN] = prePoint->GetMomentum().phi();
305  theStepInitialEnergy[theStepN] = prePoint->GetTotalEnergy();
306  theStepInitialPx[theStepN] = prePoint->GetMomentum().x();
307  theStepInitialPy[theStepN] = prePoint->GetMomentum().y();
308  theStepInitialPz[theStepN] = prePoint->GetMomentum().z();
309  theStepInitialBeta[theStepN] = prePoint->GetBeta();
310  theStepInitialGamma[theStepN] = prePoint->GetGamma();
311  theStepInitialMass[theStepN] = prePoint->GetMass();
312  theStepFinalPt[theStepN] = postPoint->GetMomentum().perp();
313  theStepFinalEta[theStepN] = postPoint->GetMomentum().eta();
314  theStepFinalPhi[theStepN] = postPoint->GetMomentum().phi();
315  theStepFinalEnergy[theStepN] = postPoint->GetTotalEnergy();
316  theStepFinalPx[theStepN] = postPoint->GetMomentum().x();
317  theStepFinalPy[theStepN] = postPoint->GetMomentum().y();
318  theStepFinalPz[theStepN] = postPoint->GetMomentum().z();
319  theStepFinalBeta[theStepN] = postPoint->GetBeta();
320  theStepFinalGamma[theStepN] = postPoint->GetGamma();
321  theStepFinalMass[theStepN] = postPoint->GetMass();
322  int preProcType = -99;
323  int postProcType = -99;
324  if (interactionPre) preProcType = interactionPre->GetProcessType();
325  theStepPreProcess[theStepN] = preProcType;
326  if (interactionPost) postProcType = interactionPost->GetProcessType();
327  theStepPostProcess[theStepN] = postProcType;
328 #ifdef TREE_DEBUG
329  std::cout << " step " << theStepN
330  << "\tDelta MB = " << theDmb[theStepN]
331  << std::endl
332  << "\t\tSupport " << theSupportDmb[theStepN]
333  << " Sensitive " << theSensitiveDmb[theStepN]
334  << " Cables " << theCablesDmb[theStepN]
335  << " Cooling " << theCoolingDmb[theStepN]
336  << " Electronics " << theElectronicsDmb[theStepN]
337  << " Other " << theOtherDmb[theStepN]
338  << " Air " << theAirDmb[theStepN]
339  << std::endl
340  << "\tDelta IL = " << theDil[theStepN]
341  << std::endl
342  << "\t\tSupport " << theSupportDil[theStepN]
343  << " Sensitive " << theSensitiveDil[theStepN]
344  << " Cables " << theCablesDil[theStepN]
345  << " Cooling " << theCoolingDil[theStepN]
346  << " Electronics " << theElectronicsDil[theStepN]
347  << " Other " << theOtherDil[theStepN]
348  << " Air " << theAirDil[theStepN]
349  << std::endl;
350  if (interactionPre)
351  std::cout << "\tProcess Pre " << interactionPre->GetProcessName()
352  << " type " << theStepPreProcess[theStepN] << " " << interactionPre->GetProcessTypeName(G4ProcessType(theStepPreProcess[theStepN]))
353  << std::endl;
354  if (interactionPost)
355  std::cout << "\tProcess Post " << interactionPost->GetProcessName()
356  << " type " << theStepPostProcess[theStepN] << " "
357  << interactionPost->GetProcessTypeName(G4ProcessType(theStepPostProcess[theStepN]))
358  << std::endl;
359  std::cout << "\tPre x = " << theInitialX[theStepN]
360  << "\ty = " << theInitialY[theStepN]
361  << "\tz = " << theInitialZ[theStepN]
362  << "\tPolar Radius = " << sqrt(prePos.x()*prePos.x()+prePos.y()*prePos.y())
363  << "\tPt = " << theStepInitialPt[theStepN]
364  << "\tEnergy = " << theStepInitialEnergy[theStepN]
365  // << std::endl
366  // << "B-field(T) at Pre (cm): " << field->fieldInTesla(GlobalPoint(pos.x()/10.,pos.y()/10.,pos.z()/10.))
367  << std::endl;
368  std::cout << "\tPost x = " << theFinalX[theStepN]
369  << "\ty = " << theFinalY[theStepN]
370  << "\tz = " << theFinalZ[theStepN]
371  << "\tPolar Radius = " << sqrt(postPos.x()*postPos.x()+postPos.y()*postPos.y())
372  << "\tPt = " << theStepFinalPt[theStepN]
373  << "\tEnergy = " << theStepFinalEnergy[theStepN]
374  << std::endl;
375  std::cout << "\tvolume " << volumeID << " " << theVolumeName[theStepN]
376  << " copy number " << theVolumeCopy[theStepN]
377  << "\tmaterial " << theMaterialID[theStepN] << " " << theMaterialName[theStepN]
378  << "\tDensity = " << theMaterialDensity[theStepN] << " g/cm3"
379  << "\tX0 = " << theMaterialX0[theStepN] << " mm"
380  << "\tLambda0 = " << theMaterialLambda0[theStepN] << " mm"
381  << std::endl;
382  std::cout << "\t\tParticle " << theStepID[theStepN]
383  << " Initial Pt = " << theStepInitialPt[theStepN] << " MeV/c"
384  << " eta = " << theStepInitialEta[theStepN]
385  << " phi = " << theStepInitialPhi[theStepN]
386  << " Energy = " << theStepInitialEnergy[theStepN] << " MeV"
387  << " Mass = " << theStepInitialMass[theStepN] << " MeV/c2"
388  << " Beta = " << theStepInitialBeta[theStepN]
389  << " Gamma = " << theStepInitialGamma[theStepN]
390  << std::endl
391  << "\t\tParticle " << theStepID[theStepN]
392  << " Final Pt = " << theStepFinalPt[theStepN] << " MeV/c"
393  << " eta = " << theStepFinalEta[theStepN]
394  << " phi = " << theStepFinalPhi[theStepN]
395  << " Energy = " << theStepFinalEnergy[theStepN] << " MeV"
396  << " Mass = " << theStepFinalMass[theStepN] << " MeV/c2"
397  << " Beta = " << theStepFinalBeta[theStepN]
398  << " Gamma = " << theStepFinalGamma[theStepN]
399  << std::endl;
400  std:: cout << "\tVolume Centre x = " << theVolumeX[theStepN]
401  << "\ty = " << theVolumeY[theStepN]
402  << "\tz = " << theVolumeZ[theStepN]
403  << "\tPolar Radius = " << sqrt( theVolumeX[theStepN]*theVolumeX[theStepN] +
404  theVolumeY[theStepN]*theVolumeY[theStepN] )
405  << std::endl;
406  std::cout << "\tx axis = ("
407  << theVolumeXaxis1[theStepN] << ","
408  << theVolumeXaxis2[theStepN] << ","
409  << theVolumeXaxis3[theStepN] << ")"
410  << std::endl;
411  std::cout << "\ty axis = ("
412  << theVolumeYaxis1[theStepN] << ","
413  << theVolumeYaxis2[theStepN] << ","
414  << theVolumeYaxis3[theStepN] << ")"
415  << std::endl;
416  std::cout << "\tz axis = ("
417  << theVolumeZaxis1[theStepN] << ","
418  << theVolumeZaxis2[theStepN] << ","
419  << theVolumeZaxis3[theStepN] << ")"
420  << std::endl;
421  std::cout << "\tSecondaries"
422  << std::endl;
423  for(G4TrackVector::iterator iSec = aStep->GetSecondary()->begin(); iSec!=aStep->GetSecondary()->end(); iSec++) {
424  std::cout << "\t\tid " << (*iSec)->GetDefinition()->GetPDGEncoding()
425  << " created through process "
426  << " type " << (*iSec)->GetCreatorProcess()->GetProcessType()
427  << " " << (*iSec)->GetCreatorProcess()->GetProcessTypeName(G4ProcessType((*iSec)->GetCreatorProcess()->GetProcessType()))
428  << std::endl;
429  }
430 #endif
431  }
432 
433  theTrkLen = aStep->GetTrack()->GetTrackLength();
434  //- std::cout << " theTrkLen " << theTrkLen << " theTrkLen2 " << theTrkLen2 << " postPos " << postPos.mag() << postPos << std::endl;
435  thePVname = pv->GetName();
436  thePVcopyNo = pv->GetCopyNo();
437  theRadLen = radlen;
438  theIntLen = intlen;
439  theTotalMB += dmb;
440  theTotalIL += dil;
441 
442  // rr
445  theCablesMB += (dmb * theCablesFractionMB);
448  theOtherMB += (dmb * theOtherFractionMB);
449  theAirMB += (dmb * theAirFractionMB);
452  theCablesIL += (dil * theCablesFractionIL);
455  theOtherIL += (dil * theOtherFractionIL);
456  theAirIL += (dil * theAirFractionIL);
457  // rr
458 
459  theStepN++;
460 
461 }
462 
463 
std::vector< float > x0fraction(std::string s)
std::string * theMaterialName
T sqrt(T t)
Definition: SSEVec.h:18
void dataEndTrack(const G4Track *aTrack)
def pv(vc)
Definition: MetAnalyzer.py:6
void dataPerStep(const G4Step *aStep)
MaterialBudgetCategorizer * myMaterialBudgetCategorizer
void dataStartTrack(const G4Track *aTrack)
std::string * theVolumeName
std::vector< float > l0fraction(std::string s)
dbl *** dir
Definition: mlp_gen.cc:35