![]() |
![]() |
00001 // -*- C++ -*- 00002 // 00003 // Package: RecHitCorrector 00004 // Class: RecHitCorrector 00005 // 00013 // 00014 // Original Author: Hans Van Haevermaet 00015 // Created: Wed Feb 23 11:29:43 CET 2011 00016 // $Id: RecHitCorrector.cc,v 1.1 2011/02/24 09:45:08 hvanhaev Exp $ 00017 // 00018 // 00019 00020 00021 // system include files 00022 #include <memory> 00023 00024 // user include files 00025 #include "FWCore/Framework/interface/Frameworkfwd.h" 00026 #include "FWCore/Framework/interface/EDProducer.h" 00027 00028 #include "FWCore/Framework/interface/Event.h" 00029 #include "FWCore/Framework/interface/MakerMacros.h" 00030 #include "FWCore/Framework/interface/ESHandle.h" 00031 #include "FWCore/Framework/interface/EventSetup.h" 00032 00033 #include "FWCore/ParameterSet/interface/ParameterSet.h" 00034 00035 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h" 00036 #include "CalibFormats/CastorObjects/interface/CastorCoderDb.h" 00037 #include "CalibFormats/CastorObjects/interface/CastorCalibrations.h" 00038 #include "CalibFormats/CastorObjects/interface/CastorDbService.h" 00039 #include "CalibFormats/CastorObjects/interface/CastorDbRecord.h" 00040 00041 00042 // 00043 // class declaration 00044 // 00045 00046 class RecHitCorrector : public edm::EDProducer { 00047 public: 00048 explicit RecHitCorrector(const edm::ParameterSet&); 00049 ~RecHitCorrector(); 00050 00051 private: 00052 virtual void beginJob() ; 00053 virtual void produce(edm::Event&, const edm::EventSetup&); 00054 virtual void endJob() ; 00055 00056 // ----------member data --------------------------- 00057 edm::InputTag inputLabel_; 00058 double factor_; 00059 }; 00060 00061 // 00062 // constants, enums and typedefs 00063 // 00064 00065 00066 // 00067 // static data member definitions 00068 // 00069 00070 // 00071 // constructors and destructor 00072 // 00073 RecHitCorrector::RecHitCorrector(const edm::ParameterSet& iConfig): 00074 inputLabel_(iConfig.getParameter<edm::InputTag>("rechitLabel")), 00075 factor_(iConfig.getParameter<double>("revertFactor")) 00076 { 00077 //register your products 00078 produces<CastorRecHitCollection>(); 00079 //now do what ever other initialization is needed 00080 00081 } 00082 00083 00084 RecHitCorrector::~RecHitCorrector() 00085 { 00086 00087 // do anything here that needs to be done at desctruction time 00088 // (e.g. close files, deallocate resources etc.) 00089 00090 } 00091 00092 00093 // 00094 // member functions 00095 // 00096 00097 // ------------ method called to produce the data ------------ 00098 void 00099 RecHitCorrector::produce(edm::Event& iEvent, const edm::EventSetup& iSetup) 00100 { 00101 using namespace edm; 00102 00103 edm::Handle<CastorRecHitCollection> rechits; 00104 iEvent.getByLabel(inputLabel_,rechits); 00105 00106 // get conditions 00107 edm::ESHandle<CastorDbService> conditions; 00108 iSetup.get<CastorDbRecord>().get(conditions); 00109 00110 if (!rechits.isValid()) std::cout << "No valid CastorRecHitCollection found, please check the InputLabel..." << std::endl; 00111 00112 CastorCalibrations calibrations; 00113 00114 std::auto_ptr<CastorRecHitCollection> rec(new CastorRecHitCollection); 00115 00116 for (unsigned int i=0;i<rechits->size();i++) { 00117 CastorRecHit rechit = (*rechits)[i]; 00118 //std::cout << "rechit energy = " << rechit.energy() << std::endl; 00119 double fC = factor_*rechit.energy(); 00120 double time = rechit.time(); 00121 //std::cout << "rechit energy(fC) = " << fC << " time = " << time << std::endl; 00122 00123 // do proper gain calibration reading the latest entries in the condDB 00124 const CastorCalibrations& calibrations=conditions->getCastorCalibrations(rechit.id()); 00125 int capid = 0; // take some capid 00126 double correctedenergy = fC*calibrations.gain(capid); 00127 //std::cout << " correctedenergy = " << correctedenergy << " gain = " << calibrations.gain(capid) << std::endl; 00128 00129 CastorRecHit *correctedhit = new CastorRecHit(rechit.id(),correctedenergy,time); 00130 rec->push_back(*correctedhit); 00131 } 00132 00133 iEvent.put(rec); 00134 00135 } 00136 00137 // ------------ method called once each job just before starting event loop ------------ 00138 void 00139 RecHitCorrector::beginJob() 00140 { 00141 } 00142 00143 // ------------ method called once each job just after ending the event loop ------------ 00144 void 00145 RecHitCorrector::endJob() { 00146 } 00147 00148 //define this as a plug-in 00149 DEFINE_FWK_MODULE(RecHitCorrector);