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