Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

SigMappedCalibrator.cxx

Go to the documentation of this file.
00001 
00002 // $Id: SigMappedCalibrator.cxx,v 1.1 2004/07/26 16:52:20 tagg Exp $
00003 //
00004 // Prototype PE gain Calibrator class
00005 //
00006 // rjn@hep.ucl.ac.uk
00008 #include "MessageService/MsgService.h"
00009 #include "CandDigit/CandDigitHandle.h"
00010 #include "Calibrator/SigMappedCalibrator.h"
00011 #include "Plex/PlexSEIdAltL.h"
00012 #include "Plex/PlexStripEndId.h"
00013 #include "DatabaseInterface/DbiValidityRec.h"
00014 #include "Validity/VldRange.h"
00015 
00016 CVSID("$Id: SigMappedCalibrator.cxx,v 1.1 2004/07/26 16:52:20 tagg Exp $");
00017 SigMappedCalibrator::SigMappedCalibrator(Int_t calMode)
00018    : fMuonPtr(), fMapperFitsPtr(), fMapperDataPtr(), fCalMode(calMode)
00019 {
00020    MSG("Calibrator",Msg::kVerbose) << "SigMappedCalibrator::SigMappedCalibrator" 
00021                                    << endl;
00022 }
00023 
00024 SigMappedCalibrator::SigMappedCalibrator(const VldContext vc, Int_t calMode)
00025    : fMuonPtr(vc),fMapperFitsPtr(vc),fMapperDataPtr(vc),fCalMode(calMode)
00026 {
00027    //assert(fMuonPtr.GetNumRows()!=0);
00028 
00029   if(fCalMode>0){
00030     if(fMuonPtr.GetNumRows()==0) {
00031       MSG("MuonCalibrator",Msg::kWarning) 
00032         << "No rows in database table with validity context "
00033         << vc.AsString() << " will assert() here" << ".\n";
00034       MSG("MuonCalibrator",Msg::kWarning)
00035         << "TimeStamp " << vc.GetTimeStamp() << "\n";
00036       MSG("MuonCalibrator",Msg::kWarning)
00037         << "SimFlag " << (int)vc.GetSimFlag() << "\n";
00038       MSG("MuonCalibrator",Msg::kWarning)
00039         << "Detector " << (int)vc.GetDetector() << "\n";
00040       
00041       
00042       if ( ! ((int)vc.GetDetector() & 127) ) {
00043         MSG("MuonCalibrator",Msg::kWarning)
00044           << "Detector " << (int)vc.GetDetector() 
00045           << " is the problem.\n";
00046       }
00047       if ( ! ((int)vc.GetSimFlag()  & 127) ) {
00048         MSG("MuonCalibrator",Msg::kWarning)
00049           << "Simflag " << (int)vc.GetSimFlag() 
00050           << " is the problem.\n";
00051       }
00052       
00053       
00054       const DbiValidityRec* fred = fMuonPtr.GetValidityRec();
00055       const VldRange freda=fred->GetVldRange();
00056       MSG("MuonCalibrator",Msg::kWarning) 
00057         << "bugger "
00058         << freda.AsString() << ".\n";
00059     }
00060     if(fMapperFitsPtr.GetNumRows()==0) {
00061       MSG("MapperFitsCalibrator",Msg::kWarning) 
00062         << "No rows in database table with validity context "
00063         << vc.AsString() << " will assert() here" << ".\n";
00064       MSG("MapperFitsCalibrator",Msg::kWarning)
00065         << "TimeStamp " << vc.GetTimeStamp() << "\n";
00066       MSG("MapperFitsCalibrator",Msg::kWarning)
00067         << "SimFlag " << (int)vc.GetSimFlag() << "\n";
00068       MSG("MapperFitsCalibrator",Msg::kWarning)
00069         << "Detector " << (int)vc.GetDetector() << "\n";
00070       
00071       
00072       if ( ! ((int)vc.GetDetector() & 127) ) {
00073         MSG("MapperFitsCalibrator",Msg::kWarning)
00074           << "Detector " << (int)vc.GetDetector() 
00075           << " is the problem.\n";
00076       }
00077       if ( ! ((int)vc.GetSimFlag()  & 127) ) {
00078         MSG("MapperFitsCalibrator",Msg::kWarning)
00079           << "Simflag " << (int)vc.GetSimFlag() 
00080           << " is the problem.\n";
00081       }
00082       
00083       
00084       const DbiValidityRec* fred = fMapperFitsPtr.GetValidityRec();
00085       const VldRange freda=fred->GetVldRange();
00086       MSG("MapperFitsCalibrator",Msg::kWarning) 
00087         << "bugger "
00088         << freda.AsString() << ".\n";
00089     }
00090   }
00091   else{
00092       MSG("MapperFitsCalibrator",Msg::kInfo) << "No MapperFits Calibration table loaded.\n";
00093   }
00094 }
00095 //......................................................................
00096 
00097 Float_t SigMappedCalibrator::Calibrate(Float_t siglin, Float_t y,
00098                                          PlexStripEndId seid) const
00099 {
00100 //======================================================================
00101 // Purpose: Calibrate method
00102 //======================================================================
00103    return ApplyCalib(siglin,y, seid);
00104    
00105 }
00106 
00107 //......................................................................
00108 
00109 Float_t  SigMappedCalibrator::ApplyCalib(Float_t siglin, Float_t Y,
00110                                            PlexStripEndId seid) const
00111 {
00112 //======================================================================
00113 // Purpose: The actual numerical calibration.
00114   // depending upon mode variable, uses mapper fit, muon fit, or
00115   // 'raw' mapper data
00116 //======================================================================
00117 
00118   Float_t MapCorrected;
00119   Float_t MuonCorrected;
00120   Float_t MuonPlusMapCorrected;
00121    
00122  MSG("Calibrator",Msg::kVerbose) << "SigMappedCalibrator on " << siglin 
00123                                  << " siglin in seid " << seid 
00124                                  << " (indexed as " << seid.BuildPlnStripEndKey() 
00125                                  <<" )\n";
00126  
00127  switch (fCalMode){
00128  case 0:
00129     // in this case forgo calibration
00130     
00131     break;
00132  case 1:
00133     {
00134     // default:  Use fits to mapper only
00135        const CalMapperFits* mappercal = fMapperFitsPtr.GetRowByIndex(seid.BuildPlnStripEndKey());
00136        if(mappercal ==0) {
00137           static int msglimit = 20;  // no more than 20 complaints
00138           if (msglimit) {
00139             MSG("MapperCalibrator",Msg::kWarning) 
00140               << "No database row for StripEnd " << seid 
00141               << " (indexed as " << seid.BuildPlnStripEndKey() << ")" << endl;
00142             if (--msglimit == 0)
00143               MSG("MapperCalibrator",Msg::kWarning)
00144                 << " ... last warning of this type" << endl;
00145           }
00146           return siglin;
00147        }
00148        
00149        MapCorrected = mappercal->AttenCorrected(siglin,Y);
00150        return MapCorrected;
00151        
00152        break;
00153     }
00154  case 2:
00155     {
00156        // use full mapper table only
00157        
00158        break;
00159     }
00160  case 3:
00161     {
00162        // use muon fits 
00163        const CalMuonCalibration* muoncal = fMuonPtr.GetRowByIndex(seid.BuildPlnStripEndKey());
00164        if(muoncal ==0) {
00165        MSG("MuonCalibrator",Msg::kWarning) 
00166           << "No database row for StripEnd " << seid.BuildPlnStripEndKey() << "\n";
00167        return siglin;
00168        }
00169        MuonCorrected = muoncal->AttenCorrected(siglin,Y);
00170        return MuonCorrected;
00171        break;
00172     }
00173  case 4:
00174     {
00175        // use muon fits, then mapper table as tweaks
00176        // use muon fits 
00177        const CalMuonCalibration* muoncal = fMuonPtr.GetRowByIndex(seid.BuildPlnStripEndKey());
00178        const CalMapperData* mapperdata = fMapperDataPtr.GetRowByIndex(seid.BuildPlnStripEndKey());
00179        if(muoncal ==0) {
00180           MSG("MuonCalibrator",Msg::kWarning) 
00181              << "No database row for StripEnd " << seid.BuildPlnStripEndKey() << "\n";
00182           return siglin;
00183        }
00184        
00185        MuonCorrected = muoncal->AttenCorrected(siglin,Y); 
00186        MuonPlusMapCorrected = mapperdata->ResponseCorrected(MuonCorrected,Y);
00187        return MuonPlusMapCorrected;
00188        break;
00189     }
00190 
00191  }
00192 
00193 
00194  return siglin; 
00195 
00196 }
00197 
00198 //......................................................................
00199 
00200 void SigMappedCalibrator::ReInit(VldContext vc) {
00201    MSG("Calibrator",Msg::kVerbose) << "SigMappedCalibrator::ReInit(VldContext)" << endl;
00202    switch (fCalMode){
00203    case 0:
00204       // in this case forgo calibration
00205       break;
00206    case 1:
00207       // default:  Use fits to mapper only
00208       fMapperFitsPtr.NewQuery(vc,0);
00209       break;
00210    case 2:
00211       // use full mapper table only
00212       break;
00213    case 3:
00214       // use muon fits 
00215       fMuonPtr.NewQuery(vc,0);
00216       break;
00217    case 4:
00218       // use muon fits, then mapper table as tweaks
00219       fMuonPtr.NewQuery(vc,0);
00220       fMapperDataPtr.NewQuery(vc,0);
00221       break;
00222    default:
00223       //Don't know what to do.
00224       break;
00225    }
00226 }
00227 
00228 //......................................................................
00229 
00230 const CalMapperFits* SigMappedCalibrator::GetCalMapperFits(PlexStripEndId seid) const
00231 {
00232  return fMapperFitsPtr.GetRowByIndex(seid.BuildPlnStripEndKey());
00233 }

Generated on Thu Nov 1 15:53:46 2007 for loon by  doxygen 1.3.9.1