CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCGeometryBuilder.cc
Go to the documentation of this file.
1 #include "CSCGeometryBuilder.h"
2 //#include <CondFormats/GeometryObjects/interface/CSCRecoDigiParameters.h>
3 //#include <CondFormats/GeometryObjects/interface/RecoIdealGeometry.h>
4 
6 
10 
12 
13 #include <iostream>
14 #include <iomanip>
15 #include <algorithm>
16 #include <vector>
17 
18 CSCGeometryBuilder::CSCGeometryBuilder() : myName("CSCGeometryBuilder"){}
19 
20 
22 
23 
24 void CSCGeometryBuilder::build( boost::shared_ptr<CSCGeometry> theGeometry
25  , const RecoIdealGeometry& rig
26  , const CSCRecoDigiParameters& cscpars ) {
27 
28  // CSCGeometry* theGeometry = new CSCGeometry;
29 
30  std::vector<float> fpar;
31  std::vector<float> gtran;
32  std::vector<float> grmat;
33  std::vector<float> fupar;
34  std::vector<double>::const_iterator it, endIt;
35  const std::vector<DetId>& detids(rig.detIds());
36 
37  for ( size_t idt = 0; idt < detids.size(); ++idt) {
38  CSCDetId detid = CSCDetId( detids[idt] );
39  // int jendcap = detid.endcap();
40  int jstation = detid.station();
41  int jring = detid.ring();
42  // int jchamber = detid.chamber();
43 
44  endIt = rig.shapeEnd(idt);
45  fpar.clear();
46  for ( it = rig.shapeStart(idt); it != endIt; ++it) {
47  fpar.push_back( (float)(*it) );
48  }
49 
50  gtran.clear();
51  endIt = rig.tranEnd(idt);
52  for ( it = rig.tranStart(idt); it != endIt; ++it ) {
53  gtran.push_back((float)(*it));
54  }
55  grmat.clear();
56  endIt = rig.rotEnd(idt);
57  for ( it = rig.rotStart(idt) ; it != endIt; ++it ) {
58  grmat.push_back((float)(*it));
59  }
60 
61  // get the chamber type from existing info
62  int chamberType = CSCChamberSpecs::whatChamberType( jstation, jring );
63  // std::cout << "Chamber type = " << chamberType << std::endl;
64  size_t cs = 0;
65  // assert ( cscpars.pCSCDetIds.size() != 0 );
66  assert ( cscpars.pChamberType.size() != 0 );
67  // while (cs < cscpars.pCSCDetIds.size() && detid != cscpars.pCSCDetIds[cs]) {
68  while (cs < cscpars.pChamberType.size() && chamberType != cscpars.pChamberType[cs]) {
69  ++cs;
70  }
71  // assert ( cs != cscpars.pCSCDetIds.size() );
72  assert ( cs != cscpars.pChamberType.size() );
73 
74  // check the existence of the specs for this type WHY? Remove it...
75  // const CSCChamberSpecs* aSpecs = theGeometry->findSpecs( chamberType );
76  size_t fu, numfuPars;
78  fu = cscpars.pUserParOffset[cs];
79  numfuPars = fu + 1 + size_t(cscpars.pfupars[fu]);
80 
81  // upars from db are now uparvals + wg info so we need to unwrap only part here first...
82  LogTrace(myName) << myName << ": I think I have " << cscpars.pUserParSize[cs] << " values in pfupars (uparvals)." << std::endl;
83  LogTrace(myName) << myName << ": For fupar I will start at " << cscpars.pUserParOffset[cs] + 1
84  << " in pfupars and go to " << numfuPars << "." << std::endl;
85  // if ( aSpecs == 0 ) {
86  for ( ++fu; fu < numfuPars; ++fu ) {
87  LogTrace(myName) << myName << ": pfupars[" << fu << "]=" << cscpars.pfupars[fu] << std::endl;
88  fupar.push_back(cscpars.pfupars[fu]);
89  }
90 // } else {
91 // fu = fu + numfuPars + 1;
92 // }
93  // now, we need to start from "here" at fu to go on and build wg...
94  wg.wireSpacing = cscpars.pfupars[fu++];
95  wg.alignmentPinToFirstWire = cscpars.pfupars[fu++];
96  wg.numberOfGroups = int(cscpars.pfupars[fu++]);
97  wg.narrowWidthOfWirePlane = cscpars.pfupars[fu++];
98  wg.wideWidthOfWirePlane = cscpars.pfupars[fu++];
99  wg.lengthOfWirePlane = cscpars.pfupars[fu++];
100  size_t numgrp = static_cast<size_t>(cscpars.pfupars[fu]);
101  size_t maxFu = fu + 1 + numgrp;
102  fu++;
103  for ( ;fu < maxFu; ++fu ) {
104  wg.wiresInEachGroup.push_back(int(cscpars.pfupars[fu]));
105  }
106  maxFu = fu + numgrp;
107  //stupid comment // MEC: 2008-04-30: decided I need to have wg every time unless whole wg idea is re-worked.
108  // std::cout << " fu = " << fu << " going to maxFu = " << maxFu << std::endl;
109  for ( ;fu < maxFu; ++fu ) {
110  wg.consecutiveGroups.push_back(int(cscpars.pfupars[fu]));
111  }
112 
113  if ( wg.numberOfGroups != 0 ) {
114  LogTrace(myName) << myName << ": TotNumWireGroups = " << wg.numberOfGroups ;
115  LogTrace(myName) << myName << ": WireSpacing = " << wg.wireSpacing ;
116  LogTrace(myName) << myName << ": AlignmentPinToFirstWire = " << wg.alignmentPinToFirstWire ;
117  LogTrace(myName) << myName << ": Narrow width of wire plane = " << wg.narrowWidthOfWirePlane ;
118  LogTrace(myName) << myName << ": Wide width of wire plane = " << wg.wideWidthOfWirePlane ;
119  LogTrace(myName) << myName << ": Length in y of wire plane = " << wg.lengthOfWirePlane ;
120  LogTrace(myName) << myName << ": wg.consecutiveGroups.size() = " << wg.consecutiveGroups.size() ;
121  LogTrace(myName) << myName << ": wg.wiresInEachGroup.size() = " << wg.wiresInEachGroup.size() ;
122  LogTrace(myName) << myName << ": \tNumGroups\tWiresInGroup" ;
123  for (size_t i = 0; i < wg.consecutiveGroups.size(); i++) {
124  LogTrace(myName) << myName << " \t" << wg.consecutiveGroups[i] << "\t\t" << wg.wiresInEachGroup[i] ;
125  }
126  } else {
127  LogTrace(myName) << myName << ": DDD is MISSING SpecPars for wire groups" ;
128  }
129  LogTrace(myName) << myName << ": end of wire group info. " ;
130 
131  // CSCWireGroupPackage wg = cscpars.pWGPs[cs];
132  // Are we going to apply centre-to-intersection offsets, even if values exist in the specs file?
133  if ( !theGeometry->centreTIOffsets() ) fupar[30] = 0.; // reset to zero if flagged 'off'
134 
135  buildChamber (theGeometry, detid, fpar, fupar, gtran, grmat, wg ); //, cscpars.pWGPs[cs] );
136  fupar.clear();
137  }
138  // return theGeometry;
139 }
140 
142  boost::shared_ptr<CSCGeometry> theGeometry // the geometry container
143  , CSCDetId chamberId // the DetId for this chamber
144  , const std::vector<float>& fpar // volume parameters hB, hT. hD, hH
145  , const std::vector<float>& fupar // user parameters
146  , const std::vector<float>& gtran // translation vector
147  , const std::vector<float>& grmat // rotation matrix
148  , const CSCWireGroupPackage& wg // wire group info
149  ) {
150 
151  LogTrace(myName) << myName << ": entering buildChamber" ;
152 
153  int jend = chamberId.endcap();
154  int jstat = chamberId.station();
155  int jring = chamberId.ring();
156  int jch = chamberId.chamber();
157  int jlay = chamberId.layer();
158 
159  if (jlay != 0 ) edm::LogWarning(myName) << "Error! CSCGeometryBuilderFromDDD was fed layer id = " << jlay << "\n";
160 
161  const size_t kNpar = 4;
162  if ( fpar.size() != kNpar )
163  edm::LogError(myName) << "Error, expected npar="
164  << kNpar << ", found npar=" << fpar.size() << std::endl;
165 
166  LogTrace(myName) << myName << ": E" << jend << " S" << jstat << " R" << jring <<
167  " C" << jch << " L" << jlay ;
168  LogTrace(myName) << myName << ": npar=" << fpar.size() << " hB=" << fpar[0]
169  << " hT=" << fpar[1] << " hD=" << fpar[2] << " hH=" << fpar[3] ;
170  LogTrace(myName) << myName << ": gtran[0,1,2]=" << gtran[0] << " " << gtran[1] << " " << gtran[2] ;
171  LogTrace(myName) << myName << ": grmat[0-8]=" << grmat[0] << " " << grmat[1] << " " << grmat[2] << " "
172  << grmat[3] << " " << grmat[4] << " " << grmat[5] << " "
173  << grmat[6] << " " << grmat[7] << " " << grmat[8] ;
174  LogTrace(myName) << myName << ": nupar=" << fupar.size() << " upar[0]=" << fupar[0]
175  << " upar[" << fupar.size()-1 << "]=" << fupar[fupar.size()-1];
176 
177 
178  CSCChamber* chamber = const_cast<CSCChamber*>(theGeometry->chamber( chamberId ));
179  if ( chamber ){
180  }
181  else { // this chamber not yet built/stored
182 
183  LogTrace(myName) << myName <<": CSCChamberSpecs::build requested for ME" << jstat << jring ;
184  int chamberType = CSCChamberSpecs::whatChamberType( jstat, jring );
185  const CSCChamberSpecs* aSpecs = theGeometry->findSpecs( chamberType );
186 // // CSCChamberSpecs* aSpecs = CSCChamberSpecs::specs( chamberType );
187 // if ( aSpecs == 0 ) aSpecs = theGeometry->buildSpecs( chamberType, fpar, fupar, wg );
188  // aSpecs = CSCChamberSpecs::build( chamberType, fpar, fupar, wg );
189  if ( fupar.size() != 0 && aSpecs == 0 ) {
190  // make new one:
191  aSpecs = theGeometry->buildSpecs (chamberType, fpar, fupar, wg);
192  } else if ( fupar.size() == 0 && aSpecs == 0 ) {
193  std::cout << "SHOULD BE THROW? Error, wg and/or fupar size are 0 BUT this Chamber Spec has not been built!" << std::endl;
194  }
195 // else if (fupar.size() != 0 && aSpecs != 0 ) {
196 // std::cout << "SHOULD BE THROW? Error, a Chamber Specs was found AND still the fupar and/or wg were/was non-zero! " << std::endl;
197 // }
198 
199 
200  // Build a Transformation out of GEANT gtran and grmat...
201  // These are used to transform a point in the local reference frame
202  // of a subdetector to the global frame of CMS by
203  // (grmat)^(-1)*local + (gtran)
204  // The corresponding transformation from global to local is
205  // (grmat)*(global - gtran)
206 
207  BoundSurface::RotationType aRot( grmat[0], grmat[1], grmat[2],
208  grmat[3], grmat[4], grmat[5],
209  grmat[6], grmat[7], grmat[8] );
210 
211  // This rotation from GEANT considers the detector face as the x-z plane.
212  // We want this to be the local x-y plane.
213  // Furthermore, the -z_global endcap has LH local coordinates, since it is built
214  // in GEANT as a *reflection* of the +z_global endcap.
215  // So we need to rotate, and in -z flip local x.
216 
217  // aRot.rotateAxes will transform aRot in place so that it becomes
218  // applicable to the new local coordinates: detector face in x-y plane
219  // looking out along z, in either endcap.
220 
221  // The interface for rotateAxes specifies 'new' X,Y,Z but the
222  // implementation deals with them as the 'old'.
223 
224  Basic3DVector<float> oldX( 1., 0., 0. );
225  Basic3DVector<float> oldY( 0., 0., -1. );
226  Basic3DVector<float> oldZ( 0., 1., 0. );
227 
228  if ( gtran[2]<0. ) oldX *= -1;
229 
230  aRot.rotateAxes( oldX, oldY, oldZ );
231 
232  // Need to know z of layers w.r.t to z of centre of chamber.
233 
234  float frameThickness = fupar[31]/10.; // mm -> cm
235  float gapThickness = fupar[32]/10.; // mm -> cm
236  float panelThickness = fupar[33]/10.; // mm -> cm
237  float zAverageAGVtoAF = fupar[34]/10.; // mm -> cm
238 
239  float layerThickness = gapThickness; // consider the layer to be the gas gap
240  float layerSeparation = gapThickness + panelThickness; // centre-to-centre of neighbouring layers
241 
242  float chamberThickness = 7.*panelThickness + 6.*gapThickness + 2.*frameThickness ; // chamber frame thickness
243  float hChamberThickness = chamberThickness/2.; // @@ should match value returned from DDD directly
244 
245  // distAverageAGVtoAF is offset between centre of chamber (AF) and (L1+L6)/2 (average AGVs)
246  // where AF = AluminumFrame and AGV=ActiveGasVolume (volume names in DDD).
247  // It is signed based on global z values: zc - (zl1+zl6)/2
248 
249  // Local z values w.r.t. AF...
250  // z of wires in layer 1 = z_w1 = +/- zAverageAGVtoAF + 2.5*layerSeparation; // layer 1 is at most +ve local z
251  // The sign in '+/-' depends on relative directions of local and global z.
252  // It is '-' if they are the same direction, and '+' if opposite directions.
253  // z of wires in layer N = z_wN = z_w1 - (N-1)*layerSeparation;
254  // z of strips in layer N = z_sN = z_wN + gapThickness/2.; @@ BEWARE: need to check if it should be '-gapThickness/2' !
255 
256  // Set dimensions of trapezoidal chamber volume
257  // N.B. apothem is 4th in fpar but 3rd in ctor
258 
259  // hChamberThickness and fpar[2] should be the same - but using the above value at least shows
260  // how chamber structure works
261 
262  // TrapezoidalPlaneBounds* bounds = new TrapezoidalPlaneBounds( fpar[0], fpar[1], fpar[3], fpar[2] );
263  TrapezoidalPlaneBounds* bounds = new TrapezoidalPlaneBounds( fpar[0], fpar[1], fpar[3], hChamberThickness );
264 
265  // Centre of chamber in z is specified in DDD
266  Surface::PositionType aVec( gtran[0], gtran[1], gtran[2] );
267 
268  BoundPlane::BoundPlanePointer plane = BoundPlane::build(aVec, aRot, bounds);
269  delete bounds; // bounds cloned by BoundPlane, so we can delete it
270 
271  CSCChamber* chamber = new CSCChamber( plane, chamberId, aSpecs );
272  theGeometry->addChamber( chamber );
273 
274  LogTrace(myName) << myName << ": Create chamber E" << jend << " S" << jstat
275  << " R" << jring << " C" << jch
276  << " z=" << gtran[2]
277  << " t/2=" << fpar[2] << " (DDD) or " << hChamberThickness
278  << " (specs) adr=" << chamber ;
279 
280  // Create the component layers of this chamber
281  // We're taking the z as the z of the wire plane within the layer (middle of gas gap)
282 
283  // Specify global z of layer by offsetting from centre of chamber: since layer 1
284  // is nearest to IP in stations 1/2 but layer 6 is nearest in stations 3/4,
285  // we need to adjust sign of offset appropriately...
286  int localZwrtGlobalZ = +1;
287  if ( (jend==1 && jstat<3 ) || ( jend==2 && jstat>2 ) ) localZwrtGlobalZ = -1;
288  int globalZ = +1;
289  if ( jend == 2 ) globalZ = -1;
290 // int localZwrtGlobalZ = +1;
291 // if ( (jend==1 && jstat<3 ) || ( jend==2 && jstat>2 ) ) localZwrtGlobalZ = -1;
292 
293 
294  LogTrace(myName) << myName << ": layerSeparation=" << layerSeparation
295  << ", zAF-zAverageAGV=" << zAverageAGVtoAF
296  << ", localZwrtGlobalZ=" << localZwrtGlobalZ
297  << ", gtran[2]=" << gtran[2] ;
298 
299  for ( short j = 1; j <= 6; ++j ) {
300 
301  CSCDetId layerId = CSCDetId( jend, jstat, jring, jch, j );
302 
303  // extra-careful check that we haven't already built this layer
304  const CSCLayer* cLayer = dynamic_cast<const CSCLayer*> (theGeometry->idToDet( layerId ) );
305 
306  if ( cLayer == 0 ) {
307 
308  // build the layer - need the chamber's specs and an appropriate layer-geometry
309  const CSCChamberSpecs* aSpecs = chamber->specs();
310  const CSCLayerGeometry* geom =
311  (j%2 != 0) ? aSpecs->oddLayerGeometry( jend ) :
312  aSpecs->evenLayerGeometry( jend );
313 
314  // Build appropriate BoundPlane, based on parent chamber, with gas gap as thickness
315 
316  // centre of chamber is at global z = gtran[2]
317  float zlayer = gtran[2] - globalZ*zAverageAGVtoAF + localZwrtGlobalZ*(3.5-j)*layerSeparation;
318 
319  BoundSurface::RotationType chamberRotation = chamber->surface().rotation();
320  BoundPlane::PositionType layerPosition( gtran[0], gtran[1], zlayer );
321  // TrapezoidalPlaneBounds* bounds = new TrapezoidalPlaneBounds( *geom );
322  // std::vector<float> dims = bounds->parameters(); // returns hb, ht, d, a
323  std::vector<float> dims = geom->parameters(); // returns hb, ht, d, a
324  dims[2] = layerThickness/2.; // half-thickness required and note it is 3rd value in vector
325  // delete bounds;
326  // bounds = new TrapezoidalPlaneBounds( dims[0], dims[1], dims[3], dims[2] );
327  TrapezoidalPlaneBounds* bounds = new TrapezoidalPlaneBounds( dims[0], dims[1], dims[3], dims[2] );
328  BoundPlane::BoundPlanePointer plane = BoundPlane::build(layerPosition, chamberRotation, bounds);
329  delete bounds;
330 
331  CSCLayer* layer = new CSCLayer( plane, layerId, chamber, geom );
332 
333  LogTrace(myName) << myName << ": Create layer E" << jend << " S" << jstat
334  << " R" << jring << " C" << jch << " L" << j
335  << " z=" << zlayer
336  << " t=" << layerThickness << " or " << layer->surface().bounds().thickness()
337  << " adr=" << layer << " layerGeom adr=" << geom ;
338 
339  chamber->addComponent(j, layer);
340  theGeometry->addLayer( layer );
341  }
342  else {
343  edm::LogError(myName) << ": ERROR, layer " << j <<
344  " for chamber = " << ( chamber->id() ) <<
345  " already exists: layer address=" << cLayer <<
346  " chamber address=" << chamber << "\n";
347  }
348 
349  } // layer construction within chamber
350  } // chamber construction
351 }
int chamber() const
Definition: CSCDetId.h:70
int i
Definition: DBlmapReader.cc:9
auto_ptr< ClusterSequence > cs
std::vector< double >::const_iterator rotEnd(size_t ind) const
static int whatChamberType(int istation, int iring)
std::vector< double >::const_iterator rotStart(size_t ind) const
void buildChamber(boost::shared_ptr< CSCGeometry > theGeometry, CSCDetId chamberId, const std::vector< float > &fpar, const std::vector< float > &fupar, const std::vector< float > &gtran, const std::vector< float > &grmat, const CSCWireGroupPackage &wg)
Build one CSC chamber, and its component layers, and add them to the geometry.
static BoundPlanePointer build(const PositionType &pos, const RotationType &rot, const Bounds *bounds, MediumProperties *mp=0)
Definition: BoundPlane.h:26
int layer() const
Definition: CSCDetId.h:63
TkRotation & rotateAxes(const Basic3DVector< T > &newX, const Basic3DVector< T > &newY, const Basic3DVector< T > &newZ)
std::vector< float > pfupars
int endcap() const
Definition: CSCDetId.h:95
virtual float thickness() const =0
virtual const std::vector< float > parameters() const
std::vector< double >::const_iterator tranEnd(size_t ind) const
std::vector< int > pChamberType
std::vector< double >::const_iterator tranStart(size_t ind) const
const CSCLayerGeometry * evenLayerGeometry(int iendcap) const
int j
Definition: DBlmapReader.cc:9
std::vector< int > pUserParOffset
const std::string myName
#define LogTrace(id)
const std::vector< DetId > & detIds() const
int ring() const
Definition: CSCDetId.h:77
const Bounds & bounds() const
Definition: BoundSurface.h:89
std::vector< int > pUserParSize
CSCGeometryBuilder()
Constructor.
const CSCLayerGeometry * oddLayerGeometry(int iendcap) const
Accessors for LayerGeometry&#39;s.
std::vector< double >::const_iterator shapeEnd(size_t ind) const
void build(boost::shared_ptr< CSCGeometry > theGeometry, const RecoIdealGeometry &rig, const CSCRecoDigiParameters &cscpars)
Build the geometry.
std::vector< double >::const_iterator shapeStart(size_t ind) const
const BoundPlane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
virtual ~CSCGeometryBuilder()
Destructor.
int station() const
Definition: CSCDetId.h:88
tuple cout
Definition: gather_cfg.py:121