Run macro file

Dear All,
I’m running the macro file to make histogram from a root file. But I’m getting error. As this macro was running okay in ROOT5.34 but not working on ROOT 6.28. Can anyone help me?

"char name[20]="TOFcut3828";
    int maxnum = 24;
    int maxeventnum=10000;
    
    TChain tr("ge"); // treeNameという名のTTreeのchain
    
    tr.Add(Form("%s.root",name)); // treeNameなTTreeを含むROOTファイル
    for(i=1;i<=maxnum;i++){ // 連番ファイルの連結の例
        if(i<=9){
            tr.Add(Form("%s_00%d.root",name,i));}
        else{
            tr.Add(Form("%s_0%d.root",name,i));}
    }
    
    tr.GetEntries();


ROOT Version: ROOT 6.28/02
Platform: mac


Welcome to the ROOT forum

The macro you sent does not seem to be complete. Can you sent it as attachment ?
Also what are the error messages ?

chain.c (389 Bytes)
M1back.cc (1.9 KB)

Basically your macro M1Back.cc is:

void M1back(){
   char name[20]="cut3823";
   int maxnum = 3;
   int maxeventnum=10000;

   TChain tr("ge"); // treeNameという名のTTreeのchain
   tr.Add(Form("%s.root",name)); // treeNameなTTreeを含むROOTファイル

   for(int i=1;i<=maxnum;i++){ // 連番ファイルの連結の例
      if(i<=9){
         tr.Add(Form("%s_00%d.root",name,i));}
      else{
         tr.Add(Form("%s_0%d.root",name,i));}
   }
   tr.GetEntries();

   TH1D *h = new TH1D("h","h",16000,-0.5,15999.5);
   ge->Draw("c16.E>>h","c29.E>1310&&c29.E<1350");

   TSpectrum *s = new TSpectrum;
   s->Background(h,20,"");

   TH1D *h1 =new TH1D("h1","h1",16000,-0.5,15999.5);
   h1->Add(h);
   h1->Add(h_background,-1.);
}

just after the line TH1D *h ... you draw ge but ge is not declared.

Can you help me in this regard?

I think you should simply do:

   tr.Draw("c16.E>>h","c29.E>1310&&c29.E<1350");

Thanks for your valuable comment. Can you please tell me in which portion I need to change?

Try something like that:

void M1back(){
   char name[20]="cut3823";
   int maxnum = 3;
   int maxeventnum=10000;

   auto tr = new TChain("ge"); // treeNameという名のTTreeのchain
   tr->Add(Form("%s.root",name)); // treeNameなTTreeを含むROOTファイル

   for(int i=1;i<=maxnum;i++){ // 連番ファイルの連結の例
      if(i<=9){
         tr->Add(Form("%s_00%d.root",name,i));}
      else{
         tr->Add(Form("%s_0%d.root",name,i));}
   }
   tr->GetEntries();

   auto h = new TH1D("h","h",16000,-0.5,15999.5);
   tr->Draw("c16.E>>h","c29.E>1310&&c29.E<1350");

   auto s = new TSpectrum();
   s->Background(h,20,"");

   auto h1 =new TH1D("h1","h1",16000,-0.5,15999.5);
   h1->Add(h);
   h1->Add(h_background,-1.); // >>> h_background should be defined !
}

Note: in your example h_background is not defined. You need to define it. See the comment

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.