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