]> jspc29.x-matter.uni-frankfurt.de Git - radhard.git/commitdiff
newCOMBI: added SQL labbook support, CSV support is commented out, but still preserved
authorBenjamin Linnik <blinnik@jspc28.x-matter.uni-frankfurt.de>
Tue, 12 Nov 2013 16:43:32 +0000 (17:43 +0100)
committerBenjamin Linnik <blinnik@jspc28.x-matter.uni-frankfurt.de>
Tue, 12 Nov 2013 16:43:32 +0000 (17:43 +0100)
newCOMBI/ChargeSpektrum.c

index e5c4b1c90c5e1ecd9a04fabfff0f0fa0a3ff27c9..e214027f463abd721cc5ee0dbb1b9ec885686fc7 100755 (executable)
@@ -3,9 +3,15 @@
 #include <vector>
 #include <string>
 #include <stdlib.h>
+
+// mySQL Anbindung
+#include <TSQLServer.h>
+#include <TSQLResult.h>
+#include <TSQLRow.h>
+
 #include "CSVRow.h"
 //#ifdef __CINT__
-#include "CSVRow.C"    // bad C-style... but root wants it this way... no correct separation of declaration and implementation possible.
+#include "CSVRow.C" // bad C-style... but root wants it this way... no correct separation of declaration and implementation possible.
 
 #include "TFile.h"
 #include "TTree.h"
@@ -29,7 +35,7 @@
 
 
 #define NUMPIXELS 25
-#define VETO_THRESHOLD 20
+#define VETO_THRESHOLD 10
 
 #define FIT_FUNC "gaus"
 #define DRAW_FITS true
 #define DATAPATH "/d/salt/data_recovered/maps/DennisDoering/root/Analysedata/"
 struct laborbook
 {
- Int_t inputRun;
- TString system;
- Float_t temp;
- Float_t tempSens;
- TString chip;
- TString source;
- TString matrix;
- TString radDose;
   Int_t inputRun;
   TString system;
   Float_t temp;
   Float_t tempSens;
   TString chip;
   TString source;
   TString matrix;
   TString radDose;
 };
 struct histogram
 {
- TH1F* Seed;
- TH1F* Sum;
- TH1F* Veto;
- Int_t inputRun;
- Float_t posSeed;
- Float_t posSum;
- Float_t posVeto;
- struct laborbook laborbookdata;
   TH1F* Seed;
   TH1F* Sum;
   TH1F* Veto;
   Int_t inputRun;
   Float_t posSeed;
   Float_t posSum;
   Float_t posVeto;
   struct laborbook laborbookdata;
 };
 struct noise
 {
- TH1F* noiseHisto;
- Int_t inputRun;
- Double_t quantiles;
- struct laborbook laborbookdata;
   TH1F* noiseHisto;
   Int_t inputRun;
   Double_t quantiles;
   struct laborbook laborbookdata;
 };
 struct histogram GenerateHisto(Int_t inputRun);
 Float_t FitPerform(TH1F*, Int_t);
 struct laborbook LaborBuch(Int_t inputRun);
