4 #include <prototype3/RawTower_Temperature.h>
5 #include <prototype3/RawTower_Prototype3.h>
6 #include <calobase/RawTowerContainer.h>
7 #include <calobase/RawTowerGeomContainer_Cylinderv1.h>
8 #include <pdbcalbase/PdbParameterMap.h>
9 #include <phparameter/PHParameters.h>
31 #include <TLorentzVector.h>
49 SubsysReco(
"Proto3ShowerCalib"), _is_sim(
false), _use_hodoscope_calibs(
false),_filename(filename), _ievent(
66 for (
int row = 0; row <
n_size; ++row)
87 <<
"Proto3ShowerCalib::get_HistoManager - Making Fun4AllHistoManager Proto3ShowerCalib_HISTOS"
102 cout <<
"Proto3ShowerCalib::InitRun" << endl;
105 cout<<
"IS THIS SIMULATION: "<<
_is_sim<<endl;
108 "PHCompositeNode",
"DST"));
111 std::cerr <<
PHWHERE <<
"DST Node missing, doing nothing." << std::endl;
113 "Failed to find DST node in EmcRawTowerBuilder::CreateNodes");
116 fmodbins[
i] = 0. +
i * 2. / (
float)(nfmodbins-1);
124 cout <<
"Proto3ShowerCalib::End - write to " <<
_filename << endl;
129 for (
unsigned int i = 0;
i < hm->
nHistos();
i++)
146 cout <<
"Proto3ShowerCalib::get_HistoManager - Making PHTFileServer "
155 TH2F * hCheck_Cherenkov =
new TH2F(
"hCheck_Cherenkov",
"hCheck_Cherenkov",
156 1000, -2000, 2000, 5, .5, 5.5);
157 hCheck_Cherenkov->GetYaxis()->SetBinLabel(1,
"C1");
158 hCheck_Cherenkov->GetYaxis()->SetBinLabel(2,
"C2 in");
159 hCheck_Cherenkov->GetYaxis()->SetBinLabel(3,
"C2 out");
160 hCheck_Cherenkov->GetYaxis()->SetBinLabel(4,
"C2 sum");
163 TH1F *
hNormalization =
new TH1F(
"hNormalization",
"hNormalization", 10, .5,
165 hCheck_Cherenkov->GetXaxis()->SetBinLabel(1,
"ALL");
166 hCheck_Cherenkov->GetXaxis()->SetBinLabel(2,
"C2-e");
167 hCheck_Cherenkov->GetXaxis()->SetBinLabel(3,
"trigger_veto_pass");
168 hCheck_Cherenkov->GetXaxis()->SetBinLabel(4,
"valid_hodo_h");
169 hCheck_Cherenkov->GetXaxis()->SetBinLabel(5,
"valid_hodo_v");
170 hCheck_Cherenkov->GetXaxis()->SetBinLabel(6,
"good_e");
171 hCheck_Cherenkov->GetXaxis()->SetBinLabel(7,
"good_data");
174 hm->
registerHisto(
new TH1F(
"hCheck_Veto",
"hCheck_Veto", 1000, -500, 500));
176 new TH1F(
"hCheck_Hodo_H",
"hCheck_Hodo_H", 1000, -500, 500));
178 new TH1F(
"hCheck_Hodo_V",
"hCheck_Hodo_V", 1000, -500, 500));
180 hm->
registerHisto(
new TH1F(
"hBeam_Mom",
"hBeam_Mom", 1200, -120, 120));
182 hm->
registerHisto(
new TH2F(
"hEoP",
"hEoP", 1000, 0, 1.5, 120, .5, 120.5));
184 hm->
registerHisto(
new TH1F(
"hTemperature",
"hTemperature", 500, 0, 50));
187 TTree *
T =
new TTree(
"T",
"T");
206 hodoinfile.open(
"/sphenix/user/jdosbo/Prototype3/EMCal/JoeShowerCalib/hodoscope_calibs_thirdjointenergyscan.txt",
ifstream::in);
209 if(hodoinfile.is_open()){
210 while (!hodoinfile.eof()){
213 float hodo0, hodo1, hodo2, hodo3, hodo4, hodo5, hodo6, hodo7;
214 hodoinfile>>hodo0>>hodo1>>hodo2>>hodo3>>hodo4>>hodo5>>hodo6>>hodo7;
230 if(!hodoinfile.is_open())
231 cout<<
"HODO CALIBRATION FILE DIDNT OPEN"<<endl;
237 infile.open(
"/sphenix/user/jdosbo/Prototype3/EMCal/JoeShowerCalib/3x3clus_posdep_recals_fromsim.txt");
240 if(infile.is_open()){
241 while(!infile.eof()){
246 float vals[nfmodbins-1];
247 infile>>vals[0]>>vals[1]>>vals[2]>>vals[3]>>vals[4]>>vals[5]>>vals[6]>>vals[7]
248 >>vals[8]>>vals[9]>>vals[10]>>vals[11]>>vals[12]>>vals[13]>>vals[14]>>vals[15];
250 for(
int i=0;
i<nfmodbins-1;
i++)
258 cout<<
"NO SIMULATION POSITION DEPENDENT RECAL OPEN"<<endl;
261 infile1.open(
"/sphenix/user/jdosbo/Prototype3/EMCal/JoeShowerCalib/5x5clus_posdep_recals_fromsim.txt");
264 if(infile1.is_open()){
265 while(!infile1.eof()){
270 float vals[nfmodbins-1];
271 infile1>>vals[0]>>vals[1]>>vals[2]>>vals[3]>>vals[4]>>vals[5]>>vals[6]>>vals[7]
272 >>vals[8]>>vals[9]>>vals[10]>>vals[11]>>vals[12]>>vals[13]>>vals[14]>>vals[15];
274 for(
int i=0;
i<nfmodbins-1;
i++)
282 cout<<
"NO SIMULATION POSITION DEPENDENT RECAL 5X5 OPEN"<<endl;
297 cout <<
"Proto3ShowerCalib::process_event() entered" << endl;
321 run_info_copy.FillFrom(info);
325 TH1F * hBeam_Mom =
dynamic_cast<TH1F *
>(hm->
getHisto(
"hBeam_Mom"));
335 EventHeader* eventheader = findNode::getClass<EventHeader>(topNode,
374 TH1F * hNormalization =
dynamic_cast<TH1F *
>(hm->
getHisto(
"hNormalization"));
377 hNormalization->Fill(
"ALL", 1);
380 topNode, _is_sim ?
"TOWER_RAW_LG_CEMC" :
"TOWER_RAW_CEMC");
383 topNode, _is_sim ?
"TOWER_CALIB_LG_CEMC" :
"TOWER_CALIB_CEMC");
391 assert(TOWER_CALIB_TRIGGER_VETO);
398 assert(TOWER_CALIB_HODO_HORIZONTAL);
404 assert(TOWER_CALIB_HODO_VERTICAL);
411 assert(TOWER_TEMPERATURE_EMCAL);
415 topNode,
"TOWER_CALIB_C1");
421 topNode,
"TOWER_CALIB_C2");
436 bool cherekov_e =
false;
445 t_c2_in = TOWER_CALIB_C2->
getTower(10);
446 t_c2_out = TOWER_CALIB_C2->
getTower(11);
450 t_c2_in = TOWER_CALIB_C2->
getTower(0);
451 t_c2_out = TOWER_CALIB_C2->
getTower(1);
463 hNormalization->Fill(
"C2-e", cherekov_e);
465 TH2F * hCheck_Cherenkov =
dynamic_cast<TH2F *
>(hm->
getHisto(
466 "hCheck_Cherenkov"));
468 hCheck_Cherenkov->Fill(c1,
"C1", 1);
469 hCheck_Cherenkov->Fill(c2_in,
"C2 in", 1);
470 hCheck_Cherenkov->Fill(c2_out,
"C2 out", 1);
471 hCheck_Cherenkov->Fill(c2_in + c2_out,
"C2 sum", 1);
475 TH1F * hCheck_Veto =
dynamic_cast<TH1F *
>(hm->
getHisto(
"hCheck_Veto"));
477 bool trigger_veto_pass =
true;
480 auto range = TOWER_CALIB_TRIGGER_VETO->
getTowers();
481 for (
auto it = range.first;
it != range.second; ++
it)
489 trigger_veto_pass =
false;
492 hNormalization->Fill(
"trigger_veto_pass", trigger_veto_pass);
496 TH1F * hCheck_Hodo_H =
dynamic_cast<TH1F *
>(hm->
getHisto(
"hCheck_Hodo_H"));
498 int hodo_h_count = 0;
501 auto range = TOWER_CALIB_HODO_HORIZONTAL->
getTowers();
502 for (
auto it = range.first;
it != range.second; ++
it)
516 const bool valid_hodo_h = hodo_h_count == 1;
517 hNormalization->Fill(
"valid_hodo_h", valid_hodo_h);
520 TH1F * hCheck_Hodo_V =
dynamic_cast<TH1F *
>(hm->
getHisto(
"hCheck_Hodo_V"));
522 int hodo_v_count = 0;
525 auto range = TOWER_CALIB_HODO_VERTICAL->
getTowers();
526 for (
auto it = range.first;
it != range.second; ++
it)
540 const bool valid_hodo_v = hodo_v_count == 1;
542 hNormalization->Fill(
"valid_hodo_v", valid_hodo_v);
544 const bool good_e = (valid_hodo_v and valid_hodo_h and cherekov_e
545 and trigger_veto_pass) and (not _is_sim);
546 hNormalization->Fill(
"good_e", good_e);
549 pair<int, int> max_3x3 =
find_max(TOWER_CALIB_CEMC, 3);
550 pair<int, int> max_5x5 =
find_max(TOWER_CALIB_CEMC, 5);
571 bool good_temp =
true;
572 double sum_energy_calib = 0;
573 double sum_energy_T = 0;
574 TH1F * hTemperature =
dynamic_cast<TH1F *
>(hm->
getHisto(
"hTemperature"));
581 std::vector<float> toweretas3x3;
582 std::vector<float> towerphis3x3;
583 std::vector<float> towerenergies3x3;
584 std::vector<float> toweretas5x5;
585 std::vector<float> towerphis5x5;
586 std::vector<float> towerenergies5x5;
595 auto range = TOWER_CALIB_CEMC->
getTowers();
596 for (
auto it = range.first;
it != range.second; ++
it)
608 if (col < 0 or col >= 8)
611 if (row < 0 or row >= 8)
614 if((hodorow<0 or hodorow>7) and !_is_sim)
616 if((hodocol<0 or hodocol>7) and !_is_sim)
619 const double energy_calib = tower->
get_energy();
620 sum_energy_calib += energy_calib;
625 double energy_T = energy_calib;
647 double energy_recalib=0;
650 energy_recalib = energy_T
658 sum_energy_T += energy_T;
663 if (col >= max_5x5.first - 1 and col <= max_5x5.first + 1
664 and row >= max_5x5.second - 1 and row <= max_5x5.second + 1)
676 if (col >= max_3x3.first - 1 and col <= max_3x3.first + 1)
677 if (row >= max_3x3.second - 1 and row <= max_3x3.second + 1)
698 toweretas3x3.push_back(col);
699 towerphis3x3.push_back(row);
700 towerenergies3x3.push_back(energy_calib);
707 if (col >= max_5x5.first - 2 and col <= max_5x5.first + 2)
708 if (row >= max_5x5.second - 2 and row <= max_5x5.second + 2)
728 toweretas5x5.push_back(col);
729 towerphis5x5.push_back(row);
730 towerenergies5x5.push_back(energy_calib);
752 int ntowers = toweretas3x3.size();
765 for (
int j = 0;
j < ntowers;
j++)
767 float energymult = towerenergies3x3.at(
j) * toweretas3x3.at(
j);
768 etamult += energymult;
769 etasum += towerenergies3x3.at(
j);
771 int phibin = towerphis3x3.at(
j);
773 if (phibin - towerphis3x3.at(0) < -nphibin / 2)
775 else if (phibin - towerphis3x3.at(0) > +nphibin / 2)
777 assert(abs(phibin - towerphis3x3.at(0)) <= nphibin / 2);
779 energymult = towerenergies3x3.at(
j) * phibin;
780 phimult += energymult;
781 phisum += towerenergies3x3.at(
j);
785 float avgphi = phimult / phisum;
786 float avgeta = etamult / etasum;
788 if (avgphi<0) avgphi += nphibin;
791 float fmodphi3x3 = fmod(avgphi, 2.);
792 float fmodeta3x3 = fmod(avgeta, 2.);
797 int fmodetabin = -99;
798 int fmodphibin = -99;
799 for(
int k=0;
k<nfmodbins-1;
k++)
802 for(
int k=0;
k<nfmodbins-1;
k++)
815 ntowers = toweretas5x5.size();
822 for (
int j = 0;
j < ntowers;
j++)
824 float energymult = towerenergies5x5.at(
j) * toweretas5x5.at(
j);
825 etamult += energymult;
826 etasum += towerenergies5x5.at(
j);
828 int phibin = towerphis5x5.at(
j);
830 if (phibin - towerphis5x5.at(0) < -nphibin / 2)
832 else if (phibin - towerphis5x5.at(0) > +nphibin / 2)
834 assert(abs(phibin - towerphis5x5.at(0)) <= nphibin / 2);
836 energymult = towerenergies5x5.at(
j) * phibin;
837 phimult += energymult;
838 phisum += towerenergies5x5.at(
j);
841 float avgphi = phimult / phisum;
842 float avgeta = etamult / etasum;
844 if (avgphi < 0) avgphi += nphibin;
846 float fmodphi5x5 = fmod(avgphi , 2.);
847 float fmodeta5x5 = fmod(avgeta , 2.);
852 int fmodetabin = -99;
853 int fmodphibin = -99;
854 for(
int k=0;
k<nfmodbins-1;
k++)
857 for(
int k=0;
k<nfmodbins-1;
k++)
880 hNormalization->Fill(
"good_temp", good_temp);
883 bool good_data = good_e;
884 hNormalization->Fill(
"good_data", good_data);
896 cout << __PRETTY_FUNCTION__ <<
" sum_energy_calib = "
897 << sum_energy_calib <<
" sum_energy_T = " << sum_energy_T
900 TH2F * hEoP =
dynamic_cast<TH2F *
>(hm->
getHisto(
"hEoP"));
916 fdata << sdata.str();
921 TTree * T =
dynamic_cast<TTree *
>(hm->
getHisto(
"T"));
931 const int clus_edge_size = (cluster_size - 1) / 2;
932 assert(clus_edge_size >= 0);
934 pair<int, int> max(-1000, -1000);
938 for (
int row = 0; row <
n_size; ++row)
942 for (
int dcol = col - clus_edge_size; dcol <= col + clus_edge_size;
944 for (
int drow = row - clus_edge_size; drow <= row + clus_edge_size;
947 if (dcol < 0 or drow < 0)
957 max = make_pair(col, row);
970 cout << __PRETTY_FUNCTION__ <<
" - input recalibration constant from "
974 ifstream fcalib(file);
980 while (not fcalib.eof())
982 getline(fcalib, line);
986 cout << __PRETTY_FUNCTION__ <<
" get line " << line << endl;
988 istringstream sline(line);
994 sline >> col >> row >> calib;
996 if (not sline.fail())
1000 cout << __PRETTY_FUNCTION__ <<
" - recalibration constant "
1001 << col <<
"," << row <<
" = " << calib << endl;