CMS 3D CMS Logo

List of all members | Classes | Public Member Functions | Private Member Functions | Private Attributes
MaterialBudgetVolume Class Reference
Inheritance diagram for MaterialBudgetVolume:
SimProducer Observer< const BeginOfRun *> Observer< const BeginOfEvent *> Observer< const BeginOfTrack *> Observer< const G4Step *> Observer< const EndOfTrack *> SimWatcher

Classes

struct  MatInfo
 

Public Member Functions

 MaterialBudgetVolume (const edm::ParameterSet &p)
 
 MaterialBudgetVolume (const MaterialBudgetVolume &)=delete
 
const MaterialBudgetVolumeoperator= (const MaterialBudgetVolume &)=delete
 
void produce (edm::Event &, const edm::EventSetup &) override
 
 ~MaterialBudgetVolume () override
 
- Public Member Functions inherited from SimProducer
const SimProduceroperator= (const SimProducer &)=delete
 
void registerProducts (edm::ProducesCollector producesCollector)
 
 SimProducer ()
 
 SimProducer (const SimProducer &)=delete
 
- Public Member Functions inherited from SimWatcher
virtual void beginRun (edm::EventSetup const &)
 
bool isMT () const
 
const SimWatcheroperator= (const SimWatcher &)=delete
 
virtual void registerConsumes (edm::ConsumesCollector)
 
 SimWatcher ()
 
 SimWatcher (const SimWatcher &)=delete
 
virtual ~SimWatcher ()
 
- Public Member Functions inherited from Observer< const BeginOfRun *>
 Observer ()
 
void slotForUpdate (const BeginOfRun * iT)
 
virtual ~Observer ()
 
- Public Member Functions inherited from Observer< const BeginOfEvent *>
 Observer ()
 
void slotForUpdate (const BeginOfEvent * iT)
 
virtual ~Observer ()
 
- Public Member Functions inherited from Observer< const BeginOfTrack *>
 Observer ()
 
void slotForUpdate (const BeginOfTrack * iT)
 
virtual ~Observer ()
 
- Public Member Functions inherited from Observer< const G4Step *>
 Observer ()
 
void slotForUpdate (const G4Step * iT)
 
virtual ~Observer ()
 
- Public Member Functions inherited from Observer< const EndOfTrack *>
 Observer ()
 
void slotForUpdate (const EndOfTrack * iT)
 
virtual ~Observer ()
 

Private Member Functions

void endOfEvent (edm::MaterialInformationContainer &matbg)
 
int findLV (const G4VTouchable *)
 
bool loadLV ()
 
bool stopAfter (const G4Step *)
 
void update (const BeginOfRun *run) override
 This routine will be called when the appropriate signal arrives. More...
 
void update (const BeginOfEvent *evt) override
 This routine will be called when the appropriate signal arrives. More...
 
void update (const BeginOfTrack *) override
 This routine will be called when the appropriate signal arrives. More...
 
void update (const EndOfTrack *) override
 This routine will be called when the appropriate signal arrives. More...
 
void update (const G4Step *step) override
 This routine will be called when the appropriate signal arrives. More...
 

Private Attributes

int iaddLevel_
 
bool init_
 
std::vector< MatInfolengths_
 
std::vector< int > lvLevel_
 
std::vector< std::string > lvNames_
 
std::map< int, std::pair< G4LogicalVolume *, int > > mapLV_
 
double rMax_
 
std::vector< MaterialInformationstore_
 
double zMax_
 

Additional Inherited Members

- Protected Member Functions inherited from SimProducer
template<class T >
void produces ()
 
template<class T >
void produces (const std::string &instanceName)
 
- Protected Member Functions inherited from SimWatcher
void setMT (bool val)
 

Detailed Description

Definition at line 36 of file MaterialBudgetVolume.cc.

Constructor & Destructor Documentation

◆ MaterialBudgetVolume() [1/2]

MaterialBudgetVolume::MaterialBudgetVolume ( const edm::ParameterSet p)

