CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_1/src/DQMOffline/Muon/src/CSCOfflineMonitor.cc

Go to the documentation of this file.
00001 /*
00002  *  Offline DQM module for CSC local reconstruction.
00003  *
00004  *  Andy Kubik
00005  *  Northwestern University
00006  */
00007 
00008 #include "DQMOffline/Muon/src/CSCOfflineMonitor.h"
00009 
00010 using namespace std;
00011 using namespace edm;
00012 
00013 
00015 //  CONSTRUCTOR  //
00017 CSCOfflineMonitor::CSCOfflineMonitor(const ParameterSet& pset){
00018 
00019   param = pset;
00020 
00021   stripDigiTag_  = pset.getParameter<edm::InputTag>("stripDigiTag");
00022   wireDigiTag_   = pset.getParameter<edm::InputTag>("wireDigiTag"); 
00023   alctDigiTag_   = pset.getParameter<edm::InputTag>("alctDigiTag");
00024   clctDigiTag_   = pset.getParameter<edm::InputTag>("clctDigiTag"); 
00025   cscRecHitTag_  = pset.getParameter<edm::InputTag>("cscRecHitTag");
00026   cscSegTag_     = pset.getParameter<edm::InputTag>("cscSegTag");
00027   FEDRawDataCollectionTag_  = pset.getParameter<edm::InputTag>("FEDRawDataCollectionTag");
00028 
00029   finalizedHistograms_=false;
00030 
00031 }
00032 
00033 void CSCOfflineMonitor::beginJob(void){
00034       dbe = Service<DQMStore>().operator->();
00035   
00036       // Occupancies
00037       dbe->setCurrentFolder("CSC/CSCOfflineMonitor/Occupancy");
00038       hCSCOccupancy = dbe->book1D("hCSCOccupancy","overall CSC occupancy",13,-0.5,12.5);
00039       hCSCOccupancy->setBinLabel(2,"Total Events");
00040       hCSCOccupancy->setBinLabel(4,"# Events with Wires");
00041       hCSCOccupancy->setBinLabel(6,"# Events with Strips");
00042       hCSCOccupancy->setBinLabel(8,"# Events with Wires&Strips");
00043       hCSCOccupancy->setBinLabel(10,"# Events with Rechits");
00044       hCSCOccupancy->setBinLabel(12,"# Events with Segments");
00045       hOWiresAndCLCT = dbe->book2D("hOWiresAndCLCT","Wire and CLCT Digi Occupancy ",36,0.5,36.5,20,0.5,20.5);
00046       hOWires = dbe->book2D("hOWires","Wire Digi Occupancy",36,0.5,36.5,20,0.5,20.5);
00047       hOWireSerial = dbe->book1D("hOWireSerial","Wire Occupancy by Chamber Serial",601,-0.5,600.5);
00048       hOWireSerial->setAxisTitle("Chamber Serial Number");
00049       hOStrips = dbe->book2D("hOStrips","Strip Digi Occupancy",36,0.5,36.5,20,0.5,20.5);
00050       hOStripSerial = dbe->book1D("hOStripSerial","Strip Occupancy by Chamber Serial",601,-0.5,600.5);
00051       hOStripSerial->setAxisTitle("Chamber Serial Number");
00052       hOStripsAndWiresAndCLCT = dbe->book2D("hOStripsAndWiresAndCLCT","Strip And Wire And CLCT Digi Occupancy",36,0.5,36.5,20,0.5,20.5);
00053       hOStripsAndWiresAndCLCT->setAxisTitle("Chamber #");
00054       hORecHits = dbe->book2D("hORecHits","RecHit Occupancy",36,0.5,36.5,20,0.5,20.5);
00055       hORecHitsSerial = dbe->book1D("hORecHitSerial","RecHit Occupancy by Chamber Serial",601,-0.5,600.5);
00056       hORecHitsSerial->setAxisTitle("Chamber Serial Number");
00057       hOSegments = dbe->book2D("hOSegments","Segment Occupancy",36,0.5,36.5,20,0.5,20.5);
00058       hOSegmentsSerial = dbe->book1D("hOSegmentSerial","Segment Occupancy by Chamber Serial",601,-0.5,600.5);
00059       hOSegmentsSerial->setAxisTitle("Chamber Serial Number");
00060 
00061       // wire digis
00062       dbe->setCurrentFolder("CSC/CSCOfflineMonitor/Digis");
00063       hWirenGroupsTotal = dbe->book1D("hWirenGroupsTotal","Fired Wires per Event; # Wiregroups Fired",61,-0.5,60.5);
00064       hWireTBin.push_back(dbe->book1D("hWireTBin_m42","Wire TBin Fired (ME -4/2); Time Bin (25ns)",17,-0.5,16.5));
00065       hWireTBin.push_back(dbe->book1D("hWireTBin_m41","Wire TBin Fired (ME -4/1); Time Bin (25ns)",17,-0.5,16.5));
00066       hWireTBin.push_back(dbe->book1D("hWireTBin_m32","Wire TBin Fired (ME -3/2); Time Bin (25ns)",17,-0.5,16.5));
00067       hWireTBin.push_back(dbe->book1D("hWireTBin_m31","Wire TBin Fired (ME -3/1); Time Bin (25ns)",17,-0.5,16.5));
00068       hWireTBin.push_back(dbe->book1D("hWireTBin_m22","Wire TBin Fired (ME -2/2); Time Bin (25ns)",17,-0.5,16.5));
00069       hWireTBin.push_back(dbe->book1D("hWireTBin_m21","Wire TBin Fired (ME -2/1); Time Bin (25ns)",17,-0.5,16.5));
00070       hWireTBin.push_back(dbe->book1D("hWireTBin_m11a","Wire TBin Fired (ME -1/1a); Time Bin (25ns)",17,-0.5,16.5));
00071       hWireTBin.push_back(dbe->book1D("hWireTBin_m13","Wire TBin Fired (ME -1/3); Time Bin (25ns)",17,-0.5,16.5));
00072       hWireTBin.push_back(dbe->book1D("hWireTBin_m12","Wire TBin Fired (ME -1/2); Time Bin (25ns)",17,-0.5,16.5));
00073       hWireTBin.push_back(dbe->book1D("hWireTBin_m11b","Wire TBin Fired (ME -1/1b); Time Bin (25ns)",17,-0.5,16.5));
00074       hWireTBin.push_back(dbe->book1D("hWireTBin_p11b","Wire TBin Fired (ME +1/1b); Time Bin (25ns)",17,-0.5,16.5));
00075       hWireTBin.push_back(dbe->book1D("hWireTBin_p12","Wire TBin Fired (ME +1/2); Time Bin (25ns)",17,-0.5,16.5));
00076       hWireTBin.push_back(dbe->book1D("hWireTBin_p13","Wire TBin Fired (ME +1/3); Time Bin (25ns)",17,-0.5,16.5));
00077       hWireTBin.push_back(dbe->book1D("hWireTBin_p11a","Wire TBin Fired (ME +1/1a); Time Bin (25ns)",17,-0.5,16.5));
00078       hWireTBin.push_back(dbe->book1D("hWireTBin_p21","Wire TBin Fired (ME +2/1); Time Bin (25ns)",17,-0.5,16.5));
00079       hWireTBin.push_back(dbe->book1D("hWireTBin_p22","Wire TBin Fired (ME +2/2); Time Bin (25ns)",17,-0.5,16.5));
00080       hWireTBin.push_back(dbe->book1D("hWireTBin_p31","Wire TBin Fired (ME +3/1); Time Bin (25ns)",17,-0.5,16.5));
00081       hWireTBin.push_back(dbe->book1D("hWireTBin_p32","Wire TBin Fired (ME +3/2); Time Bin (25ns)",17,-0.5,16.5));
00082       hWireTBin.push_back(dbe->book1D("hWireTBin_p41","Wire TBin Fired (ME +4/1); Time Bin (25ns)",17,-0.5,16.5));
00083       hWireTBin.push_back(dbe->book1D("hWireTBin_p42","Wire TBin Fired (ME +4/2); Time Bin (25ns)",17,-0.5,16.5));
00084       hWireNumber.push_back(dbe->book1D("hWireNumber_m42","Wiregroup Number Fired (ME -4/2); Wiregroup #",113,-0.5,112.5));
00085       hWireNumber.push_back(dbe->book1D("hWireNumber_m41","Wiregroup Number Fired (ME -4/1); Wiregroup #",113,-0.5,112.5));
00086       hWireNumber.push_back(dbe->book1D("hWireNumber_m32","Wiregroup Number Fired (ME -3/2); Wiregroup #",113,-0.5,112.5));
00087       hWireNumber.push_back(dbe->book1D("hWireNumber_m31","Wiregroup Number Fired (ME -3/1); Wiregroup #",113,-0.5,112.5));
00088       hWireNumber.push_back(dbe->book1D("hWireNumber_m22","Wiregroup Number Fired (ME -2/2); Wiregroup #",113,-0.5,112.5));
00089       hWireNumber.push_back(dbe->book1D("hWireNumber_m21","Wiregroup Number Fired (ME -2/1); Wiregroup #",113,-0.5,112.5));
00090       hWireNumber.push_back(dbe->book1D("hWireNumber_m11a","Wiregroup Number Fired (ME -1/1a); Wiregroup #",113,-0.5,112.5));
00091       hWireNumber.push_back(dbe->book1D("hWireNumber_m13","Wiregroup Number Fired (ME -1/3); Wiregroup #",113,-0.5,112.5));
00092       hWireNumber.push_back(dbe->book1D("hWireNumber_m12","Wiregroup Number Fired (ME -1/2); Wiregroup #",113,-0.5,112.5));
00093       hWireNumber.push_back(dbe->book1D("hWireNumber_m11b","Wiregroup Number Fired (ME -1/1b); Wiregroup #",113,-0.5,112.5));
00094       hWireNumber.push_back(dbe->book1D("hWireNumber_p11b","Wiregroup Number Fired (ME +1/1b); Wiregroup #",113,-0.5,112.5));
00095       hWireNumber.push_back(dbe->book1D("hWireNumber_p12","Wiregroup Number Fired (ME +1/2); Wiregroup #",113,-0.5,112.5));
00096       hWireNumber.push_back(dbe->book1D("hWireNumber_p13","Wiregroup Number Fired (ME +1/3); Wiregroup #",113,-0.5,112.5));
00097       hWireNumber.push_back(dbe->book1D("hWireNumber_p11a","Wiregroup Number Fired (ME +1/1a); Wiregroup #",113,-0.5,112.5));
00098       hWireNumber.push_back(dbe->book1D("hWireNumber_p21","Wiregroup Number Fired (ME +2/1); Wiregroup #",113,-0.5,112.5));
00099       hWireNumber.push_back(dbe->book1D("hWireNumber_p22","Wiregroup Number Fired (ME +2/2); Wiregroup #",113,-0.5,112.5));
00100       hWireNumber.push_back(dbe->book1D("hWireNumber_p31","Wiregroup Number Fired (ME +3/1); Wiregroup #",113,-0.5,112.5));
00101       hWireNumber.push_back(dbe->book1D("hWireNumber_p32","Wiregroup Number Fired (ME +3/2); Wiregroup #",113,-0.5,112.5));
00102       hWireNumber.push_back(dbe->book1D("hWireNumber_p41","Wiregroup Number Fired (ME +4/1); Wiregroup #",113,-0.5,112.5));
00103       hWireNumber.push_back(dbe->book1D("hWireNumber_p42","Wiregroup Number Fired (ME +4/2); Wiregroup #",113,-0.5,112.5));
00104 
00105       // strip digis
00106       hStripNFired = dbe->book1D("hStripNFired","Fired Strips per Event; # Strips Fired (above 13 ADC)",101,-0.5,100.5);
00107       hStripNumber.push_back(dbe->book1D("hStripNumber_m42","Strip Number Fired (ME -4/2); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00108       hStripNumber.push_back(dbe->book1D("hStripNumber_m41","Strip Number Fired (ME -4/1); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00109       hStripNumber.push_back(dbe->book1D("hStripNumber_m32","Strip Number Fired (ME -3/2); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00110       hStripNumber.push_back(dbe->book1D("hStripNumber_m31","Strip Number Fired (ME -3/1); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00111       hStripNumber.push_back(dbe->book1D("hStripNumber_m22","Strip Number Fired (ME -2/2); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00112       hStripNumber.push_back(dbe->book1D("hStripNumber_m21","Strip Number Fired (ME -2/1); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00113       hStripNumber.push_back(dbe->book1D("hStripNumber_m11a","Strip Number Fired (ME -1/1a); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00114       hStripNumber.push_back(dbe->book1D("hStripNumber_m13","Strip Number Fired (ME -1/3); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00115       hStripNumber.push_back(dbe->book1D("hStripNumber_m12","Strip Number Fired (ME -1/2); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00116       hStripNumber.push_back(dbe->book1D("hStripNumber_m11b","Strip Number Fired (ME -1/1b); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00117       hStripNumber.push_back(dbe->book1D("hStripNumber_p11b","Strip Number Fired (ME +1/1b); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00118       hStripNumber.push_back(dbe->book1D("hStripNumber_p12","Strip Number Fired (ME +1/2); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00119       hStripNumber.push_back(dbe->book1D("hStripNumber_p13","Strip Number Fired (ME +1/3); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00120       hStripNumber.push_back(dbe->book1D("hStripNumber_p11a","Strip Number Fired (ME +1/1a); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00121       hStripNumber.push_back(dbe->book1D("hStripNumber_p21","Strip Number Fired (ME +2/1); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00122       hStripNumber.push_back(dbe->book1D("hStripNumber_p22","Strip Number Fired (ME +2/2); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00123       hStripNumber.push_back(dbe->book1D("hStripNumber_p31","Strip Number Fired (ME +3/1); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00124       hStripNumber.push_back(dbe->book1D("hStripNumber_p32","Strip Number Fired (ME +3/2); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00125       hStripNumber.push_back(dbe->book1D("hStripNumber_p41","Strip Number Fired (ME +4/1); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00126       hStripNumber.push_back(dbe->book1D("hStripNumber_p42","Stripgroup Number Fired (ME +4/2); Strip # Fired (above 13 ADC)",81,-0.5,80.5));
00127 
00128       //Pedestal Noise Plots
00129       dbe->setCurrentFolder("CSC/CSCOfflineMonitor/PedestalNoise");
00130       hStripPed.push_back(dbe->book1D("hStripPedMEm42","Pedestal Noise Distribution Chamber ME -4/2; ADC Counts",50,-25.,25.));
00131       hStripPed.push_back(dbe->book1D("hStripPedMEm41","Pedestal Noise Distribution Chamber ME -4/1; ADC Counts",50,-25.,25.));
00132       hStripPed.push_back(dbe->book1D("hStripPedMEm32","Pedestal Noise Distribution Chamber ME -3/2; ADC Counts",50,-25.,25.));
00133       hStripPed.push_back(dbe->book1D("hStripPedMEm31","Pedestal Noise Distribution Chamber ME -3/1; ADC Counts",50,-25.,25.));
00134       hStripPed.push_back(dbe->book1D("hStripPedMEm22","Pedestal Noise Distribution Chamber ME -2/2; ADC Counts",50,-25.,25.));
00135       hStripPed.push_back(dbe->book1D("hStripPedMEm21","Pedestal Noise Distribution Chamber ME -2/1; ADC Counts",50,-25.,25.));
00136       hStripPed.push_back(dbe->book1D("hStripPedMEm11a","Pedestal Noise Distribution Chamber ME -1/1; ADC Counts",50,-25.,25.));
00137       hStripPed.push_back(dbe->book1D("hStripPedMEm13","Pedestal Noise Distribution Chamber ME -1/3; ADC Counts",50,-25.,25.));
00138       hStripPed.push_back(dbe->book1D("hStripPedMEm12","Pedestal Noise Distribution Chamber ME -1/2; ADC Counts",50,-25.,25.));
00139       hStripPed.push_back(dbe->book1D("hStripPedMEm11b","Pedestal Noise Distribution Chamber ME -1/1; ADC Counts",50,-25.,25.));
00140       hStripPed.push_back(dbe->book1D("hStripPedMEp11b","Pedestal Noise Distribution Chamber ME +1/1; ADC Counts",50,-25.,25.));
00141       hStripPed.push_back(dbe->book1D("hStripPedMEp12","Pedestal Noise Distribution Chamber ME +1/2; ADC Counts",50,-25.,25.));
00142       hStripPed.push_back(dbe->book1D("hStripPedMEp13","Pedestal Noise Distribution Chamber ME +1/3; ADC Counts",50,-25.,25.));
00143       hStripPed.push_back(dbe->book1D("hStripPedMEp11a","Pedestal Noise Distribution Chamber ME +1/1; ADC Counts",50,-25.,25.));
00144       hStripPed.push_back(dbe->book1D("hStripPedMEp21","Pedestal Noise Distribution Chamber ME +2/1; ADC Counts",50,-25.,25.));
00145       hStripPed.push_back(dbe->book1D("hStripPedMEp22","Pedestal Noise Distribution Chamber ME +2/2; ADC Counts",50,-25.,25.));
00146       hStripPed.push_back(dbe->book1D("hStripPedMEp31","Pedestal Noise Distribution Chamber ME +3/1; ADC Counts",50,-25.,25.));
00147       hStripPed.push_back(dbe->book1D("hStripPedMEp32","Pedestal Noise Distribution Chamber ME +3/2; ADC Counts",50,-25.,25.));
00148       hStripPed.push_back(dbe->book1D("hStripPedMEp41","Pedestal Noise Distribution Chamber ME +4/1; ADC Counts",50,-25.,25.));
00149       hStripPed.push_back(dbe->book1D("hStripPedMEp42","Pedestal Noise Distribution Chamber ME +4/2; ADC Counts",50,-25.,25.));
00150 
00151       // recHits
00152       dbe->setCurrentFolder("CSC/CSCOfflineMonitor/recHits");
00153       hRHnrechits = dbe->book1D("hRHnrechits","recHits per Event (all chambers); # of RecHits",50,0,50);
00154       hRHGlobal.push_back(dbe->book2D("hRHGlobalp1","recHit global X,Y station +1; Global X (cm); Global Y (cm)",100,-800.,800.,100,-800.,800.));
00155       hRHGlobal.push_back(dbe->book2D("hRHGlobalp2","recHit global X,Y station +2; Global X (cm); Global Y (cm)",100,-800.,800.,100,-800.,800.));
00156       hRHGlobal.push_back(dbe->book2D("hRHGlobalp3","recHit global X,Y station +3; Global X (cm); Global Y (cm)",100,-800.,800.,100,-800.,800.));
00157       hRHGlobal.push_back(dbe->book2D("hRHGlobalp4","recHit global X,Y station +4; Global X (cm); Global Y (cm)",100,-800.,800.,100,-800.,800.));
00158       hRHGlobal.push_back(dbe->book2D("hRHGlobalm1","recHit global X,Y station -1; Global X (cm); Global Y (cm)",100,-800.,800.,100,-800.,800.));
00159       hRHGlobal.push_back(dbe->book2D("hRHGlobalm2","recHit global X,Y station -2; Global X (cm); Global Y (cm)",100,-800.,800.,100,-800.,800.));
00160       hRHGlobal.push_back(dbe->book2D("hRHGlobalm3","recHit global X,Y station -3; Global X (cm); Global Y (cm)",100,-800.,800.,100,-800.,800.));
00161       hRHGlobal.push_back(dbe->book2D("hRHGlobalm4","recHit global X,Y station -4; Global X (cm); Global Y (cm)",100,-800.,800.,100,-800.,800.));
00162       hRHSumQ.push_back(dbe->book1D("hRHSumQm42","Sum 3x3 recHit Charge (ME -4/2); ADC counts",100,0,2000));
00163       hRHSumQ.push_back(dbe->book1D("hRHSumQm41","Sum 3x3 recHit Charge (ME -4/1); ADC counts",100,0,2000));
00164       hRHSumQ.push_back(dbe->book1D("hRHSumQm32","Sum 3x3 recHit Charge (ME -3/2); ADC counts",100,0,2000));
00165       hRHSumQ.push_back(dbe->book1D("hRHSumQm31","Sum 3x3 recHit Charge (ME -3/1); ADC counts",100,0,2000));
00166       hRHSumQ.push_back(dbe->book1D("hRHSumQm22","Sum 3x3 recHit Charge (ME -2/2); ADC counts",100,0,2000));
00167       hRHSumQ.push_back(dbe->book1D("hRHSumQm21","Sum 3x3 recHit Charge (ME -2/1); ADC counts",100,0,2000));
00168       hRHSumQ.push_back(dbe->book1D("hRHSumQm11a","Sum 3x3 recHit Charge (ME -1/1a); ADC counts",100,0,4000));
00169       hRHSumQ.push_back(dbe->book1D("hRHSumQm13","Sum 3x3 recHit Charge (ME -1/3); ADC counts",100,0,2000));
00170       hRHSumQ.push_back(dbe->book1D("hRHSumQm12","Sum 3x3 recHit Charge (ME -1/2); ADC counts",100,0,2000));
00171       hRHSumQ.push_back(dbe->book1D("hRHSumQm11b","Sum 3x3 recHit Charge (ME -1/1b); ADC counts",100,0,4000));
00172       hRHSumQ.push_back(dbe->book1D("hRHSumQp11b","Sum 3x3 recHit Charge (ME +1/1b); ADC counts",100,0,4000));
00173       hRHSumQ.push_back(dbe->book1D("hRHSumQp12","Sum 3x3 recHit Charge (ME +1/2); ADC counts",100,0,2000));
00174       hRHSumQ.push_back(dbe->book1D("hRHSumQp13","Sum 3x3 recHit Charge (ME +1/3); ADC counts",100,0,2000));
00175       hRHSumQ.push_back(dbe->book1D("hRHSumQp11a","Sum 3x3 recHit Charge (ME +1/1a); ADC counts",100,0,4000));
00176       hRHSumQ.push_back(dbe->book1D("hRHSumQp21","Sum 3x3 recHit Charge (ME +2/1); ADC counts",100,0,2000));
00177       hRHSumQ.push_back(dbe->book1D("hRHSumQp22","Sum 3x3 recHit Charge (ME +2/2); ADC counts",100,0,2000));
00178       hRHSumQ.push_back(dbe->book1D("hRHSumQp31","Sum 3x3 recHit Charge (ME +3/1); ADC counts",100,0,2000));
00179       hRHSumQ.push_back(dbe->book1D("hRHSumQp32","Sum 3x3 recHit Charge (ME +3/2); ADC counts",100,0,2000));
00180       hRHSumQ.push_back(dbe->book1D("hRHSumQp41","Sum 3x3 recHit Charge (ME +4/1); ADC counts",100,0,2000));
00181       hRHSumQ.push_back(dbe->book1D("hRHSumQp42","Sum 3x3 recHit Charge (ME +4/2); ADC counts",100,0,2000));
00182       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm42","Charge Ratio (Ql+Qr)/Qt (ME -4/2); (Ql+Qr)/Qt",100,-0.1,1.1));
00183       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm41","Charge Ratio (Ql+Qr)/Qt (ME -4/1); (Ql+Qr)/Qt",100,-0.1,1.1));
00184       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm32","Charge Ratio (Ql+Qr)/Qt (ME -3/2); (Ql+Qr)/Qt",100,-0.1,1.1));
00185       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm31","Charge Ratio (Ql+Qr)/Qt (ME -3/1); (Ql+Qr)/Qt",100,-0.1,1.1));
00186       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm22","Charge Ratio (Ql+Qr)/Qt (ME -2/2); (Ql+Qr)/Qt",100,-0.1,1.1));
00187       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm21","Charge Ratio (Ql+Qr)/Qt (ME -2/1); (Ql+Qr)/Qt",100,-0.1,1.1));
00188       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm11a","Charge Ratio (Ql+Qr)/Qt (ME -1/1a); (Ql+Qr)/Qt",100,-0.1,1.1));
00189       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm13","Charge Ratio (Ql+Qr)/Qt (ME -1/3); (Ql+Qr)/Qt",100,-0.1,1.1));
00190       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm12","Charge Ratio (Ql+Qr)/Qt (ME -1/2); (Ql+Qr)/Qt",100,-0.1,1.1));
00191       hRHRatioQ.push_back(dbe->book1D("hRHRatioQm11b","Charge Ratio (Ql+Qr)/Qt (ME -1/1b); (Ql+Qr)/Qt",100,-0.1,1.1));
00192       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp11b","Charge Ratio (Ql+Qr)/Qt (ME +1/1b); (Ql+Qr)/Qt",100,-0.1,1.1));
00193       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp12","Charge Ratio (Ql+Qr)/Qt (ME +1/2); (Ql+Qr)/Qt",100,-0.1,1.1));
00194       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp13","Charge Ratio (Ql+Qr)/Qt (ME +1/3); (Ql+Qr)/Qt",100,-0.1,1.1));
00195       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp11a","Charge Ratio (Ql+Qr)/Qt (ME +1/1a); (Ql+Qr)/Qt",100,-0.1,1.1));
00196       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp21","Charge Ratio (Ql+Qr)/Qt (ME +2/1); (Ql+Qr)/Qt",100,-0.1,1.1));
00197       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp22","Charge Ratio (Ql+Qr)/Qt (ME +2/2); (Ql+Qr)/Qt",100,-0.1,1.1));
00198       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp31","Charge Ratio (Ql+Qr)/Qt (ME +3/1); (Ql+Qr)/Qt",100,-0.1,1.1));
00199       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp32","Charge Ratio (Ql+Qr)/Qt (ME +3/2); (Ql+Qr)/Qt",100,-0.1,1.1));
00200       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp41","Charge Ratio (Ql+Qr)/Qt (ME +4/1); (Ql+Qr)/Qt",100,-0.1,1.1));
00201       hRHRatioQ.push_back(dbe->book1D("hRHRatioQp42","Charge Ratio (Ql+Qr)/Qt (ME +4/2); (Ql+Qr)/Qt",100,-0.1,1.1));
00202       hRHTiming.push_back(dbe->book1D("hRHTimingm42","recHit Time (ME -4/2); ns",200,-500.,500.));
00203       hRHTiming.push_back(dbe->book1D("hRHTimingm41","recHit Time (ME -4/1); ns",200,-500.,500.));
00204       hRHTiming.push_back(dbe->book1D("hRHTimingm32","recHit Time (ME -3/2); ns",200,-500.,500.));
00205       hRHTiming.push_back(dbe->book1D("hRHTimingm31","recHit Time (ME -3/1); ns",200,-500.,500.));
00206       hRHTiming.push_back(dbe->book1D("hRHTimingm22","recHit Time (ME -2/2); ns",200,-500.,500.));
00207       hRHTiming.push_back(dbe->book1D("hRHTimingm21","recHit Time (ME -2/1); ns",200,-500.,500.));
00208       hRHTiming.push_back(dbe->book1D("hRHTimingm11a","recHit Time (ME -1/1a); ns",200,-500.,500.));
00209       hRHTiming.push_back(dbe->book1D("hRHTimingm13","recHit Time (ME -1/3); ns",200,-500.,500.));
00210       hRHTiming.push_back(dbe->book1D("hRHTimingm12","recHit Time (ME -1/2); ns",200,-500.,500.));
00211       hRHTiming.push_back(dbe->book1D("hRHTimingm11b","recHit Time (ME -1/1b); ns",200,-500.,500.));
00212       hRHTiming.push_back(dbe->book1D("hRHTimingp11b","recHit Time (ME +1/1b); ns",200,-500.,500.));
00213       hRHTiming.push_back(dbe->book1D("hRHTimingp12","recHit Time (ME +1/2); ns",200,-500.,500.));
00214       hRHTiming.push_back(dbe->book1D("hRHTimingp13","recHit Time (ME +1/3); ns",200,-500.,500.));
00215       hRHTiming.push_back(dbe->book1D("hRHTimingp11a","recHit Time (ME +1/1a); ns",200,-500.,500.));
00216       hRHTiming.push_back(dbe->book1D("hRHTimingp21","recHit Time (ME +2/1); ns",200,-500.,500.));
00217       hRHTiming.push_back(dbe->book1D("hRHTimingp22","recHit Time (ME +2/2); ns",200,-500.,500.));
00218       hRHTiming.push_back(dbe->book1D("hRHTimingp31","recHit Time (ME +3/1); ns",200,-500.,500.));
00219       hRHTiming.push_back(dbe->book1D("hRHTimingp32","recHit Time (ME +3/2); ns",200,-500.,500.));
00220       hRHTiming.push_back(dbe->book1D("hRHTimingp41","recHit Time (ME +4/1); ns",200,-500.,500.));
00221       hRHTiming.push_back(dbe->book1D("hRHTimingp42","recHit Time (ME +4/2); ns",200,-500.,500.));
00222       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem42","Anode recHit Time (ME -4/2); ns",80,-500.,500.));
00223       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem41","Anode recHit Time (ME -4/1); ns",80,-500.,500.));
00224       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem32","Anode recHit Time (ME -3/2); ns",80,-500.,500.));
00225       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem31","Anode recHit Time (ME -3/1); ns",80,-500.,500.));
00226       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem22","Anode recHit Time (ME -2/2); ns",80,-500.,500.));
00227       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem21","Anode recHit Time (ME -2/1); ns",80,-500.,500.));
00228       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem11a","Anode recHit Time (ME -1/1a); ns",80,-500.,500.));
00229       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem13","Anode recHit Time (ME -1/3); ns",80,-500.,500.));
00230       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem12","Anode recHit Time (ME -1/2); ns",80,-500.,500.));
00231       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodem11b","Anode recHit Time (ME -1/1b); ns",80,-500.,500.));
00232       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep11b","Anode recHit Time (ME +1/1b); ns",80,-500.,500.));
00233       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep12","Anode recHit Time (ME +1/2); ns",80,-500.,500.));
00234       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep13","Anode recHit Time (ME +1/3); ns",80,-500.,500.));
00235       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep11a","Anode recHit Time (ME +1/1a); ns",80,-500.,500.));
00236       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep21","Anode recHit Time (ME +2/1); ns",80,-500.,500.));
00237       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep22","Anode recHit Time (ME +2/2); ns",80,-500.,500.));
00238       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep31","Anode recHit Time (ME +3/1); ns",80,-500.,500.));
00239       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep32","Anode recHit Time (ME +3/2); ns",80,-500.,500.));
00240       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep41","Anode recHit Time (ME +4/1); ns",80,-500.,500.));
00241       hRHTimingAnode.push_back(dbe->book1D("hRHTimingAnodep42","Anode recHit Time (ME +4/2); ns",80,-500.,500.));
00242       hRHstpos.push_back(dbe->book1D("hRHstposm42","Reconstructed Position on Strip (ME -4/2); Strip Widths",120,-0.6,0.6));
00243       hRHstpos.push_back(dbe->book1D("hRHstposm41","Reconstructed Position on Strip (ME -4/1); Strip Widths",120,-0.6,0.6));
00244       hRHstpos.push_back(dbe->book1D("hRHstposm32","Reconstructed Position on Strip (ME -3/2); Strip Widths",120,-0.6,0.6));
00245       hRHstpos.push_back(dbe->book1D("hRHstposm31","Reconstructed Position on Strip (ME -3/1); Strip Widths",120,-0.6,0.6));
00246       hRHstpos.push_back(dbe->book1D("hRHstposm22","Reconstructed Position on Strip (ME -2/2); Strip Widths",120,-0.6,0.6));
00247       hRHstpos.push_back(dbe->book1D("hRHstposm21","Reconstructed Position on Strip (ME -2/1); Strip Widths",120,-0.6,0.6));
00248       hRHstpos.push_back(dbe->book1D("hRHstposm11a","Reconstructed Position on Strip (ME -1/1a); Strip Widths",120,-0.6,0.6));
00249       hRHstpos.push_back(dbe->book1D("hRHstposm13","Reconstructed Position on Strip (ME -1/3); Strip Widths",120,-0.6,0.6));
00250       hRHstpos.push_back(dbe->book1D("hRHstposm12","Reconstructed Position on Strip (ME -1/2); Strip Widths",120,-0.6,0.6));
00251       hRHstpos.push_back(dbe->book1D("hRHstposm11b","Reconstructed Position on Strip (ME -1/1b); Strip Widths",120,-0.6,0.6));
00252       hRHstpos.push_back(dbe->book1D("hRHstposp11b","Reconstructed Position on Strip (ME +1/1b); Strip Widths",120,-0.6,0.6));
00253       hRHstpos.push_back(dbe->book1D("hRHstposp12","Reconstructed Position on Strip (ME +1/2); Strip Widths",120,-0.6,0.6));
00254       hRHstpos.push_back(dbe->book1D("hRHstposp13","Reconstructed Position on Strip (ME +1/3); Strip Widths",120,-0.6,0.6));
00255       hRHstpos.push_back(dbe->book1D("hRHstposp11a","Reconstructed Position on Strip (ME +1/1a); Strip Widths",120,-0.6,0.6));
00256       hRHstpos.push_back(dbe->book1D("hRHstposp21","Reconstructed Position on Strip (ME +2/1); Strip Widths",120,-0.6,0.6));
00257       hRHstpos.push_back(dbe->book1D("hRHstposp22","Reconstructed Position on Strip (ME +2/2); Strip Widths",120,-0.6,0.6));
00258       hRHstpos.push_back(dbe->book1D("hRHstposp31","Reconstructed Position on Strip (ME +3/1); Strip Widths",120,-0.6,0.6));
00259       hRHstpos.push_back(dbe->book1D("hRHstposp32","Reconstructed Position on Strip (ME +3/2); Strip Widths",120,-0.6,0.6));
00260       hRHstpos.push_back(dbe->book1D("hRHstposp41","Reconstructed Position on Strip (ME +4/1); Strip Widths",120,-0.6,0.6));
00261       hRHstpos.push_back(dbe->book1D("hRHstposp42","Reconstructed Position on Strip (ME +4/2); Strip Widths",120,-0.6,0.6));
00262       hRHsterr.push_back(dbe->book1D("hRHsterrm42","Estimated Error on Strip Measurement (ME -4/2); Strip Widths",75,-0.01,0.24));
00263       hRHsterr.push_back(dbe->book1D("hRHsterrm41","Estimated Error on Strip Measurement (ME -4/1); Strip Widths",75,-0.01,0.24));
00264       hRHsterr.push_back(dbe->book1D("hRHsterrm32","Estimated Error on Strip Measurement (ME -3/2); Strip Widths",75,-0.01,0.24));
00265       hRHsterr.push_back(dbe->book1D("hRHsterrm31","Estimated Error on Strip Measurement (ME -3/1); Strip Widths",75,-0.01,0.24));
00266       hRHsterr.push_back(dbe->book1D("hRHsterrm22","Estimated Error on Strip Measurement (ME -2/2); Strip Widths",75,-0.01,0.24));
00267       hRHsterr.push_back(dbe->book1D("hRHsterrm21","Estimated Error on Strip Measurement (ME -2/1); Strip Widths",75,-0.01,0.24));
00268       hRHsterr.push_back(dbe->book1D("hRHsterrm11a","Estimated Error on Strip Measurement (ME -1/1a); Strip Widths",75,-0.01,0.24));
00269       hRHsterr.push_back(dbe->book1D("hRHsterrm13","Estimated Error on Strip Measurement (ME -1/3); Strip Widths",75,-0.01,0.24));
00270       hRHsterr.push_back(dbe->book1D("hRHsterrm12","Estimated Error on Strip Measurement (ME -1/2); Strip Widths",75,-0.01,0.24));
00271       hRHsterr.push_back(dbe->book1D("hRHsterrm11b","Estimated Error on Strip Measurement (ME -1/1b); Strip Widths",75,-0.01,0.24));
00272       hRHsterr.push_back(dbe->book1D("hRHsterrp11b","Estimated Error on Strip Measurement (ME +1/1b); Strip Widths",75,-0.01,0.24));
00273       hRHsterr.push_back(dbe->book1D("hRHsterrp12","Estimated Error on Strip Measurement (ME +1/2); Strip Widths",75,-0.01,0.24));
00274       hRHsterr.push_back(dbe->book1D("hRHsterrp13","Estimated Error on Strip Measurement (ME +1/3); Strip Widths",75,-0.01,0.24));
00275       hRHsterr.push_back(dbe->book1D("hRHsterrp11a","Estimated Error on Strip Measurement (ME +1/1a); Strip Widths",75,-0.01,0.24));
00276       hRHsterr.push_back(dbe->book1D("hRHsterrp21","Estimated Error on Strip Measurement (ME +2/1); Strip Widths",75,-0.01,0.24));
00277       hRHsterr.push_back(dbe->book1D("hRHsterrp22","Estimated Error on Strip Measurement (ME +2/2); Strip Widths",75,-0.01,0.24));
00278       hRHsterr.push_back(dbe->book1D("hRHsterrp31","Estimated Error on Strip Measurement (ME +3/1); Strip Widths",75,-0.01,0.24));
00279       hRHsterr.push_back(dbe->book1D("hRHsterrp32","Estimated Error on Strip Measurement (ME +3/2); Strip Widths",75,-0.01,0.24));
00280       hRHsterr.push_back(dbe->book1D("hRHsterrp41","Estimated Error on Strip Measurement (ME +4/1); Strip Widths",75,-0.01,0.24));
00281       hRHsterr.push_back(dbe->book1D("hRHsterrp42","Estimated Error on Strip Measurement (ME +4/2); Strip Widths",75,-0.01,0.24));
00282 
00283 
00284       // segments
00285       dbe->setCurrentFolder("CSC/CSCOfflineMonitor/Segments");
00286       hSnSegments   = dbe->book1D("hSnSegments","Number of Segments per Event; # of Segments",11,-0.5,10.5);
00287       hSnhitsAll = dbe->book1D("hSnhits","N hits on Segments; # of hits",8,-0.5,7.5);
00288       hSnhits.push_back(dbe->book1D("hSnhitsm42","# of hits on Segments (ME -4/2); # of hits",8,-0.5,7.5));
00289       hSnhits.push_back(dbe->book1D("hSnhitsm41","# of hits on Segments (ME -4/1); # of hits",8,-0.5,7.5));
00290       hSnhits.push_back(dbe->book1D("hSnhitsm32","# of hits on Segments (ME -3/2); # of hits",8,-0.5,7.5));
00291       hSnhits.push_back(dbe->book1D("hSnhitsm31","# of hits on Segments (ME -3/1); # of hits",8,-0.5,7.5));
00292       hSnhits.push_back(dbe->book1D("hSnhitsm22","# of hits on Segments (ME -2/2); # of hits",8,-0.5,7.5));
00293       hSnhits.push_back(dbe->book1D("hSnhitsm21","# of hits on Segments (ME -2/1); # of hits",8,-0.5,7.5));
00294       hSnhits.push_back(dbe->book1D("hSnhitsm11a","# of hits on Segments (ME -1/1a); # of hits",8,-0.5,7.5));
00295       hSnhits.push_back(dbe->book1D("hSnhitsm13","# of hits on Segments (ME -1/3); # of hits",8,-0.5,7.5));
00296       hSnhits.push_back(dbe->book1D("hSnhitsm12","# of hits on Segments (ME -1/2); # of hits",8,-0.5,7.5));
00297       hSnhits.push_back(dbe->book1D("hSnhitsm11b","# of hits on Segments (ME -1/1b); # of hits",8,-0.5,7.5));
00298       hSnhits.push_back(dbe->book1D("hSnhitsp11b","# of hits on Segments (ME +1/1b); # of hits",8,-0.5,7.5));
00299       hSnhits.push_back(dbe->book1D("hSnhitsp12","# of hits on Segments (ME +1/2); # of hits",8,-0.5,7.5));
00300       hSnhits.push_back(dbe->book1D("hSnhitsp13","# of hits on Segments (ME +1/3); # of hits",8,-0.5,7.5));
00301       hSnhits.push_back(dbe->book1D("hSnhitsp11a","# of hits on Segments (ME +1/1a); # of hits",8,-0.5,7.5));
00302       hSnhits.push_back(dbe->book1D("hSnhitsp21","# of hits on Segments (ME +2/1); # of hits",8,-0.5,7.5));
00303       hSnhits.push_back(dbe->book1D("hSnhitsp22","# of hits on Segments (ME +2/2); # of hits",8,-0.5,7.5));
00304       hSnhits.push_back(dbe->book1D("hSnhitsp31","# of hits on Segments (ME +3/1); # of hits",8,-0.5,7.5));
00305       hSnhits.push_back(dbe->book1D("hSnhitsp32","# of hits on Segments (ME +3/2); # of hits",8,-0.5,7.5));
00306       hSnhits.push_back(dbe->book1D("hSnhitsp41","# of hits on Segments (ME +4/1); # of hits",8,-0.5,7.5));
00307       hSnhits.push_back(dbe->book1D("hSnhitsp42","# of hits on Segments (ME +4/2); # of hits",8,-0.5,7.5));
00308       hSChiSqAll = dbe->book1D("hSChiSq","Segment Normalized Chi2; Chi2/ndof",110,-0.05,10.5);
00309       hSChiSq.push_back(dbe->book1D("hSChiSqm42","Segment Normalized Chi2 (ME -4/2); Chi2/ndof",110,-0.05,10.5));
00310       hSChiSq.push_back(dbe->book1D("hSChiSqm41","Segment Normalized Chi2 (ME -4/1); Chi2/ndof",110,-0.05,10.5));
00311       hSChiSq.push_back(dbe->book1D("hSChiSqm32","Segment Normalized Chi2 (ME -3/2); Chi2/ndof",110,-0.05,10.5));
00312       hSChiSq.push_back(dbe->book1D("hSChiSqm31","Segment Normalized Chi2 (ME -3/1); Chi2/ndof",110,-0.05,10.5));
00313       hSChiSq.push_back(dbe->book1D("hSChiSqm22","Segment Normalized Chi2 (ME -2/2); Chi2/ndof",110,-0.05,10.5));
00314       hSChiSq.push_back(dbe->book1D("hSChiSqm21","Segment Normalized Chi2 (ME -2/1); Chi2/ndof",110,-0.05,10.5));
00315       hSChiSq.push_back(dbe->book1D("hSChiSqm11a","Segment Normalized Chi2 (ME -1/1a); Chi2/ndof",110,-0.05,10.5));
00316       hSChiSq.push_back(dbe->book1D("hSChiSqm13","Segment Normalized Chi2 (ME -1/3); Chi2/ndof",110,-0.05,10.5));
00317       hSChiSq.push_back(dbe->book1D("hSChiSqm12","Segment Normalized Chi2 (ME -1/2); Chi2/ndof",110,-0.05,10.5));
00318       hSChiSq.push_back(dbe->book1D("hSChiSqm11b","Segment Normalized Chi2 (ME -1/1b); Chi2/ndof",110,-0.05,10.5));
00319       hSChiSq.push_back(dbe->book1D("hSChiSqp11b","Segment Normalized Chi2 (ME +1/1b); Chi2/ndof",110,-0.05,10.5));
00320       hSChiSq.push_back(dbe->book1D("hSChiSqp12","Segment Normalized Chi2 (ME +1/2); Chi2/ndof",110,-0.05,10.5));
00321       hSChiSq.push_back(dbe->book1D("hSChiSqp13","Segment Normalized Chi2 (ME +1/3); Chi2/ndof",110,-0.05,10.5));
00322       hSChiSq.push_back(dbe->book1D("hSChiSqp11a","Segment Normalized Chi2 (ME +1/1a); Chi2/ndof",110,-0.05,10.5));
00323       hSChiSq.push_back(dbe->book1D("hSChiSqp21","Segment Normalized Chi2 (ME +2/1); Chi2/ndof",110,-0.05,10.5));
00324       hSChiSq.push_back(dbe->book1D("hSChiSqp22","Segment Normalized Chi2 (ME +2/2); Chi2/ndof",110,-0.05,10.5));
00325       hSChiSq.push_back(dbe->book1D("hSChiSqp31","Segment Normalized Chi2 (ME +3/1); Chi2/ndof",110,-0.05,10.5));
00326       hSChiSq.push_back(dbe->book1D("hSChiSqp32","Segment Normalized Chi2 (ME +3/2); Chi2/ndof",110,-0.05,10.5));
00327       hSChiSq.push_back(dbe->book1D("hSChiSqp41","Segment Normalized Chi2 (ME +4/1); Chi2/ndof",110,-0.05,10.5));
00328       hSChiSq.push_back(dbe->book1D("hSChiSqp42","Segment Normalized Chi2 (ME +4/2); Chi2/ndof",110,-0.05,10.5));
00329       hSChiSqProbAll = dbe->book1D("hSChiSqProb","Segment chi2 Probability; Probability",110,-0.05,1.05);
00330       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm42","Segment chi2 Probability (ME -4/2); Probability",110,-0.05,1.05));
00331       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm41","Segment chi2 Probability (ME -4/1); Probability",110,-0.05,1.05));
00332       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm32","Segment chi2 Probability (ME -3/2); Probability",110,-0.05,1.05));
00333       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm31","Segment chi2 Probability (ME -3/1); Probability",110,-0.05,1.05));
00334       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm22","Segment chi2 Probability (ME -2/2); Probability",110,-0.05,1.05));
00335       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm21","Segment chi2 Probability (ME -2/1); Probability",110,-0.05,1.05));
00336       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm11a","Segment chi2 Probability (ME -1/1a); Probability",110,-0.05,1.05));
00337       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm13","Segment chi2 Probability (ME -1/3); Probability",110,-0.05,1.05));
00338       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm12","Segment chi2 Probability (ME -1/2); Probability",110,-0.05,1.05));
00339       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbm11b","Segment chi2 Probability (ME -1/1b); Probability",110,-0.05,1.05));
00340       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp11b","Segment chi2 Probability (ME +1/1b); Probability",110,-0.05,1.05));
00341       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp12","Segment chi2 Probability (ME +1/2); Probability",110,-0.05,1.05));
00342       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp13","Segment chi2 Probability (ME +1/3); Probability",110,-0.05,1.05));
00343       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp11a","Segment chi2 Probability (ME +1/1a); Probability",110,-0.05,1.05));
00344       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp21","Segment chi2 Probability (ME +2/1); Probability",110,-0.05,1.05));
00345       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp22","Segment chi2 Probability (ME +2/2); Probability",110,-0.05,1.05));
00346       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp31","Segment chi2 Probability (ME +3/1); Probability",110,-0.05,1.05));
00347       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp32","Segment chi2 Probability (ME +3/2); Probability",110,-0.05,1.05));
00348       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp41","Segment chi2 Probability (ME +4/1); Probability",110,-0.05,1.05));
00349       hSChiSqProb.push_back(dbe->book1D("hSChiSqProbp42","Segment chi2 Probability (ME +4/2); Probability",110,-0.05,1.05));
00350       hSGlobalTheta = dbe->book1D("hSGlobalTheta","Segment Direction (Global Theta); Global Theta (radians)",136,-0.1,3.3);
00351       hSGlobalPhi   = dbe->book1D("hSGlobalPhi","Segment Direction (Global Phi); Global Phi (radians)",  128,-3.2,3.2);
00352       hSTimeCathode  = dbe->book1D("hSTimeCathode", "Cathode Only Segment Time  [ns]",200,-200,200);
00353       hSTimeCombined = dbe->book1D("hSTimeCombined", "Segment Time (anode+cathode times) [ns]",200,-200,200);
00354       hSTimeVsZ   = dbe->book2D("hSTimeVsZ","Segment Time vs. Z; [ns] vs. [cm]",200,-1200,1200,200,-200,200);
00355       hSTimeVsTOF = dbe->book2D("hSTimeVsTOF","Segment Time vs. Distance from IP; [ns] vs. [cm]",180,500,1400, 200,-200,200);
00356       // Resolution
00357       dbe->setCurrentFolder("CSC/CSCOfflineMonitor/Resolution");
00358       hSResid.push_back(dbe->book1D("hSResidm42","Fitted Position on Strip - Reconstructed for Layer 3 (ME -4/2); Strip Widths",100,-0.5,0.5));
00359       hSResid.push_back(dbe->book1D("hSResidm41","Fitted Position on Strip - Reconstructed for Layer 3 (ME -4/1); Strip Widths",100,-0.5,0.5));
00360       hSResid.push_back(dbe->book1D("hSResidm32","Fitted Position on Strip - Reconstructed for Layer 3 (ME -3/2); Strip Widths",100,-0.5,0.5));
00361       hSResid.push_back(dbe->book1D("hSResidm31","Fitted Position on Strip - Reconstructed for Layer 3 (ME -3/1); Strip Widths",100,-0.5,0.5));
00362       hSResid.push_back(dbe->book1D("hSResidm22","Fitted Position on Strip - Reconstructed for Layer 3 (ME -2/2); Strip Widths",100,-0.5,0.5));
00363       hSResid.push_back(dbe->book1D("hSResidm21","Fitted Position on Strip - Reconstructed for Layer 3 (ME -2/1); Strip Widths",100,-0.5,0.5));
00364       hSResid.push_back(dbe->book1D("hSResidm11a","Fitted Position on Strip - Reconstructed for Layer 3 (ME -1/1a); Strip Widths",100,-0.5,0.5));
00365       hSResid.push_back(dbe->book1D("hSResidm13","Fitted Position on Strip - Reconstructed for Layer 3 (ME -1/3); Strip Widths",100,-0.5,0.5));
00366       hSResid.push_back(dbe->book1D("hSResidm12","Fitted Position on Strip - Reconstructed for Layer 3 (ME -1/2); Strip Widths",100,-0.5,0.5));
00367       hSResid.push_back(dbe->book1D("hSResidm11b","Fitted Position on Strip - Reconstructed for Layer 3 (ME -1/1b); Strip Widths",100,-0.5,0.5));
00368       hSResid.push_back(dbe->book1D("hSResidp11b","Fitted Position on Strip - Reconstructed for Layer 3 (ME +1/1b); Strip Widths",100,-0.5,0.5));
00369       hSResid.push_back(dbe->book1D("hSResidp12","Fitted Position on Strip - Reconstructed for Layer 3 (ME +1/2); Strip Widths",100,-0.5,0.5));
00370       hSResid.push_back(dbe->book1D("hSResidp13","Fitted Position on Strip - Reconstructed for Layer 3 (ME +1/3); Strip Widths",100,-0.5,0.5));
00371       hSResid.push_back(dbe->book1D("hSResidp11a","Fitted Position on Strip - Reconstructed for Layer 3 (ME +1/1a); Strip Widths",100,-0.5,0.5));
00372       hSResid.push_back(dbe->book1D("hSResidp21","Fitted Position on Strip - Reconstructed for Layer 3 (ME +2/1); Strip Widths",100,-0.5,0.5));
00373       hSResid.push_back(dbe->book1D("hSResidp22","Fitted Position on Strip - Reconstructed for Layer 3 (ME +2/2); Strip Widths",100,-0.5,0.5));
00374       hSResid.push_back(dbe->book1D("hSResidp31","Fitted Position on Strip - Reconstructed for Layer 3 (ME +3/1); Strip Widths",100,-0.5,0.5));
00375       hSResid.push_back(dbe->book1D("hSResidp32","Fitted Position on Strip - Reconstructed for Layer 3 (ME +3/2); Strip Widths",100,-0.5,0.5));
00376       hSResid.push_back(dbe->book1D("hSResidp41","Fitted Position on Strip - Reconstructed for Layer 3 (ME +4/1); Strip Widths",100,-0.5,0.5));
00377       hSResid.push_back(dbe->book1D("hSResidp42","Fitted Position on Strip - Reconstructed for Layer 3 (ME +4/2); Strip Widths",100,-0.5,0.5));
00378 
00379       // Efficiency
00380       
00381       dbe->setCurrentFolder("CSC/CSCOfflineMonitor/Efficiency");
00382       hSSTE = dbe->book1D("hSSTE","hSSTE",40,0.5,40.5);
00383       hRHSTE = dbe->book1D("hRHSTE","hRHSTE",40,0.5,40.5);
00384       hSEff = dbe->book1D("hSEff","Segment Efficiency",20,0.5,20.5);
00385       hRHEff = dbe->book1D("hRHEff","recHit Efficiency",20,0.5,20.5);
00386       hSSTE2 = dbe->book2D("hSSTE2","hSSTE2",36,0.5,36.5, 18, 0.5, 18.5);
00387       hRHSTE2 = dbe->book2D("hRHSTE2","hRHSTE2",36,0.5,36.5, 18, 0.5, 18.5);
00388       hStripSTE2 = dbe->book2D("hStripSTE2","hStripSTE2",36,0.5,36.5, 18, 0.5, 18.5);
00389       hWireSTE2 = dbe->book2D("hWireSTE2","hWireSTE2",36,0.5,36.5, 18, 0.5, 18.5);
00390       hEffDenominator = dbe->book2D("hEffDenominator","hEffDenominator",36,0.5,36.5, 18, 0.5, 18.5);
00391       hSEff2 = dbe->book2D("hSEff2","Segment Efficiency 2D",36,0.5,36.5, 18, 0.5, 18.5);
00392       hRHEff2 = dbe->book2D("hRHEff2","recHit Efficiency 2D",36,0.5,36.5, 18, 0.5, 18.5);
00393       hStripReadoutEff2 = dbe->book2D("hStripReadoutEff2","strip readout ratio [(strip+clct+wires)/(clct+wires)] 2D",36,0.5,36.5, 20, 0.5, 20.5);
00394       hStripReadoutEff2->setAxisTitle("Chamber #");
00395       hStripEff2 = dbe->book2D("hStripEff2","strip Efficiency 2D",36,0.5,36.5, 18, 0.5, 18.5);
00396       hWireEff2 = dbe->book2D("hWireEff2","wire Efficiency 2D",36,0.5,36.5, 18, 0.5, 18.5);
00397       hSensitiveAreaEvt = dbe->book2D("hSensitiveAreaEvt","Events Passing Selection for Efficiency",36,0.5,36.5, 18, 0.5, 18.5);
00398 
00399       // BX Monitor for trigger synchronization
00400       dbe->setCurrentFolder("CSC/CSCOfflineMonitor/BXMonitor");
00401       hALCTgetBX = dbe->book1D("hALCTgetBX","ALCT position in ALCT-L1A match window [BX]",7,-0.5,6.5);
00402       hALCTgetBXChamberMeans = dbe->book1D("hALCTgetBXChamberMeans","Chamber Mean ALCT position in ALCT-L1A match window [BX]",60,0,6);
00403       hALCTgetBXSerial = dbe->book2D("hALCTgetBXSerial","ALCT position in ALCT-L1A match window [BX]",601,-0.5,600.5,7,-0.5,6.5);
00404       hALCTgetBXSerial->setAxisTitle("Chamber Serial Number");
00405       hALCTgetBX2DNumerator = dbe->book2D("hALCTgetBX2DNumerator","ALCT position in ALCT-L1A match window [BX] (sum)",36,0.5,36.5,20,0.5,20.5);
00406       hALCTgetBX2DMeans = dbe->book2D("hALCTgetBX2DMeans","ALCT position in ALCT-L1A match window [BX]",36,0.5,36.5,20,0.5,20.5);
00407       hALCTgetBX2Denominator = dbe->book2D("hALCTgetBX2Denominator","Number of ALCT Digis checked",36,0.5,36.5,20,0.5,20.5);
00408       hALCTgetBX2DMeans->setAxisTitle("Chamber #");
00409       hALCTgetBX2Denominator->setAxisTitle("Chamber #");
00410       hALCTMatch = dbe->book1D("hALCTMatch","ALCT position in ALCT-CLCT match window [BX]",7,-0.5,6.5);
00411       hALCTMatchChamberMeans = dbe->book1D("hALCTMatchChamberMeans","Chamber Mean ALCT position in ALCT-CLCT match window [BX]",60,0,6);
00412       hALCTMatchSerial = dbe->book2D("hALCTMatchSerial","ALCT position in ALCT-CLCT match window [BX]",601,-0.5,600.5,7,-0.5,6.5);
00413       hALCTMatchSerial->setAxisTitle("Chamber Serial Number");
00414       hALCTMatch2DNumerator = dbe->book2D("hALCTMatch2DNumerator","ALCT position in ALCT-CLCT match window [BX] (sum)",36,0.5,36.5,20,0.5,20.5);
00415       hALCTMatch2DMeans = dbe->book2D("hALCTMatch2DMeans","ALCT position in ALCT-CLCT match window [BX]",36,0.5,36.5,20,0.5,20.5);
00416       hALCTMatch2Denominator = dbe->book2D("hALCTMatch2Denominator","Number of ALCT-CLCT matches checked",36,0.5,36.5,20,0.5,20.5);
00417       hALCTMatch2DMeans->setAxisTitle("Chamber #");
00418       hALCTMatch2Denominator->setAxisTitle("Chamber #");
00419       hCLCTL1A = dbe->book1D("hCLCTL1A","L1A - CLCTpreTrigger at TMB [BX]",10,149.5,159.5);
00420       hCLCTL1AChamberMeans = dbe->book1D("hCLCTL1AChamberMeans","Chamber Mean L1A - CLCTpreTrigger at TMB [BX]",90,150,159);
00421       hCLCTL1ASerial = dbe->book2D("hCLCTL1ASerial","L1A - CLCTpreTrigger at TMB [BX]",601,-0.5,600.5,10,149.5,159.5);
00422       hCLCTL1ASerial->setAxisTitle("Chamber Serial Number");
00423       hCLCTL1A2DNumerator = dbe->book2D("hCLCTL1A2DNumerator","L1A - CLCTpreTrigger at TMB [BX] (sum)",36,0.5,36.5,20,0.5,20.5);
00424       hCLCTL1A2DMeans = dbe->book2D("hCLCTL1A2DMeans","L1A - CLCTpreTrigger at TMB [BX]",36,0.5,36.5,20,0.5,20.5);
00425       hCLCTL1A2Denominator = dbe->book2D("hCLCTL1A2Denominator","Number of TMB CLCTs checked",36,0.5,36.5,20,0.5,20.5);
00426 
00427 
00428       // Set all Labels
00429       applyCSClabels(hOWiresAndCLCT, EXTENDED, Y);
00430       applyCSClabels(hOWires, EXTENDED, Y);
00431       applyCSClabels(hOStrips, EXTENDED, Y);
00432       applyCSClabels(hOStripsAndWiresAndCLCT, EXTENDED, Y);
00433       applyCSClabels(hORecHits, EXTENDED, Y);
00434       applyCSClabels(hOSegments, EXTENDED, Y);
00435       applyCSClabels(hSEff, EXTENDED, X);
00436       applyCSClabels(hRHEff, EXTENDED, X);
00437       applyCSClabels(hSEff2, SMALL, Y);
00438       applyCSClabels(hSSTE2, SMALL, Y);
00439       applyCSClabels(hEffDenominator, SMALL, Y);
00440       applyCSClabels(hRHEff2, SMALL, Y);
00441       applyCSClabels(hRHSTE2, SMALL, Y);
00442       applyCSClabels(hStripReadoutEff2, EXTENDED, Y);
00443       applyCSClabels(hStripEff2, SMALL, Y);
00444       applyCSClabels(hStripSTE2, SMALL, Y);
00445       applyCSClabels(hWireEff2, SMALL, Y);
00446       applyCSClabels(hWireSTE2, SMALL, Y);
00447       applyCSClabels(hSensitiveAreaEvt, SMALL, Y);
00448       applyCSClabels(hALCTgetBX2DMeans, EXTENDED, Y);
00449       applyCSClabels(hALCTgetBX2Denominator, EXTENDED, Y);
00450       applyCSClabels(hALCTMatch2DMeans, EXTENDED, Y);
00451       applyCSClabels(hALCTMatch2Denominator, EXTENDED, Y);
00452       applyCSClabels(hCLCTL1A2DMeans, EXTENDED, Y);
00453       applyCSClabels(hCLCTL1A2Denominator,EXTENDED, Y);
00454 }
00455 
00457 //  DESTRUCTOR  //
00459 CSCOfflineMonitor::~CSCOfflineMonitor(){
00460 
00461 }
00462 
00463 void CSCOfflineMonitor::endRun( edm::Run const &, edm::EventSetup const & ){
00464   
00465   if (!finalizedHistograms_){
00466     finalize() ;
00467     finalizedHistograms_ = true ;
00468   }
00469 
00470 }
00471 
00472 void CSCOfflineMonitor::endJob(){
00473   
00474   finalize() ;
00475   finalizedHistograms_ = true ;
00476   
00477   bool saveHistos = param.getParameter<bool>("saveHistos");
00478   string outputFileName = param.getParameter<string>("outputFileName");
00479   if(saveHistos){
00480     dbe->save(outputFileName);
00481   }
00482 
00483 }
00484 
00485 
00486 void CSCOfflineMonitor::finalize() {
00487 
00488   hRHEff = dbe->get("CSC/CSCOfflineMonitor/Efficiency/hRHEff");
00489   hSEff = dbe->get("CSC/CSCOfflineMonitor/Efficiency/hSEff");
00490   hSEff2 = dbe->get("CSC/CSCOfflineMonitor/Efficiency/hSEff2");
00491   hRHEff2 = dbe->get("CSC/CSCOfflineMonitor/Efficiency/hRHEff2");
00492   hStripEff2 = dbe->get("CSC/CSCOfflineMonitor/Efficiency/hStripEff2");
00493   hWireEff2 = dbe->get("CSC/CSCOfflineMonitor/Efficiency/hWireEff2");
00494 
00495   hOStripsAndWiresAndCLCT= dbe->get("CSC/CSCOfflineMonitor/Occupancy/hOStripsAndWiresAndCLCT");
00496   hOWiresAndCLCT= dbe->get("CSC/CSCOfflineMonitor/Occupancy/hOWiresAndCLCT");
00497   hStripReadoutEff2 = dbe->get("CSC/CSCOfflineMonitor/Efficiency/hStripReadoutEff2");
00498 
00499   hALCTgetBX2DMeans = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hALCTgetBX2DMeans");
00500   hALCTMatch2DMeans = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hALCTMatch2DMeans");
00501   hCLCTL1A2DMeans   = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hCLCTL1A2DMeans");
00502 
00503   hALCTgetBXSerial = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hALCTgetBXSerial");
00504   hALCTMatchSerial = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hALCTMatchSerial");
00505   hCLCTL1ASerial   = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hCLCTL1ASerial");
00506 
00507   hALCTgetBXChamberMeans = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hALCTgetBXChamberMeans");
00508   hALCTMatchChamberMeans = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hALCTMatchChamberMeans");
00509   hCLCTL1AChamberMeans   = dbe->get("CSC/CSCOfflineMonitor/BXMonitor/hCLCTL1AChamberMeans");
00510 
00511   if (hRHEff) histoEfficiency(hRHSTE->getTH1F(),hRHEff);
00512   if (hSEff) histoEfficiency(hSSTE->getTH1F(),hSEff);
00513   if (hSEff2) hSEff2->getTH2F()->Divide(hSSTE2->getTH2F(),\
00514                                         hEffDenominator->getTH2F(), 1., 1.,"B");
00515   if (hRHEff2) hRHEff2->getTH2F()->Divide(hRHSTE2->getTH2F(),\
00516                                           hEffDenominator->getTH2F(), 1., 1., "B");
00517   if (hStripEff2) hStripEff2->getTH2F()->Divide(hStripSTE2->getTH2F(),\
00518                                                 hEffDenominator->getTH2F(), 1., 1., "B");
00519   if (hWireEff2) hWireEff2->getTH2F()->Divide(hWireSTE2->getTH2F(),\
00520                                               hEffDenominator->getTH2F(), 1., 1., "B");
00521   if (hStripReadoutEff2) hStripReadoutEff2->getTH2F()->Divide(hOStripsAndWiresAndCLCT->getTH2F(),\
00522                                                               hOWiresAndCLCT->getTH2F(), 1., 1., "B");
00523   if (hALCTMatch2DMeans){ 
00524     harvestChamberMeans(hALCTMatchChamberMeans,\
00525                         hALCTMatch2DMeans,\
00526                         hALCTMatch2DNumerator,\
00527                         hALCTMatch2Denominator );
00528   }
00529   if (hALCTgetBX2DMeans) {
00530     harvestChamberMeans(hALCTgetBXChamberMeans,\
00531                         hALCTgetBX2DMeans,\
00532                         hALCTgetBX2DNumerator,\
00533                         hALCTgetBX2Denominator );
00534   }
00535   if (hCLCTL1A2DMeans) {
00536     harvestChamberMeans(hCLCTL1AChamberMeans,\
00537                         hCLCTL1A2DMeans,\
00538                         hCLCTL1A2DNumerator,\
00539                         hCLCTL1A2Denominator );
00540   }
00541 
00542   if(hALCTgetBXSerial)  normalize(hALCTgetBXSerial);
00543   if(hALCTMatchSerial)  normalize(hALCTMatchSerial);
00544   if(hCLCTL1ASerial)    normalize(hCLCTL1ASerial);
00545 
00546 
00547 }
00548 
00549 void CSCOfflineMonitor::harvestChamberMeans(MonitorElement* meMean1D,\
00550                                             MonitorElement *meMean2D,\
00551                                             MonitorElement *hNum,\
00552                                             MonitorElement *meDenom){
00553 
00554 
00555   if (hNum->getNbinsY()!= meDenom->getNbinsY() || hNum->getNbinsX()!= meDenom->getNbinsX())
00556     return;
00557   if (meMean2D->getNbinsY()!= meDenom->getNbinsY() || meMean2D->getNbinsX()!= meDenom->getNbinsX())
00558     return;
00559 
00560   float mean;
00561   for (int biny = 0; biny < hNum->getNbinsY()+1 ; biny++){
00562     for (int binx = 0; binx < hNum->getNbinsX()+1 ; binx++){
00563       if ( meDenom->getBinContent(binx,biny) > 0){
00564         mean = hNum->getBinContent(binx,biny)/meDenom->getBinContent(binx,biny);
00565         meMean1D->Fill(mean);
00566         meMean2D->setBinContent(binx,biny,mean);
00567       }
00568     }
00569   }
00570 
00571   return;
00572 }
00573 
00574 void CSCOfflineMonitor::normalize(MonitorElement* me){
00575     
00576   TH2F* h = me->getTH2F();
00577   if (! h)
00578     return;
00579   TH1D* hproj = h->ProjectionX("hproj");
00580 
00581   for (int binx = 0; binx < h->GetNbinsX()+1 ; binx++){
00582     Double_t entries = hproj->GetBinContent(binx);
00583     for (Int_t biny=1;biny <= h->GetNbinsY();biny++) {
00584       Double_t cxy = h->GetBinContent(binx,biny);
00585       if (cxy > 0 && entries>0) h->SetBinContent(binx,biny,cxy/entries);
00586     }
00587   }
00588 
00589 
00590     return;
00591 
00592 }
00593 
00594 
00595 
00597 //  Analysis  //
00599 void CSCOfflineMonitor::analyze(const Event & event, const EventSetup& eventSetup){
00600 
00601   edm::Handle<CSCWireDigiCollection> wires;
00602   edm::Handle<CSCStripDigiCollection> strips;
00603   edm::Handle<CSCALCTDigiCollection> alcts;
00604   edm::Handle<CSCCLCTDigiCollection> clcts;
00605   event.getByLabel(stripDigiTag_, strips);
00606   event.getByLabel(wireDigiTag_, wires);
00607   event.getByLabel(alctDigiTag_, alcts);
00608   event.getByLabel(clctDigiTag_, clcts);
00609 
00610   // Get the CSC Geometry :
00611   ESHandle<CSCGeometry> cscGeom;
00612   eventSetup.get<MuonGeometryRecord>().get(cscGeom);
00613 
00614   // Get the RecHits collection :
00615   Handle<CSCRecHit2DCollection> recHits;
00616   event.getByLabel(cscRecHitTag_,recHits);
00617 
00618   // get CSC segment collection
00619   Handle<CSCSegmentCollection> cscSegments;
00620   event.getByLabel(cscSegTag_, cscSegments);
00621 
00622 
00623   doOccupancies(strips,wires,recHits,cscSegments,clcts);
00624   doStripDigis(strips);
00625   doWireDigis(wires);
00626   doRecHits(recHits,strips,cscGeom);
00627   doSegments(cscSegments,cscGeom);
00628   doResolution(cscSegments,cscGeom);
00629   doPedestalNoise(strips);
00630   doEfficiencies(wires,strips, recHits, cscSegments,cscGeom);
00631   doBXMonitor(alcts, clcts, event, eventSetup);
00632 }
00633 
00634 // ==============================================
00635 //
00636 // look at Occupancies
00637 //
00638 // ==============================================
00639 
00640 void CSCOfflineMonitor::doOccupancies(edm::Handle<CSCStripDigiCollection> strips, edm::Handle<CSCWireDigiCollection> wires,
00641                                       edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<CSCSegmentCollection> cscSegments,
00642                                       edm::Handle<CSCCLCTDigiCollection> clcts){
00643 
00644   bool clcto[2][4][4][36];
00645   bool wireo[2][4][4][36];
00646   bool stripo[2][4][4][36];
00647   bool rechito[2][4][4][36];
00648   bool segmento[2][4][4][36];
00649 
00650   bool hasWires = false;
00651   bool hasStrips = false;
00652   bool hasRecHits = false;
00653   bool hasSegments = false;
00654 
00655   for (int e = 0; e < 2; e++){
00656     for (int s = 0; s < 4; s++){
00657       for (int r = 0; r < 4; r++){
00658         for (int c = 0; c < 36; c++){
00659           clcto[e][s][r][c] = false;
00660           wireo[e][s][r][c] = false;
00661           stripo[e][s][r][c] = false;
00662           rechito[e][s][r][c] = false;
00663           segmento[e][s][r][c] = false;
00664         }
00665       }
00666     }
00667   }
00668 
00669   //clcts
00670   for (CSCCLCTDigiCollection::DigiRangeIterator j=clcts->begin(); j!=clcts->end(); j++) {
00671     CSCDetId id = (CSCDetId)(*j).first;
00672     int kEndcap  = id.endcap();
00673     int kRing    = id.ring();
00674     int kStation = id.station();
00675     int kChamber = id.chamber();
00676     const CSCCLCTDigiCollection::Range& range =(*j).second;
00677     for (CSCCLCTDigiCollection::const_iterator digiIt = range.first; digiIt!=range.second; ++digiIt){
00678       // Valid digi in the chamber (or in neighbouring chamber) 
00679       if((*digiIt).isValid()){
00680       //Check whether this CLCT came from ME11a
00681         if( kStation ==1 && kRing==1 && (*digiIt).getKeyStrip()>128)
00682           kRing = 4;
00683         clcto[kEndcap-1][kStation-1][kRing-1][kChamber-1] = true;
00684       }
00685     }
00686   }
00687 
00688   //wires
00689   for (CSCWireDigiCollection::DigiRangeIterator wi=wires->begin(); wi!=wires->end(); wi++) {
00690     CSCDetId id = (CSCDetId)(*wi).first;
00691     int kEndcap  = id.endcap();
00692     int kRing    = id.ring();
00693     int kStation = id.station();
00694     int kChamber = id.chamber();
00695     std::vector<CSCWireDigi>::const_iterator wireIt = (*wi).second.first;
00696     std::vector<CSCWireDigi>::const_iterator lastWire = (*wi).second.second;
00697     for( ; wireIt != lastWire; ++wireIt){
00698       if (!wireo[kEndcap-1][kStation-1][kRing-1][kChamber-1]){
00699         wireo[kEndcap-1][kStation-1][kRing-1][kChamber-1] = true;
00700         hOWires->Fill(kChamber,typeIndex(id,2));
00701         hOWireSerial->Fill(chamberSerial(id));
00702         hasWires = true;
00703         if( clcto[kEndcap-1][kStation-1][kRing-1][kChamber-1])
00704           hOWiresAndCLCT->Fill(kChamber,typeIndex(id,2));
00705         //Also check for a CLCT in ME11a if you're in ME11 already
00706         if (kStation==1 && kRing==1 && clcto[kEndcap-1][kStation-1][3][kChamber-1]){
00707           CSCDetId idME11a = CSCDetId(kEndcap, kStation, 4, kChamber);
00708           hOWiresAndCLCT->Fill(kChamber,typeIndex(idME11a,2));
00709         } 
00710       }
00711     }//end for loop
00712   }
00713   
00714   //strips
00715   for (CSCStripDigiCollection::DigiRangeIterator si=strips->begin(); si!=strips->end(); si++) {
00716     CSCDetId id = (CSCDetId)(*si).first;
00717     int kEndcap  = id.endcap();
00718     int kRing    = id.ring();
00719     int kStation = id.station();
00720     int kChamber = id.chamber();
00721     std::vector<CSCStripDigi>::const_iterator stripIt = (*si).second.first;
00722     std::vector<CSCStripDigi>::const_iterator lastStrip = (*si).second.second;
00723     for( ; stripIt != lastStrip; ++stripIt) {
00724       std::vector<int> myADCVals = stripIt->getADCCounts();
00725       bool thisStripFired = false;
00726       float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
00727       float threshold = 13.3 ;
00728       float diff = 0.;
00729       for (unsigned int iCount = 0; iCount < myADCVals.size(); iCount++) {
00730         diff = (float)myADCVals[iCount]-thisPedestal;
00731         if (diff > threshold) { thisStripFired = true; }
00732       }
00733       if (thisStripFired) {
00734         if (!stripo[kEndcap-1][kStation-1][kRing-1][kChamber-1]){
00735           stripo[kEndcap-1][kStation-1][kRing-1][kChamber-1] = true;
00736           hOStrips->Fill(kChamber,typeIndex(id,2));
00737           hOStripSerial->Fill(chamberSerial(id));
00738           hasStrips = true;
00739           if (clcto[kEndcap-1][kStation-1][kRing-1][kChamber-1]){
00740             // check if there is a wire digi in this chamber too
00741             // for ME 1/4 check for a wire in ME 1/1
00742             if(wireo[kEndcap-1][kStation-1][kRing-1][kChamber-1] || (kRing==4 && wireo[kEndcap-1][kStation-1][0][kChamber-1]) ){
00743               hOStripsAndWiresAndCLCT->Fill(kChamber,typeIndex(id,2));
00744             }
00745           }//end clct and wire digi check
00746         }
00747       }//end if (thisStripFired)
00748     }
00749   }
00750 
00751   //rechits
00752   CSCRecHit2DCollection::const_iterator recIt;
00753   for (recIt = recHits->begin(); recIt != recHits->end(); recIt++) {
00754     CSCDetId idrec = (CSCDetId)(*recIt).cscDetId();
00755     int kEndcap  = idrec.endcap();
00756     int kRing    = idrec.ring();
00757     int kStation = idrec.station();
00758     int kChamber = idrec.chamber();
00759     if (!rechito[kEndcap-1][kStation-1][kRing-1][kChamber-1]){
00760       rechito[kEndcap-1][kStation-1][kRing-1][kChamber-1] = true;
00761       hORecHitsSerial->Fill(chamberSerial(idrec));
00762       hORecHits->Fill(kChamber,typeIndex(idrec,2));
00763       hasRecHits = true;
00764     }
00765   }
00766 
00767   //segments
00768   for(CSCSegmentCollection::const_iterator segIt=cscSegments->begin(); segIt != cscSegments->end(); segIt++) {
00769     CSCDetId id  = (CSCDetId)(*segIt).cscDetId();
00770     int kEndcap  = id.endcap();
00771     int kRing    = id.ring();
00772     int kStation = id.station();
00773     int kChamber = id.chamber();
00774     if (!segmento[kEndcap-1][kStation-1][kRing-1][kChamber-1]){
00775       segmento[kEndcap-1][kStation-1][kRing-1][kChamber-1] = true;
00776       hOSegmentsSerial->Fill(chamberSerial(id));
00777       hOSegments->Fill(kChamber,typeIndex(id,2));
00778       hasSegments = true;
00779     }
00780   }
00781 
00782   //Overall CSC Occupancy
00783   hCSCOccupancy->Fill(1);
00784   if (hasWires) hCSCOccupancy->Fill(3);
00785   if (hasStrips) hCSCOccupancy->Fill(5);
00786   if (hasWires && hasStrips) hCSCOccupancy->Fill(7);
00787   if (hasRecHits) hCSCOccupancy->Fill(9);
00788   if (hasSegments) hCSCOccupancy->Fill(11);
00789 
00790 
00791   }
00792 
00793 
00794 // ==============================================
00795 //
00796 // look at WIRE DIGIs
00797 //
00798 // ==============================================
00799 
00800 void CSCOfflineMonitor::doWireDigis(edm::Handle<CSCWireDigiCollection> wires){
00801 
00802   int nWireGroupsTotal = 0;
00803   for (CSCWireDigiCollection::DigiRangeIterator dWDiter=wires->begin(); dWDiter!=wires->end(); dWDiter++) {
00804     CSCDetId id = (CSCDetId)(*dWDiter).first;
00805     std::vector<CSCWireDigi>::const_iterator wireIter = (*dWDiter).second.first;
00806     std::vector<CSCWireDigi>::const_iterator lWire = (*dWDiter).second.second;
00807     for( ; wireIter != lWire; ++wireIter) {
00808       int myWire = wireIter->getWireGroup();
00809       int myTBin = wireIter->getTimeBin();
00810       nWireGroupsTotal++;
00811       hWireTBin[typeIndex(id)-1]->Fill(myTBin);
00812       hWireNumber[typeIndex(id)-1]->Fill(myWire);
00813     }
00814   } // end wire loop
00815 
00816   // this way you can zero suppress but still store info on # events with no digis
00817   if (nWireGroupsTotal == 0) nWireGroupsTotal = -1;
00818   hWirenGroupsTotal->Fill(nWireGroupsTotal);
00819   
00820 }
00821 
00822 
00823 // ==============================================
00824 //
00825 // look at STRIP DIGIs
00826 //
00827 // ==============================================
00828 
00829 void CSCOfflineMonitor::doStripDigis(edm::Handle<CSCStripDigiCollection> strips){
00830 
00831   int nStripsFired = 0;
00832   for (CSCStripDigiCollection::DigiRangeIterator dSDiter=strips->begin(); dSDiter!=strips->end(); dSDiter++) {
00833     CSCDetId id = (CSCDetId)(*dSDiter).first;
00834     std::vector<CSCStripDigi>::const_iterator stripIter = (*dSDiter).second.first;
00835     std::vector<CSCStripDigi>::const_iterator lStrip = (*dSDiter).second.second;
00836     for( ; stripIter != lStrip; ++stripIter) {
00837       int myStrip = stripIter->getStrip();
00838       std::vector<int> myADCVals = stripIter->getADCCounts();
00839       bool thisStripFired = false;
00840       float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
00841       float threshold = 13.3 ;
00842       float diff = 0.;
00843       for (unsigned int iCount = 0; iCount < myADCVals.size(); iCount++) {
00844         diff = (float)myADCVals[iCount]-thisPedestal;
00845         if (diff > threshold) { thisStripFired = true; }
00846       } 
00847       if (thisStripFired) {
00848         nStripsFired++;
00849         hStripNumber[typeIndex(id)-1]->Fill(myStrip);
00850       }
00851     }
00852   } // end strip loop
00853 
00854   // this way you can zero suppress but still store info on # events with no digis
00855   if (nStripsFired == 0) nStripsFired = -1;
00856   hStripNFired->Fill(nStripsFired);
00857   // fill n per event
00858 
00859 }
00860 
00861 
00862 //=======================================================
00863 //
00864 // Look at the Pedestal Noise Distributions
00865 //
00866 //=======================================================
00867 
00868 void CSCOfflineMonitor::doPedestalNoise(edm::Handle<CSCStripDigiCollection> strips){
00869 
00870   for (CSCStripDigiCollection::DigiRangeIterator dPNiter=strips->begin(); dPNiter!=strips->end(); dPNiter++) {
00871     CSCDetId id = (CSCDetId)(*dPNiter).first;
00872     int kStation = id.station();
00873     int kRing = id.ring();
00874     std::vector<CSCStripDigi>::const_iterator pedIt = (*dPNiter).second.first;
00875     std::vector<CSCStripDigi>::const_iterator lStrip = (*dPNiter).second.second;
00876     for( ; pedIt != lStrip; ++pedIt) {
00877       int myStrip = pedIt->getStrip();
00878       std::vector<int> myADCVals = pedIt->getADCCounts();
00879       float TotalADC = getSignal(*strips, id, myStrip);
00880       bool thisStripFired = false;
00881       float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
00882       float thisSignal = (1./6)*(myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
00883       float threshold = 13.3;
00884       if(kStation == 1 && kRing == 4)
00885         {
00886           kRing = 1;
00887           if(myStrip <= 16) myStrip += 64; // no trapping for any bizarreness
00888         }
00889       if (TotalADC > threshold) { thisStripFired = true;}
00890       if (!thisStripFired){
00891         float ADC = thisSignal - thisPedestal;
00892         hStripPed[typeIndex(id)-1]->Fill(ADC);
00893       }
00894     }
00895   }
00896 
00897 }
00898 
00899 
00900 // ==============================================
00901 //
00902 // look at RECHITs
00903 //
00904 // ==============================================
00905 
00906 void CSCOfflineMonitor::doRecHits(edm::Handle<CSCRecHit2DCollection> recHits,
00907                                   edm::Handle<CSCStripDigiCollection> strips,
00908                                   edm::ESHandle<CSCGeometry> cscGeom){
00909 
00910   // Get the RecHits collection :
00911   int nRecHits = recHits->size();
00912   
00913   // ---------------------
00914   // Loop over rechits 
00915   // ---------------------
00916   // Build iterator for rechits and loop :
00917   CSCRecHit2DCollection::const_iterator dRHIter;
00918   for (dRHIter = recHits->begin(); dRHIter != recHits->end(); dRHIter++) {
00919 
00920     // Find chamber with rechits in CSC 
00921     CSCDetId idrec = (CSCDetId)(*dRHIter).cscDetId();
00922 
00923     // Store rechit as a Local Point:
00924     LocalPoint rhitlocal = (*dRHIter).localPosition();  
00925     //float xreco = rhitlocal.x();
00926     //float yreco = rhitlocal.y();
00927 
00928     // Get the reconstucted strip position and error
00929     float stpos = (*dRHIter).positionWithinStrip();
00930     float sterr = (*dRHIter).errorWithinStrip();
00931 
00933     
00934     int adcsize = dRHIter->nStrips()*dRHIter->nTimeBins();
00935     float rHSumQ = 0;
00936     float sumsides = 0;
00937     for (unsigned int i = 0; i < dRHIter->nStrips(); i++){
00938       for (unsigned int j=0; j<dRHIter->nTimeBins()-1; j++) {
00939         rHSumQ+=dRHIter->adcs(i,j);
00940         if ( i != 1 ) sumsides += dRHIter->adcs(i,j); // skip central strip
00941       }
00942     }   
00943 
00944     float rHratioQ = sumsides/rHSumQ;
00945     if (adcsize != 12) rHratioQ = -99;
00946 
00947     // Get the signal timing of this hit
00948     float rHtime = (*dRHIter).tpeak(); //calculated from cathode SCA bins
00949     float rHtimeAnode = (*dRHIter).wireTime(); // calculated from anode wire bx
00950 
00951     // Get pointer to the layer:
00952     const CSCLayer* csclayer = cscGeom->layer( idrec );
00953 
00954     // Transform hit position from local chamber geometry to global CMS geom
00955     GlobalPoint rhitglobal= csclayer->toGlobal(rhitlocal);
00956     float grecx   =  rhitglobal.x();
00957     float grecy   =  rhitglobal.y();
00958 
00959     // Fill some histograms
00960     int sIndex = idrec.station() + ((idrec.endcap()-1) * 4);
00961     int tIndex = typeIndex(idrec);
00962     hRHSumQ[tIndex-1]->Fill(rHSumQ);
00963     hRHRatioQ[tIndex-1]->Fill(rHratioQ);
00964     hRHstpos[tIndex-1]->Fill(stpos);
00965     hRHsterr[tIndex-1]->Fill(sterr);
00966     hRHTiming[tIndex-1]->Fill(rHtime);
00967     hRHTimingAnode[tIndex-1]->Fill(rHtimeAnode);
00968     hRHGlobal[sIndex-1]->Fill(grecx,grecy);
00969 
00970   } //end rechit loop
00971 
00972   if (nRecHits == 0) nRecHits = -1;
00973   hRHnrechits->Fill(nRecHits);
00974 
00975 }
00976 
00977 
00978 // ==============================================
00979 //
00980 // look at SEGMENTs
00981 //
00982 // ===============================================
00983 
00984 void CSCOfflineMonitor::doSegments(edm::Handle<CSCSegmentCollection> cscSegments,
00985                                    edm::ESHandle<CSCGeometry> cscGeom){
00986 
00987   // get CSC segment collection
00988   int nSegments = cscSegments->size();
00989 
00990   for(CSCSegmentCollection::const_iterator dSiter=cscSegments->begin(); dSiter != cscSegments->end(); dSiter++) {
00991     CSCDetId id  = (CSCDetId)(*dSiter).cscDetId();
00992     float chisq    = (*dSiter).chi2();
00993     int nhits      = (*dSiter).nRecHits();
00994     int nDOF       = 2*nhits-4;
00995     float nChi2    = chisq/nDOF;
00996     double chisqProb = ChiSquaredProbability( (double)chisq, nDOF );
00997     LocalPoint localPos = (*dSiter).localPosition();
00998     LocalVector segDir = (*dSiter).localDirection();
00999 
01000     // prepare to calculate segment times 
01001     float timeCathode = 0;  //average from cathode information alone
01002     float timeAnode = 0;  //average from pruned anode information alone
01003     float timeCombined = 0; //average from cathode hits and pruned anode list
01004     std::vector<float> cathodeTimes;
01005     std::vector<float> anodeTimes;
01006     // Get the CSC recHits that contribute to this segment.
01007     std::vector<CSCRecHit2D> theseRecHits = (*dSiter).specificRecHits();
01008     for ( vector<CSCRecHit2D>::const_iterator iRH = theseRecHits.begin(); iRH != theseRecHits.end(); iRH++) {
01009       if ( !((*iRH).isValid()) ) continue;  // only interested in valid hits
01010       cathodeTimes.push_back((*iRH).tpeak());
01011       anodeTimes.push_back((*iRH).wireTime());
01012     }//end rechit loop
01013     
01014     // Calculate cathode average
01015     for (unsigned int i=0; i<cathodeTimes.size(); i++) 
01016         timeCathode+=cathodeTimes[i]/cathodeTimes.size();
01017     
01018     // Prune the anode list to deal with the late tail 
01019     float anodeMaxDiff;
01020     bool modified = false;
01021     std::vector<float>::iterator anodeMaxHit;
01022     do {
01023       if (anodeTimes.size()==0) continue;
01024       timeAnode=0;
01025       anodeMaxDiff=0;
01026       modified=false;
01027 
01028       // Find the average
01029       for (unsigned int j=0; j<anodeTimes.size(); j++) timeAnode+=anodeTimes[j]/anodeTimes.size();
01030 
01031       // Find the maximum outlier hit
01032       for (unsigned int j=0; j<anodeTimes.size(); j++) {
01033         if (fabs(anodeTimes[j]-timeAnode)>anodeMaxDiff) {
01034           anodeMaxHit=anodeTimes.begin()+j;
01035           anodeMaxDiff=fabs(anodeTimes[j]-timeAnode);
01036         }
01037       }
01038       
01039       // Cut hit if its greater than some time away
01040       if (anodeMaxDiff>26) {
01041         modified=true;
01042         anodeTimes.erase(anodeMaxHit);
01043       }
01044     } while (modified);
01045 
01046     // Calculate combined anode and cathode time average
01047     if(cathodeTimes.size()+anodeTimes.size() >0 )
01048       timeCombined = (timeCathode*cathodeTimes.size() + timeAnode*anodeTimes.size())/(cathodeTimes.size()+anodeTimes.size());
01049 
01050     // global transformation
01051     float globX = 0.;
01052     float globY = 0.;
01053     float globZ = 0.;
01054     float globTOF = 0.;
01055     float globTheta = 0.;
01056     float globPhi   = 0.;
01057     const CSCChamber* cscchamber = cscGeom->chamber(id);
01058     if (cscchamber) {
01059       GlobalPoint globalPosition = cscchamber->toGlobal(localPos);
01060       globX = globalPosition.x();
01061       globY = globalPosition.y();
01062       globZ = globalPosition.z();
01063       globTOF = sqrt(globX*globX+globY*globY+globZ*globZ);
01064       GlobalVector globalDirection = cscchamber->toGlobal(segDir);
01065       globTheta = globalDirection.theta();
01066       globPhi   = globalDirection.phi();
01067     }
01068 
01069     // Fill histos
01070     int tIndex = typeIndex(id);
01071     hSnhitsAll->Fill(nhits);
01072     hSnhits[tIndex-1]->Fill(nhits);
01073     hSChiSqAll->Fill(nChi2);
01074     hSChiSq[tIndex-1]->Fill(nChi2);
01075     hSChiSqProbAll->Fill(chisqProb);
01076     hSChiSqProb[tIndex-1]->Fill(chisqProb);
01077     hSGlobalTheta->Fill(globTheta);
01078     hSGlobalPhi->Fill(globPhi);
01079     hSTimeCathode->Fill(timeCathode);
01080     hSTimeCombined->Fill(timeCombined);
01081     hSTimeVsZ->Fill(globZ, timeCombined);
01082     hSTimeVsTOF->Fill(globTOF, timeCombined);
01083 
01084   } // end segment loop
01085 
01086   if (nSegments == 0) nSegments = -1;
01087   hSnSegments->Fill(nSegments);
01088 
01089 }
01090 
01091 // ==============================================
01092 //
01093 // look at hit Resolution
01094 //
01095 // ==============================================
01096 void CSCOfflineMonitor::doResolution(edm::Handle<CSCSegmentCollection> cscSegments,
01097                                      edm::ESHandle<CSCGeometry> cscGeom){
01098 
01099   for(CSCSegmentCollection::const_iterator dSiter=cscSegments->begin(); dSiter != cscSegments->end(); dSiter++) {
01100     CSCDetId id  = (CSCDetId)(*dSiter).cscDetId();
01101     //
01102     // try to get the CSC recHits that contribute to this segment.
01103     std::vector<CSCRecHit2D> theseRecHits = (*dSiter).specificRecHits();
01104     int nRH = (*dSiter).nRecHits();
01105     int jRH = 0;
01106     CLHEP::HepMatrix sp(6,1);
01107     CLHEP::HepMatrix se(6,1);
01108     for ( vector<CSCRecHit2D>::const_iterator iRH = theseRecHits.begin(); iRH != theseRecHits.end(); iRH++) {
01109       jRH++;
01110       CSCDetId idRH = (CSCDetId)(*iRH).cscDetId();
01111       //int kEndcap  = idRH.endcap();
01112       int kRing    = idRH.ring();
01113       int kStation = idRH.station();
01114       //int kChamber = idRH.chamber();
01115       int kLayer   = idRH.layer();
01116 
01118       int centerid    =  iRH->nStrips()/2 + 1;
01119       int centerStrip =  iRH->channels(centerid - 1);   
01120 
01121       // If this segment has 6 hits, find the position of each hit on the strip in units of stripwidth and store values
01122       if (nRH == 6){
01123         float stpos = (*iRH).positionWithinStrip();
01124         se(kLayer,1) = (*iRH).errorWithinStrip();
01125         // Take into account half-strip staggering of layers (ME1/1 has no staggering)
01126         if (kStation == 1 && (kRing == 1 || kRing == 4)) sp(kLayer,1) = stpos + centerStrip;
01127         else{
01128           if (kLayer == 1 || kLayer == 3 || kLayer == 5) sp(kLayer,1) = stpos + centerStrip;
01129           if (kLayer == 2 || kLayer == 4 || kLayer == 6) sp(kLayer,1) = stpos - 0.5 + centerStrip;
01130         }
01131       }
01132 
01133     }
01134 
01135     float residual = -99;
01136     // Fit all points except layer 3, then compare expected value for layer 3 to reconstructed value
01137     if (nRH == 6){
01138       float expected = fitX(sp,se);
01139       residual = expected - sp(3,1);
01140     }
01141 
01142     hSResid[typeIndex(id)-1]->Fill(residual);
01143 
01144   } // end segment loop
01145 
01146 
01147 
01148 }
01149 
01150 
01151 //-------------------------------------------------------------------------------------
01152 // Fits a straight line to a set of 5 points with errors.  Functions assumes 6 points
01153 // and removes hit in layer 3.  It then returns the expected position value in layer 3
01154 // based on the fit.
01155 //-------------------------------------------------------------------------------------
01156 float CSCOfflineMonitor::fitX(CLHEP::HepMatrix points, CLHEP::HepMatrix errors){
01157 
01158   float S   = 0;
01159   float Sx  = 0;
01160   float Sy  = 0;
01161   float Sxx = 0;
01162   float Sxy = 0;
01163   float sigma2 = 0;
01164 
01165   for (int i=1;i<7;i++){
01166     if (i != 3){
01167       sigma2 = errors(i,1)*errors(i,1);
01168       S = S + (1/sigma2);
01169       Sy = Sy + (points(i,1)/sigma2);
01170       Sx = Sx + ((i)/sigma2);
01171       Sxx = Sxx + (i*i)/sigma2;
01172       Sxy = Sxy + (((i)*points(i,1))/sigma2);
01173     }
01174   }
01175 
01176   float delta = S*Sxx - Sx*Sx;
01177   float intercept = (Sxx*Sy - Sx*Sxy)/delta;
01178   float slope = (S*Sxy - Sx*Sy)/delta;
01179 
01180   return (intercept + slope*3);
01181 
01182 }
01183 
01184 //---------------------------------------------------------------------------------------
01185 // Given a set of digis, the CSCDetId, and the central strip of your choosing, returns
01186 // the avg. Signal-Pedestal for 6 time bin x 5 strip .
01187 //
01188 // Author: P. Jindal
01189 //---------------------------------------------------------------------------------------
01190 
01191 float CSCOfflineMonitor::getSignal(const CSCStripDigiCollection& stripdigis, 
01192                                    CSCDetId idCS, int centerStrip){
01193 
01194   float SigADC[5];
01195   float TotalADC = 0;
01196   SigADC[0] = 0;
01197   SigADC[1] = 0;
01198   SigADC[2] = 0;
01199   SigADC[3] = 0;
01200   SigADC[4] = 0;
01201 
01202  
01203   // Loop over strip digis 
01204   CSCStripDigiCollection::DigiRangeIterator sIt;
01205   
01206   for (sIt = stripdigis.begin(); sIt != stripdigis.end(); sIt++){
01207     CSCDetId id = (CSCDetId)(*sIt).first;
01208     if (id == idCS){
01209 
01210       // First, find the Signal-Pedestal for center strip
01211       vector<CSCStripDigi>::const_iterator digiItr = (*sIt).second.first;
01212       vector<CSCStripDigi>::const_iterator last = (*sIt).second.second;
01213       for ( ; digiItr != last; ++digiItr ) {
01214         int thisStrip = digiItr->getStrip();
01215         if (thisStrip == (centerStrip)){
01216           std::vector<int> myADCVals = digiItr->getADCCounts();
01217           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01218           float thisSignal = (myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
01219           SigADC[0] = thisSignal - 6*thisPedestal;
01220         }
01221      // Now,find the Signal-Pedestal for neighbouring 4 strips
01222         if (thisStrip == (centerStrip+1)){
01223           std::vector<int> myADCVals = digiItr->getADCCounts();
01224           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01225           float thisSignal = (myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
01226           SigADC[1] = thisSignal - 6*thisPedestal;
01227         }
01228         if (thisStrip == (centerStrip+2)){
01229           std::vector<int> myADCVals = digiItr->getADCCounts();
01230           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01231           float thisSignal = (myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
01232           SigADC[2] = thisSignal - 6*thisPedestal;
01233         }
01234         if (thisStrip == (centerStrip-1)){
01235           std::vector<int> myADCVals = digiItr->getADCCounts();
01236           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01237           float thisSignal = (myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
01238           SigADC[3] = thisSignal - 6*thisPedestal;
01239         }
01240         if (thisStrip == (centerStrip-2)){
01241           std::vector<int> myADCVals = digiItr->getADCCounts();
01242           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01243           float thisSignal = (myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
01244           SigADC[4] = thisSignal - 6*thisPedestal;
01245         }
01246       }
01247       TotalADC = 0.2*(SigADC[0]+SigADC[1]+SigADC[2]+SigADC[3]+SigADC[4]);
01248     }
01249   }
01250   return TotalADC;
01251 }
01252 
01253 
01254 
01255 //----------------------------------------------------------------------------
01256 // Calculate basic efficiencies for recHits and Segments
01257 // Author: S. Stoynev
01258 //----------------------------------------------------------------------------
01259 
01260 void CSCOfflineMonitor::doEfficiencies(edm::Handle<CSCWireDigiCollection> wires, edm::Handle<CSCStripDigiCollection> strips,
01261                                        edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<CSCSegmentCollection> cscSegments,
01262                                        edm::ESHandle<CSCGeometry> cscGeom){
01263 
01264   bool allWires[2][4][4][36][6];
01265   bool allStrips[2][4][4][36][6];
01266   bool AllRecHits[2][4][4][36][6];
01267   bool AllSegments[2][4][4][36];
01268   
01269   //bool MultiSegments[2][4][4][36];
01270   for(int iE = 0;iE<2;iE++){
01271     for(int iS = 0;iS<4;iS++){
01272       for(int iR = 0; iR<4;iR++){
01273         for(int iC =0;iC<36;iC++){
01274           AllSegments[iE][iS][iR][iC] = false;
01275           //MultiSegments[iE][iS][iR][iC] = false;
01276           for(int iL=0;iL<6;iL++){
01277             allWires[iE][iS][iR][iC][iL] = false;
01278             allStrips[iE][iS][iR][iC][iL] = false;
01279             AllRecHits[iE][iS][iR][iC][iL] = false;
01280           }
01281         }
01282       }
01283     }
01284   }
01285   
01286   
01287   // Wires
01288   for (CSCWireDigiCollection::DigiRangeIterator dWDiter=wires->begin(); dWDiter!=wires->end(); dWDiter++) {
01289     CSCDetId idrec = (CSCDetId)(*dWDiter).first;
01290     std::vector<CSCWireDigi>::const_iterator wireIter = (*dWDiter).second.first;
01291     std::vector<CSCWireDigi>::const_iterator lWire = (*dWDiter).second.second;
01292     for( ; wireIter != lWire; ++wireIter) {
01293       allWires[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber() -1][idrec.layer() -1] = true;
01294       break;
01295     }
01296   }
01297 
01298   //---- STRIPS
01299   for (CSCStripDigiCollection::DigiRangeIterator dSDiter=strips->begin(); dSDiter!=strips->end(); dSDiter++) {
01300     CSCDetId idrec = (CSCDetId)(*dSDiter).first;
01301     std::vector<CSCStripDigi>::const_iterator stripIter = (*dSDiter).second.first;
01302     std::vector<CSCStripDigi>::const_iterator lStrip = (*dSDiter).second.second;
01303     for( ; stripIter != lStrip; ++stripIter) {
01304       std::vector<int> myADCVals = stripIter->getADCCounts();
01305       bool thisStripFired = false;
01306       float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01307       float threshold = 13.3 ;
01308       float diff = 0.;
01309       for (unsigned int iCount = 0; iCount < myADCVals.size(); iCount++) {
01310         diff = (float)myADCVals[iCount]-thisPedestal;
01311         if (diff > threshold) {
01312           thisStripFired = true;
01313           break;
01314         }
01315       }
01316       if(thisStripFired){
01317         allStrips[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber() -1][idrec.layer() -1] = true;
01318         break;
01319       }
01320     }
01321   }
01322 
01323   // Rechits
01324   for (CSCRecHit2DCollection::const_iterator recEffIt = recHits->begin(); recEffIt != recHits->end(); recEffIt++) {
01325     //CSCDetId idrec = (CSCDetId)(*recIt).cscDetId();
01326     CSCDetId  idrec = (CSCDetId)(*recEffIt).cscDetId();
01327     AllRecHits[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber() -1][idrec.layer() -1] = true;
01328 
01329   }
01330 
01331   std::vector <uint> seg_ME2(2,0) ;
01332   std::vector <uint> seg_ME3(2,0) ;
01333   std::vector < pair <CSCDetId, CSCSegment> > theSegments(4);
01334   // Segments
01335   for(CSCSegmentCollection::const_iterator segEffIt=cscSegments->begin(); segEffIt != cscSegments->end(); segEffIt++) {
01336     CSCDetId idseg  = (CSCDetId)(*segEffIt).cscDetId();
01337     //if(AllSegments[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber()]){
01338     //MultiSegments[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber()] = true;
01339     //}
01340     AllSegments[idseg.endcap() -1][idseg.station() -1][idseg.ring() -1][idseg.chamber() -1] = true;
01341     // "Intrinsic" efficiency measurement relies on "good" segment extrapolation - we need the pre-selection below
01342     // station 2 "good" segment will be used for testing efficiencies in ME1 and ME3
01343     // station 3 "good" segment will be used for testing efficiencies in ME2 and ME4
01344     if(2==idseg.station() || 3==idseg.station()){
01345       uint seg_tmp ; 
01346       if(2==idseg.station()){
01347         ++seg_ME2[idseg.endcap() -1];
01348         seg_tmp = seg_ME2[idseg.endcap() -1];
01349       }
01350       else{
01351         ++seg_ME3[idseg.endcap() -1];
01352         seg_tmp = seg_ME3[idseg.endcap() -1];
01353       }
01354       // is the segment good
01355       if(1== seg_tmp&& 6==(*segEffIt).nRecHits() && (*segEffIt).chi2()/(*segEffIt).degreesOfFreedom()<3.){
01356         pair <CSCDetId, CSCSegment> specSeg = make_pair( (CSCDetId)(*segEffIt).cscDetId(),*segEffIt);
01357         theSegments[2*(idseg.endcap()-1)+(idseg.station() -2)] = specSeg;
01358       }
01359     }
01360     /*
01361     if(2==idseg.station()){
01362         ++seg_ME2[idseg.endcap() -1];
01363        if(1==seg_ME2[idseg.endcap() -1] && 6==(*segEffIt).nRecHits() && (*segEffIt).chi2()/(*segEffIt).degreesOfFreedom()<3.){
01364            pair <CSCDetId, CSCSegment> specSeg = make_pair( (CSCDetId)(*segEffIt).cscDetId(),*segEffIt);
01365            theSegments[2*(idseg.endcap()-1)+(idseg.station() -2)] = specSeg;
01366        }
01367     }
01368     else if(3==idseg.station()){
01369         ++seg_ME3[idseg.endcap() -1];
01370         if(1==seg_ME3[idseg.endcap() -1] && 6==(*segEffIt).nRecHits() && (*segEffIt).chi2()/(*segEffIt).degreesOfFreedom()<3.){
01371          pair <CSCDetId, CSCSegment> specSeg = make_pair( (CSCDetId)(*segEffIt).cscDetId(),*segEffIt);
01372          theSegments[2*(idseg.endcap()-1)+(idseg.station() -2)] = specSeg;
01373        }
01374     }
01375     */
01376     
01377   }
01378   // Simple efficiency calculations
01379   for(int iE = 0;iE<2;iE++){
01380     for(int iS = 0;iS<4;iS++){
01381       for(int iR = 0; iR<4;iR++){
01382         for(int iC =0;iC<36;iC++){
01383           int NumberOfLayers = 0;
01384           for(int iL=0;iL<6;iL++){
01385             if(AllRecHits[iE][iS][iR][iC][iL]){
01386               NumberOfLayers++;
01387             }
01388           }
01389           int bin = 0;
01390           if (iS==0) bin = iR+1+(iE*10);
01391           else bin = (iS+1)*2 + (iR+1) + (iE*10);
01392           if(NumberOfLayers>1){
01393             //if(!(MultiSegments[iE][iS][iR][iC])){
01394             if(AllSegments[iE][iS][iR][iC]){
01395               //---- Efficient segment evenents
01396               hSSTE->Fill(bin);
01397             }
01398             //---- All segment events (normalization)
01399             hSSTE->Fill(20+bin);
01400             //}
01401           }
01402           if(AllSegments[iE][iS][iR][iC]){
01403             if(NumberOfLayers==6){
01404               //---- Efficient rechit events
01405               hRHSTE->Fill(bin);;
01406             }
01407             //---- All rechit events (normalization)
01408             hRHSTE->Fill(20+bin);;
01409           }
01410         }
01411       }
01412     }
01413   }
01414 
01415   // pick a segment only if there are no others in the station
01416   std::vector < pair <CSCDetId, CSCSegment> * > theSeg;
01417   if(1==seg_ME2[0]) theSeg.push_back(&theSegments[0]);
01418   if(1==seg_ME3[0]) theSeg.push_back(&theSegments[1]);
01419   if(1==seg_ME2[1]) theSeg.push_back(&theSegments[2]);
01420   if(1==seg_ME3[1]) theSeg.push_back(&theSegments[3]);
01421 
01422   // Needed for plots
01423   // at the end the chamber types will be numbered as 1 to 18 
01424   // (ME-4/1, -ME3/2, -ME3/1, ..., +ME3/1, +ME3/2, ME+4/1 ) 
01425   std::map <std::string, float> chamberTypes;
01426   chamberTypes["ME1/a"] = 0.5;
01427   chamberTypes["ME1/b"] = 1.5;
01428   chamberTypes["ME1/2"] = 2.5;
01429   chamberTypes["ME1/3"] = 3.5;
01430   chamberTypes["ME2/1"] = 4.5;
01431   chamberTypes["ME2/2"] = 5.5;
01432   chamberTypes["ME3/1"] = 6.5;
01433   chamberTypes["ME3/2"] = 7.5;
01434   chamberTypes["ME4/1"] = 8.5;
01435 
01436   if(theSeg.size()){
01437     std::map <int , GlobalPoint> extrapolatedPoint;
01438     std::map <int , GlobalPoint>::iterator it;
01439     const std::vector<CSCChamber*> ChamberContainer = cscGeom->chambers();
01440     // Pick which chamber with which segment to test
01441     for(unsigned int nCh=0;nCh<ChamberContainer.size();nCh++){
01442       const CSCChamber *cscchamber = ChamberContainer[nCh];
01443       pair <CSCDetId, CSCSegment> * thisSegment = 0;
01444       for(uint iSeg =0;iSeg<theSeg.size();++iSeg ){
01445         if(cscchamber->id().endcap() == theSeg[iSeg]->first.endcap()){ 
01446           if(1==cscchamber->id().station() || 3==cscchamber->id().station() ){
01447             if(2==theSeg[iSeg]->first.station()){
01448               thisSegment = theSeg[iSeg];
01449             }
01450           }
01451           else if (2==cscchamber->id().station() || 4==cscchamber->id().station()){
01452             if(3==theSeg[iSeg]->first.station()){
01453               thisSegment = theSeg[iSeg];
01454             }
01455           }
01456         }
01457       }
01458       // this chamber is to be tested with thisSegment
01459       if(thisSegment){
01460         CSCSegment * seg = &(thisSegment->second);
01461         const CSCChamber *segChamber = cscGeom->chamber(thisSegment->first);
01462         LocalPoint localCenter(0.,0.,0);
01463         GlobalPoint cscchamberCenter =  cscchamber->toGlobal(localCenter);
01464         // try to save some time (extrapolate a segment to a certain position only once)
01465         it = extrapolatedPoint.find(int(cscchamberCenter.z()));
01466         if(it==extrapolatedPoint.end()){
01467           GlobalPoint segPos = segChamber->toGlobal(seg->localPosition());
01468           GlobalVector segDir = segChamber->toGlobal(seg->localDirection());
01469           double paramaterLine = lineParametrization(segPos.z(),cscchamberCenter.z() , segDir.z());
01470           double xExtrapolated = extrapolate1D(segPos.x(),segDir.x(), paramaterLine);
01471           double yExtrapolated = extrapolate1D(segPos.y(),segDir.y(), paramaterLine);
01472           GlobalPoint globP (xExtrapolated, yExtrapolated, cscchamberCenter.z());
01473           extrapolatedPoint[int(cscchamberCenter.z())] = globP;
01474         }
01475         // Where does the extrapolated point lie in the (tested) chamber local frame? Here: 
01476         LocalPoint extrapolatedPointLocal = cscchamber->toLocal(extrapolatedPoint[int(cscchamberCenter.z())]);
01477         const CSCLayer *layer_p = cscchamber->layer(1);//layer 1
01478         const CSCLayerGeometry *layerGeom = layer_p->geometry ();
01479         const std::array<const float, 4> & layerBounds = layerGeom->parameters ();
01480         float shiftFromEdge = 15.;//cm
01481         float shiftFromDeadZone = 10.;
01482         // is the extrapolated point within a sensitive region
01483         bool pass = withinSensitiveRegion(extrapolatedPointLocal, layerBounds, 
01484                                           cscchamber->id().station(), cscchamber->id().ring(), 
01485                                           shiftFromEdge, shiftFromDeadZone);
01486         if(pass){// the extrapolation point of the segment lies within sensitive region of that chamber
01487           // how many rechit layers are there in the chamber?
01488           // 0 - maybe the muon died or is deflected at large angle? do not use that case
01489           // 1 - could be noise...
01490           // 2 or more - this is promissing; this is our definition of a reliable signal; use it below
01491           // is other definition better? 
01492           int nRHLayers = 0;
01493           for(int iL =0;iL<6;++iL){
01494             if(AllRecHits[cscchamber->id().endcap()-1]
01495                [cscchamber->id().station()-1]
01496                [cscchamber->id().ring()-1][cscchamber->id().chamber()-1][iL]){
01497               ++nRHLayers;
01498             }
01499           }
01500           //std::cout<<" nRHLayers = "<<nRHLayers<<std::endl;
01501           float verticalScale = chamberTypes[cscchamber->specs()->chamberTypeName()];
01502           if(cscchamberCenter.z()<0){
01503             verticalScale = - verticalScale;
01504           } 
01505           verticalScale +=9.5;
01506           hSensitiveAreaEvt->Fill(float(cscchamber->id().chamber()),verticalScale);
01507           if(nRHLayers>1){// this chamber contains a reliable signal
01508             //chamberTypes[cscchamber->specs()->chamberTypeName()];
01509             // "intrinsic" efficiencies
01510             //std::cout<<" verticalScale = "<<verticalScale<<" chType = "<<cscchamber->specs()->chamberTypeName()<<std::endl;
01511             // this is the denominator forr all efficiencies
01512             hEffDenominator->Fill(float(cscchamber->id().chamber()),verticalScale);
01513             // Segment efficiency
01514             if(AllSegments[cscchamber->id().endcap()-1]
01515                [cscchamber->id().station()-1]
01516                [cscchamber->id().ring()-1][cscchamber->id().chamber()-1]){
01517               hSSTE2->Fill(float(cscchamber->id().chamber()),float(verticalScale));
01518             }
01519           
01520             for(int iL =0;iL<6;++iL){
01521               float weight = 1./6.;
01522               // one shold account for the weight in the efficiency...
01523               // Rechit efficiency
01524               if(AllRecHits[cscchamber->id().endcap()-1]
01525                  [cscchamber->id().station()-1]
01526                  [cscchamber->id().ring()-1][cscchamber->id().chamber()-1][iL]){
01527                 hRHSTE2->Fill(float(cscchamber->id().chamber()),float(verticalScale),weight);
01528               }
01529               // Wire efficiency
01530               if(allWires[cscchamber->id().endcap()-1]
01531                  [cscchamber->id().station()-1]
01532                  [cscchamber->id().ring()-1][cscchamber->id().chamber()-1][iL]){
01533                 // one shold account for the weight in the efficiency...
01534                 hWireSTE2->Fill(float(cscchamber->id().chamber()),float(verticalScale),weight);
01535               }
01536               // Strip efficiency
01537               if(allStrips[cscchamber->id().endcap()-1]
01538                  [cscchamber->id().station()-1]
01539                  [cscchamber->id().ring()-1][cscchamber->id().chamber()-1][iL]){
01540                 // one shold account for the weight in the efficiency...
01541                 hStripSTE2->Fill(float(cscchamber->id().chamber()),float(verticalScale),weight);
01542               }
01543             }
01544           }
01545         }
01546       }
01547     }
01548   }
01549   //
01550 
01551 
01552 }
01553 
01554 // ==============================================
01555 //
01556 // Look at BX level trigger synchronization
01557 //
01558 // ==============================================
01559 
01560 void CSCOfflineMonitor::doBXMonitor(edm::Handle<CSCALCTDigiCollection> alcts, edm::Handle<CSCCLCTDigiCollection> clcts, const edm::Event & event, const EventSetup& eventSetup){
01561 
01562   // Loop over ALCTDigis
01563 
01564   for (CSCALCTDigiCollection::DigiRangeIterator j=alcts->begin(); j!=alcts->end(); j++) {
01565     const CSCDetId& idALCT = (*j).first;
01566     const CSCALCTDigiCollection::Range& range =(*j).second;
01567     for (CSCALCTDigiCollection::const_iterator digiIt = range.first; digiIt!=range.second; ++digiIt){
01568       // Valid digi in the chamber (or in neighbouring chamber)  
01569       if((*digiIt).isValid()){
01570         hALCTgetBX->Fill((*digiIt).getBX());
01571         hALCTgetBXSerial->Fill(chamberSerial(idALCT),(*digiIt).getBX());
01572         hALCTgetBX2DNumerator->Fill(idALCT.chamber(),typeIndex(idALCT,2),(*digiIt).getBX());
01573         hALCTgetBX2Denominator->Fill(idALCT.chamber(),typeIndex(idALCT,2));
01574       }
01575     }
01576   }// end ALCT Digi loop
01577 
01578 
01579   // Loop over raw data to get TMBHeader information
01580   // Taking code from EventFilter/CSCRawToDigis/CSCDCCUnpacker.cc
01581   edm::ESHandle<CSCCrateMap> hcrate;
01582   eventSetup.get<CSCCrateMapRcd>().get(hcrate); 
01583   const CSCCrateMap* pcrate = hcrate.product();
01584 
01585 
01586   // Try to get raw data
01587   edm::Handle<FEDRawDataCollection> rawdata;
01588   if (!(event.getByLabel(FEDRawDataCollectionTag_,rawdata)) ){
01589     edm::LogWarning("CSCOfflineMonitor")<<" raw data with label "<<FEDRawDataCollectionTag_ <<" not available";
01590     return;
01591   }
01592 
01593 
01594 
01595   bool goodEvent = false;
01596   unsigned long dccBinCheckMask = 0x06080016;
01597   unsigned int examinerMask = 0x1FEBF3F6;
01598   unsigned int errorMask = 0x0;
01599 
01600   for (int id=FEDNumbering::MINCSCFEDID;
01601        id<=FEDNumbering::MAXCSCFEDID; ++id) { // loop over DCCs
01604      
01606     const FEDRawData& fedData = rawdata->FEDData(id);
01607     unsigned long length =  fedData.size();
01608    
01609     if (length>=32){ 
01610       CSCDCCExaminer* examiner = NULL;
01611       std::stringstream examiner_out, examiner_err;
01612       goodEvent = true;
01613       examiner = new CSCDCCExaminer();
01614       examiner->output1().redirect(examiner_out);
01615       examiner->output2().redirect(examiner_err);
01616       if( examinerMask&0x40000 ) examiner->crcCFEB(1);
01617       if( examinerMask&0x8000  ) examiner->crcTMB (1);
01618       if( examinerMask&0x0400  ) examiner->crcALCT(1);
01619       examiner->output1().show();
01620       examiner->output2().show();
01621       examiner->setMask(examinerMask);
01622       const short unsigned int *data = (short unsigned int *)fedData.data();
01623  
01624       int res = examiner->check(data,long(fedData.size()/2));
01625       if( res < 0 )   {
01626         goodEvent=false;
01627       } 
01628       else {    
01629         goodEvent=!(examiner->errors()&dccBinCheckMask);
01630       }
01631  
01632                  
01633       if (goodEvent) {
01635  
01636         CSCDCCExaminer * ptrExaminer = examiner;
01637         CSCDCCEventData dccData((short unsigned int *) fedData.data(), ptrExaminer);
01639         const std::vector<CSCDDUEventData> & dduData = dccData.dduData();
01640         
01642         CSCDetId layer(1, 1, 1, 1, 1);
01643         for (unsigned int iDDU=0; iDDU<dduData.size(); ++iDDU) {  // loop over DDUs
01646           if (dduData[iDDU].trailer().errorstat()&errorMask) {
01647             LogTrace("CSCDCCUnpacker|CSCRawToDigi") << "DDU# " << iDDU << " has serious error - no digis unpacked! " <<
01648               std::hex << dduData[iDDU].trailer().errorstat();
01649             continue; // to next iteration of DDU loop
01650           }
01651           
01653           const std::vector<CSCEventData> & cscData = dduData[iDDU].cscData();
01654           
01655           
01656           for (unsigned int iCSC=0; iCSC<cscData.size(); ++iCSC) { // loop over CSCs
01657             
01659             int vmecrate = cscData[iCSC].dmbHeader()->crateID();
01660             int dmb = cscData[iCSC].dmbHeader()->dmbID();
01661             
01662             int icfeb = 0;  
01663             int ilayer = 0; 
01664             
01665              if ((vmecrate>=1)&&(vmecrate<=60) && (dmb>=1)&&(dmb<=10)&&(dmb!=6)) {
01666                layer = pcrate->detId(vmecrate, dmb,icfeb,ilayer );
01667              } 
01668              else{
01669                LogTrace ("CSCOfflineMonitor") << " detID input out of range!!! ";
01670                LogTrace ("CSCOfflineMonitor")
01671                  << " skipping chamber vme= " << vmecrate << " dmb= " << dmb;
01672                continue; // to next iteration of iCSC loop
01673              }
01674 
01675 
01677             int nalct = cscData[iCSC].dmbHeader()->nalct();
01678             bool goodALCT=false;
01679             //if (nalct&&(cscData[iCSC].dataPresent>>6&0x1)==1) {
01680             if (nalct&&cscData[iCSC].alctHeader()) {  
01681               if (cscData[iCSC].alctHeader()->check()){
01682                 goodALCT=true;
01683               }
01684             }
01685             
01687             int nclct = cscData[iCSC].dmbHeader()->nclct();
01688             bool goodTMB=false;
01689             if (nclct&&cscData[iCSC].tmbData()) {
01690               if (cscData[iCSC].tmbHeader()->check()){
01691                 if (cscData[iCSC].clctData()->check()) goodTMB=true; 
01692               }
01693             }
01694             
01695             if (goodTMB && goodALCT) { 
01696               const CSCTMBHeader *tmbHead = cscData[iCSC].tmbHeader();
01697               std::vector<CSCCLCTDigi> clcts = cscData[iCSC].tmbHeader()->CLCTDigis(layer.rawId());
01698               if (clcts.size()==0 || !(clcts[0].isValid()))
01699                 continue;
01700               // Check if the CLCT was in ME11a (ring 4)
01701               if(layer.station()==1 && layer.ring() ==1 && clcts[0].getKeyStrip()>128){
01702                 layer = CSCDetId(layer.endcap(),layer.station(),4, layer.chamber()); 
01703               }
01704               hALCTMatch->Fill(tmbHead->ALCTMatchTime());
01705               hALCTMatchSerial->Fill(chamberSerial(layer),tmbHead->ALCTMatchTime());
01706               // Only fill big 2D display if ALCTMatchTime !=6, since this bin is polluted by the CLCT only triggers
01707               // One will have to look at the serial plots to see if the are a lot of entries here
01708               if(tmbHead->ALCTMatchTime()!=6){
01709                 hALCTMatch2DNumerator->Fill(layer.chamber(),typeIndex(layer,2),tmbHead->ALCTMatchTime());
01710                 hALCTMatch2Denominator->Fill(layer.chamber(),typeIndex(layer,2));             
01711               }
01712 
01713               int TMB_CLCTpre_rel_L1A = tmbHead->BXNCount()-clcts[0].getFullBX();
01714               if (TMB_CLCTpre_rel_L1A > 3563)
01715                 TMB_CLCTpre_rel_L1A = TMB_CLCTpre_rel_L1A - 3564;
01716               if (TMB_CLCTpre_rel_L1A < 0)
01717                 TMB_CLCTpre_rel_L1A = TMB_CLCTpre_rel_L1A + 3564;
01718 
01719               hCLCTL1A->Fill(TMB_CLCTpre_rel_L1A);
01720               hCLCTL1ASerial->Fill(chamberSerial(layer),TMB_CLCTpre_rel_L1A);
01721               hCLCTL1A2DNumerator->Fill(layer.chamber(),typeIndex(layer,2),TMB_CLCTpre_rel_L1A);
01722               hCLCTL1A2Denominator->Fill(layer.chamber(),typeIndex(layer,2));         
01723               
01724             }// end if goodTMB and goodALCT
01725           }// end loop CSCData
01726         }// end loop DDU
01727       }// end if good event
01728       if (examiner!=NULL) delete examiner;
01729     }// end if non-zero fed data
01730   }// end DCC loop for NON-REFERENCE
01731 
01732   return;
01733 
01734 }
01735 
01736 
01737 
01738 void CSCOfflineMonitor::getEfficiency(float bin, float Norm, std::vector<float> &eff){
01739   //---- Efficiency with binomial error
01740   float Efficiency = 0.;
01741   float EffError = 0.;
01742   if(fabs(Norm)>0.000000001){
01743     Efficiency = bin/Norm;
01744     if(bin<Norm){
01745       EffError = sqrt( (1.-Efficiency)*Efficiency/Norm );
01746     }
01747   }
01748   eff[0] = Efficiency;
01749   eff[1] = EffError;
01750 }
01751 
01752 void CSCOfflineMonitor::histoEfficiency(TH1F *readHisto, MonitorElement *writeHisto){
01753   std::vector<float> eff(2);
01754   int Nbins =  readHisto->GetSize()-2;//without underflows and overflows
01755   std::vector<float> bins(Nbins);
01756   std::vector<float> Efficiency(Nbins);
01757   std::vector<float> EffError(Nbins);
01758   float Num = 1;
01759   float Den = 1;
01760   for (int i=0;i<20;i++){
01761     Num = readHisto->GetBinContent(i+1);
01762     Den = readHisto->GetBinContent(i+21);
01763     getEfficiency(Num, Den, eff);
01764     Efficiency[i] = eff[0];
01765     EffError[i] = eff[1];
01766     writeHisto->setBinContent(i+1, Efficiency[i]);
01767     writeHisto->setBinError(i+1, EffError[i]);
01768   }
01769 }
01770 
01771 bool CSCOfflineMonitor::withinSensitiveRegion(LocalPoint localPos, const std::array<const float, 4> & layerBounds,
01772                                               int station, int ring, float shiftFromEdge, float shiftFromDeadZone){
01773 //---- check if it is in a good local region (sensitive area - geometrical and HV boundaries excluded) 
01774   bool pass = false;
01775 
01776   float y_center = 0.;
01777   double yUp = layerBounds[3] + y_center;
01778   double yDown = - layerBounds[3] + y_center;
01779   double xBound1Shifted = layerBounds[0] - shiftFromEdge;//
01780   double xBound2Shifted = layerBounds[1] - shiftFromEdge;//
01781   double lineSlope = (yUp - yDown)/(xBound2Shifted-xBound1Shifted);
01782   double lineConst = yUp - lineSlope*xBound2Shifted;
01783   double yBorder =  lineSlope*abs(localPos.x()) + lineConst;
01784       
01785   //bool withinChamberOnly = false;// false = "good region"; true - boundaries only
01786   std::vector <float> deadZoneCenter(6);
01787   float cutZone = shiftFromDeadZone;//cm
01788   //---- hardcoded... not good
01789   if(station>1 && station<5){
01790     if(2==ring){
01791       deadZoneCenter[0]= -162.48 ;
01792       deadZoneCenter[1] = -81.8744;
01793       deadZoneCenter[2] = -21.18165;
01794       deadZoneCenter[3] = 39.51105;
01795       deadZoneCenter[4] = 100.2939;
01796       deadZoneCenter[5] = 160.58;
01797       
01798       if(localPos.y() >yBorder &&
01799          ((localPos.y()> deadZoneCenter[0] + cutZone && localPos.y()< deadZoneCenter[1] - cutZone) ||
01800           (localPos.y()> deadZoneCenter[1] + cutZone && localPos.y()< deadZoneCenter[2] - cutZone) ||
01801           (localPos.y()> deadZoneCenter[2] + cutZone && localPos.y()< deadZoneCenter[3] - cutZone) ||
01802           (localPos.y()> deadZoneCenter[3] + cutZone && localPos.y()< deadZoneCenter[4] - cutZone) ||
01803           (localPos.y()> deadZoneCenter[4] + cutZone && localPos.y()< deadZoneCenter[5] - cutZone))){
01804         pass = true;
01805       }
01806     }
01807     else if(1==ring){
01808       if(2==station){
01809         deadZoneCenter[0]= -95.80 ;
01810         deadZoneCenter[1] = -27.47;
01811         deadZoneCenter[2] = 33.67;
01812         deadZoneCenter[3] = 90.85;
01813         }
01814       else if(3==station){
01815         deadZoneCenter[0]= -89.305 ;
01816         deadZoneCenter[1] = -39.705;
01817         deadZoneCenter[2] = 20.195;
01818         deadZoneCenter[3] = 77.395;
01819       }
01820       else if(4==station){
01821         deadZoneCenter[0]= -75.645;
01822         deadZoneCenter[1] = -26.055;
01823         deadZoneCenter[2] = 23.855;
01824         deadZoneCenter[3] = 70.575;
01825       }
01826       if(localPos.y() >yBorder &&
01827          ((localPos.y()> deadZoneCenter[0] + cutZone && localPos.y()< deadZoneCenter[1] - cutZone) ||
01828           (localPos.y()> deadZoneCenter[1] + cutZone && localPos.y()< deadZoneCenter[2] - cutZone) ||
01829           (localPos.y()> deadZoneCenter[2] + cutZone && localPos.y()< deadZoneCenter[3] - cutZone))){
01830         pass = true;
01831       }
01832     }
01833   }
01834   else if(1==station){
01835     if(3==ring){
01836       deadZoneCenter[0]= -83.155 ;
01837       deadZoneCenter[1] = -22.7401;
01838       deadZoneCenter[2] = 27.86665;
01839       deadZoneCenter[3] = 81.005;
01840       if(localPos.y() > yBorder &&
01841          ((localPos.y()> deadZoneCenter[0] + cutZone && localPos.y()< deadZoneCenter[1] - cutZone) ||
01842           (localPos.y()> deadZoneCenter[1] + cutZone && localPos.y()< deadZoneCenter[2] - cutZone) ||
01843           (localPos.y()> deadZoneCenter[2] + cutZone && localPos.y()< deadZoneCenter[3] - cutZone))){
01844         pass = true;
01845       }
01846     }
01847     else if(2==ring){
01848       deadZoneCenter[0]= -86.285 ;
01849       deadZoneCenter[1] = -32.88305;
01850       deadZoneCenter[2] = 32.867423;
01851       deadZoneCenter[3] = 88.205;
01852       if(localPos.y() > (yBorder) &&
01853          ((localPos.y()> deadZoneCenter[0] + cutZone && localPos.y()< deadZoneCenter[1] - cutZone) ||
01854           (localPos.y()> deadZoneCenter[1] + cutZone && localPos.y()< deadZoneCenter[2] - cutZone) ||
01855           (localPos.y()> deadZoneCenter[2] + cutZone && localPos.y()< deadZoneCenter[3] - cutZone))){
01856         pass = true;
01857       }
01858     }
01859     else{
01860       deadZoneCenter[0]= -81.0;
01861       deadZoneCenter[1] = 81.0;
01862       if(localPos.y() > (yBorder) &&
01863          (localPos.y()> deadZoneCenter[0] + cutZone && localPos.y()< deadZoneCenter[1] - cutZone )){
01864         pass = true;
01865       }
01866     }
01867   }
01868   return pass;
01869 }
01870 
01871 
01872 int CSCOfflineMonitor::typeIndex(CSCDetId id, int flag){
01873   
01874   if (flag == 1){
01875     // linearlized index bases on endcap, station, and ring
01876     int index = 0;
01877     if (id.station() == 1) index = id.ring();
01878     else index = id.station()*2 + id.ring();
01879     if (id.endcap() == 1) index = index + 10;
01880     if (id.endcap() == 2) index = 11 - index;
01881     return index;
01882   }
01883 
01884   else if (flag == 2){
01885     int index = 0;
01886     if (id.station() == 1 && id.ring() != 4) index = id.ring()+1;
01887     if (id.station() == 1 && id.ring() == 4) index = 1; 
01888     if (id.station() != 1) index = id.station()*2 + id.ring();
01889     if (id.endcap() == 1) index = index + 10;
01890     if (id.endcap() == 2) index = 11 - index;
01891     return index;
01892   }
01893 
01894   else return 0;
01895 
01896 }
01897 
01898 int CSCOfflineMonitor::chamberSerial( CSCDetId id ) {
01899   int st = id.station();
01900   int ri = id.ring();
01901   int ch = id.chamber();
01902   int ec = id.endcap();
01903   int kSerial = ch;
01904   if (st == 1 && ri == 1) kSerial = ch;
01905   if (st == 1 && ri == 2) kSerial = ch + 36;
01906   if (st == 1 && ri == 3) kSerial = ch + 72;
01907   if (st == 1 && ri == 4) kSerial = ch;
01908   if (st == 2 && ri == 1) kSerial = ch + 108;
01909   if (st == 2 && ri == 2) kSerial = ch + 126;
01910   if (st == 3 && ri == 1) kSerial = ch + 162;
01911   if (st == 3 && ri == 2) kSerial = ch + 180;
01912   if (st == 4 && ri == 1) kSerial = ch + 216;
01913   if (st == 4 && ri == 2) kSerial = ch + 234;  // one day...
01914   if (ec == 2) kSerial = kSerial + 300;
01915   return kSerial;
01916 }
01917 
01918 void CSCOfflineMonitor::applyCSClabels( MonitorElement* me, LabelType t, AxisType a ) {
01919   if (me != NULL)
01920   {
01921     me->setAxisTitle("Chamber #");
01922     if (t == EXTENDED)
01923     {
01924       me->setBinLabel(1,"ME -4/2",a);
01925       me->setBinLabel(2,"ME -4/1",a);
01926       me->setBinLabel(3,"ME -3/2",a);
01927       me->setBinLabel(4,"ME -3/1",a);
01928       me->setBinLabel(5,"ME -2/2",a);
01929       me->setBinLabel(6,"ME -2/1",a);
01930       me->setBinLabel(7,"ME -1/3",a);
01931       me->setBinLabel(8,"ME -1/2",a);
01932       me->setBinLabel(9,"ME -1/1b",a);
01933       me->setBinLabel(10,"ME -1/1a",a);
01934       me->setBinLabel(11,"ME +1/1a",a);
01935       me->setBinLabel(12,"ME +1/1b",a);
01936       me->setBinLabel(13,"ME +1/2",a);
01937       me->setBinLabel(14,"ME +1/3",a);
01938       me->setBinLabel(15,"ME +2/1",a);
01939       me->setBinLabel(16,"ME +2/2",a);
01940       me->setBinLabel(17,"ME +3/1",a);
01941       me->setBinLabel(18,"ME +3/2",a);
01942       me->setBinLabel(19,"ME +4/1",a);
01943       me->setBinLabel(20,"ME +4/2",a);
01944     }
01945     else if (t == SMALL)
01946     {
01947       me->setBinLabel(1,"ME -4/1",a);
01948       me->setBinLabel(2,"ME -3/2",a);
01949       me->setBinLabel(3,"ME -3/1",a);
01950       me->setBinLabel(4,"ME -2/2",a);
01951       me->setBinLabel(5,"ME -2/1",a);
01952       me->setBinLabel(6,"ME -1/3",a);
01953       me->setBinLabel(7,"ME -1/2",a);
01954       me->setBinLabel(8,"ME -1/1b",a);
01955       me->setBinLabel(9,"ME -1/1a",a);
01956       me->setBinLabel(10,"ME +1/1a",a);
01957       me->setBinLabel(11,"ME +1/1b",a);
01958       me->setBinLabel(12,"ME +1/2",a);
01959       me->setBinLabel(13,"ME +1/3",a);
01960       me->setBinLabel(14,"ME +2/1",a);
01961       me->setBinLabel(15,"ME +2/2",a);
01962       me->setBinLabel(16,"ME +3/1",a);
01963       me->setBinLabel(17,"ME +3/2",a);
01964       me->setBinLabel(18,"ME +4/1",a);
01965     }
01966   }
01967 }
01968 
01969 DEFINE_FWK_MODULE(CSCOfflineMonitor);
01970