CMS 3D CMS Logo

DDG4ProductionCuts.cc
Go to the documentation of this file.
2 
5 
6 #include "G4ProductionCuts.hh"
7 #include "G4RegionStore.hh"
8 
9 #include <algorithm>
10 
12  int verb,
13  const edm::ParameterSet& p)
14  : map_(map), m_Verbosity(verb) {
15  m_KeywordRegion = "CMSCutsRegion";
16  m_protonCut = p.getUntrackedParameter<bool>("CutsOnProton", true);
17  initialize();
18 }
19 
21 
27 bool dd_is_greater(const std::pair<G4LogicalVolume*, DDLogicalPart>& p1,
28  const std::pair<G4LogicalVolume*, DDLogicalPart>& p2) {
29  bool result = false;
30  if (p1.second.name().ns() > p2.second.name().ns()) {
31  result = true;
32  }
33  if (p1.second.name().ns() == p2.second.name().ns()) {
34  if (p1.second.name().name() > p2.second.name().name()) {
35  result = true;
36  }
37  if (p1.second.name().name() == p2.second.name().name()) {
38  if (p1.first->GetName() > p2.first->GetName()) {
39  result = true;
40  }
41  }
42  }
43  return result;
44 }
45 
47  //
48  // Loop over all DDLP and provide the cuts for each region
49  //
50  for (G4LogicalVolumeToDDLogicalPartMap::Vector::iterator tit = vec_.begin(); tit != vec_.end(); tit++) {
51  setProdCuts((*tit).second, (*tit).first);
52  }
53 }
54 
57  // sort all root volumes - to get the same sequence at every run of the application.
58  // (otherwise, the sequence will depend on the pointer (memory address) of the
59  // involved objects, because 'new' does no guarantee that you allways get a
60  // higher (or lower) address when allocating an object of the same type ...
61  sort(vec_.begin(), vec_.end(), &dd_is_greater);
62  if (m_Verbosity > 0) {
63  LogDebug("Physics") << " DDG4ProductionCuts (New) : starting\n"
64  << " DDG4ProductionCuts : Got " << vec_.size() << " region roots.\n"
65  << " DDG4ProductionCuts : List of all roots:";
66  for (size_t jj = 0; jj < vec_.size(); ++jj)
67  LogDebug("Physics") << " DDG4ProductionCuts : root=" << vec_[jj].second.name();
68  }
69 
70  // Now generate all the regions
71  for (G4LogicalVolumeToDDLogicalPartMap::Vector::iterator tit = vec_.begin(); tit != vec_.end(); tit++) {
72  std::string regionName;
73  unsigned int num = map_.toString(m_KeywordRegion, (*tit).second, regionName);
74 
75  if (num != 1) {
76  throw cms::Exception("SimG4CorePhysics", " DDG4ProductionCuts::initialize: Problem with Region tags.");
77  }
78  G4Region* region = getRegion(regionName);
79  region->AddRootLogicalVolume((*tit).first);
80 
81  if (m_Verbosity > 0)
82  LogDebug("Physics") << " MakeRegions: added " << ((*tit).first)->GetName() << " to region " << region->GetName();
83  }
84 }
85 
86 void DDG4ProductionCuts::setProdCuts(const DDLogicalPart lpart, G4LogicalVolume* lvol) {
87  if (m_Verbosity > 0)
88  LogDebug("Physics") << " DDG4ProductionCuts: inside setProdCuts";
89 
90  G4Region* region = nullptr;
91 
92  std::string regionName;
93  unsigned int num = map_.toString(m_KeywordRegion, lpart, regionName);
94 
95  if (num != 1) {
96  throw cms::Exception("SimG4CorePhysics", " DDG4ProductionCuts::setProdCuts: Problem with Region tags.");
97  }
98  if (m_Verbosity > 0)
99  LogDebug("Physics") << "Using region " << regionName;
100 
101  region = getRegion(regionName);
102 
103  //
104  // search for production cuts
105  // you must have four of them: e+ e- gamma proton
106  //
107  double gammacut;
108  double electroncut;
109  double positroncut;
110  double protoncut = 0.0;
111  int temp = map_.toDouble("ProdCutsForGamma", lpart, gammacut);
112  if (temp != 1) {
113  throw cms::Exception(
114  "SimG4CorePhysics",
115  " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForGamma.");
116  }
117  temp = map_.toDouble("ProdCutsForElectrons", lpart, electroncut);
118  if (temp != 1) {
119  throw cms::Exception(
120  "SimG4CorePhysics",
121  " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForElectrons.");
122  }
123  temp = map_.toDouble("ProdCutsForPositrons", lpart, positroncut);
124  if (temp != 1) {
125  throw cms::Exception(
126  "SimG4CorePhysics",
127  " DDG4ProductionCuts::setProdCuts: Problem with Region tags - no/more than one ProdCutsForPositrons.");
128  }
129  //
130  // For the moment I assume all of the three are set
131  //
132  G4ProductionCuts* prodCuts = getProductionCuts(region);
133  prodCuts->SetProductionCut(gammacut, idxG4GammaCut);
134  prodCuts->SetProductionCut(electroncut, idxG4ElectronCut);
135  prodCuts->SetProductionCut(positroncut, idxG4PositronCut);
136  // For recoil use the same cut as for e-
137  if (m_protonCut) {
138  protoncut = electroncut;
139  }
140  prodCuts->SetProductionCut(protoncut, idxG4ProtonCut);
141  if (m_Verbosity > 0) {
142  LogDebug("Physics") << "DDG4ProductionCuts : Setting cuts for " << regionName << "\n Electrons: " << electroncut
143  << "\n Positrons: " << positroncut << "\n Gamma : " << gammacut;
144  }
145 }
146 
147 G4Region* DDG4ProductionCuts::getRegion(const std::string& regName) {
148  G4Region* reg = G4RegionStore::GetInstance()->FindOrCreateRegion(regName);
149  return reg;
150 }
151 
152 G4ProductionCuts* DDG4ProductionCuts::getProductionCuts(G4Region* reg) {
153  G4ProductionCuts* prodCuts = reg->GetProductionCuts();
154  if (!prodCuts) {
155  prodCuts = new G4ProductionCuts();
156  reg->SetProductionCuts(prodCuts);
157  }
158  return prodCuts;
159 }
#define LogDebug(id)
G4LogicalVolumeToDDLogicalPartMap map_
T getUntrackedParameter(std::string const &, T const &) const
bool dd_is_greater(const std::pair< G4LogicalVolume *, DDLogicalPart > &p1, const std::pair< G4LogicalVolume *, DDLogicalPart > &p2)
void setProdCuts(const DDLogicalPart lpart, G4LogicalVolume *lvolume)
unsigned int toDouble(const std::string &name, const KeyType &key, double &value, unsigned int pos=0) const
returns the number specific parameters named &#39;name&#39; and the corrsponding double
Definition: DDMapper.h:119
std::string m_KeywordRegion
G4ProductionCuts * getProductionCuts(G4Region *region)
A DDLogicalPart aggregates information concerning material, solid and sensitveness ...
Definition: DDLogicalPart.h:93
DDG4ProductionCuts(const G4LogicalVolumeToDDLogicalPartMap &, int, const edm::ParameterSet &p)
double p2[4]
Definition: TauolaWrapper.h:90
unsigned int toString(const std::string &name, const KeyType &key, std::string &value, unsigned int pos=0) const
same as toDouble but for std::string-valued values of named parameters
Definition: DDMapper.h:182
G4LogicalVolumeToDDLogicalPartMap::Vector vec_
G4Region * getRegion(const std::string &region)
double p1[4]
Definition: TauolaWrapper.h:89
Vector all(const std::string &name, const std::string &value) const
get all std::mapped instances which have a specific &#39;name&#39; with value &#39;value&#39;
Definition: DDMapper.h:208