source: trunk/Mars/manalysis/MSoftwareTrigger.cc@ 18476

Last change on this file since 18476 was 18476, checked in by tbretz, 9 years ago
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// MSoftwareTrigger
28//
29//////////////////////////////////////////////////////////////////////////////
30#include "MSoftwareTrigger.h"
31
32#include <algorithm>
33
34#include "MLog.h"
35#include "MLogManip.h"
36
37#include "MParList.h"
38
39#include "MParameters.h"
40#include "MRawEvtData.h"
41#include "MPedestalSubtractedEvt.h"
42
43ClassImp(MSoftwareTrigger);
44
45using namespace std;
46
47// --------------------------------------------------------------------------
48//
49// Default constructor.
50//
51MSoftwareTrigger::MSoftwareTrigger(const char *name, const char *title)
52 : fRawEvt(0), fSignal(0), fTriggerSignal(0), fTriggerBaseline(0)
53{
54 fName = name ? name : "MSoftwareTrigger";
55 fTitle = title ? title : "Calculate the FACT trigger in software";
56}
57
58// --------------------------------------------------------------------------
59//
60Int_t MSoftwareTrigger::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 fTriggerSignal = (MParameterD*)pList->FindCreateObj("MParameterD","SoftwareTriggerSignal");
77 if (!fTriggerSignal)
78 return kFALSE;
79
80 fTriggerBaseline = (MParameterD*)pList->FindCreateObj("MParameterD","SoftwareTriggerBaseline");
81 if (!fTriggerBaseline)
82 return kFALSE;
83
84 *fLog << flush << inf;
85 return kTRUE;
86}
87
88// --------------------------------------------------------------------------
89//
90Bool_t MSoftwareTrigger::ReInit(MParList *pList)
91{
92 return kTRUE;
93}
94
95// --------------------------------------------------------------------------
96//
97Int_t MSoftwareTrigger::Process()
98{
99 const UShort_t *idx = fRawEvt->GetPixelIds();
100
101 const int beg = 10;
102 const int end = std::min(UInt_t(200), fSignal->GetNumSamples());
103 const int num = end-beg;
104
105 MArrayF buf(160*num);
106
107 for (int hw=0; hw<1440; hw++)
108 {
109 // dead pixels
110 if (hw==927 || hw==80 || hw==873) // 3
111 continue;
112 // crazy pixels
113 if (hw==863 || hw==297 || hw==868) // 3
114 continue;
115 // broken DRS board
116 if (hw>=720 && hw<=728) // 9
117 continue;
118 // broken/suspicious bias channels
119 if ((hw>=171 && hw<=174) || (hw>=184 && hw<=188)) // 9
120 continue;
121
122 const UInt_t sw = idx[hw];
123
124 const Float_t *raw = fSignal->GetSamples(sw);
125
126 Float_t *sum = buf.GetArray()+(hw/9)*num;
127
128 for (const Float_t *ptr=raw+beg; ptr<raw+end; ptr++, sum++)
129 *sum += *ptr;
130 }
131
132 // apply correction factor for patches
133 // 927/9, 80/9, 873/9, 863/9, 297/9, 868/9
134
135 const int excl[] = { 8, 33, 95, 96, 97, 103, -1};
136 for (const int *e=excl; *e>=0; e++)
137 {
138 Float_t *raw = buf.GetArray() + *e * num;
139 for (Float_t *ptr=raw; ptr<raw+num; ptr++)
140 *ptr *= 1.125; // 9/8
141 }
142 {
143 Float_t *raw = buf.GetArray() + 19 * num; // 171-174
144 for (Float_t *ptr=raw; ptr<raw+num; ptr++)
145 *ptr *= 1.8; // 9/5 // 5 channels left
146 }
147 {
148 Float_t *raw = buf.GetArray() + 20 * num; // 184-188
149 for (Float_t *ptr=raw; ptr<raw+num; ptr++)
150 *ptr *= 2.25; // 9/4 // 4 channels left
151 }
152
153
154 Float_t max = 0;
155 double avg = 0;
156
157 const UInt_t nsum = buf.GetSize();
158 for (Float_t *sum=buf.GetArray(); sum<sum+nsum; sum+=num)
159 {
160 int idx = 0;
161 Float_t v[4] = { 0, 0, 0, 0 };
162
163 for (Float_t *ptr=sum+20; ptr<sum+num; ptr++)
164 {
165 *ptr -= 0.6 * ptr[-20];
166 avg += *ptr;
167 v[idx++%4] = *ptr;
168
169 const Float_t min = *std::min_element(v, v+4);
170 if (min>max)
171 max = min;
172 }
173 }
174
175 avg /= num*(1440-9); // excluding the 0's from the broken DRS board
176
177 fTriggerSignal->SetVal(max);
178 fTriggerSignal->SetReadyToSave();
179
180 fTriggerBaseline->SetVal(avg);
181 fTriggerBaseline->SetReadyToSave();
182
183 return kTRUE;
184}
185
186// --------------------------------------------------------------------------
187//
188Int_t MSoftwareTrigger::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
189{
190 return kTRUE;
191}
192
Note: See TracBrowser for help on using the repository browser.