// $Id$ // // File: DCustomAction_DetectorStudies.cc // Created: Thu May 1 18:23:01 EDT 2014 // Creator: pmatt (on Darwin pmattLaptop 10.8.0 i386) // #include "DCustomAction_DetectorStudies.h" void DCustomAction_DetectorStudies::Initialize(JEventLoop* locEventLoop) { //Optional: Create histograms and/or modify member variables. //Create any histograms/trees/etc. within a ROOT lock. //This is so that when running multithreaded, only one thread is writing to the ROOT file at a time. //When creating a reaction-independent action, only modify member variables within a ROOT lock. //Objects created within a plugin (such as reaction-independent actions) can be accessed by many threads simultaneously. japp->RootWriteLock(); //ACQUIRE ROOT LOCK!! { // Optional: Useful utility functions. // locEventLoop->GetSingle(dAnalysisUtilities); //Required: Create a folder in the ROOT output file that will contain all of the output ROOT objects (if any) for this action. //If another thread has already created the folder, it just changes to it. CreateAndChangeTo_ActionDirectory(); // Optional: Create a ROOT subfolder. //If another thread has already created the folder, it just changes to it. CreateAndChangeTo_Directory("HitInfo", "HitInfo"); { //FCAL if(gDirectory->Get("FCALShowerTime") == NULL) //check to see if already created by another thread dHist_FCALShowerTime = new TH1D("FCALShowerTime", ";FCAL Shower Time (ns)", 1600, -800.0, 800.0); else //already created by another thread dHist_FCALShowerTime = static_cast(gDirectory->Get("FCALShowerTime")); if(gDirectory->Get("FCALShowerEnergy") == NULL) //check to see if already created by another thread dHist_FCALShowerEnergy = new TH1D("FCALShowerEnergy", ";FCAL Shower Energy (GeV)", 1600, 0.0, 8.0); else //already created by another thread dHist_FCALShowerEnergy = static_cast(gDirectory->Get("FCALShowerEnergy")); if(gDirectory->Get("FCALShowerEnergyVsTime") == NULL) //check to see if already created by another thread dHist_FCALShowerEnergyVsTime = new TH2D("FCALShowerEnergyVsTime", ";FCAL Shower Time (ns);FCAL Shower Energy (GeV)", 400, -800.0, 800.0, 400, 0.0, 8.0); else //already created by another thread dHist_FCALShowerEnergyVsTime = static_cast(gDirectory->Get("FCALShowerEnergyVsTime")); if(gDirectory->Get("FCALShowerPhi") == NULL) //check to see if already created by another thread dHist_FCALShowerPhi = new TH1D("FCALShowerPhi", ";FCAL Shower #phi#circ", 720, -180.0, 180.0); else //already created by another thread dHist_FCALShowerPhi = static_cast(gDirectory->Get("FCALShowerPhi")); //BCAL if(gDirectory->Get("BCALShowerTime") == NULL) //check to see if already created by another thread dHist_BCALShowerTime = new TH1D("BCALShowerTime", ";BCAL Shower Time (ns)", 1600, -800.0, 800.0); else //already created by another thread dHist_BCALShowerTime = static_cast(gDirectory->Get("BCALShowerTime")); if(gDirectory->Get("BCALShowerEnergy") == NULL) //check to see if already created by another thread dHist_BCALShowerEnergy = new TH1D("BCALShowerEnergy", ";BCAL Shower Energy (GeV)", 1600, 0.0, 8.0); else //already created by another thread dHist_BCALShowerEnergy = static_cast(gDirectory->Get("BCALShowerEnergy")); if(gDirectory->Get("BCALShowerEnergyVsTime") == NULL) //check to see if already created by another thread dHist_BCALShowerEnergyVsTime = new TH2D("BCALShowerEnergyVsTime", ";BCAL Shower Time (ns);BCAL Shower Energy (GeV)", 400, -800.0, 800.0, 400, 0.0, 8.0); else //already created by another thread dHist_BCALShowerEnergyVsTime = static_cast(gDirectory->Get("BCALShowerEnergyVsTime")); if(gDirectory->Get("BCALShowerPhi") == NULL) //check to see if already created by another thread dHist_BCALShowerPhi = new TH1D("BCALShowerPhi", ";BCAL Shower #phi#circ", 720, -180.0, 180.0); else //already created by another thread dHist_BCALShowerPhi = static_cast(gDirectory->Get("BCALShowerPhi")); //TOF if(gDirectory->Get("TOFPointTime") == NULL) //check to see if already created by another thread dHist_TOFPointTime = new TH1D("TOFPointTime", ";TOF Point Time (ns)", 1600, -800.0, 800.0); else //already created by another thread dHist_TOFPointTime = static_cast(gDirectory->Get("TOFPointTime")); //SC if(gDirectory->Get("SCHitTime") == NULL) //check to see if already created by another thread dHist_SCHitTime = new TH1D("SCHitTime", ";SC Hit Time (ns)", 1600, -800.0, 800.0); else //already created by another thread dHist_SCHitTime = static_cast(gDirectory->Get("SCHitTime")); //Neutral Showers if(gDirectory->Get("NeutralShowerPhi") == NULL) //check to see if already created by another thread dHist_NeutralShowerPhi = new TH1D("NeutralShowerPhi", ";Neutral Shower #phi#circ", 720, -180.0, 180.0); else //already created by another thread dHist_NeutralShowerPhi = static_cast(gDirectory->Get("NeutralShowerPhi")); //Neutral Particles if(gDirectory->Get("NeutralParticlePhi") == NULL) //check to see if already created by another thread dHist_NeutralParticlePhi = new TH1D("NeutralParticlePhi", ";Neutral Particle #phi#circ", 720, -180.0, 180.0); else //already created by another thread dHist_NeutralParticlePhi = static_cast(gDirectory->Get("NeutralParticlePhi")); } gDirectory->cd(".."); //return to the action directory } japp->RootUnLock(); //RELEASE ROOT LOCK!! } bool DCustomAction_DetectorStudies::Perform_Action(JEventLoop* locEventLoop, const DParticleCombo* locParticleCombo) { //Expect locParticleCombo to be NULL since this is a reaction-independent action. //Optional: Quit the action if it has already been executed this event (else may result in double-counting when filling histograms) if(Get_NumPreviousParticleCombos() != 0) return true; vector locBCALShowers; locEventLoop->Get(locBCALShowers); vector locFCALShowers; locEventLoop->Get(locFCALShowers); vector locTOFPoints; locEventLoop->Get(locTOFPoints); vector locSCHits; locEventLoop->Get(locSCHits); vector locNeutralShowers; locEventLoop->Get(locNeutralShowers); vector locNeutralParticles; locEventLoop->Get(locNeutralParticles); //Optional: Fill histograms japp->RootWriteLock(); //ACQUIRE ROOT LOCK!! { for(size_t loc_i = 0; loc_i < locFCALShowers.size(); ++loc_i) { dHist_FCALShowerTime->Fill(locFCALShowers[loc_i]->getTime()); dHist_FCALShowerEnergy->Fill(locFCALShowers[loc_i]->getEnergy()); dHist_FCALShowerEnergyVsTime->Fill(locFCALShowers[loc_i]->getTime(), locFCALShowers[loc_i]->getEnergy()); dHist_FCALShowerPhi->Fill(locFCALShowers[loc_i]->getPosition().Phi()*180.0/TMath::Pi()); } for(size_t loc_i = 0; loc_i < locBCALShowers.size(); ++loc_i) { dHist_BCALShowerTime->Fill(locBCALShowers[loc_i]->t); dHist_BCALShowerEnergy->Fill(locBCALShowers[loc_i]->E); dHist_BCALShowerEnergyVsTime->Fill(locBCALShowers[loc_i]->t, locBCALShowers[loc_i]->E); dHist_BCALShowerPhi->Fill(atan2(locBCALShowers[loc_i]->y, locBCALShowers[loc_i]->x)*180.0/TMath::Pi()); } for(size_t loc_i = 0; loc_i < locTOFPoints.size(); ++loc_i) dHist_TOFPointTime->Fill(locTOFPoints[loc_i]->t); for(size_t loc_i = 0; loc_i < locSCHits.size(); ++loc_i) dHist_SCHitTime->Fill(locSCHits[loc_i]->t); for(size_t loc_i = 0; loc_i < locNeutralShowers.size(); ++loc_i) dHist_NeutralShowerPhi->Fill(locNeutralShowers[loc_i]->dSpacetimeVertex.Phi()*180.0/TMath::Pi()); for(size_t loc_i = 0; loc_i < locNeutralParticles.size(); ++loc_i) { const DNeutralParticleHypothesis* locNeutralParticleHypothesis = locNeutralParticles[loc_i]->Get_BestFOM(); dHist_NeutralParticlePhi->Fill(locNeutralParticleHypothesis->momentum().Phi()*180.0/TMath::Pi()); } } japp->RootUnLock(); //RELEASE ROOT LOCK!! return true; //return false if you want to use this action to apply a cut (and it fails the cut!) }