CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC2_patch1/src/SimCalorimetry/HcalTrigPrimProducers/src/HcalTrigPrimDigiProducer.cc

Go to the documentation of this file.
00001 #include "SimCalorimetry/HcalTrigPrimProducers/src/HcalTrigPrimDigiProducer.h"
00002 #include "FWCore/Framework/interface/Event.h"
00003 #include "FWCore/Framework/interface/EventSetup.h"
00004 #include "DataFormats/Common/interface/Handle.h"
00005 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00006 #include "FWCore/Framework/interface/ESHandle.h"
00007 #include "DataFormats/HcalDigi/interface/HcalDigiCollections.h"
00008 #include "DataFormats/HcalDigi/interface/HBHEDataFrame.h"
00009 #include "DataFormats/HcalDigi/interface/HFDataFrame.h"
00010 #include "DataFormats/HcalDigi/interface/HcalTriggerPrimitiveDigi.h"
00011 #include "FWCore/Framework/interface/MakerMacros.h"
00012 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00013 #include "CalibFormats/HcalObjects/interface/HcalTPGRecord.h"
00014 #include "CalibFormats/HcalObjects/interface/HcalTPGCoder.h"
00015 #include "CalibFormats/CaloTPG/interface/HcalTPGCompressor.h"
00016 #include "CalibFormats/CaloTPG/interface/CaloTPGRecord.h"
00017 #include "CalibFormats/CaloTPG/interface/CaloTPGTranscoder.h"
00018 #include "CalibFormats/HcalObjects/interface/HcalDbService.h"
00019 #include "CalibFormats/HcalObjects/interface/HcalDbRecord.h"
00020 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00021 #include "CondFormats/HcalObjects/interface/HcalElectronicsMap.h"
00022 #include "CondFormats/HcalObjects/interface/HcalLutMetadata.h"
00023 #include "Geometry/Records/interface/CaloGeometryRecord.h"
00024 
00025 #include <algorithm>
00026 
00027 HcalTrigPrimDigiProducer::HcalTrigPrimDigiProducer(const edm::ParameterSet& ps)
00028 : 
00029   theAlgo_(ps.getParameter<bool>("peakFilter"),
00030           ps.getParameter<std::vector<double> >("weights"),
00031           ps.getParameter<int>("latency"),
00032           ps.getParameter<uint32_t>("FG_threshold"),
00033       ps.getParameter<uint32_t>("ZS_threshold"),
00034           ps.getParameter<int>("numberOfSamples"),
00035           ps.getParameter<int>("numberOfPresamples"),
00036       ps.getParameter<uint32_t>("MinSignalThreshold"),
00037       ps.getParameter<uint32_t>("PMTNoiseThreshold")
00038    ),
00039   inputLabel_(ps.getParameter<std::vector<edm::InputTag> >("inputLabel")),
00040   inputTagFEDRaw_(ps.getParameter<edm::InputTag> ("InputTagFEDRaw")),
00041   runZS_(ps.getParameter<bool>("RunZS")),
00042   runFrontEndFormatError_(ps.getParameter<bool>("FrontEndFormatError"))
00043 {
00044    produces<HcalTrigPrimDigiCollection>();
00045    theAlgo_.setPeakFinderAlgorithm(ps.getParameter<int>("PeakFinderAlgorithm"));
00046 }
00047 
00048 
00049 void HcalTrigPrimDigiProducer::produce(edm::Event& iEvent, const edm::EventSetup& eventSetup) {
00050 
00051   // Step A: get the conditions, for the decoding
00052   edm::ESHandle<HcalTPGCoder> inputCoder;
00053   eventSetup.get<HcalTPGRecord>().get(inputCoder);
00054 
00055   edm::ESHandle<CaloTPGTranscoder> outTranscoder;
00056   eventSetup.get<CaloTPGRecord>().get(outTranscoder);
00057   outTranscoder->setup(eventSetup,CaloTPGTranscoder::HcalTPG);
00058 
00059   edm::ESHandle<HcalLutMetadata> lutMetadata;
00060   eventSetup.get<HcalLutMetadataRcd>().get(lutMetadata);
00061   float rctlsb = lutMetadata->getRctLsb();
00062 
00063   edm::ESHandle<HcalTrigTowerGeometry> pG;
00064   eventSetup.get<CaloGeometryRecord>().get(pG);
00065   
00066   // Step B: Create empty output
00067   std::auto_ptr<HcalTrigPrimDigiCollection> result(new HcalTrigPrimDigiCollection());
00068 
00069   edm::Handle<HBHEDigiCollection> hbheDigis;
00070   edm::Handle<HFDigiCollection>   hfDigis;
00071 
00072   iEvent.getByLabel(inputLabel_[0],hbheDigis);
00073   iEvent.getByLabel(inputLabel_[1],hfDigis);
00074 
00075   // protect here against missing input collections
00076   // there is no protection in HcalTriggerPrimitiveAlgo
00077 
00078   if (!hbheDigis.isValid()) {
00079       edm::LogInfo("HcalTrigPrimDigiProducer")
00080               << "\nWarning: HBHEDigiCollection with input tag "
00081               << inputLabel_[0]
00082               << "\nrequested in configuration, but not found in the event."
00083               << "\nQuit returning empty product." << std::endl;
00084 
00085       // put empty HcalTrigPrimDigiCollection in the event
00086       iEvent.put(result);
00087 
00088       outTranscoder->releaseSetup();
00089 
00090       return;
00091   }
00092 
00093   if (!hfDigis.isValid()) {
00094       edm::LogInfo("HcalTrigPrimDigiProducer")
00095               << "\nWarning: HFDigiCollection with input tag "
00096               << inputLabel_[1]
00097               << "\nrequested in configuration, but not found in the event."
00098               << "\nQuit returning empty product." << std::endl;
00099 
00100       // put empty HcalTrigPrimDigiCollection in the event
00101       iEvent.put(result);
00102 
00103       outTranscoder->releaseSetup();
00104 
00105       return;
00106   }
00107 
00108 
00109   // Step C: Invoke the algorithm, passing in inputs and getting back outputs.
00110   theAlgo_.run(inputCoder.product(),outTranscoder->getHcalCompressor().get(),
00111                *hbheDigis,  *hfDigis, *result, &(*pG), rctlsb);
00112 
00113   // Step C.1: Run FE Format Error / ZS for real data.
00114   if (runFrontEndFormatError_) {
00115 
00116         edm::ESHandle < HcalDbService > pSetup;
00117         eventSetup.get<HcalDbRecord> ().get(pSetup);
00118         const HcalElectronicsMap *emap = pSetup->getHcalMapping();
00119 
00120         edm::Handle < FEDRawDataCollection > fedHandle;
00121         iEvent.getByLabel(inputTagFEDRaw_, fedHandle);
00122 
00123         if (fedHandle.isValid() && emap != 0) {
00124             theAlgo_.runFEFormatError(fedHandle.product(), emap, *result);
00125         } else {
00126             edm::LogInfo("HcalTrigPrimDigiProducer")
00127                     << "\nWarning: FEDRawDataCollection with input tag "
00128                     << inputTagFEDRaw_
00129                     << "\nrequested in configuration, but not found in the event."
00130                     << "\nQuit returning empty product." << std::endl;
00131 
00132             // produce empty HcalTrigPrimDigiCollection and put it in the event
00133             std::auto_ptr < HcalTrigPrimDigiCollection > emptyResult(
00134                     new HcalTrigPrimDigiCollection());
00135 
00136             iEvent.put(emptyResult);
00137 
00138             outTranscoder->releaseSetup();
00139 
00140             return;
00141         }
00142 
00143   }
00144 
00145   if (runZS_) theAlgo_.runZS(*result);
00146 
00147   //  edm::LogInfo("HcalTrigPrimDigiProducer") << "HcalTrigPrims: " << result->size();
00148 
00149   // Step D: Put outputs into event
00150   iEvent.put(result);
00151 
00152   outTranscoder->releaseSetup();
00153 }
00154 
00155