CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/L1Trigger/GlobalCaloTrigger/plugins/L1GctEmulator.cc

Go to the documentation of this file.
00001 #include "L1Trigger/GlobalCaloTrigger/plugins/L1GctEmulator.h"
00002 
00003 // system includes
00004 #include <memory>
00005 #include <vector>
00006 
00007 // EDM includes
00008 #include "FWCore/PluginManager/interface/ModuleDef.h"
00009 #include "FWCore/Framework/interface/Frameworkfwd.h"
00010 #include "FWCore/Framework/interface/EDProducer.h"
00011 #include "FWCore/Framework/interface/Event.h"
00012 #include "FWCore/Framework/interface/MakerMacros.h"
00013 #include "FWCore/Framework/interface/ESHandle.h"
00014 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00015 
00016 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00017 
00018 // Trigger configuration includes
00019 #include "CondFormats/L1TObjects/interface/L1CaloEtScale.h"
00020 #include "CondFormats/L1TObjects/interface/L1GctJetFinderParams.h"
00021 #include "CondFormats/L1TObjects/interface/L1GctChannelMask.h"
00022 #include "CondFormats/DataRecord/interface/L1JetEtScaleRcd.h"
00023 #include "CondFormats/DataRecord/interface/L1HtMissScaleRcd.h"
00024 #include "CondFormats/DataRecord/interface/L1HfRingEtScaleRcd.h"
00025 #include "CondFormats/DataRecord/interface/L1GctJetFinderParamsRcd.h"
00026 #include "CondFormats/DataRecord/interface/L1GctChannelMaskRcd.h"
00027 
00028 // GCT include files
00029 #include "L1Trigger/GlobalCaloTrigger/interface/L1GctJetEtCalibrationLut.h"
00030 
00031 // RCT data includes
00032 #include "DataFormats/L1CaloTrigger/interface/L1CaloCollections.h"
00033 
00034 // GCT data includes
00035 #include "DataFormats/L1GlobalCaloTrigger/interface/L1GctCollections.h"
00036 
00037 using std::vector;
00038 
00039 L1GctEmulator::L1GctEmulator(const edm::ParameterSet& ps) :
00040   m_jetEtCalibLuts(),
00041   m_writeInternalData(ps.getParameter<bool>("writeInternalData")),
00042   m_verbose(ps.getUntrackedParameter<bool>("verbose", false))
00043  {
00044 
00045   // list of products
00046   produces<L1GctEmCandCollection>("isoEm");
00047   produces<L1GctEmCandCollection>("nonIsoEm");
00048   produces<L1GctJetCandCollection>("cenJets");
00049   produces<L1GctJetCandCollection>("forJets");
00050   produces<L1GctJetCandCollection>("tauJets");
00051   produces<L1GctInternJetDataCollection>();
00052   produces<L1GctEtTotalCollection>();
00053   produces<L1GctEtHadCollection>();
00054   produces<L1GctEtMissCollection>();
00055   produces<L1GctHtMissCollection>();
00056   produces<L1GctInternEtSumCollection>();
00057   produces<L1GctInternHtMissCollection>();
00058   produces<L1GctHFBitCountsCollection>();
00059   produces<L1GctHFRingEtSumsCollection>();
00060 
00061   // get the input label
00062   edm::InputTag inputTag  = ps.getParameter<edm::InputTag>("inputLabel");
00063   m_inputLabel = inputTag.label();
00064 
00065   // Get the number of bunch crossings to be processed
00066   int firstBx = -ps.getParameter<unsigned>("preSamples");
00067   int  lastBx =  ps.getParameter<unsigned>("postSamples");
00068 
00069   // instantiate the GCT. Argument selects the type of jetFinder to be used.
00070   L1GctJetLeafCard::jetFinderType jfType=L1GctJetLeafCard::hardwareJetFinder;
00071   std::string jfTypeStr = ps.getParameter<std::string>("jetFinderType");
00072   if (jfTypeStr == "tdrJetFinder") { jfType = L1GctJetLeafCard::tdrJetFinder; }
00073   else if (jfTypeStr != "hardwareJetFinder") {
00074     edm::LogWarning ("L1GctEmulatorSetup") << "Unrecognised jetFinder option " << jfTypeStr
00075                                            << "\nHardware jetFinder will be used";
00076   }
00077   bool hwTest = ps.getParameter<bool>("hardwareTest");
00078   if (hwTest) {
00079     unsigned mask = ps.getUntrackedParameter<unsigned>("jetLeafMask", 0);
00080     m_gct = new L1GlobalCaloTrigger(jfType, mask);
00081     edm::LogWarning ("L1GctEmulatorSetup") << "Emulator has been configured in hardware test mode with mask " << mask
00082                                            << "\nThis mode should NOT be used for Physics studies!";
00083   } else {
00084     m_gct = new L1GlobalCaloTrigger(jfType);
00085   }
00086   m_gct->setBxRange(firstBx, lastBx);
00087 
00088   // Fill the jetEtCalibLuts vector
00089   lutPtr nextLut( new L1GctJetEtCalibrationLut() );
00090 
00091   for (unsigned ieta=0; ieta<L1GctJetFinderParams::NUMBER_ETA_VALUES; ieta++) {
00092     nextLut->setEtaBin(ieta);
00093     m_jetEtCalibLuts.push_back(nextLut);
00094     nextLut.reset ( new L1GctJetEtCalibrationLut() );
00095   }
00096 
00097   // Setup the tau algorithm parameters
00098   bool useImprovedTauAlgo            = ps.getParameter<bool>("useImprovedTauAlgorithm");
00099   bool ignoreTauVetoBitsForIsolation = ps.getParameter<bool>("ignoreRCTTauVetoBitsForIsolation");
00100   m_gct->setupTauAlgo(useImprovedTauAlgo, ignoreTauVetoBitsForIsolation);
00101 
00102   // set verbosity (not implemented yet!)
00103   //  m_gct->setVerbose(m_verbose);
00104 
00105   // print debug info?
00106   if (m_verbose) {
00107     m_gct->print();
00108   }
00109 }
00110 
00111 L1GctEmulator::~L1GctEmulator() {
00112   if (m_gct != 0) delete m_gct;
00113 }
00114 
00115 
00116 void L1GctEmulator::beginJob()
00117 {
00118 }
00119 
00120 void L1GctEmulator::endJob()
00121 {
00122 }
00123 
00124 int L1GctEmulator::configureGct(const edm::EventSetup& c)
00125 {
00126   int success = 0;
00127   if (&c==0) {
00128     success = -1;
00129     if (m_verbose) {
00130       edm::LogWarning("L1GctConfigFailure") << "Cannot find EventSetup information." << std::endl;
00131     }
00132   }
00133 
00134   if (success == 0) {
00135     // get data from EventSetup
00136     edm::ESHandle< L1GctJetFinderParams > jfPars ;
00137     c.get< L1GctJetFinderParamsRcd >().get( jfPars ) ; // which record?
00138     edm::ESHandle< L1GctChannelMask > chanMask ;
00139     c.get< L1GctChannelMaskRcd >().get( chanMask ) ; // which record?
00140     edm::ESHandle< L1CaloEtScale > etScale ;
00141     c.get< L1JetEtScaleRcd >().get( etScale ) ; // which record?
00142     edm::ESHandle< L1CaloEtScale > htMissScale ;
00143     c.get< L1HtMissScaleRcd >().get( htMissScale ) ; // which record?
00144     edm::ESHandle< L1CaloEtScale > hfRingEtScale ;
00145     c.get< L1HfRingEtScaleRcd >().get( hfRingEtScale ) ; // which record?
00146 
00147 
00148     if (jfPars.product() == 0) {
00149       success = -1;
00150       if (m_verbose) {
00151         edm::LogWarning("L1GctConfigFailure")
00152           << "Failed to find a L1GctJetFinderParamsRcd:L1GctJetFinderParams in EventSetup!" << std::endl;
00153       }
00154     }
00155 
00156     if (chanMask.product() == 0) {
00157       success = -1;
00158       if (m_verbose) {
00159         edm::LogWarning("L1GctConfigFailure")
00160           << "Failed to find a L1GctChannelMaskRcd:L1GctChannelMask in EventSetup!" << std::endl;
00161       }
00162     }
00163 
00164     if (hfRingEtScale.product() == 0) {
00165       success = -1;
00166       if (m_verbose) {
00167         edm::LogWarning("L1GctConfigFailure")
00168           << "Failed to find a L1HfRingEtScaleRcd:L1HfRingEtScaleRcd in EventSetup!" << std::endl;
00169       }
00170     }
00171 
00172 
00173     if (success==0) {
00174       // tell the jet Et Luts about the scales
00175       for (unsigned ieta=0; ieta<m_jetEtCalibLuts.size(); ieta++) {
00176         m_jetEtCalibLuts.at(ieta)->setFunction(jfPars.product());
00177         m_jetEtCalibLuts.at(ieta)->setOutputEtScale(etScale.product());
00178       }
00179 
00180       // pass all the setup info to the gct
00181       m_gct->setJetEtCalibrationLuts(m_jetEtCalibLuts);
00182       m_gct->setJetFinderParams(jfPars.product());
00183       m_gct->setHtMissScale(htMissScale.product());
00184       m_gct->setupHfSumLuts(hfRingEtScale.product());
00185       m_gct->setChannelMask(chanMask.product());
00186     }
00187   }
00188 
00189   if (success != 0 && m_verbose) {
00190     edm::LogError("L1GctConfigError")
00191       << "Configuration failed - GCT emulator will not be run" << std::endl;
00192   }
00193   return success;
00194 }
00195 
00196 void L1GctEmulator::produce(edm::Event& e, const edm::EventSetup& c) {
00197 
00198   // The emulator will always produce output collections, which get filled as long as
00199   // the setup and input data are present. Start by making empty output collections.
00200 
00201   // create the em and jet collections
00202   std::auto_ptr<L1GctEmCandCollection> isoEmResult   (new L1GctEmCandCollection( ) );
00203   std::auto_ptr<L1GctEmCandCollection> nonIsoEmResult(new L1GctEmCandCollection( ) );
00204   std::auto_ptr<L1GctJetCandCollection> cenJetResult(new L1GctJetCandCollection( ) );
00205   std::auto_ptr<L1GctJetCandCollection> forJetResult(new L1GctJetCandCollection( ) );
00206   std::auto_ptr<L1GctJetCandCollection> tauJetResult(new L1GctJetCandCollection( ) );
00207 
00208   // create the energy sum digis
00209   std::auto_ptr<L1GctEtTotalCollection> etTotResult (new L1GctEtTotalCollection( ) );
00210   std::auto_ptr<L1GctEtHadCollection>   etHadResult (new L1GctEtHadCollection  ( ) );
00211   std::auto_ptr<L1GctEtMissCollection>  etMissResult(new L1GctEtMissCollection ( ) );
00212   std::auto_ptr<L1GctHtMissCollection>  htMissResult(new L1GctHtMissCollection ( ) );
00213 
00214   // create the Hf sums digis
00215   std::auto_ptr<L1GctHFBitCountsCollection>  hfBitCountResult (new L1GctHFBitCountsCollection ( ) );
00216   std::auto_ptr<L1GctHFRingEtSumsCollection> hfRingEtSumResult(new L1GctHFRingEtSumsCollection( ) );
00217 
00218   // create internal data collections
00219   std::auto_ptr<L1GctInternJetDataCollection> internalJetResult   (new L1GctInternJetDataCollection( ));
00220   std::auto_ptr<L1GctInternEtSumCollection>   internalEtSumResult (new L1GctInternEtSumCollection  ( ));
00221   std::auto_ptr<L1GctInternHtMissCollection>  internalHtMissResult(new L1GctInternHtMissCollection ( ));
00222 
00223   // get config data from EventSetup.
00224   // check this has been done successfully before proceeding
00225   if (configureGct(c) == 0) { 
00226 
00227     // get the RCT data
00228     edm::Handle<L1CaloEmCollection> em;
00229     edm::Handle<L1CaloRegionCollection> rgn;
00230     bool gotEm  = e.getByLabel(m_inputLabel, em);
00231     bool gotRgn = e.getByLabel(m_inputLabel, rgn);
00232 
00233     // check the data
00234     if (!gotEm && m_verbose) {
00235       edm::LogError("L1GctInputFailedError")
00236         << "Failed to get em candidates with label " << m_inputLabel << " - GCT emulator will not be run" << std::endl;
00237     }
00238 
00239     if (!gotRgn && m_verbose) {
00240       edm::LogError("L1GctInputFailedError")
00241         << "Failed to get calo regions with label " << m_inputLabel << " - GCT emulator will not be run" << std::endl;
00242     }
00243 
00244     if (gotEm && !em.isValid()) {
00245       gotEm = false;
00246       if (m_verbose) {
00247         edm::LogError("L1GctInputFailedError")
00248           << "isValid() flag set to false for em candidates with label " << m_inputLabel << " - GCT emulator will not be run" << std::endl;
00249       }
00250     }
00251 
00252     if (gotRgn && !rgn.isValid()) {
00253       gotRgn = false;
00254       if (m_verbose) {
00255         edm::LogError("L1GctInputFailedError")
00256           << "isValid() flag set to false for calo regions with label " << m_inputLabel << " - GCT emulator will not be run" << std::endl;
00257       }
00258     }
00259 
00260     // if all is ok, proceed with GCT processing
00261     if (gotEm && gotRgn) {
00262       // reset the GCT internal buffers
00263       m_gct->reset();
00264 
00265       // fill the GCT source cards
00266       m_gct->fillEmCands(*em);
00267       m_gct->fillRegions(*rgn);
00268   
00269       // process the event
00270       m_gct->process();
00271 
00272       // fill the em and jet collections
00273       *isoEmResult    = m_gct->getIsoElectrons();
00274       *nonIsoEmResult = m_gct->getNonIsoElectrons();
00275       *cenJetResult   = m_gct->getCentralJets();
00276       *forJetResult   = m_gct->getForwardJets();
00277       *tauJetResult   = m_gct->getTauJets();
00278 
00279       // fill the energy sum digis
00280       *etTotResult  = m_gct->getEtSumCollection();
00281       *etHadResult  = m_gct->getEtHadCollection();
00282       *etMissResult = m_gct->getEtMissCollection();
00283       *htMissResult = m_gct->getHtMissCollection();
00284 
00285       // fill the Hf sums digis
00286       *hfBitCountResult  = m_gct->getHFBitCountsCollection ();
00287       *hfRingEtSumResult = m_gct->getHFRingEtSumsCollection();
00288 
00289       // fill internal data collections if required
00290       if (m_writeInternalData) {
00291         *internalJetResult    = m_gct->getInternalJets();
00292         *internalEtSumResult  = m_gct->getInternalEtSums();
00293         *internalHtMissResult = m_gct->getInternalHtMiss();
00294       }
00295     }
00296   }
00297 
00298   // put the collections into the event
00299   e.put(isoEmResult,"isoEm");
00300   e.put(nonIsoEmResult,"nonIsoEm");
00301   e.put(cenJetResult,"cenJets");
00302   e.put(forJetResult,"forJets");
00303   e.put(tauJetResult,"tauJets");
00304   e.put(etTotResult);
00305   e.put(etHadResult);
00306   e.put(etMissResult);
00307   e.put(htMissResult);
00308   e.put(hfBitCountResult);
00309   e.put(hfRingEtSumResult);
00310 
00311   e.put(internalJetResult);
00312   e.put(internalEtSumResult);
00313   e.put(internalHtMissResult);
00314 
00315 }
00316 
00317 DEFINE_FWK_MODULE(L1GctEmulator);
00318