#include #include #include #include #include "TBox.h" #include "TCanvas.h" #define SIGN_OF_INT(i) ((i > 0) - (i < 0)) static const int MAXIX = 20; // x cells go from -MAXIX ... iX ... MAXIX static const int MAXIY = 20; // y cells go from -MAXIY ... iY ... MAXIY static const int X0 = 0; // x offset for the display static const int Y0 = 0; // y offset for the display static const int W = 20; // rectangle size // ************************* // helper functions // ************************* int getX(int iX){ return (-W*iX + X0 + MAXIX*W + SIGN_OF_INT(iX) * (W/2)); } int getY(int iY){ return (-W*iY + Y0 + MAXIY*W + SIGN_OF_INT(iY) * (W/2)); } bool hasBlock(int iX, int iY){ if( (abs(iX)>MAXIX) || (abs(iY)>MAXIX) || (iX*iY==0) ) return false; if ( (abs(iX) < 2) && (abs(iY) < 2) ) return false; return true; } // ************************* // write to a new file called "ecal_widgets.xml" // using "ecal_cell.xml" as a template // ************************* void writeCells(){ ofstream outfile("ecal_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("ecal_widgets.xml",ios::app); ifstream infile("ecal_cell.xml"); string instring; while (!infile.eof()){ getline(infile,instring); if (instring.find("") != std::string::npos){ outfile2 << " CELL_" << iX << "_" << iY << "" << endl; } else if (instring.find("ECAL:") != std::string::npos){ outfile2 << " " << "ECAL:" << iX << ":" << 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("") != std::string::npos){ outfile2 << " " << iX << "," << 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(); } } }