Changeset 9274 for trunk/MagicSoft/Mars/msimcamera
- Timestamp:
- 01/27/09 10:40:55 (16 years ago)
- Location:
- trunk/MagicSoft/Mars/msimcamera
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/msimcamera/MSimCamera.cc
r9256 r9274 47 47 48 48 #include "MSpline3.h" 49 #include "MPulseShape.h" 49 50 50 51 #include "MParList.h" 52 //#include "MParameters.h" 51 53 52 54 #include "MPhotonEvent.h" … … 67 69 // 68 70 MSimCamera::MSimCamera(const char* name, const char *title) 69 : fEvt(0), fStat(0), fRunHeader(0), fCamera(0), fSpline(0), 70 fFunction("exp(-(x/2)^2/2)"), fNpx(25), fXmin(-25), fXmax(25) 71 : fEvt(0), fStat(0), fRunHeader(0), fCamera(0), fSpline(0)//, fPulsePos(0) 71 72 { 72 73 fName = name ? name : "MSimCamera"; … … 76 77 // -------------------------------------------------------------------------- 77 78 // 78 // Call Clear()79 //80 MSimCamera::~MSimCamera()81 {82 Clear();83 }84 85 // --------------------------------------------------------------------------86 //87 // Delete fSpline if set and set it to 088 //89 void MSimCamera::Clear(Option_t *)90 {91 if (fSpline)92 delete fSpline;93 fSpline=0;94 }95 96 // --------------------------------------------------------------------------97 //98 // Read the intended pulse shape from a file and initialize the spline99 // accordingly100 //101 Bool_t MSimCamera::ReadFile(const char *fname)102 {103 if (!fRunHeader)104 return kFALSE;105 106 if (fname)107 fFileName = fname;108 109 *fLog << inf << "Reading pulse shape from " << fFileName << endl;110 111 const TGraph g(fFileName);112 if (g.GetN()==0)113 {114 *fLog << err << "ERROR - No data points from " << fFileName << "." << endl;115 return kFALSE;116 }117 118 // option: b1/e1 b2/e2 (first second derivative?)119 // option: valbeg/valend (first second derivative?)120 121 Clear();122 fSpline = new MSpline3(g, fRunHeader->GetFreqSampling()/1000.);123 124 return kTRUE;125 }126 127 void MSimCamera::SetFunction(const TF1 &f)128 {129 // FIXME: Use TF1 directly? (In most cases this seems to be slower)130 if (!fRunHeader)131 return;// kFALSE;132 133 // option: b1/e1 b2/e2 (first second derivative?)134 // option: valbeg/valend (first second derivative?)135 136 // if (f.GetNpar()==0)137 // No SUPPORT138 139 Clear();140 fSpline = new MSpline3(f, fRunHeader->GetFreqSampling()/1000.);141 142 fFunction = f.GetTitle();143 }144 145 Bool_t MSimCamera::SetFunction(const char *func, Int_t n, Double_t xmin, Double_t xmax)146 {147 // FIXME: Use TF1 directly? (In most cases this seems to be slower)148 TF1 f("f", func, xmin, xmax);149 f.SetNpx(n);150 151 SetFunction(f);152 153 return kTRUE;154 }155 156 // --------------------------------------------------------------------------157 //158 // SetReadyToSave for fRunHeader159 //160 Bool_t MSimCamera::ReInit(MParList *pList)161 {162 // make that the run-header gets written to the file163 fRunHeader->SetReadyToSave();164 165 return kTRUE;166 }167 168 // --------------------------------------------------------------------------169 //170 79 // Search for the necessayr parameter containers. 171 80 // Setup spline for pulse shape. … … 197 106 return kFALSE; 198 107 } 199 200 201 // FIMXE: Move to ReInit in case fRunHeader is read form file? 202 if (!fFileName.IsNull()) 203 return ReadFile(fFileName); 204 205 if (!fFunction.IsNull()) 206 return SetFunction(fFunction, fNpx, fXmin, fXmax); 207 108 /* 109 fPulsePos = (MParameterD*)pList->FindObject("IntendedPulsePos", "MParameterD"); 110 if (!fPulsePos) 111 { 112 *fLog << err << "IntendedPulsePos [MParameterD] not found... aborting." << endl; 113 return kFALSE; 114 } 115 */ 116 MPulseShape *pulse = (MPulseShape*)pList->FindObject("MPulseShape"); 117 if (!pulse) 118 { 119 *fLog << err << "MPulseShape not found... aborting." << endl; 120 return kFALSE; 121 } 122 123 *fLog << warn << "FIXME - SCALE WITH THE SAMPLING FREQUENCY." << endl; 124 125 fSpline = pulse->GetSpline(); 208 126 if (!fSpline) 209 127 { … … 225 143 const Double_t freq = fRunHeader->GetFreqSampling()/1000.; 226 144 227 const Double_t start = fStat->GetTimeFirst()*freq + fSpline->GetXmin();228 const Double_t end = fStat->GetTimeLast() *freq + fSpline->GetXmax();145 const Double_t start = fStat->GetTimeFirst()*freq; 146 const Double_t end = fStat->GetTimeLast() *freq; 229 147 230 148 const UInt_t nlen = TMath::CeilNint(end-start); … … 236 154 const UInt_t npix = fStat->GetMaxIndex()+1; 237 155 156 const Double_t pl = fSpline->GetXmin()*freq; 157 const Double_t pr = fSpline->GetXmax()*freq; 158 238 159 // Init the arrays and set the range which will contain valid data 239 160 fCamera->Init(npix, nlen); 240 fCamera->SetValidRange(0 -TMath::FloorNint(fSpline->GetXmin()), 241 nlen-TMath::CeilNint( fSpline->GetXmax())); 161 fCamera->SetValidRange(TMath::FloorNint(pr), TMath::CeilNint(nlen+pl)); 242 162 243 163 // Add electronic noise to empty channels … … 258 178 259 179 const UInt_t idx = ph.GetTag(); 260 const Double_t t = (ph.GetTime()-fStat->GetTimeFirst())*freq - fSpline->GetXmin();180 const Double_t t = (ph.GetTime()-fStat->GetTimeFirst())*freq;// - fSpline->GetXmin(); 261 181 262 182 // FIXME: Time jitter? 263 183 // FIXME: Add additional routing here? 264 184 185 // === FIXME === FIXME === FIXME === Frequency!!!! 265 186 (*fCamera)[idx].AddPulse(*fSpline, t, ph.GetWeight()); 266 187 } 267 188 268 189 return kTRUE; 269 }270 271 // --------------------------------------------------------------------------272 //273 // FileName: pulse-shape.txt274 // Function.Name: gaus275 // Function.Npx: 50276 // Function.Xmin: -5277 // Function.Xmax: 5278 //279 Int_t MSimCamera::ReadEnv(const TEnv &env, TString prefix, Bool_t print)280 {281 Bool_t rc = kFALSE;282 if (IsEnvDefined(env, prefix, "FileName", print))283 {284 rc = kTRUE;285 SetFileName(GetEnvValue(env, prefix, "FileName", fFileName));286 }287 288 if (IsEnvDefined(env, prefix, "Function.Name", print))289 {290 rc = kTRUE;291 SetFunction(GetEnvValue(env, prefix, "Function.Name", fFunction));292 293 if (IsEnvDefined(env, prefix, "Function.Npx", print))294 fNpx = GetEnvValue(env, prefix, "Function.Npx", fNpx);295 if (IsEnvDefined(env, prefix, "Function.Xmin", print))296 fXmin = GetEnvValue(env, prefix, "Function.Xmin", fXmin);297 if (IsEnvDefined(env, prefix, "Function.Xmax", print))298 fXmax = GetEnvValue(env, prefix, "Function.Xmax", fXmax);299 }300 301 return rc;302 190 } 303 191 -
trunk/MagicSoft/Mars/msimcamera/MSimCamera.h
r9256 r9274 12 12 class MAnalogChannels; 13 13 14 class TF1;15 14 class MSpline3; 16 15 … … 24 23 MAnalogChannels *fCamera; //! Output of the analog signals 25 24 26 MSpline3 *fSpline; //! Spline to describe the pulse shape 27 28 TString fFileName; // File name of a file describing the pulse shape 29 30 TString fFunction; // Function describing the pulse shape 31 Int_t fNpx; // Number of 32 Float_t fXmin; 33 Float_t fXmax; 34 35 // MParContainer 36 Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print=kFALSE); 25 MSpline3 *fSpline; 37 26 38 27 // MTask 39 28 Int_t PreProcess(MParList *pList); 40 29 Int_t Process(); 41 Bool_t ReInit(MParList *pList);42 43 Bool_t ReadFile(const char *fname);44 Bool_t SetFunction(const char *func, Int_t n, Double_t xmin, Double_t xmax);45 30 46 31 public: 47 32 MSimCamera(const char *name=NULL, const char *title=NULL); 48 ~MSimCamera();49 50 void SetFunction(const TF1 &f);51 void SetFunction(const char *f) { fFunction=f; fFileName=""; }52 void SetFileName(const char *n) { fFileName=n; fFunction=""; }53 54 void Clear(Option_t *o="");55 33 56 34 ClassDef(MSimCamera, 0) // Task to simulate the electronic noise and to convert photons into pulses -
trunk/MagicSoft/Mars/msimcamera/MSimGeomCam.cc
r9243 r9274 61 61 #include "MRawRunHeader.h" 62 62 63 #include "MPulseShape.h" 64 63 65 ClassImp(MSimGeomCam); 64 66 … … 70 72 // 71 73 MSimGeomCam::MSimGeomCam(const char* name, const char *title) 72 : fGeom(0), fEvt(0), fStat(0), fNameGeomCam("MGeomCam") 74 : fGeom(0), fEvt(0), fStat(0), fPulsePos(0), fHeader(0), fPulse(0), 75 fNameGeomCam("MGeomCam") 73 76 { 74 77 fName = name ? name : "MSimGeomCam"; … … 96 99 { 97 100 *fLog << err << "MPhotonEvent not found... aborting." << endl; 101 return kFALSE; 102 } 103 104 fPulse = (MPulseShape*)pList->FindObject("MPulseShape"); 105 if (!fPulse) 106 { 107 *fLog << err << "MPulsShape not found... aborting." << endl; 98 108 return kFALSE; 99 109 } … … 166 176 const Float_t ns = fHeader->GetFreqSampling()/1000.*fHeader->GetNumSamplesHiGain(); 167 177 const Float_t pp = fPulsePos->GetVal(); 168 169 // FIXME FIXME FIXME --- Make it depending on the trigger position? 170 171 fStat->SetTime(first-pp, last+(ns-pp)); 178 const Float_t pw = fPulse->GetPulseWidth(); 179 180 fStat->SetTime(first-pp-pw, last+(ns-pp)+pw); 172 181 fStat->SetMaxIndex(fGeom->GetNumPixels()-1); 173 182 fStat->SetReadyToSave(); -
trunk/MagicSoft/Mars/msimcamera/MSimGeomCam.h
r9239 r9274 13 13 class MParameterD; 14 14 class MRawRunHeader; 15 class MPulseShape; 15 16 16 17 class MSimGeomCam : public MTask … … 22 23 MParameterD *fPulsePos; //! Intended pulse position in digitization window [ns] 23 24 MRawRunHeader *fHeader; //! Length of digitization window 24 25 MPulseShape *fPulse; //! 25 26 26 27 TString fNameGeomCam; -
trunk/MagicSoft/Mars/msimcamera/MSimReadout.cc
r9272 r9274 133 133 fRunHeader->SetValidMagicNumber(); 134 134 fRunHeader->SetSourceInfo("MonteCarlo"); // "Muon" from first event?? 135 fRunHeader->SetReadyToSave(); 135 136 136 137 fData->InitRead(fRunHeader); … … 197 198 { 198 199 *fLog << err << "ERROR - Trigger position beyond valid analog signal range." << endl; 200 *fLog << " Trigger: " << fTrigger->GetVal() << endl; 201 *fLog << " PulsePos: " << pulpos << endl; 202 *fLog << " SamplesIn: " << nsamp << endl; 203 *fLog << " SamplesOut: " << nslices << endl; 199 204 return kERROR; 200 205 } … … 239 244 fData->SetReadyToSave(); 240 245 246 // FIMXE: This will never be stored correctly :( 241 247 fRunHeader->SetNumEvents(fRunHeader->GetNumEvents()+1); 242 248 -
trunk/MagicSoft/Mars/msimcamera/MSimSignalCam.cc
r9261 r9274 46 46 47 47 #include "MParList.h" 48 #include "MParameters.h" 48 49 49 50 #include "MSignalCam.h" … … 62 63 // 63 64 MSimSignalCam::MSimSignalCam(const char* name, const char *title) 64 : fEvt(0), fStat(0), fSignal(0) 65 : fEvt(0), fStat(0), fSignal(0), fTrigger(0) 65 66 { 66 67 fName = name ? name : "MSimSignalCam"; … … 85 86 { 86 87 *fLog << err << "MPhotonStatistics not found... aborting." << endl; 88 return kFALSE; 89 } 90 91 fTrigger = (MParameterD*)pList->FindObject("TriggerPos", "MParameterD"); 92 if (!fTrigger) 93 { 94 *fLog << err << "TriggerPos [MParameterD] not found... aborting." << endl; 87 95 return kFALSE; 88 96 } … … 123 131 { 124 132 // FIXME: Check the maximum index in GetTag from the statistics container 125 126 133 fCont.Reset(); 127 134 fTime.Reset(); … … 152 159 // Get time of start point from the statistics container 153 160 // FIXME: Should be the real time of the first photon 154 const Float_t first = fStat->GetTimeFirst(); 161 162 // ====> Distance to trigger position! (if TrigPos found!) 163 // What about events with trigger<0? 164 const Float_t trig = fTrigger && fTrigger->GetVal()>=0 ? fTrigger->GetVal() : 0; 165 const Float_t first = fStat->GetTimeFirst()+trig /*+50+40*/; 155 166 156 167 // Loop over all pixels and set signal and arrival time. … … 161 172 MSignalPix &pix = (*fSignal)[idx]; 162 173 163 pix.SetNumPhotons(fCont[idx]); // gRandom->Uniform(last-first)174 pix.SetNumPhotons(fCont[idx]); 164 175 pix.SetArrivalTime(fCont[idx]<=0 ? -1 : fTime[idx]/fCont[idx]-first); 165 176 pix.SetRing(fCont[idx]>0); // Used==1, Unused==0 -
trunk/MagicSoft/Mars/msimcamera/MSimSignalCam.h
r9239 r9274 18 18 class MPhotonStatistics; 19 19 class MSignalCam; 20 class MParameterD; 20 21 21 22 class MSimSignalCam : public MTask 22 23 { 23 24 private: 24 MPhotonEvent *fEvt; //! Event containing the photons 25 MPhotonStatistics *fStat; //! Statistics about the event 26 MSignalCam *fSignal; //! Output container 25 MPhotonEvent *fEvt; //! Event containing the photons 26 MPhotonStatistics *fStat; //! Statistics about the event 27 MSignalCam *fSignal; //! Output container 28 MParameterD *fTrigger; //! Trigger position w.r.t. analog channels 27 29 28 30 MArrayD fCont; //! Local buffer for contents -
trunk/MagicSoft/Mars/msimcamera/MSimTrigger.cc
r9265 r9274 231 231 const Float_t pulspos = fPulsePos->GetVal()/freq; 232 232 233 // Valid range in units of bins 233 234 const Float_t min = fCamera->GetValidRangeMin()+pulspos; 234 const Float_t max = fCamera->GetValidRangeMax() +pulspos-nsamp;235 const Float_t max = fCamera->GetValidRangeMax()-(nsamp-pulspos); 235 236 236 237 // Define gate time (minimum coincidence time) … … 240 241 TObjArray triggers; 241 242 triggers.SetOwner(); 243 244 Int_t cnt = 0; 245 Int_t rmlo = 0; 246 Int_t rmhi = 0; 242 247 243 248 for (int j=0; j<fCoincidenceMap.GetEntries(); j++) … … 266 271 MDigitalSignal *ttl = 0; 267 272 while ((ttl=static_cast<MDigitalSignal*>(Next()))) 268 if (ttl->GetStart()<min || ttl->GetStart()>max) 273 { 274 if (ttl->GetStart()<min) 275 { 269 276 delete arr->Remove(ttl); 277 rmlo++; 278 } 279 if (ttl->GetStart()>max) 280 { 281 delete arr->Remove(ttl); 282 rmhi++; 283 } 284 } 270 285 271 286 // Remove the empty slots 272 287 arr->Compress(); 288 289 cnt += arr->GetEntriesFast(); 273 290 274 291 // If we have at least one trigger keep the earliest one. … … 284 301 // No trigger issued. Go on. 285 302 if (triggers.GetEntriesFast()==0) 303 { 304 *fLog << all << rmlo << "/" << rmhi << " trigger out of valid range. No trigger raised." << endl; 286 305 return kTRUE; 306 } 287 307 288 308 // There are usually not enough entries that it is worth to search … … 292 312 triggers.Sort(); 293 313 314 // FIXME: Jitter! (Own class?) 315 fTrigger->SetVal(static_cast<MDigitalSignal*>(triggers[0])->GetStart()); 316 294 317 // inf2? 295 318 *fLog << all; 296 *fLog << triggers.GetEntriesFast() << " triggers in " << triggers.GetEntriesFast() << " patches.";319 *fLog << cnt << " triggers left in " << triggers.GetEntriesFast() << " patches (" << rmlo << "/" << rmhi << " trigger out of valid range), T=" << fTrigger->GetVal(); 297 320 *fLog << endl; 298 299 // FIXME: Jitter! (Own class?)300 fTrigger->SetVal(static_cast<MDigitalSignal*>(triggers[0])->GetStart());301 302 321 303 322 return kTRUE;
Note:
See TracChangeset
for help on using the changeset viewer.