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
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
00046 theAlignPosTEC( false ),
00047 theAlignNegTEC( false ),
00048 theAlignTEC2TEC( 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
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
00104 std::string alias ( theConf.getParameter<std::string>("@module_label") );
00105
00106
00107 produces<edm::DetSetVector<SiStripDigi> >().setBranchAlias( alias + "siStripDigis" );
00108 produces<LASBeamProfileFitCollection>().setBranchAlias( alias + "LASBeamProfileFits" );
00109 produces<LASAlignmentParameterCollection>().setBranchAlias( alias + "LASAlignmentParameters" );
00110
00111
00112
00113 theLASAlignPosTEC = new LaserAlignmentPosTEC;
00114 theLASAlignNegTEC = new LaserAlignmentNegTEC;
00115 theLASAlignTEC2TEC = new LaserAlignmentTEC2TEC;
00116
00117
00118 theAlignmentAlgorithmBW = new AlignmentAlgorithmBW;
00119
00120
00121
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
00167 theBeamFitter = new BeamProfileFitter( theBeamFitPS, &theSetup );
00168
00169
00170 theFile = new TFile(theFileName.c_str(),"RECREATE","CMS ROOT file");
00171 theFile->SetCompressionLevel(theCompression);
00172
00173
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
00185 fillDetectorId();
00186
00187
00188 theSetup.get<TrackerDigiGeometryRecord>().get( theTrackerGeometry );
00189 theSetup.get<IdealGeometryRecord>().get( gD );
00190
00191
00192 edm::ESHandle<SiStripPedestals> pedestalsHandle;
00193 if( theDoPedestalSubtraction ) {
00194 theSetup.get<SiStripPedestalsRcd>().get( pedestalsHandle );
00195 fillPedestalProfiles( pedestalsHandle );
00196 }
00197
00198
00199
00200
00201
00202
00203
00204
00205 std::stringstream nameBuilder;
00206
00207
00208 int det, ring, beam, disk, pos;
00209
00210
00211
00212
00213 det = 0; ring = 0; beam = 0; disk = 0;
00214 do {
00215
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
00221 isAcceptedProfile.SetTECEntry( det, ring, beam, disk, 0 );
00222
00223
00224
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;
00230 if( det == 0 ) nameBuilder << "Pos"; else nameBuilder << "Neg";
00231 nameBuilder << "TEC";
00232 theProfileNames.SetTECEntry( det, ring, beam, disk, nameBuilder.str() );
00233
00234
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
00243 det = 2; beam = 0; pos = 0;
00244 do {
00245
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
00251 isAcceptedProfile.SetTIBTOBEntry( det, beam, pos, 0 );
00252
00253
00254 nameBuilder.clear();
00255 nameBuilder.str( "" );
00256 nameBuilder << "Beam" << beam;
00257 if( det == 2 ) nameBuilder << "TIB"; else nameBuilder << "TOB";
00258 nameBuilder << "Position" << pos + 1;
00259 theProfileNames.SetTIBTOBEntry( det, beam, pos, nameBuilder.str() );
00260
00261
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
00270 det = 0; beam = 0; disk = 0;
00271 do {
00272
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
00278 isAcceptedProfile.SetTEC2TECEntry( det, beam, disk, 0 );
00279
00280
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
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
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
00320 trackerStatistics( theEvent, theSetup );
00321
00322
00323
00324
00325 int det, ring, beam, disk, pos;
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
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 {
00345 isAcceptedProfile.SetTECEntry( det, ring, beam, disk, 0 );
00346 }
00347 }
00348 }
00349 }
00350
00351
00352 det = 2; beam = 0; pos = 0;
00353 do {
00354
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 {
00359 isAcceptedProfile.SetTIBTOBEntry( det, beam, pos, 0 );
00360 }
00361
00362 } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
00363
00364
00365
00366
00367
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
00381
00382
00383
00384
00385
00386
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
00393
00394 if( ring == 0 && find( tecDoubleHitDetId.begin(), tecDoubleHitDetId.end(), detectorId.GetTECEntry( det, ring, beam, disk ) ) != tecDoubleHitDetId.end() ) {
00395
00396 if( isTECMode ) {
00397
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 {
00407
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
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
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
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
00443
00444 if( ring == 0 && find( tecDoubleHitDetId.begin(), tecDoubleHitDetId.end(), detectorId.GetTECEntry( det, ring, beam, disk ) ) != tecDoubleHitDetId.end() ) {
00445
00446 if( isATMode ) {
00447
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 {
00457
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
00469
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
00498 int det, ring, beam, disk, pos;
00499
00500 if( theUseNewAlgorithms ) {
00501
00504
00507
00508
00509
00510 LASGlobalData<LASCoordinateSet> measuredCoordinates;
00511
00512
00513 LASPeakFinder peakFinder;
00514 std::pair<double,double> peakFinderResults;
00515 bool isGoodFit;
00516
00517
00518 const TrackerGeometry& theTracker( *theTrackerGeometry );
00519
00520
00521 CalculateNominalCoordinates();
00522
00523
00524
00525
00526
00527 det = 0; ring = 0; beam = 0; disk = 0;
00528 do {
00529
00530
00531 isGoodFit = peakFinder.FindPeakIn( collectedDataProfiles.GetTECEntry( det, ring, beam, disk ), peakFinderResults, 0 );
00532
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
00537
00538
00539 const DetId theDetId( detectorId.GetTECEntry( det, ring, beam, disk ) );
00540 const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
00541
00542
00543 measuredCoordinates.SetTECEntry( det, ring, beam, disk, nominalCoordinates.GetTECEntry( det, ring, beam, disk ) );
00544
00545 if( isGoodFit ) {
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 );
00549
00550
00551 }
00552 else {
00553 measuredCoordinates.GetTECEntry( det, ring, beam, disk ).SetPhiError( 1000. );
00554 }
00555
00556 } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
00557
00558
00559
00560
00561
00562 det = 2; beam = 0; pos = 0;
00563 do {
00564
00565
00566 isGoodFit = peakFinder.FindPeakIn( collectedDataProfiles.GetTIBTOBEntry( det, beam, pos ), peakFinderResults, getTOBProfileOffset( det, beam, pos ) );
00567
00568 if( !isGoodFit ) std::cout << " [LaserAlignment::endJob] ** WARNING: Fit failed for TIB/TOB det: "
00569 << det << ", beam: " << beam << ", pos: " << pos << "." << std::endl;
00570
00571
00572
00573
00574 const DetId theDetId( detectorId.GetTIBTOBEntry( det, beam, pos ) );
00575 const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
00576
00577
00578 measuredCoordinates.SetTIBTOBEntry( det, beam, pos, nominalCoordinates.GetTIBTOBEntry( det, beam, pos ) );
00579
00580 if( isGoodFit ) {
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 );
00583 }
00584 else {
00585 measuredCoordinates.GetTIBTOBEntry( det, beam, pos ).SetPhiError( 1000. );
00586 }
00587
00588 } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
00589
00590
00591
00592
00593
00594 det = 0; beam = 0; disk = 0;
00595 do {
00596
00597
00598 isGoodFit = peakFinder.FindPeakIn( collectedDataProfiles.GetTEC2TECEntry( det, beam, disk ), peakFinderResults, 0 );
00599
00600 if( !isGoodFit ) std::cout << " [LaserAlignment::endJob] ** WARNING: Fit failed for TEC2TEC det: "
00601 << det << ", beam: " << beam << ", disk: " << disk << "." << std::endl;
00602
00603
00604
00605
00606 const DetId theDetId( detectorId.GetTEC2TECEntry( det, beam, pos ) );
00607 const StripGeomDetUnit* const theStripDet = dynamic_cast<const StripGeomDetUnit*>( theTracker.idToDet( theDetId ) );
00608
00609
00610 measuredCoordinates.SetTEC2TECEntry( det, beam, disk, nominalCoordinates.GetTEC2TECEntry( det, beam, disk ) );
00611
00612 if( isGoodFit ) {
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 );
00615 }
00616 else {
00617 measuredCoordinates.GetTEC2TECEntry( det, beam, disk ).SetPhiError( 1000. );
00618 }
00619
00620 } while( moduleLoop.TEC2TECLoop( det, beam, disk ) );
00621
00622
00623
00624
00625
00626 LASBarrelAlignmentParameterSet barrelParameters = barrelAlgorithm.CalculateParameters( measuredCoordinates, nominalCoordinates );
00627 LASEndcapAlignmentParameterSet endcapParameters = endcapAlgorithm.CalculateParameters( measuredCoordinates, nominalCoordinates );
00628
00629
00630 LASGeometryUpdater geometryUpdater;
00631 geometryUpdater.Update( endcapParameters, barrelParameters, *theAlignableTracker );
00632
00633
00634 }
00635
00636
00637
00638
00639
00640
00641
00642
00643 else if( !theUseNewAlgorithms ) {
00644
00647
00648
00651
00652
00653
00654
00655
00656
00657
00658 theDigiVector.reserve(10000);
00659 theDigiVector.clear();
00660
00661
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
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688 std::vector<LASBeamProfileFit> collector;
00689
00690
00691 det = 0; ring = 0; beam = 0; disk = 0;
00692 do {
00693
00694
00695
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
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
00705 int aRing, aBeam, aDet;
00706 if( ring == 0 ) {
00707 aRing = 4;
00708 aBeam = beam;
00709 }
00710 else {
00711 aRing = 6;
00712 aBeam = beam + 8;
00713 }
00714 if( det == 0 ) aDet = 2;
00715 else aDet = 1;
00716
00717
00718
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 , theIsGoodFit );
00725
00726
00727
00728
00729 if ( theIsGoodFit ) {
00730
00731 theBeamProfileFitStore[theProfileNames.GetTECEntry( det, ring, beam, disk )] = collector;
00732 }
00733
00734
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
00747 det = 2; beam = 0; pos = 0;
00748 do {
00749
00750
00751
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
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
00762 int aRing = 0, aBeam = 0, aDet = 0;
00763 disk = 0;
00764
00765
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 , theIsGoodFit );
00772
00773
00774
00775
00776 if ( theIsGoodFit ) {
00777
00778 theBeamProfileFitStore[theProfileNames.GetTIBTOBEntry( det, beam, pos )] = collector;
00779 }
00780
00781
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
00798 det = 0; ring = 0; beam = 0; disk = 0;
00799 do {
00800
00801
00802
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
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
00812 int aRing, aBeam, aDet;
00813 aRing = 4;
00814 aBeam = beam;
00815 if( det == 0 ) aDet = 2;
00816 else aDet = 1;
00817
00818
00819
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 , theIsGoodFit );
00826
00827
00828
00829
00830 if ( theIsGoodFit ) {
00831
00832 theBeamProfileFitStore[theProfileNames.GetTEC2TECEntry( det, beam, disk )] = collector;
00833 }
00834
00835
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
00851
00852
00853
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
00865 theDigiStore.clear();
00866
00867
00868
00869
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
00879
00880
00881 LASBeamProfileFitCollection::Range inputRange;
00882 inputRange.first = (iBeamFit->second).begin();
00883 inputRange.second = (iBeamFit->second).end();
00884
00885
00886
00887
00888
00889 LASBeamProfileFit theFit = (iBeamFit->second).at(0);
00890 theLaserPhi.push_back(theFit.phi());
00891 theLaserPhiError.push_back(thePhiErrorScalingFactor * theFit.phiError());
00892
00893
00894 std::vector<int> sectorLocation = checkBeam(iHistName, iHist);
00895
00896 if (sectorLocation.at(0) == 1)
00897 {
00898 if (sectorLocation.at(1) == 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)
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)
00910 {
00911 if (sectorLocation.at(1) == 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)
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
00923 }
00924 else
00925 {
00926
00927
00928
00929
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
00941
00942
00943 double thePosition = 0.0;
00944 double thePositionError = 0.05;
00945
00946
00947 std::vector<int> sectorLocation = checkBeam(iHistName, iHist);
00948
00949 if (sectorLocation.at(0) == 1)
00950 {
00951 if (sectorLocation.at(1) == 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)
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)
00963 {
00964 if (sectorLocation.at(1) == 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)
00970 {
00971 thePosTECR6BeamPositions[sectorLocation.at(2)][sectorLocation.at(3)] = thePosition;
00972 thePosTECR6BeamPositionErrors[sectorLocation.at(2)][sectorLocation.at(3)] = thePositionError;
00973 }
00974 }
00975
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
00985 theBeamProfileFitStore.clear();
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998 theNumberOfIterations = 0;
00999
01000
01001 if (theUseBrunosAlgorithm) {
01002
01003
01004 std::vector<LASAlignmentParameter> theAPPosTECR4;
01005 std::vector<LASAlignmentParameter> theAPPosTECR6;
01006 std::vector<LASAlignmentParameter> theAPNegTECR4;
01007 std::vector<LASAlignmentParameter> theAPNegTECR6;
01008
01009
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
01019
01020
01021
01022
01023 LASAlignmentParameterCollection::Range inputRangeT1R4;
01024 inputRangeT1R4.first = theAPPosTECR4.begin();
01025 inputRangeT1R4.second = theAPPosTECR4.end();
01026
01027
01028 LASAlignmentParameterCollection::Range inputRangeT1R6;
01029 inputRangeT1R6.first = theAPPosTECR6.begin();
01030 inputRangeT1R6.second = theAPPosTECR6.end();
01031
01032
01033 LASAlignmentParameterCollection::Range inputRangeT2R4;
01034 inputRangeT2R4.first = theAPNegTECR4.begin();
01035 inputRangeT2R4.second = theAPNegTECR4.end();
01036
01037
01038 LASAlignmentParameterCollection::Range inputRangeT2R6;
01039 inputRangeT2R6.first = theAPNegTECR6.begin();
01040 inputRangeT2R6.second = theAPNegTECR6.end();
01041
01042
01043
01044
01048 const align::Alignables& TECs = theAlignableTracker->endCaps();
01049
01050 const Alignable *TECplus = TECs[0], *TECminus = TECs[1];
01051
01052 if (TECplus->globalPosition().z() < 0)
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
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
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
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 }
01091
01092
01093
01094
01095
01096
01097
01098
01099 Alignments* alignments = theAlignableTracker->alignments();
01100 AlignmentErrors* alignmentErrors = theAlignableTracker->alignmentErrors();
01101
01102
01103 if ( theStoreToDB ) {
01104
01105 std::cout << " [LaserAlignment::endJob] -- Storing the calculated alignment parameters to the DataBase:" << std::endl;
01106
01107
01108 edm::Service<cond::service::PoolDBOutputService> poolDbService;
01109 if( !poolDbService.isAvailable() )
01110 throw cms::Exception("NotAvailable") << "PoolDBOutputService not available";
01111
01112
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
01134
01135
01136
01137
01138
01139
01140 std::auto_ptr<edm::DetSetVector<SiStripRawDigi> > theDigiOutput(new edm::DetSetVector<SiStripRawDigi>(theDigiVector));
01141
01142
01143
01144
01145
01146
01147
01148
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
01166 det = 0; ring = 0; beam = 0; disk = 0;
01167 do {
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
01178 det = 2; beam = 0; pos = 0;
01179 do {
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
01190 det = 0; beam = 0; disk = 0;
01191 do {
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
01217 int channel = 0;
01218 edm::DetSet<SiStripRawDigi>::const_iterator theFirstPosition = digiRangeIterator;
01219
01220
01221 for (; digiRangeIterator != digiRangeIteratorEnd; ++digiRangeIterator) {
01222 const SiStripRawDigi *digi = &*digiRangeIterator;
01223
01224
01225
01226
01227 theDigiStore[theDetId].push_back((*digi));
01228
01229
01230
01231
01232
01233
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
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();
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;
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
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;
01377 do {
01378 if( isAcceptedProfile.GetTIBTOBEntry( det, beam, pos ) == 1 ) numberOfProfiles++;
01379 } while( moduleLoop.TIBTOBLoop( det, beam, pos ) );
01380
01381
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
01404 if( det != 3 ) return 0;
01405
01406
01407 if( beam < 2 || beam == 7 ) return 0;
01408
01409
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
01434
01435
01436
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 };
01439
01440
01441 const double tobRPosition = 600.;
01442 const double tibRPosition = 514.;
01443 const double tecRPosition[2] = { 564., 840. };
01444
01445
01446 const double tobZPosition[6] = { 1040., 580., 220., -140., -500., -860. };
01447 const double tibZPosition[6] = { 620., 380., 180., -100., -340., -540. };
01448
01449 const double tecZPosition[9] = { 1250., 1390., 1530., 1670., 1810., 1985., 2175., 2380., 2595. };
01450
01451
01452
01453
01454
01455
01456
01457
01458 LASGlobalLoop moduleLoop;
01459 int det, ring, beam, disk, pos;
01460
01461
01462
01463 det = 0; ring = 0, beam = 0; disk = 0;
01464 do {
01465
01466 if( det == 0 ) {
01467 nominalCoordinates.SetTECEntry( det, ring, beam, disk, LASCoordinateSet( tecPhiPositions[beam], 0., tecRPosition[ring], 0., tecZPosition[disk], 0. ) );
01468 }
01469 else {
01470 nominalCoordinates.SetTECEntry( det, ring, beam, disk, LASCoordinateSet( tecPhiPositions[beam], 0., tecRPosition[ring], 0., -1. * tecZPosition[disk], 0. ) );
01471 }
01472
01473 } while( moduleLoop.TECLoop( det, ring, beam, disk ) );
01474
01475
01476
01477
01478 det = 2; beam = 0; pos = 0;
01479 do {
01480 if( det == 2 ) {
01481 nominalCoordinates.SetTIBTOBEntry( det, beam, pos, LASCoordinateSet( atPhiPositions[beam], 0., tibRPosition, 0., tibZPosition[pos], 0. ) );
01482 }
01483 else {
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
01493 det = 0; beam = 0; disk = 0;
01494 do {
01495
01496 if( det == 0 ) {
01497 nominalCoordinates.SetTEC2TECEntry( det, beam, disk, LASCoordinateSet( atPhiPositions[beam], 0., tecRPosition[0], 0., tecZPosition[disk], 0. ) );
01498 }
01499 else {
01500 nominalCoordinates.SetTEC2TECEntry( det, beam, disk, LASCoordinateSet( atPhiPositions[beam], 0., tecRPosition[0], 0., -1. * tecZPosition[disk], 0. ) );
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
01530 #include "FWCore/Framework/interface/MakerMacros.h"
01531
01532 DEFINE_FWK_MODULE(LaserAlignment);