From d721dced17f7627413aefa7a1e26a4f1ca198218 Mon Sep 17 00:00:00 2001 From: Vardan Tadevosyan <tadevosn@jlab.org> Date: Thu, 13 Mar 2014 19:31:44 +0400 Subject: [PATCH] Add saving raw data for HMS calorimeter calibration into file. --- hcal_calib/THcShHit.h | 12 ++-- hcal_calib/THcShTrack.h | 16 +++-- hcal_calib/THcShowerCalib.h | 129 +++++------------------------------- hcal_calib/hcal_calib.cpp | 14 ++-- 4 files changed, 40 insertions(+), 131 deletions(-) diff --git a/hcal_calib/THcShHit.h b/hcal_calib/THcShHit.h index 8b277b8..5807edf 100644 --- a/hcal_calib/THcShHit.h +++ b/hcal_calib/THcShHit.h @@ -35,7 +35,7 @@ class THcShHit { UInt_t GetBlkNumber() {return BlkNumber;} - void Print(); + void Print(ostream & ostrm); }; THcShHit::THcShHit() { @@ -57,10 +57,12 @@ THcShHit::THcShHit(Double_t adc_pos, Double_t adc_neg, THcShHit::~THcShHit() { }; -void THcShHit::Print() { - cout << "Hit: ADCpos =" << ADCpos << " ADCneg =" << ADCneg - << " Epos =" << Epos << " Eneg =" << Eneg - << " BlkNumber=" << BlkNumber << endl; +void THcShHit::Print(ostream & ostrm) { + // ostrm << "Hit: ADCpos =" << ADCpos << " ADCneg =" << ADCneg + // << " Epos =" << Epos << " Eneg =" << Eneg + // << " BlkNumber=" << BlkNumber << endl; + ostrm << ADCpos << " " << ADCneg << " " << Epos << " " << Eneg << " " + << BlkNumber << endl; }; struct pmt_hit {Double_t signal; UInt_t channel;}; diff --git a/hcal_calib/THcShTrack.h b/hcal_calib/THcShTrack.h index 506bc99..defd5be 100644 --- a/hcal_calib/THcShTrack.h +++ b/hcal_calib/THcShTrack.h @@ -4,6 +4,7 @@ #include <vector> #include <iterator> #include <iostream> +#include <fstream> using namespace std; @@ -46,7 +47,7 @@ class THcShTrack { UInt_t GetNhits() {return Hits.size();}; - void Print(); + void Print(ostream & ostrm); // Bool_t CheckHitNumber(); @@ -126,14 +127,15 @@ THcShHit* THcShTrack::GetHit(UInt_t k) { return *it; } -void THcShTrack::Print() { - cout << "ShTrack: P=" << P << " X=" << X << " Xp=" << Xp - << " Y=" << Y << " Yp=" << Yp << endl; - // << " Y=" << Y << " Yp=" << Yp << " Nhits=" << Nhits << endl; - cout << "Hits size=" << Hits.size() << endl; +void THcShTrack::Print(ostream & ostrm) { + // ostrm << "ShTrack: P=" << P << " X=" << X << " Xp=" << Xp + // << " Y=" << Y << " Yp=" << Yp << endl; + // ostrm << "Hits size=" << Hits.size() << endl; + ostrm << P << " " << X << " " << Xp << " " << Y << " " << Yp << " " + << Hits.size() << endl; for (THcShHitIt iter = Hits.begin(); iter != Hits.end(); iter++) { - (*iter)->Print(); + (*iter)->Print(ostrm); }; }; diff --git a/hcal_calib/THcShowerCalib.h b/hcal_calib/THcShowerCalib.h index 3a4e027..9c5e03a 100644 --- a/hcal_calib/THcShowerCalib.h +++ b/hcal_calib/THcShowerCalib.h @@ -27,7 +27,6 @@ class THcShowerCalib { THcShowerCalib(); ~THcShowerCalib(); - void ExtractData(); void Init(); void ReadShRawTrack(THcShTrack &trk, UInt_t ientry); void CalcThresholds(); @@ -35,6 +34,7 @@ class THcShowerCalib { void SolveAlphas(); void FillHEcal(); void SaveAlphas(); + void SaveRawData(); TH1F* hEunc; TH1F* hEuncSel; @@ -85,120 +85,25 @@ THcShowerCalib::~THcShowerCalib() { //------------------------------------------------------------------------------ -void THcShowerCalib::ExtractData() { +void THcShowerCalib::SaveRawData() { - // Extract data for calibration from the Root file. - // Loop over ntuples to get track parameters and calorimeter - // hit quantities. + // Output raw data into file for debug purposes. - char* fname = Form("Root_files/hcal_calib_%d.root",fRunNumber); - cout << "THcShowerCalib::ExtractData: fname= " << fname << endl; - - //Reset ROOT and connect tree file - gROOT->Reset(); - // TFile *f = (TFile*)gROOT->GetListOfFiles()->FindObject(fname); - TFile *f = new TFile(fname); - // if (!f) { - // f = new TFile(fname); - // } - TTree* tree; - f->GetObject("T",tree); - - //Declaration of leaves types - - // Calorimeter ADC signals. - - Double_t H_cal_1pr_aneg_p[THcShTrack::fNrows]; - Double_t H_cal_1pr_apos_p[THcShTrack::fNrows]; - - Double_t H_cal_2ta_aneg_p[THcShTrack::fNrows]; - Double_t H_cal_2ta_apos_p[THcShTrack::fNrows]; - - Double_t H_cal_3ta_aneg_p[THcShTrack::fNrows]; - Double_t H_cal_3ta_apos_p[THcShTrack::fNrows]; - - Double_t H_cal_4ta_aneg_p[THcShTrack::fNrows]; - Double_t H_cal_4ta_apos_p[THcShTrack::fNrows]; - - // Track parameters. + cout << "SaveRawData: Output raw data into hcal_calib.raw_data." << endl; - Double_t H_cal_trp; - Double_t H_cal_trx; - Double_t H_cal_trxp; - Double_t H_cal_try; - Double_t H_cal_tryp; - - // Set branch addresses. - - tree->SetBranchAddress("H.cal.1pr.aneg_p",H_cal_1pr_aneg_p); - tree->SetBranchAddress("H.cal.1pr.apos_p",H_cal_1pr_apos_p); - - tree->SetBranchAddress("H.cal.2ta.aneg_p",H_cal_2ta_aneg_p); - tree->SetBranchAddress("H.cal.2ta.apos_p",H_cal_2ta_apos_p); - - tree->SetBranchAddress("H.cal.3ta.aneg_p",H_cal_3ta_aneg_p); - tree->SetBranchAddress("H.cal.3ta.apos_p",H_cal_3ta_apos_p); - - tree->SetBranchAddress("H.cal.4ta.aneg_p",H_cal_4ta_aneg_p); - tree->SetBranchAddress("H.cal.4ta.apos_p",H_cal_4ta_apos_p); - - tree->SetBranchAddress("H.cal.trp",&H_cal_trp); - tree->SetBranchAddress("H.cal.trx",&H_cal_trx); - tree->SetBranchAddress("H.cal.trxp",&H_cal_trxp); - tree->SetBranchAddress("H.cal.try",&H_cal_try); - tree->SetBranchAddress("H.cal.tryp",&H_cal_tryp); + ofstream fout; + fout.open("hcal_calib.raw_data",ios::out); - Long64_t nentries = tree->GetEntries(); - cout << "THcShowerCalib::ExtractData: nentries= " << nentries << endl; - - // Output stream. + THcShTrack trk; - char* FName = Form("raw_data/%d_raw.dat",fRunNumber); - cout << "ExtractData: FName=" << FName << endl; - ofstream output; - output.open(FName,ios::out); - - // Loop over ntuples. - - Long64_t nbytes = 0; - for (Long64_t i=0; i<nentries;i++) { - nbytes += tree->GetEntry(i); - Int_t nhit = 0; - for (Int_t j=0; j<THcShTrack::fNrows; j++) { - if (H_cal_1pr_apos_p[j]>0. || H_cal_1pr_aneg_p[j]>0.) nhit++; - if (H_cal_2ta_apos_p[j]>0. || H_cal_2ta_aneg_p[j]>0.) nhit++; - if (H_cal_3ta_apos_p[j]>0. || H_cal_3ta_aneg_p[j]>0.) nhit++; - if (H_cal_4ta_apos_p[j]>0. || H_cal_4ta_aneg_p[j]>0.) nhit++; - } - output << nhit << " " << H_cal_trp << " " - << H_cal_trx << " " << H_cal_trxp << " " - << H_cal_try << " " << H_cal_tryp << endl; - for (Int_t j=0; j<THcShTrack::fNrows; j++) { - if (H_cal_1pr_apos_p[j]>0. || H_cal_1pr_aneg_p[j]>0.) - output << H_cal_1pr_apos_p[j] << " " << H_cal_1pr_aneg_p[j] << " " - << j+1 << endl; - } - for (Int_t j=0; j<THcShTrack::fNrows; j++) { - if (H_cal_2ta_apos_p[j]>0. || H_cal_2ta_aneg_p[j]>0.) - output << H_cal_2ta_apos_p[j] << " " << H_cal_2ta_aneg_p[j] << " " - << j+1 + THcShTrack::fNrows << endl; - } - for (Int_t j=0; j<THcShTrack::fNrows; j++) { - if (H_cal_3ta_apos_p[j]>0. || H_cal_3ta_aneg_p[j]>0.) - output << H_cal_3ta_apos_p[j] << " " << H_cal_3ta_aneg_p[j] << " " - << j+1 + 2*THcShTrack::fNrows << endl; - } - for (Int_t j=0; j<THcShTrack::fNrows; j++) { - if (H_cal_4ta_apos_p[j]>0. || H_cal_4ta_aneg_p[j]>0.) - output << H_cal_4ta_apos_p[j] << " " << H_cal_4ta_aneg_p[j] << " " - << j+1 + 3*THcShTrack::fNrows << endl; - } + for (UInt_t ientry=0; ientry<fNentries; ientry++) { + ReadShRawTrack(trk, ientry); + trk.SetEs(falphaC); + trk.Print(fout); + } - } // over entries + fout.close(); - f->Close(); - output.close(); - cout << "THcShowerCalib::ExtractData: nbytes= " << nbytes << endl; } //------------------------------------------------------------------------------ @@ -287,7 +192,7 @@ void THcShowerCalib::CalcThresholds() { ReadShRawTrack(trk, ientry); - // trk.Print(); + // trk.Print(cout); // getchar(); trk.SetEs(falpha0); @@ -452,7 +357,7 @@ void THcShowerCalib::ComposeVMs() { if (Enorm>fLoThr && Enorm<fHiThr) { trk.SetEs(falpha1); // Set energies with unit gains for now. - // trk.Print(); + // trk.Print(cout); fe0 += trk.GetP(); // Accumulate track momenta. @@ -463,7 +368,7 @@ void THcShowerCalib::ComposeVMs() { for (UInt_t i=0; i<trk.GetNhits(); i++) { THcShHit* hit = trk.GetHit(i); - // hit->Print(); + // hit->Print(cout); UInt_t nb = hit->GetBlkNumber(); @@ -723,7 +628,7 @@ void THcShowerCalib::FillHEcal() { for (UInt_t ientry=0; ientry<fNentries; ientry++) { ReadShRawTrack(trk, ientry); - // trk.Print(); + // trk.Print(cout); trk.SetEs(falphaC); // use 'constrained' calibration constants // trk.SetEs(falphaU); diff --git a/hcal_calib/hcal_calib.cpp b/hcal_calib/hcal_calib.cpp index b2cdcf8..032364c 100644 --- a/hcal_calib/hcal_calib.cpp +++ b/hcal_calib/hcal_calib.cpp @@ -11,13 +11,13 @@ void hcal_calib(Int_t RunNumber) { THcShowerCalib theShowerCalib(RunNumber); - // theShowerCalib.ExtractData(); // Extract data from the Root file - theShowerCalib.Init(); // Initialize constants adn variables - theShowerCalib.CalcThresholds(); // Thresholds on the uncalibrated Edep/P - theShowerCalib.ComposeVMs(); // Compute vectors amd matrices for calib. - theShowerCalib.SolveAlphas(); // Solve for the calibration constants - theShowerCalib.FillHEcal(); // Fill histograms - theShowerCalib.SaveAlphas(); // Save the constants + theShowerCalib.Init(); // Initialize constants adn variables + theShowerCalib.CalcThresholds(); // Thresholds on the uncalibrated Edep/P + theShowerCalib.ComposeVMs(); // Compute vectors amd matrices for calib. + theShowerCalib.SolveAlphas(); // Solve for the calibration constants + theShowerCalib.SaveAlphas(); // Save the constants + theShowerCalib.SaveRawData(); // Save raw data into file for debug purposes + theShowerCalib.FillHEcal(); // Fill histograms // Plot histograms -- GitLab