MCInitModule Class Reference

#include <MCInitModule.h>

Inheritance diagram for MCInitModule:
JobCModule

List of all members.

Public Types

enum  EInitMethod { kSetKine, kUnknown }

Public Member Functions

 MCInitModule ()
virtual ~MCInitModule ()
const RegistryDefaultConfig () const
void Config (const Registry &r)
void HandleCommand (JobCommand *cmd)
void BeginJob ()
JobCResult Get (MomNavigator *mom)
VldTimeStamp GetSnarlTimeInterval () const
VldTimeStamp GetStartTimeStamp () const
VldTimeStamp GetCurrentTimeStamp () const
VldContext GetCurrentVld () const
void SetKine (Int_t pdg, Double_t vx, Double_t vy, Double_t vz, Double_t px, Double_t py, Double_t pz)

Static Public Member Functions

static const char * AsString (EInitMethod method)

Private Member Functions

void BuildInitialState (SimSnarlRecord *simrec)
void BuildSetKine (SimSnarlRecord *simrec)

Private Attributes

UInt_t fRun
UInt_t fSubRun
Int_t fSnarl
Detector::Detector_t fDetector
SimFlag::SimFlag_t fSimFlag
VldTimeStamp fStartTimeStamp
VldTimeStamp fSnarlTimeInterval
VldContext fCurrentVld
EInitMethod fInitMethod
TParticle * fKineParticle

Detailed Description

Definition at line 55 of file MCInitModule.h.


Member Enumeration Documentation

Enumerator:
kSetKine 
kUnknown 

Definition at line 59 of file MCInitModule.h.

00059                    {
00060     // Kinematic method used to generate events
00061     kSetKine, // SetKine command is used to set particle kinematics
00062     kUnknown 
00063   };


Constructor & Destructor Documentation

MCInitModule::MCInitModule (  ) 

Definition at line 66 of file MCInitModule.cxx.

00066                            :
00067   fRun(0),fSubRun(0),fSnarl(-1),fDetector(Detector::kFar),
00068   fSimFlag(SimFlag::kMC),fSnarlTimeInterval((time_t)1,900000000),
00069   fInitMethod(kSetKine),fKineParticle(0) {
00070   //
00071   // Purpose: Default constructor
00072   //
00073   
00074 }

MCInitModule::~MCInitModule (  )  [virtual]

Definition at line 78 of file MCInitModule.cxx.

References fKineParticle.

00078                             {
00079   // 
00080   // Purpose:: Destructor
00081   //
00082 
00083   if ( fKineParticle ) delete fKineParticle; fKineParticle = 0;
00084   
00085 }


Member Function Documentation

const char * MCInitModule::AsString ( EInitMethod  method  )  [static]

Definition at line 44 of file MCInitModule.cxx.

References Msg::kWarning, and MSG.

Referenced by BeginJob(), and BuildInitialState().

00044                                                          {
00045   //
00046   // Purpose: Static method to convert enumerated init method to a string
00047   //
00048 
00049   switch ( initmethod ) {
00050 
00051   case kSetKine:
00052     return "SetKine";
00053 
00054   default:
00055     MSG("MCInit",Msg::kWarning) 
00056     << "MCInitModule::AsString called with unknown EInitMethod "
00057     << (int)initmethod << endl;
00058     return "Unknown";
00059 
00060   } // end of switch
00061   
00062 }

void MCInitModule::BeginJob ( void   )  [virtual]

Implement for notification of begin of job

Reimplemented from JobCModule.

Definition at line 154 of file MCInitModule.cxx.

References AsString(), fCurrentVld, fDetector, fInitMethod, fKineParticle, fSimFlag, fSnarlTimeInterval, fStartTimeStamp, Msg::kDebug, Msg::kFatal, kSetKine, and MSG.

