Blinder Class Reference

#include <Blinder.h>

Inheritance diagram for Blinder:
JobCModule

List of all members.

Classes

class  BlindingFunction

Public Member Functions

 Blinder ()
 ~Blinder ()
virtual JobCResult Ana (const MomNavigator *mom)
virtual JobCResult Reco (MomNavigator *mom)
const RegistryDefaultConfig () const
void Config (const Registry &r)
Float_t GetBlindingProb (Float_t eventLength, Float_t eventEnergy, Int_t epoch=11)

Private Member Functions

Bool_t GetInfo (const MomNavigator *mom, Int_t &run, Int_t &snarl, Int_t &epoch, Float_t &length, Float_t &energy)
const REROOT_NeuKinGetTruth (const MomNavigator *mom)

Private Attributes

Int_t fSeed
TFile * fFile
TNtuple * fTree
TRandom * fRandom
TRandom * fParameterChooser
BlindingFunction fBlindingFunction

Detailed Description

Definition at line 27 of file Blinder.h.


Constructor & Destructor Documentation

Blinder::Blinder (  ) 

Definition at line 81 of file Blinder.cxx.

References fBlindingFunction, fFile, fParameterChooser, fRandom, fSeed, fTree, and Blinder::BlindingFunction::SetParameters().

00082 {
00083   fSeed = 0;
00084   fFile = 0;
00085   fTree = 0;
00086 
00087   fRandom = new TRandom3;
00088   fParameterChooser = new TRandom3;
00089   fBlindingFunction.SetParameters(fParameterChooser,fSeed);
00090 }

Blinder::~Blinder (  ) 

Definition at line 94 of file Blinder.cxx.

References fFile, fParameterChooser, fRandom, and fTree.

00095 {
00096   if(fFile) {
00097     fFile->cd();
00098     fTree->Write();
00099     fFile->Write();
00100     fFile->Close();
00101   }
00102   if(fRandom) delete fRandom;
00103   if(fParameterChooser) delete fParameterChooser;
00104 }


Member Function Documentation

JobCResult Blinder::Ana ( const MomNavigator mom  )  [virtual]

Implement this for read only access to the MomNavigator

This function returns kPassed if the event is allowed in the open dataset, or kFailed if the event should be in the blind data set.

If the relevant info isn't available, it returns kPassed.

Reimplemented from JobCModule.

Definition at line 108 of file Blinder.cxx.

References Blinder::BlindingFunction::EventBlindProb(), fBlindingFunction, fParameterChooser, fRandom, fSeed, GetInfo(), JobCResult::kFailed, JobCResult::kPassed, run(), and Blinder::BlindingFunction::SetParameters().

00109 {
00116   Int_t run;
00117   Int_t snarl;
00118   Int_t epoch;
00119   Float_t length;
00120   Float_t energy;
00121 
00122 
00123   if(GetInfo(mom,run,snarl,epoch,length,energy)) {
00124     // Set the parameters from the epoch:
00125     fBlindingFunction.SetParameters(fParameterChooser,fSeed + 3 * epoch);
00126     
00127     // Find the probability of blinding this event:
00128     Float_t prob = fBlindingFunction.EventBlindProb(length,energy);
00129 
00130     // Get a pseudo-random number specific for this event:
00131     fRandom->SetSeed(run*1000 + snarl);
00132     Float_t r = fRandom->Rndm();
00133     
00134     // Allow event to be open if r<prob
00135     if(r<=prob) return JobCResult::kPassed;
00136     else        return JobCResult::kFailed;
00137   };
00138 
00139   // No blindness info obtained; return default. (This is probably a monitoring block.)
00140   return JobCResult::kPassed;
00141 }

void Blinder::Config ( const Registry r  )  [virtual]

Return the actual configuration. If your module directly pulls its configuration from the fConfig Registry, you don't need to override this. Override if you have local config variables.

Reimplemented from JobCModule.

Definition at line 386 of file Blinder.cxx.

References fBlindingFunction, fParameterChooser, fSeed, Registry::Get(), and Blinder::BlindingFunction::SetParameters().

