CMS 3D CMS Logo

SeedingLayerSetsBuilder.cc

Go to the documentation of this file.
00001 #include "RecoTracker/TkSeedingLayers/interface/SeedingLayerSetsBuilder.h"
00002 
00003 #include "FWCore/Framework/interface/EventSetup.h"
00004 #include "FWCore/Framework/interface/ESHandle.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 
00007 #include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
00008 #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"
00009 
00010 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"
00011 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHit.h"
00012 #include "RecoTracker/TransientTrackingRecHit/interface/TkTransientTrackingRecHitBuilder.h"
00013 
00014 #include "TrackingTools/DetLayers/interface/BarrelDetLayer.h"
00015 #include "TrackingTools/DetLayers/interface/ForwardDetLayer.h"
00016 #include "RecoTracker/TkDetLayers/interface/PixelForwardLayer.h"
00017 #include "RecoTracker/TkDetLayers/interface/TOBLayer.h"
00018 #include "RecoTracker/TkDetLayers/interface/TIBLayer.h"
00019 
00020 #include "HitExtractorPIX.h"
00021 #include "HitExtractorSTRP.h"
00022 
00023 #include <iostream>
00024 #include <sstream>
00025 #include <ostream>
00026 #include <fstream>
00027 #include <map>
00028 
00029 
00030 using namespace ctfseeding;
00031 using namespace std;
00032 
00033 
00034 std::string SeedingLayerSetsBuilder::LayerSpec::print() const
00035 {
00036   std::ostringstream str;
00037   str << "Layer="<<name<<", hitBldr: "<<hitBuilder<<", useErrorsFromParam: ";
00038   if (useErrorsFromParam) {
00039      str <<"true,"<<" errRPhi: "<<hitErrorRPhi<<", errRZ: "<<hitErrorRZ; 
00040   }
00041   else str<<"false";
00042 
00043   str << ", useRingSelector: ";
00044   if (useRingSelector) {
00045     str <<"true,"<<" Rings: ("<<minRing<<","<<maxRing<<")"; 
00046   } else  str<<"false";
00047 
00048   return str.str();
00049 }
00050 
00051 SeedingLayerSetsBuilder::SeedingLayerSetsBuilder(const edm::ParameterSet & cfg)
00052 {
00053   std::vector<std::string> namesPset = cfg.getParameter<std::vector<std::string> >("layerList");
00054   std::vector<std::vector<std::string> > layerNamesInSets = this->layerNamesInSets(namesPset);
00055 
00056   // debug printout of layers
00057   typedef std::vector<std::string>::const_iterator IS;
00058   typedef std::vector<std::vector<std::string> >::const_iterator IT;
00059   std::ostringstream str;
00060   // The following should not be set to cout
00061 //  for (IT it = layerNamesInSets.begin(); it != layerNamesInSets.end(); it++) {
00062 //    str << "SET: ";
00063 //    for (IS is = it->begin(); is != it->end(); is++)  str << *is <<" ";  
00064 //    str << std::endl;
00065 //  }
00066 //  std::cout << str.str() << std::endl;
00067 
00068   map<string,LayerSpec> mapConfig; // for debug printout only!
00069 
00070   for (IT it = layerNamesInSets.begin(); it != layerNamesInSets.end(); it++) {
00071     vector<LayerSpec> layersInSet;
00072     for (IS is = it->begin(); is != it->end(); is++) {
00073       LayerSpec layer;
00074 
00075       layer.name = *is;
00076       //std::cout << "layer name in config: " << *is << std::endl;
00077       edm::ParameterSet cfgLayer = layerConfig(layer.name, cfg);
00078 
00079       layer.usePixelHitProducer = true;
00080       layer.useMatchedRecHits = true; 
00081       layer.useRPhiRecHits = true;
00082       layer.useStereoRecHits = true;
00083       if (cfgLayer.exists("HitProducer")) {
00084           layer.pixelHitProducer = cfgLayer.getParameter<string>("HitProducer"); 
00085       }else{
00086           layer.usePixelHitProducer = false;
00087       }
00088       if (cfgLayer.exists("matchedRecHits")) {
00089           layer.matchedRecHits = cfgLayer.getParameter<edm::InputTag>("matchedRecHits"); 
00090       }else{
00091           layer.useMatchedRecHits = false;
00092       }
00093       if (cfgLayer.exists("rphiRecHits")) {
00094           layer.rphiRecHits = cfgLayer.getParameter<edm::InputTag>("rphiRecHits"); 
00095       }else{
00096           layer.useRPhiRecHits = false;
00097       }
00098       if (cfgLayer.exists("stereoRecHits")) {
00099           layer.stereoRecHits= cfgLayer.getParameter<edm::InputTag>("stereoRecHits"); 
00100       }else{
00101           layer.useStereoRecHits = false;
00102       }
00103 
00104       layer.hitBuilder  = cfgLayer.getParameter<string>("TTRHBuilder");
00105 
00106       layer.useErrorsFromParam = cfgLayer.getUntrackedParameter<bool>("useErrorsFromParam",false);
00107       if(layer.useErrorsFromParam) {
00108         layer.hitErrorRPhi = cfgLayer.getParameter<double>("hitErrorRPhi");
00109         layer.hitErrorRZ   = cfgLayer.getParameter<double>("hitErrorRZ");
00110       }
00111 
00112       layer.useRingSelector = cfgLayer.getUntrackedParameter<bool>("useRingSlector",false);
00113       if (layer.useRingSelector) {
00114         layer.minRing = cfgLayer.getParameter<int>("minRing");
00115         layer.maxRing = cfgLayer.getParameter<int>("maxRing");
00116       }
00117 
00118       layer.useSimpleRphiHitsCleaner = cfgLayer.getUntrackedParameter<bool>("useSimpleRphiHitsCleaner",true);
00119       //std::cout << "from configuration, useCleaner: " << layer.useSimpleRphiHitsCleaner << std::endl;
00120 
00121       layersInSet.push_back(layer);
00122       mapConfig[layer.name]=layer;
00123     }
00124     theLayersInSets.push_back(layersInSet);
00125   }
00126 
00127   // debug printout
00128   // The following should not be set to cout
00129 //  for (map<string,LayerSpec>::const_iterator im = mapConfig.begin(); im != mapConfig.end(); im++) {
00130 //    std::cout << (*im).second.print() << std::endl; 
00131 //  }
00132 }
00133 
00134 edm::ParameterSet SeedingLayerSetsBuilder::layerConfig(const std::string & nameLayer,const edm::ParameterSet& cfg) const
00135 {
00136   edm::ParameterSet result;
00137    
00138   for (string::size_type iEnd=nameLayer.size(); iEnd > 0; --iEnd) {
00139     string name = nameLayer.substr(0,iEnd);
00140     if (cfg.exists(name)) return cfg.getParameter<edm::ParameterSet>(name);
00141   } 
00142   cout <<"configuration for layer: "<<nameLayer<<" not found, job will probably crash!"<<endl;
00143   return result;
00144 }
00145 
00146 vector<vector<string> > SeedingLayerSetsBuilder::layerNamesInSets( const vector<string> & namesPSet)
00147 {
00148   std::vector<std::vector<std::string> > result; 
00149   for (std::vector<std::string>::const_iterator is=namesPSet.begin(); is < namesPSet.end(); ++is) {
00150     vector<std::string> layersInSet;
00151     string line = *is;
00152     string::size_type pos=0;
00153     while (pos != string::npos ) {
00154       pos=line.find("+");
00155       string layer = line.substr(0,pos);
00156       layersInSet.push_back(layer);
00157       line=line.substr(pos+1,string::npos); 
00158     }
00159     result.push_back(layersInSet);
00160   }
00161   return result;
00162 }
00163 
00164 SeedingLayerSets SeedingLayerSetsBuilder::layers(const edm::EventSetup& es) const
00165 {
00166   typedef std::vector<SeedingLayer> Set;
00167   SeedingLayerSets  result;
00168 
00169   edm::ESHandle<GeometricSearchTracker> tracker;
00170   es.get<TrackerRecoGeometryRecord>().get( tracker );
00171 
00172   std::vector<BarrelDetLayer*>  bpx  = tracker->barrelLayers();
00173   std::vector<BarrelDetLayer*>  tib  = tracker->tibLayers();
00174   std::vector<BarrelDetLayer*>  tob  = tracker->tobLayers();
00175 
00176   std::vector<ForwardDetLayer*> fpx_pos = tracker->posForwardLayers();
00177   std::vector<ForwardDetLayer*> tid_pos = tracker->posTidLayers();
00178   std::vector<ForwardDetLayer*> tec_pos = tracker->posTecLayers();
00179 
00180   std::vector<ForwardDetLayer*> fpx_neg = tracker->negForwardLayers();
00181   std::vector<ForwardDetLayer*> tid_neg = tracker->negTidLayers();
00182   std::vector<ForwardDetLayer*> tec_neg = tracker->negTecLayers();
00183   
00184   typedef std::vector<std::vector<LayerSpec> >::const_iterator IT;
00185   typedef std::vector<LayerSpec>::const_iterator IS;
00186 
00187   for (IT it = theLayersInSets.begin(); it != theLayersInSets.end(); it++) {
00188     Set set;
00189     bool setOK = true;
00190     for (IS is = it->begin(), isEnd = it->end(); is < isEnd; ++is) {
00191       const LayerSpec & layer = (*is);
00192       std::string name = layer.name;
00193       const DetLayer * detLayer =0;
00194       SeedingLayer::Side side=SeedingLayer::Barrel;
00195       int idLayer = 0;
00196       bool nameOK = true;
00197       HitExtractor * extractor = 0; 
00198       
00199       //
00200       // BPIX
00201       //
00202       if (name.substr(0,4) == "BPix") {
00203         idLayer = atoi(name.substr(4,1).c_str());
00204         side=SeedingLayer::Barrel;
00205         detLayer=bpx[idLayer-1]; 
00206       }
00207       //
00208       // FPIX
00209       //
00210       else if (name.substr(0,4) == "FPix") {
00211         idLayer = atoi(name.substr(4,1).c_str());
00212         if ( name.find("pos") != string::npos ) {
00213           side = SeedingLayer::PosEndcap;
00214           detLayer = fpx_pos[idLayer-1];
00215         } else {
00216           side = SeedingLayer::NegEndcap;
00217           detLayer = fpx_neg[idLayer-1];
00218         }
00219       }
00220       //
00221       // TIB
00222       //
00223       else if (name.substr(0,3) == "TIB") {
00224         idLayer = atoi(name.substr(3,1).c_str());
00225         side=SeedingLayer::Barrel;
00226         detLayer=tib[idLayer-1];
00227       }
00228       //
00229       // TID
00230       //
00231       else if (name.substr(0,3) == "TID") {
00232         idLayer = atoi(name.substr(3,1).c_str());
00233         if ( name.find("pos") != string::npos ) {
00234           side = SeedingLayer::PosEndcap;
00235           detLayer = tid_pos[idLayer-1];
00236         } else {
00237           side = SeedingLayer::NegEndcap;
00238           detLayer = tid_neg[idLayer-1];
00239         }
00240       }
00241       //
00242       // TOB
00243       //
00244       else if (name.substr(0,3) == "TOB") {
00245         idLayer = atoi(name.substr(3,1).c_str());
00246         side=SeedingLayer::Barrel;
00247         detLayer=tob[idLayer-1];
00248       }
00249       //
00250       // TEC
00251       //
00252       else if (name.substr(0,3) == "TEC") {
00253         idLayer = atoi(name.substr(3,1).c_str());
00254         if ( name.find("pos") != string::npos ) {
00255           side = SeedingLayer::PosEndcap;
00256           detLayer = tec_pos[idLayer-1];
00257         } else {
00258           side = SeedingLayer::NegEndcap;
00259           detLayer = tec_neg[idLayer-1];
00260         }
00261       }
00262       else {
00263         nameOK = false;
00264         setOK = false;
00265       }
00266 
00267       if(nameOK) {
00268         if ( detLayer->subDetector() == GeomDetEnumerators::PixelBarrel ||
00269              detLayer->subDetector() == GeomDetEnumerators::PixelEndcap) {
00270           extractor = new HitExtractorPIX(side,idLayer,layer.pixelHitProducer);
00271         } else {
00272           HitExtractorSTRP extSTRP(detLayer,side,idLayer);
00273           if (layer.useMatchedRecHits) extSTRP.useMatchedHits(layer.matchedRecHits);
00274           if (layer.useRPhiRecHits)    extSTRP.useRPhiHits(layer.rphiRecHits);
00275           if (layer.useStereoRecHits)  extSTRP.useStereoHits(layer.stereoRecHits);
00276           if (layer.useRingSelector)   extSTRP.useRingSelector(layer.minRing,layer.maxRing);
00277           extSTRP.useSimpleRphiHitsCleaner(layer.useSimpleRphiHitsCleaner);
00278           extractor = extSTRP.clone();
00279         }
00280 
00281         edm::ESHandle<TransientTrackingRecHitBuilder> builder;
00282         es.get<TransientRecHitRecord>().get(layer.hitBuilder, builder);
00283 
00284         if (layer.useErrorsFromParam) {
00285           set.push_back( SeedingLayer( name, detLayer, builder.product(), 
00286                                        extractor, true, layer.hitErrorRPhi,layer.hitErrorRZ));
00287         } else {
00288           set.push_back( SeedingLayer( name, detLayer, builder.product(), extractor));
00289         }
00290       }
00291     
00292     }
00293     if(setOK) result.push_back(set);
00294   }
00295   return result;
00296 }

Generated on Tue Jun 9 17:45:59 2009 for CMSSW by  doxygen 1.5.4