waveform_sampler.cc

Go to the documentation of this file.
00001 #ifndef WAVEFORM_SAMPLER_CC
00002 #define WAVEFORM_SAMPLER_CC
00003 
00004 #include "waveform_sampler.hh"
00005 
00006 waveform_sampler::waveform_sampler() : _sel_info(), _hWF_map()
00007 { 
00008   _name="waveform_sampler"; 
00009   _fout=0;
00010   _selector=0;
00011   _wf_length = 0;
00012 };
00013 
00014 bool waveform_sampler::initialize() {
00015 
00016   if(!(_selector)) {
00017 
00018     Message::send(MSG::ERROR,__FUNCTION__,
00019           "pulse selection algorithm has not been set! Aborting...");
00020 
00021     return false;
00022   }
00023 
00024   if(_wf_length < 1) {
00025 
00026     Message::send(MSG::ERROR,__FUNCTION__,
00027           "sample waveform length is set to < 1! Aborting...");
00028     
00029     return false;
00030   }
00031 
00032   _hWF_map.clear();
00033 
00034   return true;
00035 }
00036 
00037 void waveform_sampler::clear_event(){
00038 
00039   _sel_info.clear();
00040 
00041 }
00042 
00043 bool waveform_sampler::analyze(storage_manager* storage) {
00044 
00045   pulse_collection *pulses = (pulse_collection*)(storage->get_data(_selector->pulse_type()));
00046   
00047   pmt_wf_collection   *wfs    = (pmt_wf_collection*)(storage->get_data(DATA_STRUCT::PMT_WF_COLLECTION));
00048 
00049   if(!pulses){
00050 
00051     Message::send(MSG::ERROR,__FUNCTION__,
00052           "Necessary input pulses not found!");
00053 
00054     return false;
00055 
00056   }
00057 
00058   if(!wfs){
00059 
00060     Message::send(MSG::ERROR,__FUNCTION__,
00061           "Necessary input raw waveform not found!");
00062 
00063     return false;
00064 
00065   }
00066 
00067   clear_event();
00068 
00069   if(!(_selector->analyze(storage))) return false;
00070 
00071   //
00072   // Log ch number, frame id, sample number of selected pulse
00073   //
00074   for(auto pulse : *pulses){
00075     
00076     if(!(_selector->select_pulse(&pulse))) continue;
00077     
00078     PMT::ch_number_t ch     = pulse.channel_number();
00079     PMT::word_t      frame  = pulse.frame_id();
00080     PMT::word_t      sample = pulse.timeslice();
00081     
00082     if(_sel_info.find(ch)==_sel_info.end()) 
00083       
00084       _sel_info[ch] = std::map<PMT::word_t,std::set<PMT::word_t> >();
00085     
00086     if(_sel_info[ch].find(frame) == _sel_info[ch].end() )
00087       
00088       _sel_info[ch][frame] = std::set<PMT::word_t>(); 
00089     
00090     if(_sel_info[ch][frame].find(sample) == _sel_info[ch][frame].end())
00091       
00092       _sel_info[ch][frame].insert(sample);
00093 
00094   }
00095   
00096   //
00097   // Loop over waveforms that matches with the selected IDs
00098   //
00099   for(auto wf : *wfs){
00100 
00101     PMT::ch_number_t ch     = wf.channel_number();
00102     PMT::word_t      frame  = wf.channel_frame_id();
00103     PMT::word_t      sample = wf.timeslice();
00104 
00105     if(_sel_info.find(ch) == _sel_info.end()) continue;
00106 
00107     if(_sel_info[ch].find(frame) == _sel_info[ch].end()) continue;
00108 
00109     if(_sel_info[ch][frame].find(sample) == _sel_info[ch][frame].end()) continue;
00110 
00111     sample_waveform(&wf);
00112 
00113   }  
00114 
00115   /*
00116   for(pmt_wf_collection::iterator iter(wfs->begin());
00117       iter != wfs->end();
00118       ++iter){
00119 
00120     PMT::ch_number_t ch     = (*iter).channel_number();
00121     PMT::word_t      frame  = (*iter).channel_frame_id();
00122     PMT::word_t      sample = (*iter).timeslice();
00123 
00124     if(_sel_info.find(ch) == _sel_info.end()) continue;
00125 
00126     if(_sel_info[ch].find(frame) == _sel_info[ch].end()) continue;
00127 
00128     if(_sel_info[ch][frame].find(sample) == _sel_info[ch][frame].end()) continue;
00129 
00130     sample_waveform(&(*iter));
00131 
00132   }  
00133   */
00134 
00135 
00136   return true;
00137 }
00138 
00139 void waveform_sampler::sample_waveform(const pmt_waveform *wf){
00140 
00141   PMT::ch_number_t ch(wf->channel_number());
00142 
00143   int nbins = (_wf_length < (int)(wf->size())) ? _wf_length : (int)(wf->size());
00144 
00145   _fout->cd();
00146   if(_hWF_map.find(ch)==_hWF_map.end()) {
00147     
00148     TString pulse_name(Form("%s",DATA_STRUCT::DATA_TREE_NAME[_selector->pulse_type()].c_str()));
00149     pulse_name.ReplaceAll("pulse_","");
00150     pulse_name.ReplaceAll("_window","");    
00151 
00152     _hWF_map[ch] = new TH2D(Form("hWF_%s_Ch%02d",pulse_name.Data(),ch),
00153                 Form("Raw Waveform Sample for Ch %d; Timeslice; ADC",ch),
00154                 nbins, -0.5, ((double)nbins)-0.5, 4096, -0.5,4095.5);
00155     
00156   }
00157 
00158   for(int i=0; i<nbins; i++)
00159 
00160     _hWF_map[ch]->Fill((double)i, (double)(wf->at(i)));
00161   
00162 }
00163 
00164 bool waveform_sampler::finalize() {
00165 
00166   if(_fout){
00167     
00168     _fout->cd();
00169 
00170     for(std::map<PMT::ch_number_t,TH2D*>::const_iterator iter(_hWF_map.begin());
00171     iter!=_hWF_map.end();
00172     ++iter){
00173 
00174       (*iter).second->Write();
00175 
00176     }
00177   
00178   }
00179 
00180   return true;
00181 }
00182 
00183 #endif

Generated on Mon Apr 7 15:35:12 2014 for MyProject by  doxygen 1.4.7