CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_1/src/CalibTracker/SiPixelConnectivity/src/SiPixelFedCablingMapBuilder.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 
00003 #include "CalibTracker/SiPixelConnectivity/interface/SiPixelFedCablingMapBuilder.h"
00004 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00005 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00006 #include "Geometry/TrackerGeometryBuilder/interface/PixelGeomDetUnit.h"
00007 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00008 #include "FWCore/Framework/interface/ESHandle.h"
00009 
00010 #include <ostream>
00011 #include "DataFormats/SiPixelDetId/interface/PixelEndcapName.h"
00012 #include "DataFormats/SiPixelDetId/interface/PixelBarrelName.h"
00013 
00014 #include "CalibTracker/SiPixelConnectivity/interface/PixelToFEDAssociate.h"
00015 #include "CalibTracker/SiPixelConnectivity/interface/TRange.h"
00016 #include "CondFormats/SiPixelObjects/interface/PixelFEDCabling.h"
00017 #include "CalibTracker/SiPixelConnectivity/interface/PixelBarrelLinkMaker.h"
00018 #include "CalibTracker/SiPixelConnectivity/interface/PixelEndcapLinkMaker.h"
00019 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
00020 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
00021 
00022 #include "DataFormats/GeometryVector/interface/GlobalPoint.h"
00023 #include "DataFormats/GeometryVector/interface/LocalPoint.h"
00024 #include "CalibTracker/SiPixelConnectivity/interface/PixelToLNKAssociateFromAscii.h"
00025 
00026 #include <bitset>
00027 
00028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00029 
00030 using namespace std;
00031 using namespace sipixelobjects;
00032 
00033 
00034 SiPixelFedCablingMapBuilder::SiPixelFedCablingMapBuilder(const string & associatorName) : theAssociatorName(associatorName)
00035 { }
00036 
00037 
00038 SiPixelFedCablingTree * SiPixelFedCablingMapBuilder::produce( const edm::EventSetup& setup)
00039 {
00040   FEDNumbering fednum;
00041 //  TRange<int> fedIds(FEDNumbering::MINSiPixelFEDID, FEDNumbering::MAXSiPixelFEDID);
00042   TRange<int> fedIds(0,39);
00043   edm::LogInfo("SiPixelFedCablingMapBuilder")<<"pixel fedid range: "<<fedIds;
00044 
00045 
00046   edm::ESHandle<PixelToFEDAssociate> associator;
00047   setup.get<TrackerDigiGeometryRecord>().get(theAssociatorName,associator);
00048 //   PixelToFEDAssociate * associator = new PixelToLNKAssociateFromAscii("pixelToLNK.ascii");
00049 
00050   
00051   const PixelToFEDAssociate & name2fed = *associator; 
00052   
00053   string version = name2fed.version();
00054   SiPixelFedCablingTree * result = new SiPixelFedCablingTree(version);
00055 
00056 
00057   LogDebug("read tracker geometry...");
00058   edm::ESHandle<TrackerGeometry> pDD;
00059   setup.get<TrackerDigiGeometryRecord>().get( pDD );
00060   LogDebug("tracker geometry read")<<"There are: "<<  pDD->dets().size() <<" detectors";
00061 
00062   typedef TrackerGeometry::DetContainer::const_iterator ITG;
00063   int npxdets = 0;
00064 
00065   typedef  std::vector<pair<PixelModuleName* , uint32_t> > UNITS;
00066   UNITS units;
00067 
00068   for (ITG it = pDD->dets().begin(); it != pDD->dets().end(); it++){
00069     const PixelGeomDetUnit * pxUnit = dynamic_cast<const PixelGeomDetUnit*>(*it);
00070     if (pxUnit  ==0 ) continue;
00071     npxdets++;
00072     DetId geomid = pxUnit->geographicalId();
00073     PixelModuleName * name =  0;
00074     if (1 == geomid.subdetId()) {
00075       name = new PixelBarrelName(geomid);
00076     } else {
00077       name = new PixelEndcapName(geomid);
00078 //      cout << " NAME: "<<name->name()<<myprint(pxUnit)<<endl;
00079     } 
00080     units.push_back( std::make_pair( name, geomid.rawId() ) );
00081   }
00082 
00083 
00084   if (theAssociatorName=="PixelToFEDAssociateFromAscii") {
00085   cout <<" HERE PixelToFEDAssociateFromAscii"<<endl;
00086   vector<FedSpec> fedSpecs(fedIds.max()-fedIds.min()+1); 
00087   for (int id=fedIds.first; id<=fedIds.second; id++) {
00088     FedSpec fs={ id, vector<PixelModuleName* >(), vector<uint32_t>()};
00089     int idx = id - fedIds.min();
00090     fedSpecs[idx]= fs;
00091   }
00092   for (UNITS::iterator iu=units.begin(); iu != units.end(); iu++) {
00093     PixelModuleName* name = (*iu).first;
00094     uint32_t rawId = (*iu).second;
00095     int fedId = name2fed( *name);
00096     if ( fedIds.inside(fedId) ) {
00097       int idx = fedId - fedIds.min();
00098       fedSpecs[idx].rawids.push_back(rawId);
00099       fedSpecs[idx].names.push_back(name);
00100     } else edm::LogError("SiPixelFedCablingMapBuilder")
00101           <<"problem with numbering! "<<fedId<<" name: " << name->name();
00102   }
00103 
00104   LogDebug("tracker geometry read")<<"There are: "<< npxdets<<" pixel detetors";
00105   // construct FEDs
00106   typedef vector<FedSpec>::iterator FI;
00107   for ( FI it = fedSpecs.begin(); it != fedSpecs.end(); it++) {
00108     int fedId = it->fedId;
00109     vector<PixelModuleName* > names = it->names;
00110     vector<uint32_t> units = it->rawids;
00111     if ( names.size() == 0) continue;
00112     PixelFEDCabling fed(fedId);
00113     bool barrel = it->names.front()->isBarrel();
00114     if (barrel) {
00115       PixelFEDCabling::Links links = 
00116           PixelBarrelLinkMaker(&fed).links(names,units);
00117       fed.setLinks(links);
00118       result->addFed(fed);
00119     } else {
00120       PixelFEDCabling::Links links =
00121           PixelEndcapLinkMaker(&fed).links(names,units);
00122       fed.setLinks(links);
00123       result->addFed(fed);
00124     }
00125   }
00126   } else {
00127     PixelToFEDAssociate::DetectorRocId detectorRocId;
00128     cout <<" HERE PixelToLNKAssociateFromAscii"<<endl;
00129     for (UNITS::iterator iu=units.begin(); iu != units.end(); iu++) {
00130       PixelModuleName * name =  (*iu).first; 
00131       detectorRocId.module = name;
00132       for (int rocDetId=0; rocDetId<=16; rocDetId++) {
00133         detectorRocId.rocDetId = rocDetId;
00134         const PixelToFEDAssociate::CablingRocId * cablingRocId =  name2fed(detectorRocId);
00135         if (cablingRocId) {
00136           sipixelobjects::PixelROC roc( iu->second, rocDetId, cablingRocId->rocLinkId ); 
00137           result->addItem(cablingRocId->fedId, cablingRocId->linkId, roc);
00138         }
00139       }
00140     }
00141   }
00142 
00143   //clear names:
00144   for (UNITS::iterator iu=units.begin(); iu != units.end(); iu++) delete iu->first;
00145 
00146 
00147   return result;
00148 
00149 }
00150 std::string SiPixelFedCablingMapBuilder::myprint(const PixelGeomDetUnit * pxUnit)
00151 {
00152   std::ostringstream str;
00153   const PixelTopology & tpl = pxUnit->specificTopology();
00154   LocalPoint local;
00155   GlobalPoint global;
00156 
00157   local = LocalPoint(0,0,0); global = (*pxUnit).toGlobal(local);
00158   // phi measured from Y axis
00159   float phi = 180*atan2(global.x(),global.y())/M_PI;  if (phi > 180.) phi = phi-360;
00160   float r = global.perp();
00161   float z = global.z();
00162   str <<"    POSITION: "<<" r="<<r<<" phi="<<phi<<" z="<<z;
00163   str <<"   (rows,coll:"<<tpl.nrows()<<","<<tpl.ncolumns()<<")";
00164   str <<endl; 
00165   local = LocalPoint(0,0,0); str <<local<<"global: "<<(*pxUnit).toGlobal(local) <<endl;
00166   local = LocalPoint(1,0,0); str <<local<<"global: "<<(*pxUnit).toGlobal(local) <<endl;
00167   local = LocalPoint(0,1,0); str <<local<<"global: "<<(*pxUnit).toGlobal(local) <<endl;
00168   local = LocalPoint(0,0,1); str <<local<<"global: "<<(*pxUnit).toGlobal(local) <<endl;
00169       
00170   return str.str();
00171 }