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

CustomLightInjector.cxx

Go to the documentation of this file.
00001 
00002 // $Id: CustomLightInjector.cxx,v 1.12 2006/12/12 17:07:04 rhatcher Exp $
00003 //
00004 // Job control interface to input data streams
00005 //
00006 // messier@huhepl.harvard.edu
00008 #include "TSystem.h"
00009 #include "TRegexp.h"
00010 
00011 #include "CustomLightInjector.h"
00012 #include <cassert>
00013 #include <cmath>
00014 
00015 #include "MessageService/MsgService.h"
00016 #include "MinosObjectMap/MomNavigator.h"
00017 #include "JobControl/JobCInputModule.h"
00018 #include "JobControl/JobCModuleRegistry.h"
00019 #include "JobControl/JobCEnv.h"
00020 #include "RawData/RawRecord.h"
00021 #include "RawData/RawDaqSnarlHeader.h"
00022 #include "Record/RecRecord.h"
00023 #include "Record/RecPhysicsHeader.h"
00024 #include "Registry/Registry.h"
00025 #include "Validity/VldContext.h"
00026 #include "Util/UtilString.h"
00027 #include <TRandom.h>
00028 #include "Digitization/DigiList.h"
00029 #include "Digitization/DigiPE.h"
00030 #include "Record/SimSnarlRecord.h"
00031 #include "Record/SimSnarlHeader.h"
00032 #include "RawData/RawRecord.h"
00033 #include "RawData/RawDaqSnarlHeader.h"
00034 #include "RawData/RawDigitDataBlock.h"
00035 #include "RawData/RawDigit.h"
00036 #include "DataUtil/Truthifier.h"
00037 #include "TClonesArray.h"
00038 #include "Conventions/Munits.h"
00039 
00040 #include <algorithm>
00041 
00042 //CVSID("$Id: CustomLightInjector.cxx,v 1.12 2006/12/12 17:07:04 rhatcher Exp $");
00043 JOBMODULE(CustomLightInjector,"CustomLightInjector","Simulated Light Injection");
00044 
00045 RawChannelId CustomLightInjector::fRcid1;
00046 RawChannelId CustomLightInjector::fRcid2;
00047 
00048 
00049 //......................................................................
00050 
00051 CustomLightInjector::CustomLightInjector() : 
00052   fCurrentSnarl(0)
00053 { }
00054 
00055 //......................................................................
00056 
00057 CustomLightInjector::~CustomLightInjector() 
00058 { 
00059 }
00060 
00061 //......................................................................
00062 
00063 void CustomLightInjector::BeginJob() 
00064 {
00065 }
00066 
00067 
00068 //......................................................................
00069 
00070 const Registry& CustomLightInjector::DefaultConfig() const 
00071 {
00072 //======================================================================
00073 // Get the default configuration for this module
00074 //======================================================================
00075   static Registry r; // Default configuration for module
00076 
00077   // Set name of config
00078   std::string name = this->GetName();
00079   name += ".config.default";
00080   r.SetName(name.c_str());
00081 
00082   // Set values in configuration
00083   r.UnLockValues();
00084   r.Set("detectorType", 2);
00085   r.Set("rate",         1.0);
00086   r.Set("date",         20030101);
00087   r.Set("time",         000000);
00088   r.Set("photonRate",   0.0);
00089 
00090   r.LockValues();
00091 
00092   return r;
00093 }
00094 
00095 //......................................................................
00096 
00097 void CustomLightInjector::Config(const Registry& r) 
00098 {
00099 //======================================================================
00100 // Configure the module given the Registry r
00101 //======================================================================
00102   int    tmpi;
00103   double tmpd;
00104 
00105   if (r.Get("detectorType",tmpi)) { fDetector = tmpi; }
00106   if (r.Get("rate",tmpd)) { fRate = tmpd; }
00107   if (r.Get("date",tmpi)) { fDate = tmpi; }
00108   if (r.Get("time",tmpi)) { fTime = tmpi; }
00109   r.Get("photonRate",fPhotonRate);
00110 
00111   fPulseTime = VldTimeStamp(fDate,fTime,0);
00112   fContext =   VldContext(Detector::CharToEnum((char)fDetector),
00113                           SimFlag::kReroot,
00114                           fPulseTime);
00115 }
00116 
00117 //......................................................................  
00118 
00119 JobCResult CustomLightInjector::Get()
00120 {
00121   MomNavigator* mom = this->GetMom();
00122   assert(mom);
00123   mom -> Clear(); // Moving on so clear contents of Mom
00124 
00125 
00126   // Make a SimSnarl.
00127   Int_t   run      = 1000;
00128   Int_t   trigbits = 0;
00129   Short_t subrun = 0;
00130   Short_t runtype = 0;
00131   Int_t   errcode = 0;
00132   Int_t   timeframe = -1;
00133 
00134   // Increment the time by the pulse rate.
00135   int secs;
00136   double frac = frexp(fRate*fCurrentSnarl,&secs);
00137   int nsecs = int(frac*1e9);
00138   VldTimeStamp offset(secs,nsecs);
00139   fPulseTime = VldTimeStamp(fDate,fTime,0);
00140   fPulseTime.Add(offset);
00141 
00142   // Reset the context.
00143   fContext = VldContext(Detector::CharToEnum((char)fDetector),
00144                         SimFlag::kMC,
00145                         fPulseTime);
00146 
00147   VldTimeStamp now;
00148   std::string  codename = SimSnarlHeader::TrimCodename("$Name:  $");
00149   std::string hostname(gSystem->HostName());
00150 
00151   SimSnarlHeader simheader(fContext,run,subrun,runtype,
00152                            errcode,fCurrentSnarl,trigbits,timeframe,-1,
00153                            now,codename,hostname);
00154                                                 
00155   SimSnarlRecord* simsnarl = new SimSnarlRecord(simheader);
00156 
00157   simsnarl->GetTempTags().Set("stream","SimSnarl");  // no idea....
00158     
00159   // Give it to mom.
00160   mom -> AdoptFragment(simsnarl);
00161 
00162   // Add the DigiPE list to the simsnarl.
00163   TObjArray* PeList = new TObjArray(0);
00164   PeList->SetName("DigiListPe");
00165   PeList->SetOwner(true);
00166 
00167   // Find out how many of them to make.
00168   gRandom->SetSeed(fCurrentSnarl);
00169 
00170   // Make the photoelectron objects.
00171   // i.e: 
00172   //  DigiPE*  pe = new DigiPE(time, fPsid, NULL);
00173   // PeList->Add(pe);
00174   
00176   
00177   PlexHandle plex(fContext);
00178   PlexStripEndId seid1(fContext.GetDetector(),
00179                        1, 10, StripEnd::kWest);
00180   
00181   PlexStripEndId seid2(fContext.GetDetector(),
00182                        5, 15, StripEnd::kWest);
00183 
00184   PlexPixelSpotId psid1 = plex.GetPixelSpotId(seid1);
00185   PlexPixelSpotId psid2 = plex.GetPixelSpotId(seid2);
00186 
00187   fRcid1 = plex.GetRawChannelId(psid1);
00188   fRcid2 = plex.GetRawChannelId(psid2);
00189 
00190   //cout << "Injecting on " << psid1.AsString() << "->" << fRcid1.AsString() << endl;
00191   //cout << "         and " << psid2.AsString() << "->" << fRcid2.AsString() << endl;
00192 
00193 
00194   float npe = 0;
00195   for(int i=0;i<1*fCurrentSnarl;i++) {
00196     npe++;
00197     double time = double(i) * fPhotonRate*Munits::ns;
00198     DigiPE* pe;
00199     pe = new DigiPE(time, psid1, DigiSignal::kGenuine);
00200     PeList->Add(pe);
00201     pe = new DigiPE(time, psid2, DigiSignal::kGenuine);
00202     PeList->Add(pe);
00203   }
00204 
00205   cout << npe;
00206 
00208 
00209 
00210   simsnarl->AdoptTemporary(PeList);
00211 
00212   TClonesArray *new_arr = new TClonesArray("DigiScintHit",0);
00213   new_arr->SetName("DigiScintHits");
00214   simsnarl->AdoptComponent(new_arr);
00215   
00216 
00217   return JobCResult::kAOK;
00218 }
00219 
00220 //......................................................................
00221 
00222 JobCResult CustomLightInjector::Next(int n)
00223 {
00224 //======================================================================
00225 // Advance the position in the stream n record sets. Load the records
00226 // at the last position
00227 //======================================================================
00228   fCurrentSnarl+=n;
00229   return this->Get();
00230 }
00231 
00232 //......................................................................
00233 
00234 JobCResult CustomLightInjector::Prev(int n) 
00235 {
00236   if(fCurrentSnarl>0) fCurrentSnarl-=n;
00237   return this->Get();
00238 }
00239 
00240 //......................................................................
00241 
00242 JobCResult CustomLightInjector::GoTo(int /* run */, int snarl, int /* searchDir */) 
00243 {
00244   fCurrentSnarl = snarl;
00245   return this->Get();
00246 }
00247 
00248 //......................................................................
00249 
00250 JobCResult CustomLightInjector::Ana(const MomNavigator* mom)
00251 {
00252   const Truthifier& truth = Truthifier::Instance(mom);
00253 
00254   std::vector<int> adcs1(0);
00255   std::vector<int> adcs2(0);
00256   std::vector<float> q1(0);
00257   std::vector<float> q2(0);
00258           
00259  
00260  // Get the RawDigitDataBlock.
00261   TObject* tobj;
00262   TIter    fragiter = mom->FragmentIter();
00263   while( ( tobj = fragiter.Next() ) ) {
00264     RawRecord* rawRec = dynamic_cast<RawRecord*>(tobj);
00265     if(rawRec) {
00266       TIter itr = rawRec->GetRawBlockIter();
00267       RawDataBlock* rawBlk;
00268       while ( ( rawBlk = dynamic_cast<RawDataBlock*>(itr.Next()) ) ) {
00269         RawDigitDataBlock* rddb = dynamic_cast<RawDigitDataBlock*>(rawBlk);
00270         if(rddb) {
00271           //cout << "Ana context: " << rawRec->GetRawHeader()->GetVldContext().AsString() << endl;
00272           //PlexHandle plex(rawRec->GetRawHeader()->GetVldContext());
00273 
00274           TIter iter = rddb->GetDatumIter();
00275           while( (tobj=iter.Next() ) ) {
00276             
00277             // Process a digit.     
00278             
00279             RawDigit*        rawDigit = dynamic_cast<RawDigit *>(tobj);
00280             //cout << *rawDigit << endl;
00281 
00282             if(rawDigit) {
00283               if(rawDigit->GetChannel().IsSameChannel(fRcid1)) {
00284                 q1.push_back(truth.GetSignal(rawDigit)->GetCharge()/Munits::fC);
00285                 adcs1.push_back(rawDigit->GetADC());
00286               }
00287               else if(rawDigit->GetChannel().IsSameChannel(fRcid2)) 
00288                 adcs2.push_back(rawDigit->GetADC());            
00289               else {
00290                 //cout << "Xtalk chan? "  << *rawDigit << endl;
00291               }
00292                 
00293             }
00294 
00295           }
00296 
00297         }
00298       }
00299     }
00300   } // It's so ugly!
00301 
00302   for(UInt_t i=0;i<5;i++) {
00303     if(adcs1.size()>i) cout << "\t" << adcs1[i];
00304     else               cout << "\t" << 0;         
00305   }
00306   for(UInt_t i=0;i<5;i++) {
00307     if(q1.size()>i) cout << "\t" << q1[i];
00308     else            cout << "\t" << 0;    
00309   }
00310 
00311   cout << endl;
00312           
00313 
00314   return JobCResult::kPassed; // kNoDecision, kFailed, etc.
00315 }

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