Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:08:12

0001 #ifndef rpcdqm_utils_H
0002 #define rpcdqm_utils_H
0003 
0004 #include "DataFormats/MuonDetId/interface/RPCDetId.h"
0005 #include "DQMServices/Core/interface/DQMStore.h"
0006 
0007 #include <vector>
0008 #include <iomanip>
0009 #include <string>
0010 
0011 namespace rpcdqm {
0012   using dqm::reco::DQMStore;
0013   using dqm::reco::MonitorElement;
0014 
0015   enum RPCMeFLag { OCCUPANCY = 1, CLUSTERSIZE = 2, MULTIPLICITY = 3, BX = 4 };
0016 
0017   struct RPCMEHelper {
0018     static void setNoAlphanumeric(MonitorElement* myMe) {
0019       // Set no-alphanumeric flag to avoid malfunctioning in multithread environment.
0020       TH2* h2 = dynamic_cast<TH2*>(myMe->getTH1());
0021       if (!h2)
0022         return;
0023 
0024       h2->GetXaxis()->SetNoAlphanumeric(true);
0025       h2->GetYaxis()->SetNoAlphanumeric(true);
0026     }
0027   };
0028 
0029   class utils {
0030   public:
0031     int detId2RollNr(const RPCDetId& _id) {
0032       if (_id.region() == 0) {     //Barrel
0033         if (_id.station() == 1) {  // Station1
0034           if (_id.layer() == 1) {  //in
0035             if (_id.roll() == 1)   //forward
0036               _cnr = 1;            //RB1inF
0037             else                   //backward
0038               _cnr = 2;            //RB1inB
0039           } else {                 //out
0040             if (_id.roll() == 1)
0041               _cnr = 3;  //RB1outF
0042             else
0043               _cnr = 4;  //RB1outB
0044           }
0045         } else if (_id.station() == 2) {  //Station 2
0046           if (_id.layer() == 1) {
0047             if (_id.roll() == 1)
0048               _cnr = 5;  //RB2inB
0049             else if (_id.roll() == 3)
0050               _cnr = 6;  //RB2inF
0051             else if (_id.roll() == 2)
0052               _cnr = 7;  //RB2inM
0053           } else {
0054             if (_id.roll() == 2)
0055               _cnr = 7;  //RB2outM
0056             else if (_id.roll() == 1)
0057               _cnr = 8;  //RB2outB
0058             else if (_id.roll() == 3)
0059               _cnr = 9;  //RB2outF
0060           }
0061         } else if (_id.station() == 3) {  //Station 3
0062           if (_id.subsector() == 1) {
0063             if (_id.roll() == 1)
0064               _cnr = 10;  //RB3-B
0065             else
0066               _cnr = 11;  //RB3-F
0067           } else {
0068             if (_id.roll() == 1)
0069               _cnr = 12;  //RB3+B
0070             else
0071               _cnr = 13;  //RB3+F
0072           }
0073         } else if (_id.station() == 4) {  //Station 4
0074           if (_id.sector() == 4) {
0075             if (_id.subsector() == 2) {  //RB4--
0076               if (_id.roll() == 1)
0077                 _cnr = 14;
0078               else
0079                 _cnr = 15;
0080             } else if (_id.subsector() == 3) {  //RB4-
0081               if (_id.roll() == 1)
0082                 _cnr = 16;
0083               else
0084                 _cnr = 17;
0085             } else if (_id.subsector() == 1) {  //RB4+
0086               if (_id.roll() == 1)
0087                 _cnr = 18;
0088               else
0089                 _cnr = 19;
0090             } else if (_id.subsector() == 4) {  //RB4++
0091               if (_id.roll() == 1)
0092                 _cnr = 20;
0093               else
0094                 _cnr = 21;
0095             }
0096           } else {
0097             if (_id.subsector() == 1) {
0098               if (_id.roll() == 1)
0099                 _cnr = 14;
0100               else
0101                 _cnr = 15;
0102             } else {
0103               if (_id.roll() == 1)
0104                 _cnr = 16;
0105               else
0106                 _cnr = 17;
0107             }
0108           }
0109         }
0110       } else {  //Endcap
0111         int nsub = 6;
0112         if (_id.ring() == 1 && _id.station() > 1) {
0113           nsub = 3;
0114         }
0115         _cnr = (_id.subsector() - 1) * 3 + _id.roll() + (_id.ring() - 1) * nsub * 3;
0116       }
0117       return _cnr;
0118     }
0119 
0120     void fillvect() {
0121       Wvector2.push_back(0);     //Sec 0 - doen't exist ;)
0122       Wvector2.push_back(1140);  //Sec1
0123       Wvector2.push_back(1140);  //Sec2
0124       Wvector2.push_back(1140);  //Sec3
0125       Wvector2.push_back(1236);  //Sec4
0126       Wvector2.push_back(1140);  //Sec5
0127       Wvector2.push_back(1140);  //Sec6
0128       Wvector2.push_back(1140);  //Sec7
0129       Wvector2.push_back(1116);  //Sec8
0130       Wvector2.push_back(1044);  //Sec9
0131       Wvector2.push_back(1188);  //Sec10
0132       Wvector2.push_back(1044);  //Sec11
0133       Wvector2.push_back(1166);  //Sec12
0134 
0135       Wvector1.push_back(0);     //Sec 0 - doen't exist ;)
0136       Wvector1.push_back(1146);  //Sec1
0137       Wvector1.push_back(1146);  //Sec2
0138       Wvector1.push_back(1146);  //Sec3
0139       Wvector1.push_back(1242);  //Sec4
0140       Wvector1.push_back(1146);  //Sec5
0141       Wvector1.push_back(1146);  //Sec6
0142       Wvector1.push_back(1146);  //Sec7
0143       Wvector1.push_back(1122);  //Sec8
0144       Wvector1.push_back(1050);  //Sec9
0145       Wvector1.push_back(1194);  //Sec10
0146       Wvector1.push_back(1050);  //Sec11
0147       Wvector1.push_back(1122);  //Sec12
0148     }
0149 
0150     std::vector<int> SectorStrips2() { return Wvector2; }
0151 
0152     std::vector<int> SectorStrips1() { return Wvector1; }
0153 
0154     void dolabeling(bool useRollInfo) {
0155       if (useRollInfo) {
0156         ylabel[1] = "RB1in_B";
0157         ylabel[2] = "RB1in_F";
0158         ylabel[3] = "RB1out_B";
0159         ylabel[4] = "RB1out_F";
0160         ylabel[5] = "RB2in_B";
0161         ylabel[6] = "RB2in_F";
0162 
0163         ylabel[7] = "RB2in_M";
0164         ylabel[0] = "RB2out_M";
0165 
0166         ylabel[8] = "RB2out_B";
0167         ylabel[9] = "RB2out_F";
0168         ylabel[10] = "RB3-_B";
0169         ylabel[11] = "RB3-_F";
0170         ylabel[12] = "RB3+_B";
0171         ylabel[13] = "RB3+_F";
0172         ylabel[14] = "RB4,-_B";
0173         ylabel[15] = "RB4,-_F";
0174         ylabel[16] = "RB4+_B";
0175         ylabel[17] = "RB4+_F";
0176         ylabel[18] = "RB4--_B";
0177         ylabel[19] = "RB4--_F";
0178         ylabel[20] = "RB4++_B";
0179         ylabel[21] = "RB4++_F";
0180       } else {
0181         ylabel[1] = "RB1in";
0182         ylabel[2] = "";
0183         ylabel[3] = "RB1out";
0184         ylabel[4] = "";
0185         ylabel[5] = "RB2in";
0186         ylabel[6] = "";
0187 
0188         ylabel[7] = "";
0189         ylabel[0] = "";
0190 
0191         ylabel[8] = "RB2out";
0192         ylabel[9] = "";
0193         ylabel[10] = "RB3-";
0194         ylabel[11] = "";
0195         ylabel[12] = "RB3+";
0196         ylabel[13] = "";
0197         ylabel[14] = "RB4,-";
0198         ylabel[15] = "";
0199         ylabel[16] = "RB4+";
0200         ylabel[17] = "";
0201         ylabel[18] = "RB4--";
0202         ylabel[19] = "";
0203         ylabel[20] = "RB4++";
0204         ylabel[21] = "";
0205       }
0206     }
0207 
0208     void doEndcapLabeling(bool useRollInfo) {
0209       std::string rolls[3];
0210       rolls[0] = "A";
0211       rolls[1] = "B";
0212       rolls[2] = "C";
0213 
0214       endcapYLabels_.clear();
0215       std::stringstream myLabel;
0216 
0217       for (int ring = 1; ring <= 3; ring++) {
0218         for (int ch = 1; ch <= 6; ch++) {
0219           for (int r = 0; r < 3; r++) {
0220             myLabel.str("");
0221             myLabel << "R" << ring << "_C" << ch << "_" << rolls[r];
0222             endcapYLabels_.push_back(myLabel.str());
0223           }
0224         }
0225       }
0226     }
0227 
0228     std::string YLabel(int i) { return ylabel[i]; }
0229 
0230     //use only with RollvsSector MEs
0231     void labelXAxisSector(MonitorElement* myMe) {
0232       //before do some checks
0233       if (!myMe)
0234         return;
0235       RPCMEHelper::setNoAlphanumeric(myMe);
0236 
0237       std::stringstream xLabel;
0238 
0239       for (int x = 1; x <= myMe->getNbinsX(); x++) {
0240         xLabel.str("");
0241         xLabel << "Sec" << x;
0242         myMe->setBinLabel(x, xLabel.str(), 1);
0243       }
0244     }
0245 
0246     //use only with RingvsSegment MEs
0247     void labelXAxisSegment(MonitorElement* myMe) {
0248       //before do some checks
0249       if (!myMe)
0250         return;
0251       RPCMEHelper::setNoAlphanumeric(myMe);
0252 
0253       std::stringstream xLabel;
0254 
0255       myMe->setAxisTitle("Segments", 1);
0256 
0257       for (int x = 1; x <= myMe->getNbinsX(); x++) {
0258         xLabel.str("");
0259         xLabel << x;
0260         myMe->setBinLabel(x, xLabel.str(), 1);
0261       }
0262     }
0263 
0264     //use only with RollvsSector MEs
0265     void labelYAxisRoll(MonitorElement* myMe, int region, int ring, bool useRollInfo) {
0266       //before do some checks
0267       if (!myMe)
0268         return;
0269       RPCMEHelper::setNoAlphanumeric(myMe);
0270 
0271       //set bin labels
0272       if (region == 0) {
0273         //initialize label vector
0274         this->dolabeling(useRollInfo);
0275         if (ring == -2 || ring == 2)
0276           ylabel[7] = ylabel[0];
0277 
0278         for (int y = 1; y <= myMe->getNbinsY() && y < 22; y++)
0279           myMe->setBinLabel(y, ylabel[y], 2);
0280 
0281       } else {  //Endcap
0282 
0283         this->doEndcapLabeling(useRollInfo);
0284 
0285         for (int y = 1; y <= myMe->getNbinsY() && y < (int)endcapYLabels_.size(); y++)
0286           myMe->setBinLabel(y, endcapYLabels_[y], 2);
0287       }
0288     }
0289 
0290     //use only with RingvsSegment MEs
0291     void labelYAxisRing(MonitorElement* myMe, int numberOfRings, bool useRollInfo) {
0292       //before do some checks
0293       if (!myMe)
0294         return;
0295       std::string labels[9];
0296       if (useRollInfo) {
0297         labels[0] = "C";
0298         labels[1] = "Ring1 B";
0299         labels[2] = "A";
0300         labels[3] = "C";
0301         labels[4] = "Ring2 B";
0302         labels[5] = "A";
0303         labels[6] = "C";
0304         labels[7] = "Ring3 B";
0305         labels[8] = "A";
0306       } else {
0307         labels[0] = "";
0308         labels[1] = "Ring1";
0309         labels[2] = "";
0310         labels[3] = "";
0311         labels[4] = "Ring2";
0312         labels[5] = "";
0313         labels[6] = "";
0314         labels[7] = "Ring3";
0315         labels[8] = "";
0316       }
0317       int startBin;
0318       (numberOfRings == 2 ? startBin = 3 : startBin = 0);
0319 
0320       //set bin labels
0321       RPCMEHelper::setNoAlphanumeric(myMe);
0322       for (int y = 1; y <= myMe->getNbinsY() && y <= 9; y++) {
0323         myMe->setBinLabel(y, labels[y - 1 + startBin], 2);
0324       }
0325     }
0326 
0327     int detId2ChamberNr(const RPCDetId& _id) {
0328       if (_id.region() == 0) {     //Barrel
0329         if (_id.station() == 1) {  // Station1
0330           if (_id.layer() == 1) {
0331             ch = 1;  //RB1in
0332 
0333           } else {
0334             ch = 2;  //RB1out
0335           }
0336 
0337         } else if (_id.station() == 2) {  //Station 2
0338           if (_id.layer() == 1) {
0339             ch = 3;  //RB2in
0340           } else {
0341             ch = 4;  //RB2out
0342           }
0343         } else if (_id.station() == 3) {  //Station 3
0344           if (_id.subsector() == 1) {
0345             ch = 5;  //RB3+
0346           } else {
0347             ch = 6;  //RB3-
0348           }
0349         } else if (_id.station() == 4) {  //Station 4
0350           if (_id.sector() == 4) {
0351             if (_id.subsector() == 1) {
0352               ch = 7;  //RB4-
0353 
0354             } else if (_id.subsector() == 2) {
0355               ch = 8;  //RB4+
0356             } else if (_id.subsector() == 3) {
0357               ch = 9;  //RB4--
0358             } else if (_id.subsector() == 4) {
0359               ch = 10;  //RB4++
0360             }
0361           } else {
0362             if (_id.subsector() == 1)
0363               ch = 7;  //RB4-
0364             else
0365               ch = 8;  //RB4+
0366           }
0367         }
0368       } else {  //Endcap
0369       }
0370       return ch;
0371     }
0372 
0373     std::string detId2ChamberLabel(const RPCDetId& _id) {
0374       if (_id.region() == 0) {     //Barrel
0375         if (_id.station() == 1) {  // Station1
0376           if (_id.layer() == 1) {
0377             ChLabel = "RB1in";
0378 
0379           } else {
0380             ChLabel = "RB1out";
0381           }
0382 
0383         } else if (_id.station() == 2) {  //Station 2
0384           if (_id.layer() == 1) {
0385             ChLabel = "RB2in";
0386           } else {
0387             ChLabel = "RB2out";
0388           }
0389         } else if (_id.station() == 3) {  //Station 3
0390           if (_id.subsector() == 1) {
0391             ChLabel = "RB3+";
0392           } else {
0393             ChLabel = "RB3-";
0394           }
0395         } else if (_id.station() == 4) {  //Station 4
0396           if (_id.sector() == 4) {
0397             if (_id.subsector() == 1) {
0398               ChLabel = "RB4-";
0399 
0400             } else if (_id.subsector() == 2) {
0401               ChLabel = "RB4+";
0402             } else if (_id.subsector() == 3) {
0403               ChLabel = "RB4--";
0404             } else if (_id.subsector() == 4) {
0405               ChLabel = "RB4++";
0406             }
0407           } else {
0408             if (_id.subsector() == 1)
0409               ChLabel = "RB4-";
0410             else
0411               ChLabel = "RB4-";
0412           }
0413         }
0414       } else {  //Endcap
0415       }
0416       return ChLabel;
0417     }
0418 
0419   private:
0420     int _cnr;
0421     int ch;
0422     std::vector<std::string> endcapYLabels_;
0423     std::string ChLabel;
0424     std::vector<int> Wvector2;
0425     std::vector<int> Wvector1;
0426     std::string ylabel[22];
0427   };
0428 }  // namespace rpcdqm
0429 
0430 #endif