#include #include #include #include #include "TBox.h" #include "TCanvas.h" static const int MAXIX = 29; // x cells go from -MAXIX ... iX ... MAXIX static const int MAXIY = 29; // y cells go from -MAXIY ... iY ... MAXIY static const int X0 = 5; // x offset for the display static const int Y0 = 5; // y offset for the display static const int W = 10; // rectangle size // ************************* // helper functions // ************************* int getX(int iX){ return (W*iX + X0 + MAXIX*W); } int getY(int iY){ return (W*iY + Y0 + MAXIY*W); } bool hasBlock(int iX, int iY){ int edges[MAXIY*2+1] = {7, 10, 12, 14, 16, 17, 19, 20, 21, 22, 23, 23, 24, 25, 25, 26, 26, 27, 27, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 28, 28, 28, 27, 27, 26, 26, 25, 25, 24, 23, 23, 22, 21, 20, 19, 17, 16, 14, 12, 10, 7}; int iiY = iY + MAXIY; if (iiY < 0) return false; if (iiY > MAXIY*2) return false; if (abs(iX) > edges[iiY]) return false; if ((abs(iX) <= 10) && (abs(iY) <= 10)) return false; return true; } // ************************* // write to a new file called "widgets.xml" // using "fcal_cell.xml" as a template // ************************* void writeCells(bool lookDownstream=false){ int streamFactor = lookDownstream? -1 : 1; cout << "Stream factor: " << streamFactor << endl; ofstream outfile("widgets.xml",ios::out); // outfile << "LIST OF WIDGETS" << endl << endl << endl; outfile.close(); for (int iX = -1*MAXIX-5; iX < MAXIX+5; iX++){ for (int iY = -1*MAXIY-5; iY < MAXIY+5; iY++){ if (hasBlock(iX,iY)){ cout << "writing cell " << iX << " " << iY << endl; ofstream outfile2("widgets.xml",ios::app); ifstream infile("fcal_cell.xml"); string instring; while (!infile.eof()){ getline(infile,instring); if (instring.find("") != std::string::npos){ outfile2 << " CELL_" << streamFactor*iX << "_" << -1*iY << "" << endl; } else if (instring.find("") != std::string::npos && instring.find("scaler_r1") != std::string::npos ) { outfile2 << " FCAL:" << streamFactor*iX << ":" << -1*iY << ":scaler_r1" << endl; } else if (instring.find("") != std::string::npos){ outfile2 << " " << getX(iX) << "" << endl; } else if (instring.find("") != std::string::npos){ outfile2 << " " << getY(iY) << "" << endl; } else if (instring.find("") != std::string::npos){ outfile2 << " " << W << "" << endl; } else if (instring.find("") != std::string::npos){ outfile2 << " " << W << "" << endl; } else if (instring.find("FCAL:" << streamFactor*iX << ":" << -1*iY << ":scaler_r1" << endl; } else if (instring.find("") != std::string::npos){ outfile2 << " " << streamFactor*iX << "," << -1*iY << endl; } else if (instring.find("") != std::string::npos){ outfile2 << " " << streamFactor*iX << "_" << -1*iY << "" << endl; } else{ outfile2 << instring << endl; } } outfile2.close(); } } } } // ************************* // quick test with root // ************************* void testDraw(){ TCanvas* c1 = new TCanvas("c1","c1",500,500); for (int iX = -1*MAXIX-5; iX < MAXIX+5; iX++){ for (int iY = -1*MAXIY-5; iY < MAXIY+5; iY++){ TBox* b = new TBox(getX(iX)/1000.0,getY(iY)/1000.0,(getX(iX)+W)/1000.0,(getY(iY)+W)/1000.0); if (abs(iX + iY)%2 == 0) b->SetFillColor(kGreen); if (abs(iX + iY)%2 == 1) b->SetFillColor(kRed); if (!hasBlock(iX,iY)) b->SetFillColor(kWhite); b->Draw(); } } }