00154                             {
00155   //
00156   // Purpose: Called at the beginning of the job, after module configuration
00157  
00158   MSG("MCInit",Msg::kDebug) << "MCInitModule::BeginJob " << endl;
00159   
00160   // Rewind, because first Get() will move forward
00161   fStartTimeStamp = fStartTimeStamp - fSnarlTimeInterval; 
00162   fCurrentVld = VldContext(fDetector,fSimFlag,fStartTimeStamp);
00163 
00164   if ( fInitMethod == kSetKine ) {
00165     if ( fKineParticle ) {
00166       MSG("MCInit",Msg::kDebug) << "Initialization method "
00167           << AsString(kSetKine) << "\npdg " << fKineParticle->GetPdgCode() 
00168           << "/" << fKineParticle->GetName()  
00169           << " vtx(x,y,z)(m) (" << fKineParticle->Vx()  << "," 
00170           <<  fKineParticle->Vy() << "," << fKineParticle->Vz() << ")" 
00171           << " p(x,y,z)(GeV/c) (" << fKineParticle->Px() << "," 
00172           <<  fKineParticle->Py() << "," << fKineParticle->Pz() << ")"
00173           << endl;
00174     }
00175     else {
00176       MSG("MCInit",Msg::kFatal) << "SetKine Initialization method chosen,\n"
00177           << "but no initial state defined. Use\n"
00178           << "jc.Mod(''MCInit'').Cmd(''SetKine pdgId vx vy vz px py pz'')\n" 
00179           << "Abort!" << endl;
00180       abort();
00181     }
00182   }
00183            
00184 }

void MCInitModule::BuildInitialState ( SimSnarlRecord simrec  )  [private]

Definition at line 336 of file MCInitModule.cxx.

References AsString(), BuildSetKine(), fInitMethod, Msg::kFatal, kSetKine, and MSG.

Referenced by Get().

00336                                                            {
00337   //
00338   //  Purpose: Private method to build initial state particles according
00339   //           to specified method EInitMethod.  NeuKin and StdHep arrays
00340   //           are created and filled in SimSnarlRecord.
00341   //
00342   //  Arguments: SimSnarlRecord.
00343   //  
00344   //  Return: none.
00345   // 
00346 
00347 
00348   switch (fInitMethod) {
00349 
00350   case kSetKine:
00351     BuildSetKine(simrec);
00352     break;
00353 
00354   default:
00355     MSG("MCInit",Msg::kFatal) << "Unknown EInitMethod " 
00356            << MCInitModule::AsString(fInitMethod) << ". Abort!" << endl;
00357     abort();
00358   }
00359 
00360 }

void MCInitModule::BuildSetKine ( SimSnarlRecord simrec  )  [private]

Definition at line 363 of file MCInitModule.cxx.

References NEUKIN_DEF::A, NEUKIN_DEF::EMFrac, fKineParticle, NEUKIN_DEF::IAction, NEUKIN_DEF::IBoson, NEUKIN_DEF::ID, NEUKIN_DEF::INu, NEUKIN_DEF::INuNoOsc, NEUKIN_DEF::IResonance, NEUKIN_DEF::ITg, Msg::kFatal, MSG, NEUKIN_DEF::P4El1, NEUKIN_DEF::P4El2, NEUKIN_DEF::P4Mu1, NEUKIN_DEF::P4Mu2, NEUKIN_DEF::P4Neu, NEUKIN_DEF::P4NeuNoOsc, NEUKIN_DEF::P4Shw, NEUKIN_DEF::P4Tau, NEUKIN_DEF::P4Tgt, NEUKIN_DEF::Q2, NEUKIN_DEF::Sigma, NEUKIN_DEF::W2, NEUKIN_DEF::X, NEUKIN_DEF::Y, and NEUKIN_DEF::Z.

Referenced by BuildInitialState().

