#define SelSplitData_cxx // The class definition in SelSplitData.h has been generated automatically // by the ROOT utility TTree::MakeSelector(). This class is derived // from the ROOT class TSelector. For more information on the TSelector // framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual. // The following methods are defined in this file: // Begin(): called every time a loop on the tree starts, // a convenient place to create your histograms. // SlaveBegin(): called after Begin(), when on PROOF called only on the // slave servers. // Process(): called for each event, in this function you decide what // to read and fill your histograms. // SlaveTerminate: called at the end of the loop on the tree, when on PROOF // called only on the slave servers. // Terminate(): called at the end of the loop on the tree, // a convenient place to draw/fit your histograms. // // To use this file, try the following session on your Tree T: // // root> T->Process("SelSplitData.C") // root> T->Process("SelSplitData.C","some options") // root> T->Process("SelSplitData.C+") // #include "SelSplitData.h" #include #include void SelSplitData::Begin(TTree * /*tree*/) { // The Begin() function is called at the start of the query. // When running with PROOF Begin() is only called on the client. // The tree argument is deprecated (on PROOF 0 is passed). TString option = GetOption(); TParameter *splitFrac = dynamic_cast *>(fInput -> FindObject("RUN_SplitFrac")) ; if(splitFrac) { fSplitFrac = splitFrac -> GetVal() ; Info("Begin","Splitting dataset into 2 sets with fractions %f - %f\n",fSplitFrac,1.0 - fSplitFrac) ; } else { Error("Begin","No split fraction provided\n") ; Abort("") ; } TNamed *nmfile = dynamic_cast (fInput -> FindObject("RUN_TempFileName")) ; if(nmfile) fOutFileName = nmfile -> GetTitle() ; else { Error("Begin","Session temporary file not known\n") ; Abort("") ; } TNamed *nmsplit = dynamic_cast (fInput -> FindObject("RUN_SplitName")) ; if(nmsplit) { fSplitName1 = nmsplit -> GetTitle() ; fSplitName1 += "_sub1" ; fSplitName2 = nmsplit -> GetTitle() ; fSplitName2 += "_sub2" ; } else { Error("Begin","Split name not found \n") ; Abort("") ; } TNamed *titlesplit = dynamic_cast (fInput -> FindObject("RUN_SplitTitle")) ; if(titlesplit) { fSplitDataSets = titlesplit -> GetTitle() ; } else { Error("Begin","Split name not found \n") ; Abort("") ; } fSplitDataSets.ReplaceAll(" ","") ; elist_sub1 = new TEntryList(fSplitName1.Data(), fSplitDataSets.Data()); elist_sub2 = new TEntryList(fSplitName2.Data(), fSplitDataSets.Data()); TNamed *nmaddcuts = dynamic_cast (fInput -> FindObject("RUN_Cuts")) ; if(nmaddcuts) { elist_sub1_cuts = new TEntryList((fSplitName1 + "_with_cuts").Data(), fSplitDataSets.Data()); elist_sub2_cuts = new TEntryList((fSplitName2 + "_with_cuts").Data(), fSplitDataSets.Data()); kAdditionalCuts = true ; fSelection = nmaddcuts -> GetTitle() ; } else { elist_sub1_cuts = 0 ; elist_sub2_cuts = 0 ; } // // Add to the input list for processing in PROOF, if needed if (fInput) { //// fInput->Add(new TNamed("fillList","")); // // We send a clone to avoid double deletes when importing the result fInput->Add(elist_sub1); fInput->Add(elist_sub2); if(elist_sub1_cuts) fInput -> Add(elist_sub1_cuts) ; if(elist_sub2_cuts) fInput -> Add(elist_sub2_cuts) ; // This is needed to avoid warnings from output-to-members mapping elist_sub1 = 0; elist_sub2 = 0; elist_sub1_cuts = 0 ; elist_sub2_cuts = 0 ; } // Info("Begin", "creating entry-lists"); } void SelSplitData::SlaveBegin(TTree * /*tree*/) { // The SlaveBegin() function is called after the Begin() function. // When running with PROOF SlaveBegin() is called on each slave server. // The tree argument is deprecated (on PROOF 0 is passed). TString option = GetOption(); TParameter *splitFrac = dynamic_cast *>(fInput -> FindObject("RUN_SplitFrac")) ; if(splitFrac) { fSplitFrac = splitFrac -> GetVal() ; Info("Begin","Splitting dataset into 2 sets with fractions %f - %f\n",fSplitFrac,1.0 - fSplitFrac) ; } else { Error("Begin","No split fraction provided\n") ; Abort("") ; } TNamed *nmsplit = dynamic_cast (fInput -> FindObject("RUN_SplitName")) ; if(nmsplit) { fSplitName1 = nmsplit -> GetTitle() ; fSplitName1 += "_sub1" ; fSplitName2 = nmsplit -> GetTitle() ; fSplitName2 += "_sub2" ; } else { Error("Begin","Split name not found \n") ; Abort("") ; } TNamed *titlesplit = dynamic_cast (fInput -> FindObject("RUN_SplitTitle")) ; if(titlesplit) { fSplitDataSets = titlesplit -> GetTitle() ; } else { Error("Begin","Split name not found \n") ; Abort("") ; } TNamed *nmaddcuts = dynamic_cast (fInput -> FindObject("RUN_Cuts")) ; if(nmaddcuts) { elist_sub1_cuts = new TEntryList((fSplitName1 + "_with_cuts").Data(), fSplitDataSets.Data()); elist_sub2_cuts = new TEntryList((fSplitName2 + "_with_cuts").Data(), fSplitDataSets.Data()); kAdditionalCuts = true ; fSelection = nmaddcuts -> GetTitle() ; } fSplitDataSets.ReplaceAll(" ","") ; elist_sub1 = dynamic_cast (fInput -> FindObject(fSplitName1.Data()) ) ; if(elist_sub1) { elist_sub1 = (TEntryList*)elist_sub1 -> Clone() ; fOutput -> Add(elist_sub1) ; } elist_sub2 = dynamic_cast (fInput -> FindObject(fSplitName2.Data()) ) ; if(elist_sub2) { elist_sub2 = (TEntryList*)elist_sub2 -> Clone() ; fOutput -> Add(elist_sub2) ; } elist_sub1_cuts = dynamic_cast (fInput -> FindObject((fSplitName1 + "_with_cuts").Data()) ) ; if(elist_sub1_cuts) { elist_sub1_cuts = (TEntryList*)elist_sub1_cuts -> Clone() ; fOutput -> Add(elist_sub1_cuts) ; } elist_sub2_cuts = dynamic_cast (fInput -> FindObject((fSplitName2 + "_with_cuts").Data()) ) ; if(elist_sub2_cuts) { elist_sub2_cuts = (TEntryList*)elist_sub2_cuts -> Clone() ; fOutput -> Add(elist_sub2_cuts) ; } rndmgen.SetSeed(0) ; Info("SlaveBegin", "creating an entry-list"); } Bool_t SelSplitData::Process(Long64_t entry) { // The Process() function is called for each entry in the tree (or possibly // keyed object in the case of PROOF) to be processed. The entry argument // specifies which entry in the currently loaded tree is to be processed. // It can be passed to either SelSplitData::GetEntry() or TBranch::GetEntry() // to read either all or the required parts of the data. When processing // keyed objects with PROOF, the object is already loaded and is available // via the fObject pointer. // // This function should contain the "body" of the analysis. It can contain // simple or elaborate selection criteria, run algorithms on the data // of the event and typically fill histograms. // // The processing can be stopped by calling Abort(). // // Use fStatus to set the return value of TTree::Process(). // // The return value is currently not used. Int_t cutresult = (Int_t)fCutsFormula -> EvalInstance() ; if(rndmgen.Uniform(0.0,1.0) < fSplitFrac) { if(elist_sub1) elist_sub1 -> Enter(entry) ; if(cutresult) { elist_sub1_cuts -> Enter(entry) ; Info("Process","Went to first entry list\n"); } } else { if(elist_sub2) elist_sub2 -> Enter(entry) ; if(cutresult) { elist_sub2_cuts -> Enter(entry) ; Info("Process","Went to second entry list\n"); } } return kTRUE; } void SelSplitData::SlaveTerminate() { // The SlaveTerminate() function is called after all entries or objects // have been processed. When running with PROOF SlaveTerminate() is called // on each slave server. } void SelSplitData::Terminate() { // The Terminate() function is the last function to be called during // a query. It always runs on the client, it can be used to present // the results graphically or save the results to file. //save the entry lists to a Root file if one was produced if (!elist_sub1) elist_sub1 = dynamic_cast(fOutput->FindObject(fSplitName1.Data())); if (elist_sub1) { Printf("Entry list '%s' created:\n",elist_sub1 -> GetName()); elist_sub1->Print(); TFile efile(fOutFileName.Data(),"update"); elist_sub1->Write(); } else { Error("Terminate", "entry list requested but not found in output"); } if (!elist_sub2) elist_sub2 = dynamic_cast(fOutput->FindObject(fSplitName2.Data())); if (elist_sub1) { Printf("Entry list '%s' created:",elist_sub2 -> GetName()); elist_sub2->Print(); TFile efile(fOutFileName.Data(),"update"); elist_sub2->Write(); } else { Error("Terminate", "entry list requested but not found in output"); } if (kAdditionalCuts) elist_sub1_cuts = dynamic_cast(fOutput->FindObject((fSplitName1 + "_with_cuts").Data())); if (elist_sub1_cuts) { Printf("Entry list '%s' created:\n",elist_sub1_cuts -> GetName() ); elist_sub1_cuts ->Print("all"); TFile efile(fOutFileName.Data(),"update"); elist_sub1_cuts -> Write(); } else { Error("Terminate", "entry list requested but not found in output"); } if (kAdditionalCuts) elist_sub2_cuts = dynamic_cast(fOutput->FindObject((fSplitName2 + "_with_cuts").Data())); if (elist_sub2_cuts) { Printf("Entry list '%s' created:\n",elist_sub2_cuts -> GetName() ); elist_sub2_cuts->Print("all"); TFile efile(fOutFileName.Data(),"update"); elist_sub2_cuts -> Write(); } else { Error("Terminate", "entry list requested but not found in output"); } }