void KVDP2toCsIGridConvertor::ReadGammaFile(const Char_t* gammafile) { ifstream gamfile; gamfile.open(gammafile); if (!gamfile.good()) { Error(KV__ERROR(ReadGammaFile), "Problem reading file %s", gammafile); return; } KVString s; s.ReadLine(gamfile); while (gamfile.good()) { if (s == "") { s.ReadLine(gamfile); continue; } if (!s.BeginsWith('#')) { //'#' sign signals comments int ring, modu, frun, lrun; if (sscanf(s.Data(), "%d %d %d %d", &ring, &modu, &frun, &lrun) != 4) { Error(KV__ERROR(ReadGammaFile), "Problem reading file %s\nLast line read: %s", gammafile, s.Data()); return; }; //get grid for this ring,mod TString name; name. Form ("CsI R-L Grid First run=%d Last run=%d Ring min=%d Ring max=%d Mod min=%d Mod max=%d", frun, lrun, ring, ring, modu, modu); KVIDGrid* grid = (KVIDGrid*)fGrids->FindObject(name.Data()); if (!grid) { Error(KV__ERROR(ReadGammaFile), "Can't find grid %s", name.Data()); } int npoints; gamfile >> npoints; //found gamma line KVIDLine* line = 0; if (grid) { line = grid->NewLine("ok"); line->SetName("gamma_line"); line->Set(npoints); grid->Add("ok", line); } //read in points for (int i = 0; i < npoints; i++) { Double_t x, y; gamfile >> x >> y; if (grid) line->SetPoint(i, x, y); } } s.ReadLine(gamfile); }
//________________________________________________________________ void KVZALineFinder::FindZLine(Int_t zz) { fLinearHisto->SetAxisRange(zz-0.5,zz+0.5,"Y"); KVIDLine* line = (KVIDLine*)fGrid->GetIdentifier(zz,2*zz+1); // A=2*zz+1 : dummy, A is ignored in this case if(!line) { int i=1; while(!(line = (KVIDLine*)fGrid->GetIdentifier(zz+i,2*zz+1))) i++; } if(!line) return; Double_t lX, lY; line->GetStartPoint(lX,lY); Int_t xbmin = 1; line->GetEndPoint(lX,lY); Int_t xbmax = fLinearHisto->GetXaxis()->FindBin(lX); Int_t width = (Int_t)((xbmax-xbmin)*1.0/100.); Int_t widthmax = (Int_t)((xbmax-xbmin)*1.0/30.); KVIDZALine* TheLine = 0; TheLine = (KVIDZALine*)((KVIDZAGrid*)fGeneratedGrid)->NewLine("ID"); TheLine->SetZ(zz); TheLine->SetA(fAList.at(zz-1)); TH1* projey = 0; Int_t i=0; Double_t lasty = zz; for(int xx=xbmin; xx<xbmax; xx+=width) { projey = fLinearHisto->ProjectionY("ProjectionAfterLin",TMath::Max(xx-width/2,xbmin),xx+width/2); Double_t xline = fLinearHisto->GetBinCenter(xx); Double_t yline = projey->GetMean(); if((yline>zz-0.5)&&(yline<zz+0.5)) { if(i==0) lasty = yline; if(TMath::Abs(yline-lasty)<0.2) { TheLine->SetPoint(i, xline, yline); lasty = yline; i++; if(width<widthmax) width*=1.2; } } delete projey; } if(TheLine->GetN()>5) fGeneratedGrid->Add("ID",TheLine); }
Double_t KVIDTelescope::GetMeanDEFromID(Int_t& status, Int_t Z, Int_t A, Double_t Eres) { // Returns the Y-axis value in the 2D identification map containing isotope (Z,A) // corresponding to either the given X-axis/Eres value or the current X-axis value given by GetIDMapX. // If no mass information is available, just give Z. // // In this (default) implementation this means scanning the ID grids associated with // this telescope until we find an identification line Z or (Z,A), and then interpolating // the Y-coordinate for the current X-coordinate value. // // Status variable can take one of following values: // // KVIDTelescope::kMeanDE_OK all OK // KVIDTelescope::kMeanDE_XtooSmall X-coordinate is smaller than smallest X-coordinate of ID line // KVIDTelescope::kMeanDE_XtooLarge X-coordinate is larger than largest X-coordinate of ID line // KVIDTelescope::kMeanDE_NoIdentifie No identifier found for Z or (Z,A) status = kMeanDE_OK; // loop over grids TIter next(fIDGrids); KVIDGrid* grid; KVIDLine* idline = 0; while ((grid = (KVIDGrid*)next())) { idline = (KVIDLine*)grid->GetIdentifier(Z, A); if (idline) break; } if (!idline) { status = kMeanDE_NoIdentifier; return -1.; } Double_t x, x1, y1, x2, y2; x = (Eres < 0 ? GetIDMapX() : Eres); idline->GetEndPoint(x2, y2); if (x > x2) { status = kMeanDE_XtooLarge; return -1; } idline->GetStartPoint(x1, y1); if (x < x1) { status = kMeanDE_XtooSmall; return -1.; } return idline->Eval(x); }
//________________________________________________________________ void KVZALineFinder::FindALine(Int_t zz, Int_t width) { fLinearHisto->SetAxisRange(zz-0.5,zz+0.5,"Y"); KVIDLine* line = (KVIDLine*)fGrid->GetIdentifier(zz,2*zz+1); // A=2*zz+1 : dummy, A is ignored in this case if(!line) { int i=1; while(!(line = (KVIDLine*)fGrid->GetIdentifier(zz+i,2*zz+1))) i++; } if(!line) return; Double_t lX, lY; line->GetStartPoint(lX,lY); Int_t xbmin = 0;//fLinearHisto->GetYaxis()->FindBin(lX); line->GetEndPoint(lX,lY); Int_t xbmax = fLinearHisto->GetXaxis()->FindBin(lX); // create lines TList Lines; KVSpiderLine* tmp = 0; fLinearHisto->SetAxisRange(fLinearHisto->GetXaxis()->GetBinCenter(50),lX,"X");//fLinearHisto->GetXaxis()->GetXmax(),"X"); TH1* tmph = fLinearHisto->ProjectionX(Form("tmph%d",zz)); Int_t startBin = (Int_t)(tmph->GetMaximumBin()*0.95); delete tmph; TH1* projey = 0; if(startBin) { projey = fLinearHisto->ProjectionY("ProjectionAfterLin",startBin-width*3,startBin+width*3); int nfound = fSpectrum.Search(projey,0.05,"goff",0.0001); Info("FindALine","%d peack found...",nfound); #if ROOT_VERSION_CODE > ROOT_VERSION(5,99,01) Double_t* xpeaks = fSpectrum.GetPositionX(); Double_t* ypeaks = fSpectrum.GetPositionY(); #else Float_t* xpeaks = fSpectrum.GetPositionX(); Float_t* ypeaks = fSpectrum.GetPositionY(); #endif for(int p=0;p<nfound;p++) { if(p>8) break; if(ypeaks[p]<10) continue; Double_t xline = fLinearHisto->GetXaxis()->GetBinCenter(startBin); Double_t yline = xpeaks[p]; KVSpiderLine* tmp = 0; TIter next(&Lines); while((tmp=(KVSpiderLine*)next())) { Info("FindALine","line found but I don't know why..."); if(TMath::Abs(tmp->GetY()-yline)<0.05) continue; } tmp = new KVSpiderLine(zz,-1); Lines.AddLast(tmp); tmp->AddPoint(xline,yline); fPoints->SetPoint(fNPoints,xline,yline); fNPoints++; } if(projey) delete projey; } else Error("FindALine","not starting bin indicated..."); SortLines(&Lines); Int_t nLines = Lines.GetSize(); tmp = 0; for(int xx=startBin-width; xx>xbmin; xx-=width) { projey = fLinearHisto->ProjectionY("ProjectionAfterLin",xx-width/2,xx+width/2); int nfound = fSpectrum.Search(projey,0.05,"goff",0.02); #if ROOT_VERSION_CODE > ROOT_VERSION(5,99,01) Double_t* xpeaks = fSpectrum.GetPositionX(); Double_t* ypeaks = fSpectrum.GetPositionY(); #else Float_t* xpeaks = fSpectrum.GetPositionX(); Float_t* ypeaks = fSpectrum.GetPositionY(); #endif for(int p=0;p<nfound;p++) { if(p>=nLines+1) continue; if(ypeaks[p]<5) continue; Double_t xline = fLinearHisto->GetXaxis()->GetBinCenter(xx); Double_t yline = xpeaks[p]; KVSpiderLine* tmp = 0; TIter next(&Lines); while((tmp=(KVSpiderLine*)next())) { if((TMath::Abs(tmp->GetY()-yline)<0.05)) break; } if(tmp) { if((TMath::Abs(tmp->GetX()-xline)<10*width)) tmp->AddPoint(xline,yline); } } if(projey) delete projey; } TIter nextli(&Lines); while((tmp=(KVSpiderLine*)nextli()))tmp->Sort(true); tmp = 0; for(int xx=startBin+width; xx<=xbmax-width/2; xx+=width) { projey = fLinearHisto->ProjectionY("ProjectionAfterLin",xx-width/2,xx+width/2); int nfound = fSpectrum.Search(projey,0.05,"goff",0.02); #if ROOT_VERSION_CODE > ROOT_VERSION(5,99,01) Double_t* xpeaks = fSpectrum.GetPositionX(); Double_t* ypeaks = fSpectrum.GetPositionY(); #else Float_t* xpeaks = fSpectrum.GetPositionX(); Float_t* ypeaks = fSpectrum.GetPositionY(); #endif for(int p=0;p<nfound;p++) { if(p>=nLines+1) continue; if(ypeaks[p]<5) continue; Double_t xline = fLinearHisto->GetXaxis()->GetBinCenter(xx); Double_t yline = xpeaks[p]; KVSpiderLine* tmp = 0; TIter next(&Lines); while((tmp=(KVSpiderLine*)next())) { if(TMath::Abs(tmp->GetY()-yline)<0.05) break; } if(tmp) { if((TMath::Abs(tmp->GetX()-xline)<10*width)) tmp->AddPoint(xline,yline); } } if(projey) delete projey; } fLines->AddAll(&Lines); }
void KVDP2toIDGridConvertor::ReadFile(const Char_t* filename) { // Read grids in file and add to fGrids list if (!fGridClass) { Error(KV__ERROR(ReadFile), "Set class of ID grids to generate first!"); return; } ifstream datfile; datfile.open(filename); if (!datfile.good()) { Error(KV__ERROR(ReadFile), "Problem reading file %s", filename); return; } KVString s; s.ReadLine(datfile); while (datfile.good()) { if (s == "") { s.ReadLine(datfile); continue; } if (!s.BeginsWith('#')) { //'#' sign signals comments int ring, modu, frun, lrun, totpoints; if (sscanf(s.Data(), "%d %d %d %d", &ring, &modu, &frun, &lrun) != 4) { Error(KV__ERROR(ReadFile), "Problem reading file %s\nLast line read: %s", filename, s.Data()); return; }; KVIDGrid* grid = (KVIDGrid*) fGridClass->New(); //create new grid //add to list of grids fGrids->Add(grid); grid->GetParameters()->SetValue("First run", frun); grid->GetParameters()->SetValue("Last run", lrun); grid->GetParameters()->SetValue("Ring min", ring); grid->GetParameters()->SetValue("Ring max", ring); grid->GetParameters()->SetValue("Mod min", modu); grid->GetParameters()->SetValue("Mod max", modu); int nlines; datfile >> nlines; totpoints = 0; //read Z,A and number of points in each line for (int i = 0; i < nlines; i++) { int z, a, npoints; datfile >> z >> a >> npoints; totpoints += 2 * npoints; if (z > 0) { //identification line KVIDLine* line = (KVIDLine*)grid->NewLine("id"); line->SetZ(z); line->SetA(a); line->Set(npoints); grid->Add("id", line); } else { //"ok" line KVIDLine* line = (KVIDLine*)grid->NewLine("ok"); line->Set(npoints); grid->Add("ok", line); } } ReadLineCoords(grid, datfile); //calculate line widths in grid grid->CalculateLineWidths(); } s.ReadLine(datfile); }