CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_6/src/RecoLocalCalo/CastorReco/plugins/CastorSimpleReconstructor.cc

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/Selector.h"
00008 #include "FWCore/Framework/interface/ESHandle.h"
00009 #include "FWCore/Framework/interface/EventSetup.h"
00010 #include "CalibFormats/CastorObjects/interface/CastorCoderDb.h"
00011 #include "CalibFormats/CastorObjects/interface/CastorCalibrations.h"
00012 #include "CalibFormats/CastorObjects/interface/CastorDbService.h"
00013 #include "CalibFormats/CastorObjects/interface/CastorDbRecord.h"
00014 #include "CondFormats/DataRecord/interface/CastorRecoParamsRcd.h"
00015 #include "CondFormats/CastorObjects/interface/CastorRecoParams.h"
00016 #include "CondFormats/CastorObjects/interface/CastorChannelQuality.h"
00017 #include "CondFormats/CastorObjects/interface/CastorChannelStatus.h"
00018 #include "CondFormats/DataRecord/interface/CastorChannelQualityRcd.h"
00019 
00020 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00021 #include <iostream>
00022 
00023     
00024 CastorSimpleReconstructor::CastorSimpleReconstructor(edm::ParameterSet const& conf):
00025   reco_(conf.getParameter<int>("firstSample"),conf.getParameter<int>("samplesToAdd"),conf.getParameter<bool>("correctForTimeslew"),
00026         conf.getParameter<bool>("correctForPhaseContainment"),conf.getParameter<double>("correctionPhaseNS")),
00027   det_(DetId::Hcal),
00028   inputLabel_(conf.getParameter<edm::InputTag>("digiLabel")),
00029   firstSample_(conf.getParameter<int>("firstSample")),
00030   samplesToAdd_(conf.getParameter<int>("samplesToAdd")),
00031   tsFromDB_(conf.getUntrackedParameter<bool>("tsFromDB",true))
00032 {
00033   std::string subd=conf.getParameter<std::string>("Subdetector");
00034   if (!strcasecmp(subd.c_str(),"CASTOR")) {
00035     det_=DetId::Calo;
00036     subdet_=HcalCastorDetId::SubdetectorId;
00037     produces<CastorRecHitCollection>();
00038   } else {
00039     edm::LogWarning("CastorSimpleReconstructor") << "CastorSimpleReconstructor is not associated with CASTOR subdetector!" << std::endl;
00040   }       
00041   
00042 }
00043 
00044 CastorSimpleReconstructor::~CastorSimpleReconstructor() {
00045 }
00046 
00047 void CastorSimpleReconstructor::beginRun(edm::Run&r, edm::EventSetup const & es){
00048 
00049   if (tsFromDB_) {
00050         edm::ESHandle<CastorRecoParams> p;
00051         es.get<CastorRecoParamsRcd>().get(p);
00052         if (!p.isValid()) { 
00053                 tsFromDB_ = false;
00054                 edm::LogWarning("CastorSimpleReconstructor") << "Could not handle the CastorRecoParamsRcd correctly, using parameters from cfg file. These parameters could be wrong for this run... please check" << std::endl;
00055         } else {
00056                 paramTS_ = new CastorRecoParams(*p.product());
00057         }
00058   }
00059   
00060 }
00061 void CastorSimpleReconstructor::produce(edm::Event& e, const edm::EventSetup& eventSetup)
00062 {
00063   // get conditions
00064   edm::ESHandle<CastorDbService> conditions;
00065   eventSetup.get<CastorDbRecord>().get(conditions);
00066   const CastorQIEShape* shape = conditions->getCastorShape (); // this one is generic
00067   
00068   CastorCalibrations calibrations;
00069   
00070    edm::ESHandle<CastorChannelQuality> p;
00071    eventSetup.get<CastorChannelQualityRcd>().get(p);
00072    CastorChannelQuality* myqual = new CastorChannelQuality(*p.product());
00073   
00074   
00075 //  if (det_==DetId::Hcal) {
00076      if (det_==DetId::Calo && subdet_==HcalCastorDetId::SubdetectorId) {
00077     edm::Handle<CastorDigiCollection> digi;
00078     e.getByLabel(inputLabel_,digi);
00079     
00080     // create empty output
00081     std::auto_ptr<CastorRecHitCollection> rec(new CastorRecHitCollection);
00082     // run the algorithm
00083     CastorDigiCollection::const_iterator i;
00084     for (i=digi->begin(); i!=digi->end(); i++) {
00085       HcalCastorDetId cell = i->id();
00086       DetId detcell=(DetId)cell;          
00087  const CastorCalibrations& calibrations=conditions->getCastorCalibrations(cell);
00088 
00089         // now check the channelquality of this rechit
00090         bool ok = true;
00091         std::vector<DetId> channels = myqual->getAllChannels();
00092         for (std::vector<DetId>::iterator channel = channels.begin();channel !=  channels.end();channel++) {    
00093                 if (channel->rawId() == detcell.rawId()) {
00094                         const CastorChannelStatus* mydigistatus=myqual->getValues(*channel);
00095                         if (mydigistatus->getValue() == 2989) ok = false; // 2989 = BAD
00096                 }
00097         }
00098 
00099 //conditions->makeCastorCalibration (cell, &calibrations);
00100       
00101       if (tsFromDB_) {
00102           const CastorRecoParam* param_ts = paramTS_->getValues(detcell.rawId());
00103           reco_.resetTimeSamples(param_ts->firstSample(),param_ts->samplesToAdd());
00104           //std::cout << "using CastorRecoParam from DB, reco_ parameters are reset to: firstSample_ = " << param_ts->firstSample() << " samplesToAdd_ = " << 
00105           //param_ts->samplesToAdd() << std::endl;
00106       }          
00107       const CastorQIECoder* channelCoder = conditions->getCastorCoder (cell);
00108       CastorCoderDb coder (*channelCoder, *shape);
00109       if (ok) rec->push_back(reco_.reconstruct(*i,coder,calibrations));
00110     }
00111     // return result
00112     e.put(rec);     
00113 //     }
00114   }
00115 }