]> jspc29.x-matter.uni-frankfurt.de Git - radhard.git/commitdiff
newCOMBI: cleaned up ChargeSpektrum.c code
authorBenjamin Linnik <blinnik@jspc28.x-matter.uni-frankfurt.de>
Fri, 13 Dec 2013 21:49:54 +0000 (22:49 +0100)
committerBenjamin Linnik <blinnik@jspc28.x-matter.uni-frankfurt.de>
Fri, 13 Dec 2013 21:49:54 +0000 (22:49 +0100)
newCOMBI/ChargeSpektrum.c

index 001eba4d97c25d2784d8ba92ebce472ea44efda4..2abfe7c8ace7fc7d210812e0acb2a472fffd4de9 100755 (executable)
@@ -76,6 +76,8 @@ struct laborbook LaborBuch(Int_t inputRun);
 struct laborbook LaborBuchSQL(Int_t inputRun);
 Int_t* ReadRunList(Int_t* numberRuns);
 struct noise Noise(Int_t inputRun);
+Int_t GetMaxBin(TString system);
+
 void ChargeSpektrum()
 {
     
@@ -92,10 +94,10 @@ void ChargeSpektrum()
         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);
+    TCanvas * c1 = new TCanvas("c", "Seed spectra", w, h);
     c1->SetWindowSize(w + (w - c1->GetWw()), h + (h - c1->GetWh()));
     
     arrayHisto[0].Seed->Draw("");
@@ -104,71 +106,77 @@ void ChargeSpektrum()
         arrayHisto[lauf].Seed->Draw("same");
     }
     
-    TString ergebnisfile="ergebnisfile.dat";
+    TString ergebnisfile= "ergebnisfile.dat";
+    TString header;
+    TString outline;
     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);
+        header ="Start\t";
+        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();
+        
+    for(Int_t lauf=0;lauf<numberRuns;lauf++)
+    {   
+      ergebnisfile = TString(DATAPATH) + Form("%i_analyzeresult.dat", arrayHisto[lauf].inputRun);
+      fout->open(ergebnisfile,ios::out);
+      
+      header ="runnumber\trad source\tmatrix\ttemp cooling\ttemp chip\trad dose\tpos. seed\tpos. sum\tpos. veto\tquantiles\n";
+      outline=header+Form("%i", arrayHisto[lauf].inputRun)+"\t"+arrayHisto[lauf].laborbookdata.source+"\t"+arrayHisto[lauf].laborbookdata.matrix+"\t"+Form("%.2f",arrayHisto[lauf].laborbookdata.temp)+"\t"+Form("%.2f",arrayHisto[lauf].laborbookdata.tempSens)+"\t"+arrayHisto[lauf].laborbookdata.radDose+"\t"+Form("%.2f", arrayHisto[lauf].posSeed)+"\t"+Form("%.2f", arrayHisto[lauf].posSum)+"\t"+Form("%.2f", arrayHisto[lauf].posVeto)+"\t"+Form("%.2f", noiseHisto[lauf].quantiles);
+      
+      *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;
-     */
+    *    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=LaborBuchSQL(inputRun);
-//     cout<<"TEST2 Run:"<<laborbookdata.inputRun<<endl;  
-    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);
+    
+    Int_t maxBin = GetMaxBin(laborbookdata.system);
+  
+    TH1F* histNtuple = new TH1F(Form("Inhist%i",inputRun),  Form("Seed spectrum %i",inputRun), 200, 0, maxBin);
+    TH1F* histNtupleSum=new TH1F(Form("InhistSum%i",inputRun), "Sum over cluster", 200, 0, maxBin);
+    TH1F* histNtupleVeto=new TH1F(Form("InhistVeto%i",inputRun), "Veto spectrum", 200, 0, maxBin);
     // open the file
     TString path = TString(DATAPATH) + Form("%i_0.root", inputRun);
     TFile* f = TFile::Open(path);
@@ -178,46 +186,22 @@ struct histogram GenerateHisto(Int_t inputRun)
         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);
