Update:  New B/EEMC embedding framework from Wei-Ming Zhang currently in peer review

The present BEMC embedding works as an afterburner that must be done after the TPC embedding.  Wei-Ming Zhang is working on a version that work in parallel with the TPC embedding.  Here's the current workflow:

During TPC embedding

In this step, only real EMC data is processed with all of the TPC embedding.  In the end, there are two files:
  1. .event.root - This file contains the TPC reconstructed tracks (real data + simulation) and BEMC reco information (real data only)
  2. .geant.root - This files contains the simulated tracks (TPC + EMC simulated data)
Once again, no BEMC embedding is done at this level.  The chain that process the BEMC real data is the same as the one used for production (StEmcRawMaker, StPreEclMaker and StEpcMaker)

After TPC embedding

This is where the BEMC embedding happens.  The idea is to get the output from the TPC embedding (.geant.root and .event.root files) and mix the BEMC simulated data with the real BEMC data.  The mixing is performed by StEmcMixerMaker and the main idea is to add the simulated ADC values to the real event ADC values.  In order to do that we need to follow some simple rules:
  1. We have to simulate the ADC values with the same calibration table used for the real data
  2. We cannot add pedestals or noise to the simulated data.  The real data already include the pedestals and noise.  If we simulate them we will end up overestimating both quantities.
  3. We should embed simulated hits only for the towers with status==1.
The macro that runs the embedding can be found at StRoot/StEmcMixerMaker/macros/doEmcEmbedEvent.C.  The basic chain that runs in this macro is
  1. StIOMaker - to read the .event.root and .geant.root files
  2. St_db_Maker - to make the interface with the STAR database and get the BEMC tables
  3. StEmcADCtoEMaker - reprocesses the real BEMC data and fills an StEvent object with the calibrated real data.
  4. StEmcPreMixerMaker - this is a simple maker whose only function is to make sure the chain timestamp is set using the real data event time.  This is very important to make sure the tables are correctly retrieved from the database.
  5. StMcEventMaker - builds an StMcEvent object in memory.  This is necessary because the simulator maker needs to get the BEMC simulated data in this format.
  6. StEmcSimulatorMaker - this maker gets the StMcEvent in memory that contains the BEMC simulated hits and does a slow simulation of the detector, generating the ADC values with the correct calibration tables.  At this point we have two StEmcCollections in memory: the one with the real BEMC data from step 3, and the one with the simulated data from the simulator maker.
  7. StEmcMixerMaker - this maker gets the two StEmcCollections and adds the simulated one to the real data.  This is a simple ADC_total = ADC1 + ADC2 for each channel in each detector.  Only simulated hits belonging to channels that were good in the real data are added.
  8. StEmcADCtoEMaker - reconstructs the event once more.  This step gets the new ADC values and recalibrates them.
  9. StPreEclMaker - reconstructs the clusters with the embedded hits.
  10. StEpcMaker - reconstructs the points
  11. StAssociationMaker - does the TPC association
  12. StEmcAssociationMaker - does the BEMC association
  13. Add your own analysis maker
The embedding flow is illustrated in the following diagram: