00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include <memory>
00011 #include <vector>
00012 #include <iostream>
00013 #include <string>
00014 #include <sstream>
00015
00016
00017 #include "FWCore/Framework/interface/Frameworkfwd.h"
00018 #include "FWCore/Framework/interface/EDAnalyzer.h"
00019 #include "FWCore/Framework/interface/Event.h"
00020 #include "FWCore/Framework/interface/MakerMacros.h"
00021 #include "FWCore/Framework/interface/ESHandle.h"
00022 #include "FWCore/ParameterSet/interface/ParameterSet.h"
00023
00024
00025 #include "CalibTracker/Records/interface/SiStripDetCablingRcd.h"
00026 #include "CalibFormats/SiStripObjects/interface/SiStripDetCabling.h"
00027 #include "CondFormats/SiStripObjects/interface/FedChannelConnection.h"
00028
00029
00030 #include "CondFormats/SiStripObjects/interface/SiStripPedestals.h"
00031 #include "CondFormats/DataRecord/interface/SiStripPedestalsRcd.h"
00032
00033
00034 #include "CondFormats/SiStripObjects/interface/SiStripNoises.h"
00035 #include "CondFormats/DataRecord/interface/SiStripNoisesRcd.h"
00036
00037
00038 #include "DataFormats/SiStripCommon/interface/SiStripFedKey.h"
00039
00040 #include "DataFormats/FEDRawData/interface/FEDRawDataCollection.h"
00041 #include "DataFormats/SiStripDigi/interface/SiStripRawDigi.h"
00042 #include "DataFormats/SiStripDigi/interface/SiStripProcessedRawDigi.h"
00043 #include "DataFormats/SiStripDigi/interface/SiStripDigi.h"
00044 #include "DataFormats/Common/interface/DetSetVector.h"
00045 #include "DataFormats/SiStripCommon/interface/SiStripConstants.h"
00046
00047
00048 #include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBuffer.h"
00049 #include "EventFilter/SiStripRawToDigi/interface/SiStripFEDBufferGenerator.h"
00050 #include "EventFilter/SiStripRawToDigi/interface/SiStripDigiToRaw.h"
00051
00052
00053 #include "DQM/SiStripMonitorHardware/interface/SiStripSpyUtilities.h"
00054
00055
00056 #include "FWCore/ServiceRegistry/interface/Service.h"
00057 #include "CommonTools/UtilAlgos/interface/TFileService.h"
00058 #include "TH1S.h"
00059 #include "TH1D.h"
00060
00061
00062
00063
00064 enum FEDSpyHistogramType {SCOPE_MODE,
00065 PAYLOAD_RAW,
00066 REORDERED_PAYLOAD_RAW,
00067 REORDERED_MODULE_RAW,
00068 PEDESTAL_VALUES,
00069 NOISE_VALUES,
00070 POST_PEDESTAL,
00071 POST_COMMON_MODE,
00072 ZERO_SUPPRESSED_PADDED,
00073 ZERO_SUPPRESSED,
00074 VR_COMP,
00075 ZERO_SUPPRESSED_COMP};
00076
00077
00078
00079
00080
00081
00093 class SiStripSpyDisplayModule : public edm::EDAnalyzer {
00094 public:
00095 explicit SiStripSpyDisplayModule(const edm::ParameterSet&);
00096 ~SiStripSpyDisplayModule();
00097
00098 private:
00099 virtual void beginRun(const edm::Run&, const edm::EventSetup&);
00100 virtual void beginJob() ;
00101 virtual void analyze(const edm::Event&, const edm::EventSetup&);
00102 virtual void endJob() ;
00103
00104 Bool_t MakeRawDigiHist_(const edm::Handle< edm::DetSetVector<SiStripRawDigi> > & digi_handle,
00105 uint32_t specifier,
00106 const TFileDirectory & dir,
00107 FEDSpyHistogramType type);
00108
00109 Bool_t MakeProcessedRawDigiHist_(const edm::Handle< edm::DetSetVector<SiStripProcessedRawDigi> > & digi_handle,
00110 uint32_t specifier,
00111 const TFileDirectory & dir,
00112 FEDSpyHistogramType type);
00113
00114 Bool_t MakeDigiHist_( const edm::Handle< edm::DetSetVector<SiStripDigi> > & digi_handle,
00115 uint32_t detID,
00116 const TFileDirectory & dir,
00117 FEDSpyHistogramType type);
00118
00119
00120 std::vector<uint32_t> detIDs_;
00121
00122
00123 sistrip::SpyUtilities utility_;
00124
00125
00126
00127 edm::InputTag inputScopeModeRawDigiLabel_;
00128 edm::InputTag inputPayloadRawDigiLabel_;
00129 edm::InputTag inputReorderedPayloadRawDigiLabel_;
00130 edm::InputTag inputReorderedModuleRawDigiLabel_;
00131 edm::InputTag inputPedestalsLabel_;
00132 edm::InputTag inputNoisesLabel_;
00133 edm::InputTag inputPostPedestalRawDigiLabel_;
00134 edm::InputTag inputPostCMRawDigiLabel_;
00135 edm::InputTag inputZeroSuppressedRawDigiLabel_;
00136 edm::InputTag inputZeroSuppressedDigiLabel_;
00137 edm::InputTag inputCompVirginRawDigiLabel_;
00138 edm::InputTag inputCompZeroSuppressedDigiLabel_;
00139
00140
00141
00142 std::string outputFolderName_;
00143
00144
00145 };
00146
00147
00148
00149
00150
00151
00152 using namespace sistrip;
00153 using namespace std;
00154
00155
00156
00157
00158 SiStripSpyDisplayModule::SiStripSpyDisplayModule(const edm::ParameterSet& iConfig) :
00159 detIDs_( iConfig.getParameter< std::vector<uint32_t> >( "detIDs")),
00160 inputScopeModeRawDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputScopeModeRawDigiLabel" ) ),
00161 inputPayloadRawDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputPayloadRawDigiLabel" ) ),
00162 inputReorderedPayloadRawDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputReorderedPayloadRawDigiLabel" ) ),
00163 inputReorderedModuleRawDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputReorderedModuleRawDigiLabel" ) ),
00164 inputPedestalsLabel_( iConfig.getParameter<edm::InputTag>( "InputPedestalsLabel" ) ),
00165 inputNoisesLabel_( iConfig.getParameter<edm::InputTag>( "InputNoisesLabel" ) ),
00166 inputPostPedestalRawDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputPostPedestalRawDigiLabel" ) ),
00167 inputPostCMRawDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputPostCMRawDigiLabel" ) ),
00168 inputZeroSuppressedRawDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputZeroSuppressedRawDigiLabel" ) ),
00169 inputZeroSuppressedDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputZeroSuppressedDigiLabel" ) ),
00170 inputCompVirginRawDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputCompVirginRawDigiLabel" ) ),
00171 inputCompZeroSuppressedDigiLabel_( iConfig.getParameter<edm::InputTag>( "InputCompZeroSuppressedDigiLabel" ) ),
00172 outputFolderName_( iConfig.getParameter<std::string>( "OutputFolderName" ) )
00173 {
00174
00175 }
00176
00177
00178 SiStripSpyDisplayModule::~SiStripSpyDisplayModule()
00179 {
00180
00181
00182 }
00183
00184
00185
00186
00187
00188 void
00189 SiStripSpyDisplayModule::beginRun(const edm::Run & iRun, const edm::EventSetup & iSetup)
00190 {
00191
00192
00193
00194
00195
00196
00197 }
00198
00199
00200 void
00201 SiStripSpyDisplayModule::beginJob()
00202 {
00203
00204 edm::Service<TFileService> fs;
00205
00206 if ( !fs.isAvailable() ) {
00207 throw cms::Exception("Configuration") << "TFileService not available: did you configure it ?";
00208 }
00209 }
00210
00211
00212 void SiStripSpyDisplayModule::endJob() {}
00213
00214
00215 void
00216 SiStripSpyDisplayModule::analyze(const edm::Event& iEvent, const edm::EventSetup& iSetup)
00217 {
00218 using namespace edm;
00219 using namespace std;
00220
00221
00222 const SiStripDetCabling* lCabling = utility_.getDetCabling( iSetup );
00223
00224
00225
00226
00227 edm::Service<TFileService> fs;
00228
00229
00230 TFileDirectory an_dir = fs->mkdir( outputFolderName_ );
00231
00232
00233 stringstream ev_dir_name;
00234 ev_dir_name << "run" << iEvent.id().run() << "_event" << iEvent.id().event();
00235 TFileDirectory evdir = an_dir.mkdir( ev_dir_name.str() );
00236
00237
00238 if (detIDs_.size()==0) {
00239
00240 if (!((inputCompZeroSuppressedDigiLabel_.label()=="") && (inputCompZeroSuppressedDigiLabel_.instance()==""))) {
00241 edm::Handle< edm::DetSetVector< SiStripDigi > > czs_digis;
00242 iEvent.getByLabel( inputCompZeroSuppressedDigiLabel_, czs_digis );
00243 std::vector< edm::DetSet<SiStripDigi> >::const_iterator digis_it = czs_digis->begin();
00244 for (; digis_it!=czs_digis->end(); ++digis_it) {
00245 detIDs_.push_back(digis_it->detId());
00246 }
00247 }
00248 else if (!((inputCompVirginRawDigiLabel_.label()=="") && (inputCompVirginRawDigiLabel_.instance()==""))) {
00249 edm::Handle< edm::DetSetVector< SiStripRawDigi > > cvr_digis;
00250 iEvent.getByLabel( inputCompVirginRawDigiLabel_, cvr_digis );
00251 std::vector< edm::DetSet<SiStripRawDigi> >::const_iterator digis_it = cvr_digis->begin();
00252 for (; digis_it!=cvr_digis->end(); ++digis_it) {
00253 detIDs_.push_back(digis_it->detId());
00254 }
00255 }
00256
00257 }
00258
00259
00260 for (std::vector<uint32_t>::iterator d = detIDs_.begin(); d!=detIDs_.end(); ++d) {
00261
00262 const std::vector<const FedChannelConnection *> & conns = lCabling->getConnections( *d );
00263
00264
00265 if (!(conns.size())) {
00266
00267
00268 continue;
00269 }
00270
00271
00272 stringstream sss;
00273 sss << "detID_" << *d;
00274 TFileDirectory detID_dir = evdir.mkdir( sss.str() );
00275
00276
00277 for (uint32_t ch = 0; ch<conns.size(); ch++) {
00278
00279
00280 stringstream ssss; ssss << sss.str() << "_APVpair_" << ch;
00281 TFileDirectory chan_dir = detID_dir.mkdir(ssss.str());
00282
00283
00284 uint32_t fedkey = SiStripFedKey::fedIndex(conns[ch]->fedId(), conns[ch]->fedCh());
00285
00286
00287
00288
00289
00290 if (!((inputScopeModeRawDigiLabel_.label()=="") && (inputScopeModeRawDigiLabel_.instance()==""))) {
00291
00292
00293
00294
00295 edm::Handle< edm::DetSetVector< SiStripRawDigi > > sm_rawdigis;
00296 iEvent.getByLabel( inputScopeModeRawDigiLabel_, sm_rawdigis );
00297
00298
00299
00300
00301
00302 if (!(MakeRawDigiHist_(sm_rawdigis, fedkey, chan_dir, SCOPE_MODE))) { ; }
00303 }
00304
00305
00306
00307 if (!((inputPayloadRawDigiLabel_.label()=="") && (inputPayloadRawDigiLabel_.instance()==""))) {
00308 uint32_t fedindex = SiStripFedKey::fedIndex(conns[ch]->fedId(), conns[ch]->fedCh());
00309
00310 edm::Handle< edm::DetSetVector< SiStripRawDigi > > ur_rawdigis;
00311 iEvent.getByLabel( inputPayloadRawDigiLabel_, ur_rawdigis );
00312 if (!(MakeRawDigiHist_(ur_rawdigis, fedindex, chan_dir, PAYLOAD_RAW))) { ; }
00313 }
00314
00315
00316 if (!((inputReorderedPayloadRawDigiLabel_.label()=="") && (inputReorderedPayloadRawDigiLabel_.instance()==""))) {
00317 uint32_t fedkey = SiStripFedKey::fedIndex(conns[ch]->fedId(), conns[ch]->fedCh());
00318 edm::Handle< edm::DetSetVector< SiStripRawDigi > > rrp_rawdigis;
00319 iEvent.getByLabel( inputReorderedPayloadRawDigiLabel_, rrp_rawdigis );
00320 if (!(MakeRawDigiHist_(rrp_rawdigis, fedkey, chan_dir, REORDERED_PAYLOAD_RAW))) { ; }
00321 }
00322 }
00323
00324
00325
00326 if (!((inputReorderedModuleRawDigiLabel_.label()=="") && (inputReorderedModuleRawDigiLabel_.instance()==""))) {
00327 edm::Handle< edm::DetSetVector< SiStripRawDigi > > rr_rawdigis;
00328 iEvent.getByLabel( inputReorderedModuleRawDigiLabel_, rr_rawdigis );
00329
00330 if (!(MakeRawDigiHist_(rr_rawdigis, *d, detID_dir, REORDERED_MODULE_RAW))) { ; }
00331 }
00332
00333
00334
00335
00336 if (!((inputPedestalsLabel_.label()=="") && (inputPedestalsLabel_.instance()==""))) {
00337 edm::Handle< edm::DetSetVector< SiStripRawDigi > > pd_rawdigis;
00338 iEvent.getByLabel( inputPedestalsLabel_, pd_rawdigis );
00339
00340 if (!(MakeRawDigiHist_(pd_rawdigis, *d, detID_dir, PEDESTAL_VALUES))) { ; }
00341 }
00342
00343
00344
00345 if (!((inputNoisesLabel_.label()=="") && (inputNoisesLabel_.instance()==""))) {
00346 edm::Handle< edm::DetSetVector< SiStripProcessedRawDigi > > pd_rawdigis;
00347 iEvent.getByLabel( inputNoisesLabel_, pd_rawdigis );
00348
00349 if (!(MakeProcessedRawDigiHist_(pd_rawdigis, *d, detID_dir, NOISE_VALUES))) { ; }
00350 }
00351
00352
00353
00354 if (!((inputPostPedestalRawDigiLabel_.label()=="") && (inputPostPedestalRawDigiLabel_.instance()==""))) {
00355 edm::Handle< edm::DetSetVector< SiStripRawDigi > > pp_rawdigis;
00356 iEvent.getByLabel( inputPostPedestalRawDigiLabel_, pp_rawdigis );
00357
00358 if (!(MakeRawDigiHist_(pp_rawdigis, *d, detID_dir, POST_PEDESTAL))) { ; }
00359 }
00360
00361
00362
00363 if (!((inputPostCMRawDigiLabel_.label()=="") && (inputPostCMRawDigiLabel_.instance()==""))) {
00364 edm::Handle< edm::DetSetVector< SiStripRawDigi > > pc_rawdigis;
00365 iEvent.getByLabel( inputPostCMRawDigiLabel_, pc_rawdigis );
00366
00367 if (!(MakeRawDigiHist_(pc_rawdigis, *d, detID_dir, POST_COMMON_MODE))) { ; }
00368 }
00369
00370
00371
00372
00373
00374 if (!((inputZeroSuppressedDigiLabel_.label()=="") && (inputZeroSuppressedDigiLabel_.instance()==""))) {
00375
00376 edm::Handle< edm::DetSetVector< SiStripDigi > > zs_digis;
00377 iEvent.getByLabel( inputZeroSuppressedDigiLabel_, zs_digis );
00378
00379 MakeDigiHist_(zs_digis, *d, detID_dir, ZERO_SUPPRESSED);
00380 }
00381
00382 if (!((inputCompVirginRawDigiLabel_.label()=="") && (inputCompVirginRawDigiLabel_.instance()==""))) {
00383
00384 edm::Handle< edm::DetSetVector< SiStripRawDigi > > cvr_digis;
00385 iEvent.getByLabel( inputCompVirginRawDigiLabel_, cvr_digis );
00386
00387 MakeRawDigiHist_(cvr_digis, *d, detID_dir, VR_COMP);
00388 }
00389 if (!((inputCompZeroSuppressedDigiLabel_.label()=="") && (inputCompZeroSuppressedDigiLabel_.instance()==""))) {
00390
00391 edm::Handle< edm::DetSetVector< SiStripDigi > > czs_digis;
00392 iEvent.getByLabel( inputCompZeroSuppressedDigiLabel_, czs_digis );
00393
00394 MakeDigiHist_(czs_digis, *d, detID_dir, ZERO_SUPPRESSED_COMP);
00395 }
00396
00397
00398 }
00399
00400 }
00401
00402 Bool_t SiStripSpyDisplayModule::MakeRawDigiHist_(
00403 const edm::Handle< edm::DetSetVector< SiStripRawDigi > > & digi_handle,
00404 uint32_t specifier,
00405 const TFileDirectory & dir,
00406 FEDSpyHistogramType type)
00407
00408 {
00409
00410 TH1S * hist;
00411 if (type==SCOPE_MODE) hist = dir.make<TH1S>("ScopeMode", ";Sample number;ADC counts / strip", 298, 0, 298);
00412 else if (type==PAYLOAD_RAW) hist = dir.make<TH1S>("PayloadRaw", ";Sample number;ADC counts / strip", 256, 0, 256);
00413 else if (type==REORDERED_PAYLOAD_RAW) hist = dir.make<TH1S>("ReorderedPayloadRaw", ";Sample number;ADC counts / strip", 256, 0, 256);
00414 else if (type==REORDERED_MODULE_RAW) hist = dir.make<TH1S>("ReorderedModuleRaw", ";Sample number;ADC counts / strip", 768, 0, 768);
00415 else if (type==PEDESTAL_VALUES) hist = dir.make<TH1S>("PedestalValues", ";Strip number;Pedestal / strip", 768, 0, 768);
00416 else if (type==POST_PEDESTAL) hist = dir.make<TH1S>("PostPedestal", ";Strip number;ADC counts / strip", 768, 0, 768);
00417 else if (type==POST_COMMON_MODE) hist = dir.make<TH1S>("PostCommonMode", ";Strip number;ADC counts / strip", 768, 0, 768);
00418 else if (type==ZERO_SUPPRESSED_PADDED) hist = dir.make<TH1S>("ZeroSuppressedRaw" , ";Strip number;ADC counts / strip", 768, 0, 768);
00419 else if (type==VR_COMP) hist = dir.make<TH1S>("VirginRawCom" , ";Strip number;ADC counts / strip", 768, 0, 768);
00420 else {hist = 0; return false;}
00421
00422
00423
00424 std::vector< edm::DetSet<SiStripRawDigi> >::const_iterator digis_it = digi_handle->find( specifier );
00425 if (digis_it == digi_handle->end()) {
00426
00427 return false;
00428 }
00429
00430
00431
00432 edm::DetSet<SiStripRawDigi>::const_iterator idigi = digis_it->data.begin();
00433 uint32_t count = 0;
00434 for ( ; idigi != digis_it->data.end(); ++idigi ) {
00435 count++;
00436 hist->SetBinContent(count,static_cast<int>((*idigi).adc()));
00437 }
00438 return true;
00439 }
00440
00441 Bool_t SiStripSpyDisplayModule::MakeProcessedRawDigiHist_(
00442 const edm::Handle< edm::DetSetVector< SiStripProcessedRawDigi > > & digi_handle,
00443 uint32_t specifier,
00444 const TFileDirectory & dir,
00445 FEDSpyHistogramType type)
00446
00447 {
00448
00449 TH1F * hist;
00450 if (type==NOISE_VALUES) hist = dir.make<TH1F>("NoiseValues",";Strip number;Noise / strip",768, 0, 768);
00451 else {
00452 hist = 0;
00453 return false;
00454 }
00455
00456
00457
00458 std::vector< edm::DetSet<SiStripProcessedRawDigi> >::const_iterator digis_it = digi_handle->find( specifier );
00459 if (digis_it == digi_handle->end()) {
00460
00461 return false;
00462 }
00463
00464
00465
00466 edm::DetSet<SiStripProcessedRawDigi>::const_iterator idigi = digis_it->data.begin();
00467 uint32_t count = 0;
00468 for ( ; idigi != digis_it->data.end(); ++idigi ) {
00469 count++;
00470 hist->SetBinContent(count,static_cast<float>((*idigi).adc()));
00471 }
00472 return true;
00473 }
00474
00475 Bool_t SiStripSpyDisplayModule::MakeDigiHist_(
00476 const edm::Handle< edm::DetSetVector< SiStripDigi > > & digi_handle,
00477 uint32_t detID,
00478
00479 const TFileDirectory & dir,
00480 FEDSpyHistogramType type)
00481
00482 {
00483
00484 TH1S * hist;
00485 if (type==ZERO_SUPPRESSED) hist = dir.make<TH1S>("ZeroSuppressedDigi", ";Strip number;ADC counts / strip", 768, 0, 768);
00486 else if (type==ZERO_SUPPRESSED_COMP) hist = dir.make<TH1S>("ZeroSuppressedDigiComp", ";Strip number;ADC counts / strip", 768, 0, 768);
00487 else {hist = 0; return false;}
00488
00489
00490 std::vector< edm::DetSet<SiStripDigi> >::const_iterator digis_it = digi_handle->find( detID );
00491 if (digis_it == digi_handle->end()) {
00492 return false;
00493 }
00494 else {
00495
00496 }
00497
00498
00499 edm::DetSet<SiStripDigi>::const_iterator idigi = digis_it->data.begin();
00500 bool founddigi = false;
00501 for ( ; idigi != digis_it->data.end(); ++idigi ) {
00502
00503
00504
00505
00506 hist->SetBinContent( static_cast<int>(((*idigi).strip())) + 1, static_cast<int>((*idigi).adc()) );
00507 if ( (*idigi).adc() > 0 ) founddigi = true;
00508
00509
00510 }
00511
00512 return founddigi;
00513 }
00514
00515
00516 DEFINE_FWK_MODULE(SiStripSpyDisplayModule);