StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
BEMCPlots.cxx
1 #include <iostream>
2 #include <fstream>
3 using namespace std;
4 #include <TH1F.h>
5 #include <TH2F.h>
6 #include <TFile.h>
7 #include <TCanvas.h>
8 #include <TLine.h>
9 #include <TArrow.h>
10 #include <TLatex.h>
11 #include <TString.h>
12 #include <TBox.h>
13 #include <TObjArray.h>
14 #include <TDatime.h>
15 
16 #ifndef NEW_DAQ_READER
17 # include "evpReader.hh"
18 # include "emcReader.h"
19 # include "trgReader.h"
20 #define BSMD_FIBERS 12
21 #define BSMD_DATSIZE 4800
22 #else
23 # include "DAQ_READER/daqReader.h"
24 # include "DAQ_READER/daq_dta.h"
25 # include "DAQ_BSMD/daq_bsmd.h"
26 # include "DAQ_BTOW/daq_btow.h"
27 # include "DAQ_EMC/daq_emc.h"
28 # include "DAQ_TRG/daq_trg.h"
29 # include <RTS/include/daqFormats.h>
30 #endif
31 
32 #include <StEmcUtil/database/StEmcDecoder.h>
33 #include <StEmcUtil/geometry/StEmcGeom.h>
34 
35 #include "BEMCPlots.h"
36 #include "BEMC_DSM_decoder.h"
37 #include "BEMCPlotsNames.h"
38 
39 
40 BEMCPlots *BEMCPlotsInstance = 0;
41 StEmcDecoder *BEMCDecoder = 0;
42 
43 
44 #define BEMCOK 1
45 #define BEMCNOTINSTALLED 2
46 #define BEMCCORRUPTED 3
47 
48 
49 //--------------------------------------
50 
51 
52 
53 //-------------------------------------------------------------------
54 void BEMCPlots::initHisto(TObjArray *list, const char *bemcStatus) {
55  if (BEMCPlotsInstance) delete BEMCPlotsInstance; BEMCPlotsInstance = 0;
56  BEMCPlotsInstance = new BEMCPlots(list);
57  if (BEMCPlotsInstance) {
58  BEMCPlotsInstance->setDebug(0);
59  BEMCPlotsInstance->clear(bemcStatus);
60  }
61 
62 }
63 
64 //-------------------------------------------------------------------
65 void BEMCPlots::resetHisto(const char *bemcStatus) {
66  if (BEMCPlotsInstance) {
67  BEMCPlotsInstance->clear(bemcStatus);
68  }
69 }
70 //-------------------------------------------------------------------
71 void BEMCPlots::saveHisto(TFile *hfile) {
72  if (BEMCPlotsInstance) {
73  BEMCPlotsInstance->saveHistograms(hfile);
74  }
75 }
76 //-------------------------------------------------------------------
77 void BEMCPlots::fillHisto( char *datap
78  , const unsigned char *dsmL0WestInput
79  , const unsigned char *dsmL0EastInput
80  , const unsigned short *dsmL1Input
81  , const unsigned short *dsmL2Input
82  , const unsigned short *dsmL3Input
83  ) {
84 
85  if (BEMCPlotsInstance) {
86  BEMCPlotsInstance->processEvent(datap, dsmL0WestInput, dsmL0EastInput, dsmL1Input, dsmL2Input, dsmL3Input);
87  }
88 }
89 //-------------------------------------------------------------------
90 BEMCPlots::BEMCPlots(TObjArray *list)
91  : mDebug(0)
92 {
93 
94 #define ADDHIST(hist) if (list && (hist)) list->Add(hist);
95 
96  this->mHistTot = new TH1F(HistTotName, "BEMC, Total number of events processed;;Number of events", 1, 0, 1);
97  ADDHIST(this->mHistTot)
98 
99  this->mHistDsmL0InputHighTower = new TH2F(HistDsmL0InputHighTowerName, "BEMC DSM L0 Input - HighTower;triggerPatch;HighTower", 300, -0.5, 300 - 0.5, 64, 0, 64);
100  ADDHIST(this->mHistDsmL0InputHighTower)
101  this->mHistDsmL0InputPatchSum = new TH2F(HistDsmL0InputPatchSumName, "BEMC DSM L0 Input - PatchSum;triggerPatch;PatchSum", 300, -0.5, 300 - 0.5, 64, 0, 64);
102  ADDHIST(this->mHistDsmL0InputPatchSum)
103 
104  this->mHistDsmL1InputHighTowerBits = new TH2F(HistDsmL1InputHighTowerBitsName, "BEMC DSM L1 Input - HighTower bits;DSM Level-1 channels;HighTower bits", 36, -0.5, 36-0.5, 5, 0, 5);
105  ADDHIST(this->mHistDsmL1InputHighTowerBits)
106  this->mHistDsmL1InputPatchSum = new TH2F(HistDsmL1InputPatchSumName, "BEMC DSM L1 Input - PatchSum;Channel;PatchSum", 36, -0.5, 36-0.5, 128, 0, 256/*1024*/);
107  ADDHIST(this->mHistDsmL1InputPatchSum)
108 
109  this->mHistDsmL2InputHighTowerBits = new TH2F(HistDsmL2InputHighTowerBitsName, "BEMC DSM L2 Input - HighTower bits;JetPatch;HighTower bits", BEMCNJET, -0.5, BEMCNJET-0.5, 5, 0, 5);
110  ADDHIST(this->mHistDsmL2InputHighTowerBits)
111  this->mHistDsmL2InputPatchSumBits = new TH2F(HistDsmL2InputPatchSumBitsName, "BEMC DSM L2 Input - PatchSum bits;JetPatch;PatchSum bits", BEMCNJET, -0.5, BEMCNJET-0.5, 4, 0, 4);
112  ADDHIST(this->mHistDsmL2InputPatchSumBits)
113  this->mHistDsmL2InputPatchSum = new TH2F(HistDsmL2InputPatchSumName, "BEMC DSM L2 Input - PatchSum;JetPatch pair;PatchSum", 6, -0.5, 6-0.5, 256, 0, 256);
114  ADDHIST(this->mHistDsmL2InputPatchSum)
115 
116  this->mHistDsmL3InputHighTowerBits = new TH1F(HistDsmL3InputHighTowerBitsName, "BEMC DSM L3 Input - HighTower bits;HighTower bits", 4, -0.5, 4-0.5);
117  ADDHIST(this->mHistDsmL3InputHighTowerBits)
118  this->mHistDsmL3InputPatchSumBits = new TH1F(HistDsmL3InputPatchSumBitsName, "BEMC DSM L3 Input - PatchSum bits;PatchSum bits", 4, -0.5, 4-0.5);
119  ADDHIST(this->mHistDsmL3InputPatchSumBits)
120  this->mHistDsmL3InputBackToBackBit = new TH1F(HistDsmL3InputBackToBackBitName, "BEMC DSM L3 Input - Back-to-Back bit;Back-to-Back bit", 2, -0.5, 2-0.5);
121  ADDHIST(this->mHistDsmL3InputBackToBackBit)
122  this->mHistDsmL3InputJPsiTopoBit = new TH1F(HistDsmL3InputJPsiTopoBitName, "BEMC DSM L3 Input - J/Psi topology bit;J/Psi bit", 2, -0.5, 2-0.5);
123  ADDHIST(this->mHistDsmL3InputJPsiTopoBit)
124  this->mHistDsmL3InputJetPatchTopoBit = new TH1F(HistDsmL3InputJetPatchTopoBitName, "BEMC DSM L3 Input - JetPatch topology bit;JetPatch bit", 2, -0.5, 2-0.5);
125  ADDHIST(this->mHistDsmL3InputJetPatchTopoBit)
126 
127  this->mHistRawAdc1 = new TH2F(HistRawAdc1Name, "BTOW ADC, 1 <= SoftId <= 1220;SoftId;ADC", 1220, 0000.5, 1220.5, 300, -0.5, 4096-0.5);
128  this->mHistRawAdc2 = new TH2F(HistRawAdc2Name, "BTOW ADC, 1221 <= SoftId <= 2400;SoftId;ADC", 1180, 1220.5, 2400.5, 300, -0.5, 4096-0.5);
129  this->mHistRawAdc3 = new TH2F(HistRawAdc3Name, "BTOW ADC, 2401 <= SoftId <= 3540;SoftId;ADC", 1140, 2400.5, 3540.5, 300, -0.5, 4096-0.5);
130  this->mHistRawAdc4 = new TH2F(HistRawAdc4Name, "BTOW ADC, 3541 <= SoftId <= 4800;SoftId;ADC", 1260, 3540.5, 4800.5, 300, -0.5, 4096-0.5);
131 
132  this->mHistRawAdc1zoom = new TH2F(HistRawAdc1NameZoom, "BTOW ADC, 1 <= SoftId <= 1220;SoftId;ADC", 1220, 0000.5, 1220.5, 300, -0.5, 500-0.5);
133  this->mHistRawAdc2zoom = new TH2F(HistRawAdc2NameZoom, "BTOW ADC, 1221 <= SoftId <= 2400;SoftId;ADC", 1180, 1220.5, 2400.5, 300, -0.5, 500-0.5);
134  this->mHistRawAdc3zoom = new TH2F(HistRawAdc3NameZoom, "BTOW ADC, 2401 <= SoftId <= 3540;SoftId;ADC", 1140, 2400.5, 3540.5, 300, -0.5, 500-0.5);
135  this->mHistRawAdc4zoom = new TH2F(HistRawAdc4NameZoom, "BTOW ADC, 3541 <= SoftId <= 4800;SoftId;ADC", 1260, 3540.5, 4800.5, 300, -0.5, 500-0.5);
136 
137  this->mHistRawAdcPsd1 = new TH2F(HistRawAdcPsd1Name, "BPRS ADC, 1 <= SoftId <= 1220;SoftId;ADC", 1220, 0000.5, 1220.5, 300, -0.5, 1000-0.5);
138  this->mHistRawAdcPsd2 = new TH2F(HistRawAdcPsd2Name, "BPRS ADC, 1221 <= SoftId <= 2400;SoftId;ADC", 1180, 1220.5, 2400.5, 300, -0.5, 1000-0.5);
139  this->mHistRawAdcPsd3 = new TH2F(HistRawAdcPsd3Name, "BPRS ADC, 2401 <= SoftId <= 3540;SoftId;ADC", 1140, 2400.5, 3540.5, 300, -0.5, 1000-0.5);
140  this->mHistRawAdcPsd4 = new TH2F(HistRawAdcPsd4Name, "BPRS ADC, 3541 <= SoftId <= 4800;SoftId;ADC", 1260, 3540.5, 4800.5, 300, -0.5, 1000-0.5);
141 
142  this->mHistSmdFeeSum = new TH2F(HistSmdFeeSumName, "BSMD FEE Sum;Module;Sum", 120, 0.5, 120+0.5, 100, -0.5, 5000-0.5);
143  this->mHistPsdFeeSum = new TH2F(HistPsdFeeSumName, "BPRS FEE Sum;PMT Box;Sum", 60, 0.5, 60+0.5, 100, -0.5, 5000-0.5);
144 
145  this->mHistSmdFeeSumNonZS = new TH2F(HistSmdFeeSumNonZSName, "BSMD FEE Sum, Non-ZS;Module;Sum", 120, 0.5, 120+0.5, 100, -0.5, 100000-0.5);
146  this->mHistPsdFeeSumNonZS = new TH2F(HistPsdFeeSumNonZSName, "BPRS FEE Sum, Non-ZS;PMT Box;Sum", 60, 0.5, 60+0.5, 100, -0.5, 40000-0.5);
147 
148  ADDHIST(this->mHistRawAdc1)
149  ADDHIST(this->mHistRawAdc2)
150  ADDHIST(this->mHistRawAdc3)
151  ADDHIST(this->mHistRawAdc4)
152 
153  ADDHIST(this->mHistRawAdc1zoom)
154  ADDHIST(this->mHistRawAdc2zoom)
155  ADDHIST(this->mHistRawAdc3zoom)
156  ADDHIST(this->mHistRawAdc4zoom)
157 
158  ADDHIST(this->mHistRawAdcPsd1)
159  ADDHIST(this->mHistRawAdcPsd2)
160  ADDHIST(this->mHistRawAdcPsd3)
161  ADDHIST(this->mHistRawAdcPsd4)
162 
163  ADDHIST(this->mHistSmdFeeSum)
164  ADDHIST(this->mHistPsdFeeSum)
165 
166  ADDHIST(this->mHistSmdFeeSumNonZS)
167  ADDHIST(this->mHistPsdFeeSumNonZS)
168 
169  for (int i = 0;i < BEMCNJET;i++) {
170  TString name;
171  TString title;
172  name = Form("%s_%u", HistHighTowerSpectrumName, i);
173  title = Form("JetPatch %u - HighTower spectrum;HighTower", i);
174  this->mHistHighTowerSpectrum[i] = new TH1F(name.Data(), title.Data(), 64, -0.5, 64-0.5);
175  ADDHIST(this->mHistHighTowerSpectrum[i])
176  name = Form("%s_%u", HistPatchSumSpectrumName, i);
177  title = Form("JetPatch %u - PatchSum spectrum;PatchSum", i);
178  this->mHistPatchSumSpectrum[i] = new TH1F(name.Data(), title.Data(), 200, -0.5, 300-0.5);
179  ADDHIST(this->mHistPatchSumSpectrum[i])
180  }
181 
182  this->mHistTriggerCorruptionHighTower = new TH1F(HistTriggerCorruptionHighTowerName, "HighTower DSM L0 Input; triggerPatch;events", 300, -0.5, 300-0.5);
183  this->mHistTriggerCorruptionPatchSum = new TH1F(HistTriggerCorruptionPatchSumName, "PatchSum DSM L0 Input; triggerPatch;events", 300, -0.5, 300-0.5);
184  this->mHistDSM0HTCorr = new TH2F(HistDSM0HTCorrName, "HighTower DSM L0 Input; DSM HighTower;Simulated HighTower", 64, 0, 64, 64, 0, 64);
185  this->mHistDSM0TPCorr = new TH2F(HistDSM0TPCorrName, "PatchSum DSM L0 Input; DSM PatchSum;Simulated PatchSum", 64, 0, 64, 64, 0, 64);
186 
187  ADDHIST(this->mHistTriggerCorruptionHighTower)
188  ADDHIST(this->mHistTriggerCorruptionPatchSum)
189  ADDHIST(this->mHistDSM0HTCorr)
190  ADDHIST(this->mHistDSM0TPCorr)
191 
192  this->mHist_TDC_status = new TH2F(Hist_TDC_statusName, "BEMC TDC Status;0=total 1=OK 2=Not Installed3=Corrupted",5,-0.5,4.5,30,-0.5,29.5);
193  this->mHist_SMD_status = new TH2F(Hist_SMD_statusName, "BEMC SMD Status;0=total 1=OK 2=Not Installed3=Corrupted",5,-0.5,4.5,8,-0.5,7.5);
194  this->mHist_PSD_status = new TH2F(Hist_PSD_statusName, "BEMC PSD Status;0=total 1=OK 2=Not Installed 3=Corrupted",5,-0.5,4.5,4,-0.5,3.5);
195  this->mHist_BTOW_Corruption = new TH1F(Hist_BTOW_CorruptionName, "BEMC TDC corruption frequency;0=total 1=OK 2=Not Installed 3=Corrupted",5,-0.5,4.5);
196 
197  this->mHist_btow_spectra_1 = new TH2F(Hist_btow_spectra_1Name, "BEMC tower spectrum 0 < TDC < 10;X = 160*TDC + index", 1600, -0.5,1599.5,100,0,500);
198  this->mHist_btow_spectra_2 = new TH2F(Hist_btow_spectra_2Name, "BEMC tower spectrum 10 < TDC < 20;X = 160*TDC + index", 1600,1599.5,3199.5,100,0,500);
199  this->mHist_btow_spectra_3 = new TH2F(Hist_btow_spectra_3Name, "BEMC tower spectrum 20 < TDC < 30;X = 160*TDC + index", 1600,3199.5,4799.5,100,0,500);
200 
201  this->mHist_smd_spectra = new TH1F(Hist_smd_spectraName, "BEMC SMD total ADC",250,100000.,6000000.);
202  this->mHist_smd_spectraNonZS= new TH1F(Hist_smd_spectraNonZSName, "BEMC SMD total ADC, Non-ZS",250,100000.,6000000.);
203  this->mHist_smd_capacitor = new TH2F(Hist_smd_capacitorName, "BEMC SMD capacitor distribution",128,-0.5,127.5,8,-0.5,7.5);
204  this->mHist_smd_sum = new TH2F(Hist_smd_sumName, "BEMC SMD total ADC per fiber",250,100000.,1000000.,8,-0.5,7.5);
205  this->mHist_psd_spectra = new TH1F(Hist_psd_spectraName, "BEMC PSD total ADC",250,100000.,4000000.);
206  this->mHist_psd_spectraNonZS= new TH1F(Hist_psd_spectraNonZSName, "BEMC PSD total ADC, Non-ZS",250,100000.,4000000.);
207  this->mHist_psd_capacitor = new TH2F(Hist_psd_capacitorName, "BEMC PSD capacitor distribution",128,-0.5,127.5,4,-0.5,3.5);
208  this->mHist_psd_sum = new TH2F(Hist_psd_sumName, "BEMC PSD total ADC per fiber",250,100000.,1000000.,4,-0.5,3.5);
209 
210  this->mHist_HTMAX_spectra = new TH2F(Hist_HTMAX_spectraName, "BEMC Maximum High Tower spectrum", 300,-0.5,299.5,64,-0.5,63.5);
211  this->mHist_PAMAX_spectra = new TH2F(Hist_PAMAX_spectraName, "BEMC Maximum Patch Sum spectrum", 300,-0.5,299.5,64,-0.5,63.5);
212  this->mHist_HTMAX_dist = new TH1F(Hist_HTMAX_distName, "BEMC Maximum High Tower distribution", 300,-0.5,299.5);
213  this->mHist_PAMAX_dist = new TH1F(Hist_PAMAX_distName, "BEMC Maximum Patch Sum distribution", 300,-0.5,299.5);
214 
215  this->mHist_JET_spectra = new TH2F(Hist_JET_spectraName, "BEMC Jet sum spectrum", BEMCNJET,-0.5,BEMCNJET-0.5,80,-0.5,79.5);
216  this->mHist_JETMAX_spectra = new TH2F(Hist_JETMAX_spectraName, "BEMC Maximum Jet sum spectrum", BEMCNJET,-0.5,BEMCNJET-0.5,80,-0.5,79.5);
217  this->mHist_JET_ped = new TH2F(Hist_JET_pedName, "BEMC Jet sum pedestal", BEMCNJET,-0.5,BEMCNJET-0.5,30,15,45);
218  this->mHist_JETMAX_dist = new TH1F(Hist_JETMAX_distName, "BEMC Maximum Jet sum distribution", BEMCNJET,-0.5,BEMCNJET-0.5);
219 
220  ADDHIST(this->mHist_TDC_status)
221  ADDHIST(this->mHist_SMD_status)
222  ADDHIST(this->mHist_PSD_status)
223  ADDHIST(this->mHist_BTOW_Corruption)
224 
225  ADDHIST(this->mHist_btow_spectra_1)
226  ADDHIST(this->mHist_btow_spectra_2)
227  ADDHIST(this->mHist_btow_spectra_3)
228 
229  ADDHIST(this->mHist_smd_spectra)
230  ADDHIST(this->mHist_smd_spectraNonZS)
231  ADDHIST(this->mHist_smd_capacitor)
232  ADDHIST(this->mHist_smd_sum)
233  ADDHIST(this->mHist_psd_spectra)
234  ADDHIST(this->mHist_psd_spectraNonZS)
235  ADDHIST(this->mHist_psd_capacitor)
236  ADDHIST(this->mHist_psd_sum)
237 
238  ADDHIST(this->mHist_HTMAX_spectra)
239  ADDHIST(this->mHist_PAMAX_spectra)
240  ADDHIST(this->mHist_HTMAX_dist)
241  ADDHIST(this->mHist_PAMAX_dist)
242 
243  ADDHIST(this->mHist_JET_spectra)
244  ADDHIST(this->mHist_JETMAX_spectra)
245  ADDHIST(this->mHist_JET_ped)
246  ADDHIST(this->mHist_JETMAX_dist)
247 
248  this->mHist_ADCEtaPhi_TowHits = new TH2F(Hist_ADCEtaPhi_TowHitsName, "Tower hits>ped+20; Phi Bin; Eta Bin",120 ,-3.15 ,3.15, 40, -1, 1);
249  this->mHist_ADCEtaPhi_Pre1Hits = new TH2F(Hist_ADCEtaPhi_Pre1HitsName, "BPSD hits>ped+20;Phi Bin; Eta Bin",120, -3.15, 3.15, 40, -1, 1);
250 
251  ADDHIST(this->mHist_ADCEtaPhi_TowHits)
252  ADDHIST(this->mHist_ADCEtaPhi_Pre1Hits)
253 
254 
255 #undef ADDHIST
256 
257  for (int i = 0;i < 4800;i++) {
258  this->mTowerData[i][0] = 1; // unmask
259  this->mTowerData[i][1] = 0; // ped
260  this->mTowerData[i][2] = 0; // FEE ped
261  }
262  this->mTriggerPedestalShift = 24 * 100;
263  for (int i = 0;i < 300;i++) {
264  this->mPatchData[i][0] = 1; // unmask HT
265  this->mPatchData[i][1] = 1; // unmask PA
266  this->mPatchData[i][2] = 3; // bit conversion mode
267  this->mPatchData[i][3] = 2; // formula
268  this->mPatchData[i][4] = 1; // formula parameter 0
269  this->mPatchData[i][5] = 0; // formula parameter 1
270  this->mPatchData[i][6] = 0; // formula parameter 2
271  this->mPatchData[i][7] = 1; // formula parameter 3
272  this->mPatchData[i][8] = 0; // formula parameter 4
273  this->mPatchData[i][9] = 0; // formula parameter 5
274  this->mPatchData[i][10] = 0; // number of masked towers
275  }
276  memset(this->BEMCJPPED, 0, sizeof(this->BEMCJPPED));
277  memset(this->BEMCNJPPED, 0, sizeof(this->BEMCNJPPED));
278 
279 }
280 //-------------------------------------------------------------------
281 BEMCPlots::~BEMCPlots() {
282  if (mDebug >= 10) cout << __FILE__ << ":" << __LINE__ << endl;
283 
284 #define DELETEHIST(HIST) if (HIST) delete (HIST); (HIST) = 0;
285 
286  DELETEHIST(this->mHistTot)
287 
288  DELETEHIST(this->mHistDsmL0InputHighTower)
289  DELETEHIST(this->mHistDsmL0InputPatchSum)
290 
291  DELETEHIST(this->mHistDsmL1InputHighTowerBits)
292  DELETEHIST(this->mHistDsmL1InputPatchSum)
293 
294  DELETEHIST(this->mHistDsmL2InputHighTowerBits)
295  DELETEHIST(this->mHistDsmL2InputPatchSumBits)
296  DELETEHIST(this->mHistDsmL2InputPatchSum)
297 
298  DELETEHIST(this->mHistDsmL3InputHighTowerBits)
299  DELETEHIST(this->mHistDsmL3InputPatchSumBits)
300  DELETEHIST(this->mHistDsmL3InputBackToBackBit)
301  DELETEHIST(this->mHistDsmL3InputJPsiTopoBit)
302  DELETEHIST(this->mHistDsmL3InputJetPatchTopoBit)
303 
304  DELETEHIST(this->mHistRawAdc1)
305  DELETEHIST(this->mHistRawAdc2)
306  DELETEHIST(this->mHistRawAdc3)
307  DELETEHIST(this->mHistRawAdc4)
308 
309  DELETEHIST(this->mHistRawAdc1zoom)
310  DELETEHIST(this->mHistRawAdc2zoom)
311  DELETEHIST(this->mHistRawAdc3zoom)
312  DELETEHIST(this->mHistRawAdc4zoom)
313 
314  DELETEHIST(this->mHistRawAdcPsd1)
315  DELETEHIST(this->mHistRawAdcPsd2)
316  DELETEHIST(this->mHistRawAdcPsd3)
317  DELETEHIST(this->mHistRawAdcPsd4)
318 
319  DELETEHIST(this->mHistSmdFeeSum)
320  DELETEHIST(this->mHistPsdFeeSum)
321 
322  DELETEHIST(this->mHistSmdFeeSumNonZS)
323  DELETEHIST(this->mHistPsdFeeSumNonZS)
324 
325  for (int i = 0;i < BEMCNJET;i++) {
326  DELETEHIST(this->mHistHighTowerSpectrum[i])
327  DELETEHIST(this->mHistPatchSumSpectrum[i])
328  }
329 
330  DELETEHIST(this->mHistTriggerCorruptionHighTower)
331  DELETEHIST(this->mHistTriggerCorruptionPatchSum)
332  DELETEHIST(this->mHistDSM0HTCorr)
333  DELETEHIST(this->mHistDSM0TPCorr)
334 
335  DELETEHIST(this->mHist_TDC_status)
336  DELETEHIST(this->mHist_SMD_status)
337  DELETEHIST(this->mHist_PSD_status)
338  DELETEHIST(this->mHist_BTOW_Corruption)
339 
340  DELETEHIST(this->mHist_btow_spectra_1)
341  DELETEHIST(this->mHist_btow_spectra_2)
342  DELETEHIST(this->mHist_btow_spectra_3)
343 
344  DELETEHIST(this->mHist_smd_spectra)
345  DELETEHIST(this->mHist_smd_spectraNonZS)
346  DELETEHIST(this->mHist_smd_capacitor)
347  DELETEHIST(this->mHist_smd_sum)
348  DELETEHIST(this->mHist_psd_spectra)
349  DELETEHIST(this->mHist_psd_spectraNonZS)
350  DELETEHIST(this->mHist_psd_capacitor)
351  DELETEHIST(this->mHist_psd_sum)
352 
353  DELETEHIST(this->mHist_HTMAX_spectra)
354  DELETEHIST(this->mHist_PAMAX_spectra)
355  DELETEHIST(this->mHist_HTMAX_dist)
356  DELETEHIST(this->mHist_PAMAX_dist)
357 
358  DELETEHIST(this->mHist_JET_spectra)
359  DELETEHIST(this->mHist_JETMAX_spectra)
360  DELETEHIST(this->mHist_JET_ped)
361 
362  DELETEHIST(this->mHist_JETMAX_dist)
363 
364  DELETEHIST(this->mHist_ADCEtaPhi_TowHits)
365  DELETEHIST(this->mHist_ADCEtaPhi_Pre1Hits)
366 
367 
368 #undef DELETEHIST
369 
370  this->clear(0);
371  if (mDebug >= 10) cout << __FILE__ << ":" << __LINE__ << endl;
372 }
373 //-------------------------------------------------------------------
374 void BEMCPlots::init(unsigned int date, unsigned int time, const char *bemcStatus) {
375 
376  if (mDebug >= 10) cout << __FILE__ << ":" << __LINE__ << endl;
377  this->clear(bemcStatus);
378  if (mDebug >= 10) cout << __FILE__ << ":" << __LINE__ << endl;
379 
380 }
381 //-------------------------------------------------------------------
382 void BEMCPlots::clear(const char *bemcStatus) {
383  if (mDebug >= 10) cout << __FILE__ << ":" << __LINE__ << endl;
384  if (mDebug >= 2) cout << "bemcStatus = " << bemcStatus << endl;
385 
386 #define RESETHIST(HIST) if (HIST) (HIST)->Reset();
387 
388  RESETHIST(this->mHistTot)
389 
390  RESETHIST(this->mHistDsmL0InputHighTower)
391  RESETHIST(this->mHistDsmL0InputPatchSum)
392 
393  RESETHIST(this->mHistDsmL1InputHighTowerBits)
394  RESETHIST(this->mHistDsmL1InputPatchSum)
395 
396  RESETHIST(this->mHistDsmL2InputHighTowerBits)
397  RESETHIST(this->mHistDsmL2InputPatchSumBits)
398  RESETHIST(this->mHistDsmL2InputPatchSum)
399 
400  RESETHIST(this->mHistDsmL3InputHighTowerBits)
401  RESETHIST(this->mHistDsmL3InputPatchSumBits)
402  RESETHIST(this->mHistDsmL3InputBackToBackBit)
403  RESETHIST(this->mHistDsmL3InputJPsiTopoBit)
404  RESETHIST(this->mHistDsmL3InputJetPatchTopoBit)
405 
406  RESETHIST(this->mHistRawAdc1)
407  RESETHIST(this->mHistRawAdc2)
408  RESETHIST(this->mHistRawAdc3)
409  RESETHIST(this->mHistRawAdc4)
410 
411  RESETHIST(this->mHistRawAdc1zoom)
412  RESETHIST(this->mHistRawAdc2zoom)
413  RESETHIST(this->mHistRawAdc3zoom)
414  RESETHIST(this->mHistRawAdc4zoom)
415 
416  RESETHIST(this->mHistRawAdcPsd1)
417  RESETHIST(this->mHistRawAdcPsd2)
418  RESETHIST(this->mHistRawAdcPsd3)
419  RESETHIST(this->mHistRawAdcPsd4)
420 
421  RESETHIST(this->mHistSmdFeeSum)
422  RESETHIST(this->mHistPsdFeeSum)
423 
424  RESETHIST(this->mHistSmdFeeSumNonZS)
425  RESETHIST(this->mHistPsdFeeSumNonZS)
426 
427  for (int i = 0;i < BEMCNJET;i++) {
428  RESETHIST(this->mHistHighTowerSpectrum[i])
429  RESETHIST(this->mHistPatchSumSpectrum[i])
430  }
431 
432  RESETHIST(this->mHistTriggerCorruptionHighTower)
433  RESETHIST(this->mHistTriggerCorruptionPatchSum)
434  RESETHIST(this->mHistDSM0HTCorr)
435  RESETHIST(this->mHistDSM0TPCorr)
436 
437  RESETHIST(this->mHist_TDC_status)
438  RESETHIST(this->mHist_SMD_status)
439  RESETHIST(this->mHist_PSD_status)
440  RESETHIST(this->mHist_BTOW_Corruption)
441 
442  RESETHIST(this->mHist_btow_spectra_1)
443  RESETHIST(this->mHist_btow_spectra_2)
444  RESETHIST(this->mHist_btow_spectra_3)
445 
446  RESETHIST(this->mHist_smd_spectra)
447  RESETHIST(this->mHist_smd_spectraNonZS)
448  RESETHIST(this->mHist_smd_capacitor)
449  RESETHIST(this->mHist_smd_sum)
450  RESETHIST(this->mHist_psd_spectra)
451  RESETHIST(this->mHist_psd_spectraNonZS)
452  RESETHIST(this->mHist_psd_capacitor)
453  RESETHIST(this->mHist_psd_sum)
454 
455  RESETHIST(this->mHist_HTMAX_spectra)
456  RESETHIST(this->mHist_PAMAX_spectra)
457  RESETHIST(this->mHist_HTMAX_dist)
458  RESETHIST(this->mHist_PAMAX_dist)
459 
460  RESETHIST(this->mHist_JET_spectra)
461  RESETHIST(this->mHist_JETMAX_spectra)
462  RESETHIST(this->mHist_JET_ped)
463  RESETHIST(this->mHist_JETMAX_dist)
464 
465  RESETHIST(this->mHist_ADCEtaPhi_TowHits)
466  RESETHIST(this->mHist_ADCEtaPhi_Pre1Hits)
467 
468 
469 #undef RESETHIST
470 
471  for (int i = 0;i < 4800;i++) {
472  this->mTowerData[i][0] = 1; // unmask
473  this->mTowerData[i][1] = 0; // ped
474  this->mTowerData[i][2] = 0; // FEE ped
475  }
476  this->mTriggerPedestalShift = 24 * 100;
477  for (int i = 0;i < 300;i++) {
478  this->mPatchData[i][0] = 1; // unmask HT
479  this->mPatchData[i][1] = 1; // unmask PA
480  this->mPatchData[i][2] = 3; // bit conversion mode
481  this->mPatchData[i][3] = 2; // formula
482  this->mPatchData[i][4] = 1; // formula parameter 0
483  this->mPatchData[i][5] = 0; // formula parameter 1
484  this->mPatchData[i][6] = 0; // formula parameter 2
485  this->mPatchData[i][7] = 1; // formula parameter 3
486  this->mPatchData[i][8] = 0; // formula parameter 4
487  this->mPatchData[i][9] = 0; // formula parameter 5
488  this->mPatchData[i][10] = 0; // number of masked towers
489  }
490  memset(this->BEMCJPPED, 0, sizeof(this->BEMCJPPED));
491  memset(this->BEMCNJPPED, 0, sizeof(this->BEMCNJPPED));
492 
493  if (!BEMCDecoder) BEMCDecoder = new StEmcDecoder();
494 
495  if (bemcStatus) {
496  ifstream ifstr(bemcStatus);
497  if (ifstr.good()) {
498  cout << "Reading BEMC trigger status file " << bemcStatus << endl;
499  } else {
500  cout << "Cannot open BEMC trigger status file! " << bemcStatus << endl;
501  }
502  while (ifstr.good()) {
503  string token;
504  do {
505  if (token == "#") {
506  char dummy[4096];
507  ifstr.getline(dummy, sizeof(dummy));
508  }
509  ifstr >> token;
510  } while (ifstr.good() && (token != "SoftId") && (token != "triggerPatch") && (token != "TriggerPedestalShift"));
511  if (ifstr.good()) {
512  if (token == "SoftId") {
513  int softId, crate, crateSeq, unmaskTower, unmaskHT, unmaskPA, triggerPatch;
514  float ped;
515  ifstr >> softId >> crate >> crateSeq >> unmaskTower >> unmaskHT >> unmaskPA >> ped >> triggerPatch;
516  if (mDebug >= 2) cout << "Read: " << token << " " << softId << "\t" << crate << "\t" << crateSeq << "\t" << unmaskTower << "\t" << unmaskHT << "\t" << unmaskPA << "\t" << ped << "\t" << triggerPatch << endl;
517  if ((softId >= 1) && (softId <= 4800)) {
518  towerPed[softId-1]=ped;
519  this->mTowerData[softId - 1][0] = unmaskTower;
520  this->mTowerData[softId - 1][1] = int(ped * 100.0);
521  //int triggerPatch;
522  //if ((unmaskTower == 0) && BEMCDecoder && BEMCDecoder->GetTriggerPatchFromCrate(crate, crateSeq, triggerPatch)) {
523  if ((triggerPatch >= 0) && (triggerPatch < 300) && (unmaskTower == 0)) {
524  this->mPatchData[triggerPatch][10] += 1;
525  }
526  //}
527  }
528  } else if (token == "triggerPatch") {
529  int triggerPatch, crate, crateSeq, unmaskHT, unmaskPA, bitConv, formula, formulaParam0, formulaParam1, formulaParam2, formulaParam3, formulaParam4, formulaParam5;
530  ifstr >> triggerPatch >> crate >> crateSeq >> unmaskHT >> unmaskPA >> bitConv >> formula >> formulaParam0 >> formulaParam1 >> formulaParam2 >> formulaParam3 >> formulaParam4 >> formulaParam5;
531  if (mDebug >= 2) cout << "Read: " << token << " " << triggerPatch << "\t" << crate << "\t" << crateSeq << "\t" << unmaskHT << "\t" << unmaskPA << "\t" << bitConv << "\t" << formula << "\t" << formulaParam0 << "\t" << formulaParam1 << "\t" << formulaParam2 << "\t" << formulaParam3 << "\t" << formulaParam4 << "\t" << formulaParam5 << endl;
532  if ((triggerPatch >= 0) && (triggerPatch < 300)) {
533  this->mPatchData[triggerPatch][0] = unmaskHT;
534  this->mPatchData[triggerPatch][1] = unmaskPA;
535  this->mPatchData[triggerPatch][2] = bitConv;
536  this->mPatchData[triggerPatch][3] = formula;
537  this->mPatchData[triggerPatch][4] = formulaParam0;
538  this->mPatchData[triggerPatch][5] = formulaParam1;
539  this->mPatchData[triggerPatch][6] = formulaParam2;
540  this->mPatchData[triggerPatch][7] = formulaParam3;
541  this->mPatchData[triggerPatch][8] = formulaParam4;
542  this->mPatchData[triggerPatch][9] = formulaParam5;
543  }
544  } else if (token == "TriggerPedestalShift") {
545  float pedShift;
546  ifstr >> pedShift;
547  this->mTriggerPedestalShift = int(pedShift * 100.0);
548  if (mDebug >= 2) cout << "Read: " << token << " " << pedShift << endl;
549  }
550  }
551  }
552  ifstr.close();
553  for (int i = 0;i < 4800;i++) {
554  this->mTowerData[i][2] = getFEEpedestal(float(this->mTowerData[i][1]) / 100.0, this->mTriggerPedestalShift / 100.0, false/*(i >= (3285 - 1)) && (i <= (3288 - 1))*/);
555  }
556  }
557  if (mDebug >= 10) cout << __FILE__ << ":" << __LINE__ << endl;
558 }
559 //-------------------------------------------------------------------
560 void BEMCPlots::saveHistograms(TFile *hfile) {
561  if (mDebug >= 10) cout << __FILE__ << ":" << __LINE__ << endl;
562  if (!hfile || (mDebug >= 2)) cout << "hfile = " << hfile << endl;
563  if (hfile) {
564  hfile->cd();
565 
566 #define SAVEHIST(HIST) if (HIST) (HIST)->Write();
567 
568  SAVEHIST(this->mHistTot)
569 
570  SAVEHIST(this->mHistDsmL0InputHighTower)
571  SAVEHIST(this->mHistDsmL0InputPatchSum)
572 
573  SAVEHIST(this->mHistDsmL1InputHighTowerBits)
574  SAVEHIST(this->mHistDsmL1InputPatchSum)
575 
576  SAVEHIST(this->mHistDsmL2InputHighTowerBits)
577  SAVEHIST(this->mHistDsmL2InputPatchSumBits)
578  SAVEHIST(this->mHistDsmL2InputPatchSum)
579 
580  SAVEHIST(this->mHistDsmL3InputHighTowerBits)
581  SAVEHIST(this->mHistDsmL3InputPatchSumBits)
582  SAVEHIST(this->mHistDsmL3InputBackToBackBit)
583  SAVEHIST(this->mHistDsmL3InputJPsiTopoBit)
584  SAVEHIST(this->mHistDsmL3InputJetPatchTopoBit)
585 
586  SAVEHIST(this->mHistRawAdc1)
587  SAVEHIST(this->mHistRawAdc2)
588  SAVEHIST(this->mHistRawAdc3)
589  SAVEHIST(this->mHistRawAdc4)
590 
591  SAVEHIST(this->mHistRawAdc1zoom)
592  SAVEHIST(this->mHistRawAdc2zoom)
593  SAVEHIST(this->mHistRawAdc3zoom)
594  SAVEHIST(this->mHistRawAdc4zoom)
595 
596  SAVEHIST(this->mHistRawAdcPsd1)
597  SAVEHIST(this->mHistRawAdcPsd2)
598  SAVEHIST(this->mHistRawAdcPsd3)
599  SAVEHIST(this->mHistRawAdcPsd4)
600 
601  SAVEHIST(this->mHistSmdFeeSum)
602  SAVEHIST(this->mHistPsdFeeSum)
603 
604  SAVEHIST(this->mHistSmdFeeSumNonZS)
605  SAVEHIST(this->mHistPsdFeeSumNonZS)
606 
607  for (int i = 0;i < BEMCNJET;i++) {
608  SAVEHIST(this->mHistHighTowerSpectrum[i])
609  SAVEHIST(this->mHistPatchSumSpectrum[i])
610  }
611 
612  SAVEHIST(this->mHistTriggerCorruptionHighTower)
613  SAVEHIST(this->mHistTriggerCorruptionPatchSum)
614  SAVEHIST(this->mHistDSM0HTCorr)
615  SAVEHIST(this->mHistDSM0TPCorr)
616 
617  SAVEHIST(this->mHist_TDC_status)
618  SAVEHIST(this->mHist_SMD_status)
619  SAVEHIST(this->mHist_PSD_status)
620  SAVEHIST(this->mHist_BTOW_Corruption)
621 
622  SAVEHIST(this->mHist_btow_spectra_1)
623  SAVEHIST(this->mHist_btow_spectra_2)
624  SAVEHIST(this->mHist_btow_spectra_3)
625 
626  SAVEHIST(this->mHist_smd_spectra)
627  SAVEHIST(this->mHist_smd_spectraNonZS)
628  SAVEHIST(this->mHist_smd_capacitor)
629  SAVEHIST(this->mHist_smd_sum)
630  SAVEHIST(this->mHist_psd_spectra)
631  SAVEHIST(this->mHist_psd_spectraNonZS)
632  SAVEHIST(this->mHist_psd_capacitor)
633  SAVEHIST(this->mHist_psd_sum)
634 
635  SAVEHIST(this->mHist_HTMAX_spectra)
636  SAVEHIST(this->mHist_PAMAX_spectra)
637  SAVEHIST(this->mHist_HTMAX_dist)
638  SAVEHIST(this->mHist_PAMAX_dist)
639 
640  SAVEHIST(this->mHist_JET_spectra)
641  SAVEHIST(this->mHist_JETMAX_spectra)
642  SAVEHIST(this->mHist_JET_ped)
643 
644  SAVEHIST(this->mHist_JETMAX_dist)
645 
646  SAVEHIST(this->mHist_ADCEtaPhi_TowHits)
647  SAVEHIST(this->mHist_ADCEtaPhi_Pre1Hits)
648 
649 
650 
651 #undef SAVEHIST
652 
653  }
654  if (mDebug >= 10) cout << __FILE__ << ":" << __LINE__ << endl;
655 }
656 
657 
658 
659 
660 //-------------------------------------------------------------------
661 void BEMCPlots::processEvent( char *datap
662  , const unsigned char *dsmL0WestInput
663  , const unsigned char *dsmL0EastInput
664  , const unsigned short *dsmL1Input
665  , const unsigned short *dsmL2Input
666  , const unsigned short *dsmL3Input
667  ) {
668 
669  if (mDebug >= 10) cout << __FILE__ << ":" << __LINE__ << endl;
670 #ifdef NEW_DAQ_READER
671  daqReader *rdr = (daqReader*)(datap);
672 #else
673  evpReader *evp_reader = (evpReader*)(datap);
674  int ret = emcReader(datap);
675 #endif
676 
677  {
678 #ifdef NEW_DAQ_READER
679  TDatime evt_time(rdr->evt_time); // time in unix seconds
680 #else
681  TDatime evt_time(evp_reader->evt_time);
682 #endif
683  if (BEMCDecoder) BEMCDecoder->SetDateTime(evt_time.GetDate(),evt_time.GetTime());
684  }
685 
686 
687  /*
688  if (!dsmL0WestInput || !dsmL0EastInput || !dsmL1Input || !dsmL2Input || !dsmL3Input) {
689  #ifdef NEW_DAQ_READER
690  daq_dta *dd_trg = rdr ? (rdr->det("trg")->get("legacy")) : 0;
691  if (dd_trg) while (dd_trg->iterate()) {
692  trg_t *d = (trg_t *) dd_trg->Void;
693  if (d) {
694  dsmL0WestInput = &(d->BEMC[0][0]);
695  dsmL0EastInput = &(d->BEMC[1][0]);
696  dsmL1Input = &(d->BEMC_l1[0]);
697  dsmL2Input = ((unsigned short*)d->trg_sum ? (((TrgSumData*)d->trg_sum)->DSMdata.EMC) : 0);
698  dsmL3Input = ((unsigned short*)d->trg_sum ? (((TrgSumData*)d->trg_sum)->DSMdata.lastDSM) : 0);
699  }
700  }
701  #else
702  trgReader(datap);
703  dsmL0WestInput = &(trg.BEMC[0][0]);
704  dsmL0EastInput = &(trg.BEMC[1][0]);
705  dsmL1Input = trg.BEMC_l1;
706  dsmL2Input = ((unsigned short*) trg.trg_sum ? (((TrgSumData*)trg.trg_sum)->DSMdata.EMC) : 0);
707  dsmL3Input = ((unsigned short*) trg.trg_sum ? (((TrgSumData*)trg.trg_sum)->DSMdata.lastDSM) : 0);
708  #endif
709  }
710  */
711  if (!datap || (mDebug >= 2)) cout << "datap = " << (int*)datap << endl;
712  if (!dsmL0WestInput || (mDebug >= 2)) cout << "dsmL0WestInput = " << (int*)dsmL0WestInput << endl;
713  if (!dsmL0EastInput || (mDebug >= 2)) cout << "dsmL0EastInput = " << (int*)dsmL0EastInput << endl;
714  if (!dsmL1Input || (mDebug >= 2)) cout << "dsmL1Input = " << (int*)dsmL1Input << endl;
715  if (!dsmL2Input || (mDebug >= 2)) cout << "dsmL2Input = " << (int*)dsmL2Input << endl;
716  if (!dsmL3Input || (mDebug >= 2)) cout << "dsmL3Input = " << (int*)dsmL3Input << endl;
717  if (!BEMCDecoder || (mDebug >= 2)) cout << "BEMCDecoder = " << BEMCDecoder << endl;
718 
719  bool DSM_L0_present = BEMC_DSM_L0_decoder(dsmL0WestInput, dsmL0EastInput, &(this->mDsmL0InputHighTower[0]), &(this->mDsmL0InputPatchSum[0]));
720 
721  bool DSM_L1_present = BEMC_DSM_L1_decoder(dsmL1Input, &(this->mDsmL1InputHighTowerBits[0][0]), &(this->mDsmL1InputPatchSum[0][0]));
722 
723  bool DSM_L2_present = BEMC_DSM_L2_decoder(dsmL2Input, &(this->mDsmL2InputHighTowerBits[0]), &(this->mDsmL2InputPatchSumBits[0]), &(this->mDsmL2InputPatchSum[0]));
724 
725  bool DSM_L3_present = BEMC_DSM_L3_decoder(dsmL3Input, &(this->mDsmL3InputHighTowerBits[0]), &(this->mDsmL3InputPatchSumBits[0]), &(this->mDsmL3InputBackToBackBit[0]), &(this->mDsmL3InputJPsiTopoBit[0]), &(this->mDsmL3InputJetPatchTopoBit[0]));
726 
727 
728  if (this->mHistTot) this->mHistTot->Fill(0.5);
729 
730  if (DSM_L0_present) {
731  int jetPatchSum[BEMCNJET];
732  int jetPatchHT[BEMCNJET];
733  memset(jetPatchSum, 0, sizeof(jetPatchSum));
734  memset(jetPatchHT, 0, sizeof(jetPatchHT));
735  int MAXHT = 0;
736  int MAXPA = 0;
737  int MAXHTID = 0;
738  int MAXPAID = 0;
739  for (int i = 0;i < 300;i++) {
740  if (this->mHistDsmL0InputHighTower) this->mHistDsmL0InputHighTower->Fill(i, this->mDsmL0InputHighTower[i]);
741  if (this->mHistDsmL0InputPatchSum) this->mHistDsmL0InputPatchSum->Fill(i, this->mDsmL0InputPatchSum[i]);
742 
743  if((this->mDsmL0InputHighTower[i] > MAXHT) && (this->mDsmL0InputHighTower[i] < 63)) {MAXHT = this->mDsmL0InputHighTower[i]; MAXHTID = i;}
744  if((this->mDsmL0InputPatchSum[i] > MAXPA) && (this->mDsmL0InputPatchSum[i] < 63)) {MAXPA = this->mDsmL0InputPatchSum[i]; MAXPAID = i;}
745 
746  if (BEMCDecoder) {
747  int jetPatch = -1, jetPatchSeq = -1;
748  if (BEMCDecoder->GetJetPatchAndSequenceFromTriggerPatch(i, jetPatch, jetPatchSeq)) {
749  if ((jetPatch >= 0) && (jetPatch < BEMCNJET)) {
750  if (jetPatchHT[jetPatch] < this->mDsmL0InputHighTower[i]) jetPatchHT[jetPatch] = this->mDsmL0InputHighTower[i];
751  jetPatchSum[jetPatch] += this->mDsmL0InputPatchSum[i];
752  }
753  }
754  }
755 
756  if (mDebug >= 3) cout << "TriggerPatch " << i << ": HighTower = " << this->mDsmL0InputHighTower[i] << ", PatchSum = " << this->mDsmL0InputPatchSum[i] << endl;
757  }
758  if(this->mHist_HTMAX_spectra) this->mHist_HTMAX_spectra->Fill((float)MAXHTID,(float)MAXHT);
759  if(this->mHist_PAMAX_spectra) this->mHist_PAMAX_spectra->Fill((float)MAXPAID,(float)MAXPA);
760 
761  int HTTH = 12;
762  int PATH = 12;
763  if((MAXHT > HTTH) && this->mHist_HTMAX_dist) this->mHist_HTMAX_dist->Fill((float)MAXHTID);
764  if((MAXPA > PATH) && this->mHist_PAMAX_dist) this->mHist_PAMAX_dist->Fill((float)MAXPAID);
765 
766  int MAXJETID =0;
767  int MAXJETVALUE =-9999;
768  for (int i = 0;i < BEMCNJET;i++) {
769  if (this->mHistHighTowerSpectrum[i]) this->mHistHighTowerSpectrum[i]->Fill(jetPatchHT[i]);
770  if (this->mHistPatchSumSpectrum[i]) this->mHistPatchSumSpectrum[i]->Fill(jetPatchSum[i]);
771  if (jetPatchSum[i] > MAXJETVALUE) { MAXJETVALUE = jetPatchSum[i]; MAXJETID = i;}
772  if (this->mHist_JET_spectra) this->mHist_JET_spectra->Fill(i, jetPatchSum[i]);
773  }
774  if (this->mHist_JETMAX_spectra) this->mHist_JETMAX_spectra->Fill(MAXJETID,MAXJETVALUE);
775  int JETPATH = 35;
776  if ((MAXJETVALUE > JETPATH) && this->mHist_JETMAX_dist) this->mHist_JETMAX_dist->Fill(MAXJETID);
777 
778  for (int i=0;i<BEMCNJET;i++) {
779  if (i != MAXJETID) {
780  BEMCJPPED[i] += jetPatchSum[i];
781  BEMCNJPPED[i]++;
782  if(BEMCNJPPED[i]==10) {
783  if (this->mHist_JET_ped) this->mHist_JET_ped->Fill(i,(float)BEMCJPPED[i]/(float)BEMCNJPPED[i]);
784  BEMCJPPED[i] = 0;
785  BEMCNJPPED[i] = 0;
786  }
787  }
788  }
789  }
790 
791  if (DSM_L1_present) {
792  int ch = 0;
793  for (int idsmL1 = 0;idsmL1 < 6;idsmL1++) {
794  for (int idsmL1ch = 0;idsmL1ch < 6;idsmL1ch++) {
795  int idsmL1WestFirst = (idsmL1 < 3) ? (idsmL1 + 3) : (idsmL1 - 3);
796  if (this->mHistDsmL1InputHighTowerBits) this->mHistDsmL1InputHighTowerBits->Fill(ch, this->mDsmL1InputHighTowerBits[idsmL1WestFirst][idsmL1ch]);
797  if (this->mHistDsmL1InputPatchSum) this->mHistDsmL1InputPatchSum->Fill(ch, this->mDsmL1InputPatchSum[idsmL1WestFirst][idsmL1ch]);
798  ch++;
799  }
800  }
801  }
802 
803  if (DSM_L2_present) {
804  for (int ijp = 0;ijp < BEMCNJET;ijp++) {
805  if (this->mHistDsmL2InputHighTowerBits) this->mHistDsmL2InputHighTowerBits->Fill(ijp, this->mDsmL2InputHighTowerBits[ijp]);
806  if (this->mHistDsmL2InputPatchSumBits) this->mHistDsmL2InputPatchSumBits->Fill(ijp, this->mDsmL2InputPatchSumBits[ijp]);
807  }
808  for (int ijpp = 0;ijpp < 6;ijpp++) {
809  int ijppWestFirst = (ijpp < 3) ? (ijpp + 3) : (ijpp - 3);
810  if (this->mHistDsmL2InputPatchSum) this->mHistDsmL2InputPatchSum->Fill(ijppWestFirst, this->mDsmL2InputPatchSum[ijpp]);
811  }
812  }
813 
814  if (DSM_L3_present) {
815  if (this->mHistDsmL3InputHighTowerBits) this->mHistDsmL3InputHighTowerBits->Fill(this->mDsmL3InputHighTowerBits[0]);
816  if (this->mHistDsmL3InputPatchSumBits) this->mHistDsmL3InputPatchSumBits->Fill(this->mDsmL3InputPatchSumBits[0]);
817  if (this->mHistDsmL3InputBackToBackBit) this->mHistDsmL3InputBackToBackBit->Fill(this->mDsmL3InputBackToBackBit[0]);
818  if (this->mHistDsmL3InputJPsiTopoBit) this->mHistDsmL3InputJPsiTopoBit->Fill(this->mDsmL3InputJPsiTopoBit[0]);
819  if (this->mHistDsmL3InputJetPatchTopoBit) this->mHistDsmL3InputJetPatchTopoBit->Fill(this->mDsmL3InputJetPatchTopoBit[0]);
820  }
821 
822  int STATUS = BEMCNOTINSTALLED; //NOT PRESENT
823 #ifdef NEW_DAQ_READER
824  daq_dta *dd_btow = rdr ? (rdr->det("btow")->get("adc")) : 0;
825  if (dd_btow) while (dd_btow->iterate()) {
826  btow_t *d = (btow_t *) dd_btow->Void;
827  if (d) {
828 #else
829  if ((ret >= 0) && emc.btow_in) {
830  unsigned short *header = emc.btow_raw; // BTOW event header
831  if (header) {
832 #endif
833  if (DSM_L0_present) {
834  memset(this->mDsmSimuHighTower, 0, sizeof(this->mDsmSimuHighTower));
835  memset(this->mDsmSimuPatchSum, 0, sizeof(this->mDsmSimuPatchSum));
836  }
837  int TDCStatus[BTOW_MAXFEE];
838  memset(TDCStatus, BEMCNOTINSTALLED, sizeof(TDCStatus));
839  int TDCTotal = 0;
840  STATUS = BEMCOK; //OK
841  for (int tdc = 0; tdc < BTOW_MAXFEE;tdc++) {
842 #ifdef NEW_DAQ_READER
843  int count = d->preamble[tdc][0];
844  int error = d->preamble[tdc][1];
845 #else
846  int count = (*(header + tdc));
847  int error = (*(header + tdc + 30));
848 #endif
849  if ((error == 0) && (count == (BTOW_PRESIZE + BTOW_DATSIZE))) TDCStatus[tdc] = BEMCOK; // OK
850  else if ((error == 4095) && (count == 4095)) TDCStatus[tdc] = BEMCNOTINSTALLED; // NOT INSTALLED
851  else TDCStatus[tdc] = BEMCCORRUPTED; //CORRUPTED
852  if (TDCStatus[tdc] == BEMCCORRUPTED) STATUS = BEMCCORRUPTED; // if any crate is corrupted, mark event as corrupted
853  if (this->mHist_TDC_status) this->mHist_TDC_status->Fill(0.0, tdc);
854  if (this->mHist_TDC_status) this->mHist_TDC_status->Fill((float)TDCStatus[tdc], tdc);
855  }
856  for(int i = 0;i < (BTOW_MAXFEE * BTOW_DATSIZE);i++) {
857  int tdc = i % BTOW_MAXFEE;
858 #ifdef NEW_DAQ_READER
859  int tdc_channel = i / BTOW_MAXFEE;
860  int count = d->preamble[tdc][0];
861  int error = d->preamble[tdc][1];
862 #else
863  int count = (*(header + tdc));
864  int error = (*(header + tdc + 30));
865 #endif
866  if((error==0) && (count == (BTOW_PRESIZE + BTOW_DATSIZE))) {
867  // OK
868 #ifdef NEW_DAQ_READER
869  int adc = d->adc[tdc][tdc_channel];
870 #else
871  int adc = emc.btow[i];
872 #endif
873  TDCTotal += adc;
874  int daqid = ((tdc * BTOW_DATSIZE) + tdc_channel);
875  if ((tdc >= 0) && (tdc < 10) && (TDCStatus[tdc]!=BEMCNOTINSTALLED) && this->mHist_btow_spectra_1) this->mHist_btow_spectra_1->Fill(daqid, adc);
876  if ((tdc >= 10) && (tdc < 20) && (TDCStatus[tdc]!=BEMCNOTINSTALLED) && this->mHist_btow_spectra_2) this->mHist_btow_spectra_2->Fill(daqid, adc);
877  if ((tdc >= 20) && (tdc < 30) && (TDCStatus[tdc]!=BEMCNOTINSTALLED) && this->mHist_btow_spectra_3) this->mHist_btow_spectra_3->Fill(daqid, adc);
878  int softId = -1;
879  float iphi, eta, adcped;
880 
881  if (BEMCDecoder && BEMCDecoder->GetTowerIdFromDaqId(i, softId)) {
882 
883  adcped=adc-towerPed[softId-1];
884 
885  StEmcGeom *BEMCGeom = StEmcGeom::instance("bemc");
886 
887  if(adcped>20)
888  {
889  BEMCGeom->getEta(softId, eta);
890  BEMCGeom->getPhi(softId, iphi);
891  if ((this->mHist_ADCEtaPhi_TowHits) && (this->mTowerData[softId - 1][0] != 0) ) this->mHist_ADCEtaPhi_TowHits->Fill(iphi, eta);
892  }
893 
894  if ((softId >= 1) && (softId <= 4800)) {
895  if ((softId >= 1) && (softId <= 1220)) {
896  if (this->mHistRawAdc1) this->mHistRawAdc1->Fill(softId, adc);
897  if (this->mHistRawAdc1zoom) this->mHistRawAdc1zoom->Fill(softId, adc);
898  } else if ((softId >= 1221) && (softId <= 2400)) {
899  if (this->mHistRawAdc2) this->mHistRawAdc2->Fill(softId, adc);
900  if (this->mHistRawAdc2zoom) this->mHistRawAdc2zoom->Fill(softId, adc);
901  } else if ((softId >= 2401) && (softId <= 3540)) {
902  if (this->mHistRawAdc3) this->mHistRawAdc3->Fill(softId, adc);
903  if (this->mHistRawAdc3zoom) this->mHistRawAdc3zoom->Fill(softId, adc);
904  } else if ((softId >= 3541) && (softId <= 4800)) {
905  if (this->mHistRawAdc4) this->mHistRawAdc4->Fill(softId, adc);
906  if (this->mHistRawAdc4zoom) this->mHistRawAdc4zoom->Fill(softId, adc);
907  }
908 
909  if (DSM_L0_present && (this->mTowerData[softId - 1][0] != 0)) {
910  int crate = -1, crateSeq = -1;
911  if (BEMCDecoder->GetTowerCrateFromDaqId(i, crate, crateSeq)) {
912  int triggerPatch = -1;
913  if (BEMCDecoder->GetTriggerPatchFromCrate(crate, crateSeq, triggerPatch)) {
914  if ((triggerPatch >= 0) && (triggerPatch < 300)) {
915  int ht = -1, pa = -1;
916  if (triggerPatch == 27300) cout << "SoftId " << softId << " ";
917  simulateFEEaction(adc, this->mTowerData[softId - 1][2], this->mPatchData[triggerPatch][2], ht, pa, (triggerPatch == 27300));
918  if (ht > this->mDsmSimuHighTower[triggerPatch]) this->mDsmSimuHighTower[triggerPatch] = ht;
919  this->mDsmSimuPatchSum[triggerPatch] += pa;
920  }
921  }
922  }
923  }
924  }
925  }
926  }
927  }
928  for (int i = 0;i < 300;i++) {
929  if (this->mPatchData[i][0] == 0) this->mDsmSimuHighTower[i] = 0;
930  if (this->mPatchData[i][1] == 0) {
931  this->mDsmSimuPatchSum[i] = 0;
932  } else {
933  int lut = -1;
934  simulateFEELUT(this->mDsmSimuPatchSum[i], this->mPatchData[i][3], this->mPatchData[i][4], this->mPatchData[i][5], this->mPatchData[i][6], this->mPatchData[i][7], this->mPatchData[i][8], this->mPatchData[i][9], this->mPatchData[i][10], (int)(this->mTriggerPedestalShift / 100.0), lut, (i == 27300));
935  this->mDsmSimuPatchSum[i] = lut;
936  }
937  //cout << "Trigger patch " << i;
938  if (this->mDsmL0InputHighTower[i] != this->mDsmSimuHighTower[i]) {
939  if (mDebug >= 2) cout << i << ": HT " << this->mDsmSimuHighTower[i] << " != " << this->mDsmL0InputHighTower[i] << endl;
940  if (this->mHistTriggerCorruptionHighTower) this->mHistTriggerCorruptionHighTower->Fill(i);
941  if (this->mHistDSM0HTCorr) this->mHistDSM0HTCorr->Fill(this->mDsmL0InputHighTower[i], this->mDsmSimuHighTower[i]);
942  } else {
943  //cout << "- " << i << "HT OK" << endl;
944  }
945  if (this->mDsmL0InputPatchSum[i] != this->mDsmSimuPatchSum[i]) {
946  if (mDebug >= 2) cout << i << ": PA " << this->mDsmSimuPatchSum[i] << " != " << this->mDsmL0InputPatchSum[i] << endl;
947  if (this->mHistTriggerCorruptionPatchSum) this->mHistTriggerCorruptionPatchSum->Fill(i);
948  if (this->mHistDSM0TPCorr) this->mHistDSM0TPCorr->Fill(this->mDsmL0InputPatchSum[i], this->mDsmSimuPatchSum[i]);
949  } else {
950  //cout << "- " << i << "PA OK" << endl;
951  }
952  //cout << endl;
953  }
954  }
955  }
956  if (this->mHist_BTOW_Corruption) this->mHist_BTOW_Corruption->Fill(0.0);
957  if (this->mHist_BTOW_Corruption) this->mHist_BTOW_Corruption->Fill(STATUS);
958 
959  {
960  int totalSumSMD = 0;
961  int totalSumPSD = 0;
962  int feeSum[120];
963  int pmtSum[60];
964  memset(feeSum, 0, sizeof(feeSum));
965  memset(pmtSum, 0, sizeof(pmtSum));
966  bool smdPresent = false;
967  bool psdPresent = false;
968  for (int bsmd_fiber = 0;bsmd_fiber < BSMD_FIBERS;bsmd_fiber++) {
969  int bprs_fiber = bsmd_fiber - 8;
970 #ifdef NEW_DAQ_READER
971  daq_dta *dd_bsmd = rdr ? (rdr->det("bsmd")->get("adc", 0, bsmd_fiber + 1)) : 0; // RTS_READER counts everything from 1, not from 0
972  if (dd_bsmd) while (dd_bsmd->iterate()) {
973  bsmd_t *d = (bsmd_t *) dd_bsmd->Void;
974  if (d && BEMCDecoder) {
975 #else
976  if (emc.bsmd_in && BEMCDecoder) {
977  {
978 #endif
979  int fiberSum = 0;
980  int det = -1, m = -1, e = -1, s = -1;
981  int softId = -1, box = -1, wire = -1, Avalue = -1;
982 #ifdef NEW_DAQ_READER
983  int cap = d->cap;
984 #else
985  int cap = emc.bsmd_cap[bsmd_fiber];
986 #endif
987  for (int fiber_channel = 0;fiber_channel < BSMD_DATSIZE;fiber_channel++) {
988 #ifdef NEW_DAQ_READER
989  int adc = d->adc[fiber_channel];
990 #else
991  int adc = emc.bsmd[bsmd_fiber][fiber_channel];
992 #endif
993  fiberSum += adc;
994  if ((bsmd_fiber >= 0) && (bsmd_fiber < 8)) {
995  if (BEMCDecoder->GetSmdCoord(bsmd_fiber, fiber_channel, det, m, e, s)) {
996  smdPresent = true;
997  totalSumSMD += adc;
998  if ((m >= 1) && (m <= 120)) {
999  feeSum[m - 1] += adc;
1000  }
1001  }
1002  } else {
1003  if (BEMCDecoder->GetPsdId(bprs_fiber, fiber_channel, softId, box, wire, Avalue)) {
1004  psdPresent = true;
1005  totalSumPSD += adc;
1006  if ((box >= 1) && (box <= 60)) {
1007  pmtSum[box - 1] += adc;
1008  float iphi, eta;
1009  StEmcGeom *BEMCGeom = StEmcGeom::instance("bemc");
1010  if(adc>20){
1011  BEMCGeom->getEta(softId, eta);
1012  BEMCGeom->getPhi(softId, iphi);
1013  if (this->mHist_ADCEtaPhi_Pre1Hits) this->mHist_ADCEtaPhi_Pre1Hits->Fill(iphi, eta);
1014  }
1015  if ((softId >= 1) && (softId <= 1220)) {
1016  if (this->mHistRawAdcPsd1) this->mHistRawAdcPsd1->Fill(softId, adc);
1017  } else if ((softId >= 1221) && (softId <= 2400)) {
1018  if (this->mHistRawAdcPsd2) this->mHistRawAdcPsd2->Fill(softId, adc);
1019  } else if ((softId >= 2401) && (softId <= 3540)) {
1020  if (this->mHistRawAdcPsd3) this->mHistRawAdcPsd3->Fill(softId, adc);
1021  } else if ((softId >= 3541) && (softId <= 4800)) {
1022  if (this->mHistRawAdcPsd4) this->mHistRawAdcPsd4->Fill(softId, adc);
1023  }
1024  }
1025  }
1026  }
1027  }
1028  int BSMD_STATUS = BEMCOK;
1029  if (fiberSum == 0) BSMD_STATUS = BEMCNOTINSTALLED;
1030  //fprintf(stderr,"Sum for fiber %d = %f\n",bsmd_fiber,fiberSum);
1031  if((bsmd_fiber >= 0) && (bsmd_fiber < 8)) {
1032  if (this->mHist_SMD_status) this->mHist_SMD_status->Fill(0.0, bsmd_fiber);
1033  if (this->mHist_SMD_status) this->mHist_SMD_status->Fill(BSMD_STATUS, bsmd_fiber);
1034  if(BSMD_STATUS==BEMCOK) {
1035  if (this->mHist_smd_capacitor) this->mHist_smd_capacitor->Fill(cap, bsmd_fiber);
1036  if (this->mHist_smd_sum) this->mHist_smd_sum->Fill(fiberSum, bsmd_fiber);
1037  }
1038  } else {
1039  if (this->mHist_PSD_status) this->mHist_PSD_status->Fill(0.0, bprs_fiber);
1040  if (this->mHist_PSD_status) this->mHist_PSD_status->Fill(BSMD_STATUS, bprs_fiber);
1041  if(BSMD_STATUS==BEMCOK) {
1042  if (this->mHist_psd_capacitor) this->mHist_psd_capacitor->Fill(cap, bprs_fiber);
1043  if (this->mHist_psd_sum) this->mHist_psd_sum->Fill(fiberSum, bprs_fiber);
1044  }
1045  }
1046  }
1047  }
1048  }
1049  if (smdPresent) for (int i = 0;i < 120;i++) {
1050  if (this->mHistSmdFeeSum) this->mHistSmdFeeSum->Fill(i + 1, feeSum[i]);
1051  }
1052  if (psdPresent) for (int i = 0;i < 60;i++) {
1053  if (this->mHistPsdFeeSum) this->mHistPsdFeeSum->Fill(i + 1, pmtSum[i]);
1054  }
1055  if (smdPresent && this->mHist_smd_spectra) this->mHist_smd_spectra->Fill(totalSumSMD);
1056  if (psdPresent && this->mHist_psd_spectra) this->mHist_psd_spectra->Fill(totalSumPSD);
1057  }
1058 
1059  {
1060  int totalSumSMDNonZS = 0;
1061  int totalSumPSDNonZS = 0;
1062  int feeSumNonZS[120];
1063  int pmtSumNonZS[60];
1064  memset(feeSumNonZS, 0, sizeof(feeSumNonZS));
1065  memset(pmtSumNonZS, 0, sizeof(pmtSumNonZS));
1066  bool smdPresentNonZS = false;
1067  bool psdPresentNonZS = false;
1068  for (int bsmd_fiber = 0;bsmd_fiber < BSMD_FIBERS;bsmd_fiber++) {
1069  int bprs_fiber = bsmd_fiber - 8;
1070 #ifdef NEW_DAQ_READER
1071  daq_dta *dd_bsmd = rdr ? (rdr->det("bsmd")->get("adc_non_zs", 0, bsmd_fiber + 1)) : 0;
1072  if (dd_bsmd) while (dd_bsmd->iterate()) {
1073  bsmd_t *d = (bsmd_t *) dd_bsmd->Void;
1074  if (d && BEMCDecoder) {
1075 #else
1076  if (emc.bsmd_in && BEMCDecoder) {
1077  {
1078 #endif
1079  int fiberSum = 0;
1080  int det = -1, m = -1, e = -1, s = -1;
1081  int softId = -1, box = -1, wire = -1, Avalue = -1;
1082 #ifdef NEW_DAQ_READER
1083  int cap = d->cap;
1084 #else
1085  int cap = emc.bsmd_cap[bsmd_fiber];
1086 #endif
1087  for (int fiber_channel = 0;fiber_channel < BSMD_DATSIZE;fiber_channel++) {
1088 #ifdef NEW_DAQ_READER
1089  int adc = d->adc[fiber_channel];
1090 #else
1091  int adc = emc.bsmd[bsmd_fiber][fiber_channel];
1092 #endif
1093  fiberSum += adc;
1094  if ((bsmd_fiber >= 0) && (bsmd_fiber < 8)) {
1095  if (BEMCDecoder->GetSmdCoord(bsmd_fiber, fiber_channel, det, m, e, s)) {
1096  smdPresentNonZS = true;
1097  totalSumSMDNonZS += adc;
1098  if ((m >= 1) && (m <= 120)) {
1099  feeSumNonZS[m - 1] += adc;
1100  }
1101  }
1102  } else {
1103  if (BEMCDecoder->GetPsdId(bprs_fiber, fiber_channel, softId, box, wire, Avalue)) {
1104  psdPresentNonZS = true;
1105  totalSumPSDNonZS += adc;
1106  if ((box >= 1) && (box <= 60)) {
1107  pmtSumNonZS[box - 1] += adc;
1108  }
1109  }
1110  }
1111  }
1112  }
1113  }
1114  }
1115  if (smdPresentNonZS) for (int i = 0;i < 120;i++) {
1116  if (this->mHistSmdFeeSumNonZS) this->mHistSmdFeeSumNonZS->Fill(i + 1, feeSumNonZS[i]);
1117  }
1118  if (psdPresentNonZS) for (int i = 0;i < 60;i++) {
1119  if (this->mHistPsdFeeSumNonZS) this->mHistPsdFeeSumNonZS->Fill(i + 1, pmtSumNonZS[i]);
1120  }
1121  if (smdPresentNonZS && this->mHist_smd_spectraNonZS) this->mHist_smd_spectraNonZS->Fill(totalSumSMDNonZS);
1122  if (psdPresentNonZS && this->mHist_psd_spectraNonZS) this->mHist_psd_spectraNonZS->Fill(totalSumPSDNonZS);
1123  }
1124 
1125  if (mDebug >= 10) cout << __FILE__ << ":" << __LINE__ << endl;
1126 }
1127 
1128 
1129 
int GetTriggerPatchFromCrate(int crate, int sequence, int &patchId) const
returns the trigger patch from crate and sequence in the crate
int GetSmdCoord(int RDO, int posInFiber, int &det, int &m, int &e, int &s, bool print=false) const
Get SMD detector (3==SMDE, 4==SMDP), m, e, s from RDO and position for SMD.
Definition: DSM.hh:16
int GetTowerCrateFromDaqId(int RDO, int &crate, int &sequence) const
Get crate number from Daq Id for towers.
int GetTowerIdFromDaqId(int RDO, int &softId) const
Get Sofwtare Id from Daq Id for towers.
Definition: daq_btow.h:9
int GetJetPatchAndSequenceFromTriggerPatch(int patchId, int &jetPatch, int &sequence) const
return the big jet patch and sequence number within it from the
int GetPsdId(int RDO, int posInFiber, int &softId, bool print=false) const
Get PSD id.