CMS 3D CMS Logo

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