// File: hrichpedrawnew.cc // // Author: Angelika Elhardt // Last update by Angelika Elhardt: 01/01/09 18:37:00 // last modified by W.Schoen: 2000/11/08 // Modified by: martin.jurkovic@ph.tum.de 2005/09/11 using namespace std; #include #include #include #include #include "hevent.h" #include "hcategory.h" #include "hdetgeompar.h" #include "hlocation.h" #include "hmatrixcatiter.h" #include "hruntimedb.h" #include "hspectrometer.h" #include "hrichcalpar.h" #include "hrichcalparcell.h" #include "richdef.h" #include "hrichdetector.h" #include "hrichgeometrypar.h" #include "hrichmappingpar.h" #include "hrichpedrawnew.h" #include "hrichraw.h" ClassImp(HRichPedRawNew) HRichPedRawNew::HRichPedRawNew(Text_t *name, Text_t *title, Char_t *path, Char_t *pString) : HReconstructor(name,title) { pedPathName = path; strcpy(sectorList, pString); numSec = strlen(sectorList); pRichRaw = 0; pIter = 0; sectorMax = 6; rowMax = 90; colMax = 92; hardwareMax = 17464; size = 6.; // for finding runaways in meanAndSigma! epsilon = 0.001; channels = 2; sigmaTransformation = kFALSE; if(numSec > sectorMax) { cout<<"!!!!!!!!!!!!!!!!!!!!!!!"< 47 && b < 55)) { cout << "Attention!!! " <Fill(j, k, pStat[sIx][j][k]); runAwayHisto[i]->Fill(j, k, pRunAway[sIx][j][k]); meanHisto[i]->Fill(j, k, pMean[sIx][j][k]); Float_t radikand = pSigma[sIx][j][k] * countArray[sIx][j][k]; if(radikand < 0.0) { sigmaHisto[i]->Fill(j, k, 20000.0); cout << " !2D! numerical problem occured "<getCol(hardwarenumber); } Int_t HRichPedRawNew::getRow(Int_t hardwarenumber) { fMappingPar=gHades->getRuntimeDb()->getContainer("RichMappingParameters"); return((HRichMappingPar*) fMappingPar)->getRow(hardwarenumber); } void HRichPedRawNew::uipFile() { TFile *pFile = new TFile("uipfile_new.root", "read", "Testfile", 1); if(pFile){ vec3 = (TVector*) pFile->Get("uip"); //retrieve object from file vec5 = (TVector*) pFile->Get("pads_x"); //and keyname vec6 = (TVector*) pFile->Get("pads_y"); } else cout << "problems opening uipfile" << endl; } void HRichPedRawNew::bookCanvases() { } void HRichPedRawNew::calculate() { HRichRaw *pRaw = NULL; Bool_t kData = kFALSE; pIter->Reset(); while((pRaw = (HRichRaw *) pIter->Next())) { kData = kTRUE; Int_t sec = pRaw->getSector(); Float_t fCharge = pRaw->getCharge(); Int_t iRow = pRaw->getRow(); Int_t iCol = pRaw->getCol(); if(mask[sec][0] == 1) { if(iRow < rowMax && iCol < colMax) { Int_t sIx = mask[sec][1]; meanAndSigma(sIx, iCol, iRow, fCharge); countArray[sIx][iCol][iRow]++; pStat[sIx][iCol][iRow] = pStat[sIx][iCol][iRow] + 1; } else { cout << "Warning: impossible Pad numbers: row: " << iRow << " col: " << iCol << " charge: " << fCharge << endl; } } } if (kData) nCounter++; } void HRichPedRawNew::initializeMeanSigma() { for(Int_t i = 0; i < sectorMax; i++) { for(Int_t j = 0; j < colMax; j++) { for(Int_t k = 0; k < rowMax; k++) { pDiff[i][j][k] = 0.0; pMean[i][j][k] = 0.0; pSigma[i][j][k] = 0.0; } } } } void HRichPedRawNew::meanAndSigma(Int_t sIx, Int_t col, Int_t row, Float_t charge) { // !! das hier berechnete sigma ist die Varianz !! // !! in fill2DHistos wird aus der Varianz, die sigma heisst, sigma berechnet Double_t nEv = (Double_t) countArray[sIx][col][row]; Double_t sigma = sqrt(pSigma[sIx][col][row] * nEv); if(nEv > 5.0 && fabs(pMean[sIx][col][row] - charge) >= size * sigma + epsilon && fabs(pMean[sIx][col][row] - charge) > channels ) { // "nEv>5." to avoid numerical problems pRunAway[sIx][col][row]++; countArray[sIx][col][row]--; } else{ pDiff[sIx][col][row] = ((Double_t) charge - pMean[sIx][col][row]) / (nEv+1.); pMean[sIx][col][row] = pMean[sIx][col][row] + pDiff[sIx][col][row]; pSigma[sIx][col][row] = (nEv==0.) ? 0.0 : ((nEv-1.) / (nEv+1.)) * pSigma[sIx][col][row] + pDiff[sIx][col][row] * pDiff[sIx][col][row]; } } void HRichPedRawNew::outputFile() { Char_t fileName[128]; Char_t * extPed = "ped"; Char_t * extRoot = ".root"; strcpy(fileName, pedPathName); strcat(fileName, "_"); strcat(fileName, extPed); strcat(fileName, extRoot); dataFile = new TFile(fileName, "RECREATE"); for(Int_t i = 0; i < sectorMax; i++) { if(mask[i][0] == 1) { meanHisto[i]->Write(); mean1dHisto[i]->Write(); sigmaHisto[i]->Write(); sigma1dHisto[i]->Write(); statHisto[i]->Write(); runAwayHisto[i]->Write(); } } dataFile->Close(); cout << "Histos are written to: " << fileName << endl; } Bool_t HRichPedRawNew::init() { if(checkInput) { fillMask(); bookHistos(); HRichDetector *pRichDet = (HRichDetector*) gHades->getSetup()->getDetector("Rich"); pRichRaw=gHades->getCurrentEvent()->getCategory(catRichRaw); if (!pRichRaw) { pRichRaw=pRichDet->buildCategory(catRichRaw); if (!pRichRaw) return kFALSE; else gHades->getCurrentEvent() ->addCategory(catRichRaw, pRichRaw, "Rich"); } pIter = (HMatrixCatIter*) pRichRaw->MakeIterator(); //uipFile(); initMappingPar(); initCalPar(); nCounter = 0; } return kTRUE; } Int_t HRichPedRawNew::execute() { if(checkInput) { calculate(); } return kTRUE; } Bool_t HRichPedRawNew::finalize(void) { if(checkInput) { cout << "We are in finalize!" << endl; fill2DHistos(); if(sigmaTransformation) { fill1DHistos(); outputFile(); createPedestal(); createCalibration(); fillCalParCntr(); } } return kTRUE; } void HRichPedRawNew::initMappingPar() { HRuntimeDb* rtdb=gHades->getRuntimeDb(); fMappingPar = rtdb->getContainer("RichMappingParameters"); } void HRichPedRawNew::initCalPar() { HRuntimeDb* rtdb = gHades->getRuntimeDb(); fCalPar = rtdb->getContainer("RichCalPar"); if(!fCalPar) { cerr << "HRichPedRawNew::initCalPar: couldn't initialise containers, abording" << endl; exit(EXIT_FAILURE); } // if (fCalPar) { // ((HRichCalPar*)fCalPar)-> // setSetup(pRichDet->getSectors(), // pRichDet->getRows(), // pRichDet->getColumns()); // } } Bool_t HRichPedRawNew::fillCalParCntr() { initCalPar(); HLocation loc; HRichCalParCell *pCell = 0; loc.setNIndex(3); Int_t n = 0; for(Int_t k = 0; k < sectorMax; k++) { for (Int_t i = 0; i < colMax; i++) { for (Int_t j = 0; j < rowMax; j++) { if(mask[k][0] == 1){//valid sectors // cout<<"valid Sector "<getSlot(loc); if (pCell) { pCell = new (pCell) HRichCalParCell; pCell->setSector(k); pCell->setRow(j); pCell->setCol(i); pCell->setSlope(1); pCell->setOffset(pMean[sIx][i][j]); pCell->setSigma(pSigma[sIx][i][j]); n++; } else { cerr << "Error in HRichPedRawNew::fillCalParCntr" << endl; Error("fillCalParCntr(void)", "slot not found: %i %i %i", loc[0], loc[1], loc[2]); return kFALSE; } } } } // cout<<"Number of CalParCells allocated : "<getObject(loc); cout << "Location: " << loc[0] << " " << loc[1] << " " << loc[2] << " : " << calparcell->getSlope() << " : " << calparcell->getOffset() << " : " << calparcell->getSigma() << endl; } } } } } void HRichPedRawNew::createPedestal() { Char_t pedestalFile[128]; // filename and path! Char_t * appSec[6] = {"1","2","3","4","5","6"}; Int_t rc, tmp, port, mod, ch, x, y; rc = tmp = port = mod = ch = x = y = 0; Int_t iCount, hardware; iCount=hardware = 0; HRuntimeDb* rtdb = gHades->getRuntimeDb(); fMappingPar = rtdb->getContainer("RichMappingParameters"); for(Int_t i = 0; i < sectorMax; i++) { // max. 6 sectors if(mask[i][0] == 1) { Int_t sIx = mask[i][1]; strcpy(pedestalFile, pedPathName); strcat(pedestalFile, "_"); strcat(pedestalFile, appSec[i]); strcat(pedestalFile, ".dat"); cout << "------------------------------------------" <isValidUpi(hardware)) { pedestalOut << rc << " " << port << " " << mod << " " << ch << " " << pMean[sIx][x][y] << " " << pSigma[sIx][x][y] << endl; } else { if(((HRichMappingPar*) fMappingPar)->isUnConnCh(hardware)) { pedestalOut << rc << " " << port << " " << mod << " " << ch << " " << "1023" << " " << "0" << endl; } } } } iCount++; if(iCount == 16) { iCount = 0; j = j + 84; } } pedestalOut.close(); } } } void HRichPedRawNew::createCalibration() { Char_t *extPed = ".txt"; Char_t calFile[128]; // filename and path! strcpy(calFile, pedPathName); strcat(calFile, "_cal"); strcat(calFile, extPed); cout << "--------------------------------------------" << endl; cout << "calibration file written: " << endl; cout << "fileName: " << calFile << endl; ofstream calOut(calFile, ios::out); if(!calOut) { cerr << "Error: unable to open " << calFile << endl; exit(EXIT_FAILURE); } calOut << "# ASCII calibration file" << endl << endl << endl; calOut << "[ Rich Calibrater Parameters Setup ]" << endl << endl; calOut << "Sectors Rows Columns"<< endl; calOut << sectorMax<<" "<