Analysis Software
Documentation for sPHENIX simulation software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Proto4ShowerCalib.C
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Proto4ShowerCalib.C
1 #include "Proto4ShowerCalib.h"
2 
3 #include <calobase/RawTowerContainer.h>
5 #include <pdbcalbase/PdbParameterMap.h>
6 #include <phparameter/PHParameters.h>
7 #include <prototype4/RawTower_Prototype4.h>
8 #include <prototype4/RawTower_Temperature.h>
9 
10 #include <Event/EventTypes.h>
13 #include <fun4all/Fun4AllServer.h>
14 #include <fun4all/PHTFileServer.h>
15 #include <fun4all/SubsysReco.h>
16 #include <phool/PHCompositeNode.h>
17 #include <phool/getClass.h>
18 
19 #include <phool/PHCompositeNode.h>
20 
21 #include <g4main/PHG4Particle.h>
23 #include <g4main/PHG4VtxPoint.h>
24 
25 #include <TFile.h>
26 #include <TH1F.h>
27 #include <TH2F.h>
28 #include <TLorentzVector.h>
29 #include <TNtuple.h>
30 #include <TVector3.h>
31 #include <TChain.h>
32 
33 #include <algorithm>
34 #include <cassert>
35 #include <cmath>
36 #include <exception>
37 #include <iostream>
38 #include <set>
39 #include <sstream>
40 #include <stdexcept>
41 #include <vector>
42 
43 using namespace std;
44 
47 
49  : SubsysReco("Proto4ShowerCalib")
50  , _is_sim(false)
51  , _filename(filename)
52  , _ievent(0)
53 {
54  Verbosity(1);
55 
56  _eval_run.reset();
57  _tower.reset();
58 
59  _mInPut_flag = 1;
60  _mStartEvent = -1;
61  _mStopEvent = -1;
62 
64  _mRunID = "0422";
65 }
66 
68 {
69 }
70 
73 {
75  Fun4AllHistoManager *hm = se->getHistoManager("Proto4ShowerCalib_HISTOS");
76 
77  if (not hm)
78  {
79  cout
80  << "Proto4ShowerCalib::get_HistoManager - Making Fun4AllHistoManager Proto4ShowerCalib_HISTOS"
81  << endl;
82  hm = new Fun4AllHistoManager("Proto4ShowerCalib_HISTOS");
83  se->registerHistoManager(hm);
84  }
85 
86  assert(hm);
87 
88  return hm;
89 }
90 
92 {
93  if (Verbosity())
94  cout << "Proto4ShowerCalib::InitRun" << endl;
95 
96  _ievent = 0;
97 
98  PHNodeIterator iter(topNode);
99  PHCompositeNode *dstNode = static_cast<PHCompositeNode *>(iter.findFirst(
100  "PHCompositeNode", "DST"));
101  if (!dstNode)
102  {
103  std::cerr << PHWHERE << "DST Node missing, doing nothing." << std::endl;
104  throw runtime_error(
105  "Failed to find DST node in EmcRawTowerBuilder::CreateNodes");
106  }
107 
109 }
110 
112 {
113  cout << "Proto4ShowerCalib::End - write to " << _filename << endl;
115 
117  assert(hm);
118  for (unsigned int i = 0; i < hm->nHistos(); i++)
119  hm->getHisto(i)->Write();
120 
121  // if (_T_EMCalTrk)
122  // _T_EMCalTrk->Write();
123 
125 }
126 
128 {
129  _ievent = 0;
130 
131  cout << "Proto4ShowerCalib::get_HistoManager - Making PHTFileServer "
132  << _filename << endl;
133  PHTFileServer::get().open(_filename, "RECREATE");
134 
136  assert(hm);
137 
139  TH2F *hCheck_Cherenkov = new TH2F("hCheck_Cherenkov", "hCheck_Cherenkov",
140  110, -200, 20000, 5, .5, 5.5);
141  hCheck_Cherenkov->GetYaxis()->SetBinLabel(1, "C1");
142  hCheck_Cherenkov->GetYaxis()->SetBinLabel(2, "C2 in");
143  hCheck_Cherenkov->GetYaxis()->SetBinLabel(3, "C2 out");
144  hCheck_Cherenkov->GetYaxis()->SetBinLabel(4, "C2 sum");
145  hCheck_Cherenkov->GetXaxis()->SetTitle("Amplitude");
146  hCheck_Cherenkov->GetYaxis()->SetTitle("Cherenkov Channel");
147  hm->registerHisto(hCheck_Cherenkov);
148 
150  TH1F *hNormalization = new TH1F("hNormalization", "hNormalization", 10, .5,
151  10.5);
152  hNormalization->GetXaxis()->SetBinLabel(1, "ALL");
153  hNormalization->GetXaxis()->SetBinLabel(2, "C2-e");
154  hNormalization->GetXaxis()->SetBinLabel(3, "trigger_veto_pass");
155  hNormalization->GetXaxis()->SetBinLabel(4, "valid_hodo_h");
156  hNormalization->GetXaxis()->SetBinLabel(5, "valid_hodo_v");
157  hNormalization->GetXaxis()->SetBinLabel(6, "good_e");
158  hNormalization->GetXaxis()->SetBinLabel(7, "good_anti_e");
159  hNormalization->GetXaxis()->SetTitle("Cuts");
160  hNormalization->GetYaxis()->SetTitle("Event count");
161  hm->registerHisto(hNormalization);
162 
163  hm->registerHisto(new TH1F("hCheck_Veto", "hCheck_Veto", 1000, -500, 1500));
164  hm->registerHisto(
165  new TH1F("hCheck_Hodo_H", "hCheck_Hodo_H", 1000, -500, 1500));
166  hm->registerHisto(
167  new TH1F("hCheck_Hodo_V", "hCheck_Hodo_V", 1000, -500, 1500));
168 
169  hm->registerHisto(new TH1F("hBeam_Mom", "hBeam_Mom", 1200, -120, 120));
170 
171  float histo_range = find_range();
172  // cout << "histo_range = " << histo_range << endl;
173  // float histo_range = 49.5;
174 
175  // SIM HCALIN/HCALOUT
176  if(_is_sim)
177  {
178  TH1F *h_hcalin_tower_sim[16];
179  TH1F *h_hcalout_tower_sim[16];
180  for(int i_tower = 0; i_tower < 16; ++i_tower)
181  {
182  string HistName_sim;
183  HistName_sim = Form("h_hcalin_tower_%d_sim",i_tower);
184  // h_hcalin_tower_sim[i_tower] = new TH1F(HistName_sim.c_str(),HistName_sim.c_str(),100,-0.5,9.5);
185  h_hcalin_tower_sim[i_tower] = new TH1F(HistName_sim.c_str(),HistName_sim.c_str(),100,-0.5,histo_range);
186  hm->registerHisto(h_hcalin_tower_sim[i_tower]);
187 
188  HistName_sim = Form("h_hcalout_tower_%d_sim",i_tower);
189  // h_hcalout_tower_sim[i_tower] = new TH1F(HistName_sim.c_str(),HistName_sim.c_str(),100,-0.5,9.5);
190  h_hcalout_tower_sim[i_tower] = new TH1F(HistName_sim.c_str(),HistName_sim.c_str(),100,-0.5,histo_range);
191  hm->registerHisto(h_hcalout_tower_sim[i_tower]);
192  }
193 
194  TH2F *h_tower_energy_sim = new TH2F("h_tower_energy_sim","h_tower_energy_sim",100,-1.0,1.0,100,-0.5,histo_range);
195  hm->registerHisto(h_tower_energy_sim);
196  }
197 
198  // HCALIN LG
199  TH1F *h_hcalin_lg_tower_raw[16];
200  TH1F *h_hcalin_lg_tower_calib[16];
201  for(int i_tower = 0; i_tower < 16; ++i_tower)
202  {
203  string HistName_raw = Form("h_hcalin_lg_tower_%d_raw",i_tower);
204  h_hcalin_lg_tower_raw[i_tower] = new TH1F(HistName_raw.c_str(),HistName_raw.c_str(),100,-0.5,histo_range*20.0);
205  hm->registerHisto(h_hcalin_lg_tower_raw[i_tower]);
206 
207  string HistName_calib = Form("h_hcalin_lg_tower_%d_calib",i_tower);
208  h_hcalin_lg_tower_calib[i_tower] = new TH1F(HistName_calib.c_str(),HistName_calib.c_str(),100,-0.5,histo_range);
209  hm->registerHisto(h_hcalin_lg_tower_calib[i_tower]);
210  }
211 
212  // HCALOUT LG
213  TH1F *h_hcalout_lg_tower_raw[16];
214  TH1F *h_hcalout_lg_tower_calib[16];
215  for(int i_tower = 0; i_tower < 16; ++i_tower)
216  {
217  string HistName_raw = Form("h_hcalout_lg_tower_%d_raw",i_tower);
218  h_hcalout_lg_tower_raw[i_tower] = new TH1F(HistName_raw.c_str(),HistName_raw.c_str(),100,-0.5,histo_range*20.0);
219  hm->registerHisto(h_hcalout_lg_tower_raw[i_tower]);
220 
221  string HistName_calib = Form("h_hcalout_lg_tower_%d_calib",i_tower);
222  h_hcalout_lg_tower_calib[i_tower] = new TH1F(HistName_calib.c_str(),HistName_calib.c_str(),100,-0.5,histo_range);
223  hm->registerHisto(h_hcalout_lg_tower_calib[i_tower]);
224  }
225 
226  TH2F *h_tower_energy_raw = new TH2F("h_tower_energy_raw","h_tower_energy_raw",110,-1.1,1.1,100,-0.5,histo_range*640.0);
227  hm->registerHisto(h_tower_energy_raw);
228 
229  TH2F *h_tower_energy_calib = new TH2F("h_tower_energy_calib","h_tower_energy_calib",110,-1.1,1.1,100,-0.5,histo_range);
230  hm->registerHisto(h_tower_energy_calib);
231 
232  // HCALOUT HG
233  TH1F *h_hcalout_hg_tower_raw[16];
234  TH1F *h_hcalout_hg_tower_calib[16];
235  for(int i_tower = 0; i_tower < 16; ++i_tower)
236  {
237  string HistName_raw = Form("h_hcalout_hg_tower_%d_raw",i_tower);
238  h_hcalout_hg_tower_raw[i_tower] = new TH1F(HistName_raw.c_str(),HistName_raw.c_str(),100,-0.5,histo_range*20.0);
239  hm->registerHisto(h_hcalout_hg_tower_raw[i_tower]);
240 
241  string HistName_calib = Form("h_hcalout_hg_tower_%d_calib",i_tower);
242  h_hcalout_hg_tower_calib[i_tower] = new TH1F(HistName_calib.c_str(),HistName_calib.c_str(),100,-0.5,histo_range);
243  hm->registerHisto(h_hcalout_hg_tower_calib[i_tower]);
244  }
245 
246 
247  // help index files with TChain
248  TTree *T = new TTree("HCAL_Info", "HCAL_Info");
249  assert(T);
250  hm->registerHisto(T);
251 
252  T->Branch("info", &_eval_run);
253  T->Branch("tower", &_tower);
254 
256 }
257 
259 {
260  if (Verbosity() > 2)
261  cout << "Proto4ShowerCalib::process_event() entered" << endl;
262 
263  // init eval objects
264  _eval_run.reset();
265  _tower.reset();
266 
268  assert(hm);
269 
270  if (not _is_sim)
271  {
272  PdbParameterMap *info = findNode::getClass<PdbParameterMap>(topNode,
273  "RUN_INFO");
274 
275  assert(info);
276 
277  PHParameters run_info_copy("RunInfo");
278  run_info_copy.FillFrom(info);
279 
280  _eval_run.beam_mom = run_info_copy.get_double_param("beam_MTNRG_GeV");
281 
282  TH1F *hBeam_Mom = dynamic_cast<TH1F *>(hm->getHisto("hBeam_Mom"));
283  assert(hBeam_Mom);
284 
285  hBeam_Mom->Fill(_eval_run.beam_mom);
286 
287  _eval_run.beam_2CH_mm = run_info_copy.get_double_param("beam_2CH_mm");
288  _eval_run.beam_2CV_mm = run_info_copy.get_double_param("beam_2CV_mm");
289  }
290 
291  if (not _is_sim)
292  {
293  EventHeader *eventheader = findNode::getClass<EventHeader>(topNode,
294  "EventHeader");
295 
296  if (eventheader->get_EvtType() != DATAEVENT)
297  {
298  cout << __PRETTY_FUNCTION__
299  << " disgard this event: " << endl;
300 
301  eventheader->identify();
302 
304  }
305 
306  assert(eventheader);
307 
308  _eval_run.run = eventheader->get_RunNumber();
309  if (Verbosity() > 4)
310  cout << __PRETTY_FUNCTION__ << _eval_run.run << endl;
311 
312  _eval_run.event = eventheader->get_EvtSequence();
313  }
314 
315  if (_is_sim)
316  {
318  PHG4TruthInfoContainer>(topNode, "G4TruthInfo");
319 
320  assert(truthInfoList);
321 
322  _eval_run.run = -1;
323 
324  const PHG4Particle *p =
325  truthInfoList->GetPrimaryParticleRange().first->second;
326  assert(p);
327 
328  const PHG4VtxPoint *v = truthInfoList->GetVtx(p->get_vtx_id());
329  assert(v);
330 
331  _eval_run.beam_mom = sqrt(
332  p->get_px() * p->get_px() + p->get_py() * p->get_py() + p->get_pz() * p->get_pz());
333  _eval_run.truth_y = v->get_y();
334  _eval_run.truth_z = v->get_z();
335  }
336 
337  // normalization
338  TH1F *hNormalization = dynamic_cast<TH1F *>(hm->getHisto("hNormalization"));
339  assert(hNormalization);
340 
341  hNormalization->Fill("ALL", 1);
342 
343  // get DST nodes
344 
345  // HCALIN/HCALOUT SIM information
346  RawTowerContainer *TOWER_SIM_HCALIN = findNode::getClass<
347  RawTowerContainer>(topNode, "TOWER_SIM_HCALIN");
348  if(_is_sim)
349  {
350  assert(TOWER_SIM_HCALIN);
351  }
352 
353  RawTowerContainer *TOWER_SIM_HCALOUT = findNode::getClass<
354  RawTowerContainer>(topNode, "TOWER_SIM_HCALOUT");
355  if(_is_sim)
356  {
357  assert(TOWER_SIM_HCALOUT);
358  }
359 
360  // HCAL information
361  RawTowerContainer *TOWER_RAW_LG_HCALIN = findNode::getClass<
362  RawTowerContainer>(topNode, "TOWER_RAW_LG_HCALIN");
363  assert(TOWER_RAW_LG_HCALIN);
364 
365  RawTowerContainer *TOWER_RAW_LG_HCALOUT = findNode::getClass<
366  RawTowerContainer>(topNode, "TOWER_RAW_LG_HCALOUT");
367  assert(TOWER_RAW_LG_HCALOUT);
368 
369  RawTowerContainer *TOWER_RAW_HG_HCALOUT = findNode::getClass<
370  RawTowerContainer>(topNode, "TOWER_RAW_HG_HCALOUT");
371  assert(TOWER_RAW_HG_HCALOUT);
372 
373  RawTowerContainer *TOWER_CALIB_LG_HCALIN = findNode::getClass<
374  RawTowerContainer>(topNode, "TOWER_CALIB_LG_HCALIN");
375  assert(TOWER_CALIB_LG_HCALIN);
376 
377  RawTowerContainer *TOWER_CALIB_LG_HCALOUT = findNode::getClass<
378  RawTowerContainer>(topNode, "TOWER_CALIB_LG_HCALOUT");
379  assert(TOWER_CALIB_LG_HCALOUT);
380 
381  RawTowerContainer *TOWER_CALIB_HG_HCALOUT = findNode::getClass<
382  RawTowerContainer>(topNode, "TOWER_CALIB_HG_HCALOUT");
383  assert(TOWER_CALIB_HG_HCALOUT);
384 
385  // other nodes
386  RawTowerContainer *TOWER_CALIB_TRIGGER_VETO = findNode::getClass<
387  RawTowerContainer>(topNode, "TOWER_CALIB_TRIGGER_VETO");
388  if (not _is_sim)
389  {
390  assert(TOWER_CALIB_TRIGGER_VETO);
391  }
392 
393  RawTowerContainer *TOWER_CALIB_HODO_HORIZONTAL = findNode::getClass<
394  RawTowerContainer>(topNode, "TOWER_CALIB_HODO_HORIZONTAL");
395  if (not _is_sim)
396  {
397  assert(TOWER_CALIB_HODO_HORIZONTAL);
398  }
399  RawTowerContainer *TOWER_CALIB_HODO_VERTICAL = findNode::getClass<
400  RawTowerContainer>(topNode, "TOWER_CALIB_HODO_VERTICAL");
401  if (not _is_sim)
402  {
403  assert(TOWER_CALIB_HODO_VERTICAL);
404  }
405 
406  RawTowerContainer *TOWER_CALIB_C1 = findNode::getClass<RawTowerContainer>(
407  topNode, "TOWER_CALIB_C1");
408  if (not _is_sim)
409  {
410  assert(TOWER_CALIB_C1);
411  }
412  RawTowerContainer *TOWER_CALIB_C2 = findNode::getClass<RawTowerContainer>(
413  topNode, "TOWER_CALIB_C2");
414  if (not _is_sim)
415  {
416  assert(TOWER_CALIB_C2);
417  }
418 
419  // Cherenkov
420  bool cherekov_e = false;
421  bool cherekov_anti_e = false;
422  if (not _is_sim)
423  {
424  RawTower *t_c2_in = NULL;
425  RawTower *t_c2_out = NULL;
426 
427  t_c2_in = TOWER_CALIB_C2->getTower(0);
428  t_c2_out = TOWER_CALIB_C2->getTower(1);
429 
430  assert(t_c2_in);
431  assert(t_c2_out);
432 
433  const double c2_in = t_c2_in->get_energy();
434  const double c2_out = t_c2_out->get_energy();
435  const double c1 = TOWER_CALIB_C1->getTower(0)->get_energy();
436 
437  _eval_run.C2_sum = c2_in + c2_out;
438  _eval_run.C1 = c1;
439 
440  cherekov_e = (_eval_run.C2_sum) > (abs(_eval_run.beam_mom) >= 10 ? 1000 : 1500);
441  cherekov_anti_e = (_eval_run.C2_sum) < 100;
442  hNormalization->Fill("C2-e", cherekov_e);
443 
444  TH2F *hCheck_Cherenkov = dynamic_cast<TH2F *>(hm->getHisto(
445  "hCheck_Cherenkov"));
446  assert(hCheck_Cherenkov);
447  hCheck_Cherenkov->Fill(c1, "C1", 1);
448  hCheck_Cherenkov->Fill(c2_in, "C2 in", 1);
449  hCheck_Cherenkov->Fill(c2_out, "C2 out", 1);
450  hCheck_Cherenkov->Fill(c2_in + c2_out, "C2 sum", 1);
451  }
452 
453  // veto
454  TH1F *hCheck_Veto = dynamic_cast<TH1F *>(hm->getHisto("hCheck_Veto"));
455  assert(hCheck_Veto);
456  bool trigger_veto_pass = true;
457  if (not _is_sim)
458  {
459  auto range = TOWER_CALIB_TRIGGER_VETO->getTowers();
460  for (auto it = range.first; it != range.second; ++it)
461  {
462  RawTower *tower = it->second;
463  assert(tower);
464 
465  hCheck_Veto->Fill(tower->get_energy());
466 
467  if (abs(tower->get_energy()) > 0.2)
468  trigger_veto_pass = false;
469  }
470  }
471  hNormalization->Fill("trigger_veto_pass", trigger_veto_pass);
472  _eval_run.trigger_veto_pass = trigger_veto_pass;
473 
474  // hodoscope
475  TH1F *hCheck_Hodo_H = dynamic_cast<TH1F *>(hm->getHisto("hCheck_Hodo_H"));
476  assert(hCheck_Hodo_H);
477  int hodo_h_count = 0;
478  if (not _is_sim)
479  {
480  auto range = TOWER_CALIB_HODO_HORIZONTAL->getTowers();
481  for (auto it = range.first; it != range.second; ++it)
482  {
483  RawTower *tower = it->second;
484  assert(tower);
485 
486  hCheck_Hodo_H->Fill(tower->get_energy());
487 
488  if (abs(tower->get_energy()) > 0.5)
489  {
490  hodo_h_count++;
491  _eval_run.hodo_h = tower->get_id();
492  }
493  }
494  }
495  const bool valid_hodo_h = hodo_h_count == 1;
496  hNormalization->Fill("valid_hodo_h", valid_hodo_h);
497  _eval_run.valid_hodo_h = valid_hodo_h;
498 
499  TH1F *hCheck_Hodo_V = dynamic_cast<TH1F *>(hm->getHisto("hCheck_Hodo_V"));
500  assert(hCheck_Hodo_V);
501  int hodo_v_count = 0;
502  if (not _is_sim)
503  {
504  auto range = TOWER_CALIB_HODO_VERTICAL->getTowers();
505  for (auto it = range.first; it != range.second; ++it)
506  {
507  RawTower *tower = it->second;
508  assert(tower);
509 
510  hCheck_Hodo_V->Fill(tower->get_energy());
511 
512  if (abs(tower->get_energy()) > 0.5)
513  {
514  hodo_v_count++;
515  _eval_run.hodo_v = tower->get_id();
516  }
517  }
518  }
519  const bool valid_hodo_v = hodo_v_count == 1;
520  _eval_run.valid_hodo_v = valid_hodo_v;
521  hNormalization->Fill("valid_hodo_v", valid_hodo_v);
522 
523  const bool good_e = (valid_hodo_v and valid_hodo_h and cherekov_e and trigger_veto_pass) and (not _is_sim);
524  const bool good_anti_e = (valid_hodo_v and valid_hodo_h and cherekov_anti_e and trigger_veto_pass) and (not _is_sim);
525  hNormalization->Fill("good_e", good_e);
526  hNormalization->Fill("good_anti_e", good_anti_e);
527 
528  // simple clustering by matching to cluster of max energy
529  // pair<int, int> max_tower = find_max(TOWER_CALIB_LG_HCALOUT, 1);
530 
531  // process SIM HCALIN/HCALOUT
532  if(_is_sim)
533  {
534  double hcalin_sum_e_sim = 0;
535  double hcalout_sum_e_sim = 0;
536  {
537  auto range_hcalin_sim = TOWER_SIM_HCALIN->getTowers(); // sim
538  for (auto it = range_hcalin_sim.first; it != range_hcalin_sim.second; ++it)
539  {
540  RawTower *tower = it->second;
541  assert(tower);
542  // cout << "HCALIN SIM: ";
543  // tower->identify();
544 
545  const int col = tower->get_bineta();
546  const int row = tower->get_binphi();
547  const int chanNum = getChannelNumber(row,col);
548 
549  if (col < 0 or col >= 4)
550  continue;
551  if (row < 0 or row >= 4)
552  continue;
553 
554  const double energy_sim = tower->get_energy()/samplefrac_in; // apply samplefrac_in
555  hcalin_sum_e_sim += energy_sim;
556  _tower.hcalin_twr_sim[chanNum] = energy_sim;
557 
558  string HistName_sim = Form("h_hcalin_tower_%d_sim",chanNum);
559  TH1F *h_hcalin_sim = dynamic_cast<TH1F *>(hm->getHisto(HistName_sim.c_str()));
560  assert(h_hcalin_sim);
561  h_hcalin_sim->Fill(_tower.hcalin_twr_sim[chanNum]);
562  }
563  _tower.hcalin_e_sim = hcalin_sum_e_sim;
564 
565  auto range_hcalout_sim = TOWER_SIM_HCALOUT->getTowers(); // sim
566  for (auto it = range_hcalout_sim.first; it != range_hcalout_sim.second; ++it)
567  {
568  RawTower *tower = it->second;
569  assert(tower);
570  // cout << "HCALOUT SIM: ";
571  // tower->identify();
572 
573  const int col = tower->get_bineta();
574  const int row = tower->get_binphi();
575  const int chanNum = getChannelNumber(row,col);
576 
577  if (col < 0 or col >= 4)
578  continue;
579  if (row < 0 or row >= 4)
580  continue;
581 
582  const double energy_sim = tower->get_energy()/samplefrac_out; // apply samplefrac_out
583  hcalout_sum_e_sim += energy_sim;
584  _tower.hcalout_twr_sim[chanNum] = energy_sim;
585 
586  string HistName_sim = Form("h_hcalout_tower_%d_sim",chanNum);
587  TH1F *h_hcalout_sim = dynamic_cast<TH1F *>(hm->getHisto(HistName_sim.c_str()));
588  assert(h_hcalout_sim);
589  h_hcalout_sim->Fill(_tower.hcalout_twr_sim[chanNum]);
590  }
591  _tower.hcalout_e_sim = hcalout_sum_e_sim;
592  }
593  _tower.hcal_total_sim = hcalin_sum_e_sim + hcalout_sum_e_sim;
594  _tower.hcal_asym_sim = (hcalin_sum_e_sim - hcalout_sum_e_sim)/(hcalin_sum_e_sim + hcalout_sum_e_sim);
595 
596  TH2F *h_tower_energy_sim = dynamic_cast<TH2F *>(hm->getHisto("h_tower_energy_sim"));
597  assert(h_tower_energy_sim);
598  h_tower_energy_sim->Fill(_tower.hcal_asym_sim,_tower.hcal_total_sim);
599  }
600 
601  // process HCALIN LG
602  double hcalin_sum_lg_e_raw = 0;
603  double hcalin_sum_lg_e_calib = 0;
604  {
605  auto range_hcalin_lg_raw = TOWER_RAW_LG_HCALIN->getTowers(); // raw
606  for (auto it = range_hcalin_lg_raw.first; it != range_hcalin_lg_raw.second; ++it)
607  {
608  RawTower *tower = it->second;
609  assert(tower);
610  // cout << "HCALIN RAW: ";
611  // tower->identify();
612 
613  const int col = tower->get_bineta();
614  const int row = tower->get_binphi();
615  const int chanNum = getChannelNumber(row,col);
616 
617  if (col < 0 or col >= 4)
618  continue;
619  if (row < 0 or row >= 4)
620  continue;
621 
622  // const double energy_raw = tower->get_energy()*towercalib_lg_in[chanNum]; // manual calibration
623  const double energy_raw = tower->get_energy(); // raw
624  hcalin_sum_lg_e_raw += energy_raw;
625  _tower.hcalin_lg_twr_raw[chanNum] = energy_raw;
626 
627  string HistName_raw = Form("h_hcalin_lg_tower_%d_raw",chanNum);
628  TH1F *h_hcalin_lg_raw = dynamic_cast<TH1F *>(hm->getHisto(HistName_raw.c_str()));
629  assert(h_hcalin_lg_raw);
630  h_hcalin_lg_raw->Fill(_tower.hcalin_lg_twr_raw[chanNum]);
631  }
632  _tower.hcalin_lg_e_raw = hcalin_sum_lg_e_raw;
633 
634  auto range_hcalin_lg_calib = TOWER_CALIB_LG_HCALIN->getTowers(); // calib
635  for (auto it = range_hcalin_lg_calib.first; it != range_hcalin_lg_calib.second; ++it)
636  {
637  RawTower *tower = it->second;
638  assert(tower);
639 
640  const int col = tower->get_bineta();
641  const int row = tower->get_binphi();
642  const int chanNum = getChannelNumber(row,col);
643 
644  if (col < 0 or col >= 4)
645  continue;
646  if (row < 0 or row >= 4)
647  continue;
648 
649  const double energy_calib = tower->get_energy();
650  hcalin_sum_lg_e_calib += energy_calib;
651  _tower.hcalin_lg_twr_calib[chanNum] = energy_calib;
652 
653  string HistName_calib = Form("h_hcalin_lg_tower_%d_calib",chanNum);
654  TH1F *h_hcalin_lg_calib = dynamic_cast<TH1F *>(hm->getHisto(HistName_calib.c_str()));
655  assert(h_hcalin_lg_calib);
656  h_hcalin_lg_calib->Fill(_tower.hcalin_lg_twr_calib[chanNum]);
657  }
658  _tower.hcalin_lg_e_calib = hcalin_sum_lg_e_calib;
659  }
660 
661  // process HCALOUT LG
662  double hcalout_sum_lg_e_raw = 0;
663  double hcalout_sum_lg_e_calib = 0;
664  {
665  auto range_hcalout_lg_raw = TOWER_RAW_LG_HCALOUT->getTowers(); // raw
666  for (auto it = range_hcalout_lg_raw.first; it != range_hcalout_lg_raw.second; ++it)
667  {
668  RawTower *tower = it->second;
669  assert(tower);
670  // cout << "HCALOUT RAM: ";
671  // tower->identify();
672 
673  const int col = tower->get_bineta();
674  const int row = tower->get_binphi();
675  const int chanNum = getChannelNumber(row,col);
676 
677  if (col < 0 or col >= 4)
678  continue;
679  if (row < 0 or row >= 4)
680  continue;
681 
682  // const double energy_raw = tower->get_energy()*towercalib_lg_out[chanNum]; // manual calibration
683  const double energy_raw = tower->get_energy(); // raw
684  hcalout_sum_lg_e_raw += energy_raw;
685  _tower.hcalout_lg_twr_raw[chanNum] = energy_raw;
686 
687  string HistName_raw = Form("h_hcalout_lg_tower_%d_raw",chanNum);
688  TH1F *h_hcalout_lg_raw = dynamic_cast<TH1F *>(hm->getHisto(HistName_raw.c_str()));
689  assert(h_hcalout_lg_raw);
690  h_hcalout_lg_raw->Fill(_tower.hcalout_lg_twr_raw[chanNum]);
691  }
692  _tower.hcalout_lg_e_raw = hcalout_sum_lg_e_raw;
693 
694  auto range_hcalout_lg_calib = TOWER_CALIB_LG_HCALOUT->getTowers(); // calib
695  for (auto it = range_hcalout_lg_calib.first; it != range_hcalout_lg_calib.second; ++it)
696  {
697  RawTower *tower = it->second;
698  assert(tower);
699 
700  const int col = tower->get_bineta();
701  const int row = tower->get_binphi();
702  const int chanNum = getChannelNumber(row,col);
703 
704  if (col < 0 or col >= 4)
705  continue;
706  if (row < 0 or row >= 4)
707  continue;
708 
709  const double energy_calib = tower->get_energy();
710  hcalout_sum_lg_e_calib += energy_calib;
711  _tower.hcalout_lg_twr_calib[chanNum] = energy_calib;
712 
713  string HistName_calib = Form("h_hcalout_lg_tower_%d_calib",chanNum);
714  TH1F *h_hcalout_lg_calib = dynamic_cast<TH1F *>(hm->getHisto(HistName_calib.c_str()));
715  assert(h_hcalout_lg_calib);
716  h_hcalout_lg_calib->Fill(_tower.hcalout_lg_twr_calib[chanNum]);
717  }
718  _tower.hcalout_lg_e_calib = hcalout_sum_lg_e_calib;
719  }
720 
721  _tower.hcal_total_raw = hcalin_sum_lg_e_raw + hcalout_sum_lg_e_raw;
722  _tower.hcal_asym_raw = (hcalin_sum_lg_e_raw - hcalout_sum_lg_e_raw)/(hcalin_sum_lg_e_raw + hcalout_sum_lg_e_raw);
723  TH2F *h_tower_energy_raw = dynamic_cast<TH2F *>(hm->getHisto("h_tower_energy_raw"));
724  assert(h_tower_energy_raw);
725  h_tower_energy_raw->Fill(_tower.hcal_asym_raw,_tower.hcal_total_raw);
726 
727  _tower.hcal_total_calib = hcalin_sum_lg_e_calib + hcalout_sum_lg_e_calib;
728  _tower.hcal_asym_calib = (hcalin_sum_lg_e_calib - hcalout_sum_lg_e_calib)/(hcalin_sum_lg_e_calib + hcalout_sum_lg_e_calib);
729  TH2F *h_tower_energy_calib = dynamic_cast<TH2F *>(hm->getHisto("h_tower_energy_calib"));
730  assert(h_tower_energy_calib);
731  h_tower_energy_calib->Fill(_tower.hcal_asym_calib,_tower.hcal_total_calib);
732 
733  // process HCALOUT HG
734  {
735  double hcalout_sum_hg_e_raw = 0;
736  double hcalout_sum_hg_e_calib = 0;
737  auto range_hcalout_hg_raw = TOWER_RAW_HG_HCALOUT->getTowers(); // raw
738  for (auto it = range_hcalout_hg_raw.first; it != range_hcalout_hg_raw.second; ++it)
739  {
740  RawTower *tower = it->second;
741  assert(tower);
742 
743  const int col = tower->get_bineta();
744  const int row = tower->get_binphi();
745  const int chanNum = getChannelNumber(row,col);
746 
747  if (col < 0 or col >= 4)
748  continue;
749  if (row < 0 or row >= 4)
750  continue;
751 
752  // const double energy_raw = tower->get_energy()*towercalib_hg_out[chanNum]; // manual calibration
753  const double energy_raw = tower->get_energy(); // raw
754  hcalout_sum_hg_e_raw += energy_raw;
755  _tower.hcalout_hg_twr_raw[chanNum] = energy_raw;
756 
757  string HistName_raw = Form("h_hcalout_hg_tower_%d_raw",chanNum);
758  TH1F *h_hcalout_hg_raw = dynamic_cast<TH1F *>(hm->getHisto(HistName_raw.c_str()));
759  assert(h_hcalout_hg_raw);
760  h_hcalout_hg_raw->Fill(_tower.hcalout_hg_twr_raw[chanNum]);
761  }
762  _tower.hcalout_hg_e_raw = hcalout_sum_hg_e_raw;
763 
764  auto range_hcalout_hg_calib = TOWER_CALIB_HG_HCALOUT->getTowers(); // calib
765  for (auto it = range_hcalout_hg_calib.first; it != range_hcalout_hg_calib.second; ++it)
766  {
767  RawTower *tower = it->second;
768  assert(tower);
769 
770  const int col = tower->get_bineta();
771  const int row = tower->get_binphi();
772  const int chanNum = getChannelNumber(row,col);
773 
774  if (col < 0 or col >= 4)
775  continue;
776  if (row < 0 or row >= 4)
777  continue;
778 
779  const double energy_calib = tower->get_energy();
780  hcalout_sum_hg_e_calib += energy_calib;
781  _tower.hcalout_hg_twr_calib[chanNum] = energy_calib;
782 
783  string HistName_calib = Form("h_hcalout_hg_tower_%d_calib",chanNum);
784  TH1F *h_hcalout_hg_calib = dynamic_cast<TH1F *>(hm->getHisto(HistName_calib.c_str()));
785  assert(h_hcalout_hg_calib);
786  h_hcalout_hg_calib->Fill(_tower.hcalout_hg_twr_calib[chanNum]);
787  }
788  _tower.hcalout_hg_e_calib = hcalout_sum_hg_e_calib;
789  }
790 
791  _eval_run.sum_E_HCAL_IN = hcalin_sum_lg_e_calib;
792  _eval_run.sum_E_HCAL_OUT = hcalout_sum_lg_e_calib;
793 
794  _eval_run.good_e = good_e;
795  _eval_run.good_anti_e = good_anti_e;
796 
797  TTree *T = dynamic_cast<TTree *>(hm->getHisto("HCAL_Info"));
798  assert(T);
799  T->Fill();
800 
802 }
803 
804 pair<int, int>
805 Proto4ShowerCalib::find_max(RawTowerContainer *towers, int cluster_size)
806 {
807  const int clus_edge_size = (cluster_size - 1) / 2;
808  assert(clus_edge_size >= 0);
809 
810  pair<int, int> max(-1000, -1000);
811  double max_e = 0;
812 
813  for (int col = 0; col < n_size; ++col)
814  for (int row = 0; row < n_size; ++row)
815  {
816  double energy = 0;
817 
818  for (int dcol = col - clus_edge_size; dcol <= col + clus_edge_size;
819  ++dcol)
820  for (int drow = row - clus_edge_size; drow <= row + clus_edge_size;
821  ++drow)
822  {
823  if (dcol < 0 or drow < 0)
824  continue;
825 
826  RawTower *t = towers->getTower(dcol, drow);
827  if (t)
828  energy += t->get_energy();
829  }
830 
831  if (energy > max_e)
832  {
833  max = make_pair(col, row);
834  max_e = energy;
835  }
836  }
837 
838  return max;
839 }
840 
842 {
843  if(_is_sim) _mList = "SIM";
844  if(!_is_sim) _mList = "RAW";
845  string inputdir = "/sphenix/user/xusun/TestBeam/ShowerCalib/";
846  string InPutList = Form("/direct/phenix+u/xusun/WorkSpace/sPHENIX/analysis/Prototype4/HCal/macros/list/ShowerCalib/Proto4TowerInfo%s_%s.list",_mList.c_str(),_mRunID.c_str());
847 
848  mChainInPut = new TChain("HCAL_Info");
849 
850  if (!InPutList.empty()) // if input file is ok
851  {
852  cout << "Open input database file list: " << InPutList.c_str() << endl;
853  ifstream in(InPutList.c_str()); // input stream
854  if(in)
855  {
856  cout << "input database file list is ok" << endl;
857  char str[255]; // char array for each file name
858  Long64_t entries_save = 0;
859  while(in)
860  {
861  in.getline(str,255); // take the lines of the file list
862  if(str[0] != 0)
863  {
864  string addfile;
865  addfile = str;
866  addfile = inputdir+addfile;
867  mChainInPut->AddFile(addfile.c_str(),-1,"HCAL_Info");
868  long file_entries = mChainInPut->GetEntries();
869  cout << "File added to data chain: " << addfile.c_str() << " with " << (file_entries-entries_save) << " entries" << endl;
870  entries_save = file_entries;
871  }
872  }
873  }
874  else
875  {
876  cout << "WARNING: input database file input is problemtic" << endl;
877  _mInPut_flag = 0;
878  }
879  }
880 
881  // Set the input tree
882  if (_mInPut_flag == 1 && !mChainInPut->GetBranch( "info" ))
883  {
884  cerr << "ERROR: Could not find branch 'info' in tree!" << endl;
885  }
886 
889  if(_mInPut_flag == 1)
890  {
891  mChainInPut->SetBranchAddress("info", &_mInfo);
892  mChainInPut->SetBranchAddress("tower", &_mTower);
893 
894  long NumOfEvents = (long)mChainInPut->GetEntries();
895  cout << "total number of events: " << NumOfEvents << endl;
896  _mStartEvent = 0;
897  _mStopEvent = NumOfEvents;
898 
899  cout << "New nStartEvent = " << _mStartEvent << ", new nStopEvent = " << _mStopEvent << endl;
900  }
901 
902  float histo_range = find_range();
903 
904  if(_is_sim)
905  {
906  // h_mAsymmEnergy_mixed_sim_wo_cut = new TH2F("h_mAsymmEnergy_mixed_sim_wo_cut","h_mAsymmEnergy_mixed_sim_wo_cut",100,-1.0,1.0,100,-0.5,histo_range);
907  h_mAsymmEnergy_pion_sim_wo_cut = new TH2F("h_mAsymmEnergy_pion_sim_wo_cut","h_mAsymmEnergy_pion_sim_wo_cut",100,-1.0,1.0,100,-0.5,histo_range);
908 
909  // h_mAsymmEnergy_mixed_sim = new TH2F("h_mAsymmEnergy_mixed_sim","h_mAsymmEnergy_mixed_sim",100,-1.0,1.0,100,-0.5,histo_range);
910  h_mAsymmEnergy_pion_sim = new TH2F("h_mAsymmEnergy_pion_sim","h_mAsymmEnergy_pion_sim",100,-1.0,1.0,100,-0.5,histo_range);
911  }
912  if(!_is_sim)
913  {
914  h_mAsymmAdc_mixed = new TH2F("h_mAsymmAdc_mixed","h_mAsymmAdc_mixed",110,-1.1,1.1,100,-0.5,histo_range*640.0);
915  h_mAsymmAdc_electron = new TH2F("h_mAsymmAdc_electron","h_mAsymmAdc_electron",110,-1.1,1.1,100,-0.5,histo_range*640.0);
916  h_mAsymmAdc_pion = new TH2F("h_mAsymmAdc_pion","h_mAsymmAdc_pion",110,-1.1,1.1,100,-0.5,histo_range*640.0);
917 
918  h_mAsymmEnergy_mixed_wo_cut = new TH2F("h_mAsymmEnergy_mixed_wo_cut","h_mAsymmEnergy_mixed_wo_cut",110,-1.1,1.1,100,-0.5,0.5*histo_range);
919  h_mAsymmEnergy_electron_wo_cut = new TH2F("h_mAsymmEnergy_electron_wo_cut","h_mAsymmEnergy_electron_wo_cut",110,-1.1,1.1,100,-0.5,0.5*histo_range);
920  h_mAsymmEnergy_pion_wo_cut = new TH2F("h_mAsymmEnergy_pion_wo_cut","h_mAsymmEnergy_pion_wo_cut",110,-1.1,1.1,100,-0.5,0.5*histo_range);
921 
922  h_mAsymmEnergy_mixed = new TH2F("h_mAsymmEnergy_mixed","h_mAsymmEnergy_mixed",110,-1.1,1.1,100,-0.5,0.5*histo_range);
923  h_mAsymmEnergy_electron = new TH2F("h_mAsymmEnergy_electron","h_mAsymmEnergy_electron",110,-1.1,1.1,100,-0.5,0.5*histo_range);
924  h_mAsymmEnergy_pion = new TH2F("h_mAsymmEnergy_pion","h_mAsymmEnergy_pion",110,-1.1,1.1,100,-0.5,0.5*histo_range);
925 
926  h_mAsymmEnergy_mixed_balancing = new TH2F("h_mAsymmEnergy_mixed_balancing","h_mAsymmEnergy_mixed_balancing",110,-1.1,1.1,100,-0.5,0.5*histo_range);
927  h_mAsymmEnergy_electron_balancing = new TH2F("h_mAsymmEnergy_electron_balancing","h_mAsymmEnergy_electron_balancing",110,-1.1,1.1,100,-0.5,0.5*histo_range);
928  h_mAsymmEnergy_pion_balancing = new TH2F("h_mAsymmEnergy_pion_balancing","h_mAsymmEnergy_pion_balancing",110,-1.1,1.1,100,-0.5,0.5*histo_range);
929 
930  h_mAsymmEnergy_mixed_leveling = new TH2F("h_mAsymmEnergy_mixed_leveling","h_mAsymmEnergy_mixed_leveling",110,-1.1,1.1,100,-0.5,0.5*histo_range);
931  h_mAsymmEnergy_electron_leveling = new TH2F("h_mAsymmEnergy_electron_leveling","h_mAsymmEnergy_electron_leveling",110,-1.1,1.1,100,-0.5,0.5*histo_range);
932  h_mAsymmEnergy_pion_leveling = new TH2F("h_mAsymmEnergy_pion_leveling","h_mAsymmEnergy_pion_leveling",110,-1.1,1.1,100,-0.5,0.5*histo_range);
933 
934  h_mAsymmEnergy_mixed_ShowerCalib = new TH2F("h_mAsymmEnergy_mixed_ShowerCalib","h_mAsymmEnergy_mixed_ShowerCalib",110,-1.1,1.1,100,-0.5,histo_range+15.0);
935  h_mAsymmEnergy_electron_ShowerCalib = new TH2F("h_mAsymmEnergy_electron_ShowerCalib","h_mAsymmEnergy_electron_ShowerCalib",110,-1.1,1.1,100,-0.5,histo_range+15.0);
936  h_mAsymmEnergy_pion_ShowerCalib = new TH2F("h_mAsymmEnergy_pion_ShowerCalib","h_mAsymmEnergy_pion_ShowerCalib",110,-1.1,1.1,100,-0.5,histo_range+15.0);
937 
938  // Outer HCal only study
939  h_mAsymmEnergy_mixed_MIP = new TH2F("h_mAsymmEnergy_mixed_MIP","h_mAsymmEnergy_mixed_MIP",110,-1.1,1.1,100,-0.5,0.5*histo_range);
940  h_mEnergyOut_electron = new TH1F("h_mEnergyOut_electron","h_mEnergyOut_electron",100,-0.5,0.5*histo_range);
941  h_mEnergyOut_pion = new TH1F("h_mEnergyOut_pion","h_mEnergyOut_pion",100,-0.5,0.5*histo_range);
942 
943  h_mEnergyOut_electron_ShowerCalib = new TH1F("h_mEnergyOut_electron_ShowerCalib","h_mEnergyOut_electron_ShowerCalib",100,-0.5,histo_range);
944  h_mEnergyOut_pion_ShowerCalib = new TH1F("h_mEnergyOut_pion_ShowerCalib","h_mEnergyOut_pion_ShowerCalib",100,-0.5,histo_range);
945  }
946 
947  return 0;
948 }
949 
951 {
952  cout << "Make()" << endl;
953 
954  // const int mBeamEnergy[6] = {4, 8, 12, 16, 24, 30};
955  const float c_in[5] = {0.905856, 0.943406, 0.964591, 1.0, 0.962649};
956  const float c_out[5] = {1.115980, 1.063820, 1.038110, 1.0, 1.040370};
957  // const float c_in[5] = {0.942372, 0.932490, 0.955448, 0.962649, 0.962649};
958  // const float c_out[5] = {1.065140, 1.078050, 1.048910, 1.040370, 1.040370};
959  const int mEnergyBin = find_energy();
960  const float c_in_leveling = c_in[mEnergyBin];
961  const float c_out_leveling = c_out[mEnergyBin];
962  // cout << "mEnergyBin = " << mEnergyBin << ", c_in = " << c_in[mEnergyBin] << ", c_out = " << c_out[mEnergyBin] << endl;
963 
964  unsigned long start_event_use = _mStartEvent;
965  unsigned long stop_event_use = _mStopEvent;
966 
967  mChainInPut->SetBranchAddress("info", &_mInfo);
968  mChainInPut->SetBranchAddress("tower", &_mTower);
969  mChainInPut->GetEntry(0);
970 
971  for(unsigned long i_event = start_event_use; i_event < stop_event_use; ++i_event)
972  // for(unsigned long i_event = 20; i_event < 40; ++i_event)
973  {
974  if (!mChainInPut->GetEntry( i_event )) // take the event -> information is stored in event
975  break; // end of data chunk
976 
977  if (i_event != 0 && i_event % 1000 == 0)
978  cout << "." << flush;
979  if (i_event != 0 && i_event % 10000 == 0)
980  {
981  if((stop_event_use-start_event_use) > 0)
982  {
983  double event_percent = 100.0*((double)(i_event-start_event_use))/((double)(stop_event_use-start_event_use));
984  cout << " " << i_event-start_event_use << " (" << event_percent << "%) " << "\n" << "==> Processing data (ShowerCalib) " << flush;
985  }
986  }
987 
988  if(_is_sim) // beam test simulation
989  {
990  float energy_sim = _mTower->hcal_total_sim;
991  float asymm_sim = _mTower->hcal_asym_sim;
992  const float energy_hcalin_sim = _mTower->hcalin_e_sim; // sim
993  const float energy_hcalout_sim = _mTower->hcalout_e_sim;
994 
995  // h_mAsymmEnergy_mixed_sim_wo_cut->Fill(asymm_sim,energy_sim);
996  h_mAsymmEnergy_pion_sim_wo_cut->Fill(asymm_sim,energy_sim);
997  if(energy_hcalin_sim > 0.2 && energy_hcalout_sim > 0/2)
998  {
999  // h_mAsymmEnergy_mixed_sim->Fill(asymm_sim,energy_sim);
1000  h_mAsymmEnergy_pion_sim->Fill(asymm_sim,energy_sim);
1001  }
1002  }
1003  if(!_is_sim) // beam test data
1004  {
1005  const bool good_electron = _mInfo->good_e;
1006  const bool good_pion = _mInfo->good_anti_e;
1007 
1008  float energy_raw = _mTower->hcal_total_raw; // raw
1009  float asymm_raw = _mTower->hcal_asym_raw;
1010 
1011  h_mAsymmAdc_mixed->Fill(asymm_raw,energy_raw);
1012  if(good_electron) h_mAsymmAdc_electron->Fill(asymm_raw,energy_raw);
1013  if(good_pion) h_mAsymmAdc_pion->Fill(asymm_raw,energy_raw);
1014 
1015  float energy_calib = _mTower->hcal_total_calib; // calib
1016  float asymm_calib = _mTower->hcal_asym_calib;
1017  const float energy_hcalin_calib = _mTower->hcalin_lg_e_calib;
1018  const float energy_hcalout_calib = _mTower->hcalout_lg_e_calib;
1019 
1020  h_mAsymmEnergy_mixed_wo_cut->Fill(asymm_calib,energy_calib);
1021  if(good_electron) h_mAsymmEnergy_electron_wo_cut->Fill(asymm_calib,energy_calib);
1022  if(good_pion) h_mAsymmEnergy_pion_wo_cut->Fill(asymm_calib,energy_calib);
1023 
1024  if(energy_hcalin_calib > 0.001 && energy_hcalout_calib > 0.001) // remove ped
1025  { // extract MIP
1026  h_mAsymmEnergy_mixed->Fill(asymm_calib,energy_calib);
1027  if(good_electron) h_mAsymmEnergy_electron->Fill(asymm_calib,energy_calib);
1028  if(good_pion) h_mAsymmEnergy_pion->Fill(asymm_calib,energy_calib);
1029  }
1030 
1031  const double MIP_cut = MIP_mean+MIP_width; // 1 sigma MIP energy cut
1032  if(energy_hcalin_calib <= MIP_cut && energy_hcalout_calib > 0.001 && energy_calib > MIP_cut)
1033  { // OHCal with MIP event in IHCal
1034  h_mAsymmEnergy_mixed_MIP->Fill(asymm_calib,energy_calib);
1035  if(good_electron) h_mEnergyOut_electron->Fill(energy_hcalout_calib);
1036  if(good_pion) h_mEnergyOut_pion->Fill(energy_hcalout_calib);
1037 
1038  // showercalib
1039  if(good_electron) h_mEnergyOut_electron_ShowerCalib->Fill(energy_hcalout_calib*showercalib_ohcal);
1040  if(good_pion) h_mEnergyOut_pion_ShowerCalib->Fill(energy_hcalout_calib*showercalib_ohcal);
1041  }
1042  const double MIP_energy_cut = MIP_mean+3.0*MIP_width; // 3 sigma MIP energy cut
1043  if(energy_hcalin_calib > 0.001 && energy_hcalout_calib > 0.001 && energy_calib > MIP_energy_cut)
1044  { // balancing without muon
1045  h_mAsymmEnergy_mixed_balancing->Fill(asymm_calib,energy_calib);
1046  if(good_electron) h_mAsymmEnergy_electron_balancing->Fill(asymm_calib,energy_calib);
1047  if(good_pion) h_mAsymmEnergy_pion_balancing->Fill(asymm_calib,energy_calib);
1048 
1049  // apply leveling
1050  const float energy_leveling = c_in_leveling*energy_hcalin_calib + c_out_leveling*energy_hcalout_calib;
1051  const float asymm_leveling = (c_in_leveling*energy_hcalin_calib - c_out_leveling*energy_hcalout_calib)/energy_leveling;
1052  h_mAsymmEnergy_mixed_leveling->Fill(asymm_leveling,energy_leveling);
1053  if(good_electron) h_mAsymmEnergy_electron_leveling->Fill(asymm_leveling,energy_leveling);
1054  if(good_pion) h_mAsymmEnergy_pion_leveling->Fill(asymm_leveling,energy_leveling);
1055 
1056  // apply shower calibration
1057  const float energy_showercalib = showercalib*c_in_leveling*energy_hcalin_calib + showercalib*c_out_leveling*energy_hcalout_calib;
1058  const float asymm_showercalib = (showercalib*c_in_leveling*energy_hcalin_calib - showercalib*c_out_leveling*energy_hcalout_calib)/energy_showercalib;
1059  // cout << "energy_leveling = " << energy_leveling << ", energy_showercalib = " << energy_showercalib << endl;
1060  // cout << "asymm_leveling = " << asymm_leveling << ", asymm_showercalib = " << asymm_showercalib << endl;
1061  h_mAsymmEnergy_mixed_ShowerCalib->Fill(asymm_showercalib,energy_showercalib);
1062  if(good_electron) h_mAsymmEnergy_electron_ShowerCalib->Fill(asymm_showercalib,energy_showercalib);
1063  if(good_pion) h_mAsymmEnergy_pion_ShowerCalib->Fill(asymm_showercalib,energy_showercalib);
1064  }
1065  }
1066  }
1067 
1068  cout << "." << flush;
1069  cout << " " << stop_event_use-start_event_use << "(" << 100 << "%)";
1070  cout << endl;
1071 
1072  return 1;
1073 }
1074 
1076 {
1077  cout << "Finish()" << endl;
1078  mFile_OutPut = new TFile(_filename.c_str(),"RECREATE");
1079  mFile_OutPut->cd();
1080  if(_is_sim) // beam test simulation
1081  {
1082  // h_mAsymmEnergy_mixed_sim_wo_cut->Write();
1084  // h_mAsymmEnergy_mixed_sim->Write();
1085  h_mAsymmEnergy_pion_sim->Write();
1086  }
1087  if(!_is_sim) // beam test data
1088  {
1089  h_mAsymmAdc_mixed->Write();
1090  h_mAsymmAdc_electron->Write();
1091  h_mAsymmAdc_pion->Write();
1092 
1093  h_mAsymmEnergy_mixed_wo_cut->Write();
1095  h_mAsymmEnergy_pion_wo_cut->Write();
1096 
1097  h_mAsymmEnergy_mixed->Write();
1098  h_mAsymmEnergy_electron->Write();
1099  h_mAsymmEnergy_pion->Write();
1100 
1104 
1108 
1112 
1113  h_mAsymmEnergy_mixed_MIP->Write();
1114  h_mEnergyOut_electron->Write();
1115  h_mEnergyOut_pion->Write();
1116 
1119  }
1120  mFile_OutPut->Close();
1121 
1122  return 1;
1123 }
1124 
1125 int Proto4ShowerCalib::getChannelNumber(int row, int column)
1126 {
1127  if(!_is_sim)
1128  {
1129  int hbdchanIHC[4][4] = {{4, 8, 12, 16},
1130  {3, 7, 11, 15},
1131  {2, 6, 10, 14},
1132  {1, 5, 9, 13}};
1133 
1134  return hbdchanIHC[row][column] - 1;
1135  }
1136 
1137  if(_is_sim)
1138  {
1139  int hbdchanIHC[4][4] = {{13, 9, 5, 1},
1140  {14, 10, 6, 2},
1141  {15, 11, 7, 3},
1142  {16, 12, 8, 4}};
1143 
1144  return hbdchanIHC[row][column] - 1;
1145  }
1146 
1147  return -1;
1148 }
1149 
1151 {
1152  const double energy_in[16] = {0.00763174, 0.00692298, 0.00637355, 0.0059323, 0.00762296, 0.00691832, 0.00636611, 0.0059203, 0.00762873, 0.00693594, 0.00637791, 0.00592433, 0.00762898, 0.00691679, 0.00636373, 0.00592433};
1153  const double adc_in[16] = {2972.61, 2856.43, 2658.19, 2376.10, 3283.39, 2632.81, 2775.77, 2491.68, 2994.11, 3385.70, 3258.01, 2638.31, 3479.97, 3081.41, 2768.36, 2626.77};
1154  const double gain_factor_in = 32.0;
1155 
1156  const double energy_out[16] = {0.00668176, 0.00678014, 0.00687082, 0.00706854, 0.00668973, 0.00678279, 0.00684794, 0.00705448, 0.00668976, 0.0068013, 0.00685931, 0.00704985, 0.0066926, 0.00678282, 0.00684403, 0.00704143};
1157  // const double adc_out[16] = {666.378, 1488.15, 1493.36, 1816.82, 666.378, 1488.15, 1493.36, 1816.82, 666.378, 1488.15, 1493.36, 1816.82, 666.378, 1488.15, 1493.36, 1816.82}; // use 1st column for whole HCALOUT
1158  const double adc_out[16] = {276.9, 290.0, 280.7, 272.1, 309.5, 304.8, 318.5, 289.6, 289.9, 324.2, 297.9, 294.6, 292.7, 310.5, 302.3, 298.5}; // Songkyo's number
1159  const double adc_amp[16] = {2.505, 5.330, 5.330, 6.965, 2.505, 5.330, 5.330, 6.965, 2.505, 5.330, 5.330, 6.965, 2.505, 5.330, 5.330, 6.965}; // amplify from 2017 to 2018
1160  const double gain_factor_out = 16.0;
1161 
1162  // const double tower_in[16] = {3.98902E-05,3.76295E-05,3.75111E-05,3.8131E-05,3.84078E-05,3.66107E-05,4.20291E-05,3.61503E-05,3.67743E-05,3.22359E-05,3.27909E-05,3.89949E-05,3.55663E-05,3.62068E-05,3.55327E-05,3.34781E-05}; // from Songkyo
1163  // const double tower_out[16] ={0.000144539,0.000136337,0.000129978,0.00013414,0.000135812,0.000120164,0.000123676,0.000119989,0.000133497,0.000128479,0.000116275,0.000128108,0.000131765,0.000126611,0.000121401,0.000126879};
1164 
1165  for(int i_tower = 0; i_tower < 16; ++i_tower)
1166  {
1167  towercalib_lg_in[i_tower] = gain_factor_in*energy_in[i_tower]/(adc_in[i_tower]*samplefrac_in);
1168  towercalib_lg_out[i_tower] = gain_factor_out*energy_out[i_tower]/(adc_amp[i_tower]*adc_out[i_tower]*samplefrac_out);
1169  towercalib_hg_out[i_tower] = energy_out[i_tower]/(adc_amp[i_tower]*adc_out[i_tower]*samplefrac_out);
1170  // towercalib_lg_out[i_tower] = gain_factor_out*energy_out[i_tower]/(adc_out[i_tower]*samplefrac_out);
1171  // towercalib_hg_out[i_tower] = energy_out[i_tower]/(adc_out[i_tower]*samplefrac_out);
1172 
1173  // towercalib_lg_in[i_tower] = tower_in[i_tower]*gain_factor_in;
1174  // towercalib_lg_out[i_tower] = tower_out[i_tower]*gain_factor_out;
1175  // towercalib_hg_out[i_tower] = tower_out[i_tower];
1176 
1177  // cout << "i_tower = " << i_tower << ", towercalib_lg_in = " << towercalib_lg_in[i_tower] << ", towercalib_lg_out = " << towercalib_lg_out[i_tower] << endl;
1178  }
1179 
1180  return 1;
1181 }
1182 
1184 {
1185  float range = 99.5;
1186 
1187  std::string hcal_120GeV[2] = {"0498","0762"};
1188  std::string hcal_60GeV[2] = {"0820","0821"};
1189  std::string hcal_12GeV[2] = {"0570","0571"};
1190  std::string hcal_8GeV[3] = {"0421","0422","1245"};
1191  std::string hcal_5GeV[3] = {"1087","1089","1091"};
1192 
1193  // cout << "_mRunID = " << _mRunID.c_str() << ", compare = " << _mRunID.compare(hcal_4GeV[0]) << endl;
1194 
1195  for(int i_run = 0; i_run < 2; ++i_run) // 120 GeV
1196  {
1197  if(_mRunID.compare(hcal_120GeV[i_run]) == 0)
1198  {
1199  range = 99.5;
1200  return range;
1201  }
1202  }
1203  for(int i_run = 0; i_run < 2; ++i_run) // 60 GeV
1204  {
1205  if(_mRunID.compare(hcal_60GeV[i_run]) == 0)
1206  {
1207  range = 79.5;
1208  return range;
1209  }
1210  }
1211  for(int i_run = 0; i_run < 2; ++i_run) // 12 GeV
1212  {
1213  if(_mRunID.compare(hcal_12GeV[i_run]) == 0)
1214  {
1215  range = 24.5;
1216  return range;
1217  }
1218  }
1219  for(int i_run = 0; i_run < 3; ++i_run) // 8 GeV
1220  {
1221  if(_mRunID.compare(hcal_8GeV[i_run]) == 0)
1222  {
1223  range = 16.5;
1224  return range;
1225  }
1226  }
1227  for(int i_run = 0; i_run < 3; ++i_run) // 5 GeV
1228  {
1229  if(_mRunID.compare(hcal_5GeV[i_run]) == 0)
1230  {
1231  range = 9.5;
1232  return range;
1233  }
1234  }
1235 
1236  return range;
1237 }
1238 
1240 {
1241  int energy = -1;
1242 
1243  std::string hcal_120GeV[2] = {"0498","0762"};
1244  std::string hcal_60GeV[2] = {"0820","0821"};
1245  std::string hcal_12GeV[2] = {"0570","0571"};
1246  std::string hcal_8GeV[3] = {"0421","0422","1245"};
1247  std::string hcal_5GeV[3] = {"1087","1089","1091"};
1248 
1249  // cout << "_mRunID = " << _mRunID.c_str() << ", compare = " << _mRunID.compare(hcal_4GeV[0]) << endl;
1250 
1251  for(int i_run = 0; i_run < 2; ++i_run) // 120 GeV
1252  {
1253  if(_mRunID.compare(hcal_120GeV[i_run]) == 0)
1254  {
1255  energy = 4;
1256  return energy;
1257  }
1258  }
1259  for(int i_run = 0; i_run < 2; ++i_run) // 60 GeV
1260  {
1261  if(_mRunID.compare(hcal_60GeV[i_run]) == 0)
1262  {
1263  energy = 3;
1264  return energy;
1265  }
1266  }
1267  for(int i_run = 0; i_run < 2; ++i_run) // 12 GeV
1268  {
1269  if(_mRunID.compare(hcal_12GeV[i_run]) == 0)
1270  {
1271  energy = 2;
1272  return energy;
1273  }
1274  }
1275  for(int i_run = 0; i_run < 3; ++i_run) // 8 GeV
1276  {
1277  if(_mRunID.compare(hcal_8GeV[i_run]) == 0)
1278  {
1279  energy = 1;
1280  return energy;
1281  }
1282  }
1283  for(int i_run = 0; i_run < 3; ++i_run) // 5 GeV
1284  {
1285  if(_mRunID.compare(hcal_5GeV[i_run]) == 0)
1286  {
1287  energy = 0;
1288  return energy;
1289  }
1290  }
1291 
1292  return energy;
1293 }