Definition at line 79 of file MaterialBudgetVolume.cc.

References edm::ParameterSet::getParameter(), iaddLevel_, isotrackApplyRegressor::k, lvLevel_, lvNames_, visualization-live-secondInstance_cfg::m, AlCaHLTBitMon_ParallelJobs::p, rMax_, and zMax_.

79  : init_(false) {
80  edm::ParameterSet m_p = p.getParameter<edm::ParameterSet>("MaterialBudgetVolume");
81 
82  lvNames_ = m_p.getParameter<std::vector<std::string> >("lvNames");
83  lvLevel_ = m_p.getParameter<std::vector<int> >("lvLevels");
84  iaddLevel_ = (m_p.getParameter<bool>("useDD4hep")) ? 1 : 0;
85  rMax_ = m_p.getParameter<double>("rMax") * CLHEP::m;
86  zMax_ = m_p.getParameter<double>("zMax") * CLHEP::m;
87 
88  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume: Studies Material budget for " << lvNames_.size()
89  << " volumes with addLevel " << iaddLevel_ << " and with rMax " << rMax_
90  << " mm; zMax " << zMax_ << " mm";
91  std::ostringstream st1;
92  for (unsigned int k = 0; k < lvNames_.size(); ++k)
93  st1 << " [" << k << "] " << lvNames_[k] << " at " << lvLevel_[k];
94  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume: Volumes" << st1.str();
95 
96  produces<edm::MaterialInformationContainer>("MaterialInformation");
97 #ifdef EDM_ML_DEBUG
98  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume: will produce MaterialInformationContainer";
99 #endif
100 }
Log< level::Info, true > LogVerbatim
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
std::vector< std::string > lvNames_
std::vector< int > lvLevel_

◆ MaterialBudgetVolume() [2/2]

MaterialBudgetVolume::MaterialBudgetVolume ( const MaterialBudgetVolume )
delete

◆ ~MaterialBudgetVolume()

MaterialBudgetVolume::~MaterialBudgetVolume ( )
inlineoverride

Definition at line 46 of file MaterialBudgetVolume.cc.

46 {}

Member Function Documentation

◆ endOfEvent()

void MaterialBudgetVolume::endOfEvent ( edm::MaterialInformationContainer matbg)
private

Definition at line 181 of file MaterialBudgetVolume.cc.

References info(), and store_.

Referenced by produce().

181  {
182 #ifdef EDM_ML_DEBUG
183  unsigned int kount(0);
184 #endif
185  for (const auto& element : store_) {
186  MaterialInformation info(element.vname(),
187  element.id(),
188  element.trackEta(),
189  element.trackPhi(),
190  element.stepLength(),
191  element.radiationLength(),
192  element.interactionLength());
193  matbg.push_back(info);
194 #ifdef EDM_ML_DEBUG
195  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume:: Info[" << kount << "] " << info;
196  ++kount;
197 #endif
198  }
199 }
Log< level::Info, true > LogVerbatim
static const TGPicture * info(bool iBackgroundIsBlack)
std::vector< MaterialInformation > store_

◆ findLV()

int MaterialBudgetVolume::findLV ( const G4VTouchable *  touch)
private

Definition at line 233 of file MaterialBudgetVolume.cc.

References mps_fire::i, cuy::ii, gammaJetAnalysis_CHSJECs_cff::level, GCP_tree_cfg::levels, mapLV_, and edm::second().

Referenced by update().

