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 
20 // system include files
21 #include <memory>
22 
23 // user include files
24 #include "TH1D.h"
25 #include "TProfile.h"
26 #include <vector>
27 #include <algorithm>
28 #include <string>
29 
32 
36 
38 
40 
43 
45 
48 
51 
54 
57 
62 //
63 // class decleration
64 //
65 
67 public:
68  explicit CommonModeAnalyzer(const edm::ParameterSet&);
70 
71 
72 private:
73  virtual void beginJob() override ;
74  virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
75  virtual void endRun(const edm::Run&, const edm::EventSetup&) override;
76  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
77  virtual void endJob() override ;
78 
79  void updateDetCabling( const edm::EventSetup& setup );
80 
81  // ----------member data ---------------------------
82 
88  const bool m_ignorebadfedmod;
90  int m_nevents;
91 
92  std::vector<DetIdSelector> m_selections;
93  std::vector<std::string> m_labels;
94  std::vector<TH1D*> m_cmdist;
95  std::vector<TH1D*> m_nmodules;
96  std::vector<TH1D*> m_napvs;
97  std::vector<TProfile*> m_cmvsdbxincycle;
98  std::vector<TProfile**> m_cmvsbxrun;
99  std::vector<TProfile**> m_cmvsorbitrun;
100 
102 
103  uint32_t m_cacheIdDet;
105 
106 
107 };
108 
109 //
110 // constants, enums and typedefs
111 //
112 
113 //
114 // static data member definitions
115 //
116 
117 //
118 // constructors and destructor
119 //
121  m_digicollectionToken(consumes<edm::DetSetVector<SiStripRawDigi> >(iConfig.getParameter<edm::InputTag>("digiCollection"))),
122  m_historyProductToken(consumes<EventWithHistory>(iConfig.getParameter<edm::InputTag>("historyProduct"))),
123  m_apvphasecollToken(consumes<APVCyclePhaseCollection>(iConfig.getParameter<edm::InputTag>("apvPhaseCollection"))),
124  m_digibadmodulecollectionToken(consumes<DetIdCollection>(iConfig.getParameter<edm::InputTag>("badModuleDigiCollection"))),
125  m_phasepart(iConfig.getUntrackedParameter<std::string>("phasePartition","None")),
126  m_ignorebadfedmod(iConfig.getParameter<bool>("ignoreBadFEDMod")),
127  m_ignorenotconnected(iConfig.getParameter<bool>("ignoreNotConnected")),
128  m_nevents(0),
129  m_selections(),
130  m_labels(),
131  m_cmdist(),
132  m_nmodules(),
133  m_napvs(),
135  m_cmvsbxrun(),
136  m_cmvsorbitrun(),
138  m_cacheIdDet(0),
139  m_detCabling(0)
140 {
141  //now do what ever initialization is needed
142 
144 
145  std::vector<edm::ParameterSet> selconfigs = iConfig.getParameter<std::vector<edm::ParameterSet> >("selections");
146 
147  for(std::vector<edm::ParameterSet>::const_iterator selconfig=selconfigs.begin();selconfig!=selconfigs.end();++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"); m_cmvsdbxincycle.back()->GetYaxis()->SetTitle("CM (ADC counts)");
175  }
176  {
177  std::string hname = label + "_CMvsBX";
178  std::string htitle = label + " Common Mode vs BX";
179  m_cmvsbxrun.push_back(m_rhm.makeTProfile(hname.c_str(),htitle.c_str(),3565,-0.5,3565-0.5));
180  }
181  {
182  std::string hname = label + "_CMvsOrbit";
183  std::string htitle = label + " Common Mode vs Orbit";
184  m_cmvsorbitrun.push_back(m_rhm.makeTProfile(hname.c_str(),htitle.c_str(),4*500,0,500*262144));
185  }
186  }
187 
188 }
189 
190 
192 {
193 
194  // do anything here that needs to be done at desctruction time
195  // (e.g. close files, deallocate resources etc.)
196 
197 
198 
199 
200 }
201 
202 
203 //
204 // member functions
205 //
206 
207 // ------------ method called to for each event ------------
208 void
210 {
211  using namespace edm;
212 
213  updateDetCabling( iSetup );
214 
215  m_nevents++;
216 
219 
221  iEvent.getByToken(m_apvphasecollToken,apvphase);
222 
223  Handle<DetIdCollection > badmodules;
224  iEvent.getByToken(m_digibadmodulecollectionToken,badmodules);
225 
226  int thephase = APVCyclePhaseCollection::invalid;
227  if(apvphase.isValid() && !apvphase.failedToGet()) {
228  thephase = apvphase->getPhase(m_phasepart);
229  }
230  bool isphaseok = (thephase!=APVCyclePhaseCollection::invalid &&
233 
235  iEvent.getByToken(m_digicollectionToken,digis);
236 
237  // loop on detector with digis
238 
239  std::vector<int> nmodules(m_selections.size(),0);
240  std::vector<int> napvs(m_selections.size(),0);
241 
242  for(edm::DetSetVector<SiStripRawDigi>::const_iterator mod = digis->begin();mod!=digis->end();mod++) {
243 
244  std::vector<const FedChannelConnection*> conns = m_detCabling->getConnections(mod->detId());
245 
246  if(!m_ignorebadfedmod || std::find(badmodules->begin(),badmodules->end(),mod->detId())==badmodules->end()) {
247  for(unsigned int isel=0;isel< m_selections.size(); ++isel) {
248  if(m_selections[isel].isSelected(mod->detId())) {
249  unsigned int strip = 0;
250  ++nmodules[isel];
251  for(edm::DetSet<SiStripRawDigi>::const_iterator digi=mod->begin();digi!=mod->end();digi++,strip++) {
252  LogDebug("StripNumber") << "Strip number " << strip;
253  if(!m_ignorenotconnected ||
254  ((conns.size() > strip/2) && conns[strip/2] && conns[strip/2]->isConnected())) {
255  ++napvs[isel];
256  m_cmdist[isel]->Fill(digi->adc());
257  if(isphaseok) m_cmvsdbxincycle[isel]->Fill(he->deltaBXinCycle(thephase),digi->adc());
258  if(m_cmvsbxrun[isel] && *(m_cmvsbxrun[isel])) (*(m_cmvsbxrun[isel]))->Fill(iEvent.bunchCrossing(),digi->adc());
259  if(m_cmvsorbitrun[isel] && *(m_cmvsorbitrun[isel])) (*(m_cmvsorbitrun[isel]))->Fill(iEvent.orbitNumber(),digi->adc());
260  }
261  else if(digi->adc()>0) {
262  edm::LogWarning("NonZeroCMWhenDisconnected") << " Non zero CM in "
263  << mod->detId() << " APV " << strip
264  << " with " << conns.size()
265  << " connections and connection pointer" << conns[strip/2];
266  }
267  }
268  }
269  }
270  }
271  }
272  for(unsigned int isel=0;isel < m_selections.size(); ++isel) {
273  m_nmodules[isel]->Fill(nmodules[isel]);
274  m_napvs[isel]->Fill(napvs[isel]);
275  }
276 }
277 
278 void
280 {
281 
282 
283  m_rhm.beginRun(iRun);
284 
285  for(std::vector<TProfile**>::const_iterator cmvsbx=m_cmvsbxrun.begin();cmvsbx!=m_cmvsbxrun.end();++cmvsbx) {
286  if(*cmvsbx && *(*cmvsbx)) {
287  (*(*cmvsbx))->GetXaxis()->SetTitle("BX"); (*(*cmvsbx))->GetYaxis()->SetTitle("CM (ADC counts)");
288  }
289  }
290  for(std::vector<TProfile**>::const_iterator cmvsorbit=m_cmvsorbitrun.begin();cmvsorbit!=m_cmvsorbitrun.end();++cmvsorbit) {
291  if(*cmvsorbit && *(*cmvsorbit)) {
292  (*(*cmvsorbit))->GetXaxis()->SetTitle("orbit"); (*(*cmvsorbit))->GetYaxis()->SetTitle("CM (ADC counts)");
293  (*(*cmvsorbit))->SetCanExtend(TH1::kXaxis);
294  }
295  }
296 
297 }
298 
299 void
301 {
302 }
303 
304 
305 // ------------ method called once each job just before starting event loop ------------
306 void
308 {
309 
310 }
311 
312 // ------------ method called once each job just after ending the event loop ------------
313 void
315 
316  edm::LogInfo("EndOfJob") << m_nevents << " analyzed events";
317 
318 }
320 {
321  uint32_t cache_id = setup.get<SiStripDetCablingRcd>().cacheIdentifier();//.get( cabling_ );
322 
323  if ( m_cacheIdDet != cache_id ) { // If the cache ID has changed since the last update...
324  // Update the cabling object
326  setup.get<SiStripDetCablingRcd>().get( c );
327  m_detCabling = c.product();
328  m_cacheIdDet = cache_id;
329  } // end of new cache ID check
330 }
331 
332 
333 
334 //define this as a plug-in
#define LogDebug(id)
std::vector< TH1D * > m_nmodules
T getParameter(std::string const &) const
void updateDetCabling(const edm::EventSetup &setup)
virtual void endRun(const edm::Run &, const edm::EventSetup &) override
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
std::vector< TProfile ** > m_cmvsbxrun
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:460
std::vector< TH1D * > m_cmdist
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
const_iterator end() const
Definition: EDCollection.h:153
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
selection
main part
Definition: corrVsCorr.py:98
int bunchCrossing() const
Definition: EventBase.h:66
const SiStripDetCabling * m_detCabling
The cabling object.
def setup(process, global_tag, zero_tesla=False)
Definition: GeneralSetup.py:1
T * make(const Args &...args) const
make new ROOT object
Definition: TFileService.h:64
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
uint32_t m_cacheIdDet
DB cache ID used to establish if the cabling has changed during the run.
const std::string m_phasepart
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
virtual void beginJob() override
const std::vector< const FedChannelConnection * > & getConnections(uint32_t det_id) const
int iEvent
Definition: GenABIO.cc:230
const bool m_ignorenotconnected
const int getPhase(const std::string partition) const
std::vector< TProfile ** > m_cmvsorbitrun
void Fill(HcalDetId &id, double val, std::vector< TH2F > &depth)
virtual void endJob() override
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
TProfile ** makeTProfile(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
CommonModeAnalyzer(const edm::ParameterSet &)
edm::EDGetTokenT< EventWithHistory > m_historyProductToken
int orbitNumber() const
Definition: EventBase.h:67
RunHistogramManager m_rhm
bool isValid() const
Definition: HandleBase.h:74
edm::EDGetTokenT< edm::DetSetVector< SiStripRawDigi > > m_digicollectionToken
bool failedToGet() const
Definition: HandleBase.h:78
const_iterator begin() const
Definition: EDCollection.h:146
std::vector< std::string > m_labels
const T & get() const
Definition: EventSetup.h:56
void beginRun(const edm::Run &iRun)
std::vector< DetIdSelector > m_selections
long long deltaBXinCycle(const unsigned int ev2, const unsigned int ev1, const int bx0) const
HLT enums.
std::vector< TProfile * > m_cmvsdbxincycle
edm::EDGetTokenT< DetIdCollection > m_digibadmodulecollectionToken
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:104
std::vector< TH1D * > m_napvs
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
T const * product() const
Definition: ESHandle.h:86
Definition: Run.h:42
edm::EDGetTokenT< APVCyclePhaseCollection > m_apvphasecollToken