]>
Commit | Line | Data |
---|---|---|
0cfe76b5 | 1 | /******************************************************************************* |
2 | * Copyright(c) 2003, IceCube Experiment at the South Pole. All rights reserved. | |
3 | * | |
4 | * Author: The IceCube RALICE-based Offline Project. | |
5 | * Contributors are mentioned in the code where appropriate. | |
6 | * | |
7 | * Permission to use, copy, modify and distribute this software and its | |
8 | * documentation strictly for non-commercial purposes is hereby granted | |
9 | * without fee, provided that the above copyright notice appears in all | |
10 | * copies and that both the copyright notice and this permission notice | |
11 | * appear in the supporting documentation. | |
12 | * The authors make no claims about the suitability of this software for | |
13 | * any purpose. It is provided "as is" without express or implied warranty. | |
14 | *******************************************************************************/ | |
15 | ||
16 | // $Id$ | |
17 | ||
18 | /////////////////////////////////////////////////////////////////////////// | |
19 | // Class IceRawTWR | |
20 | // Conversion of Amanda raw TWR data into IceEvent data structures. | |
21 | // The code to actually read the TWR raw data structures is an Ralice/IcePack | |
22 | // implementation of Wolfgang Wagner's (Dortmund University, Germany) | |
23 | // original read_twr_binary_file.cxx and wf2hit_new.cxx source code. | |
24 | // The trigger information as encountered in the raw data, is available | |
25 | // in the IceEvent structure via a device named "Trigger". | |
26 | // The various triggers (and times) have been stored as different "hits" | |
27 | // in this "Trigger" device, just like it was done in the IceF2k processor | |
28 | // for the mu-daq F2K data. | |
29 | // An indication of the active DAQ system is available in the IceEvent structure | |
30 | // via a device named "Daq". Here the various daq systems (TWR, Muon, ...) | |
31 | // from which the actual hits (ADC, LE, TOT) eventually will be composed | |
32 | // are indicated as "signals" of the device itself. | |
33 | // This class is derived from AliJob providing a task-based processing | |
34 | // structure on an event-by-event basis. | |
35 | // The main object in the job environment is an IceEvent* pointer. | |
36 | // In case the user has provided sub-tasks, these will be executed | |
37 | // on an event-by-event basis after the IceEvent structure has been filled | |
38 | // with the raw TWR data and before the final structures are written out. | |
39 | // Note that the data structures are only written out if an outputfile has | |
40 | // been specified via the SetOutputFile memberfunction. | |
41 | // In case no outputfile has been specified, this class provides a facility | |
42 | // to investigate/analyse raw TWR data using the Ralice/IcePack analysis tools. | |
43 | // | |
44 | // Usage example : | |
45 | // --------------- | |
46 | // | |
47 | // gSystem->Load("ralice"); | |
48 | // gSystem->Load("icepack"); | |
49 | // gSystem->Load("iceconvert"); | |
50 | // | |
51 | // IceRawTWR q("IceRawTWR","TWR raw data to IcePack data structure conversion"); | |
52 | // | |
53 | // // Limit the number of entries for testing | |
54 | // q.SetMaxEvents(10); | |
55 | // | |
56 | // // Print frequency to produce a short summary print every printfreq events | |
57 | // q.SetPrintFreq(1); | |
58 | // | |
59 | // // The TWR raw data input filename(s) | |
60 | // q.AddInputFile("twr_2005_101_009225_0983_57784_57850.dat.twr.to_tape_1"); | |
61 | // | |
62 | // // Output file for the event structures | |
63 | // q.SetOutputFile("events.root"); | |
64 | // | |
65 | // /////////////////////////////////////////////////////////////////// | |
66 | // // Here the user can specify his/her sub-tasks to be executed | |
67 | // // on an event-by-event basis after the IceEvent structure | |
68 | // // has been filled and before the data is written out. | |
69 | // // Sub-tasks (i.e. a user classes derived from TTask) are entered | |
70 | // // as follows : | |
71 | // // | |
72 | // // MyXtalk task1("task1","Cross talk correction"); | |
73 | // // MyClean task2("task2","Hit cleaning"); | |
74 | // // q.Add(&task1); | |
75 | // // q.Add(&task2); | |
76 | // // | |
77 | // // The sub-tasks will be executed in the order as they are entered. | |
78 | // /////////////////////////////////////////////////////////////////// | |
79 | // | |
80 | // // Perform the conversion and execute subtasks (if any) | |
81 | // // on an event-by-event basis | |
82 | // q.ExecuteJob(); | |
83 | // | |
84 | //--- Author: Nick van Eijndhoven 12-dec-2006 Utrecht University | |
85 | //- Modified: NvE $Date$ Utrecht University | |
86 | /////////////////////////////////////////////////////////////////////////// | |
87 | ||
88 | #include "IceRawTWR.h" | |
89 | #include "Riostream.h" | |
90 | ||
91 | ClassImp(IceRawTWR) // Class implementation to enable ROOT I/O | |
92 | ||
93 | IceRawTWR::IceRawTWR(const char* name,const char* title) : AliJob(name,title) | |
94 | { | |
95 | // Default constructor. | |
96 | // By default maxevent=-1, split=0, bsize=32000, printfreq=1. | |
97 | ||
98 | fSplit=0; | |
99 | fBsize=32000; | |
100 | fMaxevt=-1; | |
101 | fPrintfreq=1; | |
102 | fInfiles=0; | |
103 | fOutfile=0; | |
104 | } | |
105 | /////////////////////////////////////////////////////////////////////////// | |
106 | IceRawTWR::~IceRawTWR() | |
107 | { | |
108 | // Default destructor. | |
109 | ||
110 | if (fInfiles) | |
111 | { | |
112 | delete fInfiles; | |
113 | fInfiles=0; | |
114 | } | |
115 | } | |
116 | /////////////////////////////////////////////////////////////////////////// | |
117 | void IceRawTWR::SetMaxEvents(Int_t n) | |
118 | { | |
119 | // Set the maximum number of events to be processed. | |
120 | // n=-1 implies processing of the complete input file, which is the default | |
121 | // initialisation in the constructor. | |
122 | fMaxevt=n; | |
123 | } | |
124 | /////////////////////////////////////////////////////////////////////////// | |
125 | void IceRawTWR::SetPrintFreq(Int_t f) | |
126 | { | |
127 | // Set the printfrequency to produce info every f events. | |
128 | // f=1 is the default initialisation in the constructor. | |
129 | if (f>=0) fPrintfreq=f; | |
130 | } | |
131 | /////////////////////////////////////////////////////////////////////////// | |
132 | void IceRawTWR::SetSplitLevel(Int_t split) | |
133 | { | |
134 | // Set the split level for the ROOT data file. | |
135 | // split=0 is the default initialisation in the constructor. | |
136 | if (split>=0) fSplit=split; | |
137 | } | |
138 | /////////////////////////////////////////////////////////////////////////// | |
139 | void IceRawTWR::SetBufferSize(Int_t bsize) | |
140 | { | |
141 | // Set the buffer size for the ROOT data file. | |
142 | // bsize=32000 is the default initialisation in the constructor. | |
143 | if (bsize>=0) fBsize=bsize; | |
144 | } | |
145 | /////////////////////////////////////////////////////////////////////////// | |
146 | void IceRawTWR::AddInputFile(TString name) | |
147 | { | |
148 | // Add the name of this TWR raw data input file to the list to be processed. | |
149 | ||
150 | if (!fInfiles) | |
151 | { | |
152 | fInfiles=new TObjArray(); | |
153 | fInfiles->SetOwner(); | |
154 | } | |
155 | ||
156 | TObjString* s=new TObjString(); | |
157 | s->SetString(name); | |
158 | fInfiles->Add(s); | |
159 | } | |
160 | /////////////////////////////////////////////////////////////////////////// | |
161 | void IceRawTWR::SetOutputFile(TFile* ofile) | |
162 | { | |
163 | // Set the output file for the ROOT data. | |
164 | if (fOutfile) delete fOutfile; | |
165 | fOutfile=ofile; | |
166 | } | |
167 | /////////////////////////////////////////////////////////////////////////// | |
168 | void IceRawTWR::SetOutputFile(TString name) | |
169 | { | |
170 | // Create the output file for the ROOT data. | |
171 | if (fOutfile) delete fOutfile; | |
6280c0e2 | 172 | fOutfile=new TFile(name.Data(),"RECREATE","TWR raw data in IceEvent structure"); |
0cfe76b5 | 173 | } |
174 | /////////////////////////////////////////////////////////////////////////// | |
175 | TFile* IceRawTWR::GetOutputFile() | |
176 | { | |
177 | // Provide pointer to the ROOT output file. | |
178 | return fOutfile; | |
179 | } | |
180 | /////////////////////////////////////////////////////////////////////////// | |
181 | void IceRawTWR::Exec(Option_t* opt) | |
182 | { | |
183 | // Job to loop over the specified number of events and convert the | |
184 | // TWR raw data into the IceEvent structure. | |
185 | // If maxevents<0 (default) all the entries of the input file | |
186 | // will be processed. | |
187 | // Every "printfreq" events a short event summary will be printed. | |
188 | // The default value is printfreq=1. | |
189 | // The output will be written on a standard output tree named "T". | |
190 | // | |
191 | // Notes : | |
192 | // ------- | |
193 | // 1) This class is derived from AliJob, allowing a task based processing. | |
194 | // After the conversion of a raw data event into an IceEvent structure, | |
195 | // the processing of all available sub-tasks (if any) is invoked. | |
196 | // This provides an event-by-event (sub)task processing before the | |
197 | // final data structures are written out. | |
198 | // 2) The main object in this job environment is an IceEvent* pointer. | |
199 | ||
200 | if (!fInfiles) | |
201 | { | |
202 | cout << " *IceRawTWR Exec* No data input file(s) specified." << endl; | |
203 | return; | |
204 | } | |
205 | ||
206 | Int_t ninfiles=fInfiles->GetEntries(); | |
207 | if (!ninfiles) | |
208 | { | |
209 | cout << " *IceRawTWR Exec* No data input file(s) specified." << endl; | |
210 | return; | |
211 | } | |
212 | ||
213 | TTree* otree=0; | |
214 | if (fOutfile) | |
215 | { | |
216 | otree=new TTree("T","TWR raw data converted to IceEvent structures"); | |
217 | otree->SetDirectory(fOutfile); | |
218 | } | |
219 | ||
220 | IceEvent* evt=new IceEvent(); | |
221 | evt->SetTrackCopy(1); | |
222 | evt->SetDevCopy(1); | |
223 | ||
224 | // Branch in the tree for the event structure | |
225 | if (otree) otree->Branch("IceEvent","IceEvent",&evt,fBsize,fSplit); | |
226 | ||
227 | // Initialise the job working environment | |
228 | SetMainObject(evt); | |
229 | if (fOutfile) | |
230 | { | |
231 | AddObject(fOutfile); | |
232 | AddObject(otree); | |
233 | } | |
234 | ||
235 | TString inputfile; | |
236 | ||
237 | cout << " ***" << endl; | |
238 | cout << " *** Start processing of job " << GetName() << " ***" << endl; | |
239 | cout << " ***" << endl; | |
240 | for (Int_t i=0; i<ninfiles; i++) | |
241 | { | |
242 | TObjString* sx=(TObjString*)fInfiles->At(i); | |
243 | if (!sx) continue; | |
244 | inputfile=sx->GetString(); | |
245 | cout << " TWR raw data input file : " << inputfile.Data() << endl; | |
246 | } | |
247 | cout << " Maximum number of events to be processed : " << fMaxevt << endl; | |
248 | cout << " Print frequency : " << fPrintfreq << endl; | |
249 | if (fOutfile) | |
250 | { | |
251 | cout << " ROOT output file : " << fOutfile->GetName() << endl; | |
252 | cout << " Output characteristics : splitlevel = " << fSplit << " buffersize = " << fBsize << endl; | |
253 | } | |
254 | ||
255 | ListEnvironment(); | |
256 | ||
257 | // Storage of the used parameters in the IceRawTWR device | |
258 | AliDevice params; | |
259 | params.SetNameTitle("IceRawTWR","IceRawTWR processor parameters"); | |
260 | params.SetSlotName("Nchannels",1); | |
261 | params.SetSlotName("Ntriggers",2); | |
262 | params.SetSlotName("BaselineOffset",3); | |
263 | params.SetSignal(float(N_OF_CHANNELS),1); | |
264 | params.SetSignal(float(N_OF_TRIGGERS),2); | |
265 | params.SetSignal(float(BASELINE_MEAN_MAGIC),3); | |
266 | ||
267 | // Set DAQ device info | |
268 | AliDevice daq; | |
269 | daq.SetName("Daq"); | |
270 | daq.SetSlotName("TWR",1); | |
271 | daq.SetSignal(1,1); | |
272 | ||
273 | twr_raw_data_file_t twr_file; | |
274 | Int_t year,runnum,evtnum; | |
275 | ||
276 | Int_t error; | |
277 | UInt_t nhead; | |
278 | ||
279 | GPS_t gps; | |
280 | UInt_t gpslow,gpshigh,gpssecs; // The GPS time information | |
281 | Int_t seconds,nsecs; // Seconds and nanoseconds since start of the UT year | |
282 | ||
283 | Int_t nevt=0; | |
284 | fHeader=0; | |
285 | for (Int_t ifile=0; ifile<ninfiles; ifile++) | |
286 | { | |
287 | TObjString* sx=(TObjString*)fInfiles->At(ifile); | |
288 | if (!sx) continue; | |
289 | ||
290 | inputfile=sx->GetString(); | |
291 | if (inputfile=="") continue; | |
292 | ||
293 | // Open the TWR raw data input file in binary mode | |
294 | fInput=fopen(inputfile.Data(),"rb"); | |
295 | ||
296 | if (!fInput) | |
297 | { | |
298 | cout << " *IceRawTWR Exec* No input file found with name : " << inputfile.Data() << endl; | |
299 | continue; | |
300 | } | |
301 | ||
302 | // Extract info like run number, file number etc... from filename | |
303 | extract_info_from_filename((char*)inputfile.Data(),&twr_file); | |
304 | ||
305 | year=twr_file.year; | |
306 | runnum=twr_file.run_no; | |
307 | ||
308 | // Initialise the event structure | |
309 | clear_event(&fEvent); | |
310 | ||
311 | // Read the file header information | |
312 | error=read_header_from_file(fInput,&fHeader,&nhead); | |
313 | ||
314 | if (error || !nhead) | |
315 | { | |
316 | cout << " *IceRawTWR Exec* Error in header for input file : " << inputfile.Data() << endl; | |
317 | continue; | |
318 | } | |
319 | ||
320 | // Correct the mapping | |
321 | update_system(fHeader,runnum); | |
322 | ||
323 | while (!read_event(fInput,fHeader,&fEvent)) | |
324 | { | |
325 | if (fMaxevt>-1 && nevt>=fMaxevt) break; | |
326 | ||
327 | evtnum=fEvent.eventcounter; | |
328 | ||
329 | // The GPS telegram info | |
330 | gps=fEvent.gps; | |
6280c0e2 | 331 | gpslow=gps.seconds & 0x00FFFFFF; // The low 24 bits of the seconds count |
332 | gpshigh=gps.info.bits.seconds; // The high 8 bits of the seconds count | |
0cfe76b5 | 333 | gpssecs=gpshigh<<24; |
334 | gpssecs+=gpslow; | |
335 | ||
336 | // Seconds and nanoseconds since the start of the UT year | |
337 | seconds=gpssecs; | |
338 | nsecs=100*gps.count_10MHz; | |
45bba4c4 | 339 | |
340 | // Correction for GPS telegram interpretation in the TWR Daq | |
341 | if (year<2007) seconds-=24*3600; | |
0cfe76b5 | 342 | |
343 | // Reset the complete Event structure | |
344 | evt->Reset(); | |
345 | ||
346 | evt->SetRunNumber(runnum); | |
347 | evt->SetEventNumber(evtnum); | |
348 | evt->SetUT(year,0,seconds,nsecs); | |
349 | ||
350 | evt->AddDevice(params); | |
351 | evt->AddDevice(daq); | |
352 | ||
353 | PutTrigger(year); | |
354 | ||
355 | PutWaveforms(year); | |
356 | ||
357 | // Invoke all available sub-tasks (if any) | |
358 | CleanTasks(); | |
359 | ExecuteTasks(opt); | |
360 | ||
361 | if (fPrintfreq) | |
362 | { | |
363 | if (!(nevt%fPrintfreq)) evt->HeaderData(); | |
364 | } | |
365 | ||
366 | // Write the complete structure to the output Tree | |
367 | if (otree) otree->Fill(); | |
368 | ||
369 | // Update event counter | |
370 | nevt++; | |
371 | ||
372 | // Reset the raw event structure | |
373 | clear_event(&fEvent); | |
374 | } // End of event reading loop | |
375 | ||
376 | // Delete the file header structure | |
377 | clear_system(fHeader); | |
378 | ||
379 | if (fMaxevt>-1 && nevt>=fMaxevt) break; | |
380 | ||
381 | } // End of input file loop | |
382 | ||
383 | // Flush possible memory resident data to the output file | |
384 | if (fOutfile) fOutfile->Write(); | |
385 | ||
386 | // Remove the IceEvent object from the environment | |
387 | // and delete it as well | |
388 | if (evt) | |
389 | { | |
390 | RemoveObject(evt); | |
391 | delete evt; | |
392 | } | |
393 | } | |
394 | /////////////////////////////////////////////////////////////////////////// | |
395 | void IceRawTWR::PutWaveforms(Int_t year) | |
396 | { | |
397 | // Get the waveform info from the raw data event into the IcePack structure. | |
398 | ||
399 | IceEvent* evt=(IceEvent*)GetMainObject(); | |
400 | if (!evt) return; | |
401 | ||
402 | // Loop over all the waveforms and add the histo(s) to the corresponding OM's | |
403 | TH1F histo; | |
404 | Int_t nbins=0; | |
405 | Float_t xlow=0; | |
406 | Float_t xup=0; | |
407 | TString hname; | |
408 | IceAOM om; | |
409 | IceAOM* omx=0; | |
45bba4c4 | 410 | Int_t twrid; |
0cfe76b5 | 411 | Int_t omid; |
412 | Int_t omidmax=680; | |
413 | Int_t error; | |
414 | Float_t baseline; | |
415 | for (Int_t i=0; i<N_OF_CHANNELS; i++) | |
416 | { | |
417 | if (!fEvent.wfm_filled[i]) continue; | |
418 | ||
45bba4c4 | 419 | twrid=fEvent.twr_id_of_om[i]; |
420 | if (!twrid) continue; | |
421 | ||
422 | omid=i+1; | |
0cfe76b5 | 423 | if (omid<=0 || omid>omidmax) continue; // Skip trigger channels |
424 | ||
425 | // Get corresponding device from the current event structure | |
426 | omx=(IceAOM*)evt->GetIdDevice(omid); | |
427 | if (!omx) | |
428 | { | |
429 | om.Reset(1); | |
430 | om.SetUniqueID(omid); | |
431 | evt->AddDevice(om); | |
432 | omx=(IceAOM*)evt->GetIdDevice(omid); | |
433 | } | |
434 | ||
435 | if (!omx) continue; | |
436 | ||
437 | clear_waveform_analysis(&fWform); | |
438 | error=restore_waveform(fEvent.wfm[i],&fWform,year); | |
439 | ||
440 | if (error) continue; | |
441 | ||
442 | baseline=fWform.frag_mean[0]; | |
443 | ||
444 | hname="BASELINE-WF"; | |
445 | hname+=omx->GetNwaveforms()+1; | |
446 | omx->AddNamedSlot(hname); | |
447 | omx->SetSignal(baseline,hname); | |
448 | ||
449 | // Fill the waveform histogram | |
450 | hname="OM"; | |
451 | hname+=omid; | |
452 | hname+="-WF"; | |
453 | hname+=omx->GetNwaveforms()+1; | |
454 | ||
455 | histo.Reset(); | |
456 | histo.SetName(hname.Data()); | |
457 | nbins=fWform.n_point; | |
458 | xlow=fWform.wfm_x[0]; | |
459 | xup=fWform.wfm_x[nbins-1]; | |
460 | histo.SetBins(nbins,xlow,xup); | |
461 | ||
462 | for (Int_t jbin=1; jbin<=nbins; jbin++) | |
463 | { | |
464 | histo.SetBinContent(jbin,baseline-fWform.wfm_y[jbin-1]); | |
465 | } | |
466 | ||
467 | omx->SetWaveform(&histo,omx->GetNwaveforms()+1); | |
468 | } | |
469 | } | |
470 | /////////////////////////////////////////////////////////////////////////// | |
471 | void IceRawTWR::PutTrigger(Int_t year) | |
472 | { | |
473 | // Get the trigger info from the raw data event into the IcePack structure. | |
474 | // Currently only the trigger settings for the years 2005 and 2006 have been | |
475 | // implemented. | |
476 | // In addition to the hardware and software triggers as encountered in the | |
477 | // raw data, an artificial "main" trigger has been introduced. | |
478 | // This artificial "main" trigger is just an "or" of the standard hard and soft | |
479 | // triggers (except calibration and random triggers) and serves only to | |
480 | // provide a generic "main" trigger a la Amanda mu-daq so that the default | |
481 | // "IceCleanHits" hit cleaning procedure will work correctly. | |
482 | // The trigger time for the artificial "main" trigger is taken to be the | |
483 | // time of the earliest hardware trigger pulse. In case there is no hardware | |
484 | // trigger pulse available, the "main" trigger time is set to 0. | |
485 | // For other years, only the artificial "main" trigger with a trigger time | |
486 | // set to 0 will be stored in the IceEvent structure. | |
487 | ||
488 | // Fill the trigger structure | |
489 | Int_t error=retrigger(&fEvent,&fTrigger); | |
490 | if (error) return; | |
491 | ||
492 | IceEvent* evt=(IceEvent*)GetMainObject(); | |
493 | if (!evt) return; | |
494 | ||
495 | AliDevice trig; | |
496 | trig.SetNameTitle("Trigger","Amanda/IceCube event triggers"); | |
497 | AliSignal s; | |
498 | Float_t trigtime=0; | |
499 | ||
500 | if (year !=2005 && year != 2006) | |
501 | { | |
502 | s.SetName("main"); | |
503 | s.SetUniqueID(0); | |
504 | s.SetSlotName("trig_pulse_le",1); | |
505 | s.SetSignal(trigtime,1); | |
506 | trig.AddHit(s); | |
507 | // Store the trigger data into the IceEvent structure | |
508 | evt->AddDevice(trig); | |
509 | return; | |
510 | } | |
511 | ||
512 | // Trigger settings for 2005 and 2006 | |
513 | if (!fTrigger.n_software_trigger && !fTrigger.n_hardware_trigger) return; | |
514 | ||
515 | TString trignames[N_OF_TRIGGERS]={"m24","m18","string","spase","cal-t0","cal-la","m12", | |
516 | "main-logic","main-or","random","m20-frag","volume"}; | |
517 | Int_t imain=0; | |
518 | for (Int_t i=0; i<N_OF_TRIGGERS; i++) | |
519 | { | |
520 | if (!fTrigger.trigger_active[i]) continue; | |
521 | ||
522 | s.Reset(1); | |
523 | s.SetName(trignames[i]); | |
524 | s.SetUniqueID(i); | |
525 | trigtime=0; | |
526 | if (fTrigger.trigger_has_pulse[i]) trigtime=fTrigger.trigger_time[i]; | |
527 | s.SetSlotName("trig_pulse_le",1); | |
528 | s.SetSignal(trigtime,1); | |
529 | trig.AddHit(s); | |
530 | // Set flag to indicate creation of artificial "main" trigger | |
531 | if (i!=4 && i!=5 && i!=9) imain=1; | |
532 | } | |
533 | ||
534 | // Set the artificial "main" trigger | |
535 | if (imain) | |
536 | { | |
537 | s.Reset(1); | |
538 | s.SetName("main"); | |
539 | s.SetUniqueID(N_OF_TRIGGERS); | |
540 | s.SetSlotName("trig_pulse_le",1); | |
541 | trigtime=0; | |
542 | if (fTrigger.first_trigger>=0) trigtime=fTrigger.first_trigger_time; | |
543 | s.SetSignal(trigtime,1); | |
544 | trig.AddHit(s); | |
545 | } | |
546 | ||
547 | // Store the trigger data into the IceEvent structure | |
548 | evt->AddDevice(trig); | |
549 | } | |
550 | /////////////////////////////////////////////////////////////////////////// | |
551 | Int_t IceRawTWR::extract_info_from_filename(char* fname,twr_raw_data_file_t* twr_file) | |
552 | { | |
553 | char start_str[20],year_str[20],day_str[20],run_no_str[20], | |
554 | file_no_str[20],begin_str[20],end_str[20]; | |
555 | char* filename; | |
556 | ||
557 | filename = strstr(fname, "twr"); | |
558 | if(filename == NULL) | |
559 | if(strncmp("twr_", start_str, 4)) | |
560 | { | |
561 | printf("%s\n", filename); | |
562 | return(ERROR_NOT_VALID_FILENAME); | |
563 | } | |
564 | ||
565 | strncpy(start_str, filename, 4); | |
566 | if(strncmp("twr_", start_str, 4)) | |
567 | { | |
568 | printf("%s %s\n", filename, start_str); | |
569 | return(ERROR_NOT_VALID_FILENAME); | |
570 | } | |
571 | strncpy(year_str, &filename[4], 4); | |
572 | twr_file->year = strtol(year_str, 0, 10); | |
573 | ||
574 | if(twr_file->year==2003) | |
575 | { | |
576 | strncpy(day_str, &filename[9], 3); | |
577 | day_str[3] = '\0'; | |
578 | twr_file->day = strtol(day_str, 0, 10); | |
579 | ||
580 | strncpy(run_no_str, &filename[13], 4); | |
581 | run_no_str[4] = '\0'; | |
582 | twr_file->run_no = strtol(run_no_str, 0, 10); | |
583 | ||
584 | strncpy(file_no_str, &filename[18], 4); | |
585 | file_no_str[4] = '\0'; | |
586 | twr_file->file_no = strtol(file_no_str, 0, 10); | |
587 | } | |
588 | ||
589 | if(twr_file->year==2004) | |
590 | { | |
591 | strncpy(day_str, &filename[9], 3); | |
592 | day_str[3] = '\0'; | |
593 | twr_file->day = strtol(day_str, 0, 10); | |
594 | ||
595 | strncpy(run_no_str, &filename[13], 4); | |
596 | run_no_str[4] = '\0'; | |
597 | twr_file->run_no = strtol(run_no_str, 0, 10); | |
598 | ||
599 | strncpy(file_no_str, &filename[18], 4); | |
600 | file_no_str[4] = '\0'; | |
601 | twr_file->file_no = strtol(file_no_str, 0, 10); | |
602 | ||
603 | strncpy(begin_str, &filename[23], 5); | |
604 | begin_str[5] = '\0'; | |
605 | twr_file->begin = strtol(begin_str, 0, 10); | |
606 | ||
607 | strncpy(end_str, &filename[29], 5); | |
608 | end_str[5] = '\0'; | |
609 | twr_file->end = strtol(end_str, 0, 10); | |
610 | } | |
611 | ||
612 | if(twr_file->year > 2004) | |
613 | { | |
614 | strncpy(day_str, &filename[9], 3); | |
615 | day_str[3] = '\0'; | |
616 | twr_file->day = strtol(day_str, 0, 10); | |
617 | ||
618 | strncpy(run_no_str, &filename[13], 6); | |
619 | run_no_str[6] = '\0'; | |
620 | twr_file->run_no = strtol(run_no_str, 0, 10); | |
621 | ||
622 | strncpy(file_no_str, &filename[20], 4); | |
623 | file_no_str[4] = '\0'; | |
624 | twr_file->file_no = strtol(file_no_str, 0, 10); | |
625 | ||
626 | strncpy(begin_str, &filename[25], 5); | |
627 | begin_str[5] = '\0'; | |
628 | twr_file->begin = strtol(begin_str, 0, 10); | |
629 | ||
630 | strncpy(end_str, &filename[31], 5); | |
631 | end_str[5] = '\0'; | |
632 | twr_file->end = strtol(end_str, 0, 10); | |
633 | } | |
634 | return(0); | |
635 | } | |
636 | /////////////////////////////////////////////////////////////////////////// | |
637 | Int_t IceRawTWR::clear_system(sys_config_t* sys) | |
638 | { | |
639 | // Deletion of the file header structure. | |
640 | ||
641 | if (!sys) return 0; | |
642 | ||
f9556244 | 643 | for(Int_t icrate=0; icrate < int(sys->n_crates); icrate++) |
0cfe76b5 | 644 | { |
645 | if (!sys->crate[icrate]) continue; | |
f9556244 | 646 | for(Int_t itwr=0; itwr < int(sys->crate[icrate]->n_twr); itwr++) |
0cfe76b5 | 647 | { |
648 | if (sys->crate[icrate]->twr[itwr]) delete sys->crate[icrate]->twr[itwr]; | |
649 | } | |
650 | delete sys->crate[icrate]; | |
651 | } | |
652 | delete sys; | |
653 | sys=0; | |
654 | return 0; | |
655 | } | |
656 | /////////////////////////////////////////////////////////////////////////// | |
657 | Int_t IceRawTWR::clear_event(event_t* event_ptr) | |
658 | { | |
659 | Int_t i_value; | |
660 | Int_t *int_ptr = (int*) event_ptr; | |
661 | ||
f9556244 | 662 | for(i_value=0; i_value < int(sizeof(event_t)/sizeof(Int_t)); i_value++) |
0cfe76b5 | 663 | { |
664 | *int_ptr++ = 0; | |
665 | } | |
666 | return(0); | |
667 | } | |
668 | /////////////////////////////////////////////////////////////////////////// | |
669 | Int_t IceRawTWR::read_header_from_file(FILE* fin,sys_config_t** system_ptr,UInt_t* header_length) | |
670 | { | |
671 | Int_t i_crate, i_twr, i_channel; | |
672 | UInt_t count_twr_in_system = 0; | |
0cfe76b5 | 673 | UInt_t dummy; |
674 | ||
675 | sys_config_t *sys; | |
676 | ||
677 | // allocating memory for sys_config structure | |
678 | sys = (sys_config_t*) malloc( sizeof(sys_config_t) ); | |
679 | ||
680 | fread(&dummy,sizeof(UInt_t),1,fin); // Header Begin Mark | |
681 | ||
682 | fread(header_length,sizeof(UInt_t),1,fin); // Length of header | |
683 | fread(&sys->clockdiv,sizeof(UInt_t),1,fin); | |
684 | fread(&sys->n_crates,sizeof(UInt_t),1,fin); | |
685 | ||
686 | if( (sys->n_crates > MAX_N_CRATES) || (sys->n_crates < 0) ) | |
687 | return(ERROR_TOO_MANY_CRATES); | |
688 | ||
f9556244 | 689 | for(i_crate=0; i_crate < int(sys->n_crates); i_crate++) |
0cfe76b5 | 690 | { |
691 | sys->crate[i_crate] = | |
692 | (crate_config_t*) malloc( sizeof(crate_config_t) ); | |
693 | ||
694 | fread(&sys->crate[i_crate]->vme_base_bridge,sizeof(UInt_t),1,fin); | |
695 | fread(&sys->crate[i_crate]->vme_base_100MHz,sizeof(UInt_t),1,fin); | |
696 | fread(&sys->crate[i_crate]->base_gps,sizeof(UInt_t),1,fin); | |
697 | fread(&sys->crate[i_crate]->n_twr,sizeof(UInt_t),1,fin); | |
698 | ||
699 | if( (sys->crate[i_crate]->n_twr > MAX_N_TWR_PER_CRATE) | |
700 | || (sys->crate[i_crate]->n_twr < 0) ) | |
701 | return(ERROR_TOO_MANY_TWRS); | |
702 | ||
f9556244 | 703 | for(i_twr=0; i_twr < int(sys->crate[i_crate]->n_twr); i_twr++) |
0cfe76b5 | 704 | { |
705 | sys->crate[i_crate]->twr[i_twr] = | |
706 | (twr_config_t*) malloc( sizeof(twr_config_t) ); | |
707 | count_twr_in_system++; | |
708 | fread(&sys->crate[i_crate]->twr[i_twr]->base, | |
709 | sizeof(UInt_t),1,fin); | |
710 | fread(&sys->crate[i_crate]->twr[i_twr]->id, | |
711 | sizeof(UInt_t),1,fin); | |
712 | ||
713 | sys->crate[i_crate]->twr[i_twr]->id | |
714 | = sys->crate[i_crate]->twr[i_twr]->id - 0x10; /* Correct */ | |
715 | ||
716 | ||
717 | fread(&dummy,sizeof(UInt_t),1,fin); /* stat_reg */ | |
718 | fread(&sys->crate[i_crate]->twr[i_twr]->mod_id, | |
719 | sizeof(UInt_t),1,fin); | |
720 | fread(&dummy,sizeof(UInt_t),1,fin); /* acq_ctrl */ | |
721 | fread(&sys->crate[i_crate]->twr[i_twr]->ext_start, | |
722 | sizeof(UInt_t),1,fin); | |
723 | fread(&sys->crate[i_crate]->twr[i_twr]->ext_stop, | |
724 | sizeof(UInt_t),1,fin); | |
725 | fread(&dummy,sizeof(UInt_t),1,fin); /* evtconfig */ | |
726 | ||
727 | for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++) | |
728 | { | |
729 | fread(&sys->crate[i_crate]->twr[i_twr]->om_no[i_channel], | |
730 | sizeof(UInt_t),1,fin); | |
731 | } | |
732 | ||
733 | for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++) | |
734 | { | |
735 | fread(&sys->crate[i_crate]->twr[i_twr]->om_is_optical[i_channel], | |
736 | sizeof(UInt_t),1,fin); | |
737 | } | |
738 | ||
739 | for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++) | |
740 | { | |
741 | fread(&sys->crate[i_crate]->twr[i_twr]->baseline[i_channel], | |
742 | sizeof(UInt_t),1,fin); | |
743 | } | |
744 | ||
745 | for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++) | |
746 | { | |
747 | fread(&sys->crate[i_crate]->twr[i_twr]->threshold[i_channel], | |
748 | sizeof(UInt_t),1,fin); | |
749 | } | |
750 | ||
751 | sys->twr_field[(i_crate * 0x10) + i_twr] | |
752 | = sys->crate[i_crate]->twr[i_twr]; | |
753 | ||
754 | /* Bug fix needed */ | |
755 | for(i_channel=0; i_channel < 8; i_channel++) | |
756 | { | |
757 | if( sys->crate[i_crate]->twr[i_twr]->om_no[i_channel] == 9000 ) | |
758 | sys->crate[i_crate]->twr[i_twr]->om_no[i_channel] | |
759 | = N_OF_CHANNELS - 1; | |
760 | } | |
761 | } | |
762 | } | |
763 | ||
764 | // Set number of TWRs in system | |
765 | sys->n_twr = count_twr_in_system; | |
766 | ||
767 | *system_ptr = sys; | |
768 | return(0); | |
769 | } | |
770 | /////////////////////////////////////////////////////////////////////////// | |
771 | Int_t IceRawTWR::update_system(sys_config_t* sys,Int_t run_number) | |
772 | { | |
773 | Int_t i_crate, i_twr, i_channel; | |
774 | ||
0cfe76b5 | 775 | /* Data for bug fix 1 */ |
0cfe76b5 | 776 | UInt_t om_no_r1[CHANNELS_PER_TWR] |
777 | = {111, 112, 113, 114, 115, 116, 39, 118}; | |
778 | UInt_t om_is_optical_r1[CHANNELS_PER_TWR] | |
779 | = {0, 0, 0, 0, 0, 0, 0, 0}; | |
780 | UInt_t threshold_r1[CHANNELS_PER_TWR] | |
781 | = {50, 50, 50, 50, 50, 50, 80, 50}; | |
782 | ||
0cfe76b5 | 783 | UInt_t om_no_r2[CHANNELS_PER_TWR] |
784 | = {473, 484, 485, 486, 487, 475, 490, 491}; | |
785 | UInt_t om_is_optical_r2[CHANNELS_PER_TWR] | |
786 | = {1, 1, 1, 1, 1, 1, 1, 1}; | |
787 | UInt_t threshold_r2[CHANNELS_PER_TWR] | |
788 | = {15, 50, 55, 40, 15, 23, 15, 15}; | |
789 | ||
790 | ||
791 | /* Bugfix 1 Andreas Bug */ | |
792 | ||
793 | /* | |
794 | By accident this TWR was counted twice in TWR.cnf | |
795 | as Crate 0 TWR 7 and Crate 4 TWR 7 | |
796 | from run up to run | |
797 | TWR_OM 639 642 1 9 10 11 12 30 | |
798 | OPTICAL 0 0 0 0 0 0 0 0 | |
799 | TWR_BASELINE 110 120 110 140 150 160 170 180 | |
800 | TWR_THRESHOLD 50 50 80 80 80 80 80 80 | |
801 | ||
802 | Crate 4 TWR 7 should be replaced with this TWR | |
803 | TWR_OM 111 112 113 114 115 116 39 118 | |
804 | OPTICAL 0 0 0 0 0 0 0 0 | |
805 | TWR_BASELINE 110 120 130 140 150 160 170 180 | |
806 | TWR_THRESHOLD 50 50 50 50 50 50 80 50 | |
807 | */ | |
808 | ||
809 | if( | |
810 | (run_number >= 9153 ) /* Begin season 2005 13.2.05 */ | |
811 | && (run_number < 9800) /* Timo corrected TWR.cnf on after run ??? */ | |
812 | /* Need to find exact date */ | |
813 | ) | |
814 | { | |
815 | i_crate = 4; | |
816 | i_twr = 7; | |
817 | for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++) | |
818 | { | |
819 | sys->crate[i_crate]->twr[i_twr]->om_no[i_channel] | |
820 | = om_no_r1[i_channel]; | |
821 | sys->crate[i_crate]->twr[i_twr]->om_is_optical[i_channel] | |
822 | = om_is_optical_r1[i_channel]; | |
823 | sys->crate[i_crate]->twr[i_twr]->threshold[i_channel] | |
824 | = threshold_r1[i_channel]; | |
825 | } | |
826 | } | |
827 | ||
828 | /* Bugfix 2 Timos Bug */ | |
829 | ||
830 | /* | |
831 | By accident this TWR was counted twice in TWR.cnf | |
832 | as Crate 0 TWR 1 and Crate 5 TWR b | |
833 | from run 9153 up to run 9188 | |
834 | ||
835 | TWR_OM 492 493 495 496 497 499 500 501 | |
836 | OPTICAL 1 1 1 1 1 1 1 1 | |
837 | TWR_BASELINE 110 120 130 140 150 160 170 180 | |
838 | TWR_THRESHOLD 16 45 25 42 35 46 15 15 | |
839 | ||
840 | Crate 5 TWR b should be corrected to | |
841 | TWR_OM 473 484 485 486 487 475 490 491 | |
842 | OPTICAL 1 1 1 1 1 1 1 1 | |
843 | TWR_BASELINE 4000 120 130 140 150 4000 170 180 | |
844 | TWR_THRESHOLD 15 50 55 40 15 23 15 15 | |
845 | */ | |
846 | ||
847 | if( | |
848 | (run_number >= 9153 ) /* Begin season 2005 = Feb 2nd 05 */ | |
849 | && (run_number < 9189) /* Timo corrected TWR.cnf on */ | |
850 | /* Mar 15th 05 = day 74 after run 9188 */ | |
851 | ) | |
852 | { | |
853 | i_crate = 5; | |
854 | i_twr = 0xb; | |
855 | for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++) | |
856 | { | |
857 | sys->crate[i_crate]->twr[i_twr]->om_no[i_channel] | |
858 | = om_no_r2[i_channel]; | |
859 | sys->crate[i_crate]->twr[i_twr]->om_is_optical[i_channel] = | |
860 | om_is_optical_r2[i_channel]; | |
861 | sys->crate[i_crate]->twr[i_twr]->threshold[i_channel] = | |
862 | threshold_r2[i_channel]; | |
863 | } | |
864 | } | |
865 | return(0); | |
866 | } | |
867 | /////////////////////////////////////////////////////////////////////////// | |
868 | Int_t IceRawTWR::read_event(FILE* fin,sys_config_t* sys,event_t* event_ptr) | |
869 | { | |
f9556244 | 870 | Int_t i_wfm; |
871 | UInt_t length_of_event_block; | |
0cfe76b5 | 872 | |
873 | Int_t n_twr, n_of_waveforms_in_event, read_number; | |
874 | UInt_t length_wfm[CHANNELS_PER_TWR]; | |
875 | UInt_t dummy, channel_no, om_no, twr_no; | |
876 | ||
877 | // Reset waveform filled register | |
878 | memset(&event_ptr->wfm_filled[0], 0, sizeof(UInt_t) * N_OF_CHANNELS); | |
879 | ||
880 | if( !fread(&dummy,sizeof(UInt_t),1,fin) ) return(1); | |
881 | ||
882 | if(dummy != 0xbbbbbbbb) | |
883 | { | |
884 | printf("Wrong event begin mark %x\n", dummy); | |
885 | while( (dummy !=0xbbbbbbbb) | |
886 | && (fread(&dummy,sizeof(UInt_t),1,fin) != 0) ) | |
887 | {;//printf("dummy:%x\n", dummy); | |
888 | } | |
889 | } | |
890 | if( !fread(&length_of_event_block,sizeof(UInt_t),1,fin) ) return(1); | |
891 | if( !fread(&event_ptr->eventcounter,sizeof(UInt_t),1,fin) ) return(1); | |
892 | if( !fread(&event_ptr->which_trigger,sizeof(UInt_t),1,fin) ) return(1); | |
893 | if( !fread(&event_ptr->gps,sizeof(GPS_t),1,fin) ) return(1); | |
894 | ||
895 | // --reading waveforms from TWR blocks | |
896 | n_twr = 0; | |
f9556244 | 897 | while(n_twr < int(sys->n_twr)) |
0cfe76b5 | 898 | { |
899 | // --read TWR header | |
900 | if( !fread(&dummy,sizeof(UInt_t),1,fin) ) return(1); | |
901 | if(dummy != 0xffffffff) | |
902 | {printf("Wrong twr begin mark %x\n", dummy); return(2);} | |
903 | if( !fread(&twr_no,sizeof(UInt_t),1,fin) ) return(1); | |
904 | ||
905 | // nur voruebergehend !! | |
906 | twr_no -= 0x10; | |
907 | ||
908 | if( !fread(&event_ptr->twr[twr_no].timestamp,sizeof(UInt_t),1,fin) ) | |
909 | return(1); | |
910 | if( !fread(&n_of_waveforms_in_event,sizeof(UInt_t),1,fin) ) | |
911 | return(1); | |
912 | event_ptr->twr[twr_no].n_wfm = n_of_waveforms_in_event; | |
913 | ||
914 | for(i_wfm=0; i_wfm < n_of_waveforms_in_event; i_wfm++) | |
915 | { | |
916 | if( !fread(&length_wfm[i_wfm],sizeof(UInt_t),1,fin) ) return(1); | |
917 | } | |
918 | ||
919 | // read waveforms | |
920 | for(i_wfm=0; i_wfm < n_of_waveforms_in_event; i_wfm++) | |
921 | { | |
922 | if(length_wfm[i_wfm] != 0) | |
923 | { | |
924 | if( !fread(&channel_no,sizeof(UInt_t),1,fin) ) return(1); | |
925 | if(sys->twr_field[twr_no]->om_no[channel_no] | |
926 | < N_OF_CHANNELS) | |
927 | om_no = sys->twr_field[twr_no]->om_no[channel_no]; | |
928 | else | |
929 | om_no = N_OF_CHANNELS-1; | |
930 | ||
931 | /* Fix needed */ | |
932 | ||
933 | event_ptr->twr_id_of_om[om_no] = twr_no; | |
934 | ||
935 | read_number = fread(&event_ptr->wfm[om_no], | |
936 | length_wfm[i_wfm]-sizeof(UInt_t),1,fin); | |
937 | event_ptr->wfm_filled[om_no] = 1; | |
938 | if( !read_number ) return(1); | |
939 | ||
940 | // read_number correction for usage of fread() instead of read() | |
941 | read_number*=length_wfm[i_wfm]-sizeof(UInt_t); | |
942 | ||
f9556244 | 943 | if( read_number != int(length_wfm[i_wfm]-sizeof(UInt_t)) ) |
0cfe76b5 | 944 | { |
945 | cout << " read_number : " << read_number | |
946 | << " length_wfm["<<i_wfm<<"] : " << length_wfm[i_wfm] | |
947 | << " sizeof(UInt_t) : " << sizeof(UInt_t) << endl; | |
948 | return(2); | |
949 | } | |
950 | } | |
951 | } | |
952 | n_twr++; | |
953 | } // end while n_twr | |
954 | return(0); | |
955 | } | |
956 | /////////////////////////////////////////////////////////////////////////// | |
957 | Int_t IceRawTWR::retrigger(event_t* ev,trigger_hits_t* trig) | |
958 | { | |
959 | // Returns the active trigger(s) | |
960 | ||
961 | // Initialise the trigger_hits_t structure with zeroes | |
962 | memset(trig, 0, sizeof(trigger_hits_t) ); | |
963 | ||
964 | // Obtain the software trigger info | |
965 | trig->n_software_trigger=0; | |
966 | for(Int_t itrigger=0; itrigger<N_OF_TRIGGERS; itrigger++) | |
967 | { | |
968 | if(ev->which_trigger & trigger_bits[itrigger]) | |
969 | { | |
970 | //printf("SetTrigger %i\n", i_trigger); | |
971 | trig->trigger_active[itrigger]=1; | |
972 | trig->n_software_trigger++; | |
973 | } | |
974 | else | |
975 | { | |
976 | trig->trigger_active[itrigger]=0; | |
977 | } | |
978 | } | |
979 | ||
980 | // Obtain the hardware trigger info | |
981 | trig->n_hardware_trigger=0; | |
982 | trig->first_trigger_time=10000000; | |
983 | trig->first_trigger=-1; | |
984 | ||
985 | for(Int_t jtrigger=0; jtrigger<N_OF_TRIGGERS; jtrigger++) | |
986 | { | |
987 | if(!trigger_channel[jtrigger]) continue; | |
988 | ||
989 | if(ev->wfm_filled[trigger_channel[jtrigger]]) | |
990 | { | |
991 | trig->trigger_active[jtrigger]=1; | |
992 | trig->trigger_time[jtrigger]=(ev->wfm[trigger_channel[jtrigger]].value[2] & 0xfff); | |
993 | trig->trigger_has_pulse[jtrigger]=1; | |
994 | if (trig->trigger_time[jtrigger] < trig->first_trigger_time) | |
995 | { | |
996 | trig->first_trigger_time=trig->trigger_time[jtrigger]; | |
997 | trig->first_trigger=jtrigger; | |
998 | } | |
999 | trig->n_hardware_trigger++; | |
1000 | } | |
1001 | } | |
1002 | return 0; | |
1003 | } | |
1004 | /////////////////////////////////////////////////////////////////////////// | |
1005 | Int_t IceRawTWR::clear_waveform_analysis(waveform_analyse_t* wfm_om) | |
1006 | { | |
1007 | Int_t i_value, i_frag, i_edge, i_peak; | |
1008 | ||
1009 | if(wfm_om == 0) return(1); | |
1010 | ||
1011 | // output from analysis | |
1012 | wfm_om->n_frag = 0; | |
1013 | for(i_frag=0; i_frag < MAX_N_OF_FRAGS; i_frag++) | |
1014 | { | |
1015 | wfm_om->frag_n_points[i_frag] = 0; | |
1016 | wfm_om->frag_begin[i_frag] = 0; | |
1017 | wfm_om->frag_end[i_frag] = 0; | |
1018 | wfm_om->frag_mean[i_frag] = 0; | |
1019 | wfm_om->frag_begin_time[i_frag] = 0; | |
1020 | } | |
1021 | ||
1022 | wfm_om->n_peak = 0; | |
1023 | for(i_peak=0; i_peak < MAX_N_OF_PEAKS; i_peak++) | |
1024 | { | |
1025 | wfm_om->peak_begin[i_peak] = 0; | |
1026 | wfm_om->peak_end[i_peak] = 0; | |
1027 | wfm_om->peak_max[i_peak] = 0; | |
1028 | wfm_om->peak_TDC_edge[i_peak] = 0; | |
1029 | wfm_om->peak_local_minimum[i_peak] = 0; | |
1030 | wfm_om->crosstalk_charge_n_value[i_peak] = 0; | |
1031 | wfm_om->peak_in_fragment[i_peak] = 0; | |
1032 | ||
1033 | wfm_om->peak_mean[i_peak] = 0.0; | |
1034 | ||
1035 | wfm_om->peak_m[i_peak] = 0.0; | |
1036 | wfm_om->peak_b[i_peak] = 0.0; | |
1037 | wfm_om->peak_t0[i_peak] = 0.0; | |
1038 | wfm_om->peak_begin_time[i_peak] = 0.0; | |
1039 | wfm_om->peak_charge[i_peak] = 0.0; | |
1040 | wfm_om->peak_height[i_peak] = 0.0; | |
1041 | wfm_om->fitted_amplitude[i_peak] = 0.0; | |
1042 | wfm_om->fitted_TOT[i_peak] = 0.0; | |
1043 | wfm_om->crosstalk_charge[i_peak] = 0.0; | |
1044 | wfm_om->crosstalk_slope[i_peak] = 0.0; | |
1045 | } | |
1046 | ||
1047 | wfm_om->n_point = 0; | |
1048 | wfm_om->wfm_min = 4095; | |
1049 | wfm_om->wfm_max = 0; | |
1050 | wfm_om->b_out_of_range = 0; | |
1051 | ||
1052 | for(i_value=0; i_value < 1024; i_value++) | |
1053 | { | |
1054 | wfm_om->wfm_x[i_value] = 0; | |
1055 | wfm_om->wfm_y[i_value] = 0; | |
1056 | } | |
1057 | ||
1058 | wfm_om->n_tdc_edges = 0; | |
1059 | for(i_edge=0; i_edge < MAX_N_OF_TDC_EDGES; i_edge++) | |
1060 | { | |
1061 | wfm_om->leading_edge[i_edge] = 0.0; | |
1062 | wfm_om->falling_edge[i_edge] = 0.0; | |
1063 | wfm_om->identified_twr_hit[i_edge] = -1; | |
1064 | } | |
1065 | ||
1066 | return(0); | |
1067 | } | |
1068 | /////////////////////////////////////////////////////////////////////////// | |
1069 | Int_t IceRawTWR::restore_waveform(waveform_t f_wfm,waveform_analyse_t* wfm_om,Int_t year) | |
1070 | { | |
1071 | UShort_t wfm_length, mean; | |
1072 | static UShort_t tmp_wf[2000]; | |
1073 | ||
1074 | Int_t debug = 0; | |
1075 | Int_t fragment_start = 0; | |
1076 | Int_t frag_count = 0; // position in current fragment | |
1077 | Int_t n_position = 0; // position in displayed waveform | |
1078 | UInt_t n_word = 2; // position in featured waveform | |
1079 | Int_t n_fragment = 0; // actual fragment | |
1080 | Int_t b_wrong_value = 0; | |
1081 | ||
1082 | UShort_t assumed_frag_begin, last_value; /* bug in eventbuilder */ | |
1083 | ||
1084 | wfm_om->wfm_min = 4095.0; | |
1085 | wfm_om->wfm_max = 0.0; | |
1086 | ||
1087 | if( (f_wfm.value[0] & 0xf000) != 0xf000 ) return(1); | |
1088 | wfm_length = (f_wfm.value[0] & 0xfff)/2; | |
1089 | ||
1090 | mean = f_wfm.value[1] + BASELINE_MEAN_MAGIC; | |
1091 | while( ((f_wfm.value[n_word] & 0xf000) == 0x4000) && | |
1092 | (n_word < wfm_length) && | |
1093 | (n_fragment < MAX_N_OF_FRAGS) ) | |
1094 | { | |
1095 | fragment_start = f_wfm.value[n_word] & 0xfff; | |
1096 | n_word++; | |
1097 | wfm_om->frag_begin_time[n_fragment] | |
1098 | = fragment_start * NSECS_PER_TWR_BIN; | |
1099 | wfm_om->frag_begin[n_fragment] = n_position; | |
1100 | wfm_om->frag_mean[n_fragment] = mean; | |
1101 | ||
1102 | b_wrong_value = 0; | |
1103 | frag_count = 0; | |
1104 | ||
1105 | while( ((f_wfm.value[n_word] & 0xf000) != 0x2000) && | |
1106 | ((f_wfm.value[n_word] & 0xf000) != 0x4000) &&/*Reconstructable*/ | |
1107 | !b_wrong_value && /* Buggy */ | |
1108 | (n_word < wfm_length) ) | |
1109 | { | |
1110 | if(year > 2004) | |
1111 | { | |
1112 | /* 2005 2006 data */ | |
1113 | if(frag_count == 0) | |
1114 | { | |
1115 | tmp_wf[n_word] = f_wfm.value[n_word] + mean; | |
1116 | wfm_om->wfm_y[n_position] = (float) tmp_wf[n_word]; | |
1117 | wfm_om->wfm_x[n_position] = (float) | |
1118 | wfm_om->frag_begin_time[n_fragment] | |
1119 | + (frag_count * NSECS_PER_TWR_BIN); | |
1120 | } | |
1121 | else if(frag_count == 1) | |
1122 | { | |
1123 | tmp_wf[n_word] = f_wfm.value[n_word] + tmp_wf[n_word-1]; | |
1124 | wfm_om->wfm_y[n_position] = (float) tmp_wf[n_word]; | |
1125 | wfm_om->wfm_x[n_position] = (float) | |
1126 | wfm_om->frag_begin_time[n_fragment] | |
1127 | + (frag_count * NSECS_PER_TWR_BIN); | |
1128 | } | |
1129 | else | |
1130 | { | |
1131 | tmp_wf[n_word] = | |
1132 | 2*tmp_wf[n_word-1] + f_wfm.value[n_word]; | |
1133 | tmp_wf[n_word] -= tmp_wf[n_word-2]; | |
1134 | ||
1135 | wfm_om->wfm_y[n_position] = (float) tmp_wf[n_word]; | |
1136 | wfm_om->wfm_x[n_position] = (float) | |
1137 | wfm_om->frag_begin_time[n_fragment] | |
1138 | + (frag_count * NSECS_PER_TWR_BIN); | |
1139 | } | |
1140 | ||
1141 | ||
1142 | /* | |
1143 | Hack for wrongly merged overlapping fragments | |
1144 | */ | |
1145 | if(tmp_wf[n_word] > 0x1fff) | |
1146 | { | |
1147 | /* BUG FIXXXX */ | |
1148 | /* assume that fragment merge in eventbuilder caused */ | |
1149 | /* problem two fragments overlap in EXACTLY ONE point */ | |
1150 | /* and are merged first point of the added part of */ | |
1151 | /* the fragment is encoded using the former fragment */ | |
1152 | /* start as a data point */ | |
1153 | ||
1154 | last_value = tmp_wf[n_word-1]; | |
1155 | assumed_frag_begin = 0x4000 + fragment_start + frag_count; | |
1156 | tmp_wf[n_word] = f_wfm.value[n_word] + 2 * last_value; | |
1157 | tmp_wf[n_word] -= assumed_frag_begin; | |
1158 | wfm_om->wfm_y[n_position] = (float) tmp_wf[n_word]; | |
1159 | ||
1160 | /* Look if value is still buggy */ | |
1161 | if(tmp_wf[n_word] > 0x1fff) b_wrong_value = 1; | |
1162 | ||
1163 | debug = ERROR_MISS_FRAG_STOP; | |
1164 | } | |
1165 | } /* end year >= 2005 */ | |
1166 | else | |
1167 | { | |
1168 | /* 2003 2004 data */ | |
1169 | wfm_om->wfm_y[n_position] = (float) f_wfm.value[n_word]; | |
1170 | wfm_om->wfm_x[n_position] = (float) | |
1171 | wfm_om->frag_begin_time[n_fragment] | |
1172 | + (frag_count * NSECS_PER_TWR_BIN); | |
1173 | } /* end year 2003 2004 */ | |
1174 | ||
1175 | /* Set min and max Y */ | |
1176 | ||
1177 | if(wfm_om->wfm_y[n_position] > wfm_om->wfm_max) | |
1178 | wfm_om->wfm_max = wfm_om->wfm_y[n_position]; | |
1179 | if(wfm_om->wfm_y[n_position] < wfm_om->wfm_min) | |
1180 | wfm_om->wfm_min = wfm_om->wfm_y[n_position]; | |
1181 | ||
1182 | n_position++; | |
1183 | n_word++; | |
1184 | frag_count++; | |
1185 | } | |
1186 | ||
1187 | if((f_wfm.value[n_word] & 0xf000) == 0x2000) /* Normal wavf */ | |
1188 | { | |
1189 | ||
1190 | wfm_om->frag_end[n_fragment] = n_position - 1; | |
1191 | wfm_om->frag_n_points[n_fragment] = | |
1192 | wfm_om->frag_end[n_fragment] | |
1193 | - wfm_om->frag_begin[n_fragment] + 1; | |
1194 | wfm_om->n_point += wfm_om->frag_n_points[n_fragment]; | |
1195 | n_word++; | |
1196 | } | |
1197 | else | |
1198 | return(ERROR_CORRUPTED_WF); | |
1199 | ||
1200 | n_fragment++; | |
1201 | } /* end while fragment */ | |
1202 | ||
1203 | ||
1204 | wfm_om->n_frag = n_fragment; | |
1205 | if( !(n_word & 0x1) ) n_word++; | |
1206 | ||
1207 | if(n_fragment >= MAX_N_OF_FRAGS) return(ERROR_MAX_N_FRAGMENTS_EXCEEDED); | |
1208 | ||
1209 | ||
1210 | // Hack to get rid of last value of waveform always set to 0 | |
1211 | if (wfm_om->wfm_y[wfm_om->n_point] == 0.0) | |
1212 | { | |
1213 | // erase last point of waveform | |
1214 | wfm_om->n_point--; | |
1215 | ||
1216 | // Shorten last pulse if necessary | |
1217 | // if( wfm_om.peak_end[wfm_om.n_peak-1] | |
1218 | // == wfm_om.frag_end[wfm_om.n_frag-1] ) | |
1219 | // wfm_om.peak_end[wfm_om.n_peak-1]--; | |
1220 | ||
1221 | // Shorten last fragment | |
1222 | wfm_om->frag_n_points[wfm_om->n_frag-1]--; | |
1223 | wfm_om->frag_end[wfm_om->n_frag-1]--; | |
1224 | ||
1225 | wfm_om->wfm_min = 4095.0; | |
1226 | wfm_om->wfm_max = 0.0; | |
1227 | for (Int_t i_value=0; i_value < wfm_om->n_point; i_value++) | |
1228 | { | |
1229 | if (wfm_om->wfm_y[i_value] > wfm_om->wfm_max) wfm_om->wfm_max=wfm_om->wfm_y[i_value]; | |
1230 | if (wfm_om->wfm_y[i_value] < wfm_om->wfm_min) wfm_om->wfm_min=wfm_om->wfm_y[i_value]; | |
1231 | } | |
1232 | } | |
1233 | ||
1234 | return(debug); | |
1235 | } | |
1236 | /////////////////////////////////////////////////////////////////////////// |