// $Id$ // // File: DEventProcessor_SkimStudies.cc // Created: Thu May 1 18:22:22 EDT 2014 // Creator: pmatt (on Darwin pmattLaptop 10.8.0 i386) // #include "DEventProcessor_SkimStudies.h" // Routine used to create our DEventProcessor extern "C" { void InitPlugin(JApplication *locApplication) { InitJANAPlugin(locApplication); locApplication->AddProcessor(new DEventProcessor_SkimStudies()); //register this plugin } } // "C" //------------------ // init //------------------ jerror_t DEventProcessor_SkimStudies::init(void) { // This is called once at program startup. If you are creating // and filling historgrams in this plugin, you should lock the // ROOT mutex like this: // // japp->RootWriteLock(); // ... create historgrams or trees ... // japp->RootUnLock(); // return NOERROR; } //------------------ // brun //------------------ jerror_t DEventProcessor_SkimStudies::brun(jana::JEventLoop* locEventLoop, int locRunNumber) { // This is called whenever the run number changes dCustomAction_HistTotalPVsBeamE.Initialize(locEventLoop); dCustomAction_ParticleStudies.Initialize(locEventLoop); dCustomAction_DetectorStudies.Initialize(locEventLoop); return NOERROR; } //------------------ // evnt //------------------ jerror_t DEventProcessor_SkimStudies::evnt(jana::JEventLoop* locEventLoop, int locEventNumber) { // DOCUMENTATION: // ANALYSIS library: https://halldweb1.jlab.org/wiki/index.php/GlueX_Analysis_Software dCustomAction_HistTotalPVsBeamE(locEventLoop); dCustomAction_ParticleStudies(locEventLoop); dCustomAction_DetectorStudies(locEventLoop); vector locThrowns; locEventLoop->Get(locThrowns, "Primary"); const DMCThrownMatching* locMCThrownMatching = NULL; locEventLoop->GetSingle(locMCThrownMatching); //sort thrown pids, build string if(locThrowns.empty()) return NOERROR; map locNumParticlesByType; for(size_t loc_i = 0; loc_i < locThrowns.size(); ++loc_i) { Particle_t locPID = locThrowns[loc_i]->PID(); if(locNumParticlesByType.find(locPID) != locNumParticlesByType.end()) ++(locNumParticlesByType[locPID]); else locNumParticlesByType[locPID] = 1; } //Thrown Topology string locThrownTopology = ""; map::iterator locIterator = locNumParticlesByType.begin(); for(; locIterator != locNumParticlesByType.end(); ++locIterator) { if(locIterator != locNumParticlesByType.begin()) locThrownTopology += ", "; unsigned int locNumParticles = locIterator->second; if(locNumParticles > 1) { ostringstream locStream; locStream << locNumParticles; locThrownTopology += locStream.str(); } locThrownTopology += ParticleName_ROOT(locIterator->first); } if(dNumEventsByThrownTopology.find(locThrownTopology) != dNumEventsByThrownTopology.end()) ++(dNumEventsByThrownTopology[locThrownTopology]); else dNumEventsByThrownTopology[locThrownTopology] = 1; //Thrown Topology - Brief string locThrownTopology_Brief = ""; unsigned int locNumPions = 0; if(locNumParticlesByType.find(PiPlus) != locNumParticlesByType.end()) locNumPions += locNumParticlesByType[PiPlus]; if(locNumParticlesByType.find(PiMinus) != locNumParticlesByType.end()) locNumPions += locNumParticlesByType[PiMinus]; if(locNumParticlesByType.find(Pi0) != locNumParticlesByType.end()) locNumPions += locNumParticlesByType[Pi0]; if(locNumPions > 0) { ostringstream locStream; if(locNumPions > 1) locStream << locNumPions; locThrownTopology_Brief += locStream.str() + string("#it{#pi}"); } unsigned int locNumKaons = 0; if(locNumParticlesByType.find(KPlus) != locNumParticlesByType.end()) locNumKaons += locNumParticlesByType[KPlus]; if(locNumParticlesByType.find(KMinus) != locNumParticlesByType.end()) locNumKaons += locNumParticlesByType[KMinus]; if(locNumParticlesByType.find(KShort) != locNumParticlesByType.end()) locNumKaons += locNumParticlesByType[KShort]; if(locNumParticlesByType.find(KLong) != locNumParticlesByType.end()) locNumKaons += locNumParticlesByType[KLong]; if(locNumKaons > 0) { ostringstream locStream; if(locNumKaons > 1) locStream << locNumKaons; if(locThrownTopology_Brief != "") locThrownTopology_Brief += ", "; locThrownTopology_Brief += locStream.str() + string("#it{K}"); } locIterator = locNumParticlesByType.begin(); for(; locIterator != locNumParticlesByType.end(); ++locIterator) { Particle_t locPID = locIterator->first; if((locPID == PiPlus) || (locPID == PiMinus) || (locPID == Pi0)) continue; if((locPID == KPlus) || (locPID == KMinus) || (locPID == KShort) || (locPID == KLong)) continue; if(locIterator != locNumParticlesByType.begin()) locThrownTopology_Brief += ", "; unsigned int locNumParticles = locIterator->second; if(locNumParticles > 1) { ostringstream locStream; locStream << locNumParticles; locThrownTopology_Brief += locStream.str(); } locThrownTopology_Brief += ParticleName_ROOT(locIterator->first); } if(dNumEventsByThrownTopology_Brief.find(locThrownTopology_Brief) != dNumEventsByThrownTopology_Brief.end()) ++(dNumEventsByThrownTopology_Brief[locThrownTopology_Brief]); else dNumEventsByThrownTopology_Brief[locThrownTopology_Brief] = 1; return NOERROR; } //------------------ // erun //------------------ jerror_t DEventProcessor_SkimStudies::erun(void) { // This is called whenever the run number changes, before it is // changed to give you a chance to clean up before processing // events from the next run number. return NOERROR; } //------------------ // fini //------------------ jerror_t DEventProcessor_SkimStudies::fini(void) { // Called before program exit after event processing is finished. string locOutputFileName = "hd_root.root"; if(gPARMS->Exists("OUTPUT_FILENAME")) gPARMS->GetParameter("OUTPUT_FILENAME", locOutputFileName); TFile* locFile = (TFile*)gROOT->FindObject(locOutputFileName.c_str()); if(locFile == NULL) return NOERROR; locFile->cd(""); TH1D* locHist_ThrownTopologies = new TH1D("ThrownTopologies", "", dNumEventsByThrownTopology.size(), -0.5, dNumEventsByThrownTopology.size() - 0.5); //build reverse map to sort by # per topology multimap locReverseMap; map::iterator locIterator = dNumEventsByThrownTopology.begin(); for(; locIterator != dNumEventsByThrownTopology.end(); ++locIterator) locReverseMap.insert(pair(locIterator->second, locIterator->first)); //loop over reverse map to fill histogram unsigned int locBinIndex = 1; multimap::reverse_iterator locCountIterator = locReverseMap.rbegin(); for(; locCountIterator != locReverseMap.rend(); ++locCountIterator) { locHist_ThrownTopologies->SetBinContent(locBinIndex, locCountIterator->first); locHist_ThrownTopologies->GetXaxis()->SetBinLabel(locBinIndex, locCountIterator->second.c_str()); ++locBinIndex; } TH1D* locHist_ThrownTopologies_Brief = new TH1D("ThrownTopologies_Brief", "", dNumEventsByThrownTopology_Brief.size(), -0.5, dNumEventsByThrownTopology_Brief.size() - 0.5); //build reverse map to sort by # per topology multimap locReverseMap_Brief; locIterator = dNumEventsByThrownTopology_Brief.begin(); for(; locIterator != dNumEventsByThrownTopology_Brief.end(); ++locIterator) locReverseMap_Brief.insert(pair(locIterator->second, locIterator->first)); //loop over reverse map to fill histogram locBinIndex = 1; locCountIterator = locReverseMap_Brief.rbegin(); for(; locCountIterator != locReverseMap_Brief.rend(); ++locCountIterator) { locHist_ThrownTopologies_Brief->SetBinContent(locBinIndex, locCountIterator->first); locHist_ThrownTopologies_Brief->GetXaxis()->SetBinLabel(locBinIndex, locCountIterator->second.c_str()); ++locBinIndex; } return NOERROR; }