Re: [ROOT] TApplication not working properly

From: Vitaliy Ziskin (vziskin@mitlns.mit.edu)
Date: Tue Dec 18 2001 - 19:05:44 MET


Root Version   3.02/00 and I will include the code and makefile for those who
is interested in helping.

                                                Thanks,Vitaliy

Fons Rademakers wrote:

> Hi Vitaliy,
>
>   this is not enough information. Please provide example and
> info on ROOT version etc.
>
> -- Fons
>
> Vitaliy Ziskin wrote:
>
> >     Hi, Rooters.
> > I have a question about TApplication.  I have a following code
> >
> > int main(int argn, char **argv) {
> >   int i;
> >   TApplication theApp("QMA_plot", &argn,argv);
> > .................. and so on.
> >
> > However, my program seems to never go past the TApplication line and just
> > exits completely with out going to next lines of code, even without
> > theApp.Run() call.
> >
> > What am I doing wrong?
> >
> >                                                     Thanks, Vitaliy
> >
> >
> >
>
> --
> Org:    CERN, European Laboratory for Particle Physics.
> Mail:   1211 Geneve 23, Switzerland
> E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
> WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7679480

--
=====================================================================
Vitaliy Ziskin                                Tel: (617)253-9209
MIT 26-547                          http://www.lns.mit.edu/people/vziskin/
77 Massachusetts Ave
Cambridge, Ma
02139
======================================================================
        "For long you live and high you fly
         And smiles you'll give and tears you'll cry
         And all you touch and all you see
         Is all your life will ever be"--Pink Floyd




CPP = g++
LIBS = -lm
CPPFLAGS = -Wall -g -fno-rtti -fPIC -I$(ROOTSYS)/include

all: RFplot

RFplot: RFplot.o 
	g++  -Wall -g -o RFplot RFplot.o $(LIBS) -L$(ROOTSYS)/lib `root-config --glibs` -lm

RFplot.o: RFplot.cc 
	g++ -c RFplot.cc $(CPPFLAGS) 

clean: 
	rm -rf *~ core RFplot *.o





#include <math.h>  
#include <iostream.h> 
#include <string.h>

#include "TROOT.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TPad.h"
#include "TFrame.h"
#include "TSystem.h"  
#include "TGraph.h"
#include "TGraphErrors.h"
#include "TH1.h"
#include "TF1.h"
#include "TText.h"
#include "TMarker.h"
#include "TLine.h"

extern void InitGui();
VoidFuncPtr_t initfuncs[] = { InitGui, 0 };

TROOT root("QMA_signal_analysis","QMA signal analysis", initfuncs);

typedef struct { 
  float m1[20];           //mass 1
  float d_m1[20];         //error in mass 1
  float m2[20];           // mass 2
  float d_m2[20];         // error in mass 2
} Mass;

typedef struct { 
  float power[20];           //rf power
  float d_power[20];         //error in power 
} RF;

typedef struct{
  float slope;
  float d_slope;             // liner graph characteristics
  float y0;
  float d_y0;
}Graph;

typedef struct {
  float mass1low;
  float mass1high;            // limits for nice graphs
  float mass2low;
  float mass2high;
} Masslimit;

void usage(void){
    printf("Usage: RFplot [flags] [scan file name(s)]\n ");
    printf("flags:\n"); 
    printf(" -s = single rf scan file analysis. Plot everything \n"); 
    printf(" -t = multiple scan files analysis. Plot only degree of dissociation \n"); 
    printf(" -st = multiple scan files analysis. Plot everything. \n");
}  

float makeMax(float max) {
  float c,f;
  
  max *= 1.2;
  if (max !=0.){  
  f = pow(10,(int)(log10(fabs(max))));
  c = max / f;
  }
  else 
    return max;

  return c*f;
}

float makeMin(float max) {
  float c,f;
  
  max *= 0.8;
  if (max !=0.){  
  f = pow(10,(int)(log10(fabs(max))));
  c = max / f;
  }
  else 
    return max;

  return c*f;
}

Mass NormMass(int nlines,Mass mass,Graph *graph,
	     Masslimit masslimit,char *option="nodraw")
{ 
  Mass mass_mod;
  int i;
  //  TGraphErrors *gr2_1 = new TGraphErrors(nlines,mass.m2,mass.m1,
  //					 mass.d_m2,mass.d_m1);
 TGraphErrors *gr2_1 = new TGraphErrors(nlines,mass.m2,mass.m1,
					 NULL,mass.d_m1);
  if (strcmp(option,"draw")==0){
    gr2_1->SetTitle(" m1 signal vs  m2 signal ");
    gr2_1->SetFillColor(19);
    gr2_1->SetLineColor(1);
    gr2_1->SetMarkerColor(50);
    gr2_1->SetMarkerStyle(21);
    gr2_1->SetMarkerSize(1.1);
    gr2_1->Draw("P");
    gr2_1->GetYaxis()->SetTitle("mass 1 (mV)");
    gr2_1->GetXaxis()->SetTitle("mass 2 (mV)");
  }
  TF1 *f1 = new TF1("f1","pol1",makeMin(masslimit.mass2low),
		    makeMax(masslimit.mass2high));
  gr2_1->Fit("f1","R");
  graph->slope = f1->GetParameter(1); 
  graph->d_slope= f1->GetParError(1);  
  graph->y0 = f1->GetParameter(0);
  graph->d_y0 = f1->GetParError(0);
//------------------------------------------------------------
  for (i=0; i<nlines; i++){
    mass_mod.m1[i]   = mass.m1[i]/graph->y0;  
    mass_mod.d_m1[i] = fabs(mass_mod.m1[i]*
			    sqrt(pow(mass.d_m1[i]/mass.m1[i],2)
				 +pow(graph->d_y0/graph->y0,2)));
    mass_mod.m2[i] = mass.m2[i]/graph->y0*fabs(graph->slope);     
    mass_mod.d_m2[i] = fabs(mass_mod.m2[i]*
			    sqrt(pow(mass.d_m2[i]/mass.m2[i],2)
				 +pow(graph->d_y0/graph->y0,2)
				 +pow(graph->d_slope/graph->slope,2)));
  }
//----------------------------------------------------------------
  return(mass_mod);
}

void PlotSingle(char *argv,char *option="nodraw"){
  printf("inside PlotSingle \n");
  FILE *fp = fopen(argv,"r");  //open scan file
  Mass mass,mass_mod;
  RF rf;
  Graph graph;
  Masslimit masslimit;
  float temp_noz,temp_sum,temp_ave,flow,phase,r,d_r,rf_in,rf_ref;
  int ncols, nlines,massbit,i;
  char s[50];

     nlines=0;
     masslimit.mass1low=100.;
     masslimit.mass1high=0.;
     masslimit.mass2low=100.;
     masslimit.mass2high=0.;
     temp_sum=0.;
   while((ncols = fscanf(fp,"%d %f %f %f %f %f %f %f" ,&massbit,&flow,&rf_in,
			 &rf_ref, &temp_noz,&r,&phase,&d_r)) != EOF){
     temp_sum += temp_noz;
     switch (massbit){
     case 0:
       mass.m1[nlines/2]=r*1000;
       mass.d_m1[nlines/2] = d_r*1000/sqrt(30);
       rf.power[nlines/2] = rf_in-rf_ref;
       if(r*1000 <= masslimit.mass1low)masslimit.mass1low=r*1000;
       if(r*1000 >= masslimit.mass1high)masslimit.mass1high=r*1000;    /* determining limits */
       break;
     case 1:
       mass.m2[nlines/2]=r*1000;
       mass.d_m2[nlines/2] = d_r*1000/sqrt(30);
       rf.power[nlines/2] = (rf.power[nlines/2]+rf_in-rf_ref)/2;
       if(r*1000 <= masslimit.mass2low)masslimit.mass2low=r*1000;
       if(r*1000 >= masslimit.mass2high)masslimit.mass2high=r*1000;    /* determining limits */
       break;
     }
     nlines++;
   }
   temp_ave = temp_sum/nlines;
   nlines=nlines/2;
/*---------------------------------------------------------
   This ends a neccesary part for the calculations and starts a nice
   plotting part. Except for the NormMass call.  
--------------------------------------------------------------------*/
   
   TCanvas *c1 = new TCanvas("QMA_Power","QMA studies out of the Dissociator"
			     ,10,10,1000,800);
   
   c1->Range(0,0,25,18);
   c1->SetFillColor(40);
     
   TText *t = new TText();
   TMarker *marker = new TMarker(20,2.8,21);
   TLine *line = new TLine (0,1,1,0); 
   
   TPad *pad1 = new TPad("pad1","This is pad1",0.05,0.55,0.45,0.95,30);
   TPad *pad2 = new TPad("pad2","This is pad2",0.55,0.55,0.95,0.95,30);
   TPad *pad3 = new TPad("pad3","This is pad3",0.05,0.05,0.45,0.45,30);
   TPad *pad4 = new TPad("pad4","This is pad4",0.55,0.05,0.95,0.45,30);
   
   if (strcmp(option,"draw")==0){
     t->SetTextFont(32);
     t->SetTextColor(1);
     t->SetTextSize(0.03);
     t->SetTextAlign(12);
     t->DrawText(2.1,17.5,"QMA chopped signal vs RF power");
     t->DrawText(14.,17.5,"QMA m1 signal vs. m2 signal ");
     t->DrawText(2.1,8.5,"QMA m1 signal vs. m2 signal (normalized)");
     t->DrawText(14.,8.5,"QMA m1 signal (normalized) vs. RF power");
     t->DrawText(1.1,0.5,"H. Kolster, V. Ziskin, E. Ihloff, C. Crowford");
     t->DrawText(21.1,0.5,"December, 2001");    
     
     pad1->Draw();
     pad2->Draw();
     pad3->Draw();
     pad4->Draw();
     
     pad1->cd();
     pad1->Range(-0.255174,-19.25,2.29657,-6.75);
     
     pad1->DrawFrame(0,makeMin(masslimit.mass1low),200,makeMax(masslimit.mass2high));
     pad1->GetFrame()->SetFillColor(19);
   
     marker->SetMarkerColor(kBlue);
     marker-> Draw();

     t->SetTextFont(62);
     t->SetTextColor(kBlue);
     t->SetTextSize(0.07);
     t->SetTextAlign(12);
     t->DrawText(30,2.85,"mass 1");

     marker->SetMarkerColor(kRed);
     marker-> Draw();

     t->SetTextFont(62);
     t->SetTextColor(kRed);
     t->SetTextSize(0.07);
     t->SetTextAlign(12);
     t->DrawText(30,2.25,"mass 2");

     TGraphErrors *gr1_1 = new TGraphErrors(nlines,rf.power,
					   mass.m1,NULL,mass.d_m1);
     gr1_1->SetTitle(" QMA signal vs  RF power");
     gr1_1->SetFillColor(19);
     gr1_1->SetLineColor(1);
     gr1_1->SetMarkerColor(kBlue);
     gr1_1->SetMarkerStyle(21);
     gr1_1->SetMarkerSize(1.1);
     gr1_1->Draw("LP");
     gr1_1->GetYaxis()->SetTitle("Phase Lock signal (mV)");
     gr1_1->GetXaxis()->SetTitle("RF power (Watts)");
//
     TGraphErrors *gr1_2 = new TGraphErrors(nlines,rf.power,
					   mass.m2,NULL,mass.d_m2);
     gr1_2->SetTitle(" QMA signal vs  RF power");
     gr1_2->SetFillColor(19);
     gr1_2->SetLineColor(1);
     gr1_2->SetMarkerColor(50);
     gr1_2->SetMarkerStyle(29);
     gr1_2->SetMarkerSize(1.5);
     gr1_2->Draw("LP");
   
//----------------------------------------------------------------
     pad2->cd();
     pad2->Range(-0.255174,-19.25,2.29657,-6.75);

     pad2->DrawFrame(makeMin(masslimit.mass2low),
		     makeMin(masslimit.mass1low),
		     makeMax(masslimit.mass2high),
		     makeMax(masslimit.mass1high));
     pad2->GetFrame()->SetFillColor(19);
   }
     
   mass_mod = NormMass(nlines,mass,&graph,masslimit,option);
   
   if (strcmp(option,"draw")==0){
     
     t->SetTextFont(62);
     t->SetTextColor(1);
     t->SetTextSize(0.05);
     t->SetTextAlign(12);
     sprintf(s,"slope = %.4f +/- %.4f",graph.slope,graph.d_slope);
     t->DrawText(masslimit.mass2high*0.85,masslimit.mass1high,s);
     sprintf(s,"y0 = %.4f +/- %.4f",graph.y0,graph.d_y0);
     t->DrawText(masslimit.mass2high*0.85,masslimit.mass1high*0.9,s);

     pad3->cd();
     pad3->Range(-0.255174,-19.25,2.29657,-6.75);
     
     pad3->DrawFrame(0,0.,1.1,1.1);
     pad3->GetFrame()->SetFillColor(19);
     for (i=0;i<nlines;i++){
     }
     TGraphErrors *gr3_1 = new TGraphErrors(nlines,mass_mod.m2,mass_mod.m1,
					   mass_mod.d_m2,mass_mod.d_m1);
     gr3_1->SetTitle(" m1 signal vs  m2 signal ");
     gr3_1->SetFillColor(19);
     gr3_1->SetLineColor(1);
     gr3_1->SetMarkerColor(50);
     gr3_1->SetMarkerStyle(21);
     gr3_1->SetMarkerSize(1.1);
     gr3_1->Draw("P");
     gr3_1->GetYaxis()->SetTitle("mass 1 ");
     gr3_1->GetXaxis()->SetTitle("mass 2 ");

     line->Draw();

     t->SetTextFont(122);
     t->SetTextColor(1);
     t->SetTextSize(0.08);
     t->SetTextAlign(12);
     sprintf(s,"= %.4f +/- %.4f",graph.slope/(-1.0*sqrt(2)),
	     graph.d_slope/sqrt(2));
     t->DrawText(0.2,1.0,"k");
     t->DrawText(0.25,1.0,s);
//----------------------------------------------------------------
     pad4->cd();
     pad4->Range(-0.255174,-19.25,2.29657,-6.75);
     
     pad4->DrawFrame(0,0.,200,0.7);
     pad4->GetFrame()->SetFillColor(19);
     TGraphErrors *gr4_1 = new TGraphErrors(nlines,rf.power,
					   mass_mod.m1,NULL,mass_mod.d_m1);
     gr4_1->SetTitle(" m1 (normalized) signal vs  rf ");
     gr4_1->SetFillColor(19);
     gr4_1->SetLineColor(1);
     gr4_1->SetMarkerColor(kBlue);
     gr4_1->SetMarkerStyle(21);
     gr4_1->SetMarkerSize(1.1);
     gr4_1->Draw("LP");
     t->SetTextFont(62);
     t->SetTextColor(1);
     t->SetTextSize(0.08);
     t->SetTextAlign(12);
     sprintf(s,"flow = %.2f sccm",flow);
     t->DrawText(80,0.55,s);
     sprintf(s,"temperature = %.2f K",temp_ave);
     t->DrawText(60,0.50,s);
     gr4_1->GetXaxis()->SetTitle("RF power (Watts)");
     gr4_1->GetYaxis()->SetTitle("mass 1");

   }
}
void PlotMult(char *argv){

  FILE *fp = fopen(argv,"r");  //open scan file

  Mass mass,mass_mod;
  RF rf;
  Graph graph;
  Masslimit masslimit;
  float temp_noz,temp_sum,temp_ave,flow,phase,r,d_r,rf_in,rf_ref;
  int ncols, nlines,massbit;
  char s[50];

  nlines=0;
  masslimit.mass1low=100.;
  masslimit.mass1high=0.;
  masslimit.mass2low=100.;
  masslimit.mass2high=0.;
  temp_sum = 0.;
 
   while((ncols = fscanf(fp,"%d %f %f %f %f %f %f %f" ,&massbit,&flow,&rf_in,
			 &rf_ref, &temp_noz,&r,&phase,&d_r)) != EOF){
     temp_sum += temp_sum;
     switch (massbit){
     case 0:
       mass.m1[nlines/2]=r*1000;
       mass.d_m1[nlines/2] = d_r*1000/sqrt(30);
       rf.power[nlines/2] = rf_in;
       if(r*1000 <= masslimit.mass1low)masslimit.mass1low=r*1000;
       if(r*1000 >= masslimit.mass1high)masslimit.mass1high=r*1000;    /* determining limits */
       case 1:
       mass.m2[nlines/2]=r*1000;
       mass.d_m2[nlines/2] = d_r*1000/sqrt(30);
       rf.power[nlines/2] = (rf.power[nlines/2]+rf_in)/2;
       if(r*1000 <= masslimit.mass2low)masslimit.mass2low=r*1000;
       if(r*1000 >= masslimit.mass2high)masslimit.mass2high=r*1000;    /* determining limits */
     }
   }
   temp_ave = temp_sum/nlines;
   nlines=nlines/2;
   mass_mod = NormMass(nlines,mass,&graph,masslimit,"nodraw");
     
   TGraphErrors *gr4_1 = new TGraphErrors(nlines,rf.power,mass_mod.m1,
					  NULL,mass_mod.d_m1); 
   TText *t = new TText();

   gr4_1->SetTitle(" \alpha vs  rf ");
   gr4_1->SetFillColor(19);
   gr4_1->SetLineColor(1);
   gr4_1->SetMarkerColor(kBlue);
   gr4_1->SetMarkerStyle(21);
   gr4_1->SetMarkerSize(1.1);
   gr4_1->Draw("LP,same");
   gr4_1->GetYaxis()->SetTitle("\alpha");
   gr4_1->GetXaxis()->SetTitle(" RF power (Watts)");
   sprintf(s,"flow = %.2f sccm",flow);
   t->DrawText(80,0.45,s);
   sprintf(s,"temperature = %.2f K",temp_ave);
   t->DrawText(80,0.40,s);
}
int main(int argn, char **argv) {
  int i;
  TApplication *theApp = new TApplication("QMA_plot", &argn, argv);
      //      theApp.Run();
  if (argn==1) {
    usage();
    exit(1);
  }
  if(strlen(argv[1])>3 ||( strchr(argv[1],'s')==NULL && 
			   strchr(argv[1],'t')==NULL)){
    usage();
    exit(1);
  }
  
  for (i=2;i<argn;i++){  //cycle over files
    if(strchr(argv[1],'s')!=NULL && strchr(argv[1],'t')!=NULL){ 
      PlotSingle(argv[i],"draw");
      TCanvas *alpha = new TCanvas("Alpha",
				   "Fraction of dissociation from dissociator",
				  10,40,1000,800);
      alpha->Draw();
      //      PlotMult(argv[i]);
      //theApp.Run();
    }
    else if(strchr(argv[1],'s')!=NULL){
      printf("%s\n",argv[1]);
      PlotSingle(argv[i],"draw");
      printf("i = %d \n", i);
      printf("=======================================================\n");
      printf("Type [Enter] to exit \n");
      while(getchar()!='\n'){ }; 
    }
    else if(strchr(argv[1],'t')!=NULL){	
      TCanvas *alpha = new TCanvas("Alpha",
				   "Fraction of dissociation from dissociator",
				   10,40,1000,800);
      alpha->Draw();
      PlotMult(argv[i]);
    }
  }
}



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:12 MET