00001
00002
00003
00004
00005
00006
00007
00009
00010 #include <cassert>
00011
00012 #include "CandChop/AlgChopListPerfectMC.h"
00013 #include "CandChop/CandChopListHandle.h"
00014 #include "CandChop/DigitVector.h"
00015
00016
00017 #include "Algorithm/AlgConfig.h"
00018 #include "Algorithm/AlgFactory.h"
00019 #include "Algorithm/AlgHandle.h"
00020 #include "CandData/CandHeader.h"
00021 #include "CandData/CandRecord.h"
00022 #include "CandDigit/CandDigitHandle.h"
00023 #include "CandDigit/CandDigitListHandle.h"
00024 #include "CandDigit/CandDigitList.h"
00025 #include "Candidate/CandContext.h"
00026 #include "MessageService/MsgService.h"
00027 #include "MinosObjectMap/MomNavigator.h"
00028 #include "RawData/RawHeader.h"
00029 #include "RawData/RawRecord.h"
00030 #include "RawData/RawDigitDataBlock.h"
00031 #include "UgliGeometry/UgliGeomHandle.h"
00032 #include "UgliGeometry/UgliStripHandle.h"
00033 #include "Validity/VldContext.h"
00034 #include "Calibrator/Calibrator.h"
00035 #include "DataUtil/Truthifier.h"
00036
00037 ClassImp(AlgChopListPerfectMC)
00038 CVSID( " $Id: AlgChopListPerfectMC.cxx,v 1.3 2007/11/11 08:26:13 rhatcher Exp $ ");
00039
00040 struct compareDigitTimes : public binary_function<const CandDigitHandle&, const CandDigitHandle&, bool> {
00041 bool operator()(const CandDigitHandle& d1, const CandDigitHandle& d2) {
00042 return (d1.GetTime() < d2.GetTime());
00043 }
00044 };
00045
00046 const RawChannelId kQieRcid(Detector::kNear,ElecType::kQIE,0,0,false,false);
00047
00048
00049
00050 AlgChopListPerfectMC::AlgChopListPerfectMC()
00051 {
00055
00056 }
00057
00058
00059 AlgChopListPerfectMC::~AlgChopListPerfectMC()
00060 {
00061 }
00062
00063
00064
00065
00066 void AlgChopListPerfectMC::RunAlg(AlgConfig& ,
00067 CandHandle &candHandle,
00068 CandContext &candContext)
00069 {
00073
00074 assert(candHandle.InheritsFrom("CandChopListHandle"));
00075 CandChopListHandle &sliceList = dynamic_cast<CandChopListHandle &>(candHandle);
00076
00077 assert(candContext.GetDataIn());
00078
00079 if (!(candContext.GetDataIn()->InheritsFrom("CandDigitListHandle"))) {
00080 MSG("Chop",Msg::kWarning ) << "Data into AlgChopListPerfectMC is not a digit list." << std::endl;
00081 }
00082
00083 const CandDigitListHandle *cdlh_ptr =
00084 dynamic_cast<const CandDigitListHandle*>(candContext.GetDataIn());
00085
00086 const MomNavigator *mom = candContext.GetMom();
00087 RawRecord *rr = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord"));
00088 if (!rr) {
00089 MSG("Chop", Msg::kWarning) << "No RawRecord in MOM." << endl;
00090 return;
00091 }
00092 const RawDigitDataBlock *rddb = dynamic_cast<const RawDigitDataBlock *>
00093 (rr->FindRawBlock("RawDigitDataBlock"));
00094 if (!rddb) {
00095 MSG("Chop", Msg::kWarning) << "No RawDigitDataBlock in RawRecord." << endl;
00096 return;
00097 }
00098
00099
00100 AlgFactory &af = AlgFactory::GetInstance();
00101 AlgHandle ah = af.GetAlgHandle("AlgChop","default");
00102 CandContext cxx(this,candContext.GetMom());
00103
00104 const VldContext &context = *(candContext.GetCandRecord()->GetVldContext());
00105 if(context.GetDetector() != Detector::kNear)
00106 MSG("Chop",Msg::kError) << "Running the PerfectMC algorithm on FD data is a no-no!" << endl;
00107
00108
00109 UgliGeomHandle ugli(context);
00110
00111
00112
00113
00114 DigitVector digits(cdlh_ptr);
00115 UInt_t ndigits = digits.size();
00116 UInt_t nslice = 0;
00117
00118 const Truthifier& truth = Truthifier::Instance(candContext.GetMom());
00119 std::vector<Int_t> neutrinos = truth.GetListOfNeutrinoIndecies();
00120
00121 for(UInt_t inu=0; inu < neutrinos.size(); inu++) {
00122
00123 DigitVector slc;
00124
00125
00126 for(UInt_t idig = 0; idig<ndigits; idig++) {
00127 float frac = truth.IsDigitFromNeutrino(neutrinos[inu],digits[idig]);
00128 if(frac>0.20)
00129 slc.push_back(digits[idig]);
00130 }
00131 if(slc.size()>0) {
00132
00133 cxx.SetDataIn(&(slc));
00134 CandDigitListHandle sliceHandle = CandDigitList::MakeCandidate(ah,cxx);
00135 sliceHandle.SetName(Form("Chop %d",nslice++));
00136 sliceHandle.SetTitle(Form("Neutrino %d StdHepIndex %d",inu,neutrinos[inu]));
00137 sliceList.AddDaughterLink(sliceHandle);
00138 }
00139 }
00140
00141 }
00142
00143
00144 void AlgChopListPerfectMC::Trace(const char * ) const
00145 {
00146 }
00147