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

LILookup.cxx

Go to the documentation of this file.
00001 
00002 
00003 // Program name: LILookup.cxx
00004 //                                                                     
00005 // Package: LISummary  
00006 //                                                                    
00007 // Coded by Jeff Hartnell Nov/2002-Jan/2004                             
00008 //                                                                    
00009 // Purpose: Provides LI constants and lookup funtions 
00010 //                                                                    
00011 // Contact: jeffrey.hartnell@physics.ox.ac.uk                         
00013 
00014 #include "Conventions/StripEnd.h"
00015 #include "MessageService/MsgService.h"
00016 
00017 #include "LISummary/LILookup.h"
00018 
00019 #include <cmath>
00020 
00021 //make default values those of FD
00022 Int_t LILookup::FIRSTSTRIP=0;
00023 Int_t LILookup::LASTSTRIP=191;
00024 Int_t LILookup::NUMSTRIPS=192;
00025 
00026 Int_t LILookup::NUMCHADD=8000;
00027 
00028 Int_t LILookup::FIRSTLED=1;
00029 Int_t LILookup::LASTLED=20;
00030 Int_t LILookup::NUMLEDS=20;
00031 
00032 Int_t LILookup::FIRSTASHTRAY=1;
00033 Int_t LILookup::LASTASHTRAY=20;
00034 Int_t LILookup::NUMASHTRAYS=20;
00035 
00036 Int_t LILookup::FIRSTPULSERBOX=0;
00037 Int_t LILookup::LASTPULSERBOX=15;
00038 Int_t LILookup::NUMPULSERBOXES=16;
00039 Int_t LILookup::NUMPULSERBOXESCURRENT=14;
00040 
00041 Int_t LILookup::NUMCHANNELS=8000;
00042 
00043 Int_t LILookup::FIRSTCRATE=0;
00044 Int_t LILookup::LASTCRATE=15;
00045 Int_t LILookup::NUMCRATES=16;
00046 
00047 Int_t LILookup::FIRSTVARC=0;
00048 Int_t LILookup::LASTVARC=3; 
00049 Int_t LILookup::NUMVARCS=4;
00050 
00051 Int_t LILookup::FIRSTVMM=0;
00052 Int_t LILookup::LASTVMM=5;
00053 Int_t LILookup::NUMVMMS=6;
00054 
00055 Int_t LILookup::FIRSTVFB=0;
00056 Int_t LILookup::LASTVFB=1;
00057 Int_t LILookup::NUMVFBS=2;
00058 
00059 Int_t LILookup::FIRSTCHIP=0;
00060 Int_t LILookup::LASTCHIP=2;
00061 Int_t LILookup::NUMCHIPS=3;
00062 
00063 Int_t LILookup::FIRSTPMT=0;
00064 Int_t LILookup::LASTPMT=2;
00065 Int_t LILookup::NUMPMTS=3;
00066 
00067 Int_t LILookup::FIRSTPIXEL=0;
00068 Int_t LILookup::LASTPIXEL=15;
00069 Int_t LILookup::NUMPIXELS=16;
00070 
00071 Int_t LILookup::FIRSTPIXELSPOT=0;
00072 Int_t LILookup::LASTPIXELSPOT=7;
00073 Int_t LILookup::NUMPIXELSPOTS=8;
00074 
00075 Int_t LILookup::FIRSTVACHANNEL=0;
00076 Int_t LILookup::LASTVACHANNEL=21;
00077 Int_t LILookup::NUMVACHANNELS=22;
00078 
00079 Int_t LILookup::NUMSIDES=2;
00080 Int_t LILookup::FIRSTSIDE=1;
00081 Int_t LILookup::LASTSIDE=2;
00082 
00083 Int_t LILookup::FIRSTEND=1;
00084 Int_t LILookup::LASTEND=2;
00085 Int_t LILookup::SECONDEND=2;
00086 Int_t LILookup::NUMENDS=2;
00087 
00088 Int_t LILookup::NUMRACKLEVELS=2;
00089 Int_t LILookup::NUMLEVELS=3;
00090     
00091 Int_t LILookup::FIRSTRACK=1;
00092 Int_t LILookup::LASTRACK=16;
00093 Int_t LILookup::NUMRACKS=16;
00094 
00095 Int_t LILookup::FIRSTMUX=0;
00096 Int_t LILookup::LASTMUX=7;
00097 Int_t LILookup::NUMMUX=8;
00098 
00099 Int_t LILookup::NUMPINGAINS=2;
00100 
00101 Int_t LILookup::PB0STARTPLANE=0;   //  0- 64 inclusive
00102 Int_t LILookup::PB2STARTPLANE=65;  // 65-128
00103 Int_t LILookup::PB4STARTPLANE=129; //129-192
00104 Int_t LILookup::PB6STARTPLANE=193; //193-248
00105 Int_t LILookup::PB8STARTPLANE=249; //249-313
00106 Int_t LILookup::PB10STARTPLANE=314;//314-377
00107 Int_t LILookup::PB12STARTPLANE=378;//378-441
00108 Int_t LILookup::PB14STARTPLANE=442;//442-485
00109 
00110 Int_t LILookup::FIRSTPLANE=0;
00111 Int_t LILookup::FIRSTSCINTPLANE=1;
00112 Int_t LILookup::LASTSM1SCINTPLANE=248;
00113 
00114 Int_t LILookup::FIRSTSM2PLANE=249;
00115 Int_t LILookup::FIRSTSM2SCINTPLANE=250;
00116 Int_t LILookup::LASTSCINTPLANE=485;
00117 Int_t LILookup::LASTPLANE=485;
00118 Int_t LILookup::NUMPLANES=486;
00119 
00120 Int_t LILookup::NUMBOOKENDS=2;
00121 Int_t LILookup::SM1BOOKEND=0;//steel only plane
00122 Int_t LILookup::SM2BOOKEND=249;//steel only plane
00123 
00124 Int_t LILookup::FIRSTSPECTROMETERPLANE=10000;//nonsense for FD
00125 
00126 CVSID("$Id: LILookup.cxx,v 1.39 2007/11/11 08:00:53 rhatcher Exp $");
00127 
00128 ClassImp(LILookup)
00129 
00130 //......................................................................
00131 
00132 LILookup::LILookup()
00133 {
00134   MSG("LILookup", Msg::kDebug) 
00135     <<"Running LILookup constructor..."<<endl;
00136 
00137   MSG("LILookup", Msg::kDebug) 
00138     <<"Finished LILookup constructor"<<endl;
00139 }
00140 
00141 //......................................................................
00142 
00143 LILookup::~LILookup()
00144 {
00145   MSG("LILookup", Msg::kDebug) 
00146     <<"Running LILookup destructor..."<<endl;
00147 
00148 
00149   MSG("LILookup", Msg::kDebug) 
00150     <<"Finished LILookup destructor"<<endl;
00151 }
00152 
00153 //......................................................................
00154 
00155 void LILookup::SetDetector(Int_t det)
00156 {
00157 
00158   MSG("LILookup", Msg::kInfo)
00159     <<"Setting Detector specific variables using detector type: "
00160     <<Detector::AsString(static_cast<Detector::
00161                              Detector_t>(det))<<endl; 
00162 
00163   if (det==Detector::kCalDet){
00167     FIRSTSTRIP=0;
00168     LASTSTRIP=23;
00169     NUMSTRIPS=24;
00170     
00171     FIRSTLED=1;
00172     LASTLED=6;
00173     NUMLEDS=6;
00174 
00175     FIRSTASHTRAY=1;
00176     LASTASHTRAY=3;
00177     NUMASHTRAYS=3;
00178 
00179     FIRSTPULSERBOX=0;
00180     LASTPULSERBOX=0;
00181     NUMPULSERBOXES=1;
00182     NUMPULSERBOXESCURRENT=1;
00183 
00184     FIRSTPMT=0;
00185     LASTPMT=2;
00186     NUMPMTS=3;
00187 
00188     FIRSTPIXEL=0;
00189     LASTPIXEL=15;
00190     NUMPIXELS=16;
00191 
00192     FIRSTPIXELSPOT=0;
00193     LASTPIXELSPOT=7;
00194     NUMPIXELSPOTS=8;
00195 
00196     NUMCHADD=8000;
00197     NUMCHANNELS=8000;
00198 
00199     FIRSTCRATE=0;
00200     LASTCRATE=2;
00201     NUMCRATES=3;
00202 
00203     FIRSTVARC=0;
00204     LASTVARC=3; 
00205     NUMVARCS=4;
00206 
00207     FIRSTVMM=0;
00208     LASTVMM=5;
00209     NUMVMMS=6;
00210 
00211     FIRSTVFB=0;
00212     LASTVFB=1;
00213     NUMVFBS=2;
00214 
00215     FIRSTCHIP=0;
00216     LASTCHIP=2;
00217     NUMCHIPS=3;
00218 
00219     FIRSTVACHANNEL=0;
00220     LASTVACHANNEL=21;
00221     NUMVACHANNELS=22;
00222 
00223     FIRSTSIDE=1;
00224     LASTSIDE=2;
00225     NUMSIDES=2;
00226 
00227     FIRSTEND=1;
00228     LASTEND=2;
00229     SECONDEND=2;
00230     NUMENDS=2;
00231 
00232     NUMRACKLEVELS=2;
00233     NUMLEVELS=3;
00234 
00235     FIRSTRACK=1;
00236     LASTRACK=16;
00237     NUMRACKS=16;
00238 
00239     FIRSTMUX=0;
00240     LASTMUX=7;
00241     NUMMUX=8;
00242 
00243     NUMPINGAINS=2;
00244 
00245     PB0STARTPLANE=0;  //  0- 59 inclusive
00246 
00247     //<Rubbish for CalDet but keep>
00248     PB2STARTPLANE=0; 
00249     PB4STARTPLANE=0; 
00250     PB6STARTPLANE=0; 
00251     PB8STARTPLANE=0; 
00252     PB10STARTPLANE=0;
00253     PB12STARTPLANE=0;
00254     PB14STARTPLANE=0;
00255     //</Rubbish for CalDet but keep>
00256 
00257     FIRSTPLANE=0;
00258     FIRSTSCINTPLANE=0;
00259     LASTSM1SCINTPLANE=59;
00260 
00261     FIRSTSM2PLANE=0;
00262 
00263     //<Rubbish for CalDet but keep>
00264     FIRSTSM2SCINTPLANE=0;
00265     //</Rubbish for CalDet but keep>
00266 
00267     LASTSCINTPLANE=59;
00268     LASTPLANE=59;
00269     NUMPLANES=60;
00270     //the total number of instrumented planes will be 60 since
00271     //there are no bookends at CalDet
00272 
00273     NUMBOOKENDS=0;
00274     SM1BOOKEND=-1;//steel only plane
00275     SM2BOOKEND=-1;//steel only plane
00276 
00277     FIRSTSPECTROMETERPLANE=10000;//nonsense for FD and CD
00278   }
00279   else if (det==Detector::kFar){
00283     FIRSTSTRIP=0;
00284     LASTSTRIP=191;
00285     NUMSTRIPS=192;
00286 
00287     FIRSTLED=1;
00288     LASTLED=20;
00289     NUMLEDS=20;
00290 
00291     FIRSTASHTRAY=1;
00292     LASTASHTRAY=20;
00293     NUMASHTRAYS=20;
00294 
00295     FIRSTPULSERBOX=0;
00296     LASTPULSERBOX=15;
00297     NUMPULSERBOXES=16;
00298     NUMPULSERBOXESCURRENT=14;
00299 
00300     FIRSTPMT=0;
00301     LASTPMT=2;
00302     NUMPMTS=3;
00303 
00304     FIRSTPIXEL=0;
00305     LASTPIXEL=15;
00306     NUMPIXELS=16;
00307 
00308     FIRSTPIXELSPOT=0;
00309     LASTPIXELSPOT=7;
00310     NUMPIXELSPOTS=8;
00311 
00312     NUMCHADD=8000;
00313     NUMCHANNELS=8000;
00314 
00315     FIRSTCRATE=0;
00316     LASTCRATE=15;
00317     NUMCRATES=16;
00318 
00319     FIRSTVARC=0;
00320     LASTVARC=3; 
00321     NUMVARCS=4;
00322 
00323     FIRSTVMM=0;
00324     LASTVMM=5;
00325     NUMVMMS=6;
00326 
00327     FIRSTVFB=0;
00328     LASTVFB=1;
00329     NUMVFBS=2;
00330 
00331     FIRSTCHIP=0;
00332     LASTCHIP=2;
00333     NUMCHIPS=3;
00334 
00335     FIRSTVACHANNEL=0;
00336     LASTVACHANNEL=21;
00337     NUMVACHANNELS=22;
00338 
00339     NUMSIDES=2;
00340     FIRSTSIDE=1;
00341     LASTSIDE=2;
00342 
00343     FIRSTEND=1;
00344     LASTEND=2;
00345     SECONDEND=2;
00346     NUMENDS=2;
00347 
00348     NUMRACKLEVELS=2;
00349     NUMLEVELS=3;
00350     
00351     FIRSTRACK=1;
00352     LASTRACK=16;
00353     NUMRACKS=16;
00354 
00355     FIRSTMUX=0;
00356     LASTMUX=7;
00357     NUMMUX=8;
00358 
00359     NUMPINGAINS=2;
00360 
00361     PB0STARTPLANE=0;  //  0- 64 inclusive
00362     PB2STARTPLANE=65;  // 65-128
00363     PB4STARTPLANE=129; //129-192
00364     PB6STARTPLANE=193; //193-248
00365     PB8STARTPLANE=249; //249-313
00366     PB10STARTPLANE=314;//314-377
00367     PB12STARTPLANE=378;//378-441
00368     PB14STARTPLANE=442;//442-485
00369 
00370     FIRSTPLANE=0;
00371     FIRSTSCINTPLANE=1;
00372     LASTSM1SCINTPLANE=248;
00373 
00374     FIRSTSM2PLANE=249;
00375     FIRSTSM2SCINTPLANE=250;
00376     LASTSCINTPLANE=485;
00377     LASTPLANE=485;
00378     NUMPLANES=486;
00379 
00380     NUMBOOKENDS=2;
00381     SM1BOOKEND=0;//steel only plane
00382     SM2BOOKEND=249;//steel only plane
00383 
00384     FIRSTSPECTROMETERPLANE=10000;//nonsense for FD and CD
00385 
00386     //the total number of instrumented planes will be 484 since
00387     //0 and 249 are bookends
00388   }
00389   else if (det==Detector::kNear){
00393     FIRSTSTRIP=0;
00394     LASTSTRIP=95;
00395     NUMSTRIPS=96;
00396 
00397     FIRSTLED=1;
00398     LASTLED=40;
00399     NUMLEDS=40;
00400 
00401     FIRSTASHTRAY=1;//?
00402     LASTASHTRAY=20;
00403     NUMASHTRAYS=20;
00404 
00405     FIRSTPULSERBOX=0;
00406     LASTPULSERBOX=2;
00407     NUMPULSERBOXES=3;
00408     NUMPULSERBOXESCURRENT=3;
00409 
00410     FIRSTPMT=0;//?
00411     LASTPMT=0;
00412     NUMPMTS=0;
00413 
00414     FIRSTPIXEL=0;
00415     LASTPIXEL=63;
00416     NUMPIXELS=64;
00417 
00418     FIRSTPIXELSPOT=0;
00419     LASTPIXELSPOT=0;
00420     NUMPIXELSPOTS=1;
00421 
00422     NUMCHADD=50000;//?
00423     NUMCHANNELS=50000;
00424 
00425     FIRSTCRATE=0;//?
00426     LASTCRATE=7;
00427     NUMCRATES=8;
00428 
00429     //<Rubbish for NearDet but keep>
00430     FIRSTVARC=0;
00431     LASTVARC=0; 
00432     NUMVARCS=0;
00433 
00434     FIRSTVMM=0;
00435     LASTVMM=0;
00436     NUMVMMS=0;
00437 
00438     FIRSTVFB=0;
00439     LASTVFB=0;
00440     NUMVFBS=0;
00441 
00442     FIRSTCHIP=0;
00443     LASTCHIP=0;
00444     NUMCHIPS=0;
00445 
00446     FIRSTVACHANNEL=0;
00447     LASTVACHANNEL=0;
00448     NUMVACHANNELS=0;
00449     //</Rubbish for NearDet but keep>
00450 
00451     NUMSIDES=1;
00452     FIRSTSIDE=1;//?
00453     LASTSIDE=1;//?
00454 
00455     FIRSTEND=2;//?
00456     LASTEND=2;
00457     SECONDEND=2;
00458     NUMENDS=1;
00459 
00460     NUMRACKLEVELS=2;
00461     NUMLEVELS=2;
00462     
00463     FIRSTRACK=1;//?
00464     LASTRACK=16;
00465     NUMRACKS=16;
00466 
00467     //<Rubbish for NearDet but keep>
00468     FIRSTMUX=0;
00469     LASTMUX=0;
00470     NUMMUX=0;
00471     //</Rubbish for NearDet but keep>
00472 
00473     NUMPINGAINS=2;
00474 
00475     PB0STARTPLANE=0;   //  0-120 inclusive
00476     PB2STARTPLANE=121; //121-281
00477 
00478     //<Rubbish for NearDet but keep>
00479     PB4STARTPLANE=0;
00480     PB6STARTPLANE=0;
00481     PB8STARTPLANE=0;
00482     PB10STARTPLANE=0;
00483     PB12STARTPLANE=0;
00484     PB14STARTPLANE=0;
00485     //<Rubbish for NearDet but keep>
00486 
00487     FIRSTPLANE=0;
00488     FIRSTSCINTPLANE=1;
00489 
00490     LASTSM1SCINTPLANE=120;//end of forward section not SM obviously
00491     FIRSTSM2PLANE=121;
00492     FIRSTSM2SCINTPLANE=121;
00493     LASTSCINTPLANE=281;
00494     LASTPLANE=281;
00495     NUMPLANES=282;
00496 
00497     NUMBOOKENDS=2;
00498     SM1BOOKEND=0;//steel only plane
00499     //consider SM2BE to be first steel-only plane in ND spectrometer
00500     SM2BOOKEND=122;//steel only plane
00501 
00502     //this is ND only
00503     FIRSTSPECTROMETERPLANE=121;
00504 
00505     //the total number of instrumented planes will be 153 since
00506     //0 is a bookend and 32*4=128 are uninstrumented in the spectrometer
00507 
00508     //Different regions in the ND:
00509     //Breakdown of number of planes:
00510     // Veto=21 planes numbered 0-20 (1st is steel bookend)
00511     // Target=40 planes numbered 21-60
00512     // Shower=60 planes numbered 61-120
00513     // Spectrometer=161 planes 121-281
00514     //   First and last are instrumented
00515     //   33 have scintillator, 128 are steel
00516     //   4 steel planes for each one with scintillator,
00517     //   Altogether: 5*32=160, 160+1 at end=161
00518 
00519     //Number of strips:
00520     //Forward section:
00521     //96 planes with 64 strips
00522     //24 planes with 96 strips
00523     //Spectrometer section:
00524     //33 planes with 96 strips
00525     //96+24+33=153 instrumented in total
00526   }
00527   else{
00528     MSG("LILookup",Msg::kWarning)
00529       <<"Detector Type="<<det<<" not supported yet"<<endl;
00530   }
00531 }
00532 
00533 //......................................................................
00534 
00535 TGraph* LILookup::TGraphVect(vector<Double_t>& vX,
00536                              vector<Double_t>& vY)
00537 {
00538   MSG("LIPlexMaps",Msg::kDebug) 
00539     <<" ** Running TGraphVect method... **"<<endl;
00540 
00541   TGraph* g=0;
00542 
00543   if (vX.size()!=vY.size()){
00544     MSG("LIPlexMaps",Msg::kError)
00545       <<"Cannot create TGraph from the two vectors as they are"<<endl
00546       <<"different sizes. vX="<<vX.size()<<", vY="<<vY.size()<<endl; 
00547     return g;
00548   }
00549 
00550   g=new TGraph(vX.size());
00551   
00552   for (UInt_t i=0;i<vX.size();i++){
00553     g->SetPoint(i,vX[i],vY[i]);
00554   }    
00555 
00556   MSG("LIPlexMaps",Msg::kDebug) 
00557     <<" ** Finished TGraphVect method **"<<endl;
00558   return g;
00559 }
00560 
00561 //......................................................................
00562 
00563 TGraphAsymmErrors* LILookup::
00564 TGraphAsymmErrorsVectEY(vector<Double_t>& vX,vector<Double_t>& vY,
00565                         vector<Double_t>& vEYL,vector<Double_t>& vEYH)
00566 {
00567   MSG("LIPlexMaps",Msg::kDebug) 
00568     <<" ** Running TGraphVectAsymmErrors method... **"<<endl;
00569 
00570   TGraphAsymmErrors* g=0;
00571 
00572   //check two vectors are same size
00573   if (vX.size()!=vY.size()){
00574     MSG("LIPlexMaps",Msg::kError)
00575       <<"Cannot create TGraphAsymmErrors from the two vectors"
00576       <<" of points as they are"<<endl
00577       <<"different sizes. vX="<<vX.size()<<", vY="<<vY.size()<<endl; 
00578     return g;
00579   }
00580   //check two error vectors are same size
00581   if (vEYL.size()!=vEYH.size()){
00582     MSG("LIPlexMaps",Msg::kError)
00583       <<"Cannot create TGraphAsymmErrors from the two vectors"
00584       <<" of errors as they are"<<endl
00585       <<"different sizes. vEX="<<vEYL.size()
00586       <<", vEY="<<vEYH.size()<<endl; 
00587     return g;
00588   }
00589   //check error vectors are same size as the point vectors
00590   //if you get here then two errors are the same size and
00591   //the two points are the same size
00592   //so, if either of each are different, it is enough to check just that
00593   if (vEYL.size()!=vY.size()){
00594     MSG("LIPlexMaps",Msg::kError)
00595       <<"Cannot create TGraphAsymmErrors from the two vectors"
00596       <<" of errors as they are"<<endl
00597       <<"different sizes. vEY="<<vEYL.size()<<", vY="<<vY.size()<<endl; 
00598     return g;
00599   }
00600 
00601   g=new TGraphAsymmErrors(vX.size());
00602 
00603   for (UInt_t i=0;i<vX.size();i++){
00604     g->SetPoint(i,vX[i],vY[i]);
00605     g->SetPointError(i,0,0,vY[i]-vEYL[i],vEYH[i]-vY[i]);
00606   }    
00607 
00608   MSG("LIPlexMaps",Msg::kDebug) 
00609     <<" ** Finished TGraphVectAsymmErrors method **"<<endl;
00610   return g;
00611 }
00612 
00613 //......................................................................
00614 
00615 void LILookup::SetNewPoint(vector<Double_t>& v,Double_t value,UInt_t i)
00616 {
00617   MSG("LILookup",Msg::kVerbose) 
00618     <<"Running SetNewPoint method..."<<endl;
00619   
00620   if (i<=v.size()){
00621     vector<Double_t>::iterator point;
00622     point=v.begin();
00623     point+=i;
00624     
00625     if (i==v.size()) MSG("LILookup",Msg::kVerbose)
00626       <<"Inserting at end v.size()="<<v.size()<<endl;
00627     
00628     //inserts value at the point immediately before the original ith
00629     //element so, if i=3 then 0=0, 1=1, 2=2, 3=new, 4=old3
00630     v.insert(point,value);
00631 
00632     if (i+1==v.size()) MSG("LILookup",Msg::kVerbose)
00633       <<"Inserted at end, now v.size()="<<v.size()<<endl;
00634   }
00635   else {
00636     MSG("LILookup",Msg::kWarning) 
00637       <<"Only "<<v.size()<<" elements available in vector"
00638       <<", cannot insert value at point "<<i<<endl;
00639   }
00640 
00641   MSG("LILookup",Msg::kVerbose) 
00642     <<"SetNewPoint method finished"<<endl;
00643 }
00644 
00645 //......................................................................
00646 
00647 Double_t LILookup::GetVectorPoint(const std::vector<Double_t>& v,
00648                                   UInt_t point)
00649 {
00650   MSG("LILookup",Msg::kVerbose) 
00651     <<"Running GetVectorPoint method..."<<endl;
00652   
00653   if (point<v.size()) return v[point];
00654   else {
00655     MSG("LILookup",Msg::kWarning) 
00656       <<"Only "<<v.size()<<" elements available, returning -1"<<endl;
00657     return -1;
00658   }
00659 
00660   MSG("LILookup",Msg::kVerbose) 
00661     <<"GetVectorPoint method finished"<<endl;
00662 }
00663 
00664 //......................................................................
00665 
00666 UInt_t LILookup::FindInsertPoint(const std::vector<Double_t>& v,
00667                                  Double_t valueToInsert)
00668 {
00669   MSG("LILookup",Msg::kVerbose) 
00670     <<"Running FindInsertPoint method..."<<endl;
00671   
00672   //insert point - the ith element of the vector
00673   UInt_t i=0;
00674   
00675   if (v.size()>=1){
00676     //get iterator
00677     vector<Double_t>::const_iterator vectValue;
00678     //set iterator to the begining
00679     vectValue=v.begin();
00680     //loop over the vector
00681     while (vectValue!=v.end()){
00682       //if the vector element is greater than the value to insert
00683       //then stop looping
00684       //else increment the vector element
00685       //the min value of i is 0, 
00686       //the max is v.size(), i.e. one past the end 
00687 
00688       MSG("LILookup",Msg::kDebug)
00689         <<"i="<<i<<", ith value="<<*vectValue
00690         <<", valueToInsert="<<valueToInsert<<endl;
00691 
00692       if (*vectValue>valueToInsert) break;
00693       i++;
00694       vectValue++;
00695     }
00696   }
00697 
00698   //check if first point
00699   if (v.size()==0){
00700     MSG("LILookup",Msg::kDebug)
00701       <<endl<<"First point to be inserted: i="<<i
00702       <<", vSize="<<v.size()
00703       <<", valueToInsert="<<valueToInsert<<endl;
00704   }
00705   //insert at beginning (of finite vector)
00706   else if (i==0){
00707     MSG("LILookup",Msg::kDebug)
00708       <<endl<<"Insert at beginning of vector: i="<<i
00709       <<", first current value="<<v[i]
00710       <<", vSize="<<v.size()
00711       <<", valueToInsert="<<valueToInsert<<endl;
00712   }
00713   //insert at end
00714   else if (i==v.size()){
00715     MSG("LILookup",Msg::kDebug)
00716       <<endl<<"Insert at end of vector: i="<<i
00717       <<", last current value="<<v[i-1]
00718       <<", vSize="<<v.size()
00719       <<", valueToInsert="<<valueToInsert<<endl;
00720   }
00721   //insert somewhere in the middle
00722   else{
00723     MSG("LILookup",Msg::kDebug)
00724       <<endl<<"Insert at point i="<<i
00725       <<", v[i-1]="<<v[i-1]
00726       <<", v[i]="<<v[i]
00727       <<", vSize="<<v.size()
00728       <<", valueToInsert="<<valueToInsert<<endl;
00729   }
00730   
00731   MSG("LILookup",Msg::kVerbose) 
00732     <<"FindInsertPoint method finished"<<endl;
00733   return i;
00734 }
00735 
00736 //......................................................................
00737 
00738 string LILookup::GetVectorAsString(std::vector<Double_t>& v,
00739                                    const std::string& prefix) const 
00740 {
00741   MSG("LILookup",Msg::kVerbose) 
00742     <<"Running GetVectorAsString method..."<<endl;
00743 
00744   string sV="";
00745 
00746   MSG("LILookup",Msg::kVerbose)
00747     <<endl<<"Vector size = "<<v.size()<<", prefix="<<prefix<<endl;
00748 
00749   //loop over the vector
00750   for (UInt_t i=0;i<v.size();i++){
00751     if (i==0) sV+=prefix;
00752     sV+=Form("%d",static_cast<Int_t>(v[i]));
00753     MSG("LILookup",Msg::kVerbose)
00754       <<Form("%d",static_cast<Int_t>(v[i]))<<endl;
00755     if (i==v.size()-1) sV+="\n";
00756     else sV+=",";
00757   }
00758 
00759   MSG("LILookup",Msg::kDebug)<<"Returning string:"<<sV<<endl;
00760 
00761   MSG("LILookup",Msg::kVerbose) 
00762     <<"GetVectorAsString method finished"<<endl;
00763   return sV;
00764 }
00765 
00766 //......................................................................
00767 
00768 string LILookup::GetVectorAsString(std::vector<Int_t>& v,
00769                                    const std::string& prefix) const 
00770 {
00771   MSG("LILookup",Msg::kVerbose) 
00772     <<"Running GetVectorAsString method..."<<endl;
00773 
00774   string sV="";
00775 
00776   MSG("LILookup",Msg::kVerbose)
00777     <<endl<<"Vector size = "<<v.size()<<", prefix="<<prefix<<endl;
00778 
00779   //loop over the vector
00780   for (UInt_t i=0;i<v.size();i++){
00781     if (i==0) sV+=prefix;
00782     sV+=Form("%d",static_cast<Int_t>(v[i]));
00783     MSG("LILookup",Msg::kVerbose)
00784       <<Form("%d",static_cast<Int_t>(v[i]))<<endl;
00785     if (i==v.size()-1) sV+="\n";
00786     else sV+=",";
00787   }
00788 
00789   MSG("LILookup",Msg::kDebug)<<"Returning string:"<<sV<<endl;
00790 
00791   MSG("LILookup",Msg::kVerbose) 
00792     <<"GetVectorAsString method finished"<<endl;
00793   return sV;
00794 }
00795 
00796 //......................................................................
00797 
00798 Double_t LILookup::CalcGain(Double_t mean,Double_t rms, Double_t QE)
00799 {
00800   //gain=rms**2/mean * 1/(1-p)
00801   Double_t gain=-1;
00802 
00803   //protect against fpe
00804   if (mean!=0 && 1-QE!=0) gain=(rms*rms/mean)*(1/(1-QE));
00805   
00806   return gain;
00807 }
00808 
00809 //......................................................................
00810 
00811 Double_t LILookup::CalcNpe(Double_t mean,Double_t rms,Double_t QE)
00812 {
00813   //npe=(mean/rms)**2 * (1-p)
00814   Double_t npe=-1;
00815 
00816   //protect against fpe
00817   if (rms!=0) npe=pow(mean/rms,2)*(1-QE);
00818   
00819   return npe;
00820 }
00821 
00822 //......................................................................
00823 
00824 Double_t LILookup::CalcRms(Double_t mean,Double_t gain,Double_t QE)
00825 {
00826   //rms=sqrt(gain*mean*(1-p))
00827   Double_t rms=-1;
00828 
00829   //protect against fpe
00830   Double_t rms2=gain*mean*(1-QE);
00831   if (rms2>=0) rms=sqrt(rms2);
00832   
00833   return rms;
00834 }
00835 
00836 //......................................................................
00837 
00838 Double_t LILookup::CalcMean(Double_t gain,Double_t rms,Double_t QE)
00839 {
00840   //mean=rms**2/gain * 1/(1-p)
00841   Double_t mean=-1;
00842 
00843   //protect against fpe
00844   if (gain!=0 && 1-QE!=0) mean=(rms*rms/gain)*(1/(1-QE));
00845   
00846   return mean;
00847 }
00848 
00849 //......................................................................
00850 
00851 Double_t LILookup::CalcMeanFromNpe(Double_t npe,Double_t rms,
00852                                    Double_t QE)
00853 {
00854   //mean=sqrt(npe/(1-p)) * rms
00855   Double_t mean=-1;
00856 
00857   //protect against fpe
00858   Double_t x=0;
00859   if (1-QE!=0) x=npe/(1-QE);
00860   if (x>=0) mean=sqrt(x)*rms;
00861   
00862   return mean;
00863 }
00864 
00865 //......................................................................
00866 
00867 Int_t LILookup::ConvertEastWest(string sEastWest)
00868 {
00869   MSG("LILookup",Msg::kDebug) 
00870     <<" ** Running the ConvertEastWest method... ** "<<endl;
00871 
00872   Int_t eastWest=-1;
00873   
00874   //translate east west to an integer
00875   if (sEastWest=="E") eastWest=StripEnd::kEast;//kEast=1=kNeg
00876   else if (sEastWest=="W") eastWest=StripEnd::kWest;//kWest=2=kPos
00877   //else stays as -1
00878 
00879   if (StripEnd::kEast!=1) MSG("LILookup",Msg::kInfo)
00880     <<"Convention error!"<<endl; 
00881 
00882   MSG("LILookup",Msg::kDebug) 
00883     <<" ** Finished the ConvertEastWest method **"<<endl;
00884   return eastWest;
00885 }
00886 
00887 //......................................................................
00888 
00889 Int_t LILookup::ConvertRackLevel(string sRackLevel)
00890 {
00891   MSG("LILookup",Msg::kDebug) 
00892     <<" ** Running the ConvertRackLevel method... ** "<<endl;
00893 
00894   Int_t rackLevel=-1;
00895   
00896   //translate east west to an integer
00897   if (sRackLevel=="L") rackLevel=0;
00898   else if (sRackLevel=="U") rackLevel=1;
00899   else if (sRackLevel=="?") rackLevel=-2;//this appears too often
00900   //else stays as -1
00901 
00902   MSG("LILookup",Msg::kDebug) 
00903     <<" ** Finished the ConvertRackLevel method **"<<endl;
00904   return rackLevel;
00905 }
00906 
00907 //......................................................................
00908 
00909 Int_t LILookup::GetOppPb(Int_t pulserBox,Int_t detectorType)
00910 { 
00911   MSG("LILookup",Msg::kDebug) 
00912     <<" ** Running the GetOppPb method... ** "<<endl;
00913 
00914   Int_t oppPulserBox=-1;
00915   
00916   if (detectorType==Detector::kFar){
00917     if (pulserBox>=FIRSTPULSERBOX && pulserBox<=LASTPULSERBOX){ 
00918       if (pulserBox%2==0){//east
00919         oppPulserBox=pulserBox+1;
00920       }
00921       else if (pulserBox%2==1){//west
00922         oppPulserBox=pulserBox-1;
00923       }
00924     }    
00925   }
00926   else if(detectorType==Detector::kCalDet){
00927     //only 1 pulser box at CalDet!
00928     oppPulserBox=pulserBox;
00929   }
00930   else if(detectorType==Detector::kNear){
00931     //pulser boxes are only on one side so this is meaningless
00932     //but return it anyway
00933     oppPulserBox=pulserBox;
00934   }
00935   else{
00936     MSG("LILookup",Msg::kWarning)
00937       <<"Detector Type = "<<detectorType<<" not supported yet"<<endl;
00938   }
00939 
00940   MSG("LILookup",Msg::kDebug) 
00941     <<" ** Finished the GetOppPb method **"<<endl;
00942   return oppPulserBox;
00943 }
00944 
00945 //......................................................................
00946 
00947 Int_t LILookup::GetOppCrate(Int_t crate,Int_t detectorType)
00948 { 
00949   MSG("LILookup",Msg::kDebug) 
00950     <<" ** Running the GetOppCrate method... ** "<<endl;
00951 
00952   Int_t oppCrate=-1;
00953 
00954   if (detectorType==Detector::kFar){
00955     if (crate>=FIRSTCRATE && crate<=LASTCRATE){ 
00956       if (crate%2==0){//east
00957         oppCrate=crate+1;
00958       }
00959       else if (crate%2==1){//west
00960         oppCrate=crate-1;
00961       }
00962     }
00963   }
00964   else if(detectorType==Detector::kCalDet){
00965     if (crate>=0 && crate<=1){ 
00966       if (crate==0){
00967         oppCrate=crate+1;
00968       }
00969       else if (crate==1){
00970         oppCrate=crate-1;
00971       }
00972     }
00973   }
00974   else{
00975     MSG("LILookup",Msg::kWarning)
00976       <<"Detector Type = "<<detectorType<<" not supported yet"<<endl;
00977   }
00978 
00979   MSG("LILookup",Msg::kDebug) 
00980     <<" ** Finished the GetOppCrate method **"<<endl;
00981   return oppCrate;
00982 }
00983 
00984 //......................................................................
00985 
00986 Int_t LILookup::Pb2TrigPmtChannel(Int_t pulserBox,Int_t detectorType)
00987 { 
00988   MSG("LILookup",Msg::kDebug) 
00989     <<" ** Running the Pb2TrigPmtChannel method... ** "<<endl;
00990 
00991   Int_t channel=-1;
00992 
00993   if (detectorType==Detector::kFar){
00994     //This list was made empirically by looking at the channels which had
00995     //saturated adc values
00996     Int_t pB2TrigPmtChannel[]=
00997       {14,  3, 12,  9,  6,
00998        11, 15,  4,  5, 16,
00999        7,  10, 13,  8,  2,
01000        17};
01001 
01002     if (pulserBox>=FIRSTPULSERBOX && pulserBox<=LASTPULSERBOX){ 
01003       channel=pB2TrigPmtChannel[pulserBox];
01004     }    
01005   }
01006   else if(detectorType==Detector::kCalDet){
01007     //varc 2 vmm 5 vfb 0 chip 1
01008     Int_t pB2TrigPmtChannel[]={4};
01009     
01010     if (pulserBox>=0){ 
01011       channel=pB2TrigPmtChannel[pulserBox];
01012     }    
01013   }
01014   else if(detectorType==Detector::kNear){
01015     //need to work out the tpmt channels for pb 1 and 2
01016     //QIE(0,16,0,14)
01017     Int_t pB2TrigPmtChannel[]={8,  14, -1};
01018     if (pulserBox>=FIRSTPULSERBOX && pulserBox<=LASTPULSERBOX){ 
01019       channel=pB2TrigPmtChannel[pulserBox];
01020     } 
01021     else{
01022       MSG("LILookup",Msg::kWarning)<<"No pulser box="<<pulserBox<<endl;
01023     }
01024   }
01025   else{
01026     MSG("LILookup",Msg::kWarning)
01027       <<"Detector Type = "<<detectorType<<" not supported yet"<<endl;
01028   }
01029 
01030   MSG("LILookup",Msg::kDebug) 
01031     <<" ** Finished the Pb2TrigPmtChannel method **"<<endl;
01032   return channel;
01033 }
01034 
01035 //......................................................................
01036 
01037 void LILookup::SetPbPlanes(Int_t *planeMin,Int_t *planeMax,
01038                            Int_t detectorType)
01039 { 
01040   MSG("LILookup",Msg::kDebug) 
01041     <<" ** Running the SetPbPlanes method... ** "<<endl;
01042 
01043   if (detectorType==Detector::kFar){
01044     for (Int_t j=0;j<2;j++){    
01045       planeMin[0+j]=PB0STARTPLANE;
01046       planeMax[0+j]=PB2STARTPLANE;
01047       planeMin[2+j]=PB2STARTPLANE;
01048       planeMax[2+j]=PB4STARTPLANE;
01049       planeMin[4+j]=PB4STARTPLANE;
01050       planeMax[4+j]=PB6STARTPLANE;
01051       planeMin[6+j]=PB6STARTPLANE;
01052       planeMax[6+j]=PB8STARTPLANE;
01053       planeMin[8+j]=PB8STARTPLANE;
01054       planeMax[8+j]=PB10STARTPLANE;
01055       planeMin[10+j]=PB10STARTPLANE;
01056       planeMax[10+j]=PB12STARTPLANE;
01057       planeMin[12+j]=PB12STARTPLANE;
01058       planeMax[12+j]=PB14STARTPLANE;
01059       planeMin[14+j]=PB14STARTPLANE;
01060       planeMax[14+j]=LASTPLANE+1;
01061     }
01062   }
01063   else if (detectorType==Detector::kCalDet){
01064     for (Int_t j=0;j<2;j++){    
01065       planeMin[0+j]=FIRSTPLANE;
01066       planeMax[0+j]=LASTPLANE+1;
01067       
01068       if (NUMCRATES==3){
01069         MSG("LILookup",Msg::kInfo)
01070           <<"Setting 3rd crate plane min and max - hack"<<endl;
01071         planeMin[2]=FIRSTSCINTPLANE;
01072         planeMax[2]=LASTPLANE+1;
01073       }
01074     }
01075   }
01076 
01077   // Near Detector:
01078   // pulser box 0 serves the spectrometer
01079   // pulser boxes 1,2 both serve the whole calorimeter
01080   // 1 the V planes and 2 the U planes
01081 
01082   //  else if (detectorType==Detector::kNear){
01083   //  planeMin[0] = FIRSTSPECTROMETERPLANE;
01084   //  planeMax[0] = LASTPLANE;
01085   //  for (Int_t j=1;j<NUMPULSERBOXES;j++){
01086   //    planeMin[j] = FIRSTSCINTPLANE;
01087   //    planeMax[j] = FIRSTSPECTROMETERPLANE;
01088   //  }
01089   // }
01090   
01091   // At the moment, use whole detector. All the gains will be in the
01092   // crate 0 plot.
01093 
01094   else if (detectorType==Detector::kNear){
01095     for (Int_t j=0;j<NUMCRATES;j++){  
01096       planeMin[j]=FIRSTPLANE;
01097       planeMax[j]=LASTPLANE+1;
01098     }
01099   }
01100   else{
01101     MSG("LILookup",Msg::kWarning)
01102       <<"Detector Type = "<<detectorType<<" not supported yet"<<endl;
01103   }
01104   
01105   for (Int_t j=FIRSTPULSERBOX;j<NUMPULSERBOXES;j++){    
01106     MSG("LILookup",Msg::kInfo) 
01107       <<"PulserBox "<<j<<" has planes "<<planeMin[j]<<" -> " 
01108       <<planeMax[j]-1<<" inclusive"<<endl;
01109   }
01110   
01111   MSG("LILookup",Msg::kDebug) 
01112     <<" ** Finished the SetPbPlanes method **"<<endl;
01113 }
01114 
01115 //......................................................................
01116 
01117 Int_t LILookup::Chip2Pmt(Int_t chip,Int_t detectorType)
01118 { 
01119   MSG("LILookup",Msg::kDebug) 
01120     <<" ** Running the Chip2Pmt method... ** "<<endl;
01121 
01122   Int_t pmt=-1;
01123 
01124   if (detectorType==Detector::kFar){
01125     if (chip==0) pmt=0;
01126     if (chip==1) pmt=2;
01127     if (chip==2) pmt=1;
01128   }
01129   else{
01130     MSG("LILookup",Msg::kWarning)
01131       <<"Detector Type = "<<detectorType<<" not supported yet"<<endl;
01132   }
01133 
01134   MSG("LILookup",Msg::kDebug) 
01135     <<" ** Finished the Chip2Pmt method **"<<endl;
01136   return pmt;
01137 }
01138 
01139 //......................................................................
01140 
01141 Int_t LILookup::Led2Ashtray(Int_t led,Int_t plane,Int_t detectorType)
01142 {  //this should go in the plex!!
01143 
01144   MSG("LILookup",Msg::kDebug) 
01145     <<" ** Running the Led2Ashtray method... ** "<<endl;
01146 
01147   Int_t ashtray=-1;
01148 
01149   if (detectorType==Detector::kFar){
01150     Int_t led2Ashtray[20]={20,19,18,17,16,
01151                                 15,14,13,12,11,
01152                                 10, 9, 8, 7, 6,
01153                                 5, 4, 3, 2, 1};
01154     
01155     if (led>=FIRSTLED && led<=NUMLEDS){
01156       ashtray=led2Ashtray[led-1];
01157       //SM1
01158       if (plane>=FIRSTSCINTPLANE && plane<=LASTSM1SCINTPLANE){
01159         if((plane-1)%4>1){
01160           ashtray=ashtray-1;
01161           if(ashtray<1) ashtray=20;
01162         }
01163       }
01164       //SM2
01165       else{
01166         if ((plane%4)<2) {
01167           ashtray=ashtray-1;
01168           if(ashtray<1) ashtray=20;
01169         }
01170       }
01171     }
01172     MSG("LILookup_Led2Ashtray", Msg::kDebug) 
01173     <<"  ashtray="<<ashtray
01174     <<", led="<<led
01175     <<endl;
01176   }
01177   else if (detectorType==Detector::kCalDet){
01178     //you need to know the side as well to do this
01179     //see ryans webpage for details
01180     ashtray=-1;
01181   }
01182   else if (detectorType==Detector::kNear){
01183     //not implemented yet
01184     ashtray=-1;
01185   }
01186   else{
01187     MSG("LILookup",Msg::kWarning)
01188       <<"Detector Type = "<<detectorType<<" not supported yet"<<endl;
01189   }
01190 
01191   MSG("LILookup",Msg::kDebug) 
01192     <<" ** Finished the Led2Ashtray method **"<<endl;
01193   return ashtray;
01194 }
01195 
01196 //......................................................................
01197 
01198 Int_t LILookup::Strip2Ashtray(Int_t strip,Int_t detectorType)
01199 {
01200   MSG("LILookup",Msg::kDebug) 
01201     <<" ** Running the Strip2Ashtray method... ** "<<endl;
01202 
01203   Int_t ashtray=-1;
01204 
01205   if (detectorType==Detector::kFar){
01206     Int_t strip2Ashtray[192]={ 1,1,1,1,1,1,1,1,
01207                                      2,2,2,2,2,2,2,2,2,2,
01208                                      3,3,3,3,3,3,3,3,3,3,
01209                                      4,4,4,4,4,4,4,4,
01210                                      5,5,5,5,5,5,5,5,5,5,
01211                                      6,6,6,6,6,6,6,6,6,6,
01212                                      7,7,7,7,7,7,7,7,7,7,
01213                                      8,8,8,8,8,8,8,8,8,8,
01214                                      9,9,9,9,9,9,9,9,9,9,
01215                                      10,10,10,10,10,10,10,10,10,10,
01216                                      11,11,11,11,11,11,11,11,11,11,
01217                                      12,12,12,12,12,12,12,12,12,12,
01218                                      13,13,13,13,13,13,13,13,13,13,
01219                                      14,14,14,14,14,14,14,14,14,14,
01220                                      15,15,15,15,15,15,15,15,15,15,
01221                                      16,16,16,16,16,16,16,16,16,16,
01222                                      17,17,17,17,17,17,17,17,
01223                                      18,18,18,18,18,18,18,18,18,18,
01224                                      19,19,19,19,19,19,19,19,19,19,
01225                                      20,20,20,20,20,20,20,20};
01226     if (strip>=0 && strip<NUMSTRIPS){
01227       ashtray=strip2Ashtray[strip];
01228     }
01229   }
01230   else{
01231     MSG("LILookup",Msg::kWarning)
01232       <<"Detector Type = "<<detectorType<<" not supported yet"<<endl;
01233   }
01234   
01235   MSG("LILookup",Msg::kDebug) 
01236     <<" ** Finished the Strip2Ashtray method **"<<endl;
01237   return ashtray;
01238 }
01239 
01240 //......................................................................
01241 
01242 pair<Int_t,Int_t> LILookup::GetPinDiodePlanes(PlexPinDiodeId pinId,
01243                                               PlexHandle* plexHandle)
01244 {
01245   //this function returns the planes associated with the pin
01246   //diode, i.e. readout by the same chip on the vfb
01247 
01248   //a pair to hold the potentially two planes associated 
01249   //with the pin diodes
01250   pair<Int_t,Int_t> planes(-1,-1);
01251 
01252   //get the raw channel ids of the pins
01253   RawChannelId rawChanId=plexHandle->GetRawChannelId(pinId);
01254   
01255   if (MsgService::Instance()->IsActive("LILookup",Msg::kDebug)){
01256     rawChanId.Print();
01257     cout<<endl;//the above doesn't leave a line annoyingly
01258   }
01259     
01260   MSG("LIPlexMaps",Msg::kDebug) 
01261     <<"Pin chip="<<rawChanId.GetVaChip()<<endl;
01262 
01263   //loop over all the channels on the va chip 
01264   //At caldet the first pin is on a non-shared pmt (chip 0),
01265   //the second pin is on the shared pmt and chip 1
01266   for (Int_t i=0;i<NUMVACHANNELS;i++){
01267     //change the channel, get the altlist and then the plane
01268     rawChanId.SetVaChannel(i);
01269       
01270     //Get strip-end alternative list
01271     PlexSEIdAltL altList=plexHandle->GetSEIdAltL(rawChanId);
01272     
01273     //the plane is known from the rawchannel via altlist
01274     Int_t currentPlane=altList.GetPlane();  
01275     if (currentPlane>-1 && planes.first==-1){
01276       planes.first=currentPlane;
01277     }
01278     else if (currentPlane>-1 && currentPlane!=planes.first){
01279       planes.second=currentPlane;
01280     }
01281     
01282     MSG("LIPlexMaps",Msg::kDebug) 
01283       <<"Looping over VA: channel="<<i<<", plane1="<<planes.first
01284       <<", plane2="<<planes.second<<endl;    
01285 
01286     //jump out of loop if you have both planes
01287     if (planes.second>-1) break;
01288   }
01289 
01290   //sort the planes so lowest is first (except if only one plane
01291   Int_t tempPlane=planes.first;
01292   if (planes.second<planes.first  && planes.second!=-1){
01293     planes.first=planes.second;
01294     planes.second=tempPlane;
01295   }
01296 
01297   return planes;  
01298 }
01299 
01300 //......................................................................
01301 
01302 pair<PlexPinDiodeId,PlexPinDiodeId> LILookup::
01303 GetPinDiodeIds(PlexHandle plexHandle,Int_t led)
01304 {
01306   //prior to march 2003
01308   //Int_t highpinchadds[6]={4146,4274,4402,4786,4914,5042};
01309   //Int_t lowpinchadds[6]={4114,4242,4370,4626,4882,5010};
01310  
01311   //The pin diode information in the plex is as follows
01312   //The electronics information is in descending hierarchial order
01313   //(x:y) is pulser box x and led y
01314   //e.g. (crate,varc,vmm,vfb,VA chip,VA channel)
01315 
01316   //(0:1) Planes=41&43 Pin1=VA(0,2,0,0,0,18)=4114 
01317   //Pin2=VA(0,2,0,0,1,18)=4146
01318   //(0:2) Planes=45&47 Pin1=VA(0,2,0,1,0,18)=4242 
01319   //Pin2=VA(0,2,0,1,1,18)=4274
01320   //(0:3) Planes=49&51 Pin1=VA(0,2,1,0,0,18)=4370 
01321   //Pin2=VA(0,2,1,0,1,18)=4402
01322   //(0:4) Planes=40&42 Pin1=VA(0,2,2,0,0,18)=4626 
01323   //Pin2=VA(0,2,2,1,1,18)=4786
01324   //(0:5) Planes=44&46 Pin1=VA(0,2,3,0,0,18)=4882 
01325   //Pin2=VA(0,2,3,0,1,18)=4914
01326   //(0:6) Planes=48&50 Pin1=VA(0,2,3,1,0,18)=5010 
01327   //Pin2=VA(0,2,3,1,1,18)=5042
01328 
01330   //since to march 2003
01332   Int_t highpinchadds[6]={4146,4274,4402,4786,4914,5042};
01333   Int_t lowpinchadds[6]={4114,4242,4370,4626,4882,5010};
01334 
01335   //get high
01336   PlexPinDiodeId high=plexHandle.GetPinDiodeId
01337     (RawChannelId(Detector::kCalDet,ElecType::kVA,
01338                   0,highpinchadds[led-1]));
01339   
01340   //get low
01341   PlexPinDiodeId low=plexHandle.GetPinDiodeId
01342     (RawChannelId(Detector::kCalDet,ElecType::kVA,
01343                   0,lowpinchadds[led-1]));
01344   
01345   //  cout<<"Therefore: "<<high.GetEncoded()<<"\t"
01346   //    << low.GetEncoded()<<endl;
01347     return make_pair(high,low);
01348 }
01349 
01350 //......................................................................
01351 
01352 Int_t LILookup::Strip2Led(Int_t strip,Int_t plane,Int_t detectorType,
01353                           Int_t crate)
01354 {
01355   MSG("LILookup",Msg::kDebug) 
01356     <<" ** Running the Strip2Led method... ** "<<endl;
01357 
01358   Int_t led=-1;
01359   
01360   if (detectorType==Detector::kFar){
01361     Int_t strip2Led[192]={ 20,20,20,20,20,20,20,20,
01362                            19,19,19,19,19,19,19,19,19,19,
01363                            18,18,18,18,18,18,18,18,18,18,
01364                            17,17,17,17,17,17,17,17,
01365                            16,16,16,16,16,16,16,16,16,16,
01366                            15,15,15,15,15,15,15,15,15,15,
01367                            14,14,14,14,14,14,14,14,14,14,
01368                            13,13,13,13,13,13,13,13,13,13,
01369                            12,12,12,12,12,12,12,12,12,12,
01370                            11,11,11,11,11,11,11,11,11,11,
01371                            10,10,10,10,10,10,10,10,10,10,
01372                            9,9,9,9,9,9,9,9,9,9,
01373                            8,8,8,8,8,8,8,8,8,8,
01374                            7,7,7,7,7,7,7,7,7,7,
01375                            6,6,6,6,6,6,6,6,6,6,
01376                            5,5,5,5,5,5,5,5,5,5,
01377                            4,4,4,4,4,4,4,4,
01378                            3,3,3,3,3,3,3,3,3,3,
01379                            2,2,2,2,2,2,2,2,2,2,
01380                            1,1,1,1,1,1,1,1};
01381     
01382     if (strip>=0 && strip<NUMSTRIPS){
01383       led=strip2Led[strip];
01384 
01385       //due to the strange cyclic permutation caused by a mux box
01386       //numbering scheme cock up and another cock up to do with which
01387       //led was 1 and which was 20 you have the following complicated
01388       //scheme
01389       //SM1
01390       if (plane<249 && plane>0){
01391         if((plane-1)%4>1){
01392           led=led-1;
01393           if(led<1) led=20;
01394         }
01395       }
01396       //SM2
01397       else{
01398         if ((plane%4)<2) {
01399           led=led-1;
01400           if(led<1) led=20;
01401         }
01402       }
01403     }
01404   }
01405   else if (detectorType==Detector::kCalDet){
01406     //Thanks to Ryan for this piece of code
01407 
01408     //On the kPos=kWest=ND side the leds in plane 40 and 50 are switched
01409     //On the kNeg=kEast=FD side the leds in plane 56 and 58 were
01410     //switched but not since March 2003
01411     
01412     if(plane>59 || plane <0) {
01413       return -1;
01414     }
01415     
01416     //for crate 1 and 2
01417     if (crate==1 || crate ==2)
01418       if (strip<4) {
01419         if (plane==40) return 2;
01420         if ((plane%4)==0||(plane%4)==1) return 1;
01421         return 2;
01422       } 
01423       else if (strip<14) {
01424         if (plane==50) return 3;
01425         if (plane==40) return 1;
01426         if ((plane%4)==0||(plane%4)==1) return 2;
01427         return 1;
01428       } 
01429       else {
01430         if (plane==50) return 1;
01431         return 3;
01432       }
01433     //for crate 0
01434     else if (crate==0){
01435       if (strip<10) {
01436         //if (plane==56||plane==58||plane==12 ) return 4;
01437         return 6;
01438       } 
01439       else if (strip<20) {
01440         //if (plane==58) return 6;
01441         if ((plane%4)==0 || (plane%4)==1) return 5;
01442         return 4;
01443       } 
01444       else {
01445         //if(plane==56 || plane==12 ) return 6;
01446         if ((plane%4)==0 || (plane%4)==1) return 4;
01447         return 5;
01448       }
01449     }
01450   }
01451   else{
01452     MSG("LILookup",Msg::kWarning)
01453       <<"Detector Type = "<<detectorType<<" not supported yet"<<endl;
01454   }
01455   
01456   MSG("LILookup",Msg::kDebug) 
01457     <<" ** Finished the Strip2Led method **"<<endl;
01458   return led;
01459 }
01460 
01461 //......................................................................
01462 
01463 Int_t LILookup::Plane2Pb(Int_t plane,Int_t side)
01464 {
01465   MSG("LILookup",Msg::kDebug) 
01466     <<" ** Running the Plane2Pb method... ** "<<endl;
01467 
01468   Int_t pulserBox=-1;
01469 
01470   if (side==StripEnd::kEast){
01471     pulserBox=Plane2PbEast(plane);
01472   }
01473   if (side==StripEnd::kWest){
01474     if (side!=2) MSG("LILookup",Msg::kInfo)<<"Convention error!"<<endl; 
01475     pulserBox=Plane2PbWest(plane);
01476   }
01477   //else pulser box stays as -1
01478 
01479   MSG("LILookup",Msg::kDebug) 
01480     <<" ** Finished the Plane2Pb method **"<<endl;
01481   return pulserBox;
01482 }
01483 
01484 //......................................................................
01485 
01486 Int_t LILookup::Plane2PbEast(Int_t plane)
01487 {
01488   MSG("LILookup",Msg::kDebug) 
01489     <<" ** Running the Plane2PbEast method... ** "<<endl;
01490 
01491   Int_t pulserBox=-1;
01492 
01493   if (plane>=FIRSTSCINTPLANE && plane<PB2STARTPLANE) pulserBox=0;
01494   else if (plane>=PB2STARTPLANE && plane<PB4STARTPLANE) pulserBox=2;
01495   else if (plane>=PB4STARTPLANE && plane<PB6STARTPLANE) pulserBox=4;
01496   else if (plane>=PB6STARTPLANE && plane<=LASTSM1SCINTPLANE) pulserBox=6;
01497   else if (plane>=PB8STARTPLANE && plane<PB10STARTPLANE) pulserBox=8;
01498   else if (plane>=PB10STARTPLANE && plane<PB12STARTPLANE) pulserBox=10;
01499   else if (plane>=PB12STARTPLANE && plane<PB14STARTPLANE) pulserBox=12;
01500   else if (plane>=PB14STARTPLANE && plane<=LASTSCINTPLANE) pulserBox=14;
01501 
01502   MSG("LILookup",Msg::kDebug) 
01503     <<" ** Finished the Plane2PbEast method **"<<endl;
01504   return pulserBox;
01505 }
01506 
01507 //......................................................................
01508 
01509 Int_t LILookup::Plane2PbWest(Int_t plane)
01510 {
01511   MSG("LILookup",Msg::kDebug) 
01512     <<" ** Running the Plane2PbWest method... ** "<<endl;
01513 
01514   Int_t pulserBox=-1;
01515   pulserBox=Plane2PbEast(plane);
01516   if (pulserBox>=0 && pulserBox<NUMPULSERBOXES){
01517     pulserBox++;//west pulser box is always one more than east
01518   }
01519 
01520   MSG("LILookup",Msg::kDebug) 
01521     <<" ** Finished the Plane2PbWest method **"<<endl;
01522   return pulserBox;
01523 }
01524 
01525 //......................................................................
01526 
01527 Int_t LILookup::Plane2Crate(Int_t plane,Int_t side,Int_t detectorType)
01528 {
01529   MSG("LILookup",Msg::kDebug) 
01530     <<" ** Running the Plane2Crate method... **"<<endl;
01531 
01532   Int_t crate=-1;
01533 
01534   if (detectorType==Detector::kFar){
01535     if (side==StripEnd::kEast){
01536       crate=Plane2CrateEast(plane,detectorType);
01537     }
01538     else if (side==StripEnd::kWest){
01539       crate=Plane2CrateWest(plane,detectorType);
01540     }
01541     //else crate stays as -1
01542   }
01543   else if (detectorType==Detector::kCalDet){
01544 
01545     //this gets a bit messy for near only running
01546     if (side==StripEnd::kEast){
01547       crate=0;
01548     }
01549     if (side==StripEnd::kWest){
01550       crate=1;
01551     }
01552     //else crate stays as -1
01553   }
01554   else if (detectorType==Detector::kNear){
01555     MAXMSG("LILookup",Msg::kWarning,3)
01556       <<"Detector Type = "<<detectorType
01557       <<" not supported properly yet, returning crate=0"<<endl;
01558     crate=0;
01559   }
01560   else {
01561     MSG("LILookup",Msg::kWarning)
01562       <<"Detector Type = "<<detectorType<<" not supported yet"<<endl;
01563   }
01564 
01565   MSG("LILookup",Msg::kDebug) 
01566     <<" ** Finished the Plane2Crate method **"<<endl;
01567   return crate;
01568 }
01569 
01570 //......................................................................
01571 
01572 Int_t LILookup::Plane2CrateEast(Int_t plane,Int_t detectorType)
01573 {
01574   MSG("LILookup",Msg::kDebug) 
01575     <<" ** Running the Plane2CrateEast method... **"<<endl;
01576 
01578 
01579   Int_t crate=-1;
01580 
01581   if (detectorType==Detector::kFar){
01582     crate=Plane2PbEast(plane);//pb and cr have the same numbers
01583   }
01584   else if (detectorType==Detector::kCalDet){
01585     crate=0;//the left side
01586   }
01587   else {
01588     MSG("LILookup",Msg::kWarning)
01589       <<"Detector Type = "<<detectorType<<" not supported yet"<<endl;
01590   }
01591   
01592   MSG("LILookup",Msg::kDebug) 
01593     <<" ** Finished the Plane2CrateEast method **"<<endl;
01594   return crate;
01595 }
01596 
01597 //......................................................................
01598 
01599 Int_t LILookup::Plane2CrateWest(Int_t plane,Int_t detectorType)
01600 {
01601   MSG("LILookup",Msg::kDebug) 
01602     <<" ** Running the Plane2CrateWest method... ** "<<endl;
01603 
01604   Int_t crate=-1;
01605 
01606   if (detectorType==Detector::kFar){
01607     crate=Plane2PbWest(plane);//pb and cr have the same numbers
01608   }
01609   else if (detectorType==Detector::kCalDet){
01610     crate=1;//the right side
01611   }
01612   else {
01613     MSG("LILookup",Msg::kWarning)
01614       <<"Detector Type = "<<detectorType<<" not supported yet"<<endl;
01615   }
01616 
01617   MSG("LILookup",Msg::kDebug) 
01618     <<" ** Finished the Plane2CrateWest method **"<<endl;
01619   return crate;
01620 }
01621 
01622 //......................................................................
01623 
01624 Int_t LILookup::NearOrFar(Int_t crate,Int_t pulserBox,
01625                           Int_t nearPulserBox, Int_t farPulserBox,
01626                           Int_t led,Int_t detectorType,
01627                           Int_t plane,Int_t runNumber)
01628 {
01629   MSG("LILookup",Msg::kDebug) 
01630     <<" ** Running the NearOrFar method... ** "<<endl;
01631 
01635 
01636   //modified 16/08/03 to include the fact that the ND electronics
01637   //at caldet now has 2 crates
01638 
01639   Int_t nearOrFar=kUnknownSide;
01640 
01641   if (detectorType==Detector::kFar){ 
01642 
01643     if (pulserBox<FIRSTPULSERBOX || pulserBox>LASTPULSERBOX){
01644       MSG("LILookup",Msg::kWarning)
01645         <<"Near or far determination not possible, PB out of range="
01646         <<pulserBox<<endl;      
01647     }
01648     else if (pulserBox==nearPulserBox){
01649       nearOrFar=kNearSide;
01650     }
01651     else if (pulserBox==farPulserBox){
01652       nearOrFar=kFarSide;
01653     }
01654     else{
01655       nearOrFar=kUnknownSide;
01656     }
01657   }
01658   else if (detectorType==Detector::kCalDet){  
01659 
01660     if (runNumber<80000){
01661       if (led==1 || led==2 || led==3){
01662         if (crate==1 || crate==2) nearOrFar=kNearSide;
01663         else if (crate==0) nearOrFar=kFarSide;
01664       }
01665       else if (led==4 || led==5 || led==6){
01666         if (crate==0) nearOrFar=kNearSide;
01667         else if (crate==1 || crate==2) nearOrFar=kFarSide;
01668       }
01669       else{
01670         MSG("LILookup",Msg::kWarning)
01671           <<"Near or far determination not possible for led = "
01672           <<led<<endl;      }
01673     }
01674     else{//section for near only running=pain in the arse
01675       //even planes have leds 1-3 as near leds
01676       //odd planes have leds 4-6 as near leds
01677       if (led==1 || led==2 || led==3){
01678         if (plane%2==0) nearOrFar=kNearSide;
01679         else if (plane%2==1) nearOrFar=kFarSide;
01680       }
01681       else if (led==4 || led==5 || led==6){
01682         if (plane%2==1) nearOrFar=kNearSide;
01683         else if (plane%2==0) nearOrFar=kFarSide;
01684       }
01685       else{
01686         MSG("LILookup",Msg::kWarning)
01687           <<"Near or far determination not possible for led = "
01688           <<led<<endl;
01689       }
01690     }
01691   }
01692   else if (detectorType==Detector::kNear){
01693     //always return kNearSide, it's all it can be!
01694     nearOrFar=kNearSide;
01695   }
01696   else {
01697     MSG("LILookup",Msg::kWarning)
01698       <<"Detector Type = "<<detectorType<<" not supported yet"<<endl;
01699   }
01700 
01701   MSG("LILookup",Msg::kDebug) 
01702     <<" ** Finished the NearOrFar method **"<<endl;
01703   return nearOrFar;
01704 }
01705 
01706 //......................................................................
01707 
01708 void LILookup::UnencodePlnStripEndKey(Int_t plnStripEndKey,
01709                                        Detector::Detector_t det,
01710                                        Int_t& plane,Int_t& strip,
01711                                        Int_t& stripEnd)
01712 {
01713   MSG("LILookup",Msg::kDebug) 
01714     <<" ** Running the UnencodePlnStripEndKey method... ** "<<endl;
01715 
01716   //this bit was stolen from the plex
01717   Int_t nStrips = 192;  // need some default
01718   switch (det) {
01719   case Detector::kNear:   nStrips =  96; break;
01720   case Detector::kFar:    nStrips = 192; break;
01721   case Detector::kCalDet: nStrips =  24; break;
01722   default:
01723     MSG("LILookup",Msg::kWarning)
01724       <<"Detector Type is not Near/Far/CalDet"<<endl;
01725   }
01726 
01727   //the strip end is stored as the lowest bit so need to shift 
01728   //that bit off before dividing by nStrips
01729   //kEast is stored as a 0 and kWest as a 1 so need to add one
01730   //to get to their actual values
01731 
01732   //EXCEPT the ND does not have a strip end stored - no point!!!
01733 
01734   //00245    if (det == Detector::kNear) {
01735   //00246       // near detector only has west readout
01736   //00247      if (end != StripEnd::kWest) {
01737   //00248        MAXMSG("Plex",Msg::kWarning,10)
01738   //00249          << "PlexStripEndId " << *this << " has non-West readout" << endl;
01739   //00250      // but do nothing
01740   //00251      }
01741   //00252    }
01742   //00253    else {
01743   //00254       // make room for end bit
01744   //00255       hvalue <<= 1;
01745   //00256       switch (GetEnd()) {
01746   //00257       case StripEnd::kEast: hvalue += 0; break;
01747   //00258       case StripEnd::kWest: hvalue += 1; break;
01748   //0/0259       default:
01749   //00260          MAXMSG("Plex",Msg::kWarning,10)
01750   //00261             << "PlexStripEndId " << *this << " is not East/West" << endl;
01751   //00262       }
01752   //00263    }
01753 
01754   if (det==Detector::kFar || det==Detector::kCalDet){
01755     plane=(plnStripEndKey>>1)/nStrips;
01756     strip=(plnStripEndKey>>1)%nStrips;
01757     //look at only the lowest bit
01758     stripEnd=(plnStripEndKey&0x1)+1;
01759   }
01760   else if (det==Detector::kNear){
01761     plane=plnStripEndKey/nStrips;
01762     strip=plnStripEndKey%nStrips;
01763     stripEnd=2;//because it always is
01764   }
01765   else{
01766     MSG("LILookup",Msg::kWarning)
01767       <<"Detector Type is not Near/Far/CalDet"<<endl;
01768   }
01769 
01770   MSG("LILookup",Msg::kDebug) 
01771     <<" ** Finished the UnencodePlnStripEndKey method **"<<endl;
01772 }
01773 
01774 //......................................................................
01775 
01776 Int_t LILookup::GetNumericMuxBox(Int_t pmtNo,Int_t detectorType)
01777 {
01778   MSG("LILookup",Msg::kDebug)
01779     <<" ** Running the GetNumericMuxBox method... ** "<<endl;
01780 
01781   Int_t MuxBox = -1;
01782 
01783   if (detectorType==Detector::kNear){
01784 
01785     Int_t numericMuxBox[194] = {4112,4113,5136,4114,5137,4115,5138,5139,4116,5140,4117,5141,4118,4119,5142,4128,
01786                                 5143,4129,5152,5153,4130,5154,4131,5155,4132,4133,5156,4134,5157,4135,5158,5159,
01787                                 4144,5168,4145,5169,4146,4147,5170,4148,5171,4149,5172,5173,4150,5174,4151,5175,
01788                                 4160,4161,5184,4162,5185,4163,5186,5187,4164,5188,4165,5189,4166,4167,5190,4176,
01789                                 5191,4177,5200,5201,4178,5202,4179,5203,4180,4181,5204,4182,5205,4183,5206,5207,
01790                                 4192,5216,4193,5217,4194,4195,5218,4196,5219,4197,5220,5221,4198,5222,4199,5223,
01791                                 4208,4209,5232,4210,5233,4211,5234,5235,4212,5236,4213,5237,4214,4215,5238,4224,
01792                                 5239,4225,5248,5249,4226,5250,4227,5251,4228,4229,5252,4230,5253,4231,5254,5255,
01793                                 4240,5264,4241,5265,4242,4243,5266,4244,5267,4245,5268,5269,4246,5270,4247,5271,
01794                                 4257,4256,5280,5281,4258,5282,4261,4260,5284,5285,4262,5286,4273,4272,5296,5297,
01795                                 4274,5298,4277,4276,5300,5301,4278,5302,4289,4288,5312,5313,4290,5314,4293,4292,
01796                                 5316,5317,4294,5318,4305,4304,5328,5329,4306,5330,4309,4308,5332,5333,4310,5334,
01797                                 4311,4307};
01798     MuxBox = numericMuxBox[pmtNo];
01799   }
01800   else{
01801     MSG("LILookup",Msg::kWarning)
01802       <<"Detector Type = "<<detectorType<<" not supported yet"<<endl;
01803   }
01804 
01805   MSG("LILookup",Msg::kDebug)
01806     <<" ** Finished the GetNumericMuxBox method **"<<endl;
01807   return MuxBox;
01808 }
01809 
01810 //......................................................................

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