Ignore:
Timestamp:
01/24/04 01:52:51 (21 years ago)
Author:
gaug
Message:
*** empty log message ***
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/MagicSoft/Mars/mcalib/MCalibrationCalc.cc

    r2885 r2904  
    2727//   MCalibrationCalc
    2828//
    29 //   This is a task which calculates the number of photons from the FADC
    30 //   time slices. At the moment it integrates simply the FADC values.
    31 //
    32 //
    33 //  The class MCalibrationCam hold one entry of type MCalibrationPix for
    34 //  every pixel. It is filled in the following way:
    35 //  PreParocess: MalibrationCam::InitSize(577) is called which allocates
    36 //               memory in an TClonesArray of type MCalibrationPix and
    37 //               all pointers to NULL.
    38 //
    39 //  Process:     The NULL pointer is tested on every pixel via
    40 //               MalibrationCam::IsPixelUsed(npix).
    41 //
    42 //               In case, IsPixelUsed returns NULL,
    43 //               MalibrationCam::AddPixel(npix) is invoked which creates a
    44 //               new MCalibrationPix(npix) in the npix's entry
    45 //               of the TClonesArray.
    46 //
     29//   Task to calculate the calibration conversion factors from the FADC
     30//   time slices. The integrated time slices have to be delivered by an
     31//   MExtractedSignalCam. The pedestals by an MPedestalCam and possibly
     32//   arrival times from MArrivalTime
     33//
     34//   The output container MCalibrationCam holds one entry of type MCalibrationPix
     35//   for every pixel. It is filled in the following way:
     36//
     37//   ProProcess: Search for MPedestalCam, MExtractedSignalCam
     38//               Initialize MCalibrationCam
     39//               Initialize MArrivalTime if exists
     40//               Initialize pulser light wavelength
     41//               
     42//   ReInit:     MCalibrationCam::InitSize(NumPixels) is called which allocates
     43//               memory in a TClonesArray of type MCalibrationPix
     44//               Initialize number of used FADC slices
     45//               Optionally exclude pixels from calibration               
     46//
     47//   Process:    Optionally, a cut on cosmics can be performed
     48//               
    4749//               Every MCalibrationPix holds a histogram class,
    4850//               MHCalibrationPixel which itself hold histograms of type:
     
    5254//               HChargevsN(npix) (distribution of charges vs. event number.
    5355//
    54 // PostProcess:  All histograms HCharge(npix) are fitted to a Gaussian
    55 //               All histograms HTime(npix) are fitted to a Gaussian
    56 //               The histogram HBlindPixelCharge (blind pixel) is fitted to
    57 //               a single
    58 //                   PhE fit
    59 //               The histogram HBlindPixelTime (blind pixel) is fitted to a
    60 //               Gaussian
    61 //               The histograms of the PIN Diode are fitted to Gaussians
    62 //
    63 //               Fits can be excluded via the commands:
    64 //               MalibrationCam::SetSkipTimeFits()   (skip all time fits)
    65 //               MalibrationCam::SetSkipBlindPixelFits()  (skip all blind
    66 //               pixel fits)
    67 //               MalibrationCam::SetSkipPinDiodeFits()  (skip all PIN Diode
    68 //               fits)
     56//  PostProcess:  All histograms HCharge(npix) are fitted to a Gaussian
     57//                All histograms HTime(npix) are fitted to a Gaussian
     58//                The histogram HBlindPixelCharge (blind pixel) is fitted to
     59//                a single PhE fit
     60//
     61//                The histograms of the PIN Diode are fitted to Gaussians
     62//
     63//                Fits can be excluded via the commands:
     64//                MalibrationCam::SkipTimeFits()   (skip all time fits)
     65//                MalibrationCam::SkipBlindPixelFits()  (skip all blind
     66//                pixel fits)
     67//                MalibrationCam::SkipPinDiodeFits()  (skip all PIN Diode
     68//                fits)
    6969//
    7070//  Input Containers:
    7171//   MRawEvtData
     72//   MPedestalCam
     73//   MExtractedSignalCam
    7274//
    7375//  Output Containers:
     
    8082#include <fstream>
    8183
    82 // FXIME: This has to be removed!!!!
     84// FXIME: This has to be removed!!!! (YES, WHEN WE HAVE ACCESS TO THE DATABASE!!!!!)
    8385#include "MCalibrationConfig.h"
    8486
     
    106108#include "MCalibrationPINDiode.h"
    107109
     110#include "MArrivalTime.h"
     111
    108112ClassImp(MCalibrationCalc);
    109113
     
    116120MCalibrationCalc::MCalibrationCalc(const char *name, const char *title)
    117121    : fPedestals(NULL), fCalibrations(NULL), fSignals(NULL),
    118       fRawEvt(NULL), fRunHeader(NULL), fEvtTime(NULL),
    119       fEvents(0), fHistOverFlow(0), fCosmics(0),
     122      fRawEvt(NULL), fRunHeader(NULL), fArrivalTime(NULL), fEvtTime(NULL),
     123      fEvents(0), fCosmics(0),
    120124      fNumHiGainSamples(0), fNumLoGainSamples(0), fConversionHiLo(0.),
    121125      fNumExcludedPixels(0),
     
    131135    AddToBranchList("MRawEvtData.fLoGainFadcSamples");
    132136
    133     SETBIT(fFlags, kUseTimeFits);
     137    SETBIT(fFlags, kUseTimes);
    134138    SETBIT(fFlags, kUseBlindPixelFit);
    135139    SETBIT(fFlags, kUsePinDiodeFit);
     140    SETBIT(fFlags, kUseCosmicsRejection);
     141    SETBIT(fFlags, kUseQualityChecks);
    136142
    137143}
     
    158164//  - MHCalibrationBlindPixel
    159165//  - MCalibrationCam
     166//
     167// The following output containers are only searched, but not created
     168//
     169//  - MArrivaltime
    160170//  - MTime
    161171//
     
    186196      }
    187197
     198    fArrivalTime  = (MArrivalTime*)pList->FindObject("MArrivalTime");
     199
     200    if (!fArrivalTime)
     201      CLRBIT(fFlags,kUseTimes);
     202
     203    fEvtTime      = (MTime*)pList->FindObject("MTime");
    188204
    189205    switch (fColor)
     
    268284                                     fSignals->GetLastUsedSliceLoGain());
    269285       
     286        if (!TESTBIT(fFlags,kUseQualityChecks))
     287          pix.SetExcludeQualityCheck();
     288
    270289      }
    271290   
     
    340359{
    341360
    342     Int_t cosmicpix = 0;
    343 
    344     MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
    345     MCalibrationPINDiode &pindiode   = *(fCalibrations->GetPINDiode());
    346 
    347     MRawEvtPixelIter pixel(fRawEvt);
    348 
    349     //
    350     // Create a first loop to sort out the cosmics ...
    351     //
    352     // This is a very primitive check for the number of cosmicpixs
    353     // The cut will be applied in the fit, but for the blind pixel,
    354     // we need to remove this event
    355     //
    356     // FIXME: In the future need a much more sophisticated one!!!
    357     //
    358 
    359     while (pixel.Next())
    360       {
    361        
    362         const UInt_t pixid = pixel.GetPixelId();
    363        
    364         MExtractedSignalPix &sig =  (*fSignals)[pixid];
    365         MPedestalPix        &ped =  (*fPedestals)[pixid];
    366         Float_t pedrms           = ped.GetPedestalRms()*fSqrtHiGainSamples;
    367         Float_t sumhi            = sig.GetExtractedSignalHiGain();
     361  //
     362  // Initialize pointers to blind pixel, PIN Diode and individual pixels
     363  //
     364  MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
     365  MCalibrationPINDiode &pindiode   = *(fCalibrations->GetPINDiode());
     366 
     367  MRawEvtPixelIter pixel(fRawEvt);
     368 
     369  //
     370  // Perform cosmics cut
     371  //
     372  if (TESTBIT(fFlags,kUseCosmicsRejection))
     373    {
    368374       
    369         //
    370         // We consider a pixel as presumably due to cosmics
    371         // if its sum of FADC slices is lower than 3 pedestal RMS
    372         //
    373         if (sumhi < 3.*pedrms ) 
    374           cosmicpix++;
    375      }
    376 
    377     //
    378     // If the camera contains more than 230
    379     // (this is the number of outer pixels plus about 50 inner ones)
    380     // presumed pixels due to cosmics, then the event is discarted.
    381     // This procedure is more or less equivalent to keeping only events
    382     // with at least 350 pixels with high signals.
    383     //
    384     if (cosmicpix > 230.)
    385       {
    386         fCosmics++;
    387         return kCONTINUE;
    388       }
    389 
    390     pixel.Reset();
    391     fEvents++;
    392 
    393 
    394     //
    395     // Create a second loop to do fill the calibration histograms
    396     //
    397 
    398     while (pixel.Next())
    399       {
    400 
    401         const UInt_t pixid = pixel.GetPixelId();
    402        
    403         MCalibrationPix &pix = (*fCalibrations)[pixid];
    404 
    405         if (pix.IsExcluded())
    406           continue;
    407 
    408         MExtractedSignalPix &sig =  (*fSignals)[pixid];
    409        
    410         Float_t sumhi  = sig.GetExtractedSignalHiGain();
    411         Float_t sumlo  = sig.GetExtractedSignalLoGain();
    412         Float_t mtime  = sig.GetMeanArrivalTime();
    413 
    414 
    415         switch(pixid)
    416           {
    417            
    418           case gkCalibrationBlindPixelId:
    419 
    420             if (!blindpixel.FillCharge(sumhi))
    421               *fLog << warn <<
    422                 "Overflow or Underflow occurred filling Blind Pixel sum = " << sumhi << endl;
    423 
    424             if (!blindpixel.FillTime((int)mtime))
    425               *fLog << warn <<
    426                 "Overflow or Underflow occurred filling Blind Pixel time = " << mtime << endl;
    427            
    428             if (!blindpixel.FillRChargevsTime(sumhi,fEvents))
    429               *fLog << warn <<
    430                 "Overflow or Underflow occurred filling Blind Pixel eventnr = " << fEvents << endl;
    431             break;
    432            
    433           case gkCalibrationPINDiodeId:
    434             if (!pindiode.FillCharge(sumhi))
    435               *fLog << warn <<
    436                 "Overflow or Underflow occurred filling PINDiode: sum = " << sumhi << endl;
    437             if (!pindiode.FillTime((int)mtime))
    438               *fLog << warn <<
    439                 "Overflow or Underflow occurred filling PINDiode: time = " << mtime << endl;
    440             if (!pindiode.FillRChargevsTime(sumhi,fEvents))
    441               *fLog << warn <<
    442                 "Overflow or Underflow occurred filling PINDiode: eventnr = " << fEvents << endl;
    443             break;
    444 
    445           default:
    446 
    447             pix.SetChargesInGraph(sumhi,sumlo);
    448 
    449             if (!pix.FillRChargevsTimeLoGain(sumlo,fEvents))
    450               *fLog << warn << "Could not fill Lo Gain Charge vs. EvtNr of pixel: "
    451                     << pixid << " signal = " << sumlo  << " event Nr: " << fEvents << endl;
    452                
    453             if (!pix.FillRChargevsTimeHiGain(sumhi,fEvents))
    454               *fLog << warn << "Could not fill Hi Gain Charge vs. EvtNr of pixel: "
    455                     << pixid << " signal = " << sumhi  << " event Nr: " << fEvents << endl;
    456 
    457             if (sig.IsLoGainUsed())
    458               {
    459                
    460                 if (!pix.FillChargeLoGain(sumlo))
    461                   *fLog << warn << "Could not fill Lo Gain Charge of pixel: " << pixid
    462                         << " signal = " << sumlo << endl;
    463 
    464                 if (!pix.FillTimeLoGain((int)mtime))
    465                   *fLog << warn << "Could not fill Lo Gain Time of pixel: "
    466                         << pixid << " time = " << mtime << endl;
    467                
    468               }
    469             else
    470               {
    471                 if (!pix.FillChargeHiGain(sumhi))
    472                   *fLog << warn << "Could not fill Hi Gain Charge of pixel: " << pixid
    473                         << " signal = " << sumhi << endl;
    474                
    475                 if (!pix.FillTimeHiGain((int)mtime))
    476                   *fLog << warn << "Could not fill Hi Gain Time of pixel: "
    477                         << pixid << " time = " << mtime << endl;
    478                
    479               }
    480             break;
    481            
    482           } /* switch(pixid) */
    483 
    484       } /* while (pixel.Next()) */
    485 
    486     return kTRUE;
     375      Int_t cosmicpix = 0;
     376     
     377      //
     378      // Create a first loop to sort out the cosmics ...
     379      //
     380      // This is a very primitive check for the number of cosmicpixs
     381      // The cut will be applied in the fit, but for the blind pixel,
     382      // we need to remove this event
     383      //
     384      // FIXME: In the future need a much more sophisticated one!!!
     385      //
     386     
     387      while (pixel.Next())
     388        {
     389         
     390          const UInt_t pixid = pixel.GetPixelId();
     391         
     392          MExtractedSignalPix &sig =  (*fSignals)[pixid];
     393          MPedestalPix        &ped =  (*fPedestals)[pixid];
     394          Float_t pedrms           = ped.GetPedestalRms()*fSqrtHiGainSamples;
     395          Float_t sumhi            = sig.GetExtractedSignalHiGain();
     396         
     397          //
     398          // We consider a pixel as presumably due to cosmics
     399          // if its sum of FADC slices is lower than 3 pedestal RMS
     400          //
     401          if (sumhi < 3.*pedrms ) 
     402            cosmicpix++;
     403        }
     404     
     405      //
     406      // If the camera contains more than 230
     407      // (this is the number of outer pixels plus about 50 inner ones)
     408      // presumed pixels due to cosmics, then the event is discarted.
     409      // This procedure is more or less equivalent to keeping only events
     410      // with at least 350 pixels with high signals.
     411      //
     412      if (cosmicpix > 230.)
     413        {
     414          fCosmics++;
     415          return kCONTINUE;
     416        }
     417     
     418      pixel.Reset();
     419    }
     420 
     421  fEvents++;
     422 
     423  //
     424  // Create a (second) loop to do fill the calibration histograms
     425  //
     426 
     427  while (pixel.Next())
     428    {
     429     
     430      const UInt_t pixid = pixel.GetPixelId();
     431     
     432      MCalibrationPix &pix = (*fCalibrations)[pixid];
     433     
     434      if (pix.IsExcluded())
     435        continue;
     436     
     437      MExtractedSignalPix &sig =  (*fSignals)[pixid];
     438     
     439      const Float_t sumhi  = sig.GetExtractedSignalHiGain();
     440      const Float_t sumlo  = sig.GetExtractedSignalLoGain();
     441
     442      Double_t mtime = 0.;
     443
     444      if (TESTBIT(fFlags,kUseTimes))
     445        mtime = (*fArrivalTime)[pixid];
     446     
     447      switch(pixid)
     448        {
     449         
     450        case gkCalibrationBlindPixelId:
     451         
     452          if (!blindpixel.FillCharge(sumhi))
     453            *fLog << warn <<
     454              "Overflow or Underflow occurred filling Blind Pixel sum = " << sumhi << endl;
     455         
     456          if (TESTBIT(fFlags,kUseTimes))
     457            {
     458              if (!blindpixel.FillTime(mtime))
     459                *fLog << warn <<
     460                  "Overflow or Underflow occurred filling Blind Pixel time = " << mtime << endl;
     461            }
     462         
     463          if (!blindpixel.FillRChargevsTime(sumhi,fEvents))
     464            *fLog << warn <<
     465              "Overflow or Underflow occurred filling Blind Pixel eventnr = " << fEvents << endl;
     466          break;
     467         
     468        case gkCalibrationPINDiodeId:
     469
     470          if (!pindiode.FillCharge(sumhi))
     471            *fLog << warn <<
     472              "Overflow or Underflow occurred filling PINDiode: sum = " << sumhi << endl;
     473
     474          if (TESTBIT(fFlags,kUseTimes))
     475            {
     476              if (!pindiode.FillTime(mtime))
     477                *fLog << warn <<
     478                  "Overflow or Underflow occurred filling PINDiode: time = " << mtime << endl;
     479            }
     480         
     481          if (!pindiode.FillRChargevsTime(sumhi,fEvents))
     482            *fLog << warn <<
     483              "Overflow or Underflow occurred filling PINDiode: eventnr = " << fEvents << endl;
     484          break;
     485         
     486        default:
     487         
     488          pix.FillChargesInGraph(sumhi,sumlo);
     489
     490          if (!pix.FillRChargevsTimeLoGain(sumlo,fEvents))
     491            *fLog << warn << "Could not fill Lo Gain Charge vs. EvtNr of pixel: "
     492                  << pixid << " signal = " << sumlo  << " event Nr: " << fEvents << endl;
     493         
     494          if (!pix.FillRChargevsTimeHiGain(sumhi,fEvents))
     495            *fLog << warn << "Could not fill Hi Gain Charge vs. EvtNr of pixel: "
     496                  << pixid << " signal = " << sumhi  << " event Nr: " << fEvents << endl;
     497         
     498          if (sig.IsLoGainUsed())
     499            {
     500             
     501              if (!pix.FillChargeLoGain(sumlo))
     502                *fLog << warn << "Could not fill Lo Gain Charge of pixel: " << pixid
     503                      << " signal = " << sumlo << endl;
     504             
     505              if (TESTBIT(fFlags,kUseTimes))
     506                {
     507                  if (!pix.FillTimeLoGain(mtime))
     508                    *fLog << warn << "Could not fill Lo Gain Time of pixel: "
     509                          << pixid << " time = " << mtime << endl;
     510                }
     511            } /* if (sig.IsLoGainUsed()) */
     512          else
     513            {
     514              if (!pix.FillChargeHiGain(sumhi))
     515                *fLog << warn << "Could not fill Hi Gain Charge of pixel: " << pixid
     516                      << " signal = " << sumhi << endl;
     517             
     518              if (TESTBIT(fFlags,kUseTimes))
     519                {
     520                  if (!pix.FillTimeHiGain(mtime))
     521                    *fLog << warn << "Could not fill Hi Gain Time of pixel: "
     522                          << pixid << " time = " << mtime << endl;
     523                }
     524            } /* else (sig.IsLoGainUsed()) */
     525          break;
     526         
     527        } /* switch(pixid) */
     528     
     529    } /* while (pixel.Next()) */
     530 
     531  return kTRUE;
    487532}
    488533
     
    531576        }
    532577
    533       //blindpixel.DrawClone();
     578      blindpixel.DrawClone();
    534579    }
    535580  else
     
    573618      // Perform the Gauss fits to the arrival times
    574619      //
    575       if (TESTBIT(fFlags,kUseTimeFits))
     620      if (TESTBIT(fFlags,kUseTimes))
    576621        pix.FitTime();
    577622     
Note: See TracChangeset for help on using the changeset viewer.