CMS 3D CMS Logo

APVShotsAnalyzer.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiStripTools
4 // Class: APVShotsAnalyzer
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 "TH1F.h"
25 #include "TProfile.h"
26 #include <vector>
27 #include <string>
28 
31 
34 
36 
38 
41 
43 
46 
49 
52 
54 //******** Single include for the TkMap *************
56 //***************************************************
57 
58 //******** includes for the cabling *************
63 //***************************************************
64 
65 
66 //
67 // class decleration
68 //
69 
71 public:
72  explicit APVShotsAnalyzer(const edm::ParameterSet&);
74 
75 
76 private:
77  virtual void beginJob() override ;
78  virtual void beginRun(const edm::Run&, const edm::EventSetup&) override;
79  virtual void endRun(const edm::Run&, const edm::EventSetup&) override;
80  virtual void analyze(const edm::Event&, const edm::EventSetup&) override;
81  virtual void endJob() override ;
82 
83  void updateDetCabling( const edm::EventSetup& setup );
84 
85  // ----------member data ---------------------------
86 
91  bool _zs;
93  int _nevents;
94 
95  TH1F* _nShots;
96  TH1F* _whichAPV;
97  TH1F* _stripMult;
98  TH1F* _median;
99  TH1F* _subDetector;
100  TH1F* _fed;
102 
103  TProfile* _nShotsbxcycle;
104  TProfile* _nShotsdbx;
105  TProfile* _nShotsdbxincycle;
107  TProfile* _nShotsdbxprev;
109 
112 
114 
115  TH1F** _nShotsrun;
116  TProfile** _nShotsVsTimerun;
117  TH1F** _whichAPVrun;
119  TH1F** _medianrun;
121  TH1F** _fedrun;
122 
124 
125  // DetCabling
127  uint32_t _cacheIdDet;
129 
130 };
131 
132 //
133 // constants, enums and typedefs
134 //
135 
136 //
137 // static data member definitions
138 //
139 
140 //
141 // constructors and destructor
142 //
144  _digicollectionToken(consumes<edm::DetSetVector<SiStripDigi> >(iConfig.getParameter<edm::InputTag>("digiCollection"))),
145  _historyProductToken(consumes<EventWithHistory>(iConfig.getParameter<edm::InputTag>("historyProduct"))),
146  _apvphasecollToken(consumes<APVCyclePhaseCollection>(iConfig.getParameter<edm::InputTag>("apvPhaseCollection"))),
147  _phasepart(iConfig.getUntrackedParameter<std::string>("phasePartition","None")),
148  _zs(iConfig.getUntrackedParameter<bool>("zeroSuppressed",true)),
149  _suffix(iConfig.getParameter<std::string>("mapSuffix")),
150  _nevents(0),
152  _useCabling(iConfig.getUntrackedParameter<bool>("useCabling",true)),
153  _cacheIdDet(0),
154  _detCabling(0)
155 {
156  //now do what ever initialization is needed
157 
158  if(!_zs) _suffix += "_notZS";
159 
161 
162  _nShots = tfserv->make<TH1F>("nShots","Number of Shots per event",200,-0.5,199.5);
163  _nShots->GetXaxis()->SetTitle("Shots"); _nShots->GetYaxis()->SetTitle("Events");
164  _nShots->StatOverflows(kTRUE);
165 
166  _whichAPV = tfserv->make<TH1F>("whichAPV","APV with shots",6,-0.5,5.5);
167  _whichAPV->GetXaxis()->SetTitle("APV"); _whichAPV->GetYaxis()->SetTitle("Shots");
168 
169  _stripMult = tfserv->make<TH1F>("stripMultiplicity","Shot Strip Multiplicity",129,-0.5,128.5);
170  _stripMult->GetXaxis()->SetTitle("Number of Strips"); _stripMult->GetYaxis()->SetTitle("Shots");
171 
172  _median = tfserv->make<TH1F>("median","APV Shot charge median",256,-0.5,255.5);
173  _median->GetXaxis()->SetTitle("Charge [ADC]"); _median->GetYaxis()->SetTitle("Shots");
174 
175  _subDetector = tfserv->make<TH1F>("subDets","SubDetector Shot distribution",10,-0.5,9.5);
176  _subDetector->GetYaxis()->SetTitle("Shots");
177 
178  _nShotsbxcycle = tfserv->make<TProfile>("nShotsBXcycle","Number of shots vs APV cycle bin",70,-0.5,69.5);
179  _nShotsbxcycle->GetXaxis()->SetTitle("Event BX mod(70)"); _nShotsbxcycle->GetYaxis()->SetTitle("APV shots");
180 
181  _nShotsdbx = tfserv->make<TProfile>("nShotsDBX","Number of shots vs #Delta(BX)",1000,-0.5,999.5);
182  _nShotsdbx->GetXaxis()->SetTitle("Event #Delta(BX)"); _nShotsdbx->GetYaxis()->SetTitle("APV shots");
183 
184  _nShotsdbxincycle = tfserv->make<TProfile>("nShotsDBXincycle","Number of shots vs #Delta(BX) w.r.t. APV cycle",1000,-0.5,999.5);
185  _nShotsdbxincycle->GetXaxis()->SetTitle("Event #Delta(BX) w.r.t. APV cycle"); _nShotsdbxincycle->GetYaxis()->SetTitle("APV shots");
186 
187  _nShotsbxcycleprev = tfserv->make<TProfile>("nShotsBXcycleprev","Number of shots vs APV cycle bin of previous L1A",70,-0.5,69.5);
188  _nShotsbxcycleprev->GetXaxis()->SetTitle("Previous L1A BX mod(70)"); _nShotsbxcycleprev->GetYaxis()->SetTitle("APV shots");
189 
190  _nShotsdbxprev = tfserv->make<TProfile>("nShotsDBXprev","Number of shots vs #Delta(BX) of previous L1A",1000,-0.5,999.5);
191  _nShotsdbxprev->GetXaxis()->SetTitle("Previous L1A #Delta(BX)"); _nShotsdbxprev->GetYaxis()->SetTitle("APV shots");
192 
193  _nShotsdbxincycleprev = tfserv->make<TProfile>("nShotsDBXincycleprev","Number of shots vs #Delta(BX) w.r.t. APV cycle of previous L1A",1000,-0.5,999.5);
194  _nShotsdbxincycleprev->GetXaxis()->SetTitle("Previous L1A #Delta(BX) w.r.t. APV cycle"); _nShotsdbxincycleprev->GetYaxis()->SetTitle("APV shots");
195 
196  _nShotsrun = _rhm.makeTH1F("nShotsrun","Number of Shots per event",200,-0.5,199.5);
197  _nShotsVsTimerun = _rhm.makeTProfile("nShotsVsTimerun","Mean number of shots vs orbit number",4*500,0,500*262144);
198  _whichAPVrun = _rhm.makeTH1F("whichAPVrun","APV with shots",6,-0.5,5.5);
199  _stripMultrun = _rhm.makeTH1F("stripMultiplicityrun","Shot Strip Multiplicity",129,-0.5,128.5);
200  _medianrun = _rhm.makeTH1F("medianrun","APV Shot charge median",256,-0.5,255.5);
201  _subDetectorrun = _rhm.makeTH1F("subDetsrun","SubDetector Shot distribution",10,-0.5,9.5);
202 
203  if (_useCabling) {
204  _fed = tfserv->make<TH1F>("fed","FED Shot distribution",440,50,490);
205  _fed->GetYaxis()->SetTitle("Shots");
206  _fedrun = _rhm.makeTH1F("fedrun","FED Shot distribution",440,50,490);
207 
208  _channelvsfed = tfserv->make<TH2F>("channelvsfed","Channel vs FED Shot distribution",440,50,490,97,-0.5,96.5);
209  _channelvsfed->GetXaxis()->SetTitle("FED"); _channelvsfed->GetYaxis()->SetTitle("Channel");
210 
211 
212  _nShotsVsFED = tfserv->make<TH2F>("nShotsVsFED","Number of Shots per event vs fedid",440,50,490,200,-0.5,199.5);
213  _nShotsVsFED->GetXaxis()->SetTitle("fedId"); _nShots->GetYaxis()->SetTitle("Shots"); _nShots->GetZaxis()->SetTitle("Events");
214  _nShotsVsFED->StatOverflows(kTRUE);
215 
216  _medianVsFED = tfserv->make<TH2F>("medianVsFED","APV Shot charge median vs fedid",440,50,490,256,-0.5,255.5);
217  _medianVsFED->GetXaxis()->SetTitle("fedId");_medianVsFED->GetYaxis()->SetTitle("Charge [ADC]"); _median->GetZaxis()->SetTitle("Shots");
218  }
219 
220  tkhisto =new TkHistoMap("ShotMultiplicity","ShotMultiplicity",-1);
221  tkhisto2 =new TkHistoMap("StripMultiplicity","StripMultiplicity",-1);
222 }
223 
224 
226 {
227 
228  // do anything here that needs to be done at desctruction time
229  // (e.g. close files, deallocate resources etc.)
230  if ( _detCabling ) _detCabling = 0;
231 
232 }
233 
234 
235 //
236 // member functions
237 //
238 
239 // ------------ method called to for each event ------------
240 void
242 {
243  using namespace edm;
244 
245  if (_useCabling){
246  //retrieve cabling
247  updateDetCabling( iSetup );
248  }
249 
250  _nevents++;
251 
253  iEvent.getByToken(_historyProductToken,he);
254 
256  iEvent.getByToken(_apvphasecollToken,apvphase);
257 
258  int thephase = APVCyclePhaseCollection::invalid;
259  if(apvphase.isValid() && !apvphase.failedToGet()) {
260  thephase = apvphase->getPhase(_phasepart);
261  }
262  bool isphaseok = (thephase!=APVCyclePhaseCollection::invalid &&
265 
267  iEvent.getByToken(_digicollectionToken,digis);
268 
269  // loop on detector with digis
270 
271  int nshots=0;
272  std::vector<int> nshotsperFed;
273 
274  const uint16_t lNumFeds = sistrip::FED_ID_MAX-sistrip::FED_ID_MIN+1;
275  if (_useCabling){
276  nshotsperFed.resize(lNumFeds,0);
277  }
278 
279  APVShotFinder apvsf(*digis,_zs);
280  const std::vector<APVShot>& shots = apvsf.getShots();
281 
282  for(std::vector<APVShot>::const_iterator shot=shots.begin();shot!=shots.end();++shot) {
283  if(shot->isGenuine()) {
284 
285  //get the fedid from the detid
286 
287  uint32_t det=shot->detId();
288  if (_useCabling){
289 
290  int apvPair = shot->apvNumber()/2;
291  LogDebug("APVPair") << apvPair;
292 
293  const FedChannelConnection& theConn = _detCabling->getConnection( det , apvPair);
294 
295  int lChannelId = -1;
296  int thelFEDId = -1;
297  if(theConn.isConnected()) {
298  lChannelId = theConn.fedCh();
299  thelFEDId = theConn.fedId();
300  }
301  else {
302  edm::LogWarning("ConnectionNotFound") << "connection of det " << det << " APV pair " << apvPair << " not found";
303  }
304  LogDebug("FED channels") << thelFEDId << " " << lChannelId ;
305 
306  const std::vector<const FedChannelConnection *> & conns = _detCabling->getConnections( det );
307 
308  if (!(conns.size())) continue;
309  uint16_t lFedId = 0;
310  for (uint32_t ch = 0; ch<conns.size(); ch++) {
311  if(conns[ch] && conns[ch]->isConnected()) {
312  LogDebug("Dump") << *(conns[ch]);
313  LogDebug("ReadyForFEDid") << "Ready for FED id " << ch;
314  lFedId = conns[ch]->fedId();
315  LogDebug("FEDid") << "obtained FED id " << ch << " " << lFedId;
316  //uint16_t lFedCh = conns[ch]->fedCh();
317 
318  if (lFedId < sistrip::FED_ID_MIN || lFedId > sistrip::FED_ID_MAX){
319  edm::LogWarning("InvalidFEDid") << lFedId << " for detid " << det << " connection " << ch;
320  continue;
321  }
322  else break;
323  }
324  }
325  if (lFedId < sistrip::FED_ID_MIN || lFedId > sistrip::FED_ID_MAX){
326  edm::LogWarning("NoValidFEDid") << lFedId << "found for detid " << det;
327  continue;
328  }
329 
330  if(lFedId != thelFEDId) {
331  edm::LogWarning("FEDidMismatch") << " Mismatch in FED id for det " << det << " APV pair "
332  << apvPair << " : " << lFedId << " vs " << thelFEDId;
333  }
334 
335  LogDebug("FillingArray") << nshotsperFed.size() << " " << lFedId-sistrip::FED_ID_MIN;
336  ++nshotsperFed[lFedId-sistrip::FED_ID_MIN];
337 
338  LogDebug("ReadyToBeFilled") << " ready to be filled with " << thelFEDId << " " << lChannelId;
339  _channelvsfed->Fill(thelFEDId,lChannelId);
340  LogDebug("Filled") << " filled with " << thelFEDId << " " << lChannelId;
341 
342  _fed->Fill(lFedId);
343 
344  if(_fedrun && *_fedrun) (*_fedrun)->Fill(lFedId);
345  _medianVsFED->Fill(lFedId,shot->median());
346 
347 
348  }
349 
350  ++nshots;
351 
352 
353  _whichAPV->Fill(shot->apvNumber());
354  _median->Fill(shot->median());
355  _stripMult->Fill(shot->nStrips());
356  _subDetector->Fill(shot->subDet());
357 
358  if(_whichAPVrun && *_whichAPVrun) (*_whichAPVrun)->Fill(shot->apvNumber());
359  if(_medianrun && *_medianrun) (*_medianrun)->Fill(shot->median());
360  if(_stripMultrun && *_stripMultrun) (*_stripMultrun)->Fill(shot->nStrips());
361  if(_subDetectorrun && *_subDetectorrun) (*_subDetectorrun)->Fill(shot->subDet());
362 
363  tkhisto2->fill(det,shot->nStrips());;
364  tkhisto->add(det,1);
365 
366 
367 
368  }
369  }
370 
371  _nShots->Fill(nshots);
372  if(_nShotsrun && *_nShotsrun) (*_nShotsrun)->Fill(nshots);
373 
374  _nShotsdbx->Fill(he->deltaBX(),nshots);
375  _nShotsdbxprev->Fill(he->deltaBX(),nshots);
376  if(isphaseok) {
377  _nShotsbxcycle->Fill(he->absoluteBXinCycle(thephase)%70,nshots);
378  _nShotsdbxincycle->Fill(he->deltaBXinCycle(thephase),nshots);
379  _nShotsbxcycleprev->Fill(he->absoluteBXinCycle(1,thephase)%70,nshots);
380  _nShotsdbxincycleprev->Fill(he->deltaBXinCycle(1,2,thephase),nshots);
381  }
382 
383  if (_useCabling){
384  for (uint16_t lFed(0); lFed<lNumFeds; lFed++){
385  _nShotsVsFED->Fill(lFed+sistrip::FED_ID_MIN,nshotsperFed[lFed]);
386  }
387  }
388 
389  if(_nShotsVsTimerun && *_nShotsVsTimerun) (*_nShotsVsTimerun)->Fill(iEvent.orbitNumber(),nshots);
390 
391 
392 }
393 
394 void
396 {
397 
398 
399  _rhm.beginRun(iRun);
400 
401  if(_nShotsrun && *_nShotsrun) {
402  (*_nShotsrun)->GetXaxis()->SetTitle("Shots"); (*_nShotsrun)->GetYaxis()->SetTitle("Events");
403  (*_nShotsrun)->StatOverflows(kTRUE);
404  }
405 
407  (*_nShotsVsTimerun)->GetXaxis()->SetTitle("Orbit"); (*_nShotsVsTimerun)->GetYaxis()->SetTitle("Number of Shots");
408  (*_nShotsVsTimerun)->SetCanExtend(TH1::kXaxis);
409  }
410 
411  if(_whichAPVrun && *_whichAPVrun) {
412  (*_whichAPVrun)->GetXaxis()->SetTitle("APV"); (*_whichAPVrun)->GetYaxis()->SetTitle("Shots");
413  }
414 
415  if(_stripMultrun && *_stripMultrun) {
416  (*_stripMultrun)->GetXaxis()->SetTitle("Number of Strips"); (*_stripMultrun)->GetYaxis()->SetTitle("Shots");
417  }
418 
419  if(_medianrun && *_medianrun) {
420  (*_medianrun)->GetXaxis()->SetTitle("Charge [ADC]"); (*_medianrun)->GetYaxis()->SetTitle("Shots");
421  }
422 
424  (*_subDetectorrun)->GetYaxis()->SetTitle("Shots");
425  }
426 
427  if (_useCabling) {
428  if(_fedrun && *_fedrun) {
429  (*_fedrun)->GetYaxis()->SetTitle("Shots");
430  }
431  }
432 
433 }
434 
435 void
437 {
438 }
439 
440 
441 // ------------ method called once each job just before starting event loop ------------
442 void
444 {
445 
446 }
447 
448 // ------------ method called once each job just after ending the event loop ------------
449 void
451 
452  edm::LogInfo("EndOfJob") << _nevents << " analyzed events";
453 
455  TrackerMap tkmap,tkmap2;
456 
457  tkmap.setPalette(1);
458  tkmap2.setPalette(1);
459  tkhisto->dumpInTkMap(&tkmap);
460  tkhisto2->dumpInTkMap(&tkmap2);
461  std::string tkshotmultmapname = "ShotMultiplicity_" + _suffix + ".png";
462  tkmap.save(true,0,0,tkshotmultmapname);
463  std::string tkstripmultmapname = "StripMultiplicity_" + _suffix + ".png";
464  tkmap2.save(true,0,0,tkstripmultmapname);
465 
466  std::string rootmapname = "TKMap_"+_suffix+".root";
467  tkhisto->save(rootmapname);
468  tkhisto2->save(rootmapname);
469 }
470 
471 
473 {
474  if (_useCabling){
475  uint32_t cache_id = setup.get<SiStripDetCablingRcd>().cacheIdentifier();//.get( cabling_ );
476 
477  if ( _cacheIdDet != cache_id ) { // If the cache ID has changed since the last update...
478  // Update the cabling object
480  setup.get<SiStripDetCablingRcd>().get( c );
481  _detCabling = c.product();
482  _cacheIdDet = cache_id;
483  } // end of new cache ID check
484  }
485 }
486 
487 
488 
489 
490 //define this as a plug-in
#define LogDebug(id)
virtual void beginJob() override
const FedChannelConnection & getConnection(uint32_t det_id, unsigned short apv_pair) const
static const uint16_t FED_ID_MIN
long long deltaBX(const unsigned int ev2, const unsigned int ev1) const
const uint16_t & fedCh() const
bool getByToken(EDGetToken token, Handle< PROD > &result) const
Definition: Event.h:457
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
TProfile ** _nShotsVsTimerun
virtual void endRun(const edm::Run &, const edm::EventSetup &) override
long long absoluteBXinCycle(const unsigned int ev1, const int bx0) const
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
virtual void endJob() override
const uint16_t & fedId() const
TProfile * _nShotsbxcycleprev
TProfile * _nShotsdbxincycle
EDGetTokenT< ProductType > consumes(edm::InputTag const &tag)
const std::vector< const FedChannelConnection * > & getConnections(uint32_t det_id) const
const std::vector< APVShot > & getShots() const
void save(std::string filename)
Definition: TkHistoMap.cc:57
TH1F ** makeTH1F(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
int iEvent
Definition: GenABIO.cc:230
const int getPhase(const std::string partition) const
APVShotsAnalyzer(const edm::ParameterSet &)
TkHistoMap * tkhisto2
edm::EDGetTokenT< EventWithHistory > _historyProductToken
Class containning control, module, detector and connection information, at the level of a FED channel...
ConsumesCollector consumesCollector()
Use a ConsumesCollector to gather consumes information from helper functions.
void fill(uint32_t &detid, float value)
Definition: TkHistoMap.cc:180
void setPalette(int numpalette)
Definition: TrackerMap.h:124
TProfile * _nShotsbxcycle
void save(bool print_total=true, float minval=0., float maxval=0., std::string s="svgmap.svg", int width=1500, int height=800)
Definition: TrackerMap.cc:698
TProfile ** makeTProfile(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
virtual void beginRun(const edm::Run &, const edm::EventSetup &) override
const SiStripDetCabling * _detCabling
The cabling object.
int orbitNumber() const
Definition: EventBase.h:65
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
bool isValid() const
Definition: HandleBase.h:74
void dumpInTkMap(TrackerMap *tkmap, bool dumpEntries=false)
Definition: TkHistoMap.cc:234
bool failedToGet() const
Definition: HandleBase.h:78
TkHistoMap * tkhisto
const T & get() const
Definition: EventSetup.h:56
void beginRun(const edm::Run &iRun)
TProfile * _nShotsdbxincycleprev
long long deltaBXinCycle(const unsigned int ev2, const unsigned int ev1, const int bx0) const
const std::string _phasepart
HLT enums.
TProfile * _nShotsdbxprev
RunHistogramManager _rhm
static const uint16_t FED_ID_MAX
virtual void analyze(const edm::Event &, const edm::EventSetup &) override
edm::EDGetTokenT< APVCyclePhaseCollection > _apvphasecollToken
edm::EDGetTokenT< edm::DetSetVector< SiStripDigi > > _digicollectionToken
uint32_t _cacheIdDet
DB cache ID used to establish if the cabling has changed during the run.
T const * product() const
Definition: ESHandle.h:86
void add(uint32_t &detid, float value)
Definition: TkHistoMap.cc:213
void updateDetCabling(const edm::EventSetup &setup)
Definition: Run.h:42