17 if (inTotFile.empty())
return false;
19 TFile totFile(inTotFile.c_str(),
"READ");
20 if (not totFile.IsOpen()) {
21 printf(
"Error - File %s could not be opened.\n",inTotFile.c_str());
25 printf(
"File %s opened.\n",inTotFile.c_str());
26 printf(
"Running TOT calibration...\n");
30 std::vector< std::vector< std::unique_ptr<TH1F> > > histogramsTOT;
31 std::vector< std::vector< std::unique_ptr<TH1F> > > histogramsTOTsig;
32 for(
unsigned int FE = 0; FE <
m_nFE; FE++){
34 histogramsTOT.push_back( std::vector< std::unique_ptr<TH1F> >() );
35 histogramsTOTsig.push_back( std::vector< std::unique_ptr<TH1F> >() );
41 htot->SetDirectory(0);
43 htotsig->SetDirectory(0);
45 histogramsTOT.at(FE).push_back(std::move(htot));
47 histogramsTOTsig.at(FE).push_back(std::move(htotsig));
55 while ((rodKey=
static_cast<TKey*
>(rodItr()))) {
56 TDirectoryFile* rodDir =
static_cast<TDirectoryFile*
>(rodKey->ReadObj());
58 const TString rodName(rodKey->GetName());
59 printf(
"%s\n",rodName.Data());
61 while ((modKey=
static_cast<TKey*
>(modItr()))) {
62 const TString
modName(modKey->GetName());
71 printf(
" -> %s\n",
modName.Data());
74 std::array<std::array<float, m_ncharge>,
m_nFE> totArrI{};
75 std::array<std::array<float, m_ncharge>,
m_nFE> totErrArrI{};
76 std::array<std::array<float, m_ncharge>,
m_nFE> totSigArrI{};
77 std::array<std::array<float, m_ncharge>,
m_nFE> totSigErrArrI{};
78 std::array<std::array<float, m_ncharge>,
m_nFE> totLongArrI{};
79 std::array<std::array<float, m_ncharge>,
m_nFE> totErrLongArrI{};
87 if(!h2dTOTmean or !h2dTOTsig) {
90 h2dTOTmean->SetDirectory(0);
91 h2dTOTsig->SetDirectory(0);
93 for (
unsigned int ieta = 0; ieta <
m_etaBins; ieta++) {
94 for (
unsigned int iphi = 0; iphi <
m_phiBins; iphi++) {
95 float totmean = h2dTOTmean->GetBinContent(ieta + 1, iphi + 1);
96 float totsig = h2dTOTsig ->GetBinContent(ieta + 1, iphi + 1);
102 int FE =
chipId(iphi, ieta);
109 histogramsTOT.at(FE).at(
pixel)->Fill(totmean);
110 histogramsTOTsig.at(FE).at(
pixel)->Fill(totsig);
120 for(
unsigned int FE = 0; FE <
m_nFE; FE++){
124 totArrI.at(FE).at(
c) = histogramsTOT.at(FE).at(
pixel)->GetMean();
125 totErrArrI.at(FE).at(
c) = histogramsTOT.at(FE).at(
pixel)->GetMeanError();
126 totSigArrI.at(FE).at(
c) = std::sqrt(
std::pow(histogramsTOTsig.at(FE).at(
pixel)->GetMean() ,2)+
std::pow(histogramsTOT.at(FE).at(
pixel)->GetRMS() ,2));
127 totSigErrArrI.at(FE).at(
c) = std::sqrt(
std::pow(histogramsTOTsig.at(FE).at(
pixel)->GetMeanError(),2)+
std::pow(histogramsTOT.at(FE).at(
pixel)->GetRMSError(),2));
129 if(totSigErrArrI.at(FE).at(
c) > 1.0){
130 totArrI.at(FE).at(
c) = 0.0;
135 totLongArrI.at(FE).at(
c) = histogramsTOT.at(FE).at(
pixel)->GetMean();
136 totErrLongArrI.at(FE).at(
c) = histogramsTOT.at(FE).at(
pixel)->GetMeanError();
138 if(totErrLongArrI.at(FE).at(
c) > 1.0){
139 totLongArrI.at(FE).at(
c) = 0.0;
145 histogramsTOT.at(FE).at(
pixel)->Reset(
"ICESM");
146 histogramsTOTsig.at(FE).at(
pixel)->Reset(
"ICESM");
152 for(
unsigned int FE = 0; FE <
m_nFE; FE++) {
156 std::vector<float> v_Q;
157 std::vector<float> v_Qerr;
158 std::vector<float> v_TOT;
159 std::vector<float> v_TOTerr;
160 std::vector<float> v_TOTsig;
161 std::vector<float> v_TOTsigerr;
162 std::vector<float> v_TOTlong;
163 std::vector<float> v_TOTlongerr;
174 std::vector<float> pixNormalParams;
175 std::vector<float> pixNormalParamsQuality;
176 std::vector<float> pixSigParams;
177 std::vector<float> pixSigParamsQuality;
178 std::vector<float> pixLongParams;
179 std::vector<float> pixLongParamsQuality;
184 int vecsize = v_Q.size();
186 std::unique_ptr<TGraphErrors> graphnormal = std::make_unique<TGraphErrors>(vecsize, &v_Q.at(0), &v_TOT.at(0) , &v_Qerr.at(0), &v_TOTerr.at(0) );
187 std::unique_ptr<TGraphErrors> graphsig = std::make_unique<TGraphErrors>(vecsize, &v_Q.at(0), &v_TOTsig.at(0) , &v_Qerr.at(0), &v_TOTsigerr.at(0) );
192 graphnormal->Fit(functnormal.get() ,
"MRQ");
193 graphsig ->Fit(functnormalsig.get(),
"MRQ");
195 pixNormalParams =
getParams(functnormal.get() ,3 );
196 pixSigParams =
getParams(functnormalsig.get(),2 );
213 graphnormal->Write(TString(
"normal_fit_"+
std::to_string(n_fit)), TObject::kWriteDelete);
214 graphsig->Write(TString(
"smearing_fit_"+
std::to_string(n_fit)), TObject::kWriteDelete);
219 functnormalsig.reset();
224 }
while(
reFit_normalPix(pixNormalParams, v_Q, v_Qerr, v_TOT, v_TOTerr, v_TOTsig, v_TOTsigerr, FE ) );
239 int vecsize = v_Q.size();
241 std::unique_ptr<TGraphErrors> graflong = std::make_unique<TGraphErrors>(vecsize, &v_Q.at(0), &v_TOTlong.at(0), &v_Qerr.at(0), &v_TOTlongerr.at(0) );
245 graflong ->Fit(functlong.get() ,
"MRQ");
247 pixLongParams =
getParams(functlong.get() ,3 );
262 auto itr = map_info.find( modID );
264 if (itr != map_info.end()) {
265 (itr->second).at(FE)->set_NormalParams( pixNormalParams);
266 (itr->second).at(FE)->set_LongParams ( pixLongParams );
267 (itr->second).at(FE)->set_SigParams ( pixSigParams );
269 (itr->second).at(FE)->set_times_fitted ( n_fit );
271 (itr->second).at(FE)->set_NormalParamsQuality( pixNormalParamsQuality);
272 (itr->second).at(FE)->set_LongParamsQuality ( pixLongParamsQuality );
273 (itr->second).at(FE)->set_SigParamsQuality ( pixSigParamsQuality );
276 printf(
"Error - Module not found in fitting step... Skipping.\n");
285 for(
unsigned int FE = 0; FE <
m_nFE; FE++) {
287 histogramsTOT.at(FE).at(
pixel).reset();
288 histogramsTOTsig.at(FE).at(
pixel).reset();