Double_t distance=1000; //Flight path (cm) Double_t * GetPositions(Int_t index){ Double_t vec[2]; vec[0]=-Pixel::GetDetSizeX()/2+(index%100+0.5)*Pixel::GetPixelSizeX(); vec[1]= Pixel::GetDetSizeX()/2-(index/100+0.5)*Pixel::GetPixelSizeX(); return vec; } //main macro void makePixelTree( Float_t beam_momentum) { gROOT->LoadMacro("Pixel.cxx++g"); gROOT->LoadMacro("PixelTimeInfo.cxx++g"); // Create some histograms. TH2F *hXvsY = new TH2F("hXvsY","X-Y distribution of Pixels",100,5,-5, 100,-5,5); TH1F *hTime = new TH1F("hTime","Time distribution of Pixels",1000,30,50); //opzioni grafiche istogrammi hXvsY->SetMarkerStyle(21); hXvsY->SetMarkerSize(0.3); hXvsY->SetMarkerColor(2); hXvsY->GetYaxis()->SetTitle("Position Y (cm)"); hXvsY->GetXaxis()->SetTitle("Position X (cm)"); hTime->GetXaxis()->SetTitle("Time (ns)"); //open a root file TTree *T = new TTree("T","Pixel tree"); //create a tree Double_t mass, time,x,y; Int_t index; T->Branch("mass",&mass,"mass/D"); T->Branch("time",&time,"time/D"); T->Branch("x",&x,"x/D"); T->Branch("y",&y,"y/D"); T->Branch("index",&index,"index/I"); PixelTimeInfo::OpenCalibFile(); // Create Pixels from tracks hitting randomly on the detector randomly gBenchmark->Reset(); gBenchmark->Start("makeHistos"); gRandom->SetSeed(); // setting the initial seed Int_t iParticle=0; Double_t particle_Mass[]={0.149,0.498,0.938}; PixelTimeInfo myPixel; for ( Int_t i=0; i<100000; i++) { iParticle= gRandom->Rndm()*3; //random extraction of species index = gRandom->Rndm()*10000; //random extraction of pixel position Double_t *vec=GetPositions(index); x=vec[0], y=vec[1]; mass=particle_Mass[iParticle]; Float_t path=TMath::Sqrt(x*x +y*y+distance*distance); time=path*TMath::Sqrt(beam_momentum*beam_momentum+particle_Mass[iParticle]*particle_Mass[iParticle])/(beam_momentum*2.99E1); // this is the flight time, t=path/(beta*c), in ns time=gRandom->Gaus(time,0.1); myPixel=PixelTimeInfo(index,time); hXvsY->Fill(myPixel.GetPosX(),myPixel.GetPosY()); hTime->Fill(myPixel.GetTime()); T->Fill(); } //stop benchmarking execution time gBenchmark->Stop("makeHistos"); gBenchmark->Show("makeHistos"); PixelTimeInfo::CloseCalibFile(); // draw the histogram TCanvas *cHist=new TCanvas("cHist","test histograms",50,50,700,300); cHist->Divide(2,1); cHist->cd(1); hXvsY->Draw(); cHist->cd(2); hTime->Draw(); TFile *file = new TFile("pixelTree.root","recreate"); //apro il file root hXvsY->Write(); hTime->Write(); T->Write(); //scrive il tree su file file->Close();//chiudo il file }