CalDigitizer Class Reference

#include <CalDigitizer.h>

Inheritance diagram for CalDigitizer:

JobCModule CfgObserver List of all members.

Public Member Functions

 CalDigitizer (const char *version)
 ~CalDigitizer ()
JobCResult Reco (EDMEventHandle &evt)
void NewRun (int run, int subrun)
void Update (const CfgConfig &c)
bool GetPedestals (int)
void GetCalMCCHits (EDMEventHandle &evt)
void CalHist ()

Private Attributes

std::vector< const MCCHit * > fHits
std::vector< const MCCCaloHits * > fCaloHits
int fDebug
double fHscale
double fEscale
double fHsigma
TTree * fCalMCTree
int fNHits
int fMinRun
int fMaxRun
float ecal_energy [EMCal::nEcalChan]
float hcal_energy [EMCal::nHcalChan]
short fPed [EMCal::nCalChan]
short fWidth [EMCal::nCalChan]
short pedestal
int fEAdc [EMCal::nEcalChan]
int fHAdc [EMCal::nHcalChan]
int fEAdd [EMCal::nEcalChan]
int fHAdd [EMCal::nHcalChan]
int fEMtot
int fHtot
float em_totedep
float h_totedep

Static Private Attributes

static const double ecal_e2adc = 1.00e7
static const double hcal_e2adc = 2.5e3
static const double hcal_sigma = 0.006

Detailed Description

Definition at line 22 of file CalDigitizer.h.


Constructor & Destructor Documentation

CalDigitizer::CalDigitizer ( const char *  version  ) 

Definition at line 35 of file CalDigitizer.cxx.

References CalHist(), and JobCModule::SetCfgVersion().

00035                                               :
00036   JobCModule("CalDigitizer")
00037 { 
00038   this->SetCfgVersion(version);
00039   
00040   CalHist();
00041 }

CalDigitizer::~CalDigitizer (  ) 

Definition at line 45 of file CalDigitizer.cxx.

References fCalMCTree.

00046 {
00047   if (fCalMCTree)   
00048     {
00049       fCalMCTree->Write();
00050       delete fCalMCTree;
00051     }
00052 }


Member Function Documentation

void CalDigitizer::CalHist (  ) 

Definition at line 55 of file CalDigitizer.cxx.

References ecal_energy, em_totedep, fCalMCTree, fEAdc, fEAdd, fEMtot, fHAdc, fHAdd, fHtot, h_totedep, and hcal_energy.

Referenced by CalDigitizer().

00056 {
00057   fCalMCTree = new TTree("CalMC","Calorimeter MC Digits");
00058   fCalMCTree->Branch("EMDep", &ecal_energy,"ecal_energy[640]/D");
00059   fCalMCTree->Branch("HDep", &hcal_energy,"hcal_energy[8]/D");
00060   fCalMCTree->Branch("EMadd", &fEAdd,"fEAdd[640]/I");
00061   fCalMCTree->Branch("Hadd", &fHAdd,"fHAdd[8]/I");
00062   fCalMCTree->Branch("EMadc", &fEAdc,"fEAdc[640]/I");
00063   fCalMCTree->Branch("Hadc", &fHAdc,"fHAdc[8]/I");
00064   fCalMCTree->Branch("EMtot",&fEMtot,"fEMtot/I");
00065   fCalMCTree->Branch("Htot",&fHtot,"fHtot/I");
00066   fCalMCTree->Branch("totEMedep",&em_totedep,"em_totedep/D");
00067   fCalMCTree->Branch("totHedep",&h_totedep,"h_totedep/D");
00068 
00069 }

void CalDigitizer::GetCalMCCHits ( EDMEventHandle evt  ) 

Definition at line 252 of file CalDigitizer.cxx.

References EDMEventHandle::DetSim(), fDebug, fHits, fNHits, and EDMDataBucket::Get().

00253 {
00254  /* get hits from MCCHit which holds hits as per gsahit 
00255     this will  have all the "unsummed hits" for emxt/emyt
00256   */
00257   // Get hits
00258   fHits.clear();
00259   try {
00260     evt.DetSim().Get("./ecal", fHits);
00261     if (fHits.empty()) {
00262     }
00263   }
00264   catch (...) {
00265     if (fDebug) std::cout << "No hits folder for EMCal " << std::endl;
00266   }
00267   fNHits = fHits.size();
00268   if (fDebug) {
00269     for (int i = 0; i < fNHits; ++i) {
00270       std::cout << *(fHits[i]) << std::endl;
00271     }
00272   }
00273 
00274   float ed=0;
00275   for (int i=0; i<fNHits; i++) {
00276     const MCCHit* hits = fHits[i];
00277     ed = hits->EDep();
00278   }
00279 }

