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

THisto.C

Go to the documentation of this file.
00001 
00002 // Class THisto
00003 //
00004 // Author     : F. Cassol Brunner
00005 // Created    : 6/11/2002
00006 // Last update: 
00007 //          by: 
00009 
00010 
00011 #include "Marana/THisto.h"
00012 
00013 
00014 
00015 
00016 ClassImp(THisto)
00017 
00018 THisto::THisto()
00019 {
00020 //--- empty constructor
00021 
00022 }
00023 
00024 THisto::THisto(const TRunHisto& run,string Tag,string textfile)
00025 {
00026   debug=run.debug;
00027   
00028   NumSelEve=0;
00029   NumEve=0;
00030   NumSelEvePerRun=0;
00031   NumSelEvePerRunOld=0;
00032   fp=NULL;
00033   hatCopy=NULL; 
00034   modsCopy=NULL; 
00035 
00036 //... Open file to write selected events
00037   if(textfile!=""){
00038     
00039     if ((fp  = fopen(textfile.c_str(),"w+")) == NULL) {
00040        cout << "THisto::THisto : error in opening "<< textfile <<endl;
00041     }
00042   }
00043 //...read the parameters and book the histograms in the / dir
00044   ReadParameters(run.histo_par_file,Tag,0);
00045 
00046 //...read the parameters and book the histograms in each sub-directory of run.output_file_root
00047   TList* dir=run.output_file_root->GetListOfKeys();
00048   for(int i=0;i<dir->GetSize();i++){
00049     cout << "--> Create histo in  dir "<< dir->At(i)->GetName() << endl;
00050     run.output_file_root->cd(dir->At(i)->GetName());
00051     
00052     ReadParameters(run.histo_par_file,Tag,i+1);
00053   }
00054   run.output_file_root->cd();
00055 
00056   ntuple=NULL;
00057 
00058 //... open hat/mods file to write selected events
00059   
00060   if(run.out_file_mods_hat!=""){
00061     
00062 
00063     for(list<string>::const_iterator itag=run.TagToBeWritten.begin();itag!=run.TagToBeWritten.end();itag++)
00064     {
00065         
00066 
00067         if((*itag)==Tag){ 
00068           string dir="";
00069           string file="";
00070           unsigned int pos=run.out_file_mods_hat.rfind("/");
00071           if(pos!=string::npos){
00072              dir=run.out_file_mods_hat.substr(0,pos+1);   
00073              file=run.out_file_mods_hat.substr(pos+1) ;          
00074              
00075           }  else {
00076              file=run.out_file_mods_hat; 
00077           
00078           }   
00079 
00080             
00081           if ( gH1Tree->GetChain(3)) {
00082             string hatname;
00083 
00084             hatname=dir+"HAT."+Tag+"."+file;
00085             cout << "\n--> output hat: "<< hatname<<endl;      
00086         
00087             hatCopy = gH1Tree->CopyTree("HAT", hatname.c_str() );
00088             if (!hatCopy) throw string("THisto::THisto= could not copy HAT-tree!");
00089             
00090         
00091           }
00092 
00093           if ( gH1Tree->GetChain(2) ) {
00094             string modsname;
00095             modsname=dir+"MODS."+Tag+"."+file;
00096             cout << "\n--> output mods: "<< modsname<<endl;    
00097 
00098             modsCopy = gH1Tree->CopyTree("MODS", modsname.c_str());
00099             if (!modsCopy)throw string("THisto::THisto= could not copy MODS-tree!");
00100           }
00101         }
00102 
00103      }  
00104   }
00105   
00106 
00107 }
00108 THisto::~THisto()
00109 {
00110 // Base destructor
00111   if ( hatCopy )  hatCopy->BuildIndex("RunNumber","EventNumber");
00112   if ( modsCopy ) modsCopy->BuildIndex("RunNumber","EventNumber");
00113 
00114   
00115   if (fp) fclose(fp);
00116   
00117 }
00118 void THisto::Print(const TMarEvent &event){
00119   if (fp){
00120   // Write selected events of channel in text file 
00121     Char_t OutString[50];
00122     sprintf(OutString,"%d %d\n",event.RunNumber,event.EventNumber);
00123     fputs(OutString,fp);
00124   }
00125   else {
00126     cout << "THisto::Print = error, no output file opened!"<<endl;
00127   }
00128 }
00129 
00130 
00131 Bool_t THisto::Cut(TMarEvent &event){
00132 
00133 //...Fill Lumi info before the cut
00134   if(event.Syst_Type==0){
00135     FillLumi(event);
00136     NumEve++;
00137   }
00138   
00139   if(event.IsCosmic()) return kFALSE;
00140 
00141   if(fabs(event.Vertex[2])>50) return kFALSE;
00142 
00143   if(event.Syst_Type==0){  
00144     NumSelEve++;  
00145     NumSelEvePerRun++;
00146   }
00147 
00148   return kTRUE; 
00149 
00150 } 
00151 
00152 
00153 void THisto::FillLumi(TMarEvent &event)
00154 {
00155 
00156 //... fill lumi info if new run
00157   if (event.lumi==NULL)return;
00158 
00159   if (!event.NewRun)
00160   {
00161      NumSelEvePerRunOld=NumSelEvePerRun;
00162      return;
00163   }  
00164 
00165 
00166   if(event.num>1){
00167 //...here one has to fill the lumi info objects      
00168 
00169       cout <<  "  - lumi : "<<event.lumi->TotalLumiOld << " " << event.lumi->LumiPerRunOld <<" "<< NumSelEve<< 
00170            " "<<NumSelEvePerRunOld<< endl; 
00171    
00172 //     FillHisto(1,event.lumi->TotalLumiOld,NumSelEve,event.MCWeight);
00173 //     FillHisto(2,event.lumi->TotalLumiOld,NumSelEvePerRunOld/event.lumi->LumiPerRunOld,event.MCWeight);
00174   
00175 //     if(nt_lumi!=NULL)nt_lumi->Fill(event.lumi->TotalLumiOld,event.lumi->LumiPerRunOld,(Float_t)NumSelEve,(Float_t)NumSelEvePerRunOld);
00176 
00177      NumSelEvePerRun=0;  
00178     
00179  
00180   }  
00181 
00182 
00183 }
00184 

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