From: Benjamin Linnik Date: Mon, 2 Mar 2015 19:18:16 +0000 (+0100) Subject: Run analyzer: Code cleanup X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=4be9788e228c2fd684f41eae1c1932df28d8087b;p=radhard.git Run analyzer: Code cleanup --- diff --git a/MABS_run_analyzer/ChargeSpektrum.c b/MABS_run_analyzer/ChargeSpektrum.c index 6c1cf09..62d2b70 100644 --- a/MABS_run_analyzer/ChargeSpektrum.c +++ b/MABS_run_analyzer/ChargeSpektrum.c @@ -42,7 +42,7 @@ void ChargeSpektrum() cout << "Found " << numberRuns << " run(s) in 'runlist.txt'." << endl; for(Int_t runi=0;runiBranch("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<<"-----------------------"<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<<"-----------------------"<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 : "<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<<"-----------------------"<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!"<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 << "!"<SetBranchAddress("noise" , &NOISE ); noiseTree->SetBranchAddress("pedestal" , &PEDESTAL ); diff --git a/MABS_run_analyzer/MAPS.h b/MABS_run_analyzer/MAPS.h index 19842e2..23625b4 100644 --- a/MABS_run_analyzer/MAPS.h +++ b/MABS_run_analyzer/MAPS.h @@ -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 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 -// 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 diff --git a/MABS_run_analyzer/Run.c b/MABS_run_analyzer/Run.c index 2e52091..e172746 100644 --- a/MABS_run_analyzer/Run.c +++ b/MABS_run_analyzer/Run.c @@ -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; frameifHitTree->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; hitifFrameInfo.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; clustericlustersize*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 + } + } } } diff --git a/MABS_run_analyzer/Run.h b/MABS_run_analyzer/Run.h index 3eebd9e..fbfee1d 100644 --- a/MABS_run_analyzer/Run.h +++ b/MABS_run_analyzer/Run.h @@ -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