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

BiggestChopModule.cxx

Go to the documentation of this file.
00001 
00002 // $Id: BiggestChopModule.cxx,v 1.6 2006/10/25 15:04:00 tagg Exp $
00003 //
00004 // FILL_IN: [Document your code!!]
00005 //
00006 // n.tagg1@physics.ox.ac.uk
00008 #include "BiggestChopModule.h"
00009 #include "DigitVector.h"
00010 #include "CandChopListHandle.h"
00011 #include "CandChopList.h"
00012 
00013 #include "MessageService/MsgService.h"
00014 #include "MinosObjectMap/MomNavigator.h"
00015 #include "JobControl/JobCModuleRegistry.h" // For JOBMODULE macro
00016 #include "Algorithm/AlgFactory.h"
00017 #include "CandData/CandRecord.h"
00018 #include "Candidate/CandContext.h"
00019 #include "CandDigit/CandDigitListHandle.h"
00020 #include "CandDigit/CandDigitList.h"
00021 #include "CandDigit/CandDigitHandle.h"
00022 
00023 #include "DataUtil/GetRawBlock.h"
00024 #include "RawData/RawDigitDataBlock.h"
00025 #include "RawData/RawDigit.h"
00026 #include "Plex/PlexHandle.h"
00027 #include "Calibrator/Calibrator.h"
00028 #include "Conventions/Munits.h"
00029 
00030 
00031 JOBMODULE(BiggestChopModule, "BiggestChopModule",
00032           "Chooses the biggest chop from the list.");
00033 CVSID(" $Id: BiggestChopModule.cxx,v 1.6 2006/10/25 15:04:00 tagg Exp $");
00034 
00035 BiggestChopModule::BiggestChopModule() :
00036   fChopsWithLi(0),
00037   fSnarlsWithLi(0)
00038 {
00039 }
00040 
00041 //......................................................................
00042 
00043 BiggestChopModule::~BiggestChopModule()
00044 {
00045   MSG("BiggestChop",Msg::kInfo) << "Number of chops rejected as LI event: "   << fChopsWithLi << endl;
00046   MSG("BiggestChop",Msg::kInfo) << "Number of snarls with an  LI event:   "   << fSnarlsWithLi << endl;
00047 }
00048 
00049 //......................................................................
00050 
00051 JobCResult BiggestChopModule::Reco(MomNavigator* mom)
00052 {
00053   JobCResult result = JobCResult::kPassed;
00054 
00055   // config.
00056   Registry& cfg = this->GetConfig();
00057   const char* algName        = cfg.GetCharString("BiggestChopAlgorithm");
00058   const char* algConfigName  = cfg.GetCharString("BiggestChopAlgConfig");
00059   const char* listIn         = cfg.GetCharString("ListIn");
00060   const char* listOut        = cfg.GetCharString("ListOut");
00061   bool        switchPerToTemp = cfg.GetInt("SwitchPersToTemp");
00062   double      minEnergy      = cfg.GetDouble("MinEnergy");
00063   bool        omitLiEvents   = cfg.GetInt("OmitLiEvents");
00064   double      liVetoWindowLow = cfg.GetDouble("LiVetoWindowLow");
00065   double      liVetoWindowHigh= cfg.GetDouble("LiVetoWindowHigh");
00066   
00067   // Find PrimaryCandidateRecord fragment in MOM.
00068   CandRecord *candrec = dynamic_cast<CandRecord *>
00069     (mom->GetFragment("CandRecord", "PrimaryCandidateRecord"));
00070   if (candrec == 0) {
00071     MSG("BiggestChop", Msg::kWarning) << "No PrimaryCandidateRecord in MOM."
00072                                  << endl;
00073     return JobCResult::kFailed;
00074   }
00075 
00076   
00077   if(switchPerToTemp) {
00078     // The user requested that we get rid of the original CandDigitList
00079     // in favor of the new (chopped) list.
00080     // Find the original digit list. of chops.
00081     CandDigitListHandle *orig_cdlh = dynamic_cast<CandDigitListHandle*>
00082       (candrec->FindCandHandle("CandDigitListHandle", listOut));
00083    
00084     if(orig_cdlh)
00085       candrec->SwitchCandHandlePersToTemp(orig_cdlh);
00086   }
00087 
00088   // find the list of chops.
00089   CandChopListHandle *chopList = dynamic_cast<CandChopListHandle*>
00090     (candrec->FindCandHandle("CandChopListHandle", listIn));
00091 
00092 
00093   if(!chopList) {
00094     MSG("BiggestChop",Msg::kError) << "Could not find a ChopList in Mom." << endl;
00095     result.SetWarning().SetFailed();
00096     return result;
00097   }
00098 
00099   if(chopList->GetNDaughters()==0) {
00100     MSG("BiggestChop",Msg::kError) << "Could not find any Chops in the ChopList." << endl;
00101     result.SetWarning().SetFailed();
00102     return result;
00103   }
00104 
00105   
00106   const VldContext* contextptr = chopList->GetVldContext();
00107 
00108   // Find the RawDigitDataBlock.
00109   // Use it to find any TPMT hits to reject LI
00110   double liTime = 100.;
00111   if(omitLiEvents) {
00112     const RawDigitDataBlock* rddb = DataUtil::GetRawBlock<RawDigitDataBlock>(mom);
00113     if(!rddb) {
00114       MSG("BiggestChop",Msg::kError) << "Could not find a RawDigitDataBlock in Mom." << endl;
00115       result.SetWarning().SetFailed();
00116       return result;
00117     }
00118     assert(contextptr);
00119     PlexHandle plex(*contextptr);
00120 
00121     RawDigit *rawdigit;
00122     TIter iter = rddb->GetDatumIter();
00123     TObject* tobj;
00124     while( (tobj=iter.Next() ) ) {
00125       if( ( rawdigit = dynamic_cast<RawDigit*>(tobj) ) ) {;
00126         RawDigit* rawdigit = dynamic_cast<RawDigit*>(tobj);
00127         
00128         RawChannelId rcid = rawdigit->GetChannel();
00129         ReadoutType::Readout_t type = plex.GetReadoutType(rcid);
00130         
00131         if(type == ReadoutType::kFlashTrigPMT) {
00132           if( rawdigit->GetADC() > 100) {
00133             liTime = Calibrator::Instance().GetTimeFromTDC(rawdigit->GetTDC(),rawdigit->GetChannel());    
00134             MSG("BiggestChop",Msg::kDebug) << "Found LI trigger at " << liTime << endl;
00135           }
00136         }
00137       }
00138     }
00139   }
00140 
00141   // Loop through and find the best.
00142   CandDigitListHandleItr listItr(chopList->GetDaughterIterator());
00143 
00144   CandDigitListHandle bestChop;
00145   double              bestChopEnergy = -1;
00146   bool                vetoedLi = false;
00147 
00148   double vetoLow  = liTime + liVetoWindowLow;
00149   double vetoHigh = liTime + liVetoWindowHigh;
00150 
00151   while( CandDigitListHandle *chop = listItr()) {
00152     
00153     // Add up the energy in this chop.
00154     double energy = 0;    
00155     double chopStart = 99e9;
00156     double chopEnd   = -99e9;
00157     CandDigitHandleItr digitItr(chop->GetDaughterIterator());
00158     while(CandDigitHandle *cdh = digitItr()) {
00159       if(!cdh->GetPlexSEIdAltL().IsVetoShield()) {
00160         energy += cdh->GetCharge();
00161         double t = cdh->GetTime();
00162         if(t<chopStart) chopStart = t;
00163         if(t>chopEnd)   chopEnd   = t;
00164       }
00165     }
00166     
00167     // Is this chop an LI event?    
00168     double choptime = chop->GetAbsTime();   
00169     bool isLI = false;
00170 
00171     MSG("BiggestChop",Msg::kDebug) << "Comparing chop time " << choptime 
00172                                    << " to " << liTime 
00173                                    << " delta = " << chopStart-liTime << endl;    
00174     
00175     // look for any intersection with the LI event, from -1 to +31 us from the 
00176     // TPMT hit.
00177     if( (chopEnd>vetoLow) && (chopStart<vetoHigh) ) isLI = true;
00178     
00179     // See if we have a winner.
00180     if(energy>bestChopEnergy) {
00181       if(isLI){
00182         vetoedLi = true;
00183         fChopsWithLi++;
00184       }    
00185 
00186       if(isLI && omitLiEvents) {
00187         MSG("BiggestChop",Msg::kDebug) << "Chop is too close to an LI event." << endl;  
00188       } else {     
00189         bestChopEnergy = energy;
00190         bestChop = *chop;
00191       }
00192     }     
00193   }
00194 
00195   if(vetoedLi) fSnarlsWithLi++; // Statistics gathering.
00196      
00197   if(bestChopEnergy<minEnergy) {
00198     // We didn't find a match.
00199     MSG("Chop",Msg::kWarning) << "Found insufficient energy in any chop. NO chop chosen" << endl;
00200     return JobCResult::kFailed;
00201   }
00202 
00203   MSG("Chop",Msg::kDebug) << "Chose chop " << bestChop.GetName() << " with energy " << bestChopEnergy << endl;
00204   
00205   // Ok, now we want a copy of bestChop. Boy, this is laborious:
00206   DigitVector v(&bestChop);
00207   AlgFactory &af = AlgFactory::GetInstance();
00208   AlgHandle adlh = af.GetAlgHandle(algName,algConfigName);
00209   CandContext cx(this, mom);
00210   cx.SetDataIn(&v);
00211   CandDigitListHandle outList = CandDigitList::MakeCandidate(adlh,cx);
00212   outList.SetName(listOut);
00213   outList.SetTitle("Biggest chop chosen by BiggestChopModule");
00214  
00215   candrec->SecureCandHandle(outList);
00216                      
00217 
00218   return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00219 }
00220 
00221 //......................................................................
00222 
00223 
00224 
00225 JobCResult BiggestChopModule::Ana(const MomNavigator* /*mom*/)
00226 {
00227   return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00228 }
00229 
00230 //......................................................................
00231 
00232 const Registry& BiggestChopModule::DefaultConfig() const
00233 {
00234   //======================================================================
00235   // Supply the default configuration for the module
00236   //======================================================================
00237   static Registry r; // Default configuration for module
00238   
00239   // Set name of config
00240   std::string name = this->JobCModule::GetName();
00241   name += ".config.default";
00242   r.SetName(name.c_str());
00243   
00244   // Set values in configuration
00245   r.UnLockValues();
00246   r.Set("BiggestChopAlgorithm","AlgChop");
00247   r.Set("BiggestChopAlgConfig","default");
00248   r.Set("ListIn",         "candchoplist");
00249   r.Set("ListOut",        "canddigitlist");
00250   r.Set("SwitchPersToTemp",1);
00251   r.Set("MinEnergy",      0.0);
00252   r.Set("OmitLiEvents",   1);
00253   r.Set("LiVetoWindowLow",-1.0*Munits::microsecond);
00254   r.Set("LiVetoWindowHigh",31.0*Munits::microsecond);
00255 
00256   r.LockValues();
00257 
00258   return r;
00259 }
00260 

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