Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

TMarH1LarCalParameters.C

Go to the documentation of this file.
00001 /***************************************************************************
00002                           TMarH1LarCalParameters.C
00003 
00004                                 based on
00005 
00006                           H1CalibParameters.C  -  description
00007                              -------------------
00008     begin                : Fri Jun 13 2002
00009     copyright            : (C) 2002 by Nicole Werner
00010     email                : nwerner@mail.desy.de
00011     last update          : $Date: 2005/03/11 08:52:43 $ (UTC)
00012     by                   : $Author: sauvan $
00013 
00014 ***************************************************************************/
00015 
00016 /***************************************************************************
00017 *                                                                         *
00018 *   This program is free software; you can redistribute it and/or modify  *
00019 *   it under the terms of the GNU General Public License as published by  *
00020 *   the Free Software Foundation; either version 2 of the License, or     *
00021 *   (at your option) any later version.                                   *
00022 *                                                                         *
00023 ***************************************************************************/
00024 
00025 
00026 #ifndef __TMarH1LarCalParameters_H
00027 #include "TMarH1LarCalParameters.h"
00028 #endif
00029 
00030 #include "TMath.h"
00031 #include "H1Steering/H1SteerManager.h"
00032 #include <iostream>
00033 
00034 ClassImp(TMarH1LarCalParameters)
00035 
00036 //------------------------------------------------------
00037 
00038 TMarH1LarCalParameters::TMarH1LarCalParameters(TString DataSet, Int_t RunPeriod)
00039 {
00040   // Constructor
00041 
00042   fDataSet = DataSet;
00043   fRunPeriod = RunPeriod;
00044   fRunPeriodName = "";
00045 
00046   fOctantConstants = new H1ArrayF(32);
00047   fZimpactConstants = new H1ArrayF(208);
00048   fForwardWheelConstants = new H1ArrayF(6);
00049   fEnergyResolutionConstantsData = new H1ArrayF(57); // size???
00050   fEnergyResolutionConstantsMC = new H1ArrayF(57); // size???
00051 
00052   fOctantCalibrationFactor = 1.0;
00053   fZimpactCalibrationFactor = 1.0;
00054   fForwardWheelCalibrationFactor = 1.0;
00055   fResolutionSmearingFactor = 1.0;
00056 
00057   fRandom = new TRandom(1);
00058 
00059   Reset();
00060 }
00061 
00062 TMarH1LarCalParameters::~TMarH1LarCalParameters()
00063 {
00064   // Destructor
00065 
00066   if (fOctantConstants) {
00067     delete fOctantConstants;
00068   }
00069   if (fZimpactConstants) {
00070     delete fZimpactConstants;
00071   }
00072   if (fForwardWheelConstants) {
00073     delete fForwardWheelConstants;
00074   }
00075   if (fEnergyResolutionConstantsData) {
00076     delete fEnergyResolutionConstantsData;
00077   }
00078   if (fEnergyResolutionConstantsMC) {
00079     delete fEnergyResolutionConstantsMC;
00080   }
00081 
00082   if (fRandom) {
00083     delete fRandom;
00084   }
00085 
00086 }
00087 
00088 void TMarH1LarCalParameters::Reset()
00089 {
00090   // Reset the boolean flags - Use to Read in new parameters
00091 
00092   bReadOctantConstants = false;
00093   bReadZimpactConstants = false;
00094   bReadForwardWheelConstants = false;
00095   bReadEnergyResolutionConstants = false;
00096 }
00097 
00098 
00099 void TMarH1LarCalParameters::SetCalibrationParametersFile(TString filename)
00100 {
00101   // Sets up the gH1SteerManager with the given steering file
00102 
00103   if (fRunPeriod == 5) {
00104     fRunPeriodName = "9900";
00105   } else if (fRunPeriod == 6 || fRunPeriod == 7 || fRunPeriod == 8) {
00106     fRunPeriodName = "0304";
00107   } else {
00108     Warning("SetCalibrationParametersFile", "RunPeriod %i not supported.  Set to 9900.", fRunPeriod);
00109     fRunPeriodName = "9900";
00110   }
00111 
00112 //   TString filePath = "TMarH1ElecCalibration/";
00113   TString filePath = "./";
00114   filename.Append(fRunPeriodName);
00115   filename.Append(".steer");
00116   filePath.Append(filename);  
00117   gH1SteerManager->SetFilename(filePath);
00118   
00119   gH1SteerManager->SetClassname("H1LarCalParameters");
00120 }
00121 
00122 Double_t TMarH1LarCalParameters::GetOctantCalibrationFactor(Float_t &phi, Float_t &zimpact)
00123 {
00124   // Get the phi dependent calibration factor for LAr electrons
00125   // The factor depends on the Wheel and the Octant within that wheel
00126   SetOctantConstants();
00127   SetOctantCalibrationFactors(phi, zimpact);
00128   return fOctantCalibrationFactor;
00129 }
00130 
00131 Double_t TMarH1LarCalParameters::GetZimpactCalibrationFactor(Float_t &zimpact)
00132 {
00133   // Get the zimpact dependent calibration factor for LAr electrons
00134   SetZimpactConstants();
00135   SetZimpactCalibrationFactors(zimpact);
00136   return fZimpactCalibrationFactor;
00137 }
00138 
00139 Double_t TMarH1LarCalParameters::GetForwardWheelCalibrationFactor(Float_t &zimpact)
00140 {
00141   // Get the calibration factor for LAr electrons in forward wheels
00142   SetForwardWheelConstants();
00143   SetForwardWheelCalibrationFactors(zimpact);
00144   return fForwardWheelCalibrationFactor;
00145 }
00146 
00147 Double_t TMarH1LarCalParameters::GetResolutionSmearingFactor(Float_t &zimpact)
00148 {
00149   // Get the zimpact dependent smearing factor for MC
00150   SetEnergyResolutionConstants();
00151   SetResolutionSmearingFactors(zimpact);
00152   return fResolutionSmearingFactor;
00153 }
00154 
00155 void TMarH1LarCalParameters::SetOctantConstants()
00156 {
00157   // Read in the Wheel + Octant dependent constants from the H1SteerManager
00158   
00159   if (!bReadOctantConstants) {
00160     bReadOctantConstants = true;
00161 
00162 
00163     if ( (fDataSet.CompareTo("Default"))==0 ) {
00164       // Set default array for 94-98 data, no calibration applied
00165       fOctantConstants->Reset(1.0);
00166       return;
00167     }
00168 
00169     SetCalibrationParametersFile("LarCalStackFactors");
00170     TString steerName = "NStack";
00171     steerName.Append(fDataSet);
00172 
00173     Float_t phiConstants[32];
00174     gH1SteerManager->ReadArray(steerName,phiConstants);
00175 
00176     fOctantConstants->Set(32, phiConstants);
00177   }
00178 }
00179 
00180 void TMarH1LarCalParameters::SetZimpactConstants()
00181 {
00182   // Read in the Zimpact dependent constants from the H1SteerManager
00183   
00184   if (!bReadZimpactConstants) {
00185     bReadZimpactConstants = true;
00186 
00187 
00188     if ( (fDataSet.CompareTo("Default"))==0 ) {
00189       // Set default array for 94-98 data, no calibration applied
00190       fZimpactConstants->Reset(1.0);
00191       return;
00192     }
00193 
00194     SetCalibrationParametersFile("LarCalZimpactFactors");
00195     TString steerName = "Zimpact";
00196     steerName.Append(fDataSet);
00197 
00198     Float_t zimpactConstants[286];
00199     gH1SteerManager->ReadArray(steerName,zimpactConstants);
00200 
00201     fZimpactConstants->Set(286, zimpactConstants);
00202   }
00203 }
00204 
00205 void TMarH1LarCalParameters::SetForwardWheelConstants()
00206 {
00207   // Read in the zimpact dependent constants for the forward wheels from the H1SteerManager
00208   
00209   if (!bReadForwardWheelConstants) {
00210     bReadForwardWheelConstants = true;
00211 
00212 
00213     if ( (fDataSet.CompareTo("Default"))==0 ) {
00214       // Set default array for 94-98 data, no calibration applied
00215       fForwardWheelConstants->Reset(1.0);
00216       return;
00217     }
00218 
00219     SetCalibrationParametersFile("LarCalForwardWheelFactors");
00220     TString steerName = "ForwardWheel";
00221     steerName.Append(fDataSet);
00222 
00223     Float_t forwardwheelConstants[6];
00224     gH1SteerManager->ReadArray(steerName,forwardwheelConstants);
00225 
00226     fForwardWheelConstants->Set(6, forwardwheelConstants);
00227   }
00228 
00229 }
00230 
00231 void TMarH1LarCalParameters::SetEnergyResolutionConstants()
00232 {
00233   // Read in the data/mc energy resolutions from the H1SteerManager
00234 
00235   if (!bReadEnergyResolutionConstants) {
00236     bReadEnergyResolutionConstants=true;
00237     
00238     SetCalibrationParametersFile("LarCalResFactors");
00239     TString steerName = "Res";
00240     TString steerNameData(steerName + fRunPeriodName);  // run period e.g. 9900 (Data)
00241     TString steerNameMC(steerName + fDataSet);  // dataset here is e.g. 99NC (Django)
00242 
00243     Float_t energyResolutionConstantsData[57];
00244     gH1SteerManager->ReadArray(steerNameData,energyResolutionConstantsData);
00245     Float_t energyResolutionConstantsMC[57];
00246     gH1SteerManager->ReadArray(steerNameMC,energyResolutionConstantsMC);
00247 
00248     fEnergyResolutionConstantsData->Set(57, energyResolutionConstantsData);
00249     fEnergyResolutionConstantsMC->Set(57, energyResolutionConstantsMC);
00250 
00251   }
00252 }
00253 
00254 void TMarH1LarCalParameters::SetOctantCalibrationFactors(Float_t &phi, Float_t &zimpact)
00255 {
00256   // returns the octant dependent calibration factor
00257   
00258   Int_t nOctant = SetLarOctant(phi);
00259   Int_t nWheel = SetLarWheel(zimpact);
00260   Int_t nStack = (nWheel * 8) + nOctant;
00261 
00262   if (nStack < 0) {
00263     cout << "NWheel = " << nWheel << "\t"
00264          << "NOctant = " << nOctant << endl;
00265     cout << "Phi = " << phi << "\t"
00266          << "zImpact = " << zimpact << endl;
00267   }
00268 
00269   if (nWheel < 4)
00270     fOctantCalibrationFactor = fOctantConstants->At(nStack);
00271   else
00272     fOctantCalibrationFactor = 1.0;
00273 }
00274 
00275 void TMarH1LarCalParameters::SetZimpactCalibrationFactors(Float_t &zimpact)
00276 {
00277   // returns the zimpact dependent calibration factor
00278 
00279   Int_t zStep = SetLarZBin(zimpact, 1);
00280 
00281   if ( (zStep-190) >= -190 && (zStep-190) < 95)
00282     fZimpactCalibrationFactor = fZimpactConstants->At(zStep);
00283   else
00284     fZimpactCalibrationFactor = 1.0;
00285 
00286 }
00287 
00288 void TMarH1LarCalParameters::SetForwardWheelCalibrationFactors(Float_t &zimpact)
00289 {
00290   // returns the zimpact dependent calibration factor for forward wheels
00291 
00292   Int_t zStep = SetForwardWheelZBin(zimpact);
00293 
00294   fForwardWheelCalibrationFactor = 1.0;
00295   
00296   if (zStep>=0)
00297     fForwardWheelCalibrationFactor += fForwardWheelConstants->At(zStep);
00298 }
00299 
00300 void TMarH1LarCalParameters::SetResolutionSmearingFactors(Float_t &zimpact)
00301 {
00302   // Smear MC according according difference in resolution with data
00303   // Shamelessly stolen from H1CalibElec
00304 
00305   Float_t Sigma = -1.0;
00306 
00307   if(zimpact >= -190.0 && zimpact < 0) {
00308     Int_t zBin = SetLarZBin(zimpact, 5);
00309     
00310     //  Smear MC if resolution better than in data
00311     if(fEnergyResolutionConstantsData->At(zBin) > fEnergyResolutionConstantsMC->At(zBin))
00312 
00313       Sigma=TMath::Sqrt(TMath::Power(fEnergyResolutionConstantsData->At(zBin),2)-
00314                         TMath::Power(fEnergyResolutionConstantsMC->At(zBin),2));
00315 
00316   } else if(zimpact>=0&&zimpact<20) 
00317     Sigma=0.028;
00318   else if(zimpact>=20&&zimpact<95) 
00319     Sigma=0.028;
00320   else
00321     Sigma=0.036;
00322   
00323   if(Sigma>0.001)
00324     fResolutionSmearingFactor = fRandom->Gaus(1,Sigma);       // apply smearing
00325   else
00326     fResolutionSmearingFactor = 1.0;
00327 }
00328 
00329 Int_t TMarH1LarCalParameters::SetLarOctant(Float_t &phi)
00330 {
00331   // returns the Octant in the LAr corresponding to the phi position
00332   
00333   // Transform -180 < phi < 180 to 0 < phi < 360
00334   phi += TMath::Pi();
00335   
00336   // Label each 45.0 octant of phi as 0...7
00337   Int_t nOctant = Int_t(TMath::Floor( phi / (TMath::Pi()/4.0) )); // Round down and convert to Int_t
00338   
00339   return nOctant;
00340 }
00341 
00342 Int_t TMarH1LarCalParameters::SetLarWheel(Float_t &zimpact)
00343 {
00344   // Returns the wheel in the LAr corresponding to zimpact
00345   // wheel boundaries copied from H1Calculator/H1Constants
00346 
00347   Int_t nWheel = 100;
00348 
00349   if ( zimpact < -152.5 ) {
00350     nWheel = 0;
00351   } else if ( zimpact < -60 ){
00352     nWheel = 1;
00353   } else if ( zimpact < 20 ){
00354     nWheel = 2;
00355   } else if ( zimpact < 95 ){
00356     nWheel = 3;
00357   } else if ( zimpact < 300 ){
00358     nWheel = 4;
00359   } else if ( zimpact < FLT_MAX ){
00360     nWheel = 5;
00361   } else  {
00362     Warning("GetLarWheel", ("zImpact %d not inside LAr!"), zimpact);
00363   }
00364   
00365   return nWheel;
00366 }
00367 
00368 Int_t TMarH1LarCalParameters::SetLarZBin(Float_t &zimpact, Int_t binsize)
00369 {
00370   // returns the Zimpact position of the electron in the Lar, in binsize cm bins
00371   Int_t zStep = (Int_t)TMath::Floor(zimpact/binsize);
00372   zStep += 190 / binsize;
00373 
00374   return zStep;
00375 }
00376 
00377 Int_t TMarH1LarCalParameters::SetForwardWheelZBin(Float_t &zimpact)
00378 {
00379   // returns the forward wheel corresponding to the Zimpact position of the electron
00380 
00381   Int_t zStep=-1;
00382 
00383   // hardwired numbers for forward Lar geometry taken from H1CalibElec,
00384   // presumably taken from lotus++/electronphan/qcalelar.F
00385   if(zimpact>=95.0&&zimpact<120.0)
00386     zStep=0;
00387   else if(zimpact>=120.0 && zimpact<180.0)
00388     zStep=1;
00389   else if(zimpact>=180 && zimpact<215)
00390     zStep=2;
00391   else if(zimpact>=215 && zimpact<290)
00392     zStep=3;
00393   else if(zimpact>=290 && zimpact<320)
00394     zStep=4;
00395   else if(zimpact>=320)
00396     zStep=5;
00397 
00398   return zStep;
00399 }

Generated on Thu Jul 28 11:48:52 2005 for SFHMarana by doxygen 1.3.2