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

LISummarySorter.cxx

Go to the documentation of this file.
00001 
00002 
00003 // Program name: LISummarySorter.cxx     
00004 //                                                                     
00005 // Package: LISummary                    
00006 //
00007 // Coded by Jeff Hartnell Oct/2002 - Sep/2003  
00008 //
00009 // Based on code by: Rob Morse Feb/2002 
00010 //                                                                   
00011 // Purpose: To sort the raw LI summaries into the right electronics 
00012 //          channel 
00013 //                                                                    
00014 // Contact: jeffrey.hartnell@physics.ox.ac.uk   
00016 
00017 #include <fstream>
00018 #include <string>
00019 #include <cmath>
00020 
00021 #include "TText.h"
00022 #include "TPaveText.h"
00023 #include "TCanvas.h"
00024 #include "TPad.h"
00025 
00026 #include "MessageService/MsgService.h"
00027 #include "MessageService/MsgFormat.h"
00028 
00029 #include "LISummary/LISummarySorter.h"
00030 
00031 CVSID("$Id: LISummarySorter.cxx,v 1.46 2007/11/11 08:00:53 rhatcher Exp $");
00032 
00033 //......................................................................
00034 
00035 LISummarySorter::LISummarySorter()
00036 {
00037   MSG("LISummarySorter",Msg::kDebug) 
00038     <<"Running LISummarySorter Constructor..."<<endl;
00039 
00040   //initialise data members
00041   ashtray=-1;
00042   badHitCounter=0;
00043   calibPoint=-1;
00044   calibType=-1;
00045   cerenkovCounter=0;
00046   chAdd=-1;
00047   channel=-1;
00048   chip=-1;
00049   commonModeCounter=0;//readoutType counter
00050   correlatedHit=-1;
00051   crate=-1;
00052   detectorType=-1;
00053   eastWest=-1;//0 is east, 1 is west 
00054   elecType=-1;
00055   farLed=-1;
00056   farPulserBox=-1;
00057   first_time=0;
00058   inRack=-1;//determines mux box in rack 0-7
00059   geoAdd=-1;
00060   goodHitCounter=0;
00061   led=-1;
00062   fMasterCh=-1;
00063   mean=-1.;
00064   fMinderCh=-1;
00065   nearLed=-1;
00066   nearPulserBox=-1;
00067   numEntries=-1;
00068   numericMuxBox=-1;
00069   outtree=0;//set pointer to tree to zero
00070   outputFile=0;
00071   fPe=-1;
00072   period=-1;
00073   pixel=-1;
00074   pinCounter=0;
00075   pinGain=-1;//0 is low, 1 is high gain
00076   pinInBox=-1;//0 is low gain (VA=0), 1 is high gain (VA=1)
00077   plane=-1;
00078   plexHandle=0;
00079   pulseHeight=-1;
00080   pulserBox=-1;
00081   pulses=-1;
00082   pulseWidth=-1;
00083   rackBay=-1;//determines which rack 0-15
00084   rackLevel=-1;//0 is top, 1 is bottom
00085   rawSummaryBlockCounter=0;
00086   rawSummaryCounter=0;
00087   readoutType=-1;
00088   rms=-1.;
00089   runNumber=-1;
00090   runNumberSub=-1;
00091   runType=-1;
00092   strip=-1;
00093   stripCounter=0;
00094   fStripEnd=-1;
00095   summaryCounter=0;
00096   timestamp=-1;
00097   timestampNanoSec=-1;
00098   timingFidCounter=0;
00099   tofCounter=0;
00100   triggerOrCounter=0;
00101   trigPmtCounter=0;
00102   unconnectedPixelCounter=0;
00103   unknownCounter=0;
00104   varc=-1;
00105   vfb=-1;
00106   vmm=-1;
00107 
00108   MSG("LISummarySorter",Msg::kDebug) 
00109     <<"Finished LISummarySorter Constructor"<<endl;
00110 }
00111 
00112 //......................................................................
00113 
00114 LISummarySorter::~LISummarySorter()
00115 {
00116   MSG("LISummarySorter",Msg::kDebug) 
00117     <<"Running LISummarySorter destructor..."<<endl;
00118 
00119   //get rid of memory leak right at the end
00120   if (plexHandle) delete plexHandle;
00121 
00122   MSG("LISummarySorter",Msg::kDebug) 
00123     <<"Finished LISummarySorter destructor"<<endl;
00124 }
00125 
00126 //......................................................................
00127   
00128 void LISummarySorter::PrintRecoSummary()
00129 {
00130   MSG("LISummarySorter",Msg::kVerbose)
00131     <<"Running PrintRecoSummary method..."<<endl;
00132 
00133   //print out summary of reconstruction information
00134   if (runNumber!=-1 && runNumberSub!=-1 && detectorType!=-1){
00135     Int_t totalHits=0;
00136     totalHits=
00137       unconnectedPixelCounter+
00138       unknownCounter+
00139       stripCounter+
00140       pinCounter+
00141       trigPmtCounter+
00142       commonModeCounter+
00143       triggerOrCounter+
00144       cerenkovCounter+
00145       tofCounter+
00146       timingFidCounter;
00147     
00148     MSG("LISummarySorter",Msg::kInfo) 
00149       <<endl 
00150       <<" ** Job Summary Information: **"<<endl
00151       <<"  Readout types processed:"<<endl
00152       <<"    kUnknown="<<unknownCounter<<endl      
00153       <<"    kScintStrip="<<stripCounter<<endl
00154       <<"    kUnconnectedPixel="<<unconnectedPixelCounter<<endl
00155       <<"    kPinDiode="<<pinCounter<<endl
00156       <<"    kFlashTrigPMT="<<trigPmtCounter<<endl
00157       <<"    kVACommonMode="<<commonModeCounter<<endl
00158       <<"    kTriggerOR="<<triggerOrCounter<<endl
00159       <<"    kCerenkov="<<cerenkovCounter<<endl
00160       <<"    kTOF="<<tofCounter<<endl
00161       <<"    kTimingFid="<<timingFidCounter<<endl
00162       <<"    Total hits="<<totalHits<<endl;
00163     
00164     if (totalHits!=0){
00165 
00166       MSG("LISummarySorter",Msg::kInfo) 
00167         <<endl
00168         <<"  Scintillator hits that were attributed to an LI pulse:" 
00169         <<endl
00170         <<"    Successful="<<goodHitCounter<<endl
00171         <<"    Failures="<<badHitCounter<<endl
00172         <<"    Sum of above=" 
00173         <<badHitCounter+goodHitCounter<<endl;
00174     
00175       //number of entries found for each pulser box
00176       totalHits=0;
00177       MSG("LISummarySorter",Msg::kInfo) 
00178         <<endl 
00179         <<"  Number of hits when a given pulser box was flashing:"<<endl;
00180       for (Int_t i=0;i<fLookup.NUMPULSERBOXES;i++){
00181         MSG("LISummarySorter",Msg::kInfo) 
00182           <<"    Pulser Box "<<i<<"=" 
00183           <<pulserBoxes[i]<<endl;
00184         totalHits+=pulserBoxes[i];
00185       }
00186       MSG("LISummarySorter",Msg::kInfo) 
00187         <<"    Total hits ="<<totalHits<<endl;
00188     
00189       //Plex results for pulser boxes
00190       totalHits=0;
00191       MSG("LISummarySorter",Msg::kInfo) 
00192         <<endl
00193         <<"  Plex results for pulser boxes:" 
00194         <<endl;
00195       for (Int_t i=0;i<fLookup.NUMPULSERBOXES;i++){
00196         MSG("LISummarySorter",Msg::kInfo) 
00197           <<"    Pulser Box "<<i<<"=" 
00198           <<plexPbCounter[i] 
00199           <<"    Opposite Pulser Box "<<i<<"=" 
00200           <<plexOppPbCounter[i] 
00201           <<endl;
00202         totalHits+=plexPbCounter[i];
00203       }
00204       MSG("LISummarySorter",Msg::kInfo) 
00205         <<"    Total hits ="<<totalHits<<endl;
00206     
00207       //number of entries found for each crate using plex
00208       totalHits=0;
00209       MSG("LISummarySorter",Msg::kInfo) 
00210         <<endl 
00211         <<"  Plex results for crates:"<<endl;
00212       for (Int_t i=0;i<fLookup.NUMCRATES;i++){
00213         MSG("LISummarySorter",Msg::kInfo) 
00214           <<"    Crate "<<i<<"=" 
00215           <<crates[i]<<endl;
00216         totalHits+=crates[i];
00217       }
00218       MSG("LISummarySorter",Msg::kInfo) 
00219         <<"  Total hits ="<<totalHits<<endl;
00220     
00221       //number of entries found for each led
00222       totalHits=0;
00223       MSG("LISummarySorter",Msg::kInfo) 
00224         <<endl<<"  Number of hits when a given led was flashing:"<<endl;
00225       for (Int_t i=0;i<fLookup.NUMLEDS;i++){
00226         MSG("LISummarySorter",Msg::kInfo) 
00227           <<"    led "<<i+1<<" = "<<leds[i]<<endl;
00228         totalHits+=leds[i];
00229       }
00230       MSG("LISummarySorter",Msg::kInfo) 
00231         <<"    Total hits = "<<totalHits<<endl;
00232 
00233       //number of reconstructed pins
00234       totalHits=0;
00235       MSG("LISummarySorter",Msg::kInfo) 
00236         <<endl<<"  Number of pins reconstructed:"<<endl;
00237       for (Int_t i=0;i<fLookup.NUMLEDS;i++){
00238         MSG("LISummarySorter",Msg::kInfo) 
00239           <<"    led "<<i+1<<" = "<<pinCounterReco[i]<<endl;
00240         totalHits+=pinCounterReco[i];
00241       }
00242 
00243       //change this bit for fpe problem
00244       MSG("LISummarySorter",Msg::kInfo) 
00245         <<"    Total reconstructed pins = "<<totalHits<<" of "
00246         <<pinCounter;
00247       if (pinCounter>0){
00248         MSG("LISummarySorter",Msg::kInfo) 
00249           <<" ("<<100.*totalHits/pinCounter<<"%)"<<endl;
00250       }
00251       else MSG("LISummarySorter",Msg::kInfo)<<endl;
00252 
00253       //number of summary blocks and summaries in those blocks    
00254       MSG("LISummarySorter",Msg::kInfo)  
00255         <<endl<<" Number of raw LI summary blocks found = "
00256         <<rawSummaryBlockCounter<<endl;     
00257       MSG("LISummarySorter",Msg::kInfo)   
00258         <<" Total number of raw LI summaries in above blocks = " 
00259         <<rawSummaryCounter<<endl; 
00260       MSG("LISummarySorter",Msg::kInfo)    
00261         <<" Average number of summaries per block = "  
00262         <<rawSummaryCounter/rawSummaryBlockCounter<<endl;  
00263     }//end of if totalHits
00264 
00265     MSG("LISummarySorter",Msg::kInfo) 
00266       <<endl<<" ** End of Job Summary Information: ** "<<endl; 
00267   }
00268   else {
00269     MSG("LISummarySorter",Msg::kInfo) 
00270       <<" ** No LI stream found in this file **"<<endl<<endl;
00271   }
00272 
00273   MSG("LISummarySorter",Msg::kVerbose) 
00274     <<"OutputData PrintRecoSummary finished"<<endl;
00275 }
00276 
00277 //......................................................................
00278   
00279 void LISummarySorter::OutputData()
00280 {
00281   MSG("LISummarySorter",Msg::kVerbose)
00282     <<"Running OutputData method..."<<endl;
00283 
00284   this->WriteFile(outputFile);
00285   this->CloseFile(outputFile);  
00286 
00287   MSG("LISummarySorter",Msg::kVerbose) 
00288     <<"OutputData method finished"<<endl;
00289 }
00290 
00291 //......................................................................
00292   
00293 void LISummarySorter::PrintBlockInfo(string preString) const
00294 {
00295   MSG("LISummarySorter",Msg::kVerbose)<<"PrintBlockInfo..."<<endl;
00296 
00297   if (time.GetSec()<1000){
00298     static Int_t numberMsg=0;
00299     if (numberMsg<10){
00300       MSG("LISummarySorter",Msg::kWarning) 
00301         <<"Number of seconds="<<time.GetSec()<<endl;
00302       if (numberMsg==9){
00303         MSG("LISummarySorter",Msg::kWarning) 
00304           <<endl
00305           <<"This is the last message of this type to be printed"
00306           <<endl;
00307       }
00308     }
00309     numberMsg++;
00310   }
00311   
00312   TDatime datime;
00313   datime.Set(time.GetSec());
00314   
00315   //play around with the formatting a little
00316   string sHour=Form("%d",datime.GetHour());
00317   string sMinute=Form("%d",datime.GetMinute());
00318   string sSecond=Form("%d",datime.GetSecond());
00319   string sMonth=Form("%d",datime.GetMonth());
00320   string sDay=Form("%d",datime.GetDay());
00321   if (datime.GetHour()<10) sHour="0"+sHour;
00322   if (datime.GetMinute()<10) sMinute="0"+sMinute;
00323   if (datime.GetSecond()<10) sSecond="0"+sSecond;
00324   if (datime.GetMonth()<10) sMonth="0"+sMonth;
00325   if (datime.GetDay()<10) sDay="0"+sDay;
00326 
00327   //protect from fpe
00328   Double_t pulseFreq=-1;
00329   if (period!=0) pulseFreq=ceil(1.0/(period*1.0e-5));
00330   string sPulseFreq=Form("%d",static_cast<Int_t>(pulseFreq));
00331   string sPeriod=Form("%d",static_cast<Int_t>(period));
00332   if (pulseFreq<0) sPulseFreq="??? (period="+sPeriod+")";
00333 
00334   MSG("LISummarySorter",Msg::kInfo) 
00335     <<preString 
00336     <<"PB="<<pulserBox 
00337     <<" Led="<<led
00338     <<" CP="<<calibPoint
00339     <<"/"<<calibType
00340     <<" PH="<<pulseHeight
00341     <<" PW="<<pulseWidth
00342     <<" PF="<<sPulseFreq
00343     <<" PN="<<pulses
00344     <<" at "<<sHour
00345     <<":"<<sMinute
00346     <<":"<<sSecond
00347     <<" on "<<datime.GetYear()
00348     <<"/"<<sMonth
00349     <<"/"<<sDay
00350     <<endl;
00351 
00352   MSG("LISummarySorter",Msg::kVerbose) 
00353     <<"PrintBlockInfo method finished"<<endl;
00354 }
00355 
00356 //......................................................................
00357 
00358 void LISummarySorter::SetLIVariables(Int_t new_led,
00359                                      Int_t new_pulseHeight,
00360                                      Int_t new_pulseWidth,
00361                                      Int_t new_pulserBox,
00362                                      Int_t new_calibPoint,
00363                                      VldTimeStamp new_time, 
00364                                      Int_t new_calibType,
00365                                      Int_t new_pulses,
00366                                      Int_t new_period)
00367 {
00368   //set summarySorters variables
00369   calibPoint=new_calibPoint;
00370   pulseHeight=new_pulseHeight;
00371   pulseWidth=new_pulseWidth;
00372   pulserBox=new_pulserBox;
00373   led=new_led;
00374   time=new_time;
00375   period=new_period;
00376   calibType=new_calibType;
00377   pulses=new_pulses; 
00378 }
00379 
00380 //......................................................................
00381 
00382 Bool_t LISummarySorter::Update(Int_t new_led,
00383                              Int_t new_pulseHeight,
00384                              Int_t new_pulseWidth,
00385                              Int_t new_pulserBox,
00386                              Int_t new_calibPoint,
00387                              VldTimeStamp new_time, 
00388                              Int_t new_calibType,
00389                              Int_t new_pulses,
00390                              Int_t new_period)
00391 {
00396   
00397   //this method gets called once for each raw summary block so
00398   //count the number of summary blocks here
00399   rawSummaryBlockCounter++;
00400 
00401   MSG("LISummarySorter",Msg::kVerbose)
00402     <<"Running LISummarySorter::Update method..."<<endl;
00403 
00404   if(led==-1){//it is initialised to -1
00405 
00406     MSG("LISummarySorter",Msg::kInfo) 
00407       <<"Initialising variables for LI settings in Update()"<<endl;
00408     
00409     //initialise the vector of LIChannels
00410     if (channels.size()==0){
00411       for (Int_t i=0;i<LILookup::NUMCRATES*LILookup::NUMCHADD;i++){
00412         channels.push_back(LIChannel());
00413       }
00414       MSG("LISummarySorter",Msg::kInfo) 
00415         <<"Vector of channels initialised to "
00416         <<LILookup::NUMCRATES*LILookup::NUMCHADD
00417         <<" (NUMCRATES="<<LILookup::NUMCRATES
00418         <<", NUMCHADD="<<LILookup::NUMCHADD<<")"
00419         <<endl; 
00420     }
00421     else{
00422       MSG("LISummarySorter",Msg::kInfo) 
00423         <<"Channels vector can't be initialised; already done!"<<endl;
00424     }
00425 
00426     this->SetLIVariables(new_led,new_pulseHeight,new_pulseWidth,
00427                          new_pulserBox,new_calibPoint,new_time,
00428                          new_calibType,new_pulses,new_period);
00429       
00430     this->PrintBlockInfo("First initialisation ");
00431     return false;//didn't update tree
00432   }
00433   // Write out data from previous led, pulse height, etc here
00434   else if(new_led!=led ||
00435           new_pulseHeight!=pulseHeight ||
00436           new_pulseWidth!=pulseWidth ||
00437           new_pulserBox!=pulserBox ||
00438           new_calibPoint!=calibPoint){
00439 
00440     //get an iterator to the map
00441     vector<LIChannel>::iterator chIt;
00442     chIt=channels.begin()-1;//so can increment straight away
00443     Int_t ch=-1;
00444 
00445     //loop over every possible channel
00446     while (chIt!=channels.end()){
00447 
00448       //increment the loop variables
00449       ch++;
00450       chIt++;
00451       MSG("LISummarySorterUltraVerbose",Msg::kVerbose) 
00452         <<"At beginning: Channel="<<ch<<endl;
00453 
00454       numEntries=channels[ch].GetNumEntries();      
00455       //check if channel was hit 
00456       if(numEntries==0) continue;
00457 
00458       //reset the variables and get the electronics info        
00459       this->ResetTreeVariables();
00460       this->GetElectronicsData(ch);
00461 
00462       //gather run statistics
00463       crates[crate]++;
00464       if (crate>fLookup.NUMCRATES || crate<0){
00465         MSG("LISummarySorter",Msg::kError) 
00466           <<"Crate out of range: crate="<<crate<<endl;
00467       }
00468 
00469       if (pulserBox<fLookup.NUMPULSERBOXES && pulserBox>=0 && 
00470           led<=fLookup.NUMLEDS && led>=1){
00471         pulserBoxes[pulserBox]++;
00472         leds[led-1]++;
00473       }
00474       else{
00475         static Int_t numberMsg=0;
00476         if (numberMsg<10){
00477           MSG("LISummarySorter",Msg::kError)
00478             <<"Pulser box or Led out of range: (PB,LED)=("<<pulserBox 
00479             <<","<<led<<")"<<endl;
00480           if (numberMsg==9){
00481             MSG("LISummarySorter",Msg::kError)
00482               <<endl
00483               <<"This is the last message of this type to be printed"
00484               <<endl;
00485           } 
00486         }
00487         numberMsg++;
00488       }
00489 
00490       //get readout type
00491       //      ReadoutType::Readout_t rt=plexHandle->
00492       //GetReadoutType(channels[ch]->GetChannelId());
00493       ReadoutType::Readout_t rt=plexHandle->
00494         GetReadoutType(chIt->GetChannelId());
00495       readoutType=static_cast<Int_t>(rt);//set tree variable
00496       MSG("LISummarySorter",Msg::kVerbose) 
00497         <<"rt="<<ReadoutType::AsString(rt)
00498         <<", mean="<<mean <<", rms="<<rms 
00499         <<", numEnt="<<numEntries 
00500         <<" "<<this->GetElecString()<<endl; 
00501 
00502       //check for dodgy channels
00503       if (rms==0 || numEntries==0 || mean==0){
00504         if (numEntries>10){
00505           if (readoutType==ReadoutType::kTOF ||
00506               readoutType==ReadoutType::kUnknown || 
00507               readoutType==ReadoutType::kTriggerOR){
00508             MSG("LISanityCheck",Msg::kVerbose) 
00509               <<" ** Channel with strange values: mean="<<mean 
00510               <<", rms="<<rms 
00511               <<", numEnt="<<numEntries 
00512               <<", rt="<<ReadoutType::AsString(rt)
00513               <<" "<<this->GetElecString()<<endl; 
00514           }
00515           else{
00516             //if (rms==0 && detectorType==Detector::kNear){
00517               //do nothing; too many of these with bad channels
00518             //}
00519             //else{
00520               MAXMSG("LISanityCheck",Msg::kInfo,50) 
00521                 <<"Writing out bad channel: mean="
00522                 <<(Int_t)mean 
00523                 <<", rms="<<rms 
00524                 <<", numEnt="<<numEntries 
00525                 <<", rt="<<ReadoutType::AsString(rt)
00526                 <<" "<<this->GetElecString()<<endl; 
00527               //}
00528           }
00529         }
00530       }
00531 
00532       //use the readout type to decide what to do
00533       //count the number of each type in file
00534       if (rt==ReadoutType::kUnknown){
00535         unknownCounter++;
00536       }
00537       else if (rt==ReadoutType::kUnconnectedPixel){
00538         unconnectedPixelCounter++;
00539       }
00540       else if (rt==ReadoutType::kScintStrip) {
00541         stripCounter++;
00542 
00543         //run the algorithm to correlate hits with flashes and 
00544         //determine the strip end
00545         this->ReconstructStripEnd(ch);
00546 
00547         //count hits that were attributed to an LI pulse        
00548         if (correlatedHit){
00549           goodHitCounter++;
00550         }
00551         else{
00552           badHitCounter++;
00553         }
00554       }//end of if
00555       else if (rt==ReadoutType::kPinDiode){
00556         pinCounter++;
00557         this->ReconstructPin(ch);
00558       }
00559       else if (rt==ReadoutType::kFlashTrigPMT){
00560         trigPmtCounter++;
00561         this->ReconstructTrigPmt();
00562       }
00563       else if (rt==ReadoutType::kVACommonMode){
00564         commonModeCounter++;
00565       }
00566       else if (rt==ReadoutType::kTriggerOR){
00567         triggerOrCounter++;
00568       }
00569       else if (rt==ReadoutType::kCerenkov){
00570         cerenkovCounter++;
00571       }
00572       else if (rt==ReadoutType::kTOF){
00573         tofCounter++;
00574       }
00575       else if (rt==ReadoutType::kTimingFid){
00576         timingFidCounter++;
00577       }
00578       else {
00579         MSG("LISummarySorter",Msg::kWarning) 
00580           <<"ReadoutType not defined:" 
00581           <<" rt="<<ReadoutType::AsString(rt)
00582           <<" "<<this->GetElecString()
00583           <<endl;
00584       }   
00585       //fill the tree with all the current data for this channel
00586       outtree->Fill();
00587     }//end of loop
00588 
00589     this->PrintBlockInfo("Wrote point: ");
00590 
00591     //reset all channels for next point
00592     for(UInt_t ch=0;ch<channels.size();ch++){
00593       channels[ch].Clean();       
00594     }
00595 
00596     //set the variables to be the new ones
00597     this->SetLIVariables(new_led,new_pulseHeight,new_pulseWidth,
00598                          new_pulserBox,new_calibPoint,new_time,
00599                          new_calibType,new_pulses,new_period);
00600     
00601     return true;//did update tree
00602   }//end of else if
00603 
00604   MSG("LISummarySorter",Msg::kVerbose)
00605     <<"Finished LISummarySorter::Update method..."<<endl;
00606   return false;//didn't update tree
00607 }
00608 
00609 //......................................................................
00610   
00611 void LISummarySorter::ResetTreeVariables()
00612 {
00613   //reset reconstructed tree variables
00614   //but not the LI pulser box settings
00615 
00616   //listed here for a checksum
00617   //   calibPoint=new_calibPoint;
00618   //   pulseHeight=new_pulseHeight;
00619   //   pulseWidth=new_pulseWidth;
00620   //   pulserBox=new_pulserBox;
00621   //   led=new_led;
00622   //   time=new_time;
00623   //   period=new_period;
00624   //   calibType=new_calibType;
00625   //   pulses=new_pulses;
00626   // 9 above but time is a struct and not directly in tree so only 8
00627     
00628   ashtray=-1;
00629   chAdd=-1;
00630   channel=-1;
00631   chip=-1;
00632   correlatedHit=0;
00633   crate=-1;
00634 
00635   //this only gets updated when you have a new led
00636   //so don't reset here
00637   //detectorType=-1;
00638 
00639   eastWest=-1;
00640   elecType=-1;
00641   farLed=-1;
00642   farPulserBox=-1;
00643   geoAdd=-1;
00644   inRack=-1;
00645   fMasterCh=-1;
00646   mean=-1.;
00647   fMinderCh=-1;
00648   nearLed=-1;
00649   nearPulserBox=-1;
00650   numEntries=-1;
00651   numericMuxBox=-1;
00652   fPe=-1;
00653   pixel=-1;
00654   pinGain=-1;
00655   pinInBox=-1;
00656   plane=-1;
00657   rackBay=-1;
00658   rackLevel=-1;
00659   readoutType=-1;
00660   rms=-1.;
00661 
00662   //these three only get updated when you have a new led etc
00663   //so don't reset here
00664   //runNumber=-1;
00665   //runNumberSub=-1;
00666   //runType=-1;
00667 
00668   strip=-1;
00669   fStripEnd=-1;
00670   summaryCounter=0;
00671   timestamp=-1;
00672   timestampNanoSec=-1;
00673   varc=-1;
00674   vfb=-1;
00675   vmm=-1;
00676 
00677   //38 variables above +fPe
00678   //+8 for pulser box settings
00679   //=46 altogether - same as number of branches in tree
00680 }
00681 
00682 //......................................................................
00683 
00684 void LISummarySorter::PrintBigMessage() const
00685 { 
00686   MSG("LISummarySorter",Msg::kInfo) 
00687     <<"("<<pulserBox<<":"<<led<<")";
00688     
00689   if (elecType==ElecType::kVA){
00690     MSG("LISummarySorter",Msg::kInfo) 
00691       <<"VA("<<crate<<","<<varc<<","<<vmm<<","<<vfb
00692       <<","<<chip<<","<<channel<<")";
00693   }
00694   else if (elecType==ElecType::kQIE){
00695     MSG("LISummarySorter",Msg::kInfo) 
00696       <<"QIE("<<crate<<","<<geoAdd<<","<<fMasterCh<<","<<fMinderCh<<")";
00697   }
00698   
00699   MSG("LISummarySorter",Msg::kInfo) 
00700     <<", (m,r,n)=("<<mean<<","<<rms
00701     <<","<<numEntries<<"), cHit="<<correlatedHit
00702     <<", e/w="<<eastWest<<", rt="<<readoutType
00703     <<" (Pl;St)=("<<plane<<";"<<strip<<")"<<endl;
00704 }
00705 
00706 //......................................................................
00707 
00708 string LISummarySorter::GetElecString() const 
00709 {
00710   MSG("LISummarySorter",Msg::kVerbose) 
00711     <<"Running GetElecString method..."<<endl;
00712 
00713   string elecString="";
00714   string sCrate=Form("%d",crate);
00715 
00716   if (elecType==ElecType::kVA){
00717     string sVarc=Form("%d",varc);
00718     string sVmm=Form("%d",vmm);
00719     string sVfb=Form("%d",vfb);
00720     string sChip=Form("%d",chip);
00721     string sChannel=Form("%d",channel);
00722     string sElecType="VA";
00723     
00724     elecString=sElecType+
00725       "("+sCrate+","+sVarc+","+sVmm+","+sVfb+","+sChip+","+sChannel+")";
00726   }     
00727   else if (elecType==ElecType::kQIE){
00728     string sGeoAdd=Form("%d",geoAdd);
00729     string sMasterCh=Form("%d",fMasterCh);
00730     string sMinderCh=Form("%d",fMinderCh);
00731     string sElecType="QIE";
00732     
00733     elecString=sElecType+
00734       "("+sCrate+","+sGeoAdd+","+sMasterCh+","+sMinderCh+")";
00735   }
00736   return elecString;
00737 }
00738 
00739 //......................................................................
00740 
00741 string LISummarySorter::GetElecString(RawChannelId rChId) const
00742 {
00743   MSG("LISummarySorter",Msg::kVerbose) 
00744     <<"Running GetElecString method..."<<endl;
00745 
00746   string elecString="";
00747   string sCrate=Form("%d",rChId.GetCrate());
00748   string sElecType=ElecType::AsString(rChId.GetElecType());
00749 
00750   if (rChId.GetElecType()==ElecType::kVA){
00751     string sVarc=Form("%d",rChId.GetVarcId());
00752     string sVmm=Form("%d",rChId.GetVmm());
00753     string sVfb=Form("%d",rChId.GetVaAdcSel());
00754     string sChip=Form("%d",rChId.GetVaChip());
00755     string sChannel=Form("%d",rChId.GetVaChannel());
00756 
00757     elecString=sElecType+
00758       "("+sCrate+","+sVarc+","+sVmm+","+sVfb+","+sChip+","+sChannel+")";
00759   }     
00760   else if (rChId.GetElecType()==ElecType::kQIE){
00761     string sGeoAdd=Form("%d",rChId.GetGeographicAddress());
00762     string sMasterCh=Form("%d",rChId.GetMasterChannel());
00763     string sMinderCh=Form("%d",rChId.GetMinderChannel());
00764         
00765     elecString=sElecType+
00766       "("+sCrate+","+sGeoAdd+","+sMasterCh+","+sMinderCh+")";
00767   }
00768   return elecString;
00769 }
00770 
00771 //......................................................................
00772 
00773 void LISummarySorter::GetElectronicsData(Int_t ch)
00774 {
00775   //get the raw channel id to use below
00776   RawChannelId rChId=channels[ch].GetChannelId();
00777 
00778   //get generic electronics stuff
00779   elecType=rChId.GetElecType();
00780   crate=rChId.GetCrate();
00781 
00782   //fardet stuff
00783   chAdd=rChId.GetChAdd();
00784   varc=rChId.GetVarcId();
00785   vmm=rChId.GetVmm();
00786   vfb=rChId.GetVaAdcSel();
00787   chip=rChId.GetVaChip();
00788   channel=rChId.GetVaChannel();  
00789 
00790   //neardet stuff
00791   fMasterCh=rChId.GetMasterChannel();
00792   fMinderCh=rChId.GetMinderChannel();
00793   geoAdd=rChId.GetGeographicAddress();
00794 
00795   //not strictly electronics!
00796   timestamp=static_cast<Int_t>(time.GetSec());
00797   timestampNanoSec=time.GetNanoSec();
00798   mean=channels[ch].GetMean();
00799   rms=channels[ch].GetRms();
00800   numEntries=channels[ch].GetNumEntries();
00801   summaryCounter=channels[ch].GetSummaryCounter();
00802 }
00803 
00804 //......................................................................
00805 
00806 void LISummarySorter::ReconstructStripEnd(Int_t ch)
00807 {
00810 
00838   MSG("LISummarySorter",Msg::kDebug) 
00839     <<"Reconstructing strip end..."<<endl;
00840 
00841   //Get strip-end alternative list
00842   PlexSEIdAltL altlist = plexHandle->
00843     GetSEIdAltL(channels[ch].GetChannelId());
00844   
00845   //the plane is known from the rawchannel so get it here
00846   plane=altlist.GetPlane();  
00847   MSG("LISummarySorter",Msg::kVerbose)
00848     <<"New altlist: plane="<<plane<<endl;
00849 
00850   //check that the plane view is kX, kY, kU or kV before reconstructing
00851   PlaneView::PlaneView_t planeView=altlist.GetPlaneView();  
00852   if (planeView>PlaneView::kV){
00853 
00854     Msg::LogLevel_t msgLevel=Msg::kDebug;
00855     //if (planeView>7 || planeView<7) msgLevel=Msg::kVerbose;
00856     
00857     MSG("LISummarySorter",msgLevel) 
00858       <<"Plane="<<plane
00859       <<", PlaneView="<<PlaneView::AsString(planeView)
00860       <<", therefore not reconstructing this plane"<<endl;
00861 
00862     //if (planeView==7) this->PrintBigMessage();
00863     //I am seeing some unknown views on vmm 5 in various crates???
00864 
00865     return;//don't reconstruct planes with no LI
00866   }
00867 
00868   //variable to sanity check reconstruction
00869   Int_t loopCounter=0;
00870   //hold true strip end id
00871   PlexStripEndId tmpSeid;
00872 
00874   //loop over the alternative strips
00876   for (PlexSEIdAltL::iterator it=altlist.begin(); 
00877        it!=altlist.end();it++){
00878 
00879     //set default values for led and pin plex variables
00880     Int_t plexLedInBox=-1;
00881     Int_t plexPulserBox=-1;
00882     Int_t plexOppLedInBox=-1;
00883     Int_t plexOppPulserBox=-1;
00884 
00885     //get strip end and opposite strip end id
00886     PlexStripEndId SEId=(*it).GetSEId();
00887     PlexStripEndId oppSEId=SEId.GetOppositeSEId();
00888 
00889     //get the temporary pixel of this possible strip
00890     //it is always the same for FD but 4 diff possibilites for ND
00891     PlexPixelSpotId plexPixelSpotId=plexHandle->GetPixelSpotId
00892       ((*it).GetSEId());
00893     //pixel is the same for all altSE
00894     Int_t tmpPixel=plexPixelSpotId.GetPixel();
00895 
00896     //a bit of sanity checking
00897     loopCounter++;
00898     if ((loopCounter>1 && detectorType==Detector::kCalDet) || 
00899         (loopCounter>8 && detectorType==Detector::kFar) ||
00900         (loopCounter>4 && detectorType==Detector::kNear)){
00901       MSG("LISummarySorter",Msg::kWarning) 
00902         <<"SEIdAltList has > 1 entry, loopCounter="<<loopCounter
00903         <<", CH="<<correlatedHit
00904         <<", end="<<SEId.GetEnd()
00905         <<", led="<<led
00906         <<", pl="<<plane
00907         <<", "<<this->GetElecString()<<endl;
00908     }
00909 
00910     //get ledIds for strip end and opp strip end
00911     PlexLedId ledId=plexHandle->GetLedId(SEId);       
00912     PlexLedId oppLedId=plexHandle->GetLedId(oppSEId);
00913 
00914     //sanity check that ledid is valid
00915     if (!ledId.IsValid()){
00916       MAXMSG("LISummarySorter",Msg::kWarning,20) 
00917         <<"LedId not valid, jumping to next SEId"
00918         << ", L="<<led
00919         << ", PB="<<pulserBox
00920         << ", pl="<<plane
00921         << ", mean="<<mean
00922         << endl;
00923       continue;
00924     }   
00925 
00926     //get pulserbox info for both sides
00927     plexPulserBox=ledId.GetPulserBox();   
00928     plexOppPulserBox=oppLedId.GetPulserBox();
00929     
00930     //these are the same for all alternative SEs
00931     nearPulserBox=plexPulserBox;
00932     farPulserBox=plexOppPulserBox;
00933     
00934     //get led number for both sides
00935     plexLedInBox=ledId.GetLedInBox();
00936     plexOppLedInBox=oppLedId.GetLedInBox();
00937     
00938     //reconstruct the strip for xtalk hits at CalDet and at ND forward
00939     //section (ND spectrometer is ambiguous due to 4 pixels=1 channel)
00940     if ((detectorType==Detector::kCalDet) ||
00941         (detectorType==Detector::kNear && 
00942          plane<LILookup::FIRSTSPECTROMETERPLANE)){
00943       //this is unambiguous at CalDet, so do it here for ALL hits
00944       //i.e. do it for xtalk too
00945       nearLed=plexLedInBox;
00946       farLed=plexOppLedInBox;
00947       strip=SEId.GetStrip();
00948       fStripEnd=SEId.GetEnd();
00949       
00950       MAXMSG("LISummarySorter",Msg::kDebug,200) 
00951         <<"XTalk reco: PB="<<pulserBox
00952         <<", pl="<<plane
00953         <<", s="<<strip
00954         <<", mean="<<mean
00955         <<endl;
00956     }  
00957 
00958     //determine whether to continue or not
00959     //ignore noise hits in crates not being flashed
00960     //there is no more information that can be determined for them
00961     //18-Sep-04: moved below section to allocate strips to ND forward
00962     //section
00963     if (plexPulserBox!=pulserBox && 
00964         plexOppPulserBox!=pulserBox) continue;
00965 
00966     //if (led==18){
00967     MSG("LISummarySorter",Msg::kDebug) 
00968       <<"pxL="<<plexLedInBox
00969       <<", L="<<led
00970       <<", pxPB="<<plexPulserBox
00971       <<", pxOpPB="<<plexOppPulserBox
00972       <<", PB="<<pulserBox
00973       <<", pl="<<plane
00974       <<", s="<<strip
00975       <<", sPlex="<<SEId.GetStrip()
00976       <<", pix="<<tmpPixel
00977       <<", mean="<<mean
00978       <<endl;
00979     //}
00980     //determine if it's a correlated hit    
00981     if ((pulserBox==nearPulserBox && led==plexLedInBox) ||
00982         (pulserBox==farPulserBox && led==plexOppLedInBox)){
00983 
00984       //sanity check 
00985       if (((nearLed>0 || farLed>0) && 
00986            detectorType!=Detector::kCalDet && 
00987            (detectorType!=Detector::kNear &&
00988             plane>=LILookup::FIRSTSPECTROMETERPLANE)) || 
00989           correlatedHit==1){
00990         //only do the led check if detector is not CalDet
00991         //otherwise check that leds have not already been set
00992         MAXMSG("LISummarySorter",Msg::kWarning,50) 
00993           <<"Overwritten near or far led during strip reconstruction"
00994           <<", correlatedHit="<<correlatedHit<<endl
00995           <<"led="<<led
00996           <<", oldnL="<<nearLed<<", newnL="<<plexLedInBox
00997           <<", oldfL="<<farLed<<", newfL="<<plexOppLedInBox
00998           <<", oldSt="<<strip<<", newSt="<<SEId.GetStrip()
00999           <<", pix="<<tmpPixel<<", pl="<<plane
01000           <<" "<<this->GetElecString()<<endl;
01001       }
01002       
01003       //if (led==18){
01004       MSG("LISummarySorter",Msg::kDebug) 
01005         <<"Found CorrelatedHit"<<endl
01006         <<"led="<<led
01007         <<", oldnL="<<nearLed<<", newnL="<<plexLedInBox
01008         <<", oldfL="<<farLed<<", newfL="<<plexOppLedInBox
01009         <<", oldSt="<<strip<<", newSt="<<SEId.GetStrip()
01010         <<", pix="<<tmpPixel<<", pl="<<plane
01011         <<" "<<this->GetElecString()<<endl;
01012       //}
01013       //count entries for pulserboxes
01014       plexPbCounter[plexPulserBox]++;
01015       plexOppPbCounter[plexOppPulserBox]++;
01016       
01017       //set more variables
01018       correlatedHit=1;
01019       strip=SEId.GetStrip();
01020       fStripEnd=SEId.GetEnd();
01021       //Int_t oppStrip=oppSEId.GetStrip();//just used for message below
01022       nearLed=plexLedInBox;
01023       farLed=plexOppLedInBox;  
01024       //note that strip, se, nearL and farL get set twice for correlated
01025       //hits in CalDet, but so what!
01026       //Less complicated than checking if CalDet or not
01027 
01028       //save the reconstructed seid
01029       tmpSeid=SEId;
01030     }//end of if
01031     
01032     //use the led to determine which ashtray was being illuminated
01033     //only set the variable if the channel is in the crate 
01034     //(or opposite crate) that is being illuminated
01035     if (pulserBox==nearPulserBox || pulserBox==farPulserBox){
01036       ashtray=fLookup.Led2Ashtray(led,plane,detectorType);
01037     }
01038   }//end of for
01039   
01041   //reconstruct the pixel and mux box info
01043   //get pixel spot id for strip end
01044   PlexPixelSpotId plexPixelSpotId;
01045   if (tmpSeid.IsValid()){
01046     plexPixelSpotId=plexHandle->GetPixelSpotId(tmpSeid);
01047     pixel=plexPixelSpotId.GetPixel();
01048   }
01049   else{
01050     //if a stripend wasn't reconstructed then just use the first
01051     //strip end in the altlist to get the pixel
01052     //even though it will only be one of the possible four in the ND
01053     plexPixelSpotId=plexHandle->GetPixelSpotId
01054       ((*altlist.begin()).GetSEId());
01055     pixel=plexPixelSpotId.GetPixel();
01056   }
01057   //set all the mux box variables
01058   this->GetMuxBoxInfo(plexPixelSpotId);
01059 
01060   MSG("LISummarySorter",Msg::kVerbose) 
01061     <<"ReconstructStripEnd method finished"<<endl;
01062 }
01063 
01064 //......................................................................
01065   
01066 Bool_t LISummarySorter::ReconstructPin(Int_t ch)
01067 {
01070 
01071   MSG("LISummarySorter",Msg::kVerbose) 
01072     <<"Reconstructing Pin..."<<endl;
01073 
01074   PlexPinDiodeId plexPinDiodeId=plexHandle->
01075     GetPinDiodeId(channels[ch].GetChannelId());
01076 
01077   //check if pin diode id is valid          
01078   if (!plexPinDiodeId.IsValid()){
01079     MSG("LISummarySorter",Msg::kWarning)
01080       <<"PIN diode id not valid"
01081       <<", LED="<<led<<", PB="<<pulserBox<<", pl="<<plane
01082       <<", mean="<<mean<<endl;    
01083     MSG("LISummarySorter",Msg::kVerbose) 
01084       <<"ReconstructPin method finished"<<endl;
01085     return false;
01086   }
01087 
01088   //get led id associated with actual pin diode hit
01089   PlexLedId plexLedId=plexHandle->GetLedId(plexPinDiodeId);
01090 
01091   //check if led id associated with pin is valid
01092   if (!plexLedId.IsValid()){
01093     MSG("LISummarySorter",Msg::kVerbose)
01094       <<"LedId obtained from pin not valid = "<<plexLedId.AsString()
01095       <<" "<<this->GetElecString()<<endl;
01096     MSG("LISummarySorter",Msg::kVerbose) 
01097       <<"ReconstructPin method finished"<<endl;
01098     return false;
01099   }
01100   
01101   //set nearLed to be the led that the plex associates with the pin
01102   nearLed=plexLedId.GetLedInBox();
01103   farLed=-1;// there is no far led for a pin!
01104   //get pulserbox info
01105   nearPulserBox=plexLedId.GetPulserBox();
01106   //there is no far pulser box associated with a pin diode 
01107   //but get it anyway since it is just the opposite one
01108   farPulserBox=fLookup.GetOppPb(pulserBox,detectorType);
01109   
01110   //quick sanity check
01111   if ((nearLed<fLookup.FIRSTLED || nearLed>fLookup.LASTLED) && 
01112       detectorType==Detector::kFar){
01113     MSG("LISummarySorter",Msg::kWarning)
01114       <<"Strange values for led = "<<nearLed
01115       <<" "<<this->GetElecString()<<endl;
01116   }
01117   
01118   pinInBox=plexPinDiodeId.GetInBox();
01119   pinGain=plexPinDiodeId.GetGain();
01120   
01121   MSG("LISummarySorter",Msg::kVerbose)  
01122     <<"plexPinDiodeId="<<plexPinDiodeId.AsString() 
01123     <<", inBox="<<pinInBox 
01124     <<", pinGain="<<pinGain<<endl;
01125   
01126   //set all the mux box variables
01127   this->GetMuxBoxInfo(plexPinDiodeId);
01128   
01129   //generate a plex led id to then get the two possible pins
01130   PlexLedId ledId;
01131   if (detectorType==Detector::kFar){
01132     ledId=PlexLedId(Detector::kFar,pulserBox,led); 
01133   }
01134   else if (detectorType==Detector::kNear){
01135     ledId=PlexLedId(Detector::kNear,pulserBox,led); 
01136   }
01137   else if (detectorType==Detector::kCalDet){
01138     ledId=PlexLedId(Detector::kCalDet,pulserBox,led); 
01139   }
01140   else {
01141     MSG("LISummarySorter",Msg::kFatal)
01142       <<"Detector type not known = "<<detectorType<<endl;
01143   }
01144   
01145   if (!ledId.IsValid()){
01146     MSG("LISummarySorter",Msg::kWarning)
01147       <<"LedId not valid = "<<ledId.AsString()<<endl;
01148   }
01149 
01150   //create a pair to hold the two possible pin diode ids
01151   pair<PlexPinDiodeId,PlexPinDiodeId> plexPins=plexHandle->
01152     GetPinDiodeIds(ledId);
01153   
01154   //first is gain=1, second is gain=0
01155   MSG("LISummarySorter",Msg::kVerbose) 
01156     <<"first pin gain="<<plexPins.first.GetGain()
01157     <<", second pin gain="<<plexPins.second.GetGain()<<endl;
01158   
01159   //get the pin diode id of the current pin
01160   PlexPinDiodeId currentPinId=plexHandle->
01161     GetPinDiodeId(channels[ch].GetChannelId());
01162 
01163   //get the planes associated with the pin diode
01164   pair<Int_t,Int_t> pinPlanes=fLookup.GetPinDiodePlanes(currentPinId,
01165                                                         plexHandle);
01166 
01167   //set the plane to be the first
01168   //at FD this is ok since the shared pmt is not used
01169   //at CD you can work it out since you always return the lower plane
01170   plane=pinPlanes.first;
01171 
01172   MSG("LISummarySorter",Msg::kVerbose)
01173     <<"PIN diode's associated plane="<<plane<<endl;
01174 
01175   //get the raw channel id of the plex pin for this 
01176   //led and pulser box combination to then compare with the
01177   //raw channel id of the actual pin being reconstructed
01178   pair<RawChannelId,RawChannelId> rawChanIds;
01179   //get chan ids of pins 
01180   rawChanIds.first=plexHandle->GetRawChannelId(plexPins.first);
01181   rawChanIds.second=plexHandle->GetRawChannelId(plexPins.second);
01182 
01183   //compare chan id of first pin
01184   if (rawChanIds.first.IsSameChannel(channels[ch].GetChannelId())){
01185     MSG("LISummarySorter",Msg::kVerbose)
01186       <<"PIN reconstructed: First pin="
01187       <<plexPins.first.AsString()<<endl
01188       <<"                         pin="
01189       <<plexPinDiodeId.AsString()<<endl;
01190     correlatedHit=1;
01191     pinCounterReco[led-1]++;
01192   }
01193   else{//compare the second possibility
01194     if (rawChanIds.second.IsSameChannel(channels[ch].GetChannelId())){
01195       MSG("LISummarySorter",Msg::kVerbose) 
01196         <<"PIN reconstructed: Second pin="<<
01197         plexPins.second.AsString()<<endl
01198         <<"                          pin="<<
01199         plexPinDiodeId.AsString()<<endl;
01200       correlatedHit=1;
01201       pinCounterReco[led-1]++;
01202     }
01203   }
01204 
01205   //print out pin info of non-reconstructed pins
01206   if (correlatedHit!=1){
01207     MSG("LISummarySorter",Msg::kVerbose) 
01208       <<endl<<"PIN not reconstructed, noise hit"
01209       <<", pin="<<plexPinDiodeId.AsString()<<endl;
01210   }
01211 
01212   MSG("LISummarySorter",Msg::kVerbose) 
01213     <<"ReconstructPin method finished"<<endl;
01214   if (correlatedHit==1) return true;
01215   else return false;
01216 }
01217 
01218 //......................................................................
01219 
01220 void LISummarySorter::ReconstructTrigPmt() 
01221 {
01222   MSG("LISummarySorter",Msg::kVerbose) 
01223     <<"Reconstructing Trigger Pmt..."<<endl;
01224 
01225   if (channel==fLookup.Pb2TrigPmtChannel(pulserBox,detectorType)){
01226     nearPulserBox=pulserBox;
01227     //there is no far pulser box associated with a trig pmt hit
01228     //but get it anyway
01229     farPulserBox=fLookup.GetOppPb(pulserBox,detectorType);
01230     correlatedHit=1;
01231   }
01232 
01233   if (fLookup.Pb2TrigPmtChannel(pulserBox,detectorType)==-1){
01234     this->PrintBigMessage();
01235   }
01236   
01237   MSG("LISummarySorter",Msg::kVerbose)
01238     <<"ReconstructTrigPmt method finished"<<endl;
01239 }
01240 
01241 //......................................................................
01242 
01243 void LISummarySorter::GetMuxBoxInfo(PlexPinDiodeId plexPinDiodeId) 
01244 {
01245   MSG("LISummarySorter",Msg::kVerbose) 
01246     <<"Getting mux box info..."<<endl;
01247 
01248     rackBay=static_cast<Int_t>(plexPinDiodeId.GetRackBay());
01249     inRack=static_cast<Int_t>(plexPinDiodeId.GetInRack());
01250     numericMuxBox=static_cast<Int_t>
01251       (plexPinDiodeId.GetNumericMuxBox());
01252     const Char_t eastWestChar=plexPinDiodeId.GetEastWest();
01253     const Char_t rackLevelChar=plexPinDiodeId.GetRackLevel();
01254     string sEastWest=static_cast<string>(&eastWestChar);
01255     sEastWest=sEastWest[0];//sometimes has two characters
01256     string sRackLevel=static_cast<string>(&rackLevelChar);
01257     sRackLevel=sRackLevel[0];
01258     
01259     //translate eastWest string to an integer
01260     eastWest=fLookup.ConvertEastWest(sEastWest);
01261     if (eastWest==-1) {
01262       MSG("LISummarySorter",Msg::kWarning) 
01263         << "plexPinDiodeId="<<plexPinDiodeId.AsString()
01264         << ", eastWest="<<sEastWest
01265         << ", length="<<sEastWest.size()
01266         << ", 1st="<<sEastWest[0]
01267         << ", 2nd="<<sEastWest[1]
01268         << endl;
01269     }
01270          
01271     //translate rackLevel string to an integer
01272     rackLevel=fLookup.ConvertRackLevel(sRackLevel);
01273     if (rackLevel==-1){
01274       MSG("LISummarySorter",Msg::kWarning) 
01275         << "plexPinDiodeId="<<plexPinDiodeId.AsString()
01276         << ", rackLevel="<<sRackLevel 
01277         << ", length="<<sRackLevel.size()
01278         << ", 1st="<<sRackLevel[0]
01279         << ", 2nd="<<sRackLevel[1]
01280         << endl;
01281     }      
01282 
01283   MSG("LISummarySorter",Msg::kVerbose)
01284     <<"Finished getting mux box info"<<endl;
01285 }
01286 
01287 //......................................................................
01288 
01289 void LISummarySorter::GetMuxBoxInfo(PlexPixelSpotId plexPixelSpotId) 
01290 {
01291   MSG("LISummarySorter",Msg::kVerbose) 
01292     <<"Getting mux box info..."<<endl;
01293 
01294     rackBay=static_cast<Int_t>(plexPixelSpotId.GetRackBay());
01295     inRack=static_cast<Int_t>(plexPixelSpotId.GetInRack());
01296     numericMuxBox=static_cast<Int_t>
01297       (plexPixelSpotId.GetNumericMuxBox());
01298     const Char_t eastWestChar=plexPixelSpotId.GetEastWest();
01299     const Char_t rackLevelChar=plexPixelSpotId.GetRackLevel();
01300     string sEastWest=static_cast<string>(&eastWestChar);
01301     sEastWest=sEastWest[0];//sometimes has two characters
01302     string sRackLevel=static_cast<string>(&rackLevelChar);
01303     sRackLevel=sRackLevel[0];
01304     
01305     //translate eastwest string to an integer
01306     eastWest=fLookup.ConvertEastWest(sEastWest);
01307     if (eastWest==-1) {
01308       MSG("LISummarySorter",Msg::kWarning) 
01309         <<"plexPixelSpotId="<<plexPixelSpotId.AsString()
01310         <<", eastWest="<<sEastWest
01311         <<", length="<<sEastWest.size()
01312         <<", 1st="<<sEastWest[0]
01313         <<", 2nd="<<sEastWest[1]
01314         << endl;
01315     }
01316               
01317     //translate rackLevel string to an integer
01318     rackLevel=fLookup.ConvertRackLevel(sRackLevel);
01319     if (rackLevel==-1){
01320       MSG("LISummarySorter",Msg::kWarning) 
01321         <<"plexPixelSpotId="<<plexPixelSpotId.AsString()
01322         <<", rackLevel="<<sRackLevel 
01323         <<",size="<<sRackLevel.size()
01324         <<",1s="<<sRackLevel[0]
01325         <<",2s="<<sRackLevel[1]
01326         << endl;
01327     }      
01328 
01329   MSG("LISummarySorter",Msg::kVerbose)
01330     <<"Finished getting mux box info"<<endl;
01331 }
01332 
01333 //......................................................................
01334 
01335 void LISummarySorter::AddEntry(RawChannelId channelId,
01336                                Float_t mean,
01337                                Float_t rms,
01338                                Int_t numEntries)
01339 {
01340   //initialise the tree if the first time (also opens file)
01341   if (!outtree) this->InitialiseTree();
01342 
01343   Int_t ch=channelId.GetCrate()*fLookup.NUMCHADD+channelId.GetChAdd();
01344   
01345   MSG("LISummarySorterUltraVerbose",Msg::kVerbose) 
01346     <<"ch="<<ch<<", ChAdd="<<channelId.GetChAdd()<<endl;
01347 
01348   //set the channelId of the channel
01349   channels[ch].SetChannelId(channelId);
01350   
01351   //this is deliberately LIChannel type message
01352   MSG("LIChannel",Msg::kVerbose) 
01353     <<this->GetElecString(channels[ch].GetChannelId())<<endl;
01354 
01356   //do I really want to add zero channels????
01357   //maybe just add the channel once, so it appears in the tree?
01358   //probably just put everything in there!
01360 
01361   string msgPrefix="Used Summary w/ strange values ";
01362 
01363   //add the means and rms to the running total
01364   channels[ch].AddEntry(numEntries,mean,rms); 
01365 
01366   //do some sanity checking that there are no strange entries
01367   if (mean==0 || numEntries==0){
01368     //get the raw channel id to use below
01369     RawChannelId rChId=channels[ch].GetChannelId();
01370     
01371     //have to get the readout type since it wont have been set for the
01372     //first point
01373     if (plexHandle->GetReadoutType(channels[ch].GetChannelId())==
01374         ReadoutType::kTOF || 
01375         plexHandle->GetReadoutType(channels[ch].GetChannelId())==
01376         ReadoutType::kUnknown || 
01377         plexHandle->GetReadoutType(channels[ch].GetChannelId())==
01378         ReadoutType::kTriggerOR
01379         ){
01380 
01381       //these often have zero mean but finite num entries at caldet
01382       MAXMSG("LISanityCheck",Msg::kVerbose,50) 
01383         <<msgPrefix
01384         <<"numHits="<<numEntries
01385         <<", mean="<<static_cast<Int_t>(mean)
01386         <<", rms="<<static_cast<Int_t>(rms)
01387         <<", rt="<<ReadoutType::AsString(plexHandle->GetReadoutType
01388                                          (channels[ch].GetChannelId()))
01389         <<" "<<this->GetElecString(rChId)<<endl;
01390     }
01391     else{
01392       MAXMSG("LISanityCheck",Msg::kWarning,50) 
01393         <<msgPrefix
01394         <<"numHits="<<numEntries
01395         <<", mean="<<static_cast<Int_t>(mean)
01396         <<", rms="<<static_cast<Int_t>(rms)
01397         <<", rt="<<ReadoutType::AsString(plexHandle->GetReadoutType
01398                                          (channels[ch].GetChannelId()))
01399         <<" "<<this->GetElecString(rChId)<<endl;
01400     }
01401   }
01402   //check that there are no strange zero rms channels
01403   else if (rms==0){
01404     //get the raw channel id to use below
01405     RawChannelId rChId=channels[ch].GetChannelId();
01406     
01407     if (numEntries>=6){
01408       MAXMSG("LISanityCheck",Msg::kInfo,50) 
01409         <<msgPrefix
01410         <<"numHits="<<numEntries
01411         <<", adc="<<static_cast<Int_t>(mean)
01412         <<", rms="<<static_cast<Int_t>(rms)
01413         <<", rt="<<ReadoutType::AsString(plexHandle->GetReadoutType
01414                                          (channels[ch].GetChannelId()))
01415         <<" "<<this->GetElecString(rChId)<<endl;
01416     }
01417     else if (numEntries>=5){
01418       MAXMSG("LISanityCheck",Msg::kDebug,50) 
01419         <<msgPrefix
01420         <<"numHits="<<numEntries
01421         <<", mean="<<static_cast<Int_t>(mean)
01422         <<", rms="<<static_cast<Int_t>(rms)
01423         <<", rt="<<ReadoutType::AsString(plexHandle->GetReadoutType
01424                                          (channels[ch].GetChannelId()))
01425         <<" "<<this->GetElecString(rChId)<<endl;
01426     }
01427     else if (numEntries>=4){
01428       MAXMSG("LISanityCheck",Msg::kVerbose,50) 
01429         <<msgPrefix
01430         <<"numHits="<<numEntries
01431         <<", mean="<<static_cast<Int_t>(mean)
01432         <<", rms="<<static_cast<Int_t>(rms)
01433         <<", rt="<<ReadoutType::AsString(plexHandle->GetReadoutType
01434                                          (channels[ch].GetChannelId()))
01435         <<" "<<this->GetElecString(rChId)<<endl;
01436     }
01437   }
01438 }
01439 
01440 //......................................................................
01441  
01442 void LISummarySorter::InitialiseTree()
01443 {
01444   //open the file, doing this before the tree is created 
01445   //ensures tree is written to disk as it is created
01446   outputFile=this->OpenFile(runNumber,runNumberSub,detectorType);
01447 
01448   outtree = new TTree("li_tree","li_tree");
01449   
01450   //set tree branches  
01451   outtree->Branch("ashtray",&ashtray,"ashtray/I",32000);
01452   outtree->Branch("calibPoint",&calibPoint,"calibPoint/I",32000);
01453   outtree->Branch("calibType",&calibType,"calibType/I",32000);
01454   outtree->Branch("chAdd",&chAdd,"chAdd/I",32000);
01455   outtree->Branch("channel",&channel,"channel/I",32000);
01456   //
01457   outtree->Branch("chip",&chip,"chip/I",32000);
01458   outtree->Branch("correlatedHit",&correlatedHit,
01459                   "correlatedHit/I",32000);
01460   outtree->Branch("crate",&crate,"crate/I",32000);
01461   outtree->Branch("detectorType",&detectorType,"detectorType/I",32000); 
01462   outtree->Branch("eastWest",&eastWest,"eastWest/I",32000);
01463   //  
01464   outtree->Branch("elecType",&elecType,"elecType/I",32000);
01465   outtree->Branch("farLed",&farLed,"farLed/I",32000);
01466   outtree->Branch("farPulserBox",&farPulserBox,"farPulserBox/I",32000);
01467   outtree->Branch("geoAdd",&geoAdd,"geoAdd/I",32000);
01468   outtree->Branch("inRack",&inRack,"inRack/I",32000);
01469   //
01470   outtree->Branch("led",&led,"led/I",32000);
01471   outtree->Branch("masterCh",&fMasterCh,"masterCh/I",32000);
01472   outtree->Branch("mean",&mean,"mean/F",32000);
01473   outtree->Branch("minderCh",&fMinderCh,"minderCh/I",32000);
01474   outtree->Branch("nearLed",&nearLed,"nearLed/I",32000);
01475   //
01476   outtree->Branch("nearPulserBox",&nearPulserBox,
01477                   "nearPulserBox/I",32000);
01478   outtree->Branch("numEntries",&numEntries,"numEntries/I",32000);
01479   outtree->Branch("numericMuxBox",&numericMuxBox,
01480                   "numericMuxBox/I",32000);
01481   outtree->Branch("pe",&fPe,"pe/I",32000);
01482 
01483   outtree->Branch("period",&period,"period/I",32000);
01484   //
01485   outtree->Branch("pinGain",&pinGain,"pinGain/I",32000);
01486   outtree->Branch("pinInBox",&pinInBox,"pinInBox/I",32000);
01487   outtree->Branch("pixel",&pixel,"pixel/I",32000);
01488   outtree->Branch("plane",&plane,"plane/I",32000);
01489   outtree->Branch("pulseHeight",&pulseHeight,"pulseHeight/I",32000);
01490   //
01491   outtree->Branch("pulserBox",&pulserBox,"pulserBox/I",32000); 
01492   outtree->Branch("pulses",&pulses,"pulses/I",32000);
01493   outtree->Branch("pulseWidth",&pulseWidth,"pulseWidth/I",32000);
01494   outtree->Branch("rackBay",&rackBay,"rackBay/I",32000);
01495   outtree->Branch("rackLevel",&rackLevel,"rackLevel/I",32000);
01496   //
01497   outtree->Branch("readoutType",&readoutType,"readoutType/I",32000);
01498   outtree->Branch("rms",&rms,"rms/F",32000);
01499   outtree->Branch("runNumber",&runNumber,"runNumber/I",32000);
01500   outtree->Branch("runNumberSub",&runNumberSub,"runNumberSub/I",32000);
01501   outtree->Branch("runType",&runType,"runType/I",32000);
01502   //
01503   outtree->Branch("strip",&strip,"strip/I",32000);
01504   outtree->Branch("stripEnd",&fStripEnd,"stripEnd/I",32000);
01505   outtree->Branch("summaryCounter",&summaryCounter,
01506                   "summaryCounter/I",32000);
01507   outtree->Branch("timestamp",&timestamp,"timestamp/I",32000);
01508   outtree->Branch("varc",&varc,"varc/I",32000);
01509   //
01510   outtree->Branch("vfb",&vfb,"vfb/I",32000);
01511   outtree->Branch("vmm",&vmm,"vmm/I",32000);//this is branch number 47 
01512 }
01513 
01514 //......................................................................
01515 
01516 TFile* LISummarySorter::OpenFile(Int_t runNumber,Int_t runNumberSub,
01517                                  Int_t detectorType)
01518 {
01519   TFile *outputFile=0;
01520 
01521   string sRunNumber=Form("%d",runNumber);
01522   string sRunNumberSub=Form("%d",runNumberSub);
01523   string sDetector="";
01524   if (detectorType==static_cast<Int_t>(Detector::kFar)){
01525     sDetector="F";
01526   }
01527   else if (detectorType==static_cast<Int_t>(Detector::kNear)){
01528     sDetector="N"; 
01529   }
01530   else if (detectorType==static_cast<Int_t>(Detector::kCalDet)){
01531     sDetector="C"; 
01532   }
01533   else{
01534     sDetector="TypeNotKnown"; 
01535   }
01536   string sZeros="";
01537   string sZeros2="";
01538 
01539   if (runNumber>=0 && runNumber<10) sZeros="00000000";
01540   else if (runNumber>=10 && runNumber<100) sZeros="000000";
01541   else if (runNumber>=100 && runNumber<1000) sZeros="00000";
01542   else if (runNumber>=1000 && runNumber<10000) sZeros="0000";
01543   else if (runNumber>=10000 && runNumber<100000) sZeros="000";
01544   else if (runNumber>=100000 && runNumber<1000000) sZeros="00";
01545   else if (runNumber>=1000000 && runNumber<10000000) sZeros="0";
01546   else if (runNumber>=10000000 && runNumber<100000000) sZeros="";
01547 
01548   if (runNumberSub>=0 && runNumberSub<10) sZeros2="000";
01549   else if (runNumberSub>=10 && runNumberSub<100) sZeros2="00";
01550   else if (runNumberSub>=100 && runNumberSub<1000) sZeros2="0";
01551   else if (runNumberSub>=1000 && runNumberSub<10000) sZeros2="";
01552 
01553   string sFileName="LIData"+sDetector+sZeros+sRunNumber+"_"+
01554     sZeros2+sRunNumberSub+".root";
01555 
01556   //test if file already exists
01557   ifstream Test(sFileName.c_str());
01558 
01559   if(!Test){
01560     outputFile= new TFile(sFileName.c_str(),"NEW");
01561   }
01562   else {
01563     //Need new filename
01564     Int_t fred=1;
01565     while(Test) {
01566       Test.close();
01567       string sAppendage=Form("%d",fred);
01568       sFileName="LIData"+sDetector+sZeros+sRunNumber+"_"+
01569         sZeros2+sRunNumberSub+"_"+sAppendage+".root";
01570       Test.open(sFileName.c_str());
01571       fred++;
01572     }
01573     outputFile = new TFile(sFileName.c_str(),"NEW");
01574     outputFile->SetCompressionLevel(9);
01575   }
01576   MSG("LISummarySorter",Msg::kInfo) 
01577     <<" ** Output file opened: "<<sFileName<<" ** "<<endl;
01578   return outputFile;
01579 }
01580 
01581 //......................................................................
01582 
01583 void LISummarySorter::WriteFile(TFile* outfile)
01584 {
01585   if (outfile && outtree){
01586     MSG("LISummarySorter",Msg::kInfo)<<"Writing out tree..."<<endl;
01587     outfile->cd();
01588     outtree->Write();
01589     delete outtree;  
01590     MSG("LISummarySorter",Msg::kInfo) 
01591       <<"Tree written and deleted"<<endl;
01592   }
01593   else {
01594     MSG("LISummarySorter",Msg::kWarning)
01595       <<"Can't write out tree (outtree="<<outtree
01596       <<", outfile="<<outfile<<")"<<endl;
01597   }
01598 }
01599 
01600 //......................................................................
01601 
01602 void LISummarySorter::CloseFile(TFile* outfile)
01603 {
01604   if (outfile){
01605     MSG("LISummarySorter",Msg::kInfo)<<"Closing output file..."<<endl;
01606     outfile->Close();
01607     MSG("LISummarySorter",Msg::kInfo)<<"Output file closed"<<endl;
01608   }
01609   else{
01610     MSG("LISummarySorter",Msg::kWarning)
01611       <<"Can't close file: outfile="<<outfile<<endl;
01612   }
01613 }
01614 
01615 //......................................................................
01616 
01617 void LISummarySorter::SetPlexHandle(VldContext vldC)
01618 {
01619   MSG("LISummarySorter",Msg::kVerbose) 
01620     <<"Setting new validity context for plex handle..."<<endl;
01621 
01622   MSG("LISummarySorter",Msg::kDebug)
01623     <<"Input to SetPlexHandle() VldC="<<vldC.AsString()<<endl;
01624   
01625   if (vldC.GetTimeStamp().GetSec()==0){
01626     static Int_t numberMsg=0;
01627     if (numberMsg<2){
01628       MSG("LISummarySorter",Msg::kWarning)
01629         <<endl<<endl
01630         <<"************************* WARNING ********************"<<endl
01631         <<"* Number of seconds in summary block=0"<<endl
01632         <<"* Using RawDaqHeader timestamp to create"<<endl
01633         <<"* plex handle instead"<<endl
01634         <<"******************************************************"<<endl
01635         <<endl;
01636     }
01637     numberMsg++;
01638 
01639     const VldTimeStamp ts=fRawDaqVldCtx.GetTimeStamp();
01640 
01641     //print the timestamp if verbose
01642     if (MsgService::Instance()->IsActive("LISummarySorter",
01643                                          Msg::kVerbose)){
01644       MSG("LISummarySorter",Msg::kInfo) 
01645         <<"Using VldTimeStamp="<<endl;
01646       ts.Print();
01647     }
01648     
01649     VldContext hackedVldC(vldC.GetDetector(),SimFlag::kData,ts);
01650     
01651     MSG("LISummarySorter",Msg::kDebug) 
01652       <<"After setting plex handle using VldC="
01653       <<hackedVldC.AsString()<<endl; 
01654     
01655     //check if the validity context is valid then create the plex handle
01656     if (hackedVldC.IsValid()){
01657 
01658       //delete the plex handle if it already exists
01659       if (plexHandle){
01660         delete plexHandle;
01661       }
01662       //create a new plex handle
01663       plexHandle=new PlexHandle(hackedVldC); 
01664     }
01665     else{
01666       MSG("LISummarySorter",Msg::kFatal) 
01667         <<"Validity context not valid="<<vldC.AsString()<<endl;
01668       exit(1);
01669     }
01670   }
01671   else{ 
01672     //check if the validity context is valid then create the plex handle
01673     if (vldC.IsValid()){
01674 
01675       //delete the plex handle if it already exists
01676       if (plexHandle){
01677         delete plexHandle;
01678       }
01679 
01680       //create a new plex handle
01681       plexHandle=new PlexHandle(vldC); 
01682       
01683       //get validity range
01684       VldRange myVldRange=plexHandle->GetVldRange();
01685       MSG("LISummarySorter",Msg::kVerbose)
01686         <<"Range TimeStart="<<myVldRange.GetTimeStart().AsString()<<endl
01687         <<"Range TimeEnd="<<myVldRange.GetTimeEnd().AsString()<<endl
01688         <<"Compatible="<<myVldRange.IsCompatible(vldC)<<endl;
01689     }
01690     else{
01691       MSG("LISummarySorter",Msg::kFatal) 
01692         <<"Validity context not valid="<<vldC.AsString()<<endl;
01693       exit(1);
01694     }
01695   }
01696   
01697   MSG("LISummarySorter",Msg::kVerbose) 
01698     <<"Finished setting new validity context for plex handle"<<endl;
01699 }
01700 
01701 //......................................................................
01702 
01703 void LISummarySorter::SetRawDaqVldCtx(VldContext vldC) 
01704 { 
01705   MSG("LISummarySorter",Msg::kVerbose)  
01706     <<"Setting RawDaqVldCtx"<<endl; 
01707  
01708   MSG("LISummarySorter",Msg::kDebug) 
01709     <<"Input to SetRawDaqVldCtx() VldC="<<vldC.AsString()<<endl; 
01710    
01711   //check if the validity context is valid 
01712   if (vldC.IsValid()){
01713     fRawDaqVldCtx=vldC;
01714   } 
01715   else{ 
01716     MSG("LISummarySorter",Msg::kWarning)  
01717       <<"Validity context not valid = "<<vldC.AsString()
01718       <<endl<<"Could not set fRawDaqVldCtx"<<endl; 
01719   } 
01720  
01721   MSG("LISummarySorter",Msg::kVerbose)  
01722     <<"Finished SetRawDaqVldCtx method"<<endl; 
01723 } 
01724 
01725 //......................................................................
01726 
01727 void LISummarySorter::SetDetector(VldContext vldC) 
01728 { 
01729   MSG("LISummarySorter",Msg::kVerbose)  
01730     <<"Setting detector type..."<<endl; 
01731  
01732   MSG("LISummarySorter",Msg::kDebug) 
01733     <<"Argument of SetDetector: VldC="<<vldC.AsString()<<endl; 
01734    
01735   //check if the validity context is valid 
01736   if (vldC.IsValid()){
01737 
01738     detectorType=static_cast<Int_t>(vldC.GetDetector()); 
01739     MSG("LISummarySorter",Msg::kDebug) 
01740       <<"Detector Type "<<detectorType<<" found"<<endl;
01741 
01742     //set the detector specific variables only once
01743     static Bool_t detNotSet=true;
01744     if (detNotSet){
01745       fLookup.SetDetector(detectorType);
01746       detNotSet=false;
01747     }
01748   } 
01749   else{ 
01750     MSG("LISummarySorter",Msg::kWarning)  
01751       <<"Validity context not valid = "<<vldC.AsString()
01752       <<endl<<"Could not set detector type"<<endl; 
01753   } 
01754  
01755   MSG("LISummarySorter",Msg::kVerbose)  
01756     <<"Finished SetDetector method"<<endl; 
01757 } 
01758  
01759 //......................................................................

Generated on Fri Mar 28 15:34:16 2008 for loon by  doxygen 1.3.9.1