{
    // Setting plots range and style
    gStyle->SetOptStat(0.1);
    gStyle->SetMarkerSize(1);
    gStyle->SetMarkerStyle(20);
    gStyle->SetMarkerColor(0);

    // Setting plots range and style
    int i, unixtime_bin = 100;
    int temp_bin = 200, temp_min = 15, temp_max = 26;
    int p_bin = 200, p_min = 920, p_max = 980;
    int rh_bin = 200, rh_min = -5, rh_max = 65;
    int histo_bin = 200, histo_min = 0, histo_max = 10000;
    int volt_bin = 200, volt_min = 0, volt_max = 10;
    int current_bin = 200, current_min = 0, current_max = 1;
    
    // Text positioning
    Double_t x1=0.9,y1=0.6,x2=x1+0.09,y2=0.63;
    float label_font=0.025;
    float axis_offset=0.9;
    float time_bin=5;
    float label_size=0.03;

    // Defining variable already present in the dst file
    Char_t      Psupply[80];
    Int_t       unixtime;
    Char_t      Name[80];
    Int_t       Slot;
    Int_t       Channel;
    Int_t       tdc;
    Float_t     Volt; 
    Float_t     Current;
    Int_t       status;
    Float_t     env_t;
    Float_t     env_rh;
    Float_t     env_p;

    // Opening the DSTiles
    FILE *fp = fopen("FEB4_b.dat","r");
    
    TFile *hfile = 0;
    hfile = TFile::Open("904lab_plot.root","RECREATE");
    
    // Tree and Branch definitions
    TTree *rpclab = new TTree("904lab","904 RPC Lab - PLOTS");
    rpclab->Branch("Psupply",Psupply,"Psupply/C");
    rpclab->Branch("unixtime",&unixtime,"unixtime/I");    
    rpclab->Branch("Name",Name,"Name/C");
    rpclab->Branch("Slot",&Slot,"Slot/I");
    rpclab->Branch("Channel",&Channel,"Channel/I");
    rpclab->Branch("Volt",&Volt,"Volt/F");
    rpclab->Branch("Current",&Current,"Current/F");
    rpclab->Branch("status",&status,"status/I");
    rpclab->Branch("tdc",&tdc,"tdc/I");
    rpclab->Branch("env_t",&env_t,"env_t/F");
    rpclab->Branch("env_rh",&env_rh,"env_rh/F");
    rpclab->Branch("env_p",&env_p,"env_p/F");

    // Scanning the dst file and filling the Tree
    while (!feof(fp))
    {
        i = i + 1;
        fscanf(fp,"%s %d %s %d %d %f %f",Psupply, &unixtime, Name, &Slot, &Channel, &Volt, &Current);
        fscanf(fp,"%d %f %f %f %f\n",&status, &tdc, &env_t, &env_rh, &env_p);
        rpclab->Fill();
        if (i==1) start=unixtime;
        finish = unixtime;
    }
    fclose(fp);
    rpclab->Write();

    //rpclab->Draw("current:unixtime","","");
    
    
    //Environmental Temperature and Pressure
    TCanvas *FramexTandP = new TCanvas("FramexTandP","T & P",0,0,1500,900);//creating Canvas
    TPad *pad1 = new TPad("pad1","",0,0,1,1); //1st pad for T
    TPad *pad2 = new TPad("pad2","",0,0,1,1); //2nd pad for P
    pad2->SetFillStyle(4000); //will be transparent
    pad1->Draw();
    pad1->cd();
    
    TH2F *sens1 = new  TH2F("sens1","sens1",unixtime_bin,start,finish,temp_bin,temp_min,temp_max);  
    sens1->SetMarkerColor(1);
    sens1->SetMarkerStyle(20);
    sens1->SetMarkerSize(0.7);
	sens1->SetTitle("904lab System Environmental T and P");
    sens1->GetXaxis()->SetTitleOffset(axis_offset);
    sens1->GetXaxis()->SetTimeDisplay(1); 
    sens1->GetXaxis()->SetTimeFormat("%Y %m %d %H:%M %F 1970-01-01 00:00:00"); 
    sens1->GetXaxis()->SetNdivisions(time_bin); 
    sens1->GetXaxis()->SetLabelSize(label_size);
    sens1->GetXaxis()->SetTitle("time");
    sens1->GetYaxis()->SetTitleOffset(axis_offset);
    sens1->GetYaxis()->SetLabelSize(label_size);
    sens1->GetYaxis()->SetTitle("Temperature [°C]");
    sens1->GetYaxis()->SetTitleSize(0.03);
	gPad->SetGrid();
	
	TH2F *environ3 = new TH2F("environ3","environ3",unixtime_bin,start,finish,p_bin,p_min,p_max);
    environ3->SetMarkerColor(860);
    environ3->SetMarkerStyle(20);
    environ3->SetMarkerSize(0.7);
    
	rpclab->Draw("env_t:unixtime>>sens1","");
    sens1->Draw("");
    
	pad1->Update();
	pad1->Modified();
    FramexTandP->cd();
	
	//compute the pad range with suitable margins
    Double_t ymin = p_min;
    Double_t ymax = p_max;
    Double_t dy = (ymax-ymin)/0.8; //% margins top and bottom
    Double_t xmin = start;
    Double_t xmax = finish;
    Double_t dx = (xmax-xmin)/0.8; //% margins left and right
    pad2->Range(xmin-0.1*dx,ymin-0.1*dy,xmax+0.1*dx,ymax+0.1*dy);
    pad2->Draw();
    pad2->cd();
	
	rpclab->Draw("env_p:unixtime>>environ3","","same");
    environ3->Draw("][sames");
    pad2->Update();
    
    // draw axis on the right side of the pad
    TGaxis *axis = new TGaxis(xmax,ymin,xmax,ymax,ymin,ymax,50510,"+L");
    axis->SetLabelColor(860);
	axis->SetLineColor(860);
    axis->SetTitleOffset(axis_offset);
    axis->SetLabelSize(label_size);
	axis->SetLabelColor(860);
	axis->SetTitle("Pressure [mbar]");
	axis->SetTitleSize(0.03);
	axis->SetTitleColor(860);
	axis->Draw();
	
	x1=0.9,y1=0.17,x2=x1+0.095,y2=y1+0.035;
    TLegend *leg1=new TLegend(x1,y1,x2,y2);
    leg1->AddEntry(sens1,"T [°C]","p");
    leg1->SetTextColor(0);
    leg1->SetFillColor(1);
    leg1->SetTextSize(0.025);
    leg1->Draw();
    y2=y2-0.04;
    y1=y1-0.04;
    
    TLegend *leg2=new TLegend(x1,y1,x2,y2);
    leg2->AddEntry(sens1,"P [mbar]","p");
    leg2->SetTextColor(0);
    leg2->SetFillColor(860);
    leg2->SetTextSize(0.025);
    leg2->Draw();
    
    
    
    
    // PERFORMANCES
    TCanvas *Frameperf = new TCanvas("Frameperf","Current and Voltages",0,0,1500,900);//creating Canvas
    TPad *pad1 = new TPad("pad1","",0,0,1,1); //1st pad for T
    TPad *pad2 = new TPad("pad2","",0,0,1,1); //2nd pad for P
    pad2->SetFillStyle(4000); //will be transparent
    pad1->Draw();
    pad1->cd();
    
    TH2F *sens1 = new  TH2F("sens1","sens1",unixtime_bin,start,finish,current_bin,current_min,current_max);  
    sens1->SetMarkerColor(1);
    sens1->SetMarkerStyle(20);
    sens1->SetMarkerSize(0.7);
	sens1->SetTitle("904lab System performances");
    sens1->GetXaxis()->SetTitleOffset(axis_offset);
    sens1->GetXaxis()->SetTimeDisplay(1); 
    sens1->GetXaxis()->SetTimeFormat("%Y %m %d %H:%M %F 1970-01-01 00:00:00"); 
    sens1->GetXaxis()->SetNdivisions(time_bin); 
    sens1->GetXaxis()->SetLabelSize(label_size);
    sens1->GetXaxis()->SetTitle("time");
    sens1->GetYaxis()->SetTitleOffset(axis_offset);
    sens1->GetYaxis()->SetLabelSize(label_size);
    sens1->GetYaxis()->SetTitle("Current [uA]");
    sens1->GetYaxis()->SetTitleSize(0.03);
	gPad->SetGrid();
	
	TH2F *environ3 = new TH2F("environ3","environ3",unixtime_bin,start,finish,volt_bin,volt_min,volt_max);
    environ3->SetMarkerColor(2);
    environ3->SetMarkerStyle(20);
    environ3->SetMarkerSize(0.7);
    
	rpclab->Draw("Current:unixtime>>sens1","");
    sens1->Draw("");
    
	pad1->Update();
	pad1->Modified();
    Frameperf->cd();
	
	//compute the pad range with suitable margins
    Double_t ymin = volt_min;
    Double_t ymax = volt_max;
    Double_t dy = (ymax-ymin)/0.8; //% margins top and bottom
    Double_t xmin = start;
    Double_t xmax = finish;
    Double_t dx = (xmax-xmin)/0.8; //% margins left and right
    pad2->Range(xmin-0.1*dx,ymin-0.1*dy,xmax+0.1*dx,ymax+0.1*dy);
    pad2->Draw();
    pad2->cd();
	
	rpclab->Draw("Volt:unixtime>>environ3","","same");
    environ3->Draw("][sames");
    pad2->Update();
    
    
    // draw axis on the right side of the pad
    TGaxis *axis = new TGaxis(xmax,ymin,xmax,ymax,ymin,ymax,50510,"+L");
    axis->SetLabelColor(2);
	axis->SetLineColor(2);
    axis->SetTitleOffset(axis_offset);
    axis->SetLabelSize(label_size);
	axis->SetLabelColor(2);
	axis->SetTitle("Volt [V]");
	axis->SetTitleSize(0.03);
	axis->SetTitleColor(2);
	axis->Draw();
	
	x1=0.9,y1=0.17,x2=x1+0.095,y2=y1+0.035;
    TLegend *leg1=new TLegend(x1,y1,x2,y2);
    leg1->AddEntry(sens1,"Current [uA]","p");
    leg1->SetTextColor(1);
    leg1->SetFillColor(0);
    leg1->SetTextSize(0.020);
    leg1->Draw();
    y2=y2-0.04;
    y1=y1-0.04;
    
    TLegend *leg2=new TLegend(x1,y1,x2,y2);
    leg2->AddEntry(sens1,"Volt [V]","p");
    leg2->SetTextColor(2);
    leg2->SetFillColor(0);
    leg2->SetTextSize(0.020);
    leg2->Draw();
    
    //Writing histo into ROOT file
}