CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SiStripSpyDisplayModule.cc
Go to the documentation of this file.
1 /* \file SiStripSpyDisplayModule.cc
2  * \brief File containing code for the SiStripMonitorFEDProcessing plugin module.
3  */
4 // -*- C++ -*-
5 //
6 // Package: SiStripMonitorHardware
7 // Class: SiStripSpyDisplayModule
8 //
9 // Standard
10 #include <memory>
11 #include <vector>
12 #include <iostream>
13 #include <string>
14 #include <sstream>
15 
16 // Framework include files
23 
24 // Needed for the SST cabling
28 
29 // Needed for the pedestal values
32 
33 // Needed for the noise values
36 
37 // For translating between FED key and det ID
39 
46 
47 // Needed for the FED raw data processing
51 
52 //for cabling
54 
55 // For plotting
58 #include "TH1S.h"
59 #include "TH1D.h"
60 
61 //
62 // constants, enums and typedefs
63 //
76 
77 //
78 // class declaration
79 //
80 
81 
94  public:
97 
98  private:
99  virtual void beginRun(const edm::Run&, const edm::EventSetup&);
100  virtual void beginJob() ;
101  virtual void analyze(const edm::Event&, const edm::EventSetup&);
102  virtual void endJob() ;
103 
104  Bool_t MakeRawDigiHist_(const edm::Handle< edm::DetSetVector<SiStripRawDigi> > & digi_handle,
105  uint32_t specifier,
106  const TFileDirectory & dir,
108 
110  uint32_t specifier,
111  const TFileDirectory & dir,
112  FEDSpyHistogramType type);
113 
114  Bool_t MakeDigiHist_( const edm::Handle< edm::DetSetVector<SiStripDigi> > & digi_handle,
115  uint32_t detID,
116  const TFileDirectory & dir,
117  FEDSpyHistogramType type);
118 
119  // ----------member data ---------------------------
120  std::vector<uint32_t> detIDs_;
121  //now from utility class
122  // edm::ESHandle<SiStripDetCabling> cabling_; //!< The Strip Tracker cabling object.
124 
125  // Data input labels
126  //===================
139  //
140  // Output information
141  //====================
143 
144 
145 }; // end of SiStripSpyDisplayModule class
146 
147 
148 //
149 // static data member definitions
150 //
151 
152 using namespace sistrip;
153 using namespace std;
154 
155 //
156 // constructors and destructor
157 //
159  detIDs_( iConfig.getParameter< std::vector<uint32_t> >( "detIDs")),
160  inputScopeModeRawDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputScopeModeRawDigiLabel" ) ),
161  inputPayloadRawDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputPayloadRawDigiLabel" ) ),
162  inputReorderedPayloadRawDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputReorderedPayloadRawDigiLabel" ) ),
163  inputReorderedModuleRawDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputReorderedModuleRawDigiLabel" ) ),
164  inputPedestalsLabel_( iConfig.getParameter<edm::InputTag>( "InputPedestalsLabel" ) ),
165  inputNoisesLabel_( iConfig.getParameter<edm::InputTag>( "InputNoisesLabel" ) ),
166  inputPostPedestalRawDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputPostPedestalRawDigiLabel" ) ),
167  inputPostCMRawDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputPostCMRawDigiLabel" ) ),
168  inputZeroSuppressedRawDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputZeroSuppressedRawDigiLabel" ) ),
169  inputZeroSuppressedDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputZeroSuppressedDigiLabel" ) ),
170  inputCompVirginRawDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputCompVirginRawDigiLabel" ) ),
171  inputCompZeroSuppressedDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputCompZeroSuppressedDigiLabel" ) ),
172  outputFolderName_( iConfig.getParameter<std::string>( "OutputFolderName" ) )
173 {
174  //now do what ever initialization is needed
175 }
176 
177 
179 {
180  // do anything here that needs to be done at desctruction time
181  // (e.g. close files, deallocate resources etc.)
182 }
183 
184 //
185 // member functions
186 //
187 
188 void
190 {
191  // Retrieve FED cabling object
192  //iSetup.get<SiStripDetCablingRcd>().get( cabling_ );
193  //std::stringstream ss;
194  //cabling_->print(ss);
195  //std::cout << ss.str() << std::endl;
196 
197 } // end of beginRun method.
198 
199 // ------------ method called once each job just before starting event loop ------------
200 void
202 {
203  // register to the TFileService
205  // Check that the TFileService has been configured
206  if ( !fs.isAvailable() ) {
207  throw cms::Exception("Configuration") << "TFileService not available: did you configure it ?";
208  }
209 } // end of beginJob method.
210 
211 // ------------ method called once each job just after ending the event loop ------------
213 
214 // ------------ method called to for each event ------------
215 void
217 {
218  using namespace edm;
219  using namespace std;
220 
221  //retrieve cabling
222  const SiStripDetCabling* lCabling = utility_.getDetCabling( iSetup );
223 
224  // Set up the event-level histogram folder
225  //-----------------------------------------
226  // register to the TFileService
228 
229  // Make the EDAnalyzer instance name directory
230  TFileDirectory an_dir = fs->mkdir( outputFolderName_ );
231 
232  // Make the event directory filename
233  stringstream ev_dir_name;
234  ev_dir_name << "run" << iEvent.id().run() << "_event" << iEvent.id().event();
235  TFileDirectory evdir = an_dir.mkdir( ev_dir_name.str() );
236 
237  //if there are no detIds, get them from the comparison digis...
238  if (detIDs_.size()==0) {
239  //get the detIds of the modules in the zero-suppressed comparison
242  iEvent.getByLabel( inputCompZeroSuppressedDigiLabel_, czs_digis );
243  std::vector< edm::DetSet<SiStripDigi> >::const_iterator digis_it = czs_digis->begin();
244  for (; digis_it!=czs_digis->end(); ++digis_it) {
245  detIDs_.push_back(digis_it->detId());
246  }
247  }
250  iEvent.getByLabel( inputCompVirginRawDigiLabel_, cvr_digis );
251  std::vector< edm::DetSet<SiStripRawDigi> >::const_iterator digis_it = cvr_digis->begin();
252  for (; digis_it!=cvr_digis->end(); ++digis_it) {
253  detIDs_.push_back(digis_it->detId());
254  }
255  }
256 
257  }
258 
259  // Loop over detIDs as obtained from the SpyChannelMonitor config file.
260  for (std::vector<uint32_t>::iterator d = detIDs_.begin(); d!=detIDs_.end(); ++d) {
261  // TODO: Need some error checking here, probably...
262  const std::vector<const FedChannelConnection *> & conns = lCabling->getConnections( *d );
263  //cout << "________________________________________________" << endl;
264  //cout << "FED channels found in detId " << *d << " is " << conns.size() << endl;
265  if (!(conns.size())) {
266  // TODO: Properly DEBUG/warning this...
267  //cout << "Skipping detID " << uint32_t(*d) << endl;
268  continue;
269  }
270 
271  // Create a histogram directory for each specified and available detID
272  stringstream sss;
273  sss << "detID_" << *d;
274  TFileDirectory detID_dir = evdir.mkdir( sss.str() );
275 
276  // Loop over the channels found with the detID and add directories.
277  for (uint32_t ch = 0; ch<conns.size(); ch++) {
278 
279  // Name of channel histogram directory
280  stringstream ssss; ssss << sss.str() << "_APVpair_" << ch;
281  TFileDirectory chan_dir = detID_dir.mkdir(ssss.str());
282 
283  // Get the fed key from the detID and the channel
284  uint32_t fedkey = SiStripFedKey::fedIndex(conns[ch]->fedId(), conns[ch]->fedCh());
285 
286  // (Spy) Scope Mode (SM)
287  //=======================
288  // Get the fed key from the FED ID and the FED channel (from conns)
289  // This is because scope mode always stores in the collection by FED ID
291  // Use the SiStripFedKey object to return the FED key
292  //cout << "detID=" << *d << ", FED key looking for is " << fedkey << endl;
293  //cout << "Attempting to find scope mode raw digis" << endl;
294  //
296  iEvent.getByLabel( inputScopeModeRawDigiLabel_, sm_rawdigis );
297  //
298  // Note that the fed key (also a uint32_t) is passed in this case.
299  // The method itself doesn't actually care, but it assumes whatever collection
300  // is stored in sm_rawdigis is indexed by FED key ;-)
301  // TODO: Make this, um, better.
302  if (!(MakeRawDigiHist_(sm_rawdigis, fedkey, chan_dir, SCOPE_MODE))) { ; }
303  }
304 
305  // Payload Unordered Raw (UR)
306  //============================
308  uint32_t fedindex = SiStripFedKey::fedIndex(conns[ch]->fedId(), conns[ch]->fedCh());
309  //cout << "Attempting to find payload mode raw digis" << endl;
311  iEvent.getByLabel( inputPayloadRawDigiLabel_, ur_rawdigis );
312  if (!(MakeRawDigiHist_(ur_rawdigis, fedindex, chan_dir, PAYLOAD_RAW))) { ; }
313  }
314  // Payload Reordered Raw
315  //=======================
317  uint32_t fedkey = SiStripFedKey::fedIndex(conns[ch]->fedId(), conns[ch]->fedCh());
319  iEvent.getByLabel( inputReorderedPayloadRawDigiLabel_, rrp_rawdigis );
320  if (!(MakeRawDigiHist_(rrp_rawdigis, fedkey, chan_dir, REORDERED_PAYLOAD_RAW))) { ; }
321  }
322  } // end of loop over channels
323  //
324  // Module Reordered Raw (RR)
325  //====================
328  iEvent.getByLabel( inputReorderedModuleRawDigiLabel_, rr_rawdigis );
329  //cout << "Making Reordered module histogram for detID " << *d << endl;
330  if (!(MakeRawDigiHist_(rr_rawdigis, *d, detID_dir, REORDERED_MODULE_RAW))) { ; }
331  } // end of ReorderedModuleRaw check
332 
333  //
334  // Pedestal values
335  //========================
336  if (!((inputPedestalsLabel_.label()=="") && (inputPedestalsLabel_.instance()==""))) {
338  iEvent.getByLabel( inputPedestalsLabel_, pd_rawdigis );
339  //cout << "Making pedestal values module histogram for detID " << *d << endl;
340  if (!(MakeRawDigiHist_(pd_rawdigis, *d, detID_dir, PEDESTAL_VALUES))) { ; }
341  }
342  //
343  // Noise values
344  //========================
345  if (!((inputNoisesLabel_.label()=="") && (inputNoisesLabel_.instance()==""))) {
347  iEvent.getByLabel( inputNoisesLabel_, pd_rawdigis );
348  //cout << "Making noise values module histogram for detID " << *d << endl;
349  if (!(MakeProcessedRawDigiHist_(pd_rawdigis, *d, detID_dir, NOISE_VALUES))) { ; }
350  }
351  //
352  // Post-Pedestal Raw (PP)
353  //========================
356  iEvent.getByLabel( inputPostPedestalRawDigiLabel_, pp_rawdigis );
357  //cout << "Making post-pedestal module histogram for detID " << *d << endl;
358  if (!(MakeRawDigiHist_(pp_rawdigis, *d, detID_dir, POST_PEDESTAL))) { ; }
359  }
360  //
361  // Post-Common Mode Subtraction Raw (PC)
362  //=======================================
365  iEvent.getByLabel( inputPostCMRawDigiLabel_, pc_rawdigis );
366  //cout << "Making post-CM module histogram for detID " << *d << endl;
367  if (!(MakeRawDigiHist_(pc_rawdigis, *d, detID_dir, POST_COMMON_MODE))) { ; }
368  }
369 
370  //
371  // Zero-Suppressed Digis
372  //=======================
373  //bool founddigispy = false, founddigimain = false;
375  //cout << "Making ZeroSuppressed histogram!" << endl;
377  iEvent.getByLabel( inputZeroSuppressedDigiLabel_, zs_digis );
378  //founddigispy =
379  MakeDigiHist_(zs_digis, *d, detID_dir, ZERO_SUPPRESSED);
380  }
381  //comparison to mainline data
383  //cout << "Making Mainline VirginRaw histogram!" << endl;
385  iEvent.getByLabel( inputCompVirginRawDigiLabel_, cvr_digis );
386  //founddigimain =
387  MakeRawDigiHist_(cvr_digis, *d, detID_dir, VR_COMP);
388  }
390  //cout << "Making ZeroSuppressed histogram!" << endl;
392  iEvent.getByLabel( inputCompZeroSuppressedDigiLabel_, czs_digis );
393  //founddigimain =
394  MakeDigiHist_(czs_digis, *d, detID_dir, ZERO_SUPPRESSED_COMP);
395  }
396  //if (founddigimain && founddigispy) cout << "Found digis for both in detid=" << *d << endl;
397 
398  } // end of loop over detIDs specified in the config.
399 
400 } // end of Analyze method.
401 
403  const edm::Handle< edm::DetSetVector< SiStripRawDigi > > & digi_handle,
404  uint32_t specifier,
405  const TFileDirectory & dir,
407  //const std::string & name)
408 {
409  // TODO: Remove the hard-coded numbers(!).
410  TH1S * hist;
411  if (type==SCOPE_MODE) hist = dir.make<TH1S>("ScopeMode", ";Sample number;ADC counts / strip", 298, 0, 298);
412  else if (type==PAYLOAD_RAW) hist = dir.make<TH1S>("PayloadRaw", ";Sample number;ADC counts / strip", 256, 0, 256);
413  else if (type==REORDERED_PAYLOAD_RAW) hist = dir.make<TH1S>("ReorderedPayloadRaw", ";Sample number;ADC counts / strip", 256, 0, 256);
414  else if (type==REORDERED_MODULE_RAW) hist = dir.make<TH1S>("ReorderedModuleRaw", ";Sample number;ADC counts / strip", 768, 0, 768);
415  else if (type==PEDESTAL_VALUES) hist = dir.make<TH1S>("PedestalValues", ";Strip number;Pedestal / strip", 768, 0, 768);
416  else if (type==POST_PEDESTAL) hist = dir.make<TH1S>("PostPedestal", ";Strip number;ADC counts / strip", 768, 0, 768);
417  else if (type==POST_COMMON_MODE) hist = dir.make<TH1S>("PostCommonMode", ";Strip number;ADC counts / strip", 768, 0, 768);
418  else if (type==ZERO_SUPPRESSED_PADDED) hist = dir.make<TH1S>("ZeroSuppressedRaw" , ";Strip number;ADC counts / strip", 768, 0, 768);
419  else if (type==VR_COMP) hist = dir.make<TH1S>("VirginRawCom" , ";Strip number;ADC counts / strip", 768, 0, 768);
420  else {hist = 0; return false;}
421 
422  // TODO: May need to make this error checking independent when refactoring...
423  //std::cout << "| * digis for " << type << " and detID " << specifier;
424  std::vector< edm::DetSet<SiStripRawDigi> >::const_iterator digis_it = digi_handle->find( specifier );
425  if (digis_it == digi_handle->end()) {
426  //std::cout << " not found :( ";
427  return false;
428  }
429  //std::cout << std::endl;
430 
431  // Loop over the digis for the detID and APV pair.
432  edm::DetSet<SiStripRawDigi>::const_iterator idigi = digis_it->data.begin();
433  uint32_t count = 0;
434  for ( ; idigi != digis_it->data.end(); ++idigi ) {
435  count++;
436  hist->SetBinContent(count,static_cast<int>((*idigi).adc()));
437  } // end of loop over the digis
438  return true; // Success! (Probably.)
439 }
440 
443  uint32_t specifier,
444  const TFileDirectory & dir,
446  //const std::string & name)
447 {
448  // TODO: Remove the hard-coded numbers(!).
449  TH1F * hist;
450  if (type==NOISE_VALUES) hist = dir.make<TH1F>("NoiseValues",";Strip number;Noise / strip",768, 0, 768);
451  else {
452  hist = 0;
453  return false;
454  }
455 
456  // TODO: May need to make this error checking independent when refactoring...
457  //std::cout << "| * digis for " << type << " and detID " << specifier;
458  std::vector< edm::DetSet<SiStripProcessedRawDigi> >::const_iterator digis_it = digi_handle->find( specifier );
459  if (digis_it == digi_handle->end()) {
460  //std::cout << " not found :( ";
461  return false;
462  }
463  //std::cout << std::endl;
464 
465  // Loop over the digis for the detID and APV pair.
466  edm::DetSet<SiStripProcessedRawDigi>::const_iterator idigi = digis_it->data.begin();
467  uint32_t count = 0;
468  for ( ; idigi != digis_it->data.end(); ++idigi ) {
469  count++;
470  hist->SetBinContent(count,static_cast<float>((*idigi).adc()));
471  } // end of loop over the digis
472  return true; // Success! (Probably.)
473 }
474 
476  const edm::Handle< edm::DetSetVector< SiStripDigi > > & digi_handle,
477  uint32_t detID,
478  //uint32_t channel,
479  const TFileDirectory & dir,
481  //const std::string & name)
482 {
483  // TODO: Remove the hard-coded numbers.
484  TH1S * hist;
485  if (type==ZERO_SUPPRESSED) hist = dir.make<TH1S>("ZeroSuppressedDigi", ";Strip number;ADC counts / strip", 768, 0, 768);
486  else if (type==ZERO_SUPPRESSED_COMP) hist = dir.make<TH1S>("ZeroSuppressedDigiComp", ";Strip number;ADC counts / strip", 768, 0, 768);
487  else {hist = 0; return false;}
488 
489  // TODO: May need to make this error checking independent when refactoring...
490  std::vector< edm::DetSet<SiStripDigi> >::const_iterator digis_it = digi_handle->find( detID );
491  if (digis_it == digi_handle->end()) {
492  return false;
493  }
494  else {
495  //cout << "--* ZS digis found for detID " << detID << endl;
496  }
497 
498  // Loop over the digis for the detID and APV pair.
499  edm::DetSet<SiStripDigi>::const_iterator idigi = digis_it->data.begin();
500  bool founddigi = false;
501  for ( ; idigi != digis_it->data.end(); ++idigi ) {
502  // Check strip number is within the channel limits
503  //if ( static_cast<uint16_t>( (*idigi).strip()/256. ) == channel ) {
504  // hist->SetBinContent( ((*idigi).strip())%256 + 1,(*idigi).adc());
505  //}
506  hist->SetBinContent( static_cast<int>(((*idigi).strip())) + 1, static_cast<int>((*idigi).adc()) );
507  if ( (*idigi).adc() > 0 ) founddigi = true;
508  //cout << "----* ZS digi found at " << static_cast<int>(((*idigi).strip()))
509  // << ", " << static_cast<int>((*idigi).adc()) << endl;
510  } // end of loop over the digis
511 
512  return founddigi;
513 }
514 
515 // Define this as a plug-in
RunNumber_t run() const
Definition: EventID.h:42
edm::InputTag inputZeroSuppressedRawDigiLabel_
Label for the zero-suppressed, zero-padded RawDigi module input tag.
type
Definition: HCALResponse.h:21
EventNumber_t event() const
Definition: EventID.h:44
edm::InputTag inputCompZeroSuppressedDigiLabel_
Zero-suppressed digis to compare (from mainline)
edm::InputTag inputPayloadRawDigiLabel_
Label for the virgin raw RawDigi collection input tag.
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
Bool_t MakeDigiHist_(const edm::Handle< edm::DetSetVector< SiStripDigi > > &digi_handle, uint32_t detID, const TFileDirectory &dir, FEDSpyHistogramType type)
const SiStripDetCabling * getDetCabling(const edm::EventSetup &)
Updates the det cabling object from the DB.
edm::InputTag inputReorderedPayloadRawDigiLabel_
Label for the re-ordered RawDigi module input tag.
static uint32_t fedIndex(const uint16_t &fed_id, const uint16_t &fed_ch)
virtual void analyze(const edm::Event &, const edm::EventSetup &)
edm::InputTag inputPostCMRawDigiLabel_
Label for the post-common mode subtraction RawDigi module input tag.
std::string outputFolderName_
Name for the folder in the TFileService file output.
int iEvent
Definition: GenABIO.cc:243
SiStripSpyDisplayModule(const edm::ParameterSet &)
bool isAvailable() const
Definition: Service.h:47
edm::InputTag inputPostPedestalRawDigiLabel_
Label for the post-pedestal subtraction RawDigi module input tag.
edm::InputTag inputCompVirginRawDigiLabel_
VR RawDigis to compare (from mainline)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:361
TFileDirectory mkdir(const std::string &dir, const std::string &descr="")
create a new subdirectory
edm::InputTag inputScopeModeRawDigiLabel_
Label for the scope-mode RawDigi collection input tag.
edm::InputTag inputNoisesLabel_
Label for the noises.
std::string const & label() const
Definition: InputTag.h:42
edm::EventID id() const
Definition: EventBase.h:56
collection_type data
Definition: DetSet.h:79
EDAnalyzer for the online monitoring of the FED using STT spy channel data.
edm::InputTag inputZeroSuppressedDigiLabel_
Guess what? It&#39;s the input label for the zero-suppressed digi.
T * make() const
make new ROOT object
sistrip::SpyUtilities utility_
Bool_t MakeRawDigiHist_(const edm::Handle< edm::DetSetVector< SiStripRawDigi > > &digi_handle, uint32_t specifier, const TFileDirectory &dir, FEDSpyHistogramType type)
edm::InputTag inputPedestalsLabel_
Label for the pedestals.
edm::InputTag inputReorderedModuleRawDigiLabel_
Label for the re-ordered RawDigi module input tag.
dbl *** dir
Definition: mlp_gen.cc:35
collection_type::const_iterator const_iterator
Definition: DetSet.h:34
Bool_t MakeProcessedRawDigiHist_(const edm::Handle< edm::DetSetVector< SiStripProcessedRawDigi > > &digi_handle, uint32_t specifier, const TFileDirectory &dir, FEDSpyHistogramType type)
std::string const & instance() const
Definition: InputTag.h:43
virtual void beginRun(const edm::Run &, const edm::EventSetup &)
Definition: Run.h:36
std::vector< uint32_t > detIDs_
Vector of detIDs that are of interest (config-specified).