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