Changeset 2821
- Timestamp:
- 01/15/04 16:44:47 (21 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r2820 r2821 4 4 5 5 -*-*- END OF LINE -*-*- 6 2004/01/15: Javier Rico 7 8 * manalysis/MPedCalcPedRun.[h,cc] 9 - optimize the running time 10 - add (some) documentation 11 - correct treatment for the case of several input files 12 13 * macros/pedvsevent.C 14 - added 15 - draw pedestal mean and rms vs event# for input pixel# and run 16 file, and compares them to the global pedestal mean and rms 17 6 18 7 19 2004/01/15: Raquel de los Reyes -
trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc
r2806 r2821 18 18 ! Author(s): Josep Flix 04/2001 <mailto:jflix@ifae.es> 19 19 ! Author(s): Thomas Bretz 05/2001 <mailto:tbretz@uni-sw.gwdg.de> 20 ! Author(s): Sebastian Commichau 12/2003 21 ! Author(s): Javier Rico 01/2004 20 22 ! 21 ! Copyright: MAGIC Software Development, 2000-200 123 ! Copyright: MAGIC Software Development, 2000-2004 22 24 ! 23 25 ! … … 28 30 // MPedCalcPedRun // 29 31 // // 32 // This task takes a pedestal run file and fills MPedestalCam during // 33 // the Process() with the pedestal and rms computed in an event basis. // 34 // In the PostProcess() MPedestalCam is finally filled with the pedestal // 35 // mean and rms computed in a run basis. // 36 // More than one run (file) can be merged // 37 // // 30 38 // Input Containers: // 31 39 // MRawEvtData // … … 33 41 // Output Containers: // 34 42 // MPedestalCam // 43 // // 35 44 // // 36 45 ///////////////////////////////////////////////////////////////////////////// … … 70 79 if (!fRawEvt) 71 80 { 72 *fLog << dbginf<< "MRawEvtData not found... aborting." << endl;81 *fLog << err << "MRawEvtData not found... aborting." << endl; 73 82 return kFALSE; 74 83 } … … 78 87 return kFALSE; 79 88 80 MGeomCamMagic magiccam; 81 82 fSumx.Set(magiccam.GetNumPixels()); 83 fSumx2.Set(magiccam.GetNumPixels()); 84 85 for(UInt_t i=0;i<magiccam.GetNumPixels();i++) 86 { 87 fSumx.AddAt(0,i); 88 fSumx2.AddAt(0,i); 89 } 89 fNumSamplesTot=0; 90 90 91 91 return kTRUE; 92 92 } 93 93 94 Bool_t MPedCalcPedRun::ReInit(MParList *pList )94 Bool_t MPedCalcPedRun::ReInit(MParList *pList) 95 95 { 96 const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader"); 97 if (!runheader) 98 { 99 *fLog << warn << dbginf; 100 *fLog << "Warning - cannot check file type, MRawRunHeader not found." << endl; 101 } 102 else 103 if (runheader->GetRunType() == kRTMonteCarlo) 104 return kTRUE; 96 105 97 fRunheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader"); 98 if (!fRunheader) 99 { 100 *fLog << warn << dbginf << 101 "Warning - cannot check file type, MRawRunHeader not found." << endl; 102 } 103 else 104 if (fRunheader->GetRunType() == kRTMonteCarlo) 105 { 106 return kTRUE; 107 } 106 fNumPixels = fPedestals->GetSize(); 108 107 109 fNumHiGainSamples = fRunheader->GetNumSamplesHiGain(); 108 if(fSumx.GetSize()==0) 109 { 110 fSumx.Set(fNumPixels); 111 fSumx2.Set(fNumPixels); 110 112 111 fPedestals->InitSize(fRunheader->GetNumPixel()); 113 memset(fSumx.GetArray(), 0, sizeof(Float_t)*fNumPixels); 114 memset(fSumx2.GetArray(), 0, sizeof(Float_t)*fNumPixels); 115 } 116 117 // Calculate an even number for the hi gain samples to avoid 118 // biases due to the fluctuation in pedestal from one slice to 119 // the other one 120 fNumHiGainSamples = runheader->GetNumSamplesHiGain() & ~1; 112 121 113 122 return kTRUE; 114 115 123 } 116 117 124 118 125 Int_t MPedCalcPedRun::Process() 119 126 { 120 121 127 MRawEvtPixelIter pixel(fRawEvt); 122 128 123 129 while (pixel.Next()) 124 130 { 125 Byte_t shift=(fNumHiGainSamples/2*2==fNumHiGainSamples) ? 0:1;126 131 Byte_t *ptr = pixel.GetHiGainSamples(); 127 const Byte_t *end = ptr + f RawEvt->GetNumHiGainSamples()-shift;132 const Byte_t *end = ptr + fNumHiGainSamples; 128 133 129 const Float_t higainped = CalcHiGainMean(ptr, end); 130 const Float_t higainrms = CalcHiGainRms(ptr, end, higainped); 131 132 const UInt_t pixid = pixel.GetPixelId(); 133 MPedestalPix &pix = (*fPedestals)[pixid]; 134 UInt_t sum = 0; 135 UInt_t sqr = 0; 134 136 135 // cumulate the sum of pedestals and of pedestal squares 136 fSumx.AddAt(higainped+fSumx.At(pixid),pixid); 137 fSumx2.AddAt(GetSumx2(ptr, end)+fSumx2.At(pixid),pixid); 138 139 // set the value of the pedestal and rms computed from the processed event 140 pix.Set(higainped, higainrms); 137 do 138 { 139 sum += *ptr; 140 sqr += *ptr * *ptr; 141 } 142 while (++ptr != end); 143 144 const Float_t msum = (Float_t)sum; 145 const Float_t msqr = (Float_t)sqr; 146 147 const Float_t higainped = msum/fNumHiGainSamples; 148 const Float_t higainrms = TMath::Sqrt((msqr-msum*msum/fNumHiGainSamples)/(fNumHiGainSamples-1.)); 149 150 const UInt_t idx = pixel.GetPixelId(); 151 (*fPedestals)[idx].Set(higainped, higainrms); 152 153 fSumx[idx] += msum; 154 fSumx2[idx] += sqr; 141 155 } 142 156 143 157 fPedestals->SetReadyToSave(); 144 158 fNumSamplesTot+=fNumHiGainSamples; 159 145 160 return kTRUE; 146 161 } … … 148 163 Int_t MPedCalcPedRun::PostProcess() 149 164 { 150 // Compute pedestals and rms from the whole run 151 152 MRawEvtPixelIter pixel(fRawEvt); 153 154 while (pixel.Next()) 165 // Compute pedestals and rms from the whole run 166 const Int_t n = fNumSamplesTot; 167 168 MRawEvtPixelIter pixel(fRawEvt); 169 170 while (pixel.Next()) 155 171 { 156 const UInt_t pixid = pixel.GetPixelId(); 157 MPedestalPix &pix = (*fPedestals)[pixid]; 158 159 const Int_t N = GetNumExecutions(); 160 const Float_t sum = fSumx.At(pixid); 161 const Float_t sum2 = fSumx2.At(pixid); 162 const Float_t higainped = sum/N; 163 const Float_t higainrms = sqrt(1./(N-1.)*(sum2-sum*sum/N)); 164 pix.Set(higainped,higainrms); 165 172 const UInt_t pixid = pixel.GetPixelId(); 173 174 const Float_t sum = fSumx.At(pixid); 175 const Float_t sum2 = fSumx2.At(pixid); 176 177 const Float_t higainped = sum/n; 178 const Float_t higainrms = TMath::Sqrt((sum2-sum*sum/n)/(n-1.)); 179 180 (*fPedestals)[pixid].Set(higainped, higainrms); 166 181 } 167 return kTRUE;168 182 183 return kTRUE; 169 184 } 170 185 171 186 172 Float_t MPedCalcPedRun::CalcHiGainMean(Byte_t *ptr, const Byte_t *end) const173 {174 Int_t sum=0;175 Byte_t EvenNumSamples=(fNumHiGainSamples/2*2==fNumHiGainSamples)176 ? fNumHiGainSamples : fNumHiGainSamples-1;177 178 do sum += *ptr;179 while (++ptr != end);180 181 return (Float_t)sum/EvenNumSamples;182 }183 184 185 186 Float_t MPedCalcPedRun::GetSumx2(Byte_t *ptr, const Byte_t *end) const187 {188 Float_t square = 0;189 190 // Take an even number of time slices to avoid biases due to A/B effect191 Byte_t EvenNumSamples=(fNumHiGainSamples/2*2==fNumHiGainSamples) ? fNumHiGainSamples:fNumHiGainSamples-1;192 193 do194 {195 const Float_t val = (Float_t)(*ptr);196 197 square += val*val;198 } while (++ptr != end);199 200 return square/EvenNumSamples;201 }202 203 204 Float_t MPedCalcPedRun::CalcHiGainRms(Byte_t *ptr, const Byte_t *end, Float_t higainped) const205 {206 Float_t rms = 0;207 Byte_t EvenNumSamples=(fNumHiGainSamples/2*2==fNumHiGainSamples) ? fNumHiGainSamples:fNumHiGainSamples-1;208 209 do210 {211 const Float_t diff = (Float_t)(*ptr)-higainped;212 213 rms += diff*diff;214 } while (++ptr != end);215 216 return sqrt(rms/(EvenNumSamples-1));217 }218 219 220 221 /*222 Float_t MPedCalcPedRun::CalcHiGainMeanErr(Float_t higainrms) const223 {224 return higainrms/sqrt((float)fNumHiGainSamples);225 }226 227 Float_t MPedCalcPedRun::CalcHiGainRmsErr(Float_t higainrms) const228 {229 return higainrms/sqrt(2.*fNumHiGainSamples);230 }231 */ -
trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.h
r2747 r2821 16 16 #include <TArrayF.h> 17 17 18 class MRawRunHeader;19 18 class MRawEvtData; 20 19 class MPedestalCam; … … 22 21 class MPedCalcPedRun : public MTask 23 22 { 24 Byte_t fNumHiGainSamples; 23 Byte_t fNumHiGainSamples; 24 UShort_t fNumPixels; 25 ULong_t fNumSamplesTot; 25 26 26 MRawRunHeader *fRunheader; // raw event run header27 27 MRawEvtData *fRawEvt; // raw event data (time slices) 28 28 MPedestalCam *fPedestals; // Pedestals of all pixels in the camera … … 30 30 TArrayF fSumx; // sum of values 31 31 TArrayF fSumx2; // sum of squared values 32 33 Float_t CalcHiGainMean(Byte_t *ptr, const Byte_t *end) const;34 Float_t CalcHiGainRms(Byte_t *ptr, const Byte_t *end, Float_t higainped) const;35 Float_t GetSumx2(Byte_t* ptr, const Byte_t* end) const;36 //Float_t CalcHiGainMeanErr(Float_t higainrms) const;37 //Float_t CalcHiGainRmsErr(Float_t higainrms) const;38 32 39 33 Bool_t ReInit(MParList *pList); … … 44 38 45 39 public: 46 47 40 MPedCalcPedRun(const char *name=NULL, const char *title=NULL); 48 41
Note:
See TracChangeset
for help on using the changeset viewer.