CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoEgamma/EgammaPhotonProducers/src/ConversionTrackCandidateProducer.cc

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <vector>
00003 #include <memory>
00004 
00005 // Framework
00006 #include "FWCore/Framework/interface/Event.h"
00007 #include "FWCore/Framework/interface/EventSetup.h"
00008 #include "DataFormats/Common/interface/Handle.h"
00009 #include "FWCore/Framework/interface/ESHandle.h"
00010 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00011 #include "FWCore/Utilities/interface/Exception.h"
00012 //
00013 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
00014 #include "DataFormats/EgammaTrackReco/interface/TrackCandidateSuperClusterAssociation.h"
00015 #include "DataFormats/EgammaTrackReco/interface/TrackCandidateCaloClusterAssociation.h"
00016 //
00017 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00018 //
00019 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00020 //  Abstract classes for the conversion tracking components
00021 #include "RecoEgamma/EgammaPhotonAlgos/interface/ConversionSeedFinder.h"
00022 #include "RecoEgamma/EgammaPhotonAlgos/interface/ConversionTrackFinder.h"
00023 // Class header file
00024 #include "RecoEgamma/EgammaPhotonProducers/interface/ConversionTrackCandidateProducer.h"
00025 //
00026 #include "RecoTracker/Record/interface/CkfComponentsRecord.h"
00027 #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"
00028 #include "RecoTracker/Record/interface/NavigationSchoolRecord.h"
00029 
00030 #include "RecoEgamma/EgammaPhotonAlgos/interface/OutInConversionSeedFinder.h"
00031 #include "RecoEgamma/EgammaPhotonAlgos/interface/InOutConversionSeedFinder.h"
00032 #include "RecoEgamma/EgammaPhotonAlgos/interface/OutInConversionTrackFinder.h"
00033 #include "RecoEgamma/EgammaPhotonAlgos/interface/InOutConversionTrackFinder.h"
00034 #include "RecoEgamma/EgammaIsolationAlgos/interface/EgammaTowerIsolation.h"
00035 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00036 
00037 ConversionTrackCandidateProducer::ConversionTrackCandidateProducer(const edm::ParameterSet& config) : 
00038   conf_(config), 
00039   theNavigationSchool_(0), 
00040   theOutInSeedFinder_(0), 
00041   theOutInTrackFinder_(0), 
00042   theInOutSeedFinder_(0),
00043   theInOutTrackFinder_(0)
00044 {
00045 
00046 
00047   
00048   //std::cout << "ConversionTrackCandidateProducer CTOR " << "\n";
00049   nEvt_=0;  
00050    
00051   // use onfiguration file to setup input/output collection names
00052  
00053 
00054   bcBarrelCollection_     = conf_.getParameter<edm::InputTag>("bcBarrelCollection");
00055   bcEndcapCollection_     = conf_.getParameter<edm::InputTag>("bcEndcapCollection");
00056   
00057   scHybridBarrelProducer_       = conf_.getParameter<edm::InputTag>("scHybridBarrelProducer");
00058   scIslandEndcapProducer_       = conf_.getParameter<edm::InputTag>("scIslandEndcapProducer");
00059   
00060   OutInTrackCandidateCollection_ = conf_.getParameter<std::string>("outInTrackCandidateCollection");
00061   InOutTrackCandidateCollection_ = conf_.getParameter<std::string>("inOutTrackCandidateCollection");
00062 
00063 
00064   OutInTrackSuperClusterAssociationCollection_ = conf_.getParameter<std::string>("outInTrackCandidateSCAssociationCollection");
00065   InOutTrackSuperClusterAssociationCollection_ = conf_.getParameter<std::string>("inOutTrackCandidateSCAssociationCollection");
00066 
00067   hcalTowers_ = conf_.getParameter<edm::InputTag>("hcalTowers");
00068   hOverEConeSize_   = conf_.getParameter<double>("hOverEConeSize");
00069   maxHOverE_        = conf_.getParameter<double>("maxHOverE");
00070   minSCEt_        = conf_.getParameter<double>("minSCEt");
00071 
00072 
00073   // Register the product
00074   produces< TrackCandidateCollection > (OutInTrackCandidateCollection_);
00075   produces< TrackCandidateCollection > (InOutTrackCandidateCollection_);
00076 
00077   produces< reco::TrackCandidateCaloClusterPtrAssociation > ( OutInTrackSuperClusterAssociationCollection_);
00078   produces< reco::TrackCandidateCaloClusterPtrAssociation > ( InOutTrackSuperClusterAssociationCollection_);
00079   
00080 
00081 }
00082 
00083 ConversionTrackCandidateProducer::~ConversionTrackCandidateProducer() {}
00084 
00085 void  ConversionTrackCandidateProducer::setEventSetup (const edm::EventSetup & theEventSetup) {
00086 
00087 
00088   theOutInSeedFinder_->setEventSetup(theEventSetup);
00089   theInOutSeedFinder_->setEventSetup(theEventSetup);
00090   theOutInTrackFinder_->setEventSetup(theEventSetup);
00091   theInOutTrackFinder_->setEventSetup(theEventSetup);
00092 
00093 }
00094 
00095 
00096 void  ConversionTrackCandidateProducer::beginRun (edm::Run& r , edm::EventSetup const & theEventSetup) {
00097 
00098   edm::ESHandle<NavigationSchool> nav;
00099   theEventSetup.get<NavigationSchoolRecord>().get("SimpleNavigationSchool", nav);
00100   theNavigationSchool_ = nav.product();
00101 
00102   // get the Out In Seed Finder  
00103   theOutInSeedFinder_ = new OutInConversionSeedFinder (  conf_ );
00104   
00105   // get the Out In Track Finder
00106   theOutInTrackFinder_ = new OutInConversionTrackFinder ( theEventSetup, conf_  );
00107 
00108   
00109   // get the In Out Seed Finder  
00110   theInOutSeedFinder_ = new InOutConversionSeedFinder ( conf_ );
00111   
00112   
00113   // get the In Out Track Finder
00114   theInOutTrackFinder_ = new InOutConversionTrackFinder ( theEventSetup, conf_  );
00115 
00116 
00117 }
00118 
00119 
00120 void  ConversionTrackCandidateProducer::endRun (edm::Run& r , edm::EventSetup const & theEventSetup) {
00121   delete theOutInSeedFinder_; 
00122   delete theOutInTrackFinder_;
00123   delete theInOutSeedFinder_;  
00124   delete theInOutTrackFinder_;
00125 }
00126 
00127 
00128 
00129 
00130 void ConversionTrackCandidateProducer::produce(edm::Event& theEvent, const edm::EventSetup& theEventSetup) {
00131   
00132   using namespace edm;
00133   nEvt_++;
00134   //  std::cout << "ConversionTrackCandidateProducer Analyzing event number " <<   theEvent.id() <<  " Global Counter " << nEvt_ << "\n";
00135   
00136 
00137   
00138   setEventSetup( theEventSetup );
00139   theOutInSeedFinder_->setEvent(theEvent);
00140   theInOutSeedFinder_->setEvent(theEvent);
00141   theOutInTrackFinder_->setEvent(theEvent);
00142   theInOutTrackFinder_->setEvent(theEvent);
00143 
00144 // Set the navigation school  
00145   NavigationSetter setter(*theNavigationSchool_);  
00146 
00147   //
00148   // create empty output collections
00149   //
00150   //  Out In Track Candidates
00151   std::auto_ptr<TrackCandidateCollection> outInTrackCandidate_p(new TrackCandidateCollection); 
00152   //  In Out  Track Candidates
00153   std::auto_ptr<TrackCandidateCollection> inOutTrackCandidate_p(new TrackCandidateCollection); 
00154   //   Track Candidate  calo  Cluster Association
00155   std::auto_ptr<reco::TrackCandidateCaloClusterPtrAssociation> outInAssoc_p(new reco::TrackCandidateCaloClusterPtrAssociation);
00156   std::auto_ptr<reco::TrackCandidateCaloClusterPtrAssociation> inOutAssoc_p(new reco::TrackCandidateCaloClusterPtrAssociation);
00157     
00158   // Get the basic cluster collection in the Barrel 
00159   bool validBarrelBCHandle=true;
00160   edm::Handle<edm::View<reco::CaloCluster> > bcBarrelHandle;
00161   theEvent.getByLabel(bcBarrelCollection_, bcBarrelHandle);
00162   if (!bcBarrelHandle.isValid()) {
00163     edm::LogError("ConversionTrackCandidateProducer") << "Error! Can't get the product "<<bcBarrelCollection_.label();
00164     validBarrelBCHandle=false;
00165   }
00166   
00167   
00168   // Get the basic cluster collection in the Endcap 
00169   bool validEndcapBCHandle=true;
00170   edm::Handle<edm::View<reco::CaloCluster> > bcEndcapHandle;
00171   theEvent.getByLabel(bcEndcapCollection_, bcEndcapHandle);
00172   if (!bcEndcapHandle.isValid()) {
00173     edm::LogError("CoonversionTrackCandidateProducer") << "Error! Can't get the product "<<bcEndcapCollection_.label();
00174     validEndcapBCHandle=false; 
00175   }
00176   
00177   
00178 
00179   // Get the Super Cluster collection in the Barrel
00180   bool validBarrelSCHandle=true;
00181   edm::Handle<edm::View<reco::CaloCluster> > scBarrelHandle;
00182   theEvent.getByLabel(scHybridBarrelProducer_,scBarrelHandle);
00183   if (!scBarrelHandle.isValid()) {
00184     edm::LogError("CoonversionTrackCandidateProducer") << "Error! Can't get the product "<<scHybridBarrelProducer_.label();
00185     validBarrelSCHandle=false;
00186   }
00187 
00188 
00189   // Get the Super Cluster collection in the Endcap
00190   bool validEndcapSCHandle=true;
00191   edm::Handle<edm::View<reco::CaloCluster> > scEndcapHandle;
00192   theEvent.getByLabel(scIslandEndcapProducer_,scEndcapHandle);
00193   if (!scEndcapHandle.isValid()) {
00194     edm::LogError("CoonversionTrackCandidateProducer") << "Error! Can't get the product "<<scIslandEndcapProducer_.label();
00195     validEndcapSCHandle=false;
00196   }
00197 
00198 
00199   // get the geometry from the event setup:
00200   theEventSetup.get<CaloGeometryRecord>().get(theCaloGeom_);
00201 
00202   // get Hcal towers collection 
00203   Handle<CaloTowerCollection> hcalTowersHandle;
00204   theEvent.getByLabel(hcalTowers_, hcalTowersHandle);
00205 
00206 
00207   caloPtrVecOutIn_.clear();
00208   caloPtrVecInOut_.clear();
00209 
00210   if ( validBarrelBCHandle && validBarrelSCHandle ) 
00211     buildCollections(scBarrelHandle, bcBarrelHandle, hcalTowersHandle, *outInTrackCandidate_p,*inOutTrackCandidate_p,caloPtrVecOutIn_,caloPtrVecInOut_ );
00212   if ( validEndcapBCHandle && validEndcapSCHandle ) 
00213     buildCollections(scEndcapHandle, bcEndcapHandle, hcalTowersHandle, *outInTrackCandidate_p,*inOutTrackCandidate_p,caloPtrVecOutIn_,caloPtrVecInOut_ );
00214 
00215 
00216 
00217 
00218   //  std::cout  << "  ConversionTrackCandidateProducer  caloPtrVecOutIn_ size " <<  caloPtrVecOutIn_.size() << " caloPtrVecInOut_ size " << caloPtrVecInOut_.size()  << "\n"; 
00219   
00220 
00221 
00222   // put all products in the event
00223  // Barrel
00224  //std::cout  << "ConversionTrackCandidateProducer Putting in the event " << (*outInTrackCandidate_p).size() << " Out In track Candidates " << "\n";
00225  const edm::OrphanHandle<TrackCandidateCollection> refprodOutInTrackC = theEvent.put( outInTrackCandidate_p, OutInTrackCandidateCollection_ );
00226  //std::cout  << "ConversionTrackCandidateProducer  refprodOutInTrackC size  " <<  (*(refprodOutInTrackC.product())).size()  <<  "\n";
00227  //
00228  //std::cout  << "ConversionTrackCandidateProducer Putting in the event  " << (*inOutTrackCandidate_p).size() << " In Out track Candidates " <<  "\n";
00229  const edm::OrphanHandle<TrackCandidateCollection> refprodInOutTrackC = theEvent.put( inOutTrackCandidate_p, InOutTrackCandidateCollection_ );
00230  //std::cout  << "ConversionTrackCandidateProducer  refprodInOutTrackC size  " <<  (*(refprodInOutTrackC.product())).size()  <<  "\n";
00231 
00232 
00233  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerOI(*outInAssoc_p);
00234  fillerOI.insert(refprodOutInTrackC, caloPtrVecOutIn_.begin(), caloPtrVecOutIn_.end());
00235  fillerOI.fill();
00236  edm::ValueMap<reco::CaloClusterPtr>::Filler fillerIO(*inOutAssoc_p);
00237  fillerIO.insert(refprodInOutTrackC, caloPtrVecInOut_.begin(), caloPtrVecInOut_.end());
00238  fillerIO.fill();
00239 
00240 
00241   
00242  // std::cout  << "ConversionTrackCandidateProducer Putting in the event   OutIn track - SC association: size  " <<  (*outInAssoc_p).size() << "\n";  
00243  theEvent.put( outInAssoc_p, OutInTrackSuperClusterAssociationCollection_);
00244  
00245  // std::cout << "ConversionTrackCandidateProducer Putting in the event   InOut track - SC association: size  " <<  (*inOutAssoc_p).size() << "\n";  
00246  theEvent.put( inOutAssoc_p, InOutTrackSuperClusterAssociationCollection_);
00247 
00248  theOutInSeedFinder_->clear();
00249  theInOutSeedFinder_->clear();
00250  
00251 
00252   
00253 }
00254 
00255 
00256 void ConversionTrackCandidateProducer::buildCollections( const edm::Handle<edm::View<reco::CaloCluster> > & scHandle,
00257                                                          const edm::Handle<edm::View<reco::CaloCluster> > & bcHandle,
00258                                                          const edm::Handle<CaloTowerCollection> & hcalTowersHandle,
00259                                                          TrackCandidateCollection& outInTrackCandidates,
00260                                                          TrackCandidateCollection& inOutTrackCandidates,
00261                                                          std::vector<edm::Ptr<reco::CaloCluster> >& vecRecOI,
00262                                                          std::vector<edm::Ptr<reco::CaloCluster> >& vecRecIO )
00263 
00264 {
00265 
00266   //  std::cout << "ConversionTrackCandidateProducer builcollections bc size " << bcHandle->size() <<  "\n";
00267   //const CaloGeometry* geometry = theCaloGeom_.product();
00268 
00269   //  Loop over SC in the barrel and reconstruct converted photons
00270   for (unsigned i = 0; i < scHandle->size(); ++i ) {
00271 
00272     reco::CaloClusterPtr aClus= scHandle->ptrAt(i);
00273 
00274     // preselection based in Et and H/E cut. 
00275     if (aClus->energy()/cosh(aClus->eta()) <= minSCEt_) continue;
00276     const reco::CaloCluster* pClus=&(*aClus);
00277     const reco::SuperCluster*  sc=dynamic_cast<const reco::SuperCluster*>(pClus);
00278     const CaloTowerCollection* hcalTowersColl = hcalTowersHandle.product();
00279     EgammaTowerIsolation towerIso(hOverEConeSize_,0.,0.,-1,hcalTowersColl) ;
00280     double HoE=towerIso.getTowerESum(sc)/sc->energy();
00281     if (HoE>=maxHOverE_)  continue;
00283 
00284     theOutInSeedFinder_->setCandidate(pClus->energy(), GlobalPoint(pClus->position().x(),pClus->position().y(),pClus->position().z() ) );
00285     theOutInSeedFinder_->makeSeeds( bcHandle );
00286 
00287     std::vector<Trajectory> theOutInTracks= theOutInTrackFinder_->tracks(theOutInSeedFinder_->seeds(),  outInTrackCandidates);    
00288 
00289  
00290     theInOutSeedFinder_->setCandidate(pClus->energy(), GlobalPoint(pClus->position().x(),pClus->position().y(),pClus->position().z() ) );  
00291     theInOutSeedFinder_->setTracks(  theOutInTracks );   
00292     theInOutSeedFinder_->makeSeeds(  bcHandle);
00293     
00294     std::vector<Trajectory> theInOutTracks= theInOutTrackFinder_->tracks(theInOutSeedFinder_->seeds(),  inOutTrackCandidates); 
00295 
00296 
00297     // Debug
00298     //   std::cout  << "ConversionTrackCandidateProducer  theOutInTracks.size() " << theOutInTracks.size() << " theInOutTracks.size() " << theInOutTracks.size() <<  " Event pointer to out in track size barrel " << outInTrackCandidates.size() << " in out track size " << inOutTrackCandidates.size() <<   "\n";
00299 
00300 
00302     for (std::vector<Trajectory>::const_iterator it = theOutInTracks.begin(); it !=  theOutInTracks.end(); ++it) {
00303       caloPtrVecOutIn_.push_back(aClus);
00304       //     std::cout  << "ConversionTrackCandidateProducer Barrel OutIn Tracks Number of hits " << (*it).foundHits() << "\n"; 
00305     }
00306 
00307     for (std::vector<Trajectory>::const_iterator it = theInOutTracks.begin(); it !=  theInOutTracks.end(); ++it) {
00308       caloPtrVecInOut_.push_back(aClus);
00309       //     std::cout  << "ConversionTrackCandidateProducer Barrel InOut Tracks Number of hits " << (*it).foundHits() << "\n"; 
00310     }
00311 
00312 
00313 
00314 
00315     
00316 
00317   }
00318 
00319 
00320 
00321 }
00322