00363                                                       {
00364   //
00365   //  Purpose: Private method to build initial state particles according
00366   //           to specified method EInitMethod::kSetKine.  
00367   //           NeuKin and StdHep arrays are created and filled in 
00368   //           SimSnarlRecord.
00369   //
00370   //  Arguments: SimSnarlRecord.
00371   //  
00372   //  Return: none.
00373   // 
00374 
00375 
00376   // Create StdHep entry
00377   Int_t nstdhep = 1; // 1 primary track
00378   TClonesArray* stdheparray = new TClonesArray("TParticle",nstdhep);
00379   stdheparray -> SetName("StdHep");
00380   simrec -> AdoptComponent(stdheparray);
00381 
00382   if ( !fKineParticle ) {
00383     MSG("MCInit",Msg::kFatal) << "SetKine Initialization method chosen,\n"
00384           << "but no initial state defined. Use\n"
00385           << "jc.Mod(''MCInit'').Cmd(''SetKine pdgId vx vy vz px py pz'')\n" 
00386           << "Abort!" << endl;
00387     abort();
00388   }
00389   new ((*stdheparray)[0])TParticle(*fKineParticle);
00390 
00391 
00392   // Create single dummy REROOT_NeuKin object, REROOT_NeuKin to be replaced
00393   Int_t nneukin = 1; // 1 primary
00394   TClonesArray* neukinarray = new TClonesArray("REROOT_NeuKin",nneukin);
00395   neukinarray -> SetName("NeuKinList");
00396   simrec -> AdoptComponent(neukinarray);
00397 
00398   // This bit of nonsense is because REROOT_NeuKin constructor doesn't
00399   // initialize data members
00400   NEUKIN_DEF neukin;
00401   neukin.ID= 1; //index of this neukin, set to 1 cuz REROOT_NeuKin subtracts 1
00402   neukin.INu = 0; // particle id
00403   neukin.INuNoOsc = 0;
00404   neukin.ITg = 0;
00405   neukin.IBoson = -99999; // to be the same as reroot
00406   neukin.IResonance = 0;
00407   neukin.IAction = 0;
00408   neukin.A = 0;
00409   neukin.Z = 0;
00410   neukin.Sigma = 0;
00411   for ( int ic = 0; ic < 4; ic++ ) {
00412     neukin.P4Neu[ic] = 0;
00413     neukin.P4NeuNoOsc[ic] = 0;
00414     neukin.P4Tgt[ic] = 0;
00415   }
00416   neukin.X = 0;
00417   neukin.Y = 0;
00418   neukin.Q2 = 0;
00419   neukin.W2 = 0;
00420   for ( int ic = 0; ic < 4; ic++ ) {
00421     neukin.P4Shw[ic] = 0;
00422     neukin.P4Mu1[ic] = 0;
00423     neukin.P4Mu2[ic] = 0;
00424   }
00425   if (TMath::Abs(fKineParticle->GetPdgCode()) == 13 ) {
00426     // Muon primary, gminos/reroot labels these muon final state
00427     neukin.P4Mu1[0] = fKineParticle->Px();
00428     neukin.P4Mu1[1] = fKineParticle->Py();
00429     neukin.P4Mu1[2] = fKineParticle->Pz();
00430     neukin.P4Mu1[3] = fKineParticle->Energy();
00431   }
00432   neukin.EMFrac = 0;
00433   for ( int ic = 0; ic < 4; ic++ ) {
00434     neukin.P4El1[ic] = 0;
00435     neukin.P4El2[ic] = 0;
00436     neukin.P4Tau[ic] = 0;
00437   }
00438   
00439   // new with placement, create dummy REROOT_NeuKin
00440   new ((*neukinarray)[0])REROOT_NeuKin(&neukin);
00441 
00442   
00443   return;
00444   
00445 }

void MCInitModule::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 118 of file MCInitModule.cxx.

References fDetector, fInitMethod, fRun, fSimFlag, fSnarl, fSnarlTimeInterval, fStartTimeStamp, fSubRun, Registry::Get(), Msg::kDebug, and MSG.

