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