CMS 3D CMS Logo

CSCValHists.cc

Go to the documentation of this file.
00001 #include "RecoLocalMuon/CSCValidation/src/CSCValHists.h"
00002 
00003 using namespace std;
00004 
00005 
00006   CSCValHists::CSCValHists(){
00007 
00008     cout << "Initializing Histogram Manager..." << endl;
00009 
00010   }  
00011 
00012 
00013   CSCValHists::~CSCValHists(){
00014 
00015   }
00016 
00017 
00018   void CSCValHists::writeHists(TFile* theFile){
00019 
00020     vector<string> theFolders;
00021     vector<string>::iterator fit;
00022     theFile->cd();
00023 
00024     map<string,pair<TH1*,string> >::const_iterator mapit;
00025     for (mapit = theMap.begin(); mapit != theMap.end(); mapit++){
00026       string folder = (*mapit).second.second.c_str();
00027       fit = find(theFolders.begin(), theFolders.end(), folder);
00028       if (fit == theFolders.end()){
00029         theFolders.push_back(folder);
00030         theFile->mkdir(folder.c_str());
00031       }
00032       theFile->cd((*mapit).second.second.c_str());
00033       (*mapit).second.first->Write();
00034       theFile->cd();
00035     }
00036 
00037   }
00038 
00039   
00040   void CSCValHists::writeTrees(TFile* theFile){
00041 
00042     theFile->cd("recHits");
00043     rHTree->Write();
00044     theFile->cd();
00045 
00046     theFile->cd("Segments");
00047     segTree->Write();
00048     theFile->cd();
00049 
00050 
00051   }
00052 
00053   
00054   void CSCValHists::setupTrees(){
00055 
00056     // Create the root tree to hold position info
00057     rHTree  = new TTree("rHPositions","Local and Global reconstructed positions for recHits");
00058     segTree = new TTree("segPositions","Local and Global reconstructed positions for segments");
00059 
00060     // Create a branch on the tree
00061     rHTree->Branch("rHpos",&rHpos,"endcap/I:station/I:ring/I:chamber/I:layer/I:localx/F:localy/F:globalx/F:globaly/F");
00062     segTree->Branch("segpos",&segpos,"endcap/I:station/I:ring/I:chamber/I:layer/I:localx/F:localy/F:globalx/F:globaly/F");
00063 
00064   }
00065 
00066   
00067   void CSCValHists::fillRechitTree(float x, float y, float gx, float gy, int en, int st, int ri, int ch, int la){
00068 
00069     // Fill the rechit position branch
00070     rHpos.localx  = x;
00071     rHpos.localy  = y;
00072     rHpos.globalx = gx;
00073     rHpos.globaly = gy;
00074     rHpos.endcap  = en;
00075     rHpos.ring    = ri;
00076     rHpos.station = st;
00077     rHpos.chamber = ch;
00078     rHpos.layer   = la;
00079     rHTree->Fill();
00080 
00081   }
00082   
00083   void CSCValHists::fillSegmentTree(float x, float y, float gx, float gy, int en, int st, int ri, int ch){
00084 
00085     // Fill the segment position branch
00086     segpos.localx  = x;
00087     segpos.localy  = y;
00088     segpos.globalx = gx;
00089     segpos.globaly = gy;
00090     segpos.endcap  = en;
00091     segpos.ring    = ri;
00092     segpos.station = st;
00093     segpos.chamber = ch;
00094     segpos.layer   = 0;
00095     segTree->Fill();
00096 
00097   }
00098 
00099   void CSCValHists::insertPlot(TH1* thePlot, string name, string folder){
00100 
00101     theMap[name] = pair<TH1*,string>(thePlot, folder);
00102 
00103   }
00104   
00105 
00106   void CSCValHists::fillCalibHist(float x, string name, string title, int bins, float xmin, float xmax,
00107                                   int bin, string folder){
00108 
00109     map<string,pair<TH1*,string> >::iterator it;
00110     it = theMap.find(name);
00111     if (it == theMap.end()){
00112       theMap[name] = pair<TH1*,string>(new TH1I(name.c_str(),title.c_str(),bins,xmin,xmax), folder);
00113     }
00114 
00115     theMap[name].first->SetBinContent(bin,x);
00116 
00117   }
00118 
00119 
00120   void CSCValHists::fill1DHist(float x, string name, string title,
00121                                int bins, float xmin, float xmax, string folder){
00122 
00123     map<string,pair<TH1*,string> >::iterator it;
00124     it = theMap.find(name);
00125     if (it == theMap.end()){
00126       theMap[name] = pair<TH1*,string>(new TH1I(name.c_str(),title.c_str(),bins,xmin,xmax), folder);
00127     }
00128 
00129 
00130     theMap[name].first->Fill(x);
00131 
00132   }
00133 
00134 
00135   void CSCValHists::fill2DHist(float x, float y, string name, string title,
00136                                int binsx, float xmin, float xmax,
00137                                int binsy, float ymin, float ymax, string folder){
00138 
00139     map<string,pair<TH1*,string> >::iterator it;
00140     it = theMap.find(name);
00141     if (it == theMap.end()){
00142       theMap[name] = pair<TH1*,string>(new TH2F(name.c_str(),title.c_str(),binsx,xmin,xmax,binsy,ymin,ymax),folder);
00143     }
00144 
00145     theMap[name].first->Fill(x,y);
00146 
00147   }
00148 
00149 
00150   void CSCValHists::fill1DHistByType(float x, string name, string title, CSCDetId id,
00151                                      int bins, float xmin, float xmax, string folder){
00152 
00153     string endcap;
00154     if (id.endcap() == 1) endcap = "+";
00155     if (id.endcap() == 2) endcap = "-";
00156 
00157     map<string,pair<TH1*,string> >::iterator it;
00158     ostringstream oss1;
00159     ostringstream oss2;
00160     oss1 << name << endcap << id.station() << id.ring();
00161     oss2 << title << "  (ME " << endcap << id.station() << "/" << id.ring() << ")";
00162     name = oss1.str();
00163     title = oss2.str();
00164     it = theMap.find(name);
00165     if (it == theMap.end()){
00166       theMap[name] = pair<TH1*,string>(new TH1F(name.c_str(),title.c_str(),bins,xmin,xmax), folder);
00167     }
00168 
00169     theMap[name].first->Fill(x);
00170 
00171   }
00172 
00173   void CSCValHists::fill2DHistByType(float x, float y, string name, string title, CSCDetId id,
00174                                    int binsx, float xmin, float xmax,
00175                                    int binsy, float ymin, float ymax, string folder){
00176 
00177     string endcap;
00178     if (id.endcap() == 1) endcap = "+";
00179     if (id.endcap() == 2) endcap = "-";
00180 
00181     map<string,pair<TH1*,string> >::iterator it;
00182     ostringstream oss1;
00183     ostringstream oss2;
00184     oss1 << name << endcap << id.station() << id.ring();
00185     oss2 << title << "  (ME " << endcap << id.station() << "/" << id.ring() << ")";
00186     name = oss1.str();
00187     title = oss2.str();
00188     it = theMap.find(name);
00189     if (it == theMap.end()){
00190       theMap[name] = pair<TH1*,string>(new TH2F(name.c_str(),title.c_str(),binsx,xmin,xmax,binsy,ymin,ymax), folder);
00191     }
00192 
00193     theMap[name].first->Fill(x,y);
00194 
00195   }
00196 
00197 
00198   void CSCValHists::fill2DHistByStation(float x, float y, string name, string title, CSCDetId id,
00199                                         int binsx, float xmin, float xmax,
00200                                         int binsy, float ymin, float ymax, string folder){
00201 
00202     string endcap;
00203     if (id.endcap() == 1) endcap = "+";
00204     if (id.endcap() == 2) endcap = "-";
00205 
00206     map<string,pair<TH1*,string> >::iterator it;
00207     ostringstream oss1;
00208     ostringstream oss2;
00209     oss1 << name << endcap << id.station();
00210     oss2 << title << "  (Station " << endcap << id.station() << ")";
00211     name = oss1.str();
00212     title = oss2.str();
00213     it = theMap.find(name);
00214     if (it == theMap.end()){
00215       theMap[name] = pair<TH1*,string>(new TH2F(name.c_str(),title.c_str(),binsx,xmin,xmax,binsy,ymin,ymax), folder);
00216     }
00217 
00218     theMap[name].first->Fill(x,y);
00219 
00220   }
00221 
00222 
00223   void CSCValHists::fill1DHistByChamber(float x, string name, string title, CSCDetId id,
00224                                        int bins, float xmin, float xmax, string folder){
00225 
00226     string endcap;
00227     if (id.endcap() == 1) endcap = "+";
00228     if (id.endcap() == 2) endcap = "-";
00229 
00230     map<string,pair<TH1*,string> >::iterator it;
00231     ostringstream oss1;
00232     ostringstream oss2;
00233     oss1 << name << "_" << endcap << id.station() << "_" << id.ring() << "_" << id.chamber();
00234     oss2 << title << "  (ME " << endcap << id.station() << "/" << id.ring() << "/" << id.chamber() << ")";
00235     name = oss1.str();
00236     title = oss2.str();
00237     it = theMap.find(name);
00238     if (it == theMap.end()){
00239       theMap[name] = pair<TH1*,string>(new TH1F(name.c_str(),title.c_str(),bins,xmin,xmax),folder);
00240     }
00241 
00242     theMap[name].first->Fill(x);
00243 
00244   }
00245 
00246 
00247   void CSCValHists::fill2DHistByChamber(float x, float y, string name, string title, CSCDetId id,
00248                                         int binsx, float xmin, float xmax,
00249                                         int binsy, float ymin, float ymax, string folder){
00250 
00251     string endcap;
00252     if (id.endcap() == 1) endcap = "+";
00253     if (id.endcap() == 2) endcap = "-";
00254 
00255     map<string,pair<TH1*,string> >::iterator it;
00256     ostringstream oss1;
00257     ostringstream oss2;
00258     oss1 << name << "_" << endcap << id.station() << "_" << id.ring() << "_" << id.chamber();
00259     oss2 << title << "  (ME " << endcap << id.station() << "/" << id.ring() << "/" << id.chamber() << ")";
00260     name = oss1.str();
00261     title = oss2.str();
00262     it = theMap.find(name);
00263     if (it == theMap.end()){
00264       theMap[name] = pair<TH1*,string>(new TH2F(name.c_str(),title.c_str(),binsx,xmin,xmax,binsy,ymin,ymax),folder);
00265     }
00266 
00267     theMap[name].first->Fill(x,y);
00268 
00269   }
00270 
00271   void CSCValHists::fill1DHistByLayer(float x, string name, string title, CSCDetId id,
00272                                       int bins, float xmin, float xmax, string folder){
00273 
00274     string endcap;
00275     if (id.endcap() == 1) endcap = "+";
00276     if (id.endcap() == 2) endcap = "-";
00277 
00278     map<string,pair<TH1*,string> >::iterator it;
00279     ostringstream oss1;
00280     ostringstream oss2;
00281     oss1 << name << "_" << endcap << id.station() << "_" << id.ring() << "_" << id.chamber() << "_L" << id.layer();
00282     oss2 << title << "  (ME " << endcap << id.station() << "/" << id.ring() << "/" << id.chamber() << "/L" << id.layer() << ")";
00283     name = oss1.str();
00284     title = oss2.str();
00285     it = theMap.find(name);
00286     if (it == theMap.end()){
00287       theMap[name] = pair<TH1*,string>(new TH1F(name.c_str(),title.c_str(),bins,xmin,xmax),folder);
00288     }
00289 
00290     theMap[name].first->Fill(x);
00291 
00292   }
00293 
00294 
00295   void CSCValHists::fill2DHistByLayer(float x, float y, string name, string title, CSCDetId id,
00296                                       int binsx, float xmin, float xmax,
00297                                       int binsy, float ymin, float ymax, string folder){
00298 
00299     string endcap;
00300     if (id.endcap() == 1) endcap = "+";
00301     if (id.endcap() == 2) endcap = "-";
00302 
00303     map<string,pair<TH1*,string> >::iterator it;
00304     ostringstream oss1;
00305     ostringstream oss2;
00306     oss1 << name << "_" << endcap << id.station() << "_" << id.ring() << "_" << id.chamber() << "_L" << id.layer();;
00307     oss2 << title << "  (ME " << endcap << id.station() << "/" << id.ring() << "/" << id.chamber() << "/L" << id.layer() << ")";
00308     name = oss1.str();
00309     title = oss2.str();
00310     it = theMap.find(name);
00311     if (it == theMap.end()){
00312       theMap[name] = pair<TH1*,string>(new TH2F(name.c_str(),title.c_str(),binsx,xmin,xmax,binsy,ymin,ymax),folder);
00313     }
00314 
00315     theMap[name].first->Fill(x,y);
00316 
00317   }
00318 
00319 
00320   void CSCValHists::fillProfile(float x, float y, string name, string title,
00321                                 int binsx, float xmin, float xmax,
00322                                 float ymin, float ymax, string folder){
00323 
00324     map<string,pair<TH1*,string> >::iterator it;
00325     it = theMap.find(name);
00326     if (it == theMap.end()){
00327       theMap[name] = pair<TProfile*,string>(new TProfile(name.c_str(),title.c_str(),binsx,xmin,xmax,ymin,ymax), folder);
00328     }
00329 
00330     theMap[name].first->Fill(x,y);
00331 
00332   }
00333 
00334 
00335   void CSCValHists::fillProfileByType(float x, float y, string name, string title, CSCDetId id,
00336                                       int binsx, float xmin, float xmax,
00337                                       float ymin, float ymax, string folder){
00338 
00339     map<string,pair<TH1*,string> >::iterator it;
00340     string endcap;
00341     if (id.endcap() == 1) endcap = "+";
00342     if (id.endcap() == 2) endcap = "-";
00343 
00344     ostringstream oss1;
00345     ostringstream oss2;
00346     oss1 << name << endcap << id.station() << id.ring();
00347     oss2 << title << "  (ME " << endcap << id.station() << "/" << id.ring() << ")";
00348     name = oss1.str();
00349     title = oss2.str();
00350 
00351     it = theMap.find(name);
00352     if (it == theMap.end()){
00353       theMap[name] = pair<TProfile*,string>(new TProfile(name.c_str(),title.c_str(),binsx,xmin,xmax,ymin,ymax), folder);
00354     }
00355 
00356     theMap[name].first->Fill(x,y);
00357 
00358   }
00359 
00360 
00361   void CSCValHists::fillProfileByChamber(float x, float y, string name, string title, CSCDetId id,
00362                                          int binsx, float xmin, float xmax,
00363                                          float ymin, float ymax, string folder){
00364 
00365     map<string,pair<TH1*,string> >::iterator it;
00366     string endcap;
00367     if (id.endcap() == 1) endcap = "+";
00368     if (id.endcap() == 2) endcap = "-";
00369 
00370     ostringstream oss1;
00371     ostringstream oss2;
00372     oss1 << name << "_" << endcap << id.station() << "_" << id.ring() << "_" << id.chamber();
00373     oss2 << title << "  (ME " << endcap << id.station() << "/" << id.ring() << "/" << id.chamber() << ")";
00374     name = oss1.str();
00375     title = oss2.str();
00376 
00377     it = theMap.find(name);
00378     if (it == theMap.end()){
00379       theMap[name] = pair<TProfile*,string>(new TProfile(name.c_str(),title.c_str(),binsx,xmin,xmax,ymin,ymax), folder);
00380     }
00381 
00382     theMap[name].first->Fill(x,y);
00383 
00384   }
00385 
00386 
00387   void CSCValHists::fill2DProfile(float x, float y, float z, string name, string title,
00388                                   int binsx, float xmin, float xmax,
00389                                   int binsy, float ymin, float ymax,
00390                                   float zmin, float zmax, string folder){
00391 
00392     map<string,pair<TH1*,string> >::iterator it;
00393 
00394     it = theMap.find(name);
00395     if (it == theMap.end()){
00396       theMap[name] = pair<TProfile2D*,string>(new TProfile2D(name.c_str(),title.c_str(),binsx,xmin,xmax,binsy,ymin,ymax,zmin,zmax), folder);
00397     }
00398 
00399     TProfile2D *tempp = (TProfile2D*)theMap[name].first;
00400     tempp->Fill(x,y,z);
00401 
00402   }
00403 

Generated on Tue Jun 9 17:43:52 2009 for CMSSW by  doxygen 1.5.4