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

PEGainModule.cxx

Go to the documentation of this file.
00001 
00002 
00004 #include <cstdio>
00005 #include <fstream>
00006 // ROOT includes
00007 #include "TFile.h"
00008 #include "TH2.h"
00009 #include "TCanvas.h"
00010 #include "TStyle.h"
00011 #include "TMultiGraph.h"
00012 #include "TGraphErrors.h"
00013 // MINOS includes
00014 #include "MessageService/MsgService.h"     // MSG text output
00015 #include "MinosObjectMap/MomNavigator.h"   // Data access
00016 #include "CandData/CandRecord.h"           // DigitList handling
00017 #include "CandDigit/CandDigitListHandle.h" // "                "
00018 #include "CandDigit/CandDigitHandle.h"     // "                "
00019 #include "JobControl/JobCommand.h"         // JobCommand handling
00020 #include "JobControl/JobCModuleRegistry.h" // JOBMODULE registration macro
00021 #include "RawData/RawDaqSnarlHeader.h"
00022 #include "RawData/RawSnarlHeaderBlock.h"
00023 #include "RawData/RawRecord.h"
00024 #include "RawData/RawDigitDataBlock.h"
00025 #include "PulserCalibration/PulserSummaryList.h"
00026 #include "PulserCalibration/PulserFromRawSummaryList.h"
00027 #include "PulserCalibration/PulserSummary.h"
00028 #include "PEGain/PEGainModule.h"
00029 #include "PEGain/PEGainMuxBox.h"
00030 #include "Plex/PlexStripEndId.h"
00031 #include "Plex/PlexHandle.h"
00032 #include "RawData/RawChannelId.h"
00033 #include "RawData/RawDigit.h"
00034 #include "Conventions/StripEnd.h"
00035 #include "Conventions/Detector.h"
00036 #include "Conventions/SimFlag.h"
00037 #include "DatabaseInterface/DbiWriter.h"
00038 #include "Validity/VldContext.h"
00039 #include "Validity/VldRange.h"
00040 #include "Validity/VldTimeStamp.h"
00041 #include "Plex/PlexStripEndToLed.h"
00042 #include "Plex/PlexPinDiodeToLed.h"
00043 #include <set>
00044 #include <vector>
00045 //include "PEGain/PEGainFitter.h"
00046 
00047 
00048 
00049 ClassImp(PEGainModule)
00050 
00051 CVSID("$Id: PEGainModule.cxx,v 1.11 2007/11/11 05:44:59 rhatcher Exp $");
00052 JOBMODULE(PEGainModule,"PEGainModule","Compute and record total charge\n");
00053 
00054 //......................................................................
00055 
00056 //......................................................................
00057 
00058 PEGainModule::PEGainModule()
00059    :fRun(-1),doingBox(-1),doingLed(-1),doingHeight(-1),
00060     doingPinBox(-1),doingPinLed(-1),doingPinHeight(-1),doingPinWidth(-1)
00061 {
00062 //======================================================================
00063 // Set the initial state of your module. The code above initializes the
00064 // variables listed to the values in parentheses. In this case that's
00065 // all I need to do so the method itself is empty...
00066 //======================================================================
00067     fDoAllStrips=0;
00068     fDoDebugTree=0;
00069     fJustAnalyse=0;
00070     fDontAnalyse=0;
00071     fUseFromRawSummaries=0;
00072     fAnalyseRunNumber=0;
00073     fJustMakeTree=0;
00074     fTriggers=0;
00075     fRecoFile = 0;
00076     fFile = 0;
00077     fDebugFile = 0;
00078     for(int i=0;i<2880;i++) hists[i] = 0;
00079 
00080 }
00081 
00082 //......................................................................
00083 void PEGainModule::HandleCommand(JobCommand *command) 
00084 {
00085    
00086 // Process configuration commands
00087    TString cmd = command->PopCmd();
00088 
00089    MSG("PEGain", Msg::kDebug)
00090                    << "PEGainModule:HandleCommand: " << cmd << endl;
00091   if (cmd == "DoAllStrips") {
00092      fDoAllStrips=1;
00093   }
00094   else if (cmd == "MakeDebugTree") {
00095       fDoDebugTree=1;
00096   }
00097   else if (cmd == "JustAnalyse") {
00098       fJustAnalyse=1;
00099       fAnalyseRunNumber=command->PopIntOpt();
00100   }
00101   else if (cmd == "DontAnalyse") {
00102       fDontAnalyse=1;
00103   }
00104   else if (cmd == "FromRaw") {
00105       fUseFromRawSummaries=1;
00106   }
00107   else if (cmd == "JustMakeTree") {
00108       fJustMakeTree=1;
00109   }
00110   else {
00111      MSG("PEGain", Msg::kWarning)
00112                           << "Unrecognized Command: " << cmd << endl;
00113   }
00114 
00115 }
00116 
00117 //......................................................................
00118 
00119 JobCResult PEGainModule::Ana(const MomNavigator *mom) 
00120 {
00121     if(fJustAnalyse) return JobCResult::kFailed;
00122     if(fDoDebugTree) MakeDebugTree(mom);
00123     if(fUseFromRawSummaries) return DoMeanSigmaFromRawSums(mom);
00124     return DoMeanSigmaFromSums(mom);
00125 }
00126 
00127 //......................................................................
00128 
00129 JobCResult PEGainModule::Reco(MomNavigator *mom) 
00130 {
00131  
00132     if(fJustAnalyse) return JobCResult::kFailed;
00133     //return DoMeanSigmaFromData(mom);
00134     return MakeHistosFromData(mom);
00135 }
00136 
00137 //......................................................................
00138 int PEGainModule::makeBoxIndex(RawChannelId &rcid) {
00139     int tempCrate=rcid.GetCrate();
00140     int tempVarc=rcid.GetVarcId();
00141     int tempVmm=rcid.GetVmm();
00142     int tempVaadc=rcid.GetVaAdcSel();
00143 
00144     return tempVaadc+2*tempVmm+12*tempVarc+48*tempCrate;
00145 
00146 }
00147 
00148 //......................................................................
00149 int PEGainModule::makeChannelIndex(RawChannelId &rcid) {
00150     int tempCrate=rcid.GetCrate();
00151     int tempVarc=rcid.GetVarcId();
00152     int tempVmm=rcid.GetVmm();
00153     int tempVaadc=rcid.GetVaAdcSel();
00154     int tempVachip=rcid.GetVaChip();
00155     int tempVachannel=rcid.GetVaChannel();
00156 
00157     return tempVachannel+22*tempVachip+66*tempVaadc+
00158         132*tempVmm+1584*tempVarc+6336*tempCrate;
00159 
00160 }
00161 //......................................................................
00162 
00163 JobCResult PEGainModule::DoMeanSigmaFromData(MomNavigator *mom) {
00164    MSG("PEGain",Msg::kVerbose) << "PEGainModule::DoMeanSigmaFromData()\n";
00165    
00166       
00167    Char_t filename[80];
00168    if (!fRecoFile) {
00169       Int_t tempRun = -1;
00170       if(fRun>-1) {
00171           tempRun=fRun;
00172       }
00173       else {
00174           RawRecord *rr = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord"));
00175           if (rr == 0) {
00176               MSG("PEGain", Msg::kWarning) << "No RawRecord in MOM." << endl;
00177               return JobCResult::kFailed;
00178           }
00179           
00180           const RawDaqHeader* daqHdr =
00181               dynamic_cast<const RawDaqHeader*>(rr->GetRawHeader());   
00182           if (daqHdr) {
00183                   tempRun = daqHdr->GetRun();
00184           }
00185           fRun=tempRun;
00186       }
00187       sprintf(filename,"newHistosFile%d.root",tempRun);
00188       fRecoFile = new TFile(filename,"RECREATE");
00189    }
00190 
00191    // Find RawRecord fragment in MOM.
00192    TIter iter = mom->FragmentIter();
00193    while (TObject *obj = iter.Next()) {
00194        RawRecord *rawrec = dynamic_cast<RawRecord *>(obj);
00195       if (rawrec) {
00196          
00197        MSG("PEGain",Msg::kVerbose) << "PSM::Reco() got vld: " <<(rawrec->GetRawHeader())->GetVldContext() <<endl;
00198        //int sec = rawrec->GetHeader()->GetVldContext().GetTimeStamp().GetSec();
00199        // look for a RawLIAdcSummaryBlock in the RawRecord
00200        
00201        const RawLIAdcSummaryBlock *rawsum = 
00202           dynamic_cast<const RawLIAdcSummaryBlock *>
00203           (rawrec->FindRawBlock("RawLIAdcSummaryBlock"));   
00204        if (rawsum) {
00205           MSG("PEGain",Msg::kDebug) 
00206              << "Got LI Summary for Led :" 
00207              << rawsum->GetLed()
00208              << " H " << rawsum->GetPulseHeight() << endl;
00209           
00210           if(doingBox==-1) {
00211              //First Point.
00212              //Maybe Do something.
00213              doingBox=rawsum->GetPulserBox();
00214              doingLed=rawsum->GetLed();
00215              doingHeight=rawsum->GetPulseHeight();
00216              fAggregateNo = 
00217                 PlexLedId(rawsum->GetVldContext().GetDetector(),
00218                           doingBox, doingLed);
00219           }
00220           else if(doingBox==rawsum->GetPulserBox() && 
00221                   doingLed==rawsum->GetLed()  && 
00222                   doingHeight==rawsum->GetPulseHeight()) {
00223              //It is the same point...carry on.
00224           }
00225           else {
00226              //Different point save histos and carry on.
00227              //Write out histos
00228              for(Int_t i=0;i<2880;i++) {
00229                 if(fRecoFile) {
00230                    fRecoFile->cd();
00231                    if(hists[i]) {
00232                       if(hists[i]->GetEntries()>0) {
00233                          sprintf(fHistname,
00234                                  "pl%d_st%d_end%d_led%d_h%d",
00235                                  GetPlaneFromIndex(i),
00236                                  GetStripFromIndex(i),
00237                                  GetEndFromIndex(i),
00238                                  doingLed,doingHeight);
00239                          hists[i]->SetNameTitle(fHistname,fHistname);
00240                          MSG("PEGain",Msg::kDebug) << "Wrote histo: "
00241                                                    << hists[i]->GetName() 
00242                                                    << endl;
00243                          //cout << "Here" << endl;
00244                          hists[i]->Write();
00245                          hists[i]->Reset();
00246                          //hists[i]->Delete();
00247                          //cout << "And Here" << endl;
00248                       }
00249                    }
00250                 }
00251              }
00252              doingBox=rawsum->GetPulserBox();
00253              doingLed=rawsum->GetLed();
00254              doingHeight=rawsum->GetPulseHeight(); 
00255              fAggregateNo = 
00256                 PlexLedId(rawsum->GetVldContext().GetDetector(),
00257                           doingBox, doingLed);
00258           }
00259           
00260           
00261        }
00262        
00263        const RawSnarlHeaderBlock *rawsnrhea = 
00264           dynamic_cast<const RawSnarlHeaderBlock *>
00265           (rawrec->FindRawBlock("RawSnarlHeaderBlock"));   
00266        if (rawsnrhea) {
00267           MSG("PEGain",Msg::kVerbose) 
00268              << "Got Snarl Header Block for Run :" 
00269              << rawsnrhea->GetRun()
00270              << " TrigSource " << rawsnrhea->GetTriggerSource() 
00271              << endl;
00272           
00273        }
00274        
00275        const RawDigitDataBlock *rawddb =
00276           dynamic_cast<const RawDigitDataBlock *>
00277           (rawrec->FindRawBlock("RawDigitDataBlock")); 
00278        if (rawddb) {
00279           MSG("PEGain",Msg::kVerbose) 
00280              << "Got DigitDataBlock conataining: "
00281              << rawddb->GetNumberOfDigits() << " digits.\n";
00282           
00283          TIter rdit = rawddb->GetDatumIter();
00284          RawDigit *rd;
00285          Int_t rawdigitindex = -1;
00286 
00287          Int_t tempAdc=0;
00288          RawChannelId rcid;
00289 
00290          //Get validity context
00291          VldContext vldc(rawddb->GetVldContext());
00292          PlexHandle ph(vldc);
00293 
00294 
00295          while ((rd = (RawDigit *) rdit())) { 
00296             ++rawdigitindex;
00297             tempAdc=rd->GetADC();
00298             rcid=rd->GetChannel();
00299             ReadoutType::Readout_t rt = ph.GetReadoutType(rcid);
00300             if (rt & ReadoutType::kScintStrip) {
00301                // Find out which strip-end we are. At CalDet, this is
00302                // a bit pointless, but...
00303                PlexSEIdAltL altlist = ph.GetSEIdAltL(rcid);
00304                for (PlexSEIdAltL::iterator it = altlist.begin(); 
00305                     it!=altlist.end(); it++) {
00306                   PlexStripEndId seid = (*it).GetSEId();
00307                   if (ph.GetLedId((*it).GetSEId()) == fAggregateNo
00308                       || fDoAllStrips) {
00309                      //Then I am meant to be flashing this channel with this led.
00310                      //cout << getMyIndex(seid) << "\t" << seid <<  endl;
00311                      if(hists[getMyIndex(seid)]) {
00312                         hists[getMyIndex(seid)]->Fill(tempAdc);
00313                      }
00314                      else {
00315                         sprintf(fHistname,"pl%d_st%d_end%d_led%d_h%d",
00316                                 seid.GetPlane(),
00317                                 seid.GetStrip(),
00318                                 seid.GetEnd(),
00319                                 doingLed,doingHeight);
00320                         hists[getMyIndex(seid)] = new TH1F(fHistname,fHistname,1700,-500,16500);
00321                         hists[getMyIndex(seid)]->Fill(tempAdc);
00322                         
00323                      }
00324                   }
00325                   else if (ph.GetLedId((*it).GetSEId().GetOppositeSEId()) 
00326                       == fAggregateNo || fDoAllStrips) {
00327                      //Then I am meant to be flashing this channel with this led.
00328                      //cout << getMyIndex(seid) << "\t" << seid <<  endl;
00329                      if(hists[getMyIndex(seid)]) {
00330                         hists[getMyIndex(seid)]->Fill(tempAdc);
00331                      }
00332                      else {
00333                          sprintf(fHistname,"pl%d_st%d_end%d_led%d_h%d",
00334                                  seid.GetPlane(),seid.GetStrip(),
00335                                  seid.GetEnd(),
00336                                  doingLed,doingHeight);
00337                         hists[getMyIndex(seid)] = new TH1F(fHistname,
00338                                                            fHistname,
00339                                                            1700,-500,16500);
00340                         hists[getMyIndex(seid)]->Fill(tempAdc);
00341                      }
00342                   }
00343                }
00344             }
00345          }
00346       }
00347 
00348 
00349     }
00350   }
00351   return JobCResult::kFailed;
00352 
00353 }
00354 
00355 //......................................................................
00356 void PEGainModule::FinishPoint(PlexHandle &plex) {
00357     
00358     tr_tempBox=doingPinBox;
00359     tr_tempLed=doingPinLed;
00360     tr_tempHeight=doingPinHeight;
00361     tr_tempWidth=doingPinWidth;
00362     for (std::map<Int_t,PulserSummary>::iterator it = 
00363              fPinSummaryMap.begin();
00364          it!=fPinSummaryMap.end(); it++) {
00365         //(*it).second is the PulserSummary
00366         (*it).second.Finish(fTriggers);
00367         RawChannelId rcid((*it).second.GetChannel());
00368         tr_tempCrate=rcid.GetCrate();
00369         tr_tempVarc = rcid.GetVarcId();
00370         tr_tempVmm = rcid.GetVmm();
00371         tr_tempVaadc =rcid.GetVaAdcSel();
00372         tr_tempVachip = rcid.GetVaChip();
00373         tr_tempVachannel = rcid.GetVaChannel();
00374         tr_tempMean=(*it).second.GetMean();
00375         tr_tempRMS=(*it).second.GetRMS();
00376         tr_tempNent=(*it).second.GetEntries();  
00377         fPinTree->Fill();
00378         
00379     }
00380     fDebugFile->cd();
00381     fPinTree->Write("pinTree",TObject::kOverwrite);
00382     fPinSummaryMap.clear();
00383     
00384     typedef set<UInt_t,greater<UInt_t> > IntSet;
00385     IntSet muxWithHitNear; 
00386     IntSet muxWithHitFar; 
00387     IntSet fShouldBeHitNear;
00388     IntSet fShouldBeHitFar;
00389     
00390     std::vector<PlexStripEndId> shouldBeVector
00391         =plex.GetStripEndIdVector(fPinAggregateNo);
00392     
00393     fShouldBeHitNear.clear();
00394     fShouldBeHitFar.clear();
00395     for(int i=0;i<int(shouldBeVector.size());i++) {
00396         RawChannelId rcid=
00397             plex.GetRawChannelId(shouldBeVector[i]);
00398         muxWithHitNear.insert(makeBoxIndex(rcid));
00399         fShouldBeHitNear.insert(makeChannelIndex(rcid));
00400         RawChannelId rcid2=
00401             plex.GetRawChannelId(shouldBeVector[i].GetOppositeSEId());
00402         fShouldBeHitFar.insert(makeChannelIndex(rcid2));
00403         muxWithHitFar.insert(makeBoxIndex(rcid2));
00404         
00405     }
00406     // cout << "Should be " << fShouldBeHitNear.size() << "\t" 
00407     //   << fShouldBeHitFar.size() << endl;
00408     
00409     std::map<UInt_t,PEGainMuxBox> tempBoxHolderNear;
00410     std::map<UInt_t,PEGainMuxBox> tempBoxHolderFar;
00411     for (std::map<Int_t,PulserSummary>::iterator it = 
00412              fAllHitSummaryMap.begin();
00413          it!=fAllHitSummaryMap.end(); it++) {
00414         (*it).second.Finish(fTriggers);
00415         RawChannelId rcid((*it).second.GetChannel());
00416         if(muxWithHitNear.find(makeBoxIndex(rcid))!=
00417            muxWithHitNear.end()) {
00418             //Got hit on near mux.
00419             //cout << "Got Near: " << makeChannelIndex(rcid)  << endl;
00420             if(fShouldBeHitNear.find(makeChannelIndex(rcid))!=
00421                fShouldBeHitNear.end()) {
00422                 if(tempBoxHolderNear.find(makeBoxIndex(rcid))!=
00423                    tempBoxHolderNear.end()) {
00424                     tempBoxHolderNear[makeBoxIndex(rcid)].AddRealHit(it->second,rcid);
00425                 }
00426                 else {
00427                     tempBoxHolderNear[makeBoxIndex(rcid)].New(rcid,plex);
00428                     tempBoxHolderNear[makeBoxIndex(rcid)].AddRealHit(it->second,rcid);
00429                 }
00430                 //Flashing correct pixel.
00431             }
00432             else {
00433                 if(tempBoxHolderNear.find(makeBoxIndex(rcid))!=
00434                    tempBoxHolderNear.end()) {
00435                     tempBoxHolderNear[makeBoxIndex(rcid)].AddOtherHit(it->second,rcid);
00436                 }
00437                 else {
00438                     tempBoxHolderNear[makeBoxIndex(rcid)].New(rcid,plex);
00439                     tempBoxHolderNear[makeBoxIndex(rcid)].AddOtherHit(it->second,rcid);
00440                 }
00441                 //Not Flashing Correct Pixel
00442             }
00443         }
00444         else if(muxWithHitFar.find(makeBoxIndex(rcid))!=
00445                 muxWithHitFar.end()) {
00446                             //Got hit on far mux. 
00447             if(fShouldBeHitFar.find(makeChannelIndex(rcid))!=
00448                fShouldBeHitFar.end()) { 
00449                 if(tempBoxHolderFar.find(makeBoxIndex(rcid))!=
00450                    tempBoxHolderFar.end()) {
00451                     tempBoxHolderFar[makeBoxIndex(rcid)].AddRealHit(it->second,rcid);
00452                 }
00453                 else {
00454                     tempBoxHolderFar[makeBoxIndex(rcid)].New(rcid,plex);
00455                     tempBoxHolderFar[makeBoxIndex(rcid)].AddRealHit(it->second,rcid);
00456                 }
00457                 //Flashing correct pixel.
00458             }
00459             else {      
00460                 if(tempBoxHolderFar.find(makeBoxIndex(rcid))!=
00461                    tempBoxHolderFar.end()) {
00462                     tempBoxHolderFar[makeBoxIndex(rcid)].AddOtherHit(it->second,rcid);
00463                 }
00464                 else {
00465                     tempBoxHolderFar[makeBoxIndex(rcid)].New(rcid,plex);
00466                     tempBoxHolderFar[makeBoxIndex(rcid)].AddOtherHit(it->second,rcid);
00467                 }
00468                 //Not Flashing Correct Pixel
00469             }
00470         }
00471         
00472     }
00473     char tag[80];
00474     sprintf(tag,"near_b%d_l%d",doingPinBox,doingPinLed);
00475     fDebugFile->cd();
00476     for(std::map<UInt_t,PEGainMuxBox>::iterator it=tempBoxHolderNear.begin();it!=tempBoxHolderNear.end();it++) {
00477         TMultiGraph *mg=it->second.MakeGraphs(tag);
00478         mg->Write();
00479     }
00480     sprintf(tag,"far_b%d_l%d",doingPinBox,doingPinLed);
00481     for(std::map<UInt_t,PEGainMuxBox>::iterator it=tempBoxHolderFar.begin();it!=tempBoxHolderFar.end();it++) {
00482         TMultiGraph *mg=it->second.MakeGraphs(tag);
00483         mg->Write();
00484     }
00485                 
00486     //Insert all hit stuff here
00487     fAllHitSummaryMap.clear();
00488     
00489 }
00490 //......................................................................
00491 
00492 JobCResult PEGainModule::MakeDebugTree(const MomNavigator *mom) {
00493     //Only works on VA electronics.
00494     if (!fDebugFile) {
00495         Int_t tempRun = 0;
00496         Char_t filename[80];
00497         
00498         if(!fRecoFile) {
00499             tempRun=fRun;
00500         }
00501         else {
00502             RawRecord *rr = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord"));
00503             if (rr == 0) {
00504                 MSG("PEGain", Msg::kWarning) << "No RawRecord in MOM." << endl;
00505               return JobCResult::kFailed;
00506             }
00507             
00508             const RawDaqHeader* daqHdr =
00509                 dynamic_cast<const RawDaqHeader*>(rr->GetRawHeader());   
00510             if (daqHdr) {
00511                 tempRun = daqHdr->GetRun();
00512             }
00513             fRun=tempRun;
00514         }
00515         sprintf(filename,"debugTree%d.root",tempRun);
00516         fDebugFile = new TFile(filename,"RECREATE");
00517 
00518         fPinTree = new TTree("pinTree","pinTree");
00519         fPinTree->Branch("crate",&tr_tempCrate,"crate/I");
00520         fPinTree->Branch("varc",&tr_tempVarc,"varc/I");
00521         fPinTree->Branch("vmm",&tr_tempVmm,"vmm/I");
00522         fPinTree->Branch("vaadc",&tr_tempVaadc,"vaadc/I");
00523         fPinTree->Branch("vachip",&tr_tempVachip,"vachip/I");
00524         fPinTree->Branch("vachannel",&tr_tempVachannel,"vachannel/I");
00525         fPinTree->Branch("mean",&tr_tempMean,"mean/F");
00526         fPinTree->Branch("rms",&tr_tempRMS,"rms/F");
00527         fPinTree->Branch("entries",&tr_tempNent,"entries/I");
00528         fPinTree->Branch("box",&tr_tempBox,"box/I");
00529         fPinTree->Branch("led",&tr_tempLed,"led/I");
00530         fPinTree->Branch("height",&tr_tempHeight,"height/I");
00531         fPinTree->Branch("width",&tr_tempWidth,"width/I");
00532     }
00533     // Find RawRecord fragment in MOM.
00534     TIter iter = mom->FragmentIter();
00535     int numTriggers=0;
00536     while (TObject *obj = iter.Next()) {
00537         RawRecord *rawrec = dynamic_cast<RawRecord *>(obj);
00538         if (rawrec) {
00539             int sec = rawrec->GetHeader()->GetVldContext().GetTimeStamp().GetSec();
00540             PlexHandle plex(rawrec->GetHeader()->GetVldContext());
00541             MSG("PEGain",Msg::kVerbose) 
00542                 << "PEGainModule::Reco() got vld: " 
00543                 <<(rawrec->GetRawHeader())->GetVldContext() 
00544                 << endl;
00545             const RawLIAdcSummaryBlock *rawsum = 
00546                 dynamic_cast<const RawLIAdcSummaryBlock *>
00547                 (rawrec->FindRawBlock("RawLIAdcSummaryBlock"));   
00548             if (rawsum) {
00549                 fLastSec=sec;
00550                 MSG("PEGain",Msg::kDebug) << "Got LI Summary for Led :" 
00551                                           << rawsum->GetLed()
00552                                           << " H " << rawsum->GetPulseHeight() 
00553                                           << endl;
00554             
00555         
00556                 if(doingPinBox==-1) {
00557                     //First Point.
00558                     //Maybe Do something.
00559                     doingPinBox=rawsum->GetPulserBox();
00560                     doingPinLed=rawsum->GetLed();
00561                     doingPinHeight=rawsum->GetPulseHeight();
00562                     doingPinWidth=rawsum->GetPulseWidth();
00563                     fPinAggregateNo = 
00564                         PlexLedId(rawsum->GetVldContext().GetDetector(),
00565                                   doingPinBox, doingPinLed);
00566                     fTriggers=0;
00567                 
00568                 }
00569                 else if(doingPinBox==rawsum->GetPulserBox() && 
00570                         doingPinLed==rawsum->GetLed()
00571                         && doingPinHeight==rawsum->GetPulseHeight()
00572                         && doingPinWidth==rawsum->GetPulseWidth()) {
00573                     //It is the same point...carry on.
00574                 }
00575                 else {
00576                     //Different point 
00577                     FinishPoint(plex);
00578                     fTriggers=0;
00579                     doingPinBox=rawsum->GetPulserBox();
00580                     doingPinLed=rawsum->GetLed();
00581                     doingPinHeight=rawsum->GetPulseHeight();
00582                     doingPinWidth=rawsum->GetPulseWidth();
00583                     fPinAggregateNo = 
00584                         PlexLedId(rawsum->GetVldContext().GetDetector(),
00585                                   doingPinBox, doingPinLed);
00586         
00587                     
00588                 }
00589                 
00590                     
00591                     
00592 
00593                 TIter rawit = rawsum->GetDatumIter();
00594                 while (RawLIAdcSummary *rawch = 
00595                        dynamic_cast<RawLIAdcSummary *>(rawit.Next())) {
00596                     RawChannelId rcid = rawch->GetChannel();
00597                     ReadoutType::Readout_t rt = plex.GetReadoutType(rcid);
00598                     if (rt & ReadoutType::kPinDiode) {
00599                         MSG("PEGain",Msg::kVerbose) 
00600                             << "Got LI in PIN at "<<rawch->GetChannel()<<endl;
00601                         PlexPinDiodeId pinid = plex.GetPinDiodeId(rcid);
00602                         fPinSummaryMap[pinid.GetEncoded()].Add(*rawch,pinid);
00603 
00604                     }
00605                     else  if (rt & ReadoutType::kScintStrip) {
00606                         RawChannelId rcid = rawch->GetChannel();
00607                         fAllHitSummaryMap[makeChannelIndex(rcid)].Add(*rawch);
00608                     }
00609                     else if (rt & ReadoutType::kFlashTrigPMT) {
00610                         numTriggers = max(numTriggers,int(rawch->GetEntries()));
00611                     }
00612                     
00613                     
00614                     
00615                 }
00616                 fTriggers+=numTriggers;
00617                 return JobCResult::kPassed;
00618                 
00619             }
00620             if ((fPinSummaryMap.size()>0 || fAllHitSummaryMap.size()>0)
00621                 &&(sec-fLastSec>4)) {
00622                 // 4 secs without an LI summary? Must be end of point...
00623                 FinishPoint(plex);
00624             }
00625             //Put time checking here.
00626         }
00627     }
00628     
00629   return JobCResult::kFailed;
00630 
00631 }
00632 
00633 //......................................................................
00634 
00635 JobCResult PEGainModule::MakeHistosFromData(MomNavigator *mom) {
00636    MSG("PEGain",Msg::kVerbose) 
00637       << "PEGainModule::MakeHistosFromData()\n";
00638       
00639    Char_t filename[80];
00640    if (fRun <  0) {
00641       Int_t tempRun=0;
00642       if(fRun>-1) {
00643           tempRun=fRun;
00644       }
00645       else {
00646           RawRecord *rr = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord"));
00647           if (rr == 0) {
00648                 MSG("PEGain", Msg::kWarning) << "No RawRecord in MOM." << endl;
00649                 return JobCResult::kFailed;
00650           }
00651           
00652           const RawDaqHeader* daqHdr =
00653               dynamic_cast<const RawDaqHeader*>(rr->GetRawHeader());   
00654           if (daqHdr) {
00655               tempRun = daqHdr->GetRun();
00656           }
00657           fRun=tempRun;
00658       }
00659       if(fDoAllStrips) 
00660          sprintf(filename,"allStripHistosFile%d.root",tempRun); 
00661       else sprintf(filename,"stripHistosFile%d.root",tempRun);
00662       fRecoFile = new TFile(filename,"RECREATE");
00663    }
00664    
00665    // Find RawRecord fragment in MOM.
00666    TIter iter = mom->FragmentIter();
00667    while (TObject *obj = iter.Next()) {
00668       RawRecord *rawrec = dynamic_cast<RawRecord *>(obj);
00669       if (rawrec) {
00670          MSG("PEGain",Msg::kVerbose) 
00671             << "PEGainModule::Reco() got vld: " 
00672             <<(rawrec->GetRawHeader())->GetVldContext() 
00673             << endl;
00674          //int sec = 
00675          //   rawrec->GetHeader()->GetVldContext().GetTimeStamp().GetSec();
00676          // look for a RawLIAdcSummaryBlock in the RawRecord
00677          
00678          const RawLIAdcSummaryBlock *rawsum = 
00679             dynamic_cast<const RawLIAdcSummaryBlock *>
00680             (rawrec->FindRawBlock("RawLIAdcSummaryBlock"));   
00681          if (rawsum) {
00682             MSG("PEGain",Msg::kDebug) << "Got LI Summary for Led :" 
00683                                       << rawsum->GetLed()
00684                                       << " H " << rawsum->GetPulseHeight() 
00685                                       << endl;
00686             
00687             if(doingBox==-1) {
00688                //First Point.
00689                //Maybe Do something.
00690                doingBox=rawsum->GetPulserBox();
00691                doingLed=rawsum->GetLed();
00692                doingHeight=rawsum->GetPulseHeight();
00693                fAggregateNo = PlexLedId(rawsum->GetVldContext().GetDetector(),
00694                                         doingBox, doingLed);
00695             }
00696             else if(doingBox==rawsum->GetPulserBox() && 
00697                     doingLed==rawsum->GetLed()
00698                     && doingHeight==rawsum->GetPulseHeight()) {
00699                //It is the same point...carry on.
00700             }
00701             else {
00702                //Different point save histos and carry on.
00703                //Write out histos
00704                if(fRecoFile) {
00705                   fRecoFile->cd();
00706                   for (std::map<Int_t,PEGainStripHisto>::const_iterator it=
00707                           fGainStripHisto.begin();
00708                        it!=fGainStripHisto.end(); it++) {
00709                      (*it).second.WriteHistos(fRecoFile);
00710                   }
00711                   fGainStripHisto.clear();
00712                   //   sprintf(fHistname,"pl%d_st%d_end%d_led%d_h%d",
00713                   //   GetPlaneFromIndex(i),GetStripFromIndex(i),
00714                   //   GetEndFromIndex(i),
00715                   //   doingLed,doingHeight);
00716                   //   hists[i]->SetNameTitle(fHistname,fHistname);
00717                }
00718                
00719                doingBox=rawsum->GetPulserBox();
00720                doingLed=rawsum->GetLed();
00721                doingHeight=rawsum->GetPulseHeight(); 
00722                fAggregateNo = 
00723                   PlexLedId(rawsum->GetVldContext().GetDetector(),
00724                             doingBox, doingLed);
00725             }
00726             
00727             
00728          }
00729          
00730          const RawSnarlHeaderBlock *rawsnrhea = 
00731             dynamic_cast<const RawSnarlHeaderBlock *>
00732             (rawrec->FindRawBlock("RawSnarlHeaderBlock"));   
00733          if (rawsnrhea) {
00734             MSG("PEGain",Msg::kVerbose) 
00735                << "Got Snarl Header Block for Run :" 
00736                << rawsnrhea->GetRun()
00737                << " TrigSource " 
00738                << rawsnrhea->GetTriggerSource() << endl;
00739             
00740          }
00741          
00742          const RawDigitDataBlock *rawddb =
00743             dynamic_cast<const RawDigitDataBlock *>
00744             (rawrec->FindRawBlock("RawDigitDataBlock")); 
00745          if (rawddb) {
00746             MSG("PEGain",Msg::kVerbose) 
00747                << "Got DigitDataBlock conataining: "
00748                << rawddb->GetNumberOfDigits() 
00749                << " digits.\n";
00750             
00751             TIter rdit = rawddb->GetDatumIter();
00752             RawDigit *rd;
00753             Int_t rawdigitindex = -1;
00754             
00755             Int_t tempAdc=0;
00756             RawChannelId rcid;
00757             
00758             //Get validity context
00759             VldContext vldc(rawddb->GetVldContext());
00760             PlexHandle ph(vldc);
00761             
00762             
00763             while ((rd = (RawDigit *) rdit())) { 
00764                ++rawdigitindex;
00765                tempAdc=rd->GetADC();
00766                rcid=rd->GetChannel();
00767                ReadoutType::Readout_t rt = ph.GetReadoutType(rcid);
00768                if (rt & ReadoutType::kScintStrip) {
00769                   // Find out which strip-end we are. 
00770                   // At CalDet, this is
00771                   // a bit pointless, but...
00772                   PlexSEIdAltL altlist = ph.GetSEIdAltL(rcid);
00773                   for (PlexSEIdAltL::iterator it = altlist.begin(); 
00774                        it!=altlist.end(); it++) {
00775                      PlexStripEndId seid = (*it).GetSEId();
00776                      if ((ph.GetLedId(seid) == fAggregateNo) ||
00777                          fDoAllStrips) {
00778                         //Then I am meant to be flashing this 
00779                         //channel with this led. 
00780                         MSG("PEGain",Msg::kVerbose) 
00781                            << "Got LI hit in: "
00782                            << seid << " indexed as " 
00783                            << seid.BuildPlnStripEndKey()
00784                            << " with adc: " << tempAdc << endl;
00785                         switch (rcid.GetElecType()) {
00786                         case (ElecType::kVA):  
00787                            fGainStripHisto[seid.BuildPlnStripEndKey()].AddToNearEnd(tempAdc,seid,doingBox,doingLed,doingHeight);        
00788                            break;
00789                         case (ElecType::kQIE): 
00790                            fGainStripHisto[seid.BuildPlnStripEndKey()].AddToNearEnd(tempAdc-50,seid,doingBox,doingLed,doingHeight);     
00791                            
00792                            break;
00793                         default:
00794                            // use whatever value we started with
00795                            break;
00796                         }
00797 
00798                         
00799                         
00800                      }
00801                      else if((ph.GetLedId(seid.GetOppositeSEId())
00802                               == fAggregateNo) || fDoAllStrips) {
00803                         switch (rcid.GetElecType()) {
00804                         case (ElecType::kVA):  
00805                            fGainStripHisto[seid.BuildPlnStripEndKey()].AddToFarEnd(tempAdc,seid,doingBox,doingLed,doingHeight); 
00806                            break;
00807                         case (ElecType::kQIE): 
00808                            fGainStripHisto[seid.BuildPlnStripEndKey()].AddToFarEnd(tempAdc-50,seid,doingBox,doingLed,doingHeight);      
00809                            
00810                            break;
00811                         default:
00812                            // use whatever value we started with
00813                            break;
00814                         }
00815                                              }
00816                   }
00817                }
00818             }
00819             MSG("PEGain",Msg::kVerbose) 
00820                << "Finished adding will Fill Histos" << endl;
00821             //Actually Fill Histos.
00822             for (std::map<Int_t,PEGainStripHisto>::iterator it=
00823                     fGainStripHisto.begin();
00824                  it!=fGainStripHisto.end(); it++) {
00825                (*it).second.FillHistos();
00826                //Put in loop here!!!
00827                
00828             }
00829 
00830          }
00831          
00832          
00833       }
00834    }
00835    return JobCResult::kFailed;   
00836 }
00837 
00838 
00839 
00840 JobCResult PEGainModule::DoMeanSigmaFromSums(const MomNavigator *mom) {
00841    //Get PulserSummary...
00842     
00843     PulserSummaryList *psl = dynamic_cast<PulserSummaryList *>
00844         (mom->GetFragment("PulserSummaryList"));
00845     
00846     if (psl==0) {
00847         MSG("PEGain",Msg::kVerbose) <<"No pulser summary list here\n";
00848         return JobCResult::kFailed;
00849     }
00850     MSG("PEGain",Msg::kDebug) <<"Got pulser summary "<<psl->GetPointIndex()
00851                              <<" of "<<psl->GetExpectedPoints()<<endl;
00852    //int point = psl->GetPointIndex();
00853    PlexStripEndId tempSEID;
00854    Int_t tempRun=0;
00855    Char_t filename[80];
00856    if (!fFile) {
00857      myVC=psl->GetVldContext();
00858      //     cout << myVC.AsString() << endl;
00859        if(fRun>-1) {
00860            tempRun=fRun;
00861        }
00862        else {
00863            RawRecord *rr = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord"));
00864            if (rr == 0) {
00865                MSG("PEGain", Msg::kWarning) << "No RawRecord in MOM." << endl;
00866                return JobCResult::kFailed;
00867            }
00868 
00869 
00870            const RawDaqHeader* daqHdr =
00871                dynamic_cast<const RawDaqHeader*>(rr->GetRawHeader());   
00872            if (daqHdr) {
00873                tempRun = daqHdr->GetRun();
00874            }
00875            fRun=tempRun;
00876        }
00877        sprintf(filename,"meanSigma%d.root",tempRun);
00878        fFile = new TFile(filename,"RECREATE");
00879       fTree = new TTree("ryanLiTree","ryanLiTree");
00880       fTree->Branch("crate",&tr_tempCrate,"crate/I");
00881       fTree->Branch("varc",&tr_tempVarc,"varc/I");
00882       fTree->Branch("vmm",&tr_tempVmm,"vmm/I");
00883       fTree->Branch("vaadc",&tr_tempVaadc,"vaadc/I");
00884       fTree->Branch("vachip",&tr_tempVachip,"vachip/I");
00885       fTree->Branch("vachannel",&tr_tempVachannel,"vachannel/I");
00886       fTree->Branch("end",&tr_tempEnd,"end/I");
00887       fTree->Branch("plane",&tr_tempPlane,"plane/I");
00888       fTree->Branch("strip",&tr_tempStrip,"strip/I");
00889       fTree->Branch("mean",&tr_tempMean,"mean/F");
00890       fTree->Branch("rms",&tr_tempRMS,"rms/F");
00891       fTree->Branch("entries",&tr_tempNent,"entries/I");
00892       fTree->Branch("noPEs",&tr_tempPEs,"noPEs/F");
00893       fTree->Branch("gain",&tr_tempGain,"gain/F");
00894       fTree->Branch("box",&tr_tempBox,"box/I");
00895       fTree->Branch("led",&tr_tempLed,"led/I");
00896       fTree->Branch("height",&tr_tempHeight,"height/I");
00897       fTree->Branch("width",&tr_tempWidth,"width/I");
00898    }
00899 
00900 
00901    switch(psl->GetExpectedPoints()) {
00902    case 0:
00903       // Noise - no pulsing
00904       break; 
00905    case 1:
00906       // Doug Point
00907       MSG("PEGain",Msg::kDebug) <<"Doug Point"<<endl;
00908       for (std::map<Int_t,PulserSummary>::const_iterator it=psl->GetNearBegin();
00909            it!=psl->GetNearEnd(); it++) {
00910          tempSEID=(*it).second.GetStripEndId();
00911          if(!fJustMakeTree) 
00912              fGainChannel[tempSEID.BuildPlnStripEndKey()].AddNearEnd((*it).second,tempSEID);
00913 
00914          //(*it).second is the pulser summary.
00915          tr_tempBox=psl->GetPulserBox();
00916          tr_tempLed=psl->GetLed();
00917          tr_tempHeight=psl->GetHeight();
00918          tr_tempWidth=psl->GetWidth();
00919          tr_tempMean=(*it).second.GetMean();
00920          tr_tempRMS=(*it).second.GetRMS();
00921          tr_tempNent=(*it).second.GetEntries();
00922          
00923          RawChannelId rcid((*it).second.GetChannel());
00924          tr_tempCrate=rcid.GetCrate();
00925          tr_tempVarc = rcid.GetVarcId();
00926          tr_tempVmm = rcid.GetVmm();
00927          tr_tempVaadc =rcid.GetVaAdcSel();
00928          tr_tempVachip = rcid.GetVaChip();
00929          tr_tempVachannel = rcid.GetVaChannel();
00930          tr_tempPlane=tempSEID.GetPlane();
00931          tr_tempStrip=tempSEID.GetStrip();
00932          tr_tempPEs=pow((tr_tempMean/tr_tempRMS),2);
00933          tr_tempGain=tr_tempMean/tr_tempPEs;
00934          tr_tempEnd=(Int_t)tempSEID.GetEnd();
00935          fTree->Fill();
00936          MSG("PEGain",Msg::kDebug) << "Got Summary for " //<< tempSEID 
00937                                    << "Plane: " << tr_tempPlane
00938                                    << "\tStrip: " << tr_tempStrip
00939                                    << "\tEnd: " << StripEnd::AsString(tempSEID.GetEnd())[0]
00940                                    << "\tEnd: " << tempSEID.GetEnd()
00941             
00942                                    << "\tLed : " << tr_tempLed
00943                                    << " Mean: " << tr_tempMean 
00944                                    << "\tRMS: " << tr_tempRMS
00945                                    << "\tNent: " << tr_tempNent << endl;
00946          
00947       }
00948    
00949       for (std::map<Int_t,PulserSummary>::const_iterator it=psl->GetFarBegin();
00950            it!=psl->GetFarEnd(); it++) {
00951          // (*it).second is the pulser summary.
00952          //(*it).second is the pulser summary.
00953          tempSEID=(*it).second.GetStripEndId();
00954          if(!fJustMakeTree)
00955              fGainChannel[tempSEID.BuildPlnStripEndKey()].AddFarEnd((*it).second,tempSEID);
00956          tr_tempMean=(*it).second.GetMean();
00957          tr_tempRMS=(*it).second.GetRMS();
00958          tr_tempNent=(*it).second.GetEntries();
00959          RawChannelId rcid((*it).second.GetChannel());
00960          tr_tempCrate=rcid.GetCrate();
00961          tr_tempVarc = rcid.GetVarcId();
00962          tr_tempVmm = rcid.GetVmm();
00963          tr_tempVaadc =rcid.GetVaAdcSel();
00964          tr_tempVachip = rcid.GetVaChip();
00965          tr_tempVachannel = rcid.GetVaChannel();
00966 
00967          tr_tempPlane=tempSEID.GetPlane();
00968          tr_tempStrip=tempSEID.GetStrip();
00969          tr_tempPEs=pow((tr_tempMean/tr_tempRMS),2);
00970          tr_tempGain=tr_tempMean/tr_tempPEs;
00971          tr_tempEnd=(Int_t)tempSEID.GetEnd();;
00972          fTree->Fill();
00973          MSG("PEGain",Msg::kDebug) << "Got Summary for " //<< tempSEID 
00974                                    << "Plane: " << tr_tempPlane
00975                                    << "\tStrip: " << tr_tempStrip
00976                                    << "\tEnd: " << StripEnd::AsString(tempSEID.GetEnd())[0]
00977 
00978                                    << "\tEnd: " << tempSEID.GetEnd()
00979                                    << "\tLed : " << tr_tempLed
00980                                    << " Mean: " << tr_tempMean 
00981                                    << "\tRMS: " << tr_tempRMS
00982                                    << "\tNent: " << tr_tempNent << endl;
00983       }
00984       return JobCResult::kPassed;
00985       break;
00986    default:
00987       break;
00988       // Gain Curve
00989       
00990       
00991    }
00992    return JobCResult::kFailed;
00993 }
00994 
00995 
00996 JobCResult PEGainModule::DoMeanSigmaFromRawSums(const MomNavigator *mom) {
00997    //Get PulserSummary...
00998     PulserFromRawSummaryList *psl =
00999         dynamic_cast<PulserFromRawSummaryList *>
01000         (mom->GetFragment("PulserFromRawSummaryList"));
01001     if (psl==0) {
01002         MSG("PEGain",Msg::kVerbose) <<"No pulser summary list here\n";
01003         return JobCResult::kFailed;
01004     }
01005     MSG("PEGain",Msg::kDebug) <<"Got pulser summary "<<psl->GetPointIndex()
01006                              <<" of "<<psl->GetExpectedPoints()<<endl;
01007    //int point = psl->GetPointIndex();
01008    PlexStripEndId tempSEID;
01009    Int_t tempRun=0;
01010    Char_t filename[80];
01011    if (!fFile) {
01012        if(fRun>-1) {
01013            tempRun=fRun;
01014        }
01015        else {
01016            RawRecord *rr = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord"));
01017            if (rr == 0) {
01018                MSG("PEGain", Msg::kWarning) << "No RawRecord in MOM." << endl;
01019                return JobCResult::kFailed;
01020            }
01021            VldContext tempVC(rr->GetHeader()->GetVldContext().GetDetector(),
01022                              rr->GetHeader()->GetVldContext().GetSimFlag(),
01023                              rr->GetHeader()->GetVldContext().GetTimeStamp());
01024 
01025            myVC=tempVC;
01026            
01027            const RawDaqHeader* daqHdr =
01028                dynamic_cast<const RawDaqHeader*>(rr->GetRawHeader());   
01029            if (daqHdr) {
01030                tempRun = daqHdr->GetRun();
01031            }
01032            fRun=tempRun;
01033        }
01034        sprintf(filename,"meanSigma%d.root",tempRun);
01035       fFile = new TFile(filename,"RECREATE");
01036       fTree = new TTree("ryanLiTree","ryanLiTree");
01037       fTree->Branch("crate",&tr_tempCrate,"crate/I");
01038       fTree->Branch("varc",&tr_tempVarc,"varc/I");
01039       fTree->Branch("vmm",&tr_tempVmm,"vmm/I");
01040       fTree->Branch("vaadc",&tr_tempVaadc,"vaadc/I");
01041       fTree->Branch("vachip",&tr_tempVachip,"vachip/I");
01042       fTree->Branch("vachannel",&tr_tempVachannel,"vachannel/I");
01043       fTree->Branch("end",&tr_tempEnd,"end/I");
01044       fTree->Branch("plane",&tr_tempPlane,"plane/I");
01045       fTree->Branch("strip",&tr_tempStrip,"strip/I");
01046       fTree->Branch("mean",&tr_tempMean,"mean/F");
01047       fTree->Branch("rms",&tr_tempRMS,"rms/F");
01048       fTree->Branch("entries",&tr_tempNent,"entries/I");
01049       fTree->Branch("noPEs",&tr_tempPEs,"noPEs/F");
01050       fTree->Branch("gain",&tr_tempGain,"gain/F");
01051       fTree->Branch("box",&tr_tempBox,"box/I");
01052       fTree->Branch("led",&tr_tempLed,"led/I");
01053       fTree->Branch("height",&tr_tempHeight,"height/I");
01054       fTree->Branch("width",&tr_tempWidth,"width/I");
01055    }
01056 
01057 
01058    switch(psl->GetExpectedPoints()) {
01059    case 0:
01060       // Noise - no pulsing
01061       break; 
01062    case 1:
01063       // Doug Point
01064       MSG("PEGain",Msg::kDebug) <<"Doug Point"<<endl;
01065       for (std::map<Int_t,PulserSummary>::const_iterator it=psl->GetNearBegin();
01066            it!=psl->GetNearEnd(); it++) {
01067          tempSEID=(*it).second.GetStripEndId();
01068          if(!fJustMakeTree)
01069              fGainChannel[tempSEID.BuildPlnStripEndKey()].AddNearEnd((*it).second,tempSEID);
01070 
01071          //(*it).second is the pulser summary.
01072          tr_tempBox=psl->GetPulserBox();
01073          tr_tempLed=psl->GetLed();
01074          tr_tempHeight=psl->GetHeight();
01075          tr_tempWidth=psl->GetWidth();
01076          tr_tempMean=(*it).second.GetMean();
01077          tr_tempRMS=(*it).second.GetRMS();
01078          tr_tempNent=(*it).second.GetEntries();
01079          
01080          RawChannelId rcid((*it).second.GetChannel());
01081          tr_tempCrate=rcid.GetCrate();
01082          tr_tempVarc = rcid.GetVarcId();
01083          tr_tempVmm = rcid.GetVmm();
01084          tr_tempVaadc =rcid.GetVaAdcSel();
01085          tr_tempVachip = rcid.GetVaChip();
01086          tr_tempVachannel = rcid.GetVaChannel();
01087          tr_tempPlane=tempSEID.GetPlane();
01088          tr_tempStrip=tempSEID.GetStrip();
01089          tr_tempPEs=pow((tr_tempMean/tr_tempRMS),2);
01090          tr_tempGain=tr_tempMean/tr_tempPEs;
01091          tr_tempEnd=(Int_t)tempSEID.GetEnd();
01092          fTree->Fill();
01093          MSG("PEGain",Msg::kDebug) << "Got Summary for " //<< tempSEID 
01094                                    << "Plane: " << tr_tempPlane
01095                                    << "\tStrip: " << tr_tempStrip
01096                                    << "\tEnd: " << StripEnd::AsString(tempSEID.GetEnd())[0]
01097                                    << "\tEnd: " << tempSEID.GetEnd()
01098             
01099                                    << "\tLed : " << tr_tempLed
01100                                    << " Mean: " << tr_tempMean 
01101                                    << "\tRMS: " << tr_tempRMS
01102                                    << "\tNent: " << tr_tempNent << endl;
01103          
01104       }
01105    
01106       for (std::map<Int_t,PulserSummary>::const_iterator it=psl->GetFarBegin();
01107            it!=psl->GetFarEnd(); it++) {
01108          // (*it).second is the pulser summary.
01109          //(*it).second is the pulser summary.
01110          tempSEID=(*it).second.GetStripEndId();
01111          if(!fJustMakeTree)
01112              fGainChannel[tempSEID.BuildPlnStripEndKey()].AddFarEnd((*it).second,tempSEID);
01113          tr_tempMean=(*it).second.GetMean();
01114          tr_tempRMS=(*it).second.GetRMS();
01115          tr_tempNent=(*it).second.GetEntries();
01116          RawChannelId rcid((*it).second.GetChannel());
01117          tr_tempCrate=rcid.GetCrate();
01118          tr_tempVarc = rcid.GetVarcId();
01119          tr_tempVmm = rcid.GetVmm();
01120          tr_tempVaadc =rcid.GetVaAdcSel();
01121          tr_tempVachip = rcid.GetVaChip();
01122          tr_tempVachannel = rcid.GetVaChannel();
01123 
01124          tr_tempPlane=tempSEID.GetPlane();
01125          tr_tempStrip=tempSEID.GetStrip();
01126          tr_tempPEs=pow((tr_tempMean/tr_tempRMS),2);
01127          tr_tempGain=tr_tempMean/tr_tempPEs;
01128          tr_tempEnd=(Int_t)tempSEID.GetEnd();;
01129          fTree->Fill();
01130          MSG("PEGain",Msg::kDebug) << "Got Summary for " //<< tempSEID 
01131                                    << "Plane: " << tr_tempPlane
01132                                    << "\tStrip: " << tr_tempStrip
01133                                    << "\tEnd: " << StripEnd::AsString(tempSEID.GetEnd())[0]
01134 
01135                                    << "\tEnd: " << tempSEID.GetEnd()
01136                                    << "\tLed : " << tr_tempLed
01137                                    << " Mean: " << tr_tempMean 
01138                                    << "\tRMS: " << tr_tempRMS
01139                                    << "\tNent: " << tr_tempNent << endl;
01140       }
01141       return JobCResult::kPassed;
01142       break;
01143    default:
01144       break;
01145       // Gain Curve
01146       
01147       
01148    }
01149    return JobCResult::kFailed;
01150 }
01151 
01152 
01153 
01154 void PEGainModule::EndJob() 
01155 {
01156 
01157     if(fJustAnalyse && !fDontAnalyse) {
01158         char filename[180];       
01159         VldTimeStamp vtsnow;
01160         VldContext tempVC(Detector::kFar,SimFlag::kData,vtsnow);
01161         myVC=tempVC;
01162         fRun=fAnalyseRunNumber;
01163         sprintf(filename,"meanSigma%d.root",fAnalyseRunNumber);
01164         fFile = new TFile(filename,"OLD");
01165         if (fFile) {
01166             fFile->cd();
01167             fTree = (TTree*) gDirectory->Get("ryanLiTree");
01168             analyseMeanSigmaFile();
01169             fFile->Close();
01170         }
01171         
01172         sprintf(filename,"debugTree%d.root",fAnalyseRunNumber);
01173         fDebugFile = new TFile(filename,"OLD");
01174         if (fDebugFile) {
01175             fDebugFile->cd();
01176             analyseDebugTree();
01177             fDebugFile->Close();
01178         }
01179     }
01180     else {
01181 
01182 
01183         if(fRun>-1 && !fJustMakeTree) {
01184             Char_t tempFileName[80];
01185             sprintf(tempFileName,"theGainsFrom%d.dat",fRun);
01186             ofstream TextFile (tempFileName);
01187             if(!TextFile) {
01188                 MSG("PEGain",Msg::kError) << "Couldn't bloody open this file: "
01189                                           << tempFileName << " will just cout\n";
01190                 for (std::map<Int_t,PEGainSummary>::const_iterator it=
01191                          fGainChannel.begin();it!=fGainChannel.end(); it++) {
01192                     PlexStripEndId tempSeid = (*it).second.GetStripEndId(); 
01193                     Int_t tempPlane=tempSeid.GetPlane();
01194                     Int_t tempStrip=tempSeid.GetStrip();
01195                     Int_t tempEnd=(Int_t)tempSeid.GetEnd();
01196                     cout << tempPlane << "\t" << tempStrip<< "\t" << tempEnd
01197                          << "\t" << (*it).second.GetProperBestGain() 
01198                          << "\t" <<  (*it).second.GetProperBestError() << endl;
01199                 } 
01200             }
01201             else {
01202                 for (std::map<Int_t,PEGainSummary>::const_iterator it=
01203                          fGainChannel.begin();it!=fGainChannel.end(); it++) {
01204                     PlexStripEndId tempSeid = (*it).second.GetStripEndId(); 
01205                     Int_t tempPlane=tempSeid.GetPlane();
01206                     Int_t tempStrip=tempSeid.GetStrip();
01207                     Int_t tempEnd=(Int_t)tempSeid.GetEnd();
01208                     TextFile << tempPlane << "\t" << tempStrip<< "\t" << tempEnd
01209                              << "\t" << (*it).second.GetProperBestGain() 
01210                              << "\t" <<  (*it).second.GetProperBestError() << endl;
01211                 }
01212             }
01213         }
01214         
01215         
01216         
01217         
01218         if(fRecoFile) {
01219             fRecoFile->cd();
01220             
01221             for (std::map<Int_t,PEGainStripHisto>::const_iterator it=
01222                      fGainStripHisto.begin();
01223                  it!=fGainStripHisto.end(); it++) {
01224                 (*it).second.WriteHistos(fRecoFile);
01225             }
01226 
01227             for(Int_t i=0;i<2880;i++) {
01228                 
01229                 if(hists[i]) {
01230                     if(hists[i]->GetEntries()>0) {
01231                         sprintf(fHistname,"pl%d_st%d_end%d_led%d_h%d",
01232                                 GetPlaneFromIndex(i),GetStripFromIndex(i),GetEndFromIndex(i),
01233                                 doingLed,doingHeight);
01234                         hists[i]->SetNameTitle(fHistname,fHistname);
01235                         MSG("PEGain",Msg::kDebug) << "Wrote histo: "
01236                                                   << hists[i]->GetName() 
01237                                                   << endl;
01238 
01239                         hists[i]->Write();
01240                         hists[i]->Reset();
01241                         //hists[i]->Delete();
01242                     }
01243                 }
01244 
01245             }
01246             fRecoFile->Close();
01247         }
01248 
01249         
01250         if (fFile) {
01251             fFile->cd();
01252             fTree->Write();
01253             if(!fDontAnalyse)
01254                 analyseMeanSigmaFile();
01255             fFile->Close();
01256         }
01257 
01258         if (fDebugFile) {
01259             fDebugFile->cd();
01260             fPinTree->Write();
01261             if(!fDontAnalyse)
01262                 analyseDebugTree();
01263             fDebugFile->Close();
01264         }
01265     }
01266 
01267 }
01268     
01270 
01271 Int_t PEGainModule::analyseDebugTree() {
01272     int runnum=fRun;
01273     fDebugFile->cd();
01274     char filename[180];
01275     sprintf(filename,"pixelPlotReport%d.txt",runnum);
01276     ofstream PixelReport (filename);
01277     sprintf(filename,"deadOrMiswired%d.txt",runnum);
01278     ofstream DeadReport (filename);
01279     char name[180];
01280     int percent=0;
01281     MSG("PEGain", Msg::kInfo)  << "Doing Wiring/Pixel Check" <<  endl;
01282     for(int plane=1;plane<486;plane++) {
01283         if(float(plane*100)/float(486)>percent) {
01284             MSG("PEGain", Msg::kInfo)  << "*";
01285             percent+=3;
01286         }
01287         //cout << plane << endl;
01288         if(plane<250) {
01289             if(((plane-1)/2)%2==1) continue;
01290         }
01291         else if((plane/2)%2==0) continue;
01292 
01293         if(plane==249) continue;
01294         for(int tempBox=0;tempBox<2;tempBox++) {
01295             int box=0;
01296             if(tempBox==0) box=getEastBox(plane);
01297             if(tempBox==1) box=getWestBox(plane);
01298             int nearProbs[20]={0};
01299             int farProbs[20]={0};
01300             int nearDead[20]={0};
01301             int farDead[20]={0};
01302             int nearMiswired[20]={0};
01303             int farMiswired[20]={0};
01304             int numNearProbs=0;
01305             int numFarProbs=0;
01306             int totalNearProbs=0;
01307             int totalFarProbs=0;
01308             for(int led=1;led<=20;led++) {
01309                 int bug,bug2,bug3,bug4;
01310                 char tag[180];
01311                 sprintf(name,"pl%d_end%d_near_b%d_l%d",plane,box%2+1,box,led);
01312                 TMultiGraph *mgtop = (TMultiGraph*) gDirectory->Get(name);
01313                 if(!mgtop) {
01314                     numNearProbs++;
01315                 }
01316                 else {
01317 
01318                     sprintf(tag,"pl%d_end%d_near_b%d_l%d",
01319                             plane,box%2+1,box,led);
01320                     int numNear=getNumWrong(mgtop,tag,&bug,&bug2);
01321                     nearDead[led-1]=bug;
01322                     nearMiswired[led-1]=bug2;
01323                     nearProbs[led-1]=numNear;
01324                     if(numNear>0) numNearProbs++;
01325                     totalNearProbs+=numNear;
01326                 }
01327                     //delete mgtop;
01328                 sprintf(name,"pl%d_end%d_far_b%d_l%d",plane,3-(box%2+1),box,led);
01329                 TMultiGraph *mgtop2 = (TMultiGraph*) gDirectory->Get(name);
01330                 if(!mgtop2) {
01331                     numFarProbs++;
01332                 }
01333                 else {
01334                     sprintf(tag,"pl%d_end%d_far_b%d_l%d",
01335                             plane,3-(box%2+1),box,led);
01336                     int numFar=getNumWrong(mgtop2,tag,&bug3,&bug4);
01337                     farDead[led-1]=bug3;
01338                     farMiswired[led-1]=bug4;
01339                     farProbs[led-1]=numFar;
01340                     if(numFar>0) numFarProbs++;
01341                     totalFarProbs+=numFar;
01342                 }
01343             }
01344             if(numNearProbs==20 || numFarProbs==20) {
01345                 if(box%2==0) {
01346                     PixelReport << "Dodgy Planes East: " 
01347                                 << plane << "-" << plane+2 
01348                                 << "\tbox " << box << endl;
01349                 }
01350                 else {
01351                     PixelReport << "Dodgy Planes West: " 
01352                                 << plane << "-" << plane+2 
01353                                 << "\tbox " << box << endl;
01354                 }       
01355                 
01356             }
01357             else {
01358                 for(int led=1;led<=20;led++) {
01359                     if(nearProbs[led-1]>0 || farProbs[led-1]>0) {
01360                         if(box%2==0) {
01361                             PixelReport << "Something wrong with East: " 
01362                                         << plane << "-" << plane+2 
01363                                         << "\tbox " << box << "\tled " << led 
01364                                         << "\t Num Wrong: Near " 
01365                                         << nearProbs[led-1]
01366                                         << " Far: " << farProbs[led-1] << endl;
01367                         }
01368                         else {
01369                             PixelReport << "Something wrong with West: " 
01370                                         << plane << "-" << plane+2 
01371                                         << "\tbox " << box << "\tled " << led  
01372                                         << "\t Num Wrong: Near "  
01373                                         << nearProbs[led-1] 
01374                                         << " Far: " << farProbs[led-1] << endl;
01375                         }
01376                         
01377                     }
01378                     if((nearDead[led-1]>0 && farDead[led-1]>0) &&
01379                        nearDead[led-1]==farDead[led-1]) {
01380                         if(box%2==0) {
01381                             DeadReport << "Dead Fibre East: ";
01382                         }
01383                         else {
01384                             DeadReport << "Dead Fibre West: ";
01385                             
01386                         }
01387                         int ashtray;
01388                         if(nearDead[led-1]==1) {
01389                             DeadReport << plane;
01390                             ashtray=ledToAhstray(plane,led);
01391                         }
01392                         else {
01393                             DeadReport << plane+2;
01394                             ashtray=ledToAhstray(plane+2,led);
01395                         }
01396                         DeadReport << "\tbox " << box << "\tled " << led
01397                                    << "\t(ashtray " << ashtray
01398                                    << ")" << endl;
01399                     }
01400                     else if((nearMiswired[led-1]>0 && farMiswired[led-1]>0) &&
01401                        nearMiswired[led-1]==farMiswired[led-1]) {
01402                         int ashtray;
01403                         if(box%2==0) {
01404                             DeadReport << "Miswired Fibre East: ";
01405                         }
01406                         else {
01407                             DeadReport << "Miswired Fibre West: ";
01408                             
01409                         }
01410                         if(nearMiswired[led-1]==1) {
01411                             DeadReport << plane;
01412                             ashtray=ledToAhstray(plane,led);
01413                         }
01414                         else {
01415                             DeadReport << plane+2;
01416                             ashtray=ledToAhstray(plane+2,led);
01417                         }
01418                         DeadReport << "\tbox " << box << "\tled " << led
01419                                    << "\t(ashtray " << ashtray
01420                                    << ")" << endl;
01421                     }               
01422                     else if(nearProbs[led-1]>6 || farProbs[led-1]>6) {
01423                         if(box%2==0) {
01424                             DeadReport << "Something wrong with East: " 
01425                                        << plane << "-" << plane+2 
01426                                        << "\tbox " << box << "\tled " << led 
01427                                        << "\t(ashtrays " 
01428                                        << ledToAhstray(plane,led) << " or " 
01429                                        <<  ledToAhstray(plane+2,led)
01430                                        << ")" << endl;
01431                         }
01432                         else {
01433                             DeadReport << "Something wrong with West: " 
01434                                        << plane << "-" << plane+2 
01435                                        << "\tbox " << box << "\tled " << led  
01436                                        << "\t(ashtrays " 
01437                                        << ledToAhstray(plane,led) << " or " 
01438                                        <<  ledToAhstray(plane+2,led)
01439                                        << ")" << endl;
01440                         }
01441                         
01442                     }
01443                 }
01444             }
01445 
01446             
01447         }  
01448     }
01449     MSG("PEGain", Msg::kInfo)  << endl;
01450     return 0;
01451 }
01452 
01454 
01455 int PEGainModule::getNumWrong(TMultiGraph *mgtop,char *tag,
01456                 int *isDead, int *isMiswired) {
01457     typedef std::multimap<float,int> floatIntMap;
01458 
01459     TList *listy = mgtop->GetListOfGraphs();
01460     char name[180];
01461     char name2[180];
01462     sprintf(name,"real_%s",tag);
01463     //cout << name << endl;
01464     TGraphErrors *grReal= (TGraphErrors*) listy->FindObject(name);
01465     sprintf(name2,"other_%s",tag);
01466     //cout << name << endl;
01467     TGraphErrors *grOther= (TGraphErrors*) listy->FindObject(name2);
01468 //     TCanvas *can3 = new TCanvas("can3","can3");
01469 //     can3->Divide(1,2);
01470 //     can3->cd(1);
01471 //     grReal->Draw("ap");
01472 //     can3->cd(2);
01473 //     grOther->Draw("ap");
01474     if(!grReal || !grOther) {
01475         if(!grReal)
01476             MSG("PEGain", Msg::kInfo)  << endl << "Couldn't find: " << name ;
01477         if(!grOther)
01478             MSG("PEGain", Msg::kInfo)   << endl << "Couldn't find: " << name2;
01479         return -1;
01480     }
01481         
01482     Double_t *realx=grReal->GetX();
01483     Double_t *realy=grReal->GetY();
01484     Double_t *otherx=grOther->GetX();
01485     Double_t *othery=grOther->GetY();
01486     Int_t numberReal=grReal->GetN();
01487     Int_t numberOther=grOther->GetN();
01488     
01489     floatIntMap mappy;
01490     double meanReal[2]={0,0};
01491     double maxReal[2]={0,0};
01492     double minReal[2]={16000,16000};
01493     double numReal[2]={0,0};
01494     double meanOther[2]={0,0};
01495     double maxOther[2]={0,0};
01496     double minOther[2]={16000,16000};
01497     double numOther[2]={0,0};
01498     for(int i=0;i<numberReal;i++) {
01499         mappy.insert(make_pair(realy[i],int(1*realx[i])));
01500         meanReal[int(realx[i]/29)]+=realy[i];
01501         numReal[int(realx[i]/29)]++;
01502         if(realy[i]>maxReal[int(realx[i]/29)]) maxReal[int(realx[i]/29)]=realy[i];
01503         if(realy[i]<minReal[int(realx[i]/29)]) minReal[int(realx[i]/29)]=realy[i];
01504 //      cout << "Real " << i <<" :\t" 
01505 //      << realx[i] << " " << realy[i] << endl;
01506     }
01507     if(numReal[0]>0) 
01508       meanReal[0]/=numReal[0];
01509     if(numReal[1]>0) 
01510       meanReal[1]/=numReal[1];
01511     for(int i=0;i<numberOther;i++) {
01512         //map->Add(TObject(realy[i]),TObject(1));
01513         mappy.insert(make_pair(othery[i],int(-1*otherx[i])));
01514         meanOther[int(otherx[i]/29)]+=othery[i];
01515         numOther[int(otherx[i]/29)]++;
01516         if(othery[i]>maxOther[int(otherx[i]/29)]) maxOther[int(otherx[i]/29)]=othery[i];
01517         if(othery[i]<minOther[int(otherx[i]/29)]) minOther[int(otherx[i]/29)]=othery[i];
01518 //      cout << "Other " << i <<" :\t" 
01519 //           << otherx[i] << " " << othery[i] << endl;
01520     }
01521     if(numOther[0]>0)
01522       meanOther[0]/=numOther[0];
01523     if(numOther[1]>0) 
01524       meanOther[1]/=numOther[1];
01525     floatIntMap::iterator pos;
01526     Int_t upto=0;
01527     int bug=0;
01528     int bug2=0;
01529     bug=0;
01530     bug2=0;
01531     for(pos=mappy.begin();pos!=mappy.end();pos++) {
01532         if(pos->second>0) {
01533             if(upto<numberOther) bug++;
01534             // cout << "Real: "<< pos->second 
01535 //          << " " << pos->first << endl;
01536         }
01537         else {
01538             if(upto>=numberOther) bug2++;
01539             //cout << "Other: "<< -1*pos->second 
01540             //<< " " << pos->first << endl;
01541         }
01542         upto++;
01543     }
01544 //    cout << bug << " \t" << bug2 << endl;
01545     *isDead=0;
01546     *isMiswired=0;
01547     if(bug>0 && bug2>0) {
01548         
01549         if(maxOther[0]>meanReal[0]) {
01550 
01551             //Dead or miswired??
01552             if(maxReal[0]<3.0*minOther[0]) {
01553                 //Dead
01554                 if(maxReal[0]<0.2*maxReal[1]&& maxOther[0]<0.2*maxReal[1]) {
01555                     //  cout << "Dead " << tag << endl;
01556                     *isDead=1;
01557                 }
01558                 else if(maxOther[0]<3.0*minOther[0] || 
01559                    maxOther[0]<0.2*maxReal[1]) {
01560 //                  cout << "Dead " << tag << endl;
01561                     *isDead=1;
01562                 }
01563                 else {
01564                     *isMiswired=1;
01565                     //cout << "Miswired " << tag << endl;
01566                 }
01567             }
01568             else if(maxReal[0]<0.2*maxReal[1]&& maxOther[0]<0.2*maxReal[1]) {
01569                 
01570                 *isDead=1;
01571                 //cout << "Dead " << tag << endl;
01572            }
01573             else{
01574                   *isMiswired=1;
01575                   //cout << "Miswired " << tag << endl;
01576             }
01577         }
01578         if(maxOther[1]>meanReal[1]) {
01579             //Dead or miswired??
01580             if(maxReal[1]<3.0*minOther[1]) {
01581                 //Dead
01582                 if(maxReal[1]<0.2*maxReal[0]&& maxOther[1]<0.2*maxReal[0]) {
01583                     *isDead=2;
01584                     //cout << "Dead " << tag << endl;
01585                 }
01586                 else if(maxOther[1]<3.0*minOther[1] || 
01587                    maxOther[1]<0.2*maxReal[0]) {
01588                     *isDead=2;
01589                     //cout << "Dead " << tag << endl;
01590                 }
01591                 else {
01592                     *isMiswired=2;
01593                     //cout << "Miswired " << tag << endl;
01594                 }
01595             }
01596             else if(maxReal[1]<0.2*maxReal[0] && maxOther[1]<0.2*maxReal[0] ) {
01597                 *isDead=2;
01598                 //cout << "Dead " << tag << endl;
01599             }
01600             else {
01601                 *isMiswired=2;
01602                 //cout << "Miswired " << tag << endl;
01603             }
01604         }
01605         
01606         return bug2+bug;
01607     }
01608     return 0;
01609 }
01610 
01612 
01613 int PEGainModule::analyseMeanSigmaFile() {
01614     MSG("PEGain", Msg::kDebug) << "Starting analyseMeanSigmaFile() " << endl;
01615     PlexHandle ph(myVC);
01616     MSG("PEGain", Msg::kDebug) << "Got Plex " << endl;
01617     char filename[180];
01618     int LAST_PLANE=0;
01619 //    int MAX_BAD_IN_ASH=10;
01620     //  float FRACTION_STRIP_HITS_NEEDED=0.9;
01621     int runnum=fRun;
01622     TTree *ryanLiTree=fTree;
01623     Int_t crate;
01624     Int_t           varc;
01625     Int_t           vmm;
01626     Int_t           vaadc;
01627     Int_t           vachip;
01628     Int_t           vachannel;
01629     Int_t           end;
01630     Int_t           plane;
01631     Int_t           strip;
01632     Float_t         mean;
01633     Float_t         rms;
01634     Int_t           entries;
01635     Float_t         noPEs;
01636     Float_t         gain;
01637     Int_t           box;
01638     Int_t           led;
01639     Int_t           height;
01640     Int_t           width;
01641     //Set branch addresses
01642     ryanLiTree->SetBranchAddress("crate",&crate);
01643     ryanLiTree->SetBranchAddress("varc",&varc);
01644     ryanLiTree->SetBranchAddress("vmm",&vmm);
01645     ryanLiTree->SetBranchAddress("vaadc",&vaadc);
01646     ryanLiTree->SetBranchAddress("vachip",&vachip);
01647     ryanLiTree->SetBranchAddress("vachannel",&vachannel);
01648     ryanLiTree->SetBranchAddress("end",&end);
01649     ryanLiTree->SetBranchAddress("plane",&plane);
01650     ryanLiTree->SetBranchAddress("strip",&strip);
01651     ryanLiTree->SetBranchAddress("mean",&mean);
01652     ryanLiTree->SetBranchAddress("rms",&rms);
01653     ryanLiTree->SetBranchAddress("entries",&entries);
01654     ryanLiTree->SetBranchAddress("noPEs",&noPEs);
01655     ryanLiTree->SetBranchAddress("gain",&gain);
01656     ryanLiTree->SetBranchAddress("box",&box);
01657     ryanLiTree->SetBranchAddress("led",&led);
01658     ryanLiTree->SetBranchAddress("height",&height);
01659     ryanLiTree->SetBranchAddress("width",&width);
01660     
01661     sprintf(filename,"errorReport%d.txt",runnum);
01662     ofstream ErrorReport (filename);
01663    
01664     sprintf(filename,"liMaps%d.root",runnum);
01665     TFile *fpout = new TFile(filename,"RECREATE");
01666     fpout->cd();
01667     TH1F *histNent = new TH1F("histNent","histNent",1000,0,300000);
01668 
01669     TH2F *histNearPlaneMean1 = new TH2F("histNearPlaneMean1",
01670                                        "histNearPlaneMean1",
01671                                        500,-0.5,499.5,200,-0.5,199.5);
01672     TH2F *histNearPlaneMean2 = new TH2F("histNearPlaneMean2",
01673                                         "histNearPlaneMean2",
01674                                         500,-0.5,499.5,200,-0.5,199.5);
01675     
01676     TH2F *histNearPlaneNent1 = new TH2F("histNearPlaneNent1",
01677                                         "histNearPlaneNent1",
01678                                         500,-0.5,499.5,200,-0.5,199.5);
01679     TH2F *histNearPlaneNent2 = new TH2F("histNearPlaneNent2",
01680                                         "histNearPlaneNent2",
01681                                         500,-0.5,499.5,200,-0.5,199.5);
01682     
01683     TH2F *histFarPlaneMean1 = new TH2F("histFarPlaneMean1",
01684                                        "histFarPlaneMean1",
01685                                        500,-0.5,499.5,200,-0.5,199.5);
01686     TH2F *histFarPlaneMean2 = new TH2F("histFarPlaneMean2",
01687                                        "histFarPlaneMean2",
01688                                        500,-0.5,499.5,200,-0.5,199.5);
01689     TH2F *histFarPlaneNent1 = new TH2F("histFarPlaneNent1","histFarPlaneNent1",
01690                                        500,-0.5,499.5,200,-0.5,199.5);
01691     TH2F *histFarPlaneNent2 = new TH2F("histFarPlaneNent2","histFarPlaneNent2",
01692                                        500,-0.5,499.5,200,-0.5,199.5);
01693     
01694     
01695     TH2F *histNearPlaneLed1 = new TH2F("histNearPlaneLed1",
01696                                        "histNearPlaneLed1",
01697                                        500,-0.5,499.5,200,-0.5,199.5);
01698     TH2F *histNearPlaneLed2 = new TH2F("histNearPlaneLed2",
01699                                        "histNearPlaneLed2",
01700                                        500,-0.5,499.5,200,-0.5,199.5);
01701    TH2F *histFarPlaneLed1 = new TH2F("histFarPlaneLed1",
01702                                      "histFarPlaneLed1",
01703                                      500,-0.5,499.5,200,-0.5,199.5);
01704    TH2F *histFarPlaneLed2 = new TH2F("histFarPlaneLed2",
01705                                      "histFarPlaneLed2",
01706                                      500,-0.5,499.5,200,-0.5,199.5);
01707    
01708    TH2F *histEvenPBTrans = new TH2F("histEvenPBTrans","histEvenPBTrans",
01709                                     500,-0.5,499.5,200,-0.5,199.5);
01710    TH2F *histOddPBTrans = new TH2F("histOddPBTrans","histOddPBTrans",
01711                                   500,-0.5,499.5,200,-0.5,199.5);
01712    
01713    TH2F *histNearPlaneRms1 = new TH2F("histNearPlaneRms1",
01714                                        "histNearPlaneRms1",
01715                                        500,-0.5,499.5,200,-0.5,199.5);
01716     TH2F *histNearPlaneRms2 = new TH2F("histNearPlaneRms2",
01717                                        "histNearPlaneRms2",
01718                                        500,-0.5,499.5,200,-0.5,199.5);
01719      
01720     TH2F *histNearPlanePe1 = new TH2F("histNearPlanePe1",
01721                                        "histNearPlanePe1",
01722                                        500,-0.5,499.5,200,-0.5,199.5);
01723     TH2F *histNearPlanePe2 = new TH2F("histNearPlanePe2",
01724                                        "histNearPlanePe2",
01725                                        500,-0.5,499.5,200,-0.5,199.5);
01726 
01727     TH2F *histFarPlaneRms1 = new TH2F("histFarPlaneRms1",
01728                                        "histFarPlaneRms1",
01729                                        500,-0.5,499.5,200,-0.5,199.5);
01730     TH2F *histFarPlaneRms2 = new TH2F("histFarPlaneRms2",
01731                                        "histFarPlaneRms2",
01732                                        500,-0.5,499.5,200,-0.5,199.5);
01733                                                                                 
01734     TH2F *histFarPlanePe1 = new TH2F("histFarPlanePe1",
01735                                        "histFarPlanePe1",
01736                                        500,-0.5,499.5,200,-0.5,199.5);
01737     TH2F *histFarPlanePe2 = new TH2F("histFarPlanePe2",
01738                                        "histFarPlanePe2",
01739                                        500,-0.5,499.5,200,-0.5,199.5);
01740 
01741    typedef std::map<int,int> intMap;
01742    //Store hit chips, channels, leds in below maps
01743    intMap nearChipsHit;
01744    intMap farChipsHit;
01745    intMap nearChannelsHit;
01746    intMap farChannelsHit;
01747    intMap ledsHit;
01748    intMap nearLedsHit;
01749    intMap farLedsHit;
01750    
01751    //Store problem planes in below maps.
01752    intMap badPlanes;
01753    intMap badEvenNear;
01754    intMap badEvenFar;
01755    intMap badOddNear;
01756    intMap badOddFar;
01757    
01758    int isReal=0;
01759    Int_t nentries = (int)ryanLiTree->GetEntries();
01760    //cout << "There are " << nentries << " entries in the tree." << endl;
01761    MSG("PEGain", Msg::kInfo)  << "Doing LED/FEE checking" << endl;
01762 //   cout  << "Doing LED/FEE checking" << endl;
01763    Int_t nbytes = 0;
01764    int percent=0;
01765    intMap doneLedIndex;
01766    intMap::iterator doneLedPos;
01767    int lastLedIndex;
01768    for (Int_t i=0; i<nentries;i++) {
01769        nbytes += ryanLiTree->GetEntry(i);
01770        
01771        if(plane>LAST_PLANE) {
01772            LAST_PLANE=plane;
01773        } 
01774        if(float(i*100)/float(nentries)>percent) {
01775            //MSG("PEGain", Msg::kInfo)  << "*";
01776 //         cerr  << "*";
01777            percent+=3;
01778        }
01779        int tempLedIndex=(led-1)+20*box;
01780        if(lastLedIndex!=tempLedIndex) 
01781            doneLedIndex[lastLedIndex]=1;
01782        lastLedIndex=tempLedIndex;
01783        doneLedPos=doneLedIndex.find(tempLedIndex);
01784        if(doneLedPos!=doneLedIndex.end()) { //We've had you before
01785            continue;
01786        }
01787                
01788        isReal=0;
01789        if(end==1) {
01790            if(box==crate) { 
01791                isReal=1;
01792                histNearPlaneLed1->Fill(plane,strip,led);
01793                histNearPlaneMean1->Fill(plane,strip,mean);           
01794                histNearPlaneRms1->Fill(plane,strip,rms);
01795                histNearPlanePe1->Fill(plane,strip,(mean/rms)*(mean/rms)/.8);
01796 
01797                histNearPlaneNent1->Fill(plane,strip,entries);
01798            }
01799            else if(box/2 == crate/2) { 
01800                isReal=1;
01801                histFarPlaneLed1->Fill(plane,strip,led);
01802                histFarPlaneMean1->Fill(plane,strip,mean); 
01803                histFarPlaneRms1->Fill(plane,strip,rms);
01804                histFarPlanePe1->Fill(plane,strip,(mean/rms)*(mean/rms)/.8);
01805                histFarPlaneNent1->Fill(plane,strip,entries);
01806            }
01807            else {
01808                ErrorReport << "Dodgy: " << crate << " "  << varc << " " << vmm
01809                            << " " << vaadc << " " << vachip << " " << vachannel
01810                            << " Plane: " << plane << " " << strip << " " << end
01811                            << " Led: " << box << " " << led << endl;
01812            }
01813            
01814        }
01815        else if(end==2) {
01816            if(box==crate) {  
01817                isReal=1;
01818                histNearPlaneLed2->Fill(plane,strip,led);
01819                histNearPlaneMean2->Fill(plane,strip,mean);
01820                histNearPlaneRms2->Fill(plane,strip,rms);
01821                histNearPlanePe2->Fill(plane,strip,(mean/rms)*(mean/rms)/.8);
01822                histNearPlaneNent2->Fill(plane,strip,entries);
01823            }
01824            else if(box/2 == crate/2) { 
01825                isReal=1;
01826                histFarPlaneLed2->Fill(plane,strip,led);                       
01827                histFarPlaneRms2->Fill(plane,strip,rms);
01828                histFarPlanePe2->Fill(plane,strip,(mean/rms)*(mean/rms)/.8);
01829                histFarPlaneMean2->Fill(plane,strip,mean);
01830                histFarPlaneNent2->Fill(plane,strip,entries);
01831            }
01832            else {
01833              ErrorReport << "Dodgy: " << crate << " "  << varc << " " << vmm
01834                   << " " << vaadc << " " << vachip << " " << vachannel
01835                   << " Plane: " << plane << " " << strip << " " << end
01836                   << " Led: " << box << " " << led << endl;
01837            }
01838        }
01839        if(isReal) {
01840            if(box==crate) {
01841                if(nearLedsHit.find((led-1)+20*box)==nearLedsHit.end()) {
01842                    nearLedsHit.insert(make_pair((led-1)+20*box,int(entries/getFractionOf64PerCrate(box))));
01843                }
01844                else {
01845                    nearLedsHit[(led-1)+20*box]+=int(entries/getFractionOf64PerCrate(box));
01846                }
01847                if(nearChipsHit.find(makeChipIndex(crate,varc,vmm,vaadc,vachip))
01848                   ==nearChipsHit.end()) {
01849                    
01850                    nearChipsHit.insert(make_pair(makeChipIndex(crate,varc,vmm,vaadc,vachip),entries));
01851                }
01852                else {
01853                    nearChipsHit[makeChipIndex(crate,varc,vmm,vaadc,vachip)]+=
01854                        entries;
01855                }
01856                if(nearChannelsHit.find(makeChannelIndex(crate,varc,vmm,vaadc,vachip,vachannel))==nearChannelsHit.end()) {
01857                    nearChannelsHit.insert(make_pair(makeChannelIndex(crate,varc,vmm,vaadc,vachip,vachannel),entries));
01858                }
01859                else {
01860                    nearChannelsHit[makeChannelIndex(crate,varc,vmm,vaadc,vachip,vachannel)]+=entries;
01861                }
01862            }
01863            else { 
01864                if(farLedsHit.find((led-1)+20*box)==farLedsHit.end()) {
01865                    farLedsHit.insert(make_pair((led-1)+20*box,int(entries/getFractionOf64PerCrate(box))));
01866                }
01867                else {
01868                    farLedsHit[(led-1)+20*box]+=int(entries/getFractionOf64PerCrate(box));
01869                }
01870                if(farChipsHit.find(makeChipIndex(crate,varc,vmm,vaadc,vachip))
01871                   ==farChipsHit.end()) {
01872                    farChipsHit.insert(make_pair(makeChipIndex(crate,varc,vmm,vaadc,vachip),entries));
01873                }
01874                else {
01875                    farChipsHit[makeChipIndex(crate,varc,vmm,vaadc,vachip)]+=entries;
01876                }
01877                if(farChannelsHit.find(makeChannelIndex(crate,varc,vmm,vaadc,vachip,vachannel))==farChannelsHit.end()) {
01878                    farChannelsHit.insert(make_pair(makeChannelIndex(crate,varc,vmm,vaadc,vachip,vachannel),entries));
01879                }
01880                else {
01881                    farChannelsHit[makeChannelIndex(crate,varc,vmm,vaadc,vachip,vachannel)]+=entries;
01882                }
01883            }
01884            if(ledsHit.find((led-1)+20*box)==ledsHit.end()) {
01885                ledsHit.insert(make_pair((led-1)+20*box,int(entries/getFractionOf64PerCrate(box))));    
01886            }
01887            else {
01888                ledsHit[(led-1)+20*box]+=int(entries/getFractionOf64PerCrate(box));
01889            }
01890        }
01891    }
01892    LAST_PLANE++;
01893    MSG("PEGain", Msg::kInfo)  << endl;
01894    ErrorReport << endl << endl 
01895                << "<<<<<<<<<<<<<<<<<<<<<<< BOX/LED REPORT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
01896                << endl;
01897    int maxLedHits[20]={0};
01898    int maxNearLedHits[20]={0};
01899    int maxFarLedHits[20]={0};
01900    int skipBox[16]={0};
01901    for(int b=0;b<16;b++) {
01902        int missingLeds[20]={0};
01903        int numMissing=0;
01904        for(int l=0;l<20;l++) {
01905            intMap::iterator ledPos=ledsHit.find(l+20*b);
01906            if(ledPos!=ledsHit.end()) {
01907                if(ledPos->second>maxLedHits[l]) maxLedHits[l]=ledPos->second;
01908                ledPos=nearLedsHit.find(l+20*b);
01909                if(ledPos!=nearLedsHit.end()) {
01910                    if(ledPos->second>maxNearLedHits[l]) 
01911                        maxNearLedHits[l]=ledPos->second;
01912                }
01913                ledPos=farLedsHit.find(l+20*b);
01914                if(ledPos!=farLedsHit.end()) {
01915                    if(ledPos->second>maxFarLedHits[l]) 
01916                        maxFarLedHits[l]=ledPos->second;
01917                }
01918            }
01919            else {
01920                // cout << "Missing Led " << l+1 << " Box " << b << endl;
01921                missingLeds[l]=1;
01922                numMissing++;
01923            }
01924                
01925        }
01926        if(numMissing==20) {
01927            skipBox[b]=1;
01928            ErrorReport << "Missing Pulser Box " << b << " Completely." << endl;
01929        }
01930        else if(numMissing>0) {
01931            for(int l=0;l<20;l++) {
01932                if(missingLeds[l]==1) {
01933                    ErrorReport << "Missing Led " << l+1 << " From Box " << b
01934                         << endl;
01935                }
01936            }
01937        }
01938    }
01939    
01940    for(int b=0;b<16;b++) {
01941        int numLow=0;
01942        int countBoxHits=0;
01943        int maxBoxHits=0;
01944        if(skipBox[b]) continue;
01945        for(int l=0;l<20;l++) {
01946            intMap::iterator ledPos=ledsHit.find(l+20*b);
01947            if(ledPos!=ledsHit.end()) {
01948                if(ledPos->second<0.9*maxLedHits[l]) {
01949                    numLow++;
01950                }
01951                countBoxHits+=ledPos->second;
01952                maxBoxHits+=maxLedHits[l];
01953            }
01954        }
01955        if(numLow==20) {
01956            skipBox[b]=2;
01957            ErrorReport << "Very Quiet Box " <<   b
01958                        << " Only " << countBoxHits << " Associated Hits (" 
01959                        << int(100.0*
01960                               float(countBoxHits)/
01961                               float(maxBoxHits)) << "%)" << endl;
01962            continue;
01963        }    
01964        for(int l=0;l<20;l++) {
01965            intMap::iterator ledPos=ledsHit.find(l+20*b);
01966            if(ledPos!=ledsHit.end()) {
01967                if(ledPos->second<0.9*maxLedHits[l]) {
01968                    ErrorReport << "Very Quiet Led " << l+1 << " From Box " << b
01969                                << " Only " <<  ledPos->second 
01970                                << " Associated Hits (" 
01971                                << int(100.0*
01972                                       float(ledPos->second)/
01973                                       float(maxLedHits[l])) << "%)" << endl;
01974                }
01975            }
01976        }
01977    }
01978    ErrorReport << "<<<<<<<<<<<<<<<<<<<<<<< END OF REPORT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
01979                << endl << endl;        
01980    
01981    
01982    ErrorReport << "<<<<<<<<<<<<<<<<<<<<<<< FEE REPORT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
01983                << endl;
01984    ErrorReport << "No Hits Beyond Plane " << LAST_PLANE-1 << endl;
01985    int missingCrates[16];
01986    int missingVarcs[16][3];
01987    int maxChip[2]={0};
01988    int maxChannel[2]={0};
01989    intMap::iterator channelPos;
01990    int lastChip=0;
01991    int numHitsInCrate[16];
01992    int numHitsInVarc[16][3];
01993    for(crate=0;crate<16;crate++) {
01994        numHitsInCrate[crate]=0;
01995        missingCrates[crate]=0;
01996        for(varc=0;varc<3;varc++) {
01997            numHitsInVarc[crate][varc]=0;
01998            missingVarcs[crate][varc]=0;
01999        }
02000    }
02001    int tempHitsOnChip=0;
02002    for(channelPos=nearChannelsHit.begin();
02003        channelPos!=nearChannelsHit.end();channelPos++) {
02004        getStuffFromChannelIndex(channelPos->first,&crate,&varc,
02005                                 &vmm,&vaadc,&vachip,&vachannel);
02006        numHitsInCrate[crate]+=channelPos->second;
02007        numHitsInVarc[crate][varc]+=channelPos->second;
02008        if(channelPos->second>maxChannel[0]) maxChannel[0]=channelPos->second;
02009        int tempIndex=makeChipIndex(crate,varc,vmm,vaadc,vachip);
02010        if(tempIndex!=lastChip) {
02011            if(maxChip[0]<tempHitsOnChip) maxChip[0]=tempHitsOnChip;
02012            tempHitsOnChip=0;
02013        }
02014        tempHitsOnChip+=channelPos->second;
02015        lastChip=tempIndex;
02016    }
02017    for(channelPos=farChannelsHit.begin();
02018        channelPos!=farChannelsHit.end();channelPos++) {
02019        getStuffFromChannelIndex(channelPos->first,&crate,&varc,
02020                                 &vmm,&vaadc,&vachip,&vachannel);
02021        numHitsInCrate[crate]+=channelPos->second;
02022        numHitsInVarc[crate][varc]+=channelPos->second;
02023        if(channelPos->second>maxChannel[1]) maxChannel[1]=channelPos->second;
02024        int tempIndex=makeChipIndex(crate,varc,vmm,vaadc,vachip);
02025        if(tempIndex!=lastChip) {
02026            if(maxChip[1]<tempHitsOnChip) maxChip[1]=tempHitsOnChip;
02027            tempHitsOnChip=0;
02028        }
02029        tempHitsOnChip+=channelPos->second;
02030        lastChip=tempIndex;
02031    }
02032        
02033    for(crate=0;crate<16;crate++) {
02034        if(numHitsInCrate[crate]==0) {
02035            ErrorReport << "Missing Crate --- Crate " << crate << endl;
02036 //         fillBadPlanes(badPlanes,crate);
02037 //         if(crate%2==0) {
02038 //             fillBadPlanes(badEvenNear,crate);
02039 //             fillBadPlanes(badOddFar,crate);
02040 //         }
02041 //         else {
02042 //             fillBadPlanes(badOddNear,crate);
02043 //             fillBadPlanes(badEvenFar,crate);
02044 //         }
02045            
02046            missingCrates[crate]=1;
02047            continue;
02048        }
02049        for(varc=0;varc<3;varc++) {
02050            if(numHitsInVarc[crate][varc]==0) {
02051                missingVarcs[crate][varc]=1;
02052                ErrorReport << "Missing Varc --- Crate " << crate 
02053                            << " Varc " << varc << endl; 
02054            }
02055        }
02056    }
02057 
02058    intMap::iterator nearPos=nearChipsHit.begin();
02059    intMap::iterator farPos=farChipsHit.begin();
02060    int missingChips[3][2]={{0,0},{0,0},{0,0}};
02061    int maxHitsInChip=maxChip[0]+maxChip[1];
02062    int maxHitsInChannel= maxChannel[0]+maxChannel[1];
02063    int tempPlane = -1;
02064    //cout << maxChip[0] << "\t" << maxChip[1] << endl;
02065    for(int index=0;index<2304;index++) {
02066        getStuffFromChipIndex(index,&crate,&varc,
02067                              &vmm,&vaadc,&vachip);
02068        // cout << "Doing " << crate << " "  << varc << " " << vmm 
02069        //   << " "  << vaadc << " " << vachip << endl;
02070        if(missingCrates[crate]) continue;
02071        if(missingVarcs[crate][varc]) continue;
02072        RawChannelId rcid(myVC.GetDetector(),ElecType::kVA,crate,varc,
02073                          vmm,vaadc,vachip,2); //Look at channel 2
02074        
02075        if(vachip==0) {
02076            tempPlane=ph.GetSEIdAltL(rcid).GetPlane();
02077        }
02078        ReadoutType::Readout_t rt = ph.GetReadoutType(rcid);
02079        if (rt & ReadoutType::kScintStrip && (tempPlane>0 && tempPlane<487)) {
02080            
02081            
02082            //Real Scintillator Hit
02083            nearPos=nearChipsHit.find(index);
02084            farPos=farChipsHit.find(index);
02085            missingChips[vachip][0]=0;
02086            missingChips[vachip][1]=0;
02087            
02088            if(nearPos!=nearChipsHit.end() && farPos!=farChipsHit.end()) {
02089                //            if(tempPlane==382 || tempPlane==384) {
02090              //                cout << "Case 1: " << crate << "\t" 
02091              //                     << varc << "\t" << vmm
02092              //                     << "\t" << vaadc << "\t" << vachip << "\t"
02093              //                     << nearPos->second << "\t" << farPos->second
02094              //                     << endl;
02095              //              }
02096                //Got hit on both ends.
02097                histNent->Fill(nearPos->second+farPos->second);
02098                if(nearPos->second<0.97*maxChip[0]) {
02099                    missingChips[vachip][0]=nearPos->second;
02100                }
02101                if(farPos->second<0.97*maxChip[1]) {
02102                    missingChips[vachip][1]=farPos->second;
02103                }
02104                
02105            }
02106            else if(nearPos!=nearChipsHit.end() && farPos==farChipsHit.end()) {
02107                
02108 //           if(tempPlane==382 || tempPlane==384) {
02109 //             cout << "Case 2: " << crate << "\t" << varc << "\t" << vmm
02110 //                  << "\t" << vaadc << "\t" << vachip << "\t"
02111 //                  << nearPos->second << "\t" << 0
02112 //                  << endl;
02113 //           }
02114                //Only got hit from near end.
02115                histNent->Fill(nearPos->second);
02116                if(nearPos->second<0.97*maxChip[0]) {
02117                    missingChips[vachip][0]=nearPos->second;
02118                }
02119                missingChips[vachip][1]=-1;
02120                
02121            }
02122            else if(nearPos==nearChipsHit.end() && farPos!=farChipsHit.end()) { 
02123 //             if(tempPlane==382 || tempPlane==384) {
02124 //             cout << "Case 3: " 
02125 //                  << crate << "\t" << varc << "\t" << vmm
02126 //                  << "\t" << vaadc << "\t" << vachip << "\t"
02127 //                  << 0 << "\t" << farPos->second
02128 //                  << endl;
02129 //           }
02130                    //Only got hit from far end
02131                histNent->Fill(farPos->second);
02132                missingChips[vachip][0]=-1;
02133                if(farPos->second<0.97*maxChip[1]) {
02134                    missingChips[vachip][1]=farPos->second;
02135                }
02136            }
02137            else if(nearPos==nearChipsHit.end() && farPos==farChipsHit.end()) {
02138 //           if(tempPlane==382 || tempPlane==384) {
02139 //             cout << "Case 4: " 
02140 //                  << crate << "\t" << varc << "\t" << vmm
02141 //                  << "\t" << vaadc << "\t" << vachip << "\t"
02142 //                  << 0 << "\t" << 0
02143 //                  << endl;
02144 //           }
02145                //Missing both ends
02146                histNent->Fill(0.0);
02147                missingChips[vachip][0]=-1;
02148                missingChips[vachip][1]=-1;
02149            }
02150            
02151            if(vachip==2) {
02152                //End of VFB
02153              if(missingChips[0][0]<0  && missingChips[1][0]<0 
02154                 && missingChips[2][0]<0 && missingChips[0][1]<0
02155                   && missingChips[1][1]<0 && missingChips[2][1]<0 ) {
02156                    if(tempPlane<LAST_PLANE) {
02157                        ErrorReport << "Missing VFB ----  "
02158                                    << crate << " " << varc << " " << vmm 
02159                                    << " " << vaadc << " -- Planes " 
02160                                    << tempPlane 
02161                                    << "-" << tempPlane+2 << endl;
02162                        //      fillBadPlanes(badPlanes,crate,varc,vmm,vaadc);
02163                        
02164         //             if(crate%2==0) {
02165 //                         fillBadPlanes(badEvenNear,crate,varc,vmm,vaadc);
02166 //                         fillBadPlanes(badOddFar,crate,varc,vmm,vaadc);
02167 //                     }
02168 //                     else {
02169 //                         fillBadPlanes(badOddNear,crate,varc,vmm,vaadc);
02170 //                         fillBadPlanes(badEvenFar,crate,varc,vmm,vaadc);
02171 //                     }
02172                    }
02173                }
02174                else if(missingChips[0][0]!=0 && 
02175                        missingChips[1][0]!=0 
02176                        && missingChips[2][0]!=0&& 
02177                        missingChips[0][1]!=0
02178                        && missingChips[1][1]!=0 && 
02179                        missingChips[2][1]!=0 ) {
02180                    int totHitsVFB=missingChips[0][0]+missingChips[1][0]+
02181                        missingChips[2][0]+missingChips[0][1]+missingChips[1][1]
02182                        +missingChips[2][1];
02183                    int maxHitsVFB=3*maxChip[0]+3*maxChip[1];
02184                    if(tempPlane<LAST_PLANE) {
02185                        ErrorReport << "Low VFB ----  "
02186                                    << crate << " " << varc << " " << vmm 
02187                                    << " " << vaadc << " -- Planes " 
02188                                    << tempPlane 
02189                                    << "-" << tempPlane+2 
02190                                    << " Only " << totHitsVFB << " Hits  ( "  
02191                                    << int(100.0*float(totHitsVFB)/
02192                                           float(maxHitsVFB)) 
02193                                    << "%)" << endl;
02194 //                     fillBadPlanes(badPlanes,crate,varc,vmm,vaadc);
02195 //                     if(crate%2==0) {
02196 //                         fillBadPlanes(badEvenNear,crate,varc,vmm,vaadc);
02197 //                         fillBadPlanes(badOddFar,crate,varc,vmm,vaadc);
02198 //                     }
02199 //                     else {
02200 //                         fillBadPlanes(badOddNear,crate,varc,vmm,vaadc);
02201 //                         fillBadPlanes(badEvenFar,crate,varc,vmm,vaadc);
02202 //                     }
02203                    }
02204                }
02205                else if(missingChips[0][0]!=0 ||  missingChips[1][0]!=0 
02206                        || missingChips[2][0]!=0 || missingChips[0][1]!=0
02207                        || missingChips[1][1]!=0 || missingChips[2][1]!=0){
02208                    //Missing some hits
02209                 
02210                    if((missingChips[0][0]!=0 ||  missingChips[1][0]!=0 
02211                        || missingChips[2][0]!=0) && 
02212                       !( missingChips[0][1]!=0 || missingChips[1][1]!=0 
02213                          || missingChips[2][1]!=0)) {
02214                        //Just Missing Near Side Flashes    
02215                    }
02216                    else if(!(missingChips[0][0]!=0 ||  missingChips[1][0]!=0 
02217                              || missingChips[2][0]!=0) && 
02218                            ( missingChips[0][1]!=0 || missingChips[1][1]!=0 
02219                              || missingChips[2][1]!=0)) {
02220                            //Just Missing Far Side Flashes
02221                        
02222                    }
02223                    else if((missingChips[0][0]!=0 ||  missingChips[1][0]!=0 
02224                             || missingChips[2][0]!=0) &&
02225                            ( missingChips[0][1]!=0 || missingChips[1][1]!=0 
02226                              || missingChips[2][1]!=0)) {
02227                        //Missing Both Side Flashes
02228 //                   if(tempPlane==382 || tempPlane==384) {
02229 //                     cout << "Near " << missingChips[0][0] << "\t" 
02230 //                          << missingChips[1][0] << "\t" 
02231 //                          << missingChips[2][0] << "\t"
02232 //                          << " Far  " << missingChips[0][1] << "\t"
02233 //                          << missingChips[1][1] << "\t"
02234 //                          << missingChips[2][1] << endl;
02235 //                   }
02236                        for(vachip=0;vachip<3;vachip++) { 
02237                            if(missingChips[vachip][0]<0 &&
02238                               missingChips[vachip][1]<0 ) {   
02239                                //Missing the chip.
02240                                
02241                                if(tempPlane<LAST_PLANE) {
02242                                 //    fillBadPlanes(badPlanes,crate,varc,vmm,
02243 //                                               vaadc,vachip);
02244 //                                 if(crate%2==0) {
02245 //                                     fillBadPlanes(badEvenNear,crate,
02246 //                                                   varc,vmm,vaadc,vachip);
02247 //                                     fillBadPlanes(badOddFar,crate,varc,
02248 //                                                   vmm,vaadc,vachip);
02249 //                                 }
02250 //                                 else {
02251 //                                     fillBadPlanes(badOddNear,crate,varc,
02252 //                                                   vmm,vaadc,vachip);
02253 //                                     fillBadPlanes(badEvenFar,crate,varc,
02254 //                                                   vmm,vaadc,vachip);
02255 //                                 }
02256                                    ErrorReport << "Missing Chip ----  ";
02257                                    ErrorReport 
02258                                        << crate << " " << varc << " " << vmm 
02259                                        << " " << vaadc << " " << vachip;
02260                                    if(vachip==2) {
02261                                        ErrorReport  
02262                                            << " -- Planes " 
02263                                            << tempPlane << "-"
02264                                            << tempPlane+2;
02265                                    }
02266                                    else if(vachip==1) {
02267                                        ErrorReport  
02268                                            << " -- Plane " << tempPlane+2;
02269                                    }
02270                                    else if(vachip==0) {
02271                                        ErrorReport  
02272                                            << " -- Plane " << tempPlane;
02273                                    }
02274                                    
02275                                    ErrorReport  << endl;
02276                                    
02277                                }
02278                            }
02279                            else if((missingChips[vachip][0]!=0 &&
02280                                    missingChips[vachip][1]!=0 ) ) {
02281                                int numBadChannels=0;
02282                                int numHitsInChip=0;
02283                                int numHitsInChannel=0;
02284                                int badChannel=0;
02285                                for(vachannel=2;vachannel<18;vachannel++) {
02286                                    int chanInd=
02287                                        makeChannelIndex(crate,varc,vmm,vaadc,
02288                                                         vachip,vachannel);
02289                                    channelPos=nearChannelsHit.find(chanInd);
02290                                    int tempNear=0;
02291                                    if(channelPos!=nearChannelsHit.end()) {
02292                                        tempNear=channelPos->second;
02293                                    }
02294                                    channelPos=farChannelsHit.find(chanInd);
02295                                    int tempFar=0;
02296                                    if(channelPos!=farChannelsHit.end()) {
02297                                        tempFar=channelPos->second;
02298                                    }
02299                                    numHitsInChip+=tempNear+tempFar;
02300                                    if(tempNear<  0.7*maxChannel[0] &&
02301                                       tempFar<0.7*maxChannel[1] ) {
02302                                        numHitsInChannel=tempNear+tempFar;
02303                                        numBadChannels++;
02304                                        badChannel=vachannel;
02305                                    }
02306                                }                                   
02307                                if(numBadChannels==1) {
02308                                    RawChannelId rcid2(myVC.GetDetector(),
02309                                                       ElecType::kVA,crate,varc,
02310                                                       vmm,vaadc,vachip,2);
02311                                    
02312                                    
02313                                    tempPlane=ph.GetSEIdAltL(rcid2).GetPlane();
02314                                    if(tempPlane<LAST_PLANE) {
02315                                        if(int(100.0*float(numHitsInChannel)/
02316                                               float(maxHitsInChannel))<50){
02317                                            ErrorReport 
02318                                                << "Very Low Channel/Pixel ----  ";
02319                                        }
02320                                        else {
02321                                            ErrorReport 
02322                                                << "Low Channel/Pixel      ----  ";
02323                                        }
02324                                        //          fillBadPlanes(badPlanes,crate,varc,vmm,
02325 //                                                       vaadc,vachip,vachannel);
02326 //                                         if(crate%2==0) {
02327 //                                             fillBadPlanes(badEvenNear,crate,
02328 //                                                           varc,vmm,vaadc,
02329 //                                                           vachip,vachannel);
02330 //                                             fillBadPlanes(badOddFar, 
02331 //                                                           crate,varc,
02332 //                                                           vmm,vaadc,
02333 //                                                           vachip,vachannel);
02334 //                                         }
02335 //                                         else {
02336 //                                             fillBadPlanes(badOddNear,
02337 //                                                           crate,varc,
02338 //                                                               vmm,vaadc,vachip,
02339 //                                                           vachannel);
02340 //                                             fillBadPlanes(badEvenFar,
02341 //                                                           crate,varc,
02342 //                                                           vmm, vaadc,vachip,
02343 //                                                           vachannel);
02344 //                                         }
02345                                        ErrorReport 
02346                                            << crate << " " << varc 
02347                                            << " " << vmm 
02348                                            << " " << vaadc << " " << vachip
02349                                            << " " << badChannel
02350                                            << " -- Plane "
02351                                            << tempPlane
02352                                            << " Only " 
02353                                            << numHitsInChannel
02354                                            << " Hits  ( "  
02355                                            << int(100.0*
02356                                                   float(numHitsInChannel)/
02357                                                   float(maxHitsInChannel)) 
02358                                            << "%)" << endl;
02359                                    }
02360                                }
02361                                else { 
02362                                    
02363                                    if(tempPlane<LAST_PLANE) {
02364                                        if(int(100.0*
02365                                               float(numHitsInChip)/
02366                                               float(maxHitsInChip))<50) {
02367                                            ErrorReport 
02368                                                << "Very Low Chip ----  ";
02369                                        }
02370                                        else {
02371                                            ErrorReport 
02372                                                << "Low Chip  ----  ";
02373                                        }  
02374                                        
02375 //                                     fillBadPlanes(badPlanes,crate,
02376 //                                                   varc,vmm,
02377 //                                                   vaadc,vachip);
02378 //                                     if(crate%2==0) {
02379 //                                         fillBadPlanes(badEvenNear,crate,
02380 //                                                       varc,vmm,vaadc,
02381 //                                                       vachip);
02382 //                                             fillBadPlanes(badOddFar,crate,
02383 //                                                           varc,
02384 //                                                           vmm,vaadc,vachip);
02385 //                                     }
02386 //                                     else {
02387 //                                         fillBadPlanes(badOddNear,crate,varc,
02388 //                                                       vmm,vaadc,vachip);
02389 //                                         fillBadPlanes(badEvenFar,crate,varc,
02390 //                                                       vmm,vaadc,vachip);
02391 //                                     }
02392                                        ErrorReport
02393                                            << crate << " " << varc 
02394                                            << " " << vmm 
02395                                            << " " << vaadc << " " << vachip;
02396                                        if(vachip==2) {
02397                                            ErrorReport  
02398                                                << " -- Planes " 
02399                                                << tempPlane << "-"
02400                                                << tempPlane+2;
02401                                        }
02402                                        else if(vachip==1) {
02403                                            ErrorReport  
02404                                                << " -- Plane " << tempPlane+2;
02405                                        }
02406                                        else if(vachip==0) {
02407                                            ErrorReport  
02408                                                << " -- Plane " << tempPlane;
02409                                        }
02410                                        ErrorReport 
02411                                            << " Only " << numHitsInChip
02412                                            << " Hits  ( "  
02413                                            << int(100.0*
02414                                                   float(numHitsInChip)/
02415                                                   float(maxHitsInChip)) 
02416                                            << "%)" << endl;
02417                                    }
02418                                }
02419                            }
02420 
02421                        }
02422                            
02423                    }
02424                }
02425            }
02426        }
02427    }
02428    
02429    ErrorReport 
02430        << "<<<<<<<<<<<<<<<<<<<<<<< END OF REPORT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
02431        << endl << endl;
02432 
02433    LAST_PLANE+=5;
02434 
02435    gStyle->SetOptStat(0);
02436 
02437    
02438    TCanvas *cantrans = new TCanvas("cantrans","cantrans",800,600);
02439    cantrans->Divide(1,2);
02440    cantrans->cd(1);
02441    histEvenPBTrans->SetAxisRange(0,LAST_PLANE);
02442    histEvenPBTrans->SetMaximum(0.5);
02443    histEvenPBTrans->Divide(histFarPlaneMean2,histNearPlaneMean1);
02444    histEvenPBTrans->SetTitle("Transmission (Far/Near) -- Even Pulser Boxes");
02445    histEvenPBTrans->GetXaxis()->SetTitle("Plane");
02446    histEvenPBTrans->GetYaxis()->SetTitle("Strip");
02447    histEvenPBTrans->Draw("colz");
02448    cantrans->cd(2);
02449    histOddPBTrans->SetAxisRange(0,LAST_PLANE);
02450    histOddPBTrans->SetMaximum(0.5);
02451    histOddPBTrans->Divide(histFarPlaneMean1,histNearPlaneMean2);
02452    histOddPBTrans->SetTitle("Transmission (Far/Near) -- Odd Pulser Boxes");
02453    histOddPBTrans->GetXaxis()->SetTitle("Plane");
02454    histOddPBTrans->GetYaxis()->SetTitle("Strip");
02455    histOddPBTrans->Draw("colz");
02456    
02457    
02458 
02459    TCanvas *canevenpbnent = new TCanvas("canevenpbnent","canevenpbnent",800,600);
02460    canevenpbnent->Divide(1,2);
02461    canevenpbnent->cd(1);
02462    histNearPlaneNent1->SetAxisRange(0,LAST_PLANE);
02463    histNearPlaneNent1->SetTitle("Num Entries -- Even Pulser Boxes Near Side (East)");
02464    histNearPlaneNent1->GetXaxis()->SetTitle("Plane");
02465    histNearPlaneNent1->GetYaxis()->SetTitle("Strip");
02466    histNearPlaneNent1->Draw("colz");
02467    canevenpbnent->cd(2);
02468    histFarPlaneNent2->SetAxisRange(0,LAST_PLANE);
02469    histFarPlaneNent2->SetTitle("Num Entries -- Even Pulser Boxes Far Side (West)");
02470    histFarPlaneNent2->GetXaxis()->SetTitle("Plane");
02471    histFarPlaneNent2->GetYaxis()->SetTitle("Strip");
02472    histFarPlaneNent2->Draw("colz");
02473    
02474    TCanvas *canoddpbnent = new TCanvas("canoddpbnent","canoddpbnent",800,600);
02475    canoddpbnent->Divide(1,2);
02476    canoddpbnent->cd(1);
02477    histNearPlaneNent2->SetAxisRange(0,LAST_PLANE);
02478    histNearPlaneNent2->SetTitle("Num Entries -- Odd Pulser Boxes Near Side (West)");
02479    histNearPlaneNent2->GetXaxis()->SetTitle("Plane");
02480    histNearPlaneNent2->GetYaxis()->SetTitle("Strip");
02481    histNearPlaneNent2->Draw("colz");
02482    canoddpbnent->cd(2);
02483    histFarPlaneNent1->SetAxisRange(0,LAST_PLANE);
02484    histFarPlaneNent1->SetTitle("Num Entries -- Odd Pulser Boxes Far Side (East)");
02485    histFarPlaneNent1->GetXaxis()->SetTitle("Plane");
02486    histFarPlaneNent1->GetYaxis()->SetTitle("Strip");
02487    histFarPlaneNent1->Draw("colz");
02488    
02489    
02490    TCanvas *canevenpbmean = new TCanvas("canevenpbmean","canevenpbmean",800,600);
02491    canevenpbmean->Divide(1,2);
02492    canevenpbmean->cd(1);
02493    histNearPlaneMean1->SetMaximum(15000);
02494    histNearPlaneMean1->SetMinimum(0);
02495    histNearPlaneMean1->SetAxisRange(0,LAST_PLANE);
02496    histNearPlaneMean1->SetTitle("Mean -- Even Pulser Boxes Near Side (East)");
02497    histNearPlaneMean1->GetXaxis()->SetTitle("Plane");
02498    histNearPlaneMean1->GetYaxis()->SetTitle("Strip");
02499    histNearPlaneMean1->Draw("colz");
02500    canevenpbmean->cd(2);
02501    histFarPlaneMean2->SetMaximum(15000);
02502    histFarPlaneMean2->SetMinimum(0);
02503    histFarPlaneMean2->SetAxisRange(0,LAST_PLANE);
02504    histFarPlaneMean2->SetTitle("Mean -- Even Pulser Boxes Far Side (West)");
02505    histFarPlaneMean2->GetXaxis()->SetTitle("Plane");
02506    histFarPlaneMean2->GetYaxis()->SetTitle("Strip");
02507    histFarPlaneMean2->Draw("colz");
02508    
02509    TCanvas *canoddpbmean = new TCanvas("canoddpbmean","canoddpbmean",800,600);
02510    canoddpbmean->Divide(1,2);
02511    canoddpbmean->cd(1);
02512    histNearPlaneMean2->SetMaximum(15000);
02513    histNearPlaneMean2->SetMinimum(0);
02514    histNearPlaneMean2->SetAxisRange(0,LAST_PLANE);
02515    histNearPlaneMean2->SetTitle("Mean -- Odd Pulser Boxes Near Side (West)");
02516    histNearPlaneMean2->GetXaxis()->SetTitle("Plane");
02517    histNearPlaneMean2->GetYaxis()->SetTitle("Strip");
02518    histNearPlaneMean2->Draw("colz");
02519    canoddpbmean->cd(2);
02520    histFarPlaneMean1->SetMaximum(15000);
02521    histFarPlaneMean1->SetMinimum(0);
02522    histFarPlaneMean1->SetAxisRange(0,LAST_PLANE);
02523    histFarPlaneMean1->SetTitle("Mean -- Odd Pulser Boxes Far Side (East)");
02524    histFarPlaneMean1->GetXaxis()->SetTitle("Plane");
02525    histFarPlaneMean1->GetYaxis()->SetTitle("Strip");
02526    histFarPlaneMean1->Draw("colz");
02527 
02528    TCanvas *canevenpbrms = new TCanvas("canevenpbrms","canevenpbrms",800,600);
02529    canevenpbrms->Divide(1,2);
02530    canevenpbrms->cd(1);
02531    histNearPlaneRms1->SetMaximum(15000);
02532    histNearPlaneRms1->SetMinimum(0);
02533    histNearPlaneRms1->SetAxisRange(0,LAST_PLANE);
02534    histNearPlaneRms1->SetTitle("Rms -- Even Pulser Boxes Near Side (East)");
02535    histNearPlaneRms1->GetXaxis()->SetTitle("Plane");
02536    histNearPlaneRms1->GetYaxis()->SetTitle("Strip");
02537    histNearPlaneRms1->Draw("colz");
02538    canevenpbrms->cd(2);
02539    histFarPlaneRms2->SetMaximum(15000);
02540    histFarPlaneRms2->SetMinimum(0);
02541    histFarPlaneRms2->SetAxisRange(0,LAST_PLANE);
02542    histFarPlaneRms2->SetTitle("Rms -- Even Pulser Boxes Far Side (West)");
02543    histFarPlaneRms2->GetXaxis()->SetTitle("Plane");
02544    histFarPlaneRms2->GetYaxis()->SetTitle("Strip");
02545    histFarPlaneRms2->Draw("colz");
02546 
02547    TCanvas *canoddpbrms = new TCanvas("canoddpbrms","canoddpbrms",800,600);
02548    canoddpbrms->Divide(1,2);
02549    canoddpbrms->cd(1);
02550    histNearPlaneRms2->SetMaximum(15000);
02551    histNearPlaneRms2->SetMinimum(0);
02552    histNearPlaneRms2->SetAxisRange(0,LAST_PLANE);
02553    histNearPlaneRms2->SetTitle("Rms -- Odd Pulser Boxes Near Side (West)");
02554    histNearPlaneRms2->GetXaxis()->SetTitle("Plane");
02555    histNearPlaneRms2->GetYaxis()->SetTitle("Strip");
02556    histNearPlaneRms2->Draw("colz");
02557    canoddpbrms->cd(2);
02558    histFarPlaneRms1->SetMaximum(15000);
02559    histFarPlaneRms1->SetMinimum(0);
02560    histFarPlaneRms1->SetAxisRange(0,LAST_PLANE);
02561    histFarPlaneRms1->SetTitle("Rms -- Odd Pulser Boxes Far Side (East)");
02562    histFarPlaneRms1->GetXaxis()->SetTitle("Plane");
02563    histFarPlaneRms1->GetYaxis()->SetTitle("Strip");
02564    histFarPlaneRms1->Draw("colz");
02565 
02566    TCanvas *canevenpbpe = new TCanvas("canevenpbpe","canevenpbpe",800,600);
02567    canevenpbpe->Divide(1,2);
02568    canevenpbpe->cd(1);
02569    histNearPlanePe1->SetMaximum(15000);
02570    histNearPlanePe1->SetMinimum(0);
02571    histNearPlanePe1->SetAxisRange(0,LAST_PLANE);
02572    histNearPlanePe1->SetTitle("Pe -- Even Pulser Boxes Near Side (East)");
02573    histNearPlanePe1->GetXaxis()->SetTitle("Plane");
02574    histNearPlanePe1->GetYaxis()->SetTitle("Strip");
02575    histNearPlanePe1->Draw("colz");
02576    canevenpbpe->cd(2);
02577    histFarPlanePe2->SetMaximum(15000);
02578    histFarPlanePe2->SetMinimum(0);
02579    histFarPlanePe2->SetAxisRange(0,LAST_PLANE);
02580    histFarPlanePe2->SetTitle("Pe -- Even Pulser Boxes Far Side (West)");
02581    histFarPlanePe2->GetXaxis()->SetTitle("Plane");
02582    histFarPlanePe2->GetYaxis()->SetTitle("Strip");
02583    histFarPlanePe2->Draw("colz");
02584 
02585    TCanvas *canoddpbpe = new TCanvas("canoddpbpe","canoddpbpe",800,600);
02586    canoddpbpe->Divide(1,2);
02587    canoddpbpe->cd(1);
02588    histNearPlanePe2->SetMaximum(15000);
02589    histNearPlanePe2->SetMinimum(0);
02590    histNearPlanePe2->SetAxisRange(0,LAST_PLANE);
02591    histNearPlanePe2->SetTitle("Pe -- Odd Pulser Boxes Near Side (West)");
02592    histNearPlanePe2->GetXaxis()->SetTitle("Plane");
02593    histNearPlanePe2->GetYaxis()->SetTitle("Strip");
02594    histNearPlanePe2->Draw("colz");
02595    canoddpbpe->cd(2);
02596    histFarPlanePe1->SetMaximum(15000);
02597    histFarPlanePe1->SetMinimum(0);
02598    histFarPlanePe1->SetAxisRange(0,LAST_PLANE);
02599    histFarPlanePe1->SetTitle("Pe -- Odd Pulser Boxes Far Side (East)");
02600    histFarPlanePe1->GetXaxis()->SetTitle("Plane");
02601    histFarPlanePe1->GetYaxis()->SetTitle("Strip");
02602    histFarPlanePe1->Draw("colz");
02603 
02604    
02605    TCanvas *canevenpbled = new TCanvas("canevenpbled","canevenpbled",800,600);
02606    canevenpbled->Divide(1,2);
02607    canevenpbled->cd(1);
02608    histNearPlaneLed1->SetAxisRange(0,LAST_PLANE);
02609    histNearPlaneLed1->SetTitle("Led -- Even Pulser Boxes Near Side (East)");
02610    histNearPlaneLed1->GetXaxis()->SetTitle("Plane");
02611    histNearPlaneLed1->GetYaxis()->SetTitle("Strip");
02612    histNearPlaneLed1->Draw("colz");
02613    canevenpbled->cd(2);
02614    histFarPlaneLed2->SetAxisRange(0,LAST_PLANE);
02615    histFarPlaneLed2->SetTitle("Led -- Even Pulser Boxes Far Side (West)");
02616    histFarPlaneLed2->GetXaxis()->SetTitle("Plane");
02617    histFarPlaneLed2->GetYaxis()->SetTitle("Strip");
02618    histFarPlaneLed2->Draw("colz");
02619    
02620    TCanvas *canoddpbled = new TCanvas("canoddpbled","canoddpbled",800,600);
02621    canoddpbled->Divide(1,2);
02622    canoddpbled->cd(1);
02623    histNearPlaneLed2->SetAxisRange(0,LAST_PLANE);
02624    histNearPlaneLed2->SetTitle("Led -- Odd Pulser Boxes Near Side (West)");
02625    histNearPlaneLed2->GetXaxis()->SetTitle("Plane");
02626    histNearPlaneLed2->GetYaxis()->SetTitle("Strip");
02627    histNearPlaneLed2->Draw("colz");
02628    canoddpbled->cd(2);
02629    histFarPlaneLed1->SetAxisRange(0,LAST_PLANE);
02630    histFarPlaneLed1->SetTitle("Led-- Odd Pulser Boxes Far Side (East)");
02631    histFarPlaneLed1->GetXaxis()->SetTitle("Plane");
02632    histFarPlaneLed1->GetYaxis()->SetTitle("Strip");
02633    histFarPlaneLed1->Draw("colz");
02634    
02635    
02636 
02637   canevenpbnent->Write();
02638   canoddpbnent->Write();
02639   canevenpbled->Write();
02640   canoddpbled->Write();
02641   canevenpbmean->Write();
02642   canoddpbmean->Write();
02643   canevenpbrms->Write();
02644   canoddpbrms->Write();
02645   canevenpbpe->Write();
02646   canoddpbpe->Write();
02647   cantrans->Write();
02648 
02649 
02650 
02651    fpout->Write();
02652    fpout->Close();
02653    return 0;
02654 }
02656    
02657 int PEGainModule::getMyIndex(PlexStripEndId seid) {
02658    Int_t tempEnd=seid.GetEnd();
02659    Int_t tempStrip=seid.GetStrip();
02660    Int_t tempPlane=seid.GetPlane();
02661    return tempStrip+(24*tempPlane)+1440*(tempEnd-1);
02662 }
02663 
02664 int PEGainModule::GetEndFromIndex(Int_t index) {
02665    return (index/1440) +1;
02666 }
02667 
02668 int PEGainModule::GetPlaneFromIndex(Int_t index) {
02669    Int_t tempRemainder=index%1440;
02670    return tempRemainder/24;
02671 }
02672 
02673 int PEGainModule::GetStripFromIndex(Int_t index) {
02674    Int_t tempRemainder=index%1440;
02675    return tempRemainder%24;
02676 }
02677 
02678 
02679 
02680 //......................................................................
02681 
02682 float PEGainModule::getFractionOf64PerCrate(int crate) {
02683     if(crate<6) return 1.0;
02684     if(crate<8) return 56.0/64.0;
02685     if(crate<14) return 1.0;
02686     return 44.0/64.0;
02687 }
02688 
02689 //......................................................................
02690  int PEGainModule::makeChannelIndex(int tempCrate,int tempVarc,int tempVmm,
02691                                    int tempVaadc, int tempVachip,
02692                                    int tempVachannel) {
02693 
02694     return tempVachannel+22*tempVachip+66*tempVaadc+
02695         132*tempVmm+1584*tempVarc+6336*tempCrate;
02696 
02697 }
02698 //......................................................................
02699 
02700 int PEGainModule::makeChipIndex(int crate,int varc,int vmm,int vaadc,int vachip) {
02701     
02702     return vachip + 3*vaadc + 6*vmm +36*varc + 144*crate;
02703     
02704 }
02705 //......................................................................
02706  void PEGainModule::getStuffFromChannelIndex(int index, int *crate,int *varc,
02707                                              int *vmm,int *vaadc,int *vachip,
02708                                              int *vachannel) {
02709     
02710     int tempcrate=index/6336;
02711     int tempvarc=(index-tempcrate*6336)/1584;
02712     int tempvmm=(index-tempcrate*6336-tempvarc*1584)/132;
02713     int tempvaadc=(index-tempcrate*6336-tempvarc*1584-tempvmm*132)/66;
02714     int tempvachip=(index-tempcrate*6336-tempvarc*1584-
02715                     tempvmm*132-66*tempvaadc)/22;
02716     int tempvachannel=(index-tempcrate*6336-tempvarc*1584-
02717                        tempvmm*132-66*tempvaadc-22*tempvachip);
02718     
02719     *crate=tempcrate;
02720     *varc=tempvarc;
02721     *vmm=tempvmm;
02722     *vaadc=tempvaadc;
02723     *vachip=tempvachip;
02724     *vachannel=tempvachannel;
02725 }
02726 //......................................................................
02727  void PEGainModule::getStuffFromChipIndex(int index, int *crate,int *varc,
02728                                           int *vmm,int *vaadc,int *vachip) {
02729     
02730     int tempcrate=index/144;
02731     int tempvarc=(index-tempcrate*144)/36;
02732     int tempvmm=(index-tempcrate*144-tempvarc*36)/6;
02733     int tempvaadc=(index-tempcrate*144-tempvarc*36-tempvmm*6)/3;
02734     int tempvachip=(index-tempcrate*144-tempvarc*36-tempvmm*6-3*tempvaadc);
02735     
02736     *crate=tempcrate;
02737     *varc=tempvarc;
02738     *vmm=tempvmm;
02739     *vaadc=tempvaadc;
02740     *vachip=tempvachip;
02741 }
02742 
02743 //......................................................................
02744 int PEGainModule::getEastBox(int plane) {
02745     if(plane<1 || plane==249 || plane>485) return -2;
02746     if(plane<65) return 0;
02747     if(plane<129) return 2;
02748     if(plane<193) return 4;
02749     if(plane<250) return 6;
02750     if(plane<314) return 8;
02751     if(plane<378) return 10;
02752     if(plane<442) return 12;
02753     return 14;
02754     
02755 }
02756 //......................................................................
02757 
02758 int PEGainModule::getWestBox(int plane) {
02759     return getEastBox(plane)+1;
02760 }
02761 
02762 int PEGainModule::ledToAhstray(int plane,int led) {
02763     if((plane<250 && ((plane-1)/2)%2==0) ||
02764        (plane>=250 && (plane/2)%2==1)) {
02765         return 21-led;
02766     }
02767     else {
02768         if(led==20) return 20;
02769         return 20-led;
02770     }
02771 }

Generated on Fri Mar 28 15:37:18 2008 for loon by  doxygen 1.3.9.1