CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LaserAlignment.cc
Go to the documentation of this file.
1 
12 
13 
14 
15 
20  theEvents(0),
21  theDoPedestalSubtraction( theConf.getUntrackedParameter<bool>( "SubtractPedestals", true ) ),
22  theUseMinuitAlgorithm( theConf.getUntrackedParameter<bool>( "RunMinuitAlignmentTubeAlgorithm", false ) ),
23  theApplyBeamKinkCorrections( theConf.getUntrackedParameter<bool>( "ApplyBeamKinkCorrections", true ) ),
24  peakFinderThreshold( theConf.getUntrackedParameter<double>( "PeakFinderThreshold", 10. ) ),
25  enableJudgeZeroFilter( theConf.getUntrackedParameter<bool>( "EnableJudgeZeroFilter", true ) ),
26  judgeOverdriveThreshold( theConf.getUntrackedParameter<unsigned int>( "JudgeOverdriveThreshold", 220 ) ),
27  updateFromInputGeometry( theConf.getUntrackedParameter<bool>( "UpdateFromInputGeometry", false ) ),
28  misalignedByRefGeometry( theConf.getUntrackedParameter<bool>( "MisalignedByRefGeometry", false ) ),
29  theStoreToDB ( theConf.getUntrackedParameter<bool>( "SaveToDbase", false ) ),
30  theDigiProducersList( theConf.getParameter<std::vector<edm::ParameterSet> >( "DigiProducersList" ) ),
31  theSaveHistograms( theConf.getUntrackedParameter<bool>( "SaveHistograms", false ) ),
32  theCompression( theConf.getUntrackedParameter<int>( "ROOTFileCompression", 1 ) ),
33  theFileName( theConf.getUntrackedParameter<std::string>( "ROOTFileName", "test.root" ) ),
34  theMaskTecModules( theConf.getUntrackedParameter<std::vector<unsigned int> >( "MaskTECModules" ) ),
35  theMaskAtModules( theConf.getUntrackedParameter<std::vector<unsigned int> >( "MaskATModules" ) ),
36  theSetNominalStrips( theConf.getUntrackedParameter<bool>( "ForceFitterToNominalStrips", false ) ),
37  theLasConstants( theConf.getUntrackedParameter<std::vector<edm::ParameterSet> >( "LaserAlignmentConstants" ) ),
38  theFile(),
39  theAlignableTracker(),
40  theAlignRecordName( "TrackerAlignmentRcd" ),
41  theErrorRecordName( "TrackerAlignmentErrorRcd" ),
42  firstEvent_(true),
43  theParameterSet( theConf )
44 {
45 
46 
47  std::cout << std::endl;
48  std::cout << "=============================================================="
49  << "\n=== LaserAlignment module configuration ==="
50  << "\n"
51  << "\n Write histograms to file = " << (theSaveHistograms?"true":"false")
52  << "\n Histogram file name = " << theFileName
53  << "\n Histogram file compression = " << theCompression
54  << "\n Subtract pedestals = " << (theDoPedestalSubtraction?"true":"false")
55  << "\n Run Minuit AT algorithm = " << (theUseMinuitAlgorithm?"true":"false")
56  << "\n Apply beam kink corrections = " << (theApplyBeamKinkCorrections?"true":"false")
57  << "\n Peak Finder Threshold = " << peakFinderThreshold
58  << "\n EnableJudgeZeroFilter = " << (enableJudgeZeroFilter?"true":"false")
59  << "\n JudgeOverdriveThreshold = " << judgeOverdriveThreshold
60  << "\n Update from input geometry = " << (updateFromInputGeometry?"true":"false")
61  << "\n Misalignment from ref geometry = " << (misalignedByRefGeometry?"true":"false")
62  << "\n Number of TEC modules masked = " << theMaskTecModules.size() << " (s. below list if > 0)"
63  << "\n Number of AT modules masked = " << theMaskAtModules.size() << " (s. below list if > 0)"
64  << "\n Store to database = " << (theStoreToDB?"true":"false")
65  << "\n ----------------------------------------------- ----------"
66  << (theSetNominalStrips?"\n Set strips to nominal = true":"\n")
67  << "\n=============================================================" << std::endl;
68 
69  // tell about masked modules
70  if( theMaskTecModules.size() ) {
71  std::cout << " ===============================================================================================\n" << std::flush;
72  std::cout << " The following " << theMaskTecModules.size() << " TEC modules have been masked out and will not be considered by the TEC algorithm:\n " << std::flush;
73  for( std::vector<unsigned int>::iterator moduleIt = theMaskTecModules.begin(); moduleIt != theMaskTecModules.end(); ++moduleIt ) {
74  std::cout << *moduleIt << (moduleIt!=--theMaskTecModules.end()?", ":"") << std::flush;
75  }
76  std::cout << std::endl << std::flush;
77  std::cout << " ===============================================================================================\n\n" << std::flush;
78  }
79  if( theMaskAtModules.size() ) {
80  std::cout << " ===============================================================================================\n" << std::flush;
81  std::cout << " The following " << theMaskAtModules.size() << " AT modules have been masked out and will not be considered by the AT algorithm:\n " << std::flush;
82  for( std::vector<unsigned int>::iterator moduleIt = theMaskAtModules.begin(); moduleIt != theMaskAtModules.end(); ++moduleIt ) {
83  std::cout << *moduleIt << (moduleIt!=--theMaskAtModules.end()?", ":"") << std::flush;
84  }
85  std::cout << std::endl << std::flush;
86  std::cout << " ===============================================================================================\n\n" << std::flush;
87  }
88 
89 
90 
91  // alias for the Branches in the root files
92  std::string alias ( theConf.getParameter<std::string>("@module_label") );
93 
94  // declare the product to produce
95  produces<TkLasBeamCollection, edm::InRun>( "tkLaserBeams" ).setBranchAlias( alias + "TkLasBeamCollection" );
96 
97  // switch judge's zero filter depending on cfg
99 
100  // set the upper threshold for zero suppressed data
102 
103 }
104 
105 
106 
107 
108 
113 
114  if ( theSaveHistograms ) theFile->Write();
115  if ( theFile ) { delete theFile; }
116  if ( theAlignableTracker ) { delete theAlignableTracker; }
117 
118 }
119 
120 
121 
122 
123 
128 
129 
130  // write sumed histograms to file (if selected in cfg)
131  if( theSaveHistograms ) {
132 
133  // creating a new file
134  theFile = new TFile( theFileName.c_str(), "RECREATE", "CMS ROOT file" );
135 
136  // initialize the histograms
137  if ( theFile ) {
138  theFile->SetCompressionLevel(theCompression);
139  singleModulesDir = theFile->mkdir( "single modules" );
140  } else
141  throw cms::Exception( " [LaserAlignment::beginJob]") << " ** ERROR: could not open file:"
142  << theFileName.c_str() << " for writing." << std::endl;
143 
144  }
145 
146  // detector id maps (hard coded)
147  fillDetectorId();
148 
149  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150  // PROFILE, HISTOGRAM & FITFUNCTION INITIALIZATION
151  // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
152 
153  // object used to build various strings for names and labels
154  std::stringstream nameBuilder;
155 
156  // loop variables for use with LASGlobalLoop object
157  int det, ring, beam, disk, pos;
158 
159  // loop TEC modules
160  det = 0; ring = 0; beam = 0; disk = 0;
161  do { // loop using LASGlobalLoop functionality
162  // init the profiles
163  pedestalProfiles.GetTECEntry( det, ring, beam, disk ).SetAllValuesTo( 0. );
164  currentDataProfiles.GetTECEntry( det, ring, beam, disk ).SetAllValuesTo( 0. );
165  collectedDataProfiles.GetTECEntry( det, ring, beam, disk ).SetAllValuesTo( 0. );
166 
167  // init the hit maps
168  isAcceptedProfile.SetTECEntry( det, ring, beam, disk, 0 );
169  numberOfAcceptedProfiles.SetTECEntry( det, ring, beam, disk, 0 );
170 
171  // create strings for histo names
172  nameBuilder.clear();
173  nameBuilder.str( "" );
174  nameBuilder << "TEC";
175  if( det == 0 ) nameBuilder << "+"; else nameBuilder << "-";
176  nameBuilder << "_Ring";
177  if( ring == 0 ) nameBuilder << "4"; else nameBuilder << "6";
178  nameBuilder << "_Beam" << beam;
179  nameBuilder << "_Disk" << disk;
180  theProfileNames.SetTECEntry( det, ring, beam, disk, nameBuilder.str() );
181 
182  // init the histograms
183  if( theSaveHistograms ) {
184  nameBuilder << "_Histo";
185  summedHistograms.SetTECEntry( det, ring, beam, disk, new TH1D( nameBuilder.str().c_str(), nameBuilder.str().c_str(), 512, 0, 512 ) );
186  summedHistograms.GetTECEntry( det, ring, beam, disk )->SetDirectory( singleModulesDir );
187  }
188 
189  } while ( moduleLoop.TECLoop( det, ring, beam, disk ) );
190 
191 
192  // TIB & TOB section
193  det = 2; beam = 0; pos = 0;
194  do { // loop using LASGlobalLoop functionality
195  // init the profiles
196  pedestalProfiles.GetTIBTOBEntry( det, beam, pos ).SetAllValuesTo( 0. );
197  currentDataProfiles.GetTIBTOBEntry( det, beam, pos ).SetAllValuesTo( 0. );
198  collectedDataProfiles.GetTIBTOBEntry( det, beam, pos ).SetAllValuesTo( 0. );
199 
200  // init the hit maps
201  isAcceptedProfile.SetTIBTOBEntry( det, beam, pos, 0 );
202  numberOfAcceptedProfiles.SetTIBTOBEntry( det, beam, pos, 0 );
203 
204  // create strings for histo names
205  nameBuilder.clear();
206  nameBuilder.str( "" );
207  if( det == 2 ) nameBuilder << "TIB"; else nameBuilder << "TOB";
208  nameBuilder << "_Beam" << beam;
209  nameBuilder << "_Zpos" << pos;
210 
211  theProfileNames.SetTIBTOBEntry( det, beam, pos, nameBuilder.str() );
212 
213  // init the histograms
214  if( theSaveHistograms ) {
215  nameBuilder << "_Histo";
216  summedHistograms.SetTIBTOBEntry( det, beam, pos, new TH1D( nameBuilder.str().c_str(), nameBuilder.str().c_str(), 512, 0, 512 ) );
217  summedHistograms.GetTIBTOBEntry( det, beam, pos )->SetDirectory( singleModulesDir );
218  }
219 
220  } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
221 
222 
223  // TEC2TEC AT section
224  det = 0; beam = 0; disk = 0;
225  do { // loop using LASGlobalLoop functionality
226  // init the profiles
227  pedestalProfiles.GetTEC2TECEntry( det, beam, disk ).SetAllValuesTo( 0. );
228  currentDataProfiles.GetTEC2TECEntry( det, beam, disk ).SetAllValuesTo( 0. );
229  collectedDataProfiles.GetTEC2TECEntry( det, beam, disk ).SetAllValuesTo( 0. );
230 
231  // init the hit maps
232  isAcceptedProfile.SetTEC2TECEntry( det, beam, disk, 0 );
233  numberOfAcceptedProfiles.SetTEC2TECEntry( det, beam, disk, 0 );
234 
235  // create strings for histo names
236  nameBuilder.clear();
237  nameBuilder.str( "" );
238  nameBuilder << "TEC(AT)";
239  if( det == 0 ) nameBuilder << "+"; else nameBuilder << "-";
240  nameBuilder << "_Beam" << beam;
241  nameBuilder << "_Disk" << disk;
242  theProfileNames.SetTEC2TECEntry( det, beam, disk, nameBuilder.str() );
243 
244  // init the histograms
245  if( theSaveHistograms ) {
246  nameBuilder << "_Histo";
247  summedHistograms.SetTEC2TECEntry( det, beam, disk, new TH1D( nameBuilder.str().c_str(), nameBuilder.str().c_str(), 512, 0, 512 ) );
248  summedHistograms.GetTEC2TECEntry( det, beam, disk )->SetDirectory( singleModulesDir );
249  }
250 
251  } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
252 
253  firstEvent_ = true;
254 }
255 
256 
257 
258 
259 
260 
264 void LaserAlignment::produce(edm::Event& theEvent, edm::EventSetup const& theSetup) {
265 
266  if (firstEvent_) {
267 
268  //Retrieve tracker topology from geometry
269  edm::ESHandle<TrackerTopology> tTopoHandle;
270  theSetup.get<IdealGeometryRecord>().get(tTopoHandle);
271  const TrackerTopology* const tTopo = tTopoHandle.product();
272 
273  // access the tracker
275  theSetup.get<IdealGeometryRecord>().get( gD );
276 
277  // access pedestals (from db..) if desired
278  edm::ESHandle<SiStripPedestals> pedestalsHandle;
280  theSetup.get<SiStripPedestalsRcd>().get( pedestalsHandle );
281  fillPedestalProfiles( pedestalsHandle );
282  }
283 
284  // global positions
285  // edm::ESHandle<Alignments> theGlobalPositionRcd;
286  theSetup.get<TrackerDigiGeometryRecord>().getRecord<GlobalPositionRcd>().get( theGlobalPositionRcd );
287 
288  // select the reference geometry
289  if( !updateFromInputGeometry ) {
290  // the AlignableTracker object is initialized with the ideal geometry
291  edm::ESHandle<GeometricDet> theGeometricDet;
292  theSetup.get<IdealGeometryRecord>().get(theGeometricDet);
293  TrackerGeomBuilderFromGeometricDet trackerBuilder;
294  TrackerGeometry* theRefTracker = trackerBuilder.build(&*theGeometricDet, theParameterSet);
295 
296  theAlignableTracker = new AlignableTracker(&(*theRefTracker), tTopo);
297  }
298  else {
299  // the AlignableTracker object is initialized with the input geometry from DB
301  }
302 
303  firstEvent_ = false;
304  }
305 
306  LogDebug("LaserAlignment") << "==========================================================="
307  << "\n Private analysis of event #"<< theEvent.id().event()
308  << " in run #" << theEvent.id().run();
309 
310 
311  // do the Tracker Statistics to retrieve the current profiles
312  fillDataProfiles( theEvent, theSetup );
313 
314  // index variables for the LASGlobalLoop object
315  int det, ring, beam, disk, pos;
316 
317  //
318  // first pre-loop on selected entries to find out
319  // whether the TEC or the AT beams have fired
320  // (pedestal profiles are left empty if false in cfg)
321  //
322 
323 
324  // TEC+- (only ring 6)
325  ring = 1;
326  for( det = 0; det < 2; ++det ) {
327  for( beam = 0; beam < 8; ++ beam ) {
328  for( disk = 0; disk < 9; ++disk ) {
329  if( judge.IsSignalIn( currentDataProfiles.GetTECEntry( det, ring, beam, disk ) - pedestalProfiles.GetTECEntry( det, ring, beam, disk ), 0 ) ) {
330  isAcceptedProfile.SetTECEntry( det, ring, beam, disk, 1 );
331  }
332  else { // assume no initialization
333  isAcceptedProfile.SetTECEntry( det, ring, beam, disk, 0 );
334  }
335  }
336  }
337  }
338 
339  // TIBTOB
340  det = 2; beam = 0; pos = 0;
341  do {
342  // add current event's data and subtract pedestals
343  if( judge.IsSignalIn( currentDataProfiles.GetTIBTOBEntry( det, beam, pos ) - pedestalProfiles.GetTIBTOBEntry( det, beam, pos ), getTIBTOBNominalBeamOffset( det, beam, pos ) ) ) {
344  isAcceptedProfile.SetTIBTOBEntry( det, beam, pos, 1 );
345  }
346  else { // dto.
347  isAcceptedProfile.SetTIBTOBEntry( det, beam, pos, 0 );
348  }
349 
350  } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
351 
352 
353 
354 
355  // now come the beam finders
356  bool isTECMode = isTECBeam();
357  // LogDebug( " [LaserAlignment::produce]" ) << "LaserAlignment::isTECBeam declares this event " << ( isTECMode ? "" : "NOT " ) << "a TEC event." << std::endl;
358  std::cout << " [LaserAlignment::produce] -- LaserAlignment::isTECBeam declares this event " << ( isTECMode ? "" : "NOT " ) << "a TEC event." << std::endl;
359 
360  bool isATMode = isATBeam();
361  // LogDebug( " [LaserAlignment::produce]" ) << "LaserAlignment::isATBeam declares this event " << ( isATMode ? "" : "NOT " ) << "an AT event." << std::endl;
362  std::cout << " [LaserAlignment::produce] -- LaserAlignment::isATBeam declares this event " << ( isATMode ? "" : "NOT " ) << "an AT event." << std::endl;
363 
364 
365 
366 
367  //
368  // now pass the pedestal subtracted profiles to the judge
369  // if they're accepted, add them on the collectedDataProfiles
370  // (pedestal profiles are left empty if false in cfg)
371  //
372 
373 
374  // loop TEC+- modules
375  det = 0; ring = 0; beam = 0; disk = 0;
376  do {
377 
378  LogDebug( "[LaserAlignment::produce]" ) << "Profile is: " << theProfileNames.GetTECEntry( det, ring, beam, disk ) << "." << std::endl;
379 
380  // this now depends on the AT/TEC mode, is this a doubly hit module? -> look for it in vector<int> tecDoubleHitDetId
381  // (ring == 0 not necessary but makes it a little faster)
382  if( ring == 0 && find( tecDoubleHitDetId.begin(), tecDoubleHitDetId.end(), detectorId.GetTECEntry( det, ring, beam, disk ) ) != tecDoubleHitDetId.end() ) {
383 
384  if( isTECMode ) { // add profile to TEC collection
385  // add current event's data and subtract pedestals
386  if( judge.JudgeProfile( currentDataProfiles.GetTECEntry( det, ring, beam, disk ) - pedestalProfiles.GetTECEntry( det, ring, beam, disk ), 0 ) ) {
387  collectedDataProfiles.GetTECEntry( det, ring, beam, disk ) += currentDataProfiles.GetTECEntry( det, ring, beam, disk ) - pedestalProfiles.GetTECEntry( det, ring, beam, disk );
388  numberOfAcceptedProfiles.GetTECEntry( det, ring, beam, disk )++;
389  }
390  }
391  }
392 
393  else { // not a doubly hit module, don't care about the mode
394  // add current event's data and subtract pedestals
395  if( judge.JudgeProfile( currentDataProfiles.GetTECEntry( det, ring, beam, disk ) - pedestalProfiles.GetTECEntry( det, ring, beam, disk ), 0 ) ) {
396  collectedDataProfiles.GetTECEntry( det, ring, beam, disk ) += currentDataProfiles.GetTECEntry( det, ring, beam, disk ) - pedestalProfiles.GetTECEntry( det, ring, beam, disk );
397  numberOfAcceptedProfiles.GetTECEntry( det, ring, beam, disk )++;
398  }
399  }
400 
401  } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
402 
403 
404 
405 
406 
407  // loop TIB/TOB modules
408  det = 2; beam = 0; pos = 0;
409  do {
410 
411  LogDebug( "[LaserAlignment::produce]" ) << "Profile is: " << theProfileNames.GetTIBTOBEntry( det, beam, pos ) << "." << std::endl;
412 
413  // add current event's data and subtract pedestals
414  if( judge.JudgeProfile( currentDataProfiles.GetTIBTOBEntry( det, beam, pos ) - pedestalProfiles.GetTIBTOBEntry( det, beam, pos ), getTIBTOBNominalBeamOffset( det, beam, pos ) ) ) {
415  collectedDataProfiles.GetTIBTOBEntry( det, beam, pos ) += currentDataProfiles.GetTIBTOBEntry( det, beam, pos ) - pedestalProfiles.GetTIBTOBEntry( det, beam, pos );
416  numberOfAcceptedProfiles.GetTIBTOBEntry( det, beam, pos )++;
417  }
418 
419  } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
420 
421 
422 
423  // loop TEC2TEC modules
424  det = 0; beam = 0; disk = 0;
425  do {
426 
427  LogDebug( "[LaserAlignment::produce]" ) << "Profile is: " << theProfileNames.GetTEC2TECEntry( det, beam, disk ) << "." << std::endl;
428 
429  // this again depends on the AT/TEC mode, is this a doubly hit module?
430  // (ring == 0 not necessary but makes it a little faster)
431  if( ring == 0 && find( tecDoubleHitDetId.begin(), tecDoubleHitDetId.end(), detectorId.GetTECEntry( det, ring, beam, disk ) ) != tecDoubleHitDetId.end() ) {
432 
433  if( isATMode ) { // add profile to TEC2TEC collection
434  // add current event's data and subtract pedestals
435  if( judge.JudgeProfile( currentDataProfiles.GetTEC2TECEntry( det, beam, disk ) - pedestalProfiles.GetTEC2TECEntry( det, beam, disk ), 0 ) ) {
436  collectedDataProfiles.GetTEC2TECEntry( det, beam, disk ) += currentDataProfiles.GetTEC2TECEntry( det, beam, disk ) - pedestalProfiles.GetTEC2TECEntry( det, beam, disk );
437  numberOfAcceptedProfiles.GetTEC2TECEntry( det, beam, disk )++;
438  }
439  }
440 
441  }
442 
443  else { // not a doubly hit module, don't care about the mode
444  // add current event's data and subtract pedestals
445  if( judge.JudgeProfile( currentDataProfiles.GetTEC2TECEntry( det, beam, disk ) - pedestalProfiles.GetTEC2TECEntry( det, beam, disk ), 0 ) ) {
446  collectedDataProfiles.GetTEC2TECEntry( det, beam, disk ) += currentDataProfiles.GetTEC2TECEntry( det, beam, disk ) - pedestalProfiles.GetTEC2TECEntry( det, beam, disk );
447  numberOfAcceptedProfiles.GetTEC2TECEntry( det, beam, disk )++;
448  }
449  }
450 
451 
452  } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
453 
454 
455 
456  // total event number counter
457  theEvents++;
458 
459 }
460 
461 
462 
463 
464 
468 void LaserAlignment::endRunProduce( edm::Run& theRun, const edm::EventSetup& theSetup ) {
469 
470 
471  std::cout << " [LaserAlignment::endRun] -- Total number of events processed: " << theEvents << std::endl;
472 
473  // for debugging only..
475 
476  // index variables for the LASGlobalLoop objects
477  int det, ring, beam, disk, pos;
478 
479  // measured positions container for the algorithms
480  LASGlobalData<LASCoordinateSet> measuredCoordinates;
481 
482  // fitted peak positions in units of strips (pair for value,error)
483  LASGlobalData<std::pair<float,float> > measuredStripPositions;
484 
485  // the peak finder, a pair (pos/posErr in units of strips) for its results, and the success confirmation
486  LASPeakFinder peakFinder;
488  std::pair<double,double> peakFinderResults;
489  bool isGoodFit;
490 
491  // tracker geom. object for calculating the global beam positions
492  const TrackerGeometry& theTracker( *theTrackerGeometry );
493 
494  // fill LASGlobalData<LASCoordinateSet> nominalCoordinates
496 
497  // for determining the phi errors
498  // ErrorFrameTransformer errorTransformer; // later...
499 
500 
501 
502 
503 
504  // do the fits for TEC+- internal
505  det = 0; ring = 0; beam = 0; disk = 0;
506  do {
507 
508  // do the fit
509  isGoodFit = peakFinder.FindPeakIn( collectedDataProfiles.GetTECEntry( det, ring, beam, disk ), peakFinderResults,
510  summedHistograms.GetTECEntry( det, ring, beam, disk ), 0 ); // offset is 0 for TEC
511 
512  // now we have the measured positions in units of strips.
513  if( !isGoodFit ) std::cout << " [LaserAlignment::endRun] ** WARNING: Fit failed for TEC det: "
514  << det << ", ring: " << ring << ", beam: " << beam << ", disk: " << disk
515  << " (id: " << detectorId.GetTECEntry( det, ring, beam, disk ) << ")." << std::endl;
516 
517 
518 
519  // <- here we will later implement the kink corrections
520 
521  // access the tracker geometry for this module
522  const DetId theDetId( detectorId.GetTECEntry( det, ring, beam, disk ) );
523  const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
524 
525  if (theStripDet) {
526  // first, set the measured coordinates to their nominal values
527  measuredCoordinates.SetTECEntry( det, ring, beam, disk, nominalCoordinates.GetTECEntry( det, ring, beam, disk ) );
528 
529  if( isGoodFit ) { // convert strip position to global phi and replace the nominal phi value/error
530 
531  measuredStripPositions.GetTECEntry( det, ring, beam, disk ) = peakFinderResults;
532  const float positionInStrips = theSetNominalStrips ? 256. : peakFinderResults.first; // implementation of "ForceFitterToNominalStrips" config parameter
533  const GlobalPoint& globalPoint = theStripDet->surface().toGlobal( theStripDet->specificTopology().localPosition( positionInStrips ) );
534  measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhi( ConvertAngle( globalPoint.barePhi() ) );
535 
536  // const GlobalError& globalError = errorTransformer.transform( theStripDet->specificTopology().localError( peakFinderResults.first, pow( peakFinderResults.second, 2 ) ), theStripDet->surface() );
537  // measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhiError( globalError.phierr( globalPoint ) );
538  measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhiError( 0.00046 ); // PRELIMINARY ESTIMATE
539 
540  }
541  else { // keep nominal position (middle-of-module) but set a giant phi error so that the module can be ignored by the alignment algorithm
542  measuredStripPositions.GetTECEntry( det, ring, beam, disk ) = std::pair<float,float>( 256., 1000. );
543  const GlobalPoint& globalPoint = theStripDet->surface().toGlobal( theStripDet->specificTopology().localPosition( 256. ) );
544  measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhi( ConvertAngle( globalPoint.barePhi() ) );
545  measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhiError( 1000. );
546  }
547  }
548 
549  } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
550 
551 
552 
553 
554  // do the fits for TIB/TOB
555  det = 2; beam = 0; pos = 0;
556  do {
557 
558  // do the fit
559  isGoodFit = peakFinder.FindPeakIn( collectedDataProfiles.GetTIBTOBEntry( det, beam, pos ), peakFinderResults,
560  summedHistograms.GetTIBTOBEntry( det, beam, pos ), getTIBTOBNominalBeamOffset( det, beam, pos ) );
561 
562  // now we have the measured positions in units of strips.
563  if( !isGoodFit ) std::cout << " [LaserAlignment::endJob] ** WARNING: Fit failed for TIB/TOB det: "
564  << det << ", beam: " << beam << ", pos: " << pos
565  << " (id: " << detectorId.GetTIBTOBEntry( det, beam, pos ) << ")." << std::endl;
566 
567 
568  // <- here we will later implement the kink corrections
569 
570  // access the tracker geometry for this module
571  const DetId theDetId( detectorId.GetTIBTOBEntry( det, beam, pos ) );
572  const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
573 
574  if (theStripDet) {
575  // first, set the measured coordinates to their nominal values
576  measuredCoordinates.SetTIBTOBEntry( det, beam, pos, nominalCoordinates.GetTIBTOBEntry( det, beam, pos ) );
577 
578  if( isGoodFit ) { // convert strip position to global phi and replace the nominal phi value/error
579  measuredStripPositions.GetTIBTOBEntry( det, beam, pos ) = peakFinderResults;
580  const float positionInStrips = theSetNominalStrips ? 256. + getTIBTOBNominalBeamOffset( det, beam, pos ) : peakFinderResults.first; // implementation of "ForceFitterToNominalStrips" config parameter
581  const GlobalPoint& globalPoint = theStripDet->surface().toGlobal( theStripDet->specificTopology().localPosition( positionInStrips ) );
582  measuredCoordinates.GetTIBTOBEntry( det, beam, pos ).SetPhi( ConvertAngle( globalPoint.barePhi() ) );
583  measuredCoordinates.GetTIBTOBEntry( det, beam, pos ).SetPhiError( 0.00028 ); // PRELIMINARY ESTIMATE
584  }
585  else { // keep nominal position but set a giant phi error so that the module can be ignored by the alignment algorithm
586  measuredStripPositions.GetTIBTOBEntry( det, beam, pos ) = std::pair<float,float>( 256. + getTIBTOBNominalBeamOffset( det, beam, pos ), 1000. );
587  const GlobalPoint& globalPoint = theStripDet->surface().toGlobal( theStripDet->specificTopology().localPosition( 256. + getTIBTOBNominalBeamOffset( det, beam, pos ) ) );
588  measuredCoordinates.GetTIBTOBEntry( det, beam, pos ).SetPhi( ConvertAngle( globalPoint.barePhi() ) );
589  measuredCoordinates.GetTIBTOBEntry( det, beam, pos ).SetPhiError( 1000. );
590  }
591  }
592 
593  } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
594 
595 
596 
597 
598  // do the fits for TEC AT
599  det = 0; beam = 0; disk = 0;
600  do {
601 
602  // do the fit
603  isGoodFit = peakFinder.FindPeakIn( collectedDataProfiles.GetTEC2TECEntry( det, beam, disk ), peakFinderResults,
604  summedHistograms.GetTEC2TECEntry( det, beam, disk ), getTEC2TECNominalBeamOffset( det, beam, disk ) );
605  // now we have the positions in units of strips.
606  if( !isGoodFit ) std::cout << " [LaserAlignment::endRun] ** WARNING: Fit failed for TEC2TEC det: "
607  << det << ", beam: " << beam << ", disk: " << disk
608  << " (id: " << detectorId.GetTEC2TECEntry( det, beam, disk ) << ")." << std::endl;
609 
610 
611  // <- here we will later implement the kink corrections
612 
613  // access the tracker geometry for this module
614  const DetId theDetId( detectorId.GetTEC2TECEntry( det, beam, disk ) );
615  const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
616 
617  if (theStripDet) {
618  // first, set the measured coordinates to their nominal values
619  measuredCoordinates.SetTEC2TECEntry( det, beam, disk, nominalCoordinates.GetTEC2TECEntry( det, beam, disk ) );
620 
621  if( isGoodFit ) { // convert strip position to global phi and replace the nominal phi value/error
622  measuredStripPositions.GetTEC2TECEntry( det, beam, disk ) = peakFinderResults;
623  const float positionInStrips = theSetNominalStrips ? 256. + getTEC2TECNominalBeamOffset( det, beam, disk ) : peakFinderResults.first; // implementation of "ForceFitterToNominalStrips" config parameter
624  const GlobalPoint& globalPoint = theStripDet->surface().toGlobal( theStripDet->specificTopology().localPosition( positionInStrips ) );
625  measuredCoordinates.GetTEC2TECEntry( det, beam, disk ).SetPhi( ConvertAngle( globalPoint.barePhi() ) );
626  measuredCoordinates.GetTEC2TECEntry( det, beam, disk ).SetPhiError( 0.00047 ); // PRELIMINARY ESTIMATE
627  }
628  else { // keep nominal position but set a giant phi error so that the module can be ignored by the alignment algorithm
629  measuredStripPositions.GetTEC2TECEntry( det, beam, disk ) = std::pair<float,float>( 256. + getTEC2TECNominalBeamOffset( det, beam, disk ), 1000. );
630  const GlobalPoint& globalPoint = theStripDet->surface().toGlobal( theStripDet->specificTopology().localPosition( 256. + getTEC2TECNominalBeamOffset( det, beam, disk ) ) );
631  measuredCoordinates.GetTEC2TECEntry( det, beam, disk ).SetPhi( ConvertAngle( globalPoint.barePhi() ) );
632  measuredCoordinates.GetTEC2TECEntry( det, beam, disk ).SetPhiError( 1000. );
633  }
634  }
635 
636  } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
637 
638 
639 
640 
641 
642 
643 
644  // see what we got (for debugging)
645  // DumpStripFileSet( measuredStripPositions );
646  // DumpPosFileSet( measuredCoordinates );
647 
648 
649 
650 
651 
652 
653  // CALCULATE PARAMETERS AND UPDATE DB OBJECT
654  // for beam kink corrections, reconstructing the geometry and updating the db object
656 
657  // apply all beam corrections
658  if( theApplyBeamKinkCorrections ) geometryUpdater.ApplyBeamKinkCorrections( measuredCoordinates );
659 
660  // if we start with input geometry instead of IDEAL,
661  // reverse the adjustments in the AlignableTracker object
662  if( updateFromInputGeometry ) geometryUpdater.SetReverseDirection( true );
663 
664  // if we have "virtual" misalignment which is introduced via the reference geometry,
665  // tell the LASGeometryUpdater to reverse x & y adjustments
666  if( misalignedByRefGeometry ) geometryUpdater.SetMisalignmentFromRefGeometry( true );
667 
668  // run the endcap algorithm
669  LASEndcapAlgorithm endcapAlgorithm;
670  LASEndcapAlignmentParameterSet endcapParameters;
671 
672 
673  // this basically sets all the endcap modules to be masked
674  // to their nominal positions (since endcapParameters is overall zero)
675  if( theMaskTecModules.size() ) {
676  ApplyEndcapMaskingCorrections( measuredCoordinates, nominalCoordinates, endcapParameters );
677  }
678 
679  // run the algorithm
680  endcapParameters = endcapAlgorithm.CalculateParameters( measuredCoordinates, nominalCoordinates );
681 
682  //
683  // loop to mask out events
684  // DESCRIPTION:
685  //
686 
687  // do this only if there are modules to be masked..
688  if( theMaskTecModules.size() ) {
689 
690  const unsigned int nIterations = 30;
691  for( unsigned int iteration = 0; iteration < nIterations; ++iteration ) {
692 
693  // set the endcap modules to be masked to their positions
694  // according to the reconstructed parameters
695  ApplyEndcapMaskingCorrections( measuredCoordinates, nominalCoordinates, endcapParameters );
696 
697  // modifications applied, so re-run the algorithm
698  endcapParameters = endcapAlgorithm.CalculateParameters( measuredCoordinates, nominalCoordinates );
699 
700  }
701 
702  }
703 
704  // these are now final, so:
705  endcapParameters.Print();
706 
707 
708 
709 
710  // do a pre-alignment of the endcaps (TEC2TEC only)
711  // so that the alignment tube algorithms finds orderly disks
712  geometryUpdater.EndcapUpdate( endcapParameters, measuredCoordinates );
713 
714 
715  // the alignment tube algorithms, choose from config
716  LASBarrelAlignmentParameterSet alignmentTubeParameters;
717  // the MINUIT-BASED alignment tube algorithm
718  LASBarrelAlgorithm barrelAlgorithm;
719  // the ANALYTICAL alignment tube algorithm
720  LASAlignmentTubeAlgorithm alignmentTubeAlgorithm;
721 
722 
723  // this basically sets all the modules to be masked
724  // to their nominal positions (since alignmentTubeParameters is overall zero)
725  if( theMaskAtModules.size() ) {
726  ApplyATMaskingCorrections( measuredCoordinates, nominalCoordinates, alignmentTubeParameters );
727  }
728 
729  if( theUseMinuitAlgorithm ) {
730  // run the MINUIT-BASED alignment tube algorithm
731  alignmentTubeParameters = barrelAlgorithm.CalculateParameters( measuredCoordinates, nominalCoordinates );
732  }
733  else {
734  // the ANALYTICAL alignment tube algorithm
735  alignmentTubeParameters = alignmentTubeAlgorithm.CalculateParameters( measuredCoordinates, nominalCoordinates );
736  }
737 
738 
739 
740  //
741  // loop to mask out events
742  // DESCRIPTION:
743  //
744 
745  // do this only if there are modules to be masked..
746  if( theMaskAtModules.size() ) {
747 
748  const unsigned int nIterations = 30;
749  for( unsigned int iteration = 0; iteration < nIterations; ++iteration ) {
750 
751  // set the AT modules to be masked to their positions
752  // according to the reconstructed parameters
753  ApplyATMaskingCorrections( measuredCoordinates, nominalCoordinates, alignmentTubeParameters );
754 
755  // modifications applied, so re-run the algorithm
756  if( theUseMinuitAlgorithm ) {
757  alignmentTubeParameters = barrelAlgorithm.CalculateParameters( measuredCoordinates, nominalCoordinates );
758  }
759  else {
760  alignmentTubeParameters = alignmentTubeAlgorithm.CalculateParameters( measuredCoordinates, nominalCoordinates );
761  }
762 
763  }
764 
765  }
766 
767 
768  // these are now final, so:
769  alignmentTubeParameters.Print();
770 
771 
772  // combine the results and update the db object
773  geometryUpdater.TrackerUpdate( endcapParameters, alignmentTubeParameters, *theAlignableTracker );
774 
775 
776 
777 
778 
779 
780 
785 
786 
787  // the collection container
788  std::auto_ptr<TkLasBeamCollection> laserBeams( new TkLasBeamCollection );
789 
790 
791  // first for the endcap internal beams
792  for( det = 0; det < 2; ++det ) {
793  for( ring = 0; ring < 2; ++ring ) {
794  for( beam = 0; beam < 8; ++beam ) {
795 
796  // the beam and its identifier (see TkLasTrackBasedInterface TWiki)
797  TkLasBeam currentBeam( 100 * det + 10 * beam + ring );
798 
799  // order the hits in the beam by increasing z
800  const int firstDisk = det==0 ? 0 : 8;
801  const int lastDisk = det==0 ? 8 : 0;
802 
803  // count upwards or downwards
804  for( disk = firstDisk; det==0 ? disk <= lastDisk : disk >= lastDisk; det==0 ? ++disk : --disk ) {
805 
806  // detId for the SiStripLaserRecHit2D
807  const SiStripDetId theDetId( detectorId.GetTECEntry( det, ring, beam, disk ) );
808 
809  // need this to calculate the localPosition and its error
810  const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
811 
812  // the hit container
813  const SiStripLaserRecHit2D currentHit(
814  theStripDet->specificTopology().localPosition( measuredStripPositions.GetTECEntry( det, ring, beam, disk ).first ),
815  theStripDet->specificTopology().localError( measuredStripPositions.GetTECEntry( det, ring, beam, disk ).first, measuredStripPositions.GetTECEntry( det, ring, beam, disk ).second ),
816  theDetId
817  );
818 
819  currentBeam.push_back( currentHit );
820 
821  }
822 
823  laserBeams->push_back( currentBeam );
824 
825  }
826  }
827  }
828 
829 
830 
831  // then, following the convention in TkLasTrackBasedInterface TWiki, the alignment tube beams;
832  // they comprise hits in TIBTOB & TEC2TEC
833 
834  for( beam = 0; beam < 8; ++beam ) {
835 
836  // the beam and its identifier (see TkLasTrackBasedInterface TWiki)
837  TkLasBeam currentBeam( 100 * 2 /*beamGroup=AT=2*/ + 10 * beam + 0 /*ring=0*/);
838 
839 
840  // first: tec-
841  det = 1;
842  for( disk = 4; disk >= 0; --disk ) {
843 
844  // detId for the SiStripLaserRecHit2D
845  const SiStripDetId theDetId( detectorId.GetTEC2TECEntry( det, beam, disk ) );
846 
847  // need this to calculate the localPosition and its error
848  const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
849 
850  // the hit container
851  const SiStripLaserRecHit2D currentHit(
852  theStripDet->specificTopology().localPosition( measuredStripPositions.GetTEC2TECEntry( det, beam, disk ).first ),
853  theStripDet->specificTopology().localError( measuredStripPositions.GetTEC2TECEntry( det, beam, disk ).first, measuredStripPositions.GetTEC2TECEntry( det, beam, disk ).second ),
854  theDetId
855  );
856 
857  currentBeam.push_back( currentHit );
858 
859  }
860 
861 
862  // now TIB and TOB in one go
863  for( det = 2; det < 4; ++det ) {
864  for( pos = 5; pos >= 0; --pos ) { // stupidly, pos is defined from +z to -z in LASGlobalLoop
865 
866  // detId for the SiStripLaserRecHit2D
867  const SiStripDetId theDetId( detectorId.GetTIBTOBEntry( det, beam, pos ) );
868 
869  // need this to calculate the localPosition and its error
870  const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
871 
872  // the hit container
873  const SiStripLaserRecHit2D currentHit(
874  theStripDet->specificTopology().localPosition( measuredStripPositions.GetTIBTOBEntry( det, beam, pos ).first ),
875  theStripDet->specificTopology().localError( measuredStripPositions.GetTIBTOBEntry( det, beam, pos ).first, measuredStripPositions.GetTIBTOBEntry( det, beam, pos ).second ),
876  theDetId
877  );
878 
879  currentBeam.push_back( currentHit );
880 
881  }
882  }
883 
884 
885  // then: tec+
886  det = 0;
887  for( disk = 0; disk < 5; ++disk ) {
888 
889  // detId for the SiStripLaserRecHit2D
890  const SiStripDetId theDetId( detectorId.GetTEC2TECEntry( det, beam, disk ) );
891 
892  // need this to calculate the localPosition and its error
893  const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
894 
895  // the hit container
896  const SiStripLaserRecHit2D currentHit(
897  theStripDet->specificTopology().localPosition( measuredStripPositions.GetTEC2TECEntry( det, beam, disk ).first ),
898  theStripDet->specificTopology().localError( measuredStripPositions.GetTEC2TECEntry( det, beam, disk ).first, measuredStripPositions.GetTEC2TECEntry( det, beam, disk ).second ),
899  theDetId
900  );
901 
902  currentBeam.push_back( currentHit );
903 
904  }
905 
906 
907 
908  // save this beam to the beamCollection
909  laserBeams->push_back( currentBeam );
910 
911  } // (close beam loop)
912 
913 
914  // now attach the collection to the run
915  theRun.put( laserBeams, "tkLaserBeams" );
916 
917 
918 
919 
920 
921  // store the estimated alignment parameters into the DB
922  // first get them
923  Alignments* alignments = theAlignableTracker->alignments();
925 
926  if ( theStoreToDB ) {
927 
928  std::cout << " [LaserAlignment::endRun] -- Storing the calculated alignment parameters to the DataBase:" << std::endl;
929 
930  // Call service
932  if( !poolDbService.isAvailable() ) // Die if not available
933  throw cms::Exception( "NotAvailable" ) << "PoolDBOutputService not available";
934 
935  // Store
936 
937  // if ( poolDbService->isNewTagRequest(theAlignRecordName) ) {
938  // poolDbService->createNewIOV<Alignments>( alignments, poolDbService->currentTime(), poolDbService->endOfTime(), theAlignRecordName );
939  // }
940  // else {
941  // poolDbService->appendSinceTime<Alignments>( alignments, poolDbService->currentTime(), theAlignRecordName );
942  // }
943  poolDbService->writeOne<Alignments>( alignments, poolDbService->beginOfTime(), theAlignRecordName );
944 
945  // if ( poolDbService->isNewTagRequest(theErrorRecordName) ) {
946  // poolDbService->createNewIOV<AlignmentErrors>( alignmentErrors, poolDbService->currentTime(), poolDbService->endOfTime(), theErrorRecordName );
947  // }
948  // else {
949  // poolDbService->appendSinceTime<AlignmentErrors>( alignmentErrors, poolDbService->currentTime(), theErrorRecordName );
950  // }
951  poolDbService->writeOne<AlignmentErrors>( alignmentErrors, poolDbService->beginOfTime(), theErrorRecordName );
952 
953  std::cout << " [LaserAlignment::endRun] -- Storing done." << std::endl;
954 
955  }
956 
957 }
958 
959 
960 
961 
962 
967 }
968 
969 
970 
971 
972 
977 void LaserAlignment::fillDataProfiles( edm::Event const& theEvent, edm::EventSetup const& theSetup ) {
978 
979  // two handles for the two different kinds of digis
982 
983  bool isRawDigi = false;
984 
985  // indices for the LASGlobalLoop object
986  int det = 0, ring = 0, beam = 0, disk = 0, pos = 0;
987 
988  // query config set and loop over all PSets in the VPSet
989  for ( std::vector<edm::ParameterSet>::iterator itDigiProducersList = theDigiProducersList.begin(); itDigiProducersList != theDigiProducersList.end(); ++itDigiProducersList ) {
990 
991  std::string digiProducer = itDigiProducersList->getParameter<std::string>( "DigiProducer" );
992  std::string digiLabel = itDigiProducersList->getParameter<std::string>( "DigiLabel" );
993  std::string digiType = itDigiProducersList->getParameter<std::string>( "DigiType" );
994 
995  // now branch according to digi type (raw or processed);
996  // first we go for raw digis => SiStripRawDigi
997  if( digiType == "Raw" ) {
998  theEvent.getByLabel( digiProducer, digiLabel, theStripRawDigis );
999  isRawDigi = true;
1000  }
1001  else if( digiType == "Processed" ) {
1002  theEvent.getByLabel( digiProducer, digiLabel, theStripDigis );
1003  isRawDigi = false;
1004  }
1005  else {
1006  throw cms::Exception( " [LaserAlignment::fillDataProfiles]") << " ** ERROR: Invalid digi type: \"" << digiType << "\" specified in configuration." << std::endl;
1007  }
1008 
1009 
1010 
1011  // loop TEC internal modules
1012  det = 0; ring = 0; beam = 0; disk = 0;
1013  do {
1014 
1015  // first clear the profile
1017 
1018  // retrieve the raw id of that module
1019  const int detRawId = detectorId.GetTECEntry( det, ring, beam, disk );
1020 
1021  if( isRawDigi ) { // we have raw SiStripRawDigis
1022 
1023  // search the digis for the raw id
1024  edm::DetSetVector<SiStripRawDigi>::const_iterator detSetIter = theStripRawDigis->find( detRawId );
1025  if( detSetIter == theStripRawDigis->end() ) {
1026  throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: No raw DetSet found for det: " << detRawId << "." << std::endl;
1027  }
1028 
1029  // fill the digis to the profiles
1030  edm::DetSet<SiStripRawDigi>::const_iterator digiRangeIterator = detSetIter->data.begin(); // for the loop
1031  edm::DetSet<SiStripRawDigi>::const_iterator digiRangeStart = digiRangeIterator; // save starting positions
1032 
1033  // loop all digis
1034  for (; digiRangeIterator != detSetIter->data.end(); ++digiRangeIterator ) {
1035  const SiStripRawDigi& digi = *digiRangeIterator;
1036  const int channel = distance( digiRangeStart, digiRangeIterator );
1037  if ( channel >= 0 && channel < 512 ) currentDataProfiles.GetTECEntry( det, ring, beam, disk ).SetValue( channel, digi.adc() );
1038  else throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: raw digi channel: " << channel << " out of range for det: " << detRawId << "." << std::endl;
1039  }
1040 
1041  }
1042 
1043  else { // we have zero suppressed SiStripDigis
1044 
1045  // search the digis for the raw id
1046  edm::DetSetVector<SiStripDigi>::const_iterator detSetIter = theStripDigis->find( detRawId );
1047 
1048  // processed DetSets may be missing, just skip
1049  if( detSetIter == theStripDigis->end() ) continue;
1050 
1051  // fill the digis to the profiles
1052  edm::DetSet<SiStripDigi>::const_iterator digiRangeIterator = detSetIter->data.begin(); // for the loop
1053 
1054  for(; digiRangeIterator != detSetIter->data.end(); ++digiRangeIterator ) {
1055  const SiStripDigi& digi = *digiRangeIterator;
1056  if ( digi.strip() < 512 ) currentDataProfiles.GetTECEntry( det, ring, beam, disk ).SetValue( digi.strip(), digi.adc() );
1057  else throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: digi strip: " << digi.strip() << " out of range for det: " << detRawId << "." << std::endl;
1058  }
1059 
1060  }
1061 
1062 
1063  } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
1064 
1065 
1066 
1067 
1068 
1069  // loop TIBTOB modules
1070  det = 2; beam = 0; pos = 0;
1071  do {
1072 
1073  // first clear the profile
1075 
1076  // retrieve the raw id of that module
1077  const int detRawId = detectorId.GetTIBTOBEntry( det, beam, pos );
1078 
1079  if( isRawDigi ) { // we have raw SiStripRawDigis
1080 
1081  // search the digis for the raw id
1082  edm::DetSetVector<SiStripRawDigi>::const_iterator detSetIter = theStripRawDigis->find( detRawId );
1083  if( detSetIter == theStripRawDigis->end() ) {
1084  throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: No raw DetSet found for det: " << detRawId << "." << std::endl;
1085  }
1086 
1087  // fill the digis to the profiles
1088  edm::DetSet<SiStripRawDigi>::const_iterator digiRangeIterator = detSetIter->data.begin(); // for the loop
1089  edm::DetSet<SiStripRawDigi>::const_iterator digiRangeStart = digiRangeIterator; // save starting positions
1090 
1091  // loop all digis
1092  for (; digiRangeIterator != detSetIter->data.end(); ++digiRangeIterator ) {
1093  const SiStripRawDigi& digi = *digiRangeIterator;
1094  const int channel = distance( digiRangeStart, digiRangeIterator );
1095  if ( channel >= 0 && channel < 512 ) currentDataProfiles.GetTIBTOBEntry( det, beam, pos ).SetValue( channel, digi.adc() );
1096  else throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: raw digi channel: " << channel << " out of range for det: " << detRawId << "." << std::endl;
1097  }
1098 
1099  }
1100 
1101  else { // we have zero suppressed SiStripDigis
1102 
1103  // search the digis for the raw id
1104  edm::DetSetVector<SiStripDigi>::const_iterator detSetIter = theStripDigis->find( detRawId );
1105 
1106  // processed DetSets may be missing, just skip
1107  if( detSetIter == theStripDigis->end() ) continue;
1108 
1109  // fill the digis to the profiles
1110  edm::DetSet<SiStripDigi>::const_iterator digiRangeIterator = detSetIter->data.begin(); // for the loop
1111 
1112  for(; digiRangeIterator != detSetIter->data.end(); ++digiRangeIterator ) {
1113  const SiStripDigi& digi = *digiRangeIterator;
1114  if ( digi.strip() < 512 ) currentDataProfiles.GetTIBTOBEntry( det, beam, pos ).SetValue( digi.strip(), digi.adc() );
1115  else throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: digi strip: " << digi.strip() << " out of range for det: " << detRawId << "." << std::endl;
1116  }
1117 
1118  }
1119 
1120  } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
1121 
1122 
1123 
1124  // loop TEC AT modules
1125  det = 0; beam = 0; disk = 0;
1126  do {
1127 
1128  // first clear the profile
1130 
1131  // retrieve the raw id of that module
1132  const int detRawId = detectorId.GetTEC2TECEntry( det, beam, disk );
1133 
1134  if( isRawDigi ) { // we have raw SiStripRawDigis
1135 
1136  // search the digis for the raw id
1137  edm::DetSetVector<SiStripRawDigi>::const_iterator detSetIter = theStripRawDigis->find( detRawId );
1138  if( detSetIter == theStripRawDigis->end() ) {
1139  throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: No raw DetSet found for det: " << detRawId << "." << std::endl;
1140  }
1141 
1142  // fill the digis to the profiles
1143  edm::DetSet<SiStripRawDigi>::const_iterator digiRangeIterator = detSetIter->data.begin(); // for the loop
1144  edm::DetSet<SiStripRawDigi>::const_iterator digiRangeStart = digiRangeIterator; // save starting positions
1145 
1146  // loop all digis
1147  for (; digiRangeIterator != detSetIter->data.end(); ++digiRangeIterator ) {
1148  const SiStripRawDigi& digi = *digiRangeIterator;
1149  const int channel = distance( digiRangeStart, digiRangeIterator );
1150  if ( channel >= 0 && channel < 512 ) currentDataProfiles.GetTEC2TECEntry( det, beam, disk ).SetValue( channel, digi.adc() );
1151  else throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: raw digi channel: " << channel << " out of range for det: " << detRawId << "." << std::endl;
1152  }
1153 
1154  }
1155 
1156  else { // we have zero suppressed SiStripDigis
1157 
1158  // search the digis for the raw id
1159  edm::DetSetVector<SiStripDigi>::const_iterator detSetIter = theStripDigis->find( detRawId );
1160 
1161  // processed DetSets may be missing, just skip
1162  if( detSetIter == theStripDigis->end() ) continue;
1163 
1164  // fill the digis to the profiles
1165  edm::DetSet<SiStripDigi>::const_iterator digiRangeIterator = detSetIter->data.begin(); // for the loop
1166 
1167  for(; digiRangeIterator != detSetIter->data.end(); ++digiRangeIterator ) {
1168  const SiStripDigi& digi = *digiRangeIterator;
1169  if ( digi.strip() < 512 ) currentDataProfiles.GetTEC2TECEntry( det, beam, disk ).SetValue( digi.strip(), digi.adc() );
1170  else throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: digi strip: " << digi.strip() << " out of range for det: " << detRawId << "." << std::endl;
1171  }
1172 
1173  }
1174 
1175  } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
1176 
1177  } // theDigiProducersList loop
1178 
1179 }
1180 
1181 
1182 
1183 
1184 
1194 
1195  int det, ring, beam, disk, pos;
1196 
1197  // loop TEC modules (yet without AT)
1198  det = 0; ring = 0; beam = 0; disk = 0;
1199  do { // loop using LASGlobalLoop functionality
1200  SiStripPedestals::Range pedRange = pedestalsHandle->getRange( detectorId.GetTECEntry( det, ring, beam, disk ) );
1201  for( int strip = 0; strip < 512; ++strip ) {
1202  int thePedestal = int( pedestalsHandle->getPed( strip, pedRange ) );
1203  if( thePedestal > 895 ) thePedestal -= 1024;
1204  pedestalProfiles.GetTECEntry( det, ring, beam, disk ).SetValue( strip, thePedestal );
1205  }
1206  } while ( moduleLoop.TECLoop( det, ring, beam, disk ) );
1207 
1208 
1209  // TIB & TOB section
1210  det = 2; beam = 0; pos = 0;
1211  do { // loop using LASGlobalLoop functionality
1212  SiStripPedestals::Range pedRange = pedestalsHandle->getRange( detectorId.GetTIBTOBEntry( det, beam, pos ) );
1213  for( int strip = 0; strip < 512; ++strip ) {
1214  int thePedestal = int( pedestalsHandle->getPed( strip, pedRange ) );
1215  if( thePedestal > 895 ) thePedestal -= 1024;
1216  pedestalProfiles.GetTIBTOBEntry( det, beam, pos ).SetValue( strip, thePedestal );
1217  }
1218  } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
1219 
1220 
1221  // TEC2TEC AT section
1222  det = 0; beam = 0; disk = 0;
1223  do { // loop using LASGlobalLoop functionality
1224  SiStripPedestals::Range pedRange = pedestalsHandle->getRange( detectorId.GetTEC2TECEntry( det, beam, disk ) );
1225  for( int strip = 0; strip < 512; ++strip ) {
1226  int thePedestal = int( pedestalsHandle->getPed( strip, pedRange ) );
1227  if( thePedestal > 895 ) thePedestal -= 1024;
1228  pedestalProfiles.GetTEC2TECEntry( det, beam, disk ).SetValue( strip, thePedestal );
1229  }
1230  } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
1231 
1232 }
1233 
1234 
1235 
1236 
1237 
1244 
1245  int numberOfProfiles = 0;
1246 
1247  int ring = 1; // search all ring6 modules for signals
1248  for( int det = 0; det < 2; ++det ) {
1249  for( int beam = 0; beam < 8; ++ beam ) {
1250  for( int disk = 0; disk < 9; ++disk ) {
1251  if( isAcceptedProfile.GetTECEntry( det, ring, beam, disk ) == 1 ) numberOfProfiles++;
1252  }
1253  }
1254  }
1255 
1256  LogDebug( "[LaserAlignment::isTECBeam]" ) << " Found: " << numberOfProfiles << "hits." << std::endl;
1257  std::cout << " [LaserAlignment::isTECBeam] -- Found: " << numberOfProfiles << " hits." << std::endl;
1258 
1259  if( numberOfProfiles > 10 ) return( true );
1260  return( false );
1261 
1262 }
1263 
1264 
1265 
1266 
1267 
1273 
1275 
1276  int numberOfProfiles = 0;
1277 
1278  int det = 2; int beam = 0; int pos = 0; // search all TIB/TOB for signals
1279  do {
1280  if( isAcceptedProfile.GetTIBTOBEntry( det, beam, pos ) == 1 ) numberOfProfiles++;
1281  } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
1282 
1283  LogDebug( "[LaserAlignment::isATBeam]" ) << " Found: " << numberOfProfiles << "hits." << std::endl;
1284  std::cout << " [LaserAlignment::isATBeam] -- Found: " << numberOfProfiles << " hits." << std::endl;
1285 
1286  if( numberOfProfiles > 10 ) return( true );
1287  return( false );
1288 
1289 }
1290 
1291 
1292 
1293 
1294 
1303 double LaserAlignment::getTIBTOBNominalBeamOffset( unsigned int det, unsigned int beam, unsigned int pos ) {
1304 
1305  if( det < 2 || det > 3 || beam > 7 || pos > 5 ) {
1306  throw cms::Exception( "[LaserAlignment::getTIBTOBNominalBeamOffset]" ) << " ERROR ** Called with nonexisting parameter set: det " << det << " beam " << beam << " pos " << pos << "." << std::endl;
1307  }
1308 
1309  const double nominalOffsetsTIB[8] = { 0.00035, 2.10687, -2.10827, -0.00173446, 2.10072, -0.00135114, 2.10105, -2.10401 };
1310 
1311  // in tob, modules have alternating orientations along the rods.
1312  // this is described by the following pattern.
1313  // (even more confusing, this pattern is inversed for beams 0, 5, 6, 7)
1314  const int orientationPattern[6] = { -1, 1, 1, -1, -1, 1 };
1315  const double nominalOffsetsTOB[8] = { 0.00217408, 1.58678, 117.733, 119.321, 120.906, 119.328, 117.743, 1.58947 };
1316 
1317 
1318  if( det == 2 ) return( -1. * nominalOffsetsTIB[beam] );
1319 
1320  else {
1321  if( beam == 0 or beam > 4 ) return( nominalOffsetsTOB[beam] * orientationPattern[pos] );
1322  else return( -1. * nominalOffsetsTOB[beam] * orientationPattern[pos] );
1323  }
1324 
1325 }
1326 
1327 
1328 
1329 
1338 double LaserAlignment::getTEC2TECNominalBeamOffset( unsigned int det, unsigned int beam, unsigned int disk ) {
1339 
1340  if( det > 1 || beam > 7 || disk > 5 ) {
1341  throw cms::Exception( "[LaserAlignment::getTEC2TECNominalBeamOffset]" ) << " ERROR ** Called with nonexisting parameter set: det " << det << " beam " << beam << " disk " << disk << "." << std::endl;
1342  }
1343 
1344  const double nominalOffsets[8] = { 0., 2.220, -2.221, 0., 2.214, 0., 2.214, -2.217 };
1345 
1346  if( det == 0 ) return -1. * nominalOffsets[beam];
1347  else return nominalOffsets[beam];
1348 
1349 }
1350 
1351 
1352 
1353 
1354 
1359 
1360  //
1361  // hard coded data yet...
1362  //
1363 
1364  // nominal phi values of tec beam / alignment tube hits (parameter is beam 0-7)
1365  const double tecPhiPositions[8] = { 0.392699, 1.178097, 1.963495, 2.748894, 3.534292, 4.319690, 5.105088, 5.890486 }; // new values calculated by maple
1366  const double atPhiPositions[8] = { 0.392699, 1.289799, 1.851794, 2.748894, 3.645995, 4.319690, 5.216791, 5.778784 }; // new values calculated by maple
1367 
1368  // nominal r values (mm) of hits
1369  const double tobRPosition = 600.;
1370  const double tibRPosition = 514.;
1371  const double tecRPosition[2] = { 564., 840. }; // ring 4,6
1372 
1373  // nominal z values (mm) of hits in barrel (parameter is pos 0-6)
1374  const double tobZPosition[6] = { 1040., 580., 220., -140., -500., -860. };
1375  const double tibZPosition[6] = { 620., 380., 180., -100., -340., -540. };
1376 
1377  // nominal z values (mm) of hits in tec (parameter is disk 0-8); FOR TEC-: (* -1.)
1378  const double tecZPosition[9] = { 1322.5, 1462.5, 1602.5, 1742.5, 1882.5, 2057.5, 2247.5, 2452.5, 2667.5 };
1379 
1380 
1381  //
1382  // now we fill these into the nominalCoordinates container;
1383  // errors are zero for nominal values..
1384  //
1385 
1386  // loop object and its variables
1388  int det, ring, beam, disk, pos;
1389 
1390 
1391  // TEC+- section
1392  det = 0; ring = 0, beam = 0; disk = 0;
1393  do {
1394 
1395  if( det == 0 ) { // this is TEC+
1396  nominalCoordinates.SetTECEntry( det, ring, beam, disk, LASCoordinateSet( tecPhiPositions[beam], 0., tecRPosition[ring], 0., tecZPosition[disk], 0. ) );
1397  }
1398  else { // now TEC-
1399  nominalCoordinates.SetTECEntry( det, ring, beam, disk, LASCoordinateSet( tecPhiPositions[beam], 0., tecRPosition[ring], 0., -1. * tecZPosition[disk], 0. ) ); // just * -1.
1400  }
1401 
1402  } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
1403 
1404 
1405 
1406  // TIB & TOB section
1407  det = 2; beam = 0; pos = 0;
1408  do {
1409  if( det == 2 ) { // this is TIB
1410  nominalCoordinates.SetTIBTOBEntry( det, beam, pos, LASCoordinateSet( atPhiPositions[beam], 0., tibRPosition, 0., tibZPosition[pos], 0. ) );
1411  }
1412  else { // now TOB
1413  nominalCoordinates.SetTIBTOBEntry( det, beam, pos, LASCoordinateSet( atPhiPositions[beam], 0., tobRPosition, 0., tobZPosition[pos], 0. ) );
1414  }
1415 
1416  } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
1417 
1418 
1419 
1420 
1421  // TEC2TEC AT section
1422  det = 0; beam = 0; disk = 0;
1423  do {
1424 
1425  if( det == 0 ) { // this is TEC+, ring4 only
1426  nominalCoordinates.SetTEC2TECEntry( det, beam, disk, LASCoordinateSet( atPhiPositions[beam], 0., tecRPosition[0], 0., tecZPosition[disk], 0. ) );
1427  }
1428  else { // now TEC-
1429  nominalCoordinates.SetTEC2TECEntry( det, beam, disk, LASCoordinateSet( atPhiPositions[beam], 0., tecRPosition[0], 0., -1. * tecZPosition[disk], 0. ) ); // just * -1.
1430  }
1431 
1432  } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
1433 
1434 
1435 }
1436 
1437 
1438 
1439 
1440 
1446 
1447  if( angle < -1. * M_PI || angle > M_PI ) {
1448  throw cms::Exception(" [LaserAlignment::ConvertAngle] ") << "** ERROR: Called with illegal input angle: " << angle << "." << std::endl;
1449  }
1450 
1451  if( angle >= 0. ) return angle;
1452  else return( angle + 2. * M_PI );
1453 
1454 }
1455 
1456 
1457 
1458 
1459 
1464 
1466  int det, ring, beam, disk, pos;
1467 
1468  std:: cout << std::endl << " [LaserAlignment::DumpPosFileSet] -- Dump: " << std::endl;
1469 
1470  // TEC INTERNAL
1471  det = 0; ring = 0; beam = 0; disk = 0;
1472  do {
1473  std::cout << "POS " << det << "\t" << beam << "\t" << disk << "\t" << ring << "\t" << coordinates.GetTECEntry( det, ring, beam, disk ).GetPhi() << "\t" << coordinates.GetTECEntry( det, ring, beam, disk ).GetPhiError() << std::endl;
1474  } while ( loop.TECLoop( det, ring, beam, disk ) );
1475 
1476  // TIBTOB
1477  det = 2; beam = 0; pos = 0;
1478  do {
1479  std::cout << "POS " << det << "\t" << beam << "\t" << pos << "\t" << "-1" << "\t" << coordinates.GetTIBTOBEntry( det, beam, pos ).GetPhi() << "\t" << coordinates.GetTIBTOBEntry( det, beam, pos ).GetPhiError() << std::endl;
1480  } while( loop.TIBTOBLoop( det, beam, pos ) );
1481 
1482  // TEC2TEC
1483  det = 0; beam = 0; disk = 0;
1484  do {
1485  std::cout << "POS " << det << "\t" << beam << "\t" << disk << "\t" << "-1" << "\t" << coordinates.GetTEC2TECEntry( det, beam, disk ).GetPhi() << "\t" << coordinates.GetTEC2TECEntry( det, beam, disk ).GetPhiError() << std::endl;
1486  } while( loop.TEC2TECLoop( det, beam, disk ) );
1487 
1488  std:: cout << std::endl << " [LaserAlignment::DumpPosFileSet] -- End dump: " << std::endl;
1489 
1490 }
1491 
1492 
1493 
1494 
1495 
1499 void LaserAlignment::DumpStripFileSet( LASGlobalData<std::pair<float,float> >& measuredStripPositions ) {
1500 
1502  int det, ring, beam, disk, pos;
1503 
1504  std:: cout << std::endl << " [LaserAlignment::DumpStripFileSet] -- Dump: " << std::endl;
1505 
1506  // TEC INTERNAL
1507  det = 0; ring = 0; beam = 0; disk = 0;
1508  do {
1509  std::cout << "STRIP " << det << "\t" << beam << "\t" << disk << "\t" << ring << "\t" << measuredStripPositions.GetTECEntry( det, ring, beam, disk ).first
1510  << "\t" << measuredStripPositions.GetTECEntry( det, ring, beam, disk ).second << std::endl;
1511  } while ( loop.TECLoop( det, ring, beam, disk ) );
1512 
1513  // TIBTOB
1514  det = 2; beam = 0; pos = 0;
1515  do {
1516  std::cout << "STRIP " << det << "\t" << beam << "\t" << pos << "\t" << "-1" << "\t" << measuredStripPositions.GetTIBTOBEntry( det, beam, pos ).first
1517  << "\t" << measuredStripPositions.GetTIBTOBEntry( det, beam, pos ).second << std::endl;
1518  } while( loop.TIBTOBLoop( det, beam, pos ) );
1519 
1520  // TEC2TEC
1521  det = 0; beam = 0; disk = 0;
1522  do {
1523  std::cout << "STRIP " << det << "\t" << beam << "\t" << disk << "\t" << "-1" << "\t" << measuredStripPositions.GetTEC2TECEntry( det, beam, disk ).first
1524  << "\t" << measuredStripPositions.GetTEC2TECEntry( det, beam, disk ).second << std::endl;
1525  } while( loop.TEC2TECLoop( det, beam, disk ) );
1526 
1527  std:: cout << std::endl << " [LaserAlignment::DumpStripFileSet] -- End dump: " << std::endl;
1528 
1529 
1530 }
1531 
1532 
1533 
1534 
1535 
1539 void LaserAlignment::DumpHitmaps( LASGlobalData<int> &numberOfAcceptedProfiles ) {
1540 
1541  std::cout << " [LaserAlignment::DumpHitmaps] -- Dumping hitmap for TEC+:" << std::endl;
1542  std::cout << " [LaserAlignment::DumpHitmaps] -- Ring4:" << std::endl;
1543  std::cout << " disk0 disk1 disk2 disk3 disk4 disk5 disk6 disk7 disk8" << std::endl;
1544 
1545  for( int beam = 0; beam < 8; ++beam ) {
1546  std::cout << " beam" << beam << ":";
1547  for( int disk = 0; disk < 9; ++disk ) {
1548  std::cout << "\t" << numberOfAcceptedProfiles.GetTECEntry( 0, 0, beam, disk );
1549  }
1550  std::cout << std::endl;
1551  }
1552 
1553  std::cout << " [LaserAlignment::DumpHitmaps] -- Ring6:" << std::endl;
1554  std::cout << " disk0 disk1 disk2 disk3 disk4 disk5 disk6 disk7 disk8" << std::endl;
1555 
1556  for( int beam = 0; beam < 8; ++beam ) {
1557  std::cout << " beam" << beam << ":";
1558  for( int disk = 0; disk < 9; ++disk ) {
1559  std::cout << "\t" << numberOfAcceptedProfiles.GetTECEntry( 0, 1, beam, disk );
1560  }
1561  std::cout << std::endl;
1562  }
1563 
1564  std::cout << " [LaserAlignment::DumpHitmaps] -- Dumping hitmap for TEC-:" << std::endl;
1565  std::cout << " [LaserAlignment::DumpHitmaps] -- Ring4:" << std::endl;
1566  std::cout << " disk0 disk1 disk2 disk3 disk4 disk5 disk6 disk7 disk8" << std::endl;
1567 
1568  for( int beam = 0; beam < 8; ++beam ) {
1569  std::cout << " beam" << beam << ":";
1570  for( int disk = 0; disk < 9; ++disk ) {
1571  std::cout << "\t" << numberOfAcceptedProfiles.GetTECEntry( 1, 0, beam, disk );
1572  }
1573  std::cout << std::endl;
1574  }
1575 
1576  std::cout << " [LaserAlignment::DumpHitmaps] -- Ring6:" << std::endl;
1577  std::cout << " disk0 disk1 disk2 disk3 disk4 disk5 disk6 disk7 disk8" << std::endl;
1578 
1579  for( int beam = 0; beam < 8; ++beam ) {
1580  std::cout << " beam" << beam << ":";
1581  for( int disk = 0; disk < 9; ++disk ) {
1582  std::cout << "\t" << numberOfAcceptedProfiles.GetTECEntry( 1, 1, beam, disk );
1583  }
1584  std::cout << std::endl;
1585  }
1586 
1587  std::cout << " [LaserAlignment::DumpHitmaps] -- End of dump." << std::endl << std::endl;
1588 
1589 }
1590 
1591 
1592 
1593 
1594 
1600 
1601  // loop the list of modules to be masked
1602  for( std::vector<unsigned int>::iterator moduleIt = theMaskTecModules.begin(); moduleIt != theMaskTecModules.end(); ++moduleIt ) {
1603 
1604  // loop variables
1606  int det, ring, beam, disk;
1607 
1608  // this will calculate the corrections from the alignment parameters
1609  LASEndcapAlgorithm endcapAlgorithm;
1610 
1611  // find the location of the respective module in the container with this loop
1612  det = 0; ring = 0; beam = 0; disk = 0;
1613  do {
1614 
1615  // here we got it
1616  if( detectorId.GetTECEntry( det, ring, beam, disk ) == *moduleIt ) {
1617 
1618  // the nominal phi value for this module
1619  const double nominalPhi = nominalCoordinates.GetTECEntry( det, ring, beam, disk ).GetPhi();
1620 
1621  // the offset from the alignment parameters
1622  const double phiCorrection = endcapAlgorithm.GetAlignmentParameterCorrection( det, ring, beam, disk, nominalCoordinates, endcapParameters );
1623 
1624  // apply the corrections
1625  measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhi( nominalPhi - phiCorrection );
1626 
1627  }
1628 
1629  } while ( moduleLoop.TECLoop( det, ring, beam, disk ) );
1630 
1631  }
1632 
1633 }
1634 
1635 
1636 
1637 
1638 
1644 
1645  // loop the list of modules to be masked
1646  for( std::vector<unsigned int>::iterator moduleIt = theMaskAtModules.begin(); moduleIt != theMaskAtModules.end(); ++moduleIt ) {
1647 
1648  // loop variables
1650  int det, beam, disk, pos;
1651 
1652  // this will calculate the corrections from the alignment parameters
1653  LASAlignmentTubeAlgorithm atAlgorithm;
1654 
1655 
1656  // find the location of the respective module in the container with these loops:
1657 
1658  // first TIB+TOB
1659  det = 2; beam = 0; pos = 0;
1660  do {
1661 
1662  // here we got it
1663  if( detectorId.GetTIBTOBEntry( det, beam, pos ) == *moduleIt ) {
1664 
1665  // the nominal phi value for this module
1666  const double nominalPhi = nominalCoordinates.GetTIBTOBEntry( det, beam, pos ).GetPhi();
1667 
1668  // the offset from the alignment parameters
1669  const double phiCorrection = atAlgorithm.GetTIBTOBAlignmentParameterCorrection( det, beam, pos, nominalCoordinates, atParameters );
1670 
1671  // apply the corrections
1672  measuredCoordinates.GetTIBTOBEntry( det, beam, pos ).SetPhi( nominalPhi - phiCorrection );
1673 
1674  }
1675 
1676  } while ( moduleLoop.TIBTOBLoop( det, beam, pos ) );
1677 
1678 
1679 
1680  // then TEC(AT)
1681  det = 0; beam = 0; disk = 0;
1682  do {
1683 
1684  // here we got it
1685  if( detectorId.GetTEC2TECEntry( det, beam, disk ) == *moduleIt ) {
1686 
1687  // the nominal phi value for this module
1688  const double nominalPhi = nominalCoordinates.GetTEC2TECEntry( det, beam, disk ).GetPhi();
1689 
1690  // the offset from the alignment parameters
1691  const double phiCorrection = atAlgorithm.GetTEC2TECAlignmentParameterCorrection( det, beam, disk, nominalCoordinates, atParameters );
1692 
1693  // apply the corrections
1694  measuredCoordinates.GetTEC2TECEntry( det, beam, disk ).SetPhi( nominalPhi - phiCorrection );
1695 
1696  }
1697 
1698  } while ( moduleLoop.TEC2TECLoop( det, beam, disk ) );
1699 
1700  }
1701 
1702 }
1703 
1704 
1705 
1706 
1707 
1713 
1714 
1715  // tracker geom. object for calculating the global beam positions
1716  const TrackerGeometry& theTracker( *theTrackerGeometry );
1717 
1718  const double atPhiPositions[8] = { 0.392699, 1.289799, 1.851794, 2.748894, 3.645995, 4.319690, 5.216791, 5.778784 };
1719  const double tecPhiPositions[8] = { 0.392699, 1.178097, 1.963495, 2.748894, 3.534292, 4.319690, 5.105088, 5.890486 };
1720  const double zPositions[9] = { 125.0, 139.0, 153.0, 167.0, 181.0, 198.5, 217.5, 238.0, 259.5 };
1721  const double zPositionsTIB[6] = { 62.0, 38.0, 18.0, -10.0, -34.0, -54.0 };
1722  const double zPositionsTOB[6] = { 104.0, 58.0, 22.0, -14.0, -50.0, -86.0 };
1723 
1724  int det, beam, disk, pos, ring;
1725 
1726  // loop TEC+- internal
1727  det = 0; ring = 0; beam = 0; disk = 0;
1728  do {
1729 
1730  const double radius = ring?84.0:56.4;
1731 
1732  // access the tracker geometry for this module
1733  const DetId theDetId( detectorId.GetTECEntry( det, ring, beam, disk ) );
1734  const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
1735 
1736  if (theStripDet) {
1737  const GlobalPoint gp( GlobalPoint::Cylindrical( radius, tecPhiPositions[beam], zPositions[disk] ) );
1738 
1739  const LocalPoint lp( theStripDet->surface().toLocal( gp ) );
1740  std::cout << "__TEC: " << 256. - theStripDet->specificTopology().strip( lp ) << std::endl;
1741  }
1742 
1743  } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
1744 
1745 
1746  // loop TIBTOB
1747  det = 2; beam = 0; pos = 0;
1748  do {
1749 
1750  const double radius = (det==2?51.4:58.4);
1751  const double theZ = (det==2?zPositionsTIB[pos]:zPositionsTOB[pos]);
1752 
1753  // access the tracker geometry for this module
1754  const DetId theDetId( detectorId.GetTIBTOBEntry( det, beam, pos ) );
1755  const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
1756 
1757  if (theStripDet) {
1758  const GlobalPoint gp( GlobalPoint::Cylindrical( radius, atPhiPositions[beam], theZ ) );
1759 
1760  const LocalPoint lp( theStripDet->surface().toLocal( gp ) );
1761  std::cout << "__TIBTOB det " << det << " beam " << beam << " pos " << pos << " " << 256. - theStripDet->specificTopology().strip( lp );
1762  std::cout << " " << theStripDet->position().perp()<< std::endl;
1763  }
1764 
1765  } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
1766 
1767 
1768  // loop TEC2TEC
1769  det = 0; beam = 0; disk = 0;
1770  do {
1771 
1772  const double radius = 56.4;
1773 
1774  // access the tracker geometry for this module
1775  const DetId theDetId( detectorId.GetTEC2TECEntry( det, beam, disk ) );
1776  const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
1777 
1778  if (theStripDet) {
1779  const GlobalPoint gp( GlobalPoint::Cylindrical( radius, atPhiPositions[beam], zPositions[disk] ) );
1780 
1781  const LocalPoint lp( theStripDet->surface().toLocal( gp ) );
1782  std::cout << "__TEC2TEC det " << det << " beam " << beam << " disk " << disk << " " << 256. - theStripDet->specificTopology().strip( lp ) << std::endl;
1783  }
1784 
1785  } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
1786 
1787 
1788 }
1789 
1790 
1791 
1792 
1793 
1794 
1795 
1796 
1797 
1798 // define the SEAL module
1800 
1802 
1803 
1804 
1805 
1806 // the ATTIC
1807 
#define LogDebug(id)
RunNumber_t run() const
Definition: EventID.h:39
bool IsSignalIn(const LASModuleProfile &, double)
bool isATBeam(void)
void SetTEC2TECEntry(int subdetector, int beam, int tecDisk, T)
T theZ
void SetPhi(double aPhi)
const uint16_t & adc() const
T getParameter(std::string const &) const
EventNumber_t event() const
Definition: EventID.h:41
unsigned int judgeOverdriveThreshold
config parameters for the LASProfileJudge
void fillDataProfiles(edm::Event const &, edm::EventSetup const &)
fill profiles from SiStrip(Raw)Digi container
virtual void beginJob() override
const edm::ParameterSet theParameterSet
bool theSaveHistograms
config switch
void SetPhiError(double aPhiError)
void ApplyEndcapMaskingCorrections(LASGlobalData< LASCoordinateSet > &, LASGlobalData< LASCoordinateSet > &, LASEndcapAlignmentParameterSet &)
apply endcap correction to masked modules in TEC
virtual void produce(edm::Event &, edm::EventSetup const &) override
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventIDconst &, edm::Timestampconst & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
void TrackerUpdate(LASEndcapAlignmentParameterSet &, LASBarrelAlignmentParameterSet &, AlignableTracker &)
void SetMisalignmentFromRefGeometry(bool)
bool misalignedByRefGeometry
config switch
std::string theAlignRecordName
#define DEFINE_FWK_MODULE(type)
Definition: MakerMacros.h:17
bool isTECBeam(void)
decide whether TEC or AT beams have fired
TrackerGeometry * build(const GeometricDet *gd, const edm::ParameterSet &pSet)
LaserAlignment(edm::ParameterSet const &theConf)
double getTIBTOBNominalBeamOffset(unsigned int, unsigned int, unsigned int)
returns the nominal beam position (strips) in TOB for the profileJudge
edm::ESHandle< TrackerGeometry > theTrackerGeometry
double peakFinderThreshold
config parameter
void DumpHitmaps(LASGlobalData< int > &)
for debugging only, will disappear
void DumpPosFileSet(LASGlobalData< LASCoordinateSet > &)
for debugging only, will disappear
LASGlobalData< int > numberOfAcceptedProfiles
void SetAllValuesTo(const double &)
int loop
CMSSW
std::pair< ContainerIterator, ContainerIterator > Range
bool theDoPedestalSubtraction
config switch
LASGlobalData< LASModuleProfile > currentDataProfiles
data profiles for the current event
std::vector< unsigned int > theMaskTecModules
config parameters
bool theUseMinuitAlgorithm
config switch
TFile * theFile
Tree stuff.
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:7
LASGlobalData< int > isAcceptedProfile
std::vector< edm::ParameterSet > theDigiProducersList
void DumpStripFileSet(LASGlobalData< std::pair< float, float > > &)
for debugging only, will disappear
void fillPedestalProfiles(edm::ESHandle< SiStripPedestals > &)
fill pedestals from dbase
double GetPhi(void) const
Handle< TkLasBeamCollection > laserBeams
T barePhi() const
Definition: PV3DBase.h:68
LASGlobalData< TH1D * > summedHistograms
bool FindPeakIn(const LASModuleProfile &, std::pair< double, double > &, TH1D *, const double)
TDirectory * singleModulesDir
void push_back(const SiStripLaserRecHit2D &aHit)
insert a hit in the data vector
Definition: TkLasBeam.h:37
tuple iteration
Definition: align_cfg.py:5
double ConvertAngle(double)
convert an angle in the [-pi,pi] range to the [0,2*pi] range
LASBarrelAlignmentParameterSet CalculateParameters(LASGlobalData< LASCoordinateSet > &, LASGlobalData< LASCoordinateSet > &)
edm::ESHandle< Alignments > theGlobalPositionRcd
const uint16_t & strip() const
Definition: SiStripDigi.h:40
bool TEC2TECLoop(int &, int &, int &) const
std::string theFileName
config parameter (histograms file output name)
void get(HolderT &iHolder) const
bool isAvailable() const
Definition: Service.h:46
AlignmentErrors * alignmentErrors() const
Return alignment errors, sorted by DetId.
virtual void endJob() override
std::vector< unsigned int > tecDoubleHitDetId
void writeOne(T *payload, Time_t time, const std::string &recordName, bool withlogging=false)
void SetAmplitudeThreshold(double)
virtual void endRunProduce(edm::Run &, const edm::EventSetup &) override
bool theApplyBeamKinkCorrections
config switch
T & GetTIBTOBEntry(int subdetector, int beam, int tibTobPosition)
bool JudgeProfile(const LASModuleProfile &, double)
A Digi for the silicon strip detector, containing both strip and adc information, and suitable for st...
Definition: SiStripDigi.h:12
void SetTIBTOBEntry(int subdetector, int beam, int tibTobPosition, T)
bool getByLabel(InputTag const &tag, Handle< PROD > &result) const
Definition: Event.h:402
void CalculateNominalCoordinates(void)
fills a LASGlobalData&lt;LASCoordinateSet&gt; with nominal module positions
iterator end()
Return the off-the-end iterator.
Definition: DetSetVector.h:365
#define M_PI
LASEndcapAlignmentParameterSet CalculateParameters(LASGlobalData< LASCoordinateSet > &, LASGlobalData< LASCoordinateSet > &)
std::string theErrorRecordName
double GetTEC2TECAlignmentParameterCorrection(int, int, int, LASGlobalData< LASCoordinateSet > &, LASBarrelAlignmentParameterSet &)
void SetValue(unsigned int theStripNumber, const double &theValue)
bool theStoreToDB
config switch
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:17
Definition: DetId.h:18
LASGlobalData< LASModuleProfile > pedestalProfiles
T & GetTEC2TECEntry(int subdetector, int beam, int tecDisk)
LASGlobalData< LASCoordinateSet > nominalCoordinates
AlignableTracker * theAlignableTracker
int theEvents
counter for the total number of events processed
const T & get() const
Definition: EventSetup.h:55
LASBarrelAlignmentParameterSet CalculateParameters(LASGlobalData< LASCoordinateSet > &, LASGlobalData< LASCoordinateSet > &)
LASConstants theLasConstants
double getTEC2TECNominalBeamOffset(unsigned int, unsigned int, unsigned int)
returns the nominal beam position (strips) in TEC (AT) for the profileJudge
T const * product() const
Definition: ESHandle.h:86
void SetOverdriveThreshold(unsigned int)
T & GetTECEntry(int subdetector, int tecRing, int beam, int tecDisk)
Definition: LASGlobalData.h:91
LASGlobalData< std::string > theProfileNames
double GetAlignmentParameterCorrection(int, int, int, int, LASGlobalData< LASCoordinateSet > &, LASEndcapAlignmentParameterSet &)
std::vector< unsigned int > theMaskAtModules
void ApplyATMaskingCorrections(LASGlobalData< LASCoordinateSet > &, LASGlobalData< LASCoordinateSet > &, LASBarrelAlignmentParameterSet &)
same for alignment tube modules
void testRoutine(void)
for debugging &amp; testing only, will disappear..
LASGlobalData< LASModuleProfile > collectedDataProfiles
edm::EventID id() const
Definition: EventBase.h:56
void fillDetectorId(void)
fill hard coded detIds
void ApplyBeamKinkCorrections(LASGlobalData< LASCoordinateSet > &) const
int theCompression
config parameter (histograms file compression level)
void EnableZeroFilter(bool)
LASGlobalData< unsigned int > detectorId
bool TECLoop(int &, int &, int &, int &) const
bool TIBTOBLoop(int &, int &, int &) const
double GetPhiError(void) const
tuple cout
Definition: gather_cfg.py:121
void put(std::auto_ptr< PROD > product)
Put a new product.
Definition: Run.h:107
std::vector< TkLasBeam > TkLasBeamCollection
iterator begin()
Return an iterator to the first DetSet.
Definition: DetSetVector.h:350
bool enableJudgeZeroFilter
config switch
volatile std::atomic< bool > shutdown_flag false
Alignments * alignments() const
Return alignments, sorted by DetId.
collection_type::const_iterator const_iterator
Definition: DetSet.h:33
collection_type::const_iterator const_iterator
Definition: DetSetVector.h:108
const uint16_t & adc() const
Definition: SiStripDigi.h:41
A Digi for the silicon strip detector, containing only adc information, and suitable for storing raw ...
double GetTIBTOBAlignmentParameterCorrection(int, int, int, LASGlobalData< LASCoordinateSet > &, LASBarrelAlignmentParameterSet &)
void SetTECEntry(int subdetector, int tecRing, int beam, int tecDisk, T)
edm::ESHandle< GeometricDet > gD
tracker geometry;
void EndcapUpdate(LASEndcapAlignmentParameterSet &, LASGlobalData< LASCoordinateSet > &)
Definition: Run.h:41
virtual const TrackerGeomDet * idToDet(DetId) const
LASGlobalLoop moduleLoop
LASProfileJudge judge
bool updateFromInputGeometry
config switch
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11
bool theSetNominalStrips
config switch