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>
10 #include <Event/EventTypes.h>
29 #include <TLorentzVector.h>
80 <<
"Proto4TowerCalib::get_HistoManager - Making Fun4AllHistoManager Proto4TowerCalib_HISTOS"
94 cout <<
"Proto4TowerCalib::InitRun" << endl;
100 "PHCompositeNode",
"DST"));
103 std::cerr <<
PHWHERE <<
"DST Node missing, doing nothing." << std::endl;
105 "Failed to find DST node in EmcRawTowerBuilder::CreateNodes");
113 cout <<
"Proto4TowerCalib::End - write to " <<
_filename << endl;
118 for (
unsigned int i = 0;
i < hm->
nHistos();
i++)
131 cout <<
"Proto4TowerCalib::get_HistoManager - Making PHTFileServer "
139 TH1F *
hNormalization =
new TH1F(
"hNormalization",
"hNormalization", 1, 0.5, 1.5);
140 hNormalization->GetXaxis()->SetBinLabel(1,
"ALL");
141 hNormalization->GetXaxis()->SetTitle(
"Cuts");
142 hNormalization->GetYaxis()->SetTitle(
"Event count");
148 TH1F *h_hcalin_tower_sim[16];
149 TH1F *h_hcalout_tower_sim[16];
150 for(
int i_tower = 0; i_tower < 16; ++i_tower)
153 HistName_sim = Form(
"h_hcalin_tower_%d_sim",i_tower);
154 h_hcalin_tower_sim[i_tower] =
new TH1F(HistName_sim.c_str(),HistName_sim.c_str(),500,-0.5,99.5);
157 HistName_sim = Form(
"h_hcalout_tower_%d_sim",i_tower);
158 h_hcalout_tower_sim[i_tower] =
new TH1F(HistName_sim.c_str(),HistName_sim.c_str(),500,-0.5,99.5);
164 TH1F *h_hcalin_lg_tower_raw[16];
165 TH1F *h_hcalin_lg_tower_calib[16];
166 for(
int i_tower = 0; i_tower < 16; ++i_tower)
168 string HistName_raw = Form(
"h_hcalin_lg_tower_%d_raw",i_tower);
169 h_hcalin_lg_tower_raw[i_tower] =
new TH1F(HistName_raw.c_str(),HistName_raw.c_str(),40,0.5,16000.5);
172 string HistName_calib = Form(
"h_hcalin_lg_tower_%d_calib",i_tower);
173 h_hcalin_lg_tower_calib[i_tower] =
new TH1F(HistName_calib.c_str(),HistName_calib.c_str(),100,-0.5,19.5);
178 TH1F *h_hcalout_lg_tower_raw[16];
179 TH1F *h_hcalout_lg_tower_calib[16];
180 for(
int i_tower = 0; i_tower < 16; ++i_tower)
182 string HistName_raw = Form(
"h_hcalout_lg_tower_%d_raw",i_tower);
183 h_hcalout_lg_tower_raw[i_tower] =
new TH1F(HistName_raw.c_str(),HistName_raw.c_str(),40,0.5,16000.5);
186 string HistName_calib = Form(
"h_hcalout_lg_tower_%d_calib",i_tower);
187 h_hcalout_lg_tower_calib[i_tower] =
new TH1F(HistName_calib.c_str(),HistName_calib.c_str(),100,-0.5,19.5);
192 TH1F *h_hcalout_hg_tower_raw[16];
193 TH1F *h_hcalout_hg_tower_calib[16];
194 for(
int i_tower = 0; i_tower < 16; ++i_tower)
196 string HistName_raw = Form(
"h_hcalout_hg_tower_%d_raw",i_tower);
197 h_hcalout_hg_tower_raw[i_tower] =
new TH1F(HistName_raw.c_str(),HistName_raw.c_str(),40,0.5,16000.5);
200 string HistName_calib = Form(
"h_hcalout_hg_tower_%d_calib",i_tower);
201 h_hcalout_hg_tower_calib[i_tower] =
new TH1F(HistName_calib.c_str(),HistName_calib.c_str(),100,-0.5,19.5);
206 TTree *
T =
new TTree(
"HCAL_Info",
"HCAL_Info");
210 T->Branch(
"TowerCalib", &
_tower);
218 cout <<
"Proto4TowerCalib::process_event() entered" << endl;
260 hNormalization->Fill(
"ALL", 1);
276 assert(TOWER_SIM_HCALOUT);
282 assert(TOWER_RAW_LG_HCALIN);
286 assert(TOWER_CALIB_LG_HCALIN);
291 assert(TOWER_RAW_LG_HCALOUT);
295 assert(TOWER_CALIB_LG_HCALOUT);
300 assert(TOWER_RAW_HG_HCALOUT);
304 assert(TOWER_CALIB_HG_HCALOUT);
312 double hcalin_sum_e_sim = 0;
313 double hcalout_sum_e_sim = 0;
315 auto range_hcalin_sim = TOWER_SIM_HCALIN->
getTowers();
316 for (
auto it = range_hcalin_sim.first;
it != range_hcalin_sim.second; ++
it)
329 if (col < 0 or col >= 4)
331 if (row < 0 or row >= 4)
334 const double energy_sim = tower->
get_energy();
335 hcalin_sum_e_sim += energy_sim;
338 string HistName_sim = Form(
"h_hcalin_tower_%d_sim",chanNum);
339 TH1F *h_hcalin_sim =
dynamic_cast<TH1F *
>(hm->
getHisto(HistName_sim.c_str()));
345 auto range_hcalout_sim = TOWER_SIM_HCALOUT->
getTowers();
346 for (
auto it = range_hcalout_sim.first;
it != range_hcalout_sim.second; ++
it)
357 if (col < 0 or col >= 4)
359 if (row < 0 or row >= 4)
362 const double energy_sim = tower->
get_energy();
363 hcalout_sum_e_sim += energy_sim;
366 string HistName_sim = Form(
"h_hcalout_tower_%d_sim",chanNum);
367 TH1F *h_hcalout_sim =
dynamic_cast<TH1F *
>(hm->
getHisto(HistName_sim.c_str()));
374 _tower.
hcal_asym_sim = (hcalin_sum_e_sim - hcalout_sum_e_sim)/(hcalin_sum_e_sim + hcalout_sum_e_sim);
378 double hcalin_sum_lg_e_raw = 0;
379 double hcalin_sum_lg_e_calib = 0;
381 auto range_hcalin_lg_raw = TOWER_RAW_LG_HCALIN->
getTowers();
382 for (
auto it = range_hcalin_lg_raw.first;
it != range_hcalin_lg_raw.second; ++
it)
394 if (col < 0 or col >= 4)
396 if (row < 0 or row >= 4)
399 const double energy_raw = tower->
get_energy();
400 hcalin_sum_lg_e_raw += energy_raw;
403 string HistName_raw = Form(
"h_hcalin_lg_tower_%d_raw",chanNum);
404 TH1F *h_hcalin_lg_raw =
dynamic_cast<TH1F *
>(hm->
getHisto(HistName_raw.c_str()));
410 auto range_hcalin_lg_calib = TOWER_CALIB_LG_HCALIN->
getTowers();
411 for (
auto it = range_hcalin_lg_calib.first;
it != range_hcalin_lg_calib.second; ++
it)
420 if (col < 0 or col >= 4)
422 if (row < 0 or row >= 4)
425 const double energy_calib = tower->
get_energy();
426 hcalin_sum_lg_e_calib += energy_calib;
429 string HistName_calib = Form(
"h_hcalin_lg_tower_%d_calib",chanNum);
430 TH1F *h_hcalin_lg_calib =
dynamic_cast<TH1F *
>(hm->
getHisto(HistName_calib.c_str()));
431 assert(h_hcalin_lg_calib);
438 double hcalout_sum_lg_e_raw = 0;
439 double hcalout_sum_lg_e_calib = 0;
441 auto range_hcalout_lg_raw = TOWER_RAW_LG_HCALOUT->
getTowers();
442 for (
auto it = range_hcalout_lg_raw.first;
it != range_hcalout_lg_raw.second; ++
it)
455 if (col < 0 or col >= 4)
457 if (row < 0 or row >= 4)
460 const double energy_raw = tower->
get_energy();
461 hcalout_sum_lg_e_raw += energy_raw;
464 string HistName_raw = Form(
"h_hcalout_lg_tower_%d_raw",chanNum);
465 TH1F *h_hcalout_lg_raw =
dynamic_cast<TH1F *
>(hm->
getHisto(HistName_raw.c_str()));
471 auto range_hcalout_lg_calib = TOWER_CALIB_LG_HCALOUT->
getTowers();
472 for (
auto it = range_hcalout_lg_calib.first;
it != range_hcalout_lg_calib.second; ++
it)
481 if (col < 0 or col >= 4)
483 if (row < 0 or row >= 4)
486 const double energy_calib = tower->
get_energy();
487 hcalout_sum_lg_e_calib += energy_calib;
490 string HistName_calib = Form(
"h_hcalout_lg_tower_%d_calib",chanNum);
491 TH1F *h_hcalout_lg_calib =
dynamic_cast<TH1F *
>(hm->
getHisto(HistName_calib.c_str()));
492 assert(h_hcalout_lg_calib);
499 double hcalout_sum_hg_e_raw = 0;
500 double hcalout_sum_hg_e_calib = 0;
502 auto range_hcalout_hg_raw = TOWER_RAW_HG_HCALOUT->
getTowers();
503 for (
auto it = range_hcalout_hg_raw.first;
it != range_hcalout_hg_raw.second; ++
it)
516 if (col < 0 or col >= 4)
518 if (row < 0 or row >= 4)
521 const double energy_raw = tower->
get_energy();
522 hcalout_sum_hg_e_raw += energy_raw;
525 string HistName_raw = Form(
"h_hcalout_hg_tower_%d_raw",chanNum);
526 TH1F *h_hcalout_hg_raw =
dynamic_cast<TH1F *
>(hm->
getHisto(HistName_raw.c_str()));
533 auto range_hcalout_hg_calib = TOWER_CALIB_HG_HCALOUT->
getTowers();
534 for (
auto it = range_hcalout_hg_calib.first;
it != range_hcalout_hg_calib.second; ++
it)
543 if (col < 0 or col >= 4)
545 if (row < 0 or row >= 4)
548 const double energy_calib = tower->
get_energy();
549 hcalout_sum_hg_e_calib += energy_calib;
552 string HistName_calib = Form(
"h_hcalout_hg_tower_%d_calib",chanNum);
553 TH1F *h_hcalout_hg_calib =
dynamic_cast<TH1F *
>(hm->
getHisto(HistName_calib.c_str()));
554 assert(h_hcalout_hg_calib);
563 _tower.
hcal_asym_raw = (hcalin_sum_lg_e_raw - hcalout_sum_lg_e_raw)/(hcalin_sum_lg_e_raw + hcalout_sum_lg_e_raw);
564 _tower.
hcal_asym_calib = (hcalin_sum_lg_e_calib - hcalout_sum_lg_e_calib)/(hcalin_sum_lg_e_calib + hcalout_sum_lg_e_calib);
566 TTree *
T =
dynamic_cast<TTree *
>(hm->
getHisto(
"HCAL_Info"));
576 const int clus_edge_size = (cluster_size - 1) / 2;
577 assert(clus_edge_size >= 0);
579 pair<int, int> max(-1000, -1000);
583 for (
int row = 0; row <
n_size; ++row)
587 for (
int dcol =
col - clus_edge_size; dcol <=
col + clus_edge_size;
589 for (
int drow = row - clus_edge_size; drow <= row + clus_edge_size;
592 if (dcol < 0 or drow < 0)
602 max = make_pair(
col, row);
614 int hbdchanIHC[4][4] = {{4, 8, 12, 16},
619 return hbdchanIHC[row][column] - 1;
624 int hbdchanIHC[4][4] = {{13, 9, 5, 1},
629 return hbdchanIHC[row][column] - 1;
639 string inputdir =
"/sphenix/user/xusun/TestBeam/TowerCalib/";
640 string InPutList = Form(
"/direct/phenix+u/xusun/WorkSpace/sPHENIX/analysis/Prototype4/HCal/macros/list/Proto4TowerInfo%s_%s_%d.list",
_mList.c_str(),
_mDet.c_str(),
_mCol);
644 if (!InPutList.empty())
646 cout <<
"Open input database file list: " << InPutList.c_str() << endl;
647 ifstream
in(InPutList.c_str());
650 cout <<
"input database file list is ok" << endl;
652 Long64_t entries_save = 0;
660 addfile = inputdir+addfile;
661 mChainInPut->AddFile(addfile.c_str(),-1,
"HCAL_Info");
662 long file_entries = mChainInPut->GetEntries();
663 cout <<
"File added to data chain: " << addfile.c_str() <<
" with " << (file_entries-entries_save) <<
" entries" << endl;
664 entries_save = file_entries;
670 cout <<
"WARNING: input database file input is problemtic" << endl;
676 if (
_mInPut_flag == 1 && !mChainInPut->GetBranch(
"TowerCalib" ))
678 cerr <<
"ERROR: Could not find branch 'HCAL_Tower' in tree!" << endl;
684 mChainInPut->SetBranchAddress(
"TowerCalib", &
_mTower);
686 long NumOfEvents = (long)mChainInPut->GetEntries();
687 cout <<
"total number of events: " << NumOfEvents << endl;
693 for(
int i_tower = 0; i_tower < 16; ++i_tower)
696 if(
_is_sim)
h_mHCAL[i_tower] =
new TH1F(HistName.c_str(),HistName.c_str(),500,0.5,100.5);
697 if(!
_is_sim)
h_mHCAL[i_tower] =
new TH1F(HistName.c_str(),HistName.c_str(),80,0.5,16000.5);
706 cout <<
"Make()" << endl;
713 for(
unsigned long i_event = start_event_use; i_event < stop_event_use; ++i_event)
721 for(
int i_tower = 0; i_tower < 16; ++i_tower)
723 if(
_mDet ==
"HCALIN")
728 if(
_mDet ==
"HCALOUT")
737 for(
int i_tower = 0; i_tower < 16; ++i_tower)
739 if(
_mDet ==
"HCALIN")
744 if(
_mDet ==
"HCALOUT")
764 cout <<
"Finish()" << endl;
767 for(
int i_tower = 0; i_tower < 16; ++i_tower)
793 for(
int i_row = 0; i_row < 4; ++i_row)
805 for(
int i_tower = 0; i_tower < 16; ++i_tower)