]> jspc29.x-matter.uni-frankfurt.de Git - radhard.git/commitdiff
Run analyzer: Important bugfix - fixed memory leakage, cleaned up code, added error...
authorBenjamin Linnik <blinnik@jspc28.x-matter.uni-frankfurt.de>
Thu, 14 May 2015 04:56:06 +0000 (06:56 +0200)
committerBenjamin Linnik <blinnik@jspc28.x-matter.uni-frankfurt.de>
Thu, 14 May 2015 04:56:06 +0000 (06:56 +0200)
MABS_run_analyzer/ChargeSpektrum.c
MABS_run_analyzer/MAPS.c
MABS_run_analyzer/MAPS.h
MABS_run_analyzer/Run.c
MABS_run_analyzer/Run.h

index d86124530d039d2ab25c1057e78edeed8b163265..7031977ca0533fac0c8a6b8e5f2eb29dd0a23d99 100644 (file)
@@ -7,27 +7,16 @@
  * 
  */
 
-#include "Run.h"
-#include "MAPS.h"
-
-
-/**
- * @file
- * @brief Use brief, otherwise the index won't have a brief explanation.
- *
- * Detailed explanation.
- * 
- * 
- */
-
 // bad c- style fix me
-#include "Run.c"
 #include "MAPS.c"
+#include "Run.c"
 #include "CSVRow.h"
 #include "CSVRow.C"
 #include <TTimeStamp.h>
+#include <fstream>
 
 Int_t* ReadRunList();
+Int_t ReadRunList(std::vector<int>*);
 void plotAllRuns();
 void plotAllRuns(TString);
 
@@ -35,87 +24,184 @@ Run** runs;
 Int_t numberRuns;
 Bool_t isBatch = kFALSE;
 