233  {
234  int level(-1);
235  int levels = ((touch->GetHistoryDepth()) + 1);
236  for (const auto& lvs : mapLV_) {
237  if ((lvs.second).second <= levels) {
238  int ii = levels - (lvs.second).second;
239  if ((touch->GetVolume(ii)->GetLogicalVolume()) == (lvs.second).first) {
240  level = lvs.first;
241  break;
242  }
243  }
244  }
245 #ifdef EDM_ML_DEBUG
246  if (level < 0) {
247  edm::LogVerbatim("MaterialBudget") << "findLV: Gets " << level << " from " << levels << " levels in touchables";
248  for (int i = 0; i < levels; ++i)
249  edm::LogVerbatim("MaterialBudget") << "[" << (levels - i) << "] " << touch->GetVolume(i)->GetLogicalVolume()
250  << " : " << touch->GetVolume(i)->GetLogicalVolume()->GetName();
251  }
252 #endif
253  return level;
254 }
Log< level::Info, true > LogVerbatim
std::map< int, std::pair< G4LogicalVolume *, int > > mapLV_
U second(std::pair< T, U > const &p)
ii
Definition: cuy.py:589

◆ loadLV()

bool MaterialBudgetVolume::loadLV ( )
private

Definition at line 201 of file MaterialBudgetVolume.cc.

References dqmdumpme::first, RemoveAddSevLevel::flag, mps_fire::i, iaddLevel_, isotrackApplyRegressor::k, lvLevel_, lvNames_, mapLV_, mergeVDriftHistosByStation::name, and AlCaHLTBitMon_QueryRunRegistry::string.

Referenced by update().

201  {
202  const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
203  bool flag(false);
204  if (lvs != nullptr) {
205  std::vector<G4LogicalVolume*>::const_iterator lvcite;
206  for (unsigned int i = 0; i < lvNames_.size(); i++) {
207  G4LogicalVolume* lv = nullptr;
209  for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
210  std::string namx(dd4hep::dd::noNamespace((*lvcite)->GetName()));
211  if (namx == name) {
212  lv = (*lvcite);
213  break;
214  }
215  }
216  if (lv != nullptr)
217  mapLV_[i] = std::make_pair(lv, (lvLevel_[i] + iaddLevel_));
218  }
219  flag = true;
220 #ifdef EDM_ML_DEBUG
221  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume::Finds " << mapLV_.size() << " logical volumes";
222  unsigned int k(0);
223  for (const auto& lvs : mapLV_) {
224  edm::LogVerbatim("MaterialBudget") << "Entry[" << k << "] " << lvs.first << ": (" << (lvs.second).first << ", "
225  << (lvs.second).second << ") : " << lvNames_[lvs.first];
226  ++k;
227  }
228 #endif
229  }
230  return flag;
231 }
Log< level::Info, true > LogVerbatim
std::map< int, std::pair< G4LogicalVolume *, int > > mapLV_
std::vector< std::string > lvNames_
std::vector< int > lvLevel_

◆ operator=()

const MaterialBudgetVolume& MaterialBudgetVolume::operator= ( const MaterialBudgetVolume )
delete

◆ produce()

void MaterialBudgetVolume::produce ( edm::Event e,
const edm::EventSetup  
)
overridevirtual

Implements SimProducer.

Definition at line 102 of file MaterialBudgetVolume.cc.

References MillePedeFileConverter_cfg::e, endOfEvent(), and eostools::move().

102  {
103  std::unique_ptr<edm::MaterialInformationContainer> matbg(new edm::MaterialInformationContainer);
104  endOfEvent(*matbg);
105  e.put(std::move(matbg), "MaterialInformation");
106 }
std::vector< MaterialInformation > MaterialInformationContainer
void endOfEvent(edm::MaterialInformationContainer &matbg)
def move(src, dest)
Definition: eostools.py:511

◆ stopAfter()

bool MaterialBudgetVolume::stopAfter ( const G4Step *  aStep)
private

Definition at line 256 of file MaterialBudgetVolume.cc.

References funct::abs(), RemoveAddSevLevel::flag, rMax_, findQualityFiles::rr, zMax_, and geometryCSVtoXML::zz.

Referenced by update().

