00001 #include "MakeSiliconEvents.h"
00002 #include "RegisterModule.inc"
00003 #include "TGlobalData.h"
00004 #include "TSetupData.h"
00005 #include "ModulesOptions.h"
00006 #include "definitions.h"
00007 #include "TSiliconEvent.h"
00008 #include "TMuonEvent.h"
00009
00010 #include <iostream>
00011 using std::cout;
00012 using std::endl;
00013
00014 extern SourceDetPulseMap gDetectorPulseMap;
00015 extern MuonEventList gMuonEvents;
00016
00017 MakeSiliconEvents::MakeSiliconEvents(modules::options* opts):
00018 BaseModule("MakeSiliconEvents",opts,false),
00019 fSiWindow(opts->GetDouble("si_window",100)){
00020 }
00021
00022 MakeSiliconEvents::~MakeSiliconEvents(){
00023 }
00024
00025 int MakeSiliconEvents::BeforeFirstEntry(TGlobalData* gData,const TSetupData *setup){
00026
00027 for(int i=0;i<LR::kNum;i++){
00028 for(int ch=0;ch<Ch::kNum;ch++){
00029 fSourceList[i][ch]=GetTDPSource(Form("Si%s%s",LR::str(i),Ch::str(ch)));
00030 }
00031 }
00032 return 0;
00033 }
00034
00035 int MakeSiliconEvents::ProcessEntry(TGlobalData* gData,const TSetupData *setup){
00036
00037
00038 TSiliconEvent si_hit;
00039 for(MuonEventList::iterator i_tme=gMuonEvents.begin();
00040 i_tme!=gMuonEvents.end(); ++i_tme){
00041 TMuonEvent* tme=*i_tme;
00042
00043 for(int i_side=0;i_side <2; ++i_side){
00044
00045 for(DetectorPulseList::const_iterator i_Si2=tme->BeginPulses(fSourceList[i_side][Ch::k2]);
00046 i_Si2!=tme->EndPulses(fSourceList[i_side][Ch::k2]); ++i_Si2){
00047 si_hit.Reset();
00048 double thick_time=(*i_Si2)->GetTime();
00049 double E_thick=(*i_Si2)->GetEnergy(TDetectorPulse::kSlow);
00050 si_hit.SetThick(E_thick,thick_time);
00051 for(int i=0; i<4;++i){
00052 for(DetectorPulseList::const_iterator i_thin=tme->BeginPulses(fSourceList[i_side][i]);
00053 i_thin!=tme->EndPulses(fSourceList[i_side][i]); ++i_thin){
00054 const TDetectorPulse* pulse=*i_thin;
00055 if(!pulse->IsGood())continue;
00056 double time=pulse->GetTime(TDetectorPulse::kFast);
00057 if( time > thick_time +fSiWindow) break;
00058 if( time < thick_time -fSiWindow) continue;
00059 si_hit.AddThin(i+1,pulse->GetEnergy(TDetectorPulse::kSlow));
00060 }
00061 }
00062 tme->InsertSiliconEvent((TMuonEvent::LeftRight_t) i_side,si_hit);
00063 }
00064 }
00065 }
00066 return 0;
00067 }
00068
00069 int MakeSiliconEvents::AfterLastEntry(TGlobalData* gData,const TSetupData *setup){
00070 return 0;
00071 }
00072
00073 const IDs::source& MakeSiliconEvents::GetTDPSource(const std::string& ch ){
00074 IDs::channel chan(ch);
00075 SourceDetPulseMap::const_iterator i_so=gDetectorPulseMap.begin();
00076 while(i_so!=gDetectorPulseMap.end() && !(i_so->first==chan)) ++i_so;
00077 if(i_so==gDetectorPulseMap.end()){
00078 static IDs::source invalid(IDs::kErrorDetector, IDs::kErrorSlowFast, "","");
00079 return invalid;
00080 }
00081 return i_so->first;
00082 }
00083
00084 const char* Ch::str(Ch::Type e){
00085 switch(e){
00086 case Ch::k1_1 : return "1_1";
00087 case Ch::k1_2 : return "1_2";
00088 case Ch::k1_3 : return "1_3";
00089 case Ch::k1_4 : return "1_4";
00090 case Ch::k2 : return "2";
00091 case Ch::kNum : return "NumThinThick";
00092 }
00093 return "-------";
00094 }
00095
00096 const char* LR::str(LR::Type e, bool big){
00097 switch(e){
00098 case LR::kLeft: return big?"Left":"L";
00099 case LR::kRight: return big?"Right":"R";
00100 case LR::kNum: return "NumLR";
00101 }
00102 return "-------";
00103 }
00104
00105
00106
00107 ALCAP_REGISTER_MODULE(MakeSiliconEvents, si_window);