1 /*******************************************************************************
2 * Copyright(c) 2003, IceCube Experiment at the South Pole. All rights reserved.
4 * Author: The IceCube RALICE-based Offline Project.
5 * Contributors are mentioned in the code where appropriate.
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 *******************************************************************************/
18 ///////////////////////////////////////////////////////////////////////////
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.
47 // gSystem->Load("ralice");
48 // gSystem->Load("icepack");
49 // gSystem->Load("iceconvert");
51 // IceRawTWR q("IceRawTWR","TWR raw data to IcePack data structure conversion");
53 // // Limit the number of entries for testing
54 // q.SetMaxEvents(10);
56 // // Print frequency to produce a short summary print every printfreq events
59 // // The TWR raw data input filename(s)
60 // q.AddInputFile("twr_2005_101_009225_0983_57784_57850.dat.twr.to_tape_1");
62 // // Output file for the event structures
63 // q.SetOutputFile("events.root");
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
72 // // MyXtalk task1("task1","Cross talk correction");
73 // // MyClean task2("task2","Hit cleaning");
77 // // The sub-tasks will be executed in the order as they are entered.
78 // ///////////////////////////////////////////////////////////////////
80 // // Perform the conversion and execute subtasks (if any)
81 // // on an event-by-event basis
84 //--- Author: Nick van Eijndhoven 12-dec-2006 Utrecht University
85 //- Modified: NvE $Date$ Utrecht University
86 ///////////////////////////////////////////////////////////////////////////
88 #include "IceRawTWR.h"
89 #include "Riostream.h"
91 ClassImp(IceRawTWR) // Class implementation to enable ROOT I/O
93 IceRawTWR::IceRawTWR(const char* name,const char* title) : AliJob(name,title)
95 // Default constructor.
96 // By default maxevent=-1, split=0, bsize=32000, printfreq=1.
105 ///////////////////////////////////////////////////////////////////////////
106 IceRawTWR::~IceRawTWR()
108 // Default destructor.
116 ///////////////////////////////////////////////////////////////////////////
117 void IceRawTWR::SetMaxEvents(Int_t n)
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.
124 ///////////////////////////////////////////////////////////////////////////
125 void IceRawTWR::SetPrintFreq(Int_t f)
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;
131 ///////////////////////////////////////////////////////////////////////////
132 void IceRawTWR::SetSplitLevel(Int_t split)
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;
138 ///////////////////////////////////////////////////////////////////////////
139 void IceRawTWR::SetBufferSize(Int_t bsize)
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;
145 ///////////////////////////////////////////////////////////////////////////
146 void IceRawTWR::AddInputFile(TString name)
148 // Add the name of this TWR raw data input file to the list to be processed.
152 fInfiles=new TObjArray();
153 fInfiles->SetOwner();
156 TObjString* s=new TObjString();
160 ///////////////////////////////////////////////////////////////////////////
161 void IceRawTWR::SetOutputFile(TFile* ofile)
163 // Set the output file for the ROOT data.
164 if (fOutfile) delete fOutfile;
167 ///////////////////////////////////////////////////////////////////////////
168 void IceRawTWR::SetOutputFile(TString name)
170 // Create the output file for the ROOT data.
171 if (fOutfile) delete fOutfile;
172 fOutfile=new TFile(name.Data(),"RECREATE","F2K data in IceEvent structure");
174 ///////////////////////////////////////////////////////////////////////////
175 TFile* IceRawTWR::GetOutputFile()
177 // Provide pointer to the ROOT output file.
180 ///////////////////////////////////////////////////////////////////////////
181 void IceRawTWR::Exec(Option_t* opt)
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".
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.
202 cout << " *IceRawTWR Exec* No data input file(s) specified." << endl;
206 Int_t ninfiles=fInfiles->GetEntries();
209 cout << " *IceRawTWR Exec* No data input file(s) specified." << endl;
216 otree=new TTree("T","TWR raw data converted to IceEvent structures");
217 otree->SetDirectory(fOutfile);
220 IceEvent* evt=new IceEvent();
221 evt->SetTrackCopy(1);
224 // Branch in the tree for the event structure
225 if (otree) otree->Branch("IceEvent","IceEvent",&evt,fBsize,fSplit);
227 // Initialise the job working environment
237 cout << " ***" << endl;
238 cout << " *** Start processing of job " << GetName() << " ***" << endl;
239 cout << " ***" << endl;
240 for (Int_t i=0; i<ninfiles; i++)
242 TObjString* sx=(TObjString*)fInfiles->At(i);
244 inputfile=sx->GetString();
245 cout << " TWR raw data input file : " << inputfile.Data() << endl;
247 cout << " Maximum number of events to be processed : " << fMaxevt << endl;
248 cout << " Print frequency : " << fPrintfreq << endl;
251 cout << " ROOT output file : " << fOutfile->GetName() << endl;
252 cout << " Output characteristics : splitlevel = " << fSplit << " buffersize = " << fBsize << endl;
257 // Storage of the used parameters in the IceRawTWR device
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);
267 // Set DAQ device info
270 daq.SetSlotName("TWR",1);
273 twr_raw_data_file_t twr_file;
274 Int_t year,runnum,evtnum;
280 UInt_t gpslow,gpshigh,gpssecs; // The GPS time information
281 Int_t seconds,nsecs; // Seconds and nanoseconds since start of the UT year
285 for (Int_t ifile=0; ifile<ninfiles; ifile++)
287 TObjString* sx=(TObjString*)fInfiles->At(ifile);
290 inputfile=sx->GetString();
291 if (inputfile=="") continue;
293 // Open the TWR raw data input file in binary mode
294 fInput=fopen(inputfile.Data(),"rb");
298 cout << " *IceRawTWR Exec* No input file found with name : " << inputfile.Data() << endl;
302 // Extract info like run number, file number etc... from filename
303 extract_info_from_filename((char*)inputfile.Data(),&twr_file);
306 runnum=twr_file.run_no;
308 // Initialise the event structure
309 clear_event(&fEvent);
311 // Read the file header information
312 error=read_header_from_file(fInput,&fHeader,&nhead);
316 cout << " *IceRawTWR Exec* Error in header for input file : " << inputfile.Data() << endl;
320 // Correct the mapping
321 update_system(fHeader,runnum);
323 while (!read_event(fInput,fHeader,&fEvent))
325 if (fMaxevt>-1 && nevt>=fMaxevt) break;
327 evtnum=fEvent.eventcounter;
329 // The GPS telegram info
331 gpslow=gps.seconds; // The low 24 bits of the seconds count
332 gpshigh=gps.info.bits.seconds; // The high 8 bits of the seconds count
336 // Seconds and nanoseconds since the start of the UT year
338 nsecs=100*gps.count_10MHz;
340 // Reset the complete Event structure
343 evt->SetRunNumber(runnum);
344 evt->SetEventNumber(evtnum);
345 evt->SetUT(year,0,seconds,nsecs);
347 evt->AddDevice(params);
354 // Invoke all available sub-tasks (if any)
360 if (!(nevt%fPrintfreq)) evt->HeaderData();
363 // Write the complete structure to the output Tree
364 if (otree) otree->Fill();
366 // Update event counter
369 // Reset the raw event structure
370 clear_event(&fEvent);
371 } // End of event reading loop
373 // Delete the file header structure
374 clear_system(fHeader);
376 if (fMaxevt>-1 && nevt>=fMaxevt) break;
378 } // End of input file loop
380 // Flush possible memory resident data to the output file
381 if (fOutfile) fOutfile->Write();
383 // Remove the IceEvent object from the environment
384 // and delete it as well
391 ///////////////////////////////////////////////////////////////////////////
392 void IceRawTWR::PutWaveforms(Int_t year)
394 // Get the waveform info from the raw data event into the IcePack structure.
396 IceEvent* evt=(IceEvent*)GetMainObject();
399 // Loop over all the waveforms and add the histo(s) to the corresponding OM's
411 for (Int_t i=0; i<N_OF_CHANNELS; i++)
413 if (!fEvent.wfm_filled[i]) continue;
415 omid=fEvent.twr_id_of_om[i];
416 if (omid<=0 || omid>omidmax) continue; // Skip trigger channels
418 // Get corresponding device from the current event structure
419 omx=(IceAOM*)evt->GetIdDevice(omid);
423 om.SetUniqueID(omid);
425 omx=(IceAOM*)evt->GetIdDevice(omid);
430 clear_waveform_analysis(&fWform);
431 error=restore_waveform(fEvent.wfm[i],&fWform,year);
435 baseline=fWform.frag_mean[0];
438 hname+=omx->GetNwaveforms()+1;
439 omx->AddNamedSlot(hname);
440 omx->SetSignal(baseline,hname);
442 // Fill the waveform histogram
446 hname+=omx->GetNwaveforms()+1;
449 histo.SetName(hname.Data());
450 nbins=fWform.n_point;
451 xlow=fWform.wfm_x[0];
452 xup=fWform.wfm_x[nbins-1];
453 histo.SetBins(nbins,xlow,xup);
455 for (Int_t jbin=1; jbin<=nbins; jbin++)
457 histo.SetBinContent(jbin,baseline-fWform.wfm_y[jbin-1]);
460 omx->SetWaveform(&histo,omx->GetNwaveforms()+1);
463 ///////////////////////////////////////////////////////////////////////////
464 void IceRawTWR::PutTrigger(Int_t year)
466 // Get the trigger info from the raw data event into the IcePack structure.
467 // Currently only the trigger settings for the years 2005 and 2006 have been
469 // In addition to the hardware and software triggers as encountered in the
470 // raw data, an artificial "main" trigger has been introduced.
471 // This artificial "main" trigger is just an "or" of the standard hard and soft
472 // triggers (except calibration and random triggers) and serves only to
473 // provide a generic "main" trigger a la Amanda mu-daq so that the default
474 // "IceCleanHits" hit cleaning procedure will work correctly.
475 // The trigger time for the artificial "main" trigger is taken to be the
476 // time of the earliest hardware trigger pulse. In case there is no hardware
477 // trigger pulse available, the "main" trigger time is set to 0.
478 // For other years, only the artificial "main" trigger with a trigger time
479 // set to 0 will be stored in the IceEvent structure.
481 // Fill the trigger structure
482 Int_t error=retrigger(&fEvent,&fTrigger);
485 IceEvent* evt=(IceEvent*)GetMainObject();
489 trig.SetNameTitle("Trigger","Amanda/IceCube event triggers");
493 if (year !=2005 && year != 2006)
497 s.SetSlotName("trig_pulse_le",1);
498 s.SetSignal(trigtime,1);
500 // Store the trigger data into the IceEvent structure
501 evt->AddDevice(trig);
505 // Trigger settings for 2005 and 2006
506 if (!fTrigger.n_software_trigger && !fTrigger.n_hardware_trigger) return;
508 TString trignames[N_OF_TRIGGERS]={"m24","m18","string","spase","cal-t0","cal-la","m12",
509 "main-logic","main-or","random","m20-frag","volume"};
511 for (Int_t i=0; i<N_OF_TRIGGERS; i++)
513 if (!fTrigger.trigger_active[i]) continue;
516 s.SetName(trignames[i]);
519 if (fTrigger.trigger_has_pulse[i]) trigtime=fTrigger.trigger_time[i];
520 s.SetSlotName("trig_pulse_le",1);
521 s.SetSignal(trigtime,1);
523 // Set flag to indicate creation of artificial "main" trigger
524 if (i!=4 && i!=5 && i!=9) imain=1;
527 // Set the artificial "main" trigger
532 s.SetUniqueID(N_OF_TRIGGERS);
533 s.SetSlotName("trig_pulse_le",1);
535 if (fTrigger.first_trigger>=0) trigtime=fTrigger.first_trigger_time;
536 s.SetSignal(trigtime,1);
540 // Store the trigger data into the IceEvent structure
541 evt->AddDevice(trig);
543 ///////////////////////////////////////////////////////////////////////////
544 Int_t IceRawTWR::extract_info_from_filename(char* fname,twr_raw_data_file_t* twr_file)
546 char start_str[20],year_str[20],day_str[20],run_no_str[20],
547 file_no_str[20],begin_str[20],end_str[20];
550 filename = strstr(fname, "twr");
552 if(strncmp("twr_", start_str, 4))
554 printf("%s\n", filename);
555 return(ERROR_NOT_VALID_FILENAME);
558 strncpy(start_str, filename, 4);
559 if(strncmp("twr_", start_str, 4))
561 printf("%s %s\n", filename, start_str);
562 return(ERROR_NOT_VALID_FILENAME);
564 strncpy(year_str, &filename[4], 4);
565 twr_file->year = strtol(year_str, 0, 10);
567 if(twr_file->year==2003)
569 strncpy(day_str, &filename[9], 3);
571 twr_file->day = strtol(day_str, 0, 10);
573 strncpy(run_no_str, &filename[13], 4);
574 run_no_str[4] = '\0';
575 twr_file->run_no = strtol(run_no_str, 0, 10);
577 strncpy(file_no_str, &filename[18], 4);
578 file_no_str[4] = '\0';
579 twr_file->file_no = strtol(file_no_str, 0, 10);
582 if(twr_file->year==2004)
584 strncpy(day_str, &filename[9], 3);
586 twr_file->day = strtol(day_str, 0, 10);
588 strncpy(run_no_str, &filename[13], 4);
589 run_no_str[4] = '\0';
590 twr_file->run_no = strtol(run_no_str, 0, 10);
592 strncpy(file_no_str, &filename[18], 4);
593 file_no_str[4] = '\0';
594 twr_file->file_no = strtol(file_no_str, 0, 10);
596 strncpy(begin_str, &filename[23], 5);
598 twr_file->begin = strtol(begin_str, 0, 10);
600 strncpy(end_str, &filename[29], 5);
602 twr_file->end = strtol(end_str, 0, 10);
605 if(twr_file->year > 2004)
607 strncpy(day_str, &filename[9], 3);
609 twr_file->day = strtol(day_str, 0, 10);
611 strncpy(run_no_str, &filename[13], 6);
612 run_no_str[6] = '\0';
613 twr_file->run_no = strtol(run_no_str, 0, 10);
615 strncpy(file_no_str, &filename[20], 4);
616 file_no_str[4] = '\0';
617 twr_file->file_no = strtol(file_no_str, 0, 10);
619 strncpy(begin_str, &filename[25], 5);
621 twr_file->begin = strtol(begin_str, 0, 10);
623 strncpy(end_str, &filename[31], 5);
625 twr_file->end = strtol(end_str, 0, 10);
629 ///////////////////////////////////////////////////////////////////////////
630 Int_t IceRawTWR::clear_system(sys_config_t* sys)
632 // Deletion of the file header structure.
636 for(Int_t icrate=0; icrate < int(sys->n_crates); icrate++)
638 if (!sys->crate[icrate]) continue;
639 for(Int_t itwr=0; itwr < int(sys->crate[icrate]->n_twr); itwr++)
641 if (sys->crate[icrate]->twr[itwr]) delete sys->crate[icrate]->twr[itwr];
643 delete sys->crate[icrate];
649 ///////////////////////////////////////////////////////////////////////////
650 Int_t IceRawTWR::clear_event(event_t* event_ptr)
653 Int_t *int_ptr = (int*) event_ptr;
655 for(i_value=0; i_value < int(sizeof(event_t)/sizeof(Int_t)); i_value++)
661 ///////////////////////////////////////////////////////////////////////////
662 Int_t IceRawTWR::read_header_from_file(FILE* fin,sys_config_t** system_ptr,UInt_t* header_length)
664 Int_t i_crate, i_twr, i_channel;
665 UInt_t count_twr_in_system = 0;
670 // allocating memory for sys_config structure
671 sys = (sys_config_t*) malloc( sizeof(sys_config_t) );
673 fread(&dummy,sizeof(UInt_t),1,fin); // Header Begin Mark
675 fread(header_length,sizeof(UInt_t),1,fin); // Length of header
676 fread(&sys->clockdiv,sizeof(UInt_t),1,fin);
677 fread(&sys->n_crates,sizeof(UInt_t),1,fin);
679 if( (sys->n_crates > MAX_N_CRATES) || (sys->n_crates < 0) )
680 return(ERROR_TOO_MANY_CRATES);
682 for(i_crate=0; i_crate < int(sys->n_crates); i_crate++)
684 sys->crate[i_crate] =
685 (crate_config_t*) malloc( sizeof(crate_config_t) );
687 fread(&sys->crate[i_crate]->vme_base_bridge,sizeof(UInt_t),1,fin);
688 fread(&sys->crate[i_crate]->vme_base_100MHz,sizeof(UInt_t),1,fin);
689 fread(&sys->crate[i_crate]->base_gps,sizeof(UInt_t),1,fin);
690 fread(&sys->crate[i_crate]->n_twr,sizeof(UInt_t),1,fin);
692 if( (sys->crate[i_crate]->n_twr > MAX_N_TWR_PER_CRATE)
693 || (sys->crate[i_crate]->n_twr < 0) )
694 return(ERROR_TOO_MANY_TWRS);
696 for(i_twr=0; i_twr < int(sys->crate[i_crate]->n_twr); i_twr++)
698 sys->crate[i_crate]->twr[i_twr] =
699 (twr_config_t*) malloc( sizeof(twr_config_t) );
700 count_twr_in_system++;
701 fread(&sys->crate[i_crate]->twr[i_twr]->base,
702 sizeof(UInt_t),1,fin);
703 fread(&sys->crate[i_crate]->twr[i_twr]->id,
704 sizeof(UInt_t),1,fin);
706 sys->crate[i_crate]->twr[i_twr]->id
707 = sys->crate[i_crate]->twr[i_twr]->id - 0x10; /* Correct */
710 fread(&dummy,sizeof(UInt_t),1,fin); /* stat_reg */
711 fread(&sys->crate[i_crate]->twr[i_twr]->mod_id,
712 sizeof(UInt_t),1,fin);
713 fread(&dummy,sizeof(UInt_t),1,fin); /* acq_ctrl */
714 fread(&sys->crate[i_crate]->twr[i_twr]->ext_start,
715 sizeof(UInt_t),1,fin);
716 fread(&sys->crate[i_crate]->twr[i_twr]->ext_stop,
717 sizeof(UInt_t),1,fin);
718 fread(&dummy,sizeof(UInt_t),1,fin); /* evtconfig */
720 for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++)
722 fread(&sys->crate[i_crate]->twr[i_twr]->om_no[i_channel],
723 sizeof(UInt_t),1,fin);
726 for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++)
728 fread(&sys->crate[i_crate]->twr[i_twr]->om_is_optical[i_channel],
729 sizeof(UInt_t),1,fin);
732 for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++)
734 fread(&sys->crate[i_crate]->twr[i_twr]->baseline[i_channel],
735 sizeof(UInt_t),1,fin);
738 for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++)
740 fread(&sys->crate[i_crate]->twr[i_twr]->threshold[i_channel],
741 sizeof(UInt_t),1,fin);
744 sys->twr_field[(i_crate * 0x10) + i_twr]
745 = sys->crate[i_crate]->twr[i_twr];
748 for(i_channel=0; i_channel < 8; i_channel++)
750 if( sys->crate[i_crate]->twr[i_twr]->om_no[i_channel] == 9000 )
751 sys->crate[i_crate]->twr[i_twr]->om_no[i_channel]
757 // Set number of TWRs in system
758 sys->n_twr = count_twr_in_system;
763 ///////////////////////////////////////////////////////////////////////////
764 Int_t IceRawTWR::update_system(sys_config_t* sys,Int_t run_number)
766 Int_t i_crate, i_twr, i_channel;
768 /* Data for bug fix 1 */
769 UInt_t om_no_r1[CHANNELS_PER_TWR]
770 = {111, 112, 113, 114, 115, 116, 39, 118};
771 UInt_t om_is_optical_r1[CHANNELS_PER_TWR]
772 = {0, 0, 0, 0, 0, 0, 0, 0};
773 UInt_t threshold_r1[CHANNELS_PER_TWR]
774 = {50, 50, 50, 50, 50, 50, 80, 50};
776 UInt_t om_no_r2[CHANNELS_PER_TWR]
777 = {473, 484, 485, 486, 487, 475, 490, 491};
778 UInt_t om_is_optical_r2[CHANNELS_PER_TWR]
779 = {1, 1, 1, 1, 1, 1, 1, 1};
780 UInt_t threshold_r2[CHANNELS_PER_TWR]
781 = {15, 50, 55, 40, 15, 23, 15, 15};
784 /* Bugfix 1 Andreas Bug */
787 By accident this TWR was counted twice in TWR.cnf
788 as Crate 0 TWR 7 and Crate 4 TWR 7
790 TWR_OM 639 642 1 9 10 11 12 30
791 OPTICAL 0 0 0 0 0 0 0 0
792 TWR_BASELINE 110 120 110 140 150 160 170 180
793 TWR_THRESHOLD 50 50 80 80 80 80 80 80
795 Crate 4 TWR 7 should be replaced with this TWR
796 TWR_OM 111 112 113 114 115 116 39 118
797 OPTICAL 0 0 0 0 0 0 0 0
798 TWR_BASELINE 110 120 130 140 150 160 170 180
799 TWR_THRESHOLD 50 50 50 50 50 50 80 50
803 (run_number >= 9153 ) /* Begin season 2005 13.2.05 */
804 && (run_number < 9800) /* Timo corrected TWR.cnf on after run ??? */
805 /* Need to find exact date */
810 for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++)
812 sys->crate[i_crate]->twr[i_twr]->om_no[i_channel]
813 = om_no_r1[i_channel];
814 sys->crate[i_crate]->twr[i_twr]->om_is_optical[i_channel]
815 = om_is_optical_r1[i_channel];
816 sys->crate[i_crate]->twr[i_twr]->threshold[i_channel]
817 = threshold_r1[i_channel];
821 /* Bugfix 2 Timos Bug */
824 By accident this TWR was counted twice in TWR.cnf
825 as Crate 0 TWR 1 and Crate 5 TWR b
826 from run 9153 up to run 9188
828 TWR_OM 492 493 495 496 497 499 500 501
829 OPTICAL 1 1 1 1 1 1 1 1
830 TWR_BASELINE 110 120 130 140 150 160 170 180
831 TWR_THRESHOLD 16 45 25 42 35 46 15 15
833 Crate 5 TWR b should be corrected to
834 TWR_OM 473 484 485 486 487 475 490 491
835 OPTICAL 1 1 1 1 1 1 1 1
836 TWR_BASELINE 4000 120 130 140 150 4000 170 180
837 TWR_THRESHOLD 15 50 55 40 15 23 15 15
841 (run_number >= 9153 ) /* Begin season 2005 = Feb 2nd 05 */
842 && (run_number < 9189) /* Timo corrected TWR.cnf on */
843 /* Mar 15th 05 = day 74 after run 9188 */
848 for(i_channel = 0; i_channel < CHANNELS_PER_TWR; i_channel++)
850 sys->crate[i_crate]->twr[i_twr]->om_no[i_channel]
851 = om_no_r2[i_channel];
852 sys->crate[i_crate]->twr[i_twr]->om_is_optical[i_channel] =
853 om_is_optical_r2[i_channel];
854 sys->crate[i_crate]->twr[i_twr]->threshold[i_channel] =
855 threshold_r2[i_channel];
860 ///////////////////////////////////////////////////////////////////////////
861 Int_t IceRawTWR::read_event(FILE* fin,sys_config_t* sys,event_t* event_ptr)
864 UInt_t length_of_event_block;
866 Int_t n_twr, n_of_waveforms_in_event, read_number;
867 UInt_t length_wfm[CHANNELS_PER_TWR];
868 UInt_t dummy, channel_no, om_no, twr_no;
870 // Reset waveform filled register
871 memset(&event_ptr->wfm_filled[0], 0, sizeof(UInt_t) * N_OF_CHANNELS);
873 if( !fread(&dummy,sizeof(UInt_t),1,fin) ) return(1);
875 if(dummy != 0xbbbbbbbb)
877 printf("Wrong event begin mark %x\n", dummy);
878 while( (dummy !=0xbbbbbbbb)
879 && (fread(&dummy,sizeof(UInt_t),1,fin) != 0) )
880 {;//printf("dummy:%x\n", dummy);
883 if( !fread(&length_of_event_block,sizeof(UInt_t),1,fin) ) return(1);
884 if( !fread(&event_ptr->eventcounter,sizeof(UInt_t),1,fin) ) return(1);
885 if( !fread(&event_ptr->which_trigger,sizeof(UInt_t),1,fin) ) return(1);
886 if( !fread(&event_ptr->gps,sizeof(GPS_t),1,fin) ) return(1);
888 // --reading waveforms from TWR blocks
890 while(n_twr < int(sys->n_twr))
893 if( !fread(&dummy,sizeof(UInt_t),1,fin) ) return(1);
894 if(dummy != 0xffffffff)
895 {printf("Wrong twr begin mark %x\n", dummy); return(2);}
896 if( !fread(&twr_no,sizeof(UInt_t),1,fin) ) return(1);
898 // nur voruebergehend !!
901 if( !fread(&event_ptr->twr[twr_no].timestamp,sizeof(UInt_t),1,fin) )
903 if( !fread(&n_of_waveforms_in_event,sizeof(UInt_t),1,fin) )
905 event_ptr->twr[twr_no].n_wfm = n_of_waveforms_in_event;
907 for(i_wfm=0; i_wfm < n_of_waveforms_in_event; i_wfm++)
909 if( !fread(&length_wfm[i_wfm],sizeof(UInt_t),1,fin) ) return(1);
913 for(i_wfm=0; i_wfm < n_of_waveforms_in_event; i_wfm++)
915 if(length_wfm[i_wfm] != 0)
917 if( !fread(&channel_no,sizeof(UInt_t),1,fin) ) return(1);
918 if(sys->twr_field[twr_no]->om_no[channel_no]
920 om_no = sys->twr_field[twr_no]->om_no[channel_no];
922 om_no = N_OF_CHANNELS-1;
926 event_ptr->twr_id_of_om[om_no] = twr_no;
928 read_number = fread(&event_ptr->wfm[om_no],
929 length_wfm[i_wfm]-sizeof(UInt_t),1,fin);
930 event_ptr->wfm_filled[om_no] = 1;
931 if( !read_number ) return(1);
933 // read_number correction for usage of fread() instead of read()
934 read_number*=length_wfm[i_wfm]-sizeof(UInt_t);
936 if( read_number != int(length_wfm[i_wfm]-sizeof(UInt_t)) )
938 cout << " read_number : " << read_number
939 << " length_wfm["<<i_wfm<<"] : " << length_wfm[i_wfm]
940 << " sizeof(UInt_t) : " << sizeof(UInt_t) << endl;
949 ///////////////////////////////////////////////////////////////////////////
950 Int_t IceRawTWR::retrigger(event_t* ev,trigger_hits_t* trig)
952 // Returns the active trigger(s)
954 // Initialise the trigger_hits_t structure with zeroes
955 memset(trig, 0, sizeof(trigger_hits_t) );
957 // Obtain the software trigger info
958 trig->n_software_trigger=0;
959 for(Int_t itrigger=0; itrigger<N_OF_TRIGGERS; itrigger++)
961 if(ev->which_trigger & trigger_bits[itrigger])
963 //printf("SetTrigger %i\n", i_trigger);
964 trig->trigger_active[itrigger]=1;
965 trig->n_software_trigger++;
969 trig->trigger_active[itrigger]=0;
973 // Obtain the hardware trigger info
974 trig->n_hardware_trigger=0;
975 trig->first_trigger_time=10000000;
976 trig->first_trigger=-1;
978 for(Int_t jtrigger=0; jtrigger<N_OF_TRIGGERS; jtrigger++)
980 if(!trigger_channel[jtrigger]) continue;
982 if(ev->wfm_filled[trigger_channel[jtrigger]])
984 trig->trigger_active[jtrigger]=1;
985 trig->trigger_time[jtrigger]=(ev->wfm[trigger_channel[jtrigger]].value[2] & 0xfff);
986 trig->trigger_has_pulse[jtrigger]=1;
987 if (trig->trigger_time[jtrigger] < trig->first_trigger_time)
989 trig->first_trigger_time=trig->trigger_time[jtrigger];
990 trig->first_trigger=jtrigger;
992 trig->n_hardware_trigger++;
997 ///////////////////////////////////////////////////////////////////////////
998 Int_t IceRawTWR::clear_waveform_analysis(waveform_analyse_t* wfm_om)
1000 Int_t i_value, i_frag, i_edge, i_peak;
1002 if(wfm_om == 0) return(1);
1004 // output from analysis
1006 for(i_frag=0; i_frag < MAX_N_OF_FRAGS; i_frag++)
1008 wfm_om->frag_n_points[i_frag] = 0;
1009 wfm_om->frag_begin[i_frag] = 0;
1010 wfm_om->frag_end[i_frag] = 0;
1011 wfm_om->frag_mean[i_frag] = 0;
1012 wfm_om->frag_begin_time[i_frag] = 0;
1016 for(i_peak=0; i_peak < MAX_N_OF_PEAKS; i_peak++)
1018 wfm_om->peak_begin[i_peak] = 0;
1019 wfm_om->peak_end[i_peak] = 0;
1020 wfm_om->peak_max[i_peak] = 0;
1021 wfm_om->peak_TDC_edge[i_peak] = 0;
1022 wfm_om->peak_local_minimum[i_peak] = 0;
1023 wfm_om->crosstalk_charge_n_value[i_peak] = 0;
1024 wfm_om->peak_in_fragment[i_peak] = 0;
1026 wfm_om->peak_mean[i_peak] = 0.0;
1028 wfm_om->peak_m[i_peak] = 0.0;
1029 wfm_om->peak_b[i_peak] = 0.0;
1030 wfm_om->peak_t0[i_peak] = 0.0;
1031 wfm_om->peak_begin_time[i_peak] = 0.0;
1032 wfm_om->peak_charge[i_peak] = 0.0;
1033 wfm_om->peak_height[i_peak] = 0.0;
1034 wfm_om->fitted_amplitude[i_peak] = 0.0;
1035 wfm_om->fitted_TOT[i_peak] = 0.0;
1036 wfm_om->crosstalk_charge[i_peak] = 0.0;
1037 wfm_om->crosstalk_slope[i_peak] = 0.0;
1040 wfm_om->n_point = 0;
1041 wfm_om->wfm_min = 4095;
1042 wfm_om->wfm_max = 0;
1043 wfm_om->b_out_of_range = 0;
1045 for(i_value=0; i_value < 1024; i_value++)
1047 wfm_om->wfm_x[i_value] = 0;
1048 wfm_om->wfm_y[i_value] = 0;
1051 wfm_om->n_tdc_edges = 0;
1052 for(i_edge=0; i_edge < MAX_N_OF_TDC_EDGES; i_edge++)
1054 wfm_om->leading_edge[i_edge] = 0.0;
1055 wfm_om->falling_edge[i_edge] = 0.0;
1056 wfm_om->identified_twr_hit[i_edge] = -1;
1061 ///////////////////////////////////////////////////////////////////////////
1062 Int_t IceRawTWR::restore_waveform(waveform_t f_wfm,waveform_analyse_t* wfm_om,Int_t year)
1064 UShort_t wfm_length, mean;
1065 static UShort_t tmp_wf[2000];
1068 Int_t fragment_start = 0;
1069 Int_t frag_count = 0; // position in current fragment
1070 Int_t n_position = 0; // position in displayed waveform
1071 UInt_t n_word = 2; // position in featured waveform
1072 Int_t n_fragment = 0; // actual fragment
1073 Int_t b_wrong_value = 0;
1075 UShort_t assumed_frag_begin, last_value; /* bug in eventbuilder */
1077 wfm_om->wfm_min = 4095.0;
1078 wfm_om->wfm_max = 0.0;
1080 if( (f_wfm.value[0] & 0xf000) != 0xf000 ) return(1);
1081 wfm_length = (f_wfm.value[0] & 0xfff)/2;
1083 mean = f_wfm.value[1] + BASELINE_MEAN_MAGIC;
1084 while( ((f_wfm.value[n_word] & 0xf000) == 0x4000) &&
1085 (n_word < wfm_length) &&
1086 (n_fragment < MAX_N_OF_FRAGS) )
1088 fragment_start = f_wfm.value[n_word] & 0xfff;
1090 wfm_om->frag_begin_time[n_fragment]
1091 = fragment_start * NSECS_PER_TWR_BIN;
1092 wfm_om->frag_begin[n_fragment] = n_position;
1093 wfm_om->frag_mean[n_fragment] = mean;
1098 while( ((f_wfm.value[n_word] & 0xf000) != 0x2000) &&
1099 ((f_wfm.value[n_word] & 0xf000) != 0x4000) &&/*Reconstructable*/
1100 !b_wrong_value && /* Buggy */
1101 (n_word < wfm_length) )
1105 /* 2005 2006 data */
1108 tmp_wf[n_word] = f_wfm.value[n_word] + mean;
1109 wfm_om->wfm_y[n_position] = (float) tmp_wf[n_word];
1110 wfm_om->wfm_x[n_position] = (float)
1111 wfm_om->frag_begin_time[n_fragment]
1112 + (frag_count * NSECS_PER_TWR_BIN);
1114 else if(frag_count == 1)
1116 tmp_wf[n_word] = f_wfm.value[n_word] + tmp_wf[n_word-1];
1117 wfm_om->wfm_y[n_position] = (float) tmp_wf[n_word];
1118 wfm_om->wfm_x[n_position] = (float)
1119 wfm_om->frag_begin_time[n_fragment]
1120 + (frag_count * NSECS_PER_TWR_BIN);
1125 2*tmp_wf[n_word-1] + f_wfm.value[n_word];
1126 tmp_wf[n_word] -= tmp_wf[n_word-2];
1128 wfm_om->wfm_y[n_position] = (float) tmp_wf[n_word];
1129 wfm_om->wfm_x[n_position] = (float)
1130 wfm_om->frag_begin_time[n_fragment]
1131 + (frag_count * NSECS_PER_TWR_BIN);
1136 Hack for wrongly merged overlapping fragments
1138 if(tmp_wf[n_word] > 0x1fff)
1141 /* assume that fragment merge in eventbuilder caused */
1142 /* problem two fragments overlap in EXACTLY ONE point */
1143 /* and are merged first point of the added part of */
1144 /* the fragment is encoded using the former fragment */
1145 /* start as a data point */
1147 last_value = tmp_wf[n_word-1];
1148 assumed_frag_begin = 0x4000 + fragment_start + frag_count;
1149 tmp_wf[n_word] = f_wfm.value[n_word] + 2 * last_value;
1150 tmp_wf[n_word] -= assumed_frag_begin;
1151 wfm_om->wfm_y[n_position] = (float) tmp_wf[n_word];
1153 /* Look if value is still buggy */
1154 if(tmp_wf[n_word] > 0x1fff) b_wrong_value = 1;
1156 debug = ERROR_MISS_FRAG_STOP;
1158 } /* end year >= 2005 */
1161 /* 2003 2004 data */
1162 wfm_om->wfm_y[n_position] = (float) f_wfm.value[n_word];
1163 wfm_om->wfm_x[n_position] = (float)
1164 wfm_om->frag_begin_time[n_fragment]
1165 + (frag_count * NSECS_PER_TWR_BIN);
1166 } /* end year 2003 2004 */
1168 /* Set min and max Y */
1170 if(wfm_om->wfm_y[n_position] > wfm_om->wfm_max)
1171 wfm_om->wfm_max = wfm_om->wfm_y[n_position];
1172 if(wfm_om->wfm_y[n_position] < wfm_om->wfm_min)
1173 wfm_om->wfm_min = wfm_om->wfm_y[n_position];
1180 if((f_wfm.value[n_word] & 0xf000) == 0x2000) /* Normal wavf */
1183 wfm_om->frag_end[n_fragment] = n_position - 1;
1184 wfm_om->frag_n_points[n_fragment] =
1185 wfm_om->frag_end[n_fragment]
1186 - wfm_om->frag_begin[n_fragment] + 1;
1187 wfm_om->n_point += wfm_om->frag_n_points[n_fragment];
1191 return(ERROR_CORRUPTED_WF);
1194 } /* end while fragment */
1197 wfm_om->n_frag = n_fragment;
1198 if( !(n_word & 0x1) ) n_word++;
1200 if(n_fragment >= MAX_N_OF_FRAGS) return(ERROR_MAX_N_FRAGMENTS_EXCEEDED);
1203 // Hack to get rid of last value of waveform always set to 0
1204 if (wfm_om->wfm_y[wfm_om->n_point] == 0.0)
1206 // erase last point of waveform
1209 // Shorten last pulse if necessary
1210 // if( wfm_om.peak_end[wfm_om.n_peak-1]
1211 // == wfm_om.frag_end[wfm_om.n_frag-1] )
1212 // wfm_om.peak_end[wfm_om.n_peak-1]--;
1214 // Shorten last fragment
1215 wfm_om->frag_n_points[wfm_om->n_frag-1]--;
1216 wfm_om->frag_end[wfm_om->n_frag-1]--;
1218 wfm_om->wfm_min = 4095.0;
1219 wfm_om->wfm_max = 0.0;
1220 for (Int_t i_value=0; i_value < wfm_om->n_point; i_value++)
1222 if (wfm_om->wfm_y[i_value] > wfm_om->wfm_max) wfm_om->wfm_max=wfm_om->wfm_y[i_value];
1223 if (wfm_om->wfm_y[i_value] < wfm_om->wfm_min) wfm_om->wfm_min=wfm_om->wfm_y[i_value];
1229 ///////////////////////////////////////////////////////////////////////////