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 ()
 
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_
 
std::vector< MaterialInformationstore_
 

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 77 of file MaterialBudgetVolume.cc.

References edm::ParameterSet::getParameter(), iaddLevel_, dqmdumpme::k, lvLevel_, lvNames_, and AlCaHLTBitMon_ParallelJobs::p.

77  : init_(false) {
78  edm::ParameterSet m_p = p.getParameter<edm::ParameterSet>("MaterialBudgetVolume");
79 
80  lvNames_ = m_p.getParameter<std::vector<std::string> >("lvNames");
81  lvLevel_ = m_p.getParameter<std::vector<int> >("lvLevels");
82  iaddLevel_ = (m_p.getParameter<bool>("useDD4hep")) ? 1 : 0;
83 
84  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume: Studies Material budget for " << lvNames_.size()
85  << " volumes with addLevel " << iaddLevel_;
86  std::ostringstream st1;
87  for (unsigned int k = 0; k < lvNames_.size(); ++k)
88  st1 << " [" << k << "] " << lvNames_[k] << " at " << lvLevel_[k];
89  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume: Volumes" << st1.str();
90 
91  produces<edm::MaterialInformationContainer>("MaterialInformation");
92 #ifdef EDM_ML_DEBUG
93  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume: will produce MaterialInformationContainer";
94 #endif
95 }
Log< level::Info, true > LogVerbatim
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
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 170 of file MaterialBudgetVolume.cc.

References info(), and store_.

Referenced by produce().

170  {
171 #ifdef EDM_ML_DEBUG
172  unsigned int kount(0);
173 #endif
174  for (const auto& element : store_) {
175  MaterialInformation info(element.vname(),
176  element.id(),
177  element.trackEta(),
178  element.trackPhi(),
179  element.stepLength(),
180  element.radiationLength(),
181  element.interactionLength());
182  matbg.push_back(info);
183 #ifdef EDM_ML_DEBUG
184  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume:: Info[" << kount << "] " << info;
185  ++kount;
186 #endif
187  }
188 }
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 222 of file MaterialBudgetVolume.cc.

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

Referenced by update().

222  {
223  int level(-1);
224  int levels = ((touch->GetHistoryDepth()) + 1);
225  for (const auto& lvs : mapLV_) {
226  if ((lvs.second).second <= levels) {
227  int ii = levels - (lvs.second).second;
228  if ((touch->GetVolume(ii)->GetLogicalVolume()) == (lvs.second).first) {
229  level = lvs.first;
230  break;
231  }
232  }
233  }
234 #ifdef EDM_ML_DEBUG
235  if (level < 0) {
236  edm::LogVerbatim("MaterialBudget") << "findLV: Gets " << level << " from " << levels << " levels in touchables";
237  for (int i = 0; i < levels; ++i)
238  edm::LogVerbatim("MaterialBudget") << "[" << (levels - i) << "] " << touch->GetVolume(i)->GetLogicalVolume()
239  << " : " << touch->GetVolume(i)->GetLogicalVolume()->GetName();
240  }
241 #endif
242  return level;
243 }
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 190 of file MaterialBudgetVolume.cc.

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

Referenced by update().

190  {
191  const G4LogicalVolumeStore* lvs = G4LogicalVolumeStore::GetInstance();
192  bool flag(false);
193  if (lvs != nullptr) {
194  std::vector<G4LogicalVolume*>::const_iterator lvcite;
195  for (unsigned int i = 0; i < lvNames_.size(); i++) {
196  G4LogicalVolume* lv = nullptr;
198  for (lvcite = lvs->begin(); lvcite != lvs->end(); lvcite++) {
199  std::string namx(dd4hep::dd::noNamespace((*lvcite)->GetName()));
200  if (namx == name) {
201  lv = (*lvcite);
202  break;
203  }
204  }
205  if (lv != nullptr)
206  mapLV_[i] = std::make_pair(lv, (lvLevel_[i] + iaddLevel_));
207  }
208  flag = true;
209 #ifdef EDM_ML_DEBUG
210  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume::Finds " << mapLV_.size() << " logical volumes";
211  unsigned int k(0);
212  for (const auto& lvs : mapLV_) {
213  edm::LogVerbatim("MaterialBudget") << "Entry[" << k << "] " << lvs.first << ": (" << (lvs.second).first << ", "
214  << (lvs.second).second << ") : " << lvNames_[lvs.first];
215  ++k;
216  }
217 #endif
218  }
219  return flag;
220 }
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 97 of file MaterialBudgetVolume.cc.

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

