source: trunk/Mars/mtemp/mifae/library/MAddGainFluctuation.cc@ 17976

Last change on this file since 17976 was 6209, checked in by blanch, 20 years ago
*** empty log message ***
File size: 5.2 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): Oscar Blanch Bigas 01/2005 <mailto:blanch@ifae.es>
19!
20! Copyright: MAGIC Software Development, 2002-2005
21!
22!
23\* ======================================================================== */
24
25//////////////////////////////////////////////////////////////////////////////
26//
27// MAddGainFluctuation
28//
29// This is a task which add gain fluctuatins
30//
31// Input Containers:
32// MCerPhotEvt
33// MGainFluctuationCam
34// MGeomCam
35//
36// Output Containers:
37// MCerPhotEvt
38//
39//////////////////////////////////////////////////////////////////////////////
40#include "MAddGainFluctuation.h"
41
42#include "MParList.h"
43
44#include "MLog.h"
45#include "MLogManip.h"
46
47#include "MGeomCam.h"
48
49#include "MCerPhotEvt.h"
50#include "MCerPhotPix.h"
51#include "MGainFluctuationCam.h"
52
53#include "TRandom.h"
54
55ClassImp(MAddGainFluctuation);
56
57using namespace std;
58
59// --------------------------------------------------------------------------
60//
61// Default constructor.
62//
63MAddGainFluctuation::MAddGainFluctuation(const char *name, const char *title)
64{
65 fName = name ? name : "MAddGainFluctuation";
66 fTitle = title ? title : "Add gain fluctuation";
67
68 FillHist(1,0.1);
69}
70
71// --------------------------------------------------------------------------
72//
73// The PreProcess searches for the following input containers:
74// - MCerPhotEvt
75// - MGeomCam
76//
77// The following containers are also searched and created if
78// they were not found:
79// - MGainFluctuationCam
80//
81//
82Int_t MAddGainFluctuation::PreProcess(MParList *pList)
83{
84
85 fGeomCam = (MGeomCam*)pList->FindObject(AddSerialNumber("MGeomCam"));
86 if (!fGeomCam)
87 {
88 *fLog << err << "MGeomCam not found... aborting." << endl;
89 return kFALSE;
90 }
91
92 fCerPhotEvt = (MCerPhotEvt*)pList->FindObject(AddSerialNumber("MCerPhotEvt"));
93 if (!fCerPhotEvt)
94 return kFALSE;
95
96 fGainFlucCam = (MGainFluctuationCam*)pList->FindCreateObj(AddSerialNumber("MGainFluctuationCam"));
97 if (!fGainFlucCam)
98 return kFALSE;
99
100
101 Fill();
102
103 return kTRUE;
104}
105
106// --------------------------------------------------------------------------
107//
108//
109Bool_t MAddGainFluctuation::ReInit(MParList *pList)
110{
111 return kTRUE;
112}
113
114// --------------------------------------------------------------------------
115//
116// Scale the content of MCerPhotPix by Gain fluctuaion
117//
118Int_t MAddGainFluctuation::Process()
119{
120 //fCerPhotEvt->InitSize(fRawEvt->GetNumPixels());
121
122// if (fIsMcFile)
123// ScalePedestals();
124
125 if(!fAddFluctuations)
126 return kTRUE;
127
128 Double_t gain;
129
130 MCerPhotPix *pix = 0;
131
132 TIter Next(*fCerPhotEvt);
133
134 while ((pix=(MCerPhotPix*)Next()))
135 {
136 const UInt_t idx = pix->GetPixId();
137
138 fGainFlucCam->GetPixelContent(gain,idx,*fGeomCam,1);
139 pix->Scale(1.0/gain);
140 }
141
142 return kTRUE;
143}
144
145// --------------------------------------------------------------------------
146//
147// Fill Histogram with Gain Fluctuations distribution in the Camera
148//
149// flag:
150//
151// 0 : All to one
152// 1 : Gaussian centered at one with sigma "sigma"
153// 2 : Uniform distribution from 1/sigma to 1*sigma
154void MAddGainFluctuation::FillHist(int flag, float sigma){
155
156 TRandom rnd;
157 Float_t val;
158
159 fGainsDistribution = new TH1F("Gain","Gain Fluctuatins",1000,0.0,2.0);
160
161 switch(flag){
162 case 0:
163 fAddFluctuations=0;
164 break;
165 case 1:
166 fAddFluctuations=1;
167 for(int i=0;i<10000;i++){
168 val=rnd.Gaus(1.0,sigma);
169 fGainsDistribution->Fill(val);
170 }
171 break;
172 case 2:
173 fAddFluctuations=1;
174 for(int i=0;i<10000;i++){
175 val=rnd.Uniform(1.0/sigma,1.0*sigma);
176 fGainsDistribution->Fill(val);
177 }
178 break;
179 default:
180 fAddFluctuations=0;
181 for(int i=0;i<10000;i++){
182 val=rnd.Gaus(1.0,sigma);
183 fGainsDistribution->Fill(val);
184 }
185 break;
186 }
187}
188
189// --------------------------------------------------------------------------
190//
191// Set and Fill Histogram with Gain Fluctuations distribution in the Camera
192//
193void MAddGainFluctuation::SetHist(int bins, float fb, float lb, float *values){
194
195 fGainsDistribution = new TH1F("Gain","Gain Fluctuatins",bins,fb,lb);
196
197 for(int i=0;i<bins;i++){
198 fGainsDistribution->SetBinContent(i,values[i]);
199 }
200
201}
202
203// --------------------------------------------------------------------------
204//
205// Fill MGainFluctuatinCam
206//
207void MAddGainFluctuation::Fill(){
208
209 const Int_t pixels=fGeomCam->GetNumPixels();
210
211 if(fAddFluctuations)
212 for (int idx=0;idx<pixels;idx++)
213 fGainFlucCam->AddPixel(idx,fGainsDistribution->GetRandom());
214 else
215 for (int idx=0;idx<pixels;idx++)
216 fGainFlucCam->AddPixel(idx,1.0);
217
218}
219
Note: See TracBrowser for help on using the repository browser.