// $Id$ // // File: DBCALTimeSpectrum_factory_2006BeamTest.cc // Created: Thu Aug 30 9:34:05 EDT 2011 // Creator: davidl (on Linux ifarm1102 2.6.18-128.7.1.el5 x86_64) // #include #include #include using namespace std; #include "DBCALTimeSpectrum_factory.h" #include "DBCALTimeSpectrum_factory_2006BeamTest.h" using namespace jana; // These are copied from a version of timewalk.cc which is // auto-generated from timewalk_calibrate.C for the specific // summing scheme implemented here. static double BCAL_TimeWalkUp(double fADC, int layer); static double BCAL_TimeWalkDn(double fADC, int layer); #include "timewalk_2006BeamTest.h" //------------------ // init //------------------ jerror_t DBCALTimeSpectrum_factory_2006BeamTest::init(void) { /// Fill in the sum_map. This is used later to produce summed /// cells. // It's easiest just to loop over all SiPM layer/sector combos // and index the map with the id causing it to be created if it // doesn't already exist. for(int layer=1; layer<=10; layer++){ for(int sector=1; sector<=4; sector++){ int idx = GetSummedCell(layer, sector); sum_map[idx]; // This is all that's need to ensure an entry in sum_map exists } } return NOERROR; } //------------------ // GetSummedLayer //------------------ int DBCALTimeSpectrum_factory_2006BeamTest::GetSummedLayer(int layer, int sector) { switch(layer){ case 1: case 2: return 1; case 3: case 4: return 2; case 5: case 6: return 3; case 7: return 4; case 8: if(sector==2 || sector==3)return 5; return 4; case 9: if(sector==2 || sector==3)return 6; return 6; case 10: if(sector==2 || sector==3)return 7; return 6; } return 0; } //------------------ // GetSummedSector //------------------ int DBCALTimeSpectrum_factory_2006BeamTest::GetSummedSector(int layer, int sector) { switch(sector){ case 1: return 1; case 2: case 3: return 2; case 4: return 3; } return 0; } //------------------ // GetSummedCell //------------------ int DBCALTimeSpectrum_factory_2006BeamTest::GetSummedCell(int layer, int sector) { // Return the index of the summed cell given the layer // and sector. int summed_layer = GetSummedLayer(layer, sector); int summed_sector = GetSummedSector(layer, sector); return summed_layer*10 + summed_sector; } //------------------ // GetSummedLayerAndSectorFromCell //------------------ void DBCALTimeSpectrum_factory_2006BeamTest::GetSummedLayerAndSectorFromCell(int cell, int &summed_layer, int &summed_sector) { // Return the summed layer and summed sector based on the cell number summed_layer = cell/10; summed_sector = cell%10; } //------------------ // brun //------------------ jerror_t DBCALTimeSpectrum_factory_2006BeamTest::brun(jana::JEventLoop *eventLoop, int runnumber) { return NOERROR; } //------------------ // evnt //------------------ jerror_t DBCALTimeSpectrum_factory_2006BeamTest::evnt(JEventLoop *loop, int eventnumber) { vector spectra; // Jump through hoops to get to untagged factory DBCALTimeSpectrum_factory *fac = (DBCALTimeSpectrum_factory*)loop->GetFactory("DBCALTimeSpectrum","",false); fac->Get(spectra); // Clear all sum vectors map >::iterator iter; for(iter=sum_map.begin(); iter!=sum_map.end(); iter++){ iter->second.clear(); } // Loop over single SiPM spectra and sort them into // lists according to the summing scheme for(unsigned int i=0; ilayer, spectrum->sector); sum_map[idx].push_back(spectrum); } // Loop over all summed cells and create DBCALTimeSpectrum objects // for each for(iter=sum_map.begin(); iter!=sum_map.end(); iter++){ int summed_layer, summed_sector; GetSummedLayerAndSectorFromCell(iter->first, summed_layer, summed_sector); double thresh_mV = 44.7; DBCALTimeSpectrum *spectrum = new DBCALTimeSpectrum(THRESH_TDC_mV, iter->second, summed_layer, summed_sector); // Overwrite corrected times so we can apply timewalk // corrections for the summed cells spectrum->tup_corrected = spectrum->tup; if(spectrum->tup>-1000.0){ spectrum->tup_corrected -= BCAL_TimeWalkUp(spectrum->fADC_up, summed_layer); } spectrum->tdn_corrected = spectrum->tdn; if(spectrum->tdn>-1000.0){ spectrum->tdn_corrected -= BCAL_TimeWalkDn(spectrum->fADC_dn, summed_layer); } _data.push_back(spectrum); } return NOERROR; } //------------------ // erun //------------------ jerror_t DBCALTimeSpectrum_factory_2006BeamTest::erun(void) { return NOERROR; } //------------------ // fini //------------------ jerror_t DBCALTimeSpectrum_factory_2006BeamTest::fini(void) { return NOERROR; }