]> jspc29.x-matter.uni-frankfurt.de Git - radhard.git/commitdiff
Singlerun
authorDennis Doering <dennis@jspc31.x-matter.uni-frankfurt.de>
Wed, 18 Sep 2013 10:31:51 +0000 (12:31 +0200)
committerDennis Doering <dennis@jspc31.x-matter.uni-frankfurt.de>
Wed, 18 Sep 2013 10:31:51 +0000 (12:31 +0200)
newCOMBI/ChargeSpektrum.c [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 09d4c16..aafb0a9
@@ -3,7 +3,9 @@
 #include <vector>
 #include <string>
 #include <stdlib.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 "TFile.h"
 #include "TTree.h"
 #include "TF1.h"
 #include "TMath.h"
 
+#define COLRUNNO 4
+#define COLSYSTEM 0
+#define COLTEMP 5
+#define COLTEMPSENS 14
+#define COLCHIP 7
+#define COLSOURCE 11
+#define COLMATRIX 10
+#define COLRADDOSE 12
+
+
 #define NUMPIXELS 25
-#define RIGHT_BOUNDARY 7000
 #define VETO_THRESHOLD 20
 
 #define FIT_FUNC "gaus"
@@ -29,46 +40,78 @@ struct histogram
  TH1F* Seed;
  TH1F* Sum;
  TH1F* Veto;
- int zahl;
+ Int_t inputRun;
+ Float_t posSeed;
+ Float_t posSum;
+ Float_t posVeto;
+};
+struct laborbook
+{
+ Int_t inputRun;
+ TString system;
+ Float_t temp;
+ Float_t tempSens;
+ TString chip;
+ TString source;
+ TString matrix;
+ TString radDose;
 };
-
 struct histogram GenerateHisto(Int_t inputRun);
-void FitPerform(TH1F*, Int_t);
+Float_t FitPerform(TH1F*, Int_t);
+struct laborbook LaborBuch(Int_t inputRun);
 void ChargeSpektrum()
 {
- Int_t inputRun=34009;
+Int_t inputRun=34009;
  //Int_t inputRun=341270;
  struct histogram arrayHisto;
  arrayHisto=GenerateHisto(inputRun);
   inputRun=341270;
  struct histogram arrayHisto2;
  arrayHisto2=GenerateHisto(inputRun);
- TCanvas* c1 = new TCanvas();
+         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./400.;
+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./7000.;
+double factor2 = 1640./6352.;
 arrayHisto2.Seed->GetXaxis()->SetLimits(xmin2*factor2,xmax2*factor2);
  //arrayHisto.Sum->Draw("same");
  //arrayHisto.Veto->Draw("same");
- cout<<arrayHisto.zahl<<endl;
+ 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;
-
-  TH1F*        histNtuple = new TH1F(Form("hist%i",inputRun), "Histogram title", 200, 0, RIGHT_BOUNDARY);
-  TH1F*        histNtupleSum=new TH1F(Form("histSum%i",inputRun), "Histogram title", 200, 0, RIGHT_BOUNDARY);
-  TH1F*        histNtupleVeto=new TH1F(Form("histVeto%i",inputRun), "Histogram title", 200, 0, RIGHT_BOUNDARY);
+       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);
@@ -81,7 +124,7 @@ cout<<inputRun<<endl;
          
          // get a pointer to the tree
          TNtuple* hitNtuple = (TNtuple*) f->Get("hit");
-         TNtuple* hitsNtuple = (TNtuple*) f->Get("hits");
+         //TNtuple* hitsNtuple = (TNtuple*) f->Get("hits");
          
          // one array element and one branch for each pixel
          Float_t pixel[NUMPIXELS];
@@ -99,8 +142,6 @@ cout<<inputRun<<endl;
          
          // loop over all hits to fill histogram
          Int_t nentries = hitNtuple->GetEntries();
-         // Double_t meanNotSeedSum=0;
-         // Int_t nhits=0;
        
          for (Int_t cnt=0; cnt<nentries; cnt++) 
          {
@@ -137,28 +178,98 @@ cout<<inputRun<<endl;
            histNtupleVeto->Fill(pixel[12]);    // histogram with the single pixel
            
          }
-         FitPerform(histNtuple, inputRun);
+         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=histNtuple;
-         arrayHisto.Sum=histNtupleSum;
-         arrayHisto.Veto=histNtupleVeto;
-         arrayHisto.zahl=3;
+         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;
 return arrayHisto;}
 
-void FitPerform(TH1F* histNtuple, Int_t inputRun)
+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) 
        {
-       Float_t posMax = 0;
-       histNtuple->GetXaxis()->SetRange(histNtuple->GetXaxis()->FindBin(50),histNtuple->GetXaxis()->FindBin(RIGHT_BOUNDARY));  // look only for maxima with x greater than 20
+       
+       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,RIGHT_BOUNDARY);
+        TF1* fitFunc = new TF1("fitFunc",FIT_FUNC,0,maxBin);
        if (TString(FIT_FUNC)=="gaus") 
        {
-         histNtuple->Fit(fitFunc, "N,Q,W", "", xValMax-10, xValMax+10);
+         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") 
        {
@@ -168,7 +279,7 @@ if (DRAW_FITS)
          Float_t minFitMax = 1000;
          Float_t maxFitMax = 1000;
          
-         histNtuple->Fit(fitFunc, "N,Q,W", "", 20, RIGHT_BOUNDARY);
+         histNtuple->Fit(fitFunc, "N,Q,W", "", 20, maxBin);
          fitMax1 = fitFunc->GetParameter(1);
          fitFunc->DrawCopy("same");
          histNtuple->Fit(fitFunc, "N,Q,W", "", 20, fitMax1);
@@ -176,7 +287,7 @@ if (DRAW_FITS)
          fitFunc->SetLineColor(kBlue);
          fitFunc->SetLineStyle(2);     // dashed
          fitFunc->DrawCopy("same");
-         histNtuple->Fit(fitFunc, "N,Q,W", "", fitMax1, RIGHT_BOUNDARY);
+         histNtuple->Fit(fitFunc, "N,Q,W", "", fitMax1, maxBin);
          fitMax3 = fitFunc->GetParameter(1);
          fitFunc->SetLineColor(kGreen);
          fitFunc->DrawCopy("same");
@@ -194,8 +305,62 @@ if (DRAW_FITS)
 //   leg->SetHeader();//"Legend Title");
   leg->SetFillStyle(0);
          leg->AddEntry((TObject*) 0, legendEntry, "");
-         leg->SetTextSize(0.02);
+         leg->SetTextSize(0.05);
          leg->Draw();
+         
          }
        }
+       
+return posMax;
+}
+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("LaborbuchMi34Test.txt");
+  CSVRow       row;
+  file >> row;
+   while (file >> row) 
+   {
+    
+    try 
+       {
+       Int_t runLabor;
+       runLabor=atoi(row[COLRUNNO].c_str());
+       
+      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;
 }
\ No newline at end of file