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

SexyPedReco.cxx

Go to the documentation of this file.
00001 #define SexyPedReco_cxx
00002 
00003 #include "SexyPedReco.h"
00004 
00005 using namespace std;
00006 
00007 CVSID("$Id: SexyPedReco.cxx,v 1.8 2007/11/11 05:27:55 rhatcher Exp $");
00008 JOBMODULE(SexyPedReco,"SexyPedReco","");
00009 
00010 //......................................................................
00011 
00012 SexyPedReco::SexyPedReco() {
00013 
00014  fFile = 0;
00015 
00016  myPedAna = 0;
00017  
00018  fSexyPedTree = 0;
00019  fPedTree     = 0;
00020  fSparTree    = 0;
00021 
00022  //fGetTableTree = true;
00023  //fStoreTree    = true;
00024  //fOnline       = false;
00025 
00026  fGotCalledPed  = false;
00027  fGotCalledSpar = false;
00028 }
00029 
00030 //......................................................................
00031 
00032 SexyPedReco::~SexyPedReco() {
00033 
00034   return;
00035 }
00036 
00037 //......................................................................
00038 
00039 JobCResult SexyPedReco::Ana(const MomNavigator *mom) {
00040 
00041   if(!fFile) {
00042     char filename[180];
00043     RawRecord *rr = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord"));
00044     if (rr == 0) return JobCResult::kFailed;
00045       
00046     const RawDaqHeader* daqHdr = dynamic_cast<const RawDaqHeader*>(rr->GetRawHeader());      
00047 
00048     if (daqHdr) frunNum = daqHdr->GetRun();
00049 
00050     sprintf(filename,"SexyPedestalTree_%d.root",frunNum);
00051 
00052 
00053     if(fStoreTree) fFile = new TFile(filename,"RECREATE");
00054 
00055     if(fFile!=0) {
00056       fSexyPedTree = new TTree("sexyPedTree","SexyPedestal TTree");
00057       
00058       fSexyPedTree->Branch("run",  &frunNum,  "run/I");
00059       fSexyPedTree->Branch("error",&ferror,   "error/I");
00060       fSexyPedTree->Branch("crate",&fcrate,   "crate/I");
00061       fSexyPedTree->Branch("varc", &fvarc,    "varc/I");
00062       fSexyPedTree->Branch("vmm",  &fvmm,     "vmm/I");
00063       fSexyPedTree->Branch("vfb",  &fvfb,     "vfb/I");
00064       fSexyPedTree->Branch("va",   &fva,      "va/I");
00065       fSexyPedTree->Branch("vach", &fvach,    "vach/I");
00066       fSexyPedTree->Branch("adc",  &fadc,     "adc/I");
00067       fSexyPedTree->Branch("tdc",  &ftdc,     "tdc/D");
00068       fSexyPedTree->Branch("plane",&fplane,   "plane/I");
00069       fSexyPedTree->Branch("tUTC", &ftimeUTC, "tUTC/D");
00070       
00071       if(fGetTableTree) {
00072         
00073         fPedTree = new TTree("pedTableTree","Online Pedestals Table TTree");
00074         fPedTree->Branch("crate",&icrate,     "crate/I");
00075         fPedTree->Branch("varc", &ivarc,      "varc/I");
00076         fPedTree->Branch("vmm",  &ivmm,       "vmm/I");
00077         fPedTree->Branch("vfb",  &ivfb,       "vfb/I");
00078         fPedTree->Branch("va",   &iva,        "va/I");
00079         fPedTree->Branch("vach", &ivach,      "vach/I");
00080         fPedTree->Branch("adc",  &fPedTable,  "adc/I");
00081         fPedTree->Branch("time", &fLoadTime,  "time/D");
00082         
00083         fSparTree = new TTree("sparTableTree","Sparsicification Table TTree");
00084         fSparTree->Branch("crate",&icrate,    "crate/I");
00085         fSparTree->Branch("varc", &ivarc,     "varc/I");
00086         fSparTree->Branch("vmm",  &ivmm,      "vmm/I");
00087         fSparTree->Branch("vfb",  &ivfb,      "vfb/I");
00088         fSparTree->Branch("va",   &iva,       "va/I");
00089         fSparTree->Branch("vach", &ivach,     "vach/I");
00090         fSparTree->Branch("adc",  &fSparTable,"adc/I");
00091         fSparTree->Branch("time", &fLoadTime, "time/D");
00092       }
00093     }
00094   }
00095 
00096   TObject* tobj;
00097   TIter    fragiter = mom->FragmentIter();
00098 
00099   while( ( tobj = fragiter.Next() ) ) { //Loop over MOM fragments
00100     RawRecord* rawrec;
00101     if( ( rawrec = dynamic_cast<RawRecord*>(tobj) ) ) {  //Loop over RawRecords
00102 
00103       //RAWSNARLHEARDERBLOCK info:
00104       const RawSnarlHeaderBlock* snarlHdr = 
00105         dynamic_cast<const RawSnarlHeaderBlock*> (rawrec->FindRawBlock("RawSnarlHeaderBlock"));
00106       if (snarlHdr) {
00107         ftimeUTC = snarlHdr->GetTriggerTime().GetSec(); //From 1/1/1970
00108         MSG("SexyPedReco", Msg::kInfo) << "Timeframe: " << snarlHdr->GetTimeFrameNum() << endl;
00109       }
00110       else MSG("SexyPedReco", Msg::kDebug) << "There was not RawSnarlHeaderBlock this time!" << endl;
00111       
00112       //Loop over other blocks:
00113       TIter rdbit = rawrec->GetRawBlockIter();
00114       TObject *tob;
00115       while ((tob = rdbit())) {
00116         
00117         //Pedestal Table read in:
00118         RawPedestalTableBlock* rptb;
00119         if( tob->InheritsFrom("RawPedestalTableBlock") ) {
00120           rptb = dynamic_cast<RawPedestalTableBlock*>(tob);
00121           
00122           this->GetPedestalTable(rptb);
00123         }
00124         
00125         //Sparsifier Table read in:
00126         RawSparsifierTableBlock* rstb;
00127         if( tob->InheritsFrom("RawSparsifierTableBlock") ) {
00128           rstb = dynamic_cast<RawSparsifierTableBlock*>(tob);
00129 
00130           this->GetSparsificationTable(rstb);
00131 
00132         }
00133 
00134         //RawDigits get into SexyPedestal TTree:
00135         RawDigitDataBlock* rdb;
00136         if( tob->InheritsFrom("RawDigitDataBlock") ) {
00137           rdb = dynamic_cast<RawDigitDataBlock*>(tob);
00138 
00139           this->GetSexyPedestals(rdb);
00140         }
00141         //return JobCResult::kFailed; 
00142       }
00143     }
00144   }
00145 
00146   return JobCResult::kPassed;
00147 }
00148 
00149 //......................................................................
00150 
00151 void SexyPedReco::GetPedestalTable(RawPedestalTableBlock *rptb) {
00152   
00153   if(!fGetTableTree || fGotCalledPed) return;
00154 
00155   MSG("SexyPedReco", Msg::kDebug) << endl << "Creating the Pedestal TTree" << endl << endl;
00156   
00157   fGotCalledPed = true;
00158   
00159   //Load time of the table:
00160   fLoadTime = rptb->GetLoadTime().GetSec();
00161   
00162   MSG("SexyPedReco", Msg::kInfo) << "Pedestal Table Loaded on: " << endl;
00163   rptb->GetLoadTime().Print();
00164   cout << endl;
00165   
00166   for(icrate = 0; icrate < 16; icrate++) {
00167     for(ivarc = 0; ivarc < 3; ivarc++) {
00168       for(ivmm = 0; ivmm < 6; ivmm++) {
00169         for(ivfb = 0; ivfb < 2; ivfb++) {
00170           for(iva = 0; iva < 3; iva++) {
00171             for(ivach = 0; ivach < 22; ivach++) {
00172               
00173               const RawChannelId thisRawChannel(Detector::kFar,
00174                                                 ElecType::kVA,
00175                                                 icrate, ivarc, ivmm, ivfb, iva, ivach);
00176               
00177               fPedTable = rptb->GetPedValue(thisRawChannel);
00178 
00179               MSG("SexyPedReco", Msg::kDebug) << fPedTable << "\t" 
00180                                               << icrate    << "\t" 
00181                                               << ivarc    << "\t" 
00182                                               << ivmm     << "\t" 
00183                                               << ivfb     << "\t" 
00184                                               << iva      << "\t" 
00185                                               << ivach    << endl;
00186               
00187               fPedTree->Fill();
00188             }
00189           }
00190         }
00191       }
00192     }
00193   }
00194   return;
00195 }
00196 
00197 //......................................................................
00198 
00199 void SexyPedReco::GetSparsificationTable(RawSparsifierTableBlock *rstb) {
00200 
00201   if(!fGetTableTree || fGotCalledSpar) return;
00202 
00203   MSG("SexyPedReco", Msg::kDebug) << "Creating the Sparsification TTree" << endl << endl;
00204   
00205   fGotCalledSpar = true;
00206   
00207   //Load time of the table:           
00208   fLoadTime = rstb->GetLoadTime().GetSec();
00209   
00210   MSG("SexyPedReco", Msg::kInfo) << "Sparsification Table Loaded on: " << endl; 
00211   rstb->GetLoadTime().Print();
00212   cout << endl;
00213     
00214   for(icrate = 0; icrate < 16; icrate++) {
00215     for(ivarc = 0; ivarc < 3; ivarc++) { 
00216       for(ivmm = 0; ivmm < 6; ivmm++) { 
00217         for(ivfb = 0; ivfb < 2; ivfb++) {
00218           for(iva = 0; iva < 3; iva++) {
00219             for(ivach = 0; ivach < 22; ivach++) {
00220               
00221               RawChannelId thisRawChannel(Detector::kFar,
00222                                           ElecType::kVA,
00223                                           icrate, ivarc, ivmm, ivfb, iva, ivach);
00224               
00225               fSparTable = rstb->GetThresholdValue(thisRawChannel);
00226                                 
00227               MSG("SexyPedReco", Msg::kDebug) << fSparTable << "\t" 
00228                                               << icrate    << "\t" 
00229                                               << ivarc    << "\t" 
00230                                               << ivmm     << "\t" 
00231                                               << ivfb     << "\t" 
00232                                               << iva      << "\t" 
00233                                               << ivach    << endl;
00234 
00235               fSparTree->Fill();
00236             }
00237           }
00238         }
00239       }
00240     }
00241   }
00242 
00243   return;
00244 }
00245 
00246 //......................................................................
00247 
00248 void SexyPedReco::GetSexyPedestals(RawDigitDataBlock *rdb) {
00249 
00250   MSG("SexyPedReco", Msg::kDebug) << "Filling the Sexy Pedestal TTree with RawDigits data" << endl;
00251 
00252   TIter rdit = rdb->GetDatumIter();
00253   RawDigit *rd;
00254   
00255   //Get validity context
00256   while ( (rd = (RawDigit*) rdit()) ) {
00257     RawChannelId rawid = rd->GetChannel();
00258     
00259     fcrate = rawid.GetCrate();
00260     fvarc  = rawid.GetVarcId();
00261     fvmm   = rawid.GetVmm();
00262     fvfb   = rawid.GetVaAdcSel();
00263     fva    = rawid.GetVaChip();
00264     fvach  = rawid.GetVaChannel();
00265     
00266     fadc   = rd->GetADC();
00267     ftdc   = rd->GetTDC()*1.5625e-9;
00268     ferror = rd->GetErrorCode();
00269     
00270     if(!fOnline) {
00271       PlexHandle ph(rdb->GetVldContext());
00272       fplane = ph.GetSEIdAltL(rawid).GetPlane();
00273     }
00274     else fplane = -1;
00275 
00276     //
00277     //Fill SexyPedestal TTree:
00278     //
00279     if(fStoreTree) fSexyPedTree->Fill();
00280 
00281     //
00282     // Perform Online calculations
00283     //
00284     if(fOnline){ //&& ferror&2==2) {
00285 
00286       if(!myPedAna) myPedAna = SexyPedAna::InstantiateMe();
00287 
00288       Int_t key = SexyPedestal::EncriptMeAKey(fcrate,fvarc,fvmm,fvfb,fva,fvach);
00289       
00290       //If it does not found (i.e. iter points to end) -> then create it:
00291       if( myPedAna->mySP.find(key) == myPedAna->mySP.end() ) myPedAna->mySP[key] = new SexyPedestal();
00292 
00293       myPedAna->frun = frunNum;      
00294       myPedAna->mySP[key]->AddressMe(fcrate,fvarc,fvmm,fvfb,fva,fvach);
00295       myPedAna->mySP[key]->SetPlane(fplane);
00296       myPedAna->mySP[key]->SetError(ferror);
00297       myPedAna->mySP[key]->InputSPEntry(fadc);
00298 
00299       if(ferror>2)
00300         MSG("SexyPedReco", Msg::kError) << "Found ErrorCode (!=2): " << ferror << endl;
00301 
00302     }
00303     //if(ferror>2)
00304     //MSG("SexyPedReco", Msg::kError) << "Found Errors on data: " << ferror << endl;
00305   }
00306   return;
00307 }
00308 
00309 //......................................................................
00310 
00311 void SexyPedReco::Config(const Registry& r) {
00312 
00313   Int_t tmpi;
00314 
00315   if(r.Get("GetPed-SparsTables", tmpi)) fGetTableTree  = tmpi;
00316   if(r.Get("StoreSexyTree", tmpi))      fStoreTree     = tmpi;
00317   if(r.Get("OnlineVersion", tmpi))      fOnline        = tmpi;
00318 
00319   return;
00320 }
00321 
00322 //......................................................................
00323 
00324 const Registry& SexyPedReco::DefaultConfig() const { 
00325 
00326   static Registry r;
00327 
00328   string name=this->JobCModule::GetName();
00329   name+=".config.default";
00330   r.SetName(name.c_str());
00331 
00332   r.UnLockValues();
00333   r.Set("GetPed-SparsTables",1);
00334   r.Set("StoreSexyTree",1);
00335   r.Set("OnlineVersion",0);
00336   r.LockValues();
00337 
00338   return r;
00339 }       
00340 
00341 
00342 //......................................................................
00343 
00344 void SexyPedReco::EndJob() {
00345 
00346   //
00347   // Store Tree into File
00348   //
00349   if(fStoreTree) {
00350 
00351     fFile->Write();
00352     fFile->Close();
00353   }
00354 
00355   //
00356   // Perform Quick Analysis for Online purposes:
00357   //
00358   if(fOnline) myPedAna->DoOnlineAnalysis();
00359 
00360   return; 
00361 }
00362 
00363 //EOF

Generated on Mon Jun 16 14:58:36 2008 for loon by  doxygen 1.3.9.1