This page holds a few example code-snippets for use in myana analysis. Compare with Pyana user examples to see how the same things can be done using the pyana analysis framework.
Display images from Princeton camera
Some variables are needed both in beginjob()
and event()
member functions. The myana solution is to declare them as global variables right after the necessary include-files.
#include <TH2I.h> TH2I* h_image; static int widthSxrRCI0; static int heightSxrRCI0; static int orgXSxrRCI0; static int orgYSxrRCI0; static int binXSxrRCI0; static int binYSxrRCI0;
In beginjob()
, get configuration object and book histogram
// Processing Princeton Config Data int fail = getPrincetonConfig( DetInfo::SxrEndstation, 0, widthSxrRCI0, heightSxrRCI0, orgXSxrRCI0, orgYSxrRCI0, binXSxrRCI0, binYSxrRCI0 ); if ( fail == 0 ) {// success printf( "Get Princeton config for SxrRCI0: width %d height %d org (%d,%d) binX %d binY %d\n", widthSxrRCI0, heightSxrRCI0, orgXSxrRCI0, orgYSxrRCI0, binXSxrRCI0, binYSxrRCI0 ); } // Book a histogram h_image = new TH2I("h_image","Princeton images (summed)", // name and title widthSxrRCI0,orgXSxrRCI0,widthSxrRCI0, // nBinsX, xmin, xmax heightSxrRCI0,orgYSxrRCI0,heightSxrRCI0); // nBinsY, ymin, ymax
In event()
, fetch data from Princeton camera for the current event. Add to histogram (which will hold the sum of all events). Note, we here use a root TH2 histogram. It's rather slow for images, so you may want to use some other display service...
unsigned short* pixels; int fail = getPrincetonValue( DetInfo::SxrEndstation, 0, pixels); if ( fail == 0 ) { // Fill histogram from 2D array for(int irow=0; irow<heightSxrRCI0; irow++){ for(int icol=0; icol<widthSxrRCI0; icol++){ h_image->Fill(icol,irow,*pixels); pixels++; // go to the next pixel } } }
Once all events have been processed, you can display and/or store the histogram in myana's endjob()
function.
h_image->Draw(); h_image->SaveAs("myana_princ_image.root"); // 1D projections h_image->ProjectionX()->SaveAs("myana_princ_imageX.root"); h_image->ProjectionY()->SaveAs("myana_princ_imageY.root");
At this point, you can open the histogram in root sessions and draw them there and interactively adjust display properties as needed.
> root root > TFile f("myana_princ_image.root") root > f.ls() root > gStyle->SetPalette(1) root > h_image->Draw()
Here's the plot: