152 std::string hname, htitle;
163 double maxQ = 1073741824;
164 unsigned int Qbins = 8192;
166 if(
set->GetNumberOfCaenAdcModules() > 0 ) {
171 else if(
set->GetNumberOfFebexSfps() > 1 &&
172 set->GetNumberOfFebexBoards() > 0 &&
173 set->GetNumberOfFebexChannels() > 0 ) {
175 if(
cal->FebexType( 1, 0, 0 ) ==
"Qshort" ) {
180 for(
unsigned int i = 0; i <
set->GetNumberOfCDDetectors(); ++i ) {
187 for(
unsigned int j = 0; j <
set->GetNumberOfCDSectors(); ++j ) {
190 cd_nQ_pQ[i][j].resize(
set->GetNumberOfCDPStrips() );
192 for(
unsigned int k = 0; k <
set->GetNumberOfCDPStrips(); ++k ) {
194 hname =
"cd_" + std::to_string(i) +
"_" + std::to_string(j);
195 hname +=
"_nen_" + std::to_string(
ptag) +
"_pen_" + std::to_string(k);
196 htitle =
"CD n-side energy vs p-side energy for detector " + std::to_string(i);
197 htitle +=
", sector " + std::to_string(j) +
", pid " + std::to_string(k);
198 htitle +=
", nid " + std::to_string(
ntag);
199 htitle +=
";n-side energy (keV);p-side energy (keV);Counts";
200 cd_nen_pen[i][j][k] =
new TH2F( hname.data(), htitle.data(),
201 4000, 0, 2000e3, 4000, 0, 2000e3 );
204 hname =
"cd_" + std::to_string(i) +
"_" + std::to_string(j);
205 hname +=
"_nQ_" + std::to_string(
ptag) +
"_pQ_" + std::to_string(k);
206 htitle =
"CD n-side energy vs p-side raw charge for detector " + std::to_string(i);
207 htitle +=
", sector " + std::to_string(j) +
", pid " + std::to_string(k);
208 htitle +=
", nid " + std::to_string(
ntag);
209 htitle +=
";n-side raw charge (ADC units);p-side raw charge (ADC units);Counts";
210 cd_nQ_pQ[i][j][k] =
new TH2F( hname.data(), htitle.data(),
211 Qbins, 0, maxQ, Qbins, 0, maxQ );
219 for(
unsigned int k = 0; k <
set->GetNumberOfCDNStrips(); ++k ) {
221 hname =
"cd_" + std::to_string(i) +
"_" + std::to_string(j);
222 hname +=
"_pen_" + std::to_string(
ptag) +
"_nen_" + std::to_string(k);
223 htitle =
"CD p-side energy vs n-side energy for detector " + std::to_string(i);
224 htitle +=
", sector " + std::to_string(j) +
", pid " + std::to_string(
ptag);
225 htitle +=
", nid " + std::to_string(k);
226 htitle +=
";p-side energy (keV);n-side energy (keV);Counts";
227 cd_pen_nen[i][j][k] =
new TH2F( hname.data(), htitle.data(),
228 4000, 0, 2000e3, 4000, 0, 2000e3 );
231 hname =
"cd_" + std::to_string(i) +
"_" + std::to_string(j);
232 hname +=
"_pen_" + std::to_string(
ptag) +
"_nQ_" + std::to_string(k);
233 htitle =
"CD p-side energy vs n-side raw charge for detector " + std::to_string(i);
234 htitle +=
", sector " + std::to_string(j) +
", pid " + std::to_string(
ptag);
235 htitle +=
", nid " + std::to_string(k);
236 htitle +=
";p-side energy (keV);n-side raw charge (ADC units);Counts";
237 cd_pen_nQ[i][j][k] =
new TH2F( hname.data(), htitle.data(),
238 4000, 0, 2000e3, Qbins, 0, maxQ );
276 for(
unsigned int m = 0; m <
set->GetNumberOfCaenAdcModules(); ++m ) {
279 for(
unsigned int c = 0; c <
set->GetNumberOfCaenAdcChannels(); ++c ) {
282 if( !
set->IsCD(m,c) )
continue;
285 if(
set->GetCDDetector(m,c) != det )
continue;
288 if(
set->GetCDSector(m,c) != sec )
continue;
291 if(
set->GetCDSide(m,c) != side )
continue;
294 if(
set->GetCDStrip(m,c) != strip )
continue;
305 std::cerr <<
"CD strip not found, det=" << det <<
", sec=" << sec;
306 std::cerr <<
", side=" << side <<
", strip=" << strip << std::endl;
314 for(
unsigned int s = 0; s <
set->GetNumberOfFebexSfps(); ++s ) {
317 for(
unsigned int m = 0; m <
set->GetNumberOfFebexBoards(); ++m ) {
320 for(
unsigned int c = 0; c <
set->GetNumberOfFebexChannels(); ++c ) {
323 if( !
set->IsCD(s,m,c) )
continue;
326 if(
set->GetCDDetector(s,m,c) != det )
continue;
329 if(
set->GetCDSector(s,m,c) != sec )
continue;
332 if(
set->GetCDSide(s,m,c) != side )
continue;
335 if(
set->GetCDStrip(s,m,c) != strip )
continue;
349 std::cerr <<
"CD strip not found, det=" << det <<
", sec=" << sec;
350 std::cerr <<
", side=" << side <<
", strip=" << strip << std::endl;
359 if(
set->GetNumberOfCaenAdcModules() > 0 )
363 auto pfit = std::make_unique<TF1>(
"pfit",
"[0]+[1]*x", 0, 1e9 );
366 gErrorIgnoreLevel = kError;
367 std::vector<std::vector<std::unique_ptr<TCanvas>>> canv;
368 canv.resize(
set->GetNumberOfCDDetectors() );
371 for(
unsigned int i = 0; i <
set->GetNumberOfCDDetectors(); ++i ) {
373 canv[i].resize(
set->GetNumberOfCDSectors() );
376 for(
unsigned int j = 0; j <
set->GetNumberOfCDSectors(); ++j ) {
378 std::string cname =
"cdcal_p_" + std::to_string(i) +
"_" + std::to_string(j);
379 canv[i][j] = std::make_unique<TCanvas>( cname.data(), cname.data(), 800, 1000 );
382 for(
unsigned int k = 0; k <
set->GetNumberOfCDPStrips(); ++k ) {
385 auto res =
cd_nQ_pQ[i][j][k]->Fit( pfit.get(),
"QWL" );
386 if( res != 0 )
continue;
387 double fit_gain =
ngain / pfit->GetParameter(1);
388 double fit_offset =
noffset - pfit->GetParameter(0) * fit_gain;
392 std::cout <<
"!! This is the p-side tag channel, cross-check check the parameters below !!" << std::endl;
398 std::string cal_base;
399 std::string modchstr;
407 modchstr = std::to_string(fmod) +
"_" + std::to_string(fch);
417 modchstr = std::to_string(fsfp) +
"_" + std::to_string(fmod);
418 modchstr +=
"_" + std::to_string(fch);
423 std::string gainstr = cal_base + modchstr +
".Gain: " + std::to_string( fit_gain );
424 std::string offsetstr = cal_base + modchstr +
".Offset: " + std::to_string( fit_offset );
427 std::cout << gainstr << std::endl;
428 std::cout << offsetstr << std::endl;
433 std::string pdfname = cname +
".pdf";
434 if( k == 0 &&
set->GetNumberOfCDPStrips() != 1 )
436 else if( k > 0 && k ==
set->GetNumberOfCDPStrips() - 1 )
438 canv[i][j]->Print( pdfname.data(),
"pdf" );
447 gErrorIgnoreLevel = kInfo;
457 if(
set->GetNumberOfCaenAdcModules() > 0 )
461 auto nfit = std::make_unique<TF1>(
"nfit",
"[0]+[1]*x", 0, 1e9 );
464 gErrorIgnoreLevel = kError;
465 std::vector<std::vector<std::unique_ptr<TCanvas>>> canv;
466 canv.resize(
set->GetNumberOfCDDetectors() );
469 for(
unsigned int i = 0; i <
set->GetNumberOfCDDetectors(); ++i ) {
471 canv[i].resize(
set->GetNumberOfCDSectors() );
474 for(
unsigned int j = 0; j <
set->GetNumberOfCDSectors(); ++j ) {
476 std::string cname =
"cdcal_n_" + std::to_string(i) +
"_" + std::to_string(j);
477 canv[i][j] = std::make_unique<TCanvas>( cname.data(), cname.data(), 800, 1000 );
480 for(
unsigned int k = 0; k <
set->GetNumberOfCDNStrips(); ++k ) {
483 auto res =
cd_pen_nQ[i][j][k]->Fit( nfit.get(),
"QWL" );
484 if( res != 0 )
continue;
485 double fit_gain = 1.0 / nfit->GetParameter(1);
486 double fit_offset = -1.0 * nfit->GetParameter(0) * fit_gain;
497 std::string cal_base;
498 std::string modchstr;
506 modchstr = std::to_string(fmod) +
"_" + std::to_string(fch);
516 modchstr = std::to_string(fsfp) +
"_" + std::to_string(fmod);
517 modchstr +=
"_" + std::to_string(fch);
522 std::string gainstr = cal_base + modchstr +
".Gain: " + std::to_string( fit_gain );
523 std::string offsetstr = cal_base + modchstr +
".Offset: " + std::to_string( fit_offset );
526 std::cout << gainstr << std::endl;
527 std::cout << offsetstr << std::endl;
532 std::string pdfname = cname +
".pdf";
533 if( k == 0 &&
set->GetNumberOfCDNStrips() != 1 )
535 else if( k > 0 && k ==
set->GetNumberOfCDNStrips() - 1 )
537 canv[i][j]->Print( pdfname.data(),
"pdf" );
546 gErrorIgnoreLevel = kInfo;
555 std::vector<unsigned char> pindex;
556 std::vector<unsigned char> nindex;
559 for(
unsigned int i = 0; i <
set->GetNumberOfCDDetectors(); ++i ){
561 for(
unsigned int j = 0; j <
set->GetNumberOfCDSectors(); ++j ){
566 std::vector<unsigned char>().swap(pindex);
567 std::vector<unsigned char>().swap(nindex);
570 for(
unsigned int k = 0; k <
cd_en_list.size(); ++k ){
586 if( pindex.size() != 1 || nindex.size() != 1 )
598 if( nQ / pQ > 1.5 || pQ / nQ > 1.5 )
continue;
612 cd_nQ_pQ[i][j][pid]->Fill( nQ, pQ );
629 std::cout <<
" CD Calibrator: nothing to do" << std::endl;
639 std::cout <<
" CD Calibrator: number of entries in input tree = ";
642 std::cout <<
"\tnumber of MBS Events/triggers in input tree = ";
648 for(
unsigned long i = 0; i <
n_entries; ++i ) {
672 std::cerr <<
"Didn't find matching MBS Event IDs at start of the file: ";
685 if(
set->GetMbsEventMode() ) {
697 std::cout <<
"Out of order event in ";
698 std::cout <<
input_tree->GetName() << std::endl;
705 std::cout <<
"Out of order MBS event " <<
myeventid;
730 unsigned int adc_tmp_value;
780 unsigned int adc_tmp_value =
adc_data->GetQshort();
850 std::cerr <<
"MBS Event " <<
myeventid <<
" not found by index, looking up manually" << std::endl;
863 std::cerr <<
"Didn't find matching MBS Event IDs at start of the file: ";
877 if(
set->GetMbsEventMode() ) {
914 bool update_progress =
false;
916 update_progress =
true;
918 update_progress =
true;
920 if( update_progress ) {
923 float percent = (float)(i+1)*100.0/(float)
n_entries;
928 prog->SetPosition( percent );
929 gSystem->ProcessEvents();
934 std::cout <<
" " << std::setw(6) << std::setprecision(4);
935 std::cout << percent <<
"% \r";
947 std::cout <<
"\n\nUsing p-side strip " << (int)
ptag <<
" as reference for calibrating n-sides" << std::endl;
949 std::cout <<
"\n\nUsing n-side strip " << (int)
ntag <<
" as reference for calibrating p-sides" << std::endl;
956 std::cout <<
"\n MiniballCDCalibrator finished..." << std::endl;