97  {
98  std::unique_ptr<edm::MaterialInformationContainer> matbg(new edm::MaterialInformationContainer);
99  endOfEvent(*matbg);
100  e.put(std::move(matbg), "MaterialInformation");
101 }
std::vector< MaterialInformation > MaterialInformationContainer
void endOfEvent(edm::MaterialInformationContainer &matbg)
def move(src, dest)
Definition: eostools.py:511

◆ 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 103 of file MaterialBudgetVolume.cc.

References init_, loadLV(), and mapLV_.

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

103  {
104  init_ = loadLV();
105 
106 #ifdef EDM_ML_DEBUG
107  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume::Finds " << mapLV_.size()
108  << " logical volumes with return flag " << init_;
109 #endif
110 }
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 112 of file MaterialBudgetVolume.cc.

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

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

112  {
113 #ifdef EDM_ML_DEBUG
114  int iev = (*evt)()->GetEventID();
115  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume: =====> Begin event = " << iev << std::endl;
116 #endif
117  if (!init_)
118  init_ = loadLV();
119 
120  store_.clear();
121 }
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 123 of file MaterialBudgetVolume.cc.

References lengths_, and mapLV_.

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

123  {
124  lengths_ = std::vector<MatInfo>(mapLV_.size());
125 
126 #ifdef EDM_ML_DEBUG
127  const G4Track* aTrack = (*trk)();
128  const G4ThreeVector& mom = aTrack->GetMomentum();
129  double theEnergy = aTrack->GetTotalEnergy();
130  int theID = static_cast<int>(aTrack->GetDefinition()->GetPDGEncoding());
131  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolumme: Track " << aTrack->GetTrackID() << " Code " << theID
132  << " Energy " << theEnergy / CLHEP::GeV << " GeV; Momentum " << mom / CLHEP::GeV
133  << " GeV";
134 #endif
135 }
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 156 of file MaterialBudgetVolume.cc.

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

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

156  {
157  const G4Track* aTrack = (*trk)();
158  int id = aTrack->GetTrackID();
159  double eta = aTrack->GetMomentumDirection().eta();
160  double phi = aTrack->GetMomentumDirection().phi();
161  for (unsigned int k = 0; k < lengths_.size(); ++k) {
162  MaterialInformation info(lvNames_[k], id, eta, phi, lengths_[k].stepL, lengths_[k].radL, lengths_[k].intL);
163  store_.emplace_back(info);
164 #ifdef EDM_ML_DEBUG
165  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume::Volume[" << k << "]: " << info;
166 #endif
167  }
168 }
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 137 of file MaterialBudgetVolume.cc.

References findLV(), and lengths_.

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

137  {
138  G4Material* material = aStep->GetPreStepPoint()->GetMaterial();
139  double step = aStep->GetStepLength();
140  double radl = material->GetRadlen();
141  double intl = material->GetNuclearInterLength();
142  const G4VTouchable* touch = aStep->GetPreStepPoint()->GetTouchable();
143  int index = findLV(touch);
144  if (index >= 0) {
145  lengths_[index].stepL += step;
146  lengths_[index].radL += (step / radl);
147  lengths_[index].intL += (step / intl);
148  }
149 #ifdef EDM_ML_DEBUG
150  edm::LogVerbatim("MaterialBudget") << "MaterialBudgetVolume::Step in "
151  << touch->GetVolume(0)->GetLogicalVolume()->GetName() << " Index " << index
152  << " Step " << step << " RadL " << step / radl << " IntL " << step / intl;
153 #endif
154 }
Log< level::Info, true > LogVerbatim
std::vector< MatInfo > lengths_
int findLV(const G4VTouchable *)
step
Definition: StallMonitor.cc:98

Member Data Documentation

◆ iaddLevel_

int MaterialBudgetVolume::iaddLevel_
private

Definition at line 70 of file MaterialBudgetVolume.cc.

Referenced by loadLV(), and MaterialBudgetVolume().

◆ init_

bool MaterialBudgetVolume::init_
private

Definition at line 71 of file MaterialBudgetVolume.cc.

Referenced by update().

◆ lengths_

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

Definition at line 73 of file MaterialBudgetVolume.cc.

Referenced by update().

◆ lvLevel_

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

Definition at line 69 of file MaterialBudgetVolume.cc.

Referenced by loadLV(), and MaterialBudgetVolume().

◆ lvNames_

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

Definition at line 68 of file MaterialBudgetVolume.cc.

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

◆ mapLV_

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

Definition at line 72 of file MaterialBudgetVolume.cc.

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

◆ store_

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

Definition at line 74 of file MaterialBudgetVolume.cc.

Referenced by endOfEvent(), and update().