PhotonInjector Class Reference

#include <PhotonInjector.h>

Inheritance diagram for PhotonInjector:
JobCInputModule JobCModule

List of all members.

Public Member Functions

 PhotonInjector ()
 ~PhotonInjector ()
JobCResult Get ()
JobCResult Next (int n=1)
JobCResult Prev (int n=1)
JobCResult GoTo (int run, int snarl, int=0)
JobCResult GoTo (const VldContext &)
const RegistryDefaultConfig () const
void Config (const Registry &r)
JobCResult SimulateEvent ()

Private Attributes

VldContext fContext
const SimSnarlHeaderfSimHeader
TObjArray * fPeList
TRandom * fRandom
Int_t fCurrentSnarl
Int_t fRun
Int_t fDate
Int_t fTime
Int_t fDetector
Int_t fPulserBox
Int_t fLed
Double_t fRate
Double_t fPulseWidth
Double_t fPulseHeight
Int_t fRandomSeed

Detailed Description

Definition at line 17 of file PhotonInjector.h.


Constructor & Destructor Documentation

PhotonInjector::PhotonInjector (  ) 

Definition at line 45 of file PhotonInjector.cxx.

00045                                :
00046   fRandom(new TRandom3),
00047   fRandomSeed(0)
00048 {
00049 }

PhotonInjector::~PhotonInjector (  ) 

Definition at line 53 of file PhotonInjector.cxx.

00054 {
00055 }


Member Function Documentation

void PhotonInjector::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 169 of file PhotonInjector.cxx.

References fDate, fDetector, fLed, fPulseHeight, fPulserBox, fPulseWidth, fRandomSeed, fRate, fRun, fTime, and Registry::Get().

00170 {
00171 //======================================================================
00172 // Configure the module given the Registry r
00173 //======================================================================
00174   r.Get("Run",fRun);
00175   r.Get("Date",fDate);
00176   r.Get("Time",fTime);
00177   r.Get("Detector",fDetector);
00178   r.Get("PulserBox",fPulserBox);
00179   r.Get("Led",fLed);
00180   r.Get("Rate",fRate);
00181   r.Get("PulseWidth",fPulseWidth);
00182   r.Get("PulseHeight",fPulseHeight);
00183   r.Get("RandomSeed",fRandomSeed);
00184 }

const Registry & PhotonInjector::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 149 of file PhotonInjector.cxx.

References MuELoss::e, PhotonConfiguration(), and Registry::Set().

00150 {
00151 //======================================================================
00152 // Supply the default configuration for the module
00153 //======================================================================
00154   static Registry kReg;
00155   kReg = PhotonConfiguration();
00156   kReg.Set("Date",VldTimeStamp().GetDate()); // Now
00157   kReg.Set("Time",VldTimeStamp().GetTime()); // Now
00158   kReg.Set("Detector",2); // Far
00159   kReg.Set("PulserBox",1);
00160   kReg.Set("Led",1);
00161   kReg.Set("Rate",200.); //Hz
00162   kReg.Set("PulseWidth",50e-9);
00163   kReg.Set("PulseHeight",330.);
00164   return kReg;
00165 }

JobCResult PhotonInjector::Get ( void   )  [virtual]

Reimplemented from JobCInputModule.

Definition at line 59 of file PhotonInjector.cxx.

References VldTimeStamp::Add(), RecDataRecord< T >::AdoptTemporary(), Detector::CharToEnum(), fContext, fCurrentSnarl, fDate, fDetector, fPeList, MomNavigator::FragmentIter(), fRandom, fRandomSeed, fRate, fRun, fTime, VldContext::GetDetector(), JobCInputModule::GetMom(), RecRecordImp< T >::GetTempTags(), VldContext::GetTimeStamp(), gSystem(), hostname, Calibrator::Instance(), Msg::kInfo, SimFlag::kMC, JobCResult::kPassed, MSG, CalScheme::Reset(), Registry::Set(), SimulateEvent(), and SimSnarlHeader::TrimCodename().

Referenced by GoTo(), Next(), and Prev().

