NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
IceRootx.cxx
Go to the documentation of this file.
1
17
19
87
88#include "IceRootx.h"
89#include "Riostream.h"
90
91ClassImp(IceRootx); // Class implementation to enable ROOT I/O
92
93IceRootx::IceRootx(const char* name,const char* title) : NcJob(name,title)
94{
101
102 fSplit=0;
103 fBsize=32000;
104 fMaxevt=-1;
105 fPrintfreq=1;
106 fInfiles=0;
107 fOutfile=0;
108}
109
111{
117
118 if (fInfiles)
119 {
120 delete fInfiles;
121 fInfiles=0;
122 }
123}
124
126{
134
135 fMaxevt=n;
136}
137
139{
146
147 if (f>=0) fPrintfreq=f;
148}
149
150void IceRootx::SetSplitLevel(Int_t split)
151{
158
159 if (split>=0) fSplit=split;
160}
161
162void IceRootx::SetBufferSize(Int_t bsize)
163{
170
171 if (bsize>=0) fBsize=bsize;
172}
173
174void IceRootx::AddInputFile(TString name)
175{
181
182 if (!fInfiles)
183 {
184 fInfiles=new TObjArray();
185 fInfiles->SetOwner();
186 }
187
188 TObjString* s=new TObjString();
189 s->SetString(name);
190 fInfiles->Add(s);
191}
192
193void IceRootx::SetOutputFile(TFile* ofile)
194{
200
201 if (fOutfile) delete fOutfile;
202 fOutfile=ofile;
203}
204
205void IceRootx::SetOutputFile(TString name)
206{
212
213 if (fOutfile) delete fOutfile;
214 fOutfile=new TFile(name.Data(),"RECREATE","Simple Root data in IceEvent structure");
215}
216
218{
224
225 return fOutfile;
226}
227
228void IceRootx::Exec(Option_t* opt)
229{
250
251 if (!fInfiles)
252 {
253 cout << " *IceRootx Exec* No data input file(s) specified." << endl;
254 return;
255 }
256
257 Int_t ninfiles=fInfiles->GetEntries();
258 if (!ninfiles)
259 {
260 cout << " *IceRootx Exec* No data input file(s) specified." << endl;
261 return;
262 }
263
264 // Create output tree if necessary
265 TTree* otree=0;
266 if (fOutfile)
267 {
268 otree=new TTree("T","Simple Root data converted to IceEvent structures");
269 otree->SetDirectory(fOutfile);
270 }
271
272 // Create IceEvent structure
273 IceEvent* evt=new IceEvent();
274 evt->SetTrackCopy(1);
275 evt->SetDevCopy(1);
276
277 // Branch in the tree for the event structure
278 if (otree) otree->Branch("IceEvent","IceEvent",&evt,fBsize,fSplit);
279
280 // Initialise the job working environment
281 SetMainObject(evt);
282
283 // Some output for the user's convenience
284 TString inputfile;
285 cout << " ***" << endl;
286 cout << " *** Start processing of job " << GetName() << " ***" << endl;
287 cout << " ***" << endl;
288 for (Int_t i=0; i<ninfiles; i++)
289 {
290 TObjString* sx=(TObjString*)fInfiles->At(i);
291 if (!sx) continue;
292 inputfile=sx->GetString();
293 cout << " Simple Root data input file : " << inputfile.Data() << endl;
294 }
295 cout << " Maximum number of events to be processed : " << fMaxevt << endl;
296 cout << " Print frequency : " << fPrintfreq << endl;
297 if (fOutfile)
298 {
299 cout << " ROOT output file : " << fOutfile->GetName() << endl;
300 cout << " Output characteristics : splitlevel = " << fSplit << " buffersize = " << fBsize << endl;
301 }
302
304
305 // Set DAQ device info
306 NcDevice daq;
307 daq.SetName("Daq");
308 daq.SetSlotName("TWR",1);
309 daq.SetSignal(1,1);
310
311 // Trigger device
312 NcDevice trig;
313 trig.SetNameTitle("Trigger","Amanda/IceCube event triggers");
314 NcSignal s;
315
316 // Some variables
317 Double_t triggertime=0;
318 Int_t eventtimemjd=0;
319 Int_t eventtimemjds=0;
320 Int_t eventtimemjdns=0;
321 Int_t eventid=0;
322 Int_t runid=0;
323 Int_t String=0;
324 Int_t OM=0;
325 Float_t baseline=0;
326 Double_t binsize=10;
327 Short_t type=0;
328 Int_t numberbins=0;
329 Float_t starttime=0;
330 Int_t ntracks=0;
331
332 Int_t nevt=0;
333 Int_t lastevent=0;
334 Int_t omid=0;
335
336 TString hname;
337 TH1F histo;
338 IceAOM om;
339 IceAOM* omx=0;
340 NcTrack t;
341 Double_t vec[3];
342 NcPosition r;
343 Nc3Vector p;
344
345 Float_t pi=acos(-1.);
346
347 Int_t firstomonstring[20];
348 firstomonstring[0]=0;
349 firstomonstring[1]=1;
350 firstomonstring[2]=21;
351 firstomonstring[3]=41;
352 firstomonstring[4]=61;
353 firstomonstring[5]=87;
354 firstomonstring[6]=123;
355 firstomonstring[7]=159;
356 firstomonstring[8]=195;
357 firstomonstring[9]=231;
358 firstomonstring[10]=267;
359 firstomonstring[11]=303;
360 firstomonstring[12]=345;
361 firstomonstring[13]=387;
362 firstomonstring[14]=429;
363 firstomonstring[15]=471;
364 firstomonstring[16]=513;
365 firstomonstring[17]=555;
366 firstomonstring[18]=597;
367 firstomonstring[19]=639;
368
369 TFile* input=0;
370
371 for (Int_t ifile=0; ifile<ninfiles; ifile++)
372 {
373 TObjString* sx=(TObjString*)fInfiles->At(ifile);
374 if (!sx) continue;
375
376 inputfile=sx->GetString();
377 if (inputfile=="") continue;
378
379 // Open the simple Root data input file
380 input=TFile::Open(inputfile);
381
382 if (!input)
383 {
384 cout << " *IceRootx Exec* No input file found with name : " << inputfile.Data() << endl;
385 continue;
386 }
387
388 // Get simple Root tree
389 fTree=(TTree*)input->Get("T");
390 fTree->SetBranchAddress("triggertime",&triggertime);
391 fTree->SetBranchAddress("eventtimemjd",&eventtimemjd);
392 fTree->SetBranchAddress("eventtimemjds",&eventtimemjds);
393 fTree->SetBranchAddress("eventtimemjdns",&eventtimemjdns);
394 fTree->SetBranchAddress("eventid",&eventid);
395 fTree->SetBranchAddress("runid",&runid);
396 fTree->SetBranchAddress("String",&String);
397 fTree->SetBranchAddress("OM",&OM);
398 fTree->SetBranchAddress("baseline",&baseline);
399 fTree->SetBranchAddress("type",&type);
400 fTree->SetBranchAddress("numberbins",&numberbins);
401 fTree->SetBranchAddress("starttime",&starttime);
402 fTree->SetBranchAddress("ntracks",&ntracks);
403 if(fTree->GetBranch("binsize")) fTree->SetBranchAddress("binsize",&binsize);
404
405 Int_t nmaxbins=(Int_t)fTree->GetLeaf("numberbins")->GetMaximum();
406 Float_t* wvform=new Float_t[nmaxbins+1];
407 fTree->SetBranchAddress("wvform",wvform);
408
409 Int_t nmaxtracks=(Int_t)fTree->GetLeaf("ntracks")->GetMaximum();
410 Float_t* trackx=new Float_t[nmaxtracks];
411 Float_t* tracky=new Float_t[nmaxtracks];
412 Float_t* trackz=new Float_t[nmaxtracks];
413 Double_t* trackenergy=new Double_t[nmaxtracks];
414 Float_t* trackzenith=new Float_t[nmaxtracks];
415 Float_t* trackazimuth=new Float_t[nmaxtracks];
416 Int_t* tracktype=new Int_t[nmaxtracks];
417 fTree->SetBranchAddress("trackx",trackx);
418 fTree->SetBranchAddress("tracky",tracky);
419 fTree->SetBranchAddress("trackz",trackz);
420 fTree->SetBranchAddress("trackenergy",trackenergy);
421 fTree->SetBranchAddress("trackzenith",trackzenith);
422 fTree->SetBranchAddress("trackazimuth",trackazimuth);
423 fTree->SetBranchAddress("tracktype",tracktype);
424
425 // Prepare for loop over entries
426 lastevent=0;
427
428 // Loop over waveforms in tree
429 for(Int_t ientry=0; ientry<fTree->GetEntries(); ientry++)
430 {
431 fTree->GetEntry(ientry);
432
433 // If new event
434 if(eventid!=lastevent)
435 {
436 // Write old event to tree (if it contains data)
437 if(evt->GetDevices("IceAOM"))
438 {
439 // Invoke all available sub-tasks (if any) and write event to tree
440 CleanTasks();
441 ExecuteTasks(opt);
442 if(otree) otree->Fill();
443 if (fPrintfreq) { if (!(nevt%fPrintfreq)) evt->HeaderData(); }
444 // Update event counter
445 nevt++;
446 if (fMaxevt>-1 && nevt>=fMaxevt)
447 {
448 evt->Reset();
449 break;
450 }
451 }
452
453 // Start new event
454 evt->Reset();
455 evt->SetRunNumber(runid);
456 evt->SetEventNumber(eventid);
457 evt->SetMJD(eventtimemjd,eventtimemjds,eventtimemjdns,0);
458 evt->AddDevice(daq);
459
460 // Store trigger information
461 trig.Reset(1);
462 s.Reset(1);
463 s.SetName("main");
464 s.SetTitle("First trigger for TWR time reference");
465 s.SetUniqueID(12);
466 s.SetSlotName("trig_pulse_le",1);
467 s.SetSignal(triggertime,1);
468 trig.AddHit(s);
470 evt->AddDevice(trig);
471
472 // Loop over all the tracks and add them to the current event
473 Int_t nrecotracks=0;
474 Int_t nmctracks=0;
475 for (Int_t itrack=0; itrack<ntracks; itrack++)
476 {
477 t.Reset();
478
479 // Beginpoint of the track
480 vec[0]=trackx[itrack];
481 vec[1]=tracky[itrack];
482 vec[2]=trackz[itrack];
483 r.SetPosition(vec,"car");
484 t.SetBeginPoint(r);
485
486 // Momentum in GeV/c
487 vec[0]=trackenergy[itrack];
488 vec[1]=pi-trackzenith[itrack];
489 vec[2]=trackazimuth[itrack]+pi;
490 if(vec[2]>=2*pi) vec[2]-=2*pi;
491 p.SetVector(vec,"sph");
492 t.Set3Momentum(p);
493
494 // Check for unreconstructed tracks (NaN values) and reset track if necessary
495 if(trackx[itrack]!=trackx[itrack] || tracky[itrack]!=tracky[itrack] || trackz[itrack]!=trackz[itrack] ||
496 trackzenith[itrack]!=trackzenith[itrack] || trackazimuth[itrack]!=trackazimuth[itrack]){
497 t.Reset();
498 }
499
500 // Track ID and name
501 // Monte Carlo track
502 if(tracktype[itrack]==7){
503 nmctracks++;
504 t.SetId(-nmctracks);
505 }
506 // Reco track
507 else {
508 nrecotracks++;
509 t.SetId(nrecotracks);
510 }
511 if(tracktype[itrack]==1) { t.SetName("I3CFIRST"); t.SetTitle("IceTray CFIRST track"); }
512 else if(tracktype[itrack]==2) { t.SetName("I3direct"); t.SetTitle("IceTray direct walk track"); }
513 else if(tracktype[itrack]==3) { t.SetName("I3Jams_cluster"); t.SetTitle("IceTray Jams cluster"); }
514 else if(tracktype[itrack]==4) { t.SetName("I3Jams_qual"); t.SetTitle("IceTray Jams quality"); }
515 else if(tracktype[itrack]==5) { t.SetName("I3TOIFit"); t.SetTitle("IceTray TOI fit"); }
516 else if(tracktype[itrack]==6) { t.SetName("I3line-direct"); t.SetTitle("IceTray line direct walk"); }
517 else if(tracktype[itrack]==7) { t.SetName("I3MCTrack"); t.SetTitle("I3MCTrack"); }
518 else { t.SetName("Unknown"); t.SetTitle("IceTray track of unknown type"); }
519
520 // Add track to event
521 evt->AddTrack(t);
522 }
523
524 // Remember event nr
525 lastevent=eventid;
526 }
527
528 // Get OM from event strcture, or create and add it
529 omid=firstomonstring[-String]+OM-1;
530 if(omid==681) continue; // Skip OM 681, which should never give data: avoid all risk of confusion
531 omx=(IceAOM*)evt->GetIdDevice(omid);
532 if (!omx)
533 {
534 om.Reset(1);
535 om.SetUniqueID(omid);
536 evt->AddDevice(om);
537 omx=(IceAOM*)evt->GetIdDevice(omid);
538 }
539 if (!omx) continue;
540
541 // Store baseline info
542 hname="BASELINE-WF";
543 hname+=omx->GetNwaveforms()+1;
544 omx->AddNamedSlot(hname);
545 omx->SetSignal(baseline,hname);
546
547 // Store readout type
548 omx->AddNamedSlot("READOUT");
549 if(type==0) omx->SetSignal(1,"READOUT"); // Electrical
550 else if(type==1) omx->SetSignal(2,"READOUT"); // Optical
551 else if(type==2) omx->SetSignal(3,"READOUT"); // Digital
552 else omx->SetSignal(0,"READOUT"); // Unknown
553
554 // Fill the waveform histogram with this fragment
555 hname="OM";
556 hname+=omid;
557 hname+="-WF";
558 hname+=omx->GetNwaveforms()+1;
559
560 histo.Reset();
561 histo.SetName(hname.Data());
562 histo.SetBins(numberbins,triggertime+starttime,triggertime+starttime+numberbins*binsize);
563
564 for (Int_t jbin=1; jbin<=numberbins; jbin++)
565 {
566 histo.SetBinContent(jbin,baseline-wvform[jbin-1]);
567 }
568
569 omx->SetWaveform(&histo,omx->GetNwaveforms()+1);
570
571 }
572
573 // Write last event to tree
574 if(evt->GetDevices("IceAOM"))
575 {
576 CleanTasks();
577 ExecuteTasks(opt);
578 if (otree) otree->Fill();
579 if (fPrintfreq) { if (!(nevt%fPrintfreq)) evt->HeaderData(); }
580 // Update event counter
581 nevt++;
582 if (fMaxevt>-1 && nevt>=fMaxevt) break;
583 }
584
585 // Reset event
586 evt->Reset();
587
588 // Close input file
589 input->Close();
590
591 // Clean up
592 delete[] wvform;
593 delete[] trackx;
594 delete[] tracky;
595 delete[] trackz;
596 delete[] trackenergy;
597 delete[] trackzenith;
598 delete[] trackazimuth;
599 delete[] tracktype;
600
601 // Stop looping over input files if max. nr. of events is reached
602 if (fMaxevt>-1 && nevt>=fMaxevt)
603 {
604 break;
605 }
606
607 } // End of input file loop
608
609 // Flush possible memory resident data to the output file
610 if (fOutfile) fOutfile->Write();
611
612 // Remove the IceEvent object from the environment
613 // and delete it as well
614 if (evt)
615 {
616 RemoveObject(evt);
617 delete evt;
618 }
619}
620
ClassImp(IceRootx)
Signal (Hit) handling of a generic Amanda Optical Module (AOM).
Definition IceAOM.h:12
Handling of IceCube event data.
Definition IceEvent.h:20
virtual void Reset()
Definition IceEvent.cxx:326
Job for conversion of simple Root data into IceEvent data structures.
Definition IceRootx.h:23
TObjArray * fInfiles
Definition IceRootx.h:42
void SetBufferSize(Int_t bsize)
Definition IceRootx.cxx:162
Int_t fSplit
Definition IceRootx.h:38
IceRootx(const char *name="IceRootx", const char *title="")
Definition IceRootx.cxx:93
Int_t fMaxevt
Definition IceRootx.h:40
virtual void Exec(Option_t *opt)
Definition IceRootx.cxx:228
void SetOutputFile(TFile *ofile)
Definition IceRootx.cxx:193
virtual ~IceRootx()
Definition IceRootx.cxx:110
void AddInputFile(TString name)
Definition IceRootx.cxx:174
TFile * fOutfile
Definition IceRootx.h:43
TFile * GetOutputFile()
Definition IceRootx.cxx:217
void SetPrintFreq(Int_t f)
Definition IceRootx.cxx:138
void SetSplitLevel(Int_t split)
Definition IceRootx.cxx:150
TTree * fTree
Definition IceRootx.h:45
Int_t fBsize
Definition IceRootx.h:39
void SetMaxEvents(Int_t n)
Definition IceRootx.cxx:125
Int_t fPrintfreq
Definition IceRootx.h:41
Handling of 3-vectors in various reference frames.
Definition Nc3Vector.h:15
void SetVector(Double_t *v, TString f, TString u="rad")
void AddNamedSlot(TString s)
void SetSlotName(TString s, Int_t j=1)
Signal (Hit) handling of a generic device.
Definition NcDevice.h:14
void AddHit(NcSignal &s)
Definition NcDevice.cxx:336
virtual void Reset(Int_t mode=0)
Definition NcDevice.cxx:222
NcDevice * GetIdDevice(Int_t id, TObjArray *devs=0) const
Definition NcEvent.cxx:1451
void AddDevice(NcDevice &d)
Definition NcEvent.cxx:1210
void SetEventNumber(Int_t evt)
Definition NcEvent.cxx:573
virtual void HeaderData()
Definition NcEvent.cxx:996
void SetDevCopy(Int_t j)
Definition NcEvent.cxx:1313
TObjArray * GetDevices(TString classname, TObjArray *devices=0)
Definition NcEvent.cxx:1656
void SetRunNumber(Int_t run)
Definition NcEvent.cxx:562
void SetTrackCopy(Int_t j)
Definition NcJet.cxx:1413
void AddTrack(NcTrack &t)
Definition NcJet.cxx:313
void SetMainObject(TObject *obj)
Definition NcJob.cxx:305
void RemoveObject(TObject *obj)
Definition NcJob.cxx:384
NcJob(const char *name="NcJob", const char *title="")
Definition NcJob.cxx:139
void ListEnvironment()
Definition NcJob.cxx:205
Handling of positions (with timestamps) in various reference frames.
Definition NcPosition.h:18
void SetPosition(Double_t *r, TString f, TString u="rad")
Generic handling of (extrapolated) detector signals.
Definition NcSignal.h:23
Int_t GetNwaveforms() const
virtual void Reset(Int_t mode=0)
Definition NcSignal.cxx:334
virtual void SetSignal(Double_t sig, Int_t j=1)
Definition NcSignal.cxx:516
void SetWaveform(TH1F *waveform, Int_t j=1)
void SetMJD(Int_t mjd, Int_t sec, Int_t ns, Int_t ps=0, TString utc="U", Int_t leap=0, Double_t dut=0)
Handling of the attributes of a reconstructed particle track.
Definition NcTrack.h:19
void SetBeginPoint(NcPosition &p)
Definition NcTrack.cxx:1423
void Set3Momentum(Nc3Vector &p)
Definition NcTrack.cxx:401
virtual void Reset()
Definition NcTrack.cxx:321
void SetId(Int_t id)
Definition NcTrack.cxx:1772