static void AEMarchingCubes(uint8_t* voxels, uint32_t stepX, uint32_t stepY, uint32_t stepZ, double isovalue, uint32_t w, uint32_t h, uint32_t d, AEMCTriangleArray* triangleArray) { // Run the processCube function on every cube in the grid for(uint32_t x = stepX; x < w-2*stepX; x += stepX) { for(uint32_t y = stepY; y < h-2*stepY; y += stepY) { for(uint32_t z = stepZ; z < d-2*stepZ; z += stepZ) { /*GRIDCELL c = {{ {x,y,z, (double)(voxels[Index(x+stepX,y,z,w,h,d)]-voxels[Index(x-stepX,y,z,w,h,d)]) / -stepX, (double)(voxels[Index(x,y+stepY,z,w,h,d)]-voxels[Index(x,y-stepY,z,w,h,d)]) / -stepY, (double)(voxels[Index(x,y,z+stepZ,w,h,d)]-voxels[Index(x,y,z-stepZ,w,h,d)]) / -stepZ }, {x+stepX,y,z, (double)(voxels[Index(x+2*stepX,y,z,w,h,d)]-voxels[Index(x,y,z,w,h,d)]) / -stepX, (double)(voxels[Index(x+stepX,y+stepY,z,w,h,d)]-voxels[Index(x+stepX,y-stepY,z,w,h,d)]) / -stepY, (double)(voxels[Index(x+stepX,y,z+stepZ,w,h,d)]-voxels[Index(x+stepX,y,z-stepZ,w,h,d)]) / -stepZ }, {x+stepX,y,z+stepZ, (double)(voxels[Index(x+2*stepX,y,z+stepZ,w,h,d)]-voxels[Index(x,y,z+stepZ,w,h,d)]) / -stepX, (double)(voxels[Index(x+stepX,y+stepY,z+stepZ,w,h,d)]-voxels[Index(x+stepX,y-stepY,z+stepZ,w,h,d)]) / -stepY, (double)(voxels[Index(x+stepX,y,z+2*stepZ,w,h,d)]-voxels[Index(x+stepX,y,z,w,h,d)]) / -stepZ }, {x,y,z+stepZ, (double)(voxels[Index(x+stepX,y,z+stepZ,w,h,d)]-voxels[Index(x-stepX,y,z+stepZ,w,h,d)]) / -stepX, (double)(voxels[Index(x,y+stepY,z+stepZ,w,h,d)]-voxels[Index(x,y-stepY,z+stepZ,w,h,d)]) / -stepY, (double)(voxels[Index(x,y,z+2*stepZ,w,h,d)]-voxels[Index(x,y,z,w,h,d)]) / -stepZ }, {x,y+stepY,z, (double)(voxels[Index(x+stepX,y+stepY,z,w,h,d)]-voxels[Index(x-stepX,y+stepY,z,w,h,d)]) / -stepX, (double)(voxels[Index(x,y+2*stepY,z,w,h,d)]-voxels[Index(x,y,z,w,h,d)]) / -stepY, (double)(voxels[Index(x,y+stepY,z+stepZ,w,h,d)]-voxels[Index(x,y+stepY,z-stepZ,w,h,d)]) / -stepZ }, {x+stepX,y+stepY,z, (double)(voxels[Index(x+2*stepX,y+stepY,z,w,h,d)]-voxels[Index(x+stepX,y+stepY,z,w,h,d)]) / -stepX, (double)(voxels[Index(x+stepX,y+2*stepY,z,w,h,d)]-voxels[Index(x+stepX,y,z,w,h,d)]) / -stepY, (double)(voxels[Index(x+stepX,y+stepY,z+stepZ,w,h,d)]-voxels[Index(x+stepX,y+stepY,z-stepZ,w,h,d)]) / -stepZ }, {x+stepX,y+stepY,z+stepZ, (double)(voxels[Index(x+2*stepX,y+stepY,z+stepZ,w,h,d)]-voxels[Index(x,y+stepY,z+stepZ,w,h,d)]) / -stepX, (double)(voxels[Index(x+stepX,y+2*stepY,z+stepZ,w,h,d)]-voxels[Index(x+stepX,y,z+stepZ,w,h,d)]) / -stepY, (double)(voxels[Index(x+stepX,y+stepY,z+2*stepZ,w,h,d)]-voxels[Index(x+stepX,y+stepY,z,w,h,d)]) / -stepZ }, {x,y+stepY,z+stepZ, (double)(voxels[Index(x+stepX,y+stepY,z+stepZ,w,h,d)]-voxels[Index(x-stepX,y+stepY,z+stepZ,w,h,d)]) / -stepX, (double)(voxels[Index(x,y+2*stepY,z+stepZ,w,h,d)]-voxels[Index(x,y,z+stepZ,w,h,d)]) / -stepY, (double)(voxels[Index(x,y+stepY,z+2*stepZ,w,h,d)]-voxels[Index(x,y+stepY,z,w,h,d)]) / -stepZ } },{ voxels[Index(x,y,z,w,h,d)], voxels[Index(x+stepX,y,z,w,h,d)], voxels[Index(x+stepX,y,z+stepZ,w,h,d)], voxels[Index(x,y,z+stepZ,w,h,d)], voxels[Index(x,y+stepY,z,w,h,d)], voxels[Index(x+stepX,y+stepY,z,w,h,d)], voxels[Index(x+stepX,y+stepY,z+stepZ,w,h,d)], voxels[Index(x,y+stepY,z+stepZ,w,h,d)] }};*/ GRIDCELL c={{ {x,y,z,0,0,0}, {x+stepX,y,z,0,0,0}, {x+stepX,y,z+stepZ,0,0,0}, {x,y,z+stepZ,0,0,0}, {x,y+stepY,z,0,0,0}, {x+stepX,y+stepY,z,0,0,0}, {x+stepX,y+stepY,z+stepZ,0,0,0}, {x,y+stepY,z+stepZ,0,0,0} },{ voxels[Index(x,y,z,w,h,d)], voxels[Index(x+stepX,y,z,w,h,d)], voxels[Index(x+stepX,y,z+stepZ,w,h,d)], voxels[Index(x,y,z+stepZ,w,h,d)], voxels[Index(x,y+stepY,z,w,h,d)], voxels[Index(x+stepX,y+stepY,z,w,h,d)], voxels[Index(x+stepX,y+stepY,z+stepZ,w,h,d)], voxels[Index(x,y+stepY,z+stepZ,w,h,d)] }}; ///Polygonise(c, isovalue); TRIANGLE triangles[5]; size_t count=Polygonise(c, isovalue, triangles); for (size_t i=0; i<count; i++) { AEArrayAddBytes(triangleArray, triangles+i); } } } } }
nsresult HTMLOptionElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName, const nsAttrValueOrString* aValue, bool aNotify) { nsresult rv = nsGenericHTMLElement::BeforeSetAttr(aNamespaceID, aName, aValue, aNotify); NS_ENSURE_SUCCESS(rv, rv); if (aNamespaceID != kNameSpaceID_None || aName != nsGkAtoms::selected || mSelectedChanged) { return NS_OK; } bool defaultSelected = aValue; // First make sure we actually set our mIsSelected state to reflect our new // defaultSelected state. If that turns out to be wrong, // SetOptionsSelectedByIndex will fix it up. But otherwise we can end up in a // situation where mIsSelected is still false, but mSelectedChanged becomes // true (later in this method, when we compare mIsSelected to // defaultSelected), and then we start returning false for Selected() even // though we're actually selected. mIsSelected = defaultSelected; // We just changed out selected state (since we look at the "selected" // attribute when mSelectedChanged is false). Let's tell our select about // it. HTMLSelectElement* selectInt = GetSelect(); if (!selectInt) { return NS_OK; } NS_ASSERTION(!mSelectedChanged, "Shouldn't be here"); bool inSetDefaultSelected = mIsInSetDefaultSelected; mIsInSetDefaultSelected = true; int32_t index = Index(); uint32_t mask = HTMLSelectElement::SET_DISABLED; if (defaultSelected) { mask |= HTMLSelectElement::IS_SELECTED; } if (aNotify) { mask |= HTMLSelectElement::NOTIFY; } // This can end up calling SetSelectedInternal if our selected state needs to // change, which we will allow to take effect so that parts of // SetOptionsSelectedByIndex that might depend on it working don't get // confused. selectInt->SetOptionsSelectedByIndex(index, index, mask); // Now reset our members; when we finish the attr set we'll end up with the // rigt selected state. mIsInSetDefaultSelected = inSetDefaultSelected; // mIsSelected might have been changed by SetOptionsSelectedByIndex. Possibly // more than once; make sure our mSelectedChanged state is set correctly. mSelectedChanged = mIsSelected != defaultSelected; return NS_OK; }
void compare_patches(double eps, int ndim, double *patch1, int lo1[], int hi1[], int dims1[],double *patch2, int lo2[], int hi2[], int dims2[]) { int i,j, elems=1; int subscr1[MAXDIMS], subscr2[MAXDIMS]; double diff,max; int offset1 = 0, offset2 = 0; for(i=0;i<ndim;i++){ /* count # of elements & verify consistency of both patches */ int diff = hi1[i]-lo1[i]; assert(diff == (hi2[i]-lo2[i])); assert(diff < dims1[i]); assert(diff < dims2[i]); elems *= diff+1; subscr1[i]= lo1[i]; subscr2[i]=lo2[i]; } /* compare element values in both patches */ for(j=0; j< elems; j++){ int idx1, idx2; idx1 = Index(ndim, subscr1, dims1); /* calculate element Index from a subscript */ idx2 = Index(ndim, subscr2, dims2); if(j==0){ offset1 =idx1; offset2 =idx2; } idx1 -= offset1; idx2 -= offset2; diff = patch1[idx1] - patch2[idx2]; max = MAX(ABS(patch1[idx1]),ABS(patch2[idx2])); if(max == 0. || max <eps) max = 1.; if(eps < ABS(diff)/max){ char msg[48]; sprintf(msg,"(proc=%d):%f",me,patch1[idx1]); print_subscript("ERROR: a",ndim,subscr1,msg); sprintf(msg,"%f\n",patch2[idx2]); print_subscript(" b",ndim,subscr2,msg); printf("\nA = %f B = %f\n", patch1[idx1], patch2[idx2]); fflush(stdout); sleep(1); fprintf(stderr, "Bailing out\n"); MPI_Abort(MPI_COMM_WORLD, 1); } { /* update subscript for the patches */ update_subscript(ndim, subscr1, lo1,hi1, dims1); update_subscript(ndim, subscr2, lo2,hi2, dims2); } } /* make sure we reached upper limit */ /*for(i=0;i<ndim;i++){ assert(subscr1[i]==hi1[i]); assert(subscr2[i]==hi2[i]); }*/ }
main() { FILE *f; char filename[50]; printf("input the name of the file:"); scanf("%s",filename);//the file's name can be absolute path,include the .txt example: D:\\file1\\file2\\test.txt f=fopen(filename,"r"); if (f==NULL)//if can not open the file,stop the program { printf("OMG,the file is not existed!\n"); system("pause"); return; } get_the_map(f);//get the information of map getchar(); printf("input the start street name:"); gets(start_street); printf("input the start house number:"); scanf("%d",&start_house); getchar(); printf("input the destination street name:"); gets(destination_street); printf("input the destination house number:"); scanf("%d",&destination_house); Insert_start_destination(street_num,start_house,destination_house,start_street,destination_street); if (start_unique=='\0' || destination_unique=='\0')//if we don't get the unique number for start and destination nodes,we stop. { system("pause"); return 0; } if (start_unique == destination_unique)//if the start node has the same coordinate as the destination node.stop. { printf("the start point is the same as destination!\n"); system("pause"); return 0; } int k=1; int i,j; Dijkstra();//Dijkstra is to store each node's father unique numbers struct search_path BFS_array[50]; /*the destination node has his father nodes,and these father nodes also have their own father nodes. So it's a tree,and I use the BFS method to find every shortest path. */ int label; label=Index(destination_unique); BFS_array[1].unique=destination_unique; i=1; int from,present;//"from" and "present" are labels in the array from=2; j=from; present=from+adj_list[label].father_num; while (i<=adj_list[label].father_num)//begin at the destination,so that store the destination's father firstly { BFS_array[j].unique=adj_list[label].father_unique_num[i]; BFS_array[j].pre_label=1; j++; i++; } get_BFS_list(BFS_array,from,present);//"from" to store the present first father's position,and "present" to store the array's present position i=1; int counter=0; while(BFS_array[i].unique!='\0')//"counter" is to get the total number of the shortest pathes { if (BFS_array[i].unique==start_unique) counter++; i++; } struct each_path shortest_ways[counter+1]; get_the_pathes(shortest_ways,BFS_array); int ways=counter; for (i=1;i<=ways;i++)//for each shortest path,store each node's distance between he and his father { path_link present; present=&shortest_ways[i]; float pre_x,pre_y; if (present->unique_num==1)//if the unique number is 1,do some special operations { pre_x=start_x; pre_y=start_y; } else { present->x=present->unique_num/100; present->y=present->unique_num%100; pre_x=present->x; pre_y=present->y; } present=present->next_node; while(present!=NULL) { float X,Y; if (present->unique_num==2)//if the next node is destination node,also do some special operations { X=pre_x-destination_x; Y=pre_y-destination_y; present->distance=sqrt(pow(X,2)+pow(Y,2))*mile; } else { present->x=present->unique_num/100; present->y=present->unique_num%100; X=pre_x-present->x; Y=pre_y-present->y; present->distance=sqrt(pow(X,2)+pow(Y,2))*mile; pre_x=present->x; pre_y=present->y; } present=present->next_node; } } turn_by_turn(shortest_ways,ways);//turn by turn output each shortest path system("pause"); }
// This one can load both leftover map files on game discs (like Zelda), and mapfiles // produced by SaveSymbolMap below. // bad=true means carefully load map files that might not be from exactly the right version bool PPCSymbolDB::LoadMap(const std::string& filename, bool bad) { File::IOFile f(filename, "r"); if (!f) return false; // four columns are used in American Mensa Academy map files and perhaps other games bool started = false, four_columns = false; int good_count = 0, bad_count = 0; char line[512]; while (fgets(line, 512, f.GetHandle())) { size_t length = strlen(line); if (length < 4) continue; if (length == 34 && strcmp(line, " address Size address offset\n") == 0) { four_columns = true; continue; } char temp[256]; sscanf(line, "%255s", temp); if (strcmp(temp, "UNUSED")==0) continue; if (strcmp(temp, ".text")==0) {started = true; continue;}; if (strcmp(temp, ".init")==0) {started = true; continue;}; if (strcmp(temp, "Starting")==0) continue; if (strcmp(temp, "extab")==0) continue; if (strcmp(temp, ".ctors")==0) break; //uh? if (strcmp(temp, ".dtors")==0) break; if (strcmp(temp, ".rodata")==0) continue; if (strcmp(temp, ".data")==0) continue; if (strcmp(temp, ".sbss")==0) continue; if (strcmp(temp, ".sdata")==0) continue; if (strcmp(temp, ".sdata2")==0) continue; if (strcmp(temp, "address")==0) continue; if (strcmp(temp, "-----------------------")==0) continue; if (strcmp(temp, ".sbss2")==0) break; if (temp[1] == ']') continue; if (!started) continue; u32 address, vaddress, size, offset, unknown; char name[512], container[512]; if (four_columns) { // sometimes there is no unknown number, and sometimes it is because it is an entry of something else if (length > 37 && line[37]==' ') { unknown = 0; sscanf(line, "%08x %08x %08x %08x %511s", &address, &size, &vaddress, &offset, name); char *s = strstr(line, "(entry of "); if (s) { sscanf(s + 10, "%511s", container); char *s2 = (strchr(container, ')')); if (s2 && container[0]!='.') { s2[0] = '\0'; strcat(container, "::"); strcat(container, name); strcpy(name, container); } } } else { sscanf(line, "%08x %08x %08x %08x %i %511s", &address, &size, &vaddress, &offset, &unknown, name); } } // some entries in the table have a function name followed by " (entry of " followed by a container name, followed by ")" // instead of a space followed by a number followed by a space followed by a name else if (length > 27 && line[27] != ' ' && strstr(line, "(entry of ")) { unknown = 0; sscanf(line, "%08x %08x %08x %511s", &address, &size, &vaddress, name); char *s = strstr(line, "(entry of "); if (s) { sscanf(s + 10, "%511s", container); char *s2 = (strchr(container, ')')); if (s2 && container[0] != '.') { s2[0] = '\0'; strcat(container, "::"); strcat(container, name); strcpy(name, container); } } } else { sscanf(line, "%08x %08x %08x %i %511s", &address, &size, &vaddress, &unknown, name); } const char *namepos = strstr(line, name); if (namepos != nullptr) //would be odd if not :P strcpy(name, namepos); name[strlen(name) - 1] = 0; // we want the function names only .... TODO: or do we really? aren't we wasting information here? for (size_t i = 0; i < strlen(name); i++) { if (name[i] == ' ') name[i] = 0x00; if (name[i] == '(') name[i] = 0x00; } // Check if this is a valid entry. if (strcmp(name, ".text") != 0 && strcmp(name, ".init") != 0 && strlen(name) > 0) { vaddress |= 0x80000000; bool good = !bad; if (!good) { // check for BLR before function u32 opcode = PowerPC::HostRead_Instruction(vaddress - 4); if (opcode == 0x4e800020) { // check for BLR at end of function opcode = PowerPC::HostRead_Instruction(vaddress + size - 4); if (opcode == 0x4e800020) good = true; } } if (good) { ++good_count; AddKnownSymbol(vaddress | 0x80000000, size, name); // ST_FUNCTION } else { ++bad_count; } } } Index(); if (bad) SuccessAlertT("Loaded %d good functions, ignored %d bad functions.", good_count, bad_count); return true; }
void cSkeleton<_DataType>::ConnectingFlaggedVoxels() { int i, j, k, loc[3], NextPos_i[3], NumContinuousVoxels; unsigned char VoxelFlag_uc; printf ("Connecting Flagged Voxels ... \n"); fflush(stdout); #ifdef DEBUG_CONNECTING // int MaxNumContinuousVoxels = 0; #endif for (k=1; k<Depth_mi-1; k++) { for (j=1; j<Height_mi-1; j++) { for (i=1; i<Width_mi-1; i++) { loc[0] = Index(i, j, k); if (VoxelFlags_muc[loc[0]]==FLAG_NONUNIFORM) { #ifdef DEBUG_CONNECTING printf ("Start (%d %d %d)\n", i, j, k); #endif NextPos_i[0] = i; NextPos_i[1] = j; NextPos_i[2] = k; NumContinuousVoxels = 0; do { NextPos_i[0] = (int)((float)NextPos_i[0] + GVFDistance_mf[loc[0]*3 + 0] + 0.5); NextPos_i[1] = (int)((float)NextPos_i[1] + GVFDistance_mf[loc[0]*3 + 1] + 0.5); NextPos_i[2] = (int)((float)NextPos_i[2] + GVFDistance_mf[loc[0]*3 + 2] + 0.5); loc[0] = Index (NextPos_i[0], NextPos_i[1], NextPos_i[2]); NumContinuousVoxels++; #ifdef DEBUG_CONNECTING printf ("(%d %d %d)", NextPos_i[0], NextPos_i[1], NextPos_i[2]); DisplayFlag(VoxelFlags_muc[loc[0]]); printf (", "); #endif VoxelFlag_uc = VoxelFlags_muc[loc[0]]; if (VoxelFlag_uc == FLAG_CONNECTED || VoxelFlag_uc == FLAG_NONUNIFORM || VoxelFlag_uc == FLAG_EMPTY) break; VoxelFlags_muc[loc[0]] = FLAG_CONNECTED; } while (VoxelFlag_uc != FLAG_NONUNIFORM); } } } } for (i=0; i<WHD_mi; i++) { if (VoxelFlags_muc[i]==FLAG_NONUNIFORM) VoxelFlags_muc[i] = FLAG_CONNECTED; } int NumConnectedVoxels = 0; for (i=0; i<WHD_mi; i++) { if (VoxelFlags_muc[i]==FLAG_CONNECTED) NumConnectedVoxels++; } printf ("Num. Connected Voxels = %d\n", NumConnectedVoxels); printf ("Num. Connected / NumSegmented = %f %%\n", (float)NumConnectedVoxels/NumSegmentedVoxels_mi*100.0); printf ("Num. Connected / Total Num. Voxels = %f %%\n", (double)NumConnectedVoxels/WHD_mi*100.0); fflush (stdout); }
void FitterUtilsSimultaneousExpOfPolyTimesX::fit(bool wantplot, bool constPartReco, double fracPartReco_const, ofstream& out, TTree* t, bool update, string plotsfile) { //***************Get the PDFs from the workspace TFile fw(workspacename.c_str()); RooWorkspace* workspace = (RooWorkspace*)fw.Get("workspace"); RooRealVar *B_plus_M = workspace->var("B_plus_M"); RooRealVar *misPT = workspace->var("misPT"); RooRealVar *l1Kee = workspace->var("l1Kee"); RooRealVar *l2Kee = workspace->var("l2Kee"); RooRealVar *l3Kee = workspace->var("l3Kee"); RooRealVar *l4Kee = workspace->var("l4Kee"); RooRealVar *l5Kee = workspace->var("l5Kee"); RooRealVar *l1KeeGen = workspace->var("l1KeeGen"); RooRealVar *l2KeeGen = workspace->var("l2KeeGen"); RooRealVar *l3KeeGen = workspace->var("l3KeeGen"); RooRealVar *l4KeeGen = workspace->var("l4KeeGen"); RooRealVar *l5KeeGen = workspace->var("l5KeeGen"); RooRealVar *fractionalErrorJpsiLeak = workspace->var("fractionalErrorJpsiLeak"); RooRealVar l1Kemu(*l1Kee); l1Kemu.SetName("l1Kemu"); l1Kemu.SetTitle("l1Kemu"); RooRealVar l2Kemu(*l2Kee); l2Kemu.SetName("l2Kemu"); l2Kemu.SetTitle("l2Kemu"); RooRealVar l3Kemu(*l3Kee); l3Kemu.SetName("l3Kemu"); l3Kemu.SetTitle("l3Kemu"); RooRealVar l4Kemu(*l4Kee); l4Kemu.SetName("l4Kemu"); l4Kemu.SetTitle("l4Kemu"); RooRealVar l5Kemu(*l5Kee); l5Kemu.SetName("l5Kemu"); l5Kemu.SetTitle("l5Kemu"); RooHistPdf *histPdfSignalZeroGamma = (RooHistPdf *) workspace->pdf("histPdfSignalZeroGamma"); RooHistPdf *histPdfSignalOneGamma = (RooHistPdf *) workspace->pdf("histPdfSignalOneGamma"); RooHistPdf *histPdfSignalTwoGamma = (RooHistPdf *) workspace->pdf("histPdfSignalTwoGamma"); RooHistPdf *histPdfPartReco = (RooHistPdf *) workspace->pdf("histPdfPartReco"); RooHistPdf *histPdfJpsiLeak(0); if(nGenJpsiLeak>0) histPdfJpsiLeak = (RooHistPdf *) workspace->pdf("histPdfJpsiLeak"); //Here set in the Kemu PDF the parameters that have to be shared RooExpOfPolyTimesX* combPDF = new RooExpOfPolyTimesX("combPDF", "combPDF", *B_plus_M, *misPT, *l1Kee, *l2Kee, *l3Kee, *l4Kee, *l5Kee); RooExpOfPolyTimesX* KemuPDF = new RooExpOfPolyTimesX("kemuPDF", "kemuPDF", *B_plus_M, *misPT, l1Kemu, *l2Kee, *l3Kee, *l4Kee, *l5Kee); RooWorkspace* workspaceGen = (RooWorkspace*)fw.Get("workspaceGen"); RooDataSet* dataGenSignalZeroGamma = (RooDataSet*)workspaceGen->data("dataGenSignalZeroGamma"); RooDataSet* dataGenSignalOneGamma = (RooDataSet*)workspaceGen->data("dataGenSignalOneGamma"); RooDataSet* dataGenSignalTwoGamma = (RooDataSet*)workspaceGen->data("dataGenSignalTwoGamma"); RooDataSet* dataGenPartReco = (RooDataSet*)workspaceGen->data("dataGenPartReco"); RooDataSet* dataGenComb = (RooDataSet*)workspaceGen->data("dataGenComb"); RooDataSet* dataGenKemu = (RooDataSet*)workspaceGen->data("dataGenKemu"); RooDataSet* dataGenJpsiLeak(0); if(nGenJpsiLeak>0) dataGenJpsiLeak = (RooDataSet*)workspaceGen->data("dataGenJpsiLeak"); if(wantplot) { //**************Must get the datasets RooDataSet* dataSetSignalZeroGamma = (RooDataSet*)workspace->data("dataSetSignalZeroGamma"); RooDataSet* dataSetSignalOneGamma = (RooDataSet*)workspace->data("dataSetSignalOneGamma"); RooDataSet* dataSetSignalTwoGamma = (RooDataSet*)workspace->data("dataSetSignalTwoGamma"); RooDataSet* dataSetPartReco = (RooDataSet*)workspace->data("dataSetPartReco"); RooDataSet* dataSetComb = (RooDataSet*)workspace->data("dataSetComb"); RooDataSet* dataSetJpsiLeak = (RooDataSet*)workspace->data("dataSetJpsiLeak"); //**************Plot all the different components cout<<"dataGenSignalZeroGamma: "<<dataGenSignalZeroGamma<<endl; PlotShape(*dataSetSignalZeroGamma, *dataGenSignalZeroGamma, *histPdfSignalZeroGamma, plotsfile, "cSignalZeroGamma", *B_plus_M, *misPT); PlotShape(*dataSetSignalOneGamma, *dataGenSignalOneGamma, *histPdfSignalOneGamma, plotsfile, "cSignalOneGamma", *B_plus_M, *misPT); PlotShape(*dataSetSignalTwoGamma, *dataGenSignalTwoGamma, *histPdfSignalTwoGamma, plotsfile, "cSignalTwoGamma", *B_plus_M, *misPT); PlotShape(*dataSetPartReco, *dataGenPartReco, *histPdfPartReco, plotsfile, "cPartReco", *B_plus_M, *misPT); PlotShape(*dataSetComb, *dataGenComb, *combPDF, plotsfile, "cComb", *B_plus_M, *misPT); if(nGenJpsiLeak>1) PlotShape(*dataSetJpsiLeak, *dataGenJpsiLeak, *histPdfJpsiLeak, plotsfile, "cJpsiLeak", *B_plus_M, *misPT); } //***************Merge datasets RooDataSet* dataGenTot(dataGenPartReco); dataGenTot->append(*dataGenSignalZeroGamma); dataGenTot->append(*dataGenSignalOneGamma); dataGenTot->append(*dataGenSignalTwoGamma); dataGenTot->append(*dataGenComb); if(nGenJpsiLeak>0) dataGenTot->append(*dataGenJpsiLeak); //**************Create index category and join samples RooCategory category("category", "category"); category.defineType("Kee"); category.defineType("Kemu"); RooDataSet dataGenSimultaneous("dataGenSimultaneous", "dataGenSimultaneous", RooArgSet(*B_plus_M, *misPT), Index(category), Import("Kee", *dataGenTot), Import("Kemu", *dataGenKemu)); //**************Prepare fitting function RooRealVar nSignal("nSignal", "#signal events", 1.*nGenSignal, nGenSignal-7*sqrt(nGenSignal), nGenSignal+7*sqrt(nGenSignal)); RooRealVar nPartReco("nPartReco", "#nPartReco", 1.*nGenPartReco, nGenPartReco-7*sqrt(nGenPartReco), nGenPartReco+7*sqrt(nGenPartReco)); RooRealVar nComb("nComb", "#nComb", 1.*nGenComb, nGenComb-7*sqrt(nGenComb), nGenComb+7*sqrt(nGenComb)); RooRealVar nKemu("nKemu", "#nKemu", 1.*nGenKemu, nGenKemu-7*sqrt(nGenKemu), nGenKemu+7*sqrt(nGenKemu)); RooRealVar nJpsiLeak("nJpsiLeak", "#nJpsiLeak", 1.*nGenJpsiLeak, nGenJpsiLeak-7*sqrt(nGenJpsiLeak), nGenJpsiLeak+7*sqrt(nGenJpsiLeak)); RooRealVar fracZero("fracZero", "fracZero",0.5,0,1); RooRealVar fracOne("fracOne", "fracOne",0.5, 0,1); RooFormulaVar fracPartReco("fracPartReco", "nPartReco/nSignal", RooArgList(nPartReco,nSignal)); RooFormulaVar fracOneRec("fracOneRec", "(1-fracZero)*fracOne", RooArgList(fracZero, fracOne)); RooAddPdf histPdfSignal("histPdfSignal", "histPdfSignal", RooArgList(*histPdfSignalZeroGamma, *histPdfSignalOneGamma, *histPdfSignalTwoGamma), RooArgList(fracZero, fracOneRec)); RooArgList pdfList(histPdfSignal, *histPdfPartReco, *combPDF); RooArgList yieldList(nSignal, nPartReco, nComb); if(nGenJpsiLeak>0) { pdfList.add(*histPdfJpsiLeak); yieldList.add(nJpsiLeak); } RooAddPdf totPdf("totPdf", "totPdf", pdfList, yieldList); RooExtendPdf totKemuPdf("totKemuPdf", "totKemuPdf", *KemuPDF, nKemu); //**************** Prepare simultaneous PDF RooSimultaneous simPdf("simPdf", "simPdf", category); simPdf.addPdf(totPdf, "Kee"); simPdf.addPdf(totKemuPdf, "Kemu"); //**************** Constrain the fraction of zero and one photon int nGenSignalZeroGamma(floor(nGenFracZeroGamma*nGenSignal)); int nGenSignalOneGamma(floor(nGenFracOneGamma*nGenSignal)); int nGenSignalTwoGamma(floor(nGenSignal-nGenSignalZeroGamma-nGenSignalOneGamma)); RooRealVar fracZeroConstMean("fracZeroConstMean", "fracZeroConstMean", nGenSignalZeroGamma*1./nGenSignal); RooRealVar fracZeroConstSigma("fracZeroConstSigma", "fracZeroConstSigma", sqrt(nGenSignalZeroGamma)/nGenSignal); RooGaussian fracZeroConst("fracZeroConst", "fracZeroConst", fracZero, fracZeroConstMean, fracZeroConstSigma); RooRealVar fracOneConstMean("fracOneConstMean", "fracOneConstMean", nGenSignalOneGamma*1./nGenSignal/(1-fracZeroConstMean.getVal())); RooRealVar fracOneConstSigma("fracOneConstSigma", "fracOneConstSigma", sqrt(nGenSignalOneGamma)/nGenSignal/(1-fracZeroConstMean.getVal())); RooGaussian fracOneConst("fracOneConst", "fracOneConst", fracOne, fracOneConstMean, fracOneConstSigma); RooRealVar fracPartRecoMean("fracPartRecoMean", "fracPartRecoMean", nGenPartReco/(1.*nGenSignal)); RooRealVar fracPartRecoSigma("fracPartRecoSigma", "fracPartRecoSigma", fracPartReco_const*fracPartRecoMean.getVal()); RooGaussian fracPartRecoConst("fracPartRecoConst", "fracPartRecoConst", fracPartReco, fracPartRecoMean, fracPartRecoSigma); RooRealVar JpsiLeakMean("JpsiLeakMean", "JpsiLeakMean", nGenJpsiLeak); RooRealVar JpsiLeakSigma("JpsiLeakSigma", "JpsiLeakSigma", nGenJpsiLeak*fractionalErrorJpsiLeak->getVal()); RooGaussian JpsiLeakConst("JpsiLeakConst", "JpsiLeakConst", nJpsiLeak, JpsiLeakMean, JpsiLeakSigma); //**************** fit RooAbsReal::defaultIntegratorConfig()->setEpsAbs(1e-8) ; RooAbsReal::defaultIntegratorConfig()->setEpsRel(1e-8) ; initiateParams(nGenSignalZeroGamma, nGenSignalOneGamma, nGenSignalTwoGamma, nKemu, nSignal, nPartReco, nComb, fracZero, fracOne, nJpsiLeak, constPartReco, fracPartRecoSigma, *l1Kee, *l2Kee, *l3Kee, *l4Kee, *l5Kee, l1Kemu, l2Kemu, l3Kemu, l4Kemu, l5Kemu, *l1KeeGen, *l2KeeGen, *l3KeeGen, *l4KeeGen, *l5KeeGen); RooArgSet constraints(fracZeroConst, fracOneConst); if (constPartReco) constraints.add(fracPartRecoConst); if(nGenJpsiLeak>0) constraints.add(JpsiLeakConst); RooAbsReal* nll = simPdf.createNLL(dataGenSimultaneous, Extended(), ExternalConstraints(constraints)); RooMinuit minuit(*nll); minuit.setStrategy(2); int migradRes(1); int hesseRes(4); vector<int> migradResVec; vector<int> hesseResVec; double edm(10); int nrefit(0); RooFitResult* fitRes(0); vector<RooFitResult*> fitResVec; bool hasConverged(false); for(int i(0); (i<15) && !hasConverged ; ++i) { initiateParams(nGenSignalZeroGamma, nGenSignalOneGamma, nGenSignalTwoGamma, nKemu, nSignal, nPartReco, nComb, fracZero, fracOne, nJpsiLeak, constPartReco, fracPartRecoSigma, *l1Kee, *l2Kee, *l3Kee, *l4Kee, *l5Kee, l1Kemu, l2Kemu, l3Kemu, l4Kemu, l5Kemu, *l1KeeGen, *l2KeeGen, *l3KeeGen, *l4KeeGen, *l5KeeGen); cout<<"FITTING: starting with nsignal = "<<nSignal.getValV()<<" refit nbr. "<<i<<endl; //if(fitRes != NULL && fitRes != 0) delete fitRes; migradRes = minuit.migrad(); hesseRes = minuit.hesse(); fitRes = minuit.save(); edm = fitRes->edm(); fitResVec.push_back(fitRes); migradResVec.push_back(migradRes); hesseResVec.push_back(hesseRes); if( migradRes == 0 && hesseRes == 0 && edm < 1e-3 ) hasConverged = true; ++nrefit; cout<<"Fitting nbr "<<i<<" done. Hesse: "<<hesseRes<<" migrad: "<<migradRes<<" edm: "<<edm<<" minNll: "<<fitRes->minNll()<<endl; } if(!hasConverged) { double minNll(1e20); int minIndex(-1); for(unsigned int i(0); i<fitResVec.size(); ++i) { if( fitResVec.at(i)->minNll() < minNll) { minIndex = i; minNll = fitResVec[i]->minNll(); } } migradRes = migradResVec.at(minIndex); hesseRes = hesseResVec.at(minIndex); cout<<"Fit not converged, choose fit "<<minIndex<<". Hesse: "<<hesseRes<<" migrad: "<<migradRes<<" edm: "<<edm<<" minNll: "<<fitRes->minNll()<<endl; } fillTreeResult(t, fitRes, update, migradRes, hesseRes, hasConverged); for(unsigned int i(0); i<fitResVec.size(); ++i) delete fitResVec.at(i); //totPdf.fitTo(*dataGenTot, Extended(), Save(), Warnings(false)); //*************** output fit status int w(12); out<<setw(w)<<migradRes<<setw(w)<<hesseRes<<setw(w)<<edm<<setw(w)<<nrefit<<endl; if(wantplot) plot_fit_result(plotsfile, totPdf, *dataGenTot); if(wantplot) plot_kemu_fit_result(plotsfile, totKemuPdf, *dataGenKemu); fw.Close(); //delete and return delete nll; delete workspace; delete workspaceGen; delete combPDF; delete KemuPDF; }
LUA_API void lua_rawgeti (lua_State *L, int index, int n) { StkId o = Index(L, index); LUA_ASSERT(ttype(o) == LUA_TTABLE, "table expected"); *L->top = *luaH_getnum(hvalue(o), n); api_incr_top(L); }
LUA_API void lua_settable (lua_State *L, int index) { StkId t = Index(L, index); StkId top = L->top; luaV_settable(L, t, top-2); L->top = top-2; /* pop index and value */ }
bool ElevationMap::fuseAll() { ROS_DEBUG("Requested to fuse entire elevation map."); boost::recursive_mutex::scoped_lock scopedLock(fusedMapMutex_); return fuse(Index(0, 0), fusedMap_.getSize()); }
LUA_API void lua_gettable (lua_State *L, int index) { StkId t = Index(L, index); StkId top = L->top; *(top-1) = *luaV_gettable(L, t); L->top = top; /* tag method may change top */ }
// Column major grid dissection order for the sparse // QR decomposition algorithm. void grid_dissection_order( const grid2 *g0, int *perm ) { int width = Width(*g0); int height = Height(*g0); int size = width*height; int mid, x, y, i, *p; grid2 g1, g2, gs; g1 = g2 = gs = *g0; if( width >= 4 || height >= 4 ) { #ifdef DEBUG_DISSECTION_ORDER printf( "dissecting %dx%d grid based at %d:\n", width, height, g0->base ); #endif if( width < height ) { mid = height / 2; // 1st grid g1.ran[1][1] = g0->ran[1][0] + mid-1; // 2nd grid g2.base = g0->base + Size(g1); g2.ran[1][0] = g0->ran[1][0] + mid+1; // Separating grid gs.base = g2.base + Size(g2); gs.ran[1][0] = g0->ran[1][0] + mid-1; gs.ran[1][1] = g0->ran[1][0] + mid+1; #ifdef DEBUG_DISSECTION_ORDER printf( "\tg1: base = %d, \tran_x = [%d,%d), \tran_y = [%d,%d)\n", g1.base, g1.ran[0][0], g1.ran[0][1], g1.ran[1][0], g1.ran[1][1] ); printf( "\tgs: base = %d, \tran_x = [%d,%d), \tran_y = [%d,%d)\n", gs.base, gs.ran[0][0], gs.ran[0][1], gs.ran[1][0], gs.ran[1][1] ); printf( "\tg2: base = %d, \tran_x = [%d,%d), \tran_y = [%d,%d)\n", g2.base, g2.ran[0][0], g2.ran[0][1], g2.ran[1][0], g2.ran[1][1] ); printf( "\n" ); printf( "Mapping Nodes:\n" ); #endif for( i=g0->base, p=perm+i; i < size; ++i, ++p ) { Node(*g0,i,x,y); #ifdef DEBUG_DISSECTION_ORDER printf( "\tNode %d @ (%d,%d) -> ", i, x, y ); if( y >= g2.ran[1][0] ) printf("%d (g2)\n", Index(g2,x,y)); else if( y >= gs.ran[1][0] ) printf("%d (gs)\n", Index(gs,x,y)); else printf("%d (g1)\n", Index(g1,x,y)); #endif if( y >= g2.ran[1][0] ) {*p = Index(g2,x,y); continue;} if( y >= gs.ran[1][0] ) {*p = Index(gs,x,y); continue;} *p = Index(g1,x,y); } // for( i, p ) grid_dissection_order( &g1, perm ); grid_dissection_order( &g2, perm ); } else { // width >= height mid = width / 2; // 1st grid g1.ran[0][1] = g0->ran[0][0] + mid-1; // 2nd grid g2.base = g0->base + Size(g1); g2.ran[0][0] = g0->ran[0][0] + mid+1; // Separating grid gs.base = g2.base + Size(g2); gs.ran[0][0] = g0->ran[0][0] + mid-1; gs.ran[0][1] = g0->ran[0][0] + mid+1; #ifdef DEBUG_DISSECTION_ORDER printf( "\tg1: base = %d, \tran_x = [%d,%d), \tran_y = [%d,%d)\n", g1.base, g1.ran[0][0], g1.ran[0][1], g1.ran[1][0], g1.ran[1][1] ); printf( "\tgs: base = %d, \tran_x = [%d,%d), \tran_y = [%d,%d)\n", gs.base, gs.ran[0][0], gs.ran[0][1], gs.ran[1][0], gs.ran[1][1] ); printf( "\tg2: base = %d, \tran_x = [%d,%d), \tran_y = [%d,%d)\n", g2.base, g2.ran[0][0], g2.ran[0][1], g2.ran[1][0], g2.ran[1][1] ); printf( "\n" ); printf( "Mapping Nodes:\n" ); #endif i = Index(*g0,gs.ran[0][0],gs.ran[1][0]); for( p=perm+i; i < size; ++i, ++p ) { Node(*g0,i,x,y); #ifdef DEBUG_DISSECTION_ORDER printf( "\tNode %d @ (%d,%d) -> ", i, x, y ); if( x >= g2.ran[0][0] ) printf("%d (g2)\n", Index(g2,x,y)); else if( x >= gs.ran[0][0] ) printf("%d (gs)\n", Index(gs,x,y)); else printf("%d (g1)\n", *p); #endif if( x >= g2.ran[0][0] ) {*p = Index(g2,x,y); continue;} if( x >= gs.ran[0][0] ) {*p = Index(gs,x,y); continue;} } // for( i, p ) grid_dissection_order( &g1, perm ); grid_dissection_order( &g2, perm ); } // if( width < height ) } }
int main(int argc, const char** argv){ bool ReDoCuts=false; TCut TwelveCut = "gamma_CL>0.1&&BDT_response>0.36&&piplus_MC12TuneV3_ProbNNpi>0.2&&piminus_MC12TuneV3_ProbNNpi>0.2&&Kaon_MC12TuneV3_ProbNNk>0.4"; TCut ElevenCut = "gamma_CL>0.1&&BDT_response>0.30&&piplus_MC12TuneV3_ProbNNpi>0.2&&piminus_MC12TuneV3_ProbNNpi>0.2&&Kaon_MC12TuneV3_ProbNNk>0.4"; //______________________________MAKE CUT FILE FOR 2012___________________________________ if(ReDoCuts){ DataFile MCA(std::getenv("BUKETAPMCBDTRESPROOT"),MC,Twel,MagAll,buketap,"BDTApplied_SampleA"); DataFile MCB(std::getenv("BUKETAPMCBDTRESPROOT"),MC,Twel,MagAll,buketap,"BDTApplied_SampleB"); TreeReader* MC12Reader= new TreeReader("DecayTree"); MC12Reader->AddFile(MCA); MC12Reader->AddFile(MCB); MC12Reader->Initialize(); TFile* MC12Cut = new TFile("CutFile12.root","RECREATE"); TTree* MC12CutTree=MC12Reader->CopyTree(TwelveCut,-1,"DecayTree"); TRandom3 *MCRand = new TRandom3(224); TH1I * MCnCands12= new TH1I("MCnCands12","MCnCands12",10,0,10); TTree*MC12SingleTree=HandyFunctions::GetSingleTree(MCRand,MC12CutTree,MCnCands12,NULL); MCnCands12->Write(); MC12SingleTree->Write(); MC12Cut->Close(); //________________________________MAKE CUT FILE FOR 2011__________________________________ DataFile MC11A(std::getenv("BUKETAPMCBDTRESPROOT"),MC,Elev,MagAll,buketap,"BDTApplied_SampleA"); DataFile MC11B(std::getenv("BUKETAPMCBDTRESPROOT"),MC,Elev,MagAll,buketap,"BDTApplied_SampleB"); TreeReader* MC11Reader= new TreeReader("DecayTree"); MC11Reader->AddFile(MC11A); MC11Reader->AddFile(MC11B); MC11Reader->Initialize(); TFile* MC11Cut = new TFile("CutFile11.root","RECREATE"); TTree* MC11CutTree=MC11Reader->CopyTree(ElevenCut,-1,"DecayTree"); TH1I * MCnCands11= new TH1I("MCnCands11","MCnCands11",10,0,10); TTree* MC11SingleTree=HandyFunctions::GetSingleTree(MCRand,MC11CutTree,MCnCands11,NULL); MCnCands11->Write(); MC11SingleTree->Write(); MC11Cut->Close(); //_________________________________ MAKE FLAT TREES ____________________________________ TFile* MC12Input = new TFile("CutFile12.root"); TTree* MC12InputTree=(TTree*)MC12Input->Get("DecayTree"); Float_t MCEta_Mass12[20]; MC12InputTree->SetBranchAddress("Bu_DTFNoFix_eta_prime_M",&MCEta_Mass12); Int_t isSingle12; MC12InputTree->SetBranchAddress("isSingle",&isSingle12); TFile* MC12FlatOut = new TFile("MCMinimalFile12.root","RECREATE"); TTree* MC12FlatTree = MC12InputTree->CloneTree(0); Double_t MCBu_DTFNoFix_eta_Prime_MF12; MC12FlatTree->Branch("Bu_DTFNoFix_eta_prime_MF",&MCBu_DTFNoFix_eta_Prime_MF12,"Bu_DTFNoFix_eta_prime_MF/D"); Long64_t Entries12=MC12InputTree->GetEntries(); for(int i=0;i<Entries12;++i){ MC12InputTree->GetEntry(i); if(isSingle12==0)continue; MCBu_DTFNoFix_eta_Prime_MF12=MCEta_Mass12[0]; MC12FlatTree->Fill(); } MC12FlatTree->Write(); MC12FlatOut->Close(); TFile* MC11Input = new TFile("CutFile11.root"); TTree* MC11InputTree=(TTree*)MC11Input->Get("DecayTree"); Float_t MCEta_Mass11[20]; MC11InputTree->SetBranchAddress("Bu_DTFNoFix_eta_prime_M",&MCEta_Mass11); Int_t isSingle11; MC11InputTree->SetBranchAddress("isSingle",&isSingle11); TFile* MC11FlatOut = new TFile("MCMinimalFile11.root","RECREATE"); TTree* MC11FlatTree = MC11InputTree->CloneTree(0); Double_t MCBu_DTFNoFix_eta_Prime_MF11; MC11FlatTree->Branch("Bu_DTFNoFix_eta_prime_MF",&MCBu_DTFNoFix_eta_Prime_MF11,"Bu_DTFNoFix_eta_prime_MF/D"); Long64_t Entries11=MC11InputTree->GetEntries(); for(int i=0;i<Entries11;++i){ MC11InputTree->GetEntry(i); if(isSingle11==0)continue; MCBu_DTFNoFix_eta_Prime_MF11=MCEta_Mass11[0]; MC11FlatTree->Fill(); } MC11FlatTree->Write(); MC11FlatOut->Close(); } //_____________________________________________LOAD ROODATASETS___________________________________ TFile* MCFlatInput12= new TFile("MCMinimalFile12.root"); TTree* MCFlatInputTree12=(TTree*)MCFlatInput12->Get("DecayTree"); TFile* MCFlatInput11= new TFile("MCMinimalFile11.root"); TTree* MCFlatInputTree11=(TTree*)MCFlatInput11->Get("DecayTree"); RooRealVar MCBMass("Bu_DTF_MF","Bu_DTF_MF",5000.0,5600.0); RooRealVar MCEtaMass("eta_prime_MM","eta_prime_MM",700.0,1200.0); RooRealVar BDT_response("BDT_response","BDT_response",-1.0,1.0); RooRealVar gamma_CL("gamma_CL","gamma_CL",0.1,1.0); RooArgSet Args(MCBMass,MCEtaMass,BDT_response,gamma_CL); RooDataSet* MCData12 = new RooDataSet("MCData12","MCData12",Args,Import(*MCFlatInputTree12)); std::cout <<" Data File 12 Loaded"<<std::endl; RooDataSet* MCData11 = new RooDataSet("MCData11","MCData11",Args,Import(*MCFlatInputTree11)); std::cout<<" Data File 11 loaded"<<std::endl; RooDataSet* MCDataAll= new RooDataSet("MCDataAll","MCDataAll",Args); MCDataAll->append(*MCData12); MCDataAll->append(*MCData11); RooPlot* massFrame = MCBMass.frame(Title("Data Import Check"),Bins(50)); MCDataAll->plotOn(massFrame); RooPlot *BDTFrame = BDT_response.frame(Title("BDT Cut Check"),Bins(50)); MCDataAll->plotOn(BDTFrame); TCanvas C; C.Divide(2,1); C.cd(1); massFrame->Draw(); C.cd(2); BDTFrame->Draw(); C.SaveAs("ImportChecks.eps"); //________________________________MAKE MCROODATACATEGORIES__________________________________ RooDataSet* MCBData=(RooDataSet*)MCDataAll->reduce(RooArgSet(MCBMass)); MCBData->Print("v"); RooDataSet* MCEtaData=(RooDataSet*)MCDataAll->reduce(RooArgSet(MCEtaMass)); MCEtaData->Print("v"); RooCategory MCMassType("MCMassType","MCMassType") ; MCMassType.defineType("B") ; MCMassType.defineType("Eta") ; // Construct combined dataset in (x,sample) RooDataSet MCcombData("MCcombData","MC combined data",Args,Index(MCMassType),Import("B",*MCBData),Import("Eta",*MCEtaData)); //=============================================== MC FIT MODEL=================================== RooRealVar Mean("Mean","Mean",5279.29,5276.0,5284.00); RooRealVar Sigma("Sigma","Sigma",20.54,17.0,24.8); RooRealVar LAlpha("LAlpha","LAlpha",-1.064,-2.5,0.0); RooRealVar RAlpha("RAlpha","RAlpha",1.88,0.0,5.0); RooRealVar LN("LN","LN",13.0,0.0,40.0); RooRealVar RN("RN","RN",2.56,0.0,6.0); RooCBShape CBLeft("CBLeft","CBLeft",MCBMass,Mean,Sigma,LAlpha,LN); RooCBShape CBRight("CBRight","CBRight",MCBMass,Mean,Sigma,RAlpha,RN); RooRealVar FitFraction("FitFraction","FitFraction",0.5,0.0,1.0); RooAddPdf DCB("DCB","DCB",RooArgList(CBRight,CBLeft),FitFraction); RooRealVar SignalYield("SignalYield","SignalYield",4338.0,500.0,10000.0); // RooExtendPdf ExtDCB("ExtDCB","ExtDCB",DCB,SignalYield); //==============================ETA DCB ++++++++++++++++++++++++++++++ RooRealVar MCEtamean("MCEtamean","MCEtamean",958.0,955.0,960.0); RooRealVar MCEtasigma("MCEtasigma","MCEtasigma",9.16,8.0,14.0); RooRealVar EtaLAlpha("EtaLAlpha","EtaLAlpha",-1.45,-5.0,1.0); RooRealVar EtaRAlpha("EtaRAlpha","EtaRAlpha",1.76,0.0,4.0); RooRealVar EtaLN("EtaLN","EtaLN",0.1,0.0,20.0); RooRealVar EtaRN("EtaRN","EtaRN",0.1,0.0,20.0); RooCBShape EtaCBLeft("EtaCBLeft","EtaCBLeft",MCEtaMass,MCEtamean,MCEtasigma,EtaLAlpha,EtaLN); RooCBShape EtaCBRight("EtaCBRight","EtaCBRight",MCEtaMass,MCEtamean,MCEtasigma,EtaRAlpha,EtaRN); RooRealVar EtaFitFraction("EtaFitFraction","EtaFitFraction",0.22,0.1,1.0); RooAddPdf EtaDCB("EteaDCB","EtaDCB",RooArgList(EtaCBRight,EtaCBLeft),EtaFitFraction); RooProdPdf MCSignalPdf("MCSignalPdf","MCSignalPdf",RooArgSet(EtaDCB,DCB)); RooExtendPdf ExtendedMCSignalPdf("ExtendedMCSignalPdf","ExtendedMCSignalPdf",MCSignalPdf,SignalYield); RooSimultaneous MCsimPdf("MCsimPdf","MC simultaneous pdf",MCMassType) ; // MCsimPdf.addPdf(ExtDCB,"B"); // MCsimPdf.addPdf(ExtendedMCEtaDCB,"Eta"); //============================== DO the MC FIT ======================================= //MCsimPdf.fitTo(MCcombData,Extended(kTRUE),Minos(kTRUE)); //ExtendedMCEtaDCB.fitTo(*MCEtaData,Extended(kTRUE),Minos(kTRUE)); //ExtDCB.fitTo(*MCBData,Extended( ExtendedMCSignalPdf.fitTo(*MCDataAll,Extended(kTRUE),Minos(kTRUE)); RooPlot* MCframe1 = MCBMass.frame(Range(5100.0,5500.0),Bins(50),Title("B mass projection")); MCDataAll->plotOn(MCframe1); ExtendedMCSignalPdf.plotOn(MCframe1); ExtendedMCSignalPdf.paramOn(MCframe1); RooPlot* MCframe2 = MCEtaMass.frame(Range(880.0,1020.0),Bins(50),Title("Eta mass projection")) ; MCDataAll->plotOn(MCframe2); ExtendedMCSignalPdf.plotOn(MCframe2); ExtendedMCSignalPdf.paramOn(MCframe2); TCanvas* MCc = new TCanvas("rf501_simultaneouspdf","rf403_simultaneouspdf",1200,1000) ; gPad->SetLeftMargin(0.15) ; MCframe1->GetYaxis()->SetTitleOffset(1.4) ; MCframe1->Draw() ; MCc->SaveAs("MCSimulCanvas.pdf"); TCanvas* MCcEta = new TCanvas(" Eta Canvas","Eta Canvas",1200,1000); gPad->SetLeftMargin(0.15) ; MCframe2->GetYaxis()->SetTitleOffset(1.4) ; MCframe2->Draw() ; MCcEta->SaveAs("MCEtaCanvas.pdf"); TFile* MCFits= new TFile("MCFitResult.root","RECREATE"); // TCanvas* DecMCB=HandyFunctions::DecoratePlot(MCframe1); // TCanvas* DecMCEta=HandyFunctions::DecoratePlot(MCframe2); //DecMCEta->Write(); // DecMCB->Write(); MCc->Write(); MCcEta->Write(); std::cout<<"MC Eta Chi2 = "<<MCframe2->chiSquare()<<std::endl; std::cout<<"MC B Chi2 = "<<MCframe1->chiSquare()<<std::endl; //___________________________________ CUT DOWN COLLISION DATA ______________________________ if(ReDoCuts){ DataFile TwelveA(std::getenv("BUKETAPDATABDTRESPROOT"),Data,Twel,MagAll,buketap,"BDTApplied_SampleA"); DataFile TwelveB(std::getenv("BUKETAPDATABDTRESPROOT"),Data,Twel,MagAll,buketap,"BDTApplied_SampleB"); DataFile ElevenA(std::getenv("BUKETAPDATABDTRESPROOT"),Data,Elev,MagAll,buketap,"BDTApplied_SampleA"); DataFile ElevenB(std::getenv("BUKETAPDATABDTRESPROOT"),Data,Elev,MagAll,buketap,"BDTApplied_SampleB"); TRandom3* DataRand= new TRandom3(224); TH1I* DataNCand12= new TH1I("DataNCand12","DataNCand12",10,0,10); TH1I* DataNCand11= new TH1I("DataNCand11","DataNCand11",10,0,10); TreeReader* UncutDataReader12= new TreeReader("DecayTree"); UncutDataReader12->AddFile(TwelveA); UncutDataReader12->AddFile(TwelveB); UncutDataReader12->Initialize(); TFile* CutDataFile12 = new TFile("CutDataFile12.root","RECREATE"); TTree* CutDataTree12 = UncutDataReader12->CopyTree(TwelveCut,-1,"DecayTree"); TTree* SingleCutDataTree12=HandyFunctions::GetSingleTree(DataRand,CutDataTree12,DataNCand12,NULL); SingleCutDataTree12->Write(); CutDataFile12->Close(); TreeReader* UncutDataReader11= new TreeReader("DecayTree"); UncutDataReader11->AddFile(ElevenB); UncutDataReader11->AddFile(ElevenA); UncutDataReader11->Initialize(); TFile* CutDataFile11 = new TFile("CutDataFile11.root","RECREATE"); TTree* CutDataTree11 = UncutDataReader11->CopyTree(ElevenCut,-1,"DecayTree"); TTree* SingleCutDataTree11=HandyFunctions::GetSingleTree(DataRand,CutDataTree11,DataNCand11,NULL); SingleCutDataTree11->Write(); CutDataFile11->Close(); TFile* DataInput12 = new TFile("CutDataFile12.root"); TTree* DataInputTree12=(TTree*)DataInput12->Get("DecayTree"); DataInputTree12->SetBranchStatus("*",0); DataInputTree12->SetBranchStatus("Bu_DTF_MF",1); DataInputTree12->SetBranchStatus("Bu_DTFNoFix_eta_prime_M",1); DataInputTree12->SetBranchStatus("eta_prime_MM",1); DataInputTree12->SetBranchStatus("isSingle",1); Float_t Eta_Mass12[20]; DataInputTree12->SetBranchAddress("Bu_DTFNoFix_eta_prime_M",&Eta_Mass12); Int_t isSingle12; DataInputTree12->SetBranchAddress("isSingle",&isSingle12); TFile* MinimalDataFile12 = new TFile("MinimalDataFile12.root","RECREATE"); TTree* MinimalDataTree12= DataInputTree12->CloneTree(0); Double_t Bu_DTFNoFix_eta_prime_MF12; MinimalDataTree12->Branch("Bu_DTFNoFix_eta_prime_MF",&Bu_DTFNoFix_eta_prime_MF12,"Bu_DTFNoFix_eta_prime_MF/D"); Long64_t Entries12=DataInputTree12->GetEntries(); for(int i=0;i<Entries12;++i){ DataInputTree12->GetEntry(i); if(isSingle12==0)continue; Bu_DTFNoFix_eta_prime_MF12=Eta_Mass12[0]; MinimalDataTree12->Fill(); } MinimalDataTree12->Write(); MinimalDataFile12->Close(); TFile* DataInput11 = new TFile("CutDataFile11.root"); TTree* DataInputTree11=(TTree*)DataInput11->Get("DecayTree"); DataInputTree11->SetBranchStatus("*",0); DataInputTree11->SetBranchStatus("Bu_DTF_MF",1); DataInputTree11->SetBranchStatus("Bu_DTFNoFix_eta_prime_M",1); DataInputTree11->SetBranchStatus("eta_prime_MM",1); DataInputTree11->SetBranchStatus("isSingle",1); Float_t Eta_Mass11[20]; DataInputTree11->SetBranchAddress("Bu_DTFNoFix_eta_prime_M",&Eta_Mass11); Int_t isSingle11; DataInputTree11->SetBranchAddress("isSingle",&isSingle11); TFile* MinimalDataFile11 = new TFile("MinimalDataFile11.root","RECREATE"); TTree* MinimalDataTree11= DataInputTree11->CloneTree(0); Double_t Bu_DTFNoFix_eta_prime_MF11; MinimalDataTree11->Branch("Bu_DTFNoFix_eta_prime_MF",&Bu_DTFNoFix_eta_prime_MF11,"Bu_DTFNoFix_eta_prime_MF/D"); Long64_t Entries11=DataInputTree11->GetEntries(); for(int i=0;i<Entries11;++i){ DataInputTree11->GetEntry(i); if(isSingle11==0)continue; Bu_DTFNoFix_eta_prime_MF11=Eta_Mass11[0]; MinimalDataTree11->Fill(); } MinimalDataTree11->Write(); MinimalDataFile11->Close(); } //___________________________________ LOAD DATA TO ROODATASET____________________________________ RooRealVar BMass("Bu_DTF_MF","Bu_DTF_MF",5000.0,5600.0); RooRealVar EtaMass("eta_prime_MM","eta_prime_MM",870.0,1050.0); RooArgSet MassArgs(BMass,EtaMass); TFile* Data12File = new TFile("MinimalDataFile12.root"); TTree* DataTree12=(TTree*)Data12File->Get("DecayTree"); RooDataSet* Data12 = new RooDataSet("Data12","Data12",MassArgs,Import(*DataTree12)); TFile* Data11File = new TFile("MinimalDataFile11.root"); TTree* DataTree11=(TTree*)Data11File->Get("DecayTree"); RooDataSet* Data11 = new RooDataSet("Data11","Data11",MassArgs,Import(*DataTree11)); RooDataSet* AllData = new RooDataSet("AllData","AllData",MassArgs); AllData->append(*Data12); AllData->append(*Data11); TCanvas ImportC; RooPlot* ImportCheck = BMass.frame(Title("ImportCheck"),Bins(50)); AllData->plotOn(ImportCheck); ImportCheck->Draw(); ImportC.SaveAs("Alldataimport.pdf"); std::cout<<" Data Loaded, Total Entries = "<<AllData->numEntries()<<std::endl; AllData->Print("v"); RooDataSet* BData=(RooDataSet*)AllData->reduce(RooArgSet(BMass)); BData->Print("v"); RooDataSet* EtaData=(RooDataSet*)AllData->reduce(RooArgSet(EtaMass)); EtaData->Print("v"); //___________________________________Fit to Eta_Prime in BMass Sidebands______________________ RooDataSet* BSidebands=(RooDataSet*)AllData->reduce(Cut("(Bu_DTF_MF>5000.0&&Bu_DTF_MF<5179.0)||(Bu_DTF_MF>5379.0&&Bu_DTF_MF<5800.0)")); TCanvas BSidebandCanvas; RooPlot* BSidebandPlot = EtaMass.frame(Title("B sidebands"),Bins(30)); BSidebands->plotOn(BSidebandPlot); BSidebandPlot->Draw(); BSidebandCanvas.SaveAs("BSidebandDataCheck.pdf"); RooRealVar BsbMean(" Mean","BsbMean",958.0,900.0,1020.0); RooRealVar BsbSigma(" Sigma","BsbSigma",19.8,10.0,40.8); RooRealVar BsbLAlpha(" Alpha","BsbLAlpha",-1.63,-10.0,0.0); // RooRealVar BsbRAlpha("BsbRAlpha","BsbRAlpha",1.47,0.0,10.0); RooRealVar BsbLN(" N","BsbLN",0.1,0.0,20.0); // RooRealVar BsbRN("BsbRN","BsbRN",0.1,0.0,20.0); RooCBShape BsbCBLeft("BsbCBLeft","BsbCBLeft",EtaMass,BsbMean,BsbSigma,BsbLAlpha,BsbLN); // RooCBShape BsbCBRight("BsbCBRight","BsbCBRight",EtaMass,BsbMean,BsbSigma,BsbRAlpha,BsbRN); // RooRealVar BsbFitFraction("BsbFitFraction","BsbFitFraction",0.5,0.0,1.0); // RooAddPdf BsbDCB("BsbDCB","BsbDCB",RooArgList(BsbCBRight,BsbCBLeft),BsbFitFraction); RooRealVar Bsbslope("Bsbslope","Bsbslope",0.5,0.0,1.0); RooRealVar BsbP2("BsbP2","BsbP2",-0.5,-1.0,0.0); RooChebychev BsbLinear("BsbLinear","BsbLinear",EtaMass,RooArgSet(Bsbslope,BsbP2)); RooRealVar BsbFitFraction("BsbFitFraction","BsbFitFraction",0.2,0.0,1.0); RooAddPdf BsbBackground("BsbBackground","BsbBackground",RooArgList(BsbLinear,BsbCBLeft),BsbFitFraction); RooRealVar BsbYield(" Yield","BsbYield",500.0,0.0,1000.0); RooExtendPdf BsbExtDCB("BsbExtDCB","BsbExtDCB",BsbCBLeft,BsbYield); BsbExtDCB.fitTo(*BSidebands,Extended(kTRUE),Minos(kTRUE)); TCanvas BSBFitCanvas; RooPlot* BSBFitPlot = EtaMass.frame(Title("Eta fit in B Sidebands"),Bins(30)); BSidebands->plotOn(BSBFitPlot); BsbExtDCB.plotOn(BSBFitPlot); BsbExtDCB.paramOn(BSBFitPlot); BSBFitPlot->Draw(); BSBFitCanvas.SaveAs("BSidebandFit.pdf"); TFile * SidebandFitFile= new TFile("SidebandFit.root","RECREATE"); BSBFitCanvas.Write(); SidebandFitFile->Close(); //___________________________________DO THE 2D FIT TO DATA___________________________________ const double PDGBMass= 5279.26; BMass.setRange("SignalWindow",PDGBMass-(3*Sigma.getVal()),PDGBMass+(3*Sigma.getVal())); RooRealVar DSignalYield("DSignalYield","DSignalYield",4000.0,0.0,10000.0); //================================= B MASS SIGNAL PDF============================== RooRealVar DMean("Mean","DMean",5279.29,5270.0,5290.00); RooRealVar DSigma("Sigma","DSigma",19.8,10.0,40.8); RooRealVar DLAlpha("DLAlpha","DLAlpha",LAlpha.getVal()); RooRealVar DRAlpha("DRAlpha","DRAlpha",RAlpha.getVal()); RooRealVar DLN("DLN","DLN",LN.getVal()); RooRealVar DRN("DRN","DRN",RN.getVal()); RooCBShape DCBLeft("DCBLeft","DCBLeft",BMass,DMean,DSigma,DLAlpha,DLN); RooCBShape DCBRight("DCBRight","DCBRight",BMass,DMean,DSigma,DRAlpha,DRN); RooRealVar DFitFraction("FitFraction","DFitFraction",0.5,0.0,1.0); RooAddPdf DDCB("DDCB","DDCB",RooArgList(DCBRight,DCBLeft),DFitFraction); //==============================B MASS BKG PDF============================== RooRealVar slope("slope","slope",-0.5,-1.0,0.0); RooChebychev bkg("bkg","Background",BMass,RooArgSet(slope)); //==============================Eta mass signal pdf================================ RooRealVar DEtamean("Etamean","DEtamean",958.0,945.0,980.0) ; RooRealVar DEtasigma("Etasigma","DEtasigma",15.0,5.0,65.0) ; RooRealVar DEtaLAlpha("DEtaLAlpha","DEtaLAlpha",EtaLAlpha.getVal()); RooRealVar DEtaRAlpha("DEtaRAlpha","DEtaRAlpha",EtaRAlpha.getVal()); RooRealVar DEtaLN("DEtaLN","DEtaLN",EtaLN.getVal()); RooRealVar DEtaRN("DEtaRN","DEtaRN",EtaRN.getVal()); RooCBShape EtaDCBLeft("EtaDCBLeft","EtaDCBLeft",EtaMass,DEtamean,DEtasigma,DEtaLAlpha,DEtaLN); RooCBShape EtaDCBRight("EtaDCBRight","EtaDCBRight",EtaMass,DEtamean,DEtasigma,DEtaRAlpha,DEtaRN); RooRealVar DEtaFitFraction("EtaFitFraction","DEtaFitFraction",0.5,0.0,1.0); RooAddPdf EtaDDCB("EtaDDCB","EtaDDCB",RooArgList(EtaDCBRight,EtaDCBLeft),DEtaFitFraction); RooProdPdf DSignalPdf("DSignalPdf","DSignalPdf",RooArgList(EtaDDCB,DDCB)); RooExtendPdf DExtSignalPdf("DExtSignalPdf","DExtSignalPdf",DSignalPdf,DSignalYield); //=============================== Eta mass bkg pdf================================== RooRealVar EtaBkgMean("EtaBkgMean","EtaBkgMean",958.0,900.0,1020.0); RooRealVar EtaBkgSigma("EtaBkgSigma","EtaBkgSigma",19.8,10.0,40.8); RooRealVar EtaBkgLAlpha("EtaBkgLAlpha","EtaBkgLAlpha",BsbLAlpha.getVal()); // RooRealVar EtaBkgRAlpha("EtaBkgRAlpha","EtaBkgRAlpha",BsbRAlpha.getVal()); RooRealVar EtaBkgLN("EtaBkgLN","EtaBkgLN",BsbLN.getVal()); // RooRealVar EtaBkgRN("EtaBkgRN","EtaBkgRN",BsbRN.getVal()); RooCBShape EtaBkgCBLeft("EtaBkgCBLeft","EtaBkgCBLeft",EtaMass,DEtamean,EtaBkgSigma,EtaBkgLAlpha,EtaBkgLN); // RooCBShape EtaBkgCBRight("EtaBkgCBRight","EtaBkgCBRight",EtaMass,DEtamean,EtaBkgSigma,EtaBkgRAlpha,EtaBkgRN); // RooRealVar EtaBkgFitFraction("EtaBkgFitFraction","EtaBkgFitFraction",0.5,0.0,1.0); // RooAddPdf EtaBkgDCB("EtaBkgDCB","EtaBkgDCB",RooArgList(EtaBkgCBRight,EtaBkgCBLeft),EtaBkgFitFraction); RooProdPdf DataBackgroundPDF("DataBackgroundPDF","DataBackgroundPDF",RooArgList(EtaBkgCBLeft,bkg)); RooRealVar DataBackgroundYield("BackgroundYield","DataBackgroundYield",500.0,0.0,10000.0); RooExtendPdf ExtDataBackgroundPDF("ExtDataBackgroundPDF","ExtDataBackgroundPDF",DataBackgroundPDF,DataBackgroundYield); RooAddPdf TotalPDF("TotalPDF","TotalPDF",RooArgList(ExtDataBackgroundPDF,DExtSignalPdf)); std::cout<<"Dependents = "<<std::endl; RooArgSet* Dependents=TotalPDF.getDependents(AllData); Dependents->Print("v"); std::cout<<"parameters= "<<std::endl; RooArgSet* parameters=TotalPDF.getParameters(AllData); parameters->Print("v"); RooCategory MassType("MassType","MassType") ; MassType.defineType("B") ; MassType.defineType("Eta") ; // Construct combined dataset in (x,sample) RooDataSet combData("combData","combined data",MassArgs,Index(MassType),Import("B",*BData),Import("Eta",*EtaData)); RooSimultaneous simPdf("simPdf","simultaneous pdf",MassType) ; // Associate model with the physics state and model_ctl with the control state // simPdf.addPdf(WholeFit,"B"); // simPdf.addPdf(WholeEtaFit,"Eta"); // simPdf.fitTo(combData,Extended(kTRUE)/*,Minos(kTRUE)*/); TotalPDF.fitTo(*AllData,Extended(kTRUE),Minos(kTRUE)); RooPlot* frame1 = BMass.frame(Bins(50),Title("B mass projection")); AllData->plotOn(frame1); TotalPDF.plotOn(frame1,Components(ExtDataBackgroundPDF),LineStyle(kDashed),LineColor(kRed)); TotalPDF.plotOn(frame1); TotalPDF.paramOn(frame1); // The same plot for the control sample slice RooPlot* frame2 = EtaMass.frame(Bins(50),Title("Eta mass projection")) ; AllData->plotOn(frame2); TotalPDF.plotOn(frame2,Components(ExtDataBackgroundPDF),LineStyle(kDashed),LineColor(kRed)); TotalPDF.plotOn(frame2); TotalPDF.paramOn(frame2); TCanvas* DecoratedCanvas =HandyFunctions::DecoratePlot(frame2); TCanvas* DataBC= new TCanvas("BCanvas","BCanvas",1200,1000) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.4) ; frame1->Draw() ; TCanvas* EtaBC= new TCanvas("EtaCanvas","EtaCanvas",1200,1000) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.4) ; frame2->Draw() ; DataBC->SaveAs("DataBC.pdf"); EtaBC->SaveAs("EtaBC.pdf"); TFile * DataSimulFit = new TFile("DataSimulFit.root","RECREATE"); DataBC->Write(); EtaBC->Write(); DecoratedCanvas->Write(); }
// This one can load both leftover map files on game discs (like Zelda), and mapfiles // produced by SaveSymbolMap below. // bad=true means carefully load map files that might not be from exactly the right version bool PPCSymbolDB::LoadMap(const std::string& filename, bool bad) { File::IOFile f(filename, "r"); if (!f) return false; // four columns are used in American Mensa Academy map files and perhaps other games bool four_columns = false; int good_count = 0; int bad_count = 0; char line[512]; std::string section_name; while (fgets(line, 512, f.GetHandle())) { size_t length = strlen(line); if (length < 4) continue; if (length == 34 && strcmp(line, " address Size address offset\n") == 0) { four_columns = true; continue; } char temp[256]; sscanf(line, "%255s", temp); if (strcmp(temp, "UNUSED") == 0) continue; // Support CodeWarrior and Dolphin map if (StringEndsWith(line, " section layout\n") || strcmp(temp, ".text") == 0 || strcmp(temp, ".init") == 0) { section_name = temp; continue; } // Skip four columns' header. // // Four columns example: // // .text section layout // Starting Virtual // address Size address // ----------------------- if (strcmp(temp, "Starting") == 0) continue; if (strcmp(temp, "address") == 0) continue; if (strcmp(temp, "-----------------------") == 0) continue; // Skip link map. // // Link map example: // // Link map of __start // 1] __start(func, weak) found in os.a __start.c // 2] __init_registers(func, local) found in os.a __start.c // 3] _stack_addr found as linker generated symbol // ... // 10] EXILock(func, global) found in exi.a EXIBios.c if (StringEndsWith(temp, "]")) continue; // TODO - Handle/Write a parser for: // - Memory map // - Link map // - Linker generated symbols if (section_name.empty()) continue; u32 address, vaddress, size, offset, alignment; char name[512], container[512]; if (four_columns) { // sometimes there is no alignment value, and sometimes it is because it is an entry of // something else if (length > 37 && line[37] == ' ') { alignment = 0; sscanf(line, "%08x %08x %08x %08x %511s", &address, &size, &vaddress, &offset, name); char* s = strstr(line, "(entry of "); if (s) { sscanf(s + 10, "%511s", container); char* s2 = (strchr(container, ')')); if (s2 && container[0] != '.') { s2[0] = '\0'; strcat(container, "::"); strcat(container, name); strcpy(name, container); } } } else { sscanf(line, "%08x %08x %08x %08x %i %511s", &address, &size, &vaddress, &offset, &alignment, name); } } // some entries in the table have a function name followed by " (entry of " followed by a // container name, followed by ")" // instead of a space followed by a number followed by a space followed by a name else if (length > 27 && line[27] != ' ' && strstr(line, "(entry of ")) { alignment = 0; sscanf(line, "%08x %08x %08x %511s", &address, &size, &vaddress, name); char* s = strstr(line, "(entry of "); if (s) { sscanf(s + 10, "%511s", container); char* s2 = (strchr(container, ')')); if (s2 && container[0] != '.') { s2[0] = '\0'; strcat(container, "::"); strcat(container, name); strcpy(name, container); } } } else { sscanf(line, "%08x %08x %08x %i %511s", &address, &size, &vaddress, &alignment, name); } const char* namepos = strstr(line, name); if (namepos != nullptr) // would be odd if not :P strcpy(name, namepos); name[strlen(name) - 1] = 0; if (name[strlen(name) - 1] == '\r') name[strlen(name) - 1] = 0; // Check if this is a valid entry. if (strlen(name) > 0) { // Can't compute the checksum if not in RAM bool good = !bad && PowerPC::HostIsInstructionRAMAddress(vaddress) && PowerPC::HostIsInstructionRAMAddress(vaddress + size - 4); if (!good) { // check for BLR before function PowerPC::TryReadInstResult read_result = PowerPC::TryReadInstruction(vaddress - 4); if (read_result.valid && read_result.hex == 0x4e800020) { // check for BLR at end of function read_result = PowerPC::TryReadInstruction(vaddress + size - 4); good = read_result.valid && read_result.hex == 0x4e800020; } } if (good) { ++good_count; if (section_name == ".text" || section_name == ".init") AddKnownSymbol(vaddress, size, name, Symbol::Type::Function); else AddKnownSymbol(vaddress, size, name, Symbol::Type::Data); } else { ++bad_count; } } } Index(); if (bad) SuccessAlertT("Loaded %d good functions, ignored %d bad functions.", good_count, bad_count); return true; }
void cSkeleton<_DataType>::ComputeDistance() { int i, j, k, n, df_i, db_i, d_i, Tempi; int MaxRes, *Buffer_i; printf ("Computing Distance ... \n"); fflush(stdout); if (Distance_mi == NULL) { printf ("Distance_mi is NULL\n"); exit(1); } MaxRes = (Width_mi>Height_mi)? Width_mi : Height_mi; MaxRes = (MaxRes>Depth_mi)? MaxRes : Depth_mi; Buffer_i = new int [MaxRes]; // Step 1: X-axis // Forward scan for (k=0; k<Depth_mi; k++) { for (j=0; j<Height_mi; j++) { df_i = Width_mi-1; for (i=0; i<Width_mi; i++) { if (Distance_mi[Index(i, j, k)]>0) df_i++; else df_i = 0; Distance_mi[Index(i, j, k)] = df_i*df_i; } } } // Backward scan for (k=0; k<Depth_mi; k++) { for (j=0; j<Height_mi; j++) { db_i = Width_mi-1; for (i=Width_mi-1; i>=0; i--) { if (Distance_mi[Index(i, j, k)]>0) db_i++; else db_i = 0; Tempi = Distance_mi[Index(i, j, k)]; Distance_mi[Index(i, j, k)] = (Tempi < db_i*db_i)? Tempi : db_i*db_i; } } } // Step 2: Y-axis int w_i, rStart, rMax, rEnd; for (k=0; k<Depth_mi; k++) { for (i=0; i<Width_mi; i++) { for (j=0; j<Height_mi; j++) { Buffer_i[j] = Distance_mi[Index(i, j, k)]; } for (j=0; j<Height_mi; j++) { d_i = Buffer_i[j]; if (d_i>0) { rMax = (int)(sqrt((double)d_i)) + 1; rStart = (rMax<(j-1))? rMax : (j-1); rEnd = (rMax<(Height_mi-1 - j))? rMax : (Height_mi-1 - j); for (n=-rStart; n<=rEnd; n++) { w_i = Buffer_i[j+n] + n*n; if (w_i<d_i) d_i = w_i; } } Distance_mi[Index(i, j, k)] = d_i; } } } // Step 3: Z-axis for (j=0; j<Height_mi; j++) { for (i=0; i<Width_mi; i++) { for (k=0; k<Depth_mi; k++) { Buffer_i[k] = Distance_mi[Index(i, j, k)]; } for (k=0; k<Depth_mi; k++) { d_i = Buffer_i[k]; if (d_i>0) { rMax = (int)(sqrt((double)d_i)) + 1; rStart = (rMax<(k-1))? rMax : (k-1); rEnd = (rMax<(Depth_mi-1 - k))? rMax : (Depth_mi-1 - k); for (n=-rStart; n<=rEnd; n++) { w_i = Buffer_i[k+n] + n*n; if (w_i<d_i) d_i = w_i; } } Distance_mi[Index(i, j, k)] = d_i; } } } #ifdef DEBUG_DIST_TF printf ("\nStep 3:\n"); Display_Distance(76); printf ("\nStep 3:\n"); Display_Distance(77); printf ("\nStep 3:\n"); Display_Distance(78); printf ("\nStep 3:\n"); Display_Distance(79); printf ("\nStep 3:\n"); Display_Distance(80); printf ("\nStep 3:\n"); Display_Distance(81); printf ("\nStep 3:\n"); Display_Distance(82); printf ("\nStep 3:\n"); Display_Distance(83); printf ("\nStep 3:\n"); Display_Distance(84); printf ("\nStep 3:\n"); Display_Distance(85); printf ("\nStep 3:\n"); Display_Distance(86); #endif delete [] Buffer_i; }
LUA_API void lua_rawset (lua_State *L, int index) { StkId t = Index(L, index); LUA_ASSERT(ttype(t) == LUA_TTABLE, "table expected"); *luaH_set(L, hvalue(t), L->top-2) = *(L->top-1); L->top -= 2; }
void cSkeleton<_DataType>::FlagNonUniformGradient() { int i, j, k, l, m, n, Idx, loc[8]; int NumNonunifromVoxels, IsNonuniform; float AveVec_f[3], DotProduct_f, Tempf; printf ("\n"); printf ("Flag NonUniform Gradient() ... \n"); fflush(stdout); for (k=1; k<Depth_mi-1; k++) { for (j=1; j<Height_mi-1; j++) { for (i=1; i<Width_mi-1; i++) { loc[0] = Index (i, j, k); if (VoxelFlags_muc[loc[0]]==FLAG_EMPTY || VoxelFlags_muc[loc[0]]==FLAG_NONUNIFORM) continue; if (Distance_mi[loc[0]]<=1) continue; for (m=0; m<3; m++) AveVec_f[m] = 0.0; Idx = 0; for (n=k; n<=k+1; n++) { for (m=j; m<=j+1; m++) { for (l=i; l<=i+1; l++) { loc[Idx] = Index (l, m, n); AveVec_f[0] += GVFDistance_mf[loc[Idx]*3 + 0]; AveVec_f[1] += GVFDistance_mf[loc[Idx]*3 + 1]; AveVec_f[2] += GVFDistance_mf[loc[Idx]*3 + 2]; Idx++; } } } for (l=0; l<3; l++) AveVec_f[l] /= 8.0; // When the vector length is zero, then mark the voxels as nonuniform voxels Tempf = fsqrt (AveVec_f[0]*AveVec_f[0] + AveVec_f[1]*AveVec_f[1] + AveVec_f[2]*AveVec_f[2]); if (Tempf<1e-6) { for (m=0; m<8; m++) VoxelFlags_muc[loc[m]] = FLAG_NONUNIFORM; continue; } IsNonuniform = false; for (m=0; m<8; m++) { DotProduct_f = 0; for (l=0; l<3; l++) { DotProduct_f += AveVec_f[l]*GVFDistance_mf[loc[m]*3 + l]; } if (DotProduct_f<=0) { IsNonuniform = true; break; } } if (IsNonuniform) { for (m=0; m<8; m++) VoxelFlags_muc[loc[m]] = FLAG_NONUNIFORM; } } } } NumNonunifromVoxels = 0; for (i=0; i<WHD_mi; i++) { if (VoxelFlags_muc[i]==FLAG_NONUNIFORM) NumNonunifromVoxels++; } printf ("Num. Nonuniform Voxels = %d\n", NumNonunifromVoxels); printf ("Num. Segmented Voxels = %d\n", NumSegmentedVoxels_mi); printf ("Num. Nonuniform / NumSegmented = %f %%\n", (float)NumNonunifromVoxels/NumSegmentedVoxels_mi*100.0); printf ("Num. Nonuniform / Total Num. Voxels = %f %%\n", (double)NumNonunifromVoxels/WHD_mi*100.0); fflush (stdout); }
LUA_API void lua_rawseti (lua_State *L, int index, int n) { StkId o = Index(L, index); LUA_ASSERT(ttype(o) == LUA_TTABLE, "table expected"); *luaH_setint(L, hvalue(o), n) = *(L->top-1); L->top--; }
void cSkeleton<_DataType>::FindingRootAndEndLoc(int MaxCCLoc, int &RootLoc_Ret, int &EndLoc_Ret) { int i, j, k, X_i, Y_i, Z_i, loc[3]; int Root_i[3]; printf ("Finding the root and end voxels...\n"); fflush (stdout); //----------------------------------------------------------------------- // Finding the root voxel of skeleton // The root voxel has the smallest Y coordinate, which means that // it is the front of the heart Root_i[0] = 0; // X Coordinate Root_i[1] = Height_mi; // Y Coordinate Root_i[2] = 0; // Z coordinate for (j=0; j<Height_mi; j++) { for (k=0; k<Depth_mi; k++) { for (i=0; i<Width_mi; i++) { if (CCVolume_muc[Index(i, j, k)]==255) { Root_i[0] = i; Root_i[1] = j; Root_i[2] = k; i = j = k = WHD_mi; // Exiting this three overlapped loops } } } } RootLoc_Ret = Index (Root_i[0], Root_i[1], Root_i[2]); printf ("The root voxel = (%d, %d, %d)\n", Root_i[0], Root_i[1], Root_i[2]); fflush (stdout); //----------------------------------------------------------------------- //----------------------------------------------------------------------- // Finding the end voxels of skeleton // The end voxel is the farthest voxel from the root voxel map<int, unsigned char> CurrBoundary_m; DistanceFromSkeletons_mi = new int [WHD_mi]; loc[0] = RootLoc_Ret; CurrBoundary_m.clear(); CurrBoundary_m[loc[0]] = (unsigned char)1; // Adding the current location EndLoc_Ret = ComputeDistanceFromCurrSkeletons (CurrBoundary_m); CurrBoundary_m.clear(); Z_i = EndLoc_Ret/WtimesH_mi; Y_i = (EndLoc_Ret - Z_i*WtimesH_mi)/Width_mi; X_i = EndLoc_Ret % Width_mi; printf ("The end voxel = (%d, %d, %d)\n", X_i, Y_i, Z_i); //----------------------------------------------------------------------- int Maxi=-9999999, Mini=9999999; for (i=0; i<WHD_mi; i++) { if (Mini > DistanceFromSkeletons_mi[i]) Mini = DistanceFromSkeletons_mi[i]; if (Maxi < DistanceFromSkeletons_mi[i]) Maxi = DistanceFromSkeletons_mi[i]; } printf ("Min & Max distance from the root = %d, %d\n", Mini, Maxi); fflush (stdout); }
TObject *luaA_index (lua_State *L, int index) { return Index(L, index); }
void turn_by_turn(struct each_path *shortest_ways,int ways)//"ways" save the number of the shorest ways,shortest_ways[] save all the shortest pathes { int i; printf("/---------------------Next Path-------------------/\n"); for (i=1;i<=ways;i++) { path_link present,next,future; present=&shortest_ways[i]; next=present->next_node; future=next->next_node; next->section_distance=next->distance; float x1,yl,x2,y2,x3,y3; if (present->unique_num==1)//if the presetn node is start node,take the x and y value in special ways { x1=start_x; yl=start_y; } else if (present->unique_num!=1) { x1=present->x; yl=present->y; } if (next->unique_num==2)//if the next node is destination node,take the x and y value in special ways { x2=destination_x; y2=destination_y; } else if (next->unique_num!=2) { x2=next->x; y2=next->y; } if (x1>x2 && yl>y2)//diceide the first direction printf("Head SouthWest "); else if (x1<x2 && yl>y2) printf("Head SouthEast "); else if (x1>x2 && yl<y2) printf("Head NorthWest "); else if (x1<x2 && yl<y2) printf("Head NorthEest "); else if (x1>x2 && yl==y2) printf("Head West "); else if (x1<x2 && yl==y2) printf("Head Eest "); else if (x1==x2 && yl<y2) printf("Head North "); else if (x1==x2 && yl>y2) printf("Head South "); int present_label,future_label,next_label; int j,k; char start_street[20]; present_label=Index(present->unique_num); next_label=Index(next->unique_num); for (j=1;j<=adj_list[present_label].present_num;j++)//find the start_street name { int get_name=0; for (k=1;k<=adj_list[next_label].present_num;k++) if (strcmp(adj_list[present_label].street_name[j],adj_list[next_label].street_name[k])==0) { get_name=1; strcpy(start_street,adj_list[present_label].street_name[j]); break; } if (get_name==1) break; } printf("on %s.\n",start_street);//start_street must be the same street for both first node and the second node if (future==NULL)//if future==NULL means they are very closed. { float distance,miles,decimal;//to find out the miles in 1 decimal place and the foot in integer int integer,feet; distance=next->section_distance; distance=distance*10; integer=distance/1; decimal=distance-integer; miles=(float)integer/10; feet=5280*decimal/10; if (miles==0) printf("stop on street %s,house number is %d,in %d foot.\n",destination_street,destination_house,feet); else if (feet==0) printf("stop on street %s,house number is %d,in %.1f miles.\n",destination_street,destination_house,miles); else if (miles>0 && feet>0) printf("stop on street %s,house number is %d,in %.1f miles and %d foot.\n",destination_street,destination_house,miles,feet); } while (future!=NULL) { present_label=Index(present->unique_num); future_label=Index(future->unique_num); next_label=Index(next->unique_num); int same_street=0;//to check whether the future node has the same as the previous two nodes char same_street_name[20]; for (j=1;j<=adj_list[present_label].present_num;j++) { int get_name=0; for (k=1;k<=adj_list[next_label].present_num;k++) if (strcmp(adj_list[present_label].street_name[j],adj_list[next_label].street_name[k])==0) { get_name=1; strcpy(same_street_name,adj_list[present_label].street_name[j]); break; } if (get_name==1) break; } for (k=1;k<=adj_list[future_label].present_num;k++) if (strcmp(same_street_name,adj_list[future_label].street_name[k])==0) { same_street=1; break; } if (same_street==1)//if they are in the same street { future->section_distance=future->distance+next->section_distance; future=future->next_node; next=next->next_node; present=present->next_node; if (future==NULL) { float distance,miles,decimal;//to find out the miles in 1 decimal place and the foot in integer int integer,feet; distance=next->section_distance; distance=distance*10; integer=distance/1; decimal=distance-integer; miles=(float)integer/10; feet=5280*decimal/10; if (miles==0) printf("stop on street %s,house number is %d,in %d foot.\n",destination_street,destination_house,feet); else if (feet==0) printf("stop on street %s,house number is %d,in %.1f miles.\n",destination_street,destination_house,miles); else if (miles>0 && feet>0) printf("stop on street %s,house number is %d,in %.1f miles and %d foot.\n",destination_street,destination_house,miles,feet); } while (future!=NULL) { int go_ahead=0; future_label=Index(future->unique_num); for (k=1;k<=adj_list[future_label].present_num;k++)//if they are still in a same street,continue to find.Until emerge a node in a different street. if (strcmp(same_street_name,adj_list[future_label].street_name[k])==0) { go_ahead=1; future->section_distance=future->distance+next->section_distance; future=future->next_node; next=next->next_node; present=present->next_node; break; } if (future==NULL) { float distance,miles,decimal;//to find out the miles in 1 decimal place and the foot in integer int integer,feet; distance=next->section_distance; distance=distance*10; integer=distance/1; decimal=distance-integer; miles=(float)integer/10; feet=5280*decimal/10; if (miles==0) printf("stop on street %s,house number is %d,in %d foot.\n",destination_street,destination_house,feet); else if (feet==0) printf("stop on street %s,house number is %d,in %.1f miles.\n",destination_street,destination_house,miles); else if (miles>0 && feet>0) printf("stop on street %s,house number is %d,in %.1f miles and %d foot.\n",destination_street,destination_house,miles,feet); } if (go_ahead==0)//has to stop and turn a direction { float distance,miles,decimal;//to find out the miles in 1 decimal place and the foot in integer int integer,feet; distance=next->section_distance; distance=distance*10; integer=distance/1; decimal=distance-integer; miles=(float)integer/10; feet=5280*decimal/10; if (miles==0) printf("go to the vertex %d %d in %d foot.And then ",next->x,next->y,feet); else if (feet==0) printf("go to the vertex %d %d in %.1f miles.And then ",next->x,next->y,miles); else if (miles>0 && feet>0) printf("go to the vertex %d %d in %.1f miles and %d foot.And then ",next->x,next->y,miles,feet); if (present->unique_num==1 && future->unique_num==2) { x1=start_x; yl=start_y; x2=next->x; y2=next->y; x3=destination_x; y3=destination_y; } else if (present->unique_num==1 && future->unique_num!=2) { x1=start_x; yl=start_y; x2=next->x; y2=next->y; x3=future->x; y3=future->y; } else if (present->unique_num!=1 && future->unique_num==2) { x1=present->x; yl=present->y; x2=next->x; y2=next->y; x3=destination_x; y3=destination_y; } else if (present->unique_num!=1 && future->unique_num!=2) { x1=present->x; yl=present->y; x2=next->x; y2=next->y; x3=future->x; y3=future->y; } direction(x1,yl,x2,y2,x3,y3);//output the direction by using three pairs of coordinates next_label=Index(next->unique_num); char next_street[10]; for (j=1;j<=adj_list[next_label].present_num;j++)//find the street name after turn a direction { int get_name=0; for (k=1;k<=adj_list[future_label].present_num;k++) if (strcmp(adj_list[next_label].street_name[j],adj_list[future_label].street_name[k])==0) { get_name=1; strcpy(next_street,adj_list[next_label].street_name[j]); break; } if (get_name==1) break; } printf("onto %s\n",next_street);//out put the next street name future=future->next_node; next=next->next_node; present=present->next_node; next->section_distance=next->distance; if (future==NULL) { float distance,miles,decimal; int integer,feet; distance=next->section_distance; distance=distance*10; integer=distance/1; decimal=distance-integer; miles=(float)integer/10; feet=5280*decimal/10; if (miles==0) printf("stop on street %s,house number is %d,in %d foot.\n",destination_street,destination_house,feet); else if (feet==0) printf("stop on street %s,house number is %d,in %.1f miles.\n",destination_street,destination_house,miles); else if (miles>0 && feet>0) printf("stop on street %s,house number is %d,in %.1f miles and %d foot.\n",destination_street,destination_house,miles,feet); } break; } } } if (same_street==0) { float distance,miles,decimal;//to find out the miles in 1 decimal place and the foot in integer int integer,feet; distance=next->section_distance; distance=distance*10; integer=distance/1; decimal=distance-integer; miles=(float)integer/10; feet=5280*decimal/10; if (miles==0) printf("go to the vertex %d %d in %d foot.And then ",next->x,next->y,feet); else if (feet==0) printf("go to the vertex %d %d in %.1f miles.And then ",next->x,next->y,miles); else if (miles>0 && feet>0) printf("go to the vertex %d %d in %.1f miles and %d foot.And then ",next->x,next->y,miles,feet); if (present->unique_num==1 && future->unique_num==2) { x1=start_x; yl=start_y; x2=next->x; y2=next->y; x3=destination_x; y3=destination_y; } else if (present->unique_num==1 && future->unique_num!=2) { x1=start_x; yl=start_y; x2=next->x; y2=next->y; x3=future->x; y3=future->y; } else if (present->unique_num!=1 && future->unique_num==2) { x1=present->x; yl=present->y; x2=next->x; y2=next->y; x3=destination_x; y3=destination_y; } else if (present->unique_num!=1 && future->unique_num!=2) { x1=present->x; yl=present->y; x2=next->x; y2=next->y; x3=future->x; y3=future->y; } direction(x1,yl,x2,y2,x3,y3); char next_street[10]; for (j=1;j<=adj_list[next_label].present_num;j++)//find the street name after turn a direction { int get_name=0; for (k=1;k<=adj_list[future_label].present_num;k++) if (strcmp(adj_list[next_label].street_name[j],adj_list[future_label].street_name[k])==0) { get_name=1; strcpy(next_street,adj_list[next_label].street_name[j]); break; } if (get_name==1) break; } printf("onto %s\n",next_street);//output the next street name future=future->next_node; next=next->next_node; present=present->next_node; next->section_distance=next->distance; if (future==NULL) { float distance,miles,decimal;//to find out the miles in 1 decimal place and the foot in integer int integer,feet; distance=next->section_distance; distance=distance*10; integer=distance/1; decimal=distance-integer; miles=(float)integer/10; feet=5280*decimal/10; if (miles==0) printf("stop on street %s,house number is %d,in %d foot.\n",destination_street,destination_house,feet); else if (feet==0) printf("stop on street %s,house number is %d,in %.1f miles.\n",destination_street,destination_house,miles); else if (miles>0 && feet>0) printf("stop on street %s,house number is %d,in %.1f miles and %d foot.\n",destination_street,destination_house,miles,feet); } } } if (i<ways)//if the path is over printf("/---------------------Next Path-------------------/\n"); } }
// This one can load both leftover map files on game discs (like Zelda), and mapfiles // produced by SaveSymbolMap below. bool PPCSymbolDB::LoadMap(const std::string& filename) { File::IOFile f(filename, "r"); if (!f) return false; bool started = false; char line[512]; while (fgets(line, 512, f.GetHandle())) { if (strlen(line) < 4) continue; char temp[256]; sscanf(line, "%255s", temp); if (strcmp(temp, "UNUSED")==0) continue; if (strcmp(temp, ".text")==0) {started = true; continue;}; if (strcmp(temp, ".init")==0) {started = true; continue;}; if (strcmp(temp, "Starting")==0) continue; if (strcmp(temp, "extab")==0) continue; if (strcmp(temp, ".ctors")==0) break; //uh? if (strcmp(temp, ".dtors")==0) break; if (strcmp(temp, ".rodata")==0) continue; if (strcmp(temp, ".data")==0) continue; if (strcmp(temp, ".sbss")==0) continue; if (strcmp(temp, ".sdata")==0) continue; if (strcmp(temp, ".sdata2")==0) continue; if (strcmp(temp, "address")==0) continue; if (strcmp(temp, "-----------------------")==0) continue; if (strcmp(temp, ".sbss2")==0) break; if (temp[1] == ']') continue; if (!started) continue; u32 address, vaddress, size, unknown; char name[512]; sscanf(line, "%08x %08x %08x %i %511s", &address, &size, &vaddress, &unknown, name); const char *namepos = strstr(line, name); if (namepos != nullptr) //would be odd if not :P strcpy(name, namepos); name[strlen(name) - 1] = 0; // we want the function names only .... TODO: or do we really? aren't we wasting information here? for (size_t i = 0; i < strlen(name); i++) { if (name[i] == ' ') name[i] = 0x00; if (name[i] == '(') name[i] = 0x00; } // Check if this is a valid entry. if (strcmp(name, ".text") != 0 || strcmp(name, ".init") != 0 || strlen(name) > 0) { AddKnownSymbol(vaddress | 0x80000000, size, name); // ST_FUNCTION } } Index(); return true; }
void Dijkstra() { int visited_set[50]; int i,j; visited_set[1]=start_unique; int set_num=1;//set_num is to store how many visited nodes already have while(visited_set[set_num]!=destination_unique)//when the last visited node in the set is not the destination,continue { i=1; j=1; int label; struct shorter_path lenth_compare[20]={0};//lenth_compare[] is to store all the protential link while (i<=set_num) { label=Index(visited_set[i]);//visited_set[i] is an unique number,label is to find this unique number's position in the adjance list adj_link temp; temp=&adj_list[label]; temp=temp->next_node; while (temp!=NULL)//temp is the child of the current node in the set { int n; for (n=1;n<=set_num;n++) if (visited_set[n]==temp->unique_num) break; if (n>set_num)//if this node has never been visited,then store its lenth { float a; a=temp->distance+adj_list[label].distance_to_start_node;//"a" is to store the distance from start node to the father node plus distance from father to his child lenth_compare[j].distance=a; lenth_compare[j].unique_from=adj_list[label].unique_num;//unique_from is to record the father's unique number lenth_compare[j].unique_to=temp->unique_num;//unique_to is to record the current node's unique number j++; } temp=temp->next_node; } i++; } int k=1; float min_distance; min_distance=lenth_compare[k].distance; k++; while (k<j)//j repersents the number of the protential links we are going to compare { if (min_distance>lenth_compare[k].distance)//get the shortest one min_distance=lenth_compare[k].distance; k++; } for (k=1;k<j;k++) { if (min_distance==lenth_compare[k].distance)//if this is the shortest one { int num_of_father=1; int temp; temp=lenth_compare[k].unique_to; label=Index(temp); while (k<j)//this loop is to find out how many different fathers the "unique_to" has { if (lenth_compare[k].distance==min_distance && lenth_compare[k].unique_to==temp) { adj_list[label].distance_to_start_node=min_distance; adj_list[label].father_unique_num[num_of_father]=lenth_compare[k].unique_from; num_of_father++;//increase the number of his father } k++; } adj_list[label].father_num=num_of_father-1; set_num++;//the number of the visited set increases visited_set[set_num]=temp;//take this node's unique into the visited set break; } } } }
void cSkeleton<_DataType>::ComputeSkeletons(int RootLoc, int EndLoc, int Threshold_Dist) { int i, j, k, X_i, Y_i, Z_i, loc[3]; int FurthestVoxelLoc, FurthestVoxelDistance_i; map<int, unsigned char> CurrBoundary_m; cStack<int> EndLocs_stack; // Initializing the skeleton volume data Skeletons_muc = new unsigned char [WHD_mi]; for (i=0; i<WHD_mi; i++) Skeletons_muc[i] = (unsigned char)0; Skeletons_muc[RootLoc] = (unsigned char)255; Skeletons_muc[EndLoc] = (unsigned char)255; FurthestVoxelDistance_i = SkeletonTracking_Marking(EndLoc); printf ("Furthest Voxel Distance = %d\n", FurthestVoxelDistance_i); fflush (stdout); //-------------------------------------------------------------------------------------- // Computing other branches of the skeletons EndLocs_stack.Clear(); do { CurrBoundary_m.clear(); for (i=0; i<WHD_mi; i++) { if (Skeletons_muc[i]==255) CurrBoundary_m[i] = (unsigned char)0; } FurthestVoxelLoc = ComputeDistanceFromCurrSkeletons(CurrBoundary_m); FurthestVoxelDistance_i = SkeletonTracking_Marking(FurthestVoxelLoc); EndLocs_stack.Push(FurthestVoxelLoc); printf ("Furthest Voxel Distance = %d\n", FurthestVoxelDistance_i); fflush (stdout); } while (FurthestVoxelDistance_i >= Threshold_Dist); printf ("Num. end points = %d\n", EndLocs_stack.Size()); fflush (stdout); //-------------------------------------------------------------------------------------- // Marking the root voxel Z_i = RootLoc/WtimesH_mi; Y_i = (RootLoc - Z_i*WtimesH_mi)/Width_mi; X_i = RootLoc % Width_mi; for (k=Z_i-5; k<=Z_i+5; k++) { for (j=Y_i-5; j<=Y_i+5; j++) { for (i=X_i-5; i<=X_i+5; i++) { loc[0] = Index (i, j, k); Skeletons_muc[loc[0]] = (unsigned char)245; } } } // Marking the end voxel Z_i = EndLoc/WtimesH_mi; Y_i = (EndLoc - Z_i*WtimesH_mi)/Width_mi; X_i = EndLoc % Width_mi; for (k=Z_i-3; k<=Z_i+3; k++) { for (j=Y_i-3; j<=Y_i+3; j++) { for (i=X_i-3; i<=X_i+3; i++) { loc[0] = Index (i, j, k); Skeletons_muc[loc[0]] = (unsigned char)240; } } } // Marking the end voxles of the skeletons int GreyColor_i = 235; do { EndLocs_stack.Pop(loc[0]); Z_i = loc[0]/WtimesH_mi; Y_i = (loc[0] - Z_i*WtimesH_mi)/Width_mi; X_i = loc[0] % Width_mi; for (k=Z_i-2; k<=Z_i+2; k++) { for (j=Y_i-2; j<=Y_i+2; j++) { for (i=X_i-2; i<=X_i+2; i++) { loc[0] = Index (i, j, k); Skeletons_muc[loc[0]] = (unsigned char)GreyColor_i; } } } GreyColor_i -= 1; printf ("The grey colors for the end voxels = %d\n", GreyColor_i); fflush (stdout); if (GreyColor_i<60) GreyColor_i = 60; } while (!EndLocs_stack.IsEmpty()); // Combining the initial segmented volume with the skeletons for (i=0; i<WHD_mi; i++) { if (InitVolume_muc[i]==255 && Skeletons_muc[i]==0) { Skeletons_muc[i] = 50; } } }
NS_IMETHODIMP HTMLOptionElement::GetIndex(int32_t* aIndex) { *aIndex = Index(); return NS_OK; }
int cSkeleton<_DataType>::ComputeDistanceFromCurrSkeletons(map<int, unsigned char> &InitialBoundary_m) { int i, j, k, l, X_i, Y_i, Z_i, loc[3]; map<int, unsigned char> CurrBoundary_m, NextBoundary_m; map<int, unsigned char>::iterator Boundary_it; int CurrDistance_i; CurrBoundary_m.clear(); NextBoundary_m.clear(); for (i=0; i<WHD_mi; i++) DistanceFromSkeletons_mi[i] = -1; CurrDistance_i = 0; Boundary_it = InitialBoundary_m.begin(); for (i=0; i<InitialBoundary_m.size(); i++, Boundary_it++) { loc[0] = (*Boundary_it).first; CurrBoundary_m[loc[0]] = (unsigned char)1; DistanceFromSkeletons_mi[loc[0]] = CurrDistance_i; } do { CurrDistance_i++; Boundary_it = CurrBoundary_m.begin(); for (l=0; l<CurrBoundary_m.size(); l++, Boundary_it++) { loc[0] = (*Boundary_it).first; Z_i = loc[0]/WtimesH_mi; Y_i = (loc[0] - Z_i*WtimesH_mi)/Width_mi; X_i = loc[0] % Width_mi; for (k=Z_i-1; k<=Z_i+1; k++) { for (j=Y_i-1; j<=Y_i+1; j++) { for (i=X_i-1; i<=X_i+1; i++) { loc[0] = Index(i, j, k); if (CCVolume_muc[loc[0]]==255 && DistanceFromSkeletons_mi[loc[0]]<0) { NextBoundary_m[loc[0]] = (unsigned char)1; // Adding the loc to the curr map DistanceFromSkeletons_mi[loc[0]] = CurrDistance_i; } } } } } if (NextBoundary_m.size()==0) break; CurrBoundary_m.clear(); Boundary_it = NextBoundary_m.begin(); for (l=0; l<NextBoundary_m.size(); l++, Boundary_it++) { CurrBoundary_m[(*Boundary_it).first] = (unsigned char)1; } NextBoundary_m.clear(); } while (1); // returning one of the furthest voxel locations Boundary_it = CurrBoundary_m.begin(); loc[0] = (*Boundary_it).first; return loc[0]; }
Status Updates::Insert(const string& relation, // Name of the relation const int attrCnt, // Number of attributes specified in INSERT statement const attrInfo attrList[]) // Value of attributes specified in INSERT statement { /* Your solution goes here */ Record record; int TempattrCnt; AttrDesc *attrd; bool insert = true; Status Stat; Stat = attrCat->getRelInfo(relation, TempattrCnt, attrd); if(Stat != OK){ return Stat; } if(TempattrCnt == attrCnt){ //Get length of record and allocate memory for it record.length = attrd[TempattrCnt-1].attrOffset+attrd[TempattrCnt-1].attrLen-attrd[0].attrOffset; record.data = malloc(record.length); //Reorder AttrList attrInfo Tempattrl[TempattrCnt]; for(int i=0; i<TempattrCnt; ++i){ for(int j=0; j<TempattrCnt; ++j){ if(strcmp(attrd[i].attrName, attrList[j].attrName)==0){ Tempattrl[i] = attrList[j]; } } } //Package data into record for(int i =0; i<TempattrCnt;i++){ int len = strlen((char*)Tempattrl[i].attrValue); if((Datatype)Tempattrl[i].attrType==2 && len>attrd[i].attrLen){ insert = false; }else{ memcpy((char*)record.data+attrd[i].attrOffset, Tempattrl[i].attrValue, attrd[i].attrLen); } } //Insert Data Entry into Heapfile Status openHeapStat, insertHeapStat, openIndexStat, insertIndexStat; RID recordId; int unique = 0; Datatype type; //Utilities U;//for insert test HeapFile tempHeap = HeapFile(relation, openHeapStat); if(openHeapStat == OK && insert){ //insert record into heapfile and release memory insertHeapStat = tempHeap.insertRecord(record, recordId); //U.Print(relation);//for insert test free(record.data); if(insertHeapStat == OK){ for (int i=0; i< TempattrCnt; ++i){ if(attrd[i].indexed==1){ type = (Datatype)attrd[i].attrType; Index index = Index(relation, attrd[i].attrOffset, attrd[i].attrLen,type, unique, openIndexStat); if (openIndexStat == OK){ insertIndexStat = index.insertEntry(Tempattrl[i].attrValue,recordId); }else{ delete []attrd; return openIndexStat; } } } }else{ delete []attrd; return insertHeapStat; } }else{ free(record.data); if(!insert){ delete []attrd; return ATTRTOOLONG; }else{ delete []attrd; return openHeapStat; } } }else{ delete []attrd; return ATTRTYPEMISMATCH; } delete []attrd; return OK; }
void cSkeleton<_DataType>::BinarySegment2(_DataType MatMin, _DataType MatMax) { int i, j, k, l, m, n, loc[8], CubeXYZ_i[8][3], NumSegmentedVoxels; int NumPosSigns, Idx; double GradVec_d[3], DataLoc_d[3], Length_d; double AveGradM_d, Step_d, GradM_d[15]; printf ("Binary Segmentation 2 ... \n"); fflush(stdout); delete [] Distance_mi; Distance_mi = new int[WHD_mi]; delete [] VoxelFlags_muc; VoxelFlags_muc = new unsigned char[WHD_mi]; for (i=0; i<WHD_mi; i++) { if (MatMin <= Data_mT[i] && Data_mT[i] <= MatMax) { Distance_mi[i] = (int)255; VoxelFlags_muc[i] = FLAG_SEGMENTED; } else { Distance_mi[i] = (int)0; VoxelFlags_muc[i] = (unsigned char)FLAG_EMPTY; } } // It is for the Index() function Distance_mi[0] = (int)0; VoxelFlags_muc[0] = (unsigned char)FLAG_EMPTY; for (k=1; k<Depth_mi-1; k++) { for (j=1; j<Height_mi-1; j++) { for (i=1; i<Width_mi-1; i++) { loc[0] = Index(i, j, k); if (Distance_mi[loc[0]]==0) continue; Idx = 0; NumPosSigns = 0; AveGradM_d = 0.0; for (n=k; n<=k+1; n++) { for (m=j; m<=j+1; m++) { for (l=i; l<=i+1; l++) { loc[Idx] = Index(l, m, n); if (SecondDerivative_mf[loc[Idx]]>=0) NumPosSigns++; CubeXYZ_i[Idx][0] = l; CubeXYZ_i[Idx][1] = m; CubeXYZ_i[Idx][2] = n; AveGradM_d += (double)GradientMag_mf[loc[Idx]]; Idx++; } } } AveGradM_d /= 8.0; if (NumPosSigns<8 && NumPosSigns>0 && AveGradM_d>5.0) { for (n=0; n<8; n++) { for (l=0; l<3; l++) GradVec_d[l] = (double)GradientVec_mf[loc[n]*3 + l]; Length_d = 0.0; for (l=0; l<3; l++) Length_d += GradVec_d[l]*GradVec_d[l]; Length_d = sqrt (Length_d); for (l=0; l<3; l++) GradVec_d[l] /= Length_d; Idx = 0; Step_d = -1.5; for (l=0; l<3; l++) DataLoc_d[l] = (double)CubeXYZ_i[n][l] + GradVec_d[l]*Step_d; GradM_d[Idx] = GradientInterpolation(DataLoc_d); Idx++; Step_d = -1.5 + 0.25; for (l=0; l<3; l++) DataLoc_d[l] = (double)CubeXYZ_i[n][l] + GradVec_d[l]*Step_d; GradM_d[Idx] = GradientInterpolation(DataLoc_d); Idx++; for (Step_d = -1.5 + 0.25*2.0; Step_d<=1.5; Step_d+=0.25) { for (l=0; l<3; l++) DataLoc_d[l] = (double)CubeXYZ_i[n][l] + GradVec_d[l]*Step_d; GradM_d[Idx] = GradientInterpolation(DataLoc_d); if (GradM_d[Idx-2] < GradM_d[Idx-1] && GradM_d[Idx-1] > GradM_d[Idx]) { Distance_mi[loc[n]] = (int)0; VoxelFlags_muc[loc[n]] = (unsigned char)FLAG_EMPTY; break; } Idx++; } /* printf ("\n"); printf ("(%3d %3d %3d): ", i, j, k); printf ("Vec = (%6.3f %6.3f %6.3f), ", GradVec_d[0], GradVec_d[1], GradVec_d[2]); printf ("Second D = "); for (l=0; l<Idx; l++) { printf ("%8.3f ", SecondD_d[l]); } printf ("\n"); */ } } } } } delete [] InitVolume_muc; InitVolume_muc = new unsigned char [WHD_mi]; NumSegmentedVoxels = 0; for (i=0; i<WHD_mi; i++) { if (Distance_mi[i]==255) { if (VoxelFlags_muc[i] != FLAG_SEGMENTED) { printf ("Error!!!, VoxelFlags_muc[i] should be FLAG_SEGMENTED\n"); exit(1); } NumSegmentedVoxels++; InitVolume_muc[i] = (unsigned char)255; } else { if (VoxelFlags_muc[i] != FLAG_EMPTY) { printf ("Error!!!, VoxelFlags_muc[i] should be FLAG_EMPTY\n"); exit(1); } InitVolume_muc[i] = (unsigned char)0; } } NumSegmentedVoxels_mi = NumSegmentedVoxels; printf ("The voxels of zero second derivative are removed\n"); printf ("Num. Segmented Voxels = %d\n", NumSegmentedVoxels_mi); printf ("Total Num. Voxels = %d\n", WHD_mi); printf ("Num. Segmented / Total Num. Voxels = %f %%\n", (double)NumSegmentedVoxels_mi/WHD_mi*100.0); printf ("\n"); fflush(stdout); }
void test_dim(int ndim) { int dim,elems; int i,j, proc; /* double a[DIM4][DIM3][DIM2][DIM1], b[EDIM4][EDIM3][EDIM2][EDIM1];*/ double *b; double *a, *a1, *a2, *c; int ridx; MPI_Datatype typeA, typeB; int rstrideB[MAXDIMS]; int rcount[MAXDIMS]; int pidx1 = -1, pidx2 = -1, pidx3 = -1; elems = 1; strideA[0]=sizeof(double); strideB[0]=sizeof(double); for(i=0;i<ndim;i++){ strideA[i] *= dimsA[i]; strideB[i] *= dimsB[i]; if(i<ndim-1){ strideA[i+1] = strideA[i]; strideB[i+1] = strideB[i]; } elems *= dimsA[i]; } /* create shared and local arrays */ create_safe_array((void**)&b, sizeof(double),ndim,dimsB); a1 = (double *)malloc(sizeof(double)*elems); assert(a1); a2 = (double *)malloc(sizeof(double)*elems); assert(a2); c = (double *)malloc(sizeof(double)*elems); assert(c); init(a1, ndim, elems, dimsA, me!=0, 0); init(a2, ndim, elems, dimsA, me!=0, 1); if(me==0){ printf("--------array[%d",dimsA[0]); for(dim=1;dim<ndim;dim++)printf(",%d",dimsA[dim]); printf("]--------\n"); } sleep(1); MP_BARRIER(); for(i=0;i<LOOP;i++){ int idx1, idx2, idx3, ridx; MPI_Request request; if (i%2) { a = a2; } else { a = a1; } get_range(ndim, dimsA, loA, hiA); new_range(ndim, dimsB, loA, hiA, loB, hiB); new_range(ndim, dimsA, loA, hiA, loC, hiC); proc=nproc-1-me; if(me==0){ print_range("local",ndim,loA, hiA,"-> "); print_range("remote",ndim,loB, hiB,"-> "); print_range("local",ndim,loC, hiC,"\n"); } idx1 = Index(ndim, loA, dimsA); idx2 = Index(ndim, loB, dimsB); idx3 = Index(ndim, loC, dimsA); MPI_Sendrecv(&idx2, 1, MPI_INT, proc, 666, &ridx, 1, MPI_INT, proc, 666, MPI_COMM_WORLD, MPI_STATUS_IGNORE); for(j=0;j<ndim;j++)count[j]=hiA[j]-loA[j]+1; count[0] *= sizeof(double); /* convert range to bytes at stride level zero */ Strided_to_dtype(strideA, count, ndim-1, MPI_BYTE, &typeA); MPI_Type_commit(&typeA); Strided_to_dtype(strideB, count, ndim-1, MPI_BYTE, &typeB); MPI_Type_commit(&typeB); MPI_Accumulate(a + idx1, 1, typeA, proc, (MPI_Aint)(idx2*sizeof(double)), 1, typeB, MPI_REPLACE, win); MP_FLUSH(proc); /* note that we do not need Fence here since * consectutive operations targeting the same process are ordered */ MPI_Get_accumulate(NULL, 0, MPI_BYTE, c + idx3, 1, typeA, proc, (MPI_Aint)(idx2*sizeof(double)), 1, typeB, MPI_NO_OP, win); MP_FLUSH(proc); compare_patches(0., ndim, a+idx1, loA, hiA, dimsA, c+idx3, loC, hiC, dimsA); pidx1 = idx1; pidx2 = idx2; pidx3 = idx3; MPI_Type_free(&typeA); MPI_Type_free(&typeB); } free(c); destroy_safe_array(); free(a); }
/* * Test Data: * 01: love book manage * 02: work water * 03: word index list * 04: string list test * 05: love string * 06: help window * 07: help project * 08: help run * 09: window project run * 10: edit file * * So the word index list should be like this: * book: 1 * edit: 10 * file: 10 * help: 6, 7, 8 * index: 3 * list: 3, 4 * love: 1, 5 * manage: 1 * project: 7, 9 * run: 8, 9 * string: 4, 5 * test: 4 * water: 2 * window: 6, 9 * word: 3 * work: 2 */ WordIndexList getTestWordIndexList() { WordIndexList list = NULL; Status status = 0; status = Initial(&list); if (status != OK) return NULL; Index(list, 1, "love"); Index(list, 1, "book"); Index(list, 1, "manage"); Index(list, 2, "work"); Index(list, 2, "water"); Index(list, 3, "word"); Index(list, 3, "index"); Index(list, 3, "list"); Index(list, 4, "string"); Index(list, 4, "list"); Index(list, 4, "test"); Index(list, 5, "love"); Index(list, 5, "string"); Index(list, 6, "help"); Index(list, 6, "window"); Index(list, 7, "help"); Index(list, 7, "project"); Index(list, 8, "help"); Index(list, 8, "run"); Index(list, 9, "window"); Index(list, 9, "project"); Index(list, 9, "run"); Index(list, 10, "edit"); status = Index(list, 10, "file"); if (status != OK) return NULL; return list; }