#include #include #include #include "JEventProcessor_TPOL_waveform.h" #include using namespace std; using namespace jana; #include #include #include #include #include "DAQ/Df250WindowRawData.h" #include "TPOL/DTPOLSectorDigiHit.h" #include "TPOL/DTPOLHit.h" #include "PAIR_SPECTROMETER/DPSPair.h" #include "PAIR_SPECTROMETER/DPSCPair.h" // Need this or else cannot get Df250PulseIntegral objects // from event loop #include //////////////////////// KM hists ///////////////////////////////////// /// number of digihits for each detector /// static TH1I *hnwaveforms; static TH1I *hnoWaveformSector; //---------------------------------------------------------------------------------- // Routine used to create our JEventProcessor extern "C"{ void InitPlugin(JApplication *app){ InitJANAPlugin(app); app->AddProcessor(new JEventProcessor_TPOL_waveform()); } } //---------------------------------------------------------------------------------- JEventProcessor_TPOL_waveform::JEventProcessor_TPOL_waveform() { DEBUG_TPOL = false; INVERTED_POLARITY = false; gPARMS->SetDefaultParameter("TPOL:DEBUG_TPOL",DEBUG_TPOL); // This should probably be put in the CCDB... gPARMS->SetDefaultParameter("TPOL:INVERTED_POLARITY",INVERTED_POLARITY); } //---------------------------------------------------------------------------------- JEventProcessor_TPOL_waveform::~JEventProcessor_TPOL_waveform() { } //---------------------------------------------------------------------------------- jerror_t JEventProcessor_TPOL_waveform::init(void) { japp->RootWriteLock(); //ACQUIRE ROOT LOCK!! // Create root folder for ST and cd to it, store main dir TDirectory *main = gDirectory; gDirectory->mkdir("TPOL_waveform")->cd(); //////////////////////// KM hists ///////////////////////////////////// hnwaveforms = new TH1I("hnwaveforms",";# of TPOL waveforms;",50,-0.5,49.5); hnoWaveformSector = new TH1I("hnoWaveformSector",";sector with no waveform;",50,-0.5,49.5); // cd back to main directory main->cd(); outtree = new TTree("TPOL_waveformTree","TPOL_waveformTree"); // # of hits outtree->Branch("nwaveforms",&nwaveforms,"nwaveforms/i"); outtree->Branch("eventnum",&eventnum,"eventnum/I"); outtree->Branch("slot",slot,"slot[nwaveforms]/I"); outtree->Branch("sector",sector,"sector[nwaveforms]/I"); outtree->Branch("pedestal",pedestal,"pedestal[nwaveforms]/D"); outtree->Branch("maxcounts",maxcounts,"maxcounts[nwaveforms]/s"); outtree->Branch("waveform",waveform,"waveform[nwaveforms][100]/s"); outtree->Branch("nhits_PSC",&nhits_PSC,"nhits_PSC/i"); outtree->Branch("iLeft_PSC",iLeft_PSC,"iLeft_PSC[nhits_PSC]/I"); outtree->Branch("iRight_PSC",iRight_PSC,"iRight_PSC[nhits_PSC]/I"); outtree->Branch("t_iLeft_PSC",t_iLeft_PSC,"t_iLeft_PSC[nhits_PSC]/F"); outtree->Branch("t_iRight_PSC",t_iRight_PSC,"t_iRight_PSC[nhits_PSC]/F"); outtree->Branch("nhits_PS",&nhits_PS,"nhits_PS/i"); outtree->Branch("iLeft_PS",iLeft_PS,"iLeft_PS[nhits_PS]/I"); outtree->Branch("iRight_PS",iRight_PS,"iRight_PS[nhits_PS]/I"); outtree->Branch("e_iLeft_PS",e_iLeft_PS,"e_iLeft_PS[nhits_PS]/F"); outtree->Branch("e_iRight_PS",e_iRight_PS,"e_iRight_PS[nhits_PS]/F"); japp->RootUnLock(); //RELEASE ROOT LOCK!! cout << "end of init" << endl; return NOERROR; } //---------------------------------------------------------------------------------- jerror_t JEventProcessor_TPOL_waveform::brun(JEventLoop *eventLoop, int runnumber) { // This is called whenever the run number changes return NOERROR; } //---------------------------------------------------------------------------------- jerror_t JEventProcessor_TPOL_waveform::evnt(JEventLoop *eventLoop, int eventnumber) { // Get all data objects first so we minimize the time we hold the ROOT mutex lock if(DEBUG_TPOL){ cout << "------------- entry = " << eventnumber << " -------------" << endl; } // Each detector's hits vector windowrawdata; // Get Df250PulseIntegral objects eventLoop->Get(windowrawdata); // Each detector's hits vector cpairs; vector fpairs; eventLoop->Get(cpairs); eventLoop->Get(fpairs); // cout << "pairs : " << cpairs.size() << " " << fpairs.size() << endl; assert(cpairs.size() < NMAX); assert(fpairs.size() < NMAX); // Lock ROOT mutex so other threads won't interfere japp->RootWriteLock(); { // All variables need to be within lock. eventnum = eventnumber; nhits_PSC = cpairs.size(); nhits_PS = fpairs.size(); for(UInt_t i=0;irocid == 84 && (windowrawdata[i]->slot == 13 || windowrawdata[i]->slot == 14) ){ UInt_t sl = windowrawdata[i]->slot; UInt_t ch = windowrawdata[i]->channel; // TPOL sectors are 1 - 32 slot[nwaveforms] = windowrawdata[i]->slot; if(slot[nwaveforms]==13 || slot[nwaveforms]==14){ sector[nwaveforms] = 16 * (sl - 13) + ch + 1; }else{ sector[nwaveforms] = 0; } if(DEBUG_TPOL){ cout << "sector[" << nwaveforms << "] = " << sector[nwaveforms] << endl << "Found Windowrawdata with rocid = " << windowrawdata[i]->rocid << endl << " slot = " << slot[nwaveforms] << endl << " channel = " << windowrawdata[i]->channel << endl << " sector = " << sector[nwaveforms] << endl << "getting rawdata for TPOL ch " << windowrawdata[nwaveforms]->channel << endl; } const vector &samplesvector = windowrawdata[i]->samples; assert(samplesvector.size() == 100); maxcounts[nwaveforms] = 0; Int_t maxsample = -999; UShort_t sum = 0; for(UInt_t sample=0;sampleee.first; // left hit in coarse PS const DPSCHit* crhit = cpairs[i_PSC]->ee.second;// right hit in coarse PS iRight_PSC[i_PSC] = crhit->module; iLeft_PSC[i_PSC] = clhit->module; t_iRight_PSC[i_PSC] = crhit->t; t_iLeft_PSC[i_PSC] = clhit->t; } // PS pairs for(UInt_t i_PS=0;i_PSee.first; // left hit in fine PS const DPSHit* frhit = fpairs[i_PS]->ee.second; // right hit in fine PS iRight_PS[i_PS] = frhit->column; iLeft_PS[i_PS] = flhit->column; if(iRight_PS[i_PS] > 145) cout << "iRight_PS[i_PS] = " << iRight_PS[i_PS] << endl; e_iRight_PS[i_PS] = frhit->E; e_iLeft_PS[i_PS] = flhit->E; } // Fill tree!! hnwaveforms->Fill(nwaveforms); outtree->Fill(); //////////////////////////////////////////////////////////////////////////////////////// // Use JANA framework // Get DTPOLSectorDigiHits if(nwaveforms!=0){ // vector dtpolsectordigihit; // eventLoop->Get(dtpolsectordigihit); // cout << "nwaveforms = " << nwaveforms << " number of DTPOLSectorDigiHit objects: " << dtpolsectordigihit.size() << endl; } // Get DTPOLHits // vector dtpolhit; // eventLoop->Get(dtpolhit); // cout << "number of DTPOLHit objects: " << dtpolhit.size() << endl; } japp->RootUnLock(); return NOERROR; } //---------------------------------------------------------------------------------- jerror_t JEventProcessor_TPOL_waveform::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; } //---------------------------------------------------------------------------------- jerror_t JEventProcessor_TPOL_waveform::fini(void) { // Called before program exit after event processing is finished. outtree->Write(); return NOERROR; } //---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------