Crossing point of two signals(function)

Hi boys,

I’m really glad to start ROOT learning. Would anyone be kind enough to help a beginner ?

Well, i have two plot that i could draw them successfully. Next i draw them at ones Canvas using “same”. Okay, Now i’m looking for the cross point. I mean somewhere that the first signal cross the second one. The crossing coordinate is my interest.

I’m beginner and i can share my code if need.

Any help will appreciated. :rose::rose::rose:

What kind of object are you using to draw these two plots ? TH1/D/F ? TGraph ?

1 Like

@couet // Thanks a lot for answering. Actually its two digitized signals that i saved the digitized data in a txt file. the txt file consisting a numbers that correspond to ADC heights. look at this :


I saved this signal data to a txt file.
As i said, i have 2 signal and now i plot them at one canvas

I’m looking for the crossing point.
Hope to could convey my mean

@couet // Because I’m new user , i can not share more image.:persevere:
The txt file is something like this :
Untitled

I could draw two plot at one canvas and i share it in the next post.

Can you send the ROOT commands you used to produce this plot ? I guess you wrote a macro…

1 Like

@couet // This is something that i draw :

I’m looking for the coordinate of red circular.

This is my root code : ( ofc just root part )

TApplication app("app", &argc, argv);

TCanvas *Canv1 = new TCanvas("Canv1", "Energy Spectrum");
TH1D *Charge = new TH1D("Charge", "Charge Histogram", 500, 0.0, 10000000.0);
TCanvas *Canv2 = new TCanvas("Canv2", "Timing");
TH1I *RisingTime = new TH1I("RisingTime", "RisingTime Histogram", 1024, -1024, 1024);
TCanvas *Canv3 = new TCanvas("Canv3", "Signlas");
TCanvas *Canv4 = new TCanvas("Canv4", "CrossPoint");

 Charge->Fill(Q);
 RisingTime->Fill(0.9*RiseTime * 2);

TGraph *Plot1 = new TGraph("Output1.txt");
TGraph *Plot2 = new TGraph("Output2.txt");
TGraph *Plot3 = new TGraph("Output3.txt");

Canv1->cd();
Charge->Draw();
		
Canv2->cd();
RisingTime->Draw();
		
Canv3->Divide(1, 2);

Canv3->cd(1);
Plot1->Draw();

Canv3->cd(2);
Plot2->Draw();
		
Canv4->cd();
Plot2->Draw();
Plot1->Draw("Same");

Canv1->Update();
Canv2->Update();
Canv3->Update();
Canv4->Update();

In addition i dont know what do u mean by saying “macro”.

may be you can try this:
https://root.cern.ch/doc/master/namespaceROOT_1_1VecOps.html#a2e903e9bed20c05d7a70afb393355643

1 Like

@couet // Thanks, But could not grasp and applied it in my c++ code . :disappointed_relieved:

should i use plot1_intersect_plot2 ?

can you send me the two file Output1.txt Output2.txt ?

1 Like

@couet // Ofcourse, really thanks. I use ROOT through Visual studio.

Forgive me to taking your time, as i said first, i’m beginner.

Output1.txt (999.3 KB)
Output2.txt (1.1 MB)

some idea:

void intersect() {
   auto Plot1 = new TGraph("Output1.txt");
   auto Plot2 = new TGraph("Output2.txt");

   Plot2->Draw("AL");
   Plot1->Draw("L");

   double min = 33000;
   double max = 35000;
   double d   = 1.;
   double eps = 1.;

   for (double s=min; s<max; s=s+d) {
      if (TMath::Abs(Plot2->Eval(s)-Plot1->Eval(s)) < eps) {
         printf("Plot1 and Plot2 might intersect at (%g, %g)\n",s,Plot2->Eval(s));
      }
   }
}

the execution of this macro gives:

$ root intersect.C 
   ------------------------------------------------------------
  | Welcome to ROOT 6.17/01                  https://root.cern |
  |                               (c) 1995-2019, The ROOT Team |
  | Built for macosx64 on Apr 29 2019, 11:02:08                |
  | From heads/master@v6-16-00-rc1-1795-ga98d98cf5b            |
  | Try '.help', '.demo', '.license', '.credits', '.quit'/'.q' |
   ------------------------------------------------------------
root [0] 
Processing intersect.C...
Info in <TCanvas::MakeDefCanvas>:  created default TCanvas with name c1
Plot1 and Plot2 might intersect at (34284, 15)
Plot1 and Plot2 might intersect at (34285, 16)
root [1] 
1 Like

@couet // i encounter with this eror : :zipper_mouth_face:

did you execute the macro exactly as I did ? … it is not clear on your screen dump

1 Like

I copy all of thing u wrote here and i saved as “intersect.C” file in root/bin.
Then i drag it and open with root shortcut on my desktop .

Did i made a mistake ?

Seems program fall in and endless for loop, I dont know…

It says illegal number of point, Why ? how could u run it with no error ?

the two files Output1.txt and Output2.txt must both be in the folder where intersect.C is

1 Like

Indeed, I know. But it’s not the problem .:disappointed_relieved:

It seems your graphs have an invalid number of points… so the graph are not created properly… It might be that the txt files are not found… Can you send the beginning of the log ? … Just after .x intersect.C ?

1 Like

@couet // Omg, unbelievable…
You know, when i run ROOT and then command .x fileopen.c and in the next when root object browser opened and i choose intersect.c it work correctly !!!

in contrast, when i just drag intersect and put on root icon, its going to error !!! cant understand whats wrong. both way are the same.

Could the reason be this that i using old version of ROOT ?


  *******************************************
  *                                         *
  *        W E L C O M E  to  R O O T       *
  *                                         *
  *   Version   5.34/36      5 April 2016   *
  *                                         *
  *  You are welcome to visit our Web site  *
  *          http://root.cern.ch            *
  *                                         *
  *******************************************
ROOT 5.34/36 (v5-34-36@v5-34-36, Apr 05 2016, 10:25:45 on win32)
CINT/ROOT C/C++ Interpreter version 5.18.00, July 2, 2010
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0]

Look at your browser… the macro intersect.C and the two txt file are in the same directory. When you run “.x intersect.C” from the root prompt you must first cd to that directory before starting root.

1 Like

@couet // Thanks a lot for your guidance. I do anything u said but, i encounter with the same error as i showed before. At last i could not grasp whats wrong, however, The only way to run intersect.c here, is that open it with ROOT " filebrowser.C ".

Thank you anyway.