CMS 3D CMS Logo

MaterialBudgetCastorHistos.cc
Go to the documentation of this file.
2 
11 
12 #include "CLHEP/Units/GlobalPhysicalConstants.h"
13 #include "CLHEP/Units/GlobalSystemOfUnits.h"
14 
15 #include <string>
16 
18 
19  binEta = p.getUntrackedParameter<int>("NBinEta", 100);
20  binPhi = p.getUntrackedParameter<int>("NBinPhi", 180);
21  etaLow = p.getUntrackedParameter<double>("EtaLow", 5.0);
22  etaHigh = p.getUntrackedParameter<double>("EtaHigh", 7.0);
23  fillHistos = p.getUntrackedParameter<bool>("FillHisto", true);
24  printSum = p.getUntrackedParameter<bool>("PrintSummary", false);
25  edm::LogInfo("MaterialBudget") << "MaterialBudgetCastorHistos: FillHisto : "
26  << fillHistos << " PrintSummary " << printSum
27  << " == Eta plot: NX " << binEta << " Range "
28  << etaLow << " (" << -etaHigh << ") : "
29  << etaHigh << " (" << -etaLow <<") Phi plot: "
30  << "NX " << binPhi << " Range " << -pi << ":"
31  << pi << " (Eta limit " << etaLow << ":"
32  << etaHigh <<")";
33  if (fillHistos) book();
34 
35 }
36 
38  edm::LogInfo("MaterialBudget") << "MaterialBudgetCastorHistos: Save user "
39  << "histos ===";
40 }
41 
42 void MaterialBudgetCastorHistos::fillStartTrack(const G4Track* aTrack) {
43 
44  id1 = id2 = steps = 0;
45  radLen = intLen = stepLen = 0;
46 
47  const G4ThreeVector& dir = aTrack->GetMomentum() ;
48  if (dir.theta() != 0 ) {
49  eta = dir.eta();
50  } else {
51  eta = -99;
52  }
53  phi = dir.phi();
54  double theEnergy = aTrack->GetTotalEnergy();
55  int theID = (int)(aTrack->GetDefinition()->GetPDGEncoding());
56 
57  if (printSum) {
58  matList.clear();
59  stepLength.clear();
60  radLength.clear();
61  intLength.clear();
62  }
63 
64  edm::LogInfo("MaterialBudget") << "MaterialBudgetCastorHistos: Track "
65  << aTrack->GetTrackID() << " Code " << theID
66  << " Energy " << theEnergy/GeV << " GeV; Eta "
67  << eta << " Phi " << phi/deg << " PT "
68  << dir.perp()/GeV << " GeV *****";
69 }
70 
71 
72 void MaterialBudgetCastorHistos::fillPerStep(const G4Step* aStep) {
73 
74  G4Material * material = aStep->GetPreStepPoint()->GetMaterial();
75  double step = aStep->GetStepLength();
76  double radl = material->GetRadlen();
77  double intl = material->GetNuclearInterLength();
78  double density = material->GetDensity() / (g/cm3);
79 
80  int id1Old = id1;
81  int id2Old = id2;
82  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
83  std::string name = touch->GetVolume(0)->GetName();
84  std::string matName = material->GetName();
85  if (printSum) {
86  bool found = false;
87  for (unsigned int ii=0; ii<matList.size(); ii++) {
88  if (matList[ii] == matName) {
89  stepLength[ii] += step;
90  radLength[ii] += (step/radl);
91  intLength[ii] += (step/intl);
92  found = true;
93  break;
94  }
95  }
96  if (!found) {
97  matList.push_back(matName);
98  stepLength.push_back(step);
99  radLength.push_back(step/radl);
100  intLength.push_back(step/intl);
101  }
102  edm::LogInfo("MaterialBudget") << name << " " << step << " " << matName
103  << " " << stepLen << " " << step/radl << " "
104  << radLen << " " <<step/intl << " " <<intLen;
105  } else {
106  edm::LogInfo("MaterialBudget") << "MaterialBudgetCastorHistos: Step at "
107  << name << " Length " << step << " in "
108  << matName << " of density " << density
109  << " g/cc; Radiation Length " <<radl <<" mm;"
110  << " Interaction Length " << intl << " mm\n"
111  << " Position "
112  << aStep->GetPreStepPoint()->GetPosition()
113  << " Cylindrical R "
114  <<aStep->GetPreStepPoint()->GetPosition().perp()
115  << " Length (so far) " << stepLen << " L/X0 "
116  << step/radl << "/" << radLen << " L/Lambda "
117  << step/intl << "/" << intLen;
118  }
119 
120  int level = ((touch->GetHistoryDepth())+1);
121  std::string name1="XXXX", name2="XXXX";
122  if (level>3) name1 = touch->GetVolume(level-4)->GetName();
123  if (level>4) name2 = touch->GetVolume(level-5)->GetName();
124  if (name1 == "CAST") {
125  id1 = 1;
126  if (name2 == "CAEC") id2 = 2;
127  else if (name2 == "CAHC") id2 = 3;
128  else if (name2 == "CEDC") id2 = 4;
129  else if (name2 == "CHDC") id2 = 5;
130  else id2 = 0;
131  } else {
132  id1 = id2 = 0;
133  }
134  LogDebug("MaterialBudget") << "MaterialBudgetCastorHistos: Level " << level
135  << " Volume " << name1 << " and " << name2
136  << " ID1 " << id1 << " (" << id1Old << ") ID2 "
137  << id2 << " (" << id2Old << ")";
138 
139  if (fillHistos) {
140  if (id1 != id1Old) {
141  if (id1 == 0) fillHisto(id1Old, 1);
142  else fillHisto(id1, 0);
143  }
144  if (id2 != id2Old) {
145  if (id2 == 0) fillHisto(id2Old, 1);
146  else fillHisto(id2, 0);
147  }
148  }
149 
150  stepLen += step;
151  radLen += step/radl;
152  intLen += step/intl;
153 }
154 
155 
157 
158  if (fillHistos) {
159  if (id1 != 0) fillHisto(id1, 1);
160  if (id2 != 0) fillHisto(id2, 1);
161  }
162  if (printSum) {
163  for (unsigned int ii=0; ii<matList.size(); ii++) {
164  edm::LogInfo("MaterialBudget") << matList[ii] << "\t" << stepLength[ii]
165  << "\t" << radLength[ii] << "\t"
166  << intLength[ii];
167  }
168  }
169 }
170 
172 
173  // Book histograms
175 
176  if ( !tfile.isAvailable() )
177  throw cms::Exception("BadConfig") << "TFileService unavailable: "
178  << "please add it to config file";
179 
180  double maxPhi=pi;
181  edm::LogInfo("MaterialBudget") << "MaterialBudgetCastorHistos: Booking user "
182  << "histos === with " << binEta << " bins "
183  << "in eta from " << etaLow << " to "
184  << etaHigh << " and " << binPhi << " bins "
185  << "in phi from " << -maxPhi << " to "
186  << maxPhi;
187 
188  std::string tag1, tag2;
189  // total X0
190  for (int i=0; i<maxSet; i++) {
191  double minEta=etaLow;
192  double maxEta=etaHigh;
193  int ireg = i;
194  if (i > 9) {
195  minEta = -etaHigh;
196  maxEta = -etaLow;
197  ireg -= 10;
198  tag2 = " (-ve Eta Side)";
199  } else {
200  tag2 = " (+ve Eta Side)";
201  }
202  if ((i%2) == 0) {
203  ireg /= 2;
204  tag1 = " == Start";
205  } else {
206  ireg = (ireg-1)/2;
207  tag1 = " == End";
208  }
209  std::string title = std::to_string(ireg) + tag1 + tag2;
210  me100[i] = tfile->make<TProfile>(std::to_string(i + 100).c_str(),
211  ("MB(X0) prof Eta in region " + title).c_str(), binEta, minEta, maxEta);
212  me200[i] = tfile->make<TProfile>(std::to_string(i + 200).c_str(),
213  ("MB(L0) prof Eta in region " + title).c_str(), binEta, minEta, maxEta);
214  me300[i] = tfile->make<TProfile>(std::to_string(i + 300).c_str(),
215  ("MB(Step) prof Eta in region " + title).c_str(), binEta, minEta, maxEta);
216  me400[i] = tfile->make<TH1F>(std::to_string(i + 400).c_str(),
217  ("Eta in region " + title).c_str(), binEta, minEta, maxEta);
218  me500[i] = tfile->make<TProfile>(std::to_string(i + 500).c_str(),
219  ("MB(X0) prof Ph in region " + title).c_str(), binPhi, -maxPhi, maxPhi);
220  me600[i] = tfile->make<TProfile>(std::to_string(i + 600).c_str(),
221  ("MB(L0) prof Ph in region " + title).c_str(), binPhi, -maxPhi, maxPhi);
222  me700[i] = tfile->make<TProfile>(std::to_string(i + 700).c_str(),
223  ("MB(Step) prof Ph in region " + title).c_str(), binPhi, -maxPhi, maxPhi);
224  me800[i] = tfile->make<TH1F>(std::to_string(i + 800).c_str(),
225  ("Phi in region " + title).c_str(), binPhi, -maxPhi, maxPhi);
226  me900[i] = tfile->make<TProfile2D>(std::to_string(i + 900).c_str(),
227  ("MB(X0) prof Eta Phi in region " + title).c_str(), binEta/2, minEta, maxEta,
228  binPhi/2, -maxPhi, maxPhi);
229  me1000[i]= tfile->make<TProfile2D>(std::to_string(i + 1000).c_str(),
230  ("MB(L0) prof Eta Phi in region " + title).c_str(), binEta/2, minEta, maxEta,
231  binPhi/2, -maxPhi, maxPhi);
232  me1100[i]= tfile->make<TProfile2D>(std::to_string(i + 1100).c_str(),
233  ("MB(Step) prof Eta Phi in region " + title).c_str(), binEta/2, minEta, maxEta,
234  binPhi/2, -maxPhi, maxPhi);
235  me1200[i]= tfile->make<TH2F>(std::to_string(i + 1200).c_str(),
236  ("Eta vs Phi in region " + title).c_str(), binEta/2, minEta, maxEta,
237  binPhi/2, -maxPhi, maxPhi);
238  }
239 
240  edm::LogInfo("MaterialBudget") << "MaterialBudgetCastorHistos: Booking user "
241  << "histos done ===";
242 
243 }
244 
246 
247  int ii = 2*(id-1) + ix;
248  double etaAbs = eta;
249  if (eta < 0) {
250  etaAbs = -eta;
251  ii += 10;
252  }
253  LogDebug("MaterialBudget") << "MaterialBudgetCastorHistos:FillHisto "
254  << "called with index " << id << ":" << ix
255  << ":" << ii << " eta " << etaAbs << " ("
256  << eta << ") integrated step " << stepLen
257  << " X0 " << radLen << " Lamda " << intLen;
258 
259  me100[ii]->Fill(eta, radLen);
260  me200[ii]->Fill(eta, intLen);
261  me300[ii]->Fill(eta, stepLen);
262  me400[ii]->Fill(eta);
263 
264  if (etaAbs >= etaLow && etaAbs <= etaHigh) {
265  me500[ii]->Fill(phi, radLen);
266  me600[ii]->Fill(phi, intLen);
267  me700[ii]->Fill(phi, stepLen);
268  me800[ii]->Fill(phi);
269  }
270 
271  me900[ii]->Fill(eta, phi, radLen);
272  me1000[ii]->Fill(eta, phi, intLen);
273  me1100[ii]->Fill(eta, phi, stepLen);
274  me1200[ii]->Fill(eta, phi);
275 
276 }
#define LogDebug(id)
T getUntrackedParameter(std::string const &, T const &) const
const double GeV
Definition: MathUtil.h:16
std::vector< std::string > matList
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
MaterialBudgetCastorHistos(const edm::ParameterSet &p)
double maxEta
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e g
Definition: Activities.doc:4
const Double_t pi
bool isAvailable() const
Definition: Service.h:46
ii
Definition: cuy.py:588
step
dbl *** dir
Definition: mlp_gen.cc:35