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&);
73  ~APVShotsAnalyzer() override;
74 
75 
76 private:
77  void beginJob() override ;
78  void beginRun(const edm::Run&, const edm::EventSetup&) override;
79  void endRun(const edm::Run&, const edm::EventSetup&) override;
80  void analyze(const edm::Event&, const edm::EventSetup&) override;
81  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 
123  std::unique_ptr<TkHistoMap> tkhisto, tkhisto2;
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),
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 = nullptr;
221  tkhisto2 = nullptr;
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 = nullptr;
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  if ( ! ( tkhisto && tkhisto2 ) ) {
251  edm::ESHandle<TkDetMap> tkDetMapHandle;
252  iSetup.get<TrackerTopologyRcd>().get(tkDetMapHandle);
253  const TkDetMap* tkDetMap = tkDetMapHandle.product();
254 
255  tkhisto = std::make_unique<TkHistoMap>(tkDetMap, "ShotMultiplicity","ShotMultiplicity",-1);
256  tkhisto2 = std::make_unique<TkHistoMap>(tkDetMap, "StripMultiplicity","StripMultiplicity",-1);
257  }
258 
259  _nevents++;
260 
262  iEvent.getByToken(_historyProductToken,he);
263 
265  iEvent.getByToken(_apvphasecollToken,apvphase);
266 
267  int thephase = APVCyclePhaseCollection::invalid;
268  if(apvphase.isValid() && !apvphase.failedToGet()) {
269  thephase = apvphase->getPhase(_phasepart);
270  }
271  bool isphaseok = (thephase!=APVCyclePhaseCollection::invalid &&
274 
276  iEvent.getByToken(_digicollectionToken,digis);
277 
278  // loop on detector with digis
279 
280  int nshots=0;
281  std::vector<int> nshotsperFed;
282 
283  const uint16_t lNumFeds = sistrip::FED_ID_MAX-sistrip::FED_ID_MIN+1;
284  if (_useCabling){
285  nshotsperFed.resize(lNumFeds,0);
286  }
287 
288  APVShotFinder apvsf(*digis,_zs);
289  const std::vector<APVShot>& shots = apvsf.getShots();
290 
291  for(std::vector<APVShot>::const_iterator shot=shots.begin();shot!=shots.end();++shot) {
292  if(shot->isGenuine()) {
293 
294  //get the fedid from the detid
295 
296  uint32_t det=shot->detId();
297  if (_useCabling){
298 
299  int apvPair = shot->apvNumber()/2;
300  LogDebug("APVPair") << apvPair;
301 
302  const FedChannelConnection& theConn = _detCabling->getConnection( det , apvPair);
303 
304  int lChannelId = -1;
305  int thelFEDId = -1;
306  if(theConn.isConnected()) {
307  lChannelId = theConn.fedCh();
308  thelFEDId = theConn.fedId();
309  }
310  else {
311  edm::LogWarning("ConnectionNotFound") << "connection of det " << det << " APV pair " << apvPair << " not found";
312  }
313  LogDebug("FED channels") << thelFEDId << " " << lChannelId ;
314 
315  const std::vector<const FedChannelConnection *> & conns = _detCabling->getConnections( det );
316 
317  if (!(conns.size())) continue;
318  uint16_t lFedId = 0;
319  for (uint32_t ch = 0; ch<conns.size(); ch++) {
320  if(conns[ch] && conns[ch]->isConnected()) {
321  LogDebug("Dump") << *(conns[ch]);
322  LogDebug("ReadyForFEDid") << "Ready for FED id " << ch;
323  lFedId = conns[ch]->fedId();
324  LogDebug("FEDid") << "obtained FED id " << ch << " " << lFedId;
325  //uint16_t lFedCh = conns[ch]->fedCh();
326 
327  if (lFedId < sistrip::FED_ID_MIN || lFedId > sistrip::FED_ID_MAX){
328  edm::LogWarning("InvalidFEDid") << lFedId << " for detid " << det << " connection " << ch;
329  continue;
330  }
331  else break;
332  }
333  }
334  if (lFedId < sistrip::FED_ID_MIN || lFedId > sistrip::FED_ID_MAX){
335  edm::LogWarning("NoValidFEDid") << lFedId << "found for detid " << det;
336  continue;
337  }
338 
339  if(lFedId != thelFEDId) {
340  edm::LogWarning("FEDidMismatch") << " Mismatch in FED id for det " << det << " APV pair "
341  << apvPair << " : " << lFedId << " vs " << thelFEDId;
342  }
343 
344  LogDebug("FillingArray") << nshotsperFed.size() << " " << lFedId-sistrip::FED_ID_MIN;
345  ++nshotsperFed[lFedId-sistrip::FED_ID_MIN];
346 
347  LogDebug("ReadyToBeFilled") << " ready to be filled with " << thelFEDId << " " << lChannelId;
348  _channelvsfed->Fill(thelFEDId,lChannelId);
349  LogDebug("Filled") << " filled with " << thelFEDId << " " << lChannelId;
350 
351  _fed->Fill(lFedId);
352 
353  if(_fedrun && *_fedrun) (*_fedrun)->Fill(lFedId);
354  _medianVsFED->Fill(lFedId,shot->median());
355 
356 
357  }
358 
359  ++nshots;
360 
361 
362  _whichAPV->Fill(shot->apvNumber());
363  _median->Fill(shot->median());
364  _stripMult->Fill(shot->nStrips());
365  _subDetector->Fill(shot->subDet());
366 
367  if(_whichAPVrun && *_whichAPVrun) (*_whichAPVrun)->Fill(shot->apvNumber());
368  if(_medianrun && *_medianrun) (*_medianrun)->Fill(shot->median());
369  if(_stripMultrun && *_stripMultrun) (*_stripMultrun)->Fill(shot->nStrips());
370  if(_subDetectorrun && *_subDetectorrun) (*_subDetectorrun)->Fill(shot->subDet());
371 
372  tkhisto2->fill(det,shot->nStrips());;
373  tkhisto->add(det,1);
374 
375 
376 
377  }
378  }
379 
380  _nShots->Fill(nshots);
381  if(_nShotsrun && *_nShotsrun) (*_nShotsrun)->Fill(nshots);
382 
383  _nShotsdbx->Fill(he->deltaBX(),nshots);
384  _nShotsdbxprev->Fill(he->deltaBX(),nshots);
385  if(isphaseok) {
386  _nShotsbxcycle->Fill(he->absoluteBXinCycle(thephase)%70,nshots);
387  _nShotsdbxincycle->Fill(he->deltaBXinCycle(thephase),nshots);
388  _nShotsbxcycleprev->Fill(he->absoluteBXinCycle(1,thephase)%70,nshots);
389  _nShotsdbxincycleprev->Fill(he->deltaBXinCycle(1,2,thephase),nshots);
390  }
391 
392  if (_useCabling){
393  for (uint16_t lFed(0); lFed<lNumFeds; lFed++){
394  _nShotsVsFED->Fill(lFed+sistrip::FED_ID_MIN,nshotsperFed[lFed]);
395  }
396  }
397 
398  if(_nShotsVsTimerun && *_nShotsVsTimerun) (*_nShotsVsTimerun)->Fill(iEvent.orbitNumber(),nshots);
399 
400 
401 }
402 
403 void
405 {
406 
407 
408  _rhm.beginRun(iRun);
409 
410  if(_nShotsrun && *_nShotsrun) {
411  (*_nShotsrun)->GetXaxis()->SetTitle("Shots"); (*_nShotsrun)->GetYaxis()->SetTitle("Events");
412  (*_nShotsrun)->StatOverflows(kTRUE);
413  }
414 
416  (*_nShotsVsTimerun)->GetXaxis()->SetTitle("Orbit"); (*_nShotsVsTimerun)->GetYaxis()->SetTitle("Number of Shots");
417  (*_nShotsVsTimerun)->SetCanExtend(TH1::kXaxis);
418  }
419 
420  if(_whichAPVrun && *_whichAPVrun) {
421  (*_whichAPVrun)->GetXaxis()->SetTitle("APV"); (*_whichAPVrun)->GetYaxis()->SetTitle("Shots");
422  }
423 
424  if(_stripMultrun && *_stripMultrun) {
425  (*_stripMultrun)->GetXaxis()->SetTitle("Number of Strips"); (*_stripMultrun)->GetYaxis()->SetTitle("Shots");
426  }
427 
428  if(_medianrun && *_medianrun) {
429  (*_medianrun)->GetXaxis()->SetTitle("Charge [ADC]"); (*_medianrun)->GetYaxis()->SetTitle("Shots");
430  }
431 
433  (*_subDetectorrun)->GetYaxis()->SetTitle("Shots");
434  }
435 
436  if (_useCabling) {
437  if(_fedrun && *_fedrun) {
438  (*_fedrun)->GetYaxis()->SetTitle("Shots");
439  }
440  }
441 
442 }
443 
444 void
446 {
447 }
448 
449 
450 // ------------ method called once each job just before starting event loop ------------
451 void
453 {
454 
455 }
456 
457 // ------------ method called once each job just after ending the event loop ------------
458 void
460 
461  edm::LogInfo("EndOfJob") << _nevents << " analyzed events";
462 
464  TrackerMap tkmap,tkmap2;
465 
466  tkmap.setPalette(1);
467  tkmap2.setPalette(1);
468  tkhisto->dumpInTkMap(&tkmap);
469  tkhisto2->dumpInTkMap(&tkmap2);
470  std::string tkshotmultmapname = "ShotMultiplicity_" + _suffix + ".png";
471  tkmap.save(true,0,0,tkshotmultmapname);
472  std::string tkstripmultmapname = "StripMultiplicity_" + _suffix + ".png";
473  tkmap2.save(true,0,0,tkstripmultmapname);
474 
475  std::string rootmapname = "TKMap_"+_suffix+".root";
476  tkhisto->save(rootmapname);
477  tkhisto2->save(rootmapname);
478 }
479 
480 
482 {
483  if (_useCabling){
484  uint32_t cache_id = setup.get<SiStripDetCablingRcd>().cacheIdentifier();//.get( cabling_ );
485 
486  if ( _cacheIdDet != cache_id ) { // If the cache ID has changed since the last update...
487  // Update the cabling object
489  setup.get<SiStripDetCablingRcd>().get( c );
490  _detCabling = c.product();
491  _cacheIdDet = cache_id;
492  } // end of new cache ID check
493  }
494 }
495 
496 
497 
498 
499 //define this as a plug-in
#define LogDebug(id)
void beginJob() override
std::unique_ptr< TkHistoMap > tkhisto
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:519
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
TProfile ** _nShotsVsTimerun
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
#define nullptr
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
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 &)
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 setPalette(int numpalette)
Definition: TrackerMap.h:129
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:699
TProfile ** makeTProfile(const char *name, const char *title, const unsigned int nbinx, const double xmin, const double xmax)
void beginRun(const edm::Run &, const edm::EventSetup &) override
const SiStripDetCabling * _detCabling
The cabling object.
int orbitNumber() const
Definition: EventBase.h:67
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 endJob() override
bool failedToGet() const
Definition: HandleBase.h:78
const T & get() const
Definition: EventSetup.h:59
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
~APVShotsAnalyzer() override
void analyze(const edm::Event &, const edm::EventSetup &) override
std::unique_ptr< TkHistoMap > tkhisto2
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 updateDetCabling(const edm::EventSetup &setup)
Definition: Run.h:43