Commit 29ad0d8e authored by Emilio Depero's avatar Emilio Depero
Browse files

macro to plot file together

parent 9f2ad8f2
/////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
// Author: Jonas Nuber, jonas.nuber@psi.ch
// Date: November 2020
//////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
//// compile with g++ -std=c++11 -o reconstructAndPlot reconstructAndPlot.cc `root-config --cflags --glibs`
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <map>
#include <vector>
#include <random>
#include <algorithm>
//ROOT includes
#include "TFile.h"
#include "TSystem.h"
#include "TROOT.h"
#include "TString.h"
#include "TNtuple.h"
#include "TMath.h"
#include "TStyle.h"
#include "TCanvas.h"
#include "TH1.h"
#include "TH2.h"
#include "TColor.h"
#include "TF1.h"
#include "TF2.h"
#include "TLegend.h"
#include "TGraph.h"
#include "TGraphErrors.h"
#include "TVector.h"
#include "TList.h"
#include "TLatex.h"
#include "TRandom.h"
#include "TSystem.h"
#include "TGaxis.h"
#include "TFolder.h"
using namespace std;
//the format to store the sources
int main(int argc, char *argv[])
{
if (argc < 2 || argc > 6)
{
std::cout << "Usage: ./executable [inputFileName1] [outpuFileName2] ... (maximum is 5)" << std::endl;
return 1;
}
vector<TFile*> files;
TString outname("Plotfile.root");
for(unsigned int i(1); i < argc; ++i)
{
files.push_back(new TFile(argv[i]));
//outname += "-";
//outname += argv[i];
}
TFile* outfile = new TFile(outname, "RECREATE");
int colors[] = {kRed, kBlue, kGreen, kOrange, kViolet};
//choose histogram to cast, only 1D supported
vector<TString> histonames;
histonames.push_back("decayPositions_z");
histonames.push_back("decayPositions_z_target");
histonames.push_back("decayPositions_z_20deg");
histonames.push_back("angle");
for(unsigned int d(0); d < histonames.size(); ++d)
{
TLegend* leg = new TLegend(0.8,0.6,0.5,0.4);
TString cname(histonames[d]);cname + "_canvas";
TCanvas* c = new TCanvas(cname);
for(unsigned int n(0); n < files.size(); n++)
{
TH1D* hist = (TH1D*)files[n]->Get(histonames[d]);
//normalize
hist->Scale(1. / hist->GetEntries());
hist->SetLineColor(colors[n]);
hist->SetLineWidth(2);
leg->AddEntry(hist, files[n]->GetName(), "l");
//draw
if(n == 0)
hist->DrawClone();
else
hist->DrawClone("same");
}
leg->Draw("same");
c->Write();
}
std::cout << "PLOTTING FINISHED\n";
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment