reco_wf.cc

Go to the documentation of this file.
00001 #ifndef RECO_WF_CC
00002 #define RECO_WF_CC
00003 
00004 #include "reco_wf.hh"
00005 
00006 reco_wf::reco_wf() : _wf_histo(0) {
00007   _frame_width=4096;
00008   _name="reco_wf";
00009   reset();
00010 
00011 }
00012 
00013 void reco_wf::reset(){
00014 
00015   clear_event();
00016 }
00017 
00018 void reco_wf::clear_event(){
00019 
00020   if(_wf_histo)
00021     delete _wf_histo;
00022   _wf_histo=0;
00023   _channels.clear();
00024   _wf_map.clear();
00025   _ref_frame=0;
00026   _ref_slice=0;
00027   _event_id=0;
00028 }
00029 
00030 bool reco_wf::initialize() {
00031 
00032   if(!_frame_width){
00033     Message::send(MSG::ERROR,__FUNCTION__,"Frame width unspecified! ");
00034     return false;
00035   }
00036 
00037   return true;
00038 
00039 };
00040 
00041 bool reco_wf::analyze(storage_manager* storage){
00042 
00043   pmt_wf_collection *data = (pmt_wf_collection*)(storage->get_data(DATA_STRUCT::PMT_WF_COLLECTION));
00044   clear_event();
00045 
00046   if(!(data->size()))
00047     return true;
00048 
00049   _event_id=data->event_id();
00050 
00051   PMT::word_t rel_frame=0;
00052   PMT::word_t rel_slice=0;
00053   PMT::word_t wf_length=0;
00054 
00055   // 
00056   // Loop over event (collection of channel waveforms) to first
00057   // identify the maximum length of waveform vector to be stored.
00058   //
00059   std::set<size_t> skip_index; // a set of index in pmt_wf_collection array to be skipped
00060   for(size_t i=0; i<data->size(); ++i){
00061 
00062     const pmt_waveform* pmt_data = &(data->at(i));
00063 
00064     if(pmt_data->size()<1) {
00065       skip_index.insert(i);
00066       Message::send(MSG::ERROR,__FUNCTION__,
00067             Form("Detected 0-length waveform (Event=%d ... Ch.=%d)! Skipping.",data->event_id(),pmt_data->channel_number()));
00068       continue;
00069     }
00070 
00071     if(!(_ref_frame) || _ref_frame>pmt_data->channel_frame_id())
00072       _ref_frame = pmt_data->channel_frame_id();
00073     
00074     rel_frame = pmt_data->channel_frame_id() - _ref_frame;
00075     rel_slice = rel_frame * _frame_width + pmt_data->timeslice();
00076 
00077     if(!(_ref_slice) || _ref_slice>rel_slice)
00078       _ref_slice=rel_slice;
00079     
00080     if(!(wf_length) || wf_length<(rel_slice+pmt_data->size()))
00081       wf_length=rel_slice+pmt_data->size();
00082 
00083     if(_channels.find(pmt_data->channel_number())==_channels.end())
00084       _channels.insert(pmt_data->channel_number());
00085 
00086   }
00087 
00088   //
00089   // Loop over again. This time create a channel waveform container
00090   // and store waveform data inside. By default set all waveform
00091   // vector contents to be 0. We write out all elements, whether data
00092   // exists or not, for the time span of the first and last received
00093   // adc count among all channels.
00094   //
00095   for(size_t i=0; i<data->size(); ++i){
00096 
00097     if(skip_index.find(i)!=skip_index.end()) continue;
00098 
00099     const pmt_waveform* pmt_data = &(data->at(i));
00100     UInt_t ch=pmt_data->channel_number();    
00101 
00102     if(_wf_map.find(ch)==_wf_map.end())
00103       _wf_map[ch]=PMT::ch_waveform_t(wf_length-_ref_slice+1,0);
00104 
00105     for(size_t j=0; j<pmt_data->size(); ++j){
00106 
00107       rel_frame = pmt_data->channel_frame_id() - _ref_frame;
00108       rel_slice = rel_frame * _frame_width + pmt_data->timeslice() + j;
00109       
00110       _wf_map[ch][rel_slice - _ref_slice] = pmt_data->at(j);
00111     }
00112   }
00113   
00114   // 
00115   // Summary report if verbosity is set
00116   //
00117   if(_verbosity[MSG::INFO]){
00118     sprintf(_buf,"Event = %-4d ... %-2zd channels read out",data->event_id(),_channels.size());
00119     Message::send(MSG::INFO,__FUNCTION__,_buf);
00120   }
00121 
00122   return true;
00123 }
00124 
00125 const PMT::ch_waveform_t* reco_wf::get_ch_waveform(UInt_t ch) {
00126   
00127   if(_wf_map.find(ch)==_wf_map.end())
00128     return 0;
00129   else
00130     return &(_wf_map[ch]);
00131 }
00132 
00133 
00134 bool reco_wf::finalize(){
00135 
00136   return true;
00137 
00138 }
00139 
00140 TH2D* reco_wf::get_histo(){
00141 
00142   if(_wf_histo)
00143     return _wf_histo;
00144   
00145   if(_wf_map.size()==0) return 0;
00146 
00147   // Create a histogram
00148   int ctr=0;
00149   for(std::set<UInt_t>::const_iterator iter(_channels.begin());
00150       iter!=_channels.end();
00151       ++iter){
00152 
00153     PMT::ch_waveform_t* wf=&(_wf_map[(*iter)]);
00154     
00155     if(!(_wf_histo)){
00156       // If histogram does not yet exist, create one.
00157       // This hsould be called in the 1st loop.
00158 
00159       _wf_histo=new TH2D(Form("hWF_Event%05d", _event_id),
00160              Form("All waveform combined for event %-5d; ; Time-slice; ADC",_event_id),
00161              _channels.size(), 0, _channels.size(),                  // X-axis = channels
00162              wf->size(), _ref_slice, (_ref_slice+wf->size()) // Y-axis = time slice
00163              );
00164     }
00165     
00166     ctr++;
00167     
00168     for(unsigned int index=0; index<wf->size(); index++)
00169       
00170       _wf_histo->SetBinContent(ctr,index+1,(double)(wf->at(index)));
00171 
00172     _wf_histo->GetXaxis()->SetBinLabel(ctr,Form("Ch. %d",(*iter)));
00173   }
00174 
00175   if(_wf_histo){
00176     _wf_histo->GetXaxis()->SetTicks("-");
00177     _wf_histo->GetXaxis()->LabelsOption("h");
00178   }
00179 
00180   return _wf_histo;
00181 
00182 }
00183 
00184 #endif

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