コード例 #1
0
ファイル: read21.c プロジェクト: yuichiok/macros
void read21m() {
    
    TFile *f = new TFile("read21.root");    //root file name
    TTree *ntuple = (TTree*)f->Get("ntuple");
    
    Float_t hm,zm;  //Values
    
    ntuple->SetBranchAddress("hm",&hm);   //Values
    ntuple->SetBranchAddress("zm",&zm);
    
    //create histogram
    TH1F *higg     = new TH1F("hm","Higgs invariant mass distribution",100,0,300.);
    TH1F *zboson   = new TH1F("zm","Z0 invariant mass distribution",100,0,300.);
    
    //read all entries and fill the histograms
    Long64_t nentries = ntuple->GetEntries();
    for (Long64_t q=0;q<nentries;q++) {
        ntuple->GetEntry(q);
        higg->Fill(hm);        //Histogram value
        zboson->Fill(zm);
        }
    
    {
        higg->SetXTitle("m[GeV]");
        higg->SetYTitle("Event");
        zboson->SetXTitle("m[GeV]");
        zboson->SetYTitle("Event");
    }
    
    if (gROOT->IsBatch()) return;
    f->Write();
    new TBrowser();
    ntuple->StartViewer();
    
}
コード例 #2
0
void tree0() {
  // create a TTree   
  TTree *tree = new TTree("tree","treelibrated tree");
  Event *e = new Event;
  
  // create a branch with energy 
  tree->Branch("event",&e);
  
  // fill some events with random numbers
  Int_t nevent=10000;
  for (Int_t iev=0;iev<nevent;iev++) {
    if (iev%1000==0) cout<<"Processing event "<<iev<<"..."<<endl;
    
    Float_t ea,eb;
    gRandom->Rannor(ea,eb); // the two energies follow a gaus distribution
    e->a.e=ea;
    e->b.e=eb;
    e->a.t=gRandom->Rndm();  // random
    e->b.t=e->a.t + gRandom->Gaus(0.,.1);  // identical to a.t but a gaussian
                                           // 'resolution' was added with sigma .1

    tree->Fill();  // fill the tree with the current event
  }  

  // start the viewer
  // here you can investigate the structure of your Event class
  tree->StartViewer();

  //gROOT->SetStyle("Plain");   // uncomment to set a different style
  gStyle->SetPalette(1);        // use precomputed color palette 1

  // now draw some tree variables 
  TCanvas *c1 = new TCanvas();
  c1->Divide(2,2);
  c1->cd(1); 
  tree->Draw("a.e");  //energy of det a
  tree->Draw("a.e","3*(-.2<b.e && b.e<.2)","same");  // same but with condition on energy b; scaled by 3
  c1->cd(2); 
  tree->Draw("b.e:a.e","","colz");        // one energy against the other
  c1->cd(3); 
  tree->Draw("b.t","","e");    // time of b with errorbars
  tree->Draw("a.t","","same"); // overlay time of detector a
  c1->cd(4);
  tree->Draw("b.t:a.t");       // plot time b again time a

  cout<<endl;
  cout<<"You can now examine the structure of your tree in the TreeViewer"<<endl;
  cout<<endl;
}
コード例 #3
0
ファイル: runPEvent.C プロジェクト: asmagina1995/roottest
void runPEvent() {

#ifndef ClingWorkAroundMissingDynamicScope
   gROOT->ProcessLine(".L PEvent.cc+");
#endif

    const Int_t n = 100;
    UInt_t *array = new UInt_t[n];

#ifdef ClingWorkAroundJITandInline
    for(Int_t i(0); i<n; i++)
        array[i] = 300*TMath::Abs(sin(6.28318530717959*i/n));
#else
   for(Int_t i(0); i<n; i++)
      array[i] = 300*TMath::Abs(TMath::Sin(TMath::TwoPi()*i/n));
#endif
    QRawTriggerPulse* tp = new QRawTriggerPulse(n,array);

    TFile *f = new TFile("myTest.root","recreate");
    TTree *t = new TTree("t","mytree");

    PEvent *q = new PEvent(*tp);
    t->Branch("event.","PEvent",&q);
    //t->Branch("thepulse",&tp);


    t->Fill();
    t->AutoSave();

    for(Int_t i(0); i<n; i++)
        cout << i << "   " << tp->GetSample()[i] << endl;

    f->Close();
    delete f;
    delete q;
    delete tp;

#ifdef ClingReinstateRedeclarationAllowed
   TFile *f = new TFile("myTest.root");
   TTree *t = (TTree*)f->Get("t");   
#else
   f = new TFile("myTest.root");
   t = (TTree*)f->Get("t");
#endif
    t->StartViewer();
    t->Draw("event.fRawTriggerPulse.fSample");

}
コード例 #4
0
ファイル: read25c.c プロジェクト: yuichiok/macros
void read25cm() {
    
    TFile *f = new TFile("read25c.root");    //root file name
    TTree *ntuple = (TTree*)f->Get("ntuple");
    
    Float_t dRm,dRmbar,dRb,dRbbar;  //Values
    
    ntuple->SetBranchAddress("dRm",&dRm);   //Values
    ntuple->SetBranchAddress("dRmbar",&dRmbar);
    ntuple->SetBranchAddress("dRb",&dRb);
    ntuple->SetBranchAddress("dRbbar",&dRbbar);
    
    //create histogram
    TH1F *mudR     = new TH1F("dRm","dR distribution of mu and jet",100,0.,2 * M_PI);
    TH1F *mubardR   = new TH1F("dRmbar","dR distribution of mubar and jet",100,0.,2 * M_PI);
    TH1F *bdR     = new TH1F("dRb","dR distribution of b and jet",100,0.,2 * M_PI);
    TH1F *bbardR     = new TH1F("dRbbar","dR distribution of bbar and jet",100,0.,2 * M_PI);
    
    //read all entries and fill the histograms
    Long64_t nentries = ntuple->GetEntries();
    for (Long64_t q=0;q<nentries;q++) {
        ntuple->GetEntry(q);
        mudR->Fill(dRm);        //Histogram value
        mubardR->Fill(dRmbar);
        bdR->Fill(dRb);
        bbardR->Fill(dRbbar);
        }
    
    {
        mudR->SetXTitle("dR");
        mudR->SetYTitle("Event");
        mubardR->SetXTitle("dR");
        mubardR->SetYTitle("Event");
        bdR->SetXTitle("dR");
        bdR->SetYTitle("Event");
        bbardR->SetXTitle("dR");
        bbardR->SetYTitle("Event");
    }
    
    if (gROOT->IsBatch()) return;
    f->Write();
    new TBrowser();
    ntuple->StartViewer();
    
}
コード例 #5
0
ファイル: pythiaExample.C プロジェクト: digideskio/root
// Show the Pt spectra, and start the tree viewer.
int showEventSample()
{
  // Load needed libraries
  loadLibraries();

  // Open the file
  TFile* file = TFile::Open(FILENAME, "READ");
  if (!file || !file->IsOpen()) {
    Error("showEventSample", "Couldn;t open file %s", FILENAME);
    return 1;
  }

  // Get the tree
  TTree* tree = (TTree*)file->Get(TREENAME);
  if (!tree) {
    Error("showEventSample", "couldn't get TTree %s", TREENAME);
    return 2;
  }

  // Start the viewer.
  tree->StartViewer();

  // Get the histogram
  TH1D* hist = (TH1D*)file->Get(HISTNAME);
  if (!hist) {
    Error("showEventSample", "couldn't get TH1D %s", HISTNAME);
    return 4;
  }

  // Draw the histogram in a canvas
  gStyle->SetOptStat(1);
  TCanvas* canvas = new TCanvas("canvas", "canvas");
  canvas->SetLogy();
  hist->Draw("e1");
  TF1* func = hist->GetFunction("expo");

  char expression[64];
  sprintf(expression,"T #approx %5.1f", -1000 / func->GetParameter(1));
  TLatex* latex = new TLatex(1.5, 1e-4, expression);
  latex->SetTextSize(.1);
  latex->SetTextColor(4);
  latex->Draw();

  return 0;
}