-void ChargeSpektrum(Int_t runnumber = -1)
+const TString colorwhite = "\033[1;29m";
+const TString colorred = "\033[1;31m";
+const TString coloryellow = "\033[1;33m";
+const TString colorreset = "\033[0m";  
+const TString endlr = "\033[0m\n";  
+
+void ChargeSpektrum(Int_t runnumber)
+{
+    cout << endl << colorred << "Given parameters have wrong format, please enter integer run numbers devided by '" << colorreset  << colorwhite << "," << colorreset  << colorred << "' and surrounded by '" << colorreset  << colorwhite << "\"" << colorreset  << colorred << "'." << endlr;
+    cout << "For example run: root -l 'ChargeSpektrum.c+(\"342815,342816\")'" << endl;
+    exit(1);
+}
+
+void ChargeSpektrum(Int_t runnumber, Int_t runnumber2)
+{
+    cout << endl << colorred << "Given parameters have wrong format, please enter integer run numbers devided by '" << colorreset << colorwhite << "," << colorreset << colorred << "' and surrounded by '" << colorreset << colorwhite << "\"" << colorreset  << colorred << "'." << endlr;
+    cout << "For example run: " << colorwhite << "root -l 'ChargeSpektrum.c+(\"342815,342816\")'" << endl;
+    exit(1);
+}
+
+void ChargeSpektrum(TString runnumber = "")
 {
     cout << endl << endl; 
     if (gROOT->IsBatch())
         isBatch = kTRUE;
     
     numberRuns=0;
-    Int_t* runList;
-    if (runnumber > 0)
+    std::vector<int> runList;
+    if (runnumber.Length() > 0)
     {
-        numberRuns=1;
-        runList=new Int_t[numberRuns];
-        runList[0]=runnumber;
+        if (runnumber.Contains("-"))
+        {
+            TObjArray* runarray = runnumber.Tokenize("-");
+            if (runarray->GetEntries()==2)
+            {
+                TObjString* tempstrobj;
+                tempstrobj=static_cast<TObjString*>(runarray->At(0));
+                if (tempstrobj->GetString().Length()>0)
+                {
+                    Int_t tempintstart = tempstrobj->GetString().Atoi();
+                    tempstrobj=static_cast<TObjString*>(runarray->At(1));
+                    if (tempstrobj->GetString().Length()>0)
+                    {
+                        Int_t tempintend = tempstrobj->GetString().Atoi();
+                        if (tempintend-tempintstart > 0)
+                        {
+                            for (Int_t i=tempintstart; i <= tempintend; i++)
+                            {
+                                runList.push_back(i);
+                                numberRuns++;
+                            }
+                        }
+                        else
+                            cout << coloryellow << "Invalid run number range "<< colorreset << colorwhite << tempintstart << " till " << tempintend << endlr;
+                    }
+                    else
+                        cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempstrobj->GetString() << endlr;  
+                    
+                }
+                else
+                    cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempstrobj->GetString() << endlr;    
+            }
+            else
+            {
+                cout << endl << colorred << "Given parameters have wrong format, please enter integer run numbers devided by '" << colorreset << colorwhite << "," << colorreset << colorred << " or 2 runnumbers devided by " << colorreset << colorwhite << "-" << colorreset << colorred << "' and surrounded by '" << colorreset << colorwhite << "\"" << colorreset  << colorred << "'." << endlr;
+                cout << "For example run: " << colorwhite << "root -l 'ChargeSpektrum.c+(\"342815,342816\")'" << endl;
+                exit(1);
+            }  
+            
+        }
+        else
+        {
+            TObjArray* runarray = runnumber.Tokenize(",");
+            if (runarray->GetEntries()>0)
+            {
+                TObjString* tempstrobj;
+                for (Int_t i=0; i < runarray->GetEntries(); i++)
+                {
+                    tempstrobj=static_cast<TObjString*>(runarray->At(i));
+                    if (tempstrobj->GetString().Length()>0)
+                    {
+                        Int_t tempint = tempstrobj->GetString().Atoi();
+                        if (tempint > 0)
+                        {
+                            runList.push_back(tempint);
+                            numberRuns++;
+                        }
+                        else
+                            cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempint << endlr;
+                    }
+                    else
+                        cout << coloryellow << "Invalid run number "<< colorreset << colorwhite << tempstrobj->GetString() << endlr;
+                }                
+            }
+            else
+            {
+                cout << endl << colorred << "Given parameters have wrong format, please enter integer run numbers devided by '" << colorreset << colorwhite << "," << colorreset << colorred << "' and surrounded by '" << colorreset << colorwhite << "\"" << colorreset  << colorred << "'." << endlr;
+                cout << "For example run: " << colorwhite << "root -l 'ChargeSpektrum.c+(\"342815,342816\")'" << endl;
+                exit(1);
+            }         
+        }
     }
     else
     {
         /// number of runs to be analyzed, number of lines read by @c ReadRunList() 
-        numberRuns=0;
-        ReadRunList();
-        /// array with run numbers
-        runList=new Int_t[numberRuns];
-        runList=ReadRunList();
+        ReadRunList(&runList);
     }
     runs = new Run*[numberRuns];
     
-    cout << "Found " << numberRuns << " run(s) in 'runlist.txt'." << endl;
+    cout << "Found " << numberRuns << " run(s) in 'runlist.txt' or given as parameters." << endl;
     for(Int_t runi=0;runi<numberRuns;runi++) // loop over runs read from file
     {
-        runs[runi] = new Run(runList[runi], runi);
-        if (runi%2)
+        if (runList[runi]>0)
         {
-            // check if devided matrix is investigated
-            if (runList[runi-1] == runList[runi])
+            runs[runi] = new Run(runList[runi], runi);
+            if (!runs[runi]->error)
             {
-                cout << "Using devided matrix upper" << endl;
-                runs[runi]->dividedmatrix = 1;
-                runs[runi]->upperpart = 1;
+                if (runi%2)
+                {
+                    // check if devided matrix is investigated
+                    if (runList[runi-1] == runList[runi])
+                    {
+                        cout << "Using devided matrix upper" << endl;
+                        runs[runi]->dividedmatrix = 1;
+                        runs[runi]->upperpart = 1;
+                    }
+                }
+                if (runi+1 < numberRuns)
+                {
+                    if (runList[runi] == runList[runi+1] )
+                    {
+                        cout << "Using devided matrix lower" << endl;
+                        runs[runi]->dividedmatrix = 1;
+                        runs[runi]->upperpart = 0;
+                    }
+                }
+                runs[runi]->setResultsPath("./results/");
+                runs[runi]->useDynamicalNoise(true);
+    //             runs[runi]->analyzeFrame(542875); // creates or opens .root file, can analyze the RAW data
+                runs[runi]->error=runs[runi]->analyzeRun(false); // creates or opens .root file, can analyze the RAW data
+                if (!runs[runi]->error)
+                {
+            //         gROOT->SetBatch(kTRUE);
+                    //           runs[runi]->plotSeed();
+                    runs[runi]->plotSeedThreshold();
+            //         runs[runi]->plotSeed();
+            //         runs[runi]->plotSum();
+            //         runs[runi]->plotVeto();
+                    //         runs[runi]->plotNoise();
+                    if (!isBatch)
+                        gROOT->SetBatch(kFALSE);
+            //         runs[runi]->plotAllHistograms();
+                    runs[runi]->plotAllHistogramsThresholdCluster();
+            //          runs[runi]->plotAllHistogramsCalibrated(); 
+                    runs[runi]->writeAllHistogramsToFile(); 
+                }
             }
         }
-        if (runi+1 < numberRuns)
-        {
-            if (runList[runi] == runList[runi+1] )
-            {
-                cout << "Using devided matrix lower" << endl;
-                runs[runi]->dividedmatrix = 1;
-                runs[runi]->upperpart = 0;
-            }
-        }
-        runs[runi]->setResultsPath("./results/");
-        runs[runi]->useDynamicalNoise(true);
-        runs[runi]->analyzeRun(false); // creates or opens .root file, can analyze the RAW data
-//         gROOT->SetBatch(kTRUE);
-        //           runs[runi]->plotSeed();
-//         runs[runi]->plotSeedThreshold();
-//         runs[runi]->plotSum();
-//         runs[runi]->plotVeto();
-        //         runs[runi]->plotNoise();
-        if (!isBatch)
-            gROOT->SetBatch(kFALSE);
-//         runs[runi]->plotAllHistograms();
-        runs[runi]->plotAllHistogramsThresholdCluster();
-//          runs[runi]->plotAllHistogramsCalibrated(); 
-        runs[runi]->writeAllHistogramsToFile(); 
     }
     plotAllRuns("");
-    plotAllRuns("threshold");
+//     plotAllRuns("threshold");
 }
 
 Int_t* ReadRunList()
 {
     Int_t* runList=new Int_t[1000];
-    
     std::ifstream   file("runlist.txt");
-    CSVRow    row;
+    Int_t row;    
     Int_t runLauf=0;
     while (file >> row) 
-    {        
+    {
         try 
         {
-            runList[runLauf]=atoi(row[0].c_str());
-            runLauf++;
+            if (row > 0)
+            {
+                runList[runLauf]=row;
+                runLauf++;
+            }
         }
         catch(...)
         {
@@ -127,6 +213,29 @@ Int_t* ReadRunList()
 }
 
 
+Int_t ReadRunList(std::vector<int>* runlist)
+{
+    std::ifstream file("runlist.txt");
+    Int_t row;    
+    while (file >> row) 
+    {
+        try 
+        {
+            if (row > 0)
+            {
+                runlist->push_back(row);
+                numberRuns++;
+            }
+        }
+        catch(...)
+        {
+            cout << "File ended";
+        }
+    }
+    return numberRuns;
+}
+
+
 // void plotNoiseComparison()
 // {
 //     
@@ -135,15 +244,15 @@ Int_t* ReadRunList()
 
 void plotAllRuns(TString histogramtype)
 {
-    if (histogramtype.Contains("threshold"))
+    if (histogramtype.Contains("threshold")){
         for(Int_t runi=0;runi<numberRuns;runi++) { /* loop over runs read from file */
-            runs[runi]->histogrampointer = &runs[runi]->histogramthreshold; }
-    else if (histogramtype.Contains("calibrated") || histogramtype.Contains("electron"))
+            runs[runi]->plothistogrampointer = &runs[runi]->histogramthreshold; } }
+    else if (histogramtype.Contains("calibrated") || histogramtype.Contains("electron")) {
         for(Int_t runi=0;runi<numberRuns;runi++) /* loop over runs read from file */ {
-            runs[runi]->histogrampointer = &runs[runi]->histogramCalibrated; }
-    else
+            runs[runi]->plothistogrampointer = &runs[runi]->histogramCalibrated; } }
+    else {
         for(Int_t runi=0;runi<numberRuns;runi++) /* loop over runs read from file */ {
-            runs[runi]->histogrampointer = &runs[runi]->histogram; }
+            runs[runi]->plothistogrampointer = &runs[runi]->histogram; } }
     plotAllRuns();
 }
 
