CMS 3D CMS Logo

Public Member Functions | Private Member Functions | Private Attributes

ElectronRegressionEnergyProducer Class Reference

Inheritance diagram for ElectronRegressionEnergyProducer:
edm::EDFilter edm::ProducerBase edm::ProductRegistryHelper

List of all members.

Public Member Functions

 ElectronRegressionEnergyProducer (const edm::ParameterSet &)
 ~ElectronRegressionEnergyProducer ()

Private Member Functions

virtual bool filter (edm::Event &, const edm::EventSetup &)

Private Attributes

const CaloGeometrycaloGeometry_
const CaloTopologyecalTopology_
edm::InputTag electronTag_
uint32_t energyRegressionType_
bool geomInitialized_
std::string nameEnergyErrorReg_
std::string nameEnergyReg_
bool printDebug_
edm::InputTag recHitCollectionEB_
edm::InputTag recHitCollectionEE_
ElectronEnergyRegressionEvaluateregressionEvaluator
std::string regressionInputFile_

Detailed Description

Definition at line 35 of file ElectronRegressionEnergyProducer.cc.


Constructor & Destructor Documentation

ElectronRegressionEnergyProducer::ElectronRegressionEnergyProducer ( const edm::ParameterSet iConfig) [explicit]

Definition at line 65 of file ElectronRegressionEnergyProducer.cc.

References edm::ParameterSet::getParameter(), edm::ParameterSet::getUntrackedParameter(), ElectronEnergyRegressionEvaluate::kNoTrkVar, ElectronEnergyRegressionEvaluate::kWithSubCluVar, ElectronEnergyRegressionEvaluate::kWithTrkVarV1, and ElectronEnergyRegressionEvaluate::kWithTrkVarV2.

                                                                                                 {
  printDebug_  = iConfig.getUntrackedParameter<bool>("printDebug", false);
  electronTag_ = iConfig.getParameter<edm::InputTag>("electronTag");
  
  regressionInputFile_  = iConfig.getParameter<std::string>("regressionInputFile");
  energyRegressionType_ = iConfig.getParameter<uint32_t>("energyRegressionType");

  nameEnergyReg_      = iConfig.getParameter<std::string>("nameEnergyReg");
  nameEnergyErrorReg_ = iConfig.getParameter<std::string>("nameEnergyErrorReg");

  recHitCollectionEB_ = iConfig.getParameter<edm::InputTag>("recHitCollectionEB");
  recHitCollectionEE_ = iConfig.getParameter<edm::InputTag>("recHitCollectionEE");

  produces<edm::ValueMap<double> >(nameEnergyReg_);
  produces<edm::ValueMap<double> >(nameEnergyErrorReg_);

  regressionEvaluator = new ElectronEnergyRegressionEvaluate();

  //set regression type
  ElectronEnergyRegressionEvaluate::ElectronEnergyRegressionType type = ElectronEnergyRegressionEvaluate::kNoTrkVar;
  if (energyRegressionType_ == 1) type = ElectronEnergyRegressionEvaluate::kNoTrkVar;
  else if (energyRegressionType_ == 2) type = ElectronEnergyRegressionEvaluate::kWithSubCluVar;
  else if (energyRegressionType_ == 3) type = ElectronEnergyRegressionEvaluate::kWithTrkVarV1;
  else if (energyRegressionType_ == 4) type = ElectronEnergyRegressionEvaluate::kWithTrkVarV2;

  //load weights and initialize
  regressionEvaluator->initialize(regressionInputFile_.c_str(),type);

  geomInitialized_ = false;

}
ElectronRegressionEnergyProducer::~ElectronRegressionEnergyProducer ( )

Definition at line 98 of file ElectronRegressionEnergyProducer.cc.

{
  delete regressionEvaluator;
}

Member Function Documentation

bool ElectronRegressionEnergyProducer::filter ( edm::Event iEvent,
const edm::EventSetup iSetup 
) [private, virtual]

Implements edm::EDFilter.

Definition at line 104 of file ElectronRegressionEnergyProducer.cc.

