86 this->iNP = cutg.GetN();
89 this->iLXD = hist.GetNbinsX();
90 this->iLXG = hist.GetNbinsX();
91 this->iLYD = hist.GetNbinsY();
92 this->iLYG = hist.GetNbinsY();
96 this->fileName = fileName;
107 char cInpLine[81], cFileName[27], cHID[7], cBID[7], cDG[7], cNP[7];
108 std::sprintf(cFileName,
"%-26s", (this->fileName).c_str());
109 std::sprintf(cHID,
"%6d", this->iIH);
110 std::sprintf(cBID,
"%6d", this->iIB);
111 std::sprintf(cDG,
"%6d", this->iDG);
112 std::sprintf(cNP,
"%6d", this->iNP);
113 std::sprintf(cInpLine,
"INP %s%s%s%s%s%*c", cFileName, cHID, cBID, cDG, cNP, 26,
' ');
116 std::sprintf(cTitleLine,
"TIT %-76s", this->GetTitle());
119 char cIPX[7], cIPY[7], cLXD[7], cLXG[7], cLYD[7], cLYG[7];
120 char cNUPM[9], cIAUX[9], cJAUX[9];
121 std::sprintf(cIPX,
"%6d", this->iIPX);
122 std::sprintf(cIPY,
"%6d", this->iIPY);
123 std::sprintf(cLXD,
"%6d", this->iLXD);
124 std::sprintf(cLXG,
"%6d", this->iLXG);
125 std::sprintf(cLYD,
"%6d", this->iLYD);
126 std::sprintf(cLYG,
"%6d", this->iLYG);
127 std::sprintf(cNUPM,
"%8d", this->iNUPM);
128 std::sprintf(cIAUX,
"%8d", this->iIAUX);
129 std::sprintf(cJAUX,
"%8d", this->iJAUX);
130 std::sprintf(cGateLine,
"GATE %s%s%s%s%s%s%s%s%s%*c", cIPX, cIPY, cLXD, cLXG, cLYD, cLYG, cNUPM, cIAUX, cJAUX, 15,
133 char cCXYLine[721] =
"CXY ";
135 int nPoints = this->iNP;
137 for (
int i = 0; i < 9; i++) {
139 std::sprintf(cCXYLine,
"%sCXY ", cCXYLine);
141 while (nPoint < nPoints) {
144 this->GetPoint(nPoint, dx, dy);
152 if (nLinePoints < 7) {
154 std::sprintf(cCXYLine,
"%s%5d%5d", cCXYLine, x, y);
156 nLinePoints = nLinePoints + 1;
159 std::sprintf(cCXYLine,
"%s%*c", cCXYLine, 75 - nLinePoints * 10,
' ');
164 if (nPoint == nPoints)
165 std::sprintf(cCXYLine,
"%s%*c", cCXYLine, 75 - nLinePoints * 10,
' ');
169 std::sprintf(cBanLine,
"%s%s%s%s", cInpLine, cTitleLine, cGateLine, cCXYLine);
170 std::string sBanLine(cBanLine);
184 std::stringstream
ss;
185 std::string line, sListFileName, sHisFileName(cHisFileName), sRootFileName;
186 sListFileName = sHisFileName.substr(0, sHisFileName.length() - 3);
187 sListFileName.append(
"list");
188 sRootFileName = sHisFileName.substr(0, sHisFileName.length() - 3);
189 sRootFileName.append(
"root");
190 std::ifstream listFile;
191 listFile.open(sListFileName);
211 hisFile = std::fopen(cHisFileName,
"rb");
212 TFile *outFile =
new TFile(sRootFileName.c_str(),
"recreate");
214 while (std::getline(listFile, line)) {
219 std::cout <<
"processing line: " << line << std::endl;
220 HID = stoi(line.substr(0, 5));
221 dim = stoi(line.substr(5, 5));
222 hwpc = stoi(line.substr(10, 4));
224 minX = stoi(line.substr(31, 6));
225 maxX = stoi(line.substr(37, 6));
226 title = line.substr(54);
229 std::cout <<
"warning! more than 64 bit integer, expect bad behaviour" << std::endl;
232 std::getline(listFile, line);
235 minY = stoi(line.substr(31, 6));
236 maxY = stoi(line.substr(37, 6));
240 sHistName.Form(
"ID%d", HID);
241 TH2D *hist =
new TH2D(sHistName.Data(), title.c_str(), maxX - minX + 1, minX, maxX + 1, maxY - minY + 1,
245 for (
int iyChannel = 0; iyChannel <= maxY; iyChannel++) {
246 for (
int ixChannel = 0; ixChannel <= maxX; ixChannel++) {
247 read = std::fread(&datum, (
size_t)hwpc * 2, (
size_t)1, hisFile);
249 hist->SetBinContent(ixChannel, iyChannel, datum);
251 std::cout <<
"error occurred in reading data" << std::endl;
259 sHistName.Form(
"ID%d", HID);
260 TH1D *hist =
new TH1D(sHistName.Data(), title.c_str(), maxX - minX + 1, minX, maxX + 1);
263 for (
int ixChannel = 0; ixChannel <= maxX; ixChannel++) {
264 read = std::fread(&datum, (
size_t)hwpc * 2, (
size_t)1, hisFile);
266 hist->SetBinContent(ixChannel, datum);
268 std::cout <<
"error occurred in reading data" << std::endl;
277 if (first ==
"HID") {
295 std::stringstream
ss;
296 std::string sBanString, line;
297 std::ifstream banFile;
298 banFile.open(cBanFileName);
299 std::getline(banFile, sBanString);
304 pos = sBanString.find(
"INP ", pos);
305 line = sBanString.substr(0, pos);
307 if (line.find(std::to_string(iID)) > line.length()) {
308 std::cout <<
"ID not present in *.ban file" << std::endl;
317 std::string sBananaGate = sBanString.substr(pos - 4, sBanString.find(
"INP ", pos + 4) - pos);
319 int iTIT = sBananaGate.find(
"TIT ");
320 int iGATE = sBananaGate.find(
"GATE ");
321 int iCXY = sBananaGate.find(
"CXY ");
322 std::string sINPLine = sBananaGate.substr(0, iTIT);
323 std::string sTITLine = sBananaGate.substr(iTIT, iGATE - iTIT);
324 std::string sGATELine = sBananaGate.substr(iGATE, iCXY - iGATE);
325 std::string sCXYLine = sBananaGate.substr(iCXY);
335 std::stringstream ssINP(sINPLine);
336 std::string fileName;
337 int iIH, iIB, iDG, iNP;
348 sCutName.Form(
"bID%d", iID);
349 banGate =
new BananaGate(sCutName.Data(), iNP);
350 banGate->SetName(sCutName.Data());
360 std::string sTitle = sTITLine.substr(4);
362 banGate->SetTitle(sTitle.c_str());
365 std::stringstream ssGATE(sGATELine);
366 int iIPX, iIPY, iLXD, iLXG, iLYD, iLYG, iNUPM, iIAUX, iJAUX;
389 std::stringstream ssCXY(sCXYLine);
399 x = std::atoi(junk.c_str());
401 banGate->SetPoint(nPoint, x, y);
410 pos = sBanString.find(
"INP", pos);
411 if (pos >= sBanString.length()) {
412 std::cout <<
"End of file reached" << std::endl;
462void writeBananas(
const char *cBanFileName, std::vector<BananaGate> vBananas)
468 for (
auto &bananaGate : vBananas) {
472 std::sprintf(cHeader,
"%5d", bananaGate.GetIB());
474 std::sprintf(cHeader,
"%s%5d", cHeader, bananaGate.GetIB());
477 for (
int i = n; i < 80; i++) {
478 std::sprintf(cHeader,
"%s%5d", cHeader, 0);
481 std::ofstream outFile;
482 outFile.open(cBanFileName);
485 for (
auto &bananaGate : vBananas) {
487 outFile << bananaGate.WriteBan().c_str();
501 TIter next(gDirectory->GetListOfKeys());
503 std::vector<BananaGate> vBananas;
504 while ((key = (TKey *)next())) {
505 TClass *cl = gROOT->GetClass(key->GetClassName());
506 if (!cl->InheritsFrom(
"GamR::ORNL::BananaGate"))
508 vBananas.push_back(*(
BananaGate *)key->ReadObj());