-
+      // get a pointer to the tree
       TTree* hitNtuple = (TTree*) f->Get("hit");
       
       UInt_t frame;
       UInt_t hits;
       UInt_t seedPixel[10000];
-      Float_t pixel[25][10000];
+      Float_t pixel[NUMPIXELS][10000];
       
-      
       hitNtuple->SetBranchAddress ("frame"              , &frame);
       hitNtuple->SetBranchAddress ("hits"              , &hits);
       hitNtuple->SetBranchAddress ("pixel"              , seedPixel        );
 //       hitNtuple->SetBranchAddress ( "p13" , pixel );
       
-    
-
-      for(int i=0;i<25;i++)   { hitNtuple->SetBranchAddress( Form("p%i",i+1) , &pixel[i][0] ); }
+      // fill ttree with pixel branchs fields
+      for(int i=0;i<NUMPIXELS;i++)   { hitNtuple->SetBranchAddress( Form("p%i",i+1) , &pixel[i][0] ); }
     
     //       fHitTree        = new TTree("hit", "hit");
     
@@ -225,26 +209,19 @@ struct histogram GenerateHisto(Int_t inputRun)
     //       fHitTree->SetBranchAddress("hits"     , &fFrameInfo.hits  );
     //       fHitTree->SetBranchAddress("pixel"    , &fFrameInfo.pixel[0]  );
     
-    
     // loop over all hits to fill histogram
     Int_t nentries = hitNtuple->GetEntries();
-//     cout<<"TEST4 Run:"<<laborbookdata.inputRun<<endl;  
-    int tempsamirvar = laborbookdata.inputRun;
-//     cout<<"nentries:"<<nentries<<endl;  
-    for (Int_t cnt=0; cnt<nentries; cnt++) 
+    for (Int_t cnt=0; cnt<nentries; cnt++) // loop over all frames
     {   
-        hitNtuple->GetEntry(cnt);
-        
-//         cout << cnt << " " << laborbookdata.inputRun << " " << tempsamirvar << " " ;
-//         cout<<frame<<" "<<hits<<" "<<endl;
+        hitNtuple->GetEntry(cnt); // get 
         
+        // take only frames with less then 10 hits
         if (hits<10)
         {
           for(unsigned int i=0; i<hits;i++)
           {
 //             cout<<" ---> "<<i<<" "<<seedPixel[i]<<" "<<pixel[12][i]<<endl;
           
-
           // take only frames with a maximum of one hit
           // hitsNtuple->GetEntry((Int_t) frame);
           // if (frameCounts > 1)
@@ -255,29 +232,30 @@ struct histogram GenerateHisto(Int_t inputRun)
           histNtuple->Fill(pixel[12][i]);
           
           // histogram with the summed pixels
-//           Double_t pixelSum = 0;
-//           for (Int_t i=0; i<NUMPIXELS; i++)
-//           {
-//               pixelSum += pixel[12][i];
-//           }
-//           histNtupleSum->Fill(pixelSum);
+          Float_t pixelSum = 0;
+          for (Int_t j=0; j<NUMPIXELS; j++)
+          {
+              pixelSum += pixel[j][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
-          }}
+//           histogram with the single pixel and with "veto trigger"
+//           for the "histNtupleVeto" take only hits where only the seed pixel contains charge
+          Float_t notSeedSum = 0;
+          for (Int_t j=0; j<12; j++)
+              notSeedSum += pixel[j][i];
+          for (Int_t j=13; j<NUMPIXELS; j++)
+              notSeedSum += pixel[j][i];
+          if (TMath::Abs(notSeedSum) > VETO_THRESHOLD)
+              continue;
+//           meanNotSeedSum+=notSeedSum;
+//           nhits++;
+          histNtupleVeto->Fill(pixel[12][i]);    // histogram with the single pixel
+          }          
+        }
     }
     TCanvas* c1 = new TCanvas();
-    c1->SetTitle(Form("Seed%i",inputRun));
+    c1->SetTitle(Form("Spectra %i",inputRun));
     c1->Divide(2,2);
     c1->cd(1);
     histNtuple->Draw("");
