source: trunk/Mars/manalysis/MSoftwareTriggerCalc.cc@ 19240

Last change on this file since 19240 was 18957, checked in by tbretz, 7 years ago
Improved compiler warnings.
File size: 5.4 KB
Line 
1/* ======================================================================== *\
2!
3! *
4! * This file is part of MARS, the MAGIC 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 appear 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, 2016 <mailto:tbretz@physik.rwth-aachen.de>
19!
20! Copyright: MAGIC Software Development, 2016
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MSoftwareTriggerCalc
28//
29//////////////////////////////////////////////////////////////////////////////
30#include "MSoftwareTriggerCalc.h"
31
32#include <algorithm>
33
34#include "MLog.h"
35#include "MLogManip.h"
36
37#include "MParList.h"
38
39#include "MRawEvtData.h"
40#include "MSoftwareTrigger.h"
41#include "MPedestalSubtractedEvt.h"
42
43ClassImp(MSoftwareTriggerCalc);
44
45using namespace std;
46
47// --------------------------------------------------------------------------
48//
49// Default constructor.
50//
51MSoftwareTriggerCalc::MSoftwareTriggerCalc(const char *name, const char *title)
52 : fRawEvt(0), fSignal(0), fTrigger(0)
53{
54 fName = name ? name : "MSoftwareTriggerCalc";
55 fTitle = title ? title : "Calculate the FACT trigger in software";
56}
57
58// --------------------------------------------------------------------------
59//
60Int_t MSoftwareTriggerCalc::PreProcess(MParList *pList)
61{
62 fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");//, AddSerialNumber(fNamePedestalSubtractedEvt));
63 if (!fRawEvt)
64 {
65 *fLog << err << "MRawEvtData not found... aborting." << endl;
66 return kFALSE;
67 }
68
69 fSignal = (MPedestalSubtractedEvt*)pList->FindObject("MPedestalSubtractedEvt");//, AddSerialNumber(fNamePedestalSubtractedEvt));
70 if (!fSignal)
71 {
72 *fLog << err << "MPedestalSubtractedEvt not found... aborting." << endl;
73 return kFALSE;
74 }
75
76 fTrigger = (MSoftwareTrigger*)pList->FindCreateObj("MSoftwareTrigger");
77 if (!fTrigger)
78 return kFALSE;
79
80 return kTRUE;
81}
82
83// --------------------------------------------------------------------------
84//
85Bool_t MSoftwareTriggerCalc::ReInit(MParList *pList)
86{
87 // FIXME: Check number of samples!
88 return kTRUE;
89}
90
91// --------------------------------------------------------------------------
92//
93Int_t MSoftwareTriggerCalc::Process()
94{
95 const UShort_t *ids = fRawEvt->GetPixelIds();
96
97 const int beg = 10;
98 const int end = std::min(UInt_t(200), fSignal->GetNumSamples());
99 const int num = end-beg;
100
101 MArrayF buf(160*num);
102
103 double avg = 0;
104
105 for (int hw=0; hw<1440; hw++)
106 {
107 // dead pixels
108 if (hw==927 || hw==80 || hw==873) // 3
109 continue;
110 // crazy pixels
111 if (hw==863 || hw==297 || hw==868) // 3
112 continue;
113 // broken DRS board
114 if (hw>=720 && hw<=728) // 9
115 continue;
116 // broken/suspicious bias channels
117 if ((hw>=171 && hw<=174) || (hw>=184 && hw<=188)) // 9
118 continue;
119
120 const Float_t *raw = fSignal->GetSamples(ids[hw]);
121
122 Float_t *sum = buf.GetArray()+(hw/9)*num;
123
124 // Sum all nine pixel of one trigger patch
125 for (const Float_t *ptr=raw+beg; ptr<raw+end; ptr++, sum++)
126 *sum += *ptr;
127 }
128
129 // apply correction factor for patches
130 // 927/9, 80/9, 873/9, 863/9, 297/9, 868/9
131/*
132 const int excl[] = { 8, 33, 95, 96, 97, 103, -1};
133 for (const int *e=excl; *e>=0; e++)
134 {
135 Float_t *raw = buf.GetArray() + *e * num;
136 for (Float_t *ptr=raw; ptr<raw+num; ptr++)
137 *ptr *= 1.125; // 9/8
138 }
139 {
140 Float_t *raw = buf.GetArray() + 19 * num; // 171-174
141 for (Float_t *ptr=raw; ptr<raw+num; ptr++)
142 *ptr *= 1.8; // 9/5 // 5 channels left
143 }
144 {
145 Float_t *raw = buf.GetArray() + 20 * num; // 184-188
146 for (Float_t *ptr=raw; ptr<raw+num; ptr++)
147 *ptr *= 2.25; // 9/4 // 4 channels left
148 }
149*/
150
151 Float_t max = -50000;
152 UShort_t pos = 0;
153 Short_t patch = -1;
154
155 for (int i=0; i<160; i++)
156 {
157 int idx = 0;
158 Float_t v[4] = { 0, 0, 0, 0 };
159
160 Float_t *sum=buf.GetArray() + num*i;
161 for (Float_t *ptr=sum+15; ptr<sum+num; ptr++)
162 {
163 ptr[0] -= 0.5*ptr[-15];
164
165 avg += ptr[0];
166 v[idx++%4] = ptr[0];
167
168 const Float_t min = *std::min_element(v, v+4);
169 if (min<=max)
170 continue;
171
172 max = min;
173 pos = ptr-sum+beg;
174 patch = i;
175 }
176 }
177
178 // Question: Should we also keep position and patch id?
179
180 avg /= (num-15)*(1440-24);
181
182 fTrigger->SetData(patch, avg, pos, max);
183 fTrigger->SetReadyToSave();
184
185 return kTRUE;
186}
187
188// --------------------------------------------------------------------------
189//
190Int_t MSoftwareTriggerCalc::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
191{
192 return kTRUE;
193}
194
Note: See TracBrowser for help on using the repository browser.