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 // $Id: SiStripShotFilter.cc,v 1.4 2010/04/21 10:40:20 amagnan Exp $
11 //
12 
13 #include <sstream>
14 #include <fstream>
15 #include <iostream>
16 #include <memory>
17 #include <list>
18 #include <algorithm>
19 #include <cassert>
20 
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();
62  virtual bool filter(edm::Event&, const edm::EventSetup&);
63  virtual void endJob();
64 
65  //update the cabling if necessary
66  void updateCabling(const edm::EventSetup& eventSetup);
67 
68  //path to output file
69  std::ofstream fOut_;
70  std::string fOutPath_;
71  //FED cabling
72  uint32_t cablingCacheId_;
74 
76  bool zs_;
77 
78 };
79 
80 
81 //
82 // Constructors and destructor
83 //
84 
86  : fOutPath_(iConfig.getUntrackedParameter<std::string>("OutputFilePath","shotChannels.dat")),
87  cablingCacheId_(0),
88  digicollection_(iConfig.getParameter<edm::InputTag>("DigiCollection")),
89  zs_(iConfig.getUntrackedParameter<bool>("ZeroSuppressed",true))
90 
91 {
92 
93 }
94 
96 {
97 }
98 
99 
100 //
101 // Member functions
102 //
103 
104 // ------------ method called to for each event ------------
105 bool
107  const edm::EventSetup& iSetup)
108 {
109 
110  //update cabling
111  updateCabling(iSetup);
112 
113  //get digi data
115  iEvent.getByLabel(digicollection_,digis);
116 
117  // loop on detector with digis
118 
119  APVShotFinder apvsf(*digis,zs_);
120  const std::vector<APVShot>& shots = apvsf.getShots();
121 
122  //loop on feds first: there should be only a small number of shots...
123  //better to loop only once on all channels....
124  //to be able to output both fed/ch and module/APV.
125 
126  unsigned int lShots = 0;
127 
128  for (unsigned int fedId = FEDNumbering::MINSiStripFEDID;
130  fedId++) {//loop over FED IDs
131 
132  for (unsigned int iCh = 0;
133  iCh < sistrip::FEDCH_PER_FED;
134  iCh++) {//loop on channels
135 
136  const FedChannelConnection & lConnection = cabling_->connection(fedId,iCh);
137 
138  uint32_t lDetId = lConnection.detId();
139  short lAPVPair = lConnection.apvPairNumber();
140 
141  for(std::vector<APVShot>::const_iterator shot=shots.begin();shot!=shots.end();++shot) {//loop on shots
142 
143  if (shot->detId() == lDetId &&
144  static_cast<short>(shot->apvNumber()/2.) == lAPVPair)
145  {
146  if(shot->isGenuine()) {//genuine shot
147 
148  fOut_ << fedId << " " << iCh << " " << shot->detId() << " " << shot->apvNumber() << std::endl;
149  lShots++;
150  }//genuine shot
151  if (shot->apvNumber()%2==1) break;
152  }
153  }//loop on shots
154  }//loop on channels
155  }//loop on FEDs.
156 
157  if (lShots > 0) fOut_ << "### " << iEvent.id().event() << " " << lShots << std::endl;
158 
159  return lShots;
160 
161 }//analyze method
162 
163 // ------------ method called once each job just before starting event loop ------------
164 void
166 {
167  fOut_.open(fOutPath_.c_str(),std::ios::out);
168  if (!fOut_) std::cout << " WARNING ! Cannot open file " << fOutPath_ << " for writting. List of shot channels will not be saved." << std::endl;
169 }
170 
171 // ------------ method called once each job just after ending the event loop ------------
172 void
174 {
175 
176  fOut_.close();
177 
178 }
179 
181 {
182  uint32_t currentCacheId = eventSetup.get<SiStripFedCablingRcd>().cacheIdentifier();
183  if (cablingCacheId_ != currentCacheId) {
184  edm::ESHandle<SiStripFedCabling> cablingHandle;
185  eventSetup.get<SiStripFedCablingRcd>().get(cablingHandle);
186  cabling_ = cablingHandle.product();
187  cablingCacheId_ = currentCacheId;
188  }
189 }
190 
EventNumber_t event() const
Definition: EventID.h:44
const SiStripFedCabling * cabling_
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
uint16_t apvPairNumber() const
const FedChannelConnection & connection(uint16_t fed_id, uint16_t fed_ch) const
SiStripShotFilter(const edm::ParameterSet &)
virtual bool filter(edm::Event &, const edm::EventSetup &)
void updateCabling(const edm::EventSetup &eventSetup)
const std::vector< APVShot > & getShots() const
int iEvent
Definition: GenABIO.cc:243
const uint32_t & detId() const
Class containning control, module, detector and connection information, at the level of a FED channel...
virtual void endJob()
edm::InputTag digicollection_
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:356
virtual void beginJob()
tuple out
Definition: dbtoconf.py:99
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:62
Contains cabling info at the device level, including DetId, APV pair numbers, hardware addresses...
edm::EventID id() const
Definition: EventBase.h:56
static const uint16_t FEDCH_PER_FED
tuple cout
Definition: gather_cfg.py:121