+struct laborbook LaborBuchSQL(Int_t inputRun);
 Int_t* ReadRunList(Int_t* numberRuns);
 struct noise Noise(Int_t inputRun);
 void ChargeSpektrum()
 {
-         
-        Int_t numberRuns=0;
-               ReadRunList(&numberRuns);
-       Int_t* runList=new Int_t[numberRuns];
-       runList=ReadRunList(&numberRuns);
-       
-       struct histogram* arrayHisto = new struct histogram[numberRuns];
-       struct noise* noiseHisto = new struct noise[numberRuns];
-       for(Int_t lauf=0;lauf<numberRuns;lauf++)
-       {
-               noiseHisto[lauf]=Noise(runList[lauf]);
-               arrayHisto[lauf]=GenerateHisto(runList[lauf]);
-       }
-
-       Double_t w = 600;
+    
+    Int_t numberRuns=0;
+    ReadRunList(&numberRuns);
+    Int_t* runList=new Int_t[numberRuns];
+    runList=ReadRunList(&numberRuns);
+    
+    
+    struct histogram* arrayHisto = new struct histogram[numberRuns];
+    struct noise* noiseHisto = new struct noise[numberRuns];
+    for(Int_t lauf=0;lauf<numberRuns;lauf++)
+    {
+        noiseHisto[lauf]=Noise(runList[lauf]);
+        arrayHisto[lauf]=GenerateHisto(runList[lauf]);
+    }
+    
+    Double_t w = 600;
     Double_t h = 600;
     TCanvas * c1 = new TCanvas("c", "c", w, h);
     c1->SetWindowSize(w + (w - c1->GetWw()), h + (h - c1->GetWh()));
-
-       arrayHisto[0].Seed->Draw("");
-       for(Int_t lauf=1;lauf<numberRuns;lauf++)
-       {
-               arrayHisto[lauf].Seed->Draw("same");
-       }
-       
-       TString ergebnisfile="ergebnisfile.dat";
-       fstream* fout = new fstream(ergebnisfile,ios::out);
-       for(Int_t lauf=0;lauf<numberRuns;lauf++)
-       {       
-               TString header ="Start\t";
-           TString outline=header+Form("%i", arrayHisto[lauf].inputRun)+"\t"+arrayHisto[lauf].laborbookdata.source+"\t"+arrayHisto[lauf].laborbookdata.matrix+"\t"+Form("%.2f", arrayHisto[lauf].posSeed)+"\t"+Form("%.2f", arrayHisto[lauf].posSum)+"\t"+Form("%.2f", arrayHisto[lauf].posVeto)+"\t"+Form("%.2f", noiseHisto[lauf].quantiles);
-
-               cout<<outline<<endl;
-               *fout<<outline<<endl;
-       }
-       fout->close();
-
-/*
-cout<<runList[0]<<":"<<runList[1]<<endl;
-Int_t inputRun=34009;
- //Int_t inputRun=341270;
- struct histogram arrayHisto;
- arrayHisto=GenerateHisto(inputRun);
-  inputRun=341270;
- struct histogram arrayHisto2;
- arrayHisto2=GenerateHisto(inputRun);
-         Double_t w = 600;
-      Double_t h = 600;
-      TCanvas * c1 = new TCanvas("c", "c", w, h);
-      c1->SetWindowSize(w + (w - c1->GetWw()), h + (h - c1->GetWh()));
-
- arrayHisto.Seed->Draw("");
-  double xmin = arrayHisto.Seed->GetXaxis()->GetXmin();
-double xmax = arrayHisto.Seed->GetXaxis()->GetXmax();
-double factor = 1640./406.;
-arrayHisto.Seed->GetXaxis()->SetLimits(xmin*factor,xmax*factor);
- arrayHisto2.Seed->Draw("same");
- double xmin2 = arrayHisto2.Seed->GetXaxis()->GetXmin();
-double xmax2 = arrayHisto2.Seed->GetXaxis()->GetXmax();
-//double factor = 1640./400.;
-double factor2 = 1640./6352.;
-arrayHisto2.Seed->GetXaxis()->SetLimits(xmin2*factor2,xmax2*factor2);
- //arrayHisto.Sum->Draw("same");
- //arrayHisto.Veto->Draw("same");
- cout<<arrayHisto.inputRun<<"\t"<<arrayHisto.posSeed<<"\t"<<arrayHisto.posSum<<"\t"<<arrayHisto.posVeto<<endl;
- cout<<arrayHisto2.inputRun<<"\t"<<arrayHisto2.posSeed<<"\t"<<arrayHisto2.posSum<<"\t"<<arrayHisto2.posVeto<<endl;
- */
+    
+    arrayHisto[0].Seed->Draw("");
+    for(Int_t lauf=1;lauf<numberRuns;lauf++)
+    {
+        arrayHisto[lauf].Seed->Draw("same");
+    }
+    
+    TString ergebnisfile="ergebnisfile.dat";
+    fstream* fout = new fstream(ergebnisfile,ios::out);
+    for(Int_t lauf=0;lauf<numberRuns;lauf++)
+    {   
+        TString header ="Start\t";
+        TString outline=header+Form("%i", arrayHisto[lauf].inputRun)+"\t"+arrayHisto[lauf].laborbookdata.source+"\t"+arrayHisto[lauf].laborbookdata.matrix+"\t"+Form("%.2f", arrayHisto[lauf].posSeed)+"\t"+Form("%.2f", arrayHisto[lauf].posSum)+"\t"+Form("%.2f", arrayHisto[lauf].posVeto)+"\t"+Form("%.2f", noiseHisto[lauf].quantiles);
+        
+        cout << outline << endl;
+        *fout<<outline<<endl;
+    }
+    fout->close();
+    
+    /*
+     *    c *out<<runList[0]<<":"<<runList[1]<<endl;
+     *    Int_t inputRun=34009;
    *    //Int_t inputRun=341270;
    *    struct histogram arrayHisto;
    *    arrayHisto=GenerateHisto(inputRun);
+     *    inputRun=341270;
    *    struct histogram arrayHisto2;
    *    arrayHisto2=GenerateHisto(inputRun);
+     *    Double_t w = 600;
+     *    Double_t h = 600;
+     *    TCanvas * c1 = new TCanvas("c", "c", w, h);
+     *    c1->SetWindowSize(w + (w - c1->GetWw()), h + (h - c1->GetWh()));
+     *    
    *    arrayHisto.Seed->Draw("");
+     *    double xmin = arrayHisto.Seed->GetXaxis()->GetXmin();
+     *    double xmax = arrayHisto.Seed->GetXaxis()->GetXmax();
+     *    double factor = 1640./406.;
+     *    arrayHisto.Seed->GetXaxis()->SetLimits(xmin*factor,xmax*factor);
    *    arrayHisto2.Seed->Draw("same");
    *    double xmin2 = arrayHisto2.Seed->GetXaxis()->GetXmin();
+     *    double xmax2 = arrayHisto2.Seed->GetXaxis()->GetXmax();
+     *    //double factor = 1640./400.;
+     *    double factor2 = 1640./6352.;
+     *    arrayHisto2.Seed->GetXaxis()->SetLimits(xmin2*factor2,xmax2*factor2);
    *    //arrayHisto.Sum->Draw("same");
    *    //arrayHisto.Veto->Draw("same");
    *    cout<<arrayHisto.inputRun<<"\t"<<arrayHisto.posSeed<<"\t"<<arrayHisto.posSum<<"\t"<<arrayHisto.posVeto<<endl;
    *    cout<<arrayHisto2.inputRun<<"\t"<<arrayHisto2.posSeed<<"\t"<<arrayHisto2.posSum<<"\t"<<arrayHisto2.posVeto<<endl;
    */
 }
 
 struct histogram GenerateHisto(Int_t inputRun)
 {
-
-       cout<<inputRun<<endl;
-       
-       // Read Laborbook, save it in the struct laborbookdata
-       struct laborbook laborbookdata;
-       laborbookdata=LaborBuch(inputRun);
-       
-       Int_t maxBin;
-       if(laborbookdata.system=="USB") 
-       {
-               maxBin=800;
-       }
-       else
-       {
-               maxBin=8000;
-       }
-       
-  TH1F*        histNtuple = new TH1F(Form("Inhist%i",inputRun), "Histogram title", 200, 0, maxBin);
-  TH1F*        histNtupleSum=new TH1F(Form("InhistSum%i",inputRun), "Histogram title", 200, 0, maxBin);
-  TH1F*        histNtupleVeto=new TH1F(Form("InhistVeto%i",inputRun), "Histogram title", 200, 0, maxBin);
-         // open the file
-         TString path = TString(DATAPATH) + Form("%i_0.root", inputRun);
-         TFile* f = TFile::Open(path);
-         if (f->IsZombie()) 
-         {
-           // if we cannot open the file, print an error messageForm("hist%i",nHistNtuple) and return immediatly
-           printf("Error: cannot open %s\n", path.Data());
-           exit(0);
-         }
-         
-         // get a pointer to the tree
-         TNtuple* hitNtuple = (TNtuple*) f->Get("hit");
-         //TNtuple* hitsNtuple = (TNtuple*) f->Get("hits");
-         
-         // one array element and one branch for each pixel
-         Float_t pixel[NUMPIXELS];
-         TBranch* pixelBranch[NUMPIXELS];
-         for (Int_t cnt=0; cnt<NUMPIXELS; cnt++) 
-         {
-           hitNtuple->SetBranchAddress(Form("p%i",cnt+1), &pixel[cnt], &pixelBranch[cnt]);
-         }
-        UInt_t frame;
-         TBranch* frameBranch;
-         hitNtuple->SetBranchAddress("frame", &frame, &frameBranch);
-        UInt_t seedPixel;
-         TBranch* seedPixelBranch;
-         hitNtuple->SetBranchAddress("pixel", &seedPixel, &seedPixelBranch);
-         
-         // loop over all hits to fill histogram
-         Int_t nentries = hitNtuple->GetEntries();
-       
-         for (Int_t cnt=0; cnt<nentries; cnt++) 
-         {
-           hitNtuple->GetEntry(cnt);
-           
-           // take only frames with a maximum of one hit
-           // hitsNtuple->GetEntry((Int_t) frame);
-           // if (frameCounts > 1)
-             // continue;
-           
-           
-           // histogram with the single pixel
-           histNtuple->Fill(pixel[12]);
-           
-           // histogram with the summed pixels
-           Double_t pixelSum = 0;
-           for (Int_t i=0; i<NUMPIXELS; i++)
-               {
-             pixelSum += pixel[i];
-           }
-           histNtupleSum->Fill(pixelSum);
-           
-           // histogram with the single pixel and with "veto trigger"
-           // for the "histNtupleVeto" take only hits where only the seed pixel contains charge
-           Double_t notSeedSum = 0;
-           for (Int_t i=0; i<12; i++)
-             notSeedSum += pixel[i];
-           for (Int_t i=13; i<NUMPIXELS; i++)
-             notSeedSum += pixel[i];
-           if (TMath::Abs(notSeedSum) > VETO_THRESHOLD)
-             continue;
-           // meanNotSeedSum+=notSeedSum;
-           // nhits++;
-           histNtupleVeto->Fill(pixel[12]);    // histogram with the single pixel
-           
-         }
-         TCanvas* c1 = new TCanvas();
-         c1->SetTitle(Form("Seed%i",inputRun));
-         c1->Divide(2,2);
-         c1->cd(1);
-         histNtuple->Draw("");
-         Float_t posSeed=FitPerform(histNtuple, inputRun);
-         c1->cd(2);
-         histNtupleSum->Draw("");
-         Float_t posSum=FitPerform(histNtupleSum, inputRun);
-         c1->cd(3);
-         histNtupleVeto->Draw("");
-         Float_t posVeto=FitPerform(histNtupleVeto, inputRun);
-         c1->cd(4);
-         //Evaluate the histogram with the largest y to plot all complete in one histogram
-          Float_t maxY = 0;
-          Int_t thismax;
-          thismax = histNtuple->GetMaximum();
-          if (thismax > maxY)
-          {
-               maxY = thismax;
-          }
-          thismax = histNtupleSum->GetMaximum();
-          if (thismax > maxY)
-          {
-               maxY = thismax;
-          }
-          thismax = histNtupleVeto->GetMaximum();
-          if (thismax > maxY)
-          {
-               maxY = thismax;
-          }
-         TH1F* histNtupleSame= (TH1F*)histNtuple->Clone(Form("Samehist%i",inputRun));
-         TH1F* histNtupleSumSame= (TH1F*)histNtupleSum->Clone(Form("SamehistSum%i",inputRun));
-         TH1F* histNtupleVetoSame= (TH1F*)histNtupleVeto->Clone(Form("SamehistVeto%i",inputRun));
-         histNtupleSame->Draw("");
-         histNtupleSame->SetMaximum(1.05*maxY);
-         histNtupleSumSame->Draw("same");
-         histNtupleVetoSame->Draw("same");
-         histNtupleSumSame->SetLineColor(1);
-         histNtupleVetoSame->SetLineColor(2);
-         
-         
-         
-         struct histogram arrayHisto;
-         arrayHisto.Seed=(TH1F*)histNtuple->Clone(Form("hist%i",inputRun));
-         arrayHisto.Sum=(TH1F*)histNtupleSum->Clone(Form("histSum%i",inputRun));
-         arrayHisto.Veto=(TH1F*)histNtupleVeto->Clone(Form("histVeto%i",inputRun));
-         arrayHisto.inputRun=inputRun;
-         arrayHisto.posSeed=posSeed;
-         arrayHisto.posSum=posSum;
-         arrayHisto.posVeto=posVeto;
-         arrayHisto.laborbookdata=laborbookdata;
-return arrayHisto;
+    
+    cout<<inputRun<<endl;
+    
+    // Read Laborbook, save it in the struct laborbookdata
+    struct laborbook laborbookdata;
+    laborbookdata=LaborBuchSQL(inputRun);
+    
+    Int_t maxBin;
+    if(laborbookdata.system=="USB") 
+    {
+        maxBin=800;
+    }
+    else
+    {
+        maxBin=8000;
+    }
+    TH1F* histNtuple = new TH1F(Form("Inhist%i",inputRun),  Form("Runnumber: %i",inputRun), 200, 0, maxBin);
+    TH1F* histNtupleSum=new TH1F(Form("InhistSum%i",inputRun), "Histogram title", 200, 0, maxBin);
+    TH1F* histNtupleVeto=new TH1F(Form("InhistVeto%i",inputRun), "Histogram title", 200, 0, maxBin);
+    // open the file
+    TString path = TString(DATAPATH) + Form("%i_0.root", inputRun);
+    TFile* f = TFile::Open(path);
+    if (f->IsZombie()) 
+    {
+        // if we cannot open the file, print an error messageForm("hist%i",nHistNtuple) and return immediatly
+        printf("Error: cannot open %s\n", path.Data());
+        exit(0);
+    }
+    
+    // get a pointer to the tree
+    TNtuple* hitNtuple = (TNtuple*) f->Get("hit");
+    //TNtuple* hitsNtuple = (TNtuple*) f->Get("hits");
+    
+    // one array element and one branch for each pixel
+    Float_t pixel[NUMPIXELS];
+    TBranch* pixelBranch[NUMPIXELS];
+    for (Int_t cnt=0; cnt<NUMPIXELS; cnt++) 
+    {
+        hitNtuple->SetBranchAddress(Form("p%i",cnt+1), &pixel[cnt], &pixelBranch[cnt]);
+    }
+    UInt_t frame;
+    TBranch* frameBranch;
+    hitNtuple->SetBranchAddress("frame", &frame, &frameBranch);
+    UInt_t seedPixel;
+    TBranch* seedPixelBranch;
+    hitNtuple->SetBranchAddress("pixel", &seedPixel, &seedPixelBranch);
+    
+    // loop over all hits to fill histogram
+    Int_t nentries = hitNtuple->GetEntries();
+    
+    for (Int_t cnt=0; cnt<nentries; cnt++) 
+    {
+        hitNtuple->GetEntry(cnt);
+        
+        // take only frames with a maximum of one hit
+        // hitsNtuple->GetEntry((Int_t) frame);
+        // if (frameCounts > 1)
+        // continue;
+        
+        
+        // histogram with the single pixel
+        histNtuple->Fill(pixel[12]);
+        
+        // histogram with the summed pixels
+        Double_t pixelSum = 0;
+        for (Int_t i=0; i<NUMPIXELS; i++)
+        {
+            pixelSum += pixel[i];
+        }
+        histNtupleSum->Fill(pixelSum);
+        
+        // histogram with the single pixel and with "veto trigger"
+        // for the "histNtupleVeto" take only hits where only the seed pixel contains charge
+        Double_t notSeedSum = 0;
+        for (Int_t i=0; i<12; i++)
+            notSeedSum += pixel[i];
+        for (Int_t i=13; i<NUMPIXELS; i++)
+            notSeedSum += pixel[i];
+        if (TMath::Abs(notSeedSum) > VETO_THRESHOLD)
+            continue;
+        // meanNotSeedSum+=notSeedSum;
+        // nhits++;
+        histNtupleVeto->Fill(pixel[12]);    // histogram with the single pixel
+        
+    }
+    TCanvas* c1 = new TCanvas();
+    c1->SetTitle(Form("Seed%i",inputRun));
+    c1->Divide(2,2);
+    c1->cd(1);
+    histNtuple->Draw("");
+    Float_t posSeed=FitPerform(histNtuple, inputRun);
+    c1->cd(2);
+    histNtupleSum->Draw("");
+    Float_t posSum=FitPerform(histNtupleSum, inputRun);
+    c1->cd(3);
+    histNtupleVeto->Draw("");
+    Float_t posVeto=FitPerform(histNtupleVeto, inputRun);
+    c1->cd(4);
+    //Evaluate the histogram with the largest y to plot all complete in one histogram
+    Float_t maxY = 0;
+    Int_t thismax;
+    thismax = histNtuple->GetMaximum();
+    if (thismax > maxY)
+    {
+        maxY = thismax;
+    }
+    thismax = histNtupleSum->GetMaximum();
+    if (thismax > maxY)
+    {
+        maxY = thismax;
+    }
+    thismax = histNtupleVeto->GetMaximum();
+    if (thismax > maxY)
+    {
+        maxY = thismax;
+    }
+    TH1F* histNtupleSame= (TH1F*)histNtuple->Clone(Form("Samehist%i",inputRun));
+    TH1F* histNtupleSumSame= (TH1F*)histNtupleSum->Clone(Form("SamehistSum%i",inputRun));
+    TH1F* histNtupleVetoSame= (TH1F*)histNtupleVeto->Clone(Form("SamehistVeto%i",inputRun));
+    histNtupleSame->Draw("");
+    histNtupleSame->SetMaximum(1.05*maxY);
+    histNtupleSumSame->Draw("same");
+    histNtupleVetoSame->Draw("same");
+    histNtupleSumSame->SetLineColor(1);
+    histNtupleVetoSame->SetLineColor(2);
+    
+    
+    
+    struct histogram arrayHisto;
+    arrayHisto.Seed=(TH1F*)histNtuple->Clone(Form("hist%i",inputRun));
+    arrayHisto.Sum=(TH1F*)histNtupleSum->Clone(Form("histSum%i",inputRun));
+    arrayHisto.Veto=(TH1F*)histNtupleVeto->Clone(Form("histVeto%i",inputRun));
+    arrayHisto.inputRun=inputRun;
+    arrayHisto.posSeed=posSeed;
+    arrayHisto.posSum=posSum;
+    arrayHisto.posVeto=posVeto;
+    arrayHisto.laborbookdata=laborbookdata;
+    return arrayHisto;
 }
 
 Float_t FitPerform(TH1F* histNtuple, Int_t inputRun)
 {
-       Float_t posMax = 0;
-       // Read Laborbook, save it in the struct laborbookdata
-       struct laborbook laborbookdata;
-       laborbookdata=LaborBuch(inputRun);
-       
-       Int_t maxBin;
-       
-       if(laborbookdata.system=="USB") 
-       {
-               maxBin=800;
-               
-       }
-       else
-       {
-               maxBin=8000;
-               
-       }
-histNtuple->Draw("");
-if (DRAW_FITS) 
-       {
-       
-       histNtuple->GetXaxis()->SetRange(histNtuple->GetXaxis()->FindBin(maxBin/10),histNtuple->GetXaxis()->FindBin(maxBin));   // look only for maxima with x greater than 20
-       Int_t xValMax = histNtuple->GetBinCenter(histNtuple->GetMaximumBin());
-        TF1* fitFunc = new TF1("fitFunc",FIT_FUNC,0,maxBin);
-       if (TString(FIT_FUNC)=="gaus") 
-       {
-         histNtuple->Fit(fitFunc, "N,Q,W", "", xValMax-100, xValMax+100);
-         posMax = fitFunc->GetParameter(1);
-         fitFunc->DrawCopy("same");
-         TString  legendEntry = TString(Form("Run %i: %.1f ",inputRun,posMax));
-          TLegend* leg = new TLegend(0.5,0.5,0.89,0.89);//(0.6,0.7,0.89,0.89);
-//   leg->SetHeader();//"Legend Title");
-  leg->SetFillStyle(0);
-         leg->AddEntry((TObject*) 0, legendEntry, "");
-         leg->SetTextSize(0.05);
-         leg->Draw();
-         
-       }
-       else if (TString(FIT_FUNC)=="landau") 
-       {
-         Float_t fitMax1 = 1000;
-         Float_t fitMax2 = 1000;
-         Float_t fitMax3 = 1000;
-         Float_t minFitMax = 1000;
-         Float_t maxFitMax = 1000;
-         
-         histNtuple->Fit(fitFunc, "N,Q,W", "", 20, maxBin);
-         fitMax1 = fitFunc->GetParameter(1);
-         fitFunc->DrawCopy("same");
-         histNtuple->Fit(fitFunc, "N,Q,W", "", 20, fitMax1);
-         fitMax2 = fitFunc->GetParameter(1);
-         fitFunc->SetLineColor(kBlue);
-         fitFunc->SetLineStyle(2);     // dashed
-         fitFunc->DrawCopy("same");
-         histNtuple->Fit(fitFunc, "N,Q,W", "", fitMax1, maxBin);
-         fitMax3 = fitFunc->GetParameter(1);
-         fitFunc->SetLineColor(kGreen);
-         fitFunc->DrawCopy("same");
-         fitFunc->SetLineStyle(1);     // normal for the following fits
-         
-         // Sort the three fits and save error estimation
-         minFitMax = TMath::Min(TMath::Min(fitMax1,fitMax2),fitMax3);
-         maxFitMax = TMath::Max(TMath::Max(fitMax1,fitMax2),fitMax3);
-         posMax = fitMax1 + fitMax2 + fitMax3 - minFitMax - maxFitMax;
-         //fitLandauErrorLeft.push_back(posMax - minFitMax);
-         //fitLandauErrorRight.push_back(maxFitMax - posMax);
-         
-               TString  legendEntry = TString(Form("Run %i: %.1f %.1f  %.1f",inputRun,posMax,minFitMax,maxFitMax ));
-          TLegend* leg = new TLegend(0.5,0.5,0.89,0.89);//(0.6,0.7,0.89,0.89);
-//   leg->SetHeader();//"Legend Title");
-  leg->SetFillStyle(0);
-         leg->AddEntry((TObject*) 0, legendEntry, "");
-         leg->SetTextSize(0.05);
-         leg->Draw();
-         
-         }
-       }
-       
-return posMax;
+    Float_t posMax = 0;
+    // Read Laborbook, save it in the struct laborbookdata
+    struct laborbook laborbookdata;
+    laborbookdata=LaborBuchSQL(inputRun);
+    
+    Int_t maxBin;
+    
+    if(laborbookdata.system=="USB") 
+    {
+        maxBin=800;
+    }
+    else
+    {
+        maxBin=8000;
+        
+    }
+    histNtuple->Draw("");
+    if (DRAW_FITS) 
+    {
+        
+        histNtuple->GetXaxis()->SetRange(histNtuple->GetXaxis()->FindBin(maxBin/10),histNtuple->GetXaxis()->FindBin(maxBin));   // look only for maxima with x greater than 20
+        Int_t xValMax = histNtuple->GetBinCenter(histNtuple->GetMaximumBin());
+        TF1* fitFunc = new TF1("fitFunc",FIT_FUNC,0,maxBin);
+        if (TString(FIT_FUNC)=="gaus") 
+        {
+            histNtuple->Fit(fitFunc, "N,Q,W", "", xValMax-100, xValMax+100);
+            posMax = fitFunc->GetParameter(1);
+            fitFunc->DrawCopy("same");
+        TString  legendEntry = TString(Form("Run %i: %.1f ",inputRun,posMax));
+        TLegend* leg = new TLegend(0.5,0.5,0.89,0.89);//(0.6,0.7,0.89,0.89);
+        //   leg->SetHeader();//"Legend Title");
+        leg->SetFillStyle(0);
+        leg->AddEntry((TObject*) 0, legendEntry, "");
+        leg->SetTextSize(0.05);
+        leg->Draw();
+        
+        }
+        else if (TString(FIT_FUNC)=="landau") 
+        {
+            Float_t fitMax1 = 1000;
+            Float_t fitMax2 = 1000;
+            Float_t fitMax3 = 1000;
+            Float_t minFitMax = 1000;
+            Float_t maxFitMax = 1000;
+            
+            histNtuple->Fit(fitFunc, "N,Q,W", "", 20, maxBin);
+            fitMax1 = fitFunc->GetParameter(1);
+            fitFunc->DrawCopy("same");
+        histNtuple->Fit(fitFunc, "N,Q,W", "", 20, fitMax1);
+        fitMax2 = fitFunc->GetParameter(1);
+        fitFunc->SetLineColor(kBlue);
+        fitFunc->SetLineStyle(2); // dashed
+        fitFunc->DrawCopy("same");
+        histNtuple->Fit(fitFunc, "N,Q,W", "", fitMax1, maxBin);
+        fitMax3 = fitFunc->GetParameter(1);
+        fitFunc->SetLineColor(kGreen);
+        fitFunc->DrawCopy("same");
+        fitFunc->SetLineStyle(1); // normal for the following fits
+        
+        // Sort the three fits and save error estimation
+        minFitMax = TMath::Min(TMath::Min(fitMax1,fitMax2),fitMax3);
+        maxFitMax = TMath::Max(TMath::Max(fitMax1,fitMax2),fitMax3);
+        posMax = fitMax1 + fitMax2 + fitMax3 - minFitMax - maxFitMax;
+        //fitLandauErrorLeft.push_back(posMax - minFitMax);
+        //fitLandauErrorRight.push_back(maxFitMax - posMax);
+        
+        TString  legendEntry = TString(Form("Run %i: %.1f %.1f  %.1f",inputRun,posMax,minFitMax,maxFitMax ));
+        TLegend* leg = new TLegend(0.5,0.5,0.89,0.89);//(0.6,0.7,0.89,0.89);
+        //   leg->SetHeader();//"Legend Title");
+        leg->SetFillStyle(0);
+        leg->AddEntry((TObject*) 0, legendEntry, "");
+        leg->SetTextSize(0.05);
+        leg->Draw();
+        
+        }
+    }
+    
+    return posMax;
 }
 struct noise Noise(Int_t inputRun)
 {
-         // Read Laborbook, save it in the struct laborbookdata
-         struct laborbook laborbookdata;
-         laborbookdata=LaborBuch(inputRun);
-         TString path = TString(DATAPATH) + Form("%i_0.root", inputRun);
-         TFile* f = TFile::Open(path);
-         if (f->IsZombie()) 
-         {
-           // if we cannot open the file, print an error messageForm("hist%i",nHistNtuple) and return immediatly
-           printf("Error: cannot open %s\n", path.Data());
-           exit(0);
-         }
-         // get a pointer to the tree
-         TNtuple* noiseNtuple = (TNtuple*) f->Get("noise");
-         
-         Float_t noise;
-         TBranch* noiseBranch;
-         noiseNtuple->SetBranchAddress("noise", &noise, &noiseBranch);
-         // create histogram
-         TH1F* histNoise = new TH1F(Form("Noise%i",inputRun), "Noise title", 100, 0, 10);
-         
-         Int_t nentries_N = noiseNtuple->GetEntries();
-         for (Int_t cnt=0; cnt<nentries_N; cnt++) {
-           noiseNtuple->GetEntry(cnt);
-           histNoise->Fill(noise);
-         }
-         
-         // get median and error estimation
-         Double_t const probabilities[] = {0.3415/2, 0.5, 1-0.3415/2}; // sigma/2 from gaus to the left and to the right //{0.17, 0.5, 1-0.17};
-         Double_t quantiles[3];
-         histNoise->GetQuantiles( 3, quantiles, probabilities);
-       //  noiseLowest17percent.push_back((Float_t) quantiles[0]);     // left error bar (lowest 17% noise values are below this quantile)
-       //  noiseMedian.push_back((Float_t) quantiles[1]);              // median of the noise distribution
-       //  noiseHighest17percent.push_back((Float_t) quantiles[2]);    // right error bar (highest 17% noise values are higher than this quantile)
-         cout << "q1: " << quantiles[1] - quantiles[0] << "\tq2: " << quantiles[1] << "\tq3: " << quantiles[2] - quantiles[1] << endl;
-         
-         
-          TCanvas* cNoise = new TCanvas();
-          cNoise->SetTitle(Form("Noise%i",inputRun));
-          histNoise->Draw();
-          TString  legendEntry = TString(Form("Run %i: %.3f %.3f  %.3f",inputRun,quantiles[1],quantiles[1] - quantiles[0],quantiles[2] - quantiles[1] ));
-          TLegend* leg = new TLegend(0.5,0.5,0.89,0.89);//(0.6,0.7,0.89,0.89);
-       leg->SetFillStyle(0);
-          leg->AddEntry((TObject*) 0, legendEntry, "");
-          leg->SetTextSize(0.03);
-          leg->Draw();
-         struct noise noiseHisto;
-         noiseHisto.noiseHisto=(TH1F*)histNoise->Clone(Form("NoiseX%i",inputRun));
-         noiseHisto.inputRun=inputRun;
-         noiseHisto.quantiles=quantiles[1];
-         noiseHisto.laborbookdata=laborbookdata;
-         //-------------------------------------------------
-return noiseHisto;
+    // Read Laborbook, save it in the struct laborbookdata
+    struct laborbook laborbookdata;
+    laborbookdata=LaborBuchSQL(inputRun);
+    TString path = TString(DATAPATH) + Form("%i_0.root", inputRun);
+    TFile* f = TFile::Open(path);
+    if (f->IsZombie()) 
+    {
+        // if we cannot open the file, print an error messageForm("hist%i",nHistNtuple) and return immediatly
+        printf("Error: cannot open %s\n", path.Data());
+        exit(0);
+    }
+    // get a pointer to the tree
+    TNtuple* noiseNtuple = (TNtuple*) f->Get("noise");
+    
+    Float_t noise;
+    TBranch* noiseBranch;
+    noiseNtuple->SetBranchAddress("noise", &noise, &noiseBranch);
+    // create histogram
+    TH1F* histNoise = new TH1F(Form("Noise%i",inputRun), "Noise title", 100, 0, 10);
+    
+    Int_t nentries_N = noiseNtuple->GetEntries();
+    for (Int_t cnt=0; cnt<nentries_N; cnt++) {
+        noiseNtuple->GetEntry(cnt);
+        histNoise->Fill(noise);
+    }
+    
+    // get median and error estimation
+    Double_t const probabilities[] = {0.3415/2, 0.5, 1-0.3415/2}; // sigma/2 from gaus to the left and to the right //{0.17, 0.5, 1-0.17};
+    Double_t quantiles[3];
+    histNoise->GetQuantiles( 3, quantiles, probabilities);
+    //  noiseLowest17percent.push_back((Float_t) quantiles[0]); // left error bar (lowest 17% noise values are below this quantile)
+    //  noiseMedian.push_back((Float_t) quantiles[1]);      // median of the noise distribution
+    //  noiseHighest17percent.push_back((Float_t) quantiles[2]);    // right error bar (highest 17% noise values are higher than this quantile)
+    cout << "q1: " << quantiles[1] - quantiles[0] << "\tq2: " << quantiles[1] << "\tq3: " << quantiles[2] - quantiles[1] << endl;
+    
+    
+    TCanvas* cNoise = new TCanvas();
+    cNoise->SetTitle(Form("Noise%i",inputRun));
+    histNoise->Draw();
+    TString  legendEntry = TString(Form("Run %i: %.3f %.3f  %.3f",inputRun,quantiles[1],quantiles[1] - quantiles[0],quantiles[2] - quantiles[1] ));
+    TLegend* leg = new TLegend(0.5,0.5,0.89,0.89);//(0.6,0.7,0.89,0.89);
+    leg->SetFillStyle(0);
+    leg->AddEntry((TObject*) 0, legendEntry, "");
+    leg->SetTextSize(0.03);
+    leg->Draw();
+    struct noise noiseHisto;
+    noiseHisto.noiseHisto=(TH1F*)histNoise->Clone(Form("NoiseX%i",inputRun));
+    noiseHisto.inputRun=inputRun;
+    noiseHisto.quantiles=quantiles[1];
+    noiseHisto.laborbookdata=laborbookdata;
+    //-------------------------------------------------
+    return noiseHisto;
 }
 struct laborbook LaborBuch(Int_t inputRun)
 {
-  std::string  system;
-  Float_t      temperature;    // desired temperature
-  Float_t      tempSens;       // actual temperature
-  std::string          chip;           // chip number (eg. 1-6)
-  std::string  source;
-  std::string  matrix;
-  std::string  radDose;
-  
- std::ifstream file("LaborbuchMi34.txt");
-  CSVRow       row;
-  file >> row;
-   while (file >> row) 
-   {
+    std::string   system;
+    Float_t   temperature;    // desired temperature
+    Float_t   tempSens;   // actual temperature
+    std::string       chip;       // chip number (eg. 1-6)
+    std::string   source;
+    std::string   matrix;
+    std::string   radDose;
+    
+    std::ifstream  file("LaborbuchMi34.txt");
+    CSVRow    row;
+    file >> row;
+    while (file >> row) 
+    {
+        
+        try 
+        {
+            Int_t runLabor;
+            runLabor=atoi(row[COLRUNNO].c_str());
+            //cout<<runLabor<<endl;
+            if (runLabor == inputRun) 
+            {
+                
+                system = row[COLSYSTEM];
+                temperature = atof(row[COLTEMP].c_str());   // temperature
+                tempSens = atof(row[COLTEMPSENS].c_str());  // temperature
+                chip = row[COLCHIP];
+                source = row[COLSOURCE];
+                matrix = row[COLMATRIX];
+                radDose = row[COLRADDOSE];
+            }
+        }
+        catch(...)
+        {
+            cout << "Error while reading laboratory book (run number " << inputRun << ")!\n";
+        }
+    }
+    
+    cout<<"Run:"<<inputRun<<" System:"<<system<<" Chip:"<<chip<<" Temp:"<<temperature<<" TempSensor:"<<tempSens<<" Source:"<<source<<" RadDose:"<<radDose<<endl;  
+    
+    struct laborbook laborbookdata;
+    laborbookdata.inputRun= inputRun;
+    laborbookdata.system= system;
+    laborbookdata.temp= temperature;
+    laborbookdata.tempSens= tempSens;
+    laborbookdata.chip= chip;
+    laborbookdata.source= source;
+    laborbookdata.matrix= matrix;
+    laborbookdata.radDose= radDose;
+    return laborbookdata;
+}
+
+struct laborbook LaborBuchSQL(Int_t inputRun)
+{
+    std::string   system;
+    Float_t   temperature;    // desired temperature
+    Float_t   tempSens;   // actual temperature
+    std::string   chip;       // chip number (eg. 1-6)
+    std::string   source;
+    std::string   matrix;
+    std::string   radDose;
+    
+    
+    TSQLServer *db = TSQLServer::Connect("mysql://jspc29.x-matter.uni-frankfurt.de","radhard", "mimosa88");
+    
+    //     printf("Server info: %s\n", db->ServerInfo());
+    
+    TSQLRow *rowsql;
+    TSQLResult *res;
     
     try 
-       {
-       Int_t runLabor;
-       runLabor=atoi(row[COLRUNNO].c_str());
-       //cout<<runLabor<<endl;
-      if (runLabor == inputRun) 
-               {
-               
-                       system = row[COLSYSTEM];
-                       temperature = atof(row[COLTEMP].c_str());       // temperature
-                       tempSens = atof(row[COLTEMPSENS].c_str());      // temperature
-                       chip = row[COLCHIP];
-                       source = row[COLSOURCE];
-                       matrix = row[COLMATRIX];
-                       radDose = row[COLRADDOSE];
-               }
-       }
+    {
+        // query database and print results
+        char sqlquery[200];
+        sprintf(sqlquery, "select System,TempCooling,COALESCE(TempChipStart,-10000) as TempChipStart,COALESCE(TempChipEnd,-10000) as TempChipEnd,ChipNum,RadiationSource,Matrix,ChipRadiation from radhard.labbook WHERE runnumber=%d", inputRun);
+        res = db->Query(sqlquery);
+        
+        int nrows = res->GetRowCount();
+        //             printf("\nGot %d rows in result\n", nrows);
+        
+        if (nrows > 0)
+        {                
+            rowsql = res->Next();
+            
+            system = std::string(rowsql->GetField(0));
+            temperature = atof(rowsql->GetField(1));
+            tempSens = atof(rowsql->GetField(2));
+            chip = std::string(rowsql->GetField(4));
+            source = std::string(rowsql->GetField(5));
+            matrix = std::string(rowsql->GetField(6));
+            radDose = std::string(rowsql->GetField(7));
+            
+        }
+    }
     catch(...)
-       {
-      cout << "Error while reading laboratory book (run number " << inputRun << ")!\n";
+    {
+        cout << "Error while reading laboratory book (run number " << inputRun << ")!\n";
     }
-  }
-  
-       cout<<"Run:"<<inputRun<<" System:"<<system<<" Chip:"<<chip<<" Temp:"<<temperature<<" TempSensor:"<<tempSens<<" Source:"<<source<<" RadDose:"<<radDose<<endl;  
-    
-       struct laborbook laborbookdata;
-        laborbookdata.inputRun= inputRun;
-        laborbookdata.system= system;
-        laborbookdata.temp= temperature;
-        laborbookdata.tempSens= tempSens;
-        laborbookdata.chip= chip;
-        laborbookdata.source= source;
-        laborbookdata.matrix= matrix;
-        laborbookdata.radDose= radDose;
- return laborbookdata;
+    
+    //     cout<<"Run:"<<inputRun<<" System:"<<system<<" Chip:"<<chip<<" Temp:"<<temperature<<" TempSensor:"<<tempSens<<" Source:"<<source<<" RadDose:"<<radDose << "matrix: " << matrix <<endl;  
+    
+    struct laborbook laborbookdata;
+    laborbookdata.inputRun= inputRun;
+    laborbookdata.system= system;
+    laborbookdata.temp= temperature;
+    laborbookdata.tempSens= tempSens;
+    laborbookdata.chip= chip;
+    laborbookdata.source= source;
+    laborbookdata.matrix= matrix;
+    laborbookdata.radDose= radDose;
+    return laborbookdata;
 }
+
 Int_t* ReadRunList(Int_t* numberRuns)
 {
-       Int_t* runList=new Int_t[1000];
-       
-       std::ifstream   file("runlist.txt");
-         CSVRow        row;
-         Int_t runLauf=0;
-         while (file >> row) 
-   {
+    Int_t* runList=new Int_t[1000];
     
-    try 
-       {
-       
-       
-       
-       runList[runLauf]=atoi(row[0].c_str());
-       
-       runLauf++;
-       }
-    catch(...)
-       {
-      cout << "File ended";
+    std::ifstream   file("runlist.txt");
+    CSVRow    row;
+    Int_t runLauf=0;
+    while (file >> row) 
+    {
+        
+        try 
+        {
+            
+            
+            
+            runList[runLauf]=atoi(row[0].c_str());
+            
+            runLauf++;
+        }
+        catch(...)
+        {
+            cout << "File ended";
+        }
     }
-  }
-  *numberRuns=runLauf;
-       return runList;
+    *numberRuns=runLauf;
+    return runList;
 }
\ No newline at end of file