00001
00002
00003
00004
00005
00006
00007
00009
00010 #include <assert.h>
00011
00012 #include "Algorithm/AlgConfig.h"
00013 #include "Candidate/CandContext.h"
00014 #include "CandData/CandHeader.h"
00015 #include "CandFitShowerEM/AlgFitShowerEM.h"
00016 #include "CandFitShowerEM/CandFitShowerEMHandle.h"
00017 #include "CandShowerEM/CandShowerEMHandle.h"
00018 #include "Conventions/Mphysical.h"
00019 #include "Conventions/Munits.h"
00020 #include "Conventions/PlaneView.h"
00021 #include "MessageService/MsgService.h"
00022 #include "MessageService/MsgFormat.h"
00023 #include "MinosObjectMap/MomNavigator.h"
00024 #include "Navigation/NavKey.h"
00025 #include "Navigation/NavSet.h"
00026 #include "RecoBase/CandSliceHandle.h"
00027 #include "RecoBase/CandStripHandle.h"
00028 #include "RecoBase/CandTrackHandle.h"
00029 #include "RecoBase/ArrivalTime.h"
00030 #include "RecoBase/PropagationVelocity.h"
00031 #include "RecoBase/LinearFit.h"
00032 #include "UgliGeometry/UgliGeomHandle.h"
00033 #include "CandFitShowerEM/FitterEM.h"
00034
00035 ClassImp(AlgFitShowerEM)
00036
00037
00038 CVSID("$Id: AlgFitShowerEM.cxx,v 1.3 2007/11/11 08:30:04 rhatcher Exp $");
00039
00040
00041 AlgFitShowerEM::AlgFitShowerEM()
00042 {
00043 }
00044
00045
00046 AlgFitShowerEM::~AlgFitShowerEM()
00047 {
00048 MSG("FitShowerEM",Msg::kDebug) << "Deleting AlgFitShowerEM" << endl;
00049 }
00050
00051
00052 void AlgFitShowerEM::RunAlg(AlgConfig &ac, CandHandle &ch,
00053 CandContext &cx)
00054 {
00055 MSG("Alg", Msg::kDebug) << "Starting AlgFitShowerEM::RunAlg()" << endl;
00056
00057
00058 assert(ch.InheritsFrom("CandFitShowerEMHandle"));
00059 CandFitShowerEMHandle &cfsemh = dynamic_cast<CandFitShowerEMHandle &>(ch);
00060
00061 cfsemh.SetPass(0);
00062
00063 assert(cx.GetDataIn());
00064 assert(cx.GetDataIn()->InheritsFrom("TObjArray"));
00065
00066 const CandShowerEMHandle *shower0 = 0;
00067 const TObjArray *tclist = 0;
00068 const TObjArray *cxin = dynamic_cast<const TObjArray *>(cx.GetDataIn());
00069 for (Int_t i=0; i<=cxin->GetLast(); i++) {
00070 TObject *tobj = cxin->At(i);
00071 if (tobj->InheritsFrom("CandShowerEMHandle")) {
00072 shower0 = dynamic_cast<CandShowerEMHandle*>(tobj);
00073 }
00074 if (tobj->InheritsFrom("TObjArray")) {
00075 tclist = dynamic_cast<TObjArray*>(tobj);
00076 }
00077 }
00078
00079 if(!shower0) return;
00080
00081 fVldContext = const_cast<VldContext*>(shower0->GetVldContext());
00082 assert(fVldContext);
00083 fDetector = fVldContext->GetDetector();
00084 UgliGeomHandle ugh(*fVldContext);
00085
00086 MSG("FitShowerEM", Msg::kDebug)
00087 << "event number " << shower0->GetCandSlice()->GetCandRecord()
00088 ->GetCandHeader()->GetSnarl() << endl;
00089
00090 Double_t theEnergy = shower0->GetEnergy()/2150.;
00091 Double_t vtx[3] = {0};
00092 vtx[0] = shower0->GetVtxU();
00093 vtx[1] = shower0->GetVtxV();
00094 vtx[2] = shower0->GetVtxZ();
00095 Double_t duds = shower0->GetDirCosU();
00096 Double_t dvds = shower0->GetDirCosV();
00097 Double_t dzds = shower0->GetDirCosZ();
00098
00099 Double_t stepSize[6];
00100 stepSize[0] = ac.GetDouble("EnergyStep");
00101 stepSize[1] = ac.GetDouble("UVtxStep");
00102 stepSize[2] = ac.GetDouble("VVtxStep");
00103 stepSize[3] = ac.GetDouble("ZVtxStep");
00104 stepSize[4] = ac.GetDouble("UAngStep");
00105 stepSize[5] = ac.GetDouble("VAngStep");
00106
00107 Int_t nSteps[6];
00108 nSteps[0] = ac.GetInt("EnergyNSteps");
00109 nSteps[1] = ac.GetInt("UVtxNSteps");
00110 nSteps[2] = ac.GetInt("VVtxNSteps");
00111 nSteps[3] = ac.GetInt("ZVtxNSteps");
00112 nSteps[4] = ac.GetInt("UAngNSteps");
00113 nSteps[5] = ac.GetInt("VAngNSteps");
00114
00115 CopyFromShowerEM(shower0,cfsemh);
00116
00117 int nstp = shower0->GetNStrip();
00118 CandStripHandleItr cshi(shower0->GetDaughterIterator());
00119
00120 FitterEM *ffitterEM = new FitterEM(nstp,cshi);
00121 ffitterEM->SetInputParams(theEnergy,vtx,duds/dzds,dvds/dzds);
00122 ffitterEM->SetStepSize(stepSize);
00123 ffitterEM->SetNSteps(nSteps);
00124 ffitterEM->DoFit();
00125
00126 if(ffitterEM->Pass()){
00127 MSG("FitShowerEM",Msg::kDebug) << "Passed" << endl;
00128 cfsemh.SetPass(true);
00129 cfsemh.SetChi2(ffitterEM->GetChi2());
00130 cfsemh.SetNDOF(ffitterEM->GetNDF());
00131 Double_t *fitparms = ffitterEM->GetFittedPars();
00132 cfsemh.SetMomentum(fitparms[0]);
00133 cfsemh.SetEnergy(fitparms[0]);
00134 cfsemh.SetVtxU(fitparms[1]);
00135 cfsemh.SetVtxV(fitparms[2]);
00136 cfsemh.SetVtxZ(fitparms[3]);
00137 cfsemh.SetDirCosU(fitparms[4]);
00138 cfsemh.SetDirCosV(fitparms[5]);
00139 cfsemh.SetNIterate(ffitterEM->GetNIterations());
00140 MSG("FitShowerEM",Msg::kDebug) << "with Chi2/NDOF = "
00141 << ffitterEM->GetChi2()
00142 << "/" << ffitterEM->GetNDF() << endl;
00143 MSG("FitShowerEM",Msg::kDebug) << "and after "
00144 << ffitterEM->GetNIterations()
00145 << " iterations" << endl;
00146 }
00147 else{
00148 MSG("FitShowerEM",Msg::kDebug) << "Failed" << endl;
00149 cfsemh.SetPass(false);
00150 cfsemh.SetChi2(-1);
00151 cfsemh.SetNDOF(-1);
00152 cfsemh.SetNIterate(ffitterEM->GetNIterations());
00153 }
00154 delete ffitterEM;
00155
00156 return;
00157 }
00158
00159 void AlgFitShowerEM::CopyFromShowerEM(const CandShowerEMHandle *shower0,
00160 CandFitShowerEMHandle &cfsemh){
00161
00162 cfsemh.SetVtxPlane(shower0->GetVtxPlane());
00163 cfsemh.SetVtxZ(shower0->GetVtxZ());
00164 cfsemh.SetVtxU(shower0->GetVtxU());
00165 cfsemh.SetVtxV(shower0->GetVtxV());
00166 cfsemh.SetVtxT(shower0->GetVtxT());
00167 cfsemh.SetDirCosU(shower0->GetDirCosU());
00168 cfsemh.SetDirCosV(shower0->GetDirCosV());
00169 cfsemh.SetDirCosZ(shower0->GetDirCosZ());
00170
00171 cfsemh.SetEigenVectors(shower0->GetEigenVectors());
00172 cfsemh.SetEigenValues(shower0->GetEigenValues());
00173 cfsemh.SetAvgDev(shower0->GetAvgDev());
00174 cfsemh.SetOutPH(shower0->GetOutPH());
00175 cfsemh.SetShwStatus(shower0->GetShwStatus());
00176 cfsemh.SetEnergy(shower0->GetEnergy());
00177
00178 CandStripHandleItr stripItr(shower0->GetDaughterIterator());
00179 while (CandStripHandle *strip = stripItr()) {
00180 cfsemh.AddDaughterLink(*strip);
00181 }
00182
00183
00184
00185 }