CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/RecoParticleFlow/PFTracking/src/PFTrackTransformer.cc

Go to the documentation of this file.
00001 //
00002 // -*- C++ -*-
00003 // Package:    PFTracking
00004 // Class:      PFTrackTransformer
00005 // 
00006 // Original Author:  Michele Pioppi
00007 // Other Author: Daniele Benedetti
00008 
00009 #include "RecoParticleFlow/PFTracking/interface/PFTrackTransformer.h"
00010 
00011 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00012 #include "FWCore/Framework/interface/ESHandle.h"
00013 
00014 #include "DataFormats/ParticleFlowReco/interface/PFCluster.h"
00015 #include "DataFormats/ParticleFlowReco/interface/PFRecTrackFwd.h"
00016 #include "DataFormats/TrackReco/interface/Track.h"
00017 
00018 #include "TrackingTools/PatternTools/interface/Trajectory.h"
00019 #include "FastSimulation/BaseParticlePropagator/interface/BaseParticlePropagator.h"
00020 
00021 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00022 // Add by Daniele
00023 #include "TrackingTools/GsfTools/interface/MultiGaussianStateTransform.h"
00024 #include "TrackingTools/GsfTools/interface/MultiGaussianState1D.h"
00025 #include "TrackingTools/GsfTools/interface/GaussianSumUtilities1D.h"
00026 #include "RecoParticleFlow/PFTracking/interface/PFGsfHelper.h"
00027 
00028 using namespace std;
00029 using namespace reco;
00030 using namespace edm;
00031 
00032 
00033 
00034 PFTrackTransformer::PFTrackTransformer(math::XYZVector B):B_(B){
00035   LogInfo("PFTrackTransformer")<<"PFTrackTransformer built";
00036 
00037   PFGeometry pfGeometry;
00038   onlyprop_=false;
00039 }
00040 
00041 PFTrackTransformer::~PFTrackTransformer(){
00042   
00043 }
00044 
00045 
00046 bool 
00047 PFTrackTransformer::addPoints( reco::PFRecTrack& pftrack, 
00048                                const reco::Track& track,
00049                                const Trajectory& traj) const {
00050   
00051   LogDebug("PFTrackTransformer")<<"Trajectory propagation started";
00052   using namespace reco;
00053   using namespace std;
00054 
00055   float PT= track.pt();
00056   float pfmass= (pftrack.algoType()==reco::PFRecTrack::KF_ELCAND) ? 0.0005 : 0.139; 
00057   float pfenergy=sqrt((pfmass*pfmass)+(track.p()*track.p()));
00058    // closest approach
00059   BaseParticlePropagator theParticle = 
00060     BaseParticlePropagator( 
00061                            RawParticle(XYZTLorentzVector(track.px(),
00062                                                          track.py(),
00063                                                          track.pz(),
00064                                                          pfenergy),
00065                                        XYZTLorentzVector(track.vertex().x(),
00066                                                          track.vertex().y(),
00067                                                          track.vertex().z(),
00068                                                          0.)),
00069                            0.,0.,B_.z());
00070 
00071   theParticle.setCharge(track.charge());
00072   float pfoutenergy=sqrt((pfmass*pfmass)+track.outerMomentum().Mag2());
00073   BaseParticlePropagator theOutParticle = 
00074     BaseParticlePropagator( 
00075                            RawParticle(XYZTLorentzVector(track.outerMomentum().x(),
00076                                                          track.outerMomentum().y(),
00077                                                          track.outerMomentum().z(),
00078                                                          pfoutenergy),
00079                                        XYZTLorentzVector(track.outerPosition().x(),
00080                                                          track.outerPosition().y(),
00081                                                          track.outerPosition().z(),
00082                                                          0.)),
00083                            0.,0.,B_.z());
00084   theOutParticle.setCharge(track.charge());
00085   
00086   
00087   math::XYZTLorentzVector momClosest 
00088     = math::XYZTLorentzVector(track.px(), track.py(), 
00089                               track.pz(), track.p());
00090   math::XYZPoint posClosest = track.vertex();
00091   
00092   pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ClosestApproach,
00093                                      posClosest,momClosest));
00094   
00095   
00096   //BEAMPIPE
00097   theParticle.setPropagationConditions(PFGeometry::outerRadius(PFGeometry::BeamPipe), 
00098                                        PFGeometry::outerZ(PFGeometry::BeamPipe), false);
00099   theParticle.propagate();
00100   if(theParticle.getSuccess()!=0)
00101     pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::BeamPipeOrEndVertex,
00102                                        math::XYZPoint(theParticle.vertex()),
00103                                        math::XYZTLorentzVector(theParticle.momentum())));
00104   else {
00105     PFTrajectoryPoint dummyMaxSh;
00106     pftrack.addPoint(dummyMaxSh); 
00107   }
00108   
00109 
00110 
00111   //trajectory points
00112 
00113   if (!onlyprop_){
00114     bool direction =(traj.direction() == alongMomentum);
00115     vector<TrajectoryMeasurement> measurements =traj.measurements();
00116     int iTrajFirst = (direction) ? 0 :  measurements.size() - 1;
00117     int increment = (direction) ? +1 : -1;
00118     int iTrajLast  =  (direction) ? int(measurements.size()) : -1;
00119     
00120 
00121     for (int iTraj = iTrajFirst; iTraj != iTrajLast; iTraj += increment) {
00122       GlobalPoint v=measurements[iTraj].updatedState().globalPosition();
00123       GlobalVector p=measurements[iTraj].updatedState().globalMomentum();
00124       unsigned int iid=measurements[iTraj].recHit()->det()->geographicalId().rawId();
00125       pftrack.addPoint(PFTrajectoryPoint(iid,-1,
00126                                          math::XYZPoint(v.x(), v.y(), v.z()),
00127                                          math::XYZTLorentzVector(p.x(),p.y(),p.z(),p.mag())));
00128     }
00129   }
00130 
00131   bool isBelowPS=false; 
00132    theOutParticle.propagateToPreshowerLayer1(false);
00133    if(theOutParticle.getSuccess()!=0)
00134      pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS1,
00135                                         math::XYZPoint(theOutParticle.vertex()),
00136                                         math::XYZTLorentzVector(theOutParticle.momentum())));
00137    else {
00138      PFTrajectoryPoint dummyPS1;
00139      pftrack.addPoint(dummyPS1); 
00140    }
00141    
00142 
00143    theOutParticle.propagateToPreshowerLayer2(false);
00144    if(theOutParticle.getSuccess()!=0){
00145      pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS2,
00146                                         math::XYZPoint(theOutParticle.vertex()),
00147                                         math::XYZTLorentzVector(theOutParticle.momentum())));
00148      isBelowPS=true;
00149    }   else {
00150      PFTrajectoryPoint dummyPS2;
00151      pftrack.addPoint(dummyPS2); 
00152    }
00153 
00154    theOutParticle.propagateToEcalEntrance(false);
00155 
00156    if(theOutParticle.getSuccess()!=0){
00157      pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALEntrance,
00158                                         math::XYZPoint(theOutParticle.vertex()),
00159                                         math::XYZTLorentzVector(theOutParticle.momentum())));
00160    double ecalShowerDepth     
00161      = PFCluster::getDepthCorrection(theOutParticle.momentum().E(),
00162                                      isBelowPS, 
00163                                      false);
00164 
00165    math::XYZPoint meanShower=math::XYZPoint(theOutParticle.vertex())+
00166      math::XYZTLorentzVector(theOutParticle.momentum()).Vect().Unit()*ecalShowerDepth;
00167  
00168    pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALShowerMax,
00169                                       meanShower,
00170                                       math::XYZTLorentzVector(theOutParticle.momentum())));}
00171    else {
00172      if (PT>5.)
00173        LogWarning("PFTrackTransformer")<<"KF TRACK "<<pftrack<< " PROPAGATION TO THE ECAL HAS FAILED";
00174      PFTrajectoryPoint dummyECAL;
00175      pftrack.addPoint(dummyECAL); 
00176      PFTrajectoryPoint dummyMaxSh;
00177      pftrack.addPoint(dummyMaxSh); 
00178    }
00179 
00180 
00181  
00182    //HCAL entrance
00183    theOutParticle.propagateToHcalEntrance(false);
00184    if(theOutParticle.getSuccess()!=0)
00185      pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALEntrance,
00186                                         math::XYZPoint(theOutParticle.vertex()),
00187                                         math::XYZTLorentzVector(theOutParticle.momentum())));
00188    else{
00189      if (PT>5.)
00190        LogWarning("PFTrackTransformer")<<"KF TRACK "<<pftrack<< " PROPAGATION TO THE HCAL ENTRANCE HAS FAILED";
00191      PFTrajectoryPoint dummyHCALentrance;
00192      pftrack.addPoint(dummyHCALentrance); 
00193    }
00194 
00195    //HCAL exit
00196    theOutParticle.propagateToHcalExit(false);
00197    if(theOutParticle.getSuccess()!=0)
00198      pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALExit,
00199                                         math::XYZPoint(theOutParticle.vertex()),
00200                                         math::XYZTLorentzVector(theOutParticle.momentum())));
00201    else{
00202      if (PT>5.)
00203        LogWarning("PFTrackTransformer")<<"KF TRACK "<<pftrack<< " PROPAGATION TO THE HCAL EXIT HAS FAILED";
00204      PFTrajectoryPoint dummyHCALexit;
00205      pftrack.addPoint(dummyHCALexit); 
00206    }
00207    
00208    return true;
00209 }
00210 bool 
00211 PFTrackTransformer::addPointsAndBrems( reco::GsfPFRecTrack& pftrack, 
00212                                        const reco::Track& track,
00213                                        const Trajectory& traj,
00214                                        const bool& GetMode) const {
00215 
00216   float PT= track.pt();
00217   // Trajectory for each trajectory point
00218 
00219   bool direction =(traj.direction() == alongMomentum);
00220   vector<TrajectoryMeasurement> measurements =traj.measurements();
00221   int iTrajFirst = (direction) ? 0 :  measurements.size() - 1;
00222   int increment = (direction) ? +1 : -1;
00223   int iTrajLast  =  (direction) ? int(measurements.size()) : -1;
00224   
00225   
00226   unsigned int iTrajPos = 0;
00227   for (int iTraj = iTrajFirst; iTraj != iTrajLast; iTraj += increment) {
00228     
00229     GlobalPoint v=measurements[iTraj].updatedState().globalPosition();
00230     PFGsfHelper* PFGsf = new PFGsfHelper(measurements[iTraj]);
00231     //if (PFGsf->isValid()){ 
00232     bool ComputeMODE = GetMode;
00233     GlobalVector p = PFGsf->computeP(ComputeMODE);
00234     double DP = PFGsf->fittedDP();
00235     double SigmaDP =  PFGsf->sigmafittedDP();   
00236     unsigned int iid=measurements[iTraj].recHit()->det()->geographicalId().rawId();
00237     delete PFGsf;
00238 
00239     // --------------------------   Fill GSF Track ------------------------------------- 
00240     
00241 
00242     //    float pfmass= (pftrack.algoType()==reco::PFRecTrack::KF_ELCAND) ? 0.0005 : 0.139; 
00243     float ptot =  sqrt((p.x()*p.x())+(p.y()*p.y())+(p.z()*p.z()));
00244     float pfenergy= ptot;
00245 
00246     if (iTraj == iTrajFirst) {
00247 
00248       math::XYZTLorentzVector momClosest 
00249         = math::XYZTLorentzVector(p.x(), p.y(), 
00250                                   p.z(), ptot);
00251       math::XYZPoint posClosest = track.vertex();
00252       pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ClosestApproach,
00253                                          posClosest,momClosest));
00254       
00255       BaseParticlePropagator theInnerParticle = 
00256         BaseParticlePropagator( 
00257                                RawParticle(XYZTLorentzVector(p.x(),
00258                                                              p.y(),
00259                                                              p.z(),
00260                                                              pfenergy),
00261                                            XYZTLorentzVector(track.vertex().x(),
00262                                                              track.vertex().y(),
00263                                                              track.vertex().z(),
00264                                                              0.)),  //DANIELE Same thing v.x(),v.y(),v.()? 
00265                                0.,0.,B_.z());
00266       theInnerParticle.setCharge(track.charge());  
00267 
00268       //BEAMPIPE
00269       theInnerParticle.setPropagationConditions(PFGeometry::outerRadius(PFGeometry::BeamPipe), 
00270                                            PFGeometry::outerZ(PFGeometry::BeamPipe), false);
00271       theInnerParticle.propagate();
00272       if(theInnerParticle.getSuccess()!=0)
00273         pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::BeamPipeOrEndVertex,
00274                                            math::XYZPoint(theInnerParticle.vertex()),
00275                                            math::XYZTLorentzVector(theInnerParticle.momentum())));
00276       else {
00277         PFTrajectoryPoint dummyMaxSh;
00278         pftrack.addPoint(dummyMaxSh); 
00279       }
00280       
00281       // First Point for the trajectory == Vertex ?? 
00282       pftrack.addPoint(PFTrajectoryPoint(iid,-1,
00283                                          math::XYZPoint(v.x(), v.y(), v.z()),
00284                                          math::XYZTLorentzVector(p.x(),p.y(),p.z(),p.mag())));
00285       
00286      
00287     }
00288     if (iTraj != iTrajFirst && iTraj != (abs(iTrajLast)-1)) {
00289       pftrack.addPoint(PFTrajectoryPoint(iid,-1,
00290                                          math::XYZPoint(v.x(), v.y(), v.z()),
00291                                          math::XYZTLorentzVector(p.x(),p.y(),p.z(),p.mag())));
00292       
00293  
00294     }
00295     if (iTraj == (abs(iTrajLast)-1)) {
00296       
00297       // Last Trajectory Meas
00298       pftrack.addPoint(PFTrajectoryPoint(iid,-1,
00299                                          math::XYZPoint(v.x(), v.y(), v.z()),
00300                                          math::XYZTLorentzVector(p.x(),p.y(),p.z(),p.mag())));
00301 
00302 
00303 
00304 
00305       BaseParticlePropagator theOutParticle = 
00306         BaseParticlePropagator( 
00307                                RawParticle(XYZTLorentzVector(p.x(),
00308                                                              p.y(),
00309                                                              p.z(),
00310                                                              pfenergy),
00311                                            XYZTLorentzVector(v.x(),
00312                                                              v.y(),
00313                                                              v.z(),
00314                                                              0.)), 
00315                                0.,0.,B_.z());
00316       theOutParticle.setCharge(track.charge());  
00317       bool isBelowPS=false; 
00318       theOutParticle.propagateToPreshowerLayer1(false);
00319       if(theOutParticle.getSuccess()!=0)
00320         pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS1,
00321                                            math::XYZPoint(theOutParticle.vertex()),
00322                                            math::XYZTLorentzVector(theOutParticle.momentum())));
00323       else {
00324         PFTrajectoryPoint dummyPS1;
00325         pftrack.addPoint(dummyPS1); 
00326       }
00327       
00328       
00329       theOutParticle.propagateToPreshowerLayer2(false);
00330       if(theOutParticle.getSuccess()!=0){
00331         pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS2,
00332                                            math::XYZPoint(theOutParticle.vertex()),
00333                                            math::XYZTLorentzVector(theOutParticle.momentum())));
00334         isBelowPS=true;
00335       }   else {
00336         PFTrajectoryPoint dummyPS2;
00337         pftrack.addPoint(dummyPS2); 
00338       }
00339       
00340       theOutParticle.propagateToEcalEntrance(false);
00341       
00342       if(theOutParticle.getSuccess()!=0){
00343         pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALEntrance,
00344                                            math::XYZPoint(theOutParticle.vertex()),
00345                                            math::XYZTLorentzVector(theOutParticle.momentum())));
00346         double ecalShowerDepth     
00347           = PFCluster::getDepthCorrection(theOutParticle.momentum().E(),
00348                                           isBelowPS, 
00349                                           false);
00350         
00351         math::XYZPoint meanShower=math::XYZPoint(theOutParticle.vertex())+
00352           math::XYZTLorentzVector(theOutParticle.momentum()).Vect().Unit()*ecalShowerDepth;
00353         
00354         pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALShowerMax,
00355                                            meanShower,
00356                                            math::XYZTLorentzVector(theOutParticle.momentum())));}
00357       else {
00358         if (PT>5.)
00359           LogWarning("PFTrackTransformer")<<"GSF TRACK "<<pftrack<< " PROPAGATION TO THE ECAL HAS FAILED";
00360         PFTrajectoryPoint dummyECAL;
00361         pftrack.addPoint(dummyECAL); 
00362         PFTrajectoryPoint dummyMaxSh;
00363         pftrack.addPoint(dummyMaxSh); 
00364       }
00365       
00366       
00367       
00368       //HCAL entrance
00369       theOutParticle.propagateToHcalEntrance(false);
00370       if(theOutParticle.getSuccess()!=0)
00371         pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALEntrance,
00372                                            math::XYZPoint(theOutParticle.vertex()),
00373                                            math::XYZTLorentzVector(theOutParticle.momentum())));
00374       else{
00375         if (PT>5.)
00376           LogWarning("PFTrackTransformer")<<"GSF TRACK "<<pftrack<< " PROPAGATION TO THE HCAL ENTRANCE HAS FAILED";
00377         PFTrajectoryPoint dummyHCALentrance;
00378         pftrack.addPoint(dummyHCALentrance); 
00379       }  
00380       
00381       //HCAL exit
00382       theOutParticle.propagateToHcalExit(false);
00383       if(theOutParticle.getSuccess()!=0)
00384         pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALExit,
00385                                            math::XYZPoint(theOutParticle.vertex()),
00386                                            math::XYZTLorentzVector(theOutParticle.momentum())));
00387       else{
00388         if (PT>5.)
00389           LogWarning("PFTrackTransformer")<<"GSF TRACK "<<pftrack<< " PROPAGATION TO THE HCAL EXIT HAS FAILED";
00390         PFTrajectoryPoint dummyHCALexit;
00391         pftrack.addPoint(dummyHCALexit); 
00392       } 
00393       
00394     }
00395 
00396     // --------------------------   END GSF Track ------------------------------------- 
00397   
00398     // --------------------------   Fill Brem "Track" --------------------------------- 
00399     // Fill the brem for each traj point
00400 
00401     //check that the vertex of the brem is in the tracker volume
00402     if ((v.perp()>110) ||(fabs(v.z())>280)) continue;    
00403     unsigned int iTrajPoint =  iTrajPos + 2;
00404     if(iid%2 == 1) iTrajPoint = 99;
00405 
00406     PFBrem brem(DP,SigmaDP,iTrajPoint);
00407 
00408 
00409     GlobalVector p_gamma= p*(fabs(DP)/p.mag());   // Direction from the electron (tangent), DP without any sign!;
00410     float e_gamma = fabs(DP); // DP = pout-pin so could be negative
00411     BaseParticlePropagator theBremParticle = 
00412       BaseParticlePropagator( 
00413                              RawParticle(XYZTLorentzVector(p_gamma.x(),
00414                                                            p_gamma.y(),
00415                                                            p_gamma.z(),
00416                                                            e_gamma),
00417                                          XYZTLorentzVector(v.x(),
00418                                                            v.y(),
00419                                                            v.z(),
00420                                                            0.)),
00421                              0.,0.,B_.z());
00422     int gamma_charge = 0;
00423     theBremParticle.setCharge(gamma_charge);  
00424 
00425 
00426     // add TrajectoryPoint for Brem, PS, ECAL, ECALShowMax, HCAL
00427     // Brem Entrance PS Layer1
00428 
00429     PFTrajectoryPoint dummyClosest;   // Added just to have the right number order in PFTrack.cc
00430     brem.addPoint(dummyClosest); 
00431 
00432     
00433     PFTrajectoryPoint dummyBeamPipe;  // Added just to have the right number order in PFTrack.cc
00434     brem.addPoint(dummyBeamPipe); 
00435 
00436 
00437     
00438     bool isBelowPS=false; 
00439     theBremParticle.propagateToPreshowerLayer1(false);
00440     if(theBremParticle.getSuccess()!=0)
00441       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS1,
00442                                          math::XYZPoint(theBremParticle.vertex()),
00443                                          math::XYZTLorentzVector(theBremParticle.momentum())));
00444     else {
00445       PFTrajectoryPoint dummyPS1;
00446       brem.addPoint(dummyPS1); 
00447     }
00448     
00449     // Brem Entrance PS Layer 2
00450 
00451     theBremParticle.propagateToPreshowerLayer2(false);
00452     if(theBremParticle.getSuccess()!=0){
00453       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS2,
00454                                          math::XYZPoint(theBremParticle.vertex()),
00455                                          math::XYZTLorentzVector(theBremParticle.momentum())));
00456       isBelowPS=true;
00457     }   else {
00458       PFTrajectoryPoint dummyPS2;
00459       brem.addPoint(dummyPS2); 
00460     }
00461 
00462    theBremParticle.propagateToEcalEntrance(false);
00463 
00464    if(theBremParticle.getSuccess()!=0){
00465      brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALEntrance,
00466                                         math::XYZPoint(theBremParticle.vertex()),
00467                                         math::XYZTLorentzVector(theBremParticle.momentum())));
00468    double ecalShowerDepth     
00469      = PFCluster::getDepthCorrection(theBremParticle.momentum().E(),
00470                                      isBelowPS, 
00471                                      false);
00472 
00473    math::XYZPoint meanShower=math::XYZPoint(theBremParticle.vertex())+
00474      math::XYZTLorentzVector(theBremParticle.momentum()).Vect().Unit()*ecalShowerDepth;
00475  
00476    brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALShowerMax,
00477                                       meanShower,
00478                                       math::XYZTLorentzVector(theBremParticle.momentum())));}
00479    else {
00480      if ((DP>5.) && ((DP/SigmaDP)>3))
00481        LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE ECAL HAS FAILED";
00482      PFTrajectoryPoint dummyECAL;
00483      brem.addPoint(dummyECAL); 
00484      PFTrajectoryPoint dummyMaxSh;
00485      brem.addPoint(dummyMaxSh); 
00486    }
00487 
00488 
00489  
00490    //HCAL entrance
00491    theBremParticle.propagateToHcalEntrance(false);
00492    if(theBremParticle.getSuccess()!=0)
00493      brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALEntrance,
00494                                         math::XYZPoint(theBremParticle.vertex()),
00495                                         math::XYZTLorentzVector(theBremParticle.momentum())));
00496    else{
00497      if ((DP>5.) && ((DP/SigmaDP)>3))
00498        LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE HCAL ENTRANCE HAS FAILED";
00499      PFTrajectoryPoint dummyHCALentrance;
00500      brem.addPoint(dummyHCALentrance); 
00501    }  
00502 
00503    //HCAL exit
00504    theBremParticle.propagateToHcalExit(false);
00505    if(theBremParticle.getSuccess()!=0)
00506      brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALExit,
00507                                         math::XYZPoint(theBremParticle.vertex()),
00508                                         math::XYZTLorentzVector(theBremParticle.momentum())));
00509    else{  
00510      if ((DP>5.) && ((DP/SigmaDP)>3))
00511        LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE HCAL EXIT HAS FAILED";
00512      PFTrajectoryPoint dummyHCALexit;
00513      brem.addPoint(dummyHCALexit); 
00514    }
00515 
00516    brem.calculatePositionREP();
00517    pftrack.addBrem(brem);
00518    iTrajPos++;
00519   }
00520   return true;
00521 }
00522 
00523 bool 
00524 PFTrackTransformer::addPointsAndBrems( reco::GsfPFRecTrack& pftrack, 
00525                                        const reco::GsfTrack& track,
00526                                        const MultiTrajectoryStateTransform& mtjstate) const {
00527 
00528   //  float PT= track.pt();
00529   unsigned int iTrajPos = 0;
00530   unsigned int iid = 0; // not anymore saved
00531 
00532 
00533   // *****************************   INNER State *************************************
00534   TrajectoryStateOnSurface inTSOS = mtjstate.innerStateOnSurface((track));
00535   TrajectoryStateOnSurface outTSOS = mtjstate.outerStateOnSurface((track));
00536 
00537   if(!inTSOS.isValid() || !outTSOS.isValid()) {
00538     if(!inTSOS.isValid())
00539       LogWarning("PFTrackTransformer")<<" INNER TSOS NOT VALID ";
00540     if(!outTSOS.isValid())
00541       LogWarning("PFTrackTransformer")<<" OUTER TSOS NOT VALID ";
00542     return false;
00543   }
00544 
00545   GlobalVector InMom;
00546   GlobalPoint InPos;
00547   if(inTSOS.isValid()) {
00548     mtsMode_->momentumFromModeCartesian(inTSOS,InMom);
00549     mtsMode_->positionFromModeCartesian(inTSOS,InPos);
00550   }
00551   else {
00552     InMom = GlobalVector(track.pxMode(),track.pyMode(),track.pzMode());
00553     InPos = GlobalPoint(0.,0.,0.);
00554   }
00555 
00556   //  float pfmass= (pftrack.algoType()==reco::PFRecTrack::KF_ELCAND) ? 0.0005 : 0.139; 
00557   float ptot =  sqrt((InMom.x()*InMom.x())+(InMom.y()*InMom.y())+(InMom.z()*InMom.z()));
00558   float pfenergy= ptot;
00559   
00560   math::XYZTLorentzVector momClosest 
00561     = math::XYZTLorentzVector(InMom.x(), InMom.y(), 
00562                               InMom.z(), ptot);
00563   math::XYZPoint posClosest = track.vertex();
00564   pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ClosestApproach,
00565                                      posClosest,momClosest));
00566   
00567   BaseParticlePropagator theInnerParticle = 
00568     BaseParticlePropagator( RawParticle(XYZTLorentzVector(InMom.x(),
00569                                                           InMom.y(),
00570                                                           InMom.z(),
00571                                                           pfenergy),
00572                                         XYZTLorentzVector(track.vertex().x(),
00573                                                           track.vertex().y(),
00574                                                           track.vertex().z(),
00575                                                           0.)),  //DANIELE Same thing v.x(),v.y(),v.()? 
00576                             0.,0.,B_.z());
00577   theInnerParticle.setCharge(track.charge());   // Use the chargeMode ??   
00578   //BEAMPIPE
00579   theInnerParticle.setPropagationConditions(PFGeometry::outerRadius(PFGeometry::BeamPipe), 
00580                                             PFGeometry::outerZ(PFGeometry::BeamPipe), false);
00581   theInnerParticle.propagate();
00582   if(theInnerParticle.getSuccess()!=0)
00583     pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::BeamPipeOrEndVertex,
00584                                        math::XYZPoint(theInnerParticle.vertex()),
00585                                        math::XYZTLorentzVector(theInnerParticle.momentum())));
00586   else {
00587     PFTrajectoryPoint dummyBeam;
00588     pftrack.addPoint(dummyBeam); 
00589   }
00590   
00591 
00592   // first tjpoint 
00593   pftrack.addPoint(PFTrajectoryPoint(iid,-1,
00594                                      math::XYZPoint(InPos.x(),InPos.y(), InPos.z()),
00595                                      math::XYZTLorentzVector(InMom.x(),InMom.y(),InMom.z(),InMom.mag())));
00596   
00597   
00598   //######### Photon at INNER State ##########
00599 
00600 
00601   unsigned int iTrajPoint =  iTrajPos + 2;  
00602   double dp_tang = ptot;
00603   double sdp_tang = track.ptModeError()*(track.pMode()/track.ptMode());
00604   PFBrem brem(dp_tang,sdp_tang,iTrajPoint);
00605   BaseParticlePropagator theBremParticle = 
00606     BaseParticlePropagator( 
00607                            RawParticle(XYZTLorentzVector(InMom.x(),
00608                                                          InMom.y(),
00609                                                          InMom.z(),
00610                                                          dp_tang),
00611                                        XYZTLorentzVector(InPos.x(),
00612                                                          InPos.y(),
00613                                                          InPos.z(),
00614                                                          0.)),
00615                            0.,0.,B_.z());
00616   int gamma_charge = 0;
00617   theBremParticle.setCharge(gamma_charge);  
00618   // add TrajectoryPoint for Brem, PS, ECAL, ECALShowMax, HCAL
00619   // Brem Entrance PS Layer1
00620   PFTrajectoryPoint dummyClosest;   // Added just to have the right number order in PFTrack.cc
00621   brem.addPoint(dummyClosest); 
00622   
00623   
00624   PFTrajectoryPoint dummyBeamPipe;  // Added just to have the right number order in PFTrack.cc
00625   brem.addPoint(dummyBeamPipe); 
00626   
00627   
00628   
00629   bool isBelowPS=false; 
00630   theBremParticle.propagateToPreshowerLayer1(false);
00631   if(theBremParticle.getSuccess()!=0)
00632     brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS1,
00633                                     math::XYZPoint(theBremParticle.vertex()),
00634                                     math::XYZTLorentzVector(theBremParticle.momentum())));
00635   else {
00636     PFTrajectoryPoint dummyPS1;
00637     brem.addPoint(dummyPS1); 
00638   }
00639   
00640   // Brem Entrance PS Layer 2
00641   
00642   theBremParticle.propagateToPreshowerLayer2(false);
00643   if(theBremParticle.getSuccess()!=0){
00644     brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS2,
00645                                     math::XYZPoint(theBremParticle.vertex()),
00646                                     math::XYZTLorentzVector(theBremParticle.momentum())));
00647     isBelowPS=true;
00648   }   else {
00649     PFTrajectoryPoint dummyPS2;
00650     brem.addPoint(dummyPS2); 
00651   }
00652   
00653   theBremParticle.propagateToEcalEntrance(false);
00654   
00655   if(theBremParticle.getSuccess()!=0){
00656     brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALEntrance,
00657                                     math::XYZPoint(theBremParticle.vertex()),
00658                                     math::XYZTLorentzVector(theBremParticle.momentum())));
00659 
00660     //  for the first brem give a low default DP of 100 MeV.  
00661     double EDepthCorr = 0.01;
00662     double ecalShowerDepth     
00663       = PFCluster::getDepthCorrection(EDepthCorr,
00664                                       isBelowPS, 
00665                                       false);
00666     
00667     math::XYZPoint meanShower=math::XYZPoint(theBremParticle.vertex())+
00668       math::XYZTLorentzVector(theBremParticle.momentum()).Vect().Unit()*ecalShowerDepth;
00669     
00670     brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALShowerMax,
00671                                     meanShower,
00672                                     math::XYZTLorentzVector(theBremParticle.momentum())));}
00673   else {
00674     if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
00675       LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE ECAL HAS FAILED";
00676     PFTrajectoryPoint dummyECAL;
00677     brem.addPoint(dummyECAL); 
00678     PFTrajectoryPoint dummyMaxSh;
00679     brem.addPoint(dummyMaxSh); 
00680   }
00681   
00682   
00683   
00684   //HCAL entrance
00685   theBremParticle.propagateToHcalEntrance(false);
00686   if(theBremParticle.getSuccess()!=0)
00687     brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALEntrance,
00688                                     math::XYZPoint(theBremParticle.vertex()),
00689                                     math::XYZTLorentzVector(theBremParticle.momentum())));
00690   else{
00691     if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
00692       LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE HCAL ENTRANCE HAS FAILED";
00693     PFTrajectoryPoint dummyHCALentrance;
00694     brem.addPoint(dummyHCALentrance); 
00695   }  
00696   
00697   //HCAL exit
00698   theBremParticle.propagateToHcalExit(false);
00699   if(theBremParticle.getSuccess()!=0)
00700     brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALExit,
00701                                     math::XYZPoint(theBremParticle.vertex()),
00702                                     math::XYZTLorentzVector(theBremParticle.momentum())));
00703   else{  
00704     if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
00705       LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE HCAL EXIT HAS FAILED";
00706     PFTrajectoryPoint dummyHCALexit;
00707     brem.addPoint(dummyHCALexit); 
00708   }
00709   
00710   brem.calculatePositionREP();
00711   pftrack.addBrem(brem);
00712   iTrajPos++;
00713 
00714   
00715 
00716 
00717   // *****************************   INTERMIDIATE State *************************************
00718   //From the new Wolfgang code
00719 
00720   // To think if the cout should be removed. 
00721   if(track.gsfExtra()->tangentsSize() == 0)
00722     LogError("PFTrackTransformer")
00723       <<"BE CAREFUL: Gsf Tangents not stored in the event. You need to re-reco the particle-flow with RecoToDisplay_cfg.py and not RecoToDisplay_NoTracking_cfg.py ";
00724   
00725 
00726   vector<GsfTangent> gsftang = track.gsfExtra()->tangents();
00727   for(unsigned int iTang = 0; iTang < track.gsfExtra()->tangentsSize(); iTang++) {
00728     
00729     dp_tang = gsftang[iTang].deltaP().value();
00730     sdp_tang = gsftang[iTang].deltaP().error();
00731     
00732     //check that the vertex of the brem is in the tracker volume
00733     if ((sqrt(gsftang[iTang].position().x()*gsftang[iTang].position().x() 
00734               + gsftang[iTang].position().y()*gsftang[iTang].position().y())>110) 
00735         ||(fabs(gsftang[iTang].position().z())>280)) continue;    
00736 
00737     iTrajPoint = iTrajPos + 2;
00738     PFBrem brem(dp_tang,sdp_tang,iTrajPoint);
00739 
00740  
00741 
00742     GlobalVector p_tang=  GlobalVector(gsftang[iTang].momentum().x(),
00743                                        gsftang[iTang].momentum().y(),
00744                                        gsftang[iTang].momentum().z());
00745     
00746     
00747     // ###### track tj points
00748     pftrack.addPoint(PFTrajectoryPoint(iid,-1,
00749                                        math::XYZPoint(gsftang[iTang].position().x(),gsftang[iTang].position().y(),gsftang[iTang].position().z()),
00750                                        math::XYZTLorentzVector(p_tang.x(),p_tang.y(),p_tang.z(),p_tang.mag())));
00751     
00752 
00753     //rescale
00754     GlobalVector p_gamma = p_tang *(fabs(dp_tang)/p_tang.mag()); 
00755     
00756     // GlobalVector 
00757 
00758  
00759     double e_gamma = fabs(dp_tang); // DP = pout-pin so could be negative
00760     theBremParticle = BaseParticlePropagator( 
00761                                              RawParticle(XYZTLorentzVector(p_gamma.x(),
00762                                                                            p_gamma.y(),
00763                                                                            p_gamma.z(),
00764                                                                            e_gamma),
00765                                                          XYZTLorentzVector(gsftang[iTang].position().x(),
00766                                                                            gsftang[iTang].position().y(),
00767                                                                            gsftang[iTang].position().z(),
00768                                                                            0.)),
00769                                              0.,0.,B_.z());
00770    
00771     theBremParticle.setCharge(gamma_charge);  
00772     
00773     
00774     PFTrajectoryPoint dummyClosest;   // Added just to have the right number order in PFTrack.cc
00775     brem.addPoint(dummyClosest); 
00776     
00777     
00778     PFTrajectoryPoint dummyBeamPipe;  // Added just to have the right number order in PFTrack.cc
00779     brem.addPoint(dummyBeamPipe); 
00780     
00781     
00782     
00783     isBelowPS=false; 
00784     theBremParticle.propagateToPreshowerLayer1(false);
00785     if(theBremParticle.getSuccess()!=0)
00786       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS1,
00787                                       math::XYZPoint(theBremParticle.vertex()),
00788                                       math::XYZTLorentzVector(theBremParticle.momentum())));
00789     else {
00790       PFTrajectoryPoint dummyPS1;
00791       brem.addPoint(dummyPS1); 
00792     }
00793     
00794     // Brem Entrance PS Layer 2
00795     
00796     theBremParticle.propagateToPreshowerLayer2(false);
00797     if(theBremParticle.getSuccess()!=0){
00798       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS2,
00799                                       math::XYZPoint(theBremParticle.vertex()),
00800                                       math::XYZTLorentzVector(theBremParticle.momentum())));
00801       isBelowPS=true;
00802     }   else {
00803       PFTrajectoryPoint dummyPS2;
00804       brem.addPoint(dummyPS2); 
00805     }
00806     
00807     theBremParticle.propagateToEcalEntrance(false);
00808     
00809     if(theBremParticle.getSuccess()!=0){
00810       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALEntrance,
00811                                       math::XYZPoint(theBremParticle.vertex()),
00812                                       math::XYZTLorentzVector(theBremParticle.momentum())));
00813 
00814       double ecalShowerDepth     
00815         = PFCluster::getDepthCorrection(theBremParticle.momentum().E(),
00816                                         isBelowPS, 
00817                                         false);
00818       
00819       math::XYZPoint meanShower=math::XYZPoint(theBremParticle.vertex())+
00820         math::XYZTLorentzVector(theBremParticle.momentum()).Vect().Unit()*ecalShowerDepth;
00821       
00822       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALShowerMax,
00823                                       meanShower,
00824                                       math::XYZTLorentzVector(theBremParticle.momentum())));}
00825     else {
00826       if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
00827         LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE ECAL HAS FAILED";
00828       PFTrajectoryPoint dummyECAL;
00829       brem.addPoint(dummyECAL); 
00830       PFTrajectoryPoint dummyMaxSh;
00831       brem.addPoint(dummyMaxSh); 
00832     }
00833 
00834 
00835  
00836     //HCAL entrance
00837     theBremParticle.propagateToHcalEntrance(false);
00838     if(theBremParticle.getSuccess()!=0)
00839       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALEntrance,
00840                                       math::XYZPoint(theBremParticle.vertex()),
00841                                       math::XYZTLorentzVector(theBremParticle.momentum())));
00842     else{
00843       if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
00844         LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE HCAL ENTRANCE HAS FAILED";
00845       PFTrajectoryPoint dummyHCALentrance;
00846       brem.addPoint(dummyHCALentrance); 
00847     }  
00848     
00849     //HCAL exit
00850     theBremParticle.propagateToHcalExit(false);
00851     if(theBremParticle.getSuccess()!=0)
00852       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALExit,
00853                                       math::XYZPoint(theBremParticle.vertex()),
00854                                       math::XYZTLorentzVector(theBremParticle.momentum())));
00855     else{  
00856       if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
00857         LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE HCAL EXIT HAS FAILED";
00858       PFTrajectoryPoint dummyHCALexit;
00859       brem.addPoint(dummyHCALexit); 
00860     }
00861     
00862     brem.calculatePositionREP();
00863     pftrack.addBrem(brem);
00864     iTrajPos++;
00865   }
00866 
00867 
00868 
00869 
00870   // *****************************   OUTER State *************************************
00871  
00872   if(outTSOS.isValid()) {
00873     GlobalVector OutMom;
00874     GlobalPoint OutPos;
00875     
00876     // DANIELE ?????  if the out is not valid maybe take the last tangent?
00877     // From Wolfgang. It should be always valid 
00878 
00879     mtsMode_->momentumFromModeCartesian(outTSOS,OutMom);
00880     mtsMode_->positionFromModeCartesian(outTSOS,OutPos);
00881 
00882 
00883 
00884     // last tjpoint 
00885     pftrack.addPoint(PFTrajectoryPoint(iid,-1,
00886                                        math::XYZPoint(OutPos.x(),OutPos.y(), OutPos.z()),
00887                                        math::XYZTLorentzVector(OutMom.x(),OutMom.y(),OutMom.z(),OutMom.mag())));
00888 
00889     
00890     float ptot_out =  sqrt((OutMom.x()*OutMom.x())+(OutMom.y()*OutMom.y())+(OutMom.z()*OutMom.z()));
00891     float pTtot_out = sqrt((OutMom.x()*OutMom.x())+(OutMom.y()*OutMom.y()));
00892     float pfenergy_out = ptot_out;
00893     BaseParticlePropagator theOutParticle = 
00894       BaseParticlePropagator( RawParticle(XYZTLorentzVector(OutMom.x(),
00895                                                             OutMom.y(),
00896                                                             OutMom.z(),
00897                                                             pfenergy_out),
00898                                           XYZTLorentzVector(OutPos.x(),
00899                                                             OutPos.y(),
00900                                                             OutPos.z(),
00901                                                             0.)), 
00902                               0.,0.,B_.z());
00903     theOutParticle.setCharge(track.charge());  
00904     isBelowPS=false; 
00905     theOutParticle.propagateToPreshowerLayer1(false);
00906     if(theOutParticle.getSuccess()!=0)
00907       pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS1,
00908                                          math::XYZPoint(theOutParticle.vertex()),
00909                                          math::XYZTLorentzVector(theOutParticle.momentum())));
00910     else {
00911       PFTrajectoryPoint dummyPS1;
00912       pftrack.addPoint(dummyPS1); 
00913     }
00914     
00915     
00916     theOutParticle.propagateToPreshowerLayer2(false);
00917     if(theOutParticle.getSuccess()!=0){
00918       pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS2,
00919                                          math::XYZPoint(theOutParticle.vertex()),
00920                                          math::XYZTLorentzVector(theOutParticle.momentum())));
00921       isBelowPS=true;
00922     }   else {
00923       PFTrajectoryPoint dummyPS2;
00924       pftrack.addPoint(dummyPS2); 
00925     }
00926     
00927     theOutParticle.propagateToEcalEntrance(false);
00928     
00929     if(theOutParticle.getSuccess()!=0){
00930       pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALEntrance,
00931                                          math::XYZPoint(theOutParticle.vertex()),
00932                                          math::XYZTLorentzVector(theOutParticle.momentum())));
00933       double EDepthCorr = 0.01;
00934       double ecalShowerDepth     
00935         = PFCluster::getDepthCorrection(EDepthCorr,
00936                                         isBelowPS, 
00937                                         false);
00938       
00939       math::XYZPoint meanShower=math::XYZPoint(theOutParticle.vertex())+
00940         math::XYZTLorentzVector(theOutParticle.momentum()).Vect().Unit()*ecalShowerDepth;
00941       
00942       pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALShowerMax,
00943                                          meanShower,
00944                                          math::XYZTLorentzVector(theOutParticle.momentum())));}
00945     else {
00946       if (pTtot_out>5.)
00947         LogWarning("PFTrackTransformer")<<"GSF TRACK "<<pftrack<< " PROPAGATION TO THE ECAL HAS FAILED";
00948       PFTrajectoryPoint dummyECAL;
00949       pftrack.addPoint(dummyECAL); 
00950       PFTrajectoryPoint dummyMaxSh;
00951       pftrack.addPoint(dummyMaxSh); 
00952     }
00953     
00954     
00955     
00956     //HCAL entrance
00957     theOutParticle.propagateToHcalEntrance(false);
00958     if(theOutParticle.getSuccess()!=0)
00959       pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALEntrance,
00960                                          math::XYZPoint(theOutParticle.vertex()),
00961                                          math::XYZTLorentzVector(theOutParticle.momentum())));
00962     else{
00963       if (pTtot_out>5.)
00964         LogWarning("PFTrackTransformer")<<"GSF TRACK "<<pftrack<< " PROPAGATION TO THE HCAL ENTRANCE HAS FAILED";
00965       PFTrajectoryPoint dummyHCALentrance;
00966       pftrack.addPoint(dummyHCALentrance); 
00967     }  
00968     
00969     //HCAL exit
00970     theOutParticle.propagateToHcalExit(false);
00971     if(theOutParticle.getSuccess()!=0)
00972       pftrack.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALExit,
00973                                          math::XYZPoint(theOutParticle.vertex()),
00974                                          math::XYZTLorentzVector(theOutParticle.momentum())));
00975     else{
00976       if (pTtot_out>5.)
00977         LogWarning("PFTrackTransformer")<<"GSF TRACK "<<pftrack<< " PROPAGATION TO THE HCAL EXIT HAS FAILED";
00978       PFTrajectoryPoint dummyHCALexit;
00979       pftrack.addPoint(dummyHCALexit); 
00980     }
00981 
00982 
00983 
00984 
00985     //######## Photon at the OUTER State ##########
00986 
00987     dp_tang = OutMom.mag();
00988     // for the moment same inner error just for semplicity
00989     sdp_tang = track.ptModeError()*(track.pMode()/track.ptMode());
00990     iTrajPoint = iTrajPos + 2;
00991     PFBrem brem(dp_tang,sdp_tang,iTrajPoint);
00992 
00993     theBremParticle =   
00994       BaseParticlePropagator( RawParticle(XYZTLorentzVector(OutMom.x(),
00995                                                             OutMom.y(),
00996                                                             OutMom.z(),
00997                                                             dp_tang),
00998                                           XYZTLorentzVector(OutPos.x(),
00999                                                             OutPos.y(),
01000                                                             OutPos.z(),
01001                                                             0.)), 
01002                               0.,0.,B_.z());
01003     theBremParticle.setCharge(gamma_charge);  
01004     
01005     
01006     PFTrajectoryPoint dummyClosest;   // Added just to have the right number order in PFTrack.cc
01007     brem.addPoint(dummyClosest); 
01008     
01009     
01010     PFTrajectoryPoint dummyBeamPipe;  // Added just to have the right number order in PFTrack.cc
01011     brem.addPoint(dummyBeamPipe); 
01012     
01013     
01014     
01015     isBelowPS=false; 
01016     theBremParticle.propagateToPreshowerLayer1(false);
01017     if(theBremParticle.getSuccess()!=0)
01018       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS1,
01019                                       math::XYZPoint(theBremParticle.vertex()),
01020                                       math::XYZTLorentzVector(theBremParticle.momentum())));
01021     else {
01022       PFTrajectoryPoint dummyPS1;
01023       brem.addPoint(dummyPS1); 
01024     }
01025     
01026     // Brem Entrance PS Layer 2
01027     
01028     theBremParticle.propagateToPreshowerLayer2(false);
01029     if(theBremParticle.getSuccess()!=0){
01030       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::PS2,
01031                                       math::XYZPoint(theBremParticle.vertex()),
01032                                       math::XYZTLorentzVector(theBremParticle.momentum())));
01033       isBelowPS=true;
01034     }   else {
01035       PFTrajectoryPoint dummyPS2;
01036       brem.addPoint(dummyPS2); 
01037     }
01038     
01039     theBremParticle.propagateToEcalEntrance(false);
01040     
01041     if(theBremParticle.getSuccess()!=0){
01042       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALEntrance,
01043                                       math::XYZPoint(theBremParticle.vertex()),
01044                                       math::XYZTLorentzVector(theBremParticle.momentum())));
01045       double ecalShowerDepth     
01046         = PFCluster::getDepthCorrection(theBremParticle.momentum().E(),
01047                                         isBelowPS, 
01048                                         false);
01049       
01050       math::XYZPoint meanShower=math::XYZPoint(theBremParticle.vertex())+
01051         math::XYZTLorentzVector(theBremParticle.momentum()).Vect().Unit()*ecalShowerDepth;
01052       
01053       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::ECALShowerMax,
01054                                       meanShower,
01055                                       math::XYZTLorentzVector(theBremParticle.momentum())));}
01056     else {
01057       if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
01058         LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE ECAL HAS FAILED";
01059       PFTrajectoryPoint dummyECAL;
01060       brem.addPoint(dummyECAL); 
01061       PFTrajectoryPoint dummyMaxSh;
01062       brem.addPoint(dummyMaxSh); 
01063     }
01064 
01065 
01066  
01067     //HCAL entrance
01068     theBremParticle.propagateToHcalEntrance(false);
01069     if(theBremParticle.getSuccess()!=0)
01070       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALEntrance,
01071                                       math::XYZPoint(theBremParticle.vertex()),
01072                                       math::XYZTLorentzVector(theBremParticle.momentum())));
01073     else{
01074       if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
01075         LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE HCAL ENTRANCE HAS FAILED";
01076       PFTrajectoryPoint dummyHCALentrance;
01077       brem.addPoint(dummyHCALentrance); 
01078     }  
01079     
01080     //HCAL exit
01081     theBremParticle.propagateToHcalExit(false);
01082     if(theBremParticle.getSuccess()!=0)
01083       brem.addPoint(PFTrajectoryPoint(-1,PFTrajectoryPoint::HCALExit,
01084                                       math::XYZPoint(theBremParticle.vertex()),
01085                                       math::XYZTLorentzVector(theBremParticle.momentum())));
01086     else{  
01087       if ((dp_tang>5.) && ((dp_tang/sdp_tang)>3))
01088         LogWarning("PFTrackTransformer")<<"BREM "<<brem<<" PROPAGATION TO THE HCAL EXIT HAS FAILED";
01089       PFTrajectoryPoint dummyHCALexit;
01090       brem.addPoint(dummyHCALexit); 
01091     }
01092 
01093     brem.calculatePositionREP();
01094     pftrack.addBrem(brem);
01095     iTrajPos++;
01096   }
01097 
01098   return true;
01099 }