Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-05-23 08:15:38

0001 #include "get_runstr.h"
0002 #include "make_cdbtree.C"
0003 //#include "read_dstmbd.C"
0004 #include "pro_recal_mbd_mip.C"
0005 
0006 #include <mbd/MbdCalib.h>
0007 #include <mbd/MbdDefs.h>
0008 
0009 #include <ffamodules/CDBInterface.h>
0010 
0011 #include <phool/recoConsts.h>
0012 
0013 #include <TString.h>
0014 #include <TFile.h>
0015 #include <TTree.h>
0016 #include <TH1.h>
0017 #include <TH2.h>
0018 #include <TF1.h>
0019 #include <TCanvas.h>
0020 #include <TPad.h>
0021 #include <TSystem.h>
0022 #include <TStyle.h>
0023 
0024 #include <iostream>
0025 #include <fstream>
0026 
0027 
0028 R__LOAD_LIBRARY(libffamodules.so)
0029 R__LOAD_LIBRARY(libphool.so)
0030 R__LOAD_LIBRARY(libmbd.so)
0031 
0032 // This macro executes the sub-passes for the pass2 calibrations
0033 //pass 2.0: do tt_t0 and tq_t0 offset calibration
0034 //pass 2.1: do the slew correction calibration
0035 //pass 2.2: do the next iteration of the slew correction calibration
0036 //pass 2.3: do the mip fits for charge calibration 
0037 
0038 void pro_cal_mbd(const int runnumber, const int subpass = 0)
0039 {
0040   gStyle->SetOptFit(1111);
0041   gStyle->SetOptStat(111111);
0042 
0043   //std::cout << "cal_mbd(), tfname " << tfname << std::endl;
0044 
0045   //== Create output directory (should already exist)
0046   //int runnumber = get_runnumber(tfname);
0047   TString dir = "results/";
0048   dir += runnumber;
0049   dir += "/";
0050   TString name = "mkdir -p " + dir;
0051   gSystem->Exec( name );
0052 
0053   std::cout << name << std::endl;
0054 
0055   //runtype 0: au+au 200 GeV
0056   //runtype 1: p+p 200 GeV
0057   //int runtype = get_runtype( runnumber );
0058   //std::cout << "cal_mbd(), runtype " << runtype << std::endl;
0059 
0060   //== Load in calib constants
0061   //Float_t tq_t0_offsets[MbdDefs::MBD_N_PMT] = {};
0062 
0063   MbdCalib *mcal = new MbdCalib();
0064   mcal->Verbosity(1);
0065 
0066   // Load local mbd_sampmax and ped if they exist
0067   /*
0068   TString calfile = dir + "/mbd_sampmax.calib";
0069   if ( gSystem->AccessPathName(calfile)==0 )
0070   {
0071     mcal->Download_SampMax( calfile.Data() );
0072   }
0073   calfile = dir + "/mbd_ped.calib";
0074   if ( gSystem->AccessPathName(calfile)==0 )
0075   {
0076     mcal->Download_Ped( calfile.Data() );
0077   }
0078   */
0079 
0080   TString savefname = dir;
0081   if ( subpass==0 )
0082   {
0083     savefname += "calmbdpass2."; savefname += subpass; savefname += "_time-"; savefname += runnumber; savefname += ".root";
0084 
0085     // temp, for final t0
0086     /*
0087     calfile = dir + "/mbd_slewcorr.calib";
0088     mcal->Download_SlewCorr( calfile.Data() );
0089     std::cout << "Loaded " << calfile << std::endl;
0090     */
0091   }
0092   else if ( subpass==1 || subpass==2 )
0093   {
0094     savefname += "calmbdpass2."; savefname += subpass; savefname += "_slew-"; savefname += runnumber; savefname += ".root";
0095   }
0096   else if ( subpass==3 )
0097   {
0098     savefname += "calmbdpass2."; savefname += subpass; savefname += "_q-"; savefname += runnumber; savefname += ".root";
0099   }
0100   std::cout << "saving to " << savefname << std::endl;
0101 
0102   // Load whatever calibrations are available at each subpass
0103   /*
0104   if ( subpass>0 )
0105   {
0106     calfile = dir + "/mbd_tq_t0.calib";
0107     mcal->Download_TQT0( calfile.Data() );
0108     std::cout << "Loaded " << calfile << std::endl;
0109 
0110     calfile = dir + "/mbd_tt_t0.calib";
0111     mcal->Download_TTT0( calfile.Data() );
0112     std::cout << "Loaded " << calfile << std::endl;
0113   }
0114   if ( subpass>1 )
0115   {
0116     if ( dbtag.empty() )
0117     {
0118       calfile = dir + "/mbd_slewcorr.calib";
0119       mcal->Download_SlewCorr( calfile.Data() );
0120       std::cout << "Loaded " << calfile << std::endl;
0121     }
0122     else
0123     {
0124       recoConsts *rc = recoConsts::instance();
0125       rc->set_StringFlag("CDB_GLOBALTAG","newcdbtag"); 
0126       rc->set_uint64Flag("TIMESTAMP",runnumber);
0127       CDBInterface *cdb = CDBInterface::instance();
0128       std::string slew_url = cdb->getUrl("MBD_SLEWCORR");
0129       mcal->Download_SlewCorr(slew_url);
0130       std::cout << "Loaded " << slew_url << std::endl;
0131     }
0132   }
0133   if ( subpass>3 )
0134   {
0135     calfile = dir + "/mbd_qfit.calib";
0136     mcal->Download_Gains( calfile.Data() );
0137     std::cout << "Loaded " << calfile << std::endl;
0138   }
0139   */
0140 
0141   //TFile *savefile = new TFile(savefname,"RECREATE");
0142   TFile *savefile = new TFile(savefname,"READ");
0143 
0144   TH1 *h_qp[MbdDefs::MBD_N_PMT];
0145   TH1 *h_tt[MbdDefs::MBD_N_PMT];
0146   TH1 *h_tqp[MbdDefs::MBD_N_PMT];
0147 
0148   TH2 *h2_slew[MbdDefs::MBD_N_PMT];
0149 
0150   TString title;
0151   for (int ipmt=0; ipmt<MbdDefs::MBD_N_PMT; ipmt++)
0152   {
0153     name = "h_q"; name += ipmt;
0154     //title = "q"; title += ipmt;
0155     //h_qp[ipmt] = new TH1F(name,title,3000,-100,15000-100);
0156     //h_qp[ipmt]->SetXTitle("ADC");
0157     h_qp[ipmt] = (TH1*)savefile->Get( name );
0158 
0159     name = "h_tt"; name += ipmt;
0160     h_tt[ipmt] = (TH1*)savefile->Get( name );
0161     /*
0162     title = "tt"; title += ipmt;
0163     //h_tt[ipmt] = new TH1F(name,title,7000,-150,31*17.76);
0164     h_tt[ipmt] = new TH1F(name,title,7000,-30.,30.);
0165     h_tt[ipmt]->SetXTitle("ns");
0166     */
0167 
0168     name = "h_tq"; name += ipmt;
0169     h_tqp[ipmt] = (TH1*)savefile->Get( name );
0170     /*
0171     title = "tq"; title += ipmt;
0172     h_tqp[ipmt] = new TH1F(name,title,7000,-150,31*17.76);
0173     h_tqp[ipmt]->SetXTitle("ns");
0174     */
0175 
0176     if ( subpass>0 )
0177     {
0178       name = "h2_slew"; name += ipmt;
0179       h2_slew[ipmt] = (TH2*)savefile->Get( name );
0180       /*
0181       title = "slew curve, ch "; title += ipmt;
0182       h2_slew[ipmt] = new TH2F(name,title,4000,-0.5,16000-0.5,1100,-5,6);
0183       h2_slew[ipmt]->SetXTitle("ADC");
0184       h2_slew[ipmt]->SetYTitle("#Delta T (ns)");
0185       */
0186     }
0187   }
0188   TH2 *h2_tq = (TH2*)savefile->Get("h2_tq");
0189   TH2 *h2_tt = (TH2*)savefile->Get("h2_tt");
0190   /*
0191   TH2 *h2_tq = new TH2F("h2_tq","ch vs tq",900,-150,150,MbdDefs::MBD_N_PMT,-0.5,MbdDefs::MBD_N_PMT-0.5);
0192   h2_tq->SetXTitle("tq [ns]");
0193   h2_tq->SetYTitle("pmt ch");
0194   TH2 *h2_tt = new TH2F("h2_tt","ch vs tt",900,-150,150,MbdDefs::MBD_N_PMT,-0.5,MbdDefs::MBD_N_PMT-0.5);
0195   h2_tt->SetXTitle("tt [ns]");
0196   h2_tt->SetYTitle("pmt ch");
0197   */
0198 
0199   // Event loop, each ientry is one triggered event
0200   /*
0201   int nentries = tree->GetEntries();
0202   if ( nevt!=0 && nevt<nentries )
0203   {
0204     nentries = nevt;
0205   }
0206 
0207   double armtime[2]{0.,0.};
0208   double nhit[2]{0.,0.};
0209   float  ttcorr[128] = {0.};
0210 
0211   std::cout << "Processing " << nentries << std::endl;
0212   for (int ientry=0; ientry<nentries; ientry++)
0213   {
0214     dstmbd_GetEntry(ientry);
0215 
0216     if (ientry<4)
0217     {
0218       // print charge from channels 0 and 127
0219       std::cout << f_evt << "\tch0\t" << f_tt[0] << "\t" << f_tq[0] << "\t" << f_q[0] << std::endl;
0220       std::cout << "ch127\t" << f_tt[127] << "\t" << f_tq[127] << "\t" << f_q[127] << std::endl;
0221     }
0222 
0223     // make npmt cut
0224     //if ( f_npmt==0 )
0225     //{
0226     //  std::cout << "f_npmt == 0" << std::endl;
0227     //  continue;
0228     //}
0229 
0230     // Make vertex cut
0231     if ( subpass!=0 && std::abs(f_bz)>60. )
0232     {
0233       continue;
0234     }
0235 
0236     if ( subpass>0 )
0237     {
0238       armtime[0] = 0.;
0239       armtime[1] = 0.;
0240       nhit[0] = 0.;
0241       nhit[1] = 0.;
0242     }
0243 
0244     for (int ipmt=0; ipmt<MbdDefs::MBD_N_PMT; ipmt++)
0245     {
0246       int arm = ipmt/64;
0247 
0248       ttcorr[ipmt] = f_tt[ipmt];
0249       float tq = f_tq[ipmt];
0250 
0251       if ( subpass>0 )
0252       {
0253         if ( !std::isnan(mcal->get_tt0(ipmt)) && mcal->get_tt0(ipmt)>-100. && f_q[ipmt]>0. && f_q[ipmt]<16000. )
0254         {
0255           ttcorr[ipmt] -= mcal->get_tt0(ipmt);
0256         }
0257         if ( !std::isnan(mcal->get_tq0(ipmt)) && mcal->get_tq0(ipmt)>-100. )
0258         {
0259           tq -= mcal->get_tq0(ipmt);
0260         }
0261       }
0262 
0263       //if ( subpass==0 )  // temp, for final t0
0264       if ( subpass>1 && subpass<3 ) // apply slewcorr if subpass > 1
0265       {
0266         int feech = (ipmt / 8) * 16 + ipmt % 8;
0267         if ( !std::isnan(mcal->get_tt0(ipmt)) && mcal->get_tt0(ipmt)>-100. && f_q[ipmt]>0. && f_q[ipmt]<16000. )
0268         {
0269           ttcorr[ipmt] -= mcal->get_scorr(feech,f_q[ipmt]);
0270         }
0271       }
0272 
0273       h_tt[ipmt]->Fill( ttcorr[ipmt] );
0274       h2_tt->Fill( ttcorr[ipmt], ipmt );
0275 
0276       h_tqp[ipmt]->Fill( tq );
0277       h2_tq->Fill( tq, ipmt );
0278 
0279       if ( subpass==0 && std::abs(f_tt[ipmt])<26. )
0280       {
0281         h_qp[ipmt]->Fill( f_q[ipmt] );
0282       }
0283       else if ( subpass>0 && std::abs(ttcorr[ipmt])<26. )
0284       //else if ( subpass>0 && (std::abs(ttcorr[ipmt])<26.||f_q[ipmt]>40.) )  // to get around high threshold
0285       {
0286         h_qp[ipmt]->Fill( f_q[ipmt] );
0287 
0288         //if ( f_q[ipmt] > 500. && std::abs(ttcorr[ipmt])<26. )    // for p+p
0289         //if ( f_q[ipmt] > 2000. && std::abs(ttcorr[ipmt])<26. )
0290         if ( std::abs(ttcorr[ipmt])<26. )
0291         {
0292           nhit[arm] += 1.0;
0293           armtime[arm] += ttcorr[ipmt];
0294         }
0295 
0296         // check charge
0297         // why cuts on f_bn?
0298         //if ( arm==0 && f_bn[0]<30 )
0299         //{
0300         //  h_qp[ipmt]->Fill( f_q[ipmt] );
0301         //}
0302         //else if ( arm==1 && f_bn[1]<30 )
0303         //{
0304         //  h_qp[ipmt]->Fill( f_q[ipmt] );
0305         //}
0306       }
0307     } // end loop over PMTs
0308 
0309     // calc meantime for high amplitude
0310     for (int iarm=0; iarm<2; iarm++)
0311     {
0312       if ( nhit[iarm]>1. )
0313       {
0314         armtime[iarm] = armtime[iarm]/nhit[iarm];
0315       }
0316       //std::cout << "aaa " << iarm << "\t" << nhit[iarm] << "\t" << armtime[iarm] << std::endl;
0317     }
0318 
0319     for (int ipmt=0; ipmt<MbdDefs::MBD_N_PMT; ipmt++)
0320     {
0321       //int ifeech = (ipmt/8)*16 + 8 + ipmt%8;  // time ifeech only
0322       int arm = ipmt/64;
0323 
0324       if ( nhit[arm]<2 || f_q[ipmt]<=0. )
0325       {
0326     continue;
0327       }
0328 
0329       double dt = ttcorr[ipmt] - armtime[arm];
0330 
0331       //std::cout << "filling" << std::endl;
0332       h2_slew[ipmt]->Fill( f_q[ipmt], dt );
0333     }
0334   }
0335   */
0336 
0337   TCanvas *ac[100];
0338   int cvindex = 0;
0339 
0340   TString pdfname;  // output pdf
0341 
0342   //== Calculate tq_t0 and tt_t0 on subpass, or apply tt_t0 if subpass>0
0343   ac[cvindex] = new TCanvas("cal_tt","ch vs tt",425*1.5,550*1.5);
0344   h2_tt->Draw("colz");
0345   pdfname = dir; pdfname += "calmbdpass2."; pdfname += subpass; pdfname += "_time-"; pdfname += runnumber; pdfname += ".pdf";
0346   if ( subpass==0 )
0347   {
0348     //name = dir + "h2_tt.png";
0349     title = "t0, Timing Ch's";
0350   }
0351   else if ( subpass>0 )
0352   {
0353     //name = dir + "h2_ttcorr.png";
0354     title = "t0 corrected, Timing Ch's";
0355     h2_tt->GetXaxis()->SetRangeUser( -12.5, 12.5 );
0356     gPad->Modified();
0357     gPad->Update();
0358   }
0359   std::cout << pdfname << std::endl;
0360   ac[cvindex]->Print( pdfname + "[");
0361   ac[cvindex]->Print( pdfname, title );
0362   ++cvindex;
0363 
0364   // now tq_t0
0365   ac[cvindex] = new TCanvas("cal_tq","ch vs tq",425*1.5,550*1.5);
0366   h2_tq->Draw("colz");
0367   if ( subpass==0 )
0368   {
0369     //name = dir + "h2_tq.png";
0370     title = "t0, Charge Ch's";
0371   }
0372   else if ( subpass>0 )
0373   {
0374     //name = dir + "h2_tqcorr.png";
0375     title = "t0 corrected, Charge Ch's";
0376     h2_tq->GetXaxis()->SetRangeUser( -20,20 );
0377     gPad->Modified();
0378     gPad->Update();
0379   }
0380   std::cout << pdfname << std::endl;
0381   ac[cvindex]->Print( pdfname, title );
0382   ++cvindex;
0383 
0384   // Here we calculate tt_t0 and tq_t0, starting with tt_t0 first
0385   ac[cvindex] = new TCanvas("cal_tt_ch","tt",550*1.5,425*1.5);
0386   gPad->SetLogy(1);
0387 
0388   std::ofstream cal_tt_t0_file;
0389   TString cal_fname = dir; cal_fname += "pass"; cal_fname += subpass; cal_fname += "_mbd_tt_t0.calib";
0390   cal_tt_t0_file.open( cal_fname );
0391   std::cout << "Creating " << cal_fname << std::endl;
0392 
0393   TF1 *gaussian = new TF1("gaussian","gaus",-25,25);
0394   gaussian->SetLineColor(2);
0395   double min_twindow = -25.;
0396   double max_twindow = 25.;
0397 
0398   for (int ipmt=0; ipmt<MbdDefs::MBD_N_PMT; ipmt++)
0399   {
0400     // only look in the middle
0401     if ( ipmt==0 || ipmt==64 )
0402     {
0403       // use wide range for 1st channel in each arm
0404       h_tt[ipmt]->SetAxisRange(-25.,25.);
0405       //h_tt[ipmt]->SetAxisRange(9.,13.);
0406     }
0407     else
0408     {
0409       // for subsequent channels in an arm, use a window
0410       // determined by the 1st channel
0411       h_tt[ipmt]->SetAxisRange(min_twindow,max_twindow);
0412     }
0413     Double_t thispeak = h_tt[ipmt]->GetMaximum();
0414     int peakbin = h_tt[ipmt]->GetMaximumBin();
0415     Double_t mean = h_tt[ipmt]->GetBinCenter( peakbin );
0416     Double_t sigma = 1.0;
0417     //Double_t sigma = 3.0;
0418     gaussian->SetParameters( thispeak, mean, 5 );
0419     gaussian->SetRange( mean-3*sigma, mean+3*sigma );
0420 
0421     if ( ipmt==0 || ipmt==64 )
0422     {
0423       min_twindow = mean - 3*sigma;
0424       max_twindow = mean + 3*sigma;
0425     }
0426 
0427     h_tt[ipmt]->Fit(gaussian,"R");
0428     h_tt[ipmt]->SetAxisRange(mean-15.*sigma,mean+15.*sigma);
0429     //gPad->SetLogy(1);
0430     mean = gaussian->GetParameter(1);
0431     Double_t meanerr = gaussian->GetParError(1);
0432     sigma = gaussian->GetParameter(2);
0433     Double_t sigmaerr = gaussian->GetParError(2);
0434 
0435     // normalize th2 histogram
0436     int nbinsx = h2_tt->GetNbinsX();
0437     for (int ibinx=1; ibinx<=nbinsx; ibinx++)
0438     {
0439       Double_t fitpeak = gaussian->GetParameter(0);
0440       if ( fitpeak!=0 )
0441       {
0442         Float_t bincontent = h2_tt->GetBinContent(ibinx,ipmt+1);
0443         h2_tt->SetBinContent(ibinx,ipmt+1,bincontent/fitpeak);
0444       }
0445     }
0446 
0447     cal_tt_t0_file << ipmt << "\t" << mean << "\t" << meanerr << "\t" << sigma << "\t" << sigmaerr << std::endl;
0448     std::cout << ipmt << "\t" << mean << "\t" << meanerr << "\t" << sigma << "\t" << sigmaerr << std::endl;
0449 
0450     if ( subpass==0 )
0451     {
0452       //name = dir + "h_tt"; name += ipmt; name += ".png";
0453       title = "h_tt"; title += ipmt;
0454     }
0455     else if ( subpass==1 || subpass==2 )
0456     {
0457       //name = dir + "h_ttcorr"; name += ipmt; name += ".png";
0458       title = "h_ttcorr"; title += ipmt;
0459     }
0460     //std::cout << title << std::endl;
0461     ac[cvindex]->Print( pdfname, title );
0462   }
0463   cal_tt_t0_file.close();
0464   make_cdbtree( cal_fname );
0465   ++cvindex;
0466 
0467   // Now calculate tq_t0
0468   ac[cvindex] = new TCanvas("cal_tq_ch","tq",550*1.5,425*1.5);
0469   gPad->SetLogy(1);
0470 
0471   std::ofstream cal_tq_t0_file;
0472   cal_fname = dir; cal_fname += "pass"; cal_fname += subpass; cal_fname += "_mbd_tq_t0.calib";
0473   cal_tq_t0_file.open( cal_fname );
0474 
0475   for (int ipmt=0; ipmt<MbdDefs::MBD_N_PMT; ipmt++)
0476   {
0477     // only look in the middle
0478     if ( ipmt==0 || ipmt==64 )
0479     {
0480       // use wide range for 1st channel in each arm
0481       h_tqp[ipmt]->SetAxisRange(-25.,25.);
0482       //h_tqp[ipmt]->SetAxisRange(9.,13.); // kludge to select middle bunch during stochastic cooling
0483     }
0484     else
0485     {
0486       // for subsequent channels in an arm, use a window
0487       // determined by the 1st channel
0488       h_tqp[ipmt]->SetAxisRange(min_twindow,max_twindow);
0489     }
0490     Double_t thispeak = h_tqp[ipmt]->GetMaximum();
0491     int peakbin = h_tqp[ipmt]->GetMaximumBin();
0492     Double_t mean = h_tqp[ipmt]->GetBinCenter( peakbin );
0493     Double_t sigma = 1.0;
0494     //Double_t sigma = 3.0;
0495     gaussian->SetParameters( thispeak, mean, 5 );
0496     gaussian->SetRange( mean-3*sigma, mean+3*sigma );
0497 
0498     if ( ipmt==0 || ipmt==64 )
0499     {
0500       min_twindow = mean - 3*sigma;
0501       max_twindow = mean + 3*sigma;
0502     }
0503 
0504     h_tqp[ipmt]->Fit(gaussian,"R");
0505     h_tqp[ipmt]->SetAxisRange(mean-12.*sigma,mean+12.*sigma);
0506     //gPad->SetLogy(1);
0507     mean = gaussian->GetParameter(1);
0508     Double_t meanerr = gaussian->GetParError(1);
0509     sigma = gaussian->GetParameter(2);
0510     Double_t sigmaerr = gaussian->GetParError(2);
0511 
0512     // normalize th2 histogram
0513     int nbinsx = h2_tq->GetNbinsX();
0514     for (int ibinx=1; ibinx<=nbinsx; ibinx++)
0515     {
0516       Double_t fitpeak = gaussian->GetParameter(0);
0517       if ( fitpeak!=0 )
0518       {
0519         Float_t bincontent = h2_tq->GetBinContent(ibinx,ipmt+1);
0520         h2_tq->SetBinContent(ibinx,ipmt+1,bincontent/fitpeak);
0521       }
0522     }
0523 
0524     cal_tq_t0_file << ipmt << "\t" << mean << "\t" << meanerr << "\t" << sigma << "\t" << sigmaerr << std::endl;
0525 
0526     if ( subpass==0 )
0527     {
0528       //name = dir + "h_tq"; name += ipmt; name += ".png";
0529       title = "h_tq"; title += ipmt;
0530     }
0531     else if ( subpass==1 || subpass==2 )
0532     {
0533       //name = dir + "h_tqcorr"; name += ipmt; name += ".png";
0534       title = "h_tqcorr"; title += ipmt;
0535     }
0536     //std::cout << name << std::endl;
0537     ac[cvindex]->Print( pdfname, title );
0538   }
0539 
0540   cal_tq_t0_file.close();
0541   make_cdbtree( cal_fname );
0542 
0543   ac[0]->Print( pdfname + "]" );
0544   ++cvindex;
0545 
0546   if ( subpass==1 || subpass==2 )
0547   {
0548     //== Draw the slewcorr histograms
0549     ac[cvindex] = new TCanvas("cal_slew","slew",425*1.5,550*1.5);
0550     pdfname = dir; pdfname += "calmbdpass2."; pdfname += subpass; pdfname += "_slew-"; pdfname += runnumber; pdfname += ".pdf";
0551     ac[cvindex]->Print( pdfname + "[" );
0552 
0553     for (int ipmt=0; ipmt<MbdDefs::MBD_N_PMT; ipmt++)
0554     {
0555       h2_slew[ipmt]->Draw("colz");
0556       gPad->SetLogz(1);
0557 
0558       //name = dir + "h2_slew"; name += ipmt; name += "_pass"; name += subpass; name += ".png";
0559       name = dir + "h2_slew"; name += ipmt; name += "_pass"; name += subpass;
0560       std::cout << name << std::endl;
0561       ac[cvindex]->Print( pdfname, name );
0562     }
0563 
0564     // Here we could perhaps add a summary page
0565  
0566     ac[cvindex]->Print( pdfname + "]" );
0567     ++cvindex;
0568   }
0569 
0570   //== Draw the charge histograms
0571   if ( subpass==0 )
0572   {
0573     ac[cvindex] = new TCanvas("cal_q","q",425*1.5,550*1.5);
0574 
0575     pdfname = dir; pdfname += "calmbdpass2."; pdfname += subpass; pdfname += "_adc-"; pdfname += runnumber; pdfname += ".pdf";
0576     ac[cvindex]->Print( pdfname + "[" );
0577 
0578     gPad->SetLogy(1);
0579 
0580     for (int ipmt=0; ipmt<MbdDefs::MBD_N_PMT && subpass==0; ipmt++)
0581     {
0582       h_qp[ipmt]->Draw();
0583 
0584       //name = dir + "h_adc"; name += ipmt; name += ".png";
0585       title = "h_adc"; title += ipmt;
0586       //std::cout << pdfname << " " << title << std::endl;
0587       ac[cvindex]->Print( pdfname, title );
0588     }
0589     ac[cvindex]->Print( pdfname + "]" );
0590     ++cvindex;
0591   }
0592 
0593   //savefile->Write();
0594   //savefile->Close();
0595 
0596   if ( subpass==3 )
0597   {
0598     pro_recal_mbd_mip( runnumber, subpass );
0599   }
0600 
0601 }
0602