StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
EEdsmAna.cxx
1 //#include <iostream>
2 
3 #include <TObjArray.h>
4 #include <TH2.h>
5 #include <TFile.h>
6 
7 #include <StMessMgr.h>
8 
9 #include "EEdsmAna.h"
10 
11 #define EEmapTP_USE // trick instattiates data only in the cxx
12 #include "StTriggerUtilities/Eemc/EEmapTP.h"
13 #undef EEmapTP_USE
14 
15 #include "StTriggerUtilities/Eemc/EEdsm0.h"
16 #include "StTriggerUtilities/Eemc/EEdsm1.h"
17 #include "StTriggerUtilities/Eemc/EEdsm2.h"
18 #include "StTriggerUtilities/Eemc/EEdsm3.h"
19 
20 #include "StTriggerUtilities/StDSMUtilities/DSM.hh"
21 #include "StTriggerUtilities/StDSMUtilities/DSMAlgo_EE101_2009.hh"
22 #include "StTriggerUtilities/StDSMUtilities/DSMAlgo_EE102_2009.hh"
23 
24 
25 ClassImp(EEdsmAna)
26 
27 //--------------------------------------------------
28 EEdsmAna::EEdsmAna(const Char_t *name, int year)
29  : myName(name)
30  , mYear(year)
31  , EE101(*new DSM("EE101"))
32  , EE102(*new DSM("EE102"))
33 {
34  nTot=0;
35 
36  mJPthr[0]=16;
37  mJPthr[1]=24;
38  mJPthr[2]=30;
39  mJPthr[3]=40;
40  int TPthrSelc = 2;
41  int HTTPthrSelc = 2;
42 
43  //===================== DSM 0 ===============
44  Nee0 = 9;
45  ee0 = new EEdsm0[Nee0];
46  Nee0out = 12;
47  ee0outTPadc = new int [Nee0out];
48  ee0outHTadc = new int [Nee0out];
49 
50  // set pedestals initially to 0
51  ped0 = new int *[Nee0]; // WARN, may be old from 2005 ???, probably not used in the code
52  for (int ibr = 0;ibr < Nee0; ibr++) {
53  ped0[ibr] = new int [ee0[ibr].getNc()];
54  for(int ch = 0;ch < ee0[ibr].getNc();ch++)
55  ped0[ibr][ch]=0;
56  }
57 
58  //===================== DSM 1 ===============
59  Nee1 = 2;
60  ee1 = new EEdsm1[Nee1];
61  for(int i = 0;i < Nee1;i++) ee1[i].setYear(mYear, mJPthr, TPthrSelc, HTTPthrSelc);
62  ee1[0].setType(1);
63  ee1[1].setType(2);
64  ee1out3JPadc = new int [Nee1];
65 
66  //===================== DSM 2 ===============
67  ee2 = new EEdsm2; // Endcap
68  ee2->setYear(mYear);
69 
70  be2 = new EEdsm2[Nbe2];
71  for(int i = 0;i < Nbe2;i++) // Barrel
72  be2[i].setYear(mYear);
73 
74  //===================== DSM 3 ===============
75  ee3 = new EEdsm3;
76  ee3->setYear(mYear);
77 
78  //===================== 2009 L1 DSM =====================
79 
80  // JP E_T = (JP ADC - 5) * 0.236 GeV
81 
82  EE101.registers[0] = EE102.registers[0] = 32; // 6.4 GeV
83  EE101.registers[1] = EE102.registers[1] = 40; // 8.3 GeV
84  EE101.registers[2] = EE102.registers[2] = 60; // 13 GeV
85 
86  clear();
87 }
88 
89 //--------------------------------------------------
90 EEdsmAna::~EEdsmAna() {
91  delete& EE101;
92  delete& EE102;
93 }
94 
95 //--------------------------------------------------
96 void EEdsmAna::clear() {
97 
98  for (int i=0;i<Nee0;i++) if (ee0) ee0[i].clear();
99  for (int i=0;i<Nee0out;i++) { //# boards != # outputs
100  if (ee0outTPadc) ee0outTPadc[i]=0;
101  if (ee0outHTadc) ee0outHTadc[i]=0;
102  }
103 
104  for (int i=0;i<Nee1;i++) { // # boards ==# outputs
105  if (ee1) ee1[i].clear();
106  if (ee1out3JPadc) ee1out3JPadc[i]=0;
107  }
108 
109  memset(ee1outTPthrMax, 0, sizeof(ee1outTPthrMax));
110  memset(ee1outHTTPthrMax, 0, sizeof(ee1outHTTPthrMax));
111 
112  for (int i=0;i<EEnJetPatch;i++) {
113  ee1outJPadc[i]=0;
114  ee1outHT[i]=0;
115  AdjJPsum[i]=0;
116  }
117 
118  for (int i = 0;i < EEnHalf;i++) {
119  ee1outTPthrMax[i] = 0;
120  ee1outHTTPthrMax[i] = 0;
121  }
122 
123  if (ee2) ee2->clear();
124  ee2outHT=0;
125 
126  for (int i=0;i<Nbe2;i++)
127  if (be2) be2[i].clear();
128 
129  if (ee3) ee3->clear();
130 }
131 
132 //--------------------------------------------------
133 void EEdsmAna::initHisto(TObjArray *HList){
134  // .................level-0 input, 2D, HT ..............
135  for(int iJ = 0;iJ < EEnJetPatch;iJ++) {
136  H0inHT[iJ] = new TH2F(Form("dsm0inJP%d_HT", iJ + 1),
137  Form("HT input, DSM layer-0, Jet Patch %d (Steve), trig=%s;input 0-DSM ADC value;Trig Patch ID", iJ + 1, myName),
138  64, -0.5, 63.5, EEnTPinJP, 0.5, EEnTPinJP + 0.5);
139  if (HList) HList->Add(H0inHT[iJ]);
140  }
141 
142  H0inHTall = new TH2F("dsm0inJPall_HT",
143  Form("HT input, DSM layer-0, all trig Patches, trig=%s; Hanks ID=10*brd+inpID", myName),
144  90, -0.5, 89.5, 64, -0.5, 63.5);
145  if (HList) HList->Add(H0inHTall);
146 
147  // ........level-0 input, 2D, TP sum
148  for(int iJ = 0;iJ < EEnJetPatch;iJ++) {
149  H0inTP[iJ] = new TH2F(Form("dsm0inJP%d_TP", iJ + 1),
150  Form("TP input, DSM layer-0, Jet Patch %d (Steve), trig=%s;input to level 0;Trig Patch ID", iJ + 1,myName),
151  64, -0.5, 63.5, EEnTPinJP, 0.5, EEnTPinJP + 0.5);
152  if (HList) HList->Add(H0inTP[iJ]);
153  }
154 
155  H0inTPall = new TH2F("dsm0inJPall_TP", Form("TP input, DSM layer-0, all trig Patches, trig=%s", myName),
156  90, -0.5, 89.5, 64, -0.5, 63.5);
157  if (HList) HList->Add( H0inTPall);
158 
159  // .................level-1 input, 2D
160  //================================ TP
161 
162  for(int iJ = 0;iJ < EEnHalfJetPatch;iJ++) {
163  H1inTPvEmu[iJ] = new TH2F(Form("dsm1HJP%d_TP", iJ + 1),
164  Form("TP input vs. emulated, DSM layer-1, brd=%d ch=%d, trig=%s;emulated TP from level-0;input to level-1", iJ/6, iJ%6, myName),
165  40, 0., 400, 40, 0, 400);
166  if (HList) HList->Add(H1inTPvEmu[iJ]);
167  }
168 
169  //================================ HT
170  for(int iJ = 0;iJ < EEnHalfJetPatch;iJ++) {
171  H1inHTvEmu[iJ] = new TH2F(Form("dsm1HJP%d_HT", iJ + 1),
172  Form("HT input vs.emu, DSM-1, Half Patch %d (Falk), trig=%s;emulated HT from level-0;input to level-1", iJ + 1, myName),
173  64, -0.5, 63.5, 4, -0.5, 3.5);
174  if (HList) HList->Add(H1inHTvEmu[iJ]);
175  }
176 
177  // .................level-2 input
178 
179  //================================ HT
180  for(int iJ = 0;iJ < EEnHalf;iJ++) {
181  H2inHTTP[iJ] = new TH2F(Form("dsm2Half%d_HTTP", iJ + 1),
182  Form("TP (+) HTTP thres, JP_Falk(%d+%d+%d), trig=%s;emu layer1 out: maxTPthr*4 + maxHTTPthr;layer2 inp: TPthr*2 + HTTP",
183  3*iJ, (3*iJ) + 1, (3*iJ) + 2, myName),
184  16, -0.5, 15.5, 4, -0.5, 3.5);
185  if (HList) HList->Add(H2inHTTP[iJ]);
186  }
187 
188  //================================ half Etot sum
189  for(int iJ = 0;iJ < EEnHalf;iJ++) {
190  H1inEtot[iJ] = new TH1F(Form("dsm2Half%d_Etot", iJ + 1),
191  Form("Etot for JP_Falk(%d+%d+%d), trig=%s; level2 input", 3*iJ, (3*iJ) + 1, (3*iJ) + 2, myName),
192  32, -0.5, 31.5);
193  if (HList) HList->Add(H1inEtot[iJ]);
194  }
195 
196  // Total energy histos
197  for(int iJ = 0;iJ < mxEtotBit;iJ++) {
198  HEetot[iJ] = new TH1F(Form("dsm2E_etot%d", iJ),
199  Form("EEMC ETOT BIT=%d, trig=%s; EEMC ETOT emul sum over 1 brd @ level2", iJ, myName),
200  48, 15.5, 63.5);
201  HEetot[iJ]->SetLineColor((iJ == 1) ? kRed : kBlue);
202  if (HList) HList->Add(HEetot[iJ]);
203 
204  HBetot[iJ] = new TH1F(Form("dsm2B_etot%d", iJ),
205  Form("BEMC ETOT BIT=%d, trig=%s; BEMC ETOT emul sum over 3 brds @ level2", iJ, myName),
206  190, 65.5, 255.5);
207  HBetot[iJ]->SetLineColor((iJ == 1) ? kRed : kBlue);
208  if (HList) HList->Add(HBetot[iJ]);
209 
210  HBEetot[iJ] = new TH1F(Form("dsm2BE_etot%d", iJ),
211  Form("B+EEMC ETOT BIT=%d, trig=%s; B+EEMC ETOT emul sum over 4 brds @ level2", iJ, myName),
212  190, 65.5, 255.5);
213  HBEetot[iJ]->SetLineColor((iJ == 1) ? kRed : kBlue);
214  if (HList) HList->Add(HBEetot[iJ]);
215  }
216 
217  // .................level-3 input
218  //================================ HT
219  H3inHTTP = new TH2F("dsm3_HTTP", Form("HTTP layer=3, trig=%s;emu layer2 out: orTPbit*2 + orHTTPbit;layer3 inp: TPbit*2 + HTTPbit", myName),
220  4, -0.5, 3.5, 4, -0.5, 3.5);
221  if (HList) HList->Add(H3inHTTP);
222 
223  //..................Jet Patch sums
224  //=================================summed patch spectra
225  for(int iJ = 0;iJ < EEnJetPatch;iJ++) {
226  int steve_jp = ((iJ + 2) % EEnJetPatch) + 1; //stored by dsm input number 0-5 Want by Steves jp #
227  H4jpSums[iJ] = new TH1F(Form("JP%d_sum", steve_jp),
228  Form("Emulated Sum Jet Patch %d (DSMin %d);Jet Patch Emu Sum;Freq", ((iJ + 2) % EEnJetPatch) + 1, iJ),
229  300, -0.5, 299.5);
230  if (HList) HList->Add(H4jpSums[iJ]);
231  }
232 
233  //=================================Jet patch over threshold
234  static const char* JetPatchSumThresholdTitles[] = {
235  "Jet Patch Sum <= JP0",
236  "JP0 < Jet Patch Sum <= JP1",
237  "JP1 < Jet Patch Sum <= JP2",
238  "Jet Patch Sum > JP2"
239  };
240 
241  for (int iJ = 0;iJ < EEnThresh;iJ++) {
242  TH1F *h = new TH1F(Form("JPsumTh%d", iJ), JetPatchSumThresholdTitles[iJ], 6, 0.5, 6.5);
243  h->GetXaxis()->SetTitle("Steve's Jet Patch ID");
244  h->GetYaxis()->SetTitle("Frequency");
245  h->SetFillColor(kBlue);
246  H4jpFreq[iJ]=h;
247  if (HList) HList->Add(h);
248  }
249 
250  //=================================summed adjacent patch spectra
251  for(int iJ = 0;iJ < EEnJetPatch;iJ++) {
252  int steve_jp = ((iJ + 2) % EEnJetPatch) + 1; //stored by dsm input number 0-5 Want by Steves jp #
253  int steve_jp2 = ((iJ + 3) % EEnJetPatch) + 1;
254  H4adjpSums[iJ] = new TH1F(Form("JP%d%d_sum", steve_jp, steve_jp2),
255  Form("Emulated Sum Jet Patches %d+%d;Jet Patch Emu Sum;Freq", steve_jp, steve_jp2),
256  150, -0.5, 149.5);
257  if (HList) HList->Add(H4adjpSums[iJ]);
258  }
259 
260  //=================================adjacent patch correlation
261  for(int iJ = 0;iJ < EEnJetPatch;iJ++) {
262  int steve_jp = ((iJ + 2) % EEnJetPatch) + 1; //stored by dsm input number 0-5 Want by Steves jp #
263  int steve_jp2 = ((iJ + 3) % EEnJetPatch) + 1;
264  H4adjPcor[iJ] = new TH2F(Form("JP%d%d_cor", steve_jp, steve_jp2),
265  Form("Emulated Sum Jet Patches %d vs %d;Jet Patch %d Sum;Jet Patch %d Sum", steve_jp, steve_jp2, steve_jp, steve_jp2),
266  60, 9.5, 69.5, 60, 9.5,69.5);
267  if (HList) HList->Add(H4adjPcor[iJ]);
268  }
269 
270  { //====================freq summed adjacent patch spectra over thresh
271  H4adjpFreq = new TH1F("JPadjTh", "Adjacent Jet patches both over thr0;DSM Adjacent Jet Patch Emu Sum (FEE crate add 2);Freq",
272  8, -0.5, 7.5);
273  if (HList) HList->Add(H4adjpFreq);
274  }
275 
276  {
277  // added in 2005
278  H5jpPed = new TH2F("JPpedZoom", "Zoom in of 1x1 JP pedestals;Steve's JP ID",
279  EEnJetPatch, 0.5, EEnJetPatch + 0.5, 46, -0.5, 45.5); //2005: Y:40,34.5,74.5
280  if (HList) HList->Add(H5jpPed);
281  }
282 
283  {
284  H5jpFreq = new TH1F("JPtotFreq", Form("JP DSM sum > %d;Steve's JP ID", mJPthr[1]),
285  EEnJetPatch, 0.5, EEnJetPatch + 0.5);
286  H5jpFreq->SetFillColor(kGreen);
287  if (HList) HList->Add(H5jpFreq);
288 
289  H5jpHot = new TH1F("JPpedHot", "Hot towers;Steve's JP ID",
290  EEnJetPatch, 0.5, EEnJetPatch + 0.5);
291  H5jpHot->SetFillColor(kRed); // this histo is updated in presenter - a bit tricky
292  if (HList) HList->Add(H5jpHot); // is _not_ filled by sorter
293  }
294 }
295 
296 //--------------------------------------------------
297 void EEdsmAna::resetHisto(){
298  // .................level-0 input, 2D, HT ..............
299  for(int iJ = 0;iJ < EEnJetPatch;iJ++) {
300  if (H0inHT[iJ]) H0inHT[iJ]->Reset();
301  }
302  if (H0inHTall) H0inHTall->Reset();
303  // ........level-0 input, 2D, TP sum
304  for(int iJ = 0;iJ < EEnJetPatch;iJ++) {
305  if (H0inTP[iJ]) H0inTP[iJ]->Reset();
306  }
307  if (H0inTPall) H0inTPall->Reset();
308 
309  // .................level-1 input, 2D
310  //================================ TP
311  for(int iJ = 0;iJ < EEnHalfJetPatch;iJ++) {
312  if (H1inTPvEmu[iJ]) H1inTPvEmu[iJ]->Reset();
313  }
314  //================================ HT
315  for(int iJ = 0;iJ < EEnHalfJetPatch;iJ++) {
316  if (H1inHTvEmu[iJ]) H1inHTvEmu[iJ]->Reset();
317  }
318 
319  // .................level-2 input
320  //================================ HT
321  for(int iJ = 0;iJ < EEnHalf;iJ++) {
322  if (H2inHTTP[iJ]) H2inHTTP[iJ]->Reset();
323  }
324  //================================ half Etot sum
325  for(int iJ = 0;iJ < EEnHalf;iJ++) {
326  if (H1inEtot[iJ]) H1inEtot[iJ]->Reset();
327  }
328 
329  // Total energy histos
330  for(int iJ = 0;iJ < mxEtotBit;iJ++) {
331  if (HEetot[iJ]) HEetot[iJ]->Reset();
332  if (HBetot[iJ]) HBetot[iJ]->Reset();
333  if (HBEetot[iJ]) HBEetot[iJ]->Reset();
334  }
335 
336  // .................level-3 input
337  //================================ HT
338  if (H3inHTTP) H3inHTTP->Reset();
339 
340  //..................Jet Patch sums
341  //=================================summed patch spectra
342  for(int iJ = 0;iJ < EEnJetPatch;iJ++) {
343  if (H4jpSums[iJ]) H4jpSums[iJ]->Reset();
344  }
345  //=================================Jet patch over threshold
346  for (int iJ = 0;iJ < EEnThresh;iJ++) {
347  if (H4jpFreq[iJ]) H4jpFreq[iJ]->Reset();
348  }
349  //=================================summed adjacent patch spectra
350  for(int iJ = 0;iJ < EEnJetPatch;iJ++) {
351  if (H4adjpSums[iJ]) H4adjpSums[iJ]->Reset();
352  }
353  //=================================adjacent patch correlation
354  for(int iJ = 0;iJ < EEnJetPatch;iJ++) {
355  if (H4adjPcor[iJ]) H4adjPcor[iJ]->Reset();
356  }
357  { //====================freq summed adjacent patch spectra over thresh
358  if (H4adjpFreq) H4adjpFreq->Reset();
359  }
360  {
361  // added in 2005
362  if (H5jpPed) H5jpPed->Reset();
363  }
364  {
365  if (H5jpFreq) H5jpFreq->Reset();
366  if (H5jpHot) H5jpHot->Reset();
367  }
368 }
369 
370 
371 //--------------------------------------------------
372 void EEdsmAna::sort( const unsigned char * dsm0inp,
373  const unsigned short int * dsm1inp,
374  const unsigned short int * dsm2inp,
375  const unsigned short int * dsm3inp) {
376  nTot++;
377 
378  if (dsm0inp) readDsm0(dsm0inp);
379  if (dsm1inp) readDsm1(dsm1inp);
380  if(dsm2inp) readDsm2(dsm2inp);
381  if(dsm3inp) readDsm3(dsm3inp);
382 
383  emulDsm0();
384  emulDsm1();
385  emulDsm2();
386 
387  histoDsm0();
388  histoDsm1();
389  histoDsm2();
390  histoDsm3();
391 
392  return;
393 
394  LOG_DEBUG << "==================================" << endm;
395  printAllEndcap();
396  printAllBarrel();
397 
398 #if 0
399  // test for Steve:
400  int iJ;
401  for(iJ=0;iJ<EEnHalf;iJ++) {
402  if(ee1outTPthrMax[iJ]>=ee1outHTTPthrMax[iJ]) continue;
403  LOG_DEBUG << Form("NEW_EVE==================================\n ee1outTPthrMax[%d]=%d <ee1outHTTPthrMax[%d]=%d\n",iJ,ee1outTPthrMax[iJ],iJ,ee1outHTTPthrMax[iJ]) << endm;
404  goto dump;
405  }
406 #endif
407 
408 }
409 
410 
411 //--------------------------------------------------
412 void EEdsmAna::emulDsm0() {
413  if (ee0) {
414  for (int i = 0;i < EEnTPphi;i++) {
415  for(int j = 0;j < EEnTPeta;j++) {
416  const EEmapTP &y = eeMapTP[i][j];
417  //if (y) {
418  int ibr = y.brdIn - 1;
419  int ch = y.chIn;
420  int chOut = y.chOut;
421  const EEdsm0 &br = ee0[ibr];
422  // ........ TP ..........
423  ee0outTPadc[chOut] += br.getInpTP6bit(ch);
424  //.......... HT ..............
425  int val= br.getInpHT6bit(ch);
426  if(ee0outHTadc[chOut]< val)ee0outHTadc[chOut]=val;
427  //}
428  }
429  }
430  }
431 }
432 
433 //--------------------------------------------------
434 void EEdsmAna::emulDsm1() {
435  switch (mYear) {
436  case 2006:
437  if (ee1) {
438  for (int i=0;i<Nee1;i++) {
439  const EEdsm1 &br = ee1[i]; //Select data for board 1 or 2
440  int maxTPthr=0;
441  int maxHTTPthr=0;
442  for(int j=0;j<br.getNc(); j++) {
443  int ix=j+i*br.getNc();
444  int ijp=ix/2;
445  ee1outJPadc[ijp]+=br.getInpTPsum(j);
446  // Note jet patches are numbered in DSM input order. So ijp=0 is FEE crate 3.
447  ee1out3JPadc[i]+=br.getInpTPsum(j);
448  //int val= br.getHTthr(j);
449  //if(ee1outHT[ijp]< val)ee1outHT[ijp]=val;
450  //if(maxTPthr< br.getTPthr(j)) maxTPthr= br.getTPthr(j);
451  //if(maxHTTPthr< br.getHTTPthr(j)) maxHTTPthr= br.getHTTPthr(j);
452  }
453  ee1outTPthrMax[i] =maxTPthr;
454  ee1outHTTPthrMax[i]=maxHTTPthr;
455  }
456  }
457  //Add some further processing to check jet patch sums for passing thresholds
458  //and form adjacent patch sums.
459  for (int i=0;i<EEnJetPatch;i++) {
460  AdjJPsum[i]=ee1outJPadc[i]+ee1outJPadc[(i+1)%EEnJetPatch]; //sum adj patches
461  }
462  break;
463 
464  case 2009:
465  DSMAlgo_EE101_2009()(EE101);
466  DSMAlgo_EE102_2009()(EE102);
467 
468  // Get jet patch sums
469 
470  ee1outJPadc[0] = EE102.info[0];
471  ee1outJPadc[1] = EE102.info[1];
472  ee1outJPadc[2] = EE102.info[2];
473 
474  ee1outJPadc[3] = EE101.info[0];
475  ee1outJPadc[4] = EE101.info[1];
476  ee1outJPadc[5] = EE101.info[2];
477 
478  // Calculate adjacent jet patch sums
479 
480  for (int jp = 0; jp < 6; ++jp)
481  AdjJPsum[jp] = ee1outJPadc[jp] + ee1outJPadc[(jp+1)%6];
482 
483  break;
484  }
485 }
486 
487 //--------------------------------------------------
488 void EEdsmAna::emulDsm2() {
489  if (ee2) {
490  ee2outHT=ee2->get3JPHTthr(0);
491  if(ee2outHT<ee2->get3JPHTthr(1))ee2outHT=ee2->get3JPHTthr(1);
492  }
493 }
494 
495 //--------------------------------------------------
496 void EEdsmAna::readDsm0(const unsigned char *EEMC) {
497  /*Gets level 0 DSM inputs and reorders them. They
498  are stored 7 -> 0 followed by 15 -> 8. Output is
499  ordered as physically input to boards, 0 -> 15.
500  */
501  if (EEMC && ee0) {
502  //--------------------- initialize input to DSM level-0
503  for(int ibr = 0;ibr < Nee0;ibr++) { // index, boards ID= ibr+1
504  int k = 16 * ibr; // begin of data for given board
505  // fill in lower 8 words [ 0,1...,7]
506  for(int i = 0;i < 8;i++) ee0[ibr].setBite(7 - i, EEMC[k + i]);
507  // fill in higher 8 words [8,9,....,15]
508  for(int i = 8;i < 16;i++) ee0[ibr].setBite(23 - i, EEMC[k + i]);
509  ee0[ibr].unpack();
510  }
511  }
512 }
513 
514 //--------------------------------------------------
515 void EEdsmAna::readDsm1(const unsigned short *EEMC_l1) {
516  /* Gets level 1 DSM inputs (output of level 0) and
517  reorders them. They are stored 3 ->0 followed by
518  7 -> 4 followed by 11 -> 8 and 15 -> 12. Only 0-5
519  and 8-13 are used, the first group for the first
520  board. Output is ordered as physically input to
521  the board. For first board the order is crate 3,
522  4 then 5, and for second board crate 6, 1 then 2.
523  */
524 
525  switch (mYear) {
526  case 20006:
527  if (EEMC_l1 && ee1) {
528  for(int i = 0;i < Nee1;i++) {
529  ee1[i].setWord(0, EEMC_l1[3 + i*8]);
530  ee1[i].setWord(1, EEMC_l1[2 + i*8]);
531  ee1[i].setWord(2, EEMC_l1[1 + i*8]);
532  ee1[i].setWord(3, EEMC_l1[0 + i*8]);
533  ee1[i].setWord(4, EEMC_l1[7 + i*8]);
534  ee1[i].setWord(5, EEMC_l1[6 + i*8]);
535  }
536  }
537  break;
538 
539  case 2009:
540  if (EEMC_l1) {
541  EE101.channels[0] = EEMC_l1[3];
542  EE101.channels[1] = EEMC_l1[2];
543  EE101.channels[2] = EEMC_l1[1];
544  EE101.channels[3] = EEMC_l1[0];
545  EE101.channels[4] = EEMC_l1[7];
546  EE101.channels[5] = EEMC_l1[6];
547  EE101.channels[6] = EEMC_l1[5];
548  EE101.channels[7] = EEMC_l1[4];
549 
550  EE102.channels[0] = EEMC_l1[11];
551  EE102.channels[1] = EEMC_l1[10];
552  EE102.channels[2] = EEMC_l1[ 9];
553  EE102.channels[3] = EEMC_l1[ 8];
554  EE102.channels[4] = EEMC_l1[15];
555  EE102.channels[5] = EEMC_l1[14];
556  EE102.channels[6] = EEMC_l1[13];
557  EE102.channels[7] = EEMC_l1[12];
558  }
559  break;
560  }
561 }
562 
563 //--------------------------------------------------
564 void EEdsmAna::readDsm2(const unsigned short *EMC) {
565  if (EMC && ee2 && be2) {
566  //Endcap
567  ee2->setWord(0, EMC[5]);
568  ee2->setWord(1, EMC[4]);
569  //Barrel
570  be2[0].setWord(0, EMC[3]);
571  be2[0].setWord(1, EMC[2]);
572  be2[1].setWord(0, EMC[1]);
573  be2[1].setWord(1, EMC[0]);
574  be2[2].setWord(0, EMC[7]);
575  be2[2].setWord(1, EMC[6]);
576  }
577 }
578 
579 //--------------------------------------------------
580 void EEdsmAna::readDsm3( const unsigned short *lastDSM) {
581  if (lastDSM && ee3) {
582  ee3->setWord(0, lastDSM[0]);
583  }
584 }
585 
586 //--------------------------------------------------
587 void EEdsmAna::histoDsm0() {
588  if (ee0) {
589  for(int i = 0;i < EEnTPphi;i++) {
590  for(int j = 0;j < EEnTPeta;j++) {
591  const EEmapTP &y = eeMapTP[i][j];
592  //if (y) {
593  int ibr = y.brdIn - 1;
594  int ch = y.chIn;
595  int iJP = y.JPid - 1;
596  if ((iJP >= 0) && (iJP < EEnJetPatch)) {
597  H0inHT[iJP]->Fill(ee0[ibr].getInpHT6bit(ch), y.TPid);
598  H0inTP[iJP]->Fill(ee0[ibr].getInpTP6bit(ch), y.TPid);
599  H0inHTall->Fill((10 * ibr) + ch, ee0[ibr].getInpHT6bit(ch));
600  H0inTPall->Fill((10 * ibr) + ch, ee0[ibr].getInpTP6bit(ch));
601  }
602  //}
603  }
604  }
605  }
606 }
607 
608 //--------------------------------------------------
609 void EEdsmAna::histoDsm1(){
610  switch (mYear) {
611  case 2006:
612  if (ee1) {
613  for (int i = 0;i < Nee1;i++) {
614  const EEdsm1 &br = ee1[i];
615  //if (br) {
616  for(int j = 0;j < br.getNc();j++) {
617  int ix = j + (i * br.getNc());
618  // .... TP ..................
619  H1inTPvEmu[ix]->Fill(ee0outTPadc[ix], br.getInpTPsum(j));
620  //..... HT ............
621  //H1inHTvEmu[ix]->Fill(ee0outHTadc[ix], br.getHTthr(j));
622  }
623  //}
624  }
625  }
626 
627  /* 2006
628  6) For the upper 4 plots ( H4jpFreq[i]), change the JP sum cuts to:
629  JP sum > 16
630  JP sum in range [24,29]
631  JP sum in range [30,39]
632  JP sum > 40
633  */
634 
635  for (int i = 0;i < EEnJetPatch;i++) { //histos for jet patch sums
636  int steve_jp = ((i + 2) % EEnJetPatch) + 1; //stored by dsm input number 0-5 Want by Steves jp #
637  H4jpSums[i]->Fill(ee1outJPadc[i]);
638  int JPene = ee1outJPadc[i];
639  if(JPene > mJPthr[0]) H4jpFreq[0]->Fill(steve_jp);
640  if(JPene > mJPthr[3]) H4jpFreq[3]->Fill(steve_jp);
641  else if(JPene > mJPthr[2]) H4jpFreq[2]->Fill(steve_jp);
642  else if(JPene > mJPthr[1]) H4jpFreq[1]->Fill(steve_jp);
643 
644  H5jpPed->Fill(steve_jp, ee1outJPadc[i]);
645  if (ee1outJPadc[i] > mJPthr[1]) H5jpFreq->Fill(steve_jp);
646  int j = (i + 1) % EEnJetPatch;
647  H4adjPcor[i]->Fill(ee1outJPadc[i], ee1outJPadc[j]);
648  H4adjpSums[i]->Fill(AdjJPsum[i]);
649 
650  if ((ee1outJPadc[i] > mJPthr[1]) && (ee1outJPadc[(i + 1) % EEnJetPatch] > mJPthr[1])) H4adjpFreq->Fill(steve_jp);
651  }
652  break;
653 
654  case 2009:
655  // The jet patch numbering scheme (0-5) follows that in the West Barrel:
656  // JP0: 150 degrees (Steve's Jet Patch 6/FEE Crate 6)
657  // JP1: 90 degrees (Steve's Jet Patch 1/FEE Crate 1)
658  // JP2: 30 degrees (Steve's Jet Patch 2/FEE Crate 2)
659  // JP3: -30 degrees (Steve's Jet Patch 3/FEE Crate 3)
660  // JP4: -90 degrees (Steve's Jet Patch 4/FEE Crate 4)
661  // JP5: -150 degrees (Steve's Jet Patch 5/FEE Crate 5)
662  // See http://www.iucf.indiana.edu/U/STAR/eemc_proj/electr_trig_daq/eemc_trigger_patches_annotated.pdf
663 
664  static const int steve_jp[] = { 6, 1, 2, 3, 4, 5 };
665 
666  for (int jp = 0; jp < 6; ++jp) {
667  H4jpSums[jp]->Fill(ee1outJPadc[jp]);
668 
669  // JP threshold histogram indexes:
670  // 0 = ADC <= JP0
671  // 1 = JP0 < ADC <= JP1
672  // 2 = JP1 < ADC <= JP2
673  // 3 = JP2 < ADC
674 
675  if (ee1outJPadc[jp] <= EE101.registers[0])
676  H4jpFreq[0]->Fill(steve_jp[jp]);
677  else if (ee1outJPadc[jp] > EE101.registers[0] && ee1outJPadc[jp] <= EE101.registers[1])
678  H4jpFreq[1]->Fill(steve_jp[jp]);
679  else if (ee1outJPadc[jp] > EE101.registers[1] && ee1outJPadc[jp] <= EE101.registers[2])
680  H4jpFreq[2]->Fill(steve_jp[jp]);
681  else if (ee1outJPadc[jp] > EE101.registers[2])
682  H4jpFreq[3]->Fill(steve_jp[jp]);
683 
684  H5jpPed->Fill(steve_jp[jp], ee1outJPadc[jp]);
685  if (ee1outJPadc[jp] > EE101.registers[1]) H5jpFreq->Fill(steve_jp[jp]); // JP1 threshold
686 
687  H4adjPcor[jp]->Fill(ee1outJPadc[jp], ee1outJPadc[(jp+1)%6]);
688  H4adjpSums[jp]->Fill(AdjJPsum[jp]);
689  }
690  break;
691  }
692 }
693 
694 //--------------------------------------------------
695 void EEdsmAna::histoDsm2() {
696  if (ee2) {
697  //------------ HT ---------------
698  /*for (int iJ = 0;iJ < EEnHalf;iJ++) {
699  int max = 0;
700  for(int i = 3 * iJ;i < ((3 * iJ) + 3);i++) {
701  if (max < ee1outHT[i]) max = ee1outHT[i];
702  }
703  }*/
704 
705  //------------ TP & HTTP since 2006 ---------------
706  /*
707  4) The upper 2 plots need to be completely redefined. The result will be interpretable by me
708  and probably by few others until I train them, but it's not easy to do better unless we have
709  access to the register values that tell DSM exactly which thresholds we are choosing from TP
710  and HT x TP bits. We want to change both histograms to be 16 channels in x by 4 channels in y.
711  The left-hand plot should still deal with the layer 1 DSM that Falk labels for JP
712  0+1+2, and the right-hand plot for JP3+4+5.
713 
714  To form the 4-bit word for x in each of the above histograms, do the following:
715  a) loop over the 6 inputs to the layer 1 DSM and extract bits 12-13; place the highest of
716  these 6 2-bit values into the upper 2 bits of the address for x.
717  b) repeat (a), but now for bits 14-15 of the 6 inputs; place the highest of these 6 2-bit
718  values into the lower 2 bits of the 4-bit address for x.
719  x thus measures: (TP bits for highest threshold passed)*4 + (HTxTP bits for highest threshold
720  passed)
721 
722  For the y-value in these histograms, form a 2-bit word with bit 1=bit 9 of the corresponding
723  layer 2 DSM input word bit 0=bit 7 of the corresponding layer 2 DSM input word (all bits
724  numbered starting from 0).
725  y thus measures: (selected TP threshold passed?Y or N)*2
726  +(selected HT x TP threshold passed?Y or N)
727 
728  */
729 
730  for(int iJ = 0;iJ < EEnHalf;iJ++) {
731  int x = (ee1outTPthrMax[iJ] * 4) + ee1outHTTPthrMax[iJ];
732  int y = (ee2->getTPthr(iJ) * 2) + ee2->getHTTPthr(iJ);
733  H2inHTTP[iJ]->Fill(x,y);
734  }
735 
736  /* in 2006+
737  2 1D plots, one for each layer 1 DSM (i.e., Falk JP0+1+2 and Falk JP3+4+5).
738  The x-axis should be 32 channels and represent the value extracted from bits 0-4 of
739  the corresponding EEMC input to the layer 2 DSM. The plots should be labeled:
740  ETOT FOR JP0+1+2 and ETOT FOR JP3+4+5.
741  */
742 
743  for (int iJ = 0;iJ < EEnHalf;iJ++) H1inEtot[iJ]->Fill(ee2->get3JPsum(iJ));
744  }
745 
746  if (ee3) {
747  //Total energy histos
748  /*
749  64 channels x by 2 channels y :
750  x-axis (label EEMC ETOT emulated) ; value = sum over
751  2 EEMC inputs to layer 2 DSM the values in bits 0-4 for each input.
752 
753  y-axis (label EEMC ETOT BIT): value = bit 11 of layer
754  2 DSM output (or of TCU input).
755  */
756  unsigned short sumE = ee2->get3JPsum(0) + ee2->get3JPsum(1);
757  HEetot[ee3->getEndcapEsumthr1bit()]->Fill(sumE);
758 
759  //BARREL histos 2006
760  /*
761  256 channels x by 2 channels y:
762  x-axis (label BEMC ETOT emulated) ; value = sum over
763  6 BEMC inputs to layer 2 DSM the values in bits 0-4 for each input.
764 
765  y-axis (label BEMC ETOT BIT): value = bit 4 of layer
766  2 DSM output (or of TCU input).
767  */
768  unsigned short sumB = 0;
769  for(int i = 0;i < Nbe2;i++) {
770  sumB += be2[i].get3JPsum(0);
771  sumB += be2[i].get3JPsum(1);
772  }
773  HBetot[ee3->getBarreEsumThr1bit()]->Fill(sumB);
774 
775  /*
776  256 channels x by 2 channels y:
777  x-axis (label B+EEMC ETOT emulated) ; value = sum over
778  6 BEMC+2 EEMC inputs to layer 2 DSM the values in bits 0-4 for each input.
779 
780  y-axis (label B+EEMC ETOT BIT): value = bit 15 of layer
781  2 DSM output (or of TCU input).
782  */
783 
784  HBEetot[ee3->getEtotThr1bit()]->Fill(sumB + sumE);
785  }
786 }
787 
788 //--------------------------------------------------
789 void EEdsmAna::histoDsm3() {
790  if (ee3) {
791 /*
792  The plot should be replaced with a 4 x 4 histo:
793 x-axis = 2-bit word constructed from:
794 bit 0=OR of bit 7 on two EEMC inputs to layer 2 DSM bit 1=OR of bit 9 on two EEMC inputs to layer 2 DSM y-axis = 2-bit word constructed from:
795 bit 0=bit 12 of layer 2 DSM output (or TCU input) bit 1=bit 14 of layer 2 DSM output (or TCU input)
796 
797 This histogram should have the "normal" appearance of a diagonal band; the x-axis is the emulated TP and HT x TP inputs to layer 2, and the y-axis is the actual output from layer 2.
798 
799  */
800  bool x_b0 = ee1outTPthrMax[0] || ee1outTPthrMax[1];
801  bool x_b1 = ee1outHTTPthrMax[0] || ee1outHTTPthrMax[1];
802  int x = (x_b1 * 2) + x_b0;
803  int y = (ee3->getEndcapHTTPthr1bit() * 2) +ee3->getEndcapTPthr1bit();
804  H3inHTTP->Fill(x, y);
805  }
806 }
807 
808 //--------------------------------------------------
809 void EEdsmAna::printDsm0map() const {
810  printf("TP Map level-0 \n ");
811  for(int j=0;j< EEnTPeta;j++)
812  printf(" iEta=%d ",j);
813  printf("\n ");
814  for(int j=0;j< EEnTPeta;j++)
815  printf("JP/TP brd:ch->outCh ");
816  for(int i=0;i<EEnTPphi; i++) {
817  int phi=111-i*12;
818  if(phi<0) phi+=360;
819  printf("\nPhi/deg=%3d ",phi);
820  for(int j=0;j< EEnTPeta;j++) {
821  EEmapTP *y=&eeMapTP[i][j];
822  printf("%d/%2d %2d:%2d -> %2d ",y->JPid,y->TPid,y->brdIn,y->chIn,y->chOut);
823  }
824  }
825  printf("\n");
826 }
827 
828 //--------------------------------------------------
829 void EEdsmAna::printAllEndcap(int k) const {
830  printf("\n\nEEdsmAna(%s)::print(eve=%d) , year=%d \n",myName,nTot,mYear);
831  for(int i=0;i<Nee0;i++) {
832  printf("\n----------- level-0 Board %2d ",i+1);
833  ee0[i].print();
834  }
835  printf("\n----------- level-0 emulated output \n ch =");
836  for(int i=Nee0out-1;i>=0; i--) printf(" %4d ",i);
837  printf("\n TP =");
838  for(int i=Nee0out-1;i>=0; i--) printf(" %4d ",ee0outTPadc[i]);
839  printf("\nHTadc =");
840  for(int i=Nee0out-1;i>=0; i--) printf(" %4d ",ee0outHTadc[i]);
841  printf("\n\n----------- level-1 -----------------\n ");
842  for(int i=0;i<Nee1;i++) {
843  printf("\n----------- level-1 Board %2d , ",i+1);
844  ee1[i].print();
845  printf("emul out 3x.9 JP_Falk(%d+%d+%d) energy/dec: 13bit=%d 8bit=%d mxTPthr=%d mxHTTPthr=%d\n",3*i,3*i+1,3*i+2,ee1out3JPadc[i],ee1out3JPadc[i]>>5, ee1outTPthrMax[i], ee1outHTTPthrMax[i]);
846  }
847  printf("\n----------- level-1 emulated output \n JP_Falk =");
848  int Njp=EEnJetPatch;
849  for(int i=Njp-1;i>=0; i--) printf(" %4d ",i);
850  printf("\n JP_Steve=");
851  for(int i=Njp-1;i>=0; i--) printf(" %4d ",(i+2)%6+1);
852  printf("\n JPsum =");
853  for(int i=Njp-1;i>=0; i--) printf(" %4d ",ee1outJPadc[i]);
854  printf("\n HTthr =");
855  for(int i=Njp-1;i>=0; i--) printf(" %4d ",ee1outHT[i]);
856  if(mYear<2006) {
857  printf("\n AdjJPsum=");
858  for(int i=Njp-1;i>=0; i--) printf(" %4d ",AdjJPsum[i]);
859  }
860  printf("\n");
861  printf("emul: orTPbit=%d orHTTPbit=%d \n",ee1outTPthrMax[0]||ee1outTPthrMax[1], ee1outHTTPthrMax[0] ||ee1outHTTPthrMax[1]);
862  printf("\n\n----------- level-2 ----------------- \n");
863  ee2->print();
864  printf("\n\n----------- level-3 ( aka TCU) ----------- \n");
865  ee3->print();
866 }
867 
868 //--------------------------------------------------
869 void EEdsmAna::printAllBarrel(int k) const {
870  printf("\n\nBEdsmAna(%s)::print(eve=%d) , year=%d \n",myName,nTot,mYear);
871  for(int i=0;i<Nbe2;i++) {
872  printf("\n----------- level-2 BARREL Board %2d ",i+1);
873  be2[i].print();
874  }
875  printf("\n\n");
876 }
877 
878 //--------------------------------------------------
879 void EEdsmAna::usePed(const Char_t *fName){
880  //......................... load ped for L-0
881  LOG_INFO << "EEdsmAna(" << myName << ") reads pedestals from " << fName << endm;
882  FILE *fd = fopen(fName, "r");
883  if (fd) {
884  for (Int_t ibr = 0;ibr < Nee0;ibr++) {
885  for (Int_t ch = 0;ch < ee0[ibr].getNc();ch++) {
886  int a = 0, b = 0, c = 0;
887  int ret = fscanf(fd, "%d %d %d", &a, &b, &c);
888  if ((ret == 3) && (a == (ibr + 1)) && (b == ch)) {
889  ped0[ibr][ch] = c;
890  } else {
891  LOG_ERROR << "Bad file format " << fName << ": got ret=" << ret << ", a=" << a << ", b=" << b << ", c=" << c << endm;
892  }
893  }
894  }
895  fclose(fd);
896  fd = 0;
897  } else {
898  LOG_ERROR << "Cannot read file " << fName << endm;
899  }
900 }
901 
902 void EEdsmAna::saveHisto(TFile *f) const {
903  if (f) f->cd();
904 
905 
906  // .................level-0 input, 2D, HT ..............
907  for(int iJ = 0;iJ < EEnJetPatch;iJ++) {
908  if (H0inHT[iJ]) H0inHT[iJ]->Write();
909  }
910 
911  if (H0inHTall) H0inHTall->Write();
912 
913  // ........level-0 input, 2D, TP sum
914  for(int iJ = 0;iJ < EEnJetPatch;iJ++) {
915  if (H0inTP[iJ]) H0inTP[iJ]->Write();
916  }
917 
918  if (H0inTPall) H0inTPall->Write();
919 
920  // .................level-1 input, 2D
921  //================================ TP
922 
923  for(int iJ = 0;iJ < EEnHalfJetPatch;iJ++) {
924  if (H1inTPvEmu[iJ]) H1inTPvEmu[iJ]->Write();
925  }
926 
927  //================================ HT
928  for(int iJ = 0;iJ < EEnHalfJetPatch;iJ++) {
929  if (H1inHTvEmu[iJ]) H1inHTvEmu[iJ]->Write();
930  }
931 
932  // .................level-2 input
933 
934  //================================ HT
935  for(int iJ = 0;iJ < EEnHalf;iJ++) {
936  if (H2inHTTP[iJ]) H2inHTTP[iJ]->Write();
937  }
938 
939  //================================ half Etot sum
940  for(int iJ = 0;iJ < EEnHalf;iJ++) {
941  if (H1inEtot[iJ]) H1inEtot[iJ]->Write();
942  }
943 
944  // Total energy histos
945  for(int iJ = 0;iJ < mxEtotBit;iJ++) {
946  if (HEetot[iJ]) HEetot[iJ]->Write();
947 
948  if (HBetot[iJ]) HBetot[iJ]->Write();
949 
950  if (HBEetot[iJ]) HBEetot[iJ]->Write();
951  }
952 
953  // .................level-3 input
954  //================================ HT
955  if (H3inHTTP) H3inHTTP->Write();
956 
957  //..................Jet Patch sums
958  //=================================summed patch spectra
959  for(int iJ = 0;iJ < EEnJetPatch;iJ++) {
960  if (H4jpSums[iJ]) H4jpSums[iJ]->Write();
961  }
962 
963  //=================================Jet patch over threshold
964  for (int iJ = 0;iJ < EEnThresh;iJ++) {
965  if (H4jpFreq[iJ]) H4jpFreq[iJ]->Write();
966  }
967 
968  //=================================summed adjacent patch spectra
969  for(int iJ = 0;iJ < EEnJetPatch;iJ++) {
970  if (H4adjpSums[iJ]) H4adjpSums[iJ]->Write();
971  }
972 
973  //=================================adjacent patch correlation
974  for(int iJ = 0;iJ < EEnJetPatch;iJ++) {
975  if (H4adjPcor[iJ]) H4adjPcor[iJ]->Write();
976  }
977 
978  { //====================freq summed adjacent patch spectra over thresh
979  if (H4adjpFreq) H4adjpFreq->Write();
980  }
981 
982  {
983  // added in 2005
984  if (H5jpPed) H5jpPed->Write();
985  }
986 
987  {
988  if (H5jpFreq) H5jpFreq->Write();
989 
990  if (H5jpHot) H5jpHot->Write(); // is _not_ filled by sorter
991  }
992 }
993 
Definition: EEdsm0.h:10
Definition: EEdsm3.h:7
Definition: EEdsm1.h:8
Definition: DSM.hh:16
Definition: EEdsm2.h:7