ProofEvent.C

Go to the documentation of this file.
00001 #define ProofEvent_cxx
00002 
00003 //////////////////////////////////////////////////////////
00004 //
00005 // Example of TSelector implementation to do generic
00006 // processing with the test 'Event' structure.
00007 // See tutorials/proof/runProof.C, option "event", for an
00008 // example of how to run this selector.
00009 //
00010 //////////////////////////////////////////////////////////
00011 
00012 #include "ProofEvent.h"
00013 #include "Event.h"
00014 
00015 #include <TCanvas.h>
00016 #include <TH1F.h>
00017 #include <TRandom3.h>
00018 
00019 //_____________________________________________________________________________
00020 ProofEvent::ProofEvent()
00021 {
00022    // Constructor
00023 
00024    fEvent = 0;
00025    fNtrack = -1; 
00026    fHisto = 0;
00027    fRandom = 0;
00028 }
00029 
00030 //_____________________________________________________________________________
00031 ProofEvent::~ProofEvent()
00032 {
00033    // Destructor
00034 
00035    SafeDelete(fRandom);
00036 }
00037 
00038 //_____________________________________________________________________________
00039 void ProofEvent::Begin(TTree * /*tree*/)
00040 {
00041    // The Begin() function is called at the start of the query.
00042    // When running with PROOF Begin() is only called on the client.
00043    // The tree argument is deprecated (on PROOF 0 is passed).
00044 
00045    TString option = GetOption();
00046    Info("Begin", "starting a simple exercise with process option: %s", option.Data());
00047 }
00048 
00049 //_____________________________________________________________________________
00050 void ProofEvent::SlaveBegin(TTree * /*tree*/)
00051 {
00052    // The SlaveBegin() function is called after the Begin() function.
00053    // When running with PROOF SlaveBegin() is called on each slave server.
00054    // The tree argument is deprecated (on PROOF 0 is passed).
00055 
00056    TString option = GetOption();
00057    Info("SalveBegin", "starting on a slave with process option: %s", option.Data());
00058 
00059    // Create event
00060    fEvent = new Event();
00061 
00062    // Create the histogram
00063    fHisto = new TH1F("histo", "tracks multiplicity", 20, 0, 100);
00064    fHisto->GetYaxis()->SetTitle("number of events");
00065    fHisto->GetXaxis()->SetTitle("number of tracks");
00066 
00067    //adding histo to selector output list
00068    fOutput->Add(fHisto);
00069 
00070    // Set random seed
00071    fRandom = new TRandom3(0);
00072 }
00073 
00074 //_____________________________________________________________________________
00075 Bool_t ProofEvent::Process(Long64_t )
00076 {
00077 
00078   // Start main loop over all events
00079   // get a random parameter for connstructing event
00080 
00081    int i= (int)(100 * (fRandom->Rndm()));
00082    fEvent->Build(i,(1+i), 2);
00083    fNtrack= (fEvent->GetNtrack());
00084    if ((fNtrack >= 0 )&& (fNtrack <= 100 ))
00085       fHisto->Fill(fNtrack, 1);
00086 
00087    return kTRUE;
00088 }
00089 
00090 //_____________________________________________________________________________
00091 void ProofEvent::SlaveTerminate()
00092 {
00093    //nothing to be done
00094 
00095 }
00096 
00097 //_____________________________________________________________________________
00098 void ProofEvent::Terminate()
00099 {
00100    // The Terminate() function is the last function to be called during
00101    // a query. It always runs on the client, it can be used to present
00102    // the results graphically or save the results to file.
00103 
00104    TCanvas *c1 = new TCanvas("c1","Proof ProofEvent canvas",200,10,700,700);
00105    fHisto = dynamic_cast<TH1F *>(fOutput->FindObject(Form("histo")));
00106    if (fHisto) {
00107       fHisto->Draw("h");
00108 
00109       // Final update
00110       c1->cd();
00111       c1->Update();
00112    } else {
00113       Warning("Terminate", "histogram not found");
00114    }
00115 }

Generated on Tue Jul 5 15:44:52 2011 for ROOT_528-00b_version by  doxygen 1.5.1