CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/L1Trigger/CSCTriggerPrimitives/plugins/CSCTriggerPrimitivesProducer.cc

Go to the documentation of this file.
00001 //-------------------------------------------------
00002 //
00003 //   Class: CSCTriggerPrimitivesProducer
00004 //
00005 //   Description: Steering routine of the local Level-1 Cathode Strip Chamber
00006 //                trigger.
00007 //
00008 //   Author List: S. Valuev, UCLA.
00009 //
00010 //   $Id: CSCTriggerPrimitivesProducer.cc,v 1.16 2012/12/05 21:16:16 khotilov Exp $
00011 //
00012 //   Modifications:
00013 //
00014 //--------------------------------------------------
00015  
00016 #include "L1Trigger/CSCTriggerPrimitives/plugins/CSCTriggerPrimitivesProducer.h"
00017 #include "L1Trigger/CSCTriggerPrimitives/src/CSCTriggerPrimitivesBuilder.h"
00018 
00019 #include "DataFormats/Common/interface/Handle.h"
00020 #include "FWCore/Framework/interface/ESHandle.h"
00021 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00022 
00023 #include "Geometry/Records/interface/MuonGeometryRecord.h"
00024 #include "L1Trigger/CSCCommonTrigger/interface/CSCTriggerGeometry.h"
00025 #include "CondFormats/DataRecord/interface/CSCBadChambersRcd.h"
00026 
00027 #include "DataFormats/CSCDigi/interface/CSCComparatorDigiCollection.h"
00028 #include "DataFormats/CSCDigi/interface/CSCWireDigiCollection.h"
00029 #include "DataFormats/CSCDigi/interface/CSCALCTDigiCollection.h"
00030 #include "DataFormats/CSCDigi/interface/CSCCLCTDigiCollection.h"
00031 #include "DataFormats/CSCDigi/interface/CSCCorrelatedLCTDigiCollection.h"
00032 
00033 // Configuration via EventSetup
00034 #include "CondFormats/CSCObjects/interface/CSCDBL1TPParameters.h"
00035 #include "CondFormats/DataRecord/interface/CSCDBL1TPParametersRcd.h"
00036 
00037 
00038 CSCTriggerPrimitivesProducer::CSCTriggerPrimitivesProducer(const edm::ParameterSet& conf) : iev(0) {
00039 
00040   // if false, parameters will be read in from DB using EventSetup mechanism
00041   // else will use all parameters from the config file
00042   debugParameters_ = conf.getUntrackedParameter<bool>("debugParameters",false);
00043 
00044   wireDigiProducer_ = conf.getParameter<edm::InputTag>("CSCWireDigiProducer");
00045   compDigiProducer_ = conf.getParameter<edm::InputTag>("CSCComparatorDigiProducer");
00046   checkBadChambers_ = conf.getUntrackedParameter<bool>("checkBadChambers", true);
00047 
00048   lctBuilder_ = new CSCTriggerPrimitivesBuilder(conf); // pass on the conf
00049 
00050   // register what this produces
00051   produces<CSCALCTDigiCollection>();
00052   produces<CSCCLCTDigiCollection>();
00053   produces<CSCCLCTPreTriggerCollection>();
00054   produces<CSCCorrelatedLCTDigiCollection>();
00055   produces<CSCCorrelatedLCTDigiCollection>("MPCSORTED");
00056 }
00057 
00058 CSCTriggerPrimitivesProducer::~CSCTriggerPrimitivesProducer() {
00059   LogDebug("L1CSCTrigger")
00060     << "deleting trigger primitives after " << iev << " events.";
00061   delete lctBuilder_;
00062 }
00063 
00064 //void CSCTriggerPrimitivesProducer::beginRun(const edm::EventSetup& setup) {
00065 //}
00066 
00067 void CSCTriggerPrimitivesProducer::produce(edm::Event& ev,
00068                                            const edm::EventSetup& setup) {
00069 
00070   LogDebug("L1CSCTrigger") << "start producing LCTs for event " << ++iev;
00071 
00072   // Find the geometry (& conditions?) for this event & cache it in 
00073   // CSCTriggerGeometry.
00074   {
00075     edm::ESHandle<CSCGeometry> h;
00076     setup.get<MuonGeometryRecord>().get(h);
00077     CSCTriggerGeometry::setGeometry(h);
00078   }
00079 
00080   // Find conditions data for bad chambers.
00081   edm::ESHandle<CSCBadChambers> pBadChambers;
00082   setup.get<CSCBadChambersRcd>().get(pBadChambers);
00083 
00084   // If !debugParameters then get config parameters using EventSetup mechanism.
00085   // This must be done in produce() for every event and not in beginJob() 
00086   // (see mail from Jim Brooke sent to hn-cms-L1TrigEmulator on July 30, 2007).
00087   if (!debugParameters_) {
00088     edm::ESHandle<CSCDBL1TPParameters> conf;
00089     setup.get<CSCDBL1TPParametersRcd>().get(conf);
00090     if (conf.product() == 0) {
00091       edm::LogError("L1CSCTPEmulatorConfigError")
00092         << "+++ Failed to find a CSCDBL1TPParametersRcd in EventSetup! +++\n"
00093         << "+++ Cannot continue emulation without these parameters +++\n";
00094       return;
00095     }
00096     lctBuilder_->setConfigParameters(conf.product());
00097   }
00098   
00099   // Get the collections of comparator & wire digis from event.
00100   edm::Handle<CSCComparatorDigiCollection> compDigis;
00101   edm::Handle<CSCWireDigiCollection>       wireDigis;
00102   ev.getByLabel(compDigiProducer_.label(), compDigiProducer_.instance(), compDigis);
00103   ev.getByLabel(wireDigiProducer_.label(), wireDigiProducer_.instance(), wireDigis);
00104 
00105   // Create empty collections of ALCTs, CLCTs, and correlated LCTs upstream
00106   // and downstream of MPC.
00107   std::auto_ptr<CSCALCTDigiCollection> oc_alct(new CSCALCTDigiCollection);
00108   std::auto_ptr<CSCCLCTDigiCollection> oc_clct(new CSCCLCTDigiCollection);
00109   std::auto_ptr<CSCCLCTPreTriggerCollection> oc_pretrig(new CSCCLCTPreTriggerCollection);
00110   std::auto_ptr<CSCCorrelatedLCTDigiCollection> oc_lct(new CSCCorrelatedLCTDigiCollection);
00111   std::auto_ptr<CSCCorrelatedLCTDigiCollection> oc_sorted_lct(new CSCCorrelatedLCTDigiCollection);
00112 
00113   if (!wireDigis.isValid()) {
00114     edm::LogWarning("L1CSCTPEmulatorNoInputCollection")
00115       << "+++ Warning: Collection of wire digis with label "
00116       << wireDigiProducer_.label()
00117       << " requested in configuration, but not found in the event..."
00118       << " Skipping production of CSC TP digis +++\n";
00119   }
00120   if (!compDigis.isValid()) {
00121     edm::LogWarning("L1CSCTPEmulatorNoInputCollection")
00122       << "+++ Warning: Collection of comparator digis with label "
00123       << compDigiProducer_.label()
00124       << " requested in configuration, but not found in the event..."
00125       << " Skipping production of CSC TP digis +++\n";
00126   }
00127   // Fill output collections if valid input collections are available.
00128   if (wireDigis.isValid() && compDigis.isValid()) {   
00129     const CSCBadChambers* temp = checkBadChambers_ ? pBadChambers.product() : new CSCBadChambers;
00130     lctBuilder_->build(temp,
00131                        wireDigis.product(), compDigis.product(),
00132                        *oc_alct, *oc_clct, *oc_pretrig, *oc_lct, *oc_sorted_lct);
00133     if (!checkBadChambers_)
00134       delete temp;
00135   }
00136 
00137   // Put collections in event.
00138   ev.put(oc_alct);
00139   ev.put(oc_clct);
00140   ev.put(oc_pretrig);
00141   ev.put(oc_lct);
00142   ev.put(oc_sorted_lct,"MPCSORTED");
00143 }