bool CalDigitizer::GetPedestals ( int   ) 

Definition at line 291 of file CalDigitizer.cxx.

References fDebug, fPed, fWidth, EMCalPed::Init(), EMCalPed::Instance(), RIMCConfig::kMCRunOffset, EMCal::nCalChan, and EMCalPed::Width().

Referenced by NewRun().

00292 {
00293   int mcrun = 17011;
00294   if (run >= RIMCConfig::kMCRunOffset) 
00295     {
00296        mcrun = run%RIMCConfig::kMCRunOffset;
00297     }
00298   EMCalPed::Init(mcrun);
00299 //  std::cout << "DigiRun = " << mcrun << std::endl;
00300   
00301     memset(fPed, 0, sizeof(fPed));
00302     memset(fWidth, 0, sizeof(fWidth));
00303   // get pedestals for this run
00304   for (int i = 0; i < EMCal::nCalChan; ++i) {
00305     fPed[i]   = EMCalPed::Instance().Ped(i);
00306     fWidth[i] = EMCalPed::Instance().Width(i);
00307   }
00308   if (fDebug) {
00309     std::cout<<"  fPed[0]="<<fPed[0]<<"  fWidth[0]="<<fWidth[0]<<std::endl;
00310     std::cout<<"  fPed[647]="<<fPed[647]<<"  fWidth[647]="<<fWidth[647]<<std::endl;
00311   }
00312     return true;
00313 }

void CalDigitizer::NewRun ( int  run,
int  subrun 
) [virtual]

Reimplemented from JobCModule.

Definition at line 317 of file CalDigitizer.cxx.

References GetPedestals().

00318 {
00319   GetPedestals(run);
00320 }

JobCResult CalDigitizer::Reco ( EDMEventHandle evt  )  [virtual]

Reimplemented from JobCModule.

Definition at line 71 of file CalDigitizer.cxx.

References EDMEventHandle::DetSim(), ecal_energy, em_totedep, fCalMCTree, fCaloHits, fDebug, fEAdc, fEAdd, fEMtot, fEscale, fHAdc, fHAdd, fHscale, fHtot, fNHits, fPed, EDMDataBucket::Get(), h_totedep, hcal_energy, JobCModule::kPassed, EMCal::nEcalChan, EMCal::nHcalChan, pedestal, EDMDataBucket::Put(), EDMEventHandle::Raw(), and ADCDigit::Set().

