Skip to content

Commit

Permalink
Varie. Commit prima di provare il multithread
Browse files Browse the repository at this point in the history
  • Loading branch information
f-forcher committed Nov 11, 2016
1 parent 2e349e6 commit ec67351
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 50 deletions.
Binary file added Dati_vs_Simulations dat file.pdf
Binary file not shown.
Binary file modified Dati_vs_Simulations.pdf
Binary file not shown.
Binary file modified Optimized_Super/Dechanneling_Simulations
Binary file not shown.
Binary file modified Optimized_Super/src/main.o
Binary file not shown.
Binary file modified Optimized_Super/src/main_macro.o
Binary file not shown.
48 changes: 36 additions & 12 deletions src/cpp/read_histograms.C
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "TH1.h"
#include "TH2.h"
#include "TH1D.h"
#include "TRandom.h"
#include "TRandom3.h"

#include "../dbg_macro.h"
#include "../my_typedefs.h"
Expand Down Expand Up @@ -56,13 +58,13 @@ void read_histograms(std::string nome_cristallo,

// select +- 5 microrad in nomehisto5, +-10 in nomehisto10
string nomehisto5 = "hdati5_" + nome_cristallo;
string nomehisto5_rnd = "hdati5_" + nome_cristallo;
string nomehisto5_rnd = "hdati5_rnd_" + nome_cristallo;
string nomehisto10 = "hdati10_" + nome_cristallo;
string nomehisto10_rnd = "hdati10_" + nome_cristallo;
string nomehisto10_rnd = "hdati10_rnd_" + nome_cristallo;
string titlehisto5 = nome_cristallo + ", cuts at +- 5 microrad";
string titlehisto5_rnd = nome_cristallo + ", cuts at +- 5 microrad";
string titlehisto5_rnd = nome_cristallo + ", cuts at +- 5 microrad, randomized";
string titlehisto10 = nome_cristallo + ", cuts at +- 10 microrad";
string titlehisto10_rnd = nome_cristallo + ", cuts at +- 5 microrad";
string titlehisto10_rnd = nome_cristallo + ", cuts at +- 5 microrad, randomized";
//clog << nomehisto5 << endl;


Expand Down Expand Up @@ -93,20 +95,36 @@ void read_histograms(std::string nome_cristallo,

TH1D* histogram5_dat;
TH1D* histogram10_dat;
TH1D* histogram5_rnd_dat;
TH1D* histogram10_rnd_dat;

TRandom* rnd = new TRandom3();

if (histogram5 == nullptr or histogram10 == nullptr) {
histogram5_dat = new TH1D(
/* name */nomehisto5.c_str(),
/* title */titlehisto5.c_str(),
/* X-dimension */600 / 3, -200, 400 );
/* X-dimension */120, -200, 400 );

histogram10_dat = new TH1D(
/* name */nomehisto10.c_str(),
/* title */titlehisto10.c_str(),
/* X-dimension */600 / 3, -200, 400 );
/* X-dimension */120, -200, 400 );

histogram5_rnd_dat = new TH1D(
/* name */nomehisto5_rnd.c_str(),
/* title */titlehisto5_rnd.c_str(),
/* X-dimension */120, -200, 400 );

histogram10_rnd_dat = new TH1D(
/* name */nomehisto10_rnd.c_str(),
/* title */titlehisto10_rnd.c_str(),
/* X-dimension */120, -200, 400 );
} else {
histogram5_dat = histogram5;
histogram10_dat = histogram10;
histogram5_dat = histogram5;
histogram10_dat = histogram10;
histogram5_rnd_dat = histogram5_rnd;
histogram10_rnd_dat = histogram10_rnd;
}

//dati.print(datisize);
Expand All @@ -123,18 +141,24 @@ void read_histograms(std::string nome_cristallo,
DBG( std::clog << "delta_x: " << delta_x << std::endl; , ; )
if (x_entrata / MICRO_ > -5 and x_entrata / MICRO_ < 5) {
//vHistograms.front()->Fill(x_uscita-x_entrata);
histogram5_dat->Fill( -delta_x * 1e6 );
histogram5_dat->Fill( -delta_x / MICRO_ );
//histogram5_rnd_dat->Fill( -delta_x / MICRO_ + rnd->Gaus(-delta_x / MICRO_ ,5) ); // 5 murad of uncertainty
histogram5_rnd_dat->Fill( rnd->Gaus(-delta_x / MICRO_ ,5) ); // 5 murad of uncertainty
}

if (x_entrata / MICRO_ > -10 and x_entrata / MICRO_ < 10) {
//vHistograms.front()->Fill(x_uscita-x_entrata);
histogram10_dat->Fill( -delta_x * 1e6);
histogram10_dat->Fill( -delta_x / MICRO_ );
//histogram10_rnd_dat->Fill( -delta_x / MICRO_ + rnd->Gaus(-delta_x / MICRO_ ,5) );
histogram10_rnd_dat->Fill( rnd->Gaus(-delta_x / MICRO_ ,5) );
}
}

