LCS Experiment.C

From New IAC Wiki
Jump to navigation Jump to search

//Syed's macro to superimpose experimental and simulated histograms

  1. include "TCanvas.h"
  2. include "TStyle.h"
  3. include "TH1.h"
  4. include "TH2.h"
  5. include "TGaxis.h"
  6. include "TRandom.h"

void LCS_Experiment() {

 struct evt_experiment {
   Int_t event;
   Float_t Energy, Counts;
 };
 struct evt_simulation{
   Int_t event;
   Float_t ComptonGunTrigger, ComptonEventCounter, ComptonKE_RestFrame, pos[3],mom[3], ComptonKE_LabFrame, Compton_px_LabFrame, Compton_py_LabFrame, Compton_pz_LabFrame, pdg_ID_Compton, electronKE_RestFrame, electronPos[3],electronMom[3], electronKE_LabFrame, electron_px_LabFrame, electron_py_LabFrame, electron_pz_LabFrame, pdg_ID_Electron, LabFrame_Compton_Angle;
 };
 ifstream in_experiment, in_simulation;
 in_experiment.open("36.5keV_Experiment.txt");
 in_simulation.open("532nm.txt");
 evt_experiment evt;
 evt_simulation evt1;
 Int_t nlines=0;
 TFile *f = new TFile("36.5keV_Experiment.root","RECREATE");
 TH2F *hist = new TH2F("LCS_Xray", "LCS_Xray", 250, 0, 50, 250, 0, 140);
 
 while(in_experiment.good()){
   evt.event=nlines;
   in_experiment  >> evt.Energy

>> evt.Counts;

   nlines++;
   hist->Fill(evt.Energy, evt.Counts, 500);
 }
 TCanvas *c1 = new TCanvas("c1","hists with different scales",600,400);
 //create/fill draw hist
 gStyle->SetOptStat(kFALSE);
 hist->Draw();
 c1->Update();
 TH1F *hist1 = new TH1F("LCS_Xray1", "LCS_Xray1", 400, 0, 50);
 nlines = 0;//to keep track of Compton events
 while(in_simulation.good()){
   evt1.event=nlines;
   in_simulation  >> evt1.ComptonGunTrigger

>> evt1.ComptonEventCounter >> evt1.ComptonKE_RestFrame >> evt1.pos[0] >> evt1.pos[1] >> evt1.pos[2] >> evt1.mom[0] >> evt1.mom[1] >> evt1.mom[2] >> evt1.ComptonKE_LabFrame >> evt1.Compton_px_LabFrame >> evt1.Compton_py_LabFrame >> evt1.Compton_pz_LabFrame >> evt1.pdg_ID_Compton >> evt1.electronKE_RestFrame >> evt1.electronPos[0] >> evt1.electronPos[1] >> evt1.electronPos[2] >> evt1.electronMom[0] >> evt1.electronMom[1] >> evt1.electronMom[2] >> evt1.electronKE_LabFrame >> evt1.electron_px_LabFrame >> evt1.electron_py_LabFrame >> evt1.electron_pz_LabFrame >> evt1.pdg_ID_Electron;

   //Compton event Angular Distribution
   evt1.LabFrame_Compton_Angle=acos(evt1.Compton_pz_LabFrame/sqrt(evt1.Compton_px_LabFrame*evt1.Compton_px_LabFrame+evt1.Compton_py_LabFrame*evt1.Compton_py_LabFrame+evt1.Compton_pz_LabFrame*evt1.Compton_pz_LabFrame))*180/3.14159265359;
   nlines++;
   hist1->Fill(evt1.ComptonKE_LabFrame);
 }

 ++(evt1.event);
 Float_t simulationEvents = evt1.event;
 Float_t scalingFactor = 0.0219;
 //printf("%f\t", simulationEvents);
 hist1->SetLineColor(kRed);
 hist1->Scale(scalingFactor);
 hist1->Draw("same");

}