00001 #include <cassert>
00002 #include <cmath>
00003
00004 #include "Algorithm/AlgConfig.h"
00005 #include "Algorithm/AlgFactory.h"
00006 #include "Algorithm/AlgHandle.h"
00007 #include "CandData/CandRecord.h"
00008 #include "MuonRemoval/AlgMergeEvent.h"
00009
00010 #include "CandDigit/CandDigitHandle.h"
00011 #include "CandDigit/CandDigit.h"
00012 #include "CandDigit/CandDigitListHandle.h"
00013
00014 #include "RecoBase/CandTrackListHandle.h"
00015 #include "RecoBase/CandTrackHandle.h"
00016 #include "RecoBase/CandEventListHandle.h"
00017 #include "RecoBase/CandEventHandle.h"
00018 #include "RecoBase/CandStripHandle.h"
00019
00020 #include "Candidate/CandContext.h"
00021 #include "MessageService/MsgService.h"
00022 #include "Validity/VldContext.h"
00023 #include "Validity/VldTimeStamp.h"
00024
00025 #include "RawDigitInfo.h"
00026 #include "TClonesArray.h"
00027
00028 #include "RawData/RawDigit.h"
00029 #include "RawData/RawRecord.h"
00030 #include "RawData/RawDigitDataBlock.h"
00031
00032 #include "PmtMap.h"
00033
00034 CVSID("$Id: AlgMergeEvent.cxx,v 1.3 2006/08/31 23:52:30 cbs Exp $");
00035
00036
00037 ClassImp(AlgMergeEvent)
00038
00039 AlgMergeEvent::AlgMergeEvent()
00040 {
00041 }
00042
00043
00044 AlgMergeEvent::~AlgMergeEvent()
00045 {
00046 }
00047
00048
00049 void AlgMergeEvent::RunAlg(AlgConfig &ac, CandHandle &ch, CandContext &cx)
00050 {
00051
00052
00053 AlgFactory &algfactory = AlgFactory::GetInstance();
00054 const char *tmpcs = 0;
00055 const char *conv_algorithm = 0;
00056 const char *conv_algconfig = 0;
00057
00058 if (ac.Get("RawDigitInfoConvAlgorithm", tmpcs)) conv_algorithm = tmpcs;
00059 if (ac.Get("RawDigitInfoConvConfig", tmpcs)) conv_algconfig = tmpcs;
00060
00061 AlgHandle conv_alg = algfactory.GetAlgHandle(conv_algorithm, conv_algconfig);
00062 CandContext cxx(this, cx.GetMom());
00063 cxx.SetCandRecord(cx.GetCandRecord());
00064 const VldContext *vldc = cx.GetCandRecord()->GetVldContext();
00065
00066 MSG("EvtMrg",Msg::kDebug) << " AlgMergeEvent::RunAlg() " <<endl;
00067 MSG("EvtMrg",Msg::kDebug) << " SubAlg : " <<conv_algorithm<<endl;
00068 MSG("EvtMrg",Msg::kDebug) << " SubAlg Config : " <<conv_algconfig<<endl;
00069
00070
00071 const TObjArray *input = (TObjArray *)(cx.GetDataIn());
00072 assert(input);
00073 TClonesArray* input_mc = dynamic_cast<TClonesArray*>(input->At(0));
00074 CandDigitListHandle* input_digits = dynamic_cast<CandDigitListHandle*>(input->At(1));
00075 RawRecord* rawrecord = dynamic_cast<RawRecord*>(input->At(2));
00076 assert(rawrecord);
00077 RawDigitDataBlock *input_datablock = NULL;
00078 if(rawrecord){
00079 TIter rdbit = rawrecord->GetRawBlockIter();
00080 TObject *tob;
00081 while ((tob = rdbit())) {
00082 if (tob->InheritsFrom("RawDigitDataBlock")) {
00083 input_datablock = (RawDigitDataBlock *) tob;
00084 }
00085 }
00086 }
00087
00088
00089 vector<const RawDigit*> selected_data_digits;
00090 vector<int> selected_data_digits_index;
00091 TIter digititer(input_digits->GetDaughterIterator());
00092 while (CandDigitHandle *digit = dynamic_cast<CandDigitHandle*>(digititer())) {
00093 const RawDigit* raw_digit = input_datablock->At(digit->GetRawDigitIndex());
00094 if(raw_digit!=NULL){
00095 MSG("EvtMrg",Msg::kVerbose) << "Index TDC ADC Plane: "
00096 << digit->GetRawDigitIndex() << " "
00097 << raw_digit->GetTDC() << " "
00098 << raw_digit->GetADC() << " "
00099 << digit->GetPlexSEIdAltL().GetPlane() << endl;
00100 selected_data_digits.push_back(raw_digit);
00101 selected_data_digits_index.push_back(digit->GetRawDigitIndex());
00102 }
00103 else {
00104 MSG("EvtMrg",Msg::kError) << " Failed to find raw digit for reco'd digit " <<endl;
00105 return;
00106 }
00107 }
00108
00109
00110 PmtMap *data_map = new PmtMap();
00111 data_map->BuildMap(selected_data_digits, selected_data_digits_index,vldc);
00112 PmtMap* mc_map = new PmtMap();
00113 mc_map->BuildMap(input_mc);
00114
00115
00116 PmtMap* merged_map = new PmtMap();
00117 merged_map->Merge(*data_map, *mc_map);
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134 delete data_map; data_map = NULL;
00135 delete mc_map; mc_map = NULL;
00136
00137
00138 const unsigned int nchannel = merged_map->channel.size();
00139 for(unsigned int ichannel=0; ichannel<nchannel; ichannel++){
00140 if(merged_map->channel[ichannel].valid!=0){
00141 cxx.SetDataIn(&(merged_map->channel[ichannel]));
00142 CandDigitHandle cdh = CandDigit::MakeCandidate(conv_alg, cxx);
00143 ch.AddDaughterLink(cdh, kFALSE);
00144 }
00145 }
00146
00147
00148 delete merged_map; merged_map = NULL;
00149
00150
00151 CandDigitListHandle &cdlh = dynamic_cast<CandDigitListHandle &>(ch);
00152 cdlh.SetAbsTime(input_digits->GetAbsTime());
00153 cdlh.SetIsSparse(input_digits->GetIsSparse());
00154 }
00155
00156 void AlgMergeEvent::Trace(const char * ) const
00157 {
00158 }