CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/src/RecoParticleFlow/PFTracking/plugins/ElectronSeedMerger.cc

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Package:    PFTracking
00004 // Class:      ElectronSeedMerger
00005 // 
00006 // Original Author:  Michele Pioppi
00007 
00008 #include "RecoParticleFlow/PFTracking/interface/ElectronSeedMerger.h"
00009 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00010 #include "DataFormats/TrajectorySeed/interface/TrajectorySeed.h"
00011 #include "DataFormats/EgammaReco/interface/ElectronSeed.h"
00012 #include "DataFormats/EgammaReco/interface/ElectronSeedFwd.h"
00013 #include "DataFormats/TrajectorySeed/interface/PropagationDirection.h"
00014 #include "TrackingTools/Records/interface/TransientRecHitRecord.h"  
00015 #include <string>
00016 
00017 
00018 using namespace edm;
00019 using namespace std;
00020 using namespace reco;
00021 
00022 ElectronSeedMerger::ElectronSeedMerger(const ParameterSet& iConfig):
00023  conf_(iConfig)
00024 {
00025   LogInfo("ElectronSeedMerger")<<"Electron SeedMerger  started  ";
00026   
00027   
00028   ecalBasedSeeds_=iConfig.getParameter<InputTag>("EcalBasedSeeds");
00029   tkBasedSeeds_=iConfig.getParameter<InputTag>("TkBasedSeeds");
00030  
00031   produces<ElectronSeedCollection>();
00032 
00033 }
00034 
00035 
00036 ElectronSeedMerger::~ElectronSeedMerger()
00037 {
00038   
00039   // do anything here that needs to be done at desctruction time
00040   // (e.g. close files, deallocate resources etc.) 
00041 
00042 }
00043 
00044 
00045 //
00046 // member functions
00047 //
00048 
00049 // ------------ method called to produce the data  ------------
00050 void
00051 ElectronSeedMerger::produce(Event& iEvent, const EventSetup& iSetup)
00052 {
00053   //CREATE OUTPUT COLLECTION
00054   auto_ptr<ElectronSeedCollection> output(new ElectronSeedCollection);
00055 
00056   //HANDLE THE INPUT SEED COLLECTIONS
00057   Handle<ElectronSeedCollection> EcalBasedSeeds;
00058   iEvent.getByLabel(ecalBasedSeeds_,EcalBasedSeeds);
00059   ElectronSeedCollection ESeed = *(EcalBasedSeeds.product());
00060 
00061   Handle<ElectronSeedCollection> TkBasedSeeds;
00062   iEvent.getByLabel(tkBasedSeeds_,TkBasedSeeds);
00063   ElectronSeedCollection TSeed = *(TkBasedSeeds.product());
00064 
00065 
00066   //VECTOR FOR MATCHED SEEDS
00067   vector<bool> TSeedMatched;
00068   for (unsigned int it=0;it<TSeed.size();it++){
00069     TSeedMatched.push_back(false);
00070   } 
00071 
00072 
00073   //LOOP OVER THE ECAL SEED COLLECTION
00074   ElectronSeedCollection::const_iterator e_beg= ESeed.begin();
00075   ElectronSeedCollection::const_iterator e_end= ESeed.end();
00076   for (;e_beg!=e_end;++e_beg){
00077 
00078     ElectronSeed NewSeed=*(e_beg);
00079     bool AlreadyMatched =false;
00080     
00081     //LOOP OVER THE TK SEED COLLECTION
00082     for (unsigned int it=0;it<TSeed.size();it++){
00083       if (AlreadyMatched) continue;
00084 
00085       //HITS FOR ECAL SEED 
00086       TrajectorySeed::const_iterator eh = e_beg->recHits().first;
00087       TrajectorySeed::const_iterator eh_end = e_beg->recHits().second;
00088 
00089       //HITS FOR TK SEED 
00090       unsigned int hitShared=0;
00091       unsigned int hitSeed=0;
00092       for (;eh!=eh_end;++eh){
00093 
00094         if (!eh->isValid()) continue;
00095         hitSeed++;
00096         bool Shared=false;
00097         TrajectorySeed::const_iterator th = TSeed[it].recHits().first;
00098         TrajectorySeed::const_iterator th_end = TSeed[it].recHits().second;
00099         for (;th!=th_end;++th){
00100           if (!th->isValid()) continue;
00101           //CHECK THE HIT COMPATIBILITY: put back sharesInput 
00102           // as soon Egamma solves the bug on the seed collection
00103           if (eh->sharesInput(&(*th),TrackingRecHit::all)) Shared = true;
00104         //   if(eh->geographicalId() == th->geographicalId() &&
00105 //           (eh->localPosition() - th->localPosition()).mag() < 0.001) Shared=true;
00106         }
00107         if (Shared) hitShared++;
00108       }     
00109       if (hitShared==hitSeed){
00110         AlreadyMatched=true;
00111         TSeedMatched[it]=true;
00112         NewSeed.setCtfTrack(TSeed[it].ctfTrack());
00113       }
00114       if ( hitShared == (hitSeed-1)){
00115         NewSeed.setCtfTrack(TSeed[it].ctfTrack());
00116       }
00117     }
00118 
00119     output->push_back(NewSeed);
00120   }
00121   
00122   //FILL THE COLLECTION WITH UNMATCHED TK-BASED SEED
00123   for (unsigned int it=0;it<TSeed.size();it++){
00124     if (!TSeedMatched[it])  output->push_back(TSeed[it]);
00125   }
00126   
00127   //PUT THE MERGED COLLECTION IN THE EVENT
00128   iEvent.put(output);
00129   
00130 }