References relval_parameters_module::energy, error, edm::helper::Filler< Map >::fill(), edm::EventSetup::get(), edm::Event::getByLabel(), edm::helper::Filler< Map >::insert(), edm::Handle< T >::product(), edm::Event::put(), and rho.

                                                                                           {

  assert(regressionEvaluator->isInitialized());

  if (!geomInitialized_) {
    edm::ESHandle<CaloTopology> theCaloTopology;
    iSetup.get<CaloTopologyRecord>().get(theCaloTopology);
    ecalTopology_ = & (*theCaloTopology);
    
    edm::ESHandle<CaloGeometry> theCaloGeometry;
    iSetup.get<CaloGeometryRecord>().get(theCaloGeometry); 
    caloGeometry_ = & (*theCaloGeometry);
    geomInitialized_ = true;
  }
  
  std::auto_ptr<edm::ValueMap<double> > regrEnergyMap(new edm::ValueMap<double>() );
  edm::ValueMap<double>::Filler energyFiller(*regrEnergyMap);

  std::auto_ptr<edm::ValueMap<double> > regrEnergyErrorMap(new edm::ValueMap<double>() );
  edm::ValueMap<double>::Filler energyErrorFiller(*regrEnergyErrorMap);
  
  Handle<reco::GsfElectronCollection> egCollection;
  iEvent.getByLabel(electronTag_,egCollection);
  const reco::GsfElectronCollection egCandidates = (*egCollection.product());

  std::vector<double> energyValues;
  std::vector<double> energyErrorValues;
  energyValues.reserve(egCollection->size());
  energyErrorValues.reserve(egCollection->size());
  //
  //**************************************************************************
  // Rechits
  //**************************************************************************
  edm::Handle< EcalRecHitCollection > pEBRecHits;
  edm::Handle< EcalRecHitCollection > pEERecHits;
  iEvent.getByLabel( recHitCollectionEB_, pEBRecHits );
  iEvent.getByLabel( recHitCollectionEE_, pEERecHits );

  //**************************************************************************
  //Get Number of Vertices
  //**************************************************************************
  Handle<reco::VertexCollection> hVertexProduct;
  iEvent.getByLabel(edm::InputTag("offlinePrimaryVertices"),hVertexProduct);
  const reco::VertexCollection inVertices = *(hVertexProduct.product());  

  // loop through all vertices
  Int_t nvertices = 0;
  for (reco::VertexCollection::const_iterator inV = inVertices.begin(); 
       inV != inVertices.end(); ++inV) {
    
    // pass these vertex cuts
    if (inV->ndof() >= 4
        && inV->position().Rho() <= 2.0
        && fabs(inV->z()) <= 24.0
      ) {
      nvertices++;
    }
  }

  //**************************************************************************
  //Get Rho
  //**************************************************************************
  double rho = 0;
  Handle<double> hRhoKt6PFJets;
  iEvent.getByLabel(edm::InputTag("kt6PFJets","rho"), hRhoKt6PFJets);
  rho = (*hRhoKt6PFJets);


  for ( reco::GsfElectronCollection::const_iterator egIter = egCandidates.begin(); 
        egIter != egCandidates.end(); ++egIter) {

    const EcalRecHitCollection * recHits=0;
    if(egIter->isEB()) 
        recHits = pEBRecHits.product();
    else 
        recHits = pEERecHits.product();

    SuperClusterHelper mySCHelper(&(*egIter),recHits,ecalTopology_,caloGeometry_);

    double energy=regressionEvaluator->calculateRegressionEnergy(&(*egIter),
                                                          mySCHelper,
                                                          rho,nvertices,
                                                          printDebug_);
    
    double error=regressionEvaluator->calculateRegressionEnergyUncertainty(&(*egIter),
                                                                    mySCHelper,
                                                                    rho,nvertices,
                                                                    printDebug_);

    energyValues.push_back(energy);
    energyErrorValues.push_back(error);

  }

  energyFiller.insert( egCollection, energyValues.begin(), energyValues.end() );  
  energyFiller.fill();

  energyErrorFiller.insert( egCollection, energyErrorValues.begin(), energyErrorValues.end() );  
  energyErrorFiller.fill();
  
  iEvent.put(regrEnergyMap,nameEnergyReg_);
  iEvent.put(regrEnergyErrorMap,nameEnergyErrorReg_);
  
  return true;

}

Member Data Documentation

Definition at line 55 of file ElectronRegressionEnergyProducer.cc.

Definition at line 54 of file ElectronRegressionEnergyProducer.cc.

Definition at line 44 of file ElectronRegressionEnergyProducer.cc.

Definition at line 47 of file ElectronRegressionEnergyProducer.cc.

Definition at line 52 of file ElectronRegressionEnergyProducer.cc.

Definition at line 50 of file ElectronRegressionEnergyProducer.cc.

Definition at line 49 of file ElectronRegressionEnergyProducer.cc.

Definition at line 43 of file ElectronRegressionEnergyProducer.cc.

Definition at line 57 of file ElectronRegressionEnergyProducer.cc.

Definition at line 58 of file ElectronRegressionEnergyProducer.cc.

Definition at line 60 of file ElectronRegressionEnergyProducer.cc.

Definition at line 46 of file ElectronRegressionEnergyProducer.cc.