00118                                            {
00119   //
00120   // Purpose: Configure the module.
00121   //
00122 
00123   MSG("MCInit",Msg::kDebug) << "MCInitModule::Config" << endl;
00124   
00125   Int_t tmpi;
00126   Double_t tmpd;
00127   //  const Char_t* tmps;
00128 
00129   if ( r.Get("Run",tmpi) ) fRun = tmpi;
00130   if ( r.Get("SubRun",tmpi) ) fSubRun = tmpi;
00131   if ( r.Get("Snarl",tmpi) ) fSnarl = tmpi - 1; // will increment on first Get
00132   if ( r.Get("SimFlag",tmpi) ) fSimFlag = (SimFlag::SimFlag_t)tmpi;
00133   if ( r.Get("Detector",tmpi) ) fDetector = (Detector::Detector_t)tmpi;
00134   
00135   if ( r.Get("StartDate",tmpi) ) {
00136     if ( tmpi > 0 ) fStartTimeStamp = VldTimeStamp(tmpi,0,0);
00137     else fStartTimeStamp = VldTimeStamp(); // set to current time
00138   }
00139   if ( r.Get("SnarlTimeInterval",tmpd) ) {
00140     Int_t sec = (Int_t)tmpd; // truncate
00141     Int_t nsec = (Int_t)((tmpd - (Double_t)sec)*1.e9);
00142     fSnarlTimeInterval = VldTimeStamp(sec,nsec);
00143   }
00144        
00145   if ( r.Get("InitMethod",tmpi) ) {
00146     fInitMethod = (EInitMethod)tmpi;
00147   }
00148        
00149   return;
00150   
00151 }

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

References JobCModule::GetName(), Msg::kDebug, Detector::kFar, SimFlag::kMC, kSetKine, Registry::LockValues(), MSG, Registry::Set(), and Registry::UnLockValues().

00090                                                   {
00091   //
00092   // Purpose: Method to return default configuration.
00093   // 
00094 
00095   MSG("MCInit",Msg::kDebug) << "MCInitModule::DefaultConfig" << endl;
00096 
00097   static Registry r; 
00098   std::string name = this->JobCModule::GetName();
00099   name += ".config.default";
00100   r.SetName(name.c_str());
00101   r.UnLockValues();
00102 
00103   r.Set("Run", 0);
00104   r.Set("SubRun", 0);
00105   r.Set("Snarl", 0);
00106   r.Set("Detector", (int)Detector::kFar);
00107   r.Set("SimFlag", (int)SimFlag::kMC);
00108   r.Set("StartDate",0); 
00109   r.Set("SnarlTimeInterval",1.9);
00110   r.Set("InitMethod",(int)kSetKine);
00111  
00112   r.LockValues();
00113 
00114   return r;
00115 }

JobCResult MCInitModule::Get ( MomNavigator mom  )  [virtual]

Implement if your module needs to read data from some external source and fill mom

Reimplemented from JobCModule.

Definition at line 187 of file MCInitModule.cxx.

References BuildInitialState(), fCurrentVld, fDetector, fRun, fSimFlag, fSnarl, fSnarlTimeInterval, fStartTimeStamp, fSubRun, GetCurrentTimeStamp(), gSystem(), hostname, Msg::kDebug, Msg::kFatal, JobCResult::kPassed, MSG, and SimSnarlHeader::TrimCodename().

