Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

NueDisplayModule.cxx

Go to the documentation of this file.
00001 #include "TList.h"
00002 #include "TH2D.h"
00003 #include "THStack.h"
00004 #include "TVector3.h"
00005 #include <deque>
00006 #include "TCanvas.h"
00007 #include "TNtuple.h"
00008 #include "TPad.h"
00009 #include "TEllipse.h"
00010 #include "TText.h"
00011 #include "TLatex.h"
00012 #include "TMarker.h"
00013 #include "TButton.h"
00014 #include "TLine.h"
00015 #include "TLegend.h"
00016 #include "TGraph.h"
00017 #include "TMultiGraph.h"
00018 #include "TPaveText.h"
00019 #include "TArrow.h"
00020 #include "TStyle.h"
00021 #include "TPolyLine.h"
00022 #include "TDirectory.h"
00023 #include "TList.h"
00024 
00025 #include "NueAna/Display/NueDisplayModule.h"
00026 #include "NueAna/Display/SelectPad.h"
00027 #include "NueAna/NueRecord.h"
00028 //#include "NueAna/NuePID.h"
00029 #include "NueAna/NueAnaTools/SntpHelpers.h"
00030 
00031 #include "CandSubShowerSR/ClusterType.h"
00032 #include "CandNtupleSR/NtpSRRecord.h"
00033 #include "CandNtupleSR/NtpSREvent.h"
00034 #include "CandNtupleSR/NtpSRTrack.h"
00035 #include "CandNtupleSR/NtpSRShower.h"
00036 #include "CandNtupleSR/NtpSRCluster.h"
00037 #include "CandNtupleSR/NtpSRStrip.h"
00038 #include "CandNtupleSR/NtpSRShieldStrip.h"
00039 #include "CandNtupleSR/NtpSRShowerPulseHeight.h"
00040 #include "MCNtuple/NtpMCRecord.h"
00041 #include "MCNtuple/NtpMCTruth.h"
00042 #include "MCNtuple/NtpMCStdHep.h"
00043 #include "TruthHelperNtuple/NtpTHRecord.h"
00044 #include "TruthHelperNtuple/NtpTHEvent.h"
00045 #include "StandardNtuple/NtpStRecord.h"
00046 #include "Conventions/Detector.h"
00047 #include "Conventions/SimFlag.h"
00048 
00049 #include "Midad/Base/Mint.h"
00050 #include "Midad/Base/PageDisplay.h"
00051 #include "Midad/Base/CanvasSignals.h"
00052 #include "Midad/Base/SteelOutline.h"
00053 #include "Midad/Base/TimeHist.h"
00054 #include "Midad/Gui/GuiButton.h"
00055 #include "Midad/Gui/GuiBox.h"
00056 #include "Midad/Gui/GuiTextEntry.h"
00057 #include "Midad/Gui/GuiTextView.h"
00058 #include "Midad/Gui/GuiTab.h"
00059 #include "Midad/Gui/GuiLabel.h"
00060 #include "Midad/Gui/GuiMainWindow.h"
00061 #include <sigc++/sigc++.h>
00062 #include <sigc++/class_slot.h>
00063 
00064 #include "JobControl/JobC.h"
00065 #include "MinosObjectMap/MomNavigator.h"
00066 
00067 #include "DataUtil/GetDetector.h"
00068 #include "DataUtil/CDL2STL.h"
00069 #include "DataUtil/GetRunSnarlEvent.h"
00070 #include "DataUtil/PlaneOutline.h"
00071 
00072 #include "Calibrator/CalMIPCalibration.h"
00073 #include "Record/RecRecordImp.h"
00074 #include "Record/RecCandHeader.h"
00075 
00076 #include "Plex/PlexStripEndId.h"
00077 
00078 #include "RecoBase/PropagationVelocity.h"
00079 
00080 #include "UgliGeometry/UgliStripHandle.h"
00081 #include "UgliGeometry/UgliGeomHandle.h"
00082 
00083 #include "CandFitShowerEM/FitterEM.h"
00084 #include "MuonRemoval/NtpMRRecord.h"
00085 #include "MuonRemoval/NtpMREvent.h"
00086 #include "MuonRemoval/NtpMRTruth.h"
00087 
00088 #include "NueAna/NueAnaTools/NueConvention.h"
00089 
00090 #include <fstream>
00091 #include <cmath>
00092 
00093 using namespace DataUtil;
00094 using namespace SigC;
00095 
00096 // Boiler plate for using the Message Service.
00097 #include "MessageService/MsgService.h"
00098 CVSID("$Id: NueDisplayModule.cxx,v 1.114 2009/07/03 14:45:35 vahle Exp $");
00099 
00100 // Boiler plate needed for us to be a Job Module.
00101 #include "JobControl/JobCModuleRegistry.h"
00102 JOBMODULE(NueDisplayModule,"NueDisplayModule","Example of adding a Midad display in a Job Module\n");
00103 
00104 #include "DatabaseInterface/DbiResultPtr.tpl"
00105 
00106 const string evtpcode[] = {"N/A", "mu","e","NC","mu/NC?","e/NC?","???"};
00107 const string topocode[] = {"N/A", "QE","RES","DIS","???"};
00108 
00109 
00110 NueDisplayModule::NueDisplayModule()
00111   : fCanvas0(0)
00112   , fUVview(0)
00113   , fButtonPad(0)
00114   , fHistPad(0)
00115   , fInfo0(0)
00116   , fStdHepCan(0)
00117   , fUZview(0)
00118   , fVZview(0)
00119   , fTrkUZ(0)
00120   , fTrkVZ(0)
00121   , fShwUZ(0)
00122   , fShwVZ(0)
00123   , fSlcUZ(0)
00124   , fSlcVZ(0)
00125   , fSteelOutline(0)
00126   , pu1_outline(0)
00127   , fu1_outline(0)
00128   , pv1_outline(0)
00129   , fv1_outline(0)
00130   , pu2_outline(0)
00131   , fu2_outline(0)
00132   , pv2_outline(0)
00133   , fv2_outline(0)
00134   , stdhepinfo()
00135   , shia(stdhepinfo)
00136   , fCanvas1(0)
00137   , fHistcolz(0)
00138   , fHistlego(0)
00139   , fUZcolz(0)
00140   , fVZcolz(0)
00141   , fUZlego(0)
00142   , fVZlego(0)
00143   , ifixc(0)
00144   , ifixl(0)
00145   , evthighest_z(30)
00146   , evtlowest_z(0)
00147   , evthighest_t0(4.05)
00148   , evtlowest_t0(-4.05)
00149   , evthighest_t1(4.05)
00150   , evtlowest_t1(-4.05)
00151   , fFracVar_plots(0)
00152   , fFracVar_info(0)
00153   , highest_z(30)
00154   , lowest_z(0)
00155   , highest_t0(4.05)
00156   , lowest_t0(-4.05)
00157   , highest_t1(4.05)
00158   , lowest_t1(-4.05)
00159   , fracvars()
00160   , fva(fracvars)
00161   , fShwfit_plots(0)
00162   , fShwfit_plots_sub(0)
00163   , fShwfit_info(0)
00164   , shwfit()
00165   , sfa(shwfit)
00166   , hitcalc()
00167   , hca(hitcalc)
00168   , fAngClusterFitAna_plots(0)
00169   , angcluster()
00170   , aca(angcluster)
00171   , angclusterfit()
00172   , acfa(angclusterfit)
00173   , fCanvas5(0)
00174   , ssGraphU(0)
00175   , ssGraphV(0)
00176   , cluLegU(0)
00177   , cluLegV(0)
00178   , fCanvas6(0)
00179   , fCanvas7(0)
00180   , fSelectPad1(0)
00181   , fSelectPad2(0)
00182   , fCanvas8(0)
00183   , TimeHst(0)
00184   , TimeHstTrk(0)
00185   , TimeHstShw(0)
00186   , TimeHstUV(0)
00187   , TimeHstTrkU(0)
00188   , TimeHstTrkV(0)
00189   , TimeHstShwU(0)
00190   , TimeHstShwV(0)
00191   , TimeHst2(0)
00192   , TimeHstTrk2(0)
00193   , TimeHstShw2(0)
00194   , TimeHst2UV(0)
00195   , TimeHstTrk2U(0)
00196   , TimeHstTrk2V(0)
00197   , TimeHstShw2U(0)
00198   , TimeHstShw2V(0)
00199   , gr_dtds(0)
00200   , fCanvas9(0)
00201   , vzEventOverlay(0)
00202   , uzEventOverlay(0)
00203   , uzSliceOverlay(0)
00204   , vzSliceOverlay(0)
00205   , leg(0)
00206   , fPlusMinusOne(0)
00207   , fPlusMinusTwo(0)
00208   , fFullSnarl(0)
00209   , kShowRange(-1)
00210   , fMRuShowAll(0)
00211   , fMRuShowMR(0)
00212   , fMRuShowOld(0)                                                       
00213   , fMRdShowAll(0)
00214   , fMRdShowTrueMu(0)
00215   , fMRdShowTrueShw(0)
00216   , fMRdShowScaled(0)
00217   , fMRdShowReco(0)
00218   , clickbutton(0)
00219   , fSlice(-1)
00220   , fNumSlices(-1)
00221   , fEvent(-1)
00222   , fEvent_old(-1)
00223   , fNumEvents(-1)
00224   , fSnarl(-1)
00225   , RunNo_old(-1)
00226   , SubRunNo_old(-1)
00227   , imctruth(0)
00228   , ifixmcinfo(0)
00229   , kDPlaneCut(-1)
00230   , kLoPhNStripCut(-1)
00231   , kLoPhNPlaneCut(-1)
00232   , kPhStripCut(-1)
00233   , kPhPlaneCut(-1)
00234   , kCPhPlaneCut(-1.)
00235   , kPIDCut(-1)
00236   , kScanMode(0)
00237   , kTestMode(0)
00238   , kHideRunSnarl(0)
00239   , kDrawClu(0)
00240   , kIntReco(0)
00241   , foundmeu(false)
00242   , SIGMAPMEU(1.)
00243   , fHBox(0)
00244   , fVBox1(0)
00245   , fVBox2(0)
00246   , fVBox3(0)
00247   , fHBox1(0)
00248   , fHBox2(0)
00249   , fHBox3(0)
00250   , fHBox4(0)
00251   , fHBox5(0)
00252   , ievtp(0)
00253   , itopo(0)
00254   , iFileW(0)
00255   , hitlog(0)
00256   , icomm(0)
00257   , passfid(0)
00258   , passtrk(0)
00259   , passtrklike(0)
00260   , passshw(0)
00261   , preselec(0)
00262   , iIO(0)
00263   , selecevtp(0)
00264   , selectopo(0)
00265   , fRel(ReleaseType::kUnknown)
00266 {        
00267   ftrkshw = new TNtuple("trkshw","trkshw","x:y:type");
00268   info1 = new TLatex();
00269   info2 = new TLatex();
00270   info3 = new TLatex();
00271   info4 = new TLatex();
00272   info41 = new TLatex();
00273   info5 = new TLatex();
00274   info6 = new TLatex();
00275   info7 = new TLatex();
00276   info8 = new TLatex();
00277   info9 = new TLatex();
00278   info10 = new TLatex();
00279   info11 = new TLatex();
00280   info12 = new TLatex();
00281   info13 = new TLatex();
00282   mrInfo1 = new TLatex();
00283   mrInfo2 = new TLatex();
00284   mrInfo3 = new TLatex();
00285   mrInfo4 = new TLatex();
00286   mrInfo5 = new TLatex();
00287   mrInfo6 = new TLatex();
00288   mrInfo7 = new TLatex();
00289   mrInfo8 = new TLatex();
00290   mrInfo9 = new TLatex();
00291 
00292 
00293   mcvtx_u = new TMarker();
00294   mcvtx_u->SetMarkerStyle(2);
00295   mcvtx_v = new TMarker();
00296   mcvtx_v->SetMarkerStyle(2);
00297   srvtx_u = new TMarker();
00298   srvtx_u->SetMarkerStyle(5);
00299   srvtx_v = new TMarker();
00300   srvtx_v->SetMarkerStyle(5);
00301   srvtx_xy = new TMarker();
00302   srvtx_xy->SetMarkerStyle(5);
00303   fva.SetDisplay(1);
00304 
00305   for (int i = 0; i<7; i++){ iEvtp[i] = 0;}
00306   for (int i = 0; i<5; i++){ iTopo[i] = 0;}
00307 
00308   tfit_dt_ds_pos = new TF1("tfit_dt_ds_pos","(1./299792458.0)*x+[0]",0,30) ;
00309   tfit_dt_ds_neg = new TF1("tfit_dt_ds_neg","(-1./299792458.0)*x+[0]",0,30) ;
00310 
00311                                                                     
00312   showStpTrueMu = false;
00313   showStpTrueShw = false;
00314   showStpScaled = false;
00315   showStpRecoTrk = false;
00316   showStpAll = true;
00317 
00318   showMREvent = true;
00319   showOrigEvent = true;
00320   showNewEvent = true;
00321   
00322   //gStyle->SetTitleH(0.04);
00323   gStyle->SetPadTopMargin(0.1);
00324 }
00325 
00326 NueDisplayModule::~NueDisplayModule()
00327 {
00328   if (!iIO){ //record decisions
00329     if (iFileW){
00330       if (!kScanMode){//nornal mode
00331         if (!icomm && hitlog) outfile<<endl;
00332         outfile<<endl;
00333         outfile.close();
00334       }
00335       else {//'fast scan' mode
00336         if (fSnarl>0&&!hitlog){
00337           outfile<<RunNo_old<<" "<<SubRunNo_old<<" "<<fSnarl<<" "<<fEvent_old<<" "<<ievtp<<" "<<itopo<<"  "<<fComment->GetText()<<endl;
00338           outfile<<endl;
00339           outfile.close();
00340         }
00341         else if (fSnarl>0&&hitlog){
00342           if(!icomm) outfile<<endl;
00343           outfile<<endl;
00344           outfile.close();
00345         }
00346       }
00347     }
00348   }
00349 }
00350 
00351 void NueDisplayModule::BeginRun()
00352 {
00353   cout<<"In NueDisplayModule beginrun()"<<endl;
00354   if (gMint && !fCanvas0 && !fCanvas1) this->BuildDisplay();
00355 }
00356 
00357 JobCResult NueDisplayModule::Ana(const MomNavigator *mom)
00358 {
00359   if (gMint) {                // paranoia
00360     if (&gMint->GetJobC().Mom != mom) {
00361       MSG("NueDisplayModule",Msg::kError) << "Module's mom and JobC's mom differ: "
00362                                      << (void*)&gMint->GetJobC().Mom << " != "
00363                                      << (void*) mom << endl;
00364     }
00365   }
00366   
00367   if (!fCanvas0||!fCanvas1) {
00368     // No canvas - we can't do anything, but otherwise nothing
00369     // to say that there is a problem, so just return "ok".
00370     MSG("NueDisplayModule",Msg::kWarning) << "I have no canvas!\n";
00371     return JobCResult::kAOK;
00372   }
00373   
00374   //get data from mom
00375   foundST=false;
00376   foundSR=false;
00377   foundMC=false;
00378   foundTH=false;
00379   foundMR=false;
00380   foundSTOld=false;
00381   st = 0;
00382   sr = 0;
00383   mc = 0;
00384   th = 0;
00385   mr = 0;
00386   stOld = 0;
00387 
00388   VldContext vc;  
00389   st=dynamic_cast<NtpStRecord *>(mom->GetFragment("NtpStRecord", "Primary"));
00390   if(!st)
00391   {
00392     MSG("NueDisplayModule",Msg::kError) << "Can't find primary NtpStRecord.... looking for any!\n";
00393     st=dynamic_cast<NtpStRecord *>(mom->GetFragment("NtpStRecord"));
00394   }
00395 
00396 
00397   if(st){
00398     foundST=true;
00399     vc=st->GetHeader().GetVldContext();
00400 
00401     string relName = st->GetTitle();
00402     string reco = relName.substr(0,relName.find_first_of("("));
00403     if(reco == "CEDAR") fRel = ReleaseType::kCedar;
00404     else if(reco == "DOGWOOD") fRel = ReleaseType::kDogwood;
00405     else fRel = ReleaseType::kBirch;
00406     if(vc.GetSimFlag() == SimFlag::kMC){
00407       NtpMCGenInfo* genInfo = &(st->mchdr.geninfo);
00408       if(strstr(genInfo->codename.c_str(), "daikon") == 0)
00409         fRel += ReleaseType::kCarrot;
00410       if(strstr(genInfo->codename.c_str(), "daikon") != 0)
00411         fRel += ReleaseType::kDaikon;
00412     }
00413     if(vc.GetSimFlag() != SimFlag::kMC) fRel += ReleaseType::kData;
00414 
00415     //check for MR:
00416     mr=dynamic_cast<NtpMRRecord *>(mom->GetFragment("NtpMRRecord"));
00417     if(mr){
00418       if(ReleaseType::IsBirch(fRel)) {
00419         stOld=dynamic_cast<NtpStRecord *>(mom->GetFragment("NtpStRecord",
00420                                                            "NtpStRecordOld"));  
00421       }
00422       else if(ReleaseType::IsCedar(fRel)||ReleaseType::IsDogwood(fRel)){
00423         stOld=st;
00424         st=dynamic_cast<NtpStRecord *>(mom->GetFragment("NtpStRecord",
00425                                                         "MuonRemoved"));
00426       }
00427       if(stOld) foundMR = true;
00428     }
00429   }
00430   else {
00431     fRel = ReleaseType::kUnknown;
00432     sr = dynamic_cast<NtpSRRecord *>(mom->GetFragment("NtpSRRecord"));
00433     if (sr) {
00434       foundSR = true;
00435       vc=sr->GetHeader().GetVldContext();        
00436     }
00437     mc = static_cast<NtpMCRecord *>(mom->GetFragment("NtpMCRecord"));
00438     if (mc) {
00439       foundMC = true;
00440       th = static_cast<NtpTHRecord *>(mom->GetFragment("NtpTHRecord"));
00441       if (th) foundTH = true;
00442     }
00443   }
00444 
00445   if(!foundSR&&!foundST) {
00446     MSG("NueDisplayModule",Msg::kError)<<"Got Nothing to display"<<endl;
00447       return JobCResult::kFailed;
00448    }
00449     
00450 
00451   // Load DB CalMIPCalibration and set it for packages that need it
00452 
00453 
00454    if(!foundmeu) 
00455    {
00456     //Setup and give context
00457     DbiResultPtr<CalMIPCalibration> fResPtr;
00458     fResPtr.NewQuery(vc,10);
00459     
00460     //Get Scale
00461     if(fResPtr.GetNumRows()>0)
00462     {
00463      const CalMIPCalibration* mipcal = fResPtr.GetRow(0);
00464      SIGMAPMEU = mipcal->GetScale();
00465      foundmeu=true;
00466     }
00467    }
00468 
00469    sfa.SetParams(SIGMAPMEU);
00470    sfa.SetCutParams(kDPlaneCut,kPhStripCut,kPhPlaneCut, kCPhPlaneCut);
00471    fva.SetParams(SIGMAPMEU);
00472    hca.SetParams(SIGMAPMEU);
00473    //aneia.SetParams(SIGMAPMEU);
00474 
00475    TObject *obj=0;
00476    TIter objiter = mom->FragmentIter();
00477    vector<NueRecord *> vr;
00478    //vector<NuePID *> vpid;
00479    while((obj=objiter.Next())){
00480     const char *cn=obj->ClassName();
00481     if(strcmp(cn,"NueRecord")==0){
00482       NueRecord *nr = dynamic_cast<NueRecord *>(obj);
00483       MSG("NueDisplayModule",Msg::kDebug)<<"Found a NueRecord in MOM"
00484                                          <<" Snarl "<<nr->GetHeader().GetSnarl()
00485                                          <<" Event "<<nr->GetHeader().GetEventNo()<<endl;
00486       vr.push_back(nr);
00487     }
00488     else if(strcmp(cn,"NuePID")==0){
00489       //NuePID *npid  = dynamic_cast<NuePID *>(obj);
00490       MSG("NueDisplayModule",Msg::kDebug)<<"Found a NuePID in MOM"
00491         //     <<" Snarl "<<npid->GetHeader().GetSnarl()
00492         //     <<" Event "<<npid->GetHeader().GetEventNo()<< "PID: " << npid->IsNue i
00493                                          << endl;
00494       //vpid.push_back(npid);
00495     }
00496     else{
00497       continue;
00498     }
00499   }
00500   
00501   
00502   //so, mom will match up snarls for us,
00503   //but, we have to match up events for ourselves.
00504   MSG("NueDisplayModule",Msg::kDebug)<<"Starting to match records"<<endl;
00505   MSG("NueDisplayModule",Msg::kDebug)<<"found "<<vr.size()<<" NueR's"<<endl;
00506   foundvrmatch=false;
00507   for(unsigned int i=0;i<vr.size();i++){
00508     int event = vr[i]->GetHeader().GetEventNo();
00509     if(event==fEvent){
00510       nr=vr[i];
00511       foundvrmatch=true;
00512       break;
00513     }
00514   }     
00515   if(foundvrmatch) MSG("NueDisplayModule",Msg::kDebug)<<"Found vr"<<endl;
00516   foundpidmatch=false;
00517 /*  for(unsigned int i=0;i<vpid.size();i++){
00518     int event = vpid[i]->GetHeader().GetEventNo();
00519     if(event==fEvent){
00520       pid=vpid[i];
00521       foundpidmatch=true;
00522       break;
00523     }
00524   }     
00525 */
00526   if(foundvrmatch) MSG("NueDisplayModule",Msg::kDebug)<<"Found pid"<<endl; 
00527   
00528   MSG("NueDisplayModule",Msg::kDebug)<<"Matches?"<<endl;
00529   if(foundpidmatch){
00530     MSG("NueDisplayModule",Msg::kDebug)<<"found pid"<<endl;
00531   }
00532   if(foundvrmatch){
00533     MSG("NueDisplayModule",Msg::kDebug)<<"found record"<<endl;
00534   }
00535   
00536   if (!iIO) fEvent = 0; //in the Write mode
00537   this->UpdateDisplay(foundvrmatch, foundpidmatch);
00538   
00539   return JobCResult::kAOK;
00540 }
00541 
00542 void NueDisplayModule::BuildDisplay()
00543 {
00544   MSG("NueDisplayModule",Msg::kDebug)<<"In BuildDisplay"<<endl;
00545 
00546   //get detector/simflag/run information
00547 
00548   // Get Ugli for later.  Bail immediately if fail
00549   UgliGeomHandle ugh = gMint->GetUgliGeomHandle();
00550   if (! ugh.IsValid()) {
00551     MSG("NueDisplayModule",Msg::kWarning) << "Got invalid Ugli\n";
00552     //return;
00553   }
00554 
00555   int run=0, subrun = 0, snarl = 0, evt = 0;
00556   DataUtil::GetRunSnarlEvent(&(gMint->GetJobC().Mom),run,snarl,evt);
00557   RecRecordImp<RecCandHeader> *rr = 
00558     dynamic_cast<RecRecordImp<RecCandHeader>*>
00559     ((gMint->GetJobC().Mom).GetFragment("RecRecordImp<RecCandHeader>"));
00560   if ( rr ) {
00561     subrun   = rr->GetHeader().GetSubRun();
00562     fDetectorType = rr->GetHeader().GetVldContext().GetDetector();
00563     fSimFlag = rr->GetHeader().GetVldContext().GetSimFlag();
00564   }
00565   RunNo = run;
00566   SubRunNo = subrun;
00567 
00568   fSnarl = -1; //reset snarl no at the beginning of each run
00569   if (RunNo_old==-1&&SubRunNo_old==-1){
00570     RunNo_old = RunNo;
00571     SubRunNo_old = SubRunNo;
00572   }
00574 
00575   //generate main display
00576 
00577   const int width = 1000, height = 680;
00578   
00579   //CanvasSignals* cs_reco = 0;
00580   CanvasSignals* cs0 = 0;
00581   CanvasSignals* cs1 = 0;
00582   CanvasSignals* cs2 = 0;
00583   CanvasSignals* cs3 = 0;
00584   CanvasSignals* cs4 = 0;
00585   CanvasSignals* cs5 = 0;
00586   CanvasSignals* cs6 = 0;
00587   CanvasSignals* cs7 = 0;
00588   CanvasSignals* cs8 = 0;
00589   CanvasSignals* cs9 = 0;
00590   CanvasSignals* mrC1 = 0;
00591 
00592   PageDisplay* pd = gMint->GetDisplay();
00593   //get Button Box on the left
00594   GuiBox *fBBox = pd->GetButtonBox();
00595   // No pre-existing display, so make one to our size
00596   if (!pd) {
00597     MSG("NueDisplayModule",Msg::kDebug)<<"No display, making one"<<endl;
00598     pd = gMint->SpawnDisplay(width,height);
00599   }
00600 
00602 
00603   //add buttons in the Button Box
00604   //"Next Event" "Prev Event"
00605   fNextEventbut = pd->AddButton("Next Event ");
00606   fNextEventbut->clicked.connect(slot_class(*this,&NueDisplayModule::NextEvent));
00607   fNextEventbut = pd->AddButton("Prev Event ");
00608   fNextEventbut->clicked.connect(slot_class(*this,&NueDisplayModule::PrevEvent));
00609 
00610   //Event No
00611   fEventNo = manage(new GuiLabel(*fBBox," "));
00612   fEventNo->SetLayoutHints(kLHintsExpandX);
00613   fBBox->Add(*fEventNo);
00614   fEventEntry = pd->AddEntry(" ");
00615   fEventEntry->activated.connect(slot_class(*this,&NueDisplayModule::GotoEvent));
00616   
00617   //preselection
00618   fCuts = pd->AddButton("Cuts: OFF");
00619   fCuts->clicked.connect(slot_class(*this,&NueDisplayModule::SetCuts));
00620 
00621   //I/O
00622   fIO = pd->AddButton("Write");
00623   fIO->clicked.connect(slot_class(*this,&NueDisplayModule::SetMode));
00624 
00625   //"NextSelEvt" "PreSelEvt"
00626   fNextSelEvt = pd->AddButton("NextSelEvt");
00627   fNextSelEvt->clicked.connect(slot_class(*this,&NueDisplayModule::NextSelEvt));
00628   fPrevSelEvt = pd->AddButton("PrevSelEvt");
00629   fPrevSelEvt->clicked.connect(slot_class(*this,&NueDisplayModule::PrevSelEvt));
00630 
00631   if(!kTestMode){
00632     fMCTruth = pd->AddButton("MC Truth");
00633     fMCTruth->clicked.connect(slot_class(*this,&NueDisplayModule::showmctruth));
00634 
00635     fFixMCInfo = pd->AddButton("Fix MC Info");
00636     fFixMCInfo->clicked.connect(slot_class(*this,&NueDisplayModule::fixmcinfo));
00637   }
00638 
00639   if(kIntReco){
00640     fIntRecoCalc2 = pd->AddButton("IR: Re-Draw ");
00641     fIntRecoCalc2->clicked.connect(slot_class(*this,
00642                                              &NueDisplayModule::SetUpStripButtons));
00643     fIntRecoCalc1 = pd->AddButton("IR: Calculate");
00644     fIntRecoCalc1->clicked.connect(slot_class(*this,
00645                                              &NueDisplayModule::IntRecoCalc));
00646   }
00647 
00648   fPrint = pd->AddButton("Print");
00649   fPrint->clicked.connect(slot_class(*this,&NueDisplayModule::PrintPads));
00650 
00652 
00653   //construct frame for voting and I/O facilities
00654 
00655   //main box fHBox
00656   if(!fHBox){
00657     fHBox = manage(new GuiBox(*pd,kHorizontalFrame));
00658     fHBox->SetHeight(140);
00659     pd->SetWidth(pd->GetWidth());
00660     fHBox->SetWidth(pd->GetWidth());
00661     fHBox->SetLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX);
00662     pd->Add(*fHBox);
00663   } 
00664   
00665   //voting stuff
00666   fVBox1 = manage(new GuiBox(*fHBox,kVerticalFrame));
00667   fVBox1->SetLayoutHints(kLHintsExpandY);
00668   fHBox->Add(*fVBox1);
00669 
00670   //event type
00671   evtp1 =  manage(new GuiTextButton(*fVBox1,"mu"));
00672   evtp1->SetLayoutHints(kLHintsExpandX);
00673   fVBox1->Add(*evtp1);
00674   evtp1->clicked.connect(slot_class(*this,&NueDisplayModule::vote10));
00675 
00676   evtp2 =  manage(new GuiTextButton(*fVBox1,"e"));
00677   evtp2->SetLayoutHints(kLHintsExpandX);
00678   fVBox1->Add(*evtp2);
00679   evtp2->clicked.connect(slot_class(*this,&NueDisplayModule::vote20));
00680 
00681   evtp3 =  manage(new GuiTextButton(*fVBox1,"NC"));
00682   evtp3->SetLayoutHints(kLHintsExpandX);
00683   fVBox1->Add(*evtp3);
00684   evtp3->clicked.connect(slot_class(*this,&NueDisplayModule::vote30));
00685 
00686   evtp4 =  manage(new GuiTextButton(*fVBox1,"mu/NC?"));
00687   evtp4->SetLayoutHints(kLHintsExpandX);
00688   fVBox1->Add(*evtp4);
00689   evtp4->clicked.connect(slot_class(*this,&NueDisplayModule::vote40));
00690 
00691   evtp5 =  manage(new GuiTextButton(*fVBox1,"e/NC?"));
00692   evtp5->SetLayoutHints(kLHintsExpandX);
00693   fVBox1->Add(*evtp5);
00694   evtp5->clicked.connect(slot_class(*this,&NueDisplayModule::vote50));
00695 
00696   evtp6 =  manage(new GuiTextButton(*fVBox1,"???"));
00697   evtp6->SetLayoutHints(kLHintsExpandX);
00698   fVBox1->Add(*evtp6);
00699   evtp6->clicked.connect(slot_class(*this,&NueDisplayModule::vote60));
00700 
00701   fVBox2 = manage(new GuiBox(*fHBox,kVerticalFrame,2));
00702   fVBox2->SetLayoutHints(kLHintsExpandY);
00703   fHBox->Add(*fVBox2);
00704 
00705   //topology
00706   topo1 =  manage(new GuiTextButton(*fVBox2,"QE"));
00707   topo1->SetLayoutHints(kLHintsExpandX);
00708   fVBox2->Add(*topo1);
00709   topo1->clicked.connect(slot_class(*this,&NueDisplayModule::vote01));
00710 
00711   topo2 =  manage(new GuiTextButton(*fVBox2,"RES"));
00712   topo2->SetLayoutHints(kLHintsExpandX);
00713   fVBox2->Add(*topo2);
00714   topo2->clicked.connect(slot_class(*this,&NueDisplayModule::vote02));
00715 
00716   topo3 =  manage(new GuiTextButton(*fVBox2,"DIS"));
00717   topo3->SetLayoutHints(kLHintsExpandX);
00718   fVBox2->Add(*topo3);
00719   topo3->clicked.connect(slot_class(*this,&NueDisplayModule::vote03));
00720 
00721   topo4 =  manage(new GuiTextButton(*fVBox2,"???"));
00722   topo4->SetLayoutHints(kLHintsExpandX);
00723   fVBox2->Add(*topo4);
00724   topo4->clicked.connect(slot_class(*this,&NueDisplayModule::vote04));
00725 
00726   fEncoded = manage(new GuiLabel(*fVBox2," "));
00727   fEncoded->SetLayoutHints(kLHintsExpandX);
00728   fVBox2->Add(*fEncoded);
00729   //updateEncoded();
00730 
00731   vote = manage(new GuiTextButton(*fVBox2,"Log Details"));
00732   vote->SetLayoutHints(kLHintsExpandX);
00733   fVBox2->Add(*vote);
00734   vote->clicked.connect(slot_class(*this,&NueDisplayModule::logvote));
00735 
00736   fVBox3 = manage(new GuiBox(*fHBox,kVerticalFrame));
00737   fHBox->Add(*fVBox3);
00738 
00739   //make comments?
00740   fHBox3 = manage(new GuiBox(*fVBox3,kHorizontalFrame));
00741   fHBox3->SetLayoutHints(kLHintsExpandX);
00742   fVBox3->Add(*fHBox3);
00743   fComLab = manage(new GuiLabel(*fHBox3," Comments? "));
00744   fComLab->SetLayoutHints(kLHintsLeft);
00745   fHBox3->Add(*fComLab);
00746   fComment = manage(new GuiTextEntry(*fHBox3,""));
00747   fComment->SetLayoutHints(kLHintsExpandX);
00748   fHBox3->Add(*fComment);
00749   fComment->activated.connect(slot_class(*this,&NueDisplayModule::makecomment));
00750 
00751   //open file to read
00752   fHBox4 = manage(new GuiBox(*fVBox3,kHorizontalFrame));
00753   fHBox4->SetLayoutHints(kLHintsExpandX);
00754   fVBox3->Add(*fHBox4);
00755   fFileLab = manage(new GuiLabel(*fHBox4," File to Open? "));
00756   fFileLab->SetLayoutHints(kLHintsLeft);
00757   fHBox4->Add(*fFileLab);
00758   fFileEnt = manage(new GuiTextEntry(*fHBox4,""));
00759   fFileEnt->SetLayoutHints(kLHintsExpandX);
00760   fHBox4->Add(*fFileEnt);
00761   fFileEnt->activated.connect(slot_class(*this,&NueDisplayModule::OpenFileRead));
00762 
00763   //event type
00764   fHBox5 = manage(new GuiBox(*fVBox3,kHorizontalFrame));
00765   fHBox5->SetLayoutHints(kLHintsExpandX);
00766   fVBox3->Add(*fHBox5);
00767   fTypeLab = manage(new GuiLabel(*fHBox5," TYPE         "));
00768   fTypeLab->SetLayoutHints(kLHintsLeft);
00769   fHBox5->Add(*fTypeLab);
00770   Evtp1 = manage(new GuiCheckButton(*fHBox5,"mu"));
00771   Evtp1->SetLayoutHints(kLHintsLeft);
00772   fHBox5->Add(*Evtp1);
00773   Evtp1->clicked.connect(slot_class(*this,&NueDisplayModule::selec10));
00774   Evtp2 = manage(new GuiCheckButton(*fHBox5,"e"));
00775   Evtp2->SetLayoutHints(kLHintsLeft);
00776   fHBox5->Add(*Evtp2);
00777   Evtp2->clicked.connect(slot_class(*this,&NueDisplayModule::selec20));
00778   Evtp3 = manage(new GuiCheckButton(*fHBox5,"NC"));
00779   Evtp3->SetLayoutHints(kLHintsLeft);
00780   fHBox5->Add(*Evtp3);
00781   Evtp3->clicked.connect(slot_class(*this,&NueDisplayModule::selec30));
00782   Evtp4 = manage(new GuiCheckButton(*fHBox5,"mu/NC?"));
00783   Evtp4->SetLayoutHints(kLHintsLeft);
00784   fHBox5->Add(*Evtp4);
00785   Evtp4->clicked.connect(slot_class(*this,&NueDisplayModule::selec40));
00786   Evtp5 = manage(new GuiCheckButton(*fHBox5,"e/NC?"));
00787   Evtp5->SetLayoutHints(kLHintsLeft);
00788   fHBox5->Add(*Evtp5);
00789   Evtp5->clicked.connect(slot_class(*this,&NueDisplayModule::selec50));
00790   Evtp6 = manage(new GuiCheckButton(*fHBox5,"???"));
00791   Evtp6->SetLayoutHints(kLHintsLeft);
00792   fHBox5->Add(*Evtp6);
00793   Evtp6->clicked.connect(slot_class(*this,&NueDisplayModule::selec60));
00794   Evtp7 = manage(new GuiCheckButton(*fHBox5,"N/A"));
00795   Evtp7->SetLayoutHints(kLHintsLeft);
00796   fHBox5->Add(*Evtp7);
00797   Evtp7->clicked.connect(slot_class(*this,&NueDisplayModule::selec70));
00798 
00799   //topology
00800   fHBox6 = manage(new GuiBox(*fVBox3,kHorizontalFrame));
00801   fHBox6->SetLayoutHints(kLHintsExpandX);
00802   fVBox3->Add(*fHBox6);
00803   fTopoLab = manage(new GuiLabel(*fHBox6," TOPOLOGY "));
00804   fTopoLab->SetLayoutHints(kLHintsLeft);
00805   fHBox6->Add(*fTopoLab);
00806   Topo1 = manage(new GuiCheckButton(*fHBox6,"QE"));
00807   Topo1->SetLayoutHints(kLHintsLeft);
00808   fHBox6->Add(*Topo1);
00809   Topo1->clicked.connect(slot_class(*this,&NueDisplayModule::selec01));
00810   Topo2 = manage(new GuiCheckButton(*fHBox6,"RES"));
00811   Topo2->SetLayoutHints(kLHintsLeft);
00812   fHBox6->Add(*Topo2);
00813   Topo2->clicked.connect(slot_class(*this,&NueDisplayModule::selec02));
00814   Topo3 = manage(new GuiCheckButton(*fHBox6,"DIS"));
00815   Topo3->SetLayoutHints(kLHintsLeft);
00816   fHBox6->Add(*Topo3);
00817   Topo3->clicked.connect(slot_class(*this,&NueDisplayModule::selec03));
00818   Topo4 = manage(new GuiCheckButton(*fHBox6,"???"));
00819   Topo4->SetLayoutHints(kLHintsLeft);
00820   fHBox6->Add(*Topo4);
00821   Topo4->clicked.connect(slot_class(*this,&NueDisplayModule::selec04));
00822   Topo5 = manage(new GuiCheckButton(*fHBox6,"N/A"));
00823   Topo5->SetLayoutHints(kLHintsLeft);
00824   fHBox6->Add(*Topo5);
00825   Topo5->clicked.connect(slot_class(*this,&NueDisplayModule::selec05));
00826 
00827   fHBox7 = manage(new GuiBox(*fVBox3,kHorizontalFrame));
00828   fHBox7->SetLayoutHints(kLHintsExpandX);
00829   fVBox3->Add(*fHBox7);
00830   fFileR = manage(new GuiLabel(*fHBox7,""));
00831   fHBox7->Add(*fFileR);
00832   fTYPETOPO = manage(new GuiLabel(*fHBox7,""));
00833   fHBox7->Add(*fTYPETOPO);
00834   
00835   fHBox8 = manage(new GuiBox(*fVBox3,kHorizontalFrame));
00836   fHBox8->SetLayoutHints(kLHintsExpandX);
00837   fVBox3->Add(*fHBox8);
00838   fFileW = manage(new GuiLabel(*fHBox8,""));
00839   fHBox8->Add(*fFileW);
00840 
00841   fHBox9 = manage(new GuiBox(*fVBox3,kHorizontalFrame));
00842   fHBox9->SetLayoutHints(kLHintsExpandX);
00843   fVBox3->Add(*fHBox9);
00844 
00845   fNextEventbut1 = manage(new GuiTextButton(*fHBox9,"Next Event"));
00846   //fNextEventbut1->SetLayoutHints(kLHintsExpandX);
00847   fHBox9->Add(*fNextEventbut1);
00848   fNextEventbut1->clicked.connect(slot_class(*this,&NueDisplayModule::NextEvent));
00849 
00850   fPrevEventbut1 = manage(new GuiTextButton(*fHBox9,"Prev Event"));
00851   //fPrevEventbut1->SetLayoutHints(kLHintsExpandX);
00852   fHBox9->Add(*fPrevEventbut1);
00853   fPrevEventbut1->clicked.connect(slot_class(*this,&NueDisplayModule::PrevEvent));
00854 
00855 
00856   //reco info
00857   fHBox2 = manage(new GuiBox(*fHBox,kHorizontalFrame));
00858   fHBox->Add(*fHBox2);
00859 
00860   fRecoInfo = manage(new GuiTextView(*fHBox2,1,1));
00861   fHBox2->Add(*fRecoInfo);
00862   fRecoInfo->AddLine("Reco Information");
00863 
00864 
00865 
00867 
00868   //add user-defined canvas
00869 
00870   cs0 = dynamic_cast<CanvasSignals*>(pd->AddPage("UserCanvas"));
00871   cs1 = dynamic_cast<CanvasSignals*>(pd->AddPage("UserCanvas"));
00872   cs2 = dynamic_cast<CanvasSignals*>(pd->AddPage("UserCanvas"));
00873   cs3 = dynamic_cast<CanvasSignals*>(pd->AddPage("UserCanvas"));
00874   cs4 = dynamic_cast<CanvasSignals*>(pd->AddPage("UserCanvas"));
00875   if(kDrawClu) cs5 = dynamic_cast<CanvasSignals*>(pd->AddPage("UserCanvas"));
00876   if(kIntReco) {
00877     cs7 = dynamic_cast<CanvasSignals*>(pd->AddPage("UserCanvas"));
00878     cs6 = dynamic_cast<CanvasSignals*>(pd->AddPage("UserCanvas"));
00879   }
00880   cs8 = dynamic_cast<CanvasSignals*>(pd->AddPage("UserCanvas"));
00881   cs9 = dynamic_cast<CanvasSignals*>(pd->AddPage("UserCanvas"));
00882   mrC1 = dynamic_cast<CanvasSignals*>(pd->AddPage("UserCanvas"));
00883 
00884   if (!cs0||!cs1||!cs2||!cs3||!cs4||!cs8|!cs9|!mrC1) {
00885     MSG("NueDisplayModule",Msg::kWarning) << "Failed to get NueCanvas's CanvasSignals\n";
00886     return;
00887   }
00888 
00889     //fCanvas_reco = &cs_reco->GetCanvas();
00890     fCanvas0 = &cs0->GetCanvas();
00891     fCanvas1 = &cs1->GetCanvas();
00892     fCanvas2 = &cs2->GetCanvas();
00893     fCanvas3 = &cs3->GetCanvas();
00894     fCanvas4 = &cs4->GetCanvas();
00895     if(kDrawClu) {
00896       fCanvas5 = &cs5->GetCanvas();    
00897       fCanvas5->SetHighLightColor(0);
00898     }
00899     if(kIntReco) {
00900       fCanvas6 = &cs6->GetCanvas();
00901       fCanvas6->SetHighLightColor(0);
00902       fCanvas7 = &cs7->GetCanvas();
00903       fCanvas7->SetHighLightColor(0);
00904     }
00905     fCanvas8 = &cs8->GetCanvas();
00906     fCanvas9 = &cs9->GetCanvas();
00907     fMRCanvas1 = &mrC1->GetCanvas();
00908     
00909     //please set highlightcolor of all the canvases to be 0
00910     //otherwise buttons on the second page will be screwed
00911     fCanvas0->SetHighLightColor(0);
00912     fCanvas1->SetHighLightColor(0);
00913     fCanvas2->SetHighLightColor(0);
00914     fCanvas3->SetHighLightColor(0);
00915     fCanvas4->SetHighLightColor(0);
00916     fCanvas8->SetHighLightColor(0);
00917     fCanvas9->SetHighLightColor(0);
00918     fMRCanvas1->SetHighLightColor(0);
00919 
00920     //main canvas
00921     //fCanvas0->Divide(2,1);
00922     //fCanvas0->SetName("fCanvas0");
00923     //fCanvas1->Divide(2,1);
00924     fCanvas2->Divide(2,1);
00925     fCanvas3->Divide(2,2);
00926     fCanvas4->Divide(2,2);    
00927     fCanvas8->Divide(2,2);
00928     fCanvas8->SetName("fCanvas8");
00929     fCanvas9->Divide(2,2);
00930 //    fMRCanvas1->Divide(2,2);
00931 
00932     if(kDrawClu) {
00933       fCanvas5->cd();
00934       fCanvas5->SetName("fCanvas5");
00935       TPad *temp_pad = new TPad("c5_1","c5_1",0.0,0.5,0.42,1);
00936       temp_pad->SetNumber(1); temp_pad->Draw();
00937       temp_pad = new TPad("c5_2","c5_2",0.42,0.5,0.84,1);
00938       temp_pad->SetNumber(2); temp_pad->Draw();
00939       temp_pad = new TPad("c5_3","c5_3",0.84,0.5,1.0,1);
00940       temp_pad->SetNumber(3); temp_pad->Draw();
00941       temp_pad = new TPad("c5_4","c5_4",0.0,0.0,0.42,0.5);
00942       temp_pad->SetNumber(4); temp_pad->Draw();
00943       temp_pad = new TPad("c5_5","c5_5",0.42,0.0,0.84,0.5);
00944       temp_pad->SetNumber(5); temp_pad->Draw();
00945       temp_pad = new TPad("c5_6","c5_6",0.84,0.0,1.0,0.5);
00946       temp_pad->SetNumber(6); temp_pad->Draw();
00947     }
00948 
00949     if(!kTestMode){
00950       fCanvas0->cd();
00951       fStdHepCan = new TPad("fStdHepCan","fStdHepCan",0.5,0.,1.,0.5);
00952       fStdHepCan->Draw();
00953       fStdHepCan->Range(0,0,1,1.1);
00954       fStdHepCan->cd();
00955       TPaveText *infoTex1 = new TPaveText(0.05,1.,0.2,1.07);
00956       infoTex1->AddText("Initial State");
00957       infoTex1->SetBorderSize(1);
00958       TPaveText *infoTex2 = new TPaveText(0.3,1.,0.45,1.07);
00959       infoTex2->AddText("Intermediate");
00960       infoTex2->SetBorderSize(1);
00961       TPaveText *infoTex3 = new TPaveText(0.55,1.,0.7,1.07);
00962       infoTex3->AddText("Final State");
00963       infoTex3->SetBorderSize(1);
00964       TPaveText *infoTex4 = new TPaveText(0.8,1.,0.95,1.07);
00965       infoTex4->AddText("Later Decays");
00966       infoTex4->SetBorderSize(1);
00967       infoTex1->SetTextSize(0.05);
00968       infoTex1->SetTextFont(12);
00969       infoTex1->SetTextColor(1);
00970       infoTex2->SetTextSize(0.05);
00971       infoTex2->SetTextFont(12);
00972       infoTex2->SetTextColor(1);
00973       infoTex3->SetTextSize(0.05);
00974       infoTex3->SetTextFont(12);
00975       infoTex3->SetTextColor(1);
00976       infoTex4->SetTextSize(0.05);
00977       infoTex4->SetTextFont(12);
00978       infoTex4->SetTextColor(1);
00979       infoTex1->SetName("infoTex1");
00980       infoTex2->SetName("infoTex2");
00981       infoTex3->SetName("infoTex3");
00982       infoTex4->SetName("infoTex4");
00983       infoTex1->Draw();
00984       infoTex2->Draw();
00985       infoTex3->Draw();
00986       infoTex4->Draw();
00987     }
00988 
00989     fCanvas0->cd();
00990     fButtonPad = new TPad("fButtonPad","Buttons",0,0,0.5,0.05);
00991     fButtonPad->Draw();
00992     fButtonPad->cd();
00993     //the following button can zoom in/out the histograms on the first Canvas. TButton has no access to the class members so I have to pass the parameters through the histogram option. 
00994     fZoom = new TButton("Zoom","float a1,a2,a3,a4,a5,a6;int i;sscanf(UZview->GetOption(),\"%f,%f,%f,%f,%f,%f,%d\",&a1,&a2,&a3,&a4,&a5,&a6,&i);if(i==0){UZview->GetXaxis()->SetRangeUser(a2,a1);UZview->GetYaxis()->SetRangeUser(a4,a3);VZview->GetXaxis()->SetRangeUser(a2,a1);VZview->GetYaxis()->SetRangeUser(a6,a5);char setoptions[100];sprintf(setoptions,\"%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%d\",a1,a2,a3,a4,a5,a6,1);UZview->SetOption(setoptions);} else if(i==1){double max=UZview->GetMaximum();UZview->GetXaxis()->UnZoom();UZview->GetYaxis()->UnZoom();VZview->GetXaxis()->UnZoom();VZview->GetYaxis()->UnZoom();UZview->SetMaximum(max);VZview->SetMaximum(max);char setoptions[100];sprintf(setoptions,\"%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%d\",a1,a2,a3,a4,a5,a6,0);UZview->SetOption(setoptions);}fHistPad->cd(1);gPad->Modified();fHistPad->cd(2);gPad->Modified();",0,0,0.1,1);
00995     fZoom->SetTextSize(0.5);
00996     fZoom->Draw();
00997 
00998     fCanvas0->cd();
00999     fHistPad = new TPad("fHistPad","UZ and VZ views",0,0.05,0.5,1);
01000     //fHistPad->SetTopMargin(1);
01001     fHistPad->Draw();
01002     
01003     fHistPad->cd();
01004     fHistPad->Divide(1,2);
01005     
01006     int trkcolor = 1;
01007     int shwcolor = 6;
01008     // U vs. Z view
01009     fHistPad->cd(1);
01010     fUZview = new TH2D("UZview","Strip vs. Plane, U view",
01011                        500,0,30,210,-4.05,4.05);
01012     fUZview->SetStats(false);
01013     fUZview->SetXTitle("z(m)");
01014     fUZview->SetYTitle("u(m)");
01015     fUZview->GetYaxis()->SetTitleOffset(0.6);
01016     fUZview->Draw("COLZ");
01017     srvtx_u->Draw();
01018     fTrkUZ = new TH2D("TrkUZ","track strips, U view",
01019                        500,0,30,210,-4.05,4.05);
01020     fTrkUZ->SetStats(false);
01021     fTrkUZ->SetLineColor(trkcolor);
01022     fShwUZ = new TH2D("ShwUZ","shower strips, U view",
01023                        500,0,30,210,-4.05,4.05);
01024     fShwUZ->SetStats(false);
01025     fShwUZ->SetLineColor(shwcolor);
01026     fShwUZ->SetLineWidth(2);
01027     fSlcUZ = new TH2D("SlcUZ","Strip vs. Plane, U view",
01028                        500,0,30,210,-4.05,4.05);
01029     fSlcUZ->SetStats(false);
01030 
01031     // V vs. Z view
01032     fHistPad->cd(2);
01033     fVZview = new TH2D("VZview","Strip vs. Plane, V view",
01034                        500,0,30,210,-4.05,4.05);
01035     fVZview->SetStats(false);
01036     fVZview->SetXTitle("z(m)");
01037     fVZview->SetYTitle("v(m)");
01038     fVZview->GetYaxis()->SetTitleOffset(0.6);
01039     fVZview->Draw("COLZ");
01040     srvtx_v->Draw();
01041     fTrkVZ = new TH2D("TrkVZ","track strips, V view",
01042                        500,0,30,210,-4.05,4.05);
01043     fTrkVZ->SetStats(false);
01044     fTrkVZ->SetLineColor(trkcolor);
01045     fShwVZ = new TH2D("ShwVZ","shower strips, V view",
01046                        500,0,30,210,-4.05,4.05);
01047     fShwVZ->SetLineColor(shwcolor);
01048     fShwVZ->SetStats(false);
01049     fShwVZ->SetLineWidth(2);
01050     fSlcVZ = new TH2D("SlcVZ","Strip vs. Plane, V view",
01051                        500,0,30,210,-4.05,4.05);
01052     fSlcVZ->SetStats(false);
01053 
01054     // U vs. V view
01055     fCanvas0->cd();
01056     fUVview = new TPad("UVview","U vs V view",0.5,0.5,0.725,1);
01057     fUVview->SetFillStyle(4000);
01058     
01059     float t[4];
01060     ugh.GetTransverseExtent(PlaneView::kU,t[0],t[1]);
01061     ugh.GetTransverseExtent(PlaneView::kV,t[2],t[3]);
01062     for (int ind=0; ind<4;++ind) t[ind] = TMath::Abs(t[ind]);
01063     int maxind = TMath::LocMax(4,t);
01064     float tsize = TMath::Sqrt(2.0) * t[maxind];
01065     
01066     fUVview->Range(-tsize,-tsize,tsize,tsize);
01067     
01068     fUVview->Draw();
01069     
01070     fInfo0 = new TPad("Info0","Basic information",0.725,0.5,1,1);
01071     fInfo0->Draw();
01072     //fInfo0->cd();
01073     //fInfo0->Divide(1,2);
01074     fUVview->cd();
01075     fSteelOutline = new SteelOutline(DataUtil::GetDetector(gMint->GetJobC().Mom));
01076     if (!fSteelOutline) MSG("NueDisplayModule",Msg::kWarning)<<"Can't get the stell outline."<<endl;
01077     if (fDetectorType == Detector::kFar){//draw veto shield,copied Jim's EVD code
01078       //UgliGeomHandle ugh = gMint->GetUgliGeomHandle();
01079       if (ugh.IsValid()){
01080         vector<UgliScintPlnHandle> usphv = ugh.GetScintPlnHandleVector();
01081         vector<UgliScintPlnHandle>::reverse_iterator rit, rdone = usphv.rend();
01082         VS = new TList;
01083         VS->SetOwner();
01084         float cx,cy; 
01085         StripEnd::StripEnd_t two_sided[] = { StripEnd::kEast,
01086                                              StripEnd::kWest };
01087         StripEnd::StripEnd_t *side_list = two_sided;
01088    
01089         for (rit = usphv.rbegin(); rit != rdone; ++rit) {
01090           if (! rit->GetPlexPlaneId().IsVetoShield()) break;
01091           int nstrips = rit->NumberOfStrips();
01092           for (int istrip=0; istrip < nstrips; istrip++) {
01093             PlexStripEndId oneend(rit->GetPlexPlaneId(),istrip,side_list[0]);
01094             UgliStripHandle ush = ugh.GetStripHandle(oneend);
01095             TVector3 stripxyz0(ush.GlobalPos(-ush.GetHalfLength()));
01096             TVector3 stripxyz1(ush.GlobalPos(ush.GetHalfLength()));
01097             cx = 0.5*(stripxyz0[0]+stripxyz1[0]);
01098             cy = 0.5*(stripxyz0[1]+stripxyz1[1]);     
01099             Double_t dy[5] = {-ush.GetHalfThickness(),
01100                               -ush.GetHalfThickness(),
01101                               +ush.GetHalfThickness(),
01102                               +ush.GetHalfThickness(),
01103                               -ush.GetHalfThickness()};
01104             Double_t dx[5] = {-ush.GetHalfWidth(),
01105                               +ush.GetHalfWidth(),
01106                               +ush.GetHalfWidth(),
01107                               -ush.GetHalfWidth(),
01108                               -ush.GetHalfWidth()};
01109             if(rit->GetPlaneView()==PlaneView::kVSWallOnEdge){
01110               for (int id=0;id<6;id++){
01111                 double tmp=dy[id];
01112                 dy[id]=dx[id];
01113                 dx[id]=tmp;
01114               }
01115             }
01116             Double_t rot=0.9;
01117             if(rit->GetPlaneView()==PlaneView::kVSTopEastSlant){
01118               double newdx;
01119               double newdy;
01120               for (int id=0;id<6;id++){
01121                 newdx=dx[id]*cos(-rot)+dy[id]*sin(-rot);
01122                 newdy=-dx[id]*sin(-rot)+dy[id]*cos(-rot);
01123                 dx[id]=newdx;
01124                 dy[id]=newdy;
01125               }
01126             }
01127             if(rit->GetPlaneView()==PlaneView::kVSTopWestSlant){
01128               double newdx;
01129               double newdy;
01130               for (int id=0;id<6;id++){
01131                 newdx=dx[id]*cos(rot)+dy[id]*sin(rot);
01132                 newdy=-dx[id]*sin(rot)+dy[id]*cos(rot);
01133                 dx[id]=newdx;
01134                 dy[id]=newdy;
01135               }
01136               
01137             }
01138             Double_t xbox[5]={cx+dx[0],cx+dx[1],cx+dx[2],cx+dx[3],cx+dx[4]};
01139             Double_t ybox[5]={cy+dy[0],cy+dy[1],cy+dy[2],cy+dy[3],cy+dy[4]};
01140             TPolyLine * VSstrip = new TPolyLine(5,xbox,ybox);
01141             VSstrip->SetLineColor(13);
01142             VSstrip->SetLineWidth(1);
01143             VS->Add(VSstrip);
01144           }
01145         }
01146       }
01147     }
01148     Double_t l_coil = 0.2;
01149     Double_t x_coil[5] = {0,l_coil,0,-1*l_coil,0};
01150     Double_t y_coil[5] = {l_coil,0,-1*l_coil,0,l_coil};
01151     coil = new TPolyLine(5,x_coil,y_coil);
01152     coil->SetLineWidth(2);
01153 
01154     if (fDetectorType == Detector::kNear && !pu1_outline){
01155       //from Mad....
01156       PlaneOutline po;
01157       Color_t colu=38;
01158       Color_t colv=46;
01159       po.GetOutline(PlaneView::kV, PlaneCoverage::kNearPartial,
01160                     pv1_outline, pv2_outline);
01161       po.GetOutline(PlaneView::kV, PlaneCoverage::kNearFull,
01162                     fv1_outline, fv2_outline);
01163       po.GetOutline(PlaneView::kU, PlaneCoverage::kNearPartial,
01164                     pu1_outline, pu2_outline);
01165       po.GetOutline(PlaneView::kU, PlaneCoverage::kNearFull,
01166                     fu1_outline, fu2_outline);
01167       pv1_outline->SetLineColor(colv);
01168       pu1_outline->SetLineColor(colu);
01169 
01170       fv1_outline->SetLineColor(colv);
01171       fu1_outline->SetLineColor(colu);
01172       fv2_outline->SetFillColor(16);
01173       fu2_outline->SetFillColor(16);
01174       fv2_outline->SetFillStyle(4020);
01175       fu2_outline->SetFillStyle(4020);
01176       
01177       pv1_outline->SetLineWidth(1);
01178       pu1_outline->SetLineWidth(1);
01179       fv1_outline->SetLineWidth(1);
01180       fu1_outline->SetLineWidth(1);
01181       fv2_outline->SetLineWidth(1);
01182       fu2_outline->SetLineWidth(1);
01183 
01184     }
01185 
01186     //magnified images canvas
01187     fCanvas1->cd();
01188     fBC = new TPad("fBC","Button Panel for colz display",0,0.05,0.05,1);
01189     fBC->Draw();
01190     fBC->cd();
01191 
01192     //add buttons to get rid of low ph hitss 
01193     //originally 0,1,3,5 pe = 0,60,180,300 sigcor (far) = 0,0.1062,0.3186,0.5410 MEU (far)
01194     //originally 0,1,3,5 pe = 0,100,300,500 sigcor (near) = 
01195     cbut[0] = new TButton("PH>0","UZcolz->SetMinimum(0);VZcolz->SetMinimum(0);fHistcolz->cd(1);gPad->Modified();fHistcolz->cd(2);gPad->Modified();for(int i=0;i<4;i++){TButton *cbut=(TButton*)fBC->FindObject(Form(\"cbut%d\",i));if(i==0) cbut->SetFillColor(4); else cbut->SetFillColor(5);cbut->Paint();}",0,0.31,1,.36);
01196     cbut[0]->SetName("cbut0");
01197     cbut[1] = new TButton("PH>0.1","UZcolz->SetMinimum(0.10);VZcolz->SetMinimum(0.1);fHistcolz->cd(1);gPad->Modified();fHistcolz->cd(2);gPad->Modified();for(int i=0;i<4;i++){TButton *cbut=(TButton*)fBC->FindObject(Form(\"cbut%d\",i));if(i==1) cbut->SetFillColor(4); else cbut->SetFillColor(5);cbut->Paint();}",0,0.24,1,0.29);
01198     cbut[1]->SetName("cbut1");
01199     cbut[2] = new TButton("PH>0.3","UZcolz->SetMinimum(0.30);VZcolz->SetMinimum(0.3);fHistcolz->cd(1);gPad->Modified();fHistcolz->cd(2);gPad->Modified();for(int i=0;i<4;i++){TButton *cbut=(TButton*)fBC->FindObject(Form(\"cbut%d\",i));if(i==2) cbut->SetFillColor(4); else cbut->SetFillColor(5);cbut->Paint();}",0,0.17,1,0.22);
01200     cbut[2]->SetName("cbut2");
01201     cbut[3] = new TButton("PH>0.5","UZcolz->SetMinimum(0.50);VZcolz->SetMinimum(0.5);fHistcolz->cd(1);gPad->Modified();fHistcolz->cd(2);gPad->Modified();for(int i=0;i<4;i++){TButton *cbut=(TButton*)fBC->FindObject(Form(\"cbut%d\",i));if(i==3) cbut->SetFillColor(4); else cbut->SetFillColor(5);cbut->Paint();}",0,0.10,1,0.15);
01202     cbut[3]->SetName("cbut3");
01203     //cbut[4] = new TButton("Fix","fixc();",0,0.6,1,0.65);
01204     //cbut[4]->SetName("cbut4");
01205     for (int icbut = 0; icbut<4; icbut++){
01206       if (icbut == 0){
01207         cbut[icbut]->SetFillColor(4);
01208       }
01209       else cbut[icbut]->SetFillColor(5);
01210       cbut[icbut]->SetTextSize(0.5);
01211       cbut[icbut]->Draw();
01212     }
01213 
01214     fCanvas1->cd();
01215     fHistcolz = new TPad("fHistcolz","UZ and VZ views",0.05,0.05,0.525,1);
01216     fHistcolz->Draw();
01217     fHistcolz->cd();
01218     fHistcolz->Divide(1,2);
01219     fHistcolz->cd(1);
01220     fUZcolz = new TH2D("UZcolz","Strip vs. Plane, U view",1,0,1,1,0,1);
01221     //fUZcolz->SetTitle("Strip vs. Plane, U view");
01222     //fUZcolz->SetBins(1,0,1,1,0,1);
01223     fUZcolz->SetStats(false);
01224     fUZcolz->SetXTitle("z(m)");
01225     fUZcolz->SetYTitle("u(m)");
01226     fUZcolz->GetYaxis()->SetTitleOffset(0.6);
01227     fUZcolz->Draw("colz");
01228     srvtx_u->Draw();
01229     //mcvtx_u->Draw();
01230 
01231     fHistcolz->cd(2);
01232     fVZcolz = new TH2D("VZcolz","Strip vs. Plane, V view",1,0,1,1,0,1);
01233     fVZcolz->SetStats(false);
01234     fVZcolz->SetXTitle("z(m)");
01235     fVZcolz->SetYTitle("v(m)");
01236     fVZcolz->GetYaxis()->SetTitleOffset(0.6);
01237     //fVZcolz->SetTitle("Strip vs. Plane, V view");
01238     //fVZcolz->SetBins(1,0,1,1,0,1);
01239     fVZcolz->Draw("colz");
01240     srvtx_v->Draw();
01241     //mcvtx_v->Draw();
01242     
01243     fCanvas1->cd();
01244     fHistlego = new TPad("fHistlego","UZ and VZ views",0.525,0.05,1,1);
01245     fHistlego->Draw();
01246     fHistlego->cd();
01247     fHistlego->Divide(1,2);
01248     fHistlego->cd(1);
01249     fUZlego = new TH2D("UZlego","Strip vs. Plane, U view",1,0,1,1,0,1);
01250     fUZlego->SetStats(false);
01251     //fUZlego->SetName("fUZlego");
01252     //fUZlego->SetTitle("Strip vs. Plane, U view");
01253     //fUZlego->SetBins(1,0,1,1,0,1);
01254     fUZlego->Draw("lego2");
01255     fHistlego->cd(2);
01256     fVZlego = new TH2D("VZlego","Strip vs. Plane, V view",1,0,1,1,0,1);
01257     fVZlego->SetStats(false);
01258     //fVZlego->SetName("fVZlego");
01259     //fVZlego->SetTitle("Strip vs. Plane, V view");
01260     //fVZlego->SetBins(1,0,1,1,0,1);
01261     fVZlego->Draw("lego2");
01262 
01263     fCanvas1->cd();
01264     fBL = new TPad("fBL","Button Panel for lego display",0.525,0,1,0.05);
01265     fBL->Draw();
01266     fBL->cd();
01267 
01268     //add buttons to rotate lego plots
01269     lbut[0] = new TButton("Pan view","fHistlego->cd(1);gPad->SetPhi(30);gPad->SetTheta(30);gPad->Modified();fHistlego->cd(2);gPad->SetPhi(30);gPad->SetTheta(30);gPad->Modified();for(int i=0;i<4;i++){TButton *lbut=(TButton*)fBL->FindObject(Form(\"lbut%d\",i));if(i==0) lbut->SetFillColor(4); else lbut->SetFillColor(5);lbut->Paint();}",0.1,0,0.22,1);
01270     lbut[0]->SetName("lbut0");
01271     lbut[1] = new TButton("Side view","fHistlego->cd(1);gPad->SetPhi(15);gPad->SetTheta(30);gPad->Modified();fHistlego->cd(2);gPad->SetPhi(15);gPad->SetTheta(30);gPad->Modified();for(int i=0;i<4;i++){TButton *lbut=(TButton*)fBL->FindObject(Form(\"lbut%d\",i));if(i==1) lbut->SetFillColor(4); else lbut->SetFillColor(5);lbut->Paint();}",0.23,0,0.35,1);
01272     lbut[1]->SetName("lbut1");
01273     lbut[2] = new TButton("Front view","fHistlego->cd(1);gPad->SetPhi(75);gPad->SetTheta(60);gPad->Modified();fHistlego->cd(2);gPad->SetPhi(75);gPad->SetTheta(60);gPad->Modified();for(int i=0;i<4;i++){TButton *lbut=(TButton*)fBL->FindObject(Form(\"lbut%d\",i));if(i==2) lbut->SetFillColor(4); else lbut->SetFillColor(5);lbut->Paint();}",0.36,0,0.48,1);
01274     lbut[2]->SetName("lbut2");
01275     lbut[3] = new TButton("Top view","fHistlego->cd(1);gPad->SetPhi(30);gPad->SetTheta(75);gPad->Modified();fHistlego->cd(2);gPad->SetPhi(30);gPad->SetTheta(75);gPad->Modified();for(int i=0;i<4;i++){TButton *lbut=(TButton*)fBL->FindObject(Form(\"lbut%d\",i));if(i==3) lbut->SetFillColor(4); else lbut->SetFillColor(5);lbut->Paint();}",0.49,0,0.61,1);
01276     lbut[3]->SetName("lbut3");
01277     //lbut[4] = new TButton("Fix","",0.64,0,0.76,1);
01278     for (int ilbut = 0; ilbut<4; ilbut++){
01279       if (ilbut == 0){
01280         lbut[ilbut]->SetFillColor(4);
01281       }
01282       else lbut[ilbut]->SetFillColor(5);
01283       lbut[ilbut]->SetTextSize(0.5);
01284       lbut[ilbut]->Draw();
01285     }
01286 
01287     fCanvas1->cd();
01288     fStdLeg = new TPad("fStdLeg","legend",0,0,0.525,0.05);
01289     fStdLeg->Draw();
01290     fStdLeg->cd();
01291     
01292     //copied Chris' code
01293     TLine *line;
01294     line = new TLine(0.01,0.5,0.04,0.5);
01295     line->SetLineColor(3);
01296     line->SetLineWidth(2);
01297     line->Draw();
01298     line = new TLine(0.11,0.5,0.14,0.5);
01299     line->SetLineColor(4);
01300     line->SetLineWidth(2);
01301     line->Draw();
01302     line = new TLine(0.21,0.5,0.24,0.5);
01303     line->SetLineColor(2);
01304     line->SetLineWidth(2);
01305     line->Draw();
01306     line = new TLine(0.31,0.5,0.34,0.5);
01307     line->SetLineColor(28);
01308     line->SetLineWidth(2);
01309     line->Draw();
01310     line = new TLine(0.41,0.5,0.44,0.5);
01311     line->SetLineColor(6);
01312     line->SetLineWidth(2);
01313     line->Draw();
01314     line = new TLine(0.51,0.5,0.54,0.5);
01315     line->SetLineColor(7);
01316     line->SetLineWidth(2);
01317     line->Draw();
01318     line = new TLine(0.61,0.5,0.64,0.5);
01319     line->SetLineColor(31);
01320     line->SetLineWidth(2);
01321     line->Draw();
01322     line = new TLine(0.71,0.5,0.74,0.5);
01323     line->SetLineColor(9);
01324     line->SetLineWidth(2);
01325     line->Draw();
01326     line = new TLine(0.81,0.5,0.84,0.5);
01327     line->SetLineColor(5);
01328     line->SetLineWidth(2);
01329     line->Draw();
01330     line = new TLine(0.91,0.5,0.94,0.5);
01331     line->SetLineColor(1);
01332     line->SetLineWidth(2);
01333     line->SetLineStyle(2);
01334     line->Draw();
01335 
01336 
01337     TLatex *tex;
01338     tex = new TLatex(0.06,0.3,"e");
01339     tex->SetTextFont(132);
01340     tex->SetTextSize(0.7);
01341     tex->Draw();
01342     tex = new TLatex(0.16,0.3,"#mu");
01343     tex->SetTextFont(132);
01344     tex->SetTextSize(0.7);
01345     tex->Draw();
01346     tex = new TLatex(0.26,0.3,"p");
01347     tex->SetTextFont(132);
01348     tex->SetTextSize(0.7);
01349     tex->Draw();
01350     tex = new TLatex(0.36,0.3,"n");
01351     tex->SetTextFont(132);
01352     tex->SetTextSize(0.7);
01353     tex->Draw();
01354     tex = new TLatex(0.46,0.3,"#pi^{+/-}");
01355     tex->SetTextFont(132);
01356     tex->SetTextSize(0.7);
01357     tex->Draw();
01358     tex = new TLatex(0.56,0.3,"#pi^{0}");
01359     tex->SetTextFont(132);
01360     tex->SetTextSize(0.7);
01361     tex->Draw();
01362     tex = new TLatex(0.66,0.3,"K^{+/-/0}");
01363     tex->SetTextFont(132);
01364     tex->SetTextSize(0.7);
01365     tex->Draw();
01366     tex = new TLatex(0.76,0.3,"#gamma");
01367     tex->SetTextFont(132);
01368     tex->SetTextSize(0.7);
01369     tex->Draw();
01370     tex = new TLatex(0.86,0.3,"tau");
01371     tex->SetTextFont(132);
01372     tex->SetTextSize(0.7);
01373     tex->Draw();
01374     tex = new TLatex(0.96,0.3,"#nu");
01375     tex->SetTextFont(132);
01376     tex->SetTextSize(0.7);
01377     tex->Draw();
01378 
01379     gPad->Modified();
01380     fCanvas1->Update();
01381 
01382     fCanvas2->cd(1);
01383     fFracVar_plots = new TPad("fFracVar_plots","FracVar",0,0,1,1);
01384     fFracVar_plots->Draw();
01385     fFracVar_plots->Divide(1,2);
01386     fCanvas2->cd(2);
01387     fReco_plots = new TPad("fReco_plots","Reco",0,0,1,1);
01388     fReco_plots->Draw();
01389     fReco_plots->Divide(1,2);
01390     fReco_plots->cd(1);
01391     fSlcUZ->SetXTitle("z(m)");
01392     fSlcUZ->SetYTitle("u(m)");
01393     fSlcUZ->GetYaxis()->SetTitleOffset(0.6);
01394     fSlcUZ->Draw("colz");
01395     fShwUZ->SetMaximum(1);
01396     fShwUZ->SetMinimum(0);
01397     fShwUZ->Draw("box same");
01398     fTrkUZ->SetMaximum(1);
01399     fTrkUZ->SetMinimum(0);
01400     fTrkUZ->Draw("box same");
01401 
01402     fReco_plots->cd(2);
01403     fSlcVZ->SetXTitle("z(m)");
01404     fSlcVZ->SetYTitle("v(m)");
01405     fSlcVZ->GetYaxis()->SetTitleOffset(0.6);
01406     fSlcVZ->Draw("colz");
01407     fShwVZ->SetMaximum(1);
01408     fShwVZ->SetMinimum(0);
01409     fShwVZ->Draw("box same");
01410     fTrkVZ->SetMaximum(1);
01411     fTrkVZ->SetMinimum(0);
01412     fTrkVZ->Draw("box same");
01413 
01414     fShwfit_plots = fCanvas3;
01415 
01416     fAngClusterFitAna_plots = fCanvas4;
01417 
01418     if(kIntReco) {
01419       fCanvas6->cd();      
01420       fCanvas6->SetName("fCanvas6");
01421       fCanvas6->Divide(2,2);
01422       fCanvas6->SetFillColor(42);
01423       fCanvas6->cd(1);
01424       gPad->Range(0,0,1,1);
01425       fCanvas6->cd(2);
01426       gPad->Range(0,0,1,1);
01427       fCanvas6->cd(3);
01428       gPad->Range(0,0,1,1);
01429       fCanvas6->cd(4);
01430       gPad->Range(0,0,1,1);
01431 
01432       fCanvas6->cd(2);
01433       fIntRecoHistU = new TH1F("IntRecoHistU","Interactively Reconstructed Shower - Transverse View",1,0,1);
01434       fIntRecoHistU->SetXTitle("Transverse distance from event vertex (m)");
01435       fIntRecoHistU->SetYTitle("Summed PH (PE)");
01436       fIntRecoHistU->SetLineColor(4);
01437       fIntRecoHistU->SetStats(0);
01438       fIntRecoHistV = new TH1F("IntRecoHistV","Interactively Reconstructed Shower - Transverse View",1,0,1);
01439       fIntRecoHistV->SetXTitle("Transverse distance from event vertex (m)");
01440       fIntRecoHistV->SetYTitle("Summed PH (PE)");
01441       fIntRecoHistV->SetLineColor(6);
01442       fIntRecoHistV->SetStats(0);
01443 
01444       fPredictedHistU = new TH1F("PredictedHistU","Interactively Reconstructed Shower - Transverse View",1,0,1);
01445       fPredictedHistU->SetXTitle("Transverse distance from event vertex (m)");
01446       fPredictedHistU->SetYTitle("Summed PH (PE)");
01447       fPredictedHistU->SetLineColor(4);
01448       fPredictedHistU->SetStats(0); 
01449       fPredictedHistV = new TH1F("PredictedHistV","Interactively Reconstructed Shower - Transverse View",1,0,1);
01450       fPredictedHistV->SetXTitle("Transverse distance from event vertex (m)");
01451       fPredictedHistV->SetYTitle("Summed PH (PE)");
01452       fPredictedHistV->SetLineColor(6);
01453       fPredictedHistV->SetStats(0);
01454 
01455       fPredictedHistU->Draw();
01456       fPredictedHistV->Draw("sames");
01457       fIntRecoHistU->Draw("e1sames");
01458       fIntRecoHistV->Draw("e1sames");
01459 
01460       fCanvas6->cd(4);
01461       fIntRecoHistZ = new TH1F("IntRecoHistZ","Interactively Reconstructed Shower - Longitudinal View",1,0,1);
01462       fIntRecoHistZ->SetXTitle("Longitudinal distance from event vertex (m)");
01463       fIntRecoHistZ->SetYTitle("Summed PH (PE)");
01464       fIntRecoHistZ->SetStats(0);
01465 
01466       fPredictedHistZ = new TH1F("PredictedHistZ","Interactively Reconstructed Shower - Longitudinal View",1,0,1);
01467       fPredictedHistZ->SetXTitle("Longitudinal distance from event vertex (m)");
01468       fPredictedHistZ->SetYTitle("Summed PH (PE)");
01469       fPredictedHistZ->SetLineColor(2);
01470       fPredictedHistZ->SetStats(0);
01471       fPredictedHistZ->Draw();
01472       fIntRecoHistZ->Draw("e1sames");
01473 
01474       fUZPred = new TH2F("PredictedHistUZ","EM Prediction Based on Interactive Reconstruction - UZ View",1,0,1,1,0,1);
01475       fUZPred->SetXTitle("Plane");
01476       fUZPred->SetYTitle("U Strip");
01477       fUZPred->SetZTitle("Normalised PH");
01478       fUZPred->SetStats(0);
01479       fVZPred = new TH2F("PredictedHistVZ","EM Prediction Based on Interactive Reconstruction - VZ View",1,0,1,1,0,1);
01480       fVZPred->SetXTitle("Plane");
01481       fVZPred->SetYTitle("V Strip");
01482       fVZPred->SetZTitle("Normalised PH");      
01483       fVZPred->SetStats(0);
01484 
01485       fCanvas6->cd(1);
01486       fUZPred->Draw("COLZ");
01487       fCanvas6->cd(3);
01488       fVZPred->Draw("COLZ");
01489 
01490       fCanvas7->SetName("fCanvas7");
01491       fCanvas7->cd();
01492       fCanvas7->SetFillColor(42);
01493       fSelectPad1 = new SelectPad("fSelPad1","fSelPad1",
01494                                   0.01,0.505,0.99,0.99);
01495       fSelectPad1->Draw();      
01496       fSelectPad2 = new SelectPad("fSelPad2","fSelPad2",
01497                                   0.01,0.01,0.99,0.495);
01498       fSelectPad2->Draw();
01499       fSelectPad2->cd();
01500       fIntRecoDoSim = new TButton("Do Sim","TButton *but = (TButton*) fSelPad2->FindObject(\"IntRecoDoSimButton\");if(but->GetFillColor()==2) but->SetFillColor(3); else but->SetFillColor(2);but->Paint();",0.01,0.04,0.075,0.15);
01501       fIntRecoDoSim->SetName("IntRecoDoSimButton");
01502       fIntRecoDoSim->SetFillColor(2);
01503       fIntRecoDoSim->Draw();
01504     }
01505 
01506     fCanvas8->cd(1);
01507     TimeHst = new THStack("TimeHist",
01508                           "Digit Times (ns) Red - Trk, Blue - Shw");
01509     TimeHstTrk = new TH1F();
01510     TimeHstTrk->SetName("TimeHstTrk");
01511     TimeHstShw = new TH1F();
01512     TimeHstShw->SetName("TimeHstShw");
01513 
01514     TimeHst->Add(TimeHstTrk);
01515     TimeHst->Add(TimeHstShw);
01516     TimeHst->Draw("nostack");
01517 
01518     fCanvas8->cd(2);
01519     TimeHstUV = new THStack("TimeHistUV",
01520                             "UV Digit Times (ns) Red - Trk, Blue - Shw");
01521     TimeHstTrkU = new TH1F();
01522     TimeHstTrkU->SetName("TimeHstTrkU");
01523     TimeHstTrkV = new TH1F();
01524     TimeHstTrkV->SetName("TimeHstTrkV");
01525     TimeHstShwU = new TH1F();
01526     TimeHstShwU->SetName("TimeHstShwU");
01527     TimeHstShwV = new TH1F();
01528     TimeHstShwV->SetName("TimeHstShwV");
01529 
01530     TimeHstUV->Add(TimeHstTrkU);
01531     TimeHstUV->Add(TimeHstTrkV);
01532     TimeHstUV->Add(TimeHstShwU);
01533     TimeHstUV->Add(TimeHstShwV);
01534     TimeHstUV->Draw("nostack");
01535     
01536     fCanvas8->cd(3);
01537     TimeHst2 = new THStack("TimeHist2",
01538                            "Digit Times (ns) after prop. cor. Red - Trk, Blue - Shw");
01539     TimeHstTrk2 = new TH1F();
01540     TimeHstTrk2->SetName("TimeHstTrk2");
01541     TimeHstShw2 = new TH1F();
01542     TimeHstShw2->SetName("TimeHstShw2");
01543     
01544     TimeHst2->Add(TimeHstTrk2);
01545     TimeHst2->Add(TimeHstShw2);
01546     TimeHst2->Draw("nostack");
01547 
01548     TLatex *tmptextrk = new TLatex(0.6,0.85,"tmp");
01549     tmptextrk->SetName("tmptextrk");
01550     tmptextrk->SetTextColor(4);
01551     tmptextrk->Draw();
01552 
01553     fCanvas8->cd(4);
01554     TimeHst2UV = new THStack("TimeHist2UV",
01555                              "UV Digit Times (ns) after prop. cor. Red - Trk, Blue - Shw");
01556     TimeHstTrk2U = new TH1F();
01557     TimeHstTrk2U->SetName("TimeHstTrk2U");
01558     TimeHstTrk2V = new TH1F();
01559     TimeHstTrk2V->SetName("TimeHstTrk2V");
01560     TimeHstShw2U = new TH1F();
01561     TimeHstShw2U->SetName("TimeHstShw2U");
01562     TimeHstShw2V = new TH1F();
01563     TimeHstShw2V->SetName("TimeHstShw2V");
01564 
01565     TimeHst2UV->Add(TimeHstTrk2U);
01566     TimeHst2UV->Add(TimeHstTrk2V);
01567     TimeHst2UV->Add(TimeHstShw2U);
01568     TimeHst2UV->Add(TimeHstShw2V);
01569     TimeHst2UV->Draw("nostack");
01570 
01572 
01573     fCanvas9->cd(2);
01574 
01575     for(int i =0; i < 6; i++) place[i] = new TBox(0,0,0,0);
01576     place[0]->SetFillColor(kMagenta);
01577     place[1]->SetFillColor(kRed);
01578     place[2]->SetFillColor(kBlack);
01579     place[3]->SetFillColor(kBlue);
01580     place[4]->SetFillColor(kCyan);
01581     place[5]->SetFillColor(kGreen);
01582 
01583     leg = new TLegend(0.8,0.49,0.99,0.99);
01584     leg->SetFillColor(0);
01585     leg->AddEntry(place[0], "Earlier", "f");
01586     leg->AddEntry(place[1], "Previous", "f");
01587     leg->AddEntry(place[2], "Current", "f");
01588     leg->AddEntry(place[3], "Next", "f");
01589     leg->AddEntry(place[4], "Later", "f");
01590     leg->Draw();
01591 
01592     fCanvas9->cd(3);
01593 
01594     char cmd1[100];  char cmd2[100];  char cmd3[100];
01595     sprintf(cmd1, "gROOT->ProcessLineSync(\"((NueDisplayModule*)%p)->AdjustOverlayRange(1);\");", (void*)this);
01596     sprintf(cmd2, "gROOT->ProcessLineSync(\"((NueDisplayModule*)%p)->AdjustOverlayRange(2);\");", (void*)this); 
01597     sprintf(cmd3, "gROOT->ProcessLineSync(\"((NueDisplayModule*)%p)->AdjustOverlayRange(-1);\");", (void*)this);
01598     
01599     fCanvas9->cd();
01600     fPlusMinusOne = new TButton("+-One",cmd1,0,0.01,0.04,0.05);
01601     fPlusMinusTwo = new TButton("+-Two",cmd2,0.,0.06,0.04,0.10);
01602     fFullSnarl = new TButton("All",cmd3,0,0.11,0.04,0.15);
01603 
01604     fPlusMinusOne->Draw();
01605     fPlusMinusTwo->Draw();
01606     fFullSnarl->Draw();
01608 
01609     //set up the buttons in MR pad1
01610     fMRCanvas1->cd();
01611     
01612     mrInfoPanel = new TPad("Info0","Basic information",0.0,0.0,0.149,1);
01613     mrInfoPanel->Draw();
01614     mrInfoPanel->cd();
01615    
01616     char mrcmd1[100];
01617     sprintf(mrcmd1, "gROOT->ProcessLineSync(\"((NueDisplayModule*)%p)->MRShowEvent(0);\");", (void*)this);
01618     fMRuShowAll = new TButton("New",mrcmd1,0,0.85,0.33,0.89);
01619 
01620     sprintf(mrcmd1, "gROOT->ProcessLineSync(\"((NueDisplayModule*)%p)->MRShowEvent(1);\");", (void*)this);
01621     fMRuShowMR  = new TButton("MR",mrcmd1,0.,0.90,0.33,0.94);
01622 
01623     sprintf(mrcmd1, "gROOT->ProcessLineSync(\"((NueDisplayModule*)%p)->MRShowEvent(2);\");", (void*)this);
01624     fMRuShowOld = new TButton("Orig",mrcmd1,0,0.95,0.33,0.99);
01625 
01626     fMRuShowAll->Draw();
01627     fMRuShowMR->Draw();
01628     fMRuShowOld->Draw();
01629 
01630     sprintf(mrcmd1, "gROOT->ProcessLineSync(\"((NueDisplayModule*)%p)->MRShowMRStrips(0);\");", (void*)this);
01631     fMRdShowAll = new TButton("All",mrcmd1, 0 ,0.21,0.33,0.25);
01632       
01633     sprintf(mrcmd1, "gROOT->ProcessLineSync(\"((NueDisplayModule*)%p)->MRShowMRStrips(1);\");", (void*)this);
01634     fMRdShowTrueMu = new TButton("TruMu",mrcmd1,0,0.16,0.33,0.20);
01635 
01636     sprintf(mrcmd1, "gROOT->ProcessLineSync(\"((NueDisplayModule*)%p)->MRShowMRStrips(2);\");", (void*)this);
01637     fMRdShowTrueShw = new TButton("TruShw",mrcmd1,0.0,0.11,0.33,0.15);
01638 
01639     sprintf(mrcmd1, "gROOT->ProcessLineSync(\"((NueDisplayModule*)%p)->MRShowMRStrips(3);\");", (void*)this);
01640     fMRdShowScaled = new TButton("Scaled",mrcmd1,0,0.06,0.33,0.10);
01641 
01642     sprintf(mrcmd1, "gROOT->ProcessLineSync(\"((NueDisplayModule*)%p)->MRShowMRStrips(4);\");", (void*)this);
01643     fMRdShowReco = new TButton("Reco",mrcmd1,0.0,0.01,0.33,0.05);
01644 
01645     fMRdShowAll->Draw();
01646     fMRdShowTrueMu->Draw();
01647     fMRdShowTrueShw->Draw();
01648     fMRdShowScaled->Draw();
01649     fMRdShowReco->Draw();
01650 
01651     mrInfoPanel->Draw();
01652     
01653     /* reusing the boxes from above
01654     place[0]->SetFillColor(kMagenta);
01655     place[1]->SetFillColor(kRed);
01656     place[2]->SetFillColor(kBlack);
01657     place[3]->SetFillColor(kBlue);
01658     place[4]->SetFillColor(kCyan);
01659     */
01660 
01661 //    fMRCanvas1->cd(2);
01662     fMRUpperLeg = new TLegend(0.35,0.85,0.99,0.99);
01663     fMRUpperLeg->SetFillColor(0);
01664     fMRUpperLeg->AddEntry(place[3], "Original", "f");
01665     fMRUpperLeg->AddEntry(place[1], "MR Strips", "f");
01666     fMRUpperLeg->AddEntry(place[5], "New Event", "f");
01667     fMRUpperLeg->SetTextSize(0.1);
01668     fMRUpperLeg->SetBorderSize(1);
01669     fMRUpperLeg->Draw();
01670 
01671 //    fMRCanvas1->cd(4);
01672     fMRLowerLeg = new TLegend(0.35,0.01,0.99,0.2);
01673     fMRLowerLeg->SetFillColor(0);
01674     fMRLowerLeg->AddEntry(place[1], "True Mu", "f");
01675     fMRLowerLeg->AddEntry(place[5], "True Shw", "f");
01676     fMRLowerLeg->AddEntry(place[3], "Scaled", "f");
01677     fMRLowerLeg->AddEntry(place[4], "Reco", "f");
01678     fMRLowerLeg->SetTextSize(0.1);
01679     fMRLowerLeg->SetBorderSize(1);
01680     fMRLowerLeg->Draw();
01681    
01683 
01684     fMRCanvas1->cd();
01685     mrGraphPad = new TPad("Info0","mrgraphs",0.15,0.0,1,1);
01686     mrGraphPad->Draw();
01687     mrGraphPad->Divide(2,2);
01688                                                                                 
01689     mrGraphPad->Draw();
01690 
01691 
01692     fEvent = 0;    
01693 }
01694 
01695 static void clear_hist(TH2D* hist)
01696 {
01697     hist->Reset();
01698     hist->GetXaxis()->UnZoom();
01699     hist->GetYaxis()->UnZoom();
01700     hist->SetMaximum(-1111);
01701     hist->SetMinimum(-1111);
01702 }
01703 
01704 void NueDisplayModule::UpdateDisplay(bool /*foundnr*/, bool /*foundpid*/)
01705 {
01706   MSG("NueDisplayModule",Msg::kDebug)<<"In UpdateDisplay"<<endl;
01707   
01708   int run=0, subrun = 0, snarl = 0, evt = 0;
01709   DataUtil::GetRunSnarlEvent(&(gMint->GetJobC().Mom),run,snarl,evt);
01710   RecRecordImp<RecCandHeader> *rr = 
01711     dynamic_cast<RecRecordImp<RecCandHeader>*>
01712     ((gMint->GetJobC().Mom).GetFragment("RecRecordImp<RecCandHeader>"));
01713   if ( rr ) {
01714     subrun   = rr->GetHeader().GetSubRun();
01715     fDetectorType = rr->GetHeader().GetVldContext().GetDetector();
01716     fSimFlag = rr->GetHeader().GetVldContext().GetSimFlag();
01717   }
01718   RunNo = run;
01719   SubRunNo = subrun;
01720 
01721   clear_hist(fUZview);
01722   clear_hist(fVZview);
01723   clear_hist(fTrkUZ);
01724   clear_hist(fTrkVZ);
01725   clear_hist(fShwUZ);
01726   clear_hist(fShwVZ);
01727   clear_hist(fSlcUZ);
01728   clear_hist(fSlcVZ);
01729   clear_hist(fUZcolz);
01730   clear_hist(fVZcolz);
01731   clear_hist(fUZlego);
01732   clear_hist(fVZlego);
01733   fUVview->Clear();
01734   fInfo0->Clear();
01735   ftrkshw->Reset();
01736 
01737   if (TimeHst){
01738     TimeHst->RecursiveRemove(TimeHstTrk);
01739     TimeHst->RecursiveRemove(TimeHstShw);
01740     delete TimeHst;
01741     TimeHst = NULL;
01742   }
01743   if(TimeHstUV){
01744     TimeHstUV->RecursiveRemove(TimeHstTrkU);
01745     TimeHstUV->RecursiveRemove(TimeHstTrkV);
01746     TimeHstUV->RecursiveRemove(TimeHstShwU);
01747     TimeHstUV->RecursiveRemove(TimeHstShwV);
01748     delete TimeHstUV;
01749     TimeHstUV = NULL;
01750   }
01751 
01752   TimeHstTrk->Reset();
01753   TimeHstTrk->SetLineColor(2);
01754   TimeHstTrkU->Reset();
01755   TimeHstTrkU->SetLineColor(2);
01756   TimeHstTrkU->SetFillColor(2);
01757   TimeHstTrkU->SetFillStyle(3004);
01758   TimeHstTrkV->Reset();
01759   TimeHstTrkV->SetLineColor(46);
01760   TimeHstTrkV->SetFillColor(46);
01761   TimeHstTrkV->SetFillStyle(3005);
01762   TimeHstShw->Reset();
01763   TimeHstShw->SetLineColor(4);
01764   TimeHstShwU->Reset();
01765   TimeHstShwU->SetLineColor(4);
01766   TimeHstShwU->SetFillColor(4);
01767   TimeHstShwU->SetFillStyle(3004);
01768   TimeHstShwV->Reset();
01769   TimeHstShwV->SetLineColor(38);
01770   TimeHstShwV->SetFillColor(38);
01771   TimeHstShwV->SetFillStyle(3005);
01772 
01773   if (TimeHst2){
01774     TimeHst2->RecursiveRemove(TimeHstTrk2);
01775     TimeHst2->RecursiveRemove(TimeHstShw2);
01776     delete TimeHst2;
01777     TimeHst2 = NULL;
01778   }
01779   if (TimeHst2UV){
01780     TimeHst2UV->RecursiveRemove(TimeHstTrk2U);
01781     TimeHst2UV->RecursiveRemove(TimeHstTrk2V);
01782     TimeHst2UV->RecursiveRemove(TimeHstShw2U);
01783     TimeHst2UV->RecursiveRemove(TimeHstShw2V);
01784     delete TimeHst2UV;
01785     TimeHst2UV = NULL;
01786   }
01787 
01788   TimeHstTrk2->Reset();
01789   TimeHstTrk2->SetLineColor(2);
01790   TimeHstTrk2U->Reset();
01791   TimeHstTrk2U->SetLineColor(2);
01792   TimeHstTrk2U->SetFillColor(2);
01793   TimeHstTrk2U->SetFillStyle(3004);
01794   TimeHstTrk2V->Reset();
01795   TimeHstTrk2V->SetLineColor(46);
01796   TimeHstTrk2V->SetFillColor(46);
01797   TimeHstTrk2V->SetFillStyle(3005);
01798   TimeHstShw2->Reset();
01799   TimeHstShw2->SetLineColor(4);
01800   TimeHstShw2U->Reset();
01801   TimeHstShw2U->SetLineColor(4);
01802   TimeHstShw2U->SetFillColor(4);
01803   TimeHstShw2U->SetFillStyle(3004);
01804   TimeHstShw2V->Reset();
01805   TimeHstShw2V->SetLineColor(38);
01806   TimeHstShw2V->SetFillColor(38);
01807   TimeHstShw2V->SetFillStyle(3005);
01808 
01809   if (gr_dtds){
01810     delete gr_dtds;
01811     gr_dtds = NULL;
01812   }
01813 
01814   if(kDrawClu){
01815     delete cluLegU; cluLegU = NULL;
01816     delete cluLegV; cluLegV = NULL;
01817     delete ssGraphU; ssGraphU = NULL;
01818     delete ssGraphV; ssGraphV = NULL;
01819   }
01820 
01821   if(kIntReco){
01822     for(UInt_t i=0;i<fStripButtonU.size();i++){
01823       delete fStripButtonU[i];
01824     }
01825     fStripButtonU.clear();
01826     fStpIndexMapU.clear();
01827     for(UInt_t i=0;i<fStripButtonV.size();i++){
01828       delete fStripButtonV[i];
01829     }
01830     fStripButtonV.clear();
01831     fStpIndexMapV.clear();    
01832     fIntRecoHistZ->Reset();
01833     fIntRecoHistU->Reset();
01834     fIntRecoHistV->Reset();
01835     fPredictedHistZ->Reset();
01836     fPredictedHistV->Reset();
01837     fPredictedHistU->Reset();
01838     fUZPred->Reset();
01839     fVZPred->Reset();
01840     for(int i=1;i<=4;i++){
01841       fCanvas6->cd(i);
01842       gPad->Modified();
01843     }
01844     fCanvas6->Update();
01845     fSelectPad1->cd(); gPad->Modified();
01846     fSelectPad2->cd(); gPad->Modified();
01847     fCanvas7->Update();
01848   }
01849 
01850   fUZcolz->SetMinimum(0);
01851   fVZcolz->SetMinimum(0);
01852 
01853   for (int i = 0; i<4; i++){
01854     if (!i) cbut[i]->SetFillColor(4);
01855     else cbut[i]->SetFillColor(5);
01856     cbut[i]->Paint();
01857   }
01858     
01859   for (int i = 0; i<4; i++){
01860     if (!i) lbut[i]->SetFillColor(4);
01861     else lbut[i]->SetFillColor(5);
01862     lbut[i]->Paint();
01863   }
01864 
01865   fHistlego->cd(1);
01866   gPad->SetPhi(30);
01867   gPad->SetTheta(30);
01868   gPad->Modified();
01869   fHistlego->cd(2);
01870   gPad->SetPhi(30);
01871   gPad->SetTheta(30);
01872   gPad->Modified();
01873     
01874   if (imctruth||ifixmcinfo){
01875     imctruth = 0;
01876     fMCTruth->SetDown(false);
01877     this->delmc();
01878   }
01879   if (foundST) {
01880     fNumEvents = st->evthdr.nevent;
01881   }
01882   else if (foundSR) {
01883     fNumEvents = sr->evthdr.nevent;
01884   }
01885 
01886   if (clickbutton == -2 && fNumEvents){
01887     fEvent = fNumEvents-1;
01888     clickbutton = -1;
01889   }
01890   else if (clickbutton == -2){
01891     gMint->Prev();
01892     return;
01893   }
01894 
01895   if (!GetEvent(fEvent)){
01896     if (foundST){
01897       MSG("NueDisplayModule",Msg::kError)<<"Couldn't get event "<<fEvent
01898                                          <<" from Snarl "<<st->GetHeader().GetSnarl()<<endl;
01899       if (clickbutton == -1) gMint->Prev();
01900       if (clickbutton ==  1) gMint->Next();
01901       return;
01902     }
01903     else if(foundSR){
01904       MSG("NueDisplayModule",Msg::kError)<<"Couldn't get event "<<fEvent
01905                                          <<" from Snarl "<<sr->GetHeader().GetSnarl()<<endl;
01906       if (clickbutton == -1) gMint->Prev();
01907       if (clickbutton ==  1) gMint->Next();
01908       return;
01909     } 
01910   }
01911   
01912   //Determine if event passes the general cuts  
01913   bool passcuts = PassCuts();
01914   // Determine if event passes pid cuts
01915   bool passpidcuts = true;
01916   if (foundpidmatch){
01917 //    Int_t test=pid->IsNue; 
01918 //    MSG("NueDisplayModule",Msg::kDebug)<<" PID: "<< test << " kPIDCut: "<<kPIDCut<<endl;
01919 //    if (test<kPIDCut) passpidcuts = false;
01920   }
01921   // Determine if event passes shwfit cut (aka hiPh cut) 
01922   bool passShwfitCut = true;
01923 
01924   if(kLoPhNStripCut>0||kLoPhNPlaneCut>0){
01925     if (foundST){
01926       sfa.Analyze(fEvent,st);
01927     }
01928     else if (foundSR){
01929       sfa.Analyze(fEvent,sr);
01930     }    
01931 
01932     passShwfitCut = sfa.PassCuts(kLoPhNStripCut,kLoPhNPlaneCut);
01933     if(passShwfitCut) cout << " Passes Shwfit Count Cut " << endl; 
01934   }
01935 
01936   if (((passcuts&&passShwfitCut&&preselec==1)||!preselec)&&passpidcuts){ //passcuts
01937     //  if (((passcuts&&preselec==1)||!preselec)){
01938 
01939     //reseting voting stuff
01940     if (!iIO) {
01941       if (kScanMode&&clickbutton&&fSnarl>0){
01942         if (!iFileW){
01943           this->OpenFileWrite();
01944         }
01945         if (!hitlog){//if 'Log Details' was not clicked
01946           outfile<<RunNo_old<<" "<<SubRunNo_old<<" "<<fSnarl<<" "<<fEvent_old<<" "<<ievtp<<" "<<itopo<<"  "<<fComment->GetText()<<endl;
01947           fComment->Clear();
01948           if (RunNo_old!=RunNo || SubRunNo_old!=SubRunNo){
01949             RunNo_old = RunNo;
01950             SubRunNo_old = SubRunNo;
01951           }
01952         }
01953       }
01954       ievtp = 0;
01955       itopo = 0;
01956     }
01957     updateEncoded();
01958     if (!icomm && hitlog) outfile<<endl;
01959     hitlog = 0;
01960     icomm = 0;
01961     fEvent_old = fEvent;
01962     Analyze(fEvent);
01963 
01964     GetBasicInfo();
01965 
01966     if(kDrawClu){
01967       fCanvas5->cd(1);
01968       fUZcolz->Draw("COLZ");
01969       fCanvas5->cd(4);
01970       fVZcolz->Draw("COLZ");
01971       fCanvas5->cd(2);
01972       if(ssGraphU) ssGraphU->Draw("AP");
01973       fCanvas5->cd(3);
01974       if(cluLegU) cluLegU->Draw();
01975       fCanvas5->cd(5);
01976       if(ssGraphV) ssGraphV->Draw("AP");
01977       fCanvas5->cd(6);
01978       if(cluLegV) cluLegV->Draw();    
01979       fCanvas5->Update();
01980       fCanvas5->Modified();
01981     }
01982 
01983     fHistPad->cd(1);
01984     gPad->Modified();
01985     fHistPad->cd(2);
01986     gPad->Modified();
01987     fUVview->cd();
01988     fSteelOutline->Draw();
01989     if (fDetectorType == Detector::kFar) {
01990       VS->Draw();
01991       coil->Draw();
01992     }
01993     if (fDetectorType == Detector::kNear){
01994       fu1_outline->Draw();
01995       fu2_outline->Draw();
01996       fv1_outline->Draw();
01997       fv2_outline->Draw();
01998       pu1_outline->Draw();
01999       //pu2_outline->Draw();
02000       pv1_outline->Draw();
02001       //pv2_outline->Draw();
02002     }
02003     ftrkshw->SetMarkerStyle(20);
02004     ftrkshw->SetMarkerColor(2);
02005     ftrkshw->SetMarkerSize(0.4);
02006     ftrkshw->Draw("y:x","type>0","same");
02007     ftrkshw->SetMarkerColor(3);
02008     ftrkshw->Draw("y:x","type<0","same");
02009     srvtx_xy->Draw("same");
02010     gPad->Modified();
02011 
02012     fInfo0->cd();
02013     info1->Draw();
02014     info2->Draw();
02015     info3->Draw();
02016     info4->Draw();
02017     info41->Draw();
02018     info5->Draw();
02019     //info6->Draw();
02020     gPad->Modified();
02021     fCanvas0->Update();
02022 
02023     fHistcolz->cd(1);
02024     gPad->Modified();
02025     fHistcolz->cd(2);
02026     gPad->Modified();
02027     fHistlego->cd(1);
02028     gPad->Modified();
02029     fHistlego->cd(2);
02030     gPad->Modified();
02031     fCanvas1->Update();
02032 
02033     fEventEntry->SetText(Form("%d",fEvent));
02034     fEventNo->SetText(Form("Event: %d(%d)",fEvent,fNumEvents));
02035 
02036     
02037     if (ifixmcinfo) {this->plotmc();}
02038 
02039     fReco_plots->cd(1);
02040     fSlcUZ->GetXaxis()->SetRangeUser(lowest_z,highest_z);
02041     fSlcUZ->GetYaxis()->SetRangeUser(lowest_t0,highest_t0);
02042     gPad->Modified();
02043     fReco_plots->cd(2);
02044     fSlcVZ->GetXaxis()->SetRangeUser(lowest_z,highest_z);
02045     fSlcVZ->GetYaxis()->SetRangeUser(lowest_t1,highest_t1);
02046     gPad->Modified();
02047     fCanvas2->Update();
02048 
02049     fCanvas8->cd(1);
02050     TimeHst->Draw("nostack");    
02051     gPad->Modified();
02052     fCanvas8->cd(2);
02053     TimeHstUV->Draw("nostack");
02054     gPad->Modified();
02055 
02056     fCanvas8->cd(3);
02057     Double_t phFrac = TimeHstTrk2->Integral();
02058     if(phFrac>0) phFrac = TimeHstTrk2->GetMaximum()/phFrac;
02059     cout << "Track Timing Peak Fraction = " << phFrac << endl;
02060     phFrac = TimeHstShw2->Integral();
02061     if(phFrac>0) phFrac = TimeHstShw2->GetMaximum()/phFrac;
02062     cout << "Shower Timing Peak Fraction = " << phFrac << endl;
02063     TimeHst2->Draw("nostack");
02064     gPad->Modified();
02065 
02066     fCanvas8->cd(4);
02067     TimeHst2UV->Draw("nostack");
02068     gPad->Modified();
02069 
02070     if(false){
02071       fCanvas8->cd(2);
02072       if (gr_dtds){
02073         gPad->Clear();
02074         gr_dtds->SetMarkerStyle(20);
02075         gr_dtds->SetMarkerSize(0.5);
02076         gr_dtds->Draw("ap");
02077         tfit_dt_ds_pos->SetLineWidth(2);
02078         tfit_dt_ds_pos->SetLineColor(2);
02079         tfit_dt_ds_pos->Draw("same");
02080         tfit_dt_ds_neg->SetLineWidth(2);
02081         tfit_dt_ds_neg->SetLineColor(4);
02082         tfit_dt_ds_neg->Draw("same");
02083         gPad->Modified();
02084       }
02085       else{
02086         gPad->Clear();
02087       }
02088     }
02089     fCanvas8->Update();
02090     
02091     MSG("NueDisplayModule",Msg::kDebug)<<"Alldone with update"<<endl;
02092   }
02093   else{ 
02094     
02095     MSG("NueDisplayModule",Msg::kInfo)<<"Event does not pass cuts" << endl;
02096 
02097     info1->Clear();
02098     char text1[100];
02099     sprintf(text1,"Event did not pass cuts");
02100     info1->SetText(0.01,0.95,text1);
02101     fInfo0->cd();
02102     info1->Draw();
02103     gPad->Modified();
02104     fCanvas0->Update();
02105 
02106     if (clickbutton == -1) PrevEvent();
02107     if (clickbutton ==  1) NextEvent();
02108     
02109     return;
02110   }
02111   clickbutton = 0;
02112 
02113   fCanvas9->cd();
02114   UpdateOverlayGraphs(fEvent);
02115 
02116   fCanvas9->cd(1);
02117   if(uzSliceOverlay){
02118     uzSliceOverlay->Draw("AP");
02119     uzSliceOverlay->GetXaxis()->SetTitle("z position (m)");
02120     uzSliceOverlay->GetYaxis()->SetTitle("u Position (m)");
02121   }
02122   gPad->Modified();
02123   fCanvas9->cd(2);
02124   if(vzSliceOverlay){
02125     vzSliceOverlay->Draw("AP");
02126     vzSliceOverlay->GetXaxis()->SetTitle("z position (m)");
02127     vzSliceOverlay->GetYaxis()->SetTitle("v Position (m)");
02128   }
02129   leg->Draw();
02130 
02131   gPad->Modified();  fCanvas9->cd(3);
02132   if(uzEventOverlay){
02133     uzEventOverlay->Draw("AP");
02134     uzEventOverlay->GetXaxis()->SetTitle("z position (m)");
02135     uzEventOverlay->GetYaxis()->SetTitle("u Position (m)");
02136   }
02137   gPad->Modified(); fCanvas9->cd(4);
02138   if(vzEventOverlay){
02139     vzEventOverlay->Draw("AP");
02140     vzEventOverlay->GetXaxis()->SetTitle("z position (m)");
02141     vzEventOverlay->GetYaxis()->SetTitle("v Position (m)");
02142   }
02143   gPad->Modified();
02144 
02145   fCanvas9->Update();
02146   fCanvas9->Modified();
02147 
02148   if(foundMR){
02149     //fMRCanvas1->cd();
02150    int response = UpdateMRGraphs(fEvent);
02151 
02152    DrawUpperMRCanvas();
02153    if(response > 0){
02154       DrawLowerMRCanvas();
02155    }else
02156      {
02157         mrInfoPanel->cd();
02158         mrInfo1->SetText(0.01,0.80,"There was no MR Match");
02159         mrInfo1->SetTextSize(0.06);
02160         mrInfo1->SetTextColor(kBlack);
02161         mrInfo1->Draw();
02162      }
02163 
02164    /*
02165      fMRCanvas1->cd();
02166      fMRuShowAll->Draw();
02167      fMRuShowMR->Draw();
02168      fMRuShowOld->Draw();
02169    */                                                                                                               
02170     fMRCanvas1->Update();
02171     fMRCanvas1->Modified();
02172 
02173   }
02174   else
02175   {
02176      mrInfoPanel->cd();
02177      mrInfo1->SetText(0.01,0.80,"This Canvas is for MR Record Display");
02178      mrInfo1->SetText(0.01,0.74," No such records found");
02179 
02180      mrInfo1->SetTextSize(0.06);
02181      mrInfo1->SetTextColor(kBlack);
02182      mrInfo1->Draw();
02183   }
02184 
02185 }
02186 
02187 Int_t NueDisplayModule::GetEvent(Int_t evt){
02188 
02189   // Get Ugli for later.  Bail immediately if fail
02190   UgliGeomHandle ugh = gMint->GetUgliGeomHandle();
02191   if (! ugh.IsValid()) {
02192     MSG("NueDisplayModule",Msg::kWarning) << "Got invalid Ugli\n";
02193   }
02194 
02195   if (foundST) {
02196     event = SntpHelpers::GetEvent(evt,st);
02197   }
02198   else if(foundSR){
02199     event = SntpHelpers::GetEvent(evt,sr);
02200   }
02201 
02202   if(!event) return 0;
02203  
02204   
02205   for(int k=0; k < PHSIZE; k++) { ph0[k] = ph1[k] = -1;}
02206   SntpHelpers::FillEventEnergy(ph0, ph1, evt, st, PHSIZE);
02207 
02208   shia.SetEventEnergyArray(ph0, ph1);
02209   fva.SetEventEnergyArray(ph0, ph1);
02210   sfa.SetEventEnergyArray(ph0, ph1);
02211   hca.SetEventEnergyArray(ph0, ph1);
02212   aca.SetEventEnergyArray(ph0, ph1);
02213   acfa.SetEventEnergyArray(ph0, ph1);
02214   
02215 
02216   fUZcolz->SetBins(60,event->vtx.z-0.3,event->vtx.z+1.,
02217                      30,event->vtx.u-0.618,event->vtx.u+0.618);
02218   fVZcolz->SetBins(60,event->vtx.z-0.3,event->vtx.z+1.,
02219                    30,event->vtx.v-0.618,event->vtx.v+0.618);
02220   
02221   fUZlego->SetBins(100,event->vtx.z-0.3,event->vtx.z+1.,
02222                    30,event->vtx.u-0.618,event->vtx.u+0.618);
02223   fVZlego->SetBins(100,event->vtx.z-0.3,event->vtx.z+1.,
02224                    30,event->vtx.v-0.618,event->vtx.v+0.618);
02225   
02226   
02227   if (foundST){//ST
02228     float evthighest_plane = 0;
02229     float evtlowest_plane = 500;
02230     float evthighest_strip0 = 0;
02231     float evtlowest_strip0 = 192;
02232     float evthighest_strip1 = 0;
02233     float evtlowest_strip1 = 192;
02234     
02235     evthighest_z = 0;
02236     evtlowest_z = 30.;
02237     evthighest_t0 = -4.0;
02238     evtlowest_t0 = 4.0;
02239     evthighest_t1 = -4.0;
02240     evtlowest_t1 = 4.0;    
02241 
02242     //loop over strips to fill histograms
02243     MSG("NueDisplayModule",Msg::kDebug)<<"Looping over strips "<<event->nstrip<<endl;
02244     for(int i=0;i<event->nstrip;i++){
02245       Int_t index = SntpHelpers::GetStripIndex(i,event);
02246       NtpSRStrip *strip = SntpHelpers::GetStrip(index,st);
02247       if(!strip){
02248         MSG("NueDisplayModule",Msg::kError)<<"Couldn't get strip "<<index<<" from event 0"
02249                                            <<" in snarl "<<st->GetHeader().GetSnarl()
02250                                            <<" something has gone horribly wrong, I'll just go"
02251                                            <<" on to the next event"<<endl;
02252         return 0;
02253       }
02254       else{
02255 //      MSG("NueDisplayModule",Msg::kDebug)<<"got strip"<<endl;
02256       }
02257 
02258 
02259         if(strip->ph0.pe+strip->ph1.pe<1e-5)continue;//empty strip
02260 
02261       int tempo_pln = strip->plane;
02262       int tempo_stp = strip->strip;
02263       float tempo_tpos = strip->tpos;
02264       if(tempo_pln<evtlowest_plane) {
02265         evtlowest_plane=tempo_pln;
02266         evtlowest_z=strip->z;
02267       }
02268       if(tempo_pln>evthighest_plane) {
02269         evthighest_plane=tempo_pln;
02270         evthighest_z=strip->z;
02271       }
02272       
02273       if(strip->planeview==PlaneView::kU){
02274 //      MSG("NueDisplayModule",Msg::kDebug)<<"filling u"<<endl;
02275         fUZview->Fill(strip->z,strip->tpos,(strip->ph0.sigcor + 
02276                                             strip->ph1.sigcor)/SIGMAPMEU);
02277         if (strip->z>=event->vtx.z-0.3&&strip->z<=event->vtx.z+1.&&
02278             strip->tpos>=event->vtx.u-0.618&&strip->tpos<=event->vtx.u+0.618){
02279           fUZcolz->Fill(strip->z,strip->tpos,(strip->ph0.sigcor + 
02280                                               strip->ph1.sigcor)/SIGMAPMEU);
02281           fUZlego->Fill(strip->z,strip->tpos,(strip->ph0.sigcor + 
02282                                               strip->ph1.sigcor)/SIGMAPMEU);
02283           fStpIndexMapU[fUZcolz->FindBin(strip->z,strip->tpos)] = strip->index;
02284         }
02285         if(tempo_tpos<evtlowest_t0) {
02286           evtlowest_strip0=tempo_stp;
02287           evtlowest_t0=tempo_tpos;
02288         }
02289         if(tempo_tpos>evthighest_t0) {
02290           evthighest_strip0=tempo_stp;
02291           evthighest_t0=tempo_tpos;
02292         }
02293       }
02294       else if(strip->planeview==PlaneView::kV){
02295 //      MSG("NueDisplayModule",Msg::kDebug)<<"filling v"<<endl;
02296         fVZview->Fill(strip->z,strip->tpos,(strip->ph0.sigcor + 
02297                                             strip->ph1.sigcor)/SIGMAPMEU);
02298         if (strip->z>=event->vtx.z-0.3&&strip->z<=event->vtx.z+1.&&
02299             strip->tpos>=event->vtx.v-0.618&&strip->tpos<=event->vtx.v+0.618){
02300           fVZcolz->Fill(strip->z,strip->tpos,(strip->ph0.sigcor + 
02301                                               strip->ph1.sigcor)/SIGMAPMEU);
02302           fVZlego->Fill(strip->z,strip->tpos,(strip->ph0.sigcor + 
02303                                               strip->ph1.sigcor)/SIGMAPMEU);
02304           fStpIndexMapV[fVZcolz->FindBin(strip->z,strip->tpos)] = strip->index;
02305         }
02306         if(tempo_tpos<evtlowest_t1) {
02307           evtlowest_strip1=tempo_stp;
02308           evtlowest_t1=tempo_tpos;
02309         }
02310         if(tempo_tpos>evthighest_t1) {
02311           evthighest_strip1=tempo_stp;
02312           evthighest_t1=tempo_tpos;
02313         }
02314       }
02315     }
02316      
02317     if(evtlowest_plane-5>=0) {
02318       evtlowest_plane-=5;
02319       evtlowest_z-=5.*0.06;
02320     }
02321     else {
02322       evtlowest_plane=0;
02323       evtlowest_z=0.;
02324     }
02325 
02326     if (fDetectorType == Detector::kNear){
02327       if (evtlowest_t0 - 3.*0.041>=-4.0){
02328         evtlowest_strip0-=3;
02329         evtlowest_t0-=3.*0.041;
02330       }
02331       else {
02332         evtlowest_strip0=0;
02333         evtlowest_t0=-4.0;
02334       }
02335     }
02336     else {
02337       if (evtlowest_strip0-3>=0){
02338         evtlowest_strip0-=3;
02339         evtlowest_t0-=3.*0.041;
02340       }
02341       else {
02342         evtlowest_strip0=0;
02343         evtlowest_t0=-4.0;
02344       }
02345     }
02346 
02347     if (fDetectorType == Detector::kNear){
02348       if (evtlowest_t1 - 3.*0.041>=-4.0){
02349         evtlowest_strip1-=3;
02350         evtlowest_t1-=3.*0.041;
02351       }
02352       else {
02353         evtlowest_strip1=0;
02354         evtlowest_t1=-4.0;
02355       }
02356     }
02357     else {
02358       if (evtlowest_strip1-3>=0){
02359         evtlowest_strip1-=3;
02360         evtlowest_t1-=3.*0.041;
02361       }
02362       else {
02363         evtlowest_strip1=0;
02364         evtlowest_t1=-4.0;
02365       }
02366     }
02367 
02368     
02369     if(evthighest_plane+5<=485) {
02370       evthighest_plane+=5;
02371       evthighest_z+=5.*0.06;
02372     }
02373     else {
02374       evthighest_plane=485;
02375       evthighest_z=30.;
02376     }
02377     
02378     if(evthighest_strip0+3<=191) {
02379       evthighest_strip0+=3;
02380       evthighest_t0+=3.*0.041;
02381     }
02382     else {
02383       evthighest_strip0=191;
02384       evthighest_t0=4.0;
02385     }
02386       
02387     if(evthighest_strip1+3<=191) {
02388       evthighest_strip1+=3;
02389       evthighest_t1+=3.*0.041;
02390     }
02391     else {
02392       evthighest_strip1=191;
02393       evthighest_t1=4.0;
02394     }   
02395 
02396     //I implant the 6 parameters in the option string so they can be retrived interactively later. This is a risky trick. I hope no one will actually make use of that "options".TY
02397     char setoptions[100];
02398     sprintf(setoptions,"%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%d",evthighest_z,evtlowest_z,evthighest_t0,evtlowest_t0,evthighest_t1,evtlowest_t1,0);
02399     fUZview->SetOption(setoptions);
02400 
02401     Double_t histmax = TMath::Max(fUZview->GetMaximum(),fVZview->GetMaximum());
02402     cout<<"histmax "<<fUZview->GetMaximum()<<" "<<fVZview->GetMaximum()<<" "<<histmax<<endl;
02403     fUZview->SetMaximum(1.05*histmax);
02404     fVZview->SetMaximum(1.05*histmax);
02405     Double_t colzmax = fUZcolz->GetMaximum()>fVZcolz->GetMaximum()?fUZcolz->GetMaximum():fVZcolz->GetMaximum();
02406     fUZcolz->SetMaximum(1.05*colzmax);
02407     fVZcolz->SetMaximum(1.05*colzmax);
02408     Double_t legomax = fUZlego->GetMaximum()>fVZlego->GetMaximum()?fUZlego->GetMaximum():fVZlego->GetMaximum();
02409     fUZlego->SetMaximum(1.05*legomax);
02410     fVZlego->SetMaximum(1.05*legomax);
02411     
02412     //record track hits
02413     int ntrks = event->ntrack;
02414     if (ntrks){
02415       for (int i = 0; i<ntrks; i++){
02416         int index = SntpHelpers::GetTrackIndex(i,event);
02417         NtpSRTrack *track = SntpHelpers::GetTrack(index,st);
02418         for (int istp = 0; istp<track->nstrip; istp++){
02419           float x = track->stpx[istp];
02420           float y = track->stpy[istp];
02421           ftrkshw->Fill(x,y,1);
02422         }
02423       }
02424     }
02425 
02426     //record veto shield hits
02427     if (st->vetohdr.ishit){//projection is within boundaries of shield plane
02428       TClonesArray* shieldstparray = st->vetostp; 
02429       for (int i = 0; i<shieldstparray->GetEntries(); i++){
02430         NtpSRShieldStrip* shieldstp = dynamic_cast<NtpSRShieldStrip *>(shieldstparray->At(i));
02431         ftrkshw->Fill(shieldstp->x,shieldstp->y,-1);
02432       }
02433     }
02434 
02435     //timing histogram
02436     //find range
02437     double tmin=0, tmax=0;
02438     bool first = true;
02439     NtpSRSlice *slice = SntpHelpers::GetSlice(event->slc,st);
02440 
02441     //shamelessly stolen from Mad
02442     if (slice){//slice
02443       float highest_plane = 0;
02444       float lowest_plane = 500;
02445       float highest_strip0 = 0;
02446       float lowest_strip0 = 192;
02447       float highest_strip1 = 0;
02448       float lowest_strip1 = 192;
02449     
02450       highest_z = 0;
02451       lowest_z = 30.;
02452       highest_t0 = -4.0;
02453       lowest_t0 = 4.0;
02454       highest_t1 = -4.0;
02455       lowest_t1 = 4.0;    
02456 
02457       for (int i = 0; i<slice->nstrip; i++){//loop over strips
02458         NtpSRStrip *strip = SntpHelpers::GetStrip(slice->stp[i],st);    
02459         double t = strip->time0;
02460         if (t>-100){
02461           if (first){
02462             tmin = tmax = t;
02463             first = false;
02464           }
02465           if (t < tmin) tmin = t;
02466           if (t > tmax) tmax = t;
02467         }
02468         t = strip->time1;
02469         if (t>-100){
02470           if (first){
02471             tmin = tmax = t;
02472             first = false;
02473           }
02474           if (t < tmin) tmin = t;
02475           if (t > tmax) tmax = t;
02476         }
02477         int tempo_pln = strip->plane;
02478         int tempo_stp = strip->strip;
02479         float tempo_tpos = strip->tpos;
02480         if(tempo_pln<lowest_plane) {
02481           lowest_plane=tempo_pln;
02482           lowest_z=strip->z;
02483         }
02484         if(tempo_pln>highest_plane) {
02485           highest_plane=tempo_pln;
02486           highest_z=strip->z;
02487         }
02488 
02489         if (strip->planeview==PlaneView::kU){
02490           fSlcUZ->Fill(strip->z,strip->tpos,(strip->ph0.sigcor + 
02491                                              strip->ph1.sigcor)/SIGMAPMEU);
02492           if(tempo_tpos<lowest_t0) {
02493             lowest_strip0=tempo_stp;
02494             lowest_t0=tempo_tpos;
02495           }
02496           if(tempo_tpos>highest_t0) {
02497             highest_strip0=tempo_stp;
02498             highest_t0=tempo_tpos;
02499           }
02500         }
02501         else if (strip->planeview==PlaneView::kV){
02502           fSlcVZ->Fill(strip->z,strip->tpos,(strip->ph0.sigcor + 
02503                                              strip->ph1.sigcor)/SIGMAPMEU);
02504           if(tempo_tpos<lowest_t1) {
02505             lowest_strip1=tempo_stp;
02506             lowest_t1=tempo_tpos;
02507           }
02508           if(tempo_tpos>highest_t1) {
02509             highest_strip1=tempo_stp;
02510             highest_t1=tempo_tpos;
02511           }
02512         }
02513       }
02514       if(lowest_plane-10>=0) {
02515         lowest_plane-=10;
02516         lowest_z-=10.*0.06;
02517       }
02518       else {
02519         lowest_plane=0;
02520         lowest_z=0.;
02521       }
02522   
02523       if(lowest_strip0-5>=0) {
02524         lowest_strip0-=5;
02525         lowest_t0-=5.*0.041;
02526       }
02527       else {
02528         lowest_strip0=0;
02529         lowest_t0=-4.0;
02530       }
02531       
02532       if(lowest_strip1-5>=0) {
02533         lowest_strip1-=5;
02534         lowest_t1-=5.*0.041;
02535       }
02536       else {
02537         lowest_strip1=0;
02538         lowest_t1=-4.0;
02539       }
02540       
02541       if(highest_plane+10<=485) {
02542         highest_plane+=10;
02543         highest_z+=10.*0.06;
02544       }
02545       else {
02546         highest_plane=485;
02547         highest_z=30.;
02548       }
02549       
02550       if(highest_strip0+5<=191) {
02551         highest_strip0+=5;
02552         highest_t0+=5.*0.041;
02553       }
02554       else {
02555         highest_strip0=191;
02556         highest_t0=4.0;
02557       }
02558       
02559       if(highest_strip1+5<=191) {
02560         highest_strip1+=5;
02561         highest_t1+=5.*0.041;
02562       }
02563       else {
02564         highest_strip1=191;
02565         highest_t1=4.0;
02566       }      
02567     }
02568     // give some buffer at either end...
02569     tmin -= 50e-9;
02570     tmax += 20e-9;
02571 
02572     double eps = 1.0e-8;
02573     if (tmin == tmax) { tmin -= eps; tmax += eps; }
02574     
02575     // for far detector, suppress display of pre-trigger time interval
02576     if (fDetectorType == Detector::kFar){
02577       if ((tmax - tmin)*1e9>1500) tmin = tmax - 1500e-9;
02578     }
02579 
02580     TimeHstTrk->SetBins(100,tmin/1e-9,tmax/1e-9);
02581     TimeHstTrkU->SetBins(100,tmin/1e-9,tmax/1e-9);
02582     TimeHstTrkV->SetBins(100,tmin/1e-9,tmax/1e-9);
02583     TimeHstShw->SetBins(100,tmin/1e-9,tmax/1e-9);
02584     TimeHstShwU->SetBins(100,tmin/1e-9,tmax/1e-9);
02585     TimeHstShwV->SetBins(100,tmin/1e-9,tmax/1e-9);
02586 
02587     TimeHstTrk2->SetBins(50,0,100);
02588     TimeHstTrk2U->SetBins(50,0,100);
02589     TimeHstTrk2V->SetBins(50,0,100);
02590     TimeHstShw2->SetBins(50,0,100);
02591     TimeHstShw2U->SetBins(50,0,100);
02592     TimeHstShw2V->SetBins(50,0,100);
02593 
02594     //record track hits
02595     //int ntrks = event->ntrack;
02596     if (ntrks){//if(ntrks)
02597       int trkidx = -1;
02598       int trkplanes = -1;
02599       for (int i = 0; i<ntrks; i++){
02600         int index = SntpHelpers::GetTrackIndex(i,event);
02601         NtpSRTrack *track = SntpHelpers::GetTrack(index,st);
02602         if (track->plane.n>trkplanes){
02603           trkplanes = track->plane.n;
02604           trkidx = index;
02605         }
02606         for (int istp = 0; istp<track->nstrip; istp++){
02607           //ftrkshw->Fill(track->stpx[istp],track->stpy[istp],1);
02608           NtpSRStrip *strip = SntpHelpers::GetStrip(track->stp[istp],st);
02609           TimeHstTrk->Fill(track->stpt0[istp]/1e-9,strip->ph0.pe);
02610           TimeHstTrk->Fill(track->stpt1[istp]/1e-9,strip->ph1.pe);
02611           TimeHstTrk2->Fill((track->stpt0[istp]-tmin-(track->ds-track->stpds[istp])/3e8)/1e-9,strip->ph0.pe);
02612           TimeHstTrk2->Fill((track->stpt1[istp]-tmin-(track->ds-track->stpds[istp])/3e8)/1e-9,strip->ph1.pe);
02613           //record track strip information
02614           if(strip->planeview==PlaneView::kU){
02615             fTrkUZ->Fill(strip->z,strip->tpos,100000);//paranoia
02616 
02617             TimeHstTrkU->Fill(track->stpt0[istp]/1e-9,strip->ph0.pe);
02618             TimeHstTrkU->Fill(track->stpt1[istp]/1e-9,strip->ph1.pe);
02619             TimeHstTrk2U->Fill((track->stpt0[istp]-tmin-(track->ds-track->stpds[istp])/3e8)/1e-9,strip->ph0.pe);
02620             TimeHstTrk2U->Fill((track->stpt1[istp]-tmin-(track->ds-track->stpds[istp])/3e8)/1e-9,strip->ph1.pe);
02621           }
02622           else if(strip->planeview==PlaneView::kV){
02623             fTrkVZ->Fill(strip->z,strip->tpos,100000);
02624 
02625             TimeHstTrkV->Fill(track->stpt0[istp]/1e-9,strip->ph0.pe);
02626             TimeHstTrkV->Fill(track->stpt1[istp]/1e-9,strip->ph1.pe);
02627             TimeHstTrk2V->Fill((track->stpt0[istp]-tmin-(track->ds-track->stpds[istp])/3e8)/1e-9,strip->ph0.pe);
02628             TimeHstTrk2V->Fill((track->stpt1[istp]-tmin-(track->ds-track->stpds[istp])/3e8)/1e-9,strip->ph1.pe);
02629           }
02630         }
02631       }
02632       vector<double> spathLength;
02633       vector<double> st0;
02634       if (trkidx != -1 && fDetectorType == Detector::kNear){
02635         NtpSRTrack *track = SntpHelpers::GetTrack(trkidx,st);
02636         for (int istp = 0; istp<track->nstrip; istp++){
02637           NtpSRStrip *strip = SntpHelpers::GetStrip(track->stp[istp],st);
02638           spathLength.push_back(track->ds-track->stpds[istp]);
02639           PlexStripEndId seid(Detector::kNear,strip->plane,strip->strip,StripEnd::kWest);
02640           UgliStripHandle stripHandle = ugh.GetStripHandle(seid);
02641           float halfLength = stripHandle.GetHalfLength();
02642           const TVector3 ghitxyz(track->stpx[istp],track->stpy[istp],track->stpz[istp]);
02643           TVector3 lhitxyz = stripHandle.GlobalToLocal(ghitxyz);
02644           float fiberDist = (halfLength - lhitxyz.x() + stripHandle.ClearFiber(StripEnd::kWest) + stripHandle.WlsPigtail(StripEnd::kWest));
02645           //using strip time, I don't understand track time TJ
02646           //st0.push_back(track->stpt1[istp]-fiberDist/PropagationVelocity::Velocity());
02647           st0.push_back(strip->time1-fiberDist/PropagationVelocity::Velocity());
02648           //cout<<strip->plane<<" "<<strip->strip<<" "<<track->ds-track->stpds[istp]<<Form(" %.9f %.9f %.9f",track->stpt1[istp],strip->time1,strip->time1-fiberDist/PropagationVelocity::Velocity())<<endl;
02649         }
02650         gr_dtds = new TGraph(st0.size(),&spathLength[0],&st0[0]);
02651         tfit_dt_ds_pos -> SetParameter(0,0.0) ;
02652         gr_dtds->Fit("tfit_dt_ds_pos","QR") ;
02653         tfit_dt_ds_neg -> SetParameter(0,0.0) ;
02654         gr_dtds->Fit("tfit_dt_ds_neg","QR") ;
02655 
02656         float trms1 = 0;
02657         float trms2 = 0;
02658 
02659         for (unsigned i = 0; i<st0.size(); i++){
02660           double x,y;
02661           gr_dtds->GetPoint(i,x,y);
02662           trms1 += pow(y-tfit_dt_ds_pos->Eval(x),2);
02663           trms2 += pow(y-tfit_dt_ds_neg->Eval(x),2);
02664         }
02665         trms1/=st0.size();
02666         trms2/=st0.size();
02667         trms1=sqrt(trms1)*1e9;
02668         trms2=sqrt(trms2)*1e9;
02669         char grtitle[100];
02670         sprintf(grtitle,"dt vs ds, rms+:%.1fns rms-:%.1fns (rms+)-(rms-):%.1fns",trms1,trms2,trms1-trms2);
02671         gr_dtds->SetTitle(grtitle);
02672         gr_dtds->SetName("gr_dtds");
02673       }
02674     }
02675     
02676     //record shower hits
02677     int nshws = event->nshower;
02678     if (nshws){
02679       for (int i = 0; i<nshws; i++){
02680         int index = SntpHelpers::GetShowerIndex(i,event);
02681         NtpSRShower *shower = SntpHelpers::GetShower(index,st);
02682         for (int istp = 0; istp<shower->nstrip; istp++){
02683           NtpSRStrip *strip = SntpHelpers::GetStrip(shower->stp[istp],st);
02684           if(ReleaseType::IsCedar(fRel)||ReleaseType::IsDogwood(fRel)){
02685             TimeHstShw->Fill(shower->stpt0[istp]/1e-9,strip->ph0.pe);
02686             TimeHstShw->Fill(shower->stpt1[istp]/1e-9,strip->ph1.pe);
02687             TimeHstShw2->Fill((shower->stpt0[istp]-tmin)/1e-9,strip->ph0.pe);
02688             TimeHstShw2->Fill((shower->stpt1[istp]-tmin)/1e-9,strip->ph1.pe);
02689           }
02690           else {
02691             TimeHstShw->Fill(strip->time0/1e-9,strip->ph0.pe);
02692             TimeHstShw->Fill(strip->time1/1e-9,strip->ph1.pe);
02693             TimeHstShw2->Fill((strip->time0-tmin)/1e-9,strip->ph0.pe);
02694             TimeHstShw2->Fill((strip->time1-tmin)/1e-9,strip->ph1.pe);
02695           }
02696           //record shower strip information
02697           if(strip->planeview==PlaneView::kU){
02698             fShwUZ->Fill(strip->z,strip->tpos,100000);//paranoia
02699             if(ReleaseType::IsCedar(fRel)||ReleaseType::IsDogwood(fRel)){
02700               TimeHstShwU->Fill(shower->stpt0[istp]/1e-9,strip->ph0.pe);
02701               TimeHstShwU->Fill(shower->stpt1[istp]/1e-9,strip->ph1.pe);
02702               TimeHstShw2U->Fill((shower->stpt0[istp]-tmin)/1e-9,strip->ph0.pe);
02703               TimeHstShw2U->Fill((shower->stpt1[istp]-tmin)/1e-9,strip->ph1.pe);
02704             }
02705             else {
02706               TimeHstShwU->Fill(strip->time0/1e-9,strip->ph0.pe);
02707               TimeHstShwU->Fill(strip->time1/1e-9,strip->ph1.pe);
02708               TimeHstShw2U->Fill((strip->time0-tmin)/1e-9,strip->ph0.pe);
02709               TimeHstShw2U->Fill((strip->time1-tmin)/1e-9,strip->ph1.pe);
02710             }
02711           }
02712           else if(strip->planeview==PlaneView::kV){
02713             fShwVZ->Fill(strip->z,strip->tpos,100000);
02714             if(ReleaseType::IsCedar(fRel)||ReleaseType::IsDogwood(fRel)){
02715               TimeHstShwV->Fill(shower->stpt0[istp]/1e-9,strip->ph0.pe);
02716               TimeHstShwV->Fill(shower->stpt1[istp]/1e-9,strip->ph1.pe);
02717               TimeHstShw2V->Fill((shower->stpt0[istp]-tmin)/1e-9,strip->ph0.pe);
02718               TimeHstShw2V->Fill((shower->stpt1[istp]-tmin)/1e-9,strip->ph1.pe);
02719             }
02720             else {
02721               TimeHstShwV->Fill(strip->time0/1e-9,strip->ph0.pe);
02722               TimeHstShwV->Fill(strip->time1/1e-9,strip->ph1.pe);
02723               TimeHstShw2V->Fill((strip->time0-tmin)/1e-9,strip->ph0.pe);
02724               TimeHstShw2V->Fill((strip->time1-tmin)/1e-9,strip->ph1.pe);
02725             }
02726           }
02727         }
02728       }
02729     }
02730     TimeHst = new THStack("TimeHist",
02731                           "Digit Times (ns) Red - Trk, Blue - Shw");
02732     TimeHst->Add(TimeHstTrk);
02733     TimeHst->Add(TimeHstShw);
02734 
02735     TimeHstUV = new THStack("TimeHistUV",
02736                             "UV Digit Times (ns) Red - Trk, Blue - Shw");
02737     TimeHstUV->Add(TimeHstTrkU);
02738     TimeHstUV->Add(TimeHstTrkV);
02739     TimeHstUV->Add(TimeHstShwU);
02740     TimeHstUV->Add(TimeHstShwV);
02741 
02742     TimeHst2 = new THStack("TimeHist2",
02743                            "Digit Times (ns) after prop. cor. Red - Trk, Blue - Shw");
02744     TimeHst2->Add(TimeHstTrk2);
02745     TimeHst2->Add(TimeHstShw2);
02746 
02747     TimeHst2UV = new THStack("TimeHist2UV",
02748                            "UV Digit Times (ns) after prop. cor. Red - Trk, Blue - Shw");
02749     TimeHst2UV->Add(TimeHstTrk2U);
02750     TimeHst2UV->Add(TimeHstTrk2V);
02751     TimeHst2UV->Add(TimeHstShw2U);
02752     TimeHst2UV->Add(TimeHstShw2V);
02753   }
02754   else if (foundSR){//SR
02755     float evthighest_plane = 0;
02756     float evtlowest_plane = 500;
02757     float evthighest_strip0 = 0;
02758     float evtlowest_strip0 = 192;
02759     float evthighest_strip1 = 0;
02760     float evtlowest_strip1 = 192;
02761     
02762     evthighest_z = 0;
02763     evtlowest_z = 30.;
02764     evthighest_t0 = -4.0;
02765     evtlowest_t0 = 4.0;
02766     evthighest_t1 = -4.0;
02767     evtlowest_t1 = 4.0;    
02768     
02769     //loop over strips to fill histograms
02770     MSG("NueDisplayModule",Msg::kDebug)<<"Looping over strips "<<event->nstrip<<endl;
02771     for(int i=0;i<event->nstrip;i++){
02772       Int_t index = SntpHelpers::GetStripIndex(i,event);
02773       NtpSRStrip *strip = SntpHelpers::GetStrip(index,sr);
02774       if(!strip){
02775         MSG("NueDisplayModule",Msg::kError)<<"Couldn't get strip "<<index<<" from event 0"
02776                                            <<" in snarl "<<sr->GetHeader().GetSnarl()
02777                                            <<" something has gone horribly wrong, I'll just go"
02778                                            <<" on to the next event"<<endl;
02779         return 0;
02780       }
02781       else{
02782         MSG("NueDisplayModule",Msg::kDebug)<<"got strip"<<endl;
02783       }
02784       int tempo_pln = strip->plane;
02785       int tempo_stp = strip->strip;
02786       float tempo_tpos = strip->tpos;
02787       if(tempo_pln<evtlowest_plane) {
02788         evtlowest_plane=tempo_pln;
02789         evtlowest_z=strip->z;
02790       }
02791       if(tempo_pln>evthighest_plane) {
02792         evthighest_plane=tempo_pln;
02793         evthighest_z=strip->z;
02794       }
02795       
02796       if(strip->planeview==PlaneView::kU){
02797         MSG("NueDisplayModule",Msg::kDebug)<<"filling u"<<endl;
02798         fUZview->Fill(strip->z,strip->tpos,(strip->ph0.sigcor + 
02799                                             strip->ph1.sigcor)/SIGMAPMEU);
02800         if (strip->z>=event->vtx.z-0.3&&strip->z<=event->vtx.z+1.&&
02801             strip->tpos>=event->vtx.u-0.618&&strip->tpos<=event->vtx.u+0.618){
02802           fUZcolz->Fill(strip->z,strip->tpos,(strip->ph0.sigcor + 
02803                                               strip->ph1.sigcor)/SIGMAPMEU);
02804           fUZlego->Fill(strip->z,strip->tpos,(strip->ph0.sigcor + 
02805                                               strip->ph1.sigcor)/SIGMAPMEU);
02806           fStpIndexMapU[fUZcolz->FindBin(strip->z,strip->tpos)] = strip->index;
02807         }
02808         if(tempo_tpos<evtlowest_t0) {
02809           evtlowest_strip0=tempo_stp;
02810           evtlowest_t0=tempo_tpos;
02811         }
02812         if(tempo_tpos>evthighest_t0) {
02813           evthighest_strip0=tempo_stp;
02814           evthighest_t0=tempo_tpos;
02815         }
02816       }
02817       else if(strip->planeview==PlaneView::kV){
02818         MSG("NueDisplayModule",Msg::kDebug)<<"filling v"<<endl;
02819         fVZview->Fill(strip->z,strip->tpos,(strip->ph0.sigcor + 
02820                                             strip->ph1.sigcor)/SIGMAPMEU);
02821         if (strip->z>=event->vtx.z-0.3&&strip->z<=event->vtx.z+1.&&
02822             strip->tpos>=event->vtx.v-0.618&&strip->tpos<=event->vtx.v+0.618){
02823           fVZcolz->Fill(strip->z,strip->tpos,(strip->ph0.sigcor + 
02824                                               strip->ph1.sigcor)/SIGMAPMEU);
02825           fVZlego->Fill(strip->z,strip->tpos,(strip->ph0.sigcor + 
02826                                               strip->ph1.sigcor)/SIGMAPMEU);
02827           fStpIndexMapV[fVZcolz->FindBin(strip->z,strip->tpos)] = strip->index;
02828         }
02829         if(tempo_tpos<evtlowest_t1) {
02830           evtlowest_strip1=tempo_stp;
02831           evtlowest_t1=tempo_tpos;
02832         }
02833         if(tempo_tpos>evthighest_t1) {
02834           evthighest_strip1=tempo_stp;
02835           evthighest_t1=tempo_tpos;
02836         }
02837       }
02838     }
02839     if(evtlowest_plane-5>=0) {
02840       evtlowest_plane-=5;
02841       evtlowest_z-=5.*0.06;
02842     }
02843     else {
02844       evtlowest_plane=0;
02845       evtlowest_z=0.;
02846     }
02847 
02848     if (fDetectorType == Detector::kNear){
02849       if (evtlowest_t0 - 3.*0.041>=-4.0){
02850         evtlowest_strip0-=3;
02851         evtlowest_t0-=3.*0.041;
02852       }
02853       else {
02854         evtlowest_strip0=0;
02855         evtlowest_t0=-4.0;
02856       }
02857     }
02858     else {
02859       if (evtlowest_strip0-3>=0){
02860         evtlowest_strip0-=3;
02861         evtlowest_t0-=3.*0.041;
02862       }
02863       else {
02864         evtlowest_strip0=0;
02865         evtlowest_t0=-4.0;
02866       }
02867     }
02868 
02869     if (fDetectorType == Detector::kNear){
02870       if (evtlowest_t1 - 3.*0.041>=-4.0){
02871         evtlowest_strip1-=3;
02872         evtlowest_t1-=3.*0.041;
02873       }
02874       else {
02875         evtlowest_strip1=0;
02876         evtlowest_t1=-4.0;
02877       }
02878     }
02879     else {
02880       if (evtlowest_strip1-3>=0){
02881         evtlowest_strip1-=3;
02882         evtlowest_t1-=3.*0.041;
02883       }
02884       else {
02885         evtlowest_strip1=0;
02886         evtlowest_t1=-4.0;
02887       }
02888     }    
02889     
02890     if(evthighest_plane+5<=485) {
02891       evthighest_plane+=5;
02892       evthighest_z+=5.*0.06;
02893     }
02894     else {
02895       evthighest_plane=485;
02896       evthighest_z=30.;
02897     }
02898     
02899     if(evthighest_strip0+3<=191) {
02900       evthighest_strip0+=3;
02901       evthighest_t0+=3.*0.041;
02902     }
02903     else {
02904       evthighest_strip0=191;
02905       evthighest_t0=4.0;
02906     }
02907       
02908     if(evthighest_strip1+3<=191) {
02909       evthighest_strip1+=3;
02910       evthighest_t1+=3.*0.041;
02911     }
02912     else {
02913       evthighest_strip1=191;
02914       evthighest_t1=4.0;
02915     }       
02916 
02917     //I implant the 6 parameters in the option string so they can be retrived interactively later. This is a risky trick. I hope no one will actually make use of that "options".
02918     char setoptions[100];
02919     sprintf(setoptions,"%.1f,%.1f,%.1f,%.1f,%.1f,%.1f,%d",evthighest_z,evtlowest_z,evthighest_t0,evtlowest_t0,evthighest_t1,evtlowest_t1,0);
02920     fUZview->SetOption(setoptions);
02921 
02922     //set histogram ranges
02923     Double_t histmax = TMath::Max(fUZview->GetMaximum(),fVZview->GetMaximum());
02924     fUZview->SetMaximum(1.05*histmax);
02925     fVZview->SetMaximum(1.05*histmax);
02926     Double_t colzmax = fUZcolz->GetMaximum()>fVZcolz->GetMaximum()?fUZcolz->GetMaximum():fVZcolz->GetMaximum();
02927     fUZcolz->SetMaximum(1.05*colzmax);
02928     fVZcolz->SetMaximum(1.05*colzmax);
02929     Double_t legomax = fUZlego->GetMaximum()>fVZlego->GetMaximum()?fUZlego->GetMaximum():fVZlego->GetMaximum();
02930     fUZlego->SetMaximum(1.05*legomax);
02931     fVZlego->SetMaximum(1.05*legomax);
02932     
02933     int ntrks = event->ntrack;
02934     if (ntrks){
02935       for (int i = 0; i<ntrks; i++){
02936         int index = SntpHelpers::GetTrackIndex(i,event);
02937         NtpSRTrack *track = SntpHelpers::GetTrack(index,sr);
02938         for (int istp = 0; istp<track->nstrip; istp++){
02939           float x = track->stpx[istp];
02940           float y = track->stpy[istp];
02941           ftrkshw->Fill(x,y,1);
02942         }
02943       }
02944     }
02945 
02946     //record veto shield hits
02947     if (sr->vetohdr.ishit){//projection is within boundaries of shield plane 
02948       TClonesArray* shieldstparray = sr->vetostp; 
02949       for (int i = 0; i<shieldstparray->GetEntries(); i++){
02950         NtpSRShieldStrip* shieldstp = dynamic_cast<NtpSRShieldStrip *>(shieldstparray->At(i));
02951         ftrkshw->Fill(shieldstp->x,shieldstp->y,-1);
02952       }
02953     }
02954     //timing histogram
02955     //find range
02956     double tmin=0, tmax=0;
02957     bool first = true;
02958     NtpSRSlice *slice = SntpHelpers::GetSlice(event->slc,sr);
02959     if (slice){
02960       float highest_plane = 0;
02961       float lowest_plane = 500;
02962       float highest_strip0 = 0;
02963       float lowest_strip0 = 192;
02964       float highest_strip1 = 0;
02965       float lowest_strip1 = 192;
02966     
02967       highest_z = 0;
02968       lowest_z = 30.;
02969       highest_t0 = -4.0;
02970       lowest_t0 = 4.0;
02971       highest_t1 = -4.0;
02972       lowest_t1 = 4.0;    
02973 
02974       for (int i = 0; i<slice->nstrip; i++){
02975         NtpSRStrip *strip = SntpHelpers::GetStrip(slice->stp[i],sr);    
02976         double t = strip->time0;
02977         if (t>-100){
02978           if (first){
02979             tmin = tmax = t;
02980             first = false;
02981           }
02982           if (t < tmin) tmin = t;
02983           if (t > tmax) tmax = t;
02984         }
02985         t = strip->time1;
02986         if (t>-100){
02987           if (first){
02988             tmin = tmax = t;
02989             first = false;
02990           }
02991           if (t < tmin) tmin = t;
02992           if (t > tmax) tmax = t;
02993         }
02994         int tempo_pln = strip->plane;
02995         int tempo_stp = strip->strip;
02996         float tempo_tpos = strip->tpos;
02997         if(tempo_pln<lowest_plane) {
02998           lowest_plane=tempo_pln;
02999           lowest_z=strip->z;
03000         }
03001         if(tempo_pln>highest_plane) {
03002           highest_plane=tempo_pln;
03003           highest_z=strip->z;
03004         }
03005 
03006         if (strip->planeview==PlaneView::kU){
03007           fSlcUZ->Fill(strip->z,strip->tpos,(strip->ph0.sigcor + 
03008                                              strip->ph1.sigcor)/SIGMAPMEU);
03009           if(tempo_tpos<lowest_t0) {
03010             lowest_strip0=tempo_stp;
03011             lowest_t0=tempo_tpos;
03012           }
03013           if(tempo_tpos>highest_t0) {
03014             highest_strip0=tempo_stp;
03015             highest_t0=tempo_tpos;
03016           }
03017         }
03018         else if (strip->planeview==PlaneView::kV){
03019           fSlcVZ->Fill(strip->z,strip->tpos,(strip->ph0.sigcor + 
03020                                              strip->ph1.sigcor)/SIGMAPMEU);
03021           if(tempo_tpos<lowest_t1) {
03022             lowest_strip1=tempo_stp;
03023             lowest_t1=tempo_tpos;
03024           }
03025           if(tempo_tpos>highest_t1) {
03026             highest_strip1=tempo_stp;
03027             highest_t1=tempo_tpos;
03028           }
03029         }
03030       }
03031       if(lowest_plane-10>=0) {
03032         lowest_plane-=10;
03033         lowest_z-=10.*0.06;
03034       }
03035       else {
03036         lowest_plane=0;
03037         lowest_z=0.;
03038       }
03039   
03040       if(lowest_strip0-5>=0) {
03041         lowest_strip0-=5;
03042         lowest_t0-=5.*0.041;
03043       }
03044       else {
03045         lowest_strip0=0;
03046         lowest_t0=-4.0;
03047       }
03048       
03049       if(lowest_strip1-5>=0) {
03050         lowest_strip1-=5;
03051         lowest_t1-=5.*0.041;
03052       }
03053       else {
03054         lowest_strip1=0;
03055         lowest_t1=-4.0;
03056       }
03057       
03058       if(highest_plane+10<=485) {
03059         highest_plane+=10;
03060         highest_z+=10.*0.06;
03061       }
03062       else {
03063         highest_plane=485;
03064         highest_z=30.;
03065       }
03066       
03067       if(highest_strip0+5<=191) {
03068         highest_strip0+=5;
03069         highest_t0+=5.*0.041;
03070       }
03071       else {
03072         highest_strip0=191;
03073         highest_t0=4.0;
03074       }
03075       
03076       if(highest_strip1+5<=191) {
03077         highest_strip1+=5;
03078         highest_t1+=5.*0.041;
03079       }
03080       else {
03081         highest_strip1=191;
03082         highest_t1=4.0;
03083       }      
03084     }
03085     // give some buffer at either end...
03086     tmin -= 50e-9;
03087     tmax += 20e-9;
03088 
03089     double eps = 1.0e-8;
03090     if (tmin == tmax) { tmin -= eps; tmax += eps; }
03091     
03092     // for far detector, suppress display of pre-trigger time interval
03093     if (fDetectorType == Detector::kFar){
03094       if ((tmax - tmin)*1e9>1500) tmin = tmax - 1500e-9;
03095     }
03096 
03097     TimeHstTrk->SetBins(100,tmin/1e-9,tmax/1e-9);
03098     TimeHstTrkU->SetBins(100,tmin/1e-9,tmax/1e-9);
03099     TimeHstTrkV->SetBins(100,tmin/1e-9,tmax/1e-9);
03100     TimeHstShw->SetBins(100,tmin/1e-9,tmax/1e-9);
03101     TimeHstShwU->SetBins(100,tmin/1e-9,tmax/1e-9);
03102     TimeHstShwV->SetBins(100,tmin/1e-9,tmax/1e-9);
03103 
03104     TimeHstTrk2->SetBins(50,0,100);
03105     TimeHstTrk2U->SetBins(50,0,100);
03106     TimeHstTrk2V->SetBins(50,0,100);
03107     TimeHstShw2->SetBins(50,0,100);
03108     TimeHstShw2U->SetBins(50,0,100);
03109     TimeHstShw2V->SetBins(50,0,100);
03110 
03111 //    TH1F *h1 = (TH1F*)TimeHst->GetHists()->FindObject("TimeHstTrk");
03112 //    TH1F *h2 = (TH1F*)TimeHst->GetHists()->FindObject("TimeHstShw");
03113 //    h1->SetBins(100,tmin/1e-9,tmax/1e-9);
03114 //    h2->SetBins(100,tmin/1e-9,tmax/1e-9);
03115 
03116     //record track hits
03117     //int ntrks = event->ntrack;
03118     if (ntrks){
03119       for (int i = 0; i<ntrks; i++){
03120         int index = SntpHelpers::GetTrackIndex(i,event);
03121         NtpSRTrack *track = SntpHelpers::GetTrack(index,sr);
03122         for (int istp = 0; istp<track->nstrip; istp++){
03123           //ftrkshw->Fill(track->stpx[istp],track->stpy[istp],1);
03124           NtpSRStrip *strip = SntpHelpers::GetStrip(track->stp[istp],sr);
03125           TimeHstTrk->Fill(track->stpt0[istp]/1e-9,strip->ph0.pe);
03126           TimeHstTrk->Fill(track->stpt1[istp]/1e-9,strip->ph1.pe);
03127           TimeHstTrk2->Fill((track->stpt0[istp]-tmin-(track->ds-track->stpds[istp])/3e8)/1e-9,strip->ph0.pe);
03128           TimeHstTrk2->Fill((track->stpt1[istp]-tmin-(track->ds-track->stpds[istp])/3e8)/1e-9,strip->ph1.pe);
03129           //record track strip information
03130           if(strip->planeview==PlaneView::kU){
03131             fTrkUZ->Fill(strip->z,strip->tpos,100000);//paranoia
03132 
03133             TimeHstTrkU->Fill(track->stpt0[istp]/1e-9,strip->ph0.pe);
03134             TimeHstTrkU->Fill(track->stpt1[istp]/1e-9,strip->ph1.pe);
03135             TimeHstTrk2U->Fill((track->stpt0[istp]-tmin-(track->ds-track->stpds[istp])/3e8)/1e-9,strip->ph0.pe);
03136             TimeHstTrk2U->Fill((track->stpt1[istp]-tmin-(track->ds-track->stpds[istp])/3e8)/1e-9,strip->ph1.pe);
03137           }
03138           else if(strip->planeview==PlaneView::kV){
03139             fTrkVZ->Fill(strip->z,strip->tpos,100000);
03140 
03141             TimeHstTrkV->Fill(track->stpt0[istp]/1e-9,strip->ph0.pe);
03142             TimeHstTrkV->Fill(track->stpt1[istp]/1e-9,strip->ph1.pe);
03143             TimeHstTrk2V->Fill((track->stpt0[istp]-tmin-(track->ds-track->stpds[istp])/3e8)/1e-9,strip->ph0.pe);
03144             TimeHstTrk2V->Fill((track->stpt1[istp]-tmin-(track->ds-track->stpds[istp])/3e8)/1e-9,strip->ph1.pe);            
03145           } 
03146         }
03147       }
03148     }
03149 
03150     //record shower hits
03151     int nshws = event->nshower;
03152     if (nshws){
03153       for (int i = 0; i<nshws; i++){
03154         int index = SntpHelpers::GetShowerIndex(i,event);
03155         NtpSRShower *shower = SntpHelpers::GetShower(index,sr);
03156         for (int istp = 0; istp<shower->nstrip; istp++){
03157           NtpSRStrip *strip = SntpHelpers::GetStrip(shower->stp[istp],sr);
03158           TimeHstShw->Fill(strip->time0/1e-9,strip->ph0.pe);
03159           TimeHstShw->Fill(strip->time1/1e-9,strip->ph1.pe);
03160           TimeHstShw2->Fill((strip->time0-tmin)/1e-9,strip->ph0.pe);
03161           TimeHstShw2->Fill((strip->time1-tmin)/1e-9,strip->ph1.pe);
03162           //record shower strip information
03163           if(strip->planeview==PlaneView::kU){
03164             fShwUZ->Fill(strip->z,strip->tpos,100000);//paranoia
03165 
03166             TimeHstShwU->Fill(strip->time0/1e-9,strip->ph0.pe);
03167             TimeHstShwU->Fill(strip->time1/1e-9,strip->ph1.pe);
03168             TimeHstShw2U->Fill((strip->time0-tmin)/1e-9,strip->ph0.pe);
03169             TimeHstShw2U->Fill((strip->time1-tmin)/1e-9,strip->ph1.pe);
03170           }
03171           else if(strip->planeview==PlaneView::kV){
03172             fShwVZ->Fill(strip->z,strip->tpos,100000);
03173 
03174             TimeHstShwV->Fill(strip->time0/1e-9,strip->ph0.pe);
03175             TimeHstShwV->Fill(strip->time1/1e-9,strip->ph1.pe);
03176             TimeHstShw2V->Fill((strip->time0-tmin)/1e-9,strip->ph0.pe);
03177             TimeHstShw2V->Fill((strip->time1-tmin)/1e-9,strip->ph1.pe);
03178           } 
03179         }
03180       }
03181     }
03182     TimeHst = new THStack("TimeHist","Digit Times (ns)");
03183     TimeHst->Add(TimeHstTrk);
03184     TimeHst->Add(TimeHstShw);
03185 
03186     TimeHstUV = new THStack("TimeHistUV","UV Digit Times (ns)");
03187     TimeHstUV->Add(TimeHstTrkU);
03188     TimeHstUV->Add(TimeHstTrkV);
03189     TimeHstUV->Add(TimeHstShwU);
03190     TimeHstUV->Add(TimeHstShwV);
03191 
03192     TimeHst2 = new THStack("TimeHist2","Digit Times (ns)");
03193     TimeHst2->Add(TimeHstTrk2);
03194     TimeHst2->Add(TimeHstShw2);
03195 
03196     TimeHst2UV = new THStack("TimeHist2UV","UV Digit Times (ns)");
03197     TimeHst2UV->Add(TimeHstTrk2U);
03198     TimeHst2UV->Add(TimeHstTrk2V);
03199     TimeHst2UV->Add(TimeHstShw2U);
03200     TimeHst2UV->Add(TimeHstShw2V);
03201   }  
03202   
03203   srvtx_u->SetX(event->vtx.z);
03204   srvtx_u->SetY(event->vtx.u);
03205   srvtx_v->SetX(event->vtx.z);
03206   srvtx_v->SetY(event->vtx.v);
03207   srvtx_xy->SetX(event->vtx.x);
03208   srvtx_xy->SetY(event->vtx.y);
03209   
03210   if(kDrawClu) FillClusterGraphs();  
03211   if(kIntReco) SetUpStripButtons();
03212   
03213   return 1;
03214   }
03215   
03216   void NueDisplayModule::FillClusterGraphs()
03217   {
03218     /*
03219       RecRecordImp<RecCandHeader> *rr = 
03220       dynamic_cast<RecRecordImp<RecCandHeader>*>
03221       ((gMint->GetJobC().Mom).GetFragment("RecRecordImp<RecCandHeader>"));
03222     */
03223 
03224   ssGraphU = new TMultiGraph();
03225   ssGraphU->SetName("usubshowers");
03226   ssGraphU->SetTitle("Transverse Position vs Z - U View");
03227   cluLegU = new TLegend(0.05,0.05,0.95,0.95,"  Key: ID (P_{EM})");
03228   cluLegU->SetBorderSize(0);
03229   cluLegU->SetTextSize(0.08);
03230   
03231   ssGraphV = new TMultiGraph();
03232   ssGraphV->SetName("vsubshowers");
03233   ssGraphV->SetTitle("Transverse Position vs Z - V View");
03234   cluLegV = new TLegend(0.05,0.05,0.95,0.95,"  Key: ID (P_{EM})");
03235   cluLegV->SetBorderSize(0);
03236   cluLegV->SetTextSize(0.08);
03237 
03238   int nUclus = 0;
03239   int col0 = 1;
03240   int nVclus = 0;
03241   int col1 = 1;
03242   
03243   for(int i=0;i<event->nshower;i++){  //loop over showers
03244     int shower_index = SntpHelpers::GetShowerIndex(i,event);
03245     NtpSRShower *shower = SntpHelpers::GetShower(shower_index,st);  
03246     if(shower==0) continue;
03247 
03248     int numclustp=0;
03249     int numclustp0=0;
03250     int numclustp1=0;
03251     
03252     for(int j=0;j<shower->ncluster;j++){ //loop over clusters
03253       int cluster_index = SntpHelpers::GetClusterIndex(j,shower);
03254       NtpSRCluster *cluster = SntpHelpers::GetCluster(cluster_index,st);
03255       numclustp+=cluster->nstrip;
03256       if(cluster->planeview==2) nUclus+=1;
03257       else if(cluster->planeview==3) nVclus+=1;
03258     }
03259 
03260     float *clu_tpos = new float[numclustp];
03261     float *clu_tpos0 = new float[numclustp];
03262     float *clu_z0 = new float[numclustp];
03263     float *clu_tpos1 = new float[numclustp];
03264     float *clu_z1 = new float[numclustp];
03265     double *clu_z = new double[numclustp];
03266     int count = 0;
03267 
03268     for(int j=0;j<shower->ncluster;j++){ //loop over clusters
03269       int cluster_index = SntpHelpers::GetClusterIndex(j,shower);
03270       NtpSRCluster *cluster = SntpHelpers::GetCluster(cluster_index,st);
03271       
03272       count=0;
03273       numclustp0=0;
03274       numclustp1=0;
03275       
03276       for(int k=0;k<cluster->nstrip;k++){
03277         int strip_index = SntpHelpers::GetStripIndex(k,cluster);
03278         NtpSRStrip *strip = SntpHelpers::GetStrip(strip_index,st);
03279         clu_tpos[count] = strip->tpos;
03280         clu_z[count]    = strip->z;
03281         if(strip->planeview==2){
03282           clu_tpos0[numclustp0] = clu_tpos[count];
03283           clu_z0[numclustp0] = clu_z[count];
03284           numclustp0+=1;
03285         }
03286         else {
03287           clu_tpos1[numclustp1] = clu_tpos[count];
03288           clu_z1[numclustp1] = clu_z[count];
03289           numclustp1+=1;
03290         }
03291         count++;
03292       }
03293     
03294       if(numclustp0>0){
03295         TGraph *temp = new TGraph(numclustp0,clu_z0,clu_tpos0);
03296         if(col0==10) col0+=1;
03297         temp->SetMarkerColor(col0);
03298         temp->SetMarkerSize(0.6);
03299         temp->SetMarkerStyle(21);
03300         if(cluster->id==2 ||
03301            cluster->id==4) temp->SetMarkerStyle(25);
03302         ssGraphU->Add(temp);
03303         col0+=1;
03304         char ssnom[256];
03305         if(cluster->id==0) {
03306           sprintf(ssnom,"EM (%.2f)",cluster->probem);
03307         }
03308         else if(cluster->id==1){
03309           sprintf(ssnom,"HAD (%.2f)",cluster->probem);
03310         }
03311         else {
03312           sprintf(ssnom,"%s",
03313                   ClusterType::AsString(ClusterType::
03314                                         EClusterType(cluster->id)));
03315         }
03316         cluLegU->AddEntry(temp,ssnom,"p");
03317       }
03318       if(numclustp1>0){
03319         if(col1==10) col1+=1;
03320         TGraph *temp = new TGraph(numclustp1,clu_z1,clu_tpos1);
03321         temp->SetMarkerColor(col1);
03322         temp->SetMarkerSize(0.6);
03323         temp->SetMarkerStyle(21);
03324         if(cluster->id==2 ||
03325            cluster->id==4) temp->SetMarkerStyle(25);
03326         ssGraphV->Add(temp);
03327         col1+=1;
03328         char ssnom[256];
03329         if(cluster->id==0){
03330           sprintf(ssnom,"EM (%.2f)",cluster->probem);
03331         }
03332         else if(cluster->id==1){
03333           sprintf(ssnom,"HAD (%.2f)",cluster->probem);
03334         }
03335         else {
03336           sprintf(ssnom,"%s",
03337                   ClusterType::AsString(ClusterType::
03338                                       EClusterType(cluster->id)));
03339         }
03340         cluLegV->AddEntry(temp,ssnom,"p");
03341       }
03342     }
03343                                                                                 
03344     delete [] clu_tpos;
03345     delete [] clu_z;
03346     delete [] clu_tpos0;
03347     delete [] clu_z0;
03348     delete [] clu_tpos1;
03349     delete [] clu_z1;
03350   }
03351   if(nUclus==0) {
03352     delete ssGraphU;
03353     ssGraphU=NULL;
03354     delete cluLegU;
03355     cluLegU = NULL;
03356   }
03357   if(nVclus==0) {
03358     delete ssGraphV;
03359     ssGraphV=NULL;
03360     delete cluLegV;
03361     cluLegV = NULL;
03362   }
03363 
03364 }
03365 
03366 
03367 
03368 void NueDisplayModule::DrawInteractionDiagram(Int_t index){
03369   //modified by steve cavanaugh aug 9, 2006 to take into account double particles in mc with IstHEP=2 
03370   //with modifications for readability
03371   
03372   fStdHepCan->cd();
03373   fStdHepCan->Range(0,0,1,1.1);
03374   
03375   vector<NtpMCStdHep *> hep;
03376   if (foundST) hep = SntpHelpers::GetStdHepArray(index, st);
03377   else hep = SntpHelpers::GetStdHepArray(index, mc);
03378 
03379 
03380 
03381   Int_t nStdHep = int(hep.size());
03382   Int_t *indicesToUse = new Int_t[nStdHep];
03383   Int_t *parent = new Int_t[nStdHep];
03384   Int_t *parent1 = new Int_t[nStdHep];
03385   Int_t incomingNeutrino = -1;
03386   Int_t cnt = 0;
03387 
03388 
03389 
03390   for(int i=0;i<nStdHep;i++){    
03391     if(hep[i]->mc==index) {
03392       indicesToUse[cnt] = i;
03393 
03394 
03395 
03396       //parent[i] = hep[i]->parent[0];
03397 
03398       //in the case where we have more than 1 event per snarl we might 
03399       //have indices which refer to the actual index, not the one for the particular event.... 
03400       //so make sure we match this up properly
03401       for(int j=0;j<nStdHep;j++){
03402         if ((Int_t)hep[j]->index==hep[i]->parent[0]){
03403           parent[i]=j;
03404           break;
03405         }
03406       }
03407 
03408       
03409       for(int j=0;j<nStdHep;j++){
03410         if ((Int_t)hep[j]->index==hep[i]->parent[1]){
03411           parent1[i]=j;
03412           break;
03413         }
03414       }
03415         
03416 
03417 
03418 
03419       if(hep[i]->IstHEP==0){
03420         if(abs(hep[i]->IdHEP)==12||abs(hep[i]->IdHEP)==14
03421            ||abs(hep[i]->IdHEP)==16) {
03422           incomingNeutrino=i;
03423 
03424 
03425         }
03426         parent[i] = -1; //don't draw arrows to initial state particles
03427         parent1[i] = -1;
03428       }
03429       cnt++;
03430     }
03431     else{
03432       parent[i] = -1;
03433       parent1[i] = -1;
03434     }
03435   }
03436 
03437 
03438   
03439 
03440 
03441 
03442 
03443   //make arrows and markers
03444   TArrow *arrow[1000];
03445   TMarker *marker[1000];
03446   for(int i=0;i<nStdHep;i++) {
03447     arrow[i] = new TArrow(0,0,0,0,.01,"|>"); 
03448     arrow[i]->SetLineWidth(1);
03449     arrow[i]->SetLineStyle(3);
03450     arrow[i]->SetFillColor(39);
03451     arrow[i]->SetLineColor(39);
03452     marker[i] = new TMarker(0,0,24);
03453     marker[i]->SetMarkerSize(.2);
03454     marker[i]->SetMarkerColor(38);
03455   }
03456 
03457   //now loop through valid stdhep entries and fill variables  
03458   Float_t Available[5] = {0.9,0.7,0.7,0.7};  
03459   
03460   //cout<<"nStdHep: "<<nStdHep<<"\n";
03461 
03462   for(int i=0;i<cnt;i++){
03463     
03464     int toUse = indicesToUse[i];
03465     if(hep[toUse]->IstHEP==999){
03466       parent[i]=-1;
03467       continue;
03468     }
03469 
03470 
03471 
03472     //    cout<<toUse<<"  "<<hep[toUse]->IstHEP<<"   "<<nStdHep<<endl;
03473     //cout<<parent[toUse]<<"   "<<parent1[toUse]<<endl;
03474 
03475 
03476 
03477     
03478     
03479     //sc - avoid any double taus' charms' etc, but set the proper parent/child 
03480     //(remove the particle between true parent and child)
03481 
03482     if((hep[toUse]->child[0]==hep[toUse]->child[1]) &&
03483        (hep[toUse]->IstHEP==2 || hep[toUse]->IstHEP==3 || hep[toUse]->IstHEP==14) && 
03484        hep[toUse]->child[0]!=-1){
03485       int j;
03486       int child = hep[toUse]->child[0];
03487       for(j=0;j<cnt;j++){
03488         if ((Int_t)hep[j]->index==child)break;
03489       }
03490 
03491       //we've lost arrow tail info, so fix it
03492       if (j<nStdHep){
03493         arrow[j]->SetX1(arrow[i]->GetX1());
03494         arrow[j]->SetY1(arrow[i]->GetY1());
03495       
03496         parent[i]=-1;
03497       
03498         continue;
03499       }else{
03500         cout<<"Error! - linking failed, index out of range! \n";
03501       }
03502     }
03503 
03504     //sc - avoid any "later decays" not comming from IstHEP=1 decays .. .these are children of double taus, etc
03505 
03506     if((hep[toUse]->IstHEP==205||hep[toUse]->IstHEP==1205)&&
03507        (hep[parent[toUse]]->IstHEP!=1 || hep[parent1[toUse]]->IstHEP!=1)){
03508       parent[i]=-1;
03509       //cout <<"breaking out of loop for particle "<<i<<"\n";
03510       continue;  
03511     }
03512 
03513     
03514     Float_t mom = sqrt(hep[toUse]->p4[0]*hep[toUse]->p4[0] + 
03515                        hep[toUse]->p4[1]*hep[toUse]->p4[1] + 
03516                        hep[toUse]->p4[2]*hep[toUse]->p4[2]);
03517     float x=0.,y=0.;
03518     int col=0;
03519     char text[256];
03520 
03521     //set x,y    
03522     if(hep[toUse]->IstHEP==0) {
03523       x = 0.05;
03524       y=Available[0]; Available[0] -= 0.1;
03525     }
03526     else if(hep[toUse]->IstHEP==2) {
03527       x = 0.15;
03528       y=Available[1]; Available[1] -= 0.1;   
03529     }
03530     else if(hep[toUse]->IstHEP==11) {
03531       x = 0.05;
03532       y=Available[0]; Available[0] -= 0.1; 
03533     }
03534     else if(hep[toUse]->IstHEP==3||hep[toUse]->IstHEP==14) {   //sc - allow for both IstHEP=3 and 14 intermediate decays
03535       x = 0.3;
03536       y=Available[1]; Available[1] -= 0.1;
03537     }
03538     else if(hep[toUse]->IstHEP==1){
03539       x = 0.55;
03540       y=Available[2]; Available[2] -= 0.1;
03541     }
03542     else if((hep[toUse]->IstHEP==205||hep[toUse]->IstHEP==1205)){
03543       x = 0.8;
03544       y=Available[3]; Available[3] -= 0.1;
03545     }
03546  
03547     //set colour and label (and override y in special cases)
03548     if(abs(hep[toUse]->IdHEP)==12) { //nue
03549       if(parent[toUse]==incomingNeutrino)  y = 0.9; 
03550       sprintf(text,"#nu_{e}"); col = 3;
03551       if(hep[toUse]->IdHEP<0) sprintf(text,"#bar{#nu}_{e}");
03552     }
03553     else if(abs(hep[toUse]->IdHEP)==14) { //numu
03554      if(parent[toUse]==incomingNeutrino)  y = 0.9;  
03555      sprintf(text,"#nu_{#mu}"); col = 4;
03556       if(hep[toUse]->IdHEP<0) sprintf(text,"#bar{#nu}_{#mu}");
03557     }
03558     else if(abs(hep[toUse]->IdHEP)==16) { //nutau
03559      if(parent[toUse]==incomingNeutrino)  y = 0.9;  
03560      sprintf(text,"#nu_{#tau}"); col = 105;
03561       if(hep[toUse]->IdHEP<0) sprintf(text,"#bar{#nu}_{#tau}"); 
03562     }    
03563     else if(abs(hep[toUse]->IdHEP)==11) { //e
03564       if(parent[toUse]==incomingNeutrino) y = 0.9;          
03565       sprintf(text,"e^{-}"); col = 3;
03566       if(hep[toUse]->IdHEP<0) sprintf(text,"e^{+}");
03567     }
03568     else if(abs(hep[toUse]->IdHEP)==13) { //mu
03569       if(parent[toUse]==incomingNeutrino) y = 0.9;               
03570       sprintf(text,"#mu^{-}"); col = 4;
03571       if(hep[toUse]->IdHEP<0) sprintf(text,"#mu^{+}");
03572     }
03573     else if(abs(hep[toUse]->IdHEP)==15) { //tau
03574       //tau will decay so it is easier to read if it is not on the top line...
03575       // if(parent[toUse]==incomingNeutrino) y = 0.9;                  
03576       sprintf(text,"#tau^{-}"); col = 105;
03577       if(hep[toUse]->IdHEP<0) sprintf(text,"#tau^{+}"); 
03578     }
03579     else if(hep[toUse]->IdHEP==22) { //photon
03580       sprintf(text,"#gamma"); col = 9;      
03581     }
03582     else if(hep[toUse]->IdHEP>1000000000) { //nucleus
03583       y = 0.8;
03584       sprintf(text,"nucleus(%i,%i)",int((hep[toUse]->IdHEP-1e9)/1e6),
03585               int((hep[toUse]->IdHEP-1e9 - 1e6*int((hep[toUse]->IdHEP-1e9)
03586                                                   /1e6))/1e3)); 
03587       col = 15;
03588     }
03589     else if(hep[toUse]->IdHEP==2112){ 
03590       sprintf(text,"neutron"); col = 28;
03591     }
03592     else if(hep[toUse]->IdHEP==2212){
03593       sprintf(text,"proton"); col = 2;
03594     }
03595     else if(abs(hep[toUse]->IdHEP)==211) {
03596       sprintf(text,"#pi^{+}"); col = 6;
03597       if(hep[toUse]->IdHEP<0) sprintf(text,"#pi^{-}");
03598     }
03599     else if(hep[toUse]->IdHEP==111) {
03600       sprintf(text,"#pi^{0}"); col = 7;
03601     }
03602     else if(hep[toUse]->IdHEP==130) {
03603       sprintf(text,"K^{0}_{L}"); col = 31;
03604     }
03605     else if(hep[toUse]->IdHEP==310) {
03606       sprintf(text,"K^{0}_{S}"); col = 31;
03607     }
03608     else if(hep[toUse]->IdHEP==311) {
03609       sprintf(text,"K^{0}"); col = 31;
03610     }
03611     else if(abs(hep[toUse]->IdHEP)==321) {
03612       sprintf(text,"K^{+}"); col = 31;
03613       if(hep[toUse]->IdHEP<0) sprintf(text,"K^{-}"); col = 31;
03614     }
03615     else if(hep[toUse]->IdHEP==28) {
03616       sprintf(text,"Geantino"); col = 46;
03617       if(hep[toUse]->IdHEP<0) sprintf(text,"K^{-}"); col = 31;
03618     }
03619     else {
03620       sprintf(text,"ID: %i",hep[toUse]->IdHEP); col=43;
03621     }
03622 
03623     sprintf(text,"%s [%.1f GeV/c]",text,mom);
03624     
03625     arrow[toUse]->SetX2(x-0.02);   
03626     arrow[toUse]->SetY2(y-0.02);   
03627     marker[toUse]->SetX(x-0.02);
03628     marker[toUse]->SetY(y-0.02);
03629 
03630     for(int j=0;j<nStdHep;j++){
03631    
03632       if(parent[j]==toUse){
03633         arrow[j]->SetX1(x-0.02);
03634         arrow[j]->SetY1(y-0.02);
03635         //cout<<"writing arrows from "<<j << " to "<<parent[j]<<"\n";
03636       }
03637     }
03638  
03639     TLatex *tex = new TLatex(x,y,text);
03640     char texname[256];
03641     sprintf(texname,"tex%i",i);
03642     tex->SetName(texname);
03643     tex->SetTextSize(0.05);
03644     tex->SetTextColor(col);
03645     tex->Draw();
03646   }
03647 
03648   for(int i=0;i<nStdHep;i++){
03649     if(parent[i]==-1){
03650       delete arrow[i];
03651       delete marker[i];
03652     }
03653     else {
03654       arrow[i]->Draw();
03655       marker[i]->Draw();
03656       
03657     }
03658   }
03659   
03660 
03661 
03662 
03663 
03664   Float_t minAvail = 0;
03665   for(int i=0;i<4;i++){
03666     if(Available[i]<minAvail) minAvail = Available[i];
03667   }
03668   if(minAvail<0) fStdHepCan->Range(0,minAvail,1,1.1);
03669 
03670  
03671 
03672   delete [] indicesToUse;
03673   delete [] parent;
03674 
03675   fStdHepCan->Modified();
03676   fStdHepCan->Update();
03677 
03678 
03679 
03680 }
03681 
03682 void NueDisplayModule::Analyze(Int_t evt){
03683     DeleteOldCrap();
03684 
03685     shia.SetRelease(fRel);
03686     fva.SetRelease(fRel);
03687     sfa.SetRelease(fRel);
03688     hca.SetRelease(fRel);
03689     aca.SetRelease(fRel);
03690     acfa.SetRelease(fRel);
03691 
03692     if (foundST){
03693         fva.Analyze(evt,st);
03694     }
03695     else if (foundSR){
03696         fva.Analyze(evt,sr);
03697     }    
03698 
03699     fva.Draw(fFracVar_plots);
03700     fCanvas2->Update();
03701     
03702     MSG("NueDisplayModule",Msg::kDebug) <<"FracVar fract_road = " << fracvars.fract_road<<endl;
03703 
03704     
03705     if (foundST){
03706       sfa.Analyze(evt,st);
03707     }
03708     else if (foundSR){
03709       sfa.Analyze(evt,sr);
03710     }    
03711 
03712     shwfit.Draw(fShwfit_plots);
03713     fCanvas3->Update();
03714 
03715 
03716     DeqFloat_t x,y,z,e;
03717     Int_t primShow;
03718     DeqDeqInt_t clusterMap;
03719     TVector3 primDir;
03720     
03721     if (foundST){
03722         hca.Analyze(evt,st);
03723         hca.Get3DHit(x,y,z,e);    
03724         aca.Set3DHit(x,y,z,e);
03725         aca.Analyze(evt,st);    // Must be preceded by hca.Get3DHit
03726         //                     aca.Set3DHit
03727         aca.GetAngCluster(primShow,clusterMap,primDir);
03728         acfa.Set3DHit(x,y,z,e);
03729         acfa.SetAngCluster(primShow,clusterMap,primDir);
03730         acfa.Analyze(evt,st);    // Must be preceded by:
03731                                     // aca.GetAngCluster
03732                                     // acf.Set3DHit
03733                                     // acf.SetAngCluster
03734              
03735     }
03736     else if (foundSR){
03737         
03738         hca.Analyze(evt,sr);
03739         hca.Get3DHit(x,y,z,e);    
03740         aca.Set3DHit(x,y,z,e);
03741         aca.Analyze(evt,sr);    // Must be preceded by hca.Get3DHit
03742         //                     aca.Set3DHit
03743         aca.GetAngCluster(primShow,clusterMap,primDir);
03744         acfa.Set3DHit(x,y,z,e);
03745         acfa.SetAngCluster(primShow,clusterMap,primDir);
03746         acfa.Analyze(evt,sr);    // Must be preceded by:
03747                                  // aca.GetAngCluster
03748                                  // acf.Set3DHit
03749                                  // acf.SetAngCluster 
03750 
03751     }    
03752 
03753     acfa.Draw(fAngClusterFitAna_plots);
03754     fCanvas4->Update();
03755 
03756   if (fSimFlag == SimFlag::kMC){
03757     if (foundST){
03758       shia.Analyze(evt,st);
03759     }
03760     else if (foundMC&&foundTH){
03761       //not implemented yet
03762     }
03763   }
03764 
03765 
03766 }
03767 
03768 void NueDisplayModule::GetBasicInfo(){
03769   info1->Clear();
03770   info2->Clear();
03771   info3->Clear();
03772   info4->Clear();
03773   info41->Clear();
03774   info5->Clear();
03775   info6->Clear();
03776   info7->Clear();
03777   info8->Clear();
03778   info9->Clear();
03779   info10->Clear();
03780   info11->Clear();
03781   info12->Clear();
03782   info13->Clear();
03783   mrInfo1->Clear();
03784   char text1[100];
03785   char text2[100];
03786   char text3[100];
03787   char text31[100];
03788   char text4[100];
03789   char text5[100];
03790   char text6[100];
03791   char text7[100];
03792   char text8[100];
03793   char text9[100];
03794   char text10[100];
03795   char text11[100];
03796   char text12[100];
03797   int run=0, snarl=0, evt=0;
03798   DataUtil::GetRunSnarlEvent(&(gMint->GetJobC().Mom),run,snarl,evt);
03799   evt = fEvent;
03800   fSnarl = snarl;
03801  
03802   if(!kTestMode&&!kHideRunSnarl) sprintf(text1,"Run: %d/%d, Snarl: %d, Event: %d(%d), Slice: %d (%d)",
03803                  run,SubRunNo,snarl,evt,fNumEvents,event->slc,st->evthdr.nslice);
03804   else sprintf(text1,"Run: xxxx, Snarl: xxxx, Event: %d(%d)",evt,fNumEvents);
03805   
03806   int ntrks = event->ntrack;
03807   int nshws = event->nshower;
03808 
03809 //  Float_t trk_mom = 0;
03810 //  Float_t shw_eng = 0;
03811 //  Int_t trk_leg = 0;
03812 //  Int_t trk_like = 0;
03813 //  Int_t shw_leg = 0;
03814   Float_t zenith = -1;
03815   Float_t azimuth = -1;
03816 
03817   Float_t trk_mom_range = 0;
03818   Float_t trk_mom_fit = 0;
03819   Float_t trk_length = 0;
03820   Float_t trk_qp = 0;
03821   Float_t trk_eqp = 0;
03822   Int_t trk_planes = 0;
03823   Int_t trk_like = 0;
03824   Float_t shw_ph = 0;
03825   Float_t shw_shwph = 0;
03826   Int_t shw_planes = 0;
03827 
03828   if (foundST){
03829     if (ntrks){
03830       for (int i = 0; i<ntrks; i++){
03831         int index = SntpHelpers::GetTrackIndex(i,event);
03832         NtpSRTrack *track = SntpHelpers::GetTrack(index,st);
03833         if (track->plane.n>trk_planes) {
03834           zenith = track->cr.zenith;
03835           azimuth = track->cr.azimuth;
03836           trk_mom_range = track->momentum.range;
03837           if (track->momentum.qp) trk_mom_fit = 1./track->momentum.qp;
03838           trk_length = track->ds;
03839           trk_qp = track->momentum.qp;
03840           trk_eqp = track->momentum.eqp;
03841           trk_planes = track->plane.n;
03842           trk_like= track->plane.ntrklike;
03843         }
03844       }
03845     }
03846   
03847     if (nshws){
03848       for (int i = 0; i<nshws; i++){
03849         int index = SntpHelpers::GetShowerIndex(i,event);
03850         NtpSRShower *shower = SntpHelpers::GetShower(index,st);
03851         if (shower->shwph.linCCgev>shw_shwph) {
03852           shw_shwph = shower->shwph.linCCgev;
03853           shw_ph = shower->ph.gev;
03854           shw_planes = shower->plane.n;
03855         }
03856       }
03857     }
03858   }
03859   else if(foundSR){
03860     if (ntrks){
03861       for (int i = 0; i<ntrks; i++){
03862         int index = SntpHelpers::GetTrackIndex(i,event);
03863         NtpSRTrack *track = SntpHelpers::GetTrack(index,sr);
03864         if (track->plane.n>trk_planes) {
03865           zenith = track->cr.zenith;
03866           azimuth = track->cr.azimuth;
03867           trk_mom_range = track->momentum.range;
03868           if (track->momentum.qp) trk_mom_fit = 1./track->momentum.qp;
03869           trk_length = track->ds;
03870           trk_qp = track->momentum.qp;
03871           trk_eqp = track->momentum.eqp;
03872           trk_planes = track->plane.n;
03873           trk_like= track->plane.ntrklike;
03874         }
03875       }
03876     }
03877     
03878     if (nshws){
03879       for (int i = 0; i<nshws; i++){
03880         int index = SntpHelpers::GetShowerIndex(i,event);
03881         NtpSRShower *shower = SntpHelpers::GetShower(index,sr);
03882         if (shower->shwph.linCCgev>shw_shwph) {
03883           shw_shwph = shower->shwph.linCCgev;
03884           shw_ph = shower->ph.gev;
03885           shw_planes = shower->plane.n;
03886         }
03887       }
03888     }
03889   }
03890     
03891   sprintf(text2,"ntrks: %d nshws: %d zenith: %.1f azimuth: %.1f",ntrks,nshws,zenith,azimuth);
03892   sprintf(text3,"trk.range:%.2fGeV, fit:%.2fGeV, qp:%.3f",trk_mom_range,trk_mom_fit,trk_qp);
03893   sprintf(text31,"trk.pls:%d, length:%.1fm, like:%d, eqp:%.2f",trk_planes,trk_length,trk_like,trk_eqp);
03894   sprintf(text4,"shw.gev:%.2fGeV, linCC:%.2fGeV, pls:%d",shw_ph,shw_shwph,shw_planes);
03895   
03896   sprintf(text5,"MC");
03897   
03898   mctruth = 0;
03899   if (fSimFlag == SimFlag::kMC){
03900     if (foundST){
03901       Int_t index = SntpHelpers::GetEvent2MCIndex(fEvent,st);
03902       mctruth = SntpHelpers::GetMCTruth(index,st);
03903       thevent = dynamic_cast<NtpTHEvent*>((*st->thevt)[fEvent]);
03904     }
03905     else if (foundMC&&foundTH){
03906       Int_t index = SntpHelpers::GetEvent2MCIndex(fEvent,th);
03907       mctruth = SntpHelpers::GetMCTruth(index,mc);
03908       thevent = dynamic_cast<NtpTHEvent*>((*th->thevt)[fEvent]);
03909     }
03910   }
03911     
03912   //MC
03913   if (mctruth){
03914     char tmptxt[100];
03915     sprintf(tmptxt,"(p%.2f/c%.2f/c%.2f)",thevent->purity,thevent->completeall,thevent->completeslc);
03916     if (mctruth->iaction==0){
03917       sprintf(text6,"NC event %s",tmptxt);
03918     }
03919     else{
03920       if (abs(mctruth->inunoosc)==12&&abs(mctruth->inu)==12){
03921         sprintf(text6,"beam #nu_{e} CC %s",tmptxt);
03922       }
03923       if (abs(mctruth->inunoosc)==14&&abs(mctruth->inu)==14){
03924         sprintf(text6,"#nu_{#mu}#rightarrow#nu_{#mu} CC %s",tmptxt);
03925       }
03926       if (abs(mctruth->inunoosc)==14&&abs(mctruth->inu)==12){
03927         sprintf(text6,"#nu_{#mu}#rightarrow#nu_{e} CC %s",tmptxt);
03928       }
03929       if (abs(mctruth->inunoosc)==14&&abs(mctruth->inu)==16){
03930         sprintf(text6,"#nu_{#mu}#rightarrow#nu_{#tau} CC %s",tmptxt);
03931       }
03932     }
03933     if (mctruth->iresonance==1001 && mctruth->iaction==1){
03934       sprintf(text7,"quasi-elastic");
03935     } 
03936     if (mctruth->iresonance==1001 && mctruth->iaction==0){
03937       sprintf(text7,"elastic");
03938     } 
03939     if (mctruth->iresonance==1002){
03940       sprintf(text7,"resonance production");
03941     }
03942     if (mctruth->iresonance==1003){
03943       sprintf(text7,"DIS");
03944     }
03945     if (mctruth->iresonance==1004){
03946       sprintf(text7,"coherent production");
03947     }
03948     sprintf(text8,"E_{#nu}: %.1fGeV, E_{shw}: %.1fGeV",fabs(mctruth->p4neu[3]),fabs(mctruth->p4shw[3]));
03949     sprintf(text9,"Y: %.2f, emfrac: %.2f",mctruth->y,mctruth->emfrac);
03950     sprintf(text10,"E_{#mu}: %.1fGeV,  E_{el}: %.1fGeV",fabs(mctruth->p4mu1[3]),fabs(mctruth->p4el1[3]));
03951     if (foundST) {
03952       sprintf(text11,"E_{#pi^{0}}_tot: %.2fGeV, E_{#pi^{0}}_neugen: %.2fGeV",stdhepinfo.epi0_total,stdhepinfo.epi0_neugen);
03953       sprintf(text12,"E_{#pi^{0}}_abs: %.2fGeV, E_{#pi^{0}}_intranuke: %.2fGeV",stdhepinfo.epi0_abs,stdhepinfo.epi0_intranuke);
03954     }
03955   }
03956    
03957   //summary
03958   info1->SetText(0.01,0.95,text1);
03959   info1->SetTextSize(0.06);
03960   info1->SetTextColor(2);
03961   
03962   //Reco
03963   info2->SetText(0.01,0.88,"Reco:");
03964   info2->SetTextSize(0.06);
03965   info2->SetTextColor(4);
03966   
03967   info3->SetText(0.01,0.82,text2);
03968   info3->SetTextSize(0.06);
03969   info3->SetTextColor(9);
03970   
03971   info4->SetText(0.01,0.76,text3);
03972   info4->SetTextSize(0.06);
03973   info4->SetTextColor(9);
03974 
03975   info41->SetText(0.01,0.7,text31);
03976   info41->SetTextSize(0.06);
03977   info41->SetTextColor(9);
03978 
03979   info5->SetText(0.01,0.64,text4);
03980   info5->SetTextSize(0.06);
03981   info5->SetTextColor(9);
03982 
03983   int mcinfoc = 6;
03984   info6->SetText(0.01,0.5,"MC:");
03985   info6->SetTextSize(0.06);
03986   info6->SetTextColor(mcinfoc);
03987   
03988   if (mctruth){
03989     info7->SetText(0.05,0.44,text6);
03990     info7->SetTextSize(0.06);
03991     info7->SetTextColor(mcinfoc);
03992     
03993     info8->SetText(0.05,0.38,text7);
03994     info8->SetTextSize(0.06);
03995     info8->SetTextColor(mcinfoc);
03996 
03997     info9->SetText(0.05,0.32,text8);
03998     info9->SetTextSize(0.06);
03999     info9->SetTextColor(mcinfoc);
04000     
04001     info10->SetText(0.05,0.26,text9);
04002     info10->SetTextSize(0.06);
04003     info10->SetTextColor(mcinfoc);
04004 
04005     info11->SetText(0.05,0.2,text10);
04006     info11->SetTextSize(0.06);
04007     info11->SetTextColor(mcinfoc);
04008 
04009     info12->SetText(0.05,0.14,text11);
04010     info12->SetTextSize(0.06);
04011     info12->SetTextColor(mcinfoc);
04012 
04013     info13->SetText(0.05,0.08,text12);
04014     info13->SetTextSize(0.06);
04015     info13->SetTextColor(mcinfoc);
04016     
04017   }
04018   else {
04019     info7->SetText(0.05,0.44,"N/A");
04020     info7->SetTextSize(0.06);
04021     info7->SetTextColor(mcinfoc);
04022   }
04023   
04024   fRecoInfo->Clear();
04025   fRecoInfo->AddLine(text1);
04026   fRecoInfo->AddLine("Reco Info");
04027   fRecoInfo->AddLine(text2);
04028   fRecoInfo->AddLine(text3);
04029   fRecoInfo->AddLine(text31);
04030   fRecoInfo->AddLine(text4);
04031   //  fRecoInfo->AddLine(" ");
04032   string passcuts[2] = {"Fail","Pass"};
04033 //  string ipass = "Pre-selections: "+passcuts[passfid*passtrk*passshw]+"  Fid: "+passcuts[passfid]+"  Track: "+passcuts[passtrk]+"  Shower: "+passcuts[passshw];
04034   string ipass = "Pre-selection: "+passcuts[passfid*passtrk*passshw*passeng*passtrklike];
04035   string epass = "Fid: "+passcuts[passfid]+"  Trk: "+passcuts[passtrk]+"  Trklike: "+passcuts[passtrklike]+"  Shw: "+passcuts[passshw]+"  E: "+passcuts[passeng];
04036   fRecoInfo->AddLine(ipass.c_str());
04037   fRecoInfo->AddLine(epass.c_str());
04038 
04039 }
04040 
04041 bool NueDisplayModule::PassCuts(){
04042 
04043   //  int nshws = event->nshower;  //no. of showers
04044 
04045   passfid = 1;
04046   passtrk = 1;
04047   passshw = 1;
04048   passeng = 1;
04049   passtrklike = 1;
04050                                                                                 
04051    Int_t test = 0;
04052    if(fDetectorType == Detector::kNear)
04053       test = NueConvention::IsInsideNearFiducial_Nue_Extended(
04054                   event->vtx.x, event->vtx.y, event->vtx.z);
04055    if(fDetectorType == Detector::kFar)
04056       test = NueConvention::IsInsideFarFiducial_Nue_Extended(
04057                   event->vtx.x, event->vtx.y, event->vtx.z);
04058    if(test <= 0) passfid = 0;
04059    MSG("NueDisplayModule",Msg::kDebug) << "IsFidVtxEvt? " << test
04060        << " Detector type: " << fDetectorType << endl;
04061 
04062   if(foundST)
04063   {
04064      fCut.SetInfoObject(fEvent,st);
04065      if(!fCut.PassesHighEnergyCut()) passeng=0;
04066      if(!fCut.PassesLowEnergyCut()) passeng=0;
04067      if(!fCut.PassesEventPlaneCut()) passeng=0;
04068      if(!fCut.PassesTrackPlaneCut()) passtrk = 0;
04069      if(!fCut.PassesTrackLikePlaneCut()) passtrklike = 0;
04070      if(!fCut.PassesHighShowerEnergyCut()) passshw = 0;
04071      if(!fCut.PassesLowShowerEnergyCut()) passshw = 0;
04072      
04073   }
04074                                                                                 
04075   if(foundSR){
04076       MSG("NueDisplayModule",Msg::kWarning)
04077          << "Unable to Perform Pass Cuts for pre Birch files"<< endl;
04078   }
04079 
04080   if (passfid&&passtrk&&passshw&&passeng&&passtrklike) return true;
04081   else return false;
04082 
04083 }
04084     
04085 void NueDisplayModule::SetCuts(){ 
04086   if (preselec==1){ 
04087     fCuts->SetText("Cuts: OFF"); 
04088     preselec=0;
04089     fCuts->SetDown(false);
04090   }
04091   else if (preselec==0){ 
04092     fCuts->SetText("Cuts:  ON"); 
04093     preselec=1;
04094     fCuts->SetDown(true);
04095   }
04096 }
04097 
04098 void NueDisplayModule::NextEvent(){
04099   clickbutton = 1;
04100   if (iIO){
04101     ievtp = 0;
04102     itopo = 0;
04103   }
04104   if(fNumEvents>0){
04105     fEvent++;
04106     if(fEvent>=fNumEvents){
04107       fEvent = 0;
04108       gMint->Next();
04109       return;
04110     }
04111     this->UpdateDisplay(foundvrmatch, foundpidmatch);
04112   }
04113   else {
04114     gMint->Next();
04115     return;
04116   }
04117 }
04118 
04119 
04120 void NueDisplayModule::PrevEvent(){
04121   clickbutton = -1;
04122   if (iIO){
04123     ievtp = 0;
04124     itopo = 0;
04125   }
04126   if(fNumEvents>0){
04127     fEvent--;
04128     if(fEvent<0){
04129       clickbutton = -2;
04130       gMint->Prev();
04131       return;
04132     }
04133     this->UpdateDisplay(foundvrmatch, foundpidmatch);
04134   }
04135   else {
04136     gMint->Prev();
04137     return;
04138   }
04139 }
04140 
04141 void NueDisplayModule::GotoEvent()
04142 {
04143   if (!gMint) return;
04144 
04145   string eventno = fEventEntry->GetText();
04146   if (atoi(eventno.c_str())<fNumEvents && atoi(eventno.c_str())>=0){
04147     fEvent = atoi(eventno.c_str());
04148     this->UpdateDisplay(foundvrmatch, foundpidmatch);
04149   }
04150   else {
04151     return;
04152   }
04153 }
04154 
04155 void NueDisplayModule::showmctruth()
04156 {
04157   
04158 //  if (imctruth) {
04159 //    fMCTruth->SetDown(true);
04160 //    return;
04161 //  }
04162   if (fSimFlag!=SimFlag::kMC) return;
04163   if (ifixmcinfo) return;
04164   if (!imctruth){//not pressed yet
04165     imctruth = 1;
04166     fMCTruth->SetDown(true);
04167     plotmc();
04168   }
04169   else {
04170     imctruth = 0;
04171     fMCTruth->SetDown(false);
04172     this->delmc();
04173   }
04174 }
04175 
04176 void NueDisplayModule::plotmc()
04177 {
04178   vector<NtpMCStdHep *> hep;
04179   Int_t index = 0;
04180   if (foundST){
04181     index = SntpHelpers::GetEvent2MCIndex(fEvent,st);
04182     hep = SntpHelpers::GetStdHepArray(index, st);
04183   }
04184   else if (foundMC&&foundTH){
04185     index = SntpHelpers::GetEvent2MCIndex(fEvent,th);
04186     hep = SntpHelpers::GetStdHepArray(index, mc);
04187   }
04188   
04189   vector<double> vtx_u(hep.size());
04190   vector<double> vtx_v(hep.size());
04191   vector<double> vtx_z(hep.size());
04192   vector<double> p_u(hep.size());
04193   vector<double> p_v(hep.size());
04194   vector<double> p_z(hep.size());
04195   vector<double> p_tot(hep.size());
04196   vector<double> k_u(hep.size());
04197   vector<double> k_v(hep.size());
04198   vector<double> epar(hep.size());
04199   vector<int> idhep(hep.size());
04200   vector<int> drawline(hep.size());
04201   
04202   for (int istd = 0; istd < int(hep.size()); istd++){
04203     drawline[istd] = 0;
04204     vtx_u[istd] = (hep[istd]->vtx[0]+hep[istd]->vtx[1])*sqrt(2.)/2;
04205     vtx_v[istd] = (hep[istd]->vtx[1]-hep[istd]->vtx[0])*sqrt(2.)/2;
04206     vtx_z[istd] = hep[istd]->vtx[2];
04207     
04208     p_u[istd] = (hep[istd]->p4[0]+hep[istd]->p4[1])*sqrt(2.)/2;
04209     p_v[istd] = (hep[istd]->p4[1]-hep[istd]->p4[0])*sqrt(2.)/2;
04210     p_z[istd] = hep[istd]->p4[2];
04211     p_tot[istd] = sqrt(p_u[istd]*p_u[istd] + p_v[istd]*p_v[istd] + 
04212                        p_z[istd]*p_z[istd]);
04213     
04214     epar[istd] = hep[istd]->p4[3];
04215     idhep[istd] = abs(hep[istd]->IdHEP);
04216     if (fabs(p_z[istd])>0.) {
04217       k_u[istd] = p_u[istd]/p_z[istd];
04218       k_v[istd] = p_v[istd]/p_z[istd];
04219     }
04220     
04221     bool drawphoton = false;
04222     if (abs(hep[istd]->IdHEP)==22){//photon
04223       NtpMCStdHep* hep_parent = 0;
04224       if (foundST){
04225         hep_parent = 
04226           dynamic_cast<NtpMCStdHep*>((*st->stdhep)[hep[istd]->parent[0]]);
04227       }
04228       else if (foundMC&&foundTH){
04229         hep_parent = 
04230           dynamic_cast<NtpMCStdHep*>((*mc->stdhep)[hep[istd]->parent[0]]);
04231       }
04232       if (abs(hep_parent->IdHEP)!=111) drawphoton = true;
04233     }
04234     //cout<<istd<<" "<<hep[istd]->index<<" "<<hep[istd]->mc<<" "<<hep[istd]->IdHEP<<" "<<hep[istd]->parent[0]<<" "<<hep[istd]->child[0]<<endl;
04235     
04236     //decide what to draw
04237     if((hep[istd]->child[0]==-1 && hep[istd]->child[1]==-1 &&
04238         (hep[istd]->IdHEP) && //IdHEP == 0 means incoming particle???
04239         abs(hep[istd]->IdHEP)<10000 && //only draw particles
04240         (abs(hep[istd]->IdHEP)==22 && drawphoton || abs(hep[istd]->IdHEP)!=22)) || (abs(hep[istd]->IdHEP)==111&&hep[istd]->IstHEP!=14) //draw pi0s and photons that didn't orginate from pi0s
04241        ||abs(hep[istd]->IdHEP)==13)
04242       drawline[istd]=1;
04243   }
04244   
04245   int ipar = 0;
04246   
04247   for (int istd = 0; istd < int(hep.size()); istd++){
04248     if (drawline[istd] == 1){
04249       if (p_tot[istd]){
04250         paru.push_back(new TLine(vtx_z[istd],vtx_u[istd],
04251                                  vtx_z[istd] + (p_z[istd]/p_tot[istd])*epar[istd]/3,
04252                                  vtx_u[istd] + p_u[istd]/p_tot[istd]*epar[istd]/3));
04253         parv.push_back(new TLine(vtx_z[istd],vtx_v[istd],
04254                                  vtx_z[istd] + (p_z[istd]/p_tot[istd])*epar[istd]/3,
04255                                  vtx_v[istd] + p_v[istd]/p_tot[istd]*epar[istd]/3));
04256       }
04257       else {
04258         paru.push_back(new TLine(vtx_z[istd],vtx_u[istd],
04259                                  vtx_z[istd],vtx_u[istd]));
04260         parv.push_back(new TLine(vtx_z[istd],vtx_v[istd],
04261                                  vtx_z[istd],vtx_v[istd]));
04262       }
04263       //cout<<"ipar "<<ipar<<" "<<idhep[istd]<<endl;
04264       if(idhep[istd] == 11) {     //electron
04265         paru[ipar]->SetLineColor(3);
04266         parv[ipar]->SetLineColor(3);
04267       }
04268       else if(idhep[istd] == 13) {//muon
04269         paru[ipar]->SetLineColor(4);
04270         parv[ipar]->SetLineColor(4);
04271       }
04272       else if(idhep[istd] == 15) {//tau
04273         paru[ipar]->SetLineColor(5);
04274         parv[ipar]->SetLineColor(5);
04275       }
04276       else if(idhep[istd] == 211){//pion
04277         paru[ipar]->SetLineColor(6);
04278         parv[ipar]->SetLineColor(6);
04279       }
04280       else if(idhep[istd] == 2212){//proton
04281         paru[ipar]->SetLineColor(2);
04282         parv[ipar]->SetLineColor(2);
04283       }
04284       else if(idhep[istd] == 111) { //pi0
04285         paru[ipar]->SetLineColor(7);
04286         parv[ipar]->SetLineColor(7);
04287       }
04288       else if(idhep[istd] == 22){  //photon
04289         paru[ipar]->SetLineColor(9);
04290         parv[ipar]->SetLineColor(9);
04291       }
04292       else if(idhep[istd] == 2112){//neutron
04293         paru[ipar]->SetLineColor(28);
04294         parv[ipar]->SetLineColor(28);
04295       }
04296       else if(idhep[istd] == 321 || idhep[istd] == 311 || 
04297               idhep[istd] == 310 || idhep[istd] == 130){//kaon
04298         paru[ipar]->SetLineColor(31);
04299         parv[ipar]->SetLineColor(31);
04300       }//anything else will be black
04301       else if(idhep[istd] == 12 || idhep[istd] == 14 ||
04302               idhep[istd] == 16){  //outgoing neutrino
04303         paru[ipar]->SetLineStyle(2); //black, dashed line
04304         parv[ipar]->SetLineStyle(2);
04305       }
04306       ipar++;
04307     }
04308   }
04309 
04310   if(mctruth) {
04311     mcvtx_u->SetY((mctruth->vtxy+mctruth->vtxx)/sqrt(2.));
04312     mcvtx_u->SetX(mctruth->vtxz);
04313   
04314     mcvtx_v->SetY((mctruth->vtxy-mctruth->vtxx)/sqrt(2.));
04315     mcvtx_v->SetX(mctruth->vtxz);
04316   }
04317 
04318   fHistPad->cd(1);
04319   for (int ipar = 0; ipar<int(paru.size()); ipar++){
04320     paru[ipar]->Draw();
04321   }
04322   mcvtx_u->Draw();
04323   gPad->Modified();
04324   
04325   fHistPad->cd(2);
04326   for (int ipar = 0; ipar<int(parv.size()); ipar++){
04327     parv[ipar]->Draw();
04328   }
04329   mcvtx_v->Draw();
04330   gPad->Modified();
04331   
04332   fCanvas0->Update();
04333   
04334   fHistcolz->cd(1);
04335   for (int ipar = 0; ipar<int(paru.size()); ipar++){
04336       paru[ipar]->Draw();
04337   }
04338   mcvtx_u->Draw();
04339   gPad->Modified();
04340   
04341   fHistcolz->cd(2);
04342   for (int ipar = 0; ipar<int(parv.size()); ipar++){
04343     parv[ipar]->Draw();
04344   }
04345   mcvtx_v->Draw();
04346   gPad->Modified();
04347     
04348   fCanvas1->Update();
04349 
04350   if(kDrawClu){
04351     fCanvas5->cd(1);
04352     for (int ipar = 0; ipar<int(paru.size()); ipar++){
04353       paru[ipar]->Draw();
04354     }
04355     mcvtx_u->Draw();
04356     gPad->Modified();
04357     
04358     fCanvas5->cd(4);
04359     for (int ipar = 0; ipar<int(parv.size()); ipar++){
04360       parv[ipar]->Draw();
04361     }
04362     mcvtx_v->Draw();
04363     gPad->Modified();
04364 
04365     fCanvas5->cd(2);
04366     for (int ipar = 0; ipar<int(paru.size()); ipar++){
04367       paru[ipar]->Draw();
04368     }
04369     mcvtx_u->Draw();
04370     gPad->Modified();
04371     
04372     fCanvas5->cd(5);
04373     for (int ipar = 0; ipar<int(parv.size()); ipar++){
04374       parv[ipar]->Draw();
04375     }
04376     mcvtx_v->Draw();
04377     gPad->Modified();
04378     
04379     fCanvas5->Update();
04380   }
04381 
04382   fInfo0->cd();
04383   info6->Draw();
04384   info7->Draw();
04385   info8->Draw();
04386   info9->Draw();
04387   info10->Draw();
04388   info11->Draw();
04389   info12->Draw();
04390   info13->Draw();
04391   gPad->Modified();
04392   fCanvas0->Update();
04393 
04394   if(!kTestMode) DrawInteractionDiagram(index);
04395   
04396   return;
04397 }
04398 
04399 void NueDisplayModule::delmc()
04400 {
04401   if (paru.size()) {
04402     for (int i = 0; i<int(paru.size()); i++){
04403       delete paru[i];
04404       delete parv[i];
04405     }
04406   }
04407   paru.clear();
04408   parv.clear();
04409   
04410   mcvtx_u->SetX(-100);
04411   mcvtx_v->SetY(-100);
04412   fInfo0->Clear();
04413   fInfo0->cd();
04414   info1->Draw();
04415   info2->Draw();
04416   info3->Draw();
04417   info4->Draw();
04418   info41->Draw();
04419   info5->Draw();
04420   //info6->Draw();
04421   gPad->Modified();
04422   fCanvas0->Update();
04423   
04424   fHistcolz->cd(1);
04425   gPad->Modified();
04426   fHistcolz->cd(2);
04427   gPad->Modified();
04428   fCanvas1->Update();
04429 
04430   if(kDrawClu){
04431     fCanvas5->cd(1);
04432     gPad->Modified();
04433     fCanvas5->cd(2);  
04434     gPad->Modified();
04435     fCanvas5->cd(4);  
04436     gPad->Modified();
04437     fCanvas5->cd(5);  
04438     gPad->Modified();
04439     fCanvas5->Update();
04440   }
04441 
04442   if(!kTestMode){
04443     fStdHepCan->cd();    
04444     TList *theList = fStdHepCan->GetListOfPrimitives();
04445     TIterator *iter = theList->MakeIterator();
04446     TObject *ob;
04447     while((ob = iter->Next())){
04448       if(ob->InheritsFrom("TLatex")) {
04449         TLatex *tex = (TLatex*) ob;
04450         delete tex;
04451       }
04452       else if(ob->InheritsFrom("TArrow")) {
04453         TArrow *ar = (TArrow*) ob;
04454         delete ar;
04455       }
04456       else if(ob->InheritsFrom("TMarker")) {
04457         TMarker *m = (TMarker*) ob;
04458         delete m;
04459       }
04460     }
04461     gPad->Modified();
04462     fStdHepCan->Update();
04463   }
04464 
04465 }
04466 
04467 void NueDisplayModule::fixmcinfo()
04468 {
04469   if (fSimFlag!=SimFlag::kMC) return;
04470   if (!ifixmcinfo){
04471     fFixMCInfo->SetDown(true);
04472     ifixmcinfo = 1;
04473     if (!imctruth){
04474       plotmc();
04475     }
04476     else {
04477       fMCTruth->SetDown(false);
04478       imctruth = 0;
04479     }
04480   }
04481   else {
04482     fFixMCInfo->SetDown(false);
04483     ifixmcinfo = 0;
04484     this->delmc();
04485   }
04486 }
04487   
04488 void NueDisplayModule::PrintPads()
04489 {
04490   fCanvas0->cd();
04491   //fHistPad->Print(Form("Evt_%d_%d_%d_%d.png",RunNo,SubRunNo,fSnarl,fEvent));
04492   fHistPad->Print(Form("Evt_%d_%d_%d_%d.eps",RunNo,SubRunNo,fSnarl,fEvent));
04493   fCanvas1->cd();
04494   fHistcolz->Print(Form("Evt_%d_%d_%d_%d_zoom.eps",RunNo,SubRunNo,fSnarl,fEvent));
04495   //fHistcolz->Print(Form("Evt_%d_%d_%d_%d_zoom.png",RunNo,SubRunNo,fSnarl,fEvent));
04496   fCanvas2->cd();
04497   fReco_plots->Print(Form("Evt_%d_%d_%d_%d_reco.eps",RunNo,SubRunNo,fSnarl,fEvent));
04498 }
04499 
04500 const Registry& NueDisplayModule::DefaultConfig() const
04501 {
04502 //======================================================================
04503 // Supply the default configuration for the module
04504 //======================================================================
04505    MSG("NueDisplayModule",Msg::kDebug)<<"In NueDisplayModule::DefaultConfig"<<endl;
04506 
04507   static Registry r = fCut.DefaultConfig();
04508 
04509   // Set name of config
04510   std::string name = this->GetName();
04511   name += ".config.default";
04512   r.SetName(name.c_str());
04513 
04514   // Set values in configuration
04515   r.UnLockValues();
04516   r.Set("DPlaneCut",-1);
04517   r.Set("LoPhNStripCut",-1);
04518   r.Set("LoPhNPlaneCut",-1);
04519   r.Set("PhStripCut",-1);
04520   r.Set("PhPlaneCut",-1);
04521   r.Set("ContPhPlaneCut",-1);
04522 
04523   r.Set("PIDCut",-1);
04524   r.Set("ScanMode",0);
04525   r.Set("TestMode",0);
04526   r.Set("HideRunSnarl",0);
04527   r.Set("DrawClu",0);
04528   r.Set("IntReco",0);
04529   r.LockValues();
04530 
04531   return r;
04532 }
04533 
04534 //......................................................................
04535 
04536 void NueDisplayModule::Config(const Registry& r)
04537 {
04538 //======================================================================
04539 // Configure the module given the Registry r
04540 //======================================================================
04541   MSG("NueDisplayModule",Msg::kDebug)<<"In NueDisplayModule::Config"<<endl;
04542 
04543   fCut.Config(r);
04544 
04545   int imps;
04546   if(r.Get("DPlaneCut",imps)) { kDPlaneCut=imps;}
04547   if(r.Get("LoPhNStripCut",imps)) { kLoPhNStripCut=imps;}
04548   if(r.Get("LoPhNPlaneCut",imps)) { kLoPhNPlaneCut=imps;}
04549 
04550   if(r.Get("ScanMode",imps)) {kScanMode=imps;}
04551   if(r.Get("TestMode",imps)) {kTestMode=imps;}
04552   if(r.Get("HideRunSnarl",imps)) {kHideRunSnarl=imps;}
04553   if(r.Get("DrawClu",imps)) {kDrawClu=imps;}
04554   if(r.Get("IntReco",imps)) {kIntReco=imps;}
04555   double fmps;
04556   if(r.Get("PhStripCut",fmps)) { kPhStripCut=fmps;}
04557   if(r.Get("PhPlaneCut",fmps)) { kPhPlaneCut=fmps;}
04558   if(r.Get("ContPhPlaneCut",fmps)) { kCPhPlaneCut=fmps;}
04559 
04560   if(r.Get("PIDCut",fmps)) { kPIDCut=fmps;}
04561 }
04562 
04563 void NueDisplayModule::DeleteOldCrap()
04564 {
04565   //  cout<<"In delete old crap"<<endl;
04566   //  gDirectory->ls();
04567   TList *l = gDirectory->GetList();
04568   TIterator *it(l->MakeIterator());
04569   //  int NOBJ=l->GetSize();
04570   //  cout<<"Size of list "<<NOBJ<<endl;
04571   TObject *obj;
04572   while((obj=it->Next())){
04573     //    TObject *obj=l->At(i);
04574     const char* kn=obj->GetName();
04575     //    cout<<" Found a "<<kn<<endl;
04576     if(strstr(kn,"lenepl")!=NULL){
04577       obj->Delete();
04578       //      cout<<"deletint "<<kn<<endl;
04579     }
04580     if(strstr(kn,"tenestu")!=NULL){
04581       obj->Delete();
04582       //      cout<<"deletint "<<kn<<endl;
04583     }
04584     if(strstr(kn,"tenestv")!=NULL){
04585       obj->Delete();
04586       //      cout<<"deletint "<<kn<<endl;
04587     }
04588     if(strstr(kn,"LongHitHisto")!=NULL){
04589       obj->Delete();
04590       //      cout<<"deletint "<<kn<<endl;
04591     }
04592     if(strstr(kn,"TransHitHisto")!=NULL){
04593       obj->Delete();
04594       //      cout<<"deletint "<<kn<<endl;
04595     }
04596   }
04597 }
04598 
04599 void NueDisplayModule::updateEncoded(){
04600   string tmp = evtpcode[ievtp] + " | " + topocode[itopo];
04601   fEncoded->SetText(tmp.c_str());
04602 }
04603 
04604 void NueDisplayModule::OpenFileWrite(){
04605 
04606   if (!iFileW){
04607     string setfilename;
04608     string sRunNumber=Form("%d",RunNo);
04609     string sRunNumberSub=Form("%d",SubRunNo);
04610     setfilename = "PID-"+sRunNumber+"_"+sRunNumberSub;
04611     
04612     ifstream Test(setfilename.c_str());
04613     if(Test){
04614       //Need new filename
04615       Int_t fred=1;
04616       while(Test) {
04617         Test.close();
04618         string ifred = Form("%d",fred);
04619         setfilename = "PID-"+sRunNumber+"_"+sRunNumberSub+"_"+ifred;
04620         
04621         Test.open(setfilename.c_str());
04622         fred++;
04623       }
04624     }
04625     outfile.open(setfilename.c_str());
04626     string fn = "Write Records to File: "+setfilename;
04627     fFileW->SetText(fn.c_str());
04628     iFileW = 1; //file opened
04629   }
04630   else {
04631     //if (iIO) MSG("NueDisplayModule",Msg::kError)<<"In Read Mode"<<endl;
04632     MSG("NueDisplayModule",Msg::kInfo)<<"File already opened!"<<endl;
04633   }
04634 }  
04635 
04636 void NueDisplayModule::logvote(){
04637   if (!iFileW){
04638     this->OpenFileWrite();
04639   }
04640   if (!hitlog){
04641   
04642     //Copied from fcanvas0 to fill in energy values in the output file  
04643     int ntrks = event->ntrack;
04644     int nshws = event->nshower;
04645     Float_t trk_mom_range = 0;
04646     Float_t trk_planes = 0;
04647     Float_t shw_ph = 0;
04648     Float_t shw_shwph = 0;
04649     if (foundST){
04650     if (ntrks){
04651       for (int i = 0; i<ntrks; i++){
04652         int index = SntpHelpers::GetTrackIndex(i,event);
04653         NtpSRTrack *track = SntpHelpers::GetTrack(index,st);
04654         if (track->plane.n>trk_planes) {
04655           trk_mom_range = track->momentum.range;
04656           trk_planes = track->plane.n;
04657         }
04658         }
04659       }
04660     }
04661   
04662     if (nshws){
04663       for (int i = 0; i<nshws; i++){
04664         int index = SntpHelpers::GetShowerIndex(i,event);
04665         NtpSRShower *shower = SntpHelpers::GetShower(index,st);
04666         if (shower->shwph.linCCgev>shw_shwph) {
04667           shw_ph = shower->ph.gev;
04668           shw_shwph = shower->shwph.linCCgev;
04669         }
04670       }
04671     }
04672   
04673     
04674     outfile<<RunNo<<" "<<SubRunNo<<" "<<fSnarl<<" "<<fEvent<<" "<<ievtp<<" "<<itopo<<" "<<shw_ph+trk_mom_range<<" "<<shw_ph<<" "<<trk_mom_range;
04675     hitlog = 1;
04676     if (ievtp>=0&&ievtp<7&&itopo>=0&&itopo<5){
04677       //string tmp = evtpcode[ievtp] + " | " + topocode[itopo];
04678       string tmp = Form("%d | %d",ievtp, itopo);
04679       fEncoded->SetText(tmp.c_str());
04680     }
04681   }
04682 }
04683 
04684 void NueDisplayModule::makecomment(){
04685   if (hitlog ==1 && !icomm) {
04686     outfile<<"  "<<fComment->GetText()<<endl;
04687     fComment->Clear();
04688     icomm = 1;
04689   }
04690 }
04691 
04692 void NueDisplayModule::SetMode(){
04693   if (!iIO){ 
04694     fIO->SetText("Read"); 
04695     iIO = 1;
04696     fIO->SetDown(true);
04697     if (iFileW){
04698       if (!icomm && hitlog) outfile<<endl;
04699       outfile<<endl;
04700       outfile.close();
04701       hitlog = 0;
04702       icomm = 0;
04703       ievtp = 0;
04704       itopo = 0;
04705       this->updateEncoded();
04706       iFileW = 0;
04707       fFileW->SetText("");
04708     }
04709     string setfilename;
04710     string sRunNumber=Form("%d",RunNo);
04711     string sRunNumberSub=Form("%d",SubRunNo);
04712     setfilename = "PID-"+sRunNumber+"_"+sRunNumberSub;
04713     
04714     ifstream Test(setfilename.c_str());
04715     if(Test){
04716       fFileEnt->SetText(setfilename.c_str());
04717     }
04718   }
04719   else { 
04720     fIO->SetText("Write"); 
04721     iIO = 0;
04722     fIO->SetDown(false);
04723     fFileEnt->Clear();
04724     fFileR->SetText("");
04725     fFileW->SetText("");
04726     if (iFileW){
04727       if (!icomm && hitlog) outfile<<endl;
04728       outfile<<endl;
04729       outfile.close();
04730       hitlog = 0;
04731       iFileW = 0;
04732     }
04733     fTYPETOPO->SetText("");
04734 
04735     runno.clear();
04736     subrunno.clear();
04737     snarlno.clear();
04738     eventno.clear();
04739     eventtype.clear();
04740     eventtopo.clear();
04741     eventcomm.clear();
04742     
04743   }
04744 }
04745 
04746 void NueDisplayModule::updateselec(){
04747   if (!iEvtp[0]&&!iEvtp[1]&&!iEvtp[2]&&!iEvtp[3]&&!iEvtp[4]&&!iEvtp[5]&&!iEvtp[6]) selecevtp = 0;
04748   else selecevtp = 1;
04749   
04750   if (!iTopo[0]&&!iTopo[1]&&!iTopo[2]&&!iTopo[3]&&!iTopo[4]) selectopo = 0;
04751   else selectopo = 1;
04752 }
04753 
04754 void NueDisplayModule::OpenFileRead(){
04755   if (iIO == 1){
04756     ifstream ins(fFileEnt->GetText());
04757     if (ins){
04758       fFileR->SetText(Form("Read Records from File: %s",fFileEnt->GetText()));
04759       fFileEnt->Clear();
04760       clickbutton = 0;
04761       Int_t n1,n2,n3,n4,n5,n6;
04762       while(!ins.eof()){
04763         //ins.getline(buf,100);
04764         //sscanf(buf,"%d%d%d%d%d%d",&n1,&n2,&n3,&n4,&n5,&n6);
04765         ins>>n1>>n2>>n3>>n4>>n5>>n6;
04766         char buf[1000];
04767         ins.getline(buf,1000);
04768         if (!ins.eof()){
04769           //cout<<n1<<" "<<n2<<" "<<n3<<" "<<n4<<" "<<n5<<" "<<n6<<endl;
04770           //if (n1 == RunNo && n2 == SubRunNo){
04771           runno.push_back(n1);
04772           subrunno.push_back(n2);
04773           snarlno.push_back(n3);
04774           eventno.push_back(n4);
04775           eventtype.push_back(n5);
04776           eventtopo.push_back(n6);
04777           if (strlen(buf)>2)
04778             eventcomm.push_back(buf+2);
04779           else eventcomm.push_back(buf);
04780           //}
04781         }
04782       }//while
04783       runnoitr = runno.begin()-1;
04784       subrunnoitr = subrunno.begin()-1;
04785       snarlnoitr = snarlno.begin()-1;
04786       eventnoitr = eventno.begin()-1;
04787       typeitr = eventtype.begin()-1;
04788       topoitr = eventtopo.begin()-1;
04789       commitr = eventcomm.begin()-1;      
04790     }
04791   }
04792 }
04793 
04794 void NueDisplayModule::NextSelEvt(){
04795   if (iIO&&snarlno.size()){
04796     /*
04797       cout<<*runnoitr<<" "<<*subrunnoitr<<" "
04798       <<fSnarl<<" "<<fEvent
04799       <<" "<<*snarlnoitr<<" "<<*eventnoitr<<endl;
04800 
04801     if(runnoitr<runno.end()&&runnoitr>=runno.begin()&&
04802        subrunnoitr<subrunno.end()&&subrunnoitr>=subrunno.begin()&&
04803        snarlnoitr<snarlno.end()&&snarlnoitr>=snarlno.begin()
04804        &&(fSnarl < *snarlnoitr || fSnarl == *snarlnoitr && 
04805        fEvent < *eventnoitr)){
04806     if(fSnarl == *snarlnoitr && fEvent < *eventnoitr){
04807       if ((!selecevtp||iEvtp[*typeitr])&&(!selectopo||iTopo[*topoitr])){
04808         fEvent = *eventnoitr;
04809         ievtp = *typeitr;
04810         itopo = *topoitr;
04811         //gMint->GoTo(*runnoitr,*snarlnoitr);
04812         if (*typeitr>=0&&*typeitr<7&&*topoitr>=0&&*topoitr<5){
04813           string tmp = evtpcode[*typeitr] + " | " + topocode[*topoitr];
04814           fTYPETOPO->SetText(tmp.c_str());
04815         }
04816         fComment->SetText((*commitr).c_str());
04817       }
04818     }
04819     else 
04820     */
04821     if (snarlnoitr != snarlno.end() && snarlnoitr != snarlno.end() - 1){    
04822       runnoitr++;
04823       subrunnoitr++;
04824       snarlnoitr++;
04825       eventnoitr++;
04826       typeitr++;
04827       topoitr++;
04828       commitr++;
04829       if ((!selecevtp||iEvtp[*typeitr])&&(!selectopo||iTopo[*topoitr])){
04830         fEvent = *eventnoitr;
04831         ievtp = *typeitr;
04832         itopo = *topoitr;
04833         gMint->GoTo(*runnoitr,*snarlnoitr);
04834         if (*typeitr>=0&&*typeitr<7&&*topoitr>=0&&*topoitr<5){
04835           string tmp = evtpcode[*typeitr] + " | " + topocode[*topoitr];
04836           fTYPETOPO->SetText(tmp.c_str());
04837         }
04838         fComment->SetText((*commitr).c_str());
04839       }
04840       else {this->NextSelEvt();}
04841     }
04842   }
04843 }
04844 
04845 void NueDisplayModule::PrevSelEvt(){
04846   if (iIO&&snarlno.size()){
04847     /*
04848     cout<<*runnoitr<<" "<<*subrunnoitr<<" "
04849         <<fSnarl<<" "<<fEvent<<" "
04850         <<*snarlnoitr<<" "<<*eventnoitr<<endl;
04851     if(runnoitr<runno.end()&&runnoitr>=runno.begin()&&
04852        subrunnoitr<subrunno.end()&&subrunnoitr>=subrunno.begin()&&
04853        snarlnoitr<snarlno.end()&&snarlnoitr>=snarlno.begin()&&
04854        (fSnarl > *snarlnoitr || fSnarl == *snarlnoitr && 
04855         fEvent > *eventnoitr)){
04856       if ((!selecevtp||iEvtp[*typeitr])&&(!selectopo||iTopo[*topoitr])){
04857         fEvent = *eventnoitr;
04858         ievtp = *typeitr;
04859         itopo = *topoitr;
04860         gMint->GoTo(*runnoitr,*snarlnoitr);
04861         if (*typeitr>=0&&*typeitr<7&&*topoitr>=0&&*topoitr<5){
04862           string tmp = evtpcode[*typeitr] + " | " + topocode[*topoitr];
04863           fTYPETOPO->SetText(tmp.c_str());
04864         }
04865         fComment->SetText((*commitr).c_str());
04866       }
04867     }
04868     else */
04869     if (snarlnoitr != snarlno.begin() && snarlnoitr != snarlno.begin() -1){
04870       runnoitr--;
04871       subrunnoitr--;
04872       snarlnoitr--;
04873       eventnoitr--;
04874       typeitr--;
04875       topoitr--;
04876       commitr--;
04877       if ((!selecevtp||iEvtp[*typeitr])&&(!selectopo||iTopo[*topoitr])){
04878         fEvent = *eventnoitr;
04879         gMint->GoTo(*runnoitr,*snarlnoitr);
04880         if (*typeitr>=0&&*typeitr<7&&*topoitr>=0&&*topoitr<5){
04881           string tmp = evtpcode[*typeitr] + " | " + topocode[*topoitr];
04882           fTYPETOPO->SetText(tmp.c_str());
04883         }
04884         fComment->SetText((*commitr).c_str());
04885       }
04886       else {this->PrevSelEvt();}
04887     }
04888   }
04889 }
04890 
04891 void NueDisplayModule::IntRecoCalc(){
04892 
04893   fIntRecoHistZ->Reset();
04894   fIntRecoHistU->Reset();
04895   fIntRecoHistV->Reset();
04896   fPredictedHistZ->Reset();
04897   fPredictedHistU->Reset();
04898   fPredictedHistV->Reset();
04899   fUZPred->Reset();
04900   fVZPred->Reset();
04901 
04902   Bool_t doSim = true;
04903   if(fIntRecoDoSim->GetFillColor()==2) doSim = false;
04904   
04905   RecRecordImp<RecCandHeader> *rr = 
04906     dynamic_cast<RecRecordImp<RecCandHeader>*>
04907     ((gMint->GetJobC().Mom).GetFragment("RecRecordImp<RecCandHeader>"));
04908 
04909   vector<Int_t> striplist;
04910   for(UInt_t i=0;i<fStripButtonU.size();i++){
04911     if(fStripButtonU[i]->GetFillColor()==11){
04912       const char *name = fStripButtonU[i]->GetName();
04913       TString nom(name);
04914       nom.Chop();
04915       nom.Remove(0,nom.First("_")+1);
04916       striplist.push_back(atoi(nom.Data()));
04917     }
04918   }
04919   for(UInt_t i=0;i<fStripButtonV.size();i++){
04920     if(fStripButtonV[i]->GetFillColor()==11){
04921       const char *name = fStripButtonV[i]->GetName();
04922       TString nom(name);
04923       nom.Chop();
04924       nom.Remove(0,nom.First("_")+1);
04925       striplist.push_back(atoi(nom.Data()));
04926     }
04927   }
04928   if(striplist.size()==0) return;
04929 
04930   //translate arrow positions back to u,v,z in metres:
04931   Float_t evtZ1 = fUZcolz->GetXaxis()->GetBinCenter(1) + 
04932     (fUZcolz->GetXaxis()->GetBinLowEdge(fUZcolz->GetNbinsX()+1) - 
04933      fUZcolz->GetXaxis()->GetBinLowEdge(1)) * 
04934     (fIntRecoLineU->GetX1()-0.025)/0.95;
04935   Float_t evtU =  fUZcolz->GetYaxis()->GetBinCenter(1) + 
04936     (fUZcolz->GetYaxis()->GetBinLowEdge(fUZcolz->GetNbinsY()+1) - 
04937      fUZcolz->GetYaxis()->GetBinLowEdge(1)) * 
04938     (fIntRecoLineU->GetY1()-0.025)/0.95;
04939   Float_t evtZ = fVZcolz->GetXaxis()->GetBinCenter(1) + 
04940     (fVZcolz->GetXaxis()->GetBinLowEdge(fVZcolz->GetNbinsX()+1) - 
04941      fVZcolz->GetXaxis()->GetBinLowEdge(1)) * 
04942     (fIntRecoLineV->GetX1()-0.025)/0.95;
04943   Float_t evtV =  fVZcolz->GetYaxis()->GetBinCenter(0) + 
04944     (fVZcolz->GetYaxis()->GetBinLowEdge(fVZcolz->GetNbinsY()+1) - 
04945      fVZcolz->GetYaxis()->GetBinLowEdge(1)) * 
04946     (fIntRecoLineV->GetY1()-0.025)/0.95;
04947 
04948   Float_t endZ1 = fUZcolz->GetXaxis()->GetBinCenter(1) + 
04949     (fUZcolz->GetXaxis()->GetBinLowEdge(fUZcolz->GetNbinsX()+1) - 
04950      fUZcolz->GetXaxis()->GetBinLowEdge(1)) * 
04951     (fIntRecoLineU->GetX2()-0.025)/0.95;
04952   Float_t endU =  fUZcolz->GetYaxis()->GetBinCenter(1) + 
04953     (fUZcolz->GetYaxis()->GetBinLowEdge(fUZcolz->GetNbinsY()+1) - 
04954      fUZcolz->GetYaxis()->GetBinLowEdge(1)) * 
04955     (fIntRecoLineU->GetY2()-0.025)/0.95;
04956   Float_t endZ = fVZcolz->GetXaxis()->GetBinCenter(1) + 
04957     (fVZcolz->GetXaxis()->GetBinLowEdge(fVZcolz->GetNbinsX()+1) - 
04958      fVZcolz->GetXaxis()->GetBinLowEdge(1)) * 
04959     (fIntRecoLineV->GetX2()-0.025)/0.95;
04960   Float_t endV =  fVZcolz->GetYaxis()->GetBinCenter(0) + 
04961     (fVZcolz->GetYaxis()->GetBinLowEdge(fVZcolz->GetNbinsY()+1) - 
04962      fVZcolz->GetYaxis()->GetBinLowEdge(1)) * 
04963     (fIntRecoLineV->GetY2()-0.025)/0.95; 
04964 
04965   Float_t dudz = (endU-evtU)/(endZ1-evtZ1);
04966   Float_t dvdz = (endV-evtV)/(endZ-evtZ);
04967 
04968   //choose minimum Z value and adjust U/V vertex position
04969   if(evtZ1<evtZ) {
04970     evtV += dvdz*(evtZ1-evtZ);
04971     evtZ = evtZ1;
04972   }
04973   else evtU += dudz*(evtZ-evtZ1);
04974 
04975   Float_t minZ = 30;
04976   Float_t maxZ = -30;
04977   Float_t minTP = +8;
04978   Float_t maxTP = -8;
04979 
04980   Int_t minPl = 500;
04981   Int_t maxPl = 0;
04982   Int_t minStpU = 200;
04983   Int_t maxStpU = 0;
04984   Int_t minStpV = 200;
04985   Int_t maxStpV = 0;
04986 
04987   Int_t vtxView = 0;
04988   Int_t vtxPln = 0;
04989   Int_t vtxStpU = 0;
04990   Int_t vtxStpV = 0;
04991   Float_t vtxZDiff = 1000;
04992   Float_t vtxUDiff = 1000;
04993   Float_t vtxVDiff = 1000;
04994 
04995   vector<Int_t>::iterator stripitr = striplist.begin();
04996   vector<Int_t>::iterator stripend = striplist.end();
04997   while(stripitr!=stripend){
04998     NtpSRStrip *strip = SntpHelpers::GetStrip(*stripitr,rr);  
04999     if(strip->z-evtZ<minZ) {
05000       minZ = strip->z-evtZ;
05001       minPl = strip->plane;
05002     }
05003     if(strip->z-evtZ>maxZ) {
05004       maxZ = strip->z-evtZ;
05005       maxPl = strip->plane;
05006     }
05007     if(TMath::Abs(strip->z-evtZ)<TMath::Abs(vtxZDiff)) {
05008       vtxZDiff = strip->z-evtZ;
05009       vtxPln = strip->plane;
05010       vtxView = strip->planeview;
05011     }
05012     if(strip->planeview==2){
05013       if(strip->tpos-evtU<minTP) minTP=strip->tpos-evtU;
05014       if(strip->strip<minStpU) minStpU = strip->strip;
05015       if(strip->tpos-evtU>maxTP) maxTP=strip->tpos-evtU;
05016       if(strip->strip>maxStpU) maxStpU = strip->strip;
05017       if(TMath::Abs(strip->tpos-evtU)<TMath::Abs(vtxUDiff)) {
05018         vtxUDiff = strip->tpos-evtU;
05019         vtxStpU = strip->strip;
05020       }
05021     }
05022     if(strip->planeview==3){
05023       if(strip->tpos-evtV<minTP) minTP=strip->tpos-evtV;
05024       if(strip->strip<minStpV) minStpV = strip->strip;
05025       if(strip->tpos-evtV>maxTP) maxTP=strip->tpos-evtV;
05026       if(strip->strip>maxStpV) maxStpV = strip->strip;
05027       if(TMath::Abs(strip->tpos-evtV)<TMath::Abs(vtxVDiff)) {
05028         vtxVDiff = strip->tpos-evtV;
05029         vtxStpV = strip->strip;
05030       }
05031     }
05032     stripitr++;
05033   }
05034   stripitr = striplist.begin();
05035   
05036   // make sure vtx plane and strip are not more 
05037   // than 1plane or 1strip away from the true vertex
05038   while(TMath::Abs(vtxZDiff)>0.06) {
05039     if(vtxZDiff>0) {
05040       vtxZDiff -= 0.06;
05041       vtxPln -= 1;
05042       if(vtxView == 2) vtxView = 3;
05043       else vtxView = 2;
05044     }
05045     else if(vtxUDiff<0) {
05046       vtxZDiff += 0.06;
05047       vtxPln += 1;
05048       if(vtxView == 2) vtxView = 3;
05049       else vtxView = 2;
05050     }
05051   }
05052   while(TMath::Abs(vtxUDiff)>0.041) {
05053     if(vtxUDiff>0) {
05054       vtxUDiff -= 0.041;
05055       vtxStpU -= 1;
05056     }
05057     else if(vtxUDiff<0) {
05058       vtxUDiff += 0.041;
05059       vtxStpU += 1;
05060     }
05061   }
05062   while(TMath::Abs(vtxVDiff)>0.041) {
05063     if(vtxVDiff>0) {
05064       vtxVDiff -= 0.041;
05065       vtxStpV -= 1;
05066     }
05067     else if(vtxVDiff<0) {
05068       vtxVDiff += 0.041;
05069       vtxStpV += 1;
05070     }
05071   }
05072 
05073   fIntRecoHistZ->SetBins(5+int((maxZ-minZ)/0.0585),
05074                          minZ-0.1475,maxZ+0.1475);
05075   fIntRecoHistU->SetBins(5+int((maxTP-minTP)/0.0405),
05076                          minTP-0.1025,maxTP+0.1025);
05077   fIntRecoHistV->SetBins(5+int((maxTP-minTP)/0.0405),
05078                          minTP-0.1025,maxTP+0.1025);
05079 
05080   while(stripitr!=stripend){
05081     NtpSRStrip *strip = SntpHelpers::GetStrip(*stripitr,rr);    
05082     fIntRecoHistZ->Fill(strip->z-evtZ,(strip->ph0.sigcor + 
05083                                        strip->ph1.sigcor)/SIGMAPMEU);
05084     if(strip->planeview==2) fIntRecoHistU->Fill(strip->tpos-evtU,
05085                                                 (strip->ph0.sigcor + 
05086                                                  strip->ph1.sigcor) / 
05087                                                 SIGMAPMEU);
05088     if(strip->planeview==3) fIntRecoHistV->Fill(strip->tpos-evtV,
05089                                                 (strip->ph0.sigcor + 
05090                                                  strip->ph1.sigcor) / 
05091                                                 SIGMAPMEU);
05092     stripitr++;
05093   }
05094 
05095   for(int i=1;i<=fIntRecoHistZ->GetNbinsX();i++){
05096     Float_t error = fIntRecoHistZ->GetBinContent(i);
05097     if(error>0) error = TMath::Sqrt(error);
05098     fIntRecoHistZ->SetBinError(i,error);
05099   }
05100   for(int i=1;i<=fIntRecoHistU->GetNbinsX();i++){
05101     Float_t error = fIntRecoHistU->GetBinContent(i);
05102     if(error>0) error = TMath::Sqrt(error);
05103     fIntRecoHistU->SetBinError(i,error);
05104     error = fIntRecoHistV->GetBinContent(i);
05105     if(error>0) error = TMath::Sqrt(error);
05106     fIntRecoHistV->SetBinError(i,error);
05107   }
05108 
05109   //Get prediction:
05110   fPredictedHistZ->SetBins(5+int((maxZ-minZ)/0.0585),
05111                            minZ-0.1475,maxZ+0.1475);
05112   fPredictedHistU->SetBins(5+int((maxTP-minTP)/0.0405),
05113                            minTP-0.1025,maxTP+0.1025);
05114   fPredictedHistV->SetBins(5+int((maxTP-minTP)/0.0405),
05115                            minTP-0.1025,maxTP+0.1025);
05116   
05117   fUZPred->SetBins(5+maxPl-minPl,minPl-2.5,maxPl+2.5,
05118                    5+maxStpU-minStpU,minStpU-2.5,maxStpU+2.5);
05119   fVZPred->SetBins(5+maxPl-minPl,minPl-2.5,maxPl+2.5,
05120                    5+maxStpV-minStpV,minStpV-2.5,maxStpV+2.5);
05121 
05122   Float_t totalPE = fIntRecoHistZ->Integral();
05123   Float_t energy = totalPE*0.0268;
05124   if(doSim && energy>0.1){
05125     FitterEM *fit = new FitterEM();
05126     fit->QuickInput(energy,vtxUDiff,vtxVDiff,vtxZDiff,
05127                     dudz,dvdz,vtxView);
05128     double binFluc = 1;
05129     for(int i=minPl-2;i<=maxPl+2;i++) {
05130       
05131       Int_t view = 0;
05132       if(i%2==vtxPln%2) view = vtxView;
05133       else if(vtxView==2) view=3;
05134       else if(vtxView==3) view=2;
05135       
05136       if(view==2){
05137         for(int j=minStpU-2;j<=maxStpU+2;j++) {   
05138           fUZPred->Fill(i,j,fit->PredictEMLoss(i-vtxPln,j-vtxStpU,binFluc));
05139           fPredictedHistU->Fill(fPredictedHistU->GetBinCenter(fPredictedHistU->FindBin((j-vtxStpU)*0.041+vtxUDiff)),fit->PredictEMLoss(i-vtxPln,j-vtxStpU,binFluc));
05140           fPredictedHistZ->Fill(fPredictedHistZ->GetBinCenter(fPredictedHistZ->FindBin((i-vtxPln)*0.059+vtxZDiff)),fit->PredictEMLoss(i-vtxPln,j-vtxStpU,binFluc));
05141         }
05142       }
05143       else if(view==3){
05144         for(int j=minStpV-2;j<=maxStpV+2;j++) {   
05145           fVZPred->Fill(i,j,fit->PredictEMLoss(i-vtxPln,j-vtxStpV,binFluc));
05146           fPredictedHistV->Fill(fPredictedHistV->GetBinCenter(fPredictedHistV->FindBin((j-vtxStpV)*0.041+vtxVDiff)),fit->PredictEMLoss(i-vtxPln,j-vtxStpV,binFluc));
05147           fPredictedHistZ->Fill(fPredictedHistZ->GetBinCenter(fPredictedHistZ->FindBin((i-vtxPln)*0.059+vtxZDiff)),fit->PredictEMLoss(i-vtxPln,j-vtxStpV,binFluc));
05148         }
05149       }
05150     }
05151     delete fit;
05152   }
05153   
05154   Float_t maxValue = 0;
05155   if(fUZPred->Integral()>0) {
05156     fUZPred->Scale(fUZcolz->Integral()/fUZPred->Integral());
05157     maxValue = fUZPred->GetBinContent(fUZPred->GetMaximumBin());
05158   }
05159   if(fVZPred->Integral()>0) {
05160     fVZPred->Scale(fVZcolz->Integral()/fVZPred->Integral());
05161     if(fVZPred->GetBinContent(fVZPred->GetMaximumBin())>maxValue) 
05162       maxValue = fVZPred->GetBinContent(fVZPred->GetMaximumBin());
05163   }
05164   if(maxValue>0) {
05165     fUZPred->SetMaximum(maxValue*1.1);
05166     fVZPred->SetMaximum(maxValue*1.1);
05167     fUZPred->SetMinimum(maxValue*0.01);
05168     fVZPred->SetMinimum(maxValue*0.01);
05169   }
05170 
05171   maxValue = 0;
05172   if(fPredictedHistU->Integral()>0) {
05173     fPredictedHistU->Scale(fIntRecoHistU->Integral() /
05174                            fPredictedHistU->Integral());
05175     maxValue = fPredictedHistU->GetBinContent(fPredictedHistU->GetMaximumBin());
05176   }
05177   if(fIntRecoHistU->Integral()>0 &&
05178      fIntRecoHistU->GetBinContent(fIntRecoHistU->GetMaximumBin())>maxValue) 
05179     maxValue = fIntRecoHistU->GetBinContent(fIntRecoHistU->GetMaximumBin());
05180   
05181   if(fPredictedHistV->Integral()>0) {
05182     fPredictedHistV->Scale(fIntRecoHistV->Integral() / 
05183                            fPredictedHistV->Integral());
05184     if(fPredictedHistV->GetBinContent(fPredictedHistV->GetMaximumBin())>maxValue)
05185       maxValue = fPredictedHistV->GetBinContent(fPredictedHistV->GetMaximumBin());
05186   }
05187   if(fIntRecoHistV->GetBinContent(fIntRecoHistV->GetMaximumBin())>maxValue) 
05188     maxValue = fIntRecoHistV->GetBinContent(fIntRecoHistV->GetMaximumBin());
05189 
05190   if(maxValue>0) {
05191     fPredictedHistU->SetMaximum(maxValue*1.1);
05192     fIntRecoHistU->SetMaximum(maxValue*1.1);
05193     fPredictedHistV->SetMaximum(maxValue*1.1);
05194     fIntRecoHistV->SetMaximum(maxValue*1.1);
05195   }
05196 
05197   maxValue = 0;
05198   if(fPredictedHistZ->Integral()>0) {
05199     fPredictedHistZ->Scale(fIntRecoHistZ->Integral() / 
05200                            fPredictedHistZ->Integral());
05201     maxValue = fPredictedHistZ->GetBinContent(fPredictedHistZ->GetMaximumBin());
05202   }
05203   if(fIntRecoHistZ->Integral()>0 && 
05204      fIntRecoHistZ->GetBinContent(fIntRecoHistZ->GetMaximumBin())>maxValue) 
05205     maxValue = fIntRecoHistZ->GetBinContent(fIntRecoHistZ->GetMaximumBin());
05206   if(maxValue>0) {
05207     fPredictedHistZ->SetMaximum(maxValue*1.1);
05208     fIntRecoHistZ->SetMaximum(maxValue*1.1);
05209   }
05210   
05211   fCanvas6->cd(1); gPad->Modified();
05212   fCanvas6->cd(2); gPad->Modified();
05213   fCanvas6->cd(3); gPad->Modified();
05214   fCanvas6->cd(4); gPad->Modified();
05215   fCanvas6->Update();
05216   
05217   cout << "=================================" << endl;
05218   cout << "Interative Display Calculations:" << endl;
05219   cout << "Energy of selected hits: " << energy << " GeV" << endl;
05220   cout << "Vertex from arrow positions (u,v,z) (metres): " 
05221        << evtU << " " << evtV << " " << evtZ << endl;
05222   cout << "Approximate Vertex in strip/plane (u,v,z): " 
05223        << vtxStpU << " " << vtxStpV << " " << vtxPln << endl;
05224   cout << "Offsets from approx vertex to arrow vertex: "
05225        << vtxUDiff << " " << vtxVDiff << " " << vtxZDiff << endl;
05226   cout << "Angles from arrow directions; dudz: " << dudz 
05227        << " dvdz: " << dvdz << endl;
05228   cout << "---------------------------------" << endl;
05229   cout << endl;
05230 }
05231       
05232 void NueDisplayModule::SetUpStripButtons(){
05233 
05234   for(UInt_t i=0;i<fStripButtonU.size();i++){
05235     delete fStripButtonU[i];
05236   }
05237   fStripButtonU.clear();
05238   for(UInt_t i=0;i<fStripButtonV.size();i++){
05239     delete fStripButtonV[i];
05240   }
05241   fStripButtonV.clear();
05242 
05243   Int_t nbinsx = fUZcolz->GetNbinsX();
05244   Float_t binwidthx = 1./Float_t(nbinsx);
05245   Int_t nbinsy = fUZcolz->GetNbinsY();
05246   Float_t binwidthy = 1./Float_t(nbinsy);
05247   Float_t max = fUZcolz->GetMaximum();
05248   Float_t minChargeUZ = 0;
05249   if(fUZcolz->GetMinimum()>minChargeUZ) minChargeUZ = fUZcolz->GetMinimum();
05250   Float_t minChargeVZ = 0;
05251   if(fVZcolz->GetMinimum()>minChargeVZ) minChargeVZ = fVZcolz->GetMinimum();
05252 
05253   Int_t ncol = gStyle->GetNumberOfColors();
05254 
05255   fSelectPad1->cd();
05256   for(int i=1;i<=nbinsx;i++){
05257     for(int j=1;j<=nbinsy;j++){
05258       if(fUZcolz->GetBinContent(i,j)>minChargeUZ){
05259         char name[256];
05260         sprintf(name,"stpbut_%i_",fStpIndexMapU[fUZcolz->GetBin(i,j)]);
05261         char command[256];
05262         sprintf(command,"fSelPad1->cd(); TButton *but = (TButton*) gPad->FindObject(\"%s\"); if(but->GetFillColor()==11) but->SetFillColor(but->GetLineColor()); else but->SetFillColor(11);",name);
05263         TButton *temp_but = new TButton("",command,
05264                                         0.025 + 0.95*float(i-1)*binwidthx,
05265                                         0.025 + 0.95*float(j-1)*binwidthy,
05266                                         0.025 + 0.95*float(i)*binwidthx,
05267                                         0.025 + 0.95*float(j)*binwidthy);
05268         temp_but->SetName(name);
05269         Float_t col_val = 0;
05270         if(max!=0) col_val = fUZcolz->GetBinContent(i,j)*float(ncol)/max;
05271         temp_but->SetFillColor(gStyle->GetColorPalette(Int_t(col_val)));
05272         temp_but->SetLineColor(gStyle->GetColorPalette(Int_t(col_val)));
05273         fStripButtonU.push_back(temp_but);
05274       }
05275     }
05276   }
05277   if(!fIntRecoLineU){
05278     fIntRecoLineU = new TArrow(0,0,1,1,0.015,"|>");
05279   }
05280   Int_t zVtxBin = fUZcolz->GetXaxis()->FindBin(event->vtx.z);
05281   Int_t tVtxBin = fUZcolz->GetYaxis()->FindBin(event->vtx.u);
05282   fIntRecoLineU->SetX1(0.025+0.95*float(zVtxBin-0.5)*binwidthx+0.95*binwidthx*
05283                        (event->vtx.z - 
05284                         fUZcolz->GetXaxis()->GetBinCenter(zVtxBin)) / 
05285                        fUZcolz->GetXaxis()->GetBinWidth(zVtxBin) );  
05286   fIntRecoLineU->SetY1(0.025+0.95*float(tVtxBin-0.5)*binwidthy+0.95*binwidthy*
05287                        (event->vtx.u - 
05288                         fUZcolz->GetYaxis()->GetBinCenter(tVtxBin)) / 
05289                        fUZcolz->GetYaxis()->GetBinWidth(tVtxBin) );
05290   fIntRecoLineU->SetX2(0.95);
05291   fIntRecoLineU->SetY2(fIntRecoLineU->GetY1());
05292 
05293   nbinsx = fVZcolz->GetNbinsX();
05294   binwidthx = 1./Float_t(nbinsx);
05295   nbinsy = fVZcolz->GetNbinsY();
05296   binwidthy = 1./Float_t(nbinsy);
05297   max = fVZcolz->GetMaximum();
05298 
05299   fSelectPad2->cd();
05300   for(int i=1;i<=nbinsx;i++){
05301     for(int j=1;j<=nbinsy;j++){
05302       if(fVZcolz->GetBinContent(i,j)>minChargeVZ) {
05303         char name[256];
05304         sprintf(name,"stpbut_%i_",fStpIndexMapV[fVZcolz->GetBin(i,j)]);
05305         char command[256];
05306         sprintf(command,"fSelPad2->cd(); TButton *but = (TButton*) gPad->FindObject(\"%s\"); if(but->GetFillColor()==11) but->SetFillColor(but->GetLineColor()); else but->SetFillColor(11);",name);
05307         TButton *temp_but = new TButton("",command,
05308                                         0.025 + 0.95*float(i-1)*binwidthx,
05309                                         0.025 + 0.95*float(j-1)*binwidthy,
05310                                         0.025 + 0.95*float(i)*binwidthx,
05311                                         0.025 + 0.95*float(j)*binwidthy);
05312         temp_but->SetName(name);
05313         Float_t col_val = 0;
05314         if(max!=0) col_val = fVZcolz->GetBinContent(i,j)*float(ncol)/max;
05315         temp_but->SetFillColor(gStyle->GetColorPalette(Int_t(col_val)));
05316         temp_but->SetLineColor(gStyle->GetColorPalette(Int_t(col_val)));
05317         fStripButtonV.push_back(temp_but);
05318       }
05319     }
05320   }
05321 
05322   if(!fIntRecoLineV){
05323     fIntRecoLineV = new TArrow(0,0,1,1,0.015,"|>");
05324   }
05325   zVtxBin = fVZcolz->GetXaxis()->FindBin(event->vtx.z);
05326   tVtxBin = fVZcolz->GetYaxis()->FindBin(event->vtx.v);
05327   fIntRecoLineV->SetX1(0.025+0.95*float(zVtxBin-0.5)*binwidthx+0.95*binwidthx*
05328                        (event->vtx.z - 
05329                         fVZcolz->GetXaxis()->GetBinCenter(zVtxBin)) / 
05330                        fVZcolz->GetXaxis()->GetBinWidth(zVtxBin) );  
05331   fIntRecoLineV->SetY1(0.025+0.95*float(tVtxBin-0.5)*binwidthy+0.95*binwidthy*
05332                        (event->vtx.v - 
05333                         fVZcolz->GetYaxis()->GetBinCenter(tVtxBin)) / 
05334                        fVZcolz->GetYaxis()->GetBinWidth(tVtxBin) );
05335   fIntRecoLineV->SetX2(0.95);
05336   fIntRecoLineV->SetY2(fIntRecoLineV->GetY1());
05337 
05338   fSelectPad1->cd();
05339   for(UInt_t i=0;i<fStripButtonU.size();i++){
05340     fStripButtonU[i]->Draw();
05341   }
05342   fIntRecoLineU->Draw();
05343   gPad->Modified();
05344   fSelectPad2->cd();
05345   for(UInt_t i=0;i<fStripButtonV.size();i++){
05346     fStripButtonV[i]->Draw();
05347   }
05348   fIntRecoLineV->Draw();
05349   gPad->Modified();
05350   fCanvas7->Update();
05351   
05352 }
05353 
05354 void NueDisplayModule::GenerateOverlayMultiGraphs()
05355 {
05356       TGraph* temp;
05357 
05358       if(uzEventOverlay) delete uzEventOverlay;
05359       if(vzEventOverlay) delete vzEventOverlay;
05360       if(uzSliceOverlay) delete uzSliceOverlay;
05361       if(vzSliceOverlay) delete vzSliceOverlay;
05362 
05363       uzEventOverlay = new TMultiGraph();
05364       uzEventOverlay->SetName("uzEventOverlay");
05365       uzEventOverlay->SetTitle("U vs Z Event View");
05366 
05367       vzEventOverlay = new TMultiGraph();
05368       vzEventOverlay->SetName("vzEventOverlay");
05369       vzEventOverlay->SetTitle("V vs Z Event view");
05370 
05371       uzSliceOverlay = new TMultiGraph();
05372       uzSliceOverlay->SetName("uzSliceOverlay");
05373       uzSliceOverlay->SetTitle("U vs Z Slice view");
05374 
05375       vzSliceOverlay = new TMultiGraph();
05376       vzSliceOverlay->SetName("vzSliceOverlay");
05377       vzSliceOverlay->SetTitle("V vs Z Slice view");
05378 
05379       //Drawing of Events
05380       for(int evtNum = 0; evtNum < st->evthdr.nevent; evtNum++)
05381       {
05382         NtpSREvent* Event = SntpHelpers::GetEvent(evtNum,st);
05383 
05384         Int_t TotalStrip = Event->nstrip;
05385         Int_t NumUStrip = 0;
05386         Int_t NumVStrip = 0;
05387 
05388         Float_t* stripUPos = new Float_t[TotalStrip];
05389         Float_t* stripVPos = new Float_t[TotalStrip];
05390         Float_t* stripUPosZ = new Float_t[TotalStrip];
05391         Float_t* stripVPosZ = new Float_t[TotalStrip];
05392 
05393         for(int stpn=0;stpn < Event->nstrip;stpn++){
05394           Int_t index = SntpHelpers::GetStripIndex(stpn,Event);
05395           NtpSRStrip *strip = SntpHelpers::GetStrip(index,st);
05396           if(strip->planeview==PlaneView::kU){
05397             MSG("NueDisplayModule",Msg::kDebug)<<"filling u"<<endl;
05398             stripUPos[NumUStrip] = strip->tpos;
05399             stripUPosZ[NumUStrip] = strip->z;
05400             NumUStrip++;
05401           }
05402           if(strip->planeview==PlaneView::kV){
05403             MSG("NueDisplayModule",Msg::kDebug)<<"filling v"<<endl;
05404             stripVPos[NumVStrip] = strip->tpos;
05405             stripVPosZ[NumVStrip] = strip->z;
05406             NumVStrip++;
05407           }
05408         }
05409 
05410         if(NumUStrip > 0){
05411           temp = new TGraph(NumUStrip,stripUPosZ,stripUPos);
05412           uzEventOverlay->Add(temp);
05413         }
05414         if(NumVStrip > 0){
05415           temp = new TGraph(NumVStrip,stripVPosZ,stripVPos);
05416           vzEventOverlay->Add(temp);
05417         }
05418 
05419         delete [] stripUPos;
05420         delete [] stripVPos;
05421         delete [] stripUPosZ;
05422         delete [] stripVPosZ;
05423      }
05424  
05425      for(int slcNum = 0; slcNum < st->evthdr.nslice; slcNum++)
05426      {
05427         NtpSRSlice* slice = SntpHelpers::GetSlice(slcNum,st);
05428 
05429         Int_t TotalStrip = slice->nstrip;
05430         Int_t NumUStrip = 0;
05431         Int_t NumVStrip = 0;
05432 
05433         Float_t* stripUPos = new Float_t[TotalStrip];
05434         Float_t* stripVPos = new Float_t[TotalStrip];
05435         Float_t* stripUPosZ = new Float_t[TotalStrip];
05436         Float_t* stripVPosZ = new Float_t[TotalStrip];
05437 
05438         for(int stpn=0;stpn < slice->nstrip;stpn++){
05439           Int_t index = SntpHelpers::GetStripIndex(stpn,slice);
05440           NtpSRStrip *strip = SntpHelpers::GetStrip(index,st);
05441           if(strip->planeview==PlaneView::kU){
05442             MSG("NueDisplayModule",Msg::kDebug)<<"filling u"<<endl;
05443             stripUPos[NumUStrip] = strip->tpos;
05444             stripUPosZ[NumUStrip] = strip->z;
05445             NumUStrip++;
05446           }
05447           if(strip->planeview==PlaneView::kV){
05448             MSG("NueDisplayModule",Msg::kDebug)<<"filling v"<<endl;
05449             stripVPos[NumVStrip] = strip->tpos;
05450             stripVPosZ[NumVStrip] = strip->z;
05451             NumVStrip++;
05452           }
05453         }
05454 
05455         if(NumUStrip > 0){
05456           temp = new TGraph(NumUStrip,stripUPosZ,stripUPos);
05457           uzSliceOverlay->Add(temp);
05458         }
05459         if(NumVStrip > 0){
05460           temp = new TGraph(NumVStrip,stripVPosZ,stripVPos);
05461           vzSliceOverlay->Add(temp);
05462         }
05463 
05464         delete [] stripUPos;
05465         delete [] stripVPos;
05466         delete [] stripUPosZ;
05467         delete [] stripVPosZ;
05468      }
05469 
05470   return ;
05471 }
05472 
05473 void NueDisplayModule::UpdateOverlayGraphs(int evt)
05474 {
05475    static int currentSnarl = -10;
05476    if(fSnarl != currentSnarl)
05477    {
05478       GenerateOverlayMultiGraphs();
05479       currentSnarl = fSnarl;
05480 //      cout<<"current"<<currentSnarl<<"  "<<fSnarl<<endl;
05481    }
05482 
05483 //   if(uzEventOverlay == 0) cout<<"this is still NULL"
05484    UpdateEventOverlayColors(evt, uzEventOverlay);
05485    UpdateEventOverlayColors(evt, vzEventOverlay);
05486 
05487    UpdateSliceOverlayColors(evt, uzSliceOverlay);
05488    UpdateSliceOverlayColors(evt, vzSliceOverlay);
05489 
05490    return;
05491 }
05492 
05493 void NueDisplayModule::UpdateEventOverlayColors(int evt, TMultiGraph *mgr)
05494 {
05495    TList* graphs = mgr->GetListOfGraphs();
05496    if(graphs==0) return;
05497 
05498    TGraph *gr;
05499    for(int evtNum = 0; evtNum < st->evthdr.nevent; evtNum++)
05500    {
05501       gr = dynamic_cast<TGraph*>(graphs->At(evtNum));
05502 
05503       if(gr == 0) continue;
05504       gr->SetMarkerSize(0.6);
05505       gr->SetMarkerStyle(8);
05506 
05507       if(evtNum < evt - 1) gr->SetMarkerColor(kMagenta);
05508       if(evtNum == evt - 1) gr->SetMarkerColor(kRed);
05509       if(evtNum == evt){
05510            gr->SetMarkerColor(kBlack);
05511            gr->SetMarkerStyle(3);
05512       }
05513       if(evtNum == evt + 1) gr->SetMarkerColor(kBlue);
05514       if(evtNum > evt + 1) gr->SetMarkerColor(kCyan);
05515       if(kShowRange > 0){
05516         if(TMath::Abs(evtNum - evt) > kShowRange)
05517         {
05518             gr->SetMarkerSize(0);
05519             gr->SetMarkerStyle(1);
05520             gr->SetMarkerColor(kWhite);
05521         }
05522       }
05523   }
05524 
05525   return;
05526 }
05527 
05528 void NueDisplayModule::UpdateSliceOverlayColors(int evt, TMultiGraph *mgr)
05529 {
05530    TList* graphs = mgr->GetListOfGraphs();
05531    if(graphs==0) return;
05532 
05533    TGraph *gr;
05534    NtpSREvent* event = SntpHelpers::GetEvent(evt,st);
05535    int sliceIndex = event->slc;
05536    for(int evtNum = 0; evtNum < st->evthdr.nslice; evtNum++)
05537      {
05538       gr = dynamic_cast<TGraph*>(graphs->At(evtNum));
05539 
05540       if(gr == 0) continue;
05541       gr->SetMarkerSize(0.6);
05542       gr->SetMarkerStyle(8);
05543 
05544       if(evtNum < sliceIndex - 1) gr->SetMarkerColor(kMagenta);
05545       if(evtNum == sliceIndex - 1) gr->SetMarkerColor(kRed);
05546       if(evtNum == sliceIndex){
05547            gr->SetMarkerColor(kBlack);
05548            gr->SetMarkerStyle(3);
05549       }
05550       if(evtNum == sliceIndex + 1) gr->SetMarkerColor(kBlue);
05551       if(evtNum > sliceIndex + 1) gr->SetMarkerColor(kCyan);
05552 
05553       if(kShowRange > 0){
05554         if(TMath::Abs(evtNum - sliceIndex) > kShowRange)
05555         {
05556             gr->SetMarkerSize(0);
05557             gr->SetMarkerStyle(1);
05558             gr->SetMarkerColor(kWhite);
05559         }
05560       }
05561   }
05562 
05563 
05564   return;
05565 }
05566 
05567 void NueDisplayModule::AdjustOverlayRange(int range)
05568 {
05569 
05570   kShowRange = range;
05571 
05572   if(uzEventOverlay == 0) return;
05573 
05574   UpdateEventOverlayColors(fEvent, uzEventOverlay);
05575   UpdateEventOverlayColors(fEvent, vzEventOverlay);
05576 
05577   UpdateSliceOverlayColors(fEvent, uzSliceOverlay);
05578   UpdateSliceOverlayColors(fEvent, vzSliceOverlay);
05579 
05580   uzSliceOverlay->Draw("AP");
05581   vzSliceOverlay->Draw("AP");
05582   uzEventOverlay->Draw("AP");
05583   vzEventOverlay->Draw("AP");
05584 
05585   fCanvas9->cd(1); gPad->Modified();
05586   fCanvas9->cd(2); gPad->Modified();
05587   fCanvas9->cd(3); gPad->Modified();
05588   fCanvas9->cd(4); gPad->Modified();
05589 
05590   fCanvas9->Update();
05591   fCanvas9->Modified();
05592 
05593   return;
05594 }
05595 
05596 
05597 int NueDisplayModule::UpdateMRGraphs(int evt)
05598 {
05599    static int currentSnarlMR = -10;
05600 
05601    static vector<int> MRtoNewEventMap;
05602    static vector<int> MRtoOldEventMap;
05603 
05604    if(fSnarl != currentSnarlMR)
05605    {
05606       CreateMRMap(MRtoNewEventMap, MRtoOldEventMap);
05607       currentSnarlMR = fSnarl;
05608    }
05609 
05610    vector<int> MREvent;
05611    vector<int> OriginalEvent;
05612 
05613    for(unsigned int mrind = 0; mrind < MRtoNewEventMap.size(); mrind++)
05614    {
05615       if(evt == MRtoNewEventMap[mrind]){
05616          MREvent.push_back(mrind);
05617          OriginalEvent.push_back(MRtoOldEventMap[mrind]);
05618 //         cout<<"PushingBack "<<mrind<<"  "<<MRtoOldEventMap[mrind]<<"  "<<evt<<endl;
05619       }
05620    }
05621    
05622    //both lists could be empty if this was really a junk event
05623 
05624    GenerateMRMultiGraphs(evt, MREvent, OriginalEvent);      
05625 
05626    UpdateMRInformation(evt, MREvent, OriginalEvent);
05627                                      
05628    return MREvent.size();
05629 }
05630 
05631 void NueDisplayModule::CreateMRMap(vector<int> &MRnewEvent, vector<int> &MRoldEvent)
05632 {
05633 
05634    MRnewEvent.clear();
05635    MRoldEvent.clear();
05636 
05637    for(int mrevt = 0; mrevt < mr->mrhdr.nmrevt; mrevt++)
05638    {
05639       NtpMREvent* mrevent = SntpHelpers::GetMREvent(mrevt, mr);    
05640       MRoldEvent.push_back(mrevent->orig_event);
05641       MRnewEvent.push_back(mrevent->best_event);
05642 //      cout<<"PushingBack "<<mrevent->orig_event<<"  "
05643 //          <<(mrevent->best_event)<<endl;
05644 
05645    }
05646 }
05647 
05648 
05649 void NueDisplayModule::GenerateMRMultiGraphs(int evtNum, 
05650                         vector<int> &MREvent, vector<int> &OldEvent)
05651 {
05652    //If there is no MRevent then there should be an info which pops
05653    // up to say so.
05654 
05655    ResetMRGraphs();
05656 
05657 //   SetFrame(vzMREventOld);
05658 //   SetFrame(uzMREventOld);
05659 //   SetFrame(vzMREventOverlay);
05660 //   SetFrame(uzMREventOverlay);
05661  
05662    //Draw the New Event
05663 
05664    NtpSREvent* Event = 0;
05665     
05666 //   FillEventGraph(Event, st, uzMREventOverlay, vzMREventOverlay, "New");
05667 
05668    for(unsigned int oEvent = 0; oEvent < OldEvent.size(); oEvent++)
05669    {
05670      Event = SntpHelpers::GetEvent(OldEvent[oEvent],stOld);      
05671      FillEventGraph(Event, stOld, uzMREventOverlay, vzMREventOverlay, "Old");
05672    }
05673 
05674    for(unsigned int mrEvt = 0; mrEvt < MREvent.size(); mrEvt++)
05675    {
05676        NtpMREvent* mrevt = SntpHelpers::GetMREvent(MREvent[mrEvt], mr);
05677 //       cout<<"Contributing from Event: "<<MREvent[mrEvt]<<endl;
05678 
05679        FillMREventGraph(mrevt, st, uzMREventOverlay, vzMREventOverlay, 0);
05680        for(int striptype = 0; striptype < 7; striptype++)
05681         FillMREventGraph(mrevt, st, uzMREventOld, vzMREventOld, striptype);
05682    }
05683 
05684    Event = SntpHelpers::GetEvent(evtNum,st);
05685                                                                                 
05686    FillEventGraph(Event, st, uzMREventOverlay, vzMREventOverlay, "New");
05687 
05688 
05689    UpdateMREventOverlayColors(uzMREventOverlay);
05690    UpdateMREventOverlayColors(vzMREventOverlay);
05691 
05692    UpdateMREventStripColors(uzMREventOld);
05693    UpdateMREventStripColors(vzMREventOld);
05694                                                                                                                    
05695 
05696 /*
05697        //Now overlay it with the original event strips
05698        NtpMREvent* mrevt = SntpHelpers::GetMREvent(evtNum, mr);
05699        cout<<"This was original event "<<mrevt->orig_event<<endl;
05700        Int_t oEvent = mrevt->best_event;
05701   
05702      //          temp->SetMarkerSize(0.6);
05703      //          temp->SetMarkerStyle(8);
05704 */
05705 
05706 }
05707 
05708 
05709 void NueDisplayModule::ResetMRGraphs()
05710 {
05711       if(uzMREventOverlay) delete uzMREventOverlay;
05712       if(vzMREventOverlay) delete vzMREventOverlay;
05713                                                                                 
05714       if(uzMREventOld) delete uzMREventOld;
05715       if(vzMREventOld) delete vzMREventOld;
05716                                                                                 
05717       uzMREventOverlay = new TMultiGraph();
05718       uzMREventOverlay->SetName("uzMREventOverlay");
05719       uzMREventOverlay->SetTitle("U vs Z Event View");
05720                                                                                 
05721       vzMREventOverlay = new TMultiGraph();
05722       vzMREventOverlay->SetName("vzMREventOverlay");
05723       vzMREventOverlay->SetTitle("V vs Z Event view");
05724                                                                                 
05725       uzMREventOld = new TMultiGraph();
05726       uzMREventOld->SetName("uzMREventOld");
05727       uzMREventOld->SetTitle("U vs Z MR Strips View");
05728                                                                                 
05729       vzMREventOld = new TMultiGraph();
05730       vzMREventOld->SetName("vzMREventOld");
05731       vzMREventOld->SetTitle("V vs Z MR Strips view");
05732 }
05733 
05734 
05735 
05736 void  NueDisplayModule::FillEventGraph(NtpSREvent* Event, NtpStRecord *str,
05737           TMultiGraph* uzGraph, TMultiGraph *vzGraph, TString name)
05738 {
05739   Int_t TotalStrip = Event->nstrip;
05740   Int_t NumUStrip = 0;
05741   Int_t NumVStrip = 0;
05742                                                                                
05743   Float_t* stripUPos = new Float_t[TotalStrip];
05744   Float_t* stripVPos = new Float_t[TotalStrip];
05745   Float_t* stripUPosZ = new Float_t[TotalStrip];
05746   Float_t* stripVPosZ = new Float_t[TotalStrip];
05747 
05748 //  cout<<"nstrip - "<<Event->nstrip<<endl;                                                                                
05749   for(int stpn=0;stpn < Event->nstrip;stpn++){
05750       Int_t index = SntpHelpers::GetStripIndex(stpn,Event);
05751       NtpSRStrip *strip = SntpHelpers::GetStrip(index,str);
05752 //      cout<<"For "<<name<<" "<<index<<"  "<<strip->tpos<<"   "<<strip->z<<endl;
05753      
05754       if(strip->planeview==PlaneView::kU){
05755         MSG("NueDisplayModule",Msg::kDebug)<<"filling u"<<endl;
05756         stripUPos[NumUStrip] = strip->tpos;
05757         stripUPosZ[NumUStrip] = strip->z;
05758         NumUStrip++;
05759       }
05760       if(strip->planeview==PlaneView::kV){
05761         MSG("NueDisplayModule",Msg::kDebug)<<"filling v"<<endl;
05762         stripVPos[NumVStrip] = strip->tpos;
05763         stripVPosZ[NumVStrip] = strip->z;
05764         NumVStrip++;
05765       }
05766   }
05767 
05768   TGraph *temp;
05769 
05770   if(NumUStrip > 0){
05771      temp = new TGraph(NumUStrip,stripUPosZ,stripUPos);
05772      if(name != "NULL")
05773         temp->SetName("u"+name);
05774      uzGraph->Add(temp);
05775   }
05776   if(NumVStrip > 0){
05777      temp = new TGraph(NumVStrip,stripVPosZ,stripVPos);
05778      if(name != "NULL")
05779         temp->SetName("v"+name);
05780      vzGraph->Add(temp);
05781   }
05782                                                                                 
05783   delete [] stripUPos;
05784   delete [] stripVPos;
05785   delete [] stripUPosZ;
05786   delete [] stripVPosZ;
05787 }
05788 
05789 
05790 void NueDisplayModule::SetFrame(TMultiGraph* mg)
05791 {
05792       if(mg == 0) return;
05793 
05794       TGraph* temp = 0;
05795                                                                                 
05796       Float_t FarShell[2] = {-4.0, 4.0};
05797       Float_t FarShellZ[2] = {0.0, 30.0};
05798                                                                                 
05799       Float_t NearShell[2] = {-3.0, 3.0};
05800       Float_t NearShellZ[2] = {0.0, 16.0};
05801 
05802       if(fDetectorType == Detector::kNear)
05803           temp = new TGraph(2,NearShellZ,NearShell);
05804 
05805       if(fDetectorType == Detector::kFar)
05806           temp = new TGraph(2,FarShellZ,FarShell);
05807 
05808       temp->SetName("frame");
05809       temp->SetMarkerSize(0);
05810       temp->SetMarkerStyle(1);
05811       mg->Add(temp);
05812 }
05813 
05814 void  NueDisplayModule::FillMREventGraph(NtpMREvent* mrevt, NtpStRecord *str,
05815           TMultiGraph* uzGraph, TMultiGraph *vzGraph, int type)
05816 {
05817   if(!foundMR)
05818   {
05819       MSG("NueDisplayModule",Msg::kError) << "Call to FillMREvent with no MR records"<<endl;
05820       return;
05821   }
05822 
05823   Int_t TotalStrip = mrevt->nstrip;
05824   Int_t NumUStrip = 0;
05825   Int_t NumVStrip = 0;
05826                                                                                 
05827   Float_t* stripUPos = new Float_t[TotalStrip];
05828   Float_t* stripVPos = new Float_t[TotalStrip];
05829   Float_t* stripUPosZ = new Float_t[TotalStrip];
05830   Float_t* stripVPosZ = new Float_t[TotalStrip];
05831 
05832   Bool_t StripType[7];
05833   StripType[0] = true;  // Just that its a strip
05834 
05835   //cout<<mrevt->nstrip<<endl;                                                                                
05836   for(int stpn=0;stpn < mrevt->nstrip;stpn++){
05837       Int_t index = mrevt->stp[stpn];
05838       StripType[1] = mrevt->StpIsTrueMu(stpn);
05839       StripType[2] = mrevt->StpIsTrueShw(stpn);
05840       StripType[3] = mrevt->StpIsScaled(stpn);
05841       StripType[4] = mrevt->StpIsInRecoTrk(stpn);
05842       StripType[5] = mrevt->StpIsRetained(stpn);
05843       StripType[6] = mrevt->StpIsMCElec(stpn);
05844       
05845 //      cout<<type<<"  "<<StripType[type]<<endl;
05846       if(!StripType[type]) continue;
05847 
05848       NtpSRStrip *strip = SntpHelpers::GetStrip(index,str);
05849 //      cout<<"strip->tpos"<<strip->tpos<<"   "<<strip->z<<endl;
05850       if(strip->planeview==PlaneView::kU){
05851         MSG("NueDisplayModule",Msg::kDebug)<<"filling u"<<endl;
05852         stripUPos[NumUStrip] = strip->tpos;
05853         stripUPosZ[NumUStrip] = strip->z;
05854         NumUStrip++;
05855       }
05856       if(strip->planeview==PlaneView::kV){
05857         MSG("NueDisplayModule",Msg::kDebug)<<"filling v"<<endl;
05858         stripVPos[NumVStrip] = strip->tpos;
05859         stripVPosZ[NumVStrip] = strip->z;
05860         NumVStrip++;
05861       }
05862   }
05863      
05864                                                                            
05865   TGraph *temp;
05866                                                                                 
05867   if(NumUStrip > 0){
05868      temp = new TGraph(NumUStrip,stripUPosZ,stripUPos);
05869      if(type == 0) temp->SetName("uAll");
05870      if(type == 1) temp->SetName("uTruMu");
05871      if(type == 2) temp->SetName("uTruShw");
05872      if(type == 3) temp->SetName("uScaled");
05873      if(type == 4) temp->SetName("uReco");
05874      if(type == 5) temp->SetName("uRet");
05875      if(type == 6) temp->SetName("uEM");
05876      uzGraph->Add(temp);
05877   }
05878   if(NumVStrip > 0){
05879      temp = new TGraph(NumVStrip,stripVPosZ,stripVPos);
05880      if(type == 0) temp->SetName("vAll");
05881      if(type == 1) temp->SetName("vTruMu");
05882      if(type == 2) temp->SetName("vTruShw");
05883      if(type == 3) temp->SetName("vScaled");
05884      if(type == 4) temp->SetName("vReco");
05885      if(type == 5) temp->SetName("vRet");
05886      if(type == 6) temp->SetName("vEM");
05887      vzGraph->Add(temp);
05888   }
05889   
05890   delete [] stripUPos;
05891   delete [] stripVPos;
05892   delete [] stripUPosZ;
05893   delete [] stripVPosZ;
05894 }
05895 
05896 
05897 
05898 void NueDisplayModule::UpdateMREventStripColors(TMultiGraph *mgr)
05899 {
05900   if(mgr == 0)
05901   {
05902       MSG("NueDisplayModule",Msg::kError) 
05903          << "Call to UpdateMREventStripColor with Null MultiGraph"<<endl;
05904       return;
05905   }
05906 
05907    TList* graphs = mgr->GetListOfGraphs();
05908    if(graphs == 0) return;
05909 
05910                                                                                 
05911    TGraph *gr;
05912    Int_t grInd = 0;
05913    while ( ( gr = dynamic_cast<TGraph*>(graphs->At(grInd)) ) )
05914    {
05915      if(strstr(gr->GetName(), "frame"))
05916      {
05917         GhostGraph(gr); 
05918         grInd++;
05919         continue;
05920      }
05921 
05922     if(strstr(gr->GetName(), "All")) 
05923        if(showStpAll) ColorGraph(gr, kBlack);
05924        else GhostGraph(gr);
05925 
05926     if(strstr(gr->GetName(), "TruShw"))
05927        if((showStpAll || showStpTrueShw)) ColorGraph(gr, kGreen);
05928        else GhostGraph(gr);
05929 
05930     if(strstr(gr->GetName(), "TruMu"))
05931        if((showStpAll || showStpTrueMu)) ColorGraph(gr, kRed);
05932        else GhostGraph(gr);
05933  
05934     if(strstr(gr->GetName(), "Scaled"))
05935        if((showStpAll || showStpScaled)) ColorGraph(gr, kBlue);
05936        else GhostGraph(gr);
05937 
05938     if(strstr(gr->GetName(), "Reco"))
05939        if((showStpAll || showStpRecoTrk)) ColorGraph(gr, kCyan);
05940        else GhostGraph(gr);
05941 
05942     if(strstr(gr->GetName(), "Ret")) ColorGraph(gr, kMagenta,24,0.9);
05943     if(strstr(gr->GetName(), "EM")) ColorGraph(gr,50,24,0.7);
05944 
05945      grInd++;
05946   }
05947                                                                                 
05948   return;
05949 }
05950 
05951 void NueDisplayModule::GhostGraph(TGraph *gr)
05952 {
05953   if(gr == 0) return;
05954 
05955   gr->SetMarkerSize(0);
05956   gr->SetMarkerStyle(8);
05957   gr->SetMarkerColor(kWhite);
05958 }
05959 
05960 void NueDisplayModule::ColorGraph(TGraph *gr, int color, 
05961                                    int style, Float_t size)
05962 {
05963   if(gr == 0) return;
05964 
05965   gr->SetMarkerSize(size);
05966   gr->SetMarkerStyle(style);
05967   gr->SetMarkerColor(color);
05968 }
05969 
05970 void NueDisplayModule::UpdateMREventOverlayColors(TMultiGraph *mgr)
05971 {
05972   if(mgr == 0)
05973   {
05974       MSG("NueDisplayModule",Msg::kError)
05975          << "Call to UpdateMREventOverlayColor with Null MultiGraph"<<endl;
05976       return;
05977   }
05978 
05979   TList* graphs = mgr->GetListOfGraphs();
05980   if(graphs == 0) return;
05981 
05982   int Count = 0;
05983 
05984   TGraph *gr;
05985   Int_t grInd = 0;
05986   while ( ( gr = dynamic_cast<TGraph*>(graphs->At(grInd)) ) )
05987   {
05988 //     cout<<grInd<<"  "<<gr->GetName()<<endl;
05989      if(strstr(gr->GetName(), "frame"))
05990      {
05991         GhostGraph(gr);
05992         grInd++;
05993         continue;
05994      }
05995 
05996      if(strstr(gr->GetName(), "New"))
05997        if(showNewEvent)  ColorGraph(gr, kGreen, 8, 0.5);
05998        else GhostGraph(gr);
05999 
06000      if(strstr(gr->GetName(), "Old")){
06001        if(!showOrigEvent)  GhostGraph(gr);
06002        else 
06003          if(!showNewEvent && !showMREvent){
06004            if(Count == 0) ColorGraph(gr, kBlue);
06005            if(Count == 1) ColorGraph(gr, kGreen);
06006            if(Count == 2) ColorGraph(gr, kRed);
06007            if(Count > 2){ 
06008               cout<<"This has a lot of matches"<<endl;
06009               ColorGraph(gr, kBlue);
06010            }
06011            Count++;
06012          }else
06013             ColorGraph(gr, kBlue, 8);
06014 
06015      }
06016      if(strstr(gr->GetName(), "All")) 
06017        if(!showMREvent)  GhostGraph(gr);
06018        else
06019          if(!showNewEvent && !showOrigEvent){
06020            if(Count == 0) ColorGraph(gr, kRed);
06021            if(Count == 1) ColorGraph(gr, kGreen);
06022            if(Count == 2) ColorGraph(gr, kBlue);
06023            if(Count > 2){
06024               cout<<"This has a lot of matches"<<endl;
06025               ColorGraph(gr, kRed);
06026            }
06027            Count++;
06028          }else
06029             ColorGraph(gr, kRed, 4, 0.9);
06030 
06031                                                                                 
06032      grInd++;
06033   }
06034                                                                                 
06035   return;
06036 }
06037 
06038 void NueDisplayModule::MRShowMRStrips(int val)
06039 {
06040   if(!foundMR) return;
06041 
06042   if(val == 0) showStpAll = !showStpAll;
06043   if(val == 1) showStpTrueMu = !showStpTrueMu;
06044   if(val == 2) showStpTrueShw = !showStpTrueShw;
06045   if(val == 3) showStpScaled = !showStpScaled;
06046   if(val == 4) showStpRecoTrk = !showStpRecoTrk;
06047 
06048   UpdateMREventStripColors(uzMREventOld);
06049   UpdateMREventStripColors(vzMREventOld);
06050 
06051   DrawLowerMRCanvas();
06052 
06053 }
06054 
06055 void NueDisplayModule::MRShowEvent(int val)
06056 {
06057    if(!foundMR) return;
06058 
06059   if(val == 0) showNewEvent = !showNewEvent;
06060   if(val == 1) showMREvent = !showMREvent;
06061   if(val == 2) showOrigEvent = !showOrigEvent;
06062                                                                                                                      
06063   UpdateMREventOverlayColors(uzMREventOverlay);
06064   UpdateMREventOverlayColors(vzMREventOverlay);
06065                                                                                                                      
06066   DrawUpperMRCanvas();
06067                                                                                                                      
06068 }
06069 
06070 
06071 void NueDisplayModule::DrawLowerMRCanvas()
06072 {
06073   mrGraphPad->cd(3);
06074   if(uzMREventOld && uzMREventOld->GetListOfGraphs()){
06075      uzMREventOld->Draw("AP");  
06076      uzMREventOld->GetXaxis()->SetTitle("z position (m)");
06077      uzMREventOld->GetYaxis()->SetTitle("u Position (m)");
06078   }
06079   gPad->Modified(); mrGraphPad->cd(4);
06080   if(vzMREventOld && vzMREventOld->GetListOfGraphs()){
06081       vzMREventOld->Draw("AP");
06082       vzMREventOld->GetXaxis()->SetTitle("z position (m)");
06083       vzMREventOld->GetYaxis()->SetTitle("v Position (m)");
06084 //      fMRLowerLeg->Draw();
06085     }
06086     gPad->Modified(); 
06087 
06088     mrGraphPad->Modified();
06089     mrGraphPad->Update();
06090 
06091 
06092     mrInfoPanel->cd();
06093     fMRdShowAll->Draw();
06094     fMRdShowTrueMu->Draw();
06095     fMRdShowTrueShw->Draw();
06096     fMRdShowScaled->Draw();
06097     fMRdShowReco->Draw();
06098     
06099     fMRLowerLeg->Draw();
06100 }
06101 
06102 
06103 void NueDisplayModule::DrawUpperMRCanvas()
06104 {
06105 
06106    mrInfoPanel->cd();
06107    fMRuShowAll->Draw();
06108    fMRuShowMR->Draw();
06109    fMRuShowOld->Draw();
06110    fMRUpperLeg->Draw();
06111   
06112    mrGraphPad->cd();                                                                                                                  
06113   mrGraphPad->cd(1);
06114   if(uzMREventOverlay){
06115     uzMREventOverlay->Draw("AP");
06116     uzMREventOverlay->GetXaxis()->SetTitle("z position (m)");
06117     uzMREventOverlay->GetYaxis()->SetTitle("u Position (m)");
06118   }
06119 
06120   gPad->Modified();
06121   mrGraphPad->cd(2);
06122   if(vzMREventOverlay){
06123     vzMREventOverlay->Draw("AP");
06124     vzMREventOverlay->GetXaxis()->SetTitle("z position (m)");
06125     vzMREventOverlay->GetYaxis()->SetTitle("v Position (m)");
06126   }
06127 //  fMRUpperLeg->Draw();
06128 
06129   gPad->Modified();  
06130 
06131 }
06132 
06133 void NueDisplayModule::UpdateMRInformation(int evt,
06134                         vector<int> &MREvent, vector<int> &OldEvent)
06135 {
06136      
06137    char txt[100];
06138    sprintf(txt, "Number of matched events: %u\nFor event %i", 
06139            (UInt_t)MREvent.size(), evt);
06140 
06141    if(MREvent.size() == 0)
06142    {
06143      mrInfo1->Clear();
06144      mrInfo2->Clear();
06145      mrInfo3->Clear();
06146      mrInfo4->Clear();
06147      mrInfo5->Clear(); 
06148      mrInfo6->Clear();
06149      mrInfo7->Clear();
06150      mrInfo8->Clear();  
06151      return;
06152    }
06153 
06154    
06155    mrInfoPanel->cd();
06156 
06157 
06158    mrInfo1->SetText(0.01,0.80, txt);
06159    mrInfo1->SetTextSize(0.07);
06160    mrInfo1->SetTextColor(kBlack);
06161    mrInfo1->Draw();
06162 
06163 
06164    TString Originals = "pre-MR Event: ";
06165    for(unsigned int i = 0; i < OldEvent.size(); i++)
06166    {
06167       char temp[3];  
06168       if(i == 0) sprintf(temp, "%d", OldEvent[i]);
06169       else sprintf(temp, ", %d", OldEvent[i]);
06170  
06171       Originals += temp;
06172    } 
06173 
06174    mrInfo2->SetText(0.01,0.7,Originals); 
06175    mrInfo2->SetTextSize(0.09);
06176    mrInfo2->SetTextColor(kBlack);
06177    mrInfo2->Draw();
06178 
06179 
06180    NtpMREvent* mrevt = SntpHelpers::GetMREvent(MREvent[0], mr);
06181 
06182    sprintf(txt, "Vtx: (%2.2f, %2.2f, %2.2f)", mrevt->vtxx, mrevt->vtxy, mrevt->vtxz);
06183    mrInfo3->SetText(0.01,0.66,txt);
06184    mrInfo3->SetTextSize(0.09);
06185    mrInfo3->SetTextColor(kBlack);
06186    mrInfo3->Draw();
06187 
06188    sprintf(txt, "Pvdx: (%1.2f, %1.2f, %1.2f)", mrevt->pvdx, mrevt->pvdy, mrevt->pvdz);
06189    mrInfo4->SetText(0.01,0.63,txt);
06190    mrInfo4->SetTextSize(0.09);
06191    mrInfo4->SetTextColor(kBlack);
06192    mrInfo4->Draw();
06193 
06194    sprintf(txt, "Pur: %1.2f Comp: %1.2f", mrevt->best_purity, mrevt->best_complete);
06195    mrInfo5->SetText(0.01,0.6,txt);
06196    mrInfo5->SetTextSize(0.09);
06197    mrInfo5->SetTextColor(kBlack);
06198    mrInfo5->Draw();
06199 
06200    sprintf(txt, "PE Pur: %1.2f  Comp: %1.2f", mrevt->best_purity_phw, mrevt->best_complete_phw);
06201    mrInfo6->SetText(0.01,0.56,txt);
06202    mrInfo6->SetTextSize(0.09);
06203    mrInfo6->SetTextColor(kBlack);
06204    mrInfo6->Draw();
06205 
06206 
06207    sprintf(txt, "Pmu  (%1.2f, %1.2f, %1.2f)", mrevt->pmux, mrevt->pmuy, mrevt->pmuz);
06208    mrInfo7->SetText(0.01,0.53,txt);
06209    mrInfo7->SetTextSize(0.09);
06210    mrInfo7->SetTextColor(kBlack);
06211    mrInfo7->Draw();
06212 
06213    sprintf(txt, "TP_{#mu}  (%1.2f, %1.2f, %1.2f)", mrevt->mrmpmux, mrevt->mrmpmuy, mrevt->mrmpmuz);
06214    mrInfo8->SetText(0.01,0.5,txt);
06215    mrInfo8->SetTextSize(0.09);
06216    mrInfo8->SetTextColor(kBlack);
06217    mrInfo8->Draw();
06218 
06219 }

Generated on Mon Feb 15 11:07:11 2010 for loon by  doxygen 1.3.9.1