Changeset 8927 for trunk/MagicSoft


Ignore:
Timestamp:
06/06/08 18:02:07 (16 years ago)
Author:
tbretz
Message:
*** empty log message ***
Location:
trunk/MagicSoft/Mars/datacenter/macros
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/datacenter/macros/fillcalib.C

    r7528 r8927  
    1919!   Author(s): Daniela Dorner, 08/2004 <mailto:dorner@astro.uni-wuerzburg.de>
    2020!
    21 !   Copyright: MAGIC Software Development, 2000-2006
     21!   Copyright: MAGIC Software Development, 2000-2008
    2222!
    2323!
     
    7070#include <TSQLRow.h>
    7171
    72 #include "MSQLServer.h"
     72#include "MSQLMagic.h"
    7373
    7474#include "MStatusArray.h"
     
    7979using namespace std;
    8080
    81 // --------------------------------------------------------------------------
    82 //
    83 // Checks whether an entry is already existing
    84 //
    85 Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, Int_t test)
    86 {
    87     TString query(Form("SELECT %s FROM %s WHERE %s='%d'", column, table, column, test));
    88     TSQLResult *res = serv.Query(query);
    89     if (!res)
    90         return kFALSE;
    91 
    92     TSQLRow *row;
    93 
    94     Bool_t rc = kFALSE;
    95     while ((row=res->Next()))
    96     {
    97         if ((*row)[0])
    98         {
    99             rc = kTRUE;
    100             break;
    101         }
    102     }
    103 
    104     delete res;
    105 
    106     return rc;
    107 }
    108 
    109 int Process(MSQLServer &serv, TString fname, Bool_t dummy)
     81int Process(MSQLMagic &serv, TString fname)
    11082{
    11183    //getting number of unsuitable, unreliable and isolated pixel
     
    222194    TString meanconvouter=Form("%6.3f", meanconvo);
    223195
    224 
    225196    //Getting sequ# from filename
    226197    TString sequence = fname(TRegexp("calib[0-9]+[.]root$"));
     
    233204    Int_t seq = atoi(sequence.Data()+5);
    234205
     206    //getting the ratio of calibration events used
     207    h = (TH1*)arr.FindObjectInCanvas("ArrTm;avg", "MHCamera", "ArrTm");
     208    if (!h)
     209    {
     210        cout << "WARNING - Could not find histogram ArrTime;avg." << endl;
     211        return 2;
     212    }
     213
     214    UInt_t nevts = h->GetEntries();
     215
     216    TString query;
     217    query = Form("SELECT SUM(fNumEvents) FROM RunData "
     218                 "LEFT JOIN RunType ON RunType.fRunTypeKEY=RunData.fRunTypeKEY "
     219                 "WHERE fSequenceFirst=%d AND RunType.fRunTypeName='Calibration'",
     220                 seq);
     221
     222    TSQLResult *res = serv.Query(query);
     223    if (!res)
     224    {
     225        cout << "ERROR - Query failed: " << query << endl;
     226        return 2;
     227    }
     228
     229    TSQLRow *row = res->Next();
     230    if (!row)
     231    {
     232        cout << "ERROR - Query failed: " << query << endl;
     233        return 2;
     234    }
     235
     236    Float_t ratiocalib = 100.*nevts/atof((*row)[0]);
     237
     238    TString ratiocal = Form("%.1f", ratiocalib);
     239
     240    delete res;
    235241
    236242    cout << "Sequence #" << seq << endl;
     
    243249    cout << "  Mean Conv inner:   " << meanconvinner << endl;
    244250    cout << "  Mean Conv outer:   " << meanconvouter << endl;
     251    cout << "  Ratio Calib Evts:  " << ratiocal << endl;
    245252
    246253    //inserting or updating the information in the database
    247     TString query;
    248     if (!ExistStr(serv, "fSequenceFirst", "Calibration", seq))
    249     {
    250         query = Form("INSERT Calibration SET"
    251                      " fSequenceFirst=%d,"
    252                      " fUnsuitableInner=%d, "
    253                      " fUnsuitableOuter=%d, "
    254                      " fUnreliableInner=%d, "
    255                      " fUnreliableOuter=%d, "
    256                      " fIsolatedInner=%d, "
    257                      " fIsolatedOuter=%d, "
    258                      " fIsolatedMaxCluster=%d, "
    259                      " fArrTimeMeanInner=%s, "
    260                      " fArrTimeRmsInner=%s, "
    261                      " fArrTimeMeanOuter=%s, "
    262                      " fArrTimeRmsOuter=%s, "
    263                      " fConvFactorInner=%s, "
    264                      " fConvFactorOuter=%s ",
    265                      seq, (int)unsin, (int)unsout, (int)unrin,
    266                      (int)unrout, (int)isoin, (int)isoout,
    267                      (int)clumax,
    268                      meaninner.Data(), rmsinner.Data(),
    269                      meanouter.Data(), rmsouter.Data(),
    270                      meanconvinner.Data(), meanconvouter.Data());
    271     }
    272     else
    273     {
    274         query = Form("UPDATE Calibration SET"
    275                      " fUnsuitableInner=%d, "
    276                      " fUnsuitableOuter=%d, "
    277                      " fUnreliableInner=%d, "
    278                      " fUnreliableOuter=%d, "
    279                      " fIsolatedInner=%d, "
    280                      " fIsolatedOuter=%d, "
    281                      " fIsolatedMaxCluster=%d, "
    282                      " fArrTimeMeanInner=%s, "
    283                      " fArrTimeRmsInner=%s, "
    284                      " fArrTimeMeanOuter=%s, "
    285                      " fArrTimeRmsOuter=%s, "
    286                      " fConvFactorInner=%s, "
    287                      " fConvFactorOuter=%s "
    288                      " WHERE fSequenceFirst=%d ",
    289                      (int)unsin, (int)unsout, (int)unrin,(int)unrout,
    290                      (int)isoin, (int)isoout, (int)clumax,
    291                      meaninner.Data(), rmsinner.Data(),
    292                      meanouter.Data(), rmsouter.Data(),
    293                      meanconvinner.Data(), meanconvouter.Data(),
    294                      seq);
    295     }
    296 
    297     if (dummy)
    298         return 1;
    299 
    300     TSQLResult *res = serv.Query(query);
    301     if (!res)
    302     {
    303         cout << "ERROR - Query failed: " << query << endl;
    304         return 2;
    305     }
    306     delete res;
    307 
    308     return 1;
     254    TString vars =
     255        Form(" fSequenceFirst=%d,"
     256             " fUnsuitableInner=%d, "
     257             " fUnsuitableOuter=%d, "
     258             " fUnreliableInner=%d, "
     259             " fUnreliableOuter=%d, "
     260             " fIsolatedInner=%d, "
     261             " fIsolatedOuter=%d, "
     262             " fIsolatedMaxCluster=%d, "
     263             " fArrTimeMeanInner=%s, "
     264             " fArrTimeRmsInner=%s, "
     265             " fArrTimeMeanOuter=%s, "
     266             " fArrTimeRmsOuter=%s, "
     267             " fConvFactorInner=%s, "
     268             " fConvFactorOuter=%s, "
     269             " fRatioCalEvents=%s ",
     270             seq, (int)unsin, (int)unsout, (int)unrin,
     271             (int)unrout, (int)isoin, (int)isoout, (int)clumax,
     272             meaninner.Data(), rmsinner.Data(),
     273             meanouter.Data(), rmsouter.Data(),
     274             meanconvinner.Data(), meanconvouter.Data(),
     275             ratiocal.Data());
     276
     277    return serv.InsertUpdate("Calibration", "fSequenceFirst",
     278                             Form("%d", seq), vars.Data()) ? 1 : 2;
    309279}
    310280
     
    313283    TEnv env("sql.rc");
    314284
    315     MSQLServer serv(env);
     285    MSQLMagic serv(env);
    316286    if (!serv.IsConnected())
    317287    {
     
    327297    cout << endl;
    328298
    329     return Process(serv, fname, dummy);
     299    serv.SetIsDummy(dummy);
     300
     301    return Process(serv, fname);
    330302}
  • trunk/MagicSoft/Mars/datacenter/macros/fillsignal.C

    r8489 r8927  
    1919!   Author(s): Daniela Dorner, 04/2005 <mailto:dorner@astro.uni-wuerzburg.de>
    2020!
    21 !   Copyright: MAGIC Software Development, 2000-2006
     21!   Copyright: MAGIC Software Development, 2000-2008
    2222!
    2323!
     
    6666#include <TSQLResult.h>
    6767
    68 #include "MSQLServer.h"
     68#include "MSQLMagic.h"
    6969
    7070#include "MStatusArray.h"
     
    7777using namespace std;
    7878
    79 int Process(MSQLServer &serv, TString fname, Bool_t dummy)
     79int Process(MSQLMagic &serv, TString fname)
    8080{
    8181    TFile file(fname, "READ");
     
    331331    // the macro fillcalib.C in the script fillcallisto
    332332    // and so the table Calibration is always updated
    333     TString query = Form("UPDATE Calibration SET "
    334                          " fMeanPedRmsInner=%s,   fMeanPedRmsOuter=%s,  "
    335                          " fMeanSignalInner=%s,   fMeanSignalOuter=%s,  "
    336                          " fPulsePosMean=%s,      fPulsePosRms=%s,      "
    337                          " fPulsePosCheckMean=%s, fPulsePosCheckRms=%s, "
    338                          //" fPulsePosHiMean=%s,    fPulsePosHiRms=%s,    "
    339                          //" fPulsePosLoMean=%s,    fPulsePosLoRms=%s,    "
    340                          " fPulsePosOffMed=%s,    fPulsePosOffDev=%s,   "
    341                          " fHiLoGainRatioMed=%s,  fHiLoGainRatioDev=%s,  "
    342                          " fUnsuitable50=%d,  fUnsuitable01=%d, "
    343                          " fUnsuitableMax=%s, fDeadMax=%s "
    344                          " WHERE fSequenceFirst='%d' ",
     333    TString vars = Form(" fMeanPedRmsInner=%s,   fMeanPedRmsOuter=%s,  "
     334                        " fMeanSignalInner=%s,   fMeanSignalOuter=%s,  "
     335                        " fPulsePosMean=%s,      fPulsePosRms=%s,      "
     336                        " fPulsePosCheckMean=%s, fPulsePosCheckRms=%s, "
     337                        //" fPulsePosHiMean=%s,    fPulsePosHiRms=%s,    "
     338                        //" fPulsePosLoMean=%s,    fPulsePosLoRms=%s,    "
     339                        " fPulsePosOffMed=%s,    fPulsePosOffDev=%s,   "
     340                        " fHiLoGainRatioMed=%s,  fHiLoGainRatioDev=%s, "
     341                        " fUnsuitable50=%d,      fUnsuitable01=%d, "
     342                        " fUnsuitableMax=%s,     fDeadMax=%s "
    345343                         meanrmsinner.Data(),  meanrmsouter.Data(),
    346344                         meansiginner.Data(),  meansigouter.Data(),
     
    349347                         //meanpulhi.Data(),     rmspulhi.Data(),
    350348                         //meanpullo.Data(),     rmspullo.Data(),
    351                          medpuloff.Data(),    devpuloff.Data(),
    352                          medhilocal.Data(),   devhilocal.Data(),
    353                          unsuitable50, unsuitable01,
    354                          unsuitablemax.Data(), deadmax.Data(),
    355                          seq);
    356 
    357     if (dummy)
    358         return 1;
    359 
    360     TSQLResult *res = serv.Query(query);
    361     if (!res)
    362     {
    363         cout << "ERROR - Query failed: " << query << endl;
    364         return 2;
    365     }
    366     delete res;
    367     return 1;
     349                         medpuloff.Data(),     devpuloff.Data(),
     350                         medhilocal.Data(),    devhilocal.Data(),
     351                         unsuitable50,         unsuitable01,
     352                         unsuitablemax.Data(), deadmax.Data());
     353
     354    return serv.Update("Calibration", vars, Form("fSequenceFirst=%d", seq), vars);
    368355}
    369356
     
    372359    TEnv env("sql.rc");
    373360
    374     MSQLServer serv(env);
     361    MSQLMagic serv(env);
    375362    if (!serv.IsConnected())
    376363    {
     
    386373    cout << endl;
    387374
     375    serv.SetIsDummy(dummy);
     376
    388377    //process file
    389     return Process(serv, fname, dummy);
     378    return Process(serv, fname);
    390379}
  • trunk/MagicSoft/Mars/datacenter/macros/fillstar.C

    r8925 r8927  
    7070#include <TSQLRow.h>
    7171
    72 #include "MSQLServer.h"
     72#include "MSQLMagic.h"
    7373
    7474#include "MHCamera.h"
     
    8080using namespace std;
    8181
    82 // --------------------------------------------------------------------------
    83 //
    84 // Checks whether an entry is already existing
    85 //
    86 Bool_t ExistStr(MSQLServer &serv, const char *column, const char *table, Int_t test)
    87 {
    88     TString query(Form("SELECT %s FROM %s WHERE %s='%d'", column, table, column, test));
    89     TSQLResult *res = serv.Query(query);
    90     if (!res)
    91         return kFALSE;
    92 
    93     TSQLRow *row;
    94 
    95     Bool_t rc = kFALSE;
    96     while ((row=res->Next()))
    97     {
    98         if ((*row)[0])
    99         {
    100             rc = kTRUE;
    101             break;
    102         }
    103     }
    104 
    105     delete res;
    106 
    107     return rc;
    108 }
    109 
    110 
    111 int Process(MSQLServer &serv, TString fname, Bool_t dummy)
     82int Process(MSQLMagic &serv, TString fname)
    11283{
    11384    TFile file(fname, "READ");
     
    310281    cout << "  Skybrightness            " << skybrightnessmed << " +/- " << skybrightnessrms  << endl;
    311282
    312     TString query;
    313     if (!ExistStr(serv, "fSequenceFirst", "Star", seq))
    314     {
    315         query = Form("INSERT Star SET"
    316                      " fSequenceFirst=%d,"
    317                      " fMeanNumberIslands=%s, "
    318                      " fRatio=%s, "
    319                      " fMuonNumber=%d, "
    320                      " fEffOnTime=%d, "
    321                      " fMuonRate=%s, "
    322                      " fPSF=%s, "
    323                      " fDataRate=%d, "
    324                      " fSparkRate=%s, "
    325                      " fMaxHumidity=%s ,"
    326                      " fAvgTemperature=%s ,"
    327                      " fAvgWindSpeed=%s ,"
    328                      " fNumStarsMed=%s ,"
    329                      " fNumStarsRMS=%s ,"
    330                      " fNumStarsCorMed=%s ,"
    331                      " fNumStarsCorRMS=%s ,"
    332                      " fBrightnessMed=%s ,"
    333                      " fBrightnessRMS=%s ,"
    334                      " fInhomogeneity=%s ",
    335                      seq, islands.Data(), ratio.Data(),
    336                      num, effontime,
    337                      muonrate.Data(), PSF.Data(),
    338                      datarate, sparkrate.Data(), maxhum.Data(),
    339                      avgtemp.Data(), avgwind.Data(),
    340                      numstarsmed.Data(), numstarsrms.Data(),
    341                      numcorsmed.Data(), numcorsrms.Data(),
    342                      skybrightnessmed.Data(), skybrightnessrms.Data(),
    343                      inhomogen.Data());
    344     }
    345     else
    346     {
    347         query = Form("UPDATE Star SET"
    348                      " fMeanNumberIslands=%s, "
    349                      " fRatio=%s, "
    350                      " fMuonNumber=%d, "
    351                      " fEffOnTime=%d, "
    352                      " fMuonRate=%s, "
    353                      " fPSF=%s, "
    354                      " fDataRate=%d, "
    355                      " fSparkRate=%s, "
    356                      " fMaxHumidity=%s, "
    357                      " fNumStarsMed=%s ,"
    358                      " fNumStarsRMS=%s ,"
    359                      " fNumStarsCorMed=%s ,"
    360                      " fNumStarsCorRMS=%s ,"
    361                      " fBrightnessMed=%s ,"
    362                      " fBrightnessRMS=%s ,"
    363                      " fInhomogeneity=%s "
    364                      " WHERE fSequenceFirst=%d ",
    365                      islands.Data(), ratio.Data(),
    366                      num, effontime,
    367                      muonrate.Data(), PSF.Data(),
    368                      datarate, sparkrate.Data(), maxhum.Data(),
    369                      numstarsmed.Data(), numstarsrms.Data(),
    370                      numcorsmed.Data(), numcorsrms.Data(),
    371                      skybrightnessmed.Data(), skybrightnessrms.Data(),
    372                      inhomogen.Data(), seq);
    373     }
    374 
    375 //    cout << "Q: " << query << endl;
    376 
    377     if (dummy)
    378         return 1;
    379 
    380     TSQLResult *res = serv.Query(query);
    381     if (!res)
    382     {
    383         cout << "ERROR - Query failed: " << query << endl;
    384         return 2;
    385     }
    386     delete res;
    387 
    388     return 1;
     283    TString vars = Form(" fMeanNumberIslands=%s,"
     284                        " fRatio=%s,"
     285                        " fMuonNumber=%d,"
     286                        " fEffOnTime=%d,"
     287                        " fMuonRate=%s,"
     288                        " fPSF=%s,"
     289                        " fDataRate=%d,"
     290                        " fSparkRate=%s,"
     291                        " fMaxHumidity=%s,"
     292                        " fAvgTemperature=%s,"
     293                        " fAvgWindSpeed=%s,"
     294                        " fNumStarsMed=%s,"
     295                        " fNumStarsRMS=%s,"
     296                        " fNumStarsCorMed=%s,"
     297                        " fNumStarsCorRMS=%s,"
     298                        " fBrightnessMed=%s,"
     299                        " fBrightnessRMS=%s,"
     300                        " fInhomogeneity=%s ",
     301                        islands.Data(), ratio.Data(),
     302                        num, effontime,
     303                        muonrate.Data(), PSF.Data(),
     304                        datarate, sparkrate.Data(), maxhum.Data(),
     305                        avgtemp.Data(), avgwind.Data(),
     306                        numstarsmed.Data(), numstarsrms.Data(),
     307                        numcorsmed.Data(), numcorsrms.Data(),
     308                        skybrightnessmed.Data(), skybrightnessrms.Data(),
     309                        inhomogen.Data());
     310
     311    return serv.InsertUpdate("Star", "fSequenceFirst", Form("%d", seq), vars);
    389312}
    390313
     
    393316    TEnv env("sql.rc");
    394317
    395     MSQLServer serv(env);
     318    MSQLMagic serv(env);
    396319    if (!serv.IsConnected())
    397320    {
     
    401324
    402325    cout << "fillstar" << endl;
    403     cout << "---------" << endl;
     326    cout << "--------" << endl;
    404327    cout << endl;
    405328    cout << "Connected to " << serv.GetName() << endl;
     
    407330    cout << endl;
    408331
    409     return Process(serv, fname, dummy);
     332    serv.SetIsDummy(dummy);
     333
     334    return Process(serv, fname);
    410335}
  • trunk/MagicSoft/Mars/datacenter/macros/plotstat.C

    r8207 r8927  
    11/* ======================================================================== *\
    2 ! $Name: not supported by cvs2svn $:$Id: plotstat.C,v 1.4 2006-11-02 17:44:08 tbretz Exp $
     2! $Name: not supported by cvs2svn $:$Id: plotstat.C,v 1.5 2008-06-06 17:02:07 tbretz Exp $
    33! --------------------------------------------------------------------------
    44!
     
    2121!   Author(s): Daniela Dorner, 02/2006 <mailto:dorner@astro.uni-wuerzburg.de>
    2222!
    23 !   Copyright: MAGIC Software Development, 2000-2006
     23!   Copyright: MAGIC Software Development, 2000-2008
    2424!
    2525!
     
    4747#include <iomanip>
    4848
    49 #include <TH1.h>
     49#include <TH2.h>
    5050#include <TEnv.h>
    5151#include <TPad.h>
     
    6767using namespace std;
    6868
     69TString GetFullQuery(TString query, TString from="", TString to="")
     70{
     71    if (from.IsNull())
     72        return query;
     73
     74    if (!query.Contains("where", TString::kIgnoreCase))
     75        query += " where ";
     76    else
     77        query += " and ";
     78
     79    query += " fRunStart>'";
     80    query += from;
     81    query += "' and fRunStart<'";
     82    query += to;
     83    query += "'";
     84
     85    return query;
     86}
     87
    6988Double_t GetTime(MSQLServer &serv, TString query, TString from="", TString to="")
    7089{
    71     if (!from.IsNull())
    72     {
    73         if (!query.Contains("where", TString::kIgnoreCase))
    74             query += " where ";
    75         else
    76             query += " and ";
    77 
    78         query += " fRunStart>'";
    79         query += from;
    80         query += "' and fRunStart<'";
    81         query += to;
    82         query += "'";
    83     }
     90    query = GetFullQuery(query, from, to);
    8491
    8592    TSQLResult *res = serv.Query(query);
     
    100107    const char *time = (*row)[0];
    101108
     109    const Double_t rc = time ? atof(time) : 0;
     110
    102111    delete res;
    103     return time ? atof(time) : 0;
     112    return rc<0 || rc>200 ? 0 : rc;
     113}
     114
     115TArrayD GetObsDist(MSQLServer &serv, TString from="", TString to="")
     116{
     117    // 8: Sequenced RunTime per source and night
     118    //query[8]  = "select SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart)))/3600, ";
     119    //query[8] += "DATE_FORMAT(ADDDATE(fRunStart,Interval 12 hour), '%Y-%m-%d') as Start,";
     120    //query[8] += "from RunData where fRunTypeKEY=2 and fExcludedFDAKEY=1 group by Start, fSourceKEY";
     121
     122    TString query;
     123
     124    query  = "SELECT SUM(fRunTime)/3600, ";
     125    query += "DATE_FORMAT(ADDDATE(fRunStart, INTERVAL 12 hour), '%Y-%m-%d') AS Start ";
     126    query += "FROM Sequences ";
     127
     128    query  = GetFullQuery(query, from, to);
     129    query += " GROUP BY Start, fSourceKEY";
     130
     131
     132    TSQLResult *res = serv.Query(query);
     133    if (!res)
     134    {
     135        cout << "ERROR - Query failed: " << query << endl;
     136        return -1;
     137    }
     138
     139    TSQLRow *row = 0;
     140
     141    TArrayD arr;
     142
     143    while ((row=res->Next()))
     144    {
     145        const char *time = (*row)[0];
     146
     147        const Double_t rc = time ? atof(time) : 0;
     148
     149        if (rc>0 && rc<200)
     150        {
     151            arr.Set(arr.GetSize()+1);
     152            arr[arr.GetSize()-1] = rc;
     153        }
     154    }
     155
     156    delete res;
     157
     158    return arr;
    104159}
    105160
     
    265320
    266321    // 0: All data for which are files available
    267     query[0]  = "select ";
    268     query[0] += "SUM(if(TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)<0, ";
    269     query[0] += "TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)+24*60*60, ";
    270     query[0] += "TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)))/3600 ";
     322    query[0]  = "select SUM(TIME_TO_SEC(TIMEDIFF(fRunStop, fRunStart)))/3600 ";
    271323    query[0] += "from RunData left join RunProcessStatus on RunData.fRunNumber=RunProcessStatus.fRunNumber ";
    272324    query[0] += "where fRunTypeKey=2 and ";
     
    274326
    275327    // 1: All data
    276     query[1]  = "select ";
    277     query[1] += "SUM(if(TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)<0, ";
    278     query[1] += "TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)+24*60*60, ";
    279     query[1] += "TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)))/3600 ";
     328    query[1]  = "select SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart)))/3600 ";
    280329    query[1] += "from RunData where fRunTypeKEY=2";
    281330
    282331    // 2: All data which is not excluded
    283     query[2]  = "select ";
    284     query[2] += "SUM(if(TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)<0, ";
    285     query[2] += "TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)+24*60*60, ";
    286     query[2] += "TIME_TO_SEC(fRunStop)-TIME_TO_SEC(fRunStart)))/3600 ";
     332    query[2]  = "select SUM(TIME_TO_SEC(TIMEDIFF(fRunStop,fRunStart)))/3600 ";
    287333    query[2] += "from RunData where fRunTypeKEY=2 and fExcludedFDAKEY=1";
    288334
     
    327373
    328374    TH1F h[8];
    329 
    330     MBinning bins(last-first+1, first-0.5, last+0.5);
     375    TH2F h8;
     376
     377    MBinning binsp(last-first+1, first-0.5, last+0.5);
     378    MBinning binst(4*7, 0, 7);
    331379    for (int i=0; i<8; i++)
    332380    {
    333         bins.Apply(h[i]);
     381        binsp.Apply(h[i]);
    334382        h[i].SetName(Form("H%d", i));
    335383        h[i].SetDirectory(0);
    336384    }
     385
     386    MH::SetBinning(&h8, &binsp, &binst);
     387    h8.SetNameTitle("ObsTime", "Distribution of observation time per exposure");
     388    h8.SetXTitle("Obs. time per exposure [h]");
     389    h8.SetYTitle("Counts");
     390    h8.SetDirectory(0);
    337391
    338392    Int_t period = 0;
     
    352406                for (int i=0; i<8; i++)
    353407                    h[i].Fill(period-1, GetTime(serv, query[i], a, b));
     408
     409                TArrayD arr(GetObsDist(serv, a, b));
     410
     411                for (int i=0; i<arr.GetSize(); i++)
     412                    h8.Fill(period-1, arr[i]);
    354413            }
    355414
     
    369428    h[4].Add(&h[5]);
    370429    h[6].Add(&h[7]);
     430
     431    // --------------------------------------------
     432
     433    TCanvas &c0 = d.AddTab("ObsDist");
     434    c0.SetFillColor(kWhite);
     435
     436    gPad->SetBorderMode(0);
     437    gPad->SetFrameBorderMode(0);
     438    gPad->SetFillColor(kWhite);
     439    gPad->SetRightMargin(0.01);
     440    //gPad->SetTopMargin(0.02);
     441    //gPad->SetLeftMargin(0.09);
     442    //gPad->SetBottomMargin(0.12);
     443    gPad->SetGridx();
     444    gPad->SetGridy();
     445    gPad->SetLogy();
     446
     447    TH1 * p = h8.ProjectionY();
     448
     449    p->SetDirectory(0);
     450    p->SetBit(kCanDelete);
     451    p->Draw();
     452
     453    // --------------------------------------------
    371454
    372455    TCanvas &c1 = d.AddTab("Hist");
     
    441524    DrawCake(h);
    442525
     526    // --------------------------------------------
     527
    443528    TCanvas &cx = d.AddTab("All");
    444529    cx.SetBorderMode(0);
     
    451536    for (int i=0; i<h[0].GetNbinsX(); i++)
    452537    {
    453         TCanvas &c = d.AddTab(Form("P%d", TMath::Nint(h[0].GetBinCenter(i+1))));
    454 
     538        const Int_t num = TMath::Nint(h[0].GetBinCenter(i+1));
     539
     540        TCanvas &c = d.AddTab(Form("P%d", num));
    455541        c.SetBorderMode(0);
    456542        c.SetFrameBorderMode(0);
    457         c.SetPad(0.25, 0, 0.75, 1.0);
    458543        c.SetFillColor(kWhite);
     544
     545        c.cd();
     546
     547        TPad *pad1 = new TPad(Form("Pad%da", num), "", 0.05, 0, 0.55, 1);
     548        pad1->SetBorderMode(0);
     549        pad1->SetFrameBorderMode(0);
     550        pad1->SetFillColor(kWhite);
     551        pad1->SetBit(kCanDelete);
     552        pad1->Draw();
     553        pad1->cd();
    459554
    460555        DrawCake(h, i+1, i+1);
     
    465560            DrawCake(h, i+1, i+1);
    466561        }
     562
     563        c.cd();
     564
     565        TPad *pad2 = new TPad(Form("Pad%db", num), "", 0.6, 0.02, 1, 0.48);
     566        pad2->SetBorderMode(0);
     567        pad2->SetFrameBorderMode(0);
     568        pad2->SetFillColor(kWhite);
     569        pad2->SetBit(kCanDelete);
     570        pad2->SetGridx();
     571        pad2->SetGridy();
     572        pad2->SetRightMargin(0.01);
     573        pad2->Draw();
     574        pad2->cd();
     575
     576        TH1 * p = h8.ProjectionY(Form("Obs%d", num), i+1, i+1);
     577
     578        p->Rebin(2);
     579        p->SetBit(TH1::kNoStats);
     580        p->SetTitle("");
     581        p->SetXTitle("Obs. time per exposure [h]");
     582        p->SetYTitle("Counts");
     583        p->SetDirectory(0);
     584        p->SetBit(kCanDelete);
     585        p->Draw();
     586
     587        /*
     588        c.cd();
     589
     590        TPaveText *pave = new TPaveText(0.6, 0.52, 0.98, 0.98);
     591        pave->SetBorderSize(1);
     592        pave->AddText(Form("Period: %d", num))->SetTextAlign(22);
     593        pave->AddSeperator();
     594        pave->AddText(Form("Start: %s", num));
     595        pave->AddText(Form("End:   %s", num));
     596        pave->SetBit(kCanDelete);
     597        pave->Draw();
     598        */
    467599    }
    468600
Note: See TracChangeset for help on using the changeset viewer.