/** * Add a triplet to the factory */ void RDFStoreFactory::addTriplet(uint subject, uint predicat, uint object){ bool isConcept = false; if(predicat==0) isConcept = true; /** * Diff with previous values */ bool isDifferentSubject = (previousSubject!=subject || BpCurrentIndex==0); bool isDifferentPredicat = (previousPredicat!=predicat || BpCurrentIndex==0); bool isDifferentObject = (previousObject!=predicat || BcCurrentIndex==0); testParameters(subject, predicat, object, isConcept, isDifferentSubject, isDifferentPredicat, isDifferentObject); /** * Update the previous value */ if(isDifferentSubject) previousSubject = subject; if(isDifferentPredicat) previousPredicat = predicat; if(isDifferentObject) previousObject = object; /** * Only if its a different predicat, we add it to the first layer */ if(isDifferentPredicat){ // Subjects Bitmap Bp->setBit(BpCurrentIndex++, isDifferentSubject); // Predicats Tree WTp->setField(WTpCurrentIndex++, predicat); } /** * For each triplet an object is added */ // Objects Bitmap Bo->setBit(BoCurrentIndex++, isDifferentPredicat); // Concept Bitmap Bc->setBit(BcCurrentIndex++, isConcept); // Concept or Instance Tree if(isConcept) WToc->setField(WTocCurrentIndex++, object); else WToi->setField(WToiCurrentIndex++, object); }
int eff(){ cout << "Starting Efficency Script" << endl; cout << "Usage: eff( module_name_string , starting_hr_file_string )" << endl; cout << "for defaults enter \"hr\" for starting hr file designator. " << endl; char chpath[256]; getcwd(chpath, 255); std::string path = chpath; std::string mod("paxxx");//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //if( newmod != "" ) mod = newmod; // <<<<<< change folder/module name to run in //std::string mod("yhc691015sn3p35"); std::string dataPath = path + "/" + mod + "data"; //std::string measurementFolder = mod + "data"; //std::string configPath = path + "/" + mod; std::string configPath = path; std::string HighRateSaveFileName( "Results_Hr" ); std::string HighRateFileName( "hr" );//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< //if( fileDesg != "" ) HighRateFileName = fileDesg; int namelength = HighRateFileName.length(); // <<<<<<<<<<<<<<<<<<< change Highrate File name to use // assumes something like hr08ma_pa225_082715.root // 10 or 08 or 06 or 04 or 02 required after hr // -- looks for a root file with "HighRateFileName" followed by 10 or 08 or ect.... // -- so will parse hr10****.root and hr08**********.root ect... with above settings std::string moduleName = mod; std::string maskFileName("defaultMaskFile.dat"); //phrun files here std::string phLowName("dc05_mn325_0503.root"); std::string phHighName("dc15_mn325_0503.root"); // const bool FIDUCIAL_ONLY = true; // don't change const bool VERBOSE = true; int nTrigPerPixel = 50; // will be read from testParameters.dat int nPixels = 4160; int nTrig = nTrigPerPixel * nPixels; float pixelArea = 0.01 * 0.015; // cm^2 float triggerDuration = 25e-9; //s const int nRocs = 16; const int nDCol = 25; double worstDCol[nRocs]; for( int i = 0; i<nRocs; i++) worstDCol[i] = -1; double worstDColEff[nRocs]; for( int i = 0; i<nRocs; i++) worstDColEff[i] = 10; double bestDCol[nRocs]; for( int i = 0; i<nRocs; i++) bestDCol[i] = -1; double bestDColEff[nRocs]; for( int i = 0; i<nRocs; i++) bestDColEff[i] = 10; double lowestdceff = 10; int lowestdc = -1; int lowestroc = 25; double highdceff = -10; int highdc = -1; int highroc = 25; std::string directoryList = mod; std::string outFileName = dataPath + "/" + HighRateFileName + "Efficiency.log"; std::ofstream log(outFileName.c_str()); cout << "search for HREfficiency folders in elComandante folder structure" << endl; log << "High Rate Efficency Log File Module: "<< mod << endl << endl; TSystemDirectory dir(dataPath.c_str(), dataPath.c_str()); TList *files = dir.GetListOfFiles(); std::vector<std::string> fileList; if (files) { TSystemFile *file; TString fname; TIter next(files); while (file=(TSystemFile*)next()) { fname = file->GetName(); std::cout << fname << endl; std::string filename = fname.Data(); if (filename.substr(0,namelength) == HighRateFileName ) { if( filename.substr(( filename.length() - 4 ), 4) == "root" ){ fileList.push_back(filename); std::cout << "---Added to fileList" << endl; } } } } std::vector<double> ylist; ylist.push_back(0.05); ylist.push_back(0.10); ylist.push_back(0.15); // ylist.push_back(0.15); // ylist.push_back(0.15); std::cout << " Declaring vectors" << endl; std::vector< std::vector< std::pair< int,int > > > maskedPixels; std::vector< std::vector< double > > efficiencies; std::vector< std::vector< double > > efficiencyErrors; std::vector< std::vector< double > > rates; std::vector< std::vector< double > > rateErrors; std::vector< double > hitslow; std::vector< double > hitshigh; std::vector< double > efflow; std::vector< double > effhigh; std::vector< double > DCUni; std::vector< double > DCUniNum; // std::vector< std::vector< std::vector< double > > > byAmpEfficiencies; // std::vector< std::vector< std::vector< double > > > byAmpEfficiencyErrors; // std::vector< std::vector< std::vector< double > > > byAmpRates; // std::vector< std::vector< std::vector< double > > > byAmpRateErrors; std::vector< std::vector< std::vector< double > > > dcolHits; std::vector< std::vector< std::vector< double > > > dcolHitErrors; std::vector< std::vector< std::vector< double > > > dcolRates; std::vector< std::vector< std::vector< double > > > dcolRateErrors; std::vector< std::vector< std::vector< double > > > dcolEff; std::vector< std::vector< std::vector< double > > > dcolEffErrors; std::vector< std::vector< double > > lineList; std::vector<std::vector<double>> dclineList; std::vector< std::vector< double > > bigempty; std::vector< double > empty; std::cout << " Line Lists" << endl; for( int i=0; i <4; i++ ){ lineList.push_back(empty); dclineList.push_back(empty); } for( int i = 0; i<201;i++){ lineList[1].push_back(.98); lineList[0].push_back(i); } for( int i = 0; i<= 100; i++ ){ lineList[3].push_back(i/100); lineList[2].push_back(120.0); } for( int i = 0; i <= 450; i++){ dclineList[1].push_back(1.5); dclineList[0].push_back(i); dclineList[3].push_back(0.6); dclineList[2].push_back(i); } // std::cout << "byamp inits" << endl; /* for (int i=0;i<=5;i++){ byAmpEfficiencies.push_back(bigempty); byAmpEfficiencyErrors.push_back(bigempty); byAmpRates.push_back(bigempty); byAmpRateErrors.push_back(bigempty); } */ // std::cout << "initilizing 2 tier" << endl; /* for( int i=0; i<=5; i++){ for( int j=0;j<=nRocs;j++){ byAmpEfficiencies[i].push_back(empty); byAmpEfficiencyErrors[i].push_back(empty); byAmpRates[i].push_back(empty); byAmpRateErrors[i].push_back(empty); } } */ //std::cout << "initilizing vectors" << endl; for (int i=0;i<=nRocs;i++) { efficiencies.push_back(empty); efficiencyErrors.push_back(empty); rates.push_back(empty); rateErrors.push_back(empty); dcolHits.push_back(bigempty); dcolHitErrors.push_back(bigempty); dcolRates.push_back(bigempty); dcolRateErrors.push_back(bigempty); dcolEff.push_back(bigempty); dcolEffErrors.push_back(bigempty); } int dc98count[nRocs][nDCol]; int dc95count[nRocs][nDCol]; int totdc98 = 0; int totdc95 = 0; int dc08count[nRocs][nDCol]; int dc12count[nRocs][nDCol]; int totdc08 = 0; int totdc12 = 0; int dcbothcount[nRocs][nDCol]; int totdcboth = 0; for( int i=0; i<nRocs; i++){ for( int j=0; j<nDCol; j++){ dc98count[i][j] = 0; dc95count[i][j] = 0; dc08count[i][j] = 0; dc12count[i][j] = 0; dcbothcount[i][j] = 0; } } for( int i=0; i<=nRocs; i++){ for( int j=0; j<=nDCol; j++){ dcolHits[i].push_back(empty); dcolHitErrors[i].push_back(empty); dcolRates[i].push_back(empty); dcolRateErrors[i].push_back(empty); dcolEff[i].push_back(empty); dcolEffErrors[i].push_back(empty); } } std::cout << "loop over all commander_HREfficiency.root root files" << endl; for (int i=0;i<1;++i) { chdir(path.c_str()); std::cout << "looking in directory <" << directoryList << ">" << std::endl; std::cout << "From " << path << endl; std::string parmFile = directoryList + "/testParameters.dat"; cout << "For " << parmFile << endl; std::ifstream testParameters(parmFile.c_str()); std::string line2; cout << "Getting line" << endl; while (getline(testParameters, line2)) { cout << line2 << endl; if (line2.find("HighRate") != std::string::npos) { while (getline(testParameters, line2)) { if (line2.size() < 1) break; size_t pos = line2.find("Ntrig"); std::cout << line2 << " " << pos << endl; if (pos != std::string::npos) { nTrigPerPixel = atoi(line2.substr(pos+6).c_str()); nTrig = nTrigPerPixel * nPixels; std::cout << ">" << line2 << "< pos:" << pos << std::endl; std::cout << "number of triggers per pixel: " << nTrigPerPixel << std::endl; } } } } testParameters.close(); // read masked pixels maskedPixels.clear(); for (int j=0;j<nRocs;j++) { std::vector< std::pair<int,int> > rocMaskedPixels; maskedPixels.push_back(rocMaskedPixels); } std::ifstream maskFile; char maskFilePath[256]; sprintf(maskFilePath, "%s/%s/%s", path.c_str(), directoryList.c_str(), maskFileName.c_str()); maskFile.open(maskFilePath, std::ifstream::in); if (!maskFile) { std::cout << "ERROR: mask file <" << maskFilePath << "> can't be opened!"<<std::endl; } std::string line; std::vector< std::string > tokens; while(getline(maskFile, line)) { if (line[0] != '#') { std::stringstream ss(line); std::string buf; tokens.clear(); while (ss >> buf) { tokens.push_back(buf); } std::cout << "tok0 <" << tokens[0] << "> "; if (tokens[0] == "pix" && tokens.size() >= 4) { int roc = atoi(tokens[1].c_str()); int col = atoi(tokens[2].c_str()); int row = atoi(tokens[3].c_str()); std::cout << "mask pixel " << roc << " " << col << " " << row << std::endl; maskedPixels[roc].push_back(std::make_pair(col, row)); } } } maskFile.close(); }
int efficiency(char* path0) { char the_path[256]; getcwd(the_path, 255); std::string path(path0); unsigned found = path.find_last_of("/\\", path.size()-2); std::string dataPath(path.substr(0,found)); std::string measurementFolder(path.substr(found+1)); std::stringstream ss1(measurementFolder); std::string moduleName; std::getline(ss1, moduleName, '_'); std::string rootFileName("commander_HREfficiency.root"); std::string maskFileName("defaultMaskFile.dat"); const bool FIDUCIAL_ONLY = true; const bool VERBOSE = true; int nTrigPerPixel = 50; int nPixels = 4160; int nTrig = nTrigPerPixel * nPixels; float pixelArea = 0.01 * 0.015; // cm^2 float triggerDuration = 25e-9; //s int nRocs = 16; //search for XrarSpectrum folders in elComandante folder structure TSystemDirectory dir(path.c_str(), path.c_str()); TList *files = dir.GetListOfFiles(); std::vector<std::string> directoryList; if (files) { TSystemFile *file; TString fname; TIter next(files); while (file=(TSystemFile*)next()) { fname = file->GetName(); if (file->IsDirectory()) { std::string dirname(fname.Data()); if (dirname.find("HREfficiency") != std::string::npos) { directoryList.push_back(dirname); } } } } std::vector< std::vector< std::pair< int,int > > > maskedPixels; //sort! std::sort(directoryList.begin(), directoryList.end()); std::vector< std::vector< double > > efficiencies; std::vector< std::vector< double > > efficiencyErrors; std::vector< std::vector< double > > rates; std::vector< std::vector< double > > rateErrors; for (int i=0;i<nRocs;i++) { std::vector< double > empty; efficiencies.push_back(empty); efficiencyErrors.push_back(empty); rates.push_back(empty); rateErrors.push_back(empty); } // loop over all commander_HREfficiency.root root files for (int i=0;i<directoryList.size();++i) { chdir(path.c_str()); std::cout << "looking in directory <" << directoryList[i] << ">" << std::endl; std::ifstream testParameters(Form("%s/testParameters.dat", directoryList[i].c_str())); std::string line2; while (getline(testParameters, line2)) { std::transform(line2.begin(), line2.end(), line2.begin(), ::tolower); if (line2.find("highrate") != std::string::npos) { while (getline(testParameters, line2)) { if (line2.size() < 1) break; std::transform(line2.begin(), line2.end(), line2.begin(), ::tolower); size_t pos = line2.find("ntrig"); if (pos != std::string::npos) { nTrigPerPixel = atoi(line2.substr(pos+6).c_str()); nTrig = nTrigPerPixel * nPixels; std::cout << ">" << line2 << "< pos:" << pos << std::endl; std::cout << "number of triggers per pixel: " << nTrigPerPixel << std::endl; } } } } testParameters.close(); // read masked pixels maskedPixels.clear(); for (int j=0;j<nRocs;j++) { std::vector< std::pair<int,int> > rocMaskedPixels; maskedPixels.push_back(rocMaskedPixels); } std::ifstream maskFile; char maskFilePath[256]; sprintf(maskFilePath, "%s/%s/%s", path.c_str(), directoryList[i].c_str(), maskFileName.c_str()); maskFile.open(maskFilePath, std::ifstream::in); if (!maskFile) { std::cout << "ERROR: mask file <" << maskFilePath << "> can't be opened!"<<std::endl; } std::string line; std::vector< std::string > tokens; while(getline(maskFile, line)) { if (line[0] != '#') { std::stringstream ss(line); std::string buf; tokens.clear(); while (ss >> buf) { tokens.push_back(buf); } std::cout << "tok0 <" << tokens[0] << "> "; if (tokens[0] == "pix" && tokens.size() >= 4) { int roc = atoi(tokens[1].c_str()); int col = atoi(tokens[2].c_str()); int row = atoi(tokens[3].c_str()); std::cout << "mask pixel " << roc << " " << col << " " << row << std::endl; maskedPixels[roc].push_back(make_pair(col, row)); } } } maskFile.close(); chdir(directoryList[i].c_str()); TFile f(rootFileName.c_str()); if (f.IsZombie()) { std::cout << "could not read: " << rootFileName << " ."; exit(0); } std::cout << "list keys:" << std::endl; TIter next(f.GetListOfKeys()); bool highRateFound = false; while (TKey *obj = (TKey*)next()) { if (strcmp(obj->GetTitle(),"HighRate") == 0) highRateFound = true; if (VERBOSE) { std::cout << obj->GetTitle() << std::endl; } } if (highRateFound) { std::cout << "highRate test found, reading data..." << std::endl; TH2D* xraymap; TH2D* calmap; char calmapName[256]; char xraymapName[256]; std::ofstream output; for (int iRoc=0;iRoc<nRocs;iRoc++) { std::cout << "ROC" << iRoc << std::endl; sprintf(xraymapName, "HighRate/highRate_xraymap_C%d_V0;1", iRoc); f.GetObject(xraymapName, xraymap); if (xraymap == 0) { std::cout << "ERROR: x-ray hitmap not found!" << std::endl; } int nBinsX = xraymap->GetXaxis()->GetNbins(); int nBinsY = xraymap->GetYaxis()->GetNbins(); sprintf(calmapName, "HighRate/highRate_C%d_V0;1", iRoc); f.GetObject(calmapName, calmap); if (calmap == 0) { sprintf(calmapName, "HighRate/highRate_calmap_C%d_V0;1", iRoc); f.GetObject(calmapName, calmap); if (calmap == 0) { std::cout << "ERROR: calibration hitmap not found!" << std::endl; } } //std::cout << nBinsX << "x" << nBinsY << std::endl; float rate, efficiency; for (int doubleColumn = 1; doubleColumn < 25; doubleColumn++) { //std::cout << "reading dc " << doubleColumn << std::endl; std::vector<double> hits; std::vector<double> xray_hits; for (int y = 0; y < 160; y++) { bool masked = false; for (int iMaskedPixels=0; iMaskedPixels < maskedPixels[iRoc].size(); iMaskedPixels++) { if (maskedPixels[iRoc][iMaskedPixels].first == doubleColumn * 2 + (int)(y / 80) && maskedPixels[iRoc][iMaskedPixels].second == (y % 80)) { masked = true; break; } } if ((!FIDUCIAL_ONLY || ((y % 80) > 0 && (y % 80) < 79)) && !masked) { //std::cout << " get " << (doubleColumn * 2 + (int)(y / 80) + 1) << " / " << ((y % 80) + 1) << std::endl; hits.push_back( calmap->GetBinContent(doubleColumn * 2 + (int)(y / 80) + 1, (y % 80) + 1) ); xray_hits.push_back( xraymap->GetBinContent(doubleColumn * 2 + (int)(y / 80) + 1, (y % 80) + 1) ); } } //std::cout << "calculating rates and efficiencies" << std::endl; int nPixelsDC = hits.size(); if (nPixelsDC < 1) nPixelsDC = 1; double rate = TMath::Mean(nPixelsDC, &xray_hits[0]) / (nTrig * triggerDuration * pixelArea) * 1.0e-6; double efficiency = TMath::Mean(nPixelsDC, &hits[0]) / nTrigPerPixel; double rateError = TMath::RMS(nPixelsDC, &xray_hits[0]) / std::sqrt(nPixelsDC) / (nTrig * triggerDuration * pixelArea) * 1.0e-6; double efficiencyError = TMath::RMS(nPixelsDC, &hits[0]) / std::sqrt(nPixelsDC) / nTrigPerPixel; efficiencies[iRoc].push_back(efficiency); efficiencyErrors[iRoc].push_back(efficiencyError); rates[iRoc].push_back(rate); rateErrors[iRoc].push_back(rateError); if (VERBOSE) { std::cout << "dc " << doubleColumn << " nPixelsDC: " << nPixelsDC << " rate: " << rate << " " << efficiency << std::endl; } } } //output.open (Form("%s/output_%d.txt",the_path,i), std::ofstream::out); //output.close(); } else { std::cout << "high rate test not found"; return 1; } }