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

LIAnalysis.cxx

Go to the documentation of this file.
00001 
00002 
00003 // Program name: LIAnalysis.cxx                
00004 //                                                  
00005 // Package: LISummary
00006 //                                                                    
00007 // Coded by Jeff Hartnell Sep/2002-Oct/2003
00008 //                                                                    
00009 // Purpose: To analyse li_tree in LIData*.root files 
00010 //                                                                    
00011 // Contact: jeffrey.hartnell@physics.ox.ac.uk                         
00013 
00014 #include <fstream>
00015 #include <cmath>
00016 #include <string>
00017 
00018 #include "TStyle.h"
00019 #include "TFile.h"
00020 #include "TTree.h"
00021 #include "TH1.h"
00022 #include "TH2.h"
00023 #include "TF1.h"
00024 #include "TCanvas.h"
00025 #include "TAxis.h"
00026 #include "TDatime.h" 
00027 #include "TGraph.h"
00028 #include "TGraphAsymmErrors.h"
00029 #include "TGraphErrors.h"
00030 #include "TLegend.h"
00031 #include "TPad.h"
00032 #include "TPaveText.h"
00033 #include "TText.h"
00034 #include "TError.h"
00035 
00036 #include "Plex/PlexHandle.h"
00037 #include "MessageService/MsgService.h"
00038 
00039 #include "LISummary/LIAnalysis.h"
00040 #include "LISummary/LIChannel.h"
00041 #include "LISummary/LIPlane.h"
00042 #include "LISummary/LIRun.h"
00043 #include "LISummary/LITuning.h"
00044 #include "Validity/VldContext.h"
00045 #include "Validity/VldTimeStamp.h"
00046 #include "Calibrator/Calibrator.h"
00047 #include "Calibrator/CalScheme.h"
00048 
00049 ClassImp(LIAnalysis)
00050 
00051 CVSID("$Id: LIAnalysis.cxx,v 1.74 2009/06/02 21:29:38 nickd Exp $");
00052 
00053 //......................................................................
00054 
00055 class LIHits
00056 {
00057   //a little class to hold the hits of your desire!
00058 
00059 public:
00060   //LIHits() {};
00061   map<Float_t,Int_t> hits;
00062 };
00063 
00064 //......................................................................
00065 
00066 LIAnalysis::LIAnalysis(Int_t analyseChainFlag)
00067 {
00068   MSG("LIAnalysis", Msg::kDebug) 
00069     <<"Running LIAnalysis constructor..."<<endl;
00070 
00071   //use the pretty palette
00072   gStyle->SetPalette(1);
00073   //include the under and overflow counts
00074   gStyle->SetOptStat(1111111);
00075   gStyle->SetOptFit(1111);
00076 
00077   //data members
00078   ashtray=-1;
00079   calibPoint=-1;
00080   calibType=-1;
00081   chAdd=-1;
00082   chain=0;
00083   channel=-1;
00084   chip=-1;
00085   correlatedHit=-1;
00086   crate=-1;
00087   detectorType=-1;
00088   eastWest=-1;//0 is east, 1 is west 
00089   elecType=-1;
00090   farLed=-1;
00091   farPulserBox=-1;
00092   firstRunNumber=-1;
00093   geoAdd=-1;
00094   highRunNumber=-1;
00095   for (Int_t i=0;i<80;i++){
00096     histname[i]='?';
00097   }
00098   inRack=-1;//determines mux box in rack 0-7
00099   lastLed=-1;
00100   lastCalibPoint=-1;
00101   lastPulserBox=-1;
00102   lastRunNumber=-1;
00103   led=-1;
00104   liEvent=-1;
00105   liRunNum=-1;
00106   lowRunNumber=-1;
00107   masterCh=-1;
00108   maxLedNum=-1;
00109   maxPbNum=-1;
00110   maxCalibPoint=-1;
00111   mean=-1.;
00112   minderCh=-1;
00113   nearLed=-1;
00114   nearPulserBox=-1;
00115   numCalibPoints=0;
00116   numEntries=-1;
00117   numericMuxBox=-1;
00118   numEvents=-1; 
00119   numLeds=-1;
00120   numLiEvents=-1;
00121   for (Int_t i=0;i<NUMLEDS;i++){
00122     numLiEventsL[i]=0;
00123   }
00124   for (Int_t i=0;i<NUMPULSERBOXES;i++){
00125     numLiEventsP[i]=0;
00126   }
00127   numLiRuns=-1;
00128   period=-1;
00129   pixel=-1;
00130   pinGain=-1;//0 is low, 1 is high gain
00131   pinInBox=-1;//0 is low gain (VA=0), 1 is high gain (VA=1)
00132   plane=-1;
00133   previousRunNumber=-1;
00134   pulseHeight=-1;
00135   pulserBox=-1;
00136   pulses=-1;
00137   pulseWidth=-1;
00138   rackBay=-1;//determines which rack 0-15
00139   rackLevel=-1;//0 is top, 1 is bottom
00140   readoutType=-1;
00141   rms=-1.;
00142   run=-1;
00143   runNumber=-1;
00144   runNumberSub=-1;
00145   runType=-1;
00146   s="";
00147   fS="";
00148   strip=-1;
00149   stripEnd=-1;
00150   summaryCounter=-1;
00151   timestamp=-1;
00152   timestampNanoSec=-1;
00153   varc=-1;
00154   vfb=-1;
00155   vmm=-1;
00156 
00157   //set up the chain and perform some checks
00158   this->MakeChain();
00159   this->SetChainBranches();
00160   numEvents=static_cast<Int_t>(chain->GetEntries());
00161   MSG("LIAnalysis",Msg::kInfo) 
00162     <<"Number of events in chain="<<numEvents<<endl; 
00163   if (analyseChainFlag==1){
00164     this->AnalyseChain();
00165   }
00166   
00167   //get the last event
00168   chain->GetEvent(numEvents-1);  
00169   lastRunNumber=runNumber;
00170   
00171   //get the first event
00172   chain->GetEvent(0);  
00173   firstRunNumber=runNumber;//never need to touch this again
00174 
00175   //set which detector to use
00176   this->SetDetector(detectorType);
00177 
00178   //set the high run number to be the highest of the first and last
00179   //it will get changed if there is a higher run number
00180   //between the first and the last
00181   highRunNumber=firstRunNumber;
00182   if (lastRunNumber>firstRunNumber) highRunNumber=lastRunNumber;
00183   //similarly for low run number
00184   lowRunNumber=firstRunNumber;
00185   if (lastRunNumber<firstRunNumber) lowRunNumber=lastRunNumber;
00186 
00187   if (firstRunNumber!=lastRunNumber){
00188     MSG("LIAnalysis",Msg::kInfo)
00189       <<"First run number = "<<firstRunNumber
00190       <<", last = "<<lastRunNumber<<endl;
00191   }
00192 
00193   MSG("LIAnalysis", Msg::kInfo) 
00194     <<"Finished LIAnalysis constructor"<<endl;
00195 }
00196 
00197 //......................................................................
00198 
00199 LIAnalysis::~LIAnalysis()
00200 {
00201   MSG("LIAnalysis", Msg::kDebug) 
00202     <<"Running LIAnalysis destructor..."<<endl;
00203 
00204 
00205   MSG("LIAnalysis", Msg::kDebug) 
00206     <<"Finished LIAnalysis destructor"<<endl;
00207 }
00208 
00209 //......................................................................
00210 
00211 void LIAnalysis::MakeChain()
00212 {
00213   MSG("LIAnalysis", Msg::kDebug)<<"Running MakeChain method..."<<endl;
00214 
00215   //LI data files to read in
00216   char* envVariable=getenv("LIDATA");
00217   if (envVariable==NULL){
00218     MSG("LIAnalysis",Msg::kFatal)
00219       <<endl<<endl
00220       <<"*************************************************************"
00221       <<endl<<"Environmental variable LIDATA not set!"<<endl
00222       <<"Please set LIDATA to the directory containing the"
00223       <<" LIData*.root files"<<endl
00224       <<"Note: If more than one file is found they will be"
00225       <<" concatenated and treated as one"<<endl
00226       <<"*************************************************************"
00227       <<endl<<endl<<"Program will exit here"<<endl;
00228     exit(0);
00229   }
00230   string sEnv=envVariable;
00231   MSG("LIAnalysis",Msg::kInfo)
00232     <<"Looking for LIData*.root files using the env variable"<<endl
00233     <<"LIDATA="<<sEnv<<endl;
00234   
00235   string sFileName=sEnv+"/LIData*.root";
00236 
00237   // create a chain with li_tree
00238   chain=new TChain("li_tree");  
00239   //add the files to the chain
00240   Int_t nf=chain->Add(sFileName.c_str());
00241 
00242   if(nf==0){
00243     MSG("LIAnalysis",Msg::kFatal)
00244       <<endl<<endl
00245       <<"*************************************************************"
00246       <<endl<<"No LIData*.root files found in "<<sEnv<<endl
00247       <<"Please set LIDATA to the directory containing the"
00248       <<" LIData*.root files"<<endl
00249       <<"Note: If more than one file is found they will be"
00250       <<" concatenated and treated as one"<<endl
00251       <<"*************************************************************"
00252       <<endl<<endl<<"Program will exit here"<<endl;
00253     exit(0);
00254   }
00255     
00256   MSG("LIAnalysis",Msg::kInfo) 
00257     <<"Printing tree information:"<<endl;
00258   chain->Show(1);
00259   //chain->Print()
00260   
00261   if (nf==1){
00262     MSG("LIAnalysis",Msg::kInfo) 
00263       <<endl<<"Analysing "<<nf<<" file of the form LIData*.root in"
00264       <<endl<<"LIDATA="<<sEnv<<endl<<endl;
00265   }
00266   else{
00267     MSG("LIAnalysis",Msg::kInfo)
00268       <<endl<<"Analysing "<<nf
00269       <<" files of the form LIData*.root in directory"
00270       <<endl<<"LIDATA="<<sEnv<<endl<<endl;
00271     MSG("LIAnalysis",Msg::kInfo)
00272       <<"Reading in files..."<<endl;
00273   }
00274 
00275   MSG("LIAnalysis", Msg::kDebug)<<"Finished the MakeChain method"<<endl;
00276 }
00277 
00278 //......................................................................
00279 
00280 void LIAnalysis::SetChainBranches()
00281 {
00282   chain->SetBranchAddress("ashtray",&ashtray);
00283   chain->SetBranchAddress("calibPoint",&calibPoint);
00284   chain->SetBranchAddress("calibType",&calibType);
00285   chain->SetBranchAddress("chAdd",&chAdd);
00286   chain->SetBranchAddress("channel",&channel);
00287   chain->SetBranchAddress("chip",&chip);
00288   chain->SetBranchAddress("correlatedHit",&correlatedHit);
00289   chain->SetBranchAddress("crate",&crate);
00290   chain->SetBranchAddress("detectorType",&detectorType);
00291   chain->SetBranchAddress("eastWest",&eastWest);
00292   chain->SetBranchAddress("elecType",&elecType);
00293   chain->SetBranchAddress("farLed",&farLed);
00294   chain->SetBranchAddress("farPulserBox",&farPulserBox);
00295   chain->SetBranchAddress("geoAdd",&geoAdd);
00296   chain->SetBranchAddress("inRack",&inRack);
00297   chain->SetBranchAddress("led",&led);
00298   chain->SetBranchAddress("masterCh",&masterCh);
00299   chain->SetBranchAddress("mean",&mean);
00300   chain->SetBranchAddress("minderCh",&minderCh);
00301   chain->SetBranchAddress("nearLed",&nearLed);
00302   chain->SetBranchAddress("nearPulserBox",&nearPulserBox);
00303   chain->SetBranchAddress("numEntries",&numEntries);
00304   chain->SetBranchAddress("numericMuxBox",&numericMuxBox);
00305   chain->SetBranchAddress("period",&period);
00306   chain->SetBranchAddress("pinGain",&pinGain);
00307   chain->SetBranchAddress("pinInBox",&pinInBox);
00308   chain->SetBranchAddress("pixel",&pixel);
00309   chain->SetBranchAddress("plane",&plane);
00310   chain->SetBranchAddress("pulseHeight",&pulseHeight);
00311   chain->SetBranchAddress("pulserBox",&pulserBox);
00312   chain->SetBranchAddress("pulses",&pulses);
00313   chain->SetBranchAddress("pulseWidth",&pulseWidth);
00314   chain->SetBranchAddress("rackBay",&rackBay);
00315   chain->SetBranchAddress("rackLevel",&rackLevel);
00316   chain->SetBranchAddress("readoutType",&readoutType);
00317   chain->SetBranchAddress("rms",&rms);
00318   chain->SetBranchAddress("runNumber",&runNumber);
00319   chain->SetBranchAddress("runNumberSub",&runNumberSub);
00320   chain->SetBranchAddress("runType",&runType);
00321   chain->SetBranchAddress("strip",&strip);
00322   chain->SetBranchAddress("stripEnd",&stripEnd);
00323   chain->SetBranchAddress("summaryCounter",&summaryCounter);
00324   chain->SetBranchAddress("timestamp",&timestamp);
00325   chain->SetBranchAddress("varc",&varc);
00326   chain->SetBranchAddress("vfb",&vfb);
00327   chain->SetBranchAddress("vmm",&vmm);
00328 }
00329 
00330 //......................................................................
00331 
00332 void LIAnalysis::AnalyseChain()
00333 {
00334   this->InitialiseLoopVariables();  
00335 
00336   Int_t eventsPerLedCounter=0;
00337   Int_t lastLed2=-1;
00338   Int_t lastPulserBox2=-1;
00339   Int_t lastCalibPoint2=-1;
00340   Int_t numLiEventsC[1000];
00341   for (Int_t i=0;i<1000;i++){
00342     numLiEventsC[i]=0;
00343   }
00344 
00345   for(Int_t entry=0;entry<numEvents;entry++){
00346     
00347     this->SetLoopVariables(entry,0);
00348         
00349     if (led>maxLedNum){
00350       maxLedNum=led;
00351     }
00352     if (pulserBox>maxPbNum){
00353       maxPbNum=pulserBox;
00354     }
00355     if (calibPoint>maxCalibPoint){
00356       maxCalibPoint=calibPoint;
00357     }
00358 
00359     eventsPerLedCounter++;
00360         
00361     if (led!=lastLed2){
00362       //if an led is flashed only a few times print
00363       if (eventsPerLedCounter<100){
00364         MSG("LIAnalysis",Msg::kInfo) 
00365           <<"For LED="<<lastLed 
00366           <<", numEntries="<<eventsPerLedCounter
00367           <<endl;
00368       }
00369       eventsPerLedCounter=0;      
00370       numLiEventsL[led-1]++;
00371     }
00372 
00373     if (pulserBox!=lastPulserBox2){
00374       numLiEventsP[pulserBox]++;
00375       MSG("LIAnalysis",Msg::kInfo)<<"pulserBox="<<pulserBox<<endl;
00376     }
00377     if (calibPoint!=lastCalibPoint2){   
00378       numLiEventsC[calibPoint-1]++;
00379       MSG("LIAnalysis",Msg::kDebug) 
00380         <<"calibPoint="<<calibPoint 
00381         <<", pulseHeight="<<pulseHeight
00382         <<", pulseWidth="<<pulseWidth
00383         <<", led="<<led
00384         <<endl;
00385     }
00386     lastLed2=led;
00387     lastPulserBox2=pulserBox;
00388     lastCalibPoint2=calibPoint;
00389   }
00390 
00391   //set important variables to determine sizes of 
00392   //arrays of histograms etc
00393   numLeds=maxLedNum;
00394   numLiRuns=liRunNum+1;
00395   numLiEvents=liEvent+1;
00396   numCalibPoints=maxCalibPoint;
00397       
00398   MSG("LIAnalysis",Msg::kInfo) 
00399     <<endl
00400     <<" ** File Summary Information ** "<<endl
00401     <<"maxLedNum="<<maxLedNum<<endl
00402     <<"maxPbNum="<<maxPbNum<<endl
00403     <<"maxCalibPoint="<<maxCalibPoint<<endl
00404     <<"numLiRuns="<<numLiRuns
00405     <<", numLiRuns*maxLedNum="<<numLiRuns*maxLedNum<<endl
00406     <<"numLiEvents="<<numLiEvents<<endl;
00407 
00408   MSG("LIAnalysis",Msg::kInfo) 
00409     <<"Number of times each led was selected (any pulser box):" 
00410     <<endl;
00411   for (Int_t i=0;i<NUMLEDS;i++){
00412     MSG("LIAnalysis",Msg::kInfo) 
00413       <<"  LED "<<i+1<<" = "<<numLiEventsL[i] 
00414       <<endl;
00415   }
00416 
00417   MSG("LIAnalysis",Msg::kInfo) 
00418     <<"Number of times each pulser box was selected:"<<endl;
00419   for (Int_t i=0;i<NUMPULSERBOXES;i++){
00420     MSG("LIAnalysis",Msg::kInfo) 
00421       <<"  Pulser Box "<<i<<" = "<<numLiEventsP[i]
00422       <<endl;
00423   }
00424   
00425   MSG("LIAnalysis",Msg::kInfo) 
00426     <<"Number of times each calibration point was selected:" 
00427     <<endl;
00428   for (Int_t i=0;i<maxCalibPoint;i++){
00429     MSG("LIAnalysis",Msg::kInfo) 
00430       <<"  Calibration Point "<<i+1<<" = "<<numLiEventsC[i]
00431       <<endl;
00432   }
00433   MSG("LIAnalysis",Msg::kInfo) 
00434     <<" ** End of File Summary Information ** "<<endl;
00435 }
00436 
00437 //......................................................................
00438 
00439 void LIAnalysis::InitialiseLoopVariables()
00440 {
00441   MSG("LIAnalysis",Msg::kInfo)<<"Initialising loop variables..."<<endl;
00442 
00443   liEvent=-1;//want first event to be 0 not 1
00444   lastLed=-1;
00445   lastPulserBox=-1;
00446   lastCalibPoint=-1;
00447   liRunNum=0;
00448   run=0;
00449 
00450   //get first event
00451   chain->GetEvent(0);  
00452   previousRunNumber=runNumber;
00453 
00454   MSG("LIAnalysis",Msg::kInfo)<<"Initialisation complete"<<endl;
00455 }
00456 
00457 //......................................................................
00458 
00459 void LIAnalysis::SetLoopVariables(Int_t entry,Int_t printOnNewLed,
00460                                   Bool_t doInfoPrint)
00461 {
00462 
00463   Float_t fract=ceil(numEvents/10.);
00464   
00465   if (entry==10 && doInfoPrint) { 
00466     TDatime datime;
00467     datime.Set(timestamp);
00468     MSG("LIAnalysis",Msg::kInfo)<<" Timestamp1"<<setw(3)<<(Int_t)(100.*(entry+1)/numEvents)<<" %: "<<datime.GetDate()<<" "
00469                                 <<datime.GetYear()<<" "<<setw(2)<<datime.GetMonth()<<" "<<setw(2)<<datime.GetDay()<<" "
00470                                 <<setw(2)<<datime.GetHour()<<" "<<setw(2)<<datime.GetMinute()<<" "<<setw(2)<<datime.GetSecond()<<endl;
00471   } 
00472   if ((entry==numEvents-1 || ceil(((Float_t)entry)/fract)==((Float_t)entry)/fract) &&doInfoPrint){
00473     MSG("LIAnalysis",Msg::kInfo) 
00474       <<"Fraction of loop complete: "<<entry+1 
00475       <<"/"<<numEvents<<"  ("
00476       <<(Int_t)(100.*(entry+1)/numEvents)<<"%)"<<endl;
00477 
00478     TDatime datime;
00479     datime.Set(timestamp);
00480     MSG("LIAnalysis",Msg::kInfo)<<" Timestamp "<<setw(3)<<(Int_t)(100.*(entry+1)/numEvents)<<" %: "<<datime.GetDate()<<" "
00481                                 <<datime.GetYear()<<" "<<setw(2)<<datime.GetMonth()<<" "<<setw(2)<<datime.GetDay()<<" "
00482                                 <<setw(2)<<datime.GetHour()<<" "<<setw(2)<<datime.GetMinute()<<" "<<setw(2)<<datime.GetSecond()<<endl;
00483   }
00484 
00485   chain->GetEvent(entry); 
00486 
00487   if (runNumber<lowRunNumber) lowRunNumber=runNumber;
00488   if (runNumber>highRunNumber) highRunNumber=runNumber;
00489 
00490   if (runNumber!=previousRunNumber) {
00491     run++;
00492     if(doInfoPrint) MSG("LIAnalysis",Msg::kInfo) 
00493       << " ** Found new run number = "
00494       <<runNumber
00495       <<" (previous run number = "
00496       <<previousRunNumber<<")"
00497       <<", run="<<run<<endl;
00498   }
00499   previousRunNumber=runNumber;
00500 
00501   //calculate which set of pulses is currently being looped through
00502   if (lastLed-led>0 && lastPulserBox-pulserBox>0){
00503     liRunNum++;
00504   }
00505 
00506   if (lastPulserBox-pulserBox>0 || 
00507       (lastLed-led>0 && lastCalibPoint-calibPoint>0)){
00508     TDatime datime;
00509     datime.Set(timestamp);
00510     if(doInfoPrint) MSG("LIAnalysis",Msg::kInfo) <<"Next set: "
00511                                                  <<"Pulser Box="<<pulserBox
00512                                                  <<", first led in set="<<led
00513                                                  <<", calibType="
00514                                                  <<calibType<<endl;
00515     
00516     MSG("LIAnalysis",Msg::kDebug)
00517       <<"PH="<<pulseHeight
00518       <<", PW="<<pulseWidth
00519       <<", tstamp="<<timestamp 
00520       <<",  time="<<datime.GetTime() 
00521       <<",  date="<<datime.GetDate()
00522       <<endl;
00523   }
00524   
00525   //calculate whether a new led is being flashed
00526   if (led!=lastLed){
00527     liEvent++;//defined as a new LED flashing
00528     //print out which led is being analysed
00529     if (printOnNewLed==1&&doInfoPrint){
00530       this->PrintBlockInfo(" ** New point: ");
00531     }
00532   }
00533 
00534   lastLed=led;    
00535   lastPulserBox=pulserBox;
00536   lastCalibPoint=calibPoint;
00537 }  
00538 
00539 //......................................................................
00540 
00541 TGraph* LIAnalysis::TGraphVect(vector<Double_t>& vX,
00542                                vector<Double_t>& vY)
00543 {
00544   MSG("LIPlexMaps",Msg::kDebug) 
00545     <<" ** Running TGraphVect method... **"<<endl;
00546 
00547   TGraph* g=new TGraph(vX.size());
00548 
00549   for (UInt_t i=0;i<vX.size();i++){
00550     g->SetPoint(i,vX[i],vY[i]);
00551   }
00552 
00553   MSG("LIPlexMaps",Msg::kDebug) 
00554     <<" ** Finished TGraphVect method **"<<endl;
00555   return g;
00556 }
00557 
00558 //......................................................................
00559 
00560 void LIAnalysis::AppendVect(vector<Double_t>& trunk,
00561                             vector<Double_t> appendix)
00562 {
00563   MSG("LIAnalysis",Msg::kDebug) 
00564     <<" ** Running AppendVect method... **"<<endl;
00565   
00566   //should this work?
00567   //trunk.insert(trunk.end(),appendix.begin(),appendix.end());
00568 
00569   for (UInt_t i=0;i<appendix.size();i++){
00570     trunk.push_back(appendix[i]);
00571   }
00572 
00573   MSG("LIAnalysis",Msg::kDebug) 
00574     <<" ** Finished AppendVect method **"<<endl;
00575 }
00576 
00577 //......................................................................
00578   
00579 void LIAnalysis::PrintBlockInfo(string preString)
00580 {
00581   MSG("LIAnalysis",Msg::kVerbose)<<"PrintBlockInfo..."<<endl;
00582 
00583   MSG("LIAnalysis",Msg::kVerbose) 
00584     <<"Number of seconds="<<timestamp<<endl;
00585   
00586   TDatime datime;
00587   datime.Set(timestamp);
00588   
00589   //play around with the formatting a little
00590   string sHour=Form("%d",datime.GetHour());
00591   string sMinute=Form("%d",datime.GetMinute());
00592   string sSecond=Form("%d",datime.GetSecond());
00593   string sMonth=Form("%d",datime.GetMonth());
00594   string sDay=Form("%d",datime.GetDay());
00595   if (datime.GetHour()<10) sHour="0"+sHour;
00596   if (datime.GetMinute()<10) sMinute="0"+sMinute;
00597   if (datime.GetSecond()<10) sSecond="0"+sSecond;
00598   if (datime.GetMonth()<10) sMonth="0"+sMonth;
00599   if (datime.GetDay()<10) sDay="0"+sDay;
00600 
00601   //protect from fpe
00602   Double_t pulseFreq=-1;
00603   if (period!=0) pulseFreq=ceil(1.0/(period*1.0e-5));
00604   string sPulseFreq=Form("%d",static_cast<Int_t>(pulseFreq));
00605   string sPeriod=Form("%d",static_cast<Int_t>(period));
00606   if (pulseFreq<0) sPulseFreq="??? (period="+sPeriod+")";
00607 
00608   MSG("LIAnalysis",Msg::kInfo) 
00609     <<preString 
00610     <<"PB="<<pulserBox 
00611     <<" Led="<<led
00612     <<" CP="<<calibPoint
00613     <<"/"<<calibType
00614     <<" PH="<<pulseHeight
00615     <<" PW="<<pulseWidth
00616     <<" PF="<<sPulseFreq
00617     <<" PN="<<pulses
00618     <<" at "<<sHour
00619     <<":"<<sMinute
00620     <<":"<<sSecond
00621     <<" on "<<datime.GetYear()
00622     <<"/"<<sMonth
00623     <<"/"<<sDay
00624     <<endl;
00625 
00626   MSG("LIAnalysis",Msg::kVerbose) 
00627     <<"PrintBlockInfo method finished"<<endl;
00628 }
00629  
00630 //......................................................................
00631 
00632 void LIAnalysis::PrintBigMessage()
00633 { 
00634   MSG("LIAnalysis",Msg::kInfo) 
00635     <<"("<<pulserBox<<":"<<led<<")";
00636     
00637   if (elecType==ElecType::kVA){
00638     MSG("LIAnalysis",Msg::kInfo) 
00639       <<"VA("<<crate<<","<<varc<<","<<vmm<<","<<vfb
00640       <<","<<chip<<","<<channel<<")";
00641   }
00642   else if (elecType==ElecType::kQIE){
00643     MSG("LIAnalysis",Msg::kInfo) 
00644       <<"QIE("<<crate<<","<<geoAdd<<","<<masterCh<<","<<minderCh<<")";
00645   }
00646   
00647   MSG("LIAnalysis",Msg::kInfo) 
00648     <<", (m,r,n)=("<<mean<<","<<rms
00649     <<","<<numEntries<<"), cHit="<<correlatedHit
00650     <<", e/w="<<eastWest<<", rt="<<readoutType
00651     <<" (Pl;St)=("<<plane<<";"<<strip<<")"<<endl;
00652 }
00653 
00654 //......................................................................
00655 
00656 void LIAnalysis::PrintElec()
00657 {
00658   MSG("LIAnalysis",Msg::kInfo) 
00659     <<endl<<" ** Running the PrintElec method... ** "<<endl;
00660   
00664 
00665   this->InitialiseLoopVariables();  
00666   
00667   for(Int_t entry=0;entry<5000;entry++){
00668     //  for(Int_t entry=0;entry<numEvents;entry++){
00669     
00670     this->SetLoopVariables(entry,0);
00671     
00672     MSG("LIAnalysis",Msg::kDebug) 
00673       <<"QIE("<<crate<<","<<geoAdd<<","<<masterCh<<","<<minderCh<<")"
00674       <<", VA("<<crate<<","<<varc<<","<<vmm<<","<<vfb<<","<<chip
00675       <<","<<channel<<")"
00676       <<" mean="<<mean<<endl;
00677     
00678     if (crate>0 && correlatedHit==1 && numEntries<0.999*pulses &&
00679         lookup.NearOrFar(crate,pulserBox,nearPulserBox,
00680                          farPulserBox,led,detectorType,
00681                          plane,runNumber)==LILookup::kNearSide){
00682       MSG("LIAnalysis",Msg::kInfo)
00683         <<endl<<"******************************"<<endl
00684         <<this->GetElecString()<<", CH="<<correlatedHit
00685         <<" (P;S)=("<<plane<<";"<<strip<<")"
00686         <<" (m,r,n)=("<<static_cast<Int_t>(mean)
00687         <<","<<static_cast<Int_t>(rms)<<","<<numEntries<<")"
00688         <<endl<<"******************************"<<endl;
00689     }
00690     else if (crate>0 && 
00691              lookup.NearOrFar(crate,pulserBox,nearPulserBox,
00692                               farPulserBox,led,detectorType,
00693                               plane,runNumber)==LILookup::kNearSide){
00694       MSG("LIAnalysis",Msg::kInfo)
00695         <<this->GetElecString()<<", CH="<<correlatedHit
00696         <<" (P;S)=("<<plane<<";"<<strip<<")"
00697         <<" (m,r,n)=("<<static_cast<Int_t>(mean)
00698         <<","<<static_cast<Int_t>(rms)<<","<<numEntries<<")"
00699         <<endl;
00700     }
00701 
00702   }//end of for
00703   
00707   
00708   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
00709 
00710   MSG("LIAnalysis",Msg::kInfo) 
00711     <<endl<<" ** Finished the PrintElec method ** "<<endl;
00712 }
00713 
00714 //......................................................................
00715 
00716 void LIAnalysis::PrintPmt()
00717 {
00718   MSG("LIAnalysis",Msg::kInfo) 
00719     <<endl<<" ** Running the PrintPmt method... ** "<<endl;
00720   
00721   //chain->SetBranchAddress("eastWest",&eastWest);
00722   //chain->SetBranchAddress("inRack",&inRack);
00724   //chain->SetBranchAddress("rackBay",&rackBay);
00725   //chain->SetBranchAddress("rackLevel",&rackLevel);
00726 
00730 
00731   this->InitialiseLoopVariables();  
00732   
00733   for(Int_t entry=0;entry<numEvents;entry++){
00734     
00735     this->SetLoopVariables(entry,1);
00736     
00737     //only look at scint
00738     if (readoutType!=ReadoutType::kScintStrip) continue;
00739 
00740     MSG("LIAnalysis",Msg::kInfo) 
00741       <<this->GetElecString()
00742       <<"E/W="<<eastWest<<", rLevel="<<rackLevel<<", rBay="<<rackBay
00743       <<", inRack="<<inRack<<", muxBox="<<numericMuxBox<<endl;
00744     
00745   }//end of for
00746   
00750   
00751   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
00752 
00753   MSG("LIAnalysis",Msg::kInfo) 
00754     <<endl<<" ** Finished the PrintPmt method ** "<<endl;
00755 }
00756 
00757 //......................................................................
00758 
00759 void LIAnalysis::PrintGainTableRow(Int_t pl,Int_t st,Int_t end,
00760                                    string sPrefix,
00761                                    string sAdcN,string sGainN,
00762                                    string sGainErrN,string sNumN,
00763                                    string sAdcF,string sGainF,
00764                                    string sGainErrF,string sNumF,
00765                                    string sLogLevel)
00766 {
00767   MSG("LIAnalysis",Msg::kVerbose) 
00768     <<endl<<" ** Running the PrintGainTableRow method... ** "<<endl;
00769   
00770   //Msg::LogLevel_t logLevel=Msg::kDebug;
00771 
00772   Msg::LogLevel_t logLevel=Msg::GetLevelCode(sLogLevel.c_str());
00773 
00774   MSG("LIAnalysis",logLevel)
00775     <<"("<<pl<<";"<<st<<";"<<end<<")"
00776     <<sPrefix
00777     <<" Near(m,g,ge,n)=("<<sAdcN
00778     <<","<<sGainN
00779     <<","<<sGainErrN
00780     <<","<<sNumN<<")"
00781     <<", Far=("<<sAdcF
00782     <<","<<sGainF
00783     <<","<<sGainErrF
00784     <<","<<sNumF<<")"
00785     <<endl;
00786   
00787   MSG("LIAnalysis",Msg::kVerbose) 
00788     <<endl<<" ** Finished the PrintGainTableRow method ** "<<endl;
00789 }
00790 
00791 //......................................................................
00792 
00793 string LIAnalysis::GetElecString()
00794 {
00795   MSG("LISummarySorter",Msg::kVerbose) 
00796     <<"Running GetElecString method..."<<endl;
00797 
00798   string elecString="";
00799   string sCrate=Form("%d",crate);
00800 
00801   if (elecType==ElecType::kVA){
00802     string sVarc=Form("%d",varc);
00803     string sVmm=Form("%d",vmm);
00804     string sVfb=Form("%d",vfb);
00805     string sChip=Form("%d",chip);
00806     string sElecType="VA";
00807     
00808     elecString=sElecType+
00809       "("+sCrate+","+sVarc+","+sVmm+","+sVfb+","+sChip+")";
00810   }     
00811   else if (elecType==ElecType::kQIE){
00812     string sGeoAdd=Form("%d",geoAdd);
00813     string sMasterCh=Form("%d",masterCh);
00814     string sMinderCh=Form("%d",minderCh);
00815     string sElecType="QIE";
00816     
00817     elecString=sElecType+
00818       "("+sCrate+","+sGeoAdd+","+sMasterCh+","+sMinderCh+")";
00819   }
00820   return elecString;
00821 }
00822 
00823 //......................................................................
00824 
00825 void LIAnalysis::ClearFibres()
00826 {
00827   MSG("LIAnalysis",Msg::kInfo) 
00828     <<endl<<" ** Running the ClearFibres method... ** "<<endl;
00829 
00830   //these are the PHs that give you 8000 ADCs minus the
00831   //turn on point for each led
00832   //rather than the explicit turn on point I chose the 
00833   //value at which 1000 ADCs because light
00834   //level as a function of pulse height would seem
00835   //less likely to be linear when the led first turns on
00836   //I know that light level is proportional to PH 
00837   //for most of the PHs from looking at the pin response
00838   //(data for PB 11 with the new-new UV leds)
00839   Double_t ph[20]={155,175,140,125,145,
00840                    100,110,100,120,80,
00841                    80,80,60,125,120,
00842                    110,110,125,95,135};
00843 
00844   Double_t led[20]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
00845 
00846   TCanvas *cPhVsLed=new TCanvas("cPhVsLed","cPhVsLed",
00847                                     0,0,1200,600);
00848   cPhVsLed->SetFillColor(0);
00849   cPhVsLed->cd();
00850 
00851   TGraph* gPhVsLed=new TGraph(20,led,ph);
00852   gPhVsLed->Draw("AP");
00853   s="Corrected Pulse Height Vs Led Number";
00854   gPhVsLed->SetTitle(s.c_str());
00855   gPhVsLed->GetXaxis()->SetTitle("Led Number");
00856   gPhVsLed->GetYaxis()->SetTitle
00857     ("Corrected Pulse Height (for 8000 ADCs)");
00858   gPhVsLed->GetXaxis()->CenterTitle();
00859   gPhVsLed->GetYaxis()->CenterTitle();
00860   gPhVsLed->SetMarkerStyle(3);
00861   gPhVsLed->SetMarkerColor(2);
00862   gPhVsLed->SetMarkerSize(0.5);
00863   gPhVsLed->SetMinimum(0);
00864 
00865   MSG("LIAnalysis",Msg::kInfo) 
00866     <<" ** Finished the ClearFibres method ** "<<endl;
00867 }
00868 
00869 //......................................................................
00870 
00871 void LIAnalysis::SearchForBadLeds(Int_t minNumHits)
00872 {
00873   MSG("LIAnalysis",Msg::kInfo) 
00874     <<endl<<" ** Running the SearchForBadLeds method... ** "<<endl;
00875 
00876   vector<Int_t> numHits(NUMLEDS*NUMPULSERBOXES,0);
00877 
00881 
00882   this->InitialiseLoopVariables();  
00883   
00884   for(Int_t entry=0;entry<numEvents;entry++){
00885     
00886     this->SetLoopVariables(entry,0);
00887     
00888     //only look at scint
00889     if (readoutType!=ReadoutType::kScintStrip) continue;
00890 
00891     //avoid divide by zero errors and skip irrelevant data
00892     if (rms==0. || mean==0. || numEntries==0) continue;
00893 
00894     Int_t l=pulserBox*NUMLEDS+led-1;
00895 
00896 //these were the dead ones:
00897 // (5:2) only has 1 hits
00898 // (5:5) only has 0 hits
00899 // (5:10) only has 0 hits
00900 // (8:11) only has 1 hits
00901 // (8:12) only has 3 hits
00902 // (8:15) only has 1 hits
00903 // (8:18) only has 82 hits
00904 // (8:19) only has 1 hits
00905 // (8:20) only has 0 hits
00906 // (12:15) only has 0 hits
00907 // (12:16) only has 0 hits
00908 // (14:10) only has 0 hits
00909 // (14:13) only has 3 hits
00910 
00911     if (true==false && ((pulserBox==5 && led==2) ||
00912         (pulserBox==5 && led==5) ||
00913         (pulserBox==5 && led==10) ||
00914 
00915         (pulserBox==8 && led==11) ||
00916         (pulserBox==8 && led==12) ||
00917         (pulserBox==8 && led==15) ||
00918         (pulserBox==8 && led==18) ||
00919         (pulserBox==8 && led==19) ||
00920         (pulserBox==8 && led==20) ||
00921 
00922         (pulserBox==12 && led==15) ||
00923         (pulserBox==12 && led==16) ||
00924 
00925         (pulserBox==14 && led==10) ||
00926         (pulserBox==14 && led==13))){
00927 
00928         this->PrintBigMessage();
00929     }
00930 
00931     if (pulserBox>=FIRSTPULSERBOX && pulserBox<=LASTPULSERBOX && 
00932         correlatedHit==1 &&
00933         led>=FIRSTLED && led<=LASTLED){
00934         numHits[l]++;
00935     }
00936   }//end of for
00937 
00941 
00942   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
00943 
00944   Int_t counter=0;
00945 
00946   //print all 
00947   MSG("LIAnalysis",Msg::kInfo)
00948     <<endl<<"Printing number of hits on all leds..."<<endl;
00949   for (Int_t i=0;i<NUMPULSERBOXES;i++){
00950     for (Int_t j=0;j<NUMLEDS;j++){
00951       Int_t l=i*NUMLEDS+j;
00952       MSG("LIAnalysis",Msg::kInfo)
00953         <<"("<<i<<":"<<j+1<<") has "<<numHits[l]<<" hits"<<endl;
00954       if (numHits[l]<minNumHits) counter++;
00955     }
00956   }
00957 
00958   MSG("LIAnalysis",Msg::kInfo)
00959     <<endl<<counter<<" leds have a low number of hits:"<<endl;
00960   for (Int_t i=0;i<NUMPULSERBOXES;i++){
00961     for (Int_t j=0;j<NUMLEDS;j++){
00962       Int_t l=i*NUMLEDS+j;
00963       if (numHits[l]<minNumHits){
00964         MSG("LIAnalysis",Msg::kInfo)
00965           <<"("<<i<<":"<<j+1<<") only has "<<numHits[l]<<" hits"<<endl;
00966       }
00967     }
00968   }
00969 
00970   MSG("LIAnalysis",Msg::kInfo) 
00971     <<" ** Finished the SearchForBadLeds method ** "<<endl;
00972 }
00973 
00974 //......................................................................
00975 
00976 void LIAnalysis::PinDiodeChips()
00977 {
00978   MSG("LIAnalysis",Msg::kInfo) 
00979     <<endl<<" ** Running the PinDiodeChips method... ** "<<endl;
00980 
00981   TH1F *hChipHigh=new TH1F("hChipHigh","Pin Diode Chips",5,-1.,4.);
00982   hChipHigh->GetXaxis()->SetTitle("chip");
00983   hChipHigh->GetXaxis()->CenterTitle();
00984   hChipHigh->GetYaxis()->SetTitle("Num Entries");
00985   hChipHigh->GetYaxis()->CenterTitle();
00986   hChipHigh->SetFillColor(0);
00987   hChipHigh->SetLineColor(2);
00988   hChipHigh->SetBit(TH1::kCanRebin);
00989 
00990   TH1F *hChipLow=new TH1F("hChipLow","Pin Diode Chips",
00991                           5,-1.,4.);
00992   hChipLow->GetXaxis()->SetTitle("chip");
00993   hChipLow->GetXaxis()->CenterTitle();
00994   hChipLow->GetYaxis()->SetTitle("Num Entries");
00995   hChipLow->GetYaxis()->CenterTitle();
00996   hChipLow->SetFillColor(0);
00997   hChipLow->SetLineColor(3);
00998   hChipLow->SetBit(TH1::kCanRebin);
00999 
01000   Int_t pinsOnPulserBox=0;
01001   Int_t totalPins=0;
01002   Int_t correlatedPins=0;
01003   Int_t zeroRmsPins=0; 
01004 
01008 
01009   this->InitialiseLoopVariables();  
01010   
01011   for(Int_t entry=0;entry<numEvents;entry++){
01012     
01013     this->SetLoopVariables(entry,0);
01014     
01015     //only look at pin diodes
01016     if (readoutType!=ReadoutType::kPinDiode) continue;
01017 
01018     //avoid divide by zero errors and skip irrelevant data
01019     if (rms==0. || mean==0. || numEntries==0){
01020 
01021       MSG("LIAnalysis",Msg::kVerbose)
01022         <<"led="<<led<<", pb="<<pulserBox
01023         <<", mean="<<mean
01024         <<", rms="<<rms
01025         <<", numEntries="<<numEntries
01026         <<endl;
01027       zeroRmsPins++;
01028       if (pulserBox==nearPulserBox) pinsOnPulserBox++;
01029       if (correlatedHit==1) correlatedPins++;
01030       totalPins++;
01031       continue;    
01032     }
01033 
01034     if (pulserBox==nearPulserBox) pinsOnPulserBox++;
01035     if (correlatedHit==1) correlatedPins++;
01036     totalPins++;
01037 
01038     if (pinGain==0) hChipHigh->Fill(chip);
01039     else if (pinGain==1) hChipLow->Fill(chip);
01040     else MSG("LIAnalysis",Msg::kInfo)<<"Pin gain="<<pinGain<<endl;
01041 
01042   }//end of for
01043 
01047 
01048   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
01049 
01050   MSG("LIAnalysis",Msg::kInfo)
01051     <<endl
01052     <<"pinsOnPulserBox = "<<pinsOnPulserBox<<" of "<<totalPins
01053     <<" ("<<100.*pinsOnPulserBox/totalPins<<"%)"
01054     <<endl
01055     <<"correlatedPins = "<<correlatedPins<<" of "<<totalPins
01056     <<" ("<<100.*correlatedPins/totalPins<<"%)"
01057     <<endl
01058     <<"zeroRmsPins = "<<zeroRmsPins<<" of "<<totalPins
01059     <<" ("<<100.*zeroRmsPins/totalPins<<"%)"
01060     <<endl
01061     //<<"Pins accounted for above = "<<zeroRmsPins+correlatedPins+
01062     //pinsOnPulserBox<<" of "<<totalPins
01063     <<endl;
01064   
01065   //hRackLevel->Fill(rackLevel);
01066   //hEastWest->Fill(eastWest);
01067   //hNumericMuxBox->Fill(numericMuxBox);
01068   //hInRack->Fill(inRack);
01069   //hRackBay->Fill(rackBay);
01070   //hPinGain->Fill(pinGain);
01071   //hPinInBox->Fill(pinInBox);
01072 
01073   TCanvas *cPinChip=new TCanvas("cPinChip","cPinChip",1,1,800,600);
01074   cPinChip->SetFillColor(0);
01075   hChipHigh->Draw();
01076   hChipLow->Draw("same");
01077 
01078   MSG("LIAnalysis",Msg::kInfo) 
01079     <<" ** Finished the PinDiodeChips method ** "<<endl;
01080 }
01081 
01082 //......................................................................
01083 
01084 void LIAnalysis::AdcVsPin()
01085 {
01086   MSG("LIAnalysis",Msg::kInfo) 
01087     <<endl<<" ** Running the AdcVsPin method... ** "<<endl;
01088 
01089   Int_t numAdcBins=150;
01090 
01091   //histos for different pins, high gain
01092   TH1F **hAdcHighPin=0;
01093   hAdcHighPin= new TH1F*[NUMLEDS*NUMPULSERBOXES];
01094   for (Int_t i=0;i<NUMPULSERBOXES;i++){
01095     for (Int_t j=0;j<NUMLEDS;j++){
01096       //calculate array number
01097       Int_t l=i*NUMLEDS+j;
01098       //initialse histos
01099       sprintf(histname,"High Gain PIN Adc Distribution, PB %d, LED %d",
01100               i,j+1);
01101       hAdcHighPin[l]=new TH1F(histname,histname,numAdcBins,0,15000);
01102       hAdcHighPin[l]->GetXaxis()->SetTitle("ADC");
01103       hAdcHighPin[l]->GetXaxis()->CenterTitle();
01104       hAdcHighPin[l]->GetYaxis()->SetTitle("Number of Entries");
01105       hAdcHighPin[l]->GetYaxis()->CenterTitle();
01106       hAdcHighPin[l]->SetFillColor(0);
01107       hAdcHighPin[l]->SetLineColor(2);
01108       hAdcHighPin[l]->Fill(1);
01109       //hAdcHighPin[l]->SetBit(TH1::kCanRebin);
01110     }
01111   }
01112  
01113   //histos for different pins, low gain
01114   TH1F **hAdcLowPin=0;
01115   hAdcLowPin= new TH1F*[NUMLEDS*NUMPULSERBOXES];
01116   for (Int_t i=0;i<NUMPULSERBOXES;i++){
01117     for (Int_t j=0;j<NUMLEDS;j++){
01118       //calculate array number
01119       Int_t l=i*NUMLEDS+j;
01120       //initialse histos
01121       sprintf(histname,"Low Gain PIN Adc Distribution, PB %d, LED %d",
01122               i,j+1);
01123       hAdcLowPin[l]=new TH1F(histname,histname,numAdcBins,0,15000);
01124       hAdcLowPin[l]->GetXaxis()->SetTitle("ADC");
01125       hAdcLowPin[l]->GetXaxis()->CenterTitle();
01126       hAdcLowPin[l]->GetYaxis()->SetTitle("Number of Entries");
01127       hAdcLowPin[l]->GetYaxis()->CenterTitle();
01128       hAdcLowPin[l]->SetFillColor(0);
01129       hAdcLowPin[l]->SetLineColor(3);
01130       hAdcLowPin[l]->Fill(1);
01131       //hAdcLowPin[l]->SetBit(TH1::kCanRebin);
01132     }
01133   }
01134 
01135   Float_t* maxAdcHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01136   Float_t* maxAdcLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01137   Float_t* rmsHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01138   Float_t* rmsLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01139   Float_t* rms2HighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01140   Float_t* rms2LowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01141   Float_t* numHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01142   Float_t* numLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01143 
01144   //initialise arrays
01145   for (Int_t i=0;i<NUMLEDS*NUMPULSERBOXES;i++){ 
01146     maxAdcHighPin[i]=0;
01147     maxAdcLowPin[i]=0;
01148     rmsHighPin[i]=0;
01149     rmsLowPin[i]=0;
01150     rms2HighPin[i]=0;
01151     rms2LowPin[i]=0;
01152     numHighPin[i]=0;
01153     numLowPin[i]=0;
01154   }
01155 
01159    
01160   this->InitialiseLoopVariables();   
01161    
01162   for(Int_t entry=0;entry<numEvents;entry++){ 
01163      
01164     this->SetLoopVariables(entry,0); 
01165      
01166     //ignore any zeros 
01167     if (mean==0 || rms==0 || numEntries==0) continue; 
01168     
01169     //only look at pins 
01170     if (readoutType!=ReadoutType::kPinDiode) continue; 
01171 
01172     //cut out strange pins with high mean
01173     if (numEntries<0.8*pulses) continue;
01174 
01175     if (pulserBox>=FIRSTPULSERBOX && pulserBox<=LASTPULSERBOX &&
01176         led>=FIRSTLED && led<=LASTLED){
01177       //define led number
01178       Int_t l=pulserBox*NUMLEDS+led-1;
01179 
01180       if (numEntries<0.5*pulses && mean>1000){
01181         MSG("LIAnalysis",Msg::kInfo)
01182           <<"**** Strange pin: ("<<pulserBox<<":"<<led
01183           <<") on"
01184           <<" "<<this->GetElecString()
01185           <<", plex gain="<<pinGain<<", mean="<<mean<<", rms="<<rms
01186           <<", num="<<numEntries<<", cHit="<<correlatedHit<<endl;
01187       }
01188       
01189       //will require a correlated hit when plex is working
01190       //fill histo for appropriate pin
01191       if (chip==1){//high gain (=0) (chip 1)
01192         hAdcHighPin[l]->Fill(mean);
01193         //find max value for high gain pin
01194         if (mean>maxAdcHighPin[l]) {
01195           maxAdcHighPin[l]=mean;
01196           rmsHighPin[l]=rms;
01197           rms2HighPin[l]=rms*rms;
01198           numHighPin[l]=numEntries;
01199           MSG("LIAnalysis",Msg::kInfo)
01200             <<"HG Pin ("<<pulserBox<<":"<<led
01201             <<") on"
01202             <<" "<<this->GetElecString()
01203             <<", plex gain="<<pinGain<<", mean="<<mean<<", rms="<<rms
01204             <<", num="<<numEntries<<", cHit="<<correlatedHit<<endl;
01205         }
01206       }
01207       else if (chip==0){//low gain (=1) (chip 0)
01208         hAdcLowPin[l]->Fill(mean);
01209         //find max value for low gain pin
01210         if (mean>maxAdcLowPin[l]) {
01211           maxAdcLowPin[l]=mean;
01212           rmsLowPin[l]=rms;
01213           rms2LowPin[l]=rms*rms;
01214           numLowPin[l]=numEntries;
01215           MSG("LIAnalysis",Msg::kInfo)
01216             <<"LG Pin ("<<pulserBox<<":"<<led
01217             <<") on"
01218             <<" "<<this->GetElecString()
01219             <<", plex gain="<<pinGain<<", mean="<<mean<<", rms="<<rms
01220             <<", num="<<numEntries<<", cHit="<<correlatedHit<<endl;
01221         }
01222       }
01223 
01224       //print out warnings if there are inconsistencies
01225       if ((pinGain!=1 && chip==0) || (pinGain!=0 && chip==1)) {
01226         MSG("LIAnalysis",Msg::kDebug)
01227           <<"**** Strange pin, wrong gain in plex,"
01228           <<" "<<this->GetElecString()
01229           <<", plex gain="<<pinGain<<", mean="<<mean<<", rms="<<rms
01230           <<", num="<<numEntries<<", cHit="<<correlatedHit<<endl;
01231       }
01232     }
01233   }//end of for
01234 
01238  
01239   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
01240  
01241   //include the under and overflow counts 
01242   gStyle->SetOptStat(1111111); 
01243   //set up useful string 
01244   string sRunNumber=Form("%d",runNumber); 
01245   string sLowRunNumber=Form("%d",lowRunNumber);
01246   
01247   MSG("LIAnalysis",Msg::kInfo)
01248     <<"List of pins:"<<endl;
01249   MSG("LIAnalysis",Msg::kInfo)
01250     <<"  HG pins:"<<endl;
01251   for (Int_t i=0;i<NUMPULSERBOXES;i++){
01252     for (Int_t j=0;j<NUMLEDS;j++){
01253       Int_t l=i*NUMLEDS+j;  
01254       MSG("LIAnalysis",Msg::kInfo)
01255         <<"    ("<<i<<":"<<j+1<<") mean="<<maxAdcHighPin[l]
01256         <<", rms="<<rmsHighPin[l]
01257         <<", num="<<numHighPin[l]<<endl;
01258     }
01259   }
01260 
01261   MSG("LIAnalysis",Msg::kInfo)
01262     <<"  LG pins:"<<endl;
01263   for (Int_t i=0;i<NUMPULSERBOXES;i++){
01264     for (Int_t j=0;j<NUMLEDS;j++){
01265       Int_t l=i*NUMLEDS+j;
01266       MSG("LIAnalysis",Msg::kInfo)
01267         <<"    ("<<i<<":"<<j+1<<") mean="<<maxAdcLowPin[l]
01268         <<", rms="<<rmsLowPin[l]
01269         <<", num="<<numLowPin[l]<<endl;
01270     }
01271   }
01272 
01273   //get the maximum in order to scale all plots
01274   Int_t maxNumEnt=0;
01275   for (Int_t i=0;i<NUMPULSERBOXES*NUMLEDS;i++){
01276     if (hAdcHighPin[i]->GetMaximum()>maxNumEnt){
01277       maxNumEnt=static_cast<Int_t>(hAdcHighPin[i]->GetMaximum());
01278       MSG("LIAnalysis",Msg::kInfo)
01279         <<"Calculating max number of entries, current highest="
01280         <<maxNumEnt<<", l="<<i<<endl;
01281     }
01282   }
01283 
01284   for (Int_t i=0;i<NUMPULSERBOXES*NUMLEDS;i++){
01285     if (hAdcLowPin[i]->GetMaximum()>maxNumEnt){
01286       maxNumEnt=static_cast<Int_t>(hAdcLowPin[i]->GetMaximum());
01287       MSG("LIAnalysis",Msg::kInfo)
01288         <<"Calculating max number of entries (low), current highest="
01289         <<maxNumEnt<<", l="<<i<<endl;
01290     }
01291   }
01292 
01293   //allocate space for TGraphs then loop and fill them below
01294   TGraphAsymmErrors *gErrorsAdcHighPin=new 
01295     TGraphAsymmErrors(NUMPULSERBOXES*NUMLEDS);
01296   TGraphAsymmErrors *gErrorsAdcLowPin=new 
01297     TGraphAsymmErrors(NUMPULSERBOXES*NUMLEDS);
01298   TGraph *gAdcHighPin=new TGraph(NUMPULSERBOXES*NUMLEDS);
01299   TGraph *gAdcLowPin=new TGraph(NUMPULSERBOXES*NUMLEDS);
01300   TGraph *gRmsHighPin=new TGraph(NUMPULSERBOXES*NUMLEDS);
01301   TGraph *gRmsLowPin=new TGraph(NUMPULSERBOXES*NUMLEDS);
01302   TGraph *gRms2HighPin=new TGraph(NUMPULSERBOXES*NUMLEDS);
01303   TGraph *gRms2LowPin=new TGraph(NUMPULSERBOXES*NUMLEDS);
01304   TGraph *gNumHighPin=new TGraph(NUMPULSERBOXES*NUMLEDS);
01305   TGraph *gNumLowPin=new TGraph(NUMPULSERBOXES*NUMLEDS);
01306   TGraph *gResHighPin=new TGraph(NUMPULSERBOXES*NUMLEDS);
01307   TGraph *gResLowPin=new TGraph(NUMPULSERBOXES*NUMLEDS);
01308 
01309 
01310   gAdcHighPin->SetMinimum(0);
01311   gAdcLowPin->SetMinimum(0);
01312   gRmsHighPin->SetMinimum(0);
01313   gRmsLowPin->SetMinimum(0);
01314   gRms2HighPin->SetMinimum(0);
01315   gRms2LowPin->SetMinimum(0);
01316   gNumHighPin->SetMinimum(0);
01317   gNumLowPin->SetMinimum(0);
01318   gResHighPin->SetMinimum(0);  
01319   gResLowPin->SetMinimum(0);
01320 
01321   //create the canvas and draw
01322   TCanvas *cAdcPin=new TCanvas("cAdcPin","cAdcPin",0,0,1000,600);
01323   cAdcPin->SetFillColor(0);
01324   cAdcPin->cd();
01325   for (Int_t i=0;i<NUMPULSERBOXES;i++){
01326     for (Int_t j=0;j<NUMLEDS;j++){
01327       Int_t l=i*NUMLEDS+j;
01328 
01329       //set points for graphs
01330       gErrorsAdcHighPin->SetPoint(l,static_cast<Float_t>(l+1),
01331                                   maxAdcHighPin[l]);
01332       gErrorsAdcLowPin->SetPoint(l,static_cast<Float_t>(l+1),
01333                                  maxAdcLowPin[l]);
01334       gAdcHighPin->SetPoint(l,static_cast<Float_t>(l+1),
01335                             maxAdcHighPin[l]);
01336       gAdcLowPin->SetPoint(l,static_cast<Float_t>(l+1),maxAdcLowPin[l]);
01337 
01338       gRmsHighPin->SetPoint(l,static_cast<Float_t>(l+1),rmsHighPin[l]);
01339       gRmsLowPin->SetPoint(l,static_cast<Float_t>(l+1),rmsLowPin[l]);
01340       gRms2HighPin->SetPoint(l,static_cast<Float_t>(l+1),
01341                              rms2HighPin[l]);
01342       gRms2LowPin->SetPoint(l,static_cast<Float_t>(l+1),rms2LowPin[l]);
01343       gNumHighPin->SetPoint(l,static_cast<Float_t>(l+1),numHighPin[l]);
01344       gNumLowPin->SetPoint(l,static_cast<Float_t>(l+1),numLowPin[l]);
01345       if (maxAdcHighPin[l]>0){
01346         gResHighPin->SetPoint(l,static_cast<Float_t>(l+1),
01347                               rmsHighPin[l]/maxAdcHighPin[l]);
01348       }
01349       else {
01350         gResHighPin->SetPoint(l,static_cast<Float_t>(l+1),0);
01351       }
01352       if (maxAdcLowPin[l]>0){
01353         gResLowPin->SetPoint(l,static_cast<Float_t>(l+1),
01354                              rmsLowPin[l]/maxAdcLowPin[l]);
01355       }
01356       else {
01357         gResLowPin->SetPoint(l,static_cast<Float_t>(l+1),0);
01358       }
01359 
01360       //plot histograms
01361       cAdcPin->Clear();
01362       hAdcHighPin[l]->SetMaximum(maxNumEnt);
01363       string sPulserBox=Form("%d",i);
01364       string sLed=Form("%d",j+1);
01365       string sPulseWidth=Form("%d",pulseWidth);
01366       string sPulseHeight=Form("%d",pulseHeight);
01367       string sPulseFreq=Form("%d",static_cast<Int_t>
01368                              (ceil(1.0/(period*1.0e-5))));
01369       MSG("LIAnalysis",Msg::kDebug)
01370         <<"LI parameters: "
01371         <<", PB="<<sPulserBox
01372         <<", LED="<<sLed
01373         <<", PH="<<sPulseHeight
01374         <<", PW="<<sPulseWidth
01375         <<", PF="<<sPulseFreq
01376         <<endl;
01377       s="Pin ADC Values (High&Low Gain, PB="+sPulserBox+
01378         ", LED="+sLed+", PH="+sPulseHeight+", PW="+sPulseWidth+
01379         ", PF="+sPulseFreq+" Hz)";
01380       hAdcHighPin[l]->SetTitle(s.c_str());
01381 
01382       Int_t draw=1;
01383       if (draw==1){
01384         hAdcHighPin[l]->Draw();
01385         hAdcLowPin[l]->Draw("same");
01386         if (i*NUMLEDS+j==0){
01387           if (sLowRunNumber==sRunNumber) s=sRunNumber+
01388                                              "PinAdcHisto.ps(";
01389           else s=sLowRunNumber+"-"+sRunNumber+"PinAdcHisto.ps(";
01390           cAdcPin->Print(s.c_str());
01391           gErrorIgnoreLevel=1;
01392         }
01393         else if(i*NUMLEDS+j==NUMLEDS*NUMPULSERBOXES-1){
01394           gErrorIgnoreLevel=0;
01395           if (sLowRunNumber==sRunNumber) s=sRunNumber+
01396                                              "PinAdcHisto.ps)";
01397           else s=sLowRunNumber+"-"+sRunNumber+"PinAdcHisto.ps)";
01398           cAdcPin->Print(s.c_str());
01399           MSG("LIAnalysis",Msg::kInfo)<<"Done last plot"<<endl;  
01400         }
01401         else{
01402           if (sLowRunNumber==sRunNumber) s=sRunNumber+
01403                                              "PinAdcHisto.ps";
01404           else s=sLowRunNumber+"-"+sRunNumber+"PinAdcHisto.ps";
01405           cAdcPin->Print(s.c_str());
01406         }
01407       }
01408     }
01409   }
01410   cAdcPin->Clear();
01411   hAdcHighPin[0]->Draw();
01412   hAdcLowPin[0]->Draw("same");
01413 
01414   //set strings for use in titles
01415   string sPulseWidth=Form("%d",pulseWidth);
01416   string sPulseHeight=Form("%d",pulseHeight);
01417   string sPulseFreq=Form("%d",static_cast<Int_t>
01418                          (ceil(1.0/(period*1.0e-5))));
01419   string sPulses=Form("%d",pulses);
01420   string sConstantBit="";
01421 
01422   if (runNumber>=13123){//don't use pulse height
01423     Int_t fph=pulseHeight;
01424     chain->GetEvent(numEvents-1);
01425     Int_t lph=-10;//pulseHeight;
01426     
01427     MSG("LIAnalysis",Msg::kInfo)
01428       <<"first ph="<<fph<<", last ph="<<lph<<endl;
01429 
01430     if (lph==fph){
01431       sConstantBit=+", PH="+sPulseHeight+", PW="+sPulseWidth+
01432         ", PF="+sPulseFreq+" Hz, PN="+sPulses+")";
01433     }
01434     else if (lph!=fph){
01435       sConstantBit=+", PW="+sPulseWidth+
01436         ", PF="+sPulseFreq+" Hz, PN="+sPulses+")";
01437     } 
01438   }
01439   else{
01440     sConstantBit=+", PH="+sPulseHeight+", PW="+sPulseWidth+
01441       ", PF="+sPulseFreq+" Hz, PN="+sPulses+")";
01442   }
01443 
01445   //draw the adc graph
01447   TCanvas *cAdcPinGraph=new TCanvas("cAdcPinGraph","cAdcPinGraph",
01448                                     0,0,1200,600);
01449   cAdcPinGraph->SetFillColor(0);
01450   cAdcPinGraph->cd();
01451   gAdcHighPin->Draw("AP");
01452   s="Max Pin ADC vs LED (High&Low"+sConstantBit;
01453   gAdcHighPin->SetTitle(s.c_str());
01454   gAdcHighPin->GetXaxis()->SetTitle("Pulser Box * NUM PINS + LED");
01455   gAdcHighPin->GetYaxis()->SetTitle("Average ADC");
01456   gAdcHighPin->GetXaxis()->CenterTitle();
01457   gAdcHighPin->GetYaxis()->CenterTitle();
01458   gAdcHighPin->SetMarkerStyle(3);
01459   gAdcHighPin->SetMarkerColor(2);
01460   gAdcHighPin->SetMarkerSize(0.2);
01461   gAdcHighPin->SetLineColor(46);
01462 
01463   gAdcLowPin->Draw("P");
01464   gAdcLowPin->SetTitle(s.c_str());
01465   gAdcLowPin->SetMarkerStyle(3);
01466   gAdcLowPin->SetMarkerColor(3);
01467   gAdcLowPin->SetMarkerSize(0.3);
01468   gAdcLowPin->SetLineColor(30);
01469   //print graph to postscript
01470   if (sLowRunNumber==sRunNumber) s=sRunNumber+"PinAdcVsLed.ps(";
01471   else s=sLowRunNumber+"-"+sRunNumber+"PinAdcVsLed.ps(";
01472   //cAdcPinGraph->Modified();
01473   gAdcHighPin->SetMinimum(0);
01474   cAdcPinGraph->Print(s.c_str());
01475 
01476   //draw the adc high graph
01477   cAdcPinGraph->Clear();
01478   cAdcPinGraph->cd();
01479   //gAdcHighPin->SetMaximum(4000);
01480   gAdcHighPin->Draw("AP");
01481   s="Max Pin Adc vs LED (High Gain"+sConstantBit;
01482   gAdcHighPin->SetTitle(s.c_str());
01483   gAdcHighPin->GetXaxis()->SetTitle("Pulser Box * NUMLEDS + Led");
01484   gAdcHighPin->GetYaxis()->SetTitle("Average Adc");
01485   gAdcHighPin->GetXaxis()->CenterTitle();
01486   gAdcHighPin->GetYaxis()->CenterTitle();
01487   gAdcHighPin->SetMarkerStyle(3);
01488   gAdcHighPin->SetMarkerColor(2);
01489   gAdcHighPin->SetMarkerSize(0.2);
01490   gAdcHighPin->SetLineColor(46);
01491   //print graph to postscript
01492   if (sLowRunNumber==sRunNumber) s=sRunNumber+"PinAdcVsLed.ps";
01493   else s=sLowRunNumber+"-"+sRunNumber+"PinAdcVsLed.ps";
01494   gAdcHighPin->SetMinimum(0);
01495   cAdcPinGraph->Print(s.c_str());
01496 
01497   //draw the adc low graph
01498   cAdcPinGraph->Clear();
01499   cAdcPinGraph->cd();
01500   //gAdcLowPin->SetMaximum(2000);
01501   gAdcLowPin->Draw("AP");
01502   s="Max Pin Adc vs LED (Low Gain"+sConstantBit;
01503   gAdcLowPin->SetTitle(s.c_str());
01504   gAdcLowPin->GetXaxis()->SetTitle("Pulser Box * NUMLEDS + Led");
01505   gAdcLowPin->GetYaxis()->SetTitle("Average Adc");
01506   gAdcLowPin->GetXaxis()->CenterTitle();
01507   gAdcLowPin->GetYaxis()->CenterTitle();
01508   gAdcLowPin->SetMarkerStyle(3);
01509   gAdcLowPin->SetMarkerColor(3);
01510   gAdcLowPin->SetMarkerSize(0.2);
01511   gAdcLowPin->SetLineColor(30);
01512   //print graph to postscript
01513   if (sLowRunNumber==sRunNumber) s=sRunNumber+"PinAdcVsLed.ps)";
01514   else s=sLowRunNumber+"-"+sRunNumber+"PinAdcVsLed.ps)";
01515   gAdcLowPin->SetMinimum(0);
01516   cAdcPinGraph->Print(s.c_str());
01517 
01519   //draw the rms graph
01521   TCanvas *cRmsPinGraph=new TCanvas("cRmsPinGraph","cRmsPinGraph",
01522                                     0,0,1200,600);
01523   cRmsPinGraph->SetFillColor(0);
01524   cRmsPinGraph->cd();
01525   gRmsHighPin->Draw("AP");
01526   s="Pin RMS vs LED (High&Low Gain"+sConstantBit;
01527   gRmsHighPin->SetTitle(s.c_str());
01528   gRmsHighPin->GetXaxis()->SetTitle("Pulser Box * NUMLEDS + Led");
01529   gRmsHighPin->GetYaxis()->SetTitle("Average Rms");
01530   gRmsHighPin->GetXaxis()->CenterTitle();
01531   gRmsHighPin->GetYaxis()->CenterTitle();
01532   gRmsHighPin->SetMarkerStyle(3);
01533   gRmsHighPin->SetMarkerColor(2);
01534   gRmsHighPin->SetMarkerSize(0.2);
01535   gRmsHighPin->SetLineColor(46);
01536 
01537   gRmsLowPin->Draw("P");
01538   gRmsLowPin->SetTitle(s.c_str());
01539   gRmsLowPin->SetMarkerStyle(3);
01540   gRmsLowPin->SetMarkerColor(3);
01541   gRmsLowPin->SetMarkerSize(0.3);
01542   gRmsLowPin->SetLineColor(30);
01543   //print graph to postscript
01544   if (sLowRunNumber==sRunNumber) s=sRunNumber+"PinRmsVsLed.ps(";
01545   else s=sLowRunNumber+"-"+sRunNumber+"PinRmsVsLed.ps(";
01546   gRmsHighPin->SetMinimum(0);
01547   cRmsPinGraph->Print(s.c_str());
01548 
01549   //draw the rms high graph
01550   cRmsPinGraph->Clear();
01551   cRmsPinGraph->cd();
01552   gRmsHighPin->SetMaximum(100);
01553   gRmsHighPin->Draw("AP");
01554   s="Pin RMS vs LED (High Gain"+sConstantBit;
01555   gRmsHighPin->SetTitle(s.c_str());
01556   gRmsHighPin->GetXaxis()->SetTitle("Pulser Box * NUMLEDS + Led");
01557   gRmsHighPin->GetYaxis()->SetTitle("Average Rms");
01558   gRmsHighPin->GetXaxis()->CenterTitle();
01559   gRmsHighPin->GetYaxis()->CenterTitle();
01560   gRmsHighPin->SetMarkerStyle(3);
01561   gRmsHighPin->SetMarkerColor(2);
01562   gRmsHighPin->SetMarkerSize(0.2);
01563   gRmsHighPin->SetLineColor(46);
01564   //print graph to postscript
01565   if (sLowRunNumber==sRunNumber) s=sRunNumber+"PinRmsVsLed.ps";
01566   else s=sLowRunNumber+"-"+sRunNumber+"PinRmsVsLed.ps";
01567   gRmsHighPin->SetMinimum(0);
01568   cRmsPinGraph->Print(s.c_str());
01569 
01570   //draw the rms low graph
01571   cRmsPinGraph->Clear();
01572   cRmsPinGraph->cd();
01573   gRmsLowPin->SetMaximum(100);
01574   gRmsLowPin->Draw("AP");
01575   s="Pin RMS vs LED (Low Gain"+sConstantBit;
01576   gRmsLowPin->SetTitle(s.c_str());
01577   gRmsLowPin->GetXaxis()->SetTitle("Pulser Box * NUMLEDS + Led");
01578   gRmsLowPin->GetYaxis()->SetTitle("Average Rms");
01579   gRmsLowPin->GetXaxis()->CenterTitle();
01580   gRmsLowPin->GetYaxis()->CenterTitle();
01581   gRmsLowPin->SetMarkerStyle(3);
01582   gRmsLowPin->SetMarkerColor(3);
01583   gRmsLowPin->SetMarkerSize(0.2);
01584   gRmsLowPin->SetLineColor(30);
01585   //print graph to postscript
01586   if (sLowRunNumber==sRunNumber) s=sRunNumber+"PinRmsVsLed.ps)";
01587   else s=sLowRunNumber+"-"+sRunNumber+"PinRmsVsLed.ps)";
01588   gRmsLowPin->SetMinimum(0);
01589   cRmsPinGraph->Print(s.c_str());
01590 
01592   //draw the rms2 graph
01594   TCanvas *cRms2PinGraph=new TCanvas("cRms2PinGraph","cRms2PinGraph",
01595                                     0,0,1200,600);
01596   cRms2PinGraph->SetFillColor(0);
01597   cRms2PinGraph->cd();
01598   gRms2HighPin->Draw("AP");
01599   s="Pin RMS Sqd vs LED (High&Low Gain"+sConstantBit;
01600   gRms2HighPin->SetTitle(s.c_str());
01601   gRms2HighPin->GetXaxis()->SetTitle("Pulser Box * NUMLEDS + Led");
01602   gRms2HighPin->GetYaxis()->SetTitle("Average Rms2");
01603   gRms2HighPin->GetXaxis()->CenterTitle();
01604   gRms2HighPin->GetYaxis()->CenterTitle();
01605   gRms2HighPin->SetMarkerStyle(3);
01606   gRms2HighPin->SetMarkerColor(2);
01607   gRms2HighPin->SetMarkerSize(0.2);
01608   gRms2HighPin->SetLineColor(46);
01609 
01610   gRms2LowPin->Draw("P");
01611   gRms2LowPin->SetTitle(s.c_str());
01612   gRms2LowPin->SetMarkerStyle(3);
01613   gRms2LowPin->SetMarkerColor(3);
01614   gRms2LowPin->SetMarkerSize(0.3);
01615   gRms2LowPin->SetLineColor(30);
01616   //print graph to postscript
01617   if (sLowRunNumber==sRunNumber) s=sRunNumber+"PinRms2VsLed.ps(";
01618   else s=sLowRunNumber+"-"+sRunNumber+"PinRms2VsLed.ps(";
01619   cRms2PinGraph->Print(s.c_str());
01620 
01621   //draw the rms2 high graph
01622   cRms2PinGraph->Clear();
01623   cRms2PinGraph->cd();
01624   //gRms2HighPin->SetMaximum(1500);
01625   gRms2HighPin->Draw("AP");
01626   s="Pin RMS Sqd vs LED (High Gain"+sConstantBit;
01627   gRms2HighPin->SetTitle(s.c_str());
01628   gRms2HighPin->GetXaxis()->SetTitle("Pulser Box * NUMLEDS + Led");
01629   gRms2HighPin->GetYaxis()->SetTitle("Average Rms2");
01630   gRms2HighPin->GetXaxis()->CenterTitle();
01631   gRms2HighPin->GetYaxis()->CenterTitle();
01632   gRms2HighPin->SetMarkerStyle(3);
01633   gRms2HighPin->SetMarkerColor(2);
01634   gRms2HighPin->SetMarkerSize(0.2);
01635   gRms2HighPin->SetLineColor(46);
01636   //print graph to postscript
01637   if (sLowRunNumber==sRunNumber) s=sRunNumber+"PinRms2VsLed.ps";
01638   else s=sLowRunNumber+"-"+sRunNumber+"PinRms2VsLed.ps";
01639   cRms2PinGraph->Print(s.c_str());
01640 
01641   //draw the rms2 low graph
01642   cRms2PinGraph->Clear();
01643   cRms2PinGraph->cd();
01644   //gRms2LowPin->SetMaximum(300);
01645   gRms2LowPin->Draw("AP");
01646   s="Pin RMS Sqd vs LED (Low Gain"+sConstantBit;
01647   gRms2LowPin->SetTitle(s.c_str());
01648   gRms2LowPin->GetXaxis()->SetTitle("Pulser Box * NUMLEDS + Led");
01649   gRms2LowPin->GetYaxis()->SetTitle("Average Rms2");
01650   gRms2LowPin->GetXaxis()->CenterTitle();
01651   gRms2LowPin->GetYaxis()->CenterTitle();
01652   gRms2LowPin->SetMarkerStyle(3);
01653   gRms2LowPin->SetMarkerColor(3);
01654   gRms2LowPin->SetMarkerSize(0.2);
01655   gRms2LowPin->SetLineColor(30);
01656   //print graph to postscript
01657   if (sLowRunNumber==sRunNumber) s=sRunNumber+"PinRms2VsLed.ps)";
01658   else s=sLowRunNumber+"-"+sRunNumber+"PinRms2VsLed.ps)";
01659   cRms2PinGraph->Print(s.c_str());
01660 
01662   //draw the num graph
01664   TCanvas *cNumPinGraph=new TCanvas("cNumPinGraph","cNumPinGraph",
01665                                     0,0,1200,600);
01666   cNumPinGraph->SetFillColor(0);
01667   cNumPinGraph->cd();
01668   gNumHighPin->Draw("AP");
01669   gNumHighPin->SetMinimum(0);
01670   gNumHighPin->SetMaximum(pulses+200);
01671   s="Pin hits vs LED (High&Low Gain"+sConstantBit;
01672   gNumHighPin->SetTitle(s.c_str());
01673   gNumHighPin->GetXaxis()->SetTitle("Pulser Box * NUMLEDS + Led");
01674   gNumHighPin->GetYaxis()->SetTitle("Number of Pulses");
01675   gNumHighPin->GetXaxis()->CenterTitle();
01676   gNumHighPin->GetYaxis()->CenterTitle();
01677   gNumHighPin->SetMarkerStyle(3);
01678   gNumHighPin->SetMarkerColor(2);
01679   gNumHighPin->SetMarkerSize(0.2);
01680   gNumHighPin->SetLineColor(46);
01681 
01682   gNumLowPin->Draw("P");
01683   gNumLowPin->SetMinimum(0);
01684   gNumLowPin->SetMaximum(pulses+200);
01685   gNumLowPin->SetTitle(s.c_str());
01686   gNumLowPin->SetMarkerStyle(3);
01687   gNumLowPin->SetMarkerColor(3);
01688   gNumLowPin->SetMarkerSize(0.3);
01689   gNumLowPin->SetLineColor(30);
01690   //print graph to postscript
01691   if (sLowRunNumber==sRunNumber) s=sRunNumber+"PinNumVsLed.ps(";
01692   else s=sLowRunNumber+"-"+sRunNumber+"PinNumVsLed.ps(";
01693   cNumPinGraph->Print(s.c_str());
01694 
01695   //draw the num high graph
01696   cNumPinGraph->Clear();
01697   cNumPinGraph->cd();
01698   //gNumHighPin->SetMaximum(50);
01699   gNumHighPin->Draw("AP");
01700   s="Pin hits vs LED (High Gain"+sConstantBit;
01701   gNumHighPin->SetTitle(s.c_str());
01702   gNumHighPin->GetXaxis()->SetTitle("Pulser Box * NUMLEDS + Led");
01703   gNumHighPin->GetYaxis()->SetTitle("Number of Pulses");
01704   gNumHighPin->GetXaxis()->CenterTitle();
01705   gNumHighPin->GetYaxis()->CenterTitle();
01706   gNumHighPin->SetMarkerStyle(3);
01707   gNumHighPin->SetMarkerColor(2);
01708   gNumHighPin->SetMarkerSize(0.2);
01709   gNumHighPin->SetLineColor(46);
01710   //print graph to postscript
01711   if (sLowRunNumber==sRunNumber) s=sRunNumber+"PinNumVsLed.ps";
01712   else s=sLowRunNumber+"-"+sRunNumber+"PinNumVsLed.ps";
01713   cNumPinGraph->Print(s.c_str());
01714 
01715   //draw the num low graph
01716   cNumPinGraph->Clear();
01717   cNumPinGraph->cd();
01718   //gNumLowPin->SetMaximum(50);
01719   gNumLowPin->Draw("AP");
01720   s="Pin hits vs LED (Low Gain"+sConstantBit;
01721   gNumLowPin->SetTitle(s.c_str());
01722   gNumLowPin->GetXaxis()->SetTitle("Pulser Box * NUMLEDS + Led");
01723   gNumLowPin->GetYaxis()->SetTitle("Number of Pulses");
01724   gNumLowPin->GetXaxis()->CenterTitle();
01725   gNumLowPin->GetYaxis()->CenterTitle();
01726   gNumLowPin->SetMarkerStyle(3);
01727   gNumLowPin->SetMarkerColor(3);
01728   gNumLowPin->SetMarkerSize(0.2);
01729   gNumLowPin->SetLineColor(30);
01730   //print graph to postscript
01731   if (sLowRunNumber==sRunNumber) s=sRunNumber+"PinNumVsLed.ps)";
01732   else s=sLowRunNumber+"-"+sRunNumber+"PinNumVsLed.ps)";
01733   cNumPinGraph->Print(s.c_str());
01734 
01735 
01737   //draw the Res graph
01739   TCanvas *cResPinGraph=new TCanvas("cResPinGraph","cResPinGraph",
01740                                     0,0,1200,600);
01741   cResPinGraph->SetFillColor(0);
01742   cResPinGraph->cd();
01743   gResHighPin->Draw("AP");
01744   gResHighPin->SetMinimum(0);
01745   //gResHighPin->SetMaximum(pulses+200);
01746   s="Pin Resolution vs LED (High&Low Gain"+sConstantBit;
01747   gResHighPin->SetTitle(s.c_str());
01748   gResHighPin->GetXaxis()->SetTitle("Pulser Box * NUMLEDS + Led");
01749   gResHighPin->GetYaxis()->SetTitle("Resolution (rms/mean)");
01750   gResHighPin->GetXaxis()->CenterTitle();
01751   gResHighPin->GetYaxis()->CenterTitle();
01752   gResHighPin->SetMarkerStyle(3);
01753   gResHighPin->SetMarkerColor(2);
01754   gResHighPin->SetMarkerSize(0.2);
01755   gResHighPin->SetLineColor(46);
01756 
01757   gResLowPin->Draw("P");
01758   gResLowPin->SetMinimum(0);
01759   gResLowPin->SetMaximum(pulses+200);
01760   gResLowPin->SetTitle(s.c_str());
01761   gResLowPin->SetMarkerStyle(3);
01762   gResLowPin->SetMarkerColor(3);
01763   gResLowPin->SetMarkerSize(0.3);
01764   gResLowPin->SetLineColor(30);
01765   //print graph to postscript
01766   if (sLowRunNumber==sRunNumber) s=sRunNumber+"PinResVsLed.ps(";
01767   else s=sLowRunNumber+"-"+sRunNumber+"PinResVsLed.ps(";
01768   cResPinGraph->Print(s.c_str());
01769 
01770   //draw the Res high graph
01771   cResPinGraph->Clear();
01772   cResPinGraph->cd();
01773   gResHighPin->SetMaximum(0.2);
01774   gResHighPin->Draw("AP");
01775   s="Pin Resolution vs LED (High Gain"+sConstantBit;
01776   gResHighPin->SetTitle(s.c_str());
01777   gResHighPin->GetXaxis()->SetTitle("Pulser Box * NUMLEDS + Led");
01778   gResHighPin->GetYaxis()->SetTitle("Resolution (rms/mean)");
01779   gResHighPin->GetXaxis()->CenterTitle();
01780   gResHighPin->GetYaxis()->CenterTitle();
01781   gResHighPin->SetMarkerStyle(3);
01782   gResHighPin->SetMarkerColor(2);
01783   gResHighPin->SetMarkerSize(0.2);
01784   gResHighPin->SetLineColor(46);
01785   //print graph to postscript
01786   if (sLowRunNumber==sRunNumber) s=sRunNumber+"PinResVsLed.ps";
01787   else s=sLowRunNumber+"-"+sRunNumber+"PinResVsLed.ps";
01788   cResPinGraph->Print(s.c_str());
01789 
01790   //draw the Res low graph
01791   cResPinGraph->Clear();
01792   cResPinGraph->cd();
01793   gResLowPin->SetMaximum(0.2);
01794   gResLowPin->Draw("AP");
01795   s="Pin Resolution vs LED (Low Gain"+sConstantBit;
01796   gResLowPin->SetTitle(s.c_str());
01797   gResLowPin->GetXaxis()->SetTitle("Pulser Box * NUMLEDS + Led");
01798   gResLowPin->GetYaxis()->SetTitle("Resolution (rms/mean)");
01799   gResLowPin->GetXaxis()->CenterTitle();
01800   gResLowPin->GetYaxis()->CenterTitle();
01801   gResLowPin->SetMarkerStyle(3);
01802   gResLowPin->SetMarkerColor(3);
01803   gResLowPin->SetMarkerSize(0.2);
01804   gResLowPin->SetLineColor(30);
01805   //print graph to postscript
01806   if (sLowRunNumber==sRunNumber) s=sRunNumber+"PinResVsLed.ps)";
01807   else s=sLowRunNumber+"-"+sRunNumber+"PinResVsLed.ps)";
01808   cResPinGraph->Print(s.c_str());
01809 
01810   MSG("LIAnalysis",Msg::kInfo) 
01811     <<" ** Finished the AdcVsPin method ** "<<endl;
01812 }
01813 
01814 //......................................................................
01815 
01816 void LIAnalysis::DebugPins()
01817 {
01818   MSG("LIAnalysis",Msg::kInfo) 
01819     <<endl<<" ** Running the DebugPins method... ** "<<endl;
01820 
01821   Float_t* maxAdcHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01822   Float_t* maxAdcLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01823   Float_t* corrHitHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01824   Float_t* corrHitLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01825   Float_t* ledHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01826   Float_t* nearLedHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01827   Float_t* ledLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01828   Float_t* nearLedLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01829  
01830   Float_t* eastWestHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01831   Float_t* eastWestLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01832   Float_t* rackLevelHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01833   Float_t* rackLevelLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01834   Float_t* rackBayHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01835   Float_t* rackBayLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01836   Float_t* inRackHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01837   Float_t* inRackLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01838   Float_t* inBoxHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01839   Float_t* inBoxLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01840   Float_t* gainHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01841   Float_t* gainLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01842 
01843   Float_t* crateHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01844   Float_t* crateLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01845   Float_t* varcHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01846   Float_t* varcLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01847   Float_t* vmmHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01848   Float_t* vmmLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01849   Float_t* vfbHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01850   Float_t* vfbLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01851   Float_t* chipHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01852   Float_t* chipLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01853   Float_t* chAddHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01854   Float_t* chAddLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01855 
01856   Float_t* planeHighPin=new Float_t[NUMLEDS*NUMPULSERBOXES];
01857   Float_t* planeLowPin=new Float_t[NUMLEDS*NUMPULSERBOXES]; 
01858 
01859   //initialise arrays
01860   for (Int_t i=0;i<NUMLEDS*NUMPULSERBOXES;i++){ 
01861     maxAdcHighPin[i]=0;
01862     maxAdcLowPin[i]=0;
01863     corrHitHighPin[i]=-1;
01864     corrHitLowPin[i]=-1;
01865     ledHighPin[i]=0;
01866     nearLedHighPin[i]=0;
01867     ledLowPin[i]=0; 
01868     nearLedLowPin[i]=0; 
01869 
01870     eastWestHighPin[i]=0;
01871     eastWestLowPin[i]=0; 
01872     rackLevelHighPin[i]=0;
01873     rackLevelLowPin[i]=0; 
01874     rackBayHighPin[i]=0;
01875     rackBayLowPin[i]=0; 
01876     inRackHighPin[i]=0;
01877     inRackLowPin[i]=0; 
01878     inBoxHighPin[i]=0;
01879     inBoxLowPin[i]=0; 
01880     gainHighPin[i]=0;
01881     gainLowPin[i]=0;
01882 
01883     crateHighPin[i]=0;
01884     crateLowPin[i]=0; 
01885     varcHighPin[i]=0;
01886     varcLowPin[i]=0; 
01887     vmmHighPin[i]=0;
01888     vmmLowPin[i]=0; 
01889     vfbHighPin[i]=0;
01890     vfbLowPin[i]=0; 
01891     chipHighPin[i]=0;
01892     chipLowPin[i]=0; 
01893     chAddHighPin[i]=0;
01894     chAddLowPin[i]=0; 
01895 
01896     planeHighPin[i]=0;
01897     planeLowPin[i]=0; 
01898   }
01899 
01903    
01904   this->InitialiseLoopVariables();   
01905    
01906   for(Int_t entry=0;entry<numEvents;entry++){ 
01907      
01908     this->SetLoopVariables(entry,0); 
01909 
01910     //CalDet ND pins
01911     if (crate==1 && geoAdd==19 && masterCh==4 && 
01912         detectorType==Detector::kCalDet){
01913       this->PrintBigMessage();
01914     }
01915 
01916     //ignore any zeros that slipped through 
01917     if (mean==0 || rms==0 || numEntries==0) continue; 
01918     
01919     //only look at scint strips 
01920     if (readoutType!=ReadoutType::kPinDiode) continue; 
01921 
01922     //printout everything!
01923     if (MsgService::Instance()->IsActive("LIAnalysis",Msg::kDebug)){
01924       MSG("LIAnalysis",Msg::kInfo)  
01925         <<"("<<pulserBox<<":"<<led
01926         <<") CH="<<correlatedHit
01927         <<" ("<<static_cast<Int_t>(mean)
01928         <<","<<static_cast<Int_t>(rms)
01929         <<","<<numEntries
01930         <<"/"<<pulses
01931         <<"),"
01932         <<" "<<this->GetElecString()
01933         <<", mux=("<<eastWest
01934         <<","<<rackLevel
01935         <<","<<rackBay
01936         <<","<<inRack
01937         <<","<<pinInBox
01938         <<")"
01939         <<", gain="<<pinGain
01940         <<endl;   
01941     }
01942 
01943     //cut out strange pins with high mean
01944     if (numEntries<0.8*pulses) continue;
01945 
01946     if (pulserBox>=FIRSTPULSERBOX && pulserBox<=LASTPULSERBOX &&
01947         led>=FIRSTLED && led<=LASTLED){
01948       //define led number
01949       Int_t l=pulserBox*NUMLEDS+led-1;
01950       
01951       //will require a correlated hit when plex is working
01952       //fill histo for appropriate pin
01953       if (chip==1){//high gain (=0) (chip 1)
01954         //find max value for high gain pin
01955         if (mean>maxAdcHighPin[l]){
01956           maxAdcHighPin[l]=mean; 
01957           corrHitHighPin[l]=correlatedHit;
01958           ledHighPin[l]=led;
01959           nearLedHighPin[l]=nearLed;
01960 
01961           eastWestHighPin[l]=eastWest;
01962           rackLevelHighPin[l]=rackLevel;
01963           rackBayHighPin[l]=rackBay;
01964           inRackHighPin[l]=inRack;
01965           inBoxHighPin[l]=pinInBox;
01966           gainHighPin[l]=pinGain;
01967 
01968           crateHighPin[l]=crate;
01969           varcHighPin[l]=varc;
01970           vmmHighPin[l]=vmm;
01971           vfbHighPin[l]=vfb;
01972           chipHighPin[l]=chip;
01973           chAddHighPin[l]=chAdd;
01974           
01975           planeHighPin[l]=plane;
01976         }
01977       }
01978       else if (chip==0){//low gain (=1) (chip 0)
01979         //find max value for low gain pin
01980         if (mean>maxAdcLowPin[l]) {
01981           maxAdcLowPin[l]=mean; 
01982           corrHitLowPin[l]=correlatedHit;
01983           ledLowPin[l]=led; 
01984           nearLedLowPin[l]=nearLed; 
01985 
01986           eastWestLowPin[l]=eastWest;
01987           rackLevelLowPin[l]=rackLevel;
01988           rackBayLowPin[l]=rackBay;
01989           inRackLowPin[l]=inRack;
01990           inBoxLowPin[l]=pinInBox;
01991           gainLowPin[l]=pinGain;
01992 
01993           crateLowPin[l]=crate;
01994           varcLowPin[l]=varc;
01995           vmmLowPin[l]=vmm;
01996           vfbLowPin[l]=vfb;
01997           chipLowPin[l]=chip;
01998           chAddLowPin[l]=chAdd;
01999 
02000           planeLowPin[l]=plane;
02001         }
02002       }
02003       
02004       //print out warnings if there are inconsistencies
02005       if ((pinGain!=1 && chip==0) || (pinGain!=0 && chip==1)) {
02006         MSG("LIAnalysis",Msg::kVerbose)
02007           <<"Strange pin, wrong gain in plex,"
02008           <<" "<<this->GetElecString()
02009           <<", plex gain="<<pinGain<<", mean="<<mean<<", rms="<<rms
02010           <<", num="<<numEntries<<endl;
02011       }
02012     }
02013   }//end of for
02014 
02018  
02019   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
02020 
02021   //include the under and overflow counts 
02022   gStyle->SetOptStat(1111111); 
02023   //set up useful string 
02024   string sRunNumber=Form("%d",runNumber); 
02025   string sLowRunNumber=Form("%d",lowRunNumber);
02026   
02027   //loop over pins and print out low ones
02028   for (Int_t i=0;i<NUMPULSERBOXES;i++){ 
02029     for (Int_t j=0;j<NUMLEDS;j++){ 
02030       Int_t l=i*NUMLEDS+j; 
02031  
02032       //print out which pins have low pulse height 
02033       if (maxAdcHighPin[l]<500 && i!=11){ 
02034         MSG("LIAnalysis",Msg::kInfo) 
02035           <<"High pin has low max: PB="<<i<<", led="<<j+1 
02036           <<", mean="<<maxAdcHighPin[l]<<endl; 
02037       } 
02038       if (maxAdcLowPin[l]<200 && i!=11){  
02039         MSG("LIAnalysis",Msg::kInfo)  
02040           <<"Low pin has low max: PB="<<i<<", led="<<j+1  
02041           <<", mean="<<maxAdcLowPin[l]<<endl;  
02042       }  
02043     }
02044   }
02045 
02046   //loop over pins to compare led and nearLed
02047   MSG("LIAnalysis",Msg::kInfo) 
02048     <<endl<<"Comparing led and nearLed for pins"<<endl;
02049   for (Int_t i=0;i<NUMPULSERBOXES;i++){  
02050     for (Int_t j=0;j<NUMLEDS;j++){  
02051       Int_t l=i*NUMLEDS+j;  
02052   
02053       MSG("LIAnalysis",Msg::kInfo)  
02054         <<"("<<i<<":"<<j+1<<") High gain pin"
02055         <<" has nearLed="<<nearLedHighPin[l]
02056         <<" (mean="<<maxAdcHighPin[l]<<", plane="<<planeHighPin[l]<<")"
02057         <<endl;  
02058       MSG("LIAnalysis",Msg::kInfo)  
02059         <<"("<<i<<":"<<j+1<<") High gain pin"   
02060         <<" has nearLed="<<nearLedLowPin[l]
02061         <<" (mean="<<maxAdcLowPin[l]<<", plane="<<planeLowPin[l]<<")"
02062         <<endl<<endl;   
02063     }   
02064   } 
02065 
02066   TH1F *hVarc=new TH1F("hVarc","Varcs hit",6,-1,5);
02067   hVarc->GetXaxis()->SetTitle("Varc");
02068   hVarc->GetXaxis()->CenterTitle();
02069   hVarc->GetYaxis()->SetTitle("Number of times hit");
02070   hVarc->GetYaxis()->CenterTitle();
02071   hVarc->SetFillColor(0);
02072 
02073   TH1F *hVfb=new TH1F("hVfb","Vfbs hit",6,-1,5);
02074   hVfb->GetXaxis()->SetTitle("Vfb");
02075   hVfb->GetXaxis()->CenterTitle();
02076   hVfb->GetYaxis()->SetTitle("Number of times hit");
02077   hVfb->GetYaxis()->CenterTitle();
02078   hVfb->SetFillColor(0);
02079 
02080   TH1F *hVmm=new TH1F("hVmm","Vmms hit",9,-1,8);
02081   hVmm->GetXaxis()->SetTitle("Vmm");
02082   hVmm->GetXaxis()->CenterTitle();
02083   hVmm->GetYaxis()->SetTitle("Number of times hit");
02084   hVmm->GetYaxis()->CenterTitle();
02085   hVmm->SetFillColor(0);
02086 
02087   TH1F *hVarcW=new TH1F("hVarcW","Varcs hit",6,-1,5);
02088   hVarcW->GetXaxis()->SetTitle("Varc");
02089   hVarcW->GetXaxis()->CenterTitle();
02090   hVarcW->GetYaxis()->SetTitle("Number of times hit");
02091   hVarcW->GetYaxis()->CenterTitle();
02092   hVarcW->SetFillColor(0);
02093   hVarcW->SetLineColor(2);
02094 
02095   TH1F *hVfbW=new TH1F("hVfbW","Vfbs hit",6,-1,5);
02096   hVfbW->GetXaxis()->SetTitle("Vfb");
02097   hVfbW->GetXaxis()->CenterTitle();
02098   hVfbW->GetYaxis()->SetTitle("Number of times hit");
02099   hVfbW->GetYaxis()->CenterTitle();
02100   hVfbW->SetFillColor(0);
02101   hVfbW->SetLineColor(2);
02102 
02103   TH1F *hVmmW=new TH1F("hVmmW","Vmms hit",9,-1,8);
02104   hVmmW->GetXaxis()->SetTitle("Vmm");
02105   hVmmW->GetXaxis()->CenterTitle();
02106   hVmmW->GetYaxis()->SetTitle("Number of times hit");
02107   hVmmW->GetYaxis()->CenterTitle();
02108   hVmmW->SetFillColor(0);
02109   hVmmW->SetLineColor(2);
02110 
02111   MSG("LIAnalysis",Msg::kInfo) 
02112     <<endl<<"Making pin location histos..."<<endl;
02113   for (Int_t i=0;i<NUMPULSERBOXES;i++){  
02114     for (Int_t j=0;j<NUMLEDS;j++){  
02115       Int_t l=i*NUMLEDS+j;  
02116   
02117       Int_t side=i%2;
02118       
02119       if (side==0){
02120         hVarc->Fill(varcHighPin[l]);
02121         hVarc->Fill(varcLowPin[l]);
02122         hVmm->Fill(vmmHighPin[l]);
02123         hVmm->Fill(vmmLowPin[l]);
02124         hVfb->Fill(vfbHighPin[l]);
02125         hVfb->Fill(vfbLowPin[l]);
02126       }
02127       else if (side==1){
02128         hVarcW->Fill(varcHighPin[l]);
02129         hVarcW->Fill(varcLowPin[l]);
02130         if (varcLowPin[l]==0){
02131           MSG("LIAnalysis",Msg::kInfo)  
02132             <<"Low pin ("<<i<<":"<<j+1
02133             <<") nL="<<nearLedLowPin[l]
02134             <<", corrHit="<<corrHitLowPin[l]
02135             <<" VA("<<crateLowPin[l]
02136             <<","<<varcLowPin[l]
02137             <<","<<vmmLowPin[l]
02138             <<","<<vfbLowPin[l]
02139             <<","<<chipLowPin[l]
02140             <<")="<<chAddLowPin[l]
02141             <<", ("<<eastWestLowPin[l]
02142             <<","<<rackLevelLowPin[l]
02143             <<","<<rackBayLowPin[l]
02144             <<","<<inRackLowPin[l]
02145             <<","<<inBoxLowPin[l]
02146             <<","<<gainLowPin[l]
02147             <<")"
02148             <<endl<<endl;   
02149         }
02150         if (varcHighPin[l]==0){
02151           MSG("LIAnalysis",Msg::kInfo)  
02152             <<"High pin ("<<i<<":"<<j+1  
02153             <<") nL="<<nearLedHighPin[l]
02154             <<", corrHit="<<corrHitHighPin[l]
02155             <<" VA("<<crateHighPin[l]
02156             <<","<<varcHighPin[l]
02157             <<","<<vmmHighPin[l]
02158             <<","<<vfbHighPin[l]
02159             <<","<<chipHighPin[l]
02160             <<")="<<chAddHighPin[l]
02161             <<", ("<<eastWestHighPin[l]
02162             <<","<<rackLevelHighPin[l]
02163             <<","<<rackBayHighPin[l]
02164             <<","<<inRackHighPin[l]
02165             <<","<<inBoxHighPin[l]
02166             <<","<<gainHighPin[l]
02167             <<")"
02168             <<endl;
02169         }
02170         
02171         hVmmW->Fill(vmmHighPin[l]);
02172         hVmmW->Fill(vmmLowPin[l]);
02173         hVfbW->Fill(vfbHighPin[l]);
02174         hVfbW->Fill(vfbLowPin[l]);
02175       }
02176       else{
02177         MSG("LIAnalysis",Msg::kInfo)  
02178           <<"Warning"<<endl;
02179       }
02180     }
02181   }
02182 
02183   MSG("LIAnalysis",Msg::kInfo) 
02184     <<endl<<"Comparing mux and elec info..."<<endl;
02185   for (Int_t i=0;i<NUMPULSERBOXES;i++){  
02186     //leave a line
02187     MSG("LIAnalysis",Msg::kInfo)<<endl;
02188     for (Int_t j=0;j<NUMLEDS;j++){  
02189       //get led index
02190       Int_t l=i*NUMLEDS+j;  
02191   
02192       MSG("LIAnalysis",Msg::kInfo)  
02193         <<"HG ("<<i<<":"<<j+1
02194         <<") nL="<<nearLedHighPin[l]
02195         <<", corrHit="<<corrHitHighPin[l]
02196         <<", VA("<<crateHighPin[l]
02197         <<","<<varcHighPin[l]
02198         <<","<<vmmHighPin[l]
02199         <<","<<vfbHighPin[l]
02200         <<","<<chipHighPin[l]
02201         <<")="<<chAddHighPin[l]
02202         <<", Position=("<<eastWestHighPin[l]
02203         <<","<<rackLevelHighPin[l]
02204         <<","<<rackBayHighPin[l]
02205         <<","<<inRackHighPin[l]
02206         <<","<<inBoxHighPin[l]
02207         <<","<<gainHighPin[l]
02208         <<")"
02209         <<endl;
02210   
02211       MSG("LIAnalysis",Msg::kInfo)   
02212         <<"LG ("<<i<<":"<<j+1   
02213         <<") nL="<<nearLedLowPin[l]
02214         <<", corrHit="<<corrHitLowPin[l]
02215         <<", VA("<<crateLowPin[l]
02216         <<","<<varcLowPin[l]
02217         <<","<<vmmLowPin[l]
02218         <<","<<vfbLowPin[l]
02219         <<","<<chipLowPin[l]
02220         <<")="<<chAddLowPin[l]
02221         <<", Position=("<<eastWestLowPin[l]
02222         <<","<<rackLevelLowPin[l]
02223         <<","<<rackBayLowPin[l]
02224         <<","<<inRackLowPin[l]
02225         <<","<<inBoxLowPin[l]
02226         <<","<<gainLowPin[l]
02227         <<")"
02228         <<endl<<endl;   
02229     }   
02230   } 
02231 
02232   MSG("LIAnalysis",Msg::kInfo) 
02233     <<endl<<endl<<"No data for these pins:"<<endl;
02234   for (Int_t i=0;i<NUMPULSERBOXES;i++){  
02235     //leave a line
02236     MSG("LIAnalysis",Msg::kInfo)<<endl;
02237     for (Int_t j=0;j<NUMLEDS;j++){  
02238       //get led index
02239       Int_t l=i*NUMLEDS+j;  
02240   
02241       if (corrHitHighPin[l]==-1){
02242         MSG("LIAnalysis",Msg::kInfo)  
02243           <<"HG ("<<i<<":"<<j+1
02244           <<") nL="<<nearLedHighPin[l]
02245           <<", corrHit="<<corrHitHighPin[l]
02246           <<", VA("<<crateHighPin[l]
02247           <<","<<varcHighPin[l]
02248           <<","<<vmmHighPin[l]
02249           <<","<<vfbHighPin[l]
02250           <<","<<chipHighPin[l]
02251           <<")="<<chAddHighPin[l]
02252           <<", Position=("<<eastWestHighPin[l]
02253           <<","<<rackLevelHighPin[l]
02254           <<","<<rackBayHighPin[l]
02255           <<","<<inRackHighPin[l]
02256           <<","<<inBoxHighPin[l]
02257           <<","<<gainHighPin[l]
02258           <<")"
02259           <<endl;
02260       }
02261 
02262       if (corrHitLowPin[l]==-1){
02263         MSG("LIAnalysis",Msg::kInfo)   
02264           <<"LG ("<<i<<":"<<j+1   
02265           <<") nL="<<nearLedLowPin[l]
02266           <<", corrHit="<<corrHitLowPin[l]
02267           <<", VA("<<crateLowPin[l]
02268           <<","<<varcLowPin[l]
02269           <<","<<vmmLowPin[l]
02270           <<","<<vfbLowPin[l]
02271           <<","<<chipLowPin[l]
02272           <<")="<<chAddLowPin[l]
02273           <<", Position=("<<eastWestLowPin[l]
02274           <<","<<rackLevelLowPin[l]
02275           <<","<<rackBayLowPin[l]
02276           <<","<<inRackLowPin[l]
02277           <<","<<inBoxLowPin[l]
02278           <<","<<gainLowPin[l]
02279           <<")"
02280           <<endl<<endl;   
02281       }
02282     }   
02283   } 
02284 
02285   //create the canvas and draw
02286   TCanvas *cPin=new TCanvas("cAdcPin","cAdcPin",0,0,1000,600);
02287   cPin->SetFillColor(0);
02288 
02289   cPin->Divide(2,2);
02290   cPin->cd(1);
02291   hVarc->Draw();
02292   hVarcW->Draw("same");
02293   cPin->cd(2);
02294   hVmm->Draw();
02295   hVmmW->Draw("same");
02296   cPin->cd(3);
02297   hVfb->Draw();
02298   hVfbW->Draw("same");
02299 
02300   //The pin diode information in the plex is as follows
02301   //The electronics information is in descending hierarchial order
02302   //(x:y) is pulser box x and led y
02303   //e.g. (crate,varc,vmm,vfb,VA chip,VA channel)
02304 
02305   //(0:1) Planes=41&43  Pin1=VA(0,2,0,0,0,18)  Pin2=VA(0,2,0,0,1,18)
02306   //(0:2) Planes=45&47  Pin1=VA(0,2,0,1,0,18)  Pin2=VA(0,2,0,1,1,18)
02307   //(0:3) Planes=49&51  Pin1=VA(0,2,1,0,0,18)  Pin2=VA(0,2,1,0,1,18)
02308   //(0:4) Planes=40&42  Pin1=VA(0,2,2,0,0,18)  Pin2=VA(0,2,2,1,1,18)
02309   //(0:5) Planes=44&46  Pin1=VA(0,2,3,0,0,18)  Pin2=VA(0,2,3,0,1,18)
02310   //(0:6) Planes=48&50  Pin1=VA(0,2,3,1,0,18)  Pin2=VA(0,2,3,1,1,18)
02311 
02312   MSG("LIAnalysis",Msg::kInfo) 
02313     <<" ** Finished the DebugPins method ** "<<endl;
02314 }
02315 
02316 //......................................................................
02317 
02318 void LIAnalysis::PinMap()
02319 {  
02320   MSG("LIAnalysis",Msg::kInfo) 
02321     <<endl<<" ** Running the PinMap method... ** "<<endl;
02322 
02323   Float_t numMux=NUMMUX;
02324   Float_t numRacks=NUMRACKS;
02325   const Int_t const_numCrates=static_cast<Int_t>(NUMRACKS/2.);
02326   const Int_t const_numRacks=static_cast<Int_t>(numRacks);
02327   const Int_t const_numMux=static_cast<Int_t>(numMux);
02328 
02329   TCanvas *cEast=new TCanvas("cEast","cEast",0,0,1200,800);
02330   cEast->SetFillColor(0);
02331 
02332   TCanvas *cWest=new TCanvas("cWest","cWest",0,0,1200,800);
02333   cWest->SetFillColor(0);
02334   cWest->cd();
02335 
02336   TText *titleE = new TText(0.28,0.955,
02337                             "Plex PIN Diode Map (East Side)");
02338   titleE->SetTextSize(0.045);
02339   TText *titleW = new TText(0.28,0.955,
02340                             "Plex PIN Diode Map (West Side)");
02341   titleW->SetTextSize(0.045);
02342   cEast->cd();
02343   titleE->Draw();
02344   cWest->cd();
02345   titleW->Draw();
02346 
02347   TPaveText *info=new TPaveText(0.75,0.94,1.0,1.0);
02348   info->SetBorderSize(0);
02349   info->SetFillColor(0);
02350   info->SetTextSize(0.018);
02351   info->SetTextColor(4);
02352   info->AddText("Numbers in mux boxes are LED numbers"); 
02353   info->AddText("Dark colour number is high gain pin");
02354   info->AddText("Mux box shading indicates Pulser Box"); 
02355   cEast->cd();
02356   info->Draw();
02357   cWest->cd();
02358   info->Draw();
02359   
02360   TPad *levelUE= new TPad("levelUE","pad for mux boxes",
02361                           0.01,0.59,0.99,0.94);
02362   TPad *levelME= new TPad("levelME","pad for crates",
02363                           0.01,0.39,0.99,0.56);
02364   TPad *levelLE= new TPad("levelLE","pad for mux boxes",
02365                           0.01,0.01,0.99,0.36);
02366   TPad *levelUW= new TPad("levelUW","pad for mux boxes",
02367                           0.01,0.59,0.99,0.94);
02368   TPad *levelMW= new TPad("levelMW","pad for crates",
02369                           0.01,0.39,0.99,0.56);
02370   TPad *levelLW= new TPad("levelLW","pad for mux boxes",
02371                           0.01,0.01,0.99,0.36);
02372 
02373   levelUE->SetFillColor(11);
02374   levelUE->SetBorderSize(3);
02375   levelUW->SetFillColor(11);
02376   levelUW->SetBorderSize(3);
02377 
02378   levelME->SetFillColor(11);
02379   levelME->SetBorderSize(2);
02380   levelMW->SetFillColor(11);
02381   levelMW->SetBorderSize(2);
02382 
02383   levelLE->SetFillColor(11);
02384   levelLE->SetBorderSize(1);
02385   levelLE->SetBorderMode(0);
02386   levelLW->SetFillColor(11);
02387   levelLW->SetBorderSize(1);
02388   levelLW->SetBorderMode(0);
02389 
02390   cEast->cd();
02391   levelUE->Draw();
02392   levelME->Draw();
02393   levelLE->Draw();
02394   cWest->cd();
02395   levelUW->Draw();
02396   levelMW->Draw();
02397   levelLW->Draw();
02398   
02399   TText *tLevelUE = new TText(0.01,0.89,
02400                               "Mux Box Racks (East Side, Upper Level)");
02401   TText *tLevelUW = new TText(0.01,0.89,
02402                               "Mux Box Racks (West Side, Upper Level)");
02403   TText *tLevelME = new TText
02404     (0.01,0.89,"Electronics Crates (East Side, Middle Level)");
02405   TText *tLevelMW = new TText
02406     (0.01,0.89,"Electronics Crates (West Side, Middle Level)");
02407   TText *tLevelLE = new TText(0.01,0.89,
02408                               "Mux Box Racks (East Side, Lower Level)");
02409   TText *tLevelLW = new TText(0.01,0.89,
02410                               "Mux Box Racks (West Side, Lower Level)");
02411 
02412   tLevelUE->SetTextSize(0.1);
02413   tLevelUW->SetTextSize(0.1);
02414   tLevelME->SetTextSize(0.08);
02415   tLevelMW->SetTextSize(0.08);
02416   tLevelLE->SetTextSize(0.1);
02417   tLevelLW->SetTextSize(0.1);
02418 
02419   levelUE->cd();
02420   tLevelUE->Draw();
02421   levelUW->cd();
02422   tLevelUW->Draw();
02423 
02424   levelME->cd();
02425   tLevelME->Draw();
02426   levelMW->cd();
02427   tLevelMW->Draw();
02428   
02429   levelLE->cd();
02430   tLevelLE->Draw();
02431   levelLW->cd();
02432   tLevelLW->Draw();
02433   
02434   Float_t rackSpace=0.07/(numRacks+1.);
02435   Float_t crateSpace=3.0*rackSpace;
02436   Float_t rackWidth=(1.-((numRacks/2)+2)*rackSpace-
02437                      ((numRacks/2)-1)*crateSpace)/numRacks;
02438   Float_t xMin=-1.;
02439   MSG("LIAnalysis",Msg::kDebug) 
02440     <<"rackSpace="<<rackSpace<<", crateSpace="<<crateSpace
02441     <<", rackWidth="<<rackWidth<<endl;
02442 
02443   TPad **rackUE=0;
02444   TPad **rackUW=0;
02445   TPad **rackLE=0;
02446   TPad **rackLW=0;
02447   
02448   rackUE=new TPad*[const_numRacks];
02449   rackUW=new TPad*[const_numRacks];
02450   rackLE=new TPad*[const_numRacks];
02451   rackLW=new TPad*[const_numRacks];
02452 
02453   for (Int_t rack=0;rack<const_numRacks;rack++){
02454     Float_t crate=floor(static_cast<Float_t>(rack)/2.);
02455     
02456     xMin=rackSpace
02457       +floor((static_cast<Float_t>(rack)+1)/2)*rackSpace
02458       +crate*crateSpace
02459       +static_cast<Float_t>(rack)*rackWidth;
02460     
02461     rackUE[rack]= new TPad("rackUE","Upper East Racks",
02462                            xMin,0.,xMin+rackWidth,0.87,17,3);
02463     rackUW[rack]= new TPad("rackUW","Upper West Racks",
02464                            xMin,0.,xMin+rackWidth,0.87,17,3);
02465     rackLE[rack]= new TPad("rackLE","Lower East Racks",
02466                            xMin,0.,xMin+rackWidth,0.87,17,3);
02467     rackLW[rack]= new TPad("rackLW","Lower West Racks",
02468                            xMin,0.,xMin+rackWidth,0.87,17,3);
02469 
02470 
02471     rackUE[rack]->SetFillColor(5);
02472     rackUW[rack]->SetFillColor(5);
02473     rackLE[rack]->SetFillColor(5);
02474     rackLW[rack]->SetFillColor(5);
02475 
02476     rackUE[rack]->SetBorderSize(0);
02477     rackUW[rack]->SetBorderSize(0);
02478     rackLE[rack]->SetBorderSize(0);
02479     rackLW[rack]->SetBorderSize(0);
02480 
02481     rackUE[rack]->SetBorderMode(0);
02482     rackUW[rack]->SetBorderMode(0);
02483     rackLE[rack]->SetBorderMode(0);
02484     rackLW[rack]->SetBorderMode(0);
02485 
02486     levelUE->cd();
02487     rackUE[rack]->Draw();
02488     levelUW->cd();
02489     rackUW[rack]->Draw();
02490     levelLE->cd();
02491     rackLE[rack]->Draw();
02492     levelLW->cd();
02493     rackLW[rack]->Draw();
02494   }
02495   
02496   //create mux boxes and draw
02497   TPaveText **muxBoxBg=0;
02498   muxBoxBg=new TPaveText*[const_numRacks];
02499 
02500   for (Int_t rack=0;rack<const_numRacks;rack++){
02501     
02502     muxBoxBg[rack]=new TPaveText(0.06,0.01,0.94,0.97);
02503     muxBoxBg[rack]->SetBorderSize(0);
02504     muxBoxBg[rack]->SetFillColor(0);
02505 
02506     rackUE[rack]->cd();
02507     muxBoxBg[rack]->Draw();
02508     rackUW[rack]->cd();
02509     muxBoxBg[rack]->Draw();
02510     rackLE[rack]->cd();
02511     muxBoxBg[rack]->Draw();
02512     rackLW[rack]->cd(); 
02513     muxBoxBg[rack]->Draw();
02514   }
02515 
02516   //create mux boxes labels
02517   TPaveText ***muxTextUE=0;
02518   muxTextUE=new TPaveText**[const_numRacks];
02519   TPaveText ***muxTextUW=0;
02520   muxTextUW=new TPaveText**[const_numRacks];
02521   TPaveText ***muxTextLE=0;
02522   muxTextLE=new TPaveText**[const_numRacks];
02523   TPaveText ***muxTextLW=0;
02524   muxTextLW=new TPaveText**[const_numRacks];
02525   for (Int_t rack=0;rack<const_numRacks;rack++){
02526     muxTextUE[rack]=new TPaveText*[2*const_numMux]; 
02527     muxTextUW[rack]=new TPaveText*[2*const_numMux]; 
02528     muxTextLE[rack]=new TPaveText*[2*const_numMux]; 
02529     muxTextLW[rack]=new TPaveText*[2*const_numMux]; 
02530     for (Int_t pin=0;pin<2*const_numMux;pin++){
02531       (muxTextUE[rack])[pin]=new TPaveText
02532         (0.09,
02533          0.015+static_cast<Int_t>(pin)*0.06,
02534          0.93,
02535          0.015+static_cast<Int_t>(pin+1)*0.06-0.010*(pin%2));
02536       (muxTextUW[rack])[pin]=new TPaveText
02537         (0.09,
02538          0.015+static_cast<Int_t>(pin)*0.06,
02539          0.93,
02540          0.015+static_cast<Int_t>(pin+1)*0.06-0.010*(pin%2));
02541       (muxTextLE[rack])[pin]=new TPaveText
02542         (0.09,
02543          0.015+static_cast<Int_t>(pin)*0.06,
02544          0.93,
02545          0.015+static_cast<Int_t>(pin+1)*0.06-0.010*(pin%2));
02546       (muxTextLW[rack])[pin]=new TPaveText
02547         (0.09,
02548          0.015+static_cast<Int_t>(pin)*0.06,
02549          0.93,
02550          0.015+static_cast<Int_t>(pin+1)*0.06-0.010*(pin%2));
02551       (muxTextUE[rack])[pin]->SetBorderSize(0);
02552       (muxTextUW[rack])[pin]->SetBorderSize(0);
02553       (muxTextLE[rack])[pin]->SetBorderSize(0);
02554       (muxTextLW[rack])[pin]->SetBorderSize(0);
02555 
02556       (muxTextUE[rack])[pin]->SetTextSize(0.2);
02557       (muxTextUW[rack])[pin]->SetTextSize(0.2);
02558       (muxTextLE[rack])[pin]->SetTextSize(0.2);
02559       (muxTextLW[rack])[pin]->SetTextSize(0.2);
02560 
02561       (muxTextUE[rack])[pin]->SetTextColor(5);
02562       (muxTextUW[rack])[pin]->SetTextColor(5);
02563       (muxTextLE[rack])[pin]->SetTextColor(5);
02564       (muxTextLW[rack])[pin]->SetTextColor(5);
02565 
02566       (muxTextUE[rack])[pin]->SetTextFont(2);
02567       (muxTextUW[rack])[pin]->SetTextFont(2);
02568       (muxTextLE[rack])[pin]->SetTextFont(2);
02569       (muxTextLW[rack])[pin]->SetTextFont(2);
02570 
02571       (muxTextUE[rack])[pin]->SetFillColor(20);//18
02572       (muxTextUW[rack])[pin]->SetFillColor(20);//18
02573       (muxTextLE[rack])[pin]->SetFillColor(20);//18
02574       (muxTextLW[rack])[pin]->SetFillColor(20);//18
02575     }
02576   }
02577  
02578   //draw crates
02579   MSG("LIAnalysis",Msg::kInfo)<<"Drawing crates..."<<endl;
02580   TPad **cratesE=0;
02581   cratesE=new TPad*[const_numCrates];
02582   TPad **cratesW=0;
02583   cratesW=new TPad*[const_numCrates];
02584   
02585   TPaveText **crateLabelE=0;
02586   crateLabelE=new TPaveText*[const_numCrates];
02587   TPaveText **crateLabelW=0;
02588   crateLabelW=new TPaveText*[const_numCrates];
02589 
02590   //calculate space between crates
02591   crateSpace=(1
02592               -(numRacks/2)*rackWidth
02593               -2*(1.5*rackSpace+(rackWidth/2))
02594               )/((numRacks/2)-1);
02595 
02596   //loop over crates
02597   for (Int_t cra=0;cra<static_cast<Int_t>(numRacks/2);cra++){
02598 
02599     xMin=1.5*rackSpace+(rackWidth/2)
02600       +static_cast<Float_t>(cra)*crateSpace
02601       +static_cast<Float_t>(cra)*rackWidth;
02602 
02603     cratesE[cra]=new TPad("crates","Crates",
02604                           xMin,0.,xMin+rackWidth,0.85,17,3);
02605     cratesE[cra]->SetFillColor(5);
02606     cratesE[cra]->SetBorderSize(0);
02607     cratesE[cra]->SetBorderMode(0);
02608     levelME->cd();
02609     cratesE[cra]->Draw();
02610 
02611     cratesW[cra]=new TPad("crates","Crates",
02612                           xMin,0.,xMin+rackWidth,0.85,17,3);
02613     cratesW[cra]->SetFillColor(5);
02614     cratesW[cra]->SetBorderSize(0);
02615     cratesW[cra]->SetBorderMode(0);
02616     levelMW->cd();
02617     cratesW[cra]->Draw();
02618 
02619     crateLabelE[cra]=new TPaveText(0.1,0.01,0.9,0.95);
02620     crateLabelE[cra]->SetBorderSize(0);
02621     crateLabelW[cra]=new TPaveText(0.1,0.01,0.9,0.95);
02622     crateLabelW[cra]->SetBorderSize(0);
02623 
02624     string s=Form("%d",2*cra);
02625     crateLabelE[cra]->AddText(0.5,0.95,"Pulser");
02626     crateLabelE[cra]->AddText(0.5,0.8,"Box");
02627     crateLabelE[cra]->AddText(0.5,0.65,s.c_str());
02628     crateLabelE[cra]->SetTextSize(0.25);
02629     //set fill colour according to pulser box number
02630     crateLabelE[cra]->SetFillColor(19-cra);
02631     //crateLabelE[cra]->SetFillStyle(3008-cra);
02632     cratesE[cra]->cd();
02633     crateLabelE[cra]->Draw();
02634 
02635     string sW=Form("%d",15-(2*cra));
02636     crateLabelW[cra]->AddText(0.5,0.95,"Pulser");
02637     crateLabelW[cra]->AddText(0.5,0.8,"Box");
02638     crateLabelW[cra]->AddText(0.5,0.65,sW.c_str());
02639     crateLabelW[cra]->SetTextSize(0.25);
02640     //set fill colour according to pulser box number
02641     crateLabelW[cra]->SetFillColor(12+cra);
02642     //crateLabelE[cra]->SetFillStyle(3001+cra);
02643     cratesW[cra]->cd();
02644     crateLabelW[cra]->Draw();
02645   }
02646   MSG("LIAnalysis",Msg::kInfo)<<"... OK"<<endl;
02647 
02648 
02649 
02650   //hRackLevel->Fill(rackLevel);
02651   //hEastWest->Fill(eastWest);
02652   //hNumericMuxBox->Fill(numericMuxBox);
02653   //hInRack->Fill(inRack);
02654   //hRackBay->Fill(rackBay);
02655   //hPinGain->Fill(pinGain);
02656   //hPinInBox->Fill(pinInBox);
02657 
02661 
02662   MSG("LIAnalysis",Msg::kInfo) 
02663     <<"Looping through tree and drawing mux box labels..."<<endl;
02664 
02665   this->InitialiseLoopVariables();  
02666   
02667   for(Int_t entry=0;entry<numEvents;entry++){
02668     
02669     this->SetLoopVariables(entry,0);
02670     
02671     //avoid divide by zero errors and skip irrelevant data
02672     if (rms==0. || mean==0. || numEntries==0) continue;
02673     //only look at pin diodes
02674     if (readoutType!=ReadoutType::kPinDiode) continue;
02675 
02676     if (pulserBox!=1) continue;
02677 
02678     //draw in the correct rack bay
02679     if (rackLevel==0){
02680       if (eastWest==0){
02681         rackLE[rackBay]->cd();
02682         MSG("LIAnalysis",Msg::kVerbose)<<"Lower East:"<<endl;
02683       }
02684       else if (eastWest==1){
02685         rackLW[const_numRacks-1-rackBay]->cd();
02686         MSG("LIAnalysis",Msg::kVerbose)<<"Lower West:"<<endl;
02687       }
02688     }
02689     else if (rackLevel==1){
02690       if (eastWest==0){
02691         rackUE[rackBay]->cd();
02692         MSG("LIAnalysis",Msg::kVerbose)<<"Upper East:"<<endl;
02693       }
02694       else if (eastWest==1){
02695         rackUW[const_numRacks-1-rackBay]->cd();
02696         MSG("LIAnalysis",Msg::kVerbose)<<"Upper West:"<<endl;
02697       }
02698     }
02699     
02700     //The vfbs are flipped on the east side relative
02701     //to the west side, thus whether pin 1 is plotted
02702     //nearest the floor or the ceiling must change
02703     //depending on the side
02704     Int_t pin=-1;
02705     //On the east side pin 0 is nearest floor and pin 1
02706     //nearest ceiling
02707     if (eastWest==0){//East
02708       //pins ordered ordered: 1,0, 3,2, 5,4, 7,6 etc
02709       if (pinInBox==0){
02710         pin=2*inRack+1;
02711       }
02712       else if (pinInBox==1){
02713         pin=2*inRack+0;
02714       }
02715     }
02716     //On the west side pin 1 is nearest floor and pin 0
02717     //nearest ceiling
02718     else if (eastWest==1){//West
02719       pin=2*inRack+pinInBox;//0-15 from bottom to top
02720     }
02721 
02722     MSG("LIAnalysis",Msg::kInfo)
02723       <<"E/W="<<eastWest
02724       <<", U/L="<<rackLevel
02725       <<", rack="<<rackBay
02726       <<", mux="<<inRack
02727       <<", pinInBox="<<pinInBox
02728       <<", gain="<<pinGain
02729       <<", pb="<<pulserBox
02730      <<endl;
02731   
02732   }//end of for
02733    
02737   
02738   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
02739 
02740   MSG("LIAnalysis",Msg::kInfo)
02741     <<" ** Finished the PinMap method ** "<<endl;
02742 }
02743 
02744 //......................................................................
02745 
02746 void LIAnalysis::StripVsPlane(Int_t nearPb,Int_t farPb,Int_t ledCut)
02747 {
02748   MSG("LIAnalysis",Msg::kInfo)
02749     <<endl<<" ** Running the StripVsPlane method... ** "<<endl;
02750   
02751   chain->GetEvent(0);
02752 
02753   if (calibType>1){
02754     MSG("LIAnalysis",Msg::kWarning)
02755       <<endl<<"Gain curve file detected with "<<calibType<<" points"
02756       <<endl<<"Only the last gain curve point will be used"<<endl;
02757   }
02758 
02759   Int_t* planeMax=new Int_t[NUMCRATES];
02760   Int_t* planeMin=new Int_t[NUMCRATES];
02761   lookup.SetPbPlanes(planeMin,planeMax,detectorType);
02762 
02763   const Int_t firstStripBin=FIRSTSTRIP-8;//-8;
02764   const Int_t lastStripBin=LASTSTRIP+9;//200;
02765   const Int_t bins=lastStripBin-firstStripBin;
02766 
02767   chain->GetEvent(0);
02768   string sPulseWidth=Form("%d",pulseWidth);
02769   string sPulseHeight=Form("%d",pulseHeight);
02770   string sPulseFreq=Form("%d",static_cast<Int_t>
02771                          (ceil(1.0/(period*1.0e-5))));
02772   string sPulses=Form("%d",pulses);
02773   string sConstantBit="";
02774 
02775   if (detectorType==Detector::kFar){
02776     MSG("LIAnalysis",Msg::kInfo)
02777       <<"Setting histo titles according to detector type kFar"<<endl;
02778 
02779     if (runNumber>=13123){//don't use pulse height
02780       Int_t fph=pulseHeight;
02781       //this caused a segv so have disabled it
02782       //chain->GetEvent(numEvents-1);
02783       Int_t lph=-10;//pulseHeight;
02784       
02785       MSG("LIAnalysis",Msg::kInfo)
02786         <<"first ph="<<fph<<", last ph="<<lph<<endl;
02787 
02788       if (lph==fph){
02789         sConstantBit=+", PH="+sPulseHeight+", PW="+sPulseWidth+
02790           ", PF="+sPulseFreq+" Hz, PN="+sPulses+")";
02791       }
02792       else if (lph!=fph){
02793         sConstantBit=+", PW="+sPulseWidth+
02794           ", PF="+sPulseFreq+" Hz, PN="+sPulses+")";
02795       }
02796     }
02797     else{
02798       sConstantBit=+", PH="+sPulseHeight+", PW="+sPulseWidth+
02799         ", PF="+sPulseFreq+" Hz, PN="+sPulses+")";
02800     }
02801   }
02802   else if (detectorType==Detector::kCalDet){
02803     MSG("LIAnalysis",Msg::kInfo)
02804       <<"Setting histo titles according to detector type kCalDet"<<endl;
02805 
02806     Int_t fph=pulseHeight;
02807     //chain->GetEvent(numEvents-1);
02808     Int_t lph=-10;//pulseHeight;
02809     
02810     MSG("LIAnalysis",Msg::kInfo)
02811       <<"first ph="<<fph<<", last ph="<<lph<<endl;
02812 
02813     if (lph==fph){
02814       sConstantBit=+", PH="+sPulseHeight+", PW="+sPulseWidth+
02815         ", PF="+sPulseFreq+" Hz, PN="+sPulses+")";
02816     }
02817     else if (lph!=fph){
02818       sConstantBit=+", PW="+sPulseWidth+
02819         ", PF="+sPulseFreq+" Hz, PN="+sPulses+")";
02820     }
02821   }
02822  
02823   MSG("LIAnalysis",Msg::kInfo)
02824     <<"sConstantBit="<<sConstantBit<<endl;
02825 
02826   TH2F *hStripVsPlaneLedB=new TH2F(" "," ",
02827                                    LASTSCINTPLANE-FIRSTSCINTPLANE+2,
02828                                    FIRSTSCINTPLANE,LASTSCINTPLANE+1,
02829                                    bins,firstStripBin,lastStripBin);
02830 
02831   TH2F **hStripVsPlaneLed=0;
02832   hStripVsPlaneLed= new TH2F*[NUMCRATES];
02833   for (Int_t i=0;i<NUMCRATES;i++){
02834     string sPulserBox=Form("%d",i);
02835     s="LED (PB="+sPulserBox+sConstantBit;
02836     if (detectorType==Detector::kCalDet){
02837       s="LED (Crate="+sPulserBox+sConstantBit;
02838     }
02839     hStripVsPlaneLed[i]=new TH2F(s.c_str(),s.c_str(),
02840                                  planeMax[i]-planeMin[i],
02841                                  planeMin[i],planeMax[i]
02842                                  ,bins,firstStripBin,lastStripBin);
02843     hStripVsPlaneLed[i]->GetXaxis()->SetTitle("Plane");
02844     hStripVsPlaneLed[i]->GetXaxis()->CenterTitle();
02845     hStripVsPlaneLed[i]->GetYaxis()->SetTitle("Num Entries");
02846     hStripVsPlaneLed[i]->GetYaxis()->CenterTitle();
02847     hStripVsPlaneLed[i]->SetFillColor(0);
02848     //hStripVsPlaneLed[i]->SetBit(TH1::kCanRebin);
02849   }
02850 
02851   TH2F **hStripVsPlaneMean=0;
02852   hStripVsPlaneMean= new TH2F*[NUMCRATES];
02853   for (Int_t i=0;i<NUMCRATES;i++){
02854     string sPulserBox=Form("%d",i);
02855     s="ADC (Near End, PB="+sPulserBox+sConstantBit; 
02856     if (detectorType==Detector::kCalDet){
02857       s="ADC (Near End of Strip, Crate="+sPulserBox+sConstantBit; 
02858     }
02859     hStripVsPlaneMean[i]=new TH2F(s.c_str(),s.c_str(),
02860        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
02861        ,bins,firstStripBin,lastStripBin);
02862     hStripVsPlaneMean[i]->GetXaxis()->SetTitle("Plane");
02863     hStripVsPlaneMean[i]->GetXaxis()->CenterTitle();
02864     hStripVsPlaneMean[i]->GetYaxis()->SetTitle("Strip");
02865     hStripVsPlaneMean[i]->GetYaxis()->CenterTitle();
02866     hStripVsPlaneMean[i]->SetFillColor(0);
02867     hStripVsPlaneMean[i]->SetMaximum(14000);
02868     //hStripVsPlaneMean[i]->SetBit(TH1::kCanRebin);
02869   }
02870 
02871   TH2F **hStripVsPlaneMeanF=0;
02872   hStripVsPlaneMeanF= new TH2F*[NUMCRATES];
02873   for (Int_t i=0;i<NUMCRATES;i++){
02874     string sPulserBox=Form("%d",i);
02875     s="ADC (Far End, PB="+sPulserBox+sConstantBit; 
02876     if (detectorType==Detector::kCalDet){
02877       s="ADC (Far End of Strip, Crate="+sPulserBox+sConstantBit; 
02878     }
02879     hStripVsPlaneMeanF[i]=new TH2F(s.c_str(),s.c_str(),
02880        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
02881        ,bins,firstStripBin,lastStripBin);
02882     hStripVsPlaneMeanF[i]->GetXaxis()->SetTitle("Plane");
02883     hStripVsPlaneMeanF[i]->GetXaxis()->CenterTitle();
02884     hStripVsPlaneMeanF[i]->GetYaxis()->SetTitle("Strip");
02885     hStripVsPlaneMeanF[i]->GetYaxis()->CenterTitle();
02886     hStripVsPlaneMeanF[i]->SetFillColor(0);
02887     hStripVsPlaneMeanF[i]->SetMaximum(14000);
02888     //hStripVsPlaneMeanF[i]->SetBit(TH1::kCanRebin);
02889   }
02890 
02891   TH2F **hStripVsPlaneRms=0;
02892   hStripVsPlaneRms= new TH2F*[NUMCRATES];
02893   for (Int_t i=0;i<NUMCRATES;i++){
02894     string sPulserBox=Form("%d",i);
02895     s="RMS (Near End, PB="+sPulserBox+sConstantBit;
02896     if (detectorType==Detector::kCalDet){
02897       s="RMS (Near End of Strip, Crate="+sPulserBox+sConstantBit; 
02898     }
02899     hStripVsPlaneRms[i]=new TH2F(s.c_str(),s.c_str(),
02900        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
02901        ,bins,firstStripBin,lastStripBin);
02902     hStripVsPlaneRms[i]->GetXaxis()->SetTitle("Plane");
02903     hStripVsPlaneRms[i]->GetXaxis()->CenterTitle();
02904     hStripVsPlaneRms[i]->GetYaxis()->SetTitle("Strip");
02905     hStripVsPlaneRms[i]->GetYaxis()->CenterTitle();
02906     hStripVsPlaneRms[i]->SetFillColor(0);
02907     //hStripVsPlaneRms[i]->SetBit(TH1::kCanRebin);
02908   }
02909 
02910   TH2F **hStripVsPlaneRmsF=0;
02911   hStripVsPlaneRmsF= new TH2F*[NUMCRATES];
02912   for (Int_t i=0;i<NUMCRATES;i++){
02913     string sPulserBox=Form("%d",i);
02914     s="RMS (Far End, PB="+sPulserBox+sConstantBit; 
02915     if (detectorType==Detector::kCalDet){
02916       s="RMS (Far End of Strip, Crate="+sPulserBox+sConstantBit; 
02917     }
02918     hStripVsPlaneRmsF[i]=new TH2F(s.c_str(),s.c_str(),
02919        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
02920        ,bins,firstStripBin,lastStripBin);
02921     hStripVsPlaneRmsF[i]->GetXaxis()->SetTitle("Plane");
02922     hStripVsPlaneRmsF[i]->GetXaxis()->CenterTitle();
02923     hStripVsPlaneRmsF[i]->GetYaxis()->SetTitle("Strip");
02924     hStripVsPlaneRmsF[i]->GetYaxis()->CenterTitle();
02925     hStripVsPlaneRmsF[i]->SetFillColor(0);
02926     //hStripVsPlaneRmsF[i]->SetBit(TH1::kCanRebin);
02927   }
02928 
02929   TH2F **hStripVsPlaneNpe=0;
02930   hStripVsPlaneNpe= new TH2F*[NUMCRATES];
02931   for (Int_t i=0;i<NUMCRATES;i++){
02932     string sPulserBox=Form("%d",i);
02933     s="NPE, PB="+sPulserBox+sConstantBit; 
02934     if (detectorType==Detector::kCalDet){
02935       s="NPE, Crate="+sPulserBox+sConstantBit; 
02936     }
02937     hStripVsPlaneNpe[i]=new TH2F(s.c_str(),s.c_str(),
02938        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
02939        ,bins,firstStripBin,lastStripBin);
02940     hStripVsPlaneNpe[i]->GetXaxis()->SetTitle("Plane");
02941     hStripVsPlaneNpe[i]->GetXaxis()->CenterTitle();
02942     hStripVsPlaneNpe[i]->GetYaxis()->SetTitle("Strip");
02943     hStripVsPlaneNpe[i]->GetYaxis()->CenterTitle();
02944     hStripVsPlaneNpe[i]->SetFillColor(0);
02945     //hStripVsPlaneNpe[i]->SetBit(TH1::kCanRebin);
02946   }
02947 
02948   const Float_t adcUpperCut=8000;
02949   const Float_t adcLowerCut=800;
02950   const Float_t pulsesCut=20;//in percent of pulses
02951   string sAdcUpper=Form("%d",static_cast<Int_t>(adcUpperCut));
02952   string sAdcLower=Form("%d",static_cast<Int_t>(adcLowerCut));
02953   string sPulsesCut=Form("%d",static_cast<Int_t>(pulsesCut));
02954 
02955   s="Gain Differences (Near-Far, Cut: ADC<"+sAdcUpper+" & >"+
02956     sAdcLower+" & NP>"+sPulsesCut+"%)";
02957   TH1F *hGainDiff=new TH1F("hGainDiff",s.c_str(),100,-50,50);
02958   hGainDiff->GetXaxis()->SetTitle("Gain Difference");
02959   hGainDiff->GetXaxis()->CenterTitle();
02960   hGainDiff->GetYaxis()->SetTitle("Number of entries");
02961   hGainDiff->GetYaxis()->CenterTitle();
02962   hGainDiff->SetFillColor(0);
02963 
02964   s="ADC (Near&Far where both sides have ADC<"+sAdcUpper+" & >"+
02965     sAdcLower+" & NP>"+sPulsesCut+"%)";
02966   TH1F *hMeanDiffNear=new TH1F("hMeanDiffNear",s.c_str(),100,0,15000);
02967   hMeanDiffNear->GetXaxis()->SetTitle("ADC");
02968   hMeanDiffNear->GetXaxis()->CenterTitle();
02969   hMeanDiffNear->GetYaxis()->SetTitle("Number of entries");
02970   hMeanDiffNear->GetYaxis()->CenterTitle();
02971   hMeanDiffNear->SetLineColor(2);
02972   hMeanDiffNear->SetFillColor(0);
02973 
02974   s="ADC (Near&Far where both sides have ADC<"+sAdcUpper+" & >"+
02975     sAdcLower+" & NP>"+sPulsesCut+"%)";
02976   TH1F *hMeanDiffFar=new TH1F("hMeanDiffFar",s.c_str(),100,0,15000);
02977   hMeanDiffFar->GetXaxis()->SetTitle("ADC");
02978   hMeanDiffFar->GetXaxis()->CenterTitle();
02979   hMeanDiffFar->GetYaxis()->SetTitle("Number of entries");
02980   hMeanDiffFar->GetYaxis()->CenterTitle();
02981   hMeanDiffFar->SetLineColor(3);
02982   hMeanDiffFar->SetFillColor(0);
02983 
02984   TH2F **hStripVsPlaneGain=0;
02985   hStripVsPlaneGain= new TH2F*[NUMCRATES];
02986   for (Int_t i=0;i<NUMCRATES;i++){
02987     string sPb=Form("%d",i);
02988     s="Gain (Crate "+sPb+", Cut: ADC<"+sAdcUpper+" & >"+
02989       sAdcLower+" & NP>"+sPulsesCut+"%)";
02990     hStripVsPlaneGain[i]=new TH2F
02991       (s.c_str(),s.c_str(),
02992        planeMax[i]-planeMin[i],planeMin[i],planeMax[i],
02993        bins,firstStripBin,lastStripBin);
02994     hStripVsPlaneGain[i]->GetXaxis()->SetTitle("Plane");
02995     hStripVsPlaneGain[i]->GetXaxis()->CenterTitle();
02996     hStripVsPlaneGain[i]->GetYaxis()->SetTitle("Strip");
02997     hStripVsPlaneGain[i]->GetYaxis()->CenterTitle();
02998     hStripVsPlaneGain[i]->SetFillColor(0);
02999     //hStripVsPlaneGain[i]->SetBit(TH1::kCanRebin);
03000   }
03001 
03002   TH2F **hStripVsPlaneGainN=0; 
03003   hStripVsPlaneGainN= new TH2F*[NUMCRATES]; 
03004   for (Int_t i=0;i<NUMCRATES;i++){ 
03005     string sPulserBox=Form("%d",i);
03006     s="Gain (Near End, PB="+sPulserBox+sConstantBit; 
03007     if (detectorType==Detector::kCalDet){
03008       s="Gain (Near End of Strip, Crate="+sPulserBox+sConstantBit; 
03009     }
03010     hStripVsPlaneGainN[i]=new TH2F
03011       (s.c_str(),s.c_str(), 
03012        planeMax[i]-planeMin[i],planeMin[i],planeMax[i],
03013        bins,firstStripBin,lastStripBin); 
03014     hStripVsPlaneGainN[i]->GetXaxis()->SetTitle("Plane"); 
03015     hStripVsPlaneGainN[i]->GetXaxis()->CenterTitle(); 
03016     hStripVsPlaneGainN[i]->GetYaxis()->SetTitle("Strip"); 
03017     hStripVsPlaneGainN[i]->GetYaxis()->CenterTitle(); 
03018     hStripVsPlaneGainN[i]->SetFillColor(0); 
03019     //hStripVsPlaneGainN[i]->SetBit(TH1::kCanRebin); 
03020   } 
03021 
03022   TH2F **hStripVsPlaneGainAll=0; 
03023   hStripVsPlaneGainAll= new TH2F*[NUMSIDES]; 
03024   for (Int_t i=0;i<NUMSIDES;i++){ 
03025     if (i==0) s="Gain (East Side"+sConstantBit; 
03026     else if (i==1) s="Gain (West Side"+sConstantBit;
03027     else {
03028       s="What?";
03029     }
03030 
03031     MSG("LIAnalysis",Msg::kDebug) 
03032       <<"NUMSIDES="<<NUMSIDES<<", s="<<s<<endl;
03033     hStripVsPlaneGainAll[i]=new TH2F
03034       (s.c_str(),s.c_str(),FIRSTPLANE,LASTPLANE,NUMPLANES,
03035        bins,firstStripBin,lastStripBin); 
03036     MSG("LIAnalysis",Msg::kDebug) 
03037       <<"NUMSIDES="<<NUMSIDES<<", s="<<s<<endl;
03038     hStripVsPlaneGainAll[i]->GetXaxis()->SetTitle("Plane"); 
03039     hStripVsPlaneGainAll[i]->GetXaxis()->CenterTitle(); 
03040     hStripVsPlaneGainAll[i]->GetYaxis()->SetTitle("Strip"); 
03041     hStripVsPlaneGainAll[i]->GetYaxis()->CenterTitle(); 
03042     hStripVsPlaneGainAll[i]->SetFillColor(0); 
03043     MSG("LIAnalysis",Msg::kDebug) 
03044       <<"NUMSIDES="<<NUMSIDES<<", s="<<s<<endl;
03045     //hStripVsPlaneGainAll[i]->SetBit(TH1::kCanRebin); 
03046   }
03047   
03048   hStripVsPlaneGainAll[1]->SetBit(TH1::kCanRebin); 
03049   hStripVsPlaneGainAll[1]->Fill(100,600,1000);
03050   
03051   TH2F **hStripVsPlaneGainF=0; 
03052   hStripVsPlaneGainF= new TH2F*[NUMCRATES]; 
03053   for (Int_t i=0;i<NUMCRATES;i++){ 
03054     string sPulserBox=Form("%d",i);
03055     s="Gain (Far End, PB="+sPulserBox+sConstantBit; 
03056     if (detectorType==Detector::kCalDet){
03057       s="Gain (Far End of Strip, Crate="+sPulserBox+sConstantBit; 
03058     }
03059     hStripVsPlaneGainF[i]=new TH2F 
03060       (s.c_str(),s.c_str(), 
03061        planeMax[i]-planeMin[i],planeMin[i],planeMax[i] 
03062        ,bins,firstStripBin,lastStripBin); 
03063     hStripVsPlaneGainF[i]->GetXaxis()->SetTitle("Plane"); 
03064     hStripVsPlaneGainF[i]->GetXaxis()->CenterTitle(); 
03065     hStripVsPlaneGainF[i]->GetYaxis()->SetTitle("Strip"); 
03066     hStripVsPlaneGainF[i]->GetYaxis()->CenterTitle(); 
03067     hStripVsPlaneGainF[i]->SetFillColor(0); 
03068   } 
03069   
03070   TH2F **hStripVsPlaneGainDiff=0;
03071   hStripVsPlaneGainDiff= new TH2F*[NUMCRATES];
03072   for (Int_t i=0;i<NUMCRATES;i++){
03073     string sPb=Form("%d",i);
03074     s="Gain Difference: Near-Far (Crate "+sPb+", Cut: ADC<"+
03075       sAdcUpper+" & >"+sAdcLower+" & NP>"+sPulsesCut+"%)";
03076     hStripVsPlaneGainDiff[i]=new TH2F
03077       (s.c_str(),s.c_str(),
03078        planeMax[i]-planeMin[i],planeMin[i],planeMax[i],
03079        bins,firstStripBin,lastStripBin);
03080     hStripVsPlaneGainDiff[i]->GetXaxis()->SetTitle("Plane");
03081     hStripVsPlaneGainDiff[i]->GetXaxis()->CenterTitle();
03082     hStripVsPlaneGainDiff[i]->GetYaxis()->SetTitle("Strip");
03083     hStripVsPlaneGainDiff[i]->GetYaxis()->CenterTitle();
03084     hStripVsPlaneGainDiff[i]->SetFillColor(0);
03085     //hStripVsPlaneGainDiff[i]->SetBit(TH1::kCanRebin);
03086   }
03087   
03088   TH2F **hStripVsPlaneNum=0;
03089   hStripVsPlaneNum= new TH2F*[NUMCRATES];
03090   for (Int_t i=0;i<NUMCRATES;i++){
03091     string sPulserBox=Form("%d",i);
03092     s="Num Entries (Near End, PB="+sPulserBox+sConstantBit; 
03093     if (detectorType==Detector::kCalDet){
03094       s="Num Entries (Near End of Strip, Crate="+
03095         sPulserBox+sConstantBit; 
03096     }
03097     hStripVsPlaneNum[i]=new TH2F
03098       (s.c_str(),s.c_str(),
03099        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
03100        ,bins,firstStripBin,lastStripBin);
03101     hStripVsPlaneNum[i]->GetXaxis()->SetTitle("Plane");
03102     hStripVsPlaneNum[i]->GetXaxis()->CenterTitle();
03103     hStripVsPlaneNum[i]->GetYaxis()->SetTitle("Strip");
03104     hStripVsPlaneNum[i]->GetYaxis()->CenterTitle();
03105     hStripVsPlaneNum[i]->SetFillColor(0);
03106     //hStripVsPlaneNum[i]->SetBit(TH1::kCanRebin);
03107   }
03108 
03109   TH2F **hStripVsPlaneNumF=0; 
03110   hStripVsPlaneNumF= new TH2F*[NUMCRATES]; 
03111   for (Int_t i=0;i<NUMCRATES;i++){ 
03112     string sPulserBox=Form("%d",i); 
03113     s="Num Entries (Far End, PB="+sPulserBox+sConstantBit;  
03114     if (detectorType==Detector::kCalDet){
03115       s="Num Entries (Far End of Strip, Crate="+sPulserBox+
03116         sConstantBit; 
03117     }
03118     hStripVsPlaneNumF[i]=new TH2F 
03119       (s.c_str(),s.c_str(), 
03120        planeMax[i]-planeMin[i],planeMin[i],planeMax[i] 
03121        ,bins,firstStripBin,lastStripBin); 
03122     hStripVsPlaneNumF[i]->GetXaxis()->SetTitle("Plane"); 
03123     hStripVsPlaneNumF[i]->GetXaxis()->CenterTitle(); 
03124     hStripVsPlaneNumF[i]->GetYaxis()->SetTitle("Strip"); 
03125     hStripVsPlaneNumF[i]->GetYaxis()->CenterTitle(); 
03126     hStripVsPlaneNumF[i]->SetFillColor(0); 
03127     //hStripVsPlaneNumF[i]->SetBit(TH1::kCanRebin); 
03128   } 
03129 
03130   TH2F **hStripVsPlanePix=0;
03131   hStripVsPlanePix= new TH2F*[NUMCRATES];
03132   for (Int_t i=0;i<NUMCRATES;i++){
03133     string sPulserBox=Form("%d",i);
03134     s="Pixel (Near End, PB="+sPulserBox+sConstantBit; 
03135     if (detectorType==Detector::kCalDet){
03136       s="Pixel (Near End of Strip, Crate="+sPulserBox+sConstantBit; 
03137     }
03138     hStripVsPlanePix[i]=new TH2F
03139       (s.c_str(),s.c_str(),
03140        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
03141        ,bins,firstStripBin,lastStripBin);
03142     hStripVsPlanePix[i]->GetXaxis()->SetTitle("Plane");
03143     hStripVsPlanePix[i]->GetXaxis()->CenterTitle();
03144     hStripVsPlanePix[i]->GetYaxis()->SetTitle("Strip");
03145     hStripVsPlanePix[i]->GetYaxis()->CenterTitle();
03146     hStripVsPlanePix[i]->SetFillColor(0);
03147     //hStripVsPlanePix[i]->SetBit(TH1::kCanRebin);
03148   }
03149 
03150   TH2F **hStripVsPlanePixF=0;
03151   hStripVsPlanePixF= new TH2F*[NUMCRATES];
03152   for (Int_t i=0;i<NUMCRATES;i++){
03153     string sPulserBox=Form("%d",i);
03154     s="Pixel (Far End, PB="+sPulserBox+sConstantBit; 
03155     if (detectorType==Detector::kCalDet){
03156       s="Pixel (Far End of Strip, Crate="+sPulserBox+sConstantBit; 
03157     }
03158     hStripVsPlanePixF[i]=new TH2F
03159       (s.c_str(),s.c_str(),
03160        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
03161        ,bins,firstStripBin,lastStripBin);
03162     hStripVsPlanePixF[i]->GetXaxis()->SetTitle("Plane");
03163     hStripVsPlanePixF[i]->GetXaxis()->CenterTitle();
03164     hStripVsPlanePixF[i]->GetYaxis()->SetTitle("Strip");
03165     hStripVsPlanePixF[i]->GetYaxis()->CenterTitle();
03166     hStripVsPlanePixF[i]->SetFillColor(0);
03167     //hStripVsPlanePixF[i]->SetBit(TH1::kCanRebin);
03168   }
03169 
03170   TH2F **hStripVsPlaneEnt=0;
03171   hStripVsPlaneEnt= new TH2F*[NUMCRATES];
03172   for (Int_t i=0;i<NUMCRATES;i++){
03173     string sPulserBox=Form("%d",i);
03174     s="Entries (Near End, PB="+sPulserBox+sConstantBit; 
03175     if (detectorType==Detector::kCalDet){
03176       s="Entries (Near End of Strip, Crate="+sPulserBox+sConstantBit; 
03177     }
03178     hStripVsPlaneEnt[i]=new TH2F
03179       (s.c_str(),s.c_str(),
03180        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
03181        ,bins,firstStripBin,lastStripBin);
03182     hStripVsPlaneEnt[i]->GetXaxis()->SetTitle("Plane");
03183     hStripVsPlaneEnt[i]->GetXaxis()->CenterTitle();
03184     hStripVsPlaneEnt[i]->GetYaxis()->SetTitle("Strip");
03185     hStripVsPlaneEnt[i]->GetYaxis()->CenterTitle();
03186     hStripVsPlaneEnt[i]->SetFillColor(0);
03187     //hStripVsPlaneEnt[i]->SetBit(TH1::kCanRebin);
03188   }
03189 
03190   TH2F **hStripVsPlaneEntF=0;
03191   hStripVsPlaneEntF= new TH2F*[NUMCRATES];
03192   for (Int_t i=0;i<NUMCRATES;i++){
03193     string sPulserBox=Form("%d",i);
03194     s="Entries (Far End, PB="+sPulserBox+sConstantBit; 
03195     hStripVsPlaneEntF[i]=new TH2F
03196       (s.c_str(),s.c_str(),
03197        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
03198        ,bins,firstStripBin,lastStripBin);
03199     hStripVsPlaneEntF[i]->GetXaxis()->SetTitle("Plane");
03200     hStripVsPlaneEntF[i]->GetXaxis()->CenterTitle();
03201     hStripVsPlaneEntF[i]->GetYaxis()->SetTitle("Strip");
03202     hStripVsPlaneEntF[i]->GetYaxis()->CenterTitle();
03203     hStripVsPlaneEntF[i]->SetFillColor(0);
03204     //hStripVsPlaneEntF[i]->SetBit(TH1::kCanRebin);
03205   }
03206 
03207   TH2F **hStripVsPlaneXTalk=0;
03208   hStripVsPlaneXTalk= new TH2F*[NUMCRATES];
03209   for (Int_t i=0;i<NUMCRATES;i++){
03210     string sPulserBox=Form("%d",i);
03211     s="XTalk (Near End, PB="+sPulserBox+sConstantBit; 
03212     if (detectorType==Detector::kCalDet){
03213       s="XTalk (Near End of Strip, Crate="+sPulserBox+sConstantBit; 
03214     }
03215     hStripVsPlaneXTalk[i]=new TH2F
03216       (s.c_str(),s.c_str(),
03217        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
03218        ,bins,firstStripBin,lastStripBin);
03219     hStripVsPlaneXTalk[i]->GetXaxis()->SetTitle("Plane");
03220     hStripVsPlaneXTalk[i]->GetXaxis()->CenterTitle();
03221     hStripVsPlaneXTalk[i]->GetYaxis()->SetTitle("Strip");
03222     hStripVsPlaneXTalk[i]->GetYaxis()->CenterTitle();
03223     hStripVsPlaneXTalk[i]->SetFillColor(0);
03224     //hStripVsPlaneXTalk[i]->SetBit(TH1::kCanRebin);
03225   }
03226 
03227   TH2F **hStripVsPlaneAll=0;
03228   hStripVsPlaneAll= new TH2F*[NUMCRATES];
03229   for (Int_t i=0;i<NUMCRATES;i++){
03230     string sPulserBox=Form("%d",i);
03231     s="All (PB="+sPulserBox+sConstantBit; 
03232     if (detectorType==Detector::kCalDet){
03233       s="All (Crate="+sPulserBox+sConstantBit; 
03234     }
03235     hStripVsPlaneAll[i]=new TH2F
03236       (s.c_str(),s.c_str(),
03237        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
03238        ,bins,firstStripBin,lastStripBin);
03239     hStripVsPlaneAll[i]->GetXaxis()->SetTitle("Plane");
03240     hStripVsPlaneAll[i]->GetXaxis()->CenterTitle();
03241     hStripVsPlaneAll[i]->GetYaxis()->SetTitle("Strip");
03242     hStripVsPlaneAll[i]->GetYaxis()->CenterTitle();
03243     hStripVsPlaneAll[i]->SetFillColor(0);
03244     //hStripVsPlaneAll[i]->SetBit(TH1::kCanRebin);
03245   }
03246 
03247   Int_t maxPlane=0;
03248 
03249   MSG("LIAnalysis",Msg::kInfo) 
03250     <<"Starting main loop..."<<endl;
03251 
03255 
03256   this->InitialiseLoopVariables();  
03257 
03258   for(Int_t entry=0;entry<numEvents;entry++){
03259 
03260     this->SetLoopVariables(entry,1);
03261     
03262     //avoid divide by zero errors and skip irrelevant data
03263     if (rms==0. || mean==0. || numEntries==0) continue;
03264     //only look at scintillator strips
03265     if (readoutType!=ReadoutType::kScintStrip) continue;
03266     //decide which point to use if it's a gain curve file
03267 
03268     if (calibType>1){
03269       //only use the middle gain curve point
03270       if (calibPoint!=calibType/2) continue;
03271     }
03272 
03273     //calculate the max plane
03274     if (plane>maxPlane && mean>2000) maxPlane=plane;
03275 
03276     //Int_t side=crate%2;
03277     Float_t npe=mean*mean/(rms*rms);
03278 
03279    Float_t gain=0.8*mean/npe;
03280    
03281    // PMT fudge factor for M64 (near detector): 0.844
03282    if (detectorType==Detector::kNear) gain = 0.844*rms*rms/mean;
03283 
03284 
03286     //section for fardet or neardet setup
03288     if (detectorType==Detector::kFar
03289         || detectorType==Detector::kNear){
03290 
03291       if (pulserBox>=0 && pulserBox<NUMPULSERBOXES && 
03292           correlatedHit==1 &&
03293           strip<=LASTSTRIP && strip>=FIRSTSTRIP && 
03294           pulserBox==farPulserBox){
03295         hStripVsPlaneMeanF[pulserBox]->Fill(plane,strip,mean);
03296         hStripVsPlaneRmsF[pulserBox]->Fill(plane,strip,rms);
03297         hStripVsPlaneEntF[pulserBox]->Fill(plane,strip,1);
03298         hStripVsPlaneNumF[pulserBox]->Fill(plane,strip,numEntries); 
03299         hStripVsPlanePixF[pulserBox]->Fill(plane,strip,pixel+1);
03300         
03301         //make a cut before filling gain histo
03302         if (mean>adcLowerCut && mean<adcUpperCut && 
03303             numEntries>(pulsesCut/100.)*pulses){ 
03304           hStripVsPlaneGainF[pulserBox]->Fill(plane,strip,gain); 
03305         }
03306       }
03307       
03308       if (pulserBox>=0 && pulserBox<NUMPULSERBOXES && 
03309           correlatedHit==1 &&
03310           strip<=LASTSTRIP && strip>=FIRSTSTRIP && 
03311           pulserBox==nearPulserBox){
03312         hStripVsPlaneLed[pulserBox]->Fill(plane,strip,nearLed);
03313         hStripVsPlaneMean[pulserBox]->Fill(plane,strip,mean);
03314         hStripVsPlaneRms[pulserBox]->Fill(plane,strip,rms);
03315         hStripVsPlaneNum[pulserBox]->Fill(plane,strip,numEntries);
03316         hStripVsPlanePix[pulserBox]->Fill(plane,strip,pixel+1);
03317         hStripVsPlaneEnt[pulserBox]->Fill(plane,strip,1);
03318         
03319         //make a cut before filling gain histo
03320         if (mean>adcLowerCut && mean<adcUpperCut && 
03321             numEntries>(pulsesCut/100.)*pulses){
03322           hStripVsPlaneNpe[pulserBox]->Fill(plane,strip,npe);
03323           hStripVsPlaneGainN[pulserBox]->Fill(plane,strip,gain);
03324         }
03325         
03326         MSG("LIAnalysis",Msg::kVerbose) 
03327           <<"mean="<<mean 
03328           <<", rms="<<rms 
03329           <<", npe="<<pow(mean/rms,2)
03330           <<", gain="<<gain
03331           <<endl;
03332       }
03333     }
03334 
03336     //section for caldet setup
03338     else if (detectorType==Detector::kCalDet){
03339       //this uses crate instead of pulser box 
03340       //and uses the NearOrFar method
03341 
03342       if (ledCut==-1 || led==ledCut){
03343 
03344         //fill the everything histo
03345         if (eastWest==1 || eastWest==2){
03346           hStripVsPlaneAll[eastWest-1]->Fill(plane,strip,mean);
03347         }
03348 
03349         //fill the far histos
03350         if ((eastWest==1 || eastWest==2) && correlatedHit==1 &&
03351             strip<=LASTSTRIP && strip>=FIRSTSTRIP && 
03352             lookup.NearOrFar(crate,pulserBox,nearPulserBox,
03353                              farPulserBox,led,detectorType,
03354                              plane,runNumber)==
03355             LILookup::kFarSide &&
03356             led>=FIRSTLED && led<=LASTLED){//far
03357 
03358           hStripVsPlaneMeanF[eastWest-1]->Fill(plane,strip,mean);
03359           hStripVsPlaneRmsF[eastWest-1]->Fill(plane,strip,rms);
03360           hStripVsPlaneEntF[eastWest-1]->Fill(plane,strip,1);
03361           hStripVsPlaneNumF[eastWest-1]->Fill(plane,strip,numEntries); 
03362           hStripVsPlanePixF[eastWest-1]->Fill(plane,strip,pixel+1);
03363           
03364           //make a cut before filling gain histo
03365           if (mean>adcLowerCut && mean<adcUpperCut && 
03366               numEntries>(pulsesCut/100.)*pulses){ 
03367             hStripVsPlaneGainF[eastWest-1]->Fill(plane,strip,gain); 
03368           }
03369         }
03370         
03371         //fill the xtalk histo
03372         if ((eastWest==1 || eastWest==2) && correlatedHit==0 &&
03373             strip>=FIRSTSTRIP && strip<=LASTSTRIP &&
03374             lookup.NearOrFar(crate,pulserBox,nearPulserBox,
03375                              farPulserBox,led,detectorType,
03376                              plane,runNumber)==
03377             LILookup::kNearSide &&
03378             led>=FIRSTLED && led<=LASTLED){//near
03379           hStripVsPlaneXTalk[eastWest-1]->Fill(plane,strip,mean);
03380           //this->PrintBigMessage(); 
03381         }
03382 
03383         //fill the near histos
03384         if ((eastWest==1 || eastWest==2) && correlatedHit==1 &&
03385             strip>=FIRSTSTRIP && strip<=LASTSTRIP && 
03386             lookup.NearOrFar(crate,pulserBox,nearPulserBox,
03387                              farPulserBox,led,detectorType,
03388                              plane,runNumber)==
03389             LILookup::kNearSide &&
03390             led>=FIRSTLED && led<=LASTLED){//near
03391 
03392           if (strip==20 && plane==20){
03393             this->PrintBigMessage(); 
03394           }
03395 
03396           hStripVsPlaneLed[eastWest-1]->Fill(plane,strip,nearLed);
03397           hStripVsPlaneMean[eastWest-1]->Fill(plane,strip,mean);
03398           hStripVsPlaneRms[eastWest-1]->Fill(plane,strip,rms);
03399           hStripVsPlaneNum[eastWest-1]->Fill(plane,strip,numEntries);
03400           hStripVsPlanePix[eastWest-1]->Fill(plane,strip,pixel+1);
03401           hStripVsPlaneEnt[eastWest-1]->Fill(plane,strip,1);
03402           
03403           //make a cut before filling gain histo
03404           if (mean>adcLowerCut && mean<adcUpperCut && 
03405               numEntries>(pulsesCut/100.)*pulses){
03406             hStripVsPlaneNpe[eastWest-1]->Fill(plane,strip,npe);
03407             hStripVsPlaneGainN[eastWest-1]->Fill(plane,strip,gain);
03408             
03409           MSG("LIAnalysis",Msg::kVerbose) 
03410             <<"mean="<<mean 
03411             <<", rms="<<rms 
03412             <<", npe="<<pow(mean/rms,2)
03413             <<", gain="<<gain
03414             <<endl;
03415           }
03416         }
03417       }
03418     }
03419     else{
03420       MSG("LIAnalysis",Msg::kWarning)<<"Detector not defined"<<endl;
03421     }
03422   }//end of for
03423    
03427   
03428   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
03429   MSG("LIAnalysis",Msg::kInfo)<<"Max plane="<<maxPlane<<endl;
03430 
03431   //get rid of the stats info
03432   gStyle->SetOptStat(0);
03433   string sRunNumber=Form("%d",runNumber);
03434 
03435 /*
03436   //get rid of the white sections in histograms
03437   for (Int_t iplane=FIRSTSCINTPLANE;iplane<=maxPlane;iplane++){
03438     for (Int_t iside=StripEnd::kEast;iside<=StripEnd::kWest;iside++){ 
03439       Int_t pb=lookup.Plane2Pb(iplane,iside);
03440       MSG("LIAnalysis",Msg::kDebug)
03441         <<"Plane="<<iplane<<", side="<<iside<<", pb="<<pb<<endl;
03442       if (pb<FIRSTPULSERBOX || pb>LASTPULSERBOX) continue;
03443 
03444       for (Int_t istrip=FIRSTSTRIP;istrip<=LASTSTRIP;istrip++){ 
03445         hStripVsPlaneMean[pb]->Fill(iplane,istrip,0.01);
03446         hStripVsPlaneRms[pb]->Fill(iplane,istrip,0.01);
03447         hStripVsPlaneNpe[pb]->Fill(iplane,istrip,0.01);
03448         hStripVsPlaneGainN[pb]->Fill(iplane,istrip,0.01);
03449         hStripVsPlaneMeanF[pb]->Fill(iplane,istrip,0.01);
03450         hStripVsPlaneRmsF[pb]->Fill(iplane,istrip,0.01);
03451         hStripVsPlaneGainF[pb]->Fill(iplane,istrip,0.01);
03452       }
03453     }
03454   }
03455 */
03456 
03457   MSG("LIAnalysis",Msg::kInfo)<<"Filling gain histos"<<endl;
03458 
03459   //fill gain histogram using value first from near side then far side
03460   for (Int_t i=0;i<NUMCRATES;i++){  
03461     for (Int_t pl=0;pl<planeMax[i]-planeMin[i]+1;pl++){
03462       for (Int_t st=0;st<210;st++){
03463         //calculate opposite pulserbox to get far data
03464         Int_t oppPb=lookup.GetOppPb(i,detectorType);
03465         
03466         //check if gain is ok on near side
03467         if (static_cast<Float_t> 
03468             (hStripVsPlaneGainN[i]->
03469              GetBinContent(pl,st))>0){
03470           hStripVsPlaneGain[i]->Fill(pl+planeMin[i]-1,st+firstStripBin,
03471                                      static_cast<Float_t>
03472                                      (hStripVsPlaneGainN[i]->
03473                                       GetBinContent(pl,st)));
03474         }
03475         //else check if gain is ok on far side
03476         else if (static_cast<Float_t>  
03477                  (hStripVsPlaneGainF[oppPb]-> 
03478                   GetBinContent(pl,st))>0){ 
03479           hStripVsPlaneGain[i]->Fill(pl+planeMin[i]-1,st+firstStripBin,
03480                                      static_cast<Float_t> 
03481                                      (hStripVsPlaneGainF[oppPb]-> 
03482                                       GetBinContent(pl,st))); 
03483         }
03484 
03485         //calculate differences between gain on near and far side
03486         if (static_cast<Float_t> 
03487             (hStripVsPlaneGainN[i]->
03488              GetBinContent(pl,st))>0.1 && 
03489             static_cast<Float_t>  
03490             (hStripVsPlaneGainF[oppPb]-> 
03491              GetBinContent(pl,st))>0.1){
03492 
03493           //calculate gain difference
03494           Float_t gainDifference=static_cast<Float_t>
03495             (hStripVsPlaneGainN[i]->
03496              GetBinContent(pl,st))-
03497             static_cast<Float_t> 
03498             (hStripVsPlaneGainF[oppPb]-> 
03499              GetBinContent(pl,st));
03500  
03501           //fill difference histos
03502           hStripVsPlaneGainDiff[i]->Fill(pl+planeMin[i]-1,
03503                                          st+firstStripBin,
03504                                          gainDifference);
03505           hGainDiff->Fill(gainDifference);
03506         }
03507       } 
03508     }
03509     //set max to mean + 2.33*RMS -> to give 99%
03510     Float_t gainMax=84+2.33*20.7;
03511     hStripVsPlaneGain[i]->SetMaximum(gainMax);
03512 
03513     //set max to mean diff + 2.33*RMS -> to give 99%
03514     Float_t diffMax=-5.3+2.33*7.3;
03515     hStripVsPlaneGainDiff[i]->SetMaximum(diffMax);
03516     //set min to mean diff + 2.33*RMS -> to give 99%
03517     Float_t diffMin=-5.3-2.33*7.3;
03518     hStripVsPlaneGainDiff[i]->SetMinimum(diffMin);
03519   }
03520 
03521   MSG("LIAnalysis",Msg::kInfo)<<"Drawing histos"<<endl;
03522 
03523   TCanvas *cStripVsPlaneMean=new TCanvas
03524     ("cStripVsPlaneMean","StripVsPlane: Mean",0,0,1000,800);
03525   cStripVsPlaneMean->SetFillColor(0);
03526   cStripVsPlaneMean->cd();
03527   for (Int_t i=0;i<NUMCRATES;i++){    
03528     cStripVsPlaneMean->Clear();
03529     hStripVsPlaneMean[i]->Draw("colz");
03530     if (i==0){
03531       s=sRunNumber+"AdcNear.ps(";
03532       cStripVsPlaneMean->Print(s.c_str());
03533     }
03534     else if(i==NUMCRATES-1){
03535       s=sRunNumber+"AdcNear.ps)";
03536       cStripVsPlaneMean->Print(s.c_str()); 
03537       MSG("LIAnalysis",Msg::kInfo)<<"Printed last page of "<<s<<endl;
03538     }
03539     else{
03540       s=sRunNumber+"AdcNear.ps";
03541       cStripVsPlaneMean->Print(s.c_str());
03542     }
03543   }
03544   //draw it so it stays there
03545   cStripVsPlaneMean->Clear();
03546   hStripVsPlaneMean[nearPb]->Draw("colz");
03547   delete cStripVsPlaneMean;
03548   
03549   TCanvas *cStripVsPlaneMeanF=new TCanvas
03550     ("cStripVsPlaneMeanF","StripVsPlane: Mean (Far)",0,0,1000,800);
03551   cStripVsPlaneMeanF->SetFillColor(0);
03552   cStripVsPlaneMeanF->cd();
03553   for (Int_t i=0;i<NUMCRATES;i++){  
03554     cStripVsPlaneMeanF->Clear();
03555     hStripVsPlaneMeanF[i]->Draw("colz");
03556     if (i==0){
03557       s=sRunNumber+"AdcFar.ps(";
03558       cStripVsPlaneMeanF->Print(s.c_str());
03559     }
03560     else if(i==NUMCRATES-1){
03561       s=sRunNumber+"AdcFar.ps)";
03562       cStripVsPlaneMeanF->Print(s.c_str()); 
03563       MSG("LIAnalysis",Msg::kInfo)<<"Printed last page of "<<s<<endl;
03564     }
03565     else{
03566       s=sRunNumber+"AdcFar.ps";
03567       cStripVsPlaneMeanF->Print(s.c_str());
03568     }
03569   }
03570   //draw it so it stays there
03571   cStripVsPlaneMeanF->Clear();
03572   hStripVsPlaneMeanF[farPb]->Draw("colz");
03573   delete cStripVsPlaneMeanF;
03574 
03575   MSG("LIAnalysis",Msg::kInfo)<<"Drawing rms histos"<<endl;
03576 
03577   TCanvas *cStripVsPlaneRms=new TCanvas
03578     ("cStripVsPlaneRms","StripVsPlane: Rms",0,0,1000,800);
03579   cStripVsPlaneRms->SetFillColor(0);
03580   cStripVsPlaneRms->cd();
03581   for (Int_t i=0;i<NUMCRATES;i++){   
03582     cStripVsPlaneRms->Clear();
03583     hStripVsPlaneRms[i]->Draw("colz");
03584     if (i==0){
03585       s=sRunNumber+"RmsNear.ps(";
03586       cStripVsPlaneRms->Print(s.c_str());
03587     }
03588     else if(i==NUMCRATES-1){
03589       s=sRunNumber+"RmsNear.ps)";
03590       cStripVsPlaneRms->Print(s.c_str()); 
03591       MSG("LIAnalysis",Msg::kInfo)<<"Printed last page of "<<s<<endl;
03592     }
03593     else{
03594       s=sRunNumber+"RmsNear.ps";
03595       cStripVsPlaneRms->Print(s.c_str());
03596     }
03597   }
03598   //draw it so it stays there
03599   cStripVsPlaneRms->Clear();
03600   hStripVsPlaneRms[nearPb]->Draw("colz");
03601   delete cStripVsPlaneRms;
03602   
03603   TCanvas *cStripVsPlaneRmsF=new TCanvas
03604     ("cStripVsPlaneRmsF","StripVsPlane: Rms (Far)",0,0,1000,800);
03605   cStripVsPlaneRmsF->SetFillColor(0);
03606   cStripVsPlaneRmsF->cd();
03607   for (Int_t i=0;i<NUMCRATES;i++){  
03608     cStripVsPlaneRmsF->Clear();
03609     hStripVsPlaneRmsF[i]->Draw("colz");
03610     if (i==0){
03611       s=sRunNumber+"RmsFar.ps(";
03612       cStripVsPlaneRmsF->Print(s.c_str());
03613     }
03614     else if(i==NUMCRATES-1){
03615       s=sRunNumber+"RmsFar.ps)";
03616       cStripVsPlaneRmsF->Print(s.c_str()); 
03617       MSG("LIAnalysis",Msg::kInfo)<<"Printed last page of "<<s<<endl;
03618     }
03619     else{
03620       s=sRunNumber+"RmsFar.ps";
03621       cStripVsPlaneRmsF->Print(s.c_str());
03622     }
03623   }
03624   //draw it so it stays there
03625   cStripVsPlaneRmsF->Clear();
03626   hStripVsPlaneRmsF[farPb]->Draw("colz");
03627   delete cStripVsPlaneRmsF;
03628 
03629   MSG("LIAnalysis",Msg::kInfo)<<"Drawing num ent histos"<<endl;
03630 
03631   TCanvas *cStripVsPlaneNum=new TCanvas 
03632     ("cStripVsPlaneNum","StripVsPlane: Num",0,0,1000,800); 
03633   cStripVsPlaneNum->SetFillColor(0); 
03634   cStripVsPlaneNum->cd(); 
03635   for (Int_t i=0;i<NUMCRATES;i++){     
03636     cStripVsPlaneNum->Clear();
03637     hStripVsPlaneNum[i]->Draw("colz"); 
03638     if (i==0){ 
03639       s=sRunNumber+"NumEntriesNear.ps("; 
03640       cStripVsPlaneNum->Print(s.c_str()); 
03641     } 
03642     else if(i==NUMCRATES-1){ 
03643       s=sRunNumber+"NumEntriesNear.ps)"; 
03644       cStripVsPlaneNum->Print(s.c_str());  
03645       MSG("LIAnalysis",Msg::kInfo)<<"Printed last page of "<<s<<endl; 
03646     } 
03647     else{ 
03648       s=sRunNumber+"NumEntriesNear.ps"; 
03649       cStripVsPlaneNum->Print(s.c_str()); 
03650     } 
03651   } 
03652   //draw it so it stays there 
03653   cStripVsPlaneNum->Clear(); 
03654   hStripVsPlaneNum[nearPb]->Draw("colz"); 
03655   delete cStripVsPlaneNum; 
03656 
03657   TCanvas *cStripVsPlaneNumF=new TCanvas 
03658     ("cStripVsPlaneNumF","StripVsPlane: Num (Far)",0,0,1000,800); 
03659   cStripVsPlaneNumF->SetFillColor(0); 
03660   cStripVsPlaneNumF->cd(); 
03661   for (Int_t i=0;i<NUMCRATES;i++){   
03662     cStripVsPlaneNumF->Clear(); 
03663     hStripVsPlaneNumF[i]->Draw("colz"); 
03664     if (i==0){ 
03665       s=sRunNumber+"NumEntriesFar.ps("; 
03666       cStripVsPlaneNumF->Print(s.c_str()); 
03667     } 
03668     else if(i==NUMCRATES-1){ 
03669       s=sRunNumber+"NumEntriesFar.ps)"; 
03670       cStripVsPlaneNumF->Print(s.c_str());  
03671       MSG("LIAnalysis",Msg::kInfo)<<"Printed last page of "<<s<<endl; 
03672     } 
03673     else{ 
03674       s=sRunNumber+"NumEntriesFar.ps"; 
03675       cStripVsPlaneNumF->Print(s.c_str()); 
03676     } 
03677   } 
03678   //draw it so it stays there 
03679   cStripVsPlaneNumF->Clear(); 
03680   hStripVsPlaneNumF[farPb]->Draw("colz"); 
03681   delete cStripVsPlaneNumF; 
03682 
03683   //set stats info
03684   gStyle->SetOptStat(1111111);
03685 
03686   TCanvas *cGainDiff=new TCanvas  
03687     ("cGainDiff","Gain Differences",0,0,1200,800);  
03688   cGainDiff->SetFillColor(0);  
03689   cGainDiff->cd();  
03690   hGainDiff->Draw();  
03691   s=sRunNumber+"GainDiffHisto.ps";  
03692   cGainDiff->Print(s.c_str());  
03693 
03694   //get rid of the stats info
03695   gStyle->SetOptStat(0);
03696 
03697   TCanvas *cStripVsPlaneGain=new TCanvas  
03698     ("cStripVsPlaneGain","StripVsPlane: Gain",0,0,1000,800);  
03699   cStripVsPlaneGain->SetFillColor(0);  
03700   cStripVsPlaneGain->cd();  
03701   for (Int_t i=0;i<NUMCRATES;i++){    
03702     cStripVsPlaneGain->Clear();  
03703     hStripVsPlaneGain[i]->Draw("colz");  
03704     if (i==0){  
03705       s=sRunNumber+"Gain.ps(";  
03706       cStripVsPlaneGain->Print(s.c_str());  
03707     }  
03708     else if(i==NUMCRATES-1){  
03709       s=sRunNumber+"Gain.ps)";  
03710       cStripVsPlaneGain->Print(s.c_str());   
03711       MSG("LIAnalysis",Msg::kInfo)<<"Printed last page of "<<s<<endl;
03712     }  
03713     else{  
03714       s=sRunNumber+"Gain.ps";  
03715       cStripVsPlaneGain->Print(s.c_str());  
03716     }  
03717   }  
03718   //draw it so it stays there  
03719   cStripVsPlaneGain->Clear();  
03720   //hStripVsPlaneGain[farPb]->Draw("colz");  
03721   //delete cStripVsPlaneGain;  
03722 
03723   TCanvas *cStripVsPlaneGainN=new TCanvas 
03724     ("cStripVsPlaneGainN","StripVsPlane: Gain (Near)",0,0,1000,800); 
03725   cStripVsPlaneGainN->SetFillColor(0); 
03726   cStripVsPlaneGainN->cd(); 
03727   for (Int_t i=0;i<NUMCRATES;i++){   
03728     cStripVsPlaneGainN->Clear(); 
03729     hStripVsPlaneGainN[i]->Draw("colz"); 
03730     if (i==0){ 
03731       s=sRunNumber+"GainNear.ps("; 
03732       cStripVsPlaneGainN->Print(s.c_str()); 
03733     } 
03734     else if(i==NUMCRATES-1){ 
03735       s=sRunNumber+"GainNear.ps)"; 
03736       cStripVsPlaneGainN->Print(s.c_str());  
03737       MSG("LIAnalysis",Msg::kInfo)<<"Printed last page of "<<s<<endl;
03738     } 
03739     else{ 
03740       s=sRunNumber+"GainNear.ps"; 
03741       cStripVsPlaneGainN->Print(s.c_str()); 
03742     } 
03743   } 
03744 
03745   //draw it with a contrast enhancing colour scheme
03746   cStripVsPlaneGainN->Clear(); 
03747   //hStripVsPlaneGainN[farPb]->Draw("colz"); 
03748   //delete cStripVsPlaneGainN; 
03749   cStripVsPlaneGainN->cd(); 
03750   for (Int_t i=0;i<NUMCRATES;i++){   
03751     cStripVsPlaneGainN->Clear(); 
03752     hStripVsPlaneGainN[i]->SetMaximum(90);
03753     hStripVsPlaneGainN[i]->Draw("colz"); 
03754     if (i==0){ 
03755       s=sRunNumber+"Max90GainNear.ps("; 
03756       cStripVsPlaneGainN->Print(s.c_str()); 
03757     } 
03758     else if(i==NUMCRATES-1){ 
03759       s=sRunNumber+"Max90GainNear.ps)"; 
03760       cStripVsPlaneGainN->Print(s.c_str());  
03761       MSG("LIAnalysis",Msg::kInfo)<<"Printed last page of "<<s<<endl;
03762     } 
03763     else{ 
03764       s=sRunNumber+"Max90GainNear.ps"; 
03765       cStripVsPlaneGainN->Print(s.c_str()); 
03766     } 
03767   } 
03768 
03769   //plot the whole detector on one page
03770   cStripVsPlaneGainN->Clear(); 
03771   cStripVsPlaneGainN->cd(); 
03772   for (Int_t i=0;i<NUMSIDES;i++){   
03773     cStripVsPlaneGainN->Clear(); 
03774     hStripVsPlaneGainAll[i]->SetMaximum(90);
03775     hStripVsPlaneGainAll[i]->Draw("colz"); 
03776     if (i==0){ 
03777       s=sRunNumber+"AllGainNear.ps("; 
03778       cStripVsPlaneGainN->Print(s.c_str()); 
03779     } 
03780     else if(i==NUMSIDES-1){ 
03781       s=sRunNumber+"AllGainNear.ps)"; 
03782       cStripVsPlaneGainN->Print(s.c_str());  
03783       MSG("LIAnalysis",Msg::kInfo)<<"Printed last page of "<<s<<endl;
03784     } 
03785     else{ 
03786       s=sRunNumber+"AllGainNear.ps"; 
03787       cStripVsPlaneGainN->Print(s.c_str()); 
03788     } 
03789   } 
03790 
03791   TCanvas *cStripVsPlaneGainF=new TCanvas 
03792     ("cStripVsPlaneGainF","StripVsPlane: Gain (Far)",0,0,1000,800); 
03793   cStripVsPlaneGainF->SetFillColor(0); 
03794   cStripVsPlaneGainF->cd(); 
03795   for (Int_t i=0;i<NUMCRATES;i++){   
03796     cStripVsPlaneGainF->Clear(); 
03797     hStripVsPlaneGainF[i]->Draw("colz"); 
03798     if (i==0){ 
03799       s=sRunNumber+"GainFar.ps("; 
03800       cStripVsPlaneGainF->Print(s.c_str()); 
03801     } 
03802     else if(i==NUMCRATES-1){ 
03803       s=sRunNumber+"GainFar.ps)"; 
03804       cStripVsPlaneGainF->Print(s.c_str());  
03805       MSG("LIAnalysis",Msg::kInfo)<<"Printed last page of "<<s<<endl;
03806     } 
03807     else{ 
03808       s=sRunNumber+"GainFar.ps"; 
03809       cStripVsPlaneGainF->Print(s.c_str()); 
03810     } 
03811   } 
03812   //draw it so it stays there 
03813   cStripVsPlaneGainF->Clear(); 
03814   hStripVsPlaneGainF[farPb]->Draw("colz"); 
03815   delete cStripVsPlaneGainF; 
03816 
03817   TCanvas *cStripVsPlaneGainDiff=new TCanvas  
03818     ("cStripVsPlaneGainDiff","StripVsPlane: GainDiff",0,0,1000,800);  
03819   cStripVsPlaneGainDiff->SetFillColor(0);  
03820   cStripVsPlaneGainDiff->cd();  
03821   for (Int_t i=0;i<NUMCRATES;i++){    
03822     cStripVsPlaneGainDiff->Clear();  
03823     hStripVsPlaneGainDiff[i]->Draw("colz");  
03824     if (i==0){  
03825       s=sRunNumber+"GainDiff.ps(";  
03826       cStripVsPlaneGainDiff->Print(s.c_str());  
03827     }  
03828     else if(i==NUMCRATES-1){  
03829       s=sRunNumber+"GainDiff.ps)";  
03830       cStripVsPlaneGainDiff->Print(s.c_str());   
03831       MSG("LIAnalysis",Msg::kInfo)<<"Printed last page of "<<s<<endl;
03832     }  
03833     else{  
03834       s=sRunNumber+"GainDiff.ps";  
03835       cStripVsPlaneGainDiff->Print(s.c_str());  
03836     }  
03837   }  
03838   //draw it so it stays there  
03839   cStripVsPlaneGainDiff->Clear();  
03840   hStripVsPlaneGainDiff[farPb]->Draw("colz");  
03841   delete cStripVsPlaneGainDiff;  
03842 
03843   TCanvas *cStripVsPlaneEntEast=new TCanvas
03844     ("cStripVsPlaneEntEast","StripVsPlane: East Side (Near)"
03845      ,0,0,1200,800);
03846   cStripVsPlaneEntEast->SetFillColor(0);
03847   cStripVsPlaneEntEast->cd();
03848   hStripVsPlaneLedB->SetTitle("East Side (Near)");
03849   hStripVsPlaneLedB->Draw();
03850   for (Int_t i=0;i<NUMCRATES;i+=2){
03851     hStripVsPlaneEnt[i]->Draw("samecolz");
03852   }
03853   s=sRunNumber+"NumberEntries.ps(";
03854   cStripVsPlaneEntEast->Print(s.c_str()); 
03855   delete cStripVsPlaneEntEast;
03856 
03857   TCanvas *cStripVsPlaneEntWest=new TCanvas
03858     ("cStripVsPlaneEntWest","StripVsPlane: West Side (Near)"
03859      ,0,0,1200,800);
03860   cStripVsPlaneEntWest->SetFillColor(0);
03861   cStripVsPlaneEntWest->cd();
03862   hStripVsPlaneLedB->SetTitle("West Side (Near)");
03863   hStripVsPlaneLedB->Draw();
03864   for (Int_t i=1;i<NUMCRATES;i+=2){
03865     hStripVsPlaneEnt[i]->Draw("samecolz");
03866   }
03867   s=sRunNumber+"NumberEntries.ps";
03868   cStripVsPlaneEntWest->Print(s.c_str()); 
03869   delete cStripVsPlaneEntWest;
03870 
03871   TCanvas *cStripVsPlaneEntWestF=new TCanvas
03872     ("cStripVsPlaneEntWestF","StripVsPlane: West Side (Far)"
03873      ,0,0,1200,800);
03874   cStripVsPlaneEntWestF->SetFillColor(0);
03875   cStripVsPlaneEntWestF->cd();
03876   hStripVsPlaneLedB->SetTitle("West Side (Far)");
03877   hStripVsPlaneLedB->Draw();
03878   for (Int_t i=0;i<NUMCRATES;i+=2){
03879     hStripVsPlaneEntF[i]->Draw("samecolz");
03880   }
03881   s=sRunNumber+"NumberEntries.ps";
03882   cStripVsPlaneEntWestF->Print(s.c_str());
03883   delete cStripVsPlaneEntWestF;
03884 
03885   TCanvas *cStripVsPlaneEntEastF=new TCanvas
03886     ("cStripVsPlaneEntEastF","StripVsPlane: East Side (Far)"
03887      ,0,0,1200,800);
03888   cStripVsPlaneEntEastF->SetFillColor(0);
03889   cStripVsPlaneEntEastF->cd();
03890   hStripVsPlaneLedB->SetTitle("East Side (Far)");
03891   hStripVsPlaneLedB->Draw();
03892   for (Int_t i=1;i<NUMCRATES;i+=2){
03893     hStripVsPlaneEntF[i]->Draw("samecolz");
03894   }
03895   s=sRunNumber+"NumberEntries.ps)";
03896   cStripVsPlaneEntEastF->Print(s.c_str());
03897   MSG("LIAnalysis",Msg::kInfo)<<"Printed last page of "<<s<<endl;
03898   delete cStripVsPlaneEntEastF;
03899 
03900   TCanvas *cStripVsPlaneXTalk=new TCanvas
03901     ("cStripVsPlaneXTalk","StripVsPlane: XTalk",0,0,1000,800);
03902   cStripVsPlaneXTalk->SetFillColor(0);
03903   cStripVsPlaneXTalk->cd();
03904   for (Int_t i=0;i<NUMCRATES;i++){ 
03905     cStripVsPlaneXTalk->Clear();
03906     hStripVsPlaneXTalk[i]->Draw("colz");
03907     if (i==0){
03908       s=sRunNumber+"XTalkNear.ps(";
03909       cStripVsPlaneXTalk->Print(s.c_str());
03910     }
03911     else if(i==NUMCRATES-1){
03912       s=sRunNumber+"XTalkNear.ps)";
03913       cStripVsPlaneXTalk->Print(s.c_str()); 
03914       MSG("LIAnalysis",Msg::kInfo)<<"Printed last page of "<<s<<endl;
03915     }
03916     else{
03917       s=sRunNumber+"XTalkNear.ps";
03918       cStripVsPlaneXTalk->Print(s.c_str());
03919     }
03920   }
03921 
03922   TCanvas *cStripVsPlaneAll=new TCanvas
03923     ("cStripVsPlaneAll","StripVsPlane: All",0,0,1000,800);
03924   cStripVsPlaneAll->SetFillColor(0);
03925   cStripVsPlaneAll->cd();
03926   for (Int_t i=0;i<NUMCRATES;i++){  
03927     cStripVsPlaneAll->Clear();
03928     MSG("LIAnalysis",Msg::kInfo)
03929     <<"Drawing StripVsPlane: All"<<endl;
03930     hStripVsPlaneAll[i]->Draw("colz");
03931     if (i==0){
03932       s=sRunNumber+"All.ps(";
03933       cStripVsPlaneAll->Print(s.c_str());
03934     }
03935     else if(i==NUMCRATES-1){
03936       s=sRunNumber+"All.ps)";
03937       cStripVsPlaneAll->Print(s.c_str()); 
03938       MSG("LIAnalysis",Msg::kInfo)<<"Printed last page of "<<s<<endl;
03939     }
03940     else{
03941       s=sRunNumber+"All.ps";
03942       cStripVsPlaneAll->Print(s.c_str());
03943     }
03944   }
03945 
03946   TCanvas *cStripVsPlaneLed=new TCanvas
03947     ("cStripVsPlaneLed","StripVsPlane: Led",0,0,1000,800);
03948   cStripVsPlaneLed->SetFillColor(0);
03949   cStripVsPlaneLed->cd();
03950   for (Int_t i=0;i<NUMCRATES;i++){   
03951     cStripVsPlaneLed->Clear();
03952     hStripVsPlaneLed[i]->Draw("colz");
03953     if (i==0){
03954       s=sRunNumber+"LedNear.ps(";
03955       cStripVsPlaneLed->Print(s.c_str());
03956     }
03957     else if(i==NUMCRATES-1){
03958       s=sRunNumber+"LedNear.ps)";
03959       cStripVsPlaneLed->Print(s.c_str()); 
03960       MSG("LIAnalysis",Msg::kInfo)<<"Printed last page of "<<s<<endl;
03961     }
03962     else{
03963       s=sRunNumber+"LedNear.ps";
03964       cStripVsPlaneLed->Print(s.c_str());
03965     }
03966   }
03967 
03968   MSG("LIAnalysis",Msg::kInfo)
03969     <<" ** Finished the StripVsPlane method ** "<<endl;
03970 }
03971 //......................................................................
03972 
03973 void LIAnalysis::StripVsPlaneWholeDet()
03974 {
03975   MSG("LIAnalysis",Msg::kInfo)
03976     <<endl<<" ** Running the StripVsPlaneWholeDet method... ** "<<endl;
03977   
03978   chain->GetEvent(0);
03979 
03980   if (calibType>1){
03981     MSG("LIAnalysis",Msg::kWarning)
03982       <<endl<<"Gain curve file detected with "<<calibType<<" points"
03983       <<endl<<"Only the last gain curve point will be used"<<endl;
03984   }
03985 
03986   const Int_t firstStripBin=FIRSTSTRIP-8;//-8;
03987   const Int_t lastStripBin=LASTSTRIP+9;//200;
03988   const Int_t bins=lastStripBin-firstStripBin;
03989 
03990   string sPulseWidth=Form("%d",pulseWidth);
03991   string sPulseHeight=Form("%d",pulseHeight);
03992   string sPulseFreq=Form("%d",static_cast<Int_t>
03993                          (ceil(1.0/(period*1.0e-5))));
03994   string sPulses=Form("%d",pulses);
03995   string sConstantBit="";
03996 
03997   if (detectorType==Detector::kFar){
03998     MSG("LIAnalysis",Msg::kInfo)
03999       <<"Setting histo titles according to detector type kFar"<<endl;
04000 
04001     if (runNumber>=13123){//don't use pulse height
04002       Int_t fph=pulseHeight;
04003       //this caused a segv so have disabled it
04004       //chain->GetEvent(numEvents-1);
04005       Int_t lph=-10;//pulseHeight;
04006       
04007       MSG("LIAnalysis",Msg::kInfo)
04008         <<"first ph="<<fph<<", last ph="<<lph<<endl;
04009 
04010       if (lph==fph){
04011         sConstantBit=+", PH="+sPulseHeight+", PW="+sPulseWidth+
04012           ", PF="+sPulseFreq+" Hz, PN="+sPulses+")";
04013       }
04014       else if (lph!=fph){
04015         sConstantBit=+", PW="+sPulseWidth+
04016           ", PF="+sPulseFreq+" Hz, PN="+sPulses+")";
04017       }
04018     }
04019     else{
04020       sConstantBit=+", PH="+sPulseHeight+", PW="+sPulseWidth+
04021         ", PF="+sPulseFreq+" Hz, PN="+sPulses+")";
04022     }
04023   }
04024   else if (detectorType==Detector::kCalDet){
04025     MSG("LIAnalysis",Msg::kInfo)
04026       <<"Setting histo titles according to detector type kCalDet"<<endl;
04027 
04028     Int_t fph=pulseHeight;
04029     //chain->GetEvent(numEvents-1);
04030     Int_t lph=-10;//pulseHeight;
04031     
04032     MSG("LIAnalysis",Msg::kInfo)
04033       <<"first ph="<<fph<<", last ph="<<lph<<endl;
04034 
04035     if (lph==fph){
04036       sConstantBit=+", PH="+sPulseHeight+", PW="+sPulseWidth+
04037         ", PF="+sPulseFreq+" Hz, PN="+sPulses+")";
04038     }
04039     else if (lph!=fph){
04040       sConstantBit=+", PW="+sPulseWidth+
04041         ", PF="+sPulseFreq+" Hz, PN="+sPulses+")";
04042     }
04043   }
04044  
04045   MSG("LIAnalysis",Msg::kInfo)
04046     <<"sConstantBit="<<sConstantBit<<endl;
04047 
04048   s="Strip Vs Plane Adc Map (East side"+sConstantBit;
04049   TH2F *hStripVsPlaneAdcEast=new TH2F(s.c_str(),s.c_str(),
04050                                   LASTSCINTPLANE-FIRSTSCINTPLANE+2,
04051                                   0,LASTSCINTPLANE+1,
04052                                   bins,firstStripBin,lastStripBin);
04053   hStripVsPlaneAdcEast->GetXaxis()->SetTitle("Plane");
04054   hStripVsPlaneAdcEast->GetXaxis()->CenterTitle();
04055   hStripVsPlaneAdcEast->GetYaxis()->SetTitle("Strip");
04056   hStripVsPlaneAdcEast->GetYaxis()->CenterTitle();
04057   hStripVsPlaneAdcEast->SetFillColor(0);
04058   hStripVsPlaneAdcEast->SetMaximum(15000);
04059 
04060   s="Strip Vs Plane Adc Map (West side"+sConstantBit;
04061   TH2F *hStripVsPlaneAdcWest=new TH2F(s.c_str(),s.c_str(),
04062                                   LASTSCINTPLANE-FIRSTSCINTPLANE+2,
04063                                   0,LASTSCINTPLANE+1,
04064                                   bins,firstStripBin,lastStripBin);
04065   hStripVsPlaneAdcWest->GetXaxis()->SetTitle("Plane");
04066   hStripVsPlaneAdcWest->GetXaxis()->CenterTitle();
04067   hStripVsPlaneAdcWest->GetYaxis()->SetTitle("Strip");
04068   hStripVsPlaneAdcWest->GetYaxis()->CenterTitle();
04069   hStripVsPlaneAdcWest->SetFillColor(0);
04070   hStripVsPlaneAdcWest->SetMaximum(15000);
04071 
04072   s="Strip Vs Plane Pulses Map (East side"+sConstantBit;
04073   TH2F *hStripVsPlanePulsesEast=new TH2F(s.c_str(),s.c_str(),
04074                                   LASTSCINTPLANE-FIRSTSCINTPLANE+2,
04075                                   0,LASTSCINTPLANE+1,
04076                                   bins,firstStripBin,lastStripBin);
04077   hStripVsPlanePulsesEast->GetXaxis()->SetTitle("Plane");
04078   hStripVsPlanePulsesEast->GetXaxis()->CenterTitle();
04079   hStripVsPlanePulsesEast->GetYaxis()->SetTitle("Strip");
04080   hStripVsPlanePulsesEast->GetYaxis()->CenterTitle();
04081   hStripVsPlanePulsesEast->SetFillColor(0);
04082   //hStripVsPlanePulsesEast->SetMaximum();
04083 
04084   s="Strip Vs Plane Pulses Map (West side"+sConstantBit;
04085   TH2F *hStripVsPlanePulsesWest=new TH2F(s.c_str(),s.c_str(),
04086                                   LASTSCINTPLANE-FIRSTSCINTPLANE+2,
04087                                   0,LASTSCINTPLANE+1,
04088                                   bins,firstStripBin,lastStripBin);
04089   hStripVsPlanePulsesWest->GetXaxis()->SetTitle("Plane");
04090   hStripVsPlanePulsesWest->GetXaxis()->CenterTitle();
04091   hStripVsPlanePulsesWest->GetYaxis()->SetTitle("Strip");
04092   hStripVsPlanePulsesWest->GetYaxis()->CenterTitle();
04093   hStripVsPlanePulsesWest->SetFillColor(0);
04094   //hStripVsPlanePulsesWest->SetMaximum();
04095 
04096   s="Strip Vs Plane Gain Map (East side, max of 120"+sConstantBit;
04097   TH2F *hStripVsPlaneGainEast=new TH2F(s.c_str(),s.c_str(),
04098                                   LASTSCINTPLANE-FIRSTSCINTPLANE+2,
04099                                   0,LASTSCINTPLANE+1,
04100                                   bins,firstStripBin,lastStripBin);
04101   hStripVsPlaneGainEast->GetXaxis()->SetTitle("Plane");
04102   hStripVsPlaneGainEast->GetXaxis()->CenterTitle();
04103   hStripVsPlaneGainEast->GetYaxis()->SetTitle("Strip");
04104   hStripVsPlaneGainEast->GetYaxis()->CenterTitle();
04105   hStripVsPlaneGainEast->SetFillColor(0);
04106   hStripVsPlaneGainEast->SetMaximum(120);
04107 
04108   s="Strip Vs Plane Gain Map (West side, max of 120"+sConstantBit;
04109   TH2F *hStripVsPlaneGainWest=new TH2F(s.c_str(),s.c_str(),
04110                                   LASTSCINTPLANE-FIRSTSCINTPLANE+2,
04111                                   0,LASTSCINTPLANE+1,
04112                                   bins,firstStripBin,lastStripBin);
04113   hStripVsPlaneGainWest->GetXaxis()->SetTitle("Plane");
04114   hStripVsPlaneGainWest->GetXaxis()->CenterTitle();
04115   hStripVsPlaneGainWest->GetYaxis()->SetTitle("Strip");
04116   hStripVsPlaneGainWest->GetYaxis()->CenterTitle();
04117   hStripVsPlaneGainWest->SetFillColor(0);
04118   hStripVsPlaneGainWest->SetMaximum(120);
04119 
04120   Int_t maxPlane=0;
04121 
04122   MSG("LIAnalysis",Msg::kInfo) 
04123     <<"Starting main loop..."<<endl;
04124 
04128 
04129   this->InitialiseLoopVariables();  
04130 
04131   for(Int_t entry=0;entry<numEvents;entry++){
04132 
04133     this->SetLoopVariables(entry,0);
04134     
04135     //avoid divide by zero errors and skip irrelevant data
04136     if (rms==0. || mean==0. || numEntries==0) continue;
04137     //only look at scintillator strips
04138     if (readoutType!=ReadoutType::kScintStrip) continue;
04139     //decide which point to use if it's a gain curve file
04140     if (calibType>1){
04141       //only use the last gain curve point
04142       if (calibPoint!=calibType) continue;
04143     }
04144 
04145     //calculate the max plane
04146     if (plane>maxPlane && mean>2000) maxPlane=plane;
04147 
04148     //Int_t side=crate%2;
04149     Float_t npe=mean*mean/(rms*rms);
04150     Float_t gain=0.8*mean/npe;
04151 
04152     // PMT fudge factor for M64 (near detector): 0.844
04153     if (detectorType==Detector::kNear) gain = 0.844*rms*rms/mean;
04154 
04156     //section for fardet and neardet setup
04158     if (detectorType==Detector::kFar 
04159         || detectorType==Detector::kNear){
04160       
04161       if (pulserBox>=0 && pulserBox<NUMPULSERBOXES && 
04162           correlatedHit==1 &&
04163           strip<=LASTSTRIP && strip>=FIRSTSTRIP && 
04164           pulserBox==farPulserBox){
04165         
04166       }
04167       
04168       if (pulserBox>=0 && pulserBox<NUMPULSERBOXES && 
04169           correlatedHit==1 &&
04170           strip<=LASTSTRIP && strip>=FIRSTSTRIP && 
04171           pulserBox==nearPulserBox){
04172         
04173         if (stripEnd==StripEnd::kEast){
04174           hStripVsPlaneAdcEast->Fill(plane,strip,mean);
04175           hStripVsPlanePulsesEast->Fill(plane,strip,numEntries);
04176           if (mean<8000 && mean>500){
04177             hStripVsPlaneGainEast->Fill(plane,strip,gain);
04178           }
04179         }       
04180         else if (stripEnd==StripEnd::kWest){
04181           hStripVsPlaneAdcWest->Fill(plane,strip,mean);
04182           hStripVsPlanePulsesWest->Fill(plane,strip,numEntries);
04183           if (mean<8000 && mean>500){
04184             hStripVsPlaneGainWest->Fill(plane,strip,gain);
04185           }
04186         }       
04187       }
04188     }
04189 
04190     else{
04191       MSG("LIAnalysis",Msg::kWarning)<<"Detector not defined"<<endl;
04192     }
04193   }//end of for
04194    
04198   
04199   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
04200   MSG("LIAnalysis",Msg::kInfo)<<"Max plane="<<maxPlane<<endl;
04201 
04202   //get rid of the stats info
04203   gStyle->SetOptStat(0);
04204   string sRunNumber=Form("%d",runNumber);
04205 
04206   TCanvas *cStripVsPlaneMean=new TCanvas
04207     ("cStripVsPlaneMean","StripVsPlane: Mean",0,0,1100,800);
04208   cStripVsPlaneMean->SetFillColor(0);
04209   cStripVsPlaneMean->Divide(1,2);
04210   cStripVsPlaneMean->cd(1);
04211   hStripVsPlaneAdcEast->Draw("colz");
04212   cStripVsPlaneMean->cd(2);
04213   hStripVsPlaneAdcWest->Draw("colz");
04214   s=sRunNumber;
04215   s+="AdcNearWhole.ps";
04216   cStripVsPlaneMean->Print(s.c_str());
04217 
04218   TCanvas *cStripVsPlanePulses=new TCanvas
04219     ("cStripVsPlanePulses","StripVsPlane: Pulses",0,0,1100,800);
04220   cStripVsPlanePulses->SetFillColor(0);
04221   cStripVsPlanePulses->Divide(1,2);
04222   cStripVsPlanePulses->cd(1);
04223   hStripVsPlanePulsesEast->Draw("colz");
04224   cStripVsPlanePulses->cd(2);
04225   hStripVsPlanePulsesWest->Draw("colz");
04226   s=sRunNumber;
04227   s+="NumNearWhole.ps";
04228   cStripVsPlanePulses->Print(s.c_str());
04229 
04230   TCanvas *cStripVsPlaneGain=new TCanvas
04231     ("cStripVsPlaneGain","StripVsPlane: Gain",0,0,1100,800);
04232   cStripVsPlaneGain->SetFillColor(0);
04233   cStripVsPlaneGain->Divide(1,2);
04234   cStripVsPlaneGain->cd(1);
04235   hStripVsPlaneGainEast->Draw("colz");
04236   cStripVsPlaneGain->cd(2);
04237   hStripVsPlaneGainWest->Draw("colz");
04238   s=sRunNumber;
04239   s+="GainNearWhole.ps";
04240   cStripVsPlaneGain->Print(s.c_str());
04241 
04242   MSG("LIAnalysis",Msg::kInfo)
04243     <<" ** Finished the StripVsPlaneWholeDet method ** "<<endl;
04244 }
04245 
04246 //......................................................................
04247 
04248 void LIAnalysis::PixelVsPlane(Int_t nearPb,Int_t farPb)
04249 {
04250   MSG("LIAnalysis",Msg::kInfo)
04251     <<endl<<" ** Running the PixelVsPlane method... ** "<<endl;
04252  
04253   //get rid of the stats info
04254   gStyle->SetOptStat(0);
04255   chain->GetEvent(0);
04256 
04257   Int_t* planeMax=new Int_t[NUMPULSERBOXES];
04258   Int_t* planeMin=new Int_t[NUMPULSERBOXES];
04259   lookup.SetPbPlanes(planeMin,planeMax,detectorType);
04260 
04261   Int_t minBinPix=FIRSTPIXEL-1;
04262   Int_t maxBinPix=3*NUMPIXELS+1;
04263   Int_t numBinPix=maxBinPix-minBinPix;
04264   Int_t maxPixel=NUMPMTS*NUMPIXELS;
04265 
04266   MSG("LIAnalysis",Msg::kInfo)
04267     <<"Using the following settings:"<<endl
04268     <<"maxPixel="<<maxPixel
04269     <<", maxBinPix="<<maxBinPix
04270     <<", minBinPix="<<minBinPix
04271     <<", numBinPix="<<numBinPix
04272     <<", NUMPMTS="<<NUMPMTS
04273     <<", NUMPIXELS="<<NUMPIXELS
04274     <<endl; 
04275 
04276   TH2F *hPixelVsPlaneLedB=new TH2F(" "," ",
04277                                    LASTSCINTPLANE-FIRSTSCINTPLANE+2,
04278                                    FIRSTSCINTPLANE,LASTSCINTPLANE+1,
04279                                    numBinPix,minBinPix,maxBinPix);
04280 
04281   TH2F **hPixelVsPlaneLed=0;
04282   hPixelVsPlaneLed= new TH2F*[NUMPULSERBOXES];
04283   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04284     sprintf(histname,"Led (Pulser Box %i)",i);
04285     hPixelVsPlaneLed[i]=new TH2F
04286       (histname,histname,
04287        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
04288        ,numBinPix,minBinPix,maxBinPix);
04289     hPixelVsPlaneLed[i]->GetXaxis()->SetTitle("Plane");
04290     hPixelVsPlaneLed[i]->GetXaxis()->CenterTitle();
04291     hPixelVsPlaneLed[i]->GetYaxis()->SetTitle("Num Entries");
04292     hPixelVsPlaneLed[i]->GetYaxis()->CenterTitle();
04293     hPixelVsPlaneLed[i]->SetFillColor(0);
04294     hPixelVsPlaneLed[i]->SetBit(TH1::kCanRebin);
04295   }
04296 
04297   TH2F **hPixelVsPlaneMean=0;
04298   hPixelVsPlaneMean= new TH2F*[NUMPULSERBOXES];
04299   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04300     sprintf(histname,"ADC Value (Near Side, Pulser Box %i)",i);
04301     hPixelVsPlaneMean[i]=new TH2F
04302       (histname,histname,
04303        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
04304        ,numBinPix,minBinPix,maxBinPix);
04305     hPixelVsPlaneMean[i]->GetXaxis()->SetTitle("Plane");
04306     hPixelVsPlaneMean[i]->GetXaxis()->CenterTitle();
04307     hPixelVsPlaneMean[i]->GetYaxis()->SetTitle("Pixel");
04308     hPixelVsPlaneMean[i]->GetYaxis()->CenterTitle();
04309     hPixelVsPlaneMean[i]->SetFillColor(0);
04310     hPixelVsPlaneMean[i]->SetBit(TH1::kCanRebin);
04311   }
04312 
04313   TH2F **hPixelVsPlaneMeanF=0;
04314   hPixelVsPlaneMeanF= new TH2F*[NUMPULSERBOXES];
04315   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04316     sprintf(histname,"ADC Value (Far Side, Pulser Box %i)",i);
04317     hPixelVsPlaneMeanF[i]=new TH2F
04318       (histname,histname,
04319        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
04320        ,numBinPix,minBinPix,maxBinPix);
04321     hPixelVsPlaneMeanF[i]->GetXaxis()->SetTitle("Plane");
04322     hPixelVsPlaneMeanF[i]->GetXaxis()->CenterTitle();
04323     hPixelVsPlaneMeanF[i]->GetYaxis()->SetTitle("Pixel");
04324     hPixelVsPlaneMeanF[i]->GetYaxis()->CenterTitle();
04325     hPixelVsPlaneMeanF[i]->SetFillColor(0);
04326     hPixelVsPlaneMeanF[i]->SetBit(TH1::kCanRebin);
04327   }
04328 
04329   TH2F **hPixelVsPlaneNum=0;
04330   hPixelVsPlaneNum= new TH2F*[NUMPULSERBOXES];
04331   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04332     sprintf(histname,"Num (Pulser Box %i)",i);
04333     hPixelVsPlaneNum[i]=new TH2F
04334       (histname,histname,
04335        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
04336        ,numBinPix,minBinPix,maxBinPix);
04337     hPixelVsPlaneNum[i]->GetXaxis()->SetTitle("Plane");
04338     hPixelVsPlaneNum[i]->GetXaxis()->CenterTitle();
04339     hPixelVsPlaneNum[i]->GetYaxis()->SetTitle("Pixel");
04340     hPixelVsPlaneNum[i]->GetYaxis()->CenterTitle();
04341     hPixelVsPlaneNum[i]->SetFillColor(0);
04342     hPixelVsPlaneNum[i]->SetBit(TH1::kCanRebin);
04343   }
04344 
04345   TH2F **hPixelVsPlanePix=0;
04346   hPixelVsPlanePix= new TH2F*[NUMPULSERBOXES];
04347   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04348     sprintf(histname,"Pix (Pulser Box %i)",i);
04349     hPixelVsPlanePix[i]=new TH2F
04350       (histname,histname,
04351        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
04352        ,numBinPix,minBinPix,maxBinPix);
04353     hPixelVsPlanePix[i]->GetXaxis()->SetTitle("Plane");
04354     hPixelVsPlanePix[i]->GetXaxis()->CenterTitle();
04355     hPixelVsPlanePix[i]->GetYaxis()->SetTitle("Pixel");
04356     hPixelVsPlanePix[i]->GetYaxis()->CenterTitle();
04357     hPixelVsPlanePix[i]->SetFillColor(0);
04358     hPixelVsPlanePix[i]->SetBit(TH1::kCanRebin);
04359   }
04360 
04361   TH2F **hPixelVsPlanePixF=0;
04362   hPixelVsPlanePixF= new TH2F*[NUMPULSERBOXES];
04363   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04364     sprintf(histname,"PixF (Pulser Box %i)",i);
04365     hPixelVsPlanePixF[i]=new TH2F
04366       (histname,histname,
04367        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
04368        ,numBinPix,minBinPix,maxBinPix);
04369     hPixelVsPlanePixF[i]->GetXaxis()->SetTitle("Plane");
04370     hPixelVsPlanePixF[i]->GetXaxis()->CenterTitle();
04371     hPixelVsPlanePixF[i]->GetYaxis()->SetTitle("Pixel");
04372     hPixelVsPlanePixF[i]->GetYaxis()->CenterTitle();
04373     hPixelVsPlanePixF[i]->SetFillColor(0);
04374     hPixelVsPlanePixF[i]->SetBit(TH1::kCanRebin);
04375   }
04376 
04377   TH2F **hPixelVsPlaneEnt=0;
04378   hPixelVsPlaneEnt= new TH2F*[NUMPULSERBOXES];
04379   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04380     sprintf(histname,"Ent (Pulser Box %i, Near)",i);
04381     hPixelVsPlaneEnt[i]=new TH2F
04382       (histname,histname,
04383        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
04384        ,numBinPix,minBinPix,maxBinPix);
04385     hPixelVsPlaneEnt[i]->GetXaxis()->SetTitle("Plane");
04386     hPixelVsPlaneEnt[i]->GetXaxis()->CenterTitle();
04387     hPixelVsPlaneEnt[i]->GetYaxis()->SetTitle("Pixel");
04388     hPixelVsPlaneEnt[i]->GetYaxis()->CenterTitle();
04389     hPixelVsPlaneEnt[i]->SetFillColor(0);
04390     hPixelVsPlaneEnt[i]->SetBit(TH1::kCanRebin);
04391   }
04392 
04393   TH2F **hPixelVsPlaneEntF=0;
04394   hPixelVsPlaneEntF= new TH2F*[NUMPULSERBOXES];
04395   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04396     sprintf(histname,"EntF (Pulser Box %i, Far)",i);
04397     hPixelVsPlaneEntF[i]=new TH2F
04398       (histname,histname,
04399        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
04400        ,numBinPix,minBinPix,maxBinPix);
04401     hPixelVsPlaneEntF[i]->GetXaxis()->SetTitle("Plane");
04402     hPixelVsPlaneEntF[i]->GetXaxis()->CenterTitle();
04403     hPixelVsPlaneEntF[i]->GetYaxis()->SetTitle("Pixel");
04404     hPixelVsPlaneEntF[i]->GetYaxis()->CenterTitle();
04405     hPixelVsPlaneEntF[i]->SetFillColor(0);
04406     hPixelVsPlaneEntF[i]->SetBit(TH1::kCanRebin);
04407   }
04408   
04409   //histos for looking at noise in other pulserboxes
04411   TH2F **hPixelVsPlaneMeanNoise=0;
04412   hPixelVsPlaneMeanNoise= new TH2F*[NUMPULSERBOXES];
04413   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04414     sprintf(histname,"ADC (Noise, Pulser Box %i flashing)",i);
04415     hPixelVsPlaneMeanNoise[i]=new TH2F
04416       (histname,histname,
04417        LASTSCINTPLANE-FIRSTSCINTPLANE,FIRSTSCINTPLANE,LASTSCINTPLANE
04418        ,numBinPix,minBinPix,maxBinPix);
04419     hPixelVsPlaneMeanNoise[i]->GetXaxis()->SetTitle("Plane");
04420     hPixelVsPlaneMeanNoise[i]->GetXaxis()->CenterTitle();
04421     hPixelVsPlaneMeanNoise[i]->GetYaxis()->SetTitle("Pixel");
04422     hPixelVsPlaneMeanNoise[i]->GetYaxis()->CenterTitle();
04423     hPixelVsPlaneMeanNoise[i]->SetFillColor(0);
04424     hPixelVsPlaneMeanNoise[i]->SetBit(TH1::kCanRebin);
04425   }
04426 
04427   TH2F **hPixelVsPlaneEntNoise=0;
04428   hPixelVsPlaneEntNoise= new TH2F*[NUMPULSERBOXES];
04429   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04430     sprintf(histname,"Ent (Noise, Pulser Box %i, Near)",i);
04431     hPixelVsPlaneEntNoise[i]=new TH2F
04432       (histname,histname,
04433        LASTSCINTPLANE-FIRSTSCINTPLANE,FIRSTSCINTPLANE,LASTSCINTPLANE
04434        ,numBinPix,minBinPix,maxBinPix);
04435     hPixelVsPlaneEntNoise[i]->GetXaxis()->SetTitle("Plane");
04436     hPixelVsPlaneEntNoise[i]->GetXaxis()->CenterTitle();
04437     hPixelVsPlaneEntNoise[i]->GetYaxis()->SetTitle("Pixel");
04438     hPixelVsPlaneEntNoise[i]->GetYaxis()->CenterTitle();
04439     hPixelVsPlaneEntNoise[i]->SetFillColor(0);
04440     hPixelVsPlaneEntNoise[i]->SetBit(TH1::kCanRebin);
04441   }
04442 
04443   TH2F **hPixelVsPlaneMeanNoiseE=0;
04444   hPixelVsPlaneMeanNoiseE= new TH2F*[NUMPULSERBOXES];
04445   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04446     sprintf(histname,"ADC (Noise East Side, Pulser Box %i flashing)",i);
04447     hPixelVsPlaneMeanNoiseE[i]=new TH2F
04448       (histname,histname,
04449        LASTSCINTPLANE-FIRSTSCINTPLANE,FIRSTSCINTPLANE,LASTSCINTPLANE
04450        ,numBinPix,minBinPix,maxBinPix);
04451     hPixelVsPlaneMeanNoiseE[i]->GetXaxis()->SetTitle("Plane");
04452     hPixelVsPlaneMeanNoiseE[i]->GetXaxis()->CenterTitle();
04453     hPixelVsPlaneMeanNoiseE[i]->GetYaxis()->SetTitle("Pixel");
04454     hPixelVsPlaneMeanNoiseE[i]->GetYaxis()->CenterTitle();
04455     hPixelVsPlaneMeanNoiseE[i]->SetFillColor(0);
04456     hPixelVsPlaneMeanNoiseE[i]->SetBit(TH1::kCanRebin);
04457   }
04458 
04459   TH2F **hPixelVsPlaneEntNoiseE=0;
04460   hPixelVsPlaneEntNoiseE= new TH2F*[NUMPULSERBOXES];
04461   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04462     sprintf(histname,"Ent (Noise East Side, Pulser Box %i, Near)",i);
04463     hPixelVsPlaneEntNoiseE[i]=new TH2F
04464       (histname,histname,
04465        LASTSCINTPLANE-FIRSTSCINTPLANE,FIRSTSCINTPLANE,LASTSCINTPLANE
04466        ,numBinPix,minBinPix,maxBinPix);
04467     hPixelVsPlaneEntNoiseE[i]->GetXaxis()->SetTitle("Plane");
04468     hPixelVsPlaneEntNoiseE[i]->GetXaxis()->CenterTitle();
04469     hPixelVsPlaneEntNoiseE[i]->GetYaxis()->SetTitle("Pixel");
04470     hPixelVsPlaneEntNoiseE[i]->GetYaxis()->CenterTitle();
04471     hPixelVsPlaneEntNoiseE[i]->SetFillColor(0);
04472     hPixelVsPlaneEntNoiseE[i]->SetBit(TH1::kCanRebin);
04473   }
04474 
04475   TH2F **hPixelVsPlaneMeanNoiseW=0;
04476   hPixelVsPlaneMeanNoiseW= new TH2F*[NUMPULSERBOXES];
04477   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04478     sprintf(histname,"ADC (Noise West Side, Pulser Box %i flashing)",i);
04479     hPixelVsPlaneMeanNoiseW[i]=new TH2F
04480       (histname,histname,
04481        LASTSCINTPLANE-FIRSTSCINTPLANE,FIRSTSCINTPLANE,LASTSCINTPLANE
04482        ,numBinPix,minBinPix,maxBinPix);
04483     hPixelVsPlaneMeanNoiseW[i]->GetXaxis()->SetTitle("Plane");
04484     hPixelVsPlaneMeanNoiseW[i]->GetXaxis()->CenterTitle();
04485     hPixelVsPlaneMeanNoiseW[i]->GetYaxis()->SetTitle("Pixel");
04486     hPixelVsPlaneMeanNoiseW[i]->GetYaxis()->CenterTitle();
04487     hPixelVsPlaneMeanNoiseW[i]->SetFillColor(0);
04488     hPixelVsPlaneMeanNoiseW[i]->SetBit(TH1::kCanRebin);
04489   }
04490 
04491   TH2F **hPixelVsPlaneEntNoiseW=0;
04492   hPixelVsPlaneEntNoiseW= new TH2F*[NUMPULSERBOXES];
04493   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04494     sprintf(histname,"Ent (Noise West Side, Pulser Box %i, Near)",i);
04495     hPixelVsPlaneEntNoiseW[i]=new TH2F
04496       (histname,histname,
04497        LASTSCINTPLANE-FIRSTSCINTPLANE,FIRSTSCINTPLANE,LASTSCINTPLANE
04498        ,numBinPix,minBinPix,maxBinPix);
04499     hPixelVsPlaneEntNoiseW[i]->GetXaxis()->SetTitle("Plane");
04500     hPixelVsPlaneEntNoiseW[i]->GetXaxis()->CenterTitle();
04501     hPixelVsPlaneEntNoiseW[i]->GetYaxis()->SetTitle("Pixel");
04502     hPixelVsPlaneEntNoiseW[i]->GetYaxis()->CenterTitle();
04503     hPixelVsPlaneEntNoiseW[i]->SetFillColor(0);
04504     hPixelVsPlaneEntNoiseW[i]->SetBit(TH1::kCanRebin);
04505   }
04507   
04508   Float_t* noiseCharge=new Float_t[NUMPULSERBOXES];
04509   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04510     noiseCharge[i]=0;
04511   }
04512 
04516   
04517   this->InitialiseLoopVariables();  
04518   
04519   for(Int_t entry=0;entry<numEvents;entry++){
04520     
04521     this->SetLoopVariables(entry,0);
04522     
04523     //avoid divide by zero errors and skip irrelevant data
04524     if (rms==0. || mean==0. || numEntries==0) continue;
04525     //only look at scintillator strips
04526     if (readoutType!=ReadoutType::kScintStrip) continue;
04527 
04528     //plot pixels as 0-47
04529     Int_t pmt=lookup.Chip2Pmt(chip,detectorType);
04530     pixel=pmt*NUMPIXELS+pixel;
04531 
04532     //fill the noise histos
04533     if (pulserBox>=FIRSTPULSERBOX && pulserBox<=LASTPULSERBOX && 
04534         correlatedHit!=1 && ashtray<1 &&
04535         pulserBox!=nearPulserBox && pulserBox!=farPulserBox &&
04536         pixel<maxPixel && pixel>=FIRSTPIXEL && 
04537         plane>=FIRSTSCINTPLANE && plane<=LASTSCINTPLANE
04538         ){
04539       MSG("LIAnalysis",Msg::kVerbose) 
04540         <<"mean="<<mean<<", pl="<<plane<<", pix="<<pixel<<endl;
04541       //fill a histo for both east and west
04542       hPixelVsPlaneMeanNoise[pulserBox]->Fill(plane,pixel,mean);
04543       hPixelVsPlaneEntNoise[pulserBox]->Fill(plane,pixel,1);
04544       //sum up the total charge in the rest of the detector when
04545       //given pulser box is flashing
04546       noiseCharge[pulserBox]+=mean;
04547       //fill east side
04548       if (crate%2==0){//east side
04549         hPixelVsPlaneMeanNoiseE[pulserBox]->Fill(plane,pixel,mean);
04550         hPixelVsPlaneEntNoiseE[pulserBox]->Fill(plane,pixel,1);
04551       }
04552       //fill west side
04553       else{
04554         hPixelVsPlaneMeanNoiseW[pulserBox]->Fill(plane,pixel,mean);
04555         hPixelVsPlaneEntNoiseW[pulserBox]->Fill(plane,pixel,1);
04556       }
04557     }
04558 
04559     //fill the far x-talk histos
04560     if (pulserBox>=FIRSTPULSERBOX && pulserBox<=LASTPULSERBOX &&
04561         correlatedHit!=1 && pulserBox!=crate &&
04562         pulserBox==farPulserBox &&
04563         pixel<maxPixel && pixel>=FIRSTPIXEL && 
04564         plane>=FIRSTSCINTPLANE && plane<=LASTSCINTPLANE
04565         ){
04566       hPixelVsPlaneMeanF[pulserBox]->Fill(plane,pixel,mean);
04567       hPixelVsPlaneEntF[pulserBox]->Fill(plane,pixel,1);
04568       hPixelVsPlanePixF[pulserBox]->Fill(plane,pixel,pixel+1);
04569     }
04570 
04571     //fill the near x-talk histos
04572     if (pulserBox>=FIRSTPULSERBOX && pulserBox<=LASTPULSERBOX && 
04573         correlatedHit!=1 && pulserBox==crate  &&
04574         pixel<maxPixel && pixel>=FIRSTPIXEL && 
04575         plane>=FIRSTSCINTPLANE && plane<=LASTSCINTPLANE &&
04576         pulserBox==nearPulserBox
04577         ){
04578       hPixelVsPlaneLed[pulserBox]->Fill(plane,pixel,nearLed);
04579       hPixelVsPlaneMean[pulserBox]->Fill(plane,pixel,mean);
04580       hPixelVsPlaneNum[pulserBox]->Fill(plane,pixel,numEntries);
04581       hPixelVsPlanePix[pulserBox]->Fill(plane,pixel,pixel+1);
04582       hPixelVsPlaneEnt[pulserBox]->Fill(plane,pixel,1);
04583 
04584       MSG("LIAnalysis",Msg::kVerbose) 
04585         <<"mean="<<mean 
04586         <<", rms="<<rms 
04587         <<", npe="<<pow(mean/rms,2)
04588         <<", gain="<<mean/pow(mean/rms,2)
04589         <<endl;
04590     }
04591   }//end of for
04592    
04596   
04597   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
04598 
04599   string sRunNumber=Form("%d",runNumber);
04600 
04601   Float_t maxMean=0;
04602   Float_t maxMeanF=0;
04603   Float_t maxMeanNoise=0;
04604 
04605   //weight noise histograms according to number of entries
04606   for (Int_t pb=FIRSTPULSERBOX;pb<=LASTPULSERBOX;pb++){
04607     for (Int_t pl=FIRSTSCINTPLANE;pl<=LASTSCINTPLANE;pl++){
04608       for (Int_t pix=minBinPix;pix<=maxBinPix;pix++){
04609         //avoid divide by zero
04610         if (hPixelVsPlaneEntNoise[pb]->GetBinContent(pl,pix)>0){
04611           MSG("LIAnalysis",Msg::kVerbose) 
04612             <<"Weighting before"<<", pl="<<pl<<", pix="<<pix
04613             <<", mean="
04614             <<hPixelVsPlaneEntNoise[pb]->GetBinContent(pl,pix)
04615             <<", ent="
04616             <<hPixelVsPlaneEntNoise[pb]->GetBinContent(pl,pix)
04617             <<endl;
04618           //weight the noise histos
04619           hPixelVsPlaneMeanNoise[pb]->SetBinContent
04620             (pl,pix,hPixelVsPlaneMeanNoise[pb]->GetBinContent(pl,pix)/
04621              hPixelVsPlaneEntNoise[pb]->GetBinContent(pl,pix));
04622 
04623           MSG("LIAnalysis",Msg::kVerbose) 
04624             <<"Weighting after"<<", pl="<<pl<<", pix="<<pix
04625             <<", mean="
04626             <<hPixelVsPlaneEntNoise[pb]->GetBinContent(pl,pix)
04627             <<", ent="
04628             <<hPixelVsPlaneEntNoise[pb]->GetBinContent(pl,pix)
04629             <<endl;
04630           //calculate max
04631           if (hPixelVsPlaneMeanNoise[pb]->
04632               GetBinContent(pl,pix)>maxMeanNoise){
04633             maxMeanNoise=static_cast<Float_t>
04634               (hPixelVsPlaneMeanNoise[pb]->GetBinContent(pl,pix));
04635           }
04636         }
04637         //avoid divide by zero for the east histo
04638         if (hPixelVsPlaneEntNoiseE[pb]->GetBinContent(pl,pix)>0){
04639           //weight the noise east histos
04640           hPixelVsPlaneMeanNoiseE[pb]->SetBinContent
04641             (pl,pix,hPixelVsPlaneMeanNoiseE[pb]->GetBinContent(pl,pix)/
04642              hPixelVsPlaneEntNoiseE[pb]->GetBinContent(pl,pix));
04643         }
04644         //avoid divide by zero for the west histo
04645         if (hPixelVsPlaneEntNoiseW[pb]->GetBinContent(pl,pix)>0){
04646           //weight the noise east histos
04647           hPixelVsPlaneMeanNoiseW[pb]->SetBinContent
04648             (pl,pix,hPixelVsPlaneMeanNoiseW[pb]->GetBinContent(pl,pix)/
04649              hPixelVsPlaneEntNoiseW[pb]->GetBinContent(pl,pix));
04650         }
04651       }
04652     }
04653   }
04654   
04655   //weight x-talk histograms according to number of entries
04656   for (Int_t pb=FIRSTPULSERBOX;pb<=LASTPULSERBOX;pb++){
04657     for (Int_t pl=planeMin[pb];pl<=planeMax[pb];pl++){
04658       for (Int_t pix=minBinPix;pix<=maxBinPix;pix++){
04659         //avoid divide by zero
04660         if (hPixelVsPlaneEnt[pb]->GetBinContent(pl,pix)>0){
04661           //weight the near x-talk histos
04662           hPixelVsPlaneMean[pb]->SetBinContent
04663             (pl,pix,hPixelVsPlaneMean[pb]->GetBinContent(pl,pix)/
04664              hPixelVsPlaneEnt[pb]->GetBinContent(pl,pix));
04665           //calculate max
04666           if (hPixelVsPlaneMean[pb]->GetBinContent(pl,pix)>maxMean){
04667             maxMean=static_cast<Float_t>
04668               (hPixelVsPlaneMean[pb]->GetBinContent(pl,pix));
04669           }
04670         }
04671         //avoid divide by zero
04672         if (hPixelVsPlaneEntF[pb]->GetBinContent(pl,pix)>0){
04673           //weight the far x-talk histos
04674           hPixelVsPlaneMeanF[pb]->SetBinContent
04675             (pl,pix,hPixelVsPlaneMeanF[pb]->GetBinContent(pl,pix)/
04676              hPixelVsPlaneEntF[pb]->GetBinContent(pl,pix));
04677           //calculate max
04678           if (hPixelVsPlaneMeanF[pb]->GetBinContent(pl,pix)>maxMeanF){
04679             maxMeanF=static_cast<Float_t>
04680               (hPixelVsPlaneMeanF[pb]->GetBinContent(pl,pix));
04681           }
04682         }
04683       }
04684     }
04685   }
04686 
04687   MSG("LIAnalysis",Msg::kInfo)
04688     <<"Before setting ceiling, maxMean="<<maxMean
04689     <<", maxMeanF="<<maxMeanF
04690     <<", maxMeanNoise="<<maxMeanNoise
04691     <<endl;
04692   //set a ceiling
04693   if (maxMean>6000) maxMean=6000;
04694   if (maxMeanF>2000) maxMeanF=2000;
04695   if (maxMeanNoise>15000) maxMeanNoise=15000;
04696   //do this after it has been weighted
04697   for (Int_t pb=FIRSTPULSERBOX;pb<=LASTPULSERBOX;pb++){
04698     hPixelVsPlaneMean[pb]->SetMaximum(maxMean);
04699     hPixelVsPlaneMeanF[pb]->SetMaximum(maxMeanF);
04700     hPixelVsPlaneMeanNoise[pb]->SetMaximum(maxMeanNoise);
04701     //use maxMeanNoise for both sides
04702     hPixelVsPlaneMeanNoiseE[pb]->SetMaximum(maxMeanNoise);
04703     hPixelVsPlaneMeanNoiseW[pb]->SetMaximum(maxMeanNoise);
04704   }
04705   MSG("LIAnalysis",Msg::kInfo)
04706     <<"After setting ceiling, maxMean="<<maxMean
04707     <<", maxMeanF="<<maxMeanF
04708     <<", maxMeanNoise="<<maxMeanNoise
04709     <<endl;
04710 
04711   TCanvas *cPixelVsPlaneMean=new TCanvas
04712     ("cPixelVsPlaneMean","PixelVsPlane: Mean",0,0,1000,800);
04713   cPixelVsPlaneMean->SetFillColor(0);
04714   cPixelVsPlaneMean->cd();
04715   for (Int_t i=0;i<NUMPULSERBOXES;i++){ 
04716     cPixelVsPlaneMean->Clear();
04717     hPixelVsPlaneMean[i]->Draw("colz");
04718     if (i==0){
04719       s=sRunNumber+"AdcNearPixel.ps(";
04720       cPixelVsPlaneMean->Print(s.c_str());
04721     }
04722     else if(i==NUMPULSERBOXES-1){
04723       s=sRunNumber+"AdcNearPixel.ps)";
04724       cPixelVsPlaneMean->Print(s.c_str()); 
04725     }
04726     else{
04727       s=sRunNumber+"AdcNearPixel.ps";
04728       cPixelVsPlaneMean->Print(s.c_str());
04729     }
04730   }
04731   //draw it so it stays there
04732   cPixelVsPlaneMean->Clear();
04733   hPixelVsPlaneMean[nearPb]->Draw("colz");
04734   //delete cPixelVsPlaneMean;
04735   
04736   TCanvas *cPixelVsPlaneMeanF=new TCanvas
04737     ("cPixelVsPlaneMeanF","PixelVsPlane: MeanF",0,0,1000,800);
04738   cPixelVsPlaneMeanF->SetFillColor(0);
04739   cPixelVsPlaneMeanF->cd();
04740   for (Int_t i=0;i<NUMPULSERBOXES;i++){  
04741     cPixelVsPlaneMeanF->Clear();
04742     hPixelVsPlaneMeanF[i]->Draw("colz");
04743     if (i==0){
04744       s=sRunNumber+"AdcFarPixel.ps(";
04745       cPixelVsPlaneMeanF->Print(s.c_str());
04746     }
04747     else if(i==NUMPULSERBOXES-1){
04748       s=sRunNumber+"AdcFarPixel.ps)";
04749       cPixelVsPlaneMeanF->Print(s.c_str()); 
04750     }
04751     else{
04752       s=sRunNumber+"AdcFarPixel.ps";
04753       cPixelVsPlaneMeanF->Print(s.c_str());
04754     }
04755   }
04756   //draw it so it stays there
04757   cPixelVsPlaneMeanF->Clear();
04758   hPixelVsPlaneMeanF[farPb]->Draw("colz");
04759   //delete cPixelVsPlaneMeanF;
04760   
04761   //draw the noise histos 
04762   TCanvas *cPixelVsPlaneMeanNoise=new TCanvas
04763     ("cPixelVsPlaneMeanNoise","PixelVsPlane: Mean (Noise)",
04764      0,0,1000,800);
04765   cPixelVsPlaneMeanNoise->SetFillColor(0);
04766   cPixelVsPlaneMeanNoise->cd();
04767   for (Int_t i=0;i<NUMPULSERBOXES;i++){ 
04768     cPixelVsPlaneMeanNoise->Clear();   
04769     hPixelVsPlaneMeanNoise[i]->Draw("colz");
04770     if (i==0){
04771       s=sRunNumber+"AdcPixelNoise.ps(";
04772       cPixelVsPlaneMeanNoise->Print(s.c_str());
04773     }
04774     else if(i==NUMPULSERBOXES-1){
04775       s=sRunNumber+"AdcPixelNoise.ps)";
04776       cPixelVsPlaneMeanNoise->Print(s.c_str()); 
04777     }
04778     else{
04779       s=sRunNumber+"AdcPixelNoise.ps";
04780       cPixelVsPlaneMeanNoise->Print(s.c_str());
04781     }
04782   }
04783   //draw it so it stays there
04784   cPixelVsPlaneMeanNoise->Clear();
04785   hPixelVsPlaneMeanNoise[nearPb]->Draw("colz");
04786   //delete cPixelVsPlaneMeanNoise;
04787 
04788   //draw the east noise histos 
04789   TCanvas *cPixelVsPlaneMeanNoiseE=new TCanvas
04790     ("cPixelVsPlaneMeanNoiseE","PixelVsPlane: Mean (NoiseE)",
04791      0,0,1000,800);
04792   cPixelVsPlaneMeanNoiseE->SetFillColor(0);
04793   cPixelVsPlaneMeanNoiseE->cd();
04794   for (Int_t i=0;i<NUMPULSERBOXES;i++){ 
04795     cPixelVsPlaneMeanNoiseE->Clear();   
04796     hPixelVsPlaneMeanNoiseE[i]->Draw("colz");
04797     if (i==0){
04798       s=sRunNumber+"AdcPixelNoiseE.ps(";
04799       cPixelVsPlaneMeanNoiseE->Print(s.c_str());
04800     }
04801     else if(i==NUMPULSERBOXES-1){
04802       s=sRunNumber+"AdcPixelNoiseE.ps)";
04803       cPixelVsPlaneMeanNoiseE->Print(s.c_str()); 
04804     }
04805     else{
04806       s=sRunNumber+"AdcPixelNoiseE.ps";
04807       cPixelVsPlaneMeanNoiseE->Print(s.c_str());
04808     }
04809   }
04810   //draw it so it stays there
04811   cPixelVsPlaneMeanNoiseE->Clear();
04812   hPixelVsPlaneMeanNoiseE[nearPb]->Draw("colz");
04813   //delete cPixelVsPlaneMeanNoiseE;
04814   
04815   //draw the west noise histos 
04816   TCanvas *cPixelVsPlaneMeanNoiseW=new TCanvas
04817     ("cPixelVsPlaneMeanNoiseW","PixelVsPlane: Mean (NoiseW)",
04818      0,0,1000,800);
04819   cPixelVsPlaneMeanNoiseW->SetFillColor(0);
04820   cPixelVsPlaneMeanNoiseW->cd();
04821   for (Int_t i=0;i<NUMPULSERBOXES;i++){ 
04822     cPixelVsPlaneMeanNoiseW->Clear();   
04823     hPixelVsPlaneMeanNoiseW[i]->Draw("colz");
04824     if (i==0){
04825       s=sRunNumber+"AdcPixelNoiseW.ps(";
04826       cPixelVsPlaneMeanNoiseW->Print(s.c_str());
04827     }
04828     else if(i==NUMPULSERBOXES-1){
04829       s=sRunNumber+"AdcPixelNoiseW.ps)";
04830       cPixelVsPlaneMeanNoiseW->Print(s.c_str()); 
04831     }
04832     else{
04833       s=sRunNumber+"AdcPixelNoiseW.ps";
04834       cPixelVsPlaneMeanNoiseW->Print(s.c_str());
04835     }
04836   }
04837   //draw it so it stays there
04838   cPixelVsPlaneMeanNoiseW->Clear();
04839   hPixelVsPlaneMeanNoiseW[nearPb]->Draw("colz");
04840   //delete cPixelVsPlaneMeanNoiseW;
04841   
04842   TCanvas *cPixelVsPlaneEntEast=new TCanvas
04843     ("cPixelVsPlaneEntEast","PixelVsPlane: East Side (Near)"
04844      ,0,0,1200,800);
04845   cPixelVsPlaneEntEast->SetFillColor(0);
04846   cPixelVsPlaneEntEast->cd();
04847   hPixelVsPlaneLedB->SetTitle("East Side (Near)");
04848   hPixelVsPlaneLedB->Draw();
04849   for (Int_t i=0;i<NUMPULSERBOXES;i+=2){
04850     hPixelVsPlaneEnt[i]->Draw("samecolz");
04851   }
04852   s=sRunNumber+"EastNearPixel.eps";
04853   cPixelVsPlaneEntEast->Print(s.c_str()); 
04854   delete cPixelVsPlaneEntEast;
04855 
04856   TCanvas *cPixelVsPlaneEntWest=new TCanvas
04857     ("cPixelVsPlaneEntWest","PixelVsPlane: West Side (Near)"
04858      ,0,0,1200,800);
04859   cPixelVsPlaneEntWest->SetFillColor(0);
04860   cPixelVsPlaneEntWest->cd();
04861   hPixelVsPlaneLedB->SetTitle("West Side (Near)");
04862   hPixelVsPlaneLedB->Draw();
04863   for (Int_t i=1;i<NUMPULSERBOXES;i+=2){
04864     hPixelVsPlaneEnt[i]->Draw("samecolz");
04865   }
04866   s=sRunNumber+"WestNearPixel.eps";
04867   cPixelVsPlaneEntWest->Print(s.c_str()); 
04868   delete cPixelVsPlaneEntWest;
04869 
04870   TCanvas *cPixelVsPlaneEntWestF=new TCanvas
04871     ("cPixelVsPlaneEntWestF","PixelVsPlane: West Side (Far)"
04872      ,0,0,1200,800);
04873   cPixelVsPlaneEntWestF->SetFillColor(0);
04874   cPixelVsPlaneEntWestF->cd();
04875   hPixelVsPlaneLedB->SetTitle("West Side (Far)");
04876   hPixelVsPlaneLedB->Draw();
04877   for (Int_t i=0;i<NUMPULSERBOXES;i+=2){
04878     hPixelVsPlaneEntF[i]->Draw("samecolz");
04879   }
04880   s=sRunNumber+"WestFarPixel.eps";
04881   cPixelVsPlaneEntWestF->Print(s.c_str());
04882   delete cPixelVsPlaneEntWestF;
04883 
04884   TCanvas *cPixelVsPlaneEntEastF=new TCanvas
04885     ("cPixelVsPlaneEntEastF","PixelVsPlane: East Side (Far)"
04886      ,0,0,1200,800);
04887   cPixelVsPlaneEntEastF->SetFillColor(0);
04888   cPixelVsPlaneEntEastF->cd();
04889   hPixelVsPlaneLedB->SetTitle("East Side (Far)");
04890   hPixelVsPlaneLedB->Draw();
04891   for (Int_t i=1;i<NUMPULSERBOXES;i+=2){
04892     hPixelVsPlaneEntF[i]->Draw("samecolz");
04893   }
04894   s=sRunNumber+"EastFarPixel.eps";
04895   cPixelVsPlaneEntEastF->Print(s.c_str());
04896   delete cPixelVsPlaneEntEastF;
04897 
04898   //print out charge in other pulser boxes
04899   MSG("LIAnalysis",Msg::kInfo)
04900     <<endl
04901     <<" ** Summed charge in crates away from pulser box that "
04902     <<"was flashing **"<<endl;
04903   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04904     MSG("LIAnalysis",Msg::kInfo)
04905       <<"Pulser Box "<<i<<" has charge "<<noiseCharge[i]<<endl;
04906   }
04907   MSG("LIAnalysis",Msg::kInfo)
04908     <<" ** End of summed charge **"<<endl;
04909 
04910   MSG("LIAnalysis",Msg::kInfo)
04911     <<" ** Finished the PixelVsPlane method ** "<<endl;
04912 }
04913 
04914 //......................................................................
04915 
04916 void LIAnalysis::AshtrayVsPlane(Int_t nearPb,Int_t farPb)
04917 {
04918   //get rid of the stats info
04919   gStyle->SetOptStat(0);
04920 
04921   MSG("LIAnalysis",Msg::kInfo)
04922     <<endl<<" ** Running the AshtrayVsPlane method... **"<<endl;
04923   
04924   chain->GetEvent(0);
04925 
04926   Int_t* planeMax=new Int_t[NUMPULSERBOXES];
04927   Int_t* planeMin=new Int_t[NUMPULSERBOXES];
04928   lookup.SetPbPlanes(planeMin,planeMax,detectorType);
04929 
04930   TH2F *hAshtrayVsPlaneLedB=new TH2F(" "," ",
04931                                    LASTSCINTPLANE-FIRSTSCINTPLANE+2,
04932                                    FIRSTSCINTPLANE,LASTSCINTPLANE+1,
04933                                    22,0,22);
04934   TH2F **hAshtrayVsPlaneLed=0;
04935   hAshtrayVsPlaneLed= new TH2F*[NUMPULSERBOXES];
04936   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04937     sprintf(histname,"Led (Pulser Box %i)",i);
04938     hAshtrayVsPlaneLed[i]=new TH2F
04939       (histname,histname,
04940        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
04941        ,22,0,22);
04942     hAshtrayVsPlaneLed[i]->GetXaxis()->SetTitle("Plane");
04943     hAshtrayVsPlaneLed[i]->GetXaxis()->CenterTitle();
04944     hAshtrayVsPlaneLed[i]->GetYaxis()->SetTitle("Num Entries");
04945     hAshtrayVsPlaneLed[i]->GetYaxis()->CenterTitle();
04946     hAshtrayVsPlaneLed[i]->SetFillColor(0);
04947     hAshtrayVsPlaneLed[i]->SetBit(TH1::kCanRebin);
04948   }
04949 
04950   TH2F **hAshtrayVsPlaneMean=0;
04951   hAshtrayVsPlaneMean= new TH2F*[NUMPULSERBOXES];
04952   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04953     sprintf(histname,"ADC Value (Near Side, Pulser Box %i)",i);
04954     hAshtrayVsPlaneMean[i]=new TH2F
04955       (histname,histname,
04956        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
04957        ,22,0,22);
04958     hAshtrayVsPlaneMean[i]->GetXaxis()->SetTitle("Plane");
04959     hAshtrayVsPlaneMean[i]->GetXaxis()->CenterTitle();
04960     hAshtrayVsPlaneMean[i]->GetYaxis()->SetTitle("Ashtray");
04961     hAshtrayVsPlaneMean[i]->GetYaxis()->CenterTitle();
04962     hAshtrayVsPlaneMean[i]->SetFillColor(0);
04963     hAshtrayVsPlaneMean[i]->SetBit(TH1::kCanRebin);
04964   }
04965 
04966   TH2F **hAshtrayVsPlaneMeanF=0;
04967   hAshtrayVsPlaneMeanF= new TH2F*[NUMPULSERBOXES];
04968   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04969     sprintf(histname,"ADC Value (Far Side, Pulser Box %i)",i);
04970     hAshtrayVsPlaneMeanF[i]=new TH2F
04971       (histname,histname,
04972        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
04973        ,22,0,22);
04974     hAshtrayVsPlaneMeanF[i]->GetXaxis()->SetTitle("Plane");
04975     hAshtrayVsPlaneMeanF[i]->GetXaxis()->CenterTitle();
04976     hAshtrayVsPlaneMeanF[i]->GetYaxis()->SetTitle("Ashtray");
04977     hAshtrayVsPlaneMeanF[i]->GetYaxis()->CenterTitle();
04978     hAshtrayVsPlaneMeanF[i]->SetFillColor(0);
04979     hAshtrayVsPlaneMeanF[i]->SetBit(TH1::kCanRebin);
04980   }
04981 
04982   TH2F **hAshtrayVsPlaneNum=0;
04983   hAshtrayVsPlaneNum= new TH2F*[NUMPULSERBOXES];
04984   for (Int_t i=0;i<NUMPULSERBOXES;i++){
04985     sprintf(histname,"Num (Pulser Box %i)",i);
04986     hAshtrayVsPlaneNum[i]=new TH2F
04987       (histname,histname,
04988        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
04989        ,22,0,22);
04990     hAshtrayVsPlaneNum[i]->GetXaxis()->SetTitle("Plane");
04991     hAshtrayVsPlaneNum[i]->GetXaxis()->CenterTitle();
04992     hAshtrayVsPlaneNum[i]->GetYaxis()->SetTitle("Ashtray");
04993     hAshtrayVsPlaneNum[i]->GetYaxis()->CenterTitle();
04994     hAshtrayVsPlaneNum[i]->SetFillColor(0);
04995     hAshtrayVsPlaneNum[i]->SetBit(TH1::kCanRebin);
04996   }
04997 
04998   TH2F **hAshtrayVsPlanePix=0;
04999   hAshtrayVsPlanePix= new TH2F*[NUMPULSERBOXES];
05000   for (Int_t i=0;i<NUMPULSERBOXES;i++){
05001     sprintf(histname,"Pix (Pulser Box %i)",i);
05002     hAshtrayVsPlanePix[i]=new TH2F
05003       (histname,histname,
05004        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
05005        ,22,0,22);
05006     hAshtrayVsPlanePix[i]->GetXaxis()->SetTitle("Plane");
05007     hAshtrayVsPlanePix[i]->GetXaxis()->CenterTitle();
05008     hAshtrayVsPlanePix[i]->GetYaxis()->SetTitle("Ashtray");
05009     hAshtrayVsPlanePix[i]->GetYaxis()->CenterTitle();
05010     hAshtrayVsPlanePix[i]->SetFillColor(0);
05011     hAshtrayVsPlanePix[i]->SetBit(TH1::kCanRebin);
05012   }
05013 
05014   TH2F **hAshtrayVsPlanePixF=0;
05015   hAshtrayVsPlanePixF= new TH2F*[NUMPULSERBOXES];
05016   for (Int_t i=0;i<NUMPULSERBOXES;i++){
05017     sprintf(histname,"PixF (Pulser Box %i)",i);
05018     hAshtrayVsPlanePixF[i]=new TH2F
05019       (histname,histname,
05020        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
05021        ,22,0,22);
05022     hAshtrayVsPlanePixF[i]->GetXaxis()->SetTitle("Plane");
05023     hAshtrayVsPlanePixF[i]->GetXaxis()->CenterTitle();
05024     hAshtrayVsPlanePixF[i]->GetYaxis()->SetTitle("Ashtray");
05025     hAshtrayVsPlanePixF[i]->GetYaxis()->CenterTitle();
05026     hAshtrayVsPlanePixF[i]->SetFillColor(0);
05027     hAshtrayVsPlanePixF[i]->SetBit(TH1::kCanRebin);
05028   }
05029 
05030   TH2F **hAshtrayVsPlaneEnt=0;
05031   hAshtrayVsPlaneEnt= new TH2F*[NUMPULSERBOXES];
05032   for (Int_t i=0;i<NUMPULSERBOXES;i++){
05033     sprintf(histname,"Ent (Pulser Box %i, Near)",i);
05034     hAshtrayVsPlaneEnt[i]=new TH2F
05035       (histname,histname,
05036        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
05037        ,22,0,22);
05038     hAshtrayVsPlaneEnt[i]->GetXaxis()->SetTitle("Plane");
05039     hAshtrayVsPlaneEnt[i]->GetXaxis()->CenterTitle();
05040     hAshtrayVsPlaneEnt[i]->GetYaxis()->SetTitle("Ashtray");
05041     hAshtrayVsPlaneEnt[i]->GetYaxis()->CenterTitle();
05042     hAshtrayVsPlaneEnt[i]->SetFillColor(0);
05043     hAshtrayVsPlaneEnt[i]->SetBit(TH1::kCanRebin);
05044   }
05045 
05046   TH2F **hAshtrayVsPlaneEntF=0;
05047   hAshtrayVsPlaneEntF= new TH2F*[NUMPULSERBOXES];
05048   for (Int_t i=0;i<NUMPULSERBOXES;i++){
05049     sprintf(histname,"EntF (Pulser Box %i, Far)",i);
05050     hAshtrayVsPlaneEntF[i]=new TH2F
05051       (histname,histname,
05052        planeMax[i]-planeMin[i],planeMin[i],planeMax[i]
05053        ,22,0,22);
05054     hAshtrayVsPlaneEntF[i]->GetXaxis()->SetTitle("Plane");
05055     hAshtrayVsPlaneEntF[i]->GetXaxis()->CenterTitle();
05056     hAshtrayVsPlaneEntF[i]->GetYaxis()->SetTitle("Ashtray");
05057     hAshtrayVsPlaneEntF[i]->GetYaxis()->CenterTitle();
05058     hAshtrayVsPlaneEntF[i]->SetFillColor(0);
05059     hAshtrayVsPlaneEntF[i]->SetBit(TH1::kCanRebin);
05060   }
05061 
05065 
05066   this->InitialiseLoopVariables();  
05067   
05068   for(Int_t entry=0;entry<numEvents;entry++){
05069     
05070     this->SetLoopVariables(entry,0);
05071     
05072     //avoid divide by zero errors and skip irrelevant data
05073     if (rms==0. || mean==0. || numEntries==0) continue;
05074     //only look at scintillator strips
05075     if (readoutType!=ReadoutType::kScintStrip) continue;
05076 
05077     if (pulserBox>=FIRSTPULSERBOX && pulserBox<NUMPULSERBOXES &&
05078         correlatedHit!=1 && ashtray!=-1 && pulserBox!=crate &&
05079         ashtray<=NUMASHTRAYS && ashtray>=FIRSTASHTRAY && 
05080         plane>=FIRSTSCINTPLANE && plane<=LASTSCINTPLANE &&
05081         pulserBox==farPulserBox
05082         ){
05083       hAshtrayVsPlaneMeanF[pulserBox]->Fill(plane,ashtray,mean);
05084       hAshtrayVsPlaneEntF[pulserBox]->Fill(plane,ashtray,1);
05085       hAshtrayVsPlanePixF[pulserBox]->Fill(plane,ashtray,pixel+1);
05086     }
05087 
05088     if (pulserBox>=FIRSTPULSERBOX && pulserBox<NUMPULSERBOXES && 
05089         correlatedHit!=1  && ashtray!=-1 && pulserBox==crate  &&
05090         ashtray<=NUMASHTRAYS && ashtray>=FIRSTASHTRAY && 
05091         plane>=FIRSTSCINTPLANE && plane<=LASTSCINTPLANE &&
05092         pulserBox==nearPulserBox
05093         ){
05094       hAshtrayVsPlaneLed[pulserBox]->Fill(plane,ashtray,nearLed);
05095       hAshtrayVsPlaneMean[pulserBox]->Fill(plane,ashtray,mean);
05096       hAshtrayVsPlaneNum[pulserBox]->Fill(plane,ashtray,numEntries);
05097       hAshtrayVsPlanePix[pulserBox]->Fill(plane,ashtray,pixel+1);
05098       hAshtrayVsPlaneEnt[pulserBox]->Fill(plane,ashtray,1);
05099 
05100       MSG("LIAnalysis",Msg::kVerbose) 
05101         <<"mean="<<mean 
05102         <<", rms="<<rms 
05103         <<", npe="<<pow(mean/rms,2)
05104         <<", gain="<<mean/pow(mean/rms,2)
05105         <<endl;
05106     }
05107   }//end of for
05108    
05112   
05113   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
05114 
05115   string sRunNumber=Form("%d",runNumber);
05116 
05117   Int_t maxMean=0;
05118   Int_t maxMeanF=0;
05119   //weight histograms according to number of entries
05120   for (Int_t pb=FIRSTPULSERBOX;pb<=LASTPULSERBOX;pb++){
05121     for (Int_t pl=FIRSTSCINTPLANE;pl<=LASTSCINTPLANE;pl++){
05122       for (Int_t ash=0;ash<=NUMASHTRAYS+2;ash++){
05123 
05124         //take out known miscablings
05125         if ((ash==16 || ash==17) && pl==331) continue;
05126         if ((ash==7 || ash==8) && pl==129) continue;
05127         if ((ash==9 || ash==10) && pl==130) continue;
05128 
05129         if (hAshtrayVsPlaneEnt[pb]->GetBinContent(pl,ash)>0){
05130           hAshtrayVsPlaneMean[pb]->SetBinContent
05131             (pl,ash,hAshtrayVsPlaneMean[pb]->GetBinContent(pl,ash)/
05132              hAshtrayVsPlaneEnt[pb]->GetBinContent(pl,ash));
05133           if (hAshtrayVsPlaneMean[pb]->GetBinContent(pl,ash)>maxMean){
05134             maxMean=static_cast<Int_t>
05135               (hAshtrayVsPlaneMean[pb]->GetBinContent(pl,ash));
05136           }
05137         }
05138         if (hAshtrayVsPlaneEntF[pb]->GetBinContent(pl,ash)>0){
05139           hAshtrayVsPlaneMeanF[pb]->SetBinContent
05140             (pl,ash,hAshtrayVsPlaneMeanF[pb]->GetBinContent(pl,ash)/
05141              hAshtrayVsPlaneEntF[pb]->GetBinContent(pl,ash));
05142           if (hAshtrayVsPlaneMeanF[pb]->GetBinContent(pl,ash)>maxMean){
05143             maxMeanF=static_cast<Int_t>
05144               (hAshtrayVsPlaneMeanF[pb]->GetBinContent(pl,ash));
05145           }
05146         }
05147       }
05148     }
05149   }
05150 
05151   //do this after it has been weighted
05152   for (Int_t pb=FIRSTPULSERBOX;pb<=LASTPULSERBOX;pb++){
05153     //set a ceiling
05154     if (maxMean>4000) maxMean=4000;
05155     if (maxMeanF>3000) maxMeanF=3000;
05156     hAshtrayVsPlaneMean[pb]->SetMaximum(maxMean);
05157     hAshtrayVsPlaneMeanF[pb]->SetMaximum(maxMeanF);
05158   }
05159 
05160   //   TCanvas *cAshtrayVsPlaneLed=new TCanvas
05161   //     ("cAshtrayVsPlaneLed","AshtrayVsPlane: Led",0,0,1000,800);
05162   //   cAshtrayVsPlaneLed->SetFillColor(0);
05163   //   cAshtrayVsPlaneLed->cd();
05164   //   hAshtrayVsPlaneLedB->Draw();
05165   //   for (Int_t i=0;i<NUMPULSERBOXES;i+=2){
05166   //     hAshtrayVsPlaneLed[i]->Draw("sametextcolz");
05167   //   }
05168 
05169   TCanvas *cAshtrayVsPlaneMean=new TCanvas
05170     ("cAshtrayVsPlaneMean","AshtrayVsPlane: Mean",0,0,1000,800);
05171   cAshtrayVsPlaneMean->SetFillColor(0);
05172   cAshtrayVsPlaneMean->cd();
05173   for (Int_t i=0;i<NUMPULSERBOXES;i++){    
05174     hAshtrayVsPlaneMean[i]->Draw("colz");
05175     if (i==0){
05176       s=sRunNumber+"AdcNearAshtray.ps(";
05177       cAshtrayVsPlaneMean->Print(s.c_str());
05178     }
05179     else if(i==NUMPULSERBOXES-1){
05180       s=sRunNumber+"AdcNearAshtray.ps)";
05181       cAshtrayVsPlaneMean->Print(s.c_str()); 
05182     }
05183     else{
05184       s=sRunNumber+"AdcNearAshtray.ps";
05185       cAshtrayVsPlaneMean->Print(s.c_str());
05186     }
05187   }
05188   //draw it so it stays there
05189   cAshtrayVsPlaneMean->Clear();
05190   hAshtrayVsPlaneMean[nearPb]->Draw("colz");
05191   //delete cAshtrayVsPlaneMean;
05192   
05193   TCanvas *cAshtrayVsPlaneMeanF=new TCanvas
05194     ("cAshtrayVsPlaneMeanF","AshtrayVsPlane: MeanF",0,0,1000,800);
05195   cAshtrayVsPlaneMeanF->SetFillColor(0);
05196   cAshtrayVsPlaneMeanF->cd();
05197   for (Int_t i=0;i<NUMPULSERBOXES;i++){  
05198     cAshtrayVsPlaneMeanF->Clear();
05199     hAshtrayVsPlaneMeanF[i]->Draw("colz");
05200     if (i==0){
05201       s=sRunNumber+"AdcFarAshtray.ps(";
05202       cAshtrayVsPlaneMeanF->Print(s.c_str());
05203     }
05204     else if(i==NUMPULSERBOXES-1){
05205       s=sRunNumber+"AdcFarAshtray.ps)";
05206       cAshtrayVsPlaneMeanF->Print(s.c_str()); 
05207     }
05208     else{
05209       s=sRunNumber+"AdcFarAshtray.ps";
05210       cAshtrayVsPlaneMeanF->Print(s.c_str());
05211     }
05212   }
05213   //draw it so it stays there
05214   cAshtrayVsPlaneMeanF->Clear();
05215   hAshtrayVsPlaneMeanF[farPb]->Draw("colz");
05216   //delete cAshtrayVsPlaneMeanF;
05217 
05218   //   TCanvas *cAshtrayVsPlaneNum=new TCanvas
05219   //     ("cAshtrayVsPlaneNum","AshtrayVsPlane: Number Entries",0,0,1000,800);
05220   //   cAshtrayVsPlaneNum->SetFillColor(0);
05221   //   cAshtrayVsPlaneNum->cd();
05222   //   hAshtrayVsPlaneNum[pb]->Draw("textcolz");
05223 
05224   //   TCanvas *cAshtrayVsPlanePix=new TCanvas
05225   //     ("cAshtrayVsPlanePix","AshtrayVsPlane: Ashtray",0,0,1000,800);
05226   //   cAshtrayVsPlanePix->SetFillColor(0);
05227   //   cAshtrayVsPlanePix->cd();
05228   //   hAshtrayVsPlanePix[nearPb]->Draw("textcolz");
05229 
05230   //   TCanvas *cAshtrayVsPlanePixF=new TCanvas
05231   //     ("cAshtrayVsPlanePixF","AshtrayVsPlane: Ashtray",0,0,1000,800);
05232   //   cAshtrayVsPlanePixF->SetFillColor(0);
05233   //   cAshtrayVsPlanePixF->cd();
05234   //   hAshtrayVsPlanePixF[farPb]->Draw("textcolz");
05235 
05236   TCanvas *cAshtrayVsPlaneEntEast=new TCanvas
05237     ("cAshtrayVsPlaneEntEast","AshtrayVsPlane: East Side (Near)"
05238      ,0,0,1200,800);
05239   cAshtrayVsPlaneEntEast->SetFillColor(0);
05240   cAshtrayVsPlaneEntEast->cd();
05241   hAshtrayVsPlaneLedB->SetTitle("East Side (Near)");
05242   hAshtrayVsPlaneLedB->Draw();
05243   for (Int_t i=0;i<NUMPULSERBOXES;i+=2){
05244     hAshtrayVsPlaneEnt[i]->Draw("samecolz");
05245   }
05246   s=sRunNumber+"EastNearAshtray.eps";
05247   cAshtrayVsPlaneEntEast->Print(s.c_str()); 
05248 
05249   TCanvas *cAshtrayVsPlaneEntWest=new TCanvas
05250     ("cAshtrayVsPlaneEntWest","AshtrayVsPlane: West Side (Near)"
05251      ,0,0,1200,800);
05252   cAshtrayVsPlaneEntWest->SetFillColor(0);
05253   cAshtrayVsPlaneEntWest->cd();
05254   hAshtrayVsPlaneLedB->SetTitle("West Side (Near)");
05255   hAshtrayVsPlaneLedB->Draw();
05256   for (Int_t i=1;i<NUMPULSERBOXES;i+=2){
05257     hAshtrayVsPlaneEnt[i]->Draw("samecolz");
05258   }
05259   s=sRunNumber+"WestNearAshtray.eps";
05260   cAshtrayVsPlaneEntWest->Print(s.c_str()); 
05261 
05262   TCanvas *cAshtrayVsPlaneEntWestF=new TCanvas
05263     ("cAshtrayVsPlaneEntWestF","AshtrayVsPlane: West Side (Far)"
05264      ,0,0,1200,800);
05265   cAshtrayVsPlaneEntWestF->SetFillColor(0);
05266   cAshtrayVsPlaneEntWestF->cd();
05267   hAshtrayVsPlaneLedB->SetTitle("West Side (Far)");
05268   hAshtrayVsPlaneLedB->Draw();
05269   for (Int_t i=0;i<NUMPULSERBOXES;i+=2){
05270     hAshtrayVsPlaneEntF[i]->Draw("samecolz");
05271   }
05272   s=sRunNumber+"WestFarAshtray.eps";
05273   cAshtrayVsPlaneEntWestF->Print(s.c_str());
05274 
05275   TCanvas *cAshtrayVsPlaneEntEastF=new TCanvas
05276     ("cAshtrayVsPlaneEntEastF","AshtrayVsPlane: East Side (Far)"
05277      ,0,0,1200,800);
05278   cAshtrayVsPlaneEntEastF->SetFillColor(0);
05279   cAshtrayVsPlaneEntEastF->cd();
05280   hAshtrayVsPlaneLedB->SetTitle("East Side (Far)");
05281   hAshtrayVsPlaneLedB->Draw();
05282   for (Int_t i=1;i<NUMPULSERBOXES;i+=2){
05283     hAshtrayVsPlaneEntF[i]->Draw("samecolz");
05284   }
05285   s=sRunNumber+"EastFarAshtray.eps";
05286   cAshtrayVsPlaneEntEastF->Print(s.c_str());
05287 
05288   MSG("LIAnalysis",Msg::kInfo)
05289     <<" ** Finished the AshtrayVsPlane method ** "<<endl;
05290 }
05291 
05292 //......................................................................
05293 
05294 void LIAnalysis::MiswiringSearch(Int_t adcThreshold)
05295 {
05296   MSG("LIAnalysis",Msg::kInfo)
05297     <<endl<<" ** Running the MiswiringSearch method... ** "<<endl;
05298 
05299   Int_t lastPb=-1;
05300   Int_t lastL=-1;
05301 
05305   
05306   this->InitialiseLoopVariables();  
05307   
05308   for(Int_t entry=0;entry<numEvents;entry++){
05309     
05310     this->SetLoopVariables(entry,0);
05311     
05312     //avoid divide by zero errors and skip irrelevant data
05313     if (rms==0. || mean==0. || numEntries==0) continue;
05314     //only look at scintillator strips
05315     if (readoutType!=ReadoutType::kScintStrip) continue;
05316     
05317     if (mean>adcThreshold && correlatedHit==0){
05318       if (pulserBox==lastPb && led==lastL){
05319         MSG("LIAnalysis",Msg::kInfo) 
05320           <<"   Same PB and LED"
05321           <<", pix="<<pixel
05322           <<", chip="<<chip     
05323           <<", numEnt="<<numEntries
05324           <<", mean="<<mean<<endl;
05325       }
05326       else{
05327         MSG("LIAnalysis",Msg::kInfo) 
05328           <<"Potential mis-wiring:"
05329           <<" cr="<<crate
05330           <<", pl="<<plane
05331           <<", pb="<<pulserBox
05332           <<", led="<<led
05333           <<", ash="<<lookup.Led2Ashtray(led,plane,detectorType)
05334           <<", pix="<<pixel
05335           <<", chip="<<chip     
05336           <<", numEnt="<<numEntries
05337           <<", mean="<<mean 
05338           <<endl;
05339       }
05340       lastL=led;
05341       lastPb=pulserBox;
05342     }
05343   }//end of for
05344   
05348 
05349   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
05350 
05351   MSG("LIAnalysis",Msg::kInfo)
05352     <<" ** Finished the MiswiringSearch method ** "<<endl;
05353 
05354 }
05355 
05356 //......................................................................
05357 
05358 void LIAnalysis::HighGainSearch(Int_t maxAdcThreshold, 
05359                                 Float_t gainThreshold)
05360 {
05361   MSG("LIAnalysis",Msg::kInfo)
05362     <<endl<<" ** Running the HighGainSearch method... ** "<<endl;
05363 
05364   Int_t lastPb=-1;
05365   Int_t lastL=-1;
05366   Int_t lastPlane=-1;
05367   Int_t lastChip=-1;
05368 
05372   
05373   this->InitialiseLoopVariables();  
05374   
05375   for(Int_t entry=0;entry<numEvents;entry++){
05376     
05377     this->SetLoopVariables(entry,0);
05378     
05379     //avoid divide by zero errors and skip irrelevant data
05380     if (rms==0. || mean==0. || numEntries==0) continue;
05381     //only look at scintillator strips
05382     if (readoutType!=ReadoutType::kScintStrip) continue;
05383 
05384     Float_t gain=0.8*rms*rms/mean;
05385 
05386     // PMT fudge factor for M64 (near detector): 0.844
05387     if (detectorType==Detector::kNear) gain = 0.844*rms*rms/mean;
05388 
05389     if (lookup.NearOrFar(crate,pulserBox,nearPulserBox,farPulserBox,
05390                          led,detectorType,plane,runNumber)==
05391         LILookup::kNearSide &&
05392         detectorType==Detector::kCalDet){
05393       if (mean<maxAdcThreshold && gain>gainThreshold && 
05394           correlatedHit==1){
05395         if (plane==lastPlane && chip==lastChip){
05396           MSG("LIAnalysis",Msg::kInfo) 
05397             <<"  same pmt:"<<" chan="<<channel<<", mean="<<mean
05398             <<", gain="<<gain<<endl;
05399         }
05400         else{
05401           MSG("LIAnalysis",Msg::kInfo) 
05402             <<"High gain: pl="<<plane
05403             <<", "<<this->GetElecString()
05404             <<" mean="<<mean<<", gain="<<gain<<endl;
05405         }
05406         lastPlane=plane;
05407         lastChip=chip;
05408         lastL=led;
05409         lastPb=pulserBox;
05410       }
05411     }
05412     else if (detectorType==Detector::kFar){
05413       if (mean<maxAdcThreshold && gain>gainThreshold && 
05414           correlatedHit==1){
05415         if (plane==lastPlane && chip==lastChip){
05416           MSG("LIAnalysis",Msg::kInfo) 
05417             <<"  same pmt:"<<" chan="<<channel<<", mean="<<mean
05418             <<", gain="<<gain<<endl;
05419         }
05420         else{
05421           MSG("LIAnalysis",Msg::kInfo) 
05422             <<"High gain: pl="<<plane
05423             <<", "<<this->GetElecString()
05424             <<" mean="<<mean<<", gain="<<gain<<endl;
05425         }
05426         lastPlane=plane;
05427         lastChip=chip;
05428         lastL=led;
05429         lastPb=pulserBox;
05430       }
05431     }
05432 
05433   }//end of for
05434   
05438 
05439   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
05440 
05441   MSG("LIAnalysis",Msg::kInfo)
05442     <<" ** Finished the HighGainSearch method ** "<<endl;
05443 }
05444 
05445 //......................................................................
05446 
05447 void LIAnalysis::AdcVsPixel(Int_t pl,Int_t ashtrayMin,
05448                             Int_t ashtrayMax,Int_t l)
05449 {
05450   MSG("LIAnalysis",Msg::kInfo)
05451     <<endl<<" ** Running the AdcVsPixel method... ** "<<endl;
05452 
05453   //get first event
05454   chain->GetEvent(0);
05455 
05456   Int_t cr=lookup.Plane2CrateEast(pl,detectorType);
05457   Int_t crOpp=lookup.Plane2CrateWest(pl,detectorType);
05458   MSG("LIAnalysis",Msg::kInfo) 
05459     <<"Plane "<<pl<<", crates "<<cr<<" and "<<crOpp<<" selected"<<endl;
05460   if (ashtrayMax!=-1){
05461     MSG("LIAnalysis",Msg::kInfo) 
05462       <<"Only selecting correlated hits in ashtrays "<<ashtrayMin
05463       <<"-"<<ashtrayMax<<" inclusive"<<endl;
05464   }
05465   else{
05466     MSG("LIAnalysis",Msg::kInfo) 
05467       <<"Not using ashtray information"<<endl;
05468   }
05469 
05470   string sPlane=Form("%d",pl);
05471   string sAshtrayMin=Form("%d",ashtrayMin);
05472   string sAshtrayMax=Form("%d",ashtrayMax);
05473   string sConstantBit="";
05474   if (ashtrayMax!=-1) sConstantBit=", A "+sAshtrayMin+"-"+
05475                         sAshtrayMax+")";
05476   else sConstantBit=")";
05477 
05478   //variable to scale all histos to have the same colour
05479   Int_t maxColour=400;
05480 
05481   TH2F ***hAdcVsPixel=0;
05482   hAdcVsPixel=new TH2F**[NUMCRATES];
05483   for (Int_t i=0;i<NUMCRATES;i++){
05484     hAdcVsPixel[i]=new TH2F*[NUMCHIPS];
05485     for (Int_t j=0;j<NUMCHIPS;j++){
05486       string sChip=Form("%d",j);
05487       string sCrate=Form("%d",i);
05488       s="Adc Vs Pixel (Chip "+sChip+", Pl "+sPlane+", Cr "+sCrate+
05489         sConstantBit;
05490       (hAdcVsPixel[i])[j]=new TH2F(s.c_str(),s.c_str(),
05491                                    17,0,17,15000,0,15000);
05492       (hAdcVsPixel[i])[j]->GetXaxis()->SetTitle("Pixel");
05493       (hAdcVsPixel[i])[j]->GetXaxis()->CenterTitle();
05494       (hAdcVsPixel[i])[j]->GetYaxis()->SetTitle("Adc");
05495       (hAdcVsPixel[i])[j]->GetYaxis()->CenterTitle();
05496       (hAdcVsPixel[i])[j]->SetFillColor(0);
05497       (hAdcVsPixel[i])[j]->SetBit(TH1::kCanRebin);
05498       (hAdcVsPixel[i])[j]->SetMaximum(maxColour);
05499     }
05500   }
05501 
05505   
05506   this->InitialiseLoopVariables();  
05507   
05508   for(Int_t entry=0;entry<numEvents;entry++){
05509     
05510     this->SetLoopVariables(entry,0);
05511     
05512     //avoid divide by zero errors and skip irrelevant data
05513     if (rms==0 || mean==0 || numEntries==0) continue;
05514     //only look at scintillator strips
05515     if (readoutType!=ReadoutType::kScintStrip) continue;
05516 
05517     if (plane==pl && (crate==cr || crate==crOpp)){
05518       //Int_t ashtray=lookup.Led2Ashtray(led,plane);
05519 
05520       if (ashtray>=ashtrayMin && ashtray<=ashtrayMax){
05521         if (correlatedHit==1){
05522           //select the appropriate detectorType
05523           if (detectorType==Detector::kFar){
05524             if (pulserBox==nearPulserBox){
05525               (hAdcVsPixel[crate])[chip]->Fill(pixel,mean,maxColour);
05526             }
05527             else if (pulserBox==farPulserBox){
05528               (hAdcVsPixel[crate][chip])->Fill(pixel,mean,340);
05529             }
05530           }
05531           //CalDet
05532           else if (detectorType==Detector::kCalDet){
05533             if (led==l){
05534               if (lookup.NearOrFar(crate,pulserBox,nearPulserBox,
05535                                    farPulserBox,led,detectorType,
05536                                    plane,runNumber)==
05537                   LILookup::kNearSide){//near
05538                 (hAdcVsPixel[crate])[chip]->Fill(pixel,mean,400);
05539               }
05540               else if (lookup.NearOrFar(crate,pulserBox,nearPulserBox,
05541                                         farPulserBox,led,detectorType,
05542                                         plane,runNumber)==
05543                        LILookup::kFarSide){//far
05544                 (hAdcVsPixel[crate][chip])->Fill(pixel,mean,340);
05545               }
05546               else {
05547                 MSG("LIAnalysis",Msg::kInfo) 
05548                   <<"Missing stuff: cr="<<crate
05549                   <<", pb="<<pulserBox
05550                   <<", led="<<led<<", nL="<<nearLed<<", fL="<<farLed
05551                   <<", st="<<strip<<", chp="<<chip<<", pix="<<pixel
05552                   <<", ch="<<channel<<", m="<<mean <<endl;
05553               }
05554             }
05555           }
05556           //catch exceptions to detector type
05557           else {
05558             MSG("LIAnalysis",Msg::kWarning)
05559               <<"Detector Type = "<<detectorType<<" not supported yet"
05560               <<endl;
05561           }
05562 
05563           MSG("LIAnalysis",Msg::kInfo) 
05564             <<"correlated hit: cr="<<crate
05565             <<", pb="<<pulserBox<<", led="<<led
05566             <<", ash="<<ashtray<<", str="<<strip
05567             <<", chp="<<chip<<", pix="<<pixel<<", ch="<<channel
05568             <<", m="<<mean<<endl;
05569         }
05570         else{
05571           //crosstalk
05572           //select the appropriate detectorType
05573           if (detectorType==Detector::kFar){
05574             if (pulserBox==nearPulserBox){
05575               (hAdcVsPixel[crate])[chip]->Fill(pixel,mean,1);
05576             }
05577             else if (pulserBox==farPulserBox){
05578               (hAdcVsPixel[crate])[chip]->Fill(pixel,mean,130);
05579             }
05580           }
05581           //CalDet
05582           else if (detectorType==Detector::kCalDet){
05583             if (led==l){
05584               if (lookup.NearOrFar(crate,pulserBox,nearPulserBox,
05585                                    farPulserBox,led,detectorType,
05586                                    plane,runNumber)==
05587                   LILookup::kNearSide){//near
05588                 (hAdcVsPixel[crate])[chip]->Fill(pixel,mean,1);
05589               }
05590               else if (lookup.NearOrFar(crate,pulserBox,nearPulserBox,
05591                                         farPulserBox,led,detectorType,
05592                                         plane,runNumber)==
05593                        LILookup::kFarSide){//far
05594                 (hAdcVsPixel[crate])[chip]->Fill(pixel,mean,130);
05595               }
05596               else {
05597                 MSG("LIAnalysis",Msg::kInfo) 
05598                   <<"Missing stuff: cr="<<crate
05599                   <<", pb="<<pulserBox
05600                   <<", led="<<led
05601                   <<", nL="<<nearLed
05602                   <<", fL="<<farLed
05603                   <<", st="<<strip
05604                   <<", chp="<<chip      
05605                   <<", pix="<<pixel
05606                   <<", ch="<<channel<<", m="<<mean 
05607                   <<endl;
05608               }
05609             }
05610           }
05611           else {
05612             MSG("LIAnalysis",Msg::kWarning)
05613               <<"Detector Type = "<<detectorType<<" not supported yet"
05614               <<endl;
05615           }
05616           
05617           MSG("LIAnalysis",Msg::kInfo) 
05618             <<"xtalk: cr="<<crate
05619             <<", pb="<<pulserBox
05620             <<", led="<<led
05621             <<", ash="<<ashtray
05622             <<", str="<<strip
05623             <<", chp="<<chip    
05624             <<", pix="<<pixel
05625             <<", ch="<<channel<<", m="<<mean 
05626             <<endl;
05627         }
05628       }
05629     }
05630   }//end of for
05631    
05635 
05636   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
05637 
05638   //get rid of the stats info
05639   gStyle->SetOptStat(0);
05640 
05641   //HAS TO BE on the heap to stay on the canvas!!!!!!!!!!!!!
05642   TPaveText textLabel=TPaveText(0.6,0.1,0.8,0.6);
05643   textLabel.SetBorderSize(0);
05644   textLabel.SetTextSize(0.8);
05645   textLabel.SetTextColor(1);
05646   textLabel.SetTextFont(2);
05647   textLabel.SetFillColor(2);
05648 
05649   TText *label=new TText(0.15,0.9,"COLOUR KEY:");
05650   TText *label1=new TText
05651     (0.15,0.81,"  Dark red   = Expected hit: Light from near side");
05652   TText *label2=new TText
05653     (0.15,0.71,"  Orange     = Expected hit: Light from far side");
05654   TText *label3=new TText
05655     (0.15,0.55,"  Dark blue  = Xtalk: Light from near side");
05656   TText *label4=new TText
05657     (0.15,0.45,"  Light blue = Xtalk: Light from far side");
05658 
05659   TCanvas *cAdcVsPixel=new TCanvas("cAdcVsPixel","Adc Vs Pixel",
05660                                    0,0,1100,850);
05661   cAdcVsPixel->SetFillColor(0);
05662   cAdcVsPixel->Divide(3,3);
05663   for (Int_t i=0;i<NUMCHIPS;i++){
05664     cAdcVsPixel->cd(i+3+1);
05665     (hAdcVsPixel[cr])[i]->Draw("colz");
05666   }
05667 
05668   //  TCanvas *cAdcVsPixelOpp=new TCanvas
05669   //("cAdcVsPixelOpp","Adc Vs PixelOpp",0,0,1200,700);
05670   //cAdcVsPixelOpp->SetFillColor(0);
05671   //cAdcVsPixelOpp->Divide(2,2);
05672   for (Int_t i=0;i<NUMCHIPS;i++){
05673     cAdcVsPixel->cd(i+6+1);
05674     (hAdcVsPixel[crOpp])[i]->Draw("colz");
05675   }
05676   //cAdcVsPixelOpp->cd(4);
05677   //label->Draw();
05678   //label1->Draw();
05679   //label2->Draw();
05680   //label3->Draw();
05681   //label4->Draw();
05682   //scr=Form("%d",crOpp);
05683   //s="adcVsPixPla"+spl+"Cr"+scr+"A"+sAshMin+"-"+sAshMax+".eps";
05684   //cAdcVsPixelOpp->Print(s.c_str());
05685   //cAdcVsPixelOpp->Update();
05686 
05687   cAdcVsPixel->cd(2);
05688   label->Draw();
05689   label1->Draw();
05690   label2->Draw();
05691   label3->Draw();
05692   label4->Draw();
05693   string scr=Form("%d",cr);
05694   string sCrOpp=Form("%d",crOpp);
05695   string spl=Form("%d",pl);
05696   string sAshMin=Form("%d",ashtrayMin);
05697   string sAshMax=Form("%d",ashtrayMax);
05698   if (ashtrayMax!=-1) sConstantBit="A "+sAshtrayMin+"-"+sAshtrayMax;
05699   else sConstantBit="";
05700   s="adcVsPixPla"+spl+"Cr"+scr+"-"+sCrOpp+sConstantBit+".eps";
05701   cAdcVsPixel->Print(s.c_str());
05702 
05703   MSG("LIAnalysis",Msg::kInfo)
05704     <<" ** Finished the AdcVsPixel method ** "<<endl;
05705 }
05706 
05707 //......................................................................
05708 
05709 void LIAnalysis::AdcVsChannel(Int_t pl, Int_t cr)
05710 {  
05711   //get rid of the stats info
05712   gStyle->SetOptStat(0);
05713   
05714   MSG("LIAnalysis",Msg::kInfo)
05715     <<endl<<" ** Running the AdcVsChannel method... **"<<endl;
05716 
05717   TH2F **hAdcVsChannel=0;
05718   hAdcVsChannel= new TH2F*[NUMCHIPS];
05719   for (Int_t i=0;i<NUMCHIPS;i++){
05720     sprintf(histname,"Adc Vs Channel (VA chip %i)",i);
05721     hAdcVsChannel[i]=new TH2F
05722       (histname,histname,23,0,23,15000,0,15000);
05723     hAdcVsChannel[i]->GetXaxis()->SetTitle("Channel");
05724     hAdcVsChannel[i]->GetXaxis()->CenterTitle();
05725     hAdcVsChannel[i]->GetYaxis()->SetTitle("Adc");
05726     hAdcVsChannel[i]->GetYaxis()->CenterTitle();
05727     hAdcVsChannel[i]->SetFillColor(0);
05728     hAdcVsChannel[i]->SetBit(TH1::kCanRebin);
05729   }
05730   
05734   
05735   this->InitialiseLoopVariables();  
05736   
05737   for(Int_t entry=0;entry<numEvents;entry++){
05738     
05739     this->SetLoopVariables(entry,0);
05740     
05741     //avoid divide by zero errors and skip irrelevant data
05742     if (rms==0. || mean==0. || numEntries==0) continue;
05743     //only look at scintillator strips
05744     if (readoutType!=ReadoutType::kScintStrip) continue;
05745     
05746     if (plane==pl && crate==cr){
05747       if (correlatedHit==1){
05748         if (pulserBox==crate){
05749           hAdcVsChannel[chip]->Fill(channel,mean,20);
05750         }
05751         else if (pulserBox!=crate){
05752           hAdcVsChannel[chip]->Fill(channel,mean,10);
05753         }
05754       }
05755       else{
05756         hAdcVsChannel[chip]->Fill(channel,mean,1);
05757       }
05758       if (chip==0 && pulserBox==7){
05759         MSG("LIAnalysis",Msg::kVerbose) 
05760           <<"plane="<<plane
05761           <<", pb="<<pulserBox
05762           <<", chip="<<chip     
05763           <<", pixel="<<pixel
05764           <<", channel="<<channel
05765           <<", strip="<<strip
05766           <<", mean="<<mean 
05767           <<endl;
05768       }
05769       else if (chip==0 && pulserBox==6){
05770         MSG("LIAnalysis",Msg::kVerbose) 
05771           <<"****** plane="<<plane
05772           <<", pb="<<pulserBox
05773           <<", chip="<<chip     
05774           <<", pixel="<<pixel
05775           <<", channel="<<channel
05776           <<", strip="<<strip
05777           <<", mean="<<mean 
05778           <<endl;
05779       }
05780     }
05781 
05782 
05783   }//end of for
05784    
05788 
05789   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
05790 
05791   TCanvas *cAdcVsChannel=new TCanvas
05792     ("cAdcVsChannel","Adc Vs Channel",0,0,1200,800);
05793   cAdcVsChannel->SetFillColor(0);
05794   cAdcVsChannel->Divide(2,2);
05795   for (Int_t i=0;i<NUMCHIPS;i++){
05796     cAdcVsChannel->cd(i+1);
05797     hAdcVsChannel[i]->Draw("colz");
05798   }
05799 
05800   MSG("LIAnalysis",Msg::kInfo)
05801     <<" ** Finished the AdcVsChannel method ** "<<endl;
05802 }
05803 
05804 //......................................................................
05805 
05806 void LIAnalysis::IndividualChannels()
05807 {
05808 
05809   MSG("LIAnalysis",Msg::kInfo)
05810     <<endl<<" ** Running the IndividualChannels method... ** " 
05811     <<endl;
05812 
05813   const Int_t const_numLiRuns=numLiRuns;   
05814   const Int_t numDetChan=NUMCRATES*NUMVARCS*NUMVMMS*
05815     NUMVFBS*NUMVACHANNELS;
05816   MSG("LIAnalysis",Msg::kInfo)
05817     <<"Number of detector channels="<<numDetChan
05818     <<endl;
05819   
05820   Int_t *channelLed=new Int_t[numDetChan];
05821   //an array of arrays to hold gains for single channels
05822   Float_t **chanGain=0;
05823   Float_t **chanRms=0;
05824   Float_t **chanMean=0;
05825   Float_t **chanNpe=0;
05826   Float_t **chanNumEntries=0;
05827   Float_t **chanGainTime=0;
05828   Float_t **chanGainTemp=0;
05829 
05830   chanGain=new Float_t*[numDetChan];
05831   chanGainTime=new Float_t*[numDetChan];
05832   chanGainTemp=new Float_t*[numDetChan];
05833   chanRms=new Float_t*[numDetChan];
05834   chanMean=new Float_t*[numDetChan];
05835   chanNpe=new Float_t*[numDetChan];
05836   chanNumEntries=new Float_t*[numDetChan];
05837   for (int i=0; i<numDetChan; i++){
05838     chanGain[i]=new Float_t[const_numLiRuns];
05839     chanGainTime[i]=new Float_t[const_numLiRuns];
05840     chanGainTemp[i]=new Float_t[const_numLiRuns];
05841     chanRms[i]=new Float_t[const_numLiRuns];
05842     chanMean[i]=new Float_t[const_numLiRuns];
05843     chanNpe[i]=new Float_t[const_numLiRuns];
05844     chanNumEntries[i]=new Float_t[const_numLiRuns];
05845     for (int j=0; j<const_numLiRuns; j++){
05846       //initialise
05847       (chanGain[i])[j]=0.;
05848       (chanRms[i])[j]=0.;
05849       (chanMean[i])[j]=0.;
05850       (chanNpe[i])[j]=0.;
05851       (chanNumEntries[i])[j]=0.;
05852       (chanGainTime[i])[j]=0.;
05853       (chanGainTemp[i])[j]=0.;
05854     }
05855     channelLed[i]=-1;
05856   }
05857 
05861   
05862   this->InitialiseLoopVariables();  
05863   
05864   for(Int_t entry=0;entry<numEvents;entry++){
05865     
05866     this->SetLoopVariables(entry,0);
05867     
05868     //avoid divide by zero errors and skip irrelevant data
05869     if (rms==0. || mean==0. || numEntries==0){
05870       continue;
05871     }
05872 
05873     //only look at scintillator strips
05874     if (readoutType!=ReadoutType::kScintStrip){
05875       continue;
05876     }
05877 
05878     if (plane>=0 && plane<60 && strip<=24 && strip>=1){ 
05879       if (crate==0 && vmm==2 && varc==0){
05880         MSG("LIAnalysis",Msg::kVerbose)
05881           <<", chanNum="<<60*24*crate+24*plane+strip-1
05882           <<", mean="<<mean
05883           <<", "<<this->GetElecString()<<endl;
05884       }
05885     }
05886 
05887     //get gain for every channel
05888     if (pulseHeight==100){
05889       Int_t channelNum=crate*NUMVARCS*NUMVMMS*NUMVFBS*NUMVACHANNELS+
05890         varc*NUMVMMS*NUMVFBS*NUMVACHANNELS+
05891         vmm*NUMVFBS*NUMVACHANNELS+
05892         vfb*NUMVACHANNELS+
05893         channel;
05894       if (crate>=0 && crate<NUMCRATES &&
05895           varc>=0 && varc<NUMVARCS &&
05896           vmm>=0 && vmm<NUMVMMS &&
05897           vfb>=0 && vfb<NUMVFBS &&
05898           channel>=0 && channel<NUMVACHANNELS){ 
05899         //first check it is not already written to
05900         if ((chanGain[channelNum])[liRunNum]==0.){
05901           
05902           (chanGain[channelNum])[liRunNum]=mean/pow(mean/rms,2);
05903           
05904           (chanGainTime[channelNum])[liRunNum]=timestamp;
05905           
05906           (chanRms[channelNum])[liRunNum]=rms;
05907           
05908           (chanMean[channelNum])[liRunNum]=mean;
05909           
05910           (chanNpe[channelNum])[liRunNum]=pow(mean/rms,2);
05911           
05912           (chanNumEntries[channelNum])[liRunNum]=numEntries;
05913           
05914           if (correlatedHit && pulserBox==nearPulserBox){
05915             channelLed[channelNum]=1;
05916           }
05917           else if (correlatedHit && pulserBox==farPulserBox){
05918             channelLed[channelNum]=2;
05919           }
05920           else {
05921             channelLed[channelNum]=3;
05922           }
05923         }
05924         else {
05925           //MSG("LIAnalysis",Msg::kInfo)<<" ** WARNING ** "<<endl;
05926         }
05927       }
05928     }
05929   }//end of for
05930   
05934 
05935   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
05936 
05937   MSG("LIAnalysis",Msg::kInfo)
05938     <<"Summing all gains, Rmss, means, etc"<<endl;
05939   MSG("LIAnalysis",Msg::kInfo)<<"Initialising..."<<endl;
05940   //declare and initialise array
05941   Float_t* numEnt=new Float_t[numDetChan];
05942   Float_t* chanGainAverage=new Float_t[numDetChan];
05943   Float_t* detChan=new Float_t[numDetChan];
05944   Float_t* chanAvResidualGain=new Float_t[numDetChan];
05945   Float_t* chanRmsAverage=new Float_t[numDetChan];
05946   Float_t* chanMeanAverage=new Float_t[numDetChan];
05947   Float_t* chanNpeAverage=new Float_t[numDetChan];
05948   Float_t* chanNumEntriesAverage=new Float_t[numDetChan];
05949 
05950   for (Int_t i=0;i<numDetChan;i++){
05951     chanGainAverage[i]=0.;
05952     numEnt[i]=0.;
05953     detChan[i]=static_cast<Float_t>(i);
05954     chanAvResidualGain[i]=0.;
05955     chanRmsAverage[i]=0.;
05956     chanMeanAverage[i]=0.;
05957     chanNpeAverage[i]=0.;
05958     chanNumEntriesAverage[i]=0.;
05959   }
05960 
05961   MSG("LIAnalysis",Msg::kInfo)<<"Summing..."<<endl;
05962   //sum all gains, Rmss, means, Npes in channel
05963   for (Int_t ch=0;ch<numDetChan;ch++){
05964     for (Int_t i=0;i<numLiRuns;i++){
05965       //don't include the zeros
05966       if ((chanGain[ch])[i]!=0){
05967         chanGainAverage[ch]+=(chanGain[ch])[i];
05968         chanRmsAverage[ch]+=(chanRms[ch])[i];
05969         chanMeanAverage[ch]+=(chanMean[ch])[i];
05970         chanNpeAverage[ch]+=(chanNpe[ch])[i];
05971         chanNumEntriesAverage[ch]+=(chanNumEntries[ch])[i];
05972         numEnt[ch]++;
05973       }
05974     }//end of for
05975 
05976     //calculate average from sum
05977     if (numEnt[ch]!=0 && chanGainAverage[ch]!=0){
05978       chanGainAverage[ch]=chanGainAverage[ch]/numEnt[ch];
05979       chanRmsAverage[ch]=chanRmsAverage[ch]/numEnt[ch];
05980       chanMeanAverage[ch]=chanMeanAverage[ch]/numEnt[ch];
05981       chanNpeAverage[ch]=chanNpeAverage[ch]/numEnt[ch];
05982       chanNumEntriesAverage[ch]=chanNumEntriesAverage[ch]/numEnt[ch];
05983     }
05984     else {
05985       MSG("LIAnalysis",Msg::kVerbose) 
05986         <<"ch="<<ch  
05987         <<", numEnt[ch]="<<numEnt[ch]
05988         <<      ", chanGainAverage[ch]="<<chanGainAverage[ch]
05989         <<endl;
05990     }
05991   }
05992 
05993   MSG("LIAnalysis",Msg::kInfo)<<"Calculating residuals..."<<endl;
05994   //calculate average residuals (Rms)
05995   for (Int_t ch=0;ch<numDetChan;ch++){
05996     for (Int_t i=0;i<numLiRuns;i++){
05997       if ((chanGain[ch])[i]!=0){
05998         chanAvResidualGain[ch]+=pow(chanGainAverage[ch]-
05999                                     (chanGain[ch])[i],2);
06000       }
06001     }
06002     if (numEnt[ch]>1 && chanAvResidualGain[ch]!=0){
06003       chanAvResidualGain[ch]=sqrt(chanAvResidualGain[ch]/
06004                                   (numEnt[ch]-1));
06005     }
06006     else if (numEnt[ch]==1){
06007       chanAvResidualGain[ch]=sqrt(chanAvResidualGain[ch]);
06008       //MSG("LIAnalysis",Msg::kInfo)<<"ch="<<ch 
06009       //  <<", numEnt[ch]="<<numEnt[ch] 
06010       //  <<", chanAvResidualGain[ch]="<<chanAvResidualGain[ch]
06011       //  <<endl; 
06012     }
06013   }
06014 
06015   MSG("LIAnalysis",Msg::kInfo)<<"Plotting..."<<endl;
06016 
06017   /*  
06018       TCanvas *c106=new TCanvas("c106","c106",100,1,700,820);
06019       c106->SetFillColor(0);
06020       c106->Divide(1,3);
06021 
06022       TGraph *gGain6= new TGraph(numDetChan,detChan,chanGainAverage);
06023       gGain6->SetTitle("Average Gain Vs Channel");
06024       gGain6->SetMarkerStyle(3);
06025       gGain6->SetMarkerColor(2);
06026       gGain6->SetMarkerSize(0.2);
06027       c106->cd(1);
06028       gGain6->Draw("AP");
06029       gGain6->GetXaxis()->SetTitle("Channel");
06030       gGain6->GetYaxis()->SetTitle("Average Gain (mean/npe)");
06031       gGain6->GetXaxis()->CenterTitle();
06032       gGain6->GetYaxis()->CenterTitle();   
06033 
06034       TGraph *gGain6b= new TGraph(numDetChan,detChan,chanAvResidualGain);
06035       gGain6b->SetTitle("Average Gain Residual Vs Channel");
06036       gGain6b->SetMarkerStyle(3);
06037       gGain6b->SetMarkerColor(2);
06038       gGain6b->SetMarkerSize(0.2);
06039       c106->cd(2);
06040       gGain6b->Draw("AP");
06041       gGain6b->GetXaxis()->SetTitle("Channel");
06042       gGain6b->GetYaxis()->SetTitle("Average Residual Gain (mean/npe)");
06043       gGain6b->GetXaxis()->CenterTitle();
06044       gGain6b->GetYaxis()->CenterTitle();   
06045       c106->Modified();
06046 
06047       TGraph *gGain6c= new TGraph(numDetChan,detChan,chanNumEntriesAverage);
06048       gGain6c->SetTitle("Average Number of Entries Vs Channel");
06049       gGain6c->SetMarkerStyle(3);
06050       gGain6c->SetMarkerColor(2);
06051       gGain6c->SetMarkerSize(0.2);
06052       c106->cd(3);
06053       gGain6c->Draw("AP");
06054       gGain6c->GetXaxis()->SetTitle("Channel");
06055       gGain6c->GetYaxis()->SetTitle("Average Number of Entries");
06056       gGain6c->GetXaxis()->CenterTitle();
06057       gGain6c->GetYaxis()->CenterTitle();   
06058       c106->Modified();
06059   */
06060 
06061   TCanvas *c107=new TCanvas("c107","c107",100,1,700,820);
06062   c107->SetFillColor(0);
06063   c107->Divide(1,3);
06064 
06065   TGraph *gGain7= new TGraph(numDetChan,detChan,chanMeanAverage);
06066   gGain7->SetTitle("Average Mean Vs Channel");
06067   gGain7->SetMarkerStyle(3);
06068   gGain7->SetMarkerColor(1);
06069   gGain7->SetMarkerSize(0.2);
06070   c107->cd(1);
06071   gGain7->Draw("AP");
06072   gGain7->GetXaxis()->SetTitle("Channel");
06073   gGain7->GetYaxis()->SetTitle("Average Mean");
06074   gGain7->GetXaxis()->CenterTitle();
06075   gGain7->GetYaxis()->CenterTitle();   
06076 
06077   /*
06078     TGraph *gGain7b= new TGraph(numDetChan,detChan,chanRmsAverage);
06079     gGain7b->SetTitle("Average Rms Vs Channel");
06080     gGain7b->SetMarkerStyle(3);
06081     gGain7b->SetMarkerColor(2);
06082     gGain7b->SetMarkerSize(0.2);
06083     c107->cd(2);
06084     gGain7b->Draw("AP");
06085     gGain7b->GetXaxis()->SetTitle("Channel");
06086     gGain7b->GetYaxis()->SetTitle("Average Rms");
06087     gGain7b->GetXaxis()->CenterTitle();
06088     gGain7b->GetYaxis()->CenterTitle();   
06089 
06090     TGraph *gGain7c= new TGraph(numDetChan,detChan,chanNpeAverage);
06091     gGain7c->SetTitle("Average NPE Vs Channel");
06092     gGain7c->SetMarkerStyle(3);
06093     gGain7c->SetMarkerColor(2);
06094     gGain7c->SetMarkerSize(0.2);
06095     c107->cd(3);
06096     gGain7c->Draw("AP");
06097     gGain7c->GetXaxis()->SetTitle("Channel");
06098     gGain7c->GetYaxis()->SetTitle("Average NPE");
06099     gGain7c->GetXaxis()->CenterTitle();
06100     gGain7c->GetYaxis()->CenterTitle();   
06101   */
06102 
06103   c107->Modified();
06104 
06106   //create arrays for each LED separately
06107   
06108   const Int_t const_numLeds=numLeds;
06109 
06110   Float_t *counterL=new Float_t[numLeds];
06111 
06112   Float_t **chanGainAverageL=0;
06113   Float_t **chanAvResidualGainL=0;
06114   Float_t **chanMeanAverageL=0;
06115   Float_t **chanRmsAverageL=0;
06116   Float_t **chanNpeAverageL=0;
06117   Float_t **chanNumEntriesAverageL=0;
06118 
06119   //create arrays to hold the channel number assiciated with the above
06120   //separate LED arrays
06121   Float_t **chanGainAverageC=0;
06122   Float_t **chanAvResidualGainC=0;
06123   Float_t **chanMeanAverageC=0;
06124   Float_t **chanRmsAverageC=0;
06125   Float_t **chanNpeAverageC=0;
06126   Float_t **chanNumEntriesAverageC=0;
06127 
06128   chanGainAverageL=new Float_t*[const_numLeds];
06129   chanAvResidualGainL=new Float_t*[const_numLeds];
06130   chanMeanAverageL=new Float_t*[const_numLeds];
06131   chanRmsAverageL=new Float_t*[const_numLeds];
06132   chanNpeAverageL=new Float_t*[const_numLeds];
06133   chanNumEntriesAverageL=new Float_t*[const_numLeds];
06134 
06135   chanGainAverageC=new Float_t*[const_numLeds];
06136   chanAvResidualGainC=new Float_t*[const_numLeds];
06137   chanMeanAverageC=new Float_t*[const_numLeds];
06138   chanRmsAverageC=new Float_t*[const_numLeds];
06139   chanNpeAverageC=new Float_t*[const_numLeds];
06140   chanNumEntriesAverageC=new Float_t*[const_numLeds];
06141 
06142   for (Int_t i=0; i<const_numLeds; i++){
06143     chanGainAverageL[i]=new Float_t[numDetChan];
06144     chanAvResidualGainL[i]=new Float_t[numDetChan];
06145     chanMeanAverageL[i]=new Float_t[numDetChan];
06146     chanRmsAverageL[i]=new Float_t[numDetChan];
06147     chanNpeAverageL[i]=new Float_t[numDetChan];
06148     chanNumEntriesAverageL[i]=new Float_t[numDetChan];
06149 
06150     chanGainAverageC[i]=new Float_t[numDetChan];
06151     chanAvResidualGainC[i]=new Float_t[numDetChan];
06152     chanMeanAverageC[i]=new Float_t[numDetChan];
06153     chanRmsAverageC[i]=new Float_t[numDetChan];
06154     chanNpeAverageC[i]=new Float_t[numDetChan];
06155     chanNumEntriesAverageC[i]=new Float_t[numDetChan];
06156   }
06157 
06158   for (Int_t i=0; i<const_numLeds; i++){
06159     counterL[i]=0;
06160     for (Int_t j=0; j<numDetChan; j++){
06161       //initialise
06162       (chanGainAverageL[i])[j]=0.;
06163       (chanAvResidualGainL[i])[j]=0.;
06164       (chanMeanAverageL[i])[j]=0.;
06165       (chanRmsAverageL[i])[j]=0.;
06166       (chanNpeAverageL[i])[j]=0.;
06167       (chanNumEntriesAverageL[i])[j]=0.;
06168 
06169       (chanGainAverageC[i])[j]=0.;
06170       (chanAvResidualGainC[i])[j]=0.;
06171       (chanMeanAverageC[i])[j]=0.;
06172       (chanRmsAverageC[i])[j]=0.;
06173       (chanNpeAverageC[i])[j]=0.;
06174       (chanNumEntriesAverageC[i])[j]=0.;
06175     }
06176   }
06177 
06178   for (Int_t ch=0;ch<numDetChan; ch++){
06179     //check that the LED numbers are right to prevent segv
06180     //note channelLed is initialised to -1
06181     if (channelLed[ch]-1<numLeds && channelLed[ch]-1>=0){
06182 
06183       (chanGainAverageL[ channelLed[ch]-1 ])
06184         [static_cast<Int_t>(counterL[ channelLed[ch]-1 ])] = 
06185         chanGainAverage[ch];
06186 
06187       (chanAvResidualGainL[ channelLed[ch]-1 ])
06188         [static_cast<Int_t>(counterL[ channelLed[ch]-1 ])] = 
06189         chanAvResidualGain[ch];
06190 
06191       (chanMeanAverageL[ channelLed[ch]-1 ])
06192         [static_cast<Int_t>(counterL[ channelLed[ch]-1 ])] = 
06193         chanMeanAverage[ch];
06194 
06195       (chanRmsAverageL[ channelLed[ch]-1 ])
06196         [static_cast<Int_t>(counterL[ channelLed[ch]-1 ])] = 
06197         chanRmsAverage[ch];
06198 
06199       (chanNpeAverageL[ channelLed[ch]-1 ])
06200         [static_cast<Int_t>(counterL[ channelLed[ch]-1 ])] = 
06201         chanNpeAverage[ch];
06202 
06203       (chanNumEntriesAverageL[ channelLed[ch]-1 ])
06204         [static_cast<Int_t>(counterL[ channelLed[ch]-1 ])] = 
06205         chanNumEntriesAverage[ch];
06206 
06207 
06208       (chanGainAverageC[ channelLed[ch]-1 ])
06209         [static_cast<Int_t>(counterL[ channelLed[ch]-1 ])] = 
06210         static_cast<Float_t>(ch);
06211 
06212       (chanAvResidualGainC[ channelLed[ch]-1 ])
06213         [static_cast<Int_t>(counterL[ channelLed[ch]-1 ])] = 
06214         static_cast<Float_t>(ch);
06215 
06216       (chanMeanAverageC[ channelLed[ch]-1 ])
06217         [static_cast<Int_t>(counterL[ channelLed[ch]-1 ])] = 
06218         static_cast<Float_t>(ch);
06219 
06220       (chanRmsAverageC[ channelLed[ch]-1 ])
06221         [static_cast<Int_t>(counterL[ channelLed[ch]-1 ])] = 
06222         static_cast<Float_t>(ch);
06223 
06224       (chanNpeAverageC[ channelLed[ch]-1 ])
06225         [static_cast<Int_t>(counterL[ channelLed[ch]-1 ])] = 
06226         static_cast<Float_t>(ch);
06227 
06228       (chanNumEntriesAverageC[ channelLed[ch]-1 ])
06229         [static_cast<Int_t>(counterL[ channelLed[ch]-1 ])] = 
06230         static_cast<Float_t>(ch);
06231 
06232       //count the number of each led
06233       counterL[(channelLed[ch]-1)]++;
06234       //MSG("LIAnalysis",Msg::kInfo)<<"counterL[(channelLed[ch]-1)]=" 
06235       //    <<counterL[(channelLed[ch]-1)]
06236       //    <<", channelLed[ch]-1="<<channelLed[ch]-1
06237       //   <<endl;
06238     }
06239   }
06240 
06241   TLegend *legend2 = new TLegend(0.85, 0.7, 0.9, 0.9);
06242   legend2->SetBorderSize(0);
06243   legend2->SetFillColor(0);
06244   legend2->SetTextSize(0.035);
06245 
06246   TGraph **gGainL=0;
06247   gGainL= new TGraph*[numLeds];
06248   TGraph **gResidualL=0;
06249   gResidualL= new TGraph*[numLeds];
06250   TGraph **gMeanL=0;
06251   gMeanL= new TGraph*[numLeds];
06252   TGraph **gRmsL=0;
06253   gRmsL= new TGraph*[numLeds];
06254   TGraph **gNpeL=0;
06255   gNpeL= new TGraph*[numLeds];
06256   TGraph **gNumEntriesL=0;
06257   gNumEntriesL= new TGraph*[numLeds];
06258     
06259   for (Int_t i=0;i<3;i++){
06260     gGainL[i]=new TGraph(static_cast<Int_t>(counterL[i]),
06261                          chanGainAverageC[i],
06262                          chanGainAverageL[i]);
06263     gGainL[i]->SetMarkerStyle(3);
06264     gGainL[i]->SetMarkerColor(i+2);
06265     gGainL[i]->SetMarkerSize(0.2);
06266 
06267     gResidualL[i]=new TGraph(static_cast<Int_t>(counterL[i]),
06268                              chanAvResidualGainC[i],
06269                              chanAvResidualGainL[i]);
06270     gResidualL[i]->SetMarkerStyle(3);
06271     gResidualL[i]->SetMarkerColor(i+2);
06272     gResidualL[i]->SetMarkerSize(0.2);
06273 
06274     gMeanL[i]=new TGraph(static_cast<Int_t>(counterL[i]),
06275                          chanMeanAverageC[i],
06276                          chanMeanAverageL[i]);
06277     gMeanL[i]->SetMarkerStyle(3);
06278     gMeanL[i]->SetMarkerColor(i+2);
06279     gMeanL[i]->SetMarkerSize(0.2);
06280 
06281     gRmsL[i]=new TGraph(static_cast<Int_t>(counterL[i]),
06282                         chanRmsAverageC[i],
06283                         chanRmsAverageL[i]);
06284     gRmsL[i]->SetMarkerStyle(3);
06285     gRmsL[i]->SetMarkerColor(i+2);
06286     gRmsL[i]->SetMarkerSize(0.2);
06287 
06288     gNpeL[i]=new TGraph(static_cast<Int_t>(counterL[i]),
06289                         chanNpeAverageC[i],
06290                         chanNpeAverageL[i]);
06291     gNpeL[i]->SetMarkerStyle(3);
06292     gNpeL[i]->SetMarkerColor(i+2);
06293     gNpeL[i]->SetMarkerSize(0.2);
06294 
06295     gNumEntriesL[i]=new TGraph(static_cast<Int_t>(counterL[i]),
06296                                chanNumEntriesAverageC[i],
06297                                chanNumEntriesAverageL[i]);
06298     gNumEntriesL[i]->SetMarkerStyle(3);
06299     gNumEntriesL[i]->SetMarkerColor(i+2);
06300     gNumEntriesL[i]->SetMarkerSize(0.2);
06301 
06302 
06303     //c106->cd(1);
06304     //gGainL[i]->Draw("P");
06305     //c106->cd(2);
06306     //gResidualL[i]->Draw("P");
06307     //c106->cd(3);
06308     //gNumEntriesL[i]->Draw("P");
06309     
06310 
06311     c107->cd(1);
06312     gMeanL[i]->Draw("P");
06313 
06314     
06315     //c107->cd(2);
06316     //gRmsL[i]->Draw("P");
06317     //c107->cd(3);
06318     //gNpeL[i]->Draw("P");
06319     
06320     sprintf(histname," LED %i",i+1);
06321     legend2->AddEntry(gResidualL[i],histname,"p");
06322   }
06323 
06324   
06325   //draw the legends
06326   //c106->cd(1);
06327   //legend2->Draw();
06328   //c106->cd(2);
06329   //legend2->Draw();
06330   //c106->cd(3);
06331   //legend2->Draw();
06332   //c106->Modified(); 
06333   //draw the legends on other canvas
06334   
06335   
06336   c107->cd(1);
06337   legend2->Draw();
06338   
06339   //c107->cd(2);
06340   //legend2->Draw();
06341   //c107->cd(3);
06342   //legend2->Draw();
06343   //c107->Modified();
06344   
06345   MSG("LIAnalysis",Msg::kInfo) 
06346     <<" ** Finished the IndividualChannels method ** "<<endl;
06347 }
06348 
06349 //......................................................................
06350 
06351 void LIAnalysis::AdcDistribution()
06352 {
06353   MSG("LIAnalysis",Msg::kInfo) 
06354     <<endl<<" ** Running the AdcDistribution method... ** "<<endl;
06355 
06356   //include the under and overflow counts 
06357   gStyle->SetOptStat(1111111); 
06358 
06359   TH1F *hMean= new TH1F("hMean","Mean",150,-5,15005);
06360   hMean->GetXaxis()->SetTitle("Mean");
06361   hMean->GetXaxis()->CenterTitle();
06362   hMean->GetYaxis()->SetTitle("Number");
06363   hMean->GetYaxis()->CenterTitle();
06364   hMean->SetFillColor(0);
06365   hMean->SetBit(TH1::kCanRebin);
06366 
06367   TH1F *hMeanCorrelated= new TH1F("hMeanCorrelated","MeanCorrelated",
06368                                   150,-5,15005);
06369   hMeanCorrelated->GetXaxis()->SetTitle("Mean");
06370   hMeanCorrelated->GetXaxis()->CenterTitle();
06371   hMeanCorrelated->GetYaxis()->SetTitle("Number");
06372   hMeanCorrelated->GetYaxis()->CenterTitle();
06373   hMeanCorrelated->SetFillColor(0);
06374   hMeanCorrelated->SetLineColor(4);
06375   hMeanCorrelated->SetBit(TH1::kCanRebin);
06376 
06377   TH1F *hMeanEast= new TH1F("hMeanEast","MeanEast",
06378                                   150,-5,15005);
06379   hMeanEast->GetXaxis()->SetTitle("Mean");
06380   hMeanEast->GetXaxis()->CenterTitle();
06381   hMeanEast->GetYaxis()->SetTitle("Number");
06382   hMeanEast->GetYaxis()->CenterTitle();
06383   hMeanEast->SetLineColor(4);
06384   hMeanEast->SetFillStyle(3015); 
06385   hMeanEast->SetFillColor(4); 
06386   hMeanEast->SetLineWidth(6);
06387   hMeanEast->SetBit(TH1::kCanRebin);
06388 
06389   TH1F *hMeanWest= new TH1F("hMeanWest","MeanWest",
06390                                   150,-5,15005);
06391   hMeanWest->GetXaxis()->SetTitle("Mean");
06392   hMeanWest->GetXaxis()->CenterTitle();
06393   hMeanWest->GetYaxis()->SetTitle("Number");
06394   hMeanWest->GetYaxis()->CenterTitle();
06395   hMeanWest->SetLineColor(2);
06396   hMeanWest->SetFillStyle(3015); 
06397   hMeanWest->SetFillColor(2); 
06398   hMeanWest->SetLineWidth(6);
06399   hMeanWest->SetBit(TH1::kCanRebin);
06400 
06401   TH1F *hMeanNearPb= new TH1F("hMeanNearPb","MeanNearPb",
06402                               150,-5,15005);
06403   hMeanNearPb->GetXaxis()->SetTitle("Mean");
06404   hMeanNearPb->GetXaxis()->CenterTitle();
06405   hMeanNearPb->GetYaxis()->SetTitle("Number");
06406   hMeanNearPb->GetYaxis()->CenterTitle();
06407   hMeanNearPb->SetFillColor(0);
06408   hMeanNearPb->SetLineColor(2);
06409   hMeanNearPb->SetBit(TH1::kCanRebin);
06410 
06411   TH1F *hMeanFarPb= new TH1F("hMeanFarPb","MeanFarPb",
06412                              150,-5,15005);
06413   hMeanFarPb->GetXaxis()->SetTitle("Mean");
06414   hMeanFarPb->GetXaxis()->CenterTitle();
06415   hMeanFarPb->GetYaxis()->SetTitle("Number");
06416   hMeanFarPb->GetYaxis()->CenterTitle();
06417   hMeanFarPb->SetFillColor(0);
06418   hMeanFarPb->SetLineColor(3);
06419   hMeanFarPb->SetBit(TH1::kCanRebin);
06420 
06421   //histos for different calib points / pulse heights
06422   const Int_t const_numCalibPoints=10;
06423   Int_t pulseHeights[const_numCalibPoints];
06424   TH1F **hAdcPh=0;
06425   hAdcPh= new TH1F*[const_numCalibPoints];
06426   for (Int_t i=0;i<const_numCalibPoints;i++){
06427     //initialise heights
06428     pulseHeights[i]=-1;
06429     //initialse histos
06430     sprintf(histname,"Adc Distribution, calibpoint %d",i+1);
06431     hAdcPh[i]=new TH1F(histname,histname,200,0,15000);
06432     hAdcPh[i]->GetXaxis()->SetTitle("ADC");
06433     hAdcPh[i]->GetXaxis()->CenterTitle();
06434     hAdcPh[i]->GetYaxis()->SetTitle("Number of Entries");
06435     hAdcPh[i]->GetYaxis()->CenterTitle();
06436     hAdcPh[i]->SetFillColor(0);
06437     hAdcPh[i]->Fill(1);
06438     //hAdcPh[i]->SetBit(TH1::kCanRebin);
06439   }
06440 
06441   TH1F **hAdcPhNearPb=0;
06442   hAdcPhNearPb= new TH1F*[const_numCalibPoints];
06443   for (Int_t i=0;i<const_numCalibPoints;i++){
06444     sprintf(histname,"AdcPhNearPb Distribution, calibpoint %d",i+1);
06445     hAdcPhNearPb[i]=new TH1F(histname,histname,200,0,15000);
06446     
06447     hAdcPhNearPb[i]->GetXaxis()->SetTitle("ADC");
06448     hAdcPhNearPb[i]->GetXaxis()->CenterTitle();
06449     hAdcPhNearPb[i]->GetYaxis()->SetTitle("Number of Entries");
06450     hAdcPhNearPb[i]->GetYaxis()->CenterTitle();
06451     hAdcPhNearPb[i]->SetFillColor(0);
06452     hAdcPhNearPb[i]->SetLineColor(2);
06453     hAdcPhNearPb[i]->Fill(1);
06454     //hAdcPhNearPb[i]->SetBit(TH1::kCanRebin);
06455   }
06456 
06457   TH1F **hAdcPhFarPb=0;
06458   hAdcPhFarPb= new TH1F*[const_numCalibPoints];
06459   for (Int_t i=0;i<const_numCalibPoints;i++){
06460     sprintf(histname,"AdcPh FarPb Distribution, calibpoint %d",i+1);
06461     hAdcPhFarPb[i]=new TH1F(histname,histname,200,0,15000);
06462     
06463     hAdcPhFarPb[i]->GetXaxis()->SetTitle("ADC");
06464     hAdcPhFarPb[i]->GetXaxis()->CenterTitle();
06465     hAdcPhFarPb[i]->GetYaxis()->SetTitle("Number of Entries");
06466     hAdcPhFarPb[i]->GetYaxis()->CenterTitle();
06467     hAdcPhFarPb[i]->SetFillColor(0);
06468     hAdcPhFarPb[i]->SetLineColor(3);
06469     hAdcPhFarPb[i]->Fill(1);
06470     //hAdcPhFarPb[i]->SetBit(TH1::kCanRebin);
06471   }
06472 
06473   //histos for different pulser boxes
06474   TH1F **hAdcPb=0;
06475   hAdcPb= new TH1F*[NUMPULSERBOXES];
06476   for (Int_t i=0;i<NUMPULSERBOXES;i++){
06477     //initialse histos
06478     sprintf(histname,"Adc Distribution, pulser box %d",i);
06479     hAdcPb[i]=new TH1F(histname,histname,200,0,15000);
06480     hAdcPb[i]->GetXaxis()->SetTitle("ADC");
06481     hAdcPb[i]->GetXaxis()->CenterTitle();
06482     hAdcPb[i]->GetYaxis()->SetTitle("Number of Entries");
06483     hAdcPb[i]->GetYaxis()->CenterTitle();
06484     hAdcPb[i]->SetFillColor(0);
06485     hAdcPb[i]->Fill(1);
06486     //hAdcPb[i]->SetBit(TH1::kCanRebin);
06487   }
06488 
06489   TH1F **hAdcPbNearPb=0;
06490   hAdcPbNearPb= new TH1F*[NUMPULSERBOXES];
06491   for (Int_t i=0;i<NUMPULSERBOXES;i++){
06492     sprintf(histname,"AdcPbNearPb Distribution, pulser box %d",i);
06493     hAdcPbNearPb[i]=new TH1F(histname,histname,200,0,15000);
06494     
06495     hAdcPbNearPb[i]->GetXaxis()->SetTitle("ADC");
06496     hAdcPbNearPb[i]->GetXaxis()->CenterTitle();
06497     hAdcPbNearPb[i]->GetYaxis()->SetTitle("Number of Entries");
06498     hAdcPbNearPb[i]->GetYaxis()->CenterTitle();
06499     hAdcPbNearPb[i]->SetFillColor(0);
06500     hAdcPbNearPb[i]->SetLineColor(2);
06501     hAdcPbNearPb[i]->Fill(1);
06502     //hAdcPbNearPb[i]->SetBit(TH1::kCanRebin);
06503   }
06504 
06505   TH1F **hAdcPbFarPb=0;
06506   hAdcPbFarPb= new TH1F*[NUMPULSERBOXES];
06507   for (Int_t i=0;i<NUMPULSERBOXES;i++){
06508     sprintf(histname,"AdcPbFarPb Distribution, pulser box %d",i);
06509     hAdcPbFarPb[i]=new TH1F(histname,histname,200,0,15000);
06510     
06511     hAdcPbFarPb[i]->GetXaxis()->SetTitle("ADC");
06512     hAdcPbFarPb[i]->GetXaxis()->CenterTitle();
06513     hAdcPbFarPb[i]->GetYaxis()->SetTitle("Number of Entries");
06514     hAdcPbFarPb[i]->GetYaxis()->CenterTitle();
06515     hAdcPbFarPb[i]->SetFillColor(0);
06516     hAdcPbFarPb[i]->SetLineColor(3);
06517     hAdcPbFarPb[i]->Fill(1);
06518     //hAdcPbFarPb[i]->SetBit(TH1::kCanRebin);
06519   }
06520 
06521   //histos for different pulse widths
06522   const Int_t const_numPulseWidths=3; 
06523   TH1F **hAdcPw=0;
06524   hAdcPw= new TH1F*[const_numPulseWidths];
06525   for (Int_t i=0;i<const_numPulseWidths;i++){
06526     //initialse histos
06527     sprintf(histname,"Adc Distribution, pulse width %d",i);
06528     hAdcPw[i]=new TH1F(histname,histname,200,0,15000);
06529     hAdcPw[i]->GetXaxis()->SetTitle("ADC");
06530     hAdcPw[i]->GetXaxis()->CenterTitle();
06531     hAdcPw[i]->GetYaxis()->SetTitle("Number of Entries");
06532     hAdcPw[i]->GetYaxis()->CenterTitle();
06533     hAdcPw[i]->SetFillColor(0);
06534     hAdcPw[i]->Fill(1);
06535     //hAdcPw[i]->SetBit(TH1::kCanRebin);
06536   }
06537 
06538   TH1F **hAdcPwNearPb=0;
06539   hAdcPwNearPb= new TH1F*[const_numPulseWidths];
06540   for (Int_t i=0;i<const_numPulseWidths;i++){
06541     sprintf(histname,"AdcPwNearPb Distribution, pulser box %d",i);
06542     hAdcPwNearPb[i]=new TH1F(histname,histname,200,0,15000);
06543     
06544     hAdcPwNearPb[i]->GetXaxis()->SetTitle("ADC");
06545     hAdcPwNearPb[i]->GetXaxis()->CenterTitle();
06546     hAdcPwNearPb[i]->GetYaxis()->SetTitle("Number of Entries");
06547     hAdcPwNearPb[i]->GetYaxis()->CenterTitle();
06548     hAdcPwNearPb[i]->SetFillColor(0);
06549     hAdcPwNearPb[i]->SetLineColor(2);
06550     hAdcPwNearPb[i]->Fill(1);
06551     //hAdcPwNearPb[i]->SetBit(TH1::kCanRebin);
06552   }
06553 
06554   TH1F **hAdcPwFarPb=0;
06555   hAdcPwFarPb= new TH1F*[const_numPulseWidths];
06556   for (Int_t i=0;i<const_numPulseWidths;i++){
06557     sprintf(histname,"AdcPwFarPb Distribution, pulser box %d",i);
06558     hAdcPwFarPb[i]=new TH1F(histname,histname,200,0,15000);
06559     
06560     hAdcPwFarPb[i]->GetXaxis()->SetTitle("ADC");
06561     hAdcPwFarPb[i]->GetXaxis()->CenterTitle();
06562     hAdcPwFarPb[i]->GetYaxis()->SetTitle("Number of Entries");
06563     hAdcPwFarPb[i]->GetYaxis()->CenterTitle();
06564     hAdcPwFarPb[i]->SetFillColor(0);
06565     hAdcPwFarPb[i]->SetLineColor(3);
06566     hAdcPwFarPb[i]->Fill(1);
06567     //hAdcPwFarPb[i]->SetBit(TH1::kCanRebin);
06568   }
06569 
06573 
06574   this->InitialiseLoopVariables();  
06575   
06576   for(Int_t entry=0;entry<numEvents;entry++){
06577     
06578     this->SetLoopVariables(entry,0);
06579     
06580     //avoid divide by zero errors and skip irrelevant data
06581     if (rms==0. || mean==0. || numEntries==0) continue;
06582     //only look at scintillator strips
06583     if (readoutType!=ReadoutType::kScintStrip) continue;
06584 
06585     hMean->Fill(mean);
06586 
06587     if (correlatedHit==1){
06588 
06589       if (detectorType==Detector::kCalDet){
06590         if (plane>0 && plane<=LASTPLANE && 
06591             lookup.NearOrFar(crate,pulserBox,nearPulserBox,
06592                              farPulserBox,led,detectorType,
06593                              plane,runNumber)==
06594             LILookup::kNearSide){
06595           if (eastWest==1) hMeanEast->Fill(mean);
06596           else if (eastWest==2) hMeanWest->Fill(mean);
06597         }
06598       }
06599 
06600       //fill histogram for appropriate pulse height
06601       if (calibPoint>0 && calibPoint<=const_numCalibPoints){
06602         pulseHeights[calibPoint-1]=pulseHeight;
06603         hAdcPh[calibPoint-1]->Fill(mean);
06604       }
06605 
06606       //fill histo for appropriate pulser box      
06607       if (pulserBox>=FIRSTPULSERBOX && pulserBox<=LASTPULSERBOX){
06608         hAdcPb[pulserBox]->Fill(mean);
06609       }
06610 
06611       //fill histo for appropriate pulse width      
06612       if (pulseWidth>=1 && pulseWidth<=const_numPulseWidths){
06613         hAdcPw[pulseWidth-1]->Fill(mean);
06614       }
06615 
06616       //fill general histo
06617       hMeanCorrelated->Fill(mean);
06618 
06619       //fill histos with when pulser box is near pulser box
06620       if (nearPulserBox==pulserBox) {
06621         //fill histogram for appropriate pulse height
06622         if (calibPoint>0 && calibPoint<=const_numCalibPoints){
06623           hAdcPhNearPb[calibPoint-1]->Fill(mean);
06624         }
06625         
06626         //fill histo for appropriate pulser box     
06627         if (pulserBox>=FIRSTPULSERBOX && pulserBox<=LASTPULSERBOX){
06628           hAdcPbNearPb[pulserBox]->Fill(mean);
06629         }
06630 
06631         //fill histo for appropriate pulse width      
06632         if (pulseWidth>=1 && pulseWidth<=const_numPulseWidths){
06633           hAdcPwNearPb[pulseWidth-1]->Fill(mean);
06634         }
06635         //fill general histo
06636         hMeanNearPb->Fill(mean);
06637       }      
06638       //fill histos with when pulser box is far pulser box
06639       else if (farPulserBox==pulserBox) {
06640         //fill histogram for appropriate pulse height
06641         if (calibPoint>0 && calibPoint<=const_numCalibPoints){
06642           hAdcPhFarPb[calibPoint-1]->Fill(mean);
06643         }
06644 
06645         //fill histo for appropriate pulser box     
06646         if (pulserBox>=FIRSTPULSERBOX && pulserBox<=LASTPULSERBOX){
06647           hAdcPbFarPb[pulserBox]->Fill(mean);
06648         }
06649 
06650         //fill histo for appropriate pulse width      
06651         if (pulseWidth>=1 && pulseWidth<=const_numPulseWidths){
06652           hAdcPwFarPb[pulseWidth-1]->Fill(mean);
06653         }
06654         //fill general histo
06655         hMeanFarPb->Fill(mean);
06656       }
06657       else {
06658         MSG("LIAnalysis",Msg::kWarning) 
06659           <<" ** Wrong Pb **"<<endl;
06660       }
06661     }    
06662   }//end of for
06663 
06667 
06668   MSG("LIAnalysis",Msg::kInfo)<<"Finished main loop"<<endl;
06669 
06670   string sRunNumber=Form("%d",runNumber);
06671 
06672   TCanvas *cMean=new TCanvas("cMean","cMean",0,0,1000,600);
06673   cMean->SetFillColor(0);
06674   cMean->cd();
06675   cMean->SetLogy();
06676   hMean->Draw();
06677   hMeanNearPb->Draw("same");
06678   hMeanFarPb->Draw("same");
06679   //hMeanCorrelated->Draw("same");
06680 
06681   TCanvas *cMeanEW=new TCanvas("cMeanEW","cMeanEW",0,0,1000,600);
06682   cMeanEW->SetFillColor(0);
06683   cMeanEW->cd();
06684   hMeanWest->Draw();
06685   hMeanEast->Draw("sames");
06686 
06688   //sorted by calibration point section
06690   //get the maximum in order to scale all plots
06691   Int_t maxNumEnt=0;
06692   for (Int_t i=0;i<const_numCalibPoints;i++){
06693     if (hAdcPh[i]->GetMaximum()>maxNumEnt){
06694       maxNumEnt=static_cast<Int_t>(hAdcPh[i]->GetMaximum());
06695       MSG("LIAnalysis",Msg::kInfo) 
06696         <<"Calculating max in calib point section, current highest="
06697         <<maxNumEnt<<endl;
06698     }
06699   }
06700   //create the canvas and draw
06701   TCanvas *cAdcPh=new TCanvas("cAdcPh","cAdcPh",0,0,1000,600);
06702   cAdcPh->SetFillColor(0);
06703   cAdcPh->cd();
06704   cAdcPh->SetLogy();
06705   MSG("LIAnalysis",Msg::kInfo)
06706     <<endl<<"Number of calibration points = "<<const_numCalibPoints
06707     <<endl;  
06708   for (Int_t i=0;i<const_numCalibPoints;i++){
06709     cAdcPh->Clear();
06710     hAdcPh[i]->SetMaximum(maxNumEnt);
06711     string sPulseWidth=Form("%d",pulseWidth);
06712     string sPulseHeight=Form("%d",pulseHeights[i]);
06713     string sPulseFreq=Form("%d",static_cast<Int_t>
06714                            (ceil(1.0/(period*1.0e-5))));
06715     MSG("LIAnalysis",Msg::kInfo)
06716       <<"LI parameters: "
06717       <<", PH="<<sPulseHeight
06718       <<", PW="<<sPulseWidth
06719       <<", PF="<<sPulseFreq
06720       <<", period="<<period
06721       <<endl;
06722     s="ADC Values, Near&Far side, PH="+
06723       sPulseHeight+", PW="+sPulseWidth+
06724       ", PF="+sPulseFreq+" Hz";
06725     hAdcPh[i]->SetTitle(s.c_str());
06726     hAdcPh[i]->Draw();
06727     hAdcPhNearPb[i]->Draw("same");
06728     hAdcPhFarPb[i]->Draw("same");
06729     if (i==0){
06730       s=sRunNumber+"AdcPhHisto.ps(";
06731       cAdcPh->Print(s.c_str());
06732     }
06733     else if(i==const_numCalibPoints-1){
06734       s=sRunNumber+"AdcPhHisto.ps)";
06735       cAdcPh->Print(s.c_str()); 
06736     }
06737     else{
06738       s=sRunNumber+"AdcPhHisto.ps";
06739       cAdcPh->Print(s.c_str());
06740     }
06741   }
06742   cAdcPh->Clear();
06743   hAdcPh[0]->Draw();
06744   hAdcPhNearPb[0]->Draw("same");
06745   hAdcPhFarPb[0]->Draw("same");
06746 
06748   //sorted by pulser box section
06750   //get the maximum in order to scale all plots
06751   maxNumEnt=0;
06752   for (Int_t i=0;i<NUMPULSERBOXES;i++){
06753     if (hAdcPb[i]->GetMaximum()>maxNumEnt){
06754       maxNumEnt=static_cast<Int_t>(hAdcPb[i]->GetMaximum());
06755       MSG("LIAnalysis",Msg::kInfo) 
06756         <<"Calculating max in pulser box section, current highest="
06757         <<maxNumEnt<<endl;
06758     }
06759   }
06760   //create the canvas and draw
06761   TCanvas *cAdcPb=new TCanvas("cAdcPb","cAdcPb",0,0,1000,600);
06762   cAdcPb->SetFillColor(0);
06763   cAdcPb->cd();
06764   cAdcPb->SetLogy();
06765   MSG("LIAnalysis",Msg::kInfo)
06766     <<endl<<"Number of pulser boxes = "<<NUMPULSERBOXES<<endl;
06767   for (Int_t i=0;i<NUMPULSERBOXES;i++){
06768     cAdcPb->Clear();
06769     hAdcPb[i]->SetMaximum(maxNumEnt);
06770     string sPulserBox=Form("%d",i);
06771     string sPulseWidth=Form("%d",pulseWidth);
06772     string sPulseHeight=Form("%d",pulseHeight);
06773     string sPulseFreq=Form("%d",static_cast<Int_t>
06774                            (ceil(1.0/(period*1.0e-5))));
06775     MSG("LIAnalysis",Msg::kInfo)
06776       <<"LI parameters: "
06777       <<", PB="<<sPulserBox
06778       <<", PH="<<sPulseHeight
06779       <<", PW="<<sPulseWidth
06780       <<", PF="<<sPulseFreq
06781       <<", period="<<period
06782       <<endl;
06783     s="ADC Values, Near&Far side, PB="+sPulserBox+
06784       ", PH="+sPulseHeight+", PW="+sPulseWidth+
06785       ", PF="+sPulseFreq+" Hz";
06786     hAdcPb[i]->SetTitle(s.c_str());
06787     hAdcPb[i]->Draw();
06788     hAdcPbNearPb[i]->Draw("same");
06789     hAdcPbFarPb[i]->Draw("same");
06790     if (i==0){
06791       s=sRunNumber+"AdcPbHisto.ps(";
06792       cAdcPb->Print(s.c_str());
06793     }
06794     else if(i==NUMPULSERBOXES-1){
06795       s=sRunNumber+"AdcPbHisto.ps)";
06796       cAdcPb->Print(s.c_str()); 
06797     }
06798     else{
06799       s=sRunNumber+"AdcPbHisto.ps";
06800       cAdcPb->Print(s.c_str());
06801     }
06802   }
06803   cAdcPb->Clear();
06804   hAdcPb[0]->Draw();
06805   hAdcPbNearPb[0]->Draw("same");
06806   hAdcPbFarPb[0]->Draw("same");
06807 
06809   //sorted by pulse width
06811   //get the maximum in order to scale all plots
06812   maxNumEnt=0;
06813   for (Int_t i=0;i<const_numPulseWidths;i++){
06814     if (hAdcPw[i]->GetMaximum()>maxNumEnt){
06815       maxNumEnt=static_cast<Int_t>(hAdcPw[i]->GetMaximum());
06816       MSG("LIAnalysis",Msg::kInfo) 
06817         <<"Calculating max in pulse width section, current highest="
06818         <<maxNumEnt<<endl;
06819     }
06820   }
06821   //create the canvas and draw
06822   TCanvas *cAdcPw=new TCanvas("cAdcPw","cAdcPw",0,0,1000,600);
06823   cAdcPw->SetFillColor(0);
06824   cAdcPw->cd();
06825   cAdcPw->SetLogy();
06826   MSG("LIAnalysis",Msg::kInfo)
06827     <<endl<<"Number of pulse widths = "<<const_numPulseWidths<<endl;
06828   for (Int_t i=0;i<const_numPulseWidths;i++){
06829     cAdcPw->Clear();
06830     hAdcPw[i]->SetMaximum(maxNumEnt);
06831     string sPulseWidth=Form("%d",i+1);
06832     string sPulseHeight=Form("%d",pulseHeight);
06833     string sPulseFreq=Form("%d",static_cast<Int_t>
06834                            (ceil(1.0/(period*1.0e-5))));
06835     MSG("LIAnalysis",Msg::kInfo)
06836       <<"LI parameters: "
06837       <<", PH="<<sPulseHeight
06838       <<", PW="<<sPulseWidth
06839       <<", PF="<<sPulseFreq
06840       <<", period="<<period
06841       <<endl;
06842     s="ADC Values, Near&Far side, PH="+sPulseHeight+
06843       ", PW="+sPulseWidth+
06844       ", PF="+sPulseFreq+" Hz";
06845     hAdcPw[i]->SetTitle(s.c_str());
06846     hAdcPw[i]->Draw();
06847     hAdcPwNearPb[i]->Draw("same");
06848     hAdcPwFarPb[i]->Draw("same");
06849     if (i==0){
06850       s=sRunNumber+"AdcPwHisto.ps(";
06851       cAdcPw->Print(s.c_str());
06852     }
06853     else