Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MvtxMon.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file MvtxMon.cc
1 // use #include "" only for your local include and put
2 // those in the first line(s) before any #include <>
3 // otherwise you are asking for weird behavior
4 // (more info - check the difference in include path search when using "" versus <>)
5 
6 #include "MvtxMon.h"
7 
8 //#include <fun4allraw/SingleMvtxInput.h>
9 //#include <ffarawobjects/MvtxRawHitContainerv1.h>
10 //#include <ffarawobjects/MvtxRawHitv1.h>
11 //#include <ffarawobjects/MvtxRawEvtHeaderv1.h>
12 
13 #include <onlmon/OnlMon.h> // for OnlMon
14 #include <onlmon/OnlMonDB.h>
15 #include <onlmon/OnlMonServer.h>
16 
17 #include <Event/msg_profile.h>
18 
19 #include <TH1.h>
20 #include <TString.h>
21 #include <TList.h>
22 #include <TLatex.h>
23 #include <TH2.h>
24 #include <TH2Poly.h>
25 #include <TLine.h>
26 #include <TH3.h>
27 
28 #include <Event/Event.h>
29 #include <Event/packet.h>
30 
31 #include <cmath>
32 #include <cstdio> // for printf
33 #include <fstream>
34 #include <iostream>
35 #include <sstream>
36 #include <string> // for allocator, string, char_traits
37 #include <utility>
38 
39 
40 
41 enum
42 {
45 };
46 
48  : OnlMon(name)
49 {
50  // leave ctor fairly empty, its hard to debug if code crashes already
51  // during a new MvtxMon()
52  return;
53 }
54 
56 {
57  // you can delete NULL pointers it results in a NOOP (No Operation)
58  return;
59 }
60 
62 {
63  // read our calibrations from MvtxMonData.dat
64  const char *mvtxcalib = getenv("MVTXCALIB");
65  if (!mvtxcalib)
66  {
67  std::cout << "MVTXCALIB environment variable not set" << std::endl;
68  exit(1);
69  }
70  std::string fullfile = std::string(mvtxcalib) + "/" + "MvtxMonData.dat";
71  std::ifstream calib(fullfile);
72  calib.close();
73  // use printf for stuff which should go the screen but not into the message
74  // system (all couts are redirected)
75  printf("doing the Init\n");
77 
78  // register histograms with server otherwise client won't get them
79  mvtxmon_ChipStaveOcc = new TH2D("MVTXMON_RawData_ChipStaveOcc","Average Occupancy: Stave Number and Chip Number",NCHIP,-0.5,NCHIP-0.5,NSTAVE,-0.5,NSTAVE-0.5);
80  mvtxmon_ChipStave1D = new TH1D("MVTXMON_RawData_ChipStave1D","Average Occupancy per Chip Stave",NCHIP*NSTAVE,-0.5,NCHIP * NSTAVE-0.5);
81  mvtxmon_ChipFiredHis= new TH1D("MVTXMON_RawData_ChipFiredHis","Number of Chips Fired per Felix per RCDAQ event Distribution",NCHIP*NSTAVE/6,-0.5,NCHIP*NSTAVE/6 - 0.5);
82  mvtxmon_EvtHitChip= new TH1D("MVTXMON_RawData_EvtHitChip","Number of Hits Per Strobe Per Chip Distribution",101,-0.5,100.5);
83  mvtxmon_EvtHitDis = new TH1D("MVTXMON_RawData_EvtHitDis","Number of Hits Per Strobe Distribution",7201,-0.5,7200.5);
84 
85  mvtxmon_ChipStaveOcc->SetStats(0);
86  mvtxmon_ChipStave1D->SetStats(0);
87  mvtxmon_ChipFiredHis->SetStats(0);
88  mvtxmon_EvtHitChip->SetStats(0);
89  mvtxmon_EvtHitDis->SetStats(0);
90 
91  mvtxmon_ChipStave1D->GetXaxis()->SetTitle("Chip*Stave");
92  mvtxmon_ChipStave1D->GetYaxis()->SetTitle("Occupancy");
93 
94  mvtxmon_ChipFiredHis->GetXaxis()->SetTitle("Number of Chips");
95  mvtxmon_ChipFiredHis->GetYaxis()->SetTitle("Counts");
96 
97  mvtxmon_EvtHitChip->GetXaxis()->SetTitle("Number of Hits");
98  mvtxmon_EvtHitChip->GetYaxis()->SetTitle("Counts");
99 
100  mvtxmon_EvtHitDis->GetXaxis()->SetTitle("Number of Hits");
101  mvtxmon_EvtHitDis->GetYaxis()->SetTitle("Counts");
102 
107  se->registerHisto(this, mvtxmon_EvtHitDis);
108 
109 
110  mRCDAQevt = new TH1I("RCDAQ_evt", "Number of RCDAQ events processed", 6,-0.5,5.5);
111  mRCDAQevt->GetXaxis()->SetTitle("FELIX server");
112  mRCDAQevt->GetYaxis()->SetTitle("Counts");
113  mRCDAQevt->SetStats(0);
114  se->registerHisto(this, mRCDAQevt);
115 
116  for (int i = 0; i < NFlags; i++) {
117  mvtxmon_LaneStatusOverview[i] = new TH2Poly();
118  mvtxmon_LaneStatusOverview[i]->SetName(Form("MVTXMON_LaneStatus_laneStatusOverviewFlag%s", mLaneStatusFlag[i].c_str()));
119  TString title = Form("Fraction of lanes into %s", mLaneStatusFlag[i].c_str());
120  //title += ";mm (IB 3x);mm (IB 3x)";
121  title += ";mm;mm";
122  mvtxmon_LaneStatusOverview[i]->SetTitle(title);
124  se->registerHisto(this, mvtxmon_LaneStatusOverview[i]); // mLaneStatusOverview
125  }
126 
127  //fee
128  mTriggerVsFeeId = new TH2I("MVTXMON_FEE_TriggerVsFeeid", "Trigger count vs Trigger ID and Fee ID", NFees, 0, NFees, NTrigger, 0.5, NTrigger + 0.5);
129  mTriggerVsFeeId->GetXaxis()->SetTitle("FeeID");
130  mTriggerVsFeeId->GetYaxis()->SetTitle("Trigger ID");
131  mTriggerVsFeeId->SetStats(0);
132  for (int i = 0; i < NTrigger; i++) {
133  mTriggerVsFeeId->GetYaxis()->SetBinLabel(i + 1, mTriggerType[i]);
134  }
135  se->registerHisto(this, mTriggerVsFeeId);
136 
137  mTrigger = new TH1I("MVTXMON_FEE_TriggerFlag", "Trigger vs counts", NTrigger, 0.5, NTrigger + 0.5);
138  mTrigger->GetXaxis()->SetTitle("Trigger ID");
139  mTrigger->GetYaxis()->SetTitle("Counts");
140  mTrigger->SetStats(0);
141  for (int i = 0; i < NTrigger; i++) {
142  mTrigger->GetXaxis()->SetBinLabel(i + 1, mTriggerType[i]);
143  }
144  se->registerHisto(this, mTrigger);
145 
146  /* mLaneInfo = new TH2I("MVTXMON/FEE/LaneInfo", "Lane Information", NLanesMax, -.5, NLanesMax - 0.5, NFlags, -.5, NFlags - 0.5);
147  mLaneInfo->GetXaxis()->SetTitle("Lane");
148  mLaneInfo->GetYaxis()->SetTitle("Flag");
149  mLaneInfo->SetStats(0);
150  se->registerHisto(this, mLaneInfo);*/
151 
152  for (int i = 0; i < NFlags; i++) {
153  mLaneStatus[i] = new TH2I(Form("MVTXMON_LaneStatus_laneStatusFlag%s", mLaneStatusFlag[i].c_str()), Form("Lane Status Flag: %s", mLaneStatusFlag[i].c_str()), NFees, 0, NFees, NLanesMax, 0, NLanesMax);
154  mLaneStatus[i]->GetXaxis()->SetTitle("FEE ID");
155  mLaneStatus[i]->GetYaxis()->SetTitle("Lane");
156  mLaneStatus[i]->SetStats(0);
157  for (const int& lay : LayerBoundaryFEE) {
158  auto l = new TLine(lay, 0, lay, mLaneStatus[i]->GetNbinsY());
159  mLaneStatus[i]->GetListOfFunctions()->Add(l);
160  }
161  se->registerHisto(this, mLaneStatus[i]);
162 
163  mLaneStatusCumulative[i] = new TH2I(Form("MVTXMON_LaneStatus_laneStatusFlagCumulative%s", mLaneStatusFlag[i].c_str()), Form("Lane Status Flags since SOX: %s", mLaneStatusFlag[i].c_str()), NFees, 0, NFees, NLanesMax, 0, NLanesMax);
164  mLaneStatusCumulative[i]->GetXaxis()->SetTitle("FEE ID");
165  mLaneStatusCumulative[i]->GetYaxis()->SetTitle("Lane");
166  mLaneStatusCumulative[i]->SetStats(0);
167  for (const int& lay : LayerBoundaryFEE) {
168  auto l = new TLine(lay, 0, lay, mLaneStatusCumulative[i]->GetNbinsY());
169  mLaneStatusCumulative[i]->GetListOfFunctions()->Add(l);
170  }
171  se->registerHisto(this, mLaneStatusCumulative[i]);
172  }
173 
174 
175  for (int i = 0; i < NLAYERS; i++) {
176  mLaneStatusSummary[i] = new TH1I(Form("MVTXMON_LaneStatusSummary_LaneStatusSummaryL%i", i), Form("Lane Status Summary L%i", i), 3, 0, 3);
177  mLaneStatusSummary[i]->GetYaxis()->SetTitle("#Lanes");
178  for (int j = 0; j < NFlags; j++) {
179  mLaneStatusSummary[i]->GetXaxis()->SetBinLabel(j + 1, mLaneStatusFlag[j].c_str());
180  }
181  mLaneStatusSummary[i]->GetXaxis()->CenterLabels();
182  mLaneStatusSummary[i]->SetStats(0);
183  se->registerHisto(this, mLaneStatusSummary[i]);
184  }
185 
186  mLaneStatusSummaryIB = new TH1I("MVTXMON_LaneStatusSummary_LaneStatusSummary", "Lane Status Summary", 3, 0, 3);
187  mLaneStatusSummaryIB->GetYaxis()->SetTitle("#Lanes");
188  for (int j = 0; j < NFlags; j++) {
189  mLaneStatusSummaryIB->GetXaxis()->SetBinLabel(j + 1, mLaneStatusFlag[j].c_str());
190  }
191  mLaneStatusSummaryIB->GetXaxis()->CenterLabels();
192  mLaneStatusSummaryIB->SetStats(0);
194 
195  //raw task
196  hErrorPlots = new TH1D("MVTXMON_General_ErrorPlots", "Decoding Errors", NError, 0.5, NError + 0.5);
197  hErrorPlots->GetYaxis()->SetTitle("Counts");
198  hErrorPlots->GetXaxis()->SetTitle("Error ID");
199  hErrorPlots->SetMinimum(0); //remove
200  hErrorPlots->SetFillColor(kRed); //remove
201  hErrorPlots->SetStats(0);
202 
203  TPaveText* pt[NError]={nullptr};
204  for (int i = 0; i < NError; i++) {
205  pt[i] = new TPaveText(0.20, 0.80 - i * 0.05, 0.85, 0.85 - i * 0.05, "NDC");
206  pt[i]->SetTextSize(0.04);
207  pt[i]->SetTextAlign(12);
208  pt[i]->SetFillColor(0);
209  pt[i]->SetTextColor(2);
210  pt[i]->AddText(ErrorType[i].Data());
211  hErrorPlots->GetListOfFunctions()->Add(pt[i]);
212  }
213  se->registerHisto(this, hErrorPlots);
214 
215  hErrorFile = new TH2D("MVTXMON_General_ErrorFile", "Decoding Errors vs Packet ID", 6*8, 0, 6*8+1, NError, 0.5, NError + 0.5);
216  hErrorFile->GetYaxis()->SetTitle("Error ID");
217  hErrorFile->GetXaxis()->SetTitle("Packet ID");
218  hErrorFile->GetZaxis()->SetTitle("Counts");
219  hErrorFile->SetMinimum(0);
220  hErrorFile->SetStats(0);
221 
222  for (int i = 1; i < 6; i++) {
223  auto l = new TLine(i*8+0.5+((i-3)*0.15), 0.5, i*8+0.5+((i-3)*0.15), hErrorFile->GetNbinsY()+0.5);
224  hErrorFile->GetListOfFunctions()->Add(l);
225  }
226 
227  se->registerHisto(this, hErrorFile);
228 
229  for (int aLayer = 0; aLayer < 3; aLayer++) {
230  hOccupancyPlot[aLayer] = new TH1D(Form("MVTXMON_Occupancy_Layer%dOccupancy", aLayer), Form("MVTX Layer %d, Occupancy Distribution", aLayer), 301, -3, 0.05);
231  hOccupancyPlot[aLayer]->GetYaxis()->SetTitle("Counts");
232  hOccupancyPlot[aLayer]->GetXaxis()->SetTitle("log10(Pixel Occupancy)");
233  hOccupancyPlot[aLayer]->SetStats(0);
234  se->registerHisto(this, hOccupancyPlot[aLayer]);
235 
236  hChipStaveOccupancy[aLayer] = new TH2D(Form("MVTXMON_Occupancy_Layer%d_Layer%dChipStave", aLayer, aLayer), Form("MVTX Layer%d, Occupancy vs Chip and Stave", aLayer), 9, -.5, 9 - .5, NStaves[aLayer], -.5, NStaves[aLayer] - .5);
237  hChipStaveOccupancy[aLayer]->GetYaxis()->SetTitle("Stave Number");
238  hChipStaveOccupancy[aLayer]->GetXaxis()->SetTitle("Chip Number");
239  hChipStaveOccupancy[aLayer]->GetZaxis()->SetTitle("Number of Hits");
240  hChipStaveOccupancy[aLayer]->SetStats(0);
241  se->registerHisto(this, hChipStaveOccupancy[aLayer]);
242 
243  TString tmp = Form("MVTX Layer %d", aLayer);
244  tmp += ", Number of noisy pixels (>20\% stobes in event) per RCDAQ event";
245 
246  hChipStaveNoisy[aLayer] = new TH2D(Form("MVTXMON_Noisy_Layer%d_ChipStave", aLayer), tmp, 9, -.5, 9 - .5, NStaves[aLayer], -.5, NStaves[aLayer] - .5);
247  hChipStaveNoisy[aLayer]->GetYaxis()->SetTitle("Stave Number");
248  hChipStaveNoisy[aLayer]->GetXaxis()->SetTitle("Chip Number");
249  //hChipStaveNoisy[aLayer]->GetZaxis()->SetTitle("Number of Noisy Pixels");
250  hChipStaveNoisy[aLayer]->SetStats(0);
251  se->registerHisto(this, hChipStaveNoisy[aLayer]);
252  }
253 
254  hChipHitmap = new TH3I(Form("MVTXMON_chipHitmapFLX%d", this->MonitorServerId()), Form("MVTXMON_chipHitmapFLX%d", this->MonitorServerId()), 1024, -.5, 1023.5, 512, -.5, 511.5,8*9*6,-.5,8*9*6-0.5);
255  hChipHitmap_evt = new TH3I(Form("MVTXMON_chipHitmapFLX%d_evt", this->MonitorServerId()), Form("MVTXMON_chipHitmapFLX%d_evt", this->MonitorServerId()), 1024, -.5, 1023.5, 512, -.5, 511.5,8*9*6,-.5,8*9*6-0.5);
256  hChipHitmap->GetXaxis()->SetTitle("Col");
257  hChipHitmap->GetYaxis()->SetTitle("Row");
258  hChipHitmap->SetStats(0);
259  se->registerHisto(this, hChipHitmap);
260 
261  hChipStrobes = new TH1I("hChipStrobes", "Chip Strobes vs Chip*Stave", 8*9*6,-.5,8*9*6-0.5);
262  hChipStrobes->GetXaxis()->SetTitle("Chip*Stave");
263  hChipStrobes->GetYaxis()->SetTitle("Counts");
264  hChipStrobes->SetStats(0);
265  se->registerHisto(this, hChipStrobes);
266 
267  hChipL1 = new TH1I("hChipL1", "L1 triggers vs Chip*Stave", 8*9*6,-.5,8*9*6-0.5);
268  hChipL1->GetXaxis()->SetTitle("Chip*Stave");
269  hChipL1->GetYaxis()->SetTitle("Counts");
270  hChipL1->SetStats(0);
271  se->registerHisto(this, hChipL1);
272 
273  //fhr
274  mErrorVsFeeid = new TH2I("MVTXMON_General_ErrorVsFeeid", "Error count vs Error id and Fee id", 3 * StaveBoundary[3], 0, 3 * StaveBoundary[3], NErrorExtended, 0.5, NErrorExtended + 0.5);
275  mErrorVsFeeid->GetXaxis()->SetTitle("FEE ID");
276  mErrorVsFeeid->GetYaxis()->SetTitle("Error ID");
277  mErrorVsFeeid->SetStats(0);
278  se->registerHisto(this, mErrorVsFeeid);
279 
280  mGeneralOccupancy = new TH2Poly();
281  mGeneralOccupancy->SetTitle("General Occupancy;mm;mm");
282  mGeneralOccupancy->SetName("MVTXMON_General_Occupancy");
283  //mGeneralOccupancy->GetXaxis()->SetTitle("");
284  //mGeneralOccupancy->GetYaxis()->SetTitle("");
285  mGeneralOccupancy->SetStats(0);
286 
287  mGeneralNoisyPixel = new TH2Poly();
288  mGeneralNoisyPixel->SetTitle("Noisy Pixel Number;mm (IB 3x);mm (IB 3x)");
289  mGeneralNoisyPixel->SetName("MVTXMON_General_Noisy_Pixel");
290  mGeneralNoisyPixel->GetXaxis()->SetTitle("");
291  mGeneralNoisyPixel->GetYaxis()->SetTitle("");
292  mGeneralNoisyPixel->SetStats(0);
293 
296  se->registerHisto(this, mGeneralOccupancy);
298 
299  for (int mLayer = 0; mLayer < 3; mLayer++) {
300  mDeadChipPos[mLayer] = new TH2D(Form("MVTXMON_Occupancy_Layer%d_Layer%dDeadChipPos", mLayer, mLayer), Form("DeadChipPos on Layer %d", mLayer), 9, -0.5, 9 - 0.5, NStaves[mLayer], -0.5, NStaves[mLayer] - 0.5);
301  mDeadChipPos[mLayer] ->GetXaxis()->SetTitle("Chip Number");
302  mDeadChipPos[mLayer] ->GetYaxis()->SetTitle("Stave Number");
303  mDeadChipPos[mLayer]->SetStats(0);
304  mAliveChipPos[mLayer] = new TH2D(Form("MVTXMON_Occupancy_Layer%d_Layer%dAliveChipPos", mLayer, mLayer), Form("Fraction of RCDAQ events a chip received data on Layer %d", mLayer), 9, -0.5, 9 - 0.5, NStaves[mLayer], -0.5, NStaves[mLayer] - 0.5);
305  mAliveChipPos[mLayer]->GetXaxis()->SetTitle("Chip Number");
306  mAliveChipPos[mLayer]->GetYaxis()->SetTitle("Stave Number");
307  mAliveChipPos[mLayer]->SetStats(0);
308 
309  mDeadChipPos[mLayer]->SetStats(0);
310  mAliveChipPos[mLayer]->SetStats(0);
311 
312  for (int binx = 0; binx < mDeadChipPos[mLayer]->GetNbinsX(); binx++) {
313  for (int biny = 0; biny < mDeadChipPos[mLayer]->GetNbinsY(); biny++) {
314  mDeadChipPos[mLayer]->SetBinContent(binx+1,biny+1,1);
315  }
316  }
317 
318 
319  mOccupancyPlot[mLayer] = new TH1D(Form("MVTXMON_Occupancy_Layer%dOccupancy_LOG", mLayer), Form("MVTX Layer %d Noise pixels occupancy distribution", mLayer), 301, -3, 0.05);
320  mOccupancyPlot[mLayer]->GetXaxis()->SetTitle("log(Occupancy)");
321  mOccupancyPlot[mLayer]->GetYaxis()->SetTitle("");
322  mOccupancyPlot[mLayer]->SetStats(0);
323  se->registerHisto(this, mDeadChipPos[mLayer]);
324  se->registerHisto(this, mAliveChipPos[mLayer]);
325  se->registerHisto(this, mOccupancyPlot[mLayer]);
326  }
327 
328  mTotalDeadChipPos = new TH2D(Form("MVTXMON_Occupancy_TotalDeadChipPos"), Form("TotalDeadChipPos "), 9, -0.5, 9 - 0.5, NStaves[2], -0.5, NStaves[2] - 0.5);
329  mTotalDeadChipPos->GetXaxis()->SetTitle("Chip Number");
330  mTotalDeadChipPos->GetYaxis()->SetTitle("Stave Number");
331  se->registerHisto(this, mTotalDeadChipPos);
332 
333  mTotalAliveChipPos = new TH2D(Form("MVTXMON_Occupancy_TotalAliveChipPos"), Form("TotalAliveChipPos "), 9, -0.5, 9 - 0.5, NStaves[2], -0.5, NStaves[2] - 0.5);
334  mTotalAliveChipPos->GetXaxis()->SetTitle("Chip Number");
335  mTotalAliveChipPos->GetYaxis()->SetTitle("Stave Number");
336  se->registerHisto(this, mTotalAliveChipPos);
337 
338 
339  Reset();
340  return 0;
341 }
342 
343 int MvtxMon::BeginRun(const int /* runno */)
344 {
345  // if you need to read calibrations on a run by run basis
346  // this is the place to do it
347  return 0;
348 }
349 
351 {
352  evtcnt++;
353  mRCDAQevt->Fill(this->MonitorServerId());
354  //std::cout << "Processing Event " << evtcnt << std::endl;
356 
357  plist = new Packet *[2];
358  //SingleMvtxInput *reader = new SingleMvtxInput("onlmonreader");
359 
360  for(int l = 0; l < NLAYERS; l++){
361  for(int i = 0; i < NStaves[l]; i++){
362  for(int j = 0; j < NCHIP; j++){
363  mHitPerChip[l][i][j] = 0;
364  }
365  }
366  }
367  hChipHitmap_evt->Reset("ICESM");
368 
369  int nChipStrobes[8*9*6] = {0};
370 
371 
372  int npackets = evt->getPacketList(plist, 2);
373 
374  if (npackets > 2)
375  {
376  exit(1);
377  }
378 
379  for (int i = 0; i < npackets; i++)
380  {
381  // Ignoring packet not from MVTX detector
382  if ( (plist[i]->getIdentifier() < 2001) || (plist[i]->getIdentifier() > 2052) )
383  {
384  continue;
385  }
386  if (Verbosity() > 1)
387  {
388  plist[i]->identify();
389  }
390  int num_feeId = plist[i]->iValue(-1, "NR_LINKS");
391  if (Verbosity() > 1)
392  {
393  std::cout << "Number of feeid in RCDAQ events: " << num_feeId << " for packet "
394  << plist[i]->getIdentifier() << std::endl;
395  }
396  if (num_feeId > 0)
397  {
398  for (int i_fee{0}; i_fee < num_feeId; ++i_fee)
399  {
400  auto feeId = plist[i]->iValue(i_fee, "FEEID");
401  auto link = DecodeFeeid(feeId);
402  auto num_strobes = plist[i]->iValue(feeId, "NR_STROBES");
403  ntriggers = num_strobes;
404  auto num_L1Trgs = plist[i]->iValue(feeId, "NR_PHYS_TRG");
405  for ( int iL1 = 0; iL1 < num_L1Trgs; ++iL1 )
406  {
407  //auto l1Trg_bco = plist[i]->lValue(feeId, iL1, "L1_IR_BCO");
408  hChipL1->Fill((StaveBoundary[link.layer]+link.stave)*9 + 3 * link.gbtid + 0); //same for chip id 0 1 and 2
409  hChipL1->Fill((StaveBoundary[link.layer]+link.stave)*9 + 3 * link.gbtid + 1);
410  hChipL1->Fill((StaveBoundary[link.layer]+link.stave)*9 + 3 * link.gbtid + 2);
411  }
412 
413  //m_FeeStrobeMap[feeId] += num_strobes;
414  for (int i_strb{0}; i_strb < num_strobes; ++i_strb)
415  {
416  auto strb_bco = plist[i]->lValue(feeId, i_strb, "TRG_IR_BCO");
417  //auto strb_bc = plist[i]->iValue(feeId, i_strb, "TRG_IR_BC");
418  auto num_hits = plist[i]->iValue(feeId, i_strb, "TRG_NR_HITS");
419  if (Verbosity() > 4)
420  {
421  if(link.layer == 0){
422  std::cout << "evtno: " << ", Fee: " << feeId;
423  std::cout << " Layer: " << link.layer << " Stave: " << link.stave;
424  std::cout << " GBT: " << link.gbtid << ", bco: 0x" << std::hex << strb_bco << std::dec;
425  std::cout << ", n_hits: " << num_hits << std::endl;
426  }
427  }
428  hChipStrobes->Fill((StaveBoundary[link.layer]+link.stave%20)*9 + 3 * link.gbtid + 0); //same for chip id 0 1 and 2
429  hChipStrobes->Fill((StaveBoundary[link.layer]+link.stave%20)*9 + 3 * link.gbtid + 1);
430  hChipStrobes->Fill((StaveBoundary[link.layer]+link.stave%20)*9 + 3 * link.gbtid + 2);
431  nChipStrobes[(StaveBoundary[link.layer]+link.stave%20)*9 + 3 * link.gbtid + 0]++;
432  nChipStrobes[(StaveBoundary[link.layer]+link.stave%20)*9 + 3 * link.gbtid + 1]++;
433  nChipStrobes[(StaveBoundary[link.layer]+link.stave%20)*9 + 3 * link.gbtid + 2]++;
434 
435 
436 
437 
438  for (int i_hit{0}; i_hit < num_hits; ++i_hit)
439  {
440  //auto chip_bc = plist[i]->iValue(feeId, i_strb, i_hit, "HIT_BC");
441  auto chip_id = plist[i]->iValue(feeId, i_strb, i_hit, "HIT_CHIP_ID");
442  auto chip_row = plist[i]->iValue(feeId, i_strb, i_hit, "HIT_ROW");
443  auto chip_col = plist[i]->iValue(feeId, i_strb, i_hit, "HIT_COL");
444 
445  mHitPerChip[link.layer][link.stave%20][3 * link.gbtid + chip_id]++;
446  hChipHitmap->Fill(chip_col,chip_row,(StaveBoundary[link.layer]+link.stave%20)*9 + 3 * link.gbtid + chip_id);
447  hChipStaveOccupancy[link.layer]->Fill(3 * link.gbtid + chip_id, link.stave%20);
448  hChipHitmap_evt->Fill(chip_col,chip_row,(StaveBoundary[link.layer]+link.stave%20)*9 + 3 * link.gbtid + chip_id);
449 
450  }
451 
452 
453 
454 
455  //m_BeamClockFEE[strb_bco].insert(feeId);
456  //m_BclkStack.insert(strb_bco);
457  // m_FEEBclkMap[feeId] = strb_bco;
458  }
459  }
460  }
461  delete plist[i];
462  }
463 
464  int firedChips = 0;
465  int firedPixels = 0;
466  int sumstrobes = 0;
467  int nstrobes = 0;
468  for(int l = 0; l < NLAYERS; l++){
469  for(int s = 0; s < NStaves[l]; s++){
470  for(int j = 0; j < NCHIP; j++){
471  if(mHitPerChip[l][s][j] > 0){
472  firedChips++;
473  mvtxmon_EvtHitChip->Fill(mHitPerChip[l][s][j]/nChipStrobes[(StaveBoundary[l]+s)*9+j]);
474  firedPixels+=mHitPerChip[l][s][j];
475  sumstrobes+=nChipStrobes[(StaveBoundary[l]+s)*9+j];
476  nstrobes++;
477  }
478  }
479  }
480  }
481  mvtxmon_ChipFiredHis->Fill(firedChips);
482  mvtxmon_EvtHitDis->Fill((double)firedPixels/((double)sumstrobes/(double)nstrobes));
483 
484  double pixelOccupancy, chipOccupancy;
485  for (int iLayer = 0; iLayer < 3; iLayer++) {
486  for (int iStave = 0; iStave < NStaves[iLayer]; iStave++) {
487  for (int iChip = 0; iChip < 9; iChip++) {
488  chipOccupancy = hChipHitmap->Integral(0,-1,0,-1,(StaveBoundary[iLayer]+iStave)*9+iChip+1,(StaveBoundary[iLayer]+iStave)*9+iChip+1); //scale at client
489  double chipOccupancyNorm = chipOccupancy/hChipStrobes->GetBinContent((StaveBoundary[iLayer]+iStave)*9+iChip+1)/1024/512;
490  //if (chipOccupancyNorm > 0) mvtxmon_ChipStave1D->SetBinContent((iLayer==0?iStave:NStaves[iLayer]+iStave)*9+iChip+1,chipOccupancyNorm); //need to remember total number of occ and events and scale here
491  if (chipOccupancyNorm > 0)mvtxmon_ChipStave1D->SetBinContent((StaveBoundary[iLayer]+iStave)*9 + iChip +1,chipOccupancyNorm);
492  if (chipOccupancyNorm > 0)mGeneralOccupancy->SetBinContent(mapstave[iLayer][iStave], chipOccupancyNorm);
493  int nTrg = nChipStrobes[(StaveBoundary[iLayer]+iStave)*9+iChip];
494  for (int iCol = 0; iCol < NCols; iCol++) {
495  for (int iRow = 0; iRow < NRows; iRow++) {
496  pixelOccupancy = hChipHitmap_evt->GetBinContent(iCol + 1, iRow + 1,(StaveBoundary[iLayer]+iStave)*9+iChip+1);
497  if (pixelOccupancy > 0) {
498  if (pixelOccupancy/(double)nTrg > mOccupancyCutForNoisyPixel) {
499  mNoisyPixelNumber[iLayer][iStave][iChip]++;
500  mOccupancyPlot[iLayer]->Fill(log10(pixelOccupancy/(double)nTrg));
501  }
502  hOccupancyPlot[iLayer]->Fill(log10(pixelOccupancy/(double)nTrg));
503  }
504  }
505  }
506  }
507  }
508  }
509 
510  for (int iLayer = 0; iLayer < 3; iLayer++) {
511  for (int iStave = 0; iStave < NStaves[iLayer]; iStave++) {
512  for (int iChip = 0; iChip < 9; iChip++) {
513  double noisy = *(std::max_element(mNoisyPixelNumber[iLayer][iStave], mNoisyPixelNumber[iLayer][iStave] + 9));
514  mGeneralNoisyPixel->SetBinContent(mapstave[iLayer][iStave], noisy);
515  if(mNoisyPixelNumber[iLayer][iStave][iChip]>0) hChipStaveNoisy[iLayer]->SetBinContent(iChip+1,iStave+1,mNoisyPixelNumber[iLayer][iStave][iChip]);
516  }
517  }
518  }
519 
520 for (int iLayer = 0; iLayer < 3; iLayer++) {
521  for (int iStave = 0; iStave < NStaves[iLayer]; iStave++) {
522  for (int iChip = 0; iChip < 9; iChip++) {
523  if (!mHitPerChip[iLayer][iStave][iChip]) {
524  if(mDeadChipPos[iLayer]->GetBinContent(mDeadChipPos[iLayer]->GetXaxis()->FindBin(iChip), mDeadChipPos[iLayer]->GetYaxis()->FindBin(iStave)) > 0.5) mDeadChipPos[iLayer]->SetBinContent(mDeadChipPos[iLayer]->GetXaxis()->FindBin(iChip), mDeadChipPos[iLayer]->GetYaxis()->FindBin(iStave), 1);
525  if(mTotalDeadChipPos->GetBinContent(mTotalDeadChipPos->GetXaxis()->FindBin(iChip), mTotalDeadChipPos->GetYaxis()->FindBin(iStave)) > 0.5) mTotalDeadChipPos->SetBinContent(mTotalDeadChipPos->GetXaxis()->FindBin(iChip), mTotalDeadChipPos->GetYaxis()->FindBin(iStave), 1);
526  } else {
527  mAliveChipPos[iLayer]->Fill(iChip, iStave);
528  mTotalAliveChipPos->Fill(iChip, iStave);
529  mDeadChipPos[iLayer]->SetBinContent(mDeadChipPos[iLayer]->GetXaxis()->FindBin(iChip), mDeadChipPos[iLayer]->GetYaxis()->FindBin(iStave), 0); // not dead
530  mTotalDeadChipPos->SetBinContent(mTotalDeadChipPos->GetXaxis()->FindBin(iChip), mTotalDeadChipPos->GetYaxis()->FindBin(iStave), 0); // not dead
531  }
532  }
533  }
534  }
535 
536 
537  int packet_init = 2001;
538  //std::cout<<"processing rcdaq event"<<std::endl;
539  for ( int iPkt = 0; iPkt < 8; iPkt++ ){
540  Packet *p = evt->getPacket(packet_init + iPkt);
541  if (p){
542  //std::cout<<"PACKET: "<<iPkt<<std::endl;
543  // std::map<mvtx::InteractionRecord, std::vector<mvtx::ChipPixelData>> *data = reinterpret_cast<std::map<mvtx::InteractionRecord, std::vector<mvtx::ChipPixelData>>*>(p->pValue(-1, "ChipData"));
544  // int nevents_packet = 0;
545  if(false){
546  //std::vector<mvtx::GBTLinkDecodingStat> *linkErrors = reinterpret_cast<std::vector<mvtx::GBTLinkDecodingStat>*>(p->pValue(-1, "linkErrors"));
547 /*
548  if(linkErrors){
549  for (auto error : *linkErrors){
550  for (int ierror = 0; ierror < mvtx::GBTLinkDecodingStat::NErrorsDefined; ierror++) {
551  if (error.errorCounts[ierror] <= 0) {
552  continue;
553  }
554  //mErrorCount[istave][ilink][ierror] = GBTLinkInfo->statistics.errorCounts[ierror];
555  std::cout<<error.feeID<<" "<<ierror<<" "<<error.errorCounts[ierror]<<std::endl;
556  }
557 
558  // for (int i = 0; i < NError; i++) {
559  // hErrorPlots->SetBinContent(i + 1, mErrors[i]);
560  //hErrorFile->SetBinContent((FileID + 1 + (EPID - 4) * 12), i + 1, mErrorPerFile[i]);
561  // }
562  }
563  }
564 */
565  delete p;
566 }
567  }// if(p)
568 }// for packet loop
569 
570 
571  // get temporary pointers to histograms
572  // one can do in principle directly se->getHisto("mvtxhist1")->Fill()
573  // but the search in the histogram Map is somewhat expensive and slows
574  // things down if you make more than one operation on a histogram
575 
576 
577  std::ostringstream msg;
578  msg << "Filling Histos";
580  idummy = 0;
581  return 0;
582 }
583 
585 {
586  // reset our internal counters
587  evtcnt = 0;
588  idummy = 0;
589  return 0;
590 }
591 
592 
593 void MvtxMon::getStavePoint(int layer, int stave, double* px, double* py)
594 {
595  float stepAngle = M_PI * 2 / NStaves[layer]; // the angle between to stave
596  float midAngle = StartAngle[layer] + (stave * stepAngle); // mid point angle
597  float staveRotateAngle = M_PI / 2 - (stave * stepAngle); // how many angle this stave rotate(compare with first stave)
598  px[1] = MidPointRad[layer] * std::cos(midAngle); // there are 4 point to decide this TH2Poly bin
599  // 0:left point in this stave;
600  // 1:mid point in this stave;
601  // 2:right point in this stave;
602  // 3:higher point int this stave;
603  py[1] = MidPointRad[layer] * std::sin(midAngle); // 4 point calculated accord the blueprint
604  // roughly calculate
605  px[0] = 7.7 * std::cos(staveRotateAngle) + px[1];
606  py[0] = -7.7 * std::sin(staveRotateAngle) + py[1];
607  px[2] = -7.7 * std::cos(staveRotateAngle) + px[1];
608  py[2] = 7.7 * std::sin(staveRotateAngle) + py[1];
609  px[3] = 5.623 * std::sin(staveRotateAngle) + px[1];
610  py[3] = 5.623 * std::cos(staveRotateAngle) + py[1];
611 }
612 
613 void MvtxMon::createPoly(TH2Poly *h){
614  for (int ilayer = 0; ilayer < NLAYERS; ilayer++) {
615  for (int istave = 0; istave < NStaves[ilayer]; istave++) {
616  double* px = new double[4];
617  double* py = new double[4];
618  getStavePoint(ilayer, istave, px, py);
619  for (int icoo = 0; icoo < 4; icoo++) {
620  px[icoo] *= 3.;
621  py[icoo] *= 3.;
622  }
623  h->AddBin(4, px, py);
624  }
625  }
626 }
627 
628