@@ -310,6 +288,7 @@ struct histogram GenerateHisto(Int_t inputRun)
     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->SetTitle("All spectra");
     histNtupleSame->Draw("");
     histNtupleSame->SetMaximum(1.05*maxY);
     histNtupleSumSame->Draw("same");
@@ -317,7 +296,6 @@ struct histogram GenerateHisto(Int_t inputRun)
     histNtupleSumSame->SetLineColor(1);
     histNtupleVetoSame->SetLineColor(2);
     
-   
     
     struct histogram arrayHisto;
     arrayHisto.Seed=(TH1F*)histNtuple->Clone(Form("hist%i",inputRun));
@@ -328,7 +306,7 @@ struct histogram GenerateHisto(Int_t inputRun)
     arrayHisto.posSum=posSum;
     arrayHisto.posVeto=posVeto;
 //     cout<<"TEST1"<<endl;
-   
+  
     arrayHisto.laborbookdata=laborbookdata;
 //     cout<<"TEST2"<<endl;
     return arrayHisto;
@@ -341,17 +319,8 @@ Float_t FitPerform(TH1F* histNtuple, Int_t inputRun)
     struct laborbook laborbookdata;
     laborbookdata=LaborBuchSQL(inputRun);
     
-    Int_t maxBin;
+    Int_t maxBin = GetMaxBin(laborbookdata.system);
     
-    if(laborbookdata.system=="USB") 
-    {
-        maxBin=800;
-    }
-    else
-    {
-        maxBin=8000;
-        
-    }
     histNtuple->Draw("");
     if (DRAW_FITS) 
     {
@@ -384,37 +353,51 @@ Float_t FitPerform(TH1F* histNtuple, Int_t inputRun)
             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();
+            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;
 }
+
+
+Int_t GetMaxBin(TString system)
+{
+  if(system=="USB") 
+  {
+    return 800;
+  }
+  else
+  {
+    return 8000;
+  }
+}
+
 struct noise Noise(Int_t inputRun)
 {
     // Read Laborbook, save it in the struct laborbookdata
@@ -509,7 +492,7 @@ struct laborbook LaborBuch(Int_t inputRun)
         }
     }
     
-//     cout<<"Run:"<<inputRun<<" System:"<<system<<" Chip:"<<chip<<" Temp:"<<temperature<<" TempSensor:"<<tempSens<<" Source:"<<source<<" RadDose:"<<radDose<<endl;  
+//     cout<<"Run:.q"<<inputRun<<" System:"<<system<<" Chip:"<<chip<<" Temp:"<<temperature<<" TempSensor:"<<tempSens<<" Source:"<<source<<" RadDose:"<<radDose<<endl;  
     
     struct laborbook laborbookdata;
     laborbookdata.inputRun= inputRun;
@@ -526,8 +509,8 @@ struct laborbook LaborBuch(Int_t inputRun)
 struct laborbook LaborBuchSQL(Int_t inputRun)
 {
     std::string   system;
-    Float_t   temperature;    // desired temperature
-    Float_t   tempSens;   // actual temperature
+    Float_t   temperature = -10000;    // desired temperature
+    Float_t   tempSens = -10000;   // actual temperature
     std::string   chip;       // chip number (eg. 1-6)
     std::string   source;
     std::string   matrix;
@@ -570,7 +553,7 @@ struct laborbook LaborBuchSQL(Int_t inputRun)
         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 << "matrix: " << matrix <<endl;  
+//          cout<<"Run:"<<inputRun<<" System:"<<system<<" Chip:"<<chip<<" Temp:"<<temperature<<" TempSensor:"<<tempSens<<" Source:"<<source<<" RadDose:"<<radDose << "matrix: " << matrix <<endl;  
 
     struct laborbook laborbookdata;
     laborbookdata.inputRun= inputRun;
@@ -621,4 +604,4 @@ Int_t* ReadRunList(Int_t* numberRuns)
     }
     *numberRuns=runLauf;
     return runList;
-}
\ No newline at end of file
+}