Go to the documentation of this file.00001 using namespace std;
00002 #include "CastorSimpleReconstructor.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/ESHandle.h"
00008 #include "FWCore/Framework/interface/EventSetup.h"
00009 #include "CalibFormats/CastorObjects/interface/CastorCoderDb.h"
00010 #include "CalibFormats/CastorObjects/interface/CastorCalibrations.h"
00011 #include "CalibFormats/CastorObjects/interface/CastorDbService.h"
00012 #include "CalibFormats/CastorObjects/interface/CastorDbRecord.h"
00013 #include "CondFormats/DataRecord/interface/CastorRecoParamsRcd.h"
00014 #include "CondFormats/CastorObjects/interface/CastorRecoParams.h"
00015 #include "CondFormats/CastorObjects/interface/CastorChannelQuality.h"
00016 #include "CondFormats/CastorObjects/interface/CastorChannelStatus.h"
00017 #include "CondFormats/DataRecord/interface/CastorChannelQualityRcd.h"
00018 #include "CondFormats/DataRecord/interface/CastorSaturationCorrsRcd.h"
00019 #include "CondFormats/CastorObjects/interface/CastorSaturationCorrs.h"
00020 #include "RecoLocalCalo/HcalRecAlgos/interface/HcalCaloFlagLabels.h"
00021
00022 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00023 #include <iostream>
00024
00025
00026 CastorSimpleReconstructor::CastorSimpleReconstructor(edm::ParameterSet const& conf):
00027 reco_(conf.getParameter<int>("firstSample"),conf.getParameter<int>("samplesToAdd"),conf.getParameter<bool>("correctForTimeslew"),
00028 conf.getParameter<bool>("correctForPhaseContainment"),conf.getParameter<double>("correctionPhaseNS")),
00029 det_(DetId::Hcal),
00030 inputLabel_(conf.getParameter<edm::InputTag>("digiLabel")),
00031 firstSample_(conf.getParameter<int>("firstSample")),
00032 samplesToAdd_(conf.getParameter<int>("samplesToAdd")),
00033 maxADCvalue_(conf.getParameter<int>("maxADCvalue")),
00034 tsFromDB_(conf.getParameter<bool>("tsFromDB")),
00035 setSaturationFlag_(conf.getParameter<bool>("setSaturationFlag")),
00036 doSaturationCorr_(conf.getParameter<bool>("doSaturationCorr"))
00037 {
00038 std::string subd=conf.getParameter<std::string>("Subdetector");
00039 if (!strcasecmp(subd.c_str(),"CASTOR")) {
00040 det_=DetId::Calo;
00041 subdet_=HcalCastorDetId::SubdetectorId;
00042 produces<CastorRecHitCollection>();
00043 } else {
00044 edm::LogWarning("CastorSimpleReconstructor") << "CastorSimpleReconstructor is not associated with CASTOR subdetector!" << std::endl;
00045 }
00046
00047 }
00048
00049 CastorSimpleReconstructor::~CastorSimpleReconstructor() {
00050 }
00051
00052 void CastorSimpleReconstructor::produce(edm::Event& e, const edm::EventSetup& eventSetup)
00053 {
00054
00055 edm::ESHandle<CastorDbService> conditions;
00056 eventSetup.get<CastorDbRecord>().get(conditions);
00057 const CastorQIEShape* shape = conditions->getCastorShape ();
00058
00059 CastorCalibrations calibrations;
00060
00061
00062 edm::ESHandle<CastorRecoParams> recoparams;
00063 if (tsFromDB_) {
00064 eventSetup.get<CastorRecoParamsRcd>().get(recoparams);
00065 if (!recoparams.isValid()) {
00066 tsFromDB_ = false;
00067 edm::LogWarning("CastorSimpleReconstructor") << "Could not handle the CastorRecoParamsRcd correctly, using parameters from cfg file from this event onwards... These parameters could be wrong for this run... please check" << std::endl;
00068 }
00069 }
00070
00071
00072 edm::ESHandle<CastorSaturationCorrs> satcorr;
00073 if (doSaturationCorr_) {
00074 eventSetup.get<CastorSaturationCorrsRcd>().get(satcorr);
00075 if (!satcorr.isValid()) {
00076 doSaturationCorr_ = false;
00077 edm::LogWarning("CastorSimpleReconstructor") << "Could not handle the CastorSaturationCorrsRcd correctly. We'll not try the saturation correction from this event onwards..." << std::endl;
00078 }
00079 }
00080
00081
00082 if (det_==DetId::Calo && subdet_==HcalCastorDetId::SubdetectorId) {
00083 edm::Handle<CastorDigiCollection> digi;
00084 e.getByLabel(inputLabel_,digi);
00085
00086
00087 std::auto_ptr<CastorRecHitCollection> rec(new CastorRecHitCollection);
00088
00089 CastorDigiCollection::const_iterator i;
00090 for (i=digi->begin(); i!=digi->end(); i++) {
00091 HcalCastorDetId cell = i->id();
00092 DetId detcell=(DetId)cell;
00093 const CastorCalibrations& calibrations=conditions->getCastorCalibrations(cell);
00094
00095 if (tsFromDB_) {
00096 const CastorRecoParam* param_ts = recoparams->getValues(detcell.rawId());
00097 reco_.resetTimeSamples(param_ts->firstSample(),param_ts->samplesToAdd());
00098 }
00099 const CastorQIECoder* channelCoder = conditions->getCastorCoder (cell);
00100 CastorCoderDb coder (*channelCoder, *shape);
00101
00102
00103 rec->push_back(reco_.reconstruct(*i,coder,calibrations));
00104
00105
00106 if (setSaturationFlag_) {
00107 reco_.checkADCSaturation(rec->back(),*i,maxADCvalue_);
00108
00109
00110 if (doSaturationCorr_ && rec->back().flagField(HcalCaloFlagLabels::ADCSaturationBit)) {
00111
00112 const CastorSaturationCorr* saturationCorr = satcorr->getValues(detcell.rawId());
00113 double satCorrConst = 1.;
00114 satCorrConst = saturationCorr->getValue();
00115 reco_.recoverADCSaturation(rec->back(),coder,calibrations,*i,maxADCvalue_,satCorrConst);
00116 }
00117 }
00118 }
00119
00120 e.put(rec);
00121 }
00122 }