CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_9/src/Geometry/CSCGeometryBuilder/src/CSCGeometryParsFromDD.cc

Go to the documentation of this file.
00001 #include "CSCGeometryParsFromDD.h"
00002 
00003 #include <DetectorDescription/Core/interface/DDFilter.h>
00004 #include <DetectorDescription/Core/interface/DDFilteredView.h>
00005 #include <DetectorDescription/Core/interface/DDSolid.h>
00006 
00007 #include <Geometry/CSCGeometry/interface/CSCGeometry.h>
00008 #include <Geometry/CSCGeometry/interface/CSCChamberSpecs.h>
00009 #include <Geometry/CSCGeometry/interface/CSCChamber.h>
00010 #include <Geometry/CSCGeometry/interface/CSCLayer.h>
00011 #include <Geometry/CSCGeometry/interface/CSCLayerGeometry.h>
00012 #include <Geometry/CommonDetUnit/interface/TrackingGeometry.h>
00013 #include <Geometry/MuonNumbering/interface/CSCNumberingScheme.h>
00014 #include <Geometry/MuonNumbering/interface/MuonBaseNumber.h>
00015 #include <Geometry/MuonNumbering/interface/MuonDDDNumbering.h>
00016 #include <Geometry/MuonNumbering/interface/MuonDDDConstants.h>
00017 #include <DataFormats/GeometrySurface/interface/BoundPlane.h>
00018 #include <DataFormats/GeometrySurface/interface/TrapezoidalPlaneBounds.h>
00019 #include <DataFormats/GeometryVector/interface/Basic3DVector.h>
00020 
00021 //#include <CondFormats/RecoGeometryObjects/interface/CSCWireGroupPackage.h>
00022 #include <Geometry/CSCGeometry/src/CSCWireGroupPackage.h>
00023 #include <CondFormats/GeometryObjects/interface/CSCRecoDigiParameters.h>
00024 #include <CondFormats/GeometryObjects/interface/RecoIdealGeometry.h>
00025 
00026 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00027 
00028 #include <FWCore/MessageLogger/interface/MessageLogger.h>
00029 #include <FWCore/Utilities/interface/Exception.h>
00030 
00031 #include <iostream>
00032 #include <sstream>
00033 #include <iomanip>
00034 #include <algorithm>
00035 //#include <iterator>
00036 
00037 CSCGeometryParsFromDD::CSCGeometryParsFromDD() : myName("CSCGeometryParsFromDD") { }
00038 
00039 CSCGeometryParsFromDD::~CSCGeometryParsFromDD() { }
00040 
00041 bool CSCGeometryParsFromDD::build( const DDCompactView* cview
00042                                    , const MuonDDDConstants& muonConstants
00043                                    , RecoIdealGeometry& rig
00044                                    , CSCRecoDigiParameters& rdp
00045                                    ) {
00046   std::string attribute = "MuStructure";      // could come from outside
00047   std::string value     = "MuonEndcapCSC";    // could come from outside
00048   DDValue muval(attribute, value, 0.0);
00049 
00050   // Asking for a specific section of the MuStructure
00051 
00052   DDSpecificsFilter filter;
00053   filter.setCriteria(muval, // name & value of a variable 
00054                      DDSpecificsFilter::equals,
00055                      DDSpecificsFilter::AND, 
00056                      true, // compare strings otherwise doubles
00057                      true // use merged-specifics or simple-specifics
00058                      );
00059 
00060   DDFilteredView fv( *cview );
00061   fv.addFilter(filter);
00062 
00063   bool doSubDets = fv.firstChild();
00064 
00065   if (!doSubDets) {
00066     edm::LogError("CSCGeometryParsFromDD") << "Can not proceed, no CSC parts found with the filter.  The current node is: " << fv.logicalPart().toString();
00067     return false;
00068   }
00069   int noOfAnonParams = 0;
00070   std::vector<const DDsvalues_type *> spec = fv.specifics();
00071   std::vector<const DDsvalues_type *>::const_iterator spit = spec.begin();
00072   std::vector<double> uparvals;
00073   std::vector<double> fpar;
00074   std::vector<double> dpar;
00075   std::vector<double> gtran( 3 );
00076   std::vector<double> grmat( 9 );
00077   std::vector<double> trm ( 9 );
00078   while (doSubDets) {
00079     spec = fv.specifics();
00080     spit = spec.begin();
00081 
00082     // get numbering information early for possible speed up of code.
00083 
00084     LogTrace(myName) << myName  << ": create numbering scheme...";
00085 
00086     MuonDDDNumbering mdn(muonConstants);
00087     MuonBaseNumber mbn = mdn.geoHistoryToBaseNumber(fv.geoHistory());
00088     CSCNumberingScheme mens(muonConstants);
00089 
00090     LogTrace(myName) << myName  << ": find detid...";
00091 
00092     int id = mens.baseNumberToUnitNumber( mbn ); //@@ FIXME perhaps should return CSCDetId itself?
00093 
00094     LogTrace(myName) << myName  << ": raw id for this detector is " << id << 
00095       ", octal " << std::oct << id << ", hex " << std::hex << id << std::dec;
00096 
00097     CSCDetId detid = CSCDetId( id );
00098     int jendcap  = detid.endcap();
00099     int jstation = detid.station();
00100     int jring    = detid.ring();
00101     int jchamber = detid.chamber();
00102     int jlayer   = detid.layer();
00103 
00104     // Package up the wire group info as it's decoded
00105     CSCWireGroupPackage wg; 
00106     uparvals.clear();
00107     //std::cout << "size of spec=" << spec.size() << std::endl;
00108 
00109     // if the specs are made no need to get all this crap!
00110     int chamberType = CSCChamberSpecs::whatChamberType( jstation, jring );
00111     //    std::cout << "Chamber Type: " << chamberType << std::endl;
00112     size_t ct = 0;
00113     bool chSpecsAlreadyExist = false;
00114     for ( ; ct < rdp.pChamberType.size() ; ++ct ) {
00115       if ( chamberType == rdp.pChamberType[ct] ) {
00116         break;
00117       }
00118     }
00119     if ( ct < rdp.pChamberType.size() && rdp.pChamberType[ct] == chamberType ) {
00120       // it was found, therefore no need to load all the intermediate crap from DD.
00121       //      std::cout << "already found a " << chamberType << " at index " << ct << std::endl;
00122       chSpecsAlreadyExist = true;
00123     } else {
00124       for (;  spit != spec.end(); spit++) {
00125         DDsvalues_type::const_iterator it = (**spit).begin();
00126         for (;  it != (**spit).end(); it++) {
00127           //std::cout << "it->second.name()=" << it->second.name() << std::endl;  
00128           if (it->second.name() == "upar") {
00129             uparvals.push_back(it->second.doubles().size());
00130             for ( size_t i = 0; i < it->second.doubles().size(); ++i) {
00131               uparvals.push_back(it->second.doubles()[i]);
00132             }
00133             //std::cout << "found upars " << std::endl;
00134           } else if (it->second.name() == "NoOfAnonParams") {
00135             noOfAnonParams = static_cast<int>( it->second.doubles()[0] );
00136           } else if (it->second.name() == "NumWiresPerGrp") {
00137             //numWiresInGroup = it->second.doubles();
00138             for ( size_t i = 0 ; i < it->second.doubles().size(); i++) {
00139               wg.wiresInEachGroup.push_back( int( it->second.doubles()[i] ) );
00140             }
00141             //std::cout << "found upars " << std::endl;
00142           } else if ( it->second.name() == "NumGroups" ) {
00143             //numGroups = it->second.doubles();
00144             for ( size_t i = 0 ; i < it->second.doubles().size(); i++) {
00145               wg.consecutiveGroups.push_back( int( it->second.doubles()[i] ) );
00146             }
00147           } else if ( it->second.name() == "WireSpacing" ) {
00148             wg.wireSpacing = it->second.doubles()[0];
00149           } else if ( it->second.name() == "AlignmentPinToFirstWire" ) {
00150             wg.alignmentPinToFirstWire = it->second.doubles()[0]; 
00151           } else if ( it->second.name() == "TotNumWireGroups" ) {
00152             wg.numberOfGroups = int(it->second.doubles()[0]);
00153           } else if ( it->second.name() == "LengthOfFirstWire" ) {
00154             wg.narrowWidthOfWirePlane = it->second.doubles()[0];
00155           } else if ( it->second.name() == "LengthOfLastWire" ) {
00156             wg.wideWidthOfWirePlane = it->second.doubles()[0];
00157           } else if ( it->second.name() == "RadialExtentOfWirePlane" ) {
00158             wg.lengthOfWirePlane = it->second.doubles()[0];
00159           }
00160         }
00161       }
00162       
00170       uparvals.push_back( wg.wireSpacing );
00171       uparvals.push_back( wg.alignmentPinToFirstWire );
00172       uparvals.push_back( wg.numberOfGroups );
00173       uparvals.push_back( wg.narrowWidthOfWirePlane );
00174       uparvals.push_back( wg.wideWidthOfWirePlane );
00175       uparvals.push_back( wg.lengthOfWirePlane );
00176       uparvals.push_back( wg.wiresInEachGroup.size() ); 
00177       for (CSCWireGroupPackage::Container::const_iterator it = wg.wiresInEachGroup.begin();
00178            it != wg.wiresInEachGroup.end(); ++it) {
00179         uparvals.push_back(*it);
00180       }
00181       for (CSCWireGroupPackage::Container::const_iterator it = wg.consecutiveGroups.begin();
00182            it != wg.consecutiveGroups.end(); ++it) {
00183         uparvals.push_back(*it);
00184       }
00186     }
00187     fpar.clear();
00188     //    dpar = fv.logicalPart().solid().parameters();
00189     if ( fv.logicalPart().solid().shape() == ddsubtraction ) {
00190       const DDSubtraction& first = fv.logicalPart().solid();
00191       const DDSubtraction& second = first.solidA();
00192       const DDSolid& third = second.solidA();
00193       dpar = third.parameters();
00194     } else {
00195       dpar = fv.logicalPart().solid().parameters();
00196     }
00197 
00198     LogTrace(myName) << myName  << ": noOfAnonParams=" << noOfAnonParams;
00199     LogTrace(myName) << myName  << ": fill fpar...";
00200     LogTrace(myName) << myName  << ": dpars are... " << 
00201       dpar[4]/cm << ", " << dpar[8]/cm << ", " << 
00202       dpar[3]/cm << ", " << dpar[0]/cm;
00203 
00204     fpar.push_back( ( dpar[4]/cm) );
00205     fpar.push_back( ( dpar[8]/cm ) ); 
00206     fpar.push_back( ( dpar[3]/cm ) ); 
00207     fpar.push_back( ( dpar[0]/cm ) ); 
00208 
00209     LogTrace(myName) << myName  << ": fill gtran...";
00210 
00211     gtran[0] = (float) 1.0 * (fv.translation().X() / cm);
00212     gtran[1] = (float) 1.0 * (fv.translation().Y() / cm);
00213     gtran[2] = (float) 1.0 * (fv.translation().Z() / cm);
00214 
00215     LogTrace(myName) << myName << ": gtran[0]=" << gtran[0] << ", gtran[1]=" <<
00216       gtran[1] << ", gtran[2]=" << gtran[2];
00217 
00218     LogTrace(myName) << myName  << ": fill grmat...";
00219 
00220     fv.rotation().GetComponents(trm.begin(), trm.end());
00221     size_t rotindex = 0;
00222     for (size_t i = 0; i < 9; ++i) {
00223       grmat[i] = (float) 1.0 * trm[rotindex];
00224       rotindex = rotindex + 3;
00225       if ( (i+1) % 3 == 0 ) {
00226         rotindex = (i+1) / 3;
00227       }
00228     }
00229     LogTrace(myName) << myName  << ": looking for wire group info for layer " <<
00230       "E" << CSCDetId::endcap(id) << 
00231       " S" << CSCDetId::station(id) << 
00232       " R" << CSCDetId::ring(id) <<
00233       " C" << CSCDetId::chamber(id) <<
00234       " L" << CSCDetId::layer(id);
00235           
00236     if ( wg.numberOfGroups != 0 ) {
00237       LogTrace(myName) << myName  << ": fv.geoHistory:      = " << fv.geoHistory() ;
00238       LogTrace(myName) << myName  << ": TotNumWireGroups     = " << wg.numberOfGroups ;
00239       LogTrace(myName) << myName  << ": WireSpacing          = " << wg.wireSpacing ;
00240       LogTrace(myName) << myName  << ": AlignmentPinToFirstWire = " << wg.alignmentPinToFirstWire ;
00241       LogTrace(myName) << myName  << ": Narrow width of wire plane = " << wg.narrowWidthOfWirePlane ;
00242       LogTrace(myName) << myName  << ": Wide width of wire plane = " << wg.wideWidthOfWirePlane ;
00243       LogTrace(myName) << myName  << ": Length in y of wire plane = " << wg.lengthOfWirePlane ;
00244       LogTrace(myName) << myName  << ": wg.consecutiveGroups.size() = " << wg.consecutiveGroups.size() ;
00245       LogTrace(myName) << myName  << ": wg.wiresInEachGroup.size() = " << wg.wiresInEachGroup.size() ;
00246       LogTrace(myName) << myName  << ": \tNumGroups\tWiresInGroup" ;
00247       for (size_t i = 0; i < wg.consecutiveGroups.size(); i++) {
00248         LogTrace(myName) << myName  << " \t" << wg.consecutiveGroups[i] << "\t\t" << wg.wiresInEachGroup[i] ;
00249       }
00250     } else {
00251       LogTrace(myName) << myName  << ": DDD is MISSING SpecPars for wire groups" ;
00252     }
00253     LogTrace(myName) << myName << ": end of wire group info. " ;
00254 
00255     LogTrace(myName) << myName << ":_z_ E" << jendcap << " S" << jstation << " R" << jring <<
00256       " C" << jchamber << " L" << jlayer <<
00257       " gx=" << gtran[0] << ", gy=" << gtran[1] << ", gz=" << gtran[2] <<
00258       " thickness=" << fpar[2]*2.;
00259 
00260     if ( jlayer == 0 ) { // Can only build chambers if we're filtering them
00261 
00262       LogTrace(myName) << myName  << ":_z_ frame=" << uparvals[31]/10. <<
00263         " gap=" << uparvals[32]/10. << " panel=" << uparvals[33]/10. << " offset=" << uparvals[34]/10.;
00264 
00265     if ( jstation==1 && jring==1 ) {
00266       // set up params for ME1a and ME1b and call buildChamber *for each*
00267       // Both get the full ME11 dimensions
00268 
00269       // detid is for ME11 and that's what we're using for ME1b in the software
00270 
00271       rig.insert( id, gtran, grmat, fpar );
00272       if ( !chSpecsAlreadyExist ) {
00273         //      rdp.pCSCDetIds.push_back(CSCDetId(id));
00274         //      std::cout << " inserting chamber type " << chamberType << std::endl;
00275         rdp.pChamberType.push_back(chamberType);
00276         rdp.pUserParOffset.push_back(rdp.pfupars.size());
00277         rdp.pUserParSize.push_back(uparvals.size());
00278         std::copy ( uparvals.begin(), uparvals.end(), std::back_inserter(rdp.pfupars));
00279       }
00280 
00281       // No. of anonymous parameters per chamber type should be read from cscSpecs file...
00282       // Only required for ME11 splitting into ME1a and ME1b values,
00283       // If it isn't seen may as well try to get further but this value will depend
00284       // on structure of the file so may not even match! 
00285       const int kNoOfAnonParams = 35;
00286       if ( noOfAnonParams == 0 ) { noOfAnonParams = kNoOfAnonParams; } // in case it wasn't seen
00287       
00288       std::copy( uparvals.begin()+noOfAnonParams+1, uparvals.begin()+(2*noOfAnonParams)+2, uparvals.begin()+1 ); // copy ME1a params from back to the front
00289       
00290       CSCDetId detid1a = CSCDetId( jendcap, 1, 4, jchamber, 0 ); // reset to ME1A
00291       rig.insert( detid1a.rawId(), gtran, grmat, fpar );
00292       int chtypeA = CSCChamberSpecs::whatChamberType( 1, 4 );
00293       ct = 0;
00294       for ( ; ct < rdp.pChamberType.size() ; ++ct ) {
00295         if ( chtypeA == rdp.pChamberType[ct] ) {
00296           break;
00297         }
00298       }
00299       if ( ct < rdp.pChamberType.size() && rdp.pChamberType[ct] == chtypeA ) {
00300         // then its in already, don't put it
00301         //      std::cout << "found chamber type " << chtypeA << " so don't put it in! " << std::endl;
00302       } else {
00303         //      rdp.pCSCDetIds.push_back(detid1a);
00304         //      std::cout << " inserting chamber type " << chtypeA << std::endl;
00305         rdp.pChamberType.push_back(chtypeA);
00306         rdp.pUserParOffset.push_back(rdp.pfupars.size());
00307         rdp.pUserParSize.push_back(uparvals.size());
00308         std::copy ( uparvals.begin(), uparvals.end(), std::back_inserter(rdp.pfupars));
00309       }
00310       
00311     }
00312     else {
00313       rig.insert( id, gtran, grmat, fpar );
00314       if ( !chSpecsAlreadyExist ) {
00315         //   rdp.pCSCDetIds.push_back(CSCDetId(id));
00316         //      std::cout << " inserting chamber type " << chamberType << std::endl;
00317         rdp.pChamberType.push_back(chamberType);
00318         rdp.pUserParOffset.push_back(rdp.pfupars.size());
00319         rdp.pUserParSize.push_back(uparvals.size());
00320         std::copy ( uparvals.begin(), uparvals.end(), std::back_inserter(rdp.pfupars));
00321       }
00322     }
00323 
00324     } // filtering chambers.
00325 
00326     doSubDets = fv.next();
00327   }
00328   return true;
00329 }