]> jspc29.x-matter.uni-frankfurt.de Git - mdcoep.git/commitdiff
*** empty log message ***
authorhadeshyp <hadeshyp>
Thu, 6 Aug 2009 16:01:01 +0000 (16:01 +0000)
committerhadeshyp <hadeshyp>
Thu, 6 Aug 2009 16:01:01 +0000 (16:01 +0000)
root/NoiseTestMult.C [new file with mode: 0755]

diff --git a/root/NoiseTestMult.C b/root/NoiseTestMult.C
new file mode 100755 (executable)
index 0000000..99a45ce
--- /dev/null
@@ -0,0 +1,256 @@
+
+#include "TObjArray.h"
+#include "TH1F.h"
+#include "TH2F.h"
+#include "TStyle.h"
+#include "TString.h"
+#include "TCanvas.h"
+#include "TGraph.h"
+
+#include <iostream>
+using namespace std;
+
+#define BUF_SIZE 100
+#define GET_LINE(buf,file) if (fgets((buf),BUF_SIZE,(file)) == NULL) break
+
+Int_t readNoiseFile(TString input="",TObjArray* hists_boards=0,TObjArray* hists_channels=0,TObjArray* hists_times=0,Bool_t print = kFALSE)
+{
+    if(input.CompareTo("")==0){
+
+       cout<<"File name ist empty!"<<endl;
+       return 0;
+    }
+
+    FILE *fp;
+    fp = fopen(input.Data(), "r");
+
+    if (fp == NULL)     {
+        cout<<"Error opening file"<<endl;
+        return -1;
+    }
+
+
+    Char_t line[BUF_SIZE];
+
+    Int_t mb,thresh,datawords, all_datawords, dataword;
+    Int_t evtct = 0;
+    TString buffer="";
+    TString mbName="";
+    TString mbchName="";
+    TString mbchTime="";
+    TH1F* h;
+
+    fgets(line,100,fp);  //#line 1 wird �bersprungen
+    while(1)   {
+        GET_LINE(line,fp);//#line 2 wird �bersprungen
+        GET_LINE(line,fp);  //erste Zeile mit board groessen
+
+        h = 0;
+        while(line[0] != '#') {
+//             sscanf(line,"0x%x 0x%x",&mb,&thresh);     // holt aus der zeile das mb und die schwelle raus
+//             if(print) cout << "MB: " << hex << mb << " threshold: " << hex << thresh << endl;
+            GET_LINE(line,fp);  //naechste Zeile
+        }
+
+        GET_LINE(line,fp);  //erste Zeile mit thresholds
+
+        h = 0;
+        while(line[0] != '#') {
+            sscanf(line,"0x%x 0x%x",&mb,&thresh);     // holt aus der zeile das mb und die schwelle raus
+            if(print) cout << "MB: " << hex << mb << " threshold: " << hex << thresh << endl;
+            GET_LINE(line,fp);  //naechste Zeile
+        }
+
+        GET_LINE(line,fp);   //Event Information
+        if (line[0] == '#') continue;  //Broken Event
+          else evtct++;
+        GET_LINE(line,fp);   //Gesamtzahl Datenwoerter
+        sscanf(&line[2],"%4x",&all_datawords);
+        GET_LINE(line,fp);   //Zahl Datenwoerter
+        do{
+            sscanf(&line[2],"%4x",&datawords);
+            sscanf(&line[7],"%3x",&mb);
+            if(print) cout<<"MBO: " << hex << mb << " Words: " << hex << datawords << endl;
+            mbName = Form("OEP%x_Thresh%x",mb,thresh);
+            mbchName = Form("OEP%x_Thresh%x_Channels",mb,thresh);
+            mbchTime = Form("OEP%x_Thresh%x_Time",mb,thresh);
+
+            if((h = (TH1F*)hists_boards->FindObject(mbName.Data())) == 0){         // die funktion geht die dateien durch,
+                h = new TH1F(mbName.Data(),mbName.Data(),120,0,120);        // wenn eine mbo# neu ist, wird ein neues
+                hists_boards->Add(h);                                              // histogramm angelegt
+                h->Sumw2();
+            }
+            if(print) 
+                cout << " MBO Worte: " << datawords << endl;
+            h-> Fill(datawords);
+
+            for(Int_t j = 0; j < datawords; j++) {  //read datawords
+                GET_LINE(line,fp);
+               if (line[0] == '#') {
+                   cout << "Wrong datacount" << endl;
+                    break;
+                   }
+                sscanf(&line[2],"%x",&dataword);
+                dataword >>= 12;
+                dataword &= 0x7F;
+                if((h = (TH1F*)hists_channels->FindObject(mbchName.Data())) == 0){       // die funktion geht die dateien durch,
+                    h = new TH1F(mbchName.Data(),mbchName.Data(),96,0,96);    // wenn eine mbo# neu ist, wird ein neues
+                    hists_channels->Add(h);                                              // histogramm angelegt
+                    h->Sumw2();
+                }
+                h-> Fill(dataword);
+               
+                sscanf(&line[2],"%x",&dataword);
+                dataword &= 0x7ff;
+                if((h = (TH1F*)hists_times->FindObject(mbchTime.Data())) == 0){       // die funktion geht die dateien durch,
+                    h = new TH1F(mbchTime.Data(),mbchTime.Data(),2048,0,2048);    // wenn eine mbo# neu ist, wird ein neues
+                    hists_times->Add(h);                                              // histogramm angelegt
+                    h->Sumw2();
+                }
+                h-> Fill(dataword);
+            
+           
+           
+           }
+            GET_LINE(line,fp);   //naechste Zahl Datenwoerter
+        } while(line[0] != '#');
+    }
+
+    fclose(fp);
+
+
+    return evtct;
+}
+
+
+
+void NoiseTestMult()
+{
+    gStyle->SetOptTitle(0);
+    //gStyle->SetOptStat(0);
+    gStyle->SetOptFit(11);
+    gStyle->SetCanvasColor(10);
+    gStyle->SetTitleFillColor(10);
+    gStyle->SetStatColor(10);
+    gStyle->SetPadLeftMargin(0.15);
+
+
+    TCanvas* c1 = new TCanvas("c1","Noise Test",200,10,1000,800);
+    c1->SetGridx();
+    c1->SetGridy();
+
+    TCanvas* c2 = new TCanvas("c2","datawords/board/event",200,10,2200,1900);
+    c2->SetGridx();
+    c2->SetGridy();
+    c2->Divide(2,2);
+
+    TCanvas* c3 = new TCanvas("c3","datawords/channel",200,10,2200,1900);
+    c3->SetGridx();
+    c3->SetGridy();
+    c3->Divide(2,2);
+
+    TCanvas* c4 = new TCanvas("c4","TDC Data",0,0,2200,1900);
+    c4->SetGridx();
+    c4->SetGridy();
+    c4->Divide(2,2);
+
+
+
+    TH2F* plotocc=new TH2F("plotocc","Noise Test",80,40,120,10000,0,0.5);
+    plotocc->SetXTitle("Threshold");
+    plotocc->SetYTitle("Noise Occupancy [hits/channel/event]");
+    plotocc->SetMarkerStyle(20);
+
+    //plot->Fill(60,occ);
+
+    TObjArray* hists_boards = new TObjArray();
+    TObjArray* hists_channels = new TObjArray();
+    TObjArray* hists_times = new TObjArray();
+
+
+    Char_t* files[]={"noise_4_70","noise_4_60","noise_4_50","noise_4_40","noise_4_30",};
+// "noisedata_00.txt",
+//                       "noisedata_10.txt",
+//                       "noisedata_20.txt",
+//                       "noisedata_30.txt",
+//                       "noisedata_40.txt",
+//                       "noisedata_50.txt",
+//                       "noisedata_70.txt"
+    Int_t evts, allevts = 0;
+
+    for(Int_t i=0;i<5;i++) {
+        evts = readNoiseFile(files[i],hists_boards,hists_channels,hists_times,kFALSE);
+        allevts = allevts + evts;
+    }
+
+
+    //------------------------------------------------------------------
+
+    hists_boards->Print();
+    for(Int_t i = 0; i < hists_boards->GetEntries();i++){
+        c2->cd(i+1);
+        TH1F* h = (TH1F*)hists_boards->At(i);
+        h->SetXTitle("number of datawords per event");
+        h->SetFillColor(4);
+        cout<<evts<<" Name "<<h->GetName()<<" Integral "<<h->Integral()*h->GetMean()<<" mean "<<h->GetMean()<<endl;
+        Int_t threshold,board;
+        sscanf(h->GetName(),"OEP%x_Thresh%x",&board,&threshold);
+       if (board == 0x119)
+               plotocc->Fill(threshold,(h->GetMean())/96.);
+       else
+               plotocc->Fill(threshold,(h->GetMean())/64.);
+        h->Draw();
+    }
+
+
+    hists_channels->Print();
+    for(Int_t i = 0; i < hists_channels->GetEntries();i++){
+        c3->cd(i+1);
+        TH1F* h = (TH1F*)hists_channels->At(i);
+        h->SetXTitle("datawords per channel");
+        h->SetFillColor(4);
+        h->Draw();
+    }
+
+    
+    hists_times->Print();
+    for(Int_t i = 0; i < hists_times->GetEntries();i++){
+        c4->cd(i+1);
+        TH1F* h = (TH1F*)hists_times->At(i);
+        h->SetXTitle("TDC data");
+        h->SetFillColor(4);
+        h->Draw();
+    }    
+
+    //------------------------------------------------------------------
+    // calculating occupancy per channel
+
+    c1->cd();
+    plotocc->Draw();
+
+//     float occ;
+
+//    occ = (h->Integral()*h->GetMean())/(2*2*64*allevts);
+         //h->Integral()*h->GetMean(): Anzahl der Datenw�rter aus Histogrammen
+
+//    cout << "OCC: " << occ << endl;
+
+//     int ct = 1;
+//     const Int_t n = 100;
+//     Float_t x[n] = {0};
+//     Float_t y[n] = {0};
+// 
+//     x[0] = 60;        //test
+//     y[0] = occ;
+// 
+//     TGraph* gr = new TGraph(ct,x,y);
+//     gr->SetMarkerColor(2);
+//     gr->SetMarkerStyle(21);
+//     gr->Draw("LPsame");
+//     c1->Update();
+
+    //------------------------------------------------------------------
+
+}
+
+