]> jspc29.x-matter.uni-frankfurt.de Git - radhard.git/commitdiff
Initial commit
authorDennis Doering <dennis@jspc31.x-matter.uni-frankfurt.de>
Tue, 10 Sep 2013 15:39:39 +0000 (17:39 +0200)
committerDennis Doering <dennis@jspc31.x-matter.uni-frankfurt.de>
Tue, 10 Sep 2013 15:39:39 +0000 (17:39 +0200)
newCOMBI/MAPS.C [new file with mode: 0755]
newCOMBI/MAPS.h [new file with mode: 0644]
newCOMBI/help.h [new file with mode: 0644]
newCOMBI/run.C [new file with mode: 0755]

diff --git a/newCOMBI/MAPS.C b/newCOMBI/MAPS.C
new file mode 100755 (executable)
index 0000000..1ce08b2
--- /dev/null
@@ -0,0 +1,1437 @@
+#include <stdlib.h>
+#include <TClass.h>
+#include <fstream>
+#include <iostream>
+#include "Riostream.h"
+#include <string>
+#include "TString.h"
+#include "TMath.h"
+#include <TFile.h>
+#include <TNtuple.h>
+#include <TH1F.h>
+#include <TH2F.h>
+#include "TH1.h"
+#include "TF1.h"
+#include "TROOT.h"
+#include <TApplication.h>
+#include "TCanvas.h"
+#include "TObject.h"
+#include "TStyle.h"
+#include "TEnv.h"
+#include "TGraph.h"
+#include "TGaxis.h"
+#include "TStyle.h"
+#include "TFrame.h"
+#include "TVector.h"
+#include "TVectorD.h"
+#include "Foption.h"
+#include "TRandom.h"
+#include "TSpline.h"
+#include "TPaveStats.h"
+#include "TVirtualFitter.h"
+#include "TVirtualPad.h"
+#include "TVirtualGraphPainter.h"
+#include "TBrowser.h"
+#include "TSystem.h"
+#include "TPluginManager.h"
+#include "TPad.h"
+#include <TQObject.h>
+#include <TMultiGraph.h>
+#include <iostream>
+#include <fstream>
+#include <sstream>
+#include <stdio.h>
+#include <stdlib.h>
+
+using namespace std;
+
+#include"MAPS.h"
+//####################################################################
+
+MAPS::MAPS() {
+
+};
+
+//####################################################################
+
+MAPS::MAPS( TString InDir, TString OutDir, Int_t RunNumber, Int_t Rows, Int_t Columns, TString System, TString OrderCode, Int_t Matrix, bool Save ) {
+//-----------------------------------------------
+       
+       initMapsRun( InDir, OutDir, RunNumber, Rows, Columns, System, OrderCode, Matrix, Save);
+       
+       UInt_t  FileEvNb;               // Event number per file
+       UInt_t  TotEvNb;                // Total events in RUN - should be less if RUN was stopped before endl
+       
+       if ( checkConf(FileEvNb, TotEvNb, fPixelsData) )
+       {
+//-----------------------------------------------
+//Check and open Data Files
+               sleep(1);
+               int MaxFiles = TotEvNb/FileEvNb;
+               
+               if( checkDataFiles(MaxFiles) )
+               {
+                       initSave();
+               }
+//-----------------------------------------------
+       }
+}
+
+//####################################################################
+
+MAPS::~MAPS(void) {
+       
+       if(fSave && fOk) 
+       {
+               fOutputFile->cd();
+                
+               fHitTree->Write("",TObject::kOverwrite);
+               fNoiseTree->Write("",TObject::kOverwrite);
+               
+               hint1->Write("",TObject::kOverwrite);
+               hint2->Write("",TObject::kOverwrite);
+               
+               fOutputFile->Save();
+               fOutputFile->Close();
+               
+               cout<<endl<<"-----------------------"<<endl;
+               cout<<"TTrees written!"<<endl;
+               cout<<fOutDir+Form("%i_%i.root",fRunNumber,fMatrix)<<" saved!"<<endl;
+               //fOutputFile->Close();
+               cout<<"...finished!"<<endl;
+               cout<<"-----------------------"<<endl;
+               
+               TString FILENAME = fOutDir+Form("%i_%i.root",fRunNumber,fMatrix);
+               TFile::Open(FILENAME);
+               gROOT->ProcessLine("new TBrowser;");
+               
+//             delete[] fOutputFile;
+//             delete[] fHitNtup;
+//             delete[] fNoiseNtup;
+//             delete[] fMeanNoiseNtup;
+       }
+       
+       for(Int_t i=0;i<fFile;i++)
+       {
+               fInn[i].close();
+       }
+                       
+       delete[] fEvents;
+       delete[] fF0matrix;
+       delete[] fF1matrix;
+       delete[] fCdsmatrix;
+       delete[] fNoise;
+       delete[] fPedestals;
+       cout<<"================================================================="<<endl;
+       
+};
+
+//####################################################################
+
+void MAPS::initMapsRun( TString InDir, TString OutDir, Int_t RunNumber, Int_t Rows, Int_t Columns, TString System, TString OrderCode, Int_t Matrix, bool Save ) {
+//-----------------------------------------------
+//Set:
+    fInDir             = InDir;
+    fOutDir            = OutDir;
+    fRunNumber = RunNumber;
+       fPixels         = Rows*Columns;
+    fRows              = Rows;
+    fColumns   = Columns;
+       fOrderCode      = OrderCode;
+       fMatrix         = Matrix;
+       fSave           = Save;
+       fSystem         = System;
+       
+       fOk                     = false;
+       fNoiseOk        = false;
+       fNoiseExt       = false;
+//-----------------------------------------------
+       cout<<"================================================================="<<endl;
+       cout<<"-----------------------"<<endl;
+       cout<<" == Initiate MAPS() ... == "<<endl;
+       cout<<"-----------------------"<<endl;
+       cout<<" Input  Directory      : "<<fInDir<<endl;
+       cout<<" Output Directory      : "<<fOutDir<<endl;
+       cout<<" Runnumber             : "<<fRunNumber<<endl;
+       cout<<" Pixels                : "<<fPixels<<" --> "<<fRows<<" x "<<fColumns<<" (Rows x Columns)"<<endl;
+       cout<<" Matrix to scan        : "<<fMatrix<<endl;
+       cout<<" Ordering according to : "<<fOrderCode<<endl;
+       cout<<" Save/Overwrite data   : "<<fSave<<endl;
+       cout<<" System specified      : "<<fSystem<<endl;
+//-----------------------------------------------
+       unsigned short int vi,vj;
+       for (vi = 0; vi <= 0xFF; vi++) {
+       for (vj = 0; vj <= 0xFF; vj++) {
+       value2[vi][vj] = (vi + (vj & 0x0F) * 256);
+       value1[vi][vj] = (vj*16 + (vi & 0xF0) / 16); } }
+//-----------------------------------------------
+       gStyle->SetOptFit(1011);
+       gStyle->SetPalette(1);
+       gStyle->SetCanvasColor(0);
+       gStyle->SetFrameFillColor(10);
+       gStyle->SetOptStat(0);
+//-----------------------------------------------
+}
+
+//####################################################################
+
+bool MAPS::checkConf( UInt_t &FileEvNb, UInt_t &TotEvNb, Int_t &PixelData ) {
+       
+       UInt_t DataSz;
+       UInt_t NrAdcBoards;
+       
+       TString         FILENAME = fInDir+Form("%i/RUN_%i_i.rz",fRunNumber,fRunNumber);
+       ifstream        inn(FILENAME, ios::binary);
+       
+       if( inn.good() )
+       {
+               inn.seekg(0, ios::end);
+               int End = inn.tellg();
+               inn.seekg(0, ios::beg);
+               
+               char* RAWDATA = new char[End];
+               inn.read        ( RAWDATA, End);
+               inn.close();
+               
+               FileEvNb        = littleEndian32( RAWDATA, 4*3);        // Event number per file
+               TotEvNb         = littleEndian32( RAWDATA, 4*4);        // Total events in RUN - should be less if RUN was stopped before endl
+               DataSz          = littleEndian32( RAWDATA, 4*6);        // Datas size = BDB_VFAS_RAM_SZ_W32 X Adc number ( VFasRunNb field )
+               NrAdcBoards     = littleEndian32( RAWDATA, 4*9);        // Number of Adc boards installed in the system
+               
+               PixelData       = DataSz/4;
+               
+               TString System[5] = {"","","USB","","PXI"};
+               if( fSystem == "" )
+               {
+                       if( NrAdcBoards == 1)   { fSystem = "USB"; }
+                       if( NrAdcBoards == 2)   { fSystem = "USB"; }
+                       if( NrAdcBoards == 4)   { fSystem = "PXI"; }
+               }
+               else if( (NrAdcBoards == 2 && fSystem != "USB") || (NrAdcBoards == 4 && fSystem != "PXI") )
+               {
+                       cout<<"---------"<<endl;
+                       cout<<"System specification ( "<<fSystem<<" ) might be incorrect!"<<endl;
+                       cout<<"Wait 10 sec. to continue: ";
+                       
+                       for(int i=0;i<10;i++)
+                       {
+                               cout<<".";
+                               fflush( stdout );
+                               sleep(1);
+                       }
+                       cout<<endl;
+                       cout<<"---------"<<endl;
+               }
+               
+               delete[] RAWDATA;
+//-----------------------------------------------
+               cout<<"-----------------------"<<endl;
+               cout<<" ==> Check config file ..."<<endl;
+               cout<<"-----------------------"<<endl;
+               cout<<" Config File           : "<< FILENAME    <<endl;
+               cout<<" Events per File       : "<<setw(10)<<right<< FileEvNb   <<endl;
+               cout<<" Total Events          : "<<setw(10)<<right<< TotEvNb            <<" (?)"<<endl;
+               cout<<" Pixels in Data        : "<<fPixelsData<<endl;
+               cout<<" System found          : "<<System[NrAdcBoards]<<endl;
+               cout<<"-----------------------"<<endl;
+               
+               if( fPixelsData<fPixels ) 
+               { 
+                       cout<<"ERROR -> Number of Pixels defined is bigger than found: "<<fPixels<<" <-> "<<fPixelsData<<endl;
+                       cout<<"-----------------------"<<endl;
+                       return false;
+               }
+//-----------------------------------------------
+//PARAMETER:
+               fF0matrix       = new Int_t             [fPixelsData];
+               fF1matrix       = new Int_t             [fPixelsData];
+               fCdsmatrix      = new Int_t             [fPixelsData];
+               fNoise          = new Float_t   [fPixelsData];
+               fPedestals      = new Float_t   [fPixelsData];
+//-----------------------------------------------
+               return true;
+       }
+       else
+       {
+               cout<<"-----------------------"<<endl;
+               cout << "Configuration file not found: ";
+               cout << fInDir+Form("%i/RUN_%i_i.rz",fRunNumber,fRunNumber);
+               cout << endl;
+               
+               cout << " -- STOP -- " << endl;
+               return false;
+       }
+}
+
+//####################################################################
+
+bool MAPS::checkDataFiles( Int_t MaxFiles ) {
+       UInt_t  Frames;
+       TString FILENAME;
+       
+       if(MaxFiles>50)
+       {
+               cout<<"Expected Nr of Files is too big: "<<MaxFiles<<" ! Nr of Files reduced to 50!"<<endl;
+               MaxFiles=50;
+       }
+       
+       fFile           = 0;
+       fEventsSum      = 0;
+       fEvents = new Int_t             [MaxFiles];
+       fInn    = new ifstream  [MaxFiles];
+       
+       for( ;fFile<MaxFiles;fFile++)
+       {
+               if( !checkDataFile(fFile, Frames) ) { break; }
+               
+               fEvents[fFile]   = Frames;
+               fEventsSum              += Frames;
+               
+               FILENAME = fInDir+Form("%i/RUN_%i_%i.rz",fRunNumber,fRunNumber,fFile);
+               fInn[fFile].open(FILENAME, ios::binary);
+               fInn[fFile].seekg(0, ios::beg);
+               
+               fOk     = true;
+       }
+       cout<<"-----------------------"<<endl;
+       cout<< "TOTAL FRAMES FOUND: "<<fEventsSum<<endl;
+       if(!fOk)
+       {
+               cout<<"-----------------------"<<endl;
+               cout<<"ERROR: Data files not found!"<<endl;
+               cout<<"-----------------------"<<endl;
+               return false;
+       }
+       else
+       {
+               return true;
+       }
+}
+
+//####################################################################
+               
+bool MAPS::checkDataFile( UInt_t FileNr, UInt_t &Frames ) {
+       
+       TString         FILENAME = fInDir+Form("%i/RUN_%i_%i.rz",fRunNumber,fRunNumber,FileNr);
+       ifstream        inn(FILENAME, ios::binary);
+//     Int_t Pixels=0;
+       if( !inn.good() )
+       {
+               return false;
+       }
+       else
+       {
+               ULong_t End;
+//             UInt_t dataword;
+//             int count               = 0;
+//             int count_tmp   = -1;
+//             int countframes = -1;
+               char* RAWDATA = new char[4];
+               
+               inn.seekg(0, ios::end);
+               End = inn.tellg();
+               inn.seekg(0, ios::beg);
+               
+//             while( inn.good() )
+//             {
+//                     inn.read        ( RAWDATA, 4);
+//                     dataword= littleEndian32( RAWDATA, 0);
+//                     
+//                     if( dataword==0x89abcdef )
+//                     {
+//                             countframes++;
+//                             
+//                             if( countframes==0 )
+//                             {
+//                                     Pixels = count-28;
+//                             }
+//                             if( count-count_tmp!=Pixels+29 && count-count_tmp!=1 )
+//                             {
+//                                     cout<<"Error in File -> Wrong Number of Pixels: ( "<< count-count_tmp-29 <<" ) in Framenr: "<<countframes<<endl;
+//                             }
+//                             count_tmp = count;
+//                     }
+//                             
+//                     count++;
+//             }
+               
+               inn.close();
+               delete[] RAWDATA;
+//             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(15)<<left<<Form("%7i Pixels",Pixels);
+               cout<<endl;
+//-----------------------------------------------
+               return true;
+       }
+}
+
+//####################################################################
+
+void MAPS::initSave() {
+       if(fSave )
+       {
+               TString FILENAME = fOutDir+Form("%i_%i.root",fRunNumber,fMatrix);
+               fOutputFile     = new TFile(FILENAME,"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");
+//-----------------------------------------------
+               hint1           = new TH2F("Hitmulit", "Hit multiplicity",                      fColumns, 0, fColumns, fRows, 0, fRows);
+               hint2           = new TH2F("Pixmulit", "Pix multiplicity",                      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<<FILENAME<<" recreated!"<<endl;
+               cout<<"-----------------------"<<endl;
+       }
+}
+
+//####################################################################
+
+bool MAPS::getFrame(Int_t FrameNumber) {
+       
+       fFrameNumber = FrameNumber;
+       
+       if(fFrameNumber<fEventsSum)
+       {
+               Int_t EVENTOFF  = 0;
+               Int_t FFILE             = 0;
+               
+               for( ;FFILE<fFile;FFILE++)
+               {
+                       EVENTOFF+=fEvents[FFILE];
+                       
+                       if(fFrameNumber<EVENTOFF) { EVENTOFF-=fEvents[FFILE]; break; }
+               }
+               
+               Int_t POSFILE           = 4*(fPixelsData+29)*(fFrameNumber-EVENTOFF);
+               Int_t HDRLENGTH         = 4*28;
+               Int_t DATALENGTH        = 4*fPixelsData;
+
+               char* HDRDATA = new char[HDRLENGTH];            //delete[] HDRDATA;
+               char* RAWDATA = new char[DATALENGTH];           //delete[] RAWDATA;
+               
+               fInn[FFILE].seekg       (POSFILE, ios::beg);
+               fInn[FFILE].read        (HDRDATA,HDRLENGTH);
+               fInn[FFILE].read        (RAWDATA,DATALENGTH);
+// Process Header Data
+               UInt_t EvNo                     = littleEndian32(HDRDATA, 1*4);         // Event number  : Increment from 0 at each event taken
+               UInt_t EvPos            = littleEndian32(HDRDATA, 2*4);         // Event position in file : Increment from 0 after each event write
+//             UInt_t EvDate           = littleEndian32(HDRDATA, 4*4);         // Event date = 0
+//             UInt_t EvTime           = littleEndian32(HDRDATA, 5*4);         // Event time = SSSS ssss ( S = second s = mS - 10 ms resolution )
+//             UInt_t EvVmeTime        = littleEndian32(HDRDATA, 7*4);         // Time to read VME boards in ms [10 ms res]
+//             UInt_t EvNetTime        = littleEndian32(HDRDATA,10*4);         // Time to send one event by ethernet in ms [10 ms res]
+//             
+               fFrameInfo.frame        = fFrameNumber;                                         // Own counting
+               fFrameInfo.evno         = EvNo;
+               fFrameInfo.evpos        = EvPos;
+               
+// Process Pixel Data
+               for(Int_t i=0;i<fPixelsData;i++)
+               {
+                       if              ( fSystem == "PXI" )
+                       {
+                               fF0matrix       [i] = (Int_t)littleEndian16(RAWDATA,4*i+2);
+                               fF1matrix       [i] = (Int_t)littleEndian16(RAWDATA,4*i+0);
+                               if( fF1matrix[i]<0 ) { fF0matrix[i]+=1; }                                       // Correction to error in DAQ code
+                       }
+                       else if ( fSystem == "USB" )
+                       {
+                               fF0matrix       [i]     = value1        [(UChar_t)RAWDATA[4*i+1]]       [(UChar_t)RAWDATA[4*i+2]];
+                               fF1matrix       [i]     = value2        [(UChar_t)RAWDATA[4*i]] [(UChar_t)RAWDATA[4*i+1]];
+                       }
+                       
+                       fCdsmatrix      [i] = fF0matrix[i] - fF1matrix[i];
+               }
+//==========================================================================
+// -----------------
+// If pixel array is different from 'standard',
+// please manipulate these arrays accordingly:
+// - fCdsmatrix
+// - fF0matrix
+// - fF1matrix
+// Use 'fOrderCode' to choose the respective order!
+// -----------------
+               if                      (fOrderCode == "")              { }
+//             else if         (fOrderCode == "Mi26")  { reorderMi26();        }
+               else if         (fOrderCode == "Mi29a") { reorderMi29a();       }
+//             else if         (fOrderCode == "Mi29b") { reorderMi29b();       }
+//==========================================================================
+               delete[] HDRDATA;
+               delete[] RAWDATA;
+               
+               fFrameOk = true;
+               return true;
+       }
+       else
+       {
+               cout<<"Event number: "<<fFrameNumber<<" is too big! Max: "<<fEventsSum<<endl;
+               fFrameOk = false;
+               return false;
+       }
+};
+
+//####################################################################
+
+bool MAPS::getNoise(Int_t Start, Int_t Frames) {
+//Noise + Pedestals
+       if(fOk)
+       {
+               cout<<"Run getNoise() ..."<<endl;
+//Check amount of Frames
+               if(Frames<50)
+               {
+                       cout<<"Too few Frames! Change Frames from "<<Frames<<" to ";
+                       Frames = 50;
+                       cout<<Frames<<" !"<<endl;
+               }
+//Check availabilty of Frames
+               if( Frames                      > fEventsSum )  { Frames = fEventsSum;                  printf("Changed 'Number Frames' to: %u\n", Frames ); }
+               if( Frames+Start        > fEventsSum )  { Start = fEventsSum-Frames;    printf("Changed 'First Event'   to: %u\n", Start ); }
+// Get fPixels and allocate array
+               Int_t *ARR = new Int_t[Frames*fPixels];
+               Float_t PEDESTAL;
+               Float_t NOISE;
+               Int_t PIXEL;
+
+               for(Int_t i=Start; i<Frames+Start;i++)
+               {
+                       getFrame(i);
+                       
+                       for(Int_t j=0; j<fPixels;j++)
+                       {
+                               ARR[(i-Start)*fPixels+j] = fCdsmatrix[j];
+                       }
+               }
+
+               
+               if(fSave)
+               {
+                       fNoiseTree->Branch("pixel"              , &PIXEL        , "pixel/i"             , 32000);
+                       fNoiseTree->Branch("noise"              , &NOISE        , "noise/F"             , 32000);
+                       fNoiseTree->Branch("pedestal"   , &PEDESTAL     , "pedestal/F"  , 32000);
+               }
+               
+               for(Int_t i=0; i<fPixels;i++)
+               {
+                       PEDESTAL        = 0;
+                       NOISE           = 0;
+                       
+                       for(Int_t j=0; j<Frames;j++)
+                       {
+                               PEDESTAL+=ARR[j*fPixels+i];
+                       }
+
+                       PEDESTAL = PEDESTAL/Frames;
+                       
+                       for(Int_t j=0; j<Frames;j++)
+                       {
+                               NOISE+=TMath::Power(ARR[j*fPixels+i]-PEDESTAL,2);
+                       }
+
+                       NOISE = TMath::Sqrt(NOISE/(Frames));
+                       
+                       fNoise[i]               = NOISE;
+                       fPedestals[i]   = PEDESTAL;
+                       PIXEL                   = i;
+                       
+                       if(fSave)       { fNoiseTree->Fill(); }
+               }
+               
+               cout<<"-----------------------"<<endl;
+                               
+               delete[] ARR;
+               fNoiseOk = true;
+               return true;
+       }
+       else
+       {
+                       return false;
+       }
+};
+
+//####################################################################
+
+bool MAPS::loadNoise( TString InDir, Int_t RunNumber, Int_t Matrix) {
+       
+       TString FILENAME = InDir+Form("%i/%i_%i.root",RunNumber,RunNumber,Matrix);
+       TFile *f = new TFile(FILENAME,"READ");
+       
+       if(f->IsZombie()) 
+       {
+               cerr<<"ERROR: loadNoise() failed!"<<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");
+               
+               UInt_t  PIXEL;
+               Float_t NOISE, PEDESTAL;
+               
+               noiseTree->SetBranchAddress("pixel"             , &PIXEL        );
+               noiseTree->SetBranchAddress("noise"             , &NOISE        );
+               noiseTree->SetBranchAddress("pedestal"  , &PEDESTAL     );
+               
+               Int_t entries           = noiseTree->GetEntries();
+               
+               for(Int_t i=0; i<entries; i++)
+               {
+                       noiseTree->GetEntry(i);
+                       
+                       fNoise[i]               = NOISE;
+                       fPedestals[i]   = PEDESTAL;
+               }
+               cout<<"-----------------------"<<endl;
+               fNoiseOk        = true;
+               fNoiseExt       = true;
+               return true;
+       }
+};
+
+//####################################################################
+
+bool MAPS::setNoise(Float_t Noise) {
+       
+       for(Int_t i=0; i<fPixels; i++)
+       {
+               fNoise[i]               = Noise;
+       }
+       
+       fNoiseOk = true;
+       return true;
+};
+
+//####################################################################
+
+bool MAPS::setPedestals(Float_t Pedestals) {
+       
+       for(Int_t i=0; i<fPixels; i++)
+       {
+               fPedestals[i]   = Pedestals;
+       }
+       
+//     fNoiseOk = true;
+       return true;
+};
+
+//####################################################################
+
+void MAPS::hitana() {
+
+       if(!fFrameOk)           {cout<<"\rNo frame loaded!      ";}
+       else if(!fNoiseOk)      {cout<<"Noise/Pedestals not set!"<<endl; exit(-1); }
+       else {
+
+//Local variables
+       TArrayI HITS;
+       Int_t HITNR = 0;
+       Int_t *Hitlist;
+       Int_t A;
+       Int_t B;
+       Int_t DUMMY=0;
+       Float_t CLUSTER[25];
+       Int_t CHANCE;
+       
+       for(Int_t i=0; i<fPixels; i++)
+       {
+               if( (float)(1.*fCdsmatrix[i]-fPedestals[i]) > (5.*fNoise[i]) )
+               {
+                       HITNR++;
+                       HITS.Set(HITNR);
+                       HITS.AddAt(i,(HITNR-1));
+                       
+                       if(fSave)       { hint2->Fill(i%fColumns, (int)(i/fColumns)); }
+               }
+       }
+
+//Rewrite HITS to fHitlist array
+       Hitlist= new Int_t[HITNR];
+       
+       for(Int_t i=0;i<HITNR;i++) 
+       {
+               Hitlist[i]=HITS.At(i); 
+       }
+
+//Begin: loop over all potential seed pixels:
+//Determine 'hit-vicinity':
+       fHits = 0;
+       
+       for(Int_t hit=0; hit<HITNR;hit++)
+       {
+               A = (Hitlist[hit])/fColumns;                    // A: row of seed
+               B = (Hitlist[hit])%fColumns;                    // B: column of seed
+               
+               // Consider boundaries => Remove hits where the seed pixel is within 2 pixels beside the edge
+               //  Hitlist[hit]%fColumn = x-coordinate of the seed pixel, Hitlist[hit]/fColumns = y-coordinate of the seed pixel
+               if (Hitlist[hit]%fColumns < 2 || Hitlist[hit]%fColumns > fColumns-3 || Hitlist[hit]/fColumns < 2 || Hitlist[hit]/fColumns > fRows-3)
+        continue;
+               
+//Provide 5x5 clusters with CDS - content:
+               for(Int_t row=0;row<5;row++)
+               {
+                       for(Int_t column=0;column<5;column++)
+                       {
+                               if                      ( (row==0) && (A<2) )                                   {CLUSTER[(row*5)+column]=DUMMY; }
+                               else if         ( (row==1) && (A<1) )                                   {CLUSTER[(row*5)+column]=DUMMY; }
+                               else if         ( (row==3) && (A>= (fRows-1)) )                 {CLUSTER[(row*5)+column]=DUMMY; }
+                               else if         ( (row==4) && (A>= (fRows-2)) )                 {CLUSTER[(row*5)+column]=DUMMY; }
+                               else
+                               {
+                                       if              ( (column==0) && (B<2) )                                {CLUSTER[(row*5)+column]=DUMMY; }
+                                       else if ( (column==1) && (B==0) )                               {CLUSTER[(row*5)+column]=DUMMY; }
+                                       else if ( (column==3) && (B==fColumns-1))               {CLUSTER[(row*5)+column]=DUMMY; }
+                                       else if ( (column==4) && (B>fColumns-3))                {CLUSTER[(row*5)+column]=DUMMY; }
+                                       else                                                                                    {CLUSTER[(row*5)+column] = 1.*fCdsmatrix [Hitlist[hit]+(row-2)*fColumns+(column-2)] - fPedestals [Hitlist[hit]+(row-2)*fColumns+(column-2)]; }
+                               }
+                       }
+               }
+
+//Check seeds (whether highest entry in cluster):
+               for(Int_t i=6;i<19;i++)
+               {
+                       if              ( (i!=12) && (CLUSTER[i] > CLUSTER[12]) )                               {CHANCE=0; break;}
+                       else if         ( (i!=12) && (CLUSTER[i] == CLUSTER[12]) && i>12 )              {CHANCE=0; break;}      //NOTE: potential error source
+                       else                                                                                                                            {CHANCE=100;  if(i%5==3) {i+=2;}; }
+               }
+
+//Begin: loop evaluate true seeds:
+               if(CHANCE==100)
+               {
+//Fill hit TTree:
+                       fFrameInfo.pixel[fHits] = Hitlist[hit];
+                       for(int clupos=0;clupos<25;clupos++)
+                       {
+                               fFrameInfo.p [clupos][fHits] = CLUSTER[clupos];
+                       }
+                       
+                       fHits++;
+                       
+                       if(fSave) { hint1->Fill( Hitlist[hit]%fColumns, (int)(Hitlist[hit]/fColumns) ); }
+               }
+       }
+//End: loop evaluate true seeds:
+//End: loop over all potential seed pixels:
+
+       if(fSave)
+       {
+               fFrameInfo.hits         = fHits;
+               if(fHits<100)
+               {
+                       fHitTree->Fill();
+               }
+               else
+               {
+                       cout<<"\rFrame: "<<fFrameNumber<<" not saved! Too many hits: "<<fHits<<endl;
+               }
+       }
+       
+       delete[] Hitlist;
+}}
+
+//####################################################################
+
+void MAPS::filterCommonMode() {
+       
+       Float_t CommonModeInRow = 0;
+//     Int_t   Count                   = 0;
+       bool warning                    = false; 
+       
+       Float_t* Arr = new Float_t[fColumns];
+       
+       for(int row=0; row<fRows; row++ )
+       {
+               CommonModeInRow = 0;
+//             Count                   = 0;
+               
+               for(int column=0; column<fColumns; column++ )
+               {
+//                     CommonModeInRow += fCdsmatrix[ row*fColumns+column ];
+                       Arr[column]              = fCdsmatrix[ row*fColumns+column ];
+               }
+               
+//             CommonModeInRow = CommonModeInRow/fColumns;
+               CommonModeInRow = TMath::Median(fColumns, Arr);
+//             cout<<CommonModeInRow<<endl;
+//             CommonModeInRow = 0;
+               if(TMath::Abs(CommonModeInRow)>100)
+               {
+                       warning = true;
+               }
+               
+               for(int column=0; column<fColumns; column++ )
+               {
+//                     cout<<CommonModeInRow<<"\t"<<fCdsmatrix[ row*fColumns+column ]<<"\t";
+                       fCdsmatrix[ row*fColumns+column ] = fCdsmatrix[ row*fColumns+column ] - CommonModeInRow;
+//                     cout<<fCdsmatrix[ row*fColumns+column ]<<endl;
+               }
+       }
+       
+       if(warning) { cout<<"\rFrame: "<<fFrameNumber<<" --> Common Mode suspiciously high!               "<<endl; }
+}
+
+//####################################################################
+
+void MAPS::plotFrame(Int_t FrameNumber) {
+       
+       if(!getFrame(FrameNumber)) {cout<<"Frame could not be loaded!"<<endl;}
+       else {
+
+       TCanvas* cm1;
+       cm1 = new TCanvas("cm1","Matrix",50,100,1200,800);
+       cm1->Divide(2,3);
+       gStyle->SetOptFit(1011);
+       gStyle->SetPalette(1);
+       gStyle->SetCanvasColor(0);
+       gStyle->SetFrameFillColor(10);
+       gStyle->SetOptStat(0);
+       
+       TH2F *h1  = new TH2F("CDS matrix", "CDS matrix",                        fColumns, 0, fColumns, fRows, 0, fRows);
+       TH2F *h2  = new TH2F("Frame 0 matrix", "Frame 0 matrix",        fColumns, 0, fColumns, fRows, 0, fRows);
+       TH2F *h3  = new TH2F("Frame 1 matrix", "Frame 1 matrix",        fColumns, 0, fColumns, fRows, 0, fRows);
+       TH1F *h4  = new TH1F("Frame 0 histo", "Frame 0 histo",          2*16384, -16384, 16384);
+       TH1F *h5  = new TH1F("Frame 1 histo", "Frame 1 histo",          2*16384, -16384, 16384);
+       
+       Int_t column;
+       Int_t row;
+       Float_t F0,F1,CDS;
+       
+       for(Int_t i=0; i<fPixels;i++)
+       {
+               row             = i/fColumns;
+               column  = i%fColumns;
+               
+               CDS     = fCdsmatrix[i];
+               F0      = fF0matrix[i];
+               F1      = fF1matrix[i];
+
+               h1->Fill(column,row,CDS);
+               h2->Fill(column,row,F0);
+               h3->Fill(column,row,F1);
+               h4->Fill(F0);
+               h5->Fill(F1);
+               
+       }
+
+       cm1->cd(1);
+       h1->Draw("colz");
+       h1->GetXaxis()->SetTitle("column");
+       h1->GetYaxis()->SetTitle("row");
+       h1->GetZaxis()->SetTitle("Signal [ADC]");
+
+       cm1->cd(2);
+       h1->Draw("surf2z");
+       h1->GetXaxis()->SetTitle("column");
+       h1->GetYaxis()->SetTitle("row");
+       h1->GetZaxis()->SetTitle("Signal [ADC]");
+       
+       cm1->cd(3);
+       h2->Draw("surf2z");
+       h2->GetXaxis()->SetTitle("column");
+       h2->GetYaxis()->SetTitle("row");
+       h2->GetZaxis()->SetTitle("Signal [ADC]");
+       
+       cm1->cd(4);
+       h3->Draw("surf2z");
+       h3->GetXaxis()->SetTitle("column");
+       h3->GetYaxis()->SetTitle("row");
+       h3->GetZaxis()->SetTitle("Signal [ADC]");
+       
+       cm1->cd(5);
+       h4->Draw();
+       h4->GetXaxis()->SetTitle("Signal [ADC]");
+       h4->GetYaxis()->SetTitle("Counts");
+       
+       cm1->cd(6);
+       h5->Draw();
+       h5->GetXaxis()->SetTitle("Signal [ADC]");
+       h5->GetYaxis()->SetTitle("Counts");
+
+       cm1->DrawClone();
+       cm1->Close();
+       cm1->Update();
+       cout<<"\rPIXELMATRIX plotted!                           "<<endl;
+       cout<<"-------------------"<<endl;
+       }
+}
+
+//####################################################################
+
+void MAPS::plotNoise() {
+
+       if(!fNoiseOk) {cout<<"Noise/Pedestals not calculated/set!"<<endl;}
+       else {
+       
+       TCanvas* cm2;
+       cm2 = new TCanvas("cm2","Noise",50,100,1200,800);
+       cm2->Divide(2,2);
+       gStyle->SetOptFit(1011);
+       gStyle->SetPalette(1);
+       gStyle->SetCanvasColor(0);
+       gStyle->SetFrameFillColor(10);
+       gStyle->SetOptStat(1);
+       
+       TH1F *h1  = new TH1F("noisee",                  "noise",                        2000, 0, 200);
+       TH1F *h2  = new TH1F("pedestal",                "pedestal",                     1000, -50, 50);
+       TH2F *h3  = new TH2F("noise matrix",    "noise matrix",         fColumns, 0, fColumns, fRows, 0, fRows);
+       TH2F *h4  = new TH2F("pedestal matrix", "pedestal matrix",      fColumns, 0, fColumns, fRows, 0, fRows);
+       
+       Int_t column;
+       Int_t row;
+       Float_t NOISE,PEDESTAL;
+       
+       for(Int_t i=0; i<fPixels;i++)
+       {
+               
+               column  = i%fColumns;
+               row             = i/fColumns;
+               NOISE           = fNoise[i];
+               PEDESTAL        = fPedestals[i];
+
+               h1->Fill(NOISE);
+               h2->Fill(PEDESTAL);
+               h3->Fill(column,row,NOISE);
+               h4->Fill(column,row,PEDESTAL);
+       }
+       
+       cm2->cd(1);
+       h3->Draw("colz");
+       h3->GetXaxis()->SetTitle("column");
+       h3->GetYaxis()->SetTitle("row");
+       h3->GetZaxis()->SetTitle("Noise [ADC]");
+       
+       cm2->cd(2);
+       h4->Draw("colz");
+       h4->GetXaxis()->SetTitle("column");
+       h4->GetYaxis()->SetTitle("row");
+       h4->GetZaxis()->SetTitle("Pedstals [ADC]");
+       
+       cm2->cd(3);
+       h1->Draw();
+       h1->GetXaxis()->SetTitle("Noise [ADC]");
+       h1->GetYaxis()->SetTitle("Counts");
+       
+       cm2->cd(4);
+       h2->Draw();
+       h2->GetXaxis()->SetTitle("Pedestal [ADC]");
+       h2->GetYaxis()->SetTitle("Counts");
+       
+       cm2->DrawClone();
+       cm2->Close();
+       cm2->Update();
+       cout<<"NOISE plotted!     "<<endl;
+       cout<<"-------------------"<<endl;
+       }
+}
+
+//####################################################################
+
+void MAPS::plotHitDis(Int_t Start, Int_t Frames) {
+       
+       if(fOk)
+       {
+//Check availabilty of Frames
+               if( Frames                      > fEventsSum )  { Frames = fEventsSum;                  printf("Changed 'Number Frames' to: %u\n", Frames ); }
+               if( Frames+Start        > fEventsSum )  { Start = fEventsSum-Frames;    printf("Changed 'First Event'   to: %u\n", Start ); }
+       }
+}
+
+//####################################################################
+
+void MAPS::plotSignal(Int_t Start, Int_t Frames) {
+
+       if(fOk)
+       {
+//Check availabilty of Frames
+               if( Frames                      > fEventsSum )  { Frames = fEventsSum;                  printf("Changed 'Number Frames' to: %u\n", Frames ); }
+               if( Frames+Start        > fEventsSum )  { Start = fEventsSum-Frames;    printf("Changed 'First Event'   to: %u\n", Start ); }
+               
+               TH2F *h1  = new TH2F("Frames 0 "                , "Frame 0"                     ,               fPixels, 0, fPixels, 2*16384, -16384, 16384);
+               TH2F *h2  = new TH2F("Frames 1"                 , "Frame 1"                     ,               fPixels, 0, fPixels, 2*16384, -16384, 16384);
+               TH2F *h3  = new TH2F("CDS"                              , "CDS"                         ,               fPixels, 0, fPixels, 2*16384, -16384, 16384);
+
+               TH1F *h4  = new TH1F("Frames 0 histo"   , "Frames 0 histo"      ,               2*16384, -16384, 16384);
+               TH1F *h5  = new TH1F("Frames 1 histo"   , "Frames 1 histo"      ,               2*16384, -16384, 16384);
+               TH1F *h6  = new TH1F("CDS histo"                , "CDS histo"           ,               2*16384, -16384, 16384);
+               
+               for(int i=Start;i<Start+Frames;i++)
+               {
+                       if(getFrame(i))
+                       {
+                               for(int j=0;j<fPixels;j++)
+                               {
+                                       h1->Fill(j,fF0matrix    [j]);
+                                       h2->Fill(j,fF1matrix    [j]);
+                                       h3->Fill(j,fCdsmatrix   [j]);
+                                       
+                                       h4->Fill(fF0matrix      [j]);
+                                       h5->Fill(fF1matrix      [j]);
+                                       h6->Fill(fCdsmatrix     [j]);
+                               }
+                       }
+               }
+               
+               
+               TCanvas* cm11;
+               cm11 = new TCanvas("cm11","Signal",50,100,1200,800);
+               cm11->Divide(3,2);
+               gStyle->SetOptFit(1011);
+               gStyle->SetPalette(1);
+               gStyle->SetCanvasColor(0);
+               gStyle->SetFrameFillColor(10);
+               gStyle->SetOptStat(0);
+       
+               cm11->cd(1);
+               h1->Draw("colz");
+               h1->GetXaxis()->SetTitle("Pixel#");
+               h1->GetYaxis()->SetTitle("Signal");
+               
+               cm11->cd(2);
+               h2->Draw("colz");
+               h2->GetXaxis()->SetTitle("Pixel#");
+               h2->GetYaxis()->SetTitle("Signal");
+               
+               cm11->cd(3);
+               h3->Draw("colz");
+               h3->GetXaxis()->SetTitle("Pixel#");
+               h3->GetYaxis()->SetTitle("Signal");
+               
+               cm11->cd(4);
+               h4->Draw();
+               h4->GetXaxis()->SetTitle("Signal [ADC]");
+               h4->GetYaxis()->SetTitle("Counts");
+               
+               cm11->cd(5);
+               h5->Draw();
+               h5->GetXaxis()->SetTitle("Signal [ADC]");
+               h5->GetYaxis()->SetTitle("Counts");
+               
+               cm11->cd(6);
+               h6->Draw();
+               h6->GetXaxis()->SetTitle("Signal [ADC]");
+               h6->GetYaxis()->SetTitle("Counts");
+
+               cm11->DrawClone();
+               cm11->Close();
+               cm11->Update();
+               cout<<"\rSIGNALS plotted!                           "<<endl;
+               cout<<"-------------------"<<endl;
+       }
+}
+
+//####################################################################
+
+void MAPS::plotPixSignal(Int_t Start, Int_t Frames, Int_t Pixel) {
+
+       if(fOk)
+       {
+//Check availabilty of Frames
+               TCanvas* cm4;
+               cm4 = new TCanvas("cm4","PixelSignal",50,100,1200,800);
+               cm4->Divide(3,2);
+               gStyle->SetOptFit(1011);
+               gStyle->SetPalette(1);
+               gStyle->SetCanvasColor(0);
+               gStyle->SetFrameFillColor(10);
+               gStyle->SetOptStat(0);
+               
+               if( Frames                      > fEventsSum )  { Frames = fEventsSum;                  printf("Changed 'Number Frames' to: %u\n", Frames ); }
+               if( Frames+Start        > fEventsSum )  { Start = fEventsSum-Frames;    printf("Changed 'First Event'   to: %u\n", Start ); }
+               
+               TH2F *h1  = new TH2F("Frame 0 vs T"             , "Frame 0 vs T"        ,               Frames, Start, Start+Frames, 2*16384, -16384, 16384);
+               TH2F *h2  = new TH2F("Frame 1 vs T"             , "Frame 1 vs T"        ,               Frames, Start, Start+Frames, 2*16384, -16384, 16384);
+               TH2F *h3  = new TH2F("CDS vs T"                 , "CDS vs T"            ,               Frames, Start, Start+Frames, 2*16384, -16384, 16384);
+
+               TH1F *h4  = new TH1F("Frames 0 phisto"  , "Frames 0 phisto"     ,               2*16384, -16384, 16384);
+               TH1F *h5  = new TH1F("Frames 1 phisto"  , "Frames 1 phisto"     ,               2*16384, -16384, 16384);
+               TH1F *h6  = new TH1F("CDS phisto"               , "CDS phisto"          ,               2*16384, -16384, 16384);
+               
+               for(int i=Start;i<Start+Frames;i++)
+               {
+                       if(getFrame(i))
+                       {
+                               h1->Fill( i,fF0matrix[Pixel]) ;
+                               h2->Fill( i,fF1matrix[Pixel]) ;
+                               h3->Fill( i,fCdsmatrix[Pixel] );
+                               
+                               h4->Fill( fF0matrix[Pixel] );
+                               h5->Fill( fF1matrix[Pixel] );
+                               h6->Fill( fCdsmatrix[Pixel] );
+                       }
+               }
+               
+               cm4->cd(1);
+               h1->Draw("colz");
+               h1->GetXaxis()->SetTitle("Frame#");
+               h1->GetYaxis()->SetTitle("Signal");
+
+               cm4->cd(2);
+               h2->Draw("colz");
+               h2->GetXaxis()->SetTitle("Frame#");
+               h2->GetYaxis()->SetTitle("Signal");
+
+               cm4->cd(3);
+               h3->Draw("colz");
+               h3->GetXaxis()->SetTitle("Frame#");
+               h3->GetYaxis()->SetTitle("Signal");
+
+               cm4->cd(4);
+               h4->Draw();
+               h4->GetXaxis()->SetTitle("Signal [ADC]");
+               h4->GetYaxis()->SetTitle("Counts");
+
+               cm4->cd(5);
+               h5->Draw();
+               h5->GetXaxis()->SetTitle("Signal [ADC]");
+               h5->GetYaxis()->SetTitle("Counts");
+
+               cm4->cd(6);
+               h6->Draw();
+               h6->GetXaxis()->SetTitle("Signal [ADC]");
+               h6->GetYaxis()->SetTitle("Counts");
+
+//             cm4->DrawClone();
+//             cm4->Update();
+//             cm4->Close();
+               cout<<"\rPIXELSIGNALS plotted!                           "<<endl;
+               cout<<"-------------------"<<endl;
+       }
+}
+
+//####################################################################
+
+void MAPS::writeData() {
+//     int file=1;
+// 
+//     TH1F *histo1[3];
+//     TH2F *histo2[3];
+//     
+//     histo1[0]  = new TH1F("F0 matrixh"      , "F0 matrixh",                         2*16384*4, -16384*4, 16384*4);
+//     histo1[1]  = new TH1F("F1 matrixh"      , "F1 matrixh",                         2*16384*4, -16384*4, 16384*4);
+//     histo1[2]  = new TH1F("CDS matrixh"     , "CDS matrixh",                        2*16384*4, -16384*4, 16384*4);
+//     
+//     histo2[0]  = new TH2F("F0 matrix"       , "F0 matrix",                          16, 0, 16, 64, 0, 64);
+//     histo2[1]  = new TH2F("F1 matrix"       , "F1 matrix",                          16, 0, 16, 64, 0, 64);
+//     histo2[2]  = new TH2F("CDS matrix"      , "CDS matrix",                         16, 0, 16, 64, 0, 64);
+//     
+// //          char* RAWDATA= new char[200];
+//             char* PARDATA= new char[4];
+//             
+//             fInn[file].seekg        ( 0                     , ios::beg      );
+// //          fInn[0].read    ( RAWDATA       , 200           );
+//             
+//             uint a;//,b;
+//             int16_t a1,a2;
+//             int16_t b1,b2;
+//             int x,y,z1,z2,z3;
+//             
+// //          for(int i=0;i<200/4;i++)
+// //          {
+// //                  
+// //                  a = TMath::Power(2,24)*(Int_t)RAWDATA[i]+TMath::Power(2,16)*(Int_t)RAWDATA[i+1]+TMath::Power(2,8)*(Int_t)RAWDATA[i+2]+TMath::Power(2,0)*(Int_t)RAWDATA[i+3];
+// //                  cout<<dec<<i<<"\t"<<a<<endl;
+// //          }
+//             
+//             int count               = 0;
+//             int count_tmp   = 0;
+//             
+//             int countframes = 0;
+//             int countinframe = 0;
+//             
+// 
+// 
+//             while( fInn[file].good() )
+//             {
+//                     fInn[file].read ( PARDATA       , 4);
+//                     
+//                     a       = littleEndian32(PARDATA,0);
+//                     a1      = littleEndian16(PARDATA,0);
+//                     a2      = littleEndian16(PARDATA,2);
+// //                  if(a1<0) {a2+=1;}
+//                     
+// 
+//                     
+// //                  b       = TMath::Power(2,0)*(Int_t)(Char_t)PARDATA[0] + TMath::Power(2,8)*(Int_t)(Char_t)PARDATA[1]+TMath::Power(2,16)*(Int_t)(Char_t)PARDATA[2] + TMath::Power(2,24)*(Int_t)(Char_t)PARDATA[3];
+// //                  b1      = TMath::Power(2,0)*(Int_t)(Char_t)PARDATA[0] + TMath::Power(2,8)*(Int_t)(Char_t)PARDATA[1];
+// //                  b2      = TMath::Power(2,0)*(Int_t)(Char_t)PARDATA[2] + TMath::Power(2,8)*(Int_t)(Char_t)PARDATA[3];
+//                     
+// //                  a1 = conv[a1];
+// //                  a2 = conv[a2];
+//                     
+//                     if(1)
+// //                  if(count==count_tmp+13)
+//                     {
+// //                          cout<<count%1053<<"\t"<<countframes<<endl;
+// //                          if( (count%1053)>=28 && (count%1053)<28+64*16 && countframes==11)
+//                                     if( (count%1053)>=28 && (count%1053)<28+64*16)
+//                             {
+//                                     y = ((count%1053)-28)%64;
+//                                     x = ((count%1053)-28)/64;
+//                                     
+//                                     z1 = a1;
+//                                     z2 = a2;
+//                                     z3 = a1-a2;
+//                                     
+//                                     histo1[0]->Fill(z1);
+//                                     histo1[1]->Fill(z2);
+//                                     histo1[2]->Fill(z3);
+//                                     
+//                                     histo2[0]->Fill(x,y,z1);
+//                                     histo2[1]->Fill(x,y,z2);
+//                                     histo2[2]->Fill(x,y,z3);
+//                                     
+// //                                  cout<< (count%1053)-28 <<"\t"<<x<<"\t"<<y<<"\t"<<z1<<endl;
+//                                     countinframe++;
+//                             }
+//                             
+//                             if(count<50 || (count>=1050 && count<1053+50))
+// //                          if( count%1053==13 )
+//                             {
+//                             cout<<right<<setw(5)<<dec<<count%1053;
+//                             cout<<right<<setw(5)<<dec<<count;
+// //                          cout<<right<<setw(10)<<hex<<a;
+//                             cout<<" | ";
+//                             for(int j=0;j<4;j++)
+//                             {
+//                                     for(int i=0;i<8;i++)
+//                                     {
+//                                             cout<<(( PARDATA[3-j] >> (7-i)) &   1);
+//                                     }
+//                                     if(1) {cout<<" ";}
+//                             }
+// //                          cout<<" ";
+// //                          cout<<right<<setw(10)<<hex<<a2;
+// //                          cout<<right<<setw(10)<<hex<<a1;
+// //                          cout<<right<<setw(10)<<dec<<a2;
+// //                          cout<<right<<setw(10)<<dec<<a1;
+// //                          cout<<right<<setw(10)<<dec<<a2-a1;
+//                             
+//                             int n=CHAR_BIT*sizeof(a);
+//                             n=32;
+//                             cout<<"| ";
+//                             for (int i=16;i<n;i++)
+//                             {
+//                                     if ( a2 & (1<<(n-1-i)) )        { printf("1"); }
+//                                     else                                            { printf("0"); }
+//                             }
+//                             cout<<" ";
+//                             for (int i=16;i<n;i++)
+//                             {
+//                                     if ( a1 & (1<<(n-1-i)) )        { printf("1"); }
+//                                     else                                            { printf("0"); }
+//                             }
+//                             cout<<" | ";
+//                             for (int i=0;i<n;i++)
+//                             {
+//                                     if ( a & (1<<(n-1-i)) )         { printf("1"); }
+//                                     else                                            { printf("0"); }
+//                             }
+//                             cout<<" | ";
+//                             for (int i=16;i<n;i++)
+//                             {
+//                                     if ( b2 & (1<<(n-1-i)) )        { printf("1"); }
+//                                     else                                            { printf("0"); }
+//                             }
+//                             cout<<" ";
+//                             for (int i=16;i<n;i++)
+//                             {
+//                                     if ( b1 & (1<<(n-1-i)) )        { printf("1"); }
+//                                     else                                            { printf("0"); }
+//                             }
+//                             cout<<" | ";
+//                             
+// //                          cout<<right<<setw(10)<<dec<<a2;
+// //                          cout<<right<<setw(10)<<dec<<a1;
+// //                          cout<<right<<setw(15)<<dec<<a;
+//                             
+// //                          cout<<right<<setw(10)<<dec<<(short)b2;
+// //                          cout<<right<<setw(10)<<dec<<(short)b1;
+//                             
+//                             cout<<endl;
+//                             }
+//                             if( (count%1053) == 0)
+//                             {
+//                                     countframes++;
+//                             }
+//                     }
+//             
+// //                  if(a==0x88aaccef)
+//                     if(a==0x89abcdef)
+//                     {
+// //                          cout<<count<<"\t"<<count-count_tmp<<endl;
+// //                          count_tmp=count;
+//                             countframes++;
+// //                          break;
+//                     }
+//                     
+//                     count++;
+//                     
+// //                  if(count==50) break;
+//             }
+//             cout<<right<<setw(10)<<hex<<a2;
+//             cout<<right<<setw(10)<<hex<<a1;
+//             cout<<right<<setw(10)<<hex<<a<<endl;
+//             cout<<dec<<countframes<<"\t"<<countinframe<<endl;
+//   
+//     TCanvas* cm;
+//     cm = new TCanvas("cc2","Matrix",50,100,1200,800);
+//     cm->Divide(3,2);
+//     gStyle->SetOptFit(1011);
+//     gStyle->SetPalette(1);
+//     gStyle->SetCanvasColor(0);
+//     gStyle->SetFrameFillColor(10);
+//     gStyle->SetOptStat(1);
+//     
+//     cm->cd(1);
+//     histo1[0]->Draw();
+//     histo1[0]->GetXaxis()->SetTitle("Signal [ADC]");
+//     histo1[0]->GetYaxis()->SetTitle("Entries");
+//     cm->Update();
+//     cm->cd(2);
+//     histo1[1]->Draw();
+//     histo1[1]->GetXaxis()->SetTitle("Signal [ADC]");
+//     histo1[1]->GetYaxis()->SetTitle("Entries");
+//     cm->Update();
+//     cm->cd(3);
+//     histo1[2]->Draw();
+//     histo1[2]->GetXaxis()->SetTitle("Signal [ADC]");
+//     histo1[2]->GetYaxis()->SetTitle("Entries");
+//     cm->Update();
+//     
+//     cm->cd(4);
+//     histo2[0]->Draw("colz");
+//     histo2[0]->GetXaxis()->SetTitle("column");
+//     histo2[0]->GetYaxis()->SetTitle("row");
+//     histo2[0]->GetZaxis()->SetTitle("Signal [ADC]");
+//     cm->Update();
+//     cm->cd(5);
+//     histo2[1]->Draw("colz");
+//     histo2[1]->GetXaxis()->SetTitle("column");
+//     histo2[1]->GetYaxis()->SetTitle("row");
+//     histo2[1]->GetZaxis()->SetTitle("Signal [ADC]");
+//     cm->Update();
+//     cm->cd(6);
+//     histo2[2]->Draw("colz");
+//     histo2[2]->GetXaxis()->SetTitle("column");
+//     histo2[2]->GetYaxis()->SetTitle("row");
+//     histo2[2]->GetZaxis()->SetTitle("Signal [ADC]");
+//     cm->Update();
+}
+
+//####################################################################
+//####################################################################
+
+UInt_t MAPS::littleEndian32(char* RawData, Int_t Pos) {
+       
+//     for(int j=3;j>=0;j--)
+//     {
+//             char a = RawData[j+Pos];
+//             
+//             int n=CHAR_BIT*sizeof(a);
+//             
+//             cout<<" | ";
+//             for (int i=0;i<n;i++)
+//             {
+//                     if ( a  & (1<<(n-1-i)) )        { printf("1"); }
+//                     else                                            { printf("0"); }
+//             }
+//     }
+//     cout<<right<<setw(20)<<
+//     (UInt_t)((Int_t)(UChar_t)RawData[3+Pos]*TMath::Power(2,24) + (Int_t)(UChar_t)RawData[2+Pos]*TMath::Power(2,16) + (Int_t)(UChar_t) RawData[1+Pos]*TMath::Power(2,8) + (Int_t)(UChar_t)RawData[0+Pos]);
+                       
+       return  (Int_t)(UChar_t)RawData[3+Pos]*TMath::Power(2,24) +
+                       (Int_t)(UChar_t)RawData[2+Pos]*TMath::Power(2,16) +
+                       (Int_t)(UChar_t)RawData[1+Pos]*TMath::Power(2,8) +
+                       (Int_t)(UChar_t)RawData[0+Pos];
+}
+       
+//####################################################################
+
+Short_t MAPS::littleEndian16(char* RawData, Int_t Pos) {
+       
+       return  (Int_t)(UChar_t)RawData[1+Pos]*TMath::Power(2,8) +
+                       (Int_t)(UChar_t)RawData[0+Pos];
+}
+
+//####################################################################
+
+void MAPS::reorderMi29a() {
+       
+       if( fMatrix>5 )
+       {
+               cerr<<"ERROR: "<<fMatrix<<". Matrix not found! Choose: 0 to 5 !"<<endl;
+               cerr<<"-----------------------"<<endl;
+               fRows           = 0;
+               fColumns        = 0;
+               fPixels         = 0;
+       }
+       else
+       {
+               Int_t ROWSSUB[6]        = {48,48,32,32,32,32};
+               Int_t OFFSET            = 0;
+               
+               for(Int_t i=0;i<fMatrix;i++)
+               {
+                       OFFSET+=ROWSSUB[i];
+               }
+               OFFSET = OFFSET*48;
+               
+               fRows   = ROWSSUB[fMatrix];
+               fColumns        = 48;
+               fPixels = fRows*fColumns;
+               
+               Int_t CDSMATRIX [fPixels];
+               Int_t F0MATRIX  [fPixels];
+               Int_t F1MATRIX  [fPixels];
+               
+               for(Int_t i=0;i<fPixels;i++)
+               {
+                       CDSMATRIX       [i] = fCdsmatrix[OFFSET+i];
+                       F0MATRIX        [i] = fF0matrix [OFFSET+i];
+                       F1MATRIX        [i] = fF1matrix [OFFSET+i];
+               }
+               
+               for(Int_t i=0;i<fPixels;i++)
+               {
+                       fCdsmatrix      [i] = CDSMATRIX [i];
+                       fF0matrix       [i] = F0MATRIX  [i];
+                       fF1matrix       [i] = F1MATRIX  [i];
+               }
+       }
+}
+
+//####################################################################
+
diff --git a/newCOMBI/MAPS.h b/newCOMBI/MAPS.h
new file mode 100644 (file)
index 0000000..c18f71c
--- /dev/null
@@ -0,0 +1,93 @@
+#include <help.h>
+
+class MAPS {
+
+private:
+               
+       TString         fInDir;
+       TString         fOutDir;
+       TString         fOrderCode;                     // If the pixel data is in wrong order use this. You have to implement the class which does the ordering
+       Int_t           fRunNumber;
+       Int_t           fPixelsData;            // Number of Pixels found in Raw Data
+       Int_t           fPixels;                        // Number of Pixels written to fCdsmatrix and used for analysis 
+       Int_t           fRows;
+       Int_t           fColumns;
+       Int_t           fMatrix;                        // Variable to be able to subdivide the Matric according to fOrderCode
+       Int_t           fEventsSum;
+       Int_t           fFile;
+       
+       Int_t           fFrameNumber;
+       bool            fOk;
+       bool            fSave;
+       bool            fFrameOk;
+       bool            fNoiseOk;
+       bool            fNoiseExt;
+       Float_t         HIT_tmp[29];
+               
+       Int_t*          fEvents;
+       Int_t*          fF0matrix;
+       Int_t*          fF1matrix;
+       Int_t*          fCdsmatrix;
+       Float_t*        fNoise;
+       Float_t*        fPedestals;
+               Int_t fHits;
+       
+       frameInfo fFrameInfo;// = new frameInfo;
+       
+       ifstream*       fInn;
+       TFile*          fOutputFile;
+       TTree*  fHitTree;
+       TTree*  fNoiseTree;
+       
+       TString fSystem;
+       
+       unsigned short int value1[0x100][0x100];
+       unsigned short int value2[0x100][0x100];
+       
+       TH2F*           hint1,*hint2;
+       bool            plotHint;
+       
+       UInt_t          littleEndian32(char* RawData, Int_t Pos);
+       Short_t         littleEndian16(char* RawData, Int_t Pos);
+       
+       void            initMapsRun( TString, TString, Int_t, Int_t, Int_t, TString, TString, Int_t, bool);
+       void            initSave();
+       bool            checkConf(UInt_t&, UInt_t&, Int_t&);
+       bool            checkDataFiles( Int_t );
+       bool            checkDataFile( UInt_t, UInt_t& );
+       void            filterCommonMode();
+       
+       void reorderMi29a();
+       
+public:
+       
+       MAPS    (void); 
+       MAPS    ( TString InDir, TString OutDir, Int_t RunNumber, Int_t Rows, Int_t Columns, TString System="USB", TString OrderCode="", Int_t Matrix=0, bool Save=1);
+       ~MAPS   (void);
+       
+       bool getFrame           (Int_t FrameNumber);
+       bool getNoise           (Int_t Start, Int_t Frames);
+       bool loadNoise          (TString InDir, Int_t RunNumber, Int_t Matrix=0);
+       bool setNoise           (Float_t Noise);
+       bool setPedestals       (Float_t Pedestals);
+       void hitana                     ();
+       
+       void plotNoise          (void);
+       void plotFrame          (Int_t FrameNumber);
+       void plotHitDis         (Int_t Start, Int_t Frames);
+       void plotSignal         (Int_t Start, Int_t Frames);
+       void plotPixSignal      (Int_t Start, Int_t Frames, Int_t Pixel);
+       
+       void writeData          ();
+       
+       Int_t                   GetNumberRun()                                  { return fRunNumber;                                    }
+       Int_t                   GetNumberFrames()                               { return fEventsSum;                                    }
+       Int_t                   GetNumberPixels()                               { return fPixels;                                               }
+       Int_t                   GetNumberRows()                                 { return fRows;                                                 }
+       Int_t                   GetNumberColumn()                               { return fColumns;                                              }
+       Int_t*                  GetCDSFrame()                                   { return fCdsmatrix;                                    }
+       Int_t*                  GetF0Frame()                                    { return fF0matrix;                                             }
+       Int_t*                  GetF1Frame()                                    { return fF1matrix;                                             }
+       Float_t*                GetNoise()                                              { return fNoise;                                                }
+
+};
\ No newline at end of file
diff --git a/newCOMBI/help.h b/newCOMBI/help.h
new file mode 100644 (file)
index 0000000..6ce53da
--- /dev/null
@@ -0,0 +1,112 @@
+#ifndef HELP_H
+#define HELP_H
+
+#include <iostream>
+#include <cstdlib>
+#include <unistd.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "TStopwatch.h"
+
+#define MAXHITS                        1000000
+
+//####################################################################
+
+Int_t print_progress(Float_t ProgressInPercent) {
+       
+       Int_t nCharacter = printf("\r [");
+       Int_t iBlock;
+       
+       for( iBlock=0; iBlock<ProgressInPercent/2; ++iBlock )
+       {
+               putchar( '=' );
+               nCharacter++;
+       }
+       
+       for( ; iBlock<100/2; ++iBlock )
+       {
+               putchar( ' ' );
+               nCharacter++;
+       }
+       
+//     Int_t sec       = TimeInSec%60;
+//     Int_t min       = TimeInSec/60;
+//     Int_t hours     = TimeInSec/3600;
+       
+       nCharacter += printf( "] %4.0f%%", ProgressInPercent);
+       fflush( stdout );
+       
+       if((Int_t)ProgressInPercent==100) 
+       {
+               printf("\r");
+               for(Int_t i=0; i<nCharacter; i++)
+               {
+                       putchar( ' ' );
+               }
+               printf("\r ... done! \n");
+       }
+       
+       return nCharacter;
+}
+
+//####################################################################
+
+Int_t print_progress(Float_t ProgressInPercent, Int_t TimeInSec) {
+       
+       Int_t nCharacter = printf("\r [");
+       Int_t iBlock;
+       
+       for( iBlock=0; iBlock<ProgressInPercent/2; ++iBlock )
+       {
+               putchar( '=' );
+               nCharacter++;
+       }
+       
+       for( ; iBlock<100/2; ++iBlock )
+       {
+               putchar( ' ' );
+               nCharacter++;
+       }
+       
+       Int_t sec       = TimeInSec%60;
+       Int_t min       = TimeInSec/60;
+       Int_t hours     = TimeInSec/3600;
+       
+       nCharacter += printf( "] %6.2f%% \t %3i:%02i:%02i   ", ProgressInPercent, hours, min, sec );
+       fflush( stdout );
+       
+       if(ProgressInPercent==100) 
+       {
+               printf("\r");
+               for(Int_t i=0; i<nCharacter; i++)
+               {
+                       putchar( ' ' );
+               }
+               printf("\r ...done! \t ( %i:%02i:%02i ) \n", hours, min, sec );
+       }
+       
+       return nCharacter;
+}
+
+//####################################################################
+
+struct frameInfo{
+// --From Header File--
+       UInt_t evno;
+       UInt_t evpos;
+//     UInt_t evdate;
+//     UInt_t evtime;
+//     UInt_t evtimes;
+//     UInt_t evtimems;
+       
+// --Data and Analysis--
+       UInt_t  frame;
+       UInt_t  hits;   
+       UInt_t  pixel           [MAXHITS];
+       Float_t p               [25][MAXHITS];
+};
+
+//####################################################################
+#endif
\ No newline at end of file
diff --git a/newCOMBI/run.C b/newCOMBI/run.C
new file mode 100755 (executable)
index 0000000..3063ddc
--- /dev/null
@@ -0,0 +1,82 @@
+#include"MAPS.C"
+
+void run()
+{
+//-------------------------------------------------------
+//-------------------------------------------------------
+/*     TString path            = "/jspc53_U/PXI-System/";
+       Int_t   runnumber       = 34509;
+       Int_t   rows            = 16;
+       Int_t   columns         = 64;
+       TString system          = "PXI";
+       TString ordercode       = "";
+       Int_t   matrix          = 0;
+       bool    save            = 1;
+       
+       bool    loadNoise               = false;
+       Int_t   runnumberNoise  = 29020; */
+//-------------------------------------------------------
+//-------------------------------------------------------
+       TString path            = "/jspc12_F/Mi32/";
+       TString outpath         = "/d/salt/data_recovered/maps/DennisDoering/root/Analysedata/";
+       Int_t   runStart        = 341252;
+       Int_t   rows            = 8;
+       Int_t   columns         = 64;
+       TString system          = "USB";
+       TString ordercode       = "";
+       Int_t   matrix          = 0;
+       bool    save            = 1;
+       
+       bool    loadNoise       = false;
+       Int_t   runnumberNoise  = 29020;
+       
+//-------------------------------------------------------      
+//-------------------------------------------------------
+       ULong_t progress_tmp=-1;
+       Float_t progress;
+//-------------------------------------------------------
+for(Int_t runLauf=0;runLauf<9;runLauf++)
+       {
+        Int_t runnumber = runStart+runLauf;
+               if(loadNoise)
+               {
+                       MAPS *aa = new MAPS(path,outpath,runnumberNoise,rows,columns,system,ordercode,matrix,save);
+                       aa->getNoise(0,1000);
+                       delete aa;
+               }
+
+               MAPS *a = new MAPS(path,outpath,runnumber,rows,columns,system,ordercode,matrix,save);
+               
+               if(loadNoise)
+               {
+                       a->loadNoise    (outpath, runnumberNoise, matrix);
+               }
+               else
+               {
+                       a->getNoise             (0,1000);
+               }
+               
+               int start       = 0;
+               int entries     = a->GetNumberFrames();
+       //      entries = 4;
+               
+               for(int i=start; i<entries;i++)
+               {
+                       a->getFrame(i);
+                       a->filterCommonMode();
+                       a->hitana();
+                       
+                       progress = (Int_t)(((i-start)*100)/(entries-1)*10);
+                       if(progress!=progress_tmp)      { print_progress( (((i-start)*100.)/(entries-1)) ); progress_tmp=progress;}
+               }
+       //      a->getFrame(58879);
+       //      a->getFrame(58880);
+       //      a->getFrame(60319);
+       //      a->getFrame(60320);
+       //      a->getFrame(60321);
+               
+               delete a;
+       //-------------------------------------------------------
+               cout<<entries<<endl;
+       }
+}