CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/Geometry/GEMGeometryBuilder/src/GEMGeometryBuilderFromDDD.cc

Go to the documentation of this file.
00001 
00006 #include "Geometry/GEMGeometryBuilder/src/GEMGeometryBuilderFromDDD.h"
00007 #include "Geometry/GEMGeometry/interface/GEMGeometry.h"
00008 #include "Geometry/GEMGeometry/interface/GEMEtaPartitionSpecs.h"
00009 
00010 #include <DetectorDescription/Core/interface/DDFilter.h>
00011 #include <DetectorDescription/Core/interface/DDFilteredView.h>
00012 #include <DetectorDescription/Core/interface/DDSolid.h>
00013 
00014 #include "Geometry/MuonNumbering/interface/MuonDDDNumbering.h"
00015 #include "Geometry/MuonNumbering/interface/MuonBaseNumber.h"
00016 #include "Geometry/MuonNumbering/interface/GEMNumberingScheme.h"
00017 
00018 #include "DataFormats/GeometrySurface/interface/RectangularPlaneBounds.h"
00019 #include "DataFormats/GeometrySurface/interface/TrapezoidalPlaneBounds.h"
00020 
00021 #include "DataFormats/GeometryVector/interface/Basic3DVector.h"
00022 
00023 #include "CLHEP/Units/GlobalSystemOfUnits.h"
00024 
00025 #include <iostream>
00026 #include <algorithm>
00027 
00028 GEMGeometryBuilderFromDDD::GEMGeometryBuilderFromDDD(bool comp11) : theComp11Flag(comp11)
00029 { }
00030 
00031 GEMGeometryBuilderFromDDD::~GEMGeometryBuilderFromDDD() 
00032 { }
00033 
00034 GEMGeometry* GEMGeometryBuilderFromDDD::build(const DDCompactView* cview, const MuonDDDConstants& muonConstants)
00035 {
00036   std::string attribute = "ReadOutName"; // could come from .orcarc
00037   std::string value     = "MuonGEMHits";    // could come from .orcarc
00038   DDValue val(attribute, value, 0.0);
00039 
00040   // Asking only for the MuonGEM's
00041   DDSpecificsFilter filter;
00042   filter.setCriteria(val, // name & value of a variable 
00043                      DDSpecificsFilter::matches,
00044                      DDSpecificsFilter::AND, 
00045                      true, // compare strings otherwise doubles
00046                      true // use merged-specifics or simple-specifics
00047                      );
00048   DDFilteredView fview(*cview);
00049   fview.addFilter(filter);
00050 
00051   return this->buildGeometry(fview, muonConstants);
00052 }
00053 
00054 GEMGeometry* GEMGeometryBuilderFromDDD::buildGeometry(DDFilteredView& fview, const MuonDDDConstants& muonConstants)
00055 {
00056   LogDebug("GEMGeometryBuilderFromDDD") <<"Building the geometry service";
00057   GEMGeometry* geometry = new GEMGeometry();
00058 
00059   LogDebug("GEMGeometryBuilderFromDDD") << "About to run through the GEM structure\n" 
00060                                         <<" First logical part "
00061                                         <<fview.logicalPart().name().name();
00062   bool doSubDets = fview.firstChild();
00063 
00064   LogDebug("GEMGeometryBuilderFromDDD") << "doSubDets = " << doSubDets;
00065   while (doSubDets){
00066     LogDebug("GEMGeometryBuilderFromDDD") <<"start the loop"; 
00067 
00068     // Get the Base Muon Number
00069     MuonDDDNumbering mdddnum(muonConstants);
00070     LogDebug("GEMGeometryBuilderFromDDD") <<"Getting the Muon base Number";
00071     MuonBaseNumber   mbn=mdddnum.geoHistoryToBaseNumber(fview.geoHistory());
00072     LogDebug("GEMGeometryBuilderFromDDD") <<"Start the GEM Numbering Schema";
00073     // Get the The GEM det Id 
00074     GEMNumberingScheme gemnum(muonConstants);
00075     int detid = 0;
00076 
00077     LogDebug("GEMGeometryBuilderFromDDD") <<"Getting the Unit Number";
00078     detid = gemnum.baseNumberToUnitNumber(mbn);
00079     LogDebug("GEMGeometryBuilderFromDDD") <<"Getting the GEM det Id "<<detid;
00080 
00081     GEMDetId gemmid(detid);
00082     //    GEMDetId chid(gemmid.region(),gemmid.ring(),gemmid.station(),gemmid.sector(),gemmid.layer(),gemmid.subsector(),0);
00083 
00084     LogDebug("GEMGeometryBuilderFromDDD") <<"The GEMDetid is "<<gemmid;
00085 
00086     DDValue numbOfStrips("nStrips");
00087 
00088     std::vector<const DDsvalues_type* > specs(fview.specifics());
00089     std::vector<const DDsvalues_type* >::iterator is=specs.begin();
00090     int nStrips=0;
00091     for (;is!=specs.end(); is++){
00092       if (DDfetch( *is, numbOfStrips)){
00093         nStrips=int(numbOfStrips.doubles()[0]); 
00094       }
00095     }
00096 
00097     LogDebug("GEMGeometryBuilderFromDDD") << ((nStrips == 0 ) ? ("No strip found!!") : (""));
00098     
00099     std::vector<double> dpar=fview.logicalPart().solid().parameters();
00100     std::string name=fview.logicalPart().name().name();
00101     DDTranslation tran    = fview.translation();
00102     //removed .Inverse after comparing to DT...
00103     DDRotationMatrix rota = fview.rotation();//.Inverse();
00104     Surface::PositionType pos(tran.x()/cm,tran.y()/cm, tran.z()/cm);
00105     // CLHEP way
00106 //     Surface::RotationType rot(rota.xx(),rota.xy(),rota.xz(),
00107 //                            rota.yx(),rota.yy(),rota.yz(),
00108 //                            rota.zx(),rota.zy(),rota.zz());
00109 
00110 //ROOT::Math way
00111     DD3Vector x, y, z;
00112     rota.GetComponents(x,y,z);
00113     // doesn't this just re-inverse???
00114     Surface::RotationType rot (float(x.X()),float(x.Y()),float(x.Z()),
00115                                float(y.X()),float(y.Y()),float(y.Z()),
00116                                float(z.X()),float(z.Y()),float(z.Z())); 
00117     
00118     std::vector<float> pars;
00119     GEMEtaPartitionSpecs* etapartitionspecs= 0;
00120     Bounds* bounds = 0;
00121 
00122     float be = dpar[4]/cm;
00123     float te = dpar[8]/cm;
00124     float ap = dpar[0]/cm;
00125     float ti = 0.4/cm;
00126     //  TrapezoidalPlaneBounds* 
00127     bounds = 
00128       new TrapezoidalPlaneBounds(be,te,ap,ti);
00129     pars.push_back(dpar[4]/cm); //b/2;
00130     pars.push_back(dpar[8]/cm); //B/2;
00131     pars.push_back(dpar[0]/cm); //h/2;
00132     pars.push_back(numbOfStrips.doubles()[0]); //h/2;      
00133     LogDebug("GEMGeometryBuilderFromDDD") <<"GEM "<<name
00134                                           <<" par "<<dpar[4]/cm
00135                                           <<" "<<dpar[8]/cm<<" "<<dpar[3]/cm<<" "
00136                                           <<dpar[0];
00137     
00138     etapartitionspecs = new GEMEtaPartitionSpecs(GeomDetEnumerators::GEM,name,pars);
00139 
00140       //Change of axes for the forward
00141     Basic3DVector<float> newX(1.,0.,0.);
00142     Basic3DVector<float> newY(0.,0.,1.);
00143     //      if (tran.z() > 0. )
00144     newY *= -1;
00145     Basic3DVector<float> newZ(0.,1.,0.);
00146     rot.rotateAxes (newX, newY,newZ);
00147     
00148     LogDebug("GEMGeometryBuilderFromDDD") <<"   Number of strips "<<nStrips;    
00149     BoundPlane* bp = new BoundPlane(pos,rot,bounds);
00150     ReferenceCountingPointer<BoundPlane> surf(bp);
00151     GEMEtaPartition* gep=new GEMEtaPartition(gemmid,surf,etapartitionspecs);
00152     geometry->add(gep);
00153 
00154     std::list<GEMEtaPartition *> gepls;
00155     /*
00156     if (chids.find(chid)!=chids.end()){
00157       gepls = chids[chid];
00158     }
00159     */
00160     gepls.push_back(gep);
00161     //chids[chid]=gepls;
00162     
00163     doSubDets = fview.nextSibling(); // go to next layer
00164   }
00165   /*
00166   // Create the GEMChambers and store them on the Geometry 
00167   for( std::map<GEMDetId, std::list<GEMEtaPartition *> >::iterator ich=chids.begin();
00168        ich != chids.end(); ich++){
00169     GEMDetId chid = ich->first;
00170     std::list<GEMEtaPartition * > gepls = ich->second;5D
00171     
00172     // compute the overall boundplane. At the moment we use just the last
00173     // surface
00174     BoundPlane* bp=0;
00175     for(std::list<GEMEtaPartition *>::iterator gepl=gepls.begin();
00176         gepl!=gepls.end(); gepl++){
00177       const BoundPlane& bps = (*gepl)->surface();
00178       bp = const_cast<BoundPlane *>(&bps);
00179     }
00180     
00181     ReferenceCountingPointer<BoundPlane> surf(bp);
00182     // Create the chamber 
00183     GEMChamber* ch = new GEMChamber (chid, surf); 
00184     // Add the etapartitions to the chamber
00185     for(std::list<GEMEtaPartition *>::iterator gepl=gepls.begin();
00186         gepl!=gepls.end(); rl++){
00187       ch->add(*gepl);
00188     }
00189     // Add the chamber to the geometry
00190     geometry->add(ch);
00191   } 
00192   */
00193   return geometry;
00194 }