CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/DQM/SiStripMonitorHardware/plugins/SiStripShotFilter.cc

Go to the documentation of this file.
00001 
00002 // -*- C++ -*-
00003 //
00004 // Class:      SiStripShotFilterPlugins
00005 // 
00006 /* Description: DQM source application to filter "shots" for SiStrip data
00007 */
00008 //
00009 //         Created:  2009/12/07
00010 // $Id: SiStripShotFilter.cc,v 1.4 2010/04/21 10:40:20 amagnan Exp $
00011 //
00012 
00013 #include <sstream>
00014 #include <fstream>
00015 #include <iostream>
00016 #include <memory>
00017 #include <list>
00018 #include <algorithm>
00019 #include <cassert>
00020 
00021 #include "FWCore/Framework/interface/Frameworkfwd.h"
00022 #include "FWCore/Framework/interface/EDFilter.h"
00023 #include "FWCore/Framework/interface/Event.h"
00024 #include "FWCore/Framework/interface/EventSetup.h"
00025 #include "FWCore/Framework/interface/ESHandle.h"
00026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00027 #include "FWCore/Utilities/interface/InputTag.h"
00028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00029 #include "FWCore/ServiceRegistry/interface/Service.h"
00030 #include "FWCore/Utilities/interface/Exception.h"
00031 
00032 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00033 #include "DataFormats/FEDRawData/interface/FEDRawData.h"
00034 #include "DataFormats/FEDRawData/interface/FEDNumbering.h"
00035 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
00036 #include "DataFormats/DetId/interface/DetId.h"
00037 
00038 #include "CondFormats/DataRecord/interface/SiStripFedCablingRcd.h"
00039 #include "CondFormats/SiStripObjects/interface/SiStripFedCabling.h"
00040 
00041 #include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBuffer.h"
00042 
00043 #include "DataFormats/Common/interface/DetSetVector.h"
00044 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00045 
00046 #include "DPGAnalysis/SiStripTools/interface/APVShotFinder.h"
00047 #include "DPGAnalysis/SiStripTools/interface/APVShot.h"
00048 
00049 //
00050 // Class declaration
00051 //
00052 
00053 class SiStripShotFilter : public edm::EDFilter
00054 {
00055  public:
00056 
00057   explicit SiStripShotFilter(const edm::ParameterSet&);
00058   ~SiStripShotFilter();
00059  private:
00060 
00061   virtual void beginJob();
00062   virtual bool filter(edm::Event&, const edm::EventSetup&);
00063   virtual void endJob();
00064 
00065   //update the cabling if necessary
00066   void updateCabling(const edm::EventSetup& eventSetup);
00067 
00068   //path to output file
00069   std::ofstream fOut_;
00070   std::string fOutPath_;
00071   //FED cabling
00072   uint32_t cablingCacheId_;
00073   const SiStripFedCabling* cabling_;
00074 
00075   edm::InputTag digicollection_;
00076   bool zs_;
00077 
00078 };
00079 
00080 
00081 //
00082 // Constructors and destructor
00083 //
00084 
00085 SiStripShotFilter::SiStripShotFilter(const edm::ParameterSet& iConfig)
00086   : fOutPath_(iConfig.getUntrackedParameter<std::string>("OutputFilePath","shotChannels.dat")),
00087     cablingCacheId_(0),
00088     digicollection_(iConfig.getParameter<edm::InputTag>("DigiCollection")),
00089     zs_(iConfig.getUntrackedParameter<bool>("ZeroSuppressed",true))
00090  
00091 {
00092 
00093 }
00094 
00095 SiStripShotFilter::~SiStripShotFilter()
00096 {
00097 }
00098 
00099 
00100 //
00101 // Member functions
00102 //
00103 
00104 // ------------ method called to for each event  ------------
00105 bool
00106 SiStripShotFilter::filter(edm::Event& iEvent, 
00107                                  const edm::EventSetup& iSetup)
00108 {
00109 
00110   //update cabling
00111   updateCabling(iSetup);
00112   
00113   //get digi data
00114   edm::Handle<edm::DetSetVector<SiStripDigi> > digis;
00115   iEvent.getByLabel(digicollection_,digis);
00116 
00117   // loop on detector with digis
00118 
00119   APVShotFinder apvsf(*digis,zs_);
00120   const std::vector<APVShot>& shots = apvsf.getShots();
00121 
00122   //loop on feds first: there should be only a small number of shots...
00123   //better to loop only once on all channels....
00124   //to be able to output both fed/ch and module/APV.
00125 
00126   unsigned int lShots = 0;
00127 
00128   for (unsigned int fedId = FEDNumbering::MINSiStripFEDID; 
00129        fedId <= FEDNumbering::MAXSiStripFEDID; 
00130        fedId++) {//loop over FED IDs
00131 
00132     for (unsigned int iCh = 0; 
00133          iCh < sistrip::FEDCH_PER_FED; 
00134          iCh++) {//loop on channels
00135           
00136       const FedChannelConnection & lConnection = cabling_->connection(fedId,iCh);
00137 
00138       uint32_t lDetId = lConnection.detId();
00139       short lAPVPair = lConnection.apvPairNumber();
00140 
00141       for(std::vector<APVShot>::const_iterator shot=shots.begin();shot!=shots.end();++shot) {//loop on shots
00142 
00143         if (shot->detId() == lDetId && 
00144             static_cast<short>(shot->apvNumber()/2.) == lAPVPair)
00145           {
00146             if(shot->isGenuine()) {//genuine shot
00147   
00148               fOut_ << fedId << " " << iCh << " " << shot->detId() << " " << shot->apvNumber() << std::endl;
00149               lShots++;
00150             }//genuine shot
00151             if (shot->apvNumber()%2==1) break;
00152           }
00153       }//loop on shots
00154     }//loop on channels
00155   }//loop on FEDs.
00156 
00157   if (lShots > 0) fOut_ << "### " << iEvent.id().event() << " " << lShots << std::endl;
00158 
00159   return lShots;
00160 
00161 }//analyze method
00162 
00163 // ------------ method called once each job just before starting event loop  ------------
00164 void 
00165 SiStripShotFilter::beginJob()
00166 {
00167   fOut_.open(fOutPath_.c_str(),std::ios::out);
00168   if (!fOut_) std::cout << " WARNING ! Cannot open file " << fOutPath_ << " for writting. List of shot channels will not be saved." << std::endl;
00169 }
00170 
00171 // ------------ method called once each job just after ending the event loop  ------------
00172 void 
00173 SiStripShotFilter::endJob()
00174 {
00175 
00176   fOut_.close();
00177 
00178 }
00179 
00180 void SiStripShotFilter::updateCabling(const edm::EventSetup& eventSetup)
00181 {
00182   uint32_t currentCacheId = eventSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
00183   if (cablingCacheId_ != currentCacheId) {
00184     edm::ESHandle<SiStripFedCabling> cablingHandle;
00185     eventSetup.get<SiStripFedCablingRcd>().get(cablingHandle);
00186     cabling_ = cablingHandle.product();
00187     cablingCacheId_ = currentCacheId;
00188   }
00189 }
00190 
00191 #include "FWCore/Framework/interface/MakerMacros.h"
00192 DEFINE_FWK_MODULE(SiStripShotFilter);