00072 {
00073     //fDebug = 1;
00074     /*
00075     GetCalMCCHits(EDMEventHandle& evt);
00076     */
00077     //int runnum = evt.Header().Run();
00078 
00079 //==============
00080 // first do emcal
00081 //==============
00082 
00083 // get summed emcal hits as stored in MCCCaloHits (from get_emcal_channels)
00084 
00085     // clear the vector
00086     fCaloHits.clear();
00087     try 
00088       {
00089     evt.DetSim().Get("./ecal", fCaloHits);
00090       }
00091     catch (...) 
00092       {
00093     if (fDebug) std::cout << "No Summed EMCal Hits" << std::endl;
00094     return kPassed;
00095       }
00096  
00097    // number of hits 
00098     fNHits = fCaloHits.size();
00099 
00100     // print debugging info
00101     if (fDebug) 
00102       {
00103     for (int i = 0; i < fNHits; ++i) 
00104       {
00105         std::cout << *(fCaloHits[i]) << std::endl;
00106       }
00107       }
00108 
00109 
00110    // initialize the address and hit arrays 
00111     int address = 0;
00112     memset(ecal_energy,0,sizeof(ecal_energy));
00113 
00114     em_totedep = 0.0;
00115 
00116    // address and load the energy deposits
00117     for (int i=0; i<fNHits; i++) 
00118       {
00119     const MCCCaloHits* hits = fCaloHits[i];
00120     address = hits->CalAddr() - 1;
00121     ecal_energy[address] = hits->CalEn();
00122     em_totedep += ecal_energy[address];
00123       }
00124     if (fDebug) std::cout << "emcal total = " << em_totedep << std::endl;
00125 
00126     // convert to adc digits and write out 
00127     // folder where the adcs will go
00128     const char* edir = "./ecal";
00129 
00130     ADCDigit ecalDigit;
00131     memset(fEAdd,0,sizeof(fEAdd));
00132     memset(fEAdc,0,sizeof(fEAdc));
00133     fEMtot  = 0;
00134     for (short i=0; i<EMCal::nEcalChan; ++i)
00135     {
00136 //      pedestal = int(NMRandom::Gauss(fPed[i],fWidth[i]));
00137         pedestal = fPed[i];
00138 
00139       // convert energy to ADC units and add peds
00140       fEAdd[i] = int(ecal_energy[i]*fEscale + 0.5);
00141       fEAdc[i] =  pedestal + fEAdd[i];
00142       fEMtot += fEAdd[i];
00143 
00144       // EMCal ADCs are 12-bit. If ADC overflows 12 bits, set it to fff
00145       if (fEAdc[i] > 0x0fff) fEAdc[i] = 0x0fff;
00146 
00147       // debug
00148       if (fDebug)
00149     {
00150       if (fEAdc[i] > pedestal) std::cout << i << " " << "ped: " << pedestal << " en: " << ecal_energy[i] << " add: " << fEAdd[i] << " adc: " << fEAdc[i] << std::endl;
00151     }
00152 
00153       // set the digits
00154       ecalDigit.Set(i,fEAdc[i]);
00155 
00156       // put it out
00157       evt.Raw().Put(ecalDigit,edir);
00158 
00159       //debug
00160       if (fDebug) std::cout << "edigi: " << i << " " << fEAdc[i] << " ped=" << pedestal << std::endl;
00161     }
00162 
00163 //==============
00164 // now hcal
00165 /////////////////////////////////////////////////////////////
00166 
00167     // clear the vector
00168     fCaloHits.clear();
00169  
00170    // get hits from the sim hcal folder 
00171     try 
00172       {
00173     evt.DetSim().Get("./hcal", fCaloHits);
00174       }
00175     catch (...) 
00176       {
00177     std::cout << "No Summed HCal Hits" << std::endl;
00178     return kPassed;
00179       }
00180  
00181    // number of hits 
00182     fNHits = fCaloHits.size();
00183  
00184    // debug 
00185     if (fDebug) 
00186       {
00187     for (int i = 0; i < fNHits; ++i) 
00188       {
00189         std::cout << *(fCaloHits[i]) << std::endl;
00190       }
00191       }
00192 
00193  
00194    // initialize the address and hit arrays 
00195     address = 0;
00196     memset(hcal_energy,0,sizeof(hcal_energy));
00197   
00198    h_totedep = 0.0; 
00199    // store the addressed energy deposits 
00200     for (int i=0; i<fNHits; i++) 
00201       {
00202     const MCCCaloHits* hits = fCaloHits[i];
00203     address = hits->CalAddr() - 1;
00204     hcal_energy[address] = hits->CalEn();
00205     h_totedep += hcal_energy[address];
00206       }
00207 
00208     if (fDebug) std::cout << "hcal total = " << h_totedep << std::endl;
00209 
00210     // convert energies to ADCs and write them out
00211     // output folder name
00212     const char* hdir = "./hcal";
00213 
00214     ADCDigit hcalDigit;
00215     memset(fHAdd,0,sizeof(fHAdd));
00216     memset(fHAdc,0,sizeof(fHAdc));
00217     fHtot = 0;
00218     for (short i=0; i<EMCal::nHcalChan; ++i)
00219       {
00220     // index 640+i for the hcal peds in the fPed array
00221         int j = i + EMCal::nEcalChan;
00222 //      pedestal = int(NMRandom::Gauss(fPed[j],fWidth[j]));
00223         pedestal = fPed[j];
00224 
00225     // smear energy
00226 //  float hsmear = NMRandom::Gauss(0., hcal_sigma);
00227 //  hcal_energy[i] = hcal_energy[i] + hsmear;
00228 
00229     // convert and add peds
00230     fHAdd[i] = int(hcal_energy[i]*fHscale + 0.5);
00231         fHAdc[i] =  pedestal + fHAdd[i];
00232     fHtot += fHAdd[i];
00233 
00234     // if the adc overflows 14-bits, set it to 3fff
00235     if (fHAdc[i] > 0x3fff) fHAdc[i] = 0x3fff;
00236 
00237     // set the digits
00238     hcalDigit.Set(i,fHAdc[i]);
00239 
00240     // put it out
00241     evt.Raw().Put(hcalDigit,hdir);
00242 
00243     if (fDebug) std::cout << "hdigi: " << i << " " << fHAdc[i] << std::endl;
00244       }
00245 /* done with emcal and hcal */
00246     fCalMCTree->Fill();
00247     
00248     return kPassed;
00249 }

