CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/RecoLocalMuon/CSCValidation/src/CSCValidation.cc

Go to the documentation of this file.
00001 /*
00002  *  validation package for CSC DIGIs, RECHITs and SEGMENTs + more.
00003  *
00004  *  Michael Schmitt
00005  *  Andy Kubik
00006  *  Northwestern University
00007  */
00008 #include "RecoLocalMuon/CSCValidation/src/CSCValidation.h"
00009 
00010 using namespace std;
00011 using namespace edm;
00012 
00013 
00015 //  CONSTRUCTOR  //
00017 CSCValidation::CSCValidation(const ParameterSet& pset){ 
00018 
00019   // Get the various input parameters
00020   rootFileName         = pset.getUntrackedParameter<std::string>("rootFileName","valHists.root");
00021   isSimulation         = pset.getUntrackedParameter<bool>("isSimulation",false);
00022   writeTreeToFile      = pset.getUntrackedParameter<bool>("writeTreeToFile",true);
00023   detailedAnalysis     = pset.getUntrackedParameter<bool>("detailedAnalysis",false);
00024   useDigis             = pset.getUntrackedParameter<bool>("useDigis",true);
00025 
00026   // event quality filter
00027   useQualityFilter     = pset.getUntrackedParameter<bool>("useQualityFilter",false);
00028   pMin                 = pset.getUntrackedParameter<double>("pMin",4.);
00029   chisqMax             = pset.getUntrackedParameter<double>("chisqMax",20.);
00030   nCSCHitsMin          = pset.getUntrackedParameter<int>("nCSCHitsMin",10);
00031   nCSCHitsMax          = pset.getUntrackedParameter<int>("nCSCHitsMax",25);
00032   lengthMin            = pset.getUntrackedParameter<double>("lengthMin",140.);
00033   lengthMax            = pset.getUntrackedParameter<double>("lengthMax",600.);
00034   deltaPhiMax          = pset.getUntrackedParameter<double>("deltaPhiMax",0.2);
00035   polarMax             = pset.getUntrackedParameter<double>("polarMax",0.7);
00036   polarMin             = pset.getUntrackedParameter<double>("polarMin",0.3);
00037 
00038   // trigger filter
00039   useTriggerFilter     = pset.getUntrackedParameter<bool>("useTriggerFilter",false);
00040 
00041   // input tags for collections
00042   stripDigiTag  = pset.getParameter<edm::InputTag>("stripDigiTag");
00043   wireDigiTag   = pset.getParameter<edm::InputTag>("wireDigiTag"); 
00044   compDigiTag   = pset.getParameter<edm::InputTag>("compDigiTag");
00045   alctDigiTag   = pset.getParameter<edm::InputTag>("alctDigiTag") ;
00046   clctDigiTag   = pset.getParameter<edm::InputTag>("clctDigiTag") ;
00047   corrlctDigiTag= pset.getParameter<edm::InputTag>("corrlctDigiTag") ;
00048   cscRecHitTag  = pset.getParameter<edm::InputTag>("cscRecHitTag");
00049   cscSegTag     = pset.getParameter<edm::InputTag>("cscSegTag");
00050   saMuonTag     = pset.getParameter<edm::InputTag>("saMuonTag");
00051   l1aTag        = pset.getParameter<edm::InputTag>("l1aTag");
00052   simHitTag     = pset.getParameter<edm::InputTag>("simHitTag");
00053   hltTag        = pset.getParameter<edm::InputTag>("hltTag");
00054 
00055   // flags to switch on/off individual modules
00056   makeOccupancyPlots   = pset.getUntrackedParameter<bool>("makeOccupancyPlots",true);
00057   makeTriggerPlots     = pset.getUntrackedParameter<bool>("makeTriggerPlots",false);
00058   makeStripPlots       = pset.getUntrackedParameter<bool>("makeStripPlots",true);
00059   makeWirePlots        = pset.getUntrackedParameter<bool>("makeWirePlots",true);
00060   makeRecHitPlots      = pset.getUntrackedParameter<bool>("makeRecHitPlots",true);
00061   makeSimHitPlots      = pset.getUntrackedParameter<bool>("makeSimHitPlots",true);
00062   makeSegmentPlots     = pset.getUntrackedParameter<bool>("makeSegmentPlots",true);
00063   makeResolutionPlots  = pset.getUntrackedParameter<bool>("makeResolutionPlots",true);
00064   makePedNoisePlots    = pset.getUntrackedParameter<bool>("makePedNoisePlots",true);
00065   makeEfficiencyPlots  = pset.getUntrackedParameter<bool>("makeEfficiencyPlots",true);
00066   makeGasGainPlots     = pset.getUntrackedParameter<bool>("makeGasGainPlots",true);
00067   makeAFEBTimingPlots  = pset.getUntrackedParameter<bool>("makeAFEBTimingPlots",true);
00068   makeCompTimingPlots  = pset.getUntrackedParameter<bool>("makeCompTimingPlots",true);
00069   makeADCTimingPlots   = pset.getUntrackedParameter<bool>("makeADCTimingPlots",true);
00070   makeRHNoisePlots     = pset.getUntrackedParameter<bool>("makeRHNoisePlots",false);
00071   makeCalibPlots       = pset.getUntrackedParameter<bool>("makeCalibPlots",false);
00072   makeStandalonePlots  = pset.getUntrackedParameter<bool>("makeStandalonePlots",false);
00073   makeTimeMonitorPlots = pset.getUntrackedParameter<bool>("makeTimeMonitorPlots",false);
00074   makeHLTPlots         = pset.getUntrackedParameter<bool>("makeHLTPlots",false);
00075 
00076   // set counters to zero
00077   nEventsAnalyzed = 0;
00078   rhTreeCount = 0;
00079   segTreeCount = 0;
00080   firstEvent = true; 
00081  
00082   // Create the root file for the histograms
00083   theFile = new TFile(rootFileName.c_str(), "RECREATE");
00084   theFile->cd();
00085 
00086   // Create object of class CSCValHists to manage histograms
00087   histos = new CSCValHists();
00088 
00089   // book Occupancy Histos
00090   hOWires    = new TH2I("hOWires","Wire Digi Occupancy",36,0.5,36.5,20,0.5,20.5);
00091   hOStrips   = new TH2I("hOStrips","Strip Digi Occupancy",36,0.5,36.5,20,0.5,20.5);
00092   hORecHits  = new TH2I("hORecHits","RecHit Occupancy",36,0.5,36.5,20,0.5,20.5);
00093   hOSegments = new TH2I("hOSegments","Segments Occupancy",36,0.5,36.5,20,0.5,20.5);
00094 
00095   // book Eff histos
00096   hSSTE = new TH1F("hSSTE","hSSTE",40,0,40);
00097   hRHSTE = new TH1F("hRHSTE","hRHSTE",40,0,40);
00098   hSEff = new TH1F("hSEff","Segment Efficiency",20,0.5,20.5);
00099   hRHEff = new TH1F("hRHEff","recHit Efficiency",20,0.5,20.5);
00100 
00101   const int nChambers = 36; 
00102   const int nTypes = 18;
00103   float nCH_min = 0.5;
00104   float nCh_max = float(nChambers) + 0.5;
00105   float nT_min = 0.5;
00106   float nT_max = float(nTypes) + 0.5;
00107 
00108   hSSTE2 = new TH2F("hSSTE2","hSSTE2",nChambers,nCH_min,nCh_max, nTypes, nT_min, nT_max);
00109   hRHSTE2 = new TH2F("hRHSTE2","hRHSTE2",nChambers,nCH_min,nCh_max, nTypes, nT_min, nT_max);
00110   hStripSTE2 = new TH2F("hStripSTE2","hStripSTE2",nChambers,nCH_min,nCh_max, nTypes, nT_min, nT_max);
00111   hWireSTE2 = new TH2F("hWireSTE2","hWireSTE2",nChambers,nCH_min,nCh_max, nTypes, nT_min, nT_max);
00112   
00113 
00114   hEffDenominator = new TH2F("hEffDenominator","hEffDenominator",nChambers,nCH_min,nCh_max, nTypes, nT_min, nT_max);
00115   hSEff2 = new TH2F("hSEff2","Segment Efficiency 2D",nChambers,nCH_min,nCh_max, nTypes, nT_min, nT_max);
00116   hRHEff2 = new TH2F("hRHEff2","recHit Efficiency 2D",nChambers,nCH_min,nCh_max, nTypes, nT_min, nT_max);
00117 
00118   hStripEff2 = new TH2F("hStripEff2","strip Efficiency 2D",nChambers,nCH_min,nCh_max, nTypes, nT_min, nT_max);
00119   hWireEff2 = new TH2F("hWireEff2","wire Efficiency 2D",nChambers,nCH_min,nCh_max, nTypes, nT_min, nT_max);
00120 
00121   hSensitiveAreaEvt = new TH2F("hSensitiveAreaEvt","events in sensitive area",nChambers,nCH_min,nCh_max, nTypes, nT_min, nT_max);
00122  
00123   // setup trees to hold global position data for rechits and segments
00124   if (writeTreeToFile) histos->setupTrees();
00125 
00126 
00127 }
00128 
00130 //  DESTRUCTOR  //
00132 CSCValidation::~CSCValidation(){
00133 
00134   // produce final efficiency histograms
00135   histoEfficiency(hRHSTE,hRHEff);
00136   histoEfficiency(hSSTE,hSEff);
00137   hSEff2->Divide(hSSTE2,hEffDenominator,1.,1.,"B");
00138   hRHEff2->Divide(hRHSTE2,hEffDenominator,1.,1.,"B");
00139   hStripEff2->Divide(hStripSTE2,hEffDenominator,1.,1.,"B");
00140   hWireEff2->Divide(hWireSTE2,hEffDenominator,1.,1.,"B");
00141 
00142   histos->insertPlot(hRHSTE,"hRHSTE","Efficiency");
00143   histos->insertPlot(hSSTE,"hSSTE","Efficiency");
00144   histos->insertPlot(hSSTE2,"hSSTE2","Efficiency");
00145   histos->insertPlot(hEffDenominator,"hEffDenominator","Efficiency");
00146   histos->insertPlot(hRHSTE2,"hRHSTE2","Efficiency");
00147   histos->insertPlot(hStripSTE2,"hStripSTE2","Efficiency");
00148   histos->insertPlot(hWireSTE2,"hWireSTE2","Efficiency");
00149 
00150   //moving this to post job macros
00151   histos->insertPlot(hSEff,"hSEff","Efficiency");
00152   histos->insertPlot(hRHEff,"hRHEff","Efficiency");
00153 
00154   histos->insertPlot(hSEff2,"hSEff2","Efficiency");
00155   histos->insertPlot(hRHEff2,"hRHEff2","Efficiency");
00156   histos->insertPlot(hStripEff2,"hStripff2","Efficiency");
00157   histos->insertPlot(hWireEff2,"hWireff2","Efficiency");
00158   
00159   histos->insertPlot(hSensitiveAreaEvt,"","Efficiency");
00160 
00161   // throw in occupancy plots so they're saved
00162   histos->insertPlot(hOWires,"hOWires","Digis");
00163   histos->insertPlot(hOStrips,"hOStrips","Digis");
00164   histos->insertPlot(hORecHits,"hORecHits","recHits");
00165   histos->insertPlot(hOSegments,"hOSegments","Segments");
00166 
00167   
00168   // write histos to the specified file
00169   histos->writeHists(theFile);
00170   if (writeTreeToFile) histos->writeTrees(theFile);
00171   theFile->Close();
00172 
00173 }
00174 
00176 //  Analysis  //
00178 void CSCValidation::analyze(const Event & event, const EventSetup& eventSetup){
00179   // increment counter
00180   nEventsAnalyzed++;
00181 
00182   //int iRun   = event.id().run();
00183   //int iEvent = event.id().event();
00184 
00185   // Get the Digis
00186   edm::Handle<CSCWireDigiCollection> wires;
00187   edm::Handle<CSCStripDigiCollection> strips;
00188   edm::Handle<CSCComparatorDigiCollection> compars;
00189   edm::Handle<CSCALCTDigiCollection> alcts;
00190   edm::Handle<CSCCLCTDigiCollection> clcts;
00191   edm::Handle<CSCCorrelatedLCTDigiCollection> correlatedlcts;
00192   if (useDigis){
00193     event.getByLabel(stripDigiTag,strips);
00194     event.getByLabel(wireDigiTag,wires);
00195     event.getByLabel(compDigiTag,compars);
00196     event.getByLabel(alctDigiTag, alcts);
00197     event.getByLabel(clctDigiTag, clcts);
00198     event.getByLabel(corrlctDigiTag, correlatedlcts);
00199  }
00200 
00201   // Get the CSC Geometry :
00202   ESHandle<CSCGeometry> cscGeom;
00203   eventSetup.get<MuonGeometryRecord>().get(cscGeom);
00204 
00205   // Get the RecHits collection :
00206   Handle<CSCRecHit2DCollection> recHits;
00207   event.getByLabel(cscRecHitTag,recHits);
00208 
00209   //CSCRecHit2DCollection::const_iterator recIt;
00210   //for (recIt = recHits->begin(); recIt != recHits->end(); recIt++) {
00211   //  recIt->print();
00212   // }
00213 
00214 
00215   // Get the SimHits (if applicable)
00216   Handle<PSimHitContainer> simHits;
00217   if (isSimulation) event.getByLabel(simHitTag, simHits);
00218 
00219   // get CSC segment collection
00220   Handle<CSCSegmentCollection> cscSegments;
00221   event.getByLabel(cscSegTag, cscSegments);
00222 
00223   // get the trigger collection
00224   edm::Handle<L1MuGMTReadoutCollection> pCollection;
00225   if (makeTriggerPlots || useTriggerFilter || (useDigis && makeTimeMonitorPlots)){
00226     event.getByLabel(l1aTag,pCollection);
00227   }
00228   edm::Handle<TriggerResults> hlt;
00229   if (makeHLTPlots) event.getByLabel(hltTag,hlt);
00230 
00231   // get the standalone muon collection
00232   Handle<reco::TrackCollection> saMuons;
00233   if (makeStandalonePlots || useQualityFilter) event.getByLabel(saMuonTag,saMuons);
00234 
00235 
00236 
00238   // Run the modules //
00240 
00241   // Only do this for the first event
00242   // this is probably outdated and needs to be looked at
00243   if (nEventsAnalyzed == 1 && makeCalibPlots) doCalibrations(eventSetup);
00244 
00245 
00246   // Look at the l1a trigger info (returns true if csc L1A present)
00247   bool CSCL1A = false;
00248   if (makeTriggerPlots || useTriggerFilter) CSCL1A = doTrigger(pCollection);
00249   if (!useTriggerFilter) CSCL1A = true;  // always true if not filtering on trigger
00250 
00251 
00252   cleanEvent = false;
00253   if (makeStandalonePlots || useQualityFilter) cleanEvent = filterEvents(recHits,cscSegments,saMuons);
00254   if (!useQualityFilter) cleanEvent = true; // always true if not filtering on event quality
00255 
00256   
00257   // look at various chamber occupancies
00258   // keep this outside of filter for diagnostics???
00259   if (makeOccupancyPlots && CSCL1A) doOccupancies(strips,wires,recHits,cscSegments);
00260 
00261 
00262   if (makeHLTPlots) doHLT(hlt);
00263 
00264 
00265   if (cleanEvent && CSCL1A){
00266 
00267     // general look at strip digis
00268     if (makeStripPlots && useDigis) doStripDigis(strips);
00269 
00270     // general look at wire digis
00271     if (makeWirePlots && useDigis) doWireDigis(wires);
00272 
00273 
00274     // general look at rechits
00275     if (makeRecHitPlots) doRecHits(recHits,cscGeom);
00276 
00277     // look at simHits
00278     if (isSimulation && makeSimHitPlots) doSimHits(recHits,simHits);
00279 
00280     // general look at Segments
00281     if (makeSegmentPlots) doSegments(cscSegments,cscGeom);
00282 
00283     // look at hit resolution
00284     if (makeResolutionPlots) doResolution(cscSegments,cscGeom);
00285 
00286 
00287     // look at Pedestal Noise
00288     if (makePedNoisePlots && useDigis) doPedestalNoise(strips);
00289   
00290     // look at recHit and segment efficiencies
00291     if (makeEfficiencyPlots) doEfficiencies(wires,strips, recHits, cscSegments,cscGeom);
00292 
00293     // gas gain
00294     if (makeGasGainPlots && useDigis) doGasGain(*wires,*strips,*recHits);
00295 
00296 
00297     // AFEB timing
00298     if (makeAFEBTimingPlots && useDigis) doAFEBTiming(*wires);
00299 
00300     // Comparators timing
00301     if (makeCompTimingPlots && useDigis) doCompTiming(*compars);
00302 
00303     // strip ADC timing
00304     if (makeADCTimingPlots) doADCTiming(*recHits);
00305 
00306 
00307 
00308     // recHit Noise
00309     if (makeRHNoisePlots && useDigis) doNoiseHits(recHits,cscSegments,cscGeom,strips);
00310 
00311     // look at standalone muons (not implemented yet)
00312     if (makeStandalonePlots) doStandalone(saMuons);
00313 
00314     // make plots for monitoring the trigger and offline timing
00315     if (makeTimeMonitorPlots) doTimeMonitoring(recHits,cscSegments, alcts, clcts, correlatedlcts, pCollection,cscGeom, eventSetup, event);
00316 
00317     firstEvent = false;
00318 
00319   }
00320 
00321 }
00322 
00323 // ==============================================
00324 //
00325 // event filter, returns true only for events with "good" standalone muon
00326 //
00327 // ==============================================
00328 
00329 bool CSCValidation::filterEvents(edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<CSCSegmentCollection> cscSegments,
00330                                  edm::Handle<reco::TrackCollection> saMuons){
00331 
00332   //int  nGoodSAMuons = 0;
00333 
00334   if (recHits->size() < 4 || recHits->size() > 100) return false;
00335   if (cscSegments->size() < 1 || cscSegments->size() > 15) return false;
00336   return true;
00337   //if (saMuons->size() != 1) return false;
00338   /*
00339   for(reco::TrackCollection::const_iterator muon = saMuons->begin(); muon != saMuons->end(); ++ muon ) {  
00340     double p  = muon->p();
00341     double reducedChisq = muon->normalizedChi2();
00342 
00343     GlobalPoint  innerPnt(muon->innerPosition().x(),muon->innerPosition().y(),muon->innerPosition().z());
00344     GlobalPoint  outerPnt(muon->outerPosition().x(),muon->outerPosition().y(),muon->outerPosition().z());
00345     GlobalVector innerKin(muon->innerMomentum().x(),muon->innerMomentum().y(),muon->innerMomentum().z());
00346     GlobalVector outerKin(muon->outerMomentum().x(),muon->outerMomentum().y(),muon->outerMomentum().z());
00347     GlobalVector deltaPnt = innerPnt - outerPnt;
00348     double crudeLength = deltaPnt.mag();
00349     double deltaPhi = innerPnt.phi() - outerPnt.phi();
00350     double innerGlobalPolarAngle = innerKin.theta();
00351     double outerGlobalPolarAngle = outerKin.theta();
00352 
00353     int nCSCHits = 0;
00354     for (trackingRecHit_iterator hit = muon->recHitsBegin(); hit != muon->recHitsEnd(); ++hit ) {
00355       if ( (*hit)->isValid() ) {
00356         const DetId detId( (*hit)->geographicalId() );
00357         if (detId.det() == DetId::Muon) {
00358           if (detId.subdetId() == MuonSubdetId::CSC) {
00359             nCSCHits++;
00360           } // this is a CSC hit
00361         } // this is a muon hit
00362       } // hit is valid
00363     } // end loop over rechits
00364 
00365     bool goodSAMuon = (p > pMin)
00366       && ( reducedChisq < chisqMax )
00367       && ( nCSCHits >= nCSCHitsMin )
00368       && ( nCSCHits <= nCSCHitsMax )
00369       && ( crudeLength > lengthMin )
00370       && ( crudeLength < lengthMax );
00371 
00372     
00373     goodSAMuon = goodSAMuon && ( fabs(deltaPhi) < deltaPhiMax );
00374     goodSAMuon = goodSAMuon &&
00375       (
00376        ( (     innerGlobalPolarAngle > polarMin) && (     innerGlobalPolarAngle < polarMax) ) ||
00377        ( (M_PI-innerGlobalPolarAngle > polarMin) && (M_PI-innerGlobalPolarAngle < polarMax) )
00378        );
00379     goodSAMuon = goodSAMuon &&
00380       (
00381        ( (     outerGlobalPolarAngle > polarMin) && (     outerGlobalPolarAngle < polarMax) ) ||
00382        ( (M_PI-outerGlobalPolarAngle > polarMin) && (M_PI-outerGlobalPolarAngle < polarMax) )
00383        );
00384 
00385    //goodSAMuon = goodSAMuon && (nCSCHits > nCSCHitsMin) && (nCSCHits < 13);  
00386    //goodSAMuon = goodSAMuon && (nCSCHits > 13) && (nCSCHits < 19);
00387    //goodSAMuon = goodSAMuon && (nCSCHits > 19) && (nCSCHits < nCSCHitsMax);
00388 
00389 
00390    if (goodSAMuon) nGoodSAMuons++;
00391    
00392   } // end loop over stand-alone muon collection
00393 
00394 
00395   histos->fill1DHist(nGoodSAMuons,"hNGoodMuons", "Number of Good STA Muons per Event",11,-0.5,10.5,"STAMuons");
00396 
00397   if (nGoodSAMuons == 1) return true;
00398   return false;
00399   */
00400 }
00401 
00402 // ==============================================
00403 //
00404 // look at Occupancies
00405 //
00406 // ==============================================
00407 
00408 void CSCValidation::doOccupancies(edm::Handle<CSCStripDigiCollection> strips, edm::Handle<CSCWireDigiCollection> wires,
00409                                   edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<CSCSegmentCollection> cscSegments){
00410 
00411   bool wireo[2][4][4][36];
00412   bool stripo[2][4][4][36];
00413   bool rechito[2][4][4][36];
00414   bool segmento[2][4][4][36];
00415 
00416   bool hasWires = false;
00417   bool hasStrips = false;
00418   bool hasRecHits = false;
00419   bool hasSegments = false;
00420 
00421   for (int e = 0; e < 2; e++){
00422     for (int s = 0; s < 4; s++){
00423       for (int r = 0; r < 4; r++){
00424         for (int c = 0; c < 36; c++){
00425           wireo[e][s][r][c] = false;
00426           stripo[e][s][r][c] = false;
00427           rechito[e][s][r][c] = false;
00428           segmento[e][s][r][c] = false;
00429         }
00430       }
00431     }
00432   }
00433 
00434   if (useDigis){
00435     //wires
00436     for (CSCWireDigiCollection::DigiRangeIterator wi=wires->begin(); wi!=wires->end(); wi++) {
00437       CSCDetId id = (CSCDetId)(*wi).first;
00438       int kEndcap  = id.endcap();
00439       int kRing    = id.ring();
00440       int kStation = id.station();
00441       int kChamber = id.chamber();
00442       std::vector<CSCWireDigi>::const_iterator wireIt = (*wi).second.first;
00443       std::vector<CSCWireDigi>::const_iterator lastWire = (*wi).second.second;
00444       for( ; wireIt != lastWire; ++wireIt){
00445         if (!wireo[kEndcap-1][kStation-1][kRing-1][kChamber-1]){
00446           wireo[kEndcap-1][kStation-1][kRing-1][kChamber-1] = true;
00447           hOWires->Fill(kChamber,typeIndex(id));
00448           histos->fill1DHist(chamberSerial(id),"hOWireSerial","Wire Occupancy by Chamber Serial",601,-0.5,600.5,"Digis");
00449           hasWires = true;
00450         }
00451       }
00452     }
00453   
00454     //strips
00455     for (CSCStripDigiCollection::DigiRangeIterator si=strips->begin(); si!=strips->end(); si++) {
00456       CSCDetId id = (CSCDetId)(*si).first;
00457       int kEndcap  = id.endcap();
00458       int kRing    = id.ring();
00459       int kStation = id.station();
00460       int kChamber = id.chamber();
00461       std::vector<CSCStripDigi>::const_iterator stripIt = (*si).second.first;
00462       std::vector<CSCStripDigi>::const_iterator lastStrip = (*si).second.second;
00463       for( ; stripIt != lastStrip; ++stripIt) {
00464         std::vector<int> myADCVals = stripIt->getADCCounts();
00465         bool thisStripFired = false;
00466         float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
00467         float threshold = 13.3 ;
00468         float diff = 0.;
00469         for (unsigned int iCount = 0; iCount < myADCVals.size(); iCount++) {
00470           diff = (float)myADCVals[iCount]-thisPedestal;
00471           if (diff > threshold) { thisStripFired = true; }
00472         }
00473         if (thisStripFired) {
00474           if (!stripo[kEndcap-1][kStation-1][kRing-1][kChamber-1]){
00475             stripo[kEndcap-1][kStation-1][kRing-1][kChamber-1] = true;
00476             hOStrips->Fill(kChamber,typeIndex(id));
00477             histos->fill1DHist(chamberSerial(id),"hOStripSerial","Strip Occupancy by Chamber Serial",601,-0.5,600.5,"Digis");
00478             hasStrips = true;
00479           }
00480         }
00481       }
00482     }
00483   }
00484 
00485   //rechits
00486   CSCRecHit2DCollection::const_iterator recIt;
00487   for (recIt = recHits->begin(); recIt != recHits->end(); recIt++) {
00488     CSCDetId idrec = (CSCDetId)(*recIt).cscDetId();
00489     int kEndcap  = idrec.endcap();
00490     int kRing    = idrec.ring();
00491     int kStation = idrec.station();
00492     int kChamber = idrec.chamber();
00493     if (!rechito[kEndcap-1][kStation-1][kRing-1][kChamber-1]){
00494       rechito[kEndcap-1][kStation-1][kRing-1][kChamber-1] = true;
00495       histos->fill1DHist(chamberSerial(idrec),"hORecHitsSerial","RecHit Occupancy by Chamber Serial",601,-0.5,600.5,"recHits");
00496       hORecHits->Fill(kChamber,typeIndex(idrec));
00497       hasRecHits = true;
00498     }
00499   }
00500 
00501   //segments
00502   for(CSCSegmentCollection::const_iterator segIt=cscSegments->begin(); segIt != cscSegments->end(); segIt++) {
00503     CSCDetId id  = (CSCDetId)(*segIt).cscDetId();
00504     int kEndcap  = id.endcap();
00505     int kRing    = id.ring();
00506     int kStation = id.station();
00507     int kChamber = id.chamber();
00508     if (!segmento[kEndcap-1][kStation-1][kRing-1][kChamber-1]){
00509       segmento[kEndcap-1][kStation-1][kRing-1][kChamber-1] = true;
00510       histos->fill1DHist(chamberSerial(id),"hOSegmentsSerial","Segment Occupancy by Chamber Serial",601,-0.5,600.5,"Segments");
00511       hOSegments->Fill(kChamber,typeIndex(id));
00512       hasSegments = true;
00513     }
00514   }
00515 
00516   // overall CSC occupancy (events with CSC data compared to total)
00517   histos->fill1DHist(1,"hCSCOccupancy","overall CSC occupancy",15,-0.5,14.5,"GeneralHists");
00518   if (hasWires) histos->fill1DHist(3,"hCSCOccupancy","overall CSC occupancy",15,-0.5,14.5,"GeneralHists");
00519   if (hasStrips) histos->fill1DHist(5,"hCSCOccupancy","overall CSC occupancy",15,-0.5,14.5,"GeneralHists");
00520   if (hasWires && hasStrips) histos->fill1DHist(7,"hCSCOccupancy","overall CSC occupancy",15,-0.5,14.5,"GeneralHists");
00521   if (hasRecHits) histos->fill1DHist(9,"hCSCOccupancy","overall CSC occupancy",15,-0.5,14.5,"GeneralHists");
00522   if (hasSegments) histos->fill1DHist(11,"hCSCOccupancy","overall CSC occupancy",15,-0.5,14.5,"GeneralHists");
00523   if (!cleanEvent) histos->fill1DHist(13,"hCSCOccupancy","overall CSC occupancy",15,-0.5,14.5,"GeneralHists");
00524 
00525 }
00526 
00527 // ==============================================
00528 //
00529 // look at Trigger info
00530 //
00531 // ==============================================
00532 
00533 bool CSCValidation::doTrigger(edm::Handle<L1MuGMTReadoutCollection> pCollection){
00534 
00535   std::vector<L1MuGMTReadoutRecord> L1Mrec = pCollection->getRecords();
00536   std::vector<L1MuGMTReadoutRecord>::const_iterator igmtrr;
00537 
00538   bool csc_l1a  = false;
00539   bool dt_l1a   = false;
00540   bool rpcf_l1a = false;
00541   bool rpcb_l1a = false;
00542   bool beamHaloTrigger = false;
00543 
00544   int myBXNumber = -1000;
00545 
00546   for(igmtrr=L1Mrec.begin(); igmtrr!=L1Mrec.end(); igmtrr++) {
00547     std::vector<L1MuRegionalCand>::const_iterator iter1;
00548     std::vector<L1MuRegionalCand> rmc;
00549 
00550     // CSC
00551     int icsc = 0;
00552     rmc = igmtrr->getCSCCands();
00553     for(iter1=rmc.begin(); iter1!=rmc.end(); iter1++) {
00554       if ( !(*iter1).empty() ) {
00555         icsc++;
00556         int kQuality = (*iter1).quality();   // kQuality = 1 means beam halo
00557         if (kQuality == 1) beamHaloTrigger = true;
00558       }
00559     }
00560     if (igmtrr->getBxInEvent() == 0 && icsc>0) csc_l1a = true;
00561     if (igmtrr->getBxInEvent() == 0 ) { myBXNumber = igmtrr->getBxNr(); }
00562 
00563     // DT
00564     int idt = 0;
00565     rmc = igmtrr->getDTBXCands();
00566     for(iter1=rmc.begin(); iter1!=rmc.end(); iter1++) {
00567       if ( !(*iter1).empty() ) {
00568         idt++;
00569       }
00570     }
00571     if(igmtrr->getBxInEvent()==0 && idt>0) dt_l1a = true;
00572 
00573     // RPC Barrel
00574     int irpcb = 0;
00575     rmc = igmtrr->getBrlRPCCands();
00576     for(iter1=rmc.begin(); iter1!=rmc.end(); iter1++) {
00577       if ( !(*iter1).empty() ) {
00578         irpcb++;
00579       }
00580     }
00581     if(igmtrr->getBxInEvent()==0 && irpcb>0) rpcb_l1a = true;
00582 
00583     // RPC Forward
00584     int irpcf = 0;
00585     rmc = igmtrr->getFwdRPCCands();
00586     for(iter1=rmc.begin(); iter1!=rmc.end(); iter1++) {
00587       if ( !(*iter1).empty() ) {
00588         irpcf++;
00589       }
00590     }
00591     if(igmtrr->getBxInEvent()==0 && irpcf>0) rpcf_l1a = true;
00592 
00593   }
00594 
00595   // Fill some histograms with L1A info
00596   if (csc_l1a)          histos->fill1DHist(myBXNumber,"vtBXNumber","BX Number",4001,-0.5,4000.5,"Trigger");
00597   if (csc_l1a)          histos->fill1DHist(1,"vtBits","trigger bits",11,-0.5,10.5,"Trigger");
00598   if (dt_l1a)           histos->fill1DHist(2,"vtBits","trigger bits",11,-0.5,10.5,"Trigger");
00599   if (rpcb_l1a)         histos->fill1DHist(3,"vtBits","trigger bits",11,-0.5,10.5,"Trigger");
00600   if (rpcf_l1a)         histos->fill1DHist(4,"vtBits","trigger bits",11,-0.5,10.5,"Trigger");
00601   if (beamHaloTrigger)  histos->fill1DHist(8,"vtBits","trigger bits",11,-0.5,10.5,"Trigger");
00602 
00603   if (csc_l1a) {
00604     histos->fill1DHist(1,"vtCSCY","trigger bits",11,-0.5,10.5,"Trigger");
00605     if (dt_l1a)   histos->fill1DHist(2,"vtCSCY","trigger bits",11,-0.5,10.5,"Trigger");
00606     if (rpcb_l1a) histos->fill1DHist(3,"vtCSCY","trigger bits",11,-0.5,10.5,"Trigger");
00607     if (rpcf_l1a) histos->fill1DHist(4,"vtCSCY","trigger bits",11,-0.5,10.5,"Trigger");
00608     if (  dt_l1a || rpcb_l1a || rpcf_l1a)  histos->fill1DHist(5,"vtCSCY","trigger bits",11,-0.5,10.5,"Trigger");
00609     if (!(dt_l1a || rpcb_l1a || rpcf_l1a)) histos->fill1DHist(6,"vtCSCY","trigger bits",11,-0.5,10.5,"Trigger");
00610   } else {
00611     histos->fill1DHist(1,"vtCSCN","trigger bits",11,-0.5,10.5,"Trigger");
00612     if (dt_l1a)   histos->fill1DHist(2,"vtCSCN","trigger bits",11,-0.5,10.5,"Trigger");
00613     if (rpcb_l1a) histos->fill1DHist(3,"vtCSCN","trigger bits",11,-0.5,10.5,"Trigger");
00614     if (rpcf_l1a) histos->fill1DHist(4,"vtCSCN","trigger bits",11,-0.5,10.5,"Trigger");
00615     if (  dt_l1a || rpcb_l1a || rpcf_l1a)  histos->fill1DHist(5,"vtCSCN","trigger bits",11,-0.5,10.5,"Trigger");
00616     if (!(dt_l1a || rpcb_l1a || rpcf_l1a)) histos->fill1DHist(6,"vtCSCN","trigger bits",11,-0.5,10.5,"Trigger");
00617   }
00618 
00619   // if valid CSC L1A then return true for possible use elsewhere
00620 
00621   if (csc_l1a) return true;
00622   
00623   return false;
00624 
00625 }
00626 
00627 // ==============================================
00628 //    
00629 // look at HLT Trigger
00630 //  
00631 // ==============================================
00632 
00633 bool CSCValidation::doHLT(Handle<TriggerResults> hlt){
00634 
00635   // HLT stuff
00636   int hltSize = hlt->size();
00637   for (int i = 0; i < hltSize; ++i){
00638     if (hlt->accept(i)) histos->fill1DHist(i,"hltBits","HLT Trigger Bits",hltSize+1,-0.5,(float)hltSize+0.5,"Trigger");
00639   }
00640 
00641   return true;
00642 }
00643 
00644 
00645 // ==============================================
00646 //
00647 // look at Calibrations
00648 //
00649 // ==============================================
00650 
00651 void CSCValidation::doCalibrations(const edm::EventSetup& eventSetup){
00652 
00653   // Only do this for the first event
00654   if (nEventsAnalyzed == 1){
00655 
00656     LogDebug("Calibrations") << "Loading Calibrations...";
00657 
00658     // get the gains
00659     edm::ESHandle<CSCDBGains> hGains;
00660     eventSetup.get<CSCDBGainsRcd>().get( hGains );
00661     const CSCDBGains* pGains = hGains.product();
00662     // get the crosstalks
00663     edm::ESHandle<CSCDBCrosstalk> hCrosstalk;
00664     eventSetup.get<CSCDBCrosstalkRcd>().get( hCrosstalk );
00665     const CSCDBCrosstalk* pCrosstalk = hCrosstalk.product();
00666     // get the noise matrix
00667     edm::ESHandle<CSCDBNoiseMatrix> hNoiseMatrix;
00668     eventSetup.get<CSCDBNoiseMatrixRcd>().get( hNoiseMatrix );
00669     const CSCDBNoiseMatrix* pNoiseMatrix = hNoiseMatrix.product();
00670     // get pedestals
00671     edm::ESHandle<CSCDBPedestals> hPedestals;
00672     eventSetup.get<CSCDBPedestalsRcd>().get( hPedestals );
00673     const CSCDBPedestals* pPedestals = hPedestals.product();
00674 
00675     LogDebug("Calibrations") << "Calibrations Loaded!";
00676 
00677     for (int i = 0; i < 400; i++){
00678       int bin = i+1;
00679       histos->fillCalibHist(pGains->gains[i].gain_slope,"hCalibGainsS","Gains Slope",400,0,400,bin,"Calib");
00680       histos->fillCalibHist(pCrosstalk->crosstalk[i].xtalk_slope_left,"hCalibXtalkSL","Xtalk Slope Left",400,0,400,bin,"Calib");
00681       histos->fillCalibHist(pCrosstalk->crosstalk[i].xtalk_slope_right,"hCalibXtalkSR","Xtalk Slope Right",400,0,400,bin,"Calib");
00682       histos->fillCalibHist(pCrosstalk->crosstalk[i].xtalk_intercept_left,"hCalibXtalkIL","Xtalk Intercept Left",400,0,400,bin,"Calib");
00683       histos->fillCalibHist(pCrosstalk->crosstalk[i].xtalk_intercept_right,"hCalibXtalkIR","Xtalk Intercept Right",400,0,400,bin,"Calib");
00684       histos->fillCalibHist(pPedestals->pedestals[i].ped,"hCalibPedsP","Peds",400,0,400,bin,"Calib");
00685       histos->fillCalibHist(pPedestals->pedestals[i].rms,"hCalibPedsR","Peds RMS",400,0,400,bin,"Calib");
00686       histos->fillCalibHist(pNoiseMatrix->matrix[i].elem33,"hCalibNoise33","Noise Matrix 33",400,0,400,bin,"Calib");
00687       histos->fillCalibHist(pNoiseMatrix->matrix[i].elem34,"hCalibNoise34","Noise Matrix 34",400,0,400,bin,"Calib");
00688       histos->fillCalibHist(pNoiseMatrix->matrix[i].elem35,"hCalibNoise35","Noise Matrix 35",400,0,400,bin,"Calib");
00689       histos->fillCalibHist(pNoiseMatrix->matrix[i].elem44,"hCalibNoise44","Noise Matrix 44",400,0,400,bin,"Calib");
00690       histos->fillCalibHist(pNoiseMatrix->matrix[i].elem45,"hCalibNoise45","Noise Matrix 45",400,0,400,bin,"Calib");
00691       histos->fillCalibHist(pNoiseMatrix->matrix[i].elem46,"hCalibNoise46","Noise Matrix 46",400,0,400,bin,"Calib");
00692       histos->fillCalibHist(pNoiseMatrix->matrix[i].elem55,"hCalibNoise55","Noise Matrix 55",400,0,400,bin,"Calib");
00693       histos->fillCalibHist(pNoiseMatrix->matrix[i].elem56,"hCalibNoise56","Noise Matrix 56",400,0,400,bin,"Calib");
00694       histos->fillCalibHist(pNoiseMatrix->matrix[i].elem57,"hCalibNoise57","Noise Matrix 57",400,0,400,bin,"Calib");
00695       histos->fillCalibHist(pNoiseMatrix->matrix[i].elem66,"hCalibNoise66","Noise Matrix 66",400,0,400,bin,"Calib");
00696       histos->fillCalibHist(pNoiseMatrix->matrix[i].elem67,"hCalibNoise67","Noise Matrix 67",400,0,400,bin,"Calib");
00697       histos->fillCalibHist(pNoiseMatrix->matrix[i].elem77,"hCalibNoise77","Noise Matrix 77",400,0,400,bin,"Calib");
00698 
00699  
00700     }
00701 
00702   }
00703 
00704 
00705 }
00706 
00707 
00708 // ==============================================
00709 //
00710 // look at WIRE DIGIs
00711 //
00712 // ==============================================
00713 
00714 void CSCValidation::doWireDigis(edm::Handle<CSCWireDigiCollection> wires){
00715 
00716   int nWireGroupsTotal = 0;
00717   for (CSCWireDigiCollection::DigiRangeIterator dWDiter=wires->begin(); dWDiter!=wires->end(); dWDiter++) {
00718     CSCDetId id = (CSCDetId)(*dWDiter).first;
00719     std::vector<CSCWireDigi>::const_iterator wireIter = (*dWDiter).second.first;
00720     std::vector<CSCWireDigi>::const_iterator lWire = (*dWDiter).second.second;
00721     for( ; wireIter != lWire; ++wireIter) {
00722       int myWire = wireIter->getWireGroup();
00723       int myTBin = wireIter->getTimeBin();
00724       nWireGroupsTotal++;
00725       histos->fill1DHistByType(myWire,"hWireWire","Wiregroup Numbers Fired",id,113,-0.5,112.5,"Digis");
00726       histos->fill1DHistByType(myTBin,"hWireTBin","Wire TimeBin Fired",id,17,-0.5,16.5,"Digis");
00727       histos->fillProfile(chamberSerial(id),myTBin,"hWireTBinProfile","Wire TimeBin Fired",601,-0.5,600.5,-0.5,16.5,"Digis");
00728       if (detailedAnalysis){
00729         histos->fill1DHistByLayer(myWire,"hWireWire","Wiregroup Numbers Fired",id,113,-0.5,112.5,"WireNumberByLayer");
00730         histos->fill1DHistByLayer(myTBin,"hWireTBin","Wire TimeBin Fired",id,17,-0.5,16.5,"WireTimeByLayer");
00731       }
00732     }
00733   } // end wire loop
00734 
00735   // this way you can zero suppress but still store info on # events with no digis
00736   if (nWireGroupsTotal == 0) nWireGroupsTotal = -1;
00737 
00738   histos->fill1DHist(nWireGroupsTotal,"hWirenGroupsTotal","Wires Fired Per Event",151,-0.5,150.5,"Digis");
00739   
00740 }
00741 
00742 // ==============================================
00743 //
00744 // look at STRIP DIGIs
00745 //
00746 // ==============================================
00747 
00748 void CSCValidation::doStripDigis(edm::Handle<CSCStripDigiCollection> strips){
00749 
00750   int nStripsFired = 0;
00751   for (CSCStripDigiCollection::DigiRangeIterator dSDiter=strips->begin(); dSDiter!=strips->end(); dSDiter++) {
00752     CSCDetId id = (CSCDetId)(*dSDiter).first;
00753     std::vector<CSCStripDigi>::const_iterator stripIter = (*dSDiter).second.first;
00754     std::vector<CSCStripDigi>::const_iterator lStrip = (*dSDiter).second.second;
00755     for( ; stripIter != lStrip; ++stripIter) {
00756       int myStrip = stripIter->getStrip();
00757       std::vector<int> myADCVals = stripIter->getADCCounts();
00758       bool thisStripFired = false;
00759       float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
00760       float threshold = 13.3 ;
00761       float diff = 0.;
00762       for (unsigned int iCount = 0; iCount < myADCVals.size(); iCount++) {
00763         diff = (float)myADCVals[iCount]-thisPedestal;
00764         if (diff > threshold) { thisStripFired = true; }
00765       } 
00766       if (thisStripFired) {
00767         nStripsFired++;
00768         // fill strip histos
00769         histos->fill1DHistByType(myStrip,"hStripStrip","Strip Number",id,81,-0.5,80.5,"Digis");
00770         if (detailedAnalysis){
00771           histos->fill1DHistByLayer(myStrip,"hStripStrip","Strip Number",id,81,-0.5,80.5,"StripNumberByLayer");
00772         }
00773       }
00774     }
00775   } // end strip loop
00776 
00777   if (nStripsFired == 0) nStripsFired = -1;
00778 
00779   histos->fill1DHist(nStripsFired,"hStripNFired","Fired Strips per Event",251,-0.5,250.5,"Digis");
00780 
00781 }
00782 
00783 //=======================================================
00784 //
00785 // Look at the Pedestal Noise Distributions
00786 //
00787 //=======================================================
00788 
00789 void CSCValidation::doPedestalNoise(edm::Handle<CSCStripDigiCollection> strips){
00790 
00791   for (CSCStripDigiCollection::DigiRangeIterator dPNiter=strips->begin(); dPNiter!=strips->end(); dPNiter++) {
00792     CSCDetId id = (CSCDetId)(*dPNiter).first;
00793     std::vector<CSCStripDigi>::const_iterator pedIt = (*dPNiter).second.first;
00794     std::vector<CSCStripDigi>::const_iterator lStrip = (*dPNiter).second.second;
00795     for( ; pedIt != lStrip; ++pedIt) {
00796       int myStrip = pedIt->getStrip();
00797       std::vector<int> myADCVals = pedIt->getADCCounts();
00798       float TotalADC = getSignal(*strips, id, myStrip);
00799       bool thisStripFired = false;
00800       float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
00801       float thisSignal = (1./6)*(myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
00802       float threshold = 13.3;
00803       if(id.station() == 1 && id.ring() == 4)
00804         {
00805           if(myStrip <= 16) myStrip += 64; // no trapping for any bizarreness
00806         }
00807       if (TotalADC > threshold) { thisStripFired = true;}
00808       if (!thisStripFired){
00809         float ADC = thisSignal - thisPedestal;
00810         histos->fill1DHist(ADC,"hStripPed","Pedestal Noise Distribution",50,-25.,25.,"PedestalNoise");
00811         histos->fill1DHistByType(ADC,"hStripPedME","Pedestal Noise Distribution",id,50,-25.,25.,"PedestalNoise");
00812         histos->fillProfile(chamberSerial(id),ADC,"hStripPedMEProfile","Wire TimeBin Fired",601,-0.5,600.5,-25,25,"PedestalNoise");
00813         if (detailedAnalysis){
00814           histos->fill1DHistByLayer(ADC,"hStripPedME","Pedestal Noise Distribution",id,50,-25.,25.,"PedestalNoiseByLayer");
00815         }
00816       }
00817     }
00818   }
00819 
00820 }
00821 
00822 
00823 // ==============================================
00824 //
00825 // look at RECHITs
00826 //
00827 // ==============================================
00828 
00829 void CSCValidation::doRecHits(edm::Handle<CSCRecHit2DCollection> recHits, edm::ESHandle<CSCGeometry> cscGeom){
00830 
00831   // Get the RecHits collection :
00832   int nRecHits = recHits->size();
00833  
00834   // ---------------------
00835   // Loop over rechits 
00836   // ---------------------
00837   int iHit = 0;
00838 
00839   // Build iterator for rechits and loop :
00840   CSCRecHit2DCollection::const_iterator dRHIter;
00841   for (dRHIter = recHits->begin(); dRHIter != recHits->end(); dRHIter++) {
00842     iHit++;
00843 
00844     // Find chamber with rechits in CSC 
00845     CSCDetId idrec = (CSCDetId)(*dRHIter).cscDetId();
00846     int kEndcap  = idrec.endcap();
00847     int kRing    = idrec.ring();
00848     int kStation = idrec.station();
00849     int kChamber = idrec.chamber();
00850     int kLayer   = idrec.layer();
00851 
00852     // Store rechit as a Local Point:
00853     LocalPoint rhitlocal = (*dRHIter).localPosition();  
00854     float xreco = rhitlocal.x();
00855     float yreco = rhitlocal.y();
00856     LocalError rerrlocal = (*dRHIter).localPositionError();  
00857     //these errors are squared!
00858     float xxerr = rerrlocal.xx();
00859     float yyerr = rerrlocal.yy();
00860     float xyerr = rerrlocal.xy();
00861     // errors in strip units
00862     float stpos = (*dRHIter).positionWithinStrip();
00863     float sterr = (*dRHIter).errorWithinStrip();
00864 
00865     // Find the charge associated with this hit
00866     float rHSumQ = 0;
00867     float sumsides=0.;
00868     int adcsize=dRHIter->nStrips()*dRHIter->nTimeBins();
00869     for ( unsigned int i=0; i< dRHIter->nStrips(); i++) {
00870       for ( unsigned int j=0; j< dRHIter->nTimeBins()-1; j++) {
00871         rHSumQ+=dRHIter->adcs(i,j); 
00872         if (i!=1) sumsides+=dRHIter->adcs(i,j);
00873       }
00874     }
00875 
00876     float rHratioQ = sumsides/rHSumQ;
00877     if (adcsize != 12) rHratioQ = -99;
00878 
00879     // Get the signal timing of this hit
00880     float rHtime = 0;
00881     rHtime = (*dRHIter).tpeak()/50.;
00882 
00883     // Get pointer to the layer:
00884     const CSCLayer* csclayer = cscGeom->layer( idrec );
00885 
00886     // Transform hit position from local chamber geometry to global CMS geom
00887     GlobalPoint rhitglobal= csclayer->toGlobal(rhitlocal);
00888     float grecx   =  rhitglobal.x();
00889     float grecy   =  rhitglobal.y();
00890 
00891     // Fill the rechit position branch
00892     if (writeTreeToFile && rhTreeCount < 1500000){
00893       histos->fillRechitTree(xreco, yreco, grecx, grecy, kEndcap, kStation, kRing, kChamber, kLayer);
00894       rhTreeCount++;
00895     }    
00896 
00897     // Fill some histograms
00898     // only fill if 3 strips were used in the hit
00899     histos->fill2DHistByStation(grecx,grecy,"hRHGlobal","recHit Global Position",idrec,100,-800.,800.,100,-800.,800.,"recHits");
00900     if (kStation == 1 && (kRing == 1 || kRing == 4)) histos->fill1DHistByType(rHSumQ,"hRHSumQ","Sum 3x3 recHit Charge",idrec,125,0,4000,"recHits");
00901     else histos->fill1DHistByType(rHSumQ,"hRHSumQ","Sum 3x3 recHit Charge",idrec,125,0,2000,"recHits");
00902     histos->fill1DHistByType(rHratioQ,"hRHRatioQ","Charge Ratio (Ql+Qr)/Qt",idrec,120,-0.1,1.1,"recHits");
00903     histos->fill1DHistByType(rHtime,"hRHTiming","recHit Timing",idrec,200,-10,10,"recHits");
00904     histos->fill1DHistByType(sqrt(xxerr),"hRHxerr","RecHit Error on Local X",idrec,100,-0.1,2,"recHits");
00905     histos->fill1DHistByType(sqrt(yyerr),"hRHyerr","RecHit Error on Local Y",idrec,100,-0.1,2,"recHits");
00906     histos->fill1DHistByType(xyerr,"hRHxyerr","Corr. RecHit XY Error",idrec,100,-1,2,"recHits");
00907     if (adcsize == 12) histos->fill1DHistByType(stpos,"hRHstpos","Reconstructed Position on Strip",idrec,120,-0.6,0.6,"recHits");
00908     histos->fill1DHistByType(sterr,"hRHsterr","Estimated Error on Strip Measurement",idrec,120,-0.05,0.25,"recHits");
00909     histos->fillProfile(chamberSerial(idrec),rHSumQ,"hRHSumQProfile","Sum 3x3 recHit Charge",601,-0.5,600.5,0,4000,"recHits");
00910     histos->fillProfile(chamberSerial(idrec),rHtime,"hRHTimingProfile","recHit Timing",601,-0.5,600.5,-11,11,"recHits");
00911     if (detailedAnalysis){
00912       if (kStation == 1 && (kRing == 1 || kRing == 4)) histos->fill1DHistByLayer(rHSumQ,"hRHSumQ","Sum 3x3 recHit Charge",idrec,125,0,4000,"RHQByLayer");
00913       else histos->fill1DHistByLayer(rHSumQ,"hRHSumQ","Sum 3x3 recHit Charge",idrec,125,0,2000,"RHQByLayer");
00914       histos->fill1DHistByLayer(rHratioQ,"hRHRatioQ","Charge Ratio (Ql+Qr)/Qt",idrec,120,-0.1,1.1,"RHQByLayer");
00915       histos->fill1DHistByLayer(rHtime,"hRHTiming","recHit Timing",idrec,200,-10,10,"RHTimingByLayer");
00916       histos->fill2DHistByLayer(xreco,yreco,"hRHLocalXY","recHit Local Position",idrec,50,-100.,100.,75,-150.,150.,"RHLocalXYByLayer");
00917       histos->fill1DHistByLayer(sqrt(xxerr),"hRHxerr","RecHit Error on Local X",idrec,100,-0.1,2,"RHErrorsByLayer");
00918       histos->fill1DHistByLayer(sqrt(yyerr),"hRHyerr","RecHit Error on Local Y",idrec,100,-0.1,2,"RHErrorsByLayer");
00919       histos->fill1DHistByType(stpos,"hRHstpos","Reconstructed Position on Strip",idrec,120,-0.6,0.6,"RHStripPosByLayer");
00920       histos->fill1DHistByType(sterr,"hRHsterr","Estimated Error on Strip Measurement",idrec,120,-0.05,0.25,"RHStripPosByLayer");
00921     }
00922 
00923   } //end rechit loop
00924 
00925   if (nRecHits == 0) nRecHits = -1;
00926 
00927   histos->fill1DHist(nRecHits,"hRHnrechits","recHits per Event (all chambers)",151,-0.5,150.5,"recHits");
00928 
00929 }
00930 
00931 // ==============================================
00932 //
00933 // look at SIMHITS
00934 //
00935 // ==============================================
00936 
00937 void CSCValidation::doSimHits(edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<PSimHitContainer> simHits){
00938 
00939   CSCRecHit2DCollection::const_iterator dSHrecIter;
00940   for (dSHrecIter = recHits->begin(); dSHrecIter != recHits->end(); dSHrecIter++) {
00941 
00942     CSCDetId idrec = (CSCDetId)(*dSHrecIter).cscDetId();
00943     LocalPoint rhitlocal = (*dSHrecIter).localPosition();
00944     float xreco = rhitlocal.x();
00945     float yreco = rhitlocal.y();
00946     float xError = sqrt((*dSHrecIter).localPositionError().xx());
00947     float yError = sqrt((*dSHrecIter).localPositionError().yy());
00948     float simHitXres = -99;
00949     float simHitYres = -99;
00950     float xPull      = -99;
00951     float yPull      = -99;
00952     float mindiffX   = 99;
00953     float mindiffY   = 10;
00954     // If MC, find closest muon simHit to check resolution:
00955     PSimHitContainer::const_iterator dSHsimIter;
00956     for (dSHsimIter = simHits->begin(); dSHsimIter != simHits->end(); dSHsimIter++){
00957       // Get DetID for this simHit:
00958       CSCDetId sId = (CSCDetId)(*dSHsimIter).detUnitId();
00959       // Check if the simHit detID matches that of current recHit
00960       // and make sure it is a muon hit:
00961       if (sId == idrec && abs((*dSHsimIter).particleType()) == 13){
00962         // Get the position of this simHit in local coordinate system:
00963         LocalPoint sHitlocal = (*dSHsimIter).localPosition();
00964         // Now we need to make reasonably sure that this simHit is
00965         // responsible for this recHit:
00966         if ((sHitlocal.x() - xreco) < mindiffX && (sHitlocal.y() - yreco) < mindiffY){
00967           simHitXres = (sHitlocal.x() - xreco);
00968           simHitYres = (sHitlocal.y() - yreco);
00969           mindiffX = (sHitlocal.x() - xreco);
00970           xPull = simHitXres/xError;
00971           yPull = simHitYres/yError;
00972         }
00973       }
00974     }
00975 
00976     histos->fill1DHistByType(simHitXres,"hSimXResid","SimHitX - Reconstructed X",idrec,100,-1.0,1.0,"Resolution");
00977     histos->fill1DHistByType(simHitYres,"hSimYResid","SimHitY - Reconstructed Y",idrec,100,-5.0,5.0,"Resolution");
00978     histos->fill1DHistByType(xPull,"hSimXPull","Local X Pulls",idrec,100,-5.0,5.0,"Resolution");
00979     histos->fill1DHistByType(yPull,"hSimYPull","Local Y Pulls",idrec,100,-5.0,5.0,"Resolution");
00980 
00981   }
00982 
00983 }
00984 
00985 // ==============================================
00986 //
00987 // look at SEGMENTs
00988 //
00989 // ===============================================
00990 
00991 void CSCValidation::doSegments(edm::Handle<CSCSegmentCollection> cscSegments, edm::ESHandle<CSCGeometry> cscGeom){
00992 
00993   // get CSC segment collection
00994   int nSegments = cscSegments->size();
00995 
00996   // -----------------------
00997   // loop over segments
00998   // -----------------------
00999   int iSegment = 0;
01000   for(CSCSegmentCollection::const_iterator dSiter=cscSegments->begin(); dSiter != cscSegments->end(); dSiter++) {
01001     iSegment++;
01002     //
01003     CSCDetId id  = (CSCDetId)(*dSiter).cscDetId();
01004     int kEndcap  = id.endcap();
01005     int kRing    = id.ring();
01006     int kStation = id.station();
01007     int kChamber = id.chamber();
01008 
01009     //
01010     float chisq    = (*dSiter).chi2();
01011     int nhits      = (*dSiter).nRecHits();
01012     int nDOF       = 2*nhits-4;
01013     double chisqProb = ChiSquaredProbability( (double)chisq, nDOF );
01014     LocalPoint localPos = (*dSiter).localPosition();
01015     float segX     = localPos.x();
01016     float segY     = localPos.y();
01017     LocalVector segDir = (*dSiter).localDirection();
01018     double theta   = segDir.theta();
01019 
01020     // global transformation
01021     float globX = 0.;
01022     float globY = 0.;
01023     float globTheta = 0.;
01024     float globPhi   = 0.;
01025     const CSCChamber* cscchamber = cscGeom->chamber(id);
01026     if (cscchamber) {
01027       GlobalPoint globalPosition = cscchamber->toGlobal(localPos);
01028       globX = globalPosition.x();
01029       globY = globalPosition.y();
01030       GlobalVector globalDirection = cscchamber->toGlobal(segDir);
01031       globTheta = globalDirection.theta();
01032       globPhi   = globalDirection.phi();
01033     }
01034 
01035 
01036     // Fill segment position branch
01037     if (writeTreeToFile && segTreeCount < 1500000){
01038       histos->fillSegmentTree(segX, segY, globX, globY, kEndcap, kStation, kRing, kChamber);
01039       segTreeCount++;
01040     }
01041 
01042     // Fill histos
01043     histos->fill2DHistByStation(globX,globY,"hSGlobal","Segment Global Positions;global x (cm)",id,100,-800.,800.,100,-800.,800.,"Segments");
01044     histos->fill1DHistByType(nhits,"hSnHits","N hits on Segments",id,8,-0.5,7.5,"Segments");
01045     histos->fill1DHistByType(theta,"hSTheta","local theta segments",id,128,-3.2,3.2,"Segments");
01046     histos->fill1DHistByType((chisq/nDOF),"hSChiSq","segments chi-squared/ndof",id,110,-0.05,10.5,"Segments");
01047     histos->fill1DHistByType(chisqProb,"hSChiSqProb","segments chi-squared probability",id,110,-0.05,1.05,"Segments");
01048     histos->fill1DHist(globTheta,"hSGlobalTheta","segment global theta",128,0,3.2,"Segments");
01049     histos->fill1DHist(globPhi,"hSGlobalPhi","segment global phi",128,-3.2,3.2,"Segments");
01050     histos->fillProfile(chamberSerial(id),nhits,"hSnHitsProfile","N hits on Segments",601,-0.5,600.5,-0.5,7.5,"Segments");
01051     if (detailedAnalysis){
01052       histos->fill1DHistByChamber(nhits,"hSnHits","N hits on Segments",id,8,-0.5,7.5,"HitsOnSegmentByChamber");
01053       histos->fill1DHistByChamber(theta,"hSTheta","local theta segments",id,128,-3.2,3.2,"DetailedSegments");
01054       histos->fill1DHistByChamber((chisq/nDOF),"hSChiSq","segments chi-squared/ndof",id,110,-0.05,10.5,"SegChi2ByChamber");
01055       histos->fill1DHistByChamber(chisqProb,"hSChiSqProb","segments chi-squared probability",id,110,-0.05,1.05,"SegChi2ByChamber");
01056     }
01057 
01058   } // end segment loop
01059 
01060   if (nSegments == 0) nSegments = -1;
01061 
01062   histos->fill1DHist(nSegments,"hSnSegments","Segments per Event",31,-0.5,30.5,"Segments");
01063 
01064 }
01065 
01066 // ==============================================
01067 //
01068 // look at hit Resolution
01069 //
01070 // ===============================================
01071 
01072 void CSCValidation::doResolution(edm::Handle<CSCSegmentCollection> cscSegments, edm::ESHandle<CSCGeometry> cscGeom){
01073 
01074 
01075   for(CSCSegmentCollection::const_iterator dSiter=cscSegments->begin(); dSiter != cscSegments->end(); dSiter++) {
01076 
01077     CSCDetId id  = (CSCDetId)(*dSiter).cscDetId();
01078 
01079     //
01080     // try to get the CSC recHits that contribute to this segment.
01081     std::vector<CSCRecHit2D> theseRecHits = (*dSiter).specificRecHits();
01082     int nRH = (*dSiter).nRecHits();
01083     int jRH = 0;
01084     CLHEP::HepMatrix sp(6,1);
01085     CLHEP::HepMatrix se(6,1);
01086     for ( std::vector<CSCRecHit2D>::const_iterator iRH = theseRecHits.begin(); iRH != theseRecHits.end(); iRH++) {
01087       jRH++;
01088       CSCDetId idRH = (CSCDetId)(*iRH).cscDetId();
01089       int kRing    = idRH.ring();
01090       int kStation = idRH.station();
01091       int kLayer   = idRH.layer();
01092 
01093       // Find the strip containing this hit
01094       int centerid     =  iRH->nStrips()/2;
01095       int centerStrip =  iRH->channels(centerid);
01096 
01097       // If this segment has 6 hits, find the position of each hit on the strip in units of stripwidth and store values
01098       if (nRH == 6){
01099         float stpos = (*iRH).positionWithinStrip();
01100         se(kLayer,1) = (*iRH).errorWithinStrip();
01101         // Take into account half-strip staggering of layers (ME1/1 has no staggering)
01102         if (kStation == 1 && (kRing == 1 || kRing == 4)) sp(kLayer,1) = stpos + centerStrip;
01103         else{
01104           if (kLayer == 1 || kLayer == 3 || kLayer == 5) sp(kLayer,1) = stpos + centerStrip;
01105           if (kLayer == 2 || kLayer == 4 || kLayer == 6) sp(kLayer,1) = stpos - 0.5 + centerStrip;
01106         }
01107       }
01108 
01109     }
01110 
01111     float residual = -99;
01112     float pull = -99;
01113     // Fit all points except layer 3, then compare expected value for layer 3 to reconstructed value
01114     if (nRH == 6){
01115       float expected = fitX(sp,se);
01116       residual = expected - sp(3,1);
01117       pull = residual/se(3,1);
01118     }
01119 
01120     // Fill histos
01121     histos->fill1DHistByType(residual,"hSResid","Fitted Position on Strip - Reconstructed for Layer 3",id,100,-0.5,0.5,"Resolution");
01122     histos->fill1DHistByType(pull,"hSStripPosPull","Strip Measurement Pulls",id,100,-5.0,5.0,"Resolution");
01123     histos->fillProfile(chamberSerial(id),residual,"hSResidProfile","Fitted Position on Strip - Reconstructed for Layer 3",601,-0.5,600.5,-0.5,0.5,"Resolution");
01124     if (detailedAnalysis){
01125       histos->fill1DHistByChamber(residual,"hSResid","Fitted Position on Strip - Reconstructed for Layer 3",id,100,-0.5,0.5,"DetailedResolution");
01126       histos->fill1DHistByChamber(pull,"hSStripPosPull","Strip Measurement Pulls",id,100,-5.0,5.0,"Resolution");
01127     }
01128 
01129 
01130   }
01131 
01132 }
01133 
01134 // ==============================================
01135 //
01136 // look at Standalone Muons
01137 //
01138 // ==============================================
01139 
01140 void CSCValidation::doStandalone(Handle<reco::TrackCollection> saMuons){
01141 
01142   int nSAMuons = saMuons->size();
01143   histos->fill1DHist(nSAMuons,"trNSAMuons","N Standalone Muons per Event",6,-0.5,5.5,"STAMuons");
01144 
01145   for(reco::TrackCollection::const_iterator muon = saMuons->begin(); muon != saMuons->end(); ++ muon ) {
01146     float preco  = muon->p();
01147     float ptreco = muon->pt();
01148     int   n = muon->recHitsSize();
01149     float chi2 = muon->chi2();
01150     float normchi2 = muon->normalizedChi2();
01151 
01152     // loop over hits
01153     int nDTHits = 0;
01154     int nCSCHits = 0;
01155     int nCSCHitsp = 0;
01156     int nCSCHitsm = 0;
01157     int nRPCHits = 0;
01158     int nRPCHitsp = 0;
01159     int nRPCHitsm = 0;
01160     int np = 0;
01161     int nm = 0;
01162     std::vector<CSCDetId> staChambers;
01163     for (trackingRecHit_iterator hit = muon->recHitsBegin(); hit != muon->recHitsEnd(); ++hit ) {
01164       const DetId detId( (*hit)->geographicalId() );
01165       if (detId.det() == DetId::Muon) {
01166         if (detId.subdetId() == MuonSubdetId::RPC) {
01167           RPCDetId rpcId(detId.rawId());
01168           nRPCHits++;
01169           if (rpcId.region() == 1){ nRPCHitsp++; np++;}
01170           if (rpcId.region() == -1){ nRPCHitsm++; nm++;}
01171         }
01172         if (detId.subdetId() == MuonSubdetId::DT) {
01173           nDTHits++;
01174         }
01175         else if (detId.subdetId() == MuonSubdetId::CSC) {
01176           CSCDetId cscId(detId.rawId());
01177           staChambers.push_back(detId.rawId());
01178           nCSCHits++;
01179           if (cscId.endcap() == 1){ nCSCHitsp++; np++;}
01180           if (cscId.endcap() == 2){ nCSCHitsm++; nm++;}
01181         }
01182       }
01183     }
01184 
01185     GlobalPoint  innerPnt(muon->innerPosition().x(),muon->innerPosition().y(),muon->innerPosition().z());
01186     GlobalPoint  outerPnt(muon->outerPosition().x(),muon->outerPosition().y(),muon->outerPosition().z());
01187     GlobalVector innerKin(muon->innerMomentum().x(),muon->innerMomentum().y(),muon->innerMomentum().z());
01188     GlobalVector outerKin(muon->outerMomentum().x(),muon->outerMomentum().y(),muon->outerMomentum().z());
01189     GlobalVector deltaPnt = innerPnt - outerPnt;
01190     double crudeLength = deltaPnt.mag();
01191     double deltaPhi = innerPnt.phi() - outerPnt.phi();
01192     double innerGlobalPolarAngle = innerKin.theta();
01193     double outerGlobalPolarAngle = outerKin.theta();
01194 
01195 
01196     // fill histograms
01197     histos->fill1DHist(n,"trN","N hits on a STA Muon Track",51,-0.5,50.5,"STAMuons");
01198     if (np != 0) histos->fill1DHist(np,"trNp","N hits on a STA Muon Track (plus endcap)",51,-0.5,50.5,"STAMuons");
01199     if (nm != 0) histos->fill1DHist(nm,"trNm","N hits on a STA Muon Track (minus endcap)",51,-0.5,50.5,"STAMuons");
01200     histos->fill1DHist(nDTHits,"trNDT","N DT hits on a STA Muon Track",51,-0.5,50.5,"STAMuons");
01201     histos->fill1DHist(nCSCHits,"trNCSC","N CSC hits on a STA Muon Track",51,-0.5,50.5,"STAMuons");
01202     if (nCSCHitsp != 0) histos->fill1DHist(nCSCHitsp,"trNCSCp","N CSC hits on a STA Muon Track (+ endcap)",51,-0.5,50.5,"STAMuons");
01203     if (nCSCHitsm != 0) histos->fill1DHist(nCSCHitsm,"trNCSCm","N CSC hits on a STA Muon Track (- endcap)",51,-0.5,50.5,"STAMuons");
01204     histos->fill1DHist(nRPCHits,"trNRPC","N RPC hits on a STA Muon Track",51,-0.5,50.5,"STAMuons");
01205     if (nRPCHitsp != 0) histos->fill1DHist(nRPCHitsp,"trNRPCp","N RPC hits on a STA Muon Track (+ endcap)",51,-0.5,50.5,"STAMuons");
01206     if (nRPCHitsm != 0) histos->fill1DHist(nRPCHitsm,"trNRPCm","N RPC hits on a STA Muon Track (- endcap)",51,-0.5,50.5,"STAMuons");
01207     histos->fill1DHist(preco,"trP","STA Muon Momentum",100,0,300,"STAMuons");
01208     histos->fill1DHist(ptreco,"trPT","STA Muon pT",100,0,40,"STAMuons");
01209     histos->fill1DHist(chi2,"trChi2","STA Muon Chi2",100,0,200,"STAMuons");
01210     histos->fill1DHist(normchi2,"trNormChi2","STA Muon Normalized Chi2",100,0,10,"STAMuons");
01211     histos->fill1DHist(crudeLength,"trLength","Straight Line Length of STA Muon",120,0.,2400.,"STAMuons");
01212     histos->fill1DHist(deltaPhi,"trDeltaPhi","Delta-Phi Between Inner and Outer STA Muon Pos.",100,-0.5,0.5,"STAMuons");
01213     histos->fill1DHist(innerGlobalPolarAngle,"trInnerPolar","Polar Angle of Inner P Vector (STA muons)",128,0,3.2,"STAMuons");
01214     histos->fill1DHist(outerGlobalPolarAngle,"trOuterPolar","Polar Angle of Outer P Vector (STA muons)",128,0,3.2,"STAMuons");
01215     histos->fill1DHist(innerPnt.phi(),"trInnerPhi","Phi of Inner Position (STA muons)",256,-3.2,3.2,"STAMuons");
01216     histos->fill1DHist(outerPnt.phi(),"trOuterPhi","Phi of Outer Position (STA muons)",256,-3.2,3.2,"STAMuons");
01217 
01218   }
01219 
01220 }
01221 
01222 
01223 //--------------------------------------------------------------
01224 // Compute a serial number for the chamber.
01225 // This is useful when filling histograms and working with arrays.
01226 //--------------------------------------------------------------
01227 int CSCValidation::chamberSerial( CSCDetId id ) {
01228   int st = id.station();
01229   int ri = id.ring();
01230   int ch = id.chamber();
01231   int ec = id.endcap();
01232   int kSerial = ch;
01233   if (st == 1 && ri == 1) kSerial = ch;
01234   if (st == 1 && ri == 2) kSerial = ch + 36;
01235   if (st == 1 && ri == 3) kSerial = ch + 72;
01236   if (st == 1 && ri == 4) kSerial = ch;
01237   if (st == 2 && ri == 1) kSerial = ch + 108;
01238   if (st == 2 && ri == 2) kSerial = ch + 126;
01239   if (st == 3 && ri == 1) kSerial = ch + 162;
01240   if (st == 3 && ri == 2) kSerial = ch + 180;
01241   if (st == 4 && ri == 1) kSerial = ch + 216;
01242   if (st == 4 && ri == 2) kSerial = ch + 234;  // one day...
01243   if (ec == 2) kSerial = kSerial + 300;
01244   return kSerial;
01245 }
01246 
01247 //--------------------------------------------------------------
01248 // Compute a serial number for the ring.
01249 // This is useful when filling histograms and working with arrays.
01250 //--------------------------------------------------------------
01251 int CSCValidation::ringSerial( CSCDetId id ) {
01252   int st = id.station();
01253   int ri = id.ring();
01254   int ec = id.endcap();
01255   int kSerial = 0 ;
01256   if (st == 1 && ri == 1) kSerial = ri;
01257   if (st == 1 && ri == 2) kSerial = ri ;
01258   if (st == 1 && ri == 3) kSerial = ri ;
01259   if (st == 1 && ri == 4) kSerial = 1;
01260   if (st == 2 ) kSerial = ri + 3;
01261   if (st == 3 ) kSerial = ri + 5;
01262   if (st == 4 ) kSerial = ri + 7;
01263   if (ec == 2) kSerial = kSerial * (-1);
01264   return kSerial;
01265 }
01266 
01267 //-------------------------------------------------------------------------------------
01268 // Fits a straight line to a set of 5 points with errors.  Functions assumes 6 points
01269 // and removes hit in layer 3.  It then returns the expected position value in layer 3
01270 // based on the fit.
01271 //-------------------------------------------------------------------------------------
01272 float CSCValidation::fitX(CLHEP::HepMatrix points, CLHEP::HepMatrix errors){
01273 
01274   float S   = 0;
01275   float Sx  = 0;
01276   float Sy  = 0;
01277   float Sxx = 0;
01278   float Sxy = 0;
01279   float sigma2 = 0;
01280 
01281   for (int i=1;i<7;i++){
01282     if (i != 3){
01283       sigma2 = errors(i,1)*errors(i,1);
01284       S = S + (1/sigma2);
01285       Sy = Sy + (points(i,1)/sigma2);
01286       Sx = Sx + ((i)/sigma2);
01287       Sxx = Sxx + (i*i)/sigma2;
01288       Sxy = Sxy + (((i)*points(i,1))/sigma2);
01289     }
01290   }
01291 
01292   float delta = S*Sxx - Sx*Sx;
01293   float intercept = (Sxx*Sy - Sx*Sxy)/delta;
01294   float slope = (S*Sxy - Sx*Sy)/delta;
01295 
01296   //float chi = 0;
01297   //float chi2 = 0;
01298 
01299   // calculate chi2 (not currently used)
01300   //for (int i=1;i<7;i++){
01301   //  chi = (points(i,1) - intercept - slope*i)/(errors(i,1));
01302   //  chi2 = chi2 + chi*chi;
01303   //}
01304 
01305   return (intercept + slope*3);
01306 
01307 }
01308 
01309 
01310 //----------------------------------------------------------------------------
01311 // Calculate basic efficiencies for recHits and Segments
01312 // Author: S. Stoynev
01313 //----------------------------------------------------------------------------
01314 
01315 void CSCValidation::doEfficiencies(edm::Handle<CSCWireDigiCollection> wires, edm::Handle<CSCStripDigiCollection> strips,
01316                                    edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<CSCSegmentCollection> cscSegments,
01317                                    edm::ESHandle<CSCGeometry> cscGeom){
01318 
01319   bool allWires[2][4][4][36][6];
01320   bool allStrips[2][4][4][36][6];
01321   bool AllRecHits[2][4][4][36][6];
01322   bool AllSegments[2][4][4][36];
01323   
01324   //bool MultiSegments[2][4][4][36];
01325   for(int iE = 0;iE<2;iE++){
01326     for(int iS = 0;iS<4;iS++){
01327       for(int iR = 0; iR<4;iR++){
01328         for(int iC =0;iC<36;iC++){
01329           AllSegments[iE][iS][iR][iC] = false;
01330           //MultiSegments[iE][iS][iR][iC] = false;
01331           for(int iL=0;iL<6;iL++){
01332             allWires[iE][iS][iR][iC][iL] = false;
01333             allStrips[iE][iS][iR][iC][iL] = false;
01334             AllRecHits[iE][iS][iR][iC][iL] = false;
01335           }
01336         }
01337       }
01338     }
01339   }
01340   
01341   if (useDigis){
01342     // Wires
01343     for (CSCWireDigiCollection::DigiRangeIterator dWDiter=wires->begin(); dWDiter!=wires->end(); dWDiter++) {
01344       CSCDetId idrec = (CSCDetId)(*dWDiter).first;
01345       std::vector<CSCWireDigi>::const_iterator wireIter = (*dWDiter).second.first;
01346       std::vector<CSCWireDigi>::const_iterator lWire = (*dWDiter).second.second;
01347       for( ; wireIter != lWire; ++wireIter) {
01348         allWires[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber() -1][idrec.layer() -1] = true;
01349         break;
01350       }
01351     }
01352 
01353     //---- STRIPS
01354     for (CSCStripDigiCollection::DigiRangeIterator dSDiter=strips->begin(); dSDiter!=strips->end(); dSDiter++) {
01355       CSCDetId idrec = (CSCDetId)(*dSDiter).first;
01356       std::vector<CSCStripDigi>::const_iterator stripIter = (*dSDiter).second.first;
01357       std::vector<CSCStripDigi>::const_iterator lStrip = (*dSDiter).second.second;
01358       for( ; stripIter != lStrip; ++stripIter) {
01359         std::vector<int> myADCVals = stripIter->getADCCounts();
01360         bool thisStripFired = false;
01361         float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01362         float threshold = 13.3 ;
01363         float diff = 0.;
01364         for (unsigned int iCount = 0; iCount < myADCVals.size(); iCount++) {
01365           diff = (float)myADCVals[iCount]-thisPedestal;
01366           if (diff > threshold) {
01367             thisStripFired = true;
01368             break;
01369           }
01370         }
01371         if(thisStripFired){
01372           allStrips[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber() -1][idrec.layer() -1] = true;
01373           break;
01374         }
01375       }
01376     }
01377   }
01378 
01379   // Rechits
01380   for (CSCRecHit2DCollection::const_iterator recEffIt = recHits->begin(); recEffIt != recHits->end(); recEffIt++) {
01381     //CSCDetId idrec = (CSCDetId)(*recIt).cscDetId();
01382     CSCDetId  idrec = (CSCDetId)(*recEffIt).cscDetId();
01383     AllRecHits[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber() -1][idrec.layer() -1] = true;
01384 
01385   }
01386 
01387   std::vector <unsigned int> seg_ME2(2,0) ;
01388   std::vector <unsigned int> seg_ME3(2,0) ;
01389   std::vector < std::pair <CSCDetId, CSCSegment> > theSegments(4);
01390   // Segments
01391   for(CSCSegmentCollection::const_iterator segEffIt=cscSegments->begin(); segEffIt != cscSegments->end(); segEffIt++) {
01392     CSCDetId idseg  = (CSCDetId)(*segEffIt).cscDetId();
01393     //if(AllSegments[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber()]){
01394     //MultiSegments[idrec.endcap() -1][idrec.station() -1][idrec.ring() -1][idrec.chamber()] = true;
01395     //}
01396     AllSegments[idseg.endcap() -1][idseg.station() -1][idseg.ring() -1][idseg.chamber() -1] = true;
01397     // "Intrinsic" efficiency measurement relies on "good" segment extrapolation - we need the pre-selection below
01398     // station 2 "good" segment will be used for testing efficiencies in ME1 and ME3
01399     // station 3 "good" segment will be used for testing efficiencies in ME2 and ME4
01400     if(2==idseg.station() || 3==idseg.station()){
01401       unsigned int seg_tmp ; 
01402       if(2==idseg.station()){
01403         ++seg_ME2[idseg.endcap() -1];
01404         seg_tmp = seg_ME2[idseg.endcap() -1];
01405       }
01406       else{
01407         ++seg_ME3[idseg.endcap() -1];
01408         seg_tmp = seg_ME3[idseg.endcap() -1];
01409       }
01410       // is the segment good
01411       if(1== seg_tmp&& 6==(*segEffIt).nRecHits() && (*segEffIt).chi2()/(*segEffIt).degreesOfFreedom()<3.){
01412         std::pair <CSCDetId, CSCSegment> specSeg = make_pair( (CSCDetId)(*segEffIt).cscDetId(),*segEffIt);
01413         theSegments[2*(idseg.endcap()-1)+(idseg.station() -2)] = specSeg;
01414       }
01415     }
01416     /*
01417     if(2==idseg.station()){
01418         ++seg_ME2[idseg.endcap() -1];
01419        if(1==seg_ME2[idseg.endcap() -1] && 6==(*segEffIt).nRecHits() && (*segEffIt).chi2()/(*segEffIt).degreesOfFreedom()<3.){
01420            std::pair <CSCDetId, CSCSegment> specSeg = make_pair( (CSCDetId)(*segEffIt).cscDetId(),*segEffIt);
01421            theSegments[2*(idseg.endcap()-1)+(idseg.station() -2)] = specSeg;
01422        }
01423     }
01424     else if(3==idseg.station()){
01425         ++seg_ME3[idseg.endcap() -1];
01426         if(1==seg_ME3[idseg.endcap() -1] && 6==(*segEffIt).nRecHits() && (*segEffIt).chi2()/(*segEffIt).degreesOfFreedom()<3.){
01427          std::pair <CSCDetId, CSCSegment> specSeg = make_pair( (CSCDetId)(*segEffIt).cscDetId(),*segEffIt);
01428          theSegments[2*(idseg.endcap()-1)+(idseg.station() -2)] = specSeg;
01429        }
01430     }
01431     */
01432     
01433   }
01434   // Simple efficiency calculations
01435   for(int iE = 0;iE<2;iE++){
01436     for(int iS = 0;iS<4;iS++){
01437       for(int iR = 0; iR<4;iR++){
01438         for(int iC =0;iC<36;iC++){
01439           int NumberOfLayers = 0;
01440           for(int iL=0;iL<6;iL++){
01441             if(AllRecHits[iE][iS][iR][iC][iL]){
01442               NumberOfLayers++;
01443             }
01444           }
01445           int bin = 0;
01446           if (iS==0) bin = iR+1+(iE*10);
01447           else bin = (iS+1)*2 + (iR+1) + (iE*10);
01448           if(NumberOfLayers>1){
01449             //if(!(MultiSegments[iE][iS][iR][iC])){
01450             if(AllSegments[iE][iS][iR][iC]){
01451               //---- Efficient segment evenents
01452               hSSTE->AddBinContent(bin);
01453             }
01454             //---- All segment events (normalization)
01455             hSSTE->AddBinContent(20+bin);
01456             //}
01457           }
01458           if(AllSegments[iE][iS][iR][iC]){
01459             if(NumberOfLayers==6){
01460               //---- Efficient rechit events
01461               hRHSTE->AddBinContent(bin);;
01462             }
01463             //---- All rechit events (normalization)
01464             hRHSTE->AddBinContent(20+bin);;
01465           }
01466         }
01467       }
01468     }
01469   }
01470 
01471 // pick a segment only if there are no others in the station
01472   std::vector < std::pair <CSCDetId, CSCSegment> * > theSeg;
01473   if(1==seg_ME2[0]) theSeg.push_back(&theSegments[0]);
01474   if(1==seg_ME3[0]) theSeg.push_back(&theSegments[1]);
01475   if(1==seg_ME2[1]) theSeg.push_back(&theSegments[2]);
01476   if(1==seg_ME3[1]) theSeg.push_back(&theSegments[3]);
01477 
01478   // Needed for plots
01479   // at the end the chamber types will be numbered as 1 to 18 
01480   // (ME-4/1, -ME3/2, -ME3/1, ..., +ME3/1, +ME3/2, ME+4/1 ) 
01481   std::map <std::string, float> chamberTypes;
01482   chamberTypes["ME1/a"] = 0.5;
01483   chamberTypes["ME1/b"] = 1.5;
01484   chamberTypes["ME1/2"] = 2.5;
01485   chamberTypes["ME1/3"] = 3.5;
01486   chamberTypes["ME2/1"] = 4.5;
01487   chamberTypes["ME2/2"] = 5.5;
01488   chamberTypes["ME3/1"] = 6.5;
01489   chamberTypes["ME3/2"] = 7.5;
01490   chamberTypes["ME4/1"] = 8.5;
01491 
01492   if(theSeg.size()){
01493     std::map <int , GlobalPoint> extrapolatedPoint;
01494     std::map <int , GlobalPoint>::iterator it;
01495     const std::vector<CSCChamber*> ChamberContainer = cscGeom->chambers();
01496     // Pick which chamber with which segment to test
01497     for(size_t nCh=0;nCh<ChamberContainer.size();nCh++){
01498       const CSCChamber *cscchamber = ChamberContainer[nCh];
01499       std::pair <CSCDetId, CSCSegment> * thisSegment = 0;
01500       for(size_t iSeg =0;iSeg<theSeg.size();++iSeg ){
01501         if(cscchamber->id().endcap() == theSeg[iSeg]->first.endcap()){ 
01502           if(1==cscchamber->id().station() || 3==cscchamber->id().station() ){
01503             if(2==theSeg[iSeg]->first.station()){
01504               thisSegment = theSeg[iSeg];
01505             }
01506           }
01507           else if (2==cscchamber->id().station() || 4==cscchamber->id().station()){
01508             if(3==theSeg[iSeg]->first.station()){
01509               thisSegment = theSeg[iSeg];
01510             }
01511           }
01512         }
01513       }
01514       // this chamber is to be tested with thisSegment
01515       if(thisSegment){
01516         CSCSegment * seg = &(thisSegment->second);
01517         const CSCChamber *segChamber = cscGeom->chamber(thisSegment->first);
01518         LocalPoint localCenter(0.,0.,0);
01519         GlobalPoint cscchamberCenter =  cscchamber->toGlobal(localCenter);
01520         // try to save some time (extrapolate a segment to a certain position only once)
01521         it = extrapolatedPoint.find(int(cscchamberCenter.z()));
01522         if(it==extrapolatedPoint.end()){
01523           GlobalPoint segPos = segChamber->toGlobal(seg->localPosition());
01524           GlobalVector segDir = segChamber->toGlobal(seg->localDirection());
01525           double paramaterLine = lineParametrization(segPos.z(),cscchamberCenter.z() , segDir.z());
01526           double xExtrapolated = extrapolate1D(segPos.x(),segDir.x(), paramaterLine);
01527           double yExtrapolated = extrapolate1D(segPos.y(),segDir.y(), paramaterLine);
01528           GlobalPoint globP (xExtrapolated, yExtrapolated, cscchamberCenter.z());
01529           extrapolatedPoint[int(cscchamberCenter.z())] = globP;
01530         }
01531         // Where does the extrapolated point lie in the (tested) chamber local frame? Here: 
01532         LocalPoint extrapolatedPointLocal = cscchamber->toLocal(extrapolatedPoint[int(cscchamberCenter.z())]);
01533         const CSCLayer *layer_p = cscchamber->layer(1);//layer 1
01534         const CSCLayerGeometry *layerGeom = layer_p->geometry ();
01535         const std::vector<float> layerBounds = layerGeom->parameters ();
01536         float shiftFromEdge = 15.;//cm
01537         float shiftFromDeadZone = 10.;
01538         // is the extrapolated point within a sensitive region
01539         bool pass = withinSensitiveRegion(extrapolatedPointLocal, layerBounds, 
01540                                           cscchamber->id().station(), cscchamber->id().ring(), 
01541                                           shiftFromEdge, shiftFromDeadZone);
01542         if(pass){// the extrapolation point of the segment lies within sensitive region of that chamber
01543           // how many rechit layers are there in the chamber?
01544           // 0 - maybe the muon died or is deflected at large angle? do not use that case
01545           // 1 - could be noise...
01546           // 2 or more - this is promissing; this is our definition of a reliable signal; use it below
01547           // is other definition better? 
01548           int nRHLayers = 0;
01549           for(int iL =0;iL<6;++iL){
01550             if(AllRecHits[cscchamber->id().endcap()-1]
01551                [cscchamber->id().station()-1]
01552                [cscchamber->id().ring()-1][cscchamber->id().chamber()-1][iL]){
01553               ++nRHLayers;
01554             }
01555           }
01556           //std::cout<<" nRHLayers = "<<nRHLayers<<std::endl;
01557           float verticalScale = chamberTypes[cscchamber->specs()->chamberTypeName()];
01558           if(cscchamberCenter.z()<0){
01559             verticalScale = - verticalScale;
01560           } 
01561           verticalScale +=9.5;
01562           hSensitiveAreaEvt->Fill(float(cscchamber->id().chamber()),verticalScale);
01563           if(nRHLayers>1){// this chamber contains a reliable signal
01564             //chamberTypes[cscchamber->specs()->chamberTypeName()];
01565             // "intrinsic" efficiencies
01566             //std::cout<<" verticalScale = "<<verticalScale<<" chType = "<<cscchamber->specs()->chamberTypeName()<<std::endl;
01567             // this is the denominator forr all efficiencies
01568             hEffDenominator->Fill(float(cscchamber->id().chamber()),verticalScale);
01569             // Segment efficiency
01570             if(AllSegments[cscchamber->id().endcap()-1]
01571                [cscchamber->id().station()-1]
01572                [cscchamber->id().ring()-1][cscchamber->id().chamber()-1]){
01573               hSSTE2->Fill(float(cscchamber->id().chamber()),float(verticalScale));
01574             }
01575           
01576             for(int iL =0;iL<6;++iL){
01577               float weight = 1./6.;
01578               // one shold account for the weight in the efficiency...
01579               // Rechit efficiency
01580               if(AllRecHits[cscchamber->id().endcap()-1]
01581                  [cscchamber->id().station()-1]
01582                  [cscchamber->id().ring()-1][cscchamber->id().chamber()-1][iL]){
01583                 hRHSTE2->Fill(float(cscchamber->id().chamber()),float(verticalScale),weight);
01584               }
01585               if (useDigis){
01586                 // Wire efficiency
01587                 if(allWires[cscchamber->id().endcap()-1]
01588                   [cscchamber->id().station()-1]
01589                   [cscchamber->id().ring()-1][cscchamber->id().chamber()-1][iL]){
01590                   // one shold account for the weight in the efficiency...
01591                   hWireSTE2->Fill(float(cscchamber->id().chamber()),float(verticalScale),weight);
01592                 }
01593                 // Strip efficiency
01594                 if(allStrips[cscchamber->id().endcap()-1]
01595                   [cscchamber->id().station()-1]
01596                   [cscchamber->id().ring()-1][cscchamber->id().chamber()-1][iL]){
01597                   // one shold account for the weight in the efficiency...
01598                   hStripSTE2->Fill(float(cscchamber->id().chamber()),float(verticalScale),weight);
01599                 }
01600               }
01601             }
01602           }
01603         }
01604       }
01605     }
01606   }
01607   //
01608   
01609   
01610 }
01611 
01612 void CSCValidation::getEfficiency(float bin, float Norm, std::vector<float> &eff){
01613   //---- Efficiency with binomial error
01614   float Efficiency = 0.;
01615   float EffError = 0.;
01616   if(fabs(Norm)>0.000000001){
01617     Efficiency = bin/Norm;
01618     if(bin<Norm){
01619       EffError = sqrt( (1.-Efficiency)*Efficiency/Norm );
01620     }
01621   }
01622   eff[0] = Efficiency;
01623   eff[1] = EffError;
01624 }
01625 
01626 void CSCValidation::histoEfficiency(TH1F *readHisto, TH1F *writeHisto){
01627   std::vector<float> eff(2);
01628   int Nbins =  readHisto->GetSize()-2;//without underflows and overflows
01629   std::vector<float> bins(Nbins);
01630   std::vector<float> Efficiency(Nbins);
01631   std::vector<float> EffError(Nbins);
01632   float Num = 1;
01633   float Den = 1;
01634   for (int i=0;i<20;i++){
01635     Num = readHisto->GetBinContent(i+1);
01636     Den = readHisto->GetBinContent(i+21);
01637     getEfficiency(Num, Den, eff);
01638     Efficiency[i] = eff[0];
01639     EffError[i] = eff[1];
01640     writeHisto->SetBinContent(i+1, Efficiency[i]);
01641     writeHisto->SetBinError(i+1, EffError[i]);
01642   }
01643 }
01644 
01645 bool CSCValidation::withinSensitiveRegion(LocalPoint localPos, const std::vector<float> layerBounds, int station, int ring, float shiftFromEdge, float shiftFromDeadZone){
01646 //---- check if it is in a good local region (sensitive area - geometrical and HV boundaries excluded) 
01647   bool pass = false;
01648 
01649   float y_center = 0.;
01650   double yUp = layerBounds[3] + y_center;
01651   double yDown = - layerBounds[3] + y_center;
01652   double xBound1Shifted = layerBounds[0] - shiftFromEdge;//
01653   double xBound2Shifted = layerBounds[1] - shiftFromEdge;//
01654   double lineSlope = (yUp - yDown)/(xBound2Shifted-xBound1Shifted);
01655   double lineConst = yUp - lineSlope*xBound2Shifted;
01656   double yBorder =  lineSlope*abs(localPos.x()) + lineConst;
01657       
01658   //bool withinChamberOnly = false;// false = "good region"; true - boundaries only
01659   std::vector <float> deadZoneCenter(6);
01660   float cutZone = shiftFromDeadZone;//cm
01661   //---- hardcoded... not good
01662   if(station>1 && station<5){
01663     if(2==ring){
01664       deadZoneCenter[0]= -162.48 ;
01665       deadZoneCenter[1] = -81.8744;
01666       deadZoneCenter[2] = -21.18165;
01667       deadZoneCenter[3] = 39.51105;
01668       deadZoneCenter[4] = 100.2939;
01669       deadZoneCenter[5] = 160.58;
01670       
01671       if(localPos.y() >yBorder &&
01672          ((localPos.y()> deadZoneCenter[0] + cutZone && localPos.y()< deadZoneCenter[1] - cutZone) ||
01673           (localPos.y()> deadZoneCenter[1] + cutZone && localPos.y()< deadZoneCenter[2] - cutZone) ||
01674           (localPos.y()> deadZoneCenter[2] + cutZone && localPos.y()< deadZoneCenter[3] - cutZone) ||
01675           (localPos.y()> deadZoneCenter[3] + cutZone && localPos.y()< deadZoneCenter[4] - cutZone) ||
01676           (localPos.y()> deadZoneCenter[4] + cutZone && localPos.y()< deadZoneCenter[5] - cutZone))){
01677         pass = true;
01678       }
01679     }
01680     else if(1==ring){
01681       if(2==station){
01682         deadZoneCenter[0]= -95.80 ;
01683         deadZoneCenter[1] = -27.47;
01684         deadZoneCenter[2] = 33.67;
01685         deadZoneCenter[3] = 90.85;
01686         }
01687       else if(3==station){
01688         deadZoneCenter[0]= -89.305 ;
01689         deadZoneCenter[1] = -39.705;
01690         deadZoneCenter[2] = 20.195;
01691         deadZoneCenter[3] = 77.395;
01692       }
01693       else if(4==station){
01694         deadZoneCenter[0]= -75.645;
01695         deadZoneCenter[1] = -26.055;
01696         deadZoneCenter[2] = 23.855;
01697         deadZoneCenter[3] = 70.575;
01698       }
01699       if(localPos.y() >yBorder &&
01700          ((localPos.y()> deadZoneCenter[0] + cutZone && localPos.y()< deadZoneCenter[1] - cutZone) ||
01701           (localPos.y()> deadZoneCenter[1] + cutZone && localPos.y()< deadZoneCenter[2] - cutZone) ||
01702           (localPos.y()> deadZoneCenter[2] + cutZone && localPos.y()< deadZoneCenter[3] - cutZone))){
01703         pass = true;
01704       }
01705     }
01706   }
01707   else if(1==station){
01708     if(3==ring){
01709       deadZoneCenter[0]= -83.155 ;
01710       deadZoneCenter[1] = -22.7401;
01711       deadZoneCenter[2] = 27.86665;
01712       deadZoneCenter[3] = 81.005;
01713       if(localPos.y() > yBorder &&
01714          ((localPos.y()> deadZoneCenter[0] + cutZone && localPos.y()< deadZoneCenter[1] - cutZone) ||
01715           (localPos.y()> deadZoneCenter[1] + cutZone && localPos.y()< deadZoneCenter[2] - cutZone) ||
01716           (localPos.y()> deadZoneCenter[2] + cutZone && localPos.y()< deadZoneCenter[3] - cutZone))){
01717         pass = true;
01718       }
01719     }
01720     else if(2==ring){
01721       deadZoneCenter[0]= -86.285 ;
01722       deadZoneCenter[1] = -32.88305;
01723       deadZoneCenter[2] = 32.867423;
01724       deadZoneCenter[3] = 88.205;
01725       if(localPos.y() > (yBorder) &&
01726          ((localPos.y()> deadZoneCenter[0] + cutZone && localPos.y()< deadZoneCenter[1] - cutZone) ||
01727           (localPos.y()> deadZoneCenter[1] + cutZone && localPos.y()< deadZoneCenter[2] - cutZone) ||
01728           (localPos.y()> deadZoneCenter[2] + cutZone && localPos.y()< deadZoneCenter[3] - cutZone))){
01729         pass = true;
01730       }
01731     }
01732     else{
01733       deadZoneCenter[0]= -81.0;
01734       deadZoneCenter[1] = 81.0;
01735       if(localPos.y() > (yBorder) &&
01736          (localPos.y()> deadZoneCenter[0] + cutZone && localPos.y()< deadZoneCenter[1] - cutZone )){
01737         pass = true;
01738       }
01739     }
01740   }
01741   return pass;
01742 }
01743 
01744 
01745 
01746 //---------------------------------------------------------------------------------------
01747 // Given a set of digis, the CSCDetId, and the central strip of your choosing, returns
01748 // the avg. Signal-Pedestal for 6 time bin x 5 strip .
01749 //
01750 // Author: P. Jindal
01751 //---------------------------------------------------------------------------------------
01752 
01753 float CSCValidation::getSignal(const CSCStripDigiCollection& stripdigis, CSCDetId idCS, int centerStrip){
01754 
01755   float SigADC[5];
01756   float TotalADC = 0;
01757   SigADC[0] = 0;
01758   SigADC[1] = 0;
01759   SigADC[2] = 0;
01760   SigADC[3] = 0;
01761   SigADC[4] = 0;
01762 
01763  
01764   // Loop over strip digis 
01765   CSCStripDigiCollection::DigiRangeIterator sIt;
01766   
01767   for (sIt = stripdigis.begin(); sIt != stripdigis.end(); sIt++){
01768     CSCDetId id = (CSCDetId)(*sIt).first;
01769     if (id == idCS){
01770 
01771       // First, find the Signal-Pedestal for center strip
01772       std::vector<CSCStripDigi>::const_iterator digiItr = (*sIt).second.first;
01773       std::vector<CSCStripDigi>::const_iterator last = (*sIt).second.second;
01774       for ( ; digiItr != last; ++digiItr ) {
01775         int thisStrip = digiItr->getStrip();
01776         if (thisStrip == (centerStrip)){
01777           std::vector<int> myADCVals = digiItr->getADCCounts();
01778           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01779           float thisSignal = (myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
01780           SigADC[0] = thisSignal - 6*thisPedestal;
01781         }
01782      // Now,find the Signal-Pedestal for neighbouring 4 strips
01783         if (thisStrip == (centerStrip+1)){
01784           std::vector<int> myADCVals = digiItr->getADCCounts();
01785           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01786           float thisSignal = (myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
01787           SigADC[1] = thisSignal - 6*thisPedestal;
01788         }
01789         if (thisStrip == (centerStrip+2)){
01790           std::vector<int> myADCVals = digiItr->getADCCounts();
01791           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01792           float thisSignal = (myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
01793           SigADC[2] = thisSignal - 6*thisPedestal;
01794         }
01795         if (thisStrip == (centerStrip-1)){
01796           std::vector<int> myADCVals = digiItr->getADCCounts();
01797           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01798           float thisSignal = (myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
01799           SigADC[3] = thisSignal - 6*thisPedestal;
01800         }
01801         if (thisStrip == (centerStrip-2)){
01802           std::vector<int> myADCVals = digiItr->getADCCounts();
01803           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
01804           float thisSignal = (myADCVals[2]+myADCVals[3]+myADCVals[4]+myADCVals[5]+myADCVals[6]+myADCVals[7]);
01805           SigADC[4] = thisSignal - 6*thisPedestal;
01806         }
01807       }
01808       TotalADC = 0.2*(SigADC[0]+SigADC[1]+SigADC[2]+SigADC[3]+SigADC[4]);
01809     }
01810   }
01811   return TotalADC;
01812 }
01813 
01814 //---------------------------------------------------------------------------------------
01815 // Look at non-associated recHits
01816 // Author: P. Jindal
01817 //---------------------------------------------------------------------------------------
01818 
01819 void CSCValidation::doNoiseHits(edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<CSCSegmentCollection> cscSegments,
01820                                 edm::ESHandle<CSCGeometry> cscGeom,  edm::Handle<CSCStripDigiCollection> strips){
01821 
01822   CSCRecHit2DCollection::const_iterator recIt;
01823   for (recIt = recHits->begin(); recIt != recHits->end(); recIt++) {
01824 
01825     CSCDetId idrec = (CSCDetId)(*recIt).cscDetId();
01826 
01827     //Store the Rechits into a Map
01828     AllRechits.insert(std::pair<CSCDetId , CSCRecHit2D>(idrec,*recIt));
01829 
01830     // Find the strip containing this hit
01831     int centerid     =  recIt->nStrips()/2;
01832     int centerStrip =  recIt->channels(centerid);
01833 
01834     float  rHsignal = getthisSignal(*strips, idrec, centerStrip);
01835     histos->fill1DHist(rHsignal,"hrHSignal", "Signal in the 4th time bin for centre strip",1100,-99,1000,"recHits");
01836 
01837   }
01838 
01839   for(CSCSegmentCollection::const_iterator it=cscSegments->begin(); it != cscSegments->end(); it++) {
01840 
01841     std::vector<CSCRecHit2D> theseRecHits = (*it).specificRecHits();
01842     for ( std::vector<CSCRecHit2D>::const_iterator iRH = theseRecHits.begin(); iRH != theseRecHits.end(); iRH++) {
01843       CSCDetId idRH = (CSCDetId)(*iRH).cscDetId();
01844       LocalPoint lpRH = (*iRH).localPosition();
01845       float xrec = lpRH.x();
01846       float yrec = lpRH.y();
01847       float zrec = lpRH.z();
01848       bool RHalreadyinMap = false;
01849       //Store the rechits associated with segments into a Map
01850       multimap<CSCDetId , CSCRecHit2D>::iterator segRHit;
01851       segRHit = SegRechits.find(idRH);
01852       if (segRHit != SegRechits.end()){
01853         for( ; segRHit != SegRechits.upper_bound(idRH); ++segRHit){
01854           //for( segRHit = SegRechits.begin(); segRHit != SegRechits.end() ;++segRHit){
01855           LocalPoint lposRH = (segRHit->second).localPosition();
01856           float xpos = lposRH.x();
01857           float ypos = lposRH.y();
01858           float zpos = lposRH.z();
01859           if ( xrec == xpos && yrec == ypos && zrec == zpos){
01860           RHalreadyinMap = true;
01861           //std::cout << " Already exists " <<std ::endl;
01862           break;}
01863         }
01864       }
01865       if(!RHalreadyinMap){ SegRechits.insert(std::pair<CSCDetId , CSCRecHit2D>(idRH,*iRH));}
01866     }
01867   }
01868 
01869   findNonAssociatedRecHits(cscGeom,strips);
01870 
01871 }
01872 
01873 //---------------------------------------------------------------------------------------
01874 // Given  the list of all rechits and the rechits on a segment finds the rechits 
01875 // not associated to a segment and stores in a list
01876 //
01877 //---------------------------------------------------------------------------------------
01878 
01879 void CSCValidation::findNonAssociatedRecHits(edm::ESHandle<CSCGeometry> cscGeom,  edm::Handle<CSCStripDigiCollection> strips){
01880  
01881   for(std::multimap<CSCDetId , CSCRecHit2D>::iterator allRHiter =  AllRechits.begin();allRHiter != AllRechits.end(); ++allRHiter){
01882         CSCDetId idRH = allRHiter->first;
01883     LocalPoint lpRH = (allRHiter->second).localPosition();
01884     float xrec = lpRH.x();
01885     float yrec = lpRH.y();
01886     float zrec = lpRH.z();
01887     
01888     bool foundmatch = false;
01889     multimap<CSCDetId , CSCRecHit2D>::iterator segRHit;
01890     segRHit = SegRechits.find(idRH);
01891     if (segRHit != SegRechits.end()){
01892                 for( ; segRHit != SegRechits.upper_bound(idRH); ++segRHit){
01893                         
01894                         LocalPoint lposRH = (segRHit->second).localPosition();
01895                         float xpos = lposRH.x();
01896                         float ypos = lposRH.y();
01897                         float zpos = lposRH.z();
01898 
01899                         if ( xrec == xpos && yrec == ypos && zrec == zpos){
01900                                 foundmatch = true;}
01901           
01902                         float d      = 0.;
01903                         float dclose =1000.;
01904 
01905                         if ( !foundmatch) {
01906                                 
01907                                 d = sqrt(pow(xrec-xpos,2)+pow(yrec-ypos,2)+pow(zrec-zpos,2));
01908                                 if (d < dclose) {
01909                                         dclose = d;
01910                                         if( distRHmap.find((allRHiter->second)) ==  distRHmap.end() ) { // entry for rechit does not yet exist, create one
01911                                                 distRHmap.insert(make_pair(allRHiter->second,dclose) );
01912                                         }
01913                                         else {
01914                                                 // we already have an entry for the detid.
01915                                                 distRHmap.erase(allRHiter->second);
01916                                                 distRHmap.insert(make_pair(allRHiter->second,dclose)); // fill rechits for the segment with the given detid
01917                                         }
01918                                 }
01919                         }           
01920                 }
01921     }
01922     if(!foundmatch){NonAssociatedRechits.insert(std::pair<CSCDetId , CSCRecHit2D>(idRH,allRHiter->second));}
01923   }
01924 
01925   for(std::map<CSCRecHit2D,float,ltrh>::iterator iter =  distRHmap.begin();iter != distRHmap.end(); ++iter){
01926     histos->fill1DHist(iter->second,"hdistRH","Distance of Non Associated RecHit from closest Segment RecHit",500,0.,100.,"NonAssociatedRechits");
01927   }
01928 
01929   for(std::multimap<CSCDetId , CSCRecHit2D>::iterator iter =  NonAssociatedRechits.begin();iter != NonAssociatedRechits.end(); ++iter){
01930     CSCDetId idrec = iter->first;
01931     int kEndcap  = idrec.endcap();
01932     int cEndcap  = idrec.endcap();
01933     if (kEndcap == 2)cEndcap = -1;
01934     int kRing    = idrec.ring();
01935     int kStation = idrec.station();
01936     int kChamber = idrec.chamber();
01937     int kLayer   = idrec.layer();
01938 
01939     // Store rechit as a Local Point:
01940     LocalPoint rhitlocal = (iter->second).localPosition();  
01941     float xreco = rhitlocal.x();
01942     float yreco = rhitlocal.y();
01943 
01944     // Find the strip containing this hit
01945     int centerid    =  (iter->second).nStrips()/2;
01946     int centerStrip =  (iter->second).channels(centerid);
01947 
01948     // Find the charge associated with this hit
01949     float rHSumQ = 0;
01950     float sumsides=0.;
01951     int adcsize=(iter->second).nStrips()*(iter->second).nTimeBins();
01952     for ( unsigned int i=0; i< (iter->second).nStrips(); i++) {
01953       for ( unsigned int j=0; j< (iter->second).nTimeBins()-1; j++) {
01954         rHSumQ+=(iter->second).adcs(i,j);
01955         if (i!=1) sumsides+=(iter->second).adcs(i,j);
01956       }
01957     }
01958 
01959     float rHratioQ = sumsides/rHSumQ;
01960     if (adcsize != 12) rHratioQ = -99;
01961 
01962     // Get the signal timing of this hit
01963     float rHtime = (iter->second).tpeak()/50;
01964 
01965     // Get the width of this hit
01966     int rHwidth = getWidth(*strips, idrec, centerStrip);
01967 
01968 
01969     // Get pointer to the layer:
01970     const CSCLayer* csclayer = cscGeom->layer( idrec );
01971 
01972     // Transform hit position from local chamber geometry to global CMS geom
01973     GlobalPoint rhitglobal= csclayer->toGlobal(rhitlocal);
01974     float grecx   =  rhitglobal.x();
01975     float grecy   =  rhitglobal.y();
01976 
01977 
01978 
01979    // Simple occupancy variables
01980     int kCodeBroad  = cEndcap * ( 4*(kStation-1) + kRing) ;
01981     int kCodeNarrow = cEndcap * ( 100*(kRing-1) + kChamber) ;
01982 
01983     //Fill the non-associated rechits parameters in histogram
01984     histos->fill1DHist(kCodeBroad,"hNARHCodeBroad","broad scope code for recHits",33,-16.5,16.5,"NonAssociatedRechits");
01985     if (kStation == 1) histos->fill1DHist(kCodeNarrow,"hNARHCodeNarrow1","narrow scope recHit code station 1",801,-400.5,400.5,"NonAssociatedRechits");
01986     if (kStation == 2) histos->fill1DHist(kCodeNarrow,"hNARHCodeNarrow2","narrow scope recHit code station 2",801,-400.5,400.5,"NonAssociatedRechits");
01987     if (kStation == 3) histos->fill1DHist(kCodeNarrow,"hNARHCodeNarrow3","narrow scope recHit code station 3",801,-400.5,400.5,"NonAssociatedRechits");
01988     if (kStation == 4) histos->fill1DHist(kCodeNarrow,"hNARHCodeNarrow4","narrow scope recHit code station 4",801,-400.5,400.5,"NonAssociatedRechits");
01989     histos->fill1DHistByType(kLayer,"hNARHLayer","RecHits per Layer",idrec,8,-0.5,7.5,"NonAssociatedRechits");
01990     histos->fill1DHistByType(xreco,"hNARHX","Local X of recHit",idrec,160,-80.,80.,"NonAssociatedRechits");
01991     histos->fill1DHistByType(yreco,"hNARHY","Local Y of recHit",idrec,60,-180.,180.,"NonAssociatedRechits");
01992     if (kStation == 1 && (kRing == 1 || kRing == 4)) histos->fill1DHistByType(rHSumQ,"hNARHSumQ","Sum 3x3 recHit Charge",idrec,250,0,4000,"NonAssociatedRechits");
01993     else histos->fill1DHistByType(rHSumQ,"hNARHSumQ","Sum 3x3 recHit Charge",idrec,250,0,2000,"NonAssociatedRechits");
01994     histos->fill1DHistByType(rHratioQ,"hNARHRatioQ","Ratio (Ql+Qr)/Qt)",idrec,120,-0.1,1.1,"NonAssociatedRechits");
01995     histos->fill1DHistByType(rHtime,"hNARHTiming","recHit Timing",idrec,200,-10,10,"NonAssociatedRechits");
01996     histos->fill2DHistByStation(grecx,grecy,"hNARHGlobal","recHit Global Position",idrec,400,-800.,800.,400,-800.,800.,"NonAssociatedRechits");
01997     histos->fill1DHistByType(rHwidth,"hNARHwidth","width for Non associated recHit",idrec,21,-0.5,20.5,"NonAssociatedRechits");
01998     
01999   }
02000 
02001    for(std::multimap<CSCDetId , CSCRecHit2D>::iterator iter =  SegRechits.begin();iter != SegRechits.end(); ++iter){
02002            CSCDetId idrec = iter->first;
02003            int kEndcap  = idrec.endcap();
02004            int cEndcap  = idrec.endcap();
02005            if (kEndcap == 2)cEndcap = -1;
02006            int kRing    = idrec.ring();
02007            int kStation = idrec.station();
02008            int kChamber = idrec.chamber();
02009            int kLayer   = idrec.layer();
02010 
02011            // Store rechit as a Local Point:
02012            LocalPoint rhitlocal = (iter->second).localPosition();  
02013            float xreco = rhitlocal.x();
02014            float yreco = rhitlocal.y();
02015 
02016            // Find the strip containing this hit
02017            int centerid    =  (iter->second).nStrips()/2;
02018            int centerStrip =  (iter->second).channels(centerid);
02019 
02020            // Find the charge associated with this hit
02021 
02022            float rHSumQ = 0;
02023            float sumsides=0.;
02024            int adcsize=(iter->second).nStrips()*(iter->second).nTimeBins();
02025            for ( unsigned int i=0; i< (iter->second).nStrips(); i++) {
02026              for ( unsigned int j=0; j< (iter->second).nTimeBins()-1; j++) {
02027                rHSumQ+=(iter->second).adcs(i,j);
02028                if (i!=1) sumsides+=(iter->second).adcs(i,j);
02029              }
02030            }
02031            
02032            float rHratioQ = sumsides/rHSumQ;
02033            if (adcsize != 12) rHratioQ = -99;
02034            
02035            // Get the signal timing of this hit
02036            float rHtime = (iter->second).tpeak()/50;
02037 
02038            // Get the width of this hit
02039            int rHwidth = getWidth(*strips, idrec, centerStrip);
02040 
02041 
02042            // Get pointer to the layer:
02043            const CSCLayer* csclayer = cscGeom->layer( idrec );
02044            
02045            // Transform hit position from local chamber geometry to global CMS geom
02046            GlobalPoint rhitglobal= csclayer->toGlobal(rhitlocal);
02047            float grecx   =  rhitglobal.x();
02048            float grecy   =  rhitglobal.y();
02049 
02050            // Simple occupancy variables
02051            int kCodeBroad  = cEndcap * ( 4*(kStation-1) + kRing) ;
02052            int kCodeNarrow = cEndcap * ( 100*(kRing-1) + kChamber) ;
02053 
02054            //Fill the non-associated rechits global position in histogram
02055            histos->fill1DHist(kCodeBroad,"hSegRHCodeBroad","broad scope code for recHits",33,-16.5,16.5,"AssociatedRechits");
02056            if (kStation == 1) histos->fill1DHist(kCodeNarrow,"hSegRHCodeNarrow1","narrow scope recHit code station 1",801,-400.5,400.5,"AssociatedRechits");
02057            if (kStation == 2) histos->fill1DHist(kCodeNarrow,"hSegRHCodeNarrow2","narrow scope recHit code station 2",801,-400.5,400.5,"AssociatedRechits");
02058            if (kStation == 3) histos->fill1DHist(kCodeNarrow,"hSegRHCodeNarrow3","narrow scope recHit code station 3",801,-400.5,400.5,"AssociatedRechits");
02059            if (kStation == 4) histos->fill1DHist(kCodeNarrow,"hSegRHCodeNarrow4","narrow scope recHit code station 4",801,-400.5,400.5,"AssociatedRechits");
02060            histos->fill1DHistByType(kLayer,"hSegRHLayer","RecHits per Layer",idrec,8,-0.5,7.5,"AssociatedRechits");
02061            histos->fill1DHistByType(xreco,"hSegRHX","Local X of recHit",idrec,160,-80.,80.,"AssociatedRechits");
02062            histos->fill1DHistByType(yreco,"hSegRHY","Local Y of recHit",idrec,60,-180.,180.,"AssociatedRechits");
02063            if (kStation == 1 && (kRing == 1 || kRing == 4)) histos->fill1DHistByType(rHSumQ,"hSegRHSumQ","Sum 3x3 recHit Charge",idrec,250,0,4000,"AssociatedRechits");
02064            else histos->fill1DHistByType(rHSumQ,"hSegRHSumQ","Sum 3x3 recHit Charge",idrec,250,0,2000,"AssociatedRechits");
02065            histos->fill1DHistByType(rHratioQ,"hSegRHRatioQ","Ratio (Ql+Qr)/Qt)",idrec,120,-0.1,1.1,"AssociatedRechits");
02066            histos->fill1DHistByType(rHtime,"hSegRHTiming","recHit Timing",idrec,200,-10,10,"AssociatedRechits");
02067            histos->fill2DHistByStation(grecx,grecy,"hSegRHGlobal","recHit Global Position",idrec,400,-800.,800.,400,-800.,800.,"AssociatedRechits");
02068            histos->fill1DHistByType(rHwidth,"hSegRHwidth","width for Non associated recHit",idrec,21,-0.5,20.5,"AssociatedRechits");
02069            
02070    }
02071 
02072    distRHmap.clear();
02073    AllRechits.clear();
02074    SegRechits.clear();
02075    NonAssociatedRechits.clear();
02076 }
02077 
02078 
02079 
02080 float CSCValidation::getthisSignal(const CSCStripDigiCollection& stripdigis, CSCDetId idRH, int centerStrip){
02081         // Loop over strip digis responsible for this recHit
02082         CSCStripDigiCollection::DigiRangeIterator sIt;
02083         float thisADC = 0.;
02084         //bool foundRHid = false;
02085         // std::cout<<"iD   S/R/C/L = "<<idRH<<"    "<<idRH.station()<<"/"<<idRH.ring()<<"/"<<idRH.chamber()<<"/"<<idRH.layer()<<std::endl;
02086         for (sIt = stripdigis.begin(); sIt != stripdigis.end(); sIt++){
02087                 CSCDetId id = (CSCDetId)(*sIt).first;
02088                 //std::cout<<"STRIPS: id    S/R/C/L = "<<id<<"     "<<id.station()<<"/"<<id.ring()<<"/"<<id.chamber()<<"/"<<id.layer()<<std::endl;
02089                 if (id == idRH){
02090                         //foundRHid = true;
02091                         vector<CSCStripDigi>::const_iterator digiItr = (*sIt).second.first;
02092                         vector<CSCStripDigi>::const_iterator last = (*sIt).second.second;
02093                         //if(digiItr == last ) {std::cout << " Attention1 :: Size of digi collection is zero " << std::endl;}
02094                         int St = idRH.station();
02095                         int Rg    = idRH.ring();
02096                         if (St == 1 && Rg == 4){
02097                                 while(centerStrip> 16) centerStrip -= 16;
02098                         }
02099                         for ( ; digiItr != last; ++digiItr ) {
02100                                 int thisStrip = digiItr->getStrip();
02101                                 //std::cout<<" thisStrip = "<<thisStrip<<" centerStrip = "<<centerStrip<<std::endl;
02102                                 std::vector<int> myADCVals = digiItr->getADCCounts();
02103                                 float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
02104                                 float Signal = (float) myADCVals[3];
02105                                 if (thisStrip == (centerStrip)){
02106                                         thisADC = Signal-thisPedestal;
02107                                         //if(thisADC >= 0. && thisADC <2.) {std::cout << " Attention2 :: The Signal is equal to the pedestal " << std::endl;
02108                                         //}
02109                                         //if(thisADC < 0.) {std::cout << " Attention3 :: The Signal is less than the pedestal " << std::endl;
02110                                         //}
02111                                 }
02112                                 if (thisStrip == (centerStrip+1)){
02113                                         std::vector<int> myADCVals = digiItr->getADCCounts();
02114                                 }
02115                                 if (thisStrip == (centerStrip-1)){
02116                                         std::vector<int> myADCVals = digiItr->getADCCounts();
02117                                 }
02118                         }
02119                 }
02120         }
02121         //if(!foundRHid){std::cout << " Attention4 :: Did not find a matching RH id in the Strip Digi collection " << std::endl;}
02122         return thisADC;
02123 }
02124 
02125 //---------------------------------------------------------------------------------------
02126 //
02127 // Function is meant to take the DetId and center strip number of a recHit and return
02128 // the width in terms of strips
02129 //---------------------------------------------------------------------------------------
02130 
02131 int CSCValidation::getWidth(const CSCStripDigiCollection& stripdigis, CSCDetId idRH, int centerStrip){
02132 
02133   int width = 1;
02134   int widthpos = 0;
02135   int widthneg = 0;
02136 
02137   // Loop over strip digis responsible for this recHit and sum charge
02138   CSCStripDigiCollection::DigiRangeIterator sIt;
02139 
02140   for (sIt = stripdigis.begin(); sIt != stripdigis.end(); sIt++){
02141           CSCDetId id = (CSCDetId)(*sIt).first;
02142           if (id == idRH){
02143                   std::vector<CSCStripDigi>::const_iterator digiItr = (*sIt).second.first;
02144                   std::vector<CSCStripDigi>::const_iterator first = (*sIt).second.first;
02145                   std::vector<CSCStripDigi>::const_iterator last = (*sIt).second.second;
02146                   std::vector<CSCStripDigi>::const_iterator it = (*sIt).second.first;
02147                   std::vector<CSCStripDigi>::const_iterator itr = (*sIt).second.first;
02148                   //std::cout << " IDRH " << id <<std::endl;
02149                   int St = idRH.station();
02150                   int Rg    = idRH.ring();
02151                   if (St == 1 && Rg == 4){
02152                           while(centerStrip> 16) centerStrip -= 16;
02153                   }
02154                   for ( ; digiItr != last; ++digiItr ) {
02155                           int thisStrip = digiItr->getStrip();
02156                           if (thisStrip == (centerStrip)){
02157                                   it = digiItr;
02158                                   for( ; it != last; ++it ) {
02159                                           int strip = it->getStrip();
02160                                           std::vector<int> myADCVals = it->getADCCounts();
02161                                           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
02162                                           if(((float)myADCVals[3]-thisPedestal) < 6 || widthpos == 10 || it==last){break;}
02163                                            if(strip != centerStrip){ widthpos += 1;
02164                                            }
02165                                   }
02166                                   itr = digiItr;
02167                                   for( ; itr != first; --itr) {
02168                                           int strip = itr->getStrip();
02169                                           std::vector<int> myADCVals = itr->getADCCounts();
02170                                           float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
02171                                           if(((float)myADCVals[3]-thisPedestal) < 6 || widthneg == 10 || itr==first){break;}     
02172                                           if(strip != centerStrip) {widthneg += 1 ; 
02173                                           }
02174                                   }
02175                           }
02176                   }
02177           }
02178   }
02179   //std::cout << "Widthneg - " <<  widthneg << "Widthpos + " <<  widthpos << std::endl;
02180   width =  width + widthneg +  widthpos ;
02181   //std::cout << "Width " <<  width << std::endl;
02182   return width;
02183 }
02184 
02185 
02186 //---------------------------------------------------------------------------
02187 // Module for looking at gas gains
02188 // Author N. Terentiev
02189 //---------------------------------------------------------------------------
02190 
02191 void CSCValidation::doGasGain(const CSCWireDigiCollection& wirecltn, 
02192                               const CSCStripDigiCollection&   strpcltn,
02193                               const CSCRecHit2DCollection& rechitcltn) {
02194      float y;
02195      int channel=0,mult,wire,layer,idlayer,idchamber,ring;
02196      int wire_strip_rechit_present;
02197      std::string name,title,endcapstr;
02198      ostringstream ss;
02199      CSCIndexer indexer;
02200      std::map<int,int>::iterator intIt;
02201 
02202      m_single_wire_layer.clear();
02203 
02204   if(firstEvent) {
02205 
02206   // HV segments, their # and location in terms of wire groups
02207 
02208   m_wire_hvsegm.clear();
02209   std::map<int,std::vector<int> >::iterator intvecIt;
02210   //                    ME1a ME1b ME1/2 ME1/3 ME2/1 ME2/2 ME3/1 ME3/2 ME4/1 ME4/2 
02211   int csctype[10]=     {1,   2,   3,    4,    5,    6,    7,    8,    9,    10};
02212   int hvsegm_layer[10]={1,   1,   3,    3,    3,    5,    3,    5,    3,    5};
02213   int id;
02214   nmbhvsegm.clear();
02215   for(int i=0;i<10;i++) nmbhvsegm.push_back(hvsegm_layer[i]);
02216   // For ME1/1a
02217   std::vector<int> zer_1_1a(49,0);
02218   id=csctype[0];
02219   if(m_wire_hvsegm.find(id) == m_wire_hvsegm.end()) m_wire_hvsegm[id]=zer_1_1a;
02220   intvecIt=m_wire_hvsegm.find(id);
02221   for(int wire=1;wire<=48;wire++)  intvecIt->second[wire]=1;  // Segment 1
02222 
02223   // For ME1/1b
02224   std::vector<int> zer_1_1b(49,0);
02225   id=csctype[1];
02226   if(m_wire_hvsegm.find(id) == m_wire_hvsegm.end()) m_wire_hvsegm[id]=zer_1_1b;
02227   intvecIt=m_wire_hvsegm.find(id);
02228   for(int wire=1;wire<=48;wire++)  intvecIt->second[wire]=1;  // Segment 1
02229  
02230   // For ME1/2
02231   std::vector<int> zer_1_2(65,0);
02232   id=csctype[2];
02233   if(m_wire_hvsegm.find(id) == m_wire_hvsegm.end()) m_wire_hvsegm[id]=zer_1_2;
02234   intvecIt=m_wire_hvsegm.find(id);
02235   for(int wire=1;wire<=24;wire++)  intvecIt->second[wire]=1;  // Segment 1
02236   for(int wire=25;wire<=48;wire++) intvecIt->second[wire]=2;  // Segment 2
02237   for(int wire=49;wire<=64;wire++) intvecIt->second[wire]=3;  // Segment 3
02238  
02239   // For ME1/3
02240   std::vector<int> zer_1_3(33,0);
02241   id=csctype[3];
02242   if(m_wire_hvsegm.find(id) == m_wire_hvsegm.end()) m_wire_hvsegm[id]=zer_1_3;
02243   intvecIt=m_wire_hvsegm.find(id);
02244   for(int wire=1;wire<=12;wire++)  intvecIt->second[wire]=1;  // Segment 1
02245   for(int wire=13;wire<=22;wire++) intvecIt->second[wire]=2;  // Segment 2
02246   for(int wire=23;wire<=32;wire++) intvecIt->second[wire]=3;  // Segment 3
02247  
02248   // For ME2/1
02249   std::vector<int> zer_2_1(113,0);
02250   id=csctype[4];
02251   if(m_wire_hvsegm.find(id) == m_wire_hvsegm.end()) m_wire_hvsegm[id]=zer_2_1;
02252   intvecIt=m_wire_hvsegm.find(id);
02253   for(int wire=1;wire<=44;wire++)   intvecIt->second[wire]=1;  // Segment 1
02254   for(int wire=45;wire<=80;wire++)  intvecIt->second[wire]=2;  // Segment 2
02255   for(int wire=81;wire<=112;wire++) intvecIt->second[wire]=3;  // Segment 3
02256  
02257   // For ME2/2
02258   std::vector<int> zer_2_2(65,0);
02259   id=csctype[5];
02260   if(m_wire_hvsegm.find(id) == m_wire_hvsegm.end()) m_wire_hvsegm[id]=zer_2_2;
02261   intvecIt=m_wire_hvsegm.find(id);
02262   for(int wire=1;wire<=16;wire++)  intvecIt->second[wire]=1;  // Segment 1
02263   for(int wire=17;wire<=28;wire++) intvecIt->second[wire]=2;  // Segment 2
02264   for(int wire=29;wire<=40;wire++) intvecIt->second[wire]=3;  // Segment 3
02265   for(int wire=41;wire<=52;wire++) intvecIt->second[wire]=4;  // Segment 4
02266   for(int wire=53;wire<=64;wire++) intvecIt->second[wire]=5;  // Segment 5
02267 
02268   // For ME3/1
02269   std::vector<int> zer_3_1(97,0);
02270   id=csctype[6];
02271   if(m_wire_hvsegm.find(id) == m_wire_hvsegm.end()) m_wire_hvsegm[id]=zer_3_1;
02272   intvecIt=m_wire_hvsegm.find(id);
02273   for(int wire=1;wire<=32;wire++)  intvecIt->second[wire]=1;  // Segment 1
02274   for(int wire=33;wire<=64;wire++) intvecIt->second[wire]=2;  // Segment 2
02275   for(int wire=65;wire<=96;wire++) intvecIt->second[wire]=3;  // Segment 3
02276  
02277   // For ME3/2
02278   std::vector<int> zer_3_2(65,0);
02279   id=csctype[7];
02280   if(m_wire_hvsegm.find(id) == m_wire_hvsegm.end()) m_wire_hvsegm[id]=zer_3_2;
02281   intvecIt=m_wire_hvsegm.find(id);
02282   for(int wire=1;wire<=16;wire++)  intvecIt->second[wire]=1;  // Segment 1
02283   for(int wire=17;wire<=28;wire++) intvecIt->second[wire]=2;  // Segment 2
02284   for(int wire=29;wire<=40;wire++) intvecIt->second[wire]=3;  // Segment 3
02285   for(int wire=41;wire<=52;wire++) intvecIt->second[wire]=4;  // Segment 4
02286   for(int wire=53;wire<=64;wire++) intvecIt->second[wire]=5;  // Segment 5
02287 
02288   // For ME4/1
02289   std::vector<int> zer_4_1(97,0);
02290   id=csctype[8];
02291   if(m_wire_hvsegm.find(id) == m_wire_hvsegm.end()) m_wire_hvsegm[id]=zer_4_1;
02292   intvecIt=m_wire_hvsegm.find(id);
02293   for(int wire=1;wire<=32;wire++)  intvecIt->second[wire]=1;  // Segment 1
02294   for(int wire=33;wire<=64;wire++) intvecIt->second[wire]=2;  // Segment 2
02295   for(int wire=65;wire<=96;wire++) intvecIt->second[wire]=3;  // Segment 3
02296 
02297   // For ME4/2
02298   std::vector<int> zer_4_2(65,0);
02299   id=csctype[9];
02300   if(m_wire_hvsegm.find(id) == m_wire_hvsegm.end()) m_wire_hvsegm[id]=zer_4_2;
02301   intvecIt=m_wire_hvsegm.find(id);
02302   for(int wire=1;wire<=16;wire++)  intvecIt->second[wire]=1;  // Segment 1
02303   for(int wire=17;wire<=28;wire++) intvecIt->second[wire]=2;  // Segment 2
02304   for(int wire=29;wire<=40;wire++) intvecIt->second[wire]=3;  // Segment 3
02305   for(int wire=41;wire<=52;wire++) intvecIt->second[wire]=4;  // Segment 4
02306   for(int wire=53;wire<=64;wire++) intvecIt->second[wire]=5;  // Segment 5
02307 
02308   } // end of if(nEventsAnalyzed==1)
02309 
02310 
02311      // do wires, strips and rechits present?
02312      wire_strip_rechit_present=0;
02313      if(wirecltn.begin() != wirecltn.end())  
02314        wire_strip_rechit_present= wire_strip_rechit_present+1;
02315      if(strpcltn.begin() != strpcltn.end())    
02316        wire_strip_rechit_present= wire_strip_rechit_present+2;
02317      if(rechitcltn.begin() != rechitcltn.end())
02318        wire_strip_rechit_present= wire_strip_rechit_present+4;
02319 
02320      if(wire_strip_rechit_present==7) {
02321 
02322 //       std::cout<<"Event "<<nEventsAnalyzed<<std::endl;
02323 //       std::cout<<std::endl;
02324 
02325        // cycle on wire collection for all CSC to select single wire hit layers
02326        CSCWireDigiCollection::DigiRangeIterator wiredetUnitIt;
02327  
02328        for(wiredetUnitIt=wirecltn.begin();wiredetUnitIt!=wirecltn.end();
02329           ++wiredetUnitIt) {
02330           const CSCDetId id = (*wiredetUnitIt).first;
02331           idlayer=indexer.dbIndex(id, channel);
02332           idchamber=idlayer/10;
02333           layer=id.layer();
02334           // looping in the layer of given CSC
02335           mult=0; wire=0; 
02336           const CSCWireDigiCollection::Range& range = (*wiredetUnitIt).second;
02337           for(CSCWireDigiCollection::const_iterator digiIt =
02338              range.first; digiIt!=range.second; ++digiIt){
02339              wire=(*digiIt).getWireGroup();
02340              mult++;
02341           }     // end of digis loop in layer
02342 
02343           // select layers with single wire hit
02344           if(mult==1) {
02345             if(m_single_wire_layer.find(idlayer) == m_single_wire_layer.end())
02346               m_single_wire_layer[idlayer]=wire;
02347           } // end of if(mult==1)
02348        }   // end of cycle on detUnit
02349 
02350        // Looping thru rechit collection
02351        CSCRecHit2DCollection::const_iterator recIt;
02352        CSCRecHit2D::ADCContainer m_adc;
02353 
02354        for(recIt = rechitcltn.begin(); recIt != rechitcltn.end(); ++recIt) {
02355           CSCDetId id = (CSCDetId)(*recIt).cscDetId();
02356           idlayer=indexer.dbIndex(id, channel);
02357           idchamber=idlayer/10;
02358           layer=id.layer();
02359           // select layer with single wire rechit
02360           if(m_single_wire_layer.find(idlayer) != m_single_wire_layer.end()) {
02361 
02362             if(recIt->nStrips()==3)  {        
02363               // get 3X3 ADC Sum
02364               unsigned int binmx=0;
02365               float adcmax=0.0;
02366  
02367               for(unsigned int i=0;i<recIt->nStrips();i++) 
02368                 for(unsigned int j=0;j<recIt->nTimeBins();j++)
02369                   if(recIt->adcs(i,j)>adcmax) {
02370                     adcmax=recIt->adcs(i,j); 
02371                     binmx=j;
02372                   }
02373 
02374               float adc_3_3_sum=0.0;
02375               //well, this really only works for 3 strips in readout - not sure the right fix for general case
02376               for(unsigned int i=0;i<recIt->nStrips();i++) 
02377                 for(unsigned int j=binmx-1;j<=binmx+1;j++) 
02378                   adc_3_3_sum+=recIt->adcs(i,j);
02379                 
02380 
02381                if(adc_3_3_sum > 0.0 &&  adc_3_3_sum < 2000.0) {
02382 
02383                  // temporary fix for ME1/1a to avoid triple entries
02384                  int flag=0;
02385                  if(id.station()==1 && id.ring()==4 &&  recIt->channels(1)>16)  flag=1;
02386                  // end of temporary fix
02387                  if(flag==0) {
02388 
02389                  wire= m_single_wire_layer[idlayer];
02390                  int chambertype=id.iChamberType(id.station(),id.ring());
02391                  int hvsgmtnmb=m_wire_hvsegm[chambertype][wire];
02392                  int nmbofhvsegm=nmbhvsegm[chambertype-1];
02393                  int location= (layer-1)*nmbofhvsegm+hvsgmtnmb;
02394                  float x=location;
02395                 
02396                  ss<<"gas_gain_rechit_adc_3_3_sum_location_ME_"<<idchamber;
02397                  name=ss.str(); ss.str("");
02398                  if(id.endcap()==1) endcapstr = "+";
02399                  ring=id.ring();
02400                  if(id.station()==1 && id.ring()==4) ring=1;
02401                  if(id.endcap()==2) endcapstr = "-"; 
02402                  ss<<"Gas Gain Rechit ADC3X3 Sum ME"<<endcapstr<<
02403                    id.station()<<"/"<<ring<<"/"<<id.chamber();
02404                  title=ss.str(); ss.str("");
02405                  x=location;
02406                  y=adc_3_3_sum;
02407                  histos->fill2DHist(x,y,name.c_str(),title.c_str(),30,1.0,31.0,50,0.0,2000.0,"GasGain");
02408 
02409                  /*
02410                    std::cout<<idchamber<<"   "<<id.station()<<" "<<id.ring()<<" "
02411                    <<id.chamber()<<"    "<<layer<<" "<< wire<<" "<<m_strip[1]<<" "<<
02412                    chambertype<<" "<< hvsgmtnmb<<" "<< nmbofhvsegm<<" "<< 
02413                    location<<"   "<<adc_3_3_sum<<std::endl;
02414                  */
02415                } // end of if flag==0
02416                } // end if(adcsum>0.0 && adcsum<2000.0)
02417             } // end of if if(m_strip.size()==3
02418           } // end of if single wire
02419         } // end of looping thru rechit collection
02420      }   // end of if wire and strip and rechit present 
02421 }
02422 
02423 //---------------------------------------------------------------------------
02424 // Module for looking at AFEB Timing
02425 // Author N. Terentiev
02426 //---------------------------------------------------------------------------
02427 
02428 void CSCValidation::doAFEBTiming(const CSCWireDigiCollection& wirecltn) {
02429      ostringstream ss;
02430      std::string name,title,endcapstr;
02431      float x,y;
02432      int wire,wiretbin,nmbwiretbin,layer,afeb,idlayer,idchamber;
02433      int channel=0; // for  CSCIndexer::dbIndex(id, channel); irrelevant here
02434      CSCIndexer indexer;
02435 
02436      if(wirecltn.begin() != wirecltn.end())  {
02437 
02438        //std::cout<<std::endl;
02439        //std::cout<<"Event "<<nEventsAnalyzed<<std::endl;
02440        //std::cout<<std::endl;
02441 
02442        // cycle on wire collection for all CSC
02443        CSCWireDigiCollection::DigiRangeIterator wiredetUnitIt;
02444        for(wiredetUnitIt=wirecltn.begin();wiredetUnitIt!=wirecltn.end();
02445           ++wiredetUnitIt) {
02446           const CSCDetId id = (*wiredetUnitIt).first;
02447           idlayer=indexer.dbIndex(id, channel);
02448           idchamber=idlayer/10;
02449           layer=id.layer();
02450 
02451           if (id.endcap() == 1) endcapstr = "+";
02452           if (id.endcap() == 2) endcapstr = "-";
02453 
02454           // looping in the layer of given CSC
02455  
02456           const CSCWireDigiCollection::Range& range = (*wiredetUnitIt).second;
02457           for(CSCWireDigiCollection::const_iterator digiIt =
02458              range.first; digiIt!=range.second; ++digiIt){
02459              wire=(*digiIt).getWireGroup();
02460              wiretbin=(*digiIt).getTimeBin();
02461              nmbwiretbin=(*digiIt).getTimeBinsOn().size();
02462              afeb=3*((wire-1)/8)+(layer+1)/2;
02463              
02464              // Anode wire group time bin vs afeb for each CSC
02465              x=afeb;
02466              y=wiretbin;
02467              ss<<"afeb_time_bin_vs_afeb_occupancy_ME_"<<idchamber;
02468              name=ss.str(); ss.str("");
02469              ss<<"Time Bin vs AFEB Occupancy ME"<<endcapstr<<id.station()<<"/"<<id.ring()<<"/"<< id.chamber();
02470              title=ss.str(); ss.str("");
02471              histos->fill2DHist(x,y,name.c_str(),title.c_str(),42,1.,43.,16,0.,16.,"AFEBTiming");
02472 
02473              // Number of anode wire group time bin vs afeb for each CSC
02474              x=afeb;
02475              y=nmbwiretbin;
02476              ss<<"nmb_afeb_time_bins_vs_afeb_ME_"<<idchamber;
02477              name=ss.str(); ss.str("");
02478              ss<<"Number of Time Bins vs AFEB ME"<<endcapstr<<id.station()<<"/"<<id.ring()<<"/"<< id.chamber();
02479              title=ss.str(); 
02480              ss.str("");
02481              histos->fill2DHist(x,y,name.c_str(),title.c_str(),42,1.,43.,16,0.,16.,"AFEBTiming");
02482              
02483           }     // end of digis loop in layer
02484        } // end of wire collection loop
02485      } // end of      if(wirecltn.begin() != wirecltn.end())
02486 }
02487 
02488 //---------------------------------------------------------------------------
02489 // Module for looking at Comparitor Timing
02490 // Author N. Terentiev
02491 //---------------------------------------------------------------------------
02492 
02493 void CSCValidation::doCompTiming(const CSCComparatorDigiCollection& compars) {
02494 
02495      ostringstream ss;      std::string name,title,endcap;
02496      float x,y;
02497      int strip,tbin,cfeb,idlayer,idchamber;
02498      int channel=0; // for  CSCIndexer::dbIndex(id, channel); irrelevant here
02499      CSCIndexer indexer;
02500                                                                                 
02501      if(compars.begin() != compars.end())  {
02502                                                                                 
02503        //std::cout<<std::endl;
02504        //std::cout<<"Event "<<nEventsAnalyzed<<std::endl;
02505        //std::cout<<std::endl;
02506                                                                                 
02507        // cycle on comparators collection for all CSC
02508        CSCComparatorDigiCollection::DigiRangeIterator compdetUnitIt;
02509        for(compdetUnitIt=compars.begin();compdetUnitIt!=compars.end();
02510           ++compdetUnitIt) {
02511           const CSCDetId id = (*compdetUnitIt).first;
02512           idlayer=indexer.dbIndex(id, channel); // channel irrelevant here
02513           idchamber=idlayer/10;
02514                                                                                 
02515           if (id.endcap() == 1) endcap = "+";
02516           if (id.endcap() == 2) endcap = "-";
02517           // looping in the layer of given CSC
02518           const CSCComparatorDigiCollection::Range& range = 
02519           (*compdetUnitIt).second;
02520           for(CSCComparatorDigiCollection::const_iterator digiIt =
02521              range.first; digiIt!=range.second; ++digiIt){
02522              strip=(*digiIt).getStrip();
02523           /*
02524           if(id.station()==1 && (id.ring()==1 || id.ring()==4))
02525              std::cout<<idchamber<<" "<<id.station()<<" "<<id.ring()<<" "
02526                       <<strip <<std::endl;  
02527           */
02528              indexer.dbIndex(id, strip); // strips 1-16 of ME1/1a 
02529                                          // become strips 65-80 of ME1/1 
02530              tbin=(*digiIt).getTimeBin();
02531              cfeb=(strip-1)/16+1;
02532                                                                                 
02533              // time bin vs cfeb for each CSC
02534 
02535              x=cfeb;
02536              y=tbin;
02537              ss<<"comp_time_bin_vs_cfeb_occupancy_ME_"<<idchamber;
02538              name=ss.str(); ss.str("");
02539              ss<<"Comparator Time Bin vs CFEB Occupancy ME"<<endcap<<
02540                  id.station()<<"/"<< id.ring()<<"/"<< id.chamber();             
02541              title=ss.str(); ss.str("");
02542              histos->fill2DHist(x,y,name.c_str(),title.c_str(),5,1.,6.,16,0.,16.,"CompTiming");
02543 
02544          }     // end of digis loop in layer
02545        } // end of collection loop
02546      } // end of      if(compars.begin() !=compars.end())
02547 }
02548 
02549 //---------------------------------------------------------------------------
02550 // Module for looking at Strip Timing
02551 // Author N. Terentiev
02552 //---------------------------------------------------------------------------
02553 
02554 void CSCValidation::doADCTiming(const CSCRecHit2DCollection& rechitcltn) {
02555   float  adc_3_3_sum,adc_3_3_wtbin,x,y;
02556      int cfeb,idchamber,ring;
02557 
02558      std::string name,title,endcapstr;
02559      ostringstream ss;
02560      std::vector<float> zer(6,0.0);
02561 
02562      CSCIndexer indexer;
02563      std::map<int,int>::iterator intIt;
02564 
02565      if(rechitcltn.begin() != rechitcltn.end()) {
02566 
02567   //   std::cout<<"Event "<<nEventsAnalyzed <<std::endl;
02568 
02569        // Looping thru rechit collection
02570        CSCRecHit2DCollection::const_iterator recIt;
02571        CSCRecHit2D::ADCContainer m_adc;
02572        for(recIt = rechitcltn.begin(); recIt != rechitcltn.end(); ++recIt) {
02573           CSCDetId id = (CSCDetId)(*recIt).cscDetId();
02574           // getting strips comprising rechit
02575           if(recIt->nStrips()==3) {
02576             // get 3X3 ADC Sum
02577               // get 3X3 ADC Sum
02578               unsigned int binmx=0;
02579               float adcmax=0.0;
02580  
02581               for(unsigned int i=0;i<recIt->nStrips();i++) 
02582                 for(unsigned int j=0;j<recIt->nTimeBins();j++)
02583                   if(recIt->adcs(i,j)>adcmax) {
02584                     adcmax=recIt->adcs(i,j); 
02585                     binmx=j;
02586                   }
02587 
02588               adc_3_3_sum=0.0;
02589               //well, this really only works for 3 strips in readout - not sure the right fix for general case
02590               for(unsigned int i=0;i<recIt->nStrips();i++) 
02591                 for(unsigned int j=binmx-1;j<=binmx+1;j++) 
02592                   adc_3_3_sum+=recIt->adcs(i,j);
02593 
02594 
02595                 // ADC weighted time bin
02596                 if(adc_3_3_sum > 100.0) {
02597                   
02598 
02599                   int centerStrip=recIt->channels(1); //take central from 3 strips;
02600                 // temporary fix
02601                   int flag=0;
02602                   if(id.station()==1 && id.ring()==4 &&  centerStrip>16) flag=1;
02603                 // end of temporary fix
02604                   if(flag==0) {
02605                   adc_3_3_wtbin=(*recIt).tpeak()/50;   //getTiming(strpcltn, id, centerStrip);
02606                   idchamber=indexer.dbIndex(id, centerStrip)/10; //strips 1-16 ME1/1a
02607                                               // become strips 65-80 ME1/1 !!!
02608                   /*
02609                   if(id.station()==1 && (id.ring()==1 || id.ring()==4))
02610                   std::cout<<idchamber<<" "<<id.station()<<" "<<id.ring()<<" "<<m_strip[1]<<" "<<
02611                       "      "<<centerStrip<<
02612                          " "<<adc_3_3_wtbin<<"     "<<adc_3_3_sum<<std::endl;    
02613                   */      
02614                  ss<<"adc_3_3_weight_time_bin_vs_cfeb_occupancy_ME_"<<idchamber;
02615                  name=ss.str(); ss.str("");
02616 
02617                  std::string endcapstr;
02618                  if(id.endcap() == 1) endcapstr = "+";
02619                  if(id.endcap() == 2) endcapstr = "-";
02620                  ring=id.ring(); if(id.ring()==4) ring=1;
02621                  ss<<"ADC 3X3 Weighted Time Bin vs CFEB Occupancy ME"
02622                    <<endcapstr<<id.station()<<"/"<<ring<<"/"<<id.chamber();
02623                  title=ss.str(); ss.str("");
02624 
02625                  cfeb=(centerStrip-1)/16+1;
02626                  x=cfeb; y=adc_3_3_wtbin;
02627                  histos->fill2DHist(x,y,name.c_str(),title.c_str(),5,1.,6.,80,-8.,8.,"ADCTiming");                                     
02628                  } // end of if flag==0
02629                 } // end of if (adc_3_3_sum > 100.0)
02630             } // end of if if(m_strip.size()==3
02631        } // end of the  pass thru CSCRecHit2DCollection
02632      }  // end of if (rechitcltn.begin() != rechitcltn.end())
02633 }
02634 
02635 //---------------------------------------------------------------------------------------
02636 // Construct histograms for monitoring the trigger and offline timing
02637 // Author: A. Deisher
02638 //---------------------------------------------------------------------------------------
02639 
02640 void CSCValidation::doTimeMonitoring(edm::Handle<CSCRecHit2DCollection> recHits, edm::Handle<CSCSegmentCollection> cscSegments,
02641                                      edm::Handle<CSCALCTDigiCollection> alcts, edm::Handle<CSCCLCTDigiCollection> clcts,
02642                                      edm::Handle<CSCCorrelatedLCTDigiCollection> correlatedlcts,
02643                                      edm::Handle<L1MuGMTReadoutCollection> pCollection, edm::ESHandle<CSCGeometry> cscGeom, 
02644                                      const edm::EventSetup& eventSetup, const edm::Event &event){
02645 
02646   map<CSCDetId, float > segment_median_map; //structure for storing the median time for segments in a chamber 
02647   map<CSCDetId, GlobalPoint > segment_position_map; //structure for storing the global position for segments in a chamber 
02648   
02649   // -----------------------
02650   // loop over segments
02651   // -----------------------
02652   int iSegment = 0; 
02653   for(CSCSegmentCollection::const_iterator dSiter=cscSegments->begin(); dSiter != cscSegments->end(); dSiter++) {
02654     iSegment++;
02655     
02656     CSCDetId id  = (CSCDetId)(*dSiter).cscDetId();
02657     LocalPoint localPos = (*dSiter).localPosition();
02658     GlobalPoint globalPosition = GlobalPoint(0.0, 0.0, 0.0);
02659     const CSCChamber* cscchamber = cscGeom->chamber(id);
02660     if (cscchamber) {
02661       globalPosition = cscchamber->toGlobal(localPos);
02662     }
02663     
02664     // try to get the CSC recHits that contribute to this segment.
02665     std::vector<CSCRecHit2D> theseRecHits = (*dSiter).specificRecHits();
02666     int nRH = (*dSiter).nRecHits();
02667     if (nRH < 4 ) continue;
02668     
02669     //Store the recHit times of a segment in a vector for later sorting
02670     vector<float> non_zero;
02671     
02672     for ( vector<CSCRecHit2D>::const_iterator iRH = theseRecHits.begin(); iRH != theseRecHits.end(); iRH++) {
02673       non_zero.push_back( iRH->tpeak());
02674       
02675     }// end rechit loop
02676     
02677     //Sort the vector of hit times for this segment and average the center two
02678     sort(non_zero.begin(),non_zero.end());
02679     int middle_index = non_zero.size()/2;
02680     float average_two = (non_zero.at(middle_index-1) + non_zero.at(middle_index))/2.;
02681     if(non_zero.size()%2)
02682       average_two = non_zero.at(middle_index);
02683 
02684     //If we've vetoed events with multiple segments per chamber, this should never overwrite informations
02685     segment_median_map[id]=average_two;
02686     segment_position_map[id]=globalPosition;
02687     
02688     double distToIP = sqrt(globalPosition.x()*globalPosition.x()+globalPosition.y()*globalPosition.y()+globalPosition.z()*globalPosition.z());
02689      
02690     histos->fillProfile(chamberSerial(id),average_two,"timeChamber","Segment mean time",601,-0.5,600.5,-400.,400.,"TimeMonitoring");
02691     histos->fillProfileByType(id.chamber(),average_two,"timeChamberByType","Segment mean time by chamber",id,36,0.5,36.5,-400,400.,"TimeMonitoring");
02692     histos->fill2DHist(distToIP,average_two,"seg_time_vs_distToIP","Segment time vs. Distance to IP",80,600.,1400.,800,-400,400.,"TimeMonitoring");
02693     histos->fill2DHist(globalPosition.z(),average_two,"seg_time_vs_globZ","Segment time vs. z position",240,-1200,1200,800,-400.,400.,"TimeMonitoring");
02694     histos->fill2DHist(fabs(globalPosition.z()),average_two,"seg_time_vs_absglobZ","Segment time vs. abs(z position)",120,0.,1200.,800,-400.,400.,"TimeMonitoring");
02695     
02696   }//end segment loop
02697   
02698    //Now that the information for each segment we're interest in is stored, it is time to go through the pairs and make plots
02699   map<CSCDetId, float >::const_iterator it_outer; //for the outer loop 
02700   map<CSCDetId, float >::const_iterator it_inner; //for the nested inner loop
02701   for (it_outer = segment_median_map.begin(); it_outer != segment_median_map.end(); it_outer++){
02702     
02703     CSCDetId id_outer =  it_outer->first;
02704     float t_outer = it_outer->second;
02705     
02706     //begin the inner loop
02707     for (it_inner = segment_median_map.begin(); it_inner != segment_median_map.end(); it_inner++){
02708       
02709       CSCDetId id_inner =  it_inner->first;
02710       float t_inner = it_inner->second;
02711       
02712       // we're looking at ordered pairs, so combinations will be double counted 
02713       // (chamber a, chamber b) will be counted as well as (chamber b, chamber a)
02714       // We will avoid (chamber a, chamber a) with the following line
02715       if (chamberSerial(id_outer) == chamberSerial(id_inner)) continue;
02716       
02717       // Calculate expected TOF (in ns units)
02718       // GlobalPoint gp_outer = segment_position_map.find(id_outer)->second;
02719       // GlobalPoint gp_inner = segment_position_map.find(id_inner)->second;
02720       // GlobalVector flight = gp_outer - gp_inner; //in cm
02721       // float TOF = flight.mag()/30.0;             //to ns
02722       
02723       //Plot t(ME+) - t(ME-) for chamber pairs in the same stations and rings but opposite endcaps
02724       if (id_outer.endcap() ==1 && id_inner.endcap() == 2 && id_outer.station() == id_inner.station() && id_outer.ring() == id_inner.ring() ){
02725         histos->fill1DHist(t_outer-t_inner,"diff_opposite_endcaps","#Delta t [ME+]-[ME-] for chambers in same station and ring",800,-400.,400.,"TimeMonitoring");
02726         histos->fill1DHistByType(t_outer-t_inner,"diff_opposite_endcaps_byType","#Delta t [ME+]-[ME-] for chambers in same station and ring",id_outer,800,-400.,400.,"TimeMonitoring");
02727       }
02728 
02729     }//end inner loop of segment pairs
02730   }//end outer loop of segment pairs
02731 
02732   //if the digis, return here
02733   if( !useDigis ) return;
02734 
02735   //looking for the global trigger number 
02736   vector<L1MuGMTReadoutRecord> L1Mrec = pCollection->getRecords();
02737   vector<L1MuGMTReadoutRecord>::const_iterator igmtrr;
02738   int L1GMT_BXN = -100;
02739   bool has_CSCTrigger = false;
02740   bool has_beamHaloTrigger = false;
02741   for(igmtrr=L1Mrec.begin(); igmtrr!=L1Mrec.end(); igmtrr++) {
02742     std::vector<L1MuRegionalCand>::const_iterator iter1;
02743     std::vector<L1MuRegionalCand> rmc;
02744     // CSC
02745     int icsc = 0;
02746     rmc = igmtrr->getCSCCands();
02747     for(iter1=rmc.begin(); iter1!=rmc.end(); iter1++) {
02748       if ( !(*iter1).empty() ) {
02749         icsc++;
02750         int kQuality = (*iter1).quality();   // kQuality = 1 means beam halo
02751         if (kQuality == 1) has_beamHaloTrigger = true;
02752       }
02753     }
02754     if (igmtrr->getBxInEvent() == 0 && icsc>0){
02755       //printf("L1 CSCCands exist.  L1MuGMTReadoutRecord BXN = %d \n", igmtrr->getBxNr());
02756       L1GMT_BXN = igmtrr->getBxNr();
02757       has_CSCTrigger = true;
02758     }
02759     else if (igmtrr->getBxInEvent() == 0 ) { 
02760       //printf("L1 CSCCands do not exist.  L1MuGMTReadoutRecord BXN = %d \n", igmtrr->getBxNr());
02761       L1GMT_BXN = igmtrr->getBxNr();
02762     }
02763   }
02764 
02765   // *************************************************
02766   // *** ALCT Digis **********************************
02767   // *************************************************
02768   
02769   int n_alcts = 0;
02770   map<CSCDetId, int > ALCT_KeyWG_map; //structure for storing the key wire group for the first ALCT for each chamber
02771   for (CSCALCTDigiCollection::DigiRangeIterator j=alcts->begin(); j!=alcts->end(); j++) {
02772     const CSCALCTDigiCollection::Range& range =(*j).second;
02773     const CSCDetId& idALCT = (*j).first;
02774     for (CSCALCTDigiCollection::const_iterator digiIt = range.first; digiIt!=range.second; ++digiIt){
02775       // Valid digi in the chamber (or in neighbouring chamber)  
02776       if((*digiIt).isValid()){
02777         n_alcts++;
02778         histos->fill1DHist( (*digiIt).getBX(), "ALCT_getBX","ALCT.getBX()",11,-0.5,10.5,"TimeMonitoring");
02779         histos->fill1DHist( (*digiIt).getFullBX(), "ALCT_getFullBX","ALCT.getFullBX()",3601,-0.5,3600.5,"TimeMonitoring");
02780         //if we don't already have digi information stored for this chamber, then we fill it
02781         if (ALCT_KeyWG_map.find(idALCT.chamberId()) == ALCT_KeyWG_map.end()){
02782           ALCT_KeyWG_map[idALCT.chamberId()] = (*digiIt).getKeyWG();
02783           //printf("I did fill ALCT info for Chamber %d %d %d %d \n",idALCT.chamberId().endcap(), idALCT.chamberId().station(), idALCT.chamberId().ring(), idALCT.chamberId().chamber());
02784         }
02785 
02786       }
02787     }
02788   }
02789    
02790   // *************************************************
02791   // *** CLCT Digis **********************************
02792   // *************************************************
02793   int n_clcts = 0;
02794   map<CSCDetId, int > CLCT_getFullBx_map; //structure for storing the pretrigger bxn for the first CLCT for each chamber
02795   for (CSCCLCTDigiCollection::DigiRangeIterator j=clcts->begin(); j!=clcts->end(); j++) {
02796     const CSCCLCTDigiCollection::Range& range =(*j).second;
02797     const CSCDetId& idCLCT = (*j).first;
02798     for (CSCCLCTDigiCollection::const_iterator digiIt = range.first; digiIt!=range.second; ++digiIt){
02799       // Valid digi in the chamber (or in neighbouring chamber) 
02800       if((*digiIt).isValid()){
02801         n_clcts++;
02802         histos->fill1DHist( (*digiIt).getBX(), "CLCT_getBX","CLCT.getBX()",11,-0.5,10.5,"TimeMonitoring");
02803         histos->fill1DHist( (*digiIt).getFullBX(), "CLCT_getFullBX","CLCT.getFullBX()",3601,-0.5,3600.5,"TimeMonitoring");
02804         //if we don't already have digi information stored for this chamber, then we fill it
02805         if (CLCT_getFullBx_map.find(idCLCT.chamberId()) == CLCT_getFullBx_map.end()){
02806           CLCT_getFullBx_map[idCLCT.chamberId()] = (*digiIt).getFullBX();
02807           //printf("I did fill CLCT info for Chamber %d %d %d %d \n",idCLCT.chamberId().endcap(), idCLCT.chamberId().station(), idCLCT.chamberId().ring(), idCLCT.chamberId().chamber());
02808         }
02809       }
02810     }
02811   }
02812   
02813   // *************************************************
02814   // *** CorrelatedLCT Digis *************************
02815   // *************************************************
02816   int n_correlatedlcts = 0;
02817   for (CSCCorrelatedLCTDigiCollection::DigiRangeIterator j=correlatedlcts->begin(); j!=correlatedlcts->end(); j++) {
02818     const CSCCorrelatedLCTDigiCollection::Range& range =(*j).second;
02819     for (CSCCorrelatedLCTDigiCollection::const_iterator digiIt = range.first; digiIt!=range.second; ++digiIt){
02820       if((*digiIt).isValid()){
02821         n_correlatedlcts++;
02822         histos->fill1DHist( (*digiIt).getBX(), "CorrelatedLCTS_getBX","CorrelatedLCT.getBX()",11,-0.5,10.5,"TimeMonitoring");
02823       }
02824     }
02825   }
02826 
02827 
02828   int nRecHits = recHits->size();
02829   int nSegments = cscSegments->size();
02830   if (has_CSCTrigger){
02831     histos->fill1DHist(L1GMT_BXN,"BX_L1CSCCand","BX of L1 CSC Cand",4001,-0.5,4000.5,"TimeMonitoring");
02832     histos->fill2DHist(L1GMT_BXN,n_alcts,"n_ALCTs_v_BX_L1CSCCand","Number of ALCTs vs. BX of L1 CSC Cand",4001,-0.5,4000.5,51,-0.5,50.5,"TimeMonitoring");
02833     histos->fill2DHist(L1GMT_BXN,n_clcts,"n_CLCTs_v_BX_L1CSCCand","Number of CLCTs vs. BX of L1 CSC Cand",4001,-0.5,4000.5,51,-0.5,50.5,"TimeMonitoring");
02834     histos->fill2DHist(L1GMT_BXN,n_correlatedlcts,"n_CorrelatedLCTs_v_BX_L1CSCCand","Number of CorrelatedLCTs vs. BX of L1 CSC Cand",4001,-0.5,4000.5,51,-0.5,50.5,"TimeMonitoring");
02835     histos->fill2DHist(L1GMT_BXN,nRecHits,"n_RecHits_v_BX_L1CSCCand","Number of RecHits vs. BX of L1 CSC Cand",4001,-0.5,4000.5,101,-0.5,100.5,"TimeMonitoring");
02836     histos->fill2DHist(L1GMT_BXN,nSegments,"n_Segments_v_BX_L1CSCCand","Number of Segments vs. BX of L1 CSC Cand",4001,-0.5,4000.5,51,-0.5,50.5,"TimeMonitoring");
02837   }
02838   if (has_CSCTrigger && has_beamHaloTrigger){
02839     histos->fill1DHist(L1GMT_BXN,"BX_L1CSCCand_w_beamHalo","BX of L1 CSC (w beamHalo bit)",4001,-0.5,4000.5,"TimeMonitoring");
02840     histos->fill2DHist(L1GMT_BXN,n_alcts,"n_ALCTs_v_BX_L1CSCCand_w_beamHalo","Number of ALCTs vs. BX of L1 CSC Cand (w beamHalo bit)",4001,-0.5,4000.5,51,-0.5,50.5,"TimeMonitoring");
02841     histos->fill2DHist(L1GMT_BXN,n_clcts,"n_CLCTs_v_BX_L1CSCCand_w_beamHalo","Number of CLCTs vs. BX of L1 CSC Cand (w beamHalo bit)",4001,-0.5,4000.5,51,-0.5,50.5,"TimeMonitoring");
02842     histos->fill2DHist(L1GMT_BXN,n_correlatedlcts,"n_CorrelatedLCTs_v_BX_L1CSCCand_w_beamHalo","Number of CorrelatedLCTs vs. BX of L1 CSC Cand (w beamHalo bit)",4001,-0.5,4000.5,51,-0.5,50.5,"TimeMonitoring");
02843     histos->fill2DHist(L1GMT_BXN,nRecHits,"n_RecHits_v_BX_L1CSCCand_w_beamHalo","Number of RecHits vs. BX of L1 CSC Cand (w beamHalo bit)",4001,-0.5,4000.5,101,-0.5,100.5,"TimeMonitoring");
02844     histos->fill2DHist(L1GMT_BXN,nSegments,"n_Segments_v_BX_L1CSCCand_w_beamHalo","Number of Segments vs. BX of L1 CSC Cand (w beamHalo bit)",4001,-0.5,4000.5,51,-0.5,50.5,"TimeMonitoring");
02845   }
02846   
02847   // *******************************************************************
02848   // Get information from the TMB header.  
02849   // Can this eventually come out of the digis?
02850   // Taking code from EventFilter/CSCRawToDigis/CSCDCCUnpacker.cc
02851   // *******************************************************************
02852   
02853   edm::ESHandle<CSCCrateMap> hcrate;
02854   eventSetup.get<CSCCrateMapRcd>().get(hcrate); 
02855   const CSCCrateMap* pcrate = hcrate.product();
02856   
02858   edm::Handle<FEDRawDataCollection> rawdata;
02859   event.getByLabel("source", rawdata);
02860   bool goodEvent = false;
02861   // If set selective unpacking mode 
02862   // hardcoded examiner mask below to check for DCC and DDU level errors will be used first
02863   // then examinerMask for CSC level errors will be used during unpacking of each CSC block
02864   unsigned long dccBinCheckMask = 0x06080016;
02865   unsigned int examinerMask = 0x1FEBF3F6; 
02866   unsigned int errorMask = 0x0;
02867 
02868   for (int id=FEDNumbering::MINCSCFEDID; id<=FEDNumbering::MAXCSCFEDID; ++id) {
02869     // loop over DCCs
02872     
02874     const FEDRawData& fedData = rawdata->FEDData(id);
02875     unsigned long length =  fedData.size();
02876     
02877     if (length>=32){ 
02878       CSCDCCExaminer* examiner = NULL;
02879       std::stringstream examiner_out, examiner_err;
02880       goodEvent = true;
02882       //CSCDCCExaminer examiner;
02883       examiner = new CSCDCCExaminer();
02884       examiner->output1().redirect(examiner_out);
02885       examiner->output2().redirect(examiner_err);
02886       if( examinerMask&0x40000 ) examiner->crcCFEB(1);
02887       if( examinerMask&0x8000  ) examiner->crcTMB (1);
02888       if( examinerMask&0x0400  ) examiner->crcALCT(1);
02889       examiner->output1().show();
02890       examiner->output2().show();
02891       examiner->setMask(examinerMask);
02892       const short unsigned int *data = (short unsigned int *)fedData.data();
02893      
02894       if( examiner->check(data,long(fedData.size()/2)) < 0 )    {
02895         goodEvent=false;
02896       } 
02897       else {      
02898         goodEvent=!(examiner->errors()&dccBinCheckMask);
02899       }  
02900       
02901       if (goodEvent) {
02903         CSCDCCExaminer * ptrExaminer = examiner;
02904         CSCDCCEventData dccData((short unsigned int *) fedData.data(),ptrExaminer);
02905         
02907         const std::vector<CSCDDUEventData> & dduData = dccData.dduData();
02908         
02910         CSCDetId layer(1, 1, 1, 1, 1);
02911         
02912         for (unsigned int iDDU=0; iDDU<dduData.size(); ++iDDU) {  // loop over DDUs
02915           if (dduData[iDDU].trailer().errorstat()&errorMask) {
02916             LogTrace("CSCDCCUnpacker|CSCRawToDigi") << "DDU# " << iDDU << " has serious error - no digis unpacked! " <<
02917               std::hex << dduData[iDDU].trailer().errorstat();
02918             continue; // to next iteration of DDU loop
02919           }
02920           
02922           const std::vector<CSCEventData> & cscData = dduData[iDDU].cscData();
02923           for (unsigned int iCSC=0; iCSC<cscData.size(); ++iCSC) { // loop over CSCs
02924             
02925             int vmecrate = cscData[iCSC].dmbHeader()->crateID();
02926             int dmb = cscData[iCSC].dmbHeader()->dmbID();
02927             
02929             // SKIPPING MTCC redefinition of vmecrate
02930             
02931             int icfeb = 0;  
02932             int ilayer = 0; 
02933             
02934             if ((vmecrate>=1)&&(vmecrate<=60) && (dmb>=1)&&(dmb<=10)&&(dmb!=6)) {
02935               layer = pcrate->detId(vmecrate, dmb,icfeb,ilayer );
02936             } 
02937             else{
02938               LogTrace ("CSCTimingAlignment|CSCDCCUnpacker|CSCRawToDigi") << " detID input out of range!!! ";
02939               LogTrace ("CSCTimingAlignment|CSCDCCUnpacker|CSCRawToDigi")
02940                 << " skipping chamber vme= " << vmecrate << " dmb= " << dmb;
02941               continue; // to next iteration of iCSC loop
02942             }
02943             
02945             int nalct = cscData[iCSC].dmbHeader()->nalct();
02946             bool goodALCT=false;
02947             //if (nalct&&(cscData[iCSC].dataPresent>>6&0x1)==1) {
02948             if (nalct&&cscData[iCSC].alctHeader()) {  
02949               if (cscData[iCSC].alctHeader()->check()){
02950                 goodALCT=true;
02951               }
02952             }
02953             
02955             int nclct = cscData[iCSC].dmbHeader()->nclct();
02956             bool goodTMB=false;
02957             if (nclct&&cscData[iCSC].tmbData()) {
02958               if (cscData[iCSC].tmbHeader()->check()){
02959                 if (cscData[iCSC].clctData()->check()) goodTMB=true; 
02960               }
02961             }  
02962               
02963             if (goodTMB && goodALCT) { 
02964 
02965               if (ALCT_KeyWG_map.find(layer) == ALCT_KeyWG_map.end()) {
02966                 printf("no ALCT info for Chamber %d %d %d %d \n",layer.endcap(), layer.station(), layer.ring(), layer.chamber());
02967                 continue;
02968               }
02969               if (CLCT_getFullBx_map.find(layer) == CLCT_getFullBx_map.end()) {
02970                 printf("no CLCT info for Chamber %d %d %d %d \n",layer.endcap(), layer.station(), layer.ring(), layer.chamber());
02971                 continue;
02972               }
02973               int ALCT0Key = ALCT_KeyWG_map.find(layer)->second;
02974               int CLCTPretrigger = CLCT_getFullBx_map.find(layer)->second;
02975 
02976 
02977 
02978               const CSCTMBHeader *tmbHead = cscData[iCSC].tmbHeader();
02979 
02980               histos->fill1DHistByStation(tmbHead->BXNCount(),     "TMB_BXNCount"     ,"TMB_BXNCount"     , layer.chamberId(),3601,-0.5,3600.5,"TimeMonitoring");
02981               histos->fill1DHistByStation(tmbHead->ALCTMatchTime(),"TMB_ALCTMatchTime","TMB_ALCTMatchTime", layer.chamberId(),7,-0.5,6.5,"TimeMonitoring");
02982 
02983               histos->fill1DHist(tmbHead->BXNCount(),     "TMB_BXNCount"     ,"TMB_BXNCount"     , 3601,-0.5,3600.5,"TimeMonitoring");
02984               histos->fill1DHist(tmbHead->ALCTMatchTime(),"TMB_ALCTMatchTime","TMB_ALCTMatchTime", 7,-0.5,6.5,"TimeMonitoring");
02985 
02986               histos->fill1DHistByType(tmbHead->ALCTMatchTime(),"TMB_ALCTMatchTime","TMB_ALCTMatchTime",layer.chamberId(), 7,-0.5,6.5,"TimeMonitoring");
02987 
02988               histos->fillProfile( chamberSerial(layer.chamberId()),tmbHead->ALCTMatchTime(),"prof_TMB_ALCTMatchTime","prof_TMB_ALCTMatchTime", 601,-0.5,600.5,-0.5,7.5,"TimeMonitoring");
02989               histos->fillProfile(ALCT0Key,tmbHead->ALCTMatchTime(),"prof_TMB_ALCTMatchTime_v_ALCT0KeyWG","prof_TMB_ALCTMatchTime_v_ALCT0KeyWG",128,-0.5,127.5,0,7,"TimeMonitoring");
02990               histos->fillProfileByType(ALCT0Key,tmbHead->ALCTMatchTime(),"prf_TMB_ALCTMatchTime_v_ALCT0KeyWG","prf_TMB_ALCTMatchTime_v_ALCT0KeyWG",layer.chamberId(),128,-0.5,127.5,0,7,"TimeMonitoring");
02991 
02992               //Attempt to make a few sum plots
02993 
02994               int TMB_ALCT_rel_L1A = tmbHead->BXNCount()-(CLCTPretrigger+2+tmbHead->ALCTMatchTime());
02995               if (TMB_ALCT_rel_L1A > 3563)
02996                 TMB_ALCT_rel_L1A = TMB_ALCT_rel_L1A - 3564;
02997               if (TMB_ALCT_rel_L1A < 0)
02998                 TMB_ALCT_rel_L1A = TMB_ALCT_rel_L1A + 3564;
02999 
03000               //Plot TMB_ALCT_rel_L1A
03001               histos->fill1DHist(TMB_ALCT_rel_L1A,"h1D_TMB_ALCT_rel_L1A","h1D_TMB_ALCT_rel_L1A",11,144.5,155.5,"TimeMonitoring");
03002               histos->fill2DHist( chamberSerial(layer.chamberId()),TMB_ALCT_rel_L1A,"h2D_TMB_ALCT_rel_L1A","h2D_TMB_ALCT_rel_L1A", 601,-0.5,600.5,11,144.5,155.5,"TimeMonitoring");
03003               histos->fill2DHist( ringSerial(layer.chamberId()),TMB_ALCT_rel_L1A,"h2D_TMB_ALCT_rel_L1A_by_ring","h2D_TMB_ALCT_rel_L1A_by_ring",19,-9.5,9.5,11,144.5,155.5,"TimeMonitoring");
03004               histos->fillProfile( chamberSerial(layer.chamberId()),TMB_ALCT_rel_L1A,"prof_TMB_ALCT_rel_L1A","prof_TMB_ALCT_rel_L1A", 601,-0.5,600.5,145,155,"TimeMonitoring");
03005               histos->fillProfile( ringSerial(layer.chamberId()),TMB_ALCT_rel_L1A,"prof_TMB_ALCT_rel_L1A_by_ring","prof_TMB_ALCT_rel_L1A_by_ring",19,-9.5,9.5,145,155,"TimeMonitoring");
03006 
03007               histos->fill2DHist (ALCT0Key,TMB_ALCT_rel_L1A,"h2D_TMB_ALCT_rel_L1A_v_ALCT0KeyWG","h2D_TMB_ALCT_rel_L1A_v_ALCT0KeyWG",  128,-0.5,127.5,11,144.5,155.5,"TimeMonitoring");
03008               histos->fillProfile(ALCT0Key,TMB_ALCT_rel_L1A,"prof_TMB_ALCT_rel_L1A_v_ALCT0KeyWG","prof_TMB_ALCT_rel_L1A_v_ALCT0KeyWG",128,-0.5,127.5,145,155,"TimeMonitoring");
03009               histos->fillProfileByType(ALCT0Key,TMB_ALCT_rel_L1A,"prf_TMB_ALCT_rel_L1A_v_ALCT0KeyWG","prf_TMB_ALCT_rel_L1A_v_ALCT0KeyWG",layer.chamberId(),128,-0.5,127.5,145,155,"TimeMonitoring");
03010             }
03011 
03012           } // end CSCData loop
03013         } // end ddu data loop
03014       } // end if goodEvent
03015       if (examiner!=NULL) delete examiner;
03016     }// end if non-zero fed data
03017   } // end DCC loop for NON-REFERENCE
03018 
03019 }
03020 
03021 
03022 void CSCValidation::endJob() {
03023 
03024      std::cout<<"Events in "<<nEventsAnalyzed<<std::endl;
03025 }
03026 
03027 DEFINE_FWK_MODULE(CSCValidation);
03028