Logo ROOT   6.14/05
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 /** \class RooBlindTools
18  \ingroup Roofit
19 
20 **/
21 
22 #include "RooFit.h"
23 
24 #include "RooBlindTools.h"
25 #include "RooBlindTools.h"
26 
27 #include "RooErrorHandler.h"
28 #include "Riostream.h"
29 #include <fstream>
30 #include <math.h>
31 #include <string.h>
32 #include <ctype.h>
33 
34 using namespace std;
35 
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Constructor
40 
42  Double_t centralValue, Double_t sigmaOffset, Bool_t s2bMode) :
43 
44  _PrecisionOffsetScale(sigmaOffset),
45  _PrecisionCentralValue(centralValue),
46  _mode(Mode),
47  _s2bMode(s2bMode)
48 {
49  setup(stSeedIn);
50 }
51 
52 ////////////////////////////////////////////////////////////////////////////////
53 /// Constructor
54 
58  _mode(blindTool.mode()),
59  _s2bMode(blindTool._s2bMode)
60 {
61  setup(blindTool.stSeed());
62 }
63 
64 ////////////////////////////////////////////////////////////////////////////////
65 
66 void RooBlindTools::setup(const char *stSeedIn)
67 {
68  _stSeed = stSeedIn;
69 
70  _DeltaZScale = 1.56;
71 
72  _DeltaZOffset = _DeltaZScale*MakeOffset("abcdefghijklmnopqrstuvwxyz");
73 
74  _DeltaZSignFlip = MakeSignFlip("ijklmnopqrstuvwxyzabcdefgh");
75 
76  _AsymOffset = MakeGaussianOffset("opqrstuvwxyzabcdefghijklmn");
77 
78  _AsymSignFlip = MakeSignFlip("zyxwvutsrqponmlkjihgfedcba");
79 
80  _DeltaMScale = 0.1;
81 
82  _DeltaMOffset = _DeltaMScale*MakeOffset("opqrstuvwxyzabcdefghijklmn");
83 
84  _MysteryPhase = 3.14159 *
85  MakeOffset("wxyzabcdefghijklmnopqrstuv");
86 
87  if (_s2bMode) {
88  _PrecisionSignFlip = MakeSignFlip("zyxwvutsrqponmlkjihgfedcba");
89  } else {
90  _PrecisionSignFlip = MakeSignFlip("klmnopqrstuvwxyzabcdefghij");
91  }
92 
93  _PrecisionOffset = _PrecisionOffsetScale*MakeGaussianOffset("opqrstuvwxyzabcdefghijklmn");
94 
95  _PrecisionUniform = _PrecisionOffsetScale*MakeOffset("jihgfedcbazyxwvutsrqponmlk");
96 
97  _STagConstant = Randomizer("fghijklmnopqrstuvwxyzabcde");
98 }
99 
100 ////////////////////////////////////////////////////////////////////////////////
101 /// Destructor
102 
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 
108  Int_t sTag = SignOfTag(STag);
109  Double_t DeltaZPrime = _DeltaZSignFlip*DeltaZ*sTag + _DeltaZOffset;
110 
111  return DeltaZPrime;
112 }
113 
114 ////////////////////////////////////////////////////////////////////////////////
115 
117  Int_t sTag = SignOfTag(STag);
118  Double_t DeltaZPrime = _DeltaZSignFlip*(DeltaZ - PdG)*sTag + _DeltaZOffset;
119 
120  return DeltaZPrime;
121 }
122 
123 ////////////////////////////////////////////////////////////////////////////////
124 
126  Int_t sTag = SignOfTag(STag);
127  Double_t DeltaZ = (DeltaZPrime - _DeltaZOffset)/(sTag*_DeltaZSignFlip);
128 
129  return DeltaZ;
130 }
131 
132 ////////////////////////////////////////////////////////////////////////////////
133 
135  Int_t sTag = SignOfTag(STag);
136  Double_t DeltaZ = PdG + (DeltaZPrime - _DeltaZOffset)/(sTag*_DeltaZSignFlip);
137 
138  return DeltaZ;
139 }
140 
141 ////////////////////////////////////////////////////////////////////////////////
142 
144  if(mode()==dataonly) return AsymPrime;
145 
146  Double_t Asym = (AsymPrime - _AsymOffset)/_AsymSignFlip;
147 
148  return Asym;
149 }
150 
151 ////////////////////////////////////////////////////////////////////////////////
152 
154  if(mode()==dataonly) return Asym;
155 
156  Double_t AsymPrime = Asym*_AsymSignFlip + _AsymOffset;
157 
158  return AsymPrime;
159 }
160 
161 ////////////////////////////////////////////////////////////////////////////////
162 
164  if(mode()==dataonly) return DeltaMPrime;
165 
166  Double_t DeltaM = DeltaMPrime - _DeltaMOffset;
167 
168  return DeltaM;
169 }
170 
171 ////////////////////////////////////////////////////////////////////////////////
172 
174  if(mode()==dataonly) return DeltaM;
175 
176  Double_t DeltaMPrime = DeltaM + _DeltaMOffset;
177 
178  return DeltaMPrime;
179 }
180 
181 ////////////////////////////////////////////////////////////////////////////////
182 
184  if(mode()==dataonly) return AsymPrime;
185 
186  Double_t Asym = PdG + (AsymPrime - _AsymOffset)/_AsymSignFlip;
187 
188  return Asym;
189 }
190 
191 ////////////////////////////////////////////////////////////////////////////////
192 
194  if(mode()==dataonly) return 0.0;
195 
196  return _MysteryPhase;
197 }
198 
199 ////////////////////////////////////////////////////////////////////////////////
200 
202  if(mode()==dataonly) return Asym;
203 
204  Double_t AsymPrime = (Asym - PdG)*_AsymSignFlip + _AsymOffset;
205 
206  return AsymPrime;
207 }
208 
209 ////////////////////////////////////////////////////////////////////////////////
210 
212  if(mode()==dataonly) return PrecisionPrime;
213 
214  Double_t Precision(0.);
215 
216  if (_PrecisionSignFlip>0) {
217  Precision = PrecisionPrime - _PrecisionOffset;
218  }
219  else {
220  Precision = 2.0*_PrecisionCentralValue - PrecisionPrime + _PrecisionOffset;
221  }
222 
223 
224  return Precision;
225 }
226 
227 ////////////////////////////////////////////////////////////////////////////////
228 
230  if(mode()==dataonly) return Precision;
231 
232  Double_t PrecisionPrime(0.);
233 
234  if (_PrecisionSignFlip>0) {
235  PrecisionPrime = Precision + _PrecisionOffset;
236  }
237  else {
238  PrecisionPrime = 2.0*_PrecisionCentralValue - Precision + _PrecisionOffset;
239  }
240 
241  return PrecisionPrime;
242 }
243 
244 ////////////////////////////////////////////////////////////////////////////////
245 
247  if(mode()==dataonly) return PrecisionPrime;
248 
249  return PrecisionPrime - _PrecisionOffset;
250 }
251 
252 ////////////////////////////////////////////////////////////////////////////////
253 
255  if(mode()==dataonly) return Precision;
256 
257  return Precision + _PrecisionOffset;
258 }
259 
260 ////////////////////////////////////////////////////////////////////////////////
261 
263  if(mode()==dataonly) return PrecisionPrime;
264 
265  return PrecisionPrime - _PrecisionUniform;
266 }
267 
268 ////////////////////////////////////////////////////////////////////////////////
269 
271  if(mode()==dataonly) return Precision;
272 
273  return Precision + _PrecisionUniform;
274 }
275 
276 ////////////////////////////////////////////////////////////////////////////////
277 
279  Int_t Seed = EventNumber % 7997 + 2;
280  Double_t r = PseudoRandom(Seed);
281  Double_t STagPrime(0.0);
282 
283  if (r < _STagConstant){
284  STagPrime = STag;
285  } else {
286  STagPrime = -1.0 * STag ;
287  }
288 
289  return STagPrime;
290 
291 }
292 
293 ////////////////////////////////////////////////////////////////////////////////
294 
295 Double_t RooBlindTools::Randomizer(const char *StringAlphabet) const{
296  char lowerseed[1024] ;
297  strlcpy(lowerseed,_stSeed,1024) ;
298 
299  Int_t lengthSeed = strlen(lowerseed);
300 
301  for (Int_t j=0; j<lengthSeed; j++){
302  lowerseed[j] =tolower(_stSeed[j]);
303  }
304  Int_t sumSeed = 0;
305  for (Int_t i=0; i<lengthSeed; i++){
306  for (Int_t iAlphabet=0; iAlphabet<26; iAlphabet++){
307  if ( lowerseed[i] == StringAlphabet[iAlphabet] ){
308  if (_s2bMode) {
309  sumSeed = (iAlphabet<<(5*(i%3)))^sumSeed;
310  } else {
311  sumSeed = sumSeed + iAlphabet ;
312  }
313  }
314  }
315  }
316 
317  if (lengthSeed<5 || ((sumSeed<1 || sumSeed>8000)&&!_s2bMode)) {
318  cout<< "RooBlindTools::Randomizer: Your String Seed is Bad: '" << _stSeed << "'" << endl ;
320  }
321 
322  Int_t ia = 8121;
323  Int_t ic = 28411;
324  Int_t im = 134456;
325  UInt_t jRan = (sumSeed*ia + ic) % im;
326 
327  jRan = (jRan*ia + ic) % im;
328  jRan = (jRan*ia + ic) % im;
329  jRan = (jRan*ia + ic) % im;
330 
331  Double_t theRan = (float) jRan / (float) im;
332 
333  return theRan; //theRan is between 0.0 - 1.0
334 
335 }
336 
337 ////////////////////////////////////////////////////////////////////////////////
338 
340  if (Seed<1 || Seed>8000 ) {
341  cout<< "RooBlindTools::PseudoRandom: Your integer Seed is Bad" <<endl;
342  }
343 
344  Int_t ia = 8121;
345  Int_t ic = 28411;
346  Int_t im = 134456;
347  UInt_t jRan = (Seed*ia + ic) % im;
348 
349  jRan = (jRan*ia + ic) % im;
350  jRan = (jRan*ia + ic) % im;
351  jRan = (jRan*ia + ic) % im;
352 
353  Double_t theRan = (float) jRan / (float) im;
354 
355  return theRan; //theRan is between 0.0 - 1.0
356 
357 }
358 
359 ////////////////////////////////////////////////////////////////////////////////
360 
361 Double_t RooBlindTools::MakeOffset(const char *StringAlphabet) const{
362  Double_t theRan = Randomizer(StringAlphabet);
363 
364  Double_t theOffset = (2.0)*theRan - (1.0);
365 
366  return theOffset; //theOffset lies between -1.0 and 1.0
367 }
368 
369 ////////////////////////////////////////////////////////////////////////////////
370 
371 Double_t RooBlindTools::MakeGaussianOffset(const char *StringAlphabet) const{
372  Double_t theRan1 = Randomizer(StringAlphabet);
373  Double_t theRan2 = Randomizer("cdefghijklmnopqrstuvwxyzab");
374 
375  if (theRan1==0.0 || theRan1==1.0){
376  theRan1 = 0.5;
377  }
378  if (theRan2==0.0 || theRan2==1.0){
379  theRan2 = 0.5;
380  }
381 
382  Double_t theOffset = sin(2.0*3.14159*theRan1)*sqrt(-2.0*log(theRan2));
383 
384  return theOffset; //theOffset is Gaussian with mean 0, sigma 1
385 }
386 
387 ////////////////////////////////////////////////////////////////////////////////
388 
389 Double_t RooBlindTools::MakeSignFlip(const char *StringAlphabet) const{
390  Double_t theRan = Randomizer(StringAlphabet);
391 
392  Double_t theSignFlip = 1.0;
393  if (theRan>0.5){
394  theSignFlip = 1.0;
395  } else {
396  theSignFlip = -1.0;
397  }
398 
399  return theSignFlip; //theSignFlip is = +1 or -1
400 }
401 
402 ////////////////////////////////////////////////////////////////////////////////
403 
405  Int_t sTag;
406  if (STag < 0.0){
407  sTag = -1;
408  }
409  else if (STag > 0.0) {
410  sTag = 1;
411  }
412  else {
413  sTag = 1;
414  }
415 
416  return sTag;
417 
418 }
Double_t UnHideDeltaM(Double_t DeltaMPrime) const
Double_t UnHideDeltaZ(Double_t DeltaZPrime, Double_t STag) const
static void softAbort()
Double_t MysteryPhase() const
Int_t SignOfTag(Double_t STag) const
Double_t getPrecisionCentralValue() const
Double_t _DeltaZScale
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const blindMode & mode() const
STL namespace.
Double_t MakeGaussianOffset(const char *StringAlphabet) const
Double_t MakeSignFlip(const char *StringAlphabet) const
Double_t _STagConstant
Double_t UnHideUniform(Double_t PrecisionBlind) const
const char * stSeed() const
double sqrt(double)
void setup(const char *stSeed)
double sin(double)
Double_t RandomizeTag(Double_t STag, Int_t EventNumber) const
Double_t _DeltaZSignFlip
Double_t UnHiDelZPdG(Double_t DeltaZPrime, Double_t STag, Double_t PdG) const
Double_t getPrecisionOffsetScale() const
Double_t UnHideOffset(Double_t PrecisionBlind) const
Double_t HideDeltaM(Double_t DeltaM) const
Double_t HideDeltaZ(Double_t DeltaZ, Double_t STag) const
ROOT::R::TRInterface & r
Definition: Object.C:4
Double_t _PrecisionSignFlip
unsigned int UInt_t
Definition: RtypesCore.h:42
blindMode _mode
Double_t UnHiAsPdG(Double_t AsymPrime, Double_t PdG) const
Double_t _DeltaZOffset
Double_t _PrecisionCentralValue
Double_t HiDelZPdG(Double_t DeltaZ, Double_t STag, Double_t PdG) const
Double_t _AsymSignFlip
Double_t PseudoRandom(Int_t Seed) const
Double_t _DeltaMScale
Double_t _AsymOffset
RooCmdArg Precision(Double_t prec)
#define ClassImp(name)
Definition: Rtypes.h:359
Double_t _PrecisionOffsetScale
double Double_t
Definition: RtypesCore.h:55
Double_t Randomizer(const char *StringAlphabet) const
Double_t UnHideAsym(Double_t AsymPrime) const
virtual ~RooBlindTools()
Destructor.
Double_t _PrecisionUniform
Double_t _MysteryPhase
Double_t HideOffset(Double_t Precision) const
Double_t HidePrecision(Double_t Precision) const
Double_t HideUniform(Double_t Precision) const
Double_t _DeltaMOffset
Double_t HideAsym(Double_t Asym) const
Double_t _PrecisionOffset
Double_t MakeOffset(const char *StringAlphabet) const
Double_t UnHidePrecision(Double_t PrecisionPrime) const
double log(double)
Double_t HiAsPdG(Double_t Asym, Double_t PdG) const