// $Id$ // // File: JEventProcessor_bcal_timing.cc // Created: Mon Aug 1 08:51:12 EDT 2011 // Creator: davidl (on Linux ifarm1102 2.6.18-128.7.1.el5 x86_64) // #include #include "JEventProcessor_bcal_timing.h" #include "JFactoryGenerator_DBCALTimeSpectrum.h" using namespace jana; #include #include "DBCALTimeSpectrum.h" // Routine used to create our JEventProcessor #include extern "C"{ void InitPlugin(JApplication *app){ InitJANAPlugin(app); app->AddFactoryGenerator(new JFactoryGenerator_DBCALTimeSpectrum); app->AddProcessor(new JEventProcessor_bcal_timing()); } } // "C" //------------------ // JEventProcessor_bcal_timing (Constructor) //------------------ JEventProcessor_bcal_timing::JEventProcessor_bcal_timing() { pthread_mutex_init(&root_mutex, NULL); } //------------------ // ~JEventProcessor_bcal_timing (Destructor) //------------------ JEventProcessor_bcal_timing::~JEventProcessor_bcal_timing() { } //------------------ // init //------------------ jerror_t JEventProcessor_bcal_timing::init(void) { events_to_save = 1; gPARMS->SetDefaultParameter("EVENTS_TO_SAVE", events_to_save, "Number of events to save electronic pulse shape histos for."); pthread_mutex_lock(&root_mutex); hit_tree = new TTree("tree", "hits"); hit_tree->Branch("T", &hit, "event/I:layer:sector:fADC_up:fADC_dn:Etot/F:geometric_mean:tup:tdn:tup_corrected:tdn_corrected:theta_thrown:E_thrown"); pthread_mutex_unlock(&root_mutex); return NOERROR; } //------------------ // brun //------------------ jerror_t JEventProcessor_bcal_timing::brun(JEventLoop *eventLoop, int runnumber) { // This is called whenever the run number changes return NOERROR; } //------------------ // evnt //------------------ jerror_t JEventProcessor_bcal_timing::evnt(JEventLoop *loop, int eventnumber) { vector mcthrowns; vector bcalTimeSpectra; loop->Get(mcthrowns); loop->Get(bcalTimeSpectra); if(mcthrowns.size()!=1)return NOERROR; const DMCThrown *thrown = mcthrowns[0]; // Fill hit tree pthread_mutex_lock(&root_mutex); for(unsigned int i=0; i< bcalTimeSpectra.size(); i++){ const DBCALTimeSpectrum *spectrum = bcalTimeSpectra[i]; hit.event = eventnumber; hit.layer = spectrum->layer; hit.sector = spectrum->sector; hit.fADC_up = spectrum->fADC_up; hit.fADC_dn = spectrum->fADC_dn; hit.Etot = spectrum->Etot; hit.geometric_mean = spectrum->geometric_mean; hit.tup = spectrum->tup; hit.tdn = spectrum->tdn; hit.tup_corrected = spectrum->tup_corrected; hit.tdn_corrected = spectrum->tdn_corrected; hit.theta_thrown = thrown->momentum().Theta(); hit.E_thrown = thrown->energy(); hit_tree->Fill(); } pthread_mutex_unlock(&root_mutex); // Save histograms for first event if(eventnumber<=events_to_save){ pthread_mutex_lock(&root_mutex); TDirectory *save_dir = gDirectory; char dirname[256]; sprintf(dirname, "evt%03d", eventnumber); TDirectory *evt_dir = new TDirectoryFile(dirname,dirname); evt_dir->cd(); for(unsigned int i=0; i< bcalTimeSpectra.size(); i++){ const DBCALTimeSpectrum *spectrum = bcalTimeSpectra[i]; char hname[256]; sprintf(hname, "lay%02dsec%d_up", spectrum->layer, spectrum->sector); spectrum->Eup.MakeTH1D(hname, hname); sprintf(hname, "lay%02dsec%d_dn", spectrum->layer, spectrum->sector); spectrum->Edn.MakeTH1D(hname, hname); sprintf(hname, "elec_lay%02dsec%d_up", spectrum->layer, spectrum->sector); spectrum->electronic_up.MakeTH1D(hname, hname); sprintf(hname, "elec_lay%02dsec%d_dn", spectrum->layer, spectrum->sector); spectrum->electronic_dn.MakeTH1D(hname, hname); } save_dir->cd(); pthread_mutex_unlock(&root_mutex); } return NOERROR; } //------------------ // erun //------------------ jerror_t JEventProcessor_bcal_timing::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 JEventProcessor_bcal_timing::fini(void) { // Called before program exit after event processing is finished. return NOERROR; }