Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ZdcMon.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file ZdcMon.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 "ZdcMon.h"
7 
8 #include <onlmon/OnlMon.h> // for OnlMon
9 #include <onlmon/OnlMonDB.h>
10 #include <onlmon/OnlMonServer.h>
11 
12 #include <Event/msg_profile.h>
13 #include <calobase/TowerInfoDefs.h>
14 #include <caloreco/CaloWaveformFitting.h>
15 
16 #include <Event/Event.h>
17 #include <Event/EventTypes.h>
18 #include <Event/msg_profile.h>
19 
20 
21 #include <TH1.h>
22 #include <TH2.h>
23 #include <TRandom.h>
24 
25 #include <cmath>
26 #include <cstdio> // for printf
27 #include <fstream>
28 #include <iostream>
29 #include <sstream>
30 #include <string> // for allocator, string, char_traits
31 
32 enum
33 {
36 };
37 
39  : OnlMon(name)
40 {
41  // leave ctor fairly empty, its hard to debug if code crashes already
42  // during a new ZdcMon()
43  return;
44 }
45 
47 {
48  // you can delete NULL pointers it results in a NOOP (No Operation)
49  return;
50 }
51 
53 {
54  const float MAX_ENERGY1 = 15000.;
55  const float MAX_ENERGY2 = 15000.;
56  const int BIN_NUMBER = 1500;
57 
58 // gRandom->SetSeed(rand());
59  // read our calibrations from ZdcMonData.dat
60  const char *zdccalib = getenv("ZDCCALIB");
61  if (!zdccalib)
62  {
63  std::cout << "ZDCCALIB environment variable not set" << std::endl;
64  exit(1);
65  }
66  std::string fullfile = std::string(zdccalib) + "/" + "ZdcMonData.dat";
67  std::ifstream calib(fullfile);
68  calib.close();
69  // use printf for stuff which should go the screen but not into the message
70  // system (all couts are redirected)
71  printf("doing the Init\n");
72 
73  zdc_adc_north = new TH1F("zdc_adc_north", "ZDC ADC north", BIN_NUMBER, 0, MAX_ENERGY1);
74  zdc_adc_south = new TH1F("zdc_adc_south", "ZDC ADC south", BIN_NUMBER, 0, MAX_ENERGY2);
75 
77  //register histograms with server otherwise client won't get them
78  se->registerHisto(this, zdc_adc_north );
79  se->registerHisto(this, zdc_adc_south );
80 
82 
83  Reset();
84  return 0;
85 }
86 
87 int ZdcMon::BeginRun(const int /* runno */)
88 {
89  // if you need to read calibrations on a run by run basis
90  // this is the place to do it
91  return 0;
92 }
93 
94 std::vector<float> ZdcMon::anaWaveformFast(Packet *p, const int channel)
95 {
96  std::vector<float> waveform;
97  for (int s = 0; s < p->iValue(0, "SAMPLES"); s++)
98  {
99  waveform.push_back(p->iValue(s, channel));
100  }
101  std::vector<std::vector<float>> multiple_wfs;
102  multiple_wfs.push_back(waveform);
103 
104  std::vector<std::vector<float>> fitresults_zdc;
105  fitresults_zdc = WaveformProcessingFast->calo_processing_fast(multiple_wfs);
106 
107  std::vector<float> result;
108  result = fitresults_zdc.at(0);
109  return result;
110 
111 }
112 
113 
115 {
116  evtcnt++;
117 
118  float totalzdcsouthsignal = 0.;
119  float totalzdcnorthsignal = 0.;
120  int packet = 12001;
121 
122  Packet *p = e->getPacket(packet);
123  if (p)
124  {
125 
126  for (int c = 0; c < p->iValue(0, "CHANNELS"); c++)
127  {
128  std::vector<float> resultFast = anaWaveformFast(p, c); // fast waveform fitting
129  float signalFast = resultFast.at(0);
130  float signal = signalFast;
131 
132  unsigned int towerkey = TowerInfoDefs::decode_zdc(c);
133  int zdc_side = TowerInfoDefs::get_zdc_side(towerkey);
134 
135  int mod = c%2;
136  if (mod != 0) continue;
137  if((c < 16) && ((c != 6) && (c != 14)))
138  {
139  if (zdc_side == 0)
140  {
141  totalzdcsouthsignal+= signal;
142  }
143  else if (zdc_side == 1)
144  {
145  totalzdcnorthsignal+= signal;
146  }
147  else
148  {
149  std::cout << "arm bin not assigned ... " << std::endl;
150  return -1;
151  }
152  } //select zdc high gain channels only
153  } // channel loop end
154  } // if packet good
155 
156  zdc_adc_south->Fill(totalzdcsouthsignal);
157  zdc_adc_north->Fill(totalzdcnorthsignal);
158 
159  delete p;
160 
161  return 0;
162 }
163 
165 {
166  // reset our internal counters
167  evtcnt = 0;
168  idummy = 0;
169  return 0;
170 }
171