00387 {
00388   //======================================================================
00389   // Configure the module given the Registry r
00390   //======================================================================
00391   
00392   r.Get("Seed",fSeed);
00393   
00394   // reset the paramaters:
00395   fBlindingFunction.SetParameters(fParameterChooser,fSeed);
00396 }

const Registry & Blinder::DefaultConfig ( void   )  const [virtual]

Get the default configuration registry. This should normally be overridden. One useful idiom is to implement it like:

const Registry& MyModule::DefaultConfig() const { static Registry cfg; // never is destroyed if (cfg.Size()) return cfg; // already filled it // set defaults: cfg.Set("TheAnswer",42); cfg.Set("Units","unknown"); return cfg; }

Reimplemented from JobCModule.

Definition at line 364 of file Blinder.cxx.

References JobCModule::GetName(), Registry::LockValues(), Registry::Set(), and Registry::UnLockValues().

00365 {
00366 //======================================================================
00367 // Supply the default configuration for the module
00368 //======================================================================
00369   static Registry r; // Default configuration for module
00370 
00371   // Set name of config
00372   std::string name = this->GetName();
00373   name += ".config.default";
00374   r.SetName(name.c_str());
00375 
00376   // Set values in configuration
00377   r.UnLockValues();
00378   r.Set("Seed", 10127);  // Seed with Nathaniel's fnal ID number.. that's pretty random.
00379   r.LockValues();
00380 
00381   return r;
00382 }

Float_t Blinder::GetBlindingProb ( Float_t  eventLength,
Float_t  eventEnergy,
Int_t  epoch = 11 
)

Definition at line 144 of file Blinder.cxx.

References Blinder::BlindingFunction::EventBlindProb(), fBlindingFunction, fParameterChooser, fSeed, and Blinder::BlindingFunction::SetParameters().

00145 {
00146   // Test subroutine for running from the command line.
00147   // To use:
00148   // gSystem->Load("libFiltration");
00149   // Blinder b;
00150   // Registry r = b.DefaultConfig();
00151   // b.Config(r);
00152   // b.GetBlindingProb(length, energy, epoch);
00153   fBlindingFunction.SetParameters(fParameterChooser,fSeed + 3 * epoch);
00154   Float_t prob = fBlindingFunction.EventBlindProb(eventLength,eventEnergy);
00155   return prob;
00156 }

Bool_t Blinder::GetInfo ( const MomNavigator mom,
Int_t &  run,
Int_t &  snarl,
Int_t &  epoch,
Float_t &  length,
Float_t &  energy 
) [private]

Definition at line 158 of file Blinder.cxx.

References digit(), RawDigit::GetADC(), RawDigit::GetChannel(), RawDigitDataBlock::GetDatumIter(), VldContext::GetDetector(), MomNavigator::GetFragment(), PlexSEIdAltL::GetPlane(), RawRecord::GetRawBlockIter(), RawRecord::GetRawHeader(), RawDaqHeader::GetRun(), VldContext::GetSimFlag(), RawDaqSnarlHeader::GetSnarl(), VldContext::GetTimeStamp(), RecMinosHdr::GetVldContext(), SimFlag::kData, Detector::kFar, Msg::kInfo, ReadoutType::kScintStrip, and MAXMSG.

Referenced by Ana(), and Reco().

00164 {
00165   //
00166   // This function pulls the neccessary info from the current Mom to find
00167   // the run, snarl, event length (with a basic clustering algorithm) and 
00168   // event energy (in raw ADC counts).
00169   //
00170   run = 0; 
00171   snarl = 0;
00172   length = 0;
00173   energy = 0;
00174   epoch = 0;
00175   
00176   // Find raw data.
00177   const RawRecord* rr = 
00178     dynamic_cast<const RawRecord*>(mom->GetFragment("RawRecord",0,"DaqSnarl"));
00179   if(rr==0) return false;
00180 
00181   const RawDaqSnarlHeader* snarlHead = 
00182     dynamic_cast<const RawDaqSnarlHeader*>(rr->GetRawHeader());
00183   if(snarlHead==0)  return false;
00184 
00185 
00186   TIter rdbit = rr->GetRawBlockIter();
00187   TObject *tob;
00188   const RawDigitDataBlock *rddb = 0;
00189   while ((tob = rdbit())) {
00190     if (tob->InheritsFrom("RawDigitDataBlock")) {
00191       rddb = dynamic_cast<const RawDigitDataBlock *>(tob);
00192     }
00193   }
00194   if(rddb==0) return false;
00195 
00196   if(snarlHead->GetVldContext().GetDetector()!=Detector::kFar) return false;
00197 
00198   if(snarlHead->GetVldContext().GetSimFlag()!=SimFlag::kData) epoch = 10;
00199 
00200   // Put epoch here:
00201   // These lines change the blinding function at certain
00202   // watershed dates.
00203   const VldTimeStamp kShutdown2006(2006,4,15,0,0,0); // April 15, 2006, midnight
00204   if(snarlHead->GetVldContext().GetTimeStamp() > kShutdown2006) epoch +=1;
00205 
00206   MAXMSG("Blinder",Msg::kInfo,1) << "Blinding FD data. Epoch = " << epoch << endl;
00207   
00208   // Get plex info.
00209   PlexHandle plex(snarlHead->GetVldContext());
00210 
00211   // Get the header data.
00212   run = snarlHead->GetRun();
00213   snarl = snarlHead->GetSnarl();
00214  
00215   // Map of the planes.
00216   std::vector<int> planes(500,0);
00217 
00218   // Loop the digits.
00219   TIter rdit = rddb->GetDatumIter();
00220   const RawDigit *digit;
00221   Int_t rawdigitindex = -1;
00222   while ((digit = (const RawDigit *) rdit())) {
00223     ++rawdigitindex;
00224     
00225     if(plex.GetReadoutType(digit->GetChannel()) != ReadoutType::kScintStrip) 
00226       continue;
00227 
00228     // Find plane.
00229     PlexSEIdAltL altl = plex.GetSEIdAltL(digit->GetChannel());
00230     Int_t plane = altl.GetPlane();
00231 
00232     // Find energy.
00233     Int_t adc = digit->GetADC();
00234 
00235     // add it up.
00236     if((plane>=0)&&(plane<490))
00237       planes[plane] ++;
00238 
00239     energy+=(float)adc;
00240   }
00241 
00242   // do the number-of-planes matching.  Look for the largest 'cluster' 
00243   int start = 0;
00244   int end = 0;
00245   int longest = 0;
00246   while(start<500) {
00247     if(planes[start]==0) {
00248       start++;
00249       continue;
00250     };
00251     
00252     // Found a starting place.
00253     end = start;
00254     int gap = 0;
00255     int thislen = 0;
00256     while(end<490) {
00257       end++;
00258       if(planes[end]==0) gap++;
00259       else thislen = end-start;
00260       if(gap>2) break;
00261     }
00262     
00263     if(thislen > longest) longest = thislen;
00264 
00265     start=end;    
00266   }
00267   length = longest;
00268 
00269   return true;
00270 }

const REROOT_NeuKin * Blinder::GetTruth ( const MomNavigator mom  )  [private]

Definition at line 339 of file Blinder.cxx.

References RecDataRecord< T >::FindComponent(), and MomNavigator::FragmentIter().

Referenced by Reco().

00340 {
00341     // Look for the simSnarl in Mom.
00342   SimSnarlRecord* simsnarl = 0;
00343   TObject* tobj;
00344   TIter    fragiter = mom->FragmentIter();
00345   while( ( tobj = fragiter.Next() ) ) {
00346     simsnarl = dynamic_cast<SimSnarlRecord*>(tobj);
00347     if(simsnarl) break;
00348   }
00349 
00350   if(simsnarl==0) return 0;
00351 
00352   // Get the NeuKin list.
00353   const TClonesArray* neuKins = dynamic_cast<const TClonesArray*>(simsnarl->FindComponent("TClonesArray","NeuKinList"));
00354   if(neuKins==0) return 0;
00355 
00356   return dynamic_cast<const REROOT_NeuKin*>((*neuKins)[0]); 
00357 }

JobCResult Blinder::Reco ( MomNavigator mom  )  [virtual]

Implement this for read-write access to the MomNavigator

This function serves to dump the blinding info to an ntuple file for doing research on how well the blinding function is doing.

Reimplemented from JobCModule.

Definition at line 278 of file Blinder.cxx.

References Blinder::BlindingFunction::EventBlindProb(), fBlindingFunction, fFile, fRandom, fTree, GetInfo(), GetTruth(), REROOT_NeuKin::IAction(), REROOT_NeuKin::INu(), JobCResult::kPassed, REROOT_NeuKin::P4El1(), REROOT_NeuKin::P4El2(), REROOT_NeuKin::P4Mu1(), REROOT_NeuKin::P4Mu2(), REROOT_NeuKin::P4Neu(), REROOT_NeuKin::P4Shw(), REROOT_NeuKin::P4Tau(), and run().

00279 {
00284   Int_t run;
00285   Int_t snarl;
00286   Int_t epoch;
00287   Float_t length;
00288   Float_t energy;
00289 
00290   if(GetInfo(mom,run,epoch,snarl,length,energy)) {
00291     float prob = fBlindingFunction.EventBlindProb(length,energy);
00292 
00293     fRandom->SetSeed(run*1000 + snarl);
00294     Float_t r = fRandom->Rndm();
00295 
00296     float blind = 0;
00297     if(r<=prob) blind = 1;
00298 
00299     float enu=0;
00300     float evis=0;
00301     float cc=0;
00302     float emu=0;
00303     float esh=0;
00304     float nu=0;
00305 
00306     const REROOT_NeuKin* truth = GetTruth(mom);
00307     if(truth) {
00308       enu = fabs(truth->P4Neu()[3]);
00309       cc  = truth->IAction();
00310       emu = fabs(truth->P4Mu1()[3]) + fabs(truth->P4Mu2()[3]);
00311       esh = fabs(truth->P4Shw()[3]);
00312       evis = emu + esh 
00313         + fabs(truth->P4El1()[3])
00314         + fabs(truth->P4El2()[3])
00315         + fabs(truth->P4Tau()[3]);      
00316       nu = truth->INu();
00317     }
00318 
00319     if(!fTree) {
00320       fFile = new TFile("blind.root","RECREATE");
00321       fTree = new TNtuple("blind","blind",
00322                           "run:snarl:len:energy"
00323                           ":enu:evis:cc:nu:emu:esh"
00324                           ":prob:blind"
00325                           );      
00326     }
00327 
00328     if(fTree) {
00329       fTree->Fill(run,snarl,length,energy
00330                   ,enu,evis,cc,nu,emu,esh
00331                   ,prob,blind
00332                   );      
00333     }
00334   };
00335   
00336   return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00337 }


Member Data Documentation

Definition at line 78 of file Blinder.h.

Referenced by Ana(), Blinder(), Config(), GetBlindingProb(), and Reco().

TFile* Blinder::fFile [private]

Definition at line 72 of file Blinder.h.

Referenced by Blinder(), Reco(), and ~Blinder().

TRandom* Blinder::fParameterChooser [private]

Definition at line 75 of file Blinder.h.

Referenced by Ana(), Blinder(), Config(), GetBlindingProb(), and ~Blinder().

TRandom* Blinder::fRandom [private]

Definition at line 74 of file Blinder.h.

Referenced by Ana(), Blinder(), Reco(), and ~Blinder().

Int_t Blinder::fSeed [private]

Definition at line 55 of file Blinder.h.

Referenced by Ana(), Blinder(), Config(), and GetBlindingProb().

TNtuple* Blinder::fTree [private]

Definition at line 73 of file Blinder.h.

Referenced by Blinder(), Reco(), and ~Blinder().


The documentation for this class was generated from the following files:

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1