WCSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
WCSimRootEvent.cc
Go to the documentation of this file.
1 // Based on Root test Event.cxx
3 
4 #include "TObject.h"
5 #include "TDirectory.h"
6 #include "TProcessID.h"
7 #include <string>
8 #include <vector>
9 #include <iostream>
10 #include <typeinfo>
11 
12 #include <TStopwatch.h>
13 #include "WCSimRootEvent.hh"
14 #include "WCSimRootTools.hh"
15 
16 using std::cout;
17 using std::cerr;
18 using std::endl;
19 using std::vector;
20 
21 #ifndef REFLEX_DICTIONARY
23 ClassImp(WCSimRootCherenkovHit)
25 ClassImp(WCSimRootTrack)
26 ClassImp(WCSimRootPi0)
27 ClassImp(WCSimRootEventHeader)
28 ClassImp(WCSimRootTrigger)
29 ClassImp(WCSimRootEvent)
30 #endif
31 
32 //TClonesArray* WCSimRootTrigger::fgTracks = 0;
33 //
34 //TClonesArray* WCSimRootTrigger::fgCherenkovHits = 0;
35 //TClonesArray* WCSimRootTrigger::fgCherenkovHitTimes = 0;
36 //TClonesArray* WCSimRootTrigger::fgCherenkovDigiHits = 0;
37 //
38 //TClonesArray* WCSimRootTrigger::fgFVCherenkovHits = 0;
39 //TClonesArray* WCSimRootTrigger::fgFVCherenkovHitTimes = 0;
40 //TClonesArray* WCSimRootTrigger::fgFVCherenkovDigiHits = 0;
41 //
42 //
43 //_____________________________________________________________________________
44 
46 {
47  // Create an WCSimRootTrigger object.
48 
49  fNvtxs=0;
50 
51  // WARNING : default constructor for ROOT : do not allocate memory
52  // inside it or upon re-reading the object there will be a memory leak
53  // TClonesArray of WCSimRootTracks
54  fTracks = 0;
55  fNtrack = 0;
56  fNtrack_slots = 0;
57 
58  // TClonesArray of WCSimRootCherenkovHits
59  fCherenkovHits = 0;
61  fNcherenkovhits = 0;
63 
64  // TClonesArray of WCSimRootCherenkovDigiHits
68  fSumQ = 0;
69 
71  fTriggerInfo.clear();
72 
73  IsZombie = true;
74 
75 }
76 
77 WCSimRootTrigger::WCSimRootTrigger(int Number,int Subevt)
78 {
79  this->Initialize();
80  fEvtHdr.Set(Number,0,0,Subevt);
81 }
82 
83 //copy constructor --> only shallow copy of preallocated objects ??
84 
85 
86 void WCSimRootTrigger::Initialize() //actually allocate memory for things in here
87 {
88  // Create an WCSimRootTrigger object.
89  // When the constructor is invoked for the first time, the class static
90  // variable fgTracks is 0 and the TClonesArray fgTracks is created.
91  // Sim. for the other TClonesArray
92  TStopwatch* mystopw = new TStopwatch();
93 
94  // TClonesArray of WCSimRootTracks
95  fTracks = new TClonesArray("WCSimRootTrack", 10000);
96  fTracks->BypassStreamer(kFALSE); // use the member Streamer
97  fNtrack = 0;
98  fNtrack_slots = 0;
99 
100  // TClonesArray of WCSimRootCherenkovHits
101  fCherenkovHits = new TClonesArray("WCSimRootCherenkovHit",
102  10000);
103  fCherenkovHitTimes = new TClonesArray("WCSimRootCherenkovHitTime",
104  10000);
105  fCherenkovHits->BypassStreamer(kFALSE); // use the member Streamer
106  fCherenkovHitTimes->BypassStreamer(kFALSE); // use the member Streamer
107  fNcherenkovhits = 0;
109 
110  // TClonesArray of WCSimRootCherenkovDigiHits
111  fCherenkovDigiHits = new TClonesArray("WCSimRootCherenkovDigiHit",
112  10000);
113  fCherenkovDigiHits->BypassStreamer(kFALSE); // use the member Streamer
116  fSumQ = 0;
117 
119  fTriggerInfo.clear();
120 
121  // G4cout << " Time to allocate the TCAs : Real = " << mystopw->RealTime()
122  // << " ; CPU = " << mystopw->CpuTime() << "\n";
123  delete mystopw;
124 
125 
126  IsZombie = false; // the memory has been allocated
127 }
128 
129 //_____________________________________________________________________________
130 
132 {
133  // now we must do a bunch a deleting stuff...
134  //Destroys all the TClonesArray.. Let's see if Ren'e Brun is right...
135 
136  TStopwatch* mystopw = new TStopwatch();
137 
138  mystopw->Start();
139 
140  if (!IsZombie) {
141 
142  fTracks->Delete();
143  fCherenkovHits->Delete();
144  fCherenkovHitTimes->Delete();
145  fCherenkovDigiHits->Delete();
146 
147  delete fTracks;
148  delete fCherenkovHits;
149  delete fCherenkovHitTimes;
150  delete fCherenkovDigiHits;
151  }
152  mystopw->Stop();
153 
154  // G4cout << " Time to delete the TCAs : Real = " << mystopw->RealTime()
155  // << " ; CPU = " << mystopw->CpuTime() << "\n";
156 
157  delete mystopw;
158  //Clear("C");
159 }
160 
161 //_____________________________________________________________________________
162 
164 {
165  if(this == &in) return *this;
166  //first clear everything
167  this->Clear();
168 
169  //then fill
170  fEvtHdr = in.fEvtHdr;
171  fNvtxs = in.fNvtxs;
172  for(int i = 0; i < MAX_N_VERTICES; i++) {
173  fVtxsvol[i] = in.fVtxsvol[i];
174  for(int j = 0; j < 4; j++) {
175  fVtxs[i][j] = in.fVtxs[i][j];
176  }//j
177  fMode[i] = in.fMode[i];
178 
179  }//i
181  fJmu = in.fJmu;
182  fJp = in.fJp;
183  fPi0 = in.fPi0;
184  fNpar = in.fNpar;
185  fNtrack = in.fNtrack;
186  fTracks = (TClonesArray*)in.fTracks->Clone();
189  fCherenkovHits = (TClonesArray*)in.fCherenkovHits->Clone();
192  fCherenkovHitTimes = (TClonesArray*)in.fCherenkovHitTimes->Clone();
195  fSumQ = in.fSumQ;
196  fCherenkovDigiHits = (TClonesArray*)in.fCherenkovDigiHits->Clone();
199  IsZombie = in.IsZombie;
200  return *this;
201 }
202 
203 //_____________________________________________________________________________
204 
205 void WCSimRootTrigger::Clear(Option_t */*option*/)
206 {
207  // To be filled in
208  // Filled in, by MF, 31/08/06 -> Keep all the alloc'ed memory but reset all
209  // the indices to 0 in the TCAs.
210  fNtrack = 0;
211  fNtrack_slots = 0;
212 
213  // TClonesArray of WCSimRootCherenkovHits
214  fNcherenkovhits = 0;
216 
217  // TClonesArray of WCSimRootCherenkovDigiHits
220  fSumQ = 0;
221 
222  // remove whatever's in the arrays
223  // but don't deallocate the arrays themselves
224 
225  fTracks->Delete();
226  fCherenkovHits->Delete();
227  fCherenkovHitTimes->Delete();
228  fCherenkovDigiHits->Delete();
229 
231  fTriggerInfo.clear();
232 
233  IsZombie = false ; // we DO NOT deallocate the memory
234 }
235 
236 //_____________________________________________________________________________
237 
238 void WCSimRootTrigger::Reset(Option_t */*option*/)
239 {
240 // Static function to reset all static objects for this event
241 // To be filled in
242 }
243 
244 //_____________________________________________________________________________
245 
247  Int_t run,
248  int64_t date,Int_t subevent)
249 {
250  // Set the header values
251  fEvtHdr.Set(i, run, date,subevent);
252 }
253 
254 //_____________________________________________________________________________
255 
257  std::vector<Float_t> trigger_info)
258 {
259  fTriggerType = trigger_type;
260  fTriggerInfo.resize(trigger_info.size());
261  for(size_t i = 0; i < trigger_info.size(); i++)
262  fTriggerInfo[i] = trigger_info[i];
263 }
264 
265 //_____________________________________________________________________________
266 
267 void WCSimRootTrigger::SetPi0Info(Double_t pi0Vtx[3],
268  Int_t gammaID[2],
269  Double_t gammaE[2],
270  Double_t gammaVtx[2][3])
271 {
272  fPi0.Set(pi0Vtx,
273  gammaID,
274  gammaE,
275  gammaVtx);
276 }
277 
278 //_____________________________________________________________________________
279 
280 void WCSimRootPi0::Set(Double_t pi0Vtx[3],
281  Int_t gammaID[2],
282  Double_t gammaE[2],
283  Double_t gammaVtx[2][3])
284 {
285  for (int i=0;i<2;i++)
286  {
287  fGammaID[i] = gammaID[i];
288  fGammaE[i] = gammaE[i];
289  }
290 
291  for (int j=0;j<3;j++)
292  {
293  fPi0Vtx[j] = pi0Vtx[j];
294  fGammaVtx[0][j] = gammaVtx[0][j];
295  fGammaVtx[1][j] = gammaVtx[1][j];
296  }
297 }
298 
299 //_____________________________________________________________________________
300 
302  Int_t flag,
303  Double_t m,
304  Double_t p,
305  Double_t E,
306  Int_t startvol,
307  Int_t stopvol,
308  Double_t dir[3],
309  Double_t pdir[3],
310  Double_t stop[3],
311  Double_t start[3],
312  Int_t parenttype,
313  Double_t time,
314  Int_t id)
315 {
316  // Add a new WCSimRootTrack to the list of tracks for this event.
317  // To avoid calling the very time consuming operator new for each track,
318  // the standard but not well know C++ operator "new with placement"
319  // is called. If tracks[i] is 0, a new Track object will be created
320  // otherwise the previous Track[i] will be overwritten.
321 
322  TClonesArray &tracks = *fTracks;
323  WCSimRootTrack *track =
324  new(tracks[fNtrack_slots++]) WCSimRootTrack(ipnu,
325  flag,
326  m,
327  p,
328  E,
329  startvol,
330  stopvol,
331  dir,
332  pdir,
333  stop,
334  start,
335  parenttype,
336  time,id);
337  fNtrack++;
338  return track;
339 }
340 
341 //_____________________________________________________________________________
342 
344 {
345  // Add a new WCSimRootTrack to the list of tracks for this event.
346  // To avoid calling the very time consuming operator new for each track,
347  // the standard but not well know C++ operator "new with placement"
348  // is called. If tracks[i] is 0, a new Track object will be created
349  // otherwise the previous Track[i] will be overwritten.
350 
351  Double_t dir[3], pdir[3], stop[3], start[3];
352  for(int i = 0; i < 3; i++) {
353  dir [i] = track->GetDir(i);
354  pdir [i] = track->GetPdir(i);
355  stop [i] = track->GetStop(i);
356  start[i] = track->GetStart(i);
357  }//i
358  TClonesArray &tracks = *fTracks;
359  WCSimRootTrack *track_out =
360  new(tracks[fNtrack_slots++]) WCSimRootTrack(track->GetIpnu(),
361  track->GetFlag(),
362  track->GetM(),
363  track->GetP(),
364  track->GetE(),
365  track->GetStartvol(),
366  track->GetStopvol(),
367  dir,
368  pdir,
369  stop,
370  start,
371  track->GetParenttype(),
372  track->GetTime(),
373  track->GetId());
374  fNtrack++;
375  return track_out;
376 }
377 
378 //_____________________________________________________________________________
379 
381 {
382  WCSimRootTrack * tmp = (WCSimRootTrack *)fTracks->Remove(track);
383  if(tmp)
384  fNtrack--;
385  return tmp;
386 }
387 
388 //_____________________________________________________________________________
389 
391  Int_t flag,
392  Double_t m,
393  Double_t p,
394  Double_t E,
395  Int_t startvol,
396  Int_t stopvol,
397  Double_t dir[3],
398  Double_t pdir[3],
399  Double_t stop[3],
400  Double_t start[3],
401  Int_t parenttype,
402  Double_t time,Int_t id)
403 {
404 
405  // Create a WCSimRootTrack object and fill it with stuff
406 
407  fIpnu = ipnu;
408  fFlag = flag;
409  fM = m;
410  fP = p;
411  fE = E;
412  fStartvol = startvol;
413  fStopvol = stopvol;
414  int i;
415  for (i=0;i<3;i++)
416  {
417  fDir[i] = dir[i];
418  fPdir[i] = pdir[i];
419  fStop[i] = stop[i];
420  fStart[i] = start[i];
421  }
422  fParenttype = parenttype;
423  fTime = time;
424  fId = id;
425 }
426 
427 //_____________________________________________________________________________
428 
429 WCSimRootCherenkovHit *WCSimRootTrigger::AddCherenkovHit(Int_t tubeID,std::vector<Double_t> truetime,std::vector<Int_t> primParID)
430 {
431  // Add a new Cherenkov hit to the list of Cherenkov hits
432  TClonesArray &cherenkovhittimes = *fCherenkovHitTimes;
433 
434  for (unsigned int i =0;i<truetime.size();i++)
435  {
437 
438  //WCSimRootCherenkovHitTime *cherenkovhittime =
439  new(cherenkovhittimes[fNcherenkovhittimes++]) WCSimRootCherenkovHitTime(truetime[i],primParID[i]);
440  }
441 
442  Int_t WC_Index[2];
443  WC_Index[0] = fNcherenkovhittimes-truetime.size(); //fCherenkovHitCounter-truetime.size();
444  WC_Index[1] = truetime.size();
445 
446  TClonesArray &cherenkovhits = *fCherenkovHits;
447 
448  WCSimRootCherenkovHit *cherenkovhit
449  = new(cherenkovhits[fNcherenkovhits++]) WCSimRootCherenkovHit(tubeID,
450  WC_Index);
451 
452  return cherenkovhit;
453 }
454 //_____________________________________________________________________________
455 
457  Int_t totalPe[2])
458 {
459  // Create a WCSimRootCherenkovHitIndex object and fill it with stuff
460 
461  fTubeID = tubeID;
462  fTotalPe[0] = totalPe[0];
463  fTotalPe[1] = totalPe[1];
464 }
465 
467  Int_t primParID)
468 {
469  // Create a WCSimRootCherenkovHit object and fill it with stuff
470  fTruetime = truetime;
471  fPrimaryParentID = primParID;
472 }
473 
474 //_____________________________________________________________________________
475 
477  Double_t t,
478  Int_t tubeid,
479  std::vector<int> photon_ids)
480 {
481  // Add a new digitized hit to the list of digitized hits
482  TClonesArray &cherenkovdigihits = *fCherenkovDigiHits;
483  WCSimRootCherenkovDigiHit *cherenkovdigihit =
484  new(cherenkovdigihits[fNcherenkovdigihits_slots++]) WCSimRootCherenkovDigiHit(q,
485  t,
486  tubeid,
487  photon_ids);
489 
490  return cherenkovdigihit;
491 }
492 
493 //_____________________________________________________________________________
494 
496 {
497  // Add a new digitized hit to the list of digitized hits
498  TClonesArray &cherenkovdigihits = *fCherenkovDigiHits;
499  WCSimRootCherenkovDigiHit *cherenkovdigihit =
500  new(cherenkovdigihits[fNcherenkovdigihits_slots++]) WCSimRootCherenkovDigiHit(
501  digit->GetQ(),
502  digit->GetT(),
503  digit->GetTubeId(),
504  digit->GetPhotonIds());
505 
507 
508  return cherenkovdigihit;
509 }
510 
511 //_____________________________________________________________________________
512 
514  Double_t t,
515  Int_t tubeid,
516  std::vector<int> photon_ids)
517 {
518  // Create a WCSimRootCherenkovDigiHit object and fill it with stuff
519 
520  fQ = q;
521  fT = t;
522  fTubeId = tubeid;
523  fPhotonIds = photon_ids;
524 }
525 
526 //_____________________________________________________________________________
527 
529 {
531  if(tmp)
533  return tmp;
534 }
535 
536 
537 //_____________________________________________________________________________
538 
539 // M Fechner, august 2006
540 
542 {
543  // default constructor : nothing happens
544  //fEventList.push_back(new WCSimRootTrigger() ); //at least one event
545  // this is standard root practise for streaming ROOT objtecs : if memory is alloc'ed here,
546  // it will be lost
547  fEventList = 0;
548  Current = 0;
549 }
550 
552 {
553  if (this == &in) return *this;
554  this->Clear();
555  Current = in.Current;
556  fEventList = (TClonesArray*)in.fEventList->Clone();
557  return *this;
558 }
559 
561 {
562  fEventList = new TObjArray(10,0); // very rarely more than 10 subevents...
563  fEventList->AddAt(new WCSimRootTrigger(0,0),0);
564  Current = 0;
565 }
566 
567 
569 {
570  if (fEventList != 0) {
571  for (int i = 0 ; i < fEventList->GetEntriesFast() ; i++) {
572  delete (*fEventList)[i];
573  }
574  delete fEventList;
575  }
576  // std::vector<WCSimRootTrigger*>::iterator iter = fEventList.begin();
577  //for ( ; iter != fEventList.end() ; ++iter) delete (*iter);
578  //Clear("");
579 }
580 
581 void WCSimRootEvent::Clear(Option_t* /*o*/)
582 {
583  //nothing for now
584 }
585 
586 void WCSimRootEvent::Reset(Option_t* /*o*/)
587 {
588  //nothing for now
589 }
590 
591 
592 
593 
594 //
595 //COMPARISON OPERATORS
596 //
597 //_____________________________________________________________________________
599 {
600  bool failed = false;
601  failed = (!ComparisonPassed(fIpnu, c->GetIpnu(), typeid(*this).name(), __func__, "Ipnu")) || failed;
602  failed = (!ComparisonPassed(fFlag, c->GetFlag(), typeid(*this).name(), __func__, "Flag")) || failed;
603  failed = (!ComparisonPassed(fM, c->GetM(), typeid(*this).name(), __func__, "M")) || failed;
604  failed = (!ComparisonPassed(fP, c->GetP(), typeid(*this).name(), __func__, "P")) || failed;
605  failed = (!ComparisonPassed(fE, c->GetE(), typeid(*this).name(), __func__, "E")) || failed;
606  failed = (!ComparisonPassed(fStartvol, c->GetStartvol(), typeid(*this).name(), __func__, "Startvol")) || failed;
607  failed = (!ComparisonPassed(fStopvol, c->GetStopvol(), typeid(*this).name(), __func__, "Stopvol")) || failed;
608  for(int i = 0; i < 3; i++) {
609  failed = (!ComparisonPassed(fDir[i], c->GetDir(i), typeid(*this).name(), __func__, TString::Format("%s[%d]", "Dir", i))) || failed;
610  }//i
611  for(int i = 0; i < 3; i++) {
612  failed = (!ComparisonPassed(fPdir[i], c->GetPdir(i), typeid(*this).name(), __func__, TString::Format("%s[%d]", "Pdir", i))) || failed;
613  }//i
614  for(int i = 0; i < 3; i++) {
615  failed = (!ComparisonPassed(fStop[i], c->GetStop(i), typeid(*this).name(), __func__, TString::Format("%s[%d]", "Stop", i))) || failed;
616  }//i
617  for(int i = 0; i < 3; i++) {
618  failed = (!ComparisonPassed(fStart[i], c->GetStart(i), typeid(*this).name(), __func__, TString::Format("%s[%d]", "Start", i))) || failed;
619  }//i
620  failed = (!ComparisonPassed(fParenttype, c->GetParenttype(), typeid(*this).name(), __func__, "Parenttype")) || failed;
621  failed = (!ComparisonPassed(fTime, c->GetTime(), typeid(*this).name(), __func__, "Time")) || failed;
622  failed = (!ComparisonPassed(fId, c->GetId(), typeid(*this).name(), __func__, "Id")) || failed;
623 
624  return !failed;
625 }
626 
627 //_____________________________________________________________________________
629 {
630  bool failed = false;
631 
632  failed = (!ComparisonPassed(fTubeID, c->GetTubeID(), typeid(*this).name(), __func__, "TubeID")) || failed;
633  for(int i = 0; i < 2; i++) {
634  failed = (!ComparisonPassed(fTotalPe[i], c->GetTotalPe(i), typeid(*this).name(), __func__, TString::Format("%s[%d]", "TotalPe", i))) || failed;
635  }//i
636 
637  return !failed;
638 }
639 
640 //_____________________________________________________________________________
642 {
643  bool failed = false;
644 
645  failed = (!ComparisonPassed(fTruetime, c->GetTruetime(), typeid(*this).name(), __func__, "Truetime")) || failed;
646  failed = (!ComparisonPassed(fPrimaryParentID, c->GetParentID(), typeid(*this).name(), __func__, "PrimaryParentID")) || failed;
647 
648  return !failed;
649 }
650 
651 //_____________________________________________________________________________
653 {
654  bool failed = false;
655 
656  failed = (!ComparisonPassed(fQ, c->GetQ(), typeid(*this).name(), __func__, "Q")) || failed;
657  failed = (!ComparisonPassed(fT, c->GetT(), typeid(*this).name(), __func__, "T")) || failed;
658  failed = (!ComparisonPassed(fTubeId, c->GetTubeId(), typeid(*this).name(), __func__, "TubeId")) || failed;
659  failed = (!ComparisonPassedVec(fPhotonIds, c->GetPhotonIds(), typeid(*this).name(), __func__, "PhotonIds")) || failed;
660 
661  return !failed;
662 }
663 
664 //_____________________________________________________________________________
666 {
667  bool failed = false;
668 
669  failed = (!ComparisonPassed(fEvtNum, c->GetEvtNum(), typeid(*this).name(), __func__, "EvtNum")) || failed;
670  failed = (!ComparisonPassed(fRun, c->GetRun(), typeid(*this).name(), __func__, "Run")) || failed;
671  failed = (!ComparisonPassed(fDate, c->GetDate(), typeid(*this).name(), __func__, "Date")) || failed;
672  failed = (!ComparisonPassed(fSubEvtNumber, c->GetSubEvtNumber(), typeid(*this).name(), __func__, "SubEvtNumber")) || failed;
673 
674  return !failed;
675 }
676 
677 //_____________________________________________________________________________
679 {
680  bool failed = false;
681 
682  for(int i = 0; i < 3; i++) {
683  failed = (!ComparisonPassed(fPi0Vtx[i], c->GetPi0Vtx(i), typeid(*this).name(), __func__, TString::Format("%s[%d]", "Pi0Vtx", i))) || failed;
684  }//i
685  for(int i = 0; i < 2; i++) {
686  failed = (!ComparisonPassed(fGammaID[i], c->GetGammaID(i), typeid(*this).name(), __func__, TString::Format("%s[%d]", "GammaID", i))) || failed;
687  }//i
688  for(int i = 0; i < 2; i++) {
689  failed = (!ComparisonPassed(fGammaE[i], c->GetGammaE(i), typeid(*this).name(), __func__, TString::Format("%s[%d]", "GammaE", i))) || failed;
690  }//i
691  for(int i = 0; i < 2; i++) {
692  for(int j = 0; j < 3; j++) {
693  failed = (!ComparisonPassed(fGammaVtx[i][j], c->GetGammaVtx(i, j), typeid(*this).name(), __func__, TString::Format("%s[%d][%d]", "GammaVtx", i, j))) || failed;
694  }//j
695  }//i
696 
697  return !failed;
698 }
699 
700 //_____________________________________________________________________________
701 bool WCSimRootTrigger::CompareAllVariables(const WCSimRootTrigger * c, bool deep_comparison) const
702 {
703  bool failed = false;
704 
705  failed = !(fEvtHdr.CompareAllVariables(c->GetHeader() )) || failed;
706  failed = !(fPi0 .CompareAllVariables(c->GetPi0Info())) || failed;
707 
708  //
709  //Check the totals of the arrays of tracks/hits/hittimes/digits
710  //
711  if(this->GetTracks()->GetEntries() != c->GetTracks()->GetEntries()) {
712  cerr << "WCSimRootTrigger::CompareAllVariables() Different number of tracks: " << this->GetTracks()->GetEntries() << ", " << c->GetTracks()->GetEntries() << endl;
713  failed = true;
714  }
715  if(this->GetCherenkovHits()->GetEntries() != c->GetCherenkovHits()->GetEntries()) {
716  cerr << "WCSimRootTrigger::CompareAllVariables() Different number of Cherenkov hits: " << this->GetCherenkovHits()->GetEntries() << ", " << c->GetCherenkovHits()->GetEntries() << endl;
717  failed = true;
718  }
719  if(this->GetCherenkovHitTimes()->GetEntries() != c->GetCherenkovHitTimes()->GetEntries()) {
720  cerr << "WCSimRootTrigger::CompareAllVariables() Different number of Cherenkov hit times: " << this->GetCherenkovHitTimes()->GetEntries() << ", " << c->GetCherenkovHitTimes()->GetEntries() << endl;
721  failed = true;
722  }
723  if(this->GetCherenkovDigiHits()->GetEntries() != c->GetCherenkovDigiHits()->GetEntries()) {
724  cerr << "WCSimRootTrigger::CompareAllVariables() Different number of Cherenkov digi hits: " << this->GetCherenkovDigiHits()->GetEntries() << ", " << c->GetCherenkovDigiHits()->GetEntries() << endl;
725  failed = true;
726  }
727 
728  //check tracks
729  // this is more complicated because there can be some empty slots for at least one of the TClonesArray
730  int ithis = -1, ithat = -1;
731  WCSimRootTrack * tmp_track_1, * tmp_track_2;
732  int ncomp_track = 0;
733  while(true) {
734  tmp_track_1 = 0;
735  while(!tmp_track_1 && ithis < this->GetNtrack_slots() - 1) {
736  ithis++;
737  tmp_track_1 = (WCSimRootTrack *)this->GetTracks()->At(ithis);
738  }
739  tmp_track_2 = 0;
740  while(!tmp_track_2 && ithat < c->GetNtrack_slots() - 1) {
741  ithat++;
742  tmp_track_2 = (WCSimRootTrack *)c->GetTracks()->At(ithat);
743  }
744  if(!tmp_track_1 || !tmp_track_2)
745  break;
746 #ifdef VERBOSE_COMPARISON
747  cout << "Comparing track " << ithis " in this with track"
748  << ithat " in that" << endl;
749 #endif
750  failed = !(tmp_track_1->CompareAllVariables(tmp_track_2)) || failed;
751  ncomp_track++;
752  }//ithis ithat
753  if(ncomp_track != fNtrack && ncomp_track != c->GetNtrack()) {
754  cerr << "Only compared " << ncomp_track << " tracks. There should be " << TMath::Min(fNtrack, c->GetNtrack()) << " comparisons" << endl;
755  }
756 
757  //check hits & hit times
758  for(int i = 0; i < TMath::Min(this->GetCherenkovHits()->GetEntries(), c->GetCherenkovHits()->GetEntries()); i++) {
759 #ifdef VERBOSE_COMPARISON
760  cout << "Hit " << i << endl;
761 #endif
762  bool thisfailed = !((WCSimRootCherenkovHit *)this->GetCherenkovHits()->At(i))->CompareAllVariables((WCSimRootCherenkovHit *)c->GetCherenkovHits()->At(i));
763  failed = thisfailed || failed;
764 
765  if(!thisfailed) {
766  //"hit" compared, now check the "hit times" for the same PMT
767  int timepos = ((WCSimRootCherenkovHit *)this->GetCherenkovHits()->At(i))->GetTotalPe(0);
768  int totalpe = ((WCSimRootCherenkovHit *)this->GetCherenkovHits()->At(i))->GetTotalPe(1);
769  for(int j = timepos; j < timepos + totalpe; j++) {
770 #ifdef VERBOSE_COMPARISON
771  cout << "Hit Time " << j << endl;
772 #endif
774  }//j (WCSimRootCherenkovHitTime)
775  }
776  }//i (WCSimRootCherenkovHit)
777 
778  //check digitised hits
779  // this is more complicated because there can be some empty slots for at least one of the TClonesArray
780  // also, digits can potentially be in different orders
781  ithis = -1, ithat = -1;
782  WCSimRootCherenkovDigiHit * tmp_digit_1, * tmp_digit_2;
783  int ncomp_digi = 0;
784  bool failed_digits = false;
785  while(true) {
786  tmp_digit_1 = 0;
787  while(!tmp_digit_1 && ithis < this->GetNcherenkovdigihits_slots() - 1) {
788  ithis++;
789  tmp_digit_1 = (WCSimRootCherenkovDigiHit *)this->GetCherenkovDigiHits()->At(ithis);
790  }
791  tmp_digit_2 = 0;
792  while(!tmp_digit_2 && ithat < c->GetNcherenkovdigihits_slots() - 1) {
793  ithat++;
794  tmp_digit_2 = (WCSimRootCherenkovDigiHit *)c->GetCherenkovDigiHits()->At(ithat);
795  }
796  if(!tmp_digit_1 || !tmp_digit_2)
797  break;
798 #ifdef VERBOSE_COMPARISON
799  cout << "Comparing digit " << ithis " in this with digit"
800  << ithat " in that" << endl;
801 #endif
802  failed_digits = !(tmp_digit_1->CompareAllVariables(tmp_digit_2)) || failed_digits;
803  ncomp_digi++;
804  }//while(true)
805  if(ncomp_digi != fNcherenkovdigihits && ncomp_digi != c->GetNcherenkovdigihits()) {
806  cerr << "Only compared " << ncomp_digi << " digits. There should be " << TMath::Min(fNcherenkovdigihits, c->GetNcherenkovdigihits()) << " comparisons" << endl;
807  }
808  if(!deep_comparison)
809  failed = failed || failed_digits;
810  else if(failed_digits) {
811  cout << "Peforming deep comparison" << endl;
812  // We're running a deep comparison and we have some failed digits.
813  // We're therefore going to do the check under the assumption that the order of digits can be different between this and that
814  vector<WCSimRootCherenkovDigiHit *> tmpdigis;
815  for(ithis = 0; ithis < this->GetNcherenkovdigihits_slots() - 1; ithis++) {
816  tmp_digit_1 = (WCSimRootCherenkovDigiHit *)this->GetCherenkovDigiHits()->At(ithis);
817  if(!tmp_digit_1)
818  continue;
819  int this_pmtid = tmp_digit_1->GetTubeId();
820  for(ithat = 0; ithat < c->GetNcherenkovdigihits_slots() - 1; ithat++) {
821  tmp_digit_2 = (WCSimRootCherenkovDigiHit *)c->GetCherenkovDigiHits()->At(ithat);
822  if(!tmp_digit_2)
823  continue;
824  if(tmp_digit_2->GetTubeId() != this_pmtid) {
825  continue;
826  }
827  tmpdigis.push_back(tmp_digit_2);
828  }//ithat
829  //we've now got a single digit from this, and all the digits on the same PMT from that
830  if(!tmpdigis.size()) {
831  cerr << "No digits on this PMT with ID " << this_pmtid << " found on that" << endl;
832  failed = true;
833  }
834  bool found = false;
835  for(unsigned int i = 0; i < tmpdigis.size(); i++) {
836  found = tmp_digit_1->CompareAllVariables(tmpdigis.at(i));
837  if(found)
838  break;
839  }
840  if(!found)
841  failed = true;
842  tmpdigis.clear();
843  }//ithis
844  }//failed_digits && deep_comparison
845 
846  failed = (!ComparisonPassed(fMode[0], c->GetMode(), typeid(*this).name(), __func__, "Mode")) || failed;
847  failed = (!ComparisonPassed(fNvtxs, c->GetNvtxs(), typeid(*this).name(), __func__, "Nvtxs")) || failed;
848  for(int ivtx = 0; ivtx < fNvtxs; ivtx++) {
849  failed = (!ComparisonPassed(fVtxsvol[ivtx], c->GetVtxsvol(ivtx), typeid(*this).name(), __func__, TString::Format("Vtxvols[%d]", ivtx))) || failed;
850  for(int i = 0; i < 4; i++) {
851  failed = (!ComparisonPassed(fVtxs[ivtx][i], c->GetVtxs(ivtx, i), typeid(*this).name(), __func__, TString::Format("%s[%d][%d]", "Vtxs", ivtx, i))) || failed;
852  }//i
853  }//ivtx
854  failed = (!ComparisonPassed(fVecRecNumber, c->GetVecRecNumber(), typeid(*this).name(), __func__, "VecRecNumber")) || failed;
855  failed = (!ComparisonPassed(fJmu, c->GetJmu(), typeid(*this).name(), __func__, "Jmu")) || failed;
856  failed = (!ComparisonPassed(fJp, c->GetJp(), typeid(*this).name(), __func__, "Jp")) || failed;
857  failed = (!ComparisonPassed(fNpar, c->GetNpar(), typeid(*this).name(), __func__, "Npar")) || failed;
858  failed = (!ComparisonPassed(fNumTubesHit, c->GetNumTubesHit(), typeid(*this).name(), __func__, "NumTubesHit")) || failed;
859  failed = (!ComparisonPassed(fNumDigitizedTubes, c->GetNumDigiTubesHit(), typeid(*this).name(), __func__, "NumDigitizedTubes")) || failed;
860  failed = (!ComparisonPassed(fNtrack, c->GetNtrack(), typeid(*this).name(), __func__, "Ntrack")) || failed;
861  //don't expect this to pass in general, so don't affect failed
862  ComparisonPassed(fNtrack_slots, c->GetNtrack_slots(), typeid(*this).name(), __func__, "Ntrack_slots (shouldn't necessarily be equal)");
863  failed = (!ComparisonPassed(fNcherenkovhits, c->GetNcherenkovhits(), typeid(*this).name(), __func__, "Ncherenkovhits")) || failed;
864  failed = (!ComparisonPassed(fNcherenkovhittimes, c->GetNcherenkovhittimes(), typeid(*this).name(), __func__, "Ncherenkovhittimes")) || failed;
865  failed = (!ComparisonPassed(fNcherenkovdigihits, c->GetNcherenkovdigihits(), typeid(*this).name(), __func__, "Ncherenkovdigihits")) || failed;
866  //don't expect this to pass in general, so don't affect failed
867  ComparisonPassed(fNcherenkovdigihits_slots, c->GetNcherenkovdigihits_slots(), typeid(*this).name(), __func__, "Ncherenkovdigihits_slots (shouldn't necessarily be equal)");
868  failed = (!ComparisonPassed(fSumQ, c->GetSumQ(), typeid(*this).name(), __func__, "SumQ")) || failed;
869  failed = (!ComparisonPassed(fTriggerType, c->GetTriggerType(), typeid(*this).name(), __func__, "TriggerType")) || failed;
870  failed = (!ComparisonPassedVec(fTriggerInfo, c->GetTriggerInfo(), typeid(*this).name(), __func__, "TriggerInfo")) || failed;
871 
872  return !failed;
873 }
874 
875 
876 //_____________________________________________________________________________
877 bool WCSimRootEvent::CompareAllVariables(const WCSimRootEvent * c, bool deep_comparison) const
878 {
879  bool failed = false;
880 
881  if(this->GetNumberOfEvents() != c->GetNumberOfEvents()) {
882  cerr << "WCSimRootEvent::CompareAllVariables() Different number of events: " << this->GetNumberOfEvents() << ", " << c->GetNumberOfEvents() << endl;
883  failed = true;
884  }
885 
886  for(int i = 0; i < TMath::Min(this->GetNumberOfEvents(), c->GetNumberOfEvents()); i++) {
887  failed = !(this->GetTrigger(i)->CompareAllVariables(c->GetTrigger(i), deep_comparison)) || failed;
888  }
889 
890  return !failed;
891 }
892 
893 
894 //_____________________________________________________________________________
895 
896 // LocalWords: GetCherenkovDigiHits
Float_t fGammaE[2]
Int_t GetSubEvtNumber() const
virtual ~WCSimRootEvent()
Int_t GetRun() const
Float_t fPi0Vtx[3]
Float_t GetM() const
Double_t GetTruetime() const
WCSimRootTrigger & operator=(const WCSimRootTrigger &in)
Float_t GetGammaE(int i) const
enum ETriggerType TriggerType_t
Int_t GetEvtNum() const
int64_t GetDate() const
bool ComparisonPassedVec(const vector< int > &val1, const vector< int > &val2, const char *callerclass, const char *callerfunc, const char *tag)
TriggerType_t fTriggerType
Int_t GetGammaID(int i) const
WCSimRootCherenkovHit * AddCherenkovHit(Int_t tubeID, std::vector< Double_t > truetime, std::vector< Int_t > primParID)
Double_t GetTime() const
bool CompareAllVariables(const WCSimRootTrack *c) const
Float_t GetPdir(Int_t i=0) const
Float_t GetPi0Vtx(int i) const
TClonesArray * GetCherenkovHitTimes() const
bool ComparisonPassed(int val1, int val2, const char *callerclass, const char *callerfunc, const char *tag)
WCSimRootEventHeader * GetHeader()
static void Reset(Option_t *option="")
Int_t GetTubeID() const
Int_t GetNcherenkovdigihits() const
TClonesArray * GetCherenkovHits() const
WCSimRootEvent & operator=(const WCSimRootEvent &in)
Float_t GetGammaVtx(int i, int j) const
Int_t GetJmu() const
WCSimRootCherenkovDigiHit * RemoveCherenkovDigiHit(WCSimRootCherenkovDigiHit *digit)
Float_t GetVtxs(Int_t n, Int_t i=0) const
Int_t GetNumTubesHit() const
Float_t fStop[3]
Float_t GetStart(Int_t i=0) const
std::vector< Float_t > GetTriggerInfo() const
bool CompareAllVariables(const WCSimRootCherenkovHitTime *c) const
TClonesArray * fTracks
Float_t fPdir[3]
void Clear(Option_t *option="")
std::vector< Float_t > fTriggerInfo
WCSimRootPi0 * GetPi0Info()
Int_t fNcherenkovdigihits_slots
TClonesArray * GetTracks() const
Int_t GetStartvol() const
WCSimRootCherenkovDigiHit * AddCherenkovDigiHit(Double_t q, Double_t t, Int_t tubeid, std::vector< int > photon_ids)
void Clear(Option_t *option="")
Float_t fVtxs[MAX_N_VERTICES][4]
std::vector< int > GetPhotonIds() const
TClonesArray * fCherenkovDigiHits
bool CompareAllVariables(const WCSimRootPi0 *c) const
Int_t GetVtxsvol(Int_t i) const
bool CompareAllVariables(const WCSimRootEvent *c, bool deep_comparison=false) const
Int_t GetJp() const
void SetTriggerInfo(TriggerType_t trigger_type, std::vector< Float_t > trigger_info)
Int_t GetParenttype() const
Int_t fMode[MAX_N_VERTICES]
std::vector< int > fPhotonIds
void SetPi0Info(Double_t pi0Vtx[3], Int_t gammaID[2], Double_t gammaE[2], Double_t gammaVtx[2][3])
Float_t fGammaVtx[2][3]
Int_t GetMode() const
WCSimRootTrigger * GetTrigger(int number)
Int_t GetNtrack() const
Float_t GetE() const
WCSimRootPi0 fPi0
WCSimRootEventHeader fEvtHdr
Float_t GetStop(Int_t i=0) const
Float_t fDir[3]
Int_t GetNtrack_slots() const
Int_t fGammaID[2]
Int_t GetNumberOfEvents() const
Float_t GetP() const
Int_t GetNpar() const
bool CompareAllVariables(const WCSimRootCherenkovHit *c) const
TClonesArray * fCherenkovHitTimes
static void Reset(Option_t *option="")
WCSimRootTrack * AddTrack(Int_t ipnu, Int_t flag, Double_t m, Double_t p, Double_t E, Int_t startvol, Int_t stopvol, Double_t dir[3], Double_t pdir[3], Double_t stop[3], Double_t start[3], Int_t parenttype, Double_t time, Int_t id)
Int_t GetNcherenkovhits() const
TriggerType_t GetTriggerType() const
TClonesArray * GetCherenkovDigiHits() const
void SetHeader(Int_t i, Int_t run, int64_t date, Int_t subevtn=1)
virtual ~WCSimRootTrigger()
bool CompareAllVariables(const WCSimRootEventHeader *c) const
Float_t GetSumQ() const
void Set(Double_t pi0Vtx[3], Int_t gammaID[2], Double_t gammaE[2], Double_t gammaVtx[2][3])
Int_t GetId() const
Int_t GetFlag() const
Int_t GetIpnu() const
void Set(Int_t i, Int_t r, int64_t d, Int_t s=1)
Int_t GetVecRecNumber() const
bool CompareAllVariables(const WCSimRootCherenkovDigiHit *c) const
static const int MAX_N_VERTICES
Definition: jhfNtuple.h:3
Int_t GetNvtxs() const
Float_t GetDir(Int_t i=0) const
TObjArray * fEventList
TClonesArray * fCherenkovHits
Int_t GetTotalPe(int i) const
bool CompareAllVariables(const WCSimRootTrigger *c, bool deep_comparison=false) const
WCSimRootTrack * RemoveTrack(WCSimRootTrack *track)
Float_t fStart[3]
Int_t GetNcherenkovdigihits_slots() const
Int_t GetNumDigiTubesHit() const
Int_t GetNcherenkovhittimes() const
Int_t fVtxsvol[MAX_N_VERTICES]
Int_t GetStopvol() const