CMS 3D CMS Logo

SimplifiedGeometryFactory.cc
Go to the documentation of this file.
2 
9 
10 #include <TH1F.h>
11 #include <cctype>
12 
13 
16  const std::map<std::string,fastsim::InteractionModel *> & interactionModelMap,
17  double magneticFieldHistMaxR,
18  double magneticFieldHistMaxZ)
19  : geometricSearchTracker_(geometricSearchTracker)
20  , magneticField_(&magneticField)
21  , interactionModelMap_(&interactionModelMap)
22  , magneticFieldHistMaxR_(magneticFieldHistMaxR)
23  , magneticFieldHistMaxZ_(magneticFieldHistMaxZ)
24 {
25  // naming convention for barrel DetLayer lists
29 
30  // naming convention for forward DetLayer lists
37 }
38 
39 std::unique_ptr<fastsim::BarrelSimplifiedGeometry> fastsim::SimplifiedGeometryFactory::createBarrelSimplifiedGeometry(const edm::ParameterSet & cfg) const
40 {
41  std::unique_ptr<fastsim::SimplifiedGeometry> layer = createSimplifiedGeometry(BARREL,cfg);
42  return std::unique_ptr<fastsim::BarrelSimplifiedGeometry>(static_cast<fastsim::BarrelSimplifiedGeometry *>(layer.release()));
43 }
44 
46  const edm::ParameterSet & cfg) const
47 {
48  if(layerType != NEGFWD && layerType != POSFWD)
49  {
50  throw cms::Exception("fastsim::SimplifiedGeometry::createForwardLayer") << " called with forbidden layerType. Allowed layerTypes are NEGFWD and POSFWD";
51  }
52  std::unique_ptr<fastsim::SimplifiedGeometry> layer = createSimplifiedGeometry(layerType,cfg);
53  return std::unique_ptr<fastsim::ForwardSimplifiedGeometry>(static_cast<fastsim::ForwardSimplifiedGeometry *>(layer.release()));
54 }
55 
57  const edm::ParameterSet & cfg) const
58 {
59 
60  // some flags for internal usage
61  bool isForward = true;
62  bool isOnPositiveSide = false;
63  if(layerType == BARREL)
64  {
65  isForward = false;
66  }
67  else if(layerType == POSFWD)
68  {
69  isOnPositiveSide = true;
70  }
71 
72  // -------------------------------
73  // extract DetLayer (i.e. full geometry of tracker modules)
74  // -------------------------------
75 
76  std::string detLayerName = cfg.getUntrackedParameter<std::string>("activeLayer","");
77  const DetLayer * detLayer = nullptr;
78 
79  if(!detLayerName.empty() && geometricSearchTracker_)
80  {
81  if(isForward)
82  {
83  detLayerName = (isOnPositiveSide ? "pos" : "neg") + detLayerName;
84  }
85  detLayer = getDetLayer(detLayerName,*geometricSearchTracker_);
86  }
87 
88  // ------------------------------
89  // radius / z of layers
90  // ------------------------------
91 
92  // first try to get it from the configuration
93  double position = 0;
94  std::string positionParameterName = (isForward ? "z" : "radius");
95  if(cfg.exists(positionParameterName))
96  {
97  position = fabs(cfg.getUntrackedParameter<double>(positionParameterName));
98  if(isForward && !isOnPositiveSide)
99  {
100  position = -position;
101  }
102  }
103  // then try extracting from detLayer
104  else if(detLayer)
105  {
106  if(isForward)
107  {
108  position = static_cast<ForwardDetLayer const*>(detLayer)->surface().position().z();
109  }
110  else
111  {
112  position = static_cast<BarrelDetLayer const*>(detLayer)->specificSurface().radius();
113  }
114  }
115  // then throw error
116  else
117  {
118  std::string cfgString;
119  cfg.allToString(cfgString);
120  throw cms::Exception("fastsim::SimplifiedGeometry") << "Cannot extract a "
121  << (isForward ? "position" : "radius") << " for this "
122  << (isForward ? "forward" : "barrel") << " layer:\n"
123  << cfgString;
124  }
125 
126  // -----------------------------
127  // create the layers
128  // -----------------------------
129 
130  std::unique_ptr<fastsim::SimplifiedGeometry> layer;
131  if(isForward)
132  {
133  layer.reset(new fastsim::ForwardSimplifiedGeometry(position));
134  }
135  else
136  {
137  layer.reset(new fastsim::BarrelSimplifiedGeometry(position));
138  }
139  layer->detLayer_ = detLayer;
140 
141  // -----------------------------
142  // thickness histogram
143  // -----------------------------
144 
145  // Get limits
146  const std::vector<double> & limits = cfg.getUntrackedParameter<std::vector<double> >("limits");
147  // and check order.
148  for(unsigned index = 1;index < limits.size();index++)
149  {
150  if(limits[index] < limits[index-1])
151  {
152  std::string cfgString;
153  cfg.allToString(cfgString);
154  throw cms::Exception("fastsim::SimplifiedGeometryFactory")
155  << "limits must be provided in increasing order. error in:\n"
156  << cfgString;
157  }
158  }
159  // Get thickness values
160  const std::vector<double> & thickness = cfg.getUntrackedParameter<std::vector<double> >("thickness");
161  // and check compatibility with limits
162  if(limits.size() < 2 || thickness.size() != limits.size() - 1)
163  {
164  std::string cfgString;
165  cfg.allToString(cfgString);
166  throw cms::Exception("fastim::SimplifiedGeometryFactory")
167  << "layer thickness and limits not configured properly! error in:"
168  << cfgString;
169  }
170  // create the histogram
171  layer->thicknessHist_.reset(new TH1F("h", "h", limits.size()-1, &limits[0]));
172  layer->thicknessHist_->SetDirectory(nullptr);
173  for(unsigned i = 1; i < limits.size(); ++i){
174  layer->thicknessHist_->SetBinContent(i, thickness[i-1]);
175  }
176 
177  // -----------------------------
178  // nuclear interaction thickness factor
179  // -----------------------------
180 
181  layer->nuclearInteractionThicknessFactor_ = cfg.getUntrackedParameter<double>("nuclearInteractionThicknessFactor",1.);
182 
183  // -----------------------------
184  // magnetic field
185  // -----------------------------
186 
187  layer->magneticFieldHist_.reset(new TH1F("h", "h", 100, 0., isForward ? magneticFieldHistMaxR_ : magneticFieldHistMaxZ_));
188  layer->magneticFieldHist_->SetDirectory(nullptr);
189  for(int i = 1; i <= 101; i++)
190  {
191  GlobalPoint point = isForward ?
192  GlobalPoint(layer->magneticFieldHist_->GetXaxis()->GetBinCenter(i), 0.,position)
193  : GlobalPoint(position, 0.,layer->magneticFieldHist_->GetXaxis()->GetBinCenter(i));
194  layer->magneticFieldHist_->SetBinContent(i, magneticField_->inTesla(point).z());
195  }
196 
197  // -----------------------------
198  // list of interaction models
199  // -----------------------------
200 
201  std::vector<std::string> interactionModelLabels = cfg.getUntrackedParameter<std::vector<std::string> >("interactionModels");
202  for(const auto & label : interactionModelLabels)
203  {
204  std::map<std::string,fastsim::InteractionModel *>::const_iterator interactionModel = interactionModelMap_->find(label);
205  if(interactionModel == interactionModelMap_->end())
206  {
207  throw cms::Exception("fastsim::SimplifiedGeometryFactory") << "unknown interaction model '" << label << "'";
208  }
209  layer->interactionModels_.push_back(interactionModel->second);
210  }
211 
212  // -----------------------------
213  // Hack to interface "old" calorimetry with "new" propagation in tracker
214  // -----------------------------
215 
216  if(cfg.exists("caloType"))
217  {
218  std::string caloType = cfg.getUntrackedParameter<std::string>("caloType");
219 
220  if(caloType == "PRESHOWER1"){
221  layer->setCaloType(SimplifiedGeometry::PRESHOWER1);
222  }else if(caloType == "PRESHOWER2"){
223  layer->setCaloType(SimplifiedGeometry::PRESHOWER2);
224  }else if(caloType == "ECAL"){
225  layer->setCaloType(SimplifiedGeometry::ECAL);
226  }else if(caloType == "HCAL"){
227  layer->setCaloType(SimplifiedGeometry::HCAL);
228  }else if(caloType == "VFCAL"){
229  layer->setCaloType(SimplifiedGeometry::VFCAL);
230  }else{
231  throw cms::Exception("fastsim::SimplifiedGeometryFactory") << "unknown caloType '" << caloType << "' (defined PRESHOWER1, PRESHOWER2, ECAL, HCAL, VFCAL)";
232  }
233  }
234 
235 
236  // -----------------------------
237  // and return the layer!
238  // -----------------------------
239 
240  return layer;
241 }
242 
243 const DetLayer *
244 fastsim::SimplifiedGeometryFactory::getDetLayer(const std::string & detLayerName, const GeometricSearchTracker & geometricSearchTracker) const
245 {
246  if(detLayerName.empty())
247  {
248  return nullptr;
249  }
250 
251  // obtain the index from the detLayerName
252  unsigned pos = detLayerName.size();
253  while(isdigit(detLayerName[pos-1]))
254  {
255  pos -= 1;
256  }
257  if(pos == detLayerName.size())
258  {
259  throw cms::Exception("fastsim::SimplifiedGeometry::getDetLayer") << "last part of detLayerName must be index of DetLayer in list. Error in detLayerName" << detLayerName << std::endl;
260  }
261  int index = atoi(detLayerName.substr(pos).c_str());
262  std::string detLayerListName = detLayerName.substr(0,pos);
263 
264  try
265  {
266  // try to find the detLayer in the barrel map
267  if(barrelDetLayersMap_.find(detLayerListName) != barrelDetLayersMap_.end())
268  {
269  auto detLayerList = barrelDetLayersMap_.find(detLayerListName)->second;
270  return detLayerList->at(index-1); // use at, to provoce the throwing of an error in case of a bad index
271  }
272 
273  // try to find the detLayer in the forward map
274  else if(forwardDetLayersMap_.find(detLayerListName) != forwardDetLayersMap_.end())
275  {
276  auto detLayerList = forwardDetLayersMap_.find(detLayerListName)->second;
277  return detLayerList->at(index-1); // use at, to provoce the throwing of an error in case of a bad index
278  }
279  // throw an error
280  else
281  {
282  throw cms::Exception("fastsim::SimplifiedGeometry::getDetLayer") << " could not find list of detLayers corresponding to detLayerName " << detLayerName << std::endl;
283  }
284  }
285  catch (const std::out_of_range& error)
286  {
287  throw cms::Exception("fastsim::SimplifiedGeometry::getDetLayer") << " index out of range for detLayerName: " << detLayerName << " " << error.what() << std::endl;
288  }
289 }
290 
291 
T getUntrackedParameter(std::string const &, T const &) const
Implementation of a forward detector layer (disk).
std::map< std::string, const std::vector< BarrelDetLayer const * > * > barrelDetLayersMap_
A map of strings and pointers to detLayers.
const double magneticFieldHistMaxZ_
Limit in +-Z for histogram of magnetic field.
const DetLayer * getDetLayer(const std::string &detLayerName, const GeometricSearchTracker &geometricSearchTracker) const
Method returns a pointer to a DetLayer according to the string that was passed.
std::vector< ForwardDetLayer const * > const & posPixelForwardLayers() const
const MagneticField *const magneticField_
The full magnetic field.
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
bool isForward(DetId const &)
bool exists(std::string const &parameterName) const
checks if a parameter exists
Implementation of a barrel detector layer (cylindrical).
std::vector< BarrelDetLayer const * > const & tobLayers() const
SimplifiedGeometryFactory(const GeometricSearchTracker *geometricSearchTracker, const MagneticField &magneticField, const std::map< std::string, fastsim::InteractionModel * > &interactionModelMap, double magneticFieldHistMaxR, double magneticFieldHistMaxZ)
Constructor.
std::vector< ForwardDetLayer const * > const & negPixelForwardLayers() const
char const * label
T z() const
Definition: PV3DBase.h:64
std::vector< BarrelDetLayer const * > const & pixelBarrelLayers() const
const GeometricSearchTracker *const geometricSearchTracker_
The full tracker geometry.
virtual GlobalVector inTesla(const GlobalPoint &gp) const =0
Field value ad specified global point, in Tesla.
std::vector< BarrelDetLayer const * > const & tibLayers() const
virtual const Surface::PositionType & position() const
Returns position of the surface.
std::vector< ForwardDetLayer const * > const & posTecLayers() const
std::unique_ptr< SimplifiedGeometry > createSimplifiedGeometry(LayerType type, const edm::ParameterSet &cfg) const
Main method of this class. Creates a new detector layer (SimplifiedGeometry).
std::vector< ForwardDetLayer const * > const & negTidLayers() const
std::map< std::string, const std::vector< ForwardDetLayer const * > * > forwardDetLayersMap_
A map of strings and pointers to detLayers.
void allToString(std::string &result) const
std::vector< ForwardDetLayer const * > const & posTidLayers() const
static int position[264][3]
Definition: ReadPGInfo.cc:509
const std::map< std::string, fastsim::InteractionModel * > * interactionModelMap_
Map of interaction models.
std::unique_ptr< ForwardSimplifiedGeometry > createForwardSimplifiedGeometry(LayerType type, const edm::ParameterSet &cfg) const
Helper method for createSimplifiedGeometry(..) to create a forward layer (ForwardSimplifiedGeometry)...
std::unique_ptr< BarrelSimplifiedGeometry > createBarrelSimplifiedGeometry(const edm::ParameterSet &cfg) const
Helper method for createSimplifiedGeometry(..) to create a barrel layer (BarrelSimplifiedGeometry).
std::vector< ForwardDetLayer const * > const & negTecLayers() const
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
LayerType
Each layer is either a barrel layer, or a forward layer (either at ppositive or negative Z)...
const double magneticFieldHistMaxR_
Limit in R for histogram of magnetic field.