Changeset 9274 for trunk/MagicSoft/Mars/melectronics
- Timestamp:
- 01/27/09 10:40:55 (16 years ago)
- Location:
- trunk/MagicSoft/Mars/melectronics
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/melectronics/ElectronicsLinkDef.h
r9242 r9274 6 6 7 7 #pragma link C++ class APD+; 8 #pragma link C++ class MPulseShape+; 8 9 #pragma link C++ class MAnalogSignal+; 9 10 #pragma link C++ class MDigitalSignal+; -
trunk/MagicSoft/Mars/melectronics/MAnalogSignal.cc
r9252 r9274 33 33 #include "MAnalogSignal.h" 34 34 35 #include <TF1.h> 35 36 #include <TRandom.h> 36 37 #include <TObjArray.h> … … 69 70 // and multiplied by f. 70 71 // 71 void MAnalogSignal::AddPulse(const MSpline3 &spline, Float_t t, Float_t f) 72 // Return kTRUE if the full range of the spline could be added to the 73 // analog signal, kFALSE otherwise. 74 // 75 Bool_t MAnalogSignal::AddPulse(const MSpline3 &spline, Float_t t, Float_t f) 72 76 { 73 77 // FIXME: This could be improved using a MExtralgoSpline with … … 79 83 const Float_t end = t+spline.GetXmax(); 80 84 81 /*const*/ Int_t first = TMath::CeilNint(start); 82 /*const*/ UInt_t last = TMath::CeilNint(end); // Ceil:< Floor:<= 83 84 if (first<0 || last>GetSize()) 85 { 86 gLog << err << "ERROR - AddPulse: Out of bounds, "; 87 gLog << "Win=[" << first << "," << last << "] N=" << GetSize() << " t=" << t; 88 gLog << " Spline=[" << spline.GetXmin() << "," << spline.GetXmax() << "]" << endl; 89 90 if (first<0) 91 first=0; 92 if (last>GetSize()) 93 last=GetSize(); 94 } 85 Int_t first = TMath::CeilNint(start); 86 UInt_t last = TMath::CeilNint(end); // Ceil:< Floor:<= 87 88 Bool_t rc = kTRUE; 89 if (first<0) 90 { 91 first=0; 92 rc = kFALSE; 93 } 94 if (last>GetSize()) 95 { 96 last=GetSize(); 97 rc = kFALSE; 98 } 99 100 // FIXME: As soon as we have access to TSpline3::fPoly we can 101 // gain a lot in execution speed here. 95 102 96 103 Float_t *arr = GetArray(); 97 104 for (UInt_t i=first; i<last; i++) 98 105 arr[i] += spline.Eval(i-t)*f; 106 107 return rc; 108 } 109 110 // ------------------------------------------------------------------------ 111 // 112 // Evaluate the spline an add the result between t+xmin and t+xmax 113 // (xmin and xmax are the limits of the TF1) to the signal. 114 // The spline is evaluated at the bin-center of the analog signal 115 // and multiplied by f. 116 // 117 // Return kTRUE if the full range of the function could be added to the 118 // analog signal, kFALSE otherwise. 119 // 120 Bool_t MAnalogSignal::AddPulse(const TF1 &func, Float_t t, Float_t f) 121 { 122 // Both in units of the sampling frequency 123 const Float_t start = t+func.GetXmin(); 124 const Float_t end = t+func.GetXmax(); 125 126 Int_t first = TMath::CeilNint(start); 127 UInt_t last = TMath::CeilNint(end); // Ceil:< Floor:<= 128 129 Bool_t rc = kTRUE; 130 if (first<0) 131 { 132 first=0; 133 rc = kFALSE; 134 } 135 if (last>GetSize()) 136 { 137 last=GetSize(); 138 rc = kFALSE; 139 } 140 141 // FIXME: As soon as we have access to TSpline3::fPoly we can 142 // gain a lot in execution speed here. 143 144 Float_t *arr = GetArray(); 145 for (UInt_t i=first; i<last; i++) 146 arr[i] += func.Eval(i-t)*f; 147 148 return rc; 99 149 } 100 150 … … 156 206 // The user is responsible of deleting the TObjArray. 157 207 // 158 TObjArray *MAnalogSignal::Discriminate(Float_t threshold, Float_t len) const208 TObjArray *MAnalogSignal::Discriminate(Float_t threshold, Double_t start, Double_t end, Float_t len) const 159 209 { 160 210 TObjArray *ttl = new TObjArray; … … 175 225 176 226 Double_t x1 = 0; 177 Double_t x2 = 0;227 Double_t x2 = start; // Start searching at x2 178 228 179 229 while (1) 180 230 { 181 x1 = sp.SearchYup(x2+deadtime, threshold); 182 if (x1<0) 183 break; 184 185 const Bool_t rising = sp.Deriv1(x1)>0; 186 if (!rising) 231 // Search for the next rising edge (starting at x2) 232 while (1) 187 233 { 188 // The last value might just have been a local max/min 189 // or its period was short than 1e-4 234 x1 = sp.SearchYup(x2+deadtime, threshold); 235 if (x1<0 || x1>=end) 236 return ttl; 237 238 const Bool_t rising = sp.Deriv1(x1)>0; 239 if (rising) 240 break; 241 190 242 x2 = x1; 191 //gLog << warn << "Rising edge expected at " << x1 << " (after " << x2 << ", N=" << fN << ")" << endl;192 continue;193 243 } 194 244 195 x2 = sp.SearchYup(x1+deadtime, threshold); 196 if (x2<0) 197 break; 198 199 const Bool_t falling = sp.Deriv1(x2)<=0; 200 if (!falling) 245 // Search for the next falling edge (starting at x1) 246 while (1) 201 247 { 202 // The last value might just have been a local max/min 203 // or its period was short than 1e-4 248 x2 = sp.SearchYup(x1+deadtime, threshold); 249 if (x2<0) 250 x2 = end; 251 if (x2>=end) 252 break; 253 254 const Bool_t falling = sp.Deriv1(x2)<0; 255 if (falling) 256 break; 257 204 258 x1 = x2; 205 //gLog << warn << "Falling edge expected at " << x2 << " (after " << x1 << " N=" << fN << ")" << endl;206 continue;207 259 } 208 260 261 // We found a rising and a falling edge 209 262 MDigitalSignal *sig = new MDigitalSignal(x1, len>0?len:x2-x1); 210 263 … … 228 281 } 229 282 230 if (x1>=0)231 gLog << warn << "Falling edge expected before end at N=" << fN << "!" << endl;232 233 283 return ttl; 234 284 } -
trunk/MagicSoft/Mars/melectronics/MAnalogSignal.h
r9242 r9274 6 6 #endif 7 7 8 class TF1; 8 9 class MSpline3; 9 10 … … 17 18 MAnalogSignal(UInt_t n) { Set(n); } 18 19 19 void Set(UInt_t n); 20 void AddPulse(const MSpline3 &spline, Float_t t, Float_t f=1); 21 void AddSignal(const MAnalogSignal &s); 20 void Set(UInt_t n); 21 Bool_t AddPulse(const MSpline3 &spline, Float_t t, Float_t f=1); 22 Bool_t AddPulse(const TF1 &f1, Float_t t, Float_t f=1); 23 void AddSignal(const MAnalogSignal &s); 22 24 23 25 // Deprecated. Use MSimRandomPhotons instead … … 26 28 void AddGaussianNoise(Float_t amplitude=1, Float_t offset=0); 27 29 28 TObjArray *Discriminate(Float_t threshold, Float_t len=-1) const; 30 TObjArray *Discriminate(Float_t threshold, Double_t start, Double_t end, Float_t len=-1) const; 31 TObjArray *Discriminate(Float_t threshold, Float_t len=-1) const { return Discriminate(threshold, 0, fN-1, len); } 29 32 30 33 ClassDef(MAnalogSignal, 1) // Storage class for an analog signal -
trunk/MagicSoft/Mars/melectronics/Makefile
r9242 r9274 24 24 MAnalogSignal.cc \ 25 25 MAnalogChannels.cc \ 26 MDigitalSignal.cc 26 MDigitalSignal.cc \ 27 MPulseShape.cc 27 28 28 29 ############################################################
Note:
See TracChangeset
for help on using the changeset viewer.