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 
32 
35 
37 
39 
42 
44 
47 
50 
53 
56 
61 //
62 // class decleration
63 //
64 
65 class CommonModeAnalyzer : public edm::one::EDAnalyzer<edm::one::SharedResources, edm::one::WatchRuns> {
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 
77  void updateDetCabling(const SiStripDetCablingRcd& iRcd);
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 
103  const SiStripDetCabling* m_detCabling = nullptr;
104 };
105 
106 //
107 // constants, enums and typedefs
108 //
109 
110 //
111 // static data member definitions
112 //
113 
114 //
115 // constructors and destructor
116 //
118  : m_digicollectionToken(
119  consumes<edm::DetSetVector<SiStripRawDigi> >(iConfig.getParameter<edm::InputTag>("digiCollection"))),
120  m_historyProductToken(consumes<EventWithHistory>(iConfig.getParameter<edm::InputTag>("historyProduct"))),
121  m_apvphasecollToken(consumes<APVCyclePhaseCollection>(iConfig.getParameter<edm::InputTag>("apvPhaseCollection"))),
122  m_digibadmodulecollectionToken(
123  consumes<DetIdCollection>(iConfig.getParameter<edm::InputTag>("badModuleDigiCollection"))),
124  m_phasepart(iConfig.getUntrackedParameter<std::string>("phasePartition", "None")),
125  m_ignorebadfedmod(iConfig.getParameter<bool>("ignoreBadFEDMod")),
126  m_ignorenotconnected(iConfig.getParameter<bool>("ignoreNotConnected")),
127  m_nevents(0),
128  m_selections(),
129  m_labels(),
130  m_cmdist(),
131  m_nmodules(),
132  m_napvs(),
133  m_cmvsdbxincycle(),
134  m_cmvsbxrun(),
135  m_cmvsorbitrun(),
136  m_rhm(consumesCollector()),
137  m_detCablingWatcher(this, &CommonModeAnalyzer::updateDetCabling),
138  m_detCablingToken(esConsumes()) {
139  //now do what ever initialization is needed
140  usesResource(TFileService::kSharedResource);
141 
143 
144  std::vector<edm::ParameterSet> selconfigs = iConfig.getParameter<std::vector<edm::ParameterSet> >("selections");
145 
146  for (std::vector<edm::ParameterSet>::const_iterator selconfig = selconfigs.begin(); selconfig != selconfigs.end();
147  ++selconfig) {
148  std::string label = selconfig->getParameter<std::string>("label");
149  DetIdSelector selection(*selconfig);
150  m_selections.push_back(selection);
151 
152  {
153  std::string hname = label + "_CommonMode";
154  std::string htitle = label + " Common Mode";
155  m_cmdist.push_back(tfserv->make<TH1D>(hname.c_str(), htitle.c_str(), 1024, -0.5, 1024 - 0.5));
156  m_cmdist.back()->GetXaxis()->SetTitle("ADC");
157  }
158  {
159  std::string hname = label + "_nmodules";
160  std::string htitle = label + " Number of Modules with CM value";
161  m_nmodules.push_back(tfserv->make<TH1D>(hname.c_str(), htitle.c_str(), 20000, -0.5, 20000 - 0.5));
162  m_nmodules.back()->GetXaxis()->SetTitle("#modules");
163  }
164  {
165  std::string hname = label + "_napvs";
166  std::string htitle = label + " Number of APVs with CM value";
167  m_napvs.push_back(tfserv->make<TH1D>(hname.c_str(), htitle.c_str(), 2000, -0.5, 80000 - 0.5));
168  m_napvs.back()->GetXaxis()->SetTitle("#apvs");
169  }
170  {
171  std::string hname = label + "_CMvsDBXinCycle";
172  std::string htitle = label + " Common Mode vs DBX in Cycle";
173  m_cmvsdbxincycle.push_back(tfserv->make<TProfile>(hname.c_str(), htitle.c_str(), 1000, -0.5, 1000 - 0.5));
174  m_cmvsdbxincycle.back()->GetXaxis()->SetTitle("DBX in cycle");
175  m_cmvsdbxincycle.back()->GetYaxis()->SetTitle("CM (ADC counts)");
176  }
177  {
178  std::string hname = label + "_CMvsBX";
179  std::string htitle = label + " Common Mode vs BX";
180  m_cmvsbxrun.push_back(m_rhm.makeTProfile(hname.c_str(), htitle.c_str(), 3565, -0.5, 3565 - 0.5));
181  }
182  {
183  std::string hname = label + "_CMvsOrbit";
184  std::string htitle = label + " Common Mode vs Orbit";
185  m_cmvsorbitrun.push_back(m_rhm.makeTProfile(hname.c_str(), htitle.c_str(), 4 * 500, 0, 500 * 262144));
186  }
187  }
188 }
189 
191  // do anything here that needs to be done at desctruction time
192  // (e.g. close files, deallocate resources etc.)
193 }
194 
195 //
196 // member functions
197 //
198 
199 // ------------ method called to for each event ------------
201  using namespace edm;
202 
203  m_detCablingWatcher.check(iSetup);
204 
205  m_nevents++;
206 
208  iEvent.getByToken(m_historyProductToken, he);
209 
211  iEvent.getByToken(m_apvphasecollToken, apvphase);
212 
213  Handle<DetIdCollection> badmodules;
214  iEvent.getByToken(m_digibadmodulecollectionToken, badmodules);
215 
216  int thephase = APVCyclePhaseCollection::invalid;
217  if (apvphase.isValid() && !apvphase.failedToGet()) {
218  thephase = apvphase->getPhase(m_phasepart);
219  }
220  bool isphaseok = (thephase != APVCyclePhaseCollection::invalid && thephase != APVCyclePhaseCollection::multiphase &&
222 
224  iEvent.getByToken(m_digicollectionToken, digis);
225 
226  // loop on detector with digis
227 
228  std::vector<int> nmodules(m_selections.size(), 0);
229  std::vector<int> napvs(m_selections.size(), 0);
230 
231  for (edm::DetSetVector<SiStripRawDigi>::const_iterator mod = digis->begin(); mod != digis->end(); mod++) {
232  std::vector<const FedChannelConnection*> conns = m_detCabling->getConnections(mod->detId());
233 
234  if (!m_ignorebadfedmod || std::find(badmodules->begin(), badmodules->end(), mod->detId()) == badmodules->end()) {
235  for (unsigned int isel = 0; isel < m_selections.size(); ++isel) {
236  if (m_selections[isel].isSelected(mod->detId())) {
237  unsigned int strip = 0;
238  ++nmodules[isel];
239  for (edm::DetSet<SiStripRawDigi>::const_iterator digi = mod->begin(); digi != mod->end(); digi++, strip++) {
240  LogDebug("StripNumber") << "Strip number " << strip;
241  if (!m_ignorenotconnected ||
242  ((conns.size() > strip / 2) && conns[strip / 2] && conns[strip / 2]->isConnected())) {
243  ++napvs[isel];
244  m_cmdist[isel]->Fill(digi->adc());
245  if (isphaseok)
246  m_cmvsdbxincycle[isel]->Fill(he->deltaBXinCycle(thephase), digi->adc());
247  if (m_cmvsbxrun[isel] && *(m_cmvsbxrun[isel]))
248  (*(m_cmvsbxrun[isel]))->Fill(iEvent.bunchCrossing(), digi->adc());
249  if (m_cmvsorbitrun[isel] && *(m_cmvsorbitrun[isel]))
250  (*(m_cmvsorbitrun[isel]))->Fill(iEvent.orbitNumber(), digi->adc());
251  } else if (digi->adc() > 0) {
252  edm::LogWarning("NonZeroCMWhenDisconnected")
253  << " Non zero CM in " << mod->detId() << " APV " << strip << " with " << conns.size()
254  << " connections and connection pointer" << conns[strip / 2];
255  }
256  }
257  }
258  }
259  }
260  }
261  for (unsigned int isel = 0; isel < m_selections.size(); ++isel) {
262  m_nmodules[isel]->Fill(nmodules[isel]);
263  m_napvs[isel]->Fill(napvs[isel]);
264  }
265 }
266 
268  m_rhm.beginRun(iRun);
269 
270  for (std::vector<TProfile**>::const_iterator cmvsbx = m_cmvsbxrun.begin(); cmvsbx != m_cmvsbxrun.end(); ++cmvsbx) {
271  if (*cmvsbx && *(*cmvsbx)) {
272  (*(*cmvsbx))->GetXaxis()->SetTitle("BX");
273  (*(*cmvsbx))->GetYaxis()->SetTitle("CM (ADC counts)");
274  }
275  }
276  for (std::vector<TProfile**>::const_iterator cmvsorbit = m_cmvsorbitrun.begin(); cmvsorbit != m_cmvsorbitrun.end();
277  ++cmvsorbit) {
278  if (*cmvsorbit && *(*cmvsorbit)) {
279  (*(*cmvsorbit))->GetXaxis()->SetTitle("orbit");
280  (*(*cmvsorbit))->GetYaxis()->SetTitle("CM (ADC counts)");
281  (*(*cmvsorbit))->SetCanExtend(TH1::kXaxis);
282  }
283  }
284 }
285 
287 
288 // ------------ method called once each job just before starting event loop ------------
290 
291 // ------------ method called once each job just after ending the event loop ------------
292 void CommonModeAnalyzer::endJob() { edm::LogInfo("EndOfJob") << m_nevents << " analyzed events"; }
293 
296 }
297 
298 //define this as a plug-in
static const std::string kSharedResource
Definition: TFileService.h:76
std::vector< TH1D * > m_nmodules
ESGetTokenH3DDVariant esConsumes(std::string const &Record, edm::ConsumesCollector &)
Definition: DeDxTools.cc:283
void endRun(const edm::Run &, const edm::EventSetup &) override
T getParameter(std::string const &) const
Definition: ParameterSet.h:307
void analyze(const edm::Event &, const edm::EventSetup &) override
const std::vector< const FedChannelConnection * > & getConnections(uint32_t det_id) const
std::vector< TProfile ** > m_cmvsbxrun
std::vector< TH1D * > m_cmdist
void beginRun(const edm::Run &, const edm::EventSetup &) override
selection
main part
Definition: corrVsCorr.py:100
const SiStripDetCabling * m_detCabling
The cabling object.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
edm::ESGetToken< SiStripDetCabling, SiStripDetCablingRcd > m_detCablingToken
const std::string m_phasepart
void beginJob() override
bool failedToGet() const
Definition: HandleBase.h:72
char const * label
int iEvent
Definition: GenABIO.cc:224
const bool m_ignorenotconnected
std::vector< TProfile ** > m_cmvsorbitrun
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
void endJob() override
TProfile ** makeTProfile(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
CommonModeAnalyzer(const edm::ParameterSet &)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:16
edm::EDGetTokenT< EventWithHistory > m_historyProductToken
RunHistogramManager m_rhm
const_iterator begin() const
Definition: EDCollection.h:118
edm::EDGetTokenT< edm::DetSetVector< SiStripRawDigi > > m_digicollectionToken
edm::ESWatcher< SiStripDetCablingRcd > m_detCablingWatcher
Log< level::Info, false > LogInfo
std::vector< std::string > m_labels
void beginRun(const edm::Run &iRun)
bool isSelected(const std::vector< L1HPSPFTauQualityCut > &qualityCuts, const l1t::PFCandidate &pfCand, float_t primaryVertexZ)
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:57
bool isValid() const
Definition: HandleBase.h:70
std::vector< DetIdSelector > m_selections
const int getPhase(const std::string partition) const
HLT enums.
std::vector< TProfile * > m_cmvsdbxincycle
edm::EDGetTokenT< DetIdCollection > m_digibadmodulecollectionToken
void updateDetCabling(const SiStripDetCablingRcd &iRcd)
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
Log< level::Warning, false > LogWarning
collection_type::const_iterator const_iterator
Definition: DetSet.h:31
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:102
std::vector< TH1D * > m_napvs
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
const_iterator end() const
Definition: EDCollection.h:123
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4
Definition: Run.h:45
edm::EDGetTokenT< APVCyclePhaseCollection > m_apvphasecollToken
#define LogDebug(id)