]> jspc29.x-matter.uni-frankfurt.de Git - radhard.git/commitdiff
Run analyzer: Code cleanup
authorBenjamin Linnik <blinnik@jspc28.x-matter.uni-frankfurt.de>
Mon, 2 Mar 2015 19:18:16 +0000 (20:18 +0100)
committerBenjamin Linnik <blinnik@jspc28.x-matter.uni-frankfurt.de>
Mon, 2 Mar 2015 19:18:16 +0000 (20:18 +0100)
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 6c1cf097c4960d71c1adeef73eb0c70dc3d4e3fc..62d2b703e989641d9972a3e625343c17615ed202 100644 (file)
@@ -42,7 +42,7 @@ void ChargeSpektrum()
     cout << "Found " << numberRuns << " run(s) in 'runlist.txt'." << endl;
     for(Int_t runi=0;runi<numberRuns;runi++) // loop over runs read from file
     {
-        runs[runi] = new Run(342265);
+        runs[runi] = new Run(342132);
         if (runi%2)
         {
             // check if devided matrix is investigated
index e6d201b37ea1df7ce1cd6dc7efda18a81c5f2863..aad77fb3c160c5de10751faf0723b44d1a0e4a46 100644 (file)
@@ -38,7 +38,10 @@ MAPS::MAPS(Run* runp) {
         initMapsRun( );
     }        sleep(1); // TODO test if removable
     
+}
+
 
+Bool_t MAPS::initNewRootFile() {
     if ( checkConf(fPixelsData) ) // TODO FileEvNbInConfig
     {
         //-----------------------------------------------
@@ -46,11 +49,52 @@ MAPS::MAPS(Run* runp) {
         int MaxFiles = FileTotalEvNbInConfig/FileEvNbInConfig;
         if( checkDataFiles(MaxFiles) )
         {
-            initSave();
+            fOutputFile     = new TFile(fRootFile,"RECREATE");
+            // Hit TTree
+            fHitTree        = new TTree("hit", "hit");
+            fHitTree->Branch("frame"    , &fFrameInfo.frame ,     "frame/i"         , 32000);
+            fHitTree->Branch("hits"     , &fFrameInfo.hits  ,     "hits/i"          , 32000);
+            fHitTree->Branch("pixel"    , &fFrameInfo.pixel[0]  , "pixel[hits]/i"   , 32000);
+            for(int i=0; i<25; i++) {
+                fHitTree->Branch( Form("p%i",i+1)   , &fFrameInfo.p[i][0]   , Form("p%i [hits]/F",i+1)  , 32000);
+            }
+            // Noise TTree
+            fNoiseTree      = new TTree("noise", "noise");
+            fDynNoiseTree   = fNoiseTree;            
+            cout<<"-----------------------"<<endl;
+            cout<<fRootFile<<" recreated!"<<endl;
+            cout<<"-----------------------"<<endl;
+            return 0;
         }
         //-----------------------------------------------
     }        sleep(1); // TODO test if removable
+    return 1;
+    
+}
 
+
+Bool_t MAPS::initOldRootFile() {
+    fOutputFile     = new TFile(fRootFile,"UPDATE");
+    if (fOutputFile->IsZombie())
+    {
+        cout << "Error opening old ROOT file!" << endl;
+        return 1;
+    }
+    fHitTree =  (TTree*) fOutputFile->Get("hit");
+    fHitTree->SetBranchAddress("frame" , &fFrameInfo.frame );
+    fHitTree->SetBranchAddress("hits" , &fFrameInfo.hits );
+    fHitTree->SetBranchAddress ("pixel", &fFrameInfo.pixel[0]);
+    for(int i=0; i<25; i++) {
+        fHitTree->SetBranchAddress( Form("p%i",i+1)   , &fFrameInfo.p[i][0]);
+    }
+    
+    fHitTree =  (TTree*) fOutputFile->Get("noise");
+    fDynNoiseTree   = fNoiseTree;
+    
+    cout<<"-----------------------"<<endl;
+    cout<<fRootFile<<" opened!"<<endl;
+    cout<<"-----------------------"<<endl;
+    return 0;    
 }
 //####################################################################
 
@@ -112,7 +156,7 @@ MAPS::~MAPS(void) {
 void MAPS::initMapsRun( ) {
 // 
     fInDir=run->storepathLinux;
-    fOutDir = run->storepathLinux; // ouput directory is input directory
+    fOutDir = run->storepathLinux; // default ouput directory is input directory
        
        fRunNumber = run->labbook.runnumber;
     fRows = run->sensorinfocurrent.rows;
@@ -135,11 +179,8 @@ void MAPS::initMapsRun( ) {
     cout<<" Ordering according to : "<<fOrderCode<<endl;
     cout<<" Save/Overwrite data   : "<<fSave<<endl;
     cout<<" System specified      : "<<fSystem<<endl;
-    cout<<" Dynamic noise calc    : ";
-    if (useexponentialdecayingnoisewindow)
-        cout << "Modified moving average (MMA)" << endl;
-    else
-        cout << "Simple moving average (SMA)" << endl;
+    
+//     loadNoise();
 
 //-----------------------------------------------
     unsigned short int vi,vj;
@@ -149,13 +190,8 @@ void MAPS::initMapsRun( ) {
             value1[vi][vj] = (vj*16 + (vi & 0xF0) / 16);
         }
     }
-    // TODO remove this part?
-    // config ROOT plotting style
-    gStyle->SetOptFit(1011);
-    gStyle->SetPalette(1);
-    gStyle->SetCanvasColor(0);
-    gStyle->SetFrameFillColor(10);
-    gStyle->SetOptStat(0);
+    
+    initHistograms();
 //-----------------------------------------------
 }
 
@@ -439,47 +475,37 @@ bool MAPS::checkDataFile( UInt_t FileNr, UInt_t &Frames ) {
 
 //####################################################################
 
-void MAPS::initSave() {
-    if(fSave )
-    {
-        fOutputFile    = new TFile(fRootFile,"RECREATE");
-        // Hit TTree
-        fHitTree               = new TTree("hit", "hit");
-
-        fHitTree->Branch("frame"       , &fFrameInfo.frame     , "frame/i"                     , 32000);
-        fHitTree->Branch("hits"                , &fFrameInfo.hits      , "hits/i"                      , 32000);
-        fHitTree->Branch("pixel"       , &fFrameInfo.pixel[0]  , "pixel[hits]/i"       , 32000);
-        for(int i=0; i<25; i++)        {
-            fHitTree->Branch( Form("p%i",i+1)  , &fFrameInfo.p[i][0]   , Form("p%i [hits]/F",i+1)      , 32000);
-        }
-        // Noise TTree
-        fNoiseTree             = new TTree("noise", "noise");
-        fDynNoiseTree  = fNoiseTree;
-//-----------------------------------------------
-        hint1          = new TH2F("Hitmulit", "Hit multiplicity",                      fColumns, 0, fColumns, fRows, 0, fRows);
-        hint2          = new TH2F("Pixmulit", "Pix multiplicity",                      fColumns, 0, fColumns, fRows, 0, fRows);
-        
-        fdiscriminatedhitmatrix = new TH2F("HittedPixel Discri", "HittedPixel Discri", fColumns, 0, fColumns, fRows, 0, fRows);
-        fADCHitmatrix = new TH2F("HittedPixel ADC", "HittedPixel", fColumns, 0, fColumns, fRows, 0, fRows);
-
-        hint1->GetXaxis()->SetRangeUser(0, fColumns);
-        hint1->GetYaxis()->SetRangeUser(0, fRows);
-        hint1->GetXaxis()->SetTitle("column");
-        hint1->GetYaxis()->SetTitle("row");
-        hint1->GetZaxis()->SetTitle("Signal [ADC]");
-
-        hint2->GetXaxis()->SetRangeUser(0, fColumns);
-        hint2->GetYaxis()->SetRangeUser(0, fRows);
-        hint2->GetXaxis()->SetTitle("column");
-        hint2->GetYaxis()->SetTitle("row");
-        hint2->GetZaxis()->SetTitle("Signal [ADC]");
-//-----------------------------------------------
-        cout<<"-----------------------"<<endl;
-        cout<<fRootFile<<" recreated!"<<endl;
-        cout<<"-----------------------"<<endl;
-    }
+
+void MAPS::initHistograms() {
+    //-----------------------------------------------
+    gStyle->SetOptFit(1011);
+    gStyle->SetPalette(1);
+    gStyle->SetCanvasColor(0);
+    gStyle->SetFrameFillColor(10);
+    gStyle->SetOptStat(0);
+    
+    hint1       = new TH2F("Hitmulit", "Hit multiplicity",          fColumns, 0, fColumns, fRows, 0, fRows);
+    hint2       = new TH2F("Pixmulit", "Pix multiplicity",          fColumns, 0, fColumns, fRows, 0, fRows);
+    fdiscriminatedhitmatrix = new TH2F("HittedPixel Discri", "HittedPixel Discri", fColumns, 0, fColumns, fRows, 0, fRows);
+    fADCHitmatrix = new TH2F("HittedPixel ADC", "HittedPixel", fColumns, 0, fColumns, fRows, 0, fRows);
+
+    hint1->GetXaxis()->SetRangeUser(0, fColumns);
+    hint1->GetYaxis()->SetRangeUser(0, fRows);
+    hint1->GetXaxis()->SetTitle("column");
+    hint1->GetYaxis()->SetTitle("row");
+    hint1->GetZaxis()->SetTitle("Signal [ADC]");
+
+    hint2->GetXaxis()->SetRangeUser(0, fColumns);
+    hint2->GetYaxis()->SetRangeUser(0, fRows);
+    hint2->GetXaxis()->SetTitle("column");
+    hint2->GetYaxis()->SetTitle("row");
+    hint2->GetZaxis()->SetTitle("Signal [ADC]");
+    //-----------------------------------------------
 }
 
+
+
+
 //####################################################################
 
 bool MAPS::getFrame(Int_t FrameNumber) {
@@ -665,6 +691,11 @@ bool MAPS::getNoise(Int_t Start, Int_t Frames) {
 //####################################################################
 // initial Dynamic Noise + Pedestals calculation
 bool MAPS::InitialDynNoise(Int_t startframe, Int_t frames) {
+    cout<<" Dynamic noise calc    : ";
+    if (useexponentialdecayingnoisewindow)
+        cout << "Modified moving average (MMA)" << endl;
+    else
+        cout << "Simple moving average (SMA)" << endl;
     // temporal local variables
     /// temporal variable to save second pedestial estimate
     Float_t* pixelpedestal2 = new Float_t[fPixels]();
@@ -1087,22 +1118,23 @@ bool MAPS::regetDynNoise(Int_t Frames) {
 }
 
 //###################################################################
-bool MAPS::loadNoise( TString InDir, Int_t RunNumber, Int_t Matrix) {
+bool MAPS::loadNoise() {
+    loadNoise(fRootFile);
+}
 
-    TString FILENAME = InDir+Form("%i/%i_%i.root",RunNumber,RunNumber,Matrix);
-    TFile *f = new TFile(FILENAME,"READ");
+bool MAPS::loadNoise( TString filename) {
+    TFile *f = new TFile(filename,"READ");
 
     if(f->IsZombie())
     {
         cerr<<"ERROR: loadNoise() failed!"<<endl;
-        cerr<<FILENAME<<" not found!"<<endl;
+        cerr<<filename<<" not found!"<<endl;
         cerr<<"-----------------------"<<endl;
         return false;
         exit(-1);
     }
     else
     {
-        cout<<"Noise/Pedestals loaded from:"<< FILENAME << "!"<<endl;
 
         TTree *noiseTree       = (TNtuple*) f->Get("noise");
 
@@ -1110,6 +1142,7 @@ bool MAPS::loadNoise( TString InDir, Int_t RunNumber, Int_t Matrix) {
         Float_t        NOISE, PEDESTAL;
 
         noiseTree->SetBranchAddress("pixel"            , &PIXEL        );
+        cout<<"Noise/Pedestals loaded from:"<< filename << "!"<<endl;
         noiseTree->SetBranchAddress("noise"            , &NOISE        );
         noiseTree->SetBranchAddress("pedestal" , &PEDESTAL     );
 
index 19842e2f058a17eb7148f896d6a4142cb38866cb..23625b48986a9ce5d4f16fc70c9a68f09d8d0624 100644 (file)
@@ -209,7 +209,7 @@ private:
      * 
      * Called in the constructor of @c MAPS()
      */
-    void        initSave();
+    void        initRootfile();
     
     /**
      *  @brief  Compares provided information with that found in the RAW data
@@ -267,14 +267,11 @@ private:
     
     template <typename arraytype>
     arraytype debugStream(const arraytype* (a), Int_t n=512, Int_t columns=8, Int_t precision=2);
-    
-//     /**
-//      * @brief Sums over a given array
-//      *
-//      * Give this function an array, it weill return a sum
-//      */
-//     template <typename arraytype>
-//     arraytype SumOverArray(const arraytype* (a), Int_t n);
+        
+    /**
+     * @brief Initialize histogram labels and histograms #hint1, #hint2, #fdiscriminatedhitmatrix, #fADCHitmatrix
+     */
+    void initHistograms();
     
     
 public:
@@ -289,6 +286,24 @@ public:
     MAPS    ( Run* );
     ~MAPS   (void);
     
+    
+    /**
+     * @brief Checks RAW data files and creates a new ROOT file
+     *
+     * Creates a new ROOT file with TTrees "hit" and "noise"
+     * 
+     */
+    Bool_t initNewRootFile();
+    
+    
+    /**
+     * @brief Reopens an allready existing ROOT file
+     *
+     * Loads a ROOT file
+     * 
+     */
+    Bool_t initOldRootFile();
+    
     /**
      * @brief Reads in RAW data, offsets to specific frame, sets fF0matrix, fF1matrix and fCdsmatrix
      * 
@@ -365,7 +380,8 @@ public:
      * @param RunNumber The runnumber is used to substitute the correct name of the .root file
      * @param Matrix Used to substitute in filename
      */
-    bool loadNoise      (TString InDir, Int_t RunNumber, Int_t Matrix=0);
+    bool loadNoise      (TString filename);
+    bool loadNoise      ();
     /**
      * @brief Sets noise of each pixel to a given value
      * 
@@ -426,5 +442,10 @@ public:
     /// Output Directory, set and passed initMapsRun() to  in the constructor
     TString     fOutDir;///< Some documentation for first.
     Run* run;
+    
+protected:
+    
+    /// Size of cluster. Don't change without code modification
+    const Int_t clustersize = 5;
 };
 #endif
\ No newline at end of file
index 2e52091fbf120ac649aa8e5af4bb1e1e38a3c577..e17274656fe9b73e1879606f5228052ac827c8db 100644 (file)
@@ -18,8 +18,8 @@ Run::Run( void )
 
 Run::~Run( void)
 {
-    db->Close();
     delete processed;
+    db->Close();
     rootfile->Close();
 }
 
@@ -80,7 +80,7 @@ Run::Run(Int_t runnumber)
             {
                 getVetoPeakPositionFromFe55Run();
             }
-                       setSystemInfo();
+            setSystemSpecificParameters();
             generateReadableRunCode();
             runexistsinDB = 1;
         }
@@ -103,6 +103,7 @@ Bool_t Run::analyzeRun(Bool_t force)
         processed = new MAPS(this);
         if (!runAllreadyAnalyzed() || force)
         {
+            processed->initNewRootFile();
             /// progress meter, temporal variable
             ULong_t progress_tmp=-1;
             /// progress meter
@@ -120,6 +121,7 @@ Bool_t Run::analyzeRun(Bool_t force)
                 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(storepathLinux + "/rootfilecreated",std::ios::out);
             *fout << "" << endl;
@@ -128,12 +130,27 @@ Bool_t Run::analyzeRun(Bool_t force)
         else
         {
             cout << "\033[1;33mSkipped analysis of run " << labbook.runnumber << ", I think the root file for this run allready exists.\033[0m" << endl;
+            
+            processed->initOldRootFile();
+//             TString rootfilepath = storepathLinux + Form ("/RUN_%i_i.root", labbook.runnumber);
+//             
+//             
+//             rootfile = new TFile(rootfilepath);
+//             if (!(rootfile->IsZombie())) 
+//             {
+//                 runexistsAsRootFile = 1;
+//             }
+//             else
+//             {
+//                 // if we cannot open the file, print an error messageForm("hist%i",nHistNtuple) and return immediatly
+//                 cout << "\033[1;31mError: cannot open " << rootfilepath << "\033[0m\n";
+//                 exit(0);
+//             }
         }
 //         binNoise();
 //         binSeedSumVeto();
         
-//          TString rootfilepath = storepathLinux + Form ("/RUN_%i_i.root", labbook.runnumber);
-//         rootfile = new TFile(rootfilepath);
+         
 //         if (!(rootfile->IsZombie())) 
 //         {
 //             runexistsAsRootFile = 1;
@@ -161,7 +178,7 @@ Bool_t Run::analyzeFrame(Int_t frame)
         {
             processed->InitialDynNoise(100);
             processed->getFrame(frame);
-//             processed->filterCommonMode();
+            processed->filterCommonMode();
             processed->hitana();
             processed->plotFrame(frame);
             binNoise();
@@ -265,6 +282,14 @@ Float_t Run::stringToNumber ( string Text )
     return ss >> result ? result : 0;
 }
 
+
+void Run::setSystemSpecificParameters()
+{
+    // if USB system, threshold = 5, if PXI = 65
+    vetothreshold=labbook.system=="USB"?5:75;
+    setSystemInfo();
+}
+
 void Run::setSystemInfo()
 {
     sensorinfostruct sensorinfoMi34USB;
@@ -427,15 +452,39 @@ Bool_t Run::binSeedSumVeto()
     /// pixel number of seed pixel, position on sensor
     UInt_t seedPixel[10000];
     /// Array of CLUSTERSIZE * CLUSTERSIZE clusters, seed pixel in the middle
-    Float_t pixelcluster[5*5][10000];
+    Float_t pixelcluster[processed->clustersize*processed->clustersize][10000];
+    
+    /// collected charge in cluster
+    Float_t pixelSum = 0;
+    Float_t notSeedSum = 0;
     
     for (Int_t framei=0; framei<processed->fHitTree->GetEntries(); framei++) // loop over all frames
     {
         processed->fHitTree->GetEntry(framei);
         // account only frames with less then 10 hits
-        cout << processed->fFrameInfo.hits << endl;
-//         if (processed->fFrameInfo.hits<10)
-//         {
+        if (processed->fFrameInfo.hits<10)
+        {
+            for(Int_t hiti=0; hiti<processed->fFrameInfo.hits;hiti++)
+            {
+                // histogram with the single pixel
+                histogram.Seed->Fill(processed->fFrameInfo.p[12][hiti]);
+                
+                // sum histogram
+                pixelSum = 0;
+                notSeedSum = 0;
+                for (Int_t clusteri=0; clusteri<processed->clustersize*processed->clustersize; clusteri++)
+                {
+                    pixelSum += processed->fFrameInfo.p[clusteri][hiti];
+                    if (clusteri != 12)
+                        notSeedSum += processed->fFrameInfo.p[clusteri][hiti];
+                }
+                histogram.Sum->Fill(pixelSum);
+                
+                // veto spectrum
+                if (TMath::Abs(notSeedSum) < vetothreshold)
+                    histogram.Veto->Fill(processed->fFrameInfo.p[12][hiti]);    // histogram with the single pixel
+            }
+        }
     }
 }
 
index 3eebd9eedac2d2a7aa6e990e95a6aec75c9255cd..fbfee1d21aaf6c050936ddb6e1b92ac73d53c9d5 100644 (file)
@@ -141,7 +141,7 @@ private:
      * @brief Checks if a file exists
      */
     Bool_t checkFileExists(TString);
-       
+       
 public:
     /** @brief empty constructor */
     Run    (void);
@@ -167,6 +167,8 @@ public:
     Bool_t analyzeFrame(Int_t frame);
     
     
+    Int_t getClustersize();    
+    
     Bool_t runAllreadyAnalyzed();
     
     Bool_t plotNoise();
@@ -217,7 +219,9 @@ public:
     
     /** @brief sets #sensorinfocurrent after run data got from db, USB or PXI */
     void setSystemInfo();
-        
+    
+    /** @brief sets system dependant variables after run data got from db, USB or PXI */
+    void setSystemSpecificParameters();
     
     /** @brief A structure to hold the histogram data for the run
      * 
@@ -266,6 +270,9 @@ public:
     /// fitted position of the calibration peak of Fe55-beta-photons in the seed spectrum, from a run best suited to the current
     Float_t posVeto=0;
     
+    /// veto threshold, if sum in cluster small then given value, consider as direct diode hit and add to veto histogram
+    /// is set to 5 if USB system and to 75 if PXI
+    Float_t vetothreshold;    
     
     /** @brief related Fe55 run
      * 
@@ -316,5 +323,6 @@ public:
     
     /// sensor information to use in analysis, is the system read out by USB or PXI? Number of rows differ
     sensorinfostruct sensorinfocurrent;
+    
 };
 #endif
\ No newline at end of file