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  const 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") << "MaterialBudgetCastorHistos: "
103  << name << " " << step << " " << matName
104  << " " << stepLen << " " << step/radl << " "
105  << radLen << " " <<step/intl << " " <<intLen;
106  } else {
107  edm::LogInfo("MaterialBudget") << "MaterialBudgetCastorHistos: Step at "
108  << name << " Length " << step << " in "
109  << matName << " of density " << density
110  << " g/cc; Radiation Length " <<radl <<" mm;"
111  << " Interaction Length " << intl << " mm\n"
112  << " Position "
113  << aStep->GetPreStepPoint()->GetPosition()
114  << " Cylindrical R "
115  <<aStep->GetPreStepPoint()->GetPosition().perp()
116  << " Length (so far) " << stepLen << " L/X0 "
117  << step/radl << "/" << radLen << " L/Lambda "
118  << step/intl << "/" << intLen;
119  }
120 
121  int level = ((touch->GetHistoryDepth())+1);
122  std::string name1="XXXX", name2="XXXX";
123  if (level>3) name1 = touch->GetVolume(level-4)->GetName();
124  if (level>4) name2 = touch->GetVolume(level-5)->GetName();
125  if (name1 == "CAST") {
126  id1 = 1;
127  if (name2 == "CAEC") id2 = 2;
128  else if (name2 == "CAHC") id2 = 3;
129  else if (name2 == "CEDC") id2 = 4;
130  else if (name2 == "CHDC") id2 = 5;
131  else id2 = 0;
132  } else {
133  id1 = id2 = 0;
134  }
135  LogDebug("MaterialBudget") << "MaterialBudgetCastorHistos: Level " << level
136  << " Volume " << name1 << " and " << name2
137  << " ID1 " << id1 << " (" << id1Old << ") ID2 "
138  << id2 << " (" << id2Old << ")";
139 
140  if (fillHistos) {
141  if (id1 != id1Old) {
142  if (id1 == 0) fillHisto(id1Old, 1);
143  else fillHisto(id1, 0);
144  }
145  if (id2 != id2Old) {
146  if (id2 == 0) fillHisto(id2Old, 1);
147  else fillHisto(id2, 0);
148  }
149  }
150 
151  stepLen += step;
152  radLen += step/radl;
153  intLen += step/intl;
154 }
155 
156 
158 
159  if (fillHistos) {
160  if (id1 != 0) fillHisto(id1, 1);
161  if (id2 != 0) fillHisto(id2, 1);
162  }
163  if (printSum) {
164  for (unsigned int ii=0; ii<matList.size(); ii++) {
165  edm::LogInfo("MaterialBudget") << "MaterialBudgetCastorHistos: "
166  << matList[ii] << "\t" << stepLength[ii]
167  << "\t" << radLength[ii] << "\t"
168  << intLength[ii];
169  }
170  }
171 }
172 
174 
175  // Book histograms
177 
178  if ( !tfile.isAvailable() )
179  throw cms::Exception("BadConfig") << "MaterialBudgetCastorHistos: TFileService unavailable: "
180  << "please add it to config file";
181 
182  double maxPhi=pi;
183  edm::LogInfo("MaterialBudget") << "MaterialBudgetCastorHistos: Booking user "
184  << "histos === with " << binEta << " bins "
185  << "in eta from " << etaLow << " to "
186  << etaHigh << " and " << binPhi << " bins "
187  << "in phi from " << -maxPhi << " to "
188  << maxPhi;
189 
190  std::string tag1, tag2;
191  // total X0
192  for (int i=0; i<maxSet; i++) {
193  double minEta=etaLow;
194  double maxEta=etaHigh;
195  int ireg = i;
196  if (i > 9) {
197  minEta = -etaHigh;
198  maxEta = -etaLow;
199  ireg -= 10;
200  tag2 = " (-ve Eta Side)";
201  } else {
202  tag2 = " (+ve Eta Side)";
203  }
204  if ((i%2) == 0) {
205  ireg /= 2;
206  tag1 = " == Start";
207  } else {
208  ireg = (ireg-1)/2;
209  tag1 = " == End";
210  }
211  std::string title = std::to_string(ireg) + tag1 + tag2;
212  me100[i] = tfile->make<TProfile>(std::to_string(i + 100).c_str(),
213  ("MB(X0) prof Eta in region " + title).c_str(), binEta, minEta, maxEta);
214  me200[i] = tfile->make<TProfile>(std::to_string(i + 200).c_str(),
215  ("MB(L0) prof Eta in region " + title).c_str(), binEta, minEta, maxEta);
216  me300[i] = tfile->make<TProfile>(std::to_string(i + 300).c_str(),
217  ("MB(Step) prof Eta in region " + title).c_str(), binEta, minEta, maxEta);
218  me400[i] = tfile->make<TH1F>(std::to_string(i + 400).c_str(),
219  ("Eta in region " + title).c_str(), binEta, minEta, maxEta);
220  me500[i] = tfile->make<TProfile>(std::to_string(i + 500).c_str(),
221  ("MB(X0) prof Ph in region " + title).c_str(), binPhi, -maxPhi, maxPhi);
222  me600[i] = tfile->make<TProfile>(std::to_string(i + 600).c_str(),
223  ("MB(L0) prof Ph in region " + title).c_str(), binPhi, -maxPhi, maxPhi);
224  me700[i] = tfile->make<TProfile>(std::to_string(i + 700).c_str(),
225  ("MB(Step) prof Ph in region " + title).c_str(), binPhi, -maxPhi, maxPhi);
226  me800[i] = tfile->make<TH1F>(std::to_string(i + 800).c_str(),
227  ("Phi in region " + title).c_str(), binPhi, -maxPhi, maxPhi);
228  me900[i] = tfile->make<TProfile2D>(std::to_string(i + 900).c_str(),
229  ("MB(X0) prof Eta Phi in region " + title).c_str(), binEta/2, minEta, maxEta,
230  binPhi/2, -maxPhi, maxPhi);
231  me1000[i]= tfile->make<TProfile2D>(std::to_string(i + 1000).c_str(),
232  ("MB(L0) prof Eta Phi in region " + title).c_str(), binEta/2, minEta, maxEta,
233  binPhi/2, -maxPhi, 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(), binEta/2, minEta, maxEta,
236  binPhi/2, -maxPhi, maxPhi);
237  me1200[i]= tfile->make<TH2F>(std::to_string(i + 1200).c_str(),
238  ("Eta vs Phi in region " + title).c_str(), binEta/2, minEta, maxEta,
239  binPhi/2, -maxPhi, maxPhi);
240  }
241 
242  edm::LogInfo("MaterialBudget") << "MaterialBudgetCastorHistos: Booking user "
243  << "histos done ===";
244 
245 }
246 
248 
249  int ii = 2*(id-1) + ix;
250  double etaAbs = eta;
251  if (eta < 0) {
252  etaAbs = -eta;
253  ii += 10;
254  }
255  LogDebug("MaterialBudget") << "MaterialBudgetCastorHistos:FillHisto "
256  << "called with index " << id << ":" << ix
257  << ":" << ii << " eta " << etaAbs << " ("
258  << eta << ") integrated step " << stepLen
259  << " X0 " << radLen << " Lamda " << intLen;
260 
261  me100[ii]->Fill(eta, radLen);
262  me200[ii]->Fill(eta, intLen);
263  me300[ii]->Fill(eta, stepLen);
264  me400[ii]->Fill(eta);
265 
266  if (etaAbs >= etaLow && etaAbs <= etaHigh) {
267  me500[ii]->Fill(phi, radLen);
268  me600[ii]->Fill(phi, intLen);
269  me700[ii]->Fill(phi, stepLen);
270  me800[ii]->Fill(phi);
271  }
272 
273  me900[ii]->Fill(eta, phi, radLen);
274  me1000[ii]->Fill(eta, phi, intLen);
275  me1100[ii]->Fill(eta, phi, stepLen);
276  me1200[ii]->Fill(eta, phi);
277 
278 }
#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:40
ii
Definition: cuy.py:590
step
Definition: StallMonitor.cc:94
dbl *** dir
Definition: mlp_gen.cc:35