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): Oscar Blanch 11/2001 < mailto:blanch@ifae.es>
|
---|
19 | !
|
---|
20 | ! Copyright: MAGIC Software Development, 2000-2001
|
---|
21 | !
|
---|
22 | !
|
---|
23 | \* ======================================================================== */
|
---|
24 |
|
---|
25 | /////////////////////////////////////////////////////////////////////////////
|
---|
26 | // //
|
---|
27 | // MMcPedestalNSBAdd //
|
---|
28 | // //
|
---|
29 | // This Task adds the contribution of the diffuse NSB to the FADC //
|
---|
30 | // pedestals. We assume that NSB introduces larger fluctuation but does //
|
---|
31 | // not change the mean value. //
|
---|
32 | // To be precise we add quadratically to the rms that is already in //
|
---|
33 | // MPedestalCam the NSB contribution. //
|
---|
34 | // The number of photons from the diffuse NSB follows a poisson //
|
---|
35 | // distribution with expected mean value X, then its standard desviation //
|
---|
36 | // is sqrt(X). //
|
---|
37 | // X is the number of phe per ns so we have to convert in FADC counts per //
|
---|
38 | // slice: //
|
---|
39 | // //
|
---|
40 | // Y=sqrt(X*FADC_time/Number_of_slice*pixel_size)*Amp_single_phe_response //
|
---|
41 | // //
|
---|
42 | // Input Containers: //
|
---|
43 | // MMcFadcHeader //
|
---|
44 | // MMcRunHeader //
|
---|
45 | // MRawRunHeader //
|
---|
46 | // //
|
---|
47 | // Output Containers: //
|
---|
48 | // MPedestalCam //
|
---|
49 | // //
|
---|
50 | /////////////////////////////////////////////////////////////////////////////
|
---|
51 |
|
---|
52 | #include "MMcPedestalNSBAdd.h"
|
---|
53 |
|
---|
54 | #include "MParList.h"
|
---|
55 |
|
---|
56 | #include "MLog.h"
|
---|
57 | #include "MLogManip.h"
|
---|
58 |
|
---|
59 | #include "MPedestalCam.h"
|
---|
60 | #include "MRawRunHeader.h"
|
---|
61 | #include "MMcRunHeader.hxx"
|
---|
62 | #include "MMcFadcHeader.hxx"
|
---|
63 | #include "MGeomCam.h"
|
---|
64 | #include "MGeomPix.h"
|
---|
65 |
|
---|
66 | ClassImp(MMcPedestalNSBAdd);
|
---|
67 |
|
---|
68 | // --------------------------------------------------------------------------
|
---|
69 | //
|
---|
70 | // Default constructor.
|
---|
71 | //
|
---|
72 | MMcPedestalNSBAdd::MMcPedestalNSBAdd(const Float_t difnsb,
|
---|
73 | const char *name, const char *title)
|
---|
74 | : fDnsbPixel(difnsb)
|
---|
75 | {
|
---|
76 | fName = name ? name : "MMcPedestalNSBAdd";
|
---|
77 | fTitle = title ? title : "Task to copy monte carlo pedestals into MPedestal Container";
|
---|
78 |
|
---|
79 | //
|
---|
80 | // This is not needed here using MReadMarsFile because for the
|
---|
81 | // RunHeader tree the auto scheme is disabled by default
|
---|
82 | //
|
---|
83 | AddToBranchList("fPedesMean");
|
---|
84 | AddToBranchList("fElecNoise");
|
---|
85 | }
|
---|
86 |
|
---|
87 | Bool_t MMcPedestalNSBAdd::CheckRunType(MParList *pList) const
|
---|
88 | {
|
---|
89 | MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
|
---|
90 | if (!runheader)
|
---|
91 | {
|
---|
92 | *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
|
---|
93 | return kTRUE;
|
---|
94 | }
|
---|
95 |
|
---|
96 | return runheader->GetRunType() == kRTMonteCarlo;
|
---|
97 | }
|
---|
98 |
|
---|
99 | // --------------------------------------------------------------------------
|
---|
100 | //
|
---|
101 | // The PreProcess does nothing since the process does not exist and
|
---|
102 | // therefore it does not need any pointer or files already initialysed
|
---|
103 |
|
---|
104 | Bool_t MMcPedestalNSBAdd::PreProcess(MParList *pList)
|
---|
105 | {
|
---|
106 |
|
---|
107 | // FIX ME , ReInit should be called automatically. When it is
|
---|
108 | // implemented then this line should be removed.
|
---|
109 |
|
---|
110 | if (!CheckRunType(pList))
|
---|
111 | {
|
---|
112 | *fLog << warn << dbginf << "Warning - MMcPedestalNSB is for Monte Carlo files only... removing this task from list." << endl;
|
---|
113 | return kSKIP;
|
---|
114 | }
|
---|
115 |
|
---|
116 | fFadc = (MMcFadcHeader*)pList->FindObject("MMcFadcHeader");
|
---|
117 | if (!fFadc)
|
---|
118 | {
|
---|
119 | *fLog << err << dbginf << "MMcFadcHeader not found... aborting." << endl;
|
---|
120 | return kFALSE;
|
---|
121 | }
|
---|
122 |
|
---|
123 | fGeom = (MGeomCam*)pList->FindObject("MGeomCam");
|
---|
124 | if (!fGeom)
|
---|
125 | {
|
---|
126 | *fLog << err << dbginf << "MGeomCam not found... aborting." << endl;
|
---|
127 | return kFALSE;
|
---|
128 | }
|
---|
129 |
|
---|
130 | fPedCam = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
|
---|
131 | if (!fPedCam)
|
---|
132 | return kFALSE;
|
---|
133 |
|
---|
134 | MMcRunHeader *mcrunheader = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
|
---|
135 | if (!mcrunheader && fDnsbPixel < 0 )
|
---|
136 | {
|
---|
137 | *fLog << err << dbginf << "Using the default argument of MMcPedestalNSB::MMcPedestalNSB() ";
|
---|
138 | *fLog << "only allowed if MMcRunHeader is available... aborting." << endl;
|
---|
139 | return kFALSE;
|
---|
140 | }
|
---|
141 |
|
---|
142 | return kTRUE;
|
---|
143 | }
|
---|
144 |
|
---|
145 | // --------------------------------------------------------------------------
|
---|
146 | //
|
---|
147 | // This function is called each time MReadTree::Notify is called, which
|
---|
148 | // happens when it changes the file to read from.
|
---|
149 | // Here we add the contribution from NSB to the pedestals.
|
---|
150 | // The ReInit searches for the following input containers:
|
---|
151 | // - MRawRunHeader
|
---|
152 | // - MMcRunHeader
|
---|
153 | // - MMcFacdHeader
|
---|
154 | // - MGeomCam
|
---|
155 | //
|
---|
156 | // The following output containers are also searched and created if
|
---|
157 | // they were not found:
|
---|
158 | // - MPedestalCam
|
---|
159 | //
|
---|
160 | Float_t MMcPedestalNSBAdd::GetDnsb(MParList *pList) const
|
---|
161 | {
|
---|
162 | MMcRunHeader *mcrunheader = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
|
---|
163 | if (!mcrunheader && fDnsbPixel < 0 )
|
---|
164 | {
|
---|
165 | *fLog << err << dbginf << "Using the default argument of MMcPedestalNSB::MMcPedestalNSB() ";
|
---|
166 | *fLog << "only allowed if MMcRunHeader is available... aborting." << endl;
|
---|
167 | return -1;
|
---|
168 | }
|
---|
169 |
|
---|
170 | if (!mcrunheader)
|
---|
171 | return fDnsbPixel;
|
---|
172 |
|
---|
173 | if (fDnsbPixel >= 0 && fDnsbPixel != mcrunheader->GetNumPheFromDNSB())
|
---|
174 | {
|
---|
175 | *fLog << warn << dbginf << "The MC file has been generated with diffuse nsb " << mcrunheader->GetNumPheFromDNSB();
|
---|
176 | *fLog <<" but you set up the diffuse NSB to " << fDnsbPixel << endl;
|
---|
177 |
|
---|
178 | return fDnsbPixel;
|
---|
179 | }
|
---|
180 |
|
---|
181 | return mcrunheader->GetNumPheFromDNSB();
|
---|
182 | }
|
---|
183 |
|
---|
184 | Bool_t MMcPedestalNSBAdd::ReInit(MParList *pList)
|
---|
185 | {
|
---|
186 | if (!CheckRunType(pList))
|
---|
187 | return kFALSE;
|
---|
188 |
|
---|
189 | Float_t dnsbpix = GetDnsb(pList) * 50.0/15.0;
|
---|
190 |
|
---|
191 | if (dnsbpix < 0)
|
---|
192 | return kFALSE;
|
---|
193 |
|
---|
194 | const int num = fFadc->GetNumPixel();
|
---|
195 |
|
---|
196 | fPedCam->InitSize(num);
|
---|
197 |
|
---|
198 | const Float_t size0 = (*fGeom)[0].GetR() * (*fGeom)[0].GetR();
|
---|
199 |
|
---|
200 | for (int i=0; i<num; i++)
|
---|
201 | {
|
---|
202 | MPedestalPix &pix = (*fPedCam)[i];
|
---|
203 | MGeomPix &pixgeom = (*fGeom)[i];
|
---|
204 |
|
---|
205 | const Float_t pedrms = pix.GetSigma();
|
---|
206 | const Float_t size = pixgeom.GetR()*pixgeom.GetR()/size0;
|
---|
207 |
|
---|
208 | const Float_t ampl = fFadc->GetAmplitud();
|
---|
209 |
|
---|
210 | pix.SetSigma(sqrt(pedrms*pedrms + dnsbpix*ampl*ampl*size));
|
---|
211 | }
|
---|
212 |
|
---|
213 | return kTRUE;
|
---|
214 | }
|
---|
215 |
|
---|