Changeset 4584 for trunk/MagicSoft/Mars


Ignore:
Timestamp:
08/12/04 06:58:34 (20 years ago)
Author:
wittek
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/Changelog

    r4581 r4584  
    1919
    2020                                                 -*-*- END OF LINE -*-*-
     21
     22
     23
     24  2004/08/12 : Wolfgang Wittek
     25
     26    * manalysis/MSigmabarCalc.[h,cc]
     27      - replace MMcEvt by MPointingPos
     28
     29    * manalysis/MSigmabar.[h,cc]
     30      - in member function Calc() return fSigmabarInner,
     31        not fSigmabar
     32      - update comments
     33      - sigmabar is the sqrt of the average (pedRMS^2/area)
     34
     35    * manalysis/MPad.[h,cc]
     36      - replace MMcEvt by MPointingPos
     37      - remove bugs
     38
     39    * mfilter/MFSelBasic.[h,cc]
     40      - replace MMcEvt by MPointingPos
     41
     42    * mfilter/Makefile
     43      - add -I../mpointing
     44
     45
     46    * mhist/MHSigmaTheta.[h,cc]
     47      - replace MMcEvt by MPointingPos     
     48      - replace 'MCerPhotPix cerpix' by 'MCerPhotPix &cerpix'
     49      - add plot "Sigmabar(Outer) versus Theta"
     50
     51    * macros/ONOFFAnalysis.C
     52      - Job A : got the padding working, work in progress
    2153
    2254
  • trunk/MagicSoft/Mars/macros/ONOFFAnalysis.C

    r3598 r4584  
    171171      //-----------------------------------------------
    172172      //TString tag = "040126";
    173       TString tag = "040127";
    174       //TString tag = "040215";
     173      //TString tag = "040127";
     174      TString tag = "040215";
    175175
    176176      //const char *offfile = "~magican/ct1test/wittek/offdata.preproc";
     
    183183      //const char *offfile  = "*.OFF";
    184184      // 15 Feb 04
    185       const char *offfile  = "*.OFF";
     185      //const char *offfile  = "*.OFF";
     186      const char *offfile  = "174*.OFF";
    186187
    187188
     
    191192      //const char *onfile  = "MCerPhot_output";
    192193      //const char *onfile  = "*.ON";
    193       const char *onfile  = "1216*.ON";
     194      //const char *onfile  = "1216*.ON";
    194195      // 27 Jan 04
    195196      //const char *onfile  = "12*.ON";
     
    198199      // 15 Feb 04
    199200      //const char *onfile  = "*.ON";
    200 
    201 
    202      const char *mcfile  = "/data/MAGIC/mc_eth/magLQE_3/gh/0/0/G_M0_00_0_550*.root";
     201      const char *onfile  = "174*.ON";
     202
     203
     204      //const char *mcfile  = "/data/MAGIC/mc_eth/magLQE_3/gh/0/0/G_M0_00_0_550*.root";
    203205      //const char *mcfile  = "/data/MAGIC/mc_eth/magLQE_4/gh/0/0/G_M0_00_0_550*.root";
    204206      //const char *mcfile  = "/data/MAGIC/mc_eth/magLQE_5/gh/0/0/G_M0_00_0_550*.root";
     207      //const char *mcfile = "calibrated_gammas";
     208      const char *mcfile = "calibrated_data_david*";
     209
    205210      //-----------------------------------------------
    206211
     
    224229
    225230     // 15 Feb 04, David
    226      if (tag == "040215")
    227        TString inPath = "/mnt/magicserv01/scratch/David/CalibratedData/Crab/2004_02_15/";
    228    
     231     //if (tag == "040215")
     232     //  TString inPath = "/mnt/magicserv01/scratch/David/CalibratedData/Crab/2004_02_15/";
     233     if (tag == "040215")   
     234       TString inPathON = "/.magic/magicserv01/scratch/Daniel/CalibratedData/MispointingTest/2004_02_15ForgottenData/finesam20/";
     235       TString inPathOFF = "/.magic/magicserv01/scratch/David/CalibratedData/Mkn421/2004_02_15/";
     236       TString inPathMC = "/.magic/magicserv01/scratch/David/MCData/MCApril2004/Data/gammas_highnoise/";
    229237
    230238      // path for output from Mars
    231239      //TString outPath = "~wittek/datacrab_feb04/";
    232240     //TString outPath = "~wittek/datacrab_01march04/";
    233       TString outPath = "~wittek/datacrab_19mar04/";
     241      TString outPath = "~wittek/datacrab_27april04/";
    234242
    235243      //-----------------------------------------------
     
    248256
    249257    Bool_t JobA    = kTRUE; 
    250     Bool_t GPad    = kFALSE;    // generate padding histograms?
    251     Bool_t WPad    = kFALSE;   // write out padding histograms ?
    252     Bool_t RPad    = kFALSE;   // read in padding histograms ?
    253     Bool_t Wout    = kTRUE;   // write out root file ON1.root
    254                                // (or OFF1.root or MC1.root)?
     258    Bool_t GPadON  = kFALSE;    // \  generate padding histograms
     259    Bool_t GPadOFF = kFALSE;    //  | and write them onto disk
     260    Bool_t GPadMC  = kFALSE;    // /
     261    Bool_t Merge   = kFALSE;   // merge padding histograms
     262                               // and write them onto disk
     263    Bool_t Wout    = kTRUE;   // read in merged padding histograms and
     264                              // write out root file of padded data
     265                              // (ON1.root, OFF1.root or MC1.root)
    255266
    256267
     
    310321    // Job E_XX : extended version of E_XX (including flux plots) 
    311322    //  - select g/h separation method XX
    312     //  - read MC root file 
    313     //  - calculate eff. collection area
     323    //  - read MC root file
     324    //  - calculate eff. collection area
    314325    //  - optimize energy estimator
    315326    //  - read ON root file
     
    346357    gLog << "Macro ONOFFAnalysis : Start of Job A" << endl;
    347358    gLog << "" << endl;
    348     gLog << "Macro ONOFFAnalysis : JobA, WPad, RPad, Wout = "
    349          << (JobA ? "kTRUE" : "kFALSE")  << ",  "
    350          << (WPad ? "kTRUE" : "kFALSE")  << ",  "
    351          << (RPad ? "kTRUE" : "kFALSE")  << ",  "
    352          << (Wout ? "kTRUE" : "kFALSE")  << endl;
     359    gLog << "Macro ONOFFAnalysis : JobA, GPadON, GPadOFF, GPadMC, Merge, Wout = "
     360         << (JobA    ? "kTRUE" : "kFALSE")  << ",  "
     361         << (GPadON  ? "kTRUE" : "kFALSE")  << ",  "
     362         << (GPadOFF ? "kTRUE" : "kFALSE")  << ",  "
     363         << (GPadMC  ? "kTRUE" : "kFALSE")  << ",  "
     364         << (Merge   ? "kTRUE" : "kFALSE")  << ",  "
     365         << (Wout    ? "kTRUE" : "kFALSE")  << endl;
    353366   
    354367
     
    358371
    359372
    360     TString fileON  = inPath;
     373    TString fileON  = inPathON;
    361374    fileON += onfile;
    362375    fileON += ".root";
    363376
    364     TString fileOFF = inPath;
     377    TString fileOFF = inPathOFF;
    365378    fileOFF += offfile;
    366379    fileOFF += ".root";
    367380
    368     TString fileMC  = mcfile;
     381    TString fileMC = inPathMC;
    369382    fileMC += mcfile;
    370383    fileMC += ".root";
     
    373386         << fileOFF << ",  " << fileMC   << endl;
    374387
    375     // name of file to conatin the histograms for the padding
     388    // name of file to conatin the merged histograms for the padding
    376389    TString outNameSigTh = outPath;
    377390    outNameSigTh += "SigmaTheta";
     
    379392
    380393    //--------------------------------------------------
     394    // name of files to contain the paddding histograms of ON, OFF and MC data
     395      TString NamePadON(outPath);
     396      NamePadON += "PadON";
     397      NamePadON += ".root";
     398
     399      TString NamePadOFF(outPath);
     400      NamePadOFF += "PadOFF";
     401      NamePadOFF += ".root";
     402
     403      TString NamePadMC(outPath);
     404      NamePadMC += "PadMC";
     405      NamePadMC += ".root";
     406
     407    //--------------------------------------------------
    381408    // type of data to be padded
    382     TString typeInput = "ON";
    383     //TString typeInput = "OFF";
    384     //TString typeInput = "MC";
     409      //TString typeInput = "ON";
     410      //TString typeInput = "OFF";
     411      TString typeInput = "MC";
    385412    gLog << "typeInput = " << typeInput << endl;
    386413
     
    416443    //
    417444    // read ON, OFF and MC data files
    418     // generate (or read in) the padding histograms for ON and OFF data
    419     //                       and merge these histograms
     445    // generate (or read in) the padding histograms for ON, OFF and MC data
     446    //
    420447
    421448    MPad pad;
     
    423450    pad.SetDataType(typeInput);
    424451
     452    if (GPadON || GPadOFF || GPadMC)
     453    {
    425454    // generate the padding histograms
    426     if (GPad)
    427     {
    428455      gLog << "=====================================================" << endl;
    429456      gLog << "Start generating the padding histograms" << endl;
     457    }
     458
    430459      //-----------------------------------------
    431460      // ON events
     461
     462      if (GPadON)
     463      {
    432464
    433465      gLog << "-----------" << endl;
     
    438470      MParList pliston;
    439471
     472    MObservatory observon;
     473
    440474    MReadMarsFile  readON("Events", fileON);
    441475    readON.DisableAutoScheme();
    442     //MCT1ReadPreProc readON(fileON);
    443 
    444       //MFSelBasic selthetaon;
    445       //selthetaon.SetCuts(-100.0, 29.5, 35.5);
    446       //MContinue contthetaon(&selthetaon);
    447 
    448       MBlindPixelCalc blindon;
    449       blindon.SetUseBlindPixels();
     476
     477    MGeomApply        apply;
     478
     479    MSourcePosfromStarPos sourcefromstaron;
     480    sourcefromstaron.AddFile("~wittek/datacrab_26feb04/positions040215.txt", 0);
     481
     482      MBlindPixelsCalc2 blindon;
     483      //blindon.SetUseBlindPixels();
     484      blindon.SetCheckPedestalRms();
    450485
    451486      MFSelBasic selbasicon;
     
    459494
    460495      MHSigmaTheta sigthON("SigmaThetaON");
    461       MFillH fillsigthetaON ("SigmaThetaON[MHSigmaTheta]", "MMcEvt");
     496      MFillH fillsigthetaON ("SigmaThetaON[MHSigmaTheta]", "MPointingPos");
    462497      fillsigthetaON.SetName("FillSigTheta");   
    463498 
     
    467502      pliston.AddToList(&tliston);
    468503      InitBinnings(&pliston);
     504      pliston.AddToList(&observon);
    469505      pliston.AddToList(&blindON);
    470506      pliston.AddToList(&sigthON);
     
    475511   
    476512      tliston.AddToList(&readON);
    477       //tliston.AddToList(&contthetaon);
     513      tliston.AddToList(&apply);
     514      tliston.AddToList(&sourcefromstaron);
    478515
    479516      tliston.AddToList(&blindon);
     
    489526      evtloopon.SetProgressBar(&baron);
    490527
    491       Int_t maxeventson = -1;
    492       //Int_t maxeventson = 10000;
     528      //Int_t maxeventson = -1;
     529      Int_t maxeventson = 10000;
    493530      if ( !evtloopon.Eventloop(maxeventson) )
    494531          return;
     
    507544      TH2D *blindnthon  = blindON.GetBlindN();
    508545
     546      gLog << "" << endl;
     547      gLog << "Macro ONOFFAnalysis : write padding plots for ON data from file "
     548           << NamePadON << endl;
     549
     550      TFile filewriteon(NamePadON, "RECREATE", "");
     551      sigthon->Write();
     552      sigpixthon->Write();
     553      diffpixthon->Write();
     554      blindidthon->Write();
     555      blindnthon->Write();
     556      filewriteon.Close();
     557
     558      gLog << "" << endl;
     559      gLog << "Macro ONOFFAnalysis : padding plots for ON data written onto file "
     560           << NamePadON << endl;
     561      }
     562      // end of GPadON
     563
     564
    509565      //-----------------------------------------
    510566      // OFF events
     567
     568      if (GPadOFF)
     569      {
    511570
    512571      gLog << "------------" << endl;
     
    517576      MParList plistoff;
    518577
     578    MObservatory observoff;
     579
    519580    MReadMarsFile  readOFF("Events", fileOFF);
    520581    readOFF.DisableAutoScheme();
    521     //      MCT1ReadPreProc readOFF(fileOFF);
    522 
    523       MFSelBasic selthetaoff;
    524       selthetaoff.SetCuts(-100.0, 29.5, 35.5);
    525       MContinue contthetaoff(&selthetaoff);
    526 
    527       MBlindPixelCalc blindoff;
    528       blindoff.SetUseBlindPixels();
     582
     583    MSourcePosfromStarPos sourcefromstaroff;
     584    sourcefromstaroff.AddFile("~wittek/datacrab_26feb04/positions040215.txt", 0);
     585
     586      MBlindPixelsCalc2 blindoff;
     587      //blindoff.SetUseBlindPixels();
     588      blindoff.SetCheckPedestalRms();
    529589
    530590      MFSelBasic selbasicoff;
     
    538598
    539599      MHSigmaTheta sigthOFF("SigmaThetaOFF");
    540       MFillH fillsigthetaOFF ("SigmaThetaOFF[MHSigmaTheta]", "MMcEvt");
     600      MFillH fillsigthetaOFF ("SigmaThetaOFF[MHSigmaTheta]", "MPointingPos");
    541601      fillsigthetaOFF.SetName("FillSigThetaOFF");     
    542602
     
    546606      plistoff.AddToList(&tlistoff);
    547607      InitBinnings(&plistoff);
     608      plistoff.AddToList(&observoff);
    548609      plistoff.AddToList(&blindOFF);
    549610      plistoff.AddToList(&sigthOFF);
     
    554615   
    555616      tlistoff.AddToList(&readOFF);
    556       //tlistoff.AddToList(&contthetaoff);
     617      tlistoff.AddToList(&sourcefromstaroff);
    557618
    558619      tlistoff.AddToList(&blindoff);
     
    568629      evtloopoff.SetProgressBar(&baroff);
    569630
    570       Int_t maxeventsoff = -1;
    571       //Int_t maxeventsoff = 20000;
     631      //Int_t maxeventsoff = -1;
     632      Int_t maxeventsoff = 10000;
    572633      if ( !evtloopoff.Eventloop(maxeventsoff) )
    573634          return;
     
    586647      TH2D *blindnthoff  = blindOFF.GetBlindN();
    587648
     649      gLog << "" << endl;
     650      gLog << "Macro ONOFFAnalysis : write padding plots for OFF data from file "
     651           << NamePadOFF << endl;
     652
     653      TFile filewriteoff(NamePadOFF, "RECREATE", "");
     654      sigthoff->Write();
     655      sigpixthoff->Write();
     656      diffpixthoff->Write();
     657      blindidthoff->Write();
     658      blindnthoff->Write();
     659      filewriteoff.Close();
     660
     661      gLog << "" << endl;
     662      gLog << "Macro ONOFFAnalysis : padding plots for OFF data written onto file "
     663           << NamePadOFF << endl;
     664      }
     665      // end of GPadOFF
     666
     667
    588668
    589669      //-----------------------------------------
    590670      // MC events
     671
     672      if (GPadMC)
     673      {
    591674
    592675      gLog << "------------" << endl;
     
    597680      MParList plistmc;
    598681
     682    MObservatory observmc;
     683
    599684    MReadMarsFile  readMC("Events", fileMC);
    600685    readMC.DisableAutoScheme();
    601     //      MCT1ReadPreProc readMC(fileMC);
    602 
    603       MFSelBasic selthetamc;
    604       selthetamc.SetCuts(-100.0, 29.5, 35.5);
    605       MContinue contthetamc(&selthetamc);
    606 
    607       MBlindPixelCalc blindmc;
    608       blindmc.SetUseBlindPixels();
     686
     687    MSourcePosfromStarPos sourcefromstarmc;
     688
     689      MBlindPixelsCalc2 blindmc;
     690      //blindmc.SetUseBlindPixels();
     691      blindmc.SetCheckPedestalRms();
    609692
    610693      MFSelBasic selbasicmc;
     
    618701
    619702      MHSigmaTheta sigthMC("SigmaThetaMC");
    620       MFillH fillsigthetaMC ("SigmaThetaMC[MHSigmaTheta]", "MMcEvt");
     703      MFillH fillsigthetaMC ("SigmaThetaMC[MHSigmaTheta]", "MPointingPos");
    621704      fillsigthetaMC.SetName("FillSigThetaMC");     
    622705
     
    626709      plistmc.AddToList(&tlistmc);
    627710      InitBinnings(&plistmc);
     711      plistmc.AddToList(&observmc);
    628712      plistmc.AddToList(&blindMC);
    629713      plistmc.AddToList(&sigthMC);
     
    634718   
    635719      tlistmc.AddToList(&readMC);
    636       //tlistmc.AddToList(&contthetamc);
     720      tlistmc.AddToList(&sourcefromstarmc);
    637721
    638722      tlistmc.AddToList(&blindmc);
     
    648732      evtloopmc.SetProgressBar(&barmc);
    649733
    650       Int_t maxeventsmc = -1;
    651       //Int_t maxeventsmc = 20000;
     734      //Int_t maxeventsmc = -1;
     735      Int_t maxeventsmc = 10000;
    652736      if ( !evtloopmc.Eventloop(maxeventsmc) )
    653737          return;
     
    666750      TH2D *blindnthmc  = blindMC.GetBlindN();
    667751
     752      gLog << "" << endl;
     753      gLog << "Macro ONOFFAnalysis : write padding plots for MC data from file "
     754           << NamePadMC << endl;
     755
     756      TFile filewritemc(NamePadMC, "RECREATE", "");
     757      sigthmc->Write();
     758      sigpixthmc->Write();
     759      diffpixthmc->Write();
     760      blindidthmc->Write();
     761      blindnthmc->Write();
     762      filewritemc.Close();
     763
     764      gLog << "" << endl;
     765      gLog << "Macro ONOFFAnalysis : padding plots for MC data written onto file "
     766           << NamePadMC << endl;
     767      }
     768      // end of GPadMC
    668769
    669770      //-----------------------------------------
    670771
     772    if (GPadON || GPadOFF || GPadMC)
     773    {
     774      gLog << "" << endl;
    671775      gLog << "End of generating the padding histograms" << endl;
    672776      gLog << "=====================================================" << endl;
    673 
    674       pad.MergeONOFFMC(sigthmc,      diffpixthmc,  sigpixthmc,
    675                        blindidthmc,  blindnthmc,
    676                        sigthon,      diffpixthon,  sigpixthon,
    677                        blindidthon,  blindnthon,
    678                        sigthoff,     diffpixthoff, sigpixthoff,
    679                        blindidthoff, blindnthoff);
    680 
    681 
    682       if (WPad)
    683       {
    684         // write the padding histograms onto a file  ---------
    685         pad.WritePaddingDist(outNameSigTh);     
    686       }
    687777    }
    688778
    689     // read the padding histograms ---------------------------
    690     if (RPad)
     779    if (Merge)
    691780    {
    692       pad.ReadPaddingDist(outNameSigTh);
     781
     782      //-----------------------------------
     783      TH2D sigon;
     784      TH3D sigpixon;
     785      TH3D diffpixon;
     786      TH2D blindidon;
     787      TH2D blindnon;
     788
     789      TFile filereadon(NamePadON);
     790      filereadon.ls();
     791      sigon.Read("2D-ThetaSigmabar(Inner)");
     792      sigpixon.Read("3D-ThetaPixSigma");
     793      diffpixon.Read("3D-ThetaPixDiff");
     794      blindidon.Read("2D-IdBlindPixels");
     795      blindnon.Read("2D-NBlindPixels");
     796
     797      TH2D *sigthon     = new TH2D( (const TH2D&)sigon     );
     798      TH3D *sigpixthon  = new TH3D( (const TH3D&)sigpixon  );
     799      TH3D *diffpixthon = new TH3D( (const TH3D&)diffpixon );
     800      TH2D *blindidthon = new TH2D( (const TH2D&)blindidon );
     801      TH2D *blindnthon  = new TH2D( (const TH2D&)blindnon  );
     802
     803      /*
     804      TH2D *sigthon     = (TH2D*)sigon.Clone();
     805      TH3D *sigpixthon  = (TH3D*)sigpixon.Clone();
     806      TH3D *diffpixthon = (TH3D*)diffpixon.Clone();
     807      TH2D *blindidthon = (TH2D*)blindidon.Clone();
     808      TH2D *blindnthon  = (TH2D*)blindnon.Clone();
     809      */
     810
     811      //filereadon.Close();
     812      gLog << "" << endl;
     813      gLog << "Macro ONOFFAnalysis : padding plots for ON data read from file "
     814           << NamePadON << endl;
     815
     816
     817      //-----------------------------------
     818      TH2D sigoff;
     819      TH3D sigpixoff;
     820      TH3D diffpixoff;
     821      TH2D blindidoff;
     822      TH2D blindnoff;
     823
     824      TFile filereadoff(NamePadOFF);
     825      filereadoff.ls();
     826      sigoff.Read("2D-ThetaSigmabar(Inner)");
     827      sigpixoff.Read("3D-ThetaPixSigma");
     828      diffpixoff.Read("3D-ThetaPixDiff");
     829      blindidoff.Read("2D-IdBlindPixels");
     830      blindnoff.Read("2D-NBlindPixels");
     831 
     832      TH2D *sigthoff     = new TH2D( (const TH2D&)sigoff     );
     833      TH3D *sigpixthoff  = new TH3D( (const TH3D&)sigpixoff  );
     834      TH3D *diffpixthoff = new TH3D( (const TH3D&)diffpixoff );
     835      TH2D *blindidthoff = new TH2D( (const TH2D&)blindidoff );
     836      TH2D *blindnthoff  = new TH2D( (const TH2D&)blindnoff  );
     837
     838      /*
     839      TH2D *sigthoff     = (TH2D*)sigoff.Clone();
     840      TH3D *sigpixthoff  = (TH3D*)sigpixoff.Clone();
     841      TH3D *diffpixthoff = (TH3D*)diffpixoff.Clone();
     842      TH2D *blindidthoff = (TH2D*)blindidoff.Clone();
     843      TH2D *blindnthoff  = (TH2D*)blindnoff.Clone();
     844      */
     845
     846      //filereadoff.Close();
     847      gLog << "" << endl;
     848      gLog << "Macro ONOFFAnalysis : padding plots for OFF data read from file "
     849           << NamePadOFF << endl;
     850
     851
     852      //-----------------------------------
     853      TH2D sigmc;
     854      TH3D sigpixmc;
     855      TH3D diffpixmc;
     856      TH2D blindidmc;
     857      TH2D blindnmc;
     858
     859      TFile filereadmc(NamePadMC);
     860      filereadmc.ls();
     861      sigmc.Read("2D-ThetaSigmabar(Inner)");
     862      sigpixmc.Read("3D-ThetaPixSigma");
     863      diffpixmc.Read("3D-ThetaPixDiff");
     864      blindidmc.Read("2D-IdBlindPixels");
     865      blindnmc.Read("2D-NBlindPixels");
     866 
     867      TH2D *sigthmc     = new TH2D( (const TH2D&)sigmc     );
     868      TH3D *sigpixthmc  = new TH3D( (const TH3D&)sigpixmc  );
     869      TH3D *diffpixthmc = new TH3D( (const TH3D&)diffpixmc );
     870      TH2D *blindidthmc = new TH2D( (const TH2D&)blindidmc );
     871      TH2D *blindnthmc  = new TH2D( (const TH2D&)blindnmc  );
     872
     873      /*
     874      TH2D *sigthmc     = (TH2D*)sigmc.Clone();
     875      TH3D *sigpixthmc  = (TH3D*)sigpixmc.Clone();
     876      TH3D *diffpixthmc = (TH3D*)diffpixmc.Clone();
     877      TH2D *blindidthmc = (TH2D*)blindidmc.Clone();
     878      TH2D *blindnthmc  = (TH2D*)blindnmc.Clone();
     879      */
     880
     881      //filereadmc.Close();
     882      gLog << "" << endl;
     883      gLog << "Macro ONOFFAnalysis : padding plots for MC data read from file "
     884           << NamePadMC << endl;
     885
     886      pad.MergeONOFFMC(*sigthmc,     *diffpixthmc, *sigpixthmc,
     887                       *blindidthmc, *blindnthmc,
     888                       *sigthon,     *diffpixthon, *sigpixthon,
     889                       *blindidthon, *blindnthon,
     890                       *sigthoff,    *diffpixthoff,*sigpixthoff,
     891                       *blindidthoff,*blindnthoff);
     892
     893      // write the target padding histograms onto a file  ---------
     894      pad.WritePaddingDist(outNameSigTh);     
    693895    }
     896    // end of Merge
     897
    694898
    695899
     
    698902  if (Wout)
    699903  {
     904    // read the target padding histograms ---------------------------
     905    pad.ReadPaddingDist(outNameSigTh);
     906
     907
    700908    gLog << "=====================================================" << endl;
    701909    gLog << "Start the padding" << endl;
     
    723931    MGeomApply        apply;
    724932
    725     //MPedestalWorkaround waround;
    726 
    727933    // a way to find out whether one is dealing with MC :
    728     MFDataMember f1("MRawRunHeader.fRunType", '>', 255.5);  // MC
    729     f1.SetName("Select MC");
    730     MFDataMember f2("MRawRunHeader.fRunType", '<', 255.5);  // data
    731     f2.SetName("Select Data");
    732 
    733     //if (typeInput ==  "ON")
    734     //{
    735     //   MCT1PointingCorrCalc pointcorr(sourceName, "MCT1PointingCorrCalc",
    736     //                                             "MCT1PointingCorrCalc");
    737     //}
     934    //MFDataMember f1("MRawRunHeader.fRunType", '>', 255.5);  // MC
     935    //f1.SetName("Select MC");
     936    //MFDataMember f2("MRawRunHeader.fRunType", '<', 255.5);  // data
     937    //f2.SetName("Select Data");
     938
    738939    MSourcePosfromStarPos sourcefromstar;
    739940    if (typeInput == "ON")
    740941    {
    741       sourcefromstar.SetSourceAndStarPosition(
    742                                "Crab", 22,  0, 52, 5, 34, 32.0,
    743                            "Zeta-Tau", 21,  8, 33, 5, 37, 38.7);
    744       sourcefromstar.AddStar("Tau114", 21, 56, 13, 5, 27, 38.1);
    745       //sourcefromstar.AddFile("~wittek/datacrab_26feb04/positionsOn.4.txt",0);
    746 
    747       if(inPath == "/.magic/magicserv01/scratch/calibrated/")
    748       {
    749         sourcefromstar.AddFile("~wittek/datacrab_26feb04/positions2stars.txt", 0);
    750         //sourcefromstar.AddFile("~wittek/datacrab_26feb04/positionsNoStar.txt", 0);
    751       }
    752       else if(inPath == "/.magic/magicserv01/scratch/calibrated26/")
    753         sourcefromstar.AddFile("~wittek/datacrab_26feb04/stars_2004_01_26", 0);
    754 
    755       else if(inPath == "/mnt/magicserv01/scratch/David/CalibratedData/Crab/2004_02_15/")
    756         sourcefromstar.AddFile("~wittek/datacrab_26feb04/positions040215.txt", 0);
     942      //sourcefromstar.SetSourceAndStarPosition(
     943      //                         "Crab", 22,  0, 52, 5, 34, 32.0,
     944      //                           "Zeta-Tau", 21,  8, 33, 5, 37, 38.7);
     945      //sourcefromstar.AddStar("Tau114", 21, 56, 13, 5, 27, 38.1);
     946      ////sourcefromstar.AddFile("~wittek/datacrab_26feb04/positionsOn.4.txt",0);
     947
     948      //if(inPath == "/.magic/magicserv01/scratch/calibrated/")
     949      //{
     950        //sourcefromstar.AddFile("~wittek/datacrab_26feb04/positions2stars.txt", 0);
     951        ////sourcefromstar.AddFile("~wittek/datacrab_26feb04/positionsNoStar.txt", 0);
     952      //}
     953      //else if(inPath == "/.magic/magicserv01/scratch/calibrated26/")
     954      //  sourcefromstar.AddFile("~wittek/datacrab_26feb04/stars_2004_01_26", 0);
     955
     956      //else if(inPath == "/mnt/magicserv01/scratch/David/CalibratedData/Crab/2004_02_15/")
     957      sourcefromstar.AddFile("~wittek/datacrab_26feb04/positions040215.txt", 0);
    757958    }
    758959    else if (typeInput == "OFF")
    759960    {
    760       if(inPath == "/.magic/magicserv01/scratch/calibrated/")
    761         sourcefromstar.AddFile("~wittek/datacrab_26feb04/positionsOff.txt", 0);
    762       else if(inPath == "/.magic/magicserv01/scratch/calibrated26/")
    763         sourcefromstar.AddFile("~wittek/datacrab_26feb04/positions_2004_01_26", 0);
    764       else if(inPath == "/mnt/magicserv01/scratch/David/CalibratedData/Crab/2004_02_15")
    765         sourcefromstar.AddFile("~wittek/datacrab_26feb04/positions040215.txt", 0);
     961      //if(inPath == "/.magic/magicserv01/scratch/calibrated/")
     962      //  sourcefromstar.AddFile("~wittek/datacrab_26feb04/positionsOff.txt", 0);
     963      //else if(inPath == "/.magic/magicserv01/scratch/calibrated26/")
     964      //  sourcefromstar.AddFile("~wittek/datacrab_26feb04/positions_2004_01_26", 0);
     965      //else if(inPath == "/mnt/magicserv01/scratch/David/CalibratedData/Crab/2004_02_15")
     966      sourcefromstar.AddFile("~wittek/datacrab_26feb04/positions040215.txt", 0);
    766967    }
    767 
    768 
    769     //MBlindPixelCalc blindbeforepad;
     968    else if (typeInput == "MC")
     969    {
     970    }
     971
     972    MBlindPixelsCalc2 blindbeforepad;
    770973    //blindbeforepad.SetUseBlindPixels();
    771     //blindbeforepad.SetName("BlindBeforePadding");
    772 
    773     //MBlindPixelCalc blind;
    774     //blind.SetUseBlindPixels();
    775     //blind.SetUseInterpolation();
    776     //blind.SetName("BlindAfterPadding");
    777 
    778     MSigmabarCalc sigbar;
     974    blindbeforepad.SetCheckPedestalRms();
     975    blindbeforepad.SetName("BlindBeforePadding");
    779976
    780977    //MBadPixelCalcRms blind;
     
    794991    MSigmabarCalc sigbarcalc;
    795992
    796     MFillH fillsigtheta ("SigmaTheta[MHSigmaTheta]", "MMcEvt");
     993    MFillH fillsigtheta ("SigmaTheta[MHSigmaTheta]", "MPointingPos");
    797994    fillsigtheta.SetName("HSigmaTheta");
    798995
     
    8451042      //write.AddContainer("MMcRunHeader",  "RunHeaders", kFALSE);
    8461043      //write.AddContainer("MTime",         "Events");
    847       write.AddContainer("MMcEvt",        "Events");
    848       //write.AddContainer("ThetaOrig",     "Events");
     1044      write.AddContainer("MPointingPos", "Events");
    8491045      write.AddContainer("MSrcPosCam",    "Events");
    8501046      write.AddContainer("MSigmabar",     "Events");
     
    8681064   
    8691065    tliston.AddToList(&read);
    870 
    8711066    //tliston.AddToList(&f1);
    8721067    //tliston.AddToList(&f2);
    8731068    tliston.AddToList(&apply);
    874     //tliston.AddToList(&waround);
    8751069    tliston.AddToList(&sourcefromstar);
    8761070
    877     //tliston.AddToList(&blindbeforepad);
    878     //  tliston.AddToList(&pad);
    879     //  if (typeInput ==  "ON")
    880     //  tliston.AddToList(&pointcorr);
    881 
    882     tliston.AddToList(&sigbar);
     1071    tliston.AddToList(&blindbeforepad);
     1072
     1073    tliston.AddToList(&contbasic);
     1074    tliston.AddToList(&pad);
     1075
    8831076    tliston.AddToList(&blind);
    884     tliston.AddToList(&contbasic);
    885 
    8861077    tliston.AddToList(&fillblind);
    887     //tliston.AddToList(&sigbarcalc);
     1078    tliston.AddToList(&sigbarcalc);
    8881079    tliston.AddToList(&fillsigtheta);
    8891080    tliston.AddToList(&clean);
     
    9131104    //  evtloop.Write();
    9141105
    915     Int_t maxevents = -1;
    916     //Int_t maxevents = 1000;
     1106    //Int_t maxevents = -1;
     1107    Int_t maxevents = 2000;
    9171108    if ( !evtloop.Eventloop(maxevents) )
    9181109        return;
     
    11091300    matrixg.EnableGraphicalOutput();
    11101301
    1111     matrixg.AddColumn("cos(MMcEvt.fTelescopeTheta)");
     1302    matrixg.AddColumn("cos((MPointingPos.fZd)/kRad2Deg)");
    11121303    matrixg.AddColumn("MSigmabar.fSigmabar");
    11131304    matrixg.AddColumn("log10(MHillas.fSize)");
     
    11981389    bing.SetEdges(10, 0., 1.0);
    11991390
    1200     MH3 gref("cos(MMcEvt.fTelescopeTheta)");
     1391    MH3 gref("cos((MPointingPos.fZd)/kRad2Deg)");
    12011392    gref.SetName(mgname);
    12021393    MH::SetBinning(&gref.GetHist(), &bing);
     
    12311422      writetraing.AddContainer("MRawRunHeader", "RunHeaders");
    12321423      writetraing.AddContainer("MTime",         "Events");
    1233       writetraing.AddContainer("MMcEvt",        "Events");
     1424      writetraing.AddContainer("MPointingPos",  "Events");
    12341425      writetraing.AddContainer("ThetaOrig",     "Events");
    12351426      writetraing.AddContainer("MSrcPosCam",    "Events");
     
    12481439      writetestg.AddContainer("MRawRunHeader", "RunHeaders");
    12491440      writetestg.AddContainer("MTime",         "Events");
    1250       writetestg.AddContainer("MMcEvt",        "Events");
     1441      writetestg.AddContainer("MPointingPos",  "Events");
    12511442      writetestg.AddContainer("ThetaOrig",     "Events");
    12521443      writetestg.AddContainer("MSrcPosCam",    "Events");
     
    13311522    binh.SetEdges(10, 0., 1.0);
    13321523
    1333     //MH3 href("cos(MMcEvt.fTelescopeTheta)");
     1524    //MH3 href("cos((MPointingPos.fZd)/kRad2Deg)");
    13341525    //href.SetName(mhname);
    13351526    //MH::SetBinning(&href.GetHist(), &binh);
     
    13661557      writetrainh.AddContainer("MRawRunHeader", "RunHeaders");
    13671558      writetrainh.AddContainer("MTime",         "Events");
    1368       writetrainh.AddContainer("MMcEvt",        "Events");
     1559      writetrainh.AddContainer("MPointingPos",  "Events");
    13691560      writetrainh.AddContainer("ThetaOrig",     "Events");
    13701561      writetrainh.AddContainer("MSrcPosCam",    "Events");
     
    13821573      writetesth.AddContainer("MRawRunHeader", "RunHeaders");
    13831574      writetesth.AddContainer("MTime",         "Events");
    1384       writetesth.AddContainer("MMcEvt",        "Events");
     1575      writetesth.AddContainer("MPointingPos",  "Events");
    13851576      writetesth.AddContainer("ThetaOrig",     "Events");
    13861577      writetesth.AddContainer("MSrcPosCam",    "Events");
     
    16671858      write.AddContainer("MRawRunHeader", "RunHeaders");
    16681859      write.AddContainer("MTime",         "Events");
    1669       write.AddContainer("MMcEvt",        "Events");
     1860      write.AddContainer("MPointingPos",  "Events");
    16701861      write.AddContainer("ThetaOrig",     "Events");
    16711862      write.AddContainer("MSrcPosCam",    "Events");
     
    19922183      bin.SetEdges(10, 0., 1.0);
    19932184
    1994       MH3 mh3("cos(MMcEvt.fTelescopeTheta)");
     2185      MH3 mh3("cos((MPointingPos.fZd)/kRad2Deg)");
    19952186      mh3.SetName(mname);
    19962187      MH::SetBinning(&mh3.GetHist(), &bin);
     
    23552546
    23562547      write.AddContainer("MRawRunHeader", "RunHeaders");
    2357       //write.AddContainer("MTime",         "Events");
    2358       write.AddContainer("MMcEvt",        "Events");
    2359       //write.AddContainer("ThetaOrig",     "Events");
     2548      write.AddContainer("MTime",         "Events");
     2549      write.AddContainer("MPointingPos",  "Events");
    23602550      write.AddContainer("MSrcPosCam",    "Events");
    23612551      write.AddContainer("MSigmabar",     "Events");
     
    31373327
    31383328
    3139     MFillH filler("MHMcCollectionArea", "MMcEvt");
     3329    MFillH filler("MHMcCollectionArea", "MPointingPos");
    31403330    filler.SetName("CollectionArea");
    31413331
     
    33263516      write.AddContainer("MRawRunHeader", "RunHeaders");
    33273517      write.AddContainer("MTime",         "Events");
    3328       write.AddContainer("MMcEvt",        "Events");
     3518      write.AddContainer("MPointingPos",  "Events");
    33293519      write.AddContainer("ThetaOrig",     "Events");
    33303520      write.AddContainer("MSrcPosCam",    "Events");
     
    34003590    // new from Robert
    34013591
    3402     MFillH hfill6("MHTimeDiffTheta", "MMcEvt");
     3592    MFillH hfill6("MHTimeDiffTheta", "MPointingPos");
    34033593    hfill6.SetName("HTimeDiffTheta");
    34043594
    3405     MFillH hfill6a("MHTimeDiffTime", "MMcEvt");
     3595    MFillH hfill6a("MHTimeDiffTime", "MPointingPos");
    34063596    hfill6a.SetName("HTimeDiffTime");
    34073597
     
    36113801
    36123802
    3613 
    3614 
    3615 
    3616 
    3617 
    3618 
    3619 
    3620 
    3621 
    3622 
    3623 
    3624 
    3625 
    3626 
    3627 
    3628 
    3629 
    3630 
    3631 
    3632 
    3633 
    3634 
     3803   
     3804
     3805
     3806
     3807
     3808
     3809
     3810
     3811
     3812
     3813
     3814
     3815
     3816
     3817
     3818
     3819
     3820
     3821
     3822
     3823
     3824
  • trunk/MagicSoft/Mars/manalysis/MPad.cc

    r2798 r4584  
    6464#include <TCanvas.h>
    6565#include <TFile.h>
     66#include <TVirtualPad.h>
    6667
    6768#include "MBinning.h"
    6869#include "MSigmabar.h"
    69 #include "MMcEvt.hxx"
     70#include "MPointingPos.h"
    7071#include "MLog.h"
    7172#include "MLogManip.h"
     
    7576#include "MCerPhotPix.h"
    7677#include "MCerPhotEvt.h"
     78
     79#include "MH.h"
    7780
    7881#include "MPedPhotCam.h"
     
    190193  //             from sigma_k to sigma_j
    191194
     195  //*fLog << all << "MPad::Merge2Distributions(); Entry" << endl;
     196
    192197  Double_t eps = 1.e-10;
    193198
     
    205210  Double_t v, s, w, t, x, u, a, b, arg;
    206211
     212  //*fLog << "Content of histcp : " << endl;
     213
    207214  for (Int_t j=nbinssig; j >= 1; j--)
    208215  {
     216    //*fLog << "j, hista, histb , histap : " << j << ",  "
     217    //                              <<  hista->GetBinContent(j) << ",  "
     218    //                              <<  histb->GetBinContent(j) << ",  "
     219    //                              <<  histap->GetBinContent(j) << endl;
     220
    209221    v = histcp->GetBinContent(j);
     222    //*fLog << "cp : j, v = " << j << ",  " << v << endl;
     223
    210224    if ( fabs(v) < eps ) continue;
    211225    if (v >= 0.0)
     
    255269      }
    256270
    257       *fLog << all << "k, j, arg = " << k << ",  " << j
    258             << ",  " << arg << endl;
     271      //*fLog << all << "k, j, arg = " << k << ",  " << j
     272      //      << ",  " << arg << endl;
    259273
    260274      //......................................
     
    302316
    303317  // check results
     318
     319  //*fLog << "Content of histap, histbp, histcp : " << endl;
     320
    304321  for (Int_t j=1; j<=nbinssig; j++)
    305322  {
     
    308325    Double_t c = histcp->GetBinContent(j);
    309326
     327    //*fLog << "j, a, b, c = " << j << ":  " << a << ",  " << b << ",  "
     328    //      << c << endl;
     329
    310330    if( fabs(a-b)>3.0*eps  ||  fabs(c)>3.0*eps )
    311331      *fLog << err << "MPad::Merge2Distributions(); inconsistency in results; j, a, b, c = "
     
    314334
    315335  //---------------------------------------------------------------
    316   TCanvas &c = *(MH::MakeDefCanvas("Merging", "", 600, 600));
    317   c.Divide(2, 2);
     336  TCanvas *pad = MH::MakeDefCanvas("Merging", "", 600, 600);
    318337  gROOT->SetSelectedPad(NULL);
    319338
    320   c.cd(1);
     339  pad->Divide(2, 2);
     340
     341  pad->cd(1);
     342  gPad->SetBorderMode(0);
    321343  hista->SetDirectory(NULL);
    322   hista->DrawCopy();
     344  hista->Draw();
    323345  hista->SetBit(kCanDelete);   
    324346
    325   c.cd(2);
     347  pad->cd(2);
     348  gPad->SetBorderMode(0);
    326349  histb->SetDirectory(NULL);
    327   histb->DrawCopy();
     350  histb->Draw();
    328351  histb->SetBit(kCanDelete);   
    329352
    330   c.cd(3);
     353  pad->cd(3);
     354  gPad->SetBorderMode(0);
    331355  histap->SetDirectory(NULL);
    332   histap->DrawCopy();
     356  histap->Draw();
    333357  histap->SetBit(kCanDelete);   
     358
     359  pad->DrawClone();
    334360
    335361  //--------------------------------------------------------------------
     
    339365  delete histcp;
    340366
     367  //*fLog << all << "MPad::Merge2Distributions(); Exit" << endl;
     368
    341369  return kTRUE;
    342370}
     
    357385
    358386Bool_t MPad::MergeONOFFMC(
    359    TH2D *sigthmc,  TH3D *diffpixthmc,  TH3D *sigmapixthmc,
    360    TH2D *blindidthmc,  TH2D *blindnthmc,
    361    TH2D *sigthon,  TH3D *diffpixthon,  TH3D *sigmapixthon,
    362    TH2D *blindidthon,  TH2D *blindnthon,
    363    TH2D *sigthoff, TH3D *diffpixthoff, TH3D *sigmapixthoff,
    364    TH2D *blindidthoff, TH2D *blindnthoff)
     387   TH2D& sigthmc,  TH3D& diffpixthmc,  TH3D& sigmapixthmc,
     388   TH2D& blindidthmc,  TH2D& blindnthmc,
     389   TH2D& sigthon,  TH3D& diffpixthon,  TH3D& sigmapixthon,
     390   TH2D& blindidthon,  TH2D& blindnthon,
     391   TH2D& sigthoff, TH3D& diffpixthoff, TH3D& sigmapixthoff,
     392   TH2D& blindidthoff, TH2D& blindnthoff)
    365393{
     394  //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
     395  // for testing
     396  /*
     397  TAxis *xa = sigthon.GetXaxis();
     398  Int_t nbitheta = xa->GetNbins();
     399
     400  TAxis *ya = sigthon.GetYaxis();
     401  Int_t nbisig = ya->GetNbins();
     402  for (Int_t i=1; i<=nbitheta; i++)
     403  {
     404    for (Int_t j=1; j<=nbisig; j++)
     405    {
     406      if (i>0)
     407      {
     408        sigthmc.SetBinContent( i, j, (Float_t) (625000.0+(nbisig*nbisig*nbisig-j*j*j)) );
     409        sigthon.SetBinContent( i, j, (Float_t)(1.0) );
     410        sigthoff.SetBinContent(  i, j, (Float_t)( (0.5*nbisig-j)*(0.5*nbisig-j)            ) );
     411      }
     412      else
     413      {
     414        sigthmc.SetBinContent( i, j, 0.0);
     415        sigthon.SetBinContent( i, j, 0.0);
     416        sigthoff.SetBinContent(i, j, 0.0);
     417      }
     418    }
     419  }
     420  */
     421  //$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
     422
    366423  *fLog << all << "----------------------------------------------------------------------------------" << endl;
    367424  *fLog << all << "MPad::MergeONOFFMC(); Merge the ON, OFF and MC histograms to obtain the target distributions for the padding"
    368425        << endl;
    369426
    370   fHSigmaTheta = new TH2D( (TH2D&)*sigthon );
     427  fHSigmaTheta = new TH2D( (const TH2D&) sigthon );
    371428  fHSigmaTheta->SetNameTitle("2D-ThetaSigmabar", "2D-ThetaSigmabar (target)");
    372429
    373   fHDiffPixTheta = new TH3D( (TH3D&)*diffpixthon );
     430  *fLog << "after booking fHSigmaTheta" << endl;
     431
     432  fHDiffPixTheta = new TH3D( (const TH3D&) diffpixthon );
    374433  fHDiffPixTheta->SetNameTitle("3D-ThetaPixDiff", "3D-ThetaPixDiff (target)");
    375434
    376   fHSigmaPixTheta = new TH3D( (TH3D&)*sigmapixthon );
     435  *fLog << "after booking fHDiffPixTheta" << endl;
     436
     437  fHSigmaPixTheta = new TH3D( (const TH3D&) sigmapixthon );
    377438  fHSigmaPixTheta->SetNameTitle("3D-ThetaPixSigma", "3D-ThetaPixSigma (target)");
    378 
    379   fHBlindPixNTheta = new TH2D( (TH2D&)*blindnthon );
     439  *fLog << "after booking fHSigmaPixTheta" << endl;
     440
     441  fHBlindPixNTheta = new TH2D( (const TH2D&) blindnthon );
    380442  fHBlindPixNTheta->SetNameTitle("2D-ThetaBlindN", "2D-ThetaBlindN (target)");
    381443
    382   fHBlindPixIdTheta = new TH2D( (TH2D&)*blindidthon );
     444  *fLog << "after booking fHBlindPixNTheta" << endl;
     445
     446  fHBlindPixIdTheta = new TH2D( (const TH2D&) blindidthon );
    383447  fHBlindPixIdTheta->SetNameTitle("2D-ThetaBlindId", "2D-ThetaBlindId (target)");
    384448
     449  *fLog << "after booking fHBlindPixIdTheta" << endl;
     450  *fLog << all << "Histograms for the merged padding plots were booked"
     451        << endl;
     452
    385453  //--------------------------
    386   fHSigmaThetaMC = sigthmc;
     454  fHSigmaThetaMC = &sigthmc;
    387455  fHSigmaThetaMC->SetNameTitle("2D-ThetaSigmabarMC", "2D-ThetaSigmabarMC (orig.)");
    388   fHSigmaThetaON = sigthon;
     456  fHSigmaThetaON = &sigthon;
    389457  fHSigmaThetaON->SetNameTitle("2D-ThetaSigmabarON", "2D-ThetaSigmabarON (orig.)");
    390   fHSigmaThetaOFF = sigthoff;
     458  fHSigmaThetaOFF = &sigthoff;
    391459  fHSigmaThetaOFF->SetNameTitle("2D-ThetaSigmabarOFF", "2D-ThetaSigmabarOFF (orig.)");
    392460
     461  //*fLog << all << "addresses of SigmaTheta padding plots were copied"
     462  //      << endl;
     463
    393464  //--------------------------
    394   fHBlindPixNThetaMC = blindnthmc;
     465  fHBlindPixNThetaMC = &blindnthmc;
    395466  fHBlindPixNThetaMC->SetNameTitle("2D-ThetaBlindNMC", "2D-ThetaBlindNMC (orig.)");
    396   fHBlindPixNThetaON = blindnthon;
     467  fHBlindPixNThetaON = &blindnthon;
    397468  fHBlindPixNThetaON->SetNameTitle("2D-ThetaBlindNON", "2D-ThetaBlindNON (orig.)");
    398   fHBlindPixNThetaOFF = blindnthoff;
     469  fHBlindPixNThetaOFF = &blindnthoff;
    399470  fHBlindPixNThetaOFF->SetNameTitle("2D-ThetaBlindNOFF", "2D-ThetaBlindNOFF (orig.)");
    400471
     472  //*fLog << all << "addresses of BlindPixTheta padding plots were copied"
     473  //      << endl;
     474
    401475  //--------------------------
    402   fHBlindPixIdThetaMC = blindidthmc;
     476  fHBlindPixIdThetaMC = &blindidthmc;
    403477  fHBlindPixIdThetaMC->SetNameTitle("2D-ThetaBlindIdMC", "2D-ThetaBlindIdMC (orig.)");
    404   fHBlindPixIdThetaON = blindidthon;
     478  fHBlindPixIdThetaON = &blindidthon;
    405479  fHBlindPixIdThetaON->SetNameTitle("2D-ThetaBlindIdON", "2D-ThetaBlindIdON (orig.)");
    406   fHBlindPixIdThetaOFF = blindidthoff;
     480  fHBlindPixIdThetaOFF = &blindidthoff;
    407481  fHBlindPixIdThetaOFF->SetNameTitle("2D-ThetaBlindIdOFF", "2D-ThetaBlindIdOFF (orig.)");
    408482
     483  //*fLog << all << "addresses of BlindPixIdTheta padding plots were copied"
     484  //      << endl;
     485
    409486  //--------------------------
    410   fHDiffPixThetaMC = diffpixthmc;
     487  fHDiffPixThetaMC = &diffpixthmc;
    411488  fHDiffPixThetaMC->SetNameTitle("3D-ThetaPixDiffMC", "3D-ThetaPixDiffMC (orig.)");
    412   fHDiffPixThetaON = diffpixthon;
     489  fHDiffPixThetaON = &diffpixthon;
    413490  fHDiffPixThetaON->SetNameTitle("3D-ThetaPixDiffON", "3D-ThetaPixDiffON (orig.)");
    414   fHDiffPixThetaOFF = diffpixthoff;
     491  fHDiffPixThetaOFF = &diffpixthoff;
    415492  fHDiffPixThetaOFF->SetNameTitle("3D-ThetaPixDiffOFF", "3D-ThetaPixDiffOFF (orig.)");
    416493
     494  //*fLog << all << "addresses of DiffPixTheta padding plots were copied"
     495  //      << endl;
     496
    417497  //--------------------------
    418   fHSigmaPixThetaMC = sigmapixthmc;
     498  fHSigmaPixThetaMC = &sigmapixthmc;
    419499  fHSigmaPixThetaMC->SetNameTitle("3D-ThetaPixSigmaMC", "3D-ThetaPixSigmaMC (orig.)");
    420   fHSigmaPixThetaON = sigmapixthon;
     500  fHSigmaPixThetaON = &sigmapixthon;
    421501  fHSigmaPixThetaON->SetNameTitle("3D-ThetaPixSigmaON", "3D-ThetaPixSigmaON (orig.)");
    422   fHSigmaPixThetaOFF = sigmapixthoff;
     502  fHSigmaPixThetaOFF = &sigmapixthoff;
    423503  fHSigmaPixThetaOFF->SetNameTitle("3D-ThetaPixSigmaOFF", "3D-ThetaPixSigmaOFF (orig.)");
     504
     505  //*fLog << all << "addresses of SigmaPixTheta padding plots were copied"
     506  //      << endl;
     507
    424508  //--------------------------
    425509
     
    427511  // get binning for fHgON, fHgOFF and fHgMC  from sigthon
    428512  // binning in Theta
    429   TAxis *ax = sigthon->GetXaxis();
     513  TAxis *ax = sigthon.GetXaxis();
     514  Int_t nbinstheta = ax->GetNbins();
     515  TArrayD edgesx;
     516  edgesx.Set(nbinstheta+1);
     517  for (Int_t i=0; i<=nbinstheta; i++)
     518  {
     519    edgesx[i] = ax->GetBinLowEdge(i+1);
     520    //*fLog << all << "i, theta low edge = " << i << ",  " << edgesx[i]
     521    //      << endl;
     522  }
     523  MBinning binth;
     524  binth.SetEdges(edgesx);
     525
     526  // binning in sigmabar
     527  TAxis *ay = sigthon.GetYaxis();
     528  Int_t nbinssig = ay->GetNbins();
     529  TArrayD edgesy;
     530  edgesy.Set(nbinssig+1);
     531  for (Int_t i=0; i<=nbinssig; i++)
     532  {
     533    edgesy[i] = ay->GetBinLowEdge(i+1);
     534    //*fLog << all << "i, sigmabar low edge = " << i << ",  " << edgesy[i]
     535    //      << endl;
     536  }
     537  MBinning binsg;
     538  binsg.SetEdges(edgesy);
     539
     540
     541  fHgMC = new TH3D;
     542  MH::SetBinning(fHgMC, &binth, &binsg, &binsg);
     543  fHgMC->SetNameTitle("3D-PaddingMatrixMC", "3D-PadMatrixThetaMC");
     544
     545  fHgON = new TH3D;
     546  MH::SetBinning(fHgON, &binth, &binsg, &binsg);
     547  fHgON->SetNameTitle("3D-PaddingMatrixON", "3D-PadMatrixThetaON");
     548
     549  fHgOFF = new TH3D;
     550  MH::SetBinning(fHgOFF, &binth, &binsg, &binsg);
     551  fHgOFF->SetNameTitle("3D-PaddingMatrixOFF", "3D-PadMatrixThetaOFF");
     552
     553  //*fLog << all << "fHg histograms were booked" << endl;
     554
     555  //............   loop over Theta bins   ...........................
     556
     557
     558
     559  //*fLog << all << "MPad::MergeONOFFMC(); bins of Theta, Sigmabarold, Sigmabarnew, fraction of events to be padded" << endl;
     560  for (Int_t l=1; l<=nbinstheta; l++)
     561  {
     562    //-------------------------------------------
     563    // merge ON and OFF distributions
     564    // input : hista is the normalized 1D distr. of sigmabar for ON  data
     565    //         histb is the normalized 1D distr. of sigmabar for OFF data
     566    // output : histap    will be the merged distribution (ON-OFF)
     567    //          fHga(k,j) will tell which fraction of ON events should be
     568    //                    padded from bin k to bin j
     569    //          fHgb(k,j) will tell which fraction of OFF events should be
     570    //                    padded from bin k to bin j
     571
     572    TH2D * fHga = new TH2D;
     573    MH::SetBinning(fHga, &binsg, &binsg);
     574    TH2D * fHgb = new TH2D;
     575    MH::SetBinning(fHgb, &binsg, &binsg);
     576
     577    TH1D *hista  = sigthon.ProjectionY("sigon_y", l, l, "");
     578    hista->SetNameTitle("ON-orig", "ON (orig)");
     579    Stat_t suma = hista->Integral();
     580    if (suma != 0.0) hista->Scale(1./suma);
     581
     582    TH1D *histap  = new TH1D( (const TH1D&)*hista );
     583    histap->SetNameTitle("ON-OFF-merged)", "ON-OFF (merged)");
     584
     585    TH1D *histb  = sigthoff.ProjectionY("sigoff_y", l, l, "");
     586    histb->SetNameTitle("OFF-orig", "OFF (orig)");
     587    Stat_t sumb = histb->Integral();
     588    if (sumb != 0.0) histb->Scale(1./sumb);
     589
     590    if (suma == 0.0  ||  sumb == 0.0)
     591    {
     592      delete hista;
     593      delete histb;
     594      delete fHga;
     595      delete fHgb;
     596      delete histap;
     597
     598      *fLog << err
     599            << "cannot call Merge2Distributions(ON, OFF)  for theta bin l = "
     600            << l << ";  NevON, NevOFF = " << suma << ",  " << sumb << endl;
     601
     602      // go to next theta bin (l)
     603      continue;
     604    }
     605
     606    //*fLog << "call Merge2Distributions(ON, OFF)  for theta bin l = "
     607    //      << l << endl;
     608
     609    Merge2Distributions(hista, histb, histap, fHga, fHgb, nbinssig);
     610
     611    // fill fHgON and fHgOFF
     612    for (Int_t k=1; k<=nbinssig; k++)
     613      for (Int_t j=1; j<=nbinssig; j++)
     614      {
     615        Double_t a = fHga->GetBinContent(k,j);
     616        fHgON->SetBinContent(l, k, j, a);
     617
     618        Double_t b = fHgb->GetBinContent(k,j);
     619        fHgOFF->SetBinContent(l, k, j, b);
     620      }
     621
     622    //-------------------------------------------
     623    // now merge ON-OFF and MC distributions
     624    // input : histe is the result of the merging of ON and OFF distributions 
     625    //         histf is the normalized 1D distr. of sigmabar for MC data
     626    // output : histep    will be the merged distribution (target distribution)
     627    //          fHge(k,j) will tell which fraction of ON, OFF events should be
     628    //                    padded from bin k to bin j
     629    //          fHgf(k,j) will tell which fraction of MC events should be
     630    //                    padded from bin k to bin j
     631
     632    TH2D * fHge = new TH2D;
     633    MH::SetBinning(fHge, &binsg, &binsg);
     634    TH2D * fHgf = new TH2D;
     635    MH::SetBinning(fHgf, &binsg, &binsg);
     636
     637    TH1D *histe  = new TH1D( (const TH1D&)*histap);
     638    histe->SetNameTitle("ON-OFF-merged", "ON-OFF (merged)");
     639
     640    TH1D *histep  = new TH1D( (const TH1D&)*histe);
     641    histep->SetNameTitle("ON-OFF-MC-merged)", "ON-OFF-MC (merged)");
     642
     643    TH1D *histf  = sigthmc.ProjectionY("sigmc_y", l, l, "");
     644    histf->SetNameTitle("MC-orig", "MC (orig)");
     645    Double_t sumf = histf->Integral();
     646    if (sumf != 0.0) histf->Scale(1./sumf);
     647
     648    if (sumf == 0.0)
     649    {
     650      delete hista;
     651      delete histb;
     652      delete fHga;
     653      delete fHgb;
     654      delete histap;
     655
     656      delete histe;
     657      delete histf;
     658      delete fHge;
     659      delete fHgf;
     660      delete histep;
     661
     662      *fLog << err
     663            << "cannot call Merge2Distributions(ON-OFF,MC)  for theta bin l = "
     664            << l << ";  NevMC = " << sumf << endl;
     665
     666      // go to next theta bin (l)
     667      continue;
     668    }
     669
     670    //*fLog << "call Merge2Distributions(ON-OFF, MC)  for theta bin l = "
     671    //      << l << endl;
     672
     673    Merge2Distributions(histe, histf, histep, fHge, fHgf, nbinssig);
     674
     675    // update fHgON and fHgOFF
     676    UpdateHg(fHga, histap, fHge, fHgON,  nbinssig, l);
     677    UpdateHg(fHgb, histap, fHge, fHgOFF, nbinssig, l);
     678
     679    // fill fHgMC
     680    for (Int_t k=1; k<=nbinssig; k++)
     681      for (Int_t j=1; j<=nbinssig; j++)
     682      {
     683        Double_t f = fHgf->GetBinContent(k,j);
     684        fHgMC->SetBinContent(l, k, j, f);
     685      }
     686
     687    // fill target distribution fHSigmaTheta
     688    // (only for plotting, it will not  be used in the padding)
     689    for (Int_t j=1; j<=nbinssig; j++)
     690    {
     691      Double_t ep = histep->GetBinContent(j);
     692      fHSigmaTheta->SetBinContent(l, j, ep);
     693    }
     694    //-------------------------------------------
     695
     696    delete hista;
     697    delete histb;
     698    delete fHga;
     699    delete fHgb;
     700    delete histap;
     701
     702    delete histe;
     703    delete histf;
     704    delete fHge;
     705    delete fHgf;
     706    delete histep;
     707  }
     708  //............   end of loop over Theta bins   ....................
     709
     710 
     711  // Define the target distributions
     712  //        fHDiffPixTheta, fHSigmaPixTheta
     713  //               (they are calculated as
     714  //               averages of the ON and OFF distributions)
     715  //        fHBlindPixNTheta, fHBlindPixIdTheta
     716  //               (they are calculated as
     717  //               the sum of the ON and OFF distributions)
     718  // (fHDiffPixTheta will be used in the padding of MC events)
     719
     720  //............   start of new loop over Theta bins   ....................
     721  for (Int_t j=1; j<=nbinstheta; j++)
     722  {
     723    // fraction of ON/OFF/MC events to be padded : fracON, fracOFF, fracMC
     724
     725    Double_t fracON  = fHgON->Integral (j, j, 1, nbinssig, 1, nbinssig, "");
     726    Double_t fracOFF = fHgOFF->Integral(j, j, 1, nbinssig, 1, nbinssig, "");
     727    Double_t fracMC  = fHgMC->Integral(j, j, 1, nbinssig, 1, nbinssig, "");
     728
     729    Double_t normON;
     730    Double_t normOFF;
     731
     732    // set ranges for 2D-projections of 3D-histograms
     733    TAxis *ax = diffpixthon.GetXaxis();
     734    ax->SetRange(j, j);
     735    ax = diffpixthoff.GetXaxis();
     736    ax->SetRange(j, j);
     737
     738    TH2D *hist;
     739    TH2D *histOFF;
     740
     741    TH1D *hist1;
     742    TH1D *hist1OFF;
     743
     744    // weights for ON and OFF distrubtions when
     745    // calculating the weighted average
     746    Double_t facON  = 0.5 * (1. - fracON + fracOFF);
     747    Double_t facOFF = 0.5 * (1. + fracON - fracOFF);
     748 
     749    *fLog << all << "Theta bin j : fracON, fracOFF, fracMC, facON, facOFF = "
     750          << j << ",  " << fracON << ",  " << fracOFF << ",  "
     751          << fracMC << ",  " << facON << ",  " << facOFF << endl;
     752
     753    //------------------------------------------------------------------
     754    // define target distribution  'sigma^2-sigmavar^2 vs. pixel number'
     755    ay = diffpixthon.GetYaxis();
     756    Int_t nbinspixel = ay->GetNbins();
     757
     758    TAxis *az = diffpixthon.GetZaxis();
     759    Int_t nbinsdiff = az->GetNbins();
     760
     761    hist    = (TH2D*)diffpixthon.Project3D("zy");
     762    hist->SetName("dummy");
     763    histOFF = (TH2D*)diffpixthoff.Project3D("zy");
     764
     765    normON  = hist->Integral();
     766    normOFF = histOFF->Integral();
     767    if (normON  != 0.0) hist->Scale(1.0/normON);
     768    if (normOFF != 0.0) histOFF->Scale(1.0/normOFF);
     769
     770    // weighted average of ON and OFF distributions
     771    hist->Scale(facON);
     772    hist->Add(histOFF, facOFF);
     773
     774    for (Int_t k=1; k<=nbinspixel; k++)
     775      for (Int_t l=1; l<=nbinsdiff; l++)
     776      {
     777        Double_t cont = hist->GetBinContent(k,l);
     778        fHDiffPixTheta->SetBinContent(j, k, l, cont); 
     779      }
     780
     781    delete hist;
     782    delete histOFF;
     783
     784    //------------------------------------------------------------------
     785    // define target distribution  'sigma vs. pixel number'
     786    ay = sigmapixthon.GetYaxis();
     787    nbinspixel = ay->GetNbins();
     788
     789    az = sigmapixthon.GetZaxis();
     790    Int_t nbinssigma = az->GetNbins();
     791
     792    hist    = (TH2D*)sigmapixthon.Project3D("zy");
     793    hist->SetName("dummy");
     794    histOFF = (TH2D*)sigmapixthoff.Project3D("zy");
     795
     796    normON  = hist->Integral();
     797    normOFF = histOFF->Integral();
     798    if (normON  != 0.0) hist->Scale(1.0/normON);
     799    if (normOFF != 0.0) histOFF->Scale(1.0/normOFF);
     800
     801    // weighted average of ON and OFF distributions
     802    hist->Scale(facON);
     803    hist->Add(histOFF, facOFF);
     804
     805    for (Int_t k=1; k<=nbinspixel; k++)
     806      for (Int_t l=1; l<=nbinssigma; l++)
     807      {
     808        Double_t cont = hist->GetBinContent(k,l);
     809        fHSigmaPixTheta->SetBinContent(j, k, l, cont); 
     810      }
     811
     812    delete hist;
     813    delete histOFF;
     814
     815
     816    //------------------------------------------------------------------
     817    // define target distribution  'number of blind pixels per event'
     818    ay = blindnthon.GetYaxis();
     819    Int_t nbinsn = ay->GetNbins();
     820
     821    hist1    = fHBlindPixNThetaON->ProjectionY("", j, j, "");
     822    hist1->SetName("dummy");
     823    hist1OFF = fHBlindPixNThetaOFF->ProjectionY("", j, j, "");
     824
     825    normON  = hist1->Integral();
     826    normOFF = hist1OFF->Integral();
     827    if (normON  != 0.0) hist1->Scale(1.0/normON);
     828    if (normOFF != 0.0) hist1OFF->Scale(1.0/normOFF);
     829
     830    // sum of ON and OFF distributions
     831    hist1->Add(hist1OFF, 1.0);
     832    Stat_t sum1 = hist1->Integral();
     833    if (sum1 != 0.0) hist1->Scale( 1.0/sum1 );
     834
     835    for (Int_t k=1; k<=nbinsn; k++)
     836      {
     837        Double_t cont = hist1->GetBinContent(k);
     838        fHBlindPixNTheta->SetBinContent(j, k, cont); 
     839      }
     840
     841    delete hist1;
     842    delete hist1OFF;
     843
     844    //------------------------------------------------------------------
     845    // define target distribution  'id of blind pixel'
     846    ay = blindidthon.GetYaxis();
     847    Int_t nbinsid = ay->GetNbins();
     848
     849    hist1    = fHBlindPixIdThetaON->ProjectionY("", j, j, "");
     850    hist1->SetName("dummy");
     851    hist1OFF = fHBlindPixIdThetaOFF->ProjectionY("", j, j, "");
     852
     853    // divide by the number of events (from fHBlindPixNTheta)
     854    if (normON  != 0.0) hist1->Scale(1.0/normON);
     855    if (normOFF != 0.0) hist1OFF->Scale(1.0/normOFF);
     856
     857    // sum of ON and OFF distributions
     858    hist1->Add(hist1OFF, 1.0);
     859
     860    for (Int_t k=1; k<=nbinsid; k++)
     861      {
     862        Double_t cont = hist1->GetBinContent(k);
     863        fHBlindPixIdTheta->SetBinContent(j, k, cont); 
     864      }
     865
     866    delete hist1;
     867    delete hist1OFF;
     868  }
     869  //............   end of new loop over Theta bins   ....................
     870
     871  *fLog << all
     872        << "MPad::MergeONOFFMC(); The target distributions for the padding have been created"
     873        << endl;
     874  *fLog << all << "----------------------------------------------------------"
     875        << endl;
     876  //--------------------------------------------
     877
     878  fHSigmaThetaMC->SetDirectory(NULL);
     879  fHSigmaThetaON->SetDirectory(NULL);
     880  fHSigmaThetaOFF->SetDirectory(NULL);
     881
     882  fHDiffPixThetaMC->SetDirectory(NULL);
     883  fHDiffPixThetaON->SetDirectory(NULL);
     884  fHDiffPixThetaOFF->SetDirectory(NULL);
     885
     886  fHSigmaPixThetaMC->SetDirectory(NULL);
     887  fHSigmaPixThetaON->SetDirectory(NULL);
     888  fHSigmaPixThetaOFF->SetDirectory(NULL);
     889
     890  fHBlindPixIdThetaMC->SetDirectory(NULL);
     891  fHBlindPixIdThetaON->SetDirectory(NULL);
     892  fHBlindPixIdThetaOFF->SetDirectory(NULL);
     893
     894  fHBlindPixNThetaMC->SetDirectory(NULL);
     895  fHBlindPixNThetaON->SetDirectory(NULL);
     896  fHBlindPixNThetaOFF->SetDirectory(NULL);
     897
     898  fHgMC->SetDirectory(NULL);
     899  fHgON->SetDirectory(NULL);
     900  fHgOFF->SetDirectory(NULL);
     901
     902  return kTRUE;
     903}
     904
     905// --------------------------------------------------------------------------
     906//
     907// Update the matrix fHgA
     908// which contains the final padding prescriptions
     909//
     910
     911Bool_t MPad::UpdateHg(TH2D *fHga, TH1D *histap, TH2D *fHge, TH3D *fHgA,
     912                      Int_t nbinssig, Int_t l)
     913{
     914  // histap  target distribution after ON-OFF merging
     915  // fHga    padding prescription for ON (or OFF) data to get to histap
     916  // fHge    padding prescription to get from histap to the target
     917  //         distribution after the ON-OFF-MC merging
     918  // fHgA    updated padding prescription for ON (or OFF) data to get
     919  //         from the original ON (or OFF) histogram to the target
     920  //         distribution after the ON-OFF-MC merging
     921  // l       Theta bin
     922
     923  Double_t eps = 1.e-10;
     924
     925  for (Int_t k=1; k<=nbinssig; k++)
     926  {
     927    Double_t na  = fHga->Integral(1, nbinssig, k, k, " ");
     928    Double_t ne  = fHge->Integral(k, k, 1, nbinssig, " ");
     929    Double_t nap = histap->GetBinContent(k);
     930
     931    if (ne <= eps)
     932    {
     933      // go to next k
     934      continue;
     935    }
     936
     937    Double_t r = nap - na;
     938
     939    if (r >= ne-eps)
     940    {
     941      for (Int_t j=k+1; j<=nbinssig; j++)
     942      {
     943        Double_t e = fHge->GetBinContent(k,j);
     944        Double_t A = fHgA->GetBinContent(l,k,j);
     945        fHgA->SetBinContent(l, k, j, A + e);
     946      }
     947      // go to next k
     948      continue;
     949    }
     950
     951    for (Int_t j=k+1; j<=nbinssig; j++)
     952    {
     953      Double_t e = fHge->GetBinContent(k,j);
     954      Double_t A = fHgA->GetBinContent(l,k,j);
     955      fHgA->SetBinContent(l, k, j, A + r*e/ne);
     956    }
     957
     958    if (na <= eps)
     959    {
     960      // go to next k
     961      continue;
     962    }
     963
     964    for (Int_t i=1; i<k; i++)
     965    {
     966      Double_t a = fHga->GetBinContent(i,k);
     967      Double_t A = fHgA->GetBinContent(l,i,k);
     968      fHgA->SetBinContent(l, i, k, A - (ne-r)*a/na);
     969    }
     970
     971    for (Int_t i=1; i<=nbinssig; i++)
     972    {
     973      if (i == k) continue;
     974      for (Int_t j=i+1; j<=nbinssig; j++)
     975      {
     976        if (j == k) continue;
     977        Double_t a = fHga->GetBinContent(i,k);
     978        Double_t e = fHge->GetBinContent(k,j);
     979        Double_t A = fHgA->GetBinContent(l,i,j);
     980        fHgA->SetBinContent(l, i, j, A + (ne-r)*a*e/(na*ne)  );
     981      }
     982    }
     983  }
     984
     985  return kTRUE;
     986}
     987
     988// --------------------------------------------------------------------------
     989//
     990// Merge the distributions
     991//   fHSigmaTheta      2D-histogram  (Theta, sigmabar)
     992//
     993// ===>   of ON and MC data   <==============
     994//
     995// and define the matrices fHgMC and fHgON 
     996//
     997// These matrices tell which fraction of events should be padded
     998// from bin k of sigmabar to bin j
     999//
     1000
     1001Bool_t MPad::MergeONMC(
     1002   TH2D& sigthmc,  TH3D& diffpixthmc,  TH3D& sigmapixthmc,
     1003   TH2D& blindidthmc,  TH2D& blindnthmc,
     1004   TH2D& sigthon,  TH3D& diffpixthon,  TH3D& sigmapixthon,
     1005   TH2D& blindidthon,  TH2D& blindnthon)
     1006{
     1007  *fLog << all << "----------------------------------------------------------------------------------" << endl;
     1008  *fLog << all << "MPad::MergeONMC(); Merge the ON  and MC histograms to obtain the target distributions for the padding"
     1009        << endl;
     1010
     1011  fHSigmaTheta = new TH2D( (TH2D&) sigthon );
     1012  fHSigmaTheta->SetNameTitle("2D-ThetaSigmabar", "2D-ThetaSigmabar (target)");
     1013
     1014  fHDiffPixTheta = new TH3D( (TH3D&) diffpixthon );
     1015  fHDiffPixTheta->SetNameTitle("3D-ThetaPixDiff", "3D-ThetaPixDiff (target)");
     1016
     1017  fHSigmaPixTheta = new TH3D( (TH3D&) sigmapixthon );
     1018  fHSigmaPixTheta->SetNameTitle("3D-ThetaPixSigma", "3D-ThetaPixSigma (target)");
     1019
     1020  fHBlindPixNTheta = new TH2D( (TH2D&) blindnthon );
     1021  fHBlindPixNTheta->SetNameTitle("2D-ThetaBlindN", "2D-ThetaBlindN (target)");
     1022
     1023  fHBlindPixIdTheta = new TH2D( (TH2D&) blindidthon );
     1024  fHBlindPixIdTheta->SetNameTitle("2D-ThetaBlindId", "2D-ThetaBlindId (target)");
     1025
     1026  //--------------------------
     1027  fHSigmaThetaMC = &sigthmc;
     1028  fHSigmaThetaMC->SetNameTitle("2D-ThetaSigmabarMC", "2D-ThetaSigmabarMC (orig.)");
     1029  fHSigmaThetaON = &sigthon;
     1030  fHSigmaThetaON->SetNameTitle("2D-ThetaSigmabarON", "2D-ThetaSigmabarON (orig.)");
     1031
     1032  //--------------------------
     1033  fHBlindPixNThetaMC = &blindnthmc;
     1034  fHBlindPixNThetaMC->SetNameTitle("2D-ThetaBlindNMC", "2D-ThetaBlindNMC (orig.)");
     1035  fHBlindPixNThetaON = &blindnthon;
     1036  fHBlindPixNThetaON->SetNameTitle("2D-ThetaBlindNON", "2D-ThetaBlindNON (orig.)");
     1037
     1038  //--------------------------
     1039  fHBlindPixIdThetaMC = &blindidthmc;
     1040  fHBlindPixIdThetaMC->SetNameTitle("2D-ThetaBlindIdMC", "2D-ThetaBlindIdMC (orig.)");
     1041  fHBlindPixIdThetaON = &blindidthon;
     1042  fHBlindPixIdThetaON->SetNameTitle("2D-ThetaBlindIdON", "2D-ThetaBlindIdON (orig.)");
     1043
     1044  //--------------------------
     1045  fHDiffPixThetaMC = &diffpixthmc;
     1046  fHDiffPixThetaMC->SetNameTitle("3D-ThetaPixDiffMC", "3D-ThetaPixDiffMC (orig.)");
     1047  fHDiffPixThetaON = &diffpixthon;
     1048  fHDiffPixThetaON->SetNameTitle("3D-ThetaPixDiffON", "3D-ThetaPixDiffON (orig.)");
     1049
     1050  //--------------------------
     1051  fHSigmaPixThetaMC = &sigmapixthmc;
     1052  fHSigmaPixThetaMC->SetNameTitle("3D-ThetaPixSigmaMC", "3D-ThetaPixSigmaMC (orig.)");
     1053  fHSigmaPixThetaON = &sigmapixthon;
     1054  fHSigmaPixThetaON->SetNameTitle("3D-ThetaPixSigmaON", "3D-ThetaPixSigmaON (orig.)");
     1055
     1056  //--------------------------
     1057
     1058
     1059  // get binning for fHgON and fHgMC  from sigthon
     1060  // binning in Theta
     1061  TAxis *ax = sigthon.GetXaxis();
    4301062  Int_t nbinstheta = ax->GetNbins();
    4311063  TArrayD edgesx;
     
    4411073
    4421074  // binning in sigmabar
    443   TAxis *ay = sigthon->GetYaxis();
     1075  TAxis *ay = sigthon.GetYaxis();
    4441076  Int_t nbinssig = ay->GetNbins();
    4451077  TArrayD edgesy;
     
    4631095  fHgON->SetNameTitle("3D-PaddingMatrixON", "3D-PadMatrixThetaON");
    4641096
    465   fHgOFF = new TH3D;
    466   MH::SetBinning(fHgOFF, &binth, &binsg, &binsg);
    467   fHgOFF->SetNameTitle("3D-PaddingMatrixOFF", "3D-PadMatrixThetaOFF");
    468 
    469   //............   loop over Theta bins   ...........................
    470 
    471 
    472 
    473   *fLog << all << "MPad::MergeONOFFMC(); bins of Theta, Sigmabarold, Sigmabarnew, fraction of events to be padded" << endl;
    474   for (Int_t l=1; l<=nbinstheta; l++)
    475   {
    476     TH2D * fHga = new TH2D;
    477     MH::SetBinning(fHga, &binsg, &binsg);
    478     TH2D * fHgb = new TH2D;
    479     MH::SetBinning(fHgb, &binsg, &binsg);
    480 
    481     //-------------------------------------------
    482     // merge ON and OFF distributions
    483     // input : hista is the normalized 1D distr. of sigmabar for ON  data
    484     //         histb is the normalized 1D distr. of sigmabar for OFF data
    485     // output : histap    will be the merged distribution (ON-OFF)
    486     //          fHga(k,j) will tell which fraction of ON events should be
    487     //                    padded from bin k to bin j
    488     //          fHgb(k,j) will tell which fraction of OFF events should be
    489     //                    padded from bin k to bin j
    490 
    491     TH1D *hista  = sigthon->ProjectionY("sigon_y", l, l, "");
    492     Stat_t suma = hista->Integral();
    493     hista->Scale(1./suma);
    494 
    495     TH1D *histap  = new TH1D( (const TH1D&)*hista );
    496 
    497     TH1D *histb  = sigthoff->ProjectionY("sigoff_y", l, l, "");
    498     Stat_t sumb = histb->Integral();
    499     histb->Scale(1./sumb);
    500 
    501     Merge2Distributions(hista, histb, histap, fHga, fHgb, nbinssig);
    502     delete hista;
    503     delete histb;
    504 
    505     // fill fHgON and fHgOFF
    506     for (Int_t k=1; k<=nbinssig; k++)
    507       for (Int_t j=1; j<=nbinssig; j++)
    508       {
    509         Double_t a = fHga->GetBinContent(k,j);
    510         fHga->SetBinContent (k, j, 0.0);
    511         fHgON->SetBinContent(l, k, j, a);
    512 
    513         Double_t b = fHgb->GetBinContent(k,j);
    514         fHgb->SetBinContent (k, j, 0.0);
    515         fHgOFF->SetBinContent(l, k, j, b);
    516       }
    517 
    518     //-------------------------------------------
    519     // now merge ON-OFF and MC distributions
    520     // input : hista is the result of the merging of ON and OFF distributions 
    521     //         histb is the normalized 1D distr. of sigmabar for MC data
    522     // output : histap    will be the merged distribution (target distribution)
    523     //          fHga(k,j) will tell which fraction of ON, OFF events should be
    524     //                    padded from bin k to bin j
    525     //          fHgb(k,j) will tell which fraction of MC events should be
    526     //                    padded from bin k to bin j
    527 
    528     hista  = new TH1D( (const TH1D&)*histap);
    529 
    530     histb  = sigthmc->ProjectionY("sigmc_y", l, l, "");
    531     sumb = histb->Integral();
    532     histb->Scale(1./sumb);
    533 
    534     Merge2Distributions(hista, histb, histap, fHga, fHgb, nbinssig);
    535     delete hista;
    536     delete histb;
    537 
    538     // update fHgON and fHgOFF and fill fHgMC
    539     for (Int_t k=1; k<=nbinssig; k++)
    540       for (Int_t j=1; j<=nbinssig; j++)
    541       {
    542         Double_t a   =  fHga->GetBinContent  (k,j);
    543 
    544         Double_t aON = fHgON->GetBinContent(l,k,j);
    545         fHgON->SetBinContent(l, k, j, aON+a);
    546 
    547         Double_t aOFF = fHgOFF->GetBinContent(l,k,j);
    548         fHgOFF->SetBinContent(l, k, j, aOFF+a);
    549 
    550         Double_t b = fHgb->GetBinContent(k,j);
    551         fHgMC->SetBinContent(l, k, j, b);
    552       }
    553 
    554     // fill target distribution fHSigmaTheta
    555     // (only for plotting, it will not  be used in the padding)
    556     for (Int_t j=1; j<=nbinssig; j++)
    557     {
    558       Double_t a = histap->GetBinContent(j);
    559       fHSigmaTheta->SetBinContent(l, j, a);
    560     }
    561 
    562     delete fHga;
    563     delete fHgb;
    564 
    565     delete histap;
    566   }
    567   //............   end of loop over Theta bins   ....................
    568 
    569  
    570   // Define the target distributions
    571   //        fHDiffPixTheta, fHSigmaPixTheta
    572   //               (they are calculated as
    573   //               averages of the ON and OFF distributions)
    574   //        fHBlindPixNTheta, fHBlindPixIdTheta
    575   //               (they are calculated as
    576   //               the sum of the ON and OFF distributions)
    577   // (fHDiffPixTheta will be used in the padding of MC events)
    578 
    579   //............   start of new loop over Theta bins   ....................
    580   for (Int_t j=1; j<=nbinstheta; j++)
    581   {
    582     // fraction of ON/OFF/MC events to be padded : fracON, fracOFF, fracMC
    583 
    584     Double_t fracON  = fHgON->Integral (j, j, 1, nbinssig, 1, nbinssig, "");
    585     Double_t fracOFF = fHgOFF->Integral(j, j, 1, nbinssig, 1, nbinssig, "");
    586     Double_t fracMC  = fHgMC->Integral(j, j, 1, nbinssig, 1, nbinssig, "");
    587 
    588     Double_t normON;
    589     Double_t normOFF;
    590 
    591     // set ranges for 2D-projections of 3D-histograms
    592     TAxis *ax = diffpixthon->GetXaxis();
    593     ax->SetRange(j, j);
    594     ax = diffpixthoff->GetXaxis();
    595     ax->SetRange(j, j);
    596 
    597     TH2D *hist;
    598     TH2D *histOFF;
    599 
    600     TH1D *hist1;
    601     TH1D *hist1OFF;
    602 
    603     // weights for ON and OFF distrubtions when
    604     // calculating the weighted average
    605     Double_t facON  = 0.5 * (1. - fracON + fracOFF);
    606     Double_t facOFF = 0.5 * (1. + fracON - fracOFF);
    607  
    608     *fLog << all << "Theta bin j : fracON, fracOFF, facON, facOFF = "
    609           << j << ",  " << fracON << ",  " << fracOFF << ",  "
    610           << fracMC << ",  " << facON << ",  " << facOFF << endl;
    611 
    612     //------------------------------------------------------------------
    613     // define target distribution  'sigma^2-sigmavar^2 vs. pixel number'
    614     ay = diffpixthon->GetYaxis();
    615     Int_t nbinspixel = ay->GetNbins();
    616 
    617     TAxis *az = diffpixthon->GetZaxis();
    618     Int_t nbinsdiff = az->GetNbins();
    619 
    620     hist    = (TH2D*)diffpixthon->Project3D("zy");
    621     hist->SetName("dummy");
    622     histOFF = (TH2D*)diffpixthoff->Project3D("zy");
    623 
    624     normON  = hist->Integral();
    625     normOFF = histOFF->Integral();
    626     if (normON  != 0.0) hist->Scale(1.0/normON);
    627     if (normOFF != 0.0) histOFF->Scale(1.0/normOFF);
    628 
    629     // weighted average of ON and OFF distributions
    630     hist->Scale(facON);
    631     hist->Add(histOFF, facOFF);
    632 
    633     for (Int_t k=1; k<=nbinspixel; k++)
    634       for (Int_t l=1; l<=nbinsdiff; l++)
    635       {
    636         Double_t cont = hist->GetBinContent(k,l);
    637         fHDiffPixTheta->SetBinContent(j, k, l, cont); 
    638       }
    639 
    640     delete hist;
    641     delete histOFF;
    642 
    643     //------------------------------------------------------------------
    644     // define target distribution  'sigma vs. pixel number'
    645     ay = sigmapixthon->GetYaxis();
    646     nbinspixel = ay->GetNbins();
    647 
    648     az = sigmapixthon->GetZaxis();
    649     Int_t nbinssigma = az->GetNbins();
    650 
    651     hist    = (TH2D*)sigmapixthon->Project3D("zy");
    652     hist->SetName("dummy");
    653     histOFF = (TH2D*)sigmapixthoff->Project3D("zy");
    654 
    655     normON  = hist->Integral();
    656     normOFF = histOFF->Integral();
    657     if (normON  != 0.0) hist->Scale(1.0/normON);
    658     if (normOFF != 0.0) histOFF->Scale(1.0/normOFF);
    659 
    660     // weighted average of ON and OFF distributions
    661     hist->Scale(facON);
    662     hist->Add(histOFF, facOFF);
    663 
    664     for (Int_t k=1; k<=nbinspixel; k++)
    665       for (Int_t l=1; l<=nbinssigma; l++)
    666       {
    667         Double_t cont = hist->GetBinContent(k,l);
    668         fHSigmaPixTheta->SetBinContent(j, k, l, cont); 
    669       }
    670 
    671     delete hist;
    672     delete histOFF;
    673 
    674 
    675     //------------------------------------------------------------------
    676     // define target distribution  'number of blind pixels per event'
    677     ay = blindnthon->GetYaxis();
    678     Int_t nbinsn = ay->GetNbins();
    679 
    680     hist1    = fHBlindPixNThetaON->ProjectionY("", j, j, "");
    681     hist1->SetName("dummy");
    682     hist1OFF = fHBlindPixNThetaOFF->ProjectionY("", j, j, "");
    683 
    684     normON  = hist1->Integral();
    685     normOFF = hist1OFF->Integral();
    686     if (normON  != 0.0) hist1->Scale(1.0/normON);
    687     if (normOFF != 0.0) hist1OFF->Scale(1.0/normOFF);
    688 
    689     // sum of ON and OFF distributions
    690     hist1->Add(hist1OFF, 1.0);
    691     hist1->Scale( 1.0/hist1->Integral() );
    692 
    693     for (Int_t k=1; k<=nbinsn; k++)
    694       {
    695         Double_t cont = hist1->GetBinContent(k);
    696         fHBlindPixNTheta->SetBinContent(j, k, cont); 
    697       }
    698 
    699     delete hist1;
    700     delete hist1OFF;
    701 
    702     //------------------------------------------------------------------
    703     // define target distribution  'id of blind pixel'
    704     ay = blindidthon->GetYaxis();
    705     Int_t nbinsid = ay->GetNbins();
    706 
    707     hist1    = fHBlindPixIdThetaON->ProjectionY("", j, j, "");
    708     hist1->SetName("dummy");
    709     hist1OFF = fHBlindPixIdThetaOFF->ProjectionY("", j, j, "");
    710 
    711     // divide by the number of events (from fHBlindPixNTheta)
    712     if (normON  != 0.0) hist1->Scale(1.0/normON);
    713     if (normOFF != 0.0) hist1OFF->Scale(1.0/normOFF);
    714 
    715     // sum of ON and OFF distributions
    716     hist1->Add(hist1OFF, 1.0);
    717 
    718     for (Int_t k=1; k<=nbinsid; k++)
    719       {
    720         Double_t cont = hist1->GetBinContent(k);
    721         fHBlindPixIdTheta->SetBinContent(j, k, cont); 
    722       }
    723 
    724     delete hist1;
    725     delete hist1OFF;
    726   }
    727   //............   end of new loop over Theta bins   ....................
    728 
    729   *fLog << all
    730         << "MPad::MergeONOFFMC(); The target distributions for the padding have been created"
    731         << endl;
    732   *fLog << all << "----------------------------------------------------------"
    733         << endl;
    734   //--------------------------------------------
    735 
    736   fHSigmaThetaMC->SetDirectory(NULL);
    737   fHSigmaThetaON->SetDirectory(NULL);
    738   fHSigmaThetaOFF->SetDirectory(NULL);
    739 
    740   fHDiffPixThetaMC->SetDirectory(NULL);
    741   fHDiffPixThetaON->SetDirectory(NULL);
    742   fHDiffPixThetaOFF->SetDirectory(NULL);
    743 
    744   fHSigmaPixThetaMC->SetDirectory(NULL);
    745   fHSigmaPixThetaON->SetDirectory(NULL);
    746   fHSigmaPixThetaOFF->SetDirectory(NULL);
    747 
    748   fHBlindPixIdThetaMC->SetDirectory(NULL);
    749   fHBlindPixIdThetaON->SetDirectory(NULL);
    750   fHBlindPixIdThetaOFF->SetDirectory(NULL);
    751 
    752   fHBlindPixNThetaMC->SetDirectory(NULL);
    753   fHBlindPixNThetaON->SetDirectory(NULL);
    754   fHBlindPixNThetaOFF->SetDirectory(NULL);
    755 
    756   fHgMC->SetDirectory(NULL);
    757   fHgON->SetDirectory(NULL);
    758   fHgOFF->SetDirectory(NULL);
    759 
    760   return kTRUE;
    761 }
    762 
    763 // --------------------------------------------------------------------------
    764 //
    765 // Merge the distributions
    766 //   fHSigmaTheta      2D-histogram  (Theta, sigmabar)
    767 //
    768 // ===>   of ON and MC data   <==============
    769 //
    770 // and define the matrices fHgMC and fHgON 
    771 //
    772 // These matrices tell which fraction of events should be padded
    773 // from bin k of sigmabar to bin j
    774 //
    775 
    776 Bool_t MPad::MergeONMC(
    777    TH2D *sigthmc,  TH3D *diffpixthmc,  TH3D *sigmapixthmc,
    778    TH2D *blindidthmc,  TH2D *blindnthmc,
    779    TH2D *sigthon,  TH3D *diffpixthon,  TH3D *sigmapixthon,
    780    TH2D *blindidthon,  TH2D *blindnthon)
    781 {
    782   *fLog << all << "----------------------------------------------------------------------------------" << endl;
    783   *fLog << all << "MPad::MergeONMC(); Merge the ON  and MC histograms to obtain the target distributions for the padding"
    784         << endl;
    785 
    786   fHSigmaTheta = new TH2D( (TH2D&)*sigthon );
    787   fHSigmaTheta->SetNameTitle("2D-ThetaSigmabar", "2D-ThetaSigmabar (target)");
    788 
    789   fHDiffPixTheta = new TH3D( (TH3D&)*diffpixthon );
    790   fHDiffPixTheta->SetNameTitle("3D-ThetaPixDiff", "3D-ThetaPixDiff (target)");
    791 
    792   fHSigmaPixTheta = new TH3D( (TH3D&)*sigmapixthon );
    793   fHSigmaPixTheta->SetNameTitle("3D-ThetaPixSigma", "3D-ThetaPixSigma (target)");
    794 
    795   fHBlindPixNTheta = new TH2D( (TH2D&)*blindnthon );
    796   fHBlindPixNTheta->SetNameTitle("2D-ThetaBlindN", "2D-ThetaBlindN (target)");
    797 
    798   fHBlindPixIdTheta = new TH2D( (TH2D&)*blindidthon );
    799   fHBlindPixIdTheta->SetNameTitle("2D-ThetaBlindId", "2D-ThetaBlindId (target)");
    800 
    801   //--------------------------
    802   fHSigmaThetaMC = sigthmc;
    803   fHSigmaThetaMC->SetNameTitle("2D-ThetaSigmabarMC", "2D-ThetaSigmabarMC (orig.)");
    804   fHSigmaThetaON = sigthon;
    805   fHSigmaThetaON->SetNameTitle("2D-ThetaSigmabarON", "2D-ThetaSigmabarON (orig.)");
    806 
    807   //--------------------------
    808   fHBlindPixNThetaMC = blindnthmc;
    809   fHBlindPixNThetaMC->SetNameTitle("2D-ThetaBlindNMC", "2D-ThetaBlindNMC (orig.)");
    810   fHBlindPixNThetaON = blindnthon;
    811   fHBlindPixNThetaON->SetNameTitle("2D-ThetaBlindNON", "2D-ThetaBlindNON (orig.)");
    812 
    813   //--------------------------
    814   fHBlindPixIdThetaMC = blindidthmc;
    815   fHBlindPixIdThetaMC->SetNameTitle("2D-ThetaBlindIdMC", "2D-ThetaBlindIdMC (orig.)");
    816   fHBlindPixIdThetaON = blindidthon;
    817   fHBlindPixIdThetaON->SetNameTitle("2D-ThetaBlindIdON", "2D-ThetaBlindIdON (orig.)");
    818 
    819   //--------------------------
    820   fHDiffPixThetaMC = diffpixthmc;
    821   fHDiffPixThetaMC->SetNameTitle("3D-ThetaPixDiffMC", "3D-ThetaPixDiffMC (orig.)");
    822   fHDiffPixThetaON = diffpixthon;
    823   fHDiffPixThetaON->SetNameTitle("3D-ThetaPixDiffON", "3D-ThetaPixDiffON (orig.)");
    824 
    825   //--------------------------
    826   fHSigmaPixThetaMC = sigmapixthmc;
    827   fHSigmaPixThetaMC->SetNameTitle("3D-ThetaPixSigmaMC", "3D-ThetaPixSigmaMC (orig.)");
    828   fHSigmaPixThetaON = sigmapixthon;
    829   fHSigmaPixThetaON->SetNameTitle("3D-ThetaPixSigmaON", "3D-ThetaPixSigmaON (orig.)");
    830 
    831   //--------------------------
    832 
    833 
    834   // get binning for fHgON and fHgMC  from sigthon
    835   // binning in Theta
    836   TAxis *ax = sigthon->GetXaxis();
    837   Int_t nbinstheta = ax->GetNbins();
    838   TArrayD edgesx;
    839   edgesx.Set(nbinstheta+1);
    840   for (Int_t i=0; i<=nbinstheta; i++)
    841   {
    842     edgesx[i] = ax->GetBinLowEdge(i+1);
    843     *fLog << all << "i, theta low edge = " << i << ",  " << edgesx[i]
    844           << endl;
    845   }
    846   MBinning binth;
    847   binth.SetEdges(edgesx);
    848 
    849   // binning in sigmabar
    850   TAxis *ay = sigthon->GetYaxis();
    851   Int_t nbinssig = ay->GetNbins();
    852   TArrayD edgesy;
    853   edgesy.Set(nbinssig+1);
    854   for (Int_t i=0; i<=nbinssig; i++)
    855   {
    856     edgesy[i] = ay->GetBinLowEdge(i+1);
    857     *fLog << all << "i, sigmabar low edge = " << i << ",  " << edgesy[i]
    858           << endl;
    859   }
    860   MBinning binsg;
    861   binsg.SetEdges(edgesy);
    862 
    863 
    864   fHgMC = new TH3D;
    865   MH::SetBinning(fHgMC, &binth, &binsg, &binsg);
    866   fHgMC->SetNameTitle("3D-PaddingMatrixMC", "3D-PadMatrixThetaMC");
    867 
    868   fHgON = new TH3D;
    869   MH::SetBinning(fHgON, &binth, &binsg, &binsg);
    870   fHgON->SetNameTitle("3D-PaddingMatrixON", "3D-PadMatrixThetaON");
    871 
    8721097
    8731098  //............   loop over Theta bins   ...........................
     
    8931118    //                    padded from bin k to bin j
    8941119
    895     TH1D *hista  = sigthon->ProjectionY("sigon_y", l, l, "");
     1120    TH1D *hista  = sigthon.ProjectionY("sigon_y", l, l, "");
    8961121    Stat_t suma = hista->Integral();
    897     hista->Scale(1./suma);
     1122    if (suma != 0.0) hista->Scale(1./suma);
    8981123
    8991124    TH1D *histap  = new TH1D( (const TH1D&)*hista );
    9001125
    901     TH1D *histb  = sigthmc->ProjectionY("sigmc_y", l, l, "");
     1126    TH1D *histb  = sigthmc.ProjectionY("sigmc_y", l, l, "");
    9021127    Stat_t sumb = histb->Integral();
    903     histb->Scale(1./sumb);
     1128    if (sumb != 0.0) histb->Scale(1./sumb);
    9041129
    9051130    Merge2Distributions(hista, histb, histap, fHga, fHgb, nbinssig);
     
    9581183
    9591184    // set ranges for 2D-projections of 3D-histograms
    960     TAxis *ax = diffpixthon->GetXaxis();
     1185    TAxis *ax = diffpixthon.GetXaxis();
    9611186    ax->SetRange(j, j);
    962     ax = diffpixthmc->GetXaxis();
     1187    ax = diffpixthmc.GetXaxis();
    9631188    ax->SetRange(j, j);
    9641189
     
    9801205    //------------------------------------------------------------------
    9811206    // define target distribution  'sigma^2-sigmavar^2 vs. pixel number'
    982     ay = diffpixthon->GetYaxis();
     1207    ay = diffpixthon.GetYaxis();
    9831208    Int_t nbinspixel = ay->GetNbins();
    9841209
    985     TAxis *az = diffpixthon->GetZaxis();
     1210    TAxis *az = diffpixthon.GetZaxis();
    9861211    Int_t nbinsdiff = az->GetNbins();
    9871212
    988     hist    = (TH2D*)diffpixthon->Project3D("zy");
     1213    hist    = (TH2D*)diffpixthon.Project3D("zy");
    9891214    hist->SetName("dummy");
    990     histMC = (TH2D*)diffpixthmc->Project3D("zy");
     1215    histMC = (TH2D*)diffpixthmc.Project3D("zy");
    9911216
    9921217    normON  = hist->Integral();
     
    10111236    //------------------------------------------------------------------
    10121237    // define target distribution  'sigma vs. pixel number'
    1013     ay = sigmapixthon->GetYaxis();
     1238    ay = sigmapixthon.GetYaxis();
    10141239    nbinspixel = ay->GetNbins();
    10151240
    1016     az = sigmapixthon->GetZaxis();
     1241    az = sigmapixthon.GetZaxis();
    10171242    Int_t nbinssigma = az->GetNbins();
    10181243
    1019     hist    = (TH2D*)sigmapixthon->Project3D("zy");
     1244    hist    = (TH2D*)sigmapixthon.Project3D("zy");
    10201245    hist->SetName("dummy");
    1021     histMC = (TH2D*)sigmapixthmc->Project3D("zy");
     1246    histMC = (TH2D*)sigmapixthmc.Project3D("zy");
    10221247
    10231248    normON  = hist->Integral();
    10241249    normMC = histMC->Integral();
    10251250    if (normON  != 0.0) hist->Scale(1.0/normON);
    1026     if (normMC != 0.0) histMC->Scale(1.0/normMC);
     1251    if (normMC  != 0.0) histMC->Scale(1.0/normMC);
    10271252
    10281253    // weighted average of ON and MC distributions
     
    10431268    //------------------------------------------------------------------
    10441269    // define target distribution  'number of blind pixels per event'
    1045     ay = blindnthon->GetYaxis();
     1270    ay = blindnthon.GetYaxis();
    10461271    Int_t nbinsn = ay->GetNbins();
    10471272
     
    10531278    normMC  = hist1MC->Integral();
    10541279    if (normON  != 0.0) hist1->Scale(1.0/normON);
    1055     if (normMC != 0.0) hist1MC->Scale(1.0/normMC);
     1280    if (normMC  != 0.0) hist1MC->Scale(1.0/normMC);
    10561281
    10571282    // sum of ON and MC distributions
    10581283    hist1->Add(hist1MC, 1.0);
    1059     hist1->Scale( 1.0/hist1->Integral() );
     1284    Stat_t sum1 = hist1->Integral();
     1285    if (sum1 != 0.0) hist1->Scale( 1.0/sum1 );
    10601286
    10611287    for (Int_t k=1; k<=nbinsn; k++)
     
    10701296    //------------------------------------------------------------------
    10711297    // define target distribution  'id of blind pixel'
    1072     ay = blindidthon->GetYaxis();
     1298    ay = blindidthon.GetYaxis();
    10731299    Int_t nbinsid = ay->GetNbins();
    10741300
     
    10791305    // divide by the number of events (from fHBlindPixNTheta)
    10801306    if (normON  != 0.0) hist1->Scale(1.0/normON);
    1081     if (normMC != 0.0) hist1MC->Scale(1.0/normMC);
     1307    if (normMC  != 0.0) hist1MC->Scale(1.0/normMC);
    10821308
    10831309    // sum of ON and MC distributions
     
    11381364
    11391365    //------------------------------------
     1366 
     1367      /*
    11401368      fHSigmaThetaMC =
    11411369      (TH2D*) gROOT->FindObject("2D-ThetaSigmabarMC");
     
    11471375          return kFALSE;
    11481376        }
     1377      */ 
     1378      fHSigmaThetaMC = new TH2D;
     1379      fHSigmaThetaMC->Read("2D-ThetaSigmabarMC");
    11491380      *fLog << all
    11501381            << "MPad : Object '2D-ThetaSigmabarMC' was read in" << endl;
    11511382
     1383      /*
    11521384      fHSigmaThetaON =
    11531385      (TH2D*) gROOT->FindObject("2D-ThetaSigmabarON");
     
    11591391          return kFALSE;
    11601392        }
     1393      */
     1394      fHSigmaThetaON = new TH2D;
     1395      fHSigmaThetaON->Read("2D-ThetaSigmabarON");
    11611396      *fLog << all
    11621397            << "MPad : Object '2D-ThetaSigmabarON' was read in" << endl;
    11631398
     1399      /*
    11641400      fHSigmaThetaOFF =
    11651401      (TH2D*) gROOT->FindObject("2D-ThetaSigmabarOFF");
     
    11711407          return kFALSE;
    11721408        }
     1409      */
     1410      fHSigmaThetaOFF = new TH2D;
     1411      fHSigmaThetaOFF->Read("2D-ThetaSigmabarOFF");
    11731412      *fLog << all
    11741413            << "MPad:Object '2D-ThetaSigmabarOFF' was read in" << endl;
    11751414
    11761415    //------------------------------------
     1416      /*
    11771417      fHDiffPixTheta =
    11781418      (TH3D*) gROOT->FindObject("3D-ThetaPixDiff");
     
    11841424          return kFALSE;
    11851425        }
     1426      */
     1427      fHDiffPixTheta = new TH3D;
     1428      fHDiffPixTheta->Read("3D-ThetaPixDiff");
    11861429      *fLog << all
    11871430            << "MPad : Object '3D-ThetaPixDiff' was read in" << endl;
    11881431
     1432      /*
    11891433      fHDiffPixThetaMC =
    11901434      (TH3D*) gROOT->FindObject("3D-ThetaPixDiffMC");
     
    11961440          return kFALSE;
    11971441        }
     1442      */
     1443      fHDiffPixThetaMC = new TH3D;
     1444      fHDiffPixThetaMC->Read("3D-ThetaPixDiffMC");
    11981445      *fLog << all
    11991446            << "MPad : Object '3D-ThetaPixDiffMC' was read in" << endl;
    12001447
     1448      /*
    12011449      fHDiffPixThetaON =
    12021450      (TH3D*) gROOT->FindObject("3D-ThetaPixDiffON");
     
    12081456          return kFALSE;
    12091457        }
     1458      */
     1459      fHDiffPixThetaON = new TH3D;
     1460      fHDiffPixThetaON->Read("3D-ThetaPixDiffON");
    12101461      *fLog << all
    12111462            << "MPad : Object '3D-ThetaPixDiffON' was read in" << endl;
    12121463
     1464      /*
    12131465      fHDiffPixThetaOFF =
    12141466      (TH3D*) gROOT->FindObject("3D-ThetaPixDiffOFF");
     
    12201472          return kFALSE;
    12211473        }
     1474      */
     1475      fHDiffPixThetaOFF = new TH3D;
     1476      fHDiffPixThetaOFF->Read("3D-ThetaPixDiffOFF");
    12221477      *fLog << all
    12231478            << "MPad : Object '3D-ThetaPixDiffOFF' was read in" << endl;
     
    12251480
    12261481    //------------------------------------
     1482      /*
    12271483       fHSigmaPixTheta =
    12281484      (TH3D*) gROOT->FindObject("3D-ThetaPixSigma");
     
    12341490          return kFALSE;
    12351491        }
     1492      */
     1493      fHSigmaPixTheta = new TH3D;
     1494      fHSigmaPixTheta->Read("3D-ThetaPixSigma");
    12361495      *fLog << all
    12371496            << "MPad : Object '3D-ThetaPixSigma' was read in" << endl;
    12381497
     1498      /*
    12391499       fHSigmaPixThetaMC =
    12401500      (TH3D*) gROOT->FindObject("3D-ThetaPixSigmaMC");
     
    12461506          return kFALSE;
    12471507        }
     1508      */
     1509      fHSigmaPixThetaMC = new TH3D;
     1510      fHSigmaPixThetaMC->Read("3D-ThetaPixSigmaMC");
    12481511      *fLog << all
    12491512            << "MPad : Object '3D-ThetaPixSigmaMC' was read in" << endl;
    12501513
     1514      /*
    12511515      fHSigmaPixThetaON =
    12521516      (TH3D*) gROOT->FindObject("3D-ThetaPixSigmaON");
     
    12581522          return kFALSE;
    12591523        }
     1524      */
     1525      fHSigmaPixThetaON = new TH3D;
     1526      fHSigmaPixThetaON->Read("3D-ThetaPixSigmaON");
    12601527      *fLog << all
    12611528            << "MPad : Object '3D-ThetaPixSigmaON' was read in" << endl;
    12621529
     1530      /*
    12631531      fHSigmaPixThetaOFF =
    12641532      (TH3D*) gROOT->FindObject("3D-ThetaPixSigmaOFF");
     
    12701538          return kFALSE;
    12711539        }
     1540      */
     1541      fHSigmaPixThetaOFF = new TH3D;
     1542      fHSigmaPixThetaOFF->Read("3D-ThetaPixSigmaOFF");
    12721543      *fLog << all
    12731544            << "MPad : Object '3D-ThetaPixSigmaOFF' was read in" << endl;
    12741545
    12751546    //------------------------------------
     1547      /*
    12761548      fHgMC =
    12771549      (TH3D*) gROOT->FindObject("3D-PaddingMatrixMC");
     
    12831555          return kFALSE;
    12841556        }
     1557      */
     1558      fHgMC = new TH3D;
     1559      fHgMC->Read("3D-PaddingMatrixMC");
    12851560      *fLog << all
    12861561            << "MPad : Object '3D-PaddingMatrixMC' was read in" << endl;
    12871562
     1563      /*
    12881564      fHgON =
    12891565      (TH3D*) gROOT->FindObject("3D-PaddingMatrixON");
     
    12951571          return kFALSE;
    12961572        }
     1573      */
     1574      fHgON = new TH3D;
     1575      fHgON->Read("3D-PaddingMatrixON");
    12971576      *fLog << all
    12981577            << "MPad : Object '3D-PaddingMatrixON' was read in" << endl;
    12991578
     1579      /*
    13001580      fHgOFF =
    13011581      (TH3D*) gROOT->FindObject("3D-PaddingMatrixOFF");
     
    13071587          return kFALSE;
    13081588        }
     1589      */
     1590      fHgOFF = new TH3D;
     1591      fHgOFF->Read("3D-PaddingMatrixOFF");
    13091592      *fLog << all
    13101593            << "MPad : Object '3D-PaddingMatrixOFF' was read in" << endl;
    13111594
    13121595    //------------------------------------
     1596      /*
     1597      fHBlindPixIdTheta =
     1598      (TH2D*) gROOT->FindObject("2D-ThetaBlindId");
     1599      if (!fHBlindPixIdTheta)
     1600        {
     1601          *fLog << all
     1602                << "MPad : Object '2D-ThetaBlindId' not found on root file"
     1603                << endl;
     1604          return kFALSE;
     1605        }
     1606      */
     1607      fHBlindPixIdTheta = new TH2D;
     1608      fHBlindPixIdTheta->Read("2D-ThetaBlindId");
     1609      *fLog << all
     1610            << "MPad : Object '2D-ThetaBlindId' was read in" << endl;
     1611
     1612      /*
    13131613      fHBlindPixIdThetaMC =
    13141614      (TH2D*) gROOT->FindObject("2D-ThetaBlindIdMC");
     
    13201620          return kFALSE;
    13211621        }
     1622      */
     1623      fHBlindPixIdThetaMC = new TH2D;
     1624      fHBlindPixIdThetaMC->Read("2D-ThetaBlindIdMC");
    13221625      *fLog << all
    13231626            << "MPad : Object '2D-ThetaBlindIdMC' was read in" << endl;
    13241627
     1628      /*
    13251629      fHBlindPixIdThetaON =
    13261630      (TH2D*) gROOT->FindObject("2D-ThetaBlindIdON");
     
    13321636          return kFALSE;
    13331637        }
     1638      */
     1639      fHBlindPixIdThetaON = new TH2D;
     1640      fHBlindPixIdThetaON->Read("2D-ThetaBlindIdON");
    13341641      *fLog << all
    13351642            << "MPad : Object '2D-ThetaBlindIdON' was read in" << endl;
    13361643
     1644      /*
    13371645      fHBlindPixIdThetaOFF =
    13381646      (TH2D*) gROOT->FindObject("2D-ThetaBlindIdOFF");
     
    13441652          return kFALSE;
    13451653        }
     1654      */
     1655      fHBlindPixIdThetaOFF = new TH2D;
     1656      fHBlindPixIdThetaOFF->Read("2D-ThetaBlindIdOFF");
    13461657      *fLog << all
    1347             << "MPad : Object '2D-ThetaBlindIdMC' was read in" << endl;
     1658            << "MPad : Object '2D-ThetaBlindIdOFF' was read in" << endl;
    13481659
    13491660    //------------------------------------
     1661      /*
     1662      fHBlindPixNTheta =
     1663      (TH2D*) gROOT->FindObject("2D-ThetaBlindN");
     1664      if (!fHBlindPixNTheta)
     1665        {
     1666          *fLog << all
     1667                << "MPad : Object '2D-ThetaBlindN' not found on root file"
     1668                << endl;
     1669          return kFALSE;
     1670        }
     1671      */
     1672      fHBlindPixNTheta = new TH2D;
     1673      fHBlindPixNTheta->Read("2D-ThetaBlindN");
     1674      *fLog << all
     1675            << "MPad : Object '2D-ThetaBlindN' was read in" << endl;
     1676
     1677      /*
    13501678      fHBlindPixNThetaMC =
    13511679      (TH2D*) gROOT->FindObject("2D-ThetaBlindNMC");
     
    13571685          return kFALSE;
    13581686        }
     1687      */
     1688      fHBlindPixNThetaMC = new TH2D;
     1689      fHBlindPixNThetaMC->Read("2D-ThetaBlindNMC");
    13591690      *fLog << all
    13601691            << "MPad : Object '2D-ThetaBlindNMC' was read in" << endl;
    13611692
     1693      /*
    13621694      fHBlindPixNThetaON =
    13631695      (TH2D*) gROOT->FindObject("2D-ThetaBlindNON");
     
    13691701          return kFALSE;
    13701702        }
     1703      */
     1704      fHBlindPixNThetaON = new TH2D;
     1705      fHBlindPixNThetaON->Read("2D-ThetaBlindNON");
    13711706      *fLog << all
    13721707            << "MPad : Object '2D-ThetaBlindNON' was read in" << endl;
    13731708
     1709      /*
    13741710      fHBlindPixNThetaOFF =
    13751711      (TH2D*) gROOT->FindObject("2D-ThetaBlindNOFF");
     
    13811717          return kFALSE;
    13821718        }
     1719      */
     1720      fHBlindPixNThetaOFF = new TH2D;
     1721      fHBlindPixNThetaOFF->Read("2D-ThetaBlindNOFF");
    13831722      *fLog << all
    13841723            << "MPad : Object '2D-ThetaBlindNOFF' was read in" << endl;
     
    14021741  TFile outfile(namefileout, "RECREATE");
    14031742
     1743  fHBlindPixNTheta->Write();
    14041744  fHBlindPixNThetaMC->Write();
    14051745  fHBlindPixNThetaON->Write();
    14061746  fHBlindPixNThetaOFF->Write();
    14071747
     1748  fHBlindPixIdTheta->Write();
    14081749  fHBlindPixIdThetaMC->Write();
    14091750  fHBlindPixIdThetaON->Write();
     
    14701811  }
    14711812
    1472   fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
    1473   if (!fMcEvt)
     1813  fPointPos = (MPointingPos*)pList->FindObject("MPointingPos");
     1814  if (!fPointPos)
    14741815    {
    1475        *fLog << err << dbginf << "MPad : MMcEvt not found... aborting."
     1816       *fLog << err << dbginf << "MPad : MPointingPos not found... aborting."
    14761817             << endl;
    14771818       return kFALSE;
    1478      }
     1819    }
    14791820 
    14801821   fPed = (MPedPhotCam*)pList->FindObject("MPedPhotCam");
     
    15101851     }
    15111852
    1512    fBlinds = (MBlindPixels*)pList->FindCreateObj("MBlindPixels");
    1513    if (!fBlinds)
     1853   fBlindPix = (MBlindPixels*)pList->FindCreateObj("MBlindPixels");
     1854   if (!fBlindPix)
    15141855     {
    15151856       *fLog << err << "MPad : MBlindPixels not found... aborting."
     
    15321873   // plot pedestal sigmas
    15331874   fHSigmaPedestal = new TH2D("SigPed","Sigma: after vs. before padding",
    1534                      100, 0.0, 5.0, 100, 0.0, 5.0);
     1875                     100, 0.0, 75.0, 100, 0.0, 75.0);
    15351876   fHSigmaPedestal->SetXTitle("Pedestal sigma before padding");
    15361877   fHSigmaPedestal->SetYTitle("Pedestal sigma after padding");
     
    15381879   // plot no.of photons (before vs. after padding)
    15391880   fHPhotons = new TH2D("Photons","Photons: after vs.before padding",
    1540                         100, -10.0, 90.0, 100, -10, 90);
     1881                        100, -100.0, 300.0, 100, -100, 300);
    15411882   fHPhotons->SetXTitle("no.of photons before padding");
    15421883   fHPhotons->SetYTitle("no.of photons after padding");
    15431884
    15441885   // plot of added NSB
    1545    fHNSB = new TH1D("NSB","Distribution of added NSB", 100, -10.0, 10.0);
     1886   fHNSB = new TH1D("NSB","Distribution of added NSB", 100, -100.0, 200.0);
    15461887   fHNSB->SetXTitle("no.of added NSB photons");
    15471888   fHNSB->SetYTitle("no.of pixels");
     
    15501891   //--------------------------------------------------------------------
    15511892
    1552    fIter = 20;
     1893   fIter = 10;
    15531894
    15541895   memset(fErrors,   0, sizeof(fErrors));
     
    15701911Int_t MPad::Process()
    15711912{
    1572   *fLog << all << "Entry MPad::Process();" << endl;
     1913  //*fLog << all << "Entry MPad::Process();" << endl;
    15731914
    15741915  // this is the conversion factor from the number of photons
     
    15761917  // later to be taken from MCalibration
    15771918  // fPEperPhoton = PW * LG * QE * 1D
    1578   Double_t fPEperPhoton = 0.95 * 0.90 * 0.13 * 0.9;
     1919  Double_t fPEperPhoton = 0.92 * 0.94 * 0.23 * 0.9;
    15791920
    15801921  //------------------------------------------------
    1581   // add pixels to MCerPhotEvt which are not yet in;
    1582   // set their number of photons equal to zero
    1583 
     1922  // Add pixels to MCerPhotEvt which are not yet in;
     1923  // set their number of photons equal to zero.
     1924  // Purpose : by the padding the number of photons is changed
     1925  // so that cleaning and cuts may be affected.
     1926  // However, no big effect is expectec unless the padding is strong
     1927  // (strong increase of the noise level)
     1928  // At present comment out this code
     1929
     1930  /*
    15841931  UInt_t imaxnumpix = fCam->GetNumPixels();
    15851932
     
    16031950    fEvt->AddPixel(i, 0.0, (*fPed)[i].GetRms());
    16041951  }
    1605 
     1952  */
    16061953
    16071954
     
    16151962  // Calculate average sigma of the event
    16161963  //
    1617   Double_t sigbarold_phot = fSigmabar->Calc(*fCam, *fPed, *fEvt);
    1618   *fLog << all << "MPad::Process(); before padding : " << endl;
    1619   fSigmabar->Print("");
    1620   Double_t sigbarold  = sigbarold_phot * fPEperPhoton;
    1621   Double_t sigbarold2 = sigbarold*sigbarold;
    1622 
    1623   const Double_t theta = kRad2Deg*fMcEvt->GetTelescopeTheta();
    1624   *fLog << all << "theta = " << theta << endl;
     1964
     1965  fSigmabar->Calc(*fCam, *fPed, *fEvt);
     1966  //*fLog << all << "MPad::Process(); before padding : " << endl;
     1967  //fSigmabar->Print("");
     1968
     1969  // inner sigmabar/sqrt(area)
     1970  Double_t sigbarInnerold_phot = fSigmabar->GetSigmabarInner();
     1971  Double_t sigbarInnerold  = sigbarInnerold_phot * fPEperPhoton;
     1972  Double_t sigbarInnerold2 = sigbarInnerold*sigbarInnerold;
     1973
     1974  // outer sigmabar/sqrt(area)
     1975  Double_t sigbarOuterold_phot = fSigmabar->GetSigmabarOuter();
     1976  Double_t sigbarOuterold  = sigbarOuterold_phot * fPEperPhoton;
     1977  Double_t sigbarOuterold2 = sigbarOuterold*sigbarOuterold;
     1978
     1979  const Double_t theta = fPointPos->GetZd();
     1980
     1981  //*fLog << all << "theta = " << theta << endl;
    16251982
    16261983  Int_t binTheta = fHBlindPixNTheta->GetXaxis()->FindBin(theta);
     
    16291986    *fLog << warn
    16301987          << "MPad::Process(); binNumber out of range : theta, binTheta = "
    1631           << theta << ",  " << binTheta << ";  Skip event " << endl;
    1632     // event cannot be padded; skip event
     1988          << theta << ",  " << binTheta << ";  aborting " << endl;
    16331989
    16341990    rc = 2;
     
    16371993  }
    16381994
     1995  //*fLog << all << "binTheta = " << binTheta << endl;
     1996 
     1997
    16391998  //-------------------------------------------
    16401999  // get number of events in this theta bin
    1641   // and number of events in this sigbarold_phot bin
     2000  // and number of events in this sigbarInnerold_phot bin
    16422001
    16432002  Double_t nTheta;
     
    16572016  TH1D *hn;
    16582017  hn = st->ProjectionY("", binTheta, binTheta, "");
     2018
     2019  //*fLog << "Title of histogram : " << st->GetTitle() << endl;
     2020  //for (Int_t i=1; i<=hn->GetNbinsX(); i++)
     2021  //{
     2022  //  *fLog << "bin " << i << " : no.of entries = " << hn->GetBinContent(i)
     2023  //        << endl;
     2024  //}
     2025
    16592026  nTheta = hn->Integral();
    1660   Int_t binSigma = hn->FindBin(sigbarold_phot);
     2027  Int_t binSigma = hn->FindBin(sigbarInnerold_phot);
    16612028  nSigma = hn->GetBinContent(binSigma);
    16622029
    1663    *fLog << all           
    1664          << "Theta, sigbarold_phot, binTheta, binSigma, nTheta, nSigma = "
    1665          << theta << ",  " << sigbarold_phot << ",  " << binTheta << ",  "
    1666          << binSigma << ",  " << nTheta << ",  " << nSigma   << endl;     
     2030  //*fLog << all           
     2031  //       << "Theta, sigbarold_phot, binTheta, binSigma, nTheta, nSigma = "
     2032  //       << theta << ",  " << sigbarInnerold_phot << ",  " << binTheta
     2033  //       << ",  "
     2034  //       << binSigma << ",  " << nTheta << ",  " << nSigma   << endl;     
    16672035
    16682036  delete hn;
    1669  
    1670 
     2037 
    16712038  //-------------------------------------------
    16722039  // for the current theta :
     
    16882055    if ( nblind->Integral() == 0.0 )
    16892056    {
    1690       *fLog << warn << "MPad::Process(); projection for Theta bin "
    1691             << binTheta << " has no entries; Skip event " << endl;
     2057      *fLog << warn << "MPad::Process(); projection of '"
     2058            << fHBlindPixNThetaOFF->GetName() << "' for Theta bin "
     2059            << binTheta << " has no entries; aborting " << endl;
    16922060      // event cannot be padded; skip event
    16932061      delete nblind;
     
    17322100          nlist++;
    17332101
    1734           fBlinds->SetPixelBlind(idBlind);
    1735           *fLog << all << "idBlind = " << idBlind << endl;
     2102          fBlindPix->SetPixelBlind(idBlind);
     2103          //*fLog << all << "idBlind = " << idBlind << endl;
    17362104        }
    1737       fBlinds->SetReadyToSave();
     2105      fBlindPix->SetReadyToSave();
    17382106
    17392107      delete hblind;
     
    17522120    if ( nblind->Integral() == 0.0 )
    17532121    {
    1754       *fLog << warn << "MPad::Process(); projection for Theta bin "
     2122      *fLog << warn << "MPad::Process(); projection of '"
     2123            << fHBlindPixNThetaON->GetName() << "' for Theta bin "
    17552124            << binTheta << " has no entries; Skip event " << endl;
    1756       // event cannot be padded; skip event
    17572125      delete nblind;
    17582126
     
    17962164          nlist++;
    17972165
    1798           fBlinds->SetPixelBlind(idBlind);
    1799           *fLog << all << "idBlind = " << idBlind << endl;
     2166          fBlindPix->SetPixelBlind(idBlind);
     2167          //*fLog << all << "idBlind = " << idBlind << endl;
    18002168        }
    1801       fBlinds->SetReadyToSave();
     2169      fBlindPix->SetReadyToSave();
    18022170
    18032171      delete hblind;
     
    18102178  //
    18112179
    1812   Int_t binSig = fHgON->GetYaxis()->FindBin(sigbarold_phot);
    1813   *fLog << all << "binSig, sigbarold_phot = " << binSig << ",  "
    1814           << sigbarold_phot << endl;
     2180  Int_t binSig = fHgON->GetYaxis()->FindBin(sigbarInnerold_phot);
     2181  //*fLog << all << "binSig, sigbarInnerold_phot = " << binSig << ",  "
     2182  //        << sigbarInnerold_phot << endl;
    18152183
    18162184  Double_t prob;
     
    18432211    prob = 0.0;
    18442212
    1845    *fLog << all << "nTheta, nSigma, prob = " << nTheta << ",  " << nSigma
    1846          << ",  " << prob << endl;
     2213  //*fLog << all << "nTheta, nSigma, prob = " << nTheta << ",  " << nSigma
     2214  //       << ",  " << prob << endl;
    18472215
    18482216  if ( prob <= 0.0  ||  gRandom->Uniform() > prob )
     
    18502218    delete hpad;
    18512219    // event should not be padded
    1852     *fLog << all << "event is not padded" << endl;
     2220    //*fLog << all << "event is not padded" << endl;
    18532221
    18542222    rc = 8;
     
    18572225  }
    18582226  // event should be padded
    1859   *fLog << all << "event will be padded" << endl; 
     2227  //*fLog << all << "event will be padded" << endl; 
    18602228
    18612229
     
    18642232  //     for MC/ON/OFF data according to the matrix fHgMC/ON/OFF
    18652233  //
    1866   Double_t sigmabar_phot = 0;
    1867   Double_t sigmabar      = 0;
     2234  Double_t sigmabarInner_phot = 0;
     2235  Double_t sigmabarInner      = 0;
    18682236
    18692237 
     
    18762244  //}
    18772245
    1878   sigmabar_phot = hpad->GetRandom();
    1879   sigmabar = sigmabar_phot * fPEperPhoton;
    1880 
    1881   *fLog << all << "sigmabar_phot = " << sigmabar_phot << endl;
     2246  sigmabarInner_phot = hpad->GetRandom();
     2247  sigmabarInner = sigmabarInner_phot * fPEperPhoton;
     2248
     2249  //*fLog << all << "sigmabarInner_phot = " << sigmabarInner_phot << endl;
    18822250
    18832251  delete hpad;
    18842252 
    1885   const Double_t sigmabar2 = sigmabar*sigmabar;
     2253  // new inner sigmabar2/area
     2254  const Double_t sigmabarInner2 = sigmabarInner*sigmabarInner;
    18862255
    18872256  //-------------------------------------------
    18882257
    1889   *fLog << all << "MPad::Process(); sigbarold, sigmabar = "
    1890         << sigbarold << ",  "<< sigmabar << endl;
    1891 
    1892   // Skip event if target sigmabar is <= sigbarold
    1893   if (sigmabar <= sigbarold)
     2258  //*fLog << all << "MPad::Process(); sigbarInnerold, sigmabarInner = "
     2259  //      << sigbarInnerold << ",  "<< sigmabarInner << endl;
     2260
     2261  // Stop if target sigmabar is <= sigbarold
     2262  if (sigmabarInner <= sigbarInnerold)
    18942263  {
    1895     *fLog << all << "MPad::Process(); target sigmabar is less than sigbarold : "
    1896           << sigmabar << ",  " << sigbarold << ",   Skip event" << endl;
     2264    *fLog << all << "MPad::Process(); target sigmabarInner is less than sigbarInnerold : "
     2265          << sigmabarInner << ",  " << sigbarInnerold << ",   aborting"
     2266          << endl;
    18972267
    18982268    rc = 4;
     
    19232293  }
    19242294
    1925   // Get RMS of (Sigma^2-sigmabar^2) in this Theta bin.
    1926   // The average electronic noise (to be added) has to be well above this RMS,
    1927   // otherwise the electronic noise of an individual pixel (elNoise2Pix)
    1928   // may become negative
     2295  // In this Theta bin, get RMS of (Sigma^2-sigmabar^2) for inner pixels
     2296  // The average electronic noise (to be added) has to be in the order of
     2297  // this RMS, otherwise the electronic noise of an individual pixel
     2298  // (elNoise2Pix) may become negative
     2299
     2300  // Attention : maximum ID of inner pixels hard coded !!!
     2301  Int_t idmaxpixinner = 396;
     2302  Int_t binmaxpixinner =
     2303        fHDiffPixTheta->GetYaxis()->FindBin( (Double_t)idmaxpixinner );
    19292304
    19302305  TH1D *hnoise;
    19312306  if (fType == "MC")
    1932     hnoise = fHDiffPixTheta->ProjectionZ("", binTheta, binTheta, 0, 9999, "");
     2307    hnoise = fHDiffPixTheta->ProjectionZ("", binTheta, binTheta, 0, binmaxpixinner, "");
    19332308  else if (fType == "ON")
    1934     hnoise = fHDiffPixThetaOFF->ProjectionZ("", binTheta, binTheta, 0, 9999, "");
     2309    hnoise = fHDiffPixThetaOFF->ProjectionZ("", binTheta, binTheta, 0, binmaxpixinner, "");
    19352310  else if (fType == "OFF")
    1936     hnoise = fHDiffPixThetaON->ProjectionZ("", binTheta, binTheta, 0, 9999, "");
     2311    hnoise = fHDiffPixThetaON->ProjectionZ("", binTheta, binTheta, 0, binmaxpixinner, "");
    19372312  else
    19382313  {
     
    19462321  delete hnoise;
    19472322
    1948   elNoise2 = TMath::Min(RMS,  sigmabar2 - sigbarold2);
    1949   *fLog << all << "elNoise2 = " << elNoise2 << endl;
    1950 
    1951   lambdabar = (sigmabar2 - sigbarold2 - elNoise2) / F2excess; 
     2323  elNoise2 = TMath::Min(2.0*RMS,  sigmabarInner2 - sigbarInnerold2);
     2324  //*fLog << all << "elNoise2 = " << elNoise2 << endl;
     2325
     2326  lambdabar = (sigmabarInner2 - sigbarInnerold2 - elNoise2) / F2excess; 
    19522327
    19532328  // This value of lambdabar is the same for all pixels;
     
    19572332  // do the padding for each pixel
    19582333  //
    1959   // pad only pixels   - which are used (before image cleaning)
     2334  // pad only pixels   - which are used and not blind (before image cleaning)
    19602335  //
    19612336
     
    19712346
    19722347
     2348  // throw the Sigma for the pixels from the distribution fHDiffPixTheta
     2349  // MC  : from fHDiffPixTheta
     2350  // ON  : from fHDiffPixThetaOFF
     2351  // OFF : from fHDiffPixThetaON
     2352
     2353  TH3D *sp = NULL;
     2354
     2355  if      (fType == "MC")  sp = fHDiffPixTheta;
     2356  else if (fType == "ON")  sp = fHDiffPixThetaOFF;
     2357  else if (fType == "OFF") sp = fHDiffPixThetaON;
     2358  else
     2359  {
     2360    *fLog << err << "MPad::Process(); illegal data type... aborting"
     2361          << endl;
     2362    return kERROR;
     2363  }
     2364
     2365  Double_t sigbarold2;
     2366  Double_t sigmabar2;
     2367  Double_t sigmabarOuter2;
     2368
     2369
    19732370  for (UInt_t i=0; i<npix; i++)
    19742371  {   
     2372
    19752373    MCerPhotPix &pix = (*fEvt)[i];
    19762374    if ( !pix.IsPixelUsed() )
     
    19902388    Double_t ratioArea = 1.0 / fCam->GetPixRatio(j);
    19912389
     2390    if (ratioArea < 1.5)
     2391    {
     2392      sigbarold2 = sigbarInnerold2;
     2393      sigmabar2  = sigmabarInner2;
     2394    }
     2395    else
     2396    {
     2397      sigbarold2    = sigbarOuterold2;
     2398      //sigbarOuter2  = sigmabarInner2 * sigbarOuterold2 / sigbarInnerold2;
     2399      sigmabarOuter2  = sigmabarInner2 + (sigbarOuterold2 - sigbarInnerold2);
     2400      sigmabar2     = sigmabarOuter2;
     2401    }
     2402
    19922403    MPedPhotPix &ppix = (*fPed)[j];
     2404
     2405    if ( fBlindPix != NULL  &&  fBlindPix->IsBlind(j) )
     2406    {
     2407       // this should never occur, because blind pixels should have
     2408       // been set unused by MBlindPixelsCalc2::UnMap()
     2409       //*fLog << all << "MPad::Process; blind pixel found which is used, j = "
     2410       //       << j << "... go to next pixel." << endl;
     2411       continue;
     2412    }   
     2413
     2414    // count number of pixels treated
     2415    fWarnings[0]++;
     2416
     2417
    19932418    Double_t oldsigma_phot = ppix.GetRms();
    19942419    Double_t oldsigma = oldsigma_phot * fPEperPhoton;
    1995     Double_t oldsigma2 = oldsigma*oldsigma;
     2420    Double_t oldsigma2 = oldsigma*oldsigma / ratioArea;
    19962421
    19972422    //---------------------------------
     
    20052430    TH1D *hdiff;
    20062431
    2007     // throw the Sigma for this pixel from the distribution fHDiffPixTheta
    2008     // MC  : from fHDiffPixTheta
    2009     // ON  : from fHDiffPixThetaOFF
    2010     // OFF : from fHDiffPixThetaON
    2011 
    2012     TH3D *sp = NULL;
    2013 
    2014     if      (fType == "MC")  sp = fHDiffPixTheta;
    2015     else if (fType == "ON")  sp = fHDiffPixThetaOFF;
    2016     else if (fType == "OFF") sp = fHDiffPixThetaON;
    2017     else
    2018     {
    2019       *fLog << err << "MPad::Process(); illegal data type... aborting"
    2020             << endl;
    2021       return kERROR;
    2022     }
    2023 
    2024     hdiff = sp->ProjectionZ("", binTheta, binTheta,
    2025                                 binPixel, binPixel, "");
    2026 
    2027     if ( hdiff->GetEntries() == 0 )
    2028     {
    2029       *fLog << warn << "MPad::Process(); projection for Theta bin "
    2030             << binTheta << "  and pixel bin " << binPixel 
    2031             << " has no entries;  aborting " << endl;
    2032       delete hdiff;
    2033 
    2034       rc = 5;
    2035       fErrors[rc]++;
    2036       return kCONTINUE;     
    2037     }
    2038 
    2039     count = 0;
    2040     ok = kFALSE;
    2041     for (Int_t m=0; m<fIter; m++)
    2042     {
    2043       count += 1;
    2044       diff_phot = hdiff->GetRandom();
    2045       diff = diff_phot * fPEperPhoton * fPEperPhoton;
     2432
     2433     hdiff = sp->ProjectionZ("", binTheta, binTheta,
     2434                                 binPixel, binPixel, "");
     2435     Double_t integral =  hdiff->Integral();
     2436     // if there are no entries in hdiff, diff cannot be thrown
     2437     // in this case diff will be set to zero
     2438     if ( integral == 0 )
     2439     {
     2440       //*fLog << warn << "MPad::Process(); fType = " << fType
     2441       //      << ", projection of '"
     2442       //      << sp->GetName() << "' for Theta bin "
     2443       //      << binTheta << "  and pixel " << j 
     2444       //      << " has no entries; set diff equal to the old difference  "
     2445       //      << endl;
     2446
     2447       diff = TMath::Max(oldsigma2 - sigbarold2,
     2448                         lambdabar*F2excess + oldsigma2 - sigmabar2);
     2449
     2450       rc = 2;
     2451       fWarnings[rc]++;
     2452     }
     2453
     2454     // start of else -------------------
     2455     else
     2456     {
     2457       count = 0;
     2458       ok = kFALSE;
     2459       for (Int_t m=0; m<fIter; m++)
     2460       {
     2461         count += 1;
     2462         diff_phot = hdiff->GetRandom();
     2463
     2464         //*fLog << "after GetRandom : j, m, diff_phot = " << j << " : "
     2465         //      << m << ",  " << diff_phot << endl;
     2466
     2467         diff = diff_phot * fPEperPhoton * fPEperPhoton;
    20462468 
    2047      // the following condition ensures that elNoise2Pix > 0.0
    2048       if ( (diff + sigmabar2 - oldsigma2/ratioArea
    2049                                - lambdabar*F2excess) > 0.0 )
    2050       {
    2051         ok = kTRUE;
    2052         break;
    2053       }
    2054     }
    2055 
    2056     if (!ok)
    2057     {
    2058       *fLog << all << "theta, j, count, sigmabar, diff = " << theta
    2059             << ",  "
    2060             << j << ",  " << count << ",  " << sigmabar << ",  "
    2061             << diff << endl;
    2062       diff = lambdabar*F2excess + oldsigma2/ratioArea - sigmabar2;
    2063 
    2064       rw = 1;
    2065       fWarnings[rw]++;
    2066     }
    2067     else
    2068     {
    2069       rw = 0;
    2070       fWarnings[rw]++;
    2071     }
     2469         // the following condition ensures that elNoise2Pix > 0.0
     2470         if ( (diff + sigmabar2 - oldsigma2
     2471                                - lambdabar*F2excess) > 0.0 )
     2472         {
     2473           ok = kTRUE;
     2474           break;
     2475         }
     2476       }
     2477
     2478       if (!ok)
     2479       {
     2480         //*fLog << all << "theta, j, count, sigmabar2, diff, oldsigma2, ratioArea, lambdabar = "
     2481         //      << theta << ",  "
     2482         //      << j << ",  " << count << ",  " << sigmabar2 << ",  "
     2483         //      << diff << ",  " << oldsigma2 << ",  " << ratioArea << ",  "
     2484         //      << lambdabar << endl;
     2485         diff = lambdabar*F2excess + oldsigma2 - sigmabar2;
     2486
     2487         rw = 1;
     2488         fWarnings[rw]++;
     2489       }
     2490     }
     2491     // end of else --------------------
    20722492
    20732493    delete hdiff;
     
    20782498    // get the additional sigma^2 for this pixel (due to the padding)
    20792499
    2080     addSig2 = sigma2*ratioArea - oldsigma2;
     2500    addSig2 = (sigma2 - oldsigma2) * ratioArea;
    20812501    addSig2_phot = addSig2 / (fPEperPhoton * fPEperPhoton);
    20822502
     
    21392559
    21402560
    2141     Double_t newsigma = sqrt( oldsigma2 + addSig2 );
     2561    Double_t newsigma = sqrt( sigma2 * ratioArea );
    21422562    Double_t newsigma_phot = newsigma / fPEperPhoton;
    21432563    ppix.SetRms( newsigma_phot );
     
    21502570
    21512571  fSigmabar->Calc(*fCam, *fPed, *fEvt);
    2152   *fLog << all << "MPad::Process(); after padding : " << endl;
    2153   fSigmabar->Print("");
    2154 
    2155   *fLog << all << "Exit MPad::Process();" << endl;
     2572  //*fLog << all << "MPad::Process(); after padding : " << endl;
     2573  //fSigmabar->Print("");
     2574
     2575  //*fLog << all << "Exit MPad::Process();" << endl;
    21562576
    21572577  rc = 0;
     
    21732593    *fLog << dec << setfill(' ');
    21742594
    2175     int temp;
    2176     if (fWarnings[0] != 0.0)   
    2177       temp = (int)(fWarnings[1]*100/fWarnings[0]);
    2178     else
    2179       temp = 100;
     2595    if (fWarnings[0] == 0 ) fWarnings[0] = 1;
    21802596
    21812597    *fLog << " " << setw(7) << fWarnings[1] << " (" << setw(3)
    2182           << temp
    2183           << "%) Warning : iteration to find acceptable sigma failed"
     2598          << (int)(fWarnings[1]*100/fWarnings[0])
     2599          << "%) Pixel: iteration to find acceptable sigma failed"
    21842600          << ", fIter = " << fIter << endl;
    21852601
    2186     *fLog << " " << setw(7) << fErrors[1] << " (" << setw(3)
    2187           << (int)(fErrors[1]*100/GetNumExecutions())
    2188           << "%) Evts skipped due to: Sigmabar_old > 0" << endl;
     2602    *fLog << " " << setw(7) << fWarnings[2] << " (" << setw(3)
     2603          << (int)(fWarnings[2]*100/fWarnings[0])
     2604          << "%) Pixel: No data for generating Sigma^2-Sigmabar^2" << endl;
     2605
    21892606
    21902607    *fLog << " " << setw(7) << fErrors[2] << " (" << setw(3)
     
    21922609          << "%) Evts skipped due to: Zenith angle out of range" << endl;
    21932610
    2194     *fLog << " " << setw(7) << fErrors[3] << " (" << setw(3)
    2195           << (int)(fErrors[3]*100/GetNumExecutions())
    2196           << "%) Evts skipped due to: No data for generating Sigmabar" << endl;
    2197 
    21982611    *fLog << " " << setw(7) << fErrors[4] << " (" << setw(3)
    21992612          << (int)(fErrors[4]*100/GetNumExecutions())
    22002613          << "%) Evts skipped due to: Target sigma <= Sigmabar_old" << endl;
    2201 
    2202     *fLog << " " << setw(7) << fErrors[5] << " (" << setw(3)
    2203           << (int)(fErrors[5]*100/GetNumExecutions())
    2204           << "%) Evts skipped due to: No data for generating Sigma^2-Sigmabar^2" << endl;
    2205 
    2206     *fLog << " " << setw(7) << fErrors[6] << " (" << setw(3)
    2207           << (int)(fErrors[6]*100/GetNumExecutions())
    2208           << "%) Evts skipped due to: No data for generating Sigma" << endl;
    22092614
    22102615    *fLog << " " << setw(7) << fErrors[7] << " (" << setw(3)
     
    22242629
    22252630    //---------------------------------------------------------------
    2226     TCanvas &c = *(MH::MakeDefCanvas("Pad", "", 900, 1500));
    2227     c.Divide(3, 5);
     2631    TCanvas &c = *(MH::MakeDefCanvas("Pad", "", 900, 600));
     2632    c.Divide(3, 2);
    22282633    gROOT->SetSelectedPad(NULL);
    22292634
     
    22452650    //--------------------------------------------------------------------
    22462651
    2247 
     2652    /*
    22482653    c.cd(4);
    22492654    fHSigmaTheta->SetDirectory(NULL);
     
    22512656    fHSigmaTheta->DrawCopy();     
    22522657    fHSigmaTheta->SetBit(kCanDelete);     
    2253 
     2658    */
    22542659
    22552660    //--------------------------------------------------------------------
    22562661
    2257 
     2662    /*
    22582663    c.cd(7);
    22592664    fHBlindPixNTheta->SetDirectory(NULL);
     
    22612666    fHBlindPixNTheta->DrawCopy();     
    22622667    fHBlindPixNTheta->SetBit(kCanDelete);     
     2668    */
    22632669
    22642670    //--------------------------------------------------------------------
    22652671
    2266 
     2672    /*
    22672673    c.cd(10);
    22682674    fHBlindPixIdTheta->SetDirectory(NULL);
     
    22702676    fHBlindPixIdTheta->DrawCopy();     
    22712677    fHBlindPixIdTheta->SetBit(kCanDelete);     
    2272 
     2678    */
    22732679
    22742680    //--------------------------------------------------------------------
    22752681    // draw the 3D histogram (target): Theta, pixel, Sigma^2-Sigmabar^2
    22762682
     2683    /*
    22772684    c.cd(5);
    22782685    TH2D *l1 = NULL;
     
    22962703    l2->DrawCopy("box");
    22972704    l2->SetBit(kCanDelete);;
     2705    */
    22982706
    22992707    //--------------------------------------------------------------------
    23002708    // draw the 3D histogram (target): Theta, pixel, Sigma
    23012709
     2710    /*
    23022711    c.cd(6);
    23032712    TH2D *k1 = NULL;
     
    23212730    k2->DrawCopy("box");
    23222731    k2->SetBit(kCanDelete);;
    2323 
     2732    */
    23242733
    23252734    //--------------------------------------------------------------------
    23262735
    2327     c.cd(13);
     2736   
     2737    c.cd(4);
    23282738    TH2D *m1;
    23292739    m1 = (TH2D*) ((TH3*)fHgON)->Project3D("zy");
    23302740    m1->SetDirectory(NULL);
    2331     m1->SetTitle("(Target) Sigmabar-new vs. Sigmabar-old (ON, all  \\Theta)");
     2741    m1->SetTitle("(fHgON) Sigmabar-new vs. Sigmabar-old (ON, all  \\Theta)");
    23322742    m1->SetXTitle("Sigmabar-old");
    23332743    m1->SetYTitle("Sigmabar-new");
     
    23362746    m1->SetBit(kCanDelete);;
    23372747
    2338     c.cd(14);
     2748    c.cd(5);
    23392749    TH2D *m2;
    23402750    m2 = (TH2D*) ((TH3*)fHgOFF)->Project3D("zy");
    23412751    m2->SetDirectory(NULL);
    2342     m2->SetTitle("(Target) Sigmabar-new vs. Sigmabar-old (OFF, all  \\Theta)");
     2752    m2->SetTitle("(fHgOFF) Sigmabar-new vs. Sigmabar-old (OFF, all  \\Theta)");
    23432753    m2->SetXTitle("Sigmabar-old");
    23442754    m2->SetYTitle("Sigmabar-new");
     
    23472757    m2->SetBit(kCanDelete);;
    23482758
    2349     c.cd(15);
     2759    c.cd(6);
    23502760    TH2D *m3;
    23512761    m3 = (TH2D*) ((TH3*)fHgMC)->Project3D("zy");
    23522762    m3->SetDirectory(NULL);
    2353     m3->SetTitle("(Target) Sigmabar-new vs. Sigmabar-old (MC, all  \\Theta)");
     2763    m3->SetTitle("(fHgMC) Sigmabar-new vs. Sigmabar-old (MC, all  \\Theta)");
    23542764    m3->SetXTitle("Sigmabar-old");
    23552765    m3->SetYTitle("Sigmabar-new");
     
    23692779
    23702780
     2781
     2782
     2783
     2784
  • trunk/MagicSoft/Mars/manalysis/MPad.h

    r2798 r4584  
    1717class MCerPhotEvt;
    1818class MPedPhotCam;
    19 class MMcEvt;
     19class MPointingPos;
    2020class MSigmabar;
    2121class MParList;
     
    3131    MCerPhotEvt    *fEvt;
    3232    MSigmabar      *fSigmabar;
    33     MMcEvt         *fMcEvt;
     33    MPointingPos   *fPointPos;
    3434    MPedPhotCam    *fPed;
    35     MBlindPixels   *fBlinds;
     35    MBlindPixels   *fBlindPix;
    3636
    3737    TString        fType;           // type of data to be padded
     
    4141
    4242    Int_t          fErrors[9];
    43     Int_t          fWarnings[2];
     43    Int_t          fWarnings[3];
    4444
    4545    //----------------------------------
     
    8989
    9090
    91     Bool_t Merge2Distributions(TH1D *hista, TH1D * histb, TH1D * histap,
    92                                TH2D *fHga,  TH2D * fHgb, Int_t nbinssig);
     91    Bool_t Merge2Distributions(TH1D *hista, TH1D *histb, TH1D *histap,
     92                               TH2D *fHga,  TH2D *fHgb, Int_t nbinssig);
    9393
     94    Bool_t UpdateHg(TH2D *fHga, TH1D *histap, TH2D *fHge, TH3D *fHgA,
     95                    Int_t nbinssig, Int_t l);
    9496
    9597public:
     
    98100
    99101    Bool_t MergeONOFFMC(
    100       TH2D *sigthmc,  TH3D *diffpixthmc, TH3D *sigmapixthmc,
    101       TH2D *blindidthmc,  TH2D *blindnthmc,
    102       TH2D *sigthon,  TH3D *diffpixthon, TH3D *sigmapixthon,
    103       TH2D *blindidthon,  TH2D *blindnthon,
    104       TH2D *sigthoff=NULL, TH3D *diffpixthoff=NULL,TH3D *sigmapixthoff=NULL,
    105       TH2D *blindidthoff=NULL, TH2D *blindnthoff=NULL);
     102      TH2D& sigthmc,  TH3D& diffpixthmc, TH3D& sigmapixthmc,
     103      TH2D& blindidthmc,  TH2D& blindnthmc,
     104      TH2D& sigthon,  TH3D& diffpixthon, TH3D& sigmapixthon,
     105      TH2D& blindidthon,  TH2D& blindnthon,
     106      TH2D& sigthoff, TH3D& diffpixthoff,TH3D& sigmapixthoff,
     107      TH2D& blindidthoff, TH2D& blindnthoff);
    106108
    107109    Bool_t MergeONMC(
    108       TH2D *sigthmc,  TH3D *diffpixthmc, TH3D *sigmapixthmc,
    109       TH2D *blindidthmc,  TH2D *blindnthmc,
    110       TH2D *sigthon,  TH3D *diffpixthon, TH3D *sigmapixthon,
    111       TH2D *blindidthon,  TH2D *blindnthon);
     110      TH2D& sigthmc,  TH3D& diffpixthmc, TH3D& sigmapixthmc,
     111      TH2D& blindidthmc,  TH2D& blindnthmc,
     112      TH2D& sigthon,  TH3D&diffpixthon, TH3D& sigmapixthon,
     113      TH2D& blindidthon,  TH2D& blindnthon);
    112114
    113115    Bool_t ReadPaddingDist(const char *filein);
  • trunk/MagicSoft/Mars/manalysis/MSigmabar.cc

    r3530 r4584  
    3030//                                                                         //
    3131// This is the storage container to hold information about                 //
    32 // "average" pedestal sigmas                                               //
    33 //                                                                         //
    34 // In calculating averages all sigmas are normalized to the area of pixel 0//
     32// "average" pedestal RMS                                                  //
     33//                                                                         //
     34// The "average" pedestal RMS is calculated as                             //
     35//     <pedRMS> = sqrt( sum_i( (pedRMS_i)^2/area_i ) / no.of pixels )      //
     36//                                                                         //
     37//     which is the sqrt of the average (pedRMS^2 per area)                //
    3538//                                                                         //
    3639/////////////////////////////////////////////////////////////////////////////
     
    109112
    110113    //
    111     // sum up sigma/sqrt(area) for each sector,
     114    // sum up sigma^2/area for each sector,
    112115    // separately for inner and outer region;
    113116    //
     
    147150        const Double_t ratio = geom.GetPixRatio(idx);
    148151
     152        //*fLog << "pixel id, ratio = " << idx << ",  " << ratio << endl;
     153
    149154        const MGeomPix &gpix = geom[idx];
    150155
     
    171176        {
    172177            innerPixels[sector]++;
    173             innerSum[sector]+= sigma * sqrt(ratio);
     178            innerSum[sector]+= sigma*sigma * ratio;
    174179        }
    175180        else
    176181        {
    177182            outerPixels[sector]++;
    178             outerSum[sector]+= sigma * sqrt(ratio);
     183            outerSum[sector]+= sigma*sigma * ratio;
    179184        }
    180185    }
     
    192197    }
    193198
    194     if (fInnerPixels > 0) fSigmabarInner = fSumInner / fInnerPixels;
    195     if (fOuterPixels > 0) fSigmabarOuter = fSumOuter / fOuterPixels;
    196 
    197     //
    198     // this is the average sigma/sqrt(area) (over all pixels)
     199    if (fInnerPixels > 0) fSigmabarInner = sqrt(fSumInner / fInnerPixels);
     200    if (fOuterPixels > 0) fSigmabarOuter = sqrt(fSumOuter / fOuterPixels);
     201
     202    //
     203    // this is the sqrt of the average sigma^2/area
    199204    //
    200205    fSigmabar = (fInnerPixels+fOuterPixels)<=0 ? 0:
    201                 (fSumInner+fSumOuter)/(fInnerPixels+fOuterPixels);
     206                sqrt( (fSumInner+fSumOuter)/(fInnerPixels+fOuterPixels) );
    202207
    203208    for (UInt_t i=0; i<6; i++)
     
    209214
    210215        const Double_t sum = ip + op;
    211         fSigmabarInnerSector[i] = ip <=0 ? 0 :       iss/ip;
    212         fSigmabarOuterSector[i] = op <=0 ? 0 :       oss/op;
    213         fSigmabarSector[i]      = sum<=0 ? 0 : (iss+oss)/sum;
     216        fSigmabarInnerSector[i] = ip <=0 ? 0 :        sqrt(iss/ip);
     217        fSigmabarOuterSector[i] = op <=0 ? 0 :        sqrt(oss/op);
     218        fSigmabarSector[i]      = sum<=0 ? 0 : sqrt((iss+oss)/sum);
    214219    }
    215220
     
    217222    //Print(opt);
    218223
    219   return fSigmabar;
     224  return fSigmabarInner;
    220225}
    221226
  • trunk/MagicSoft/Mars/manalysis/MSigmabar.h

    r2798 r4584  
    1414{
    1515private:
    16     Float_t fSigmabar;          // Sigmabar ("average" RMS) of pedestal
     16    Float_t fSigmabar;          // Sigmabar ( sqrt(average pedestalRMS^2) )
    1717    Float_t fSigmabarInner;     // --only for inner pixels
    1818    Float_t fSigmabarOuter;     // --only for outer pixels 
  • trunk/MagicSoft/Mars/manalysis/MSigmabarCalc.cc

    r2798 r4584  
    3737//   MPedPhotCam
    3838//   MRawRunHeader
    39 //   MMcEvt  (FIXME: Must be replaced by a 'real-data' container)
     39//   MPointingPos
    4040//   MCerPhotEvt
    4141//
     
    5858#include "MSigmabarParam.h"
    5959
    60 #include "MMcEvt.hxx"
     60#include "MPointingPos.h"
    6161
    6262ClassImp(MSigmabarCalc);
     
    105105
    106106    // This is needed for determining min/max Theta
    107     fMcEvt = (MMcEvt*)pList->FindObject(AddSerialNumber("MMcEvt"));
    108     if (!fMcEvt)
     107    fPointPos = (MPointingPos*)pList->FindObject(AddSerialNumber("MPointingPos"));
     108    if (!fPointPos)
    109109    {
    110         *fLog << warn << "MMcEvt not found... aborting." << endl;
     110        *fLog << warn << "MPointingPos not found... aborting." << endl;
    111111        fThetaMin =  0;
    112112        fThetaMax = 90;
     
    148148    if (rc<fSigmabarMin) fSigmabarMin=rc;
    149149
    150     if (!fMcEvt)
     150    if (!fPointPos)
    151151        return kTRUE;
    152152
    153     const Double_t theta = fMcEvt->GetTelescopeTheta()*kRad2Deg;
     153    const Double_t theta = fPointPos->GetZd();
    154154
    155     if (theta>fSigmabarMax) fSigmabarMax=theta;
    156     if (theta<fSigmabarMax) fSigmabarMin=theta;
     155    if (theta>fThetaMax) fThetaMax=theta;
     156    if (theta<fThetaMin) fThetaMin=theta;
    157157
    158158    return kTRUE;
     
    176176void MSigmabarCalc::Reset()
    177177{
    178     if (!fMcEvt)
     178    if (!fPointPos)
    179179        return;
    180180
  • trunk/MagicSoft/Mars/manalysis/MSigmabarCalc.h

    r2798 r4584  
    1010#endif
    1111
    12 #ifndef MARS_MMcEvt
    13 #include "MMcEvt.hxx"
     12#ifndef MARS_MPointingPos
     13#include "MPointingPos.h"
    1414#endif
    1515
     
    3333{
    3434private:
    35     MMcEvt         *fMcEvt;
     35    MPointingPos   *fPointPos;
    3636    MCerPhotEvt    *fEvt;
    3737    MGeomCam       *fCam;
  • trunk/MagicSoft/Mars/mfilter/MFSelBasic.cc

    r3274 r4584  
    4646#include "MParList.h"
    4747
    48 #include "MMcEvt.hxx"
     48#include "MPointingPos.h"
    4949
    5050#include "MCerPhotEvt.h"
     
    104104    }
    105105
    106     fMcEvt = (MMcEvt*)pList->FindObject("MMcEvt");
    107     if (!fMcEvt)
    108     {
    109         *fLog << dbginf << "MMcEvt not found... aborting." << endl;
     106    fPointPos = (MPointingPos*)pList->FindObject("MPointingPos");
     107    if (!fPointPos)
     108    {
     109        *fLog << dbginf << "MPointingPos not found... aborting." << endl;
    110110        return kFALSE;
    111111    }
     
    146146Int_t MFSelBasic::Process()
    147147{
    148     const Double_t theta = kRad2Deg*fMcEvt->GetTelescopeTheta();
     148    const Double_t theta = fPointPos->GetZd();
    149149
    150150    fResult  = kFALSE;
  • trunk/MagicSoft/Mars/mfilter/MFSelBasic.h

    r2663 r4584  
    1414#endif
    1515
    16 class MMcEvt;
     16class MPointingPos;
    1717class MGeomCam;
    1818class MCerPhotEvt;
     
    2323{
    2424private:
    25     const MMcEvt        *fMcEvt;       
     25    const MPointingPos  *fPointPos;       
    2626    const MGeomCam      *fCam;      // Camera Geometry
    2727    const MCerPhotEvt   *fEvt;      // Cerenkov Photon Event
  • trunk/MagicSoft/Mars/mfilter/Makefile

    r3927 r4584  
    1313INCLUDES = -I. -I../mbase -I../mfbase -I../mraw -I../mmc -I../mdata \
    1414           -I../manalysis -I../mfileio  -I../mgeom -I../mimage      \
    15            -I../mhbase -I../mmain -I../mgui -I../msignal            \
     15           -I../mhbase -I../mmain -I../mgui -I../msignal -I../mpointing  \
    1616           -I../mpedestal
    1717
  • trunk/MagicSoft/Mars/mhist/MHSigmaTheta.cc

    r3339 r4584  
    2626//////////////////////////////////////////////////////////////////////////////
    2727//                                                                          //
    28 //  MHSigmaTheta (extension of Robert's MHSigmabarTheta)                    //
     28//  MHSigmaTheta                                                            //
    2929//                                                                          //
    30 //  calculates - the 2D-histogram   sigmabar vs. Theta, and                 //
     30//  calculates - the 2D-histogram   sigmabar vs. Theta (Inner), and         //
     31//             - the 2D-histogram   sigmabar vs. Theta (Outer)              //
    3132//             - the 3D-histogram   sigma, pixel no., Theta                 //
    3233//             - the 3D-histogram   (sigma^2-sigmabar^2), pixel no., Theta  //
     
    3940
    4041#include "MTime.h"
    41 #include "MMcEvt.hxx"
     42#include "MPointingPos.h"
    4243
    4344#include "MBinning.h"
     
    4647
    4748#include "MGeomCam.h"
     49#include "MBlindPixels.h"
    4850
    4951#include "MPedPhotCam.h"
     
    7072
    7173    fSigmaTheta.SetDirectory(NULL);
    72     fSigmaTheta.SetName("2D-ThetaSigmabar");
     74    fSigmaTheta.SetName("2D-ThetaSigmabar(Inner)");
    7375    fSigmaTheta.SetTitle("2D: \\bar{\\sigma}, \\Theta");
    7476    fSigmaTheta.SetXTitle("\\Theta [\\circ]");
    75     fSigmaTheta.SetYTitle("Sigmabar");
     77    fSigmaTheta.SetYTitle("Sigmabar(Inner) / SQRT(Area)");
     78
     79    fSigmaThetaOuter.SetDirectory(NULL);
     80    fSigmaThetaOuter.SetName("2D-ThetaSigmabar(Outer)");
     81    fSigmaThetaOuter.SetTitle("2D: \\bar{\\sigma}, \\Theta");
     82    fSigmaThetaOuter.SetXTitle("\\Theta [\\circ]");
     83    fSigmaThetaOuter.SetYTitle("Sigmabar(Outer) / SQRT(Area)");
    7684
    7785    fSigmaPixTheta.SetDirectory(NULL);
     
    8088    fSigmaPixTheta.SetXTitle("\\Theta [\\circ]");
    8189    fSigmaPixTheta.SetYTitle("Pixel Id");
    82     fSigmaPixTheta.SetZTitle("\\sigma");
     90    fSigmaPixTheta.SetZTitle("Sigma");
    8391
    8492    fDiffPixTheta.SetDirectory(NULL);
     
    8795    fDiffPixTheta.SetXTitle("\\Theta [\\circ]");
    8896    fDiffPixTheta.SetYTitle("Pixel Id");
    89     fDiffPixTheta.SetZTitle("{\\sigma}^{2}-\\bar{\\sigma}^{2}");
     97    fDiffPixTheta.SetZTitle("(Sigma2 - Sigmabar2)/Area");
    9098
    9199    // Set default binning
     
    102110    binspix.SetEdges(578, -0.5, 577.5);
    103111
    104     SetBinning(&fSigmaTheta,    &binst, &binsb);
    105     SetBinning(&fSigmaPixTheta, &binst, &binspix, &binsb);
    106     SetBinning(&fDiffPixTheta,  &binst, &binspix, &binsd);
     112    SetBinning(&fSigmaTheta,      &binst, &binsb);
     113    SetBinning(&fSigmaThetaOuter, &binst, &binsb);
     114    SetBinning(&fSigmaPixTheta,   &binst, &binspix, &binsb);
     115    SetBinning(&fDiffPixTheta,    &binst, &binspix, &binsd);
    107116}
    108117
     
    120129    }
    121130
    122     fMcEvt = (MMcEvt*)plist->FindObject("MMcEvt");
    123     if (!fMcEvt)
    124         *fLog << warn << "MMcEvt not found... aborting." << endl;
     131    fPointPos = (MPointingPos*)plist->FindObject("MPointingPos");
     132    if (!fPointPos)
     133        *fLog << warn << "MPointingPos not found... aborting." << endl;
    125134
    126135
     
    132141    }
    133142    fPed->InitSize(fCam->GetNumPixels());
     143
     144   
     145    fBlindPix = (MBlindPixels*)plist->FindObject("MBlindPixels");
     146    if (!fBlindPix)
     147    { 
     148       *fLog << err << "MBlindPixels not found... continue. " << endl;
     149    }
    134150
    135151
     
    177193    if (binssigma)
    178194    {
    179         SetBinning(&fSigmaTheta, binstheta, binssigma);
    180         SetBinning(&fSigmaPixTheta, binstheta, &binspix, binssigma);
     195        SetBinning(&fSigmaTheta,      binstheta, binssigma);
     196        SetBinning(&fSigmaThetaOuter, binstheta, binssigma);
     197        SetBinning(&fSigmaPixTheta,   binstheta, &binspix, binssigma);
    181198    }
    182199
     
    191208//  Fill the histograms
    192209//
     210//  ignore pixels if they are unused or blind
     211//
    193212Bool_t MHSigmaTheta::Fill(const MParContainer *par, const Stat_t w)
    194213{
    195     Double_t theta = fMcEvt ? fMcEvt->GetTelescopeTheta()*kRad2Deg : 0;
     214    Double_t theta = fPointPos->GetZd();
    196215    fSigmabar->Calc(*fCam, *fPed, *fEvt);
    197     Double_t mysig = fSigmabar->GetSigmabarInner();
    198 
    199     //*fLog << "theta, mysig = " << theta << ",  " << mysig << endl;
     216    Double_t mysig      = fSigmabar->GetSigmabarInner();
     217    Double_t mysigouter = fSigmabar->GetSigmabarOuter();
     218
     219    //*fLog << "theta, mysig, mysigouter = " << theta << ",  " << mysig
     220    //      << ",  " << mysigouter << endl;
    200221
    201222    fSigmaTheta.Fill(theta, mysig);
     223    fSigmaThetaOuter.Fill(theta, mysigouter);
    202224
    203225    const UInt_t npix = fEvt->GetNumPixels();
     
    205227    for (UInt_t i=0; i<npix; i++)
    206228    {
    207         MCerPhotPix cerpix = (*fEvt)[i];
     229        MCerPhotPix &cerpix = (*fEvt)[i];
     230        const Int_t id = cerpix.GetPixId();
     231
    208232        if (!cerpix.IsPixelUsed())
    209             continue;
    210 
    211         const Int_t id = cerpix.GetPixId();
     233        {
     234          //*fLog << all << "MHSigmaTheta::Fill; unused pixel found, id = "
     235          //      << id << endl;
     236          continue;
     237        }
     238
    212239        const MPedPhotPix &pix = (*fPed)[id];
     240
     241        if ( fBlindPix != NULL  &&  fBlindPix->IsBlind(id) )
     242        {
     243          // this should never occur, because blind pixels should have
     244          // been set unused by MBlindPixelsCalc2::UnMap()
     245          //*fLog << all << "MHSigmaTheta::Fill; blind pixel found which is used, id = "
     246          //      << id << "... go to next pixel." << endl;
     247          continue;
     248        }
    213249
    214250        // ratio is the area of pixel 0
     
    219255        fSigmaPixTheta.Fill(theta, (Double_t)id, sigma*sqrt(ratio));
    220256
    221         const Double_t diff = sigma*sigma*ratio - mysig*mysig;
     257        Double_t diff;
     258        if (ratio > 0.5)
     259        {
     260          // inner pixel
     261          diff = sigma*sigma*ratio - mysig*mysig;
     262        }
     263        else
     264        {
     265          // outer pixel
     266          diff = sigma*sigma*ratio - mysigouter*mysigouter;
     267        }
     268
    222269        fDiffPixTheta.Fill(theta, (Double_t)id, diff);
    223270    }
     
    262309    AppendPad("");
    263310
    264     pad->Divide(3, 2);
     311    pad->Divide(3, 3);
    265312
    266313    // draw the 2D histogram Sigmabar versus Theta
     
    283330    h->SetTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2} vs. \\Theta (all pixels)");
    284331    h->SetXTitle("\\Theta [\\circ]");
    285     h->SetYTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2}");
     332    h->SetYTitle("(Sigma2 - Sigmabar2) / Area");
    286333    h->Draw("box");
    287334    h->SetBit(kCanDelete);
     
    293340    h->SetTitle("\\sigma_{ped} vs. \\Theta (all pixels)");
    294341    h->SetXTitle("\\Theta [\\circ]");
    295     h->SetYTitle("\\sigma_{ped}");
     342    h->SetYTitle("Sigma");
    296343    h->Draw("box");
    297344    h->SetBit(kCanDelete);
     
    313360    h->SetTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2} vs. pixel Id (all  \\Theta)");
    314361    h->SetXTitle("Pixel Id");
    315     h->SetYTitle("\\sigma_{ped}^{2}-\\bar{\\sigma}_{ped}^{2}");
     362    h->SetYTitle("Sigma2 - sigmabar2) / Area");
    316363    h->Draw("box");
    317364    h->SetBit(kCanDelete);
     
    323370    h->SetTitle("\\sigma_{ped} vs. pixel Id (all  \\Theta)");
    324371    h->SetXTitle("Pixel Id");
    325     h->SetYTitle("\\sigma_{ped}");
     372    h->SetYTitle("Sigma");
    326373    h->Draw("box");
    327374    h->SetBit(kCanDelete);
     
    329376    pad->cd(4);
    330377    fSigmaTheta.Draw(opt);
     378
     379    pad->cd(7);
     380    fSigmaThetaOuter.Draw(opt);
    331381
    332382    //pad->cd(8);
  • trunk/MagicSoft/Mars/mhist/MHSigmaTheta.h

    r2798 r4584  
    1616class MGeomCam;
    1717class MCerPhotEvt;
    18 class MMcEvt;
     18class MPointingPos;
    1919class MPedPhotCam;
    2020class MSigmabar;
    2121class MParList;
     22class MBlindPixels;
    2223
    2324
     
    2930    MCerPhotEvt    *fEvt;        //!
    3031    MSigmabar      *fSigmabar;   //!
    31     MMcEvt         *fMcEvt;      //!
    32  
    33     TH2D fSigmaTheta;    // 2D-distribution sigmabar versus Theta;
    34                          // sigmabar is the average pedestasl sigma in an event
     32    MPointingPos   *fPointPos;   //!
     33    MBlindPixels   *fBlindPix;   //!
     34
     35                           // sigmabar is the average pedestal sigma 
     36    TH2D fSigmaTheta;      // 2D-distribution sigmabar versus Theta (Inner)
     37    TH2D fSigmaThetaOuter; // 2D-distribution sigmabar versus Theta (Outer)
     38
    3539    TH3D fSigmaPixTheta; // 3D-distr.:Theta, pixel, pedestal sigma
    3640    TH3D fDiffPixTheta;  // 3D-distr.:Theta, pixel, sigma^2-sigmabar^2
     
    4650    const TH2D *GetSigmaTheta() { return &fSigmaTheta; }
    4751    const TH2D *GetSigmaTheta() const { return &fSigmaTheta; }
     52
     53    const TH2D *GetSigmaThetaOuter() { return &fSigmaThetaOuter; }
     54    const TH2D *GetSigmaThetaOuter() const { return &fSigmaThetaOuter; }
    4855
    4956    const TH3D *GetSigmaPixTheta() { return &fSigmaPixTheta; }
Note: See TracChangeset for help on using the changeset viewer.