void CalDigitizer::Update ( const CfgConfig c  )  [virtual]

Implements CfgObserver.

Definition at line 282 of file CalDigitizer.cxx.

References fDebug, fEscale, fHscale, and fHsigma.

00283 {
00284   c("Debug").Get(fDebug);
00285   c("HScale").Get(fHscale);
00286   c("EScale").Get(fEscale);
00287   c("HSigma").Get(fHsigma);
00288 }


Member Data Documentation

const double CalDigitizer::ecal_e2adc = 1.00e7 [static, private]

Definition at line 78 of file CalDigitizer.h.

float CalDigitizer::ecal_energy[EMCal::nEcalChan] [private]

Definition at line 54 of file CalDigitizer.h.

Referenced by CalHist(), and Reco().

float CalDigitizer::em_totedep [private]

Definition at line 71 of file CalDigitizer.h.

Referenced by CalHist(), and Reco().

TTree* CalDigitizer::fCalMCTree [private]

Definition at line 44 of file CalDigitizer.h.

Referenced by CalHist(), Reco(), and ~CalDigitizer().

std::vector<const MCCCaloHits*> CalDigitizer::fCaloHits [private]

Definition at line 37 of file CalDigitizer.h.

Referenced by Reco().

int CalDigitizer::fDebug [private]

Definition at line 40 of file CalDigitizer.h.

Referenced by GetCalMCCHits(), GetPedestals(), Reco(), and Update().

int CalDigitizer::fEAdc[EMCal::nEcalChan] [private]

Definition at line 63 of file CalDigitizer.h.

Referenced by CalHist(), and Reco().

int CalDigitizer::fEAdd[EMCal::nEcalChan] [private]

Definition at line 65 of file CalDigitizer.h.

Referenced by CalHist(), and Reco().

int CalDigitizer::fEMtot [private]

Definition at line 69 of file CalDigitizer.h.

Referenced by CalHist(), and Reco().

double CalDigitizer::fEscale [private]

Definition at line 41 of file CalDigitizer.h.

Referenced by Reco(), and Update().

int CalDigitizer::fHAdc[EMCal::nHcalChan] [private]

Definition at line 64 of file CalDigitizer.h.

Referenced by CalHist(), and Reco().

int CalDigitizer::fHAdd[EMCal::nHcalChan] [private]

Definition at line 66 of file CalDigitizer.h.

Referenced by CalHist(), and Reco().

std::vector<const MCCHit*> CalDigitizer::fHits [private]

Definition at line 36 of file CalDigitizer.h.

Referenced by GetCalMCCHits().

double CalDigitizer::fHscale [private]

Definition at line 41 of file CalDigitizer.h.

Referenced by Reco(), and Update().

double CalDigitizer::fHsigma [private]

Definition at line 41 of file CalDigitizer.h.

Referenced by Update().

int CalDigitizer::fHtot [private]

Definition at line 70 of file CalDigitizer.h.

Referenced by CalHist(), and Reco().

int CalDigitizer::fMaxRun [private]

Definition at line 51 of file CalDigitizer.h.

int CalDigitizer::fMinRun [private]

Definition at line 50 of file CalDigitizer.h.

int CalDigitizer::fNHits [private]

Definition at line 47 of file CalDigitizer.h.

Referenced by GetCalMCCHits(), and Reco().

short CalDigitizer::fPed[EMCal::nCalChan] [private]

Definition at line 58 of file CalDigitizer.h.

Referenced by GetPedestals(), and Reco().

short CalDigitizer::fWidth[EMCal::nCalChan] [private]

Definition at line 59 of file CalDigitizer.h.

Referenced by GetPedestals().

float CalDigitizer::h_totedep [private]

Definition at line 72 of file CalDigitizer.h.

Referenced by CalHist(), and Reco().

const double CalDigitizer::hcal_e2adc = 2.5e3 [static, private]

Definition at line 81 of file CalDigitizer.h.

float CalDigitizer::hcal_energy[EMCal::nHcalChan] [private]

Definition at line 55 of file CalDigitizer.h.

Referenced by CalHist(), and Reco().

const double CalDigitizer::hcal_sigma = 0.006 [static, private]

Definition at line 84 of file CalDigitizer.h.

short CalDigitizer::pedestal [private]

Definition at line 60 of file CalDigitizer.h.

Referenced by Reco().


The documentation for this class was generated from the following files:
Generated on Mon Nov 23 08:03:59 2009 for MIPP(E907) by  doxygen 1.4.7