Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:54

0001 // -------------------------------------------------------------------
0002 // -------------------------------------------------------------------
0003 //
0004 // *********************************************************************
0005 // To execute this macro under ROOT after your simulation ended,
0006 //   1 - launch ROOT (usually type 'root' at your machine's prompt)
0007 //   2 - type '.X plot.C' at the ROOT session prompt
0008 // *********************************************************************
0009 
0010 void SetLeafAddress(TNtuple* ntuple, const char* name, void* address);
0011 
0012 void plot()
0013 {
0014   gROOT->Reset();
0015   gStyle->SetPalette(1);
0016   gROOT->SetStyle("Plain");
0017 
0018   TCanvas* c1 = new TCanvas ("c1","",20,20,2000,500);
0019   c1->Divide(4,1);
0020 
0021   // Uncomment if merging should be done
0022   //system ("rm -rf dna.root");
0023   //system ("hadd dna.root dna_*.root");
0024 
0025   TFile* f = new TFile("dna.root");
0026 
0027   TNtuple* ntuple;
0028   ntuple = (TNtuple*)f->Get("step");
0029   bool rowWise = true;
0030   TBranch* eventBranch = ntuple->FindBranch("row_wise_branch");
0031   if ( ! eventBranch ) rowWise = false;
0032   // std::cout <<  "rowWise: " << rowWise << std::endl;
0033 
0034   //*********************************************************************
0035   // canvas tab 1
0036   //*********************************************************************
0037 
0038   c1->cd(1);
0039   gStyle->SetOptStat(000000);
0040 
0041   // All
0042   ntuple->SetFillStyle(1001);
0043   ntuple->SetFillColor(2);
0044   ntuple->Draw("flagProcess","","B");
0045 
0046   // Excitation
0047   ntuple->SetFillStyle(1001);
0048   ntuple->SetFillColor(3);
0049   ntuple->Draw("flagProcess","flagProcess==12||flagProcess==15||flagProcess==22||flagProcess==32||flagProcess==42||flagProcess==52||flagProcess==62","Bsame");
0050 
0051   // Elastic
0052   ntuple->SetFillStyle(1001);
0053   ntuple->SetFillColor(4);
0054   ntuple->Draw("flagProcess","flagProcess==11||flagProcess==21||flagProcess==31||flagProcess==41||flagProcess==51||flagProcess==61||flagProcess==110||flagProcess==210||flagProcess==410||flagProcess==510||flagProcess==710||flagProcess==120||flagProcess==220||flagProcess==420||flagProcess==520||flagProcess==720","Bsame");
0055 
0056   // Ionisation
0057   ntuple->SetFillStyle(1001);
0058   ntuple->SetFillColor(5);
0059   ntuple->Draw("flagProcess","flagProcess==13||flagProcess==23||flagProcess==33||flagProcess==43||flagProcess==53||flagProcess==63||flagProcess==73||flagProcess==130||flagProcess==230||flagProcess==430||flagProcess==530||flagProcess==730","Bsame");
0060 
0061   // Charge decrease
0062   //ntuple->SetFillStyle(1001);
0063   //ntuple->SetFillColor(6);
0064   //ntuple->Draw("flagProcess","flagProcess==24||flagProcess==44||flagProcess==54","Bsame");
0065 
0066   // Charge increase
0067   //ntuple->SetFillStyle(1001);
0068   //ntuple->SetFillColor(7);
0069   //ntuple->Draw("flagProcess","flagProcess==35||flagProcess==55||flagProcess==65","Bsame");
0070 
0071   gPad->SetLogy();
0072 
0073   //*********************************************************************
0074   // canvas tab 2
0075   //*********************************************************************
0076 
0077   c1->cd(2);
0078 
0079   ntuple->SetMarkerColor(2);
0080 
0081   ntuple->Draw("x:y:z","flagParticle==1");
0082 
0083   //ntuple->SetMarkerColor(4);
0084   //ntuple->SetMarkerSize(4);
0085   //ntuple->Draw("x:y:z/1000","flagParticle==4 || flagParticle==5 || flagParticle==6","same");
0086 
0087   //*********************************************************************
0088   // canvas tab 3
0089   //*********************************************************************
0090 
0091   c1->cd(3);
0092 
0093   Double_t flagParticle;
0094   Double_t flagProcess;
0095   Double_t x;
0096   Double_t y;
0097   Double_t z;
0098   Double_t totalEnergyDeposit;
0099   Double_t stepLength;
0100   Double_t kineticEnergyDifference;
0101   Int_t eventID;
0102   Double_t kineticEnergy;
0103   Int_t stepID;
0104   Int_t trackID;
0105   Int_t parentID;
0106   Double_t angle;
0107 
0108   if ( ! rowWise ) {
0109     ntuple->SetBranchAddress("flagParticle",&flagParticle);
0110     ntuple->SetBranchAddress("flagProcess",&flagProcess);
0111     ntuple->SetBranchAddress("x",&x);
0112     ntuple->SetBranchAddress("y",&y);
0113     ntuple->SetBranchAddress("z",&z);
0114     ntuple->SetBranchAddress("totalEnergyDeposit",&totalEnergyDeposit);
0115     ntuple->SetBranchAddress("stepLength",&stepLength);
0116     ntuple->SetBranchAddress("kineticEnergyDifference",&kineticEnergyDifference);
0117     ntuple->SetBranchAddress("kineticEnergy",&kineticEnergy);
0118     ntuple->SetBranchAddress("cosTheta",&angle);
0119     ntuple->SetBranchAddress("eventID",&eventID);
0120     ntuple->SetBranchAddress("trackID",&trackID);
0121     ntuple->SetBranchAddress("parentID",&parentID);
0122     ntuple->SetBranchAddress("stepID",&stepID);
0123   }
0124   else {
0125     SetLeafAddress(ntuple, "flagParticle",&flagParticle);
0126     SetLeafAddress(ntuple, "flagProcess",&flagProcess);
0127     SetLeafAddress(ntuple, "x",&x);
0128     SetLeafAddress(ntuple, "y",&y);
0129     SetLeafAddress(ntuple, "z",&z);
0130     SetLeafAddress(ntuple, "totalEnergyDeposit",&totalEnergyDeposit);
0131     SetLeafAddress(ntuple, "stepLength",&stepLength);
0132     SetLeafAddress(ntuple, "kineticEnergyDifference",&kineticEnergyDifference);
0133     SetLeafAddress(ntuple, "kineticEnergy",&kineticEnergy);
0134     SetLeafAddress(ntuple, "cosTheta",&angle);
0135     SetLeafAddress(ntuple, "eventID",&eventID);
0136     SetLeafAddress(ntuple, "trackID",&trackID);
0137     SetLeafAddress(ntuple, "parentID",&parentID);
0138     SetLeafAddress(ntuple, "stepID",&stepID);
0139   }
0140 
0141   TH1F* hsolvE = new TH1F ("hsolvE","solvE",100,0,2000);
0142   TH1F* helastE = new TH1F ("helastE","elastE",100,0,2000);
0143   TH1F* hexcitE = new TH1F ("hexcitE","excitE",100,0,2000);
0144   TH1F* hioniE = new TH1F ("hiioniE","ioniE",100,0,2000);
0145   TH1F* hattE = new TH1F ("hattE","attE",100,0,2000);
0146   TH1F* hvibE = new TH1F ("hvibE","vibE",100,0,2000);
0147 
0148   for (Int_t j=0;j<ntuple->GetEntries(); j++)
0149   {
0150     ntuple->GetEntry(j);
0151     if (flagProcess==10) hsolvE->Fill(x);
0152     if (flagProcess==11) helastE->Fill(x);
0153     if (flagProcess==12) hexcitE->Fill(x);
0154     if (flagProcess==13) hioniE->Fill(x);
0155     if (flagProcess==14) hattE->Fill(x);
0156     if (flagProcess==15) hvibE->Fill(x);
0157 
0158   }
0159 
0160   helastE->GetXaxis()->SetTitle("x (nm)");
0161   helastE->SetLineColor(2);
0162 
0163   hexcitE->SetLineColor(3);
0164   hioniE->SetLineColor(4);
0165   hattE->SetLineColor(5);
0166   hvibE->SetLineColor(6);
0167   hsolvE->SetLineColor(7);
0168 
0169   gPad->SetLogy();
0170 
0171   helastE->Draw("");
0172   hexcitE->Draw("SAME");
0173   hioniE->Draw("SAME");
0174   hattE->Draw("SAME");
0175   hvibE->Draw("SAME");
0176   hsolvE->Draw("SAME");
0177 
0178   //*********************************************************************
0179   // canvas tab 4
0180   //*********************************************************************
0181 
0182   TNtuple* ntuple2;
0183   ntuple2 = (TNtuple*)f->Get("track");
0184   bool rowWise2 = true;
0185   TBranch* eventBranch2 = ntuple2->FindBranch("row_wise_branch");
0186   if ( ! eventBranch2 ) rowWise2 = false;
0187 
0188   c1->cd(4);
0189   gStyle->SetOptStat(000000);
0190 
0191   // All
0192   ntuple2->SetFillStyle(1001);
0193   ntuple2->SetFillColor(2);
0194   ntuple2->Draw("kineticEnergy","flagParticle==1","B");
0195 
0196   gPad->SetLogy();
0197 
0198 }
0199 
0200 void SetLeafAddress(TNtuple* ntuple, const char* name, void* address) {
0201   TLeaf* leaf = ntuple->FindLeaf(name);
0202   if ( ! leaf ) {
0203     std::cerr << "Error in <SetLeafAddress>: unknown leaf --> " << name << std::endl;
0204     return;
0205   }
0206   leaf->SetAddress(address);
0207 }