00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "RooFit.h"
00021
00022 #include "RooBlindTools.h"
00023 #include "RooBlindTools.h"
00024
00025 #include "RooErrorHandler.h"
00026 #include "Riostream.h"
00027 #include <fstream>
00028 #include <math.h>
00029 #include <string.h>
00030 #include <ctype.h>
00031
00032 ClassImp(RooBlindTools)
00033
00034
00035
00036
00037
00038
00039
00040 RooBlindTools::RooBlindTools(const char *stSeedIn, blindMode Mode,
00041 Double_t centralValue, Double_t sigmaOffset, Bool_t s2bMode) :
00042
00043 _PrecisionOffsetScale(sigmaOffset),
00044 _PrecisionCentralValue(centralValue),
00045 _mode(Mode),
00046 _s2bMode(s2bMode)
00047 {
00048 setup(stSeedIn);
00049 }
00050
00051
00052
00053
00054 RooBlindTools::RooBlindTools(const RooBlindTools& blindTool):
00055 _PrecisionOffsetScale(blindTool.getPrecisionOffsetScale()),
00056 _PrecisionCentralValue(blindTool.getPrecisionCentralValue()),
00057 _mode(blindTool.mode()),
00058 _s2bMode(blindTool._s2bMode)
00059 {
00060 setup(blindTool.stSeed());
00061 }
00062
00063
00064
00065
00066 void RooBlindTools::setup(const char *stSeedIn)
00067 {
00068
00069 _stSeed = stSeedIn;
00070
00071 _DeltaZScale = 1.56;
00072
00073 _DeltaZOffset = _DeltaZScale*MakeOffset("abcdefghijklmnopqrstuvwxyz");
00074
00075 _DeltaZSignFlip = MakeSignFlip("ijklmnopqrstuvwxyzabcdefgh");
00076
00077 _AsymOffset = MakeGaussianOffset("opqrstuvwxyzabcdefghijklmn");
00078
00079 _AsymSignFlip = MakeSignFlip("zyxwvutsrqponmlkjihgfedcba");
00080
00081 _DeltaMScale = 0.1;
00082
00083 _DeltaMOffset = _DeltaMScale*MakeOffset("opqrstuvwxyzabcdefghijklmn");
00084
00085 _MysteryPhase = 3.14159 *
00086 MakeOffset("wxyzabcdefghijklmnopqrstuv");
00087
00088 if (_s2bMode) {
00089 _PrecisionSignFlip = MakeSignFlip("zyxwvutsrqponmlkjihgfedcba");
00090 } else {
00091 _PrecisionSignFlip = MakeSignFlip("klmnopqrstuvwxyzabcdefghij");
00092 }
00093
00094 _PrecisionOffset = _PrecisionOffsetScale*MakeGaussianOffset("opqrstuvwxyzabcdefghijklmn");
00095
00096 _PrecisionUniform = _PrecisionOffsetScale*MakeOffset("jihgfedcbazyxwvutsrqponmlk");
00097
00098 _STagConstant = Randomizer("fghijklmnopqrstuvwxyzabcde");
00099 }
00100
00101
00102
00103
00104
00105
00106
00107 RooBlindTools::~RooBlindTools(){}
00108
00109
00110
00111
00112
00113
00114
00115 Double_t RooBlindTools::HideDeltaZ(Double_t DeltaZ, Double_t STag)const{
00116
00117 Int_t sTag = SignOfTag(STag);
00118 Double_t DeltaZPrime = _DeltaZSignFlip*DeltaZ*sTag + _DeltaZOffset;
00119
00120 return DeltaZPrime;
00121 }
00122
00123
00124
00125 Double_t RooBlindTools::HiDelZPdG(Double_t DeltaZ, Double_t STag, Double_t PdG) const{
00126
00127 Int_t sTag = SignOfTag(STag);
00128 Double_t DeltaZPrime = _DeltaZSignFlip*(DeltaZ - PdG)*sTag + _DeltaZOffset;
00129
00130 return DeltaZPrime;
00131 }
00132
00133
00134
00135 Double_t RooBlindTools::UnHideDeltaZ(Double_t DeltaZPrime, Double_t STag) const{
00136
00137 Int_t sTag = SignOfTag(STag);
00138 Double_t DeltaZ = (DeltaZPrime - _DeltaZOffset)/(sTag*_DeltaZSignFlip);
00139
00140 return DeltaZ;
00141 }
00142
00143
00144
00145 Double_t RooBlindTools::UnHiDelZPdG(Double_t DeltaZPrime, Double_t STag, Double_t PdG) const{
00146
00147 Int_t sTag = SignOfTag(STag);
00148 Double_t DeltaZ = PdG + (DeltaZPrime - _DeltaZOffset)/(sTag*_DeltaZSignFlip);
00149
00150 return DeltaZ;
00151 }
00152
00153
00154
00155 Double_t RooBlindTools::UnHideAsym(Double_t AsymPrime) const{
00156
00157 if(mode()==dataonly) return AsymPrime;
00158
00159 Double_t Asym = (AsymPrime - _AsymOffset)/_AsymSignFlip;
00160
00161 return Asym;
00162 }
00163
00164
00165
00166 Double_t RooBlindTools::HideAsym(Double_t Asym) const{
00167
00168 if(mode()==dataonly) return Asym;
00169
00170 Double_t AsymPrime = Asym*_AsymSignFlip + _AsymOffset;
00171
00172 return AsymPrime;
00173 }
00174
00175
00176
00177
00178 Double_t RooBlindTools::UnHideDeltaM(Double_t DeltaMPrime) const{
00179
00180 if(mode()==dataonly) return DeltaMPrime;
00181
00182 Double_t DeltaM = DeltaMPrime - _DeltaMOffset;
00183
00184 return DeltaM;
00185 }
00186
00187
00188
00189 Double_t RooBlindTools::HideDeltaM(Double_t DeltaM) const{
00190
00191 if(mode()==dataonly) return DeltaM;
00192
00193 Double_t DeltaMPrime = DeltaM + _DeltaMOffset;
00194
00195 return DeltaMPrime;
00196 }
00197
00198
00199
00200 Double_t RooBlindTools::UnHiAsPdG(Double_t AsymPrime, Double_t PdG) const{
00201
00202 if(mode()==dataonly) return AsymPrime;
00203
00204 Double_t Asym = PdG + (AsymPrime - _AsymOffset)/_AsymSignFlip;
00205
00206 return Asym;
00207 }
00208
00209
00210
00211 Double_t RooBlindTools::MysteryPhase() const{
00212
00213 if(mode()==dataonly) return 0.0;
00214
00215 return _MysteryPhase;
00216 }
00217
00218
00219
00220 Double_t RooBlindTools::HiAsPdG(Double_t Asym, Double_t PdG) const{
00221
00222 if(mode()==dataonly) return Asym;
00223
00224 Double_t AsymPrime = (Asym - PdG)*_AsymSignFlip + _AsymOffset;
00225
00226 return AsymPrime;
00227 }
00228
00229
00230
00231 Double_t RooBlindTools::UnHidePrecision(Double_t PrecisionPrime) const{
00232
00233 if(mode()==dataonly) return PrecisionPrime;
00234
00235 Double_t Precision(0.);
00236
00237 if (_PrecisionSignFlip>0) {
00238 Precision = PrecisionPrime - _PrecisionOffset;
00239 }
00240 else {
00241 Precision = 2.0*_PrecisionCentralValue - PrecisionPrime + _PrecisionOffset;
00242 }
00243
00244
00245 return Precision;
00246 }
00247
00248
00249
00250
00251 Double_t RooBlindTools::HidePrecision(Double_t Precision) const{
00252
00253 if(mode()==dataonly) return Precision;
00254
00255 Double_t PrecisionPrime(0.);
00256
00257 if (_PrecisionSignFlip>0) {
00258 PrecisionPrime = Precision + _PrecisionOffset;
00259 }
00260 else {
00261 PrecisionPrime = 2.0*_PrecisionCentralValue - Precision + _PrecisionOffset;
00262 }
00263
00264 return PrecisionPrime;
00265 }
00266
00267
00268
00269
00270 Double_t RooBlindTools::UnHideOffset(Double_t PrecisionPrime) const{
00271
00272 if(mode()==dataonly) return PrecisionPrime;
00273
00274 return PrecisionPrime - _PrecisionOffset;
00275 }
00276
00277
00278
00279
00280 Double_t RooBlindTools::HideOffset(Double_t Precision) const{
00281
00282 if(mode()==dataonly) return Precision;
00283
00284 return Precision + _PrecisionOffset;
00285 }
00286
00287
00288
00289
00290 Double_t RooBlindTools::UnHideUniform(Double_t PrecisionPrime) const{
00291
00292 if(mode()==dataonly) return PrecisionPrime;
00293
00294 return PrecisionPrime - _PrecisionUniform;
00295 }
00296
00297
00298
00299
00300 Double_t RooBlindTools::HideUniform(Double_t Precision) const{
00301
00302 if(mode()==dataonly) return Precision;
00303
00304 return Precision + _PrecisionUniform;
00305 }
00306
00307
00308
00309
00310
00311 Double_t RooBlindTools::RandomizeTag(Double_t STag, Int_t EventNumber) const{
00312
00313 Int_t Seed = EventNumber % 7997 + 2;
00314 Double_t r = PseudoRandom(Seed);
00315 Double_t STagPrime(0.0);
00316
00317 if (r < _STagConstant){
00318 STagPrime = STag;
00319 } else {
00320 STagPrime = -1.0 * STag ;
00321 }
00322
00323 return STagPrime;
00324
00325 }
00326
00327
00328
00329
00330 Double_t RooBlindTools::Randomizer(const char *StringAlphabet) const{
00331
00332 char lowerseed[1024] ;
00333 strlcpy(lowerseed,_stSeed,1024) ;
00334
00335 Int_t lengthSeed = strlen(lowerseed);
00336
00337 for (Int_t j=0; j<lengthSeed; j++){
00338 lowerseed[j] =tolower(_stSeed[j]);
00339 }
00340 Int_t sumSeed = 0;
00341 for (Int_t i=0; i<lengthSeed; i++){
00342 for (Int_t iAlphabet=0; iAlphabet<26; iAlphabet++){
00343 if ( lowerseed[i] == StringAlphabet[iAlphabet] ){
00344 if (_s2bMode) {
00345 sumSeed = (iAlphabet<<(5*(i%3)))^sumSeed;
00346 } else {
00347 sumSeed = sumSeed + iAlphabet ;
00348 }
00349 }
00350 }
00351 }
00352
00353 if (lengthSeed<5 || ((sumSeed<1 || sumSeed>8000)&&!_s2bMode)) {
00354 cout<< "RooBlindTools::Randomizer: Your String Seed is Bad: '" << _stSeed << "'" << endl ;
00355 RooErrorHandler::softAbort() ;
00356 }
00357
00358 Int_t ia = 8121;
00359 Int_t ic = 28411;
00360 Int_t im = 134456;
00361 UInt_t jRan = (sumSeed*ia + ic) % im;
00362
00363 jRan = (jRan*ia + ic) % im;
00364 jRan = (jRan*ia + ic) % im;
00365 jRan = (jRan*ia + ic) % im;
00366
00367 Double_t theRan = (float) jRan / (float) im;
00368
00369 return theRan;
00370
00371 }
00372
00373
00374
00375 Double_t RooBlindTools::PseudoRandom(Int_t Seed) const{
00376
00377 if (Seed<1 || Seed>8000 ) {
00378 cout<< "RooBlindTools::PseudoRandom: Your integer Seed is Bad" <<endl;
00379 }
00380
00381 Int_t ia = 8121;
00382 Int_t ic = 28411;
00383 Int_t im = 134456;
00384 UInt_t jRan = (Seed*ia + ic) % im;
00385
00386 jRan = (jRan*ia + ic) % im;
00387 jRan = (jRan*ia + ic) % im;
00388 jRan = (jRan*ia + ic) % im;
00389
00390 Double_t theRan = (float) jRan / (float) im;
00391
00392 return theRan;
00393
00394 }
00395
00396
00397
00398
00399 Double_t RooBlindTools::MakeOffset(const char *StringAlphabet) const{
00400
00401 Double_t theRan = Randomizer(StringAlphabet);
00402
00403 Double_t theOffset = (2.0)*theRan - (1.0);
00404
00405 return theOffset;
00406 }
00407
00408
00409
00410
00411 Double_t RooBlindTools::MakeGaussianOffset(const char *StringAlphabet) const{
00412
00413 Double_t theRan1 = Randomizer(StringAlphabet);
00414 Double_t theRan2 = Randomizer("cdefghijklmnopqrstuvwxyzab");
00415
00416 if (theRan1==0.0 || theRan1==1.0){
00417 theRan1 = 0.5;
00418 }
00419 if (theRan2==0.0 || theRan2==1.0){
00420 theRan2 = 0.5;
00421 }
00422
00423 Double_t theOffset = sin(2.0*3.14159*theRan1)*sqrt(-2.0*log(theRan2));
00424
00425 return theOffset;
00426 }
00427
00428
00429
00430
00431 Double_t RooBlindTools::MakeSignFlip(const char *StringAlphabet) const{
00432
00433 Double_t theRan = Randomizer(StringAlphabet);
00434
00435 Double_t theSignFlip = 1.0;
00436 if (theRan>0.5){
00437 theSignFlip = 1.0;
00438 } else {
00439 theSignFlip = -1.0;
00440 }
00441
00442 return theSignFlip;
00443 }
00444
00445
00446
00447 Int_t RooBlindTools::SignOfTag(Double_t STag) const{
00448
00449 Int_t sTag;
00450 if (STag < 0.0){
00451 sTag = -1;
00452 }
00453 else if (STag > 0.0) {
00454 sTag = 1;
00455 }
00456 else {
00457 sTag = 1;
00458 }
00459
00460 return sTag;
00461
00462 }
00463
00464