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
28  ) {
29  std::string attribute = "MuStructure"; // could come from outside
30  std::string value = "MuonEndcapCSC"; // could come from outside
31 
32  // Asking for a specific section of the MuStructure
33 
34  DDSpecificsMatchesValueFilter filter{ DDValue(attribute, value, 0.0) };
35 
36  DDFilteredView fv( *cview, filter );
37 
38  bool doSubDets = fv.firstChild();
39 
40  if (!doSubDets) {
41  edm::LogError("CSCGeometryParsFromDD") << "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 <<
70  ", octal " << std::oct << id << ", hex " << 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(); ++it) {
154  uparvals.emplace_back(*it);
155  }
156  for (CSCWireGroupPackage::Container::const_iterator it = wg.consecutiveGroups.begin();
157  it != wg.consecutiveGroups.end(); ++it) {
158  uparvals.emplace_back(*it);
159  }
161  }
162  fpar.clear();
163  // dpar = fv.logicalPart().solid().parameters();
164  if ( fv.logicalPart().solid().shape() == ddsubtraction ) {
165  const DDSubtraction& first = fv.logicalPart().solid();
166  const DDSubtraction& second = first.solidA();
167  const DDSolid& third = second.solidA();
168  dpar = third.parameters();
169  } else {
170  dpar = fv.logicalPart().solid().parameters();
171  }
172 
173  LogTrace(myName) << myName << ": noOfAnonParams=" << noOfAnonParams;
174  LogTrace(myName) << myName << ": fill fpar...";
175  LogTrace(myName) << myName << ": dpars are... " <<
176  dpar[4]/cm << ", " << dpar[8]/cm << ", " <<
177  dpar[3]/cm << ", " << dpar[0]/cm;
178 
179  fpar.emplace_back( ( dpar[4]/cm) );
180  fpar.emplace_back( ( dpar[8]/cm ) );
181  fpar.emplace_back( ( dpar[3]/cm ) );
182  fpar.emplace_back( ( dpar[0]/cm ) );
183 
184  LogTrace(myName) << myName << ": fill gtran...";
185 
186  gtran[0] = (float) 1.0 * (fv.translation().X() / cm);
187  gtran[1] = (float) 1.0 * (fv.translation().Y() / cm);
188  gtran[2] = (float) 1.0 * (fv.translation().Z() / cm);
189 
190  LogTrace(myName) << myName << ": gtran[0]=" << gtran[0] << ", gtran[1]=" <<
191  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) <<
206  " S" << CSCDetId::station(id) <<
207  " R" << CSCDetId::ring(id) <<
208  " C" << CSCDetId::chamber(id) <<
209  " L" << CSCDetId::layer(id);
210 
211  if ( wg.numberOfGroups != 0 ) {
212  LogTrace(myName) << myName << ": fv.geoHistory: = " << fv.geoHistory() ;
213  LogTrace(myName) << myName << ": TotNumWireGroups = " << wg.numberOfGroups ;
214  LogTrace(myName) << myName << ": WireSpacing = " << wg.wireSpacing ;
215  LogTrace(myName) << myName << ": AlignmentPinToFirstWire = " << wg.alignmentPinToFirstWire ;
216  LogTrace(myName) << myName << ": Narrow width of wire plane = " << wg.narrowWidthOfWirePlane ;
217  LogTrace(myName) << myName << ": Wide width of wire plane = " << wg.wideWidthOfWirePlane ;
218  LogTrace(myName) << myName << ": Length in y of wire plane = " << wg.lengthOfWirePlane ;
219  LogTrace(myName) << myName << ": wg.consecutiveGroups.size() = " << wg.consecutiveGroups.size() ;
220  LogTrace(myName) << myName << ": wg.wiresInEachGroup.size() = " << wg.wiresInEachGroup.size() ;
221  LogTrace(myName) << myName << ": \tNumGroups\tWiresInGroup" ;
222  for (size_t i = 0; i < wg.consecutiveGroups.size(); i++) {
223  LogTrace(myName) << myName << " \t" << wg.consecutiveGroups[i] << "\t\t" << wg.wiresInEachGroup[i] ;
224  }
225  } else {
226  LogTrace(myName) << myName << ": DDD is MISSING SpecPars for wire groups" ;
227  }
228  LogTrace(myName) << myName << ": end of wire group info. " ;
229 
230  LogTrace(myName) << myName << ":_z_ E" << jendcap << " S" << jstation << " R" << jring <<
231  " C" << jchamber << " L" << jlayer <<
232  " gx=" << gtran[0] << ", gy=" << gtran[1] << ", gz=" << gtran[2] <<
233  " thickness=" << fpar[2]*2.;
234 
235  if ( jlayer == 0 ) { // Can only build chambers if we're filtering them
236 
237  LogTrace(myName) << myName << ":_z_ frame=" << uparvals[31]/10. <<
238  " gap=" << uparvals[32]/10. << " panel=" << uparvals[33]/10. << " offset=" << uparvals[34]/10.;
239 
240  if ( jstation==1 && jring==1 ) {
241  // set up params for ME1a and ME1b and call buildChamber *for each*
242  // Both get the full ME11 dimensions
243 
244  // detid is for ME11 and that's what we're using for ME1b in the software
245 
246  rig.insert( id, gtran, grmat, fpar );
247  if ( !chSpecsAlreadyExist ) {
248  // rdp.pCSCDetIds.emplace_back(CSCDetId(id));
249  LogDebug(myName) << " inserting chamber type " << chamberType << std::endl;
250  rdp.pChamberType.emplace_back(chamberType);
251  rdp.pUserParOffset.emplace_back(rdp.pfupars.size());
252  rdp.pUserParSize.emplace_back(uparvals.size());
253  std::copy ( uparvals.begin(), uparvals.end(), std::back_inserter(rdp.pfupars));
254  }
255 
256  // No. of anonymous parameters per chamber type should be read from cscSpecs file...
257  // Only required for ME11 splitting into ME1a and ME1b values,
258  // If it isn't seen may as well try to get further but this value will depend
259  // on structure of the file so may not even match!
260  const int kNoOfAnonParams = 35;
261  if ( noOfAnonParams == 0 ) { noOfAnonParams = kNoOfAnonParams; } // in case it wasn't seen
262 
263  std::copy( uparvals.begin()+noOfAnonParams+1, uparvals.begin()+(2*noOfAnonParams)+2, uparvals.begin()+1 ); // copy ME1a params from back to the front
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  }
287  else {
288  rig.insert( id, gtran, grmat, fpar );
289  if ( !chSpecsAlreadyExist ) {
290  // rdp.pCSCDetIds.emplace_back(CSCDetId(id));
291  LogDebug(myName) << " inserting chamber type " << chamberType;
292  rdp.pChamberType.emplace_back(chamberType);
293  rdp.pUserParOffset.emplace_back(rdp.pfupars.size());
294  rdp.pUserParSize.emplace_back(uparvals.size());
295  std::copy ( uparvals.begin(), uparvals.end(), std::back_inserter(rdp.pfupars));
296  }
297  }
298 
299  } // filtering chambers.
300 
301  doSubDets = fv.next();
302  }
303  return true;
304 }
#define LogDebug(id)
int chamber() const
Definition: CSCDetId.h:68
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Definition: DDSolid.cc:150
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
def copy(args, dbName)
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.
type of data representation of DDCompactView
Definition: DDCompactView.h:90
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
int layer() const
Definition: CSCDetId.h:61
A DDSolid represents the shape of a part.
Definition: DDSolid.h:38
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:93
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:144
Definition: value.py:1
#define LogTrace(id)
DDSolid solidA(void) const
Definition: DDSolid.cc:662
int ring() const
Definition: CSCDetId.h:75
std::string toString() const
Definition: DDBase.h:82
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:86
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)