CMS 3D CMS Logo

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