CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2/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   {
00067     LogDebug("GEMGeometryBuilderFromDDD") <<"start the loop"; 
00068 
00069     // Get the Base Muon Number
00070     MuonDDDNumbering mdddnum(muonConstants);
00071     LogDebug("GEMGeometryBuilderFromDDD") <<"Getting the Muon base Number";
00072     MuonBaseNumber   mbn = mdddnum.geoHistoryToBaseNumber(fview.geoHistory());
00073     LogDebug("GEMGeometryBuilderFromDDD") <<"Start the GEM Numbering Schema";
00074     // Get the The GEM det Id 
00075     GEMNumberingScheme gemnum(muonConstants);
00076     int detid = 0;
00077 
00078     LogDebug("GEMGeometryBuilderFromDDD") <<"Getting the Unit Number";
00079     detid = gemnum.baseNumberToUnitNumber(mbn);
00080     LogDebug("GEMGeometryBuilderFromDDD") <<"Getting the GEM det Id "<<detid;
00081 
00082     GEMDetId gemmid(detid);
00083     //    GEMDetId chid(gemmid.region(),gemmid.ring(),gemmid.station(),gemmid.sector(),gemmid.layer(),gemmid.subsector(),0);
00084 
00085     LogDebug("GEMGeometryBuilderFromDDD") <<"The GEMDetid is "<<gemmid;
00086 
00087     DDValue numbOfStrips("nStrips");
00088     DDValue numbOfPads("nPads");
00089 
00090     std::vector<const DDsvalues_type* > specs(fview.specifics());
00091     std::vector<const DDsvalues_type* >::iterator is = specs.begin();
00092     double nStrips = 0., nPads = 0.;
00093     for (;is != specs.end(); is++)
00094     {
00095       if (DDfetch( *is, numbOfStrips)) nStrips = numbOfStrips.doubles()[0];
00096       if (DDfetch( *is, numbOfPads))   nPads = numbOfPads.doubles()[0];
00097     }
00098     LogDebug("GEMGeometryBuilderFromDDD") << ((nStrips == 0. ) ? ("No nStrips found!!") : (""));
00099     LogDebug("GEMGeometryBuilderFromDDD") << ((nPads == 0. ) ? ("No nPads found!!") : (""));
00100     //std::cout <<"# strips, pads: "<< nStrips<<", "<<nPads<<std::endl;
00101 
00102 
00103     std::vector<double> dpar=fview.logicalPart().solid().parameters();
00104     std::string name = fview.logicalPart().name().name();
00105     DDTranslation tran = fview.translation();
00106     //removed .Inverse after comparing to DT...
00107     DDRotationMatrix rota = fview.rotation();//.Inverse();
00108     Surface::PositionType pos(tran.x()/cm, tran.y()/cm, tran.z()/cm);
00109     // CLHEP way
00110 //     Surface::RotationType rot(rota.xx(),rota.xy(),rota.xz(),
00111 //                            rota.yx(),rota.yy(),rota.yz(),
00112 //                            rota.zx(),rota.zy(),rota.zz());
00113 
00114 //ROOT::Math way
00115     DD3Vector x, y, z;
00116     rota.GetComponents(x,y,z);
00117     // doesn't this just re-inverse???
00118     Surface::RotationType rot (float(x.X()), float(x.Y()), float(x.Z()),
00119                                float(y.X()), float(y.Y()), float(y.Z()),
00120                                float(z.X()), float(z.Y()), float(z.Z())); 
00121     
00122     Bounds* bounds = 0;
00123     float be = dpar[4]/cm;
00124     float te = dpar[8]/cm;
00125     float ap = dpar[0]/cm;
00126     float ti = 0.4/cm;
00127     //  TrapezoidalPlaneBounds* 
00128     bounds = new TrapezoidalPlaneBounds(be, te, ap, ti);
00129 
00130     std::vector<float> pars;
00131     pars.push_back(dpar[4]/cm); //b/2;
00132     pars.push_back(dpar[8]/cm); //B/2;
00133     pars.push_back(dpar[0]/cm); //h/2;
00134     pars.push_back(nStrips);
00135     pars.push_back(nPads);
00136 
00137     LogDebug("GEMGeometryBuilderFromDDD") <<"GEM "<<name
00138                                           <<" par "<<dpar[4]/cm
00139                                           <<" "<<dpar[8]/cm<<" "<<dpar[3]/cm<<" "
00140                                           <<dpar[0];
00141     
00142     GEMEtaPartitionSpecs* e_p_specs = new GEMEtaPartitionSpecs(GeomDetEnumerators::GEM, name, pars);
00143 
00144       //Change of axes for the forward
00145     Basic3DVector<float> newX(1.,0.,0.);
00146     Basic3DVector<float> newY(0.,0.,1.);
00147     //      if (tran.z() > 0. )
00148     newY *= -1;
00149     Basic3DVector<float> newZ(0.,1.,0.);
00150     rot.rotateAxes (newX, newY, newZ);
00151     
00152     LogDebug("GEMGeometryBuilderFromDDD") <<"   Number of strips "<<nStrips<<"  Number of pads "<<nPads;    
00153     BoundPlane* bp = new BoundPlane(pos, rot, bounds);
00154     ReferenceCountingPointer<BoundPlane> surf(bp);
00155     GEMEtaPartition* gep = new GEMEtaPartition(gemmid, surf, e_p_specs);
00156     geometry->add(gep);
00157 
00158     std::list<GEMEtaPartition *> gepls;
00159     /*
00160     if (chids.find(chid)!=chids.end()){
00161       gepls = chids[chid];
00162     }
00163     */
00164     gepls.push_back(gep);
00165     //chids[chid]=gepls;
00166     
00167     doSubDets = fview.nextSibling(); // go to next layer
00168   }
00169   /*
00170   // Create the GEMChambers and store them on the Geometry 
00171   for( std::map<GEMDetId, std::list<GEMEtaPartition *> >::iterator ich=chids.begin();
00172        ich != chids.end(); ich++){
00173     GEMDetId chid = ich->first;
00174     std::list<GEMEtaPartition * > gepls = ich->second;5D
00175     
00176     // compute the overall boundplane. At the moment we use just the last
00177     // surface
00178     BoundPlane* bp=0;
00179     for(std::list<GEMEtaPartition *>::iterator gepl=gepls.begin();
00180         gepl!=gepls.end(); gepl++){
00181       const BoundPlane& bps = (*gepl)->surface();
00182       bp = const_cast<BoundPlane *>(&bps);
00183     }
00184     
00185     ReferenceCountingPointer<BoundPlane> surf(bp);
00186     // Create the chamber 
00187     GEMChamber* ch = new GEMChamber (chid, surf); 
00188     // Add the etapartitions to the chamber
00189     for(std::list<GEMEtaPartition *>::iterator gepl=gepls.begin();
00190         gepl!=gepls.end(); rl++){
00191       ch->add(*gepl);
00192     }
00193     // Add the chamber to the geometry
00194     geometry->add(ch);
00195   } 
00196   */
00197   return geometry;
00198 }