CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/PhysicsTools/TagAndProbe/plugins/ElectronConversionRejectionVars.cc

Go to the documentation of this file.
00001 //
00002 
00013 #include "FWCore/Framework/interface/EDProducer.h"
00014 #include "FWCore/Framework/interface/Event.h"
00015 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00016 #include "FWCore/Utilities/interface/InputTag.h"
00017 
00018 #include "DataFormats/Common/interface/ValueMap.h"
00019 #include "DataFormats/Common/interface/View.h"
00020 
00021 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00022 #include "DataFormats/Candidate/interface/Candidate.h"
00023 #include "DataFormats/TrackReco/interface/Track.h"
00024 #include "RecoEgamma/EgammaTools/interface/ConversionFinder.h"
00025 #include "MagneticField/Records/interface/IdealMagneticFieldRecord.h"
00026 #include "MagneticField/Engine/interface/MagneticField.h"
00027 #include "DataFormats/TrackReco/interface/TrackExtra.h"
00028 #include "DataFormats/Scalers/interface/DcsStatus.h"
00029 #include "DataFormats/EgammaCandidates/interface/GsfElectron.h"
00030 #include "DataFormats/EgammaCandidates/interface/GsfElectronFwd.h"
00031 
00032 
00033 class ElectronConversionRejectionVars : public edm::EDProducer {
00034     public:
00035         explicit ElectronConversionRejectionVars(const edm::ParameterSet & iConfig);
00036         virtual ~ElectronConversionRejectionVars() ;
00037 
00038         virtual void produce(edm::Event & iEvent, const edm::EventSetup & iSetup);
00039 
00040     private:
00041         edm::InputTag probes_;            
00042 };
00043 
00044 ElectronConversionRejectionVars::ElectronConversionRejectionVars(const edm::ParameterSet & iConfig) :
00045     probes_(iConfig.getParameter<edm::InputTag>("probes"))
00046 {
00047     produces<edm::ValueMap<float> >("dist");
00048     produces<edm::ValueMap<float> >("dcot");
00049     produces<edm::ValueMap<float> >("convradius");
00050     produces<edm::ValueMap<float> >("passConvRej");
00051 }
00052 
00053 
00054 ElectronConversionRejectionVars::~ElectronConversionRejectionVars()
00055 {
00056 }
00057 
00058 void 
00059 ElectronConversionRejectionVars::produce(edm::Event & iEvent, const edm::EventSetup & iSetup) {
00060     using namespace edm;
00061 
00062     // read input
00063     Handle<View<reco::Candidate> > probes;
00064     edm::Handle<reco::TrackCollection> tracks_h;
00065     edm::Handle<reco::GsfElectronCollection> elHandle;
00066 
00067     iEvent.getByLabel(probes_,  probes);
00068     iEvent.getByLabel("generalTracks", tracks_h );
00069     iEvent.getByLabel("gsfElectrons", elHandle);
00070     
00071     float evt_bField = 3.8;
00072 
00073 
00074     // prepare vector for output   
00075     std::vector<float> values;
00076     std::vector<float> values2;
00077     std::vector<float> values3;
00078     std::vector<float> values4;
00079 
00080     // fill: use brute force    
00081     double dist = 0.0;
00082     double dcot = 0.0;
00083     double convradius = 0.0;
00084     double passConvRej = 0.0;
00085     ConversionFinder convFinder;
00086 
00087     View<reco::Candidate>::const_iterator probe, endprobes = probes->end(); 
00088     const reco::GsfElectronCollection* electronCollection = elHandle.product();
00089     reco::GsfElectronCollection::const_iterator eleIt = electronCollection->begin();
00090 
00091     for (probe = probes->begin(); probe != endprobes; ++probe) {
00092       for (eleIt=electronCollection->begin(); eleIt!=electronCollection->end(); eleIt++) {
00093         if( fabs(eleIt->et() - probe->et() ) < 0.05 && fabs(eleIt->eta() - probe->eta() ) < 0.01 
00094             && fabs(eleIt->phi() - probe->phi() ) < 0.01 ){
00095           //we have a match    
00096           ConversionInfo convInfo = convFinder.getConversionInfo(*eleIt, tracks_h, evt_bField);
00097           dist = convInfo.dist();
00098           dcot = convInfo.dcot();
00099           convradius = convInfo.radiusOfConversion();
00100           if( fabs(dist)>0.02 && fabs(dcot)>0.02)  passConvRej = 1.0;
00101           break; //got our guy, so break  
00102         }
00103       }
00104       values.push_back(dist);
00105       values2.push_back(dcot);
00106       values3.push_back(convradius);
00107       values4.push_back(passConvRej);
00108     }
00109 
00110 
00111     // convert into ValueMap and store
00112     std::auto_ptr<ValueMap<float> > valMap(new ValueMap<float>());
00113     ValueMap<float>::Filler filler(*valMap);
00114     filler.insert(probes, values.begin(), values.end());
00115     filler.fill();
00116     iEvent.put(valMap, "dist");
00117 
00118 
00119     // ---> same for dcot   
00120     std::auto_ptr<ValueMap<float> > valMap2(new ValueMap<float>());
00121     ValueMap<float>::Filler filler2(*valMap2);
00122     filler2.insert(probes, values2.begin(), values2.end());
00123     filler2.fill();
00124     iEvent.put(valMap2, "dcot");
00125 
00126     // ---> same for convradius   
00127     std::auto_ptr<ValueMap<float> > valMap3(new ValueMap<float>());
00128     ValueMap<float>::Filler filler3(*valMap3);
00129     filler3.insert(probes, values3.begin(), values3.end());
00130     filler3.fill();
00131     iEvent.put(valMap3, "convradius");
00132 
00133 
00134     // ---> same for passConvRej  
00135     std::auto_ptr<ValueMap<float> > valMap4(new ValueMap<float>());
00136     ValueMap<float>::Filler filler4(*valMap4);
00137     filler4.insert(probes, values4.begin(), values4.end());
00138     filler4.fill();
00139     iEvent.put(valMap4, "passConvRej");
00140 }
00141 
00142 
00143 #include "FWCore/Framework/interface/MakerMacros.h"
00144 DEFINE_FWK_MODULE(ElectronConversionRejectionVars);