/[PAMELA software]/DarthVader/CalorimeterLevel2/src/CaloLevel1.cpp
ViewVC logotype

Diff of /DarthVader/CalorimeterLevel2/src/CaloLevel1.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by mocchiut, Tue Nov 28 10:20:27 2006 UTC revision 1.4 by mocchiut, Mon Mar 26 14:02:06 2007 UTC
# Line 3  Line 3 
3   * \author Emiliano Mocchiutti   * \author Emiliano Mocchiutti
4   *   *
5  **/  **/
 #include <TObject.h>  
 #include <TMath.h>  
6  #include <CaloLevel1.h>  #include <CaloLevel1.h>
7  //  //
8  ClassImp(CaloStrip);  ClassImp(CaloStrip);
# Line 16  ClassImp(CaloLevel1); Line 14  ClassImp(CaloLevel1);
14  CaloStrip::CaloStrip() {  CaloStrip::CaloStrip() {
15    c1 = 0;    c1 = 0;
16    this->Clear();    this->Clear();
17      UseStandardAlig();
18  };  };
19    
20  /**  /**
# Line 24  CaloStrip::CaloStrip() { Line 23  CaloStrip::CaloStrip() {
23  CaloStrip::CaloStrip(CaloLevel1 *calo) {  CaloStrip::CaloStrip(CaloLevel1 *calo) {
24    c1 = calo->GetCaloLevel1();    c1 = calo->GetCaloLevel1();
25    this->Clear();    this->Clear();
26      ismech = false;
27  };  };
28    
29  /**  /**
30   * Clear variables   * Clear variables
31  **/  **/
32  void CaloStrip::Clear() {  void CaloStrip::Clear() {  
33    fE = 0.;    fE = 0.;
34    fX = 0.;    fX = 0.;
35    fY = 0.;    fY = 0.;
# Line 40  void CaloStrip::Clear() { Line 40  void CaloStrip::Clear() {
40  };  };
41    
42  /**  /**
43     * Connect to the DB and retrieve alignement parameters
44     **/
45    void CaloStrip::UseStandardAlig(){
46      //
47      ismech = false;
48      //
49      stringstream aligfile;
50      Int_t error = 0;
51      FILE *f = 0;
52      ifstream badfile;
53      GL_PARAM *glparam = new GL_PARAM();
54      //
55      TString host = "mysql://localhost/pamelaprod";
56      TString user = "anonymous";
57      TString psw = "";
58      const char *pamdbhost=gSystem->Getenv("PAM_DBHOST");
59      const char *pamdbuser=gSystem->Getenv("PAM_DBUSER");
60      const char *pamdbpsw=gSystem->Getenv("PAM_DBPSW");
61      if ( !pamdbhost ) pamdbhost = "";
62      if ( !pamdbuser ) pamdbuser = "";
63      if ( !pamdbpsw ) pamdbpsw = "";
64      if ( strcmp(pamdbhost,"") ) host = pamdbhost;
65      if ( strcmp(pamdbuser,"") ) user = pamdbuser;
66      if ( strcmp(pamdbpsw,"") ) psw = pamdbpsw;
67      TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
68      //
69      UXal = 0.;
70      UYal = 0.;
71      UZal = 0.;
72      //
73      if ( dbc ){
74        //
75        // determine where I can find calorimeter ADC to MIP conversion file  
76        //
77        printf(" Querying DB for calorimeter parameters files...\n");
78        //
79        //
80        //
81        error = 0;
82        error = glparam->Query_GL_PARAM(1000,102,dbc);
83        if ( error >= 0 ){
84          //
85          aligfile.str("");
86          aligfile << glparam->PATH.Data() << "/";
87          aligfile << glparam->NAME.Data();
88          //
89          printf("\n Using parameter file: \n %s \n",aligfile.str().c_str());
90          f = fopen(aligfile.str().c_str(),"rb");
91          if ( f ){
92            //
93            fread(&UXal,sizeof(UXal),1,f);
94            fread(&UYal,sizeof(UYal),1,f);
95            fread(&UZal,sizeof(UZal),1,f);
96            //
97            fclose(f);
98          };
99          //
100        };
101        dbc->Close();
102      };
103      if ( !UXal ){
104        //
105        printf(" No able to query DB for calorimeter parameters files\n Using hard-coded parameters \n");
106        UXal = CTX;
107        UYal = CTY;
108        UZal = CTZ;
109      };
110      //
111    };
112    
113    
114    
115    
116    
117    
118    /**
119   * Given a strip returns its position in the PAMELA reference system   * Given a strip returns its position in the PAMELA reference system
120  **/  **/
121  void CaloStrip::Set(Int_t view, Int_t plane, Int_t strip) {  void CaloStrip::Set(Int_t view, Int_t plane, Int_t strip) {
# Line 76  void CaloStrip::Set(Int_t view, Int_t pl Line 152  void CaloStrip::Set(Int_t view, Int_t pl
152      lShift = 0.5;      lShift = 0.5;
153    };    };
154    //    //
155      if ( fView == 2 ) lShift = - lShift;
156      //
157    shift_.shift = lShift;    shift_.shift = lShift;
158    //    //
159    Float_t zplane[22];    Float_t zplane[22];
# Line 96  void CaloStrip::Set(Int_t view, Int_t pl Line 174  void CaloStrip::Set(Int_t view, Int_t pl
174      //      //
175      // X view      // X view
176      //      //
177      fX = (lPos - CTX)/10.;      fX = (lPos - UXal)/10.;
178      fY = 0.;      fY = 0.;
179      fZ = (zplane[fPlane-1] - 5.81 + CTZ)/10.;          fZ = (zplane[fPlane-1] - 5.81 + UZal)/10.;    
180    } else {    } else {
181      //      //
182      // Y view      // Y view
183      //      //
184      fX = 0;      fX = 0;
185      fY = (lPos - CTY)/10.;      fY = (lPos - UYal)/10.;
186      fZ = (zplane[fPlane-1] + CTZ)/10.;      fZ = (zplane[fPlane-1] + UZal)/10.;
187    };    };
188    //      //  
189  };  };
# Line 134  void CaloStrip::Set(Float_t X, Float_t Y Line 212  void CaloStrip::Set(Float_t X, Float_t Y
212    Float_t dzx[22];    Float_t dzx[22];
213    Float_t dzy[22];    Float_t dzy[22];
214    for ( Int_t i=0; i < 22; i++){    for ( Int_t i=0; i < 22; i++){
215      dzx[i] = fabs(fZ*10. - (zplane[i] - 5.81 + CTZ));      dzx[i] = fabs(fZ*10. - (zplane[i] - 5.81 + UZal));
216      dzy[i] = fabs(fZ*10. - (zplane[i] + CTZ));          dzy[i] = fabs(fZ*10. - (zplane[i] + UZal));    
217    };    };
218    //    //
219    Float_t minx = TMath::MinElement(22,dzx);    Float_t minx = TMath::MinElement(22,dzx);
# Line 157  void CaloStrip::Set(Float_t X, Float_t Y Line 235  void CaloStrip::Set(Float_t X, Float_t Y
235      if ( fView == 1 ){      if ( fView == 1 ){
236        if ( dzx[i] == minx ){        if ( dzx[i] == minx ){
237          fPlane = i+1;          fPlane = i+1;
238          pos = fX*10. + CTX;          pos = fX*10. + UXal;
239        };        };
240      } else {      } else {
241        if ( dzy[i] == miny ){        if ( dzy[i] == miny ){
242          fPlane = i+1;          fPlane = i+1;
243          pos = fY*10. + CTY;          pos = fY*10. + UYal;
244      };      };
245      };      };
246    };    };
# Line 177  void CaloStrip::Set(Float_t X, Float_t Y Line 255  void CaloStrip::Set(Float_t X, Float_t Y
255    for ( Int_t i=0; i < 96; i++){    for ( Int_t i=0; i < 96; i++){
256      ca->Set(fView-1,fPlane-1,i);      ca->Set(fView-1,fPlane-1,i);
257      if ( fView == 1 ){      if ( fView == 1 ){
258        stpos = ca->GetX()*10. + CTX;        stpos = ca->GetX()*10. + UXal;
259      } else {      } else {
260        stpos = ca->GetY()*10. + CTY;        stpos = ca->GetY()*10. + UYal;
261      };      };
262      dxy[i] = fabs(pos - stpos);      dxy[i] = fabs(pos - stpos);
263    };    };
# Line 300  Float_t CaloLevel1::DecodeEstrip(Int_t e Line 378  Float_t CaloLevel1::DecodeEstrip(Int_t e
378    return(0.);      return(0.);  
379  }  }
380    
381    /*
382     * Returns energy released on plane nplane (where 0<= nplane <= 43, 0 = 1Y, 1 = 1X, 2 = 2Y, 3 = 2X, etc. etc.).
383     */
384    Float_t CaloLevel1::qtotpl(Int_t nplane){
385      //
386      Int_t sview = 1;
387      if ( nplane%2 ) sview = 0;
388      //
389      Int_t splane = nplane-(sview+1)/2;
390      //
391      Float_t totmip = qtotpl(sview,splane);
392      //
393      return(totmip);
394      //
395    };
396    
397    /*
398     * Returns energy released on view "view" (0 = X, 1 = Y) and plane "plane" ( 0 <= plane <= 21 ).
399     */
400    Float_t CaloLevel1::qtotpl(Int_t sview, Int_t splane){
401      //
402      Int_t view = -1;
403      Int_t plane = -1;
404      Int_t strip = -1;
405      //
406      Float_t mip = 0.;
407      Float_t totmip = 0.;
408      //
409      if ( istrip == 0 ) return(0.);
410      //
411      for (Int_t i = 0; i<istrip; i++ ){
412        //
413        mip = DecodeEstrip(i,view,plane,strip);
414        //
415        if ( view == sview && splane == plane ) totmip += mip;
416        //
417        // entry are ordered by strip, plane and view number. Go out if you pass the input strip
418        //
419        if ( view == sview && plane > splane ) return(totmip);
420        if ( view > sview ) return(totmip);
421        //
422      };
423      //
424      return(totmip);
425      //
426    };

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.23