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