00060 {
00061   //======================================================================
00062   // Does the work. 
00063   // Creates photons near the LIM ashtray
00064   //======================================================================
00065   MomNavigator* mom = this->GetMom();
00066   assert(mom);
00067   mom -> Clear(); // Moving on so clear contents of Mom
00068   
00069   MSG("Photon",Msg::kInfo) << "Simulated Light Injection  running." << endl;
00070   
00071   // Make a SimSnarl.
00072   Int_t   trigbits = 0x2; // RawLI
00073   Short_t subrun = 0;
00074   Short_t runtype = 0;
00075   Int_t   errcode = 0;
00076   Int_t   timeframe = -1;
00077   Int_t   spilltype = -1;
00078   
00079   // Increment the time by the pulse rate.
00080   int secs;
00081   double frac = frexp(fCurrentSnarl/fRate,&secs);
00082   int nsecs = int(frac*1e9);
00083   VldTimeStamp offset(secs,nsecs);
00084   VldTimeStamp fPulseTime = VldTimeStamp(fDate,fTime,0);
00085   fPulseTime.Add(offset);
00086   
00087   // Reset the context.
00088   fContext = VldContext(Detector::CharToEnum((char)fDetector),
00089                         SimFlag::kMC,
00090                         fPulseTime);
00091   
00092   VldTimeStamp now;
00093   std::string  codename = SimSnarlHeader::TrimCodename("$Name:  $");
00094   std::string  hostname(gSystem->HostName());
00095 
00096   SimSnarlHeader simheader(fContext,fRun,subrun,runtype,
00097                            errcode,fCurrentSnarl,trigbits,timeframe,spilltype,
00098                            now,codename,hostname);
00099                                                 
00100   SimSnarlRecord* simsnarl = new SimSnarlRecord(simheader);
00101 
00102   simsnarl->GetTempTags().Set("stream","SimSnarl");  // no idea....
00103     
00104   // Give it to mom.
00105   mom -> AdoptFragment(simsnarl);
00106 
00107   // Generate the event:
00108   gRandom->SetSeed(fCurrentSnarl);
00109 
00110 
00111   TIter    fragiter = mom->FragmentIter();
00112 
00113   // Set the random seed to match the event.
00114   // Also add some user-configurable randomness, in case they want to
00115   // generate the same event with a different outcome.
00116   fRandom->SetSeed( fRun 
00117                     + fCurrentSnarl
00118                     + fRandomSeed );
00119   
00120   // We need a context to do table lookups
00121   VldContext simContext = fContext;
00122 
00123   // But.. we want our context to be "MC" not "Reroot". Ensure that's correct.
00124   fContext = VldContext(simContext.GetDetector(),SimFlag::kMC,simContext.GetTimeStamp());
00125 
00126   Calibrator::Instance().Reset(fContext);
00127 
00128   // Create the stat report.
00129   JobCResult res;
00130 
00131   fPeList = new TObjArray(0);
00132   fPeList->SetName("DigiListPe");
00133   fPeList->SetOwner(true);
00134   
00135   //
00136   // Do the actual work.
00137   //
00138   SimulateEvent();
00139 
00140   // Store the results.
00141   simsnarl->AdoptTemporary(fPeList);
00142   
00143   
00144   return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00145 }

JobCResult PhotonInjector::GoTo ( const VldContext  )  [inline, virtual]

Reimplemented from JobCInputModule.

Definition at line 35 of file PhotonInjector.h.

References Get().

00035 { return this->Get();};

JobCResult PhotonInjector::GoTo ( int  run,
int  snarl,
int  = 0 
) [inline, virtual]

Reimplemented from JobCInputModule.

Definition at line 33 of file PhotonInjector.h.

References fCurrentSnarl, fRun, Get(), and JobCResult::kAOK.

00034   { fRun = run; fCurrentSnarl = snarl; this->Get(); return JobCResult::kAOK;}

JobCResult PhotonInjector::Next ( int  n = 1  )  [inline, virtual]

Reimplemented from JobCInputModule.

Definition at line 29 of file PhotonInjector.h.

References fCurrentSnarl, Get(), JobCResult::kAOK, and n.

00030   { fCurrentSnarl+=n; this->Get(); return JobCResult::kAOK;}

JobCResult PhotonInjector::Prev ( int  n = 1  )  [inline, virtual]

Reimplemented from JobCInputModule.

Definition at line 31 of file PhotonInjector.h.

References fCurrentSnarl, Get(), JobCResult::kAOK, and n.

00032   { fCurrentSnarl-=n; this->Get(); return JobCResult::kAOK;}

JobCResult PhotonInjector::SimulateEvent (  ) 

The Meat:

Definition at line 188 of file PhotonInjector.cxx.

References Calibrator::DecalAttenCorrected(), MuELoss::e, fContext, fLed, fPeList, fPulseHeight, fPulserBox, fPulseWidth, fRandom, VldContext::GetDetector(), PlexStripEndId::GetEnd(), UgliStripHandle::GetHalfLength(), VldTimeStamp::GetNanoSec(), PlexHandle::GetPixelSpotId(), PlexHandle::GetStripEndIdVector(), UgliGeomHandle::GetStripHandle(), VldContext::GetTimeStamp(), Calibrator::Instance(), PlexPixelSpotId::IsValid(), DigiSignal::kFibreLight, StripEnd::kNegative, JobCResult::kPassed, StripEnd::kPositive, PlexStripEndId::SetEnd(), and UgliStripHandle::WlsPigtail().

Referenced by Get().

