/* Just a test for a "precision" cursor to be used to modify some histogram data */ TH1F *histogram; //!< histogram to work on. //-------------------------------------------------- // some key cosntants. const int KEY_ARROW_UP []={0, 4115}; const int KEY_ARROW_DOWN []={0, 4117}; const int KEY_ARROW_LEFT []={0, 4114}; const int KEY_ARROW_RIGHT []={0, 4116}; const int KEY_PLUS []={43, 43}; const int KEY_MINUS []={45, 45}; //-------------------------------------------------- // the real work is here: void myfunc() { // graphical stuff static TMarker *marker=NULL;; static TMarker *marker1=NULL;; static TLatex *infos=NULL; // data static int bin=0; int px = gPad->GetEventX(); int py = gPad->GetEventY(); // printf("myfunc called with %d %d\n",px,py); if(marker==NULL) {// first call: init what is needed bin=histogram->GetNbinsX()/2; double firstx=histogram->GetXaxis()->GetBinCenter(bin); infos=new TLatex(0.12,0.8,""); infos->SetNDC(); infos->Draw(); marker=new TMarker(firstx,0,4); marker1=new TMarker(firstx,0,3); marker->SetMarkerColor(2);; marker1->SetMarkerColor(2);; marker->SetMarkerSize(2);; marker1->SetMarkerSize(3);; marker->Draw(); marker1->Draw(); px= KEY_ARROW_UP[0]; } if(px== KEY_ARROW_UP[0] || px==KEY_PLUS[0] || px==KEY_MINUS[0]) { // modify marker pos or histo data if(py == KEY_PLUS[1] || py == KEY_ARROW_UP[1]) histogram->AddBinContent(bin,1); if(py == KEY_MINUS[1] || py == KEY_ARROW_DOWN[1]) histogram->AddBinContent(bin,-1); if(py == KEY_ARROW_LEFT[1]) bin --; if(py == KEY_ARROW_RIGHT[1]) bin ++; // check bin coordinates if(bin<1) bin=1; if(bin>histogram->GetNbinsX()) bin=histogram->GetNbinsX(); // update markers and info marker->SetX(histogram->GetBinCenter(bin)); marker->SetY( histogram->GetBinContent(bin)); marker1->SetX(marker->GetX()); marker1->SetY(marker->GetY()); infos->SetTitle(Form("Bin %3d, value %3.0f\n",bin, marker->GetY())); // update canvas. gPad->Modified(); gPad->Update(); } // done. } //===================================================================================== void test_precisioncursor() { TCanvas *c= new TCanvas("c","Test of a precision cursor"); // build some histo histogram=new TH1F("h1","Test histogram",100,-3,3); histogram->FillRandom("gaus"); histogram->SetStats(kFALSE); histogram->Draw(); // add some "instructions" TLatex *l1= new TLatex(0.3,0.95,"Left/Right arrow keys to move cursor"); l1->SetNDC(); l1->Draw(); TLatex *l2= new TLatex(0.3,0.9,"Up/Down or +- keys to change histo value"); l2->SetNDC(); l2->Draw(); // GO! c->AddExec("func","myfunc()"); myfunc(); // for first draw of cursor }