10 #include "TApplication.h" 
   14 #include "TAttMarker.h" 
   20 #include "TGraphErrors.h" 
   22 #include "TGraph2DErrors.h" 
   51   inline bool setLogX(
TObject* 
object)
 
   55     T* p = 
dynamic_cast<T*
>(object);
 
   74   inline bool setLogY(
TObject* 
object)
 
   78     T* p = 
dynamic_cast<T*
>(object);
 
   92   const char* 
const JName_t  = 
"?";     
 
   93   const char* 
const JTitle_t = 
"%";     
 
  103 int main(
int argc, 
char **argv)
 
  108   typedef JRange<double>  JRange_t;
 
  135     JParser<> zap(
"General purpose plot program for 2D ROOT objects.");
 
  137     zap[
'f'] = 
make_field(inputFile,  
"<input file>:<object name>");
 
  139     zap[
'w'] = 
make_field(canvas,     
"size of canvas <nx>x<ny> [pixels]")  = JCanvas(500, 500);
 
  141     zap[
'x'] = 
make_field(
X,          
"x-abscissa range")                   = JRange_t();
 
  142     zap[
'y'] = 
make_field(
Y,          
"y-abscissa range")                   = JRange_t();
 
  143     zap[
'z'] = 
make_field(
Z,          
"ordinate range")                     = JRange_t();
 
  144     zap[
'X'] = 
make_field(logx,       
"logarithmic x-axis (-XX log10 axis)");
 
  145     zap[
'Y'] = 
make_field(logy,       
"logarithmic y-axis (-YY log10 axis)");
 
  146     zap[
'Z'] = 
make_field(logz,       
"logarithmic z-axis");
 
  147     zap[
'P'] = 
make_field(project,    
"projection")                         = 
"", 
"xy", 
"yx", 
"xz", 
"zx", 
"yz", 
"zy";
 
  148     zap[
'>'] = 
make_field(xLabel,     
"x-axis label")                       = 
"";
 
  149     zap[
'<'] = 
make_field(yLabel,     
"y-axis label")                       = 
"";
 
  150     zap[
'^'] = 
make_field(zLabel,     
"z-axis label")                       = 
"";
 
  151     zap[
'S'] = 
make_field(markerSize, 
"marker size")                        = 1.0;
 
  152     zap[
'O'] = 
make_field(option,     
"plotting option")                    = 
"";
 
  154     zap[
'B'] = 
make_field(batch,      
"batch processing");
 
  155     zap[
'T'] = 
make_field(title,      
"graphics title (" 
  156                           << 
"\"" << JName_t  << 
"\" -> ROOT name; " 
  157                           << 
"\"" << JTitle_t << 
"\" -> ROOT title)")       = 
"KM3NeT preliminary";
 
  159     zap[
'p'] = 
make_field(palette,    
"palette")                            = -1;
 
  164   catch(
const exception &error) {
 
  165     FATAL(error.what() << endl);
 
  169   gROOT->SetBatch(batch);
 
  171   TApplication* tp = 
new TApplication(
"user", NULL, NULL);
 
  172   TCanvas*      cv = 
new TCanvas(
"c1", 
"c1", canvas.x, canvas.y);
 
  174   JSinglePointer<TStyle> gStyle(
new JStyle(
"gplot", cv->GetWw(), cv->GetWh()));
 
  177     gStyle->SetPalette(palette);
 
  180   gROOT->SetStyle(
"gplot");
 
  184   cv->SetFillStyle(4000);
 
  185   cv->SetFillColor(kWhite);
 
  191   Double_t 
xmin = numeric_limits<double>::max();
 
  192   Double_t 
xmax = numeric_limits<double>::lowest();
 
  193   Double_t ymin = numeric_limits<double>::max();
 
  194   Double_t ymax = numeric_limits<double>::lowest();
 
  195   Double_t zmin = numeric_limits<double>::max();
 
  196   Double_t zmax = numeric_limits<double>::lowest();
 
  204     DEBUG(
"Input: " << *input << endl);
 
  209       ERROR(
"File: " << input->getFullFilename() << 
" not opened." << endl);
 
  213     const TRegexp regexp(input->getObjectName());
 
  215     TIter iter(dir->GetListOfKeys());
 
  217     for (TKey* key; (key = (TKey*) iter.Next()) != NULL; ) {
 
  219       const TString tag(key->GetName());
 
  221       DEBUG(
"Key: " << tag << 
" match = " << tag.Contains(regexp) << endl);
 
  225       if (tag.Contains(regexp) && 
isTObject(key)) {
 
  227         if        (title == JName_t) {
 
  228           title = key->GetName();
 
  229         } 
else if (title == JTitle_t) {
 
  230           title = key->GetTitle();
 
  233         JRootObject object(key->ReadObj());
 
  237           TH3& h3 = 
dynamic_cast<TH3&
>(*object);
 
  239           object = h3.Project3D(project.c_str());
 
  245           TH2& h2 = 
dynamic_cast<TH2&
>(*object);
 
  247           h2.SetStats(stats != -1);
 
  249           xmin = min(
xmin, h2.GetXaxis()->GetXmin());
 
  250           xmax = max(xmax, h2.GetXaxis()->GetXmax());
 
  251           ymin = min(ymin, h2.GetYaxis()->GetXmin());
 
  252           ymax = max(ymax, h2.GetYaxis()->GetXmax());
 
  253           zmin = min(zmin, logz ? h2.GetMinimum(0.0) : h2.GetMinimum());
 
  254           zmax = max(zmax, h2.GetMaximum());
 
  260           TGraph& 
g1 = 
dynamic_cast<TGraph&
>(*object);
 
  262           for (Int_t i = 0; i != g1.GetN(); ++i) {
 
  272             if (dynamic_cast<TGraph*>(i->get()) != NULL) {
 
  283           TGraph2D& g2 = 
dynamic_cast<TGraph2D&
>(*object);
 
  285           for (Int_t i = 0; i != g2.GetN(); ++i) {
 
  286             if (!logz || g2.GetZ()[i] > 0.0) {
 
  288               xmax = max(xmax, g2.GetX()[i]);
 
  289               ymin = min(ymin, g2.GetY()[i]);
 
  290               ymax = max(ymax, g2.GetY()[i]);
 
  291               zmin = min(zmin, g2.GetZ()[i]);
 
  292               zmax = max(zmax, g2.GetZ()[i]);
 
  296           if (
Z != JRange_t()) {
 
  297             g2.SetMinimum(
Z.getLowerLimit());
 
  298             g2.SetMaximum(
Z.getUpperLimit());
 
  305           TF2& f2 = 
dynamic_cast<TF2&
>(*object);
 
  307           f2.SetLineColor(kRed);
 
  308           f2.SetTitle((title +  
";" + xLabel + 
";" + yLabel + 
";" + zLabel).c_str());
 
  315           f2.GetRange(__xmin, __ymin, __xmax, __ymax);
 
  319           ymin = min(ymin, __ymin);
 
  320           ymax = max(ymax, __ymax);
 
  321           zmin = min(zmin, f2.GetMinimum());
 
  322           zmax = max(zmax, f2.GetMaximum());
 
  328         for (TString buffer[] = { 
object.getLabel(), input->getFilename().c_str(), 
"" }, *i = buffer; *i != 
""; ++i) {
 
  330           *i = (*i)(TRegexp(
"\\[.*\\]"));
 
  332           if ((*i).Length() > 2) {
 
  333             object.setLabel((*i)(1, (*i).Length() - 2));
 
  337         if (dynamic_cast<TH2*>     (
object.
get())  !=  NULL ||
 
  338             dynamic_cast<TGraph*>  (
object.
get())  !=  NULL ||
 
  339             dynamic_cast<TGraph2D*>(
object.
get())  !=  NULL ||
 
  340             dynamic_cast<TEllipse*>(
object.
get())  !=  NULL ||
 
  341             dynamic_cast<TLine*>   (
object.
get())  !=  NULL ||
 
  342             dynamic_cast<TF2*>     (
object.
get())  !=  NULL) {
 
  344           DEBUG(
"Add object: " << tag << 
" with label <" << 
object.
getLabel() << 
">" << endl);
 
  347             master = 
dynamic_cast<TH2*
>(
object.get());
 
  350           listOfObjects.push_back(
object);
 
  353           ERROR(
"For other objects than 2D histograms, use JPlot1D" << endl);
 
  359   if (listOfObjects.empty()) {
 
  360     ERROR(
"Nothing to draw." << endl);
 
  367   if (option.find(
"COLZ") != string::npos ||
 
  368       option.find(
"colz") != string::npos) {
 
  369     gPad->SetRightMargin(0.20);
 
  372   if (
X != JRange_t()) {    
 
  373     xmin = 
X.getLowerLimit();
 
  374     xmax = 
X.getUpperLimit();
 
  377   if (
Y != JRange_t()) {    
 
  378     ymin = 
Y.getLowerLimit();
 
  379     ymax = 
Y.getUpperLimit();
 
  382   if (
Z != JRange_t()) {
 
  383     zmin = 
Z.getLowerLimit();
 
  384     zmax = 
Z.getUpperLimit();
 
  385   } 
else if (zmax > zmin) {
 
  389   if (!listOfObjects.empty()) {
 
  393       master = 
new TH2D(MASTER.c_str(), NULL, 
 
  403     TText* p = 
new TText(0.5, 0.5, 
"No data");
 
  411     if (logx) { gPad->SetLogx(); }
 
  412     if (logy) { gPad->SetLogy(); }
 
  413     if (logz) { gPad->SetLogz(); }
 
  416     master->GetYaxis()->SetRangeUser(ymin, ymax);
 
  421     master->SetTitle(title.c_str());
 
  426     if (xLabel != 
"") { 
master->GetXaxis()->SetTitle(xLabel.c_str()); 
master->GetXaxis()->CenterTitle(
true); }
 
  427     if (yLabel != 
"") { 
master->GetYaxis()->SetTitle(yLabel.c_str()); 
master->GetYaxis()->CenterTitle(
true); }
 
  428     if (zLabel != 
"") { 
master->GetZaxis()->SetTitle(zLabel.c_str()); 
master->GetZaxis()->CenterTitle(
true); }
 
  432     master->GetYaxis()->SetMoreLogLabels((logy == 1 && 
log10(ymax/ymin) < 2) ||
 
  433                                          (logy >  1 &&       ymax-ymin  < 2));
 
  436       master->SetNdivisions(i->second, i->first.c_str());
 
  439     DEBUG(
"Draw " << 
master->GetName() << 
' ' << option << endl);
 
  441     master->Draw(option.c_str());
 
  444   if (logx > 1 || logy > 1) {
 
  446       if (dynamic_cast<TH2*>(i->get()) != 
master) {
 
  448           if      (setLogX<TH2>           (i->get())) {}
 
  449           else if (setLogX<TF2>           (i->get())) {}
 
  450           else if (setLogX<TGraph2DErrors>(i->get())) {}
 
  451           else if (setLogX<TGraph2D>      (i->get())) {}
 
  452           else if (setLogX<TGraphErrors>  (i->get())) {}
 
  453           else if (setLogX<TGraph>        (i->get())) {}
 
  454           else if (setLogX<TLine>         (i->get())) {}
 
  455           else if (setLogX<TEllipse>      (i->get())) {}
 
  458           if      (setLogY<TH2>           (i->get())) {}
 
  459           else if (setLogY<TF2>           (i->get())) {}
 
  460           else if (setLogY<TGraph2DErrors>(i->get())) {}
 
  461           else if (setLogY<TGraph2D>      (i->get())) {}
 
  462           else if (setLogY<TGraphErrors>  (i->get())) {}
 
  463           else if (setLogY<TGraph>        (i->get())) {}
 
  464           else if (setLogY<TLine>         (i->get())) {}
 
  465           else if (setLogY<TEllipse>      (i->get())) {}
 
  471   if (grid.count(
'x') || grid.count(
'X')) { gPad->SetGridx(); }
 
  472   if (grid.count(
'y') || grid.count(
'Y')) { gPad->SetGridy(); }
 
  475     gStyle->SetOptStat(stats);
 
  477     gStyle->SetOptFit(kFALSE);
 
  481     DEBUG(
"Draw " << (*i)->GetName() << 
' ' << (*i)->GetTitle() << endl);
 
  483     string buffer(option);
 
  489       TH2& h2 = 
dynamic_cast<TH2&
>(*(*i));
 
  498       TGraph& 
g1 = 
dynamic_cast<TGraph&
>(*(*i));
 
  506       TGraph2D& g2 = 
dynamic_cast<TGraph2D&
>(*(*i));
 
  515       TF2& f2 = 
dynamic_cast<TF2&
>(*(*i));
 
  526     (*i)->Draw(buffer.c_str());
 
  541   return (
master != NULL ? 0 : 1);
 
Utility class to parse command line options. 
 
then echo Test string reversed by master(hit< return > to continue)." $DIR/JProcess -c "$DIR/JEcho" -rC fi if (( 1 ))
 
int main(int argc, char *argv[])
 
std::string getLabel(const JLocation &location)
Get module label for monitoring and other applications. 
 
Empty structure for specification of parser element that is initialised (i.e. does not require input)...
 
then fatal Wrong number of arguments fi set_variable STRING $argv[1] set_variable DETECTORXY_TXT $WORKDIR $DETECTORXY_TXT tail read X Y CHI2 RMS printf optimum n $X $Y $CHI2 $RMS awk v Y
 
void setLogarithmicX(TList *list)
Make x-axis of objects in list logarithmic (e.g. after using log10()). 
 
T & getInstance(const T &object)
Get static instance from temporary object. 
 
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object 
 
set_variable E_E log10(E_{fit}/E_{#mu})"
 
do set_variable OUTPUT_DIRECTORY $WORKDIR T
 
General purpose messaging. 
 
void setLogarithmicY(TList *list)
Make y-axis of objects in list logarithmic (e.g. after using log10()). 
 
void setRange(double &xmin, double &xmax, const bool logx)
Set axis range. 
 
Auxiliary class to define a range between two values. 
 
Utility class to parse command line options. 
 
Auxiliary class to handle multiple boolean-like I/O. 
 
bool isTObject(const TKey *key)
Check if given key corresponds to a TObject. 
 
no fit printf nominal n $STRING awk v X
 
TDirectory * getDirectory(const JRootObjectID &id)
Get TDirectory pointer. 
 
do set_variable MODULE getModule a $WORKDIR detector_a datx L $STRING JEditDetector a $WORKDIR detector_a datx M $MODULE setz o $WORKDIR detector_a datx JEditDetector a $WORKDIR detector_b datx M $MODULE setz o $WORKDIR detector_b datx done echo Output stored at $WORKDIR detector_a datx and $WORKDIR tripod_a txt JDrawDetector2D a $WORKDIR detector_a datx a $WORKDIR detector_b datx L BL o detector $FORMAT $BATCH JDrawDetector2D T $WORKDIR tripod_a txt T $WORKDIR tripod_b txt L BL o tripod $FORMAT $BATCH JCompareDetector a $WORKDIR detector_a datx b $WORKDIR detector_b datx o $WORKDIR abc root &dev null for KEY in X Y Z
 
#define DEBUG(A)
Message macros. 
 
Double_t g1(const Double_t x)
Function.