#include #include #include #include #include #include "strutil.h" #include "histos.h" #include "histos2.h" #include "hisprof.h" #include "ntuple.h" #include "pawexecut.h" #include "nobjmgr.h" #include "servnobjm.h" #include "pistdimgapp.h" #ifdef SANS_EVOLPLANCK #include "cvector.h" #include "matrix.h" #else #include "tmatrix.h" #include "tvector.h" #endif /* Reza + cmv 13/10/99 */ uint_4 PAWExecutor::autoc_counter_ = 0; /* methode */ PAWExecutor::PAWExecutor(PIACmd *piac, PIStdImgApp* app) : mApp(app) { string kw, usage; string hgrp = "pawCmd"; 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"; 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 Related commands: plot2dw plot3d"; 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 Related commands: projh1d projh2d projprof"; piac->RegisterCommand(kw,usage,this,hgrp); kw = "h/integ"; usage = "Integrate a 1D histogram"; usage += "\n h/integ nameh1d [norm]"; usage += "\n Related commands: h/deriv"; 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"; 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"; 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/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); } /* methode */ PAWExecutor::~PAWExecutor() { } /* methode */ int PAWExecutor::Execute(string& kw, vector& tokens) { if(kw == "reset") { reset(tokens); return(0); } else if(kw == "n/plot") { n_plot(tokens); return(0); } else if(kw == "n/proj") { n_proj(tokens); return(0); } else if(kw == "h/integ") { h_integ(tokens); return(0); } else if(kw == "h/deriv") { h_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/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 return(1); } /* methode */ void PAWExecutor::reset(vector& tokens) // Reset d'histogrammes, vecteurs et matrices { if(tokens.size() < 1) {cout<<"Usage: reset nameobj"<Zero();} else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; ob->Zero();} #else if(typeid(*mobj)==typeid(Vector)) {Vector* ob=(Vector*) mobj; (*ob) = 0.; } // ob->DataBlock().Reset(0.);} else if(typeid(*mobj)==typeid(Matrix)) {Matrix* ob=(Matrix*) mobj; (*ob) = 0.; } //ob->DataBlock().Reset(0.);} #endif 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 { 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; } } 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 "<=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::h_deriv(vector& 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::h_rebin(vector& 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);} else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,false,true);} #endif // 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);} else if( oper[0]=='/') {h3->Clone(*h1); h3->DivElt(*h2,false,true);} #endif // 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 */ int PAWExecutor::decodepawstring(string tokens,string& nameobj ,string& xexp,string& yexp,string& zexp) // Decodage general de "nameobj.xexp" // "nameobj.yexp%xexp" // "nameobj.zexp%yexp%xexp" // Return: nombre de variables trouvees, -1 si probleme { nameobj = ""; xexp= ""; yexp= ""; zexp= ""; int lt = (int) tokens.length(); if(lt<=0) return -1; // decodage de la chaine de type PAW. char *str = new char[lt+2]; strcpy(str,tokens.c_str()); strip(str,'B',' '); lt = strlen(str); //cout<<"chaine1["<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 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 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 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 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 i=i1;i<=i2;i++) for(int 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 i=0;iNBins();i++) { double x = (double) (*h)(i); double 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 i=0;iNBinX();i++) for(int j=0;jNBinY();j++) { double x = (double) (*h2)(i,j); double e = f(x); h2->Error2(i,j) = e*e; } } else { cout<<"PAWExecutor::h_err Error: type mismatch for Histo/Histo2D\n" <