Hi sorry to open a new topic, but I think that in this one Particle direction there is a lot confusion, so it’s better to write a new one.
I’ve this ROOT file
si-500596.root (1.4 MB)
by this macro
TBAlign.C (22.4 KB) TBAlign.h (4.3 KB)
and thanks to @Wile_E_Coyote who helped me to run it, I generete a new ROOT file in which I traslated the xh coordinate from local one to laboratory one.
By this code
if(nx33==1) hx33->Fill(x33[0]);
if(nx35==1) hx35->Fill(x35[0]);
if(nx37==1) hx37->Fill(x37[0]);
I also produced 3 histograms of the x33[0] @z33=1833.73, x35[0] @z35=1995.43 and x37[0] @z37=2125.43 where
x33[0], x35[0] and x37[0] are the x coordinates and z33, z35 and z37 the z coordinate of hits in 3 silicon trackers called 33,35 and 37, as showed in this image
Now I’ve a problem.
In the ROOT file I’ve 5237 entries.
When I’ve a hit in the three silicon tracker (i.e. if(nx33==1 && nx35==1 && nx37==1)
) for each event, I’ve to fit by this by this fuction
fit_line.C (1.2 KB)
the 3 the triad
Ai=(z33, x33[0])
Bi=(z35, x35[0])
Ci=(z35, x37[0])
where x33[0], x35[0], x37[0] values are stored in the ROOT file, instead I’ve to set z33=1873.93, z35= 1995.43 and z37=2125.43.
You see that given that I’ve 5237 entries, I can’t write by hand 5237 times the values in the macro and the fit results in the output file. So I need a way to read all the 5237 entries of x33[0], x35[0], x37[0] to fit the points Ai, Bi, Ci and write the results of the fit in a txt file.
I was trying in this way.
#include <fstream>
ofstream results;
results.open("C:/si-calo-sep18/Fit_parameters.txt", ios::out);
char s[]="Fit Parameters";
int i;
int n=3;
int ne=5237; //number of entries in the ROOT file
x[0]=x33[0];
x[1]=x35[0];
x[2]=x37[0];
results << "i \t a \t \ae \t b \t be \t chi2 \t \q" << endl;
for( i=0; i<=fChain->GetEntries(); i++){
z[0]=1873.93;
z[1]=1995.43;
z[2]=2125.43;
ex[0]=0.1;
ex[1]=0.1;
ex[2]=0.1;
if(nx33==1 && nx35==1 && nx37==1){
fit_line(z, x, n, ex, a, b, ae, be, chi2, q); // hits x versus z
results << i << "\t " << a << "\t " << ae << "\t " << b << "\t " << be << "\t " << chi2 << "\t "<< q << endl;
}
}
results.close();
What I would to do was:
- To fill a 5237 rows and 3 culomns array z[] with the values
- 1873.93 in the 5237 rows of the first culomn;
- 1995.43 in the 5237 rows of the second culomn;
- 2125.43 in the 5237 rows of the third culomn;
To fill a 5237 rows and 3 culomns array ex[] with the values
- 0.1 in the 5237 rows of the first culomn;
- 0.1 in the 5237 rows of the second culomn;
- 0.1 in the 5237 rows of the third culomn;
(ex[] is the error on the x-coordinate that I must set 0.1 for the 3 silicon trackers)
- Only when I have an hit in the 3 silicon trackers (that’s because I wrote
if(nx33==1 && nx35==1 && nx37==1)
- Fit the point the 3 point of each event and write the fit parameters (a,b,chi2, etc) on a txt file
I runned the macro whitout errors, and I get the txt file but
- The results of all rows are identical, so I guess that the macro doesn’t fit all the line, but just the firs one
- I should get a negative value of the
a
parameter (because thex values
are all negative), instead I get a positive one! - I get 5237 lines in the result file, instead surely the are rows without hit in some silicon tracker (so I’ve not fit these rows)
Here the results
Fit_parameters.txt (310.9 KB)
@Wile_E_Coyote, @bellenot, @couet, @moneta please someone can check the macro?
Thank you
Please read tips for efficient and successful posting and posting code
ROOT Version: 6.20/24
Platform: Windows
Compiler: Not Provided