@@ -170,26 +279,32 @@ void plotAllRuns()
         
         for(Int_t runi=0;runi<numberRuns;runi++) // loop over runs read from file
         {
-            canvas->cd(1);
-            runs[runi]->histogrampointer->Seed->Draw("SAME");
-            lastbin = runs[runi]->histogrampointer->Seed->GetBinCenter(runs[runi]->histogrampointer->Seed->FindLastBinAbove(2,1));
-            runs[runi]->histogrampointer->Seed->SetAxisRange(0,lastbin*1.1,"X");
-            gPad->SetLogy(1);
-            legendEntry = Form("%s", runs[runi]->histogrampointer->Seed->GetTitle());
-            leg1->AddEntry(runs[runi]->histogrampointer->Veto, legendEntry, "l");
-            leg1->Draw("SAME");
-            canvas->cd(2);
-            runs[runi]->histogrampointer->Sum->Draw("SAME");
-            lastbin = runs[runi]->histogrampointer->Sum->GetBinCenter(runs[runi]->histogrampointer->Sum->FindLastBinAbove(2,1));
-            runs[runi]->histogrampointer->Sum->SetAxisRange(0,lastbin*1.1,"X");
-            canvas->cd(3);
-            runs[runi]->histogrampointer->Veto->Draw("SAME");
-            runs[runi]->histogrampointer->Veto->SetAxisRange(runs[runi]->histogrampointer->posVeto*0.7,runs[runi]->histogrampointer->posVeto*1.4,"X");
-            canvas->cd(4);
-            runs[runi]->histogrampointer->Noise->Draw("SAME");
-            legendEntry = Form("%s, Noise: %.2f", runs[runi]->labbook.matrix.Data(), runs[runi]->histogrampointer->avgNoise);
-            leg2->AddEntry(runs[runi]->histogrampointer->Veto, legendEntry, "l");
-            leg2->Draw("SAME");
+            if (runs[runi] != nullptr)
+            {
+                if (!runs[runi]->error)
+                {
+                    canvas->cd(1);
+                    runs[runi]->plothistogrampointer->Seed->Draw("SAME");
+                    lastbin = runs[runi]->plothistogrampointer->Seed->GetBinCenter(runs[runi]->plothistogrampointer->Seed->FindLastBinAbove(2,1));
+                    runs[runi]->plothistogrampointer->Seed->SetAxisRange(0,lastbin*1.1,"X");
+                    gPad->SetLogy(1);
+                    legendEntry = Form("%s", runs[runi]->plothistogrampointer->Seed->GetTitle());
+                    leg1->AddEntry(runs[runi]->plothistogrampointer->Veto, legendEntry, "l");
+                    leg1->Draw("SAME");
+                    canvas->cd(2);
+                    runs[runi]->plothistogrampointer->Sum->Draw("SAME");
+                    lastbin = runs[runi]->plothistogrampointer->Sum->GetBinCenter(runs[runi]->plothistogrampointer->Sum->FindLastBinAbove(2,1));
+                    runs[runi]->plothistogrampointer->Sum->SetAxisRange(0,lastbin*1.1,"X");
+                    canvas->cd(3);
+                    runs[runi]->plothistogrampointer->Veto->Draw("SAME");
+                    runs[runi]->plothistogrampointer->Veto->SetAxisRange(runs[runi]->plothistogrampointer->posVeto*0.7,runs[runi]->plothistogrampointer->posVeto*1.4,"X");
+                    canvas->cd(4);
+                    runs[runi]->plothistogrampointer->Noise->Draw("SAME");
+                    legendEntry = Form("%s, Noise: %.2f", runs[runi]->labbook.matrix.Data(), runs[runi]->plothistogrampointer->avgNoise);
+                    leg2->AddEntry(runs[runi]->plothistogrampointer->Veto, legendEntry, "l");
+                    leg2->Draw("SAME");
+                }
+            }
         }
         
         //         canvas -> Print( runs[0]->savepathresults + "/" + canvastitle + ".eps");
