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

THistoManager.C

Go to the documentation of this file.
00001 #ifndef __THISTOMANAGER_H
00002 #include "Marana/THistoManager.h" 
00003 #endif
00004 
00005 
00006 void THistoManager::ReadParameters(string parameters_file,string Tag,const Short_t SysNum) 
00007 {  
00008 
00009  string ClassName="";
00010  
00011  list<string> PartTags;
00012  ReadParameters(parameters_file,Tag,ClassName,PartTags,SysNum);
00013 
00014 }
00015 
00016 
00017 void THistoManager::ReadParameters(string parameters_file,string Tag,string ClassName,
00018                                         list<string>& PartTags,const Short_t SysNum) 
00019 {  
00020   string item;
00021 //... open the Parameters file
00022   
00023   try {
00024 
00025    if(SysNum>=40) {
00026      ostringstream error;
00027       error << "THistoManager::FillHisto = Error Systematic num " 
00028           << SysNum << " >= 40 "<< endl;              
00029     string mess=error.str();      
00030      
00031     throw mess; 
00032     return;
00033    }
00034 
00035 
00036 
00037    ifstream inParams(parameters_file.c_str());
00038    
00039    if(!inParams)
00040      throw string("THistoManager::ReadParameters = Error in opening histogram parameter file! - stop");
00041    
00042    string end="end_";
00043    string start=Tag+":";
00044    
00045    bool stop=false;
00046    string token,type,readtag,dummy;
00047    
00048 //... stream buffer with histogram definitions
00049    istringstream* parstrstr=0;
00050    string parstr;
00051    
00052     while (getline(inParams, item)) {
00053       if (item.find(start) == string::npos) { continue; }
00054       cout << endl << "Start reading loop " << Tag << ": " << endl;
00055       string bufx(item.substr(item.find(":") + 1));
00056       string::size_type more = 0;
00057       parstr = "";
00058       do {
00059         //... eat whitespace
00060         while ( bufx[0] == ' ' ) {
00061           bufx = bufx.substr(1,bufx.size());
00062         }
00063         //cout << bufx << endl;
00064 
00065         // check for multiple entries separated by ,      
00066         more = bufx.find(",");
00067         //cout << more << endl;
00068         if (more == string::npos) {
00069           token = bufx;
00070         } else {
00071           token = bufx.substr(0,more);          
00072           bufx = bufx.substr(more+1,bufx.size());
00073         }
00074 
00075         //cout << "token: " <<token << endl;
00076         //... optional histogram id offset in parentheses  
00077         Int_t hoffset = 0;
00078         string::size_type s1 = token.find("(")+1;
00079         string::size_type s2 = token.find(")")-s1;
00080         string oc = token.substr(s1,s2);  
00081         hoffset = atoi(oc.data());
00082 
00083         //cout << hoffset << endl;
00084         if (hoffset) {
00085           type = token.substr(0,s1 - 1).c_str();
00086         } else {
00087           type = token;
00088           while ( bufx[type.size()-1] == ' ' ) {//... eat whitespace
00089             type = type.substr(0,type.size()-1);
00090           }
00091          }       
00092         if(ClassName!="") type=type+ClassName;
00093 
00094         cout << endl 
00095           << "________________________________________________________" << endl
00096           << "type: '" << type <<"' histogram id offset: " << hoffset   << endl
00097           << "________________________________________________________" << endl
00098           << endl;
00099 
00100         //... on first iteration read histogram definitions into a buffer
00101         if ( parstr == "" ) {        
00102           parstr = "";
00103           while (!stop && getline(inParams,item)) {
00104             parstr += item;            
00105             parstr += '\n';
00106             if (item == end + Tag) { stop = true; }                       
00107           }
00108         }
00109 
00110         //cout << parstr << endl;
00111         parstrstr = new istringstream(parstr.data());
00112         ParseHistos(*parstrstr,type,hoffset,Tag,PartTags,SysNum);
00113         delete parstrstr;
00114 
00115         //cout << "token: " <<token << endl;
00116         //if (more!=string::npos) cout  << "_______________________" << endl;
00117 
00118       } while (more!=string::npos);
00119 
00120       stop = false;      
00121     } //... while
00122 
00123 
00124 
00125    cout << endl <<"--> number of h1f histos "<< fHisto1D[SysNum]->GetEntries()<<endl;
00126    cout << "--> number of h2f histos "<< fHisto2D[SysNum]->GetEntries()<<endl;
00127 
00128 //... close the Parameters file
00129    inParams.close(); 
00130 
00131   } //... try 
00132   catch(string error){
00133      cout << error <<endl;;
00134      exit(0); 
00135   } catch(...){
00136      throw string("THistoManager::Parameters = Undefined error in reading parameters_file! - stop");
00137      exit(0); 
00138   }     
00139      
00140 }
00141 
00142 
00143 
00144 bool THistoManager::ParseHistos(
00145   istringstream& inParams, string&type, Int_t hoffset,
00146   string Tag, list<string>& PartTags,const Short_t SysNum)
00147 {   
00148 //     Read and parse histo definitions
00149     
00150     bool   stop=false;
00151     string item;
00152     string end="end_";
00153 
00154     while (!stop && inParams >> item) {
00155 //...read and create h1f histos ;
00156         if(item=="h1f") {
00157                 ReadParamsh1f(inParams,type,hoffset,SysNum,kFALSE);
00158         }
00159         else if(item=="h1f_sys"){
00160                 ReadParamsh1f(inParams,type,hoffset,SysNum,kTRUE);
00161         }
00162         else if(item=="h2f"){
00163                 ReadParamsh2f(inParams,type,hoffset,SysNum,kFALSE);
00164         }
00165         else if(item=="h2f_sys"){
00166                 ReadParamsh2f(inParams,type,hoffset,SysNum,kTRUE);
00167         }
00168 //...read and create h1f generic histos ;
00169         else if(item=="h1fgeneric") {
00170                 ReadParamsh1fgeneric(inParams,type,hoffset,PartTags,SysNum,kFALSE);
00171         }
00172         else if(item=="h1fgeneric_sys") {
00173                 ReadParamsh1fgeneric(inParams,type,hoffset,PartTags,SysNum,kTRUE);
00174         }
00175 
00176 //... for bin histograms with fix bin width
00177         else if(item=="2dbin"){
00178                 ReadParams2dbin(inParams,type,hoffset,SysNum);
00179         }
00180         else if(item=="3dbin"){
00181                 ReadParams3dbin(inParams,type,hoffset,SysNum);
00182         }
00183 
00184 //... for bin histograms with fix bin width
00185         else if(item=="1binfh1f"){
00186                 ReadParams1binfh1f(inParams,type,hoffset,SysNum,kFALSE);
00187         }
00188         else if(item=="1binfh1f_sys"){
00189                 ReadParams1binfh1f(inParams,type,hoffset,SysNum,kTRUE);
00190         }
00191 //... for bin histogram with variable bin width
00192         else if(item=="1binvbh1f"){
00193                 ReadParams1binVarSizeh1f(inParams,type,hoffset,SysNum,kFALSE);
00194         }
00195         else if(item=="1binvbh1f_sys"){
00196                 ReadParams1binVarSizeh1f(inParams,type,hoffset,SysNum,kTRUE);
00197         }
00198 //... for bin histograms with variable bin width
00199         else if(item=="1binvh1f"){
00200                 ReadParams1binvh1f(inParams,type,hoffset,SysNum,kFALSE);
00201         }
00202         else if(item=="1binvh1f_sys"){
00203                 ReadParams1binvh1f(inParams,type,hoffset,SysNum,kTRUE);
00204         }
00205 //... for 2bin histograms with fix bin width
00206         else if(item=="2binfh1f"){
00207                 ReadParams2binfh1f(inParams,type,hoffset,SysNum,kFALSE);
00208         }
00209         else if(item=="2binfh1f_sys"){
00210                 ReadParams2binfh1f(inParams,type,hoffset,SysNum,kTRUE);
00211         }
00212 //... for 2bin histograms with variable bin width
00213         else if(item=="2binvh1f"){
00214                 ReadParams2binvh1f(inParams,type,hoffset,SysNum,kFALSE);
00215         }
00216         else if(item=="2binvh1f_sys"){
00217                 ReadParams2binvh1f(inParams,type,hoffset,SysNum,kTRUE);
00218         } else if (item == end + Tag) {
00219             stop = true;
00220           }                     //if
00221           
00222         }                       //while 
00223   return stop;
00224 }
00225 
00226 
00227 
00228  
00229 THistoManager::THistoManager(){ 
00230 
00231     for(Int_t i=0;i<40;i++) {
00232         fHisto1D[i] = new TClonesArray("TH1F",1);
00233         fHisto2D[i] = new TClonesArray("TH2F",1);
00234         fHisto3D[i] = new TClonesArray("TH3F",1);
00235     }
00236    
00237 }; 
00238 THistoManager::THistoManager(string Parameters_file,string Tag){ 
00239 
00240     for(Int_t i=0;i<40;i++) {
00241         fHisto1D[i] = new TClonesArray("TH1F",1);
00242         fHisto2D[i] = new TClonesArray("TH2F",1);
00243         fHisto3D[i] = new TClonesArray("TH3F",1);
00244     }
00245     ReadParameters(Parameters_file,Tag);
00246 };  
00247  
00248 THistoManager::~THistoManager(){ 
00249 
00250 //---- don't know why, but seems to block the jobs at the end (for 2D histos only ?)
00251 //---- therefore very brutal solution: remove it ! crack !!
00252 //  for(Int_t i=0;i<40;i++) {
00253 // //...delete array if 1D histo   
00254 //      if(fHisto1D[i]){
00255 //        fHisto1D[i]->Delete();
00256 //        delete fHisto1D[i];
00257 //      }
00258 //    
00259 // //...delete array if 2D histo 
00260 //      if(fHisto2D[i]){
00261 //        fHisto2D[i]->Delete();
00262 //        delete fHisto2D[i];
00263 //      }  
00264 //   }
00265 
00266 };
00267 
00268 void THistoManager::FillHisto(const int& num, const double& value, const double& wait,const Short_t SysNum){ 
00269 
00270 //...fill histogram
00271    if(SysNum>=40) {
00272      ostringstream error;
00273       error << "THistoManager::FillHisto = Error Systematic num " 
00274           << SysNum << " >= 40 "<< endl;              
00275     string mess=error.str();      
00276     throw mess; 
00277     return;
00278    }
00279   
00280    
00281   if(num>fHisto1D[SysNum]->GetLast()) return;
00282    TH1F* histo= (TH1F*)fHisto1D[SysNum]->At(num);
00283    
00284    if(histo != NULL)histo->Fill(value,wait);
00285    else {
00286     if(SysNum==0) {
00287         ostringstream error;
00288         error << "THistoManager::FillHisto = Error 1D histogram num " 
00289               << num << " doesn't exist "<< endl;              
00290         string mess=error.str();      
00291         throw mess; 
00292     }
00293    }
00294 }; 
00295 
00296 void THistoManager::FillHisto(const int& num, const double& value_x, const double& value_y, const double& wait,const Short_t SysNum){ 
00297 
00298 //...fill histogram h2f
00299    if(SysNum>=40) {
00300      ostringstream error;
00301       error << "THistoManager::FillHisto = Error Systematic num " 
00302           << SysNum << " >= 40 "<< endl;              
00303     string mess=error.str();      
00304      
00305     throw mess; 
00306     return;
00307    }
00308 
00309    if(num>fHisto2D[SysNum]->GetLast()) return;
00310    TH2F* histo= (TH2F*)fHisto2D[SysNum]->At(num);
00311    
00312    if(histo != NULL)histo->Fill(value_x,value_y,wait);
00313    else {
00314     if(SysNum==0) {
00315         ostringstream error;
00316         error << "THistoManager::FillHisto = Error 2D histogram num " 
00317               << num << " doesn't exist "<< endl;              
00318         string mess=error.str();      
00319         throw mess; 
00320     }
00321   
00322    }
00323 }; 
00324 
00325 void THistoManager::FillHisto(const int& num, const double& value_x, const double& value_y, const double& value_z, const double& wait,const Short_t SysNum)
00326 { 
00327 //...fill histogram h3f
00328    if(SysNum>=40) {
00329      ostringstream error;
00330       error << "THistoManager::FillHisto = Error Systematic num " 
00331           << SysNum << " >= 40 "<< endl;              
00332     string mess=error.str();      
00333      
00334     throw mess; 
00335     return;
00336    }
00337 
00338    if(num>fHisto3D[SysNum]->GetLast()) return;
00339    TH3F* histo= (TH3F*)fHisto3D[SysNum]->At(num);
00340    
00341    if(histo != NULL)histo->Fill(value_x,value_y,value_z,wait);
00342    else {
00343     if(SysNum==0) {
00344         ostringstream error;
00345         error << "THistoManager::FillHisto = Error 3D histogram num " 
00346               << num << " doesn't exist "<< endl;              
00347         string mess=error.str();      
00348         throw mess; 
00349     }
00350   
00351    }
00352 }; 
00353 
00354 
00355 void THistoManager::Fill1BinHisto(Int_t hnum,Double_t binvalue,Double_t value,Double_t wait,const Short_t SysNum)
00356 { 
00358 //     Fill 1dim. bin histograms 
00360    if(SysNum>=40) {
00361      ostringstream error;
00362       error << "THistoManager::FillHisto = Error Systematic num " 
00363           << SysNum << " >= 40 "<< endl;              
00364     string mess=error.str();      
00365     throw mess; 
00366     return;
00367    }
00368 
00369  if(hnum>fHisto1D[SysNum]->GetLast()) return;
00370  TH1F* basehisto= (TH1F*)fHisto1D[SysNum]->At(hnum);
00371    
00372  if(basehisto) {
00373         Double_t bmin,bmax;
00374         for(Int_t i=1;i<=basehisto->GetBinContent(1);i++) {
00375                 bmin=basehisto->GetBinContent(1+i);
00376                 bmax=basehisto->GetBinContent(2+i);
00377 //              printf("Min = %f Max = %f \n",bmin,bmax);
00378                 if(binvalue>bmin&&binvalue<bmax)
00379                         ((TH1F*)fHisto1D[SysNum]->At(hnum+i))->Fill(value,wait); 
00380         }
00381  } else {
00382     if(SysNum==0) {
00383        ostringstream error;
00384        error << "THistoManager::Fill1BinHisto = Error bin histograms hnum " 
00385              << hnum << " doesn't exist "<< endl;              
00386        string mess=error.str();      
00387        throw mess; 
00388     }
00389  }
00390 } 
00391 
00392 
00393 
00394 
00395 
00396 
00397 void THistoManager::Fill2BinHisto(Int_t hnum,Double_t binvalue,Double_t binvalue2,Double_t value,Double_t wait,const Short_t SysNum)
00398 { 
00400 //     Fill 2dim. bin histograms 
00402    if(SysNum>=40) {
00403      ostringstream error;
00404       error << "THistoManager::FillHisto = Error Systematic num " 
00405           << SysNum << " >= 20 "<< endl;              
00406     string mess=error.str();      
00407      
00408     throw mess; 
00409     return;
00410    }
00411 
00412  if(hnum>fHisto1D[SysNum]->GetLast()) return;
00413  TH1F* basehisto= (TH1F*)fHisto1D[SysNum]->At(hnum);
00414    
00415  Int_t numhisto=hnum;  
00416  if(basehisto) {
00417         Double_t bmin,bmax,bmin2,bmax2;
00418 //      cout<<basehisto->GetBinContent(1)<<"*"<<basehisto->GetBinContent(2)<<endl;
00419         for(Int_t i=1;i<=basehisto->GetBinContent(1);i++) {
00420            for(Int_t j=1;j<=basehisto->GetBinContent(2);j++) {
00421                 bmin=basehisto->GetBinContent(2+i);
00422                 bmax=basehisto->GetBinContent(3+i);
00423                 bmin2=basehisto->GetBinContent((Int_t)basehisto->GetBinContent(1)+1+2+j);
00424                 bmax2=basehisto->GetBinContent((Int_t)basehisto->GetBinContent(1)+1+3+j);
00425                 numhisto+=1;
00426 //              printf("%d : Min = %f Max = %f, Min2 = %f Max2 = %f\n",numhisto,bmin,bmax,bmin2,bmax2);
00427                 if((binvalue>bmin&&binvalue<bmax) && (binvalue2>bmin2&&binvalue2<bmax2))
00428                         ((TH1F*)fHisto1D[SysNum]->At(numhisto))->Fill(value,wait); 
00429         }
00430       }
00431         
00432  } else {
00433     if(SysNum==0) {
00434        ostringstream error;
00435        error << "THistoManager::Fill1BinHisto = Error bin histograms hnum " 
00436              << hnum << " doesn't exist "<< endl;              
00437        string mess=error.str();      
00438        throw mess; 
00439     }
00440  }
00441 } 
00442 
00443 
00444 
00445 
00446 void THistoManager::ReadParamsh1f(istringstream &inParams,string type, Int_t hoffset,
00447                         const Short_t SysNum,const Bool_t BookforSys)
00448 {
00450 //     read params for bin histo h1f
00452 
00453    int num=0,bin=0;
00454    string name,word;
00455    string comment="no comment";
00456    string space=" ";
00457    double min=0,max=0;
00458 
00459    inParams >> num >> name  >> word;
00460    num += hoffset;
00461    
00462    if(word=="'"){
00463      word=space; 
00464      comment=space;
00465      do {
00466        comment=comment+space+word; 
00467        inParams >> word;
00468     
00469      }while(word!="'"); 
00470    }
00471    if(comment.find("'")!=string::npos){
00472      cout << "THistoManager::ReadParameters = error in h1f " << num<< " comment format"<<endl; 
00473      throw string("stop! \n");
00474    }                 
00475    inParams  >>bin>>min>>max;
00476   
00477 
00478    name="h"+type+name;
00479    comment=comment+space+"("+type+")";
00480    if(SysNum==0) cout << num <<" " <<name <<" : "<<comment<<endl;
00481            
00482    if(SysNum==0||BookforSys) {
00483         new (fHisto1D[SysNum]->AddrAt(num)) TH1F(name.c_str(),comment.c_str(),bin,min,max); 
00484         ((TH1F*)fHisto1D[SysNum]->At(num))->Sumw2();
00485    }      
00486 
00487 
00488 }
00489 
00490 void THistoManager::ReadParamsh2f(istringstream &inParams,string type, Int_t hoffset,
00491                                 const Short_t SysNum,const Bool_t BookforSys)
00492 {
00494 //     read params for bin histo h2f
00496 
00497    int num=0,bin_x=0,bin_y=0;
00498    string name,word;
00499    string comment="no comment";
00500    string space=" ";
00501    double min_x=0,max_x=0, min_y=0,max_y=0;
00502 
00503    inParams >> num >> name  >> word;
00504    num += hoffset;
00505    
00506    if(word=="'"){
00507      word=space; 
00508      comment=space;
00509      do {
00510         comment=comment+space+word; 
00511         inParams >> word;
00512      }while(word!="'"); 
00513    } 
00514    if(comment.find("'")!=string::npos){
00515      cout << "THistoManager::ReadParameters = error in h2f " << num<< " comment format"<<endl; 
00516      throw string("stop! \n");
00517    }         
00518    inParams   >>bin_x>>min_x>>max_x>>bin_y>>min_y>>max_y; 
00519 
00520    name="h"+type+name;
00521    comment=comment+space+"("+type+")";
00522 
00523    if(SysNum==0) cout <<num <<" " << name <<": "<<comment <<endl;          
00524    if(SysNum==0||BookforSys) {
00525         new (fHisto2D[SysNum]->AddrAt(num)) 
00526                 TH2F(name.c_str(),comment.c_str(),bin_x,min_x,max_x,bin_y,min_y,max_y); 
00527         ((TH2F*)fHisto2D[SysNum]->At(num))->Sumw2();
00528    }
00529 
00530 }
00531 
00532 
00533 
00534 
00535 
00536 void THistoManager::ReadParams1binfh1f(istringstream &inParams,string type, Int_t hoffset,
00537                                         const Short_t SysNum,const Bool_t BookforSys)
00538 {
00540 //     read params for bin histo 1binfh1f
00542 
00543     cout << "Binned histo with fix bin width ..."<<endl;
00544     int num=0,bin=0;
00545     string name,word;
00546     string comment="no comment";
00547     string space=" ";
00548     double min=0,max=0;
00549     
00550     inParams >> num >> name  >> word;
00551     num += hoffset;
00552     if(word=="'"){
00553       word=space; 
00554       comment=space;
00555       do {
00556          comment=comment+space+word; 
00557          inParams >> word;
00558       }while(word!="'"); 
00559     }
00560    inParams  >>bin>>min>>max;
00561     cout <<num<<" "<<name<<" "<<comment<<" "<<bin<<" "<<min<<" "<<max<<endl;
00562 
00563     //--- read binned variable, number of bins, bin width
00564     Int_t nbbins,hnum;
00565     Double_t binwidth,bmin,bmax,offset;
00566     string binvar;
00567     Char_t hname[100],label[200];
00568     inParams >> binvar >> nbbins >> binwidth >> offset; 
00569     cout<<" "<<binvar<<" "<< nbbins<<" "<<binwidth<<endl; 
00570     sprintf(hname,"h%s%sbin%s",type.c_str(),name.c_str(),binvar.c_str());
00571     sprintf(label,"h%s%s bin values",type.c_str(),comment.c_str());
00572     if(SysNum==0||BookforSys) {
00573         new (fHisto1D[SysNum]->AddrAt(num)) TH1F(hname,label,nbbins+2,0,nbbins+2); //histo to store min/max of bins
00574         ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(1,nbbins);
00575     }
00576     for(Int_t i=0;i<nbbins;i++) {
00577           bmin=offset+i*binwidth;
00578           bmax=offset+(i+1)*binwidth;
00579           hnum=num+i+1;
00580           sprintf(hname,"h%s%s%d",type.c_str(),name.c_str(),i);
00581           sprintf(label,"%s (%7.2f<%s<%7.2f) (%s)",comment.c_str(),bmin,binvar.c_str(),bmax,type.c_str());
00582           cout << hname <<": "<< label <<endl;          
00583           if(SysNum==0||BookforSys) {
00584                 new (fHisto1D[SysNum]->AddrAt(hnum)) TH1F(hname,label,bin,min,max);
00585                 ((TH1F*)fHisto1D[SysNum]->At(hnum))->Sumw2();      
00586                 ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(i+2,bmin);
00587                 if(i==nbbins-1) ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(i+3,bmax);
00588           }
00589     }
00590 
00591 }
00592 
00593 
00594 void THistoManager::ReadParamsh1fgeneric(istringstream &inParams,string type, Int_t hoffset,
00595                                          list<string>& PartTags,
00596                                          const Short_t SysNum,const Bool_t BookforSys)
00597 {
00599 //     read params for bin histo h1fgeneric
00601 
00602     cout << "Generic h1f histo ..."<<endl;
00603     int num=0,bin=0;
00604     string name,word;
00605     string comment="no comment";
00606     string space=" ";
00607     double min=0,max=0;
00608 
00609     inParams >> num >> name  >> word;
00610     num += hoffset;
00611     if(word=="'"){
00612       word=space; 
00613       comment=space;
00614       do {
00615         comment=comment+space+word; 
00616         inParams >> word;
00617      
00618       }while(word!="'"); 
00619     }
00620     if(comment.find("'")!=string::npos){
00621       cout << "THistoManager::ReadParameters = error in h1fgeneric " << num<< " comment format"<<endl; 
00622       throw string("stop! \n");
00623     }                 
00624     inParams  >>bin>>min>>max;
00625   
00626 //--- loop over particles to book
00627    Int_t nbpart=0;
00628    for(list<string>::iterator it=PartTags.begin();it!=PartTags.end(); it++) {
00629         string& parttag=(*it);
00630  
00631         string thisname="h"+type+name+parttag;
00632         string thiscomment=comment+parttag+space+"("+type+")";
00633         Int_t thisnum=num+nbpart;
00634         if(SysNum==0) cout << thisnum <<" " <<thisname <<" : "<<thiscomment<<endl;
00635             
00636         if(SysNum==0||BookforSys) {
00637                 new (fHisto1D[SysNum]->AddrAt(thisnum)) TH1F(thisname.c_str(),thiscomment.c_str(),bin,min,max); 
00638                 ((TH1F*)fHisto1D[SysNum]->At(thisnum))->Sumw2();
00639         } 
00640         nbpart+=1;
00641    }     
00642 
00643 
00644 }
00645 
00646 
00647 
00648 
00649 void THistoManager::ReadParams1binvh1f(istringstream &inParams,string type, Int_t hoffset,
00650                                         const Short_t SysNum,const Bool_t BookforSys)
00651 {
00653 //     read params for bin histo 1binvh1f (variable width bins)
00655 
00656     cout << "Binned histo with variable bin width ..."<<endl;
00657     int num=0,bin=0;
00658     string name,word;
00659     string comment="no comment";
00660     string space=" ";
00661     double min=0,max=0;
00662     
00663     inParams >> num >> name  >> word;
00664     num += hoffset;
00665     if(word=="'"){
00666       word=space; 
00667       comment=space;
00668       do {
00669          comment=comment+space+word; 
00670          inParams >> word;
00671       }while(word!="'"); 
00672     }
00673    inParams  >>bin>>min>>max;
00674     cout <<num<<" "<<name<<" "<<comment<<" "<<bin<<" "<<min<<" "<<max<<endl;
00675 
00676     //--- read binned variable, number of bins, bin width
00677     Int_t nbbins,hnum;
00678     Double_t bmin,bmax;
00679     string binvar;
00680     Char_t hname[100],label[200];
00681     inParams >> binvar >> nbbins;
00682     inParams >> bmin;
00683 //  cout<<" "<<binvar<<" "<< nbbins<<" "<<binwidth<<endl; 
00684     sprintf(hname,"h%s%sbin%s",type.c_str(),name.c_str(),binvar.c_str());
00685     sprintf(label,"h%s%s bin values",type.c_str(),comment.c_str());
00686     if(SysNum==0||BookforSys) {
00687         new (fHisto1D[SysNum]->AddrAt(num)) TH1F(hname,label,nbbins+2,0,nbbins+2); //histo to store min/max of bins
00688         ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(1,nbbins);
00689     }
00690     for(Int_t i=0;i<nbbins;i++) {
00691           inParams >> bmax;
00692           hnum=num+i+1;
00693           sprintf(hname,"h%s%s%d",type.c_str(),name.c_str(),i);
00694           sprintf(label,"%s (%7.2f<%s<%7.2f) (%s)",comment.c_str(),bmin,binvar.c_str(),bmax,type.c_str());
00695           cout << hname <<": "<< label <<endl;          
00696           if(SysNum==0||BookforSys) {
00697                 new (fHisto1D[SysNum]->AddrAt(hnum)) TH1F(hname,label,bin,min,max);
00698                 ((TH1F*)fHisto1D[SysNum]->At(hnum))->Sumw2();
00699                 ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(i+2,bmin);
00700                 if(i==nbbins-1) ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(i+3,bmax);
00701           }
00702           bmin=bmax;
00703     }
00704 
00705 
00706 }
00707 
00708 
00709 void THistoManager::ReadParams1binVarSizeh1f(istringstream &inParams,string type, Int_t hoffset,
00710                                              const Short_t SysNum,const Bool_t BookforSys)
00711 {
00713 //     read params for bin histo 1binvbh1f (variable width bins)
00715 
00716     cout << "Histo with variable bin width ..."<<endl;
00717 
00718     // Helper vars
00719     int num=0;
00720     string name,word;
00721     string comment="no comment";
00722     string space=" ";
00723     
00724     // Lecture du numero, du nom de l'histo et du titre
00725     inParams >> num >> name  >> word;
00726     num += hoffset;
00727     if(word=="'"){
00728       word=space; 
00729       comment=space;
00730       do {
00731          comment=comment+space+word; 
00732          inParams >> word;
00733       }while(word!="'"); 
00734     }
00735 
00736     // Lecture du nombre de bins
00737     Int_t NInputBin;
00738     inParams  >>NInputBin;
00739 
00740     // Boucle sur le binning 
00741     Double_t BinningVar[NInputBin];
00742     Double_t iBinMin = 0;
00743     Double_t iBinMax = 0;
00744     for(Int_t iBin = 0;iBin<NInputBin;iBin++){
00745       inParams >> BinningVar[iBin];
00746     }
00747     iBinMin =  BinningVar[0];
00748     iBinMax =  BinningVar[NInputBin-1];
00749 
00750     for(Int_t iBin = 0;iBin<NInputBin;iBin++){
00751       //      printf("Bin%d = %g\n",iBin,BinningVar[iBin]);
00752     }
00753 
00754     // Make labels
00755     Char_t hname[100],label[200];
00756     sprintf(hname,"h%s%s",type.c_str(),name.c_str());
00757     sprintf(label,"%s",comment.c_str());
00758     cout <<num<<" "<<hname<<" "<<comment<<" ("<<NInputBin<<" bins from "<<iBinMin<<" to "<<iBinMax<< ")\n";
00759 
00760     // Store histo
00761     if(SysNum==0||BookforSys) {
00762         new (fHisto1D[SysNum]->AddrAt(num)) TH1F(hname,label,NInputBin-1,BinningVar);
00763         ((TH1F*)fHisto1D[SysNum]->At(num))->Sumw2();
00764     }
00765 
00766 }
00767 
00768 
00769 void THistoManager::ReadParams2binfh1f(istringstream &inParams,string type, Int_t hoffset,
00770                                         const Short_t SysNum,const Bool_t BookforSys)
00771 {
00773 //     read params for 2bin histo 2binfh1f
00775 
00776     cout << "Double binned histo with fix bin width ..."<<endl;
00777     int num=0,bin=0;
00778     string name,word;
00779     string comment="no comment";
00780     string space=" ";
00781     double min=0,max=0;
00782     
00783     inParams >> num >> name  >> word;
00784     num += hoffset;
00785     if(word=="'"){
00786       word=space; 
00787       comment=space;
00788       do {
00789          comment=comment+space+word; 
00790          inParams >> word;
00791       }while(word!="'"); 
00792     }
00793    inParams  >>bin>>min>>max;
00794     cout <<num<<" "<<name<<" "<<comment<<" "<<bin<<" "<<min<<" "<<max<<endl;
00795 
00796     //--- read binned variable, number of bins, bin width
00797     Int_t nbbins,nbbins2,hnum;
00798     Double_t binwidth,bmin,bmax,offset;
00799     Double_t binwidth2,bmin2,bmax2,offset2;
00800     string binvar,binvar2;
00801     Char_t hname[100],label[200];
00802     inParams >> binvar >> nbbins >> binwidth >> offset;
00803     inParams >> binvar2 >> nbbins2 >> binwidth2 >> offset2;
00804     cout<<" "<<binvar<<" "<< nbbins<<" "<<binwidth<<endl; 
00805     cout<<" "<<binvar2<<" "<< nbbins2<<" "<<binwidth2<<endl; 
00806 
00807     sprintf(hname,"h%s%sbin%s_%s",type.c_str(),name.c_str(),binvar.c_str(),binvar2.c_str());
00808     sprintf(label,"h%s%s bin values",type.c_str(),comment.c_str());
00809     if(SysNum==0||BookforSys) {
00810         new (fHisto1D[SysNum]->AddrAt(num)) TH1F(hname,label,(nbbins+nbbins2)+3,0,(nbbins+nbbins2)+3); //histo to store min/max of bins
00811         ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(1,nbbins);
00812         ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(2,nbbins2);
00813     }
00814     hnum=num;
00815     for(Int_t i=0;i<nbbins;i++) {
00816         bmin=offset+i*binwidth;
00817         bmax=offset+(i+1)*binwidth;
00818         for(Int_t j=0;j<nbbins2;j++) {
00819           bmin2=offset2+j*binwidth2;
00820           bmax2=offset2+(j+1)*binwidth2;
00821           hnum+=1;
00822           sprintf(hname,"h%s%s%d",type.c_str(),name.c_str(),hnum-num-1);
00823           sprintf(label,"%s (%7.2f<%s<%7.2f) (%7.2f<%s<%7.2f) (%s)"
00824                        ,comment.c_str(),bmin,binvar.c_str(),bmax,bmin2,binvar2.c_str(),bmax2,type.c_str());
00825           cout << hname <<": "<< label <<endl;          
00826           if(SysNum==0||BookforSys) {
00827                 new (fHisto1D[SysNum]->AddrAt(hnum)) TH1F(hname,label,bin,min,max);
00828                 ((TH1F*)fHisto1D[SysNum]->At(hnum))->Sumw2();
00829           }
00830         }
00831         if(SysNum==0||BookforSys) {
00832                 ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(i+3,bmin);
00833                 if(i==nbbins-1) ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(i+4,bmax);
00834         }
00835     }
00836     for(Int_t j=0;j<nbbins2;j++) {
00837         bmin2=offset2+j*binwidth2;
00838         bmax2=offset2+(j+1)*binwidth2;
00839         if(SysNum==0||BookforSys) {
00840                 ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(j+nbbins+1+3,bmin2);
00841                 if(j==nbbins2-1) ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(j+nbbins+1+4,bmax2);
00842         }
00843     }
00844 }
00845 
00846 
00847 
00848 
00849 void THistoManager::ReadParams2binvh1f(istringstream &inParams,string type, Int_t hoffset,
00850                                         const Short_t SysNum,const Bool_t BookforSys)
00851 {
00853 //     read params for 2bin histo 2binvh1f variable bin width
00855 
00856     cout << "Double binned histo with variable bin width ..."<<endl;
00857     int num=0,bin=0;
00858     string name,word;
00859     string comment="no comment";
00860     string space=" ";
00861     double min=0,max=0;
00862     
00863     inParams >> num >> name  >> word;
00864     num += hoffset;
00865     if(word=="'"){
00866       word=space; 
00867       comment=space;
00868       do {
00869          comment=comment+space+word; 
00870          inParams >> word;
00871       }while(word!="'"); 
00872     }
00873     inParams  >>bin>>min>>max;
00874     cout <<num<<" "<<name<<" "<<comment<<" "<<bin<<" "<<min<<" "<<max<<endl;
00875 
00876     //--- read binned variable, number of bins, bin width
00877     Int_t nbbins,nbbins2,hnum;
00878     Double_t bmin,bmax;
00879     Double_t bmin2,bmax2;
00880     string binvar,binvar2;
00881     Char_t hname[100],label[200];
00882     inParams >> binvar >> nbbins;
00883     Float_t *bins1=new Float_t[nbbins+1];
00884     inParams >> bins1[0];
00885     for(Int_t i=0;i<nbbins;i++) inParams >> bins1[i+1];
00886     inParams >> binvar2 >> nbbins2 ;
00887     Float_t *bins2=new Float_t[nbbins2+1];
00888     inParams >> bins2[0];
00889     for(Int_t i=0;i<nbbins2;i++) inParams >> bins2[i+1];
00890 
00891     cout<<" "<<binvar<<" "<< nbbins<<endl; 
00892     cout<<" "<<binvar2<<" "<< nbbins2<<endl; 
00893 
00894     sprintf(hname,"h%s%sbin%s_%s",type.c_str(),name.c_str(),binvar.c_str(),binvar2.c_str());
00895     sprintf(label,"h%s%s bin values",type.c_str(),comment.c_str());
00896     if(SysNum==0||BookforSys) {
00897         new (fHisto1D[SysNum]->AddrAt(num)) TH1F(hname,label,(nbbins+nbbins2)+3,0,(nbbins+nbbins2)+3); //histo to store min/max of bins
00898         ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(1,nbbins);
00899         ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(2,nbbins2);
00900     }
00901     hnum=num;
00902     
00903     
00904     for(Int_t i=0;i<nbbins;i++) {
00905         bmin=bins1[i];
00906         bmax=bins1[i+1];
00907         for(Int_t j=0;j<nbbins2;j++) {
00908           bmin2=bins2[j];
00909           bmax2=bins2[j+1];
00910           hnum+=1;
00911           sprintf(hname,"h%s%s%d",type.c_str(),name.c_str(),hnum-num-1);
00912           sprintf(label,"%s (%7.2f<%s<%7.2f) (%7.2f<%s<%7.2f) (%s)"
00913                        ,comment.c_str(),bmin,binvar.c_str(),bmax,bmin2,binvar2.c_str(),bmax2,type.c_str());
00914           cout << hname <<": "<< label <<endl;          
00915           if(SysNum==0||BookforSys) {
00916                 new (fHisto1D[SysNum]->AddrAt(hnum)) TH1F(hname,label,bin,min,max);
00917                 ((TH1F*)fHisto1D[SysNum]->At(hnum))->Sumw2();
00918           }
00919         }
00920         if(SysNum==0||BookforSys) {
00921                 ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(i+3,bmin);
00922                 if(i==nbbins-1) ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(i+4,bmax);
00923         }
00924     }
00925     for(Int_t j=0;j<nbbins2;j++) {
00926         bmin2=bins2[j];
00927         bmax2=bins2[j+1];
00928         if(SysNum==0||BookforSys) {
00929                 ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(j+nbbins+1+3,bmin2);
00930                 if(j==nbbins2-1) ((TH1F*)fHisto1D[SysNum]->AddrAt(num))->SetBinContent(j+nbbins+1+4,bmax2);
00931         }
00932     }
00933 
00934 delete [] bins1;
00935 delete [] bins2;
00936 
00937 }
00938 
00939 
00940 
00941 
00942 
00943 
00944 
00945 void THistoManager::ReadParams2dbin(istringstream &inParams,string type, Int_t hoffset,const Short_t SysNum)
00946 {
00948 //     read params for 2d bin (by B.P. used in NCCC analysis 
00950     cout << "2d histo with double variable bin width ..."<<endl;
00951   
00952     int num=0;
00953     string name,word;
00954     string comment="no comment";
00955     string space=" ";
00956     
00957     inParams >> num >> name  >> word;
00958     num += hoffset;
00959     if(word=="'"){
00960       word=space; 
00961       comment=space;
00962       do {
00963          comment=comment+space+word; 
00964          inParams >> word;
00965       }while(word!="'"); 
00966     }
00967     //   inParams  >>bin>>min>>max;
00968     name="h"+type+name;
00969     cout <<num<<" "<<name<<" "<<comment<<" "<<endl;
00970 
00971     //--- read binned variable, number of bins, bin width
00972     Int_t nbbins,nbbins2;
00973     //    Double_t bmin,bmax;
00974     //   Double_t bmin2,bmax2;
00975     string binvar,binvar2;
00976 //   Char_t hname[100],label[200];
00977     inParams >> binvar >> nbbins;
00978     Float_t *bins1=new Float_t[nbbins+1];
00979     inParams >> bins1[0];
00980     for(Int_t i=0;i<nbbins;i++) inParams >> bins1[i+1];
00981     inParams >> binvar2 >> nbbins2 ;
00982     Float_t *bins2=new Float_t[nbbins2+1];
00983     inParams >> bins2[0];
00984     for(Int_t i=0;i<nbbins2;i++) inParams >> bins2[i+1];
00985 
00986     cout<<" "<<binvar<<" "<< nbbins<<endl; 
00987     for(Int_t i=0;i<nbbins+1;i++){
00988       cout << " " << bins1[i];}
00989     cout << endl;
00990     cout<<" "<<binvar2<<" "<< nbbins2<<endl; 
00991    for(Int_t i=0;i<nbbins2+1;i++){
00992       cout << " " << bins2[i];}
00993     cout << endl;
00994 // now create the histogram ...
00995     new (fHisto2D[SysNum]->AddrAt(num)) 
00996              TH2F(name.c_str(),comment.c_str(),nbbins,bins1,nbbins2,bins2);   
00997           ((TH2F*)fHisto2D[SysNum]->At(num))->Sumw2();
00998 
00999 
01000 delete [] bins1;
01001 delete [] bins2;
01002 
01003 }
01004 
01005 void THistoManager::ReadParams3dbin(istringstream &inParams,string type, Int_t hoffset,const Short_t SysNum)
01006 {
01008 //     read params for 3d bin (by B.P. used in NCCC analysis 
01010     cout << "3d histo with double variable bin width ..."<<endl;
01011   
01012     int num=0;
01013     string name,word;
01014     string comment="no comment";
01015     string space=" ";
01016     
01017     inParams >> num >> name  >> word;
01018     num += hoffset;
01019     if(word=="'"){
01020       word=space; 
01021       comment=space;
01022       do {
01023          comment=comment+space+word; 
01024          inParams >> word;
01025       }while(word!="'"); 
01026     }
01027     //   inParams  >>bin>>min>>max;
01028     name="h"+type+name;
01029     cout <<num<<" "<<name<<" "<<comment<<" "<<endl;
01030 
01031     //--- read binned variable, number of bins, bin width
01032     Int_t nbbins,nbbins2,nbbins3;
01033     //    Double_t bmin,bmax;
01034     //   Double_t bmin2,bmax2;
01035     string binvar,binvar2,binvar3;
01036 //   Char_t hname[100],label[200];
01037     inParams >> binvar >> nbbins;
01038     Float_t *bins1=new Float_t[nbbins+1];
01039     inParams >> bins1[0];
01040     for(Int_t i=0;i<nbbins;i++) inParams >> bins1[i+1];
01041 
01042     inParams >> binvar2 >> nbbins2 ;
01043     Float_t *bins2=new Float_t[nbbins2+1];
01044     inParams >> bins2[0];
01045     for(Int_t i=0;i<nbbins2;i++) inParams >> bins2[i+1];
01046 
01047     inParams >> binvar3 >> nbbins3 ;
01048     Float_t *bins3=new Float_t[nbbins3+1];
01049     inParams >> bins3[0];
01050     for(Int_t i=0;i<nbbins3;i++) inParams >> bins3[i+1];
01051 
01052 
01053     cout<<" "<<binvar<<" "<< nbbins<<endl; 
01054     for(Int_t i=0;i<nbbins+1;i++){
01055       cout << " " << bins1[i];}
01056     cout << endl;
01057     cout<<" "<<binvar2<<" "<< nbbins2<<endl; 
01058    for(Int_t i=0;i<nbbins2+1;i++){
01059       cout << " " << bins2[i];}
01060     cout << endl;
01061     cout<<" "<<binvar3<<" "<< nbbins3<<endl; 
01062    for(Int_t i=0;i<nbbins3+1;i++){
01063       cout << " " << bins3[i];}
01064 // now create the histogram ...
01065     new (fHisto3D[SysNum]->AddrAt(num)) 
01066              TH3F(name.c_str(),comment.c_str(),nbbins,bins1,nbbins2,bins2,nbbins3,bins3);   
01067           ((TH3F*)fHisto3D[SysNum]->At(num))->Sumw2();
01068 
01069 
01070 delete [] bins1;
01071 delete [] bins2;
01072 delete [] bins3;
01073 
01074 }
01075 
01076 
01077 void THistoManager::Scale1dHisto(Int_t hnum,Float_t ScaleParam,const Short_t SysNum)
01078 {
01079 // Scale 1D histogram
01080 
01081   // Get histogram number hnum
01082   TH1F *Histo = (TH1F *)fHisto1D[SysNum]->At(hnum);
01083   Histo->Scale(ScaleParam);
01084 }

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