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

MadScanDisplay.cxx

Go to the documentation of this file.
00001 #ifndef madscandisplay_cxx
00002 #define madscandisplay_cxx
00003 #include <cstring>
00004 #include <iostream>
00005 #include <fstream>
00006 #include <sstream>
00007 //root includes
00008 #include "TClonesArray.h"
00009 #include "TH2.h"
00010 #include "TGraph.h"
00011 #include "TMultiGraph.h"
00012 #include "TStyle.h"
00013 #include "TCanvas.h"
00014 #include "TVector3.h"
00015 #include "TArrow.h"
00016 #include "TPolyLine.h"
00017 #include "TEllipse.h"
00018 #include "TButton.h"
00019 #include "TLatex.h"
00020 #include "TMarker.h"
00021 #include "TPave.h"
00022 #include "TPaveText.h"
00023 #include "TLegend.h"
00024 #include "TSystem.h"
00025 #include "TImage.h"
00026 #include "TFrame.h"
00027 #include "TROOT.h"
00028 #include "MadAbID.h"
00029 //minossoft includes
00030 #include "Validity/VldContext.h"
00031 #include "Conventions/Detector.h"
00032 #include "Conventions/Munits.h"
00033 #include "CandSubShowerSR/ClusterType.h"
00034 #include "Conventions/PlaneView.h"
00035 #include "DataUtil/PlaneOutline.h"
00036 //my includes
00037 #include "Mad/MadScanDisplay.h"
00038 #include "DataUtil/EnergyCorrections.h"
00039 #include "Mad/MadMKAnalysis.h"
00040 #include "DataUtil/infid_sr_interface.h"
00041 #include "Mad/ScanFrame.h"  // JM add
00042 using namespace EnergyCorrections;
00043 using namespace FidVol;
00044 MadScanDisplay::MadScanDisplay(TChain *chainSR,TChain *chainMC,
00045                                TChain *chainTH,TChain *chainEM,
00046                                const char* scan_sheet_name) : 
00047 fHaveNeatoEvents(false), fNeatoEventIdx(-1), fDefaultShowerMarkerColor(5), fDefaultShowerMarkerStyle(4)
00048 {
00049 
00050   fSetFidSet=false;
00051   Dspe_val = 2.0;
00052   Dmid_val = 20.0;
00053   ptt_msg = false;
00054   UseNuInfo = false;
00055   fAltDisplay= false;
00056   LeNu = 14;
00057   LeAction = 1;
00058   LeLego = false;
00059   LeClus = false;
00060   LeEvent = 0;
00061   LeSlice = 0;
00062   LeMCevent = 0;
00063   LeEntry = 0;
00064   LeAutoMat = true;
00065   drawSAME = false;
00066 
00067   handScan = false;
00068   ScanID = 0;
00069   ScanTop = 0;
00070   sprintf(logFileName,"handScan.dat");
00071 
00072   sprintf(printOpt,"gif");
00073   //  sprintf(printOpt,"png");
00074   //  sprintf(printOpt,"eps");
00075 
00076   if(!chainSR) {
00077     record = 0;
00078     emrecord = 0;
00079     mcrecord = 0;
00080     threcord = 0;
00081     Clear();
00082     whichSource = -1;
00083     isMC = true;
00084     isTH = true;
00085     isEM = true;
00086     Nentries = -1;
00087     return;
00088   }
00089  
00090  
00091   InitChain(chainSR,chainMC,chainTH,chainEM, true);
00092   whichSource = 0;
00093   SFrame = ScanFrame::CreateScanSheet(gClient->GetRoot(),scan_sheet_name); // JM add
00094 
00095 }
00096 
00097 MadScanDisplay::MadScanDisplay(JobC *j,string path,
00098                                int entries,
00099                                const char* scan_sheet_name) : 
00100 fHaveNeatoEvents(false), fNeatoEventIdx(-1), fDefaultShowerMarkerColor(5), fDefaultShowerMarkerStyle(4)
00101 {
00102   fSetFidSet=false;
00103   Dspe_val = 2.0;
00104   Dmid_val = 20.0;
00105   ptt_msg = false;
00106   UseNuInfo = false;
00107 
00108   LeNu = 14;
00109   LeAction = 1;
00110   LeLego = false;
00111   LeClus = false;
00112   LeEvent = 0;
00113   LeSlice = 0;
00114   LeMCevent = 0;
00115   LeEntry = 0;
00116   LeAutoMat = true;
00117   drawSAME = false;
00118 
00119   handScan = false;
00120   ScanID = 0;
00121   ScanTop = 0;
00122   sprintf(logFileName,"handScan.dat");
00123 
00124   sprintf(printOpt,"gif");
00125   //  sprintf(printOpt,"png");
00126   //  sprintf(printOpt,"eps");
00127 
00128   record = 0;
00129   emrecord = 0;
00130   mcrecord = 0;
00131   threcord = 0;
00132   Clear();
00133   isMC = true;
00134   isTH = true;
00135   isEM = true;
00136   Nentries = entries;
00137   jcPath = path;
00138   whichSource = 1;
00139   fCurRun = -1;
00140   fJC = j;
00141   fChain = NULL;
00142   SFrame = ScanFrame::CreateScanSheet(gClient->GetRoot(),scan_sheet_name); // JM add
00143 
00144 }
00145 
00146 MadScanDisplay::~MadScanDisplay()
00147 {
00148 }
00149 
00150 void MadScanDisplay::SetDVals(Float_t spe_val,Float_t mid_val)
00151 {
00152   Dspe_val = spe_val;
00153   Dmid_val = mid_val; 
00154 }
00155 
00156 void MadScanDisplay::PrintDisplay()
00157 {
00158   //Print canvases
00159   TCanvas *can[6];
00160   can[0] = (TCanvas*) gROOT->FindObject("RecoCanvas");
00161   can[1] = (TCanvas*) gROOT->FindObject("MainCanvas");
00162   can[2] = (TCanvas*) gROOT->FindObject("TruthCanvas");
00163   can[3] = (TCanvas*) gROOT->FindObject("LegoCanvas");
00164   can[4] = (TCanvas*) gROOT->FindObject("ClusterCanvas");
00165   can[5] = (TCanvas*) gROOT->FindObject("StdHepDiagramCanvas");
00166   
00167   for(int i=0;i<5;i++){
00168     if(can[i]) {
00169       TString temp(can[i]->GetName());
00170       if(isMC) {
00171         temp.Append("_MC");
00172       }
00173       temp.Append(printName);
00174       can[i]->Print(temp.Data());
00175 
00176       /*
00177       // try to use TImage (TASImage actually...) to print canvases
00178       // in the hope of solving the "canvas with bit of other window" output
00179       // this didn't work... got 
00180       // <RootX11ErrorHandler>: BadMatch and canvas was covered
00181       // or
00182       // ASImage2gif():944:<MainCanvas_MC_Run10001_Snl35_Slc1_Evt1.gif>
00183       // GIF-LIB undefined error 0.
00184       // Error in <TASImage::WriteImage>: error writing file MainCanvas_MC_Run10001_Snl35_Slc1_Evt1.gif
00185 
00186       TImage* img = TImage::Create();
00187       img->FromPad(can[i]);
00188       img->WriteImage(temp.Data());
00189       delete img;
00190       */
00191     }
00192   }  
00193 }
00194 
00195 void MadScanDisplay::SetPrintOpt(char *opt){
00196   sprintf(printOpt,"%s",opt);
00197   //  this->Display(LeEntry,LeSlice,LeEvent,LeMCevent,LeAutoMat);
00198 }
00199 
00200 Bool_t MadScanDisplay::PassCuts(){
00201   if(!ntpEvent) return false;
00202  
00203   //ND fid cuts
00204   if(false){
00205     if(ntpHeader->GetVldContext().GetDetector()==Detector::kNear){
00206       if((ntpEvent->vtx.z<1 || ntpEvent->vtx.z>5 ||
00207           sqrt(((ntpEvent->vtx.x-1.4885)*(ntpEvent->vtx.x-1.4885)) +
00208                ((ntpEvent->vtx.y-0.1397)*(ntpEvent->vtx.y-0.1397)))>1)) {
00209         return false;
00210       }
00211       Int_t track = -1;
00212       if(LoadLargestTrackFromEvent(ntpEvent->index,track)){
00213         if((ntpTrack->vtx.z<1 || ntpTrack->vtx.z>5 ||
00214             sqrt(((ntpTrack->vtx.x-1.4885)*(ntpTrack->vtx.x-1.4885)) +
00215                  ((ntpTrack->vtx.y-0.1397)*(ntpTrack->vtx.y-0.1397)))>1)) {
00216           return false;
00217         }
00218       }
00219     }
00220   }
00221 
00222   if(false){
00223     if(LoadTHEvent(ntpEvent->index)) {
00224       if(ntpTHEvent->completeslc<0.1) {
00225         cout << "low event completeness " << ntpTHEvent->completeslc << endl;
00226         return true;    
00227       }
00228       if(ntpEvent->nshower>0) {
00229         Int_t shw_ind = -1;
00230         if( ( ntpEvent->ntrack>0 && ntpTrack &&
00231               LoadShowerAtTrackVertex(ntpEvent->index,
00232                                       ntpTrack->index,shw_ind) ) ||
00233             (ntpEvent->ntrack==0 && 
00234              LoadLargestShowerFromEvent(ntpEvent->index,shw_ind) ) ){
00235           if(LoadTHShower(shw_ind)) {
00236             if(ntpTHShower->completeslc < 0.2) {
00237               cout << "low vertex shower completeness " 
00238                    << ntpTHShower->completeslc << endl;
00239               return true;    
00240             }
00241           }
00242         }
00243       }
00244     }
00245   }
00246 
00247   if(false){
00248     if(eventSummary->nshower==1 && eventSummary->ntrack==1 &&
00249        eventSummary->nevent==1 && ntpEvent->nshower==1 && 
00250        ntpEvent->ntrack==0) return true;
00251   }
00252 
00253   //>=2 showers
00254   if(false){
00255     if(ntpEvent->nshower>1 && 
00256        ntpEvent->ntrack==0) return true;
00257   }
00258 
00259   //Two or more events/slice
00260   if(false){
00261     Int_t slice = ntpEvent->slc;
00262     Int_t ev_index = ntpEvent->index;
00263     if(LoadEvent(ev_index+1)) {      
00264       if(ntpEvent->slc==slice) {
00265         //get total charge of shower in PEs for U and V:
00266         Double_t shwChargeU = 0;
00267         Double_t shwChargeV = 0;
00268         Double_t shwChargeAsym = 0;
00269         Int_t shower = -1;
00270         if(LoadLargestShowerFromEvent(ntpEvent->index,shower)){
00271           for(int i = 0; i<ntpShower->ncluster;i++){
00272             LoadCluster(ntpShower->clu[i]);
00273             if(ntpCluster->planeview==2) shwChargeU += ntpCluster->ph.pe;
00274             else shwChargeV += ntpCluster->ph.pe;
00275           }
00276           shwChargeAsym = ( TMath::Abs(shwChargeU - shwChargeV) / 
00277                             (shwChargeU+shwChargeV) );
00278           cout << "2nd: " << shwChargeU << " " << shwChargeV << " " 
00279                << shwChargeAsym << endl;
00280         }
00281         LoadEvent(ev_index);    
00282         // first event:
00283         shwChargeU = 0;
00284         shwChargeV = 0;
00285         if(LoadLargestShowerFromEvent(ntpEvent->index,shower)){
00286           for(int i = 0; i<ntpShower->ncluster;i++){
00287             LoadCluster(ntpShower->clu[i]);
00288             if(ntpCluster->planeview==2) shwChargeU += ntpCluster->ph.pe;
00289             else shwChargeV += ntpCluster->ph.pe;
00290           }
00291           shwChargeAsym = ( TMath::Abs(shwChargeU - shwChargeV) / 
00292                             (shwChargeU+shwChargeV) );
00293           
00294           cout << "1st: " << shwChargeU << " " << shwChargeV << " " 
00295                << shwChargeAsym << endl;
00296         }
00297         cout << ">1 event in slice" << endl;
00298         return true;
00299       }
00300     }
00301     LoadEvent(ev_index);
00302   }
00303 
00304   //SubShower Cuts:
00305   if(false){
00306     Int_t shower = -1;
00307     if(eventSummary->nevent==1&&ntpEvent->nshower==1&&
00308        LoadLargestShowerFromEvent(ntpEvent->index,shower)) {
00309       int goodU = 0;
00310       int goodV = 0;
00311       double maxU = 0;
00312       double maxV = 0;
00313       double avgdevU = 1.;
00314       double avgdevV = 1.;
00315       Int_t nemclu = 0;
00316       Int_t nhadclu = 0;
00317       Int_t nphysclu = 0;
00318       
00319       Int_t *clusters = ntpShower->clu;
00320       for(int k=0; k<ntpShower->ncluster; k++){
00321         Int_t index = clusters[k];
00322         if(!LoadCluster(index)) continue;
00323         if(ntpCluster->ph.gev>0.4){
00324           if(ntpCluster->id==0) nemclu++;
00325           else if(ntpCluster->id==1) nhadclu++;
00326           else if(ntpCluster->id!=2) nphysclu++;
00327         }
00328         if(ntpCluster->planeview==2){
00329           if(ntpCluster->ph.gev>maxU){
00330             if(ntpCluster->id==0){
00331               goodU = 1;
00332               if(ntpCluster->probem>0.2) goodU=3;
00333               avgdevU = ntpCluster->avgdev;
00334               maxU = ntpCluster->ph.gev;
00335             }
00336             else {
00337               goodU = 0;
00338               avgdevU = ntpCluster->avgdev;
00339             maxU = ntpCluster->ph.gev;
00340             }
00341           }
00342         }
00343         else if(ntpCluster->planeview==3){
00344           if(ntpCluster->ph.gev>maxV){
00345             if(ntpCluster->id==0){
00346               goodV = 1;
00347               if(ntpCluster->probem>0.2) goodV=3;
00348               avgdevV = ntpCluster->avgdev;
00349               maxV = ntpCluster->ph.gev;
00350             }
00351             else {
00352               goodV = 0;
00353               avgdevV = ntpCluster->avgdev;
00354               maxV = ntpCluster->ph.gev;
00355             }
00356           }
00357         }
00358       }
00359       if((goodU==1 && goodV==1) || goodU==3 || goodV==3){
00360         cout << ntpTruth->iaction << " " 
00361              << nemclu << " " << nhadclu << " " 
00362              << nemclu+nhadclu+nphysclu << endl;
00363         return true;
00364       }
00365     }
00366   }
00367   return false;
00368 }
00369 
00370 //------------------------------------------------------------
00371 
00372 Int_t MadScanDisplay::NextEvt() 
00373 {
00374   if (fHaveNeatoEvents) { return NextInterestingEvent(); }
00375 
00376   SFrame->EntryProc();
00377   int entry = LeEntry;
00378   int event = LeEvent+1;
00379  
00380   while(this->GetEntry(entry)){
00381     while(LoadEvent(event++)) {
00382       LeSlice = 0;
00383       LeEvent = event;
00384       LeMCevent = 0;
00385       Display(entry,0,event,0,LeAutoMat);
00386       return entry;
00387     }
00388     event = 0;
00389     entry+=1;
00390     if(entry>=Nentries) break;
00391   }
00392   entry = 0;
00393   Display(0,0,0,0,LeAutoMat);
00394   
00395   return entry;
00396 }
00397 
00398 //------------------------------------------------------------
00399 
00400 Int_t MadScanDisplay::PrevEvt() 
00401 {
00402   if (fHaveNeatoEvents) { return NextInterestingEvent(true); }
00403 
00404   SFrame->EntryProc();
00405   int entry = LeEntry;
00406   int event = LeEvent-1;
00407  
00408   while(this->GetEntry(entry)){
00409     while(LoadEvent(event--)) {
00410       LeSlice = 0;
00411       LeEvent = event;
00412       LeMCevent = 0;
00413       Display(entry,0,event,0,LeAutoMat);
00414       return entry;
00415     }
00416     event = 0;
00417     entry-=1;
00418     if(entry<0) break;
00419   }
00420   entry = 0;
00421   Display(0,0,0,0,LeAutoMat);
00422   
00423   return entry;
00424 }
00425 
00426 //------------------------------------------------------------
00427 
00428 Int_t MadScanDisplay::NextPass() {
00429   // override to read from list of events
00430  
00431   if(fHaveNeatoEvents) { return NextInterestingEvent(); }
00432 
00433   int entry = LeEntry;
00434   int event = LeEvent+1;
00435 
00436   if(isMC&&isTH){
00437     int mcevent = 0;
00438     while(this->GetEntry(entry)){
00439       while(LoadEvent(event)) { 
00440         if(LoadTruthForRecoTH(event,mcevent)){
00441           if(PassCuts()&&(!UseNuInfo||(abs(ntpTruth->inu)==LeNu
00442                                        &&ntpTruth->iaction==LeAction))){
00443             int slice = 0;
00444             LoadSliceForRecoTH(event,slice);
00445             LeSlice = slice;        
00446             LeEvent = event;
00447             LeMCevent = mcevent;
00448             Display(entry,slice,event,mcevent,LeAutoMat);
00449             return entry;
00450           }
00451         }
00452         event+=1;
00453       }
00454       event = 0;
00455       entry+=1;
00456       if(entry>=Nentries) break;
00457     }
00458     entry = 0;
00459     Display(0,0,0,0,LeAutoMat);
00460     return entry;
00461   }
00462 
00463   //if no MC or TH:
00464   while(this->GetEntry(entry)){
00465     while(LoadEvent(event)) {
00466       if(PassCuts()){
00467         LeSlice = 0;
00468         LeEvent = event;
00469         LeMCevent = 0;
00470         Display(entry,0,event,0,LeAutoMat);
00471         return entry;
00472       }     
00473       event+=1;
00474     }
00475     event = 0;
00476     entry+=1;
00477     if(entry>=Nentries) break;
00478   }
00479   entry = 0;
00480   Display(0,0,0,0,LeAutoMat);
00481   return entry;
00482   
00483 }
00484 
00485 Bool_t MadScanDisplay::InFidTrk(int event){
00486 
00487   int ind;
00488  int slice = ntpEvent->slc;
00489  if(!LoadSlice(slice))return false;
00490  bool slice2=false;
00491  for(int i=0;i<eventSummary->nevent;i++){
00492    if(i!=event){
00493      LoadEvent(i);
00494      if(ntpEvent->slc==slice) slice2=true;
00495    }
00496  }
00497  LoadEvent(event);
00498   LoadLargestTrackFromEvent(event,ind);
00499   if(!ntpTrack)return false;
00500   
00501   choose_infid_set("cc2008Exp");
00502   Bool_t fid = infid(*strecord,*ntpTrack);
00503   if(fid && slice2) SFrame->Pass("Slice2Evt");
00504   return fid;
00505 }
00506 
00507 Bool_t MadScanDisplay::InFidNoTrk(int event){
00508 
00509   int shower_index;
00510   int ind;
00511   bool slice2=false;
00512   int slice = ntpEvent->slc;
00513   if(!LoadSlice(slice))return false;
00514   for(int i=0;i<eventSummary->nevent;i++){
00515     if(i!=event){
00516       LoadEvent(i);
00517       if(ntpEvent->slc==slice) slice2=true;;
00518     }
00519   }
00520   LoadLargestTrackFromEvent(event ,ind);
00521   if(ntpTrack)return false;
00522   LoadShower_Jim(event,shower_index,ntpHeader->GetVldContext().GetDetector());
00523   if(!ntpShower)return false;
00524 
00525   choose_infid_set("cc2008Exp");
00526   Bool_t fid = infid(*strecord,*ntpShower);
00527   
00528   if(fid && slice2) SFrame->Pass("Slice2Evt");
00529   
00530   return fid;
00531 }
00532 
00533 Int_t MadScanDisplay::NextFidTrk() {
00534   // override to read from list of events
00535   SFrame->EntryProc();
00536   int entry = LeEntry;
00537   int event = LeEvent+1;
00538  
00539   while(this->GetEntry(entry)){
00540     while(LoadEvent(event)) {
00541       if(InFidTrk(event)){
00542         LeSlice = 0;
00543         LeEvent = event;
00544         LeMCevent = 0;
00545         Display(entry,0,event,0,LeAutoMat);
00546         return entry;
00547       }     
00548       event+=1;
00549     }
00550     event = 0;
00551     entry+=1;
00552     if(entry>=Nentries) break;
00553   }
00554   entry = 0;
00555   Display(0,0,0,0,LeAutoMat);
00556   return entry;  
00557 }
00558 
00559 Int_t MadScanDisplay::NextFidNoTrk() {
00560   // override to read from list of events
00561   SFrame->EntryProc();
00562   int entry = LeEntry;
00563   int event = LeEvent+1;
00564 
00565  
00566   while(this->GetEntry(entry)){
00567     while(LoadEvent(event)) {
00568       if(InFidNoTrk(event)){
00569         LeSlice = 0;
00570         LeEvent = event;
00571         LeMCevent = 0;
00572         Display(entry,0,event,0,LeAutoMat);
00573         return entry;
00574       }     
00575       event+=1;
00576     }
00577     event = 0;
00578     entry+=1;
00579     if(entry>=Nentries) break;
00580   }
00581   entry = 0;
00582   Display(0,0,0,0,LeAutoMat);
00583   return entry;  
00584 }
00585 
00586 Int_t MadScanDisplay::PrevPass() {
00587   // override to read from list of events
00588  
00589   if(fHaveNeatoEvents) { return NextInterestingEvent(true); }
00590 
00591   int entry = LeEntry;
00592   int event = LeEvent-1;
00593   
00594   if(isMC&&isTH){
00595     int mcevent = 0;
00596     while(this->GetEntry(entry)){
00597       if(event==-100){ 
00598         TClonesArray* pointEventArray = NULL;
00599         if(isST) pointEventArray = (strecord->evt);
00600         else pointEventArray = (record->evt);
00601         TClonesArray& eventArray = *pointEventArray;
00602         event = eventArray.GetEntries() - 1;
00603       }
00604       while(LoadEvent(event)) {
00605         if(LoadTruthForRecoTH(event,mcevent)){
00606           if(PassCuts()&&(!UseNuInfo||(abs(ntpTruth->inu)==LeNu
00607                                        &&ntpTruth->iaction==LeAction))){
00608             int slice = 0;
00609             LoadSliceForRecoTH(event,slice);
00610             LeSlice = slice;        
00611             LeEvent = event;
00612             LeMCevent = mcevent;
00613             Display(entry,slice,event,mcevent,LeAutoMat);
00614             SFrame->EntryProc();
00615             return entry;
00616           }
00617         }
00618         event-=1;
00619       }
00620       event = -100; //to catch when we've got to last event in snarl
00621       entry -= 1;      
00622       if(entry<0) break;
00623     }
00624     entry = 0;
00625     Display(0,0,0,0,LeAutoMat);
00626     SFrame->EntryProc();
00627     return entry;
00628   }
00629 
00630   //if no MC or TH:
00631   while(this->GetEntry(entry)){
00632     if(event==-100){
00633       TClonesArray* pointEventArray = NULL;
00634       if(isST) pointEventArray = (strecord->evt);
00635       else pointEventArray = (record->evt);
00636       TClonesArray& eventArray = *pointEventArray;
00637       event = eventArray.GetEntries() - 1;
00638     }
00639     while(LoadEvent(event)) {
00640       if(PassCuts()){
00641         LeSlice = 0;
00642         LeEvent = event;
00643         LeMCevent = 0;
00644         Display(entry,0,event,0,LeAutoMat);
00645         SFrame->EntryProc();
00646         return entry;
00647       }
00648       event-=1;
00649     }
00650     event = -100;
00651     entry-=1;
00652     if(entry<0) break;
00653   }
00654   entry = 0;
00655   Display(0,0,0,0,LeAutoMat);
00656   SFrame->EntryProc();
00657   return entry;
00658 
00659 }
00660 Int_t MadScanDisplay::PrevFidTrk() {
00661   // override to read from list of events
00662  
00663   int entry = LeEntry;
00664   int event = LeEvent-1;
00665   
00666 
00667 
00668   while(this->GetEntry(entry)){
00669     if(event==-100){
00670       TClonesArray* pointEventArray = NULL;
00671       if(isST) pointEventArray = (strecord->evt);
00672       else pointEventArray = (record->evt);
00673       TClonesArray& eventArray = *pointEventArray;
00674       event = eventArray.GetEntries() - 1;
00675     }
00676     while(LoadEvent(event)) {
00677       if(InFidTrk(event)){
00678         LeSlice = 0;
00679         LeEvent = event;
00680         LeMCevent = 0;
00681         Display(entry,0,event,0,LeAutoMat);
00682         return entry;
00683       }
00684       event-=1;
00685     }
00686     event = -100;
00687     entry-=1;
00688     if(entry<0) break;
00689   }
00690   entry = 0;
00691   Display(0,0,0,0,LeAutoMat);
00692   return entry;
00693 
00694 }
00695 Int_t MadScanDisplay::PrevFidNoTrk() {
00696   // override to read from list of events
00697 
00698   int entry = LeEntry;
00699   int event = LeEvent-1;
00700   
00701   while(this->GetEntry(entry)){
00702     if(event==-100){
00703       TClonesArray* pointEventArray = NULL;
00704       if(isST) pointEventArray = (strecord->evt);
00705       else pointEventArray = (record->evt);
00706       TClonesArray& eventArray = *pointEventArray;
00707       event = eventArray.GetEntries() - 1;
00708     }
00709     while(LoadEvent(event)) {
00710       if(InFidNoTrk(event)){
00711         LeSlice = 0;
00712         LeEvent = event;
00713         LeMCevent = 0;
00714         Display(entry,0,event,0,LeAutoMat);
00715         return entry;
00716       }
00717       event-=1;
00718     }
00719     event = -100;
00720     entry-=1;
00721     if(entry<0) break;
00722   }
00723   entry = 0;
00724   Display(0,0,0,0,LeAutoMat);
00725   return entry;
00726 
00727 }
00728 
00729 Int_t MadScanDisplay::SkipTo()
00730 {
00731  
00732   Int_t sp = 0;
00733   std::cout << "Enter tree entry number to jump to" << std::endl;
00734   std::cin >> sp;
00735   if(sp<0||sp>Nentries) sp=0;
00736   std::cout << sp << std::endl;
00737   Display(sp,0,0,0,LeAutoMat);
00738   return sp;
00739 
00740 }
00741 
00742 Int_t MadScanDisplay::JumpTo()
00743 {
00744  
00745   if(whichSource==0){
00746     Int_t run = 0;
00747     Int_t snarl = 0;
00748     std::cout << "Enter run number of the snarl:" << std::endl;
00749     std::cin >> run;
00750     std::cout << "Enter snarl number:" << std::endl;
00751     std::cin >> snarl;
00752     Int_t entry = fChain->GetEntryNumber(run,snarl);
00753     cout << entry << endl;
00754     if(entry>=0 && entry<Nentries) {
00755       std::cout << "Displaying Run: " << run << " Snarl: " 
00756                 << snarl << std::endl;
00757       Display(entry,0,0,0,LeAutoMat);
00758       return entry;
00759     }
00760     std::cout << "Couldn't find Run: " << run << " Snarl: " 
00761               << snarl << std::endl;
00762   }
00763   return lastEntry;
00764 }
00765 
00766 void MadScanDisplay::FindUnSliced(){
00767   SFrame->SetEvent(-1);
00768   SFrame->SetSlice(-1);
00769   SFrame->EntryProc();
00770 }
00771 
00772 
00773 
00774 Bool_t MadScanDisplay::Display(Int_t entry,Int_t theSlice,Int_t theEvent,
00775                              Int_t theMCevent,Bool_t automat)
00776 {
00777 
00778   gStyle->SetTextFont(132);
00779   if(this->GetEntry(entry)==0) return false;
00780   
00781   Bool_t isReco = true;  //checks for reconstructed event
00782   Bool_t NoSlice = false;
00783 
00784   //no point using LoadStrip since it will called many times, just get arrays
00785   TClonesArray* pointShieldStripArray = NULL;
00786   if(isST) pointShieldStripArray = (strecord->vetostp);
00787   else pointShieldStripArray = (record->vetostp);
00788   TClonesArray& shieldstripArray = *pointShieldStripArray;
00789   TClonesArray* pointStripArray = NULL;
00790   if(isST) pointStripArray = (strecord->stp);
00791   else pointStripArray = (record->stp);
00792   TClonesArray& stripArray = *pointStripArray;
00793 
00794   // find all strips not in a slice
00795 
00796   int nmissU=0;
00797   int nmissV=0;
00798 
00799   int nmissUOneEnd=0;
00800   int nmissVOneEnd=0;
00801 
00802   int nmissULowPE=0;
00803   int nmissVLowPE=0;
00804 
00805   float *missstripz_0 = new float[eventSummary->nstrip];
00806   float *missstripz_1 = new float[eventSummary->nstrip];
00807   float *missstript_0 = new float[eventSummary->nstrip];
00808   float *missstript_1 = new float[eventSummary->nstrip];
00809 
00810   float *missstripzOneEnd_0 = new float[eventSummary->nstrip];
00811   float *missstripzOneEnd_1 = new float[eventSummary->nstrip];
00812   float *missstriptOneEnd_0 = new float[eventSummary->nstrip];
00813   float *missstriptOneEnd_1 = new float[eventSummary->nstrip];
00814 
00815   float *missstripzLowPE_0 = new float[eventSummary->nstrip];
00816   float *missstripzLowPE_1 = new float[eventSummary->nstrip];
00817   float *missstriptLowPE_0 = new float[eventSummary->nstrip];
00818   float *missstriptLowPE_1 = new float[eventSummary->nstrip];
00819 
00820   float lowest_missz=100;
00821   float highest_missz=0;
00822   float lowest_misst0=100;
00823   float highest_misst0=-100;
00824   
00825 
00826   for(unsigned int i=0;i<eventSummary->nstrip;i++){
00827     bool found=false;
00828     for(int j=0;j<eventSummary->nslice;j++){
00829       LoadSlice(j);
00830       for(int k=0;k<ntpSlice->nstrip;k++){
00831         unsigned int index = ntpSlice->stp[k];
00832         if(index==i){found=true; continue;}
00833       }
00834       if(found)continue;
00835     }
00836         
00837     if(!found){
00838       LoadStrip(i);
00839       if(ntpHeader->GetVldContext().GetDetector()==Detector::kFar || 
00840          ntpStrip->plane<121){
00841         if(ntpStrip->z<lowest_missz)lowest_missz=ntpStrip->z-0.2;
00842         if(ntpStrip->z>highest_missz)highest_missz=ntpStrip->z+0.2;
00843         if(ntpStrip->tpos<lowest_misst0)lowest_misst0=ntpStrip->tpos-0.2;
00844         if(ntpStrip->tpos>highest_misst0)highest_misst0=ntpStrip->tpos+0.2;
00845 
00846         if(ntpStrip->ph0.pe>0 && ntpStrip->ph1.pe>0 && ntpStrip->ph0.pe+ntpStrip->ph1.pe>2){    
00847           if(ntpStrip->planeview==PlaneView::kU){
00848             
00849             missstript_0[nmissU]=ntpStrip->tpos;
00850             missstripz_0[nmissU]=ntpStrip->z;
00851             nmissU++;
00852           }
00853           else{
00854             missstript_1[nmissV]=ntpStrip->tpos;
00855             missstripz_1[nmissV]=ntpStrip->z;
00856             nmissV++;
00857           }
00858         }
00859         else if(ntpStrip->ph0.pe==0 || ntpStrip->ph1.pe==0){    
00860           if(ntpStrip->planeview==PlaneView::kU){
00861             missstriptOneEnd_0[nmissUOneEnd]=ntpStrip->tpos;
00862             missstripzOneEnd_0[nmissUOneEnd]=ntpStrip->z;
00863             nmissUOneEnd++;
00864           }
00865           else{
00866             missstriptOneEnd_1[nmissVOneEnd]=ntpStrip->tpos;
00867             missstripzOneEnd_1[nmissVOneEnd]=ntpStrip->z;
00868             nmissVOneEnd++;
00869           }
00870         }
00871         else if((ntpStrip->ph0.pe>0 && ntpStrip->ph1.pe>0) && ntpStrip->ph0.pe+ntpStrip->ph1.pe<2){     
00872           if(ntpStrip->planeview==PlaneView::kU){
00873             missstriptLowPE_0[nmissULowPE]=ntpStrip->tpos;
00874             missstripzLowPE_0[nmissULowPE]=ntpStrip->z;
00875             nmissULowPE++;
00876           }
00877           else{
00878             missstriptLowPE_1[nmissVLowPE]=ntpStrip->tpos;
00879             missstripzLowPE_1[nmissVLowPE]=ntpStrip->z;
00880             nmissVLowPE++;
00881           }
00882         }
00883       }
00884     }
00885   }
00886  
00887   //Load the event:  
00888   if(!LoadEvent(theEvent)) { //if can't load event asked for
00889     LeEvent = theEvent = 0; //try loading event 0
00890     if(!LoadEvent(theEvent)) isReco=false; //if not present then don't 
00891                                            //try to draw reco graphs
00892   }
00893   else LeEvent = theEvent;
00894 
00895   //if we have MC and TH, load slices and truth events based on reco'd event
00896   if(isMC) {
00897     if(isTH&&automat) {
00898       if(!LoadSliceForRecoTH(theEvent,theSlice)){ //load slice from reco evt
00899         LeSlice = theSlice = 0; //if not present load slice 0
00900         if(!LoadSlice(theSlice)) {
00901           std::cerr << "No slice present in Run: " << ntpHeader->GetRun() 
00902                     << " Snarl: " << ntpHeader->GetSnarl() << std::endl; 
00903           NoSlice=true; //if not there exit with a message after delete stuff
00904         }
00905       }
00906       else LeSlice = theSlice;
00907       if(!LoadTruthForRecoTH(theEvent,theMCevent)){ //load truth from reco
00908         LeMCevent = theMCevent = 0; //if not present load truth 0
00909         LoadTruth(theMCevent);
00910       }
00911       else LeMCevent = theMCevent;
00912     }
00913     else if(automat){ //if there's no TH but we are in automatic mode
00914       if(!LoadTruthForReco(theEvent,theMCevent)){ //load truth using reco vtx
00915         LeMCevent = theMCevent = 0; //if not present load truth 0
00916         LoadTruth(theMCevent);
00917         //load slice from event->slc:
00918         theSlice = ntpEvent->slc;
00919         if(!LoadSlice(theSlice)) {
00920           LeSlice = theSlice = 0;         
00921           if(!LoadSlice(theSlice)) {
00922            std::cerr << "No slice present in Run: " << ntpHeader->GetRun() 
00923                     << " Snarl: " << ntpHeader->GetSnarl() << std::endl; 
00924           NoSlice=true; //if not there exit with a message after delete stuff 
00925           }
00926         }
00927         else LeSlice = theSlice;
00928       }
00929       else LeMCevent = theMCevent;
00930     }
00931     else { //not in automatic mode
00932       if(!LoadTruth(theMCevent)) { //load truth asked for
00933         LeMCevent = theMCevent = 0; //if not present load truth 0
00934         LoadTruth(theMCevent);  
00935       }
00936       else LeMCevent = theMCevent;
00937       if(!LoadSlice(theSlice)){
00938         LeSlice = theSlice = 0; //if not present load slice 0
00939         if(!LoadSlice(theSlice)){
00940           std::cerr << "No slice present in Run: " << ntpHeader->GetRun() 
00941                     << " Snarl: " << ntpHeader->GetSnarl() << std::endl; 
00942           NoSlice=true; //if not there exit with a message after delete stuff
00943         }
00944       }
00945       else LeSlice = theSlice;
00946     }
00947     //    DrawInteractionDiagram(theMCevent);
00948   }
00949 
00950   else { //if no MC present
00951     if(!automat) { //if not in automatic mode, load slice asked for if possible
00952       if(!LoadSlice(theSlice)) { //if the one asked for not present
00953         theSlice = 0;
00954         LeSlice = theSlice;
00955         if(!LoadSlice(theSlice)){ //trying loading slice 0
00956           std::cerr << "No slice present in Run: " << ntpHeader->GetRun() 
00957                     << " Snarl: " << ntpHeader->GetSnarl() << std::endl; 
00958           return false; //if not there exit with a message
00959         }
00960       }
00961       else LeSlice = theSlice;
00962     }
00963     else { //in automatic mode
00964       if(isReco) { //if there is a reco'd event
00965         theSlice = ntpEvent->slc; //load slice from event
00966         if(!LoadSlice(theSlice)) {
00967           LeSlice = theSlice = 0;         
00968           if(!LoadSlice(theSlice)) {
00969             std::cerr << "No slice present in Run: " << ntpHeader->GetRun() 
00970                       << " Snarl: " << ntpHeader->GetSnarl() << std::endl; 
00971             NoSlice=true; //if not there exit with a message after delete stuff 
00972           }
00973         }
00974         else LeSlice = theSlice;
00975       }
00976       else {  //no reco'd event
00977         if(!LoadSlice(theSlice)) {  //try to load the slice asked for
00978           LeSlice = theSlice = 0;   //otherwise try to load slice 0
00979           if(!LoadSlice(theSlice)) {
00980             std::cerr << "No slice present in Run: " << ntpHeader->GetRun() 
00981                       << " Snarl: " << ntpHeader->GetSnarl() << std::endl; 
00982             NoSlice=true; //if not there exit with a message after delete stuff
00983           }
00984         }
00985         else LeSlice = theSlice;
00986       }
00987     }
00988   }
00989 
00990   sprintf(printName,"_Run%i_Snl%i_Slc%i_Evt%i.%s",ntpHeader->GetRun(),
00991           ntpHeader->GetSnarl(),theSlice,theEvent,printOpt);
00992 
00994   //Set Up Display Canvas
00995   //Delete Old Graphs
00996 
00997   TCanvas *RecoCanvas = 0;
00998   TCanvas *MainCanvas = 0;
00999   TCanvas *LegoCanvas = 0;
01000   TCanvas *ClusterCanvas = 0;
01001 
01002   static TPolyLine *line = 0;
01003   static TPolyLine *pu1_outline = 0; static TPolyLine *fu1_outline = 0; 
01004   static TPolyLine *pv1_outline = 0; static TPolyLine *fv1_outline = 0;
01005   static TPolyLine *pu2_outline = 0; static TPolyLine *fu2_outline = 0; 
01006   static TPolyLine *pv2_outline = 0; static TPolyLine *fv2_outline = 0;
01007   static TEllipse  *nd_xy_fid = 0;
01008   static TPolyLine *nd_uz_fid = 0;
01009   static TPolyLine *nd_vz_fid = 0;
01010 
01011   static TEllipse  *fd_xy_fid = 0;
01012   static TPolyLine *fd_uz_fid1 = 0;
01013   static TPolyLine *fd_vz_fid1 = 0;
01014   static TPolyLine *fd_uz_fid2 = 0;
01015   static TPolyLine *fd_vz_fid2 = 0;
01016 
01017   TEllipse *ellie = 0;
01018 
01019   TH2F *xz_place = 0;
01020   TH2F *yz_place = 0;
01021   TH2F *yx_place = 0;
01022   TH2 *tz_place_0 = 0;
01023   TH2 *tz_place_1 = 0;
01024   TH2 *tz_missplace_0 = 0;
01025   TH2 *tz_missplace_1 = 0;
01026 
01027   static std::string tz_place_dopt="";
01028 
01029   TH2F *tz_0_lego = 0;
01030   TH2F *tz_1_lego = 0;  
01031     
01032   TMultiGraph *xz_trk = 0;
01033   TMultiGraph *yz_trk = 0;
01034   TMultiGraph *yx_trk = 0;
01035   TMultiGraph *xz_shw = 0;
01036   TMultiGraph *yz_shw = 0;
01037   TMultiGraph *yx_shw = 0;
01038   TMultiGraph *yx_veto = 0;
01039   
01040   TMultiGraph * tz_missstp_0 = 0;  
01041   TMultiGraph * tz_missstp_1 = 0;
01042   
01043   TMultiGraph *tz_stp_0 = 0;
01044   TMultiGraph *tz_stp_mid_0 = 0;
01045   TMultiGraph *tz_stp_spe_0 = 0;
01046   TMultiGraph *tz_stp_1 = 0;
01047   TMultiGraph *tz_stp_mid_1 = 0;
01048   TMultiGraph *tz_stp_spe_1 = 0;
01049 
01050   TMultiGraph *tz_trk0 = 0;
01051   TMultiGraph *tz_shw0 = 0;
01052   TMultiGraph *tz_emshw0 = 0;
01053   TMultiGraph *tz_clu0 = 0;
01054   TMultiGraph *tz_trk1 = 0;
01055   TMultiGraph *tz_shw1 = 0;
01056   TMultiGraph *tz_emshw1 = 0;
01057   TMultiGraph *tz_clu1 = 0;
01058   
01059   TLegend *cluLeg0 = 0;
01060   TLegend *cluLeg1 = 0;
01061   
01062   TMultiGraph *ytime = 0;
01063   TMultiGraph *ztime = 0;
01064   TMultiGraph *ytime_veto = 0;
01065     
01066   if(!gROOT->FindObject("RecoCanvas")){ 
01067 
01068     //set up canvases and placeholders
01069     gStyle->SetOptStat(0);
01070 
01071     RecoCanvas = new TCanvas("RecoCanvas","Reconstructed Tracks",0,0,900,700);
01072     RecoCanvas->Divide(3,2);
01073     TVirtualPad *RecoCanvas_5 = RecoCanvas->GetPad(5);
01074     RecoCanvas_5->Divide(1,2);
01075     
01076     if(LeLego) {
01077       LegoCanvas = new TCanvas("LegoCanvas","Lego View of Hit Strips",
01078                                0,0,900,700);
01079       LegoCanvas->Divide(1,2);
01080       
01081       /*
01082       int nzpos = 1000;
01083       double z_pos[1001];
01084       z_pos[0] = 0.5;
01085       z_pos[1] = 0.5+0.167;
01086       for(int i=2;i<1001;i++) z_pos[i] = z_pos[i-2]+1;
01087       */
01088       
01089       int nzpos = 500;
01090       double z_pos[501];
01091       z_pos[0] = 0.5;
01092       for(int i=1;i<501;i++) z_pos[i] = z_pos[i-1]+1;      
01093       
01094       tz_0_lego = new TH2F("tz_0_lego","TPos vs Plane view - U Planes",
01095                            nzpos,z_pos,192,-3.936,3.936);
01096       tz_0_lego->SetXTitle("Plane");
01097       tz_0_lego->SetYTitle("TPos (m)");
01098       tz_0_lego->SetZTitle("Pulse Height (PEs)");
01099       tz_1_lego = new TH2F("tz_1_lego","TPos vs Plane view - V Planes",
01100                            nzpos,z_pos,192,-3.936,3.936);
01101       tz_1_lego->SetXTitle("Plane");
01102       tz_1_lego->SetYTitle("TPos (m)");
01103       tz_1_lego->SetZTitle("Pulse Height (PEs)");
01104     }
01105 
01106     if(LeClus) {
01107       ClusterCanvas = new TCanvas("ClusterCanvas","Reconstructed Cluster View",
01108                                   910,0,400,700);
01109       ClusterCanvas->Divide(1,2);
01110     }
01111 
01112     MainCanvas = new TCanvas("MainCanvas","Main Display and Controls",
01113                              0,0,900,700);
01114     MainCanvas->Divide(2,2);
01115     // add zoom execs to these two pads:
01116     MainCanvas->GetPad(3)->AddExec("zoom","EVD->HandleZoomEvent()");
01117     MainCanvas->GetPad(4)->AddExec("zoom","EVD->HandleZoomEvent()");
01118 
01119     xz_place = new TH2F("xz_place","X vs Z view",70,0,35,50,-5,5);
01120     xz_place->SetXTitle("z position (m)");
01121     xz_place->SetYTitle("x position (m)");
01122 
01123     yz_place = new TH2F("yz_place","Y vs Z view",70,0,35,50,-5,5);
01124     yz_place->SetXTitle("z position (m)");
01125     yz_place->SetYTitle("y position (m)");
01126 
01127     yx_place = new TH2F("yx_place","Y vs X view",50,-5,5,50,-5,5);
01128     yx_place->SetXTitle("x position (m)");
01129     yx_place->SetYTitle("y position (m)");
01130     // mike, fill us
01131     Detector::Detector_t det=ntpHeader->GetVldContext().GetDetector();
01132     if(det==Detector::kFar){
01133       tz_place_0 = new TH2F("tz_place_0","Transverse vs Z view - U Planes",
01134                             70,0,35,50,-5,5);
01135       tz_place_1 = new TH2F("tz_place_1","Transverse vs Z view - V Planes",
01136                             70,0,35,50,-5,5);      
01137       tz_missplace_0 = new TH2F("tz_missplace_0","Transverse vs Z view - U Planes",
01138                             70,0,35,50,-5,5);
01139       tz_missplace_1 = new TH2F("tz_missplace_1","Transverse vs Z view - V Planes",
01140                             70,0,35,50,-5,5);      
01141     }
01142     else{
01143       PlaneOutline po;
01144       tz_place_0 = po.GetNDPlanesHist(PlaneView::kV);//strips measure U
01145       tz_place_0->SetName("tz_place_0");
01146       tz_place_0->SetTitle("Transverse vs Z view - U Planes");
01147       // attempt to defeat ROOT's behaviour whereby it unzooms z axis
01148       // when user unzooms y axis ... didn't work, causes whacky behaviour
01149       //tz_place_0->GetYaxis()->SetName("xaxis");
01150       tz_place_0->SetDirectory(gROOT);
01151 
01152       tz_missplace_0 = po.GetNDPlanesHist(PlaneView::kV);//strips measure U
01153       tz_missplace_0->SetName("tz_missplace_0");
01154       tz_missplace_0->SetTitle("Transverse vs Z view - U Planes");
01155       // attempt to defeat ROOT's behaviour whereby it unzooms z axis
01156       // when user unzooms y axis ... didn't work, causes whacky behaviour
01157       //tz_place_0->GetYaxis()->SetName("xaxis");
01158       tz_missplace_0->SetDirectory(gROOT);
01159       //      tz_place_0->SetDrawOption("col");
01160       tz_place_1 = po.GetNDPlanesHist(PlaneView::kU);//strips measure V
01161       tz_place_1->SetName("tz_place_1");
01162       tz_place_1->SetTitle("Transverse vs Z view - V Planes");
01163       //tz_place_1->GetYaxis()->SetName("xaxis");
01164       tz_place_1->SetDirectory(gROOT);
01165 
01166       tz_missplace_1 = po.GetNDPlanesHist(PlaneView::kU);//strips measure V
01167       tz_missplace_1->SetName("tz_missplace_1");
01168       tz_missplace_1->SetTitle("Transverse vs Z view - V Planes");
01169       //tz_place_1->GetYaxis()->SetName("xaxis");
01170       tz_missplace_1->SetDirectory(gROOT);
01171       //      tz_place_1->SetDrawOption("col");
01172 
01173       tz_place_dopt ="col";
01174     
01175     }
01176     tz_place_0->SetXTitle("z position (m)");
01177     tz_place_0->SetYTitle("transverse position (m)");
01178     tz_place_1->SetXTitle("z position (m)");
01179     tz_place_1->SetYTitle("transverse position (m)");
01180     
01181     tz_missplace_0->SetXTitle("z position (m)");
01182     tz_missplace_0->SetYTitle("transverse position (m)");
01183     tz_missplace_1->SetXTitle("z position (m)");
01184     tz_missplace_1->SetYTitle("transverse position (m)");
01185     
01186     this->DrawButtons(MainCanvas);
01187   }
01188   else {
01189     RecoCanvas = (TCanvas*) gROOT->FindObject("RecoCanvas");
01190     MainCanvas = (TCanvas*) gROOT->FindObject("MainCanvas");
01191 
01192     //Lego:
01193     if(gROOT->FindObject("LegoCanvas")) {
01194       LegoCanvas = (TCanvas*) gROOT->FindObject("LegoCanvas");
01195       LegoCanvas->cd(1);
01196       TVirtualPad *LegoCanvas_1 = LegoCanvas->GetPad(1);
01197       tz_0_lego = (TH2F*) LegoCanvas_1->FindObject("tz_0_lego");
01198       LegoCanvas->cd(2);
01199       TVirtualPad *LegoCanvas_2 = LegoCanvas->GetPad(2);
01200       tz_1_lego = (TH2F*) LegoCanvas_2->FindObject("tz_1_lego");
01201     }
01202     else if(LeLego) {
01203       LegoCanvas = new TCanvas("LegoCanvas","Lego View of Hit Strips",
01204                                0,0,900,700);
01205       LegoCanvas->Divide(1,2);
01206       
01207       /*
01208       int nzpos = 1000;
01209       double z_pos[1001];
01210       z_pos[0] = 0.5;
01211       z_pos[1] = 0.5+0.167;
01212       for(int i=2;i<1001;i++) z_pos[i] = z_pos[i-2]+1;
01213       */
01214       
01215       int nzpos = 500;
01216       double z_pos[501];
01217       z_pos[0] = 0.5;
01218       for(int i=1;i<501;i++) z_pos[i] = z_pos[i-1]+1;
01219 
01220       tz_0_lego = new TH2F("tz_0_lego","TPos vs Plane view - U Planes",
01221                            nzpos,z_pos,192,-3.936,3.936);
01222       tz_0_lego->SetXTitle("Plane");
01223       tz_0_lego->SetYTitle("TPos (m)");
01224       tz_0_lego->SetZTitle("Pulse Height (PEs)");
01225       tz_1_lego = new TH2F("tz_1_lego","TPos vs Plane view - V Planes",
01226                            nzpos,z_pos,192,-3.936,3.936);
01227       tz_1_lego->SetXTitle("Plane");
01228       tz_1_lego->SetYTitle("TPos (m)");
01229       tz_1_lego->SetZTitle("Pulse Height (PEs)");
01230 
01231       LegoCanvas->cd(1);
01232       tz_0_lego->Draw("lego");
01233       LegoCanvas->cd(2);
01234       tz_1_lego->Draw("lego");
01235     }
01236 
01237     if(!LeLego&&gROOT->FindObject("LegoCanvas")) {
01238       delete LegoCanvas;
01239       delete tz_0_lego;
01240       delete tz_1_lego;
01241     }
01242 
01244     RecoCanvas->cd(1);
01245     TVirtualPad *RecoCanvas_1 = RecoCanvas->GetPad(1);
01246     TVirtualPad *RecoCanvas_4 = RecoCanvas->GetPad(4);
01247     TVirtualPad *RecoCanvas_2 = RecoCanvas->GetPad(2);
01248     xz_trk = (TMultiGraph*) RecoCanvas_1->FindObject("xz_trk");
01249     yz_trk = (TMultiGraph*) RecoCanvas_4->FindObject("yz_trk");
01250     yx_trk = (TMultiGraph*) RecoCanvas_2->FindObject("yx_trk");
01251     xz_shw = (TMultiGraph*) RecoCanvas_1->FindObject("xz_shw");
01252     yz_shw = (TMultiGraph*) RecoCanvas_4->FindObject("yz_shw");
01253     yx_shw = (TMultiGraph*) RecoCanvas_2->FindObject("yx_shw");
01254     yx_veto = (TMultiGraph*) RecoCanvas_2->FindObject("yx_veto");
01255     
01256     if(!drawSAME) {
01257       delete xz_trk; xz_trk = 0;
01258       delete yz_trk; yz_trk = 0;
01259       delete yx_trk; yx_trk = 0;
01260       delete xz_shw; xz_shw = 0;
01261       delete yz_shw; yz_shw = 0;
01262       delete yx_shw; yx_shw = 0;
01263       delete yx_veto; yx_veto = 0;
01264     }
01265 
01266     RecoCanvas->cd(5);
01267     TVirtualPad *RecoCanvas_5 = RecoCanvas->GetPad(5);
01268     TVirtualPad *RecoCanvas_5_1 = RecoCanvas_5->GetPad(1);
01269     TVirtualPad *RecoCanvas_5_2 = RecoCanvas_5->GetPad(2);
01270     ytime = (TMultiGraph*) RecoCanvas_5_1->FindObject("ytime");
01271     ztime = (TMultiGraph*) RecoCanvas_5_2->FindObject("ztime");
01272     ytime_veto = (TMultiGraph*) RecoCanvas_5_1->FindObject("ytime_veto");
01273     
01274     if(!drawSAME) {
01275       delete ytime; ytime = 0;
01276       delete ztime; ztime = 0;
01277       delete ytime_veto; ytime_veto = 0;
01278     }
01279 
01280     MainCanvas->cd(1);
01281     TVirtualPad *MainCanvas_1 = MainCanvas->GetPad(1);
01282     TLatex *info1 = (TLatex*) MainCanvas_1->FindObject("info1");
01283     TLatex *info2 = (TLatex*) MainCanvas_1->FindObject("info2");
01284     TLatex *info3 = (TLatex*) MainCanvas_1->FindObject("info3");
01285     TLatex *info4 = (TLatex*) MainCanvas_1->FindObject("info4");
01286     TLatex *info5 = (TLatex*) MainCanvas_1->FindObject("info5");
01287     TLatex *info6 = (TLatex*) MainCanvas_1->FindObject("info6");
01288     TLatex *info7 = (TLatex*) MainCanvas_1->FindObject("info7");
01289     TLatex *info8 = (TLatex*) MainCanvas_1->FindObject("info8");
01290     TLatex *info9 = (TLatex*) MainCanvas_1->FindObject("info9");
01291     TLatex *info10 = (TLatex*) MainCanvas_1->FindObject("info10");
01292     TLatex *info11 = (TLatex*) MainCanvas_1->FindObject("info11");
01293     TLatex *info12 = (TLatex*) MainCanvas_1->FindObject("info12");
01294     TLatex *info13 = (TLatex*) MainCanvas_1->FindObject("info13");
01295     TLatex *info14 = (TLatex*) MainCanvas_1->FindObject("info14");
01296 
01297     delete info1;
01298     delete info2;
01299     delete info3;
01300     delete info4;
01301     delete info5;
01302     delete info6;
01303     delete info7;
01304     delete info8;
01305     delete info9;
01306     delete info10;
01307     delete info11;
01308     delete info12;
01309     delete info13;
01310     delete info14;
01311 
01313 
01315     MainCanvas->cd(3);
01316     TPad *MainCanvas_3 = (TPad*)MainCanvas->GetPad(3);
01317 
01318     tz_stp_0 = (TMultiGraph*) MainCanvas_3->FindObject("tz_stp_0");
01319     tz_stp_mid_0 = (TMultiGraph*) MainCanvas_3->FindObject("tz_stp_mid_0");
01320     tz_stp_spe_0 = (TMultiGraph*) MainCanvas_3->FindObject("tz_stp_spe_0");    
01321     if(!drawSAME){
01322       delete tz_stp_0; tz_stp_0 = 0;
01323       delete tz_stp_mid_0; tz_stp_mid_0 = 0;
01324       delete tz_stp_spe_0; tz_stp_spe_0 = 0;
01325     }
01326 
01327     tz_trk0 = (TMultiGraph*) MainCanvas_3->FindObject("tz_trk0");
01328     tz_shw0 = (TMultiGraph*) MainCanvas_3->FindObject("tz_shw0");
01329     tz_emshw0 = (TMultiGraph*) MainCanvas_3->FindObject("tz_emshw0");
01330     if(!drawSAME){
01331       delete tz_trk0; tz_trk0 = 0;
01332       delete tz_shw0; tz_shw0 = 0;
01333       delete tz_emshw0; tz_emshw0 = 0;
01334     }
01335     
01336     TArrow *ttz_arrow1 = (TArrow*) MainCanvas_3->FindObject("TArrow");
01337     delete ttz_arrow1;
01338     
01339     //delete stdhep lines:
01340     TLine *stdhepLine = 0;
01341     while((stdhepLine = (TLine*) MainCanvas_3->FindObject("TLine"))) {
01342       delete stdhepLine;
01343     }
01344   
01345     MainCanvas->cd(4);
01346     TPad *MainCanvas_4 = (TPad*)MainCanvas->GetPad(4);
01347 
01348     tz_stp_1 = (TMultiGraph*) MainCanvas_4->FindObject("tz_stp_1");
01349     tz_stp_mid_1 = (TMultiGraph*) MainCanvas_4->FindObject("tz_stp_mid_1");
01350     tz_stp_spe_1 = (TMultiGraph*) MainCanvas_4->FindObject("tz_stp_spe_1");
01351     if(!drawSAME){
01352       delete tz_stp_1; tz_stp_1 = 0;
01353       delete tz_stp_mid_1; tz_stp_mid_1 = 0;
01354       delete tz_stp_spe_1; tz_stp_spe_1 = 0;
01355     }
01356 
01357     tz_trk1 = (TMultiGraph*) MainCanvas_4->FindObject("tz_trk1");
01358     tz_shw1 = (TMultiGraph*) MainCanvas_4->FindObject("tz_shw1");
01359     tz_emshw1 = (TMultiGraph*) MainCanvas_4->FindObject("tz_emshw1");
01360     if(!drawSAME){
01361       delete tz_trk1; tz_trk1 = 0;
01362       delete tz_shw1; tz_shw1 = 0;
01363       delete tz_emshw1; tz_emshw1 = 0;
01364     }
01365 
01366 
01367     TArrow *ttz_arrow2 = (TArrow*) MainCanvas_4->FindObject("TArrow");
01368     delete ttz_arrow2;
01369 
01370     stdhepLine = 0;  
01371     while((stdhepLine = (TLine*) MainCanvas_4->FindObject("TLine"))) {
01372       delete stdhepLine;
01373     }
01374 
01375     //Cluster:
01376     if(gROOT->FindObject("ClusterCanvas")) {
01377       ClusterCanvas = (TCanvas*) gROOT->FindObject("ClusterCanvas");
01378       ClusterCanvas->cd(1);
01379       TVirtualPad *ClusterCanvas_1 = ClusterCanvas->GetPad(1);
01380       tz_clu0 = (TMultiGraph*) ClusterCanvas_1->FindObject("tz_clu0");
01381       cluLeg0 = (TLegend*) ClusterCanvas_1->FindObject("TPave");
01382       if(!drawSAME) {
01383         delete tz_clu0; tz_clu0 = 0;
01384         delete cluLeg0; cluLeg0 = 0;
01385       }
01386       gPad->Update();
01387       gPad->Modified();
01388       ClusterCanvas->cd(2);
01389       TVirtualPad *ClusterCanvas_2 = ClusterCanvas->GetPad(2);
01390       tz_clu1 = (TMultiGraph*) ClusterCanvas_2->FindObject("tz_clu1");
01391       cluLeg1 = (TLegend*) ClusterCanvas_2->FindObject("TPave");
01392       if(!drawSAME) {
01393         delete tz_clu1; tz_clu1 = 0;
01394         delete cluLeg1; cluLeg1 = 0;
01395       }
01396       gPad->Update();
01397       gPad->Modified();
01398     }
01399     else if(LeClus) {
01400       ClusterCanvas = new TCanvas("ClusterCanvas","Reconstructed Cluster View",
01401                                   910,0,400,700);
01402       ClusterCanvas->Divide(1,2);
01403     }
01404 
01405     if(!LeClus&&gROOT->FindObject("ClusterCanvas")) {
01406       delete ClusterCanvas;
01407     }
01408 
01410         
01412     RecoCanvas->cd(2);
01413     //    line = (TPolyLine*) RecoCanvas_2->FindObject("TPolyLine");
01414     ellie = (TEllipse*) RecoCanvas_2->FindObject("TEllipse");
01415     RecoCanvas->Clear();
01416     RecoCanvas->Divide(3,2);
01417     RecoCanvas_5 = RecoCanvas->GetPad(5);
01418     RecoCanvas_5->Divide(1,2);
01419     
01421     xz_place = (TH2F*) gROOT->FindObject("xz_place");
01422     yz_place = (TH2F*) gROOT->FindObject("yz_place");
01423     yx_place = (TH2F*) gROOT->FindObject("yx_place");
01424     tz_place_0 = (TH2*) gROOT->FindObject("tz_place_0");
01425     tz_place_1 = (TH2*) gROOT->FindObject("tz_place_1");
01426     tz_missplace_0 = (TH2*) gROOT->FindObject("tz_missplace_0");
01427     tz_missplace_1 = (TH2*) gROOT->FindObject("tz_missplace_1");
01428 
01429     xz_place->GetXaxis()->UnZoom();
01430     yz_place->GetXaxis()->UnZoom();
01431     tz_place_0->GetXaxis()->UnZoom();
01432     tz_place_1->GetXaxis()->UnZoom();
01433     tz_missplace_0->GetXaxis()->UnZoom();
01434     tz_missplace_1->GetXaxis()->UnZoom();
01435     xz_place->GetYaxis()->UnZoom();
01436     yz_place->GetYaxis()->UnZoom();
01437     tz_place_0->GetYaxis()->UnZoom();
01438     tz_place_1->GetYaxis()->UnZoom();
01439     tz_missplace_0->GetYaxis()->UnZoom();
01440     tz_missplace_1->GetYaxis()->UnZoom();
01441 
01442     if(ntpHeader->GetVldContext().GetDetector()==Detector::kNear){
01443       yx_place->GetXaxis()->SetRangeUser(-2.6,3.8);
01444       yx_place->GetYaxis()->SetRangeUser(-3.2,3.2);
01445 
01446     }
01447     else {
01448       yx_place->GetXaxis()->UnZoom();
01449       yx_place->GetYaxis()->UnZoom();
01450     }
01451     
01452     if(LeLego){
01453       tz_0_lego->GetXaxis()->UnZoom();
01454       tz_0_lego->GetYaxis()->UnZoom();
01455       tz_1_lego->GetXaxis()->UnZoom();
01456       tz_1_lego->GetYaxis()->UnZoom();
01457       if(!drawSAME) {
01458         tz_0_lego->Reset();
01459         tz_1_lego->Reset();
01460       }
01461     }
01462     if(handScan) {
01463       ScanID = 0;
01464       ScanTop = 0;
01465       ChangeLogButColor();
01466     }
01467   }
01468 
01469   //if no detector outlines, make them here:
01470   if(!line){
01471     float linex_caldet[5] = {-0.5,0.5,0.5,-0.5,-0.5};
01472     float liney_caldet[5] = {-0.5,-0.5,0.5,0.5,-0.5};
01473     if(ntpHeader->GetVldContext().GetDetector()==Detector::kFar) {
01474       line = new TPolyLine(33,"");
01475       line->SetPoint( 0, 421.8893*Munits::cm,-142.8867*Munits::cm);
01476       line->SetPoint( 1, 421.8893*Munits::cm,-138.3342*Munits::cm);
01477       line->SetPoint( 2, 400.1614*Munits::cm,-115.9855*Munits::cm);
01478       line->SetPoint( 3, 400.1614*Munits::cm,  87.6358*Munits::cm);
01479       line->SetPoint( 4, 406.9902*Munits::cm,  94.0507*Munits::cm);
01480       line->SetPoint( 5, 429.1319*Munits::cm, 101.5003*Munits::cm);
01481       line->SetPoint( 6, 447.1350*Munits::cm, 101.5003*Munits::cm);
01482       line->SetPoint( 7, 454.7915*Munits::cm,  94.2577*Munits::cm);
01483       line->SetPoint( 8, 457.6886*Munits::cm,  94.2577*Munits::cm);
01484       line->SetPoint( 9, 457.6886*Munits::cm, 109.3637*Munits::cm);
01485       line->SetPoint(10, 143.7724*Munits::cm, 423.2799*Munits::cm);
01486       line->SetPoint(11, 139.4268*Munits::cm, 423.2799*Munits::cm);
01487       line->SetPoint(12, 117.2850*Munits::cm, 401.1382*Munits::cm);
01488       line->SetPoint(13,-116.9622*Munits::cm, 401.1382*Munits::cm);
01489       line->SetPoint(14,-139.1040*Munits::cm, 423.2799*Munits::cm);
01490       line->SetPoint(15,-143.4496*Munits::cm, 423.2799*Munits::cm);
01491       line->SetPoint(16,-457.3658*Munits::cm, 109.3637*Munits::cm);
01492       line->SetPoint(17,-457.3658*Munits::cm,  94.2577*Munits::cm);
01493       line->SetPoint(18,-454.4687*Munits::cm,  94.2577*Munits::cm);
01494       line->SetPoint(19,-439.9834*Munits::cm, 101.9141*Munits::cm);
01495       line->SetPoint(20,-429.8438*Munits::cm, 101.9141*Munits::cm);
01496       line->SetPoint(21,-406.6674*Munits::cm,  94.2577*Munits::cm);
01497       line->SetPoint(22,-399.8386*Munits::cm,  84.7388*Munits::cm);
01498       line->SetPoint(23,-399.8386*Munits::cm,-115.9855*Munits::cm);
01499       line->SetPoint(24,-421.5665*Munits::cm,-137.7134*Munits::cm);
01500       line->SetPoint(25,-421.5665*Munits::cm,-142.8867*Munits::cm);
01501       line->SetPoint(26,-143.4496*Munits::cm,-421.0036*Munits::cm);
01502       line->SetPoint(27,-139.1040*Munits::cm,-421.0036*Munits::cm);
01503       line->SetPoint(28,-116.9622*Munits::cm,-398.8619*Munits::cm);
01504       line->SetPoint(29, 116.8712*Munits::cm,-398.8619*Munits::cm);
01505       line->SetPoint(30, 139.4268*Munits::cm,-421.0036*Munits::cm);
01506       line->SetPoint(31, 143.7724*Munits::cm,-421.0036*Munits::cm);
01507       line->SetPoint(32, 421.8893*Munits::cm,-142.8867*Munits::cm);
01508       
01509       fd_xy_fid = new TEllipse(0., 0., 3.74, 3.74); // 0.8 m radius
01510       fd_xy_fid->SetLineWidth(2);
01511       fd_xy_fid->SetLineColor(kBlack);
01512       fd_xy_fid->SetLineStyle(kDashed);
01513       fd_xy_fid->SetBit(kCannotPick); // hey, don't move!
01514       
01515       fd_uz_fid1 = new TPolyLine(5);
01516       fd_vz_fid1 = new TPolyLine(5);
01517       fd_uz_fid2 = new TPolyLine(5);
01518       fd_vz_fid2 = new TPolyLine(5);
01519       const double u_cen=0;
01520       const double v_cen=0;
01521       fd_uz_fid1->SetPoint(0,0.49,u_cen+3.74);
01522       fd_uz_fid1->SetPoint(1,14.9,u_cen+3.74);
01523       fd_uz_fid1->SetPoint(2,14.9,u_cen-3.74);
01524       fd_uz_fid1->SetPoint(3,0.49,u_cen-3.74);
01525       fd_uz_fid1->SetPoint(4,0.49,u_cen+3.74);
01526       fd_uz_fid1->SetLineColor(kBlack);
01527       fd_uz_fid1->SetLineStyle(kDashed);
01528       fd_uz_fid1->SetLineWidth(2);
01529       fd_uz_fid1->SetBit(kCannotPick);
01530 
01531       fd_uz_fid2->SetPoint(0,16.27,u_cen+3.74);
01532       fd_uz_fid2->SetPoint(1,27.98,u_cen+3.74);
01533       fd_uz_fid2->SetPoint(2,27.98,u_cen-3.74);
01534       fd_uz_fid2->SetPoint(3,16.27,u_cen-3.74);
01535       fd_uz_fid2->SetPoint(4,16.27,u_cen+3.74);
01536       fd_uz_fid2->SetLineColor(kBlack);
01537       fd_uz_fid2->SetLineStyle(kDashed);
01538       fd_uz_fid2->SetLineWidth(2);
01539       fd_uz_fid2->SetBit(kCannotPick);
01540 
01541       fd_vz_fid1->SetPoint(0,0.49,v_cen+3.74);
01542       fd_vz_fid1->SetPoint(1,14.9,v_cen+3.74);
01543       fd_vz_fid1->SetPoint(2,14.9,v_cen-3.74);
01544       fd_vz_fid1->SetPoint(3,0.49,v_cen-3.74);
01545       fd_vz_fid1->SetPoint(4,0.49,v_cen+3.74);
01546       fd_vz_fid1->SetLineColor(kBlack);
01547       fd_vz_fid1->SetLineStyle(kDashed);
01548       fd_vz_fid1->SetLineWidth(2);
01549       fd_vz_fid1->SetBit(kCannotPick);
01550 
01551       fd_vz_fid2->SetPoint(0,16.27,u_cen+3.74);
01552       fd_vz_fid2->SetPoint(1,27.98,u_cen+3.74);
01553       fd_vz_fid2->SetPoint(2,27.98,u_cen-3.74);
01554       fd_vz_fid2->SetPoint(3,16.27,u_cen-3.74);
01555       fd_vz_fid2->SetPoint(4,16.27,u_cen+3.74);
01556       fd_vz_fid2->SetLineColor(kBlack);
01557       fd_vz_fid2->SetLineStyle(kDashed);
01558       fd_vz_fid2->SetLineWidth(2);
01559       fd_vz_fid2->SetBit(kCannotPick);
01560 
01561 
01562     }     
01563     else if(ntpHeader->GetVldContext().GetDetector()==Detector::kNear) {
01564       line = new TPolyLine(23,"");
01565       Double_t x0 = 55.78*Munits::cm;   
01566       line->SetPoint( 0,-121.43*Munits::inch+x0,  0.47*Munits::inch);
01567       line->SetPoint( 1,-120.25*Munits::inch+x0,  0.47*Munits::inch);
01568       line->SetPoint( 2,-115.14*Munits::inch+x0,  3.42*Munits::inch);
01569       line->SetPoint( 3,-110.24*Munits::inch+x0,  3.42*Munits::inch);
01570       line->SetPoint( 4, -95.24*Munits::inch+x0, -1.48*Munits::inch);
01571       line->SetPoint( 5, -95.24*Munits::inch+x0,-35.47*Munits::inch);
01572       line->SetPoint( 6, -69.80*Munits::inch+x0,-60.91*Munits::inch);
01573       line->SetPoint( 7, -69.80*Munits::inch+x0,-75.04*Munits::inch);
01574       line->SetPoint( 8,  69.80*Munits::inch+x0,-75.04*Munits::inch);
01575       line->SetPoint( 9,  69.80*Munits::inch+x0,-60.91*Munits::inch);
01576       line->SetPoint(10,  95.24*Munits::inch+x0,-35.47*Munits::inch);
01577       line->SetPoint(11,  95.24*Munits::inch+x0, -1.48*Munits::inch);
01578       line->SetPoint(12, 110.16*Munits::inch+x0,  3.42*Munits::inch);
01579       line->SetPoint(13, 117.30*Munits::inch+x0,  3.42*Munits::inch);
01580       line->SetPoint(14, 120.25*Munits::inch+x0,  0.47*Munits::inch);
01581       line->SetPoint(15, 121.43*Munits::inch+x0,  0.47*Munits::inch);
01582       line->SetPoint(16, 121.43*Munits::inch+x0,  9.28*Munits::inch);
01583       line->SetPoint(17,  69.80*Munits::inch+x0, 60.91*Munits::inch);
01584       line->SetPoint(18,  69.80*Munits::inch+x0, 75.04*Munits::inch);
01585       line->SetPoint(19, -69.80*Munits::inch+x0, 75.04*Munits::inch);
01586       line->SetPoint(20, -69.80*Munits::inch+x0, 60.91*Munits::inch);
01587       line->SetPoint(21,-121.43*Munits::inch+x0,  9.28*Munits::inch);
01588       line->SetPoint(22,-121.43*Munits::inch+x0,  0.47*Munits::inch);
01589       line->SetBit(kCannotPick);
01590       // near detector plane outlines
01591       PlaneOutline po;
01592       Color_t colu=38;
01593       Color_t colv=46;
01594       po.GetOutline(PlaneView::kV, PlaneCoverage::kNearPartial,
01595                     pv1_outline, pv2_outline);
01596       po.GetOutline(PlaneView::kV, PlaneCoverage::kNearFull,
01597                     fv1_outline, fv2_outline);
01598       po.GetOutline(PlaneView::kU, PlaneCoverage::kNearPartial,
01599                     pu1_outline, pu2_outline);
01600       po.GetOutline(PlaneView::kU, PlaneCoverage::kNearFull,
01601                     fu1_outline, fu2_outline);
01602       pv1_outline->SetLineColor(colv);
01603       pu1_outline->SetLineColor(colu);
01604 
01605       fv1_outline->SetLineColor(colv);
01606       fu1_outline->SetLineColor(colu);
01607       fv2_outline->SetFillColor(16);
01608       fu2_outline->SetFillColor(16);
01609       fv2_outline->SetFillStyle(4020);
01610       fu2_outline->SetFillStyle(4020);
01611       
01612       pv1_outline->SetLineWidth(2);
01613       pu1_outline->SetLineWidth(2);
01614       fv1_outline->SetLineWidth(2);
01615       fu1_outline->SetLineWidth(2);
01616       fv2_outline->SetLineWidth(2);
01617       fu2_outline->SetLineWidth(2);
01618 
01619       pv1_outline->SetBit(kCannotPick);
01620       pu1_outline->SetBit(kCannotPick);
01621       fv1_outline->SetBit(kCannotPick);
01622       fu1_outline->SetBit(kCannotPick);
01623       fv2_outline->SetBit(kCannotPick);
01624       fu2_outline->SetBit(kCannotPick);
01625 
01626 
01627       nd_xy_fid = new TEllipse(1.4885, 0.1397, 0.8, 0.8); // 0.8 m radius
01628       nd_xy_fid->SetLineWidth(2);
01629       nd_xy_fid->SetLineColor(kBlack);
01630       nd_xy_fid->SetLineStyle(kDashed);
01631       nd_xy_fid->SetBit(kCannotPick); // hey, don't move!
01632 
01633       nd_uz_fid = new TPolyLine(5);
01634       nd_vz_fid = new TPolyLine(5);
01635       const double u_cen=(1.0/sqrt(2.0))*(1.4885+0.1397);
01636       const double v_cen=(1.0/sqrt(2.0))*(0.1397-1.4885);
01637       nd_uz_fid->SetPoint(0,0.8,u_cen+0.8);
01638       nd_uz_fid->SetPoint(1,4.0,u_cen+0.8);
01639       nd_uz_fid->SetPoint(2,4.0,u_cen-0.8);
01640       nd_uz_fid->SetPoint(3,0.8,u_cen-0.8);
01641       nd_uz_fid->SetPoint(4,0.8,u_cen+0.8);
01642       nd_uz_fid->SetLineColor(kBlack);
01643       nd_uz_fid->SetLineStyle(kDashed);
01644       nd_uz_fid->SetLineWidth(2);
01645       nd_uz_fid->SetBit(kCannotPick);
01646 
01647       nd_vz_fid->SetPoint(0,0.8,v_cen+0.8);
01648       nd_vz_fid->SetPoint(1,4.0,v_cen+0.8);
01649       nd_vz_fid->SetPoint(2,4.0,v_cen-0.8);
01650       nd_vz_fid->SetPoint(3,0.8,v_cen-0.8);
01651       nd_vz_fid->SetPoint(4,0.8,v_cen+0.8);
01652       nd_vz_fid->SetLineColor(kBlack);
01653       nd_vz_fid->SetLineStyle(kDashed);
01654       nd_vz_fid->SetLineWidth(2);
01655       nd_vz_fid->SetBit(kCannotPick);
01656 
01657      }
01658     else if(ntpHeader->GetVldContext().GetDetector()==Detector::kCalDet) 
01659       line = new TPolyLine(5,linex_caldet,liney_caldet);
01660     line->SetLineWidth(3);
01661     line->SetLineColor(4);
01662   }
01663   
01664   if(!ellie&&ntpHeader->GetVldContext().GetDetector()==Detector::kFar){ 
01665     ellie = new TEllipse(0,0,3.5,3.5,0,360,0);   
01666     ellie->SetLineColor(6);
01667     ellie->SetLineWidth(3);
01668     ellie->SetLineStyle(2);
01669   }
01670 
01671   //  if(NoSlice) return false;
01672 
01673   // Missing Strips
01674 
01675   if(tz_missstp_0 && nmissU>0) {
01676     tz_missstp_0 = new TMultiGraph();
01677     tz_missstp_0->SetName("tz_missstp_0");
01678     tz_missstp_0->SetTitle("Transverse Position vs Z View");
01679   }
01680   if(tz_missstp_0 && nmissU>0){
01681     TGraph *temp = new TGraph(nmissU,missstripz_0,missstript_0);
01682     temp->SetMarkerColor(2);
01683     temp->SetMarkerSize(1);
01684     temp->SetMarkerStyle(8);
01685     tz_missstp_0->Add(temp);
01686   }
01687   if(tz_missstp_0 && nmissU>0){
01688     TGraph *temp = new TGraph(nmissU,missstripz_0,missstript_0);
01689     temp->SetMarkerColor(2);
01690     temp->SetMarkerSize(1);
01691     temp->SetMarkerStyle(8);
01692     tz_missstp_0->Add(temp);
01693   }
01694   if(tz_missstp_0 && nmissUOneEnd>0){
01695     TGraph *temp = new TGraph(nmissUOneEnd,missstripzOneEnd_0,missstriptOneEnd_0);
01696     temp->SetMarkerColor(3);
01697     temp->SetMarkerSize(1);
01698     temp->SetMarkerStyle(8);
01699     tz_missstp_0->Add(temp);
01700   }
01701   if(tz_missstp_0 && nmissULowPE>0){
01702     TGraph *temp = new TGraph(nmissULowPE,missstripzLowPE_0,missstriptLowPE_0);
01703     temp->SetMarkerColor(4);
01704     temp->SetMarkerSize(1);
01705     temp->SetMarkerStyle(8);
01706     tz_missstp_0->Add(temp);
01707   }
01708   if(tz_missstp_1 && nmissV>0) {
01709     tz_missstp_1 = new TMultiGraph();
01710     tz_missstp_1->SetName("tz_missstp_1");
01711     tz_missstp_1->SetTitle("Transverse Position vs Z View");
01712   }
01713   if(tz_missstp_1 && nmissV>0){
01714     TGraph *temp = new TGraph(nmissV,missstripz_1,missstript_1);
01715     temp->SetMarkerColor(2);
01716     temp->SetMarkerSize(1);
01717     temp->SetMarkerStyle(8);
01718     tz_missstp_1->Add(temp);
01719   }
01720   if(tz_missstp_1 && nmissVOneEnd>0){
01721     TGraph *temp = new TGraph(nmissVOneEnd,missstripzOneEnd_1,missstriptOneEnd_1);
01722     temp->SetMarkerColor(3);
01723     temp->SetMarkerSize(1);
01724     temp->SetMarkerStyle(8);
01725     tz_missstp_1->Add(temp);
01726   }
01727   if(tz_missstp_1 && nmissVLowPE>0){
01728     TGraph *temp = new TGraph(nmissVLowPE,missstripzLowPE_1,missstriptLowPE_1);
01729     temp->SetMarkerColor(4);
01730     temp->SetMarkerSize(1);
01731     temp->SetMarkerStyle(8);
01732     tz_missstp_1->Add(temp);
01733   }
01734   delete [] missstript_0;
01735   delete [] missstripz_0;
01736   delete [] missstript_1;
01737   delete [] missstripz_1;
01738 
01739   delete [] missstriptOneEnd_0;
01740   delete [] missstripzOneEnd_0;
01741   delete [] missstriptOneEnd_1;
01742   delete [] missstripzOneEnd_1;
01743 
01744   delete [] missstriptLowPE_0;
01745   delete [] missstripzLowPE_0;
01746   delete [] missstriptLowPE_1;
01747   delete [] missstripzLowPE_1;
01748 
01749 
01750 
01752   //Strips
01753   int slc_nstrip=0;
01754   if(ntpSlice){
01755     slc_nstrip = ntpSlice->nstrip;
01756   }
01757     float *stp_z_big_0 = new float[slc_nstrip];
01758     float *stp_z_mid_0 = new float[slc_nstrip];
01759     float *stp_z_spe_0 = new float[slc_nstrip];
01760     
01761     float *stp_tpos_big_0 = new float[slc_nstrip];
01762     float *stp_tpos_mid_0 = new float[slc_nstrip];
01763     float *stp_tpos_spe_0 = new float[slc_nstrip];
01764     
01765     int nstp_big_0 = 0;
01766     int nstp_mid_0 = 0;
01767     int nstp_spe_0 = 0;
01768     
01769     float *stp_z_big_1 = new float[slc_nstrip];
01770     float *stp_z_mid_1 = new float[slc_nstrip];
01771     float *stp_z_spe_1 = new float[slc_nstrip];
01772     
01773     float *stp_tpos_big_1 = new float[slc_nstrip];
01774     float *stp_tpos_mid_1 = new float[slc_nstrip];
01775     float *stp_tpos_spe_1 = new float[slc_nstrip];
01776     
01777     int nstp_big_1 = 0;
01778     int nstp_mid_1 = 0;
01779     int nstp_spe_1 = 0;
01780     
01781     float ATH_reco0[500][192] = {};
01782     float ATH_reco1[500][192] = {};
01783     float ATH_mcA[500][192] = {};
01784     float ATH_mcB[500][192] = {};
01785     
01786     for(int i=0;i<500;i++){
01787       for(int j=0;j<192;j++){
01788         ATH_reco0[i][j] = -1;
01789         ATH_reco1[i][j] = -1;
01790         ATH_mcA[i][j] = -1;
01791         ATH_mcB[i][j] = -1;
01792       }
01793     }
01794     
01795     float highest_plane = 0;
01796     float lowest_plane = 500;
01797     
01798     float highest_z = 0;
01799     float lowest_z = 30.;
01800     float highest_t0 = -4.0;
01801     float lowest_t0 = 4.0;
01802     float highest_t1 = -4.0;
01803     float lowest_t1 = 4.0;
01804     
01805     for(int i=0;i<slc_nstrip;i++){
01806       
01807       int index = ntpSlice->stp[i];
01808       ntpStrip = dynamic_cast<NtpSRStrip *>(stripArray[index]);
01809       
01810       int tempo_pln = ntpStrip->plane;
01811       int tempo_stp = ntpStrip->strip;
01812       
01813       if(tempo_pln<lowest_plane) {
01814         lowest_plane=tempo_pln;
01815         lowest_z=ntpStrip->z;
01816       }
01817       if(tempo_pln>highest_plane) {
01818         highest_plane=tempo_pln;
01819         highest_z=ntpStrip->z;
01820       }
01821       
01822       ATH_reco0[tempo_pln][tempo_stp] = ntpStrip->ph0.pe;
01823       ATH_reco1[tempo_pln][tempo_stp] = ntpStrip->ph1.pe;
01824       
01825       if(ntpStrip->planeview==2){
01826         
01827         if(LeLego) 
01828           tz_0_lego->Fill(tempo_pln-0.49,ntpStrip->tpos,
01829                           ntpStrip->ph0.pe+ntpStrip->ph1.pe);
01830         
01831         if(ntpStrip->tpos<lowest_t0) lowest_t0=ntpStrip->tpos;
01832         if(ntpStrip->tpos>highest_t0) highest_t0=ntpStrip->tpos;
01833         
01834         if(ntpStrip->ph0.pe+ntpStrip->ph1.pe<Dspe_val){
01835           stp_z_spe_0[nstp_spe_0]=ntpStrip->z;
01836           stp_tpos_spe_0[nstp_spe_0]=ntpStrip->tpos;
01837           nstp_spe_0++;
01838         }
01839         else if(ntpStrip->ph0.pe+ntpStrip->ph1.pe<Dmid_val){
01840           stp_z_mid_0[nstp_mid_0]=ntpStrip->z;
01841           stp_tpos_mid_0[nstp_mid_0]=ntpStrip->tpos;
01842           nstp_mid_0++;
01843         }
01844         else {
01845           stp_z_big_0[nstp_big_0]=ntpStrip->z;
01846           stp_tpos_big_0[nstp_big_0]=ntpStrip->tpos;
01847           nstp_big_0++;
01848         }
01849       }
01850       
01851       else {
01852         
01853         if(LeLego)
01854           tz_1_lego->Fill(tempo_pln-0.49,ntpStrip->tpos,
01855                           ntpStrip->ph0.pe+ntpStrip->ph1.pe);
01856         
01857         if(ntpStrip->tpos<lowest_t1) lowest_t1=ntpStrip->tpos;
01858         if(ntpStrip->tpos>highest_t1) highest_t1=ntpStrip->tpos;
01859         
01860         if(ntpStrip->ph0.pe+ntpStrip->ph1.pe<Dspe_val){
01861           stp_z_spe_1[nstp_spe_1]=ntpStrip->z;
01862           stp_tpos_spe_1[nstp_spe_1]=ntpStrip->tpos;
01863           nstp_spe_1++;
01864         }
01865         else if(ntpStrip->ph0.pe+ntpStrip->ph1.pe<Dmid_val){
01866           stp_z_mid_1[nstp_mid_1]=ntpStrip->z;
01867           stp_tpos_mid_1[nstp_mid_1]=ntpStrip->tpos;
01868           nstp_mid_1++;
01869         }
01870         else {
01871           stp_z_big_1[nstp_big_1]=ntpStrip->z;
01872           stp_tpos_big_1[nstp_big_1]=ntpStrip->tpos;
01873           nstp_big_1++;
01874         }
01875       }
01876     }
01877     
01878     if(!tz_stp_0 && nstp_big_0>0) {
01879       tz_stp_0 = new TMultiGraph();
01880       tz_stp_0->SetName("tz_stp_0");
01881       tz_stp_0->SetTitle("Transverse Position vs Z View");
01882     }
01883     if(nstp_big_0>0){
01884       TGraph *temp = new TGraph(nstp_big_0,stp_z_big_0,stp_tpos_big_0);
01885       temp->SetMarkerColor(1);
01886       temp->SetMarkerSize(1.1);
01887       temp->SetMarkerStyle(8);
01888       tz_stp_0->Add(temp);
01889     }
01890     if(!tz_stp_mid_0 && nstp_mid_0>0){
01891       tz_stp_mid_0 = new TMultiGraph();
01892       tz_stp_mid_0->SetName("tz_stp_mid_0");
01893       tz_stp_mid_0->SetTitle("Transverse Position vs Z View");
01894     }
01895     if(nstp_mid_0>0){
01896       TGraph *temp = new TGraph(nstp_mid_0,stp_z_mid_0,stp_tpos_mid_0);
01897       temp->SetMarkerColor(4);
01898       temp->SetMarkerSize(1.1);
01899       temp->SetMarkerStyle(8);
01900       tz_stp_mid_0->Add(temp);
01901     }
01902     if(!tz_stp_spe_0 && nstp_spe_0>0){
01903       tz_stp_spe_0 = new TMultiGraph();
01904       tz_stp_spe_0->SetName("tz_stp_spe_0");
01905     }
01906     if(nstp_spe_0>0){  
01907       TGraph *temp = new TGraph(nstp_spe_0,stp_z_spe_0,stp_tpos_spe_0);
01908       temp->SetMarkerColor(3);
01909       temp->SetMarkerSize(1.1);
01910       temp->SetMarkerStyle(8);
01911       tz_stp_spe_0->Add(temp);
01912     }
01913     if(!tz_stp_1 && nstp_big_1>0) {
01914       tz_stp_1 = new TMultiGraph();
01915       tz_stp_1->SetName("tz_stp_1");
01916       tz_stp_1->SetTitle("Transverse Position vs Z View");
01917     }
01918     if(nstp_big_1>0){
01919       TGraph *temp = new TGraph(nstp_big_1,stp_z_big_1,stp_tpos_big_1);
01920       temp->SetMarkerColor(1);
01921       temp->SetMarkerSize(1.1);
01922       temp->SetMarkerStyle(8);
01923       tz_stp_1->Add(temp);
01924     }
01925     
01926     if(!tz_stp_mid_1 && nstp_mid_1>0){
01927       tz_stp_mid_1 = new TMultiGraph();
01928       tz_stp_mid_1->SetName("tz_stp_mid_1");
01929       tz_stp_mid_1->SetTitle("Transverse Position vs Z View");
01930     }
01931     if(nstp_mid_1>0){
01932       TGraph *temp = new TGraph(nstp_mid_1,stp_z_mid_1,stp_tpos_mid_1);
01933       temp->SetMarkerColor(4);
01934       temp->SetMarkerSize(1.1);
01935       temp->SetMarkerStyle(8);
01936       tz_stp_mid_1->Add(temp);
01937     }
01938     
01939     if(!tz_stp_spe_1 && nstp_spe_1>0){
01940       tz_stp_spe_1 = new TMultiGraph();
01941       tz_stp_spe_1->SetName("tz_stp_spe_1");
01942     }
01943     if(nstp_spe_1>0){  
01944       TGraph *temp = new TGraph(nstp_spe_1,stp_z_spe_1,stp_tpos_spe_1);
01945       temp->SetMarkerColor(3);
01946       temp->SetMarkerSize(1.1);
01947       temp->SetMarkerStyle(8);
01948       tz_stp_spe_1->Add(temp);
01949     }
01950   
01951     delete [] stp_tpos_big_0;
01952     delete [] stp_tpos_mid_0;
01953     delete [] stp_tpos_spe_0;
01954     delete [] stp_z_big_0;
01955     delete [] stp_z_mid_0;
01956     delete [] stp_z_spe_0;
01957     
01958     delete [] stp_tpos_big_1;
01959     delete [] stp_tpos_mid_1;
01960     delete [] stp_tpos_spe_1;
01961     delete [] stp_z_big_1;
01962     delete [] stp_z_mid_1;
01963     delete [] stp_z_spe_1;
01964   
01965     if(lowest_plane-10>=0) {
01966       lowest_plane-=10;
01967       lowest_z-=10.*0.06;
01968     }
01969     else {
01970       lowest_plane=0;
01971       lowest_z=0.;
01972     }
01973     
01974     if(highest_plane+10<=485) {
01975       highest_plane+=10;
01976       highest_z+=10.*0.06;
01977     }
01978     else {
01979       highest_plane=485;
01980       highest_z=30.;
01981     }
01982     
01983     if(lowest_t0-5*0.041>=-4.0) lowest_t0-=5.*0.041;
01984     else lowest_t0=-4.0;
01985     
01986     if(lowest_t1-5*0.041>=-4.0) lowest_t1-=5.*0.041;
01987     else lowest_t1=-4.0;
01988     
01989     if(highest_t0+5*0.041<=4.0) highest_t0+=5.*0.041;
01990     else highest_t0=4.0;
01991     
01992     if(highest_t1+5*0.041<=4.0) highest_t1+=5.*0.041;
01993     else highest_t1=4.0;
01994  
01996   //Start making Reco plots for showers and tracks:
01997 
01998   //make sure there is a reconstructed event
01999   if(isReco&&eventSummary->nevent!=0){ //begin of reco code
02000 
02002     //Showers
02003     
02004     //make sure there is a shower
02005     if(ntpEvent->nshower>0){ //begin of shower code
02006       
02007       if(!tz_shw0) {
02008         tz_shw0 = new TMultiGraph();
02009         tz_shw0->SetName("tz_shw0");
02010       }
02011       if(!tz_shw1){
02012         tz_shw1 = new TMultiGraph();
02013         tz_shw1->SetName("tz_shw1");
02014       }
02015       if(!xz_shw){
02016         xz_shw = new TMultiGraph();
02017         xz_shw->SetName("xz_shw");
02018       }
02019       if(!yz_shw){
02020         yz_shw = new TMultiGraph();
02021         yz_shw->SetName("yz_shw");
02022       }
02023       if(!yx_shw){
02024         yx_shw = new TMultiGraph();
02025         yx_shw->SetName("yx_shw");
02026       }
02027       if(!ztime) {
02028         ztime = new TMultiGraph();
02029         ztime->SetName("ztime");
02030         ztime->SetTitle("Time vs Z view");      
02031       }
02032       if(!ytime){
02033         ytime = new TMultiGraph();
02034         ytime->SetName("ytime");
02035         ytime->SetTitle("Time vs Y view");
02036       }
02037 
02038       int *showers = ntpEvent->shw;
02039       
02040       int numshwstp=0;
02041       int numshwstp0=0;
02042       int numshwstp1=0;
02043 
02044       for(int i=0;i<ntpEvent->nshower;i++){
02045         int index = showers[i];
02046         LoadShower(index);
02047         numshwstp += ntpShower->nstrip;
02048       }
02049 
02050       float *shw_tpos = new float[numshwstp];      
02051       float *shw_tpos0 = new float[numshwstp];
02052       float *shw_z0 = new float[numshwstp];
02053       float *shw_tpos1 = new float[numshwstp];
02054       float *shw_z1 = new float[numshwstp];
02055       float *shwstpx = new float[numshwstp];
02056       float *shwstpy = new float[numshwstp];
02057       float *shwstpz = new float[numshwstp];
02058       double *shw_time = new double[numshwstp];
02059       double *shw_y = new double[numshwstp];
02060       double *shw_z = new double[numshwstp];
02061       int count = 0;
02062       int largest_shw_index=-1;
02063       int vtx_shw_index=-1;
02064       
02065       LoadShower_Jim(theEvent,vtx_shw_index,ntpHeader->GetVldContext().GetDetector());
02066       
02067       LoadLargestShowerFromEvent(theEvent,largest_shw_index);
02068       /*
02069       {
02070         int track_index=-1;
02071         LoadLargestTrackFromEvent(theEvent,track_index);
02072         if(track_index>-1) LoadShowerAtTrackVertex(theEvent,track_index,vtx_shw_index);
02073       }
02074       */
02075       for(int i=0;i<ntpEvent->nshower;i++){
02076         int index1 = showers[i];
02077         LoadShower(index1);
02078         Int_t *shwstrips = ntpShower->stp;
02079 
02080         count=0;
02081         numshwstp0=0;
02082         numshwstp1=0;
02083       
02084         for(int j=0;j<ntpShower->nstrip;j++){
02085           Int_t index = shwstrips[j];
02086           if(index==-1) {numshwstp=0; break;} //bug in old ntuple code
02087           ntpStrip = dynamic_cast<NtpSRStrip *>(stripArray[index]);
02088           
02089           shw_tpos[count] = ntpStrip->tpos;
02090           shw_z[count] = ntpStrip->z;
02091 
02092           if(ntpStrip->time0>0 && 
02093              ntpStrip->time1>0) shw_time[count] = (ntpStrip->time0 + 
02094                                                    ntpStrip->time1)/2.;
02095           else if(ntpStrip->time0>0) shw_time[count] = ntpStrip->time0;
02096           else if(ntpStrip->time1>0) shw_time[count] = ntpStrip->time1;
02097           else shw_time[count] = 0;
02098           /*
02099             if(ntpStrip->time0>0 && 
02100             ntpStrip->time1>0) shw_time[count] = (ntpShower->stpt0[j] + 
02101             ntpShower->stpt1[j])/2.;
02102             else if(ntpStrip->time0>0) shw_time[count] = ntpShower->stpt0[j];
02103             else if(ntpStrip->time1>0) shw_time[count] = ntpShower->stpt1[j];
02104             else shw_time[count] = 0;
02105             }
02106           */
02107           shw_time[count] -= eventSummary->trigtime;
02108           shw_time[count] *= 1e9;
02109 
02110           float shwstpu = 0;
02111           float shwstpv = 0;
02112 
02113           if(ntpStrip->planeview==2){
02114             shw_tpos0[numshwstp0] = shw_tpos[count];
02115             shw_z0[numshwstp0] = shw_z[count];
02116             numshwstp0+=1;
02117             shwstpu = shw_tpos[count];
02118             float grad = 0;
02119             if(ntpShower->vtx.dcosv!=0&&false) {
02120               grad = ntpShower->vtx.dcosz/ntpShower->vtx.dcosv;
02121             }
02122             shwstpv = ntpShower->vtx.v+(shw_z[count]-ntpShower->vtx.z)*grad;
02123             //shwstpv = ntpShower->stpv[j];
02124           }
02125           else {
02126             shw_tpos1[numshwstp1] = shw_tpos[count];
02127             shw_z1[numshwstp1] = shw_z[count];
02128             numshwstp1+=1;
02129             shwstpv = shw_tpos[count];
02130             float grad = 0;
02131             if(ntpShower->vtx.dcosu!=0&&false) {
02132               grad = ntpShower->vtx.dcosz/ntpShower->vtx.dcosu;
02133             }
02134             shwstpu = ntpShower->vtx.u+(shw_z[count]-ntpShower->vtx.z)*grad;
02135             //shwstpu = ntpShower->stpu[j];
02136           }
02137           shwstpx[count] = (shwstpu-shwstpv)/sqrt(2.);
02138           shwstpy[count] = (shwstpu+shwstpv)/sqrt(2.);
02139           shwstpz[count] = shw_z[count];
02140           shw_y[count]   = shwstpy[count];
02141           count++;
02142         }
02143         // largest ph shower will have color 5 by default
02144         // users can change this default via SetDefaultShowerMarkerColor()
02145         // others, a purplish-brown
02146         fDefaultShowerMarkerStyle=28;
02147         fDefaultShowerMarkerColor=6;
02148         int shw_marker_color=1;
02149         // vertex shower will have open circles, other open squares by default
02150         // users can change the default via SetDefaultShowerMarkerStyle()
02151         int shw_marker_style=25;
02152         if(largest_shw_index==index1) shw_marker_color = fDefaultShowerMarkerColor;
02153         if(vtx_shw_index==index1) shw_marker_style=fDefaultShowerMarkerStyle;
02154         if(numshwstp0>0){
02155           TGraph *temp = new TGraph(numshwstp0,shw_z0,shw_tpos0);
02156           temp->SetMarkerColor(shw_marker_color);
02157           temp->SetMarkerSize(1.15);
02158           temp->SetMarkerStyle(shw_marker_style);
02159           tz_shw0->Add(temp);
02160           temp = new TGraph(1,&ntpShower->vtx.z,&ntpShower->vtx.u);
02161           temp->SetMarkerColor(shw_marker_color);
02162           temp->SetMarkerSize(1);
02163           temp->SetMarkerStyle(3);
02164           tz_shw0->Add(temp);   
02165         }
02166         else {
02167           delete tz_shw0;
02168           tz_shw0 = NULL;
02169         }
02170         
02171         if(numshwstp1>0){
02172           TGraph *temp = new TGraph(numshwstp1,shw_z1,shw_tpos1);
02173           temp->SetMarkerColor(shw_marker_color);
02174           temp->SetMarkerSize(1.15);
02175           temp->SetMarkerStyle(shw_marker_style);
02176           tz_shw1->Add(temp);
02177           temp = new TGraph(1,&ntpShower->vtx.z,&ntpShower->vtx.v);
02178           temp->SetMarkerColor(shw_marker_color);
02179           temp->SetMarkerSize(1);
02180           temp->SetMarkerStyle(3);
02181           tz_shw1->Add(temp);
02182         }
02183         else {
02184           delete tz_shw1;
02185           tz_shw1 = NULL;
02186         }
02187 
02188         if(count>0){
02189           TGraph *temp = new TGraph(count,shwstpz,shwstpx);
02190           temp->SetMarkerColor(fDefaultShowerMarkerColor);
02191           temp->SetMarkerSize(0.6);
02192           temp->SetMarkerStyle(fDefaultShowerMarkerStyle);
02193           xz_shw->Add(temp);
02194           
02195           temp = new TGraph(count,shwstpz,shwstpy);
02196           temp->SetMarkerColor(fDefaultShowerMarkerColor);
02197           temp->SetMarkerSize(0.6);
02198           temp->SetMarkerStyle(fDefaultShowerMarkerStyle);
02199           yz_shw->Add(temp);
02200           
02201           temp = new TGraph(count,shwstpx,shwstpy);
02202           temp->SetMarkerColor(fDefaultShowerMarkerColor);
02203           temp->SetMarkerSize(0.6);
02204           temp->SetMarkerStyle(fDefaultShowerMarkerStyle);
02205           yx_shw->Add(temp);
02206 
02207           temp = new TGraph(count,shw_z,shw_time);
02208           temp->SetMarkerColor(fDefaultShowerMarkerColor);
02209           temp->SetMarkerSize(0.6);
02210           temp->SetMarkerStyle(fDefaultShowerMarkerStyle);
02211           ztime->Add(temp);
02212 
02213           temp = new TGraph(count,shw_y,shw_time);
02214           temp->SetMarkerColor(fDefaultShowerMarkerColor);
02215           temp->SetMarkerSize(0.6);
02216           temp->SetMarkerStyle(fDefaultShowerMarkerStyle);    
02217           ytime->Add(temp);
02218         }
02219       }
02220     
02221       delete [] shw_tpos;
02222       delete [] shw_tpos0;
02223       delete [] shw_z0;
02224       delete [] shw_tpos1;
02225       delete [] shw_z1;
02226       delete [] shwstpx;
02227       delete [] shwstpy;
02228       delete [] shwstpz;
02229       delete [] shw_time;
02230       delete [] shw_y;
02231       delete [] shw_z; 
02232       
02233     }
02234   
02236       //Clusters
02237 
02238     //make sure there is a cluster (by checking that there's a shower)
02239     if(LeClus&&ntpEvent->nshower>0){  //begin of cluster code
02240 
02241       if(!tz_clu0){
02242         tz_clu0 = new TMultiGraph();
02243         tz_clu0->SetName("tz_clu0");
02244       }
02245       if(!tz_clu1){
02246         tz_clu1 = new TMultiGraph();
02247         tz_clu1->SetName("tz_clu1");
02248       }
02249       if(!cluLeg0)
02250         cluLeg0 = new TLegend(0.85,0.7,0.98,0.98,"  Key: ID (P_{EM})");
02251       if(!cluLeg1)
02252         cluLeg1 = new TLegend(0.85,0.7,0.98,0.98,"  Key: ID (P_{EM})");
02253     
02254       int nUclus = 0;
02255       int col0 = 1;
02256       int nVclus = 0;
02257       int col1 = 1;
02258       
02259       int *showers = ntpEvent->shw;
02260       for(int i=0;i<ntpEvent->nshower;i++){
02261         int index2 = showers[i];
02262         LoadShower(index2);
02263                 
02264         int *clusters = ntpShower->clu;
02265         int numclustp=0;
02266         int numclustp0=0;
02267         int numclustp1=0;
02268         
02269         for(int j=0;j<ntpShower->ncluster;j++){
02270           int index1 = clusters[j];
02271           if(LoadCluster(index1)) {
02272             numclustp+=ntpCluster->nstrip;
02273             if(ntpCluster->planeview==2) nUclus+=1;
02274             else if(ntpCluster->planeview==3) nVclus+=1;
02275           }
02276         }
02277       
02278         float *clu_tpos = new float[numclustp];
02279         float *clu_tpos0 = new float[numclustp];
02280         float *clu_z0 = new float[numclustp];
02281         float *clu_tpos1 = new float[numclustp];
02282         float *clu_z1 = new float[numclustp];
02283         double *clu_z = new double[numclustp];
02284         int count = 0;
02285 
02286         for(int j=0;j<ntpShower->ncluster;j++){
02287           int index1 = clusters[j];
02288           if(!LoadCluster(index1)) continue;
02289           Int_t *clustrips = ntpCluster->stp;
02290 
02291           count=0;
02292           numclustp0=0;
02293           numclustp1=0;
02294 
02295           for(int k=0;k<ntpCluster->nstrip;k++){
02296             Int_t index = clustrips[k];
02297             ntpStrip = dynamic_cast<NtpSRStrip *>(stripArray[index]);
02298 
02299             clu_tpos[count] = ntpStrip->tpos;
02300             clu_z[count]    = ntpStrip->z;
02301 
02302             if(ntpStrip->planeview==2){
02303               clu_tpos0[numclustp0] = clu_tpos[count];
02304               clu_z0[numclustp0] = clu_z[count];
02305               numclustp0+=1;
02306             }
02307             else {
02308               clu_tpos1[numclustp1] = clu_tpos[count];
02309               clu_z1[numclustp1] = clu_z[count];
02310               numclustp1+=1;
02311             }
02312             count++;
02313           }
02314               
02315           if(numclustp0>0){
02316             TGraph *temp = new TGraph(numclustp0,clu_z0,clu_tpos0);
02317             if(col0==10) col0+=1;
02318             temp->SetMarkerColor(col0);
02319             temp->SetMarkerSize(0.6);
02320             temp->SetMarkerStyle(21);
02321             if(ntpCluster->id==2 || 
02322                ntpCluster->id==4) temp->SetMarkerStyle(25);
02323             tz_clu0->Add(temp);
02324             col0+=1;
02325             char ssnom[256];
02326             if(ntpCluster->id==0||ntpCluster->id==1){
02327               sprintf(ssnom,"%s (%.2f)",
02328                       ClusterType::AsString(ClusterType::
02329                                             EClusterType(ntpCluster->id)),
02330                       ntpCluster->probem);
02331             }
02332             else {
02333               sprintf(ssnom,"%s",
02334                       ClusterType::AsString(ClusterType::
02335                                             EClusterType(ntpCluster->id)));
02336             }
02337             cluLeg0->AddEntry(temp,ssnom,"p");
02338           }
02339         
02340           if(numclustp1>0){
02341             if(col1==10) col1+=1;
02342             TGraph *temp = new TGraph(numclustp1,clu_z1,clu_tpos1);
02343             temp->SetMarkerColor(col1);
02344             temp->SetMarkerSize(0.6);
02345             temp->SetMarkerStyle(21);
02346             if(ntpCluster->id==2 || 
02347                ntpCluster->id==4) temp->SetMarkerStyle(25);
02348             tz_clu1->Add(temp);
02349             col1+=1;
02350             char ssnom[256];
02351             if(ntpCluster->id==0||ntpCluster->id==1){
02352               sprintf(ssnom,"%s (%.2f)",
02353                       ClusterType::AsString(ClusterType::
02354                                             EClusterType(ntpCluster->id)),
02355                       ntpCluster->probem);
02356             }
02357             else {
02358               sprintf(ssnom,"%s",
02359                       ClusterType::AsString(ClusterType::
02360                                             EClusterType(ntpCluster->id)));
02361             }
02362             cluLeg1->AddEntry(temp,ssnom,"p");
02363           }
02364         }
02365         
02366         delete [] clu_tpos;
02367         delete [] clu_z;
02368         delete [] clu_tpos0;
02369         delete [] clu_z0;
02370         delete [] clu_tpos1;
02371         delete [] clu_z1;
02372         
02373       }
02374       if(nUclus==0) {
02375         delete tz_clu0;
02376         tz_clu0=NULL;
02377       }
02378       if(nVclus==0) {
02379         delete tz_clu1;
02380         tz_clu1=NULL;
02381       }
02382     }
02383       
02385     if(isEM){ //make sure there is an EM chain
02386     
02387       //make sure there is a shower
02388       if(ntpEMSummary->nshower!=0){ 
02389 
02390         if(!tz_emshw0){
02391           tz_emshw0 = new TMultiGraph();
02392           tz_emshw0->SetName("tz_emshw0");
02393         }
02394         if(!tz_emshw1){
02395           tz_emshw1 = new TMultiGraph();
02396           tz_emshw1->SetName("tz_emshw1");
02397         }
02398         int numemshwstp=0;
02399         int numemshwstp0=0;
02400         int numemshwstp1=0;
02401         
02402         for(int i=0;i<ntpEMSummary->nshower;i++){
02403           LoadEMShower(i);
02404           numemshwstp += ntpEMShower->nstrip;
02405         }
02406         
02407         float *emshw_tpos = new float[numemshwstp];
02408         float *emshw_z = new float[numemshwstp];
02409         float *emshw_tpos0 = new float[numemshwstp];
02410         float *emshw_z0 = new float[numemshwstp];
02411         float *emshw_tpos1 = new float[numemshwstp];
02412         float *emshw_z1 = new float[numemshwstp];
02413         int count = 0;
02414         
02415         for(int i=0;i<ntpEMSummary->nshower;i++){
02416           LoadEMShower(i);
02417           Int_t *emshwstrips = ntpEMShower->stp;
02418           count=0;
02419           numemshwstp0=0;
02420           numemshwstp1=0;
02421           for(int j=0;j<ntpEMShower->nstrip;j++){
02422             Int_t index = emshwstrips[j];
02423             ntpStrip = dynamic_cast<NtpSRStrip *>(stripArray[index]);
02424             emshw_tpos[count] = ntpStrip->tpos;
02425             emshw_z[count] = ntpStrip->z;
02426             if(ntpStrip->planeview==2){
02427               emshw_tpos0[numemshwstp0] = emshw_tpos[count];
02428               emshw_z0[numemshwstp0] = emshw_z[count];
02429               numemshwstp0+=1;
02430             }
02431             else {
02432               emshw_tpos1[numemshwstp1] = emshw_tpos[count];
02433               emshw_z1[numemshwstp1] = emshw_z[count];
02434               numemshwstp1+=1;
02435             }
02436             count++;
02437           }
02438 
02439           if(numemshwstp0>0){
02440             TGraph *temp = new TGraph(numemshwstp0,emshw_z0,emshw_tpos0);
02441             temp->SetMarkerColor(6);
02442             temp->SetMarkerSize(0.6);
02443             temp->SetMarkerStyle(28);
02444             tz_emshw0->Add(temp);
02445           }
02446           else {
02447             delete tz_emshw0;
02448             tz_emshw0 = NULL;
02449           }
02450 
02451           if(numemshwstp1>0){
02452             TGraph *temp = new TGraph(numemshwstp1,emshw_z1,emshw_tpos1);
02453             temp->SetMarkerColor(6);
02454             temp->SetMarkerSize(0.6);
02455             temp->SetMarkerStyle(28);
02456             tz_emshw1->Add(temp);
02457           }
02458           else {
02459             delete tz_emshw1;
02460             tz_emshw1 = NULL;
02461           }
02462         }
02463         delete [] emshw_tpos;
02464         delete [] emshw_z;
02465         delete [] emshw_tpos0;
02466         delete [] emshw_z0;
02467         delete [] emshw_tpos1;
02468         delete [] emshw_z1;
02469       }
02470     }
02471   
02473     //Tracks
02474   
02475     if(ntpEvent->ntrack>0){ //begin of track code
02476       if(!tz_trk0){
02477         tz_trk0 = new TMultiGraph();
02478         tz_trk0->SetName("tz_trk0");
02479       }
02480       if(!tz_trk1){
02481         tz_trk1 = new TMultiGraph();
02482         tz_trk1->SetName("tz_trk1");
02483       }
02484       if(!xz_trk){
02485         xz_trk = new TMultiGraph();
02486         xz_trk->SetName("xz_trk");
02487       }
02488       if(!yz_trk){
02489         yz_trk = new TMultiGraph();
02490         yz_trk->SetName("yz_trk");
02491       }
02492       if(!yx_trk){
02493         yx_trk = new TMultiGraph();
02494         yx_trk->SetName("yx_trk");
02495       }
02496       if(!ztime){
02497         ztime = new TMultiGraph();
02498         ztime->SetName("ztime");
02499         ztime->SetTitle("Time vs Z view");
02500       }
02501       if(!ytime){
02502         ytime = new TMultiGraph();
02503         ytime->SetName("ytime");
02504         ytime->SetTitle("Time vs Y view");
02505       }
02506     
02507       int *tracks = ntpEvent->trk;
02508       
02509       int totnumtrkstp = 0;
02510       int numtrkstpcnt = 0;
02511       int numtrkstp0 = 0;
02512       int numtrkstp1 = 0;
02513     
02514       for(int itrk=0;itrk<ntpEvent->ntrack;itrk++) {
02515         int index = tracks[itrk];
02516         LoadTrack(index);
02517         totnumtrkstp += ntpTrack->nstrip;
02518       }
02519     
02520       //just in case there are no strips in the track
02521       if(totnumtrkstp!=0) { 
02522         
02523         float *trk_tpos = new float[totnumtrkstp];
02524         float *trk_tpos0 = new float[totnumtrkstp];
02525         float *trk_tpos1 = new float[totnumtrkstp];
02526         float *trkstpz0 = new float[totnumtrkstp];
02527         float *trkstpz1 = new float[totnumtrkstp];
02528         
02529         float *trkstpx = new float[totnumtrkstp];
02530         float *trkstpy = new float[totnumtrkstp];
02531         float *trkstpz = new float[totnumtrkstp];
02532         
02533         int alpha = 0;
02534         double *trk_time = new double[totnumtrkstp*2];
02535         double *trk_y = new double[totnumtrkstp*2];
02536         double *trk_z = new double[totnumtrkstp*2];
02537       
02538         for(int itrk=0;itrk<ntpEvent->ntrack;itrk++){
02539           
02540           int index1 = tracks[itrk];
02541           LoadTrack(index1);
02542         
02543           int numtrkstp = ntpTrack->nstrip;
02544         
02545           float *trk_stp_x = ntpTrack->stpx;
02546           float *trk_stp_y = ntpTrack->stpy;
02547           float *trk_stp_z = ntpTrack->stpz;
02548         
02549           double *trkstpt0 = ntpTrack->stpt0;
02550           double *trkstpt1 = ntpTrack->stpt1;
02551           
02552           int *trkstrips = ntpTrack->stp;
02553           numtrkstpcnt=0;
02554           numtrkstp0=0;
02555           numtrkstp1=0;
02556           alpha=0;
02557         
02558           for(int i=0;i<numtrkstp;i++){
02559             int index = trkstrips[i];
02560             ntpStrip = dynamic_cast<NtpSRStrip *>(stripArray[index]);
02561             
02562             trkstpx[numtrkstpcnt] = trk_stp_x[i];
02563             trkstpy[numtrkstpcnt] = trk_stp_y[i];
02564             trkstpz[numtrkstpcnt] = trk_stp_z[i];
02565             trk_tpos[numtrkstpcnt] = ntpStrip->tpos;
02566             numtrkstpcnt++;
02567             
02568             if(ntpStrip->planeview==2){
02569               trk_tpos0[numtrkstp0] = ntpStrip->tpos;
02570               trkstpz0[numtrkstp0] = trk_stp_z[i];
02571               numtrkstp0+=1;
02572             }
02573             else {
02574               trk_tpos1[numtrkstp1] = ntpStrip->tpos;
02575               trkstpz1[numtrkstp1] = trk_stp_z[i];
02576               numtrkstp1+=1;
02577             }
02578           }
02579           
02580           for(int i=0;i<numtrkstp;i++){
02581             if(trkstpt0[i]!=-999999){
02582               trk_time[alpha] = 1e9*(trkstpt0[i]-eventSummary->trigtime);
02583               trk_z[alpha] = trk_stp_z[i];
02584               trk_y[alpha] = trk_stp_y[i];
02585               alpha+=1;
02586             }
02587             if(trkstpt1[i]!=-999999){
02588               trk_time[alpha] = 1e9*(trkstpt1[i]-eventSummary->trigtime);
02589               trk_z[alpha] = trk_stp_z[i];
02590               trk_y[alpha] = trk_stp_y[i];
02591               alpha+=1;
02592             }
02593           }
02594 
02595           TGraph *temp = 0;
02596           if(numtrkstp0>0){
02597             temp = new TGraph(numtrkstp0,trkstpz0,trk_tpos0);
02598             temp->SetMarkerColor(2);
02599             temp->SetMarkerSize(0.6);
02600             temp->SetMarkerStyle(8);
02601             tz_trk0->Add(temp);
02602             temp = new TGraph(1,&ntpTrack->vtx.z,&ntpTrack->vtx.u);
02603             temp->SetMarkerColor(2);
02604             temp->SetMarkerSize(1);
02605             temp->SetMarkerStyle(29);
02606             tz_trk0->Add(temp); 
02607           }
02608           else {
02609             delete tz_trk0;
02610             tz_trk0 = NULL;
02611           }
02612           
02613           if(numtrkstp1>0){
02614             temp = new TGraph(numtrkstp1,trkstpz1,trk_tpos1);
02615             temp->SetMarkerColor(2);
02616             temp->SetMarkerSize(0.6);
02617             temp->SetMarkerStyle(8);
02618             tz_trk1->Add(temp);
02619             temp = new TGraph(1,&ntpTrack->vtx.z,&ntpTrack->vtx.v);
02620             temp->SetMarkerColor(2);
02621             temp->SetMarkerSize(1);
02622             temp->SetMarkerStyle(29);
02623             tz_trk1->Add(temp); 
02624           }
02625           else {
02626             delete tz_trk1;
02627             tz_trk1 = NULL;
02628           }
02629         
02630           if(numtrkstpcnt>0){
02631             temp = new TGraph(numtrkstpcnt,trkstpz,trkstpx);
02632             temp->SetMarkerColor(2);
02633             temp->SetMarkerSize(0.6);
02634             temp->SetMarkerStyle(8);
02635             xz_trk->Add(temp);
02636             
02637             temp = new TGraph(numtrkstpcnt,trkstpz,trkstpy);
02638             temp->SetMarkerColor(2);
02639             temp->SetMarkerSize(0.6);
02640             temp->SetMarkerStyle(8);
02641             yz_trk->Add(temp);
02642             
02643             temp = new TGraph(numtrkstpcnt,trkstpx,trkstpy);
02644             temp->SetMarkerColor(2);
02645             temp->SetMarkerSize(0.6);
02646             temp->SetMarkerStyle(8);
02647             yx_trk->Add(temp);
02648           }
02649 
02650           if(alpha>0){
02651             temp = new TGraph(alpha,trk_z,trk_time);
02652             temp->SetMarkerColor(2);
02653             temp->SetMarkerSize(0.6);
02654             temp->SetMarkerStyle(8);
02655             ztime->Add(temp);   
02656             
02657             temp = new TGraph(alpha,trk_y,trk_time);
02658             temp->SetMarkerColor(2);
02659             temp->SetMarkerSize(0.6);
02660             temp->SetMarkerStyle(8);    
02661             ytime->Add(temp);
02662           }
02663         }
02664       
02665         delete [] trkstpx;
02666         delete [] trkstpy;
02667         delete [] trkstpz;
02668         delete [] trk_tpos;
02669         delete [] trk_tpos0;
02670         delete [] trk_tpos1;
02671         delete [] trkstpz0;
02672         delete [] trkstpz1;
02673         delete [] trk_time;
02674         delete [] trk_y;
02675         delete [] trk_z; 
02676         
02677       }
02678     }
02679   } //end of reco code
02680   
02681   //Veto Shield
02682   if(!yx_veto) {
02683     yx_veto = new TMultiGraph();
02684     yx_veto->SetName("yx_veto");
02685   }
02686   if(!ytime_veto) {
02687     ytime_veto = new TMultiGraph();
02688     ytime_veto->SetName("ytime_veto");
02689   }
02690 
02691   if(shieldstripArray.GetEntries()!=0&&shieldSummary->ishit){
02692     int nvetostp = shieldstripArray.GetEntries();    
02693     double *vetostp_x = new double[nvetostp];
02694     double *vetostp_y = new double[nvetostp];
02695     double *veto_y = new double[nvetostp*2];
02696     double *veto_time = new double[nvetostp*2];
02697     int beta = 0;
02698     
02699     for(int i=0;i<nvetostp;i++) {
02700       ntpShieldStrip = dynamic_cast<NtpSRShieldStrip *>(shieldstripArray[i]);
02701       vetostp_x[i] = ntpShieldStrip->x;
02702       vetostp_y[i] = ntpShieldStrip->y;
02703       
02704       veto_time[beta] = ntpShieldStrip->time[0];
02705       veto_y[beta] = vetostp_y[i];
02706       beta+=1;
02707       
02708       veto_time[beta] = ntpShieldStrip->time[1];
02709       veto_y[beta] = vetostp_y[i];
02710       beta+=1;      
02711     }
02712     
02713     TGraph *temp1 = new TGraph(nvetostp,vetostp_x,vetostp_y);
02714     temp1->SetMarkerColor(7);
02715     temp1->SetMarkerSize(0.6);
02716     temp1->SetMarkerStyle(8);
02717     yx_veto->Add(temp1);
02718 
02719     TGraph *temp2 = new TGraph(beta,veto_y,veto_time);
02720     temp2->SetMarkerColor(7);
02721     temp2->SetMarkerSize(0.6);
02722     temp2->SetMarkerStyle(8);
02723     ytime_veto->Add(temp2);
02724     
02725     delete [] vetostp_x;
02726     delete [] vetostp_y;
02727     delete [] veto_time;
02728     delete [] veto_y;
02729   }
02730   else {
02731     delete yx_veto; yx_veto = NULL;
02732     delete ytime_veto; ytime_veto = NULL;
02733   }
02734 
02736   //Truth Angles
02737   if(false){ 
02738     TArrow *tz_arrow1 = 0;     // arrows to show direction of
02739     TArrow *tz_arrow2 = 0;     // neutrino in tz view
02740     float nu_mu_angle = 0; // angle between nu and mu P3 vectors in rad
02741     float nu_el_angle = 0; // angle between nu and el P3 vectors in rad
02742     float zen_mu_angle = 0; // angle between mu and zenith P3 vectors in rad
02743     
02744     MainCanvas->cd(1);
02745     gPad->Clear();
02746     
02747     if(isMC){
02748       
02749       TVector3 *nuvec = new TVector3(ntpTruth->p4neunoosc[0],
02750                                      ntpTruth->p4neunoosc[1],
02751                                      ntpTruth->p4neunoosc[2]);
02752       TVector3 *muvec = new TVector3(ntpTruth->p4mu1[0],
02753                                      ntpTruth->p4mu1[1],
02754                                      ntpTruth->p4mu1[2]);
02755       TVector3 *elvec = new TVector3(ntpTruth->p4el1[0],
02756                                      ntpTruth->p4el1[1],
02757                                      ntpTruth->p4el1[2]);
02758       TVector3 *zenith = new TVector3(0,-1,0);
02759       
02760       nu_mu_angle = nuvec->Angle(*muvec);
02761       nu_el_angle = nuvec->Angle(*elvec);
02762       zen_mu_angle = muvec->Angle(*zenith);
02763       
02764       nuvec->RotateZ(-TMath::Pi()/4.);
02765       muvec->RotateZ(-TMath::Pi()/4.);
02766       TVector3 unitnu;
02767       if(ntpTruth->p4neu[3]<0.00001) unitnu = muvec->Unit();
02768       else unitnu = nuvec->Unit();
02769       
02770       float mc_vtxu = ntpTruth->vtxx/(sqrt(2.)) 
02771         + ntpTruth->vtxy/(sqrt(2.));
02772       float mc_vtxv = - ntpTruth->vtxx/(sqrt(2.)) 
02773         + ntpTruth->vtxy/(sqrt(2.));
02774       
02775       
02776       tz_arrow1 = new TArrow(ntpTruth->vtxz-unitnu.Z(),
02777                              mc_vtxu-unitnu.X(),
02778                              ntpTruth->vtxz,mc_vtxu,0.02,"|>");
02779       tz_arrow1->SetFillColor(5);
02780       tz_arrow1->SetLineColor(9);
02781       tz_arrow1->SetLineWidth(2);
02782       
02783       tz_arrow2 = new TArrow(ntpTruth->vtxz-unitnu.Z(),
02784                              mc_vtxv-unitnu.Y(),
02785                              ntpTruth->vtxz,mc_vtxv,0.02,"|>");
02786       tz_arrow2->SetFillColor(5);
02787       tz_arrow2->SetLineColor(9);
02788       tz_arrow2->SetLineWidth(2);
02789       
02790       delete nuvec;
02791       delete muvec;
02792       delete elvec;
02793     }
02794     
02795     //StdHep line drawing code from Tingjun:
02796     //stdhep vectors
02797     TLine** paru = 0;
02798     TLine** parv = 0;
02799     int nstdhep = 0;
02800     int *drawline = 0;
02801     if (isMC&&isTH){
02802       TClonesArray* pointHepArray = NULL;
02803       if(isST) pointHepArray = (strecord->stdhep);
02804       else pointHepArray = (mcrecord->stdhep);
02805       TClonesArray& heparray = *pointHepArray;
02806       nstdhep = heparray.GetLast()+1;
02807       double *vtx_u = new double[nstdhep];
02808       double *vtx_v = new double[nstdhep];
02809       double *vtx_z = new double[nstdhep];
02810       double *p_u = new double[nstdhep];
02811       double *p_v = new double[nstdhep];
02812       double *p_z = new double[nstdhep];
02813       double *p_tot = new double[nstdhep];
02814       double *k_u = new double[nstdhep];
02815       double *k_v = new double[nstdhep];
02816       double *epar = new double[nstdhep];
02817       int *idhep = new int[nstdhep];
02818       drawline = new int[nstdhep];
02819       
02820       if(LoadTHEvent(theEvent)) {
02821         NtpMCStdHep* hep0 = 
02822           dynamic_cast<NtpMCStdHep*>(heparray[ntpTHEvent->neustdhep]);
02823         int currentmc = hep0->mc;
02824         
02825         for (int istd = 0; istd < nstdhep; istd++){
02826           NtpMCStdHep* hep =  dynamic_cast<NtpMCStdHep*>(heparray[istd]);
02827           drawline[istd] = 0;
02828           vtx_u[istd] = (hep->vtx[0]+hep->vtx[1])*sqrt(2.)/2;
02829           vtx_v[istd] = (hep->vtx[1]-hep->vtx[0])*sqrt(2.)/2;
02830           vtx_z[istd] = hep->vtx[2];
02831           
02832           p_u[istd] = (hep->p4[0]+hep->p4[1])*sqrt(2.)/2;
02833           p_v[istd] = (hep->p4[1]-hep->p4[0])*sqrt(2.)/2;
02834           p_z[istd] = hep->p4[2];
02835           p_tot[istd] = sqrt(p_u[istd]*p_u[istd] + p_v[istd]*p_v[istd] + 
02836                              p_z[istd]*p_z[istd]);
02837           
02838           epar[istd] = hep->p4[3];
02839           idhep[istd] = abs(hep->IdHEP);
02840           if (fabs(p_z[istd])>0.) {
02841             k_u[istd] = p_u[istd]/p_z[istd];
02842             k_v[istd] = p_v[istd]/p_z[istd];
02843           }
02844           
02845           bool drawphoton = false;
02846           if (abs(hep->IdHEP)==22){//photon
02847             NtpMCStdHep*hep_parent = 
02848               dynamic_cast<NtpMCStdHep*>(heparray[hep->parent[0]]);
02849             if (abs(hep_parent->IdHEP)!=111) drawphoton = true;
02850           }
02851           //decide what to draw
02852           /*
02853             if((hep->mc==currentmc && hep->child[0]==-1 && hep->child[1]==-1 &&
02854             abs(hep->IdHEP)<10000 && 
02855             (abs(hep->IdHEP)==22 && drawphoton || abs(hep->IdHEP)!=22)) || 
02856             (hep->mc==currentmc && abs(hep->IdHEP)==111)) drawline[istd]=1;
02857             if(p_tot[istd]<=0) drawline[istd]=0;
02858           */
02859           if(hep->mc==currentmc){
02860             hep->Print();
02861             // draw all final state particles except photons from pi0 decay
02862             if(hep->IstHEP==1 && hep->IdHEP<10000){
02863               // do not draw geantinos (probably made by intranuke)
02864               if(hep->IdHEP!=28) drawline[istd]=1;
02865               //            if(hep->IdHEP!=22) drawline[istd]=1;
02866               //            else if(drawphoton) drawline[istd]=1;
02867             }
02868           }
02869         }
02870         paru = new TLine*[nstdhep];
02871         parv = new TLine*[nstdhep];
02872         for (int istd = 0; istd < nstdhep; istd++){
02873           if(p_tot[istd]==0)p_tot[istd]=0.001;
02874           if (drawline[istd] == 1){
02875             paru[istd] = new TLine(vtx_z[istd],vtx_u[istd],
02876                                    vtx_z[istd] + 
02877                                    (p_z[istd]/p_tot[istd])*epar[istd]/3,
02878                                    vtx_u[istd] + 
02879                                    p_u[istd]/p_tot[istd]*epar[istd]/3);
02880             parv[istd] = new TLine(vtx_z[istd],vtx_v[istd],
02881                                    vtx_z[istd] + 
02882                                    (p_z[istd]/p_tot[istd])*epar[istd]/3,
02883                                    vtx_v[istd] + 
02884                                    p_v[istd]/p_tot[istd]*epar[istd]/3);
02885             if(idhep[istd] == 11) {     //electron
02886               paru[istd]->SetLineColor(3);
02887               parv[istd]->SetLineColor(3);
02888             }
02889             else if(idhep[istd] == 13) {//muon
02890               paru[istd]->SetLineColor(4);
02891               parv[istd]->SetLineColor(4);
02892             }
02893             else if(idhep[istd] == 15) {//tau
02894               paru[istd]->SetLineColor(5);
02895               parv[istd]->SetLineColor(5);
02896             }
02897             else if(idhep[istd] == 211){//pion
02898               paru[istd]->SetLineColor(6);
02899               parv[istd]->SetLineColor(6);
02900             }
02901             else if(idhep[istd] == 2212){//proton
02902               paru[istd]->SetLineColor(2);
02903               parv[istd]->SetLineColor(2);
02904             }
02905             else if(idhep[istd] == 111) { //pi0
02906               paru[istd]->SetLineColor(7);
02907               parv[istd]->SetLineColor(7);
02908             }
02909             else if(idhep[istd] == 22){  //photon
02910               paru[istd]->SetLineColor(9);
02911               parv[istd]->SetLineColor(9);
02912             }
02913             else if(idhep[istd] == 2112){//neutron
02914               paru[istd]->SetLineColor(28);
02915               parv[istd]->SetLineColor(28);
02916             }
02917             else if(idhep[istd] == 321 || idhep[istd] == 311 || 
02918                     idhep[istd] == 310 || idhep[istd] == 130){//kaon
02919               paru[istd]->SetLineColor(31);
02920               parv[istd]->SetLineColor(31);
02921             }//anything else will be black
02922             else if(idhep[istd] == 12 || idhep[istd] == 14 ||
02923                     idhep[istd] == 16){  //outgoing neutrino
02924               paru[istd]->SetLineStyle(2); //black, dashed line
02925               parv[istd]->SetLineStyle(2);
02926             }
02927           }
02928         }
02929       }
02930       
02931       delete[] vtx_u;
02932       delete[] vtx_v;
02933       delete[] vtx_z;
02934       delete[] p_u;
02935       delete[] p_v;
02936       delete[] p_z;
02937       delete[] p_tot;
02938       delete[] k_u;
02939       delete[] k_v;
02940       delete[] epar;
02941       delete[] idhep;
02942     }
02943   }
02945   //Text Box
02946   this->DrawTextBox(MainCanvas,isReco);
02947 
02949   //Start Drawing
02950 
02951   RecoCanvas->cd(1);
02952   gPad->Clear();
02953   xz_place->Draw();
02954   if(xz_trk) xz_trk->Draw("P");
02955   if(xz_shw) xz_shw->Draw("P");
02956 
02957   RecoCanvas->cd(4);
02958   gPad->Clear();
02959   yz_place->Draw();
02960   if(yz_trk) yz_trk->Draw("P");
02961   if(yz_shw) yz_shw->Draw("P");
02962 
02963   RecoCanvas->cd(2);
02964   gPad->Clear();
02965 
02966   if(ntpHeader->GetVldContext().GetDetector()==Detector::kNear){
02967     yx_place->GetXaxis()->SetRangeUser(-2.6,3.8);
02968     yx_place->GetYaxis()->SetRangeUser(-3.2,3.2);
02969     
02970   }
02971   else {
02972     yx_place->GetXaxis()->UnZoom();
02973     yx_place->GetYaxis()->UnZoom();
02974   }
02975   yx_place->Draw();  
02976 
02977   if(yx_trk) yx_trk->Draw("P");
02978   if(yx_shw) yx_shw->Draw("P");
02979   if(yx_veto) yx_veto->Draw("P");
02980   // mike: draw plane outlines here
02981   line->Draw();
02982   if(ntpHeader->GetVldContext().GetDetector()==Detector::kNear){
02983     fu1_outline->Draw();
02984     fu2_outline->Draw();
02985     fv1_outline->Draw();
02986     fv2_outline->Draw();
02987     pu1_outline->Draw();
02988     //  pu2_outline->Draw();
02989     pv1_outline->Draw();
02990     //  pv2_outline->Draw();
02991     if(ntpHeader->GetVldContext().GetDetector()==Detector::kNear){ 
02992       nd_xy_fid->Draw();
02993     }
02994     if (ntpHeader->GetVldContext().GetDetector()==Detector::kFar){
02995       fd_xy_fid->Draw();
02996     }
02997 
02998   }
02999 
03000   if(ntpHeader->GetVldContext().GetDetector()==Detector::kFar) 
03001     ellie->Draw();
03002 
03003   RecoCanvas->cd(3);
03004   TVirtualPad *RecoCanvas_3 = RecoCanvas->GetPad(3);
03005   RecoCanvas_3->Clear();
03006 
03007   tz_place_0->SetAxisRange(lowest_z,highest_z,"X");
03008   tz_place_0->SetAxisRange(lowest_t0,highest_t0,"Y");
03009 
03010   if(fAltDisplay){
03011     tz_place_0->Draw(tz_place_dopt.c_str());    
03012     if(tz_stp_0) tz_stp_0->Draw("P");
03013     if(tz_stp_mid_0) tz_stp_mid_0->Draw("P");
03014     if(tz_stp_spe_0) tz_stp_spe_0->Draw("P");
03015     
03016     if(tz_trk0) tz_trk0->Draw("P");
03017     if(tz_shw0) tz_shw0->Draw("P");
03018     if(tz_emshw0) tz_emshw0->Draw("P");
03019   }
03020   else{
03021     tz_missplace_0->SetAxisRange(lowest_missz,highest_missz,"X");
03022     tz_missplace_0->SetAxisRange(lowest_misst0,highest_misst0,"Y");  
03023     tz_missplace_0->Draw(tz_place_dopt.c_str());
03024     if(tz_missstp_0) tz_missstp_0->Draw("P");
03025   }
03026   RecoCanvas_3->Update();
03027   RecoCanvas_3->Modified();
03028 
03029  
03030  RecoCanvas->cd(5);
03031   TVirtualPad *RecoCanvas_5 = RecoCanvas->GetPad(5);
03032   RecoCanvas_5->cd(1);
03033   gPad->Clear();
03034    
03035  if(ytime){
03036     ytime->Draw("AP");
03037     ytime->GetXaxis()->SetTitle("y position (m)");
03038     ytime->GetYaxis()->SetTitle("time (ns)");
03039     if(ytime_veto) ytime_veto->Draw("P");
03040   }
03041   
03042 
03043   gPad->Update();
03044   gPad->Modified();
03045 
03046   RecoCanvas_5->cd(2);
03047   gPad->Clear();
03048   
03049   if(ztime) {
03050     ztime->Draw("AP");
03051     ztime->GetXaxis()->SetTitle("z position (m)");
03052     ztime->GetYaxis()->SetTitle("time (ns)");
03053   }
03054   
03055   gPad->Update();
03056   gPad->Modified();
03057 
03058   RecoCanvas->cd(6);
03059   gPad->Clear(); 
03060   
03061   
03062   tz_place_1->SetAxisRange(lowest_z,highest_z,"X");
03063   tz_place_1->SetAxisRange(lowest_t1,highest_t1,"Y");
03064  
03065   if(fAltDisplay){
03066     tz_place_1->Draw(tz_place_dopt.c_str());   
03067     if(tz_stp_1) tz_stp_1->Draw("P");
03068     if(tz_stp_mid_1) tz_stp_mid_1->Draw("P");
03069     if(tz_stp_spe_1) tz_stp_spe_1->Draw("P");
03070     
03071     if(tz_trk1) tz_trk1->Draw("P");
03072     if(tz_shw1) tz_shw1->Draw("P");
03073     if(tz_emshw1) tz_emshw1->Draw("P");
03074   }
03075   else{
03076     tz_missplace_1->SetAxisRange(lowest_missz,highest_missz,"X");
03077     tz_missplace_1->SetAxisRange(lowest_misst0,highest_misst0,"Y");  
03078     tz_missplace_1->Draw(tz_place_dopt.c_str());
03079     if(tz_missstp_1) tz_missstp_1->Draw("P");
03080   }
03081   gPad->Update();
03082   gPad->Modified();
03083 
03085 
03086   MainCanvas->cd(3);
03087   gPad->Clear();
03088   if(fAltDisplay){
03089     tz_missplace_0->SetAxisRange(lowest_missz,highest_missz,"X");
03090     tz_missplace_0->SetAxisRange(lowest_misst0,highest_misst0,"Y");  
03091     tz_missplace_0->Draw(tz_place_dopt.c_str());
03092     if(tz_missstp_0) tz_missstp_0->Draw("P");
03093 
03094   }
03095   else{
03096     tz_place_0->Draw(tz_place_dopt.c_str());      
03097     if(ntpHeader->GetVldContext().GetDetector()==Detector::kNear){ 
03098       nd_uz_fid->Draw();
03099     }
03100     if (ntpHeader->GetVldContext().GetDetector()==Detector::kFar){
03101       fd_uz_fid1->Draw();
03102       fd_uz_fid2->Draw();
03103 
03104     }
03105     if(nstp_big_0>0) tz_stp_0->Draw("P");
03106     if(nstp_mid_0>0) tz_stp_mid_0->Draw("P");
03107     if(nstp_spe_0>0) tz_stp_spe_0->Draw("P");
03108     
03109     if(tz_trk0) tz_trk0->Draw("P");
03110     if(tz_shw0) tz_shw0->Draw("P");
03111     if(tz_emshw0) tz_emshw0->Draw("P");    
03112   }
03113   /*
03114   if(isMC) {
03115     tz_arrow1->Draw();
03116     if(isTH){
03117       for (int istd = 0; istd < nstdhep; istd++){
03118         if (drawline[istd] == 1 && paru[istd]!=0 ) paru[istd]->Draw("same");
03119       }
03120     }
03121   }
03122   */
03123   gPad->Modified();
03124   gPad->Update();
03125 
03126   MainCanvas->cd(4);
03127   gPad->Clear();
03128   if(fAltDisplay){
03129     tz_missplace_1->SetAxisRange(lowest_missz,highest_missz,"X");
03130     tz_missplace_1->SetAxisRange(lowest_misst0,highest_misst0,"Y");  
03131     tz_missplace_1->Draw(tz_place_dopt.c_str());
03132     if(tz_missstp_1) tz_missstp_1->Draw("P");
03133   }
03134   else{
03135     tz_place_1->Draw(tz_place_dopt.c_str());
03136     if(ntpHeader->GetVldContext().GetDetector()==Detector::kNear){ 
03137       nd_vz_fid->Draw();
03138     }
03139     if (ntpHeader->GetVldContext().GetDetector()==Detector::kFar){
03140       fd_vz_fid1->Draw();
03141       fd_vz_fid2->Draw();
03142 
03143     }
03144     
03145     if(nstp_big_1>0) tz_stp_1->Draw("P");
03146     if(nstp_mid_1>0) tz_stp_mid_1->Draw("P");
03147     if(nstp_spe_1>0) tz_stp_spe_1->Draw("P");
03148     
03149     if(tz_trk1) tz_trk1->Draw("P");
03150     if(tz_shw1) tz_shw1->Draw("P");
03151     if(tz_emshw1) tz_emshw1->Draw("P");
03152   }
03153   /*
03154   if(isMC) {
03155     tz_arrow2->Draw();
03156     if(isTH){
03157       for (int istd = 0; istd < nstdhep; istd++){
03158         if (drawline[istd] == 1 && parv[istd] ) parv[istd]->Draw("same");
03159       }
03160     }
03161   }
03162   */
03164 
03165   if(LeLego) {
03166     tz_0_lego->SetAxisRange(lowest_plane,highest_plane,"X");
03167     tz_1_lego->SetAxisRange(lowest_plane,highest_plane,"X");
03168     tz_0_lego->SetAxisRange(lowest_t0,highest_t0,"Y");
03169     tz_1_lego->SetAxisRange(lowest_t1,highest_t1,"Y");
03170 
03171     LegoCanvas->cd(1);
03172     tz_0_lego->Draw("LEGO2");
03173     gPad->Update();
03174     gPad->Modified();
03175 
03176     LegoCanvas->cd(2);
03177     tz_1_lego->Draw("LEGO2");
03178     gPad->Update();
03179     gPad->Modified();
03180   }
03181 
03183 
03184   if(LeClus){
03185     ClusterCanvas->cd(1);
03186     gPad->Clear();
03187     if(tz_clu0) {
03188       if(tz_clu0->Sizeof()>0){
03189         tz_place_0->Draw(tz_place_dopt.c_str());
03190         tz_clu0->Draw("P");
03191         if(cluLeg0) cluLeg0->Draw();
03192         if(isMC) {
03193           //tz_arrow1->Draw();
03194           if(isTH){
03195             //    for (int istd = 0; istd < nstdhep; istd++){
03196             //   if (drawline[istd] == 1 && paru[istd]) paru[istd]->Draw("same");
03197             //      }
03198           }
03199         }
03200       }
03201     }
03202     gPad->Update();
03203     gPad->Modified();    
03204     
03205 
03206     ClusterCanvas->cd(2);
03207     gPad->Clear();
03208     if(tz_clu1) {
03209       if(tz_clu1->Sizeof()>0){
03210         tz_place_1->Draw(tz_place_dopt.c_str());
03211         tz_clu1->Draw("P");
03212         if(cluLeg1) cluLeg1->Draw();
03213         if(isMC) {
03214           //tz_arrow2->Draw();
03215           if(isTH){
03216             //      for (int istd = 0; istd < nstdhep; istd++){
03217             //  if (drawline[istd] == 1 && parv[istd]) parv[istd]->Draw("same");
03218             //      }
03219           }
03220         }
03221       }
03222     }
03223     gPad->Update();
03224     gPad->Modified();
03225   }
03226 
03227   //delete stdhep 
03228 //  if (isMC&&isTH) delete[] drawline;
03229 
03231   //Print To Terminal
03232 
03233   if(ptt_msg) {
03234 
03235     //    float Sum_mcA = 0;
03236     //  float Sum_mcB = 0;
03237     //for(int i=0;i<500;i++){
03238     //  for(int j=0;j<192;j++){
03239     //    if(ATH_mcA[i][j]>0||ATH_mcB[i][j]>0) {
03240     //  Sum_mcA+=ATH_mcA[i][j];
03241     //  Sum_mcB+=ATH_mcB[i][j];      
03242     //   }
03243     // }
03244     //}
03245     
03246     std::cout << "Run: " << ntpHeader->GetRun() 
03247               << " Snarl: " << ntpHeader->GetSnarl() 
03248               << " (entry: " << entry << ")" << std::endl;
03249     std::cout << "-----------------------------------" << std::endl;
03250     //  std::cout << "Truth:" << std::endl;
03251         //    std::cout << "\tSummed PEs=" << Sum_mcA+Sum_mcB << "\tSummed PEs/0.6=" 
03252         //      << (Sum_mcA+Sum_mcB)/0.6 << std::endl;
03253     std::cout << "-----------------------------------" << std::endl;
03254     std::cout << "Reco:" << std::endl;
03255     std::cout << "\tNumber of slices\t"<< eventSummary->nslice << std::endl;
03256     std::cout << "\tSummed Raw Charge in Snarl (Current Slice) " 
03257               << eventSummary->ph.raw << " (" 
03258               << ntpSlice->ph.raw << ")" << std::endl; 
03259     std::cout << "\tSummed PEs in Snarl (Current Slice) " 
03260               << eventSummary->ph.pe << " (" 
03261               << ntpSlice->ph.pe << ")" << std::endl; 
03262     std::cout << "\tNumber of Reco Digits in Slice = " << ntpSlice->ndigit
03263               << " Strips = " 
03264               << (nstp_spe_0+nstp_spe_1+nstp_mid_0+nstp_mid_1+nstp_big_0
03265                   +nstp_big_1) << std::endl;
03266     std::cout << "===================================" << std::endl;
03267   }
03268 
03269   MainCanvas->cd(2); //change to pad with controls
03270 
03271  // JM add  update scan page
03272   SFrame->SetRun(ntpHeader->GetRun());
03273   SFrame->SetSnarl(ntpHeader->GetSnarl());
03274   SFrame->SetSlice(theSlice);
03275   SFrame->SetEvent(theEvent);
03276   
03277   int shower_index ; int track_index;
03278   if(ntpEvent){
03279     if(ntpEvent->ntrack>0){
03280       LoadLargestTrackFromEvent(theEvent,track_index);
03281       if(ntpTrack->momentum.qp!=0) SFrame->PassFloat("Curv",1./ntpTrack->momentum.qp);
03282       SFrame->PassFloat("Range",ntpTrack->momentum.range);
03283       SFrame->PassInt("TrackContained",ntpTrack->contained);
03284     }
03285     else{
03286       SFrame->PassFloat("Range",0);
03287       SFrame->PassFloat("Curv",0);
03288       SFrame->PassInt("TrackContained",0);
03289     }
03290     if(ntpEvent->nshower>0){
03291       const Detector::Detector_t det = ntpHeader->GetVldContext().GetDetector();
03292       bool OK =LoadShower_Jim(theEvent,shower_index,det);
03293       float cor_shw_energy = 0;
03294       if(OK) cor_shw_energy = CorrectShowerEnergy(ntpShower->shwph.linCCgev,
03295                                                   det,CandShowerHandle::kCC);
03296       
03297       SFrame->PassFloat("ShwE",cor_shw_energy);
03298     }
03299     else{
03300       SFrame->PassFloat("ShwE",0);
03301     }
03302     
03303     SFrame->ResetDisplay("noPH");
03304     //  ROICalc();
03305     MadAbID pid;
03306     bool pass = pid.GetPass(ntpEvent,strecord);
03307     SFrame->PassInt("Passed",pass);
03308   }
03309  //
03310 
03311   // RBP -- for zooming capabilites, we will want the TGraphs and TMultiGraphs
03312   // to be non-editable.  (No need to edit them anyway, I'd think.)
03313   MakeGraphListNonEditable(MainCanvas->GetPad(3)->GetListOfPrimitives());
03314   MakeGraphListNonEditable(MainCanvas->GetPad(4)->GetListOfPrimitives());
03315 
03316   return true;
03317 }
03318 
03319 //*****************************************************************
03320 void MadScanDisplay::DrawTextBox(TCanvas *MainCanvas,Bool_t isReco){
03321   
03322   //recalculate angles:
03323   float nu_mu_angle = 0;
03324   float nu_el_angle = 0;
03325   float zen_mu_angle = 0;
03326   if(isMC){
03327     TVector3 *nuvec = new TVector3(ntpTruth->p4neunoosc[0],
03328                                    ntpTruth->p4neunoosc[1],
03329                                    ntpTruth->p4neunoosc[2]);
03330     TVector3 *muvec = new TVector3(ntpTruth->p4mu1[0],
03331                                    ntpTruth->p4mu1[1],
03332                                    ntpTruth->p4mu1[2]);
03333     TVector3 *elvec = new TVector3(ntpTruth->p4el1[0],
03334                                    ntpTruth->p4el1[1],
03335                                    ntpTruth->p4el1[2]);
03336     TVector3 *zenith = new TVector3(0,-1,0); 
03337     nu_mu_angle = nuvec->Angle(*muvec);
03338     nu_el_angle = nuvec->Angle(*elvec);
03339     zen_mu_angle = muvec->Angle(*zenith);
03340   }
03341 
03342   //Summary
03343   char sometext1[100] = ".";
03344   if(isReco) sprintf(sometext1,
03345                      "Run: %i, Snarl: %i, Slice: %i(/%i), Event %i(/%i)",
03346                      ntpHeader->GetRun(),ntpHeader->GetSnarl(),LeSlice+1,
03347                      eventSummary->nslice,LeEvent+1,eventSummary->nevent);
03348   else sprintf(sometext1,
03349                "Run: %i, Snarl: %i, Slice: %i(/%i), Event %i(/%i)",
03350                ntpHeader->GetRun(),ntpHeader->GetSnarl(),LeSlice+1,
03351                eventSummary->nslice,0,eventSummary->nevent);
03352 
03353   //Truth
03354   char sometext2[100] = "Truth";
03355   char sometext3[100] = "N/A";
03356   char sometext4[100] = "N/A";
03357   char sometext5[100] = "N/A";
03358   char sometext6[100] = "N/A";
03359   char sometext7[100] = "N/A";
03360   char sometext8[100] = "N/A";
03361 
03362   //Reco
03363   char sometext9[100] = "N/A";
03364   char sometext10[100] = "N/A";
03365   char sometext14[100] = "N/A";
03366 
03367   if(isReco&&eventSummary->nevent!=0&&isTH) {
03368     //Slice summary:
03369     LoadTHSlice(LeSlice);
03370     if(ntpTHSlice) sprintf(sometext9,"Reco - Slice (%.3f, %.3f)",
03371                            ntpTHSlice->purity,ntpTHSlice->complete);
03372     else sprintf(sometext9,"Reco");
03373 
03374     //Shower summary:
03375     if(ntpEvent->nshower>0&&ntpTHShower){
03376       if(LoadTHShower(ntpEvent->shw[0])) {
03377           sprintf(sometext14,"     #Shws: %i (%.3f, %.3f)",
03378                 ntpEvent->nshower,ntpTHShower->purity,ntpTHShower->completeall);
03379           SFrame->PassInt("NumShw",ntpEvent->nshower);
03380       }
03381       for(int i=1;i<ntpEvent->nshower;i++){
03382         LoadTHShower(ntpEvent->shw[i]);
03383         if(ntpTHShower) 
03384           sprintf(sometext14,"%s (%.3f, %.3f)",sometext14,ntpTHShower->purity,
03385                   ntpTHShower->completeall);
03386       }
03387     }
03388     else if(ntpEvent->nshower>0) {
03389        sprintf(sometext14,"     #Shws: %i", ntpEvent->nshower);
03390        SFrame->PassInt("NumShw",ntpEvent->nshower);
03391     }
03392     else {
03393       sprintf(sometext14,"     #Shws: 0");
03394       SFrame->PassInt("NumShw",0);
03395     }
03396 
03397     //Track summary:
03398     if(ntpEvent->ntrack>0&&ntpTHTrack){
03399       sprintf(sometext10,"     #Trks: %i (%.3f, %.3f)",
03400               ntpEvent->ntrack,ntpTHTrack->purity,ntpTHTrack->completeall);
03401       SFrame->PassInt("NumTrk",ntpEvent->ntrack);
03402       for(int i=1;i<ntpEvent->ntrack;i++){
03403         LoadTHTrack(ntpEvent->trk[i]);
03404         if(ntpTHTrack) 
03405           sprintf(sometext10,"%s (%.3f, %.3f)",sometext10,ntpTHTrack->purity,
03406                   ntpTHTrack->completeall);
03407       }
03408     }
03409     else if (ntpEvent->ntrack>0) {
03410       sprintf(sometext10,"     #Trks: %i",ntpEvent->ntrack);
03411       SFrame->PassInt("NumTrk",ntpEvent->ntrack);
03412     }
03413     else {
03414       sprintf(sometext10,"     #Trks: 0");
03415       SFrame->PassInt("NumTrk",0);
03416     }
03417   }
03418   
03419   else if(isReco&&eventSummary->nevent!=0){
03420     sprintf(sometext9,"Reco");
03421     sprintf(sometext10,"     #Trks: %i",ntpEvent->ntrack);
03422     SFrame->PassInt("NumTrk",ntpEvent->ntrack);
03423     sprintf(sometext14,"     #Shws: %i",ntpEvent->nshower);
03424     SFrame->PassInt("NumShw",ntpEvent->nshower);
03425   }
03426   else {
03427     sprintf(sometext9,"Reco");
03428     sprintf(sometext10,"     No Reconstruced Event");
03429   }
03430 
03431   //Track values
03432   char sometext11[100] = "N/A";
03433   char sometext12[100] = "N/A";
03434   char sometext13[100] = "N/A";
03435   
03436   if(false){ //if MC
03437     TClonesArray* pointMcArray = NULL;
03438     if(isST) pointMcArray = (strecord->mc);
03439     else pointMcArray = (mcrecord->mc);
03440     TClonesArray& mcArray = *pointMcArray;
03441 
03442     sprintf(sometext2,"Truth - MC: %i(/%i)",LeMCevent+1,
03443             mcArray.GetEntries());
03444     
03445     sprintf(sometext3,"     Nu ID: %i;  NC/CC: %i;  Process: %i",ntpTruth->inu,
03446             ntpTruth->iaction,ntpTruth->iresonance);
03447     
03448     sprintf(sometext7,"     Shw Energy: %f",ntpTruth->p4shw[3]);
03449 
03450     sprintf(sometext8,"     Vtx: %.2f, %.2f, %.2f",ntpTruth->vtxx,
03451             ntpTruth->vtxy,ntpTruth->vtxz);    
03452     
03453     if(abs(ntpTruth->inu)==12){
03454       
03455       sprintf(sometext4,"     Nu E: %.3f;  Elec E*q: %.3f",ntpTruth->p4neu[3],
03456               ntpTruth->p4el1[3]);
03457       
03458       sprintf(sometext5,"     Elec p: %.3f;  Py: %.2f",
03459               sqrt(ntpTruth->p4el1[3]*ntpTruth->p4el1[3])
03460               -(0.000511*0.000511),ntpTruth->p4el1[1]);
03461       
03462       sprintf(sometext6,"     #theta: %.4f rad, %.2f deg",nu_el_angle,
03463               nu_el_angle*180./TMath::Pi());
03464       
03465     }
03466     
03467     else if(abs(ntpTruth->inu)==14){
03468       
03469       sprintf(sometext4,"     Nu E: %.3f;  Mu E*q: %.3f",ntpTruth->p4neu[3],
03470               ntpTruth->p4mu1[3]);
03471       
03472       sprintf(sometext5,"     Mu p: %.3f;  Py: %.2f",
03473               sqrt(ntpTruth->p4mu1[3]*ntpTruth->p4mu1[3])
03474               -(0.10555*0.10555),ntpTruth->p4mu1[1]);
03475       
03476       sprintf(sometext6,"     #theta: %.4f rad, %.2f deg",nu_mu_angle,
03477               nu_mu_angle*180./TMath::Pi());
03478       
03479     }
03480 
03481     else if(ntpTruth->p4neu[3]<0.00001){
03482       
03483       sprintf(sometext4,"     Nu E: %.3f;  Mu E*q: %.3f",ntpTruth->p4neu[3],
03484               ntpTruth->p4mu1[3]);
03485       
03486       sprintf(sometext5,"     Mu p: %.3f;  Py: %.2f",
03487               sqrt(ntpTruth->p4mu1[3]*ntpTruth->p4mu1[3])
03488               -(0.10555*0.10555),ntpTruth->p4mu1[1]);
03489       
03490       sprintf(sometext6,"     Zenith angle: %.4f rad, %.2f deg",zen_mu_angle,
03491               zen_mu_angle*180./TMath::Pi());
03492     }
03493 
03494   }
03495   
03496   if(isReco&&eventSummary->nevent!=0){ //reconstructed event present
03497     const Detector::Detector_t det 
03498       = ntpHeader->GetVldContext().GetDetector();
03499     Float_t cor_shw_energy =0; // corrected shower energy
03500     float best_trk_mom=0.0;// will be range or curvature
03501     int do_meth=0; // emu reco method we should use
03502     float reco_dircosneu=-1; // z cosine
03503     const bool is_mc
03504       =(ntpHeader->GetVldContext().GetSimFlag()==SimFlag::kMC);
03505     const double muM=0.10566; // muon mass
03506     if(ntpEvent->ntrack!=0){  //and at least one track
03507       
03508       float trk_mom_pq = 0;
03509       //for info, just show first track:
03510       int *tracks = ntpEvent->trk;
03511       int index = 0;
03512       float largestEn = 0;
03513       for(int it=0;it<ntpEvent->ntrack;it++){
03514         if(!LoadTrack(tracks[it])) continue;
03515         if(ntpTrack->momentum.qp==0) continue;
03516         if(fabs(1./ntpTrack->momentum.qp)>largestEn) {
03517           largestEn = fabs(1./ntpTrack->momentum.qp);
03518           index = tracks[it];
03519         }
03520       }
03521       LoadTrack(index);
03522       if(ntpTrack->momentum.qp!=0) trk_mom_pq = 1./ntpTrack->momentum.qp;
03523 
03524       // determine if event is contained, compute momentum      
03525       if(det==Detector::kNear){//if it's the near detector
03526         int pitt_evt_class = 
03527           MadMKAnalysis::PittTrkContained(ntpTrack->end.x,
03528                                           ntpTrack->end.y,
03529                                           ntpTrack->end.z,
03530                                           ntpTrack->end.u,
03531                                           ntpTrack->end.v);
03532         if(pitt_evt_class>0){ // if it was classified
03533           if( (pitt_evt_class == 1) || (pitt_evt_class == 3) ) 
03534             do_meth=2; // stoppers --> range
03535           else if( (pitt_evt_class == 2) || (pitt_evt_class == 4) ) 
03536             do_meth=1; // punch-through --> curvature
03537           if(do_meth==1 || do_meth==2){
03538             best_trk_mom = 
03539               RecoMKMuEnergy(do_meth,index,!is_mc);
03540           }
03541         }
03542       }
03543       else if(det==Detector::kFar){//if it's the far detector
03544         do_meth=MadMKAnalysis::FarTrkContained(ntpTrack->end.x,
03545                                                ntpTrack->end.y,
03546                                                ntpTrack->end.z);
03547         if(do_meth==1 || do_meth==2){
03548           best_trk_mom = 
03549             RecoMKMuEnergy(do_meth,index,!is_mc);
03550         }
03551       }                             
03552       best_trk_mom = sqrt(best_trk_mom*best_trk_mom - muM*muM);
03553       int range_meth=2;
03554       float mom_range = RecoMKMuEnergy(range_meth,index,!is_mc);
03555       mom_range = sqrt(mom_range*mom_range - muM*muM);
03556       if(det==Detector::kNear) 
03557         reco_dircosneu = RecoMuDCosNeuND(index);
03558       else reco_dircosneu = RecoMuDCosNeuFD(index);
03559 
03560       
03561       char range_used=' ';
03562       char curve_used='R';
03563       if(do_meth==1) curve_used='C';
03564       else range_used='*';
03565 
03566       choose_infid_set("cc2008");
03567       Bool_t fid = infid(*strecord,*ntpTrack);
03568         
03569       char track_fid = 'N';
03570       if(fid) track_fid = 'Y';
03571         
03572       sprintf(sometext11,"     q/p: %.3f +/- %.3f,  p/q: %.3f  Best: %c  Fiducial: %c ",
03573               ntpTrack->momentum.qp,
03574               ntpTrack->momentum.eqp,trk_mom_pq,curve_used, track_fid);
03575       SFrame->PassChar("BestRange",curve_used);
03576       SFrame->PassFloat("QoverP",ntpTrack->momentum.qp);
03577       
03578       sprintf(sometext12,"     TrkRangeEnergy: %.3f %c",mom_range,range_used);
03579       SFrame->PassFloat("TrkEne",mom_range);
03580       
03581       sprintf(sometext13,"     Vtx:  x: %.2f, y: %.2f, u: %.2f, v: %.2f, z: %.2f",ntpTrack->vtx.x,
03582               ntpTrack->vtx.y,ntpTrack->vtx.u, ntpTrack->vtx.v,ntpTrack->vtx.z);
03583 
03584      }
03585     else {//no track
03586       sprintf(sometext11,"     q/p: %.3f +/- %.3f,  p/q: %.3f",0.,0.,0.);
03587       SFrame->PassChar("BestRange",'?');
03588       SFrame->PassFloat("QoverP",0.);
03589       sprintf(sometext12,"     TrkRangeEnergy: %.3f",0.);
03590       SFrame->PassFloat("TrkEne",0.);
03591       sprintf(sometext13,"     Vtx: %.2f, %.2f, %.2f",0.,0.,0.);
03592     }
03593     if(ntpEvent->nshower!=0){  //at least one shower
03594       //for info, just show biggest shower:
03595       // and the sum of showers
03596       int *showers = ntpEvent->shw;      
03597       int index = 0;
03598       float largestEn = 0;
03599       float sumEn = 0;
03600       float thisEn = 0;
03601       for(int is=0;is<ntpEvent->nshower;is++){
03602         if(!LoadShower(showers[is])) continue;
03603         if(ntpShower->shwph.linCCgev>largestEn) {
03604           largestEn = ntpShower->shwph.linCCgev;
03605           index = showers[is];
03606         }
03607 
03608         thisEn=CorrectShowerEnergy(ntpShower->shwph.linCCgev,
03609                                    det,CandShowerHandle::kCC);
03610         sumEn+=thisEn;
03611         std::cout<<"shw (i,u,v,z,E,Ecor): ( "<<is<<" , "<<ntpShower->vtx.u
03612                  <<" , "<<ntpShower->vtx.v<<" , "<<ntpShower->vtx.z
03613                  <<" , "<<ntpShower->ph.gev<<" , "<<thisEn<<" ) "<<std::endl;
03614         
03615       }
03616       LoadShower(index);
03617       static int i_shw_message=1;
03618       if(i_shw_message<11){
03619         std::cout<<"Printing the corrected linCC energy ("<<i_shw_message<<"/10)";
03620         if(i_shw_message==10){
03621           std::cout<<" Last message...";
03622         }
03623         std::cout<<std::endl;
03624         i_shw_message++;
03625       }
03626 
03627       cor_shw_energy = CorrectShowerEnergy(ntpShower->shwph.linCCgev,
03628                               det,CandShowerHandle::kCC);
03629       sprintf(sometext12,"%s   RecoShwEnergy: %.3f [%.3f]",sometext12,
03630               cor_shw_energy, sumEn);
03631       SFrame->PassFloat("ShwEne",cor_shw_energy);
03632        
03633     }
03634     else {//no shower
03635       sprintf(sometext12,"%s   RecoShwEnergy: %.3f",sometext12,0.);
03636       SFrame->PassFloat("ShwEne",0.);
03637     }
03638 
03639     if(best_trk_mom>0){
03640       float reco_x=0.,reco_y=0.,reco_Q2=0.,reco_W2=0.,reco_QEQ2=0.;
03641       float reco_eshw=cor_shw_energy;
03642       float reco_emu=sqrt(best_trk_mom*best_trk_mom+muM*muM);
03643       
03644       float reco_enu=reco_emu+reco_eshw;
03645       const double M=(0.93827 + 0.93957)/2.0; // <nucleon mass>
03646       if(reco_emu>0) reco_Q2 = 
03647                        2*reco_enu*reco_emu*(1.0 - reco_dircosneu);
03648       reco_W2 = M*M - reco_Q2 + 2*M*reco_eshw;    
03649       if(reco_enu>0) reco_y = reco_eshw/reco_enu;
03650       if(reco_eshw>0 && reco_Q2>0) reco_x =  reco_Q2/(2*M*reco_eshw);
03651       
03652       float muP=(reco_emu*reco_emu -muM*muM);
03653       if(muP<0) muP=0;
03654       else muP=sqrt(muP);
03655       float reco_qe_enu = (M*reco_emu - muM*muM/2.0)
03656         /(M - reco_emu + muP*reco_dircosneu);
03657       reco_QEQ2 
03658         = abs(-2.0*reco_qe_enu*(reco_emu-muP*reco_dircosneu)+muM*muM);
03659     
03660       //      sprintf(sometext13,"%s,  x,y,Q2,W2  = %.2f, %.2f, %.2f, %.2f",
03661       //              sometext13, reco_x,reco_y,reco_Q2,reco_W2);
03662     }
03663   }
03664   else { //no event
03665     sprintf(sometext11,"     q/p: %.3f +/- %.3f,  p/q: %.3f",0.,0.,0.);
03666     sprintf(sometext12,
03667             "     TrkRangeEnergy: %.3f   RecoShwEnergy: %.3f",0.,0.);
03668     sprintf(sometext13,"     Vtx: %.2f, %.2f, %.2f",0.,0.,0.);
03669 
03670     SFrame->PassChar("BestRange",'?');
03671     SFrame->PassFloat("QoverP",0.);
03672     SFrame->PassFloat("TrkEne",0.);
03673     SFrame->PassFloat("ShwEne",0.);
03674 
03675   }
03676 
03677 
03678   //summary
03679   TLatex *Info1 = new TLatex(0.05,0.91,sometext1);
03680   Info1->SetName("info1");
03681   Info1->SetTextSize(0.06);
03682   Info1->SetTextColor(2);
03683 
03684   //Reco
03685   TLatex *Info9 = new TLatex(0.05,0.84,sometext9);
03686   Info9->SetName("info9");
03687   Info9->SetTextSize(0.06);
03688   Info9->SetTextColor(4);
03689 
03690   TLatex *Info10 = new TLatex(0.05,0.77,sometext10);
03691   Info10->SetName("info10");
03692   if(Info10->Sizeof()<70) Info10->SetTextSize(0.05);
03693   else Info10->SetTextSize(0.04);
03694   Info10->SetTextColor(9);
03695 
03696   TLatex *Info14 = new TLatex(0.05,0.70,sometext14);
03697   Info14->SetName("info14");
03698   if(Info14->Sizeof()<70) Info14->SetTextSize(0.05);
03699   else Info14->SetTextSize(0.04);
03700   Info14->SetTextColor(9);
03701 
03702   //track
03703 
03704   TLatex *Info11 = new TLatex(0.05,0.63,sometext11);
03705   Info11->SetName("info11");
03706   Info11->SetTextSize(0.05);
03707   Info11->SetTextColor(9);
03708 
03709   TLatex *Info12 = new TLatex(0.05,0.56,sometext12);
03710   Info12->SetName("info12");
03711   Info12->SetTextSize(0.05);
03712   Info12->SetTextColor(9);
03713 
03714   TLatex *Info13 = new TLatex(0.05,0.49,sometext13);
03715   Info13->SetName("info13");
03716   Info13->SetTextSize(0.05);
03717   Info13->SetTextColor(9);
03718   
03719   //truth
03720   /*
03721   TLatex *Info2 = new TLatex(0.05,0.42,sometext2);
03722   Info2->SetName("info2");
03723   Info2->SetTextSize(0.06);
03724   Info2->SetTextColor(3);
03725   
03726   TLatex *Info3 = new TLatex(0.05,0.35,sometext3);
03727   Info3->SetName("info3");
03728   Info3->SetTextSize(0.05);
03729   Info3->SetTextColor(8);
03730 
03731   TLatex *Info4 = new TLatex(0.05,0.28,sometext4);
03732   Info4->SetName("info4");
03733   Info4->SetTextSize(0.05);
03734   Info4->SetTextColor(8);
03735 
03736   TLatex *Info5 = new TLatex(0.05,0.21,sometext5);
03737   Info5->SetName("info5");
03738   Info5->SetTextSize(0.05);
03739   Info5->SetTextColor(8);
03740 
03741   TLatex *Info6 = new TLatex(0.05,0.14,sometext6);
03742   Info6->SetName("info6");
03743   Info6->SetTextSize(0.05);
03744   Info6->SetTextColor(8);
03745 
03746   TLatex *Info7 = new TLatex(0.05,0.07,sometext7);
03747   Info7->SetName("info7");
03748   Info7->SetTextSize(0.05);
03749   Info7->SetTextColor(8);
03750 
03751   TLatex *Info8 = new TLatex(0.05,0.00,sometext8);
03752   Info8->SetName("info8");
03753   Info8->SetTextSize(0.05);
03754   Info8->SetTextColor(8);
03755   */
03756   MainCanvas->cd(1);
03757   gPad->Range(0,0,1,1);
03758   Info1->Draw();
03759   //  Info2->Draw();
03760   //  Info3->Draw();
03761   // Info4->Draw();
03762   //  Info5->Draw();
03763   // Info6->Draw();
03764   // Info7->Draw();
03765   // Info8->Draw();
03766   Info9->Draw();
03767   Info10->Draw();
03768   Info11->Draw();
03769   Info12->Draw();
03770   Info13->Draw();
03771   Info14->Draw();
03772 
03773 }
03774 
03775 //*****************************************************************
03776 void MadScanDisplay::DrawKey2(TVirtualPad *KeyPad){
03777 
03778    KeyPad->cd(2);
03779 
03780    TPave *pave = new TPave(0.02,0.02,0.98,0.48);
03781    pave->Draw();
03782    //reco:
03783    TMarker *marker = new TMarker(0.2,0.89/2.,8);
03784    marker->SetMarkerColor(3);
03785    marker->SetMarkerStyle(8);
03786    marker->SetMarkerSize(1.3);
03787    marker->Draw();
03788    marker = new TMarker(0.2,0.80/2.,8);
03789    marker->SetMarkerColor(4);
03790    marker->SetMarkerStyle(8);
03791    marker->SetMarkerSize(1.3);
03792    marker->Draw();
03793    marker = new TMarker(0.2,0.71/2.,8);
03794    marker->SetMarkerStyle(8);
03795    marker->SetMarkerSize(1.3);
03796    marker->Draw();
03797    marker = new TMarker(0.2,0.62/2.,8);
03798    marker->SetMarkerColor(2);
03799    marker->SetMarkerStyle(8);
03800    marker->SetMarkerSize(0.9);
03801    marker->Draw();
03802    marker = new TMarker(0.2,0.53/2.,4);
03803    marker->SetMarkerColor(6);
03804    marker->SetMarkerStyle(28);
03805    marker->SetMarkerSize(0.9);
03806    marker->Draw();
03807    marker = new TMarker(0.2,0.44/2.,4);
03808    marker->SetMarkerColor(6);
03809    marker->SetMarkerStyle(25);
03810    marker->SetMarkerSize(0.9);
03811    marker->Draw();
03812    marker = new TMarker(0.2,0.35/2.,4);
03813    marker->SetMarkerColor(2);
03814    marker->SetMarkerStyle(29);
03815    marker->SetMarkerSize(1);
03816    marker->Draw();
03817    marker = new TMarker(0.2,0.26/2.,4);
03818    marker->SetMarkerColor(6);
03819    marker->SetMarkerStyle(3);
03820    marker->SetMarkerSize(1);
03821    marker->Draw();
03822    
03823    TLatex *tex = new TLatex(0.04,0.86/2.,"Reco");
03824    tex->SetTextFont(132);
03825    tex->SetTextSize(0.05);
03826    tex->SetLineWidth(2);
03827    tex->Draw();
03828    char temp[256];
03829    sprintf(temp,"Summed NPEs < %.1f",Dspe_val);
03830    tex = new TLatex(0.3,0.86/2.,temp);
03831    tex->SetTextFont(132);
03832    tex->SetTextSize(0.05);
03833    tex->SetLineWidth(2);
03834    tex->Draw();
03835    sprintf(temp,"%.1f < Summed NPEs < %.1f",Dspe_val,Dmid_val);
03836    tex = new TLatex(0.3,0.77/2.,temp);
03837    tex->SetTextFont(132);
03838    tex->SetTextSize(0.05);
03839    tex->SetLineWidth(2);
03840    tex->Draw();
03841    sprintf(temp,"Summed NPEs > %.1f",Dmid_val);
03842    tex = new TLatex(0.3,0.68/2.,temp);
03843    tex->SetTextFont(132);
03844    tex->SetTextSize(0.05);
03845    tex->SetLineWidth(2);
03846    tex->Draw();
03847    tex = new TLatex(0.3,0.59/2.,"Reconstructed Track Hit");
03848    tex->SetTextFont(132);
03849    tex->SetTextSize(0.05);
03850    tex->SetLineWidth(2);
03851    tex->Draw();
03852    tex = new TLatex(0.3,0.50/2.,"Reconstructed Primary Shower Hit");
03853    tex->SetTextFont(132);
03854    tex->SetTextSize(0.05);
03855    tex->SetLineWidth(2);
03856    tex->Draw();
03857    tex = new TLatex(0.3,0.41/2.,"Reconstructed Sec. Shower Hit");
03858    tex->SetTextFont(132);
03859    tex->SetTextSize(0.05);
03860    tex->SetLineWidth(2);
03861    tex->Draw();   
03862    tex = new TLatex(0.3,0.32/2.,"Track Vertex");
03863    tex->SetTextFont(132);
03864    tex->SetTextSize(0.05);
03865    tex->SetLineWidth(2);
03866    tex->Draw();   
03867 tex = new TLatex(0.3,0.23/2.,"Shower Vertex");
03868    tex->SetTextFont(132);
03869    tex->SetTextSize(0.05);
03870    tex->SetLineWidth(2);
03871    tex->Draw();
03872  
03873 }
03874 
03875 //*****************************************************************
03876 void MadScanDisplay::DrawKey(TVirtualPad *KeyPad){
03877 
03878    KeyPad->cd(2);
03879 
03880    TPave *pave = new TPave(0.02,0.02,0.98,0.48);
03881    pave->Draw();
03882 
03883    TMarker *marker = new TMarker(0.2,0.89/2.,8);
03884    marker->SetMarkerColor(3);
03885    marker->SetMarkerStyle(8);
03886    marker->SetMarkerSize(1.3);
03887    marker->Draw();
03888    marker = new TMarker(0.2,0.80/2.,8);
03889    marker->SetMarkerColor(4);
03890    marker->SetMarkerStyle(8);
03891    marker->SetMarkerSize(1.3);
03892    marker->Draw();
03893    marker = new TMarker(0.2,0.71/2.,8);
03894    marker->SetMarkerStyle(8);
03895    marker->SetMarkerSize(1.3);
03896    marker->Draw();
03897    marker = new TMarker(0.2,0.62/2.,8);
03898    marker->SetMarkerColor(2);
03899    marker->SetMarkerStyle(8);
03900    marker->SetMarkerSize(0.9);
03901    marker->Draw();
03902    marker = new TMarker(0.2,0.53/2.,4);
03903    marker->SetMarkerColor(5);
03904    marker->SetMarkerStyle(4);
03905    marker->SetMarkerSize(0.9);
03906    marker->Draw();
03907    marker = new TMarker(0.21,0.53/2.,4);
03908    marker->SetMarkerColor(7);
03909    marker->SetMarkerStyle(4);
03910    marker->SetMarkerSize(0.9);
03911    marker->Draw();
03912    marker = new TMarker(0.2,0.44/2.,25);
03913    marker->SetMarkerColor(7);
03914    marker->SetMarkerStyle(25);
03915    marker->SetMarkerSize(1.3);
03916    marker->Draw();
03917    marker = new TMarker(0.2,0.35/2.,26);
03918    marker->SetMarkerColor(3);
03919    marker->SetMarkerStyle(26);
03920    marker->SetMarkerSize(1.3);
03921    marker->Draw();
03922    marker = new TMarker(0.2,0.26/2.,27);
03923    marker->SetMarkerColor(6);
03924    marker->SetMarkerStyle(27);
03925    marker->SetMarkerSize(1.3);
03926    marker->Draw();
03927    marker = new TMarker(0.2,0.17/2.,30);
03928    marker->SetMarkerStyle(30);
03929    marker->SetMarkerSize(1.3);
03930    marker->Draw();
03931    marker = new TMarker(0.2,0.08/2.,28);
03932    marker->SetMarkerColor(5);
03933    marker->SetMarkerStyle(28);
03934    marker->SetMarkerSize(1.3);
03935    marker->Draw();
03936    TLatex *tex = new TLatex(0.04,0.86/2.,"Reco");
03937    tex->SetTextFont(132);
03938    tex->SetTextSize(0.05);
03939    tex->SetLineWidth(2);
03940    tex->Draw();
03941    tex = new TLatex(0.04,0.41/2.,"Truth");
03942    tex->SetTextFont(132);
03943    tex->SetTextSize(0.05);
03944    tex->SetLineWidth(2);
03945    tex->Draw();
03946    char temp[256];
03947    sprintf(temp,"Summed NPEs < %.1f",Dspe_val);
03948    tex = new TLatex(0.3,0.86/2.,temp);
03949    tex->SetTextFont(132);
03950    tex->SetTextSize(0.05);
03951    tex->SetLineWidth(2);
03952    tex->Draw();
03953    sprintf(temp,"%.1f < Summed NPEs < %.1f",Dspe_val,Dmid_val);
03954    tex = new TLatex(0.3,0.77/2.,temp);
03955    tex->SetTextFont(132);
03956    tex->SetTextSize(0.05);
03957    tex->SetLineWidth(2);
03958    tex->Draw();
03959    sprintf(temp,"Summed NPEs > %.1f",Dmid_val);
03960    tex = new TLatex(0.3,0.68/2.,temp);
03961    tex->SetTextFont(132);
03962    tex->SetTextSize(0.05);
03963    tex->SetLineWidth(2);
03964    tex->Draw();
03965    tex = new TLatex(0.3,0.59/2.,"Reconstructed Track Hit");
03966    tex->SetTextFont(132);
03967    tex->SetTextSize(0.05);
03968    tex->SetLineWidth(2);
03969    tex->Draw();
03970    tex = new TLatex(0.3,0.50/2.,"Reconstructed Primary Shower Hit (cyan=EM)");
03971    tex->SetTextFont(132);
03972    tex->SetTextSize(0.05);
03973    tex->SetLineWidth(2);
03974    tex->Draw();
03975   tex = new TLatex(0.3,0.50/2.,"Reconstructed Sec. Shower Hit (cyan=EM)");
03976    tex->SetTextFont(132);
03977    tex->SetTextSize(0.05);
03978    tex->SetLineWidth(2);
03979    tex->Draw();
03980    tex = new TLatex(0.3,0.41/2.,"Primary Muon (+ secondaries)");
03981    tex->SetTextFont(132);
03982    tex->SetTextSize(0.05);
03983    tex->SetLineWidth(2);
03984    tex->Draw();
03985    tex = new TLatex(0.3,0.32/2.,"Primary Electron (+ secondaries)");
03986    tex->SetTextFont(132);
03987    tex->SetTextSize(0.05);
03988    tex->SetLineWidth(2);
03989    tex->Draw();
03990    tex = new TLatex(0.3,0.23/2.,"Recoil Shower Products");
03991    tex->SetTextFont(132);
03992    tex->SetTextSize(0.05);
03993    tex->SetLineWidth(2);
03994    tex->Draw();
03995    tex = new TLatex(0.3,0.14/2.,"Noise");
03996    tex->SetTextFont(132);
03997    tex->SetTextSize(0.05);
03998    tex->SetLineWidth(2);
03999    tex->Draw();
04000    tex = new TLatex(0.3,0.05/2.,"Other");
04001    tex->SetTextFont(132);
04002    tex->SetTextSize(0.05);
04003    tex->SetLineWidth(2);
04004    tex->Draw();
04005    tex = new TLatex(0.65,0.05/2.,"Nu Unit P");
04006    tex->SetTextFont(132);
04007    tex->SetTextSize(0.05);
04008    tex->SetLineWidth(2);
04009    tex->Draw();
04010    TArrow *arrow = new TArrow(0.5,0.09/2.,0.6,0.09/2.,0.03,"|>");
04011    arrow->SetFillColor(5);
04012    arrow->SetLineColor(9);
04013    arrow->SetLineWidth(2);
04014    arrow->Draw();
04015 }
04016 
04017 //*****************************************************************
04018 Int_t *MadScanDisplay::Dec2Bin(Int_t dec){
04019 
04020   Int_t *bin = new Int_t[32];
04021   for(Int_t i=0;i<32;i++) bin[i]=0;
04022 
04023   Int_t index=1;
04024   
04025   while(true){
04026     if(dec<TMath::Power(2,index) && dec>1) {
04027       bin[index-1]=1;
04028       dec-=Int_t(TMath::Power(2,index-1));
04029       index=1;
04030     }
04031 
04032     else index+=1;
04033 
04034     if(dec==0) break;
04035     if(dec==1){
04036       bin[0]=1;
04037       dec-=1;
04038       break;
04039     }
04040   }
04041   return bin;
04042 }
04043 
04044 //*****************************************************************
04045 void MadScanDisplay::DrawInteractionDiagram(Int_t itr){
04046 
04047   if(!LoadTruth(itr)) return;
04048 
04049   //make sure there is a canvas for my art
04050   TCanvas *can;  
04051   if(gROOT->FindObject("StdHepDiagramCanvas")) {
04052     can = (TCanvas*) gROOT->FindObject("StdHepDiagramCanvas");
04053     can->cd();    
04054     TList *theList = can->GetListOfPrimitives();
04055     TIterator *iter = theList->MakeIterator();
04056     TObject *ob;      
04057     while((ob = iter->Next())){
04058       if(ob->InheritsFrom("TLatex")) {
04059         TLatex *tex = (TLatex*) ob;
04060         delete tex;
04061       }
04062       else if(ob->InheritsFrom("TArrow")) {
04063         TArrow *ar = (TArrow*) ob;
04064         delete ar;
04065       }
04066       else if(ob->InheritsFrom("TMarker")) {
04067         TMarker *m = (TMarker*) ob;
04068         delete m;
04069       }
04070     }
04071     can->Range(0,0,1,1.1);
04072   }
04073   else {
04074     can = new TCanvas("StdHepDiagramCanvas","StdHep Diagram Canvas",0,0,900,400);
04075     can->cd();
04076     can->Range(0,0,1,1.1);
04077     TPaveText *infoTex1 = new TPaveText(0.05,1.,0.2,1.07);
04078     infoTex1->AddText("Initial State");
04079     infoTex1->SetBorderSize(1);
04080     TPaveText *infoTex2 = new TPaveText(0.3,1.,0.45,1.07);
04081     infoTex2->AddText("Intermediate");
04082     infoTex2->SetBorderSize(1);
04083     TPaveText *infoTex3 = new TPaveText(0.55,1.,0.7,1.07);
04084     infoTex3->AddText("Final State");
04085     infoTex3->SetBorderSize(1);
04086     TPaveText *infoTex4 = new TPaveText(0.8,1.,0.95,1.07);
04087     infoTex4->AddText("Later Decays");
04088     infoTex4->SetBorderSize(1);
04089     infoTex1->SetTextSize(0.05);
04090     infoTex1->SetTextFont(12);
04091     infoTex1->SetTextColor(1);
04092     infoTex2->SetTextSize(0.05);
04093     infoTex2->SetTextFont(12);
04094     infoTex2->SetTextColor(1);
04095     infoTex3->SetTextSize(0.05);
04096     infoTex3->SetTextFont(12);
04097     infoTex3->SetTextColor(1);
04098     infoTex4->SetTextSize(0.05);
04099     infoTex4->SetTextFont(12);
04100     infoTex4->SetTextColor(1);
04101     infoTex1->SetName("infoTex1");
04102     infoTex2->SetName("infoTex2");
04103     infoTex3->SetName("infoTex3");
04104     infoTex4->SetName("infoTex4");
04105     infoTex1->Draw();
04106     infoTex2->Draw();
04107     infoTex3->Draw();
04108     infoTex4->Draw();
04109   }
04110   
04111   //First get indices to use:
04112   TClonesArray* pointStdhepArray = NULL;
04113   if(isST) pointStdhepArray = (strecord->stdhep);
04114   else pointStdhepArray = (mcrecord->stdhep);
04115   TClonesArray& stdhepArray = *pointStdhepArray;
04116   Int_t nStdHep = stdhepArray.GetEntries();
04117   Int_t *indicesToUse = new Int_t[nStdHep];
04118   Int_t *parent = new Int_t[nStdHep];
04119   Int_t incomingNeutrino = -1;
04120   Int_t cnt = 0;
04121   for(int i=0;i<nStdHep;i++){
04122     LoadStdHep(i);
04123     if(ntpStdHep->mc==itr) {
04124       indicesToUse[cnt] = i;
04125       parent[i] = ntpStdHep->parent[0];
04126       if(ntpStdHep->IstHEP==0){
04127         if(abs(ntpStdHep->IdHEP)==12||abs(ntpStdHep->IdHEP)==14
04128            ||abs(ntpStdHep->IdHEP)==16) {
04129           incomingNeutrino=i;
04130         }
04131         parent[i] = -1; //don't draw arrows to initial state particles
04132       }
04133       cnt++;
04134     }
04135     else parent[i] = -1;
04136   }
04137   
04138   //make arrows and markers
04139   //  TArrow *arrow[1000];
04140   //  TMarker *marker[1000];
04141   // it is possible to have more than 1000 stdhep particles
04142   // yikes...
04143   // I think that these objects are deleted in the block at
04144   // the start of this routine.
04145   std::vector<TArrow*> arrow(nStdHep);
04146   std::vector<TMarker*> marker(nStdHep);
04147 
04148   for(int i=0;i<nStdHep;i++) {
04149     arrow[i] = new TArrow(0,0,0,0,0.03,"|>");
04150     arrow[i]->SetLineWidth(1);
04151     arrow[i]->SetLineStyle(3);
04152     arrow[i]->SetFillColor(39);
04153     arrow[i]->SetLineColor(39);
04154     marker[i] = new TMarker(0,0,24);
04155     marker[i]->SetMarkerSize(1);
04156     marker[i]->SetMarkerColor(38);
04157   }
04158 
04159   //now loop through valid stdhep entries and fill variables  
04160   Float_t Available[4] = {0.9,0.7,0.9,0.7};
04161   
04162   for(int i=0;i<cnt;i++){
04163     
04164     int toUse = indicesToUse[i];
04165     LoadStdHep(toUse);
04166     if(ntpStdHep->IstHEP==999) continue;
04167     Float_t mom = sqrt(ntpStdHep->p4[0]*ntpStdHep->p4[0] + 
04168                        ntpStdHep->p4[1]*ntpStdHep->p4[1] + 
04169                        ntpStdHep->p4[2]*ntpStdHep->p4[2]);
04170     float x=0.,y=0.;
04171     int col=0;
04172     char text[256];
04173 
04174     //set x,y    
04175     if(ntpStdHep->IstHEP==0) {
04176       x = 0.05;
04177       y=Available[0]; Available[0] -= 0.1;
04178     }
04179     else if(ntpStdHep->IstHEP==11) {
04180       x = 0.05;
04181       y=Available[0]; Available[0] -= 0.1; 
04182     }
04183     else if(ntpStdHep->IstHEP==3 || ntpStdHep->IstHEP==14) {
04184       x = 0.3;
04185       y=Available[1]; Available[1] -= 0.1;
04186     }
04187     else if(ntpStdHep->IstHEP==1){
04188       x = 0.55;
04189       y=Available[2]; Available[2] -= 0.1;
04190     }
04191     else if(ntpStdHep->IstHEP==205){
04192       x = 0.8;
04193       y=Available[3]; Available[3] -= 0.1;
04194     }
04195  
04196     //set colour and label (and override y in special cases)
04197     if(abs(ntpStdHep->IdHEP)==12) { //nue
04198       y = 0.9; sprintf(text,"#nu_{e}"); col = 3;
04199       if(ntpStdHep->IdHEP<0) sprintf(text,"#bar{#nu}_{e}");
04200     }
04201     else if(abs(ntpStdHep->IdHEP)==14) { //numu
04202       y = 0.9; sprintf(text,"#nu_{#mu}"); col = 4;
04203       if(ntpStdHep->IdHEP<0) sprintf(text,"#bar{#nu}_{#mu}");
04204     }
04205     else if(abs(ntpStdHep->IdHEP)==16) { //nutau
04206       y = 0.9; sprintf(text,"#nu_{#tau}"); col = 5;
04207       if(ntpStdHep->IdHEP<0) sprintf(text,"#bar{#nu}_{#tau}"); 
04208     }    
04209     else if(abs(ntpStdHep->IdHEP)==11) { //e
04210       if(parent[toUse]==incomingNeutrino) y = 0.9;
04211       sprintf(text,"e^{-}"); col = 3;
04212       if(ntpStdHep->IdHEP<0) sprintf(text,"e^{+}");
04213     }
04214     else if(abs(ntpStdHep->IdHEP)==13) { //mu
04215       if(parent[toUse]==incomingNeutrino) y = 0.9;
04216       sprintf(text,"#mu^{-}"); col = 4;
04217       if(ntpStdHep->IdHEP<0) sprintf(text,"#mu^{+}");
04218     }
04219     else if(abs(ntpStdHep->IdHEP)==15) { //tau
04220       if(parent[toUse]==incomingNeutrino) y = 0.9;      
04221       sprintf(text,"#tau^{-}"); col = 5;
04222       if(ntpStdHep->IdHEP<0) sprintf(text,"#tau^{+}"); 
04223     }
04224     else if(ntpStdHep->IdHEP==22) { //photon
04225       sprintf(text,"#gamma"); col = 9;      
04226     }
04227     else if(ntpStdHep->IdHEP>1000000000) { //nucleus
04228       y = 0.8;
04229       sprintf(text,"nucleus(%i,%i)",int((ntpStdHep->IdHEP-1e9)/1e6),
04230               int((ntpStdHep->IdHEP-1e9 - 1e6*int((ntpStdHep->IdHEP-1e9)
04231                                                   /1e6))/1e3)); 
04232       col = 15;
04233     }
04234     else if(ntpStdHep->IdHEP==2112){ 
04235       sprintf(text,"neutron"); col = 28;
04236     }
04237     else if(ntpStdHep->IdHEP==2212){
04238       sprintf(text,"proton"); col = 2;
04239     }
04240     else if(abs(ntpStdHep->IdHEP)==211) {
04241       sprintf(text,"#pi^{+}"); col = 6;
04242       if(ntpStdHep->IdHEP<0) sprintf(text,"#pi^{-}");
04243     }
04244     else if(ntpStdHep->IdHEP==111) {
04245       sprintf(text,"#pi^{0}"); col = 7;
04246     }
04247     else if(ntpStdHep->IdHEP==130) {
04248       sprintf(text,"K^{0}_{L}"); col = 31;
04249     }
04250     else if(ntpStdHep->IdHEP==310) {
04251       sprintf(text,"K^{0}_{S}"); col = 31;
04252     }
04253     else if(ntpStdHep->IdHEP==311) {
04254       sprintf(text,"K^{0}"); col = 31;
04255     }
04256     else if(abs(ntpStdHep->IdHEP)==321) {
04257       sprintf(text,"K^{+}"); col = 31;
04258       if(ntpStdHep->IdHEP<0) sprintf(text,"K^{-}"); col = 31;
04259     }
04260     else if(ntpStdHep->IdHEP==28) {
04261       sprintf(text,"Geantino"); col = 46;
04262       if(ntpStdHep->IdHEP<0) sprintf(text,"K^{-}"); col = 31;
04263     }
04264     else {
04265       sprintf(text,"ID: %i",ntpStdHep->IdHEP); col=43;
04266     }
04267 
04268     sprintf(text,"%s [%.1f GeV/c]",text,mom);
04269     
04270     arrow[toUse]->SetX2(x-0.02);   
04271     arrow[toUse]->SetY2(y-0.02);   
04272     marker[toUse]->SetX(x-0.02);
04273     marker[toUse]->SetY(y-0.02);
04274 
04275     for(int j=0;j<nStdHep;j++){
04276       if(parent[j]==toUse){
04277         arrow[j]->SetX1(x-0.02);
04278         arrow[j]->SetY1(y-0.02);
04279       }
04280     }
04281  
04282     TLatex *tex = new TLatex(x,y,text);
04283     char texname[256];
04284     sprintf(texname,"tex%i",i);
04285     tex->SetName(texname);
04286     tex->SetTextSize(0.05);
04287     tex->SetTextColor(col);    
04288     tex->Draw();
04289   }
04290 
04291   for(int i=0;i<nStdHep;i++){
04292     if(parent[i]==-1) {
04293       delete arrow[i];
04294       delete marker[i];
04295     }
04296     else {
04297       arrow[i]->Draw();
04298       marker[i]->Draw();
04299     }
04300   }
04301 
04302   Float_t minAvail = 0;
04303   for(int i=0;i<4;i++){
04304     if(Available[i]<minAvail) minAvail = Available[i];
04305   }
04306 
04307   if(minAvail<0) can->Range(0,minAvail,1,1.1);
04308 
04309   delete [] indicesToUse;
04310   delete [] parent;
04311 
04312   can->Modified();
04313   can->Update();
04314 }
04315 
04316 void MadScanDisplay::DrawButtons(TCanvas *MainCanvas) {
04317 
04318   MainCanvas->cd(2);
04319   TVirtualPad *MainCanvas_2 = MainCanvas->GetPad(2);
04320   MainCanvas_2->Range(0,0,1,1);
04321   
04322   if(!gROOT->IsBatch()){ //if we are not in batch mode, draw controls.
04323     //otherwise let the Key fill up MainCanvas_2
04324     
04325     //Next/Prev event with cuts
04326     TButton *but1 = new TButton("Next Fid Trk","if(EVD->drawSAME) {EVD->drawSAME=false; but4b->SetFillColor(2); but4b->Modified();} ; EVD->fAltDisplay=false; EVD->LeEntry = EVD->NextFidTrk();",0.6,0.9,1,1);
04327     but1->SetTextSize(0.5);
04328     but1->SetFillColor(4);
04329     TButton *but2 = new TButton("Nxt Fid No Trk","if(EVD->drawSAME) {EVD->drawSAME=false; but4b->SetFillColor(2); but4b->Modified();}; EVD->fAltDisplay=false; EVD->LeEntry = EVD->NextFidNoTrk();",0.2,0.9,0.6,1);
04330     but2->SetTextSize(0.5);
04331     but2->SetFillColor(5);
04332     
04333     //Next/Prev event of any kind
04334     TButton *but14 = new TButton("Step Forward","if(EVD->drawSAME) {EVD->drawSAME=false; but4b->SetFillColor(2); but4b->Modified();} EVD->LeSlice=0; EVD->LeEvent=0; EVD->LeMCevent=0;  EVD->LeEntry += 1; EVD->FindUnSliced(); EVD->fAltDisplay=true; EVD->Display(EVD->LeEntry,0,0,0,EVD->LeAutoMat);",0.6,0.8,1,0.9);
04335     but14->SetTextSize(0.5);
04336     but14->SetFillColor(4);
04337     TButton *but15 = new TButton("Step Back","if(EVD->drawSAME) {EVD->drawSAME=false; but4b->SetFillColor(2); but4b->Modified();} EVD->LeSlice=0; EVD->LeEvent=0; EVD->LeMCevent=0; EVD->LeEntry -= 1; EVD->FindUnSliced(); EVD->fAltDisplay=true; EVD->Display(EVD->LeEntry,0,0,0,EVD->LeAutoMat);",0.2,0.8,0.6,0.9);
04338     but15->SetTextSize(0.5);
04339     but15->SetFillColor(5);
04340     
04341     TButton *but10 = new TButton("Next Slc","if(EVD->drawSAME) {EVD->drawSAME=false; } EVD->LeEntry = EVD->NextPass();",0.4,0.7,0.6,0.8);
04342     but10->SetName("but10");
04343     but10->SetTextSize(0.5);
04344     but10->SetFillColor(4);
04345     
04346     TButton *but12 = new TButton("Prev Slc","if(EVD->drawSAME) {EVD->drawSAME=false; } EVD->LeEntry = EVD->PrevPass();",0.2,0.7,0.4,0.8);
04347     but12->SetName("but12");
04348     but12->SetTextSize(0.5);
04349     but12->SetFillColor(5);
04350 
04351     TButton *but11 = new TButton("Next Evt","if (EVD->drawSAME) {EVD->drawSAME=false; } EVD->LeEntry = EVD->NextEvt();",0.8,0.7,1,0.8);
04352     but11->SetName("but11");
04353     but11->SetTextSize(0.5);
04354     but11->SetFillColor(4);
04355     
04356     TButton *but13 = new TButton("Prev Evt","if (EVD->drawSAME) {EVD->drawSAME=false; } EVD->LeEntry = EVD->PrevEvt();",0.6,0.7,0.8,0.8);
04357     but13->SetName("but13");
04358     but13->SetTextSize(0.5);
04359     but13->SetFillColor(5);
04360     
04361     //Skip to, +/- MC
04362     TButton *but16 = new TButton("Prev MC","EVD->LeMCevent-=1; fAltDisplay-false; EVD->Display(EVD->LeEntry,EVD->LeSlice,EVD->LeEvent,EVD->LeMCevent,EVD->LeAutoMat);",0.2,0.6,0.4,0.7);
04363     but16->SetName("but16");
04364     but16->SetTextSize(0.5);
04365     but16->SetFillColor(5);
04366     TButton *but17 = new TButton("Next MC","EVD->LeMCevent+=1; fAltDisplay=false; EVD->Display(EVD->LeEntry,EVD->LeSlice,EVD->LeEvent,EVD->LeMCevent,EVD->LeAutoMat);",0.4,0.6,0.6,0.7);
04367     but17->SetName("but17");
04368     but17->SetTextSize(0.5);
04369     but17->SetFillColor(4);
04370     
04371     TButton *but3a = new TButton("Skip to...","if(EVD->drawSAME) {EVD->drawSAME=false; but4b->SetFillColor(2); but4b->Modified();} EVD->LeSlice=0; EVD->LeEvent=0; fAltDisplay=false; EVD->LeMCevent=0; EVD->LeEntry = EVD->SkipTo();",0.6,0.65,0.8,0.7);
04372     but3a->SetTextSize(0.5);
04373     but3a->SetFillColor(9);
04374     
04375     TButton *but3e = new TButton("Run,Snarl...","if(EVD->drawSAME) {EVD->drawSAME=false; but4b->SetFillColor(2); but4b->Modified();} EVD->LeSlice=0; EVD->LeEvent=0; fAltDisplay=false; EVD->LeMCevent=0; EVD->LeEntry = EVD->JumpTo();",0.6,0.6,0.8,0.65);
04376     but3e->SetTextSize(0.5);
04377     but3e->SetFillColor(9);
04378     
04379     TButton *but3c = new TButton("AutoMatch","if(EVD->LeAutoMat) { but3c->SetFillColor(2); but10->SetFillColor(4); but12->SetFillColor(5); but16->SetFillColor(5); but17->SetFillColor(4); EVD->LeAutoMat=false; } else { but3c->SetFillColor(3); but10->SetFillColor(15); but12->SetFillColor(15); but16->SetFillColor(15); but17->SetFillColor(15); EVD->LeAutoMat = true; }; but10->Modified(); but12->Modified(); but16->Modified(); but17->Modified();",0.8,0.6,1,0.7);
04380     but3c->SetName("but3c");
04381     but3c->SetTextSize(0.5);
04382     but3c->SetFillColor(3);
04383     
04384     if(LeAutoMat) {
04385       but10->SetFillColor(15);
04386       but12->SetFillColor(15);
04387       but16->SetFillColor(15);
04388       but17->SetFillColor(15);
04389     }
04390     //Refresh/Lego/Quit/Print
04391     
04392     TButton *but4 = new TButton("Refresh","EVD->Display(EVD->LeEntry,EVD->LeSlice,EVD->LeEvent,EVD->LeMCevent,EVD->LeAutoMat);",0.2,0.55,0.4,0.6);
04393     but4->SetTextSize(0.5);
04394     but4->SetFillColor(6);
04395 
04396     TButton *but4b = new TButton("Overlay","if(EVD->drawSAME) {EVD->drawSAME=false; but4b->SetFillColor(2);} else {EVD->drawSAME=true; but4b->SetFillColor(3);}",0.2,0.5,0.4,0.55);
04397     but4b->SetName("but4b");
04398     but4b->SetTextSize(0.5);
04399     if(drawSAME) but4b->SetFillColor(3);
04400     else but4b->SetFillColor(2);
04401     
04402     TButton *but3b = new TButton("Lego?","if(EVD->LeLego) {EVD->LeLego=false; but3b->SetFillColor(2);} else {EVD->LeLego=true; but3b->SetFillColor(3);}",0.4,0.55,0.6,0.6);
04403     but3b->SetName("but3b");
04404     but3b->SetTextSize(0.5);
04405     if(LeLego) but3b->SetFillColor(3);
04406     else but3b->SetFillColor(2);    
04407     
04408     TButton *but3d = new TButton("Clusters?","if(EVD->LeClus) {EVD->LeClus=false; but3d->SetFillColor(2);} else {EVD->LeClus=true; but3d->SetFillColor(3);}",0.4,0.5,0.6,0.55);
04409     but3d->SetName("but3d");
04410     but3d->SetTextSize(0.5);
04411     if(LeClus) but3d->SetFillColor(3);
04412     else but3d->SetFillColor(2);    
04413     
04414     TButton *but18 = new TButton("Print","EVD->PrintDisplay();",
04415                                  0.6,0.5,0.8,0.6);
04416     but18->SetTextSize(0.5);
04417     but18->SetFillColor(8);
04418     
04419     TButton *but5 = new TButton("Quit",".q",0.8,0.5,1,0.6);
04420     but5->SetTextSize(0.5);
04421     but5->SetFillColor(45);
04422     
04423     but1->Draw();
04424     but2->Draw();
04425     but3a->Draw();
04426     but3b->Draw();
04427     but3c->Draw();
04428     but3d->Draw();
04429     but3e->Draw();
04430     but4->Draw();
04431     but4b->Draw();
04432     but5->Draw();
04433     but10->Draw();
04434     but11->Draw();
04435     but12->Draw();
04436     but13->Draw();
04437     but14->Draw();
04438     but15->Draw();
04439     but16->Draw();
04440     but17->Draw();
04441     but18->Draw();
04442     
04443     if(!handScan) {
04444       
04445       //Buttons to select out numu/nue/NC/CC
04446       TButton *but19 = new TButton(" Missed PH","EVD->ROICalc();",0,0.9,0.195,1);
04447       but19->SetTextSize(0.4);
04448       but19->SetName("but19");
04449       TButton *but6 = new TButton("Extra PH","EVD->ShwROICalc()",0,0.8,0.195,0.9);
04450       but6->SetTextSize(0.4);
04451       but6->SetName("but6");
04452       TButton *but7 = new TButton("NuE","EVD->LeNu=12; but6->SetFillColor(2); but7->SetFillColor(3); but6->Modified(); EVD->UseNuInfo=true; but19->SetFillColor(2); but19->Modified();",0,0.7,0.195,0.8);
04453       but7->SetTextSize(0.4);
04454       but7->SetName("but7");
04455       TButton *but8 = new TButton("NC","EVD->LeAction=0; but8->SetFillColor(3); but9->SetFillColor(2); but9->Modified(); EVD->UseNuInfo=true; but19->SetFillColor(2); but19->Modified();",0,0.6,0.195,0.7);
04456       but8->SetTextSize(0.4);
04457       but8->SetName("but8");
04458       TButton *but9 = new TButton("CC","EVD->LeAction=1; but8->SetFillColor(2); but9->SetFillColor(3); but8->Modified(); EVD->UseNuInfo=true; but19->SetFillColor(2); but19->Modified();",0,0.5,0.195,0.6);
04459       but9->SetTextSize(0.4);
04460       but9->SetName("but9");
04461         
04462       if(UseNuInfo){
04463         if(LeNu==14) {but6->SetFillColor(3); but7->SetFillColor(2);}
04464         else if(LeNu==12) {but7->SetFillColor(3); but6->SetFillColor(2);}
04465           else {but6->SetFillColor(10); but7->SetFillColor(10);}
04466         if(LeAction==0) {but8->SetFillColor(3); but9->SetFillColor(2);}
04467         else if(LeAction==1) {but9->SetFillColor(3); but8->SetFillColor(2);}
04468         else {but9->SetFillColor(10); but8->SetFillColor(10);}
04469         }
04470       else {
04471         but19->SetFillColor(3); but6->SetFillColor(15); 
04472         but7->SetFillColor(15);
04473         but8->SetFillColor(15); but9->SetFillColor(15);
04474       }
04475       
04476       but6->Draw();
04477       but7->Draw();
04478       but8->Draw();
04479       but9->Draw();
04480       but19->Draw();
04481     }
04482     else StartLogger();
04483   }
04484   //else MainCanvas_2->Range(0,0,0.5,0.5);
04485   this->DrawKey2(MainCanvas_2);
04486 }
04487 
04488 void MadScanDisplay::StartLogger()
04489 {
04490 
04491   TButton *but1 = new TButton("mu",
04492                               "EVD->ScanID=1; EVD->ChangeLogButColor();",
04493                               0.,0.8875,0.1275,0.95);
04494   but1->SetTextSize(0.6);
04495   but1->SetFillColor(2);
04496   but1->SetName("logBut1");
04497   
04498   TButton *but2 = new TButton("e",
04499                               "EVD->ScanID=2; EVD->ChangeLogButColor();",
04500                               0.,0.825,0.1275,0.8875);
04501   but2->SetTextSize(0.6);
04502   but2->SetFillColor(2);
04503   but2->SetName("logBut2");
04504   
04505   TButton *but3 = new TButton("NC",
04506                               "EVD->ScanID=3; EVD->ChangeLogButColor();",
04507                               0.,0.7625,0.1275,0.825);
04508   but3->SetTextSize(0.6);
04509   but3->SetFillColor(2);
04510   but3->SetName("logBut3");
04511   
04512   TButton *but4 = new TButton("mu/NC?",
04513                               "EVD->ScanID=4; EVD->ChangeLogButColor();",
04514                               0.,0.70,0.1275,0.7625);
04515   but4->SetTextSize(0.6);
04516   but4->SetFillColor(2);
04517   but4->SetName("logBut4");
04518   
04519   TButton *but5 = new TButton("e/NC?",
04520                               "EVD->ScanID=5; EVD->ChangeLogButColor();",
04521                               0.,0.6375,0.1275,0.7);
04522   but5->SetTextSize(0.6);
04523   but5->SetFillColor(2);
04524   but5->SetName("logBut5");
04525   
04526   TButton *but6 = new TButton("???",
04527                               "EVD->ScanID=6; EVD->ChangeLogButColor();",
04528                               0.,0.575,0.1275,0.6375);
04529   but6->SetTextSize(0.6);
04530   but6->SetFillColor(2);
04531   but6->SetName("logBut6");
04532 
04533   TButton *but8 = new TButton("QE",
04534                               "EVD->ScanTop=1; EVD->ChangeLogButColor();",
04535                               0.1275,0.85625,0.195,0.95);
04536   but8->SetTextSize(0.4);
04537   but8->SetFillColor(2);
04538   but8->SetName("logBut8");
04539   
04540   TButton *but9 = new TButton("RES",
04541                               "EVD->ScanTop=2; EVD->ChangeLogButColor();",
04542                               0.1275,0.7625,0.195,0.85625);
04543   but9->SetTextSize(0.4);
04544   but9->SetFillColor(2);
04545   but9->SetName("logBut9");
04546   
04547   TButton *but10 = new TButton("DIS",
04548                                "EVD->ScanTop=3; EVD->ChangeLogButColor();",
04549                                0.1275,0.66875,0.195,0.7625);
04550   but10->SetTextSize(0.4);
04551   but10->SetFillColor(2);
04552   but10->SetName("logBut10");
04553 
04554   TButton *but11 = new TButton("???",
04555                               "EVD->ScanTop=4; EVD->ChangeLogButColor();",
04556                               0.1275,0.575,0.195,0.66875);
04557   but11->SetTextSize(0.4);
04558   but11->SetFillColor(2);
04559   but11->SetName("logBut11");
04560     
04561   TButton *but12 = new TButton("Log Details","EVD->Log();",
04562                                0.,0.5,0.195,0.575);
04563   but12->SetTextSize(0.6);
04564   but12->SetFillColor(4);
04565 
04566   TButton *but7 = new TButton("Click for Info",
04567                                "EVD->PrintHSHelp();",
04568                                0.,0.95,0.195,1.0);
04569   but7->SetTextSize(0.6);
04570   but7->SetFillColor(45);
04571     
04572   but1->Draw();
04573   but2->Draw();
04574   but3->Draw();
04575   but4->Draw();
04576   but5->Draw();
04577   but6->Draw();
04578   but7->Draw();
04579   but8->Draw();
04580   but9->Draw();
04581   but10->Draw();
04582   but11->Draw();
04583   but12->Draw();
04584 }
04585 
04586 void MadScanDisplay::ChangeLogButColor()
04587 {
04588   if(gROOT->FindObject("MainCanvas")) {
04589     TCanvas *MainCanvas = (TCanvas*) gROOT->FindObject("MainCanvas");
04590     TVirtualPad *MainCanvas_2 = MainCanvas->GetPad(2);
04591     char butName[256];
04592     int butNums[10] = {1,2,3,4,5,6,8,9,10,11};
04593     for(int i=0;i<10;i++){
04594       sprintf(butName,"logBut%i",butNums[i]);
04595       TButton *but = (TButton*) MainCanvas_2->FindObject(butName);
04596       if(butNums[i]==ScanID || butNums[i]==ScanTop+7) {
04597         but->SetFillColor(3);
04598         but->Modified();
04599       }
04600       else if(but->GetFillColor()!=2) {
04601         but->SetFillColor(2);
04602         but->Modified();
04603       }
04604     }
04605   }
04606 }
04607 
04608 void MadScanDisplay::Log() 
04609 {
04610   ofstream outFile;
04611   outFile.open(logFileName, ofstream::out | ofstream::app);
04612   outFile << ntpHeader->GetRun() << " " 
04613           << ntpHeader->GetSubRun() << " " 
04614           << ntpHeader->GetSnarl() << " "
04615           << ntpSlice->index << " "
04616           << ntpEvent->index << " "
04617           << ScanID << " "
04618           << ScanTop << " "
04619           << endl;
04620   outFile.close();
04621 }
04622 
04623 void MadScanDisplay::EnableHandScan(char *fname)
04624 {
04625   handScan = true;
04626   if(std::strcmp(fname,"")) {
04627     sprintf(logFileName,"%s",fname);
04628   }
04629 }
04630 
04631 void MadScanDisplay::PrintHSHelp()
04632 {
04633   cout << endl;
04634   cout << endl;
04635   cout << "================= Hand Scan Info =================" << endl;
04636   cout << "Left Hand Column shows possible event ID tags:" << endl;
04637   cout << "mu    = numu CC                  -   code = 1" << endl;
04638   cout << "e     = nue CC                   -   code = 2" << endl;
04639   cout << "NC    = NC                       -   code = 3" << endl;
04640   cout << "mu/NC = numu CC / NC Ambiguity   -   code = 4" << endl;
04641   cout << "e/NC  = nue CC / NC Ambiguity    -   code = 5" << endl;
04642   cout << "???   = Complete Ambiguity       -   code = 6" << endl;
04643   cout << "N/A (all buttons red)            -   code = 0" << endl;
04644   cout << "--------------------------------------------------" << endl;
04645   cout << "Right Hand Column shows possible event topology tags:" << endl;
04646   cout << "QE                               -   code = 1" << endl;
04647   cout << "RES                              -   code = 2" << endl;
04648   cout << "DIS                              -   code = 3" << endl;
04649   cout << "???                              -   code = 4" << endl;
04650   cout << "N/A (all buttons red)            -   code = 0" << endl;
04651   cout << "--------------------------------------------------" << endl;
04652   cout << "Click 'Log Details' to write choices to text file" << endl;
04653   cout << "=================== Good Luck! ===================" << endl;
04654   cout << endl;
04655 }
04656 
04657 void MadScanDisplay::EventDump()
04658 {
04659   if(ntpEvent) ntpEvent->Print();
04660   if(LoadTrack(ntpEvent->trk[0])) ntpTrack->Print();
04661   if(LoadShower(ntpEvent->shw[0])) ntpShower->Print();
04662   if(ntpTruth) ntpTruth->Print();
04663 }
04664 
04665 bool MadScanDisplay::ReadEventsFile(const char* filename){
04666   // read text file listing interesting events
04667   // file format: run snarl event
04668   // blank lines and lines beginning with # are ignored
04669 
04670   //check that file exists
04671   FileStat_t buf;  
04672   if(gSystem->GetPathInfo(filename,buf) == 1) {
04673     std::cout<<"MadScanDisplay::ReadEventsFile: couldn't open "<<filename<<std::endl;
04674     return false;
04675   }
04676   else{
04677     std::cout<<"MadScanDisplay::ReadEventsFile: reading from "<<filename<<std::endl;
04678   }
04679   std::ifstream in(filename);
04680   int nread=0;
04681   std::string s;
04682   while(std::getline(in,s,'\n')){
04683 
04684     if(s=="") continue;// a blank line
04685     else if(s[0]=='#') continue; // a comment
04686     else{ 
04687       std::istringstream iss(s,std::istringstream::in);
04688       Int_t run,snarl,event;
04689       iss>>run>>snarl>>event;
04690 
04691       /*
04692       std::cout<<run<<" "<<snarl<<" "<<event;
04693       if(iss.good()) std::cout<<" good ";
04694       else std::cout<<" !good ";
04695       if(iss.eof()) std::cout<<" eof ";
04696       else std::cout<<" !eof ";
04697       std::cout<<std::endl;
04698       */
04699 
04700       // check that the read was ok
04701       if(iss.good() || iss.eof()){ 
04702         std::vector<Int_t> v(3); v[0]=run; v[1]=snarl; v[2]=event;
04703         fNeatoEvents.push_back(v);
04704         nread++;
04705       }
04706     }
04707   }
04708   std::cout<<"MadScanDisplay::ReadEventsFile read "<<nread<<" events."<<std::endl;
04709   if(nread>0) fHaveNeatoEvents=true;
04710   return true;
04711 }
04712 
04713 Int_t MadScanDisplay::NextInterestingEvent(bool backward){
04714   if(fNeatoEvents.size()==0) return LeEntry;
04715   //  int ncontinue;
04716   Int_t event=-1;
04717   Int_t entry=-1;
04718   while(true){
04719     if(!backward){
04720       if(fNeatoEventIdx+1 >= static_cast<Int_t>(fNeatoEvents.size())){
04721         fNeatoEventIdx=0; 
04722       }
04723       else fNeatoEventIdx++;
04724     }
04725     else{
04726       if(fNeatoEventIdx-1 < 0){
04727         fNeatoEventIdx=fNeatoEvents.size()-1;
04728       }
04729       else fNeatoEventIdx--;
04730     }
04731     //  return fNeatoEventIdx;
04732     // search for event in MadChain's list
04733     std::vector<Int_t>& v = fNeatoEvents[fNeatoEventIdx]; 
04734     entry=fChain->GetEntryNumber(v[0],v[1]);
04735     if(entry != -1) {
04736       event = v[2];
04737       break;
04738     }
04739 
04740   }
04741   this->GetEntry(entry);
04742   this->LoadEvent(event);
04743   SFrame->EntryProc();
04744   Display(entry,0,event,0,LeAutoMat);
04745   return entry;
04746 
04747 }
04748 
04749 Float_t MadScanDisplay::RecoMKMuEnergy(Int_t& opt,Int_t itrk, bool isdata){
04750   
04751   if(LoadTrack(itrk)){
04752      float mr=ntpTrack->momentum.range;
04753      mr=CorrectMomentumFromRange(mr,isdata);
04754     if(opt==0){  
04755       //return the most appropriate measure of momentum
04756       // assign opt based on our choice
04757       if(ntpTrack->fidall.dr>0.5&&ntpTrack->fidall.dz>0.5) {
04758         opt=2;
04759         return sqrt(mr*mr+ 0.10555*0.10555);
04760       }
04761       else {
04762         opt=1;
04763         // in R1.9 the tracker will apparently return (q/p)=0.0
04764         // maybe it's when a track looks perfectly rigid?
04765         // if so, we have to do something
04766         // I don't want to use the range, that could be very wrong
04767         // but wrong in a more subtle way ...
04768         // so, we'll return an obviously ridiculous value of 10 TeV
04769         if(ntpTrack->momentum.qp == 0.0) return 10000.0; 
04770         else return sqrt(1./(ntpTrack->momentum.qp*ntpTrack->momentum.qp)
04771                          + 0.10555*0.10555);
04772       }
04773     }
04774     else if(opt==1) { //return curvature measurement
04775         if(ntpTrack->momentum.qp == 0.0) return 10000.0; 
04776         else return sqrt(1./(ntpTrack->momentum.qp*ntpTrack->momentum.qp)
04777                          + 0.10555*0.10555);
04778     }
04779     else if(opt==2) //return range measurement
04780       return sqrt(mr*mr + 0.10555*0.10555);
04781     else return 0;
04782   }
04783   return 0.;
04784 }
04785 
04786 
04787 Float_t MadScanDisplay::RecoMuDCosNeuFD(Int_t itr, Float_t* /* vtx */){
04788   if(!LoadTrack(itr)) return 0.;
04789 
04790   Float_t bl_z = TMath::Cos(TMath::Pi()*3./180.); //3degree beam
04791   Float_t bl_y = sqrt(1. - bl_z*bl_z);
04792   Float_t costhbl = ntpTrack->vtx.dcosz*bl_z + ntpTrack->vtx.dcosy*bl_y;
04793   
04794   return  costhbl;
04795 }
04796 
04797 Float_t MadScanDisplay::RecoMuDCosNeuND(Int_t itr, Float_t* /* vtx */){
04798   if(!LoadTrack(itr)) return 0.;
04799   /*
04800    // simple correction based on the vertical position
04801   float vtxy=0;
04802   if(vtx) vtxy=vtx[1]; // in meters
04803   // cosine of the typical neutrino angle in the yz plane
04804   // calculated as py / sqrt( py^2 + pz^2)
04805   float nu_cos = -5.799E-2;
04806   if(vtxy>-2.0 && vtxy<2.0){ //prevents further nuttyness if vtxy is silly
04807     nu_cos += vtxy*1.23304E-3 
04808       + vtxy*vtxy*1.08212E-5 
04809       + vtxy*vtxy*vtxy*(-4.634E-5);
04810   }
04811   */
04812   float nu_cos = -5.799E-2;
04813   float nu_sin = sqrt(1 -nu_cos*nu_cos);
04814   float cosz = ntpTrack->vtx.dcosz*nu_sin + ntpTrack->vtx.dcosy*nu_cos;
04815 
04816   return cosz;
04817 
04818 }
04819 
04820 void MadScanDisplay::ROICalc(){
04821  
04822   TH2 * utz_place  = (TH2*) gROOT->FindObject("tz_place_0");
04823   TH2 * vtz_place =  (TH2*) gROOT->FindObject("tz_place_1");
04824  
04825   Double_t tmin_U=0; 
04826   Double_t tmax_U=0; 
04827   Double_t zmin_U=0; 
04828   Double_t zmax_U=0; 
04829   Double_t tmin_V=0; 
04830   Double_t tmax_V=0; 
04831   Double_t zmin_V=0; 
04832   Double_t zmax_V=0;  
04833 
04834   if(utz_place && vtz_place){
04835     int firstbin = utz_place->GetXaxis()->GetFirst();
04836     int lastbin = utz_place->GetXaxis()->GetLast();
04837     zmin_U = utz_place->GetXaxis()->GetXmin()+utz_place->GetXaxis()->GetBinWidth(0)*(firstbin-1);
04838     zmax_U = utz_place->GetXaxis()->GetXmin()+utz_place->GetXaxis()->GetBinWidth(0)*(lastbin-1);
04839 
04840     firstbin = utz_place->GetYaxis()->GetFirst();
04841     lastbin = utz_place->GetYaxis()->GetLast();
04842     tmin_U = utz_place->GetYaxis()->GetXmin()+utz_place->GetYaxis()->GetBinWidth(0)*(firstbin-1);
04843     tmax_U = utz_place->GetYaxis()->GetXmin()+utz_place->GetYaxis()->GetBinWidth(0)*(lastbin-1);
04844 
04845     firstbin = vtz_place->GetXaxis()->GetFirst();
04846     lastbin = vtz_place->GetXaxis()->GetLast();
04847     zmin_V = vtz_place->GetXaxis()->GetXmin()+vtz_place->GetXaxis()->GetBinWidth(0)*(firstbin-1);
04848     zmax_V = vtz_place->GetXaxis()->GetXmin()+vtz_place->GetXaxis()->GetBinWidth(0)*(lastbin-1);
04849 
04850     firstbin = vtz_place->GetYaxis()->GetFirst();
04851     lastbin = vtz_place->GetYaxis()->GetLast();
04852     tmin_V = vtz_place->GetYaxis()->GetXmin()+vtz_place->GetYaxis()->GetBinWidth(0)*(firstbin-1);
04853     tmax_V = vtz_place->GetYaxis()->GetXmin()+vtz_place->GetYaxis()->GetBinWidth(0)*(lastbin-1);
04854   }
04855   
04856   double slcPH=0;
04857   if(ntpEvent){
04858     LoadSlice(ntpEvent->slc);
04859     if(ntpSlice){
04860       for(int i=0;i<ntpSlice->nstrip;i++){
04861         if(!LoadStrip(ntpSlice->stp[i])) continue;
04862         Double_t zstp = ntpStrip->z;
04863         Double_t tstp = ntpStrip->tpos;
04864         Double_t ph = ntpStrip->ph1.pe + ntpStrip->ph0.pe;
04865         if(ntpStrip->planeview==PlaneView::kU){
04866           if(zstp>=zmin_U && zstp<=zmax_U && tstp>=tmin_U && tstp<=tmax_U){
04867             slcPH+=ph;
04868           }
04869         }
04870         else{
04871           if(zstp>=zmin_V && zstp<=zmax_V && tstp>=tmin_V && tstp<=tmax_V) {
04872             slcPH+=ph;
04873           }
04874           } 
04875       }
04876     }
04877     double evtPH=0;
04878     int stripbuf[10000] ; int planebuf[10000];
04879     int nbuf=0;
04880     for(int i=0;i<ntpEvent->nstrip;i++){
04881       if(!LoadStrip(ntpEvent->stp[i])) continue;
04882       bool used=false;
04883       for(int j=0;j<nbuf;j++){
04884         if(stripbuf[j]==ntpStrip->strip && planebuf[j]==ntpStrip->plane) used=true;
04885       }
04886       stripbuf[nbuf]=ntpStrip->strip; planebuf[nbuf]=ntpStrip->plane;
04887       nbuf++;
04888       if(!used){
04889         Double_t ztrk = ntpStrip->z;
04890         Double_t ttrk = ntpStrip->tpos;
04891         Double_t ph = ntpStrip->ph1.pe + ntpStrip->ph0.pe;
04892         if(ntpStrip->planeview==PlaneView::kU){
04893           if(ztrk>=zmin_U && ztrk<=zmax_U && ttrk>=tmin_U && ttrk<=tmax_U) {
04894             evtPH+=ph;
04895           }
04896 
04897         }
04898         else{
04899           if(ztrk>=zmin_V && ztrk<=zmax_V && ttrk>=tmin_V && ttrk<=tmax_V) {
04900             evtPH+=ph;
04901           }
04902         }
04903       }
04904     }
04905     double phlost = 0;
04906     if(slcPH-evtPH>0) phlost=slcPH-evtPH;
04907     SFrame->PassFloat("ShwLostPH",phlost);
04908     
04909   }
04910 }
04911 void MadScanDisplay::ShwROICalc(){
04912  
04913   TH2 * utz_place  = (TH2*) gROOT->FindObject("tz_place_0");
04914   TH2 * vtz_place =  (TH2*) gROOT->FindObject("tz_place_1");
04915  
04916   Double_t tmin_U=0; 
04917   Double_t tmax_U=0; 
04918   Double_t zmin_U=0; 
04919   Double_t zmax_U=0; 
04920   Double_t tmin_V=0; 
04921   Double_t tmax_V=0; 
04922   Double_t zmin_V=0; 
04923   Double_t zmax_V=0;  
04924 
04925   if(utz_place && vtz_place){
04926     int firstbin = utz_place->GetXaxis()->GetFirst();
04927     int lastbin = utz_place->GetXaxis()->GetLast();
04928     zmin_U = utz_place->GetXaxis()->GetXmin()+utz_place->GetXaxis()->GetBinWidth(0)*(firstbin-1);
04929     zmax_U = utz_place->GetXaxis()->GetXmin()+utz_place->GetXaxis()->GetBinWidth(0)*(lastbin-1);
04930 
04931     firstbin = utz_place->GetYaxis()->GetFirst();
04932     lastbin = utz_place->GetYaxis()->GetLast();
04933     tmin_U = utz_place->GetYaxis()->GetXmin()+utz_place->GetYaxis()->GetBinWidth(0)*(firstbin-1);
04934     tmax_U = utz_place->GetYaxis()->GetXmin()+utz_place->GetYaxis()->GetBinWidth(0)*(lastbin-1);
04935 
04936     firstbin = vtz_place->GetXaxis()->GetFirst();
04937     lastbin = vtz_place->GetXaxis()->GetLast();
04938     zmin_V = vtz_place->GetXaxis()->GetXmin()+vtz_place->GetXaxis()->GetBinWidth(0)*(firstbin-1);
04939     zmax_V = vtz_place->GetXaxis()->GetXmin()+vtz_place->GetXaxis()->GetBinWidth(0)*(lastbin-1);
04940 
04941     firstbin = vtz_place->GetYaxis()->GetFirst();
04942     lastbin = vtz_place->GetYaxis()->GetLast();
04943     tmin_V = vtz_place->GetYaxis()->GetXmin()+vtz_place->GetYaxis()->GetBinWidth(0)*(firstbin-1);
04944     tmax_V = vtz_place->GetYaxis()->GetXmin()+vtz_place->GetYaxis()->GetBinWidth(0)*(lastbin-1);
04945   }
04946   
04947   double shwPH=0;
04948   if(ntpEvent){
04949     int *showers = ntpEvent->shw;
04950     for(int i=0;i<ntpEvent->nshower;i++){
04951       int index = showers[i];
04952       LoadShower(index);
04953     }
04954     for(int i=0;i<ntpShower->nstrip;i++){
04955       if(!LoadStrip(ntpShower->stp[i])) continue;
04956       Double_t zshw = ntpStrip->z;
04957       Double_t tshw = ntpStrip->tpos;
04958       Double_t ph = ntpStrip->ph1.pe + ntpStrip->ph0.pe;
04959       if(ntpStrip->planeview==PlaneView::kU){
04960         if(zshw>=zmin_U && zshw<=zmax_U && tshw>=tmin_U && tshw<=tmax_U) {
04961           shwPH+=ph;
04962         }
04963       }
04964       else{
04965         if(zshw>=zmin_V && zshw<=zmax_V && tshw>=tmin_V && tshw<=tmax_V) {
04966           shwPH+=ph;
04967         }
04968       }
04969     }
04970   }
04971   SFrame->PassFloat("ShwExtraPH",shwPH);
04972   
04973 }
04974 
04975 
04976 
04977 void MadScanDisplay::HandleZoomEvent() {
04978   // RBP: 2008-03-13
04979   // Added this routine to allow users to drag-draw a box for zooming.
04980   // Much less wrist strain for the hand scanning studies!
04981 
04982   static Int_t    firstX, firstY, lastX , lastY , lastEvent;
04983   static Double_t holdX0, holdX1, holdY0, holdY1;
04984   static Bool_t   inside;
04985   Int_t event = gPad->GetEvent();
04986   Int_t x     = gPad->GetEventX();
04987   Int_t y     = gPad->GetEventY();
04988 
04989   // get the drawn histogram... expecting it to be At(1):
04990   TH2 *h = (TH2*)gPad->GetListOfPrimitives()->At(1);
04991   if (!h->InheritsFrom(TH1::Class())) return;
04992 
04993   if (h) {
04994       TFrame* fr = 0;
04995     switch (event) {
04996 
04997     case kButton1Down:
04998       // hold start of zoom region if inside frame
04999       fr = (TFrame*)gPad->GetListOfPrimitives()->At(0);
05000       if (x > gPad->XtoAbsPixel(fr->GetX1())&&
05001           x < gPad->XtoAbsPixel(fr->GetX2())&&
05002           y > gPad->YtoAbsPixel(fr->GetY2())&&
05003           y < gPad->YtoAbsPixel(fr->GetY1())) {
05004         inside = kTRUE;
05005         firstX = x;
05006         firstY = y;
05007         gPad->SetCursor(kCross);
05008         gPad->GetRange(holdX0,holdY0,holdX1,holdY1);
05009         gVirtualX->DrawBox(x,y,x,y,TVirtualX::kHollow);
05010         gVirtualX->SetLineColor(-1);
05011       }
05012       else {
05013         inside = kFALSE;
05014       }
05015       break;
05016       
05017     case kButton1Motion:
05018       if (inside) {
05019         // draw zooming box
05020         gVirtualX->DrawBox(firstX,firstY,lastX,lastY,TVirtualX::kHollow);
05021         gVirtualX->DrawBox(firstX,firstY,    x,    y,TVirtualX::kHollow);
05022       }
05023       break;
05024       
05025     case kButton1Up:
05026       if (gROOT->IsEscaped()) {
05027         gROOT->SetEscape(kFALSE);
05028       }
05029       else if (inside) {
05030         // zoom the axes
05031         gPad->Range(holdX0,holdY0,holdX1,holdY1);
05032         Double_t newx0 = gPad->AbsPixeltoX((firstX<x)?firstX:x);
05033         Double_t newx1 = gPad->AbsPixeltoX((firstX<x)?x:firstX);
05034         Double_t newy0 = gPad->AbsPixeltoY((firstY>y)?firstY:y);
05035         Double_t newy1 = gPad->AbsPixeltoY((firstY>y)?y:firstY);
05036         Double_t oldx0 = gPad->GetUxmin();
05037         Double_t oldx1 = gPad->GetUxmax();
05038         Double_t oldy0 = gPad->GetUymin();
05039         Double_t oldy1 = gPad->GetUymax();
05040         if ((newx1-newx0)/(oldx1-oldx0)>0.05||
05041             (newy1-newy0)/(oldy1-oldy0)>0.05) {
05042           h->GetXaxis()->SetRangeUser(newx0,newx1);
05043           h->GetYaxis()->SetRangeUser(newy0,newy1);
05044           gPad->Modified(kTRUE);
05045         }
05046       }
05047       inside = kFALSE;
05048       gVirtualX->SetLineColor(-1);
05049       break;
05050     
05051     default:
05052       break;
05053     }
05054   }
05055 
05056   lastEvent = event;
05057   lastX     = x;
05058   lastY     = y;
05059 }
05060 
05061 
05062 void MadScanDisplay::MakeGraphNonEditable(TObject *obj) {
05063   if (obj->InheritsFrom(TGraph::Class())) {
05064     ((TGraph*)obj)->SetEditable(0);
05065   }
05066   else if (obj->InheritsFrom(TMultiGraph::Class())) {
05067     MakeGraphListNonEditable(((TMultiGraph*)obj)->GetListOfGraphs());
05068   }
05069 }
05070 
05071 
05072 void MadScanDisplay::MakeGraphListNonEditable(TList *list) {
05073   TIter next(list);
05074   while (TObject *obj = next()) {
05075     MakeGraphNonEditable(obj);
05076   }
05077 }
05078 
05079 
05080 #endif // #ifdef madscandisplay_cxx

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