CMS 3D CMS Logo

SoftConversionTrackCandidateProducer.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/CaloRecHit/interface/CaloCluster.h"
00014 #include "DataFormats/CaloRecHit/interface/CaloClusterFwd.h"
00015 #include "DataFormats/TrackCandidate/interface/TrackCandidateCollection.h"
00016 #include "DataFormats/EgammaTrackReco/interface/TrackCandidateCaloClusterAssociation.h"
00017 //
00018 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00019 //
00020 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00021 //  Abstract classes for the conversion tracking components
00022 #include "RecoEgamma/EgammaPhotonAlgos/interface/ConversionSeedFinder.h"
00023 #include "RecoEgamma/EgammaPhotonAlgos/interface/ConversionTrackFinder.h"
00024 //
00025 #include "RecoTracker/Record/interface/CkfComponentsRecord.h"
00026 #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"
00027 #include "RecoTracker/Record/interface/NavigationSchoolRecord.h"
00028 
00029 #include "RecoEgamma/EgammaPhotonAlgos/interface/OutInConversionSeedFinder.h"
00030 #include "RecoEgamma/EgammaPhotonAlgos/interface/InOutConversionSeedFinder.h"
00031 #include "RecoEgamma/EgammaPhotonAlgos/interface/OutInConversionTrackFinder.h"
00032 #include "RecoEgamma/EgammaPhotonAlgos/interface/InOutConversionTrackFinder.h"
00033 #include "Math/GenVector/VectorUtil.h"
00034 // Class header file
00035 #include "RecoEgamma/EgammaPhotonProducers/interface/SoftConversionTrackCandidateProducer.h"
00036 
00037 bool IsGoodSeed(const TrajectorySeedCollection& seeds, const TrajectorySeed& seed){
00038 
00039   // This function is not satisfactory. I don't know how to check equality of TrajectorySeed
00040   // So I compare all possible quantities in them.
00041   // This function can be dropped when I find to check equality of TrajectorySeed.
00042 
00043   bool found = false;
00044   for(TrajectorySeedCollection::const_iterator it = seeds.begin(); it != seeds.end(); it++){
00045     if(it->nHits() != seed.nHits()) continue;
00046     if(it->startingState().detId() != seed.startingState().detId()) continue;
00047     if(it->startingState().surfaceSide() != seed.startingState().surfaceSide()) continue;
00048     if((it->startingState().parameters().position() - seed.startingState().parameters().position()).mag() > 1.0e-6) continue;
00049     if((it->startingState().parameters().momentum() - seed.startingState().parameters().momentum()).mag() > 1.0e-6) continue;
00050     found = true;
00051     break;
00052   }
00053 
00054   return found;
00055 }
00056 
00057 SoftConversionTrackCandidateProducer::SoftConversionTrackCandidateProducer(const edm::ParameterSet& config) : 
00058   conf_(config), 
00059   theNavigationSchool_(0), 
00060   theOutInSeedFinder_(0), 
00061   theOutInTrackFinder_(0), 
00062   theInOutSeedFinder_(0),
00063   theInOutTrackFinder_(0)
00064 {
00065   LogDebug("SoftConversionTrackCandidateProducer") << "SoftConversionTrackCandidateProducer CTOR " << "\n";
00066   
00067   clusterType_                 = conf_.getParameter<std::string>("clusterType");
00068   clusterBarrelCollection_     = conf_.getParameter<edm::InputTag>("clusterBarrelCollection");
00069   clusterEndcapCollection_     = conf_.getParameter<edm::InputTag>("clusterEndcapCollection");
00070   
00071   OutInTrackCandidateCollection_ = conf_.getParameter<std::string>("outInTrackCandidateCollection");
00072   InOutTrackCandidateCollection_ = conf_.getParameter<std::string>("inOutTrackCandidateCollection");
00073 
00074   OutInTrackClusterAssociationCollection_ = conf_.getParameter<std::string>("outInTrackCandidateClusterAssociationCollection");
00075   InOutTrackClusterAssociationCollection_ = conf_.getParameter<std::string>("inOutTrackCandidateClusterAssociationCollection");
00076 
00077   // Register the product
00078   produces< TrackCandidateCollection > (OutInTrackCandidateCollection_);
00079   produces< TrackCandidateCollection > (InOutTrackCandidateCollection_);
00080   produces< reco::TrackCandidateCaloClusterPtrAssociation > ( OutInTrackClusterAssociationCollection_);
00081   produces< reco::TrackCandidateCaloClusterPtrAssociation > ( InOutTrackClusterAssociationCollection_);
00082 
00083 }
00084 
00085 SoftConversionTrackCandidateProducer::~SoftConversionTrackCandidateProducer() {
00086   delete theOutInSeedFinder_; 
00087   delete theOutInTrackFinder_;
00088   delete theInOutSeedFinder_;  
00089   delete theInOutTrackFinder_;
00090 }
00091 
00092 void  SoftConversionTrackCandidateProducer::setEventSetup (const edm::EventSetup & theEventSetup) {
00093   theOutInSeedFinder_->setEventSetup(theEventSetup);
00094   theInOutSeedFinder_->setEventSetup(theEventSetup);
00095   theOutInTrackFinder_->setEventSetup(theEventSetup);
00096   theInOutTrackFinder_->setEventSetup(theEventSetup);
00097 }
00098 
00099 
00100 
00101 void  SoftConversionTrackCandidateProducer::beginJob (edm::EventSetup const & theEventSetup) {
00102   nEvt_=0;
00103   //get magnetic field
00104   edm::LogInfo("SoftConversionTrackCandidateProducer") << " get magnetic field" << "\n";
00105   
00106   edm::ESHandle<NavigationSchool> nav;
00107   theEventSetup.get<NavigationSchoolRecord>().get("SimpleNavigationSchool", nav);
00108   theNavigationSchool_ = nav.product();
00109   
00110   // get the Out In Seed Finder  
00111   edm::LogInfo("SoftConversionTrackCandidateProducer") << " get the OutInSeedFinder" << "\n";
00112   theOutInSeedFinder_ = new OutInConversionSeedFinder (  conf_ );
00113   
00114   // get the Out In Track Finder
00115   edm::LogInfo("SoftConversionTrackCandidateProducer") << " get the OutInTrackFinder" << "\n";
00116   theOutInTrackFinder_ = new OutInConversionTrackFinder ( theEventSetup, conf_  );
00117   
00118   // get the In Out Seed Finder  
00119   edm::LogInfo("SoftConversionTrackCandidateProducer") << " get the InOutSeedFinder" << "\n";
00120   theInOutSeedFinder_ = new InOutConversionSeedFinder ( conf_ );
00121   
00122   // get the In Out Track Finder
00123   edm::LogInfo("SoftConversionTrackCandidateProducer") << " get the InOutTrackFinder" << "\n";
00124   theInOutTrackFinder_ = new InOutConversionTrackFinder ( theEventSetup, conf_  );
00125 }
00126 
00127 
00128 
00129 void SoftConversionTrackCandidateProducer::produce(edm::Event& theEvent, const edm::EventSetup& theEventSetup) {
00130   
00131   using namespace edm;
00132   nEvt_++;
00133   edm::LogInfo("SoftConversionTrackCandidateProducer") << "SoftConversionTrackCandidateProducer Analyzing event number: " << theEvent.id() << " Global Counter " << nEvt_ << "\n";
00134 
00135   std::cout << "SoftConversionTrackCandidateProducer Analyzing event number: " << theEvent.id() << " Global Counter " << nEvt_ << "\n";
00136   
00137   setEventSetup( theEventSetup );
00138   theOutInSeedFinder_->setEvent(theEvent);
00139   theInOutSeedFinder_->setEvent(theEvent);
00140   theOutInTrackFinder_->setEvent(theEvent);
00141   theInOutTrackFinder_->setEvent(theEvent);
00142 
00143   // Set the navigation school  
00144   NavigationSetter setter(*theNavigationSchool_);  
00145 
00146   // collections to be stored in events
00147   std::auto_ptr<TrackCandidateCollection> outInTrackCandidate_p(new TrackCandidateCollection); 
00148   std::auto_ptr<TrackCandidateCollection> inOutTrackCandidate_p(new TrackCandidateCollection); 
00149   std::auto_ptr<reco::TrackCandidateCaloClusterPtrAssociation> outInAssoc_p(new reco::TrackCandidateCaloClusterPtrAssociation);
00150   std::auto_ptr<reco::TrackCandidateCaloClusterPtrAssociation> inOutAssoc_p(new reco::TrackCandidateCaloClusterPtrAssociation);
00151    
00152   std::vector<edm::Ptr<reco::CaloCluster> > vecOfClusterRefForOutIn;
00153   std::vector<edm::Ptr<reco::CaloCluster> > vecOfClusterRefForInOut;
00154 
00155   // Get the basic cluster collection in the Barrel 
00156   edm::Handle<edm::View<reco::CaloCluster> > clusterBarrelHandle;
00157   theEvent.getByLabel(clusterBarrelCollection_, clusterBarrelHandle);
00158 
00159   if (!clusterBarrelHandle.isValid()) {
00160     edm::LogError("SoftConverionTrackCandidateProducer") << "Error! Can't get the product "<<clusterBarrelCollection_.label();
00161     return;
00162   }
00163   
00164   buildCollections(clusterBarrelHandle, *outInTrackCandidate_p, *inOutTrackCandidate_p, vecOfClusterRefForOutIn, vecOfClusterRefForInOut);
00165 
00166   if(clusterType_ == "BasicCluster" ) {
00167     // Get the basic cluster collection in the Endcap 
00168     edm::Handle<edm::View<reco::CaloCluster> > clusterEndcapHandle;
00169     theEvent.getByLabel(clusterEndcapCollection_, clusterEndcapHandle);
00170 
00171     if (!clusterEndcapHandle.isValid()) {
00172       edm::LogError("SoftConversionTrackCandidateProducer") << "Error! Can't get the product "<<clusterEndcapCollection_.label();
00173       return;
00174     }
00175 
00176     buildCollections(clusterEndcapHandle, *outInTrackCandidate_p, *inOutTrackCandidate_p, vecOfClusterRefForOutIn, vecOfClusterRefForInOut);
00177 
00178   }
00179 
00180   // put all products in the event
00181   const edm::OrphanHandle<TrackCandidateCollection> refprodOutInTrackC = theEvent.put( outInTrackCandidate_p, OutInTrackCandidateCollection_ );
00182   const edm::OrphanHandle<TrackCandidateCollection> refprodInOutTrackC = theEvent.put( inOutTrackCandidate_p, InOutTrackCandidateCollection_ );
00183 
00184   edm::ValueMap<reco::CaloClusterPtr>::Filler fillerOI(*outInAssoc_p);
00185   fillerOI.insert(refprodOutInTrackC, vecOfClusterRefForOutIn.begin(), vecOfClusterRefForOutIn.end());
00186   fillerOI.fill();
00187   edm::ValueMap<reco::CaloClusterPtr>::Filler fillerIO(*inOutAssoc_p);
00188   fillerIO.insert(refprodInOutTrackC, vecOfClusterRefForInOut.begin(), vecOfClusterRefForInOut.end());
00189   fillerIO.fill();
00190 
00191   theEvent.put( outInAssoc_p, OutInTrackClusterAssociationCollection_);
00192   theEvent.put( inOutAssoc_p, InOutTrackClusterAssociationCollection_);
00193 }
00194 
00195 
00196 void SoftConversionTrackCandidateProducer::buildCollections(const edm::Handle<edm::View<reco::CaloCluster> > & clusterHandle,
00197                                                             TrackCandidateCollection& outInTrackCandidates,
00198                                                             TrackCandidateCollection& inOutTrackCandidates,
00199                                                             std::vector<edm::Ptr<reco::CaloCluster> >& vecRecOI,
00200                                                             std::vector<edm::Ptr<reco::CaloCluster> >& vecRecIO) {
00201 
00202   // temporary collection
00203   TrackCandidateCollection tempTCC;
00204   TrajectorySeedCollection totalOISeeds; // total number of out-in trajectory seeds through entire cluster collection loop
00205   TrajectorySeedCollection totalIOSeeds; // total number of in-out trajectory seeds through entire cluster collection loop
00206 
00207   int nClusters = (int) clusterHandle->size();
00208 
00209   // first loop to fill totalOISeeds and totalIOSeeds
00210 
00211   for(int iCluster=0; iCluster<nClusters; iCluster++){
00212     reco::CaloClusterPtr clusterRefOutIn = clusterHandle->ptrAt(iCluster);
00213     math::XYZPoint position = clusterRefOutIn->position();
00214     GlobalPoint gp(position.x(),position.y(),position.z());
00215     theOutInSeedFinder_->setCandidate(clusterRefOutIn->energy(),gp);
00216     theOutInSeedFinder_->makeSeeds(clusterRefOutIn);
00217 
00218 
00219     TrajectorySeedCollection oISeeds = theOutInSeedFinder_->seeds();
00220     for(TrajectorySeedCollection::const_iterator it = oISeeds.begin(); it != oISeeds.end(); it++){
00221       totalOISeeds.push_back(*it);
00222     }
00223 
00224     std::vector<Trajectory> theOutInTracks= theOutInTrackFinder_->tracks(oISeeds, tempTCC);
00225     tempTCC.clear();
00226 
00227     for(int jCluster=iCluster; jCluster<nClusters; jCluster++){
00228       reco::CaloClusterPtr clusterRefInOut = clusterHandle->ptrAt(jCluster);
00229 
00230       math::XYZPoint position2 = clusterRefInOut->position();
00231       GlobalPoint gp2(position2.x(),position2.y(),position2.z());
00232       double dEta = std::abs(position.Eta() - position2.Eta());
00233       if(dEta > 0.1) continue;
00234 
00235       double dPhi = std::abs(ROOT::Math::VectorUtil::DeltaPhi(position, position2));
00236       if(dPhi > 0.5) continue;
00237 
00238       theInOutSeedFinder_->setCandidate(clusterRefInOut->energy(),gp2);
00239       theInOutSeedFinder_->setTracks(theOutInTracks);   
00240       theInOutSeedFinder_->makeSeeds(clusterHandle);
00241 
00242       TrajectorySeedCollection iOSeeds = theInOutSeedFinder_->seeds();
00243 
00244       for(TrajectorySeedCollection::const_iterator it = iOSeeds.begin(); it != iOSeeds.end(); it++){
00245         totalIOSeeds.push_back(*it);
00246       }
00247     
00248     }// for jCluster
00249   }// for iCluster
00250 
00251 
00252   // Now we have total OI/IO seeds. Let's clean them up and save them with only giving good trajectories
00253   TrajectorySeedCollection oIFilteredSeeds;
00254   TrajectorySeedCollection iOFilteredSeeds;
00255 
00256   tempTCC.clear();
00257   std::vector<Trajectory> tempTrj = theOutInTrackFinder_->tracks(totalOISeeds,tempTCC);
00258   for(std::vector<Trajectory>::iterator it = tempTrj.begin(); it!= tempTrj.end(); it++){
00259     oIFilteredSeeds.push_back(it->seed());
00260   }
00261 
00262   tempTrj.clear();
00263   tempTCC.clear();
00264   tempTrj = theInOutTrackFinder_->tracks(totalIOSeeds,tempTCC);
00265   for(std::vector<Trajectory>::iterator it = tempTrj.begin(); it!= tempTrj.end(); it++){
00266     iOFilteredSeeds.push_back(it->seed());
00267   }
00268 
00269   tempTCC.clear();
00270   tempTrj.clear();
00271   totalOISeeds.clear();
00272   totalIOSeeds.clear();
00273 
00274 
00275   // Now start normal procedure and consider seeds that belong to filtered ones.
00276 
00277   for(int iCluster=0; iCluster<nClusters; iCluster++){
00278     reco::CaloClusterPtr clusterRefOutIn = clusterHandle->ptrAt(iCluster);
00279     math::XYZPoint position = clusterRefOutIn->position();
00280     GlobalPoint gp(position.x(),position.y(),position.z());
00281     theOutInSeedFinder_->setCandidate(clusterRefOutIn->energy(),gp);
00282     theOutInSeedFinder_->makeSeeds(clusterRefOutIn);
00283 
00284     TrajectorySeedCollection oISeeds_all = theOutInSeedFinder_->seeds();
00285     TrajectorySeedCollection oISeeds;
00286     for(TrajectorySeedCollection::iterator it = oISeeds_all.begin(); it != oISeeds_all.end(); it++){
00287       if(IsGoodSeed(oIFilteredSeeds,*it)) oISeeds.push_back(*it);
00288     }
00289 
00290     if(oISeeds.size() == 0) continue;
00291 
00292     std::vector<Trajectory> theOutInTracks= theOutInTrackFinder_->tracks(oISeeds, outInTrackCandidates);
00293 
00294     int nOITrj = (int) theOutInTracks.size();
00295     for(int itrj=0; itrj < nOITrj; itrj++) vecRecOI.push_back( clusterRefOutIn );
00296 
00297     for(int jCluster=iCluster; jCluster<nClusters; jCluster++){
00298       reco::CaloClusterPtr clusterRefInOut = clusterHandle->ptrAt(jCluster);
00299 
00300       math::XYZPoint position2 = clusterRefInOut->position();
00301       GlobalPoint gp2(position2.x(),position2.y(),position2.z());
00302       double dEta = std::abs(position.Eta() - position2.Eta());
00303       if(dEta > 0.1) continue;
00304 
00305       double dPhi = std::abs(ROOT::Math::VectorUtil::DeltaPhi(position, position2));
00306       if(dPhi > 0.5) continue;
00307 
00308       theInOutSeedFinder_->setCandidate(clusterRefInOut->energy(),gp2);
00309       theInOutSeedFinder_->setTracks(theOutInTracks);   
00310       theInOutSeedFinder_->makeSeeds(clusterHandle);
00311     
00312       TrajectorySeedCollection iOSeeds_all = theInOutSeedFinder_->seeds();
00313       TrajectorySeedCollection iOSeeds;
00314       for(TrajectorySeedCollection::iterator it = iOSeeds_all.begin(); it != iOSeeds_all.end(); it++){
00315         if(IsGoodSeed(iOFilteredSeeds,*it)) iOSeeds.push_back(*it);
00316       }
00317 
00318       if(iOSeeds.size() == 0) continue;
00319 
00320       std::vector<Trajectory> theInOutTracks= theInOutTrackFinder_->tracks(iOSeeds, inOutTrackCandidates); 
00321 
00322       int nIOTrj = (int) theInOutTracks.size();
00323       for(int itrj=0; itrj < nIOTrj; itrj++) vecRecIO.push_back( clusterRefInOut );
00324 
00325     }// for jCluster
00326   }// for iCluster
00327 
00328 
00329 }
00330 

Generated on Tue Jun 9 17:43:27 2009 for CMSSW by  doxygen 1.5.4