CMS 3D CMS Logo

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