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

FarDetSliceListModule.cxx

Go to the documentation of this file.
00001 
00002 #include "FarDetSliceListModule.h"
00003 #include "FarDetSliceListHandle.h"
00004 #include "FarDetSliceHandle.h"
00005 
00006 #include "Algorithm/AlgConfig.h"
00007 #include "Algorithm/AlgFactory.h"
00008 #include "Algorithm/AlgHandle.h"
00009 
00010 #include "MessageService/MsgService.h"  
00011 #include "JobControl/JobCModuleRegistry.h"
00012 #include "JobControl/JobCommand.h"
00013 #include "MinosObjectMap/MomNavigator.h"
00014 
00015 #include "RawData/RawRecord.h"
00016 #include "RawData/RawDaqSnarlHeader.h"
00017 #include "RawData/RawDigit.h"
00018 #include "RawData/RawChannelId.h"
00019 
00020 #include "Candidate/CandContext.h"
00021 #include "CandData/CandRecord.h"
00022 #include "CandData/CandHeader.h"
00023 
00024 #include "CandDigit/CandDigitHandle.h"
00025 #include "CandDigit/CandDeMuxDigitHandle.h"
00026 #include "RecoBase/CandStripHandle.h"
00027 #include "RecoBase/CandStripListHandle.h"
00028 
00029 #include "UgliGeometry/UgliGeomHandle.h"
00030 #include "UgliGeometry/UgliPlnNode.h"
00031 #include "Validity/VldContext.h"
00032 #include "Plex/PlexHandle.h"
00033 #include "Plex/PlexPlaneId.h"
00034 
00035 #include "TDirectory.h"
00036 
00037 CVSID("$Id: FarDetSliceListModule.cxx,v 1.3 2008/08/25 13:03:10 blake Exp $");
00038 
00039 JOBMODULE(FarDetSliceListModule,"FarDetSliceListModule","Making CandSlices");
00040 
00041 FarDetSliceListModule::FarDetSliceListModule() :
00042   fFarDetSliceFile(0),
00043   fFarDetSliceTree(0),
00044   fListIn("CandStripListHandle"),
00045   fListOut("FarDetSliceListHandle"),
00046   fFilterOnOff(0),
00047   fFilterMinPlanes(5),
00048   fFilterFC(0),
00049   fFilterPC(0),
00050   fFilter(0)
00051 {
00052 
00053 }
00054 
00055 FarDetSliceListModule::~FarDetSliceListModule()
00056 {
00057 
00058 }
00059     
00060 void FarDetSliceListModule::BeginJob()
00061 {
00062   MSG("FarDetSlice",Msg::kDebug) << " *** FarDetSliceListModule::BeginJob( ) *** " << endl;
00063 
00064   /*
00065   AlgFactory &af = AlgFactory::GetInstance();
00066   af.Register("AlgFarDetSliceList","default","libFarDetSlice.so","AlgConfig");
00067   af.Register("AlgFarDetSlice","default","libFarDetSlice.so","AlgConfig");
00068   */
00069 }
00070   
00071 JobCResult FarDetSliceListModule::Reco(MomNavigator *mom)
00072 {
00073   MSG("FarDetSlice",Msg::kDebug) << " *** FarDetSliceListModule::Reco( ) *** " << endl;
00074 
00075   fFilter=0;
00076   JobCResult result(JobCResult::kPassed);
00077 
00078   // get candrecord
00079   CandRecord* candrec = dynamic_cast<CandRecord*>(mom->GetFragment("CandRecord","PrimaryCandidateRecord"));
00080   if( candrec==0 ){
00081     MSG("FarDetSlice",Msg::kDebug) << "  *** FAILED TO FIND CANDRECORD *** " << endl;
00082     return result.SetFailed();
00083   }
00084 
00085   // make striplist handle
00086   CandStripListHandle* cslh = dynamic_cast<CandStripListHandle*>(candrec->FindCandHandle("CandStripListHandle",fListIn.Data()));
00087   if( cslh ){
00088     MSG("FarDetSlice",Msg::kDebug) << "  *** MAKE HANDLE *** " << endl;
00089 
00090     AlgFactory &af = AlgFactory::GetInstance();
00091     AlgHandle ah = af.GetAlgHandle("AlgFarDetSliceList", "default");
00092   
00093     CandContext cx(this, mom);
00094     cx.SetCandRecord(candrec);
00095     cx.SetDataIn(cslh);
00096     FarDetSliceListHandle myslicelist = FarDetSliceList::MakeCandidate(ah,cx);
00097     myslicelist.SetName(fListOut.Data());
00098     myslicelist.SetTitle(TString("Created by FarDetSliceListModule"));
00099 
00100     candrec->SecureCandHandle(myslicelist);
00101   }
00102 
00103   // contained event filter 
00104   FarDetSliceListHandle* csh = dynamic_cast<FarDetSliceListHandle*>(candrec->FindCandHandle("FarDetSliceListHandle"));
00105   if( csh ){
00106     fFilter = this->ApplyFilter(csh);
00107   }
00108 
00109   // apply filter
00110   if( fFilterOnOff ){
00111     MSG("FarDetSlice",Msg::kDebug) << "  *** APPLY FILTER *** " << endl;
00112 
00113     if( fFilter ){
00114       MSG("FarDetSlice",Msg::kDebug) << "   *** PASSED FILTER *** " << endl; 
00115       return result.SetPassed(); 
00116     }
00117     else{
00118       MSG("FarDetSlice",Msg::kDebug) << "   *** FAILED FILTER *** " << endl; 
00119       return result.SetFailed();
00120     } 
00121   }
00122 
00123   return result;
00124 }
00125   
00126 JobCResult FarDetSliceListModule::Ana(const MomNavigator* mom)
00127 {
00128   MSG("FarDetSlice",Msg::kDebug) << " *** FarDetSliceListModule::Ana( ) *** " << endl;
00129 
00130   JobCResult result(JobCResult::kPassed);  
00131   run=-1; snarl=-1; timeframe=-1;
00132 
00133   Int_t i;
00134 
00135   RawRecord *rawrec = dynamic_cast<RawRecord *>(mom->GetFragment("RawRecord"));
00136   if(rawrec){
00137 
00138     const RawDaqSnarlHeader* rawheader = dynamic_cast<const RawDaqSnarlHeader*>(rawrec->GetRawHeader());
00139     if(rawheader){
00140       if(run<0) run = rawheader->GetRun(); 
00141       if(snarl<0) snarl = rawheader->GetSnarl();
00142       if(timeframe<0) timeframe = rawheader->GetTimeFrameNum();
00143     }
00144 
00145     TIter rawrecitr = rawrec->GetRawBlockIter();
00146     TObject *tob;
00147     while((tob = rawrecitr())){
00148       if(tob->InheritsFrom("RawSnarlHeaderBlock")){
00149         RawSnarlHeaderBlock* rdb = (RawSnarlHeaderBlock*)(tob);
00150         if(run<0) run = rdb->GetRun(); 
00151         if(snarl<0) snarl = rdb->GetSnarl();
00152         if(timeframe<0) timeframe = rdb->GetTimeFrameNum();
00153         date = (((VldTimeStamp)(rdb->GetTriggerTime())).GetSec()-1059696000)/(3600*24);
00154         time = (((VldTimeStamp)(rdb->GetTriggerTime())).GetSec()-1059696000)%(3600*24);
00155       }
00156     }
00157   }  
00158 
00159   CandRecord* candrec = dynamic_cast<CandRecord*>(mom->GetFragment("CandRecord","PrimaryCandidateRecord"));
00160   if(candrec==0){
00161     return result.SetFailed();
00162   }
00163 
00164   VldContext *vldc = (VldContext*)(candrec->GetVldContext());
00165   UgliGeomHandle ugh(*vldc);
00166   PlexHandle ph(*vldc);
00167 
00168   FarDetSliceListHandle* myslicelist = dynamic_cast<FarDetSliceListHandle*>(candrec->FindCandHandle("FarDetSliceListHandle"));
00169   if(myslicelist==0){
00170     return result.SetFailed();
00171   }
00172 
00173   TIter myitr(myslicelist->GetDaughterIterator());
00174   FarDetSliceHandle* myslice = dynamic_cast<FarDetSliceHandle*>(myitr());
00175   if(myslice==0){
00176     return result.SetFailed();
00177   }
00178 
00179   MSG("FarDetSlice",Msg::kDebug) << " *** FOUND SLICE *** " << endl
00180                                  << "   run=" << run << " snarl=" << snarl << " timeframe=" << timeframe << endl;
00181   
00182   if(!fFarDetSliceFile){      
00183     // TString mystring("results/fardet.slice");  
00184     // mystring.Append("."); mystring+=run; 
00185     // mystring.Append(".root");
00186     TString mystring("fardet.slice.root");
00187     TDirectory* tmpd = gDirectory;
00188     fFarDetSliceFile = new TFile(mystring.Data(),"RECREATE");
00189     fFarDetSliceTree = new TTree("SliceTree","SliceTree");
00190     fFarDetSliceTree->SetAutoSave(100);
00191     fFarDetSliceTree->Branch("run",&run,"run/I");
00192     fFarDetSliceTree->Branch("snarl",&snarl,"snarl/I");
00193     fFarDetSliceTree->Branch("timeframe",&timeframe,"timeframe/I");
00194     fFarDetSliceTree->Branch("time",&time,"time/I");
00195     fFarDetSliceTree->Branch("date",&date,"date/I");
00196     fFarDetSliceTree->Branch("planes",&planes,"planes/I");
00197     fFarDetSliceTree->Branch("strips",&strips,"strips/I");
00198     fFarDetSliceTree->Branch("begpln",&begpln,"begpln/I");
00199     fFarDetSliceTree->Branch("endpln",&endpln,"endpln/I");
00200     fFarDetSliceTree->Branch("charge",&charge,"charge/D");
00201     fFarDetSliceTree->Branch("qSM1",qSM1,"qSM1[11]/D");
00202     fFarDetSliceTree->Branch("qSM2",qSM2,"qSM2[11]/D");
00203     fFarDetSliceTree->Branch("xSM1",xSM1,"xSM1[11]/D");
00204     fFarDetSliceTree->Branch("xSM2",xSM2,"xSM2[11]/D");
00205     fFarDetSliceTree->Branch("ySM1",ySM1,"ySM1[11]/D");
00206     fFarDetSliceTree->Branch("ySM2",ySM2,"ySM2[11]/D");
00207     fFarDetSliceTree->Branch("zSM1",zSM1,"zSM1[11]/D");
00208     fFarDetSliceTree->Branch("zSM2",zSM2,"zSM2[11]/D");
00209     fFarDetSliceTree->Branch("fidcharge",&fidcharge,"fidcharge/D");
00210     fFarDetSliceTree->Branch("maxplncharge",&maxplncharge,"maxplncharge/D");
00211     fFarDetSliceTree->Branch("edges",&edges,"edges/I");
00212     fFarDetSliceTree->Branch("edgesSM1",&edgesSM1,"edgesSM1/I");
00213     fFarDetSliceTree->Branch("edgesSM2",&edgesSM2,"edgesSM2/I");
00214     fFarDetSliceTree->Branch("eventidSM1",&eventidSM1,"eventidSM1/I");
00215     fFarDetSliceTree->Branch("eventidSM2",&eventidSM2,"eventidSM2/I");
00216     fFarDetSliceTree->Branch("eventidX",&eventidX,"eventidX/I");
00217     fFarDetSliceTree->Branch("eventid",&eventid,"eventid/I");
00218     gDirectory = tmpd;
00219   }
00220 
00221 
00222   if(fFarDetSliceFile){
00223 
00224     planes=myslice->GetGoodPlanes();
00225     strips=myslice->GetGoodStrips();
00226     begpln=myslice->GetBegPlane();
00227     endpln=myslice->GetEndPlane();
00228     charge=myslice->GetCharge();
00229     fidcharge=myslice->GetFidCharge();
00230     maxplncharge=myslice->GetMaxPlaneCharge();
00231     edges=myslice->GetEdges();
00232     edgesSM1=myslice->GetEdgesSM1();
00233     edgesSM2=myslice->GetEdgesSM2();
00234     eventidSM1=myslice->GetEventIdSM1();
00235     eventidSM2=myslice->GetEventIdSM2();
00236     eventidX=myslice->GetEventIdX();
00237     eventid=myslice->GetEventId();
00238 
00239     for(i=0;i<11;i++){
00240       qSM1[i]=myslice->GetFidChargeSM1(i);
00241       qSM2[i]=myslice->GetFidChargeSM2(i);
00242     }
00243     
00244     for(i=0;i<11;i++){
00245       xSM1[i]=myslice->GetMeanXPosSM1(i);
00246       xSM2[i]=myslice->GetMeanXPosSM2(i);
00247     }
00248 
00249     for(i=0;i<11;i++){
00250       ySM1[i]=myslice->GetMeanYPosSM1(i);
00251       ySM2[i]=myslice->GetMeanYPosSM2(i);
00252     }
00253 
00254     for(i=0;i<11;i++){
00255       zSM1[i]=myslice->GetMeanZPosSM1(i);
00256       zSM2[i]=myslice->GetMeanZPosSM2(i);
00257     }
00258 
00259     TDirectory* tmpd = gDirectory;
00260     fFarDetSliceFile->cd();
00261     fFarDetSliceTree->Fill();
00262     gDirectory = tmpd;
00263   }
00264 
00265   return result;
00266 }
00267   
00268 const Registry& FarDetSliceListModule::DefaultConfig() const
00269 {
00270   MSG("FarDetSlice",Msg::kDebug) << " *** FarDetSliceListModule::DefaultConfig( ) *** " << endl;
00271 
00272   static Registry r;
00273   r.SetName("FarDetSliceListModule.config.default");
00274   r.UnLockValues();
00275   r.Set("FilterOnOff",fFilterOnOff);
00276   r.Set("FilterMinPlanes",fFilterMinPlanes);
00277   r.Set("FilterFC",fFilterFC);
00278   r.Set("FilterPC",fFilterPC);
00279   r.Set("ListIn",fListIn);
00280   r.Set("ListOut",fListOut);
00281   r.Set("MinPlane",0);
00282   r.Set("MaxPlane",485);
00283   r.Set("CheckInstall",0);
00284   r.Set("EdgePlnCut",4);
00285   r.Set("EdgeRadCut",0.3);
00286   r.Set("EdgeWidthCut",1.33);
00287   r.Set("EdgeChargeCut",6.0);
00288   r.Set("FidChargeCut",10.0);
00289   r.LockValues();
00290 
00291   AlgFactory &af = AlgFactory::GetInstance();
00292 
00293   af.Register("AlgFarDetSliceList","default");
00294   AlgHandle ah_list = af.GetAlgHandle("AlgFarDetSliceList","default");
00295   AlgConfig &ac_list = ah_list.GetAlgConfig();
00296   ac_list.UnLockValues();
00297   ac_list.Set("MinPlane",0);
00298   ac_list.Set("MaxPlane",485);
00299   ac_list.Set("CheckInstall",0);
00300   ac_list.LockValues();
00301 
00302   af.Register("AlgFarDetSlice","default");
00303   AlgHandle ah_slice = af.GetAlgHandle("AlgFarDetSlice","default");
00304   AlgConfig &ac_slice = ah_slice.GetAlgConfig();
00305   ac_slice.UnLockValues();
00306   ac_slice.Set("MinPlane",0);
00307   ac_slice.Set("MaxPlane",485);
00308   ac_slice.Set("CheckInstall",0);
00309   ac_slice.Set("EdgePlnCut",4);
00310   ac_slice.Set("EdgeRadCut",0.3);
00311   ac_slice.Set("EdgeWidthCut",1.33);
00312   ac_slice.Set("EdgeChargeCut",6.0);
00313   ac_slice.Set("FidChargeCut",10.0);
00314   ac_slice.LockValues();
00315 
00316   return r;
00317 }
00318   
00319 void FarDetSliceListModule::Config(const Registry &r)
00320 {
00321   MSG("FarDetSlice",Msg::kDebug) << " *** FarDetSliceListModule::Config( ) *** " << endl;
00322 
00323   Double_t tmpdub; Int_t tmpint; const char* tmpchar = 0;
00324 
00325   if(r.Get("FilterOnOff",tmpint)) fFilterOnOff = tmpint;
00326   if(r.Get("FilterMinPlanes",tmpint)) fFilterMinPlanes = tmpint;
00327   if(r.Get("FilterFC",tmpint)) fFilterFC = tmpint;
00328   if(r.Get("FilterPC",tmpint)) fFilterPC = tmpint;
00329   if(r.Get("ListIn",tmpchar)) fListIn = tmpchar;
00330   if(r.Get("ListOut",tmpchar)) fListOut = tmpchar;
00331 
00332   AlgFactory &af = AlgFactory::GetInstance();
00333 
00334   AlgHandle ah_list = af.GetAlgHandle("AlgFarDetSliceList","default");
00335   AlgConfig &ac_list = ah_list.GetAlgConfig();
00336   ac_list.UnLockValues();
00337   if(r.Get("MinPlane",tmpint)) ac_list.Set("MinPlane",tmpint);
00338   if(r.Get("MaxPlane",tmpint)) ac_list.Set("MaxPlane",tmpint);
00339   if(r.Get("CheckInstall",tmpint)) ac_list.Set("CheckInstall",tmpint);
00340   ac_list.LockValues();
00341 
00342   AlgHandle ah_slice = af.GetAlgHandle("AlgFarDetSlice","default");
00343   AlgConfig &ac_slice = ah_slice.GetAlgConfig();
00344   ac_slice.UnLockValues();
00345   if(r.Get("MinPlane",tmpint)) ac_slice.Set("MinPlane",tmpint);
00346   if(r.Get("MaxPlane",tmpint)) ac_slice.Set("MaxPlane",tmpint);
00347   if(r.Get("CheckInstall",tmpint)) ac_slice.Set("CheckInstall",tmpint);
00348   if(r.Get("EdgePlnCut",tmpint)) ac_slice.Set("EdgePlnCut",tmpint);
00349   if(r.Get("EdgeRadCut",tmpdub)) ac_slice.Set("EdgeRadCut",tmpdub);
00350   if(r.Get("EdgeWidthCut",tmpdub)) ac_slice.Set("EdgeWidthCut",tmpdub);
00351   if(r.Get("EdgeChargeCut",tmpdub)) ac_slice.Set("EdgeChargeCut",tmpdub);
00352   if(r.Get("FidChargeCut",tmpdub)) ac_slice.Set("FidChargeCut",tmpdub);
00353   ac_slice.LockValues();
00354 
00355   MSG("FarDetSlice",Msg::kDebug) << "  configuration : " << endl
00356                                 << "     FilterOnOff=" << fFilterOnOff << endl
00357                                 << "     FilterMinPlanes=" << fFilterMinPlanes << endl
00358                                 << "     FilterFC=" << fFilterFC << endl
00359                                 << "     FilterPC=" << fFilterPC << endl
00360                                 << "     ListIn=" << fListIn.Data() << endl
00361                                 << "     ListOut=" << fListOut.Data() << endl;
00362 
00363   return;
00364 }
00365   
00366 void FarDetSliceListModule::HandleCommand(JobCommand *command)
00367 {
00368   TString cmd = command->PopCmd();
00369   if(cmd=="Set"){
00370     TString opt = command->PopOpt();
00371 
00372   }
00373 }
00374   
00375 void FarDetSliceListModule::EndJob()
00376 {
00377   MSG("FarDetSlice",Msg::kDebug) << " *** FarDetSliceListModule::EndJob( ) *** " << endl;
00378 
00379   if(fFarDetSliceFile){
00380     MSG("FarDetSlice",Msg::kDebug) << " *** saving SLICE INFO to file *** " << endl;
00381     TDirectory* tmpddd = gDirectory;
00382     fFarDetSliceFile->cd();
00383     fFarDetSliceTree->Write();
00384     fFarDetSliceFile->Close();
00385     gDirectory = tmpddd;
00386     MSG("FarDetSlice",Msg::kDebug) << "    ... data saved to file *** " << endl;
00387   }
00388 }
00389 
00390 Int_t FarDetSliceListModule::ApplyFilter(FarDetSliceListHandle* csh)
00391 {  
00392   Int_t filter=0;
00393 
00394   TIter myitr(csh->GetDaughterIterator());
00395   FarDetSliceHandle* myslice = dynamic_cast<FarDetSliceHandle*>(myitr());
00396 
00397   if( myslice ){
00398     MSG("FarDetSlice",Msg::kDebug)
00399       << endl
00400       << " eventid=" << myslice->GetEventId()
00401       << "  ( FC=" << fFilterFC 
00402       << " , PC=" << fFilterPC << " ) " << endl
00403       << " good planes=" << myslice->GetGoodPlanes()
00404       << "  ( U=" << myslice->GetGoodUPlanes() 
00405       << " , V=" << myslice->GetGoodVPlanes()
00406       << " , min=" << fFilterMinPlanes << " ) " << endl
00407       << " good strips=" << myslice->GetGoodStrips() 
00408       << " fidcharge=" << myslice->GetFidCharge() << endl;
00409   }
00410 
00411   if( myslice 
00412    && myslice->GetEventId()>-1
00413    && myslice->GetGoodUPlanes()>1 && myslice->GetGoodVPlanes()>1
00414    && myslice->GetGoodPlanes()>2 && myslice->GetGoodPlanes()>=fFilterMinPlanes ){  
00415 
00416     if( !fFilterFC && !fFilterPC ) filter=1;
00417     if( fFilterFC && myslice->GetEventId()==0 ) filter=1;
00418     if( fFilterPC && myslice->GetEventId()==1 ) filter=1;
00419 
00420   }
00421 
00422   return filter;
00423 }

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