Produces TPIs from raw data read in from BU CAEN. More...
Functions | |
static INT | module_init (void) |
static INT | module_event_caen (EVENT_HEADER *, void *) |
Variables | |
HNDLE | hDB |
TGlobalData * | gData |
Object to hold data used and produced by modules throughout alcapana stage of analysis. | |
TSetupData * | gSetup |
Hardware information about digitizers and detectors to be used during alcapana stage of analysis. | |
static vector< string > | caen_boston_bank_names |
List of BU CAEN bank names for the event loop. | |
static unsigned int | nPreSamples |
Number of samples to record before a trigger. | |
static const int | NCHAN = 4 |
Number of channels in DT5720. | |
ANA_MODULE | MDT5720ProcessRaw_module |
Produces TPIs from raw data read in from BU CAEN.
INT module_event_caen | ( | EVENT_HEADER * | pheader, | |
void * | pevent | |||
) | [static] |
Definition at line 117 of file MDT5720ProcessRaw.cpp.
References caen_boston_bank_names, TGlobalData::fPulseIslandToChannelMap, NCHAN, and nPreSamples.
00118 { 00119 // Some typedefs 00120 00121 typedef map<string, vector<TPulseIsland*> > TStringPulseIslandMap; 00122 typedef pair<string, vector<TPulseIsland*> > TStringPulseIslandPair; 00123 typedef map<string, vector<TPulseIsland*> >::iterator map_iterator; 00124 00125 // Fetch a reference to the gData structure that stores a map 00126 // of (bank_name, vector<TPulseIsland*>) pairs 00127 TStringPulseIslandMap& pulse_islands_map = 00128 gData->fPulseIslandToChannelMap; 00129 00130 // Delete the islands found in the previous block. Don't clear 00131 // the map of (bank_name, vector) pairs. Once we use a bank name 00132 // once, it will have a (possibly empty) entry in this map for the 00133 // whole run. JG: the islands.clear() line causes seg fault for > 1 TPulseIslandPair 00134 /*for(map_iterator iter = pulse_islands_map.begin(); 00135 iter != pulse_islands_map.end(); iter++){ 00136 vector<TPulseIsland*>& islands = iter->second; 00137 // Delete the pointers to TPulseIslands, then clear the vector 00138 for(unsigned int j=0; j<islands.size(); j++) { 00139 if(islands[j]) { delete islands[j]; islands[j] = NULL; } 00140 } 00141 islands.clear(); 00142 pulse_islands_map.erase(iter); // AE: need to erase the key so that blocks after the first will be recorded 00143 }*/ 00144 00145 // Get the event number 00146 int midas_event_number = pheader->serial_number; 00147 00148 BYTE *pdata; 00149 00150 // printf("In caen ER!\n"); 00151 00152 char bank_name[8]; 00153 sprintf(bank_name,"CND%i",0); // one MIDAS bank per board 00154 unsigned int bank_len = bk_locate(pevent, bank_name, &pdata); 00155 00156 // printf("MIDAS bank [%s] size %d ----------------------------------------\n",bank_name,bank_len); 00157 00158 /* uncomment when have real data 00159 if ( bank_len == 0 ) 00160 { 00161 return SUCCESS; 00162 } 00163 */ 00164 00165 00166 uint32_t *p32 = (uint32_t*)pdata; 00167 uint32_t *p32_0 = (uint32_t*)pdata; 00168 00169 00170 while ( (p32 - p32_0)*4 < bank_len ) 00171 { 00172 00173 uint32_t caen_event_cw = p32[0]>>28; 00174 // printf("CW: %08x\n",caen_event_cw); 00175 if ( caen_event_cw != 0xA ) 00176 { 00177 printf("***ERROR! Wrong data format it dt5720: incorrect control word 0x%08x\n", caen_event_cw); 00178 return SUCCESS; 00179 } 00180 00181 uint32_t caen_event_size = p32[0] & 0x0FFFFFFF; 00182 // printf("caen event size: %i\n",caen_event_size); 00183 00184 uint32_t caen_channel_mask = p32[1] & 0x000000FF; 00185 // count the number of channels in the event 00186 int nchannels = 0; 00187 for (int ichannel=0; ichannel<NCHAN; ichannel++ ) 00188 { 00189 if ( caen_channel_mask & (1<<ichannel) ) nchannels++; 00190 } 00191 // printf("caen channel mask: 0x%08x (%i)\n",caen_channel_mask,nchannels); 00192 00193 uint32_t caen_event_counter = p32[2] & 0x00FFFFFF; 00194 // printf("caen event counter: %i\n",caen_event_counter); 00195 00196 // PW: There seems to be a factor of 2 missing between the timestamp and real timestamp 00197 uint32_t caen_trigger_time = 2*p32[3]; 00198 // printf("caen trigger time: %i\n",caen_trigger_time);// = clock ticks? 00199 00200 // number of samples per channel 00201 unsigned int nsamples = ((caen_event_size-4)*2) / nchannels; 00202 // printf("waveform length: %i\n",nsamples); 00203 00204 // Loop through the channels (i.e. banks) 00205 for (std::vector<std::string>::iterator bankNameIter = caen_boston_bank_names.begin(); 00206 bankNameIter != caen_boston_bank_names.end(); bankNameIter++) { 00207 00208 vector<TPulseIsland*>& pulse_islands = pulse_islands_map[*(bankNameIter)]; 00209 std::vector<int> sample_vector; 00210 int ichannel = bankNameIter - caen_boston_bank_names.begin(); 00211 00212 // printf("TGlobalData bank [%s] ----------------------------------------\n", (*bankNameIter).c_str()); 00213 // printf("Number of TPulseIslands already existing = %d\n", pulse_islands.size()); 00214 // printf("*-- channel %i -------------------------------------------------------------*\n",ichannel); 00215 00216 if ( caen_channel_mask & (1<<ichannel) ) 00217 { 00218 // channel enabled 00219 unsigned int isample = 0; 00220 unsigned int nwords = nsamples/2; 00221 00222 for (int iword=0; iword<nwords; iword++) 00223 { 00224 00225 for (int isubword=0; isubword<2; isubword++) 00226 { 00227 uint32_t adc; 00228 00229 if (isubword == 0 ) 00230 adc = (p32[4+iword+ichannel*nwords] & 0x3fff); 00231 else 00232 adc = ((p32[4+iword+ichannel*nwords] >> 16) & 0x3fff); 00233 00234 //printf("CAEN DT5720 channel %d: adc[%i] = %i\n", ichannel, isample, adc); 00235 // h2_v1724_pulses[ichannel]->Fill(isample,adc); 00236 isample++; 00237 00238 sample_vector.push_back(adc); 00239 00240 } 00241 } 00242 00243 pulse_islands.push_back(new TPulseIsland(caen_trigger_time - nPreSamples, sample_vector, *bankNameIter)); 00244 } 00245 } 00246 00247 // *** updated by VT: align data by 32bit 00248 p32 += caen_event_size + (caen_event_size%2); 00249 // printf("offset: %i bank size: %i\n", (int)(p32-p32_0), bank_len); 00250 00251 } 00252 00253 // print for testing 00254 if(midas_event_number == 1) { 00255 // Loop through all the banks and print an output (because this ProcessRaw loops through pulses then banks, it has been put here) 00256 for (std::vector<std::string>::iterator bankNameIter = caen_boston_bank_names.begin(); 00257 bankNameIter != caen_boston_bank_names.end(); bankNameIter++) { 00258 00259 vector<TPulseIsland*>& pulse_islands = pulse_islands_map[*(bankNameIter)]; 00260 printf("TEST MESSAGE: Read %d events from bank %s in event %d\n", 00261 pulse_islands.size(), 00262 (*(bankNameIter)).c_str(), 00263 midas_event_number); 00264 } 00265 } 00266 00267 return SUCCESS; 00268 }
INT module_init | ( | void | ) | [static] |
Definition at line 79 of file MDT5720ProcessRaw.cpp.
References caen_boston_bank_names, TSetupData::fBankToDetectorMap, hDB, TSetupData::IsBostonCAEN(), and nPreSamples.
00080 { 00081 00082 std::map<std::string, std::string> bank_to_detector_map = gSetup->fBankToDetectorMap; 00083 for(std::map<std::string, std::string>::iterator mapIter = bank_to_detector_map.begin(); 00084 mapIter != bank_to_detector_map.end(); mapIter++) { 00085 00086 std::string bankname = mapIter->first; 00087 00088 // We only want the CAEN banks here 00089 if (TSetupData::IsBostonCAEN(bankname)) 00090 caen_boston_bank_names.push_back(bankname); 00091 } 00092 00093 /*** Get necessary data from ODB ***/ 00094 char key[80]; 00095 int size; 00096 unsigned int post_trigger_percentage, nSamples; 00097 00098 00099 // Get Trigger Time Tag info 00100 // Timestamp will be shifted by number of presamples 00101 00102 sprintf(key, "/Equipment/Crate 5/Settings/CAEN/waveform length"); 00103 size = sizeof(nSamples); 00104 db_get_value(hDB, 0, key, &nSamples, &size, TID_DWORD, 1); 00105 sprintf(key, "/Equipment/Crate 5/Settings/CAEN/post_trigger_size"); 00106 size = sizeof(post_trigger_percentage); 00107 db_get_value(hDB, 0, key, &post_trigger_percentage, &size, TID_BYTE, 1); 00108 //nPreSamples = (int) (0.01 * ((100 - post_trigger_percentage) * nSamples)); 00109 nPreSamples = 20; // From the Golden Data, it looks like there are 20 presamples. 00110 // The frontend does not seem to correctly load post_trigger_size 00111 // onto the CAEN. 00112 00113 return SUCCESS; 00114 }
vector<string> caen_boston_bank_names [static] |
List of BU CAEN bank names for the event loop.
Definition at line 49 of file MDT5720ProcessRaw.cpp.
Referenced by module_event_caen(), and module_init().
Object to hold data used and produced by modules throughout alcapana stage of analysis.
Definition at line 76 of file analyzer.cpp.
Hardware information about digitizers and detectors to be used during alcapana stage of analysis.
Definition at line 80 of file analyzer.cpp.
HNDLE hDB |
ANA_MODULE MDT5720ProcessRaw_module |
{ "MDT5720ProcessRaw", "Vladimir Tishchenko", module_event_caen, NULL, NULL, module_init, NULL, NULL, 0, NULL, }
Definition at line 64 of file MDT5720ProcessRaw.cpp.
const int NCHAN = 4 [static] |
Number of channels in DT5720.
Definition at line 62 of file MDT5720ProcessRaw.cpp.
Referenced by module_event_caen().
unsigned int nPreSamples [static] |
Number of samples to record before a trigger.
At the moment this is hard coded into the module_init function instead of grabbed from the ODB. The way the CAEN should work is that a percentage of the total sampling window is set to be the "after trigger". However, it does not seem like this was set correctly in the front end.
Definition at line 59 of file MDT5720ProcessRaw.cpp.
Referenced by PulseEstimate::Estimate(), module_event_caen(), and module_init().