00001 #include "TMuonEvent.h"
00002 #include "AlcapExcept.h"
00003 #include <iostream>
00004 #include <iterator>
00005 #include "debug_tools.h"
00006 using std::cout;
00007 using std::endl;
00008
00009 namespace {
00010 IDs::channel MuSc(IDs::kMuSc,IDs::kNotApplicable);
00011 IDs::channel MuScA(IDs::kMuScA,IDs::kNotApplicable);
00012 }
00013
00014 MAKE_EXCEPTION(TMuonEvent,Base)
00015 MAKE_EXCEPTION(OutOfRange,TMuonEvent)
00016 MAKE_EXCEPTION(EndOfWindowBeforeStart,TMuonEvent)
00017 MAKE_EXCEPTION(InvalidSource,TMuonEvent)
00018
00019 const TDetectorPulse* TMuonEvent::GetPulse(const IDs::source& source, int index)const{
00020 SourceDetPulseMap::const_iterator i_source=fPulseLists.find(source);
00021 if(i_source==fPulseLists.end()) return NULL;
00022 if(index>(int)i_source->second.size() || index<0) throw Except::OutOfRange();
00023 const TDetectorPulse* pulse= *(i_source->second.begin()+index);
00024 return pulse;
00025 }
00026
00027 void TMuonEvent::AddPulse(const IDs::source& source, TDetectorPulse* pulse){
00028 fPulseLists[source].push_back(pulse);
00029 }
00030
00031 void TMuonEvent::AddPulses(const IDs::source& source,
00032 DetectorPulseList::const_iterator start,
00033 DetectorPulseList::const_iterator stop){
00034 if(stop-start <0) throw Except::EndOfWindowBeforeStart();
00035 for(DetectorPulseList::const_iterator i_p=start; i_p!=stop; ++i_p){
00036 if( (*i_p)->IsGood()) fPulseLists[source].push_back(*i_p);
00037 }
00038 }
00039
00040 const IDs::source& TMuonEvent::GetSource(int n)const{
00041 if(n>(int)fPulseLists.size() || n<0) throw Except::OutOfRange();
00042 SourceDetPulseMap::const_iterator i_source=fPulseLists.begin();
00043 std::advance(i_source,n);
00044 return i_source->first;
00045 }
00046
00047 int TMuonEvent::GetSourceIndex(const IDs::channel& ch, int start)const{
00048 if(start>(int)fPulseLists.size() || start<0) throw Except::OutOfRange();
00049 SourceDetPulseMap::const_iterator i_source=fPulseLists.begin();
00050 for(std::advance(i_source,start);
00051 i_source!=fPulseLists.end(); ++i_source){
00052 if(i_source->first.matches(ch))
00053 return std::distance( fPulseLists.begin(),i_source);
00054 }
00055 return -1;
00056 }
00057
00058 int TMuonEvent::GetFirstSourceIndex(const IDs::channel& ch)const{
00059 for( SourceDetPulseMap::const_iterator i_source=fPulseLists.begin();
00060 i_source!=fPulseLists.end(); ++i_source){
00061 if(i_source->first.matches(ch))
00062 return std::distance( fPulseLists.begin(),i_source);
00063 }
00064 return -1;
00065 }
00066
00067 int TMuonEvent::GetLastSourceIndex(const IDs::channel& ch)const{
00068 for( SourceDetPulseMap::const_reverse_iterator i_source=fPulseLists.rbegin();
00069 i_source!=fPulseLists.rend(); ++i_source){
00070 if(i_source->first.matches(ch))
00071 return std::distance( i_source,fPulseLists.rend());
00072 }
00073 return -1;
00074 }
00075
00076
00077
00078 int TMuonEvent::TotalNumPulses()const{
00079 int size=0;
00080 for(SourceDetPulseMap::const_iterator i_source=fPulseLists.begin();
00081 i_source!=fPulseLists.end(); ++i_source){
00082 size+=i_source->second.size();
00083 }
00084 return size;
00085 }
00086
00087 int TMuonEvent::NumPulses(const IDs::channel& channel)const{
00088 int size=0;
00089 for(SourceDetPulseMap::const_iterator i_source=fPulseLists.begin();
00090 i_source!=fPulseLists.end(); ++i_source){
00091 if(i_source->first==channel) size+=i_source->second.size();
00092 }
00093 return size;
00094 }
00095
00096 int TMuonEvent::NumPulses(const IDs::source& source)const{
00097 SourceDetPulseMap::const_iterator i_source=fPulseLists.find(source);
00098 if(i_source==fPulseLists.end()) return 0;
00099 return i_source->second.size();
00100 }
00101
00102 bool TMuonEvent::HasMuonHit()const{
00103 return NumPulses(MuSc);
00104 }
00105
00106 bool TMuonEvent::HasMuonPileup()const{
00107 return NumPulses(MuSc)>1 ;
00108 }
00109
00110 bool TMuonEvent::WasEarlyInEvent()const{
00111 DEBUG_PRINT("TMuonEvent::WasEarlyInEvent is not yet implemented");
00112 return true;
00113 }
00114
00115 bool TMuonEvent::WasLateInEvent(double event_length, double event_uncertainty)const{
00116 DEBUG_PRINT("TMuonEvent::WasLateInEvent is not yet implemented");
00117 return true;
00118 }
00119
00120 DetectorPulseList::const_iterator TMuonEvent::BeginPulses(const IDs::source& detector)const{
00121 if(NumPulses(detector)==0) return DetectorPulseList::const_iterator();
00122 return fPulseLists.at(detector).begin();
00123 }
00124 DetectorPulseList::const_iterator TMuonEvent::EndPulses(const IDs::source& detector)const{
00125 if(NumPulses(detector)==0) return DetectorPulseList::const_iterator();
00126 return fPulseLists.at(detector).end();
00127 }