00189 {
00190   JobCResult res = JobCResult::kPassed;
00191 
00193 
00194   PlexHandle plex(fContext);
00195   UgliGeomHandle ugli(fContext);
00196 
00197   // Identify the LED.
00198   PlexLedId led(fContext.GetDetector(), fPulserBox, fLed);
00199   std::vector<PlexStripEndId> stripsHit = plex.GetStripEndIdVector(led);
00200 
00201   cout << "Pulsing LED: " << led.AsString() << endl;
00202   cout << "Total stripends = " << stripsHit.size() << endl;
00203 
00204   // Loop over the strip ends.
00205   for(UInt_t i=0; i<stripsHit.size(); i++) {
00206     PlexStripEndId seid = stripsHit[i];
00207     PlexStripEndId farseid = seid;
00208     farseid.SetEnd((seid.GetEnd()==StripEnd::kNegative)?StripEnd::kPositive:StripEnd::kNegative);
00209     
00210     // Total length of green fibre
00211     UgliStripHandle ustrip = ugli.GetStripHandle(seid);
00212     Float_t xfibre = ustrip.GetHalfLength() + ustrip.WlsPigtail(seid.GetEnd());
00213     if(seid.GetEnd()==StripEnd::kNegative) xfibre = -xfibre;
00214 
00215     // Clear fibre is the same on both ends, and can be ignored.
00216 
00217     // Find attenuation factor.
00218     Float_t atten = Calibrator::Instance().DecalAttenCorrected(1,xfibre,seid);
00219 
00220     // Find number of pe at each end.
00221     Int_t npe_near = fRandom->Poisson(fPulseHeight);
00222     Int_t npe_far  = fRandom->Poisson(fPulseHeight/atten);
00223     PlexPixelSpotId spot_near = plex.GetPixelSpotId(seid);
00224     PlexPixelSpotId spot_far  = plex.GetPixelSpotId(farseid);
00225     std::cout << "Generating near/far: " << npe_near << "/" << npe_far << std::endl;
00226 
00227     for(int i=0;i<(npe_near+npe_far);i++) {
00228       PlexPixelSpotId spot = spot_near;
00229       if(i>=npe_near) spot = spot_far;
00230       if(!spot.IsValid()) continue;
00231       
00232       // Choose time.
00233       Double_t t = gRandom->Gaus()*fPulseWidth
00234         + fContext.GetTimeStamp().GetNanoSec()*1e-9;
00235       
00236       DigiPE* pe = new DigiPE(t,spot,DigiSignal::kFibreLight); // Close enough.
00237       fPeList->Add(pe);
00238     }
00239      
00240   }
00241 
00242   return res;
00243 }


Member Data Documentation

Definition at line 48 of file PhotonInjector.h.

Referenced by Get(), and SimulateEvent().

Definition at line 54 of file PhotonInjector.h.

Referenced by Get(), GoTo(), Next(), and Prev().

Int_t PhotonInjector::fDate [private]

Definition at line 59 of file PhotonInjector.h.

Referenced by Config(), and Get().

Int_t PhotonInjector::fDetector [private]

Definition at line 61 of file PhotonInjector.h.

Referenced by Config(), and Get().

Int_t PhotonInjector::fLed [private]

Definition at line 63 of file PhotonInjector.h.

Referenced by Config(), and SimulateEvent().

TObjArray* PhotonInjector::fPeList [private]

Definition at line 50 of file PhotonInjector.h.

Referenced by Get(), and SimulateEvent().

Double_t PhotonInjector::fPulseHeight [private]

Definition at line 66 of file PhotonInjector.h.

Referenced by Config(), and SimulateEvent().

Int_t PhotonInjector::fPulserBox [private]

Definition at line 62 of file PhotonInjector.h.

Referenced by Config(), and SimulateEvent().

Double_t PhotonInjector::fPulseWidth [private]

Definition at line 65 of file PhotonInjector.h.

Referenced by Config(), and SimulateEvent().

TRandom* PhotonInjector::fRandom [private]

Definition at line 52 of file PhotonInjector.h.

Referenced by Get(), and SimulateEvent().

Int_t PhotonInjector::fRandomSeed [private]

Definition at line 67 of file PhotonInjector.h.

Referenced by Config(), and Get().

Double_t PhotonInjector::fRate [private]

Definition at line 64 of file PhotonInjector.h.

Referenced by Config(), and Get().

Int_t PhotonInjector::fRun [private]

Definition at line 58 of file PhotonInjector.h.

Referenced by Config(), Get(), and GoTo().

Definition at line 49 of file PhotonInjector.h.

Int_t PhotonInjector::fTime [private]

Definition at line 60 of file PhotonInjector.h.

Referenced by Config(), and Get().


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

Generated on 22 Nov 2017 for loon by  doxygen 1.6.1