CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/CalibMuon/DTCalibration/src/DTTMax.cc

Go to the documentation of this file.
00001 /*
00002  *  See header file for a description of this class.
00003  *
00004  *  $Date: 2009/05/13 13:25:04 $
00005  *  $Revision: 1.8 $
00006  *  \author Marina Giunta
00007  */
00008 
00009 #include "CalibMuon/DTCalibration/interface/DTTMax.h"
00010 #include "Geometry/DTGeometry/interface/DTLayer.h"
00011 #include "Geometry/DTGeometry/interface/DTSuperLayer.h"
00012 #include "CalibMuon/DTDigiSync/interface/DTTTrigBaseSync.h"
00013 // Declare histograms for debugging purposes
00014 #include "CalibMuon/DTCalibration/interface/Histogram.h"
00015 
00016 #include <map>
00017 #include <iostream>
00018 
00019 using namespace std;
00020 using namespace dttmaxenums;
00021 using namespace DTEnums;
00022 
00023 DTTMax::InfoLayer::InfoLayer(DTRecHit1D rh_, const DTSuperLayer & isl, GlobalVector dir,
00024                              GlobalPoint pos, DTTTrigBaseSync* sync):
00025   rh(rh_), idWire(rh.wireId()), lr(rh.lrSide()) {
00026     const DTLayer*  layer = isl.layer(idWire.layerId());
00027     LocalPoint wirePosInLayer(layer->specificTopology().wirePosition(idWire.wire()), 0, 0);
00028     LocalPoint wirePosInSL=isl.toLocal(layer->toGlobal(wirePosInLayer));
00029     wireX = wirePosInSL.x();
00030     
00031     //-- Correction for signal propagation along wire, t0 subtraction,
00032     LocalVector segDir =  layer->toLocal(dir);
00033     LocalPoint segPos = layer->toLocal(pos);
00034     LocalPoint segPosAtLayer = segPos + segDir*(-segPos.z())/cos(segDir.theta());
00035     LocalPoint hitPos(rh.localPosition().x() ,segPosAtLayer.y(),0.);
00036     time = rh.digiTime() - sync->offset(layer, idWire, layer->toGlobal(hitPos));
00037  
00038     if (time < 0. || time > 415.) {
00039       // FIXME introduce time window to reject "out-of-time" digis
00040       cout << " *** WARNING time = " << time << endl;
00041     }
00042   }
00043 
00044 
00045 DTTMax::DTTMax(const vector<DTRecHit1D>& hits, const DTSuperLayer & isl, GlobalVector dir, 
00046                GlobalPoint pos, DTTTrigBaseSync* sync):
00047   theInfoLayers(4,(InfoLayer*)0), //FIXME
00048   theTMaxes(4,(TMax*)0) 
00049 {
00050   // debug parameter for verbose output
00051   debug = "true";
00052 
00053   // Collect all information using InfoLayer
00054   for (vector<DTRecHit1D>::const_iterator hit=hits.begin(); hit!=hits.end();
00055        ++hit) {
00056     //     cout << "Hit Pos " << (*hit).localPosition() << endl;
00057     
00058     InfoLayer* layInfo = new InfoLayer((*hit), isl, dir, pos, sync);
00059     int ilay = layInfo->idWire.layer();
00060     if (getInfoLayer(ilay)==0) {
00061       getInfoLayer(ilay) = layInfo;
00062     } else {
00063       // FIXME: in case there is > 1 hit/layer, the first is taken and the others are IGNORED.
00064       delete layInfo;
00065     }
00066   }
00067 
00068   // Get the segment direction
00069   theSegDir = ((isl.toLocal(dir).x() < 0)? L : R);
00070 
00071   int layersIn = 0; 
00072   int nGoodHits=0;
00073   for(vector<InfoLayer*>::const_iterator ilay =  theInfoLayers.begin();
00074       ilay != theInfoLayers.end(); ilay++) {
00075     if ((*ilay) == 0 ) {
00076       theSegType+= "X";
00077       continue;
00078     }
00079     DTEnums::DTCellSide lOrR =(*ilay)->lr;
00080     if(lOrR == Left) theSegType+= "L";
00081     else if (lOrR == Right) theSegType+="R"; 
00082     else theSegType+= "X";
00083     
00084     // layersIn : 6 =  layers 1,2,3
00085     //            7 =         1,2,4
00086     //            8 =         1,3,4
00087     //            9 =         2,3,4
00088     //            10=         1,2,3,4  
00089     layersIn += (*ilay)->idWire.layer();
00090     nGoodHits++;
00091   }
00092 
00093   if(nGoodHits >=3 && (theSegType != "RRRR" && theSegType != "LLLL")) {
00094     float t1 = 0.;
00095     float t2 = 0.;
00096     float t3 = 0.;
00097     float t4 = 0.;
00098     float x1 = 0.;
00099     float x2 = 0.;
00100     float x3 = 0.;
00101     float x4 = 0.;
00102 
00103     if(layersIn <= 8  || layersIn == 10) {
00104       t1 = getInfoLayer(1)->time;       
00105       x1 = getInfoLayer(1)->wireX;      
00106     }
00107     if(layersIn <= 7  || layersIn >= 9) {
00108       t2 = getInfoLayer(2)->time; 
00109       x2 = getInfoLayer(2)->wireX;            
00110     }
00111     if(layersIn == 6  || layersIn >= 8) {
00112       t3 = getInfoLayer(3)->time; 
00113       x3 = getInfoLayer(3)->wireX;            
00114     }
00115     if( layersIn >= 7) {
00116       t4 = getInfoLayer(4)->time;
00117       x4 = getInfoLayer(4)->wireX;
00118     }
00119     
00120     float t = 0.;
00121     TMaxCells cGroup = notInit;
00122     string type;
00123     SigmaFactor sigma = noR; // Return the factor relating the width of the TMax distribution and the cell resolution
00124     float halfCell = 2.1;    // 2.1 is the half cell length in cm
00125     float delta = 0.5;       // (diff. wire pos.) < delta, halfCell+delta, .....
00126     unsigned t0Factor = 99;  // "quantity" of Delta(t0) included in the tmax formula
00127 
00128     //Debug
00129     if (debug) {
00130       cout << "seg. type: " << theSegType << " and dir: " << theSegDir << endl;
00131       cout << "t1, t2, t3, t4: " << t1 << " " << t2 << " " << t3 << " " << t4 << endl;
00132       cout << "x1, x2, x3, x4: " << x1 << " " << x2 << " " << x3 << " " << x4 << endl;
00133     }
00134     
00135     //different t0 hists (if you have at least one hit within a certain distance from the wire)
00136     unsigned hSubGroup = 99; //
00137     if(t1 == 0. || t2 == 0. || t3 == 0. || t4 == 0.)
00138       hSubGroup = 0; //if only 3 hits
00139     else if(t1<=5. || t2<=5. || t3<=5. || t4<=5.)
00140       hSubGroup = 1; //if distance of one hit from wire < 275um (v_drift=55um/ns) 
00141     else if(t1<=10. || t2<=10. || t3<=10. || t4<=10.)
00142       hSubGroup = 2;
00143     else if(t1<=20. || t2<=20. || t3<=20. || t4<=20.)
00144       hSubGroup = 3;
00145     else if(t1<=50. || t2<=50. || t3<=50. || t4<=50.)
00146       hSubGroup = 4;
00147 
00148     if((layersIn == 6 || layersIn == 10) && (fabs(x1-x3)<delta)) {
00149       cGroup = c123;
00150       ((type+=theSegType[0])+=theSegType[1])+=theSegType[2];
00151       sigma = r32;
00152       if(type == "LRL" || type == "RLR") {
00153         t0Factor = 2;
00154         t = (t1+t3)/2.+t2;
00155         hT123LRL->Fill(t);
00156       }
00157       else if((type == "LLR" && theSegDir == R) ||
00158               (type == "RRL" && theSegDir == L)) {
00159         t0Factor = 1;
00160         t = (t3-t1)/2.+t2;
00161         hT123LLR->Fill(t);
00162       }
00163       else if((type == "LRR" && theSegDir == R) ||
00164               (type == "RLL" && theSegDir == L)) {
00165         t0Factor = 1;
00166         t = (t1-t3)/2.+t2;
00167         hT123LRR->Fill(t);
00168       }
00169       else {
00170         t = -1.;
00171         sigma = noR;
00172         hT123Bad->Fill(t);
00173       }
00174       theTMaxes[cGroup] = new TMax(t,cGroup,type,sigma,t0Factor,hSubGroup);
00175       if(debug) cout << "tmax123 " << t << " " << type << endl;
00176     }
00177     if(layersIn == 7 || layersIn == 10) {
00178       cGroup = c124;
00179       type.clear();
00180       sigma = r72;
00181       ((type+=theSegType[0])+=theSegType[1])+=theSegType[3];
00182       if((theSegType == "LRLR" && type == "LRR" && x1 > x4) ||
00183          (theSegType == "RLRL" && type == "RLL" && x1 < x4)) {
00184         t0Factor = 2;
00185         t = 1.5*t2+t1-t4/2.;
00186         hT124LRR1gt4->Fill(t);
00187       }
00188       else if((type == "LLR" && theSegDir == R && (fabs(x2-x4)<delta) && x1 < x2) ||
00189               (type == "RRL" && theSegDir == L && (fabs(x2-x4)<delta) && x1 > x2)) {
00190         t0Factor = 1;
00191         t = 1.5*t2-t1+t4/2.;
00192         hT124LLR->Fill(t);
00193       }
00194       else if((type == "LLL" && theSegDir == R && (fabs(x2-x4)<delta) && x1 < x2) ||
00195               (type == "RRR" && theSegDir == L && (fabs(x2-x4)<delta) && x1 > x2)) {
00196         t0Factor = 0;
00197         t = 1.5*t2-t1-t4/2.;
00198         hT124LLLR->Fill(t);
00199       }
00200       else if((type == "LLL" && theSegDir == L && (fabs(x2-x4)<delta)) ||
00201               (type == "RRR" && theSegDir == R && (fabs(x2-x4)<delta))) {
00202         t0Factor = 0;
00203         t = -1.5*t2+t1+t4/2.;
00204         hT124LLLL->Fill(t);
00205       } 
00206       else if((type == "LRL" && theSegDir == L && (fabs(x2-x4)<delta)) ||
00207               (type == "RLR" && theSegDir == R && (fabs(x2-x4)<delta))) {
00208         t0Factor = 3;
00209         t = 1.5*t2+t1+t4/2.;
00210         hT124LRLL->Fill(t);
00211       }
00212       else if((type == "LRL" && theSegDir == R && (fabs(x1-x4)<(halfCell+delta))) ||
00213               (type == "RLR" && theSegDir == L && (fabs(x1-x4)<(halfCell+delta)))) {
00214         t0Factor = 99;  // it's actually 1.5, but this value it's not used  
00215         t = 3./4.*t2+t1/2.+t4/4.;
00216         sigma = r78;
00217         hT124LRLR->Fill(t);
00218       }
00219       else if((type == "LRR" && theSegDir == R && x1 < x4 && (fabs(x1-x4)<(halfCell+delta)))||
00220                (type == "RLL" && theSegDir == L && x1 > x4 && (fabs(x1-x4)<(halfCell+delta)))) {
00221         t0Factor = 1;
00222         t = 3./4.*t2+t1/2.-t4/4.;
00223         sigma = r78;
00224         hT124LRR1lt4->Fill(t);
00225       }
00226       else {
00227         t = -1.; 
00228         sigma = noR;
00229         hT124Bad->Fill(t);
00230       }
00231       theTMaxes[cGroup] = new TMax(t,cGroup,type,sigma,t0Factor,hSubGroup);
00232       if(debug) cout << "tmax124 " << t << " " << t0Factor << " "  << type << endl;
00233     }
00234     if(layersIn == 8 || layersIn == 10) {
00235       cGroup = c134;
00236       type.clear();
00237       ((type+=theSegType[0])+=theSegType[2])+=theSegType[3];
00238       sigma = r72;
00239       if((type == "LLR" && x1 > x4 && theSegType == "LRLR") ||
00240          (type == "RRL" && x1 < x4 && theSegType == "RLRL")) {
00241         t0Factor = 2;
00242         t = 1.5*t3+t4-t1/2.;
00243         hT134LLR1gt4->Fill(t);
00244       }
00245       else if((type == "LLR"  && x1 < x4 && (fabs(x1-x4)<(halfCell+delta))) ||
00246                (type == "RRL"  && x1 > x4 && (fabs(x1-x4)<(halfCell+delta)))) {
00247         t0Factor = 1;
00248         t = 3./4.*t3+t4/2.-t1/4.; 
00249         sigma = r78;
00250         hT134LLR1lt4->Fill(t);
00251       }
00252       else if((type == "LRR"  && theSegDir == R && x1 < x4 && (fabs(x1-x3)<delta)) ||
00253                (type == "RLL"  && theSegDir == L && x1 > x4 &&(fabs(x1-x3)<delta))) {
00254         t0Factor = 1;
00255         t = 1.5*t3-t4+t1/2.;
00256         hT134LRR->Fill(t);
00257       }
00258       else if((type == "LRL"  && theSegDir == R && (fabs(x1-x3)<delta)) ||
00259               (type == "RLR"  && theSegDir == L && (fabs(x1-x3)<delta))) {
00260         t0Factor = 3;
00261         t = 1.5*t3+t4+t1/2.;
00262         hT134LRLR->Fill(t);
00263       }
00264       else if((type == "LRL"  && theSegDir == L && (fabs(x1-x3)<(2.*halfCell+delta))) ||
00265               (type == "RLR"  && theSegDir == R && (fabs(x1-x3)<(2.*halfCell+delta)))) {
00266         t0Factor = 99; // it's actually 1.5, but this value it's not used  
00267         t = 3./4.*t3+t4/2.+t1/4.;
00268         sigma = r78;
00269         hT134LRLL->Fill(t);
00270       }
00271       else if((type == "LLL"  && theSegDir == L && x1 > x4 && (fabs(x1-x3)<delta)) ||
00272               (type == "RRR"  && theSegDir == R && x1 < x4 && (fabs(x1-x3)<delta))) {
00273         t0Factor = 0;
00274         t = 1.5*t3-t4-t1/2.;
00275         hT134LLLL->Fill(t);     
00276       }
00277       else if((type == "LLL"  && theSegDir == R && (fabs(x1-x3)<delta)) ||
00278               (type == "RRR"  && theSegDir == L && (fabs(x1-x3)<delta))) {
00279         t0Factor = 0;
00280         t = -1.5*t3+t4+t1/2.;
00281         hT134LLLR->Fill(t);
00282       }
00283       else {
00284         t = -1;
00285         sigma = noR;
00286         hT134Bad->Fill(t);
00287       }
00288       theTMaxes[cGroup] = new TMax(t,cGroup,type,sigma,t0Factor,hSubGroup);
00289       if(debug) cout << "tmax134 " << t << " " << t0Factor << " "  << type << endl;
00290     }
00291     if((layersIn == 9 || layersIn == 10) && (fabs(x2-x4)<delta)) {
00292       cGroup = c234;
00293       type.clear();
00294       ((type+=theSegType[1])+=theSegType[2])+=theSegType[3];
00295       sigma = r32;
00296       if((type == "LRL" ) ||
00297          (type == "RLR" )) {
00298         t0Factor = 2;
00299         t = (t2+t4)/2.+t3;
00300         hT234LRL->Fill(t);
00301       }
00302       else if((type == "LRR" && theSegDir == R) ||
00303               (type == "RLL" && theSegDir == L)) {
00304         t0Factor = 1;
00305         t = (t2-t4)/2.+t3;
00306         hT234LRR->Fill(t);
00307       }
00308       else if((type == "LLR" && theSegDir == R) ||
00309               (type == "RRL" && theSegDir == L)) {
00310         t0Factor = 1;
00311         t = (t4-t2)/2.+t3;
00312         hT234LLR->Fill(t);
00313       }
00314       else {
00315         t = -1;
00316         sigma = noR;
00317         hT234Bad->Fill(t);
00318       }
00319       theTMaxes[cGroup] = new TMax(t,cGroup,type,sigma,t0Factor,hSubGroup);
00320       if(debug) cout << "tmax234 " << t << " " << type << endl;
00321     }
00322   }      
00323   
00324 }
00325 
00326 
00327 vector<const DTTMax::TMax*> DTTMax::getTMax(const DTWireId & idWire) {
00328   vector<const TMax*> v;
00329   if(idWire.layer()==1) {
00330     v.push_back(getTMax(c123)); //FIXME: needs pointer
00331     v.push_back(getTMax(c124));
00332     v.push_back(getTMax(c134));
00333   }
00334   else if(idWire.layer()==2) {
00335     v.push_back(getTMax(c123));
00336     v.push_back(getTMax(c124));
00337     v.push_back(getTMax(c234));
00338   }
00339   else if(idWire.layer()==3) {
00340     v.push_back(getTMax(c123));
00341     v.push_back(getTMax(c134));
00342     v.push_back(getTMax(c234));
00343   }
00344   else {
00345     v.push_back(getTMax(c124));
00346     v.push_back(getTMax(c134));
00347     v.push_back(getTMax(c234));
00348   }
00349   return v;
00350 }
00351 
00352 
00353 
00354 vector<const DTTMax::TMax*> DTTMax::getTMax(const DTSuperLayerId & isl) {
00355   vector<const TMax*> v;
00356   // add TMax* to the vector only if it really exists 
00357   if(getTMax(c123)) v.push_back(getTMax(c123)); 
00358   if(getTMax(c124)) v.push_back(getTMax(c124));
00359   if(getTMax(c134)) v.push_back(getTMax(c134));
00360   if(getTMax(c234)) v.push_back(getTMax(c234));  
00361   return v;
00362 }
00363 
00364 
00365 const DTTMax::TMax* DTTMax::getTMax(TMaxCells cCase){
00366   return theTMaxes[cCase];
00367 }
00368 
00369 /* Destructor */ 
00370 DTTMax::~DTTMax(){
00371   for (vector<InfoLayer*>::const_iterator ilay = theInfoLayers.begin();
00372        ilay != theInfoLayers.end(); ilay++) {
00373     delete (*ilay);
00374   }
00375 
00376   for (vector<TMax*>::const_iterator iTmax = theTMaxes.begin();
00377        iTmax != theTMaxes.end(); iTmax++) {
00378     delete (*iTmax);
00379   }
00380 }