Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:00:21

0001 #include "RecoLocalMuon/CSCValidation/src/CSCValHists.h"
0002 #include <algorithm>
0003 
0004 using namespace std;
0005 
0006 CSCValHists::CSCValHists() { std::cout << "Initializing Histogram Manager..." << std::endl; }
0007 
0008 CSCValHists::~CSCValHists() {}
0009 
0010 void CSCValHists::writeHists(TFile* theFile) {
0011   std::vector<std::string> theFolders;
0012   std::vector<std::string>::iterator fit;
0013   theFile->cd();
0014 
0015   std::map<std::string, std::pair<TH1*, string> >::const_iterator mapit;
0016   for (mapit = theMap.begin(); mapit != theMap.end(); mapit++) {
0017     std::string folder = (*mapit).second.second;
0018     fit = find(theFolders.begin(), theFolders.end(), folder);
0019     if (fit == theFolders.end()) {
0020       theFolders.push_back(folder);
0021       theFile->mkdir(folder.c_str());
0022     }
0023     theFile->cd((*mapit).second.second.c_str());
0024     (*mapit).second.first->Write();
0025     theFile->cd();
0026   }
0027 }
0028 
0029 void CSCValHists::writeTrees(TFile* theFile) {
0030   theFile->cd("recHits");
0031   rHTree->Write();
0032   theFile->cd();
0033 
0034   theFile->cd("Segments");
0035   segTree->Write();
0036   theFile->cd();
0037 }
0038 
0039 void CSCValHists::setupTrees() {
0040   // Create the root tree to hold position info
0041   rHTree = new TTree("rHPositions", "Local and Global reconstructed positions for recHits");
0042   segTree = new TTree("segPositions", "Local and Global reconstructed positions for segments");
0043 
0044   // Create a branch on the tree
0045   rHTree->Branch("rHpos", &rHpos, "endcap/I:station/I:ring/I:chamber/I:layer/I:localx/F:localy/F:globalx/F:globaly/F");
0046   segTree->Branch(
0047       "segpos", &segpos, "endcap/I:station/I:ring/I:chamber/I:layer/I:localx/F:localy/F:globalx/F:globaly/F");
0048 }
0049 
0050 void CSCValHists::fillRechitTree(float x, float y, float gx, float gy, int en, int st, int ri, int ch, int la) {
0051   // Fill the rechit position branch
0052   rHpos.localx = x;
0053   rHpos.localy = y;
0054   rHpos.globalx = gx;
0055   rHpos.globaly = gy;
0056   rHpos.endcap = en;
0057   rHpos.ring = ri;
0058   rHpos.station = st;
0059   rHpos.chamber = ch;
0060   rHpos.layer = la;
0061   rHTree->Fill();
0062 }
0063 
0064 void CSCValHists::fillSegmentTree(float x, float y, float gx, float gy, int en, int st, int ri, int ch) {
0065   // Fill the segment position branch
0066   segpos.localx = x;
0067   segpos.localy = y;
0068   segpos.globalx = gx;
0069   segpos.globaly = gy;
0070   segpos.endcap = en;
0071   segpos.ring = ri;
0072   segpos.station = st;
0073   segpos.chamber = ch;
0074   segpos.layer = 0;
0075   segTree->Fill();
0076 }
0077 
0078 void CSCValHists::insertPlot(TH1* thePlot, std::string name, std::string folder) {
0079   theMap[name] = std::pair<TH1*, string>(thePlot, folder);
0080 }
0081 
0082 void CSCValHists::fillCalibHist(
0083     float x, std::string name, std::string title, int bins, float xmin, float xmax, int bin, std::string folder) {
0084   std::map<std::string, std::pair<TH1*, string> >::iterator it;
0085   it = theMap.find(name);
0086   if (it == theMap.end()) {
0087     theMap[name] = std::pair<TH1*, string>(new TH1I(name.c_str(), title.c_str(), bins, xmin, xmax), folder);
0088   }
0089 
0090   theMap[name].first->SetBinContent(bin, x);
0091 }
0092 
0093 void CSCValHists::fill1DHist(
0094     float x, std::string name, std::string title, int bins, float xmin, float xmax, std::string folder) {
0095   std::map<std::string, std::pair<TH1*, string> >::iterator it;
0096   it = theMap.find(name);
0097   if (it == theMap.end()) {
0098     theMap[name] = std::pair<TH1*, string>(new TH1I(name.c_str(), title.c_str(), bins, xmin, xmax), folder);
0099   }
0100 
0101   theMap[name].first->Fill(x);
0102 }
0103 
0104 void CSCValHists::fill2DHist(float x,
0105                              float y,
0106                              std::string name,
0107                              std::string title,
0108                              int binsx,
0109                              float xmin,
0110                              float xmax,
0111                              int binsy,
0112                              float ymin,
0113                              float ymax,
0114                              std::string folder) {
0115   std::map<std::string, std::pair<TH1*, string> >::iterator it;
0116   it = theMap.find(name);
0117   if (it == theMap.end()) {
0118     theMap[name] =
0119         std::pair<TH1*, string>(new TH2F(name.c_str(), title.c_str(), binsx, xmin, xmax, binsy, ymin, ymax), folder);
0120   }
0121 
0122   theMap[name].first->Fill(x, y);
0123 }
0124 
0125 void CSCValHists::fill1DHistByType(
0126     float x, std::string name, std::string title, CSCDetId id, int bins, float xmin, float xmax, std::string folder) {
0127   std::string endcap;
0128   if (id.endcap() == 1)
0129     endcap = "+";
0130   if (id.endcap() == 2)
0131     endcap = "-";
0132 
0133   std::map<std::string, std::pair<TH1*, string> >::iterator it;
0134   ostringstream oss1;
0135   ostringstream oss2;
0136   oss1 << name << endcap << id.station() << id.ring();
0137   oss2 << title << "  (ME " << endcap << id.station() << "/" << id.ring() << ")";
0138   name = oss1.str();
0139   title = oss2.str();
0140   it = theMap.find(name);
0141   if (it == theMap.end()) {
0142     theMap[name] = std::pair<TH1*, string>(new TH1F(name.c_str(), title.c_str(), bins, xmin, xmax), folder);
0143   }
0144 
0145   theMap[name].first->Fill(x);
0146 }
0147 
0148 void CSCValHists::fill2DHistByType(float x,
0149                                    float y,
0150                                    std::string name,
0151                                    std::string title,
0152                                    CSCDetId id,
0153                                    int binsx,
0154                                    float xmin,
0155                                    float xmax,
0156                                    int binsy,
0157                                    float ymin,
0158                                    float ymax,
0159                                    std::string folder) {
0160   std::string endcap;
0161   if (id.endcap() == 1)
0162     endcap = "+";
0163   if (id.endcap() == 2)
0164     endcap = "-";
0165 
0166   std::map<std::string, std::pair<TH1*, string> >::iterator it;
0167   ostringstream oss1;
0168   ostringstream oss2;
0169   oss1 << name << endcap << id.station() << id.ring();
0170   oss2 << title << "  (ME " << endcap << id.station() << "/" << id.ring() << ")";
0171   name = oss1.str();
0172   title = oss2.str();
0173   it = theMap.find(name);
0174   if (it == theMap.end()) {
0175     theMap[name] =
0176         std::pair<TH1*, string>(new TH2F(name.c_str(), title.c_str(), binsx, xmin, xmax, binsy, ymin, ymax), folder);
0177   }
0178 
0179   theMap[name].first->Fill(x, y);
0180 }
0181 
0182 void CSCValHists::fill1DHistByCrate(
0183     float x, string name, string title, CSCDetId id, int bins, float xmin, float xmax, string folder) {
0184   int crate = crate_lookup(id);
0185 
0186   map<string, pair<TH1*, string> >::iterator it;
0187   ostringstream oss1;
0188   ostringstream oss2;
0189   oss1 << name << "_crate_" << crate;
0190   oss2 << title << "  (crate " << crate << ")";
0191   name = oss1.str();
0192   title = oss2.str();
0193   it = theMap.find(name);
0194   if (it == theMap.end()) {
0195     theMap[name] = pair<TH1*, string>(new TH1F(name.c_str(), title.c_str(), bins, xmin, xmax), folder);
0196   }
0197 
0198   theMap[name].first->Fill(x);
0199 }
0200 
0201 void CSCValHists::fill2DHistByCrate(float x,
0202                                     float y,
0203                                     string name,
0204                                     string title,
0205                                     CSCDetId id,
0206                                     int binsx,
0207                                     float xmin,
0208                                     float xmax,
0209                                     int binsy,
0210                                     float ymin,
0211                                     float ymax,
0212                                     string folder) {
0213   int crate = crate_lookup(id);
0214 
0215   map<string, pair<TH1*, string> >::iterator it;
0216   ostringstream oss1;
0217   ostringstream oss2;
0218   oss1 << name << "_crate_" << crate;
0219   oss2 << title << "  (crate " << crate << ")";
0220   name = oss1.str();
0221   title = oss2.str();
0222   it = theMap.find(name);
0223   if (it == theMap.end()) {
0224     theMap[name] =
0225         pair<TH1*, string>(new TH2F(name.c_str(), title.c_str(), binsx, xmin, xmax, binsy, ymin, ymax), folder);
0226   }
0227 
0228   theMap[name].first->Fill(x, y);
0229 }
0230 
0231 void CSCValHists::fill1DHistByStation(
0232     float x, string name, string title, CSCDetId id, int bins, float xmin, float xmax, string folder) {
0233   string endcap;
0234   if (id.endcap() == 1)
0235     endcap = "+";
0236   if (id.endcap() == 2)
0237     endcap = "-";
0238 
0239   map<string, pair<TH1*, string> >::iterator it;
0240   ostringstream oss1;
0241   ostringstream oss2;
0242   oss1 << name << endcap << id.station();
0243   oss2 << title << "  (Station " << endcap << id.station() << ")";
0244   name = oss1.str();
0245   title = oss2.str();
0246   it = theMap.find(name);
0247   if (it == theMap.end()) {
0248     theMap[name] = pair<TH1*, string>(new TH1F(name.c_str(), title.c_str(), bins, xmin, xmax), folder);
0249   }
0250 
0251   theMap[name].first->Fill(x);
0252 }
0253 
0254 void CSCValHists::fill2DHistByStation(float x,
0255                                       float y,
0256                                       string name,
0257                                       string title,
0258                                       CSCDetId id,
0259                                       int binsx,
0260                                       float xmin,
0261                                       float xmax,
0262                                       int binsy,
0263                                       float ymin,
0264                                       float ymax,
0265                                       std::string folder) {
0266   std::string endcap;
0267   if (id.endcap() == 1)
0268     endcap = "+";
0269   if (id.endcap() == 2)
0270     endcap = "-";
0271 
0272   std::map<std::string, std::pair<TH1*, string> >::iterator it;
0273   ostringstream oss1;
0274   ostringstream oss2;
0275   oss1 << name << endcap << id.station();
0276   oss2 << title << "  (Station " << endcap << id.station() << ")";
0277   name = oss1.str();
0278   title = oss2.str();
0279   it = theMap.find(name);
0280   if (it == theMap.end()) {
0281     theMap[name] =
0282         std::pair<TH1*, string>(new TH2F(name.c_str(), title.c_str(), binsx, xmin, xmax, binsy, ymin, ymax), folder);
0283   }
0284 
0285   theMap[name].first->Fill(x, y);
0286 }
0287 
0288 void CSCValHists::fill1DHistByChamber(
0289     float x, std::string name, std::string title, CSCDetId id, int bins, float xmin, float xmax, std::string folder) {
0290   std::string endcap;
0291   if (id.endcap() == 1)
0292     endcap = "+";
0293   if (id.endcap() == 2)
0294     endcap = "-";
0295 
0296   std::map<std::string, std::pair<TH1*, string> >::iterator it;
0297   ostringstream oss1;
0298   ostringstream oss2;
0299   oss1 << name << "_" << endcap << id.station() << "_" << id.ring() << "_" << id.chamber();
0300   oss2 << title << "  (ME " << endcap << id.station() << "/" << id.ring() << "/" << id.chamber() << ")";
0301   name = oss1.str();
0302   title = oss2.str();
0303   it = theMap.find(name);
0304   if (it == theMap.end()) {
0305     theMap[name] = std::pair<TH1*, string>(new TH1F(name.c_str(), title.c_str(), bins, xmin, xmax), folder);
0306   }
0307 
0308   theMap[name].first->Fill(x);
0309 }
0310 
0311 void CSCValHists::fill2DHistByChamber(float x,
0312                                       float y,
0313                                       std::string name,
0314                                       std::string title,
0315                                       CSCDetId id,
0316                                       int binsx,
0317                                       float xmin,
0318                                       float xmax,
0319                                       int binsy,
0320                                       float ymin,
0321                                       float ymax,
0322                                       std::string folder) {
0323   std::string endcap;
0324   if (id.endcap() == 1)
0325     endcap = "+";
0326   if (id.endcap() == 2)
0327     endcap = "-";
0328 
0329   std::map<std::string, std::pair<TH1*, string> >::iterator it;
0330   ostringstream oss1;
0331   ostringstream oss2;
0332   oss1 << name << "_" << endcap << id.station() << "_" << id.ring() << "_" << id.chamber();
0333   oss2 << title << "  (ME " << endcap << id.station() << "/" << id.ring() << "/" << id.chamber() << ")";
0334   name = oss1.str();
0335   title = oss2.str();
0336   it = theMap.find(name);
0337   if (it == theMap.end()) {
0338     theMap[name] =
0339         std::pair<TH1*, string>(new TH2F(name.c_str(), title.c_str(), binsx, xmin, xmax, binsy, ymin, ymax), folder);
0340   }
0341 
0342   theMap[name].first->Fill(x, y);
0343 }
0344 
0345 void CSCValHists::fill2DHistByEvent(int run, int event, float z, string name, string title, CSCDetId id, string folder) {
0346   string endcap;
0347   if (id.endcap() == 1)
0348     endcap = "+";
0349   if (id.endcap() == 2)
0350     endcap = "-";
0351 
0352   map<string, pair<TH1*, string> >::iterator it;
0353   ostringstream oss1;
0354   ostringstream oss2;
0355   oss1 << name << "_" << run << "_" << event;
0356   oss2 << title << "  ( Run: " << run << " Event: " << event << " )";
0357   name = oss1.str();
0358   title = oss2.str();
0359   it = theMap.find(name);
0360   if (it == theMap.end()) {
0361     theMap[name] = pair<TH1*, string>(new TH2F(name.c_str(), title.c_str(), 36, 0.5, 36.5, 18, 0.5, 18.5), folder);
0362   }
0363 
0364   int x = id.chamber();
0365   int y = id.ring();
0366   if (y == 4)
0367     y = 1;  //collapsing ME1/1a into ME1/1
0368   if (id.station() > 1)
0369     y = y + 3 + (id.station() - 2) * 2;
0370 
0371   if (id.endcap() == 1)
0372     y = y + 9;
0373   else
0374     y = -1 * y + 10;
0375 
0376   dynamic_cast<TH2F*>(theMap[name].first)->Fill(x, y, z);
0377 }
0378 
0379 void CSCValHists::fill2DHist(float z, string name, string title, CSCDetId id, string folder) {
0380   map<string, pair<TH1*, string> >::iterator it;
0381   it = theMap.find(name);
0382   if (it == theMap.end()) {
0383     theMap[name] = pair<TH1*, string>(new TH2F(name.c_str(), title.c_str(), 36, 0.5, 36.5, 18, 0.5, 18.5), folder);
0384   }
0385 
0386   int x = id.chamber();
0387   int y = id.ring();
0388   if (y == 4)
0389     y = 1;  //collapsing ME1/1a into ME1/1
0390   if (id.station() > 1)
0391     y = y + 3 + (id.station() - 2) * 2;
0392 
0393   if (id.endcap() == 1)
0394     y = y + 9;
0395   else
0396     y = -1 * y + 10;
0397 
0398   dynamic_cast<TH2F*>(theMap[name].first)->Fill(x, y, z);
0399 }
0400 
0401 void CSCValHists::fill1DHistByLayer(
0402     float x, string name, string title, CSCDetId id, int bins, float xmin, float xmax, string folder) {
0403   std::string endcap;
0404   if (id.endcap() == 1)
0405     endcap = "+";
0406   if (id.endcap() == 2)
0407     endcap = "-";
0408 
0409   std::map<std::string, std::pair<TH1*, string> >::iterator it;
0410   ostringstream oss1;
0411   ostringstream oss2;
0412   oss1 << name << "_" << endcap << id.station() << "_" << id.ring() << "_" << id.chamber() << "_L" << id.layer();
0413   oss2 << title << "  (ME " << endcap << id.station() << "/" << id.ring() << "/" << id.chamber() << "/L" << id.layer()
0414        << ")";
0415   name = oss1.str();
0416   title = oss2.str();
0417   it = theMap.find(name);
0418   if (it == theMap.end()) {
0419     theMap[name] = std::pair<TH1*, string>(new TH1F(name.c_str(), title.c_str(), bins, xmin, xmax), folder);
0420   }
0421 
0422   theMap[name].first->Fill(x);
0423 }
0424 
0425 void CSCValHists::fill2DHistByLayer(float x,
0426                                     float y,
0427                                     std::string name,
0428                                     std::string title,
0429                                     CSCDetId id,
0430                                     int binsx,
0431                                     float xmin,
0432                                     float xmax,
0433                                     int binsy,
0434                                     float ymin,
0435                                     float ymax,
0436                                     std::string folder) {
0437   std::string endcap;
0438   if (id.endcap() == 1)
0439     endcap = "+";
0440   if (id.endcap() == 2)
0441     endcap = "-";
0442 
0443   std::map<std::string, std::pair<TH1*, string> >::iterator it;
0444   ostringstream oss1;
0445   ostringstream oss2;
0446   oss1 << name << "_" << endcap << id.station() << "_" << id.ring() << "_" << id.chamber() << "_L" << id.layer();
0447   ;
0448   oss2 << title << "  (ME " << endcap << id.station() << "/" << id.ring() << "/" << id.chamber() << "/L" << id.layer()
0449        << ")";
0450   name = oss1.str();
0451   title = oss2.str();
0452   it = theMap.find(name);
0453   if (it == theMap.end()) {
0454     theMap[name] =
0455         std::pair<TH1*, string>(new TH2F(name.c_str(), title.c_str(), binsx, xmin, xmax, binsy, ymin, ymax), folder);
0456   }
0457 
0458   theMap[name].first->Fill(x, y);
0459 }
0460 
0461 void CSCValHists::fillProfile(float x,
0462                               float y,
0463                               std::string name,
0464                               std::string title,
0465                               int binsx,
0466                               float xmin,
0467                               float xmax,
0468                               float ymin,
0469                               float ymax,
0470                               std::string folder) {
0471   std::map<std::string, std::pair<TH1*, string> >::iterator it;
0472   it = theMap.find(name);
0473   if (it == theMap.end()) {
0474     theMap[name] =
0475         std::pair<TProfile*, string>(new TProfile(name.c_str(), title.c_str(), binsx, xmin, xmax, ymin, ymax), folder);
0476   }
0477 
0478   theMap[name].first->Fill(x, y);
0479 }
0480 
0481 void CSCValHists::fillProfileByType(float x,
0482                                     float y,
0483                                     std::string name,
0484                                     std::string title,
0485                                     CSCDetId id,
0486                                     int binsx,
0487                                     float xmin,
0488                                     float xmax,
0489                                     float ymin,
0490                                     float ymax,
0491                                     std::string folder) {
0492   std::map<std::string, std::pair<TH1*, string> >::iterator it;
0493   std::string endcap;
0494   if (id.endcap() == 1)
0495     endcap = "+";
0496   if (id.endcap() == 2)
0497     endcap = "-";
0498 
0499   ostringstream oss1;
0500   ostringstream oss2;
0501   oss1 << name << endcap << id.station() << id.ring();
0502   oss2 << title << "  (ME " << endcap << id.station() << "/" << id.ring() << ")";
0503   name = oss1.str();
0504   title = oss2.str();
0505 
0506   it = theMap.find(name);
0507   if (it == theMap.end()) {
0508     theMap[name] =
0509         std::pair<TProfile*, string>(new TProfile(name.c_str(), title.c_str(), binsx, xmin, xmax, ymin, ymax), folder);
0510   }
0511 
0512   theMap[name].first->Fill(x, y);
0513 }
0514 
0515 void CSCValHists::fillProfileByChamber(float x,
0516                                        float y,
0517                                        std::string name,
0518                                        std::string title,
0519                                        CSCDetId id,
0520                                        int binsx,
0521                                        float xmin,
0522                                        float xmax,
0523                                        float ymin,
0524                                        float ymax,
0525                                        std::string folder) {
0526   std::map<std::string, std::pair<TH1*, string> >::iterator it;
0527   std::string endcap;
0528   if (id.endcap() == 1)
0529     endcap = "+";
0530   if (id.endcap() == 2)
0531     endcap = "-";
0532 
0533   ostringstream oss1;
0534   ostringstream oss2;
0535   oss1 << name << "_" << endcap << id.station() << "_" << id.ring() << "_" << id.chamber();
0536   oss2 << title << "  (ME " << endcap << id.station() << "/" << id.ring() << "/" << id.chamber() << ")";
0537   name = oss1.str();
0538   title = oss2.str();
0539 
0540   it = theMap.find(name);
0541   if (it == theMap.end()) {
0542     theMap[name] =
0543         std::pair<TProfile*, string>(new TProfile(name.c_str(), title.c_str(), binsx, xmin, xmax, ymin, ymax), folder);
0544   }
0545 
0546   theMap[name].first->Fill(x, y);
0547 }
0548 
0549 void CSCValHists::fill2DProfile(float x,
0550                                 float y,
0551                                 float z,
0552                                 std::string name,
0553                                 std::string title,
0554                                 int binsx,
0555                                 float xmin,
0556                                 float xmax,
0557                                 int binsy,
0558                                 float ymin,
0559                                 float ymax,
0560                                 float zmin,
0561                                 float zmax,
0562                                 std::string folder) {
0563   std::map<std::string, std::pair<TH1*, string> >::iterator it;
0564 
0565   it = theMap.find(name);
0566   if (it == theMap.end()) {
0567     theMap[name] = std::pair<TProfile2D*, string>(
0568         new TProfile2D(name.c_str(), title.c_str(), binsx, xmin, xmax, binsy, ymin, ymax, zmin, zmax), folder);
0569   }
0570 
0571   TProfile2D* tempp = (TProfile2D*)theMap[name].first;
0572   tempp->Fill(x, y, z);
0573 }
0574 
0575 int CSCValHists::crate_lookup(CSCDetId id) {
0576   int crate = 0;
0577 
0578   if (id.station() == 1) {
0579     if (id.chamber() == 36 || id.chamber() == 1 || id.chamber() == 2)
0580       crate = 1;
0581     if (id.chamber() == 3 || id.chamber() == 4 || id.chamber() == 5)
0582       crate = 2;
0583     if (id.chamber() == 6 || id.chamber() == 7 || id.chamber() == 8)
0584       crate = 3;
0585     if (id.chamber() == 9 || id.chamber() == 10 || id.chamber() == 11)
0586       crate = 4;
0587     if (id.chamber() == 12 || id.chamber() == 13 || id.chamber() == 14)
0588       crate = 5;
0589     if (id.chamber() == 15 || id.chamber() == 16 || id.chamber() == 17)
0590       crate = 6;
0591     if (id.chamber() == 18 || id.chamber() == 19 || id.chamber() == 20)
0592       crate = 7;
0593     if (id.chamber() == 21 || id.chamber() == 22 || id.chamber() == 23)
0594       crate = 8;
0595     if (id.chamber() == 24 || id.chamber() == 25 || id.chamber() == 26)
0596       crate = 9;
0597     if (id.chamber() == 27 || id.chamber() == 28 || id.chamber() == 29)
0598       crate = 10;
0599     if (id.chamber() == 30 || id.chamber() == 31 || id.chamber() == 32)
0600       crate = 11;
0601     if (id.chamber() == 33 || id.chamber() == 34 || id.chamber() == 35)
0602       crate = 12;
0603   } else {
0604     crate = 12 + id.triggerSector() + (id.station() - 2) * 6;
0605   }
0606 
0607   if (id.endcap() == 2)
0608     crate = crate + 30;
0609 
0610   return crate;
0611 }