windons <-> ubuntu

I am a student!
I an learning Linux.

I like badminton ball, billiard ball and chinese chess.
my blog is http://baidu.com
our size is http:/baidu.com
my love is 19951112

19960102 is also my love
my god, I am not a student, but STUDENT!

include <TTree.h>

include <stdio.h>

include

include

include

include <stdlib.h>

include <string.h>

include <TFile.h>

include <math.h>

include <TNtuple.h>

//#include <>

define numOfTotalEvent 10000000

void SetLeafAddress(TNtuple *ntuple, const char *name, void *address);

void spatialResolution(/string fileName/)
{

string fileName = "run0.root";
string fileNameToRead = fileName;
TFile *f = new TFile(fileNameToRead.c_str());

TNtuple *ntuple;
ntuple = (TNtuple*)f->Get("t5");
bool rowWise = true;
TBranch *eventBranch = ntuple->FindBranch("row_wise_branch");
if(! eventBranch) rowWise = false;

double PosX, PosY;
double PhotonEnergy;
int Status;

if(! rowWise)
{
    ntuple->SetBranchAddress("PosX", &PosX);
    ntuple->SetBranchAddress("PosY", &PosY);
    ntuple->SetBranchAddress("PhotonEnergy", &PhotonEnergy);
    ntuple->SetBranchAddress("Status", &Status);


    //ntuple->SetLeafAddress("", &);
}
else
{
    SetLeafAddress(ntuple, "PosX", &PosX);
    SetLeafAddress(ntuple, "PosY", &PosY);
    SetLeafAddress(ntuple, "PhotonEnergy", &PhotonEnergy);
    SetLeafAddress(ntuple, "Status", &Status);
}

// Creat the histogram
auto pos2d = new TH2F("Pos2D", "Pos2D", 200,-5,5,200,-5,5);
auto posX = new TH1F("PosX", "PosX", 200,-5,5);
auto posY = new TH1F("PosY", "PosY", 200,-5,5);
auto energy = new TH1F("Energy", "Energy", 500, 0, 5);
auto waveLength = new TH1F("WaveLength", "WaveLnegth", 500, 0, 1000);




// 在中子与氢核发生碰撞的过程中,中子可能并不会一次性损失全部能量,而是只损失一部分,在这种情况下,损失部分能量的中子仍然可能再次与氢核发生碰撞
// 一次碰撞损失全部能量: n + H -> proton, 对于反冲质子,praentID=0, track=2【注意trackID、stepID都是从1开始的】
// 一次碰撞损失部分能量: n + H -> proton + n', n' + H -> proton'等,对于proton,praentID=0, track=2,而对于proton',praentID=0,trackID>2

//long int numOfEvent=0;

for(int i=0; i<ntuple->GetEntries(); i++)
{
    ntuple->GetEntry(i);
    //++numOfEvent;

    pos2d->Fill(PosX, PosY);
    posX->Fill(PosX);
    posY->Fill(PosY);
    energy->Fill(PhotonEnergy);
    waveLength->Fill(1240/PhotonEnergy);


}


auto c1 = new TCanvas("c1", "c1", 1920, 1080);
//c1->cd();
c1 ->Divide(3, 2);
c1->cd(1);
pos2d->Draw();

c1->cd(2);
posX->Draw();

c1->cd(3);
posY->Draw();

c1->cd(4);
energy->Draw();

c1->cd(5);
waveLength->Draw();

//c1->cd();

}

void SetLeafAddress(TNtuple* ntuple, const char *name, void *address)
{
TLeaf *leaf = ntuple->FindLeaf(name);
if(! leaf)
{
std::cerr << "Error in : unknown leaf -->" << name << std::endl;
return;
}
leaf->SetAddress(address);
}

posted @ 2021-12-01 22:16  weigy  阅读(45)  评论(0)    收藏  举报