00001 {
00002 /*** This macro gives an example of how to navigate the ReactorTree data
00003 * structure and make root plots. What it does is create charge spectra
00004 * for neutrons and positrons with radii > 200 cm, and superimposes them on
00005 * the same plot, and then creates an eps file which can be looked at with
00006 * your favorite postscript viewer.
00007 *
00008 * Remember you need to load the shared libraray libRMCEvent.so in order to use
00009 * the RMCEvent classes. To do this, make sure there is a libRMCEvent.so in your
00010 * root directory, and do .L libRMCEvent.so before you execute this macro
00011 * (with .x RMCMacro.cpp). The shared library is created by the ReactorFsim Makefile
00012 * and placed in the ./src directory. You only need to load the shared library
00013 * once per root session.
00014 ***/
00015
00016 //
00017 // First, let's re-set some graphical options, to overcome root's
00018 // disasterous defaults.
00019 //
00020 gROOT->SetStyle("Plain");
00021
00022 gStyle->SetOptStat(0);
00023 gStyle->SetOptFit(0);
00024 gStyle->GetAttDate()->SetTextColor(1);
00025 gStyle->SetOptTitle(0); // no title; comment out if you want a title
00026 gStyle->SetLabelFont(132,"XYZ");
00027 gStyle->SetTextFont(132);
00028 gStyle->SetTitleFont(132,"XYZ");
00029
00030 gROOT->ForceStyle();
00031
00032 // Now we read in the root file using the TFile class, create the root tree,
00033 // and set the first branch to be an RMCEvent object. RMCEvent holds an
00034 // array of secondary objects (for example, neutron and positron) and each
00035 // of these secondary objects will hold an array of PMT hits.
00036
00037 TFile hfile("Events.root");
00038 TTree *tree = (TTree*)hfile.Get("RTree");
00039 RMCEvent *event = new RMCEvent();
00040 tree->SetBranchAddress("RMCEvent",&event);
00041
00042 // Now create histograms for the neutrons and positrons
00043
00044 TH1F *pmtqn = new TH1F("pmtqn"," ",50,-0.1,4.0);
00045 pmtqn->SetLineColor(kBlue);
00046 pmtqn->SetLineWidth(3);
00047 pmtqn->SetLineStyle(1);
00048 pmtqn->SetXTitle("Charge (photoelectrons)");
00049 pmtqn->SetYTitle("Hits/0.08 pe");
00050 pmtqn->SetTitle("Neutron and Positron Charge Spectra for R > 200 cm");
00051
00052 TH1F *pmtqpos = new TH1F("pmtqpos"," ",50,-0.1,4.0);
00053 pmtqpos->SetLineColor(kRed);
00054 pmtqpos->SetLineWidth(3);
00055 pmtqpos->SetLineStyle(2);
00056 pmtqpos->SetXTitle("Charge (photoelectrons)");
00057 pmtqpos->SetYTitle("Hits/0.08 pe");
00058 pmtqpos->SetTitle("Neutron and Positron Charge Spectra for R > 200 cm");
00059
00060 // And a legend to tell us which is which
00061
00062 TLegend *leg = new TLegend(0.60,0.70,0.88,0.88);
00063 leg->AddEntry(pmtqpos,"Positrons","L");
00064 leg->AddEntry(pmtqn,"Neutrons","L");
00065
00066 Int_t nentries = (Int_t)tree->GetEntries(); // this gets the number of events
00067 // in the tree
00068
00069 // Now let's define some useful quantities we want to get out of the tree
00070 // structure, like the event number, the number of secondaries, the event
00071 // type, the number of hits, energy, and generated position.
00072 Int_t num;
00073 Int_t numsecs;
00074 Int_t type,hits;
00075 Double_t energy,rgen;
00076 Double_t* vertex;
00077
00078 // Now loop over all the events held in the tree
00079 for (Int_t i=0; i < nentries; i++){
00080 tree->GetEntry(i); //This gets the next event
00081 num = event->GetEventNum();
00082 numsecs = event->GetNumSecondaries();
00083 vertex = event->GetInteractionVertex();
00084 rgen = sqrt(vertex[0]*vertex[0]+vertex[1]*vertex[1]+
00085 vertex[0]*vertex[0]);
00086
00087 // Now let's create a NULL pointer of the RMCSecondary class, to use to
00088 // access information about the secondaries
00089 RMCSecondary *secondary = NULL;
00090 for (Int_t isec=0; isec<numsecs; isec++){
00091
00092 // Now we actually get the secondary information, which is the isec element
00093 // in the array held in the event
00094 secondary = (RMCSecondary *) event.fSecondaries->At(isec);
00095 type = secondary->GetSecondaryType();
00096 energy = secondary->GetSecondaryKE();
00097 hits = secondary->GetNumPMTs();
00098 int npe;
00099 double Time;
00100 Float_t Q;
00101
00102 // Now that we know how many PMT hits there are, let's loop through them and
00103 // put the measured charge in the relevant histograms
00104 for (Int_t j=0; j<hits; j++){
00105 RMCPMT *pmt = NULL;
00106 pmt = (RMCPMT *) secondary.fPMTs->At(j);
00107 Q = (Float_t) pmt->GetPMTQ();
00108 npe = pmt->GetPMTnpe();
00109 if (npe > 0){ //Let's require the tube to be hit by > 0 photons
00110 if (rgen > 200){ //And the event to have been created at r>200 cm
00111 if (isec == 0){
00112 pmtqpos->Fill(Q); //fill positron histogram
00113 }
00114 else
00115 pmtqn->Fill(Q); //fill neutron histogram
00116 }
00117 }
00118 Time = pmt->GetPMTtime(); //in case we want to look at time
00119 delete pmt;
00120 }
00121 delete secondary;
00122 }
00123 // tree->Show(); //uncomment this if you'd like to see summary info on tree
00124 }
00125 pmtqn->DrawNormalized();
00126 pmtqpos->DrawNormalized("same"); //we'll draw normalized histos, for overlaying
00127
00128
00129 leg->SetTextFont(132); // use Times-Roman font for legend
00130 leg->Draw("same"); // and draw it
00131
00132 c1->Print("Qnp.eps"); //make a postscript file
00133
00134 delete event;
00135 // hfile.Close();
00136 //
00137 return 0;
00138 }
1.2.14 written by Dimitri van Heesch,
© 1997-2002