CMS 3D CMS Logo

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