Newer
Older
TB_Chris / TbUT / src / .svn / text-base / TbUTCmsPerBeetle.cpp.svn-base
  1. //
  2. // Created by ja on 8/4/15.
  3. //
  4.  
  5. #include "TbUTCmsPerBeetle.h"
  6. #include <iostream>
  7. #include <cmath>
  8.  
  9. using namespace TbUT;
  10. using namespace std;
  11.  
  12. CmsPerBeetle::CmsPerBeetle(IChannelMaskProvider& p_masksProvider,double p_hitThreshold):
  13. m_masksProvider(p_masksProvider),
  14. m_channelNumber(RawData<>::getnChannelNumber()),
  15. m_hitThreshold(p_hitThreshold)
  16. {
  17. cout<<"create correlation per beetle"<<endl;
  18. initializeCorrectionMap();
  19. }
  20.  
  21. void CmsPerBeetle::initializeCorrectionMap()
  22. {
  23. int channelPerBeetle=32;
  24. for (int channel=0;channel<m_channelNumber;channel+=channelPerBeetle)
  25. m_correctionPerBeetle.insert(std::make_pair(channel,0));
  26. }
  27.  
  28. void CmsPerBeetle::processEvent(RawData<>* p_data, RawData<double> **p_output)
  29. {
  30. calculateCorrection(p_data);
  31. removeCM(p_data,p_output);
  32. }
  33.  
  34. void CmsPerBeetle::calculateCorrection(RawData<>* p_inputData)
  35. {
  36. int channelPerBeetle=32;
  37. for(auto& mapIt : m_correctionPerBeetle)
  38. {
  39. int usedChannels=0;
  40. for(int channel=mapIt.first;channel<mapIt.first+channelPerBeetle;channel++)
  41. {
  42. auto signal=p_inputData->getSignal(channel);
  43. if(!m_masksProvider.isMasked(channel) && abs(signal) <m_hitThreshold){
  44. mapIt.second+=signal;
  45. usedChannels++;
  46. }
  47. }
  48. if(usedChannels) mapIt.second/=static_cast<double>(usedChannels);
  49. }
  50. }
  51.  
  52. void CmsPerBeetle::removeCM(RawData<>* p_data, RawData<double> **p_output)
  53. {
  54. int channelPerBeetle=32;
  55. for(auto& mapIt : m_correctionPerBeetle)
  56. {
  57. for(int channel=mapIt.first;channel<mapIt.first+channelPerBeetle;channel++)
  58. {
  59. if(m_masksProvider.isMasked(channel)){
  60. double signalMaskedChannel=0;
  61. (*p_output)->setSignal(signalMaskedChannel);
  62. }else{
  63. double l_channelSignal=p_data->getSignal(channel)-mapIt.second;
  64. (*p_output)->setSignal(l_channelSignal);
  65. }
  66. }
  67.  
  68. }
  69.  
  70. }
  71.