CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
APVShotsFilter.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: APVShotsFilter
4 // Class: APVShotsFilter
5 //
13 //
14 // Original Author: Mia Tosi,40 3-B32,+41227671551,
15 // Created: Sun Nov 10 11:30:51 CET 2013
16 // $Id$
17 //
18 //
19 
20 
21 // system include files
22 #include <memory>
23 
24 // user include files
28 
31 
33 
35 
38 
41 
44 
45 //******** includes for the cabling *************
50 //***************************************************
51 
52 //
53 // class declaration
54 //
55 
56 class APVShotsFilter : public edm::EDFilter {
57  public:
58  explicit APVShotsFilter(const edm::ParameterSet&);
60 
61  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
62 
63  private:
64  virtual void beginJob() ;
65  virtual bool filter(edm::Event&, const edm::EventSetup&);
66  virtual void endJob() ;
67 
68  virtual bool beginRun(edm::Run&, edm::EventSetup const&);
69  virtual bool endRun(edm::Run&, edm::EventSetup const&);
72 
73  void updateDetCabling( const edm::EventSetup& setup );
74  // ----------member data ---------------------------
75 
76 
80 
82 
83  bool _zs;
84  int _nevents;
85 
86  // DetCabling
88  uint32_t _cacheIdDet;
90 
91 };
92 
93 //
94 // constants, enums and typedefs
95 //
96 
97 //
98 // static data member definitions
99 //
100 
101 //
102 // constructors and destructor
103 //
105  : _selectAPVshots (iConfig.getUntrackedParameter<bool>("selectAPVshots", true))
106  , _zs (iConfig.getUntrackedParameter<bool>("zeroSuppressed",true))
107  , _nevents(0)
108  , _useCabling (iConfig.getUntrackedParameter<bool>("useCabling",true))
109  , _cacheIdDet(0)
110  , _detCabling(0)
111 
112 {
113  //now do what ever initialization is needed
114  edm::InputTag digicollection = iConfig.getParameter<edm::InputTag>("digiCollection");
115  edm::InputTag historyProduct = iConfig.getParameter<edm::InputTag>("historyProduct");
116  edm::InputTag apvphasecoll = iConfig.getParameter<edm::InputTag>("apvPhaseCollection");
117 
118  heToken_ = consumes<EventWithHistory> (historyProduct);
119  apvphaseToken_ = consumes<APVCyclePhaseCollection> (apvphasecoll);
120  digisToken_ = consumes<edm::DetSetVector<SiStripDigi> >(digicollection);
121 
122 }
123 
124 
126 {
127 
128  // do anything here that needs to be done at desctruction time
129  // (e.g. close files, deallocate resources etc.)
130  if ( _detCabling ) _detCabling = 0;
131 
132 }
133 
134 
135 //
136 // member functions
137 //
138 
139 // ------------ method called on each new Event ------------
140 bool
142 {
143  using namespace edm;
144 
145  if (_useCabling){
146  //retrieve cabling
147  updateDetCabling( iSetup );
148  }
149  _nevents++;
150 
152  iEvent.getByToken(heToken_,he);
153 
155  iEvent.getByToken(apvphaseToken_,apvphase);
156 
158  iEvent.getByToken(digisToken_,digis);
159 
160  // loop on detector with digis
161  int nshots = 0;
162  std::vector<int> nshotsperFed;
163 
164  const int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
165  const int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
166  const uint16_t lNumFeds = (siStripFedIdMax-siStripFedIdMin)+1;
167  if (_useCabling){
168  nshotsperFed.resize(lNumFeds,0);
169  }
170 
171  APVShotFinder apvsf(*digis,_zs);
172  const std::vector<APVShot>& shots = apvsf.getShots();
173 
174  for (std::vector<APVShot>::const_iterator shot=shots.begin(); shot!=shots.end(); ++shot) {
175  if ( !shot->isGenuine() ) continue;
176  ++nshots;
177 
178  //get the fedid from the detid
179  uint32_t det=shot->detId();
180  if (_useCabling){
181 
182  int apvPair = shot->apvNumber()/2;
183  LogDebug("APVShotsFilter") << apvPair;
184 
185  const FedChannelConnection& theConn = _detCabling->getConnection( det , apvPair);
186 
187  int lChannelId = -1;
188  int thelFEDId = -1;
189  if(theConn.isConnected()) {
190  lChannelId = theConn.fedCh();
191  thelFEDId = theConn.fedId();
192  }
193  else {
194  edm::LogWarning("APVShotsFilter") << "connection of det " << det << " APV pair " << apvPair << " not found";
195  }
196  LogDebug("APVShotsFilter") << thelFEDId << " " << lChannelId ;
197 
198  const std::vector<const FedChannelConnection *> & conns = _detCabling->getConnections( det );
199 
200  if (!(conns.size())) continue;
201  uint16_t lFedId = 0;
202  for (uint32_t ch = 0; ch<conns.size(); ch++) {
203  if(conns[ch] && conns[ch]->isConnected()) {
204  LogDebug("APVShotsFilter") << *(conns[ch]);
205  LogDebug("APVShotsFilter") << "Ready for FED id " << ch;
206  lFedId = conns[ch]->fedId();
207  LogDebug("APVShotsFilter") << "obtained FED id " << ch << " " << lFedId;
208  //uint16_t lFedCh = conns[ch]->fedCh();
209 
210  if (lFedId < sistrip::FED_ID_MIN || lFedId > sistrip::FED_ID_MAX){
211  edm::LogWarning("APVShotsFilter") << lFedId << " for detid " << det << " connection " << ch;
212  continue;
213  }
214  else break;
215  }
216  }
217  if (lFedId < sistrip::FED_ID_MIN || lFedId > sistrip::FED_ID_MAX){
218  edm::LogWarning("APVShotsFilter") << lFedId << "found for detid " << det;
219  continue;
220  }
221 
222  if(lFedId != thelFEDId) {
223  edm::LogWarning("APVShotsFilter") << " Mismatch in FED id for det " << det << " APV pair "
224  << apvPair << " : " << lFedId << " vs " << thelFEDId;
225  }
226 
227  // LogDebug("APVShotsFilter") << nshotsperfed.size() << " " << lFedId-sistrip::FED_ID_MIN;
228  // ++nshotsperFed[lFedId-FEDNumbering::MINSiStripFEDID];
229 
230  LogDebug("APVShotsFilter") << " ready to be filled with " << thelFEDId << " " << lChannelId;
231  LogDebug("APVShotsFilter") << " filled with " << thelFEDId << " " << lChannelId;
232 
233  }
234  }
235 
236  bool foundAPVshots = (nshots > 0);
237  bool pass = (_selectAPVshots ? foundAPVshots : !foundAPVshots);
238  return pass;
239 }
240 
241 // ------------ method called once each job just before starting event loop ------------
242 void
244 {
245 }
246 
247 // ------------ method called once each job just after ending the event loop ------------
248 void
250 
251  edm::LogInfo("APVShotsFilter") << _nevents << " analyzed events";
252 
253 }
254 
255 // ------------ method called when starting to processes a run ------------
256 bool
258 {
259  return true;
260 }
261 
262 // ------------ method called when ending the processing of a run ------------
263 bool
265 {
266  return true;
267 }
268 
269 // ------------ method called when starting to processes a luminosity block ------------
270 bool
272 {
273  return true;
274 }
275 
276 // ------------ method called when ending the processing of a luminosity block ------------
277 bool
279 {
280  return true;
281 }
282 
284 void
286 {
287  if (_useCabling){
288  uint32_t cache_id = setup.get<SiStripDetCablingRcd>().cacheIdentifier();//.get( cabling_ );
289 
290  if ( _cacheIdDet != cache_id ) { // If the cache ID has changed since the last update...
291  // Update the cabling object
293  setup.get<SiStripDetCablingRcd>().get( c );
294  _detCabling = c.product();
295  _cacheIdDet = cache_id;
296  } // end of new cache ID check
297  }
298 }
299 
300 
301 
302 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
303 void
305  //The following says we do not know what parameters are allowed so do no validation
306  // Please change this to state exactly what you do use, even if it is no parameters
308  desc.setUnknown();
309  descriptions.addDefault(desc);
310 }
311 //define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
const SiStripDetCabling * _detCabling
The cabling object.
virtual bool filter(edm::Event &, const edm::EventSetup &)
virtual void beginJob()
const FedChannelConnection & getConnection(uint32_t det_id, unsigned short apv_pair) const
edm::EDGetTokenT< edm::DetSetVector< SiStripDigi > > digisToken_
const uint16_t & fedCh() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:464
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
edm::EDGetTokenT< APVCyclePhaseCollection > apvphaseToken_
const uint16_t & fedId() const
virtual void endJob()
const std::vector< const FedChannelConnection * > & getConnections(uint32_t det_id) const
virtual bool endRun(edm::Run &, edm::EventSetup const &)
const std::vector< APVShot > & getShots() const
int iEvent
Definition: GenABIO.cc:230
void addDefault(ParameterSetDescription const &psetDescription)
APVShotsFilter(const edm::ParameterSet &)
void updateDetCabling(const edm::EventSetup &setup)
Class containning control, module, detector and connection information, at the level of a FED channel...
virtual bool endLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
virtual bool beginLuminosityBlock(edm::LuminosityBlock &, edm::EventSetup const &)
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
uint32_t _cacheIdDet
DB cache ID used to establish if the cabling has changed during the run.
const T & get() const
Definition: EventSetup.h:56
virtual bool beginRun(edm::Run &, edm::EventSetup const &)
T const * product() const
Definition: ESHandle.h:86
edm::EDGetTokenT< EventWithHistory > heToken_
static const uint16_t FED_ID_MAX
void setup(std::vector< TH2F > &depth, std::string name, std::string units="")
Definition: Run.h:43