Logo ROOT   6.07/09
Reference Guide
RooBlindTools.cxx
Go to the documentation of this file.
1 /*****************************************************************************
2  * Project: RooFit *
3  * Package: RooFitModels *
4  * @(#)root/roofit:$Id$
5  * Authors: *
6  * AR, Aaron Roodman, Stanford University, roodman@slac.stanford.edu *
7  * WV, Wouter Verkerke, UC Santa Barbara, verkerke@slac.stanford.edu *
8  * *
9  * Copyright (c) 2000-2005, Regents of the University of California *
10  * and Stanford University. All rights reserved. *
11  * *
12  * Redistribution and use in source and binary forms, *
13  * with or without modification, are permitted according to the terms *
14  * listed in LICENSE (http://roofit.sourceforge.net/license.txt) *
15  *****************************************************************************/
16 
17 //-----------------------
18 // This Class's Header --
19 ////////////////////////////////////////////////////////////////////////////////
20 
21 #include "RooFit.h"
22 
23 #include "RooBlindTools.h"
24 #include "RooBlindTools.h"
25 
26 #include "RooErrorHandler.h"
27 #include "Riostream.h"
28 #include <fstream>
29 #include <math.h>
30 #include <string.h>
31 #include <ctype.h>
32 
33 using namespace std;
34 
36 
37 
38 //----------------
39 // Constructors --
40 //----------------
41 
42 ////////////////////////////////////////////////////////////////////////////////
43 
44 RooBlindTools::RooBlindTools(const char *stSeedIn, blindMode Mode,
45  Double_t centralValue, Double_t sigmaOffset, Bool_t s2bMode) :
46 
47  _PrecisionOffsetScale(sigmaOffset),
48  _PrecisionCentralValue(centralValue),
49  _mode(Mode),
50  _s2bMode(s2bMode)
51 {
52  setup(stSeedIn);
53 }
54 
55 
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 
60  _PrecisionOffsetScale(blindTool.getPrecisionOffsetScale()),
61  _PrecisionCentralValue(blindTool.getPrecisionCentralValue()),
62  _mode(blindTool.mode()),
63  _s2bMode(blindTool._s2bMode)
64 {
65  setup(blindTool.stSeed());
66 }
67 
68 
69 
70 ////////////////////////////////////////////////////////////////////////////////
71 
72 void RooBlindTools::setup(const char *stSeedIn)
73 {
74  _stSeed = stSeedIn;
75 
76  _DeltaZScale = 1.56;
77 
78  _DeltaZOffset = _DeltaZScale*MakeOffset("abcdefghijklmnopqrstuvwxyz");
79 
80  _DeltaZSignFlip = MakeSignFlip("ijklmnopqrstuvwxyzabcdefgh");
81 
82  _AsymOffset = MakeGaussianOffset("opqrstuvwxyzabcdefghijklmn");
83 
84  _AsymSignFlip = MakeSignFlip("zyxwvutsrqponmlkjihgfedcba");
85 
86  _DeltaMScale = 0.1;
87 
88  _DeltaMOffset = _DeltaMScale*MakeOffset("opqrstuvwxyzabcdefghijklmn");
89 
90  _MysteryPhase = 3.14159 *
91  MakeOffset("wxyzabcdefghijklmnopqrstuv");
92 
93  if (_s2bMode) {
94  _PrecisionSignFlip = MakeSignFlip("zyxwvutsrqponmlkjihgfedcba");
95  } else {
96  _PrecisionSignFlip = MakeSignFlip("klmnopqrstuvwxyzabcdefghij");
97  }
98 
99  _PrecisionOffset = _PrecisionOffsetScale*MakeGaussianOffset("opqrstuvwxyzabcdefghijklmn");
100 
101  _PrecisionUniform = _PrecisionOffsetScale*MakeOffset("jihgfedcbazyxwvutsrqponmlk");
102 
103  _STagConstant = Randomizer("fghijklmnopqrstuvwxyzabcde");
104 }
105 
106 
107 //--------------
108 // Destructor --
109 //--------------
110 
111 //_____________________________________________________________________________
113 
114 //-------------
115 // Functions --
116 //-------------
117 
118 
119 ////////////////////////////////////////////////////////////////////////////////
120 
122  Int_t sTag = SignOfTag(STag);
123  Double_t DeltaZPrime = _DeltaZSignFlip*DeltaZ*sTag + _DeltaZOffset;
124 
125  return DeltaZPrime;
126 }
127 
128 
129 ////////////////////////////////////////////////////////////////////////////////
130 
132  Int_t sTag = SignOfTag(STag);
133  Double_t DeltaZPrime = _DeltaZSignFlip*(DeltaZ - PdG)*sTag + _DeltaZOffset;
134 
135  return DeltaZPrime;
136 }
137 
138 
139 ////////////////////////////////////////////////////////////////////////////////
140 
142  Int_t sTag = SignOfTag(STag);
143  Double_t DeltaZ = (DeltaZPrime - _DeltaZOffset)/(sTag*_DeltaZSignFlip);
144 
145  return DeltaZ;
146 }
147 
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 
152  Int_t sTag = SignOfTag(STag);
153  Double_t DeltaZ = PdG + (DeltaZPrime - _DeltaZOffset)/(sTag*_DeltaZSignFlip);
154 
155  return DeltaZ;
156 }
157 
158 
159 ////////////////////////////////////////////////////////////////////////////////
160 
162  if(mode()==dataonly) return AsymPrime;
163 
164  Double_t Asym = (AsymPrime - _AsymOffset)/_AsymSignFlip;
165 
166  return Asym;
167 }
168 
169 
170 ////////////////////////////////////////////////////////////////////////////////
171 
173  if(mode()==dataonly) return Asym;
174 
175  Double_t AsymPrime = Asym*_AsymSignFlip + _AsymOffset;
176 
177  return AsymPrime;
178 }
179 
180 
181 
182 ////////////////////////////////////////////////////////////////////////////////
183 
185  if(mode()==dataonly) return DeltaMPrime;
186 
187  Double_t DeltaM = DeltaMPrime - _DeltaMOffset;
188 
189  return DeltaM;
190 }
191 
192 
193 ////////////////////////////////////////////////////////////////////////////////
194 
196  if(mode()==dataonly) return DeltaM;
197 
198  Double_t DeltaMPrime = DeltaM + _DeltaMOffset;
199 
200  return DeltaMPrime;
201 }
202 
203 
204 ////////////////////////////////////////////////////////////////////////////////
205 
207  if(mode()==dataonly) return AsymPrime;
208 
209  Double_t Asym = PdG + (AsymPrime - _AsymOffset)/_AsymSignFlip;
210 
211  return Asym;
212 }
213 
214 
215 ////////////////////////////////////////////////////////////////////////////////
216 
218  if(mode()==dataonly) return 0.0;
219 
220  return _MysteryPhase;
221 }
222 
223 
224 ////////////////////////////////////////////////////////////////////////////////
225 
227  if(mode()==dataonly) return Asym;
228 
229  Double_t AsymPrime = (Asym - PdG)*_AsymSignFlip + _AsymOffset;
230 
231  return AsymPrime;
232 }
233 
234 
235 ////////////////////////////////////////////////////////////////////////////////
236 
238  if(mode()==dataonly) return PrecisionPrime;
239 
240  Double_t Precision(0.);
241 
242  if (_PrecisionSignFlip>0) {
243  Precision = PrecisionPrime - _PrecisionOffset;
244  }
245  else {
246  Precision = 2.0*_PrecisionCentralValue - PrecisionPrime + _PrecisionOffset;
247  }
248 
249 
250  return Precision;
251 }
252 
253 
254 
255 ////////////////////////////////////////////////////////////////////////////////
256 
258  if(mode()==dataonly) return Precision;
259 
260  Double_t PrecisionPrime(0.);
261 
262  if (_PrecisionSignFlip>0) {
263  PrecisionPrime = Precision + _PrecisionOffset;
264  }
265  else {
266  PrecisionPrime = 2.0*_PrecisionCentralValue - Precision + _PrecisionOffset;
267  }
268 
269  return PrecisionPrime;
270 }
271 
272 
273 
274 ////////////////////////////////////////////////////////////////////////////////
275 
277  if(mode()==dataonly) return PrecisionPrime;
278 
279  return PrecisionPrime - _PrecisionOffset;
280 }
281 
282 
283 
284 ////////////////////////////////////////////////////////////////////////////////
285 
287  if(mode()==dataonly) return Precision;
288 
289  return Precision + _PrecisionOffset;
290 }
291 
292 
293 
294 ////////////////////////////////////////////////////////////////////////////////
295 
297  if(mode()==dataonly) return PrecisionPrime;
298 
299  return PrecisionPrime - _PrecisionUniform;
300 }
301 
302 
303 
304 ////////////////////////////////////////////////////////////////////////////////
305 
307  if(mode()==dataonly) return Precision;
308 
309  return Precision + _PrecisionUniform;
310 }
311 
312 
313 
314 
315 ////////////////////////////////////////////////////////////////////////////////
316 
318  Int_t Seed = EventNumber % 7997 + 2;
319  Double_t r = PseudoRandom(Seed);
320  Double_t STagPrime(0.0);
321 
322  if (r < _STagConstant){
323  STagPrime = STag;
324  } else {
325  STagPrime = -1.0 * STag ;
326  }
327 
328  return STagPrime;
329 
330 }
331 
332 
333 
334 ////////////////////////////////////////////////////////////////////////////////
335 
336 Double_t RooBlindTools::Randomizer(const char *StringAlphabet) const{
337  char lowerseed[1024] ;
338  strlcpy(lowerseed,_stSeed,1024) ;
339 
340  Int_t lengthSeed = strlen(lowerseed);
341 
342  for (Int_t j=0; j<lengthSeed; j++){
343  lowerseed[j] =tolower(_stSeed[j]);
344  }
345  Int_t sumSeed = 0;
346  for (Int_t i=0; i<lengthSeed; i++){
347  for (Int_t iAlphabet=0; iAlphabet<26; iAlphabet++){
348  if ( lowerseed[i] == StringAlphabet[iAlphabet] ){
349  if (_s2bMode) {
350  sumSeed = (iAlphabet<<(5*(i%3)))^sumSeed;
351  } else {
352  sumSeed = sumSeed + iAlphabet ;
353  }
354  }
355  }
356  }
357 
358  if (lengthSeed<5 || ((sumSeed<1 || sumSeed>8000)&&!_s2bMode)) {
359  cout<< "RooBlindTools::Randomizer: Your String Seed is Bad: '" << _stSeed << "'" << endl ;
361  }
362 
363  Int_t ia = 8121;
364  Int_t ic = 28411;
365  Int_t im = 134456;
366  UInt_t jRan = (sumSeed*ia + ic) % im;
367 
368  jRan = (jRan*ia + ic) % im;
369  jRan = (jRan*ia + ic) % im;
370  jRan = (jRan*ia + ic) % im;
371 
372  Double_t theRan = (float) jRan / (float) im;
373 
374  return theRan; //theRan is between 0.0 - 1.0
375 
376 }
377 
378 
379 ////////////////////////////////////////////////////////////////////////////////
380 
382  if (Seed<1 || Seed>8000 ) {
383  cout<< "RooBlindTools::PseudoRandom: Your integer Seed is Bad" <<endl;
384  }
385 
386  Int_t ia = 8121;
387  Int_t ic = 28411;
388  Int_t im = 134456;
389  UInt_t jRan = (Seed*ia + ic) % im;
390 
391  jRan = (jRan*ia + ic) % im;
392  jRan = (jRan*ia + ic) % im;
393  jRan = (jRan*ia + ic) % im;
394 
395  Double_t theRan = (float) jRan / (float) im;
396 
397  return theRan; //theRan is between 0.0 - 1.0
398 
399 }
400 
401 
402 
403 ////////////////////////////////////////////////////////////////////////////////
404 
405 Double_t RooBlindTools::MakeOffset(const char *StringAlphabet) const{
406  Double_t theRan = Randomizer(StringAlphabet);
407 
408  Double_t theOffset = (2.0)*theRan - (1.0);
409 
410  return theOffset; //theOffset lies between -1.0 and 1.0
411 }
412 
413 
414 
415 ////////////////////////////////////////////////////////////////////////////////
416 
417 Double_t RooBlindTools::MakeGaussianOffset(const char *StringAlphabet) const{
418  Double_t theRan1 = Randomizer(StringAlphabet);
419  Double_t theRan2 = Randomizer("cdefghijklmnopqrstuvwxyzab");
420 
421  if (theRan1==0.0 || theRan1==1.0){
422  theRan1 = 0.5;
423  }
424  if (theRan2==0.0 || theRan2==1.0){
425  theRan2 = 0.5;
426  }
427 
428  Double_t theOffset = sin(2.0*3.14159*theRan1)*sqrt(-2.0*log(theRan2));
429 
430  return theOffset; //theOffset is Gaussian with mean 0, sigma 1
431 }
432 
433 
434 
435 ////////////////////////////////////////////////////////////////////////////////
436 
437 Double_t RooBlindTools::MakeSignFlip(const char *StringAlphabet) const{
438  Double_t theRan = Randomizer(StringAlphabet);
439 
440  Double_t theSignFlip = 1.0;
441  if (theRan>0.5){
442  theSignFlip = 1.0;
443  } else {
444  theSignFlip = -1.0;
445  }
446 
447  return theSignFlip; //theSignFlip is = +1 or -1
448 }
449 
450 
451 ////////////////////////////////////////////////////////////////////////////////
452 
454  Int_t sTag;
455  if (STag < 0.0){
456  sTag = -1;
457  }
458  else if (STag > 0.0) {
459  sTag = 1;
460  }
461  else {
462  sTag = 1;
463  }
464 
465  return sTag;
466 
467 }
468 
469 
Double_t HideAsym(Double_t Asym) const
Int_t SignOfTag(Double_t STag) const
static void softAbort()
Double_t MysteryPhase() const
Double_t MakeOffset(const char *StringAlphabet) const
Double_t UnHideOffset(Double_t PrecisionBlind) const
Double_t HideDeltaZ(Double_t DeltaZ, Double_t STag) const
Double_t MakeGaussianOffset(const char *StringAlphabet) const
Double_t _DeltaZScale
Double_t HideUniform(Double_t Precision) const
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const char * stSeed() const
Double_t RandomizeTag(Double_t STag, Int_t EventNumber) const
STL namespace.
Double_t _STagConstant
Double_t UnHideUniform(Double_t PrecisionBlind) const
double sqrt(double)
const blindMode & mode() const
Double_t UnHideDeltaZ(Double_t DeltaZPrime, Double_t STag) const
void setup(const char *stSeed)
Double_t PseudoRandom(Int_t Seed) const
double sin(double)
Double_t _DeltaZSignFlip
Double_t MakeSignFlip(const char *StringAlphabet) const
Double_t UnHidePrecision(Double_t PrecisionPrime) const
TRandom2 r(17)
Double_t UnHiDelZPdG(Double_t DeltaZPrime, Double_t STag, Double_t PdG) const
Double_t HiDelZPdG(Double_t DeltaZ, Double_t STag, Double_t PdG) const
Double_t _PrecisionSignFlip
Double_t UnHiAsPdG(Double_t AsymPrime, Double_t PdG) const
unsigned int UInt_t
Definition: RtypesCore.h:42
Double_t _DeltaZOffset
Double_t _PrecisionCentralValue
Double_t _AsymSignFlip
Double_t Randomizer(const char *StringAlphabet) const
Double_t HideDeltaM(Double_t DeltaM) const
Double_t _DeltaMScale
Double_t _AsymOffset
RooCmdArg Precision(Double_t prec)
#define ClassImp(name)
Definition: Rtypes.h:279
Double_t _PrecisionOffsetScale
double Double_t
Definition: RtypesCore.h:55
virtual ~RooBlindTools()
Double_t HidePrecision(Double_t Precision) const
Double_t _PrecisionUniform
Double_t UnHideDeltaM(Double_t DeltaMPrime) const
Double_t _MysteryPhase
Double_t _DeltaMOffset
Double_t HiAsPdG(Double_t Asym, Double_t PdG) const
Double_t _PrecisionOffset
Double_t UnHideAsym(Double_t AsymPrime) const
Double_t HideOffset(Double_t Precision) const
double log(double)