Back to home page

sPhenix code displayed by LXR

 
 

    


File indexing completed on 2026-04-03 08:16:04

0001 //
0002 // make plots of the ped calibs to check them
0003 //
0004 //#include "get_runstr.h"
0005 #include <TFile.h>
0006 #include <TTree.h>
0007 #include <TGraphErrors.h>
0008 #include <TString.h>
0009 #include <TCanvas.h>
0010 #include <TPad.h>
0011 
0012 #include <iostream>
0013 #include <fstream>
0014 
0015 const int NFEECH = 256;
0016 const int MAXRUNS = 10000;
0017 
0018 Double_t mean[NFEECH][MAXRUNS];
0019 Double_t meanerr[NFEECH][MAXRUNS];
0020 Double_t sigma[NFEECH][MAXRUNS];
0021 Double_t sigmaerr[NFEECH][MAXRUNS];
0022 Double_t runs[MAXRUNS];
0023 
0024 TGraphErrors *g_mean[NFEECH];
0025 TGraphErrors *g_sigma[NFEECH];
0026 
0027 void plot_ped(const char *fname = "results/ped.list")
0028 {
0029   // Make a TFile for easier analysis
0030   TString name;
0031   //TFile *savefile = new TFile("peds.root");
0032 
0033 
0034   Float_t temp_mean;
0035   Float_t temp_meanerr;
0036   Float_t temp_sigma;
0037   Float_t temp_sigmaerr;
0038   Int_t   temp_feech;
0039 
0040   TString rootfname;
0041   TString runtext;
0042   TFile *cdbfile[MAXRUNS];
0043 
0044   std::ifstream inflist;
0045   inflist.open( fname );
0046 
0047   int nruns = 0;
0048 
0049   while  ( inflist >> rootfname )
0050   {
0051     cdbfile[nruns] = new TFile(rootfname,"READ");
0052 
0053     // get run number
0054     runtext = rootfname;
0055     runtext.ReplaceAll("/mbd_ped.root","");
0056     runtext.ReplaceAll("results/","");
0057     runs[nruns] = runtext.Atof();
0058     std::cout << rootfname << ", run " << runs[nruns] << std::endl;
0059 
0060     TTree *pedtree = (TTree*)cdbfile[nruns]->Get("Multiple");
0061     pedtree->SetBranchAddress("Fpedmean",&temp_mean);
0062     pedtree->SetBranchAddress("Fpedmeanerr",&temp_meanerr);
0063     pedtree->SetBranchAddress("Fpedsigma",&temp_sigma);
0064     pedtree->SetBranchAddress("Fpedsigmaerr",&temp_sigmaerr);
0065     pedtree->SetBranchAddress("IID",&temp_feech);
0066 
0067     Stat_t nentries = pedtree->GetEntries();
0068     //std::cout << nentries << std::endl;
0069     for (Stat_t ientry=0; ientry<nentries; ientry++)
0070     {
0071       pedtree->GetEntry( ientry );
0072 
0073       //if (nruns==0 ) std::cout << temp_feech << std::endl;
0074       if ( temp_feech<0 || temp_feech>255 )
0075       {
0076         std::cout << "ERROR feech " << temp_feech << std::endl;
0077         continue;
0078       }
0079       mean[temp_feech][nruns] = temp_mean;
0080       meanerr[temp_feech][nruns] = temp_meanerr;
0081       sigma[temp_feech][nruns] = temp_sigma;
0082       sigmaerr[temp_feech][nruns] = temp_sigmaerr;
0083     }
0084 
0085     //delete cdbfile[nruns];
0086     nruns++;
0087   }
0088 
0089   std::cout << "Processed " << nruns << " runs" << NFEECH << std::endl;
0090 
0091   // Make the plots
0092   for (int ifeech=0; ifeech<NFEECH; ifeech++)
0093   {
0094     g_mean[ifeech] = new TGraphErrors(nruns,runs,mean[ifeech],nullptr,meanerr[ifeech]);
0095     name = "g_mean"; name += ifeech;
0096     g_mean[ifeech]->SetName( name );
0097     g_mean[ifeech]->SetTitle( name );
0098     //g_mean[ifeech]->SetMarkerStyle( 20 );
0099 
0100     g_sigma[ifeech] = new TGraphErrors(nruns,runs,sigma[ifeech],nullptr,sigmaerr[ifeech]);
0101     name = "g_sigma"; name += ifeech;
0102     g_sigma[ifeech]->SetName( name );
0103     g_sigma[ifeech]->SetTitle( name );
0104   }
0105 
0106   TCanvas *ac[100];
0107   ac[0] = new TCanvas("cped","ped",1200,900);
0108   ac[0]->Divide(1,2);
0109 
0110   ac[0]->Print("ped.pdf[");
0111   for (int ifeech=0; ifeech<NFEECH; ifeech++)
0112   {
0113     std::cout << "feech " << ifeech << std::endl;
0114     ac[0]->cd(1);
0115     g_mean[ifeech]->Draw("alp");
0116     gPad->Modified();
0117     gPad->Update();
0118 
0119     ac[0]->cd(2);
0120     g_sigma[ifeech]->Draw("alp");
0121     gPad->Modified();
0122     gPad->Update();
0123 
0124     name = "ped, ch"; name += ifeech;
0125     ac[0]->Print("ped.pdf",name);
0126     //sleep(1);
0127   }
0128   ac[0]->Print("ped.pdf]");
0129 
0130 }