CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/RecoTracker/ConversionSeedGenerators/src/PhotonConversionTrajectorySeedProducerFromQuadrupletsAlgo.cc

Go to the documentation of this file.
00001 #include "RecoTracker/ConversionSeedGenerators/interface/PhotonConversionTrajectorySeedProducerFromQuadrupletsAlgo.h"
00002 #include "RecoTracker/ConversionSeedGenerators/interface/Quad.h"
00003 #include "FWCore/Utilities/interface/Exception.h"
00004 // ClusterShapeIncludes:::
00005 #include "RecoTracker/TkTrackingRegions/interface/OrderedHitsGenerator.h"
00006 #include "RecoTracker/TkTrackingRegions/interface/TrackingRegion.h"
00007 #include "RecoTracker/TkSeedingLayers/interface/SeedComparitor.h"
00008 #include "RecoTracker/TkSeedGenerator/interface/SeedCreator.h"
00009 #include "RecoTracker/TkSeedingLayers/interface/SeedComparitorFactory.h"
00010 #include "RecoTracker/TkSeedGenerator/interface/SeedCreatorFactory.h"
00011 /*
00012 To Do:
00013 
00014 assign the parameters to some data member to avoid search at every event
00015 
00016  */
00017 
00018 //#define debugTSPFSLA
00019 //#define mydebug_knuenz
00020 
00021 PhotonConversionTrajectorySeedProducerFromQuadrupletsAlgo::
00022 PhotonConversionTrajectorySeedProducerFromQuadrupletsAlgo(const edm::ParameterSet & conf)
00023   :_conf(conf),seedCollection(0),
00024    hitsfactoryPSet(conf.getParameter<edm::ParameterSet>("OrderedHitsFactoryPSet")),   
00025    creatorPSet(conf.getParameter<edm::ParameterSet>("SeedCreatorPSet")),
00026    regfactoryPSet(conf.getParameter<edm::ParameterSet>("RegionFactoryPSet")),
00027    theClusterCheck(conf.getParameter<edm::ParameterSet>("ClusterCheckPSet")),
00028    SeedComparitorPSet(conf.getParameter<edm::ParameterSet>("SeedComparitorPSet")),
00029    QuadCutPSet(conf.getParameter<edm::ParameterSet>("QuadCutPSet")),
00030    theSilentOnClusterCheck(conf.getParameter<edm::ParameterSet>("ClusterCheckPSet").getUntrackedParameter<bool>("silentClusterCheck",false)){
00031 
00032   init();  
00033 }
00034      
00035 void PhotonConversionTrajectorySeedProducerFromQuadrupletsAlgo::
00036 clear(){
00037   if(theHitsGenerator!=NULL)
00038     delete theHitsGenerator;
00039   if(theSeedCreator!=NULL)
00040     delete theSeedCreator;
00041   if(theRegionProducer!=NULL)
00042     delete theRegionProducer;
00043 }
00044 
00045 void PhotonConversionTrajectorySeedProducerFromQuadrupletsAlgo::
00046 init(){
00047   theHitsGenerator  = new CombinedHitQuadrupletGeneratorForPhotonConversion(hitsfactoryPSet);
00048   theSeedCreator    = new SeedForPhotonConversionFromQuadruplets(creatorPSet);
00049   theRegionProducer = new GlobalTrackingRegionProducerFromBeamSpot(regfactoryPSet);
00050 }
00051 
00052 void PhotonConversionTrajectorySeedProducerFromQuadrupletsAlgo::
00053 analyze(const edm::Event & event, const edm::EventSetup &setup){
00054 
00055   myEsetup = &setup;
00056   myEvent = &event;
00057 
00058   if(seedCollection!=0)
00059     delete seedCollection;
00060 
00061   seedCollection= new TrajectorySeedCollection();
00062 
00063   size_t clustsOrZero = theClusterCheck.tooManyClusters(event);
00064   if (clustsOrZero){
00065     if (!theSilentOnClusterCheck)
00066       edm::LogError("TooManyClusters") << "Found too many clusters (" << clustsOrZero << "), bailing out.\n";
00067     return ;
00068   }
00069 
00070   regions = theRegionProducer->regions(event,setup);
00071 
00072   event.getByLabel(_conf.getParameter<edm::InputTag>("primaryVerticesTag"), vertexHandle);
00073   if (!vertexHandle.isValid()){ 
00074     edm::LogError("PhotonConversionFinderFromTracks") << "Error! Can't get the product primary Vertex Collection "<< _conf.getParameter<edm::InputTag>("primaryVerticesTag") <<  "\n";
00075     return;
00076   }
00077 
00078   //Do the analysis
00079   loop();
00080 
00081 #ifdef mydebug_knuenz
00082   std::cout << "Running PhotonConversionTrajectorySeedProducerFromQuadrupletsAlgo" <<std::endl;
00083 #endif
00084 
00085 #ifdef debugTSPFSLA 
00086   std::stringstream ss;
00087   ss.str("");
00088   ss << "\n++++++++++++++++++\n";
00089   ss << "seed collection size " << seedCollection->size();
00090   BOOST_FOREACH(TrajectorySeed tjS,*seedCollection){
00091     po.print(ss, tjS);
00092   }
00093   edm::LogInfo("debugTrajSeedFromQuadruplets") << ss.str();
00094   //-------------------------------------------------
00095 #endif
00096 }
00097 
00098 
00099 void PhotonConversionTrajectorySeedProducerFromQuadrupletsAlgo::
00100 loop(){
00101 
00102   
00103   ss.str("");
00104   
00105   float ptMin=0.1;
00106   
00107   BOOST_FOREACH(const reco::Vertex primaryVertex, *vertexHandle){
00108 
00109     //FIXME currnetly using the first primaryVertex, should loop on the promaryVertexes
00110     GlobalTrackingRegion region(ptMin
00111                                 ,GlobalPoint(
00112                                              primaryVertex.position().x(),
00113                                              primaryVertex.position().y(), 
00114                                              primaryVertex.position().z() 
00115                                              )
00116                                 ,primaryVertex.xError()*10
00117                                 ,primaryVertex.zError()*10
00118                                 ,true
00119                                 ); 
00120     
00121 #ifdef debugTSPFSLA 
00122     ss << "[PrintRegion] " << region.print() << std::endl;
00123 #endif
00124     
00125     inspect(region);
00126 
00127   }
00128 #ifdef debugTSPFSLA 
00129   edm::LogInfo("debugTrajSeedFromQuadruplets") << ss.str();
00130 #endif
00131 }
00132   
00133 
00134 bool PhotonConversionTrajectorySeedProducerFromQuadrupletsAlgo::
00135 inspect(const TrackingRegion & region ){
00136 
00137   const OrderedSeedingHits & hitss = theHitsGenerator->run(region, *myEvent, *myEsetup);
00138   
00139   unsigned int nHitss =  hitss.size();
00140 
00141 #ifdef debugTSPFSLA 
00142   ss << "\n nHitss " << nHitss << "\n";
00143 #endif
00144 
00145   if (seedCollection->empty()) seedCollection->reserve(nHitss/2); // don't do multiple reserves in the case of multiple regions: it would make things even worse
00146                                                                // as it will cause N re-allocations instead of the normal log(N)/log(2)
00147 
00148   unsigned int iHits=0, jHits=1;
00149 
00150   //
00151   // Trivial arbitration
00152   //
00153   // Vector to store old quad values
00154   std::vector<Quad> quadVector;
00155 
00156 
00157   for (; iHits < nHitss && jHits < nHitss; iHits+=2 , jHits+=2) { 
00158 
00159 #ifdef debugTSPFSLA 
00160     //    ss << "\n iHits " << iHits << " " << jHits << "\n";
00161 #endif
00162     //phits is the pair of hits for the positron
00163     const SeedingHitSet & phits =  hitss[iHits];
00164     //mhits is the pair of hits for the electron
00165     const SeedingHitSet & mhits =  hitss[jHits];
00166 
00167 
00168     try{
00169       //FIXME (modify the interface of the seed generator if needed)
00170       //passing the region, that is centered around the primary vertex
00171       theSeedCreator->trajectorySeed(*seedCollection, phits, mhits, region, *myEsetup, ss, quadVector, SeedComparitorPSet, QuadCutPSet);
00172     }catch(cms::Exception& er){
00173       edm::LogError("SeedingConversion") << " Problem in the Quad Seed creator " <<er.what()<<std::endl;
00174     }catch(std::exception& er){
00175       edm::LogError("SeedingConversion") << " Problem in the Quad Seed creator " <<er.what()<<std::endl;
00176     }
00177   }
00178   quadVector.clear();
00179   return true;
00180 }