CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MaterialBudgetForward.cc
Go to the documentation of this file.
2 
7 
11 
12 #include "G4LogicalVolumeStore.hh"
13 #include "G4Step.hh"
14 #include "G4Track.hh"
15 
16 #include <iostream>
17 
19 
21 
22  edm::ParameterSet m_p = p.getParameter<edm::ParameterSet>("MaterialBudgetForward");
23  detTypes = m_p.getParameter<std::vector<std::string> >("DetectorTypes");
24  constituents = m_p.getParameter<std::vector<int> >("Constituents");
25  stackOrder = m_p.getParameter<std::vector<int> >("StackOrder");
26  detNames = m_p.getParameter<std::vector<std::string> >("DetectorNames");
27  detLevels = m_p.getParameter<std::vector<int> >("DetectorLevels");
28  etaRegions = m_p.getParameter<std::vector<double> >("EtaBoundaries");
29  regionTypes = m_p.getParameter<std::vector<int> >("RegionTypes");
30  boundaries = m_p.getParameter<std::vector<double> >("Boundaries");
31  edm::LogInfo("MaterialBudget") << "MaterialBudgetForward initialized for "
32  << detTypes.size() << " detector types";
33  unsigned int nc = 0;
34  for (unsigned int ii=0; ii<detTypes.size(); ++ii) {
35  edm::LogInfo("MaterialBudget") << "Type[" << ii << "] : " << detTypes[ii]
36  << " with " << constituents[ii] <<", order "
37  << stackOrder[ii] << " constituents --> ";
38  for (int kk=0; kk<constituents[ii]; ++kk) {
39  std::string name = "Unknown"; int level = -1;
40  if (nc < detNames.size()) {
41  name = detNames[nc]; level = detLevels[nc]; ++nc;
42  }
43  edm::LogInfo("MaterialBudget") << " Constituent[" << kk << "]: "
44  << name << " at level " << level;
45  }
46  }
47  edm::LogInfo("MaterialBudget") << "MaterialBudgetForward Stop condition for "
48  << etaRegions.size() << " eta regions";
49  for (unsigned int ii=0; ii<etaRegions.size(); ++ii) {
50  edm::LogInfo("MaterialBudget") << "Region[" << ii << "] : Eta < "
51  << etaRegions[ii] << " boundary type "
52  << regionTypes[ii] << " limit "
53  << boundaries[ii];
54  }
55  book(m_p);
56 }
57 
59 }
60 
62 
63  const G4LogicalVolumeStore * lvs = G4LogicalVolumeStore::GetInstance();
64  std::vector<G4LogicalVolume *>::const_iterator lvcite;
65 
66  unsigned int kount=detNames.size();
67  for (unsigned int ii=0; ii<kount; ++ii)
68  logVolumes.push_back(0);
69 
70  for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
71  for (unsigned int ii=0; ii<detNames.size(); ++ii) {
72  if (strcmp(detNames[ii].c_str(),(*lvcite)->GetName().c_str()) == 0) {
73  logVolumes[ii] = (*lvcite);
74  kount--;
75  break;
76  }
77  }
78  if (kount <= 0) break;
79  }
80  edm::LogInfo("MaterialBudget") << "MaterialBudgetForward::Finds "
81  << detNames.size()-kount << " out of "
82  << detNames.size() << " LV addresses";
83  for (unsigned int ii=0; ii<detNames.size(); ++ii) {
84  std::string name("Unknown");
85  if (logVolumes[ii] != 0) name = logVolumes[ii]->GetName();
86  edm::LogInfo("MaterialBudget") << "LV[" << ii << "] : " << detNames[ii]
87  << " Address " << logVolumes[ii] << " | "
88  << name;
89  }
90 
91  for (unsigned int ii=0; ii<(detTypes.size()+1); ++ii) {
92  stepLen.push_back(0); radLen.push_back(0); intLen.push_back(0);
93  }
94  stackOrder.push_back(0);
95 }
96 
98 
99  for (unsigned int ii=0; ii<(detTypes.size()+1); ++ii) {
100  stepLen[ii] = 0; radLen[ii] = 0; intLen[ii] = 0;
101  }
102 
103  const G4Track * aTrack = (*trk)(); // recover G4 pointer if wanted
104  const G4ThreeVector& mom = aTrack->GetMomentum() ;
105  if (mom.theta() != 0 ) {
106  eta = mom.eta();
107  } else {
108  eta = -99;
109  }
110  phi = mom.phi();
111  stepT = 0;
112 
113  double theEnergy = aTrack->GetTotalEnergy();
114  int theID = (int)(aTrack->GetDefinition()->GetPDGEncoding());
115  LogDebug("MaterialBudget") << "MaterialBudgetHcalHistos: Track "
116  << aTrack->GetTrackID() << " Code " << theID
117  << " Energy " <<theEnergy/CLHEP::GeV<<" GeV; Eta "
118  << eta << " Phi " << phi/CLHEP::deg << " PT "
119  << mom.perp()/CLHEP::GeV << " GeV *****";
120 }
121 
122 void MaterialBudgetForward::update(const G4Step* aStep) {
123 
124  //---------- each step
125  G4Material * material = aStep->GetPreStepPoint()->GetMaterial();
126  double step = aStep->GetStepLength();
127  double radl = material->GetRadlen();
128  double intl = material->GetNuclearInterLength();
129 
130  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
131  unsigned int indx = detTypes.size();
132  unsigned int nc = 0;
133  for (unsigned int ii=0; ii<detTypes.size(); ++ii) {
134  for (int kk=0; kk<constituents[ii]; ++kk) {
135  if (detLevels[nc+kk] <= (int)((touch->GetHistoryDepth())+1)) {
136  int jj = (int)((touch->GetHistoryDepth())+1)-detLevels[nc+kk];
137  if ((touch->GetVolume(jj)->GetLogicalVolume()) == logVolumes[nc+kk]) {
138  indx = ii;
139  break;
140  }
141  }
142  }
143  nc += (unsigned int)(constituents[ii]);
144  if (indx == ii) break;
145  }
146 
147  stepT += step;
148  stepLen[indx] = stepT;
149  radLen[indx] += (step/radl);
150  intLen[indx] += (step/intl);
151  LogDebug("MaterialBudget") << "MaterialBudgetForward::Step in "
152  << touch->GetVolume(0)->GetLogicalVolume()->GetName()
153  << " Index " << indx <<" Step " << step <<" RadL "
154  << step/radl << " IntL " << step/intl;
155 
156  //----- Stop tracking after selected position
157  if (stopAfter(aStep)) {
158  G4Track* track = aStep->GetTrack();
159  track->SetTrackStatus( fStopAndKill );
160  }
161 }
162 
163 
165 
166  for (unsigned int ii=0; ii<detTypes.size(); ++ii) {
167  for (unsigned int jj=0; jj<=detTypes.size(); ++jj) {
168  if (stackOrder[jj] == (int)(ii+1)) {
169  for (unsigned int kk=0; kk<=detTypes.size(); ++kk) {
170  if (stackOrder[kk] == (int)(ii)) {
171  radLen[jj] += radLen[kk];
172  intLen[jj] += intLen[kk];
173  LogDebug("MaterialBudget") << "MaterialBudgetForward::Add " << kk
174  << ":" << stackOrder[kk] << " to "
175  << jj <<":" << stackOrder[jj] <<" RadL "
176  << radLen[kk] << " : " << radLen[jj]
177  << " IntL " << intLen[kk] << " : "
178  << intLen[jj] <<" StepL " << stepLen[kk]
179  << " : " << stepLen[jj];
180  break;
181  }
182  }
183  break;
184  }
185  }
186  }
187 
188  for (unsigned int ii=0; ii<=detTypes.size(); ++ii) {
189  me100[ii]->Fill(eta, radLen[ii]);
190  me200[ii]->Fill(eta, intLen[ii]);
191  me300[ii]->Fill(eta, stepLen[ii]);
192  me400[ii]->Fill(eta);
193  me500[ii]->Fill(eta, phi, radLen[ii]);
194  me600[ii]->Fill(eta, phi, intLen[ii]);
195  me700[ii]->Fill(eta, phi, stepLen[ii]);
196  me800[ii]->Fill(eta, phi);
197 
198  std::string name("Unknown");
199  if (ii < detTypes.size()) name = detTypes[ii];
200  LogDebug("MaterialBudget") << "MaterialBudgetForward::Volume[" << ii
201  << "]: " << name << " == Step " << stepLen[ii]
202  << " RadL " << radLen[ii] << " IntL "
203  << intLen[ii];
204  }
205 }
206 
208 
209  // Book histograms
211 
212  if ( !tfile.isAvailable() )
213  throw cms::Exception("BadConfig") << "TFileService unavailable: "
214  << "please add it to config file";
215 
216  int binEta = m_p.getUntrackedParameter<int>("NBinEta", 320);
217  int binPhi = m_p.getUntrackedParameter<int>("NBinPhi", 180);
218  double minEta = m_p.getUntrackedParameter<double>("MinEta",-8.0);
219  double maxEta = m_p.getUntrackedParameter<double>("MaxEta", 8.0);
220  double maxPhi = CLHEP::pi;
221  edm::LogInfo("MaterialBudget") << "MaterialBudgetForward: Booking user "
222  << "histos === with " << binEta << " bins "
223  << "in eta from " << minEta << " to "
224  << maxEta << " and " << binPhi << " bins "
225  << "in phi from " << -maxPhi << " to "
226  << maxPhi;
227 
228  char name[20], title[80];
229  std::string named;
230  for (int i=0; i<std::min((int)(detTypes.size()+1),maxSet); i++) {
231  if (i >= (int)(detTypes.size())) named = "Unknown";
232  else named = detTypes[i];
233  sprintf(name, "%d", i+100);
234  sprintf(title, "MB(X0) prof Eta in %s", named.c_str());
235  me100[i] = tfile->make<TProfile>(name, title, binEta, minEta, maxEta);
236  sprintf(name, "%d", i+200);
237  sprintf(title, "MB(L0) prof Eta in %s", named.c_str());
238  me200[i] = tfile->make<TProfile>(name, title, binEta, minEta, maxEta);
239  sprintf(name, "%d", i+300);
240  sprintf(title, "MB(Step) prof Eta in %s", named.c_str());
241  me300[i] = tfile->make<TProfile>(name, title, binEta, minEta, maxEta);
242  sprintf(name, "%d", i+400);
243  sprintf(title, "Eta in %s", named.c_str());
244  me400[i] = tfile->make<TH1F>(name, title, binEta, minEta, maxEta);
245  sprintf(name, "%d", i+500);
246  sprintf(title, "MB(X0) prof Eta Phi in %s", named.c_str());
247  me500[i] = tfile->make<TProfile2D>(name, title, binEta/2, minEta, maxEta,
248  binPhi/2, -maxPhi, maxPhi);
249  sprintf(name, "%d", i+600);
250  sprintf(title, "MB(L0) prof Eta Phi in %s", named.c_str());
251  me600[i]= tfile->make<TProfile2D>(name, title, binEta/2, minEta, maxEta,
252  binPhi/2, -maxPhi, maxPhi);
253  sprintf(name, "%d", i+700);
254  sprintf(title, "MB(Step) prof Eta Phi in %s", named.c_str());
255  me700[i]= tfile->make<TProfile2D>(name, title, binEta/2, minEta, maxEta,
256  binPhi/2, -maxPhi, maxPhi);
257  sprintf(name, "%d", i+800);
258  sprintf(title, "Eta vs Phi in %s", named.c_str());
259  me800[i]= tfile->make<TH2F>(name, title, binEta/2, minEta, maxEta,
260  binPhi/2, -maxPhi, maxPhi);
261  }
262 
263  edm::LogInfo("MaterialBudget") << "MaterialBudgetForward: Booking user "
264  << "histos done ===";
265 
266 }
267 
268 bool MaterialBudgetForward::stopAfter(const G4Step* aStep) {
269 
270  G4ThreeVector hitPoint = aStep->GetPreStepPoint()->GetPosition();
271  if (aStep->GetPostStepPoint() != 0)
272  hitPoint = aStep->GetPostStepPoint()->GetPosition();
273  double rr = hitPoint.perp();
274  double zz = std::abs(hitPoint.z());
275 
276  bool flag(false);
277  for (unsigned int ii=0; ii<etaRegions.size(); ++ii) {
278  // LogDebug("MaterialBudget") << " MaterialBudgetForward::Eta " << eta << " in Region[" << ii << "] with " << etaRegions[ii] << " type " << regionTypes[ii] << "|" << boundaries[ii];
279  if (fabs(eta) < etaRegions[ii]) {
280  if (regionTypes[ii] == 0) {
281  if (rr >= boundaries[ii]-0.001) flag = true;
282  } else {
283  if (zz >= boundaries[ii]-0.001) flag = true;
284  }
285  if (flag)
286  LogDebug("MaterialBudget") <<" MaterialBudgetForward::Stop after R = "
287  << rr << " and Z = " << zz;
288  break;
289  }
290  }
291  // LogDebug("MaterialBudget") <<" MaterialBudgetForward:: R = " << rr << " and Z = " << zz << " Flag " << flag;
292  return flag;
293 }
#define LogDebug(id)
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
TProfile2D * me700[maxSet]
long int flag
Definition: mlp_lapack.h:47
TProfile * me100[maxSet]
list step
Definition: launcher.py:15
MaterialBudgetForward(const edm::ParameterSet &)
#define abs(x)
Definition: mlp_lapack.h:159
#define min(a, b)
Definition: mlp_lapack.h:161
double maxEta
TProfile2D * me600[maxSet]
std::vector< double > etaRegions
std::vector< int > detLevels
std::vector< double > radLen
std::vector< int > stackOrder
void update(const BeginOfRun *)
This routine will be called when the appropriate signal arrives.
const Double_t pi
TProfile * me200[maxSet]
std::vector< double > intLen
bool isAvailable() const
Definition: Service.h:47
std::vector< double > stepLen
std::vector< G4LogicalVolume * > logVolumes
std::vector< std::string > detNames
std::vector< int > constituents
bool stopAfter(const G4Step *)
void book(const edm::ParameterSet &)
std::vector< int > regionTypes
T * make() const
make new ROOT object
TProfile * me300[maxSet]
std::vector< double > boundaries
TProfile2D * me500[maxSet]
tuple level
Definition: testEve_cfg.py:34
std::vector< std::string > detTypes