index cf53a83896f418909eefb66297f9e16b06988386..1e97fbb23d59e7fc1b97ee809aee21234cea1fe1 100644 (file)
@@ -6,7 +6,8 @@
  * 
  * 
  */
-
+#ifndef __MAPS__C
+#define __MAPS__C
 #include"MAPS.h"
 #include "Run.h"
 
@@ -18,22 +19,24 @@ MAPS::MAPS() {
 
 MAPS::MAPS(Run* runp) {
        run = runp;
-    initMapsRun();
-
-    // check if sepcified system is correct, if not, switch and reinitialize
-    if ( switchsystem() )
+    error = initMapsRun();
+    if (!error)
     {
-        if (run->labbook.system.EqualTo("USB"))
+        // check if sepcified system is correct, if not, switch and reinitialize
+        if ( switchsystem() )
         {
-            run->labbook.system = Form("PXI");
-        }
-        else
-        {
-            run->labbook.system = Form("USB");
+            if (run->labbook.system.EqualTo("USB"))
+            {
+                run->labbook.system = Form("PXI");
+            }
+            else
+            {
+                run->labbook.system = Form("USB");
+            }
+            run->setSystemSpecificParameters();
+            error = initMapsRun( );
         }
-        run->setSystemSpecificParameters();
-        initMapsRun( );
-    }        sleep(1); // TODO test if removable
+    }
     
 }
 
