CMS 3D CMS Logo

CMSSW_4_4_3_patch1/src/RecoTracker/TkSeedGenerator/plugins/SeedGeneratorFromRegionHitsEDProducer.cc

Go to the documentation of this file.
00001 #include "SeedGeneratorFromRegionHitsEDProducer.h"
00002 
00003 #include "FWCore/Framework/interface/Event.h"
00004 #include "FWCore/Framework/interface/EventSetup.h"
00005 
00006 #include "DataFormats/TrajectorySeed/interface/TrajectorySeedCollection.h"
00007 
00008 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegionProducerFactory.h"
00009 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegionProducer.h"
00010 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegion.h"
00011 
00012 #include "RecoTracker/TkTrackingRegions/interface/OrderedHitsGeneratorFactory.h"
00013 #include "RecoTracker/TkTrackingRegions/interface/OrderedHitsGenerator.h"
00014 
00015 #include "RecoTracker/TkSeedingLayers/interface/SeedComparitorFactory.h"
00016 #include "RecoTracker/TkSeedingLayers/interface/SeedComparitor.h"
00017 
00018 #include "RecoTracker/TkSeedGenerator/interface/SeedCreatorFactory.h"
00019 #include "RecoTracker/TkSeedGenerator/interface/SeedCreator.h"
00020 
00021 #include "RecoTracker/TkSeedGenerator/interface/SeedGeneratorFromRegionHits.h"
00022 
00023 
00024 SeedGeneratorFromRegionHitsEDProducer::SeedGeneratorFromRegionHitsEDProducer(
00025     const edm::ParameterSet& cfg) 
00026   : theConfig(cfg), theGenerator(0), theRegionProducer(0), theClusterCheck(cfg.getParameter<edm::ParameterSet>("ClusterCheckPSet"))
00027 {
00028   theSilentOnClusterCheck = cfg.getParameter<edm::ParameterSet>("ClusterCheckPSet").getUntrackedParameter<bool>("silentClusterCheck",false);
00029   produces<TrajectorySeedCollection>();
00030 }
00031 
00032 SeedGeneratorFromRegionHitsEDProducer::~SeedGeneratorFromRegionHitsEDProducer()
00033 {
00034 }
00035 
00036 void SeedGeneratorFromRegionHitsEDProducer::endRun(edm::Run &run, const edm::EventSetup& es) {
00037   delete theRegionProducer;
00038   delete theGenerator;
00039 }
00040 
00041 void SeedGeneratorFromRegionHitsEDProducer::beginRun(edm::Run &run, const edm::EventSetup& es)
00042 {
00043   edm::ParameterSet regfactoryPSet = 
00044       theConfig.getParameter<edm::ParameterSet>("RegionFactoryPSet");
00045   std::string regfactoryName = regfactoryPSet.getParameter<std::string>("ComponentName");
00046   theRegionProducer = TrackingRegionProducerFactory::get()->create(regfactoryName,regfactoryPSet);
00047 
00048   edm::ParameterSet hitsfactoryPSet = 
00049       theConfig.getParameter<edm::ParameterSet>("OrderedHitsFactoryPSet");
00050   std::string hitsfactoryName = hitsfactoryPSet.getParameter<std::string>("ComponentName");
00051   OrderedHitsGenerator*  hitsGenerator = 
00052       OrderedHitsGeneratorFactory::get()->create( hitsfactoryName, hitsfactoryPSet);
00053 
00054   edm::ParameterSet comparitorPSet =
00055       theConfig.getParameter<edm::ParameterSet>("SeedComparitorPSet");
00056   std::string comparitorName = comparitorPSet.getParameter<std::string>("ComponentName");
00057   SeedComparitor * aComparitor = (comparitorName == "none") ? 
00058       0 :  SeedComparitorFactory::get()->create( comparitorName, comparitorPSet);   
00059 
00060   edm::ParameterSet creatorPSet =
00061       theConfig.getParameter<edm::ParameterSet>("SeedCreatorPSet");
00062   std::string creatorName = creatorPSet.getParameter<std::string>("ComponentName");
00063   SeedCreator * aCreator = SeedCreatorFactory::get()->create( creatorName, creatorPSet);
00064 
00065   theGenerator = new SeedGeneratorFromRegionHits(hitsGenerator, aComparitor, aCreator); 
00066   
00067   
00068 }
00069 
00070 void SeedGeneratorFromRegionHitsEDProducer::produce(edm::Event& ev, const edm::EventSetup& es)
00071 {
00072   std::auto_ptr<TrajectorySeedCollection> result(new TrajectorySeedCollection());
00073 
00074   //protection for big ass events...
00075   size_t clustsOrZero = theClusterCheck.tooManyClusters(ev);
00076   if (clustsOrZero){
00077     if (!theSilentOnClusterCheck)
00078         edm::LogError("TooManyClusters") << "Found too many clusters (" << clustsOrZero << "), bailing out.\n";
00079     ev.put(result);
00080     return ;
00081   }
00082 
00083   typedef std::vector<TrackingRegion* > Regions;
00084   typedef Regions::const_iterator IR;
00085   Regions regions = theRegionProducer->regions(ev,es);
00086 
00087   for (IR ir=regions.begin(), irEnd=regions.end(); ir < irEnd; ++ir) {
00088     const TrackingRegion & region = **ir;
00089 
00090     // make job
00091     theGenerator->run(*result, region, ev,es);
00092   }
00093 
00094   // clear memory
00095   for (IR ir=regions.begin(), irEnd=regions.end(); ir < irEnd; ++ir) delete (*ir);
00096 
00097   // put to event
00098   ev.put(result);
00099 }