// $Id$ // // File: DEventWriterROOT_AddST.cc // Created: Mon Apr 24 15:32:18 EDT 2017 // Creator: davidl (on Linux gluon112.jlab.org 2.6.32-642.3.1.el6.x86_64 x86_64) // #include #include "DEventWriterROOT_AddST.h" //GLUEX TTREE DOCUMENTATION: https://halldweb.jlab.org/wiki/index.php/Analysis_TTreeFormat void DEventWriterROOT_AddST::Create_CustomBranches_DataTree(DTreeBranchRegister& locBranchRegister, JEventLoop* locEventLoop, const DReaction* locReaction, bool locIsMCDataFlag) const { locBranchRegister.Register_Single("ST_max_pi"); unsigned int locInitArraySize = 10; locBranchRegister.Register_Single("InvMassOmegaSize"); locBranchRegister.Register_FundamentalArray("InvMassOmega", "InvMassOmegaSize", locInitArraySize); /* //EXAMPLES: Create a branch for a single object (e.g. Int_t, Float_t, TVector3): //If filling for a specific particle, the branch name should match the particle branch name locBranchRegister.Register_Single("DummyUInt"); locBranchRegister.Register_Single("PiPlus__DummyFloat"); locBranchRegister.Register_Single("Dummy3Vector"); locBranchRegister.Register_Single("PiPlus__Dummy4Vector"); */ /* //EXAMPLES: Create a branch to hold an array of fundamental type: //If filling for a specific particle, the branch name should match the particle branch name //locArraySizeString is the name of the branch whose variable that contains the size of the array for that tree entry //To match the default TTree branches, use either: 'NumThrown', 'NumBeam', 'NumChargedHypos', 'NumNeutralHypos', or 'NumCombos', as appropriate unsigned int locInitArraySize = 10; //if too small, will auto-increase as needed, but requires new calls //if too large, uses more memory than needed locBranchRegister.Register_Single( "DummyArraySize"); //you must store the size of the fundamental array for each entry!! locBranchRegister.Register_FundamentalArray("PiPlus__DummyIntArray", "DummyArraySize", locInitArraySize); locBranchRegister.Register_FundamentalArray("DummyFloatArray", "DummyArraySize", locInitArraySize); */ /* //EXAMPLES: Create a branch to hold a TClonesArray of TObject type: //If filling for a specific particle, the branch name should match the particle branch name unsigned int locInitObjectArraySize = 10; //if too small, will auto-increase as needed, but requires new calls //if too large, uses more memory than needed locBranchRegister.Register_ClonesArray("PiPlus__Dummy4VectorArray", locInitObjectArraySize); locBranchRegister.Register_ClonesArray("Dummy3VectorArray", locInitObjectArraySize); */ } void DEventWriterROOT_AddST::Create_CustomBranches_ThrownTree(DTreeBranchRegister& locBranchRegister, JEventLoop* locEventLoop) const { //EXAMPLES: See Create_CustomBranches_DataTree } void DEventWriterROOT_AddST::Fill_CustomBranches_DataTree(DTreeFillData* locTreeFillData, JEventLoop* locEventLoop, const DMCReaction* locMCReaction, const vector& locMCThrowns, const DMCThrownMatching* locMCThrownMatching, const DDetectorMatches* locDetectorMatches, const vector& locBeamPhotons, const vector& locChargedHypos, const vector& locNeutralHypos, const deque& locParticleCombos) const { uint32_t max_pulse_integral = 0; vector scdigihits; locEventLoop->Get(scdigihits); for(auto h : scdigihits) if(h->pulse_integral > max_pulse_integral) max_pulse_integral = h->pulse_integral; locTreeFillData->Fill_Single("ST_max_pi", max_pulse_integral); const DAnalysisUtilities* dAnalysisUtilities = NULL; locEventLoop->GetSingle(dAnalysisUtilities); Particle_t dInitialPID = omega; vector locMassesToFill; for(auto locParticleCombo : locParticleCombos){ set > > dPreviousSourceObjects; // Copied from DHistogramAction_InvariantMass for(size_t loc_i = 0; loc_i < locParticleCombo->Get_NumParticleComboSteps(); ++loc_i) { const DParticleComboStep* locParticleComboStep = locParticleCombo->Get_ParticleComboStep(loc_i); const DReactionStep* locReactionStep = locParticleCombo->Get_Reaction()->Get_ReactionStep(loc_i); if(locParticleComboStep->Get_InitialParticleID() != dInitialPID) continue; //build all possible combinations of the included pids deque dToIncludePIDs; set > locIndexCombos = dAnalysisUtilities->Build_IndexCombos(locReactionStep, dToIncludePIDs); //loop over them set >::iterator locComboIterator = locIndexCombos.begin(); for(; locComboIterator != locIndexCombos.end(); ++locComboIterator) { set > locSourceObjects; DLorentzVector locFinalStateP4 = dAnalysisUtilities->Calc_FinalStateP4(locParticleCombo, loc_i, *locComboIterator, locSourceObjects, true); if(dPreviousSourceObjects.find(locSourceObjects) != dPreviousSourceObjects.end()) continue; //dupe: already histed! dPreviousSourceObjects.insert(locSourceObjects); locMassesToFill.push_back(locFinalStateP4.M()); } //don't break: e.g. if multiple pi0's, histogram invariant mass of each one } } Int_t locOutputArraySize = locMassesToFill.size(); locTreeFillData->Fill_Single("InvMassOmegaSize", locOutputArraySize); for(Int_t loc_i = 0; loc_i < locOutputArraySize; ++loc_i) { locTreeFillData->Fill_Array("InvMassOmega", locMassesToFill[loc_i], loc_i); } //The array indices of the particles/combos in the main TTree branches match the vectors of objects passed into this function //So if you want to add custom data for each (e.g.) charged track, the correspondence to the main arrays is 1 <--> 1 /* //EXAMPLES: Fill a branch for a fundamental data type (e.g. Int_t, Float_t): //!!!!! YOU MUST BE SURE THAT template type matches the type you used to create the branch locTreeFillData->Fill_Single("DummyUInt", 14); //14: dummy value locTreeFillData->Fill_Single("PiPlus__DummyFloat", TMath::Pi()); //pi: dummy value */ /* //EXAMPLES: Fill a branch for a TObject data type (e.g. TVector3, TLorentzVector): //!!!!! YOU MUST BE SURE THAT template type matches the type you used to create the branch TVector3 locPosition(0.0, 0.0, 65.0); locTreeFillData->Fill_Single("Dummy3Vector", locPosition); TLorentzVector locP4(1.0, 2.0, 3.0, 4.0); locTreeFillData->Fill_Single("PiPlus__Dummy4Vector", locP4); */ /* //EXAMPLES: Fill a branch with an array of fundamental type: //!!!!! YOU MUST BE SURE THAT template type matches the type you used to create the branch Int_t locOutputArraySize = 7; locTreeFillData->Fill_Single("DummyArraySize", locOutputArraySize); for(Int_t loc_i = 0; loc_i < locOutputArraySize; ++loc_i) { Int_t locValue = loc_i - 14; //dummy number locTreeFillData->Fill_Array("PiPlus__DummyIntArray", locValue, loc_i); locTreeFillData->Fill_Array("DummyFloatArray", locValue + 9999, loc_i); } */ /* //EXAMPLES: Fill a branch with a TClonesArray of TObject type: //!!!!! YOU MUST BE SURE THAT template type matches the type you used to create the branch for(Int_t loc_i = 0; loc_i < 15; ++loc_i) { TLorentzVector locNewP4(99.0, 2.0, 3.0, 4.0); locTreeFillData->Fill_Array("PiPlus__Dummy4VectorArray", locNewP4, loc_i); TVector3 locNewPosition(100.0, 0.0, 65.0); locTreeFillData->Fill_Array("Dummy3VectorArray", locNewPosition, loc_i); } */ } void DEventWriterROOT_AddST::Fill_CustomBranches_ThrownTree(DTreeFillData* locTreeFillData, JEventLoop* locEventLoop, const DMCReaction* locMCReaction, const vector& locMCThrowns) const { //EXAMPLES: See Fill_CustomBranches_DataTree }