| | 114 | == ROOT == |
| | 115 | |
| | 116 | Root is sometimes a bit tricky... here are a few coding rules or hints. |
| | 117 | |
| | 118 | 0. Try to avoid using global pointers (gRandom is an exception) |
| | 119 | 0. *same* is TGraphs is done by omitting the A (A means *with axis*) |
| | 120 | 0. Try to avoid pointers, use objects, except if you add them to a root list. |
| | 121 | 0. Histograms are usually automatically written to open files (it is switched of in the MARS code, but be carefull). Avoid that by removing the histogram from everything after creation: {{{hist.SetDirectory(0)}}} |
| | 122 | 0. Make sure that all objects are properly deleted. E.g. when drawing something with DrawClone like {{{g=graph.DrawClone("AP")}}}, make sure you set the kCanDelete bit with {{{g->SetBit(kCanDelete)}}}. When you draw something with DrawCopy this is done automatically. |
| | 123 | 0. Sometimes graphs are not where they ought to be (usually when you use DrawClone). In this case, add a {{{gROOT->SetSelectedPad(0)}}} before you cd() into the pad you want the graph to appear. Alternatively you can create the Clone() first and add the clone to the pad with {{{gPad->GetListOfPrimitives(clone, draw_options)}}} |
| | 124 | |
| | 125 | |
| | 126 | === FACT camera display === |
| | 127 | |
| | 128 | {{{#!C++ |
| | 129 | |
| | 130 | // Create a FACT camera with |
| | 131 | MGeomCamFACT geom; |
| | 132 | |
| | 133 | // Create a display with |
| | 134 | MHCamera h(geom); |
| | 135 | |
| | 136 | // Set value of pixel 0 with |
| | 137 | h.SetBinContent(1); // (note the +1!) |
| | 138 | |
| | 139 | // Enable the display of the pixel with |
| | 140 | h.SetUsed(0) |
| | 141 | |
| | 142 | // Or enable the the display of all pixels with |
| | 143 | h.SetAllUsed() |
| | 144 | |
| | 145 | // Draw display |
| | 146 | h.DrawCopy(); |
| | 147 | }}} |
| | 148 | |
| | 149 | |
| | 150 | === Reading a display === |
| | 151 | |
| | 152 | {{{#!C++ |
| | 153 | TFile file("filename.root"); |
| | 154 | if (file.IsZombie()) |
| | 155 | return; |
| | 156 | |
| | 157 | MStatusArray arr; |
| | 158 | if (arr.Read()<=0) |
| | 159 | return; |
| | 160 | |
| | 161 | TWhatever *ptr = arr.FindObjectInCanvas("CanvasName", "TWhatever", "ObjectName"); |
| | 162 | if (!ptr) |
| | 163 | return; |
| | 164 | }}} |