256  {
257  bool flag(false);
258  if ((rMax_ > 0.0) && (zMax_ > 0.0)) {
259  G4ThreeVector hitPoint = aStep->GetPreStepPoint()->GetPosition();
260  double rr = hitPoint.perp();
261  double zz = std::abs(hitPoint.z());
262 
263  if (rr > rMax_ || zz > zMax_) {
264 #ifdef EDM_ML_DEBUG
265  edm::LogVerbatim("MaterialBudget") << " MaterialBudgetHcal::StopAfter R = " << rr << " and Z = " << zz;
266 #endif
267  flag = true;
268  }
269  }
270  return flag;
271 }
Log< level::Info, true > LogVerbatim
Abs< T >::type abs(const T &t)
Definition: Abs.h:22

◆ update() [1/5]

void MaterialBudgetVolume::update ( const BeginOfRun )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfRun *>.

Definition at line 108 of file MaterialBudgetVolume.cc.

References init_, loadLV(), and mapLV_.

Referenced by MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), and MatrixUtil.Steps::overwrite().

108  {
109  init_ = loadLV();
110 
111 #ifdef EDM_ML_DEBUG
112  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume::Finds " << mapLV_.size()
113  << " logical volumes with return flag " << init_;
114 #endif
115 }
Log< level::Info, true > LogVerbatim
std::map< int, std::pair< G4LogicalVolume *, int > > mapLV_

◆ update() [2/5]

void MaterialBudgetVolume::update ( const BeginOfEvent )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfEvent *>.

Definition at line 117 of file MaterialBudgetVolume.cc.

References caHitNtupletGeneratorKernels::iev, init_, loadLV(), and store_.

Referenced by MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), and MatrixUtil.Steps::overwrite().

117  {
118 #ifdef EDM_ML_DEBUG
119  int iev = (*evt)()->GetEventID();
120  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume: =====> Begin event = " << iev << std::endl;
121 #endif
122  if (!init_)
123  init_ = loadLV();
124 
125  store_.clear();
126 }
Log< level::Info, true > LogVerbatim
TkSoAView< TrackerTraits > HitToTuple< TrackerTraits > const *__restrict__ int32_t int32_t int iev
std::vector< MaterialInformation > store_

◆ update() [3/5]

void MaterialBudgetVolume::update ( const BeginOfTrack )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const BeginOfTrack *>.

Definition at line 128 of file MaterialBudgetVolume.cc.

References lengths_, and mapLV_.

Referenced by MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), and MatrixUtil.Steps::overwrite().

128  {
129  lengths_ = std::vector<MatInfo>(mapLV_.size());
130 
131 #ifdef EDM_ML_DEBUG
132  const G4Track* aTrack = (*trk)();
133  const G4ThreeVector& mom = aTrack->GetMomentum();
134  double theEnergy = aTrack->GetTotalEnergy();
135  int theID = static_cast<int>(aTrack->GetDefinition()->GetPDGEncoding());
136  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolumme: Track " << aTrack->GetTrackID() << " Code " << theID
137  << " Energy " << theEnergy / CLHEP::GeV << " GeV; Momentum " << mom / CLHEP::GeV
138  << " GeV";
139 #endif
140 }
Log< level::Info, true > LogVerbatim
std::vector< MatInfo > lengths_
std::map< int, std::pair< G4LogicalVolume *, int > > mapLV_

◆ update() [4/5]

void MaterialBudgetVolume::update ( const EndOfTrack )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const EndOfTrack *>.

Definition at line 167 of file MaterialBudgetVolume.cc.

References PVValHelper::eta, info(), isotrackApplyRegressor::k, lengths_, lvNames_, phi, and store_.

Referenced by MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), and MatrixUtil.Steps::overwrite().

167  {
168  const G4Track* aTrack = (*trk)();
169  int id = aTrack->GetTrackID();
170  double eta = aTrack->GetMomentumDirection().eta();
171  double phi = aTrack->GetMomentumDirection().phi();
172  for (unsigned int k = 0; k < lengths_.size(); ++k) {
173  MaterialInformation info(lvNames_[k], id, eta, phi, lengths_[k].stepL, lengths_[k].radL, lengths_[k].intL);
174  store_.emplace_back(info);
175 #ifdef EDM_ML_DEBUG
176  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume::Volume[" << k << "]: " << info;
177 #endif
178  }
179 }
Log< level::Info, true > LogVerbatim
static const TGPicture * info(bool iBackgroundIsBlack)
std::vector< MatInfo > lengths_
std::vector< MaterialInformation > store_
std::vector< std::string > lvNames_

