CMS 3D CMS Logo

LaserAlignment.cc

Go to the documentation of this file.
00001 
00010 #include "Alignment/LaserAlignment/plugins/LaserAlignment.h"
00011 #include "FWCore/Framework/interface/Event.h" 
00012 #include "TFile.h" 
00013 
00014 #include "FWCore/Framework/interface/EventSetup.h"
00015 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00016 
00017 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
00018 #include "Geometry/Records/interface/TrackerDigiGeometryRecord.h"
00019 #include "Geometry/TrackingGeometryAligner/interface/GeometryAligner.h"
00020 #include "DataFormats/DetId/interface/DetId.h"
00021 
00022 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00023 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00024 
00025 #include "DataFormats/LaserAlignment/interface/LASBeamProfileFit.h"
00026 #include "DataFormats/LaserAlignment/interface/LASBeamProfileFitCollection.h"
00027 #include "DataFormats/LaserAlignment/interface/LASAlignmentParameter.h"
00028 #include "DataFormats/LaserAlignment/interface/LASAlignmentParameterCollection.h"
00029 
00030 // Conditions database
00031 #include "FWCore/ServiceRegistry/interface/Service.h"
00032 #include "CondCore/DBOutputService/interface/PoolDBOutputService.h"
00033 
00034 
00035 LaserAlignment::LaserAlignment(edm::ParameterSet const& theConf) 
00036   : theEvents(0), 
00037     theDoPedestalSubtraction(theConf.getUntrackedParameter<bool>("SubtractPedestals", true)),
00038     enableJudgeZeroFilter(theConf.getUntrackedParameter<bool>("EnableJudgeZeroFilter", true)),
00039     theStoreToDB(theConf.getUntrackedParameter<bool>("saveToDbase", false)),
00040     theSaveHistograms(theConf.getUntrackedParameter<bool>("saveHistograms",false)),
00041     theDebugLevel(theConf.getUntrackedParameter<int>("DebugLevel",0)),
00042     theNEventsPerLaserIntensity(theConf.getUntrackedParameter<int>("NumberOfEventsPerLaserIntensity",100)),
00043     theNEventsForAllIntensities(theConf.getUntrackedParameter<int>("NumberOfEventsForAllIntensities",100)),
00044     theDoAlignmentAfterNEvents(theConf.getUntrackedParameter<int>("DoAlignmentAfterNEvents",1000)),
00045     // the following three are hard-coded until the complete package has been refurbished
00046     theAlignPosTEC( false ), // theAlignPosTEC(theConf.getUntrackedParameter<bool>("AlignPosTEC",false)),
00047     theAlignNegTEC( false ), // theAlignNegTEC(theConf.getUntrackedParameter<bool>("AlignNegTEC",false)), 
00048     theAlignTEC2TEC( false ), // theAlignTEC2TEC(theConf.getUntrackedParameter<bool>("AlignTECTIBTOBTEC",false)),
00049     theUseBrunosAlgorithm(theConf.getUntrackedParameter<bool>("UseBrunosAlignmentAlgorithm",true)),
00050     theUseNewAlgorithms(theConf.getUntrackedParameter<bool>("UseNewAlgorithms",true)),
00051     theIsGoodFit(false),
00052     theSearchPhiTIB(theConf.getUntrackedParameter<double>("SearchWindowPhiTIB",0.05)),
00053     theSearchPhiTOB(theConf.getUntrackedParameter<double>("SearchWindowPhiTOB",0.05)),
00054     theSearchPhiTEC(theConf.getUntrackedParameter<double>("SearchWindowPhiTEC",0.05)),
00055     theSearchZTIB(theConf.getUntrackedParameter<double>("SearchWindowZTIB",1.0)),
00056     theSearchZTOB(theConf.getUntrackedParameter<double>("SearchWindowZTOB",1.0)),
00057     thePhiErrorScalingFactor(theConf.getUntrackedParameter<double>("PhiErrorScalingFactor",1.0)),
00058     theDigiProducersList(theConf.getParameter<Parameters>("DigiProducersList")),
00059     theFile(),
00060     theCompression(theConf.getUntrackedParameter<int>("ROOTFileCompression",1)),
00061     theFileName(theConf.getUntrackedParameter<std::string>("ROOTFileName","test.root")),
00062     theBeamFitPS(theConf.getParameter<edm::ParameterSet>("BeamProfileFitter")),
00063     theAlignmentAlgorithmPS(theConf.getParameter<edm::ParameterSet>("AlignmentAlgorithm")),
00064     theMinAdcCounts(theConf.getUntrackedParameter<int>("MinAdcCounts",0)),
00065     theHistogramNames(), theHistograms(),
00066     theLaserPhi(),
00067     theLaserPhiError(),
00068     theNumberOfIterations(0), theNumberOfAlignmentIterations(0),
00069     theBeamFitter(),
00070     theLASAlignPosTEC(),
00071     theLASAlignNegTEC(),
00072     theLASAlignTEC2TEC(),
00073     theAlignmentAlgorithmBW(),
00074     theUseBSFrame(theConf.getUntrackedParameter<bool>("UseBeamSplitterFrame", true)),
00075     theDigiStore(),
00076     theBeamProfileFitStore(),
00077     theDigiVector(),
00078     theAlignableTracker(),
00079     theAlignRecordName( "TrackerAlignmentRcd" ),
00080     theErrorRecordName( "TrackerAlignmentErrorRcd" )
00081 
00082 {
00083   // load the configuration from the ParameterSet  
00084   edm::LogInfo("LaserAlignment") <<    "==========================================================="
00085                                   << "\n===                Start configuration                  ==="
00086                                   << "\n    theDebugLevel               = " << theDebugLevel
00087                                   << "\n    theAlignPosTEC              = " << theAlignPosTEC
00088                                   << "\n    theAlignNegTEC              = " << theAlignNegTEC
00089                                   << "\n    theAlignTEC2TEC             = " << theAlignTEC2TEC
00090                                   << "\n    theSearchPhiTIB             = " << theSearchPhiTIB
00091                                   << "\n    theSearchPhiTOB             = " << theSearchPhiTOB
00092                                   << "\n    theSearchPhiTEC             = " << theSearchPhiTEC 
00093                                   << "\n    theSearchZTIB               = " << theSearchZTIB
00094                                   << "\n    theSearchZTOB               = " << theSearchZTOB
00095                                   << "\n    theMinAdcCounts             = " << theMinAdcCounts
00096                                   << "\n    theNEventsPerLaserIntensity = " << theNEventsPerLaserIntensity
00097                                   << "\n    theNEventsForAllIntensiteis = " << theNEventsForAllIntensities
00098                                   << "\n    theDoAlignmentAfterNEvents  = " << theDoAlignmentAfterNEvents
00099                                   << "\n    ROOT filename               = " << theFileName
00100                                   << "\n    compression                 = " << theCompression
00101                                   << "\n===========================================================";
00102 
00103   // alias for the Branches in the root files
00104   std::string alias ( theConf.getParameter<std::string>("@module_label") );  
00105 
00106   // declare the product to produce
00107   produces<edm::DetSetVector<SiStripDigi> >().setBranchAlias( alias + "siStripDigis" );
00108   produces<LASBeamProfileFitCollection>().setBranchAlias( alias + "LASBeamProfileFits" );
00109   produces<LASAlignmentParameterCollection>().setBranchAlias( alias + "LASAlignmentParameters" );
00110 
00111 
00112   // the alignable tracker parts
00113   theLASAlignPosTEC = new LaserAlignmentPosTEC;
00114   theLASAlignNegTEC = new LaserAlignmentNegTEC;
00115   theLASAlignTEC2TEC = new LaserAlignmentTEC2TEC;
00116   
00117   // the alignment algorithm from Bruno
00118   theAlignmentAlgorithmBW = new AlignmentAlgorithmBW;
00119   
00120   // counter for the number of iterations, i.e. the number of BeamProfile fits and
00121   // local Millepede fits
00122   theNumberOfIterations = 0;
00123 }
00124 
00125 
00126 
00127 
00128 
00129 LaserAlignment::~LaserAlignment() {
00130 
00131   if (theSaveHistograms) {
00132     closeRootFile();
00133   }
00134   
00135   if (theFile != 0) { delete theFile; }
00136   
00137   if (theBeamFitter != 0) { delete theBeamFitter; }
00138   
00139   if (theLASAlignPosTEC != 0) { delete theLASAlignPosTEC; }
00140   if (theLASAlignNegTEC != 0) { delete theLASAlignNegTEC; }
00141   if (theLASAlignTEC2TEC != 0) { delete theLASAlignTEC2TEC; }
00142   if (theAlignableTracker != 0) { delete theAlignableTracker; }
00143   if (theAlignmentAlgorithmBW != 0) { delete theAlignmentAlgorithmBW; }
00144 }
00145 
00146 
00147 
00148 
00149 
00153 double LaserAlignment::angle(double theAngle) {
00154   return (theAngle >= 0.0) ? theAngle : theAngle + 2.0*M_PI;
00155 }
00156 
00157 
00158 
00159 
00160 
00164 void LaserAlignment::beginJob(const edm::EventSetup& theSetup) {
00165 
00166   // the beam profile fitter
00167   theBeamFitter = new BeamProfileFitter( theBeamFitPS, &theSetup );
00168 
00169   // creating a new file
00170   theFile = new TFile(theFileName.c_str(),"RECREATE","CMS ROOT file");
00171   theFile->SetCompressionLevel(theCompression);
00172       
00173   // initialize the histograms
00174   if (theFile) {
00175     this->initHistograms();
00176   }
00177   else {
00178     throw cms::Exception("LaserAlignment") << "<LaserAlignment::beginJob()>: ERROR!!! something wrong with the RootFile" << std::endl;
00179   } 
00180 
00181 
00182   LogDebug("LaserAlignment:beginJob()") << " access the Tracker Geometry ";
00183 
00184   // detector id maps (hard coded)
00185   fillDetectorId();
00186 
00187   // access the tracker
00188   theSetup.get<TrackerDigiGeometryRecord>().get( theTrackerGeometry );
00189   theSetup.get<IdealGeometryRecord>().get( gD );
00190 
00191   // access pedestals (from db..) if desired
00192   edm::ESHandle<SiStripPedestals> pedestalsHandle;
00193   if( theDoPedestalSubtraction ) {
00194     theSetup.get<SiStripPedestalsRcd>().get( pedestalsHandle );
00195     fillPedestalProfiles( pedestalsHandle );
00196   }
00197 
00198 
00199 
00200   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00201   //   PROFILE & HISTOGRAM INITIALIZATION
00202   // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
00203 
00204   // object used to build various strings for names and labels
00205   std::stringstream nameBuilder;
00206 
00207   // loop variables for use with LASGlobalLoop object
00208   int det, ring, beam, disk, pos;
00209 
00210 
00211 
00212   // loop TEC modules
00213   det = 0; ring = 0; beam = 0; disk = 0;
00214   do { // loop using LASGlobalLoop functionality
00215     // init the profiles
00216     pedestalProfiles.GetTECEntry( det, ring, beam, disk ).SetAllValuesTo( 0. );
00217     currentDataProfiles.GetTECEntry( det, ring, beam, disk ).SetAllValuesTo( 0. );
00218     collectedDataProfiles.GetTECEntry( det, ring, beam, disk ).SetAllValuesTo( 0. );
00219 
00220     // init the hit map
00221     isAcceptedProfile.SetTECEntry( det, ring, beam, disk, 0 );
00222     
00223     // create strings for histo names
00224     // to be still compatible with Maarten's code
00225     nameBuilder.clear();
00226     nameBuilder.str( "" );
00227     nameBuilder << "Beam" << beam << "Ring";
00228     if( ring == 0 ) nameBuilder << "4"; else nameBuilder << "6";
00229     nameBuilder << "Disc" << disk + 1; // +1 is a convention in maarten's code
00230     if( det == 0 ) nameBuilder << "Pos"; else nameBuilder << "Neg";
00231     nameBuilder << "TEC"; 
00232     theProfileNames.SetTECEntry( det, ring, beam, disk, nameBuilder.str() );
00233 
00234     // init the histograms
00235     nameBuilder << "Histo";
00236     summedHistograms.SetTECEntry( det, ring, beam, disk, new TH1D( nameBuilder.str().c_str(), nameBuilder.str().c_str(), 512, 0, 512 ) );
00237     summedHistograms.GetTECEntry( det, ring, beam, disk )->SetDirectory( singleModulesDir );
00238     
00239   } while ( moduleLoop.TECLoop( det, ring, beam, disk ) );
00240 
00241 
00242   // TIB & TOB section
00243   det = 2; beam = 0; pos = 0;
00244   do { // loop using LASGlobalLoop functionality
00245     // init the profiles
00246     pedestalProfiles.GetTIBTOBEntry( det, beam, pos ).SetAllValuesTo( 0. );
00247     currentDataProfiles.GetTIBTOBEntry( det, beam, pos ).SetAllValuesTo( 0. );
00248     collectedDataProfiles.GetTIBTOBEntry( det, beam, pos ).SetAllValuesTo( 0. );
00249 
00250     // init the hit map
00251     isAcceptedProfile.SetTIBTOBEntry( det, beam, pos, 0 );
00252 
00253     // create strings for histo names
00254     nameBuilder.clear();
00255     nameBuilder.str( "" );
00256     nameBuilder << "Beam" << beam;
00257     if( det == 2 ) nameBuilder << "TIB"; else nameBuilder << "TOB";
00258     nameBuilder << "Position" << pos + 1; // +1 is a convention in maarten's code
00259     theProfileNames.SetTIBTOBEntry( det, beam, pos, nameBuilder.str() );
00260 
00261     // init the histograms
00262     nameBuilder << "Histo";
00263     summedHistograms.SetTIBTOBEntry( det, beam, pos, new TH1D( nameBuilder.str().c_str(), nameBuilder.str().c_str(), 512, 0, 512 ) );
00264     summedHistograms.GetTIBTOBEntry( det, beam, pos )->SetDirectory( singleModulesDir );
00265     
00266   } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
00267 
00268 
00269   // TEC2TEC AT section
00270   det = 0; beam = 0; disk = 0;
00271   do { // loop using LASGlobalLoop functionality
00272     // init the profiles
00273     pedestalProfiles.GetTEC2TECEntry( det, beam, disk ).SetAllValuesTo( 0. );
00274     currentDataProfiles.GetTEC2TECEntry( det, beam, disk ).SetAllValuesTo( 0. );
00275     collectedDataProfiles.GetTEC2TECEntry( det, beam, disk ).SetAllValuesTo( 0. );
00276     
00277     // init the hit map
00278     isAcceptedProfile.SetTEC2TECEntry( det, beam, disk, 0 );
00279 
00280     // create strings for histo names
00281     nameBuilder.clear();
00282     nameBuilder.str( "" );
00283     nameBuilder << "Beam" << beam << "Ring4" << "Disc" << disk + 1;
00284     if( det == 0 ) nameBuilder << "Pos"; else nameBuilder << "Neg";
00285     nameBuilder << "TEC2TEC";
00286     theProfileNames.SetTEC2TECEntry( det, beam, disk, nameBuilder.str() );
00287 
00288     // init the histograms
00289     nameBuilder << "Histo";
00290     summedHistograms.SetTEC2TECEntry( det, beam, disk, new TH1D( nameBuilder.str().c_str(), nameBuilder.str().c_str(), 512, 0, 512 ) );
00291     summedHistograms.GetTEC2TECEntry( det, beam, disk )->SetDirectory( singleModulesDir );
00292     
00293   } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
00294 
00295 
00296 
00297   // Create the alignable hierarchy
00298   LogDebug("LaserAlignment:beginJob()") << " create the alignable hierarchy ";
00299   theAlignableTracker = new AlignableTracker( &(*theTrackerGeometry) );
00300 
00301 }
00302 
00303 
00304 
00305 
00306 
00307 
00311 void LaserAlignment::produce(edm::Event& theEvent, edm::EventSetup const& theSetup)  {
00312 
00313 
00314   LogDebug("LaserAlignment") << "==========================================================="
00315                               << "\n   Private analysis of event #"<< theEvent.id().event() 
00316                               << " in run #" << theEvent.id().run();
00317 
00318 
00319   // do the Tracker Statistics to retrieve the current profiles
00320   trackerStatistics( theEvent, theSetup );
00321 
00322 
00323 
00324   // index variables for the LASGlobalLoop object
00325   int det, ring, beam, disk, pos;
00326  
00327 
00328 
00329   //
00330   // first pre-loop on selected entries to find out
00331   // whether the TEC or the AT beams have fired
00332   // (pedestal profiles are left empty if false in cfg)
00333   // 
00334 
00335 
00336   // TEC+- (only ring 6)
00337   ring = 1;
00338   for( det = 0; det < 2; ++det ) {
00339     for( beam = 0; beam < 8; ++ beam ) {
00340       for( disk = 0; disk < 9; ++disk ) {
00341         if( judge.IsSignalIn( currentDataProfiles.GetTECEntry( det, ring, beam, disk ) - pedestalProfiles.GetTECEntry( det, ring, beam, disk ), 0 ) ) {
00342           isAcceptedProfile.SetTECEntry( det, ring, beam, disk, 1 );
00343         }
00344         else { // assume no initialization
00345           isAcceptedProfile.SetTECEntry( det, ring, beam, disk, 0 );
00346         }
00347       }
00348     }
00349   }
00350 
00351   // TIBTOB
00352   det = 2; beam = 0; pos = 0;
00353   do {
00354     // add current event's data and subtract pedestals
00355     if( judge.IsSignalIn( currentDataProfiles.GetTIBTOBEntry( det, beam, pos ) - pedestalProfiles.GetTIBTOBEntry( det, beam, pos ), getTOBProfileOffset( det, beam, pos ) ) ) {
00356       isAcceptedProfile.SetTIBTOBEntry( det, beam, pos, 1 );
00357     }
00358     else { // dto.
00359       isAcceptedProfile.SetTIBTOBEntry( det, beam, pos, 0 );
00360     }
00361 
00362   } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
00363 
00364 
00365 
00366 
00367   // now come the beam finders
00368   bool isTECMode = isTECBeam();
00369   LogDebug( " [LaserAlignment::produce]" ) << "LaserAlignment::isTECBeam declares this event " << ( isTECMode ? "" : "NOT " ) << "a TEC event." << std::endl;
00370   std::cout << " [LaserAlignment::produce] -- LaserAlignment::isTECBeam declares this event " << ( isTECMode ? "" : "NOT " ) << "a TEC event." << std::endl;
00371 
00372   bool isATMode  = isATBeam();
00373   LogDebug( " [LaserAlignment::produce]" ) << "LaserAlignment::isATBeam declares this event "  << ( isATMode ? "" : "NOT " )  << "an AT event." << std::endl;
00374   std::cout << " [LaserAlignment::produce] -- LaserAlignment::isATBeam declares this event "  << ( isATMode ? "" : "NOT " )  << "an AT event." << std::endl;
00375 
00376 
00377 
00378 
00379   //
00380   // now pass the pedestal subtracted profiles to the judge
00381   // if they're accepted, add them on the collectedDataProfiles
00382   // (pedestal profiles are left empty if false in cfg)
00383   //
00384 
00385 
00386   // loop TEC+- modules
00387   det = 0; ring = 0; beam = 0; disk = 0;
00388   do {
00389     
00390     LogDebug( "[LaserAlignment::produce]" ) << "Profile is: " << theProfileNames.GetTECEntry( det, ring, beam, disk ) << "." << std::endl;
00391 
00392     // this now depends on the AT/TEC mode, is this a doubly hit module? -> look for it in vector<int> tecDoubleHitDetId
00393     // (ring == 0 not necessary but makes it a little faster)
00394     if( ring == 0 && find( tecDoubleHitDetId.begin(), tecDoubleHitDetId.end(), detectorId.GetTECEntry( det, ring, beam, disk ) ) != tecDoubleHitDetId.end() ) {
00395 
00396       if( isTECMode ) { // add profile to TEC collection
00397         // add current event's data and subtract pedestals
00398         if( judge.JudgeProfile( currentDataProfiles.GetTECEntry( det, ring, beam, disk ) - pedestalProfiles.GetTECEntry( det, ring, beam, disk ), 0 ) ) {
00399           collectedDataProfiles.GetTECEntry( det, ring, beam, disk ) += currentDataProfiles.GetTECEntry( det, ring, beam, disk ) - pedestalProfiles.GetTECEntry( det, ring, beam, disk );
00400           numberOfAcceptedProfiles.GetTECEntry( det, ring, beam, disk )++;
00401         }
00402       }
00403 
00404     }
00405 
00406     else { // not a doubly hit module, don't care about the mode
00407       // add current event's data and subtract pedestals
00408       if( judge.JudgeProfile( currentDataProfiles.GetTECEntry( det, ring, beam, disk ) - pedestalProfiles.GetTECEntry( det, ring, beam, disk ), 0 ) ) {
00409         collectedDataProfiles.GetTECEntry( det, ring, beam, disk ) += currentDataProfiles.GetTECEntry( det, ring, beam, disk ) - pedestalProfiles.GetTECEntry( det, ring, beam, disk );
00410         numberOfAcceptedProfiles.GetTECEntry( det, ring, beam, disk )++;
00411       }
00412     }
00413     
00414   } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
00415 
00416 
00417   
00418 
00419 
00420   // loop TIB/TOB modules
00421   det = 2; beam = 0; pos = 0;
00422   do {
00423     
00424     LogDebug( "[LaserAlignment::produce]" ) << "Profile is: " << theProfileNames.GetTIBTOBEntry( det, beam, pos ) << "." << std::endl;
00425     
00426     // add current event's data and subtract pedestals
00427     if( judge.JudgeProfile( currentDataProfiles.GetTIBTOBEntry( det, beam, pos ) - pedestalProfiles.GetTIBTOBEntry( det, beam, pos ), getTOBProfileOffset( det, beam, pos ) ) ) {
00428       collectedDataProfiles.GetTIBTOBEntry( det, beam, pos ) += currentDataProfiles.GetTIBTOBEntry( det, beam, pos ) - pedestalProfiles.GetTIBTOBEntry( det, beam, pos );
00429       numberOfAcceptedProfiles.GetTIBTOBEntry( det, beam, pos )++;
00430     }
00431 
00432   } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
00433   
00434 
00435 
00436   // loop TEC2TEC modules
00437   det = 0; beam = 0; disk = 0;
00438   do {
00439     
00440     LogDebug( "[LaserAlignment::produce]" ) << "Profile is: " << theProfileNames.GetTEC2TECEntry( det, beam, disk ) << "." << std::endl;
00441 
00442     // this again depends on the AT/TEC mode, is this a doubly hit module?
00443     // (ring == 0 not necessary but makes it a little faster)
00444     if( ring == 0 && find( tecDoubleHitDetId.begin(), tecDoubleHitDetId.end(), detectorId.GetTECEntry( det, ring, beam, disk ) ) != tecDoubleHitDetId.end() ) {
00445 
00446       if( isATMode ) { // add profile to TEC2TEC collection
00447         // add current event's data and subtract pedestals
00448         if( judge.JudgeProfile( currentDataProfiles.GetTEC2TECEntry( det, beam, disk ) - pedestalProfiles.GetTEC2TECEntry( det, beam, disk ), 0 ) ) {
00449           collectedDataProfiles.GetTEC2TECEntry( det, beam, disk ) += currentDataProfiles.GetTEC2TECEntry( det, beam, disk ) - pedestalProfiles.GetTEC2TECEntry( det, beam, disk );
00450           numberOfAcceptedProfiles.GetTEC2TECEntry( det, beam, disk )++;
00451         }
00452       }
00453 
00454     }     
00455     
00456     else { // not a doubly hit module, don't care about the mode
00457       // add current event's data and subtract pedestals
00458       if( judge.JudgeProfile( currentDataProfiles.GetTEC2TECEntry( det, beam, disk ) - pedestalProfiles.GetTEC2TECEntry( det, beam, disk ), 0 ) ) {
00459         collectedDataProfiles.GetTEC2TECEntry( det, beam, disk ) += currentDataProfiles.GetTEC2TECEntry( det, beam, disk ) - pedestalProfiles.GetTEC2TECEntry( det, beam, disk );
00460         numberOfAcceptedProfiles.GetTEC2TECEntry( det, beam, disk )++;
00461       }
00462     }
00463       
00464 
00465   } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
00466 
00467 
00468   // ----- check if the actual event can be used -----
00469   /* here we can later on add some criteria for good alignment events!? */
00470   theEvents++;
00471   
00472 
00473   }
00474 
00475 
00476 
00477 
00478 
00482 void LaserAlignment::closeRootFile() {
00483   theFile->Write();
00484 }
00485 
00486 
00487 
00488 
00489 
00493 void LaserAlignment::endJob() {
00494 
00495   LogDebug("LaserAlignment") << "     Total Event number = " << theEvents;
00496 
00497   // index variables for the LASGlobalLoop objects
00498   int det, ring, beam, disk, pos;
00499   
00500   if( theUseNewAlgorithms ) {
00501 
00504     // this is the new barrel algorithm section, it uses LASPeakFinder to evaluate signals //
00507 
00508 
00509     // measured positions container for the algorithms
00510     LASGlobalData<LASCoordinateSet> measuredCoordinates;
00511     
00512     // the peak finder, a pair (pos/posErr in units of strips) for its results, and the success confirmation
00513     LASPeakFinder peakFinder;
00514     std::pair<double,double> peakFinderResults;
00515     bool isGoodFit;
00516     
00517     // tracker geom. object for calculating the global beam positions
00518     const TrackerGeometry& theTracker( *theTrackerGeometry );
00519     
00520     // fill LASGlobalData<LASCoordinateSet> nominalCoordinates
00521     CalculateNominalCoordinates();
00522     
00523     // for determining the phi errors
00524     //    ErrorFrameTransformer errorTransformer;
00525     
00526     // do the fits for TEC+- internal
00527     det = 0; ring = 0; beam = 0; disk = 0;
00528     do {
00529       
00530       // do the fit
00531       isGoodFit = peakFinder.FindPeakIn( collectedDataProfiles.GetTECEntry( det, ring, beam, disk ), peakFinderResults, 0 ); // offset is 0 for TEC
00532       // now we have the measured positions in units of strips. 
00533       if( !isGoodFit ) std::cout << " [LaserAlignment::endJob] ** WARNING: Fit failed for TEC det: "
00534                                  << det << ", ring: " << ring << ", beam: " << beam << ", disk: " << disk << "." << std::endl;
00535 
00536         // <- here we will later implement the kink corrections
00537     
00538         // access the tracker geometry for this module
00539         const DetId theDetId( detectorId.GetTECEntry( det, ring, beam, disk ) );
00540         const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
00541 
00542         // first, set the measured coordinates to their nominal values
00543         measuredCoordinates.SetTECEntry( det, ring, beam, disk, nominalCoordinates.GetTECEntry( det, ring, beam, disk ) );
00544 
00545         if( isGoodFit ) { // convert strip position to global phi and replace the nominal phi value/error
00546           const GlobalPoint& globalPoint = theStripDet->surface().toGlobal( theStripDet->specificTopology().localPosition( peakFinderResults.first ) );
00547           measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhi( ConvertAngle( globalPoint.barePhi() ) );
00548           measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhiError( 0.00046  ); // PRELIMINARY ESTIMATE
00549           //      const GlobalError& globalError = errorTransformer.transform( theStripDet->specificTopology().localError( peakFinderResults.first, pow( peakFinderResults.second, 2 ) ), theStripDet->surface() );
00550           //      measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhiError( globalError.phierr( globalPoint ) );
00551         }
00552         else { // keep nominal position but set a giant phi error so that the module is ignored by the alignment algorithm
00553           measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhiError( 1000. );
00554         }
00555     
00556     } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
00557 
00558 
00559 
00560 
00561     // do the fits for TIB/TOB
00562     det = 2; beam = 0; pos = 0;
00563     do {
00564 
00565       // do the fit
00566       isGoodFit = peakFinder.FindPeakIn( collectedDataProfiles.GetTIBTOBEntry( det, beam, pos ), peakFinderResults, getTOBProfileOffset( det, beam, pos ) );
00567       // now we have the measured positions in units of strips.
00568       if( !isGoodFit ) std::cout << " [LaserAlignment::endJob] ** WARNING: Fit failed for TIB/TOB det: "
00569                                  << det << ", beam: " << beam << ", pos: " << pos << "." << std::endl;
00570 
00571         // <- here we will later implement the kink corrections
00572     
00573         // access the tracker geometry for this module
00574         const DetId theDetId( detectorId.GetTIBTOBEntry( det, beam, pos ) );
00575         const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
00576 
00577         // first, set the measured coordinates to their nominal values
00578         measuredCoordinates.SetTIBTOBEntry( det, beam, pos, nominalCoordinates.GetTIBTOBEntry( det, beam, pos ) );
00579 
00580         if( isGoodFit ) { // convert strip position to global phi and replace the nominal phi value/error
00581           measuredCoordinates.GetTIBTOBEntry( det, beam, pos ).SetPhi( ConvertAngle( theStripDet->surface().toGlobal( theStripDet->specificTopology().localPosition( peakFinderResults.first ) ).barePhi() ) );
00582           measuredCoordinates.GetTIBTOBEntry( det, beam, pos ).SetPhiError( 0.00028 ); // PRELIMINARY ESTIMATE
00583         }
00584         else { // keep nominal position but set a giant phi error so that the module is ignored by the alignment algorithm
00585           measuredCoordinates.GetTIBTOBEntry( det, beam, pos ).SetPhiError( 1000. );
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, 0 ); // no offset for TEC modules
00599       // now we have the positions in units of strips.
00600       if( !isGoodFit ) std::cout << " [LaserAlignment::endJob] ** WARNING: Fit failed for TEC2TEC det: "
00601                                  << det << ", beam: " << beam << ", disk: " << disk << "." << std::endl;
00602 
00603         // <- here we will later implement the kink corrections
00604     
00605         // access the tracker geometry for this module
00606         const DetId theDetId( detectorId.GetTEC2TECEntry( det, beam, pos ) );
00607         const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
00608 
00609         // first, set the measured coordinates to their nominal values
00610         measuredCoordinates.SetTEC2TECEntry( det, beam, disk, nominalCoordinates.GetTEC2TECEntry( det, beam, disk ) );
00611     
00612         if( isGoodFit ) { // convert strip position to global phi and replace the nominal phi value/error
00613           measuredCoordinates.GetTEC2TECEntry( det, beam, disk ).SetPhi( ConvertAngle( theStripDet->surface().toGlobal( theStripDet->specificTopology().localPosition( peakFinderResults.first ) ).barePhi() ) );
00614           measuredCoordinates.GetTEC2TECEntry( det, beam, disk ).SetPhiError( 0.00047 ); // PRELIMINARY ESTIMATE
00615         }
00616         else { // keep nominal position but set a giant phi error so that the module is ignored by the alignment algorithm
00617           measuredCoordinates.GetTEC2TECEntry( det, beam, disk ).SetPhiError( 1000. );
00618         }
00619 
00620     } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
00621   
00622 
00623 
00624 
00625     // run the algorithms
00626     LASBarrelAlignmentParameterSet barrelParameters = barrelAlgorithm.CalculateParameters( measuredCoordinates, nominalCoordinates );
00627     LASEndcapAlignmentParameterSet endcapParameters = endcapAlgorithm.CalculateParameters( measuredCoordinates, nominalCoordinates );
00628 
00629     // combine the results and update the db object
00630     LASGeometryUpdater geometryUpdater;
00631     geometryUpdater.Update( endcapParameters, barrelParameters, *theAlignableTracker );
00632   
00633 
00634   } // if( !theUseBrunosAlgorithm )
00635 
00636 
00637 
00638 
00639 
00640 
00641 
00642 
00643   else if( !theUseNewAlgorithms ) {
00644 
00647     // this is the old algorithm section, it uses BeamProfileFitter to evaluate signals,   //
00648     // this will be replaced and work the same way as the barrel part                      //
00651     
00652     
00653     
00654     // create an empty output collection
00655     //  std::auto_ptr<LASBeamProfileFitCollection> theFitOutput(new LASBeamProfileFitCollection);
00656     //  std::auto_ptr<LASAlignmentParameterCollection> theAlignmentParameterOutput(new LASAlignmentParameterCollection);
00657     
00658     theDigiVector.reserve(10000);
00659     theDigiVector.clear();
00660     
00661     // vectors to store the beam positions for usage with Bruno's alignment algorithm
00662     LASvec2D thePosTECR4BeamPositions(8,9);
00663     LASvec2D thePosTECR6BeamPositions(8,9);
00664     LASvec2D theNegTECR4BeamPositions(8,9);
00665     LASvec2D theNegTECR6BeamPositions(8,9);
00666     LASvec2D theTEC2TECBeamPositions(8,22);
00667   
00668     LASvec2D thePosTECR4BeamPositionErrors(8,9);
00669     LASvec2D thePosTECR6BeamPositionErrors(8,9);
00670     LASvec2D theNegTECR4BeamPositionErrors(8,9);
00671     LASvec2D theNegTECR6BeamPositionErrors(8,9);
00672     LASvec2D theTEC2TECBeamPositionErrors(8,22);
00673 
00674     LogDebug("LaserAlignment") << "===========================================================";
00675   
00676     // the fit of the beam profiles
00677     //  if (theEvents % theNEventsPerLaserIntensity == 0)
00678     //  {
00679     // do the beam profile fit
00680     //    fit(theSetup);
00681     //  }
00682 
00683     //  if (theEvents % theNEventsForAllIntensities == 0)
00684     //  {
00685 
00686 
00687   
00688     std::vector<LASBeamProfileFit> collector;
00689 
00690     // do the fits for TEC+-
00691     det = 0; ring = 0; beam = 0; disk = 0;
00692     do {
00693 
00694       // fill histo from collected data.
00695       // later, the fitter will accept the profile directly
00696       for( int bin = 0; bin < 512; ++bin ) {
00697         summedHistograms.GetTECEntry( det, ring, beam, disk )->SetBinContent( 1 + bin, collectedDataProfiles.GetTECEntry( det, ring, beam, disk ).GetValue( bin ) );
00698       }
00699 
00700       // will store the detids in a separate container later, yet use Maarten's construct here
00701       std::map<std::string, std::pair<DetId, TH1D*> >::iterator iHist = theHistograms.find( theProfileNames.GetTECEntry( det, ring, beam, disk ) );
00702       if ( iHist != theHistograms.end() ) {
00703       
00704         // here we prepare the preliminary interface to Maarten's code
00705         int aRing, aBeam, aDet;
00706         if( ring == 0 ) { // this is Ring4
00707           aRing = 4;
00708           aBeam = beam;
00709         }
00710         else { // this is Ring6
00711           aRing = 6;
00712           aBeam = beam + 8;
00713         }
00714         if( det == 0 ) aDet = 2; // TEC+
00715         else aDet = 1; // TEC-
00716 
00717       
00718         // pass the histo to the beam fitter
00719         collector = theBeamFitter->doFit((iHist->second).first,
00720                                          summedHistograms.GetTECEntry( det, ring, beam, disk ), 
00721                                          theSaveHistograms,
00722                                          numberOfAcceptedProfiles.GetTECEntry( det, ring, beam, disk ), 
00723                                          aBeam, disk, aRing, 
00724                                          aDet, false /*isTEC2TEC*/, theIsGoodFit );
00725 
00726         // if the fit succeeded, add the LASBeamProfileFit to the output collection for storage
00727         // and additionally add the LASBeamProfileFit to the map for later processing (we need
00728         // the info from the fit for the Alignment Algorithm)
00729         if ( theIsGoodFit ) {
00730           // add the result of the fit to the map
00731           theBeamProfileFitStore[theProfileNames.GetTECEntry( det, ring, beam, disk )] = collector;
00732         }
00733       
00734         // set theIsGoodFit to false again for the next fit
00735         theIsGoodFit = false;
00736 
00737 
00738       }
00739       else std::cerr << "[LaserAlignment::endJob] ** WARNING: No pair<DetId,TH1D*> found for TEC det " 
00740                      << det << " ring " << ring << " beam " << beam << " disk " << disk << "." << std::endl;
00741 
00742     } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
00743 
00744   
00745 
00746     // do the fits for TIB/TOB
00747     det = 2; beam = 0; pos = 0;
00748     do {
00749 
00750       // fill histo from collected data.
00751       // later, the fitter will accept the profile directly
00752       for( int bin = 0; bin < 512; ++bin ) {
00753         summedHistograms.GetTIBTOBEntry( det, beam, pos )->SetBinContent( 1 + bin, collectedDataProfiles.GetTIBTOBEntry( det, beam, pos ).GetValue( bin ) );
00754       }
00755 
00756       // will store the detids in a separate container later, yet use Maarten's construct here
00757       std::map<std::string, std::pair<DetId, TH1D*> >::iterator iHist = theHistograms.find( theProfileNames.GetTIBTOBEntry( det, beam, pos ) );
00758       if ( iHist != theHistograms.end() ) {
00759       
00760       
00761         // here we prepare the interface to Maarten's code
00762         int aRing = 0, aBeam = 0, aDet = 0;
00763         disk = 0;
00764       
00765         // pass the histo to the beam fitter
00766         collector = theBeamFitter->doFit((iHist->second).first,
00767                                          summedHistograms.GetTIBTOBEntry( det, beam, pos ), 
00768                                          theSaveHistograms,
00769                                          numberOfAcceptedProfiles.GetTIBTOBEntry( det, beam, pos ), 
00770                                          aBeam, disk, aRing, 
00771                                          aDet, false /*isTEC2TEC*/, theIsGoodFit );
00772 
00773         // if the fit succeeded, add the LASBeamProfileFit to the output collection for storage
00774         // and additionally add the LASBeamProfileFit to the map for later processing (we need
00775         // the info from the fit for the Alignment Algorithm)
00776         if ( theIsGoodFit ) {
00777           // add the result of the fit to the map
00778           theBeamProfileFitStore[theProfileNames.GetTIBTOBEntry( det, beam, pos )] = collector;
00779         }
00780       
00781         // set theIsGoodFit to false again for the next fit
00782         theIsGoodFit = false;
00783 
00784 
00785       }
00786       else std::cerr << "[LaserAlignment::endJob] ** WARNING: No pair<DetId,TH1D*> found for TIBTOB det " 
00787                      << det << " beam " << beam << " pos " << pos << "." << std::endl;
00788     
00789     } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
00790 
00791 
00792 
00793 
00794 
00795 
00796 
00797     // now the fits for TEC AT
00798     det = 0; ring = 0; beam = 0; disk = 0;
00799     do {
00800 
00801       // fill histo from collected data.
00802       // later, the fitter will accept the profile directly
00803       for( int bin = 0; bin < 512; ++bin ) {
00804         summedHistograms.GetTEC2TECEntry( det, beam, disk )->SetBinContent( 1 + bin, collectedDataProfiles.GetTEC2TECEntry( det, beam, disk ).GetValue( bin ) );
00805       }
00806 
00807       // will store the detids in a separate container later, yet use Maarten's construct here
00808       std::map<std::string, std::pair<DetId, TH1D*> >::iterator iHist = theHistograms.find( theProfileNames.GetTEC2TECEntry( det, beam, disk ) );
00809       if ( iHist != theHistograms.end() ) {
00810       
00811         // here we prepare the interface to Maarten's code
00812         int aRing, aBeam, aDet;
00813         aRing = 4; // always Ring4
00814         aBeam = beam;
00815         if( det == 0 ) aDet = 2; // TEC+
00816         else aDet = 1; // TEC-
00817 
00818       
00819         // pass the histo to the beam fitter
00820         collector = theBeamFitter->doFit((iHist->second).first,
00821                                          summedHistograms.GetTEC2TECEntry( det, beam, disk ), 
00822                                          theSaveHistograms,
00823                                          numberOfAcceptedProfiles.GetTEC2TECEntry( det, beam, disk ), 
00824                                          aBeam, disk, aRing, 
00825                                          aDet, true /*isTEC2TEC*/, theIsGoodFit );
00826 
00827         // if the fit succeeded, add the LASBeamProfileFit to the output collection for storage
00828         // and additionally add the LASBeamProfileFit to the map for later processing (we need
00829         // the info from the fit for the Alignment Algorithm)
00830         if ( theIsGoodFit ) {
00831           // add the result of the fit to the map
00832           theBeamProfileFitStore[theProfileNames.GetTEC2TECEntry( det, beam, disk )] = collector;
00833         }
00834       
00835         // set theIsGoodFit to false again for the next fit
00836         theIsGoodFit = false;
00837 
00838       }
00839       else {
00840         std::cerr << "[LaserAlignment::endJob] ** WARNING: No pair<DetId,TH1D*> found for TEC AT det " 
00841                   << det << " beam " << beam << " disk " << disk << "." << std::endl;
00842         std::cerr << "                                     (if beam=0,3,5 it's probably ok)" << std::endl;
00843       }
00844 
00845     } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
00846 
00847 
00848 
00849 
00850     // increase the counter for the iterations
00851     //  theNumberOfIterations++;
00852 
00853     // put the digis of the beams into the StripDigiCollection
00854     for ( std::map<DetId, std::vector<SiStripRawDigi> >::const_iterator p = theDigiStore.begin(); p != theDigiStore.end(); ++p ) {
00855 
00856       edm::DetSet<SiStripRawDigi> collector((p->first).rawId());
00857     
00858       if ( ( p->second ).size() > 0 ) {
00859         collector.data = (p->second);
00860         theDigiVector.push_back(collector);
00861       }
00862     }
00863 
00864     // clear the map to fill new digis for the next theNEventsForAllIntensities number of events
00865     theDigiStore.clear();
00866 
00867 
00868     // put the LASBeamProfileFits into the LASBeamProfileFitCollection
00869     // loop over the map with the histograms and lookup the LASBeamFits
00870     for ( std::vector<std::string>::const_iterator iHistName = theHistogramNames.begin(); iHistName != theHistogramNames.end(); ++iHistName ) {
00871 
00872       std::map<std::string, std::pair<DetId, TH1D*> >::iterator iHist = theHistograms.find(*iHistName);
00873       if ( iHist != theHistograms.end() ) {
00874       
00875         std::map<std::string, std::vector<LASBeamProfileFit> >::iterator iBeamFit = theBeamProfileFitStore.find(*iHistName);
00876         if ( iBeamFit != theBeamProfileFitStore.end() ) {
00877         
00878           // get the DetId from the map with histograms
00879           //    unsigned int theDetId = ((iHist->second).first).rawId();
00880           // get the information for the LASBeamProfileFitCollection
00881           LASBeamProfileFitCollection::Range inputRange;
00882           inputRange.first = (iBeamFit->second).begin();
00883           inputRange.second = (iBeamFit->second).end();
00884         
00885           //    theFitOutput->put(inputRange,theDetId); // no production yet
00886         
00887           // now fill the fitted phi position and error into the appropriate vectors
00888           // which will be used by the Alignment Algorithm
00889           LASBeamProfileFit theFit = (iBeamFit->second).at(0);
00890           theLaserPhi.push_back(theFit.phi());
00891           theLaserPhiError.push_back(thePhiErrorScalingFactor * theFit.phiError());
00892         
00893           // fill also the LASvec2D for Bruno's algorithm
00894           std::vector<int> sectorLocation = checkBeam(iHistName, iHist);
00895         
00896           if (sectorLocation.at(0) == 1) // TEC- beams
00897             {
00898               if (sectorLocation.at(1) == 4) // Ring 4
00899                 {
00900                   theNegTECR4BeamPositions[sectorLocation.at(2)][sectorLocation.at(3)] = theFit.pitch() * (theFit.mean()-255.5);
00901                   theNegTECR4BeamPositionErrors[sectorLocation.at(2)][sectorLocation.at(3)] = theFit.pitch() * theFit.meanError();
00902                 }
00903               else if (sectorLocation.at(1) == 6) // Ring 6
00904                 {
00905                   theNegTECR6BeamPositions[sectorLocation.at(2)][sectorLocation.at(3)] = theFit.pitch() * (theFit.mean()-255.5);
00906                   theNegTECR6BeamPositionErrors[sectorLocation.at(2)][sectorLocation.at(3)] = theFit.pitch() * theFit.meanError();
00907                 }
00908             }
00909           else if (sectorLocation.at(0) == 2) // TEC+ beams
00910             {
00911               if (sectorLocation.at(1) == 4) // Ring 4
00912                 {
00913                   thePosTECR4BeamPositions[sectorLocation.at(2)][sectorLocation.at(3)] = theFit.pitch() * (theFit.mean()-255.5);
00914                   thePosTECR4BeamPositionErrors[sectorLocation.at(2)][sectorLocation.at(3)] = theFit.pitch() * theFit.meanError();
00915                 }
00916               else if (sectorLocation.at(1) == 6) // Ring 6
00917                 {
00918                   thePosTECR6BeamPositions[sectorLocation.at(2)][sectorLocation.at(3)] = theFit.pitch() * (theFit.mean()-255.5);
00919                   thePosTECR6BeamPositionErrors[sectorLocation.at(2)][sectorLocation.at(3)] = theFit.pitch() * theFit.meanError();
00920                 }                               
00921             }
00922           // implementation of TEC2TEC beams has to be done!!!!!!
00923         }
00924         else
00925           {
00926             // no BeamFit found for this layer, use the nominal phi position of the Det for the Alignment Algorithm
00927             //            // access the tracker
00928             //            edm::ESHandle<TrackerGeometry> theTrackerGeometry;
00929             //            theSetup.get<TrackerDigiGeometryRecord>().get(theTrackerGeometry);
00930           
00931             double thePhi = angle(theTrackerGeometry->idToDet((iHist->second).first)->surface().position().phi());
00932             double thePhiError = 0.1;
00933           
00934             LogDebug("LaserAlignment") << " no LASBeamProfileFit found for " << (*iHistName) << "! Use nominal phi position (" 
00935                                        << thePhi << ") for alignment ";
00936             theLaserPhi.push_back(thePhi);
00937             theLaserPhiError.push_back(thePhiErrorScalingFactor * thePhiError);
00938           
00940             //           const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>(theTrackerGeometry->idToDet((iHist->second).first));
00941           
00942             // double thePosition = 255.5 * theStripDet->specificTopology().localPitch(theStripDet->specificTopology().localPosition(255.5));
00943             double thePosition = 0.0;
00944             double thePositionError = 0.05; // set the error to half a milllimeter in this case
00945           
00946             // fill also the LASvec2D for Bruno's algorithm
00947             std::vector<int> sectorLocation = checkBeam(iHistName, iHist);
00948           
00949             if (sectorLocation.at(0) == 1) // TEC- beams
00950               {
00951                 if (sectorLocation.at(1) == 4) // Ring 4
00952                   {
00953                     theNegTECR4BeamPositions[sectorLocation.at(2)][sectorLocation.at(3)] = thePosition;
00954                     theNegTECR4BeamPositionErrors[sectorLocation.at(2)][sectorLocation.at(3)] = thePositionError;
00955                   }
00956                 else if (sectorLocation.at(1) == 6) // Ring 6
00957                   {
00958                     theNegTECR6BeamPositions[sectorLocation.at(2)][sectorLocation.at(3)] = thePosition;
00959                     theNegTECR6BeamPositionErrors[sectorLocation.at(2)][sectorLocation.at(3)] = thePositionError;
00960                   }
00961               }
00962             else if (sectorLocation.at(0) == 2) // TEC+ beams
00963               {
00964                 if (sectorLocation.at(1) == 4) // Ring 4
00965                   {
00966                     thePosTECR4BeamPositions[sectorLocation.at(2)][sectorLocation.at(3)] = thePosition;
00967                     thePosTECR4BeamPositionErrors[sectorLocation.at(2)][sectorLocation.at(3)] = thePositionError;
00968                   }
00969                 else if (sectorLocation.at(1) == 6) // Ring 6
00970                   {
00971                     thePosTECR6BeamPositions[sectorLocation.at(2)][sectorLocation.at(3)] = thePosition;
00972                     thePosTECR6BeamPositionErrors[sectorLocation.at(2)][sectorLocation.at(3)] = thePositionError;
00973                   }                             
00974               }
00975             // implementation of TEC2TEC beams has to be done!!!!!
00976           }
00977       }
00978       else 
00979         { 
00980           throw cms::Exception("LaserAlignment") << " You are in serious trouble!!! no entry for " << (*iHistName) << " found. "
00981                                                  << " To avoid the calculation of wrong alignment corrections the program will abort! "; 
00982         }
00983     }
00984     // clear the map to fill new LASBeamProfileFits for the next theNEventsForAllIntensities number of events
00985     theBeamProfileFitStore.clear();
00986     //  }
00987   
00988     // do the alignment of the tracker
00989     //   if (theEvents % theDoAlignmentAfterNEvents == 0) // do this in any case!!!
00990     //     {
00991     //       // Create the alignable hierarchy
00992     //       theAlignableTracker = new AlignableTracker( &(*gD),
00993     //                                            &(*theTrackerGeometry) );
00994 
00995     // do the Alignment of the Tracker (with Millepede) ...
00996     //  alignmentAlgorithm(theAlignmentAlgorithmPS, theAlignableTracker);
00997     // set the number of iterations to zero for the next alignment round *** NOT NEEDED FOR BRUNO'S ALGO!
00998     theNumberOfIterations = 0;
00999 
01000 
01001     if (theUseBrunosAlgorithm) {                        
01002 
01003       // do the Alignment with Bruno's algorithm
01004       std::vector<LASAlignmentParameter> theAPPosTECR4;
01005       std::vector<LASAlignmentParameter> theAPPosTECR6;
01006       std::vector<LASAlignmentParameter> theAPNegTECR4;
01007       std::vector<LASAlignmentParameter> theAPNegTECR6;
01008       // which return type do we need to calculate the final correction ((corr_R4 + corr_R6)/2)??
01009       // get them from the returned std::vector<LASAlignmentParameter>!
01010       theAPPosTECR4 = theAlignmentAlgorithmBW->run("TEC+Ring4",thePosTECR4BeamPositions, 
01011                                                    thePosTECR4BeamPositionErrors, theUseBSFrame, 4);
01012       theAPPosTECR6 = theAlignmentAlgorithmBW->run("TEC+Ring6",thePosTECR6BeamPositions, 
01013                                                    thePosTECR6BeamPositionErrors, theUseBSFrame, 6);
01014       theAPNegTECR4 = theAlignmentAlgorithmBW->run("TEC-Ring4",theNegTECR4BeamPositions, 
01015                                                    theNegTECR4BeamPositionErrors, theUseBSFrame, 4);
01016       theAPNegTECR6 = theAlignmentAlgorithmBW->run("TEC-Ring6",theNegTECR6BeamPositions, 
01017                                                    theNegTECR6BeamPositionErrors, theUseBSFrame, 6);
01018       // implementation of TEC2TEC has to be done!!!!!
01019       // theAlignmentAlgorithmBW->run(theTEC2TECBeamPositions, theTEC2TECBeamPositionErrors);
01020 
01021       // put the alignment parameters in the output collection
01022       // first TEC+ Ring 4
01023       LASAlignmentParameterCollection::Range inputRangeT1R4;
01024       inputRangeT1R4.first = theAPPosTECR4.begin();
01025       inputRangeT1R4.second = theAPPosTECR4.end();
01026       //        theAlignmentParameterOutput->put(inputRangeT1R4,"TEC+Ring4");
01027       // now TEC+ Ring 6
01028       LASAlignmentParameterCollection::Range inputRangeT1R6;
01029       inputRangeT1R6.first = theAPPosTECR6.begin();
01030       inputRangeT1R6.second = theAPPosTECR6.end();
01031       //        theAlignmentParameterOutput->put(inputRangeT1R6,"TEC+Ring6");
01032       // now TEC- Ring 4
01033       LASAlignmentParameterCollection::Range inputRangeT2R4;
01034       inputRangeT2R4.first = theAPNegTECR4.begin();
01035       inputRangeT2R4.second = theAPNegTECR4.end();
01036       //        theAlignmentParameterOutput->put(inputRangeT2R4,"TEC-Ring4");
01037       // finally TEC- Ring 6
01038       LASAlignmentParameterCollection::Range inputRangeT2R6;
01039       inputRangeT2R6.first = theAPNegTECR6.begin();
01040       inputRangeT2R6.second = theAPNegTECR6.end();
01041       //        theAlignmentParameterOutput->put(inputRangeT2R6,"TEC-Ring6");
01042 
01043       // apply the calculated corrections to the alignable Tracker. This will propagate the corrections from the
01044       // higher level hierarchy (e.g. the TEC discs) to the lowest level in the Tracker Hierarchy: the Dets
01048       const align::Alignables& TECs = theAlignableTracker->endCaps();
01049 
01050       const Alignable *TECplus = TECs[0], *TECminus = TECs[1];
01051 
01052       if (TECplus->globalPosition().z() < 0) // reverse order
01053         {
01054           TECplus = TECs[1]; TECminus = TECs[0];
01055         }
01056 
01057       const align::Alignables& posDisks = TECplus->components();
01058       const align::Alignables& negDisks = TECminus->components();
01059 
01060       for (unsigned int i = 0; i < 9; ++i) {
01061         
01062         align::GlobalVector translationPos( -1.0 * (theAPPosTECR4.at(0).dxk()[i] + theAPPosTECR6.at(0).dxk()[i])/2,
01063                                             -1.0 * (theAPPosTECR4.at(0).dyk()[i] + theAPPosTECR6.at(0).dyk()[i])/2,
01064                                             0.0);
01065         align::GlobalVector translationNeg( -1.0 * (theAPNegTECR4.at(0).dxk()[i] + theAPNegTECR6.at(0).dxk()[i])/2,
01066                                             -1.0 * (theAPNegTECR4.at(0).dyk()[i] + theAPNegTECR6.at(0).dyk()[i])/2,
01067                                             0.0);
01068         // TODO - Implement usage and propagation of errors!!!!
01069         AlignmentPositionError positionErrorPos(0.0, 0.0, 0.0);
01070         align::RotationType rotationErrorPos( Basic3DVector<float>(0.0, 0.0, 1.0), 0.0 );
01071         AlignmentPositionError positionErrorNeg(0.0, 0.0, 0.0);
01072         align::RotationType rotationErrorNeg( Basic3DVector<float>(0.0, 0.0, 1.0), 0.0 );
01073         Alignable* posDisk = posDisks[i];
01074         Alignable* negDisk = negDisks[i];
01075         
01076         // TEC+
01077         posDisk->move(translationPos);
01078         posDisk->addAlignmentPositionError(positionErrorPos);
01079         posDisk->rotateAroundGlobalZ(-1.0 * (theAPPosTECR4.at(0).dphik()[i] + theAPPosTECR6.at(0).dphik()[i])/2);
01080         posDisk->addAlignmentPositionErrorFromRotation(rotationErrorPos);
01081         // TEC-
01082         negDisk->move(translationNeg);
01083         negDisk->addAlignmentPositionError(positionErrorNeg);
01084         negDisk->rotateAroundGlobalZ(-1.0 * (theAPNegTECR4.at(0).dphik()[i] + theAPNegTECR6.at(0).dphik()[i])/2);
01085         negDisk->addAlignmentPositionErrorFromRotation(rotationErrorNeg);
01086       }
01087     }
01088 
01089 
01090   } // if( !theUseNewAlgorithms )
01091   
01092 
01093   
01094 
01095 
01096 
01097   // store the estimated alignment parameters into the DB
01098   // first get them
01099   Alignments* alignments =  theAlignableTracker->alignments();
01100   AlignmentErrors* alignmentErrors = theAlignableTracker->alignmentErrors();
01101 
01102   // Write alignments to DB: have to sort beforhand!
01103   if ( theStoreToDB ) {
01104 
01105     std::cout << " [LaserAlignment::endJob] -- Storing the calculated alignment parameters to the DataBase:" << std::endl;
01106 
01107     // Call service
01108     edm::Service<cond::service::PoolDBOutputService> poolDbService;
01109     if( !poolDbService.isAvailable() ) // Die if not available
01110       throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
01111     
01112     // Store
01113     if ( poolDbService->isNewTagRequest(theAlignRecordName) ) {
01114       poolDbService->createNewIOV<Alignments>( alignments, poolDbService->currentTime(), poolDbService->endOfTime(), theAlignRecordName );
01115     }
01116     else {
01117       poolDbService->appendSinceTime<Alignments>( alignments, poolDbService->currentTime(), theAlignRecordName );
01118     }
01119 
01120     if ( poolDbService->isNewTagRequest(theErrorRecordName) ) {
01121       poolDbService->createNewIOV<AlignmentErrors>( alignmentErrors, poolDbService->currentTime(), poolDbService->endOfTime(), theErrorRecordName );
01122     }
01123     else {
01124       poolDbService->appendSinceTime<AlignmentErrors>( alignmentErrors, poolDbService->currentTime(), theErrorRecordName );
01125     }
01126                                                        
01127     std::cout << " [LaserAlignment::endJob] -- Storing done." << std::endl;
01128     
01129 }
01130 
01131 
01132 
01133   //       // Store result to EventSetup
01134   //       GeometryAligner aligner;
01135   //       aligner.applyAlignments<TrackerGeometry>( &(*theTrackerGeometry), &(*alignments), &(*alignmentErrors) );
01136 
01137   //    }
01138 
01139   // create the output collection for the DetSetVector
01140   std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > theDigiOutput(new edm::DetSetVector<SiStripRawDigi>(theDigiVector));
01141 
01142   // write output to file
01143   //    theEvent.put(theDigiOutput);
01144   //    theEvent.put(theFitOutput);
01145   //    theEvent.put(theAlignmentParameterOutput);
01146 
01147   //   // clear the vector with pairs of DetIds and Histograms
01148   //   theHistograms.clear();
01149 
01150 }
01151 
01152 
01153 
01154 
01155 
01161 void LaserAlignment::fillPedestalProfiles( edm::ESHandle<SiStripPedestals>& pedestalsHandle ) {
01162 
01163   int det, ring, beam, disk, pos;
01164 
01165   // loop TEC modules (yet without AT)
01166   det = 0; ring = 0; beam = 0; disk = 0;
01167   do { // loop using LASGlobalLoop functionality
01168     SiStripPedestals::Range pedRange = pedestalsHandle->getRange( detectorId.GetTECEntry( det, ring, beam, disk ) );
01169     for( int strip = 0; strip < 512; ++strip ) {
01170       int thePedestal = int( pedestalsHandle->getPed( strip, pedRange ) );
01171       if( thePedestal > 895 ) thePedestal -= 1024;
01172       pedestalProfiles.GetTECEntry( det, ring, beam, disk ).SetValue( strip, thePedestal );
01173     }
01174   } while ( moduleLoop.TECLoop( det, ring, beam, disk ) );
01175 
01176 
01177   // TIB & TOB section
01178   det = 2; beam = 0; pos = 0;
01179   do { // loop using LASGlobalLoop functionality
01180     SiStripPedestals::Range pedRange = pedestalsHandle->getRange( detectorId.GetTIBTOBEntry( det, beam, pos ) );
01181     for( int strip = 0; strip < 512; ++strip ) {
01182       int thePedestal = int( pedestalsHandle->getPed( strip, pedRange ) );
01183       if( thePedestal > 895 ) thePedestal -= 1024;
01184       pedestalProfiles.GetTIBTOBEntry( det, beam, pos ).SetValue( strip, thePedestal );
01185     }
01186   } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
01187 
01188 
01189   // TEC2TEC AT section
01190   det = 0; beam = 0; disk = 0;
01191   do { // loop using LASGlobalLoop functionality
01192     SiStripPedestals::Range pedRange = pedestalsHandle->getRange( detectorId.GetTEC2TECEntry( det, beam, disk ) );
01193     for( int strip = 0; strip < 512; ++strip ) {
01194       int thePedestal = int( pedestalsHandle->getPed( strip, pedRange ) );
01195       if( thePedestal > 895 ) thePedestal -= 1024;
01196       pedestalProfiles.GetTEC2TECEntry( det, beam, disk ).SetValue( strip, thePedestal );
01197     }
01198   } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
01199 
01200 }
01201 
01202 
01203 
01204 
01205 
01209 void LaserAlignment::fillAdcCounts( TH1D* theHistogram, DetId theDetId,
01210                                     edm::DetSet<SiStripRawDigi>::const_iterator digiRangeIterator,
01211                                     edm::DetSet<SiStripRawDigi>::const_iterator digiRangeIteratorEnd,
01212                                     LASModuleProfile& theProfile ) {
01213 
01214   if (theDebugLevel > 4) std::cout << "<LaserAlignment::fillAdcCounts()>: DetUnit: " << theDetId.rawId() << std::endl;
01215 
01216   // save the first position to calculate the index (= channel/strip number)
01217   int channel = 0;
01218   edm::DetSet<SiStripRawDigi>::const_iterator theFirstPosition = digiRangeIterator;
01219 
01220   // loop over all the digis in this det
01221   for (; digiRangeIterator != digiRangeIteratorEnd; ++digiRangeIterator) {
01222     const SiStripRawDigi *digi = &*digiRangeIterator;
01223 
01224     // store the digis from the laser beams. They are later on used to create
01225     // clusters and RecHits. In this way some sort of "Laser Tracks" can be
01226     // reconstructed, which are useable for Track Based Alignment      
01227     theDigiStore[theDetId].push_back((*digi));
01228     
01229     //    if ( theDebugLevel > 5 ) { 
01230     //      std::cout << " Channel " << digi->channel() << " has " << digi->adc() << " adc counts " << std::endl; 
01231     //    }
01232     
01233     // fill the number of adc counts in the histogram & array
01234     channel = distance( theFirstPosition, digiRangeIterator );
01235     if ( channel < 512 ) {
01236       Double_t theBinContent = theHistogram->GetBinContent( channel + 1 ) + digi->adc();
01237       theHistogram->SetBinContent( channel + 1, theBinContent );
01238       theProfile.SetValue( channel, digi->adc() );
01239     }
01240     
01241   }
01242 }
01243 
01244 
01245 
01246 
01247 
01251 std::vector<int> LaserAlignment::checkBeam(std::vector<std::string>::const_iterator iHistName, std::map<std::string, std::pair<DetId, TH1D*> >::iterator iHist ) {
01252 
01253   std::vector<int> result;
01254   std::string stringDisc;
01255   std::string stringRing;
01256   std::string stringBeam;
01257   bool isTEC2TEC = false;
01258   int theDisc = 0;
01259   int theRing = 0;
01260   int theBeam = 0;
01261   int theTECSide = 0;
01262   
01263   // check if we are in the Endcap
01264   switch (((iHist->second).first).subdetId())
01265     {
01266     case StripSubdetector::TIB:
01267       {
01268         break;
01269       }
01270     case StripSubdetector::TOB:
01271       {
01272         break;
01273       }
01274     case StripSubdetector::TEC:
01275       {
01276         TECDetId theTECDetId(((iHist->second).first).rawId());
01277         
01278         theTECSide = theTECDetId.side(); // 1 for TEC-, 2 for TEC+
01279         
01280         stringBeam = (*iHistName).at(4);
01281         stringRing = (*iHistName).at(9);
01282         stringDisc = (*iHistName).at(14);
01283         isTEC2TEC = ( (*iHistName).size() > 21 ) ? true : false;
01284         break;
01285       }
01286     }
01287 
01288   if ( stringRing == "4" ) { theRing = 4; }
01289   else if ( stringRing == "6" ) { theRing = 6; }
01290 
01291   if ( stringDisc == "1" ) { theDisc = 0; }
01292   else if ( stringDisc == "2" ) { theDisc = 1; }
01293   else if ( stringDisc == "3" ) { theDisc = 2; } 
01294   else if ( stringDisc == "4" ) { theDisc = 3; } 
01295   else if ( stringDisc == "5" ) { theDisc = 4; }
01296   else if ( stringDisc == "6" ) { theDisc = 5; } 
01297   else if ( stringDisc == "7" ) { theDisc = 6; } 
01298   else if ( stringDisc == "8" ) { theDisc = 7; } 
01299   else if ( stringDisc == "9" ) { theDisc = 8; } 
01300 
01301   if ( theRing == 4 )
01302     {
01303       if ( stringBeam == "0" ) { theBeam = 0; } 
01304       else if ( stringBeam == "1" ) { theBeam = 1; } 
01305       else if ( stringBeam == "2" ) { theBeam = 2; }
01306       else if ( stringBeam == "3" ) { theBeam = 3; } 
01307       else if ( stringBeam == "4" ) { theBeam = 4; }
01308       else if ( stringBeam == "5" ) { theBeam = 5; } 
01309       else if ( stringBeam == "6" ) { theBeam = 6; } 
01310       else if ( stringBeam == "7" ) { theBeam = 7; } 
01311     }
01312   else if ( theRing == 6 )
01313     {
01314       if ( stringBeam == "0" ) { theBeam = 0; } 
01315       else if ( stringBeam == "1" ) { theBeam = 1; } 
01316       else if ( stringBeam == "2" ) { theBeam = 2; }
01317       else if ( stringBeam == "3" ) { theBeam = 3; } 
01318       else if ( stringBeam == "4" ) { theBeam = 4; }
01319       else if ( stringBeam == "5" ) { theBeam = 5; } 
01320       else if ( stringBeam == "6" ) { theBeam = 6; } 
01321       else if ( stringBeam == "7" ) { theBeam = 7; } 
01322     }
01323   result.push_back(theTECSide);
01324   result.push_back(theRing);
01325   result.push_back(theBeam);
01326   result.push_back(theDisc);
01327   
01328   return result;
01329 }
01330 
01331 
01332 
01333 
01334 
01335 
01341 bool LaserAlignment::isTECBeam( void ) {
01342   
01343   int numberOfProfiles = 0;
01344 
01345   int ring = 1; // search all ring6 modules for signals
01346   for( int det = 0; det < 2; ++det ) {
01347     for( int beam = 0; beam < 8; ++ beam ) {
01348       for( int disk = 0; disk < 9; ++disk ) {
01349         if( isAcceptedProfile.GetTECEntry( det, ring, beam, disk ) == 1 ) numberOfProfiles++;
01350       }
01351     }
01352   }
01353 
01354   //  LogDebug( "[LaserAlignment::isTECBeam]" ) << " Found: " << numberOfProfiles << "hits." << std::endl;
01355   std::cout << " [LaserAlignment::isTECBeam] -- Found: " << numberOfProfiles << " hits." << std::endl; 
01356 
01357   if( numberOfProfiles > 10 ) return( true );
01358   return( false );
01359  
01360 }
01361 
01362 
01363 
01364 
01365 
01371 
01372 bool LaserAlignment::isATBeam( void ) {
01373 
01374   int numberOfProfiles = 0;
01375 
01376   int det = 2; int beam = 0; int pos = 0; // search all TIB/TOB for signals
01377   do {
01378     if( isAcceptedProfile.GetTIBTOBEntry( det, beam, pos ) == 1 ) numberOfProfiles++;
01379   } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
01380 
01381   //  LogDebug( "[LaserAlignment::isATBeam]" ) << " Found: " << numberOfProfiles << "hits." << std::endl;
01382   std::cout << " [LaserAlignment::isATBeam] -- Found: " << numberOfProfiles << " hits." << std::endl; 
01383 
01384   if( numberOfProfiles > 10 ) return( true );
01385   return( false );
01386     
01387 }
01388 
01389 
01390 
01391 
01392 
01397 int LaserAlignment::getTOBProfileOffset( int det, int beam, int pos ) {
01398 
01399   if( det < 0 || det > 3 || beam < 0 || beam > 7 || pos < 0 || pos > 5 ) {
01400     throw cms::Exception("LaserAlignment") << "[LaserAlignment::getTOBProfileOffset] ERROR ** Called with nonexisting par: det " << det << " beam " << beam << " pos " << pos << "." << std::endl;
01401   }
01402 
01403   // only for TOB
01404   if( det != 3 ) return 0;
01405 
01406   // some beams have no offset
01407   if( beam < 2 || beam == 7 ) return 0;
01408 
01409   // two groups of beams with offsets: 2-4 and 5-6
01410   else {
01411     if( beam < 5 ) {
01412       int offsets[] = { 117, -120, -120, 117, 117, -120 };
01413       return( offsets[pos] );
01414     }
01415     else {
01416       int offsets[] = { -120, 117, 117, -120, -120, 117 };
01417       return( offsets[pos] );
01418     }
01419   }
01420 
01421 }
01422 
01423 
01424 
01425 
01426 
01430 void LaserAlignment::CalculateNominalCoordinates( void ) {
01431 
01432   //
01433   // hard coded data
01434   //
01435 
01436   // nominal phi values of tec beam / alignment tube hits (parameter is beam 0-7)
01437   const double tecPhiPositions[8]   = { 0.3927, 1.1781, 1.9635, 2.7489, 3.5343, 4.3197, 5.1051, 5.8905 };
01438   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
01439 
01440   // nominal r values (mm) of hits
01441   const double tobRPosition = 600.;
01442   const double tibRPosition = 514.;
01443   const double tecRPosition[2] = { 564., 840. }; // ring 4,6
01444 
01445   // nominal z values (mm) of hits in barrel (parameter is pos 0-6)
01446   const double tobZPosition[6] = { 1040., 580., 220., -140., -500., -860. };
01447   const double tibZPosition[6] = { 620., 380., 180., -100., -340., -540. };
01448   // nominal z values (mm) of hits in tec (parameter is disk 0-8); FOR TEC-: (* -1.)
01449   const double tecZPosition[9] = { 1250., 1390., 1530., 1670., 1810., 1985., 2175., 2380., 2595. };
01450   
01451 
01452   //
01453   // now we fill these into the nominalCoordinates container;
01454   // errors are zero for nominal values..
01455   //
01456 
01457   // loop object and its variables
01458   LASGlobalLoop moduleLoop;
01459   int det, ring, beam, disk, pos;
01460 
01461   
01462   // TEC+- section
01463   det = 0; ring = 0, beam = 0; disk = 0;
01464   do {
01465     
01466     if( det == 0 ) { // this is TEC+
01467       nominalCoordinates.SetTECEntry( det, ring, beam, disk, LASCoordinateSet( tecPhiPositions[beam], 0., tecRPosition[ring], 0., tecZPosition[disk], 0. ) );
01468     }
01469     else { // now TEC-
01470       nominalCoordinates.SetTECEntry( det, ring, beam, disk, LASCoordinateSet( tecPhiPositions[beam], 0., tecRPosition[ring], 0., -1. * tecZPosition[disk], 0. ) ); // just * -1.
01471     }
01472     
01473   } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
01474 
01475 
01476 
01477   // TIB & TOB section
01478   det = 2; beam = 0; pos = 0;
01479   do {
01480     if( det == 2 ) { // this is TIB
01481       nominalCoordinates.SetTIBTOBEntry( det, beam, pos, LASCoordinateSet( atPhiPositions[beam], 0., tibRPosition, 0., tibZPosition[pos], 0. ) );
01482     }
01483     else { // now TOB
01484       nominalCoordinates.SetTIBTOBEntry( det, beam, pos, LASCoordinateSet( atPhiPositions[beam], 0., tobRPosition, 0., tobZPosition[pos], 0. ) );
01485     }
01486 
01487   } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
01488 
01489 
01490 
01491 
01492   // TEC2TEC AT section
01493   det = 0; beam = 0; disk = 0;
01494   do {
01495     
01496     if( det == 0 ) { // this is TEC+, ring4 only
01497       nominalCoordinates.SetTEC2TECEntry( det, beam, disk, LASCoordinateSet( atPhiPositions[beam], 0., tecRPosition[0], 0., tecZPosition[disk], 0. ) );
01498     }
01499     else { // now TEC-
01500       nominalCoordinates.SetTEC2TECEntry( det, beam, disk, LASCoordinateSet( atPhiPositions[beam], 0., tecRPosition[0], 0., -1. * tecZPosition[disk], 0. ) ); // just * -1.
01501     }
01502     
01503   } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
01504 
01505 
01506 }
01507 
01508 
01509 
01510 
01511 
01516 double LaserAlignment::ConvertAngle( double angle ) {
01517 
01518   if( angle < -1. * M_PI  || angle > M_PI ) {
01519     throw cms::Exception(" [LaserAlignment::ConvertAngle] ") << "** ERROR: Called with illegal input angle: " << angle << "." << std::endl;
01520   }
01521 
01522   if( angle >= 0. ) return angle;
01523   else return( angle + 2. * M_PI );
01524 
01525 }
01526 
01527 
01528 
01529 // define the SEAL module
01530 #include "FWCore/Framework/interface/MakerMacros.h"
01531 
01532 DEFINE_FWK_MODULE(LaserAlignment);

Generated on Tue Jun 9 17:24:04 2009 for CMSSW by  doxygen 1.5.4