00187                                               {
00188   //
00189   // Purpose:  Create and fill SimSnarlRecord.
00190   //
00191   // Notes: A SimSnarlRecord is generated with contents:
00192   //          i) TClonesArray of name NeuKinList containing objects of type
00193   //             REROOT_NeuKin.
00194   //         ii) TClonesArray of name StdHep containing objects of type
00195   //             TParticle.
00196   // See description at top of MCInitModule.h for more information.
00197   //
00198 
00199   JobCResult result(JobCResult::kPassed);  
00200   MSG("MCInit",Msg::kDebug) << "MCInitModule::Get" << endl;
00201 
00202   // Check that mom exists.
00203   assert(mom);
00204 
00205   SimSnarlRecord* simrec = 0;
00206   // Check for existence of SimSnarlRecord in Mom 
00207   simrec = dynamic_cast<SimSnarlRecord*>(mom -> GetFragment("SimSnarlRecord"));
00208   if ( simrec ) {
00209     MSG("MCInit",Msg::kFatal) << "SimSnarlRecord present in input Mom!" 
00210                               << endl;
00211     abort(); // don't want to think about it yet
00212   }
00213 
00214   fSnarl++;
00215   fCurrentVld = VldContext(fDetector,fSimFlag,
00216                            GetCurrentTimeStamp() + fSnarlTimeInterval);
00217   // Not sure what to do with these flags yet. Copy RerootExodus
00218   Short_t runtype = 0;
00219   UInt_t  trigsrc = 0;
00220   UInt_t errcode = 0;
00221   // time frames in 1 second buckets, starting with timeframe 0
00222   Int_t timeframe = (GetCurrentTimeStamp() - fStartTimeStamp 
00223                    - fSnarlTimeInterval).GetSec(); 
00224   Int_t spilltype = -1;
00225 
00226   VldTimeStamp now;
00227   std::string  codename = SimSnarlHeader::TrimCodename("$Name:  $");
00228   std::string  hostname(gSystem->HostName());
00229 
00230   SimSnarlHeader simheader(fCurrentVld,fRun,fSubRun,runtype,errcode,fSnarl,
00231                            trigsrc,timeframe,spilltype,
00232                            now,codename,hostname);
00233   simrec = new SimSnarlRecord(simheader);
00234 
00235   MSG("MCInit",Msg::kDebug) 
00236     << "MCInitModule::Get created new SimSnarlRecord.\n" 
00237     <<  simheader << endl;
00238 
00239   mom -> AdoptFragment(simrec);
00240 
00241   BuildInitialState(simrec);
00242   
00243   return result;
00244   
00245 }

VldTimeStamp MCInitModule::GetCurrentTimeStamp (  )  const [inline]

Definition at line 82 of file MCInitModule.h.

References fCurrentVld, and VldContext::GetTimeStamp().

Referenced by Get().

00082 {return fCurrentVld.GetTimeStamp();}

VldContext MCInitModule::GetCurrentVld (  )  const [inline]

Definition at line 83 of file MCInitModule.h.

References fCurrentVld.

00083 { return fCurrentVld; }

VldTimeStamp MCInitModule::GetSnarlTimeInterval (  )  const [inline]

Definition at line 80 of file MCInitModule.h.

References fSnarlTimeInterval.

00080 { return fSnarlTimeInterval; }

VldTimeStamp MCInitModule::GetStartTimeStamp (  )  const [inline]

Definition at line 81 of file MCInitModule.h.

References fStartTimeStamp.

00081 { return fStartTimeStamp; }

void MCInitModule::HandleCommand ( JobCommand command  )  [virtual]

Implement to handle a JobCommand

Reimplemented from JobCModule.

Definition at line 248 of file MCInitModule.cxx.

References JobCommand::HaveCmd(), Msg::kError, Msg::kFatal, MSG, JobCommand::PopCmd(), JobCommand::PopFloatOpt(), JobCommand::PopIntOpt(), and SetKine().

00248                                                 {
00249   // 
00250   // Handle script commands that don't work through Config:
00251   //   jc.Mod("MCInit").Cmd("SetKine pdgId vx vy vz px py pz");
00252 
00253   
00254   if (!cmd->HaveCmd()) return;
00255   
00256   string s = cmd->PopCmd();
00257   if ( s == "SetKine" ) {
00258     bool isOkay = false;
00259     if (cmd -> HaveOpt() ) {
00260       int pdg = cmd->PopIntOpt();
00261       if ( cmd -> HaveOpt() ) {
00262         double vx = cmd->PopFloatOpt();
00263         if ( cmd -> HaveOpt() ) {
00264           double vy = cmd->PopFloatOpt();
00265           if ( cmd -> HaveOpt() ) {
00266             double vz = cmd->PopFloatOpt();
00267             if ( cmd -> HaveOpt() ) {
00268               double px = cmd->PopFloatOpt();
00269               if ( cmd -> HaveOpt() ) {
00270                 double py = cmd -> PopFloatOpt();
00271                 if ( cmd -> HaveOpt() ) {
00272                   double pz = cmd -> PopFloatOpt();
00273                   isOkay = true;
00274                   SetKine(pdg,vx,vy,vz,px,py,pz);
00275                 }
00276               }
00277             }
00278           }
00279         }
00280       }
00281     }
00282     if (!isOkay ) {
00283       MSG("MCInit",Msg::kFatal) 
00284         << "SetKine called w/incorrect parameter list. Abort!" << endl;
00285       abort();
00286     }
00287     return;
00288   }
00289     
00290   // Errors fall through to here
00291   MSG("MCInit",Msg::kError) << "Illegal command: " << s.c_str() << endl;
00292   
00293 }

