00001 #include "GfxMCVecList.h"
00002 #include "GfxMCVecListCfg.h"
00003 #include "GfxProxy.h"
00004 #include "ViewState.h"
00005 #include "GfxMCVec.h"
00006 #include <Midad/Base/Mint.h>
00007 #include "GfxMCVecListMenu.h"
00008
00009 #include <MinosObjectMap/MomNavigator.h>
00010 #include <Record/SimSnarlRecord.h>
00011 #include <Record/RecArrayAllocator.h>
00012 #include <TParticle.h>
00013 #include <TClonesArray.h>
00014 #include <DataUtil/TruthHelper.h>
00015 #include <RecoBase/CandSliceHandle.h>
00016 #include <string>
00017 using namespace std;
00018
00019
00020
00021 #include <sigc++/sigc++.h>
00022 #include <sigc++/class_slot.h>
00023 using namespace SigC;
00024
00025
00026 #include <Buttons.h>
00027
00028 static GfxProxy<GfxMCVecList>
00029 gsGfxMCVecListProxy("MCVecList", new GfxMCVecListMenu());
00030
00031 GfxMCVecList::GfxMCVecList()
00032 :fCfg(0)
00033 ,fHideVecs(false)
00034 {
00035 fCfg = new GfxMCVecListCfg();
00036 fCfg->modified_signal.connect
00037 (SigC::slot_class(*this,&GfxMCVecList::ReConfigure));
00038
00039 RecArrayAllocator& a = RecArrayAllocator::Instance();
00040 fVecsCA = a.GetArray("GfxMCVec");
00041 }
00042
00043 GfxMCVecList::~GfxMCVecList()
00044 {
00045 RecArrayAllocator& a = RecArrayAllocator::Instance();
00046 if (fVecsCA) { a.ReleaseArray(fVecsCA); fVecsCA = 0; }
00047 }
00048
00049
00050 void GfxMCVecList::Init(PageDisplay& pd, EVD& mp)
00051 {
00052
00053 fEVD= ∓
00054 fPageDisplay= &pd;
00055 ViewState* vs = this->GetViewState();
00056 vs->spatial_metric.connect(slot_class(*this,&GfxMCVecList::ReConfigure));
00057 }
00058
00059
00060 void GfxMCVecList::Configure(Mint& mint)
00061 {
00062
00063 if (fVecs.size()) this->ClearVecList();
00064 if (fHideVecs) return;
00065 const MomNavigator* mom = mint.GetJint().GetMom();
00066 if (!mom) return;
00067
00068 SimSnarlRecord* ssr =
00069 dynamic_cast<SimSnarlRecord*>(mom->GetFragment("SimSnarlRecord"));
00070 if (!ssr) return;
00071 const TClonesArray* ctca =
00072 dynamic_cast<const TClonesArray*>
00073 (ssr->FindComponent("TClonesArray","StdHep"));
00074 if (!ctca) return;
00075
00076 float evntP=0;
00077 int ind, siz = ctca->GetEntriesFast();
00078 for (ind=0; ind < siz; ++ind) {
00079 TParticle* part = dynamic_cast<TParticle*>((*ctca)[ind]);
00080 if (!part) {
00081 cerr << "Non particle: " << (*ctca)[ind]->GetName() << endl;
00082 continue;
00083 }
00084
00085 if(part->P()>evntP && part->P()<100.0 )evntP=part->P();
00086 }
00087 const CandSliceHandle * slc = fEVD->GetCandSlice();
00088 Int_t neuId= -1;
00089 Int_t nextneuId = -1;
00090 if(slc){
00091 CandSliceHandle slch = *slc;
00092 TruthHelper truthHelp(mom);
00093 neuId=truthHelp.GetBestSliceNeuMatch(slch);
00094 nextneuId=truthHelp.GetNextNeuId(neuId);
00095 }
00096 CandEventHandle * ev = fEVD->GetCandEvent();
00097 if(ev){
00098 TruthHelper truthHelp(mom);
00099 neuId=truthHelp.GetBestEventNeuMatch(*ev);
00100 nextneuId=truthHelp.GetNextNeuId(neuId);
00101 }
00102 for (ind=0; ind < siz; ++ind) {
00103 TParticle* part = dynamic_cast<TParticle*>((*ctca)[ind]);
00104 if (!part) {
00105 cerr << "Non particle: " << (*ctca)[ind]->GetName() << endl;
00106 continue;
00107 }
00108 if(neuId<0 || (ind >=neuId && ind < nextneuId)){
00109 if(abs(part->GetPdgCode())<19 ||
00110 abs(part->GetPdgCode())==211 ||
00111 abs(part->GetPdgCode())==2212
00112 ){
00113 int last = fVecsCA->GetLast()+1;
00114 new ((*fVecsCA)[last]) GfxMCVec(*part,evntP,*this);
00115 GfxMCVec* gs = dynamic_cast<GfxMCVec*>(fVecsCA->UncheckedAt(last));
00116 fVecs.push_back(gs);
00117 }
00118 }
00119 }
00120 this->ReConfigure();
00121
00122 }
00123
00124 void GfxMCVecList::ReConfigure()
00125 {
00126 if (fHideVecs) return;
00127 int ind=0;
00128 for (MCVecList_t::iterator it=fVecs.begin(); it != fVecs.end(); ++it) {
00129 (*it)->Configure(ind);
00130 ind++;
00131 }
00132 }
00133
00134 void GfxMCVecList::ClearVecList()
00135 {
00136 fVecs.clear();
00137 fVecsCA->Clear("C");
00138 }
00139
00140 void GfxMCVecList::Draw(Option_t* option)
00141 {
00142
00143 for (MCVecList_t::iterator it=fVecs.begin(); it != fVecs.end(); ++it) {
00144 (*it)->Draw(option);
00145
00146 }
00147 }
00148
00149 void GfxMCVecList::ExecuteEvent(int event, int , int , GfxMCVec* MCVec)
00150 {
00151 switch (event) {
00152 case kMouseEnter: {
00153 text_info.emit(Form("%s: %s P=%8.6f",
00154 "MCVec", MCVec->GetParticle().GetName(),
00155 MCVec->GetParticle().P()));
00156 break;
00157 }
00158 default:
00159 break;
00160 }
00161
00162 }
00163
00164
00165
00166 void GfxMCVecList::HideVecs(bool hide)
00167 {
00168 fHideVecs = hide;
00169 this->ReConfigure();
00170 if(GetGraphicsView()==GraphicsView::kXY)fEVD->UpdateCanvas();
00171
00172 }