#include #include #include #include #include #include #include "sopnamsp.h" #include "strutil.h" #include "strutilxx.h" #include "histos.h" #include "histos2.h" #include "hisprof.h" #include "histerr.h" #include "hist2err.h" #include "ntuple.h" #include "datatable.h" #include "pawexecut.h" #include "nobjmgr.h" #include "servnobjm.h" #include "nomgadapter.h" #include "pistdimgapp.h" #include "pihisto.h" #include "tmatrix.h" #include "tvector.h" /* Reza + cmv 13/10/99 */ inline bool __vector_sort_up_r8(r_8 x1,r_8 x2) {return x1x2;} inline bool __vector_sort_up_r4(r_4 x1,r_4 x2) {return x1x2;} inline bool __vector_sort_up_i4(int_4 x1,int_4 x2) {return x1x2;} inline bool __vector_sort_up_u8(uint_8 x1,uint_8 x2) {return x1x2;} uint_4 PAWExecutor::autoc_counter_ = 0; /* methode */ PAWExecutor::PAWExecutor(PIACmd *piac, PIStdImgApp* app) : mApp(app) { string kw, usage; string hgrp = "pawCmd"; string gdesc = "CERN PAW like expression plotting commands "; piac->AddHelpGroup(hgrp, gdesc); kw = "reset"; usage = "Reset histograms vectors or matrix"; usage += "\n reset nameobj"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "n/plot"; usage = "Plot NTuple variables \"a la paw\" (alias n/pl)"; usage += "\n n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt]"; usage += "\n n/plot nameobj.y_exp%x_exp [cut] [loop] [gratt]"; usage += "\n n/plot nameobj.z_exp%y_exp%x_exp [cut] [loop] [gratt]"; usage += "\n for default use ! , loop=i1[:i2[:di]]"; usage += "\n for 1 dimensional (1D) projection:"; usage += "\n use graphic option \"keepbin\" to keep previous"; usage += "\n plot binning for 1D distribution"; usage += "\n Related commands: plot2dw plot3d"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "n/pl"; usage = "alias to n/plot (see n/plot)"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "n/proj"; usage = "Project NTuple in histogram (1D or 2D) a la paw"; usage += "\n n/proj nameproj nameobj.x_exp [cut] [w_exp] [loop] [gratt]"; usage += "\n n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [loop] [gratt]"; usage += "\n for default use ! , loop=i1[:i2[:di]]"; usage += "\n for 1 dimensional (1D) projection:"; usage += "\n no display is performed if \"nameproj\" is an existing histogram"; usage += "\n unless a graphic option \"gratt\" is given"; usage += "\n Related commands: projh1d projh2d projprof exptovec"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "n/scan"; usage = "Scan NTuple a la paw"; usage += "\n n/scan nameobj[.exp1%exp2%exp3] cut loop"; usage += "\n [-f:filename] [list_of_variables]"; usage += "\n loop : iev1[:iev2[:diev]] or !"; usage += "\n cut : cut expression or 1. or !"; usage += "\n list_of_variables : default is all variables"; usage += "\n : var1 var2 var3 ... varn"; usage += "\n : var1 : var2 (from var1 to var2)"; usage += "\n : : var2 (from first variable to var2)"; usage += "\n : var1 : (from var1 to last variable)"; usage += "\n ex: \"v1 : v3 v7 v4 : v6 v2 v9 :\""; usage += "\n exp1%exp2%exp3 :"; usage += "\n if given add exp1,exp2,exp3 to the variable list"; usage += "\n -f:filename : write into \"filename\", Default is to stdout"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "n/read"; usage = "Read columns in an ASCII file and fill a NTuple or a DataTable"; usage += "\n n/read nt fascii [options] var_1,c_1 var_2,c_2 ... var_n,c_n "; usage += "\n nt : NTuple or DataTable (see options) name"; usage += "\n var_i,c_i : variable name, associated column in ASCII file [0,n["; usage += "\n where [options] are:"; usage += "\n \"-dt\": create a DataTable of double instead of a NTuple"; usage += "\n \"=s\": separator character is \'s\' (could be \"\t\")"; usage += "\n \"-^abcd\": do not read lines beginning with string \"abcd\" "; usage += "\n \"+^abcd\": read only lines beginning with string \"abcd\" "; usage += "\n \"-abcd\": do not read lines which contain string \"abcd\" "; usage += "\n \"+abcd\": read only lines which contain string \"abcd\" "; usage += "\n these options may be repeated (ex: \"-^abcd\" \"-^xyz\") "; usage += "\n - in case of \"do not read\" options are added with logical AND "; usage += "\n - in case of \"read only\" options are added with logical OR "; piac->RegisterCommand(kw,usage,this,hgrp); kw = "n/merge"; usage = "Merge ntuples (by adding lines)"; usage += "\n n/merge nt nt_1 nt_2 ... nt_n"; usage += "\n Merge ntuples nt_i lines into ntuple nt"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "n/merge/col"; usage = "Merge ntuples (by adding columns for each line)"; usage += "\n n/merge/col nt nt_1[,ext] nt_2[,ext] ... nt_n[,ext]"; usage += "\n Merge ntuples nt_i columns into ntuple nt"; usage += "\n ext : character string to add at the end of the ntuple variable names"; usage += "\n if \"ext\"=\"!\" no extension is added"; usage += "\n if no \"ext\" is given, automatic extension \"_0\" \"_1\" \"_2\" ..."; piac->RegisterCommand(kw,usage,this,hgrp); kw = "n/assoc/col"; usage = "Merge ntuples columns with an association index"; usage += "\n n/assoc/col ntass[,u/i] nt_1[,ext] nt_2[,ext] nt_assoc[,icass]"; usage += "\n Merge ntuples nt_1 and nt_2 columns into ntuple ntass"; usage += "\n with line association number given by ntuple nt_assoc"; usage += "\n ---"; usage += "\n icass: association number given by column \"icass\" of nt_assoc (def=0)"; usage += "\n ---"; usage += "\n ext : character string to add at the end of the ntuple variable names"; usage += "\n if \"ext\"=\"!\" no extension is added"; usage += "\n if no \"ext\" is given, automatic extension \"_0\" \"_1\" \"_2\" ..."; usage += "\n ---"; usage += "\n u : do the union of all the lines of nt_1 and nt_2"; usage += "\n (all ssociated and un-associated lines of nt_1 and nt_2)"; usage += "\n i : do the intersection of all the lines of nt_1 and nt_2"; usage += "\n (only associated lines of nt_1 and nt_2)"; usage += "\n def : write all lines of nt_1 with possible associated line of nt_2"; usage += "\n (number of entries of ntass = number of entries of nt_1)"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "n/copy"; usage = "Copy all or some variables of a ntuple into another new ntuple"; usage += "\n n/merge ntnew nt [vname1 vname2 vname3 ...]"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "h/integ"; usage = "Integrate a 1D histogram"; usage += "\n h/integ nameh1d [norm]"; usage += "\n norm<=0 means no normalisation (def norm=1)"; usage += "\n Related commands: h/deriv v/integ v/deriv"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "v/integ"; usage = "Integrate a TVector / vector"; usage += "\n v/integ namevec [norm]"; usage += "\n norm<=0 means no normalisation (def norm=0)"; usage += "\n Related commands: h/integ h/deriv v/deriv"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "v/sort"; usage = "Sort a vector into itself"; usage += "\n v/sort namevec [+1/-1]"; usage += "\n \"+1\" means increasing order, \"-1\" decreasing order"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "h/deriv"; usage = "Derivate a 1D histogram"; usage += "\n h/deriv nameh1d"; usage += "\n Related commands: h/integ v/integ v/deriv"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "v/deriv"; usage = "Derivate a TVector / vector"; usage += "\n v/deriv namevec [deriv_option]"; usage += "\n deriv_option -1 replace v[i] with v[i]-v[i-1]"; usage += "\n 0 replace v[i] with (v[i+1]-v[i-1])/2 (default)"; usage += "\n +1 replace v[i] with v[i+1]-v[i]"; usage += "\n Related commands: h/integ h/deriv v/integ"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "h/rebin"; usage = "Rebin a 1D histogram or profile"; usage += "\n h/rebin nameh1d nbin"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "h/cadd"; usage = "Add a constant to an histogram, a vector or a matrix"; usage += "\n h/cadd namehisto val"; usage += "\n Related commands: h/cmult h/oper"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "h/cmult"; usage = "Multiply an histogram, a vector or a matrix by a constant"; usage += "\n h/cmult namehisto val"; usage += "\n Related commands: h/cadd h/oper"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "h/oper"; usage = "Operation on histograms vectors or matrices"; usage += "\n h/oper @ h1 h2 hres"; usage += "\n hres = h1 @ h2 with @ = (+,-,*,/)"; usage += "\n For vectors and matrices, operations are elements by elements"; usage += "\n Related commands: h/cadd h/cmult"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "h/plot/2d"; usage = "Specific plot for 2D histogrammes"; usage += "\n h/plot/2d nameh2d show : infos on 2D histogramme projections"; usage += "\n h/plot/2d nameh2d h [dopt] : plot 2D histogramme"; usage += "\n h/plot/2d nameh2d px [dopt] : plot X projection"; usage += "\n h/plot/2d nameh2d py [dopt] : plot Y projection"; usage += "\n h/plot/2d nameh2d bx n [dopt] : plot X band number n"; usage += "\n h/plot/2d nameh2d by n [dopt] : plot Y band number n"; usage += "\n h/plot/2d nameh2d sx n [dopt] : plot X slice number n"; usage += "\n h/plot/2d nameh2d sy n [dopt] : plot Y slice number n"; usage += "\n n < 0 means Show Info"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "h/2d/geth"; usage = "Get histo projections, bandes and slices"; usage += "\n h/2d/geth nameh2d : infos on 2D histogramme projections"; usage += "\n h/2d/geth h nameh2d px : copy X projection into histo h"; usage += "\n h/2d/geth h nameh2d py : copy Y projection into histo h"; usage += "\n h/2d/geth h nameh2d bx n : copy X band number n into histo h"; usage += "\n h/2d/geth h nameh2d by n : copy Y band number n into histo h"; usage += "\n h/2d/geth h nameh2d sx n : copy X slice number n into histo h"; usage += "\n h/2d/geth h nameh2d sy n : copy Y slice number n into histo h"; usage += "\n Related commands: h/plot/2d"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "h/put_vec"; usage = "Put content of vector (matrix) into content of histogram 1D or 2D"; usage += "\n h/put_vec nameh1d namevector [cont,err2]"; usage += "\n h/put_vec nameh2d namematrix [cont,err2]"; usage += "\n cont : put into histogramme content"; usage += "\n err2 : put into histogramme error^2"; usage += "\n Related commands: h/get_vec"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "h/get_vec"; usage = "Get content of histogram 1D profile or 2D into vector (matrix)"; usage += "\n h/get_vec nameh1d namevector [cont,err2,absc] [proj]"; usage += "\n h/get_vec nameh2d namematrix [cont,err2,absc]"; usage += "\n cont : get histogramme content"; usage += "\n err2 : get histogramme error^2"; usage += "\n absc : get histogramme low bin abscissa (1D only)"; usage += "\n proj :"; usage += "\n show : show available projections for Histo2D"; usage += "\n px : get X projection"; usage += "\n py : get Y projection"; usage += "\n bx n : get X band number n"; usage += "\n by n : get Y band number n"; usage += "\n sx n : get X slice number n"; usage += "\n sy n : get Y slice number n"; usage += "\n Related commands: h/put_vec"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "h/copy"; usage = "Copy content of object1 into object2"; usage += "\n objects are Vector,Matrix,Histo,Histo2D"; usage += "\n h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"; usage += "\n copy obj1Dfrom(i1->i2) into obj1Dto(ic1->)"; usage += "\n copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->)"; usage += "\n Warning: elements from i1 to i2 included are copied"; usage += "\n If obj1Dto does not exist, is is created with size i2-i1+1"; usage += "\n or obj2Dto with size i2-i1+1,j2-j1+1"; usage += "\n The adressed content of obj?Dfrom is overwritten"; usage += "\n The non-adressed content of obj?Dfrom is left unchanged"; usage += "\n Related commands: copy"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "h/set/err"; usage = "Set Histo,Histo2D errors for range of bins or range of values"; usage += "\n h/set/err namehisto setvalue i1[:i2] [j1[:j2]]"; usage += "\n set error to setvalue for bin range i1:i2 j1:j2"; usage += "\n h/set/err namehisto setvalue v v1:v2"; usage += "\n set error to setvalue for content values range v1:v2"; usage += "\n h/set/err namehisto setvalue e e1:e2"; usage += "\n set error to setvalue for error values range v1:v2"; usage += "\n Related commands: h/set/cont"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "h/set/cont"; usage = "Set Histo,Histo2D content for range of bins or range of values"; usage += "\n h/set/cont namehisto setvalue i1[:i2] [j1[:j2]]"; usage += "\n set content to setvalue for bin range i1:i2 j1:j2"; usage += "\n h/set/cont namehisto setvalue v v1:v2"; usage += "\n set content to setvalue for content values range v1:v2"; usage += "\n h/set/cont namehisto setvalue e e1:e2"; usage += "\n set content to setvalue for error values range v1:v2"; usage += "\n Related commands: h/set/err"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "h/err"; usage = "Set Histo,Histo2D error to function of bin content value"; usage += "\n h/err namehisto expr_func"; usage += "\n Related commands: h/set/err"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "herr/mean"; usage = "Perform bin mean computation for HistoErr and Histo2DErr"; usage += "\n herr/mean nameherr todo"; usage += "\n todo = +1 : compute mean"; usage += "\n = -1 : cancel computation"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "herr/variance"; usage = "Perform bin mean and variance computation for HistoErr and Histo2DErr"; usage += "\n herr/variance nameherr todo"; usage += "\n todo = +1 : compute mean and variance"; usage += "\n = -1 : cancel computation"; piac->RegisterCommand(kw,usage,this,hgrp); } /* methode */ PAWExecutor::~PAWExecutor() { } /* methode */ int PAWExecutor::Execute(string& kw, vector& tokens, string& toks) { if(kw == "reset") { reset(tokens); return(0); } else if(kw == "n/plot" || kw == "n/pl") { n_plot(tokens); return(0); } else if(kw == "n/proj") { n_proj(tokens); return(0); } else if(kw == "n/scan") { n_scan(tokens); return(0); } else if(kw == "n/read") { n_read(tokens); return(0); } else if(kw == "n/merge") { n_merge(tokens); return(0); } else if(kw == "n/merge/col") { n_merge_col(tokens); return(0); } else if(kw == "n/assoc/col") { n_assoc_col(tokens); return(0); } else if(kw == "n/copy") { n_copy(tokens); return(0); } else if(kw == "h/integ") { h_integ(tokens); return(0); } else if(kw == "v/integ") { v_integ(tokens); return(0); } else if(kw == "v/sort") { v_sort(tokens); return(0); } else if(kw == "h/deriv") { h_deriv(tokens); return(0); } else if(kw == "v/deriv") { v_deriv(tokens); return(0); } else if(kw == "h/rebin") { h_rebin(tokens); return(0); } else if(kw == "h/cadd") { h_cadd(tokens); return(0); } else if(kw == "h/cmult") { h_cmult(tokens); return(0); } else if(kw == "h/oper") { h_oper(tokens); return(0); } else if(kw == "h/plot/2d") { h_plot_2d(tokens); return(0); } else if(kw == "h/2d/geth") { h_2d_geth(tokens); return(0); } else if(kw == "h/put_vec") { h_put_vec(tokens); return(0); } else if(kw == "h/get_vec") { h_get_vec(tokens); return(0); } else if(kw == "h/copy") { h_copy(tokens); return(0); } else if(kw == "h/set/err") { string dum = "err"; h_set(dum,tokens); return(0); } else if(kw == "h/set/cont") { string dum = "cont"; h_set(dum,tokens); return(0); } else if(kw == "h/err") { h_err(tokens); return(0); } else if(kw == "herr/mean") { herr_mean_variance(tokens,0); return(0); } else if(kw == "herr/variance") { herr_mean_variance(tokens,1); return(0); } else return(1); } /* methode */ bool PAWExecutor::IsThreadable(string const & keyw) { if ( (keyw == "n/plot") || (keyw == "n/pl") || (keyw == "n/proj") ) return true; else return false; } /* methode */ void PAWExecutor::reset(vector& tokens) // Reset d'histogrammes, vecteurs et matrices { if(tokens.size() < 1) {cout<<"Usage: reset nameobj"<DataBlock().Reset(0.);} else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; (*ob) = 0.; } //ob->DataBlock().Reset(0.);} else if(typeid(*mobj)==typeid(Histo)) {Histo* ob=(Histo*) mobj; ob->Zero();} else if(typeid(*mobj)==typeid(HProf)) {HProf* ob=(HProf*) mobj; ob->Zero();} else if(typeid(*mobj)==typeid(Histo2D)) {Histo2D* ob=(Histo2D*)mobj; ob->Zero();} else if(typeid(*mobj)==typeid(HistoErr)) {HistoErr* ob=(HistoErr*) mobj; ob->Zero();} else if(typeid(*mobj)==typeid(Histo2DErr)) {Histo2DErr* ob=(Histo2DErr*) mobj; ob->Zero();} else { cout<<"PAWExecutor::reset Error , No reset possible on "<& tokens) // Equivalent n/plot de paw // Plot 1D // n/plot nameobj.x_exp [cut] [w_exp] [gratt] // Plot 2D (plot2dw) // n/plot nameobj.y_exp%x_exp [cut] [w_exp] [gratt] // Plot 3D (plot3d) // n/plot nameobj.z_exp%y_exp%x_exp [cut] [gratt] { if(tokens.size() < 1) { cout <<"Usage: n/plot nameobj.x_exp [cut] [w_exp] [loop] [gratt] [nomh1]"<=2) expcut = tokens[1]; if(expcut=="!") expcut="1"; NamedObjMgr omg; Services2NObjMgr* srvo = omg.GetServiceObj(); if(nvar<=0) { cout<<"PAWExecutor::n_plot Error: bad coding "<=3) expwt = tokens[2]; if(expwt=="!") expwt="1."; if(tokens.size()>=4) loop = tokens[3]; if(loop=="!") loop=""; if(tokens.size()>=5) dopt = tokens[4]; if(dopt=="!") dopt=""; if(tokens.size()>=6) nameproj = tokens[5]; if(nameproj.length()<=0 || nameproj=="!") { nameproj = "/autoc/paw_n_plot1D_"; AnyDataObj* mobj = omg.GetObj(nameproj); if(mobj!=NULL) { char buff[16]; autoc_counter_++; sprintf(buff,"%d",autoc_counter_); nameproj += buff; } // --- Si option "keepbin" on projete avec le meme binning que l'histo 1D precedent if(dopt.find("keepbin")CurrentBaseWdg(); if(pibwdg) { int nbdrw = pibwdg->NbDrawers(); if(nbdrw>0) { for(int i=nbdrw-1;i>=0;i--) { PIDrawer* pidwr = pibwdg->GetDrawer(i); PIHisto* pih = NULL; if( (pih = dynamic_cast(pidwr))==NULL ) continue; P1DHistoWrapper* h = pih->HistoWrapper(); if(h==NULL) continue; if(h->NBins()<1) continue; Histo* hsame = new Histo(h->XMin(),h->XMax(),h->NBins()); omg.AddObj(hsame,nameproj); break; } } } } } // --- } srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop); } else if(nvar==2) { // c'est un plot 2D if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop=""; if(tokens.size()>=4) dopt = tokens[3]; string err = ""; srvo->DisplayPoints2D(nameobj,expx,expy,err,err,expcut,dopt,loop); } else { // c'est un plot 3D if(tokens.size()>=3) loop = tokens[2]; if(loop=="!") loop=""; if(tokens.size()>=4) dopt = tokens[3]; srvo->DisplayPoints3D(nameobj,expx,expy,expz,expcut,dopt,loop); } return; } /* methode */ void PAWExecutor::n_proj(vector& tokens) // Equivalent n/proj de paw // Project NTuple in histogram a la paw // Dans un Histo 1D // n/proj nameproj nameobj.x_exp [cut] [w_exp] [gratt] // Dans un Histo 2D ou un HProf (dans ce cas nameproj doit etre cree). // n/proj nameproj nameobj.y_exp%x_exp [cut] [w_exp] [gratt] { if(tokens.size()<2) {cout<<"Usage: n/proj nameproj nameobj.[y_exp%]x_exp [cut] [w_exp] [loop] [gratt]"<=3) expcut = tokens[2]; if(expcut=="!") expcut="1"; if(tokens.size()>=4) expwt = tokens[3]; if(expwt=="!") expwt="1."; if(tokens.size()>=5) loop = tokens[4]; if(loop=="!") loop=""; if(tokens.size()>=6) dopt = tokens[5]; NamedObjMgr omg; Services2NObjMgr* srvo = omg.GetServiceObj(); if(nvar==1) { // c'est une projection dans un histo 1D srvo->ProjectH1(nameobj,expx,expwt,expcut,nameproj,dopt,loop); } else if(nvar==2) { // c'est une projection dans un histo2D // OU un HProf si nameproj est un HProf un deja defini AnyDataObj* mobj = omg.GetObj(nameproj); if(mobj==NULL) srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop); else if(dynamic_cast(mobj)) srvo->ProjectHProf(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop); else srvo->ProjectH2(nameobj,expx,expy,expwt,expcut,nameproj,dopt,loop); } else { cout<<"PAWExecutor::n_proj Error: bad coding "<3) { if(tokens[3].find("-f:") == 0) { string filename = tokens[3].substr(3); if(filename.size()>0) { fout = fopen(filename.c_str(),"w"); if(fout==NULL) {cerr<<"PAWExecutor::n_scan Error, file "<GetNTupleInterface(adel); if(objnt == NULL) {cerr<<"PAWExecutor::n_scan Error, NTupleInterface==NULL for " <VarList_C("_zz6qi_"); PlotExprFunc f = srvo.LinkExprFunc(vardec,expr[0],expr[1],expr[2],expr[3],expcut); if(!f) {cerr<<"PAWExecutor::n_scan Error, Creation PlotExprFunc"< de 0 a ncol-1 (toutes les variables) // : v1 --> de 0 a v1 // v1 : --> de v1 a ncol-1 // v1 : v2 --> de v1 a v2 (si v2 apres v1) // v1 et v2 (si v2 avant v1) // v1 v2 v3 v4 --> v1 v2 v3 v4 (ordre indifferent) // et toute combinaison : "v1 : v3 v7 v4 : v6 v2 v9 :" // --> v1 v2 v3 v7 v4 v5 v6 v2 v9 v10...v(ncol-1) int_4 ncol = objnt->NbColumns(); if(ncol<=0) {cerr<<"PAWExecutor::n_scan Error, no columns for NTuple"< varnum; if(ldebvar>=tokens.size()) { // Toutes les variables for(int_4 i=0;iColumnIndex(tokens[ldebvar]); varnum.push_back(k);} ldebvar++; if(ldebvarColumnIndex(tokens[i]); if(frlast) klast = varnum[varnum.size()-1] + 1; if(klast>k) klast=k; for(kk=klast;kk<=k;kk++) varnum.push_back(kk); frlast=false; } else if(i==tokens.size()-1) { // separateur a la fin k = ncol-1; klast = varnum[varnum.size()-1] + 1; if(klast>k) klast=k; for(kk=klast;kk<=k;kk++) varnum.push_back(kk); } else frlast=true; // separateur pas a la fin } } vector varname; if(varnum.size()>0) for(int_4 i=0;i<(int)varnum.size();i++) { if(varnum[i]<0 || varnum[i]>=ncol) {cerr<<"PAWExecutor::n_scan Error, bad variable name at pos " <ColumnName(varnum[i]); varname.push_back(dum); } // evenements a utiliser int_8 k1=0, k2=objnt->NbLines(), dk=1; srvo.DecodeLoopParameters(loop,k1,k2,dk); if (k1<0) k1=0; if (k2<0) k2=objnt->NbLines(); if (k2>(int_8)objnt->NbLines()) k2=objnt->NbLines(); if (dk<=0) dk=1; // boucle sur les evenements et print try { int_4 i; if(fout) fprintf(fout,"#ev "); else printf("#ev "); for(i=0;i<(int)varname.size();i++) if(fout) fprintf(fout,"%s ",varname[i].c_str()); else printf( "%s ",varname[i].c_str()); if(nexpr>0) for(i=0;iGetLineD(k); if(f((int_8_exprf)k,xn,xnt,xnt+1,xnt+2,xnt+3) != 0) { if(fout) fprintf(fout,"%ld ",(long)k); else printf("%ld ",(long)k); for(i=0;i<(int)varnum.size();i++) { if(fout) fprintf(fout,"%g ",*(xn+varnum[i])); else printf( "%g ",*(xn+varnum[i])); } if(nexpr>0) for(i=0;i& tokens) { int lp=1; if(tokens.size()<3) { cerr<<"Usage: n/read nt fascii [options] var_1,c_1 ... var_n,c_n"< donotreadbeg; vector donotreadin; vector onlyreadbeg; vector onlyreadin; vector varname; vector colnum; char separator = ' '; int numcolmaxi=-1; for(int i=2;i<(int_4)tokens.size();i++) { int lc = tokens[i].size(); if(lc<2) continue; if(tokens[i].find("-dt")==0) { // create DataTable instead of NTuple create_datatable = true; continue; } const char *c = tokens[i].c_str(); if(c[0]=='=') { // Separator separator = c[1]; if(lc==3) if(c[1]=='\\' && c[2]=='t') separator = '\t'; continue; } if(c[0]=='+') { // Selection des lignes a lire if(c[1]!='^') onlyreadin.push_back(&c[1]); else if(lc>2) onlyreadbeg.push_back(&c[2]); continue; } if(c[0]=='-') { // Selection des lignes commentaire if(c[1]!='^') donotreadin.push_back(&c[1]); else if(lc>2) donotreadbeg.push_back(&c[2]); continue; } // decodage des noms de variables et des colonnes associees int p = tokens[i].find(','); if(p<1 || p>=lc-1) continue; string vn = tokens[i].substr(0,p); string cn = tokens[i].substr(p+1,lc-p-1); int ic = atoi(cn.c_str()); if(ic<0) continue; if( !isalpha(vn[0]) ) continue; if(ic>numcolmaxi) numcolmaxi = ic; varname.push_back(vn); colnum.push_back(ic); } int nvar = varname.size(); if(nvar<=0) { cerr<<"n_read: no variables to be read"<0) { cout<<"n_read Only read line containing ["<0) { cout<<"n_read Only read line begining with ["<0) { cout<<"n_read Do not read line containing ["<0) { cout<<"n_read Do not read line begining with ["<0) { cout<<"n_read Number of variables to be read: "<(varname[i].c_str()); nt = new NTuple(nvar,ntvn); delete [] ntvn; } else { //create DataTable dt = new DataTable(); for(int i=0;iAddDoubleColumn(varname[i]); } r_8 *xnt = new r_8[nvar]; // Read file char *line = new char[__LENLINE_N_READ__]; int nline=0, nlinecom=0; while(fgets(line,__LENLINE_N_READ__,fascii) != NULL ) { nline++; uint_4 lc = strlen(line); if(lc<1) continue; // Pour enlever le \n final if(line[lc-1]=='\n' || line[lc-1]=='\r') {line[lc-1]='\0'; lc = strlen(line); if(lc<1) continue;} string const sline(line); //cout<<"\'"<=lvs) continue; xnt[i] = atof(vs[ic].c_str()); } if(nt) nt->Fill(xnt); else if(dt) dt->Fill(xnt); //cout<<"...xnt"; for(int i=0;iNEntry(): dt->NEntry(); cout<<"n_read: "<0) { if(nt) omg.AddObj(nt,nament); if(dt) omg.AddObj(dt,nament); } else { if(nt) delete nt; if(dt) delete dt; } delete [] xnt; delete [] line; fclose(fascii); return; } #undef __LENLINE_N_READ__ /* methode */ void PAWExecutor::n_merge(vector& tokens) { if(tokens.size()<2) { cerr<<"Usage: n/merge nt nt_1 nt_2 ... nt_n"<(mobj); if(nt1==NULL) { cout<<"n_merge Error: "<NEntry()==0) { cout<<"n_merge Error: "<NVar()==0) { cout<<"n_merge Error: "<NVar(); vector sntvn; for(int iv=0;ivColumnName(iv)); char **ntvn = new char*[nvar]; for(int iv=0;iv(sntvn[iv].c_str()); nt = new NTuple(nvar,ntvn); delete [] ntvn; } // filling with current ntuple int nvar1 = nt1->NVar(); int n = (nvar1>nvar)? nvar1: nvar; r_8 *xnt1 = new r_8[n]; for(int iev=0;ievNEntry();iev++) { nt1->GetVecD(iev,xnt1); nt->Fill(xnt1); } nfill++; delete [] xnt1; } if(xnt!=NULL) delete [] xnt; if(nt!=NULL) { cout<<"n_merge: ntuple filled with "<NEntry()<<" entries"<NEntry()>0) omg.AddObj(nt,nament); else delete nt; } return; } /* methode */ void PAWExecutor::n_merge_col(vector& tokens) { if(tokens.size()<2) { cerr<<"Usage: n/merge/col nt nt_1[,ext] nt_2[,ext] ... nt_n[,ext]"< varname; vector ntname; vector posfirst; for(int i=1;i<(int_4)tokens.size();i++) { // Decode NTuple name and extension int_4 lc = tokens[i].size(); string ntn = tokens[i]; string ext = ""; int p = ntn.find(','); if(p>=0 && p0) ntn = ntn.substr(0,p); else ntn = ""; } // choose the extentsion: given,automatic,none if(ext.size()<1) { char str[8]; sprintf(str,"_%d",numnt); ext = str; } else if(ext[0] == '!') { ext = ""; } AnyDataObj* mobj = omg.GetObj(ntn); if(mobj==NULL) { cout<<"n_merge_col Error: unknow object "<(mobj); if(nt1==NULL) { cout<<"n_merge_col Error: "<NEntry()==0) { cout<<"n_merge_col Error: "<NVar()==0) { cout<<"n_merge_col Error: "<NEntry()>(int_4)nentmax) nentmax = nt1->NEntry(); for(int iv=0;ivNVar();iv++) { string str = nt1->ColumnName(iv) + ext; varname.push_back(str); } numnt++; ipos += nt1->NVar(); } if(ntname.size()==0) { cout<<"n_merge_col Error: no ntuple found in argument list"<(varname[iv].c_str()); NTuple * nt = new NTuple(nvar,ntvn); //for(int i=0;i<(int_4)ntname.size();i++) cout<NEntry()<<" entries"<NEntry()>0) omg.AddObj(nt,nament); else delete nt; return; } /* methode */ void PAWExecutor::n_assoc_col(vector& tokens) { if(tokens.size()<4) { cerr<<"Usage: n/assoc/col ntass[,u] nt_1[,ext] nt_2[,ext] nt_assoc[,icass]"< ntass.NEntry == nt_1.NEntry // = 1 : on remplit uniquement les lignes associees // lignes associees uniquement // -> ntass.NEntry <= min(nt_1.NEntry,nt_2.NEntry) // = 2 : on remplit l'union des lignes // lignes associees + non-associees de nt_1 + non-associees de nt_2 // -> ntass.NEntry >= max(nt_1.NEntry,nt_2.NEntry) uint_2 do_merge=0; string ntmerge = tokens[0]; int lc = tokens[0].size(); int p = tokens[0].find(','); if(p>=0 && p=0 && p=0 && p=0 && p0) ntname = ntname.substr(0,p); else ntname = ""; } // choose the extension: given,automatic,none if(i==2) { // numero de colonne avec l'index d'association if(ext[0] == '!') ext = ""; if(ext.size()>0) icass = atoi(ext.c_str()); } else { if(ext.size()<1) { char str[8]; sprintf(str,"_%d",i); ext = str; } else if(ext[0] == '!') { ext = ""; } } AnyDataObj* mobj = omg.GetObj(ntname); if(mobj==NULL) { cout<<"n_assoc_col Error: unknow object "<(mobj); if(nt[i]==NULL) { cout<<"n_assoc_col Error: "<NEntry()==0) { cout<<"n_assoc_col Error: "<NVar()==0) { cout<<"n_assoc_col Error: "<NVar();iv++) { string str = nt[i]->ColumnName(iv) + ext; varname.push_back(str); } } // Checking size of associated ntuple if(nt[0]->NEntry() != nt[2]->NEntry()) { cout<<"n_assoc_col Error: nentries mismatch " <<" first ntuple"<<"="<NEntry() <<", assoc ntuple"<<"="<NEntry()<=nt[2]->NVar()) { cout<<"n_assoc_col Error: bad association column number " <NVar()<(varname[iv].c_str()); NTuple * ntass = new NTuple(nvar,ntvn); delete [] ntvn; // Filling with current ntuple // the first column gives the associated line in nt[1] int_4 nfill[2]={0,0}; r_8 *xass = new r_8[nt[2]->NVar()]; r_8 *xnt = new r_8[nvar]; uint_2 *use2 = NULL; if(do_merge==2) { use2 = new uint_2[nt[1]->NEntry()]; for(int i=0;iNEntry();i++) use2[i] = 0; } for(int iev=0;ievNEntry();iev++) { nt[2]->GetVecD(iev,xass); int iass = (xass[icass]<0.) ? -1: int(xass[icass]+0.5); bool okass = (iass>=0 && iassNEntry()); if(do_merge==1 && !okass) continue; // pas d'assoc et intersection demandee for(int iv=0;ivGetVecD(iev,xnt); if(okass) { nt[1]->GetVecD(iass,&xnt[nt[0]->NVar()]); if(do_merge==2) use2[iass] = 1; } else nfill[0]++; ntass->Fill(xnt); } // Filling with remaining unassociated in nt[1] if requested if(do_merge==2) { for(int iev=0;ievNEntry();iev++) { if(use2[iev]!=0) continue; // deja rempli for(int iv=0;ivGetVecD(iev,&xnt[nt[0]->NVar()]); ntass->Fill(xnt); nfill[1]++; } } // Ending and saving merged ntuple delete [] xnt; delete [] xass; if(use2) delete [] use2; cout<<"n_assoc_col: ntuple "<NEntry()<<" entries" <<", unassoc in nt_1="<(mobj); if(nt==NULL) { cout<<"n_copy Error: "<NEntry()==0) { cout<<"n_copy Error: "<NVar()==0) { cout<<"n_copy Error: "< varname; vector ivar; if(tokens.size()==2) { nvar = nt->NVar(); for(int i=0;iNomIndex(i)); } } else { nvar = tokens.size()-2; for(int i=0;iIndexNom(tokens[i+2].c_str()); if(iv<0) { cout<<"n_copy Error: unkown variable "<(varname[i].c_str()); NTuple ntnew(nvar,ntvn); delete [] ntvn; // Copie du NTuple r_8 *xnt = new r_8[nt->NVar()]; r_8 *xntnew = new r_8[nvar]; for(int iev=0;ievNEntry();iev++) { nt->GetVecD(iev,xnt); for(int i=0;i& tokens) // Pour remplacer le contenu d'un histo 1D par son integrale { if(tokens.size()<1) {cout<<"Usage: h/integ nameh1d [norm]"<=2) norm = atof(tokens[1].c_str()); // attention: dynamic_cast(HProf)=Vrai! Histo* h1 = dynamic_cast(mobj); HProf* hp = dynamic_cast(mobj); if(hp || !h1) {cout<<"PAWExecutor::h_integ Error: "<HInteg(norm); } /* methode */ void PAWExecutor::v_integ(vector& tokens) // Pour remplacer le contenu d'un TVector par son integrale // normalisee a norm: // Si norm <= 0 : pas de normalisation, integration seule { if(tokens.size()<1) {cout<<"Usage: v/integ namevec [norm]"<=2) norm = atof(tokens[1].c_str()); TVector* v = dynamic_cast*>(mobj); if(!v) {cout<<"PAWExecutor::v_integ Error: "<Size(); if(n==0) {cout<<"PAWExecutor::v_integ Error: "<1) for(uint_4 i=1;i& tokens) // Pour sort in-place d'un vecteur ascendant ou descendant { if(tokens.size()<1) {cout<<"Usage: v/sort namevec [+1/-1]"<=2) if(atoi(tokens[1].c_str())<0) up=false; { TVector* v = dynamic_cast*>(mobj); if(v) { if(v->Size()==0) return; if(up) stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_up_r8); else stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_down_r8); cout<<"median is: "<<0.5*((*v)(v->Size()/2)+(*v)((v->Size()-1)/2))<* v = dynamic_cast*>(mobj); if(v) { if(v->Size()==0) return; if(up) stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_up_r4); else stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_down_r4); cout<<"median is: "<<0.5*((*v)(v->Size()/2)+(*v)((v->Size()-1)/2))<* v = dynamic_cast*>(mobj); if(v) { if(v->Size()==0) return; if(up) stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_up_i4); else stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_down_i4); cout<<"median is: "<<0.5*((*v)(v->Size()/2)+(*v)((v->Size()-1)/2))<* v = dynamic_cast*>(mobj); if(v) { if(v->Size()==0) return; if(up) stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_up_u8); else stable_sort(v->Data(), v->Data()+v->Size(), __vector_sort_down_u8); cout<<"median is: "<<0.5*((*v)(v->Size()/2)+(*v)((v->Size()-1)/2))<"<& tokens) // Pour remplacer le contenu d'un histo 1D par sa derivee { if(tokens.size()<1) {cout<<"Usage: h/deriv nameh1d"<(HProf)=Vrai! Histo* h1 = dynamic_cast(mobj); HProf* hp = dynamic_cast(mobj); if(hp || !h1) {cout<<"PAWExecutor::h_deriv Error: "<HDeriv(); } /* methode */ void PAWExecutor::v_deriv(vector& tokens) // Pour remplacer le contenu d'un TVector par sa derivee // deriv_option = -1 replace v[i] with v[i]-v[i-1] // = 0 replace v[i] with (v[i+1]-v[i-1])/2 (default) // = +1 replace v[i] with v[i+1]-v[i] { if(tokens.size()<1) {cout<<"Usage: v/deriv namevec [deriv_option(-1,0,+1)]"<=2) deriv_option = atoi(tokens[1].c_str()); TVector* v = dynamic_cast*>(mobj); if(!v) {cout<<"PAWExecutor::v_deriv Error: "<Size(); if(n==0) {cout<<"PAWExecutor::v_deriv Error: "< vsave(*v,false); if(deriv_option<0) { for(uint_4 i=1;i0) { for(uint_4 i=0;i& tokens) // Pour re-binner un histogramme 1D { if(tokens.size()<2) {cout<<"Usage: h/rebin nameh1d nbin"<(mobj); // Ca marche aussi pour les HProf, HRebin a ete passe virtuel //HProf* hp = dynamic_cast(mobj); if(hp || !h1) if(!h1) {cout<<"PAWExecutor::h_rebin Error: "<HRebin(nbin); } /* methode */ void PAWExecutor::h_cadd(vector& tokens) // Additionne une constante a un histogramme { if(tokens.size()<2) {cout<<"Usage: h/cadd nameh1d val"<(mobj); HProf* hp = dynamic_cast(mobj); Histo2D* h2 = dynamic_cast(mobj); Vector* v = dynamic_cast(mobj); Matrix* m = dynamic_cast(mobj); if(h1 && !hp) *h1 += val; else if(h2) *h2 += val; else if(v) *v += val; else if(m) *m += val; else cout<<"PAWExecutor::h_cadd Error: not implemented for "<& tokens) // Multiplie un histogramme par une constante { if(tokens.size()<2) {cout<<"Usage: h/cmult nameh1d val"<(mobj); HProf* hp = dynamic_cast(mobj); Histo2D* h2 = dynamic_cast(mobj); Vector* v = dynamic_cast(mobj); Matrix* m = dynamic_cast(mobj); if(h1 && !hp) *h1 *= val; else if(h2) *h2 *= val; else if(v) *v *= val; else if(m) *m *= val; else cout<<"PAWExecutor::h_mult Error: not implemented for "<& tokens) // Equivalent h/oper/add sub,mul,div de paw // Operation entre 2 histogrammes ou 2 vecteurs ou 2 matrices // h/oper @ h1 h2 hres // hres = h1 @ h2 with @ = (+,-,*,/) // Pour les vecteurs et les matrices, il sagit d'operations elements a elements { if(tokens.size()<4) {cout<<"Usage: n/oper @ h1 h2 hres with @=(+,-,*,/,@)"<(mobjh1) != NULL ) { if( oper[0]!='+' ) { cout<<"PAWExecutor::h_oper Error: operation "<(mobjh2) == NULL ) {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n" <NBins() != h2->NBins() ) {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 " <NBins()<<" "<NBins()<Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);} h3 = dynamic_cast(mobjh3); if(h3 == NULL) // ce n'est pas un HProf {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n" <NBins() != h3->NBins()) {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 " <NBins()<<" "<NBins()<UpdateHisto(); // Operations on Histo } else if( dynamic_cast(mobjh1) != NULL ) { if( dynamic_cast(mobjh2) == NULL ) {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n" <NBins() != h2->NBins() ) {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 " <NBins()<<" "<NBins()<Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);} h3 = dynamic_cast(mobjh3); if(h3 == NULL) // ce n'est pas un Histo {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n" <NBins() != h3->NBins()) {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 " <NBins()<<" "<NBins()<(mobjh1) != NULL ) { if( dynamic_cast(mobjh2) == NULL ) {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n" <NBinX() != h2->NBinX() || h1->NBinY() != h2->NBinY() ) {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 " <NBinX()<<","<NBinY()<<" " <NBinX()<<","<NBinY()<Zero(); omg.AddObj(h3,h3name); mobjh3 = omg.GetObj(h3name);} h3 = dynamic_cast(mobjh3); if(h3 == NULL) // ce n'est pas un Histo2D {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n" <NBinX() != h3->NBinX() || h1->NBinY() != h3->NBinY() ) {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 " <NBinX()<<","<NBinY()<<" " <NBinX()<<","<NBinY()<(mobjh1) != NULL ) { if( dynamic_cast(mobjh2) == NULL ) {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n" <NElts() != h2->NElts() ) {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 " <NElts()<<" "<NElts()<(mobjh3); if(h3 == NULL) // ce n'est pas un Vector {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n" <NElts() != h3->NElts()) {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 " <NElts()<<" "<NElts()<Clone(*h1); h3->MulElt(*h2,*h3);} else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,*h3,false,true);} // Operations on Matrix } else if( dynamic_cast(mobjh1) != NULL ) { if( dynamic_cast(mobjh2) == NULL ) {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h2\n" <NRows() != h2->NRows() || h1->NCol() != h2->NCol() ) {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h2 " <NRows()<<","<NCol()<<" " <NRows()<<","<NCol()<(mobjh3); if(h3 == NULL) // ce n'est pas un Matrix {cout<<"PAWExecutor::h_oper Error: type mismatch between h1 and h3\n" <NRows() != h3->NRows() || h1->NCol() != h3->NCol() ) {cout<<"PAWExecutor::h_oper Error: size mismatch between h1, h3 " <NRows()<<","<NCol()<<" " <NRows()<<","<NCol()<Clone(*h1); h3->MulElt(*h2,*h3);} else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,*h3,false,true);} // Doesn't work for other objects } else { cout<<"PAWExecutor::h_oper Error: not implemented for " <& tokens) // plot for 2D histogramme: plot histo, bandx/y, slicex/y or projx/y { if(tokens.size()<1) {cout<<"Usage: h/plot/2d nameh2d to_plot [n/s] [dopt]"<1) proj = tokens[1]; NamedObjMgr omg; AnyDataObj* mobj = omg.GetObj(tokens[0]); if(mobj==NULL) {cout<<"PAWExecutor::h_plot_2d Error: unknow object"<(mobj); if(!h2) {cout<<"PAWExecutor::h_plot_2d Error: "<=3) dopt = tokens[2]; if(proj == "show") { h2->ShowProj(); h2->ShowBand(2); h2->ShowSli(2); return; } else if(proj == "h") { nametoplot = tokens[0]; } else if(proj == "px") { if((h1p=h2->HProjX())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} else {h2->ShowProj(); return;} } else if(proj == "py") { if((h1p=h2->HProjY())) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} else {h2->ShowProj(); return;} } else { if(tokens.size()<3) {cout<<"Usage: h/plot/2d nameh2d bx/by/sx/sy n [dopt]"<=4) dopt = tokens[3]; if(proj == "bx") { if((h1p=h2->HBandX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} else {h2->ShowBand(); return;} } else if(proj == "by") { if((h1p=h2->HBandY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} else {h2->ShowBand(); return;} } else if(proj == "sx") { if((h1p=h2->HSliX(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} else {h2->ShowSli(); return;} } else if(proj == "sy") { if((h1p=h2->HSliY(n))) {Histo* h1=new Histo(*h1p); omg.AddObj(h1,nametoplot);} else {h2->ShowSli(); return;} } } omg.DisplayObj(nametoplot,dopt); } /* methode */ void PAWExecutor::h_2d_geth(vector& tokens) // copy bandx/y, slicex/y or projx/y from an 2D histo into a 1D histo { NamedObjMgr omg; if(tokens.size()==1) { AnyDataObj* mobj = omg.GetObj(tokens[0]); Histo2D* h2 = dynamic_cast(mobj); if(!h2) return; h2->ShowProj(); h2->ShowBand(2); h2->ShowSli(2); return; } if(tokens.size()<3) {cout<<"Usage: h/2d/geth h nameh2d [px,py,bx n,by n,sx n,sy n]"<3)? atoi(tokens[3].c_str()): -1; // Decodage Histo2D AnyDataObj* mobj = omg.GetObj(tokens[1]); if(mobj==NULL) {cout<<"PAWExecutor::h_2d_geth Error: unknow object"<(mobj); if(!h2) {cout<<"PAWExecutor::h_plot_2d Error: "<HProjX())) {Histo* h=new Histo(*h1p); omg.AddObj(h,nameh1);} else h2->ShowProj(); } else if(proj == "py") { if((h1p=h2->HProjY())) {Histo* h=new Histo(*h1p); omg.AddObj(h,nameh1);} else h2->ShowProj(); } else if(proj == "bx" && nump>=0) { if((h1p=h2->HBandX(nump))) {Histo* h=new Histo(*h1p); omg.AddObj(h,nameh1);} else h2->ShowBand(); } else if(proj == "by" && nump>=0) { if((h1p=h2->HBandY(nump))) {Histo* h=new Histo(*h1p); omg.AddObj(h,nameh1);} else h2->ShowBand(); } else if(proj == "sx" && nump>=0) { if((h1p=h2->HSliX(nump))) {Histo* h=new Histo(*h1p); omg.AddObj(h,nameh1);} else h2->ShowSli(); } else if(proj == "sy" && nump>=0) { if((h1p=h2->HSliY(nump))) {Histo* h=new Histo(*h1p); omg.AddObj(h,nameh1);} else h2->ShowSli(); } else { cout<<"PAWExecutor::h_2d_geth Error: Unknown proj name "<0) {np = 0; if(xexp.length()>0) {np++; if(yexp.length()>0) {np++; if(zexp.length()>0) np++;}}} //cout<<"pawstring["<2) toput = tokens[2]; if(toput=="!") toput = "cont"; if(toput!="cont" && toput!="err2") {cout<<"PAWExecutor::h_put_vec Error: unknow filling "<(mobjh); Vector* v = dynamic_cast(mobjv); if(toput=="cont") h->PutValue(*v); else if(toput=="err2") h->PutError2(*v); // Fill Histo2D from Matrix } else if(typeid(*mobjh) == typeid(Histo2D) && typeid(*mobjv) == typeid(Matrix)) { Histo2D* h = dynamic_cast(mobjh); Matrix* v = dynamic_cast(mobjv); if(toput=="cont") h->PutValue(*v); else if(toput=="err2") h->PutError2(*v); } else { cout<<"PAWExecutor::h_put_vec Error: type mismatch between histogram and vector/matrix\n" <& tokens) // Pour copier un histo dans un vecteur ou une matrice // Si le vecteur (matrice) n'existe pas, il est cree. // Le vecteur ou la matrice est re-dimensionne correctement. // tokens[2] = "cont" : on copie les valeurs de l'histogramme (ou "!") // = "err2" : on copie les erreurs de l'histogramme // = "absc" : on copie les erreurs de l'histogramme (1D only) // tokens[3[,4]] = show : show available projections for Histo2D // px : get X projection // py : get Y projection // bx n : get X band number n // by n : get Y band number n // sx n : get X slice number n // sy n : get Y slice number n { if(tokens.size()<2) {cout<<"Usage: h/get_vec namehisto namevector"<2) toget = tokens[2]; if(toget=="!") toget = "cont"; if(toget!="cont" && toget!="err2" && toget!="absc") {cout<<"PAWExecutor::h_get_vec Error: unknow filling "<3) proj = tokens[3]; int_4 nproj = -1; if(tokens.size()>4) nproj = atoi(tokens[4].c_str()); string hname = tokens[0]; string vname = tokens[1]; // Get objects NamedObjMgr omg; AnyDataObj* mobjh = omg.GetObj(hname); AnyDataObj* mobjv = omg.GetObj(vname); if( mobjh==NULL) {cout<<"PAWExecutor::h_put_vec Error: unknow object(s) "<(mobjh); Histo2D* h2 = dynamic_cast(mobjh); if( h != NULL ) { // Histo ou HProf h->UpdateHisto(); // pour le cas ou c'est un HProf Vector* v = NULL; if(mobjv==NULL) // le vecteur n'existe pas {v = new Vector(1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);} if(typeid(*mobjv) != typeid(Vector)) {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo/HProf and vector\n" <(mobjv); if(toget=="cont") h->GetValue(*v); else if(toget=="err2") h->GetError2(*v); else if(toget=="absc") h->GetAbsc(*v); } else if( h2 != NULL) { // Histo2D if(proj == "h") { // On veut les valeurs de l'histogramme 2D Matrix* v = NULL; if(mobjv==NULL) // la matrice n'existe pas {v = new Matrix(1,1); omg.AddObj(v,vname); mobjv = omg.GetObj(vname);} if(typeid(*mobjv) != typeid(Matrix)) {cout<<"PAWExecutor::h_get_vec Error: type mismatch between Histo2D and matrix\n" <(mobjv); if(toget=="cont") h2->GetValue(*v); else if(toget=="err2") h2->GetError2(*v); else {cout<<"PAWExecutor::h_get_vec Error: option "<ShowProj(); h2->ShowBand(2); h2->ShowSli(2);} else if(proj == "px") h = h2->HProjX(); else if(proj == "py") h = h2->HProjY(); else if(proj == "bx") h = h2->HBandX(nproj); else if(proj == "by") h = h2->HBandY(nproj); else if(proj == "sx") h = h2->HSliX(nproj); else if(proj == "sy") h = h2->HSliY(nproj); if(h==NULL) {cout<<"PAWExecutor::h_get_vec Error: unknown projection "<(mobjv); if(toget=="cont") h->GetValue(*v); else if(toget=="err2") h->GetError2(*v); else if(toget=="absc") h->GetAbsc(*v); } } else { cout<<"PAWExecutor::h_get_vec Error: type mismatch for histogram\n" <& tokens) // Pour copier un object dans un object // objects are Vector,Matrix,Histo,Histo2D // h/copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]] // copy obj1Dfrom(i1->i2) into obj1Dto(ic1->) // copy obj2Dfrom(i1,j1->i2,j2) into obj2Dto(ic1,jc1->) // Attention: elements depuis i1 jusqu'a i2 COMPRIS // Si obj1Dto n'existe pas, il est cree avec une taille i2-i1+1 // ou obj2Dto avec une taille i2-i1+1,j2-j1+1 // Le contenu de obj?Dfrom adresse est surecrit // Le contenu de obj?Dfrom non adresse reste le meme { int_4 tks = tokens.size(); if(tks<2) {cout<<"Usage: h_copy namefrom nametocopy [i1[:i2]] [j1[:j2]] [ic1[:jc1]]"<(mobjv1); nx1 = (int_4)v1->NElts(); i2=nx1-1; if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2); if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(i2(mobjv2); nx2 = (int_4)v2->NElts(); if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1); if(ic1<0) ic1=0; if(ic1>=nx2) {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<...)"<(mobjv1); nx1 = (int_4)v1->NBins(); i2=nx1-1; if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2); if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(i2(mobjv2); nx2 = (int_4)v2->NBins(); if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors(); if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d",&ic1); if(ic1<0) ic1=0; if(ic1>=nx2) {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<...)"<HasErrors()) v2->Error2(ii) = v1->Error2(i);} return; } // Cas d'une Matrix if(typeid(*mobjv1) == typeid(Matrix)) { Matrix* v1 = dynamic_cast(mobjv1); nx1=v1->NRows(); ny1=v1->NCol(); i2=nx1-1; j2=ny1-1; if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2); if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2); if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1; if(i2(mobjv2); nx2=v2->NRows(); ny2=v2->NCol(); if(tks>4) if(tokens[4]!="!") sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1); if(ic1<0) ic1=0; if(jc1<0) jc1=0; if(ic1>=nx2 || jc1>=ny2) {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<...)"<(mobjv1); nx1=v1->NBinX(); ny1=v1->NBinY(); i2=nx1-1; j2=ny1-1; if(tks>2) if(tokens[2]!="!") sscanf(tokens[2].c_str(),"%d:%d",&i1,&i2); if(tks>3) if(tokens[3]!="!") sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2); if(i1<0) i1=0; if(i2>=nx1) i2=nx1-1; if(j1<0) j1=0; if(j2>=ny1) j2=ny1-1; if(i2(mobjv2); nx2=v2->NBinX(); ny2=v2->NBinY(); if(v1->HasErrors() && !(v2->HasErrors())) v2->Errors(); if(tks>4) sscanf(tokens[4].c_str(),"%d:%d",&ic1,&jc1); if(ic1<0) ic1=0; if(jc1<0) jc1=0; if(ic1>=nx2 || jc1>=ny2) {cout<<"PAWExecutor::h_copy Error: wrong pointer to copy ["<...)"<HasErrors()) v2->Error2(ii,jj) = v1->Error2(i,j);} return; } // Cas non prevu cout<<"PAWExecutor::h_copy Error: type mismatch for Vector/Matrix/Histo/Histo2D\n" <& tokens) // Mise de valeurs/erreurs d'un histo 1D ou 2D a une valeur donnee // dum = err : on change les valeurs des erreurs // cont : on change les valeurs du contenu des bins // tokens[0] : nom de l'histogramme // tokens[1] : valeur de remplacement // tokens[2-3] : i1:i2 j1:j2 intervalle des bins qui doivent etre remplace // : v v1:v2 remplacement des bins ayant une valeur dans cet intervalle // : e e1:e2 remplacement des bins ayant une erreur dans cet intervalle { int_4 tks = tokens.size(); if(tks<3) {cout<<"Usage: h/set/[err,cont] namehisto setvalue i1[:i2] [j1[:j2]]\n" <<" v v1:v2\n" <<" e e1:e2" <3) sscanf(tokens[3].c_str(),"%d:%d",&j1,&j2); } else { if(tks<=3) {cout<<"PAWExecutor::h_set Error: h/set/... v v1:v2, please give v1:v2"<(mobj); if( (replerr || testcont==2) && !(h->HasErrors()) ) {cout<<"PAWExecutor::h_set Error: histogram has no errors"<NBins()-1;} if(i1<0 || i1>=h->NBins()) {cout<<"PAWExecutor::h_set Error: bad bin range i1="<=h->NBins()) i2=h->NBins()-1; for(int_4 i=i1;i<=i2;i++) { bool change = true; if(testcont==1) {if((*h)(i)v2) change = false;} else if(testcont==2) {if(h->Error(i)Error(i)>v2) change = false;} if(!change) continue; if(replerr) h->Error2(i) = setval; else (*h)(i) = setval; } } else if(typeid(*mobj) == typeid(Histo2D)) { // Histo 2D Histo2D* h2 = dynamic_cast(mobj); if( (replerr || testcont==2) && !(h2->HasErrors()) ) {cout<<"PAWExecutor::h_set Error: histogram has no errors"<NBinX()-1;j1=0; j2=h2->NBinY()-1;} if(i1<0 || i1>=h2->NBinX() || j1<0 || j1>=h2->NBinY()) {cout<<"PAWExecutor::h_set Error: bad bin range i1,j1="<=h2->NBinX()) i2=h2->NBinX()-1; if(j2=h2->NBinY()) j2=h2->NBinY()-1; for(int_4 i=i1;i<=i2;i++) for(int_4 j=j1;j<=j2;j++) { bool change = true; if(testcont==1) {if((*h2)(i,j)v2) change = false;} else if(testcont==2) {if(h2->Error(i,j)Error(i,j)>v2) change = false;} if(!change) continue; if(replerr) h2->Error2(i,j) = setval; else (*h2)(i,j) = setval; } } else { cout<<"PAWExecutor::h_set Error: type mismatch for Histo/Histo2D\n" <& tokens) // Mise des erreurs d'un histo 1D ou 2D a une valeur // donnee par une fonction de la valeur du bin // tokens[0] : nom de l'histogramme // tokens[1] : expression de la fonction { if(tokens.size()<2) {cout<<"Usage: h/err namehisto expr_func"<\n"); fprintf(fip,"double %s(double x) \n{\n",func.c_str()); fprintf(fip,"return(%s); \n}\n", expfunc.c_str()); fclose(fip); DlFunctionOfX f = (DlFunctionOfX) omg.GetServiceObj()->LinkFunctionFromFile(fname,func); if(!f) {cout<<"PAWExecutor::h_err Error: bad function "<(mobj); if(!(h->HasErrors())) h->Errors(); for(int_4 i=0;iNBins();i++) { r_8 x = (*h)(i); r_8 e = f(x); h->SetErr2(i,e*e); } } else if(typeid(*mobj) == typeid(Histo2D)) { // Histo 2D Histo2D* h2 = dynamic_cast(mobj); if(!(h2->HasErrors())) h2->Errors(); for(int_4 i=0;iNBinX();i++) for(int_4 j=0;jNBinY();j++) { r_8 x = (*h2)(i,j); r_8 e = f(x); h2->Error2(i,j) = e*e; } } else { cout<<"PAWExecutor::h_err Error: type mismatch for Histo/Histo2D\n" <& tokens,int var) // Pour appliquer ToMean ou FromMean a un HistoErr ou Histo2DErr // Pour appliquer ToVariance ou FromVariance a un HistoErr ou Histo2DErr { int_4 tks = tokens.size(); if(tks<1) { cout<<"Usage: herr_mean_variance namehisterr [+1,-1]"<1) sens = atoi(tokens[1].c_str()); HistoErr *herr = dynamic_cast(mobj); Histo2DErr *herr2 = dynamic_cast(mobj); if(sens>=0) { if(herr) {if(var==1) herr->ToVariance(); else herr->ToMean();} else if(herr2) {if(var==1) herr2->ToVariance(); else herr2->ToMean();} } else { if(herr) {if(var==1) herr->FromVariance(); else herr->FromMean();} else if(herr2) {if(var==1) herr2->FromVariance(); else herr2->FromMean();} } int nmean = 0; if(herr) nmean = herr->NMean(); else if(herr2) nmean = herr2->NMean(); cout<