00001 using namespace std;
00002 #include "HcalSimpleReconstructor.h"
00003 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00004 #include "DataFormats/HcalRecHit/interface/HcalRecHitCollections.h"
00005 #include "DataFormats/Common/interface/EDCollection.h"
00006 #include "DataFormats/Common/interface/Handle.h"
00007 #include "FWCore/Framework/interface/Selector.h"
00008 #include "FWCore/Framework/interface/ESHandle.h"
00009 #include "FWCore/Framework/interface/EventSetup.h"
00010 #include "CalibFormats/HcalObjects/interface/HcalCoderDb.h"
00011 #include "CalibFormats/HcalObjects/interface/HcalCalibrations.h"
00012 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00013 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00014
00015 #include <iostream>
00016
00017
00018 HcalSimpleReconstructor::HcalSimpleReconstructor(edm::ParameterSet const& conf):
00019 reco_(conf.getParameter<int>("firstSample"),conf.getParameter<int>("samplesToAdd"),conf.getParameter<bool>("correctForTimeslew"),
00020 conf.getParameter<bool>("correctForPhaseContainment"),conf.getParameter<double>("correctionPhaseNS")),
00021 det_(DetId::Hcal),
00022 inputLabel_(conf.getParameter<edm::InputTag>("digiLabel"))
00023 {
00024 std::string subd=conf.getParameter<std::string>("Subdetector");
00025 if (!strcasecmp(subd.c_str(),"HBHE")) {
00026 subdet_=HcalBarrel;
00027 produces<HBHERecHitCollection>();
00028 } else if (!strcasecmp(subd.c_str(),"HO")) {
00029 subdet_=HcalOuter;
00030 produces<HORecHitCollection>();
00031 } else if (!strcasecmp(subd.c_str(),"HF")) {
00032 subdet_=HcalForward;
00033 produces<HFRecHitCollection>();
00034 } else if (!strcasecmp(subd.c_str(),"ZDC")) {
00035 det_=DetId::Calo;
00036 subdet_=HcalZDCDetId::SubdetectorId;
00037 produces<ZDCRecHitCollection>();
00038 } else if (!strcasecmp(subd.c_str(),"CALIB")) {
00039 subdet_=HcalOther;
00040 subdetOther_=HcalCalibration;
00041 produces<HcalCalibRecHitCollection>();
00042 } else {
00043 std::cout << "HcalSimpleReconstructor is not associated with a specific subdetector!" << std::endl;
00044 }
00045
00046 }
00047
00048 HcalSimpleReconstructor::~HcalSimpleReconstructor() {
00049 }
00050
00051 void HcalSimpleReconstructor::produce(edm::Event& e, const edm::EventSetup& eventSetup)
00052 {
00053
00054 edm::ESHandle<HcalDbService> conditions;
00055 eventSetup.get<HcalDbRecord>().get(conditions);
00056 const HcalQIEShape* shape = conditions->getHcalShape ();
00057
00058
00059 if (det_==DetId::Hcal) {
00060 if (subdet_==HcalBarrel || subdet_==HcalEndcap) {
00061 edm::Handle<HBHEDigiCollection> digi;
00062
00063 e.getByLabel(inputLabel_,digi);
00064
00065
00066 std::auto_ptr<HBHERecHitCollection> rec(new HBHERecHitCollection);
00067 rec->reserve(digi->size());
00068
00069 HBHEDigiCollection::const_iterator i;
00070 for (i=digi->begin(); i!=digi->end(); i++) {
00071 HcalDetId cell = i->id();
00072 const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
00073 const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
00074 HcalCoderDb coder (*channelCoder, *shape);
00075 rec->push_back(reco_.reconstruct(*i,coder,calibrations));
00076 }
00077
00078 e.put(rec);
00079 } else if (subdet_==HcalOuter) {
00080 edm::Handle<HODigiCollection> digi;
00081 e.getByLabel(inputLabel_,digi);
00082
00083
00084 std::auto_ptr<HORecHitCollection> rec(new HORecHitCollection);
00085 rec->reserve(digi->size());
00086
00087 HODigiCollection::const_iterator i;
00088 for (i=digi->begin(); i!=digi->end(); i++) {
00089 HcalDetId cell = i->id();
00090 const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
00091 const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
00092 HcalCoderDb coder (*channelCoder, *shape);
00093 rec->push_back(reco_.reconstruct(*i,coder,calibrations));
00094 }
00095
00096 e.put(rec);
00097 } else if (subdet_==HcalForward) {
00098 edm::Handle<HFDigiCollection> digi;
00099 e.getByLabel(inputLabel_,digi);
00100
00101
00102 std::auto_ptr<HFRecHitCollection> rec(new HFRecHitCollection);
00103 rec->reserve(digi->size());
00104
00105 HFDigiCollection::const_iterator i;
00106 for (i=digi->begin(); i!=digi->end(); i++) {
00107 HcalDetId cell = i->id();
00108 const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
00109 const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
00110 HcalCoderDb coder (*channelCoder, *shape);
00111 rec->push_back(reco_.reconstruct(*i,coder,calibrations));
00112 }
00113
00114 e.put(rec);
00115 } else if (subdet_==HcalOther && subdetOther_==HcalCalibration) {
00116 edm::Handle<HcalCalibDigiCollection> digi;
00117 e.getByLabel(inputLabel_,digi);
00118
00119
00120 std::auto_ptr<HcalCalibRecHitCollection> rec(new HcalCalibRecHitCollection);
00121 rec->reserve(digi->size());
00122
00123 HcalCalibDigiCollection::const_iterator i;
00124 for (i=digi->begin(); i!=digi->end(); i++) {
00125 HcalCalibDetId cell = i->id();
00126 const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
00127 const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
00128 HcalCoderDb coder (*channelCoder, *shape);
00129 rec->push_back(reco_.reconstruct(*i,coder,calibrations));
00130 }
00131
00132 e.put(rec);
00133 }
00134 } else if (det_==DetId::Calo && subdet_==HcalZDCDetId::SubdetectorId) {
00135 edm::Handle<ZDCDigiCollection> digi;
00136 e.getByLabel(inputLabel_,digi);
00137
00138
00139 std::auto_ptr<ZDCRecHitCollection> rec(new ZDCRecHitCollection);
00140 rec->reserve(digi->size());
00141
00142 ZDCDigiCollection::const_iterator i;
00143 for (i=digi->begin(); i!=digi->end(); i++) {
00144 HcalZDCDetId cell = i->id();
00145 const HcalCalibrations& calibrations=conditions->getHcalCalibrations(cell);
00146 const HcalQIECoder* channelCoder = conditions->getHcalCoder (cell);
00147 HcalCoderDb coder (*channelCoder, *shape);
00148 rec->push_back(reco_.reconstruct(*i,coder,calibrations));
00149 }
00150
00151 e.put(rec);
00152 }
00153 }