CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoLocalCalo/CaloRecCandCreator/src/CaloRecHitCandidateProducer.cc

Go to the documentation of this file.
00001 //
00002 // Producer to converts ECAL and HCAL hits into Candidates
00003 // Author: F. Ratnikov (Maryland)
00004 // Jan. 7, 2007
00005 //
00006 
00007 #include "CaloRecHitCandidateProducer.h"
00008 
00009 #include "FWCore/Framework/interface/Event.h"
00010 #include "DataFormats/Math/interface/Vector3D.h"
00011 
00012 #include "DataFormats/RecoCandidate/interface/CaloRecHitCandidate.h"
00013 #include "DataFormats/Candidate/interface/CandidateFwd.h"
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "FWCore/Framework/interface/ESHandle.h"
00016 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00017 #include "Geometry/CaloGeometry/interface/CaloGeometry.h"
00018 #include "Geometry/CaloGeometry/interface/CaloSubdetectorGeometry.h"
00019 #include "Geometry/CaloGeometry/interface/CaloCellGeometry.h"
00020 #include "Geometry/CaloTopology/interface/HcalTopology.h"
00021 
00022 #include "DataFormats/HcalDetId/interface/HcalDetId.h"
00023 #include "DataFormats/EcalDetId/interface/EcalSubdetector.h"
00024 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00025 #include "DataFormats/EcalRecHit/interface/EcalRecHitCollections.h"
00026 
00027 using namespace edm;
00028 using namespace reco;
00029 using namespace std;
00030 
00031 namespace {
00032   template <class HitCollection>
00033   void processHits (const edm::Handle<HitCollection>& fInput, 
00034                     const CaloRecHitCandidateProducer& fProducer,
00035                     const CaloGeometry& fGeometry,
00036                     const HcalTopology& fTopology,
00037                     CandidateCollection* fOutput) { 
00038     const CaloSubdetectorGeometry* geometry = 0; // cache
00039     DetId geometryId (0);
00040     
00041     size_t size = fInput->size();
00042     for (unsigned ihit = 0; ihit < size; ihit++) {
00043       const CaloRecHit* hit = &((*fInput)[ihit]);
00044       double weight = fProducer.cellTresholdAndWeight (*hit, fTopology);
00045       if (weight > 0) { // accept hit
00046         DetId cell = hit->detid ();
00047         // get geometry
00048         if (cell.det() != geometryId.det() || cell.subdetId() != geometryId.subdetId()) {
00049           geometry = fGeometry.getSubdetectorGeometry (cell);
00050           geometryId = cell;
00051         }
00052         const CaloCellGeometry* cellGeometry = geometry->getGeometry (cell);
00053         double eta = cellGeometry->getPosition().eta ();
00054         double phi =  cellGeometry->getPosition().phi ();
00055         double energy = hit->energy() * weight;
00056         math::RhoEtaPhiVector p( 1, eta, phi );
00057         p *= ( energy / p.r() );
00058         CaloRecHitCandidate * c = new CaloRecHitCandidate( Candidate::LorentzVector( p.x(), p.y(), p.z(), energy ) );
00059         c->setCaloRecHit( RefToBase<CaloRecHit>( Ref<HitCollection>( fInput, ihit ) ) );
00060         fOutput->push_back( c );
00061       }
00062     }
00063   } 
00064 }
00065 
00066 
00067 CaloRecHitCandidateProducer::CaloRecHitCandidateProducer ( const edm::ParameterSet & fConfig ) 
00068   :  mHBHELabel (fConfig.getParameter<edm::InputTag>("hbheInput")),
00069      mHOLabel (fConfig.getParameter<edm::InputTag>("hoInput")),
00070      mHFLabel (fConfig.getParameter<edm::InputTag>("hfInput")),
00071      mEcalLabels (fConfig.getParameter<std::vector<edm::InputTag> >("ecalInputs")),
00072      mAllowMissingInputs (fConfig.getUntrackedParameter<bool>("AllowMissingInputs",false)),
00073      mUseHO (fConfig.getParameter<bool>("UseHO")),
00074 
00075      mEBthreshold (fConfig.getParameter<double>("EBThreshold")),
00076      mEEthreshold  (fConfig.getParameter<double>("EEThreshold")),
00077      mHBthreshold  (fConfig.getParameter<double>("HBThreshold")),
00078      mHESthreshold  (fConfig.getParameter<double>("HESThreshold")),
00079      mHEDthreshold  (fConfig.getParameter<double>("HEDThreshold")),
00080      mHOthreshold (fConfig.getParameter<double>("HOThreshold")),
00081      mHF1threshold (fConfig.getParameter<double>("HF1Threshold")),
00082      mHF2threshold (fConfig.getParameter<double>("HF2Threshold")),
00083      mEBweight (fConfig.getParameter<double>("EBWeight")),
00084      mEEweight (fConfig.getParameter<double>("EEWeight")),
00085      mHBweight (fConfig.getParameter<double>("HBWeight")),
00086      mHESweight (fConfig.getParameter<double>("HESWeight")),
00087      mHEDweight (fConfig.getParameter<double>("HEDWeight")),
00088      mHOweight (fConfig.getParameter<double>("HOWeight")),
00089      mHF1weight (fConfig.getParameter<double>("HF1Weight")),
00090      mHF2weight (fConfig.getParameter<double>("HF2Weight"))
00091 {
00092   produces<CandidateCollection>();
00093 }
00094 
00095 void CaloRecHitCandidateProducer::produce( edm::Event & fEvent, const edm::EventSetup & fSetup) {
00096   // get geometry
00097   //  const IdealGeometryRecord& record = fSetup.template get<IdealGeometryRecord>();
00098   const CaloGeometryRecord& caloRecord = fSetup.get<CaloGeometryRecord>();
00099   ESHandle<CaloGeometry> geometry;
00100   caloRecord.get (geometry);
00101   const IdealGeometryRecord& record = fSetup.get<IdealGeometryRecord>();
00102   ESHandle<HcalTopology> topology;
00103   record.get (topology);
00104   // set Output
00105   auto_ptr<CandidateCollection> output ( new CandidateCollection );
00106   // get and process Inputs
00107   edm::Handle<HBHERecHitCollection> hbhe;
00108   fEvent.getByLabel(mHBHELabel,hbhe);
00109   if (!hbhe.isValid()) {
00110     // can't find it!
00111     if (!mAllowMissingInputs) {
00112       *hbhe;  // will throw the proper exception
00113     }
00114   } else {
00115     processHits (hbhe, *this, *geometry, *topology, &*output);
00116   }
00117 
00118   if (mUseHO) {
00119     edm::Handle<HORecHitCollection> ho;
00120     fEvent.getByLabel(mHOLabel,ho);
00121     if (!ho.isValid()) {
00122       // can't find it!
00123       if (!mAllowMissingInputs) {
00124         *ho;  // will throw the proper exception        
00125       }
00126     } else {
00127       processHits (ho, *this, *geometry, *topology, &*output);
00128     }
00129   }
00130 
00131   edm::Handle<HFRecHitCollection> hf;
00132   fEvent.getByLabel(mHFLabel,hf);
00133   if (!hf.isValid()) {
00134     // can't find it!
00135     if (!mAllowMissingInputs) {
00136       *hf;  // will throw the proper exception
00137     }
00138   } else {
00139     processHits (hf, *this, *geometry, *topology, &*output);
00140   }
00141 
00142   std::vector<edm::InputTag>::const_iterator i;
00143   for (i=mEcalLabels.begin(); i!=mEcalLabels.end(); i++) {
00144     edm::Handle<EcalRecHitCollection> ec;
00145     fEvent.getByLabel(*i,ec);
00146     if (!ec.isValid()) {
00147       // can't find it!
00148       if (!mAllowMissingInputs) {
00149         *ec;  // will throw the proper exception
00150       }
00151     } else {
00152       processHits (ec, *this, *geometry, *topology, &*output);
00153     }
00154   }
00155   fEvent.put(output);
00156 }
00157 
00158 double CaloRecHitCandidateProducer::cellTresholdAndWeight (const CaloRecHit& fHit, const HcalTopology& fTopology) const {
00159   double weight = 0;
00160   double threshold = 0;
00161   DetId detId = fHit.detid ();
00162   DetId::Detector det = detId.det ();
00163   if(det == DetId::Ecal) {
00164     // may or may not be EB.  We'll find out.
00165     
00166     EcalSubdetector subdet = (EcalSubdetector)(detId.subdetId());
00167     if(subdet == EcalBarrel) {
00168       threshold = mEBthreshold;
00169       weight = mEBweight;
00170     }
00171     else if(subdet == EcalEndcap) {
00172       threshold = mEEthreshold;
00173       weight = mEEweight;
00174     }
00175   }
00176   else if(det == DetId::Hcal) {
00177     HcalDetId hcalDetId(detId);
00178     HcalSubdetector subdet = hcalDetId.subdet();
00179     
00180     if(subdet == HcalBarrel) {
00181       threshold = mHBthreshold;
00182       weight = mHBweight;
00183     }
00184     
00185     else if(subdet == HcalEndcap) {
00186       // check if it's single or double tower
00187       if(hcalDetId.ietaAbs() < fTopology.firstHEDoublePhiRing()) {
00188         threshold = mHESthreshold;
00189         weight = mHESweight;
00190       }
00191       else {
00192         threshold = mHEDthreshold;
00193         weight = mHEDweight;
00194       }
00195     } else if(subdet == HcalOuter) {
00196       threshold = mHOthreshold;
00197       weight = mHOweight;
00198     } else if(subdet == HcalForward) {
00199       if(hcalDetId.depth() == 1) {
00200         threshold = mHF1threshold;
00201         weight = mHF1weight;
00202       } else {
00203         threshold = mHF2threshold;
00204         weight = mHF2weight;
00205       }
00206     }
00207   }
00208   return fHit.energy () >= threshold ? weight : 0; 
00209 }
00210 
00211