Beispiel #1
0
void TH2TAPS::DrawShape(TH2DrawTool& c, bool isBaF2) {
    if(isBaF2) 
        c.Draw(TH2TAPS::baf2_shape);
    else 
        c.Draw(TH2TAPS::pbwo4_shape);
    c.FinishShape();
 
    // FinishShape adds the bin, so we get it here again
    TH2PolyBin* bin_obj = (TH2PolyBin*) fBins->Last();
    TGraph* polygon = (TGraph*)bin_obj->GetPolygon();
    if(isBaF2)
        polygon->SetNameTitle("", Form("Element %d (BaF2)",fBins->GetEntries()-1));
    else
        polygon->SetNameTitle("", Form("Element %d (PbWO4)",fBins->GetEntries()-1));
}
TGraph* makeGraph(const vector<T> &v, const char *name = "vectorGraph")
{
  TObject *obj = gROOT->FindObjectAny(name);
  if (obj) {
    obj->Delete();
  }
  TGraph *graph = new TGraph(v.size());
  graph->SetNameTitle(name, name);

  for (Int_t i=0; i < v.size(); i++) {
    graph->SetPoint(i, i, v.at(i));
  }

  return graph;
}
int main(int argc, char** argv)
{
    // read config files to see which nuclei should be used for calculation
    string configFileName = "config/filesToRead.txt";
    ifstream configFile(configFileName);

    if(!configFile.is_open())
    {
        cerr << "Error: failed to open " << configFileName << "; exiting..." << endl;
        exit(1);
    }

    string relativeFileName = "config/relativePlots.txt";
    ifstream relativeFile(relativeFileName);

    if(!relativeFile.is_open())
    {
        cerr << "Error: failed to open " << relativeFileName << "; exiting..." << endl;
        exit(1);
    }

    string buffer;
    vector<string> nuclides;
    vector<pair<string,string>> relativeDiffNames;

    while(getline(configFile, buffer))
    {
        nuclides.push_back(buffer);
    }

    while(getline(relativeFile, buffer))
    {
        vector<string> tokens;
        istringstream iss(buffer);
        copy(istream_iterator<string>(iss),
                istream_iterator<string>(),
                back_inserter(tokens));

        relativeDiffNames.push_back(make_pair(tokens[0], tokens[1]));
    }

    // begin cross section calculation
    vector<CrossSection> crossSections;

    for(auto& nucleus : nuclides)
    {
        Nucleus N("config/" + nucleus + ".txt");

        cout << "Producing cross section for " << N.Name << endl;

        // define energy range
        vector<double> energyRange;

        double startingPoint = log(1);
        double stepSize = (log(500)-log(1))/100;

        for(unsigned int i=0; i<100; i++)
        {
            energyRange.push_back(exp(i*stepSize+startingPoint));
        }

        // identify which optical model should be used for cross section
        // calculation, and perform calculation
        string argument = argv[1];

        if(argument == "SA")
        {
            // strongly absorbing disk model

            crossSections.push_back(calculateCS_SA(N, energyRange));
        }

        else if(argument == "ROP")
        {
            // optical potential with only a real, Woods-Saxon part

            OpticalPotential OP("config/" + nucleus + "_ROP.txt");
            crossSections.push_back(calculateCS_ROP(N, OP, energyRange));
        }

        else if(argument == "COP")
        {
            // optical potential with real and imaginary Woods-Saxon parts

            OpticalPotential OP("config/" + nucleus + "_COP.txt");
            crossSections.push_back(calculateCS_COP(N, OP, energyRange));
        }

        else if(argument == "COPS")
        {
            // optical potential with real and imaginary Woods-Saxon and surface
            // (derivative of Woods-Saxon) parts

            OpticalPotential OP("config/" + nucleus + "_COPS.txt");
            crossSections.push_back(calculateCS_COPS(N, OP, energyRange));
        }

        else
        {
            cerr << "Error: argument describing the optical potential to be used must be supplied." << endl;
        return 1;
        }
    }

    // cross sections have been calculated; make plots
    TFile* file = new TFile("opticalModel.root","RECREATE");

    for(auto& cs : crossSections)
    {
        TGraph* graph = new TGraph(
                cs.getDataSet().getNumberOfPoints(),
                &cs.getDataSet().getXValues()[0],
                &cs.getDataSet().getYValues()[0]);

        graph->SetNameTitle(cs.name.c_str(), cs.name.c_str());
        graph->Write();
    }

    for(auto& pair : relativeDiffNames)
    {
        CrossSection firstCS;
        CrossSection secondCS;

        for(auto& cs : crossSections)
        {
            if(cs.name == pair.first)
            {
                firstCS = cs;
            }

            if(cs.name == pair.second)
            {
                secondCS = cs;
            }
        }

        if(firstCS.name=="" || secondCS.name=="")
        {
            cerr << "Error: failed to find both cross sections \""
                << pair.first << "\", \"" << pair.second
                << " needed to calculate relative difference." << endl;

            break;
        }

        CrossSection relativeDiff = calculateRelativeDiff(firstCS, secondCS);
        relativeDiff.name = "relativeDiff(" + pair.first + "," + pair.second + ")";
        TGraph* graph = new TGraph(
                relativeDiff.getDataSet().getNumberOfPoints(),
                &relativeDiff.getDataSet().getXValues()[0],
                &relativeDiff.getDataSet().getYValues()[0]);

        graph->SetNameTitle(relativeDiff.name.c_str(), relativeDiff.name.c_str());
        graph->Write();
    }

    file->Close();

    return 0;
}
Beispiel #4
0
void genieta16calib()
{
  glob_t globbuf;

  int stat = glob (fileglob.c_str(), GLOB_MARK, NULL, &globbuf);
  if (stat) {
    switch (stat) {
    case GLOB_NOMATCH: cerr << "No file matching glob pattern "; break;
    case GLOB_NOSPACE: cerr << "glob ran out of memory "; break;
    case GLOB_ABORTED: cerr << "glob read error "; break;
    default: cerr << "unknown glob error stat=" << stat << " "; break;
    }
    cerr << fileglob << endl;
    exit(-1);
  }
  if (gl_verbose)
    cout<<globbuf.gl_pathc<<" files match the glob pattern"<<endl;
      
  for (size_t i=0; i<std::max((size_t)1,globbuf.gl_pathc); i++) {
    TVectorD vxday,vyfcamp,vzlumi;

    string path = globbuf.gl_pathv[i];

    // pick out day of year and mean(sum(fC))
    loadVectorsFromFile(path.c_str(),"%*lf %lf %lf %*lf %*s %*s %lf",vxday,vzlumi,vyfcamp);
    TGraph *pwg = new TGraph(vxday,vyfcamp);
    pwg->SetNameTitle(path.c_str(),path.c_str());

    //pwg->Print();

    v_graphs.push_back(pwg);

    optimizenorm(i,path);

    //pwg->Print();
  }

  // calc average and rms
  int ngraphs = (int)v_graphs.size();
  int npts    = v_graphs[0]->GetN();
  cout << ngraphs << " graphs, " << npts << " points per graph" << endl;
  TVectorD vx(npts),vyavg(npts),vyrms(npts), vxerr(npts);
  for (int i=0; i<npts; i++) {
    double x,y;
    v_graphs[0]->GetPoint(i,x,y);
    vx[i] = x;
    vxerr[i]=0;
    double yavg = y;
    for (int j=1; j<ngraphs; j++) {
      v_graphs[j]->GetPoint(i,x,y);
      if (x!=vx[i]) {
	cerr << x << " != " << vx[i] << endl;
	exit(-1);
      }
      yavg += y;
    }
    yavg /= (double)ngraphs;
    vyavg[i] = yavg;
    double var = 0.0;
    for (int j=0; j<ngraphs; j++) {
      v_graphs[j]->GetPoint(i,x,y);
      var += (y-yavg)*(y-yavg);
    }
    vyrms[i] = sqrt(var/(double)ngraphs);
  }

  TCanvas *c1 = new TCanvas("c1","c1",1500,600);
  v_graphs[0]->Draw("ALP");
  v_graphs[0]->GetHistogram()->GetYaxis()->SetRangeUser(0.0,2.0);
  v_graphs[0]->SetTitle("Average laser response from i#eta=-16 depth 3 over 2016, selected channels; Day # ; Arbitrary norm");
  for (int i=1; i<ngraphs; i++) {
    v_graphs[i]->Draw("LP same");
    v_graphs[i]->SetLineColor(15);
  }

  TGraphErrors *gravg = new TGraphErrors(vx,vyavg,vxerr,vyrms);

  gravg->Draw("LPE same");
  gravg->SetLineWidth(2);
  gPad->SetRightMargin(0.03);
  gPad->SetLeftMargin(0.08);
  gPad->Update();
  gPad->SaveAs("ieta-16calib.png");

  gravg->Print();
}
Beispiel #5
0
/*
root -l 'sigmapeak.C+(0.025)'
// 
Processing sigmapeak.C+(0.025)...
background only: bkg_nsigma_0_99 = -0.352803
sig_nsigma_0_59  = -0.608621
sig_nsigma_0_99  = 2.1472
sig_nsigma_60_99 = 4.14042
sig_nsigma_70_90 = 5.57689
sig_nsigma_75_85 = 8.056
*/
void sigmapeak(Double_t signal_area=0.025)
{
   Double_t bkg_mean = 0;
   Double_t bkg_sigma = 0.001;

   Double_t x[100];
   Double_t y[100];
   Int_t np = 100;
   
   TRandom3 rand;
   
   for (int i=0; i<np; ++i) {
      x[i] = i;
      y[i] = rand.Gaus(bkg_mean,bkg_sigma);
   }
   
   TGraph* gr = new TGraph(np,x,y);
   gr->SetNameTitle("gr",Form("#sigma = %0.1f",bkg_sigma));
   gr->SetMarkerStyle(7);
   gr->SetMarkerColor(46);
   new TCanvas();
   gr->Draw("ap");

   Double_t bkg_nsigma_0_99 = Nsigma(gr->GetY(), 0,99, bkg_sigma);
   cout<< "background only: bkg_nsigma_0_99 = " << bkg_nsigma_0_99 <<endl;

   // add signal

   Double_t signal_mean = 80;
   Double_t signal_sigma = 3;

   for (int i=0; i<gr->GetN(); ++i) {
      Double_t xx = (gr->GetX()[i] - signal_mean)/signal_sigma;
      Double_t arg = 0.5*xx*xx;
      Double_t exp = arg < 50? TMath::Exp(-arg): 0;
      Double_t signal = signal_area/(TMath::Sqrt(TMath::TwoPi())*signal_sigma) * exp;
      gr->SetPoint(i, gr->GetX()[i], gr->GetY()[i] + signal);
   }

   gr->SetTitle(Form("#sigma_{bkg} = %0.3f signal: area = %0.3f mean = %0.0f sigma = %0.1f", bkg_sigma,signal_area,signal_mean,signal_sigma));

   gr->Draw("apl");
   gr->Fit("gaus", "R", "", signal_mean - 5*signal_sigma, signal_mean+5*signal_sigma);
   Double_t fit_area = 2.5 * gr->GetFunction("gaus")->GetParameter("Constant") * gr->GetFunction("gaus")->GetParameter("Sigma");
   cout<< "Area under fitted gaussian = " << fit_area <<endl;

   // titmax();
   gPad->Modified();    // to create box (NB: the pad was not drawn yet at this point!)
   gPad->Update();
   TPaveText* tit = (TPaveText*)gPad->GetPrimitive("title");
   tit->SetX1NDC(0.);
   tit->SetX2NDC(1.);
   tit->SetY1NDC(0.9);
   tit->SetY2NDC(1.);
   gPad->Modified();    // to update the pad
   gPad->Update();

   Double_t sig_nsigma_0_59 = Nsigma(gr->GetY(), 0,59, bkg_sigma);
   cout<< "sig_nsigma_0_59  = " << sig_nsigma_0_59 <<endl;

   Double_t sig_nsigma_0_99 = Nsigma(gr->GetY(), 0,99, bkg_sigma);
   cout<< "sig_nsigma_0_99  = " << sig_nsigma_0_99 <<endl;

   Double_t sig_nsigma_60_99 = Nsigma(gr->GetY(), 60,99, bkg_sigma);
   cout<< "sig_nsigma_60_99 = " << sig_nsigma_60_99 <<endl;

   Double_t sig_nsigma_70_90 = Nsigma(gr->GetY(), 70,90, bkg_sigma);
   cout<< "sig_nsigma_70_90 = " << sig_nsigma_70_90 <<endl;

   Double_t sig_nsigma_75_85 = Nsigma(gr->GetY(), 75,85, bkg_sigma);
   cout<< "sig_nsigma_75_85 = " << sig_nsigma_75_85 <<endl;

   Double_t ys5[100];
   smooth5(np, gr->GetY(), ys5);
   TGraph* gr5 = new TGraph(np, x, ys5);
   gr5->SetNameTitle("gr5","smoothed on 5 points");
   gr5->SetMarkerStyle(7);
   gr5->SetMarkerColor(2);
   gr5->SetLineColor(2);
   new TCanvas;
   gr5->Draw("apl");

   Double_t ys7[100];
   smooth7(np, gr->GetY(), ys7);
   TGraph* gr7 = new TGraph(np, x, ys7);
   gr7->SetNameTitle("gr7","smoothed on 7 points");
   gr7->SetMarkerStyle(7);
   gr7->SetMarkerColor(8);
   gr7->SetLineColor(8);
   new TCanvas;
   gr7->Draw("apl");

   Double_t ys7a[100];
   smooth7a(np, gr->GetY(), ys7a);
   TGraph* gr7a = new TGraph(np, x, ys7a);
   gr7a->SetNameTitle("gr7a","smoothed on 7a points");
   gr7a->SetMarkerStyle(7);
   gr7a->SetMarkerColor(3);
   gr7a->SetLineColor(3);
   new TCanvas;
   gr7a->Draw("apl");

   Double_t ys5g[100];
   smooth5g(np, gr->GetY(), ys5g);
   TGraph* gr5g = new TGraph(np, x, ys5g);
   gr5g->SetNameTitle("gr5g","smoothed on 5g points");
   gr5g->SetMarkerStyle(7);
   gr5g->SetMarkerColor(4);
   gr5g->SetLineColor(4);
   new TCanvas;
   gr5g->Draw("apl");

   Double_t ys5a[100];
   smooth5a(np, gr->GetY(), ys5a);
   TGraph* gr5a = new TGraph(np, x, ys5a);
   gr5a->SetNameTitle("gr5a","smoothed on 5a points");
   gr5a->SetMarkerStyle(7);
   gr5a->SetMarkerColor(6);
   gr5a->SetLineColor(6);
   new TCanvas;
   gr5a->Draw("apl");
}
void TH2CB::Build()
{
    TH2DrawTool tool(this);

    const vec& a(shape.at(1));
    const vec& b(shape.at(2));



    std::set<Int_t>::const_iterator nexthole = bins_in_holes.begin();
    UInt_t vbins=0;

    tool.PushMatrix();
    for(int i=0;i<4;++i) {

        for( int j=0; j<2; ++j) {
            MakeLevel(tool,1,nexthole,vbins);
            tool.Translate(a);
            tool.Scale(-1,-1);
            MakeLevel(tool,1,nexthole,vbins);
            tool.Translate(b);
            tool.Scale(-1,-1);
        }
        tool.Translate(2.0*b-a);
    }
    tool.PopMatrix();

    tool.Translate(-1.0*a);

    for( int j=0; j<2; ++j) {
        MakeLevel(tool,1,nexthole,vbins);
        tool.Translate(a);
        tool.Scale(-1,-1);
        MakeLevel(tool,1,nexthole,vbins);
        tool.Translate(b);
        tool.Scale(-1,-1);
    }

    SetStats(kFALSE);
    GetXaxis()->SetTickLength(0);
    GetXaxis()->SetLabelSize(0);
    GetYaxis()->SetTickLength(0);
    GetYaxis()->SetLabelSize(0);

    TText* inlabel = new TText(3.24,-0.43,"Beam In");
    inlabel->SetTextSize(0.03);
    inlabel->SetTextAlign(22);  // middle, middle
    GetListOfFunctions()->Add(inlabel);

    TText* outlabel = new TText(0.73,-0.43,"Beam out");
    outlabel->SetTextSize(0.03);
    outlabel->SetTextAlign(22);  // middle, middle
    GetListOfFunctions()->Add(outlabel);

    for( int major=1;major<=20;++major){
        for( int minor=1;minor<=4;++minor) {
            for( int crystal=1;crystal<=9;++crystal) {

                const Int_t bin = GetBinOfMMC(major, minor, crystal);

                if( bin >0) {

                    TH2PolyBin* bin_obj = ((TH2PolyBin*) fBins->At(bin-1));
                    TGraph* graph = (TGraph*) bin_obj->GetPolygon();

                    const Int_t vbin = GetVBinOfMMC(major,minor,crystal);
                    if( vbin >=0 ) {
                        Int_t element = GetElementOfCrystal(vbin-1);

                        graph->SetNameTitle("", Form("Element %d (%d/%d/%d)",element, major, minor, crystal));
                    }
                }
            }

        }
    }

}