// Should be correct in either cases of the "if" above
histogram5 = histogram5_dat;
histogram10 = histogram10_dat;
histogram5 = histogram5_dat;
histogram10 = histogram10_dat;
histogram5_rnd = histogram5_rnd_dat;
histogram10_rnd = histogram10_rnd_dat;
// Technically not necessary now, but maybe I'll add more conditions
} else {
cerr << "[ERROR]: File .dat not opened!" << endl;
Expand Down
79 changes: 41 additions & 38 deletions src/main_macro.C
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ int main_macro(int argc, char* argv[]) {
// DBG( std::clog << "size: " << sim_data_test.getSize() << std::endl
// ; , ; )
std::vector<const char*> elenco_cristalli_sim {
//"STF45",
"STF49"
//"STF99"
"STF45"
// "STF49"
//"STF99"
};

char numero_run[FILENAME_MAX];
Expand All @@ -99,9 +99,11 @@ int main_macro(int argc, char* argv[]) {
DBG( std::clog << "nome_file_dat: " << nome_file_dat << std::endl
; , ; )
clog << numero_run << std::endl;
mions::read_histograms( crystal_name, nome_file_dat, histogram5, histogram5_rnd, histogram10, histogram10_rnd );
mions::read_histograms( crystal_name, nome_file_dat, histogram5, histogram5_rnd, histogram10,
histogram10_rnd );

mions::read_histograms_color( crystal_name, nome_file_dat, 10, histogramAm, histogramDech, histogramCh, histogramOth );
mions::read_histograms_color( crystal_name, nome_file_dat, 10, histogramAm, histogramDech, histogramCh,
histogramOth );
}

// string canvas_name = "Crystal simulation: " + crystal_name;
Expand All @@ -123,62 +125,63 @@ int main_macro(int argc, char* argv[]) {
// histogramCh->Draw();

histogramTot = new TH1D(
/* name */"total_histo",
/* title */"Total Histogram",
/* X-dimension */600 / 4, -200, 400 );
histogramTot->Add(histogramAm);
histogramTot->Add(histogramDech);
histogramTot->Add(histogramCh);
histogramTot->Add(histogramOth);



histogramAm-> SetFillColorAlpha(kBlue,0.4);
histogramDech-> SetFillColorAlpha(kRed,0.4);
histogramCh-> SetFillColorAlpha(kGreen,0.4);
histogramOth-> SetFillColorAlpha(kMagenta,0.4);
histogramTot-> SetLineColor(kGreen);
/* name */"total_histo",
/* title */"Total Histogram",
/* X-dimension */600 / 4, -200, 400 );
histogramTot->Add( histogramAm );
histogramTot->Add( histogramDech );
histogramTot->Add( histogramCh );
histogramTot->Add( histogramOth );

histogramAm->SetFillColorAlpha( kBlue, 0.4 );
histogramDech->SetFillColorAlpha( kRed, 0.4 );
histogramCh->SetFillColorAlpha( kGreen, 0.4 );
histogramOth->SetFillColorAlpha( kMagenta, 0.4 );
histogramTot->SetLineColor( kGreen );

//Normalize, for confronting with the data
// histogramAm->Scale(1.0/histogramAm->Integral());
// histogramCh->Scale(1.0/histogramCh->Integral());
// histogramDech->Scale(1.0/histogramDech->Integral());
// histogramOth->Scale(1.0/histogramOth->Integral());

auto totint = histogramAm->Integral() +
histogramCh->Integral() +
histogramDech->Integral() +
histogramOth->Integral();
histogramAm->Scale(1.0/totint);
histogramCh->Scale(1.0/totint);
histogramDech->Scale(1.0/totint);
histogramOth->Scale(1.0/totint);
histogramTot->Scale(1.0/histogramTot->Integral() );

auto totint = histogramAm->Integral() + histogramCh->Integral() + histogramDech->Integral()
+ histogramOth->Integral();
histogramAm->Scale( 1.0 / totint );
histogramCh->Scale( 1.0 / totint );
histogramDech->Scale( 1.0 / totint );
histogramOth->Scale( 1.0 / totint );
histogramTot->Scale( 1.0 / histogramTot->Integral() );

//histogramAm -> Draw();
//histogramCh -> Draw("same");
//histogramDech -> Draw("same");
//histogramOth -> Draw("same");
//histogramTot -> Draw("same");



// Experimental data
string nomefile_dati_sperimentali = "../Old_Macros_Dechanneling/Dechanneling_Histograms.root";
TFile * dati_sperimentali = new TFile( nomefile_dati_sperimentali.c_str() );
string nomehistoSper = "hdati10_" + string(crys); //TODO Generalizzare a un file
string nomehistoSper = "hdati10_" + string( crys ); //TODO Generalizzare a un file
TH1D * hDatiSper = (TH1D*) dati_sperimentali->Get( nomehistoSper.c_str() );

// histogram10->Scale(1.0/histogram10->Integral());
// hDatiSper->Scale(1.0/hDatiSper->Integral());

histogram10->Scale(1.0/histogram10->GetEntries());
hDatiSper->Scale(1.0/hDatiSper->GetEntries());
histogram10->Scale( 1.0 / histogram10->GetEntries() );
histogram10_rnd->Scale( 1.0 / histogram10_rnd->GetEntries() );
hDatiSper->Scale( 1.0 / hDatiSper->GetEntries() );

histogram10->SetLineColor( kGreen );
histogram10->Draw();

histogram10_rnd->SetLineColor( kRed );
histogram10_rnd->Draw( "same" );

hDatiSper -> SetLineColor(kRed);
histogram10 -> Draw();
hDatiSper -> Draw("same");
hDatiSper->SetLineColor( kRed );
hDatiSper->SetMarkerStyle( kPlus );
hDatiSper->SetMarkerSize( 0.5 );
hDatiSper->Draw( "0 P same" );

}

Expand Down

0 comments on commit ec67351

Please sign in to comment.