◆ update() [5/5]

void MaterialBudgetVolume::update ( const G4Step *  )
overrideprivatevirtual

This routine will be called when the appropriate signal arrives.

Implements Observer< const G4Step *>.

Definition at line 142 of file MaterialBudgetVolume.cc.

References findLV(), lengths_, stopAfter(), and HLT_2024v14_cff::track.

Referenced by MatrixUtil.Matrix::__setitem__(), MatrixUtil.Steps::__setitem__(), and MatrixUtil.Steps::overwrite().

142  {
143  G4Material* material = aStep->GetPreStepPoint()->GetMaterial();
144  double step = aStep->GetStepLength();
145  double radl = material->GetRadlen();
146  double intl = material->GetNuclearInterLength();
147  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
148  int index = findLV(touch);
149  if (index >= 0) {
150  lengths_[index].stepL += step;
151  lengths_[index].radL += (step / radl);
152  lengths_[index].intL += (step / intl);
153  }
154 #ifdef EDM_ML_DEBUG
155  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume::Step in "
156  << touch->GetVolume(0)->GetLogicalVolume()->GetName() << " Index " << index
157  << " Step " << step << " RadL " << step / radl << " IntL " << step / intl;
158 #endif
159 
160  //----- Stop tracking after selected position
161  if (stopAfter(aStep)) {
162  G4Track* track = aStep->GetTrack();
163  track->SetTrackStatus(fStopAndKill);
164  }
165 }
Log< level::Info, true > LogVerbatim
std::vector< MatInfo > lengths_
int findLV(const G4VTouchable *)
bool stopAfter(const G4Step *)
step
Definition: StallMonitor.cc:83

Member Data Documentation

◆ iaddLevel_

int MaterialBudgetVolume::iaddLevel_
private

Definition at line 71 of file MaterialBudgetVolume.cc.

Referenced by loadLV(), and MaterialBudgetVolume().

◆ init_

bool MaterialBudgetVolume::init_
private

Definition at line 73 of file MaterialBudgetVolume.cc.

Referenced by update().

◆ lengths_

std::vector<MatInfo> MaterialBudgetVolume::lengths_
private

Definition at line 75 of file MaterialBudgetVolume.cc.

Referenced by update().

◆ lvLevel_

std::vector<int> MaterialBudgetVolume::lvLevel_
private

Definition at line 70 of file MaterialBudgetVolume.cc.

Referenced by loadLV(), and MaterialBudgetVolume().

◆ lvNames_

std::vector<std::string> MaterialBudgetVolume::lvNames_
private

Definition at line 69 of file MaterialBudgetVolume.cc.

Referenced by loadLV(), MaterialBudgetVolume(), and update().

◆ mapLV_

std::map<int, std::pair<G4LogicalVolume*, int> > MaterialBudgetVolume::mapLV_
private

Definition at line 74 of file MaterialBudgetVolume.cc.

Referenced by findLV(), loadLV(), and update().

◆ rMax_

double MaterialBudgetVolume::rMax_
private

Definition at line 72 of file MaterialBudgetVolume.cc.

Referenced by MaterialBudgetVolume(), and stopAfter().

◆ store_

std::vector<MaterialInformation> MaterialBudgetVolume::store_
private

Definition at line 76 of file MaterialBudgetVolume.cc.

Referenced by endOfEvent(), and update().

◆ zMax_

double MaterialBudgetVolume::zMax_
private

Definition at line 72 of file MaterialBudgetVolume.cc.

Referenced by MaterialBudgetVolume(), and stopAfter().