CMS 3D CMS Logo

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