pmtbaseline_ana.cc

Go to the documentation of this file.
00001 #ifndef PMTBASELINE_ANA_CC
00002 #define PMTBASELINE_ANA_CC
00003 
00004 #include "pmtbaseline_ana.hh"
00005 
00006 pmtbaseline_ana::pmtbaseline_ana(){
00007 
00008   _name="pmtbaseline_ana"; 
00009   _fout=0;
00010   reset_cuts();
00011 
00012 }
00013 
00014 void pmtbaseline_ana::reset_cuts() {
00015 
00016   _cut_tstart_reco = std::make_pair(-1,2000);
00017   _cut_tstart   = std::make_pair(-1,2000);
00018   _cut_tend     = std::make_pair(-1,2000);
00019   _cut_amp      = std::make_pair(-1,4096);
00020   _cut_charge   = std::make_pair(-1,4096*2000);
00021   _cut_pedbase  = std::make_pair(-1,4096);
00022   _cut_pedrms   = std::make_pair(0,4096);
00023   _cut_channels = std::make_pair(0,PMT::INVALID_CH);
00024   _cut_event_id = std::make_pair(0,0xffffffff);
00025   _cut_npulse   = std::make_pair(0,0xffffffff);
00026   _cut_sum_charge = std::make_pair(0,4096*2000*PMT::NUM_PMT_CHANNEL);
00027   _cut_sum_peak = std::make_pair(0,4096*PMT::NUM_PMT_CHANNEL);
00028   
00029 }
00030 
00031 bool pmtbaseline_ana::initialize() {
00032 
00033   //
00034   // This function is called in the beggining of event loop
00035   // Do all variable initialization you wish to do here.
00036   // If you need, you have an output root file pointer "_fout".
00037 
00038   _hArray_PedMean.clear();
00039   _hArray_PedRMS.clear();
00040   _hArray_Charge.clear();
00041   _hArray_Peak.clear();
00042 
00043   return true;
00044 }
00045 
00046 bool pmtbaseline_ana::analyze(storage_manager* storage) {
00047 
00048   //
00049   // Do your event-by-event analysis here. This function is called for 
00050   // each event in the loop. You have "data" pointer which contains 
00051   // event-wise data. For a reference of pmt_wf_collection class instance, 
00052   // see the class index in the documentation.
00053   // 
00054   // Example to print out event id on screen...
00055   //
00056   //const pmt_wf_collection* event_wf = (pmt_wf_collection*)(storage->get_data(DATA_STRUCT::WF_COLLECTION));
00057   //std::cout << Form("Event ID: %d",event_wf->event_id()) << std::endl;
00058   //
00059 
00060   const pmt_wf_collection* wfs = (pmt_wf_collection*)(storage->get_data(DATA_STRUCT::PMT_WF_COLLECTION));
00061   const pulse_collection* pulses = (pulse_collection*)(storage->get_data(DATA_STRUCT::PULSE_COLLECTION));
00062 
00063   PMT::word_t event_id = wfs->event_id();
00064   double sum_charge    = pulses->sum_charge();
00065   double sum_peak      = pulses->sum_peak();
00066   UInt_t npulse      = pulses->npulse();
00067 
00068   // Check if this event is in the range of users' interest
00069   if(event_id < _cut_event_id.first || _cut_event_id.second < event_id)
00070     return true;
00071   else if(sum_charge < _cut_sum_charge.first || _cut_sum_charge.second < sum_charge)
00072     return true;
00073   else if(sum_peak < _cut_sum_peak.first || _cut_sum_peak.second < sum_peak)
00074     return true;
00075   else if(npulse < _cut_npulse.first || _cut_npulse.second < npulse)
00076     return true;
00077 
00078   // Loop over pulse collection and fill histograms
00079   for(pulse_collection::const_iterator iter(pulses->begin()); iter!=pulses->end(); ++iter){
00080 
00081     PMT::ch_number_t ch((*iter).channel_number());
00082     double      t_start  = (*iter).start_time();
00083     double      t_end    = (*iter).end_time();
00084     double      charge   = (*iter).charge();
00085     double      amp      = (*iter).pulse_peak();
00086     double      ped_base = (*iter).ped_mean();
00087     double      ped_rms  = (*iter).ped_rms();
00088     double      t_start_reco = (*iter).start_time_reco();
00089 
00090     // Check if this pulse passes the criteria
00091     if(ch < _cut_channels.first || _cut_channels.second < ch)
00092       continue;
00093     if(t_start_reco < _cut_tstart_reco.first || _cut_tstart_reco.second < t_start_reco)
00094       continue;
00095     if(t_start < _cut_tstart.first || _cut_tstart.second < t_start)
00096       continue;
00097     if(t_end < _cut_tend.first || _cut_tend.second < t_end)
00098       continue;
00099     if(charge < _cut_charge.first || _cut_charge.second < charge)
00100       continue;
00101     if(amp < _cut_amp.first || _cut_amp.second < amp)
00102       continue;
00103     if(ped_base < _cut_pedbase.first || _cut_pedbase.second < ped_base)
00104       continue;
00105     if(ped_rms < _cut_pedrms.first || _cut_pedrms.second < ped_rms)
00106       continue;    
00107 
00108     // Check if a histogram of this pulse's channel already exists. If not, add.
00109     if(_hArray_PedMean.find(ch) == _hArray_PedMean.end()) {
00110 
00111       _hArray_PedMean[ch] = new TH1D(Form("hPedMean_Ch%03d",ch),
00112                      Form("Pedestal Mean for Ch %03d; ADC; Entries",ch),
00113                      250,2000,2100);
00114       _hArray_PedRMS[ch]  = new TH1D(Form("hPedRMS_Ch%03d",ch),
00115                      Form("Pedestal RMS for Ch %03d; RMS; Entries",ch),
00116                      50,0,10);
00117       _hArray_Charge[ch]  = new TH1D(Form("hCharge_Ch%03d",ch),
00118                      Form("Integrated Charge Sum for Ch %03d; Charge [arbitrary];Entries",ch),
00119                      600,0,600);
00120       _hArray_Peak[ch]    = new TH1D(Form("hPeak_Ch%03d",ch),
00121                      Form("Max. Amplitude for Ch %03d; Peak Amp. [ADC]; Entries",ch),
00122                      500,0,200);
00123     }
00124     
00125     // Fill histograms
00126     _hArray_PedMean[ch]->Fill(ped_base);
00127     _hArray_PedRMS[ch]->Fill(ped_rms);
00128     _hArray_Charge[ch]->Fill(charge);
00129     _hArray_Peak[ch]->Fill(amp);
00130     
00131   }
00132 
00133   return true;
00134 }
00135 
00136 bool pmtbaseline_ana::finalize() {
00137 
00138   // This function is called at the end of event loop.
00139   // Do all variable finalization you wish to do here.
00140   // If you need, you can store your ROOT class instance in the output
00141   // file. You have an access to the output file through "_fout" pointer.
00142 
00143   _fout->cd();
00144   for(std::map<PMT::ch_number_t,TH1D*>::iterator iter(_hArray_PedMean.begin());
00145       iter!=_hArray_PedMean.end();
00146       ++iter){
00147     
00148     PMT::ch_number_t ch=(*iter).first;
00149 
00150     _hArray_PedMean[ch]->Write();
00151     _hArray_PedRMS[ch]->Write();
00152     _hArray_Charge[ch]->Write();
00153     _hArray_Peak[ch]->Write();
00154 
00155   }
00156 
00157   return true;
00158 }
00159 
00160 #endif

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