Drawing the projection

hi
I have E histogram in my program and i want to project this histogram in a function in my program like this:

void chan(){
for (int j=15;j<30;j=j+2){
    TF1 *f =new TF1 ("f","pol2");
    E->ProjectionY("test",j-2,j+2);
    test->Fit(f,"R","",0,100);
}
}
I add below commend in the main of my program:
for (int j=15;j<30;j=j+2){  
    chan();
ps->NewPage();
c>cd();
test->Draw();
c->Update;
}

but i don’t have my projections(test) and fits.
pleas guide me how can i draw this project?
thank you

Can you post a running macro showing the problem ? (not just two separate piece of code)

Thanks for your answer
in the attachment file you can find a part of my program.In this program i can’t draw projection of histogram of E1E2[det](“test” histogram).I use tree as input file if it is necessary i can send this tree.
Ecalib.cxx (1.8 KB)

Your macro produces many errors:

Processing Ecalib.cxx...
In file included from input_line_9:1:
/Users/couet/Downloads/Ecalib.cxx:1:1: error: extraneous closing brace ('}')
}
^
/Users/couet/Downloads/Ecalib.cxx:10:3: error: use of undeclared identifier 'test'
  test = new TH1D("test","",95,0,190);
  ^
/Users/couet/Downloads/Ecalib.cxx:16:14: error: use of undeclared identifier 'minX'
  for (int j=minX;j<maxX;j=j+2){
             ^
/Users/couet/Downloads/Ecalib.cxx:16:21: error: use of undeclared identifier 'maxX'
  for (int j=minX;j<maxX;j=j+2){
                    ^
/Users/couet/Downloads/Ecalib.cxx:18:5: error: use of undeclared identifier 'E1E2'
    E1E2[det]->ProjectionY("test",j-2,j+2);
    ^
/Users/couet/Downloads/Ecalib.cxx:19:9: error: use of undeclared identifier 'test'
    if (test->GetEntries()>20){
        ^
/Users/couet/Downloads/Ecalib.cxx:21:7: error: use of undeclared identifier 'Ref'
      Ref=test->GetMaximumBin()*2;
      ^
/Users/couet/Downloads/Ecalib.cxx:21:11: error: use of undeclared identifier 'test'
      Ref=test->GetMaximumBin()*2;
          ^
/Users/couet/Downloads/Ecalib.cxx:22:7: error: use of undeclared identifier 'BC'
      BC=test->GetBinContent(Ref/2);
      ^
/Users/couet/Downloads/Ecalib.cxx:22:10: error: use of undeclared identifier 'test'
      BC=test->GetBinContent(Ref/2);
         ^
/Users/couet/Downloads/Ecalib.cxx:22:30: error: use of undeclared identifier 'Ref'
      BC=test->GetBinContent(Ref/2);
                             ^
/Users/couet/Downloads/Ecalib.cxx:24:7: error: use of undeclared identifier 'test'
      test->Fit(f,"R","",0,Ref-30);
      ^
/Users/couet/Downloads/Ecalib.cxx:24:28: error: use of undeclared identifier 'Ref'
      test->Fit(f,"R","",0,Ref-30);
                           ^
/Users/couet/Downloads/Ecalib.cxx:25:7: error: use of undeclared identifier 'bg'
      bg=f->GetParameter(0);
      ^
/Users/couet/Downloads/Ecalib.cxx:26:25: error: use of undeclared identifier 'bg'
      f1->SetParameters(bg,0,0,BC,Ref,2);
                        ^
/Users/couet/Downloads/Ecalib.cxx:26:32: error: use of undeclared identifier 'BC'
      f1->SetParameters(bg,0,0,BC,Ref,2);
                               ^
/Users/couet/Downloads/Ecalib.cxx:26:35: error: use of undeclared identifier 'Ref'
      f1->SetParameters(bg,0,0,BC,Ref,2);
                                  ^
/Users/couet/Downloads/Ecalib.cxx:27:7: error: use of undeclared identifier 'test'
      test->Fit(f1,"R","",0,130);
      ^
/Users/couet/Downloads/Ecalib.cxx:35:5: error: use of undeclared identifier 'breakup'
int breakup::Analysis(unsigned int evSta ,unsigned int evSto,int Polar)
    ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
``

hi
thanks, i 'm sorry this was a part of my program not complete program. and i want you to see it i don’t know you want to run it
in fact my problem is that how can i draw the histogram of projection; for example i have:
E1->ProjectionY(“test”,j-2,j+2) and “test” is the histogram after projection. how can i draw “test”?
thanks

TH1D* test = E1->ProjectionY("test",j-2,j+2);
test->Draw();

See TH2::ProjectionY.

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