NCFS-Pack
A generic (astro)particle physics analysis framework
 
Loading...
Searching...
No Matches
NcTreeMaker.cxx
Go to the documentation of this file.
1
31
33
122
123#include "NcTreeMaker.h"
124#include "Riostream.h"
125
126ClassImp(NcTreeMaker); // Class implementation to enable ROOT I/O
127
129NcTreeMaker::NcTreeMaker(const char* name,const char* title) : TTask(name,title)
130{
136
137 fFirst=1;
138 fOutfile=0;
139 fOuttree=0;
140 fTrees=0;
141 fNtkmax=1000;
142 fEvt=0;
143 fAstrolab=0;
144 fTrackflag=0;
145 fEventflag=0;
146 fDeviceflag=0;
147 fUseTracks=0;
148 fUseNtk=0;
149 fUseTkMode=0;
152 fTrackMasses=0;
154 fTrackMjds=0;
155 fTrackSecs=0;
156 fTrackIds=0;
157 fTrackNsigs=0;
158 fTrackUnames=0;
159 fTn=0;
160 fTp=0;
161 fTthetap=0;
162 fTphip=0;
163 fTe=0;
164 fTm=0;
165 fTq=0;
166 fTmjd=0;
167 fTsec=0;
168 fTid=0;
169 fTnsig=0;
170 fTuser=0;
173 fEventMasses=0;
175 fEventJruns=0;
176 fEventJevts=0;
178 fEventMjds=0;
179 fEventSecs=0;
180 fEventUnames=0;
181 fEjrun=0;
182 fEjevt=0;
183 fEmjd=0;
184 fEsec=0;
185 fEp=0;
186 fEthetap=0;
187 fEphip=0;
188 fEe=0;
189 fEm=0;
190 fEq=0;
191 fEuser=0;
192 fUseDevices=0;
193 fDeviceNdevs=0;
194 fDeviceNhits=0;
195 fDndev=0;
196 fDnhit=0;
197}
198
200{
206
207 // Delete the output file.
208 // This will also delete the corresponding output Tree
209 if (fOutfile)
210 {
211 delete fOutfile;
212 fOutfile=0;
213 fOuttree=0;
214 }
215
216 if (fTrees)
217 {
218 delete fTrees;
219 fTrees=0;
220 }
221
222 if (fAstrolab)
223 {
224 delete fAstrolab;
225 fAstrolab=0;
226 }
227
228 if (fUseTracks)
229 {
230 delete fUseTracks;
231 fUseTracks=0;
232 }
233 if (fUseNtk)
234 {
235 delete fUseNtk;
236 fUseNtk=0;
237 }
238 if (fUseTkMode)
239 {
240 delete fUseTkMode;
241 fUseTkMode=0;
242 }
243
244 if (fTp)
245 {
246 delete[] fTp;
247 fTp=0;
248 }
249 if (fTthetap)
250 {
251 delete[] fTthetap;
252 fTthetap=0;
253 }
254 if (fTphip)
255 {
256 delete[] fTphip;
257 fTphip=0;
258 }
259 if (fTe)
260 {
261 delete[] fTe;
262 fTe=0;
263 }
264 if (fTm)
265 {
266 delete[] fTm;
267 fTm=0;
268 }
269 if (fTq)
270 {
271 delete[] fTq;
272 fTq=0;
273 }
274 if (fTmjd)
275 {
276 delete[] fTmjd;
277 fTmjd=0;
278 }
279 if (fTsec)
280 {
281 delete[] fTsec;
282 fTsec=0;
283 }
284 if (fTid)
285 {
286 delete[] fTid;
287 fTid=0;
288 }
289 if (fTnsig)
290 {
291 delete[] fTnsig;
292 fTnsig=0;
293 }
294 if (fTuser)
295 {
296 for (Int_t i=0; i<fTrackUnames->GetEntries(); i++)
297 {
298 delete[] fTuser[i];
299 }
300 delete[] fTuser;
301 fTuser=0;
302 }
303 if (fEuser)
304 {
305 delete[] fEuser;
306 fEuser=0;
307 }
308
309 if (fTrackUnames)
310 {
311 delete fTrackUnames;
312 fTrackUnames=0;
313 }
314 if (fEventUnames)
315 {
316 delete fEventUnames;
317 fEventUnames=0;
318 }
319
320 if (fUseDevices)
321 {
322 delete fUseDevices;
323 fUseDevices=0;
324 }
325}
326
328{
334
335 fFirst=1;
336 fOutfile=0;
337 fOuttree=0;
338 fTrees=0;
339 fEvt=0;
340
341 fAstrolab=0;
343
344 fUseTracks=0;
345 fUseNtk=0;
346 fUseTkMode=0;
347 Int_t n=0;
348 Int_t mode=0;
349 if (q.fUseTracks)
350 {
351 for (Int_t i=0; i<q.fUseTracks->GetSize(); i++)
352 {
353 TObjString* s=(TObjString*)q.fUseTracks->At(i);
354 if (s)
355 {
356 n=q.fUseNtk->At(i);
357 mode=q.fUseTkMode->At(i);
358 UseTracks(s->GetString(),n,mode);
359 }
360 }
361 }
362
363 fUseDevices=0;
364 if (q.fUseDevices)
365 {
366 for (Int_t j=0; j<q.fUseDevices->GetSize(); j++)
367 {
368 TObjString* s=(TObjString*)q.fUseDevices->At(j);
369 if (s) UseDevices(s->GetString());
370 }
371 }
372
373 fNtkmax=q.fNtkmax;
374 fTrackflag=q.fTrackflag;
375 fEventflag=q.fEventflag;
376 fDeviceflag=q.fDeviceflag;
377 fTrackMomenta=q.fTrackMomenta;
378 fTrackEnergies=q.fTrackEnergies;
379 fTrackMasses=q.fTrackMasses;
380 fTrackCharges=q.fTrackCharges;
381 fTrackMjds=q.fTrackMjds;
382 fTrackSecs=q.fTrackSecs;
383 fTrackIds=q.fTrackIds;
384 fTrackNsigs=q.fTrackNsigs;
385 fTrackUnames=0;
386 if (q.fTrackUnames)
387 {
388 for (Int_t k=0; k<q.fTrackUnames->GetSize(); k++)
389 {
390 TObjString* s=(TObjString*)q.fTrackUnames->At(k);
391 if (s) Select("track","user",s->GetString());
392 }
393 }
394 fTn=0;
395 fTp=0;
396 fTthetap=0;
397 fTphip=0;
398 fTe=0;
399 fTm=0;
400 fTq=0;
401 fTmjd=0;
402 fTsec=0;
403 fTid=0;
404 fTnsig=0;
405 fTuser=0;
406 fEventMomenta=q.fEventMomenta;
407 fEventEnergies=q.fEventEnergies;
408 fEventMasses=q.fEventMasses;
409 fEventCharges=q.fEventCharges;
410 fEventJruns=q.fEventJruns;
411 fEventJevts=q.fEventJevts;
412 fEventWeights=q.fEventWeights;
413 fEventMjds=q.fEventMjds;
414 fEventSecs=q.fEventSecs;
415 fEventUnames=0;
416 if (q.fEventUnames)
417 {
418 for (Int_t l=0; l<q.fEventUnames->GetSize(); l++)
419 {
420 TObjString* s=(TObjString*)q.fEventUnames->At(l);
421 if (s) Select("event","user",s->GetString());
422 }
423 }
424 fEjrun=0;
425 fEjevt=0;
426 fEweight=0;
427 fEmjd=0;
428 fEsec=0;
429 fEp=0;
430 fEthetap=0;
431 fEphip=0;
432 fEe=0;
433 fEm=0;
434 fEq=0;
435 fEuser=0;
436 fDeviceNdevs=q.fDeviceNdevs;
437 fDeviceNhits=q.fDeviceNhits;
438 fDndev=0;
439 fDnhit=0;
440}
441
442void NcTreeMaker::SetOutputFile(TString fname,TString ftitle,TString tname,TString ttitle)
443{
460
461 // Expand the path name of the specified output file
462 fname=gSystem->ExpandPathName(fname.Data());
463
464 if (fOutfile) delete fOutfile;
465 fOutfile=new TFile(fname.Data(),"RECREATE",ftitle.Data());
466 if (fOuttree) delete fOuttree;
467 fOuttree=new TTree(tname.Data(),ttitle.Data());
468}
469
471{
477
478 if (!fOutfile) return;
479
480 fOutfile->cd();
481
482 Int_t ntrees=0;
483 if (fTrees) ntrees=fTrees->GetEntries();
484 TTree* tree=0;
485 for (Int_t i=0; i<ntrees; i++)
486 {
487 tree=(TTree*)fTrees->At(i);
488 if (tree) tree->Write();
489 }
490 fOuttree->Write();
491
492 gROOT->cd(); // Move from the file back to memory
493}
494
496{
514
515 fNtkmax=n;
516}
517
518void NcTreeMaker::UseTracks(TString name,Int_t n,Int_t mode)
519{
559
560 if (!fUseTracks)
561 {
562 fUseTracks=new TObjArray();
563 fUseTracks->SetOwner();
564 }
565
566 if (!fUseNtk) fUseNtk=new TArrayI();
567
568 if (!fUseTkMode) fUseTkMode=new TArrayI();
569
570 // Check if this classname has already been specified before
571 TString s;
572 Int_t nen=fUseTracks->GetEntries();
573 for (Int_t i=0; i<nen; i++)
574 {
575 TObjString* sx=(TObjString*)fUseTracks->At(i);
576 if (!sx) continue;
577 s=sx->GetString();
578 if (s==name) return;
579 }
580
581 // New name to be added into the storage
582 if (nen >= fUseTracks->GetSize()) fUseTracks->Expand(nen+1);
583 if (nen >= fUseNtk->GetSize()) fUseNtk->Set(nen+1);
584 if (nen >= fUseTkMode->GetSize()) fUseTkMode->Set(nen+1);
585
586 TObjString* namex=new TObjString();
587 namex->SetString(name);
588 fUseTracks->Add(namex);
589 fUseNtk->AddAt(n,nen);
590 fUseTkMode->AddAt(mode,nen);
591}
592
593void NcTreeMaker::UseDevices(TString classname)
594{
620
621 if (!fUseDevices)
622 {
623 fUseDevices=new TObjArray();
624 fUseDevices->SetOwner();
625 }
626
627 // Check if this classname has already been specified before
628 TString s;
629 Int_t nen=fUseDevices->GetEntries();
630 for (Int_t i=0; i<nen; i++)
631 {
632 TObjString* sx=(TObjString*)fUseDevices->At(i);
633 if (!sx) continue;
634 s=sx->GetString();
635 if (s==classname) return;
636 }
637
638 // New classname to be added into the storage
639 if (nen >= fUseDevices->GetSize()) fUseDevices->Expand(nen+1);
640
641 TObjString* namex=new TObjString();
642 namex->SetString(classname);
643 fUseDevices->Add(namex);
644}
645
646void NcTreeMaker::Select(TString type,TString obs,TString uname)
647{
684
685 TString s;
686 Int_t nen;
687
688 if (type=="track") // Track observables
689 {
690 fTrackflag=1;
691 if (obs=="p" || obs=="*") fTrackMomenta=1;
692 if (obs=="e" || obs=="*") fTrackEnergies=1;
693 if (obs=="m" || obs=="*") fTrackMasses=1;
694 if (obs=="q" || obs=="*") fTrackCharges=1;
695 if (obs=="mjd" || obs=="*") fTrackMjds=1;
696 if (obs=="sec" || obs=="*") fTrackSecs=1;
697 if (obs=="id" || obs=="*") fTrackIds=1;
698 if (obs=="nsig" || obs=="*") fTrackNsigs=1;
699 if (obs=="user" && uname != "") // Selection of names of user data words
700 {
701 if (!fTrackUnames)
702 {
703 fTrackUnames=new TObjArray();
704 fTrackUnames->SetOwner();
705 }
706 // Check if this name has already been specified before
707 nen=fTrackUnames->GetEntries();
708 for (Int_t i=0; i<nen; i++)
709 {
710 TObjString* sx=(TObjString*)fTrackUnames->At(i);
711 if (!sx) continue;
712 s=sx->GetString();
713 if (s==uname) return;
714 }
715 // New name to be added into the storage
716 if (nen >= fTrackUnames->GetSize()) fTrackUnames->Expand(nen+1);
717 TObjString* namex=new TObjString();
718 namex->SetString(uname);
719 fTrackUnames->Add(namex);
720 }
721 }
722
723 if (type=="event") // Total event observables
724 {
725 fEventflag=1;
726 if (obs=="p" || obs=="*") fEventMomenta=1;
727 if (obs=="e" || obs=="*") fEventEnergies=1;
728 if (obs=="m" || obs=="*") fEventMasses=1;
729 if (obs=="q" || obs=="*") fEventCharges=1;
730 if (obs=="jrun" || obs=="*") fEventJruns=1;
731 if (obs=="jevt" || obs=="*") fEventJevts=1;
732 if (obs=="weight" || obs=="*") fEventWeights=1;
733 if (obs=="mjd" || obs=="*") fEventMjds=1;
734 if (obs=="sec" || obs=="*") fEventSecs=1;
735 if (obs=="user" && uname != "") // Selection of names of user data words
736 {
737 if (!fEventUnames)
738 {
739 fEventUnames=new TObjArray();
740 fEventUnames->SetOwner();
741 }
742 // Check if this name has already been specified before
743 nen=fEventUnames->GetEntries();
744 for (Int_t j=0; j<nen; j++)
745 {
746 TObjString* sx=(TObjString*)fEventUnames->At(j);
747 if (!sx) continue;
748 s=sx->GetString();
749 if (s==uname) return;
750 }
751 // New name to be added into the storage
752 if (nen >= fEventUnames->GetSize()) fEventUnames->Expand(nen+1);
753 TObjString* namex=new TObjString();
754 namex->SetString(uname);
755 fEventUnames->Add(namex);
756 }
757 }
758
759 if (type=="device") // Device observables
760 {
761 fDeviceflag=1;
762 if (obs=="ndev" || obs=="*") fDeviceNdevs=1;
763 if (obs=="nhit" || obs=="*") fDeviceNhits=1;
764 }
765}
766
768{
784
785 if (fAstrolab)
786 {
787 delete fAstrolab;
788 fAstrolab=0;
789 }
790
791 if (lab) fAstrolab=new NcAstrolab(*lab);
792}
793
795{
801
802 return fAstrolab;
803}
804
805void NcTreeMaker::Exec(Option_t* opt)
806{
812
813 TString name=opt;
814 NcJob* parent=(NcJob*)(gROOT->GetListOfTasks()->FindObject(name.Data()));
815
816 if (!parent) return;
817
818 fEvt=(NcEvent*)parent->GetObject("NcEvent");
819 if (!fEvt) return;
820
821 // Only process accepted events
822 NcDevice* seldev=(NcDevice*)fEvt->GetDevice("NcEventSelector");
823 if (seldev)
824 {
825 if (seldev->GetSignal("Select") < 0.1) return;
826 }
827
828 Int_t ntkmax=0; // Max. number of tracks for a certain name
829 Int_t ntnames=0; // Number of track names to be processed
830 Int_t ntunames=0; // Number of track user data names to be processed
831 Int_t neunames=0; // Number of event user data names to be processed
832 if (fUseTracks) ntnames=fUseTracks->GetEntries();
833 Int_t ndnames=0; // Number of device classes to be processed
834 if (fUseDevices) ndnames=fUseDevices->GetEntries();
835 if (fTrackUnames) ntunames=fTrackUnames->GetEntries();
836 if (fEventUnames) neunames=fEventUnames->GetEntries();
837 TObjString* strx=0;
838 TString str,str2;
839
840 TTree* tree=0;
841
842 if (fFirst)
843 {
844 // Setup of the output tree storage arrays
845 if (fTp) delete[] fTp;
846 fTp=new Float_t[fNtkmax];
847 if (fTthetap) delete[] fTthetap;
848 fTthetap=new Float_t[fNtkmax];
849 if (fTphip) delete[] fTphip;
850 fTphip=new Float_t[fNtkmax];
851 if (fTe) delete[] fTe;
852 fTe=new Float_t[fNtkmax];
853 if (fTm) delete[] fTm;
854 fTm=new Float_t[fNtkmax];
855 if (fTq) delete[] fTq;
856 fTq=new Float_t[fNtkmax];
857 if (fTmjd) delete[] fTmjd;
858 fTmjd=new Double_t[fNtkmax];
859 if (fTsec) delete[] fTsec;
860 fTsec=new Double_t[fNtkmax];
861 if (fTid) delete[] fTid;
862 fTid=new Int_t[fNtkmax];
863 if (fTnsig) delete[] fTnsig;
864 fTnsig=new Int_t[fNtkmax];
865
866 if (fTuser) delete[] fTuser;
867 fTuser=0;
868 if (ntunames)
869 {
870 fTuser=new Float_t*[ntunames];
871 for (Int_t i=0; i<ntunames; i++)
872 {
873 fTuser[i]=new Float_t[fNtkmax];
874 }
875 }
876
877 if (fEuser) delete[] fEuser;
878 fEuser=0;
879 if (neunames) fEuser=new Float_t[neunames];
880
881 if (fTrees) delete fTrees;
882 fTrees=new TObjArray();
883
884 cout << " *NcTreeMaker* Selection parameters." << endl;
885 cout << " Selection types in use :";
886 if (fTrackflag) cout << " track";
887 if (fEventflag) cout << " event";
888 if (fDeviceflag) cout << " device";
889 if (!fTrackflag && !fEventflag && !fDeviceflag) cout << " none";
890 cout << endl;
891
892 if (ntnames) cout << " Track name selections to be processed (-1=all)." << endl;
893 for (Int_t i=0; i<ntnames; i++)
894 {
895 strx=(TObjString*)fUseTracks->At(i);
896 if (!strx) continue;
897 str=strx->GetString();
898 if (str=="*") str="trk"; // Generic track name "trk" in output tree for "*" selection
899 ntkmax=fUseNtk->At(i);
900 cout << " Maximally " << ntkmax << " track(s) per event of name : " << str.Data() << endl;
901
902 // Creation of the corresponding track tree and branch structure(s)
903 if (fTrackflag)
904 {
905 tree=(TTree*)fOutfile->Get(str.Data());
906 if (!tree)
907 {
908 // String replacements to prevent problems with TreeViewer arithmetic
909 str.ReplaceAll("-","m");
910 str.ReplaceAll("+","p");
911 fOutfile->cd();
912 tree=new TTree(str.Data(),"track data");
913 if (fOuttree) fOuttree->AddFriend(tree->GetName());
914 fTrees->Add(tree);
915 }
916 if (!(tree->GetBranch("n"))) tree->Branch("n",&fTn,"n/I");
917 if (fTrackMomenta)
918 {
919 if (!(tree->GetBranch("p"))) tree->Branch("p",fTp,"p[n]/F");
920 if (!(tree->GetBranch("thetap"))) tree->Branch("thetap",fTthetap,"thetap[n]/F");
921 if (!(tree->GetBranch("phip"))) tree->Branch("phip",fTphip,"phip[n]/F");
922 }
923 if (fTrackEnergies && !(tree->GetBranch("E"))) tree->Branch("E",fTe,"E[n]/F");
924 if (fTrackMasses && !(tree->GetBranch("m"))) tree->Branch("m",fTm,"m[n]/F");
925 if (fTrackCharges && !(tree->GetBranch("q"))) tree->Branch("q",fTq,"q[n]/F");
926 if (fTrackMjds && !(tree->GetBranch("mjd"))) tree->Branch("mjd",fTmjd,"mjd[n]/D");
927 if (fTrackSecs && !(tree->GetBranch("sec"))) tree->Branch("sec",fTsec,"sec[n]/D");
928 if (fTrackIds && !(tree->GetBranch("id"))) tree->Branch("id",fTid,"id[n]/I");
929 if (fTrackNsigs && !(tree->GetBranch("nsig"))) tree->Branch("nsig",fTnsig,"nsig[n]/I");
930 if (fTrackUnames)
931 {
932 for (Int_t ituname=0; ituname<ntunames; ituname++)
933 {
934 strx=(TObjString*)fTrackUnames->At(ituname);
935 if (!strx) continue;
936 str=strx->GetString();
937 str2=str;
938 str2+="[n]/F";
939 if (!(tree->GetBranch(str.Data()))) tree->Branch(str.Data(),fTuser[ituname],str2.Data());
940 }
941 }
942 }
943 }
944
945 // Creation of the track tree and branch structure for astrophysical reference objects
946 if (fAstrolab)
947 {
948 cout << " Number of reference objects in Astrolab : " << fAstrolab->GetNRefSignals() << endl;
949
950 tree=(TTree*)fOutfile->Get("astrotrack");
951 if (!tree)
952 {
953 fOutfile->cd();
954 tree=new TTree("astrotrack","astro track data");
955 if (fOuttree) fOuttree->AddFriend(tree->GetName());
956 fTrees->Add(tree);
957 }
958 if (!(tree->GetBranch("n"))) tree->Branch("n",&fTn,"n/I");
959 if (!(tree->GetBranch("thetap"))) tree->Branch("thetap",fTthetap,"thetap[n]/F");
960 if (!(tree->GetBranch("phip"))) tree->Branch("phip",fTphip,"phip[n]/F");
961 if (!(tree->GetBranch("icrsl"))) tree->Branch("icrsl",fTe,"icrsl[n]/F");
962 if (!(tree->GetBranch("icrsb"))) tree->Branch("icrsb",fTm,"icrsb[n]/F");
963 if (!(tree->GetBranch("mjd"))) tree->Branch("mjd",fTmjd,"mjd[n]/D");
964 if (fTrackSecs && !(tree->GetBranch("sec"))) tree->Branch("sec",fTsec,"sec[n]/D");
965 }
966
967 if ((fTrackflag && ntnames) || fAstrolab) cout << " --- Max. number of output tracks per event per name : " << fNtkmax << endl;
968
969 // Creation of the event tree and branch structure(s)
970 if (fEventflag)
971 {
972 tree=(TTree*)fOutfile->Get("evt");
973 if (!tree)
974 {
975 fOutfile->cd();
976 tree=new TTree("evt","event data");
977 if (fOuttree) fOuttree->AddFriend(tree->GetName());
978 fTrees->Add(tree);
979 }
980 if (fEventJruns && !(tree->GetBranch("jrun"))) tree->Branch("jrun",&fEjrun,"jrun/I");
981 if (fEventJevts && !(tree->GetBranch("jevt"))) tree->Branch("jevt",&fEjevt,"jevt/I");
982 if (fEventWeights && !(tree->GetBranch("weight"))) tree->Branch("weight",&fEweight,"weight/D");
983 if (fEventMjds && !(tree->GetBranch("mjd"))) tree->Branch("mjd",&fEmjd,"mjd/D");
984 if (fEventSecs && !(tree->GetBranch("sec"))) tree->Branch("sec",&fEsec,"sec/D");
985 if (fEventMomenta)
986 {
987 if (!(tree->GetBranch("p"))) tree->Branch("p",&fEp,"p/F");
988 if (!(tree->GetBranch("thetap"))) tree->Branch("thetap",&fEthetap,"thetap/F");
989 if (!(tree->GetBranch("phip"))) tree->Branch("phip",&fEphip,"phip/F");
990 }
991 if (fEventEnergies && !(tree->GetBranch("E"))) tree->Branch("E",&fEe,"E/F");
992 if (fEventMasses && !(tree->GetBranch("m"))) tree->Branch("m",&fEm,"m/F");
993 if (fEventCharges && !(tree->GetBranch("q"))) tree->Branch("q",&fEq,"q/F");
994 if (fEventUnames)
995 {
996 for (Int_t ieuname=0; ieuname<neunames; ieuname++)
997 {
998 strx=(TObjString*)fEventUnames->At(ieuname);
999 if (!strx) continue;
1000 str=strx->GetString();
1001 str2=str;
1002 str2+="/F";
1003 if (!(tree->GetBranch(str.Data()))) tree->Branch(str.Data(),&fEuser[ieuname],str2.Data());
1004 }
1005 }
1006 }
1007
1008 // Creation of the device tree and branch structure(s)
1009 if (ndnames) cout << " Device classname selections to be processed." << endl;
1010 for (Int_t j=0; j<ndnames; j++)
1011 {
1012 strx=(TObjString*)fUseDevices->At(j);
1013 if (!strx) continue;
1014 str=strx->GetString();
1015 cout << " Devices (derived from) : " << str.Data() << endl;
1016 if (fDeviceflag)
1017 {
1018 tree=(TTree*)fOutfile->Get(str.Data());
1019 if (!tree)
1020 {
1021 fOutfile->cd();
1022 tree=new TTree(str.Data(),"device data");
1023 if (fOuttree) fOuttree->AddFriend(tree->GetName());
1024 fTrees->Add(tree);
1025 }
1026 if (fDeviceNdevs && !(tree->GetBranch("ndev"))) tree->Branch("ndev",&fDndev,"ndev/I");
1027 if (fDeviceNhits && !(tree->GetBranch("nhit"))) tree->Branch("nhit",&fDnhit,"nhit/I");
1028 }
1029 }
1030
1031 cout << endl;
1032
1033 fFirst=0;
1034 }
1035
1036 if (fEventflag) Event(); // Obtain total event observables
1037 if (fTrackflag) Track(); // Obtain individual track observables
1038 if (fDeviceflag) Device(); // Obtain device observables
1039 if (fAstrolab) AstroTrack(); // Create tracks from (astrophysical) reference objects
1040
1041 if (fOuttree && (fEventflag || fTrackflag || fDeviceflag)) fOuttree->Fill();
1042
1043 gROOT->cd(); // Go back from file to memory
1044}
1045
1047{
1054
1055 if (!fUseTracks) return;
1056
1057 Int_t nnames=fUseTracks->GetEntries(); // Number of track names to be processed
1058 Int_t ntkmax=0; // Max. number of tracks for a certain name
1059 Int_t tkmode=0; // Mode for track retrieval from the event based on the track name (pattern)
1060 TObjString* strx=0;
1061 TString str,str2;
1062 Int_t ntk;
1063
1064 Int_t ntunames=0; // Number of track user data names to be processed
1065 if (fTrackUnames) ntunames=fTrackUnames->GetEntries();
1066
1067 Int_t ndnames=0; // Number of device classnames to be processed
1068 if (fUseDevices) ndnames=fUseDevices->GetEntries();
1069
1070 TTree* tree=0;
1071
1072 NcTrack* track=0;
1073 TObjArray tracks;
1074 Int_t mjd,s,ns,ps;
1075 for (Int_t i=0; i<nnames; i++) // Loop over selected track names
1076 {
1077 strx=(TObjString*)fUseTracks->At(i);
1078 if (!strx) continue;
1079 str=strx->GetString();
1080 ntkmax=fUseNtk->At(i);
1081 tkmode=fUseTkMode->At(i);
1082 if (str=="*")
1083 {
1084 fEvt->GetTracks(0,2,0,&tracks);
1085 str="trk";
1086 }
1087 else
1088 {
1089 fEvt->GetTracks(str,tkmode,&tracks);
1090 }
1091 ntk=tracks.GetEntries();
1092 if (ntkmax>0 && ntk>ntkmax) ntk=ntkmax;
1093
1094 if (ntk>fNtkmax) ntk=fNtkmax; // Max. track number for output tree
1095
1096 // Enter selected observables for this track name into the output tree
1097 fTn=0;
1098 for (Int_t jtk=0; jtk<ntk; jtk++) // Loop over tracks of a certain name
1099 {
1100 track=(NcTrack*)tracks.At(jtk);
1101 if (!track) continue;
1102
1103 if (track->HasVector()==0) continue;
1104
1105 fTp[fTn]=track->GetMomentum(1);
1106 fTthetap[fTn]=track->GetX(2,"sph","rad");
1107 fTphip[fTn]=track->GetX(3,"sph","rad");
1108 fTe[fTn]=track->GetEnergy(1);
1109 fTm[fTn]=track->GetMass(1);
1110 fTq[fTn]=track->GetCharge();
1111 fTmjd[fTn]=0;
1112 fTsec[fTn]=0;
1113 NcTimestamp* ts=track->GetTimestamp();
1114 if (ts)
1115 {
1116 fTmjd[fTn]=ts->GetMJD();
1117 ts->GetMJD(mjd,s,ns);
1118 ps=fEvt->GetPs();
1119 fTsec[fTn]=double(s)+double(ns)*1.e-9+double(ps)*1.e-12;
1120 }
1121 fTid[fTn]=track->GetId();
1122
1123 fTnsig[fTn]=0;
1124 for (Int_t id=0; id<ndnames; id++) // Loop over selected device classnames
1125 {
1126 strx=(TObjString*)fUseDevices->At(id);
1127 if (!strx) continue;
1128 str2=strx->GetString();
1129 fTnsig[fTn]+=track->GetNsignals(str2.Data(),2); // Sample number of associated signals
1130 } // End of loop over selected device classnames
1131
1132 NcSignal* sx=track->GetUserData();
1133 for (Int_t ituname=0; ituname<ntunames; ituname++) // Loop over selected user data word names
1134 {
1135 fTuser[ituname][fTn]=0;
1136 strx=(TObjString*)fTrackUnames->At(ituname);
1137 if (!strx) continue;
1138 str2=strx->GetString();
1139 if (!sx) continue;
1140 fTuser[ituname][fTn]=sx->GetSignal(str2); // Get value of the requested user data word
1141 } // End of loop over selected user data word names
1142
1143 fTn++;
1144 } // End of loop over tracks of a certain name
1145
1146 // String replacements to prevent problems with TreeViewer arithmetic
1147 str.ReplaceAll("-","m");
1148 str.ReplaceAll("+","p");
1149 tree=(TTree*)fOutfile->Get(str.Data());
1150 if (tree) tree->Fill();
1151
1152 } // End of loop over selected track names
1153}
1154
1156{
1162
1163 TTree* tree=(TTree*)fOutfile->Get("evt");
1164 if (!tree) return;
1165
1166 Int_t neunames=0; // Number of event user data names to be processed
1167 if (fEventUnames) neunames=fEventUnames->GetEntries();
1168
1169 Nc3Vector p;
1170 p=fEvt->Get3Momentum();
1171 Int_t mjd,s,ns,ps;
1172 fEvt->GetMJD(mjd,s,ns);
1173 ps=fEvt->GetPs();
1174
1175 fEjrun=fEvt->GetRunNumber();
1176 fEjevt=fEvt->GetEventNumber();
1177 fEweight=fEvt->GetWeight();
1178 fEmjd=fEvt->GetMJD();
1179 fEsec=double(s)+double(ns)*1.e-9+double(ps)*1.e-12;
1180 fEp=fEvt->GetMomentum(1);
1181 fEthetap=p.GetX(2,"sph","rad");
1182 fEphip=p.GetX(3,"sph","rad");
1183 fEe=fEvt->GetEnergy(1);
1184 fEm=fEvt->GetInvmass(1);
1185 fEq=fEvt->GetCharge();
1186
1187 TObjString* strx=0;
1188 TString str;
1189 NcSignal* sx=fEvt->GetUserData();
1190 for (Int_t ieuname=0; ieuname<neunames; ieuname++) // Loop over selected user data word names
1191 {
1192 fEuser[ieuname]=0;
1193 strx=(TObjString*)fEventUnames->At(ieuname);
1194 if (!strx) continue;
1195 str=strx->GetString();
1196 if (!sx) continue;
1197 fEuser[ieuname]=sx->GetSignal(str); // Get value of the requested user data word
1198 } // End of loop over selected user data word names
1199
1200 tree->Fill();
1201}
1202
1204{
1210
1211 if (!fUseDevices) return;
1212
1213 Int_t nnames=fUseDevices->GetEntries(); // Number of device classnames to be processed
1214 TObjString* strx=0;
1215 TString str;
1216
1217 TTree* tree=0;
1218
1219 for (Int_t i=0; i<nnames; i++) // Loop over selected device classnames
1220 {
1221 strx=(TObjString*)fUseDevices->At(i);
1222 if (!strx) continue;
1223 str=strx->GetString();
1224
1225 // Enter selected observables for this device class into the output tree
1226 fDndev=fEvt->GetNdevices(str.Data());
1227 fDnhit=fEvt->GetNhits(str.Data());
1228
1229 tree=(TTree*)fOutfile->Get(str.Data());
1230 if (tree) tree->Fill();
1231
1232 } // End of loop over selected device classnames
1233}
1234
1236{
1253
1254 if (!fAstrolab) return;
1255
1256 Int_t ntk=fAstrolab->GetNRefSignals(1);
1257 if (ntk>fNtkmax) ntk=fNtkmax; // Max. track number for output tree
1258
1259 // Enter observables for each astrotrack into the output tree
1260 Double_t d,a,b;
1261 Double_t vec[3];
1262 Nc3Vector p;
1263 Int_t mjd,s,ns,ps;
1264 fTn=0;
1265 for (Int_t jtk=1; jtk<=ntk; jtk++)
1266 {
1267 NcSignal* sx=fAstrolab->GetSignal(d,a,"rad",b,"rad","loc",(NcTimestamp*)fEvt,jtk);
1268 if (!sx) continue;
1269
1270 vec[0]=d;
1271 vec[1]=a;
1272 vec[2]=b;
1273 p.SetVector(vec,"sph","rad");
1274
1275 p*=-1.; // Track direction as arriving from the (astrophysical) object
1276
1277 sx=fAstrolab->GetSignal(d,a,"rad",b,"rad","icr",(NcTimestamp*)fEvt,jtk);
1278
1279 fTthetap[fTn]=p.GetX(2,"sph","rad");
1280 fTphip[fTn]=p.GetX(3,"sph","rad");
1281 fTm[fTn]=b; // ICRS latitude in radians
1282 fTe[fTn]=a; // ICRS longitude in radians
1283 fTmjd[fTn]=0;
1284 fTsec[fTn]=0;
1285 NcTimestamp* ts=sx->GetTimestamp();
1286 if (ts)
1287 {
1288 fTmjd[fTn]=ts->GetMJD();
1289 ts->GetMJD(mjd,s,ns);
1290 ps=fEvt->GetPs();
1291 fTsec[fTn]=double(s)+double(ns)*1.e-9+double(ps)*1.e-12;
1292 }
1293 fTn++;
1294 } // End of loop over astrotracks
1295
1296 TTree* tree=(TTree*)fOutfile->Get("astrotrack");
1297 if (tree) tree->Fill();
1298}
1299
1300TObject* NcTreeMaker::Clone(const char* name) const
1301{
1310
1311 NcTreeMaker* sel=new NcTreeMaker(*this);
1312 if (name)
1313 {
1314 if (strlen(name)) sel->SetName(name);
1315 }
1316 return sel;
1317}
1318
ClassImp(NcTreeMaker)
Handling of 3-vectors in various reference frames.
Definition Nc3Vector.h:15
Double_t GetX(Int_t i, TString f, TString u="rad")
void SetVector(Double_t *v, TString f, TString u="rad")
Double_t GetX(Int_t i, TString f, TString u="rad")
Int_t HasVector() const
NcSignal * GetUserData() const
Virtual lab to provide (astro)physical parameters, treat data and relate observations with astrophysi...
Definition NcAstrolab.h:47
Signal (Hit) handling of a generic device.
Definition NcDevice.h:14
Creation and investigation of an NCFS generic event structure.
Definition NcEvent.h:15
Base class for top level job in a task based procedure.
Definition NcJob.h:18
TObject * GetObject(const char *classname) const
Definition NcJob.cxx:456
NcTimestamp * GetTimestamp()
Generic handling of (extrapolated) detector signals.
Definition NcSignal.h:23
virtual Float_t GetSignal(Int_t j=1, Int_t mode=0) const
Definition NcSignal.cxx:651
Handling of timestamps for (astro)particle physics research.
Definition NcTimestamp.h:20
Double_t GetMJD(Int_t y, Int_t m, Int_t d, Int_t hh, Int_t mm, Int_t ss, Int_t ns) const
Handling of the attributes of a reconstructed particle track.
Definition NcTrack.h:19
NcTimestamp * GetTimestamp()
Definition NcTrack.cxx:1985
Int_t GetId() const
Definition NcTrack.cxx:1783
Int_t GetNsignals() const
Definition NcTrack.cxx:970
Double_t GetEnergy(Float_t scale=-1)
Definition NcTrack.cxx:721
Double_t GetMass(Float_t scale=-1)
Definition NcTrack.cxx:671
Float_t GetCharge() const
Definition NcTrack.cxx:710
Double_t GetMomentum(Float_t scale=-1)
Definition NcTrack.cxx:627
TTask derived class to generate a plain ROOT tree from NCFS generic event structures.
Definition NcTreeMaker.h:17
TFile * fOutfile
Definition NcTreeMaker.h:35
NcAstrolab * fAstrolab
Definition NcTreeMaker.h:40
Float_t fEm
! Variable for event data storage in output tree
Definition NcTreeMaker.h:88
Int_t fEventSecs
Definition NcTreeMaker.h:71
Int_t fTrackMomenta
Definition NcTreeMaker.h:47
Float_t fEq
! Variable for event data storage in output tree
Definition NcTreeMaker.h:87
Int_t fTrackIds
Definition NcTreeMaker.h:53
Float_t * fTq
! Array for track data storage in output tree
Definition NcTreeMaker.h:61
TObjArray * fUseDevices
Definition NcTreeMaker.h:90
Float_t fEe
! Variable for event data storage in output tree
Definition NcTreeMaker.h:86
Double_t fEsec
! Variable for event data storage in output tree
Definition NcTreeMaker.h:82
Int_t fTrackEnergies
Definition NcTreeMaker.h:48
Int_t fNtkmax
Definition NcTreeMaker.h:38
void Select(TString type, TString obs, TString uname="")
TObjArray * fTrackUnames
Definition NcTreeMaker.h:55
Int_t fDeviceNhits
Definition NcTreeMaker.h:92
Int_t fEventJruns
Definition NcTreeMaker.h:68
NcTreeMaker(const char *name="NcTreeMaker", const char *title="ROOT tree data generation")
NcEvent * fEvt
Definition NcTreeMaker.h:39
Int_t fEventMomenta
Definition NcTreeMaker.h:72
Int_t fDeviceNdevs
Definition NcTreeMaker.h:91
Double_t * fTsec
! Array for track data storage in output tree
Definition NcTreeMaker.h:64
Float_t * fTthetap
! Array for track data storage in output tree
Definition NcTreeMaker.h:58
Int_t fEjrun
! Variable for event data storage in output tree
Definition NcTreeMaker.h:78
Int_t fTrackCharges
Definition NcTreeMaker.h:49
Float_t * fEuser
! Variable for event data storage in output tree
Definition NcTreeMaker.h:89
Float_t * fTp
! Array for track data storage in output tree
Definition NcTreeMaker.h:57
Int_t fDnhit
! Variable for device data storage in output tree
Definition NcTreeMaker.h:94
virtual ~NcTreeMaker()
Int_t fEventflag
Definition NcTreeMaker.h:42
Float_t * fTm
! Array for track data storage in output tree
Definition NcTreeMaker.h:62
Double_t fEweight
! Variable for event data storage in output tree
Definition NcTreeMaker.h:80
Int_t fDeviceflag
Definition NcTreeMaker.h:43
virtual void Exec(Option_t *opt)
TObjArray * fTrees
Definition NcTreeMaker.h:37
Int_t fTn
! Number of tracks in the output tree storage array
Definition NcTreeMaker.h:56
Int_t fDndev
! Variable for device data storage in output tree
Definition NcTreeMaker.h:93
Int_t fEventWeights
Definition NcTreeMaker.h:76
Int_t fEventJevts
Definition NcTreeMaker.h:69
Int_t fTrackflag
Definition NcTreeMaker.h:41
TObjArray * fEventUnames
Definition NcTreeMaker.h:77
Float_t ** fTuser
! Matrix array for track data storage in output tree
Definition NcTreeMaker.h:67
void SetAstrolab(NcAstrolab *lab)
Float_t fEp
! Variable for event data storage in output tree
Definition NcTreeMaker.h:83
virtual TObject * Clone(const char *name="") const
NcAstrolab * GetAstrolab() const
TTree * fOuttree
Definition NcTreeMaker.h:36
Int_t * fTnsig
! Array for track data storage in output tree
Definition NcTreeMaker.h:66
Int_t fEventCharges
Definition NcTreeMaker.h:74
TArrayI * fUseNtk
Definition NcTreeMaker.h:45
Float_t * fTphip
! Array for track data storage in output tree
Definition NcTreeMaker.h:59
void SetTrackMaximum(Int_t n)
Int_t fTrackMjds
Definition NcTreeMaker.h:51
Double_t * fTmjd
! Array for track data storage in output tree
Definition NcTreeMaker.h:63
Int_t fEventMasses
Definition NcTreeMaker.h:75
TArrayI * fUseTkMode
Definition NcTreeMaker.h:46
Int_t fEventMjds
Definition NcTreeMaker.h:70
Int_t fEjevt
! Variable for event data storage in output tree
Definition NcTreeMaker.h:79
Int_t * fTid
! Array for track data storage in output tree
Definition NcTreeMaker.h:65
Double_t fEmjd
! Variable for event data storage in output tree
Definition NcTreeMaker.h:81
Float_t fEphip
! Variable for event data storage in output tree
Definition NcTreeMaker.h:85
void UseDevices(TString classname)
Int_t fTrackMasses
Definition NcTreeMaker.h:50
Int_t fTrackNsigs
Definition NcTreeMaker.h:54
Float_t * fTe
! Array for track data storage in output tree
Definition NcTreeMaker.h:60
Int_t fEventEnergies
Definition NcTreeMaker.h:73
TObjArray * fUseTracks
Definition NcTreeMaker.h:44
void SetOutputFile(TString fname, TString ftitle, TString tname="Data", TString ttitle="All event data")
Int_t fTrackSecs
Definition NcTreeMaker.h:52
void UseTracks(TString name, Int_t n=-1, Int_t mode=0)
Float_t fEthetap
! Variable for event data storage in output tree
Definition NcTreeMaker.h:84