CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_6_1_2_SLHC4_patch1/src/Alignment/LaserAlignment/plugins/LaserAlignment.cc

Go to the documentation of this file.
00001 
00010 #include "Alignment/LaserAlignment/plugins/LaserAlignment.h"
00011 #include "FWCore/Framework/interface/Run.h"
00012 
00013 
00014 
00015 
00019 LaserAlignment::LaserAlignment( edm::ParameterSet const& theConf ) :
00020   theEvents(0), 
00021   theDoPedestalSubtraction( theConf.getUntrackedParameter<bool>( "SubtractPedestals", true ) ),
00022   theUseMinuitAlgorithm( theConf.getUntrackedParameter<bool>( "RunMinuitAlignmentTubeAlgorithm", false ) ),
00023   theApplyBeamKinkCorrections( theConf.getUntrackedParameter<bool>( "ApplyBeamKinkCorrections", true ) ),
00024   peakFinderThreshold( theConf.getUntrackedParameter<double>( "PeakFinderThreshold", 10. ) ),
00025   enableJudgeZeroFilter( theConf.getUntrackedParameter<bool>( "EnableJudgeZeroFilter", true ) ),
00026   judgeOverdriveThreshold( theConf.getUntrackedParameter<unsigned int>( "JudgeOverdriveThreshold", 220 ) ),
00027   updateFromInputGeometry( theConf.getUntrackedParameter<bool>( "UpdateFromInputGeometry", false ) ),
00028   misalignedByRefGeometry( theConf.getUntrackedParameter<bool>( "MisalignedByRefGeometry", false ) ),
00029   theStoreToDB ( theConf.getUntrackedParameter<bool>( "SaveToDbase", false ) ),
00030   theDigiProducersList( theConf.getParameter<std::vector<edm::ParameterSet> >( "DigiProducersList" ) ),
00031   theSaveHistograms( theConf.getUntrackedParameter<bool>( "SaveHistograms", false ) ),
00032   theCompression( theConf.getUntrackedParameter<int>( "ROOTFileCompression", 1 ) ),
00033   theFileName( theConf.getUntrackedParameter<std::string>( "ROOTFileName", "test.root" ) ),
00034   theMaskTecModules( theConf.getUntrackedParameter<std::vector<unsigned int> >( "MaskTECModules" ) ),
00035   theMaskAtModules( theConf.getUntrackedParameter<std::vector<unsigned int> >( "MaskATModules" ) ),
00036   theSetNominalStrips( theConf.getUntrackedParameter<bool>( "ForceFitterToNominalStrips", false ) ),
00037   theLasConstants( theConf.getUntrackedParameter<std::vector<edm::ParameterSet> >( "LaserAlignmentConstants" ) ),
00038   theFile(),
00039   theAlignableTracker(),
00040   theAlignRecordName( "TrackerAlignmentRcd" ),
00041   theErrorRecordName( "TrackerAlignmentErrorRcd" ),
00042   firstEvent_(true),
00043   theParameterSet( theConf )
00044 {
00045 
00046 
00047   std::cout << std::endl;
00048   std::cout <<   "=============================================================="
00049             << "\n===         LaserAlignment module configuration            ==="
00050             << "\n"
00051             << "\n    Write histograms to file       = " << (theSaveHistograms?"true":"false")
00052             << "\n    Histogram file name            = " << theFileName
00053             << "\n    Histogram file compression     = " << theCompression
00054             << "\n    Subtract pedestals             = " << (theDoPedestalSubtraction?"true":"false")
00055             << "\n    Run Minuit AT algorithm        = " << (theUseMinuitAlgorithm?"true":"false")
00056             << "\n    Apply beam kink corrections    = " << (theApplyBeamKinkCorrections?"true":"false")
00057             << "\n    Peak Finder Threshold          = " << peakFinderThreshold
00058             << "\n    EnableJudgeZeroFilter          = " << (enableJudgeZeroFilter?"true":"false")
00059             << "\n    JudgeOverdriveThreshold        = " << judgeOverdriveThreshold
00060             << "\n    Update from input geometry     = " << (updateFromInputGeometry?"true":"false")
00061             << "\n    Misalignment from ref geometry = " << (misalignedByRefGeometry?"true":"false")
00062             << "\n    Number of TEC modules masked   = " << theMaskTecModules.size() << " (s. below list if > 0)"
00063             << "\n    Number of AT modules masked    = " << theMaskAtModules.size()  << " (s. below list if > 0)"
00064             << "\n    Store to database              = " << (theStoreToDB?"true":"false")
00065             << "\n    ----------------------------------------------- ----------"
00066             << (theSetNominalStrips?"\n    Set strips to nominal       =  true":"\n")
00067             << "\n=============================================================" << std::endl;
00068 
00069   // tell about masked modules
00070   if( theMaskTecModules.size() ) {
00071     std::cout << " ===============================================================================================\n" << std::flush;
00072     std::cout << " The following " << theMaskTecModules.size() << " TEC modules have been masked out and will not be considered by the TEC algorithm:\n " << std::flush;
00073     for( std::vector<unsigned int>::iterator moduleIt = theMaskTecModules.begin(); moduleIt != theMaskTecModules.end(); ++moduleIt ) {
00074       std::cout << *moduleIt << (moduleIt!=--theMaskTecModules.end()?", ":"") << std::flush;
00075     }
00076     std::cout << std::endl << std::flush;
00077     std::cout << " ===============================================================================================\n\n" << std::flush;
00078   }
00079   if( theMaskAtModules.size() ) {
00080     std::cout << " ===============================================================================================\n" << std::flush;
00081     std::cout << " The following " << theMaskAtModules.size() << " AT modules have been masked out and will not be considered by the AT algorithm:\n " << std::flush;
00082     for( std::vector<unsigned int>::iterator moduleIt = theMaskAtModules.begin(); moduleIt != theMaskAtModules.end(); ++moduleIt ) {
00083       std::cout << *moduleIt << (moduleIt!=--theMaskAtModules.end()?", ":"") << std::flush;
00084     }
00085     std::cout << std::endl << std::flush;
00086     std::cout << " ===============================================================================================\n\n" << std::flush;
00087   }
00088   
00089 
00090 
00091   // alias for the Branches in the root files
00092   std::string alias ( theConf.getParameter<std::string>("@module_label") );  
00093 
00094   // declare the product to produce
00095   produces<TkLasBeamCollection, edm::InRun>( "tkLaserBeams" ).setBranchAlias( alias + "TkLasBeamCollection" );
00096 
00097   // switch judge's zero filter depending on cfg
00098   judge.EnableZeroFilter( enableJudgeZeroFilter );
00099 
00100   // set the upper threshold for zero suppressed data
00101   judge.SetOverdriveThreshold( judgeOverdriveThreshold );
00102 
00103 }
00104 
00105 
00106 
00107 
00108 
00112 LaserAlignment::~LaserAlignment() {
00113 
00114   if ( theSaveHistograms ) theFile->Write();
00115   if ( theFile ) { delete theFile; }
00116   if ( theAlignableTracker ) { delete theAlignableTracker; }
00117 
00118 }
00119 
00120 
00121 
00122 
00123 
00127 void LaserAlignment::beginJob() {
00128 
00129 
00130   // write sumed histograms to file (if selected in cfg)
00131   if( theSaveHistograms ) {
00132 
00133     // creating a new file
00134     theFile = new TFile( theFileName.c_str(), "RECREATE", "CMS ROOT file" );
00135     
00136     // initialize the histograms
00137     if ( theFile ) {
00138       theFile->SetCompressionLevel(theCompression);
00139       singleModulesDir = theFile->mkdir( "single modules" );
00140     } else 
00141       throw cms::Exception( " [LaserAlignment::beginJob]") << " ** ERROR: could not open file:"
00142                                                            << theFileName.c_str() << " for writing." << std::endl;
00143 
00144   }
00145 
00146   // detector id maps (hard coded)
00147   fillDetectorId();
00148 
00149   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00150   //   PROFILE, HISTOGRAM & FITFUNCTION INITIALIZATION
00151   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00152 
00153   // object used to build various strings for names and labels
00154   std::stringstream nameBuilder;
00155 
00156   // loop variables for use with LASGlobalLoop object
00157   int det, ring, beam, disk, pos;
00158 
00159   // loop TEC modules
00160   det = 0; ring = 0; beam = 0; disk = 0;
00161   do { // loop using LASGlobalLoop functionality
00162     // init the profiles
00163     pedestalProfiles.GetTECEntry( det, ring, beam, disk ).SetAllValuesTo( 0. );
00164     currentDataProfiles.GetTECEntry( det, ring, beam, disk ).SetAllValuesTo( 0. );
00165     collectedDataProfiles.GetTECEntry( det, ring, beam, disk ).SetAllValuesTo( 0. );
00166 
00167     // init the hit maps
00168     isAcceptedProfile.SetTECEntry( det, ring, beam, disk, 0 );
00169     numberOfAcceptedProfiles.SetTECEntry( det, ring, beam, disk, 0 );
00170 
00171     // create strings for histo names
00172     nameBuilder.clear();
00173     nameBuilder.str( "" );
00174     nameBuilder << "TEC";
00175     if( det == 0 ) nameBuilder << "+"; else nameBuilder << "-";
00176     nameBuilder << "_Ring";
00177     if( ring == 0 ) nameBuilder << "4"; else nameBuilder << "6";
00178     nameBuilder << "_Beam" << beam;
00179     nameBuilder << "_Disk" << disk;
00180     theProfileNames.SetTECEntry( det, ring, beam, disk, nameBuilder.str() );
00181 
00182     // init the histograms
00183     if( theSaveHistograms ) {
00184       nameBuilder << "_Histo";
00185       summedHistograms.SetTECEntry( det, ring, beam, disk, new TH1D( nameBuilder.str().c_str(), nameBuilder.str().c_str(), 512, 0, 512 ) );
00186       summedHistograms.GetTECEntry( det, ring, beam, disk )->SetDirectory( singleModulesDir );
00187     }
00188     
00189   } while ( moduleLoop.TECLoop( det, ring, beam, disk ) );
00190 
00191 
00192   // TIB & TOB section
00193   det = 2; beam = 0; pos = 0;
00194   do { // loop using LASGlobalLoop functionality
00195     // init the profiles
00196     pedestalProfiles.GetTIBTOBEntry( det, beam, pos ).SetAllValuesTo( 0. );
00197     currentDataProfiles.GetTIBTOBEntry( det, beam, pos ).SetAllValuesTo( 0. );
00198     collectedDataProfiles.GetTIBTOBEntry( det, beam, pos ).SetAllValuesTo( 0. );
00199 
00200     // init the hit maps
00201     isAcceptedProfile.SetTIBTOBEntry( det, beam, pos, 0 );
00202     numberOfAcceptedProfiles.SetTIBTOBEntry( det, beam, pos, 0 );
00203 
00204     // create strings for histo names
00205     nameBuilder.clear();
00206     nameBuilder.str( "" );
00207     if( det == 2 ) nameBuilder << "TIB"; else nameBuilder << "TOB";
00208     nameBuilder << "_Beam" << beam;
00209     nameBuilder << "_Zpos" << pos;
00210 
00211     theProfileNames.SetTIBTOBEntry( det, beam, pos, nameBuilder.str() );
00212 
00213     // init the histograms
00214     if( theSaveHistograms ) {
00215       nameBuilder << "_Histo";
00216       summedHistograms.SetTIBTOBEntry( det, beam, pos, new TH1D( nameBuilder.str().c_str(), nameBuilder.str().c_str(), 512, 0, 512 ) );
00217       summedHistograms.GetTIBTOBEntry( det, beam, pos )->SetDirectory( singleModulesDir );
00218     }
00219     
00220   } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
00221 
00222 
00223   // TEC2TEC AT section
00224   det = 0; beam = 0; disk = 0;
00225   do { // loop using LASGlobalLoop functionality
00226     // init the profiles
00227     pedestalProfiles.GetTEC2TECEntry( det, beam, disk ).SetAllValuesTo( 0. );
00228     currentDataProfiles.GetTEC2TECEntry( det, beam, disk ).SetAllValuesTo( 0. );
00229     collectedDataProfiles.GetTEC2TECEntry( det, beam, disk ).SetAllValuesTo( 0. );
00230     
00231     // init the hit maps
00232     isAcceptedProfile.SetTEC2TECEntry( det, beam, disk, 0 );
00233     numberOfAcceptedProfiles.SetTEC2TECEntry( det, beam, disk, 0 );
00234 
00235     // create strings for histo names
00236     nameBuilder.clear();
00237     nameBuilder.str( "" );
00238     nameBuilder << "TEC(AT)";
00239     if( det == 0 ) nameBuilder << "+"; else nameBuilder << "-";
00240     nameBuilder << "_Beam" << beam;
00241     nameBuilder << "_Disk" << disk;
00242     theProfileNames.SetTEC2TECEntry( det, beam, disk, nameBuilder.str() );
00243 
00244     // init the histograms
00245     if( theSaveHistograms ) {
00246       nameBuilder << "_Histo";
00247       summedHistograms.SetTEC2TECEntry( det, beam, disk, new TH1D( nameBuilder.str().c_str(), nameBuilder.str().c_str(), 512, 0, 512 ) );
00248       summedHistograms.GetTEC2TECEntry( det, beam, disk )->SetDirectory( singleModulesDir );
00249     }
00250     
00251   } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
00252 
00253   firstEvent_ = true;
00254 }
00255 
00256 
00257 
00258 
00259 
00260 
00264 void LaserAlignment::produce(edm::Event& theEvent, edm::EventSetup const& theSetup)  {
00265 
00266   if (firstEvent_) {
00267 
00268     // access the tracker
00269     theSetup.get<TrackerDigiGeometryRecord>().get( theTrackerGeometry );
00270     theSetup.get<IdealGeometryRecord>().get( gD );
00271     
00272     // access pedestals (from db..) if desired
00273     edm::ESHandle<SiStripPedestals> pedestalsHandle;
00274     if( theDoPedestalSubtraction ) {
00275       theSetup.get<SiStripPedestalsRcd>().get( pedestalsHandle );
00276       fillPedestalProfiles( pedestalsHandle );
00277     }
00278     
00279     // global positions
00280     //  edm::ESHandle<Alignments> theGlobalPositionRcd;
00281     theSetup.get<TrackerDigiGeometryRecord>().getRecord<GlobalPositionRcd>().get( theGlobalPositionRcd );
00282 
00283     // select the reference geometry
00284     if( !updateFromInputGeometry ) {
00285       // the AlignableTracker object is initialized with the ideal geometry
00286       edm::ESHandle<GeometricDet> theGeometricDet;
00287       theSetup.get<IdealGeometryRecord>().get(theGeometricDet);
00288       TrackerGeomBuilderFromGeometricDet trackerBuilder;
00289       TrackerGeometry* theRefTracker = trackerBuilder.build(&*theGeometricDet, theParameterSet);
00290       
00291       theAlignableTracker = new AlignableTracker(&(*theRefTracker));
00292     }
00293     else {
00294       // the AlignableTracker object is initialized with the input geometry from DB
00295       theAlignableTracker = new AlignableTracker( &(*theTrackerGeometry) );
00296     }
00297     
00298     firstEvent_ = false;
00299   }
00300 
00301   LogDebug("LaserAlignment") << "==========================================================="
00302                               << "\n   Private analysis of event #"<< theEvent.id().event() 
00303                               << " in run #" << theEvent.id().run();
00304 
00305 
00306   // do the Tracker Statistics to retrieve the current profiles
00307   fillDataProfiles( theEvent, theSetup );
00308 
00309   // index variables for the LASGlobalLoop object
00310   int det, ring, beam, disk, pos;
00311 
00312   //
00313   // first pre-loop on selected entries to find out
00314   // whether the TEC or the AT beams have fired
00315   // (pedestal profiles are left empty if false in cfg)
00316   // 
00317 
00318 
00319   // TEC+- (only ring 6)
00320   ring = 1;
00321   for( det = 0; det < 2; ++det ) {
00322     for( beam = 0; beam < 8; ++ beam ) {
00323       for( disk = 0; disk < 9; ++disk ) {
00324         if( judge.IsSignalIn( currentDataProfiles.GetTECEntry( det, ring, beam, disk ) - pedestalProfiles.GetTECEntry( det, ring, beam, disk ), 0 ) ) {
00325           isAcceptedProfile.SetTECEntry( det, ring, beam, disk, 1 );
00326         }
00327         else { // assume no initialization
00328           isAcceptedProfile.SetTECEntry( det, ring, beam, disk, 0 );
00329         }
00330       }
00331     }
00332   }
00333 
00334   // TIBTOB
00335   det = 2; beam = 0; pos = 0;
00336   do {
00337     // add current event's data and subtract pedestals
00338     if( judge.IsSignalIn( currentDataProfiles.GetTIBTOBEntry( det, beam, pos ) - pedestalProfiles.GetTIBTOBEntry( det, beam, pos ), getTIBTOBNominalBeamOffset( det, beam, pos ) ) ) {
00339       isAcceptedProfile.SetTIBTOBEntry( det, beam, pos, 1 );
00340     }
00341     else { // dto.
00342       isAcceptedProfile.SetTIBTOBEntry( det, beam, pos, 0 );
00343     }
00344 
00345   } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
00346 
00347 
00348 
00349 
00350   // now come the beam finders
00351   bool isTECMode = isTECBeam();
00352   //  LogDebug( " [LaserAlignment::produce]" ) << "LaserAlignment::isTECBeam declares this event " << ( isTECMode ? "" : "NOT " ) << "a TEC event." << std::endl;
00353   std::cout << " [LaserAlignment::produce] -- LaserAlignment::isTECBeam declares this event " << ( isTECMode ? "" : "NOT " ) << "a TEC event." << std::endl;
00354 
00355   bool isATMode  = isATBeam();
00356   //  LogDebug( " [LaserAlignment::produce]" ) << "LaserAlignment::isATBeam declares this event "  << ( isATMode ? "" : "NOT " )  << "an AT event." << std::endl;
00357   std::cout << " [LaserAlignment::produce] -- LaserAlignment::isATBeam declares this event "  << ( isATMode ? "" : "NOT " )  << "an AT event." << std::endl;
00358 
00359 
00360 
00361 
00362   //
00363   // now pass the pedestal subtracted profiles to the judge
00364   // if they're accepted, add them on the collectedDataProfiles
00365   // (pedestal profiles are left empty if false in cfg)
00366   //
00367 
00368 
00369   // loop TEC+- modules
00370   det = 0; ring = 0; beam = 0; disk = 0;
00371   do {
00372     
00373     LogDebug( "[LaserAlignment::produce]" ) << "Profile is: " << theProfileNames.GetTECEntry( det, ring, beam, disk ) << "." << std::endl;
00374 
00375     // this now depends on the AT/TEC mode, is this a doubly hit module? -> look for it in vector<int> tecDoubleHitDetId
00376     // (ring == 0 not necessary but makes it a little faster)
00377     if( ring == 0 && find( tecDoubleHitDetId.begin(), tecDoubleHitDetId.end(), detectorId.GetTECEntry( det, ring, beam, disk ) ) != tecDoubleHitDetId.end() ) {
00378 
00379       if( isTECMode ) { // add profile to TEC collection
00380         // add current event's data and subtract pedestals
00381         if( judge.JudgeProfile( currentDataProfiles.GetTECEntry( det, ring, beam, disk ) - pedestalProfiles.GetTECEntry( det, ring, beam, disk ), 0 ) ) {
00382           collectedDataProfiles.GetTECEntry( det, ring, beam, disk ) += currentDataProfiles.GetTECEntry( det, ring, beam, disk ) - pedestalProfiles.GetTECEntry( det, ring, beam, disk );
00383           numberOfAcceptedProfiles.GetTECEntry( det, ring, beam, disk )++;
00384         }
00385       }
00386     }
00387 
00388     else { // not a doubly hit module, don't care about the mode
00389       // add current event's data and subtract pedestals
00390       if( judge.JudgeProfile( currentDataProfiles.GetTECEntry( det, ring, beam, disk ) - pedestalProfiles.GetTECEntry( det, ring, beam, disk ), 0 ) ) {
00391         collectedDataProfiles.GetTECEntry( det, ring, beam, disk ) += currentDataProfiles.GetTECEntry( det, ring, beam, disk ) - pedestalProfiles.GetTECEntry( det, ring, beam, disk );
00392         numberOfAcceptedProfiles.GetTECEntry( det, ring, beam, disk )++;
00393       }
00394     }
00395     
00396   } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
00397 
00398 
00399   
00400 
00401 
00402   // loop TIB/TOB modules
00403   det = 2; beam = 0; pos = 0;
00404   do {
00405     
00406     LogDebug( "[LaserAlignment::produce]" ) << "Profile is: " << theProfileNames.GetTIBTOBEntry( det, beam, pos ) << "." << std::endl;
00407     
00408     // add current event's data and subtract pedestals
00409     if( judge.JudgeProfile( currentDataProfiles.GetTIBTOBEntry( det, beam, pos ) - pedestalProfiles.GetTIBTOBEntry( det, beam, pos ), getTIBTOBNominalBeamOffset( det, beam, pos ) ) ) {
00410       collectedDataProfiles.GetTIBTOBEntry( det, beam, pos ) += currentDataProfiles.GetTIBTOBEntry( det, beam, pos ) - pedestalProfiles.GetTIBTOBEntry( det, beam, pos );
00411       numberOfAcceptedProfiles.GetTIBTOBEntry( det, beam, pos )++;
00412     }
00413 
00414   } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
00415   
00416 
00417 
00418   // loop TEC2TEC modules
00419   det = 0; beam = 0; disk = 0;
00420   do {
00421     
00422     LogDebug( "[LaserAlignment::produce]" ) << "Profile is: " << theProfileNames.GetTEC2TECEntry( det, beam, disk ) << "." << std::endl;
00423 
00424     // this again depends on the AT/TEC mode, is this a doubly hit module?
00425     // (ring == 0 not necessary but makes it a little faster)
00426     if( ring == 0 && find( tecDoubleHitDetId.begin(), tecDoubleHitDetId.end(), detectorId.GetTECEntry( det, ring, beam, disk ) ) != tecDoubleHitDetId.end() ) {
00427 
00428       if( isATMode ) { // add profile to TEC2TEC collection
00429         // add current event's data and subtract pedestals
00430         if( judge.JudgeProfile( currentDataProfiles.GetTEC2TECEntry( det, beam, disk ) - pedestalProfiles.GetTEC2TECEntry( det, beam, disk ), 0 ) ) {
00431           collectedDataProfiles.GetTEC2TECEntry( det, beam, disk ) += currentDataProfiles.GetTEC2TECEntry( det, beam, disk ) - pedestalProfiles.GetTEC2TECEntry( det, beam, disk );
00432           numberOfAcceptedProfiles.GetTEC2TECEntry( det, beam, disk )++;
00433         }
00434       }
00435 
00436     }     
00437     
00438     else { // not a doubly hit module, don't care about the mode
00439       // add current event's data and subtract pedestals
00440       if( judge.JudgeProfile( currentDataProfiles.GetTEC2TECEntry( det, beam, disk ) - pedestalProfiles.GetTEC2TECEntry( det, beam, disk ), 0 ) ) {
00441         collectedDataProfiles.GetTEC2TECEntry( det, beam, disk ) += currentDataProfiles.GetTEC2TECEntry( det, beam, disk ) - pedestalProfiles.GetTEC2TECEntry( det, beam, disk );
00442         numberOfAcceptedProfiles.GetTEC2TECEntry( det, beam, disk )++;
00443       }
00444     }
00445       
00446 
00447   } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
00448 
00449 
00450 
00451   // total event number counter
00452   theEvents++;
00453 
00454 }
00455 
00456 
00457 
00458 
00459 
00463 void LaserAlignment::endRun( edm::Run& theRun, const edm::EventSetup& theSetup ) {
00464 
00465 
00466   std::cout << " [LaserAlignment::endRun] -- Total number of events processed: " << theEvents << std::endl;
00467 
00468   // for debugging only..
00469   DumpHitmaps( numberOfAcceptedProfiles );
00470 
00471   // index variables for the LASGlobalLoop objects
00472   int det, ring, beam, disk, pos;
00473     
00474   // measured positions container for the algorithms
00475   LASGlobalData<LASCoordinateSet> measuredCoordinates;
00476   
00477   // fitted peak positions in units of strips (pair for value,error)
00478   LASGlobalData<std::pair<float,float> > measuredStripPositions;
00479   
00480   // the peak finder, a pair (pos/posErr in units of strips) for its results, and the success confirmation
00481   LASPeakFinder peakFinder;
00482   peakFinder.SetAmplitudeThreshold( peakFinderThreshold );
00483   std::pair<double,double> peakFinderResults;
00484   bool isGoodFit;
00485   
00486   // tracker geom. object for calculating the global beam positions
00487   const TrackerGeometry& theTracker( *theTrackerGeometry );
00488 
00489   // fill LASGlobalData<LASCoordinateSet> nominalCoordinates
00490   CalculateNominalCoordinates();
00491   
00492   // for determining the phi errors
00493   //    ErrorFrameTransformer errorTransformer; // later...
00494   
00495 
00496 
00497 
00498 
00499   // do the fits for TEC+- internal
00500   det = 0; ring = 0; beam = 0; disk = 0;
00501   do {
00502     
00503     // do the fit
00504     isGoodFit = peakFinder.FindPeakIn( collectedDataProfiles.GetTECEntry( det, ring, beam, disk ), peakFinderResults,
00505                                        summedHistograms.GetTECEntry( det, ring, beam, disk ), 0 ); // offset is 0 for TEC
00506 
00507     // now we have the measured positions in units of strips. 
00508     if( !isGoodFit ) std::cout << " [LaserAlignment::endRun] ** WARNING: Fit failed for TEC det: "
00509                                << det << ", ring: " << ring << ", beam: " << beam << ", disk: " << disk
00510                                << " (id: " << detectorId.GetTECEntry( det, ring, beam, disk ) << ")." << std::endl;
00511 
00512     
00513 
00514     // <- here we will later implement the kink corrections
00515       
00516     // access the tracker geometry for this module
00517     const DetId theDetId( detectorId.GetTECEntry( det, ring, beam, disk ) );
00518     const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
00519       
00520     if (theStripDet) {
00521       // first, set the measured coordinates to their nominal values
00522       measuredCoordinates.SetTECEntry( det, ring, beam, disk, nominalCoordinates.GetTECEntry( det, ring, beam, disk ) );
00523       
00524       if( isGoodFit ) { // convert strip position to global phi and replace the nominal phi value/error
00525         
00526         measuredStripPositions.GetTECEntry( det, ring, beam, disk ) = peakFinderResults;
00527         const float positionInStrips =  theSetNominalStrips ? 256. : peakFinderResults.first; // implementation of "ForceFitterToNominalStrips" config parameter
00528         const GlobalPoint& globalPoint = theStripDet->surface().toGlobal( theStripDet->specificTopology().localPosition( positionInStrips ) );
00529         measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhi( ConvertAngle( globalPoint.barePhi() ) );
00530         
00531         // const GlobalError& globalError = errorTransformer.transform( theStripDet->specificTopology().localError( peakFinderResults.first, pow( peakFinderResults.second, 2 ) ), theStripDet->surface() );
00532         // measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhiError( globalError.phierr( globalPoint ) );
00533         measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhiError( 0.00046  ); // PRELIMINARY ESTIMATE
00534         
00535       }
00536       else { // keep nominal position (middle-of-module) but set a giant phi error so that the module can be ignored by the alignment algorithm
00537         measuredStripPositions.GetTECEntry( det, ring, beam, disk ) = std::pair<float,float>( 256., 1000. );
00538         const GlobalPoint& globalPoint = theStripDet->surface().toGlobal( theStripDet->specificTopology().localPosition( 256. ) );
00539         measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhi( ConvertAngle( globalPoint.barePhi() ) );
00540         measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhiError( 1000. );
00541       }
00542     }
00543       
00544   } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
00545 
00546 
00547 
00548 
00549   // do the fits for TIB/TOB
00550   det = 2; beam = 0; pos = 0;
00551   do {
00552 
00553     // do the fit
00554     isGoodFit = peakFinder.FindPeakIn( collectedDataProfiles.GetTIBTOBEntry( det, beam, pos ), peakFinderResults, 
00555                                        summedHistograms.GetTIBTOBEntry( det, beam, pos ), getTIBTOBNominalBeamOffset( det, beam, pos ) );
00556 
00557     // now we have the measured positions in units of strips.
00558     if( !isGoodFit ) std::cout << " [LaserAlignment::endJob] ** WARNING: Fit failed for TIB/TOB det: "
00559                                << det << ", beam: " << beam << ", pos: " << pos 
00560                                << " (id: " << detectorId.GetTIBTOBEntry( det, beam, pos ) << ")." << std::endl;
00561 
00562       
00563     // <- here we will later implement the kink corrections
00564       
00565     // access the tracker geometry for this module
00566     const DetId theDetId( detectorId.GetTIBTOBEntry( det, beam, pos ) );
00567     const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
00568       
00569     if (theStripDet) {
00570       // first, set the measured coordinates to their nominal values
00571       measuredCoordinates.SetTIBTOBEntry( det, beam, pos, nominalCoordinates.GetTIBTOBEntry( det, beam, pos ) );
00572       
00573       if( isGoodFit ) { // convert strip position to global phi and replace the nominal phi value/error
00574         measuredStripPositions.GetTIBTOBEntry( det, beam, pos ) = peakFinderResults;
00575         const float positionInStrips =  theSetNominalStrips ? 256. + getTIBTOBNominalBeamOffset( det, beam, pos ) : peakFinderResults.first; // implementation of "ForceFitterToNominalStrips" config parameter
00576         const GlobalPoint& globalPoint = theStripDet->surface().toGlobal( theStripDet->specificTopology().localPosition( positionInStrips ) );
00577         measuredCoordinates.GetTIBTOBEntry( det, beam, pos ).SetPhi( ConvertAngle( globalPoint.barePhi() ) );
00578         measuredCoordinates.GetTIBTOBEntry( det, beam, pos ).SetPhiError( 0.00028 ); // PRELIMINARY ESTIMATE
00579       }
00580       else { // keep nominal position but set a giant phi error so that the module can be ignored by the alignment algorithm
00581         measuredStripPositions.GetTIBTOBEntry( det, beam, pos ) = std::pair<float,float>( 256. + getTIBTOBNominalBeamOffset( det, beam, pos ), 1000. );
00582         const GlobalPoint& globalPoint = theStripDet->surface().toGlobal( theStripDet->specificTopology().localPosition( 256. + getTIBTOBNominalBeamOffset( det, beam, pos ) ) );
00583         measuredCoordinates.GetTIBTOBEntry( det, beam, pos ).SetPhi( ConvertAngle( globalPoint.barePhi() ) );
00584         measuredCoordinates.GetTIBTOBEntry( det, beam, pos ).SetPhiError( 1000. );
00585       }
00586     }
00587 
00588   } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
00589 
00590 
00591 
00592 
00593   // do the fits for TEC AT
00594   det = 0; beam = 0; disk = 0;
00595   do {
00596 
00597     // do the fit
00598     isGoodFit = peakFinder.FindPeakIn( collectedDataProfiles.GetTEC2TECEntry( det, beam, disk ), peakFinderResults,
00599                                        summedHistograms.GetTEC2TECEntry( det, beam, disk ), getTEC2TECNominalBeamOffset( det, beam, disk ) );
00600     // now we have the positions in units of strips.
00601     if( !isGoodFit ) std::cout << " [LaserAlignment::endRun] ** WARNING: Fit failed for TEC2TEC det: "
00602                                << det << ", beam: " << beam << ", disk: " << disk
00603                                << " (id: " << detectorId.GetTEC2TECEntry( det, beam, disk ) << ")." << std::endl;
00604 
00605 
00606     // <- here we will later implement the kink corrections
00607     
00608     // access the tracker geometry for this module
00609     const DetId theDetId( detectorId.GetTEC2TECEntry( det, beam, disk ) );
00610     const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
00611 
00612     if (theStripDet) {
00613       // first, set the measured coordinates to their nominal values
00614       measuredCoordinates.SetTEC2TECEntry( det, beam, disk, nominalCoordinates.GetTEC2TECEntry( det, beam, disk ) );
00615       
00616       if( isGoodFit ) { // convert strip position to global phi and replace the nominal phi value/error
00617         measuredStripPositions.GetTEC2TECEntry( det, beam, disk ) = peakFinderResults;
00618         const float positionInStrips =  theSetNominalStrips ? 256. + getTEC2TECNominalBeamOffset( det, beam, disk ) : peakFinderResults.first; // implementation of "ForceFitterToNominalStrips" config parameter
00619         const GlobalPoint& globalPoint = theStripDet->surface().toGlobal( theStripDet->specificTopology().localPosition( positionInStrips ) );
00620         measuredCoordinates.GetTEC2TECEntry( det, beam, disk ).SetPhi( ConvertAngle( globalPoint.barePhi() ) );
00621         measuredCoordinates.GetTEC2TECEntry( det, beam, disk ).SetPhiError( 0.00047 ); // PRELIMINARY ESTIMATE
00622       }
00623       else { // keep nominal position but set a giant phi error so that the module can be ignored by the alignment algorithm
00624         measuredStripPositions.GetTEC2TECEntry( det, beam, disk ) = std::pair<float,float>( 256. + getTEC2TECNominalBeamOffset( det, beam, disk ), 1000. );
00625         const GlobalPoint& globalPoint = theStripDet->surface().toGlobal( theStripDet->specificTopology().localPosition( 256. + getTEC2TECNominalBeamOffset( det, beam, disk ) ) );
00626         measuredCoordinates.GetTEC2TECEntry( det, beam, disk ).SetPhi( ConvertAngle( globalPoint.barePhi() ) );
00627         measuredCoordinates.GetTEC2TECEntry( det, beam, disk ).SetPhiError( 1000. );
00628       }
00629     }
00630 
00631   } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
00632   
00633 
00634 
00635 
00636 
00637 
00638 
00639   // see what we got (for debugging)
00640   //  DumpStripFileSet( measuredStripPositions );
00641   //  DumpPosFileSet( measuredCoordinates );
00642 
00643 
00644   
00645 
00646 
00647 
00648   // CALCULATE PARAMETERS AND UPDATE DB OBJECT
00649   // for beam kink corrections, reconstructing the geometry and updating the db object
00650   LASGeometryUpdater geometryUpdater( nominalCoordinates, theLasConstants );
00651 
00652   // apply all beam corrections
00653   if( theApplyBeamKinkCorrections ) geometryUpdater.ApplyBeamKinkCorrections( measuredCoordinates );
00654 
00655   // if we start with input geometry instead of IDEAL,
00656   // reverse the adjustments in the AlignableTracker object
00657   if( updateFromInputGeometry ) geometryUpdater.SetReverseDirection( true );
00658 
00659   // if we have "virtual" misalignment which is introduced via the reference geometry,
00660   // tell the LASGeometryUpdater to reverse x & y adjustments
00661   if( misalignedByRefGeometry ) geometryUpdater.SetMisalignmentFromRefGeometry( true );
00662 
00663   // run the endcap algorithm
00664   LASEndcapAlgorithm endcapAlgorithm;
00665   LASEndcapAlignmentParameterSet endcapParameters;
00666 
00667 
00668   // this basically sets all the endcap modules to be masked 
00669   // to their nominal positions (since endcapParameters is overall zero)
00670   if( theMaskTecModules.size() ) {
00671     ApplyEndcapMaskingCorrections( measuredCoordinates, nominalCoordinates, endcapParameters );
00672   }
00673 
00674   // run the algorithm
00675   endcapParameters = endcapAlgorithm.CalculateParameters( measuredCoordinates, nominalCoordinates );
00676 
00677   // 
00678   // loop to mask out events
00679   // DESCRIPTION:
00680   //
00681 
00682   // do this only if there are modules to be masked..
00683   if( theMaskTecModules.size() ) {
00684     
00685     const unsigned int nIterations = 30;
00686     for( unsigned int iteration = 0; iteration < nIterations; ++iteration ) {
00687       
00688       // set the endcap modules to be masked to their positions
00689       // according to the reconstructed parameters
00690       ApplyEndcapMaskingCorrections( measuredCoordinates, nominalCoordinates, endcapParameters );
00691       
00692       // modifications applied, so re-run the algorithm
00693       endcapParameters = endcapAlgorithm.CalculateParameters( measuredCoordinates, nominalCoordinates );
00694       
00695     }
00696 
00697   } 
00698 
00699   // these are now final, so:
00700   endcapParameters.Print();
00701 
00702 
00703 
00704   
00705   // do a pre-alignment of the endcaps (TEC2TEC only)
00706   // so that the alignment tube algorithms finds orderly disks
00707   geometryUpdater.EndcapUpdate( endcapParameters, measuredCoordinates );
00708 
00709 
00710   // the alignment tube algorithms, choose from config
00711   LASBarrelAlignmentParameterSet alignmentTubeParameters;
00712   // the MINUIT-BASED alignment tube algorithm
00713   LASBarrelAlgorithm barrelAlgorithm;
00714   // the ANALYTICAL alignment tube algorithm
00715   LASAlignmentTubeAlgorithm alignmentTubeAlgorithm;
00716 
00717 
00718   // this basically sets all the modules to be masked 
00719   // to their nominal positions (since alignmentTubeParameters is overall zero)
00720   if( theMaskAtModules.size() ) {
00721     ApplyATMaskingCorrections( measuredCoordinates, nominalCoordinates, alignmentTubeParameters );
00722   }
00723 
00724   if( theUseMinuitAlgorithm ) {
00725     // run the MINUIT-BASED alignment tube algorithm
00726     alignmentTubeParameters = barrelAlgorithm.CalculateParameters( measuredCoordinates, nominalCoordinates );
00727   }
00728   else {
00729     // the ANALYTICAL alignment tube algorithm
00730     alignmentTubeParameters = alignmentTubeAlgorithm.CalculateParameters( measuredCoordinates, nominalCoordinates );
00731   }
00732 
00733 
00734 
00735   // 
00736   // loop to mask out events
00737   // DESCRIPTION:
00738   //
00739 
00740   // do this only if there are modules to be masked..
00741   if( theMaskAtModules.size() ) {
00742     
00743     const unsigned int nIterations = 30;
00744     for( unsigned int iteration = 0; iteration < nIterations; ++iteration ) {
00745       
00746       // set the AT modules to be masked to their positions
00747       // according to the reconstructed parameters
00748       ApplyATMaskingCorrections( measuredCoordinates, nominalCoordinates, alignmentTubeParameters );
00749       
00750       // modifications applied, so re-run the algorithm
00751       if( theUseMinuitAlgorithm ) {
00752         alignmentTubeParameters = barrelAlgorithm.CalculateParameters( measuredCoordinates, nominalCoordinates );
00753       }
00754       else {
00755         alignmentTubeParameters = alignmentTubeAlgorithm.CalculateParameters( measuredCoordinates, nominalCoordinates );
00756       }
00757       
00758     }
00759 
00760   } 
00761 
00762 
00763   // these are now final, so:
00764   alignmentTubeParameters.Print();
00765 
00766 
00767   // combine the results and update the db object
00768   geometryUpdater.TrackerUpdate( endcapParameters, alignmentTubeParameters, *theAlignableTracker );
00769   
00770 
00771 
00772 
00773 
00774     
00775 
00780     
00781     
00782   // the collection container
00783   std::auto_ptr<TkLasBeamCollection> laserBeams( new TkLasBeamCollection );
00784 
00785   
00786   // first for the endcap internal beams
00787   for( det = 0; det < 2; ++det ) {
00788     for( ring = 0; ring < 2; ++ring ) {
00789       for( beam = 0; beam < 8; ++beam ) {
00790         
00791         // the beam and its identifier (see TkLasTrackBasedInterface TWiki)
00792         TkLasBeam currentBeam( 100 * det + 10 * beam + ring );
00793         
00794         // order the hits in the beam by increasing z
00795         const int firstDisk = det==0 ? 0 : 8;
00796         const int lastDisk  = det==0 ? 8 : 0;
00797           
00798         // count upwards or downwards
00799         for( disk = firstDisk; det==0 ? disk <= lastDisk : disk >= lastDisk; det==0 ? ++disk : --disk ) {
00800             
00801           // detId for the SiStripLaserRecHit2D
00802           const SiStripDetId theDetId( detectorId.GetTECEntry( det, ring, beam, disk ) );
00803             
00804           // need this to calculate the localPosition and its error
00805           const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
00806             
00807           // the hit container
00808           const SiStripLaserRecHit2D currentHit(
00809             theStripDet->specificTopology().localPosition( measuredStripPositions.GetTECEntry( det, ring, beam, disk ).first ),
00810             theStripDet->specificTopology().localError( measuredStripPositions.GetTECEntry( det, ring, beam, disk ).first, measuredStripPositions.GetTECEntry( det, ring, beam, disk ).second ),
00811             theDetId
00812           );
00813 
00814           currentBeam.push_back( currentHit );
00815 
00816         }         
00817           
00818         laserBeams->push_back( currentBeam );
00819           
00820       }
00821     }
00822   }
00823     
00824     
00825 
00826   // then, following the convention in TkLasTrackBasedInterface TWiki, the alignment tube beams;
00827   // they comprise hits in TIBTOB & TEC2TEC
00828 
00829   for( beam = 0; beam < 8; ++beam ) {
00830 
00831     // the beam and its identifier (see TkLasTrackBasedInterface TWiki)
00832     TkLasBeam currentBeam( 100 * 2 /*beamGroup=AT=2*/ + 10 * beam + 0 /*ring=0*/);
00833 
00834 
00835     // first: tec-
00836     det = 1;
00837     for( disk = 4; disk >= 0; --disk ) {
00838         
00839       // detId for the SiStripLaserRecHit2D
00840       const SiStripDetId theDetId( detectorId.GetTEC2TECEntry( det, beam, disk ) );
00841         
00842       // need this to calculate the localPosition and its error
00843       const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
00844         
00845       // the hit container
00846       const SiStripLaserRecHit2D currentHit(
00847         theStripDet->specificTopology().localPosition( measuredStripPositions.GetTEC2TECEntry( det, beam, disk ).first ),
00848         theStripDet->specificTopology().localError( measuredStripPositions.GetTEC2TECEntry( det, beam, disk ).first, measuredStripPositions.GetTEC2TECEntry( det, beam, disk ).second ),
00849         theDetId
00850       );
00851 
00852       currentBeam.push_back( currentHit );
00853         
00854     }
00855 
00856       
00857     // now TIB and TOB in one go
00858     for( det = 2; det < 4; ++det ) {
00859       for( pos = 5; pos >= 0; --pos ) { // stupidly, pos is defined from +z to -z in LASGlobalLoop
00860           
00861         // detId for the SiStripLaserRecHit2D
00862         const SiStripDetId theDetId( detectorId.GetTIBTOBEntry( det, beam, pos ) );
00863           
00864         // need this to calculate the localPosition and its error
00865         const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
00866           
00867         // the hit container
00868         const SiStripLaserRecHit2D currentHit(
00869           theStripDet->specificTopology().localPosition( measuredStripPositions.GetTIBTOBEntry( det, beam, pos ).first ),
00870           theStripDet->specificTopology().localError( measuredStripPositions.GetTIBTOBEntry( det, beam, pos ).first, measuredStripPositions.GetTIBTOBEntry( det, beam, pos ).second ),
00871           theDetId
00872         );
00873 
00874         currentBeam.push_back( currentHit );
00875           
00876       }
00877     }
00878       
00879 
00880     // then: tec+
00881     det = 0;
00882     for( disk = 0; disk < 5; ++disk ) {
00883         
00884       // detId for the SiStripLaserRecHit2D
00885       const SiStripDetId theDetId( detectorId.GetTEC2TECEntry( det, beam, disk ) );
00886         
00887       // need this to calculate the localPosition and its error
00888       const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
00889         
00890       // the hit container
00891       const SiStripLaserRecHit2D currentHit(
00892         theStripDet->specificTopology().localPosition( measuredStripPositions.GetTEC2TECEntry( det, beam, disk ).first ),
00893         theStripDet->specificTopology().localError( measuredStripPositions.GetTEC2TECEntry( det, beam, disk ).first, measuredStripPositions.GetTEC2TECEntry( det, beam, disk ).second ),
00894         theDetId
00895       );
00896 
00897       currentBeam.push_back( currentHit );
00898         
00899     }
00900 
00901 
00902 
00903     // save this beam to the beamCollection
00904     laserBeams->push_back( currentBeam );
00905     
00906   } // (close beam loop)
00907   
00908   
00909   // now attach the collection to the run
00910   theRun.put( laserBeams, "tkLaserBeams" );
00911   
00912 
00913 
00914   
00915 
00916   // store the estimated alignment parameters into the DB
00917   // first get them
00918   Alignments* alignments =  theAlignableTracker->alignments();
00919   AlignmentErrors* alignmentErrors = theAlignableTracker->alignmentErrors();
00920 
00921   if ( theStoreToDB ) {
00922 
00923     std::cout << " [LaserAlignment::endRun] -- Storing the calculated alignment parameters to the DataBase:" << std::endl;
00924 
00925     // Call service
00926     edm::Service<cond::service::PoolDBOutputService> poolDbService;
00927     if( !poolDbService.isAvailable() ) // Die if not available
00928       throw cms::Exception( "NotAvailable" ) << "PoolDBOutputService not available";
00929     
00930     // Store
00931 
00932     //     if ( poolDbService->isNewTagRequest(theAlignRecordName) ) {
00933     //       poolDbService->createNewIOV<Alignments>( alignments, poolDbService->currentTime(), poolDbService->endOfTime(), theAlignRecordName );
00934     //     }
00935     //     else {
00936     //       poolDbService->appendSinceTime<Alignments>( alignments, poolDbService->currentTime(), theAlignRecordName );
00937     //     }
00938     poolDbService->writeOne<Alignments>( alignments, poolDbService->beginOfTime(), theAlignRecordName );
00939 
00940     //     if ( poolDbService->isNewTagRequest(theErrorRecordName) ) {
00941     //       poolDbService->createNewIOV<AlignmentErrors>( alignmentErrors, poolDbService->currentTime(), poolDbService->endOfTime(), theErrorRecordName );
00942     //     }
00943     //     else {
00944     //       poolDbService->appendSinceTime<AlignmentErrors>( alignmentErrors, poolDbService->currentTime(), theErrorRecordName );
00945     //     }
00946     poolDbService->writeOne<AlignmentErrors>( alignmentErrors, poolDbService->beginOfTime(), theErrorRecordName );
00947 
00948     std::cout << " [LaserAlignment::endRun] -- Storing done." << std::endl;
00949     
00950   }
00951 
00952 }
00953 
00954 
00955 
00956 
00957 
00961 void LaserAlignment::endJob() {
00962 }
00963 
00964 
00965 
00966 
00967 
00972 void LaserAlignment::fillDataProfiles( edm::Event const& theEvent, edm::EventSetup const& theSetup ) {
00973 
00974   // two handles for the two different kinds of digis
00975   edm::Handle< edm::DetSetVector<SiStripRawDigi> > theStripRawDigis;
00976   edm::Handle< edm::DetSetVector<SiStripDigi> > theStripDigis;
00977 
00978   bool isRawDigi = false;
00979 
00980   // indices for the LASGlobalLoop object
00981   int det = 0, ring = 0, beam = 0, disk = 0, pos = 0;
00982 
00983   // query config set and loop over all PSets in the VPSet
00984   for ( std::vector<edm::ParameterSet>::iterator itDigiProducersList = theDigiProducersList.begin(); itDigiProducersList != theDigiProducersList.end(); ++itDigiProducersList ) {
00985 
00986     std::string digiProducer = itDigiProducersList->getParameter<std::string>( "DigiProducer" );
00987     std::string digiLabel = itDigiProducersList->getParameter<std::string>( "DigiLabel" );
00988     std::string digiType = itDigiProducersList->getParameter<std::string>( "DigiType" );
00989 
00990     // now branch according to digi type (raw or processed);    
00991     // first we go for raw digis => SiStripRawDigi
00992     if( digiType == "Raw" ) {
00993       theEvent.getByLabel( digiProducer, digiLabel, theStripRawDigis );
00994       isRawDigi = true;
00995     }
00996     else if( digiType == "Processed" ) {
00997       theEvent.getByLabel( digiProducer, digiLabel, theStripDigis );
00998       isRawDigi = false;
00999     }
01000     else {
01001       throw cms::Exception( " [LaserAlignment::fillDataProfiles]") << " ** ERROR: Invalid digi type: \"" << digiType << "\" specified in configuration." << std::endl;
01002     }    
01003 
01004 
01005 
01006     // loop TEC internal modules
01007     det = 0; ring = 0; beam = 0; disk = 0;
01008     do {
01009       
01010       // first clear the profile
01011       currentDataProfiles.GetTECEntry( det, ring, beam, disk ).SetAllValuesTo( 0. );
01012 
01013       // retrieve the raw id of that module
01014       const int detRawId = detectorId.GetTECEntry( det, ring, beam, disk );
01015       
01016       if( isRawDigi ) { // we have raw SiStripRawDigis
01017         
01018         // search the digis for the raw id
01019         edm::DetSetVector<SiStripRawDigi>::const_iterator detSetIter = theStripRawDigis->find( detRawId );
01020         if( detSetIter == theStripRawDigis->end() ) {
01021           throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: No raw DetSet found for det: " << detRawId << "." << std::endl;
01022         }
01023       
01024         // fill the digis to the profiles
01025         edm::DetSet<SiStripRawDigi>::const_iterator digiRangeIterator = detSetIter->data.begin(); // for the loop
01026         edm::DetSet<SiStripRawDigi>::const_iterator digiRangeStart = digiRangeIterator; // save starting positions
01027         
01028         // loop all digis
01029         for (; digiRangeIterator != detSetIter->data.end(); ++digiRangeIterator ) {
01030           const SiStripRawDigi& digi = *digiRangeIterator;
01031           const int channel = distance( digiRangeStart, digiRangeIterator );
01032           if ( channel >= 0 && channel < 512 ) currentDataProfiles.GetTECEntry( det, ring, beam, disk ).SetValue( channel, digi.adc() );
01033           else throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: raw digi channel: " << channel << " out of range for det: " << detRawId << "." << std::endl;
01034         }
01035 
01036       }
01037 
01038       else { // we have zero suppressed SiStripDigis
01039 
01040         // search the digis for the raw id
01041         edm::DetSetVector<SiStripDigi>::const_iterator detSetIter = theStripDigis->find( detRawId );
01042         
01043         // processed DetSets may be missing, just skip
01044         if( detSetIter == theStripDigis->end() ) continue;
01045 
01046         // fill the digis to the profiles
01047         edm::DetSet<SiStripDigi>::const_iterator digiRangeIterator = detSetIter->data.begin(); // for the loop
01048         
01049         for(; digiRangeIterator != detSetIter->data.end(); ++digiRangeIterator ) {
01050           const SiStripDigi& digi = *digiRangeIterator;
01051           if ( digi.strip() < 512 ) currentDataProfiles.GetTECEntry( det, ring, beam, disk ).SetValue( digi.strip(), digi.adc() );
01052           else throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: digi strip: " << digi.strip() << " out of range for det: " << detRawId << "." << std::endl;
01053         }
01054 
01055       }
01056 
01057       
01058     } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
01059     
01060 
01061 
01062 
01063     
01064     // loop TIBTOB modules
01065     det = 2; beam = 0; pos = 0;
01066     do {
01067 
01068       // first clear the profile
01069       currentDataProfiles.GetTIBTOBEntry( det, beam, pos ).SetAllValuesTo( 0. );
01070 
01071       // retrieve the raw id of that module
01072       const int detRawId = detectorId.GetTIBTOBEntry( det, beam, pos );
01073       
01074       if( isRawDigi ) { // we have raw SiStripRawDigis
01075         
01076         // search the digis for the raw id
01077         edm::DetSetVector<SiStripRawDigi>::const_iterator detSetIter = theStripRawDigis->find( detRawId );
01078         if( detSetIter == theStripRawDigis->end() ) {
01079           throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: No raw DetSet found for det: " << detRawId << "." << std::endl;
01080         }
01081       
01082         // fill the digis to the profiles
01083         edm::DetSet<SiStripRawDigi>::const_iterator digiRangeIterator = detSetIter->data.begin(); // for the loop
01084         edm::DetSet<SiStripRawDigi>::const_iterator digiRangeStart = digiRangeIterator; // save starting positions
01085         
01086         // loop all digis
01087         for (; digiRangeIterator != detSetIter->data.end(); ++digiRangeIterator ) {
01088           const SiStripRawDigi& digi = *digiRangeIterator;
01089           const int channel = distance( digiRangeStart, digiRangeIterator );
01090           if ( channel >= 0 && channel < 512 ) currentDataProfiles.GetTIBTOBEntry( det, beam, pos ).SetValue( channel, digi.adc() );
01091           else throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: raw digi channel: " << channel << " out of range for det: " << detRawId << "." << std::endl;
01092         }
01093 
01094       }
01095 
01096       else { // we have zero suppressed SiStripDigis
01097 
01098         // search the digis for the raw id
01099         edm::DetSetVector<SiStripDigi>::const_iterator detSetIter = theStripDigis->find( detRawId );
01100 
01101         // processed DetSets may be missing, just skip
01102         if( detSetIter == theStripDigis->end() ) continue;
01103 
01104         // fill the digis to the profiles
01105         edm::DetSet<SiStripDigi>::const_iterator digiRangeIterator = detSetIter->data.begin(); // for the loop
01106         
01107         for(; digiRangeIterator != detSetIter->data.end(); ++digiRangeIterator ) {
01108           const SiStripDigi& digi = *digiRangeIterator;
01109           if ( digi.strip() < 512 ) currentDataProfiles.GetTIBTOBEntry( det, beam, pos ).SetValue( digi.strip(), digi.adc() );
01110           else throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: digi strip: " << digi.strip() << " out of range for det: " << detRawId << "." << std::endl;
01111         }
01112 
01113       }
01114 
01115     } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
01116 
01117 
01118 
01119     // loop TEC AT modules
01120     det = 0; beam = 0; disk = 0;
01121     do {
01122 
01123       // first clear the profile
01124       currentDataProfiles.GetTEC2TECEntry( det, beam, disk ).SetAllValuesTo( 0. );
01125 
01126       // retrieve the raw id of that module
01127       const int detRawId = detectorId.GetTEC2TECEntry( det, beam, disk );
01128     
01129       if( isRawDigi ) { // we have raw SiStripRawDigis
01130       
01131         // search the digis for the raw id
01132         edm::DetSetVector<SiStripRawDigi>::const_iterator detSetIter = theStripRawDigis->find( detRawId );
01133         if( detSetIter == theStripRawDigis->end() ) {
01134           throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: No raw DetSet found for det: " << detRawId << "." << std::endl;
01135         }
01136       
01137         // fill the digis to the profiles
01138         edm::DetSet<SiStripRawDigi>::const_iterator digiRangeIterator = detSetIter->data.begin(); // for the loop
01139         edm::DetSet<SiStripRawDigi>::const_iterator digiRangeStart = digiRangeIterator; // save starting positions
01140       
01141         // loop all digis
01142         for (; digiRangeIterator != detSetIter->data.end(); ++digiRangeIterator ) {
01143           const SiStripRawDigi& digi = *digiRangeIterator;
01144           const int channel = distance( digiRangeStart, digiRangeIterator );
01145           if ( channel >= 0 && channel < 512 ) currentDataProfiles.GetTEC2TECEntry( det, beam, disk ).SetValue( channel, digi.adc() );
01146           else throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: raw digi channel: " << channel << " out of range for det: " << detRawId << "." << std::endl;
01147         }
01148       
01149       }
01150     
01151       else { // we have zero suppressed SiStripDigis
01152       
01153         // search the digis for the raw id
01154         edm::DetSetVector<SiStripDigi>::const_iterator detSetIter = theStripDigis->find( detRawId );
01155         
01156         // processed DetSets may be missing, just skip
01157         if( detSetIter == theStripDigis->end() ) continue;
01158       
01159         // fill the digis to the profiles
01160         edm::DetSet<SiStripDigi>::const_iterator digiRangeIterator = detSetIter->data.begin(); // for the loop
01161       
01162         for(; digiRangeIterator != detSetIter->data.end(); ++digiRangeIterator ) {
01163           const SiStripDigi& digi = *digiRangeIterator;
01164           if ( digi.strip() < 512 ) currentDataProfiles.GetTEC2TECEntry( det, beam, disk ).SetValue( digi.strip(), digi.adc() );
01165           else throw cms::Exception( "[Laser Alignment::fillDataProfiles]" ) << " ** ERROR: digi strip: " << digi.strip() << " out of range for det: " << detRawId << "." << std::endl;
01166         }
01167       
01168       }
01169     
01170     } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
01171 
01172   } // theDigiProducersList loop
01173 
01174 }
01175 
01176 
01177 
01178 
01179 
01188 void LaserAlignment::fillPedestalProfiles( edm::ESHandle<SiStripPedestals>& pedestalsHandle ) {
01189 
01190   int det, ring, beam, disk, pos;
01191 
01192   // loop TEC modules (yet without AT)
01193   det = 0; ring = 0; beam = 0; disk = 0;
01194   do { // loop using LASGlobalLoop functionality
01195     SiStripPedestals::Range pedRange = pedestalsHandle->getRange( detectorId.GetTECEntry( det, ring, beam, disk ) );
01196     for( int strip = 0; strip < 512; ++strip ) {
01197       int thePedestal = int( pedestalsHandle->getPed( strip, pedRange ) );
01198       if( thePedestal > 895 ) thePedestal -= 1024;
01199       pedestalProfiles.GetTECEntry( det, ring, beam, disk ).SetValue( strip, thePedestal );
01200     }
01201   } while ( moduleLoop.TECLoop( det, ring, beam, disk ) );
01202 
01203 
01204   // TIB & TOB section
01205   det = 2; beam = 0; pos = 0;
01206   do { // loop using LASGlobalLoop functionality
01207     SiStripPedestals::Range pedRange = pedestalsHandle->getRange( detectorId.GetTIBTOBEntry( det, beam, pos ) );
01208     for( int strip = 0; strip < 512; ++strip ) {
01209       int thePedestal = int( pedestalsHandle->getPed( strip, pedRange ) );
01210       if( thePedestal > 895 ) thePedestal -= 1024;
01211       pedestalProfiles.GetTIBTOBEntry( det, beam, pos ).SetValue( strip, thePedestal );
01212     }
01213   } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
01214 
01215 
01216   // TEC2TEC AT section
01217   det = 0; beam = 0; disk = 0;
01218   do { // loop using LASGlobalLoop functionality
01219     SiStripPedestals::Range pedRange = pedestalsHandle->getRange( detectorId.GetTEC2TECEntry( det, beam, disk ) );
01220     for( int strip = 0; strip < 512; ++strip ) {
01221       int thePedestal = int( pedestalsHandle->getPed( strip, pedRange ) );
01222       if( thePedestal > 895 ) thePedestal -= 1024;
01223       pedestalProfiles.GetTEC2TECEntry( det, beam, disk ).SetValue( strip, thePedestal );
01224     }
01225   } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
01226 
01227 }
01228 
01229 
01230 
01231 
01232 
01238 bool LaserAlignment::isTECBeam( void ) {
01239   
01240   int numberOfProfiles = 0;
01241 
01242   int ring = 1; // search all ring6 modules for signals
01243   for( int det = 0; det < 2; ++det ) {
01244     for( int beam = 0; beam < 8; ++ beam ) {
01245       for( int disk = 0; disk < 9; ++disk ) {
01246         if( isAcceptedProfile.GetTECEntry( det, ring, beam, disk ) == 1 ) numberOfProfiles++;
01247       }
01248     }
01249   }
01250 
01251   LogDebug( "[LaserAlignment::isTECBeam]" ) << " Found: " << numberOfProfiles << "hits." << std::endl;
01252   std::cout << " [LaserAlignment::isTECBeam] -- Found: " << numberOfProfiles << " hits." << std::endl; 
01253 
01254   if( numberOfProfiles > 10 ) return( true );
01255   return( false );
01256  
01257 }
01258 
01259 
01260 
01261 
01262 
01268 
01269 bool LaserAlignment::isATBeam( void ) {
01270 
01271   int numberOfProfiles = 0;
01272 
01273   int det = 2; int beam = 0; int pos = 0; // search all TIB/TOB for signals
01274   do {
01275     if( isAcceptedProfile.GetTIBTOBEntry( det, beam, pos ) == 1 ) numberOfProfiles++;
01276   } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
01277 
01278   LogDebug( "[LaserAlignment::isATBeam]" ) << " Found: " << numberOfProfiles << "hits." << std::endl;
01279   std::cout << " [LaserAlignment::isATBeam] -- Found: " << numberOfProfiles << " hits." << std::endl; 
01280 
01281   if( numberOfProfiles > 10 ) return( true );
01282   return( false );
01283     
01284 }
01285 
01286 
01287 
01288 
01289 
01298 double LaserAlignment::getTIBTOBNominalBeamOffset( unsigned int det, unsigned int beam, unsigned int pos ) {
01299 
01300   if( det < 2 || det > 3 || beam > 7 || pos > 5 ) {
01301     throw cms::Exception( "[LaserAlignment::getTIBTOBNominalBeamOffset]" ) << " ERROR ** Called with nonexisting parameter set: det " << det << " beam " << beam << " pos " << pos << "." << std::endl;
01302   }
01303 
01304   const double nominalOffsetsTIB[8] = { 0.00035, 2.10687, -2.10827, -0.00173446, 2.10072, -0.00135114, 2.10105, -2.10401 };
01305 
01306   // in tob, modules have alternating orientations along the rods.
01307   // this is described by the following pattern.
01308   // (even more confusing, this pattern is inversed for beams 0, 5, 6, 7)
01309   const int orientationPattern[6] = { -1, 1, 1, -1, -1, 1 };
01310   const double nominalOffsetsTOB[8] = { 0.00217408, 1.58678, 117.733, 119.321, 120.906, 119.328, 117.743, 1.58947 };
01311 
01312 
01313   if( det == 2 ) return( -1. * nominalOffsetsTIB[beam] );
01314 
01315   else {
01316     if( beam == 0 or beam > 4 ) return( nominalOffsetsTOB[beam] * orientationPattern[pos] );
01317     else return( -1. * nominalOffsetsTOB[beam] * orientationPattern[pos] );
01318   }
01319 
01320 }
01321 
01322 
01323 
01324 
01333 double LaserAlignment::getTEC2TECNominalBeamOffset( unsigned int det, unsigned int beam, unsigned int disk ) {
01334 
01335   if( det > 1 || beam > 7 || disk > 5 ) {
01336     throw cms::Exception( "[LaserAlignment::getTEC2TECNominalBeamOffset]" ) << " ERROR ** Called with nonexisting parameter set: det " << det << " beam " << beam << " disk " << disk << "." << std::endl;
01337   }
01338 
01339   const double nominalOffsets[8] = { 0., 2.220, -2.221, 0., 2.214, 0., 2.214, -2.217 };
01340   
01341   if( det == 0 ) return -1. * nominalOffsets[beam];
01342   else return nominalOffsets[beam];
01343 
01344 }
01345 
01346 
01347 
01348 
01349 
01353 void LaserAlignment::CalculateNominalCoordinates( void ) {
01354 
01355   //
01356   // hard coded data yet...
01357   //
01358 
01359   // nominal phi values of tec beam / alignment tube hits (parameter is beam 0-7)
01360   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
01361   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
01362 
01363   // nominal r values (mm) of hits
01364   const double tobRPosition = 600.;
01365   const double tibRPosition = 514.;
01366   const double tecRPosition[2] = { 564., 840. }; // ring 4,6
01367 
01368   // nominal z values (mm) of hits in barrel (parameter is pos 0-6)
01369   const double tobZPosition[6] = { 1040., 580., 220., -140., -500., -860. };
01370   const double tibZPosition[6] = { 620., 380., 180., -100., -340., -540. };
01371 
01372   // nominal z values (mm) of hits in tec (parameter is disk 0-8); FOR TEC-: (* -1.)
01373   const double tecZPosition[9] = { 1322.5, 1462.5, 1602.5, 1742.5, 1882.5, 2057.5, 2247.5, 2452.5, 2667.5 };
01374   
01375 
01376   //
01377   // now we fill these into the nominalCoordinates container;
01378   // errors are zero for nominal values..
01379   //
01380 
01381   // loop object and its variables
01382   LASGlobalLoop moduleLoop;
01383   int det, ring, beam, disk, pos;
01384 
01385   
01386   // TEC+- section
01387   det = 0; ring = 0, beam = 0; disk = 0;
01388   do {
01389     
01390     if( det == 0 ) { // this is TEC+
01391       nominalCoordinates.SetTECEntry( det, ring, beam, disk, LASCoordinateSet( tecPhiPositions[beam], 0., tecRPosition[ring], 0., tecZPosition[disk], 0. ) );
01392     }
01393     else { // now TEC-
01394       nominalCoordinates.SetTECEntry( det, ring, beam, disk, LASCoordinateSet( tecPhiPositions[beam], 0., tecRPosition[ring], 0., -1. * tecZPosition[disk], 0. ) ); // just * -1.
01395     }
01396     
01397   } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
01398 
01399 
01400 
01401   // TIB & TOB section
01402   det = 2; beam = 0; pos = 0;
01403   do {
01404     if( det == 2 ) { // this is TIB
01405       nominalCoordinates.SetTIBTOBEntry( det, beam, pos, LASCoordinateSet( atPhiPositions[beam], 0., tibRPosition, 0., tibZPosition[pos], 0. ) );
01406     }
01407     else { // now TOB
01408       nominalCoordinates.SetTIBTOBEntry( det, beam, pos, LASCoordinateSet( atPhiPositions[beam], 0., tobRPosition, 0., tobZPosition[pos], 0. ) );
01409     }
01410 
01411   } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
01412 
01413 
01414 
01415 
01416   // TEC2TEC AT section
01417   det = 0; beam = 0; disk = 0;
01418   do {
01419     
01420     if( det == 0 ) { // this is TEC+, ring4 only
01421       nominalCoordinates.SetTEC2TECEntry( det, beam, disk, LASCoordinateSet( atPhiPositions[beam], 0., tecRPosition[0], 0., tecZPosition[disk], 0. ) );
01422     }
01423     else { // now TEC-
01424       nominalCoordinates.SetTEC2TECEntry( det, beam, disk, LASCoordinateSet( atPhiPositions[beam], 0., tecRPosition[0], 0., -1. * tecZPosition[disk], 0. ) ); // just * -1.
01425     }
01426     
01427   } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
01428 
01429 
01430 }
01431 
01432 
01433 
01434 
01435 
01440 double LaserAlignment::ConvertAngle( double angle ) {
01441 
01442   if( angle < -1. * M_PI  || angle > M_PI ) {
01443     throw cms::Exception(" [LaserAlignment::ConvertAngle] ") << "** ERROR: Called with illegal input angle: " << angle << "." << std::endl;
01444   }
01445 
01446   if( angle >= 0. ) return angle;
01447   else return( angle + 2. * M_PI );
01448 
01449 }
01450 
01451 
01452 
01453 
01454 
01458 void LaserAlignment::DumpPosFileSet( LASGlobalData<LASCoordinateSet>& coordinates ) {
01459 
01460   LASGlobalLoop loop;
01461   int det, ring, beam, disk, pos;
01462 
01463   std:: cout << std::endl << " [LaserAlignment::DumpPosFileSet] -- Dump: " << std::endl;
01464 
01465   // TEC INTERNAL
01466   det = 0; ring = 0; beam = 0; disk = 0;
01467   do {
01468     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;
01469   } while ( loop.TECLoop( det, ring, beam, disk ) );
01470 
01471   // TIBTOB
01472   det = 2; beam = 0; pos = 0;
01473   do {
01474     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;
01475   } while( loop.TIBTOBLoop( det, beam, pos ) );
01476 
01477   // TEC2TEC
01478   det = 0; beam = 0; disk = 0;
01479   do {
01480     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;
01481   } while( loop.TEC2TECLoop( det, beam, disk ) );
01482 
01483   std:: cout << std::endl << " [LaserAlignment::DumpPosFileSet] -- End dump: " << std::endl;
01484 
01485 }
01486 
01487 
01488 
01489 
01490 
01494 void LaserAlignment::DumpStripFileSet( LASGlobalData<std::pair<float,float> >& measuredStripPositions ) {
01495 
01496   LASGlobalLoop loop;
01497   int det, ring, beam, disk, pos;
01498 
01499   std:: cout << std::endl << " [LaserAlignment::DumpStripFileSet] -- Dump: " << std::endl;
01500 
01501   // TEC INTERNAL
01502   det = 0; ring = 0; beam = 0; disk = 0;
01503   do {
01504     std::cout << "STRIP " << det << "\t" << beam << "\t" << disk << "\t" << ring << "\t" << measuredStripPositions.GetTECEntry( det, ring, beam, disk ).first
01505               << "\t" << measuredStripPositions.GetTECEntry( det, ring, beam, disk ).second << std::endl;
01506   } while ( loop.TECLoop( det, ring, beam, disk ) );
01507 
01508   // TIBTOB
01509   det = 2; beam = 0; pos = 0;
01510   do {
01511     std::cout << "STRIP " << det << "\t" << beam << "\t" << pos << "\t" << "-1" << "\t" << measuredStripPositions.GetTIBTOBEntry( det, beam, pos ).first
01512               << "\t" << measuredStripPositions.GetTIBTOBEntry( det, beam, pos ).second << std::endl;
01513   } while( loop.TIBTOBLoop( det, beam, pos ) );
01514 
01515   // TEC2TEC
01516   det = 0; beam = 0; disk = 0;
01517   do {
01518     std::cout << "STRIP " << det << "\t" << beam << "\t" << disk << "\t" << "-1" << "\t" << measuredStripPositions.GetTEC2TECEntry( det, beam, disk ).first
01519               << "\t" << measuredStripPositions.GetTEC2TECEntry( det, beam, disk ).second << std::endl;
01520   } while( loop.TEC2TECLoop( det, beam, disk ) );
01521 
01522   std:: cout << std::endl << " [LaserAlignment::DumpStripFileSet] -- End dump: " << std::endl;
01523   
01524   
01525 }
01526 
01527 
01528 
01529 
01530 
01534 void LaserAlignment::DumpHitmaps( LASGlobalData<int> &numberOfAcceptedProfiles ) {
01535 
01536   std::cout << " [LaserAlignment::DumpHitmaps] -- Dumping hitmap for TEC+:" << std::endl;
01537   std::cout << " [LaserAlignment::DumpHitmaps] -- Ring4:" << std::endl;
01538   std::cout << "     disk0   disk1   disk2   disk3   disk4   disk5   disk6   disk7   disk8" << std::endl;
01539 
01540   for( int beam = 0; beam < 8; ++beam ) {
01541     std::cout << " beam" << beam << ":";
01542     for( int disk = 0; disk < 9; ++disk ) {
01543       std::cout << "\t" << numberOfAcceptedProfiles.GetTECEntry( 0, 0, beam, disk );
01544     }
01545     std::cout << std::endl;
01546   }
01547 
01548   std::cout << " [LaserAlignment::DumpHitmaps] -- Ring6:" << std::endl;
01549   std::cout << "     disk0   disk1   disk2   disk3   disk4   disk5   disk6   disk7   disk8" << std::endl;
01550 
01551   for( int beam = 0; beam < 8; ++beam ) {
01552     std::cout << " beam" << beam << ":";
01553     for( int disk = 0; disk < 9; ++disk ) {
01554       std::cout << "\t" << numberOfAcceptedProfiles.GetTECEntry( 0, 1, beam, disk );
01555     }
01556     std::cout << std::endl;
01557   }
01558 
01559   std::cout << " [LaserAlignment::DumpHitmaps] -- Dumping hitmap for TEC-:" << std::endl;
01560   std::cout << " [LaserAlignment::DumpHitmaps] -- Ring4:" << std::endl;
01561   std::cout << "     disk0   disk1   disk2   disk3   disk4   disk5   disk6   disk7   disk8" << std::endl;
01562 
01563   for( int beam = 0; beam < 8; ++beam ) {
01564     std::cout << " beam" << beam << ":";
01565     for( int disk = 0; disk < 9; ++disk ) {
01566       std::cout << "\t" << numberOfAcceptedProfiles.GetTECEntry( 1, 0, beam, disk );
01567     }
01568     std::cout << std::endl;
01569   }
01570 
01571   std::cout << " [LaserAlignment::DumpHitmaps] -- Ring6:" << std::endl;
01572   std::cout << "     disk0   disk1   disk2   disk3   disk4   disk5   disk6   disk7   disk8" << std::endl;
01573 
01574   for( int beam = 0; beam < 8; ++beam ) {
01575     std::cout << " beam" << beam << ":";
01576     for( int disk = 0; disk < 9; ++disk ) {
01577       std::cout << "\t" << numberOfAcceptedProfiles.GetTECEntry( 1, 1, beam, disk );
01578     }
01579     std::cout << std::endl;
01580   }
01581 
01582   std::cout << " [LaserAlignment::DumpHitmaps] -- End of dump." << std::endl << std::endl;
01583 
01584 }
01585 
01586 
01587 
01588 
01589 
01594 void LaserAlignment::ApplyEndcapMaskingCorrections( LASGlobalData<LASCoordinateSet>& measuredCoordinates, LASGlobalData<LASCoordinateSet>& nominalCoordinates, LASEndcapAlignmentParameterSet& endcapParameters ) {
01595 
01596   // loop the list of modules to be masked
01597   for( std::vector<unsigned int>::iterator moduleIt = theMaskTecModules.begin(); moduleIt != theMaskTecModules.end(); ++moduleIt ) {
01598 
01599     // loop variables
01600     LASGlobalLoop moduleLoop;
01601     int det, ring, beam, disk;
01602 
01603     // this will calculate the corrections from the alignment parameters
01604     LASEndcapAlgorithm endcapAlgorithm;
01605 
01606     // find the location of the respective module in the container with this loop
01607     det = 0; ring = 0; beam = 0; disk = 0;
01608     do {
01609           
01610       // here we got it
01611       if( detectorId.GetTECEntry( det, ring, beam, disk ) == *moduleIt ) {
01612         
01613         // the nominal phi value for this module
01614         const double nominalPhi = nominalCoordinates.GetTECEntry( det, ring, beam, disk ).GetPhi();
01615         
01616         // the offset from the alignment parameters
01617         const double phiCorrection = endcapAlgorithm.GetAlignmentParameterCorrection( det, ring, beam, disk, nominalCoordinates, endcapParameters );
01618         
01619         // apply the corrections
01620         measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhi( nominalPhi - phiCorrection );
01621         
01622       }
01623       
01624     } while ( moduleLoop.TECLoop( det, ring, beam, disk ) );
01625     
01626   }
01627 
01628 }
01629 
01630 
01631 
01632 
01633 
01638 void LaserAlignment::ApplyATMaskingCorrections( LASGlobalData<LASCoordinateSet>& measuredCoordinates, LASGlobalData<LASCoordinateSet>& nominalCoordinates, LASBarrelAlignmentParameterSet& atParameters ) {
01639 
01640   // loop the list of modules to be masked
01641   for( std::vector<unsigned int>::iterator moduleIt = theMaskAtModules.begin(); moduleIt != theMaskAtModules.end(); ++moduleIt ) {
01642 
01643     // loop variables
01644     LASGlobalLoop moduleLoop;
01645     int det, beam, disk, pos;
01646 
01647     // this will calculate the corrections from the alignment parameters
01648     LASAlignmentTubeAlgorithm atAlgorithm;
01649 
01650 
01651     // find the location of the respective module in the container with these loops:
01652 
01653     // first TIB+TOB
01654     det = 2; beam = 0; pos = 0;
01655     do {
01656 
01657       // here we got it
01658       if( detectorId.GetTIBTOBEntry( det, beam, pos ) == *moduleIt ) {
01659 
01660         // the nominal phi value for this module
01661         const double nominalPhi = nominalCoordinates.GetTIBTOBEntry( det, beam, pos ).GetPhi();
01662 
01663         // the offset from the alignment parameters
01664         const double phiCorrection = atAlgorithm.GetTIBTOBAlignmentParameterCorrection( det, beam, pos, nominalCoordinates, atParameters );
01665 
01666         // apply the corrections
01667         measuredCoordinates.GetTIBTOBEntry( det, beam, pos ).SetPhi( nominalPhi - phiCorrection );
01668 
01669       }
01670 
01671     } while ( moduleLoop.TIBTOBLoop( det, beam, pos ) );
01672       
01673     
01674     
01675     // then TEC(AT)  
01676     det = 0; beam = 0; disk = 0;
01677     do {
01678           
01679       // here we got it
01680       if( detectorId.GetTEC2TECEntry( det, beam, disk ) == *moduleIt ) {
01681 
01682         // the nominal phi value for this module
01683         const double nominalPhi = nominalCoordinates.GetTEC2TECEntry( det, beam, disk ).GetPhi();
01684 
01685         // the offset from the alignment parameters
01686         const double phiCorrection = atAlgorithm.GetTEC2TECAlignmentParameterCorrection( det, beam, disk, nominalCoordinates, atParameters );
01687 
01688         // apply the corrections
01689         measuredCoordinates.GetTEC2TECEntry( det, beam, disk ).SetPhi( nominalPhi - phiCorrection );
01690 
01691       }
01692       
01693     } while ( moduleLoop.TEC2TECLoop( det, beam, disk ) );
01694     
01695   }
01696 
01697 }
01698 
01699 
01700 
01701 
01702 
01707 void LaserAlignment::testRoutine( void ) {
01708 
01709 
01710   // tracker geom. object for calculating the global beam positions
01711   const TrackerGeometry& theTracker( *theTrackerGeometry );
01712 
01713   const double atPhiPositions[8] = { 0.392699, 1.289799, 1.851794, 2.748894, 3.645995, 4.319690, 5.216791, 5.778784 };
01714   const double tecPhiPositions[8] = { 0.392699, 1.178097, 1.963495, 2.748894, 3.534292, 4.319690, 5.105088, 5.890486 };
01715   const double zPositions[9] = { 125.0, 139.0, 153.0, 167.0, 181.0, 198.5, 217.5, 238.0, 259.5 };
01716   const double zPositionsTIB[6] = { 62.0, 38.0, 18.0, -10.0, -34.0, -54.0 };
01717   const double zPositionsTOB[6] = { 104.0, 58.0, 22.0, -14.0, -50.0, -86.0 };
01718 
01719   int det, beam, disk, pos, ring;
01720   
01721   // loop TEC+- internal
01722   det = 0; ring = 0; beam = 0; disk = 0;
01723   do {
01724 
01725     const double radius = ring?84.0:56.4;
01726 
01727     // access the tracker geometry for this module
01728     const DetId theDetId( detectorId.GetTECEntry( det, ring, beam, disk ) );
01729     const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
01730     
01731     if (theStripDet) {
01732       const GlobalPoint gp( GlobalPoint::Cylindrical( radius, tecPhiPositions[beam], zPositions[disk] ) );
01733       
01734       const LocalPoint lp( theStripDet->surface().toLocal( gp ) );
01735       std::cout << "__TEC: " << 256. - theStripDet->specificTopology().strip( lp ) << std::endl; 
01736     }
01737 
01738   } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
01739 
01740 
01741   // loop TIBTOB
01742   det = 2; beam = 0; pos = 0;
01743   do {
01744 
01745     const double radius = (det==2?51.4:58.4); 
01746     const double theZ = (det==2?zPositionsTIB[pos]:zPositionsTOB[pos]);
01747 
01748     // access the tracker geometry for this module
01749     const DetId theDetId( detectorId.GetTIBTOBEntry( det, beam, pos ) );
01750     const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
01751     
01752     if (theStripDet) {
01753       const GlobalPoint gp( GlobalPoint::Cylindrical( radius, atPhiPositions[beam], theZ ) );
01754       
01755       const LocalPoint lp( theStripDet->surface().toLocal( gp ) );
01756       std::cout << "__TIBTOB det " << det << " beam " << beam << " pos " << pos << "  " << 256. - theStripDet->specificTopology().strip( lp );
01757       std::cout << "           " << theStripDet->position().perp()<< std::endl; 
01758     }
01759 
01760   } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
01761 
01762   
01763   // loop TEC2TEC
01764   det = 0; beam = 0; disk = 0;
01765   do {
01766 
01767     const double radius = 56.4;
01768 
01769     // access the tracker geometry for this module
01770     const DetId theDetId( detectorId.GetTEC2TECEntry( det, beam, disk ) );
01771     const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
01772     
01773     if (theStripDet) {
01774       const GlobalPoint gp( GlobalPoint::Cylindrical( radius, atPhiPositions[beam], zPositions[disk] ) );
01775       
01776       const LocalPoint lp( theStripDet->surface().toLocal( gp ) );
01777       std::cout << "__TEC2TEC det " << det << " beam " << beam << " disk " << disk << "  " << 256. - theStripDet->specificTopology().strip( lp ) << std::endl; 
01778     }
01779 
01780   } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
01781 
01782 
01783 }
01784 
01785 
01786 
01787 
01788 
01789 
01790 
01791 
01792 
01793 // define the SEAL module
01794 #include "FWCore/Framework/interface/MakerMacros.h"
01795 
01796 DEFINE_FWK_MODULE(LaserAlignment);
01797 
01798 
01799 
01800 
01801 // the ATTIC
01802