void MCInitModule::SetKine ( Int_t  pdg,
Double_t  vx,
Double_t  vy,
Double_t  vz,
Double_t  px,
Double_t  py,
Double_t  pz 
)

Definition at line 297 of file MCInitModule.cxx.

References fKineParticle, and Particle::Mass().

Referenced by HandleCommand().

00299                                                                        { 
00300   //
00301   // Purpose: Method to set initial state kinematics.  
00302   // 
00303   // Arguments: particle id (pdg)
00304   //            vtx & momentum in MINOS standard units
00305   //            (m and GeV/c respectively)
00306   // 
00307   // Notes: fKineParticle (TParticle) will be constructed from the arguments.
00308   //
00309 
00310   const TDatabasePDG& dbpdg = *(TDatabasePDG::Instance());
00311   TParticlePDG* partpdg = dbpdg.GetParticle(pdg);
00312 
00313   std::string partname = "???";
00314   if ( partpdg ) partname=partpdg->GetName();
00315   
00316   if ( fKineParticle ) {
00317     delete fKineParticle; fKineParticle = 0;
00318   }
00319   
00320   // 1 is neugen status code for final state particle 
00321   // 0 is for neutrino/nucleus primaries
00322   Int_t status = 1; 
00323   Int_t mother1 = -1;
00324   Int_t mother2 = -1;
00325   Int_t daughter1 = -1;
00326   Int_t daughter2 = -1;
00327   Double_t mass = partpdg -> Mass();
00328   Double_t etot = TMath::Sqrt(px*px + py*py + pz*pz + mass*mass);
00329   Double_t time = 0;
00330   fKineParticle = new TParticle(pdg,status,mother1,mother2,daughter1,
00331                                 daughter2,px,py,pz,etot,vx,vy,vz,time);
00332    
00333 }


Member Data Documentation

Definition at line 103 of file MCInitModule.h.

Referenced by BeginJob(), Get(), GetCurrentTimeStamp(), and GetCurrentVld().

Definition at line 99 of file MCInitModule.h.

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

Definition at line 104 of file MCInitModule.h.

Referenced by BeginJob(), BuildInitialState(), and Config().

TParticle* MCInitModule::fKineParticle [private]

Definition at line 105 of file MCInitModule.h.

Referenced by BeginJob(), BuildSetKine(), SetKine(), and ~MCInitModule().

UInt_t MCInitModule::fRun [private]

Definition at line 96 of file MCInitModule.h.

Referenced by Config(), and Get().

Definition at line 100 of file MCInitModule.h.

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

Int_t MCInitModule::fSnarl [private]

Definition at line 98 of file MCInitModule.h.

Referenced by Config(), and Get().

Definition at line 102 of file MCInitModule.h.

Referenced by BeginJob(), Config(), Get(), and GetSnarlTimeInterval().

Definition at line 101 of file MCInitModule.h.

Referenced by BeginJob(), Config(), Get(), and GetStartTimeStamp().

UInt_t MCInitModule::fSubRun [private]

Definition at line 97 of file MCInitModule.h.

Referenced by Config(), and Get().


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

Generated on 2 Nov 2017 for loon by  doxygen 1.6.1