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

ReadoutSim.cxx

Go to the documentation of this file.
00001 #include "ReadoutSim/ReadoutSim.h"
00002 #include "ReadoutSim/Simulator.h"
00003 #include "RawData/DAQHeader.h"
00004 #include "PhotonTransport/PhotonSignal.h"
00005 #include "JobControl/Exception.h"
00006 #include <TRandom3.h>
00007 #include <string>
00008 #include "Geometry/CellUniqueId.h"
00009 #include "Geometry/PlaneGeo.h"
00010 #include "Geometry/Geometry.h"
00011 #include "RawData/RawDigit.h"
00012 #include "Simulation/HitProfile.h"
00013 #include "Simulation/MCDigitInfo.h"
00014 
00015 #include "ReadoutSim/MsgLevel.h"
00016 
00017 //#include "Simulation/FLSHit.h"
00018 //#include "Simulation/FLSHitList.h"
00019 
00020 #include "PhotonTransport/PhotonSignal.h"
00021 
00022 using namespace rsim;
00023 
00024 MODULE_DECL(ReadoutSim);
00025 
00026 ClassImp(ReadoutSim);
00027 
00028 //----------------------------------------------------------------------
00029 
00030 ReadoutSim::ReadoutSim(const char* version) :
00031   jobc::Module("ReadoutSim")
00032 { 
00033   this->SetWatch("ReadoutSimConfig","default");
00034 }
00035 
00036 //----------------------------------------------------------------------
00037 
00038 ReadoutSim::~ReadoutSim()
00039 {
00040   this->RemoveAllWatches();
00041 }
00042 
00043 void ReadoutSim::Update(const cfg::Config& c)
00044 {
00045   
00046   //choose which mySim to use
00047   
00048   //std::cout <<"ReadoutSim::Update called \n";
00049   std::string simtype;
00050   c("SimType").Get(simtype);
00051   c("MessageLevel").Get(msglevel);
00052   c("StoreMCInfo").Get(storemcinfo);
00053   
00054   ChooseSim(simtype);
00055   
00056   //vector<std::string> simconfig;
00057   //c("SimConfig").Get(simconfig);
00058   //mySim->Configure(simconfig);
00059   
00060   mySim->Configure(c);
00061   
00062 }
00063 
00064 void ReadoutSim::ChooseSim(std::string simtype="")
00065 {
00066   
00067   //delete(mySim);
00068   
00069   if(!simtype.compare("SimpleReadout"))
00070   {
00071     mySim=new SimpleReadout();
00072   }
00073   else if(!simtype.compare("FarReadout"))
00074   {
00075     mySim=new FarReadout();
00076   } 
00077   else
00078   {
00079     mySim=new Simulator();
00080   }
00081 }
00082 
00083 jobc::Result ReadoutSim::Reco(edm::EventHandle& evt)
00084 {
00085   
00086   if(msglevel>=DEBUG)   printf("ReadoutSim Reco called\n");
00087   if(mySim==NULL){
00088     if(msglevel>=FATAL)std::cout<<"Major Error: Simulator never chosen....\n";
00089     return jobc::kFailed;
00090   }
00091   
00092   /*
00093     vector<const sim::FLSHitList*> hitlist(0);
00094     assert_jobc(evt.DetSim().Get("./",hitlist),
00095               "No FLSHitLists found in DetSim() folder!");
00096   */
00097   
00098   vector<const photrans::PhotonSignal*> hitlist(0);
00099   // assert_jobc(evt.Raw().Get("./",hitlist),
00100   //      "No PhotonSignals found in DetSim() folder!");
00101   
00102   try{
00103     evt.Raw().Get("./",hitlist);
00104   }catch(...){return jobc::kFailed;}
00105   
00106   std::vector<rawdata::RawDigit> rawdigitout(0);
00107   std::vector<sim::MCDigitInfo> mcdigitout(0);
00108   
00109   // take the digit list and pass it to the simulator, which returns raw digits that have passed through the simulator
00110   if(msglevel>=INFO)  std::cout <<"using simulator "<<*mySim<<"\n";     
00111   if(msglevel>=INFO)  std::cout<<"evt with "<<hitlist.size()<<" events\n";
00112   
00113   std::vector<const rawdata::DAQHeader*> header;
00114   short int det = rawdata::kFar;
00115   try{ evt.DAQ().Get("./",header); }
00116   catch(edm::Exception e){
00117     std::cerr << "Error retrieving daq header, while looking "<<
00118       "in ReadoutSim::Reco(), using default fardet geomety" << std::endl;
00119   }
00120   if(header.size() > 0) det = header[0]->DetId();
00121 
00122   mySim->SetGeom( evt.Header().Run(), det);
00123 
00124   rawdigitout = mySim->Simulate(hitlist, mcdigitout);
00125   
00126   //remove the raw digits from the root file from before the readout sim
00127   //    evt.Raw().ClearArrays();
00128   
00129   if(msglevel>=INFO) printf("   %d raw hits after simulation\n",rawdigitout.size());
00130   
00131   //put the new rawdigits
00132   for (unsigned int i=0; i<rawdigitout.size(); ++i)
00133     evt.Raw().Put(rawdigitout[i],"");
00134 
00135   // store MC info
00136   if(storemcinfo==1) {
00137     if (evt.Raw().GetFolder("./mcinfo")==0) 
00138       evt.Raw().MakeFolder("./mcinfo");
00139 
00140     /* cause bad_alloc error?
00141     for (unsigned int i=0; i<mcdigitout.size(); ++i)
00142       evt.Raw().Put(mcdigitout[i],"./mcinfo");
00143     */
00144   }    
00145 
00146   return jobc::kPassed;
00147 }
00148 
00150 

Generated on Sat Oct 11 02:35:28 2008 for NOvA Offline by  doxygen 1.3.9.1