00001 #include "Fireworks/Geometry/interface/FWRecoGeometryESProducer.h"
00002 #include "Fireworks/Geometry/interface/FWRecoGeometry.h"
00003 #include "Fireworks/Geometry/interface/FWRecoGeometryRecord.h"
00004
00005 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
00006 #include "DataFormats/GeometrySurface/interface/TrapezoidalPlaneBounds.h"
00007 #include "Geometry/CommonDetUnit/interface/GlobalTrackingGeometry.h"
00008 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00009 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00010 #include "Geometry/CSCGeometry/interface/CSCGeometry.h"
00011 #include "Geometry/DTGeometry/interface/DTGeometry.h"
00012 #include "Geometry/CSCGeometry/interface/CSCChamber.h"
00013 #include "Geometry/CSCGeometry/interface/CSCLayer.h"
00014 #include "Geometry/DTGeometry/interface/DTChamber.h"
00015 #include "Geometry/DTGeometry/interface/DTLayer.h"
00016 #include "Geometry/RPCGeometry/interface/RPCGeometry.h"
00017 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
00018 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00019 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00020 #include "Geometry/TrackerGeometryBuilder/interface/RectangularPixelTopology.h"
00021 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00022 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetUnit.h"
00023 #include "Geometry/TrackerGeometryBuilder/interface/StripGeomDetType.h"
00024 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00025 #include "Geometry/CommonTopologies/interface/RectangularStripTopology.h"
00026 #include "Geometry/CommonTopologies/interface/TrapezoidalStripTopology.h"
00027
00028 # define ADD_PIXEL_TOPOLOGY( rawid, detUnit ) \
00029 const PixelGeomDetUnit* det = dynamic_cast<const PixelGeomDetUnit*>( detUnit ); \
00030 if( det ) \
00031 { \
00032 const PixelTopology* topo = &det->specificTopology(); \
00033 m_fwGeometry->idToName[rawid].topology[0] = topo->nrows(); \
00034 m_fwGeometry->idToName[rawid].topology[1] = topo->ncolumns(); \
00035 } \
00036
00037 # define ADD_SISTRIP_TOPOLOGY( rawid, detUnit ) \
00038 const StripGeomDetUnit* det = dynamic_cast<const StripGeomDetUnit*>( detUnit ); \
00039 if( det ) \
00040 { \
00041 const StripTopology* topo = dynamic_cast<const StripTopology*>( &det->specificTopology() ); \
00042 m_fwGeometry->idToName[rawid].topology[0] = 0; \
00043 m_fwGeometry->idToName[rawid].topology[1] = topo->nstrips(); \
00044 m_fwGeometry->idToName[rawid].topology[2] = topo->stripLength(); \
00045 if( const RadialStripTopology* rtop = dynamic_cast<const RadialStripTopology*>( &(det->specificType().specificTopology()) ) ) \
00046 { \
00047 m_fwGeometry->idToName[rawid].topology[0] = 1; \
00048 m_fwGeometry->idToName[rawid].topology[3] = rtop->yAxisOrientation(); \
00049 m_fwGeometry->idToName[rawid].topology[4] = rtop->originToIntersection(); \
00050 m_fwGeometry->idToName[rawid].topology[5] = rtop->phiOfOneEdge(); \
00051 m_fwGeometry->idToName[rawid].topology[6] = rtop->angularWidth(); \
00052 } \
00053 else if( dynamic_cast<const RectangularStripTopology*>( &(det->specificType().specificTopology()) ) ) \
00054 { \
00055 m_fwGeometry->idToName[rawid].topology[0] = 2; \
00056 m_fwGeometry->idToName[rawid].topology[3] = topo->pitch(); \
00057 } \
00058 else if( dynamic_cast<const TrapezoidalStripTopology*>( &(det->specificType().specificTopology()) ) ) \
00059 { \
00060 m_fwGeometry->idToName[rawid].topology[0] = 3; \
00061 m_fwGeometry->idToName[rawid].topology[3] = topo->pitch(); \
00062 } \
00063 } \
00064
00065 FWRecoGeometryESProducer::FWRecoGeometryESProducer( const edm::ParameterSet& )
00066 : m_current( -1 )
00067 {
00068 setWhatProduced( this );
00069 }
00070
00071 FWRecoGeometryESProducer::~FWRecoGeometryESProducer( void )
00072 {}
00073
00074 boost::shared_ptr<FWRecoGeometry>
00075 FWRecoGeometryESProducer::produce( const FWRecoGeometryRecord& record )
00076 {
00077 using namespace edm;
00078
00079 m_fwGeometry = boost::shared_ptr<FWRecoGeometry>( new FWRecoGeometry );
00080
00081 record.getRecord<GlobalTrackingGeometryRecord>().get( m_geomRecord );
00082
00083 DetId detId( DetId::Tracker, 0 );
00084 m_trackerGeom = (const TrackerGeometry*) m_geomRecord->slaveGeometry( detId );
00085
00086 record.getRecord<CaloGeometryRecord>().get( m_caloGeom );
00087
00088 addPixelBarrelGeometry( );
00089 addPixelForwardGeometry();
00090 addTIBGeometry();
00091 addTIDGeometry();
00092 addTOBGeometry();
00093 addTECGeometry();
00094 addDTGeometry();
00095 addCSCGeometry();
00096 addRPCGeometry();
00097 addGEMGeometry();
00098 addCaloGeometry();
00099
00100 m_fwGeometry->idToName.resize( m_current + 1 );
00101 std::vector<FWRecoGeom::Info>( m_fwGeometry->idToName ).swap( m_fwGeometry->idToName );
00102 std::sort( m_fwGeometry->idToName.begin(), m_fwGeometry->idToName.end());
00103
00104 return m_fwGeometry;
00105 }
00106
00107 void
00108 FWRecoGeometryESProducer::addCSCGeometry( void )
00109 {
00110 DetId detId( DetId::Muon, 2 );
00111 const CSCGeometry* cscGeometry = (const CSCGeometry*) m_geomRecord->slaveGeometry( detId );
00112 for( std::vector<CSCChamber*>::const_iterator it = cscGeometry->chambers().begin(),
00113 end = cscGeometry->chambers().end();
00114 it != end; ++it )
00115 {
00116 const CSCChamber *chamber = *it;
00117
00118 if( chamber )
00119 {
00120 unsigned int rawid = chamber->geographicalId();
00121 unsigned int current = insert_id( rawid );
00122 fillShapeAndPlacement( current, chamber );
00123
00124
00125
00126 for( std::vector< const CSCLayer* >::const_iterator lit = chamber->layers().begin(),
00127 lend = chamber->layers().end();
00128 lit != lend; ++lit )
00129 {
00130 const CSCLayer* layer = *lit;
00131
00132 if( layer )
00133 {
00134 unsigned int rawid = layer->geographicalId();
00135 unsigned int current = insert_id( rawid );
00136 fillShapeAndPlacement( current, layer );
00137
00138 const CSCStripTopology* stripTopology = layer->geometry()->topology();
00139 m_fwGeometry->idToName[current].topology[0] = stripTopology->yAxisOrientation();
00140 m_fwGeometry->idToName[current].topology[1] = stripTopology->centreToIntersection();
00141 m_fwGeometry->idToName[current].topology[2] = stripTopology->yCentreOfStripPlane();
00142 m_fwGeometry->idToName[current].topology[3] = stripTopology->phiOfOneEdge();
00143 m_fwGeometry->idToName[current].topology[4] = stripTopology->stripOffset();
00144 m_fwGeometry->idToName[current].topology[5] = stripTopology->angularWidth();
00145
00146 const CSCWireTopology* wireTopology = layer->geometry()->wireTopology();
00147 m_fwGeometry->idToName[current].topology[6] = wireTopology->wireSpacing();
00148 m_fwGeometry->idToName[current].topology[7] = wireTopology->wireAngle();
00149 }
00150 }
00151 }
00152 }
00153 }
00154
00155 void
00156 FWRecoGeometryESProducer::addDTGeometry( void )
00157 {
00158 DetId detId( DetId::Muon, 1 );
00159 const DTGeometry* dtGeometry = (const DTGeometry*) m_geomRecord->slaveGeometry( detId );
00160
00161
00162
00163
00164 for( std::vector<DTChamber *>::const_iterator it = dtGeometry->chambers().begin(),
00165 end = dtGeometry->chambers().end();
00166 it != end; ++it )
00167 {
00168 const DTChamber *chamber = *it;
00169
00170 if( chamber )
00171 {
00172 unsigned int rawid = chamber->geographicalId().rawId();
00173 unsigned int current = insert_id( rawid );
00174 fillShapeAndPlacement( current, chamber );
00175 }
00176 }
00177
00178
00179 for( std::vector<DTLayer*>::const_iterator it = dtGeometry->layers().begin(),
00180 end = dtGeometry->layers().end();
00181 it != end; ++it )
00182 {
00183 const DTLayer* layer = *it;
00184
00185 if( layer )
00186 {
00187 unsigned int rawid = layer->id().rawId();
00188 unsigned int current = insert_id( rawid );
00189 fillShapeAndPlacement( current, layer );
00190
00191 const DTTopology& topo = layer->specificTopology();
00192 const BoundPlane& surf = layer->surface();
00193
00194 m_fwGeometry->idToName[current].topology[0] = topo.cellWidth();
00195 m_fwGeometry->idToName[current].topology[1] = topo.cellHeight();
00196 m_fwGeometry->idToName[current].topology[2] = topo.cellLenght();
00197 m_fwGeometry->idToName[current].topology[3] = topo.firstChannel();
00198 m_fwGeometry->idToName[current].topology[4] = topo.lastChannel();
00199 m_fwGeometry->idToName[current].topology[5] = topo.channels();
00200
00201
00202 m_fwGeometry->idToName[current].topology[6] = surf.bounds().width();
00203 m_fwGeometry->idToName[current].topology[7] = surf.bounds().thickness();
00204 m_fwGeometry->idToName[current].topology[8] = surf.bounds().length();
00205 }
00206 }
00207 }
00208
00209 void
00210 FWRecoGeometryESProducer::addRPCGeometry( void )
00211 {
00212
00213
00214
00215 DetId detId( DetId::Muon, 3 );
00216 const RPCGeometry* rpcGeom = (const RPCGeometry*) m_geomRecord->slaveGeometry( detId );
00217 for( std::vector<RPCRoll *>::const_iterator it = rpcGeom->rolls().begin(),
00218 end = rpcGeom->rolls().end();
00219 it != end; ++it )
00220 {
00221 RPCRoll* roll = (*it);
00222 if( roll )
00223 {
00224 unsigned int rawid = roll->geographicalId().rawId();
00225 unsigned int current = insert_id( rawid );
00226 fillShapeAndPlacement( current, roll );
00227
00228 const StripTopology& topo = roll->specificTopology();
00229 m_fwGeometry->idToName[current].topology[0] = topo.nstrips();
00230 m_fwGeometry->idToName[current].topology[1] = topo.stripLength();
00231 m_fwGeometry->idToName[current].topology[2] = topo.pitch();
00232 }
00233 }
00234 }
00235
00236 void
00237 FWRecoGeometryESProducer::addGEMGeometry( void )
00238 {
00239
00240
00241
00242 DetId detId( DetId::Muon, 4 );
00243 const GEMGeometry* gemGeom = (const GEMGeometry*) m_geomRecord->slaveGeometry( detId );
00244 for( std::vector<GEMEtaPartition *>::const_iterator it = gemGeom->etaPartitions().begin(),
00245 end = gemGeom->etaPartitions().end();
00246 it != end; ++it )
00247 {
00248 GEMEtaPartition* roll = (*it);
00249 if( roll )
00250 {
00251 unsigned int rawid = (*it)->geographicalId().rawId();
00252 unsigned int current = insert_id( rawid );
00253 fillShapeAndPlacement( current, roll );
00254
00255 const StripTopology& topo = roll->specificTopology();
00256 m_fwGeometry->idToName[current].topology[0] = topo.nstrips();
00257 m_fwGeometry->idToName[current].topology[1] = topo.stripLength();
00258 m_fwGeometry->idToName[current].topology[2] = topo.pitch();
00259 }
00260 }
00261 }
00262
00263
00264 void
00265 FWRecoGeometryESProducer::addPixelBarrelGeometry( void )
00266 {
00267 for( TrackerGeometry::DetContainer::const_iterator it = m_trackerGeom->detsPXB().begin(),
00268 end = m_trackerGeom->detsPXB().end();
00269 it != end; ++it)
00270 {
00271 const GeomDet *det = *it;
00272
00273 if( det )
00274 {
00275 DetId detid = det->geographicalId();
00276 unsigned int rawid = detid.rawId();
00277 unsigned int current = insert_id( rawid );
00278 fillShapeAndPlacement( current, det );
00279
00280 ADD_PIXEL_TOPOLOGY( current, m_trackerGeom->idToDetUnit( detid ));
00281 }
00282 }
00283 }
00284
00285 void
00286 FWRecoGeometryESProducer::addPixelForwardGeometry( void )
00287 {
00288 for( TrackerGeometry::DetContainer::const_iterator it = m_trackerGeom->detsPXF().begin(),
00289 end = m_trackerGeom->detsPXF().end();
00290 it != end; ++it )
00291 {
00292 const GeomDet *det = *it;
00293
00294 if( det )
00295 {
00296 DetId detid = det->geographicalId();
00297 unsigned int rawid = detid.rawId();
00298 unsigned int current = insert_id( rawid );
00299 fillShapeAndPlacement( current, det );
00300
00301 ADD_PIXEL_TOPOLOGY( current, m_trackerGeom->idToDetUnit( detid ));
00302 }
00303 }
00304 }
00305
00306 void
00307 FWRecoGeometryESProducer::addTIBGeometry( void )
00308 {
00309 for( TrackerGeometry::DetContainer::const_iterator it = m_trackerGeom->detsTIB().begin(),
00310 end = m_trackerGeom->detsTIB().end();
00311 it != end; ++it )
00312 {
00313 const GeomDet *det = *it;
00314
00315 if( det )
00316 {
00317 DetId detid = det->geographicalId();
00318 unsigned int rawid = detid.rawId();
00319 unsigned int current = insert_id( rawid );
00320 fillShapeAndPlacement( current, det );
00321
00322 ADD_SISTRIP_TOPOLOGY( current, m_trackerGeom->idToDet( detid ));
00323 }
00324 }
00325 }
00326
00327 void
00328 FWRecoGeometryESProducer::addTOBGeometry( void )
00329 {
00330 for( TrackerGeometry::DetContainer::const_iterator it = m_trackerGeom->detsTOB().begin(),
00331 end = m_trackerGeom->detsTOB().end();
00332 it != end; ++it )
00333 {
00334 const GeomDet *det = *it;
00335
00336 if( det )
00337 {
00338 DetId detid = det->geographicalId();
00339 unsigned int rawid = detid.rawId();
00340 unsigned int current = insert_id( rawid );
00341 fillShapeAndPlacement( current, det );
00342
00343 ADD_SISTRIP_TOPOLOGY( current, m_trackerGeom->idToDet( detid ));
00344 }
00345 }
00346 }
00347
00348 void
00349 FWRecoGeometryESProducer::addTIDGeometry( void )
00350 {
00351 for( TrackerGeometry::DetContainer::const_iterator it = m_trackerGeom->detsTID().begin(),
00352 end = m_trackerGeom->detsTID().end();
00353 it != end; ++it)
00354 {
00355 const GeomDet *det = *it;
00356
00357 if( det )
00358 {
00359 DetId detid = det->geographicalId();
00360 unsigned int rawid = detid.rawId();
00361 unsigned int current = insert_id( rawid );
00362 fillShapeAndPlacement( current, det );
00363
00364 ADD_SISTRIP_TOPOLOGY( current, m_trackerGeom->idToDet( detid ));
00365 }
00366 }
00367 }
00368
00369 void
00370 FWRecoGeometryESProducer::addTECGeometry( void )
00371 {
00372 for( TrackerGeometry::DetContainer::const_iterator it = m_trackerGeom->detsTEC().begin(),
00373 end = m_trackerGeom->detsTEC().end();
00374 it != end; ++it )
00375 {
00376 const GeomDet *det = *it;
00377
00378 if( det )
00379 {
00380 DetId detid = det->geographicalId();
00381 unsigned int rawid = detid.rawId();
00382 unsigned int current = insert_id( rawid );
00383 fillShapeAndPlacement( current, det );
00384
00385 ADD_SISTRIP_TOPOLOGY( current, m_trackerGeom->idToDet( detid ));
00386 }
00387 }
00388 }
00389
00390 void
00391 FWRecoGeometryESProducer::addCaloGeometry( void )
00392 {
00393 std::vector<DetId> vid = m_caloGeom->getValidDetIds();
00394 for( std::vector<DetId>::const_iterator it = vid.begin(),
00395 end = vid.end();
00396 it != end; ++it )
00397 {
00398 const CaloCellGeometry::CornersVec& cor( m_caloGeom->getGeometry( *it )->getCorners());
00399 unsigned int id = insert_id( it->rawId());
00400 fillPoints( id, cor.begin(), cor.end());
00401 }
00402 }
00403
00404 unsigned int
00405 FWRecoGeometryESProducer::insert_id( unsigned int rawid )
00406 {
00407 ++m_current;
00408 m_fwGeometry->idToName.push_back(FWRecoGeom::Info());
00409 m_fwGeometry->idToName.back().id = rawid;
00410
00411 return m_current;
00412 }
00413
00414 void
00415 FWRecoGeometryESProducer::fillPoints( unsigned int id, std::vector<GlobalPoint>::const_iterator begin, std::vector<GlobalPoint>::const_iterator end )
00416 {
00417 unsigned int index( 0 );
00418 for( std::vector<GlobalPoint>::const_iterator i = begin; i != end; ++i )
00419 {
00420 assert( index < 23 );
00421 m_fwGeometry->idToName[id].points[index] = i->x();
00422 m_fwGeometry->idToName[id].points[++index] = i->y();
00423 m_fwGeometry->idToName[id].points[++index] = i->z();
00424 ++index;
00425 }
00426 }
00427
00428
00430 void
00431 FWRecoGeometryESProducer::fillShapeAndPlacement( unsigned int id, const GeomDet *det )
00432 {
00433
00434 const Bounds *b = &((det->surface ()).bounds ());
00435 if( const TrapezoidalPlaneBounds *b2 = dynamic_cast<const TrapezoidalPlaneBounds *> (b))
00436 {
00437 std::array< const float, 4 > const & par = b2->parameters ();
00438
00439
00440 m_fwGeometry->idToName[id].shape[0] = 1;
00441 m_fwGeometry->idToName[id].shape[1] = par [0];
00442 m_fwGeometry->idToName[id].shape[2] = par [1];
00443 m_fwGeometry->idToName[id].shape[3] = par [2];
00444 m_fwGeometry->idToName[id].shape[4] = par [3];
00445 }
00446 if( const RectangularPlaneBounds *b2 = dynamic_cast<const RectangularPlaneBounds *> (b))
00447 {
00448
00449 m_fwGeometry->idToName[id].shape[0] = 2;
00450 m_fwGeometry->idToName[id].shape[1] = b2->width() * 0.5;
00451 m_fwGeometry->idToName[id].shape[2] = b2->length() * 0.5;
00452 m_fwGeometry->idToName[id].shape[3] = b2->thickness() * 0.5;
00453 }
00454
00455
00456 GlobalPoint pos = det->surface().position();
00457 m_fwGeometry->idToName[id].translation[0] = pos.x();
00458 m_fwGeometry->idToName[id].translation[1] = pos.y();
00459 m_fwGeometry->idToName[id].translation[2] = pos.z();
00460
00461
00462
00463 TkRotation<float> detRot = det->surface().rotation();
00464 m_fwGeometry->idToName[id].matrix[0] = detRot.xx();
00465 m_fwGeometry->idToName[id].matrix[1] = detRot.yx();
00466 m_fwGeometry->idToName[id].matrix[2] = detRot.zx();
00467 m_fwGeometry->idToName[id].matrix[3] = detRot.xy();
00468 m_fwGeometry->idToName[id].matrix[4] = detRot.yy();
00469 m_fwGeometry->idToName[id].matrix[5] = detRot.zy();
00470 m_fwGeometry->idToName[id].matrix[6] = detRot.xz();
00471 m_fwGeometry->idToName[id].matrix[7] = detRot.yz();
00472 m_fwGeometry->idToName[id].matrix[8] = detRot.zz();
00473 }