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

TMarLumi.C

Go to the documentation of this file.
00001 
00002 // Class TMarLumi
00003 //
00004 // Author     : F. Cassol Brunner
00005 // Created    : 02/2002
00006 // Last update: $Date: 2005/06/24 08:35:29 $
00007 //          by: $Author: gbrandt $
00008 // Comment: Contains definition of lumi class
00010 
00011 #ifndef __TMARLUMI
00012 #include "Marana/TMarLumi.h"
00013 #endif
00014 
00015 #define MARLUMIDEBUG 0
00016 
00017 
00018 
00019 ClassImp(TMarLumi)
00020 
00021 TMarLumi::TMarLumi(string filename, string FileBadRun="not_given")
00022 {
00023 
00024 
00025  // Init Lumi
00026  RunNumber=0;
00027  RunNumberOld=0;
00028  LumiPerRun=0;
00029  TotalLumi=0;
00030  LumiPerRunOld=0;
00031  TotalLumiOld=0;
00032  detStatus= NULL; 
00033   runList =NULL;  
00034 //...change  TMarLumi::GetPolar() if you change the bin of these histograms!!!!
00035  TH1F* hpolarR = new TH1F("polarR","polarisation Right",33, -82.5, 82.5);
00036  TH1F* hpolarL = new TH1F("polarL","polarisation Left",33, -82.5, 82.5);
00037  TH1F* hpolar  = new TH1F("polar","polarisation All",33, -82.5, 82.5);
00038  
00039  polar_integral = NULL;
00040 
00041  float nLzero=0;
00042  float nRzero=0;
00043 
00044 
00045 
00046  rpolar     = new TRandom();
00047 
00048  try{
00049 
00050    Int_t nrun;
00051    Float_t lumi;
00052    Float_t polar=0;
00053 
00054    // Save current ROOT directory so histos below get added to correct dir
00055    TDirectory *savedir = gDirectory;
00056    TFile* runfile=new TFile(filename.c_str());
00057    savedir->cd();
00058 
00059    if (!runfile){
00060        Error("TMarLumi","Cannot open lumi file '%s'",runfile->GetName());
00061        throw string("exit");
00062    }
00063    runfile->GetObject("H1RunList",runList);
00064    if (!runList) {
00065         Error("TMarLumi","Cannot get H1RunList from '%s'",runfile->GetName());
00066         throw  string("exit");
00067    }
00068    runfile->GetObject("MyDetectorStatus",detStatus);
00069    if (!detStatus) {
00070         Error("TMarLumi","Cannot get H1DetectorStatus from '%s'",runfile->GetName());
00071         throw  string("exit");
00072    }
00073    else { detStatus->Print(); }
00074 
00075    runList->Sort();
00076 
00077    for(int n=0;n<runList->GetNrOfRuns();n++){
00078        H1RunLumi* runLumi=(H1RunLumi*)runList->At(n);
00079 
00080        nrun=runLumi->GetRunNumber();
00081        lumi=runLumi->GetCorrectedLumi();
00082        polar=runLumi->GetPolarisation();
00083 
00084        if(MARLUMIDEBUG)cout << "- good run "<< nrun << " lumi "<< lumi << " polarization "<< polar<<endl;
00085 
00086        if(IsDataR(nrun)==kTRUE){
00087          if(polar!=0)hpolarR->Fill(polar,lumi);
00088           else nRzero+=lumi;
00089        }
00090        else if(IsDataL(nrun)==kTRUE){
00091           if(polar!=0)hpolarL->Fill(polar,lumi);
00092           else nLzero+=lumi;
00093        }
00094    }
00095    runfile->Close();
00096    delete  runfile;
00097 
00098    printf("- Found %d good runs in Lumi file \n",runList->GetNrOfRuns());
00099 
00100 
00101 
00102   } //... try
00103   catch(string error)
00104  {
00105      cout << error <<endl;;
00106      exit(0); 
00107   
00108  }
00109  catch(...)
00110  {
00111     throw string("TMarLumi::TMarLumi = Undefined error in reading parameters_file! - stop");
00112     exit(0); 
00113  }     
00114 
00115 
00116 //...scale the left and right histogram adding the run without pol data
00117   
00118   if(nRzero>0&&hpolarR->Integral()>0){
00119     float factor=(hpolarR->Integral()+nRzero)/hpolarR->Integral();
00120     hpolarR->Scale(factor);
00121   }  
00122   if(nLzero>0&&hpolarL->Integral()>0){
00123     float factor=(hpolarL->Integral()+nLzero)/hpolarL->Integral();
00124     hpolarL->Scale(factor);
00125   }
00126 
00127   hpolar->Add(hpolarR);
00128   hpolar->Add(hpolarL);
00129   
00130    
00131 //... vector with  profile of the polarisation integral (normalized to 1)
00132   
00133   if(hpolar->GetEntries()>0){
00134     hpolar->ComputeIntegral();
00135     polar_integral = new double[33];
00136     polar_integral=hpolar->GetIntegral();
00137   }
00138 
00139 
00140 }
00141 
00142 
00143 
00144 
00145 // Standard destructor
00146 TMarLumi::~TMarLumi()
00147 {
00148 
00149 };
00150 
00151   
00152 Bool_t TMarLumi::Update(Int_t nrun)
00153 {
00155 //     Get the lumi of the run number
00157 
00158  RunNumberOld=RunNumber;
00159  LumiPerRunOld=LumiPerRun;
00160  TotalLumiOld=TotalLumi;
00161 
00162 //...search in the list of good lumi runs
00163  if(runList->IsSelected(nrun)){
00164 
00165      LumiPerRun=runList->GetIntLumi(nrun,nrun);
00166 
00167  }
00168  else
00169  {
00170 //...else search in the list of bad lumi runs
00171 
00172   //cout <<"--> TMarLumi::Update = Run "<< nrun <<" is not in the RunList"<<endl;
00173 
00174    return(kFALSE);
00175  }
00176 
00177 
00178  TotalLumi+=LumiPerRun;
00179  RunNumber=nrun;
00180 
00181  return(kTRUE);  
00182  
00183  
00184 }
00185 
00186 Float_t TMarLumi::GetPolar(){
00187 
00188   if(polar_integral==NULL) return 0;
00189 
00190 //... get a uniform random number between 0 and 1
00191   Double_t u=rpolar->Uniform();
00192   int nbin=TMath::BinarySearch(33,polar_integral,u);
00193   
00194   Float_t pola=(-80.+nbin*5)/100; 
00195 
00196   return pola;
00197 };
00198 
00199 Bool_t TMarLumi::IsDataL( Int_t& irun)
00200 {
00201   if((irun > 376562  && irun <= 386696 )     || //0304L1
00202      (irun >= 402992 && irun  <=411192))        //05L1
00203     {
00204       
00205       return kTRUE;
00206     }
00207   return kFALSE;
00208 };
00209 Bool_t TMarLumi::IsDataR( Int_t& irun)
00210 {
00211   if( (irun >= 357072 && irun <= 376562) ||    //0304R1
00212       (irun >= 387942 && irun <= 392213) ||    //0304R2
00213       (irun >= 399101 && irun <= 402634)  ||   //05R1
00214       (irun >  411192))                        //05R2
00215   {
00216      return kTRUE;
00217   }
00218   return kFALSE;
00219 }
00220 

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