CMS 3D CMS Logo

CSCGeometryParsFromDD.cc
Go to the documentation of this file.
2 
5 
11 
15 
16 #include "CLHEP/Units/GlobalSystemOfUnits.h"
17 
19 
20 CSCGeometryParsFromDD::CSCGeometryParsFromDD() : myName("CSCGeometryParsFromDD") {}
21 
23 
25  const MuonDDDConstants& muonConstants,
26  RecoIdealGeometry& rig,
27  CSCRecoDigiParameters& rdp) {
28  std::string attribute = "MuStructure"; // could come from outside
29  std::string value = "MuonEndcapCSC"; // could come from outside
30 
31  // Asking for a specific section of the MuStructure
32 
33  DDSpecificsMatchesValueFilter filter{DDValue(attribute, value, 0.0)};
34 
35  DDFilteredView fv(*cview, filter);
36 
37  bool doSubDets = fv.firstChild();
38 
39  if (!doSubDets) {
40  edm::LogError("CSCGeometryParsFromDD")
41  << "Can not proceed, no CSC parts found with the filter. The current node is: " << fv.logicalPart().toString();
42  return false;
43  }
44  int noOfAnonParams = 0;
45  std::vector<const DDsvalues_type*> spec = fv.specifics();
46  std::vector<const DDsvalues_type*>::const_iterator spit = spec.begin();
47  std::vector<double> uparvals;
48  std::vector<double> fpar;
49  std::vector<double> dpar;
50  std::vector<double> gtran(3);
51  std::vector<double> grmat(9);
52  std::vector<double> trm(9);
53  while (doSubDets) {
54  spec = fv.specifics();
55  spit = spec.begin();
56 
57  // get numbering information early for possible speed up of code.
58 
59  LogTrace(myName) << myName << ": create numbering scheme...";
60 
61  MuonDDDNumbering mdn(muonConstants);
63  CSCNumberingScheme mens(muonConstants);
64 
65  LogTrace(myName) << myName << ": find detid...";
66 
67  int id = mens.baseNumberToUnitNumber(mbn); //@@ FIXME perhaps should return CSCDetId itself?
68 
69  LogTrace(myName) << myName << ": raw id for this detector is " << id << ", octal " << std::oct << id << ", hex "
70  << std::hex << id << std::dec;
71 
72  CSCDetId detid = CSCDetId(id);
73  int jendcap = detid.endcap();
74  int jstation = detid.station();
75  int jring = detid.ring();
76  int jchamber = detid.chamber();
77  int jlayer = detid.layer();
78 
79  // Package up the wire group info as it's decoded
81  uparvals.clear();
82  LogDebug(myName) << "size of spec=" << spec.size();
83 
84  // if the specs are made no need to get all this crap!
85  int chamberType = CSCChamberSpecs::whatChamberType(jstation, jring);
86  LogDebug(myName) << "Chamber Type: " << chamberType;
87  size_t ct = 0;
88  bool chSpecsAlreadyExist = false;
89  for (; ct < rdp.pChamberType.size(); ++ct) {
90  if (chamberType == rdp.pChamberType[ct]) {
91  break;
92  }
93  }
94  if (ct < rdp.pChamberType.size() && rdp.pChamberType[ct] == chamberType) {
95  // it was found, therefore no need to load all the intermediate crap from DD.
96  LogDebug(myName) << "already found a " << chamberType << " at index " << ct;
97  chSpecsAlreadyExist = true;
98  } else {
99  for (; spit != spec.end(); spit++) {
100  DDsvalues_type::const_iterator it = (**spit).begin();
101  for (; it != (**spit).end(); it++) {
102  LogDebug(myName) << "it->second.name()=" << it->second.name();
103  if (it->second.name() == "upar") {
104  uparvals.emplace_back(it->second.doubles().size());
105  for (double i : it->second.doubles()) {
106  uparvals.emplace_back(i);
107  }
108  LogDebug(myName) << "found upars ";
109  } else if (it->second.name() == "NoOfAnonParams") {
110  noOfAnonParams = static_cast<int>(it->second.doubles()[0]);
111  } else if (it->second.name() == "NumWiresPerGrp") {
112  //numWiresInGroup = it->second.doubles();
113  for (double i : it->second.doubles()) {
114  wg.wiresInEachGroup.emplace_back(int(i));
115  }
116  LogDebug(myName) << "found upars " << std::endl;
117  } else if (it->second.name() == "NumGroups") {
118  //numGroups = it->second.doubles();
119  for (double i : it->second.doubles()) {
120  wg.consecutiveGroups.emplace_back(int(i));
121  }
122  } else if (it->second.name() == "WireSpacing") {
123  wg.wireSpacing = it->second.doubles()[0];
124  } else if (it->second.name() == "AlignmentPinToFirstWire") {
125  wg.alignmentPinToFirstWire = it->second.doubles()[0];
126  } else if (it->second.name() == "TotNumWireGroups") {
127  wg.numberOfGroups = int(it->second.doubles()[0]);
128  } else if (it->second.name() == "LengthOfFirstWire") {
129  wg.narrowWidthOfWirePlane = it->second.doubles()[0];
130  } else if (it->second.name() == "LengthOfLastWire") {
131  wg.wideWidthOfWirePlane = it->second.doubles()[0];
132  } else if (it->second.name() == "RadialExtentOfWirePlane") {
133  wg.lengthOfWirePlane = it->second.doubles()[0];
134  }
135  }
136  }
137 
145  uparvals.emplace_back(wg.wireSpacing);
146  uparvals.emplace_back(wg.alignmentPinToFirstWire);
147  uparvals.emplace_back(wg.numberOfGroups);
148  uparvals.emplace_back(wg.narrowWidthOfWirePlane);
149  uparvals.emplace_back(wg.wideWidthOfWirePlane);
150  uparvals.emplace_back(wg.lengthOfWirePlane);
151  uparvals.emplace_back(wg.wiresInEachGroup.size());
152  for (CSCWireGroupPackage::Container::const_iterator it = wg.wiresInEachGroup.begin();
153  it != wg.wiresInEachGroup.end();
154  ++it) {
155  uparvals.emplace_back(*it);
156  }
157  for (CSCWireGroupPackage::Container::const_iterator it = wg.consecutiveGroups.begin();
158  it != wg.consecutiveGroups.end();
159  ++it) {
160  uparvals.emplace_back(*it);
161  }
163  }
164  fpar.clear();
165  // dpar = fv.logicalPart().solid().parameters();
167  const DDSubtraction& first = fv.logicalPart().solid();
168  const DDSubtraction& second = first.solidA();
169  const DDSolid& third = second.solidA();
170  dpar = third.parameters();
171  } else {
172  dpar = fv.logicalPart().solid().parameters();
173  }
174 
175  LogTrace(myName) << myName << ": noOfAnonParams=" << noOfAnonParams;
176  LogTrace(myName) << myName << ": fill fpar...";
177  LogTrace(myName) << myName << ": dpars are... " << dpar[4] / cm << ", " << dpar[8] / cm << ", " << dpar[3] / cm
178  << ", " << dpar[0] / cm;
179 
180  fpar.emplace_back((dpar[4] / cm));
181  fpar.emplace_back((dpar[8] / cm));
182  fpar.emplace_back((dpar[3] / cm));
183  fpar.emplace_back((dpar[0] / cm));
184 
185  LogTrace(myName) << myName << ": fill gtran...";
186 
187  gtran[0] = (float)1.0 * (fv.translation().X() / cm);
188  gtran[1] = (float)1.0 * (fv.translation().Y() / cm);
189  gtran[2] = (float)1.0 * (fv.translation().Z() / cm);
190 
191  LogTrace(myName) << myName << ": gtran[0]=" << gtran[0] << ", gtran[1]=" << gtran[1] << ", gtran[2]=" << gtran[2];
192 
193  LogTrace(myName) << myName << ": fill grmat...";
194 
195  fv.rotation().GetComponents(trm.begin(), trm.end());
196  size_t rotindex = 0;
197  for (size_t i = 0; i < 9; ++i) {
198  grmat[i] = (float)1.0 * trm[rotindex];
199  rotindex = rotindex + 3;
200  if ((i + 1) % 3 == 0) {
201  rotindex = (i + 1) / 3;
202  }
203  }
204  LogTrace(myName) << myName << ": looking for wire group info for layer "
205  << "E" << CSCDetId::endcap(id) << " S" << CSCDetId::station(id) << " R" << CSCDetId::ring(id)
206  << " C" << CSCDetId::chamber(id) << " L" << CSCDetId::layer(id);
207 
208  if (wg.numberOfGroups != 0) {
209  LogTrace(myName) << myName << ": fv.geoHistory: = " << fv.geoHistory();
210  LogTrace(myName) << myName << ": TotNumWireGroups = " << wg.numberOfGroups;
211  LogTrace(myName) << myName << ": WireSpacing = " << wg.wireSpacing;
212  LogTrace(myName) << myName << ": AlignmentPinToFirstWire = " << wg.alignmentPinToFirstWire;
213  LogTrace(myName) << myName << ": Narrow width of wire plane = " << wg.narrowWidthOfWirePlane;
214  LogTrace(myName) << myName << ": Wide width of wire plane = " << wg.wideWidthOfWirePlane;
215  LogTrace(myName) << myName << ": Length in y of wire plane = " << wg.lengthOfWirePlane;
216  LogTrace(myName) << myName << ": wg.consecutiveGroups.size() = " << wg.consecutiveGroups.size();
217  LogTrace(myName) << myName << ": wg.wiresInEachGroup.size() = " << wg.wiresInEachGroup.size();
218  LogTrace(myName) << myName << ": \tNumGroups\tWiresInGroup";
219  for (size_t i = 0; i < wg.consecutiveGroups.size(); i++) {
220  LogTrace(myName) << myName << " \t" << wg.consecutiveGroups[i] << "\t\t" << wg.wiresInEachGroup[i];
221  }
222  } else {
223  LogTrace(myName) << myName << ": DDD is MISSING SpecPars for wire groups";
224  }
225  LogTrace(myName) << myName << ": end of wire group info. ";
226 
227  LogTrace(myName) << myName << ":_z_ E" << jendcap << " S" << jstation << " R" << jring << " C" << jchamber << " L"
228  << jlayer << " gx=" << gtran[0] << ", gy=" << gtran[1] << ", gz=" << gtran[2]
229  << " thickness=" << fpar[2] * 2.;
230 
231  if (jlayer == 0) { // Can only build chambers if we're filtering them
232 
233  LogTrace(myName) << myName << ":_z_ frame=" << uparvals[31] / 10. << " gap=" << uparvals[32] / 10.
234  << " panel=" << uparvals[33] / 10. << " offset=" << uparvals[34] / 10.;
235 
236  if (jstation == 1 && jring == 1) {
237  // set up params for ME1a and ME1b and call buildChamber *for each*
238  // Both get the full ME11 dimensions
239 
240  // detid is for ME11 and that's what we're using for ME1b in the software
241 
242  rig.insert(id, gtran, grmat, fpar);
243  if (!chSpecsAlreadyExist) {
244  // rdp.pCSCDetIds.emplace_back(CSCDetId(id));
245  LogDebug(myName) << " inserting chamber type " << chamberType << std::endl;
246  rdp.pChamberType.emplace_back(chamberType);
247  rdp.pUserParOffset.emplace_back(rdp.pfupars.size());
248  rdp.pUserParSize.emplace_back(uparvals.size());
249  std::copy(uparvals.begin(), uparvals.end(), std::back_inserter(rdp.pfupars));
250  }
251 
252  // No. of anonymous parameters per chamber type should be read from cscSpecs file...
253  // Only required for ME11 splitting into ME1a and ME1b values,
254  // If it isn't seen may as well try to get further but this value will depend
255  // on structure of the file so may not even match!
256  const int kNoOfAnonParams = 35;
257  if (noOfAnonParams == 0) {
258  noOfAnonParams = kNoOfAnonParams;
259  } // in case it wasn't seen
260 
261  // copy ME1a params from back to the front
262  std::copy(
263  uparvals.begin() + noOfAnonParams + 1, uparvals.begin() + (2 * noOfAnonParams) + 2, uparvals.begin() + 1);
264 
265  CSCDetId detid1a = CSCDetId(jendcap, 1, 4, jchamber, 0); // reset to ME1A
266  rig.insert(detid1a.rawId(), gtran, grmat, fpar);
267  int chtypeA = CSCChamberSpecs::whatChamberType(1, 4);
268  ct = 0;
269  for (; ct < rdp.pChamberType.size(); ++ct) {
270  if (chtypeA == rdp.pChamberType[ct]) {
271  break;
272  }
273  }
274  if (ct < rdp.pChamberType.size() && rdp.pChamberType[ct] == chtypeA) {
275  // then its in already, don't put it
276  LogDebug(myName) << "found chamber type " << chtypeA << " so don't put it in! ";
277  } else {
278  // rdp.pCSCDetIds.emplace_back(detid1a);
279  LogDebug(myName) << " inserting chamber type " << chtypeA;
280  rdp.pChamberType.emplace_back(chtypeA);
281  rdp.pUserParOffset.emplace_back(rdp.pfupars.size());
282  rdp.pUserParSize.emplace_back(uparvals.size());
283  std::copy(uparvals.begin(), uparvals.end(), std::back_inserter(rdp.pfupars));
284  }
285 
286  } else {
287  rig.insert(id, gtran, grmat, fpar);
288  if (!chSpecsAlreadyExist) {
289  // rdp.pCSCDetIds.emplace_back(CSCDetId(id));
290  LogDebug(myName) << " inserting chamber type " << chamberType;
291  rdp.pChamberType.emplace_back(chamberType);
292  rdp.pUserParOffset.emplace_back(rdp.pfupars.size());
293  rdp.pUserParSize.emplace_back(uparvals.size());
294  std::copy(uparvals.begin(), uparvals.end(), std::back_inserter(rdp.pfupars));
295  }
296  }
297 
298  } // filtering chambers.
299 
300  doSubDets = fv.next();
301  }
302  return true;
303 }
#define LogDebug(id)
int chamber() const
Definition: CSCDetId.h:62
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Definition: DDSolid.cc:121
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
static int whatChamberType(int istation, int iring)
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
bool insert(DetId id, const std::vector< double > &trans, const std::vector< double > &rot, const std::vector< double > &pars)
virtual ~CSCGeometryParsFromDD()
Destructor.
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
int layer() const
Definition: CSCDetId.h:56
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
bool build(const DDCompactView *cview, const MuonDDDConstants &muonConstants, RecoIdealGeometry &rig, CSCRecoDigiParameters &rdp)
Build the geometry returning the RecoIdealGeometry and the CSCRecoDigiParameters objects.
std::vector< float > pfupars
int endcap() const
Definition: CSCDetId.h:85
U second(std::pair< T, U > const &p)
bool next()
set current node to the next node in the filtered tree
std::vector< int > pChamberType
std::vector< int > pUserParOffset
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:119
Definition: value.py:1
#define LogTrace(id)
DDSolid solidA(void) const
Definition: DDSolid.cc:466
int ring() const
Definition: CSCDetId.h:68
std::string toString() const
Definition: DDBase.h:63
std::vector< int > pUserParSize
int baseNumberToUnitNumber(const MuonBaseNumber &) override
bool firstChild()
set the current node to the first child ...
int station() const
Definition: CSCDetId.h:79
CSCGeometryParsFromDD()
Constructor.
const DDTranslation & translation() const
The absolute translation of the current node.
std::vector< const DDsvalues_type * > specifics() const
MuonBaseNumber geoHistoryToBaseNumber(const DDGeoHistory &history)