CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CSCEfficiency.cc
Go to the documentation of this file.
1 /*
2  * Routine to calculate CSC efficiencies
3  * Comments about the program logic are denoted by //----
4  *
5  * Stoyan Stoynev, Northwestern University.
6  */
7 
9 
17 using namespace std;
18 using namespace edm;
19 
20 //---- The Analysis (main)
21 bool CSCEfficiency::filter(Event & event, const EventSetup& eventSetup){
22  passTheEvent = false;
23  DataFlow->Fill(0.);
25 
26  //---- increment counter
27  nEventsAnalyzed++;
28  // printalot debug output
29  printalot = (nEventsAnalyzed < int(printout_NEvents)); //
30  int iRun = event.id().run();
31  int iEvent = event.id().event();
32  if(0==fmod(double (nEventsAnalyzed) ,double(1000) )){
33  if(printalot){
34  printf("\n==enter==CSCEfficiency===== run %i\tevent %i\tn Analyzed %i\n",iRun,iEvent,nEventsAnalyzed);
35  }
36  }
37  theService->update(eventSetup);
38  //---- These declarations create handles to the types of records that you want
39  //---- to retrieve from event "e".
40  if (printalot) printf("\tget handles for digi collections\n");
41 
42  //---- Pass the handle to the method "getByType", which is used to retrieve
43  //---- one and only one instance of the type in question out of event "e". If
44  //---- zero or more than one instance exists in the event an exception is thrown.
45  if (printalot) printf("\tpass handles\n");
53  //edm::Handle<reco::TrackCollection> saMuons;
54  edm::Handle<edm::View<reco::Track> > trackCollectionH;
56 
57  if(useDigis){
58  event.getByLabel(alctDigiTag_, alcts);
59  event.getByLabel(clctDigiTag_, clcts);
60  event.getByLabel(corrlctDigiTag_, correlatedlcts);
61 
62  event.getByLabel( stripDigiTag_, strips);
63  event.getByLabel( wireDigiTag_, wires);
64  }
65  if(!isData){
66  event.getByLabel(simHitTag, simhits);
67  }
68  event.getByLabel(rechitDigiTag_,rechits);
69  event.getByLabel(segmentDigiTag_, segments);
70  //event.getByLabel(saMuonTag,saMuons);
71  event.getByLabel(tracksTag,trackCollectionH);
72  const edm::View<reco::Track> trackCollection = *(trackCollectionH.product());
73 
74  //---- Get the CSC Geometry :
75  if (printalot) printf("\tget the CSC geometry.\n");
77  eventSetup.get<MuonGeometryRecord>().get(cscGeom);
78 
79  // use theTrackingGeometry instead of cscGeom?
80  ESHandle<GlobalTrackingGeometry> theTrackingGeometry;
81  eventSetup.get<GlobalTrackingGeometryRecord>().get(theTrackingGeometry);
82 
83  bool triggerPassed = true;
84  if(useTrigger){
85  // access the trigger information
86  // trigger names can be find in HLTrigger/Configuration/python/HLT_2E30_cff.py (or?)
87  // get hold of TriggerResults
89  event.getByLabel(hlTriggerResults_,hltR);
90  const edm::TriggerNames & triggerNames = event.triggerNames(*hltR);
91  triggerPassed = applyTrigger(hltR, triggerNames);
92  }
93  if(!triggerPassed){
94  return triggerPassed;
95  }
96  DataFlow->Fill(1.);
97  GlobalPoint gpZero(0.,0.,0.);
98  if(theService->magneticField()->inTesla(gpZero).mag2()<0.1){
99  magField = false;
100  }
101  else{
102  magField = true;
103  }
104 
105  //---- store info from digis
106  fillDigiInfo(alcts, clcts, correlatedlcts, wires, strips, simhits, rechits, segments, cscGeom);
107  //
109  edm::InputTag muonTag_("muons");
110  event.getByLabel(muonTag_,muons);
111 
112  edm::Handle<reco::BeamSpot> beamSpotHandle;
113  event.getByLabel("offlineBeamSpot", beamSpotHandle);
114  reco::BeamSpot vertexBeamSpot = *beamSpotHandle;
115  //
116  std::vector <reco::MuonCollection::const_iterator> goodMuons_it;
117  unsigned int nPositiveZ = 0;
118  unsigned int nNegativeZ = 0;
119  float muonOuterZPosition = -99999.;
120  if(isIPdata){
121  if (printalot)std::cout<<" muons.size() = "<<muons->size() <<std::endl;
122  for ( reco::MuonCollection::const_iterator muon = muons->begin(); muon != muons->end(); ++muon ) {
123  DataFlow->Fill(31.);
124  if (printalot) {
125  std::cout<<" iMuon = "<<muon-muons->begin()<<" charge = "<<muon->charge()<<" p = "<<muon->p()<<" pt = "<<muon->pt()<<
126  " eta = "<<muon->eta()<<" phi = "<<muon->phi()<<
127  " matches = "<<
128  muon->matches().size()<<" matched Seg = "<<muon->numberOfMatches(reco::Muon::SegmentAndTrackArbitration)<<" GLB/TR/STA = "<<
129  muon->isGlobalMuon()<<"/"<<muon->isTrackerMuon()<<"/"<<muon->isStandAloneMuon()<<std::endl;
130  }
131  if(!(muon->isTrackerMuon() && muon->isGlobalMuon())){
132  continue;
133  }
134  DataFlow->Fill(32.);
135  double relISO = ( muon->isolationR03().sumPt +
136  muon->isolationR03().emEt +
137  muon->isolationR03().hadEt)/muon->track()->pt();
138  if (printalot) {
139  std::cout<<" relISO = "<<relISO<<" emVetoEt = "<<muon->isolationR03().emVetoEt<<" caloComp = "<<
140  muon::caloCompatibility(*(muon))<<" dxy = "<<fabs(muon->track()->dxy(vertexBeamSpot.position()))<<std::endl;
141  }
142  if(
143  //relISO>0.1 || muon::caloCompatibility(*(muon))<.90 ||
144  fabs(muon->track()->dxy(vertexBeamSpot.position()))>0.2 || muon->pt()<6.){
145  continue;
146  }
147  DataFlow->Fill(33.);
148  if(muon->track()->hitPattern().numberOfValidPixelHits()<1 ||
149  muon->track()->hitPattern().numberOfValidTrackerHits()<11 ||
150  muon->combinedMuon()->hitPattern().numberOfValidMuonHits()<1 ||
151  muon->combinedMuon()->normalizedChi2()>10. ||
152  muon->numberOfMatches()<2){
153  continue;
154  }
155  DataFlow->Fill(34.);
156  float zOuter = muon->combinedMuon()->outerPosition().z();
157  float rhoOuter = muon->combinedMuon()->outerPosition().rho();
158  bool passDepth = true;
159  // barrel region
160  //if ( fabs(zOuter) < 660. && rhoOuter > 400. && rhoOuter < 480.){
161  if ( fabs(zOuter) < 660. && rhoOuter > 400. && rhoOuter < 540.){
162  passDepth = false;
163  }
164  // endcap region
165  //else if( fabs(zOuter) > 550. && fabs(zOuter) < 650. && rhoOuter < 300.){
166  else if( fabs(zOuter) > 550. && fabs(zOuter) < 650. && rhoOuter < 300.){
167  passDepth = false;
168  }
169  // overlap region
170  //else if ( fabs(zOuter) > 680. && fabs(zOuter) < 730. && rhoOuter < 480.){
171  else if ( fabs(zOuter) > 680. && fabs(zOuter) < 880. && rhoOuter < 540.){
172  passDepth = false;
173  }
174  if(!passDepth){
175  continue;
176  }
177  DataFlow->Fill(35.);
178  goodMuons_it.push_back(muon);
179  if(muon->track()->momentum().z()>0.){
180  ++nPositiveZ;
181  }
182  if(muon->track()->momentum().z()<0.){
183  ++nNegativeZ;
184  }
185  }
186  }
187 
188  //
189 
190 
191  if (printalot) std::cout<<"Start track loop over "<<trackCollection.size()<<" tracks"<<std::endl;
192  for(edm::View<reco::Track>::size_type i=0; i<trackCollection.size(); ++i) {
193  DataFlow->Fill(2.);
194  edm::RefToBase<reco::Track> track(trackCollectionH, i);
195  //std::cout<<" iTR = "<<i<<" eta = "<<track->eta()<<" phi = "<<track->phi()<<std::cout<<" pt = "<<track->pt()<<std::endl;
196  if(isIPdata){
197  if (printalot){
198  std::cout<<" nNegativeZ = "<<nNegativeZ<<" nPositiveZ = "<<nPositiveZ<<std::endl;
199  }
200  if(nNegativeZ>1 || nPositiveZ>1){
201  break;
202  }
203  bool trackOK = false;
204  if (printalot){
205  std::cout<<" goodMuons_it.size() = "<<goodMuons_it.size()<<std::endl;
206  }
207  for(size_t iM=0;iM<goodMuons_it.size();++iM){
208  //std::cout<<" iM = "<<iM<<" eta = "<<goodMuons_it[iM]->track()->eta()<<
209  //" phi = "<<goodMuons_it[iM]->track()->phi()<<
210  //" pt = "<<goodMuons_it[iM]->track()->pt()<<std::endl;
211  float deltaR = pow(track->phi()-goodMuons_it[iM]->track()->phi(),2) +
212  pow(track->eta()-goodMuons_it[iM]->track()->eta(),2);
213  deltaR = sqrt(deltaR);
214  if (printalot){
215  std::cout<<" TR mu match to a tr: deltaR = "<<deltaR<<" dPt = "<<
216  track->pt()-goodMuons_it[iM]->track()->pt()<<std::endl;
217  }
218  if(deltaR>0.01 || fabs(track->pt()-goodMuons_it[iM]->track()->pt())>0.1 ){
219  continue;
220  }
221  else{
222  trackOK = true;
223  if (printalot){
224  std::cout<<" trackOK "<<std::endl;
225  }
226  muonOuterZPosition = goodMuons_it[iM]->combinedMuon()->outerPosition().z();
227  break;
228  //++nChosenTracks;
229  }
230  }
231  if(!trackOK){
232  if (printalot){
233  std::cout<<" failed: trackOK "<<std::endl;
234  }
235  continue;
236  }
237  }
238  else{
239  //---- Do we need a better "clean track" definition?
240  if(trackCollection.size()>2){
241  break;
242  }
243  DataFlow->Fill(3.);
244  if(!i && 2==trackCollection.size()){
246  edm::RefToBase<reco::Track> trackTwo(trackCollectionH, tType);
247  if(track->outerPosition().z()*trackTwo->outerPosition().z()>0){// in one and the same "endcap"
248  break;
249  }
250  }
251  }
252  DataFlow->Fill(4.);
253  if (printalot){
254  std::cout<<"i track = "<<i<<" P = "<<track->p()<<" chi2/ndf = "<<track->normalizedChi2()<<" nSeg = "<<segments->size()<<std::endl;
255  std::cout<<"quality undef/loose/tight/high/confirmed/goodIt/size "<<
256  track->quality(reco::Track::undefQuality)<<"/"<<
257  track->quality(reco::Track::loose)<<"/"<<
258  track->quality(reco::Track::tight)<<"/"<<
259  track->quality(reco::Track::highPurity)<<"/"<<
260  track->quality(reco::Track::confirmed)<<"/"<<
261  track->quality(reco::Track::goodIterative)<<"/"<<
263  std::endl;
264  std::cout<<" pt = "<< track->pt()<<" +-"<<track->ptError()<<" q/pt = "<<track->qoverp()<<" +- "<<track->qoverpError()<<std::endl;
265  //std::cout<<" const Pmin = "<<minTrackMomentum<<" pMax = "<<maxTrackMomentum<<" maxNormChi2 = "<<maxNormChi2<<std::endl;
266  std::cout<<" track inner position = "<<track->innerPosition()<<" outer position = "<<track->outerPosition()<<std::endl;
267  std::cout<<"track eta (outer) = "<<track->outerPosition().eta()<<" phi (outer) = "<<
268  track->outerPosition().phi()<<std::endl;
269  if(fabs(track->innerPosition().z())>500.){
270  DetId innerDetId(track->innerDetId());
271  std::cout<<" dump inner state MUON detid = "<<debug.dumpMuonId(innerDetId)<<std::endl;
272  }
273  if(fabs(track->outerPosition().z())>500.){
274  DetId outerDetId(track->outerDetId());
275  std::cout<<" dump outer state MUON detid = "<<debug.dumpMuonId(outerDetId)<<std::endl;
276  }
277 
278  std::cout<<" nHits = "<<track->found()<<std::endl;
279  /*
280  trackingRecHit_iterator rhbegin = track->recHitsBegin();
281  trackingRecHit_iterator rhend = track->recHitsEnd();
282  int iRH = 0;
283  for(trackingRecHit_iterator recHit = rhbegin; recHit != rhend; ++recHit){
284  const GeomDet* geomDet = theTrackingGeometry->idToDet((*recHit)->geographicalId());
285  std::cout<<"hit "<<iRH<<" loc pos = " <<(*recHit)->localPosition()<<
286  " glob pos = " <<geomDet->toGlobal((*recHit)->localPosition())<<std::endl;
287  ++iRH;
288  }
289  */
290  }
291  float dpT_ov_pT = 0.;
292  if(fabs(track->pt())>0.001){
293  dpT_ov_pT = track->ptError()/ track->pt();
294  }
295  //---- These define a "good" track
296  if(track->normalizedChi2()>maxNormChi2){// quality
297  break;
298  }
299  DataFlow->Fill(5.);
300  if(track->found()<minTrackHits){// enough data points
301  break;
302  }
303  DataFlow->Fill(6.);
304  if(!segments->size()){// better have something in the CSC
305  break;
306  }
307  DataFlow->Fill(7.);
308  if(magField && (track->p()<minP || track->p()>maxP)){// proper energy range
309  break;
310  }
311  DataFlow->Fill(8.);
312  if(magField && (dpT_ov_pT >0.5) ){// not too crazy uncertainty
313  break;
314  }
315  DataFlow->Fill(9.);
316 
317  passTheEvent = true;
318  if (printalot) std::cout<<"good Track"<<std::endl;
319  CLHEP::Hep3Vector r3T_inner(track->innerPosition().x(),track->innerPosition().y(),track->innerPosition().z());
320  CLHEP::Hep3Vector r3T(track->outerPosition().x(),track->outerPosition().y(),track->outerPosition().z());
321  chooseDirection(r3T_inner, r3T);// for non-IP
322 
323  CLHEP::Hep3Vector p3T(track->outerMomentum().x(),track->outerMomentum().y(),track->outerMomentum().z());
324  CLHEP::Hep3Vector p3_propagated, r3_propagated;
325  AlgebraicSymMatrix66 cov_propagated, covT;
326  covT *= 1e-20;
327  cov_propagated *= 1e-20;
328  int charge = track->charge();
329  FreeTrajectoryState ftsStart = getFromCLHEP(p3T, r3T, charge, covT, &*(theService->magneticField()));
330  if (printalot){
331  std::cout<<" p = "<<track->p()<<" norm chi2 = "<<track->normalizedChi2()<<std::endl;
332  std::cout<<" dump the very first FTS = "<<debug.dumpFTS(ftsStart)<<std::endl;
333  }
334  TrajectoryStateOnSurface tSOSDest;
335  int endcap = 0;
336  //---- which endcap to look at
337  if(track->outerPosition().z()>0){
338  endcap = 1;
339  }
340  else{
341  endcap = 2;
342  }
343  int chamber = 1;
344  //---- a "refference" CSCDetId for each ring
345  std::vector< CSCDetId > refME;
346  for(int iS=1;iS<5;++iS){
347  for(int iR=1;iR<4;++iR){
348  if(1!=iS && iR>2){
349  continue;
350  }
351  else if(4==iS && iR>1){
352  continue;
353  }
354  refME.push_back( CSCDetId(endcap, iS, iR, chamber));
355  }
356  }
357  //---- loop over the "refference" CSCDetIds
358  for(size_t iSt = 0; iSt<refME.size();++iSt){
359  if (printalot){
360  std::cout<<"loop iStatation = "<<iSt<<std::endl;
361  std::cout<<"refME[iSt]: st = "<<refME[iSt].station()<<" rg = "<<refME[iSt].ring()<<std::endl;
362  }
363  std::map <std::string, bool> chamberTypes;
364  chamberTypes["ME11"] = false;
365  chamberTypes["ME12"] = false;
366  chamberTypes["ME13"] = false;
367  chamberTypes["ME21"] = false;
368  chamberTypes["ME22"] = false;
369  chamberTypes["ME31"] = false;
370  chamberTypes["ME32"] = false;
371  chamberTypes["ME41"] = false;
372  const CSCChamber* cscChamber_base = cscGeom->chamber(refME[iSt].chamberId());
373  DetId detId = cscChamber_base->geographicalId();
374  if (printalot){
375  std::cout<<" base iStation : eta = "<<cscGeom->idToDet(detId)->surface().position().eta()<<" phi = "<<
376  cscGeom->idToDet(detId)->surface().position().phi() << " y = " <<cscGeom->idToDet(detId)->surface().position().y()<<std::endl;
377  std::cout<<" dump base iStation detid = "<<debug.dumpMuonId(detId)<<std::endl;
378  std::cout<<" dump FTS start = "<<debug.dumpFTS(ftsStart)<<std::endl;
379  }
380  //---- propagate to this ME
381  tSOSDest = propagate(ftsStart, cscGeom->idToDet(detId)->surface());
382  if(tSOSDest.isValid()){
383  ftsStart = *tSOSDest.freeState();
384  if (printalot) std::cout<<" dump FTS end = "<<debug.dumpFTS(ftsStart)<<std::endl;
385  getFromFTS(ftsStart, p3_propagated, r3_propagated, charge, cov_propagated);
386  float feta = fabs(r3_propagated.eta());
387  float phi = r3_propagated.phi();
388  //---- which rings are (possibly) penetrated
389  ringCandidates(refME[iSt].station(), feta, chamberTypes);
390 
391  map<std::string,bool>::iterator iter;
392  int iterations = 0;
393  //---- loop over ring candidates
394  for( iter = chamberTypes.begin(); iter != chamberTypes.end(); iter++ ) {
395  ++iterations;
396  //---- is this ME a machinig candidate station
397  if(iter->second && (iterations-1)==int(iSt)){
398  if (printalot){
399  std::cout<<" Chamber type "<< iter->first<<" is a candidate..."<<std::endl;
400  std::cout<<" station() = "<< refME[iSt].station()<<" ring() = "<<refME[iSt].ring()<<" iSt = "<<iSt<<std::endl;
401  }
402  std::vector <int> coupleOfChambers;
403  //---- which chamber (and its closes neighbor) is penetrated by the track - candidates
404  chamberCandidates(refME[iSt].station(), refME[iSt].ring(), phi, coupleOfChambers);
405  //---- loop over the two chamber candidates
406  for(size_t iCh =0;iCh<coupleOfChambers.size();++iCh){
407  DataFlow->Fill(11.);
408  if (printalot) std::cout<<" Check chamber N = "<<coupleOfChambers.at(iCh)<<std::endl;;
409  if((!getAbsoluteEfficiency) && (true == emptyChambers
410  [refME[iSt].endcap()-1]
411  [refME[iSt].station()-1]
412  [refME[iSt].ring()-1]
413  [coupleOfChambers.at(iCh)-FirstCh])){
414  continue;
415  }
416  CSCDetId theCSCId(refME[iSt].endcap(), refME[iSt].station(), refME[iSt].ring(), coupleOfChambers.at(iCh));
417  const CSCChamber* cscChamber = cscGeom->chamber(theCSCId.chamberId());
418  const BoundPlane bpCh = cscGeom->idToDet(cscChamber->geographicalId())->surface();
419  float zFTS = ftsStart.position().z();
420  float dz = fabs(bpCh.position().z() - zFTS);
421  float zDistInner = track->innerPosition().z() - bpCh.position().z();
422  float zDistOuter = track->outerPosition().z() - bpCh.position().z();
423  //---- only detectors between the inner and outer points of the track are considered for non IP-data
424  if(printalot){
425  std::cout<<" zIn = "<<track->innerPosition().z()<<" zOut = "<<track->outerPosition().z()<<" zSurf = "<<bpCh.position().z()<<std::endl;
426  }
427  if(!isIPdata && (zDistInner*zDistOuter>0. || fabs(zDistInner)<15. || fabs(zDistOuter)<15.)){ // for non IP-data
428  if(printalot){
429  std::cout<<" Not an intermediate (as defined) point... Skip."<<std::endl;
430  }
431  continue;
432  }
433  if(isIPdata && fabs(track->eta())<1.8){
434  if(fabs(muonOuterZPosition) - fabs(bpCh.position().z())<0 ||
435  fabs(muonOuterZPosition-bpCh.position().z())<15.){
436  continue;
437  }
438  }
439  DataFlow->Fill(13.);
440  //---- propagate to the chamber (from this ME) if it is a different surface (odd/even chambers)
441  if(dz>0.1){// i.e. non-zero (float 0 check is bad)
442  //if(fabs(zChanmber - zFTS ) > 0.1){
443  tSOSDest = propagate(ftsStart, cscGeom->idToDet(cscChamber->geographicalId())->surface());
444  if(tSOSDest.isValid()){
445  ftsStart = *tSOSDest.freeState();
446  }
447  else{
448  if(printalot) std::cout<<"TSOS not valid! Break."<<std::endl;
449  break;
450  }
451  }
452  else{
453  if(printalot) std::cout<<" info: dz<0.1"<<std::endl;
454  }
455  DataFlow->Fill(15.);
456  FreeTrajectoryState ftsInit = ftsStart;
457  bool inDeadZone = false;
458  //---- loop over the 6 layers
459  for(int iLayer = 0;iLayer<6;++iLayer){
460  bool extrapolationPassed = true;
461  if (printalot){
462  std::cout<<" iLayer = "<<iLayer<<" dump FTS init = "<<debug.dumpFTS(ftsInit)<<std::endl;
463  std::cout<<" dump detid = "<<debug.dumpMuonId(cscChamber->geographicalId())<<std::endl;
464  std::cout<<"Surface to propagate to: pos = "<<cscChamber->layer(iLayer+1)->surface().position()<<" eta = "
465  <<cscChamber->layer(iLayer+1)->surface().position().eta()<<" phi = "
466  <<cscChamber->layer(iLayer+1)->surface().position().phi()<<std::endl;
467  }
468  //---- propagate to this layer
469  tSOSDest = propagate(ftsInit, cscChamber->layer(iLayer+1)->surface());
470  if(tSOSDest.isValid()){
471  ftsInit = *tSOSDest.freeState();
472  if (printalot) std::cout<<" Propagation between layers successful: dump FTS end = "<<debug.dumpFTS(ftsInit)<<std::endl;
473  getFromFTS(ftsInit, p3_propagated, r3_propagated, charge, cov_propagated);
474  }
475  else{
476  if (printalot) std::cout<<"Propagation between layers not successful - notValid TSOS"<<std::endl;
477  extrapolationPassed = false;
478  inDeadZone = true;
479  }
480  //}
481  //---- Extrapolation passed? For each layer?
482  if(extrapolationPassed){
483  GlobalPoint theExtrapolationPoint(r3_propagated.x(),r3_propagated.y(),r3_propagated.z());
484  LocalPoint theLocalPoint = cscChamber->layer(iLayer+1)->toLocal(theExtrapolationPoint);
485  //std::cout<<" Candidate chamber: extrapolated LocalPoint = "<<theLocalPoint<<std::endl;
486  inDeadZone = ( inDeadZone ||
487  !inSensitiveLocalRegion(theLocalPoint.x(), theLocalPoint.y(),
488  refME[iSt].station(), refME[iSt].ring()));
489  if (printalot){
490  std::cout<<" Candidate chamber: extrapolated LocalPoint = "<<theLocalPoint<<"inDeadZone = "<<inDeadZone<<std::endl;
491  }
492  //---- break if in dead zone for any layer ("clean" tracks)
493  if(inDeadZone){
494  break;
495  }
496  }
497  else{
498  break;
499  }
500  }
501  DataFlow->Fill(17.);
502  //---- Is a track in a sensitive area for each layer?
503  if(!inDeadZone){//---- for any layer
504  DataFlow->Fill(19.);
505  if (printalot) std::cout<<"Do efficiencies..."<<std::endl;
506  //---- Do efficiencies
507  // angle cuts applied (if configured)
508  bool angle_flag = true; angle_flag = efficienciesPerChamber(theCSCId, cscChamber, ftsStart);
509  if(useDigis && angle_flag){
510  stripWire_Efficiencies(theCSCId, ftsStart);
511  }
512  if(angle_flag){
513  recHitSegment_Efficiencies(theCSCId, cscChamber, ftsStart);
514  if(!isData){
515  recSimHitEfficiency(theCSCId, ftsStart);
516  }
517  }
518  }
519  else{
520  if(printalot) std::cout<<" Not in active area for all layers"<<std::endl;
521  }
522  }
523  if(tSOSDest.isValid()){
524  ftsStart = *tSOSDest.freeState();
525  }
526  }
527  }
528  }
529  else{
530  if (printalot) std::cout<<" TSOS not valid..."<<std::endl;
531  }
532  }
533  }
534  //---- End
535  if (printalot) printf("==exit===CSCEfficiency===== run %i\tevent %i\n\n",iRun,iEvent);
536  return passTheEvent;
537 }
538 
539 //
540 bool CSCEfficiency::inSensitiveLocalRegion(double xLocal, double yLocal, int station, int ring){
541  //---- Good region means sensitive area of a chamber. "Local" stands for the local system
542  bool pass = false;
543  std::vector <double> chamberBounds(3);// the sensitive area
544  float y_center = 99999.;
545  //---- hardcoded... not good
546  if(station>1 && station<5){
547  if(2==ring){
548  chamberBounds[0] = 66.46/2; // (+-)x1 shorter
549  chamberBounds[1] = 127.15/2; // (+-)x2 longer
550  chamberBounds[2] = 323.06/2;
551  y_center = -0.95;
552  }
553  else{
554  if(2==station){
555  chamberBounds[0] = 54.00/2; // (+-)x1 shorter
556  chamberBounds[1] = 125.71/2; // (+-)x2 longer
557  chamberBounds[2] = 189.66/2;
558  y_center = -0.955;
559  }
560  else if(3==station){
561  chamberBounds[0] = 61.40/2; // (+-)x1 shorter
562  chamberBounds[1] = 125.71/2; // (+-)x2 longer
563  chamberBounds[2] = 169.70/2;
564  y_center = -0.97;
565  }
566  else if(4==station){
567  chamberBounds[0] = 69.01/2; // (+-)x1 shorter
568  chamberBounds[1] = 125.65/2; // (+-)x2 longer
569  chamberBounds[2] = 149.42/2;
570  y_center = -0.94;
571  }
572  }
573  }
574  else if(1==station){
575  if(3==ring){
576  chamberBounds[0] = 63.40/2; // (+-)x1 shorter
577  chamberBounds[1] = 92.10/2; // (+-)x2 longer
578  chamberBounds[2] = 164.16/2;
579  y_center = -1.075;
580  }
581  else if(2==ring){
582  chamberBounds[0] = 51.00/2; // (+-)x1 shorter
583  chamberBounds[1] = 83.74/2; // (+-)x2 longer
584  chamberBounds[2] = 174.49/2;
585  y_center = -0.96;
586  }
587  else{// to be investigated
588  chamberBounds[0] = 30./2;//40./2; // (+-)x1 shorter
589  chamberBounds[1] = 60./2;//100./2; // (+-)x2 longer
590  chamberBounds[2] = 160./2;//142./2;
591  y_center = 0.;
592  }
593  }
594  double yUp = chamberBounds[2] + y_center;
595  double yDown = - chamberBounds[2] + y_center;
596  double xBound1Shifted = chamberBounds[0]-distanceFromDeadZone;//
597  double xBound2Shifted = chamberBounds[1]-distanceFromDeadZone;//
598  double lineSlope = (yUp - yDown)/(xBound2Shifted-xBound1Shifted);
599  double lineConst = yUp - lineSlope*xBound2Shifted;
600  double yBoundary = lineSlope*abs(xLocal) + lineConst;
601  pass = checkLocal(yLocal, yBoundary, station, ring);
602  return pass;
603 }
604 
605 bool CSCEfficiency::checkLocal(double yLocal, double yBoundary, int station, int ring){
606 //---- check if it is in a good local region (sensitive area - geometrical and HV boundaries excluded)
607  bool pass = false;
608  std::vector <float> deadZoneCenter(6);
609  const float deadZoneHalf = 0.32*7/2;// wire spacing * (wires missing + 1)/2
610  float cutZone = deadZoneHalf + distanceFromDeadZone;//cm
611  //---- hardcoded... not good
612  if(station>1 && station<5){
613  if(2==ring){
614  deadZoneCenter[0]= -162.48 ;
615  deadZoneCenter[1] = -81.8744;
616  deadZoneCenter[2] = -21.18165;
617  deadZoneCenter[3] = 39.51105;
618  deadZoneCenter[4] = 100.2939;
619  deadZoneCenter[5] = 160.58;
620 
621  if(yLocal >yBoundary &&
622  ((yLocal> deadZoneCenter[0] + cutZone && yLocal< deadZoneCenter[1] - cutZone) ||
623  (yLocal> deadZoneCenter[1] + cutZone && yLocal< deadZoneCenter[2] - cutZone) ||
624  (yLocal> deadZoneCenter[2] + cutZone && yLocal< deadZoneCenter[3] - cutZone) ||
625  (yLocal> deadZoneCenter[3] + cutZone && yLocal< deadZoneCenter[4] - cutZone) ||
626  (yLocal> deadZoneCenter[4] + cutZone && yLocal< deadZoneCenter[5] - cutZone))){
627  pass = true;
628  }
629  }
630  else if(1==ring){
631  if(2==station){
632  deadZoneCenter[0]= -95.94 ;
633  deadZoneCenter[1] = -27.47;
634  deadZoneCenter[2] = 33.67;
635  deadZoneCenter[3] = 93.72;
636  }
637  else if(3==station){
638  deadZoneCenter[0]= -85.97 ;
639  deadZoneCenter[1] = -36.21;
640  deadZoneCenter[2] = 23.68;
641  deadZoneCenter[3] = 84.04;
642  }
643  else if(4==station){
644  deadZoneCenter[0]= -75.82;
645  deadZoneCenter[1] = -26.14;
646  deadZoneCenter[2] = 23.85;
647  deadZoneCenter[3] = 73.91;
648  }
649  if(yLocal >yBoundary &&
650  ((yLocal> deadZoneCenter[0] + cutZone && yLocal< deadZoneCenter[1] - cutZone) ||
651  (yLocal> deadZoneCenter[1] + cutZone && yLocal< deadZoneCenter[2] - cutZone) ||
652  (yLocal> deadZoneCenter[2] + cutZone && yLocal< deadZoneCenter[3] - cutZone))){
653  pass = true;
654  }
655  }
656  }
657  else if(1==station){
658  if(3==ring){
659  deadZoneCenter[0]= -83.155 ;
660  deadZoneCenter[1] = -22.7401;
661  deadZoneCenter[2] = 27.86665;
662  deadZoneCenter[3] = 81.005;
663  if(yLocal > yBoundary &&
664  ((yLocal> deadZoneCenter[0] + cutZone && yLocal< deadZoneCenter[1] - cutZone) ||
665  (yLocal> deadZoneCenter[1] + cutZone && yLocal< deadZoneCenter[2] - cutZone) ||
666  (yLocal> deadZoneCenter[2] + cutZone && yLocal< deadZoneCenter[3] - cutZone))){
667  pass = true;
668  }
669  }
670  else if(2==ring){
671  deadZoneCenter[0]= -86.285 ;
672  deadZoneCenter[1] = -32.88305;
673  deadZoneCenter[2] = 32.867423;
674  deadZoneCenter[3] = 88.205;
675  if(yLocal > (yBoundary) &&
676  ((yLocal> deadZoneCenter[0] + cutZone && yLocal< deadZoneCenter[1] - cutZone) ||
677  (yLocal> deadZoneCenter[1] + cutZone && yLocal< deadZoneCenter[2] - cutZone) ||
678  (yLocal> deadZoneCenter[2] + cutZone && yLocal< deadZoneCenter[3] - cutZone))){
679  pass = true;
680  }
681  }
682  else{
683  deadZoneCenter[0]= -81.0;
684  deadZoneCenter[1] = 81.0;
685  if(yLocal > (yBoundary) &&
686  ((yLocal> deadZoneCenter[0] + cutZone && yLocal< deadZoneCenter[1] - cutZone) )){
687  pass = true;
688  }
689  }
690  }
691  return pass;
692 }
693 
702  edm::ESHandle<CSCGeometry> &cscGeom){
703  for(int iE=0;iE<2;iE++){
704  for(int iS=0;iS<4;iS++){
705  for(int iR=0;iR<4;iR++){
706  for(int iC=0;iC<NumCh;iC++){
707  allSegments[iE][iS][iR][iC].clear();
708  allCLCT[iE][iS][iR][iC] = allALCT[iE][iS][iR][iC] = allCorrLCT[iE][iS][iR][iC] = false;
709  for(int iL=0;iL<6;iL++){
710  allStrips[iE][iS][iR][iC][iL].clear();
711  allWG[iE][iS][iR][iC][iL].clear();
712  allRechits[iE][iS][iR][iC][iL].clear();
713  allSimhits[iE][iS][iR][iC][iL].clear();
714  }
715  }
716  }
717  }
718  }
719  //
720  if(useDigis){
721  fillLCT_info(alcts, clcts, correlatedlcts);
722  fillWG_info(wires, cscGeom);
723  fillStrips_info(strips);
724  }
725  fillRechitsSegments_info(rechits, segments, cscGeom);
726  if(!isData){
727  fillSimhit_info(simhits);
728  }
729 }
730 
731 
735  //---- ALCTDigis
736  int nSize = 0;
737  for (CSCALCTDigiCollection::DigiRangeIterator j=alcts->begin(); j!=alcts->end(); j++) {
738  ++nSize;
739  const CSCDetId& id = (*j).first;
740  const CSCALCTDigiCollection::Range& range =(*j).second;
742  range.first; digiIt!=range.second;
743  ++digiIt){
744  // Valid digi in the chamber (or in neighbouring chamber)
745  if((*digiIt).isValid()){
746  allALCT[id.endcap()-1][id.station()-1][id.ring()-1][id.chamber()-FirstCh] = true;
747  }
748  }// for digis in layer
749  }// end of for (j=...
750  ALCTPerEvent->Fill(nSize);
751  //---- CLCTDigis
752  nSize = 0;
753  for (CSCCLCTDigiCollection::DigiRangeIterator j=clcts->begin(); j!=clcts->end(); j++) {
754  ++nSize;
755  const CSCDetId& id = (*j).first;
756  std::vector<CSCCLCTDigi>::const_iterator digiIt = (*j).second.first;
757  std::vector<CSCCLCTDigi>::const_iterator last = (*j).second.second;
758  for( ; digiIt != last; ++digiIt) {
759  // Valid digi in the chamber (or in neighbouring chamber)
760  if((*digiIt).isValid()){
761  allCLCT[id.endcap()-1][id.station()-1][id.ring()-1][id.chamber()-FirstCh] = true;
762  }
763  }
764  }
765  CLCTPerEvent->Fill(nSize);
766  //---- CorrLCTDigis
767  for (CSCCorrelatedLCTDigiCollection::DigiRangeIterator j=correlatedlcts->begin(); j!=correlatedlcts->end(); j++) {
768  const CSCDetId& id = (*j).first;
769  std::vector<CSCCorrelatedLCTDigi>::const_iterator digiIt = (*j).second.first;
770  std::vector<CSCCorrelatedLCTDigi>::const_iterator last = (*j).second.second;
771  for( ; digiIt != last; ++digiIt) {
772  // Valid digi in the chamber (or in neighbouring chamber)
773  if((*digiIt).isValid()){
774  allCorrLCT[id.endcap()-1][id.station()-1][id.ring()-1][id.chamber()-FirstCh] = true;
775  }
776  }
777  }
778 }
779 //
781  //---- WIRE GROUPS
782  for (CSCWireDigiCollection::DigiRangeIterator j=wires->begin(); j!=wires->end(); j++) {
783  CSCDetId id = (CSCDetId)(*j).first;
784  const CSCLayer *layer_p = cscGeom->layer (id);
785  const CSCLayerGeometry *layerGeom = layer_p->geometry ();
786  //
787  std::vector<CSCWireDigi>::const_iterator digiItr = (*j).second.first;
788  std::vector<CSCWireDigi>::const_iterator last = (*j).second.second;
789  //
790  for( ; digiItr != last; ++digiItr) {
791  std::pair < int, float > WG_pos(digiItr->getWireGroup(), layerGeom->yOfWireGroup(digiItr->getWireGroup()));
792  std::pair <std::pair < int, float >, int > LayerSignal(WG_pos, digiItr->getTimeBin());
793 
794  //---- AllWG contains basic information about WG (WG number and Y-position, time bin)
795  allWG[id.endcap()-1][id.station()-1][id.ring()-1][id.chamber()-FirstCh]
796  [id.layer()-1].push_back(LayerSignal);
797  if(printalot){
798  //std::cout<<" WG check : "<<std::endl;
799  //printf("\t\tendcap/station/ring/chamber/layer: %i/%i/%i/%i/%i\n",id.endcap(),id.station(),id.ring(),id.chamber(),id.layer());
800  //std::cout<<" WG size = "<<allWG[id.endcap()-1][id.station()-1][id.ring()-1][id.chamber()-FirstCh]
801  //[id.layer()-1].size()<<std::endl;
802  }
803  }
804  }
805 }
807  //---- STRIPS
808  for (CSCStripDigiCollection::DigiRangeIterator j=strips->begin(); j!=strips->end(); j++) {
809  CSCDetId id = (CSCDetId)(*j).first;
810  int largestADCValue = -1;
811  std::vector<CSCStripDigi>::const_iterator digiItr = (*j).second.first;
812  std::vector<CSCStripDigi>::const_iterator last = (*j).second.second;
813  for( ; digiItr != last; ++digiItr) {
814  int maxADC=largestADCValue;
815  int myStrip = digiItr->getStrip();
816  std::vector<int> myADCVals = digiItr->getADCCounts();
817  float thisPedestal = 0.5*(float)(myADCVals[0]+myADCVals[1]);
818  float threshold = 13.3 ;
819  float diff = 0.;
820  float peakADC = -1000.;
821  for (unsigned int iCount = 0; iCount < myADCVals.size(); iCount++) {
822  diff = (float)myADCVals[iCount]-thisPedestal;
823  if (diff > threshold) {
824  if (myADCVals[iCount] > largestADCValue) {
825  largestADCValue = myADCVals[iCount];
826  }
827  }
828  if (diff > threshold && diff > peakADC) {
829  peakADC = diff;
830  }
831  }
832  if(largestADCValue>maxADC){// FIX IT!!!
833  maxADC = largestADCValue;
834  std::pair <int, float> LayerSignal (myStrip, peakADC);
835 
836  //---- AllStrips contains basic information about strips
837  //---- (strip number and peak signal for most significant strip in the layer)
838  allStrips[id.endcap()-1][id.station()-1][id.ring()-1][id.chamber()-1][id.layer()-1].clear();
839  allStrips[id.endcap()-1][id.station()-1][id.ring()-1][id.chamber()-1][id.layer()-1].push_back(LayerSignal);
840  }
841  }
842  }
843 }
845  //---- SIMHITS
846  edm::PSimHitContainer::const_iterator dSHsimIter;
847  for (dSHsimIter = simhits->begin(); dSHsimIter != simhits->end(); dSHsimIter++){
848  // Get DetID for this simHit:
849  CSCDetId sId = (CSCDetId)(*dSHsimIter).detUnitId();
850  std::pair <LocalPoint, int> simHitPos((*dSHsimIter).localPosition(), (*dSHsimIter).particleType());
851  allSimhits[sId.endcap()-1][sId.station()-1][sId.ring()-1][sId.chamber()-FirstCh][sId.layer()-1].push_back(simHitPos);
852  }
853 }
854 //
858  ){
859  //---- RECHITS AND SEGMENTS
860  //---- Loop over rechits
861  if (printalot){
862  //printf("\tGet the recHits collection.\t ");
863  printf(" The size of the rechit collection is %i\n",int(rechits->size()));
864  //printf("\t...start loop over rechits...\n");
865  }
866  recHitsPerEvent->Fill(rechits->size());
867  //---- Build iterator for rechits and loop :
869  for (recIt = rechits->begin(); recIt != rechits->end(); recIt++) {
870  //---- Find chamber with rechits in CSC
871  CSCDetId id = (CSCDetId)(*recIt).cscDetId();
872  if (printalot){
873  const CSCLayer* csclayer = cscGeom->layer( id);
874  LocalPoint rhitlocal = (*recIt).localPosition();
875  LocalError rerrlocal = (*recIt).localPositionError();
876  GlobalPoint rhitglobal= csclayer->toGlobal(rhitlocal);
877  printf("\t\tendcap/station/ring/chamber/layer: %i/%i/%i/%i/%i\n",id.endcap(),id.station(),id.ring(),id.chamber(),id.layer());
878  printf("\t\tx,y,z: %f, %f, %f\texx,eey,exy: %f, %f, %f\tglobal x,y,z: %f, %f, %f \n",
879  rhitlocal.x(), rhitlocal.y(), rhitlocal.z(), rerrlocal.xx(), rerrlocal.yy(), rerrlocal.xy(),
880  rhitglobal.x(), rhitglobal.y(), rhitglobal.z());
881  }
882  std::pair <LocalPoint, bool> recHitPos((*recIt).localPosition(), false);
883  allRechits[id.endcap()-1][id.station()-1][id.ring()-1][id.chamber()-FirstCh][id.layer()-1].push_back(recHitPos);
884  }
885  //---- "Empty" chambers
886  for(int iE=0;iE<2;iE++){
887  for(int iS=0;iS<4;iS++){
888  for(int iR=0;iR<4;iR++){
889  for(int iC=0;iC<NumCh;iC++){
890  int numLayers = 0;
891  for(int iL=0;iL<6;iL++){
892  if(allRechits[iE][iS][iR][iC][iL].size()){
893  ++numLayers;
894  }
895  }
896  if(numLayers>1){
897  emptyChambers[iE][iS][iR][iC] = false;
898  }
899  else{
900  emptyChambers[iE][iS][iR][iC] = true;
901  }
902  }
903  }
904  }
905  }
906 
907  //
908  if (printalot){
909  printf(" The size of the segment collection is %i\n", int(segments->size()));
910  //printf("\t...start loop over segments...\n");
911  }
912  segmentsPerEvent->Fill(segments->size());
913  for(CSCSegmentCollection::const_iterator it = segments->begin(); it != segments->end(); it++) {
914  CSCDetId id = (CSCDetId)(*it).cscDetId();
915  StHist[id.endcap()-1][id.station()-1].segmentChi2_ndf->Fill((*it).chi2()/(*it).degreesOfFreedom());
916  StHist[id.endcap()-1][id.station()-1].hitsInSegment->Fill((*it).nRecHits());
917  if (printalot){
918  printf("\tendcap/station/ring/chamber: %i %i %i %i\n",
919  id.endcap(),id.station(),id.ring(),id.chamber());
920  std::cout<<"\tposition(loc) = "<<(*it).localPosition()<<" error(loc) = "<<(*it).localPositionError()<<std::endl;
921  std::cout<<"\t chi2/ndf = "<<(*it).chi2()/(*it).degreesOfFreedom()<<" nhits = "<<(*it).nRecHits() <<std::endl;
922 
923  }
924  allSegments[id.endcap()-1][id.station()-1][id.ring()-1][id.chamber()-FirstCh].push_back
925  (make_pair((*it).localPosition(), (*it).localDirection()));
926 
927 
928  //---- try to get the CSC recHits that contribute to this segment.
929  //if (printalot) printf("\tGet the recHits for this segment.\t");
930  std::vector<CSCRecHit2D> theseRecHits = (*it).specificRecHits();
931  int nRH = (*it).nRecHits();
932  if (printalot){
933  printf("\tGet the recHits for this segment.\t");
934  printf(" nRH = %i\n",nRH);
935  }
936  //---- Find which of the rechits in the chamber is in the segment
937  int layerRH = 0;
938  for ( vector<CSCRecHit2D>::const_iterator iRH = theseRecHits.begin(); iRH != theseRecHits.end(); iRH++) {
939  ++layerRH;
940  CSCDetId idRH = (CSCDetId)(*iRH).cscDetId();
941  if(printalot){
942  printf("\t%i RH\tendcap/station/ring/chamber/layer: %i/%i/%i/%i/%i\n",
943  layerRH,idRH.endcap(),idRH.station(),idRH.ring(),idRH.chamber(),idRH.layer());
944  }
945  for(size_t jRH = 0;
946  jRH<allRechits[idRH.endcap()-1][idRH.station()-1][idRH.ring()-1][idRH.chamber()-FirstCh][idRH.layer()-1].size();
947  ++jRH){
948  allRechits[idRH.endcap()-1][idRH.station()-1][idRH.ring()-1][idRH.chamber()-FirstCh][idRH.layer()-1][jRH].first;
949  float xDiff = iRH->localPosition().x() -
950  allRechits[idRH.endcap()-1][idRH.station()-1][idRH.ring()-1][idRH.chamber()-FirstCh][idRH.layer()-1][jRH].first.x();
951  float yDiff = iRH->localPosition().y() -
952  allRechits[idRH.endcap()-1][idRH.station()-1][idRH.ring()-1][idRH.chamber()-FirstCh][idRH.layer()-1][jRH].first.y();
953  if(fabs(xDiff)<0.0001 && fabs(yDiff)<0.0001){
954  std::pair <LocalPoint, bool>
955  recHitPos(allRechits[idRH.endcap()-1][idRH.station()-1][idRH.ring()-1][idRH.chamber()-FirstCh][idRH.layer()-1][jRH].first, true);
956  allRechits[idRH.endcap()-1][idRH.station()-1][idRH.ring()-1][idRH.chamber()-FirstCh][idRH.layer()-1][jRH] = recHitPos;
957  if(printalot){
958  std::cout<<" number of the rechit (from zero) in the segment = "<< jRH<<std::endl;
959  }
960  }
961  }
962  }
963  }
964 }
965 //
966 
967 void CSCEfficiency::ringCandidates(int station, float feta, std::map <std::string, bool> & chamberTypes){
968  // yeah, hardcoded again...
969  switch (station){
970  case 1:
971  if(feta>0.85 && feta<1.18){//ME13
972  chamberTypes["ME13"] = true;
973  }
974  if(feta>1.18 && feta<1.7){//ME12
975  chamberTypes["ME12"] = true;
976  }
977  if(feta>1.5 && feta<2.45){//ME11
978  chamberTypes["ME11"] = true;
979  }
980  break;
981  case 2:
982  if(feta>0.95 && feta<1.6){//ME22
983  chamberTypes["ME22"] = true;
984 
985  }
986  if(feta>1.55 && feta<2.45){//ME21
987  chamberTypes["ME21"] = true;
988  }
989  break;
990  case 3:
991  if(feta>1.08 && feta<1.72){//ME32
992  chamberTypes["ME32"] = true;
993 
994  }
995  if(feta>1.69 && feta<2.45){//ME31
996  chamberTypes["ME31"] = true;
997  }
998  break;
999  case 4:
1000  if(feta>1.78 && feta<2.45){//ME41
1001  chamberTypes["ME41"] = true;
1002  }
1003  break;
1004  default:
1005  break;
1006  }
1007 }
1008 //
1009 void CSCEfficiency::chamberCandidates(int station, int ring, float phi, std::vector <int> &coupleOfChambers){
1010  coupleOfChambers.clear();
1011  // -pi< phi<+pi
1012  float phi_zero = 0.;// check! the phi at the "edge" of Ch 1
1013  float phi_const = 2.*M_PI/36.;
1014  int last_chamber = 36;
1015  int first_chamber = 1;
1016  if(1 != station && 1==ring){ // 18 chambers in the ring
1017  phi_const*=2;
1018  last_chamber /= 2;
1019  }
1020  if(phi<0.){
1021  if (printalot) std::cout<<" info: negative phi = "<<phi<<std::endl;
1022  phi += 2*M_PI;
1023  }
1024  float chamber_float = (phi - phi_zero)/phi_const;
1025  int chamber_int = int(chamber_float);
1026  if (chamber_float - float(chamber_int) -0.5 <0.){
1027  if(0!=chamber_int ){
1028  coupleOfChambers.push_back(chamber_int);
1029  }
1030  else{
1031  coupleOfChambers.push_back(last_chamber);
1032  }
1033  coupleOfChambers.push_back(chamber_int+1);
1034 
1035  }
1036  else{
1037  coupleOfChambers.push_back(chamber_int+1);
1038  if(last_chamber!=chamber_int+1){
1039  coupleOfChambers.push_back(chamber_int+2);
1040  }
1041  else{
1042  coupleOfChambers.push_back(first_chamber);
1043  }
1044  }
1045  if (printalot) std::cout<<" phi = "<<phi<<" phi_zero = "<<phi_zero<<" phi_const = "<<phi_const<<
1046  " candidate chambers: first ch = "<<coupleOfChambers[0]<<" second ch = "<<coupleOfChambers[1]<<std::endl;
1047 }
1048 
1049 //
1051  int ec, st, rg, ch, secondRing;
1052  returnTypes(id, ec, st, rg, ch, secondRing);
1053 
1054  LocalVector localDir = cscChamber->toLocal(ftsChamber.momentum());
1055  if(printalot){
1056  std::cout<<" global dir = "<<ftsChamber.momentum()<<std::endl;
1057  std::cout<<" local dir = "<<localDir<<std::endl;
1058  std::cout<<" local theta = "<<localDir.theta()<<std::endl;
1059  }
1060  float dxdz = localDir.x()/localDir.z();
1061  float dydz = localDir.y()/localDir.z();
1062  if(2==st || 3==st){
1063  if(printalot){
1064  std::cout<<"st 3 or 4 ... flip dy/dz"<<std::endl;
1065  }
1066  dydz = - dydz;
1067  }
1068  if(printalot){
1069  std::cout<<"dy/dz = "<<dydz<<std::endl;
1070  }
1071  // Apply angle cut
1072  bool out = true;
1073  if(applyIPangleCuts){
1074  if(dydz>local_DY_DZ_Max || dydz<local_DY_DZ_Min || fabs(dxdz)>local_DX_DZ_Max){
1075  out = false;
1076  }
1077  }
1078 
1079  // Segments
1080  bool firstCondition = allSegments[ec][st][rg][ch].size() ? true : false;
1081  bool secondCondition = false;
1082  //---- ME1 is special as usual - ME1a and ME1b are actually one chamber
1083  if(secondRing>-1){
1084  secondCondition = allSegments[ec][st][secondRing][ch].size() ? true : false;
1085  }
1086  if(firstCondition || secondCondition){
1087  if(out){
1088  ChHist[ec][st][rg][ch].digiAppearanceCount->Fill(1);
1089  }
1090  }
1091  else{
1092  if(out){
1093  ChHist[ec][st][rg][ch].digiAppearanceCount->Fill(0);
1094  }
1095  }
1096 
1097  if(useDigis){
1098  // ALCTs
1099  firstCondition = allALCT[ec][st][rg][ch];
1100  secondCondition = false;
1101  if(secondRing>-1){
1102  secondCondition = allALCT[ec][st][secondRing][ch];
1103  }
1104  if(firstCondition || secondCondition){
1105  if(out){
1106  ChHist[ec][st][rg][ch].digiAppearanceCount->Fill(3);
1107  }
1108  // always apply partial angle cuts for this kind of histos
1109  if(fabs(dxdz)<local_DX_DZ_Max){
1110  StHist[ec][st].EfficientALCT_momTheta->Fill(ftsChamber.momentum().theta());
1111  ChHist[ec][st][rg][ch].EfficientALCT_dydz->Fill(dydz);
1112  }
1113  }
1114  else{
1115  if(out){
1116  ChHist[ec][st][rg][ch].digiAppearanceCount->Fill(2);
1117  }
1118  if(fabs(dxdz)<local_DX_DZ_Max){
1119  StHist[ec][st].InefficientALCT_momTheta->Fill(ftsChamber.momentum().theta());
1120  ChHist[ec][st][rg][ch].InefficientALCT_dydz->Fill(dydz);
1121  }
1122  if(printalot){
1123  std::cout<<" missing ALCT (dy/dz = "<<dydz<<")";
1124  printf("\t\tendcap/station/ring/chamber: %i/%i/%i/%i\n",ec+1,st+1,rg+1,ch+1);
1125  }
1126  }
1127 
1128  // CLCTs
1129  firstCondition = allCLCT[ec][st][rg][ch];
1130  secondCondition = false;
1131  if(secondRing>-1){
1132  secondCondition = allCLCT[ec][st][secondRing][ch];
1133  }
1134  if(firstCondition || secondCondition){
1135  if(out){
1136  ChHist[ec][st][rg][ch].digiAppearanceCount->Fill(5);
1137  }
1138  if(dydz<local_DY_DZ_Max && dydz>local_DY_DZ_Min){
1139  StHist[ec][st].EfficientCLCT_momPhi->Fill(ftsChamber.momentum().phi() );// - phi chamber...
1140  ChHist[ec][st][rg][ch].EfficientCLCT_dxdz->Fill(dxdz);
1141  }
1142  }
1143  else{
1144  if(out){
1145  ChHist[ec][st][rg][ch].digiAppearanceCount->Fill(4);
1146  }
1147  if(dydz<local_DY_DZ_Max && dydz>local_DY_DZ_Min){
1148  StHist[ec][st].InefficientCLCT_momPhi->Fill(ftsChamber.momentum().phi());// - phi chamber...
1149  ChHist[ec][st][rg][ch].InefficientCLCT_dxdz->Fill(dxdz);
1150  }
1151  if(printalot){
1152  std::cout<<" missing CLCT (dx/dz = "<<dxdz<<")";
1153  printf("\t\tendcap/station/ring/chamber: %i/%i/%i/%i\n",ec+1,st+1,rg+1,ch+1);
1154  }
1155  }
1156  if(out){
1157  // CorrLCTs
1158  firstCondition = allCorrLCT[ec][st][rg][ch];
1159  secondCondition = false;
1160  if(secondRing>-1){
1161  secondCondition = allCorrLCT[ec][st][secondRing][ch];
1162  }
1163  if(firstCondition || secondCondition){
1164  ChHist[ec][st][rg][ch].digiAppearanceCount->Fill(7);
1165  }
1166  else{
1167  ChHist[ec][st][rg][ch].digiAppearanceCount->Fill(6);
1168  }
1169  }
1170  }
1171  return out;
1172 }
1173 
1174 //
1176  int ec, st, rg, ch, secondRing;
1177  returnTypes(id, ec, st, rg, ch, secondRing);
1178 
1179  bool firstCondition, secondCondition;
1180  int missingLayers_s = 0;
1181  int missingLayers_wg = 0;
1182  for(int iLayer=0;iLayer<6;iLayer++){
1183  //----Strips
1184  if(printalot){
1185  printf("\t%i swEff: \tendcap/station/ring/chamber/layer: %i/%i/%i/%i/%i\n",
1186  iLayer + 1,id.endcap(),id.station(),id.ring(),id.chamber(),iLayer+1);
1187  std::cout<<" size S = "<<allStrips[id.endcap()-1][id.station()-1][id.ring()-1][id.chamber()-FirstCh][iLayer].size()<<
1188  "size W = "<<allWG[id.endcap()-1][id.station()-1][id.ring()-1][id.chamber()-FirstCh][iLayer].size()<<std::endl;
1189 
1190  }
1191  firstCondition = allStrips[ec][st][rg][ch][iLayer].size() ? true : false;
1192  //allSegments[ec][st][rg][ch].size() ? true : false;
1193  secondCondition = false;
1194  if(secondRing>-1){
1195  secondCondition = allStrips[ec][st][secondRing][ch][iLayer].size() ? true : false;
1196  }
1197  if(firstCondition || secondCondition){
1198  ChHist[ec][st][rg][ch].EfficientStrips->Fill(iLayer+1);
1199  }
1200  else{
1201  if(printalot){
1202  std::cout<<"missing strips ";
1203  printf("\t\tendcap/station/ring/chamber/layer: %i/%i/%i/%i/%i\n",id.endcap(),id.station(),id.ring(),id.chamber(),iLayer+1);
1204  }
1205  }
1206  // Wires
1207  firstCondition = allWG[ec][st][rg][ch][iLayer].size() ? true : false;
1208  secondCondition = false;
1209  if(secondRing>-1){
1210  secondCondition = allWG[ec][st][secondRing][ch][iLayer].size() ? true : false;
1211  }
1212  if(firstCondition || secondCondition){
1213  ChHist[ec][st][rg][ch].EfficientWireGroups->Fill(iLayer+1);
1214  }
1215  else{
1216  if(printalot){
1217  std::cout<<"missing wires ";
1218  printf("\t\tendcap/station/ring/chamber/layer: %i/%i/%i/%i/%i\n",id.endcap(),id.station(),id.ring(),id.chamber(),iLayer+1);
1219  }
1220  }
1221  }
1222  // Normalization
1223  if(6!=missingLayers_s){
1224  ChHist[ec][st][rg][ch].EfficientStrips->Fill(8);
1225  }
1226  if(6!=missingLayers_wg){
1227  ChHist[ec][st][rg][ch].EfficientWireGroups->Fill(8);
1228  }
1229  ChHist[ec][st][rg][ch].EfficientStrips->Fill(9);
1230  ChHist[ec][st][rg][ch].EfficientWireGroups->Fill(9);
1231 //
1232  ChHist[ec][st][rg][ch].StripWiresCorrelations->Fill(1);
1233  if(missingLayers_s!=missingLayers_wg){
1234  ChHist[ec][st][rg][ch].StripWiresCorrelations->Fill(2);
1235  if(6==missingLayers_wg){
1236  ChHist[ec][st][rg][ch].StripWiresCorrelations->Fill(3);
1237  ChHist[ec][st][rg][ch].NoWires_momTheta->Fill(ftsChamber.momentum().theta());
1238  }
1239  if(6==missingLayers_s){
1240  ChHist[ec][st][rg][ch].StripWiresCorrelations->Fill(4);
1241  ChHist[ec][st][rg][ch].NoStrips_momPhi->Fill(ftsChamber.momentum().theta());
1242  }
1243  }
1244  else if(6==missingLayers_s){
1245  ChHist[ec][st][rg][ch].StripWiresCorrelations->Fill(5);
1246  }
1247 
1248  return true;
1249 }
1250 //
1252  int ec, st, rg, ch, secondRing;
1253  returnTypes(id, ec, st, rg, ch, secondRing);
1254  bool firstCondition, secondCondition;
1255  for(int iLayer=0; iLayer<6;iLayer++){
1256  firstCondition = allSimhits[ec][st][rg][ch][iLayer].size() ? true : false;
1257  secondCondition = false;
1258  int thisRing = rg;
1259  if(secondRing>-1){
1260  secondCondition = allSimhits[ec][st][secondRing][ch][iLayer].size() ? true : false;
1261  if(secondCondition){
1262  thisRing = secondRing;
1263  }
1264  }
1265  if(firstCondition || secondCondition){
1266  for(size_t iSH=0;
1267  iSH<allSimhits[ec][st][thisRing][ch][iLayer].size();
1268  ++iSH){
1269  if(13 ==
1270  fabs(allSimhits[ec][st][thisRing][ch][iLayer][iSH].second)){
1271  ChHist[ec][st][rg][ch].SimSimhits->Fill(iLayer+1);
1272  if(allRechits[ec][st][thisRing][ch][iLayer].size()){
1273  ChHist[ec][st][rg][ch].SimRechits->Fill(iLayer+1);
1274  }
1275  break;
1276  }
1277  }
1278  //---- Next is not too usefull...
1279  /*
1280  for(unsigned int iSimHits=0;
1281  iSimHits<allSimhits[id.endcap()-1][id.station()-1][id.ring()-1][id.chamber()-FirstCh][iLayer].size();
1282  iSimHits++){
1283  ChHist[ec][st][rg][id.chamber()-FirstCh].SimSimhits_each->Fill(iLayer+1);
1284  }
1285  for(unsigned int iRecHits=0;
1286  iRecHits<allRechits[id.endcap()-1][id.station()-1][id.ring()-1][id.chamber()-FirstCh][iLayer].size();
1287  iRecHits++){
1288  ChHist[ec][st][rg][id.chamber()-FirstCh].SimRechits_each->Fill(iLayer+1);
1289  }
1290  */
1291  //
1292  }
1293  }
1294  return true;
1295 }
1296 
1297 //
1299  int ec, st, rg, ch, secondRing;
1300  returnTypes(id, ec, st, rg, ch, secondRing);
1301  bool firstCondition, secondCondition;
1302 
1303  std::vector <bool> missingLayers_rh(6);
1304  std::vector <int> usedInSegment(6);
1305  // Rechits
1306  if(printalot) std::cout<<"RecHits eff"<<std::endl;
1307  for(int iLayer=0;iLayer<6;++iLayer){
1308  firstCondition = allRechits[ec][st][rg][ch][iLayer].size() ? true : false;
1309  secondCondition = false;
1310  int thisRing = rg;
1311  if(secondRing>-1){
1312  secondCondition = allRechits[ec][st][secondRing][ch][iLayer].size() ? true : false;
1313  if(secondCondition){
1314  thisRing = secondRing;
1315  }
1316  }
1317  if(firstCondition || secondCondition){
1318  ChHist[ec][st][rg][ch].EfficientRechits_good->Fill(iLayer+1);
1319  for(size_t iR=0;
1320  iR<allRechits[ec][st][thisRing][ch][iLayer].size();
1321  ++iR){
1322  if(allRechits[ec][st][thisRing][ch][iLayer][iR].second){
1323  usedInSegment[iLayer] = 1;
1324  break;
1325  }
1326  else{
1327  usedInSegment[iLayer] = -1;
1328  }
1329  }
1330  }
1331  else{
1332  missingLayers_rh[iLayer] = true;
1333  if(printalot){
1334  std::cout<<"missing rechits ";
1335  printf("\t\tendcap/station/ring/chamber/layer: %i/%i/%i/%i/%i\n",id.endcap(),id.station(),id.ring(),id.chamber(),iLayer+1);
1336  }
1337  }
1338  }
1339  GlobalVector globalDir;
1340  GlobalPoint globalPos;
1341  // Segments
1342  firstCondition = allSegments[ec][st][rg][ch].size() ? true : false;
1343  secondCondition = false;
1344  int secondSize = 0;
1345  int thisRing = rg;
1346  if(secondRing>-1){
1347  secondCondition = allSegments[ec][st][secondRing][ch].size() ? true : false;
1348  secondSize = allSegments[ec][st][secondRing][ch].size();
1349  if(secondCondition){
1350  thisRing = secondRing;
1351  }
1352  }
1353  if(firstCondition || secondCondition){
1354  if (printalot) std::cout<<"segments - start ec = "<<ec<<" st = "<<st<<" rg = "<<rg<<" ch = "<<ch<<std::endl;
1355  StHist[ec][st].EfficientSegments_XY->Fill(ftsChamber.position().x(),ftsChamber.position().y());
1356  if(1==allSegments[ec][st][rg][ch].size() + secondSize){
1357  globalDir = cscChamber->toGlobal(allSegments[ec][st][thisRing][ch][0].second);
1358  globalPos = cscChamber->toGlobal(allSegments[ec][st][thisRing][ch][0].first);
1359  StHist[ec][st].EfficientSegments_eta->Fill(fabs(ftsChamber.position().eta()));
1360  double residual = sqrt(pow(ftsChamber.position().x() - globalPos.x(),2)+
1361  pow(ftsChamber.position().y() - globalPos.y(),2)+
1362  pow(ftsChamber.position().z() - globalPos.z(),2));
1363  if (printalot) std::cout<<" fts.position() = "<<ftsChamber.position()<<" segPos = "<<globalPos<<" res = "<<residual<< std::endl;
1364  StHist[ec][st].ResidualSegments->Fill(residual);
1365  }
1366  for(int iLayer=0;iLayer<6;++iLayer){
1367  if(printalot) std::cout<<" iLayer = "<<iLayer<<" usedInSegment = "<<usedInSegment[iLayer]<<std::endl;
1368  if(0!=usedInSegment[iLayer]){
1369  if(-1==usedInSegment[iLayer]){
1370  ChHist[ec][st][rg][ch].InefficientSingleHits->Fill(iLayer+1);
1371  }
1372  ChHist[ec][st][rg][ch].AllSingleHits->Fill(iLayer+1);
1373  }
1374  firstCondition = allRechits[ec][st][rg][ch][iLayer].size() ? true : false;
1375  secondCondition = false;
1376  if(secondRing>-1){
1377  secondCondition = allRechits[ec][st][secondRing][ch][iLayer].size() ? true : false;
1378  }
1379  float stripAngle = 99999.;
1380  std::vector<float> posXY(2);
1381  bool oneSegment = false;
1382  if(1==allSegments[ec][st][rg][ch].size() + secondSize){
1383  oneSegment = true;
1384  const BoundPlane bp = cscChamber->layer(iLayer+1)->surface();
1385  linearExtrapolation(globalPos,globalDir, bp.position().z(), posXY);
1386  GlobalPoint gp_extrapol( posXY.at(0), posXY.at(1),bp.position().z());
1387  const LocalPoint lp_extrapol = cscChamber->layer(iLayer+1)->toLocal(gp_extrapol);
1388  posXY.at(0) = lp_extrapol.x();
1389  posXY.at(1) = lp_extrapol.y();
1390  int nearestStrip = cscChamber->layer(iLayer+1)->geometry()->nearestStrip(lp_extrapol);
1391  stripAngle = cscChamber->layer(iLayer+1)->geometry()->stripAngle(nearestStrip) - M_PI/2. ;
1392  }
1393  if(firstCondition || secondCondition){
1394  ChHist[ec][st][rg][ch].EfficientRechits_inSegment->Fill(iLayer+1);
1395  if(oneSegment){
1396  ChHist[ec][st][rg][ch].Y_EfficientRecHits_inSegment[iLayer]->Fill(posXY.at(1));
1397  ChHist[ec][st][rg][ch].Phi_EfficientRecHits_inSegment[iLayer]->Fill(stripAngle);
1398  }
1399  }
1400  else{
1401  if(oneSegment){
1402  ChHist[ec][st][rg][ch].Y_InefficientRecHits_inSegment[iLayer]->Fill(posXY.at(1));
1403  ChHist[ec][st][rg][ch].Phi_InefficientRecHits_inSegment[iLayer]->Fill(stripAngle);
1404  }
1405  }
1406  }
1407  }
1408  else{
1409  StHist[ec][st].InefficientSegments_XY->Fill(ftsChamber.position().x(),ftsChamber.position().y());
1410  if(printalot){
1411  std::cout<<"missing segment "<<std::endl;
1412  printf("\t\tendcap/station/ring/chamber: %i/%i/%i/%i\n",id.endcap(),id.station(),id.ring(),id.chamber());
1413  std::cout<<" fts.position() = "<<ftsChamber.position()<<std::endl;
1414  }
1415  }
1416  // Normalization
1417  ChHist[ec][st][rg][ch].EfficientRechits_good->Fill(8);
1418  if(allSegments[ec][st][rg][ch].size()+secondSize<2){
1419  StHist[ec][st].AllSegments_eta->Fill(fabs(ftsChamber.position().eta()));
1420  }
1421  ChHist[ec][st][rg][id.chamber()-FirstCh].EfficientRechits_inSegment->Fill(9);
1422 
1423  return true;
1424 }
1425 //
1426 void CSCEfficiency::returnTypes(CSCDetId & id, int &ec, int &st, int &rg, int &ch, int &secondRing){
1427  ec = id.endcap()-1;
1428  st = id.station()-1;
1429  rg = id.ring()-1;
1430  secondRing = -1;
1431  if(1==id.station() && (4==id.ring() || 1==id.ring()) ){
1432  rg = 0;
1433  secondRing = 3;
1434  }
1435  ch = id.chamber()-FirstCh;
1436 }
1437 
1438 //
1440  CLHEP::Hep3Vector& p3, CLHEP::Hep3Vector& r3,
1441  int& charge, AlgebraicSymMatrix66& cov){
1442 
1443  GlobalVector p3GV = fts.momentum();
1444  GlobalPoint r3GP = fts.position();
1445 
1446  p3.set(p3GV.x(), p3GV.y(), p3GV.z());
1447  r3.set(r3GP.x(), r3GP.y(), r3GP.z());
1448 
1449  charge = fts.charge();
1450  cov = fts.hasError() ? fts.cartesianError().matrix() : AlgebraicSymMatrix66();
1451 
1452 }
1453 
1454 FreeTrajectoryState CSCEfficiency::getFromCLHEP(const CLHEP::Hep3Vector& p3, const CLHEP::Hep3Vector& r3,
1455  int charge, const AlgebraicSymMatrix66& cov,
1456  const MagneticField* field){
1457 
1458  GlobalVector p3GV(p3.x(), p3.y(), p3.z());
1459  GlobalPoint r3GP(r3.x(), r3.y(), r3.z());
1460  GlobalTrajectoryParameters tPars(r3GP, p3GV, charge, field);
1461 
1462  CartesianTrajectoryError tCov(cov);
1463 
1464  return cov.kRows == 6 ? FreeTrajectoryState(tPars, tCov) : FreeTrajectoryState(tPars) ;
1465 }
1466 
1467 void CSCEfficiency::linearExtrapolation(GlobalPoint initialPosition ,GlobalVector initialDirection,
1468  float zSurface, std::vector <float> &posZY){
1469  double paramLine = lineParameter(initialPosition.z(), zSurface, initialDirection.z());
1470  double xPosition = extrapolate1D(initialPosition.x(), initialDirection.x(),paramLine);
1471  double yPosition = extrapolate1D(initialPosition.y(), initialDirection.y(),paramLine);
1472  posZY.clear();
1473  posZY.push_back(xPosition);
1474  posZY.push_back(yPosition);
1475 }
1476 //
1477 double CSCEfficiency::extrapolate1D(double initPosition, double initDirection, double parameterOfTheLine){
1478  double extrapolatedPosition = initPosition + initDirection*parameterOfTheLine;
1479  return extrapolatedPosition;
1480 }
1481 //
1482 double CSCEfficiency::lineParameter(double initZPosition, double destZPosition, double initZDirection){
1483  double paramLine = (destZPosition-initZPosition)/initZDirection;
1484  return paramLine;
1485 }
1486 //
1487 void CSCEfficiency::chooseDirection(CLHEP::Hep3Vector & innerPosition, CLHEP::Hep3Vector & outerPosition){
1488 
1489  //---- Be careful with trigger conditions too
1490  if(!isIPdata){
1491  float dy = outerPosition.y() - innerPosition.y();
1492  float dz = outerPosition.z() - innerPosition.z();
1493  if(isBeamdata){
1494  if(dz>0){
1495  alongZ = true;
1496  }
1497  else{
1498  alongZ = false;
1499  }
1500  }
1501  else{//cosmics
1502  if(dy/dz>0){
1503  alongZ = false;
1504  }
1505  else{
1506  alongZ = true;
1507  }
1508  }
1509  }
1510 }
1511 //
1512 const Propagator* CSCEfficiency::propagator(std::string propagatorName) const {
1513  return &*theService->propagator(propagatorName);
1514 }
1515 
1516 //
1518  TrajectoryStateOnSurface tSOSDest;
1519  std::string propagatorName;
1520 /*
1521 // it would work if cosmic muons had properly assigned direction...
1522  bool dzPositive = bpDest.position().z() - ftsStart.position().z() > 0 ? true : false;
1523  //---- Be careful with trigger conditions too
1524  if(!isIPdata){
1525  bool rightDirection = !(alongZ^dzPositive);
1526  if(rightDirection){
1527  if(printalot) std::cout<<" propagate along momentum"<<std::endl;
1528  propagatorName = "SteppingHelixPropagatorAlong";
1529  }
1530  else{
1531  if(printalot) std::cout<<" propagate opposite momentum"<<std::endl;
1532  propagatorName = "SteppingHelixPropagatorOpposite";
1533  }
1534  }
1535  else{
1536  if(printalot) std::cout<<" propagate any (momentum)"<<std::endl;
1537  propagatorName = "SteppingHelixPropagatorAny";
1538  }
1539 */
1540  propagatorName = "SteppingHelixPropagatorAny";
1541  tSOSDest = propagator(propagatorName)->propagate(ftsStart, bpDest);
1542  return tSOSDest;
1543 }
1544 //
1546  const edm::TriggerNames & triggerNames){
1547  bool triggerPassed = true;
1548  std::vector<std::string> hlNames=triggerNames.triggerNames();
1549  pointToTriggers.clear();
1550  for(size_t imyT = 0;imyT<myTriggers.size();++imyT){
1551  for (size_t iT=0; iT<hlNames.size(); ++iT) {
1552  //std::cout<<" iT = "<<iT<<" hlNames[iT] = "<<hlNames[iT]<<
1553  //" : wasrun = "<<hltR->wasrun(iT)<<" accept = "<<
1554  // hltR->accept(iT)<<" !error = "<<
1555  // !hltR->error(iT)<<std::endl;
1556  if(!imyT){
1557  if(hltR->wasrun(iT) &&
1558  hltR->accept(iT) &&
1559  !hltR->error(iT) ){
1560  TriggersFired->Fill(iT);
1561  }
1562  }
1563  if(hlNames[iT]==myTriggers[imyT]){
1564  pointToTriggers.push_back(iT);
1565  if(imyT){
1566  break;
1567  }
1568  }
1569  }
1570  }
1571  if(pointToTriggers.size()!=myTriggers.size()){
1572  pointToTriggers.clear();
1573  if(printalot){
1574  std::cout<<" Not all trigger names found - all trigger specifications will be ignored. Check your cfg file!"<<std::endl;
1575  }
1576  }
1577  else{
1578  if(pointToTriggers.size()){
1579  if(printalot){
1580  std::cout<<"The following triggers will be required in the event: "<<std::endl;
1581  for(size_t imyT =0; imyT <pointToTriggers.size();++imyT){
1582  std::cout<<" "<<hlNames[pointToTriggers[imyT]];
1583  }
1584  std::cout<<std::endl;
1585  std::cout<<" in condition (AND/OR) : "<<!andOr<<"/"<<andOr<<std::endl;
1586  }
1587  }
1588  }
1589 
1590  if (hltR.isValid()) {
1591  if(!pointToTriggers.size()){
1592  if(printalot){
1593  std::cout<<" No triggers specified in the configuration or all ignored - no trigger information will be considered"<<std::endl;
1594  }
1595  }
1596  for(size_t imyT =0; imyT <pointToTriggers.size();++imyT){
1597  if(hltR->wasrun(pointToTriggers[imyT]) &&
1598  hltR->accept(pointToTriggers[imyT]) &&
1599  !hltR->error(pointToTriggers[imyT]) ){
1600  triggerPassed = true;
1601  if(andOr){
1602  break;
1603  }
1604  }
1605  else{
1606  triggerPassed = false;
1607  if(!andOr){
1608  triggerPassed = false;
1609  break;
1610  }
1611  }
1612  }
1613  }
1614  else{
1615  if(printalot){
1616  std::cout<<" TriggerResults handle returns invalid state?! No trigger information will be considered"<<std::endl;
1617  }
1618  }
1619  if(printalot){
1620  std::cout<<" Trigger passed: "<<triggerPassed<<std::endl;
1621  }
1622  return triggerPassed;
1623 }
1624 //
1625 
1626 // Constructor
1628 
1629  // const float Xmin = -70;
1630  //const float Xmax = 70;
1631  //const int nXbins = int(4.*(Xmax - Xmin));
1632  const float Ymin = -165;
1633  const float Ymax = 165;
1634  const int nYbins = int((Ymax - Ymin)/2);
1635  const float Layer_min = -0.5;
1636  const float Layer_max = 9.5;
1637  const int nLayer_bins = int(Layer_max - Layer_min);
1638  //
1639 
1640  //---- Get the input parameters
1641  printout_NEvents = pset.getUntrackedParameter<unsigned int>("printout_NEvents",0);
1642  rootFileName = pset.getUntrackedParameter<string>("rootFileName","cscHists.root");
1643 
1644  isData = pset.getUntrackedParameter<bool>("runOnData",true);//
1645  isIPdata = pset.getUntrackedParameter<bool>("IPdata",false);//
1646  isBeamdata = pset.getUntrackedParameter<bool>("Beamdata",false);//
1647  getAbsoluteEfficiency = pset.getUntrackedParameter<bool>("getAbsoluteEfficiency",true);//
1648  useDigis = pset.getUntrackedParameter<bool>("useDigis", true);//
1649  distanceFromDeadZone = pset.getUntrackedParameter<double>("distanceFromDeadZone", 10.);//
1650  minP = pset.getUntrackedParameter<double>("minP",20.);//
1651  maxP = pset.getUntrackedParameter<double>("maxP",100.);//
1652  maxNormChi2 = pset.getUntrackedParameter<double>("maxNormChi2", 3.);//
1653  minTrackHits = pset.getUntrackedParameter<unsigned int>("minTrackHits",10);//
1654 
1655  applyIPangleCuts = pset.getUntrackedParameter<bool>("applyIPangleCuts", false);//
1656  local_DY_DZ_Max = pset.getUntrackedParameter<double>("local_DY_DZ_Max",-0.1);//
1657  local_DY_DZ_Min = pset.getUntrackedParameter<double>("local_DY_DZ_Min",-0.8);//
1658  local_DX_DZ_Max = pset.getUntrackedParameter<double>("local_DX_DZ_Max",0.2);//
1659 
1660  alctDigiTag_ = pset.getParameter<edm::InputTag>("alctDigiTag") ;
1661  clctDigiTag_ = pset.getParameter<edm::InputTag>("clctDigiTag") ;
1662  corrlctDigiTag_ = pset.getParameter<edm::InputTag>("corrlctDigiTag") ;
1663  stripDigiTag_ = pset.getParameter<edm::InputTag>("stripDigiTag") ;
1664  wireDigiTag_ = pset.getParameter<edm::InputTag>("wireDigiTag") ;
1665  rechitDigiTag_ = pset.getParameter<edm::InputTag>("rechitDigiTag") ;
1666  segmentDigiTag_ = pset.getParameter<edm::InputTag>("segmentDigiTag") ;
1667  simHitTag = pset.getParameter<edm::InputTag>("simHitTag");
1668  tracksTag = pset.getParameter< edm::InputTag >("tracksTag");
1669 
1670  ParameterSet serviceParameters = pset.getParameter<ParameterSet>("ServiceParameters");
1671  // maybe use the service for getting magnetic field, propagators, etc. ...
1672  theService = new MuonServiceProxy(serviceParameters);
1673 
1674  // Trigger
1675  useTrigger = pset.getUntrackedParameter<bool>("useTrigger", false);
1676  hlTriggerResults_ = pset.getParameter<edm::InputTag> ("HLTriggerResults");
1677  myTriggers = pset.getParameter<std::vector <std::string> >("myTriggers");
1678  andOr = pset.getUntrackedParameter<bool>("andOr");
1679  pointToTriggers.clear();
1680 
1681 
1682  //---- set counter to zero
1683  nEventsAnalyzed = 0;
1684  //---- set presence of magnetic field
1685  magField = true;
1686  //
1687  std::string Path = "AllChambers/";
1688  std::string FullName;
1689  //---- File with output histograms
1690  theFile = new TFile(rootFileName.c_str(), "RECREATE");
1691  theFile->cd();
1692  //---- Book histograms for the analysis
1693  char SpecName[50];
1694 
1695  sprintf(SpecName,"DataFlow");
1696  DataFlow =
1697  new TH1F(SpecName,"Data flow;condition number;entries",40,-0.5,39.5);
1698  //
1699  sprintf(SpecName,"TriggersFired");
1700  TriggersFired =
1701  new TH1F(SpecName,"Triggers fired;trigger number;entries",140,-0.5,139.5);
1702  //
1703  int Chan = 50;
1704  float minChan = -0.5;
1705  float maxChan = 49.5;
1706  //
1707  sprintf(SpecName,"ALCTPerEvent");
1708  ALCTPerEvent = new TH1F(SpecName,"ALCTs per event;N digis;entries",Chan,minChan,maxChan);
1709  //
1710  sprintf(SpecName,"CLCTPerEvent");
1711  CLCTPerEvent = new TH1F(SpecName,"CLCTs per event;N digis;entries",Chan,minChan,maxChan);
1712  //
1713  sprintf(SpecName,"recHitsPerEvent");
1714  recHitsPerEvent = new TH1F(SpecName,"RecHits per event;N digis;entries",150,-0.5,149.5);
1715  //
1716  sprintf(SpecName,"segmentsPerEvent");
1717  segmentsPerEvent = new TH1F(SpecName,"segments per event;N digis;entries",Chan,minChan,maxChan);
1718  //
1719  //---- Book groups of histograms (for any chamber)
1720 
1721  map<std::string,bool>::iterator iter;
1722  for(int ec = 0;ec<2;++ec){
1723  for(int st = 0;st<4;++st){
1724  theFile->cd();
1725  sprintf(SpecName,"Stations__E%d_S%d",ec+1, st+1);
1726  theFile->mkdir(SpecName);
1727  theFile->cd(SpecName);
1728 
1729  //
1730  sprintf(SpecName,"segmentChi2_ndf_St%d",st+1);
1731  StHist[ec][st].segmentChi2_ndf =
1732  new TH1F(SpecName,"Chi2/ndf of a segment;chi2/ndf;entries",100,0.,20.);
1733  //
1734  sprintf(SpecName,"hitsInSegment_St%d",st+1);
1735  StHist[ec][st].hitsInSegment =
1736  new TH1F(SpecName,"Number of hits in a segment;nHits;entries",7,-0.5,6.5);
1737  //
1738  Chan = 170;
1739  minChan = 0.85;
1740  maxChan = 2.55;
1741  //
1742  sprintf(SpecName,"AllSegments_eta_St%d",st+1);
1743  StHist[ec][st].AllSegments_eta =
1744  new TH1F(SpecName,"All segments in eta;eta;entries",Chan,minChan,maxChan);
1745  //
1746  sprintf(SpecName,"EfficientSegments_eta_St%d",st+1);
1747  StHist[ec][st].EfficientSegments_eta =
1748  new TH1F(SpecName,"Efficient segments in eta;eta;entries",Chan,minChan,maxChan);
1749  //
1750  sprintf(SpecName,"ResidualSegments_St%d",st+1);
1751  StHist[ec][st].ResidualSegments =
1752  new TH1F(SpecName,"Residual (segments);residual,cm;entries",75,0.,15.);
1753  //
1754  Chan = 200;
1755  minChan = -800.;
1756  maxChan = 800.;
1757  int Chan2 = 200;
1758  float minChan2 = -800.;
1759  float maxChan2 = 800.;
1760 
1761  sprintf(SpecName,"EfficientSegments_XY_St%d",st+1);
1762  StHist[ec][st].EfficientSegments_XY = new TH2F(SpecName,"Efficient segments in XY;X;Y",
1763  Chan,minChan,maxChan,Chan2,minChan2,maxChan2);
1764  sprintf(SpecName,"InefficientSegments_XY_St%d",st+1);
1765  StHist[ec][st].InefficientSegments_XY = new TH2F(SpecName,"Inefficient segments in XY;X;Y",
1766  Chan,minChan,maxChan,Chan2,minChan2,maxChan2);
1767  //
1768  Chan = 80;
1769  minChan = 0;
1770  maxChan = 3.2;
1771  sprintf(SpecName,"EfficientALCT_momTheta_St%d",st+1);
1772  StHist[ec][st].EfficientALCT_momTheta = new TH1F(SpecName,"Efficient ALCT in theta (momentum);theta, rad;entries",
1773  Chan,minChan,maxChan);
1774  //
1775  sprintf(SpecName,"InefficientALCT_momTheta_St%d",st+1);
1776  StHist[ec][st].InefficientALCT_momTheta = new TH1F(SpecName,"Inefficient ALCT in theta (momentum);theta, rad;entries",
1777  Chan,minChan,maxChan);
1778  //
1779  Chan = 160;
1780  minChan = -3.2;
1781  maxChan = 3.2;
1782  sprintf(SpecName,"EfficientCLCT_momPhi_St%d",st+1);
1783  StHist[ec][st].EfficientCLCT_momPhi = new TH1F(SpecName,"Efficient CLCT in phi (momentum);phi, rad;entries",
1784  Chan,minChan,maxChan);
1785  //
1786  sprintf(SpecName,"InefficientCLCT_momPhi_St%d",st+1);
1787  StHist[ec][st].InefficientCLCT_momPhi = new TH1F(SpecName,"Inefficient CLCT in phi (momentum);phi, rad;entries",
1788  Chan,minChan,maxChan);
1789  //
1790  theFile->cd();
1791  for(int rg = 0;rg<3;++rg){
1792  if(0!=st && rg>1){
1793  continue;
1794  }
1795  else if(1==rg && 3==st){
1796  continue;
1797  }
1798  for(int iChamber=FirstCh;iChamber<FirstCh+NumCh;iChamber++){
1799  if(0!=st && 0==rg && iChamber >18){
1800  continue;
1801  }
1802  theFile->cd();
1803  sprintf(SpecName,"Chambers__E%d_S%d_R%d_Chamber_%d",ec+1, st+1, rg+1,iChamber);
1804  theFile->mkdir(SpecName);
1805  theFile->cd(SpecName);
1806  //
1807 
1808  sprintf(SpecName,"EfficientRechits_inSegment_Ch%d",iChamber);
1809  ChHist[ec][st][rg][iChamber-FirstCh].EfficientRechits_inSegment =
1810  new TH1F(SpecName,"Existing RecHit given a segment;layers (1-6);entries",nLayer_bins,Layer_min,Layer_max);
1811  //
1812  sprintf(SpecName,"InefficientSingleHits_Ch%d",iChamber);
1813  ChHist[ec][st][rg][iChamber-FirstCh].InefficientSingleHits =
1814  new TH1F(SpecName,"Single RecHits not in the segment;layers (1-6);entries ",nLayer_bins,Layer_min,Layer_max);
1815  //
1816  sprintf(SpecName,"AllSingleHits_Ch%d",iChamber);
1817  ChHist[ec][st][rg][iChamber-FirstCh].AllSingleHits =
1818  new TH1F(SpecName,"Single RecHits given a segment; layers (1-6);entries",nLayer_bins,Layer_min,Layer_max);
1819  //
1820  sprintf(SpecName,"digiAppearanceCount_Ch%d",iChamber);
1821  ChHist[ec][st][rg][iChamber-FirstCh].digiAppearanceCount =
1822  new TH1F(SpecName,"Digi appearance (no-yes): segment(0,1), ALCT(2,3), CLCT(4,5), CorrLCT(6,7); digi type;entries",
1823  8,-0.5,7.5);
1824  //
1825  Chan = 100;
1826  minChan = -1.1;
1827  maxChan = 0.9;
1828  sprintf(SpecName,"EfficientALCT_dydz_Ch%d",iChamber);
1829  ChHist[ec][st][rg][iChamber-FirstCh].EfficientALCT_dydz =
1830  new TH1F(SpecName,"Efficient ALCT; local dy/dz (ME 3 and 4 flipped);entries",
1831  Chan, minChan, maxChan);
1832  //
1833  sprintf(SpecName,"InefficientALCT_dydz_Ch%d",iChamber);
1834  ChHist[ec][st][rg][iChamber-FirstCh].InefficientALCT_dydz =
1835  new TH1F(SpecName,"Inefficient ALCT; local dy/dz (ME 3 and 4 flipped);entries",
1836  Chan, minChan, maxChan);
1837  //
1838  Chan = 100;
1839  minChan = -1.;
1840  maxChan = 1.0;
1841  sprintf(SpecName,"EfficientCLCT_dxdz_Ch%d",iChamber);
1842  ChHist[ec][st][rg][iChamber-FirstCh].EfficientCLCT_dxdz =
1843  new TH1F(SpecName,"Efficient CLCT; local dxdz;entries",
1844  Chan, minChan, maxChan);
1845  //
1846  sprintf(SpecName,"InefficientCLCT_dxdz_Ch%d",iChamber);
1847  ChHist[ec][st][rg][iChamber-FirstCh].InefficientCLCT_dxdz =
1848  new TH1F(SpecName,"Inefficient CLCT; local dxdz;entries",
1849  Chan, minChan, maxChan);
1850  //
1851  sprintf(SpecName,"EfficientRechits_good_Ch%d",iChamber);
1852  ChHist[ec][st][rg][iChamber-FirstCh].EfficientRechits_good =
1853  new TH1F(SpecName,"Existing RecHit - sensitive area only;layers (1-6);entries",nLayer_bins,Layer_min,Layer_max);
1854  //
1855  sprintf(SpecName,"EfficientStrips_Ch%d",iChamber);
1856  ChHist[ec][st][rg][iChamber-FirstCh].EfficientStrips =
1857  new TH1F(SpecName,"Existing strip;layer (1-6); entries",nLayer_bins,Layer_min,Layer_max);
1858  //
1859  sprintf(SpecName,"EfficientWireGroups_Ch%d",iChamber);
1860  ChHist[ec][st][rg][iChamber-FirstCh].EfficientWireGroups =
1861  new TH1F(SpecName,"Existing WireGroups;layer (1-6); entries ",nLayer_bins,Layer_min,Layer_max);
1862  //
1863  sprintf(SpecName,"StripWiresCorrelations_Ch%d",iChamber);
1864  ChHist[ec][st][rg][iChamber-FirstCh].StripWiresCorrelations =
1865  new TH1F(SpecName,"StripWire correlations;; entries ",5,0.5,5.5);
1866  //
1867  Chan = 80;
1868  minChan = 0;
1869  maxChan = 3.2;
1870  sprintf(SpecName,"NoWires_momTheta_Ch%d",iChamber);
1871  ChHist[ec][st][rg][iChamber-FirstCh].NoWires_momTheta =
1872  new TH1F(SpecName,"No wires (all strips present) - in theta (momentum);theta, rad;entries",
1873  Chan,minChan,maxChan);
1874  //
1875  Chan = 160;
1876  minChan = -3.2;
1877  maxChan = 3.2;
1878  sprintf(SpecName,"NoStrips_momPhi_Ch%d",iChamber);
1879  ChHist[ec][st][rg][iChamber-FirstCh].NoStrips_momPhi =
1880  new TH1F(SpecName,"No strips (all wires present) - in phi (momentum);phi, rad;entries",
1881  Chan,minChan,maxChan);
1882  //
1883  for(int iLayer=0; iLayer<6;iLayer++){
1884  sprintf(SpecName,"Y_InefficientRecHits_inSegment_Ch%d_L%d",iChamber,iLayer);
1885  ChHist[ec][st][rg][iChamber-FirstCh].Y_InefficientRecHits_inSegment.push_back
1886  (new TH1F(SpecName,"Missing RecHit/layer in a segment (local system, whole chamber);Y, cm; entries",
1887  nYbins,Ymin, Ymax));
1888  //
1889  sprintf(SpecName,"Y_EfficientRecHits_inSegment_Ch%d_L%d",iChamber,iLayer);
1890  ChHist[ec][st][rg][iChamber-FirstCh].Y_EfficientRecHits_inSegment.push_back
1891  (new TH1F(SpecName,"Efficient (extrapolated from the segment) RecHit/layer in a segment (local system, whole chamber);Y, cm; entries",
1892  nYbins,Ymin, Ymax));
1893  //
1894  Chan = 200;
1895  minChan = -0.2;
1896  maxChan = 0.2;
1897  sprintf(SpecName,"Phi_InefficientRecHits_inSegment_Ch%d_L%d",iChamber,iLayer);
1898  ChHist[ec][st][rg][iChamber-FirstCh].Phi_InefficientRecHits_inSegment.push_back
1899  (new TH1F(SpecName,"Missing RecHit/layer in a segment (local system, whole chamber);Phi, rad; entries",
1900  Chan, minChan, maxChan));
1901  //
1902  sprintf(SpecName,"Phi_EfficientRecHits_inSegment_Ch%d_L%d",iChamber,iLayer);
1903  ChHist[ec][st][rg][iChamber-FirstCh].Phi_EfficientRecHits_inSegment.push_back
1904  (new TH1F(SpecName,"Efficient (extrapolated from the segment) in a segment (local system, whole chamber);Phi, rad; entries",
1905  Chan, minChan, maxChan));
1906 
1907  }
1908  //
1909  sprintf(SpecName,"Sim_Rechits_Ch%d",iChamber);
1910  ChHist[ec][st][rg][iChamber-FirstCh].SimRechits =
1911  new TH1F(SpecName,"Existing RecHit (Sim);layers (1-6);entries",nLayer_bins,Layer_min,Layer_max);
1912  //
1913  sprintf(SpecName,"Sim_Simhits_Ch%d",iChamber);
1914  ChHist[ec][st][rg][iChamber-FirstCh].SimSimhits =
1915  new TH1F(SpecName,"Existing SimHit (Sim);layers (1-6);entries",nLayer_bins,Layer_min,Layer_max);
1916  //
1917  /*
1918  sprintf(SpecName,"Sim_Rechits_each_Ch%d",iChamber);
1919  ChHist[ec][st][rg][iChamber-FirstCh].SimRechits_each =
1920  new TH1F(SpecName,"Existing RecHit (Sim), each;layers (1-6);entries",nLayer_bins,Layer_min,Layer_max);
1921  //
1922  sprintf(SpecName,"Sim_Simhits_each_Ch%d",iChamber);
1923  ChHist[ec][st][rg][iChamber-FirstCh].SimSimhits_each =
1924  new TH1F(SpecName,"Existing SimHit (Sim), each;layers (1-6);entries",nLayer_bins,Layer_min,Layer_max);
1925  */
1926  theFile->cd();
1927  }
1928  }
1929  }
1930  }
1931 }
1932 
1933 // Destructor
1935  if (theService) delete theService;
1936  // Write the histos to a file
1937  theFile->cd();
1938  //
1939  char SpecName[20];
1940  std::vector<float> bins, Efficiency, EffError;
1941  std::vector<float> eff(2);
1942 
1943  //---- loop over chambers
1944  std::map <std::string, bool> chamberTypes;
1945  chamberTypes["ME11"] = false;
1946  chamberTypes["ME12"] = false;
1947  chamberTypes["ME13"] = false;
1948  chamberTypes["ME21"] = false;
1949  chamberTypes["ME22"] = false;
1950  chamberTypes["ME31"] = false;
1951  chamberTypes["ME32"] = false;
1952  chamberTypes["ME41"] = false;
1953 
1954  map<std::string,bool>::iterator iter;
1955  std::cout<<" Writing proper histogram structure (patience)..."<<std::endl;
1956  for(int ec = 0;ec<2;++ec){
1957  for(int st = 0;st<4;++st){
1958  sprintf(SpecName,"Stations__E%d_S%d",ec+1, st+1);
1959  theFile->cd(SpecName);
1960  StHist[ec][st].segmentChi2_ndf->Write();
1961  StHist[ec][st].hitsInSegment->Write();
1962  StHist[ec][st].AllSegments_eta->Write();
1963  StHist[ec][st].EfficientSegments_eta->Write();
1964  StHist[ec][st].ResidualSegments->Write();
1965  StHist[ec][st].EfficientSegments_XY->Write();
1966  StHist[ec][st].InefficientSegments_XY->Write();
1967  StHist[ec][st].EfficientALCT_momTheta->Write();
1968  StHist[ec][st].InefficientALCT_momTheta->Write();
1969  StHist[ec][st].EfficientCLCT_momPhi->Write();
1970  StHist[ec][st].InefficientCLCT_momPhi->Write();
1971  for(int rg = 0;rg<3;++rg){
1972  if(0!=st && rg>1){
1973  continue;
1974  }
1975  else if(1==rg && 3==st){
1976  continue;
1977  }
1978  for(int iChamber=FirstCh;iChamber<FirstCh+NumCh;iChamber++){
1979  if(0!=st && 0==rg && iChamber >18){
1980  continue;
1981  }
1982  sprintf(SpecName,"Chambers__E%d_S%d_R%d_Chamber_%d",ec+1, st+1, rg+1,iChamber);
1983  theFile->cd(SpecName);
1984 
1985  ChHist[ec][st][rg][iChamber-FirstCh].EfficientRechits_inSegment->Write();
1986  ChHist[ec][st][rg][iChamber-FirstCh].AllSingleHits->Write();
1987  ChHist[ec][st][rg][iChamber-FirstCh].digiAppearanceCount->Write();
1988  ChHist[ec][st][rg][iChamber-FirstCh].EfficientALCT_dydz->Write();
1989  ChHist[ec][st][rg][iChamber-FirstCh].InefficientALCT_dydz->Write();
1990  ChHist[ec][st][rg][iChamber-FirstCh].EfficientCLCT_dxdz->Write();
1991  ChHist[ec][st][rg][iChamber-FirstCh].InefficientCLCT_dxdz->Write();
1992  ChHist[ec][st][rg][iChamber-FirstCh].InefficientSingleHits->Write();
1993  ChHist[ec][st][rg][iChamber-FirstCh].EfficientRechits_good->Write();
1994  ChHist[ec][st][rg][iChamber-FirstCh].EfficientStrips->Write();
1995  ChHist[ec][st][rg][iChamber-FirstCh].StripWiresCorrelations->Write();
1996  ChHist[ec][st][rg][iChamber-FirstCh].NoWires_momTheta->Write();
1997  ChHist[ec][st][rg][iChamber-FirstCh].NoStrips_momPhi->Write();
1998  ChHist[ec][st][rg][iChamber-FirstCh].EfficientWireGroups->Write();
1999  for(unsigned int iLayer = 0; iLayer< 6; iLayer++){
2000  ChHist[ec][st][rg][iChamber-FirstCh].Y_InefficientRecHits_inSegment[iLayer]->Write();
2001  ChHist[ec][st][rg][iChamber-FirstCh].Y_EfficientRecHits_inSegment[iLayer]->Write();
2002  ChHist[ec][st][rg][iChamber-FirstCh].Phi_InefficientRecHits_inSegment[iLayer]->Write();
2003  ChHist[ec][st][rg][iChamber-FirstCh].Phi_EfficientRecHits_inSegment[iLayer]->Write();
2004  }
2005  ChHist[ec][st][rg][iChamber-FirstCh].SimRechits->Write();
2006  ChHist[ec][st][rg][iChamber-FirstCh].SimSimhits->Write();
2007  /*
2008  ChHist[ec][st][rg][iChamber-FirstCh].SimRechits_each->Write();
2009  ChHist[ec][st][rg][iChamber-FirstCh].SimSimhits_each->Write();
2010  */
2011  //
2012  theFile->cd(SpecName);
2013  theFile->cd();
2014  }
2015  }
2016  }
2017  }
2018  //
2019  sprintf(SpecName,"AllChambers");
2020  theFile->mkdir(SpecName);
2021  theFile->cd(SpecName);
2022  DataFlow->Write();
2023  TriggersFired->Write();
2024  ALCTPerEvent->Write();
2025  CLCTPerEvent->Write();
2026  recHitsPerEvent->Write();
2027  segmentsPerEvent->Write();
2028  //
2029  theFile->cd(SpecName);
2030  //---- Close the file
2031  theFile->Close();
2032 }
2033 
2034 // ------------ method called once each job just before starting event loop ------------
2035 void
2037 {
2038 }
2039 
2040 // ------------ method called once each job just after ending the event loop ------------
2041 void
2043 }
2044 
2046 
double qoverp() const
q/p
Definition: TrackBase.h:115
double p() const
momentum vector magnitude
Definition: TrackBase.h:129
int chamber() const
Definition: CSCDetId.h:70
T getParameter(std::string const &) const
T getUntrackedParameter(std::string const &, T const &) const
int i
Definition: DBlmapReader.cc:9
float xx() const
Definition: LocalError.h:24
bool applyTrigger(edm::Handle< edm::TriggerResults > &hltR, const edm::TriggerNames &triggerNames)
virtual void beginJob()
CartesianTrajectoryError cartesianError() const
double normalizedChi2() const
chi-squared divided by n.d.o.f. (or chi-squared * 1e6 if n.d.o.f. is zero)
Definition: TrackBase.h:111
void fillWG_info(edm::Handle< CSCWireDigiCollection > &wires, edm::ESHandle< CSCGeometry > &cscGeom)
void chooseDirection(CLHEP::Hep3Vector &innerPosition, CLHEP::Hep3Vector &outerPosition)
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
void ringCandidates(int station, float absEta, std::map< std::string, bool > &chamberTypes)
double lineParameter(double initZPosition, double destZPosition, double initZDirection)
GlobalPoint toGlobal(const Local2DPoint &lp) const
Conversion to the global R.F. from the R.F. of the GeomDet.
Definition: GeomDet.h:47
ROOT::Math::SMatrix< double, 6, 6, ROOT::Math::MatRepSym< double, 6 > > AlgebraicSymMatrix66
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
T y() const
Definition: PV3DBase.h:63
#define abs(x)
Definition: mlp_lapack.h:159
LocalPoint toLocal(const GlobalPoint &gp) const
Conversion to the R.F. of the GeomDet.
Definition: GeomDet.h:62
bool recSimHitEfficiency(CSCDetId &id, FreeTrajectoryState &ftsChamber)
double phi() const
azimuthal angle of momentum vector
Definition: TrackBase.h:139
CSCEfficiency(const edm::ParameterSet &pset)
Constructor.
TrackCharge charge() const
virtual bool filter(edm::Event &event, const edm::EventSetup &eventSetup)
const math::XYZPoint & outerPosition() const
position of the outermost hit
Definition: Track.h:47
int layer() const
Definition: CSCDetId.h:63
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:35
double charge(const std::vector< uint8_t > &Ampls)
Strings const & triggerNames() const
Definition: TriggerNames.cc:24
virtual ~CSCEfficiency()
Destructor.
void returnTypes(CSCDetId &id, int &ec, int &st, int &rg, int &ch, int &secondRing)
float yOfWireGroup(int wireGroup, float x=0.) const
float caloCompatibility(const reco::Muon &muon)
FreeTrajectoryState getFromCLHEP(const CLHEP::Hep3Vector &p3, const CLHEP::Hep3Vector &r3, int charge, const AlgebraicSymMatrix66 &cov, const MagneticField *field)
std::string dumpMuonId(const DetId &id) const
Geom::Theta< T > theta() const
Definition: PV3DBase.h:75
std::string dumpFTS(const FreeTrajectoryState &fts) const
const math::XYZPoint & innerPosition() const
position of the innermost hit
Definition: Track.h:42
int endcap() const
Definition: CSCDetId.h:95
U second(std::pair< T, U > const &p)
C::const_iterator const_iterator
constant access iterator type
Definition: RangeMap.h:45
float xy() const
Definition: LocalError.h:25
int iEvent
Definition: GenABIO.cc:243
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:141
FreeTrajectoryState * freeState(bool withErrors=true) const
float yy() const
Definition: LocalError.h:26
T sqrt(T t)
Definition: SSEVec.h:48
double pt() const
track transverse momentum
Definition: TrackBase.h:131
Definition: Path.h:39
T z() const
Definition: PV3DBase.h:64
double ptError() const
error on Pt (set to 1000 TeV if charge==0 for safety)
Definition: TrackBase.h:194
unsigned int outerDetId() const
DetId of the detector on which surface the outermost state is located.
Definition: Track.h:59
unsigned int size_type
Definition: View.h:85
int j
Definition: DBlmapReader.cc:9
const CSCLayer * layer(CSCDetId id) const
Return the layer corresponding to the given id.
Definition: CSCChamber.cc:41
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:72
void linearExtrapolation(GlobalPoint initialPosition, GlobalVector initialDirection, float zSurface, std::vector< float > &posZY)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
bool first
Definition: L1TdeRCT.cc:94
bool isValid() const
Definition: HandleBase.h:76
void getFromFTS(const FreeTrajectoryState &fts, CLHEP::Hep3Vector &p3, CLHEP::Hep3Vector &r3, int &charge, AlgebraicSymMatrix66 &cov)
bool efficienciesPerChamber(CSCDetId &id, const CSCChamber *cscChamber, FreeTrajectoryState &ftsChamber)
GlobalVector momentum() const
void chamberCandidates(int station, int ring, float phi, std::vector< int > &coupleOfChambers)
const AlgebraicSymMatrix66 & matrix() const
void fillLCT_info(edm::Handle< CSCALCTDigiCollection > &alcts, edm::Handle< CSCCLCTDigiCollection > &clcts, edm::Handle< CSCCorrelatedLCTDigiCollection > &correlatedlcts)
void fillRechitsSegments_info(edm::Handle< CSCRecHit2DCollection > &rechits, edm::Handle< CSCSegmentCollection > &segments, edm::ESHandle< CSCGeometry > &cscGeom)
double qoverpError() const
error on signed transverse curvature
Definition: TrackBase.h:192
bool stripWire_Efficiencies(CSCDetId &cscDetId, FreeTrajectoryState &ftsChamber)
tuple out
Definition: dbtoconf.py:99
double deltaR(double eta1, double eta2, double phi1, double phi2)
Definition: TreeUtility.cc:17
int nearestStrip(const LocalPoint &lp) const
double extrapolate1D(double initPosition, double initDirection, double parameterOfTheLine)
int ring() const
Definition: CSCDetId.h:77
Definition: DetId.h:20
GlobalPoint position() const
#define M_PI
Definition: BFit3D.cc:3
void fillDigiInfo(edm::Handle< CSCALCTDigiCollection > &alcts, edm::Handle< CSCCLCTDigiCollection > &clcts, edm::Handle< CSCCorrelatedLCTDigiCollection > &correlatedlcts, edm::Handle< CSCWireDigiCollection > &wires, edm::Handle< CSCStripDigiCollection > &strips, edm::Handle< edm::PSimHitContainer > &simhits, edm::Handle< CSCRecHit2DCollection > &rechits, edm::Handle< CSCSegmentCollection > &segments, edm::ESHandle< CSCGeometry > &cscGeom)
const math::XYZVector & outerMomentum() const
momentum vector at the outermost hit position
Definition: Track.h:49
#define FirstCh
const Propagator * propagator(std::string propagatorName) const
const T & get() const
Definition: EventSetup.h:55
size_type size() const
bool recHitSegment_Efficiencies(CSCDetId &cscDetId, const CSCChamber *cscChamber, FreeTrajectoryState &ftsChamber)
std::vector< DigiType >::const_iterator const_iterator
T const * product() const
Definition: Handle.h:74
bool quality(const TrackQuality) const
Track quality.
Definition: TrackBase.h:377
bool inSensitiveLocalRegion(double xLocal, double yLocal, int station, int ring)
bool checkLocal(double yLocal, double yBoundary, int station, int ring)
T eta() const
Definition: PV3DBase.h:76
tuple muons
Definition: patZpeak.py:38
unsigned short found() const
Number of valid hits on track.
Definition: Track.h:100
void fillSimhit_info(edm::Handle< edm::PSimHitContainer > &simHits)
int station() const
Definition: CSCDetId.h:88
std::pair< const_iterator, const_iterator > Range
tuple cout
Definition: gather_cfg.py:121
int charge() const
track electric charge
Definition: TrackBase.h:113
const Point & position() const
position
Definition: BeamSpot.h:63
#define NumCh
#define debug
Definition: MEtoEDMFormat.h:34
T x() const
Definition: PV3DBase.h:62
unsigned int innerDetId() const
DetId of the detector on which surface the innermost state is located.
Definition: Track.h:61
float stripAngle(int strip) const
const CSCLayerGeometry * geometry() const
Definition: CSCLayer.h:47
tuple size
Write out results.
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40
tuple minP
Definition: alignBH_cfg.py:15
virtual void endJob()
TrajectoryStateOnSurface propagate(FreeTrajectoryState &ftsStart, const BoundPlane &bp)
double p3[4]
Definition: TauolaWrapper.h:91
Definition: DDAxes.h:10
void fillStrips_info(edm::Handle< CSCStripDigiCollection > &strips)