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

PhotonInjector.cxx

Go to the documentation of this file.
00001 
00002 // $Id: PhotonInjector.cxx,v 1.6 2007/11/11 05:47:55 rhatcher Exp $
00003 //
00004 // FILL_IN: [Document your code!!]
00005 //
00006 // n.tagg1@physics.ox.ac.uk
00008 #include "PhotonInjector.h"
00009 
00010 #include <TRandom.h>
00011 #include <TRandom3.h>
00012 
00013 #include "MessageService/MsgService.h"
00014 #include "MinosObjectMap/MomNavigator.h"
00015 #include "JobControl/JobCModuleRegistry.h" // For JOBMODULE macro
00016 
00017 #include "Digitization/DigiScintHit.h"
00018 #include "Digitization/DigiPE.h"
00019 #include "Digitization/DigiSignal.h"
00020 
00021 #include "Record/SimSnarlRecord.h"
00022 #include "Record/SimSnarlHeader.h"
00023 
00024 #include "PhotonTransportModule.h"
00025 #include "PhotonTransportMaker.h"
00026 #include "PhotonConfiguration.h"
00027 
00028 #include "Plex/PlexHandle.h"
00029 
00030 #include "Calibrator/Calibrator.h"
00031 
00032 #include <TFile.h>
00033 #include <TNtuple.h>
00034 #include <TSystem.h>
00035 
00036 #include <cmath>
00037 
00038 JOBMODULE(PhotonInjector, "PhotonInjector",
00039           "Photon transport from light injection to photoelectroncs");
00040 CVSID("$Id: PhotonInjector.cxx,v 1.6 2007/11/11 05:47:55 rhatcher Exp $");
00041 
00042 
00043 //......................................................................
00044 
00045 PhotonInjector::PhotonInjector() :
00046   fRandom(new TRandom3),
00047   fRandomSeed(0)
00048 {
00049 }
00050 
00051 //......................................................................
00052 
00053 PhotonInjector::~PhotonInjector() 
00054 {
00055 }
00056 
00057 //......................................................................
00058 
00059 JobCResult PhotonInjector::Get()
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 }
00146 
00147 //......................................................................
00148 
00149 const Registry& PhotonInjector::DefaultConfig() const
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 }
00166 
00167 //......................................................................
00168 
00169 void PhotonInjector::Config(const Registry& r)
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 }
00185 
00186 
00188 JobCResult PhotonInjector::SimulateEvent()
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 }
00244 
00245 

Generated on Mon Feb 15 11:07:22 2010 for loon by  doxygen 1.3.9.1