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

LIPlexMaps.cxx

Go to the documentation of this file.
00001 
00002 
00003 // Program name: LIPlexMaps.cxx
00004 //                                                                     
00005 // Package: LISummary          
00006 //                                                                    
00007 // Coded by Jeff Hartnell 
00008 //                                                                    
00009 // Purpose: To interogate the plex and produce information in an
00010 //          easy to digest way
00011 //                                                                    
00012 // Contact: jeffrey.hartnell@physics.ox.ac.uk                         
00014 
00015 #include <iostream>
00016 #include <vector>
00017 #include <fstream>
00018 
00019 #include "TCanvas.h"
00020 #include "TDatime.h"
00021 #include "TError.h"//needed for gErrorIgnoreLevel
00022 #include "TF1.h"
00023 #include "TH2.h"
00024 #include "TObject.h"
00025 #include "TPad.h"
00026 #include "TPaveText.h"
00027 #include "TProfile2D.h"
00028 #include "TStyle.h"
00029 #include "TText.h"
00030 #include "TRandom.h"
00031 #include "TStopwatch.h"
00032 
00033 #include "Calibrator/CalADCtoPE.h"
00034 #include "Calibrator/CalMIPCalibration.h"
00035 #include "Calibrator/CalStripToStrip.h"
00036 #include "Conventions/DetectorType.h"
00037 #include "Conventions/StripEnd.h"
00038 #include "DatabaseInterface/DbiResultPtr.h"
00039 #include "DatabaseInterface/DbiValidityRec.h"
00040 #include "DatabaseInterface/DbiWriter.h"
00041 #include "MessageService/MsgService.h"
00042 #include "PulserCalibration/PulserRawDrift.h"
00043 #include "PulserCalibration/PulserRawDriftF.h"
00044 #include "PulserCalibration/PulserRefDrift.h"
00045 #include "PulserCalibration/PulserRefDriftF.h"
00046 #include "PulserCalibration/PulserRawDriftPin.h"
00047 #include "PulserCalibration/PulserRefDriftPin.h"
00048 #include "PulserCalibration/PulserRawGain.h"
00049 #include "RawData/RawChannelId.h"
00050 #include "Validity/VldContext.h"
00051 #include "Validity/VldTimeStamp.h"
00052 
00053 #include "LISummary/LIPlexMaps.h"
00054 #include "LISummary/LIPmt.h"
00055 #include "LISummary/LIRun.h"
00056 
00057 CVSID("$Id: LIPlexMaps.cxx,v 1.44 2005/04/25 13:08:16 minoscvs Exp $");
00058 
00059 ClassImp(LIPlexMaps)
00060 
00061 //......................................................................
00062 
00063 class LedIdList : public std::vector<PlexLedId> 
00064 {
00065   
00066 public:
00067   
00068   LedIdList(const VldContext& context) { Reset(context);};
00069   LedIdList() { 
00070     VldTimeStamp ts;
00071     VldContext cx(DetectorType::kCalDet,SimFlag::kData,ts);
00072     Reset(cx);
00073   };
00074 
00075   void Reset(const VldContext& context) { 
00076     Int_t numRows=fResPtr.NewQuery(context,0);
00077     MSG("LIPlexMaps",Msg::kInfo)
00078       <<"New DB query produced "<<numRows<<" rows"<<endl;
00079     std::map<PlexLedId,int> tmpMap;
00080 
00081     for (UInt_t i=0;i<fResPtr.GetNumRows();i++) {
00082       const PlexPinDiodeToLed* datum = fResPtr.GetRow(i);
00083       if(datum){
00084         tmpMap[datum->GetPlexLedId()] += 1; // Add it to map.
00085       }
00086     }
00087 
00088     this->clear();
00089     for (std::map<PlexLedId,int>::iterator it=tmpMap.begin(); 
00090         it!=tmpMap.end(); it++) {
00091       this->push_back(it->first);
00092     }
00093   };
00094 
00095 private:
00096 
00097   DbiResultPtr<PlexPinDiodeToLed> fResPtr;
00098 
00099 };
00100 
00101 //......................................................................
00102 
00103 LIPlexMaps::LIPlexMaps()
00104 {
00105   MSG("LIPlexMaps",Msg::kDebug)<<"LIPlexMaps Constructor"<<endl;
00106 
00107   //set the pretty palette
00108   gStyle->SetPalette(1,(Int_t*)0);
00109 
00110 }
00111 
00112 //......................................................................
00113 
00114 LIPlexMaps::~LIPlexMaps()
00115 {
00116   MSG("LIPlexMaps",Msg::kDebug)<<"LIPlexMaps Destructor"<<endl;
00117 }
00118 
00119 //......................................................................
00120 
00121 Bool_t LIPlexMaps::IsPermitted() const
00122 {
00123   MSG("LIPlexMaps",Msg::kDebug) 
00124     <<" ** Running IsPermitted method... **"<<endl;
00125 
00126   char* envVariable=getenv("LITSQLPERMISSION");
00127   if (envVariable==NULL){
00128     MSG("LIAnalysis",Msg::kWarning)
00129       <<endl<<endl
00130       <<"*************************************************************"
00131       <<endl
00132       <<"WARNING: You have tried to do a sensitive operation."<<endl
00133       <<"This feature is designed to make you stop and think."<<endl
00134       <<"If you know what you are doing then look at the code."<<endl
00135       <<"*************************************************************"
00136       <<endl<<endl;
00137     return false;
00138   }
00139 
00140   MSG("LIPlexMaps",Msg::kDebug) 
00141     <<" ** Finished IsPermitted method **"<<endl;
00142   return true;
00143 }
00144 
00145 //......................................................................
00146 
00147 void LIPlexMaps::ScaleVector(vector<Double_t>& v,Double_t scaleFactor)
00148 {
00149   MSG("LIPlexMaps",Msg::kDebug) 
00150     <<" ** Running ScaleVector method... **"<<endl;
00151 
00152   for (UInt_t i=0;i<v.size();i++) v[i]*=scaleFactor;
00153 
00154   MSG("LIPlexMaps",Msg::kDebug) 
00155     <<" ** Finished ScaleVector method **"<<endl;
00156 }
00157 
00158 //......................................................................
00159 
00160 void LIPlexMaps::NormaliseVector(vector<Double_t>& v,Int_t mode)
00161 {
00162   MSG("LIPlexMaps",Msg::kDebug) 
00163     <<" ** Running NormaliseVector method... **"<<endl;
00164   
00165   if (v.size()>0){
00166 
00167     if (mode==1){//simple average
00168       //find average
00169       Double_t average=0;
00170       for (UInt_t i=0;i<v.size();i++) average+=v[i];
00171       average/=v.size();
00172       
00173       MSG("LIPlexMaps",Msg::kVerbose)<<"Average="<<average<<endl; 
00174       
00175       //normalise
00176       for (UInt_t i=0;i<v.size();i++) v[i]/=average;
00177     }
00178     else if (mode==2){//fit the function to remove effect of outliers
00179       
00180       Double_t vMax=-9e50;
00181       Double_t vMin=9e50;
00182 
00183       //work out mins and maxs
00184       for (UInt_t i=0;i<v.size();i++){
00185         if (v[i]>vMax) vMax=v[i];
00186         if (v[i]<vMin) vMin=v[i];
00187       }
00188       
00189       //limit the number of bins
00190       Int_t numBins=300;
00191       if (4*v.size()<10000) numBins=4*v.size();
00192 
00193       MSG("LIAnalysis",Msg::kInfo)
00194         <<"vMax="<<vMax <<", vMin="<<vMin<<", numBins="<<numBins<<endl;
00195 
00196       //create the histo
00197       //30/Aug/04 - changed to using fabs, not sure if this will work!
00198       TH1F* h=new TH1F("h","h",numBins,vMin-fabs(0.1*vMin),
00199                        vMax+fabs(0.1*vMin));
00200       h->SetBit(TH1::kCanRebin);
00201 
00202       Double_t average=0;
00203       for (UInt_t i=0;i<v.size();i++){
00204         //find average
00205         average+=v[i];
00206 
00207         //fill the histo
00208         h->Fill(v[i]);
00209       }
00210       average/=v.size();
00211 
00212       //fit but use 0 (zero!) otherwise it stamps on the current canvas!
00213       h->Fit("gaus","q0");
00214       TF1* func=h->GetFunction("gaus");
00215       Double_t p1=func->GetParameter(1);
00216       Double_t p2=func->GetParameter(2);
00217 
00218       //don't use the fit if it is screwed up
00219       Double_t avToNormWith=p1;
00220       if (p1<vMin || p1>vMax) avToNormWith=average;
00221 
00222       MSG("LIAnalysis",Msg::kInfo)
00223         <<"Fitted mean="<<p1
00224         <<" (average="<<average
00225         <<") fitted rms="<<p2
00226         <<", using avToNormWith="<<avToNormWith<<endl;
00227 
00228       //normalise
00229       for (UInt_t i=0;i<v.size();i++) v[i]/=avToNormWith;
00230 
00231       delete h;
00232     }
00233   }
00234 
00235   MSG("LIPlexMaps",Msg::kDebug) 
00236     <<" ** Finished NormaliseVector method **"<<endl;
00237 }
00238 
00239 //......................................................................
00240 
00241 void LIPlexMaps::BinomialGen(vector<Double_t>& v,Int_t N,Double_t p)
00242 {
00243   MSG("LIPlexMaps",Msg::kDebug) 
00244     <<" ** Running BinomialGen method... **"<<endl;
00245 
00246   //Note: This analytical method goes wrong for N>170 
00247   //because the precision of 
00248   //the doubles can't handle the large factorials
00249   //in this case the approximation to a gaussian will be used
00250 
00251   //prob of r events in N is:
00252   //N!/r!*(N-r)! * p**r * (1-p)**(N-r)
00253   //where p is the probability of a success
00254 
00255   Double_t totalProb=0;
00256 
00257   if (N<=170){
00258     vector<Double_t> factorials(N+1);
00259     this->FactorialGen(factorials);
00260     
00261     for (UInt_t r=0;r<v.size();r++){
00262       Double_t perm=factorials[N]/(factorials[r]*factorials[N-r]);
00263       Double_t successes=pow(p,(Int_t)(r));
00264       Double_t failures=pow(1-p,(Int_t)(N-r));
00265       v[r]=perm*successes*failures;
00266       totalProb+=v[r];
00267       MSG("LIPlexMaps",Msg::kInfo)
00268         <<"Prob of "<<r<<" events = "<<v[r]
00269         <<" (perm="<<perm
00270         <<", succ="<<successes
00271         <<", fail="<<failures<<")"
00272         <<endl;
00273 
00274       MSG("LIPlexMaps",Msg::kInfo)<<"Total prob = "<<totalProb<<endl;
00275     }
00276   }
00277   else if (N>170){
00278     //use gaussian distribution with following
00279     //mean=prob*ntot+0.5
00280     //standard deviation = sqrt(ntot*prob*(1-prob).
00281     MSG("LIPlexMaps",Msg::kInfo)
00282       <<"Above N=170 this has not been implemented"<<endl;
00283   }
00284 
00285   MSG("LIPlexMaps",Msg::kDebug) 
00286     <<" ** Finished BinomialGen method **"<<endl;
00287 }
00288 
00289 //......................................................................
00290 
00291 void LIPlexMaps::FactorialGen(vector<Double_t>& v)
00292 {
00293   MSG("LIPlexMaps",Msg::kDebug) 
00294     <<" ** Running FactorialGen method... **"<<endl;
00295 
00296   //Note: The precision of the double is not enough above 170!
00297   //166 factorial = 9.00369e+297
00298   //167 factorial = 1.50362e+300
00299   //168 factorial = 2.52608e+302
00300   //169 factorial = 4.26907e+304
00301   //170 factorial = 7.25742e+306
00302   //171 factorial = inf
00303   
00304   if (v.size()>=2){
00305     v[0]=1;
00306     v[1]=1;
00307   }
00308 
00309   for (UInt_t i=2;i<v.size();i++){
00310     v[i]=v[i-1]*i;
00311     MSG("LIPlexMaps",Msg::kInfo)<<i<<" factorial = "<<v[i]<<endl;
00312   }
00313 
00314   MSG("LIPlexMaps",Msg::kDebug) 
00315     <<" ** Finished FactorialGen method **"<<endl;
00316 }
00317 
00318 //......................................................................
00319 
00320 Int_t LIPlexMaps::SampleDist(vector<Double_t> v,TRandom* tRand)
00321 {
00322   MSG("LIPlexMaps",Msg::kVerbose) 
00323     <<" ** Running SampleDist method... **"<<endl;
00324 
00325   //Note: v's maximum entry must be 1
00326 
00327   Int_t size=v.size();
00328   Int_t p=-1;
00329 
00330   Int_t foundPoint=0;
00331   while (foundPoint==0){
00332     
00333     p=tRand->Integer(size);
00334     Double_t probToChose=v[p];
00335     Double_t r1=tRand->Rndm();
00336     
00337     MSG("LIPlexMaps",Msg::kVerbose) 
00338       <<"point="<<p<<", probToChose="<<probToChose<<", r1="<<r1<<endl;
00339     
00340     if (probToChose>=r1) foundPoint=1;
00341   }
00342 
00343   MSG("LIPlexMaps",Msg::kVerbose) 
00344     <<" ** Finished SampleDist method **"<<endl;
00345   return p;
00346 }
00347 
00348 //......................................................................
00349 
00350 void LIPlexMaps::Attenuation()
00351 {
00352   MSG("LIPlexMaps",Msg::kInfo) 
00353     <<" ** Running Attenuation method... **"<<endl;
00354 
00355   vector<Double_t> x;
00356   vector<Double_t> xNorm;
00357   vector<Double_t> yGreenAtt1;
00358   vector<Double_t> yGreenAtt2;
00359   vector<Double_t> yGreen;
00360   vector<Double_t> yClear;
00361   vector<Double_t> y12C;
00362   vector<Double_t> y6G;
00363   vector<Double_t> y2G;
00364   vector<Double_t> y1G_12C_1G_1;
00365   vector<Double_t> y1G_12C_1G_2;
00366   vector<Double_t> y1G_12C_1G_3;
00367   vector<Double_t> x1G_12C_1G_1;
00368   vector<Double_t> x1G_12C_1G_2;
00369   vector<Double_t> x1G_12C_1G_3;
00370   vector<Double_t> y8G;
00371   vector<Double_t> y3GNear;
00372   vector<Double_t> y6CNear;
00373   vector<Double_t> y3GFar;
00374   vector<Double_t> y6CFar;
00375 
00376   vector<Double_t> boost12C;
00377   vector<Double_t> boost6G;
00378   vector<Double_t> boost8G;
00379   vector<Double_t> boost1G_12C_1G;
00380   vector<Double_t> reflectivity;
00381 
00382   Double_t maxCableLength=20;
00383   Int_t numPoints=1000;
00384 
00385   //attenuation lengths in meters
00386   Double_t greenAtt1=1;
00387   Double_t greenAtt2=10;//6m from Leo, 10m from KR off-axis talk
00388   Double_t clearAtt=12;
00389 
00390   //from MK
00391   //Double_t greenAtt1=0.5;
00392   //Double_t greenAtt2=6.7;
00393   //Double_t clearAtt=12.5;
00394 
00395   Double_t ref=1.0;
00396 
00397   Double_t ref12C=exp(-12./clearAtt);
00398   Double_t ref6G=0.5*(exp(-6./greenAtt1)+exp(-6./greenAtt2));
00399   Double_t ref2G=0.5*(exp(-2./greenAtt1)+exp(-2./greenAtt2));
00400   Double_t ref8G=0.5*(exp(-8./greenAtt1)+exp(-8./greenAtt2));
00401   Double_t ref1G_12C_1G=ref2G*ref12C;
00402 
00403   MSG("LIPlexMaps",Msg::kInfo)
00404     <<"Reflectivity = "<<ref
00405     <<endl
00406     <<"6m green = "<<ref6G<<" (0.22)"
00407     <<endl
00408     <<"12m clear = "<<ref12C<<" (0.20)"
00409     <<endl
00410     <<"8m green = "<<ref8G<<" (0.06)"
00411     <<endl
00412     <<"1mG & 12mC & 1mG = "<<ref1G_12C_1G<<" (0.09)"
00413     <<endl;
00414 
00415   MSG("LIPlexMaps",Msg::kInfo) 
00416     <<"Calculating boosts..."<<endl;
00417   for (Int_t i=0;i<numPoints;i++){
00418     reflectivity.push_back(0);
00419     boost12C.push_back(0);
00420     boost6G.push_back(0);
00421     boost1G_12C_1G.push_back(0);
00422     boost8G.push_back(0);
00423 
00424     Double_t connectorEff=1.0;
00425 
00426     reflectivity[i]=i*1./numPoints;
00427     boost12C[i]=connectorEff*reflectivity[i]*ref12C;
00428     boost1G_12C_1G[i]=connectorEff*reflectivity[i]*ref12C*ref2G;
00429 
00430     boost6G[i]=reflectivity[i]*ref6G;
00431     boost8G[i]=reflectivity[i]*ref8G;
00432   }
00433 
00434   MSG("LIPlexMaps",Msg::kInfo) 
00435     <<"Calculating basic attenuation curves..."<<endl;
00436   for (Int_t i=0;i<numPoints;i++){
00437     x.push_back(0);
00438     yGreenAtt1.push_back(0);
00439     yGreenAtt2.push_back(0);
00440     yGreen.push_back(0);
00441     yClear.push_back(0);
00442     
00443     x[i]=i*maxCableLength/numPoints;
00444     yGreenAtt1[i]=exp(-x[i]/greenAtt1);
00445     yGreenAtt2[i]=exp(-x[i]/greenAtt2);
00446     yGreen[i]=0.5*(exp(-x[i]/greenAtt1)+exp(-x[i]/greenAtt2));
00447     yClear[i]=exp(-x[i]/clearAtt);
00448   }
00449 
00450   MSG("LIPlexMaps",Msg::kInfo) 
00451     <<"Calculating for 1st 1 m of green..."<<endl;
00452   for (Int_t i=0;i<numPoints;i++){
00453     Double_t x=i*1./numPoints;
00454     xNorm.push_back(0);
00455     y12C.push_back(0);
00456     y6G.push_back(0);
00457     y2G.push_back(0);
00458     y8G.push_back(0);
00459 
00460     //only 1 (~meter) for fractional reflected length
00461     xNorm[i]=i*1./numPoints;
00462     
00463     y12C[i]=exp(-12*xNorm[i]/clearAtt);
00464     y6G[i]=0.5*(exp(-6*xNorm[i]/greenAtt1)+exp(-6*xNorm[i]/greenAtt2));
00465     y2G[i]=0.5*(exp(-2*xNorm[i]/greenAtt1)+exp(-2*xNorm[i]/greenAtt2));
00466 
00467     if (x<1./14){
00468       Double_t x2=i*1./((1./14)*numPoints);
00469       y1G_12C_1G_1.push_back(0);
00470       x1G_12C_1G_1.push_back(0);
00471       x1G_12C_1G_1[i]=x;
00472       y1G_12C_1G_1[i]=0.5*(exp(-1*x2/greenAtt1)+exp(-1*x2/greenAtt2));
00473       MSG("LIPlexMaps",Msg::kDebug) 
00474         <<"x="<<x<<", x2="<<x2
00475         <<", x1G_12C_1G_1[i]="<<x1G_12C_1G_1[i]
00476         <<", y1G_12C_1G_1[i]="<<y1G_12C_1G_1[i]
00477         <<endl;
00478     }
00479     y8G[i]=0.5*(exp(-8*xNorm[i]/greenAtt1)+exp(-8*xNorm[i]/greenAtt2));
00480   }
00481 
00482   UInt_t size_1=y1G_12C_1G_1.size();
00483   Int_t counter=0;
00484 
00485   MSG("LIPlexMaps",Msg::kInfo) 
00486     <<"Calculating for 12 m of clear..."<<endl;
00487   for (Int_t i=0;i<numPoints;i++){
00488     Double_t x=i*1./numPoints;
00489 
00490     if (x>1./14 && x<13./14){
00491       Double_t x2=counter*1./((12./14)*numPoints);
00492       y1G_12C_1G_2.push_back(0);
00493       x1G_12C_1G_2.push_back(0);
00494       x1G_12C_1G_2[counter]=x;
00495       y1G_12C_1G_2[counter]=y1G_12C_1G_1[size_1-1]*exp(-12*x2/clearAtt);
00496       MSG("LIPlexMaps",Msg::kDebug) 
00497         <<"x="<<x<<", x2="<<x2
00498         <<", x1G_12C_1G_2[i]="<<x1G_12C_1G_2[counter]
00499         <<", y1G_12C_1G_2[i]="<<y1G_12C_1G_2[counter]
00500         <<endl;
00501       counter++;
00502     }
00503   }
00504   
00505   UInt_t size_2=y1G_12C_1G_2.size();
00506   counter=0;
00507 
00508   MSG("LIPlexMaps",Msg::kInfo) 
00509     <<"Calculating for last 1 m of green..."<<endl;
00510   for (Int_t i=0;i<numPoints;i++){
00511     Double_t x=i*1./numPoints;
00512 
00513     if (x>13./14){
00514       Double_t x2=counter*1./((1./14)*numPoints);
00515       y1G_12C_1G_3.push_back(0);
00516       x1G_12C_1G_3.push_back(0);
00517       x1G_12C_1G_3[counter]=x;
00518 
00519       //take account of the x2+1 using scaleFactor
00520       Double_t scaleFactor=1./y1G_12C_1G_1[size_1-1];
00521       y1G_12C_1G_3[counter]=scaleFactor*y1G_12C_1G_2[size_2-1]*0.5*
00522         (exp(-1*(x2+1)/greenAtt1)+
00523          exp(-1*(x2+1)/greenAtt2));
00524       MSG("LIPlexMaps",Msg::kDebug) 
00525         <<"x="<<x<<", x2="<<x2
00526         <<", x1G_12C_1G_3[i]="<<x1G_12C_1G_3[counter]
00527         <<", y1G_12C_1G_3[i]="<<y1G_12C_1G_3[counter]
00528         <<endl;
00529       counter++;
00530     }
00531   }
00532 
00533   UInt_t size_3=y1G_12C_1G_3.size();
00534   UInt_t size_8G=y8G.size();
00535 
00536   MSG("LIPlexMaps",Msg::kInfo) 
00537     <<"Calculating for last section to PMT..."<<endl;
00538   MSG("LIPlexMaps",Msg::kInfo) 
00539     <<"Near side..."<<endl;
00540   for (Int_t i=0;i<numPoints;i++){
00541     Double_t x=i*1./numPoints;
00542 
00543     y3GNear.push_back(0);
00544     y6CNear.push_back(0);
00545     
00546     y3GNear[i]=y1G_12C_1G_3[size_3-1]*0.5*
00547       (exp(-3.*x/greenAtt1)+exp(-3.*x/greenAtt2));
00548     y6CNear[i]=y8G[size_8G-1]*exp(-6.*x/clearAtt);
00549     
00550     MSG("LIPlexMaps",Msg::kDebug) 
00551       <<"x="<<x
00552       <<", y3GNear[i]="<<y3GNear[i]
00553       <<", y6CNear[i]"<<y6CNear[i]
00554       <<endl;
00555   }
00556 
00557   UInt_t size_12C=y12C.size();
00558   UInt_t size_6G=y6G.size();
00559 
00560   MSG("LIPlexMaps",Msg::kInfo) 
00561     <<"Far side..."<<endl;
00562   for (Int_t i=0;i<numPoints;i++){
00563     Double_t x=i*1./numPoints;
00564 
00565     y3GFar.push_back(0);
00566     y6CFar.push_back(0);
00567     
00568     y3GFar[i]=y12C[size_12C-1]*0.5*
00569       (exp(-3.*x/greenAtt1)+exp(-3.*x/greenAtt2));
00570     y6CFar[i]=y6G[size_6G-1]*exp(-6.*x/clearAtt);
00571     
00572     MSG("LIPlexMaps",Msg::kDebug) 
00573       <<"x="<<x
00574       <<", y3GFar[i]="<<y3GFar[i]
00575       <<", y6CFar[i]"<<y6CFar[i]
00576       <<endl;
00577   }
00578 
00579   //create canvas
00580   TCanvas *cAttenuation=new TCanvas("cAttenuation","cAttenuation",
00581                                   1,1,1000,800);
00582   cAttenuation->SetFillColor(0);
00583   cAttenuation->Divide(2,2);
00584 
00585   //create graph
00586   TGraph* gGreen=TGraphVect(x,yGreen);
00587   gGreen->SetTitle("Green Attenuation length (1+2)");
00588   gGreen->SetMarkerStyle(3);
00589   gGreen->SetMarkerColor(3);
00590   gGreen->SetMarkerSize(0.2);
00591   cAttenuation->cd(1);
00592   gGreen->Draw("AP");
00593   gGreen->GetXaxis()->SetTitle("Cable length");
00594   gGreen->GetYaxis()->SetTitle("Intensity");
00595   gGreen->GetXaxis()->CenterTitle();
00596   gGreen->GetYaxis()->CenterTitle();
00597   gGreen->SetMinimum(0);
00598   
00599   //create graph
00600   TGraph* gGreenAtt1=TGraphVect(x,yGreenAtt1);
00601   gGreenAtt1->SetTitle("Green Attenuation length 1");
00602   gGreenAtt1->SetMarkerStyle(3);
00603   gGreenAtt1->SetMarkerColor(30);
00604   gGreenAtt1->SetMarkerSize(0.2);
00605   cAttenuation->cd(2);
00606   gGreenAtt1->Draw("AP");
00607   gGreenAtt1->GetXaxis()->SetTitle("Cable length");
00608   gGreenAtt1->GetYaxis()->SetTitle("Intensity");
00609   gGreenAtt1->GetXaxis()->CenterTitle();
00610   gGreenAtt1->GetYaxis()->CenterTitle();
00611   gGreenAtt1->SetMinimum(0);
00612 
00613   //create graph
00614   TGraph* gGreenAtt2=TGraphVect(x,yGreenAtt2);
00615   gGreenAtt2->SetTitle("Green Attenuation length 2");
00616   gGreenAtt2->SetMarkerStyle(3);
00617   gGreenAtt2->SetMarkerColor(8);
00618   gGreenAtt2->SetMarkerSize(0.2);
00619   cAttenuation->cd(3);
00620   gGreenAtt2->Draw("AP");
00621   gGreenAtt2->GetXaxis()->SetTitle("Cable length");
00622   gGreenAtt2->GetYaxis()->SetTitle("Intensity");
00623   gGreenAtt2->GetXaxis()->CenterTitle();
00624   gGreenAtt2->GetYaxis()->CenterTitle();
00625   gGreenAtt2->SetMinimum(0);
00626 
00627   //create graph
00628   TGraph* gClear=TGraphVect(x,yClear);
00629   gClear->SetTitle("Clear Attenuation length");
00630   gClear->SetMarkerStyle(3);
00631   gClear->SetMarkerColor(1);
00632   gClear->SetMarkerSize(0.2);
00633   cAttenuation->cd(4);
00634   gClear->Draw("AP");
00635   gClear->GetXaxis()->SetTitle("Cable length");
00636   gClear->GetYaxis()->SetTitle("Intensity");
00637   gClear->GetXaxis()->CenterTitle();
00638   gClear->GetYaxis()->CenterTitle();
00639   gClear->SetMinimum(0);
00640 
00642   //create canvas
00644   MSG("LIPlexMaps",Msg::kInfo) 
00645     <<"Drawing cAttCalDet canvas..."<<endl;
00646   TCanvas *cAttCalDet=new TCanvas("cAttCalDet","cAttCalDet",
00647                                   1,1,1000,800);
00648   cAttCalDet->SetFillColor(0);
00649   //cAttCalDet->Divide(2,2);
00650 
00651   //create graph
00652   TGraph* g12C=TGraphVect(xNorm,y12C);
00653   g12C->SetTitle("Fractional Attenuation (LI Far Side)");
00654   g12C->SetMarkerStyle(3);
00655   g12C->SetMarkerColor(1);
00656   g12C->SetMarkerSize(0.2);
00657   cAttCalDet->cd(1);
00658   g12C->Draw("AP");
00659   g12C->GetXaxis()->SetTitle("Fraction of reflected distance (m)");
00660   g12C->GetYaxis()->SetTitle("Intensity");
00661   g12C->GetXaxis()->CenterTitle();
00662   g12C->GetYaxis()->CenterTitle();
00663   g12C->SetMinimum(0);
00664 
00665   //create graph
00666   TGraph* g6G=TGraphVect(xNorm,y6G);
00667   g6G->SetTitle("Fractional Attenuation");
00668   g6G->SetMarkerStyle(3);
00669   g6G->SetMarkerColor(3);
00670   g6G->SetMarkerSize(0.2);
00671   cAttCalDet->cd(1);
00672   g6G->Draw("P");
00673 
00674   //create graph
00675   TGraph* g12C_2=TGraphVect(xNorm,y12C);
00676   g12C_2->SetTitle("12 m Clear Attenuation");
00677   g12C_2->SetMarkerStyle(3);
00678   g12C_2->SetMarkerColor(1);
00679   g12C_2->SetMarkerSize(0.2);
00680   //cAttCalDet->cd(2);
00681   //g12C_2->Draw("AP");
00682   g12C_2->GetXaxis()->SetTitle("Fraction of reflected distance (m)");
00683   g12C_2->GetYaxis()->SetTitle("Intensity");
00684   g12C_2->GetXaxis()->CenterTitle();
00685   g12C_2->GetYaxis()->CenterTitle();
00686   g12C_2->SetMinimum(0);
00687 
00688   //create graph
00689   g6G->SetTitle("6 m Green Attenuation");
00690   g6G->SetMarkerStyle(3);
00691   g6G->SetMarkerColor(3);
00692   g6G->SetMarkerSize(0.2);
00693   //cAttCalDet->cd(3);
00694   //g6G->Draw("AP");
00695   g6G->GetXaxis()->SetTitle("Fraction of reflected distance (m)");
00696   g6G->GetYaxis()->SetTitle("Intensity");
00697   g6G->GetXaxis()->CenterTitle();
00698   g6G->GetYaxis()->CenterTitle();
00699   g6G->SetMinimum(0);
00700   
00702   //create canvas
00704   MSG("LIPlexMaps",Msg::kInfo) 
00705     <<"Drawing cAttCalDet2 canvas..."<<endl;
00706   TCanvas *cAttCalDet2=new TCanvas("cAttCalDet2","cAttCalDet2",
00707                                    1,1,1000,800);
00708   cAttCalDet2->SetFillColor(0);
00709   cAttCalDet2->Divide(1,1);
00710 
00711   //create graph
00712   TGraph* gDummy=TGraphVect(xNorm,xNorm);
00713   gDummy->SetTitle("Fractional Attenuation (LI Near Side)");
00714   gDummy->SetMinimum(0);
00715   gDummy->SetMaximum(1.2);
00716   gDummy->SetMarkerColor(0);
00717   cAttCalDet2->cd(1);
00718   gDummy->Draw("AP");
00719   gDummy->GetXaxis()->SetTitle("Fraction of reflected distance (m)");
00720   gDummy->GetYaxis()->SetTitle("Intensity");
00721   gDummy->GetXaxis()->CenterTitle();
00722   gDummy->GetYaxis()->CenterTitle();
00723 
00724   //create graph
00725   TGraph* g1G_12C_1G_1=TGraphVect(x1G_12C_1G_1,y1G_12C_1G_1);
00726   g1G_12C_1G_1->SetTitle("Fractional Attenuation");
00727   g1G_12C_1G_1->SetMarkerStyle(3);
00728   g1G_12C_1G_1->SetMarkerColor(3);
00729   g1G_12C_1G_1->SetMarkerSize(0.2);
00730   cAttCalDet2->cd(1);
00731   g1G_12C_1G_1->Draw("p");
00732   g1G_12C_1G_1->SetMinimum(0);
00733 
00734   //create graph
00735   TGraph* g1G_12C_1G_2=TGraphVect(x1G_12C_1G_2,y1G_12C_1G_2);
00736   g1G_12C_1G_2->SetTitle("Fractional Attenuation");
00737   g1G_12C_1G_2->SetMarkerStyle(3);
00738   g1G_12C_1G_2->SetMarkerColor(1);
00739   g1G_12C_1G_2->SetMarkerSize(0.2);
00740   cAttCalDet2->cd(1);
00741   g1G_12C_1G_2->Draw("P");
00742   g1G_12C_1G_2->SetMinimum(0);
00743 
00744   //create graph
00745   TGraph* g1G_12C_1G_3=TGraphVect(x1G_12C_1G_3,y1G_12C_1G_3);
00746   g1G_12C_1G_3->SetTitle("Fractional Attenuation");
00747   g1G_12C_1G_3->SetMarkerStyle(3);
00748   g1G_12C_1G_3->SetMarkerColor(3);
00749   g1G_12C_1G_3->SetMarkerSize(0.2);
00750   cAttCalDet2->cd(1);
00751   g1G_12C_1G_3->Draw("P");
00752   g1G_12C_1G_3->SetMinimum(0);
00753 
00754   //create graph
00755   TGraph* g8G=TGraphVect(xNorm,y8G);
00756   g8G->SetTitle("Fractional Attenuation");
00757   g8G->SetMarkerStyle(3);
00758   g8G->SetMarkerColor(8);
00759   g8G->SetMarkerSize(0.2);
00760   cAttCalDet2->cd(1);
00761   g8G->Draw("P");
00762   g8G->SetMinimum(0);
00763 
00765   //create canvas
00767   /*
00768   MSG("LIPlexMaps",Msg::kInfo) 
00769     <<"Drawing cAttCalDetNear canvas..."<<endl;
00770   TCanvas *cAttCalDetNear=new TCanvas("cAttCalDetNear","cAttCalDetNear",
00771                                       1,1,1000,800);
00772   cAttCalDetNear->SetFillColor(0);
00773   cAttCalDetNear->Divide(1,1);
00774 
00775   //create graph
00776   TGraph* g3GNear=TGraphVect(xNorm,y3GNear);
00777   g3GNear->SetTitle("Fractional Attenuation (LI Near Side)");
00778   g3GNear->SetMarkerStyle(3);
00779   g3GNear->SetMarkerColor(3);
00780   g3GNear->SetMarkerSize(0.2);
00781   cAttCalDetNear->cd(1);
00782   g3GNear->Draw("AP");
00783   g3GNear->GetXaxis()->SetTitle("Fraction of distance to PMT (m)");
00784   g3GNear->GetYaxis()->SetTitle("Intensity");
00785   g3GNear->GetXaxis()->CenterTitle();
00786   g3GNear->GetYaxis()->CenterTitle();
00787   g3GNear->SetMaximum(1.2);
00788   g3GNear->SetMinimum(0);
00789 
00790   //create graph
00791   TGraph* g6CNear=TGraphVect(xNorm,y6CNear);
00792   g6CNear->SetTitle("Fractional Attenuation (LI Near Side)");
00793   g6CNear->SetMarkerStyle(3);
00794   g6CNear->SetMarkerColor(1);
00795   g6CNear->SetMarkerSize(0.2);
00796   cAttCalDetNear->cd(1);
00797   g6CNear->Draw("P");
00798   g6CNear->SetMinimum(0);
00799 
00801   //create canvas
00803   MSG("LIPlexMaps",Msg::kInfo) 
00804     <<"Drawing cAttCalDetFar canvas..."<<endl;
00805   TCanvas *cAttCalDetFar=new TCanvas("cAttCalDetFar","cAttCalDetFar",
00806                                      1,1,1000,800);
00807   cAttCalDetFar->SetFillColor(0);
00808   cAttCalDetFar->Divide(1,1);
00809 
00810   //create graph
00811   TGraph* g3GFar=TGraphVect(xNorm,y3GFar);
00812   g3GFar->SetTitle("Fractional Attenuation (LI Far Side)");
00813   g3GFar->SetMarkerStyle(3);
00814   g3GFar->SetMarkerColor(3);
00815   g3GFar->SetMarkerSize(0.2);
00816   cAttCalDetFar->cd(1);
00817   g3GFar->Draw("AP");
00818   g3GFar->GetXaxis()->SetTitle("Fraction of distance to PMT (m)");
00819   g3GFar->GetYaxis()->SetTitle("Intensity");
00820   g3GFar->GetXaxis()->CenterTitle();
00821   g3GFar->GetYaxis()->CenterTitle();
00822   g3GFar->SetMaximum(1.2);
00823   g3GFar->SetMinimum(0);
00824 
00825   //create graph
00826   TGraph* g6CFar=TGraphVect(xNorm,y6CFar);
00827   g6CFar->SetTitle("Fractional Attenuation (LI Far Side)");
00828   g6CFar->SetMarkerStyle(3);
00829   g6CFar->SetMarkerColor(1);
00830   g6CFar->SetMarkerSize(0.2);
00831   cAttCalDetFar->cd(1);
00832   g6CFar->Draw("P");
00833   g6CFar->SetMinimum(0);
00834   */
00835 
00837   //create canvas
00839   MSG("LIPlexMaps",Msg::kInfo) 
00840     <<"Drawing cBoostsFar canvas..."<<endl;
00841   TCanvas *cBoostsFar=new TCanvas("cBoostsFar","cBoostsFar",
00842                                   1,1,1000,800);
00843   cBoostsFar->SetFillColor(0);
00844   cBoostsFar->Divide(1,1);
00845 
00846   //create graph
00847   TGraph* cBoost6G=TGraphVect(reflectivity,boost6G);
00848   cBoost6G->SetTitle("Fractional Boost vs Reflectivity");
00849   cBoost6G->SetMarkerStyle(3);
00850   cBoost6G->SetMarkerColor(3);
00851   cBoost6G->SetMarkerSize(0.2);
00852   cBoostsFar->cd(1);
00853   cBoost6G->Draw("AP");
00854   cBoost6G->GetXaxis()->SetTitle("Reflectivity");
00855   cBoost6G->GetYaxis()->SetTitle("Fractional Boost");
00856   cBoost6G->GetXaxis()->CenterTitle();
00857   cBoost6G->GetYaxis()->CenterTitle();
00858   cBoost6G->SetMaximum(1.2);
00859   cBoost6G->SetMinimum(0);
00860 
00861   //create graph
00862   TGraph* cBoost12C=TGraphVect(reflectivity,boost12C);
00863   cBoost12C->SetTitle("Fractional Boost vs Reflectivity");
00864   cBoost12C->SetMarkerStyle(3);
00865   cBoost12C->SetMarkerColor(1);
00866   cBoost12C->SetMarkerSize(0.2);
00867   cBoostsFar->cd(1);
00868   cBoost12C->Draw("P");
00869   cBoost12C->SetMinimum(0);
00870 
00871 
00873   //create canvas
00875   MSG("LIPlexMaps",Msg::kInfo) 
00876     <<"Drawing cBoostsNear canvas..."<<endl;
00877   TCanvas *cBoostsNear=new TCanvas("cBoostsNear","cBoostsNear",
00878                                   1,1,1000,800);
00879   cBoostsNear->SetFillColor(0);
00880   cBoostsNear->Divide(1,1);
00881 
00882   //create graph
00883   TGraph* cBoost8G=TGraphVect(reflectivity,boost8G);
00884   cBoost8G->SetTitle("Fractional Boost vs Reflectivity");
00885   cBoost8G->SetMarkerStyle(3);
00886   cBoost8G->SetMarkerColor(3);
00887   cBoost8G->SetMarkerSize(0.2);
00888   cBoostsNear->cd(1);
00889   cBoost8G->Draw("AP");
00890   cBoost8G->GetXaxis()->SetTitle("Reflectivity");
00891   cBoost8G->GetYaxis()->SetTitle("Fractional Boost");
00892   cBoost8G->GetXaxis()->CenterTitle();
00893   cBoost8G->GetYaxis()->CenterTitle();
00894   cBoost8G->SetMaximum(1.2);
00895   cBoost8G->SetMinimum(0);
00896 
00897   //create graph
00898   TGraph* cBoost1G_12C_1G=TGraphVect(reflectivity,boost1G_12C_1G);
00899   cBoost1G_12C_1G->SetTitle("Fractional Boost vs Reflectivity");
00900   cBoost1G_12C_1G->SetMarkerStyle(3);
00901   cBoost1G_12C_1G->SetMarkerColor(1);
00902   cBoost1G_12C_1G->SetMarkerSize(0.2);
00903   cBoostsNear->cd(1);
00904   cBoost1G_12C_1G->Draw("P");
00905   cBoost1G_12C_1G->SetMinimum(0);
00906 
00907   MSG("LIPlexMaps",Msg::kInfo) 
00908     <<" ** Finished Attenuation method **"<<endl;
00909 }
00910 
00911 //......................................................................
00912 
00913 void LIPlexMaps::ADCRailEffect()
00914 {
00915   MSG("LIPlexMaps",Msg::kInfo) 
00916     <<" ** Running ADCRailEffect method... **"<<endl;
00917 
00919   //Theory
00921   //gain=rms**2/mean * 1/(1-p)
00922   //thus
00923   //rms=sqrt(gain*mean*(1-p))
00924   //and
00925   //npe=(mean/rms)**2 * (1-p)
00926 
00927   //use the pretty palette
00928   gStyle->SetPalette(1);
00929   //include the under and overflow counts
00930   gStyle->SetOptStat(1111111);
00931 
00932   TStopwatch stopwatch;
00933 
00934   //these two are defined
00935   const Double_t kQE=0.13;
00936   
00937   //TRandom has a periodicity of 10^8 so if you have >100 photons
00938   //then you shouldn't use more than 1e6 points in the binomial 
00939   //distribution since you will have started at the beginning of 
00940   //the list of random numbers again
00941   //not sure how this will affect things but it seems dodgy
00942   const Int_t kNumBinomPoints=static_cast<Int_t>(1e6);//1e7 is slow
00943 
00944   MSG("LIPlexMaps",Msg::kInfo) 
00945     <<endl<<"The following parameters are used in the MC:"<<endl
00946     <<"kQE="<<kQE<<endl
00947     <<"kNumBinomPoints="<<kNumBinomPoints<<endl;
00948 
00949   Int_t maxN=150;
00950   TH1F *hBinomial= new TH1F("hBinomial","Binomial distribution",
00951                             maxN+5,-1,maxN+4);
00952   hBinomial->SetFillColor(0);
00953   hBinomial->SetBit(TH1::kCanRebin);
00954 
00955   TH1F *hBinomial2= new TH1F("hBinomial2","Binomial distribution",
00956                             maxN+5,-1,maxN+4);
00957   hBinomial2->SetFillColor(0);
00958   hBinomial2->SetLineColor(2);
00959   hBinomial2->SetBit(TH1::kCanRebin);
00960 
00961   TH1F *hBinomial3= new TH1F("hBinomial3","Binomial distribution",
00962                             maxN+5,-1,maxN+4);
00963   hBinomial3->SetFillColor(0);
00964   hBinomial3->SetLineColor(3);
00965   hBinomial3->SetBit(TH1::kCanRebin);
00966 
00967   //create a histogram based on the binomial
00968   TRandom *tRandom=new TRandom(0);
00969   
00970   for (Int_t N=100;N<160;N+=20){
00971     static Int_t counter=0;
00972     counter++;
00973     
00974     MSG("LIPlexMaps",Msg::kInfo) 
00975       <<endl<<"Generating binomial distribution..."<<endl;
00976     for (Int_t i=0;i<kNumBinomPoints;i++){
00977       //generate a binomial distribution and fill histo
00978       //this works by performing a little MC
00979       //It does N trials and see how many are below the probability p
00980       Int_t r1=tRandom->Binomial(static_cast<Int_t>(N),
00981                                  static_cast<Double_t>(kQE));
00982     
00983       //apply rail
00984       if (r1>15) r1=15;
00985 
00986       if (counter==1) hBinomial->Fill(r1);
00987       if (counter==2) hBinomial2->Fill(r1);
00988       if (counter==3) hBinomial3->Fill(r1);
00989 
00990       //print out loop progress
00991       Float_t fract=ceil(kNumBinomPoints/5.);
00992       if (ceil(((Float_t)i)/fract)==((Float_t)i)/fract){
00993         MSG("LIPlexMaps",Msg::kInfo) 
00994           <<"Fraction of loop complete: "<<i 
00995           <<"/"<<kNumBinomPoints<<"  ("
00996           <<(Int_t)(100.*i/kNumBinomPoints)<<"%)"<<endl;
00997       }    
00998     }
00999     MSG("LIPlexMaps",Msg::kInfo) 
01000       <<"Binomial distribution done"<<endl;
01001   }
01002 
01003   //draw binomial distribution
01004   TCanvas *cBinomial=new TCanvas("cBinomial","cBinomial",1,1,1000,800);
01005   cBinomial->SetFillColor(0);
01006   cBinomial->cd();
01007   hBinomial->Draw();
01008   hBinomial2->Draw("sames");
01009   hBinomial3->Draw("sames");
01010 
01011   MSG("LIPlexMaps",Msg::kInfo) 
01012     <<" ** Finished ADCRailEffect method **"<<endl;
01013 }
01014 
01015 //......................................................................
01016 
01017 void LIPlexMaps::NonLinearity()
01018 {
01019   MSG("LIPlexMaps",Msg::kInfo) 
01020     <<" ** Running NonLinearity method... **"<<endl;
01021 
01022   //use the pretty palette
01023   gStyle->SetPalette(1);
01024   //include the under and overflow counts
01025   gStyle->SetOptStat(1111111);
01026 
01027   Int_t maxN=1000;
01028 
01029   TH1F *hBinomial= new TH1F("hBinomial","Binomial distribution",
01030                             maxN+5,-1,maxN+4);
01031   hBinomial->SetFillColor(0);
01032   hBinomial->SetLineColor(3);
01033   hBinomial->SetBit(TH1::kCanRebin);
01034 
01035   TH1F *hAdc= new TH1F("hAdc","Binomial distribution",
01036                             60*maxN+5,-1,60*maxN+4);
01037   hAdc->SetFillColor(0);
01038   hAdc->SetLineColor(3);
01039   hAdc->SetBit(TH1::kCanRebin);
01040 
01041   TH1F *hGauss= new TH1F("hGauss","Binomial distribution",
01042                             maxN+5,-1,maxN+4);
01043   hGauss->SetFillColor(0);
01044   hGauss->SetLineColor(2);
01045   hGauss->SetBit(TH1::kCanRebin);
01046 
01047   //create a histogram based on the binomial
01048   TRandom *tRandom=new TRandom(0);
01049   //Double_t kQE=0.13;
01050   Int_t kNumBinomPoints=10000;
01051   vector<Double_t> vPe;
01052   vector<Double_t> vAdc;
01053 
01054   for (Int_t N=120;N<270;N+=2){
01055     static Int_t counter=0;
01056     counter++;
01057     
01058     hBinomial->Reset();
01059     hAdc->Reset();
01060     hGauss->Reset();
01061 
01062     MSG("LIPlexMaps",Msg::kInfo) 
01063       <<endl<<"Generating distribution, N="<<N<<endl;
01064     for (Int_t i=0;i<kNumBinomPoints;i++){
01065 
01066       Double_t gauss=tRandom->Gaus(1.*N,sqrt(1.*N));
01067       hGauss->Fill(gauss);
01068 
01069       Double_t adc=70.*gauss-(1.3e-6*pow(1.*gauss,4.));
01070 
01071       //apply the rail at 237
01072       if (gauss>237) adc=70*237-(1.3e-6*pow(237,4.));
01073     
01074       hAdc->Fill(adc);
01075     }
01076 
01077     vPe.push_back(1.*N);
01078     vAdc.push_back(hAdc->GetMean());
01079   }
01080 
01081   //original numbers, but 420 pe for saturation is too high
01082   /*
01083   for (Int_t N=250;N<480;N+=2){
01084     static Int_t counter=0;
01085     counter++;
01086     
01087     hBinomial->Reset();
01088     hAdc->Reset();
01089     hGauss->Reset();
01090 
01091     MSG("LIPlexMaps",Msg::kInfo) 
01092       <<endl<<"Generating distribution, N="<<N<<endl;
01093     for (Int_t i=0;i<kNumBinomPoints;i++){
01094       //generate a binomial distribution and fill histo
01095       //this works by performing a little MC
01096       //It does N trials and see how many are below the probability p
01097       //Int_t r1=tRandom->Binomial(static_cast<Int_t>(N),
01098       //                         static_cast<Double_t>(kQE));
01099       //hBinomial->Fill(r1);
01100 
01101       //Double_t gauss=tRandom->Gaus(N*kQE,3.29);
01102       Double_t gauss=tRandom->Gaus(1.*N,sqrt(1.*N));
01103       hGauss->Fill(gauss);
01104 
01105       Double_t adc=60.*gauss-(2e-7*pow(1.*gauss,4.));
01106 
01107       //apply the rail at 420
01108       if (gauss>420) adc=60*420-(2e-7*pow(420,4.));
01109 
01110       hAdc->Fill(adc);
01111     }
01112 
01113     vPe.push_back(1.*N);
01114     vAdc.push_back(hAdc->GetMean());
01115   }
01116   */
01117 
01118   //draw binomial distribution
01119   TCanvas *cBinomial=new TCanvas("cBinomial","cBinomial",1,1,1000,800);
01120   cBinomial->SetFillColor(0);
01121   cBinomial->cd();
01122   hBinomial->Draw();
01123   hGauss->Draw("sames");
01124 
01125   //draw distribution
01126   TCanvas *cAdc=new TCanvas("cAdc","cAdc",1,1,1000,800);
01127   cAdc->SetFillColor(0);
01128   cAdc->cd();
01129   hAdc->Draw();
01130 
01131   vector<Double_t> vx;
01132   vector<Double_t> vy;
01133   vector<Double_t> vStraight;
01134 
01135   for (Double_t i=0;i<300;i+=1){
01136     Double_t x=i;
01137     Double_t y=70*x-(1.3e-6*pow(x,4.));
01138 
01139     //apply the rail at 237
01140     if (x>237) y=70*237-(1.3e-6*pow(237,4.));
01141 
01142     vx.push_back(x);
01143     vy.push_back(y);
01144     vStraight.push_back(70*x);
01145 
01146   }
01147 
01148   TGraph* g=this->TGraphVect(vx,vy);
01149   TGraph* gStraight=this->TGraphVect(vx,vStraight);
01150   TGraph* gAdcVsPe=this->TGraphVect(vPe,vAdc);
01151 
01152   //draw graph
01153   TCanvas *cNonLin=new TCanvas("cNonLin","cNonLin",1,1,1000,800);
01154   cNonLin->SetFillColor(0);
01155   cNonLin->cd();
01156   g->Draw("AP");
01157   g->SetMarkerSize(1);
01158   g->SetMarkerStyle(3);
01159   g->SetMarkerColor(3);
01160   gStraight->Draw("p");
01161   gStraight->SetMarkerSize(1);
01162   gStraight->SetMarkerStyle(3);
01163   gStraight->SetMarkerColor(1);
01164   gAdcVsPe->Draw("p");
01165   gAdcVsPe->SetMarkerSize(1);
01166   gAdcVsPe->SetMarkerStyle(3);
01167   gAdcVsPe->SetMarkerColor(2);
01168   //these graphs show that the measured nonlinearity is not
01169   //the same as the actual nonlinearity near the saturation
01170   //level. But the two only differ by <1% so it shouldn't
01171   //matter too much.
01172 
01173   MSG("LIPlexMaps",Msg::kInfo) 
01174     <<" ** Finished NonLinearity method **"<<endl;
01175 }
01176 
01177 //......................................................................
01178 
01179 void LIPlexMaps::PeGen()
01180 {
01181   MSG("LIPlexMaps",Msg::kInfo) 
01182     <<" ** Running PeGen method... **"<<endl;
01183 
01185   //Theory
01187   //gain=rms**2/mean * 1/(1-p)
01188   //thus
01189   //rms=sqrt(gain*mean*(1-p))
01190   //and
01191   //npe=(mean/rms)**2 * (1-p)
01192 
01193   //use the pretty palette
01194   gStyle->SetPalette(1);
01195   //include the under and overflow counts
01196   gStyle->SetOptStat(1111111);
01197 
01198   TStopwatch stopwatch;
01199 
01200   //these two are defined
01201   const Double_t kQE=0.13;
01202   const Double_t kGain=80;
01203 
01204   //these rough numbers allow a number of photons to be derived
01205   //by specifying the roughMean
01206   //probably a bit pointless!!!
01207   Double_t roughMean=500;
01208   Double_t roughRms=fLookup.CalcRms(roughMean,kGain,kQE);
01209   Double_t roughNpe=fLookup.CalcNpe(roughMean,roughRms,kQE);
01210   
01211   //round up the number of photons
01212   Double_t tempN=-1;
01213   Double_t rem=0;
01214   rem=modf(roughNpe/kQE,&tempN);
01215   if (rem>=0.5) tempN++;
01216   
01217   //the number of photons is the number from which all others
01218   //must be derived
01219   const Int_t kN=static_cast<Int_t>(tempN);//number of photons
01220   const Double_t kNpe=kN*kQE;
01221   const Double_t kMean=kGain*kNpe;
01222   const Double_t kRms=fLookup.CalcRms(kMean,kGain,kQE);
01223   const Double_t kAdcsPerPe=kMean/kNpe;
01224 
01225   //TRandom has a periodicity of 10^8 so if you have >100 photons
01226   //then you shouldn't use more than 1e6 points in the binomial 
01227   //distribution since you will have started at the beginning of 
01228   //the list of random numbers again
01229   //not sure how this will affect things but it seems dodgy
01230   const Int_t kNumBinomPoints=static_cast<Int_t>(1e6);//1e7 is slow
01231 
01232   MSG("LIPlexMaps",Msg::kInfo) 
01233     <<endl<<"The following parameters are used in the MC:"<<endl
01234     <<"kQE="<<kQE<<endl
01235     <<"kN="<<kN<<endl
01236     <<"kMean="<<kMean<<endl
01237     <<"kRms="<<kRms<<endl
01238     <<"kGain="<<kGain<<endl
01239     <<"kNpe="<<kNpe<<endl
01240     <<"kAdcsPerPe="<<kAdcsPerPe<<endl
01241     <<"kNumBinomPoints="<<kNumBinomPoints<<endl;
01242 
01243   TH1F *hBinomial= new TH1F("hBinomial","Binomial distribution",
01244                             kN+3,-1,kN+2);
01245   hBinomial->SetFillColor(0);
01246   hBinomial->SetBit(TH1::kCanRebin);
01247 
01248   TH1F *hADC= new TH1F("hADC","hADC",15000,-1,15000);
01249   hADC->SetFillColor(0);
01250   hADC->SetBit(TH1::kCanRebin);
01251   TH1F *hADC2= new TH1F("hADC2","hADC2",15000,-1,15000);
01252   hADC2->SetFillColor(0);
01253   hADC2->SetBit(TH1::kCanRebin);
01254 
01255   vector<Double_t> vBinomial(kN+1);
01256   Double_t maxInBinomial=0;  
01257   Int_t maxInBinomialPos=0;  
01258 
01259   //create a histogram based on the binomial
01260   TRandom *tRandom=new TRandom(0);
01261   MSG("LIPlexMaps",Msg::kInfo) 
01262     <<endl<<"Generating binomial distribution..."<<endl;
01263   for (Int_t i=0;i<kNumBinomPoints;i++){
01264     //generate a binomial distribution and fill histo
01265     //this works by performing a little MC
01266     //It does N trials and see how many are below the probability p
01267     Int_t r1=tRandom->Binomial(static_cast<Int_t>(kN),
01268                                static_cast<Double_t>(kQE));
01269     hBinomial->Fill(r1);
01270     vBinomial[r1]++;
01271 
01272     //keep track of the maximum in the distribution
01273     if (vBinomial[r1]>maxInBinomial){
01274       maxInBinomial=vBinomial[r1];
01275       maxInBinomialPos=r1;
01276     }
01277 
01278     //print out loop progress
01279     Float_t fract=ceil(kNumBinomPoints/5.);
01280     if (ceil(((Float_t)i)/fract)==((Float_t)i)/fract){
01281       MSG("LIPlexMaps",Msg::kInfo) 
01282         <<"Fraction of loop complete: "<<i 
01283         <<"/"<<kNumBinomPoints<<"  ("
01284         <<(Int_t)(100.*i/kNumBinomPoints)<<"%)"<<endl;
01285     }    
01286   }
01287   MSG("LIPlexMaps",Msg::kInfo) 
01288     <<"Binomial distribution done"<<endl;
01289 
01290   //draw binomial distribution
01291   TCanvas *cBinomial=new TCanvas("cBinomial","cBinomial",1,1,1000,800);
01292   cBinomial->SetFillColor(0);
01293   cBinomial->cd();
01294   hBinomial->Draw();
01295 
01296   //scale the binomial by the max
01297   this->ScaleVector(vBinomial,1/maxInBinomial);
01298 
01299   //fill a histogram that will look like the adc distribution
01300   //you would get from the binomial distribution above
01301   for (Int_t i=0;i<2500;i++){
01302     MSG("LIPlexMaps",Msg::kVerbose)<<"i="<<i<<endl;
01303     hADC->Fill(kAdcsPerPe*hBinomial->GetRandom());
01304     Int_t npe=this->SampleDist(vBinomial,tRandom);
01305     hADC2->Fill(kAdcsPerPe*npe);
01306   }
01307 
01308   //draw the adc distribution you would expect from the binomial above
01309   TCanvas *cAdc=new TCanvas("cAdc","cAdc",1,1,1000,800);
01310   cAdc->SetFillColor(0);
01311   cAdc->Divide(2,1);
01312   cAdc->cd(1);
01313   hADC->Draw();
01314   cAdc->cd(2);
01315   hADC2->Draw();
01316 
01317   const Int_t kNumPoints=20;
01318   const Int_t kFlashes=500; 
01319   Double_t *numFlashes=new Double_t[kNumPoints];
01320 
01321   MSG("LIPlexMaps",Msg::kInfo)
01322     <<endl<<"Calculating errors analytically"<<endl;
01323   //analytically
01324   for (Int_t j=0;j<kNumPoints;j++){
01325     numFlashes[j]=static_cast<Double_t>((j+1)*kFlashes);
01326     MSG("LIPlexMaps",Msg::kInfo)
01327       <<endl<<"Point "<<j+1<<"/"<<kNumPoints
01328       <<", numFlashes="<<numFlashes[j]<<endl;
01329 
01330     //calcualte and print out the errors analytically
01331     //error on mean = rms/sqrt(NumFlashes)
01332     MSG("LIPlexMaps",Msg::kInfo)
01333       <<"Mean="<<kMean<<", rms="<<kRms
01334       <<", N="<<numFlashes[j]
01335       <<", Errors: eMean="<<kRms/sqrt(numFlashes[j])
01336       <<" ("<<((kRms/sqrt(numFlashes[j]))/kMean)*100<<"%)"
01337       <<", eRms="<<kRms/sqrt(numFlashes[j])
01338       <<" ("<<(1/sqrt(numFlashes[j]))*100<<"%)"
01339       <<", eGain="
01340       <<"("<<((1/sqrt(numFlashes[j]))*2+
01341               (kRms/sqrt(numFlashes[j]))/kMean)*100<<"%)"
01342       <<" quad="
01343       <<"("<<sqrt((1/numFlashes[j])*2+
01344                   pow((kRms/sqrt(numFlashes[j]))/kMean,2))*100<<"%)"
01345       <<endl;      
01346   }
01347 
01348   Double_t *mean=new Double_t[kNumPoints*kFlashes];
01349   Double_t *rms=new Double_t[kNumPoints*kFlashes];
01350   Double_t *gain=new Double_t[kNumPoints*kFlashes];
01351   Double_t *xAxis=new Double_t[kNumPoints*kFlashes];
01352 
01353   Double_t *rmsOfMean=new Double_t[kNumPoints];
01354   Double_t *rmsOfGain=new Double_t[kNumPoints];
01355   Double_t *rmsOfRms=new Double_t[kNumPoints];
01356   Double_t *errorOnMean=new Double_t[kNumPoints];
01357   Double_t *errorOnGain=new Double_t[kNumPoints];
01358   Double_t *errorOnRms=new Double_t[kNumPoints];
01359   Double_t *errorOnMeanN=new Double_t[kNumPoints];
01360   Double_t *errorOnGainN=new Double_t[kNumPoints];
01361   Double_t *errorOnRmsN=new Double_t[kNumPoints];
01362 
01363   const Int_t kNumLiRuns=1000;
01364 
01365   MSG("LIPlexMaps",Msg::kInfo)
01366     <<endl<<"Calculating errors by MC"<<endl;
01367   //MC
01368   for (Int_t j=0;j<kNumPoints;j++){
01369     numFlashes[j]=static_cast<Double_t>((j+1)*kFlashes);
01370     MSG("LIPlexMaps",Msg::kInfo)
01371       <<endl<<"Point "<<j+1<<"/"<<kNumPoints
01372       <<", numFlashes="<<numFlashes[j]<<endl;
01373     
01374     stopwatch.Start();
01375     
01376     //take many "runs"
01377     for (Int_t k=0;k<kNumLiRuns;k++){
01378       hADC->Reset();
01379       for (Int_t i=0;i<(j+1)*kFlashes;i++){
01380         //hADC->Fill(kAdcsPerPe*hBinomial->GetRandom());
01381         hADC->Fill(kAdcsPerPe*this->SampleDist(vBinomial,tRandom));
01382       }
01383       mean[k]=hADC->GetMean();
01384       rms[k]=hADC->GetRMS();
01385       gain[k]=fLookup.CalcGain(mean[k],rms[k],kQE);
01386       xAxis[k]=static_cast<Double_t>(k);
01387       rmsOfMean[j]+=pow(kMean-mean[k],2);
01388       rmsOfGain[j]+=pow(kGain-gain[k],2);
01389       rmsOfRms[j]+=pow(kRms-rms[k],2);
01390     }
01391     
01392     stopwatch.Stop();
01393     MSG("LIPlexMaps",Msg::kInfo)
01394       <<"Time elapsed, real="<<stopwatch.RealTime()
01395       <<", cpu="<<stopwatch.CpuTime()
01396       <<endl;
01397     
01398     //final step in rms calculation
01399     rmsOfMean[j]=sqrt(rmsOfMean[j]/kNumLiRuns);
01400     rmsOfGain[j]=sqrt(rmsOfGain[j]/kNumLiRuns);
01401     rmsOfRms[j]=sqrt(rmsOfRms[j]/kNumLiRuns);
01402     
01403     //don't do sqrt of numLiRuns because you don't want
01404     //the error on the gain if you take 1000 runs
01405     //but rather the error on each individual run!!!
01406     errorOnMean[j]=rmsOfMean[j]/sqrt(1.);
01407     errorOnGain[j]=rmsOfGain[j]/sqrt(1.);
01408     errorOnRms[j]=rmsOfRms[j]/sqrt(1.);
01409 
01410     //calcualte fractional errors
01411     errorOnMeanN[j]=errorOnMean[j]/kMean;
01412     errorOnGainN[j]=errorOnGain[j]/kGain;
01413     errorOnRmsN[j]=errorOnRms[j]/kRms;
01414     
01415     MSG("LIPlexMaps",Msg::kInfo)
01416       <<"Errors: eMean="<<errorOnMean[j]
01417       <<" ("<<errorOnMeanN[j]*100<<"%)"
01418       <<", eGain="<<errorOnGain[j]
01419       <<" ("<<errorOnGainN[j]*100<<"%)"
01420       <<", eRms="<<errorOnRms[j]
01421       <<" ("<<errorOnRmsN[j]*100<<"%)"
01422       <<endl;
01423   }
01424 
01425   //
01426   TCanvas *cGain=new TCanvas("cGain","cGain",1,1,1000,800);
01427   cGain->SetFillColor(0);
01428   cGain->Divide(1,2);
01429 
01430   TGraph *gGain=new TGraph(kNumLiRuns,xAxis,gain);
01431   gGain->SetTitle("Gain Vs 'run'");
01432   gGain->SetMarkerStyle(3);
01433   gGain->SetMarkerColor(2);
01434   gGain->SetMarkerSize(0.4);
01435   cGain->cd(1);
01436   gGain->Draw("AP");
01437   gGain->GetXaxis()->SetTitle("'run' number");
01438   gGain->GetYaxis()->SetTitle("Gain");
01439   gGain->GetXaxis()->CenterTitle();
01440   gGain->GetYaxis()->CenterTitle();
01441 
01442   TGraph *gMean=new TGraph(kNumLiRuns,xAxis,mean);
01443   gMean->SetTitle("Mean Vs 'run'");
01444   gMean->SetMarkerStyle(3);
01445   gMean->SetMarkerColor(2);
01446   gMean->SetMarkerSize(0.4);
01447   cGain->cd(2);
01448   gMean->Draw("AP");
01449   gMean->GetXaxis()->SetTitle("'run' number");
01450   gMean->GetYaxis()->SetTitle("Mean");
01451   gMean->GetXaxis()->CenterTitle();
01452   gMean->GetYaxis()->CenterTitle();
01453 
01455   //plot the errors on the gain
01457   //create canvas
01458   TCanvas *cGainError=new TCanvas("cGainError","cGainError",
01459                                   1,1,1000,800);
01460   cGainError->SetFillColor(0);
01461   cGainError->Divide(1,2);
01462   
01463   //create graph
01464   TGraph *gGainErrorNormVsFlashes=new TGraph(kNumPoints,
01465                                              numFlashes,errorOnGainN);
01466   gGainErrorNormVsFlashes->SetTitle
01467     ("Fractional Error on Gain Vs Flashes");
01468   gGainErrorNormVsFlashes->SetMarkerStyle(3);
01469   gGainErrorNormVsFlashes->SetMarkerColor(2);
01470   gGainErrorNormVsFlashes->SetMarkerSize(0.2);
01471   cGainError->cd(1);
01472   gGainErrorNormVsFlashes->Draw("AP");
01473   gGainErrorNormVsFlashes->GetXaxis()->SetTitle("Number of Flashes");
01474   gGainErrorNormVsFlashes->GetYaxis()->SetTitle
01475     ("Fractional Error on Gain");
01476   gGainErrorNormVsFlashes->GetXaxis()->CenterTitle();
01477   gGainErrorNormVsFlashes->GetYaxis()->CenterTitle();
01478   gGainErrorNormVsFlashes->SetMinimum(0);
01479 
01480   //create graph
01481   TGraph *gGainErrorVsFlashes=new TGraph(kNumPoints,
01482                                          numFlashes,errorOnGain);
01483   gGainErrorVsFlashes->SetTitle("Error on Gain Vs Flashes");
01484   gGainErrorVsFlashes->SetMarkerStyle(3);
01485   gGainErrorVsFlashes->SetMarkerColor(2);
01486   gGainErrorVsFlashes->SetMarkerSize(0.2);
01487   cGainError->cd(2);
01488   gGainErrorVsFlashes->Draw("AP");
01489   gGainErrorVsFlashes->GetXaxis()->SetTitle("Number of Flashes");
01490   gGainErrorVsFlashes->GetYaxis()->SetTitle("Error on Gain");
01491   gGainErrorVsFlashes->GetXaxis()->CenterTitle();
01492   gGainErrorVsFlashes->GetYaxis()->CenterTitle();
01493 
01495   //plot the errors on the mean
01497   //create canvas
01498   TCanvas *cGainMean=new TCanvas("cGainMean","cGainMean",1,1,1000,800);
01499   cGainMean->SetFillColor(0);
01500   cGainMean->Divide(1,2);
01501   
01502   //create graph
01503   TGraph *gMeanErrorNormVsFlashes=new TGraph(kNumPoints,
01504                                              numFlashes,errorOnMeanN);
01505   gMeanErrorNormVsFlashes->SetTitle
01506     ("Fractional Error on Mean Vs Flashes");
01507   gMeanErrorNormVsFlashes->SetMarkerStyle(3);
01508   gMeanErrorNormVsFlashes->SetMarkerColor(2);
01509   gMeanErrorNormVsFlashes->SetMarkerSize(0.2);
01510   cGainMean->cd(1);
01511   gMeanErrorNormVsFlashes->Draw("AP");
01512   gMeanErrorNormVsFlashes->GetXaxis()->SetTitle("Number of Flashes");
01513   gMeanErrorNormVsFlashes->GetYaxis()->SetTitle
01514     ("Fractional Error on Mean");
01515   gMeanErrorNormVsFlashes->GetXaxis()->CenterTitle();
01516   gMeanErrorNormVsFlashes->GetYaxis()->CenterTitle();
01517   gMeanErrorNormVsFlashes->SetMinimum(0);
01518 
01519   //create graph
01520   TGraph *gMeanErrorVsFlashes=new TGraph(kNumPoints,
01521                                          numFlashes,errorOnMean);
01522   gMeanErrorVsFlashes->SetTitle("Error on Mean Vs Flashes");
01523   gMeanErrorVsFlashes->SetMarkerStyle(3);
01524   gMeanErrorVsFlashes->SetMarkerColor(2);
01525   gMeanErrorVsFlashes->SetMarkerSize(0.2);
01526   cGainMean->cd(2);
01527   gMeanErrorVsFlashes->Draw("AP");
01528   gMeanErrorVsFlashes->GetXaxis()->SetTitle("Number of Flashes");
01529   gMeanErrorVsFlashes->GetYaxis()->SetTitle("Error on Mean");
01530   gMeanErrorVsFlashes->GetXaxis()->CenterTitle();
01531   gMeanErrorVsFlashes->GetYaxis()->CenterTitle();
01532 
01534   //plot the errors on the rms
01536   //create canvas
01537   TCanvas *cRmsErr=new TCanvas("cRmsErr","cRmsErr",1,1,1000,800);
01538   cRmsErr->SetFillColor(0);
01539   cRmsErr->Divide(1,2);
01540   
01541   //create graph
01542   TGraph *gRmsErrorNormVsFlashes=new TGraph(kNumPoints,
01543                                              numFlashes,errorOnRmsN);
01544   gRmsErrorNormVsFlashes->SetTitle
01545     ("Fractional Error on Rms Vs Flashes");
01546   gRmsErrorNormVsFlashes->SetMarkerStyle(3);
01547   gRmsErrorNormVsFlashes->SetMarkerColor(2);
01548   gRmsErrorNormVsFlashes->SetMarkerSize(0.2);
01549   cRmsErr->cd(1);
01550   gRmsErrorNormVsFlashes->Draw("AP");
01551   gRmsErrorNormVsFlashes->GetXaxis()->SetTitle("Number of Flashes");
01552   gRmsErrorNormVsFlashes->GetYaxis()->SetTitle
01553     ("Fractional Error on Rms");
01554   gRmsErrorNormVsFlashes->GetXaxis()->CenterTitle();
01555   gRmsErrorNormVsFlashes->GetYaxis()->CenterTitle();
01556   gRmsErrorNormVsFlashes->SetMinimum(0);
01557 
01558   //create graph
01559   TGraph *gRmsErrorVsFlashes=new TGraph(kNumPoints,
01560                                          numFlashes,errorOnRms);
01561   gRmsErrorVsFlashes->SetTitle("Error on Rms Vs Flashes");
01562   gRmsErrorVsFlashes->SetMarkerStyle(3);
01563   gRmsErrorVsFlashes->SetMarkerColor(2);
01564   gRmsErrorVsFlashes->SetMarkerSize(0.2);
01565   cRmsErr->cd(2);
01566   gRmsErrorVsFlashes->Draw("AP");
01567   gRmsErrorVsFlashes->GetXaxis()->SetTitle("Number of Flashes");
01568   gRmsErrorVsFlashes->GetYaxis()->SetTitle("Error on Rms");
01569   gRmsErrorVsFlashes->GetXaxis()->CenterTitle();
01570   gRmsErrorVsFlashes->GetYaxis()->CenterTitle();
01571 
01572   /*
01573   // get a random energy value between 0-40 GeV
01574   enNeutrino=(Float_t)(gRandom->Rndm())*39.99;
01575   enNeutrinoBin=(Int_t)(enNeutrino*5.+1.);
01576   enNeutrinoProb=leevents[enNeutrinoBin]; 
01577 
01578       if ((Float_t)(gRandom->Rndm())<=enNeutrinoProb){
01579 
01580         // get a random y value between 0-1 
01581         yValue=(Float_t)(gRandom->Rndm())*0.99999999;
01582         
01583         // determine the energy range  
01584         yEnergyRange=(Int_t)(enNeutrino/5.);
01585         if (yEnergyRange>5) {yEnergyRange=5;}
01586         
01587         // select y value prob from suitable y 
01588         //distribution given the energy range
01589         yValueProb=ydist[yEnergyRange*10+(Int_t)(yValue*10.)];
01590         
01591         if ((Float_t)(gRandom->Rndm())<=yValueProb){
01592           eventSelectedFlag=1;
01593           neutrinoEnergy[i]=enNeutrino;
01594           
01595           neutrinoEn=enNeutrino;
01596           if (neutrinoEn>29.9999999){neutrinoEn=29.999999;}
01597 
01598           muEffProb[i]=mueff[((Int_t)(yValue*10.)*30)+
01599                             (Int_t)(neutrinoEn)];
01600           ncEffProb[i]=nceff[((Int_t)(yValue*10.)*30)+
01601                             (Int_t)(neutrinoEn)];
01602           
01603           eHadSmeared[i]=(yValue*enNeutrino)*
01604             (1.+0.55*(gRandom->Gaus(0.,1.))/
01605              sqrt(yValue*enNeutrino));
01606           if (eHadSmeared[i]<0.) {(eHadSmeared[i]=0.);}
01607         
01608           eMuSmeared=((1-yValue)*enNeutrino)*
01609             (1+0.11*(gRandom->Gaus(0.,1.)));
01610           reconEnergy[i]=eHadSmeared[i]+eMuSmeared;
01611           //Double_t Gaus(Double_t mean, Double_t sigma) 
01612         } //end of if 
01613       } //end of if
01614     } //end of while
01615   } //end of for
01616   */
01617 
01618   MSG("LIPlexMaps",Msg::kInfo)
01619     <<" ** Finished the PeGen method ** "<<endl;
01620 }
01621 
01622 //......................................................................
01623 
01624 void LIPlexMaps::LIErrors()
01625 {
01626   MSG("LIPlexMaps",Msg::kInfo) 
01627     <<" ** Running LIErrors method... **"<<endl;
01628 
01629   //use the pretty palette
01630   gStyle->SetPalette(1);
01631   //include the under and overflow counts
01632   gStyle->SetOptStat(1111111);
01633 
01634   //these two are defined
01635   const Double_t kQE=0.13;
01636   const Double_t kGain=80;
01637 
01638   const Int_t kNumPoints=50;  
01639 
01640   TGraph *gGainErrorNormVsMean=new TGraph(kNumPoints);
01641   TGraph *gMeanErrorNormVsMean=new TGraph(kNumPoints);
01642   TGraph *gRmsErrorNormVsMean=new TGraph(kNumPoints);
01643 
01644   for (Int_t i=0;i<kNumPoints;i++){
01645 
01646     //these rough numbers allow a number of photons to be derived
01647     //by specifying the roughMean
01648     //probably a bit pointless!!!
01649     Double_t roughMean=200*(i+1);
01650     Double_t roughRms=fLookup.CalcRms(roughMean,kGain,kQE);
01651     Double_t roughNpe=fLookup.CalcNpe(roughMean,roughRms,kQE);
01652     
01653     //round up the number of photons
01654     Double_t tempN=-1;
01655     Double_t rem=0;
01656     rem=modf(roughNpe/kQE,&tempN);
01657     if (rem>=0.5) tempN++;
01658     
01659     //the number of photons is the number from which all others
01660     //must be derived
01661     const Int_t kN=static_cast<Int_t>(tempN);//number of photons
01662     const Double_t kNpe=kN*kQE;
01663     const Double_t kMean=kGain*kNpe;
01664     const Double_t kRms=fLookup.CalcRms(kMean,kGain,kQE);
01665     const Double_t kAdcsPerPe=kMean/kNpe;
01666     
01667     MSG("LIPlexMaps",Msg::kInfo) 
01668       <<endl<<"The following parameters are used in the MC:"<<endl
01669       <<"kQE="<<kQE<<endl
01670       <<"kN="<<kN<<endl
01671       <<"kMean="<<kMean<<endl
01672       <<"kRms="<<kRms<<endl
01673       <<"kGain="<<kGain<<endl
01674       <<"kNpe="<<kNpe<<endl
01675       <<"kAdcsPerPe="<<kAdcsPerPe<<endl;
01676 
01677     Double_t numFlashes=1000;    
01678     Double_t errorOnMeanN=-1;
01679     Double_t errorOnGainN=-1;
01680     Double_t errorOnRmsN=-1;
01681     
01682     //calcualte the errors analytically
01683     //error on mean (and rms) = rms/sqrt(NumFlashes)
01684       
01685     //calcualte fractional errors
01686     errorOnMeanN=(kRms/sqrt(numFlashes))/kMean;
01687     errorOnRmsN=1/sqrt(numFlashes);
01688     errorOnGainN=sqrt(pow(errorOnRmsN,2)*2+
01689                          pow(errorOnMeanN,2));
01690     
01691     MSG("LIPlexMaps",Msg::kInfo)
01692       <<"Mean="<<kMean<<", rms="<<kRms
01693       <<", N="<<numFlashes
01694       <<", Errors: eMean="
01695       <<"("<<errorOnMeanN*100<<"%)"
01696       <<", eRms="
01697       <<"("<<errorOnRmsN*100<<"%)"
01698       <<", eGain="<<"("<<errorOnGainN*100<<"%)"
01699       <<endl;      
01700     
01701     gGainErrorNormVsMean->SetPoint(i,kMean,errorOnGainN);
01702     gMeanErrorNormVsMean->SetPoint(i,kMean,errorOnMeanN);
01703     gRmsErrorNormVsMean->SetPoint(i,kMean,errorOnRmsN);
01704   }
01705     
01707   //plot the errors on the gain
01709   //create canvas
01710   TCanvas *cGainErrorVsMean=new TCanvas("cGainErrorVsMean",
01711                                         "cGainErrorVsMean",
01712                                         1,1,1000,800);
01713   cGainErrorVsMean->SetFillColor(0);
01714     
01715   gGainErrorNormVsMean->SetTitle("Fractional Error on Gain Vs Mean");
01716   gGainErrorNormVsMean->SetMarkerStyle(3);
01717   gGainErrorNormVsMean->SetMarkerColor(2);
01718   gGainErrorNormVsMean->SetMarkerSize(0.2);
01719   cGainErrorVsMean->cd(1);
01720   gGainErrorNormVsMean->Draw("AP");
01721   gGainErrorNormVsMean->GetXaxis()->SetTitle("Mean");
01722   gGainErrorNormVsMean->GetYaxis()->SetTitle
01723     ("Fractional Error on Gain");
01724   gGainErrorNormVsMean->GetXaxis()->CenterTitle();
01725   gGainErrorNormVsMean->GetYaxis()->CenterTitle();
01726   gGainErrorNormVsMean->SetMinimum(0);
01727     
01729   //plot the errors on the mean
01731   //create canvas
01732   TCanvas *cMeanErrorVsMean=new TCanvas("cMeanErrorVsMean",
01733                                         "cMeanErrorVsMean",
01734                                         1,1,1000,800);
01735   cMeanErrorVsMean->SetFillColor(0);
01736 
01737   gMeanErrorNormVsMean->SetTitle("Fractional Error on Mean Vs Mean");
01738   gMeanErrorNormVsMean->SetMarkerStyle(3);
01739   gMeanErrorNormVsMean->SetMarkerColor(2);
01740   gMeanErrorNormVsMean->SetMarkerSize(0.2);
01741   cMeanErrorVsMean->cd(1);
01742   gMeanErrorNormVsMean->Draw("AP");
01743   gMeanErrorNormVsMean->GetXaxis()->SetTitle("Mean");
01744   gMeanErrorNormVsMean->GetYaxis()->SetTitle
01745     ("Fractional Error on Mean");
01746   gMeanErrorNormVsMean->GetXaxis()->CenterTitle();
01747   gMeanErrorNormVsMean->GetYaxis()->CenterTitle();
01748   gMeanErrorNormVsMean->SetMinimum(0);
01749     
01751   //plot the errors on the rms
01753   //create canvas
01754   TCanvas *cRmsErrVsMean=new TCanvas("cRmsErrVsMean","cRmsErrVsMean",
01755                                      1,1,1000,800);
01756   cRmsErrVsMean->SetFillColor(0);
01757 
01758   gRmsErrorNormVsMean->SetTitle
01759     ("Fractional Error on Rms Vs Mean");
01760   gRmsErrorNormVsMean->SetMarkerStyle(3);
01761   gRmsErrorNormVsMean->SetMarkerColor(2);
01762   gRmsErrorNormVsMean->SetMarkerSize(0.2);
01763   cRmsErrVsMean->cd(1);
01764   gRmsErrorNormVsMean->Draw("AP");
01765   gRmsErrorNormVsMean->GetXaxis()->SetTitle("Mean");
01766   gRmsErrorNormVsMean->GetYaxis()->SetTitle
01767     ("Fractional Error on Rms");
01768   gRmsErrorNormVsMean->GetXaxis()->CenterTitle();
01769   gRmsErrorNormVsMean->GetYaxis()->CenterTitle();
01770   gRmsErrorNormVsMean->SetMinimum(0);
01771   
01772   MSG("LIPlexMaps",Msg::kInfo)
01773     <<" ** Finished the LIErrors method ** "<<endl;
01774 }
01775         
01776 //......................................................................
01777 
01778 void LIPlexMaps::PlotPlexPinMap()
01779 {
01780   MSG("LIAnalysis",Msg::kInfo) 
01781     <<"Running PlotPlexPinMap method..."<<endl;
01782 
01783   //commented out whole method to prevent array warnings!!!
01784   //should use an object or something instead, no time at the mo
01785 
01786   /*    
01787   //set validity context to todays date and far detector and real data
01788   VldTimeStamp timeStamp(2002,10,1,1,1,1,1,0,0);
01789   VldContext validityContext(DetectorType::kFar,SimFlag::kData,
01790                              timeStamp);
01791 
01792   MSG("LIAnalysis",Msg::kInfo) 
01793     <<"Using validity context: "<<validityContext.AsString()<<endl;
01794 
01795   PlexHandle *myplexhandle= new PlexHandle(validityContext);   
01796 
01797   Float_t numMux=8.;
01798   Float_t numRacks=16.;
01799   const Int_t const_numCrates=static_cast<Int_t>(numRacks/2.);
01800 
01801   const Int_t const_numEastWest=2;
01802   const Int_t const_numRackLevels=2;
01803   const Int_t const_numRacks=static_cast<Int_t>(numRacks);
01804   const Int_t const_numMux=static_cast<Int_t>(numMux);
01805   const Int_t const_numPins=2;
01806   const Int_t const_numGains=2;
01807 
01808   //declare arrays
01809   Int_t pinPulserBox[const_numEastWest][const_numRackLevels]
01810     [const_numRacks][const_numMux][const_numPins][const_numGains];
01811 
01812   Int_t pinLed[const_numEastWest][const_numRackLevels]
01813     [const_numRacks][const_numMux][const_numPins][const_numGains];
01814 
01815   Int_t pinNumEntries[const_numEastWest][const_numRackLevels]
01816     [const_numRacks][const_numMux][const_numPins][const_numGains];
01817 
01818   Int_t pinVaChip[const_numEastWest][const_numRackLevels]
01819     [const_numRacks][const_numMux][const_numPins][const_numGains];
01820 
01821   //initialise arrays
01822   for (Int_t i=0; i<const_numEastWest; i++){
01823     for (Int_t j=0; j<const_numRackLevels; j++){
01824       for (Int_t k=0; k<const_numRacks;k++){
01825         for (Int_t l=0; l<const_numMux;l++){
01826           for (Int_t m=0; m<const_numPins;m++){
01827             for (Int_t n=0; n<const_numGains;n++){
01828               pinPulserBox[i][j][k][l][m][n]=-1;
01829               pinLed[i][j][k][l][m][n]=-1;
01830               pinNumEntries[i][j][k][l][m][n]=0;
01831               pinVaChip[i][j][k][l][m][n]=-1;
01832             }
01833           }
01834         }
01835       }
01836     }
01837   }
01838   
01839   //variables 
01840   Char_t eastWest='!'; //E=0 and W=1
01841   Char_t rackLevel='!';//L=0 and U=1
01842   UInt_t rackBay=0; 
01843   UInt_t inRack=0;
01844   UInt_t inBox=0;
01845   UInt_t gain=0;
01846 
01847   //loop over every possible combination of variables
01848   for (Int_t iEastWest=0;iEastWest<const_numEastWest;iEastWest++){
01849     //convert integers into characters
01850     //E=0 and W=1
01851     if (iEastWest==0){
01852       eastWest='E';
01853     }
01854     else if (iEastWest==1){
01855       eastWest='W';
01856     }
01857     
01858     for (Int_t iRackLevel=0;iRackLevel<const_numRackLevels;
01859          iRackLevel++){
01860       //convert integers into characters
01861       //L=0 and U=1
01862       if (iRackLevel==1){
01863         rackLevel='U';
01864       }
01865       else if (iRackLevel==0){
01866         rackLevel='L';
01867       }
01868       
01869       for (rackBay=0;rackBay<static_cast<UInt_t>(const_numRacks);
01870            rackBay++){
01871         for (inRack=0;inRack<static_cast<UInt_t>(const_numMux);
01872              inRack++){
01873           for (inBox=0;inBox<static_cast<UInt_t>(const_numPins);
01874                inBox++){
01875             for (gain=0;gain<static_cast<UInt_t>(const_numPins);gain++){
01876             
01877               //create a pindiodeId according to 
01878               //loop iteration variables
01879               const PlexPinDiodeId *plexPinId =new PlexPinDiodeId
01880                 (DetectorType::kFar,ElecType::kVA,eastWest,rackLevel,
01881                  rackBay+1,inRack,inBox,gain); 
01882               
01883               //check if pindiodeid is valid
01884               //if not then print to screen and go to next iteration
01885               if (plexPinId->IsValid()){
01886                 
01887                 PlexLedId plexLedId=myplexhandle->GetLedId(*plexPinId);
01888                 
01889                 RawChannelId plexRawChId=myplexhandle->
01890                   GetRawChannelId(*plexPinId);
01891                 
01892                 //get va chip associated with rawchannel
01893                 pinVaChip[iEastWest][iRackLevel][rackBay][inRack]
01894                   [inBox][gain]=plexRawChId.GetVaChip();
01895 
01896                 //only set array values is ledid is valid
01897                 //else leave initial values, e.g. led=-1
01898                 if (plexLedId.IsValid()){
01899                   //get LED info
01900                   Int_t plexLedInBox=plexLedId.GetLedInBox();
01901                   Int_t plexPulserBox=plexLedId.GetPulserBox();
01902                   
01903                   pinLed[iEastWest][iRackLevel][rackBay][inRack]
01904                     [inBox][gain]=plexLedInBox;
01905 
01906                   pinPulserBox[iEastWest][iRackLevel][rackBay][inRack]
01907                     [inBox][gain]=plexPulserBox;
01908 
01909                   pinNumEntries[iEastWest][iRackLevel][rackBay][inRack]
01910                     [inBox][gain]++;
01911 
01912                   MSG("LIAnalysis",Msg::kVerbose) 
01913                     <<"plexLedInBox="<<plexLedInBox
01914                     <<", plexPulserBox="<<plexPulserBox
01915                     <<endl;
01916                   MSG("LIAnalysis",Msg::kVerbose) 
01917                     <<"plexLedId="<<plexLedId.AsString() 
01918                     <<endl;
01919                 }
01920                 else{
01921                   MSG("LIAnalysis",Msg::kVerbose) 
01922                     <<"ledId not valid:"
01923                     <<" plexLedId="<<plexLedId.AsString() 
01924                     <<endl
01925                     <<"plexPinId="<<plexPinId->AsString() 
01926                     <<endl;
01927                 }
01928               }
01929               else{
01930                 MSG("LIAnalysis",Msg::kVerbose) 
01931                   <<"pinId not valid:"
01932                   <<" plexPinId="<<plexPinId->AsString()<<endl;
01933               }
01934               delete plexPinId;
01935             }//end of for
01936           }//end of for
01937         }//end of for
01938       }//end of for
01939     }//end of for
01940   }//end of for
01941 
01942   TCanvas *cEast=new TCanvas("cEast","cEast",0,0,1200,800);
01943   cEast->SetFillColor(0);
01944 
01945   TCanvas *cWest=new TCanvas("cWest","cWest",0,0,1200,800);
01946   cWest->SetFillColor(0);
01947   cWest->cd();
01948 
01949   TText *titleE = new TText(0.28,0.955,
01950                             "Plex PIN Diode Map (East Side)");
01951   titleE->SetTextSize(0.045);
01952   TText *titleW = new TText(0.28,0.955,
01953                             "Plex PIN Diode Map (West Side)");
01954   titleW->SetTextSize(0.045);
01955   cEast->cd();
01956   titleE->Draw();
01957   cWest->cd();
01958   titleW->Draw();
01959 
01960   TPaveText *info=new TPaveText(0.75,0.94,1.0,1.0);
01961   info->SetBorderSize(0);
01962   info->SetFillColor(0);
01963   info->SetTextSize(0.018);
01964   info->SetTextColor(4);
01965   info->AddText("Numbers in mux boxes are LED numbers"); 
01966   info->AddText("Dark colour number is high gain pin");
01967   info->AddText("Mux box shading indicates Pulser Box"); 
01968   cEast->cd();
01969   info->Draw();
01970   cWest->cd();
01971   info->Draw();
01972   
01973   TPad *levelUE= new TPad("levelUE","pad for mux boxes",
01974                           0.01,0.59,0.99,0.94);
01975   TPad *levelME= new TPad("levelME","pad for crates",
01976                           0.01,0.39,0.99,0.56);
01977   TPad *levelLE= new TPad("levelLE","pad for mux boxes",
01978                           0.01,0.01,0.99,0.36);
01979   TPad *levelUW= new TPad("levelUW","pad for mux boxes",
01980                           0.01,0.59,0.99,0.94);
01981   TPad *levelMW= new TPad("levelMW","pad for crates",
01982                           0.01,0.39,0.99,0.56);
01983   TPad *levelLW= new TPad("levelLW","pad for mux boxes",
01984                           0.01,0.01,0.99,0.36);
01985 
01986   levelUE->SetFillColor(11);
01987   levelUE->SetBorderSize(3);
01988   levelUW->SetFillColor(11);
01989   levelUW->SetBorderSize(3);
01990 
01991   levelME->SetFillColor(11);
01992   levelME->SetBorderSize(2);
01993   levelMW->SetFillColor(11);
01994   levelMW->SetBorderSize(2);
01995 
01996   levelLE->SetFillColor(11);
01997   levelLE->SetBorderSize(1);
01998   levelLE->SetBorderMode(0);
01999   levelLW->SetFillColor(11);
02000   levelLW->SetBorderSize(1);
02001   levelLW->SetBorderMode(0);
02002 
02003   cEast->cd();
02004   levelUE->Draw();
02005   levelME->Draw();
02006   levelLE->Draw();
02007   cWest->cd();
02008   levelUW->Draw();
02009   levelMW->Draw();
02010   levelLW->Draw();
02011 
02012   
02013   TText *tLevelUE = new TText(0.01,0.89,
02014                               "Mux Box Racks (East Side, Upper Level)");
02015   TText *tLevelUW = new TText(0.01,0.89,
02016                               "Mux Box Racks (West Side, Upper Level)");
02017   TText *tLevelME = new TText
02018     (0.01,0.89,"Electronics Crates (East Side, Middle Level)");
02019   TText *tLevelMW = new TText
02020     (0.01,0.89,"Electronics Crates (West Side, Middle Level)");
02021   TText *tLevelLE = new TText(0.01,0.89,
02022                               "Mux Box Racks (East Side, Lower Level)");
02023   TText *tLevelLW = new TText(0.01,0.89,
02024                               "Mux Box Racks (West Side, Lower Level)");
02025 
02026   tLevelUE->SetTextSize(0.1);
02027   tLevelUW->SetTextSize(0.1);
02028   tLevelME->SetTextSize(0.08);
02029   tLevelMW->SetTextSize(0.08);
02030   tLevelLE->SetTextSize(0.1);
02031   tLevelLW->SetTextSize(0.1);
02032 
02033   levelUE->cd();
02034   tLevelUE->Draw();
02035   levelUW->cd();
02036   tLevelUW->Draw();
02037 
02038   levelME->cd();
02039   tLevelME->Draw();
02040   levelMW->cd();
02041   tLevelMW->Draw();
02042   
02043   levelLE->cd();
02044   tLevelLE->Draw();
02045   levelLW->cd();
02046   tLevelLW->Draw();
02047   
02048   Float_t rackSpace=0.07/(numRacks+1.);
02049   Float_t crateSpace=3.0*rackSpace;
02050   Float_t rackWidth=(1.-((numRacks/2)+2)*rackSpace-
02051                      ((numRacks/2)-1)*crateSpace)/numRacks;
02052   Float_t xMin=-1.;
02053   MSG("LIAnalysis",Msg::kDebug) 
02054     <<"rackSpace="<<rackSpace<<", crateSpace="<<crateSpace
02055     <<", rackWidth="<<rackWidth<<endl;
02056 
02057   TPad **rackUE=0;
02058   TPad **rackUW=0;
02059   TPad **rackLE=0;
02060   TPad **rackLW=0;
02061   
02062   rackUE=new TPad*[const_numRacks];
02063   rackUW=new TPad*[const_numRacks];
02064   rackLE=new TPad*[const_numRacks];
02065   rackLW=new TPad*[const_numRacks];
02066 
02067   for (Int_t rack=0;rack<const_numRacks;rack++){
02068     Float_t crate=floor(static_cast<Float_t>(rack)/2.);
02069     
02070     xMin=rackSpace
02071       +floor((static_cast<Float_t>(rack)+1)/2)*rackSpace
02072       +crate*crateSpace
02073       +static_cast<Float_t>(rack)*rackWidth;
02074     
02075     rackUE[rack]= new TPad("rackUE","Upper East Racks",
02076                            xMin,0.,xMin+rackWidth,0.87,17,3);
02077     rackUW[rack]= new TPad("rackUW","Upper West Racks",
02078                            xMin,0.,xMin+rackWidth,0.87,17,3);
02079     rackLE[rack]= new TPad("rackLE","Lower East Racks",
02080                            xMin,0.,xMin+rackWidth,0.87,17,3);
02081     rackLW[rack]= new TPad("rackLW","Lower West Racks",
02082                            xMin,0.,xMin+rackWidth,0.87,17,3);
02083 
02084 
02085     rackUE[rack]->SetFillColor(5);
02086     rackUW[rack]->SetFillColor(5);
02087     rackLE[rack]->SetFillColor(5);
02088     rackLW[rack]->SetFillColor(5);
02089 
02090     rackUE[rack]->SetBorderSize(0);
02091     rackUW[rack]->SetBorderSize(0);
02092     rackLE[rack]->SetBorderSize(0);
02093     rackLW[rack]->SetBorderSize(0);
02094 
02095     rackUE[rack]->SetBorderMode(0);
02096     rackUW[rack]->SetBorderMode(0);
02097     rackLE[rack]->SetBorderMode(0);
02098     rackLW[rack]->SetBorderMode(0);
02099 
02100     levelUE->cd();
02101     rackUE[rack]->Draw();
02102     levelUW->cd();
02103     rackUW[rack]->Draw();
02104     levelLE->cd();
02105     rackLE[rack]->Draw();
02106     levelLW->cd();
02107     rackLW[rack]->Draw();
02108   }
02109   
02110   //create mux boxes and draw
02111   TPaveText **muxBoxBg=0;
02112   muxBoxBg=new TPaveText*[const_numRacks];
02113 
02114   for (Int_t rack=0;rack<const_numRacks;rack++){
02115     
02116     muxBoxBg[rack]=new TPaveText(0.06,0.01,0.94,0.97);
02117     muxBoxBg[rack]->SetBorderSize(0);
02118     muxBoxBg[rack]->SetFillColor(0);
02119 
02120     rackUE[rack]->cd();
02121     muxBoxBg[rack]->Draw();
02122     rackUW[rack]->cd();
02123     muxBoxBg[rack]->Draw();
02124     rackLE[rack]->cd();
02125     muxBoxBg[rack]->Draw();
02126     rackLW[rack]->cd(); 
02127     muxBoxBg[rack]->Draw();
02128   }
02129 
02130   //create mux boxes labels
02131   TPaveText ***muxTextUE=0;
02132   muxTextUE=new TPaveText**[const_numRacks];
02133   TPaveText ***muxTextUW=0;
02134   muxTextUW=new TPaveText**[const_numRacks];
02135   TPaveText ***muxTextLE=0;
02136   muxTextLE=new TPaveText**[const_numRacks];
02137   TPaveText ***muxTextLW=0;
02138   muxTextLW=new TPaveText**[const_numRacks];
02139   for (Int_t rack=0;rack<const_numRacks;rack++){
02140     muxTextUE[rack]=new TPaveText*[2*const_numMux]; 
02141     muxTextUW[rack]=new TPaveText*[2*const_numMux]; 
02142     muxTextLE[rack]=new TPaveText*[2*const_numMux]; 
02143     muxTextLW[rack]=new TPaveText*[2*const_numMux];
02144  
02145     for (Int_t pin=0;pin<2*const_numMux;pin++){
02146       (muxTextUE[rack])[pin]=new TPaveText
02147         (0.09,
02148          0.015+static_cast<Int_t>(pin)*0.06,
02149          0.93,
02150          0.015+static_cast<Int_t>(pin+1)*0.06-0.010*(pin%2));
02151       (muxTextUW[rack])[pin]=new TPaveText
02152         (0.09,
02153          0.015+static_cast<Int_t>(pin)*0.06,
02154          0.93,
02155          0.015+static_cast<Int_t>(pin+1)*0.06-0.010*(pin%2));
02156       (muxTextLE[rack])[pin]=new TPaveText
02157         (0.09,
02158          0.015+static_cast<Int_t>(pin)*0.06,
02159          0.93,
02160          0.015+static_cast<Int_t>(pin+1)*0.06-0.010*(pin%2));
02161       (muxTextLW[rack])[pin]=new TPaveText
02162         (0.09,
02163          0.015+static_cast<Int_t>(pin)*0.06,
02164          0.93,
02165          0.015+static_cast<Int_t>(pin+1)*0.06-0.010*(pin%2));
02166       (muxTextUE[rack])[pin]->SetBorderSize(0);
02167       (muxTextUW[rack])[pin]->SetBorderSize(0);
02168       (muxTextLE[rack])[pin]->SetBorderSize(0);
02169       (muxTextLW[rack])[pin]->SetBorderSize(0);
02170 
02171       (muxTextUE[rack])[pin]->SetTextSize(0.2);
02172       (muxTextUW[rack])[pin]->SetTextSize(0.2);
02173       (muxTextLE[rack])[pin]->SetTextSize(0.2);
02174       (muxTextLW[rack])[pin]->SetTextSize(0.2);
02175 
02176       (muxTextUE[rack])[pin]->SetTextColor(5);
02177       (muxTextUW[rack])[pin]->SetTextColor(5);
02178       (muxTextLE[rack])[pin]->SetTextColor(5);
02179       (muxTextLW[rack])[pin]->SetTextColor(5);
02180 
02181       (muxTextUE[rack])[pin]->SetTextFont(2);
02182       (muxTextUW[rack])[pin]->SetTextFont(2);
02183       (muxTextLE[rack])[pin]->SetTextFont(2);
02184       (muxTextLW[rack])[pin]->SetTextFont(2);
02185 
02186       (muxTextUE[rack])[pin]->SetFillColor(20);//18
02187       (muxTextUW[rack])[pin]->SetFillColor(20);//18
02188       (muxTextLE[rack])[pin]->SetFillColor(20);//18
02189       (muxTextLW[rack])[pin]->SetFillColor(20);//18
02190     }
02191   }
02192  
02193   MSG("LIAnalysis",Msg::kInfo) 
02194     <<"Filling and drawing mux box labels..."<<endl;
02195   //fill and draw mux box labels
02196   for (Int_t iEastWest=0;iEastWest<const_numEastWest;iEastWest++){
02197     for (Int_t iRackLevel=0;iRackLevel<const_numRackLevels;
02198          iRackLevel++){
02199       for (rackBay=0;rackBay<static_cast<UInt_t>(const_numRacks);
02200            rackBay++){
02201         
02202         //draw in the correct rack bay
02203         if (iRackLevel==0){
02204           if (iEastWest==0){
02205             rackLE[rackBay]->cd();
02206             MSG("LIAnalysis",Msg::kInfo)<<"Lower East:"<<endl;
02207           }
02208           else if (iEastWest==1){
02209             rackLW[const_numRacks-1-rackBay]->cd();
02210             MSG("LIAnalysis",Msg::kInfo)<<"Lower West:"<<endl;
02211           }
02212         }
02213         else if (iRackLevel==1){
02214           if (iEastWest==0){
02215             rackUE[rackBay]->cd();
02216             MSG("LIAnalysis",Msg::kInfo)<<"Upper East:"<<endl;
02217           }
02218           else if (iEastWest==1){
02219             rackUW[const_numRacks-1-rackBay]->cd();
02220             MSG("LIAnalysis",Msg::kInfo)<<"Upper West:"<<endl;
02221           }
02222         }
02223         for (inRack=0;inRack<static_cast<UInt_t>(const_numMux);
02224              inRack++){
02225           for (inBox=0;inBox<static_cast<UInt_t>(const_numPins);
02226                inBox++){
02227             for (gain=0;gain<static_cast<UInt_t>(const_numPins);gain++){
02228 
02229               //The vfbs are flipped on the east side relative
02230               //to the west side, thus whether pin 1 is plotted
02231               //nearest the floor or the ceiling must change
02232               //depending on the side
02233               Int_t pin=-1;
02234               //On the east side pin 1 is nearest floor and pin one
02235               //nearest ceiling
02236               if (iEastWest==0){//East
02237                 //pins ordered ordered: 1,0, 3,2, 5,4, 7,6 etc
02238                 if (inBox==0){
02239                   pin=2*inRack+1;
02240                 }
02241                 else if (inBox==1){
02242                   pin=2*inRack+0;
02243                 }
02244               }
02245               //On the west side pin 1 is nearest ceiling and pin one
02246               //nearest floor
02247               else if (iEastWest==1){//West
02248                 pin=2*inRack+inBox;//0-15 from bottom to top
02249               }
02250 
02251               MSG("LIAnalysis",Msg::kInfo)
02252                 <<"E/W="<<iEastWest
02253                 <<", U/L="<<iRackLevel
02254                 <<", rack="<<rackBay
02255                 <<", mux="<<inRack
02256                 <<", inBox="<<inBox
02257                 <<", gain="<<gain
02258                 <<", pin="<<pin
02259                 <<", pb=" 
02260                 <<pinPulserBox[iEastWest][iRackLevel][rackBay]
02261                 [inRack][inBox][gain]
02262                 <<", led=" 
02263                 <<pinLed[iEastWest][iRackLevel][rackBay][inRack]
02264                 [inBox][gain]
02265                 <<", va=" 
02266                 <<pinVaChip[iEastWest][iRackLevel][rackBay][inRack]
02267                 [inBox][gain]
02268                 <<endl;
02269               
02270               //check if led illuminates pin
02271               if (pinNumEntries[iEastWest][iRackLevel][rackBay][inRack]
02272                   [inBox][gain]==1){
02273 
02274                 string s = Form("%d",pinLed[iEastWest][iRackLevel][rackBay][inRack][inBox][gain]);
02275 
02276                 if (iEastWest==0){//East
02277                   if (iRackLevel==1){
02278                     //label mux box according to led number
02279                     (muxTextUE[rackBay])[pin]->AddText
02280                       (0.5,0.5,s.c_str());
02281                     //set fill colour according to pulser box number
02282                     (muxTextUE[rackBay])[pin]->SetFillColor
02283                       (19-pinPulserBox[iEastWest][iRackLevel][rackBay]
02284                        [inRack][inBox][gain]/2);
02285 
02286                     if (gain==0){//low gain
02287                       (muxTextUE[rackBay])[pin]->SetTextColor(7);
02288                       //7=aqua
02289                     }
02290                     else if (gain==1){//high gain
02291                       (muxTextUE[rackBay])[pin]->SetTextColor(4);
02292                       //4=bright blue
02293                     }
02294                   }
02295                   else if (iRackLevel==0){
02296                     //label mux box according to led number
02297                     (muxTextLE[rackBay])[pin]->AddText
02298                       (0.5,0.5,s.c_str()); 
02299                     //set fill colour according to pulser box number
02300                     (muxTextLE[rackBay])[pin]->SetFillColor
02301                       (19-pinPulserBox[iEastWest][iRackLevel][rackBay]
02302                        [inRack][inBox][gain]/2);
02303 
02304                     if (gain==0){//low gain
02305                       (muxTextLE[rackBay])[pin]->SetTextColor(7);
02306                       //7=aqua
02307                     }
02308                     else if (gain==1){//high gain
02309                       (muxTextLE[rackBay])[pin]->SetTextColor(4);
02310                       //4=bright blue
02311                     }
02312                   }
02313                 }                 
02314                 else if (iEastWest==1){//West
02315                   if (iRackLevel==1){
02316                     //label mux box according to led number
02317                     (muxTextUW[rackBay])[pin]->AddText
02318                       (0.5,0.5,s.c_str()); 
02319                     //set fill colour according to pulser box number
02320                     (muxTextUW[rackBay])[pin]->
02321                       SetFillColor
02322                       (19-pinPulserBox[iEastWest][iRackLevel][rackBay]
02323                        [inRack][inBox][gain]/2);
02324 
02325                     if (gain==0){//low gain
02326                       (muxTextUW[rackBay])[pin]->
02327                         SetTextColor(7);
02328                       //7=aqua
02329                     }
02330                     else if (gain==1){//high gain
02331                       (muxTextUW[rackBay])[pin]->
02332                         SetTextColor(4);
02333                       //4=bright blue
02334                     }
02335                   }
02336                   else if (iRackLevel==0){  
02337                     //label mux box according to led number
02338                     (muxTextLW[rackBay])[pin]->
02339                       AddText
02340                       (0.5,0.5,s.c_str()); 
02341                     //set fill colour according to pulser box number
02342                     (muxTextLW[rackBay])[pin]->
02343                       SetFillColor
02344                       (19-pinPulserBox[iEastWest][iRackLevel][rackBay]
02345                        [inRack][inBox][gain]/2);
02346 
02347                     if (gain==0){//low gain
02348                       (muxTextLW[rackBay])[pin]->
02349                         SetTextColor(7);
02350                       //7=aqua
02351                     }
02352                     else if (gain==1){//high gain
02353                       (muxTextLW[rackBay])[pin]->
02354                         SetTextColor(4);
02355                       //4=bright blue
02356                     }
02357                   }
02358                 }
02359               }
02360               //there should be zero entries if the pin socket is empty
02361               else if(pinNumEntries[iEastWest][iRackLevel][rackBay]
02362                       [inRack][inBox][gain]==0){
02363                 if (gain==0){
02364                   //check if there is an led on the high gain [1] pin
02365                   //because you don't want to write in the same
02366                   //box twice
02367                   if (pinNumEntries[iEastWest][iRackLevel][rackBay]
02368                       [inRack][inBox][1]==0){               
02369                     //there was no led on either h or l pin so:
02370                     if (iEastWest==0){
02371                       if (iRackLevel==1){
02372                         (muxTextUE[rackBay])[pin]->AddText
02373                           (0.5,0.5,"NO LED"); 
02374                       }
02375                       else if (iRackLevel==0){
02376                         (muxTextLE[rackBay])[pin]->AddText
02377                           (0.5,0.5,"NO LED"); 
02378                       }
02379                     }
02380                     else if (iEastWest==1){
02381                       if (iRackLevel==1){
02382                         (muxTextUW[rackBay])[pin]->
02383                           AddText(0.5,0.5,"NO LED"); 
02384                       }
02385                       else if (iRackLevel==0){
02386                         (muxTextLW[rackBay])[pin]->
02387                           AddText(0.5,0.5,"NO LED"); 
02388                       }
02389                     }
02390                   }
02391                 }
02392                 else {//gain==1
02393                   //this will have already been set, if required, 
02394                   //because you get to the gain==0 pin first
02395                 }
02396               }
02397               else{
02398                 if (iEastWest==0){
02399                   if (iRackLevel==1){
02400                     (muxTextUE[rackBay])[pin]->AddText
02401                       (0.5,0.5,"Error!"); 
02402                   }
02403                   else if (iRackLevel==0){
02404                     (muxTextLE[rackBay])[pin]->AddText
02405                       (0.5,0.5,"Error!"); 
02406                   }
02407                 }
02408                 else if (iEastWest==1){
02409                   if (iRackLevel==1){
02410                     (muxTextUW[rackBay])[pin]->AddText
02411                       (0.5,0.5,"Error!"); 
02412                   }
02413                   else if (iRackLevel==0){
02414                     (muxTextLW[rackBay])[pin]->AddText
02415                       (0.5,0.5,"Error!"); 
02416                   }
02417                 }               
02418                 MSG("LIAnalysis",Msg::kWarning) 
02419                   <<"Warning: numEntries=" 
02420                   <<pinNumEntries[iEastWest][iRackLevel][rackBay]
02421                   [inRack][inBox][gain]
02422                   <<" for rackBay="<<rackBay<<", pin="<<pin
02423                   <<endl;
02424               }
02425 
02426               //determine which set of mux boxes need drawing         
02427               if (iEastWest==0){
02428                 if (iRackLevel==1){
02429                   (muxTextUE[rackBay])[pin]->Draw();
02430                 }
02431                 else if (iRackLevel==0){
02432                   (muxTextLE[rackBay])[pin]->Draw();
02433                 }
02434               }
02435               else if (iEastWest==1){
02436                 if (iRackLevel==1){
02437                   (muxTextUW[rackBay])[pin]->Draw();
02438                 }
02439                 else if (iRackLevel==0){
02440                   (muxTextLW[rackBay])[pin]->Draw();
02441                 }
02442               }
02443             }
02444           }
02445         }
02446       }
02447     }
02448   }
02449   MSG("LIAnalysis",Msg::kInfo)<<"... OK"<<endl;
02450   
02451   //draw crates
02452   MSG("LIAnalysis",Msg::kInfo)<<"Drawing crates..."<<endl;
02453   TPad **cratesE=0;
02454   cratesE=new TPad*[const_numCrates];
02455   TPad **cratesW=0;
02456   cratesW=new TPad*[const_numCrates];
02457   
02458   TPaveText **crateLabelE=0;
02459   crateLabelE=new TPaveText*[const_numCrates];
02460   TPaveText **crateLabelW=0;
02461   crateLabelW=new TPaveText*[const_numCrates];
02462 
02463   //calculate space between crates
02464   crateSpace=(1
02465               -(numRacks/2)*rackWidth
02466               -2*(1.5*rackSpace+(rackWidth/2))
02467               )/((numRacks/2)-1);
02468 
02469   //loop over crates
02470   for (Int_t cra=0;cra<static_cast<Int_t>(numRacks/2);cra++){
02471 
02472     xMin=1.5*rackSpace+(rackWidth/2)
02473       +static_cast<Float_t>(cra)*crateSpace
02474       +static_cast<Float_t>(cra)*rackWidth;
02475 
02476     cratesE[cra]=new TPad("crates","Crates",
02477                           xMin,0.,xMin+rackWidth,0.85,17,3);
02478     cratesE[cra]->SetFillColor(5);
02479     cratesE[cra]->SetBorderSize(0);
02480     cratesE[cra]->SetBorderMode(0);
02481     levelME->cd();
02482     cratesE[cra]->Draw();
02483 
02484     cratesW[cra]=new TPad("crates","Crates",
02485                           xMin,0.,xMin+rackWidth,0.85,17,3);
02486     cratesW[cra]->SetFillColor(5);
02487     cratesW[cra]->SetBorderSize(0);
02488     cratesW[cra]->SetBorderMode(0);
02489     levelMW->cd();
02490     cratesW[cra]->Draw();
02491 
02492     crateLabelE[cra]=new TPaveText(0.1,0.01,0.9,0.95);
02493     crateLabelE[cra]->SetBorderSize(0);
02494     crateLabelW[cra]=new TPaveText(0.1,0.01,0.9,0.95);
02495     crateLabelW[cra]->SetBorderSize(0);
02496 
02497     string s=Form("%d",2*cra);
02498     crateLabelE[cra]->AddText(0.5,0.95,"Pulser");
02499     crateLabelE[cra]->AddText(0.5,0.8,"Box");
02500     crateLabelE[cra]->AddText(0.5,0.65,s.c_str());
02501     crateLabelE[cra]->SetTextSize(0.25);
02502     //set fill colour according to pulser box number
02503     crateLabelE[cra]->SetFillColor(19-cra);
02504     //crateLabelE[cra]->SetFillStyle(3008-cra);
02505     cratesE[cra]->cd();
02506     crateLabelE[cra]->Draw();
02507 
02508     string sW=Form("%d",15-(2*cra));
02509     crateLabelW[cra]->AddText(0.5,0.95,"Pulser");
02510     crateLabelW[cra]->AddText(0.5,0.8,"Box");
02511     crateLabelW[cra]->AddText(0.5,0.65,sW.c_str());
02512     crateLabelW[cra]->SetTextSize(0.25);
02513     //set fill colour according to pulser box number
02514     crateLabelW[cra]->SetFillColor(12+cra);
02515     //crateLabelE[cra]->SetFillStyle(3001+cra);
02516     cratesW[cra]->cd();
02517     crateLabelW[cra]->Draw();
02518   }
02519   MSG("LIAnalysis",Msg::kInfo)<<"... OK"<<endl;
02520 
02521   delete myplexhandle;
02522 */
02523   MSG("LIAnalysis",Msg::kInfo) 
02524     <<"PlotPlexPinMap method finished"<<endl;
02525 }
02526 
02527 //......................................................................
02528 
02529 void LIPlexMaps::PrintPlexPinDiodeInfo(Int_t detectorType)
02530 {
02531   MSG("LIPlexMaps",Msg::kInfo) 
02532     <<"Running PrintPlexPinDiodeInfo method..."<<endl;
02533 
02534   //set validity context to todays date and real data
02535   //VldTimeStamp timeStamp(2002,9,14,1,1,1,1,0,0);
02536   VldTimeStamp timeStamp;//now
02537   //VldTimeStamp timeStamp(2003,8,17,1,1,1,1,0,0);
02538   //  VldTimeStamp timeStamp(2003,3,1,1,1,1,1,0,0);
02539 
02540   //get validity context for detector
02541   VldContext* validityContext;
02542   if (detectorType==DetectorType::kFar){
02543     validityContext=new VldContext(DetectorType::kFar,SimFlag::kData,
02544                                    timeStamp);
02545   }
02546   else if (detectorType==DetectorType::kCalDet){
02547     validityContext=new VldContext(DetectorType::kCalDet,SimFlag::kData,
02548                                    timeStamp);
02549   }
02550   else if (detectorType==DetectorType::kNear){
02551     validityContext=new VldContext(DetectorType::kNear,SimFlag::kData,
02552                                    timeStamp);
02553   }
02554   else{
02555     MSG("LIPlexMaps",Msg::kFatal)
02556       <<"Detector type not known = "<<detectorType
02557       <<endl<<"Program will exit here!"<<endl;
02558     exit(1);
02559   }
02560 
02561   MSG("LIPlexMaps",Msg::kInfo) 
02562     <<"Using validity context: "<<validityContext->AsString()<<endl;
02563 
02564   //create a plex handle to access the database
02565   PlexHandle *plexHandle=new PlexHandle(*validityContext);   
02566 
02567   //get list of leds with given validity context
02568   LedIdList leds(*validityContext);
02569   LedIdList::iterator ledId=leds.begin();
02570 
02571   //leave a line
02572   MSG("LIPlexMaps",Msg::kInfo)
02573     <<endl
02574     <<"The pin diode information in the plex is as follows"<<endl
02575     <<"The electronics information is in descending hierarchial order"
02576     <<endl
02577     <<"(x:y) is pulser box x and led y"<<endl
02578     <<"e.g. (crate,varc,vmm,vfb,VA chip,VA channel)"<<endl<<endl;
02579 
02580   //start to loop over leds
02581   while (ledId!=leds.end()){
02582     
02583     if (!(*ledId).IsValid()){
02584       MSG("LIPlexMaps",Msg::kWarning)
02585         <<"LedId not valid = "<<ledId->AsString()<<endl;
02586     }
02587     
02588     //create a pair to hold the two possible pin diode ids
02589     pair<PlexPinDiodeId,PlexPinDiodeId> plexPins=plexHandle->
02590       GetPinDiodeIds(*ledId);
02591   
02592     //first is gain=1, second is gain=0
02593     MSG("LIPlexMaps",Msg::kVerbose) 
02594       <<"first pin gain="<<plexPins.first.GetGain()
02595       <<", second pin gain="<<plexPins.second.GetGain()<<endl;
02596   
02597     //get the two planes associated with the pin diodes
02598     pair<Int_t,Int_t> pin1Planes=fLookup.GetPinDiodePlanes
02599       (plexPins.first,plexHandle);
02600     pair<Int_t,Int_t> pin2Planes=fLookup.GetPinDiodePlanes
02601       (plexPins.second,plexHandle);
02602 
02603     //get the raw channel ids of the pins
02604     pair<RawChannelId,RawChannelId> rawChanIds;
02605     rawChanIds.first=plexHandle->GetRawChannelId(plexPins.first);
02606     rawChanIds.second=plexHandle->GetRawChannelId(plexPins.second);
02607     
02608     //create the planes string 
02609     //either 1 or 2 planes depending on whether shared pmt is used
02610     string sPlane1=Form("%d",pin1Planes.first);
02611     string sPlane2=Form("%d",pin1Planes.second);
02612 
02613     string sPin1Planes="  Planes="+sPlane1+"&"+sPlane2;
02614     if (pin1Planes.second==-1){
02615       sPin1Planes="  Plane="+sPlane1;
02616     }
02617 
02618     sPlane1=Form("%d",pin2Planes.first);
02619     sPlane2=Form("%d",pin2Planes.second);
02620     string sPin2Planes="  Planes="+sPlane1+"&"+sPlane2;
02621     if (pin2Planes.second==-1){
02622       sPin2Planes="  Plane="+sPlane1;
02623     }
02624 
02625     MSG("LIPlexMaps",Msg::kInfo)
02626       <<endl
02627       <<"("<<ledId->GetPulserBox()<<":"<<ledId->GetLedInBox()<<")"
02628       <<"  Pin1="<<this->GetElecString(rawChanIds.first)
02629       <<"="<<rawChanIds.first.GetChAdd()
02630       <<"  MUX BOX: E/W="<<plexPins.first.GetEastWest()
02631       <<", rLevel="<<plexPins.first.GetRackLevel()
02632       <<", rBay="<<plexPins.first.GetRackBay()
02633       <<", inRack="<<plexPins.first.GetInRack()
02634       <<sPin1Planes
02635       <<endl
02636       //now pin2
02637       <<"("<<ledId->GetPulserBox()<<":"<<ledId->GetLedInBox()<<")"
02638       <<"  Pin2="<<this->GetElecString(rawChanIds.second)
02639       <<"="<<rawChanIds.second.GetChAdd()
02640       <<"  MUX BOX: E/W="<<plexPins.second.GetEastWest()
02641       <<", rLevel="<<plexPins.second.GetRackLevel()
02642       <<", rBay="<<plexPins.second.GetRackBay()
02643       <<", inRack="<<plexPins.second.GetInRack()
02644       <<sPin2Planes
02645       <<endl;
02646 
02647     ledId++;
02648   }
02649   
02650   MSG("LIPlexMaps",Msg::kInfo)
02651     <<endl<<" ** Finished the PrintPlexPinDiodeInfo method ** " 
02652     <<endl;
02653 }
02654 
02655 //......................................................................
02656 
02657 string LIPlexMaps::GetElecString(RawChannelId rChId)
02658 {
02659   MSG("LISummarySorter",Msg::kVerbose) 
02660     <<"Running GetElecString method..."<<endl;
02661 
02662   string elecString="";
02663   string sCrate=Form("%d",rChId.GetCrate());
02664   string sElecType=ElecType::AsString(rChId.GetElecType());
02665 
02666   if (rChId.GetElecType()==ElecType::kVA){
02667     string sVarc=Form("%d",rChId.GetVarcId());
02668     string sVmm=Form("%d",rChId.GetVmm());
02669     string sVfb=Form("%d",rChId.GetVaAdcSel());
02670     string sChip=Form("%d",rChId.GetVaChip());
02671     string sChannel=Form("%d",rChId.GetVaChannel());
02672 
02673     elecString=sElecType+
02674       "("+sCrate+","+sVarc+","+sVmm+","+sVfb+","+sChip+","+sChannel+")";
02675   }     
02676   else if (rChId.GetElecType()==ElecType::kQIE){
02677     string sGeoAdd=Form("%d",rChId.GetGeographicAddress());
02678     string sMaster=Form("%d",rChId.GetMasterChannel());
02679     string sMinder=Form("%d",rChId.GetMinderChannel());
02680         
02681     elecString=sElecType+
02682       "("+sCrate+","+sGeoAdd+","+sMaster+","+sMinder+")";
02683   }
02684   return elecString;
02685 }
02686 
02687 //......................................................................
02688 
02689 void LIPlexMaps::PlotPlexStripMap(Int_t detectorType)
02690 {
02691   MSG("LIPlexMaps",Msg::kInfo) 
02692     <<"Running PlotPlexStripMap method..."<<endl;
02693 
02694   Int_t planeMax=-1;
02695   Int_t planeMin=-1;
02696 
02697   planeMin=FIRSTSCINTPLANE-2;
02698   planeMax=LASTSCINTPLANE+5;
02699 
02700   const Int_t firstStripBin=FIRSTSTRIP-8;//-8;
02701   const Int_t lastStripBin=LASTSTRIP+9;//200 for fardet;
02702   const Int_t bins=lastStripBin-firstStripBin;
02703 
02704   //set validity context to todays date and far detector and real data
02705   //VldTimeStamp timeStamp(2002,9,14,1,1,1,1,0,0);
02706   //VldTimeStamp timeStamp(2003,8,17,1,1,1,1,0,0);
02707   VldTimeStamp timeStamp(2001,7,1,1,1,1,1,0,0);
02708   //VldTimeStamp timeStamp;//now
02709 
02710   VldContext* validityContext;
02711 
02712   if (detectorType==DetectorType::kFar){
02713     validityContext=new VldContext(DetectorType::kFar,
02714                                    SimFlag::kData,timeStamp);
02715   }
02716   else if (detectorType==DetectorType::kCalDet){
02717     validityContext=new VldContext(DetectorType::kCalDet,
02718                                    SimFlag::kData,timeStamp);
02719   }
02720   else if (detectorType==DetectorType::kNear){
02721     validityContext=new VldContext(DetectorType::kNear,
02722                                    SimFlag::kData,timeStamp);
02723   }
02724   else{
02725     MSG("LIPlexMaps",Msg::kFatal)
02726       <<"Detector type not known = "<<detectorType
02727       <<endl<<"Program will exit here!"<<endl;
02728     exit(1);
02729   }
02730 
02731   MSG("LIPlexMaps",Msg::kInfo) 
02732     <<"Using validity context: "<<validityContext->AsString()<<endl;
02733 
02734   PlexHandle *plexhandle=new PlexHandle(*validityContext);   
02735 
02736   TH2F *hStripVsPlaneLed=new TH2F("hStripVsPlaneLed",
02737                                    "Led (StripEnd=kNeg=kEast)",
02738                                    planeMax-planeMin,
02739                                    planeMin,planeMax,
02740                                    bins,firstStripBin,lastStripBin);
02741   hStripVsPlaneLed->GetXaxis()->SetTitle("Plane");
02742   hStripVsPlaneLed->GetXaxis()->CenterTitle();
02743   hStripVsPlaneLed->GetYaxis()->SetTitle("Strip");
02744   hStripVsPlaneLed->GetYaxis()->CenterTitle();
02745   hStripVsPlaneLed->SetFillColor(0);
02746   //hStripVsPlaneLed->SetBit(TH1::kCanRebin);
02747 
02748   TH2F *hStripVsPlanePix=new TH2F("hStripVsPlanePix",
02749                                    "Pixel (StripEnd=kNeg=kEast)",
02750                                    planeMax-planeMin,planeMin,planeMax,
02751                                    bins,firstStripBin,lastStripBin);
02752   hStripVsPlanePix->GetXaxis()->SetTitle("Plane");
02753   hStripVsPlanePix->GetXaxis()->CenterTitle();
02754   hStripVsPlanePix->GetYaxis()->SetTitle("Strip");
02755   hStripVsPlanePix->GetYaxis()->CenterTitle();
02756   hStripVsPlanePix->SetFillColor(0);
02757   hStripVsPlanePix->SetMinimum(-2);
02758   //hStripVsPlanePix->SetBit(TH1::kCanRebin);
02759 
02760   TH2F *hStripVsPlaneCrate=new TH2F("hStripVsPlaneCrate",
02761                                      "Crate (StripEnd=kNeg=kEast)",
02762                                      planeMax-planeMin,planeMin,
02763                                     planeMax,
02764                                      bins,firstStripBin,lastStripBin);
02765   hStripVsPlaneCrate->GetXaxis()->SetTitle("Plane");
02766   hStripVsPlaneCrate->GetXaxis()->CenterTitle();
02767   hStripVsPlaneCrate->GetYaxis()->SetTitle("Strip");
02768   hStripVsPlaneCrate->GetYaxis()->CenterTitle();
02769   hStripVsPlaneCrate->SetFillColor(0);
02770   hStripVsPlaneCrate->SetMinimum(-2);
02771   //hStripVsPlaneCrate->SetBit(TH1::kCanRebin);
02772 
02773   TH2F *hStripVsPlaneVarc=new TH2F("hStripVsPlaneVarc",
02774                                     "Varc (StripEnd=kNeg=kEast)",
02775                                     planeMax-planeMin,planeMin,planeMax,
02776                                     bins,firstStripBin,lastStripBin);
02777   hStripVsPlaneVarc->GetXaxis()->SetTitle("Plane");
02778   hStripVsPlaneVarc->GetXaxis()->CenterTitle();
02779   hStripVsPlaneVarc->GetYaxis()->SetTitle("Strip");
02780   hStripVsPlaneVarc->GetYaxis()->CenterTitle();
02781   hStripVsPlaneVarc->SetFillColor(0);
02782   hStripVsPlaneVarc->SetMinimum(-2);
02783   //hStripVsPlaneVarc->SetBit(TH1::kCanRebin);
02784 
02785   TH2F *hStripVsPlaneVmm=new TH2F("hStripVsPlaneVmm",
02786                                    "Vmm (StripEnd=kNeg=kEast)",
02787                                    planeMax-planeMin,planeMin,planeMax,
02788                                    bins,firstStripBin,lastStripBin);
02789   hStripVsPlaneVmm->GetXaxis()->SetTitle("Plane");
02790   hStripVsPlaneVmm->GetXaxis()->CenterTitle();
02791   hStripVsPlaneVmm->GetYaxis()->SetTitle("Strip");
02792   hStripVsPlaneVmm->GetYaxis()->CenterTitle();
02793   hStripVsPlaneVmm->SetFillColor(0);
02794   hStripVsPlaneVmm->SetMinimum(-2);
02795   //hStripVsPlaneVmm->SetBit(TH1::kCanRebin);
02796 
02797   TH2F *hStripVsPlaneVfb=new TH2F("hStripVsPlaneVfb",
02798                                    "Vfb (StripEnd=kNeg=kEast)",
02799                                    planeMax-planeMin,planeMin,planeMax,
02800                                    bins,firstStripBin,lastStripBin);
02801   hStripVsPlaneVfb->GetXaxis()->SetTitle("Plane");
02802   hStripVsPlaneVfb->GetXaxis()->CenterTitle();
02803   hStripVsPlaneVfb->GetYaxis()->SetTitle("Strip");
02804   hStripVsPlaneVfb->GetYaxis()->CenterTitle();
02805   hStripVsPlaneVfb->SetFillColor(0);
02806   hStripVsPlaneVfb->SetMinimum(-2);
02807   //hStripVsPlaneVfb->SetBit(TH1::kCanRebin);
02808 
02809   TH2F *hStripVsPlaneVaChip=new TH2F("hStripVsPlaneVaChip",
02810                                   "VA Chip (StripEnd=kNeg=kEast)",
02811                                   planeMax-planeMin,planeMin,planeMax,
02812                                   bins,firstStripBin,lastStripBin);
02813   hStripVsPlaneVaChip->GetXaxis()->SetTitle("Plane");
02814   hStripVsPlaneVaChip->GetXaxis()->CenterTitle();
02815   hStripVsPlaneVaChip->GetYaxis()->SetTitle("Strip");
02816   hStripVsPlaneVaChip->GetYaxis()->CenterTitle();
02817   hStripVsPlaneVaChip->SetFillColor(0);
02818   hStripVsPlaneVaChip->SetMinimum(-2);
02819   //hStripVsPlaneVaChip->SetBit(TH1::kCanRebin);
02820 
02821   TH2F *hStripVsPlaneCh=new TH2F("hStripVsPlaneCh",
02822                                   "VA Channel (StripEnd=kNeg=kEast)",
02823                                   planeMax-planeMin,planeMin,planeMax,
02824                                   bins,firstStripBin,lastStripBin);
02825   hStripVsPlaneCh->GetXaxis()->SetTitle("Plane");
02826   hStripVsPlaneCh->GetXaxis()->CenterTitle();
02827   hStripVsPlaneCh->GetYaxis()->SetTitle("Strip");
02828   hStripVsPlaneCh->GetYaxis()->CenterTitle();
02829   hStripVsPlaneCh->SetFillColor(0);
02830   hStripVsPlaneCh->SetMinimum(-2);
02831   //hStripVsPlaneCh->SetBit(TH1::kCanRebin);
02832 
02833   TH2F *hStripVsPlaneGeoAdd=new TH2F("hStripVsPlaneGeoAdd",
02834                                      "Geographic Address (StripEnd=kNeg=kEast)",
02835                                      planeMax-planeMin,planeMin,
02836                                      planeMax,
02837                                      bins,firstStripBin,lastStripBin);
02838   hStripVsPlaneGeoAdd->GetXaxis()->SetTitle("Plane");
02839   hStripVsPlaneGeoAdd->GetXaxis()->CenterTitle();
02840   hStripVsPlaneGeoAdd->GetYaxis()->SetTitle("Strip");
02841   hStripVsPlaneGeoAdd->GetYaxis()->CenterTitle();
02842   hStripVsPlaneGeoAdd->SetFillColor(0);
02843   hStripVsPlaneGeoAdd->SetMinimum(-2);
02844   //hStripVsPlaneGeoAdd->SetBit(TH1::kCanRebin);
02845 
02846   TH2F *hStripVsPlaneMasterCh=new TH2F("hStripVsPlaneMasterCh",
02847                                        "Master Channel (StripEnd=kNeg=kEast)",
02848                                         planeMax-planeMin,
02849                                         planeMin,planeMax,
02850                                         bins,
02851                                         firstStripBin,lastStripBin);
02852   hStripVsPlaneMasterCh->GetXaxis()->SetTitle("Plane");
02853   hStripVsPlaneMasterCh->GetXaxis()->CenterTitle();
02854   hStripVsPlaneMasterCh->GetYaxis()->SetTitle("Strip");
02855   hStripVsPlaneMasterCh->GetYaxis()->CenterTitle();
02856   hStripVsPlaneMasterCh->SetFillColor(0);
02857   hStripVsPlaneMasterCh->SetMinimum(-2);
02858   //hStripVsPlaneMasterCh->SetBit(TH1::kCanRebin);
02859 
02860   TH2F *hStripVsPlaneMinderCh=new TH2F("hStripVsPlaneMinderCh",
02861                                        "Minder Channel (StripEnd=kNeg=kEast)",
02862                                        planeMax-planeMin,
02863                                        planeMin,planeMax,
02864                                        bins,
02865                                        firstStripBin,lastStripBin);
02866   hStripVsPlaneMinderCh->GetXaxis()->SetTitle("Plane");
02867   hStripVsPlaneMinderCh->GetXaxis()->CenterTitle();
02868   hStripVsPlaneMinderCh->GetYaxis()->SetTitle("Strip");
02869   hStripVsPlaneMinderCh->GetYaxis()->CenterTitle();
02870   hStripVsPlaneMinderCh->SetFillColor(0);
02871   hStripVsPlaneMinderCh->SetMinimum(-2);
02872   //hStripVsPlaneMinderCh->SetBit(TH1::kCanRebin);
02873 
02874   TH2F *hStripVsPlaneSpot=new TH2F("hStripVsPlaneSpot",
02875                                    "Pixel Spot (StripEnd=kNeg=kEast)",
02876                                     planeMax-planeMin,planeMin,planeMax,
02877                                     bins,firstStripBin,lastStripBin);
02878   hStripVsPlaneSpot->GetXaxis()->SetTitle("Plane");
02879   hStripVsPlaneSpot->GetXaxis()->CenterTitle();
02880   hStripVsPlaneSpot->GetYaxis()->SetTitle("Strip");
02881   hStripVsPlaneSpot->GetYaxis()->CenterTitle();
02882   hStripVsPlaneSpot->SetFillColor(0);
02883   hStripVsPlaneSpot->SetMinimum(-2);
02884   //hStripVsPlaneSpot->SetBit(TH1::kCanRebin);
02885 
02886   TH2F *hStripVsPlaneEnt=new TH2F("hStripVsPlaneEnt",
02887                                   "Number Entries (StripEnd=kNeg=kEast)",
02888                                    planeMax-planeMin,planeMin,planeMax,
02889                                    bins,firstStripBin,lastStripBin);
02890   hStripVsPlaneEnt->GetXaxis()->SetTitle("Plane");
02891   hStripVsPlaneEnt->GetXaxis()->CenterTitle();
02892   hStripVsPlaneEnt->GetYaxis()->SetTitle("Strip");
02893   hStripVsPlaneEnt->GetYaxis()->CenterTitle();
02894   hStripVsPlaneEnt->SetFillColor(0);
02895   hStripVsPlaneEnt->SetMinimum(-2);
02896   //hStripVsPlaneEnt->SetBit(TH1::kCanRebin);
02897 
02899   //histos for the second side
02901   TH2F *hStripVsPlane2Led=new TH2F("hStripVsPlane2Led",
02902                                     "Led (StripEnd=kPos=kWest)",
02903                                    planeMax-planeMin,
02904                                    planeMin,planeMax,
02905                                    bins,firstStripBin,lastStripBin);
02906   hStripVsPlane2Led->GetXaxis()->SetTitle("Plane");
02907   hStripVsPlane2Led->GetXaxis()->CenterTitle();
02908   hStripVsPlane2Led->GetYaxis()->SetTitle("Strip");
02909   hStripVsPlane2Led->GetYaxis()->CenterTitle();
02910   hStripVsPlane2Led->SetFillColor(0);
02911   //hStripVsPlane2Led->SetBit(TH1::kCanRebin);
02912 
02913   TH2F *hStripVsPlane2Pix=new TH2F("hStripVsPlane2Pix",
02914                                    "Pixel (StripEnd=kPos=kWest)",
02915                                    planeMax-planeMin,planeMin,planeMax,
02916                                    bins,firstStripBin,lastStripBin);
02917   hStripVsPlane2Pix->GetXaxis()->SetTitle("Plane");
02918   hStripVsPlane2Pix->GetXaxis()->CenterTitle();
02919   hStripVsPlane2Pix->GetYaxis()->SetTitle("Strip");
02920   hStripVsPlane2Pix->GetYaxis()->CenterTitle();
02921   hStripVsPlane2Pix->SetFillColor(0);
02922   hStripVsPlane2Pix->SetMinimum(-2);
02923   //hStripVsPlane2Pix->SetBit(TH1::kCanRebin);
02924 
02925   TH2F *hStripVsPlane2Crate=new TH2F("hStripVsPlane2Crate",
02926                                      "Crate (StripEnd=kPos=kWest)",
02927                                      planeMax-planeMin,planeMin,planeMax,
02928                                      bins,firstStripBin,lastStripBin);
02929   hStripVsPlane2Crate->GetXaxis()->SetTitle("Plane");
02930   hStripVsPlane2Crate->GetXaxis()->CenterTitle();
02931   hStripVsPlane2Crate->GetYaxis()->SetTitle("Strip");
02932   hStripVsPlane2Crate->GetYaxis()->CenterTitle();
02933   hStripVsPlane2Crate->SetFillColor(0);
02934   hStripVsPlane2Crate->SetMinimum(-2);
02935   //hStripVsPlane2Crate->SetBit(TH1::kCanRebin);
02936 
02937   TH2F *hStripVsPlane2Varc=new TH2F("hStripVsPlane2Varc",
02938                                     "Varc (StripEnd=kPos=kWest)",
02939                                     planeMax-planeMin,planeMin,planeMax,
02940                                     bins,firstStripBin,lastStripBin);
02941   hStripVsPlane2Varc->GetXaxis()->SetTitle("Plane");
02942   hStripVsPlane2Varc->GetXaxis()->CenterTitle();
02943   hStripVsPlane2Varc->GetYaxis()->SetTitle("Strip");
02944   hStripVsPlane2Varc->GetYaxis()->CenterTitle();
02945   hStripVsPlane2Varc->SetFillColor(0);
02946   hStripVsPlane2Varc->SetMinimum(-2);
02947   //hStripVsPlane2Varc->SetBit(TH1::kCanRebin);
02948 
02949   TH2F *hStripVsPlane2Vmm=new TH2F("hStripVsPlane2Vmm",
02950                                    "Vmm (StripEnd=kPos=kWest)",
02951                                    planeMax-planeMin,planeMin,planeMax,
02952                                    bins,firstStripBin,lastStripBin);
02953   hStripVsPlane2Vmm->GetXaxis()->SetTitle("Plane");
02954   hStripVsPlane2Vmm->GetXaxis()->CenterTitle();
02955   hStripVsPlane2Vmm->GetYaxis()->SetTitle("Strip");
02956   hStripVsPlane2Vmm->GetYaxis()->CenterTitle();
02957   hStripVsPlane2Vmm->SetFillColor(0);
02958   hStripVsPlane2Vmm->SetMinimum(-2);
02959   //hStripVsPlane2Vmm->SetBit(TH1::kCanRebin);
02960 
02961   TH2F *hStripVsPlane2Vfb=new TH2F("hStripVsPlane2Vfb",
02962                                    "Vfb (StripEnd=kPos=kWest)",
02963                                    planeMax-planeMin,planeMin,planeMax,
02964                                    bins,firstStripBin,lastStripBin);
02965   hStripVsPlane2Vfb->GetXaxis()->SetTitle("Plane");
02966   hStripVsPlane2Vfb->GetXaxis()->CenterTitle();
02967   hStripVsPlane2Vfb->GetYaxis()->SetTitle("Strip");
02968   hStripVsPlane2Vfb->GetYaxis()->CenterTitle();
02969   hStripVsPlane2Vfb->SetFillColor(0);
02970   hStripVsPlane2Vfb->SetMinimum(-2);
02971   //hStripVsPlane2Vfb->SetBit(TH1::kCanRebin);
02972 
02973   TH2F *hStripVsPlane2VaChip=new TH2F("hStripVsPlane2VaChip",
02974                                   "Va Chip(StripEnd=kPos=kWest)",
02975                                   planeMax-planeMin,planeMin,planeMax,
02976                                   bins,firstStripBin,lastStripBin);
02977   hStripVsPlane2VaChip->GetXaxis()->SetTitle("Plane");
02978   hStripVsPlane2VaChip->GetXaxis()->CenterTitle();
02979   hStripVsPlane2VaChip->GetYaxis()->SetTitle("Strip");
02980   hStripVsPlane2VaChip->GetYaxis()->CenterTitle();
02981   hStripVsPlane2VaChip->SetFillColor(0);
02982   hStripVsPlane2VaChip->SetMinimum(-2);
02983   //hStripVsPlane2VaChip->SetBit(TH1::kCanRebin);
02984 
02985   TH2F *hStripVsPlane2Ch=new TH2F("hStripVsPlane2Ch",
02986                                   "VA Channel (StripEnd=kPos=kWest)",
02987                                   planeMax-planeMin,planeMin,planeMax,
02988                                   bins,firstStripBin,lastStripBin);
02989   hStripVsPlane2Ch->GetXaxis()->SetTitle("Plane");
02990   hStripVsPlane2Ch->GetXaxis()->CenterTitle();
02991   hStripVsPlane2Ch->GetYaxis()->SetTitle("Strip");
02992   hStripVsPlane2Ch->GetYaxis()->CenterTitle();
02993   hStripVsPlane2Ch->SetFillColor(0);
02994   hStripVsPlane2Ch->SetMinimum(-2);
02995   //hStripVsPlane2Ch->SetBit(TH1::kCanRebin);
02996 
02997   TH2F *hStripVsPlane2GeoAdd=new TH2F("hStripVsPlane2GeoAdd",
02998                                       "Geographic Address (StripEnd=kPos=kWest)",
02999                                       planeMax-planeMin,
03000                                       planeMin,planeMax,
03001                                       bins,firstStripBin,lastStripBin);
03002   hStripVsPlane2GeoAdd->GetXaxis()->SetTitle("Plane");
03003   hStripVsPlane2GeoAdd->GetXaxis()->CenterTitle();
03004   hStripVsPlane2GeoAdd->GetYaxis()->SetTitle("Strip");
03005   hStripVsPlane2GeoAdd->GetYaxis()->CenterTitle();
03006   hStripVsPlane2GeoAdd->SetFillColor(0);
03007   hStripVsPlane2GeoAdd->SetMinimum(-2);
03008   //hStripVsPlane2GeoAdd->SetBit(TH1::kCanRebin);
03009 
03010   TH2F *hStripVsPlane2MasterCh=new TH2F("hStripVsPlane2MasterCh",
03011                                         "Master Channel (StripEnd=kPos=kWest)",
03012                                         planeMax-planeMin,
03013                                         planeMin,planeMax,
03014                                         bins,
03015                                         firstStripBin,lastStripBin);
03016   hStripVsPlane2MasterCh->GetXaxis()->SetTitle("Plane");
03017   hStripVsPlane2MasterCh->GetXaxis()->CenterTitle();
03018   hStripVsPlane2MasterCh->GetYaxis()->SetTitle("Strip");
03019   hStripVsPlane2MasterCh->GetYaxis()->CenterTitle();
03020   hStripVsPlane2MasterCh->SetFillColor(0);
03021   hStripVsPlane2MasterCh->SetMinimum(-2);
03022   //hStripVsPlane2MasterCh->SetBit(TH1::kCanRebin);
03023 
03024   TH2F *hStripVsPlane2MinderCh=new TH2F("hStripVsPlane2MinderCh",
03025                                         "Minder Channel (StripEnd=kPos=kWest)",
03026                                         planeMax-planeMin,planeMin,
03027                                         planeMax,
03028                                         bins,firstStripBin,
03029                                         lastStripBin);
03030   hStripVsPlane2MinderCh->GetXaxis()->SetTitle("Plane");
03031   hStripVsPlane2MinderCh->GetXaxis()->CenterTitle();
03032   hStripVsPlane2MinderCh->GetYaxis()->SetTitle("Strip");
03033   hStripVsPlane2MinderCh->GetYaxis()->CenterTitle();
03034   hStripVsPlane2MinderCh->SetFillColor(0);
03035   hStripVsPlane2MinderCh->SetMinimum(-2);
03036   //hStripVsPlane2MinderCh->SetBit(TH1::kCanRebin);
03037 
03038   TH2F *hStripVsPlane2Spot=new TH2F("hStripVsPlane2Spot",
03039                                     "Pixel Spot (StripEnd=kPos=kWest)",
03040                                     planeMax-planeMin,planeMin,planeMax,
03041                                     bins,firstStripBin,lastStripBin);
03042   hStripVsPlane2Spot->GetXaxis()->SetTitle("Plane");
03043   hStripVsPlane2Spot->GetXaxis()->CenterTitle();
03044   hStripVsPlane2Spot->GetYaxis()->SetTitle("Strip");
03045   hStripVsPlane2Spot->GetYaxis()->CenterTitle();
03046   hStripVsPlane2Spot->SetFillColor(0);
03047   hStripVsPlane2Spot->SetMinimum(-2);
03048   //hStripVsPlane2Spot->SetBit(TH1::kCanRebin);
03049 
03050   TH2F *hStripVsPlane2Ent=new TH2F("hStripVsPlane2Ent",
03051                                    "Number Entries (StripEnd=kPos=kWest)",
03052                                    planeMax-planeMin,planeMin,planeMax,
03053                                    bins,firstStripBin,lastStripBin);
03054   hStripVsPlane2Ent->GetXaxis()->SetTitle("Plane");
03055   hStripVsPlane2Ent->GetXaxis()->CenterTitle();
03056   hStripVsPlane2Ent->GetYaxis()->SetTitle("Strip");
03057   hStripVsPlane2Ent->GetYaxis()->CenterTitle();
03058   hStripVsPlane2Ent->SetFillColor(0);
03059   hStripVsPlane2Ent->SetMinimum(-2);
03060   //hStripVsPlane2Ent->SetBit(TH1::kCanRebin);
03061 
03062   //create the plex plane id for use below
03063   PlexPlaneId* planeId;
03064 
03068 
03069   for (Int_t pl=planeMin;pl<planeMax;pl++){
03070 
03071     //get the plane ids
03072     if (detectorType==DetectorType::kFar){
03073       planeId=new PlexPlaneId(DetectorType::kFar,pl);
03074     }
03075     else if (detectorType==DetectorType::kCalDet){
03076       planeId=new PlexPlaneId(DetectorType::kCalDet,pl);
03077     }
03078     else{
03079       planeId=new PlexPlaneId(DetectorType::kNear,pl);
03080     }
03081 
03082     MSG("LIPlexMaps",Msg::kInfo) 
03083       <<"pl="<<pl<<", gPl="<<planeId->GetPlane()
03084       <<", view="<<planeId->GetPlaneView()
03085       <<", valid="<<planeId->IsValid()
03086       <<endl;
03087 
03088     for (Int_t st=-1;st<NUMSTRIPS+2;st++){
03089       for (Int_t se=0;se<NUMSIDES;se++){
03090 
03091         //create the strip end type
03092         StripEnd::EStripEnd stripEnd;
03093         
03094         //set the strip end type
03095         if (se==0) stripEnd=StripEnd::kEast;//FD=kNeg
03096         else if (se==1) stripEnd=StripEnd::kWest;//ND=kPos
03097 
03098         //Generate strip end id      
03099         PlexStripEndId stripEndId(*planeId,st,stripEnd);    
03100   
03101         //get led and pixel ids from strip end
03102         PlexLedId ledId=plexhandle->GetLedId(stripEndId);
03103         PlexPixelSpotId pixelId=plexhandle->GetPixelSpotId(stripEndId);
03104 
03105         Int_t crate=plexhandle->GetRawChannelId(stripEndId).
03106           GetCrate();
03107         Int_t varc=plexhandle->GetRawChannelId(stripEndId).GetVarcId();
03108         Int_t vmm=plexhandle->GetRawChannelId(stripEndId).GetVmm();
03109         Int_t vfb=plexhandle->GetRawChannelId(stripEndId).GetVaAdcSel();
03110         Int_t vaChip=plexhandle->GetRawChannelId(stripEndId).GetVaChip();
03111         Int_t ch=plexhandle->GetRawChannelId(stripEndId).GetVaChannel();
03112 
03113         Int_t masterCh=plexhandle->GetRawChannelId(stripEndId).
03114           GetMasterChannel();
03115         Int_t minderCh=plexhandle->GetRawChannelId(stripEndId).
03116           GetMinderChannel();
03117         Int_t geoAdd=plexhandle->GetRawChannelId(stripEndId).
03118           GetGeographicAddress();
03119 
03120         if (geoAdd>60000) geoAdd=-1;
03121         if (masterCh>60000) masterCh=-1;
03122         if (minderCh>60000) minderCh=-1;
03123 
03124         if (varc>60000) varc=-1;
03125         if (vmm>60000) vmm=-1;
03126         if (vfb>60000) vfb=-1;
03127         if (vaChip>60000) vaChip=-1;
03128         if (ch>60000) ch=-1;
03129 
03130         //get led and pixel from ids
03131         Int_t led=static_cast<Int_t>(ledId.GetLedInBox());
03132         Int_t pix=static_cast<Int_t>(pixelId.GetPixel());
03133         Int_t spot=pixelId.GetSpot();
03134 
03135         MSG("LIPlexMaps",Msg::kVerbose) 
03136           <<"st="<<st<<", gSt="<<stripEndId.GetStrip()
03137           <<", end="<<stripEndId.GetEnd()
03138           <<", val="<<stripEndId.IsValid()
03139           <<", gled="<<led
03140           <<", gpB="<<ledId.GetPulserBox()
03141           <<", val="<<ledId.IsValid()
03142           <<", pixel="<<pix
03143           <<", val="<<pixelId.IsValid()
03144           <<endl;
03145 
03146         if (se==0){
03147           //fill histograms
03148           hStripVsPlanePix->Fill(pl,st,pix);
03149           hStripVsPlaneSpot->Fill(pl,st,spot);
03150           hStripVsPlaneCrate->Fill(pl,st,crate);
03151           hStripVsPlaneVarc->Fill(pl,st,varc);
03152           hStripVsPlaneVmm->Fill(pl,st,vmm);
03153           hStripVsPlaneVfb->Fill(pl,st,vfb);
03154           hStripVsPlaneVaChip->Fill(pl,st,vaChip);
03155           hStripVsPlaneCh->Fill(pl,st,ch);
03156           hStripVsPlaneGeoAdd->Fill(pl,st,geoAdd);
03157           hStripVsPlaneMasterCh->Fill(pl,st,masterCh);
03158           hStripVsPlaneMinderCh->Fill(pl,st,minderCh);
03159           hStripVsPlaneLed->Fill(pl,st,led);
03160           hStripVsPlaneEnt->Fill(pl,st,1.);
03161         }
03162         else if (se==1){
03163           //fill histograms
03164           hStripVsPlane2Pix->Fill(pl,st,pix);
03165           hStripVsPlane2Spot->Fill(pl,st,spot);
03166           hStripVsPlane2Crate->Fill(pl,st,crate);
03167           hStripVsPlane2Varc->Fill(pl,st,varc);
03168           hStripVsPlane2Vmm->Fill(pl,st,vmm);
03169           hStripVsPlane2Vfb->Fill(pl,st,vfb);
03170           hStripVsPlane2VaChip->Fill(pl,st,vaChip);
03171           hStripVsPlane2Ch->Fill(pl,st,ch);
03172           hStripVsPlane2GeoAdd->Fill(pl,st,geoAdd);
03173           hStripVsPlane2MasterCh->Fill(pl,st,masterCh);
03174           hStripVsPlane2MinderCh->Fill(pl,st,minderCh);
03175           hStripVsPlane2Led->Fill(pl,st,led);
03176           hStripVsPlane2Ent->Fill(pl,st,1.);
03177         }
03178       }
03179     }
03180   }
03181 
03185 
03186   //get rid of the stats info
03187   gStyle->SetOptStat(0);
03188 
03189   Int_t draw=1;
03190   if (draw==1){
03191   TCanvas *cStripVsPlaneLed=new TCanvas
03192     ("cStripVsPlaneLed","StripVsPlane: Led",0,0,1000,800);
03193   cStripVsPlaneLed->SetFillColor(0);
03194   cStripVsPlaneLed->cd();
03195   hStripVsPlaneLed->Draw("colz");
03196 
03197   TCanvas *cStripVsPlanePix=new TCanvas
03198     ("cStripVsPlanePix","StripVsPlane: Pixel",0,0,1000,800);
03199   cStripVsPlanePix->SetFillColor(0);
03200   cStripVsPlanePix->cd();
03201   hStripVsPlanePix->Draw("textcolz");
03202   
03203   TCanvas *cStripVsPlaneCrate=new TCanvas
03204     ("cStripVsPlaneCrate","StripVsPlane: Crate",0,0,1000,800);
03205   cStripVsPlaneCrate->SetFillColor(0);
03206   cStripVsPlaneCrate->cd();
03207   hStripVsPlaneCrate->Draw("textcolz");
03208 
03209   TCanvas *cStripVsPlaneVarc=new TCanvas
03210     ("cStripVsPlaneVarc","StripVsPlane: Varc",0,0,1000,800);
03211   cStripVsPlaneVarc->SetFillColor(0);
03212   cStripVsPlaneVarc->cd();
03213   hStripVsPlaneVarc->Draw("textcolz");
03214  
03215   TCanvas *cStripVsPlaneVmm=new TCanvas
03216     ("cStripVsPlaneVmm","StripVsPlane: Vmm",0,0,1000,800);
03217   cStripVsPlaneVmm->SetFillColor(0);
03218   cStripVsPlaneVmm->cd();
03219   hStripVsPlaneVmm->Draw("textcolz");
03220 
03221   TCanvas *cStripVsPlaneVfb=new TCanvas
03222     ("cStripVsPlaneVfb","StripVsPlane: Vfb",0,0,1000,800);
03223   cStripVsPlaneVfb->SetFillColor(0);
03224   cStripVsPlaneVfb->cd();
03225   hStripVsPlaneVfb->Draw("textcolz");
03226 
03227   TCanvas *cStripVsPlaneVaChip=new TCanvas
03228     ("cStripVsPlaneVaChip","StripVsPlane: VaChip",0,0,1000,800);
03229   cStripVsPlaneVaChip->SetFillColor(0);
03230   cStripVsPlaneVaChip->cd();
03231   hStripVsPlaneVaChip->Draw("textcolz");
03232 
03233   TCanvas *cStripVsPlaneCh=new TCanvas
03234     ("cStripVsPlaneCh","StripVsPlane: Ch",0,0,1000,800);
03235   cStripVsPlaneCh->SetFillColor(0);
03236   cStripVsPlaneCh->cd();
03237   hStripVsPlaneCh->Draw("textcolz");
03238 
03239   TCanvas *cStripVsPlaneGeoAdd=new TCanvas
03240     ("cStripVsPlaneGeoAdd","StripVsPlane: GeoAdd",0,0,1000,800);
03241   cStripVsPlaneGeoAdd->SetFillColor(0);
03242   cStripVsPlaneGeoAdd->cd();
03243   hStripVsPlaneGeoAdd->Draw("textcolz");
03244 
03245   TCanvas *cStripVsPlaneMasterCh=new TCanvas
03246     ("cStripVsPlaneMasterCh","StripVsPlane: Master Channel",
03247      0,0,1000,800);
03248   cStripVsPlaneMasterCh->SetFillColor(0);
03249   cStripVsPlaneMasterCh->cd();
03250   hStripVsPlaneMasterCh->Draw("textcolz");
03251 
03252   }
03253 
03254   TCanvas *cStripVsPlaneMinderCh=new TCanvas
03255     ("cStripVsPlaneMinderCh","StripVsPlane: MinderCh",0,0,1000,800);
03256   cStripVsPlaneMinderCh->SetFillColor(0);
03257   cStripVsPlaneMinderCh->cd();
03258   hStripVsPlaneMinderCh->Draw("textcolz");
03259 
03260   TCanvas *cStripVsPlaneSpot=new TCanvas
03261     ("cStripVsPlaneSpot","StripVsPlane: Spot",0,0,1000,800);
03262   cStripVsPlaneSpot->SetFillColor(0);
03263   cStripVsPlaneSpot->cd();
03264   hStripVsPlaneSpot->Draw("textcolz");
03265 
03266   TCanvas *cStripVsPlaneEnt=new TCanvas
03267     ("cStripVsPlaneEnt","StripVsPlane: NumEntries",0,0,1000,800);
03268   cStripVsPlaneEnt->SetFillColor(0);
03269   cStripVsPlaneEnt->cd();
03270   hStripVsPlaneEnt->Draw("textcolz");
03271   
03272 
03274   //Draw the kPos=kWest side
03276 
03277   TCanvas *cStripVsPlane2Led=new TCanvas
03278     ("cStripVsPlane2Led","StripVsPlane2: Led",0,0,1000,800);
03279   cStripVsPlane2Led->SetFillColor(0);
03280   cStripVsPlane2Led->cd();
03281   hStripVsPlane2Led->Draw("colz");
03282 
03283   TCanvas *cStripVsPlane2Pix=new TCanvas
03284     ("cStripVsPlane2Pix","StripVsPlane2: Pixel",0,0,1000,800);
03285   cStripVsPlane2Pix->SetFillColor(0);
03286   cStripVsPlane2Pix->cd();
03287   hStripVsPlane2Pix->Draw("textcolz");
03288   
03289   TCanvas *cStripVsPlane2Crate=new TCanvas
03290     ("cStripVsPlane2Crate","StripVsPlane2: Crate",0,0,1000,800);
03291   cStripVsPlane2Crate->SetFillColor(0);
03292   cStripVsPlane2Crate->cd();
03293   hStripVsPlane2Crate->Draw("textcolz");
03294 
03295   TCanvas *cStripVsPlane2Varc=new TCanvas
03296     ("cStripVsPlane2Varc","StripVsPlane2: Varc",0,0,1000,800);
03297   cStripVsPlane2Varc->SetFillColor(0);
03298   cStripVsPlane2Varc->cd();
03299   hStripVsPlane2Varc->Draw("textcolz");
03300  
03301   TCanvas *cStripVsPlane2Vmm=new TCanvas
03302     ("cStripVsPlane2Vmm","StripVsPlane2: Vmm",0,0,1000,800);
03303   cStripVsPlane2Vmm->SetFillColor(0);
03304   cStripVsPlane2Vmm->cd();
03305   hStripVsPlane2Vmm->Draw("textcolz");
03306 
03307   TCanvas *cStripVsPlane2Vfb=new TCanvas
03308     ("cStripVsPlane2Vfb","StripVsPlane2: Vfb",0,0,1000,800);
03309   cStripVsPlane2Vfb->SetFillColor(0);
03310   cStripVsPlane2Vfb->cd();
03311   hStripVsPlane2Vfb->Draw("textcolz");
03312 
03313   TCanvas *cStripVsPlane2VaChip=new TCanvas
03314     ("cStripVsPlane2VaChip","StripVsPlane2: VaChip",0,0,1000,800);
03315   cStripVsPlane2VaChip->SetFillColor(0);
03316   cStripVsPlane2VaChip->cd();
03317   hStripVsPlane2VaChip->Draw("textcolz");
03318 
03319   TCanvas *cStripVsPlane2Ch=new TCanvas
03320     ("cStripVsPlane2Ch","StripVsPlane2: Ch",0,0,1000,800);
03321   cStripVsPlane2Ch->SetFillColor(0);
03322   cStripVsPlane2Ch->cd();
03323   hStripVsPlane2Ch->Draw("textcolz");
03324 
03325   TCanvas *cStripVsPlane2GeoAdd=new TCanvas
03326     ("cStripVsPlane2GeoAdd","StripVsPlane2: GeoAdd",0,0,1000,800);
03327   cStripVsPlane2GeoAdd->SetFillColor(0);
03328   cStripVsPlane2GeoAdd->cd();
03329   hStripVsPlane2GeoAdd->Draw("textcolz");
03330 
03331   TCanvas *cStripVsPlane2MasterCh=new TCanvas
03332     ("cStripVsPlane2MasterCh","StripVsPlane2: Master Channel",
03333      0,0,1000,800);
03334   cStripVsPlane2MasterCh->SetFillColor(0);
03335   cStripVsPlane2MasterCh->cd();
03336   hStripVsPlane2MasterCh->Draw("textcolz");
03337 
03338   TCanvas *cStripVsPlane2MinderCh=new TCanvas
03339     ("cStripVsPlane2MinderCh","StripVsPlane2: MinderCh",0,0,1000,800);
03340   cStripVsPlane2MinderCh->SetFillColor(0);
03341   cStripVsPlane2MinderCh->cd();
03342   hStripVsPlane2MinderCh->Draw("textcolz");
03343 
03344   TCanvas *cStripVsPlane2Spot=new TCanvas
03345     ("cStripVsPlane2Spot","StripVsPlane2: Spot",0,0,1000,800);
03346   cStripVsPlane2Spot->SetFillColor(0);
03347   cStripVsPlane2Spot->cd();
03348   hStripVsPlane2Spot->Draw("textcolz");
03349 
03350   TCanvas *cStripVsPlane2Ent=new TCanvas
03351     ("cStripVsPlane2Ent","StripVsPlane2: NumEntries",0,0,1000,800);
03352   cStripVsPlane2Ent->SetFillColor(0);
03353   cStripVsPlane2Ent->cd();
03354   hStripVsPlane2Ent->Draw("textcolz");
03355   
03356   MSG("LIPlexMaps",Msg::kInfo)
03357     <<endl<<" ** Finished the PlotPlexStripMap method ** " 
03358     <<endl;
03359 }
03360 
03361 //......................................................................
03362 
03363 void LIPlexMaps::MakePinPlexTables() 
03364 {
03365   MSG("LIPlexMaps",Msg::kInfo)
03366     <<endl<<" ** Running the MakePinPlexTables() method... ** "
03367     <<endl; 
03368   
03369   //Thanks to Ryan for the DB code of this method
03370   
03371   //First fill the pin diode table
03372   VldTimeStamp farpinstart = VldTimeStamp(2000,1,1,12,0,0);
03373   VldTimeStamp farpinend = VldTimeStamp(2010,1,1,12,0,0);
03374   VldRange farpinvr(DetectorType::kFar,SimFlag::kData,farpinstart,
03375                     farpinend,"LIPlexMaps");
03376   VldTimeStamp create; // now!
03377   VldContext vc(DetectorType::kFar,SimFlag::kData,create);
03378   PlexHandle plexHandle(vc);
03379 
03380   for(Int_t pb=0;pb<NUMPULSERBOXES;pb++){
03381     for(Int_t led=1;led<=LASTPULSERBOX;led++){
03382 
03383       PlexLedId ledId(DetectorType::kFar,pb,led);
03384 
03385       int aggNo = 0x7ff & ledId.GetEncoded();
03386 
03387       DbiWriter<PlexPinDiodeToLed> writer(farpinvr,aggNo,0,create);
03388 
03389       std::pair<PlexPinDiodeId,PlexPinDiodeId> newPins=fLookup.
03390         GetPinDiodeIds(plexHandle,ledId.GetLedInBox());
03391 
03392       PlexPinDiodeToLed hpin2led(newPins.first.GetDetector(),
03393                                  newPins.first.GetElecType(),
03394                                  newPins.first.GetEastWest(),
03395                                  newPins.first.GetRackLevel(),
03396                                  newPins.first.GetRackBay(),
03397                                  newPins.first.GetInRack(),
03398                                  newPins.first.GetInBox(),
03399                                  newPins.first.GetGain(),
03400                                  ledId.GetPulserBox(),
03401                                  ledId.GetLedInBox());
03402       PlexPinDiodeToLed lpin2led(newPins.second.GetDetector(),
03403                                  newPins.second.GetElecType(),
03404                                  newPins.second.GetEastWest(),
03405                                  newPins.second.GetRackLevel(),
03406                                  newPins.second.GetRackBay(),
03407                                  newPins.second.GetInRack(),
03408                                  newPins.second.GetInBox(),
03409                                  newPins.second.GetGain(),
03410                                  ledId.GetPulserBox(),
03411                                  ledId.GetLedInBox());
03412       writer <<hpin2led;
03413       writer <<lpin2led;
03414       //writer.Close();
03415     }
03416   }
03417 
03418   MSG("LIPlexMaps",Msg::kInfo)
03419     <<endl<<" ** Finished the MakePinPlexTables() method... ** "
03420     <<endl; 
03421 }
03422 
03423 //......................................................................
03424 
03425 void LIPlexMaps::MakeCalAdcToPe(string sGainsFileName,
03426                                 DetectorType::EDetectorType det,
03427                                 SimFlag::ESimFlag simFlag,
03428                                 VldTimeStamp vldStart,
03429                                 VldTimeStamp vldEnd,
03430                                 Int_t aggNo,
03431                                 Int_t task,
03432                                 VldTimeStamp creationDate,
03433                                 std::string dbName,
03434                                 std::string sLogComment,
03435                                 Int_t gainTooHigh,Int_t gainCeiling,
03436                                 Bool_t writeToDb)
03437 {
03438   MSG("LIPlexMaps",Msg::kInfo)
03439     <<endl<<" ** Running the MakeCalAdcToPe() method... **"<<endl; 
03440   
03441   //Thanks to Ryan for the DB code of this method  
03442 
03443   //Q: What about bookends?
03444   //A: Just don't put any data in database, can't calibrate steel!
03445 
03446   //Q: What about stripends with no info?
03447   //A: Use average of that pixel.
03448 
03449   //Q: What if no info for a pixel?
03450   //A: Use the average of nearest neighbours.
03451 
03452   //Q: What about pmts with no info?
03453   //A: Use spot from a pmt that is the average of the whole detector.
03454 
03455   //Q: What about really high gains? 
03456   //A: Set error of gains over "gainTooHigh" to a high value.
03457   //   For gains over gainCeiling set gain to equal gainCeiling.
03458   //   Set the error to that for gainTooHigh.
03459 
03460   //Q: What to do about errors in above cases?
03461   //A: The errors are set to values that represent the worse case,
03462   //   where you had a two pmts from the tails of the distributions.
03463 
03464   //Q: Where to store the special values of the errors?
03465   //A: Somewhere proper eventually, but for now in cvs!
03466 
03467   //Q: What 1PE width to use?
03468   //A: The 1PE width that corresponds to the 0.8 in the gain calc
03469   //   is 0.5 of the gain. So just times gain by 0.5.
03470 
03471   //Q: How is the error calculated?
03472   //A: It is the sum of the relative errors of rms*rms/mean
03473   //   but does not include the error on the 0.8 factor.
03474 
03475   //Q: What validity range should be used?
03476   //A: For the first pass the validity is for the lifetime of the det.
03477 
03478   //some old validities
03479   //VldTimeStamp fvldstart(102,9,14,15,0,1,0);   // T11 (Far-Far) 2002
03480   //VldTimeStamp fvldend(102,10,2,0,0,0,0);   // T11 (Far-Far)2002
03481   //VldTimeStamp fvldstart(102,6,6,0,0,0,0);  // T7 June 2002
03482   //VldTimeStamp fvldend(102,6,30,0,0,0,0);  // T7 June 2002
03483   //VldTimeStamp fvldstart=VldTimeStamp(2002,10,2,0,0,1); //T7 Oct 2002
03484   //VldTimeStamp fvldend=VldTimeStamp(2002,10,18,0,0,0);  //T7 Oct 2002
03485   //VldTimeStamp fvldstart=VldTimeStamp(2003,9,26,0,0,1); //T7 ND 2003
03486   //VldTimeStamp fvldend=VldTimeStamp(2003,10,8,0,0,1);  //T7 ND 2003
03487 
03488   //only do this once to set up variables
03489   this->SetDetector(det);
03490 
03491   //get a plex handle
03492   MSG("LIPlexMaps",Msg::kInfo)<<"Getting plex handle..."<<endl;
03493   VldContext vldCtx(det,SimFlag::kData,creationDate);
03494   PlexHandle plexHandle(vldCtx);
03495 
03496   TH1F *hGain=new TH1F("hGain","PMT Gains",300,-1,gainTooHigh);
03497   hGain->GetXaxis()->SetTitle("PMT Gain");
03498   hGain->GetXaxis()->CenterTitle();
03499   hGain->GetYaxis()->SetTitle("");
03500   hGain->GetYaxis()->CenterTitle();
03501   hGain->SetLineColor(2);
03502   hGain->SetFillStyle(3015);
03503   hGain->SetFillColor(2);
03504   hGain->SetLineWidth(5);
03505   //hGain->SetBit(TH1::kCanRebin);
03506 
03507   TH1F *hGainHighPmt=new TH1F("hGainHighPmt","PMT Gains: HighPmts",
03508                               100,gainTooHigh,gainCeiling+5);
03509   hGainHighPmt->GetXaxis()->SetTitle("PMT Gain");
03510   hGainHighPmt->GetXaxis()->CenterTitle();
03511   hGainHighPmt->GetYaxis()->SetTitle("");
03512   hGainHighPmt->GetYaxis()->CenterTitle();
03513   hGainHighPmt->SetLineColor(2);
03514   hGainHighPmt->SetFillStyle(3015); 
03515   hGainHighPmt->SetFillColor(2); 
03516   hGainHighPmt->SetLineWidth(5);
03517   //hGainHighPmt->SetBit(TH1::kCanRebin);
03518 
03519   TH1F *hGainCrazyHighPmt=new TH1F("hGainCrazyHighPmt",
03520                                    "PMT Gains: CrazyHighPmts",
03521                                    200,gainCeiling,gainCeiling+100);
03522   hGainCrazyHighPmt->GetXaxis()->SetTitle("PMT Gain");
03523   hGainCrazyHighPmt->GetXaxis()->CenterTitle();
03524   hGainCrazyHighPmt->GetYaxis()->SetTitle("");
03525   hGainCrazyHighPmt->GetYaxis()->CenterTitle();
03526   hGainCrazyHighPmt->SetLineColor(2);
03527   hGainCrazyHighPmt->SetFillStyle(3015); 
03528   hGainCrazyHighPmt->SetFillColor(2); 
03529   hGainCrazyHighPmt->SetLineWidth(5);
03530   hGainCrazyHighPmt->SetBit(TH1::kCanRebin);
03531 
03532   TH1F *hGainAvDet=new TH1F("hGainAvDet","PMT Gains in Av Detector PMT",
03533                             100,55,85);
03534   hGainAvDet->GetXaxis()->SetTitle("PMT Gain");
03535   hGainAvDet->GetXaxis()->CenterTitle();
03536   hGainAvDet->GetYaxis()->SetTitle("");
03537   hGainAvDet->GetYaxis()->CenterTitle();
03538   hGainAvDet->SetLineColor(2);
03539   hGainAvDet->SetFillStyle(3015); 
03540   hGainAvDet->SetFillColor(2); 
03541   hGainAvDet->SetLineWidth(5);
03542   hGainAvDet->SetBit(TH1::kCanRebin);
03543 
03544   TH1F *hGainErr=new TH1F("hGainErr","PMT GainErrs",
03545                           400,0,110);
03546   hGainErr->GetXaxis()->SetTitle("PMT GainErr");
03547   hGainErr->GetXaxis()->CenterTitle();
03548   hGainErr->GetYaxis()->SetTitle("");
03549   hGainErr->GetYaxis()->CenterTitle();
03550   hGainErr->SetLineColor(2);
03551   hGainErr->SetFillStyle(3015); 
03552   hGainErr->SetFillColor(2); 
03553   hGainErr->SetLineWidth(5);
03554   hGainErr->SetBit(TH1::kCanRebin);
03555 
03556   TH1F *hGainErrZoom=new TH1F("hGainErrZoom","PMT GainErrs (Zoomed)",
03557                           400,0,10);
03558   hGainErrZoom->GetXaxis()->SetTitle("PMT GainErrZoom");
03559   hGainErrZoom->GetXaxis()->CenterTitle();
03560   hGainErrZoom->GetYaxis()->SetTitle("");
03561   hGainErrZoom->GetYaxis()->CenterTitle();
03562   hGainErrZoom->SetLineColor(2);
03563   hGainErrZoom->SetFillStyle(3015); 
03564   hGainErrZoom->SetFillColor(2); 
03565   hGainErrZoom->SetLineWidth(5);
03566   //hGainErrZoom->SetBit(TH1::kCanRebin);
03567 
03568   TH1F *hGainErrFract=new TH1F("hGainErrFract",
03569                                "Fractional PMT GainErrs",
03570                                800,0.005,0.05);
03571   hGainErrFract->GetXaxis()->SetTitle("Fractional PMT GainErr");
03572   hGainErrFract->GetXaxis()->CenterTitle();
03573   hGainErrFract->GetYaxis()->SetTitle("");
03574   hGainErrFract->GetYaxis()->CenterTitle();
03575   hGainErrFract->SetLineColor(2);
03576   hGainErrFract->SetFillStyle(3015); 
03577   hGainErrFract->SetFillColor(2); 
03578   hGainErrFract->SetLineWidth(5);
03579   //hGainErrFract->SetBit(TH1::kCanRebin);
03580 
03581   TH1F *hSPEWidth=new TH1F("hSPEWidth","PMT SPEWidths",
03582                            300,0,gainCeiling/2+5);
03583   hSPEWidth->GetXaxis()->SetTitle("PMT SPEWidth");
03584   hSPEWidth->GetXaxis()->CenterTitle();
03585   hSPEWidth->GetYaxis()->SetTitle("");
03586   hSPEWidth->GetYaxis()->CenterTitle();
03587   hSPEWidth->SetLineColor(2);
03588   hSPEWidth->SetFillStyle(3015); 
03589   hSPEWidth->SetFillColor(2); 
03590   hSPEWidth->SetLineWidth(5);
03591   //hSPEWidth->SetBit(TH1::kCanRebin);
03592 
03593   Int_t* planeMax=new Int_t[NUMCRATES];
03594   Int_t* planeMin=new Int_t[NUMCRATES];
03595   fLookup.SetPbPlanes(planeMin,planeMax,det);
03596   
03597   const Int_t firstStripBin=FIRSTSTRIP-8;//-8;
03598   const Int_t lastStripBin=LASTSTRIP+9;//200;
03599   const Int_t bins=lastStripBin-firstStripBin;
03600 
03601   TH2F **hStripVsPlaneGain=0;
03602   hStripVsPlaneGain= new TH2F*[NUMCRATES];
03603   for (Int_t i=0;i<NUMCRATES;i++){
03604     string sPb=Form("%d",i);
03605     fS="Gains (Crate "+sPb+")";
03606     hStripVsPlaneGain[i]=new TH2F(fS.c_str(),fS.c_str(),
03607                                   planeMax[i]-planeMin[i],
03608                                   planeMin[i],planeMax[i],
03609                                   bins,firstStripBin,lastStripBin);
03610     hStripVsPlaneGain[i]->GetXaxis()->SetTitle("Plane");
03611     hStripVsPlaneGain[i]->GetXaxis()->CenterTitle();
03612     hStripVsPlaneGain[i]->GetYaxis()->SetTitle("Strip");
03613     hStripVsPlaneGain[i]->GetYaxis()->CenterTitle();
03614     hStripVsPlaneGain[i]->SetFillColor(0);
03615     //hStripVsPlaneGain[i]->SetBit(TH1::kCanRebin);
03616   }
03617 
03618   TH2F **hStripVsPlaneGainErr=0;
03619   hStripVsPlaneGainErr= new TH2F*[NUMCRATES];
03620   for (Int_t i=0;i<NUMCRATES;i++){
03621     string sPb=Form("%d",i);
03622     fS="Gain Errors (Crate "+sPb+")";
03623     hStripVsPlaneGainErr[i]=new TH2F(fS.c_str(),fS.c_str(),
03624                                      planeMax[i]-planeMin[i],
03625                                      planeMin[i],planeMax[i],
03626                                      bins,firstStripBin,lastStripBin);
03627     hStripVsPlaneGainErr[i]->GetXaxis()->SetTitle("Plane");
03628     hStripVsPlaneGainErr[i]->GetXaxis()->CenterTitle();
03629     hStripVsPlaneGainErr[i]->GetYaxis()->SetTitle("Strip");
03630     hStripVsPlaneGainErr[i]->GetYaxis()->CenterTitle();
03631     hStripVsPlaneGainErr[i]->SetFillColor(0);
03632     //hStripVsPlaneGainErr[i]->SetBit(TH1::kCanRebin);
03633   }
03634    
03635   TH2F **hStripVsPlaneSPEWidth=0;
03636   hStripVsPlaneSPEWidth= new TH2F*[NUMCRATES];
03637   for (Int_t i=0;i<NUMCRATES;i++){
03638     string sPb=Form("%d",i);
03639     fS="Single PE Width (Crate "+sPb+")";
03640     hStripVsPlaneSPEWidth[i]=new TH2F(fS.c_str(),fS.c_str(),
03641                                      planeMax[i]-planeMin[i],
03642                                      planeMin[i],planeMax[i],
03643                                      bins,firstStripBin,lastStripBin);
03644     hStripVsPlaneSPEWidth[i]->GetXaxis()->SetTitle("Plane");
03645     hStripVsPlaneSPEWidth[i]->GetXaxis()->CenterTitle();
03646     hStripVsPlaneSPEWidth[i]->GetYaxis()->SetTitle("Strip");
03647     hStripVsPlaneSPEWidth[i]->GetYaxis()->CenterTitle();
03648     hStripVsPlaneSPEWidth[i]->SetFillColor(0);
03649     //hStripVsPlaneSPEWidth[i]->SetBit(TH1::kCanRebin);
03650   }
03651 
03652   vector<Float_t> vGains(NUMPLANES*NUMSTRIPS*NUMENDS,0);
03653   vector<Float_t> vGainErrs(NUMPLANES*NUMSTRIPS*NUMENDS,0);
03654   vector<Float_t> vSPEWidths(NUMPLANES*NUMSTRIPS*NUMENDS,0);
03655   map<UInt_t,LIPmt> pmts;
03656   LIPmt avDetPmt;
03657   avDetPmt.Initialise(NUMPIXELS,NUMPIXELSPOTS);
03658 
03659   //variables to hold the average for whole detector
03660   Float_t gainAvDet=0;
03661   Float_t gainErrAvDet=0;
03662   Int_t gainNum=0;
03663  
03664   Float_t gainErrUnknownPixelSpot=10;//reflect variation in a pixel
03665   Float_t gainErrUnknownPixel=40;//reflect variation between NN
03666   Float_t gainErrUnknownNN=50;//reflect variation between worst pixels
03667   Float_t gainErrUnknownPmt=100;//reflect variations between worst pmts
03668   Float_t gainErrTooHighGain=90;//if cut is 150, ie could be 60
03669   Float_t SPEWidthFraction=0.5;//corresponds to the 0.8 used in gain 
03670   
03671   //open the file  
03672   MSG("LIPlexMaps",Msg::kInfo)
03673     <<"Opening file "<<sGainsFileName<<"..."<<endl;
03674   ifstream gainsFile(sGainsFileName.c_str());
03675 
03676   //check if file exists
03677   if (gainsFile){
03678 
03679     //variables to hold input from file
03680     Int_t plane=-1;
03681     Int_t strip=-1;
03682     Int_t end=-1;
03683     Float_t gain=-1;
03684     Float_t gainErr=-1;
03685     Float_t SPEWidth=-1;
03686 
03687     //printing control
03688     Int_t lastPlane=-1;
03689    
03690     //read in from the text file and fill objects
03691     while(gainsFile>>plane>>strip>>end>>gain>>gainErr>>SPEWidth) {
03692 
03693       Int_t seIndex=plane*NUMSTRIPS*NUMENDS+strip*NUMENDS+end-1;
03694 
03695       if (plane<FIRSTPLANE || plane>LASTPLANE || strip<FIRSTSTRIP || 
03696           strip>LASTSTRIP || end<FIRSTEND || end>LASTEND){
03697         MSG("LIPlexMaps",Msg::kWarning)
03698           <<"Plane, strip or stripend are out of range: plane="<<plane
03699           <<", strip="<<strip<<", end="<<end<<endl
03700           <<"Detector type is set to "<<DetectorType::AsString(det)
03701           <<endl
03702           <<"Program will exit here..."<<endl;
03703         exit(1);
03704       }
03705 
03706       //print stuff
03707       if (plane!=lastPlane && plane%20==0){
03708         MSG("LIPlexMaps",Msg::kInfo)<<"New plane="<<plane<<endl;
03709       }
03710       else if (plane!=lastPlane){
03711         MSG("LIPlexMaps",Msg::kDebug)<<"New plane="<<plane<<endl;
03712       }
03713       lastPlane=plane;
03714         
03715       //put file gains into vectors
03716       vGains[seIndex]=gain;
03717       vGainErrs[seIndex]=gainErr;
03718       vSPEWidths[seIndex]=SPEWidth;
03719       
03720       //sanity check
03721       if (gain>-1 && gain<2){
03722         MSG("LIPlexMaps",Msg::kWarning)
03723           <<"What sort of gain is this? gain="<<gain<<endl;
03724       }
03725 
03726       //get stripend id
03727       PlexStripEndId seid(det,plane,strip,
03728                           static_cast<StripEnd::EStripEnd>(end));
03729       //get pixel spot id
03730       PlexPixelSpotId pixSpotId=plexHandle.GetPixelSpotId(seid);
03731 
03732       MSG("LIPlexMaps",Msg::kVerbose)
03733         <<"("<<plane<<":"<<strip<<":"<<end<<") "
03734         <<pixSpotId.AsString()<<endl;
03735 
03736       UInt_t pmtKey=pixSpotId.GetUniquePmtEncodedValue();
03737       //initialise pmt object (only done if first time)
03738       pmts[pmtKey].Initialise(NUMPIXELS,NUMPIXELSPOTS);
03739     
03740       //only add value if there is one
03741       if (gain>-1){
03742         gainErrAvDet+=gainErr;
03743         gainAvDet+=gain;
03744         gainNum++;
03745 
03746         if (pixSpotId.GetSpot()<1){
03747           seid.Print();
03748           pixSpotId.Print();
03749         }
03750 
03751         pmts[pmtKey].SetPoint(pixSpotId.GetPixel(),pixSpotId.GetSpot(),
03752                               gain);
03753         //add point to average detector PMT
03754         avDetPmt.AddMultiPoint(pixSpotId.GetPixel(),pixSpotId.GetSpot(),
03755                                gain);
03756       }
03757     }
03758   }
03759   else{
03760     MSG("LIPlexMaps",Msg::kInfo)
03761       <<"Can't open file "<<sGainsFileName<<endl
03762       <<"Exiting here..."<<endl;
03763     exit(1);
03764   }
03765   //calculate the average gain
03766   if (gainNum!=0) gainAvDet/=gainNum;
03767   if (gainNum!=0) gainErrAvDet/=gainNum;
03768   MSG("LIPlexMaps",Msg::kInfo)
03769     <<"Average detector gain="<<gainAvDet<<", gainErr="<<gainErrAvDet
03770     <<", num pmts="<<pmts.size()<<endl;
03771   //fill the histogram with all the gains
03772   avDetPmt.FillGainsHisto(hGainAvDet);
03773 
03775   //Section to write to database
03777 
03778   Int_t pixCounter=0;
03779   Int_t nnCounter=0;
03780   Int_t pmtCounter=0;
03781   Int_t detCounter=0;
03782   Int_t gainHighCounter=0;
03783   Int_t gainCappedCounter=0;
03784   Int_t totalCounter=0;
03785   Int_t goodCounter=0;
03786 
03787   //make validity range
03788   VldRange vr(det,simFlag,vldStart,vldEnd,
03789               "LISummary/LIPlexMaps::MakeCalADCtoPE");
03790   MSG("LIPlexMaps",Msg::kInfo)
03791     <<"Using Validity Range: "<<vr.AsString()<<endl;
03792 
03793   //create the writer
03794   DbiWriter<CalADCtoPE> writer(vr,aggNo,task,creationDate,dbName,
03795                                sLogComment);
03796    
03797   //loop over all strip ends
03798   for(Int_t pl=FIRSTSCINTPLANE;pl<=LASTSCINTPLANE;pl++){
03799     for(Int_t st=FIRSTSTRIP;st<=LASTSTRIP;st++){
03800       for(Int_t end=FIRSTEND;end<=SECONDEND;end++) {
03801         
03802         //ignore the bookends
03803         if ((pl==SM1BOOKEND || pl==SM2BOOKEND) && 
03804             det==DetectorType::kFar) continue;
03805 
03806         //if (pl>70) continue;
03807         //if (pl==70) exit(1);
03808 
03809         //calculate the index
03810         Int_t seIndex=pl*NUMSTRIPS*NUMENDS+st*NUMENDS+end-1;
03811 
03812         //get the stripend id
03813         PlexStripEndId seid(det,pl,st,
03814                             static_cast<StripEnd::EStripEnd>(end));
03815 
03816         // check whether stripend actually exists
03817         if (!seid.IsValid() ) continue;
03818         
03819         // in the near detector, a further check is needed:
03820         // partial U planes have strips 0-63
03821         // partial V planes have strips 4-67
03822         if (det==DetectorType::kNear) {
03823           if (((pl-1)%5) && (pl%2)    && st>63) continue;
03824           if (((pl-1)%5) && (pl%2)==0 && st<4 ) continue;
03825         }
03826 
03827         if(vGains[seIndex]==-1){
03828 
03829           //get pixel spot id
03830           PlexPixelSpotId pixSpotId=plexHandle.GetPixelSpotId(seid);
03831           Int_t pmtKey=pixSpotId.GetUniquePmtEncodedValue();
03832 
03833           //get pmt gains etc
03834           Double_t pmtGain=pmts[pmtKey].GetAvPmtGain();
03835           Int_t pmtNum=pmts[pmtKey].GetPmtNum();
03836           Double_t pixelGain=pmts[pmtKey].GetPixelGain(pixSpotId.
03837                                                        GetPixel());
03838           Int_t pixelNum=pmts[pmtKey].GetPixelNum(pixSpotId.GetPixel());
03839           Double_t nnGain=pmts[pmtKey].
03840             GetNearestNeighboursAvGain(pixSpotId.GetPixel());
03841           Int_t nnNum=pmts[pmtKey].
03842             GetNearestNeighboursNum(pixSpotId.GetPixel());
03843 
03844           Bool_t pixGood=false;
03845           Bool_t nnGood=false;
03846           Bool_t pmtGood=false;
03847 
03848           if (pixelNum>0 && pixelGain>0) pixGood=true;
03849           if (nnNum>0 && nnGain>0) nnGood=true;
03850           if (pmtNum>0 && pmtGain>0) pmtGood=true;
03851          
03852           if (pixGood){
03853             pixCounter++;
03854             vGains[seIndex]=pixelGain;
03855             vGainErrs[seIndex]=gainErrUnknownPixelSpot;
03856             vSPEWidths[seIndex]=SPEWidthFraction*vGains[seIndex];
03857             if (MsgService::Instance()->
03858                 IsActive("LIPlexMaps",Msg::kDebug)){
03859               MSG("LIPlexMaps",Msg::kInfo)
03860                 <<"("<<pl<<":"<<st<<":"<<end<<")"
03861                 <<" No Data: Setting gain to be average of pixel ("
03862                 <<vGains[seIndex]<<")"<<endl
03863                 <<" pixGain="<<pixelGain<<" (N="<<pixelNum
03864                 <<"), nnGain="<<nnGain<<" (N="<<nnNum
03865                 <<"), pmtGain="<<pmtGain<<", (N="<<pmtNum<<")"<<endl;
03866             }
03867           }
03868           else if (nnGood){
03869             nnCounter++;
03870             vGains[seIndex]=nnGain;
03871             vGainErrs[seIndex]=gainErrUnknownPixel;
03872             vSPEWidths[seIndex]=SPEWidthFraction*vGains[seIndex];
03873             MSG("LIPlexMaps",Msg::kInfo)
03874               <<"("<<pl<<":"<<st<<":"<<end<<")"
03875               <<" No Data: Setting gain to be average of NN ("
03876               <<vGains[seIndex]<<")"<<endl
03877               <<" pixGain="<<pixelGain<<" (N="<<pixelNum
03878               <<"), nnGain="<<nnGain<<" (N="<<nnNum
03879               <<"), pmtGain="<<pmtGain<<", (N="<<pmtNum<<")"<<endl;
03880           }
03881           else if (pmtGood){
03882             pmtCounter++;
03883             vGains[seIndex]=pmtGain;
03884             vGainErrs[seIndex]=gainErrUnknownNN;
03885             vSPEWidths[seIndex]=SPEWidthFraction*vGains[seIndex];
03886             MSG("LIPlexMaps",Msg::kInfo)
03887               <<"("<<pl<<":"<<st<<":"<<end<<")"
03888               <<" No Data: Setting gain to be average of pmt ("
03889               <<vGains[seIndex]<<")"<<endl
03890               <<" pixGain="<<pixelGain<<" (N="<<pixelNum
03891               <<"), nnGain="<<nnGain<<" (N="<<nnNum
03892               <<"), pmtGain="<<pmtGain<<", (N="<<pmtNum<<")"<<endl;
03893           }
03894           else{
03895             detCounter++;
03896 
03897             //get pixel spot id
03898             PlexPixelSpotId pixSpotId=plexHandle.GetPixelSpotId(seid);
03899             Double_t avDetPmtGain=avDetPmt.GetAvPmtGain();
03900             Int_t avDetPmtNum=avDetPmt.GetPmtNum();
03901             Double_t avDetPmtPixelGain=avDetPmt.
03902               GetPixelGain(pixSpotId.GetPixel());
03903             Int_t avDetPmtPixelNum=avDetPmt.
03904               GetPixelNum(pixSpotId.GetPixel());
03905 
03906             Double_t avDetPmtSpotGain=avDetPmt.
03907               GetGain(pixSpotId.GetPixel(),pixSpotId.GetSpot());
03908 
03909             vGains[seIndex]=avDetPmtSpotGain;
03910             vGainErrs[seIndex]=gainErrUnknownPmt;
03911             vSPEWidths[seIndex]=SPEWidthFraction*vGains[seIndex];
03912             MSG("LIPlexMaps",Msg::kInfo)
03913               <<"("<<pl<<":"<<st<<":"<<end<<")"
03914               <<" No Data: Setting gain to same spot on average pmt ("
03915               <<vGains[seIndex]<<")"<<endl
03916               <<" pixGain="<<avDetPmtPixelGain
03917               <<", pixNum="<<avDetPmtPixelNum
03918               <<", pmtGain="<<avDetPmtGain
03919               <<", pmtNum="<<avDetPmtNum<<endl;
03920           }
03921         }
03922         else{
03923           goodCounter++;
03924         }
03925 
03926         //check that the gains aren't too high
03927         if(vGains[seIndex]>gainTooHigh){
03928           //have to decrement the goodCounter if gain is too high
03929           goodCounter--;
03930           //count the high gains
03931           gainHighCounter++;
03932 
03933           //get pixel spot id
03934           PlexPixelSpotId pixSpotId=plexHandle.GetPixelSpotId(seid);
03935           Int_t pmtKey=pixSpotId.GetUniquePmtEncodedValue();
03936           
03937           //get pmt gains etc
03938           Double_t pmtGain=pmts[pmtKey].GetAvPmtGain();
03939           Int_t pmtNum=pmts[pmtKey].GetPmtNum();
03940           Double_t pixelGain=pmts[pmtKey].GetPixelGain(pixSpotId.
03941                                                        GetPixel());
03942           Int_t pixelNum=pmts[pmtKey].GetPixelNum(pixSpotId.GetPixel());
03943 
03944           if (vGains[seIndex]>gainCeiling){
03945             hGainCrazyHighPmt->Fill(vGains[seIndex]);
03946 
03947             gainCappedCounter++;
03948             Float_t oldGain=vGains[seIndex];
03949             vGains[seIndex]=gainCeiling;
03950             vSPEWidths[seIndex]=SPEWidthFraction*vGains[seIndex];
03951 
03952             MSG("LIPlexMaps",Msg::kInfo)
03953               <<"("<<pl<<":"<<st<<":"<<end<<")"
03954               <<" ** Capping very high gain ("<<oldGain
03955               <<") to be gainCeiling ("<<vGains[seIndex]<<")"<<endl
03956               <<" pixGain="<<pixelGain<<", pixNum="<<pixelNum
03957               <<", pmtGain="<<pmtGain<<", pmtNum="<<pmtNum<<endl;
03958           }
03959             
03960           //the gain error is the same whether it was capped or not
03961           vGainErrs[seIndex]=gainErrTooHighGain;
03962 
03963           //fill the histo for high gain pmts
03964           hGainHighPmt->Fill(vGains[seIndex]);
03965         }
03966     
03967         //create CALADCTOPE table row
03968         CalADCtoPE calAdcToPe(seid.BuildPlnStripEndKey(),
03969                               seid.GetEncoded(),vGains[seIndex],
03970                               vGainErrs[seIndex],vSPEWidths[seIndex]);
03971             
03972         //fill the histos
03973         hGain->Fill(vGains[seIndex]);
03974         hGainErr->Fill(vGainErrs[seIndex]);
03975         hGainErrZoom->Fill(vGainErrs[seIndex]);
03976         hGainErrFract->Fill(vGainErrs[seIndex]/vGains[seIndex]);
03977         hSPEWidth->Fill(vSPEWidths[seIndex]);
03978 
03979         Int_t crate=Plane2Crate(pl,end,det);
03980         if (crate>=FIRSTCRATE && crate<=LASTCRATE){
03981           hStripVsPlaneGain[crate]->Fill(pl,st,vGains[seIndex]);
03982           hStripVsPlaneGainErr[crate]->Fill(pl,st,vGainErrs[seIndex]);
03983           hStripVsPlaneSPEWidth[crate]->
03984             Fill(pl,st,vSPEWidths[seIndex]);
03985         }
03986 
03987         //write the row to the dbiwriter
03988         writer<<calAdcToPe;
03989         //count the number of strips written out
03990         totalCounter++;
03991         
03992         if (MsgService::Instance()->
03993             IsActive("LIPlexMaps",Msg::kVerbose)){
03994           MSG("LIPlexMaps",Msg::kInfo)
03995             <<"("<<pl<<":"<<st<<":"<<end<<")"   
03996             <<" "<<vGains[seIndex]<<"  " 
03997             <<vGainErrs[seIndex]<<" "<<vSPEWidths[seIndex]<<endl;
03998         }
03999       }
04000     }
04001   }
04002   
04003   MSG("LIPlexMaps",Msg::kInfo)
04004     <<"DbiWriter.IsOpen="<<writer.IsOpen()<<endl
04005     <<"DbiWriter.CanOutput="<<writer.CanOutput()<<endl;
04006   
04007   MSG("LIAnalysis",Msg::kInfo)
04008     <<endl
04009     <<" ** Values used in method: **"<<endl
04010     <<" NUMPLANES="<<NUMPLANES<<endl
04011     <<" NUMSTRIPS="<<NUMSTRIPS<<endl
04012     <<" NUMENDS="<<NUMENDS<<endl
04013     <<" NUMBOOKENDS="<<NUMBOOKENDS<<endl;
04014 
04015     if (det==DetectorType::kNear) {
04016       MSG("LIAnalysis",Msg::kInfo)
04017         << " Total number of strip ends=" << 11616 << endl;
04018     } 
04019     else {
04020       MSG("LIAnalysis",Msg::kInfo)
04021         <<" Total number of strip ends="
04022         <<(NUMPLANES*NUMSTRIPS*NUMENDS)-(NUMBOOKENDS*NUMSTRIPS*NUMENDS)
04023         <<endl;
04024     }
04025 
04026   Int_t totalCounted=goodCounter+pixCounter+nnCounter+pmtCounter+
04027     detCounter+gainHighCounter;
04028   Int_t numBadStripends=totalCounted-goodCounter;
04029 
04030   MSG("LIPlexMaps",Msg::kInfo)
04031     <<endl
04032     <<" ** Job Summary **"<<endl
04033     <<" Num good stripends="<<goodCounter
04034     <<"  ("<<100.*goodCounter/totalCounted<<"%)"<<endl
04035     <<" Num bad stripends="<<numBadStripends
04036     <<"  ("<<100.*numBadStripends/totalCounted<<"%)"<<endl
04037     <<"   with average pixel value="<<pixCounter
04038     <<"  ("<<100.*pixCounter/totalCounted<<"%)"<<endl
04039     <<"   with average NN value="<<nnCounter
04040     <<"  ("<<100.*nnCounter/totalCounted<<"%)"<<endl
04041     <<"   with average PMT value="<<pmtCounter
04042     <<"  ("<<100.*pmtCounter/totalCounted<<"%)"<<endl
04043     <<"   with average-detector-PMT value="<<detCounter
04044     <<"  ("<<100.*detCounter/totalCounted<<"%)  Equiv. num PMTs="
04045     <<1.*detCounter/(NUMPIXELS*NUMPIXELSPOTS)<<endl
04046     <<"   with too high gain="<<gainHighCounter
04047     <<"  ("<<100.*gainHighCounter/totalCounted<<"%)"<<endl
04048     <<"   with gain capped="<<gainCappedCounter//not include
04049     <<"  ("<<100.*gainCappedCounter/totalCounted<<"%)"<<endl
04050     <<" Sum of above="<<totalCounted<<endl
04051     <<" Total num written to DB="<<totalCounter<<endl;
04052 
04053   if (writeToDb){
04054     if (this->IsPermitted()){
04055       MSG("LIPlexMaps",Msg::kInfo)
04056         <<"Writing to database..."<<endl;
04057       //this is the line that actually writes to the database
04058       writer.Close();
04059       MSG("LIPlexMaps",Msg::kInfo)
04060         <<"Finished writing to database"<<endl;
04061     }
04062   }
04063   else {
04064     MSG("LIPlexMaps",Msg::kInfo)
04065       <<"Mode is set to NOT write to database"<<endl;
04066   }
04067 
04068   //set stats info
04069   gStyle->SetOptStat(1111111);
04070 
04071   //draw gains
04072   TCanvas *cGain=new TCanvas("cGain","PMT Gain",0,0,1000,600);
04073   cGain->SetFillColor(0);
04074   cGain->cd();
04075   hGain->Draw();
04076 
04077   //draw gains
04078   TCanvas *cGainHighPmt=new TCanvas("cGainHighPmt","PMT Gain: HighPmts",
04079                                     0,0,1000,600);
04080   cGainHighPmt->SetFillColor(0);
04081   cGainHighPmt->cd();
04082   hGainHighPmt->Draw();
04083   cGainHighPmt->SetLogy();
04084 
04085   //draw crazy gains
04086   TCanvas *cGainCrazyHighPmt=new TCanvas("cGainCrazyHighPmt",
04087                                          "PMT Gain: CrazyHighPmts",
04088                                          0,0,1000,600);
04089   cGainCrazyHighPmt->SetFillColor(0);
04090   cGainCrazyHighPmt->cd();
04091   hGainCrazyHighPmt->Draw();
04092 
04093   //draw gain errs  
04094   TCanvas *cGainErr=new TCanvas("cGainErr","PMT GainErr",0,0,1000,600);
04095   cGainErr->SetFillColor(0);
04096   cGainErr->cd();
04097   hGainErr->Draw();
04098   cGainErr->SetLogy();
04099 
04100   //draw gain errs zoom
04101   TCanvas *cGainErrZoom=new TCanvas("cGainErrZoom","PMT GainErrZoom",
04102                                     0,0,1000,600);
04103   cGainErrZoom->SetFillColor(0);
04104   cGainErrZoom->cd();
04105   hGainErrZoom->Draw();
04106 
04107   //draw gain errs fract
04108   TCanvas *cGainErrFract=new TCanvas("cGainErrFract","PMT GainErrFract",
04109                                      0,0,1000,600);
04110   cGainErrFract->SetFillColor(0);
04111   cGainErrFract->cd();
04112   hGainErrFract->Draw();
04113 
04114   //draw SPEWidths
04115   TCanvas *cSPEWidth=new TCanvas("cSPEWidth","PMT SPEWidth",
04116                                  0,0,1000,600);
04117   cSPEWidth->SetFillColor(0);
04118   cSPEWidth->cd();
04119   hSPEWidth->Draw();
04120   
04121   //draw gainAvDets
04122   TCanvas *cGainAvDet=new TCanvas("cGainAvDet",
04123                                   "Gains of Av. PMT in Detector",
04124                                   0,0,1000,600);
04125   cGainAvDet->SetFillColor(0);
04126   cGainAvDet->cd();
04127   hGainAvDet->Draw();
04128 
04129   //do the gains
04130   TCanvas *cStripVsPlaneGain=new TCanvas
04131     ("cStripVsPlaneGain","StripVsPlane: Gain",0,0,1000,800);
04132   cStripVsPlaneGain->SetFillColor(0);
04133   cStripVsPlaneGain->cd();
04134   string sDbGains="DbGainsNew";
04135   sDbGains+=DetectorType::AsString(static_cast<DetectorType::
04136                                    EDetectorType>(det));
04137   sDbGains+=".ps";
04138   cStripVsPlaneGain->Print((sDbGains+"[").c_str());
04139   gErrorIgnoreLevel=1;
04140   //set stats info off
04141   gStyle->SetOptStat(0);
04142   for (Int_t i=0;i<NUMCRATES;i++){  
04143     cStripVsPlaneGain->Clear();
04144     hStripVsPlaneGain[i]->Draw("colz");
04145     cStripVsPlaneGain->Print(sDbGains.c_str());
04146   }
04147   //print 1D histos at the end
04148   //set stats on
04149   gStyle->SetOptStat(1111111);
04150   cGain->Print(sDbGains.c_str());
04151   cGainAvDet->Print(sDbGains.c_str());
04152   cGainHighPmt->Print(sDbGains.c_str());
04153   cGainCrazyHighPmt->Print(sDbGains.c_str());
04154   //close the file
04155   cStripVsPlaneGain->Print((sDbGains+"]").c_str());
04156   gErrorIgnoreLevel=0;
04157 
04158   //do the gain errors
04159   TCanvas *cStripVsPlaneGainErr=new TCanvas
04160     ("cStripVsPlaneGainErr","StripVsPlane: GainErr",0,0,1000,800);
04161   cStripVsPlaneGainErr->SetFillColor(0);
04162   cStripVsPlaneGainErr->cd();
04163   string sDbGainErrs="DbGainErrsNew";
04164   sDbGainErrs+=DetectorType::AsString(static_cast<DetectorType::
04165                                        EDetectorType>(det));
04166   sDbGainErrs+=".ps";
04167   cStripVsPlaneGainErr->Print((sDbGainErrs+"[").c_str());
04168   gErrorIgnoreLevel=1;
04169   //set stats off
04170   gStyle->SetOptStat(0);
04171   for (Int_t i=0;i<NUMCRATES;i++){  
04172     cStripVsPlaneGainErr->Clear();
04173     hStripVsPlaneGainErr[i]->Draw("colz");
04174     hStripVsPlaneGainErr[i]->SetMaximum(2.0*gainErrAvDet);
04175     cStripVsPlaneGainErr->Print(sDbGainErrs.c_str());
04176   }
04177   //print 1D histo at the end
04178   //set stats on
04179   gStyle->SetOptStat(1111111);
04180   cGainErr->Print(sDbGainErrs.c_str());
04181   cGainErrZoom->Print(sDbGainErrs.c_str());
04182   cGainErrFract->Print(sDbGainErrs.c_str());
04183   //close the file
04184   cStripVsPlaneGainErr->Print((sDbGainErrs+"]").c_str());
04185   gErrorIgnoreLevel=0;
04186 
04188   //do SPEWidths
04190   TCanvas *cStripVsPlaneSPEWidth=new TCanvas
04191     ("cStripVsPlaneSPEWidth","StripVsPlane: SPEWidth",0,0,1000,800);
04192   cStripVsPlaneSPEWidth->SetFillColor(0);
04193   cStripVsPlaneSPEWidth->cd();
04194   string sDbSPEWidths="DbSPEWidthsNew";
04195   sDbSPEWidths+=DetectorType::AsString(static_cast<DetectorType::
04196                                        EDetectorType>(det));
04197   sDbSPEWidths+=".ps";
04198   cStripVsPlaneSPEWidth->Print((sDbSPEWidths+"[").c_str());
04199   gErrorIgnoreLevel=1;
04200   //set stats off
04201   gStyle->SetOptStat(0);
04202   for (Int_t i=0;i<NUMCRATES;i++){  
04203     cStripVsPlaneSPEWidth->Clear();
04204     hStripVsPlaneSPEWidth[i]->Draw("colz");
04205     cStripVsPlaneSPEWidth->Print(sDbSPEWidths.c_str());
04206   }
04207   //print 1D histo at the end
04208   //set stats on
04209   gStyle->SetOptStat(1111111);
04210   cSPEWidth->Print(sDbSPEWidths.c_str());
04211   //close the file
04212   cStripVsPlaneSPEWidth->Print((sDbSPEWidths+"]").c_str());
04213   gErrorIgnoreLevel=0;
04214 
04215   //set stats info on
04216   gStyle->SetOptStat(1111111);
04217 
04218   MSG("LIPlexMaps",Msg::kInfo)
04219     <<endl<<" ** Finished the MakeCalAdcToPe method... ** "<<endl;
04220 }
04221 
04222 //......................................................................
04223 
04224 void LIPlexMaps::DumpCalStripToStrip(std::string sDataFileName,
04225                                      DetectorType::EDetectorType det,
04226                                      SimFlag::ESimFlag simFlag,
04227                                      VldTimeStamp ts,Int_t task) const
04228 {
04229   MSG("LIPlexMaps",Msg::kInfo)
04230     <<endl<<" ** Running the DumpCalStripToStrip() method... **"<<endl;
04231 
04232   DbiResultPtr<CalStripToStrip> dbiCalStripToStrip;
04233   VldContext vldCtx(det,simFlag,ts);
04234   UInt_t numRows=dbiCalStripToStrip.NewQuery(vldCtx,task);
04235   
04236   //open the file  
04237   MSG("LIPlexMaps",Msg::kInfo)
04238     <<"Opening file "<<sDataFileName<<"..."<<endl;
04239   ofstream odataFile(sDataFileName.c_str());
04240 
04241   MSG("LIPlexMaps",Msg::kInfo)
04242     <<"New DB query produced "<<numRows<<" rows"
04243     <<", using task="<<task<<endl
04244     <<"Looping over rows..."<<endl;
04245   //loop over the rows
04246   for(UInt_t i=0;i<numRows;i++) {
04247     const CalStripToStrip* calStripToStrip=dbiCalStripToStrip.GetRow(i);
04248     
04249     Int_t seid_enc=calStripToStrip->GetStripEndId().GetEncoded();    
04250     Float_t resp=calStripToStrip->GetResponse();
04251     Float_t respErr=calStripToStrip->GetResponseErr();
04252     
04253     odataFile<<seid_enc<<"\t"<<resp<<"\t"<<respErr<<endl;
04254   }
04255   MSG("LIPlexMaps",Msg::kInfo)
04256     <<"Output file completed"<<endl;
04257 
04258   MSG("LIPlexMaps",Msg::kInfo)
04259     <<endl<<" ** Finished the DumpCalStripToStrip method... ** "<<endl;
04260 }
04261 
04262 //......................................................................
04263 
04264 void LIPlexMaps::MakeCalStripToStrip(std::string sDataFileName,
04265                                      DetectorType::EDetectorType det,
04266                                      SimFlag::ESimFlag simFlag,
04267                                      VldTimeStamp vldStart,
04268                                      VldTimeStamp vldEnd,
04269                                      Int_t aggNo,
04270                                      Int_t task,
04271                                      VldTimeStamp creationDate,
04272                                      std::string dbName,
04273                                      std::string sLogComment,
04274                                      Bool_t writeToDb) const
04275 {
04276   MSG("LIPlexMaps",Msg::kInfo)
04277     <<endl<<" ** Running the MakeCalStripToStrip() method... **"<<endl; 
04278   
04279   //open the file  
04280   MSG("LIPlexMaps",Msg::kInfo)
04281     <<"Opening file "<<sDataFileName<<"..."<<endl;
04282   ifstream dataFile(sDataFileName.c_str());
04283 
04284   if (!dataFile){
04285     MSG("LIPlexMaps",Msg::kInfo)
04286       <<"Can't open file "<<sDataFileName<<endl
04287       <<"Exiting here..."<<endl;
04288     exit(1);
04289   }
04290  
04291   //make validity range
04292   VldRange vr(det,simFlag,vldStart,vldEnd,
04293               "LISummary/LIPlexMaps::MakeCalStripToStrip");
04294   MSG("LIPlexMaps",Msg::kInfo)
04295     <<"Using Validity Range: "<<vr.AsString()<<endl;
04296   
04297   MSG("LIPlexMaps",Msg::kInfo)
04298     <<"Log comment="<<sLogComment<<endl;
04299 
04300   //create the writer
04301   DbiWriter<CalStripToStrip> writer(vr,aggNo,task,creationDate,dbName,
04302                                     sLogComment);
04303    
04304   Int_t seid_enc=-1;
04305   Float_t resp=-1;
04306   Float_t respErr=-1;
04307   
04308   Int_t counter=0;
04309 
04310   //read in from the text file and fill objects
04311   while(dataFile>>seid_enc>>resp>>respErr) {
04312     
04313     MAXMSG("LIPlexMaps",Msg::kInfo,100)
04314       <<"Found line in file: seid_enc="<<seid_enc
04315       <<", resp="<<resp<<", respErr="<<respErr<<endl;
04316 
04317     //create CALADCTOPE table row
04318     CalStripToStrip calStripToStrip(seid_enc,resp,respErr);
04319     //Int_t seid_enc, Float_t resp, Float_t respErr)
04320     
04321     //write the row to the dbiwriter
04322     writer<<calStripToStrip;
04323 
04324     counter++;
04325   }
04326 
04327   MSG("LIPlexMaps",Msg::kInfo)
04328     <<"Found "<<counter<<" rows in file: "<<sDataFileName<<endl;
04329 
04330   MSG("LIPlexMaps",Msg::kInfo)
04331     <<"DbiWriter.IsOpen="<<writer.IsOpen()<<endl
04332     <<"DbiWriter.CanOutput="<<writer.CanOutput()<<endl;
04333   
04334   if (writeToDb){
04335     if (this->IsPermitted()){
04336       MSG("LIPlexMaps",Msg::kInfo)
04337         <<"Writing to database..."<<endl;
04338       //this is the line that actually writes to the database
04339       writer.Close();
04340       MSG("LIPlexMaps",Msg::kInfo)
04341         <<"Finished writing to database"<<endl;
04342     }
04343   }
04344   else {
04345     MSG("LIPlexMaps",Msg::kInfo)
04346       <<"Mode is set to NOT write to database"<<endl;
04347   }
04348 
04349   MSG("LIPlexMaps",Msg::kInfo)
04350     <<endl<<" ** Finished the MakeCalStripToStrip method... ** "<<endl;
04351 }
04352 
04353 //......................................................................
04354 
04355 void LIPlexMaps::MakeCalMIPCalibration(Float_t scale,
04356                                        DetectorType::EDetectorType det,
04357                                        SimFlag::ESimFlag simFlag,
04358                                        VldTimeStamp vldStart,
04359                                        VldTimeStamp vldEnd,
04360                                        Int_t aggNo,
04361                                        Int_t task,
04362                                        VldTimeStamp creationDate,
04363                                        std::string dbName,
04364                                        std::string sLogComment,
04365                                        Bool_t writeToDb)
04366 {
04367   MSG("LIPlexMaps",Msg::kInfo)
04368     <<endl<<" ** Running the MakeCalMIPCalibration() method... **"<<endl; 
04369 
04370   //make validity range
04371   VldRange vr(det,simFlag,vldStart,vldEnd,
04372               "LISummary/LIPlexMaps::MakeCalMIPCalibration");
04373   MSG("LIPlexMaps",Msg::kInfo)
04374     <<"Using Validity Range: "<<vr.AsString()<<endl;
04375 
04376   MSG("LIPlexMaps",Msg::kInfo)
04377     <<"Other settings used:"<<endl
04378     <<"aggNo="<<aggNo<<endl
04379     <<"task="<<task<<endl
04380     <<"creationDate="<<creationDate<<endl
04381     <<"dbName="<<dbName<<endl
04382     <<"sLogComment="<<sLogComment<<endl
04383     <<"writeToDb="<<writeToDb<<endl;
04384 
04385   //create the writer
04386   DbiWriter<CalMIPCalibration> writer(vr,aggNo,task,creationDate,dbName,
04387                                       sLogComment);
04388 
04389   //set these to zero since you only need one entry and the calibrator
04390   //wont check the values
04391   Int_t seidkey=0;
04392   Int_t stripendid=0;
04393 
04394   //create CALADCTOPE table row
04395   CalMIPCalibration calMIPCalibration(seidkey,stripendid,scale);
04396   MSG("LIPlexMaps",Msg::kInfo)
04397     <<"Writing point with:"<<endl
04398     <<"  seidkey="<<seidkey<<endl
04399     <<"  stripendid="<<stripendid<<endl
04400     <<"  scale="<<scale<<endl;
04401 
04402   //write the row to the dbiwriter
04403   writer<<calMIPCalibration;
04404         
04405   MSG("LIPlexMaps",Msg::kInfo)
04406     <<"DbiWriter.IsOpen="<<writer.IsOpen()<<endl
04407     <<"DbiWriter.CanOutput="<<writer.CanOutput()<<endl;
04408   
04409   if (writeToDb){
04410     if (this->IsPermitted()){
04411       MSG("LIPlexMaps",Msg::kInfo)
04412         <<"Writing to database..."<<endl;
04413       //this is the line that actually writes to the database
04414       writer.Close();
04415       MSG("LIPlexMaps",Msg::kInfo)
04416         <<"Finished writing to database"<<endl;
04417     }
04418   }
04419   else {
04420     MSG("LIPlexMaps",Msg::kInfo)
04421       <<"Mode is set to NOT write to database"<<endl;
04422   }
04423 
04424   MSG("LIPlexMaps",Msg::kInfo)
04425     <<endl<<" ** Finished the MakeCalMIPCalibration method... ** "<<endl;
04426 }
04427 
04428 //......................................................................
04429 
04430 void LIPlexMaps::MakePlexStripEndToLed(Bool_t writeToDb) 
04431 {
04432   MSG("LIPlexMaps",Msg::kInfo)
04433     <<endl<<" ** Running the MakePlexStripEndToLed method... ** "
04434     <<endl;   
04435   //Thanks to Ryan for the DB code of this method  
04436 
04437   DetectorType::EDetectorType det=DetectorType::kCalDet;
04438   
04439   Int_t* planeMax=new Int_t[NUMCRATES];
04440   Int_t* planeMin=new Int_t[NUMCRATES];
04441   fLookup.SetPbPlanes(planeMin,planeMax,det);
04442   
04443   const Int_t firstStripBin=FIRSTSTRIP-8;//-8;
04444   const Int_t lastStripBin=LASTSTRIP+9;//200;
04445   const Int_t bins=lastStripBin-firstStripBin;
04446 
04447   string sConstantBit="";
04448 
04449   MSG("LIAnalysis",Msg::kInfo)
04450     <<"sConstantBit="<<sConstantBit<<endl;
04451 
04452   TH2F **hStripVsPlaneLed=0;
04453   hStripVsPlaneLed= new TH2F*[NUMCRATES];
04454   for (Int_t i=0;i<NUMCRATES;i++){
04455     string sPb=Form("%d",i);
04456     fS="Led (Crate "+sPb+")";
04457     hStripVsPlaneLed[i]=new TH2F(fS.c_str(),fS.c_str(),
04458                                       planeMax[i]-planeMin[i],
04459                                       planeMin[i],planeMax[i],
04460                                       bins,firstStripBin,lastStripBin);
04461     hStripVsPlaneLed[i]->GetXaxis()->SetTitle("Plane");
04462     hStripVsPlaneLed[i]->GetXaxis()->CenterTitle();
04463     hStripVsPlaneLed[i]->GetYaxis()->SetTitle("Strip");
04464     hStripVsPlaneLed[i]->GetYaxis()->CenterTitle();
04465     hStripVsPlaneLed[i]->SetFillColor(0);
04466     //hStripVsPlaneLed[i]->SetBit(TH1::kCanRebin);
04467   }
04468 
04469   //First fill the pin diode table
04470   VldTimeStamp tsStart=VldTimeStamp(2003,3,1,12,0,0);
04471   MSG("LIPlexMaps",Msg::kInfo)
04472     <<"Vld start time: ";
04473   tsStart.Print();
04474   MSG("LIPlexMaps",Msg::kInfo)
04475     <<endl;
04476   VldTimeStamp tsEnd=VldTimeStamp(2010,1,1,12,0,0);
04477   MSG("LIPlexMaps",Msg::kInfo)
04478     <<"Vld end time: ";
04479   tsEnd.Print();
04480   MSG("LIPlexMaps",Msg::kInfo)
04481     <<endl;
04482 
04483   //set validity range
04484   VldRange vldRng(det,SimFlag::kData,tsStart,tsEnd,
04485                   "MakePlexStripEndToLed");
04486   MSG("LIPlexMaps",Msg::kInfo)
04487     <<"Validity range: ";
04488   vldRng.Print();
04489   MSG("LIPlexMaps",Msg::kInfo)
04490     <<endl;
04491 
04492   VldTimeStamp tsNow; // now!
04493   VldContext vldNow(det,SimFlag::kData,tsNow);
04494   PlexHandle plexHandle(vldNow);
04495   
04496   //This is the encoding of the ledId.
04497   //15 bits of 32 are used, only the first 11 are needed to
04498   //tell you the pulser box and led
04500   //This was copied from the plex
04502   //    MSB                          LSB
04503   //     3         2         1         0
04504   //    10987654321098765432109876543210
04505   //                     ddddpppppiiiiii
04506   //
04507   //const UInt_t defaultPlexLedId    =  0;
04508   
04509   //const UInt_t bitsPlexLedIdLedInBox    =  6; // iiiiii    0:63
04510   //const UInt_t bitsPlexLedIdPulserBox   =  5; // ppppp     1:31
04511   //const UInt_t bitsPlexLedIdDetector    =  4; // dddd   near,far,caldet,teststand           
04512 
04513   //Note: The aggregate number in the database is the first eleven
04514   //bits of the ledId encoding, i.e. just the pulser box and 
04515   //led information without the detector info  
04516 
04517   //Now try and fill the PlexStripEndToLed
04518   for(Int_t pb=0;pb<NUMPULSERBOXES;pb++){
04519     for(Int_t led=4;led<=6;led++){
04520       //for(Int_t led=FIRSTLED;led<=LASTLED;led++){
04521       MSG("LIPlexMaps",Msg::kInfo)
04522         <<"Pulser box="<<pb<<", led="<<led<<endl;
04523 
04524       //create the plex led id
04525       PlexLedId ledId(det,pb,led);
04526 
04527       //0x7ff=2047=eleven 1s which is the led + pulser box bits
04528       int aggNo=0x7ff & ledId.GetEncoded(); 
04529       MSG("LIPlexMaps",Msg::kInfo)
04530         <<"aggNo="<<aggNo<<", encoded="<<ledId.GetEncoded()
04531         <<", det="<<(ledId.GetEncoded()>>11)<<endl;
04532 
04533       //set log comment
04534       string logComment="Updated to reflect the state of the detector";
04535       //set database number
04536       UInt_t dbNo=1;//1 is the second database in the cascade (string)
04537 
04538       //create the dbi writer
04539       DbiWriter<PlexStripEndToLed> writer(vldRng,aggNo,0,tsNow,dbNo,
04540                                           logComment);
04541       
04542       MSG("LIPlexMaps",Msg::kInfo)
04543         <<"DbiWriter.IsOpen="<<writer.IsOpen()<<endl;
04544       //<<"DbiWriter.CanOutput="<<writer.CanOutput()<<endl;
04545 
04546       //DbiWriter (const VldRange &vr, Int_t aggNo, Dbi::Task task=0, VldTimeStamp creationDate=VldTimeStamp(0, 0), UInt_t dbNo=0,const std::string &LogComment="")
04547 
04548       //loop over all the strips and planes
04549       for(Int_t plane=FIRSTPLANE;plane<=LASTPLANE;plane++){
04550         for(Int_t strip=FIRSTSTRIP;strip<=LASTSTRIP;strip++){
04551           for(Int_t end=FIRSTEND;end<=SECONDEND;end++){
04552 
04553             StripEnd::StripEnd_t stripEndType;      
04554             if (end==StripEnd::kEast) stripEndType=StripEnd::kEast;
04555             else if (end==StripEnd::kWest) stripEndType=StripEnd::kWest;
04556 
04557             PlexStripEndId stripEndId(det,plane,strip,stripEndType);
04558  
04559             //get the crate associated with the strip and plane
04560             Int_t crate=plexHandle.GetRawChannelId(stripEndId).
04561               GetCrate();
04562 
04564             //are readout by the ND
04565             if (plane==0 && end==1 && (crate==1 || crate==2) &&
04566                 det==DetectorType::kCalDet){
04567               crate=0;
04568               MSG("LIPlexMaps",Msg::kInfo)
04569                 <<"Doing plane 0 caldet hack"<<endl;
04570             }
04571             
04572             //create a plex strip end to led for 
04573             //current strip and plane
04574             PlexStripEndToLed stripEndToLed
04575               (det,plane,strip,stripEndType,pb,
04576                fLookup.Strip2Led(strip,plane,det,crate));
04577               //(DetectorType::kCalDet,1,1,StripEnd::kWest,0,1);
04578 
04579 
04580             MSG("LIPlexMaps",Msg::kDebug)
04581               <<"("<<plane<<";"<<strip<<";"<<stripEndType<<")"
04582               <<" ("<<pb<<":"<<led<<")"
04583               <<", strip2led="
04584               <<fLookup.Strip2Led(strip,plane,det,crate)<<")"
04585               <<", crate="<<crate
04586               <<", aggNo="<<stripEndToLed.GetAggregateNo()
04587               <<endl;
04588 
04589             ReadoutType::Readout_t rt=plexHandle.GetReadoutType
04590               (plexHandle.GetRawChannelId(stripEndToLed.
04591                                           GetPlexStripEndId()));
04592             
04593             if (rt!=ReadoutType::kScintStrip){
04594               MSG("LIPlexMaps",Msg::kInfo)
04595                 <<"rt="<<ReadoutType::AsString(rt)<<endl;
04596               continue;
04597             }
04598             
04599             //check that stripend to led isn't bad
04600             if(stripEndToLed.GetPlexStripEndId().GetPlane()!=plane ||
04601                stripEndToLed.GetPlexStripEndId().IsSteel() ||
04602                stripEndToLed.GetPlexStripEndId().IsVetoShield() ||
04603                !stripEndToLed.GetPlexStripEndId().IsValid()) {
04604 
04605               MSG("LIPlexMaps",Msg::kInfo)
04606                 <<"Stripend to led was bad: IsSteel="
04607                 <<stripEndToLed.GetPlexStripEndId().IsSteel()
04608                 <<", IsVetoShield="
04609                 <<stripEndToLed.GetPlexStripEndId().IsVetoShield()
04610                 <<", IsValid="
04611                 <<stripEndToLed.GetPlexStripEndId().IsValid()
04612                 <<", GetPlane="
04613                 <<stripEndToLed.GetPlexStripEndId().GetPlane()
04614                 <<", plane="<<plane
04615                 <<endl;
04616               continue;
04617             }
04618 
04619             //check that the led and pulser box encoded in the
04620             //strip end to led are the same as the ledid
04621             if(stripEndToLed.GetPlexLedId().GetEncoded()==
04622                ledId.GetEncoded()) {
04623                
04624               //if the crate is the same as the pulser box
04625               //then write to DB
04626               //this only applies to the far detector since 
04627               //there are multiple pulser boxes
04628               if(crate!=pb && det==DetectorType::kFar) continue;
04629 
04630               MSG("LIPlexMaps",Msg::kInfo)
04631                 <<stripEndToLed.GetAggregateNo()<<" "
04632                 <<stripEndToLed.GetPlexStripEndId().GetPlane()<<" "
04633                 <<stripEndToLed.GetPlexStripEndId().GetStrip()<<" "
04634                 <<stripEndToLed.GetPlexStripEndId().GetEnd()<<" "
04635                 <<stripEndToLed.GetPlexLedId().GetPulserBox()<<" "
04636                 <<stripEndToLed.GetPlexLedId().GetLedInBox()<<endl;
04637               
04638               //fill the histo for easy visualisation
04639               hStripVsPlaneLed[end-1]->Fill
04640                 (stripEndToLed.GetPlexStripEndId().GetPlane(),
04641                  stripEndToLed.GetPlexStripEndId().GetStrip(),
04642                  stripEndToLed.GetPlexLedId().GetLedInBox());
04643 
04644               writer<<stripEndToLed;
04645               
04646             }//end of if
04647             else{
04648               MSG("LIPlexMaps",Msg::kDebug)
04649                 <<"("<<plane<<";"<<strip<<";"<<stripEndType<<")"
04650                 <<" ("<<pb<<":"<<led<<")"
04651                 <<" These don't match: stripend to led encoded="
04652                 <<stripEndToLed.GetPlexLedId().GetEncoded()
04653                 <<", ledid encoded="<<ledId.GetEncoded()
04654                 <<endl;
04655             }
04656           }//end of strip end loop
04657         }//end of strip loop
04658       }//end of plane loop
04659 
04660       MSG("LIPlexMaps",Msg::kInfo)
04661         <<"DbiWriter.IsOpen="<<writer.IsOpen()<<endl
04662         <<"DbiWriter.CanOutput="<<writer.CanOutput()<<endl;
04663 
04664       if (writeToDb){
04665         if (this->IsPermitted()){
04666           MSG("LIPlexMaps",Msg::kInfo)
04667             <<"Writing to database..."<<endl;
04668           //this is the line that actually writes to the database
04669           writer.Close();
04670           MSG("LIPlexMaps",Msg::kInfo)
04671             <<"Finished writing to database"<<endl;
04672         }
04673       }
04674       else {
04675         MSG("LIPlexMaps",Msg::kInfo)
04676           <<"Mode is set to NOT write to database"<<endl;
04677       }
04678       
04679     }//end of led loop
04680   }//end of pb loop
04681 
04682   //set stats info off
04683   gStyle->SetOptStat(0);
04684 
04685   TCanvas *cStripVsPlaneLed=new TCanvas  
04686     ("cStripVsPlaneLed","StripVsPlane: Led",0,0,1000,800);  
04687   cStripVsPlaneLed->SetFillColor(0);  
04688   cStripVsPlaneLed->Divide(1,2);  
04689   cStripVsPlaneLed->cd(1);  
04690   hStripVsPlaneLed[0]->Draw("textcolz");  
04691   cStripVsPlaneLed->cd(2);  
04692   hStripVsPlaneLed[1]->Draw("textcolz");  
04693 
04694   MSG("LIPlexMaps",Msg::kInfo)
04695     <<endl<<" ** Finished the MakePlexStripEndToLed method... ** "
04696     <<endl; 
04697 }
04698 
04699 //......................................................................
04700 
04701 void LIPlexMaps::ReadDbCalStripToStrip(Int_t det,VldTimeStamp ts,
04702                                        Int_t task) 
04703 {
04704   MSG("LIPlexMaps",Msg::kInfo)
04705     <<endl<<" ** Running the ReadDbCalStripToStrip() method... ** "<<endl; 
04706   //this must go first
04707   this->SetDetector(det);
04708 
04709   const Int_t firstStripBin=FIRSTSTRIP-2;//-8;
04710   const Int_t lastStripBin=LASTSTRIP+2;//+9, 200;
04711   const Int_t stripBins=lastStripBin-firstStripBin;
04712 
04713   const Int_t firstPlaneBin=FIRSTPLANE-2;;
04714   const Int_t lastPlaneBin=LASTPLANE+2;
04715   const Int_t planeBins=lastPlaneBin-firstPlaneBin;
04716 
04717 
04718   TH1F *hResponse=new TH1F("hResponse","hResponse",300,-1,10);
04719   hResponse->GetXaxis()->SetTitle("Response of Stripends");
04720   hResponse->GetXaxis()->CenterTitle();
04721   hResponse->GetYaxis()->SetTitle("");
04722   hResponse->GetYaxis()->CenterTitle();
04723   hResponse->SetLineColor(2);
04724   hResponse->SetFillStyle(3015);
04725   hResponse->SetFillColor(2);
04726   hResponse->SetLineWidth(3);
04727   //hResponse->SetBit(TH1::kCanRebin);
04728 
04729   TH1F *hRespE=new TH1F("hRespE","hRespE",500,-1,10);
04730   hRespE->GetXaxis()->SetTitle("Response of East Stripends");
04731   hRespE->GetXaxis()->CenterTitle();
04732   hRespE->GetYaxis()->SetTitle("");
04733   hRespE->GetYaxis()->CenterTitle();
04734   hRespE->SetLineColor(4);
04735   hRespE->SetFillStyle(3015);
04736   hRespE->SetFillColor(4);
04737   hRespE->SetLineWidth(3);
04738   //hRespE->SetBit(TH1::kCanRebin);
04739 
04740   TH1F *hRespW=new TH1F("hRespW","hRespW",500,-1,10);
04741   hRespW->GetXaxis()->SetTitle("Response of West Stripends");
04742   hRespW->GetXaxis()->CenterTitle();
04743   hRespW->GetYaxis()->SetTitle("");
04744   hRespW->GetYaxis()->CenterTitle();
04745   hRespW->SetLineColor(2);
04746   hRespW->SetFillStyle(3015);
04747   hRespW->SetFillColor(2);
04748   hRespW->SetLineWidth(3);
04749   //hRespW->SetBit(TH1::kCanRebin);
04750 
04751   TH1F *hResponseErr=new TH1F("hResponseErr","hResponseErr",
04752                               200,-0.02,0.2);
04753   hResponseErr->GetXaxis()->SetTitle("ResponseErr of Stripends");
04754   hResponseErr->GetXaxis()->CenterTitle();
04755   hResponseErr->GetYaxis()->SetTitle("");
04756   hResponseErr->GetYaxis()->CenterTitle();
04757   hResponseErr->SetLineColor(3);
04758   hResponseErr->SetFillStyle(3015);
04759   hResponseErr->SetFillColor(3);
04760   hResponseErr->SetLineWidth(3);
04761   //hResponseErr->SetBit(TH1::kCanRebin);
04762 
04763   TProfile* pSigCorVsPlane=new TProfile
04764     ("pSigCorVsPlane","pSigCorVsPlane",
04765      planeBins,firstPlaneBin,lastPlaneBin);
04766   pSigCorVsPlane->GetXaxis()->SetTitle("Plane");
04767   pSigCorVsPlane->GetXaxis()->CenterTitle();
04768   pSigCorVsPlane->GetYaxis()->SetTitle("SigCor");
04769   pSigCorVsPlane->GetYaxis()->CenterTitle();
04770   pSigCorVsPlane->SetLineColor(2);
04771   pSigCorVsPlane->SetLineWidth(3);
04772   //pSigCorVsPlane->SetBit(TH1::kCanRebin);
04773 
04774   TProfile* pSigCorVsPlaneCoarse=new TProfile
04775     ("pSigCorVsPlaneCoarse","pSigCorVsPlaneCoarse",6,0,60);
04776   pSigCorVsPlaneCoarse->GetXaxis()->SetTitle("Plane");
04777   pSigCorVsPlaneCoarse->GetXaxis()->CenterTitle();
04778   pSigCorVsPlaneCoarse->GetYaxis()->SetTitle("SigCor");
04779   pSigCorVsPlaneCoarse->GetYaxis()->CenterTitle();
04780   pSigCorVsPlaneCoarse->SetLineColor(2);
04781   pSigCorVsPlaneCoarse->SetLineWidth(3);
04782   //pSigCorVsPlaneCoarse->SetBit(TH1::kCanRebin);
04783 
04784   TProfile* pSigCorVsPlane1=new TProfile
04785     ("pSigCorVsPlane1","pSigCorVsPlane1",
04786      planeBins,firstPlaneBin,lastPlaneBin);
04787   pSigCorVsPlane1->GetXaxis()->SetTitle("Plane");
04788   pSigCorVsPlane1->GetXaxis()->CenterTitle();
04789   pSigCorVsPlane1->GetYaxis()->SetTitle("SigCor");
04790   pSigCorVsPlane1->GetYaxis()->CenterTitle();
04791   pSigCorVsPlane1->SetLineColor(2);
04792   pSigCorVsPlane1->SetLineWidth(3);
04793   //pSigCorVsPlane1->SetBit(TH1::kCanRebin);
04794 
04795   TProfile* pSigCorVsPlane2=new TProfile
04796     ("pSigCorVsPlane2","pSigCorVsPlane2",
04797      planeBins,firstPlaneBin,lastPlaneBin);
04798   pSigCorVsPlane2->GetXaxis()->SetTitle("Plane");
04799   pSigCorVsPlane2->GetXaxis()->CenterTitle();
04800   pSigCorVsPlane2->GetYaxis()->SetTitle("SigCor");
04801   pSigCorVsPlane2->GetYaxis()->CenterTitle();
04802   pSigCorVsPlane2->SetLineColor(2);
04803   pSigCorVsPlane2->SetLineWidth(3);
04804   //pSigCorVsPlane2->SetBit(TH1::kCanRebin);
04805 
04806   TProfile* pSigCorVsStrip=new TProfile
04807     ("pSigCorVsStrip","pSigCorVsStrip",
04808      stripBins,firstStripBin,lastStripBin);
04809   pSigCorVsStrip->GetXaxis()->SetTitle("Strip");
04810   pSigCorVsStrip->GetXaxis()->CenterTitle();
04811   pSigCorVsStrip->GetYaxis()->SetTitle("SigCor");
04812   pSigCorVsStrip->GetYaxis()->CenterTitle();
04813   pSigCorVsStrip->SetLineColor(4);
04814   pSigCorVsStrip->SetLineWidth(3);
04815   //pSigCorVsStrip->SetBit(TH1::kCanRebin);
04816 
04817   TProfile* pSigCorVsStripCoarse=new TProfile
04818     ("pSigCorVsStripCoarse","pSigCorVsStripCoarse",12,0,24);
04819   pSigCorVsStripCoarse->GetXaxis()->SetTitle("Strip");
04820   pSigCorVsStripCoarse->GetXaxis()->CenterTitle();
04821   pSigCorVsStripCoarse->GetYaxis()->SetTitle("SigCor");
04822   pSigCorVsStripCoarse->GetYaxis()->CenterTitle();
04823   pSigCorVsStripCoarse->SetLineColor(2);
04824   pSigCorVsStripCoarse->SetLineWidth(3);
04825   //pSigCorVsStripCoarse->SetBit(TH1::kCanRebin);
04826 
04827   TProfile* pSigCorVsStrip1=new TProfile
04828     ("pSigCorVsStrip1","pSigCorVsStrip1",
04829      stripBins,firstStripBin,lastStripBin);
04830   pSigCorVsStrip1->GetXaxis()->SetTitle("Strip");
04831   pSigCorVsStrip1->GetXaxis()->CenterTitle();
04832   pSigCorVsStrip1->GetYaxis()->SetTitle("SigCor");
04833   pSigCorVsStrip1->GetYaxis()->CenterTitle();
04834   pSigCorVsStrip1->SetLineColor(4);
04835   pSigCorVsStrip1->SetLineWidth(3);
04836   //pSigCorVsStrip1->SetBit(TH1::kCanRebin);
04837 
04838   TProfile* pSigCorVsStrip2=new TProfile
04839     ("pSigCorVsStrip2","pSigCorVsStrip2",
04840      stripBins,firstStripBin,lastStripBin);
04841   pSigCorVsStrip2->GetXaxis()->SetTitle("Strip");
04842   pSigCorVsStrip2->GetXaxis()->CenterTitle();
04843   pSigCorVsStrip2->GetYaxis()->SetTitle("SigCor");
04844   pSigCorVsStrip2->GetYaxis()->CenterTitle();
04845   pSigCorVsStrip2->SetLineColor(4);
04846   pSigCorVsStrip2->SetLineWidth(3);
04847   //pSigCorVsStrip2->SetBit(TH1::kCanRebin);
04848 
04849   map<Int_t,Float_t> mStripResp1;
04850   map<Int_t,Float_t> mStripResp2;
04851 
04852   VldContext vldCtx(static_cast<DetectorType::EDetectorType>(det),
04853                     SimFlag::kData,ts);
04854   vldCtx.Print();
04855 
04856   DbiResultPtr<CalStripToStrip> dbiCalStripToStrip;  
04857   UInt_t numRows=dbiCalStripToStrip.NewQuery(vldCtx,task);
04858 
04859   MSG("LIPlexMaps",Msg::kInfo)
04860     <<"New DB query produced "<<numRows<<" rows"
04861     <<", using task="<<task<<endl
04862     <<"Looping over rows..."<<endl;
04863 
04864   //loop over the rows
04865   for(UInt_t i=0;i<numRows;i++) {
04866     const CalStripToStrip* calStripToStrip=dbiCalStripToStrip.GetRow(i);
04867 
04868     Float_t response=calStripToStrip->GetResponse();
04869     Float_t responseErr=calStripToStrip->GetResponseErr();
04870     PlexStripEndId seid=calStripToStrip->GetStripEndId();
04871     Int_t plane=seid.GetPlane();
04872     Int_t strip=seid.GetStrip();
04873     Int_t se=seid.GetEnd();
04874 
04875     if (plane==2){
04876       if (se==1){
04877         mStripResp1[strip]=response;
04878       }
04879       else if (se==2){
04880         mStripResp2[strip]=response;
04881       }
04882     }
04883     
04884     pSigCorVsStrip->Fill(strip,response);
04885     pSigCorVsPlane->Fill(plane,response);
04886 
04887     if (se==StripEnd::kEast){
04888       hRespE->Fill(response);
04889       pSigCorVsStrip1->Fill(strip,response);
04890       pSigCorVsPlane1->Fill(plane,response);
04891     }
04892     else if (se==StripEnd::kWest){
04893       hRespW->Fill(response);
04894       pSigCorVsStrip2->Fill(strip,response);
04895       pSigCorVsPlane2->Fill(plane,response);
04896     }
04897 
04898     hResponse->Fill(response);
04899     hResponseErr->Fill(responseErr);
04900   }
04901 
04902   MSG("LIPlexMaps",Msg::kInfo)
04903     <<"Av response="<<hResponse->GetMean()
04904     <<" (N="<<hResponse->GetEntries()<<")"<<endl
04905     <<"  East av response="<<hRespE->GetMean()
04906     <<" (N="<<hRespE->GetEntries()<<")"<<endl
04907     <<"  West av response="<<hRespW->GetMean()
04908     <<" (N="<<hRespW->GetEntries()<<")"<<endl;
04909 
04910   for (UInt_t i=0;i<mStripResp2.size();i++){
04911     cout<<"Strip="<<i<<", response 1="<<mStripResp1[i]
04912         <<" response 2="<<mStripResp2[i]<<endl;
04913   }
04914 
04915   TCanvas *cResponse=new TCanvas
04916     ("cResponse","cResponse",0,0,1000,800);
04917   cResponse->SetFillColor(0);
04918   cResponse->Divide(2,1);
04919   cResponse->cd(1);
04920   hResponse->Draw();
04921   cResponse->cd(2);
04922   hResponseErr->Draw();
04923 
04924   TCanvas *cPlSt=new TCanvas
04925     ("cPlSt","cPlSt",0,0,800,1000);
04926   cPlSt->SetFillColor(0);
04927   cPlSt->Divide(1,2);
04928   cPlSt->cd(1);
04929   pSigCorVsPlane->Draw();
04930   cPlSt->cd(2);
04931   pSigCorVsStrip->Draw();
04932 
04933   TCanvas *cPlSt1_2=new TCanvas
04934     ("cPlSt1_2","cPlSt1_2",0,0,1000,1000);
04935   cPlSt1_2->SetFillColor(0);
04936   cPlSt1_2->Divide(2,2);
04937   cPlSt1_2->cd(1);
04938   pSigCorVsPlane1->Draw();
04939   cPlSt1_2->cd(2);
04940   pSigCorVsPlane2->Draw();
04941   cPlSt1_2->cd(3);
04942   pSigCorVsStrip1->Draw();
04943   cPlSt1_2->cd(4);
04944   pSigCorVsStrip2->Draw();
04945 
04946   MSG("LIPlexMaps",Msg::kInfo)
04947     <<endl<<" ** Finished the ReadDbCalStripToStrip() method... ** "<<endl; 
04948 }
04949 
04950 //......................................................................
04951 
04952 void LIPlexMaps::CompareStripToStrip(Int_t det,VldTimeStamp ts,
04953                                      Int_t taskA,Int_t taskB) 
04954 {
04955   MSG("LIPlexMaps",Msg::kInfo)
04956     <<endl<<" ** Running the CompareStripToStrip() method... ** "<<endl;
04957   //this must go first
04958   this->SetDetector(det);
04959 
04960   const Int_t firstStripBin=FIRSTSTRIP-2;//-8;
04961   const Int_t lastStripBin=LASTSTRIP+2;//+9, 200;
04962   const Int_t stripBins=lastStripBin-firstStripBin;
04963 
04964   const Int_t firstPlaneBin=FIRSTPLANE-2;;
04965   const Int_t lastPlaneBin=LASTPLANE+2;
04966   const Int_t planeBins=lastPlaneBin-firstPlaneBin;
04967 
04968 
04969   TH1F *hResponse=new TH1F("hResponse","hResponse",300,-1,10);
04970   hResponse->GetXaxis()->SetTitle("Response of Stripends");
04971   hResponse->GetXaxis()->CenterTitle();
04972   hResponse->GetYaxis()->SetTitle("");
04973   hResponse->GetYaxis()->CenterTitle();
04974   hResponse->SetLineColor(2);
04975   hResponse->SetFillStyle(3015);
04976   hResponse->SetFillColor(2);
04977   hResponse->SetLineWidth(3);
04978   //hResponse->SetBit(TH1::kCanRebin);
04979 
04980   TH1F *hResponseErr=new TH1F("hResponseErr","hResponseErr",
04981                               200,-0.02,0.2);
04982   hResponseErr->GetXaxis()->SetTitle("ResponseErr of Stripends");
04983   hResponseErr->GetXaxis()->CenterTitle();
04984   hResponseErr->GetYaxis()->SetTitle("");
04985   hResponseErr->GetYaxis()->CenterTitle();
04986   hResponseErr->SetLineColor(3);
04987   hResponseErr->SetFillStyle(3015);
04988   hResponseErr->SetFillColor(3);
04989   hResponseErr->SetLineWidth(3);
04990   //hResponseErr->SetBit(TH1::kCanRebin);
04991 
04992   TProfile* pRatioVsPlane=new TProfile
04993     ("pRatioVsPlane","pRatioVsPlane",
04994      planeBins,firstPlaneBin,lastPlaneBin);
04995   pRatioVsPlane->GetXaxis()->SetTitle("Plane");
04996   pRatioVsPlane->GetXaxis()->CenterTitle();
04997   pRatioVsPlane->GetYaxis()->SetTitle("Ratio");
04998   pRatioVsPlane->GetYaxis()->CenterTitle();
04999   pRatioVsPlane->SetLineColor(2);
05000   pRatioVsPlane->SetLineWidth(3);
05001   //pRatioVsPlane->SetBit(TH1::kCanRebin);
05002 
05003   TProfile* pRatioVsPlaneCoarse=new TProfile
05004     ("pRatioVsPlaneCoarse","pRatioVsPlaneCoarse",6,0,60);
05005   pRatioVsPlaneCoarse->SetTitle("Ratio of S2S Cal. Const. (Cosmic/PS)");
05006   pRatioVsPlaneCoarse->GetXaxis()->SetTitle("Plane");
05007   pRatioVsPlaneCoarse->GetXaxis()->CenterTitle();
05008   pRatioVsPlaneCoarse->GetYaxis()->SetTitle("Ratio");
05009   pRatioVsPlaneCoarse->GetYaxis()->CenterTitle();
05010   pRatioVsPlaneCoarse->SetLineColor(2);
05011   pRatioVsPlaneCoarse->SetLineWidth(3);
05012   //pRatioVsPlaneCoarse->SetBit(TH1::kCanRebin);
05013 
05014   TProfile* pRatioVsPlane1=new TProfile
05015     ("pRatioVsPlane1","pRatioVsPlane1",
05016      planeBins,firstPlaneBin,lastPlaneBin);
05017   pRatioVsPlane1->GetXaxis()->SetTitle("Plane");
05018   pRatioVsPlane1->GetXaxis()->CenterTitle();
05019   pRatioVsPlane1->GetYaxis()->SetTitle("Ratio");
05020   pRatioVsPlane1->GetYaxis()->CenterTitle();
05021   pRatioVsPlane1->SetLineColor(2);
05022   pRatioVsPlane1->SetLineWidth(3);
05023   //pRatioVsPlane1->SetBit(TH1::kCanRebin);
05024 
05025   TProfile* pRatioVsPlane2=new TProfile
05026     ("pRatioVsPlane2","pRatioVsPlane2",
05027      planeBins,firstPlaneBin,lastPlaneBin);
05028   pRatioVsPlane2->GetXaxis()->SetTitle("Plane");
05029   pRatioVsPlane2->GetXaxis()->CenterTitle();
05030   pRatioVsPlane2->GetYaxis()->SetTitle("Ratio");
05031   pRatioVsPlane2->GetYaxis()->CenterTitle();
05032   pRatioVsPlane2->SetLineColor(2);
05033   pRatioVsPlane2->SetLineWidth(3);
05034   //pRatioVsPlane2->SetBit(TH1::kCanRebin);
05035 
05036   Int_t coarseStBins=(lastStripBin-firstStripBin)/2;
05037   TProfile* pRatioVsStripO1=new TProfile
05038     ("pRatioVsStripO1","pRatioVsStripO1",
05039      coarseStBins,firstStripBin,lastStripBin);
05040   pRatioVsStripO1->GetXaxis()->SetTitle("Strip");
05041   pRatioVsStripO1->GetXaxis()->CenterTitle();
05042   pRatioVsStripO1->GetYaxis()->SetTitle("Ratio");
05043   pRatioVsStripO1->GetYaxis()->CenterTitle();
05044   pRatioVsStripO1->SetLineColor(2);
05045   pRatioVsStripO1->SetLineWidth(3);
05046   //pRatioVsStripO1->SetBit(TH1::kCanRebin);
05047 
05048   TProfile* pRatioVsStripO2=new TProfile
05049     ("pRatioVsStripO2","pRatioVsStripO2",
05050      coarseStBins,firstStripBin,lastStripBin);
05051   pRatioVsStripO2->GetXaxis()->SetTitle("Strip");
05052   pRatioVsStripO2->GetXaxis()->CenterTitle();
05053   pRatioVsStripO2->GetYaxis()->SetTitle("Ratio");
05054   pRatioVsStripO2->GetYaxis()->CenterTitle();
05055   pRatioVsStripO2->SetLineColor(2);
05056   pRatioVsStripO2->SetLineWidth(3);
05057   //pRatioVsStripO2->SetBit(TH1::kCanRebin);
05058 
05059   TProfile* pRatioVsStripE1=new TProfile
05060     ("pRatioVsStripE1","pRatioVsStripE1",
05061      coarseStBins,firstStripBin,lastStripBin);
05062   pRatioVsStripE1->GetXaxis()->SetTitle("Strip");
05063   pRatioVsStripE1->GetXaxis()->CenterTitle();
05064   pRatioVsStripE1->GetYaxis()->SetTitle("Ratio");
05065   pRatioVsStripE1->GetYaxis()->CenterTitle();
05066   pRatioVsStripE1->SetLineColor(2);
05067   pRatioVsStripE1->SetLineWidth(3);
05068   //pRatioVsStripE1->SetBit(TH1::kCanRebin);
05069 
05070   TProfile* pRatioVsStripE2=new TProfile
05071     ("pRatioVsStripE2","pRatioVsStripE2",
05072      coarseStBins,firstStripBin,lastStripBin);
05073   pRatioVsStripE2->GetXaxis()->SetTitle("Strip");
05074   pRatioVsStripE2->GetXaxis()->CenterTitle();
05075   pRatioVsStripE2->GetYaxis()->SetTitle("Ratio");
05076   pRatioVsStripE2->GetYaxis()->CenterTitle();
05077   pRatioVsStripE2->SetLineColor(2);
05078   pRatioVsStripE2->SetLineWidth(3);
05079   //pRatioVsStripE2->SetBit(TH1::kCanRebin);
05080 
05081   TProfile* pRatioVsStrip=new TProfile
05082     ("pRatioVsStrip","pRatioVsStrip",
05083      stripBins,firstStripBin,lastStripBin);
05084   pRatioVsStrip->GetXaxis()->SetTitle("Strip");
05085   pRatioVsStrip->GetXaxis()->CenterTitle();
05086   pRatioVsStrip->GetYaxis()->SetTitle("Ratio");
05087   pRatioVsStrip->GetYaxis()->CenterTitle();
05088   pRatioVsStrip->SetLineColor(4);
05089   pRatioVsStrip->SetLineWidth(3);
05090   //pRatioVsStrip->SetBit(TH1::kCanRebin);
05091 
05092   TProfile* pRatioVsStripCoarse=new TProfile
05093     ("pRatioVsStripCoarse","pRatioVsStripCoarse",12,0,24);
05094   pRatioVsStripCoarse->SetTitle("Ratio of S2S Cal. Const. (Cosmic/PS)");
05095   pRatioVsStripCoarse->GetXaxis()->SetTitle("Strip");
05096   pRatioVsStripCoarse->GetXaxis()->CenterTitle();
05097   pRatioVsStripCoarse->GetYaxis()->SetTitle("Ratio");
05098   pRatioVsStripCoarse->GetYaxis()->CenterTitle();
05099   pRatioVsStripCoarse->SetLineColor(2);
05100   pRatioVsStripCoarse->SetLineWidth(3);
05101   //pRatioVsStripCoarse->SetBit(TH1::kCanRebin);
05102 
05103   TProfile* pRatioVsStripCoarseFront=new TProfile
05104     ("pRatioVsStripCoarseFront","pRatioVsStripCoarseFront",12,0,24);
05105   pRatioVsStripCoarseFront->
05106     SetTitle("Ratio of S2S Cal. Const. Det. Front (Cosmic/PS)");
05107   pRatioVsStripCoarseFront->GetXaxis()->SetTitle("Strip");
05108   pRatioVsStripCoarseFront->GetXaxis()->CenterTitle();
05109   pRatioVsStripCoarseFront->GetYaxis()->SetTitle("Ratio");
05110   pRatioVsStripCoarseFront->GetYaxis()->CenterTitle();
05111   pRatioVsStripCoarseFront->SetLineColor(2);
05112   pRatioVsStripCoarseFront->SetLineWidth(3);
05113   //pRatioVsStripCoarseFront->SetBit(TH1::kCanRebin);
05114 
05115   TProfile* pRatioVsStripCoarseBack=new TProfile
05116     ("pRatioVsStripCoarseBack","pRatioVsStripCoarseBack",12,0,24);
05117   pRatioVsStripCoarseBack->
05118     SetTitle("Ratio of S2S Cal. Const. Det. Back (Cosmic/PS)");
05119   pRatioVsStripCoarseBack->GetXaxis()->SetTitle("Strip");
05120   pRatioVsStripCoarseBack->GetXaxis()->CenterTitle();
05121   pRatioVsStripCoarseBack->GetYaxis()->SetTitle("Ratio");
05122   pRatioVsStripCoarseBack->GetYaxis()->CenterTitle();
05123   pRatioVsStripCoarseBack->SetLineColor(2);
05124   pRatioVsStripCoarseBack->SetLineWidth(3);
05125   //pRatioVsStripCoarseBack->SetBit(TH1::kCanRebin);
05126 
05127   TProfile* pRatioVsStrip1=new TProfile
05128     ("pRatioVsStrip1","pRatioVsStrip1",
05129      stripBins,firstStripBin,lastStripBin);
05130   pRatioVsStrip1->GetXaxis()->SetTitle("Strip");
05131   pRatioVsStrip1->GetXaxis()->CenterTitle();
05132   pRatioVsStrip1->GetYaxis()->SetTitle("Ratio");
05133   pRatioVsStrip1->GetYaxis()->CenterTitle();
05134   pRatioVsStrip1->SetLineColor(4);
05135   pRatioVsStrip1->SetLineWidth(3);
05136   //pRatioVsStrip1->SetBit(TH1::kCanRebin);
05137 
05138   TProfile* pRatioVsStrip2=new TProfile
05139     ("pRatioVsStrip2","pRatioVsStrip2",
05140      stripBins,firstStripBin,lastStripBin);
05141   pRatioVsStrip2->GetXaxis()->SetTitle("Strip");
05142   pRatioVsStrip2->GetXaxis()->CenterTitle();
05143   pRatioVsStrip2->GetYaxis()->SetTitle("Ratio");
05144   pRatioVsStrip2->GetYaxis()->CenterTitle();
05145   pRatioVsStrip2->SetLineColor(4);
05146   pRatioVsStrip2->SetLineWidth(3);
05147   //pRatioVsStrip2->SetBit(TH1::kCanRebin);
05148 
05149   TProfile2D* pStVsPlRatio1=new TProfile2D
05150     ("pStVsPlRatio1","pStVsPlRatio1",
05151      planeBins,firstPlaneBin,lastPlaneBin,
05152      stripBins,firstStripBin,lastStripBin);
05153   pStVsPlRatio1->GetXaxis()->SetTitle("Plane");
05154   pStVsPlRatio1->GetXaxis()->CenterTitle();
05155   pStVsPlRatio1->GetYaxis()->SetTitle("Strip");
05156   pStVsPlRatio1->GetYaxis()->CenterTitle();
05157   //pStVsPlRatio1->SetBit(TH1::kCanRebin);
05158 
05159   TProfile2D* pStVsPlRatio2=new TProfile2D
05160     ("pStVsPlRatio2","pStVsPlRatio2",
05161      planeBins,firstPlaneBin,lastPlaneBin,
05162      stripBins,firstStripBin,lastStripBin);
05163   pStVsPlRatio2->GetXaxis()->SetTitle("Plane");
05164   pStVsPlRatio2->GetXaxis()->CenterTitle();
05165   pStVsPlRatio2->GetYaxis()->SetTitle("Strip");
05166   pStVsPlRatio2->GetYaxis()->CenterTitle();
05167   //pStVsPlRatio2->SetBit(TH1::kCanRebin);
05168 
05169   map<PlexStripEndId,Float_t> sigCorA;
05170   map<PlexStripEndId,Float_t> sigCorB;
05171 
05172   VldContext vldCtx(static_cast<DetectorType::EDetectorType>(det),
05173                     SimFlag::kData,ts);
05174   vldCtx.Print();
05175   UInt_t year=0;
05176   ts.GetDate(true,0,&year);
05177 
05178   DbiResultPtr<CalStripToStrip> dbiCalStripToStrip;
05179 
05180   //get taskA
05181   UInt_t numRows=dbiCalStripToStrip.NewQuery(vldCtx,taskA);
05182 
05183   MSG("LIPlexMaps",Msg::kInfo)
05184     <<"New DB query produced "<<numRows<<" rows"
05185     <<", using task="<<taskA<<endl
05186     <<"Looping over rows..."<<endl;
05187   //loop over the rows
05188   for(UInt_t i=0;i<numRows;i++) {
05189     const CalStripToStrip* calStripToStrip=dbiCalStripToStrip.GetRow(i);
05190 
05191     Float_t response=calStripToStrip->GetResponse();
05192     PlexStripEndId seid=calStripToStrip->GetStripEndId();
05193     sigCorA[seid]=response;
05194   }
05195 
05196   //now get taskB
05197   numRows=dbiCalStripToStrip.NewQuery(vldCtx,taskB);
05198 
05199   MSG("LIPlexMaps",Msg::kInfo)
05200     <<"New DB query produced "<<numRows<<" rows"
05201     <<", using task="<<taskB<<endl
05202     <<"Looping over rows..."<<endl;
05203   //loop over the rows
05204   for(UInt_t i=0;i<numRows;i++) {
05205     const CalStripToStrip* calStripToStrip=dbiCalStripToStrip.GetRow(i);
05206 
05207     Float_t response=calStripToStrip->GetResponse();
05208     PlexStripEndId seid=calStripToStrip->GetStripEndId();
05209     sigCorB[seid]=response;
05210   }
05211 
05212   MSG("LIPlexMaps",Msg::kInfo)
05213     <<"Found maps, sigCorA size="<<sigCorA.size()
05214     <<", sigCorB size="<<sigCorB.size()<<endl;
05215   
05216   for (map<PlexStripEndId,Float_t>::iterator iterA=sigCorA.begin();
05217        iterA!=sigCorA.end();++iterA){
05218 
05219     map<PlexStripEndId,Float_t>::iterator iterB=
05220       sigCorB.find(iterA->first);
05221 
05222     if (iterB==sigCorB.end()){
05223       MSG("LIPlexMaps",Msg::kWarning)
05224         <<"Ahhhhhh, missing iterB"<<endl;
05225       continue;
05226     }
05227 
05228     Int_t planeA=iterA->first.GetPlane();
05229     Int_t stripA=iterA->first.GetStrip();
05230     Int_t seA=iterA->first.GetEnd();
05231     Int_t planeB=iterB->first.GetPlane();
05232     Int_t stripB=iterB->first.GetStrip();
05233     Int_t seB=iterB->first.GetEnd();
05234 
05235     MSG("LIPlexMaps",Msg::kDebug)
05236       <<"A: st="<<stripA<<", pl="<<planeA<<", se="<<seA<<endl;
05237     MSG("LIPlexMaps",Msg::kDebug)
05238       <<"B: st="<<stripB<<", pl="<<planeB<<", se="<<seB<<endl;
05239 
05240     Float_t sigCorDiff=1;
05241     if (iterB->second!=0){
05242       //iterA->second-iterB->second;
05243       sigCorDiff=iterA->second/iterB->second;
05244     }
05245     else{
05246       MSG("LIPlexMaps",Msg::kWarning)<<"Ahh, zero calib constant"<<endl;
05247     }
05248 
05249     //make bad channel cuts...
05250     //cut out plane zero, since it is known to be badly calibrated
05251     if (planeA==0){
05252       MAXMSG("LIPlexMaps",Msg::kWarning,1)
05253         <<"Cutting out plane 0. It's known to be bad!"<<endl;
05254       continue;
05255     }
05256     else if (planeA==25 && stripA==5){
05257       MAXMSG("LIPlexMaps",Msg::kWarning,1)
05258         <<"Cutting out plane 25, strip 5. It's used to be bad"<<endl;
05259       continue;
05260     }
05261     else if (planeA==35 && year==2002){
05262       MAXMSG("LIPlexMaps",Msg::kWarning,1)
05263         <<"Cutting out plane 35. It's bad in 2002"<<endl;
05264       continue;
05265     }
05266     else if ((planeA==56 || planeA==58) && seA==StripEnd::kWest && 
05267              year==2003){
05268       MAXMSG("LIPlexMaps",Msg::kWarning,1)
05269         <<"Cutting out plane 56 & 58. It's bad in 2003"<<endl;
05270       continue;
05271     }
05272     else if ((planeA==33 || planeA==35) && year==2003){
05273       MAXMSG("LIPlexMaps",Msg::kWarning,1)
05274         <<"Cutting out plane 33 & 35. It's bad in 2003"<<endl;
05275       continue;
05276     }
05277 
05278     //fill strip vs plane maps
05279     if (seA==StripEnd::kEast){
05280       pStVsPlRatio1->Fill(planeA,stripA,sigCorDiff);
05281     }
05282     else if (seA==StripEnd::kWest){
05283       pStVsPlRatio2->Fill(planeA,stripA,sigCorDiff);
05284     }
05285 
05286     //make fiducial volume cut
05287     if (stripA>=22 || stripA<=1){
05288       MAXMSG("LIPlexMaps",Msg::kWarning,1)
05289         <<"Making fiducial volume cut on strip"<<endl;
05290       continue;
05291     }
05292 
05293     hResponse->Fill(sigCorDiff);
05294     pRatioVsStrip->Fill(stripA,sigCorDiff);
05295     pRatioVsPlane->Fill(planeA,sigCorDiff);
05296     pRatioVsStripCoarse->Fill(stripA,sigCorDiff);
05297     if (planeA<=30) pRatioVsStripCoarseFront->Fill(stripA,sigCorDiff);
05298     if (planeA>30) pRatioVsStripCoarseBack->Fill(stripA,sigCorDiff);
05299     pRatioVsPlaneCoarse->Fill(planeA,sigCorDiff);
05300 
05301     if (seA==StripEnd::kEast){
05302       pRatioVsStrip1->Fill(stripA,sigCorDiff);
05303       pRatioVsPlane1->Fill(planeA,sigCorDiff);
05304       if (planeA%2==0) pRatioVsStripE1->Fill(stripA,sigCorDiff);
05305       else if (planeA%2==1) pRatioVsStripO1->Fill(stripA,sigCorDiff);
05306     }
05307     else if (seA==StripEnd::kWest){
05308       pRatioVsStrip2->Fill(stripA,sigCorDiff);
05309       pRatioVsPlane2->Fill(planeA,sigCorDiff);
05310       if (planeA%2==0) pRatioVsStripE2->Fill(stripA,sigCorDiff);
05311       else if (planeA%2==1) pRatioVsStripO2->Fill(stripA,sigCorDiff);
05312     }
05313   }
05314   
05315   TCanvas *cResponse=new TCanvas
05316     ("cResponse","cResponse",0,0,1000,800);
05317   cResponse->SetFillColor(0);
05318   cResponse->Divide(2,1);
05319   cResponse->cd(1);
05320   hResponse->Draw();
05321   cResponse->cd(2);
05322   hResponseErr->Draw();
05323 
05324   TCanvas *cPlSt=new TCanvas
05325     ("cPlSt","cPlSt",0,0,800,1000);
05326   cPlSt->SetFillColor(0);
05327   cPlSt->Divide(1,2);
05328   cPlSt->cd(1);
05329   pRatioVsPlane->Draw();
05330   cPlSt->cd(2);
05331   pRatioVsStrip->Draw();
05332 
05333   TCanvas *cPlStCoarse=new TCanvas
05334     ("cPlStCoarse","cPlStCoarse",0,0,800,1000);
05335   cPlStCoarse->SetFillColor(0);
05336   cPlStCoarse->Divide(1,2);
05337   cPlStCoarse->cd(1);
05338   pRatioVsPlaneCoarse->Draw();
05339   cPlStCoarse->cd(2);
05340   pRatioVsStripCoarse->Draw();
05341 
05342   TCanvas *cStCoarse=new TCanvas
05343     ("cStCoarse","cStCoarse",0,0,800,1000);
05344   cStCoarse->SetFillColor(0);
05345   cStCoarse->Divide(1,2);
05346   cStCoarse->cd(1);
05347   pRatioVsStripCoarseFront->Draw();
05348   cStCoarse->cd(2);
05349   pRatioVsStripCoarseBack->Draw();
05350 
05351   TCanvas *cPlSt1_2=new TCanvas
05352     ("cPlSt1_2","cPlSt1_2",0,0,1000,1000);
05353   cPlSt1_2->SetFillColor(0);
05354   cPlSt1_2->Divide(2,2);
05355   cPlSt1_2->cd(1);
05356   pRatioVsPlane1->Draw();
05357   cPlSt1_2->cd(2);
05358   pRatioVsPlane2->Draw();
05359   cPlSt1_2->cd(3);
05360   pRatioVsStrip1->Draw();
05361   cPlSt1_2->cd(4);
05362   pRatioVsStrip2->Draw();
05363 
05364   TCanvas *cPlSt1_2OE=new TCanvas
05365     ("cPlSt1_2OE","cPlSt1_2OE",0,0,1000,1000);
05366   cPlSt1_2OE->SetFillColor(0);
05367   cPlSt1_2OE->Divide(2,2);
05368   cPlSt1_2OE->cd(1);
05369   pRatioVsStripO1->Draw();
05370   cPlSt1_2OE->cd(2);
05371   pRatioVsStripE1->Draw();
05372   cPlSt1_2OE->cd(3);
05373   pRatioVsStripO2->Draw();
05374   cPlSt1_2OE->cd(4);
05375   pRatioVsStripE2->Draw();
05376 
05377   TCanvas *cStVsPl=new TCanvas
05378     ("cStVsPl","cStVsPl",0,0,800,800);
05379   cStVsPl->SetFillColor(0);
05380   cStVsPl->Divide(1,2);
05381   cStVsPl->cd(1);
05382   pStVsPlRatio1->Draw("colz");
05383   cStVsPl->cd(2);
05384   pStVsPlRatio2->Draw("colz");
05385 
05386   MSG("LIPlexMaps",Msg::kInfo)
05387     <<endl<<" ** Finished the CompareStripToStrip() method... **"<<endl;
05388 }
05389 
05390 //......................................................................
05391 
05392 void LIPlexMaps::ReadDbGains(Int_t det,SimFlag::ESimFlag simFlag,
05393                              VldTimeStamp ts) 
05394 {
05395   MSG("LIPlexMaps",Msg::kInfo)
05396     <<endl<<" ** Running the ReadDbGains() method... ** "<<endl; 
05397 
05398   //this must go first
05399   this->SetDetector(det);
05400 
05401   //create pmts to calc detector average
05402   LIPmt avM64SE1;
05403   LIPmt avM64SE2;
05404   LIPmt avM16VA0SE1;
05405   LIPmt avM16VA0SE2;
05406   LIPmt avM16VA1SE1;
05407   LIPmt avM16VA1SE2;
05408   LIPmt avM16VA2SE1;
05409   LIPmt avM16VA2SE2;
05410 
05411   //initialise pmts
05412   avM64SE1.Initialise(64,1);
05413   avM64SE2.Initialise(64,1);
05414   avM16VA0SE1.Initialise(16,8);
05415   avM16VA0SE2.Initialise(16,8);
05416   avM16VA1SE1.Initialise(16,8);
05417   avM16VA1SE2.Initialise(16,8);
05418   avM16VA2SE1.Initialise(16,8);
05419   avM16VA2SE2.Initialise(16,8);
05420 
05421   //store pointers to all the pmts in a vector
05422   vector<LIPmt*> vPmts;
05423   vPmts.push_back(&avM64SE1);
05424   vPmts.push_back(&avM64SE2);
05425   vPmts.push_back(&avM16VA0SE1);
05426   vPmts.push_back(&avM16VA0SE2);
05427   vPmts.push_back(&avM16VA1SE1);
05428   vPmts.push_back(&avM16VA1SE2);
05429   vPmts.push_back(&avM16VA2SE1);
05430   vPmts.push_back(&avM16VA2SE2);
05431 
05432   Int_t* planeMax=new Int_t[NUMCRATES];
05433   Int_t* planeMin=new Int_t[NUMCRATES];
05434   fLookup.SetPbPlanes(planeMin,planeMax,det);
05435 
05436   const Int_t firstStripBin=FIRSTSTRIP-2;//-8;
05437   const Int_t lastStripBin=LASTSTRIP+2;//+9, 200;
05438   const Int_t bins=lastStripBin-firstStripBin;
05439 
05440   string sConstantBit="";
05441 
05442   MSG("LIAnalysis",Msg::kInfo)
05443     <<"sConstantBit="<<sConstantBit<<endl;
05444 
05445   TH2F **hStripVsPlaneGain=0;
05446   hStripVsPlaneGain= new TH2F*[NUMCRATES];
05447   for (Int_t i=0;i<NUMCRATES;i++){
05448     string sPb=Form("%d",i);
05449     string sTs=ts.AsString("s");
05450     fS="Gains (Crate "+sPb+", "+sTs+")";
05451     hStripVsPlaneGain[i]=new TH2F(fS.c_str(),fS.c_str(),
05452                                   planeMax[i]-planeMin[i],
05453                                   planeMin[i],planeMax[i],
05454                                   bins,firstStripBin,lastStripBin);
05455     hStripVsPlaneGain[i]->GetXaxis()->SetTitle("Plane");
05456     hStripVsPlaneGain[i]->GetXaxis()->CenterTitle();
05457     hStripVsPlaneGain[i]->GetYaxis()->SetTitle("Strip");
05458     hStripVsPlaneGain[i]->GetYaxis()->CenterTitle();
05459     hStripVsPlaneGain[i]->SetFillColor(0);
05460     //hStripVsPlaneGain[i]->SetBit(TH1::kCanRebin);
05461   }
05462 
05463   TH2F **hAvDetGains=0;
05464   hAvDetGains= new TH2F*[NUMCRATES];
05465   for (Int_t i=0;i<NUMCRATES;i++){
05466     string sPb=Form("%d",i);
05467     string sTs=ts.AsString("s");
05468     fS="Av Detector Gains (Crate "+sPb+", "+sTs+")";
05469     hAvDetGains[i]=new TH2F(fS.c_str(),fS.c_str(),
05470                                   planeMax[i]-planeMin[i],
05471                                   planeMin[i],planeMax[i],
05472                                   bins,firstStripBin,lastStripBin);
05473     hAvDetGains[i]->GetXaxis()->SetTitle("Plane");
05474     hAvDetGains[i]->GetXaxis()->CenterTitle();
05475     hAvDetGains[i]->GetYaxis()->SetTitle("Strip");
05476     hAvDetGains[i]->GetYaxis()->CenterTitle();
05477     hAvDetGains[i]->SetFillColor(0);
05478     //hAvDetGains[i]->SetBit(TH1::kCanRebin);
05479   }
05480 
05481   TH2F **hStripVsPlaneGainErr=0;
05482   hStripVsPlaneGainErr= new TH2F*[NUMCRATES];
05483   for (Int_t i=0;i<NUMCRATES;i++){
05484     string sPb=Form("%d",i);
05485     fS="Gain Errors (Crate "+sPb+")";
05486     hStripVsPlaneGainErr[i]=new TH2F(fS.c_str(),fS.c_str(),
05487                                      planeMax[i]-planeMin[i],
05488                                      planeMin[i],planeMax[i],
05489                                      bins,firstStripBin,lastStripBin);
05490     hStripVsPlaneGainErr[i]->GetXaxis()->SetTitle("Plane");
05491     hStripVsPlaneGainErr[i]->GetXaxis()->CenterTitle();
05492     hStripVsPlaneGainErr[i]->GetYaxis()->SetTitle("Strip");
05493     hStripVsPlaneGainErr[i]->GetYaxis()->CenterTitle();
05494     hStripVsPlaneGainErr[i]->SetFillColor(0);
05495     //hStripVsPlaneGainErr[i]->SetBit(TH1::kCanRebin);
05496   }
05497 
05498   TH2F **hStripVsPlaneSPEWidth=0;
05499   hStripVsPlaneSPEWidth= new TH2F*[NUMCRATES];
05500   for (Int_t i=0;i<NUMCRATES;i++){
05501     string sPb=Form("%d",i);
05502     fS="Single PE Width (Crate "+sPb+")";
05503     hStripVsPlaneSPEWidth[i]=new TH2F(fS.c_str(),fS.c_str(),
05504                                      planeMax[i]-planeMin[i],
05505                                      planeMin[i],planeMax[i],
05506                                      bins,firstStripBin,lastStripBin);
05507     hStripVsPlaneSPEWidth[i]->GetXaxis()->SetTitle("Plane");
05508     hStripVsPlaneSPEWidth[i]->GetXaxis()->CenterTitle();
05509     hStripVsPlaneSPEWidth[i]->GetYaxis()->SetTitle("Strip");
05510     hStripVsPlaneSPEWidth[i]->GetYaxis()->CenterTitle();
05511     hStripVsPlaneSPEWidth[i]->SetFillColor(0);
05512     //hStripVsPlaneSPEWidth[i]->SetBit(TH1::kCanRebin);
05513   }
05514 
05515   TH1F *hGains=new TH1F("hGains","hGains",200,-1,200);
05516   hGains->GetXaxis()->SetTitle("Response of Stripends");
05517   hGains->GetXaxis()->CenterTitle();
05518   hGains->GetYaxis()->SetTitle("");
05519   hGains->GetYaxis()->CenterTitle();
05520   hGains->SetLineColor(2);
05521   hGains->SetFillStyle(3015);
05522   hGains->SetFillColor(2);
05523   hGains->SetLineWidth(3);
05524   //hGains->SetBit(TH1::kCanRebin);
05525 
05526   TH1F *hGainsAll=new TH1F("hGainsAll","hGainsAll",400,-1,300);
05527   hGainsAll->GetXaxis()->SetTitle("Response of Stripends");
05528   hGainsAll->GetXaxis()->CenterTitle();
05529   hGainsAll->GetYaxis()->SetTitle("");
05530   hGainsAll->GetYaxis()->CenterTitle();
05531   hGainsAll->SetLineColor(2);
05532   hGainsAll->SetFillStyle(3015);
05533   hGainsAll->SetFillColor(2);
05534   hGainsAll->SetLineWidth(3);
05535   hGainsAll->SetBit(TH1::kCanRebin);
05536 
05537   VldContext vldCtx(static_cast<DetectorType::EDetectorType>(det),
05538                     simFlag,ts);
05539   vldCtx.Print();
05540 
05541   //create a plex handle
05542   PlexHandle plexHandle(vldCtx);
05543 
05544   DbiResultPtr<CalADCtoPE> dbiCalADCtoPE;
05545 
05546   UInt_t numRows=dbiCalADCtoPE.NewQuery(vldCtx,0);
05547 
05548   MSG("LIPlexMaps",Msg::kInfo)
05549     <<"New DB query produced "<<numRows<<" rows"<<endl
05550     <<"Looping over rows..."<<endl;
05551 
05552   //loop over the rows
05553   for(UInt_t i=0;i<numRows;i++) {
05554     const CalADCtoPE* calAdcToPe = dbiCalADCtoPE.GetRow(i);
05555 
05556     Float_t gain=calAdcToPe->GetGain();
05557     Float_t gainErr=calAdcToPe->GetGainErr();
05558     Float_t SPEWidth=calAdcToPe->GetSPEWidth();
05559     Int_t seId=calAdcToPe->GetStripEndId();
05560 
05561     UInt_t seidkey=calAdcToPe->GetSEIDkey();
05562       
05563     Int_t plane=-1;
05564     Int_t strip=-1;
05565     Int_t end=-1;
05566     fLookup.UnencodePlnStripEndKey(seidkey,static_cast<DetectorType::
05567                                    EDetectorType>(det),plane,strip,end);
05568 
05569     //fill the gains histos
05570     hGains->Fill(gain);
05571     hGainsAll->Fill(gain);
05572 
05573     //get stripend id
05574     PlexStripEndId seid(static_cast<DetectorType::EDetectorType>(det),
05575                         plane,strip,
05576                         static_cast<StripEnd::EStripEnd>(end));
05577     //get pixel spot id
05578     PlexPixelSpotId pixSpotId=plexHandle.GetPixelSpotId(seid);
05579 
05580     MSG("LIPlexMaps",Msg::kDebug)
05581       <<"pl="<<plane<<", st="<<strip<<", end="<<end
05582       <<", pix="<<pixSpotId.GetPixel()
05583       <<", pixSpot="<<pixSpotId.GetSpot()
05584       <<endl;
05585 
05586     ElecType::Elec_t elecType=plexHandle.GetRawChannelId(seid).
05587       GetElecType();
05588     Int_t vaChip=plexHandle.GetRawChannelId(seid).GetVaChip();
05589 
05590     //add point to average detector PMT
05591     //depending on electype and va chip
05592     if (elecType==ElecType::kQIE){
05593       if (end==1) avM64SE1.AddMultiPoint(pixSpotId.GetPixel(),
05594                                          pixSpotId.GetSpot(),gain);
05595       else if (end==2) avM64SE2.AddMultiPoint(pixSpotId.GetPixel(),
05596                                               pixSpotId.GetSpot(),gain);
05597     }
05598     else if (elecType==ElecType::kVA){
05599       if (vaChip==0){
05600         if (end==1) avM16VA0SE1.AddMultiPoint(pixSpotId.GetPixel(),
05601                                               pixSpotId.GetSpot(),gain);
05602         if (end==2) avM16VA0SE2.AddMultiPoint(pixSpotId.GetPixel(),
05603                                               pixSpotId.GetSpot(),gain);
05604       }
05605       else if (vaChip==1){
05606         if (end==1) avM16VA1SE1.AddMultiPoint(pixSpotId.GetPixel(),
05607                                               pixSpotId.GetSpot(),gain);
05608         if (end==2) avM16VA1SE2.AddMultiPoint(pixSpotId.GetPixel(),
05609                                               pixSpotId.GetSpot(),gain);
05610       }
05611       else if (vaChip==2){
05612         if (end==1) avM16VA2SE1.AddMultiPoint(pixSpotId.GetPixel(),
05613                                               pixSpotId.GetSpot(),gain);
05614         if (end==2) avM16VA2SE2.AddMultiPoint(pixSpotId.GetPixel(),
05615                                               pixSpotId.GetSpot(),gain);
05616       }
05617     }
05618     
05619     Int_t crate=Plane2Crate(plane,end,det);
05620     if (crate>=FIRSTCRATE && crate<=LASTCRATE){
05621       hStripVsPlaneGainErr[crate]->Fill(plane,strip,gainErr);
05622       hStripVsPlaneGain[crate]->Fill(plane,strip,gain);
05623       hStripVsPlaneSPEWidth[crate]->Fill(plane,strip,SPEWidth);
05624     }
05625 
05626     Bool_t print=false;
05627     if (det==DetectorType::kCalDet) print=true;
05628     else if (det==DetectorType::kFar && 
05629              MsgService::Instance()->
05630              IsActive("LIPlexMaps",Msg::kDebug)) print=true;
05631     else if (det==DetectorType::kNear && 
05632              MsgService::Instance()->
05633              IsActive("LIPlexMaps",Msg::kDebug)) print=true;
05634     
05635     if (print){
05636       MSG("LIPlexMaps",Msg::kInfo)
05637         <<"("<<plane<<";"<<strip<<";"<<end<<")"
05638         <<" Gain="<<gain<<", gainErr="<<gainErr<<", SPEW="<<SPEWidth
05639         <<", seId="<<seId<<endl;
05640     }
05641   }
05642 
05643   //if ();
05644   for (vector<LIPmt*>::iterator it=vPmts.begin(); 
05645        it!=vPmts.end();it++) {
05646 
05647     if ((*it)->IsEmpty()) cout<<"empty"<<endl;
05648     else{
05649       cout<<"not emp"<<endl;
05650       (*it)->Print();
05651     }
05652   }
05653 
05654 
05655 
05656   for (Int_t pl=*planeMin;pl<*planeMax;pl++){
05657     for (Int_t st=-1;st<NUMSTRIPS+2;st++){
05658       for (Int_t se=0;se<NUMSIDES;se++){
05659 
05660         //get stripend id
05661         PlexStripEndId seid(static_cast<DetectorType::EDetectorType>
05662                             (det),pl,st,
05663                             static_cast<StripEnd::EStripEnd>(se+1));
05664         
05665         //get pixel ids from strip end
05666         PlexPixelSpotId psid=plexHandle.GetPixelSpotId(seid);
05667         ElecType::Elec_t elecType=plexHandle.GetRawChannelId(seid).
05668           GetElecType();
05669         
05670         if (se+1==StripEnd::kWest && elecType==ElecType::kQIE){
05671           
05672           Double_t gain=avM64SE2.GetPixelGain(psid.GetPixel());
05673           
05674           hAvDetGains[1]->Fill(pl,st,gain);
05675         }
05676       }
05677     }
05678   }
05679 
05680   //draw the m64s
05681   if (!avM64SE1.IsEmpty() || !avM64SE2.IsEmpty()){
05682     TCanvas *cPmtFaceM64=new TCanvas
05683       ("cPmtFaceM64","cPmtFaceM64",0,0,1000,550);
05684     cPmtFaceM64->SetFillColor(0);
05685     cPmtFaceM64->Divide(2,1);
05686     cPmtFaceM64->cd(1);
05687     fS="M64 Gains (Stripend 1)"; 
05688     if (!avM64SE1.IsEmpty()) avM64SE1.GetPmtFaceMap(fS.c_str())->
05689                                 Draw("colztext");
05690     cPmtFaceM64->cd(2);
05691     fS="M64 Gains (Stripend 2)"; 
05692     if (!avM64SE2.IsEmpty()) avM64SE2.GetPmtFaceMap(fS.c_str())->
05693                                 Draw("colztext");
05694   }
05695 
05696   //draw the m16s
05697   if (!avM16VA0SE1.IsEmpty() || !avM16VA0SE1.IsEmpty() ||
05698       !avM16VA1SE1.IsEmpty() || !avM16VA1SE1.IsEmpty() ||
05699       !avM16VA2SE1.IsEmpty() || !avM16VA2SE1.IsEmpty()){
05700 
05701     TCanvas *cPmtFaceM16=new TCanvas
05702       ("cPmtFaceM16","cPmtFaceM16",0,0,1000,700);
05703     cPmtFaceM16->SetFillColor(0);
05704     cPmtFaceM16->Divide(3,2);
05705     cPmtFaceM16->cd(1);
05706     fS="M16 Gains (VA0, stripend1)"; 
05707     if (!avM16VA0SE1.IsEmpty()) avM16VA0SE1.GetPmtFaceMap(fS.c_str())->
05708                                    Draw("colztext");
05709     cPmtFaceM16->cd(2);
05710     fS="M16 Gains (VA1, stripend1)"; 
05711     if (!avM16VA1SE1.IsEmpty()) avM16VA1SE1.GetPmtFaceMap(fS.c_str())->
05712                                    Draw("colztext");
05713     cPmtFaceM16->cd(3);
05714     fS="M16 Gains (VA2, stripend1)"; 
05715     if (!avM16VA2SE1.IsEmpty()) avM16VA2SE1.GetPmtFaceMap(fS.c_str())->
05716                                    Draw("colztext");
05717     cPmtFaceM16->cd(4);
05718     fS="M16 Gains (VA0, stripend2)"; 
05719     if (!avM16VA0SE2.IsEmpty()) avM16VA0SE2.GetPmtFaceMap(fS.c_str())->
05720                                    Draw("colztext");
05721     cPmtFaceM16->cd(5);
05722     fS="M16 Gains (VA1, stripend2)"; 
05723     if (!avM16VA1SE2.IsEmpty()) avM16VA1SE2.GetPmtFaceMap(fS.c_str())->
05724                                    Draw("colztext");
05725     cPmtFaceM16->cd(6);
05726     fS="M16 Gains (VA2, stripend2)"; 
05727     if (!avM16VA2SE2.IsEmpty()) avM16VA2SE2.GetPmtFaceMap(fS.c_str())->
05728                                    Draw("colztext");
05729   }
05730 
05731   //do gains
05732   TCanvas *cAvDetGain=new TCanvas
05733     ("cAvDetGain","cAvDetGain",0,0,1000,800);
05734   cAvDetGain->SetFillColor(0);
05735   cAvDetGain->cd();
05736   hAvDetGains[1]->Draw("colz");
05737 
05738   //set stats info off
05739   gStyle->SetOptStat(0);
05740   
05741   //do gains
05742   TCanvas *cStripVsPlaneGain=new TCanvas
05743     ("cStripVsPlaneGain","StripVsPlane: Gain",0,0,1000,800);
05744   cStripVsPlaneGain->SetFillColor(0);
05745   cStripVsPlaneGain->cd();
05746   string sDbGains="DbGains";
05747   sDbGains+=DetectorType::AsString(static_cast<DetectorType::
05748                                    EDetectorType>(det));
05749   sDbGains+=".ps";
05750   cStripVsPlaneGain->Print((sDbGains+"[").c_str());
05751   gErrorIgnoreLevel=1;
05752   for (Int_t i=0;i<NUMCRATES;i++){  
05753     cStripVsPlaneGain->Clear();
05754     hStripVsPlaneGain[i]->Draw("colz");
05755     cStripVsPlaneGain->Print(sDbGains.c_str());
05756   }
05757   cStripVsPlaneGain->Print((sDbGains+"]").c_str());
05758   gErrorIgnoreLevel=0;
05759 
05760   //do gain errs
05761   TCanvas *cStripVsPlaneGainErr=new TCanvas
05762     ("cStripVsPlaneGainErr","StripVsPlane: GainErr",0,0,1000,800);
05763   cStripVsPlaneGainErr->SetFillColor(0);
05764   cStripVsPlaneGainErr->cd();
05765   string sDbGainErrs="DbGainErrs";
05766   sDbGainErrs+=DetectorType::AsString(static_cast<DetectorType::
05767                                        EDetectorType>(det));
05768   sDbGainErrs+=".ps";
05769   cStripVsPlaneGainErr->Print((sDbGainErrs+"[").c_str());
05770   gErrorIgnoreLevel=1;
05771   for (Int_t i=0;i<NUMCRATES;i++){  
05772     cStripVsPlaneGainErr->Clear();
05773     hStripVsPlaneGainErr[i]->Draw("colz");
05774     cStripVsPlaneGainErr->Print(sDbGainErrs.c_str());
05775   }
05776   cStripVsPlaneGainErr->Print((sDbGainErrs+"]").c_str());
05777   gErrorIgnoreLevel=0;
05778 
05779   //do SPEWidths
05780   TCanvas *cStripVsPlaneSPEWidth=new TCanvas
05781     ("cStripVsPlaneSPEWidth","StripVsPlane: SPEWidth",0,0,1000,800);
05782   cStripVsPlaneSPEWidth->SetFillColor(0);
05783   cStripVsPlaneSPEWidth->cd();
05784   string sDbSPEWidths="DbSPEWidths";
05785   sDbSPEWidths+=DetectorType::AsString(static_cast<DetectorType::
05786                                        EDetectorType>(det));
05787   sDbSPEWidths+=".ps";
05788   cStripVsPlaneSPEWidth->Print((sDbSPEWidths+"[").c_str());
05789   gErrorIgnoreLevel=1;
05790   for (Int_t i=0;i<NUMCRATES;i++){  
05791     cStripVsPlaneSPEWidth->Clear();
05792     hStripVsPlaneSPEWidth[i]->Draw("colz");
05793     cStripVsPlaneSPEWidth->Print(sDbSPEWidths.c_str());
05794   }
05795   cStripVsPlaneSPEWidth->Print((sDbSPEWidths+"]").c_str());
05796   gErrorIgnoreLevel=0;
05797 
05798   if (det==DetectorType::kCalDet){
05799     TCanvas *cGain=new TCanvas("cGain","cGain",0,0,1000,800);
05800     cGain->SetFillColor(0);
05801     cGain->Divide(1,2);
05802     cGain->cd(1);
05803     hStripVsPlaneGain[0]->Draw("colz");
05804     cGain->cd(2);
05805     hStripVsPlaneGain[1]->Draw("colz");
05806   }
05807   
05808   gStyle->SetOptStat(1111);
05809   TCanvas *cGain=new TCanvas("cGain","cGain",0,0,1000,800);
05810   cGain->SetFillColor(0);
05811   cGain->Divide(2,1);
05812   cGain->cd(1);
05813   hGains->Draw();
05814   cGain->cd(2);
05815   hGainsAll->Draw();
05816 
05817   MSG("LIPlexMaps",Msg::kInfo)
05818     <<endl<<" ** Finished the ReadDbGains() method... ** "<<endl; 
05819 }
05820 
05821 //......................................................................
05822 
05823 void LIPlexMaps::ReadDbPulserDrift(Int_t det,VldTimeStamp ts) 
05824 {
05825   MSG("LIPlexMaps",Msg::kInfo)
05826     <<endl<<" ** Running the ReadDbPulserDrift() method... ** "<<endl; 
05827 
05828   //Thanks to Ryan for the DB code of this method  
05829   
05830   this->SetDetector(det);
05831 
05832   Int_t* planeMax=new Int_t[NUMCRATES];
05833   Int_t* planeMin=new Int_t[NUMCRATES];
05834   fLookup.SetPbPlanes(planeMin,planeMax,det);
05835 
05836   const Int_t firstStripBin=FIRSTSTRIP-8;//-8;
05837   const Int_t lastStripBin=LASTSTRIP+9;//200;
05838   const Int_t bins=lastStripBin-firstStripBin;
05839 
05840   string sConstantBit="";
05841 
05842   MSG("LIAnalysis",Msg::kInfo)
05843     <<"sConstantBit="<<sConstantBit<<endl;
05844 
05845   TH2F **hStripVsPlaneMean=0;
05846   hStripVsPlaneMean= new TH2F*[NUMCRATES];
05847   for (Int_t i=0;i<NUMCRATES;i++){
05848     string sPb=Form("%d",i);
05849     fS="Mean (Crate "+sPb+")";
05850     hStripVsPlaneMean[i]=new TH2F(fS.c_str(),fS.c_str(),
05851                                   planeMax[i]-planeMin[i],
05852                                   planeMin[i],planeMax[i],
05853                                   bins,firstStripBin,lastStripBin);
05854     hStripVsPlaneMean[i]->GetXaxis()->SetTitle("Plane");
05855     hStripVsPlaneMean[i]->GetXaxis()->CenterTitle();
05856     hStripVsPlaneMean[i]->GetYaxis()->SetTitle("Strip");
05857     hStripVsPlaneMean[i]->GetYaxis()->CenterTitle();
05858     hStripVsPlaneMean[i]->SetFillColor(0);
05859     //hStripVsPlaneMean[i]->SetBit(TH1::kCanRebin);
05860   }
05861 
05862   TH2F **hStripVsPlaneError=0;
05863   hStripVsPlaneError= new TH2F*[NUMCRATES];
05864   for (Int_t i=0;i<NUMCRATES;i++){
05865     string sPb=Form("%d",i);
05866     fS="Gain Error (Crate "+sPb+")";
05867     hStripVsPlaneError[i]=new TH2F(fS.c_str(),fS.c_str(),
05868                                      planeMax[i]-planeMin[i],
05869                                      planeMin[i],planeMax[i],
05870                                      bins,firstStripBin,lastStripBin);
05871     hStripVsPlaneError[i]->GetXaxis()->SetTitle("Plane");
05872     hStripVsPlaneError[i]->GetXaxis()->CenterTitle();
05873     hStripVsPlaneError[i]->GetYaxis()->SetTitle("Strip");
05874     hStripVsPlaneError[i]->GetYaxis()->CenterTitle();
05875     hStripVsPlaneError[i]->SetFillColor(0);
05876     //hStripVsPlaneError[i]->SetBit(TH1::kCanRebin);
05877   }
05878   
05879   TH2F **hStripVsPlaneNumEntries=0;
05880   hStripVsPlaneNumEntries= new TH2F*[NUMCRATES];
05881   for (Int_t i=0;i<NUMCRATES;i++){
05882     string sPb=Form("%d",i);
05883     fS="NumEntries_Crate"+sPb;
05884     hStripVsPlaneNumEntries[i]=new TH2F(fS.c_str(),fS.c_str(),
05885                                      planeMax[i]-planeMin[i],
05886                                      planeMin[i],planeMax[i],
05887                                      bins,firstStripBin,lastStripBin);
05888     hStripVsPlaneNumEntries[i]->GetXaxis()->SetTitle("Plane");
05889     hStripVsPlaneNumEntries[i]->GetXaxis()->CenterTitle();
05890     hStripVsPlaneNumEntries[i]->GetYaxis()->SetTitle("Strip");
05891     hStripVsPlaneNumEntries[i]->GetYaxis()->CenterTitle();
05892     hStripVsPlaneNumEntries[i]->SetFillColor(0);
05893     //hStripVsPlaneNumEntries[i]->SetBit(TH1::kCanRebin);
05894   }
05895 
05896   VldContext vldCtx(static_cast<DetectorType::EDetectorType>(det),
05897                     SimFlag::kData,ts);
05898   vldCtx.Print();
05899 
05900   //DbiResultPtr<PulserRawDrift> dbiPulserDrift;
05901   //DbiResultPtr<PulserRawDriftF> dbiPulserDrift;
05902   DbiResultPtr<PulserRefDrift> dbiPulserDrift;
05903   //DbiResultPtr<PulserRefDriftF> dbiPulserDrift;
05904 
05905   UInt_t numRows=dbiPulserDrift.NewQuery(vldCtx,0);
05906 
05907   MSG("LIPlexMaps",Msg::kInfo)
05908     <<"New DB query produced "<<numRows<<" rows"<<endl
05909     <<"Looping over rows..."<<endl;
05910 
05912   //loop over the rows
05914   for(UInt_t i=0;i<numRows;i++) {
05915     //const PulserRawDrift* pulserDrift = dbiPulserDrift.GetRow(i);
05916     //const PulserRawDriftF* pulserDrift = dbiPulserDrift.GetRow(i);
05917     const PulserRefDrift* pulserDrift = dbiPulserDrift.GetRow(i);
05918     //const PulserRefDriftF* pulserDrift = dbiPulserDrift.GetRow(i);
05919 
05920     Float_t mean=pulserDrift->GetMean();
05921     Float_t error=pulserDrift->GetError();
05922     Float_t numEntries=pulserDrift->GetNumEntries();
05923 
05924     UInt_t seidkey=pulserDrift->GetStripEnd();
05925     Int_t plane=-1;
05926     Int_t strip=-1;
05927     Int_t end=-1;
05928     fLookup.UnencodePlnStripEndKey(seidkey,static_cast<DetectorType::
05929                                    EDetectorType>(det),plane,strip,end);
05930 
05931     Int_t crate=Plane2Crate(plane,end,det);
05932     if (crate>=FIRSTCRATE && crate<=LASTCRATE){
05933       hStripVsPlaneMean[crate]->Fill(plane,strip,mean);
05934       hStripVsPlaneError[crate]->Fill(plane,strip,error);
05935       hStripVsPlaneNumEntries[crate]->Fill(plane,strip,numEntries);
05936     }
05937 
05938     Bool_t print=false;
05939 
05940     if (det==DetectorType::kCalDet) print=true;
05941     else if (det==DetectorType::kFar && 
05942              MsgService::Instance()->
05943              IsActive("LIPlexMaps",Msg::kDebug)) print=true;
05944     else if (det==DetectorType::kNear && 
05945              MsgService::Instance()->
05946              IsActive("LIPlexMaps",Msg::kDebug)) print=true;
05947     
05948     if (print){
05949       MSG("LIPlexMaps",Msg::kInfo)
05950         <<"("<<plane<<";"<<strip<<";"<<end<<")"
05951         <<" Mean="<<mean<<", error="<<error<<", numEnt="<<numEntries
05952         <<", seidkey="<<seidkey<<endl;
05953     }
05954   }
05956   //finished loop over the rows
05958 
05959   //set stats info off
05960   gStyle->SetOptStat(0);
05961 
05962   //do the means
05963   TCanvas *cStripVsPlaneMean=new TCanvas
05964     ("cStripVsPlaneMean","StripVsPlane: Mean",0,0,1000,800);
05965   cStripVsPlaneMean->SetFillColor(0);
05966   cStripVsPlaneMean->cd();
05967   string sDbMeans="DbDrift";
05968   sDbMeans+=DetectorType::AsString(static_cast<DetectorType::
05969                                    EDetectorType>(det));
05970   sDbMeans+=".ps";
05971   cStripVsPlaneMean->Print((sDbMeans+"[").c_str());
05972   gErrorIgnoreLevel=1;
05973   //set stats info off
05974   gStyle->SetOptStat(0);
05975   for (Int_t i=0;i<NUMCRATES;i++){
05976     cStripVsPlaneMean->Clear();
05977     hStripVsPlaneMean[i]->Draw("colz");
05978     cStripVsPlaneMean->Print(sDbMeans.c_str());
05979   }
05980   //close the file
05981   cStripVsPlaneMean->Print((sDbMeans+"]").c_str());
05982   gErrorIgnoreLevel=0;
05983 
05984   TCanvas *cStripVsPlaneError=new TCanvas  
05985     ("cStripVsPlaneError","StripVsPlane: Error",0,0,1000,800);  
05986   cStripVsPlaneError->SetFillColor(0);  
05987   cStripVsPlaneError->Divide(1,2);  
05988   cStripVsPlaneError->cd(1);  
05989   hStripVsPlaneError[0]->Draw("colz");  
05990   cStripVsPlaneError->cd(2);  
05991   hStripVsPlaneError[1]->Draw("colz");  
05992 
05993   TCanvas *cStripVsPlaneNumEntries=new TCanvas  
05994     ("cStripVsPlaneNumEntries","StripVsPlane: NumEntries",
05995      0,0,1000,800);  
05996   cStripVsPlaneNumEntries->SetFillColor(0);  
05997   cStripVsPlaneNumEntries->Divide(1,2);  
05998   cStripVsPlaneNumEntries->cd(1);  
05999   hStripVsPlaneNumEntries[0]->Draw("colz");  
06000   cStripVsPlaneNumEntries->cd(2);  
06001   hStripVsPlaneNumEntries[1]->Draw("colz");  
06002 
06003   MSG("LIPlexMaps",Msg::kInfo)
06004     <<endl<<" ** Finished the ReadDbPulserDrift() method... ** "<<endl; 
06005 }
06006 
06007 //......................................................................
06008 
06009 void LIPlexMaps::DriftWithTime(VldRange vldRng,
06010                                Float_t pointSpacingMinutes) 
06011 {
06012   MSG("LIPlexMaps",Msg::kInfo)
06013     <<endl<<" ** Running the DriftWithTime method... ** "<<endl; 
06014 
06015   //get all the info from the validity range
06016   VldTimeStamp startTime=vldRng.GetTimeStart();
06017   VldTimeStamp endTime=vldRng.GetTimeEnd();
06018   const DetectorType::EDetectorType det=static_cast
06019     <DetectorType::EDetectorType>(vldRng.GetDetectorMask());
06020   const SimFlag::ESimFlag simFlag=static_cast
06021     <SimFlag::ESimFlag>(vldRng.GetSimMask());
06022 
06023   //make a vld context for the start time
06024   VldContext startVldCtx(det,simFlag,startTime);
06025 
06026   //only set detector once at the highest/first point
06027   if (det==DetectorType::kCalDet){
06028     fLookup.SetDetector(static_cast<Int_t>(det));
06029   }
06030   else if (det==DetectorType::kFar){
06031     fLookup.SetDetector(static_cast<Int_t>(det));
06032   }
06033   else if (det==DetectorType::kNear){
06034     fLookup.SetDetector(static_cast<Int_t>(det));
06035   }
06036   else{
06037     MSG("LIPlexMaps",Msg::kWarning)
06038       <<"DetectorType not supported="
06039       <<DetectorType::AsString(det)<<endl
06040       <<"Program will exit here..."<<endl;
06041     exit(1);
06042   }
06043 
06044   DbiResultPtr<PulserRawDrift> dbiPulserDrift;
06045   DbiResultPtr<PulserRawDriftF> dbiPulserDriftF;
06046 
06047   MSG("LIPlexMaps",Msg::kInfo)
06048     <<"Creating maps..."<<endl;
06049   //a map to hold the reference pin info
06050   map<Int_t,LIPulserPin> refAdcPinRatio=this->
06051     GetRefAdcPinRatio(startVldCtx);//get it once to start with
06052   //maps to hold drift point info
06053   map<UInt_t,LIRun> stripEnds;
06054   map<PlexLedId,LIRun> pins;
06055 
06056   VldContext* vldCtx=0;
06057   const PulserRawDrift *pulserDrift;
06058   const PulserRawDriftF *pulserDriftF;
06059   string sLastVldRange="Not set!";
06060 
06061   //declare stripendtype
06062   StripEnd::EStripEnd stripEndType=StripEnd::kUnknown;
06063   StripEnd::EStripEnd stripEndTypeF=StripEnd::kUnknown;
06064 
06065   //create a plex handle
06066   PlexHandle* plexHandle=0;
06067 
06068   Int_t pointSpacingSecs=static_cast<Int_t>(pointSpacingMinutes*60);
06069   Int_t startTimeSecs=startTime.GetSec();
06070   Int_t endTimeSecs=endTime.GetSec();
06071   Int_t secCounter=startTimeSecs;
06072 
06073   MSG("LIPlexMaps",Msg::kInfo)
06074     <<"Starting main loop over vld range..."<<endl;
06075   while(secCounter<endTimeSecs){
06076     VldTimeStamp currentLoopTime(secCounter,0);
06077 
06078     //print out the current loop time
06079     if (MsgService::Instance()->IsActive("LIPlexMaps",Msg::kInfo)){
06080       MSG("LIPlexMaps",Msg::kInfo)<<"New Loop ";
06081       currentLoopTime.Print();
06082     }
06083     vldCtx=new VldContext(DetectorType::kCalDet,SimFlag::kData,
06084                           currentLoopTime);
06085 
06086     //check for a new pin reference point
06087     map<Int_t,LIPulserPin> tempRefAdcPinRatio=
06088       this->GetRefAdcPinRatio(*vldCtx);
06089     if (tempRefAdcPinRatio.size()>0){
06090       refAdcPinRatio=tempRefAdcPinRatio;
06091       MSG("LIPlexMaps",Msg::kInfo)
06092         <<"New pin reference point, regenerated map"<<endl;
06093     }
06094     else{
06095       MSG("LIPlexMaps",Msg::kDebug)
06096         <<"Checked for new pin reference point, doing nothing"
06097         <<" because same as before"<<endl;
06098     }
06099 
06100     //create a plex handle
06101     plexHandle=new PlexHandle(*vldCtx);
06102 
06103     UInt_t numRows=dbiPulserDrift.NewQuery(*vldCtx,0);
06104     
06105     if (numRows!=static_cast<UInt_t>(NUMPLANES*NUMSTRIPS*NUMENDS)){
06106       MSG("LIPlexMaps",Msg::kWarning)
06107         <<"PulserRawDrift only contains "<<numRows<<" rows"
06108         <<", it should have "<<NUMPLANES*NUMSTRIPS*NUMENDS<<endl;
06109     }
06110 
06111     string sVldRange=dbiPulserDrift.GetValidityRec()->GetVldRange().
06112       AsString();
06113 
06114     MSG("LIPlexMaps",Msg::kVerbose)
06115       <<"Vld range = "<<sVldRange<<endl;
06116 
06117     if (sVldRange==sLastVldRange){
06118       MSG("LIPlexMaps",Msg::kInfo)
06119         <<"Skipping this point because validity range is the same"
06120         <<" as the previous point"<<endl;
06121       MSG("LIPlexMaps",Msg::kDebug)
06122         <<endl
06123         <<"VldRange="<<sVldRange<<endl
06124         <<"Previous VldRange="<<sLastVldRange<<endl;
06125       //set the last range now it has been used in this loop
06126       sLastVldRange=sVldRange;
06127 
06128       //increment the time
06129       secCounter+=pointSpacingSecs;
06130         
06131       //delete currentLoopTime;
06132       delete vldCtx;
06133       delete plexHandle;
06134       continue;
06135     }
06136 
06137     //set the last range now it has been used in this loop
06138     sLastVldRange=sVldRange;
06139 
06140     map<Int_t,Float_t> rawPin=this->GetRawPinMap(*vldCtx);
06141     map<PlexLedId,LIPulserPin> rawPinLedMap=this->
06142       GetRawPinLedMap(*vldCtx);
06143     UInt_t numRowsF=dbiPulserDriftF.NewQuery(*vldCtx,0);
06144 
06145     if (numRows!=numRowsF){
06146       MSG("LIPlexMaps",Msg::kInfo)
06147         <<"Near and far end tables are different sizes! Near="
06148         <<numRows<<", far="<<numRowsF<<endl;
06149     }
06150 
06152     //loop over the pin values for all the leds
06154     for(Int_t pb=FIRSTPULSERBOX;pb<=LASTPULSERBOX;pb++){
06155       for(Int_t led=FIRSTLED;led<=LASTLED;led++){
06156         //create an ledid to then use the encoded value
06157         PlexLedId ledId(det,pb,led);
06158 
06159         //add the point
06160         pins[ledId].AddPoint
06161           (secCounter,rawPinLedMap[ledId].mean,
06162            rawPinLedMap[ledId].error,rawPinLedMap[ledId].numEnt);
06163 
06164         MSG("LIPlexMaps",Msg::kDebug)
06165           <<"Adding point to lirun "<<rawPinLedMap[ledId].mean<<endl;
06166       }
06167     }
06170     
06171     for(Int_t pl=FIRSTPLANE;pl<=LASTPLANE;pl++){
06172         
06173       //quick hack
06174       if (pl>5) continue;
06175 
06176       for(Int_t st=FIRSTSTRIP;st<=LASTSTRIP;st++){
06177         for(Int_t end=FIRSTEND;end<=SECONDEND;end++){
06178 
06179           if (end==StripEnd::kEast) stripEndType=StripEnd::kEast;
06180           else if (end==StripEnd::kWest) stripEndType=StripEnd::kWest;
06181 
06182           if (end==StripEnd::kEast) stripEndTypeF=StripEnd::kWest;
06183           else if(end==StripEnd::kWest) stripEndTypeF=StripEnd::kEast;
06184 
06185           PlexStripEndId stripEndId(det,pl,st,stripEndType);
06186           PlexStripEndId stripEndIdF(det,pl,st,stripEndTypeF);
06187 
06188           //skip the stripends that aren't attached to readout
06189           if (!this->IsScintStrip(stripEndId,plexHandle)) continue;
06190 
06191           pulserDrift=0;//initialise
06192           pulserDrift=dbiPulserDrift.GetRowByIndex
06193             (stripEndId.BuildPlnStripEndKey());
06194           //get the opposite strip end for the to do ND/FD
06195           pulserDriftF=0;//initialise
06196           pulserDriftF=dbiPulserDriftF.GetRowByIndex
06197             (stripEndIdF.BuildPlnStripEndKey());
06198 
06199           if (pulserDrift){
06200             Float_t mean=pulserDrift->GetMean();
06201             Float_t error=pulserDrift->GetError();
06202             Float_t numEntries=pulserDrift->GetNumEntries();
06203             UInt_t seidkey=pulserDrift->GetStripEnd();
06204 
06205             Float_t meanF=-1;
06206             Float_t errorF=-1;
06207             Float_t numEntriesF=-1;
06208 
06209             if (pulserDriftF){
06210               meanF=pulserDriftF->GetMean();
06211               errorF=pulserDriftF->GetError();
06212               numEntriesF=pulserDriftF->GetNumEntries();
06213             }
06214 
06215             Float_t nearOverFar=-1;
06216             if (meanF>0){
06217               if (stripEndType==StripEnd::kWest){
06218                 nearOverFar=mean/meanF;
06219               }
06220               else if (stripEndType==StripEnd::kEast){
06221                 nearOverFar=meanF/mean;
06222               }
06223             }
06224 
06225             Float_t adcPinRatio=-1;
06226             if (rawPin[seidkey]>0){
06227               adcPinRatio=mean/rawPin[seidkey];
06228             }
06229             else {
06230               MSG("LIPlexMaps",Msg::kDebug)
06231                 <<"Raw pin has zero mean!"<<endl;
06232             }
06233 
06234             Float_t gainDrift=-1;
06235             if (refAdcPinRatio[seidkey].mean>0){//protect fpe
06236               if (adcPinRatio>0){//only bother if this is good
06237                 gainDrift=adcPinRatio/refAdcPinRatio[seidkey].mean;
06238               }
06239             }
06240             else {
06241               MSG("LIPlexMaps",Msg::kWarning)
06242                 <<"Ref ADC/PIN ratio has zero mean!"<<endl;
06243             }
06244 
06245             MSG("LIPlexMaps",Msg::kDebug)
06246               <<"Gain drift="<<gainDrift<<endl;
06247               
06248             if (numEntries>500 && gainDrift>0){
06249               stripEnds[seidkey].AddPoint(secCounter,mean,error,
06250                                           numEntries,gainDrift,
06251                                           nearOverFar);
06252             }
06253               
06254             Int_t plane=-1;
06255             Int_t strip=-1;
06256             Int_t end=-1;
06257             fLookup.UnencodePlnStripEndKey(seidkey,det,plane,strip,
06258                                            end);
06259               
06260             string sMean=Form("%.1f",mean);
06261             string sError=Form("%.2f",error);
06262             string sNumEntries=Form("%.0f",numEntries);
06263             string sSeId=Form("%d",seidkey);
06264 
06265             MSG("LIPlexMaps",Msg::kDebug)
06266               <<"("<<plane<<";"<<strip<<";"<<end<<")"
06267               <<" Mean="<<sMean<<", error="<<sError
06268               <<", numEnt="<<sNumEntries
06269               <<", seidkey="<<sSeId<<endl;
06270           }
06271         }
06272       }
06273     }
06274 
06275     //increment the time
06276     secCounter+=pointSpacingSecs;
06277 
06278     //delete currentLoopTime;
06279     delete vldCtx;
06280     delete plexHandle;
06281   }
06282   //}
06283   
06284   MSG("LIPlexMaps",Msg::kInfo)
06285     <<"Finished main loop over vld range"<<endl;
06286 
06287   //declare the canvas sizes
06288   Int_t canvasXmax=1200;
06289   Int_t canvasYmax=600;
06290 
06291   //create the canvases
06292   TCanvas *cMeanVsTime=new TCanvas("cMeanVsTime","MeanVsTime",
06293                                    0,0,canvasXmax,canvasYmax);
06294   cMeanVsTime->SetFillColor(0);
06295   TCanvas *cErrorVsTime=new TCanvas("cErrorVsTime","ErrorVsTime",
06296                                     0,0,canvasXmax,canvasYmax);
06297   cErrorVsTime->SetFillColor(0);
06298   TCanvas *cNumEntVsTime=new TCanvas("cNumEntVsTime","NumEntVsTime",
06299                                      0,0,canvasXmax,canvasYmax);
06300   cNumEntVsTime->SetFillColor(0);
06301   TCanvas *cGainDriftVsTime=new TCanvas("cGainDriftVsTime",
06302                                         "GainDriftVsTime",
06303                                         0,0,canvasXmax,canvasYmax);
06304   cGainDriftVsTime->SetFillColor(0);
06305   TCanvas *cGainDriftVsTimeZoom=new TCanvas("cGainDriftVsTimeZoom",
06306                                         "GainDriftVsTimeZoom",
06307                                         0,0,canvasXmax,canvasYmax);
06308   cGainDriftVsTimeZoom->SetFillColor(0);
06309   TCanvas *cPinVsTime=new TCanvas("cPinVsTime","PinVsTime",
06310                                    0,0,canvasXmax,canvasYmax);
06311   cPinVsTime->SetFillColor(0);
06312   TCanvas *cNormPinVsTime=new TCanvas("cNormPinVsTime","NormPinVsTime",
06313                                       0,0,canvasXmax,canvasYmax);
06314   cNormPinVsTime->SetFillColor(0);
06315   TCanvas *cNormPinVsTimeZoom=new TCanvas("cNormPinVsTimeZoom",
06316                                           "NormPinVsTimeZoom",
06317                                           0,0,canvasXmax,canvasYmax);
06318   cNormPinVsTimeZoom->SetFillColor(0);
06319   TCanvas *cPinErrorVsTime=new TCanvas("cPinErrorVsTime",
06320                                        "PinErrorVsTime",
06321                                        0,0,canvasXmax,canvasYmax);
06322   cPinErrorVsTime->SetFillColor(0);
06323   TCanvas *cPinNumEntVsTime=new TCanvas("cPinNumEntVsTime",
06324                                         "PinNumEntVsTime",
06325                                         0,0,canvasXmax,canvasYmax);
06326   cPinNumEntVsTime->SetFillColor(0);
06327   TCanvas *cNearOverFarVsTime=new TCanvas("cNearOverFarVsTime",
06328                                     "NearOverFarVsTime",
06329                                     0,0,canvasXmax,canvasYmax);
06330   cNearOverFarVsTime->SetFillColor(0);
06331   TCanvas *cNormNearOverFarVsTime=new TCanvas("cNormNearOverFarVsTime",
06332                                     "NormNearOverFarVsTime",
06333                                     0,0,canvasXmax,canvasYmax);
06334   cNormNearOverFarVsTime->SetFillColor(0);
06335 
06336   string sMeanVsTime="MeanVsTime.ps";
06337   string sErrorVsTime="ErrorVsTime.ps";
06338   string sNumEntVsTime="NumEntVsTime.ps";
06339   string sGainDriftVsTime="GainDriftVsTime.ps";
06340   string sGainDriftVsTimeZoom="GainDriftVsTimeZoom.ps";
06341   string sPinVsTime="PinVsTime.ps";
06342   string sNormPinVsTime="NormPinVsTime.ps";
06343   string sNormPinVsTimeZoom="NormPinVsTimeZoom.ps";
06344   string sPinErrorVsTime="PinErrorVsTime.ps";
06345   string sPinNumEntVsTime="PinNumEntVsTime.ps";
06346   string sNearOverFarVsTime="NearOverFarVsTime.ps";
06347   string sNormNearOverFarVsTime="NormNearOverFarVsTime.ps";
06348 
06349   //open the files
06350   cMeanVsTime->Print((sMeanVsTime+"[").c_str());
06351   cErrorVsTime->Print((sErrorVsTime+"[").c_str());
06352   cNumEntVsTime->Print((sNumEntVsTime+"[").c_str());
06353   cGainDriftVsTime->Print((sGainDriftVsTime+"[").c_str());
06354   cGainDriftVsTimeZoom->Print((sGainDriftVsTimeZoom+"[").c_str());
06355   cPinVsTime->Print((sPinVsTime+"[").c_str());
06356   cNormPinVsTime->Print((sNormPinVsTime+"[").c_str());
06357   cNormPinVsTimeZoom->Print((sNormPinVsTimeZoom+"[").c_str());
06358   cPinErrorVsTime->Print((sPinErrorVsTime+"[").c_str());
06359   cPinNumEntVsTime->Print((sPinNumEntVsTime+"[").c_str());
06360   cNearOverFarVsTime->Print((sNearOverFarVsTime+"[").c_str());
06361   cNormNearOverFarVsTime->Print((sNormNearOverFarVsTime+"[").c_str());
06362 
06363   gErrorIgnoreLevel=1;//suppress printing each page messages
06364 
06366   //Loop over the pins
06368   map<PlexLedId,LIRun>::iterator pinIt=pins.begin();
06369 
06370   MSG("LIPlexMaps",Msg::kInfo)
06371     <<"Iterating over the pins..."<<endl;
06372   while(pinIt!=pins.end()){
06373 
06374     //get the vectors, the names are all wrong but 
06375     //the correct values were stored above
06376     vector<Double_t> vTime=pinIt->second.GetPh();
06377     vector<Double_t> vMean=pinIt->second.GetAdc();
06378     vector<Double_t> vError=pinIt->second.GetPin(1);
06379     vector<Double_t> vNumEnt=pinIt->second.GetPin(2);
06380 
06381     TGraph* gPinVsTime=0;
06382     TGraph* gNormPinVsTime=0;
06383     TGraph* gNormPinVsTimeZoom=0;
06384     TGraph* gPinErrorVsTime=0;
06385     TGraph* gPinNumEntVsTime=0;
06386     
06387     gPinVsTime=TGraphVect(vTime,vMean);
06388     gPinErrorVsTime=TGraphVect(vTime,vError);
06389     gPinNumEntVsTime=TGraphVect(vTime,vNumEnt);
06390 
06391     string sPb=Form("%d",pinIt->first.GetPulserBox());
06392     string sLed=Form("%d",pinIt->first.GetLedInBox());
06393 
06394     MSG("LIPlexMaps",Msg::kInfo)
06395       <<"Printing ("<<sPb<<":"<<sLed<<")"
06396       <<" to postscript"<<endl;
06397 
06398     cPinVsTime->cd();
06399     cPinVsTime->Clear();
06400     fS="Light level drifts (PIN ADC) with time (PB,LED)=("+
06401       sPb+","+sLed+")";
06402     gPinVsTime->Draw("AP");
06403     gPinVsTime->SetTitle(fS.c_str());
06404     gPinVsTime->GetYaxis()->SetTitle("Pin ADC");
06405     gPinVsTime->GetYaxis()->CenterTitle();
06406     this->SetGraphAxisEtc(gPinVsTime,startTimeSecs,endTimeSecs);
06407 
06408     //normalise the vector then get the graph
06409     this->NormaliseVector(vMean,2);
06410     gNormPinVsTime=TGraphVect(vTime,vMean);
06411     gNormPinVsTimeZoom=TGraphVect(vTime,vMean);
06412 
06413     cNormPinVsTime->cd();
06414     cNormPinVsTime->Clear();
06415     fS="Fractional Drifts in PIN ADC with time (PB,LED)=("+
06416       sPb+","+sLed+")";
06417     gNormPinVsTime->Draw("AP");
06418     gNormPinVsTime->SetTitle(fS.c_str());
06419     gNormPinVsTime->GetYaxis()->SetTitle("Normalised Pin ADC");
06420     gNormPinVsTime->GetYaxis()->CenterTitle();
06421     this->SetGraphAxisEtc(gNormPinVsTime,startTimeSecs,endTimeSecs); 
06422 
06423     cNormPinVsTimeZoom->cd();
06424     cNormPinVsTimeZoom->Clear();
06425     fS="Fractional Drifts in PIN ADC with time, zoomed (PB,LED)=("+
06426       sPb+","+sLed+")";
06427     gNormPinVsTimeZoom->Draw("AP");
06428     gNormPinVsTimeZoom->SetTitle(fS.c_str());
06429     gNormPinVsTimeZoom->GetYaxis()->SetTitle("Normalised Pin ADC");
06430     gNormPinVsTimeZoom->GetYaxis()->CenterTitle();
06431     this->SetGraphAxisEtc(gNormPinVsTimeZoom,startTimeSecs,endTimeSecs);
06432     gNormPinVsTimeZoom->SetMinimum(0.97);
06433     gNormPinVsTimeZoom->SetMaximum(1.03);
06434     //gNormPinVsTimeZoom->SetMinimum(1.13);
06435     //gNormPinVsTimeZoom->SetMaximum(1.23);
06436 
06437     cPinErrorVsTime->cd();
06438     cPinErrorVsTime->Clear();
06439     fS="Error on the PIN vs time (PB,LED)=("+
06440       sPb+","+sLed+")";
06441     gPinErrorVsTime->Draw("AP");
06442     gPinErrorVsTime->SetTitle(fS.c_str());
06443     gPinErrorVsTime->GetYaxis()->SetTitle("PinError in ADCs");
06444     gPinErrorVsTime->GetYaxis()->CenterTitle();
06445     this->SetGraphAxisEtc(gPinErrorVsTime,startTimeSecs,endTimeSecs); 
06446 
06447     cPinNumEntVsTime->cd();
06448     cPinNumEntVsTime->Clear();
06449     fS="PIN Number of Entries vs Time (PB,LED)=("+
06450       sPb+","+sLed+")";
06451     gPinNumEntVsTime->Draw("AP");
06452     gPinNumEntVsTime->SetTitle(fS.c_str());
06453     gPinNumEntVsTime->GetYaxis()->SetTitle("Pin's Number of Entries");
06454     gPinNumEntVsTime->GetYaxis()->CenterTitle();
06455     this->SetGraphAxisEtc(gPinNumEntVsTime,startTimeSecs,endTimeSecs); 
06456 
06457     //print to postscript
06458     cPinVsTime->Print(sPinVsTime.c_str());
06459     cNormPinVsTime->Print(sNormPinVsTime.c_str());
06460     cNormPinVsTimeZoom->Print(sNormPinVsTimeZoom.c_str());
06461     cPinErrorVsTime->Print(sPinErrorVsTime.c_str());
06462     cPinNumEntVsTime->Print(sPinNumEntVsTime.c_str());
06463 
06464     //avoid program getting too big
06465     delete gPinVsTime;
06466     delete gNormPinVsTime;
06467     delete gNormPinVsTimeZoom;
06468     delete gPinErrorVsTime;
06469     delete gPinNumEntVsTime;
06470     
06471     //go to next pin
06472     pinIt++;
06473   }
06474   MSG("LIPlexMaps",Msg::kInfo)
06475     <<"Finished iterating over the pins"<<endl;
06476 
06478   //Now look at the stripends
06480   map<UInt_t,LIRun>::iterator seIt=stripEnds.begin();
06481   Int_t pageCounter=0;
06482 
06483   MSG("LIPlexMaps",Msg::kInfo)
06484     <<endl<<"Iterating over the stripends..."
06485     <<endl<<"Map size="<<stripEnds.size()<<endl;
06486   while(seIt!=stripEnds.end()){
06487 
06488     Int_t seidkey=seIt->first;
06489     Int_t plane=-1;
06490     Int_t strip=-1;
06491     Int_t end=-1;
06492     fLookup.UnencodePlnStripEndKey(seidkey,det,plane,strip,end);
06493 
06494     string sPlane=Form("%d",plane);
06495     string sStrip=Form("%d",strip);
06496     string sEnd=Form("%d",end);
06497 
06498     //get the vectors, the names are all wrong but 
06499     //the correct values were stored above
06500     vector<Double_t> vTime=seIt->second.GetPh();
06501     vector<Double_t> vMean=seIt->second.GetAdc();
06502     vector<Double_t> vError=seIt->second.GetPin(1);
06503     vector<Double_t> vNumEnt=seIt->second.GetPin(2);
06504     vector<Double_t> vGainDrift=seIt->second.GetAdcF();
06505     vector<Double_t> vGainDriftZoom=seIt->second.GetAdcF();
06506     vector<Double_t> vNearOverFar=seIt->second.GetAdcLow();
06507 
06508     TGraph* gMeanVsTime=0;
06509     TGraph* gErrorVsTime=0;
06510     TGraph* gNumEntVsTime=0;
06511     TGraph* gGainDriftVsTime=0;
06512     TGraph* gGainDriftVsTimeZoom=0;
06513     TGraph* gNearOverFarVsTime=0;
06514     TGraph* gNormNearOverFarVsTime=0;
06515     
06516     gMeanVsTime=TGraphVect(vTime,vMean);
06517     gErrorVsTime=TGraphVect(vTime,vError);
06518     gNumEntVsTime=TGraphVect(vTime,vNumEnt);
06519     gGainDriftVsTime=TGraphVect(vTime,vGainDrift);
06520     gGainDriftVsTimeZoom=TGraphVect(vTime,vGainDriftZoom);
06521 
06522     gNearOverFarVsTime=0;
06523     if (vNearOverFar.size()>0){
06524       gNearOverFarVsTime=TGraphVect(vTime,vNearOverFar);
06525     }
06526 
06527     if (gMeanVsTime){
06528       cMeanVsTime->cd();
06529       cMeanVsTime->Clear();
06530       fS="Mean drifting with time (Pl,St,End)=("+sPlane+","+sStrip+","+
06531         sEnd+")";
06532       gMeanVsTime->Draw("AP");
06533       gMeanVsTime->SetTitle(fS.c_str());
06534       gMeanVsTime->GetYaxis()->SetTitle("Mean ADC");
06535       gMeanVsTime->GetYaxis()->CenterTitle();
06536       this->SetGraphAxisEtc(gMeanVsTime,startTimeSecs,endTimeSecs); 
06537     }
06538     else{
06539       //go to next se
06540       seIt++;
06541       MSG("LIPlexMaps",Msg::kInfo)
06542         <<"Skipping: ("<<plane<<";"<<strip<<";"<<end<<")"<<endl;
06543       continue;
06544     }
06545 
06546     if (gErrorVsTime){
06547       cErrorVsTime->cd();
06548       cErrorVsTime->Clear();
06549       fS="Error on mean over time (Pl,St,End)=("+sPlane+","+sStrip+","+
06550         sEnd+")";
06551       gErrorVsTime->Draw("AP");
06552       gErrorVsTime->SetTitle(fS.c_str());
06553       gErrorVsTime->GetYaxis()->SetTitle("Error (ADCs)");
06554       gErrorVsTime->GetYaxis()->CenterTitle();
06555       this->SetGraphAxisEtc(gErrorVsTime,startTimeSecs,endTimeSecs); 
06556     }
06557 
06558     if (gNumEntVsTime){
06559       cNumEntVsTime->cd();
06560       cNumEntVsTime->Clear();
06561       fS="NumEnt over time (Pl,St,End)=("+sPlane+","+sStrip+","+
06562         sEnd+")";
06563       gNumEntVsTime->Draw("AP");
06564       gNumEntVsTime->SetTitle(fS.c_str());
06565       gNumEntVsTime->GetYaxis()->SetTitle("NumEnt");
06566       gNumEntVsTime->GetYaxis()->CenterTitle();
06567       this->SetGraphAxisEtc(gNumEntVsTime,startTimeSecs,endTimeSecs);
06568     }
06569 
06570     if (gGainDriftVsTime){
06571       cGainDriftVsTime->cd();
06572       cGainDriftVsTime->Clear();
06573       fS="Gain drift over time (Pl,St,End)=("+sPlane+","+sStrip+","+
06574         sEnd+")";
06575       gGainDriftVsTime->Draw("AP");
06576       gGainDriftVsTime->SetTitle(fS.c_str());
06577       gGainDriftVsTime->GetYaxis()->SetTitle("Gain Drift");
06578       gGainDriftVsTime->GetYaxis()->CenterTitle();
06579       this->SetGraphAxisEtc(gGainDriftVsTime,startTimeSecs,
06580                             endTimeSecs); 
06581     }
06582       
06583     if (gGainDriftVsTimeZoom){
06584       cGainDriftVsTimeZoom->cd();
06585       cGainDriftVsTimeZoom->Clear();
06586       fS="Gain drift over time - zoomed (Pl,St,End)=("+
06587         sPlane+","+sStrip+","+sEnd+")";
06588       gGainDriftVsTimeZoom->Draw("AP");
06589       gGainDriftVsTimeZoom->SetTitle(fS.c_str());
06590       gGainDriftVsTimeZoom->GetYaxis()->SetTitle("Gain Drift");
06591       gGainDriftVsTimeZoom->GetYaxis()->CenterTitle();
06592       this->SetGraphAxisEtc(gGainDriftVsTimeZoom,startTimeSecs,
06593                             endTimeSecs);  
06594       gGainDriftVsTimeZoom->SetMaximum(1.11);
06595       gGainDriftVsTimeZoom->SetMinimum(0.89);
06596     }
06597 
06598     if (gNearOverFarVsTime){
06599       cNearOverFarVsTime->cd();
06600       cNearOverFarVsTime->Clear();
06601       fS="Ratio of ND/FD vs Time (Pl,St,End)=("+
06602         sPlane+","+sStrip+","+sEnd+")";
06603       gNearOverFarVsTime->Draw("AP");
06604       gNearOverFarVsTime->SetTitle(fS.c_str());
06605       gNearOverFarVsTime->GetYaxis()->SetTitle("Ratio ND/FD");
06606       gNearOverFarVsTime->GetYaxis()->CenterTitle();
06607       this->SetGraphAxisEtc(gNearOverFarVsTime,startTimeSecs,
06608                             endTimeSecs);
06609     }
06610     
06611     gNormNearOverFarVsTime=0;
06612     if (vNearOverFar.size()>0){
06613       this->NormaliseVector(vNearOverFar);
06614       gNormNearOverFarVsTime=TGraphVect(vTime,vNearOverFar);
06615     }
06616 
06617     if (gNormNearOverFarVsTime){
06618       cNormNearOverFarVsTime->cd();
06619       cNormNearOverFarVsTime->Clear();
06620       fS="Ratio of Normalised ND/FD vs Time (Pl,St,End)=("+
06621         sPlane+","+sStrip+","+sEnd+")";
06622       gNormNearOverFarVsTime->Draw("AP");
06623       gNormNearOverFarVsTime->SetTitle(fS.c_str());
06624       gNormNearOverFarVsTime->GetYaxis()->SetTitle("Ratio ND/FD");
06625       gNormNearOverFarVsTime->GetYaxis()->CenterTitle();
06626       this->SetGraphAxisEtc(gNormNearOverFarVsTime,startTimeSecs,
06627                             endTimeSecs);
06628     }
06629 
06630     //print to postscript
06631     cMeanVsTime->Print(sMeanVsTime.c_str());
06632     cErrorVsTime->Print(sErrorVsTime.c_str());
06633     cNumEntVsTime->Print(sNumEntVsTime.c_str());
06634     cGainDriftVsTime->Print(sGainDriftVsTime.c_str());
06635     cGainDriftVsTimeZoom->Print(sGainDriftVsTimeZoom.c_str());
06636     cNearOverFarVsTime->Print(sNearOverFarVsTime.c_str());
06637     cNormNearOverFarVsTime->Print(sNormNearOverFarVsTime.c_str());
06638 
06639     //avoid program getting too big
06640     MSG("LIPlexMaps",Msg::kVerbose)
06641       <<"Deleting graphs..."<<endl;
06642     delete gMeanVsTime;
06643     delete gErrorVsTime;
06644     delete gNumEntVsTime;
06645     delete gGainDriftVsTime;
06646     delete gGainDriftVsTimeZoom;
06647     delete gNearOverFarVsTime;
06648     delete gNormNearOverFarVsTime;
06649 
06650     pageCounter++;
06651     if (pageCounter%50==0){
06652       MSG("LIPlexMaps",Msg::kInfo)
06653         <<"Number of pages = "<<pageCounter<<endl;
06654     }
06655     else {
06656       MSG("LIPlexMaps",Msg::kVerbose)
06657         <<"Number of pages = "<<pageCounter<<endl;
06658     }
06659 
06660     //go to next se
06661     seIt++;
06662   }
06663   
06664   //close the files
06665   gErrorIgnoreLevel=0;//turn on printing messages 
06666   cMeanVsTime->Print((sMeanVsTime+"]").c_str());
06667   cErrorVsTime->Print((sErrorVsTime+"]").c_str());
06668   cNumEntVsTime->Print((sNumEntVsTime+"]").c_str());
06669   cGainDriftVsTime->Print((sGainDriftVsTime+"]").c_str());
06670   cGainDriftVsTimeZoom->Print((sGainDriftVsTimeZoom+"]").c_str());
06671   cNearOverFarVsTime->Print((sNearOverFarVsTime+"]").c_str());
06672   cNormNearOverFarVsTime->Print((sNormNearOverFarVsTime+"]").c_str());
06673 
06674   cPinVsTime->Print((sPinVsTime+"]").c_str());
06675   cNormPinVsTime->Print((sNormPinVsTime+"]").c_str());
06676   cNormPinVsTimeZoom->Print((sNormPinVsTimeZoom+"]").c_str());
06677   cPinErrorVsTime->Print((sPinErrorVsTime+"]").c_str());
06678   cPinNumEntVsTime->Print((sPinNumEntVsTime+"]").c_str());
06679 
06680   MSG("LIPlexMaps",Msg::kInfo)
06681     <<endl<<" ** Finished the DriftWithTime method... ** "<<endl; 
06682 }
06683 
06684 //......................................................................
06685 
06686 void LIPlexMaps::SetGraphAxisEtc(TGraph* g,Int_t startTimeSecs,
06687                                  Int_t endTimeSecs) 
06688 {
06689   MSG("LIPlexMaps",Msg::kVerbose)
06690     <<endl<<" ** Running the SetGraphAxisEtc method... ** "<<endl;
06691 
06692   TDatime startDatime;
06693   startDatime.Set(startTimeSecs);
06694 
06695   TDatime endDatime;
06696   endDatime.Set(endTimeSecs);
06697 
06698   //play around with the formatting a little
06699   string sStartHour=Form("%d",startDatime.GetHour());
06700   string sStartMinute=Form("%d",startDatime.GetMinute());
06701   string sStartSecond=Form("%d",startDatime.GetSecond());
06702   string sStartYear=Form("%d",startDatime.GetYear());
06703   string sStartMonth=Form("%d",startDatime.GetMonth());
06704   string sStartDay=Form("%d",startDatime.GetDay());
06705   if (startDatime.GetHour()<10) sStartHour="0"+sStartHour;
06706   if (startDatime.GetMinute()<10) sStartMinute="0"+sStartMinute;
06707   if (startDatime.GetSecond()<10) sStartSecond="0"+sStartSecond;
06708   if (startDatime.GetMonth()<10) sStartMonth="0"+sStartMonth;
06709   if (startDatime.GetDay()<10) sStartDay="0"+sStartDay;
06710 
06711   //play around with the formatting a little
06712   string sEndHour=Form("%d",endDatime.GetHour());
06713   string sEndMinute=Form("%d",endDatime.GetMinute());
06714   string sEndSecond=Form("%d",endDatime.GetSecond());
06715   string sEndYear=Form("%d",endDatime.GetYear());
06716   string sEndMonth=Form("%d",endDatime.GetMonth());
06717   string sEndDay=Form("%d",endDatime.GetDay());
06718   if (endDatime.GetHour()<10) sEndHour="0"+sEndHour;
06719   if (endDatime.GetMinute()<10) sEndMinute="0"+sEndMinute;
06720   if (endDatime.GetSecond()<10) sEndSecond="0"+sEndSecond;
06721   if (endDatime.GetMonth()<10) sEndMonth="0"+sEndMonth;
06722   if (endDatime.GetDay()<10) sEndDay="0"+sEndDay;
06723 
06724   static Bool_t firstTime=true;
06725   if (firstTime){
06726     MSG("LIAnalysis",Msg::kInfo) 
06727       <<"Setting graph axis info:"<<endl;
06728     MSG("LIAnalysis",Msg::kInfo) 
06729       <<"  Start time "<<sStartHour
06730       <<":"<<sStartMinute
06731       <<":"<<sStartSecond
06732       <<" on "<<startDatime.GetYear()
06733       <<"/"<<sStartMonth
06734       <<"/"<<sStartDay
06735       <<endl;
06736     
06737     MSG("LIAnalysis",Msg::kInfo) 
06738       <<"  End time "<<sEndHour
06739       <<":"<<sEndMinute
06740       <<":"<<sEndSecond
06741       <<" on "<<endDatime.GetYear()
06742       <<"/"<<sEndMonth
06743       <<"/"<<sEndDay
06744       <<endl;
06745   }
06746   firstTime=false;
06747 
06748   Int_t timeRange=endTimeSecs-startTimeSecs;
06749 
06750   //check graph pointer is not null
06751   if (g){
06752     if (sStartDay==sEndDay && timeRange<1*24*60*60){
06753       string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay+")";
06754       g->GetXaxis()->SetTitle(title.c_str());
06755       g->GetXaxis()->SetTimeFormat("%H:%M");
06756     }
06757     else if (timeRange>1*24*60*60 && timeRange<2*24*60*60){//1-2 days
06758       string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay
06759         +" - "+sEndYear+"/"+sEndMonth+"/"+sEndDay+")";
06760       g->GetXaxis()->SetTitle(title.c_str());
06761       g->GetXaxis()->SetTimeFormat("%H:%M");
06762     }
06763     else if (timeRange>2*24*60*60 && timeRange<5*24*60*60){//2-5 days
06764       string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay
06765         +" - "+sEndYear+"/"+sEndMonth+"/"+sEndDay+")";
06766       g->GetXaxis()->SetTitle(title.c_str());
06767       g->GetXaxis()->SetTimeFormat("%H:%M-%d/%m");
06768     }
06769     else{
06770       string title="Time ("+sStartYear+"/"+sStartMonth+"/"+sStartDay
06771         +" - "+sEndYear+"/"+sEndMonth+"/"+sEndDay+")";
06772       g->GetXaxis()->SetTitle(title.c_str());
06773       g->GetXaxis()->SetTimeFormat("%H:%M-%d/%m");
06774       //stop it cramming loads of days on the axis!
06775       g->GetXaxis()->SetNdivisions(506);
06776       //n = N1 + 100*N2 + 10000*N3
06777       //N1=number of primary divisions.
06778       //N2=number of secondary divisions.
06779       //N3=number of 3rd divisions.
06780     }
06781     
06782     //other x-axis defaults
06783     g->GetXaxis()->SetTimeDisplay(1);
06784     g->GetXaxis()->CenterTitle();
06785     
06786     //other defaults
06787     g->SetMarkerStyle(3);
06788     g->SetMarkerColor(2);
06789     g->SetMarkerSize(0.35);
06790     g->SetLineColor(46);
06791   }
06792   else{
06793     MSG("LIPlexMaps",Msg::kError)
06794       <<"Input graph pointer is null!"
06795       <<" Will do nothing."<<endl;
06796   }
06797 
06798   MSG("LIPlexMaps",Msg::kVerbose)
06799     <<endl<<" ** Finished the SetGraphAxisEtc method... **"<<endl;
06800 }
06801 
06802 //......................................................................
06803 
06804 void LIPlexMaps::ReadDbPulserRawGain() 
06805 {
06806   MSG("LIPlexMaps",Msg::kInfo)
06807     <<endl<<" ** Running the ReadDbPulserRawGain() method... ** "<<endl;
06808 
06809   //Thanks to Ryan for the DB code of this method  
06810   
06811   Int_t detectorType=4;
06812 
06813   Int_t* planeMax=new Int_t[NUMCRATES];
06814   Int_t* planeMin=new Int_t[NUMCRATES];
06815   fLookup.SetPbPlanes(planeMin,planeMax,detectorType);
06816 
06817   const Int_t firstStripBin=FIRSTSTRIP-8;//-8;
06818   const Int_t lastStripBin=LASTSTRIP+9;//200;
06819   const Int_t bins=lastStripBin-firstStripBin;
06820 
06821   string sConstantBit="";
06822 
06823   MSG("LIAnalysis",Msg::kInfo)
06824     <<"sConstantBit="<<sConstantBit<<endl;
06825 
06826   Int_t mycrates=5;
06827 
06828   TH2F **hStripVsPlaneGain=0;
06829   hStripVsPlaneGain= new TH2F*[mycrates];
06830   for (Int_t i=0;i<NUMCRATES;i++){
06831     string sPb=Form("%d",i);
06832     fS="Gain (Crate "+sPb+")";
06833     hStripVsPlaneGain[i]=new TH2F(fS.c_str(),fS.c_str(),
06834                                   planeMax[i]-planeMin[i],
06835                                   planeMin[i],planeMax[i],
06836                                   bins,firstStripBin,lastStripBin);
06837     hStripVsPlaneGain[i]->GetXaxis()->SetTitle("Plane");
06838     hStripVsPlaneGain[i]->GetXaxis()->CenterTitle();
06839     hStripVsPlaneGain[i]->GetYaxis()->SetTitle("Strip");
06840     hStripVsPlaneGain[i]->GetYaxis()->CenterTitle();
06841     hStripVsPlaneGain[i]->SetFillColor(0);
06842     //hStripVsPlaneGain[i]->SetBit(TH1::kCanRebin);
06843   }
06844 
06845   TH2F **hStripVsPlaneError=0;
06846   hStripVsPlaneError= new TH2F*[NUMCRATES];
06847   for (Int_t i=0;i<NUMCRATES;i++){
06848     string sPb=Form("%d",i);
06849     fS="Gain Error (Crate "+sPb+")";
06850     hStripVsPlaneError[i]=new TH2F(fS.c_str(),fS.c_str(),
06851                                      planeMax[i]-planeMin[i],
06852                                      planeMin[i],planeMax[i],
06853                                      bins,firstStripBin,lastStripBin);
06854     hStripVsPlaneError[i]->GetXaxis()->SetTitle("Plane");
06855     hStripVsPlaneError[i]->GetXaxis()->CenterTitle();
06856     hStripVsPlaneError[i]->GetYaxis()->SetTitle("Strip");
06857     hStripVsPlaneError[i]->GetYaxis()->CenterTitle();
06858     hStripVsPlaneError[i]->SetFillColor(0);
06859     //hStripVsPlaneError[i]->SetBit(TH1::kCanRebin);
06860   }
06861   
06862   TH2F **hStripVsPlaneNumEntries=0;
06863   hStripVsPlaneNumEntries= new TH2F*[NUMCRATES];
06864   for (Int_t i=0;i<NUMCRATES;i++){
06865     string sPb=Form("%d",i);
06866     fS="NumEntries_Crate"+sPb;
06867     hStripVsPlaneNumEntries[i]=new TH2F(fS.c_str(),fS.c_str(),
06868                                      planeMax[i]-planeMin[i],
06869                                      planeMin[i],planeMax[i],
06870                                      bins,firstStripBin,lastStripBin);
06871     hStripVsPlaneNumEntries[i]->GetXaxis()->SetTitle("Plane");
06872     hStripVsPlaneNumEntries[i]->GetXaxis()->CenterTitle();
06873     hStripVsPlaneNumEntries[i]->GetYaxis()->SetTitle("Strip");
06874     hStripVsPlaneNumEntries[i]->GetYaxis()->CenterTitle();
06875     hStripVsPlaneNumEntries[i]->SetFillColor(0);
06876     //hStripVsPlaneNumEntries[i]->SetBit(TH1::kCanRebin);
06877   }
06878 
06879   DetectorType::EDetectorType det=DetectorType::kCalDet;
06880 
06881   VldTimeStamp tsNow;
06882   VldContext vldNow(det,SimFlag::kData,tsNow);
06883 
06884   DbiResultPtr<PulserRawGain> dbiPulserRawGain;
06885 
06886   UInt_t numRows=dbiPulserRawGain.NewQuery(vldNow,0);
06887 
06888   MSG("LIPlexMaps",Msg::kInfo)
06889     <<"New DB query produced "<<numRows<<" rows"<<endl;
06890 
06892   //loop over the rows
06894   for(UInt_t i=0;i<numRows;i++) {
06895     const PulserRawGain* pulserRawGain=dbiPulserRawGain.GetRow(i);
06896 
06897     Float_t gain=*pulserRawGain->GetMean();
06898     Float_t error=*pulserRawGain->GetError();
06899     Float_t numEntries=*pulserRawGain->GetNumEntries();
06900 
06901     UInt_t seidkey=pulserRawGain->GetStripEnd();
06902     Int_t plane=-1;
06903     Int_t strip=-1;
06904     Int_t end=-1;
06905     fLookup.UnencodePlnStripEndKey(seidkey,det,plane,strip,end);
06906 
06907     hStripVsPlaneGain[end-1]->Fill(plane,strip,gain);
06908     hStripVsPlaneError[end-1]->Fill(plane,strip,error);
06909     hStripVsPlaneNumEntries[end-1]->Fill(plane,strip,numEntries);
06910 
06911     MSG("LIPlexMaps",Msg::kInfo)
06912       <<"("<<plane<<";"<<strip<<";"<<end<<")"
06913       <<" gain="<<gain<<", error="<<error<<", numEnt="<<numEntries
06914       <<", seidkey="<<seidkey<<endl;
06915   }
06917   //finished loop over the rows
06919 
06920   //set stats info off
06921   gStyle->SetOptStat(0);
06922 
06923   TCanvas *cStripVsPlaneGain=new TCanvas  
06924     ("cStripVsPlaneGain","StripVsPlane: Gain",0,0,1000,800);  
06925   cStripVsPlaneGain->SetFillColor(0);  
06926   cStripVsPlaneGain->Divide(1,2);  
06927   cStripVsPlaneGain->cd(1);  
06928   hStripVsPlaneGain[0]->Draw("colz");  
06929   cStripVsPlaneGain->cd(2);  
06930   hStripVsPlaneGain[1]->Draw("colz");  
06931 
06932   TCanvas *cStripVsPlaneError=new TCanvas  
06933     ("cStripVsPlaneError","StripVsPlane: Error",0,0,1000,800);  
06934   cStripVsPlaneError->SetFillColor(0);  
06935   cStripVsPlaneError->Divide(1,2);  
06936   cStripVsPlaneError->cd(1);  
06937   hStripVsPlaneError[0]->Draw("colz");  
06938   cStripVsPlaneError->cd(2);  
06939   hStripVsPlaneError[1]->Draw("colz");  
06940 
06941   TCanvas *cStripVsPlaneNumEntries=new TCanvas  
06942     ("cStripVsPlaneNumEntries","StripVsPlane: NumEntries",
06943      0,0,1000,800);  
06944   cStripVsPlaneNumEntries->SetFillColor(0);  
06945   cStripVsPlaneNumEntries->Divide(1,2);  
06946   cStripVsPlaneNumEntries->cd(1);  
06947   hStripVsPlaneNumEntries[0]->Draw("colz");  
06948   cStripVsPlaneNumEntries->cd(2);  
06949   hStripVsPlaneNumEntries[1]->Draw("colz");  
06950 
06951   MSG("LIPlexMaps",Msg::kInfo)
06952     <<endl<<" ** Finished the ReadDbPulserRawGain() method... **"<<endl;
06953 }
06954 
06955 //......................................................................
06956 
06957 void LIPlexMaps::RatioRawToRefDrift()
06958 {
06959   MSG("LIPlexMaps",Msg::kInfo)
06960     <<endl<<" ** Running the RatioRawToRefDrift() method... ** "<<endl; 
06961 
06962   //Thanks to Ryan for the DB code of this method  
06963   
06964   Int_t detectorType=4;
06965 
06966   Int_t* planeMax=new Int_t[NUMCRATES];
06967   Int_t* planeMin=new Int_t[NUMCRATES];
06968   fLookup.SetPbPlanes(planeMin,planeMax,detectorType);
06969 
06970   const Int_t firstStripBin=FIRSTSTRIP-8;//-8;
06971   const Int_t lastStripBin=LASTSTRIP+9;//200;
06972   const Int_t bins=lastStripBin-firstStripBin;
06973 
06974   string sConstantBit="";
06975 
06976   MSG("LIAnalysis",Msg::kInfo)
06977     <<"sConstantBit="<<sConstantBit<<endl;
06978 
06979   TH2F **hStripVsPlaneRawToRef=0;
06980   hStripVsPlaneRawToRef= new TH2F*[NUMCRATES];
06981   for (Int_t i=0;i<NUMCRATES;i++){
06982     string sPb=Form("%d",i);
06983     fS="RawToRef (Crate "+sPb+")";
06984     hStripVsPlaneRawToRef[i]=new TH2F(fS.c_str(),fS.c_str(),
06985                                   planeMax[i]-planeMin[i],
06986                                   planeMin[i],planeMax[i],
06987                                   bins,firstStripBin,lastStripBin);
06988     hStripVsPlaneRawToRef[i]->GetXaxis()->SetTitle("Plane");
06989     hStripVsPlaneRawToRef[i]->GetXaxis()->CenterTitle();
06990     hStripVsPlaneRawToRef[i]->GetYaxis()->SetTitle("Strip");
06991     hStripVsPlaneRawToRef[i]->GetYaxis()->CenterTitle();
06992     hStripVsPlaneRawToRef[i]->SetFillColor(0);
06993     //hStripVsPlaneRawToRef[i]->SetBit(TH1::kCanRebin);
06994   }
06995 
06996   DetectorType::EDetectorType det=DetectorType::kCalDet;
06997   VldTimeStamp tsNow;
06998   VldContext vldNow(det,SimFlag::kData,tsNow);
06999 
07000   DbiResultPtr<PulserRawDrift> dbiPulserRawDrift;
07001   DbiResultPtr<PulserRefDrift> dbiPulserRefDrift;
07002 
07003   UInt_t numRowsRaw=dbiPulserRawDrift.NewQuery(vldNow,0);
07004   UInt_t numRowsRef=dbiPulserRefDrift.NewQuery(vldNow,0);
07005 
07006   if (numRowsRef!=numRowsRaw) {
07007     MSG("LIPlexMaps",Msg::kError)
07008       <<"Raw and Ref PulserDrift tables are different sizes"<<endl;
07009       //<<"Program will exit here..."<<endl;
07010     //exit(0);
07011   }
07012 
07013   UInt_t numRows=numRowsRaw;
07014   if (numRowsRaw>numRowsRef) numRows=numRowsRef;
07015 
07016   MSG("LIPlexMaps",Msg::kInfo)
07017     <<"Using "<<numRows<<" rows"<<endl;
07018 
07019   map<Int_t,PulserRawDrift> rawDrift;
07020   map<Int_t,PulserRefDrift> refDrift;
07021 
07023   //loop over the rows
07025   for(UInt_t i=0;i<numRows;i++) {
07026     const PulserRawDrift* pulserRawDrift=dbiPulserRawDrift.GetRow(i);
07027     const PulserRefDrift* pulserRefDrift=dbiPulserRefDrift.GetRow(i);
07028 
07029     //insert into map
07030     rawDrift[pulserRawDrift->GetStripEnd()]=*pulserRawDrift;
07031     refDrift[pulserRefDrift->GetStripEnd()]=*pulserRefDrift;
07032   }
07034   //finished loop over the rows
07036 
07037   MSG("LIPlexMaps",Msg::kInfo)
07038     <<"Finished loop"<<endl;
07039 
07040   map<Int_t,PulserRawDrift>::iterator raw=rawDrift.begin();
07041   map<Int_t,PulserRefDrift>::iterator ref=refDrift.begin();
07042 
07043   //now loop over map
07044   while(raw!=rawDrift.end()){
07045 
07046     Float_t meanRaw=raw->second.GetMean();
07047     Float_t errorRaw=raw->second.GetError();
07048     Float_t numEntriesRaw=raw->second.GetNumEntries();
07049     UInt_t seidkeyRaw=raw->first;
07050     Int_t planeRaw=-1;
07051     Int_t stripRaw=-1;
07052     Int_t endRaw=-1;
07053     fLookup.UnencodePlnStripEndKey(seidkeyRaw,det,planeRaw,stripRaw,
07054                                    endRaw);
07055 
07056     Float_t meanRef=ref->second.GetMean();
07057     Float_t errorRef=ref->second.GetError();
07058     Float_t numEntriesRef=ref->second.GetNumEntries();
07059     UInt_t seidkeyRef=ref->first;
07060     Int_t planeRef=-1;
07061     Int_t stripRef=-1;
07062     Int_t endRef=-1;
07063     fLookup.UnencodePlnStripEndKey(seidkeyRef,det,planeRef,stripRef,
07064                                    endRef);
07065     
07066     //check sanity of procedure
07067     if (seidkeyRef!=seidkeyRaw){
07068       MSG("LIPlexMaps",Msg::kError)
07069         <<"Raw and Ref seidkeys are different"<<endl;
07070         //<<"Program will exit here..."<<endl;
07071       //exit(0);
07072       raw++;
07073       ref++;    
07074       continue;
07075     }
07076 
07077     //protect against fpe
07078     if (meanRef>0){
07079       hStripVsPlaneRawToRef[endRef-1]->Fill(planeRef,stripRef,
07080                                             meanRaw/meanRef);
07081     }
07082 
07083     //get lots of strings
07084     string sMeanRaw=Form("%.1f",meanRaw);
07085     string sErrorRaw=Form("%.2f",errorRaw);
07086     string sNumEntriesRaw=Form("%.0f",numEntriesRaw);
07087     string sSeIdRaw=Form("%.1f",seidkeyRaw);
07088 
07089     string sMeanRef=Form("%.1f",meanRef);
07090     string sErrorRef=Form("%.2f",errorRef);
07091     string sNumEntriesRef=Form("%.0f",numEntriesRef);
07092     string sSeIdRef=Form("%.1f",seidkeyRef);
07093 
07094     string sMeanDif=Form("%.1f",meanRef-meanRaw);
07095     string sErrorDif=Form("%.2f",errorRef-errorRaw);
07096     string sNumEntriesDif=Form("%.0f",numEntriesRef-numEntriesRaw);
07097     string sSeIdDiff=Form("%.1f",seidkeyRef-seidkeyRaw);
07098 
07099     MSG("LIPlexMaps",Msg::kInfo)
07100       <<endl
07101       <<"Ref (m,er,num,seid)=("<<sMeanRef<<";"<<sErrorRef
07102       <<";"<<sNumEntriesRef<<";"<<sSeIdRef<<")"
07103       <<endl
07104       <<"Raw (m,er,num,seid)=("<<sMeanRaw<<";"<<sErrorRaw
07105       <<";"<<sNumEntriesRaw<<";"<<sSeIdRaw<<")"
07106       <<endl
07107       <<"Diff (m,er,num,seid)=("<<sMeanDif<<";"<<sErrorDif
07108       <<";"<<sNumEntriesDif<<";"<<sSeIdDiff<<")"
07109       <<endl;
07110 
07111     raw++;
07112     ref++;    
07113   }
07114 
07115   //set stats info off
07116   gStyle->SetOptStat(0);
07117 
07118   TCanvas *cStripVsPlaneRawToRef=new TCanvas  
07119     ("cStripVsPlaneRawToRef","StripVsPlane: RawToRef",0,0,1000,800);  
07120   cStripVsPlaneRawToRef->SetFillColor(0);  
07121   cStripVsPlaneRawToRef->Divide(1,2);  
07122   cStripVsPlaneRawToRef->cd(1);  
07123   hStripVsPlaneRawToRef[0]->Draw("colz");  
07124   cStripVsPlaneRawToRef->cd(2);  
07125   hStripVsPlaneRawToRef[1]->Draw("colz");  
07126 
07127   MSG("LIPlexMaps",Msg::kInfo)
07128     <<endl<<" ** Finished the RatioRawToRefDrift() method... ** "
07129     <<endl; 
07130 }
07131 
07132 
07133 //......................................................................
07134 
07135 map<Int_t,Float_t> LIPlexMaps::GetRawPinMap(VldContext vldCtx) 
07136 {
07137   MSG("LIPlexMaps",Msg::kDebug)
07138     <<endl<<" ** Running the GetRawPinMap method... **"<<endl;
07139 
07140   DetectorType::EDetectorType det=DetectorType::kCalDet;
07141   StripEnd::EStripEnd stripEndType;
07142 
07143   PlexHandle *plexHandle=new PlexHandle(vldCtx);   
07144 
07145   DbiResultPtr<PulserRawDriftPin> driftRawPin;
07146   UInt_t numRowsPin=driftRawPin.NewQuery(vldCtx,0);
07147 
07148   if (numRowsPin!=static_cast<UInt_t>(NUMLEDS*NUMPULSERBOXES*2)){
07149     MSG("LIPlexMaps",Msg::kWarning)
07150       <<"PulserRawDriftPin only contains "<<numRowsPin<<" rows"<<endl;
07151   }
07152   map<Int_t,Float_t> pinAdc;
07153 
07154   Int_t mapEntCounter=0;
07155 
07157   //loop over the pin rows
07159   for(UInt_t i=0;i<numRowsPin;i++) {
07160 
07161     //get the raw pin
07162     const PulserRawDriftPin* rawPin=driftRawPin.GetRow(i);
07163       
07164     PlexLedId ledId=plexHandle->GetLedId(rawPin->GetPinDiodeId());
07165 
07166     pair<PlexPinDiodeId,PlexPinDiodeId> plexPins=plexHandle->
07167       GetPinDiodeIds(ledId); // hi, low
07168 
07169     //ignore the low gain for now
07170     if (rawPin->GetPinDiodeId()==plexPins.second) continue;
07171 
07172     MSG("LIPlexMaps",Msg::kDebug)
07173       <<"Got high gain pin:"<<endl;
07174     if (MsgService::Instance()->IsActive("LIPlexMaps",Msg::kDebug)){
07175       rawPin->GetPinDiodeId().Print();
07176     }
07177 
07178     for(Int_t pl=FIRSTPLANE;pl<=LASTPLANE;pl++){
07179       for(Int_t st=FIRSTSTRIP;st<=LASTSTRIP;st++){
07180         for(Int_t end=FIRSTEND;end<=SECONDEND;end++){
07181           
07182           if (end==StripEnd::kEast) stripEndType=StripEnd::kEast;
07183           else if (end==StripEnd::kWest) stripEndType=StripEnd::kWest;
07184           
07185           PlexStripEndId stripEndId(det,pl,st,stripEndType);
07186           
07187           PlexLedId currentSELedId=plexHandle->GetLedId(stripEndId);
07188 
07189           if (currentSELedId==ledId){
07190             pinAdc[stripEndId.BuildPlnStripEndKey()]=rawPin->GetMean();
07191             
07192             MSG("LIPlexMaps",Msg::kVerbose)
07193               <<"Filling map, mean="<<rawPin->GetMean()<<endl;
07194             mapEntCounter++;
07195           }
07196         }
07197       }
07198     }
07199   }
07200 
07201   if (mapEntCounter!=NUMPLANES*NUMSTRIPS*NUMENDS){
07202     MSG("LIPlexMaps",Msg::kWarning)
07203       <<"Only "<<mapEntCounter<<" entries added to pin map"<<endl;
07204   }
07205 
07206   MSG("LIPlexMaps",Msg::kDebug)
07207     <<endl<<" ** Finished the GetRawPinMap method... ** "<<endl; 
07208   return pinAdc;
07209 }
07210 
07211 //......................................................................
07212 /*
07213 map<Int_t,LIPulserPin> LIPlexMaps::GetPulserRawDrift
07214 (DbiResultPtr<PulserRawDrift> dbiPulserRawDrift,VldContext vldCtx) 
07215 {
07216   MSG("LIPlexMaps",Msg::kDebug)
07217     <<endl<<" ** Running the GetPulserRawDrift method... **"<<endl;
07218 
07219   UInt_t numRowsDrift=dbiPulserRawDrift.NewQuery(vldCtx,0);
07220 
07221   //DbiResultPtr<PulserRawDriftF> dbiPulserRawDriftF;
07222   //UInt_t numRowsDriftF=dbiPulserRawDriftF.NewQuery(vldCtx,0);
07223 
07224   MSG("LIPlexMaps",Msg::kInfo)
07225     <<"PulserRawDrift contains "<<numRowsDrift<<" rows"<<endl;
07226     //<<", PulserRawDriftF contains "<<numRowsDriftF<<" rows"<<endl;
07227   
07228   map<Int_t,LIPulserPin> rawDrift;
07229   //map<Int_t,LIPulserPin> rawDriftF;
07230 
07232   //loop over the pulser drift rows
07234   for(UInt_t i=0;i<numRowsDrift;i++) {
07235     //get the raw drift 
07236     const PulserRawDrift* pulserRawDrift=dbiPulserRawDrift.GetRow(i);
07237 
07238     UInt_t seidkey=pulserRawDrift->GetStripEnd();
07239 
07240     //fill the map
07241     rawDrift[seidkey].mean=pulserRawDrift->GetMean();
07242     rawDrift[seidkey].error=pulserRawDrift->GetError();
07243     rawDrift[seidkey].numEnt=pulserRawDrift->GetNumEntries();
07244 
07245     MSG("LIPlexMaps",Msg::kInfo)
07246       <<"Filling raw drift map="<<rawDrift[seidkey].mean
07247       <<" (+/- "<<rawDrift[seidkey].error*100<<"%)"<<endl;
07248   }
07250   //finished loop over the rows
07252 
07253   MSG("LIPlexMaps",Msg::kDebug)
07254     <<endl<<" ** Finished the GetPulserRawDrift method... ** "<<endl; 
07255   return rawDrift;
07256 }
07257 */
07258 //......................................................................
07259 
07260 map<PlexLedId,LIPulserPin> LIPlexMaps::GetRawPinLedMap
07261 (VldContext vldCtx)
07262 {
07263   MSG("LIPlexMaps",Msg::kDebug)
07264     <<endl<<" ** Running the GetRawPinLedMap method... **"<<endl;
07265 
07266   PlexHandle *plexHandle=new PlexHandle(vldCtx);   
07267 
07268   DbiResultPtr<PulserRawDriftPin> driftRawPin;
07269   UInt_t numRowsPin=driftRawPin.NewQuery(vldCtx,0);
07270 
07271   if (static_cast<Int_t>(numRowsPin)!=NUMLEDS*NUMPULSERBOXES*2){
07272     MSG("LIPlexMaps",Msg::kWarning)
07273       <<"PulserRawDriftPin only contains "<<numRowsPin<<" rows"
07274       <<", expected "<<NUMLEDS*NUMPULSERBOXES*2<<endl;
07275   }
07276 
07277   map<PlexLedId,Float_t> pinAdc;
07278   map<PlexLedId,LIPulserPin> pinAdcOb;
07279 
07280   Int_t mapEntCounter=0;
07281 
07283   //loop over the pin rows
07285   for(UInt_t i=0;i<numRowsPin;i++) {
07286 
07287     //get the raw pin
07288     const PulserRawDriftPin* rawPin=driftRawPin.GetRow(i);
07289       
07290     PlexLedId ledId=plexHandle->GetLedId(rawPin->GetPinDiodeId());
07291 
07292     pair<PlexPinDiodeId,PlexPinDiodeId> plexPins=plexHandle->
07293       GetPinDiodeIds(ledId); // hi, low
07294 
07295     //ignore the low gain for now
07296     //if (rawPin->GetPinDiodeId()==plexPins.second) continue;
07297 
07298     //ignore the high gain for now
07299     if (rawPin->GetPinDiodeId()==plexPins.first) continue;
07300 
07301     MSG("LIPlexMaps",Msg::kDebug)
07302       <<"Got high gain pin:"<<endl;
07303     if (MsgService::Instance()->IsActive("LIPlexMaps",Msg::kDebug)){
07304       rawPin->GetPinDiodeId().Print();
07305     }
07306 
07307     //add the pin to the map
07308     pinAdc[ledId]=rawPin->GetMean();
07309 
07310     MSG("LIPlexMaps",Msg::kDebug)
07311       <<"Added pin mean="<<rawPin->GetMean()<<endl;
07312 
07313     pinAdcOb[ledId].mean=rawPin->GetMean();
07314     pinAdcOb[ledId].error=rawPin->GetError();
07315     pinAdcOb[ledId].numEnt=rawPin->GetNumEntries();
07316 
07317     if (rawPin->GetMean()<=0){
07318       MSG("LIPlexMaps",Msg::kInfo)
07319         <<"Warning bad pin="<<rawPin->GetMean()<<" (PB:LED)=("
07320         <<ledId.GetPulserBox()<<":"<<ledId.GetLedInBox()<<")"<<endl;
07321     }
07322 
07323     //count the number of entries
07324     mapEntCounter++;
07325   }
07326 
07327   //check the number of leds
07328   if (mapEntCounter!=NUMLEDS){
07329     MSG("LIPlexMaps",Msg::kWarning)
07330       <<"Only "<<mapEntCounter<<" entries added to pin map"<<endl;
07331   }
07332 
07333   MSG("LIPlexMaps",Msg::kDebug)
07334     <<endl<<" ** Finished the GetRawPinLedMap method... ** "<<endl; 
07335   return pinAdcOb;
07336 }
07337 
07338 //......................................................................
07339 
07340 map<Int_t,LIPulserPin> LIPlexMaps::GetRefAdcPinRatio(VldContext vldCtx) 
07341 {
07342   MSG("LIPlexMaps",Msg::kDebug)
07343     <<endl<<" ** Running the GetRefAdcPinRatio method... **"<<endl;
07344 
07345   map<Int_t,LIPulserPin> pinAdc;
07346 
07347   DetectorType::EDetectorType det=vldCtx.GetDetector();
07348   StripEnd::EStripEnd stripEndType;
07349 
07350   PlexHandle *plexHandle=new PlexHandle(vldCtx);   
07351 
07352   DbiResultPtr<PulserRefDriftPin> driftRefPin;
07353   UInt_t numRowsPin=driftRefPin.NewQuery(vldCtx,0);
07354 
07355   DbiResultPtr<PulserRefDrift> dbiPulserRefDrift;
07356   UInt_t numRowsDrift=dbiPulserRefDrift.NewQuery(vldCtx,0);
07357 
07358   static string sVldRange=dbiPulserRefDrift.GetValidityRec()->
07359     GetVldRange().AsString();
07360   static Bool_t firstTime=true;
07361 
07362   if (sVldRange==dbiPulserRefDrift.GetValidityRec()->
07363       GetVldRange().AsString() && !firstTime){
07364     return pinAdc;
07365   }
07366 
07367   MSG("LIPlexMaps",Msg::kInfo)
07368     <<endl<<"Running the GetRefAdcPinRatio method..."<<endl;
07369 
07370   //set up control variables for next time
07371   firstTime=false;
07372   sVldRange=dbiPulserRefDrift.GetValidityRec()->
07373     GetVldRange().AsString();
07374 
07375   MSG("LIPlexMaps",Msg::kInfo)
07376     <<"PulserRefDrift contains "<<numRowsDrift<<" rows"<<endl
07377     <<"PulserRefDriftPin contains "<<numRowsPin<<" rows"<<endl;
07378 
07379   Int_t mapEntCounter=0;
07380 
07382   //loop over the pin rows
07384   for(UInt_t i=0;i<numRowsPin;i++) {
07385 
07386     //get the ref pin
07387     const PulserRefDriftPin* refPin=driftRefPin.GetRow(i);
07388       
07389     PlexLedId ledId=plexHandle->GetLedId(refPin->GetPinDiodeId());
07390 
07391     pair<PlexPinDiodeId,PlexPinDiodeId> plexPins=plexHandle->
07392       GetPinDiodeIds(ledId); // hi, low
07393 
07394     //ignore the low gain for now
07395     if (refPin->GetPinDiodeId()==plexPins.second) continue;
07396 
07397     MSG("LIPlexMaps",Msg::kDebug)
07398       <<"Got high gain pin:"<<endl;
07399     if (MsgService::Instance()->IsActive("LIPlexMaps",Msg::kDebug)){
07400       refPin->GetPinDiodeId().Print();
07401     }
07402 
07403     for(Int_t pl=FIRSTPLANE;pl<=LASTPLANE;pl++){
07404       for(Int_t st=FIRSTSTRIP;st<=LASTSTRIP;st++){
07405         for(Int_t end=FIRSTEND;end<=SECONDEND;end++){
07406           
07407           if (end==StripEnd::kEast) stripEndType=StripEnd::kEast;
07408           else if (end==StripEnd::kWest) stripEndType=StripEnd::kWest;
07409           
07410           PlexStripEndId stripEndId(det,pl,st,stripEndType);
07411           
07412           if (!this->IsScintStrip(stripEndId,plexHandle)) continue;
07413 
07414           PlexLedId currentSELedId=plexHandle->GetLedId(stripEndId);
07415 
07416           if (currentSELedId==ledId){
07417             pinAdc[stripEndId.BuildPlnStripEndKey()].mean=refPin->
07418               GetMean();
07419             pinAdc[stripEndId.BuildPlnStripEndKey()].error=refPin->
07420               GetError();
07421             pinAdc[stripEndId.