CMS 3D CMS Logo

CommonModeAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripTools
4 // Class: CommonModeAnalyzer
5 //
13 //
14 // Original Author: Andrea Venturi
15 // Created: Tue Jul 19 11:56:00 CEST 2009
16 //
17 //
18 
19 // system include files
20 #include <memory>
21 
22 // user include files
23 #include "TH1D.h"
24 #include "TProfile.h"
25 #include <vector>
26 #include <algorithm>
27 #include <string>
28 
31 
35 
37 
39 
42 
44 
47 
50 
53 
56 
61 //
62 // class decleration
63 //
64 
66 public:
67  explicit CommonModeAnalyzer(const edm::ParameterSet&);
68  ~CommonModeAnalyzer() override;
69 
70 private:
71  void beginJob() override;
72  void beginRun(const edm::Run&, const edm::EventSetup&) override;
73  void endRun(const edm::Run&, const edm::EventSetup&) override;
74  void analyze(const edm::Event&, const edm::EventSetup&) override;
75  void endJob() override;
76 
78 
79  // ----------member data ---------------------------
80 
86  const bool m_ignorebadfedmod;
88  int m_nevents;
89 
90  std::vector<DetIdSelector> m_selections;
91  std::vector<std::string> m_labels;
92  std::vector<TH1D*> m_cmdist;
93  std::vector<TH1D*> m_nmodules;
94  std::vector<TH1D*> m_napvs;
95  std::vector<TProfile*> m_cmvsdbxincycle;
96  std::vector<TProfile**> m_cmvsbxrun;
97  std::vector<TProfile**> m_cmvsorbitrun;
98 
100 
101  uint32_t m_cacheIdDet;
103 };
104 
105 //
106 // constants, enums and typedefs
107 //
108 
109 //
110 // static data member definitions
111 //
112 
113 //
114 // constructors and destructor
115 //
117  : m_digicollectionToken(
118  consumes<edm::DetSetVector<SiStripRawDigi> >(iConfig.getParameter<edm::InputTag>("digiCollection"))),
119  m_historyProductToken(consumes<EventWithHistory>(iConfig.getParameter<edm::InputTag>("historyProduct"))),
120  m_apvphasecollToken(consumes<APVCyclePhaseCollection>(iConfig.getParameter<edm::InputTag>("apvPhaseCollection"))),
121  m_digibadmodulecollectionToken(
122  consumes<DetIdCollection>(iConfig.getParameter<edm::InputTag>("badModuleDigiCollection"))),
123  m_phasepart(iConfig.getUntrackedParameter<std::string>("phasePartition", "None")),
124  m_ignorebadfedmod(iConfig.getParameter<bool>("ignoreBadFEDMod")),
125  m_ignorenotconnected(iConfig.getParameter<bool>("ignoreNotConnected")),
126  m_nevents(0),
127  m_selections(),
128  m_labels(),
129  m_cmdist(),
130  m_nmodules(),
131  m_napvs(),
132  m_cmvsdbxincycle(),
133  m_cmvsbxrun(),
134  m_cmvsorbitrun(),
135  m_rhm(consumesCollector()),
136  m_cacheIdDet(0),
137  m_detCabling(nullptr) {
138  //now do what ever initialization is needed
139 
141 
142  std::vector<edm::ParameterSet> selconfigs = iConfig.getParameter<std::vector<edm::ParameterSet> >("selections");
143 
144  for (std::vector<edm::ParameterSet>::const_iterator selconfig = selconfigs.begin(); selconfig != selconfigs.end();
145  ++selconfig) {
146  std::string label = selconfig->getParameter<std::string>("label");
147  DetIdSelector selection(*selconfig);
148  m_selections.push_back(selection);
149 
150  {
151  std::string hname = label + "_CommonMode";
152  std::string htitle = label + " Common Mode";
153  m_cmdist.push_back(tfserv->make<TH1D>(hname.c_str(), htitle.c_str(), 1024, -0.5, 1024 - 0.5));
154  m_cmdist.back()->GetXaxis()->SetTitle("ADC");
155  }
156  {
157  std::string hname = label + "_nmodules";
158  std::string htitle = label + " Number of Modules with CM value";
159  m_nmodules.push_back(tfserv->make<TH1D>(hname.c_str(), htitle.c_str(), 20000, -0.5, 20000 - 0.5));
160  m_nmodules.back()->GetXaxis()->SetTitle("#modules");
161  }
162  {
163  std::string hname = label + "_napvs";
164  std::string htitle = label + " Number of APVs with CM value";
165  m_napvs.push_back(tfserv->make<TH1D>(hname.c_str(), htitle.c_str(), 2000, -0.5, 80000 - 0.5));
166  m_napvs.back()->GetXaxis()->SetTitle("#apvs");
167  }
168  {
169  std::string hname = label + "_CMvsDBXinCycle";
170  std::string htitle = label + " Common Mode vs DBX in Cycle";
171  m_cmvsdbxincycle.push_back(tfserv->make<TProfile>(hname.c_str(), htitle.c_str(), 1000, -0.5, 1000 - 0.5));
172  m_cmvsdbxincycle.back()->GetXaxis()->SetTitle("DBX in cycle");
173  m_cmvsdbxincycle.back()->GetYaxis()->SetTitle("CM (ADC counts)");
174  }
175  {
176  std::string hname = label + "_CMvsBX";
177  std::string htitle = label + " Common Mode vs BX";
178  m_cmvsbxrun.push_back(m_rhm.makeTProfile(hname.c_str(), htitle.c_str(), 3565, -0.5, 3565 - 0.5));
179  }
180  {
181  std::string hname = label + "_CMvsOrbit";
182  std::string htitle = label + " Common Mode vs Orbit";
183  m_cmvsorbitrun.push_back(m_rhm.makeTProfile(hname.c_str(), htitle.c_str(), 4 * 500, 0, 500 * 262144));
184  }
185  }
186 }
187 
189  // do anything here that needs to be done at desctruction time
190  // (e.g. close files, deallocate resources etc.)
191 }
192 
193 //
194 // member functions
195 //
196 
197 // ------------ method called to for each event ------------
199  using namespace edm;
200 
201  updateDetCabling(iSetup);
202 
203  m_nevents++;
204 
206  iEvent.getByToken(m_historyProductToken, he);
207 
209  iEvent.getByToken(m_apvphasecollToken, apvphase);
210 
211  Handle<DetIdCollection> badmodules;
212  iEvent.getByToken(m_digibadmodulecollectionToken, badmodules);
213 
214  int thephase = APVCyclePhaseCollection::invalid;
215  if (apvphase.isValid() && !apvphase.failedToGet()) {
216  thephase = apvphase->getPhase(m_phasepart);
217  }
218  bool isphaseok = (thephase != APVCyclePhaseCollection::invalid && thephase != APVCyclePhaseCollection::multiphase &&
220 
222  iEvent.getByToken(m_digicollectionToken, digis);
223 
224  // loop on detector with digis
225 
226  std::vector<int> nmodules(m_selections.size(), 0);
227  std::vector<int> napvs(m_selections.size(), 0);
228 
229  for (edm::DetSetVector<SiStripRawDigi>::const_iterator mod = digis->begin(); mod != digis->end(); mod++) {
230  std::vector<const FedChannelConnection*> conns = m_detCabling->getConnections(mod->detId());
231 
232  if (!m_ignorebadfedmod || std::find(badmodules->begin(), badmodules->end(), mod->detId()) == badmodules->end()) {
233  for (unsigned int isel = 0; isel < m_selections.size(); ++isel) {
234  if (m_selections[isel].isSelected(mod->detId())) {
235  unsigned int strip = 0;
236  ++nmodules[isel];
237  for (edm::DetSet<SiStripRawDigi>::const_iterator digi = mod->begin(); digi != mod->end(); digi++, strip++) {
238  LogDebug("StripNumber") << "Strip number " << strip;
239  if (!m_ignorenotconnected ||
240  ((conns.size() > strip / 2) && conns[strip / 2] && conns[strip / 2]->isConnected())) {
241  ++napvs[isel];
242  m_cmdist[isel]->Fill(digi->adc());
243  if (isphaseok)
244  m_cmvsdbxincycle[isel]->Fill(he->deltaBXinCycle(thephase), digi->adc());
245  if (m_cmvsbxrun[isel] && *(m_cmvsbxrun[isel]))
246  (*(m_cmvsbxrun[isel]))->Fill(iEvent.bunchCrossing(), digi->adc());
247  if (m_cmvsorbitrun[isel] && *(m_cmvsorbitrun[isel]))
248  (*(m_cmvsorbitrun[isel]))->Fill(iEvent.orbitNumber(), digi->adc());
249  } else if (digi->adc() > 0) {
250  edm::LogWarning("NonZeroCMWhenDisconnected")
251  << " Non zero CM in " << mod->detId() << " APV " << strip << " with " << conns.size()
252  << " connections and connection pointer" << conns[strip / 2];
253  }
254  }
255  }
256  }
257  }
258  }
259  for (unsigned int isel = 0; isel < m_selections.size(); ++isel) {
260  m_nmodules[isel]->Fill(nmodules[isel]);
261  m_napvs[isel]->Fill(napvs[isel]);
262  }
263 }
264 
266  m_rhm.beginRun(iRun);
267 
268  for (std::vector<TProfile**>::const_iterator cmvsbx = m_cmvsbxrun.begin(); cmvsbx != m_cmvsbxrun.end(); ++cmvsbx) {
269  if (*cmvsbx && *(*cmvsbx)) {
270  (*(*cmvsbx))->GetXaxis()->SetTitle("BX");
271  (*(*cmvsbx))->GetYaxis()->SetTitle("CM (ADC counts)");
272  }
273  }
274  for (std::vector<TProfile**>::const_iterator cmvsorbit = m_cmvsorbitrun.begin(); cmvsorbit != m_cmvsorbitrun.end();
275  ++cmvsorbit) {
276  if (*cmvsorbit && *(*cmvsorbit)) {
277  (*(*cmvsorbit))->GetXaxis()->SetTitle("orbit");
278  (*(*cmvsorbit))->GetYaxis()->SetTitle("CM (ADC counts)");
279  (*(*cmvsorbit))->SetCanExtend(TH1::kXaxis);
280  }
281  }
282 }
283 
285 
286 // ------------ method called once each job just before starting event loop ------------
288 
289 // ------------ method called once each job just after ending the event loop ------------
290 void CommonModeAnalyzer::endJob() { edm::LogInfo("EndOfJob") << m_nevents << " analyzed events"; }
292  uint32_t cache_id = setup.get<SiStripDetCablingRcd>().cacheIdentifier(); //.get( cabling_ );
293 
294  if (m_cacheIdDet != cache_id) { // If the cache ID has changed since the last update...
295  // Update the cabling object
298  m_detCabling = c.product();
299  m_cacheIdDet = cache_id;
300  } // end of new cache ID check
301 }
302 
303 //define this as a plug-in
edm::EDCollection::begin
const_iterator begin() const
Definition: EDCollection.h:117
electrons_cff.bool
bool
Definition: electrons_cff.py:372
CommonModeAnalyzer::m_historyProductToken
edm::EDGetTokenT< EventWithHistory > m_historyProductToken
Definition: CommonModeAnalyzer.cc:82
MessageLogger.h
ESHandle.h
APVCyclePhaseCollection::multiphase
Definition: APVCyclePhaseCollection.h:21
edm::Run
Definition: Run.h:45
edm::EDGetTokenT
Definition: EDGetToken.h:33
edm
HLT enums.
Definition: AlignableModifier.h:19
digitizers_cfi.strip
strip
Definition: digitizers_cfi.py:19
SiStripRawDigi.h
mod
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
CommonModeAnalyzer::updateDetCabling
void updateDetCabling(const edm::EventSetup &setup)
Definition: CommonModeAnalyzer.cc:291
edm::LogInfo
Definition: MessageLogger.h:254
CommonModeAnalyzer::m_labels
std::vector< std::string > m_labels
Definition: CommonModeAnalyzer.cc:91
EventWithHistory.h
DetIdSelector.h
CommonModeAnalyzer::m_cmvsbxrun
std::vector< TProfile ** > m_cmvsbxrun
Definition: CommonModeAnalyzer.cc:96
EDAnalyzer.h
CommonModeAnalyzer::m_selections
std::vector< DetIdSelector > m_selections
Definition: CommonModeAnalyzer.cc:90
CommonModeAnalyzer::m_digibadmodulecollectionToken
edm::EDGetTokenT< DetIdCollection > m_digibadmodulecollectionToken
Definition: CommonModeAnalyzer.cc:84
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::Handle
Definition: AssociativeIterator.h:50
CommonModeAnalyzer::m_phasepart
const std::string m_phasepart
Definition: CommonModeAnalyzer.cc:85
singleTopDQM_cfi.setup
setup
Definition: singleTopDQM_cfi.py:37
edm::EDAnalyzer
Definition: EDAnalyzer.h:29
MakerMacros.h
SiStripDetCabling.h
SiStripRawDigi
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
Definition: SiStripRawDigi.h:15
RunHistogramManager
Definition: RunHistogramManager.h:210
DEFINE_FWK_MODULE
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
Service.h
RunHistogramManager.h
SiStripDetCabling
Definition: SiStripDetCabling.h:21
APVCyclePhaseCollection
Definition: APVCyclePhaseCollection.h:8
corrVsCorr.selection
selection
main part
Definition: corrVsCorr.py:100
edm::ESHandle< SiStripDetCabling >
CommonModeAnalyzer::m_rhm
RunHistogramManager m_rhm
Definition: CommonModeAnalyzer.cc:99
SiStripDetCablingRcd
Definition: SiStripDependentRecords.h:19
CommonModeAnalyzer::CommonModeAnalyzer
CommonModeAnalyzer(const edm::ParameterSet &)
Definition: CommonModeAnalyzer.cc:116
CommonModeAnalyzer::endRun
void endRun(const edm::Run &, const edm::EventSetup &) override
Definition: CommonModeAnalyzer.cc:284
CommonModeAnalyzer::m_napvs
std::vector< TH1D * > m_napvs
Definition: CommonModeAnalyzer.cc:94
CommonModeAnalyzer
Definition: CommonModeAnalyzer.cc:65
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::LogWarning
Definition: MessageLogger.h:141
TFileService.h
CommonModeAnalyzer::m_cmvsorbitrun
std::vector< TProfile ** > m_cmvsorbitrun
Definition: CommonModeAnalyzer.cc:97
SiStripConstants.h
CommonModeAnalyzer::m_nmodules
std::vector< TH1D * > m_nmodules
Definition: CommonModeAnalyzer.cc:93
edm::HandleBase::failedToGet
bool failedToGet() const
Definition: HandleBase.h:72
HLT_2018_cff.InputTag
InputTag
Definition: HLT_2018_cff.py:79016
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:670
edm::ParameterSet
Definition: ParameterSet.h:36
Event.h
CommonModeAnalyzer::endJob
void endJob() override
Definition: CommonModeAnalyzer.cc:290
edm::DetSetVector::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
RunHistogramManager::beginRun
void beginRun(const edm::Run &iRun)
Definition: RunHistogramManager.cc:101
APVCyclePhaseCollection.h
edm::Service< TFileService >
iEvent
int iEvent
Definition: GenABIO.cc:224
CommonModeAnalyzer::analyze
void analyze(const edm::Event &, const edm::EventSetup &) override
Definition: CommonModeAnalyzer.cc:198
CommonModeAnalyzer::m_detCabling
const SiStripDetCabling * m_detCabling
The cabling object.
Definition: CommonModeAnalyzer.cc:102
CommonModeAnalyzer::m_nevents
int m_nevents
Definition: CommonModeAnalyzer.cc:88
edm::EventSetup
Definition: EventSetup.h:57
CommonModeAnalyzer::m_cmdist
std::vector< TH1D * > m_cmdist
Definition: CommonModeAnalyzer.cc:92
EventWithHistory
Definition: EventWithHistory.h:17
DetSetVector.h
HltBtagPostValidation_cff.c
c
Definition: HltBtagPostValidation_cff.py:31
get
#define get
edm::EDCollection< DetId >
HcalObjRepresent::Fill
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
Definition: HcalObjRepresent.h:1053
CommonModeAnalyzer::m_cmvsdbxincycle
std::vector< TProfile * > m_cmvsdbxincycle
Definition: CommonModeAnalyzer.cc:95
InputTag.h
edm::ParameterSet::getParameter
T getParameter(std::string const &) const
CommonModeAnalyzer::m_digicollectionToken
edm::EDGetTokenT< edm::DetSetVector< SiStripRawDigi > > m_digicollectionToken
Definition: CommonModeAnalyzer.cc:81
CommonModeAnalyzer::beginRun
void beginRun(const edm::Run &, const edm::EventSetup &) override
Definition: CommonModeAnalyzer.cc:265
APVCyclePhaseCollection::nopartition
Definition: APVCyclePhaseCollection.h:21
std
Definition: JetResolutionObject.h:76
CommonModeAnalyzer::m_ignorebadfedmod
const bool m_ignorebadfedmod
Definition: CommonModeAnalyzer.cc:86
CommonModeAnalyzer::~CommonModeAnalyzer
~CommonModeAnalyzer() override
Definition: CommonModeAnalyzer.cc:188
hcalSimParameters_cfi.he
he
Definition: hcalSimParameters_cfi.py:75
FedChannelConnection.h
DetId.h
Frameworkfwd.h
CommonModeAnalyzer::m_cacheIdDet
uint32_t m_cacheIdDet
DB cache ID used to establish if the cabling has changed during the run.
Definition: CommonModeAnalyzer.cc:101
APVCyclePhaseCollection::getPhase
const int getPhase(const std::string partition) const
Definition: APVCyclePhaseCollection.cc:5
CommonModeAnalyzer::m_apvphasecollToken
edm::EDGetTokenT< APVCyclePhaseCollection > m_apvphasecollToken
Definition: CommonModeAnalyzer.cc:83
CommonModeAnalyzer::beginJob
void beginJob() override
Definition: CommonModeAnalyzer.cc:287
SiStripDetCablingRcd.h
ParameterSet.h
CommonModeAnalyzer::m_ignorenotconnected
const bool m_ignorenotconnected
Definition: CommonModeAnalyzer.cc:87
edm::HandleBase::isValid
bool isValid() const
Definition: HandleBase.h:70
edm::Event
Definition: Event.h:73
APVCyclePhaseCollection::invalid
Definition: APVCyclePhaseCollection.h:21
edm::EDCollection::end
const_iterator end() const
Definition: EDCollection.h:122
label
const char * label
Definition: PFTauDecayModeTools.cc:11
SiStripDetCabling::getConnections
const std::vector< const FedChannelConnection * > & getConnections(uint32_t det_id) const
Definition: SiStripDetCabling.cc:161
DetIdCollection.h
DetIdSelector
Definition: DetIdSelector.h:12
TFileService::make
T * make(const Args &... args) const
make new ROOT object
Definition: TFileService.h:64
RunHistogramManager::makeTProfile
TProfile ** makeTProfile(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
Definition: RunHistogramManager.cc:52
edm::DetSet::const_iterator
collection_type::const_iterator const_iterator
Definition: DetSet.h:31