Ignore:
Timestamp:
02/03/05 12:42:21 (20 years ago)
Author:
mazin
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mtemp/mmpi/SupercutsONOFFClasses/MFindSupercutsONOFFThetaLoop.cc

    r4411 r6232  
    110110    //---------------------------
    111111
    112 
     112    // *********************************
     113    // ** NOT TRUE ANY LONGER... ** //
    113114    // Cuts (low and up) in variable ThetaOrig.fVal
    114115    // The default is not cut, i.e. all values (0-1) are taken
    115116    // fThetaOrig.fVal is measured in Radians; thus 1 = 57 degrees.
    116117
     118    //    fThetaMin = 0.0;
     119    //    fThetaMax = 1.0;
     120    // *********************************
     121
     122
     123    // For MAGIC new (July 2004) Theta is measured in degrees
     124
    117125    fThetaMin = 0.0;
    118     fThetaMax = 1.0;
     126    fThetaMax = 90.0;
     127
     128
    119129
    120130    fAlphaSig = 20; // By default, signal is expected in alpha<20 for CT1
     
    545555
    546556
    547     // Give a "soft warning" if Vector has increasing values
    548     // of CosThetas; which means decreasing values of Thetas
    549     /*
    550     if (fCosThetaRangeVector[0] <= fCosThetaRangeVector[1])
    551     {
    552         *fLog << "MFindSupercutsONOFFThetaLoop::SetCosThetaRangeVector; "
    553               << endl
    554               << "Values in vector fCosThetaRangeVector are in increasing "
    555               << "order, i.e., values in theta will be in decreasing order"
    556               << endl
    557               << "DO NOT forget it !!" << endl;
    558     }
    559 
    560     */
     557   
    561558
    562559    // fCosThetaBinCenterVector is defined
     
    622619    // Now costheta values have to be converted to Radians
    623620    // Function TMath::ACos(x) gives angle in Radians
    624 
     621   
    625622   
    626623    fThetaMin = TMath::ACos(fThetaMin);
    627624    fThetaMax = TMath::ACos(fThetaMax);
     625
     626   
     627    // For new MAGIC (July 2004), angles are given in degrees.
     628    // So I convert angles into degrees by multiplying by a the
     629    // conversion rad/degree
     630
     631    fThetaMin = fThetaMin * TMath::RadToDeg();
     632    fThetaMax = fThetaMax * TMath::RadToDeg();
     633
     634
    628635
    629636    // If fThetaMin > fThetaMax means that fCosThetaRangeVector
     
    644651          << "MFindSupercutsONOFFThetaLoop::SetThetaRange; " << endl
    645652          << "Theta range for this iteration is set to "
    646           << fThetaMin << "-" << fThetaMax << " Radians." << endl
     653          << fThetaMin << "-" << fThetaMax << " degrees." << endl
    647654          << "-------------------------------------------------"<< endl;
    648655   
     
    932939   
    933940
    934     // Histograms references are removed from the current directory
    935 
    936     /* IT DOES NOT WORK !!! THESE STATEMENTS PRODUCE SEGMENTATION FAULT.
    937     fNormFactorTrainHist -> SetDirectory(NULL);
    938    
    939     fNormFactorTestHist -> SetDirectory(NULL);
    940    
    941     fSigmaLiMaTrainHist -> SetDirectory(NULL);
    942    
    943     fSigmaLiMaTestHist -> SetDirectory(NULL);
    944    
    945     fSigmaLiMaTestHist -> SetDirectory(NULL);
    946    
    947     fNexTestHist -> SetDirectory(NULL);
    948     */
     941   
    949942
    950943
     
    10591052    Double_t fofftest)
    10601053{
     1054
     1055  // Check that fractions set by user are within the expected limits
     1056 
     1057  if (fontrain < 0.00 || fontrain > 1.00 ||
     1058      fontest < 0.00 || fontest > 1.00 ||
     1059      fofftrain < 0.00 || fofftrain > 1.00 ||
     1060      fofftest < 0.00 || fontest > 1.00)
     1061    {
     1062      *fLog << err
     1063            << "MFindSupercutsONOFFThetaLoop::SetFractionTrainTestOnOffEvents: "
     1064            << endl
     1065            << "Fractions of ON/OFF data for TRAIN/TEST sample which were specified by user " << endl
     1066            << "are outside the natural limits 0.0-1.0. " << endl
     1067            << "Set reasonable fraction numbers for TRAIN/TEST please. The program will be aborted."
     1068            << endl;
     1069     
     1070      exit(1);
     1071
     1072
     1073    }
     1074 
     1075
     1076  if((fontrain+fontest) > 1.00 ||
     1077     (fofftrain+fofftest) >1.00)
     1078   
     1079    {
     1080      *fLog << err
     1081            << "MFindSupercutsONOFFThetaLoop::SetFractionTrainTestOnOffEvents: "
     1082            << endl
     1083            << "The sum of the fractions of TRAIN/TEST for ON or OFF data which were specified by user " << endl
     1084            << "are larger than 1.0. " << endl
     1085            << "Set reasonable fraction numbers for TRAIN/TEST please. The program will be aborted."
     1086            << endl;
     1087     
     1088      exit(1);
     1089
     1090
     1091    }
     1092
    10611093
    10621094    fWhichFractionTrain = fontrain;
     
    11541186
    11551187    // Path + "OptSCParametersONOFF" + "ThetaRange"
    1156     // + int {(fThetaMin_fThetaMax)*1000} + ".root"
     1188    // + int {(fThetaMin_fThetaMax)} + ".root"
    11571189
    11581190
     
    11601192
    11611193    // Path + "ON(OFF)Data" + "Train(Test)" + "Matrix" + Fraction
    1162     // + "ThetaRange" + int {(fThetaMin_fThetaMax)*1000} + ".root"
     1194    // + "ThetaRange" + int {(fThetaMin_fThetaMax)} + ".root"
    11631195
    11641196
     
    11761208
    11771209
    1178     Int_t ThetaMinTimes1000 = 0;
    1179     Int_t ThetaMaxTimes1000 = 0;
     1210    //    Int_t ThetaMinTimes1000 = 0;
     1211    // Int_t ThetaMaxTimes1000 = 0;
     1212
     1213    // For MAGIC new (July 2004) Theta is given in deg
     1214
     1215    Int_t ThetaMinInt = 0;
     1216    Int_t ThetaMaxInt = 0;
     1217
     1218
    11801219    Int_t FractionONTrainTimes100 = 0;
    11811220    Int_t FractionONTestTimes100 = 0;
     
    12001239       
    12011240       
    1202         ThetaMinTimes1000 = int(fThetaMin*1000);
    1203         ThetaMaxTimes1000 = int(fThetaMax*1000);
    1204         sprintf(ThetaRangeString, "ThetaRange%d_%dmRad",
    1205                 ThetaMinTimes1000, ThetaMaxTimes1000);
     1241        //ThetaMinTimes1000 = int(fThetaMin*1000);
     1242        //ThetaMaxTimes1000 = int(fThetaMax*1000);
     1243        //sprintf(ThetaRangeString, "ThetaRange%d_%dmRad",
     1244        //      ThetaMinTimes1000, ThetaMaxTimes1000);
     1245
     1246        // For New MAGIC (July 2004)
     1247        // Theta is given in deg, no need to multiply by 1000
     1248       
     1249        // 0.5 is added so that the rounding to integer is correct
     1250        ThetaMinInt = int(fThetaMin + 0.5);
     1251        ThetaMaxInt = int(fThetaMax + 0.5);
     1252        sprintf(ThetaRangeString, "ThetaRange%d_%d_Degrees",
     1253                ThetaMinInt, ThetaMaxInt);
     1254
     1255       
    12061256
    12071257        fThetaRangeStringVector[i] = (ThetaRangeString);
     
    12111261        // endtmp
    12121262
    1213         Double_t tmpdouble = 0.0;
    1214         tmpdouble = fWhichFractionTrain*100 - int(fWhichFractionTrain*100);
    1215        
    1216         FractionONTrainTimes100 = tmpdouble < 0.5 ? int(fWhichFractionTrain*100):
    1217             int(fWhichFractionTrain*100) + 1;
    1218        
    1219 
    1220         tmpdouble = fWhichFractionTest*100 - int(fWhichFractionTest*100);
    1221 
    1222         FractionONTestTimes100 = tmpdouble < 0.5 ? int(fWhichFractionTest*100):
    1223             int(fWhichFractionTest*100) + 1;
    1224        
    1225         tmpdouble = fWhichFractionTrainOFF*100 - int(fWhichFractionTrainOFF*100);
    1226 
    1227         FractionOFFTrainTimes100 = tmpdouble < 0.5 ? int(fWhichFractionTrainOFF*100):
    1228             int(fWhichFractionTrainOFF*100) + 1;
    1229 
    1230         tmpdouble = fWhichFractionTestOFF*100 - int(fWhichFractionTestOFF*100);
    1231         FractionOFFTestTimes100 = tmpdouble < 0.5 ? int(fWhichFractionTestOFF*100):
    1232             int(fWhichFractionTestOFF*100) + 1;
     1263        // 0.5 is added so that the rounding to integer is correct
     1264
     1265        FractionONTrainTimes100 = int(fWhichFractionTrain*100 + 0.5);
     1266        FractionONTestTimes100 = int(fWhichFractionTest*100 + 0.5);
     1267        FractionOFFTrainTimes100 = int(fWhichFractionTrainOFF*100 + 0.5);
     1268        FractionOFFTestTimes100 = int(fWhichFractionTestOFF*100 + 0.5);
     1269         
     1270
    12331271       
    12341272       
     
    15251563        FindSupercuts.SetSizeRange(fSizeCutLow, fSizeCutUp);
    15261564
     1565        FindSupercuts.SetFilters(fLeakMax, fDistMax, fDistMin);
    15271566
    15281567
     
    16271666                  << "Reading Data matrices from root files... " << endl;
    16281667
     1668            /*
    16291669            FindSupercuts.ReadMatrix(fTrainMatrixONFilenameVector[i],
    16301670                                     fTestMatrixONFilenameVector[i]);
    16311671            FindSupercuts.ReadMatrixOFF(fTrainMatrixOFFFilenameVector[i],
    16321672                                        fTestMatrixOFFFilenameVector[i]);
     1673            */
     1674
     1675            FindSupercuts.ReadMatrixTrain(fTrainMatrixONFilenameVector[i],
     1676                                          fTrainMatrixOFFFilenameVector[i]);
     1677
     1678            if (fTestParameters)
     1679              {
     1680                FindSupercuts.ReadMatrixTest(fTestMatrixONFilenameVector[i],
     1681                                             fTestMatrixOFFFilenameVector[i]);
     1682              }
    16331683
    16341684        }
     
    23252375       
    23262376            // TEMP   
    2327             // cout << NexVSAlphaNameTmp << endl;
    2328             // cout << SignificanceVSAlphaNameTmp << endl;
     2377            //cout << NexVSAlphaNameTmp << endl;
     2378            //cout << SignificanceVSAlphaNameTmp << endl;
    23292379            // ENDTEMP
    23302380             
     
    23882438
    23892439            AlphaOFFAfterCuts = (TH1F*) rootfile.Get(TmpAlphaOFFHistoName);
     2440
     2441           
     2442
    23902443           
    23912444
     
    28852938{
    28862939
     2940
     2941   *fLog << endl << endl
     2942        << "****************************************************************************" << endl
     2943        << "Combining number of excess events and significance for the  " << endl
     2944        << "selected bins in theta angle using the function " << endl
     2945        << " MFindSupercutsONOFFThetaLoop::ComputeOverallSignificance() " << endl
     2946        << "****************************************************************************" << endl
     2947        << endl;
     2948 
     2949
     2950
     2951 
     2952
     2953
    28872954    // First of all let's check that we have the proper the "drinks" for the party
    28882955
     
    29172984    // Remember that histogram index START AT 1 !!!
    29182985
     2986
     2987
     2988    // Histograms that will contain the alpha distributions
     2989    // for the combined theta bins
     2990
     2991
    29192992    TH1F* CombinedAlphaTrainON = NULL;
    2920     TString CombinedAlphaTrainONName = ("CombinedAlphaTrainON");
     2993    TString CombinedAlphaTrainONName = ("TrainSampleAlphaONCombinedThetaBins");
    29212994    TH1F* CombinedAlphaTrainOFF = NULL;
    2922     TString CombinedAlphaTrainOFFName = ("CombinedAlphaTrainOFF");
     2995    TString CombinedAlphaTrainOFFName = ("TrainSampleAlphaOFFCombinedThetaBins");
    29232996   
    29242997    TH1F* CombinedAlphaTestON = NULL;
    2925     TString CombinedAlphaTestONName = ("CombinedAlphaTestON");
     2998    TString CombinedAlphaTestONName = ("TestSampleAlphaONCombinedThetaBins");
    29262999   
    29273000    TH1F* CombinedAlphaTestOFF = NULL;
    2928     TString CombinedAlphaTestOFFName = ("CombinedAlphaTestOFF");
     3001    TString CombinedAlphaTestOFFName = ("TestSampleAlphaONCombinedThetaBins");
    29293002   
    2930 
    2931    
     3003   
     3004
    29323005
    29333006   
     
    30893162    {
    30903163
     3164
     3165     
     3166      *fLog << endl
     3167        << "****************************************************************************" << endl
     3168        << "Combining data for the TRAIN sample " << endl
     3169        << "****************************************************************************" << endl
     3170        << endl;
     3171
    30913172        // Retrieving NormFactorTrainHisto from root file.
    30923173       
     
    34893570        CombinedAlphaTrainOFF->SetEntries(tmpint);
    34903571
    3491 
     3572        // Check that the number of events in the combined normalized histogram is
     3573        // that of the initial sample
     3574
     3575        /*
    34923576        cout << "SILLY INFO FOR TRAIN SAMPLE: Total number of events Before nomralization and "
    34933577             << " re-re normalized" << endl
    34943578             << TotalNumberOFFTrain << " - " << EventCounter << endl;
    34953579
     3580        */
    34963581    }
    34973582
     
    35063591    if (CombineTestData)
    35073592    {
     3593
     3594      *fLog << endl
     3595        << "****************************************************************************" << endl
     3596        << "Combining data for the TEST sample " << endl
     3597        << "****************************************************************************" << endl
     3598        << endl;
     3599
    35083600
    35093601        // Retrieving NormFactorTestHisto from root file.
     
    39304022
    39314023
     4024        // Check that the number of events in the combined normalized histogram is
     4025        // that of the initial sample
     4026
     4027        /*
    39324028        cout << "SILLY INFO FOR TEST SAMPLE: Total number of events Before nomralization and "
    39334029             << " re-re normalized" << endl
    39344030             << TotalNumberOFFTest << " - " << EventCounter << endl;
     4031
     4032        */
     4033
    39354034
    39364035        /*
     
    39824081    if (SuccessfulThetaBinsVector.GetSize() >= 1)
    39834082    {
     4083
     4084
     4085      *fLog << endl
     4086        << "**************************************************************************************" << endl
     4087        << "Computation of excess events and singnificance for the combined alpha histograms " << endl
     4088        << "**************************************************************************************" << endl
     4089        << endl;
     4090
    39844091        // There is, at least, ONE theta bin for which optimization of
    39854092        // supercuts was SUCCESSFUL, and thus, it is worth to
     
    40264133
    40274134            // Name of psfile where Alpha plot will be stored
    4028             TString psfilename = ("TRAINSampleCombined");
     4135         
     4136            TString psfilename = (fPathForFiles);
     4137            psfilename += ("TRAINSampleCombinedThetaBins");
    40294138           
    40304139            findsig.FindSigmaONOFF(CombinedAlphaTrainON, CombinedAlphaTrainOFF,
     
    40534162
    40544163            // Name of psfile where Alpha plot will be stored
    4055             TString psfilename = ("TESTSampleCombined");
     4164          TString psfilename = (fPathForFiles);
     4165          psfilename += ("TESTSampleCombinedThetaBins");
    40564166           
    40574167            findsig.FindSigmaONOFF(CombinedAlphaTestON, CombinedAlphaTestOFF,
     
    40754185       
    40764186
     4187        *fLog << endl
     4188              << "**************************************************************************************" << endl
     4189              << "Alpha distributions (Train/Test and ON/OFF) for the combined  " << endl
     4190              << " theta bins are stored in the root file " << endl
     4191              << fAlphaDistributionsRootFilename << endl
     4192              << "**************************************************************************************" << endl
     4193        << endl;
     4194
     4195
     4196
     4197        TFile rootfiletowrite(fAlphaDistributionsRootFilename, "UPDATE");
     4198
     4199
     4200       
     4201        // Histograms that will contain the Norm factors for the
     4202        // combined TRAIN/TEST theta bins are created
     4203
     4204       
     4205        TString CombinedNormFactorTrainName = ("TrainSampleNormFactorCombinedThetaBins");
     4206        TH1F CombinedNormFactorTrain (CombinedNormFactorTrainName,
     4207                                      CombinedNormFactorTrainName,
     4208                                      1, 0.0, 1.0);
     4209
     4210        TString CombinedNormFactorTestName = ("TestSampleNormFactorCombinedThetaBins");
     4211        TH1F CombinedNormFactorTest (CombinedNormFactorTestName,
     4212                                     CombinedNormFactorTestName,
     4213                                     1, 0.0, 1.0);
     4214
     4215
     4216        if (CombineTrainData)
     4217        {
     4218
     4219        // Histogram that will contain the Norm factors for the
     4220        // combined TRAIN theta bins are filled
     4221       
     4222       
     4223        CombinedNormFactorTrain.Fill(0.5, MeanNormFactorTrain);
     4224
     4225
     4226        // Train histos are written to root file
     4227       
     4228        CombinedAlphaTrainON -> Write();
     4229        CombinedAlphaTrainOFF -> Write();
     4230        CombinedNormFactorTrain.Write();
     4231
     4232
     4233
     4234        }
     4235
     4236
     4237        if (CombineTestData)
     4238        {
     4239
     4240          // Histogram that will contain the Norm factors for the
     4241        // combined TEST theta bins are filled
     4242
     4243       
     4244          CombinedNormFactorTest.Fill(0.5, MeanNormFactorTest);
     4245
     4246          // Test histos are written to root file
     4247
     4248        CombinedAlphaTestON -> Write();
     4249        CombinedAlphaTestOFF -> Write();
     4250        CombinedNormFactorTest.Write();
     4251       
     4252
     4253        }
     4254
     4255
     4256        // Root file is closed
     4257
     4258        rootfiletowrite.Close();
     4259
    40774260       
    40784261    }
Note: See TracChangeset for help on using the changeset viewer.