@@ -46,8 +49,8 @@ Bool_t MAPS::initNewRootFile() {
             //Check and open Data Files
             int MaxFiles = TMath::Ceil((Float_t) FileTotalEvNbInConfig/FileEvNbInConfig);
             if( checkDataFiles(MaxFiles) )
-            {
                 fOutputFile     = new TFile(fRootFile,"RECREATE");
+            {
                 // Hit TTree
                 fHitTree        = new TTree("hit", "hit");
                 fHitTree->Branch("frame"    , &fFrameInfo.frame ,     "frame/i"         , 32000);
@@ -147,15 +150,13 @@ MAPS::~MAPS(void) {
         fInn[i].close();
     }
     
-    cout << "Bevor delete MAPS Arrays! " << endl;
     delete[] fEvents;
     delete[] fF0matrix;
     delete[] fF1matrix;
     delete[] fCdsmatrix;
     delete[] fNoise;
     delete[] fPedestals;
-    cout << "Nach delete MAPS Arrays! " << endl;
-    cout<<"================================================================="<<endl;
+    cout<< colorwhite <<"================================================================="<<endlr;
 
 };
 
@@ -163,6 +164,13 @@ MAPS::~MAPS(void) {
 void MAPS::save() {
     if(fSave && fOk)
     {
+        cout<<"----------------------------------------------------------------"<<endl;
+        cout << "  Frames with suspicious pedestial value: " << fPedestalhighFrames << " out of " << fEventsSum << " (" << (1.0*fPedestalhighFrames/fEventsSum*100) << " %%)" << endl;
+        cout << "  Pixel with suspicious pedestial value: " << fPedestalhighPixel << " out of " << fEventsSum*fPixels<< " (" << (1.0*fPedestalhighPixel/(fEventsSum*fPixels)*100) << " %%)" << endl;
+        cout << "  Frames with suspicious noise value: " << fNoiseHighFrames << " out of " << fEventsSum << " (" << (1.0*fNoiseHighFrames/fEventsSum*100) << " %%)" << endl;
+        cout << "  Pixel with suspicious pedestial value: " << fNoiseHighPixel << " out of " << fEventsSum*fPixels<< " (" << (1.0*fNoiseHighPixel/(fEventsSum*fPixels)*100) << " %%)" << endl;
+        cout<<"----------------------------------------------------------------"<<endl;
+        
         fOutputFile->cd();
         
         fHitTree->Write("",TObject::kOverwrite);
@@ -181,7 +189,7 @@ void MAPS::save() {
 
 //####################################################################
 
-void MAPS::initMapsRun( ) {
+Bool_t MAPS::initMapsRun( ) {
 // 
     fInDir=run->storepathRAWLinux;
     fOutDir = run->storepathRAWLinux; // default ouput directory is input directory
@@ -225,6 +233,19 @@ void MAPS::initMapsRun( ) {
             value1[vi][vj] = (vj*16 + (vi & 0xF0) / 16);
         }
     }
+    
+    ifstream    inn(fConfigFile, ios::binary);
+    if( !inn.good() )
+    {
+        cout<<"-----------------------"<<endl;
+        cout << colorred << "Configuration file not found: " ;
+        cout << fConfigFile;
+        cout << endlr;
+        cout << " -- STOP -- " << endl;
+        return true;
+    }
+    
+    return false;
 //-----------------------------------------------
 }
 
@@ -245,7 +266,7 @@ bool MAPS::switchsystem( )
         inn.close();
 
         NrAdcBoards = littleEndian32( RAWDATA, 4*9);    // Number of Adc boards installed in the system
-
+        
         if( fSystem == "" )
         {
             if( NrAdcBoards == 1)   {
@@ -275,11 +296,13 @@ bool MAPS::switchsystem( )
         cout << endl;
 
         cout << " -- STOP -- " << endl;
-        exit(-1);
+        return false;
     }
     return false;
 }
 
+
+
 bool MAPS::checkConf( Int_t &PixelData ) {
 
     UInt_t DataSz;
@@ -303,7 +326,7 @@ bool MAPS::checkConf( Int_t &PixelData ) {
         NrAdcBoards    = littleEndian32( RAWDATA, 4*9);        ///< Number of Adc boards installed in the system
 
         PixelData      = DataSz/4;
-
+        
         TString System[5] = {"","","USB","","PXI"};
         if( fSystem == "" )
         {
@@ -476,27 +499,27 @@ bool MAPS::checkDataFile( UInt_t FileNr, UInt_t &Frames ) {
 //             Frames = countframes;
         Frames = End/(4*(fPixelsData+29));
 //-----------------------------------------------
-        cout<<setw(25)<<right<<Form("RUN_%i_%i.rz  --> ",fRunNumber,FileNr)<<left;
-
-        if             (End/(TMath::Power(2,40)) >= 1) {
-            printf("%6.2f TB  ", (Float_t)(End/(TMath::Power(2,40))) );
-        }
-        else if        (End/(TMath::Power(2,30)) >= 1) {
-            printf("%6.2f GB  ", (Float_t)(End/(TMath::Power(2,30))) );
-        }
-        else if        (End/(TMath::Power(2,20)) >= 1) {
-            printf("%6.2f MB  ", (Float_t)(End/(TMath::Power(2,20))) );
-        }
-        else if        (End/(TMath::Power(2,10)) >= 1) {
-            printf("%6.2f kB  ", (Float_t)(End/(TMath::Power(2,10))) );
-        }
-        else                                                                   {
-            printf("%6.2f B   ", (Float_t)(End));
-        }
-
-        cout<<setw(15)<<left<<Form("%7i Frames",Frames);
+//         cout<<setw(25)<<right<<Form("RUN_%i_%i.rz  --> ",fRunNumber,FileNr)<<left;
+// 
+//         if          (End/(TMath::Power(2,40)) >= 1) {
+//             printf("%6.2f TB  ", (Float_t)(End/(TMath::Power(2,40))) );
+//         }
+//         else if     (End/(TMath::Power(2,30)) >= 1) {
+//             printf("%6.2f GB  ", (Float_t)(End/(TMath::Power(2,30))) );
+//         }
+//         else if     (End/(TMath::Power(2,20)) >= 1) {
+//             printf("%6.2f MB  ", (Float_t)(End/(TMath::Power(2,20))) );
+//         }
+//         else if     (End/(TMath::Power(2,10)) >= 1) {
+//             printf("%6.2f kB  ", (Float_t)(End/(TMath::Power(2,10))) );
+//         }
+//         else                                                                        {
+//             printf("%6.2f B   ", (Float_t)(End));
+//         }
+// 
+//         cout<<setw(15)<<left<<Form("%7i Frames",Frames);
         if (Frames != FileEvNbInConfig && Frames >= 20000)
-            cout << "\033[1;31mRun could be corrupted, number of events in file doesn't match configuration! ("<< Frames << " != " << FileEvNbInConfig << ") \033[0m\n";
+            cout << colorred << "Run could be corrupted, number of events in file doesn't match configuration! ("<< Frames << " != " << FileEvNbInConfig << ")" << endlr;
 //             cout<<setw(15)<<left<<Form("%7i Pixels",Pixels);
         cout<<endl;
 //-----------------------------------------------
@@ -739,6 +762,9 @@ bool MAPS::InitialDynNoise(Int_t startframe, Int_t frames) {
     Int_t* nframescutawaythirdnoiseestimate = new Int_t[fPixels]();   
     Int_t npixelscutawaythirdnoiseestimate=0; 
         
+    
+    
+    
 //     fDynNoiseTree->Branch("frame"       , &fFrameNumber     , "frame/i"     , 32000);
 //     fDynNoiseTree->Branch("noise"       , &fNoiseMean       , "noise/F"     , 32000);
 //     fDynNoiseTree->Branch("pedestal"    , &fPedestalsMean   , "pedestal/F"  , 32000);
@@ -953,7 +979,10 @@ void MAPS::debugStream(const arraytype* (a), Int_t n, Int_t columns, Int_t preci
     cout << endl;
 }
 
+
 bool MAPS::regetDynNoise(Int_t Frames) {
+    Bool_t pedestalhighinthisframe = false;
+    Bool_t noisehighinthisframe = false;
     for(Int_t pixeli=0; pixeli<fPixels; pixeli++)
     {
         //         if (fHittedPixel[fColumns]==0)
@@ -974,7 +1003,12 @@ bool MAPS::regetDynNoise(Int_t Frames) {
                 CDSlastframes[pixeli].push(fCdsmatrix[pixeli]);
                 if (abs(fPedestals[pixeli])>20)
                 {
-                    cout<<"\rFrame: "<<fFrameNumber<< " row: " << (Int_t)pixeli/fColumns << " Pedestial of pixel: " << fPedestals[pixeli] <<  " --> Pdestial suspiciously high!"<<endl;
+                    fPedestalhighPixel++;
+                    if (!pedestalhighinthisframe) {
+                        fPedestalhighFrames++;
+                        pedestalhighinthisframe=true;                        
+                    }
+//                     cout<<"\rFrame: "<<fFrameNumber<< " row: " << (Int_t)pixeli/fColumns << " Pedestial of pixel: " << fPedestals[pixeli] <<  " --> Pedestal suspiciously high!"<<endl;
 //                     cout<<" CDS signal of sensor: ";
 //                     debugStream<>(fCdsmatrix , fPixels, fColumns, 1, 20);
 //                     cout<<" Pedestial of sensor: ";
@@ -985,7 +1019,12 @@ bool MAPS::regetDynNoise(Int_t Frames) {
                 }
                 if (abs(fNoise[pixeli])>20)
                 {
-                    cout <<"\rFrame: "<<fFrameNumber<< " row: " << (Int_t)pixeli/fColumns << " Noise of pixel: " << fNoise[pixeli] <<  " --> Noise suspiciously high!               "<<endl;
+                    fNoiseHighPixel++;
+                    if (!noisehighinthisframe) {
+                        fNoiseHighFrames++;
+                        noisehighinthisframe=true;                        
+                    }
+//                     cout <<"\rFrame: "<<fFrameNumber<< " row: " << (Int_t)pixeli/fColumns << " Noise of pixel: " << fNoise[pixeli] <<  " --> Noise suspiciously high!               "<<endl;
 //                     cout<<" CDS signal of sensor: ";
 //                     debugStream<>(fCdsmatrix , fPixels, fColumns, 1, 20);
 //                     cout<<" Noise of sensor: ";
@@ -1001,6 +1040,10 @@ bool MAPS::regetDynNoise(Int_t Frames) {
 //             cout << "Skipped pixel " << pixeli << " for noise calc" << endl;
         }        
     }
+    if (pedestalhighinthisframe)
+        cout<<"\rFrame: "<<fFrameNumber<< " --> Pedestal suspiciously high!"<<endl;
+    if (noisehighinthisframe)
+        cout<<"\rFrame: "<<fFrameNumber<< " --> Noise suspiciously high!"<<endl;
     if (fFrameNumber%Frames == 0 && RefillNoiseBranch)
     {
         if(fSave)
@@ -2093,4 +2136,5 @@ void MAPS::reorderMi29a() {
 }
 
 //####################################################################
+#endif
 
index de141998c2f5e4029be5cc0584a8ccb8b64246e2..385bdbc827e67f8b6ada717a181a9ea24a256be7 100644 (file)
@@ -127,7 +127,16 @@ private:
     /// Array mit der Größe Pixel * Frames, enthält CDS Werte
     Float_t*    fDynFrameArr; 
     /// Irgendein Array mit Grüße fPixels
-    Int_t*      fDynCounter; 
+    Int_t*      fDynCounter;
+    
+    /// how many pixel exceeded a suspecious pedestal limit
+    unsigned long fPedestalhighPixel = 0;
+    /// how many pixel exceeded a suspecious noise limit
+    unsigned long fNoiseHighPixel = 0;
+    /// in how many frames minimum one pixel exceeded a suspecious pedestal limit
+    unsigned long fPedestalhighFrames = 0;
+    /// in how many frames minimum one pixel exceeded a suspecious noise limit
+    unsigned long fNoiseHighFrames = 0;
             
     /// Array of file handlers for each RAW files, filled in @c checkDataFiles()
     ifstream*   fInn;
@@ -141,6 +150,8 @@ private:
     const static int numberofframesfornoise =100;
     
     
+    
+    
     /// full path in LINUX style to the .root file, all hit information is stored there
     TString fRootFile;
     /// full path in LINUX style to the .rz file, all run configuration is stored there
@@ -190,7 +201,7 @@ private:
      * If the RAW files indicate, that the runs are done with another system then stated in the config files, the system in the config file is ignored and
      * a warning is printed, for this @c switchsystem() is called.
      */
-    void        initMapsRun( TString, TString, Int_t, Int_t, Int_t, TString, TString, Int_t, bool);
+    Bool_t        initMapsRun( TString, TString, Int_t, Int_t, Int_t, TString, TString, Int_t, bool);
     
     
     /**
@@ -200,7 +211,7 @@ private:
      * If the RAW files indicate, that the runs are done with another system then stated in the config files, the system in the config file is ignored and
      * a warning is printed, for this @c switchsystem() is called.
      */
-    void        initMapsRun();
+    Bool_t        initMapsRun();
     
     /**
      *  @brief  initializes ROOT file structure, if fSave is set to true
@@ -291,6 +302,10 @@ public:
     ~MAPS   (void);
     
     
+    /// is set to true if somewhere a critical error occurs
+    Bool_t error = false;
+    
+    
     /**
      * @brief Checks RAW data files and creates a new ROOT file
      *
@@ -340,6 +355,7 @@ public:
     /// Pointer to the ROOT TTree of the run containing the noise, only used if external noise used
     TTree*  fNoiseTree;
     
+    
     /**
      *  @brief  Calculates a first estimate of the noise and pedestial of each pixel in #frames
      * 
@@ -389,9 +405,7 @@ public:
      * @return true if no errors occured
      */
     bool regetDynNoise  (Int_t Frames = numberofframesfornoise);
-    /**
-     * @brief Old routine, shoould be deletable without side effects */
-    bool regetDynNoise2  ();
+    
     /**
      * @brief Old routine, should load noise information from given runnumber root file
      * 
index 58a5e1fa479168f511725badf45946df44183e8d..02d4f8518a93f1f4e16492ced67a4cd8a810464e 100644 (file)
@@ -6,6 +6,8 @@
  * 
  * 
  */
+#ifndef __RUN__C
+#define __RUN__C
 
 #include "Run.h"
 using namespace std;
@@ -30,6 +32,7 @@ Run::Run(Int_t runnumber)
 Run::Run(Int_t runnumber, Int_t loopi)
 {
     plotStyle = loopi%13;
+    gethostname(hostname, 1024);
     labbook.runnumber = runnumber;
     random1 = new TRandom;  
     random1->SetSeed(0);
@@ -54,13 +57,22 @@ Run::Run(Int_t runnumber, Int_t loopi)
             // replace windows drive notation with linux style
             if (labbook.storepath.Length() > 0)
             {
+                
                 storepathRAWLinux = labbook.storepath;
 //                 storepathRAWLinux = storepathRAWLinux.ReplaceAll("H:","/jspc53_H");
 //                 storepathRAWLinux = storepathRAWLinux.ReplaceAll("h:","/jspc53_H");
-                storepathRAWLinux = storepathRAWLinux.ReplaceAll("H:","/d/garlic");
-                storepathRAWLinux = storepathRAWLinux.ReplaceAll("h:","/d/garlic");
-                storepathRAWLinux = storepathRAWLinux.ReplaceAll("U:","/jspc53_U");
-                storepathRAWLinux = storepathRAWLinux.ReplaceAll("u:","/jspc53_U");
+                storepathRAWLinux = storepathRAWLinux.ReplaceAll("H:","/d/jspc53_H");
+                storepathRAWLinux = storepathRAWLinux.ReplaceAll("h:","/d/jspc53_H");
+                if (TString(hostname).EqualTo("jspc48"))
+                {
+                    storepathRAWLinux = storepathRAWLinux.ReplaceAll("U:","/d/jspc28/jspc53_U");
+                    storepathRAWLinux = storepathRAWLinux.ReplaceAll("u:","/d/jspc28/jspc53_U");                    
+                }
+                else
+                {
+                    storepathRAWLinux = storepathRAWLinux.ReplaceAll("U:","/jspc53_U");
+                    storepathRAWLinux = storepathRAWLinux.ReplaceAll("u:","/jspc53_U");
+                }
                 storepathRAWLinux = storepathRAWLinux.ReplaceAll("F:","/jspc12_F");
                 storepathRAWLinux = storepathRAWLinux.ReplaceAll("f:","/jspc12_F");
                 storepathRAWLinux = storepathRAWLinux.ReplaceAll("O:","/d/garlic");
@@ -113,7 +125,7 @@ Run::Run(Int_t runnumber, Int_t loopi)
             initRootParameters();
             cout << colorwhite << "initHistograms():" << endlr;
             initHistograms(&histogram);
-            histogrampointer = &histogram;
+            plothistogrampointer = &histogram;
             initHistograms(&histogramthreshold, " threshold");
             runexistsinDB = 1;
             debugDBreadout();
@@ -121,11 +133,13 @@ Run::Run(Int_t runnumber, Int_t loopi)
         else
         {
             cout << "\033[1;31mNo database data for run " << numberToString<>(labbook.runnumber) << " found!\033[0m" << endl;
+            error = 1;
         }
     }
     catch(...)
     {
         cout << "\033[1;31mError while reading laboratory book (run number " << numberToString<>(labbook.runnumber) << ")!\033[0m\n";
+        error = 1;
     }
 }
 
@@ -188,43 +202,49 @@ Bool_t Run::analyzeRun(Bool_t force)
     {
         cout << colorwhite << "instatiate MAPS(this)" << endlr;
         processed = new MAPS(this);
-        if (!runAllreadyAnalyzed() || force)
+        error = processed->error;
+        if (!error)
         {
-            processed->initNewRootFile();
-            /// progress meter, temporal variable
-            ULong_t progress_tmp=-1;
-            /// progress meter
-            Float_t progress;
-            processed->InitialDynNoise();
-            int start   = 0;
-            int nframes = processed->GetNumberFrames();
-            for(int i=0; i<nframes;i++) // TODO remove 100000
+            if (!runAllreadyAnalyzed() || force)
             {
-                processed->getFrame(i);
-//                 processed->filterCommonMode();
-                processed->hitana();
-                if (dynamicalNoise)
-                    processed->regetDynNoise();
-                progress = (Int_t)(((i-start)*100)/(nframes-1)*10);
-                if (progress!=progress_tmp)  { print_progress( (((i-start)*100.)/(nframes-1)) ); progress_tmp=progress;}
-            }
-//             cout << processed->plus << " vs. " << processed->minus << " : " << (processed->plus*1.0)/processed->minus<< endl;
+                if (processed->initNewRootFile()) return 1;
+                /// progress meter, temporal variable
+                ULong_t progress_tmp=-1;
+                /// progress meter
+                Float_t progress;
+                processed->InitialDynNoise();
+                int start   = 0;
+                int nframes = processed->GetNumberFrames();
+                for(int i=0; i<nframes;i++) // TODO remove 100000
+                {
+    //                 cout << "getframe " << i << endl;
+                    processed->getFrame(i);
+                    //                 processed->filterCommonMode();
+    //                 cout << "hitana " << endl;
+                    processed->hitana();
+    //                 cout << "regetDynNoise " << endl;
+                    if (dynamicalNoise)
+                        processed->regetDynNoise();
+                    progress = (Int_t)(((i-start)*100)/(nframes-1)*10);
+                    if (progress!=progress_tmp)  { print_progress( (((i-start)*100.)/(nframes-1)) ); progress_tmp=progress;}
+                }
+    //             cout << processed->plus << " vs. " << processed->minus << " : " << (processed->plus*1.0)/processed->minus<< endl;
 
-            // print a dummy file to indicate, that a root file was created once
-            fstream* fout = new fstream(storepathRAWLinux + "/rootfilecreated",std::ios::out);
-            *fout << "" << endl;
-            fout->close();
-            processed->save();
-        }
-        else
-        {
-            cout << "Skipped analysis of run " << labbook.runnumber << ", I think the root file for this run allready exists." << endl;
-            cout << colorwhite << "initOldRootFile():" << endlr;
+                // print a dummy file to indicate, that a root file was created once
+                fstream* fout = new fstream(storepathRAWLinux + "/rootfilecreated",std::ios::out);
+                *fout << "" << endl;
+                fout->close();
+                processed->save();
+            }
+            else
+            {
+                cout << "Skipped analysis of run " << labbook.runnumber << ", I think the root file for this run allready exists." << endl;
+                cout << colorwhite << "initOldRootFile():" << endlr;
+            }
         }
-        
         if (!error)
         {
-            error = processed->initOldRootFile();
+            if (processed->initOldRootFile()) return 1;
             cout << colorwhite << "binNoise():" << endlr;
             binNoise();
             cout << colorwhite << "binSeedSumVeto():" << endlr;
@@ -235,13 +255,13 @@ Bool_t Run::analyzeRun(Bool_t force)
             calculteCCE();
             cout << colorwhite << "updateDatabase():" << endlr;
             updateDatabase();
-            cout << colorwhite << "delete processed:" << endlr;
+            cout << colorwhite << "delete MAPS class:" << endlr;
             delete processed;
-            return true;
+            return 0;
         }
         delete processed;
     }
-    return false;
+    return 1;
 }
 
 Bool_t Run::calculteCCE()
@@ -824,7 +844,7 @@ Float_t Run::FitPerform(TH1F* histogrampointer, TString fitFuncType, Bool_t verb
     Float_t posMax = 0;
     Float_t posMax2 = 0;
     Float_t posMaxValHist = histogrampointer->GetXaxis()->GetXmax();
-    Float_t noiseborder = posMaxValHist/15;
+    Float_t noiseborder = posMaxValHist/10; // for USB system, the value is 90
     
     if (doFits) 
     {        
@@ -1194,7 +1214,6 @@ void Run::initHistogram(TH1F* &histogrampointer, TString prefix)
     TString humanreadablestr = Form("%s, %s spectrum, Mi%s, chip %s, %s, T=%.1f",prefix.Data(), labbook.source.Data(), labbook.chipGen.Data(), labbook.chip.Data(), labbook.matrix.Data(), labbook.temp);
     histogrampointer=new TH1F(prefix.Data(), humanreadablestr.Data(), systemparamcur.nbins, 0, systemparamcur.maxbin);  
     histogrampointer->SetLineStyle(rootlinestyle[plotStyle]);
-    cout << "prefix: " << prefix << " rootcolor: " << rootcolors[plotStyle] << endl;
     histogrampointer->SetLineColor(rootcolors[plotStyle]);
     histogrampointer->SetStats(kTRUE);        
     histogrampointer->SetStats(111111111);
@@ -1211,3 +1230,4 @@ void Run::initRootParameters()
     rootlinestyle = new Int_t[13]{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
     
 }
+#endif
index e16d164d831f7e39a88c5f10aa6764368846403b..cba162b7c625413deaea0a520ff4054d61db52a4 100644 (file)
@@ -27,7 +27,7 @@
 #define SERVERUSER "radhard"
 #define SERVERPWD "mimosa88"
 
-#include "MAPS.h"
+#include "MAPS.c"
 class MAPS;
 
 /**
@@ -132,12 +132,12 @@ private:
     
     /// is set to true if the RAW Data is consistent
     Bool_t runRAWok = 0;
-    
-    /// is set to true if an error occured
-    Bool_t error = 0;
-    
+        
     TRandom* random1;
     
+    /// host name of the machine, used to find correct mount points
+    char hostname[1024];
+    
     /**
      * @brief fills noise #histogram  */
     Bool_t binNoise();
@@ -209,7 +209,7 @@ private:
     };
     systemparam systemparamUSB {
         900, // maxbin;
-        900/15,// nbins;
+        900/5,// nbins;
         25, //vetothreshold
         10,
         100
@@ -270,6 +270,9 @@ public:
     /** @brief Makes a gnuplot file to plot the histogram data created in  @c writeAllHistogramsToFile() */
     void MakeGnuplotFile();
     
+    /// is set to true if an error occured
+    Bool_t error = 0;
+    
     /**
      * @brief analysis the RAW data
      * 
@@ -416,7 +419,7 @@ public:
     histogramstruct histogram;
     histogramstruct histogramCalibrated;
     histogramstruct histogramthreshold;
-    histogramstruct* histogrampointer;
+    histogramstruct* plothistogrampointer;
     
     /** @brief Plots all histograms from #histogram into one canvas */
     Bool_t plotAllHistograms(histogramstruct*);