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

Generated on Sat Mar 14 22:41:07 2009 for loon by doxygen 1.3.5