CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripShotFilter.cc
Go to the documentation of this file.
1 
2 // -*- C++ -*-
3 //
4 // Class: SiStripShotFilterPlugins
5 //
6 /* Description: DQM source application to filter "shots" for SiStrip data
7 */
8 //
9 // Created: 2009/12/07
10 //
11 
12 #include <sstream>
13 #include <fstream>
14 #include <iostream>
15 #include <memory>
16 #include <list>
17 #include <algorithm>
18 #include <cassert>
19 
31 
37 
40 
42 
45 
48 
49 //
50 // Class declaration
51 //
52 
54 {
55  public:
56 
57  explicit SiStripShotFilter(const edm::ParameterSet&);
59  private:
60 
61  virtual void beginJob() override;
62  virtual bool filter(edm::Event&, const edm::EventSetup&) override;
63  virtual void endJob() override;
64 
65  //update the cabling if necessary
66  void updateCabling(const edm::EventSetup& eventSetup);
67 
68  //path to output file
69  std::ofstream fOut_;
71  //FED cabling
72  uint32_t cablingCacheId_;
74 
77  bool zs_;
78 
79 };
80 
81 
82 //
83 // Constructors and destructor
84 //
85 
87  : fOutPath_(iConfig.getUntrackedParameter<std::string>("OutputFilePath","shotChannels.dat")),
88  cablingCacheId_(0),
89  digicollection_(iConfig.getParameter<edm::InputTag>("DigiCollection")),
90  zs_(iConfig.getUntrackedParameter<bool>("ZeroSuppressed",true))
91 
92 {
93 
94  digiToken_ = consumes<edm::DetSetVector<SiStripDigi> >(digicollection_);
95 
96 }
97 
99 {
100 }
101 
102 
103 //
104 // Member functions
105 //
106 
107 // ------------ method called to for each event ------------
108 bool
110  const edm::EventSetup& iSetup)
111 {
112 
113  //update cabling
114  updateCabling(iSetup);
115 
116  //get digi data
118  iEvent.getByToken(digiToken_,digis);
119 
120  // loop on detector with digis
121 
122  APVShotFinder apvsf(*digis,zs_);
123  const std::vector<APVShot>& shots = apvsf.getShots();
124 
125  //loop on feds first: there should be only a small number of shots...
126  //better to loop only once on all channels....
127  //to be able to output both fed/ch and module/APV.
128 
129  unsigned int lShots = 0;
130 
131  for (unsigned int fedId = FEDNumbering::MINSiStripFEDID;
133  fedId++) {//loop over FED IDs
134 
135  for (unsigned int iCh = 0;
136  iCh < sistrip::FEDCH_PER_FED;
137  iCh++) {//loop on channels
138 
139  const FedChannelConnection & lConnection = cabling_->fedConnection(fedId,iCh);
140 
141  uint32_t lDetId = lConnection.detId();
142  short lAPVPair = lConnection.apvPairNumber();
143 
144  for(std::vector<APVShot>::const_iterator shot=shots.begin();shot!=shots.end();++shot) {//loop on shots
145 
146  if (shot->detId() == lDetId &&
147  static_cast<short>(shot->apvNumber()/2.) == lAPVPair)
148  {
149  if(shot->isGenuine()) {//genuine shot
150 
151  fOut_ << fedId << " " << iCh << " " << shot->detId() << " " << shot->apvNumber() << std::endl;
152  lShots++;
153  }//genuine shot
154  if (shot->apvNumber()%2==1) break;
155  }
156  }//loop on shots
157  }//loop on channels
158  }//loop on FEDs.
159 
160  if (lShots > 0) fOut_ << "### " << iEvent.id().event() << " " << lShots << std::endl;
161 
162  return lShots;
163 
164 }//analyze method
165 
166 // ------------ method called once each job just before starting event loop ------------
167 void
169 {
170  fOut_.open(fOutPath_.c_str(),std::ios::out);
171  if (!fOut_) std::cout << " WARNING ! Cannot open file " << fOutPath_ << " for writting. List of shot channels will not be saved." << std::endl;
172 }
173 
174 // ------------ method called once each job just after ending the event loop ------------
175 void
177 {
178 
179  fOut_.close();
180 
181 }
182 
184 {
185  uint32_t currentCacheId = eventSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
186  if (cablingCacheId_ != currentCacheId) {
187  edm::ESHandle<SiStripFedCabling> cablingHandle;
188  eventSetup.get<SiStripFedCablingRcd>().get(cablingHandle);
189  cabling_ = cablingHandle.product();
190  cablingCacheId_ = currentCacheId;
191  }
192 }
193 
EventNumber_t event() const
Definition: EventID.h:41
const SiStripFedCabling * cabling_
FedChannelConnection fedConnection(uint16_t fed_id, uint16_t fed_ch) const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
uint16_t apvPairNumber() const
SiStripShotFilter(const edm::ParameterSet &)
virtual void endJob() override
void updateCabling(const edm::EventSetup &eventSetup)
const std::vector< APVShot > & getShots() const
int iEvent
Definition: GenABIO.cc:230
virtual bool filter(edm::Event &, const edm::EventSetup &) override
const uint32_t & detId() const
Class containning control, module, detector and connection information, at the level of a FED channel...
virtual void beginJob() override
edm::InputTag digicollection_
tuple out
Definition: dbtoconf.py:99
const T & get() const
Definition: EventSetup.h:56
T const * product() const
Definition: ESHandle.h:86
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
edm::EventID id() const
Definition: EventBase.h:60
static const uint16_t FEDCH_PER_FED
edm::EDGetTokenT< edm::DetSetVector< SiStripDigi > > digiToken_
tuple cout
Definition: gather_cfg.py:121