1 | /* ======================================================================== *\
|
---|
2 | !
|
---|
3 | ! *
|
---|
4 | ! * This file is part of CheObs, the Modular Analysis and Reconstruction
|
---|
5 | ! * Software. It is distributed to you in the hope that it can be a useful
|
---|
6 | ! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
|
---|
7 | ! * It is distributed WITHOUT ANY WARRANTY.
|
---|
8 | ! *
|
---|
9 | ! * Permission to use, copy, modify and distribute this software and its
|
---|
10 | ! * documentation for any purpose is hereby granted without fee,
|
---|
11 | ! * provided that the above copyright notice appears in all copies and
|
---|
12 | ! * that both that copyright notice and this permission notice appear
|
---|
13 | ! * in supporting documentation. It is provided "as is" without express
|
---|
14 | ! * or implied warranty.
|
---|
15 | ! *
|
---|
16 | !
|
---|
17 | !
|
---|
18 | ! Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
|
---|
19 | ! Author(s): Qi Zhe, 06/2007 <mailto:qizhe@astro.uni-wuerzburg.de>
|
---|
20 | !
|
---|
21 | ! Copyright: CheObs Software Development, 2000-2009
|
---|
22 | !
|
---|
23 | !
|
---|
24 | \* ======================================================================== */
|
---|
25 |
|
---|
26 | /////////////////////////////////////////////////////////////////////////////
|
---|
27 | //
|
---|
28 | // MPhotonEvent
|
---|
29 | //
|
---|
30 | // Storage container to store photon collections
|
---|
31 | //
|
---|
32 | // The class is designed to be extremely fast which is important taking into
|
---|
33 | // account the extremely high number of photons. This has some impacts on
|
---|
34 | // its handling.
|
---|
35 | //
|
---|
36 | // The list has to be kept consistent, i.e. without holes.
|
---|
37 | //
|
---|
38 | // There are two ways to achieve this:
|
---|
39 | //
|
---|
40 | // a) Use RemoveAt to remove an entry somewhere
|
---|
41 | // b) Compress() the TClonesArray afterwards
|
---|
42 | //
|
---|
43 | // Compress is not the fastes, so there is an easier way.
|
---|
44 | //
|
---|
45 | // a) When you loop over the list and want to remove an entry copy all
|
---|
46 | // following entry backward in the list, so that the hole will
|
---|
47 | // be created at its end.
|
---|
48 | // b) Call Shrink(n) with n the number of valid entries in your list.
|
---|
49 | //
|
---|
50 | // To loop over the TClonesArray you can use a TIter which has some
|
---|
51 | // unnecessary overhead and therefore is slower than necessary.
|
---|
52 | //
|
---|
53 | // Since the list is kept consistent you can use a simple loop saving
|
---|
54 | // a lot of CPU time taking into account the high number of calls to
|
---|
55 | // TObjArrayIter::Next which you would create.
|
---|
56 | //
|
---|
57 | // Here is an example (how to remove every second entry)
|
---|
58 | //
|
---|
59 | // ---------------------------------------------------------------------
|
---|
60 | //
|
---|
61 | // Int_t cnt = 0;
|
---|
62 | //
|
---|
63 | // const Int_t num = event->GetNumPhotons();
|
---|
64 | // for (Int_t idx=0; idx<num; idx++)
|
---|
65 | // {
|
---|
66 | // if (idx%2==0)
|
---|
67 | // continue;
|
---|
68 | //
|
---|
69 | // MPhotonData *dat = (*event)[idx];
|
---|
70 | //
|
---|
71 | // (*event)[cnt++] = *dat;
|
---|
72 | // }
|
---|
73 | //
|
---|
74 | // event->Shrink(cnt);
|
---|
75 | //
|
---|
76 | // ---------------------------------- or -------------------------------
|
---|
77 | //
|
---|
78 | // TClonesArray &arr = MPhotonEvent->GetArray();
|
---|
79 | //
|
---|
80 | // Int_t cnt = 0;
|
---|
81 | //
|
---|
82 | // const Int_t num = arr.GetEntriesFast();
|
---|
83 | // for (Int_t idx=0; idx<num; idx++)
|
---|
84 | // {
|
---|
85 | // if (idx%2==0)
|
---|
86 | // continue;
|
---|
87 | //
|
---|
88 | // MPhotonData *dat = static_cast<MPhotonData*>(arr.UncheckedAt(idx));
|
---|
89 | //
|
---|
90 | // *static_cast<MPhotonData*>(arr.UncheckedAt(cnt++)) = *dat;
|
---|
91 | // }
|
---|
92 | //
|
---|
93 | // MPhotonEvent->Shrink(cnt);
|
---|
94 | //
|
---|
95 | // ---------------------------------------------------------------------
|
---|
96 | //
|
---|
97 | // The flag for a sorted array is for speed reasons not in all conditions
|
---|
98 | // maintained automatically. Especially Add() doesn't reset it.
|
---|
99 | //
|
---|
100 | // So be sure that if you want to sort your array it is really sorted.
|
---|
101 | //
|
---|
102 | //
|
---|
103 | // Version 1:
|
---|
104 | // ----------
|
---|
105 | // - First implementation
|
---|
106 | //
|
---|
107 | /////////////////////////////////////////////////////////////////////////////
|
---|
108 | #include "MPhotonEvent.h"
|
---|
109 |
|
---|
110 | #include <fstream>
|
---|
111 | #include <iostream>
|
---|
112 |
|
---|
113 | #include <TMarker.h>
|
---|
114 |
|
---|
115 | #include <MMath.h>
|
---|
116 |
|
---|
117 | #include "MArrayF.h"
|
---|
118 |
|
---|
119 | #include "MLog.h"
|
---|
120 | #include "MLogManip.h"
|
---|
121 |
|
---|
122 | #include "MPhotonData.h"
|
---|
123 | #include "MCorsikaFormat.h"
|
---|
124 |
|
---|
125 | ClassImp(MPhotonEvent);
|
---|
126 |
|
---|
127 | using namespace std;
|
---|
128 |
|
---|
129 | // ==========================================================================
|
---|
130 |
|
---|
131 | class MyClonesArray : public TClonesArray
|
---|
132 | {
|
---|
133 | public:
|
---|
134 | TObject **FirstRef() { return fCont; }
|
---|
135 |
|
---|
136 | // --------------------------------------------------------------------------
|
---|
137 | //
|
---|
138 | // This is an extremly optimized version of ExpandCreateFast. It only resets
|
---|
139 | // the marker for the last element (fLast) to n-1 and doen't change anything
|
---|
140 | // else. This implicitly assumes that the stored objects don't allocate
|
---|
141 | // memory. It does not necessarily mean that the slots after fLast
|
---|
142 | // are empty (set to 0). This is what is assumed in the TClonesArray.
|
---|
143 | // We also don't call Changed() because it would reset Sorted. If the
|
---|
144 | // array was sorted before it is also sorted now. You MUST make sure
|
---|
145 | // that you only set n in a range for which valid entries have been
|
---|
146 | // created before (e.g. by ExpandCreateFast).
|
---|
147 | //
|
---|
148 | void FastShrink(Int_t n)
|
---|
149 | {
|
---|
150 | fLast = n - 1;
|
---|
151 | }
|
---|
152 |
|
---|
153 | // --------------------------------------------------------------------------
|
---|
154 | //
|
---|
155 | // This is a optimized (faster) version of Delete which deletes consequtive
|
---|
156 | // entries from index idx1 to idx2 (both included) and calls their
|
---|
157 | // destructor. Note that there is no range checking done!
|
---|
158 | //
|
---|
159 | void FastRemove(Int_t idx1, Int_t idx2)
|
---|
160 | {
|
---|
161 | // Remove object at index idx.
|
---|
162 |
|
---|
163 | //if (!BoundsOk("RemoveAt", idx1)) return 0;
|
---|
164 | //if (!BoundsOk("RemoveAt", idx2)) return 0;
|
---|
165 |
|
---|
166 | Long_t dtoronly = TObject::GetDtorOnly();
|
---|
167 |
|
---|
168 | idx1 -= fLowerBound;
|
---|
169 | idx2 -= fLowerBound;
|
---|
170 |
|
---|
171 | for (TObject **obj=fCont+idx1; obj<=fCont+idx2; obj++)
|
---|
172 | {
|
---|
173 | if (!*obj)
|
---|
174 | continue;
|
---|
175 |
|
---|
176 | if ((*obj)->TestBit(kNotDeleted)) {
|
---|
177 | // Tell custom operator delete() not to delete space when
|
---|
178 | // object fCont[i] is deleted. Only destructors are called
|
---|
179 | // for this object.
|
---|
180 | TObject::SetDtorOnly(*obj);
|
---|
181 | delete *obj;
|
---|
182 | }
|
---|
183 |
|
---|
184 | *obj = 0;
|
---|
185 | // recalculate array size
|
---|
186 | }
|
---|
187 | TObject::SetDtorOnly((void*)dtoronly);
|
---|
188 |
|
---|
189 | if (idx1<=fLast && fLast<=idx2)
|
---|
190 | {
|
---|
191 | do {
|
---|
192 | fLast--;
|
---|
193 | } while (fLast >= 0 && fCont[fLast] == 0);
|
---|
194 | }
|
---|
195 |
|
---|
196 | Changed();
|
---|
197 | }
|
---|
198 |
|
---|
199 |
|
---|
200 | //void SetSorted() { fSorted = kTRUE; }
|
---|
201 |
|
---|
202 | // --------------------------------------------------------------------------
|
---|
203 | //
|
---|
204 | // This is an optimized version of Sort which doesn't check the
|
---|
205 | // IsSortable flag before. It only sorts the entries from 0
|
---|
206 | // to GetEntriesFast().
|
---|
207 | //
|
---|
208 | void UncheckedSort()
|
---|
209 | {
|
---|
210 | if (fSorted)
|
---|
211 | return;
|
---|
212 |
|
---|
213 | const Int_t nentries = GetEntriesFast();
|
---|
214 | if (nentries <= 0)
|
---|
215 | return;
|
---|
216 |
|
---|
217 | QSort(GetObjectRef(First()), fKeep->GetObjectRef(fKeep->First()),
|
---|
218 | 0, TMath::Min(nentries, kMaxInt-fLowerBound));
|
---|
219 |
|
---|
220 | fSorted = kTRUE;
|
---|
221 | }
|
---|
222 | };
|
---|
223 |
|
---|
224 | // ==========================================================================
|
---|
225 |
|
---|
226 | // --------------------------------------------------------------------------
|
---|
227 | //
|
---|
228 | // Default constructor. It initializes all arrays with zero size.
|
---|
229 | //
|
---|
230 | MPhotonEvent::MPhotonEvent(const char *name, const char *title)
|
---|
231 | : fData("MPhotonData", 1)
|
---|
232 | {
|
---|
233 | fName = name ? name : "MPhotonEvent";
|
---|
234 | fTitle = title ? title : "Corsika Event Data Information";
|
---|
235 |
|
---|
236 | fData.SetBit(TClonesArray::kForgetBits);
|
---|
237 | fData.BypassStreamer(kFALSE);
|
---|
238 | }
|
---|
239 |
|
---|
240 | // --------------------------------------------------------------------------
|
---|
241 | //
|
---|
242 | // This is an extremly optimized version of ExpandCreateFast. It only resets
|
---|
243 | // the marker for the last element (fLast) to n-1 and doen't change anything
|
---|
244 | // else. This has the advantage that the allocated memory is kept but only
|
---|
245 | // valid entries are written to a file.
|
---|
246 | //
|
---|
247 | // If the array was sorted before it is also sorted now. You MUST make sure
|
---|
248 | // that you only set n in a range for which valid entries have been
|
---|
249 | // created before (e.g. by ExpandCreateFast).
|
---|
250 | //
|
---|
251 | Int_t MPhotonEvent::Shrink(Int_t n)
|
---|
252 | {
|
---|
253 | /*
|
---|
254 | // The number of object written by the streamer is defined by
|
---|
255 | // GetEntriesFast(), i.e. this number must be shrinked to
|
---|
256 | // the real array size. We use RemoveAt instead of ExpandCreate
|
---|
257 | // because RemoveAt doesn't free memory. Thus in the next
|
---|
258 | // iteration it can be reused and doesn't need to be reallocated.
|
---|
259 | // Do not change this. It is optimized for execution speed
|
---|
260 | // for (int i=fData.GetSize()-1; i>=n; i--)
|
---|
261 | // fData.RemoveAt(i);
|
---|
262 | const Bool_t sorted = fData.IsSorted();
|
---|
263 |
|
---|
264 | MyClonesArray &loc = static_cast<MyClonesArray&>(fData);
|
---|
265 |
|
---|
266 | loc.FastRemove(n, fData.GetSize()-1);
|
---|
267 |
|
---|
268 | // If it was sorted before it is also sorted now.
|
---|
269 | if (sorted)
|
---|
270 | loc.SetSorted();
|
---|
271 | */
|
---|
272 |
|
---|
273 | // fData.ExpandCreateFast(n); // Just set fLast = n -1
|
---|
274 |
|
---|
275 | // Just set fLast = n -1
|
---|
276 | static_cast<MyClonesArray&>(fData).FastShrink(n);
|
---|
277 | return fData.GetEntriesFast();
|
---|
278 | }
|
---|
279 |
|
---|
280 | // --------------------------------------------------------------------------
|
---|
281 | //
|
---|
282 | // The resized the array. If it has to be increased in size it is done
|
---|
283 | // with ExpandCreateFast. If it should be shrinked it is done with
|
---|
284 | // ExpandCreateFast if n>fData.GetSize()/100 or n==0. This keeps the allocated
|
---|
285 | // memory and just sets the marker for the last element in the array (fLast).
|
---|
286 | //
|
---|
287 | // If the allocated memory grew to huge we reset the allocated memory
|
---|
288 | // by calling ExpandCreate(n) (frees the allocated storage for the
|
---|
289 | // objects) and Expand(n) (frees the allocated memory for the list
|
---|
290 | // of pointers to the objects)
|
---|
291 | //
|
---|
292 | // 100 hundred is an arbitrary number taking into account that todays
|
---|
293 | // computers have a lot of memory and we don't want to free and allocate
|
---|
294 | // new memory too often.
|
---|
295 | //
|
---|
296 | // In priciple there might be more clever methods to handle the memory.
|
---|
297 | //
|
---|
298 | void MPhotonEvent::Resize(Int_t n)
|
---|
299 | {
|
---|
300 | if (n==0 || n*100>fData.GetSize())
|
---|
301 | fData.ExpandCreateFast(n); // Just set fLast = n -1
|
---|
302 | else
|
---|
303 | {
|
---|
304 | fData.ExpandCreate(n); // Free memory of allocated MPhotonData
|
---|
305 | fData.Expand(n); // Free memory of allocated pointers
|
---|
306 | }
|
---|
307 | }
|
---|
308 |
|
---|
309 | // --------------------------------------------------------------------------
|
---|
310 | //
|
---|
311 | // If n is smaller than the current allocated array size a reference to
|
---|
312 | // the n-th entry is returned, otherwise an entry at n is created
|
---|
313 | // calling the default constructor. Note, that there is no range check
|
---|
314 | // but it is not recommended to call this function with
|
---|
315 | // n>fData.GetSize()
|
---|
316 | //
|
---|
317 | MPhotonData &MPhotonEvent::Add(Int_t n)
|
---|
318 | {
|
---|
319 | // Do not modify this. It is optimized for execution
|
---|
320 | // speed and flexibility!
|
---|
321 | TObject *o = 0;
|
---|
322 | if (n<fData.GetSize() && fData.UncheckedAt(n))
|
---|
323 | {
|
---|
324 | o=fData.UncheckedAt(n);
|
---|
325 | static_cast<MyClonesArray&>(fData).FastShrink(n+1);
|
---|
326 | }
|
---|
327 | else
|
---|
328 | {
|
---|
329 | o=fData.New(n);
|
---|
330 | }
|
---|
331 | return static_cast<MPhotonData&>(*o);
|
---|
332 | }
|
---|
333 |
|
---|
334 | // --------------------------------------------------------------------------
|
---|
335 | //
|
---|
336 | // Add a new photon (MPhtonData) at the end of the array.
|
---|
337 | // In this case the default constructor of MPhotonData is called.
|
---|
338 | //
|
---|
339 | // A reference to the new object is returned.
|
---|
340 | //
|
---|
341 | MPhotonData &MPhotonEvent::Add()
|
---|
342 | {
|
---|
343 | return Add(GetNumPhotons());
|
---|
344 | }
|
---|
345 |
|
---|
346 | void MPhotonEvent::Sort(Bool_t force)
|
---|
347 | {
|
---|
348 | if (force)
|
---|
349 | fData.UnSort();
|
---|
350 |
|
---|
351 | static_cast<MyClonesArray&>(fData).UncheckedSort(); /*Sort(GetEntriesFast())*/
|
---|
352 | }
|
---|
353 |
|
---|
354 | // --------------------------------------------------------------------------
|
---|
355 | //
|
---|
356 | // Get the i-th photon from the array. Not, for speed reasons there is no
|
---|
357 | // range check so you are responsible that you do not excess the number
|
---|
358 | // of photons (GetNumPhotons)
|
---|
359 | //
|
---|
360 | MPhotonData &MPhotonEvent::operator[](UInt_t idx)
|
---|
361 | {
|
---|
362 | return *static_cast<MPhotonData*>(fData.UncheckedAt(idx));
|
---|
363 | }
|
---|
364 |
|
---|
365 | // --------------------------------------------------------------------------
|
---|
366 | //
|
---|
367 | // Get the i-th photon from the array. Not, for speed reasons there is no
|
---|
368 | // range check so you are responsible that you do not excess the number
|
---|
369 | // of photons (GetNumPhotons)
|
---|
370 | //
|
---|
371 | const MPhotonData &MPhotonEvent::operator[](UInt_t idx) const
|
---|
372 | {
|
---|
373 | return *static_cast<MPhotonData*>(fData.UncheckedAt(idx));
|
---|
374 | }
|
---|
375 |
|
---|
376 | // --------------------------------------------------------------------------
|
---|
377 | //
|
---|
378 | // Return a pointer to the first photon if available.
|
---|
379 | //
|
---|
380 | MPhotonData *MPhotonEvent::GetFirst() const
|
---|
381 | {
|
---|
382 | return fData.GetEntriesFast()==0 ? 0 : static_cast<MPhotonData*>(fData.First());
|
---|
383 | }
|
---|
384 |
|
---|
385 | // --------------------------------------------------------------------------
|
---|
386 | //
|
---|
387 | // Return a pointer to the last photon if available.
|
---|
388 | //
|
---|
389 | MPhotonData *MPhotonEvent::GetLast() const
|
---|
390 | {
|
---|
391 | return fData.GetEntriesFast()==0 ? 0 : static_cast<MPhotonData*>(fData.Last());
|
---|
392 | }
|
---|
393 |
|
---|
394 | // --------------------------------------------------------------------------
|
---|
395 | //
|
---|
396 | // Return the number of "external" photons, i.e. which are not NightSky
|
---|
397 | //
|
---|
398 | Int_t MPhotonEvent::GetNumExternal() const
|
---|
399 | {
|
---|
400 | Int_t n=0;
|
---|
401 |
|
---|
402 | for (int i=0; i<GetNumPhotons(); i++)
|
---|
403 | if ((*this)[i].GetPrimary()!=MMcEvtBasic::kNightSky)
|
---|
404 | n++;
|
---|
405 |
|
---|
406 | return n;
|
---|
407 | }
|
---|
408 |
|
---|
409 | // --------------------------------------------------------------------------
|
---|
410 | //
|
---|
411 | // Return time of first photon, 0 if none in array.
|
---|
412 | // Note: If you want this to be the earliest make sure that the array
|
---|
413 | // is properly sorted.
|
---|
414 | //
|
---|
415 | Float_t MPhotonEvent::GetTimeFirst() const
|
---|
416 | {
|
---|
417 | const MPhotonData *dat=GetFirst();
|
---|
418 | return dat ? dat->GetTime() : 0;
|
---|
419 | }
|
---|
420 |
|
---|
421 | // --------------------------------------------------------------------------
|
---|
422 | //
|
---|
423 | // Return time of first photon, 0 if none in array.
|
---|
424 | // Note: If you want this to be the latest make sure that the array
|
---|
425 | // is properly sorted.
|
---|
426 | //
|
---|
427 | Float_t MPhotonEvent::GetTimeLast() const
|
---|
428 | {
|
---|
429 | const MPhotonData *dat=GetLast();
|
---|
430 | return dat ? dat->GetTime() : 0;
|
---|
431 | }
|
---|
432 |
|
---|
433 | // --------------------------------------------------------------------------
|
---|
434 | //
|
---|
435 | // Return the median devian from the median of all arrival times.
|
---|
436 | // The median deviation is calculated using MMath::MedianDev.
|
---|
437 | // It is the half width in which one sigma (~68%) of all times are
|
---|
438 | // contained around the median.
|
---|
439 | //
|
---|
440 | Double_t MPhotonEvent::GetTimeMedianDev() const
|
---|
441 | {
|
---|
442 | const UInt_t n = GetNumPhotons();
|
---|
443 |
|
---|
444 | MArrayF arr(n);
|
---|
445 | for (UInt_t i=0; i<n; i++)
|
---|
446 | arr[i] = operator[](i).GetTime();
|
---|
447 |
|
---|
448 | return MMath::MedianDev(n, arr.GetArray()/*, Double_t &med*/);
|
---|
449 | }
|
---|
450 |
|
---|
451 | Double_t MPhotonEvent::GetMeanX() const
|
---|
452 | {
|
---|
453 | const UInt_t n = GetNumPhotons();
|
---|
454 |
|
---|
455 | Double_t mean = 0;
|
---|
456 | for (UInt_t i=0; i<n; i++)
|
---|
457 | mean += operator[](i).GetPosX();
|
---|
458 |
|
---|
459 | return mean / n;
|
---|
460 | }
|
---|
461 |
|
---|
462 | Double_t MPhotonEvent::GetMeanY() const
|
---|
463 | {
|
---|
464 | const UInt_t n = GetNumPhotons();
|
---|
465 |
|
---|
466 | Double_t mean = 0;
|
---|
467 | for (UInt_t i=0; i<n; i++)
|
---|
468 | mean += operator[](i).GetPosY();
|
---|
469 |
|
---|
470 | return mean / n;
|
---|
471 | }
|
---|
472 |
|
---|
473 | // --------------------------------------------------------------------------
|
---|
474 | //
|
---|
475 | // Read the Event section from the file
|
---|
476 | //
|
---|
477 | Int_t MPhotonEvent::ReadCorsikaEvt(MCorsikaFormat *fInFormat, Int_t i)
|
---|
478 | {
|
---|
479 | Int_t n = 0;
|
---|
480 |
|
---|
481 | // --- old I/O ---
|
---|
482 | // Read only + Reflector (no absorption)
|
---|
483 | // Muons: 1.06GB/115s = 9.2MB/s (100kEvs)
|
---|
484 | // Gammas: 1.57GB/275s = 5.7MB/s ( 1kEvs)
|
---|
485 |
|
---|
486 | // Read only:
|
---|
487 | // Gammas: 1.57GB/158s = 9.9MB/s ( 1kEvs)
|
---|
488 | // Muons: 1.06GB/ 77s = 13.8MB/s (100kEvs)
|
---|
489 |
|
---|
490 | // --- new I/O ---
|
---|
491 | // Read only (don't allocate storage space):
|
---|
492 | // Gammas: 1.57GB/143s = 11.0MB/s ( 1kEvs)
|
---|
493 | // Muons: 1.06GB/ 77s = 13.8MB/s (100kEvs)
|
---|
494 |
|
---|
495 | // Read only in blocks (with storage allocation):
|
---|
496 | // Gammas: 1.57GB/28s = 56MB/s ( 1kEvs)
|
---|
497 | // Muons: 1.06GB/5.2s = 204MB/s (100kEvs)
|
---|
498 |
|
---|
499 | // Read only in blocks (without storage allocation):
|
---|
500 | // similar to just copy
|
---|
501 |
|
---|
502 | // Copy with cp
|
---|
503 | // 1.57GB/ 5s CPU
|
---|
504 | // 1.57GB/28s REAL
|
---|
505 | // 1.06GB/ 3s CPU
|
---|
506 | // 1.06GB/22s REAL
|
---|
507 | Bool_t readError = kFALSE;
|
---|
508 | Float_t * buffer;
|
---|
509 |
|
---|
510 | if ( fInFormat->IsEventioFormat() )
|
---|
511 | {
|
---|
512 | while (fInFormat->GetNextEvent(&buffer, readError))
|
---|
513 | {
|
---|
514 |
|
---|
515 | const Int_t rc = Add(n).FillEventIO(buffer);
|
---|
516 | switch (rc)
|
---|
517 | {
|
---|
518 | case kCONTINUE: continue; // No data in this bunch... skip it.
|
---|
519 | case kERROR: return kERROR; // Error occured
|
---|
520 | //case kFALSE: return kFALSE; // End of stream
|
---|
521 | }
|
---|
522 |
|
---|
523 | // This is a photon we would like to keep later.
|
---|
524 | // Increase the counter by one
|
---|
525 | n++;
|
---|
526 | }
|
---|
527 | }
|
---|
528 | else
|
---|
529 | {
|
---|
530 | while (fInFormat->GetNextEvent(&buffer, readError))
|
---|
531 | {
|
---|
532 |
|
---|
533 | const Int_t rc = Add(n).FillCorsika(buffer, i);
|
---|
534 | switch (rc)
|
---|
535 | {
|
---|
536 | case kCONTINUE: continue; // No data in this bunch... skip it.
|
---|
537 | case kERROR: return kERROR; // Error occured
|
---|
538 | //case kFALSE: return kFALSE; // End of stream
|
---|
539 | }
|
---|
540 |
|
---|
541 | // This is a photon we would like to keep later.
|
---|
542 | // Increase the counter by one
|
---|
543 | n++;
|
---|
544 | }
|
---|
545 | }
|
---|
546 | if (readError) return kFALSE;
|
---|
547 |
|
---|
548 | /*
|
---|
549 |
|
---|
550 | while (1)
|
---|
551 | {
|
---|
552 | Float_t buffer[273];
|
---|
553 | Float_t * ptr = buffer;
|
---|
554 |
|
---|
555 |
|
---|
556 | if (!fInFormat->ReadData(273, buffer))
|
---|
557 | return kFALSE;
|
---|
558 |
|
---|
559 | if (!memcmp(ptr, "EVTE", 4))
|
---|
560 | {
|
---|
561 |
|
---|
562 | fInFormat->UnreadLastData();
|
---|
563 | break;
|
---|
564 | }
|
---|
565 |
|
---|
566 | Float_t *end = ptr + 273;
|
---|
567 |
|
---|
568 | // Loop over all sub-blocks (photons) in the block and if
|
---|
569 | // they contain valid data add them to the array
|
---|
570 | while (ptr<end)
|
---|
571 | {
|
---|
572 | // Get/Add the n-th entry from the array and
|
---|
573 | // fill it with the current 7 floats
|
---|
574 | const Int_t rc = Add(n).FillCorsika(ptr);
|
---|
575 | ptr += 7;
|
---|
576 |
|
---|
577 | switch (rc)
|
---|
578 | {
|
---|
579 | case kCONTINUE: continue; // No data in this bunch... skip it.
|
---|
580 | case kERROR: return kERROR; // Error occured
|
---|
581 | //case kFALSE: return kFALSE; // End of stream
|
---|
582 | }
|
---|
583 |
|
---|
584 | // This is a photon we would like to keep later.
|
---|
585 | // Increase the counter by one
|
---|
586 | n++;
|
---|
587 | }
|
---|
588 | }
|
---|
589 |
|
---|
590 | */
|
---|
591 | Resize(n);
|
---|
592 | fData.UnSort();
|
---|
593 |
|
---|
594 | SetReadyToSave();
|
---|
595 |
|
---|
596 | //*fLog << all << "Number of photon bunches: " << fData.GetEntriesFast() << endl;
|
---|
597 | return kTRUE;
|
---|
598 |
|
---|
599 | }
|
---|
600 |
|
---|
601 | Int_t MPhotonEvent::ReadCorsikaEvt(istream &fin, Int_t i)
|
---|
602 | {
|
---|
603 | Int_t n = 0;
|
---|
604 |
|
---|
605 | // --- old I/O ---
|
---|
606 | // Read only + Reflector (no absorption)
|
---|
607 | // Muons: 1.06GB/115s = 9.2MB/s (100kEvs)
|
---|
608 | // Gammas: 1.57GB/275s = 5.7MB/s ( 1kEvs)
|
---|
609 |
|
---|
610 | // Read only:
|
---|
611 | // Gammas: 1.57GB/158s = 9.9MB/s ( 1kEvs)
|
---|
612 | // Muons: 1.06GB/ 77s = 13.8MB/s (100kEvs)
|
---|
613 |
|
---|
614 | // --- new I/O ---
|
---|
615 | // Read only (don't allocate storage space):
|
---|
616 | // Gammas: 1.57GB/143s = 11.0MB/s ( 1kEvs)
|
---|
617 | // Muons: 1.06GB/ 77s = 13.8MB/s (100kEvs)
|
---|
618 |
|
---|
619 | // Read only in blocks (with storage allocation):
|
---|
620 | // Gammas: 1.57GB/28s = 56MB/s ( 1kEvs)
|
---|
621 | // Muons: 1.06GB/5.2s = 204MB/s (100kEvs)
|
---|
622 |
|
---|
623 | // Read only in blocks (without storage allocation):
|
---|
624 | // similar to just copy
|
---|
625 |
|
---|
626 | // Copy with cp
|
---|
627 | // 1.57GB/ 5s CPU
|
---|
628 | // 1.57GB/28s REAL
|
---|
629 | // 1.06GB/ 3s CPU
|
---|
630 | // 1.06GB/22s REAL
|
---|
631 |
|
---|
632 | while (1)
|
---|
633 | {
|
---|
634 | // Stprage for one block
|
---|
635 | char c[273*4];
|
---|
636 |
|
---|
637 | // Read the first four byte to check whether the next block
|
---|
638 | // doen't belong to the event anymore
|
---|
639 | fin.read(c, 4);
|
---|
640 | if (!fin)
|
---|
641 | return kFALSE;
|
---|
642 |
|
---|
643 | // Check if the event is finished
|
---|
644 | if (!memcmp(c, "EVTE", 4))
|
---|
645 | break;
|
---|
646 |
|
---|
647 | // Now read the rest of the data
|
---|
648 | fin.read(c+4, 272*4);
|
---|
649 |
|
---|
650 | Float_t *ptr = reinterpret_cast<Float_t*>(c);
|
---|
651 | Float_t *end = ptr + 273;
|
---|
652 |
|
---|
653 | // Loop over all sub-blocks (photons) in the block and if
|
---|
654 | // they contain valid data add them to the array
|
---|
655 | while (ptr<end)
|
---|
656 | {
|
---|
657 | // Get/Add the n-th entry from the array and
|
---|
658 | // fill it with the current 7 floats
|
---|
659 | const Int_t rc = Add(n).FillCorsika(ptr, i);
|
---|
660 | ptr += 7;
|
---|
661 |
|
---|
662 | switch (rc)
|
---|
663 | {
|
---|
664 | case kCONTINUE: continue; // No data in this bunch... skip it.
|
---|
665 | case kERROR: return kERROR; // Error occured
|
---|
666 | //case kFALSE: return kFALSE; // End of stream
|
---|
667 | }
|
---|
668 |
|
---|
669 | // This is a photon we would like to keep later.
|
---|
670 | // Increase the counter by one
|
---|
671 | n++;
|
---|
672 | }
|
---|
673 | }
|
---|
674 | /*
|
---|
675 | while (1)
|
---|
676 | {
|
---|
677 | // Check the first four bytes
|
---|
678 | char c[4];
|
---|
679 | fin.read(c, 4);
|
---|
680 |
|
---|
681 | // End of stream
|
---|
682 | if (!fin)
|
---|
683 | return kFALSE;
|
---|
684 |
|
---|
685 | // Check if we found the end of the event
|
---|
686 | if (!memcmp(c, "EVTE", 4))
|
---|
687 | break;
|
---|
688 |
|
---|
689 | // The first for byte contained data already --> go back
|
---|
690 | fin.seekg(-4, ios::cur);
|
---|
691 |
|
---|
692 | // Do not modify this. It is optimized for execution
|
---|
693 | // speed and flexibility!
|
---|
694 | MPhotonData &ph = Add(n);
|
---|
695 | // It checks how many entries the lookup table has. If it has enough
|
---|
696 | // entries and the entry was already allocated, we can re-use it,
|
---|
697 | // otherwise we have to allocate it.
|
---|
698 |
|
---|
699 | // Now we read a single cherenkov bunch. Note that for speed reason we have not
|
---|
700 | // called the constructor if the event was already constructed (virtual table
|
---|
701 | // set), consequently we must make sure that ReadCorsikaEvent does reset
|
---|
702 | // all data mebers no matter whether they are read or not.
|
---|
703 | const Int_t rc = ph.ReadCorsikaEvt(fin);
|
---|
704 |
|
---|
705 | // Evaluate result from reading event
|
---|
706 | switch (rc)
|
---|
707 | {
|
---|
708 | case kCONTINUE: continue; // No data in this bunch... skip it.
|
---|
709 | case kFALSE: return kFALSE; // End of stream
|
---|
710 | case kERROR: return kERROR; // Error occured
|
---|
711 | }
|
---|
712 |
|
---|
713 | // FIXME: If fNumPhotons!=1 add the photon more than once
|
---|
714 |
|
---|
715 | // Now increase the number of entries which are kept,
|
---|
716 | // i.e. keep this photon(s)
|
---|
717 | n++;
|
---|
718 | }
|
---|
719 | */
|
---|
720 |
|
---|
721 | Resize(n);
|
---|
722 | fData.UnSort();
|
---|
723 |
|
---|
724 | SetReadyToSave();
|
---|
725 |
|
---|
726 | //*fLog << all << "Number of photon bunches: " << fData.GetEntriesFast() << endl;
|
---|
727 | return kTRUE;
|
---|
728 | }
|
---|
729 |
|
---|
730 | // --------------------------------------------------------------------------
|
---|
731 | /*
|
---|
732 | Int_t MPhotonEvent::ReadRflEvt(std::istream &fin, Int_t i)
|
---|
733 | {
|
---|
734 | Int_t n = 0;
|
---|
735 |
|
---|
736 | while (1)
|
---|
737 | {
|
---|
738 | // Check the first four bytes
|
---|
739 | char c[13];
|
---|
740 | fin.read(c, 13);
|
---|
741 |
|
---|
742 | // End of stream
|
---|
743 | if (!fin)
|
---|
744 | return kFALSE;
|
---|
745 |
|
---|
746 | // Check if we found the end of the event
|
---|
747 | if (!memcmp(c, "\nEND---EVENT\n", 13))
|
---|
748 | break;
|
---|
749 |
|
---|
750 | // The first for byte contained data already --> go back
|
---|
751 | fin.seekg(-13, ios::cur);
|
---|
752 |
|
---|
753 | // Do not modify this. It is optimized for execution
|
---|
754 | // speed and flexibility!
|
---|
755 | //TObject *o = n<fData.GetSize() && fData.UncheckedAt(n) ? fData.UncheckedAt(n) : fData.New(n);
|
---|
756 |
|
---|
757 | // Now we read a single cherenkov bunch
|
---|
758 | //const Int_t rc = static_cast<MPhotonData*>(o)->ReadRflEvt(fin);
|
---|
759 | const Int_t rc = Add(n).ReadRflEvt(fin, i);
|
---|
760 |
|
---|
761 | // Evaluate result from reading event
|
---|
762 | switch (rc)
|
---|
763 | {
|
---|
764 | case kCONTINUE: continue; // No data in this bunch... skip it.
|
---|
765 | case kFALSE: return kFALSE; // End of stream
|
---|
766 | case kERROR: return kERROR; // Error occured
|
---|
767 | }
|
---|
768 |
|
---|
769 | // Now increase the number of entries which are kept,
|
---|
770 | // i.e. keep this photon(s)
|
---|
771 | n++;
|
---|
772 | }
|
---|
773 |
|
---|
774 | Shrink(n);
|
---|
775 |
|
---|
776 | SetReadyToSave();
|
---|
777 |
|
---|
778 | // *fLog << all << "Number of photon bunches: " << fData.GetEntriesFast() << endl;
|
---|
779 | return kTRUE;
|
---|
780 | }
|
---|
781 | */
|
---|
782 | // --------------------------------------------------------------------------
|
---|
783 | //
|
---|
784 | // Print the array
|
---|
785 | //
|
---|
786 | void MPhotonEvent::Print(Option_t *) const
|
---|
787 | {
|
---|
788 | fData.Print();
|
---|
789 | }
|
---|
790 |
|
---|
791 | // ------------------------------------------------------------------------
|
---|
792 | //
|
---|
793 | // You can call Draw() to add the photons to the current pad.
|
---|
794 | // The photons are painted each tim ethe pad is updated.
|
---|
795 | // Make sure that you use the right (world) coordinate system,
|
---|
796 | // like created, eg. by the MHCamera histogram.
|
---|
797 | //
|
---|
798 | void MPhotonEvent::Paint(Option_t *)
|
---|
799 | {
|
---|
800 | MPhotonData *ph=NULL;
|
---|
801 |
|
---|
802 | TMarker m;
|
---|
803 | m.SetMarkerStyle(kFullDotMedium); // Gtypes.h
|
---|
804 |
|
---|
805 | TIter Next(&fData);
|
---|
806 | while ((ph=(MPhotonData*)Next()))
|
---|
807 | {
|
---|
808 | m.SetX(ph->GetPosY()*10); // north
|
---|
809 | m.SetY(ph->GetPosX()*10); // east
|
---|
810 | m.Paint();
|
---|
811 | }
|
---|
812 | }
|
---|