CMS 3D CMS Logo

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&);
59  ~APVShotsFilter() override;
60 
61  static void fillDescriptions(edm::ConfigurationDescriptions& descriptions);
62 
63  private:
64  bool filter(edm::Event&, const edm::EventSetup&) override;
65  void endJob() override ;
66 
67  void updateDetCabling( const edm::EventSetup& setup );
68  // ----------member data ---------------------------
69 
70 
74 
76 
77  bool _zs;
78  int _nevents;
79 
80  // DetCabling
82  uint32_t _cacheIdDet;
84 
85 };
86 
87 //
88 // constants, enums and typedefs
89 //
90 
91 //
92 // static data member definitions
93 //
94 
95 //
96 // constructors and destructor
97 //
99  : _selectAPVshots (iConfig.getUntrackedParameter<bool>("selectAPVshots", true))
100  , _zs (iConfig.getUntrackedParameter<bool>("zeroSuppressed",true))
101  , _nevents(0)
102  , _useCabling (iConfig.getUntrackedParameter<bool>("useCabling",true))
103  , _cacheIdDet(0)
105 
106 {
107  //now do what ever initialization is needed
108  edm::InputTag digicollection = iConfig.getParameter<edm::InputTag>("digiCollection");
109  edm::InputTag historyProduct = iConfig.getParameter<edm::InputTag>("historyProduct");
110  edm::InputTag apvphasecoll = iConfig.getParameter<edm::InputTag>("apvPhaseCollection");
111 
112  heToken_ = consumes<EventWithHistory> (historyProduct);
113  apvphaseToken_ = consumes<APVCyclePhaseCollection> (apvphasecoll);
114  digisToken_ = consumes<edm::DetSetVector<SiStripDigi> >(digicollection);
115 
116 }
117 
118 
120 {
121 
122  // do anything here that needs to be done at desctruction time
123  // (e.g. close files, deallocate resources etc.)
124  if ( _detCabling ) _detCabling = nullptr;
125 
126 }
127 
128 
129 //
130 // member functions
131 //
132 
133 // ------------ method called on each new Event ------------
134 bool
136 {
137  using namespace edm;
138 
139  if (_useCabling){
140  //retrieve cabling
141  updateDetCabling( iSetup );
142  }
143  _nevents++;
144 
146  iEvent.getByToken(heToken_,he);
147 
149  iEvent.getByToken(apvphaseToken_,apvphase);
150 
152  iEvent.getByToken(digisToken_,digis);
153 
154  // loop on detector with digis
155  int nshots = 0;
156  std::vector<int> nshotsperFed;
157 
158  const int siStripFedIdMin = FEDNumbering::MINSiStripFEDID;
159  const int siStripFedIdMax = FEDNumbering::MAXSiStripFEDID;
160  const uint16_t lNumFeds = (siStripFedIdMax-siStripFedIdMin)+1;
161  if (_useCabling){
162  nshotsperFed.resize(lNumFeds,0);
163  }
164 
165  APVShotFinder apvsf(*digis,_zs);
166  const std::vector<APVShot>& shots = apvsf.getShots();
167 
168  for (std::vector<APVShot>::const_iterator shot=shots.begin(); shot!=shots.end(); ++shot) {
169  if ( !shot->isGenuine() ) continue;
170  ++nshots;
171 
172  //get the fedid from the detid
173  uint32_t det=shot->detId();
174  if (_useCabling){
175 
176  int apvPair = shot->apvNumber()/2;
177  LogDebug("APVShotsFilter") << apvPair;
178 
179  const FedChannelConnection& theConn = _detCabling->getConnection( det , apvPair);
180 
181  int lChannelId = -1;
182  int thelFEDId = -1;
183  if(theConn.isConnected()) {
184  lChannelId = theConn.fedCh();
185  thelFEDId = theConn.fedId();
186  }
187  else {
188  edm::LogWarning("APVShotsFilter") << "connection of det " << det << " APV pair " << apvPair << " not found";
189  }
190  LogDebug("APVShotsFilter") << thelFEDId << " " << lChannelId ;
191 
192  const std::vector<const FedChannelConnection *> & conns = _detCabling->getConnections( det );
193 
194  if (!(conns.size())) continue;
195  uint16_t lFedId = 0;
196  for (uint32_t ch = 0; ch<conns.size(); ch++) {
197  if(conns[ch] && conns[ch]->isConnected()) {
198  LogDebug("APVShotsFilter") << *(conns[ch]);
199  LogDebug("APVShotsFilter") << "Ready for FED id " << ch;
200  lFedId = conns[ch]->fedId();
201  LogDebug("APVShotsFilter") << "obtained FED id " << ch << " " << lFedId;
202  //uint16_t lFedCh = conns[ch]->fedCh();
203 
204  if (lFedId < sistrip::FED_ID_MIN || lFedId > sistrip::FED_ID_MAX){
205  edm::LogWarning("APVShotsFilter") << lFedId << " for detid " << det << " connection " << ch;
206  continue;
207  }
208  else break;
209  }
210  }
211  if (lFedId < sistrip::FED_ID_MIN || lFedId > sistrip::FED_ID_MAX){
212  edm::LogWarning("APVShotsFilter") << lFedId << "found for detid " << det;
213  continue;
214  }
215 
216  if(lFedId != thelFEDId) {
217  edm::LogWarning("APVShotsFilter") << " Mismatch in FED id for det " << det << " APV pair "
218  << apvPair << " : " << lFedId << " vs " << thelFEDId;
219  }
220 
221  // LogDebug("APVShotsFilter") << nshotsperfed.size() << " " << lFedId-sistrip::FED_ID_MIN;
222  // ++nshotsperFed[lFedId-FEDNumbering::MINSiStripFEDID];
223 
224  LogDebug("APVShotsFilter") << " ready to be filled with " << thelFEDId << " " << lChannelId;
225  LogDebug("APVShotsFilter") << " filled with " << thelFEDId << " " << lChannelId;
226 
227  }
228  }
229 
230  bool foundAPVshots = (nshots > 0);
231  bool pass = (_selectAPVshots ? foundAPVshots : !foundAPVshots);
232  return pass;
233 }
234 
235 // ------------ method called once each job just after ending the event loop ------------
236 void
238 
239  edm::LogInfo("APVShotsFilter") << _nevents << " analyzed events";
240 
241 }
242 
244 void
246 {
247  if (_useCabling){
248  uint32_t cache_id = setup.get<SiStripDetCablingRcd>().cacheIdentifier();//.get( cabling_ );
249 
250  if ( _cacheIdDet != cache_id ) { // If the cache ID has changed since the last update...
251  // Update the cabling object
253  setup.get<SiStripDetCablingRcd>().get( c );
254  _detCabling = c.product();
255  _cacheIdDet = cache_id;
256  } // end of new cache ID check
257  }
258 }
259 
260 
261 
262 // ------------ method fills 'descriptions' with the allowed parameters for the module ------------
263 void
265  //The following says we do not know what parameters are allowed so do no validation
266  // Please change this to state exactly what you do use, even if it is no parameters
268  desc.setUnknown();
269  descriptions.addDefault(desc);
270 }
271 //define this as a plug-in
#define LogDebug(id)
T getParameter(std::string const &) const
const SiStripDetCabling * _detCabling
The cabling object.
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:517
#define nullptr
void endJob() override
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:2
edm::EDGetTokenT< APVCyclePhaseCollection > apvphaseToken_
const uint16_t & fedId() const
~APVShotsFilter() override
const std::vector< const FedChannelConnection * > & getConnections(uint32_t det_id) const
const std::vector< APVShot > & getShots() const
int iEvent
Definition: GenABIO.cc:224
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
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...
static void fillDescriptions(edm::ConfigurationDescriptions &descriptions)
uint32_t _cacheIdDet
DB cache ID used to establish if the cabling has changed during the run.
edm::EDGetTokenT< EventWithHistory > heToken_
HLT enums.
T get() const
Definition: EventSetup.h:71
static const uint16_t FED_ID_MAX
T const * product() const
Definition: ESHandle.h:86
bool filter(edm::Event &, const edm::EventSetup &) override