CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCGeometryParsFromDD.cc
Go to the documentation of this file.
2 
6 
20 
21 //#include <CondFormats/RecoGeometryObjects/interface/CSCWireGroupPackage.h>
25 
26 #include "CLHEP/Units/GlobalSystemOfUnits.h"
27 
30 
31 #include <iostream>
32 #include <sstream>
33 #include <iomanip>
34 #include <algorithm>
35 //#include <iterator>
36 
37 CSCGeometryParsFromDD::CSCGeometryParsFromDD() : myName("CSCGeometryParsFromDD") { }
38 
40 
42  , const MuonDDDConstants& muonConstants
43  , RecoIdealGeometry& rig
45  ) {
46  std::string attribute = "MuStructure"; // could come from outside
47  std::string value = "MuonEndcapCSC"; // could come from outside
48  DDValue muval(attribute, value, 0.0);
49 
50  // Asking for a specific section of the MuStructure
51 
53  filter.setCriteria(muval, // name & value of a variable
56  true, // compare strings otherwise doubles
57  true // use merged-specifics or simple-specifics
58  );
59 
60  DDFilteredView fv( *cview );
61  fv.addFilter(filter);
62 
63  bool doSubDets = fv.firstChild();
64 
65  if (!doSubDets) {
66  edm::LogError("CSCGeometryParsFromDD") << "Can not proceed, no CSC parts found with the filter. The current node is: " << fv.logicalPart().toString();
67  return false;
68  }
69  int noOfAnonParams = 0;
70  std::vector<const DDsvalues_type *> spec = fv.specifics();
71  std::vector<const DDsvalues_type *>::const_iterator spit = spec.begin();
72  std::vector<double> uparvals;
73  std::vector<double> fpar;
74  std::vector<double> dpar;
75  std::vector<double> gtran( 3 );
76  std::vector<double> grmat( 9 );
77  std::vector<double> trm ( 9 );
78  while (doSubDets) {
79  spec = fv.specifics();
80  spit = spec.begin();
81 
82  // get numbering information early for possible speed up of code.
83 
84  LogTrace(myName) << myName << ": create numbering scheme...";
85 
86  MuonDDDNumbering mdn(muonConstants);
88  CSCNumberingScheme mens(muonConstants);
89 
90  LogTrace(myName) << myName << ": find detid...";
91 
92  int id = mens.baseNumberToUnitNumber( mbn ); //@@ FIXME perhaps should return CSCDetId itself?
93 
94  LogTrace(myName) << myName << ": raw id for this detector is " << id <<
95  ", octal " << std::oct << id << ", hex " << std::hex << id << std::dec;
96 
97  CSCDetId detid = CSCDetId( id );
98  int jendcap = detid.endcap();
99  int jstation = detid.station();
100  int jring = detid.ring();
101  int jchamber = detid.chamber();
102  int jlayer = detid.layer();
103 
104  // Package up the wire group info as it's decoded
106  uparvals.clear();
107  //std::cout << "size of spec=" << spec.size() << std::endl;
108 
109  // if the specs are made no need to get all this crap!
110  int chamberType = CSCChamberSpecs::whatChamberType( jstation, jring );
111  // std::cout << "Chamber Type: " << chamberType << std::endl;
112  size_t ct = 0;
113  bool chSpecsAlreadyExist = false;
114  for ( ; ct < rdp.pChamberType.size() ; ++ct ) {
115  if ( chamberType == rdp.pChamberType[ct] ) {
116  break;
117  }
118  }
119  if ( ct < rdp.pChamberType.size() && rdp.pChamberType[ct] == chamberType ) {
120  // it was found, therefore no need to load all the intermediate crap from DD.
121  // std::cout << "already found a " << chamberType << " at index " << ct << std::endl;
122  chSpecsAlreadyExist = true;
123  } else {
124  for (; spit != spec.end(); spit++) {
125  DDsvalues_type::const_iterator it = (**spit).begin();
126  for (; it != (**spit).end(); it++) {
127  //std::cout << "it->second.name()=" << it->second.name() << std::endl;
128  if (it->second.name() == "upar") {
129  uparvals.push_back(it->second.doubles().size());
130  for ( size_t i = 0; i < it->second.doubles().size(); ++i) {
131  uparvals.push_back(it->second.doubles()[i]);
132  }
133  //std::cout << "found upars " << std::endl;
134  } else if (it->second.name() == "NoOfAnonParams") {
135  noOfAnonParams = static_cast<int>( it->second.doubles()[0] );
136  } else if (it->second.name() == "NumWiresPerGrp") {
137  //numWiresInGroup = it->second.doubles();
138  for ( size_t i = 0 ; i < it->second.doubles().size(); i++) {
139  wg.wiresInEachGroup.push_back( int( it->second.doubles()[i] ) );
140  }
141  //std::cout << "found upars " << std::endl;
142  } else if ( it->second.name() == "NumGroups" ) {
143  //numGroups = it->second.doubles();
144  for ( size_t i = 0 ; i < it->second.doubles().size(); i++) {
145  wg.consecutiveGroups.push_back( int( it->second.doubles()[i] ) );
146  }
147  } else if ( it->second.name() == "WireSpacing" ) {
148  wg.wireSpacing = it->second.doubles()[0];
149  } else if ( it->second.name() == "AlignmentPinToFirstWire" ) {
150  wg.alignmentPinToFirstWire = it->second.doubles()[0];
151  } else if ( it->second.name() == "TotNumWireGroups" ) {
152  wg.numberOfGroups = int(it->second.doubles()[0]);
153  } else if ( it->second.name() == "LengthOfFirstWire" ) {
154  wg.narrowWidthOfWirePlane = it->second.doubles()[0];
155  } else if ( it->second.name() == "LengthOfLastWire" ) {
156  wg.wideWidthOfWirePlane = it->second.doubles()[0];
157  } else if ( it->second.name() == "RadialExtentOfWirePlane" ) {
158  wg.lengthOfWirePlane = it->second.doubles()[0];
159  }
160  }
161  }
162 
170  uparvals.push_back( wg.wireSpacing );
171  uparvals.push_back( wg.alignmentPinToFirstWire );
172  uparvals.push_back( wg.numberOfGroups );
173  uparvals.push_back( wg.narrowWidthOfWirePlane );
174  uparvals.push_back( wg.wideWidthOfWirePlane );
175  uparvals.push_back( wg.lengthOfWirePlane );
176  uparvals.push_back( wg.wiresInEachGroup.size() );
177  for (CSCWireGroupPackage::Container::const_iterator it = wg.wiresInEachGroup.begin();
178  it != wg.wiresInEachGroup.end(); ++it) {
179  uparvals.push_back(*it);
180  }
181  for (CSCWireGroupPackage::Container::const_iterator it = wg.consecutiveGroups.begin();
182  it != wg.consecutiveGroups.end(); ++it) {
183  uparvals.push_back(*it);
184  }
186  }
187  fpar.clear();
188  // dpar = fv.logicalPart().solid().parameters();
189  if ( fv.logicalPart().solid().shape() == ddsubtraction ) {
190  const DDSubtraction& first = fv.logicalPart().solid();
191  const DDSubtraction& second = first.solidA();
192  const DDSolid& third = second.solidA();
193  dpar = third.parameters();
194  } else {
195  dpar = fv.logicalPart().solid().parameters();
196  }
197 
198  LogTrace(myName) << myName << ": noOfAnonParams=" << noOfAnonParams;
199  LogTrace(myName) << myName << ": fill fpar...";
200  LogTrace(myName) << myName << ": dpars are... " <<
201  dpar[4]/cm << ", " << dpar[8]/cm << ", " <<
202  dpar[3]/cm << ", " << dpar[0]/cm;
203 
204  fpar.push_back( ( dpar[4]/cm) );
205  fpar.push_back( ( dpar[8]/cm ) );
206  fpar.push_back( ( dpar[3]/cm ) );
207  fpar.push_back( ( dpar[0]/cm ) );
208 
209  LogTrace(myName) << myName << ": fill gtran...";
210 
211  gtran[0] = (float) 1.0 * (fv.translation().X() / cm);
212  gtran[1] = (float) 1.0 * (fv.translation().Y() / cm);
213  gtran[2] = (float) 1.0 * (fv.translation().Z() / cm);
214 
215  LogTrace(myName) << myName << ": gtran[0]=" << gtran[0] << ", gtran[1]=" <<
216  gtran[1] << ", gtran[2]=" << gtran[2];
217 
218  LogTrace(myName) << myName << ": fill grmat...";
219 
220  fv.rotation().GetComponents(trm.begin(), trm.end());
221  size_t rotindex = 0;
222  for (size_t i = 0; i < 9; ++i) {
223  grmat[i] = (float) 1.0 * trm[rotindex];
224  rotindex = rotindex + 3;
225  if ( (i+1) % 3 == 0 ) {
226  rotindex = (i+1) / 3;
227  }
228  }
229  LogTrace(myName) << myName << ": looking for wire group info for layer " <<
230  "E" << CSCDetId::endcap(id) <<
231  " S" << CSCDetId::station(id) <<
232  " R" << CSCDetId::ring(id) <<
233  " C" << CSCDetId::chamber(id) <<
234  " L" << CSCDetId::layer(id);
235 
236  if ( wg.numberOfGroups != 0 ) {
237  LogTrace(myName) << myName << ": fv.geoHistory: = " << fv.geoHistory() ;
238  LogTrace(myName) << myName << ": TotNumWireGroups = " << wg.numberOfGroups ;
239  LogTrace(myName) << myName << ": WireSpacing = " << wg.wireSpacing ;
240  LogTrace(myName) << myName << ": AlignmentPinToFirstWire = " << wg.alignmentPinToFirstWire ;
241  LogTrace(myName) << myName << ": Narrow width of wire plane = " << wg.narrowWidthOfWirePlane ;
242  LogTrace(myName) << myName << ": Wide width of wire plane = " << wg.wideWidthOfWirePlane ;
243  LogTrace(myName) << myName << ": Length in y of wire plane = " << wg.lengthOfWirePlane ;
244  LogTrace(myName) << myName << ": wg.consecutiveGroups.size() = " << wg.consecutiveGroups.size() ;
245  LogTrace(myName) << myName << ": wg.wiresInEachGroup.size() = " << wg.wiresInEachGroup.size() ;
246  LogTrace(myName) << myName << ": \tNumGroups\tWiresInGroup" ;
247  for (size_t i = 0; i < wg.consecutiveGroups.size(); i++) {
248  LogTrace(myName) << myName << " \t" << wg.consecutiveGroups[i] << "\t\t" << wg.wiresInEachGroup[i] ;
249  }
250  } else {
251  LogTrace(myName) << myName << ": DDD is MISSING SpecPars for wire groups" ;
252  }
253  LogTrace(myName) << myName << ": end of wire group info. " ;
254 
255  LogTrace(myName) << myName << ":_z_ E" << jendcap << " S" << jstation << " R" << jring <<
256  " C" << jchamber << " L" << jlayer <<
257  " gx=" << gtran[0] << ", gy=" << gtran[1] << ", gz=" << gtran[2] <<
258  " thickness=" << fpar[2]*2.;
259 
260  if ( jlayer == 0 ) { // Can only build chambers if we're filtering them
261 
262  LogTrace(myName) << myName << ":_z_ frame=" << uparvals[31]/10. <<
263  " gap=" << uparvals[32]/10. << " panel=" << uparvals[33]/10. << " offset=" << uparvals[34]/10.;
264 
265  if ( jstation==1 && jring==1 ) {
266  // set up params for ME1a and ME1b and call buildChamber *for each*
267  // Both get the full ME11 dimensions
268 
269  // detid is for ME11 and that's what we're using for ME1b in the software
270 
271  rig.insert( id, gtran, grmat, fpar );
272  if ( !chSpecsAlreadyExist ) {
273  // rdp.pCSCDetIds.push_back(CSCDetId(id));
274  // std::cout << " inserting chamber type " << chamberType << std::endl;
275  rdp.pChamberType.push_back(chamberType);
276  rdp.pUserParOffset.push_back(rdp.pfupars.size());
277  rdp.pUserParSize.push_back(uparvals.size());
278  std::copy ( uparvals.begin(), uparvals.end(), std::back_inserter(rdp.pfupars));
279  }
280 
281  // No. of anonymous parameters per chamber type should be read from cscSpecs file...
282  // Only required for ME11 splitting into ME1a and ME1b values,
283  // If it isn't seen may as well try to get further but this value will depend
284  // on structure of the file so may not even match!
285  const int kNoOfAnonParams = 35;
286  if ( noOfAnonParams == 0 ) { noOfAnonParams = kNoOfAnonParams; } // in case it wasn't seen
287 
288  std::copy( uparvals.begin()+noOfAnonParams+1, uparvals.begin()+(2*noOfAnonParams)+2, uparvals.begin()+1 ); // copy ME1a params from back to the front
289 
290  CSCDetId detid1a = CSCDetId( jendcap, 1, 4, jchamber, 0 ); // reset to ME1A
291  rig.insert( detid1a.rawId(), gtran, grmat, fpar );
292  int chtypeA = CSCChamberSpecs::whatChamberType( 1, 4 );
293  ct = 0;
294  for ( ; ct < rdp.pChamberType.size() ; ++ct ) {
295  if ( chtypeA == rdp.pChamberType[ct] ) {
296  break;
297  }
298  }
299  if ( ct < rdp.pChamberType.size() && rdp.pChamberType[ct] == chtypeA ) {
300  // then its in already, don't put it
301  // std::cout << "found chamber type " << chtypeA << " so don't put it in! " << std::endl;
302  } else {
303  // rdp.pCSCDetIds.push_back(detid1a);
304  // std::cout << " inserting chamber type " << chtypeA << std::endl;
305  rdp.pChamberType.push_back(chtypeA);
306  rdp.pUserParOffset.push_back(rdp.pfupars.size());
307  rdp.pUserParSize.push_back(uparvals.size());
308  std::copy ( uparvals.begin(), uparvals.end(), std::back_inserter(rdp.pfupars));
309  }
310 
311  }
312  else {
313  rig.insert( id, gtran, grmat, fpar );
314  if ( !chSpecsAlreadyExist ) {
315  // rdp.pCSCDetIds.push_back(CSCDetId(id));
316  // std::cout << " inserting chamber type " << chamberType << std::endl;
317  rdp.pChamberType.push_back(chamberType);
318  rdp.pUserParOffset.push_back(rdp.pfupars.size());
319  rdp.pUserParSize.push_back(uparvals.size());
320  std::copy ( uparvals.begin(), uparvals.end(), std::back_inserter(rdp.pfupars));
321  }
322  }
323 
324  } // filtering chambers.
325 
326  doSubDets = fv.next();
327  }
328  return true;
329 }
int chamber() const
Definition: CSCDetId.h:70
int i
Definition: DBlmapReader.cc:9
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.
void addFilter(const DDFilter &, log_op op=AND)
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:77
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
int layer() const
Definition: CSCDetId.h:63
A DDSolid represents the shape of a part.
Definition: DDSolid.h:35
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:95
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
bool first
Definition: L1TdeRCT.cc:94
#define LogTrace(id)
DDSolid solidA(void) const
Definition: DDSolid.cc:545
virtual int baseNumberToUnitNumber(const MuonBaseNumber)
int ring() const
Definition: CSCDetId.h:77
std::string toString() const
Definition: DDBase.h:86
std::vector< int > pUserParSize
bool firstChild()
set the current node to the first child ...
void setCriteria(const DDValue &nameVal, comp_op, log_op l=AND, bool asString=true, bool merged=true)
Definition: DDFilter.cc:285
int station() const
Definition: CSCDetId.h:88
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)
The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs.
Definition: DDFilter.h:37